xref: /wlan-dirver/qca-wifi-host-cmn/spectral/dispatcher/src/wlan_spectral_ucfg_api.c (revision bea437e2293c3d4fb1b5704fcf633aedac996962)
1 /*
2  * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved.
3  *
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include <wlan_spectral_ucfg_api.h>
21 #include "../../core/spectral_cmn_api_i.h"
22 #include <wlan_spectral_utils_api.h>
23 #include <qdf_module.h>
24 #include <cfg_ucfg_api.h>
25 
26 QDF_STATUS
27 ucfg_spectral_control(struct wlan_objmgr_pdev *pdev,
28 		      struct spectral_cp_request *sscan_req)
29 {
30 	struct spectral_context *sc;
31 
32 	if (!pdev) {
33 		spectral_err("PDEV is NULL!");
34 		return -EPERM;
35 	}
36 
37 	if (wlan_spectral_is_feature_disabled(wlan_pdev_get_psoc(pdev))) {
38 		spectral_info("Spectral is disabled");
39 		return -EPERM;
40 	}
41 
42 	sc = spectral_get_spectral_ctx_from_pdev(pdev);
43 	if (!sc) {
44 		spectral_err("spectral context is NULL!");
45 		return -EPERM;
46 	}
47 
48 	return sc->sptrlc_spectral_control(pdev, sscan_req);
49 }
50 qdf_export_symbol(ucfg_spectral_control);
51 
52 void ucfg_spectral_scan_set_ppid(struct wlan_objmgr_pdev *pdev, uint32_t ppid)
53 {
54 	struct pdev_spectral *ps = NULL;
55 
56 	if (!pdev) {
57 		spectral_err("PDEV is NULL!");
58 		return;
59 	}
60 	ps = wlan_objmgr_pdev_get_comp_private_obj(pdev,
61 						   WLAN_UMAC_COMP_SPECTRAL);
62 	if (!ps) {
63 		spectral_err("spectral context is NULL!");
64 		return;
65 	}
66 	ps->spectral_pid = ppid;
67 	spectral_debug("spectral ppid: %d", ppid);
68 
69 	return;
70 }
71 
72 QDF_STATUS ucfg_spectral_create_cp_req(struct spectral_cp_request *sscan_req,
73 				       void *indata, u_int32_t insize)
74 {
75 	QDF_STATUS status = QDF_STATUS_SUCCESS;
76 
77 	switch (sscan_req->req_id) {
78 	case SPECTRAL_SET_CONFIG:
79 		{
80 			if (insize < sizeof(struct spectral_config) ||
81 			    !indata) {
82 				status = QDF_STATUS_E_FAILURE;
83 				goto bad;
84 			}
85 			qdf_mem_copy(&sscan_req->config_req.sscan_config,
86 				     indata,
87 				     sizeof(struct spectral_config));
88 		}
89 		break;
90 
91 	case SPECTRAL_SET_DEBUG_LEVEL:
92 		{
93 			if (insize < sizeof(uint32_t) || !indata) {
94 				status = QDF_STATUS_E_FAILURE;
95 				goto bad;
96 			}
97 			sscan_req->debug_req.spectral_dbg_level =
98 							*(uint32_t *)indata;
99 		}
100 		break;
101 
102 	default:
103 		break;
104 	}
105 
106 bad:
107 	return status;
108 }
109 
110 qdf_export_symbol(ucfg_spectral_create_cp_req);
111 
112 QDF_STATUS ucfg_spectral_extract_response(struct spectral_cp_request *sscan_req,
113 					  void *outdata, u_int32_t *outsize)
114 {
115 	QDF_STATUS status = QDF_STATUS_SUCCESS;
116 
117 	switch (sscan_req->req_id) {
118 	case SPECTRAL_GET_CONFIG:
119 		{
120 			if (!outdata || !outsize ||
121 			    (*outsize < sizeof(struct spectral_config))) {
122 				status = QDF_STATUS_E_FAILURE;
123 				goto bad;
124 			}
125 			*outsize = sizeof(struct spectral_config);
126 			qdf_mem_copy(outdata,
127 				     &sscan_req->config_req.sscan_config,
128 				     sizeof(struct spectral_config));
129 		}
130 		break;
131 
132 	case SPECTRAL_IS_ACTIVE:
133 		{
134 			if (!outdata || !outsize ||
135 			    *outsize < sizeof(uint32_t)) {
136 				status = QDF_STATUS_E_FAILURE;
137 				goto bad;
138 			}
139 			*outsize = sizeof(uint32_t);
140 			*((uint32_t *)outdata) =
141 				sscan_req->status_req.is_active;
142 		}
143 		break;
144 
145 	case SPECTRAL_IS_ENABLED:
146 		{
147 			if (!outdata || !outsize ||
148 			    *outsize < sizeof(uint32_t)) {
149 				status = QDF_STATUS_E_FAILURE;
150 				goto bad;
151 			}
152 			*outsize = sizeof(uint32_t);
153 			*((uint32_t *)outdata) =
154 				sscan_req->status_req.is_enabled;
155 		}
156 		break;
157 
158 	case SPECTRAL_GET_DEBUG_LEVEL:
159 		{
160 			if (!outdata || !outsize ||
161 			    *outsize < sizeof(uint32_t)) {
162 				status = QDF_STATUS_E_FAILURE;
163 				goto bad;
164 			}
165 			*outsize = sizeof(uint32_t);
166 			*((uint32_t *)outdata) =
167 				sscan_req->debug_req.spectral_dbg_level;
168 		}
169 		break;
170 
171 	case SPECTRAL_GET_CAPABILITY_INFO:
172 		{
173 			if (!outdata || !outsize ||
174 			    *outsize < sizeof(struct spectral_caps)) {
175 				status = QDF_STATUS_E_FAILURE;
176 				goto bad;
177 			}
178 			*outsize = sizeof(struct spectral_caps);
179 			qdf_mem_copy(outdata, &sscan_req->caps_req.sscan_caps,
180 				     sizeof(struct spectral_caps));
181 		}
182 		break;
183 
184 	case SPECTRAL_GET_DIAG_STATS:
185 		{
186 			if (!outdata || !outsize ||
187 			    (*outsize < sizeof(struct spectral_diag_stats))) {
188 				status = QDF_STATUS_E_FAILURE;
189 				goto bad;
190 			}
191 			*outsize = sizeof(struct spectral_diag_stats);
192 			qdf_mem_copy(outdata, &sscan_req->diag_req.sscan_diag,
193 				     sizeof(struct spectral_diag_stats));
194 		}
195 		break;
196 
197 	case SPECTRAL_GET_CHAN_WIDTH:
198 		{
199 			if (!outdata || !outsize ||
200 			    *outsize < sizeof(uint32_t)) {
201 				status = QDF_STATUS_E_FAILURE;
202 				goto bad;
203 			}
204 			*outsize = sizeof(uint32_t);
205 			*((uint32_t *)outdata) =
206 				sscan_req->chan_width_req.chan_width;
207 		}
208 		break;
209 
210 	default:
211 		break;
212 	}
213 
214 bad:
215 	return status;
216 }
217 
218 qdf_export_symbol(ucfg_spectral_extract_response);
219 
220 QDF_STATUS ucfg_spectral_register_to_dbr(struct wlan_objmgr_pdev *pdev)
221 {
222 	return spectral_pdev_open(pdev);
223 }
224