1 /*
2  * Copyright (c) 2011,2017-2020 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_tgt_api.h>
21 #include <wlan_spectral_utils_api.h>
22 #include <target_type.h>
23 
24 #ifdef DIRECT_BUF_RX_ENABLE
25 #include <target_if_direct_buf_rx_api.h>
26 
27 #define DBR_EVENT_TIMEOUT_IN_MS_SPECTRAL 1
28 #define DBR_NUM_RESP_PER_EVENT_SPECTRAL 2
29 #endif
30 
31 void *
tgt_get_pdev_target_handle(struct wlan_objmgr_pdev * pdev)32 tgt_get_pdev_target_handle(struct wlan_objmgr_pdev *pdev)
33 {
34 	struct pdev_spectral *ps;
35 
36 	if (!pdev) {
37 		spectral_err("PDEV is NULL!");
38 		return NULL;
39 	}
40 	ps = wlan_objmgr_pdev_get_comp_private_obj(pdev,
41 						   WLAN_UMAC_COMP_SPECTRAL);
42 	if (!ps) {
43 		spectral_err("PDEV SPECTRAL object is NULL!");
44 		return NULL;
45 	}
46 	return ps->psptrl_target_handle;
47 }
48 
49 void *
tgt_get_psoc_target_handle(struct wlan_objmgr_psoc * psoc)50 tgt_get_psoc_target_handle(struct wlan_objmgr_psoc *psoc)
51 {
52 	struct spectral_context *sc;
53 
54 	if (!psoc) {
55 		spectral_err("psoc is NULL!");
56 		return NULL;
57 	}
58 
59 	sc = wlan_objmgr_psoc_get_comp_private_obj(psoc,
60 						   WLAN_UMAC_COMP_SPECTRAL);
61 	if (!sc) {
62 		spectral_err("psoc Spectral object is NULL!");
63 		return NULL;
64 	}
65 
66 	return sc->psoc_target_handle;
67 }
68 
69 QDF_STATUS
tgt_spectral_control(struct wlan_objmgr_pdev * pdev,struct spectral_cp_request * sscan_req)70 tgt_spectral_control(
71 	struct wlan_objmgr_pdev *pdev,
72 	struct spectral_cp_request *sscan_req)
73 {
74 	struct spectral_context *sc;
75 
76 	if (!pdev) {
77 		spectral_err("PDEV is NULL!");
78 		return -EPERM;
79 	}
80 	sc = spectral_get_spectral_ctx_from_pdev(pdev);
81 	if (!sc) {
82 		spectral_err("spectral context is NULL!");
83 		return -EPERM;
84 	}
85 	return spectral_control_cmn(pdev, sscan_req);
86 }
87 
88 void *
tgt_pdev_spectral_init(struct wlan_objmgr_pdev * pdev)89 tgt_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
90 {
91 	struct wlan_objmgr_psoc *psoc = NULL;
92 	struct wlan_lmac_if_tx_ops *tx_ops;
93 
94 	psoc = wlan_pdev_get_psoc(pdev);
95 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
96 	if (!tx_ops) {
97 		spectral_err("tx_ops is NULL");
98 		return NULL;
99 	}
100 
101 	return tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init(pdev);
102 }
103 
104 void
tgt_pdev_spectral_deinit(struct wlan_objmgr_pdev * pdev)105 tgt_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
106 {
107 	struct wlan_objmgr_psoc *psoc = NULL;
108 	struct wlan_lmac_if_tx_ops *tx_ops;
109 
110 	psoc = wlan_pdev_get_psoc(pdev);
111 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
112 	if (!tx_ops) {
113 		spectral_err("tx_ops is NULL");
114 		return;
115 	}
116 
117 	tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit(pdev);
118 }
119 
120 void *
tgt_psoc_spectral_init(struct wlan_objmgr_psoc * psoc)121 tgt_psoc_spectral_init(struct wlan_objmgr_psoc *psoc)
122 {
123 	struct wlan_lmac_if_tx_ops *tx_ops;
124 
125 	if (!psoc) {
126 		spectral_err("psoc is null");
127 		return NULL;
128 	}
129 
130 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
131 	if (!tx_ops) {
132 		spectral_err("tx_ops is NULL");
133 		return NULL;
134 	}
135 
136 	return tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_init(psoc);
137 }
138 
139 void
tgt_psoc_spectral_deinit(struct wlan_objmgr_psoc * psoc)140 tgt_psoc_spectral_deinit(struct wlan_objmgr_psoc *psoc)
141 {
142 	struct wlan_lmac_if_tx_ops *tx_ops;
143 
144 	if (!psoc) {
145 		spectral_err("psoc is null");
146 		return;
147 	}
148 
149 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
150 	if (!tx_ops) {
151 		spectral_err("tx_ops is NULL");
152 		return;
153 	}
154 
155 	tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_deinit(psoc);
156 }
157 
158 QDF_STATUS
tgt_set_spectral_config(struct wlan_objmgr_pdev * pdev,const struct spectral_cp_param * param,const enum spectral_scan_mode smode,enum spectral_cp_error_code * err)159 tgt_set_spectral_config(struct wlan_objmgr_pdev *pdev,
160 			const struct spectral_cp_param *param,
161 			const enum spectral_scan_mode smode,
162 			enum spectral_cp_error_code *err)
163 {
164 	struct wlan_objmgr_psoc *psoc = NULL;
165 	struct wlan_lmac_if_tx_ops *tx_ops;
166 
167 	psoc = wlan_pdev_get_psoc(pdev);
168 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
169 	if (!tx_ops) {
170 		spectral_err("tx_ops is NULL");
171 		return QDF_STATUS_E_FAILURE;
172 	}
173 
174 	return tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config(pdev, param,
175 			smode, err);
176 }
177 
178 QDF_STATUS
tgt_get_spectral_config(struct wlan_objmgr_pdev * pdev,struct spectral_config * sptrl_config,const enum spectral_scan_mode smode)179 tgt_get_spectral_config(struct wlan_objmgr_pdev *pdev,
180 			struct spectral_config *sptrl_config,
181 			const enum spectral_scan_mode smode)
182 {
183 	struct wlan_objmgr_psoc *psoc = NULL;
184 	struct wlan_lmac_if_tx_ops *tx_ops;
185 
186 	psoc = wlan_pdev_get_psoc(pdev);
187 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
188 	if (!tx_ops) {
189 		spectral_err("tx_ops is NULL");
190 		return QDF_STATUS_E_FAILURE;
191 	}
192 
193 	return tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config(pdev,
194 			sptrl_config,
195 			smode);
196 }
197 
198 QDF_STATUS
tgt_start_spectral_scan(struct wlan_objmgr_pdev * pdev,uint8_t vdev_id,enum spectral_scan_mode smode,enum spectral_cp_error_code * err)199 tgt_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
200 			uint8_t vdev_id,
201 			enum spectral_scan_mode smode,
202 			enum spectral_cp_error_code *err)
203 {
204 	struct wlan_objmgr_psoc *psoc = NULL;
205 	struct wlan_lmac_if_tx_ops *tx_ops;
206 
207 	psoc = wlan_pdev_get_psoc(pdev);
208 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
209 	if (!tx_ops) {
210 		spectral_err("tx_ops is NULL");
211 		return QDF_STATUS_E_FAILURE;
212 	}
213 
214 	return tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan(pdev, vdev_id,
215 								smode, err);
216 }
217 
218 QDF_STATUS
tgt_stop_spectral_scan(struct wlan_objmgr_pdev * pdev,enum spectral_scan_mode smode,enum spectral_cp_error_code * err)219 tgt_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
220 		       enum spectral_scan_mode smode,
221 		       enum spectral_cp_error_code *err)
222 {
223 	struct wlan_objmgr_psoc *psoc;
224 	struct wlan_lmac_if_tx_ops *tx_ops;
225 
226 	psoc = wlan_pdev_get_psoc(pdev);
227 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
228 	if (!tx_ops) {
229 		spectral_err("tx_ops is NULL");
230 		return QDF_STATUS_E_FAILURE;
231 	}
232 
233 	return tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan(pdev, smode,
234 			err);
235 }
236 
237 bool
tgt_is_spectral_active(struct wlan_objmgr_pdev * pdev,enum spectral_scan_mode smode)238 tgt_is_spectral_active(struct wlan_objmgr_pdev *pdev,
239 		       enum spectral_scan_mode smode)
240 {
241 	struct wlan_objmgr_psoc *psoc = NULL;
242 	struct wlan_lmac_if_tx_ops *tx_ops;
243 
244 	psoc = wlan_pdev_get_psoc(pdev);
245 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
246 	if (!tx_ops) {
247 		spectral_err("tx_ops is NULL");
248 		return false;
249 	}
250 
251 	return tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active(pdev, smode);
252 }
253 
254 bool
tgt_is_spectral_enabled(struct wlan_objmgr_pdev * pdev,enum spectral_scan_mode smode)255 tgt_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
256 			enum spectral_scan_mode smode)
257 {
258 	struct wlan_objmgr_psoc *psoc = NULL;
259 	struct wlan_lmac_if_tx_ops *tx_ops;
260 
261 	psoc = wlan_pdev_get_psoc(pdev);
262 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
263 	if (!tx_ops) {
264 		spectral_err("tx_ops is NULL");
265 		return false;
266 	}
267 
268 	return tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled(pdev, smode);
269 }
270 
271 QDF_STATUS
tgt_set_debug_level(struct wlan_objmgr_pdev * pdev,u_int32_t debug_level)272 tgt_set_debug_level(struct wlan_objmgr_pdev *pdev, u_int32_t debug_level)
273 {
274 	struct wlan_objmgr_psoc *psoc = NULL;
275 	struct wlan_lmac_if_tx_ops *tx_ops;
276 
277 	psoc = wlan_pdev_get_psoc(pdev);
278 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
279 	if (!tx_ops) {
280 		spectral_err("tx_ops is NULL");
281 		return QDF_STATUS_E_FAILURE;
282 	}
283 
284 	return tx_ops->sptrl_tx_ops.sptrlto_set_debug_level(pdev, debug_level);
285 }
286 
287 u_int32_t
tgt_get_debug_level(struct wlan_objmgr_pdev * pdev)288 tgt_get_debug_level(struct wlan_objmgr_pdev *pdev)
289 {
290 	struct wlan_objmgr_psoc *psoc = NULL;
291 	struct wlan_lmac_if_tx_ops *tx_ops;
292 
293 	psoc = wlan_pdev_get_psoc(pdev);
294 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
295 	if (!tx_ops) {
296 		spectral_err("tx_ops is NULL");
297 		return -EINVAL;
298 	}
299 
300 	return tx_ops->sptrl_tx_ops.sptrlto_get_debug_level(pdev);
301 }
302 
303 QDF_STATUS
tgt_get_spectral_capinfo(struct wlan_objmgr_pdev * pdev,struct spectral_caps * scaps)304 tgt_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
305 			 struct spectral_caps *scaps)
306 {
307 	struct wlan_objmgr_psoc *psoc = NULL;
308 	struct wlan_lmac_if_tx_ops *tx_ops;
309 
310 	psoc = wlan_pdev_get_psoc(pdev);
311 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
312 	if (!tx_ops) {
313 		spectral_err("tx_ops is NULL");
314 		return QDF_STATUS_E_FAILURE;
315 	}
316 
317 	return tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo(pdev, scaps);
318 }
319 
320 QDF_STATUS
tgt_get_spectral_diagstats(struct wlan_objmgr_pdev * pdev,struct spectral_diag_stats * stats)321 tgt_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
322 			   struct spectral_diag_stats *stats)
323 {
324 	struct wlan_objmgr_psoc *psoc = NULL;
325 	struct wlan_lmac_if_tx_ops *tx_ops;
326 
327 	psoc = wlan_pdev_get_psoc(pdev);
328 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
329 	if (!tx_ops) {
330 		spectral_err("tx_ops is NULL");
331 		return QDF_STATUS_E_FAILURE;
332 	}
333 
334 	return tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats(pdev, stats);
335 }
336 
337 QDF_STATUS
tgt_register_spectral_wmi_ops(struct wlan_objmgr_psoc * psoc,struct spectral_wmi_ops * wmi_ops)338 tgt_register_spectral_wmi_ops(struct wlan_objmgr_psoc *psoc,
339 			      struct spectral_wmi_ops *wmi_ops)
340 {
341 	struct wlan_lmac_if_sptrl_tx_ops *psptrl_tx_ops = NULL;
342 	struct wlan_lmac_if_tx_ops *tx_ops;
343 
344 	if (!psoc) {
345 		spectral_err("psoc is null");
346 		return QDF_STATUS_E_INVAL;
347 	}
348 
349 	if (!wmi_ops) {
350 		spectral_err("WMI operations table is null");
351 		return QDF_STATUS_E_INVAL;
352 	}
353 
354 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
355 	if (!tx_ops) {
356 		spectral_err("tx_ops is NULL");
357 		return QDF_STATUS_E_INVAL;
358 	}
359 
360 	psptrl_tx_ops = &tx_ops->sptrl_tx_ops;
361 
362 	return psptrl_tx_ops->sptrlto_register_spectral_wmi_ops(psoc, wmi_ops);
363 }
364 
365 QDF_STATUS
tgt_register_spectral_tgt_ops(struct wlan_objmgr_psoc * psoc,struct spectral_tgt_ops * tgt_ops)366 tgt_register_spectral_tgt_ops(struct wlan_objmgr_psoc *psoc,
367 			      struct spectral_tgt_ops *tgt_ops)
368 {
369 	struct wlan_lmac_if_sptrl_tx_ops *psptrl_tx_ops;
370 	struct wlan_lmac_if_tx_ops *tx_ops;
371 
372 	if (!psoc) {
373 		spectral_err("psoc is null");
374 		return QDF_STATUS_E_INVAL;
375 	}
376 
377 	if (!tgt_ops) {
378 		spectral_err("Target operations table is null");
379 		return QDF_STATUS_E_INVAL;
380 	}
381 
382 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
383 	if (!tx_ops) {
384 		spectral_err("tx_ops is NULL");
385 		return QDF_STATUS_E_INVAL;
386 	}
387 
388 	psptrl_tx_ops = &tx_ops->sptrl_tx_ops;
389 
390 	return psptrl_tx_ops->sptrlto_register_spectral_tgt_ops(psoc, tgt_ops);
391 }
392 
393 void
tgt_spectral_register_nl_cb(struct wlan_objmgr_pdev * pdev,struct spectral_nl_cb * nl_cb)394 tgt_spectral_register_nl_cb(
395 		struct wlan_objmgr_pdev *pdev,
396 		struct spectral_nl_cb *nl_cb)
397 {
398 	struct wlan_objmgr_psoc *psoc = NULL;
399 	struct wlan_lmac_if_sptrl_tx_ops *psptrl_tx_ops = NULL;
400 	struct wlan_lmac_if_tx_ops *tx_ops;
401 
402 	if (!pdev) {
403 		spectral_err("PDEV is NULL!");
404 		return;
405 	}
406 	psoc = wlan_pdev_get_psoc(pdev);
407 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
408 	if (!tx_ops) {
409 		spectral_err("tx_ops is NULL");
410 		return;
411 	}
412 
413 	psptrl_tx_ops = &tx_ops->sptrl_tx_ops;
414 
415 	return psptrl_tx_ops->sptrlto_register_netlink_cb(pdev, nl_cb);
416 }
417 
418 bool
tgt_spectral_use_nl_bcast(struct wlan_objmgr_pdev * pdev)419 tgt_spectral_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
420 {
421 	struct wlan_objmgr_psoc *psoc = NULL;
422 	struct wlan_lmac_if_sptrl_tx_ops *psptrl_tx_ops = NULL;
423 	struct wlan_lmac_if_tx_ops *tx_ops;
424 
425 	psoc = wlan_pdev_get_psoc(pdev);
426 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
427 	if (!tx_ops) {
428 		spectral_err("tx_ops is NULL");
429 		return false;
430 	}
431 
432 	psptrl_tx_ops = &tx_ops->sptrl_tx_ops;
433 
434 	return psptrl_tx_ops->sptrlto_use_nl_bcast(pdev);
435 }
436 
tgt_spectral_deregister_nl_cb(struct wlan_objmgr_pdev * pdev)437 void tgt_spectral_deregister_nl_cb(struct wlan_objmgr_pdev *pdev)
438 {
439 	struct wlan_objmgr_psoc *psoc = NULL;
440 	struct wlan_lmac_if_sptrl_tx_ops *psptrl_tx_ops = NULL;
441 	struct wlan_lmac_if_tx_ops *tx_ops;
442 
443 	if (!pdev) {
444 		spectral_err("PDEV is NULL!");
445 		return;
446 	}
447 	psoc = wlan_pdev_get_psoc(pdev);
448 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
449 	if (!tx_ops) {
450 		spectral_err("tx_ops is NULL");
451 		return;
452 	}
453 
454 	psptrl_tx_ops = &tx_ops->sptrl_tx_ops;
455 
456 	psptrl_tx_ops->sptrlto_deregister_netlink_cb(pdev);
457 }
458 
459 int
tgt_spectral_process_report(struct wlan_objmgr_pdev * pdev,void * payload)460 tgt_spectral_process_report(struct wlan_objmgr_pdev *pdev,
461 			    void *payload)
462 {
463 	struct wlan_objmgr_psoc *psoc = NULL;
464 	struct wlan_lmac_if_sptrl_tx_ops *psptrl_tx_ops = NULL;
465 	struct wlan_lmac_if_tx_ops *tx_ops;
466 
467 	psoc = wlan_pdev_get_psoc(pdev);
468 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
469 	if (!tx_ops) {
470 		spectral_err("tx_ops is NULL");
471 		return -EINVAL;
472 	}
473 
474 	psptrl_tx_ops = &tx_ops->sptrl_tx_ops;
475 
476 	return psptrl_tx_ops->sptrlto_process_spectral_report(pdev, payload);
477 }
478 
479 uint32_t
tgt_spectral_get_target_type(struct wlan_objmgr_psoc * psoc)480 tgt_spectral_get_target_type(struct wlan_objmgr_psoc *psoc)
481 {
482 	uint32_t target_type = 0;
483 	struct wlan_lmac_if_target_tx_ops *target_type_tx_ops;
484 	struct wlan_lmac_if_tx_ops *tx_ops;
485 
486 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
487 	if (!tx_ops) {
488 		spectral_err("tx_ops is NULL");
489 		return target_type;
490 	}
491 
492 	target_type_tx_ops = &tx_ops->target_tx_ops;
493 
494 	if (target_type_tx_ops->tgt_get_tgt_type)
495 		target_type = target_type_tx_ops->tgt_get_tgt_type(psoc);
496 
497 	return target_type;
498 }
499 
500 #ifdef DIRECT_BUF_RX_ENABLE
501 QDF_STATUS
tgt_spectral_register_to_dbr(struct wlan_objmgr_pdev * pdev)502 tgt_spectral_register_to_dbr(struct wlan_objmgr_pdev *pdev)
503 {
504 	struct wlan_objmgr_psoc *psoc;
505 	struct wlan_lmac_if_direct_buf_rx_tx_ops *dbr_tx_ops = NULL;
506 	struct wlan_lmac_if_sptrl_tx_ops *sptrl_tx_ops = NULL;
507 	struct dbr_module_config dbr_config = {0};
508 	struct wlan_lmac_if_tx_ops *tx_ops;
509 
510 	psoc = wlan_pdev_get_psoc(pdev);
511 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
512 	if (!tx_ops) {
513 		spectral_err("tx_ops is NULL");
514 		return QDF_STATUS_E_FAILURE;
515 	}
516 
517 	dbr_tx_ops = &tx_ops->dbr_tx_ops;
518 	sptrl_tx_ops = &tx_ops->sptrl_tx_ops;
519 	dbr_config.num_resp_per_event = DBR_NUM_RESP_PER_EVENT_SPECTRAL;
520 	dbr_config.event_timeout_in_ms = DBR_EVENT_TIMEOUT_IN_MS_SPECTRAL;
521 
522 	if ((sptrl_tx_ops->sptrlto_direct_dma_support) &&
523 	    (sptrl_tx_ops->sptrlto_direct_dma_support(pdev))) {
524 		if (sptrl_tx_ops->sptrlto_check_and_do_dbr_buff_debug)
525 			sptrl_tx_ops->sptrlto_check_and_do_dbr_buff_debug(pdev);
526 		if (dbr_tx_ops->direct_buf_rx_module_register)
527 			dbr_tx_ops->direct_buf_rx_module_register
528 				(pdev, 0, &dbr_config,
529 				 spectral_dbr_event_handler);
530 		if (sptrl_tx_ops->sptrlto_check_and_do_dbr_ring_debug)
531 			sptrl_tx_ops->sptrlto_check_and_do_dbr_ring_debug(pdev);
532 	}
533 
534 	return QDF_STATUS_SUCCESS;
535 }
536 
537 QDF_STATUS
tgt_spectral_unregister_to_dbr(struct wlan_objmgr_pdev * pdev)538 tgt_spectral_unregister_to_dbr(struct wlan_objmgr_pdev *pdev)
539 {
540 	struct wlan_objmgr_psoc *psoc;
541 	struct wlan_lmac_if_direct_buf_rx_tx_ops *dbr_tx_ops = NULL;
542 	struct wlan_lmac_if_sptrl_tx_ops *sptrl_tx_ops = NULL;
543 	struct wlan_lmac_if_tx_ops *tx_ops;
544 
545 	psoc = wlan_pdev_get_psoc(pdev);
546 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
547 	if (!tx_ops) {
548 		spectral_err("tx_ops is NULL");
549 		return QDF_STATUS_E_FAILURE;
550 	}
551 
552 	dbr_tx_ops = &tx_ops->dbr_tx_ops;
553 	sptrl_tx_ops = &tx_ops->sptrl_tx_ops;
554 
555 	if ((sptrl_tx_ops->sptrlto_direct_dma_support) &&
556 	    (sptrl_tx_ops->sptrlto_direct_dma_support(pdev))) {
557 		/* Stop DBR debug as the buffers itself are freed now */
558 		if (dbr_tx_ops->direct_buf_rx_stop_ring_debug)
559 			dbr_tx_ops->direct_buf_rx_stop_ring_debug(pdev, 0);
560 
561 		/*No need to zero-out as buffers are anyway getting freed*/
562 		if (dbr_tx_ops->direct_buf_rx_stop_buffer_poisoning)
563 			dbr_tx_ops->direct_buf_rx_stop_buffer_poisoning
564 				(pdev, 0);
565 		if (dbr_tx_ops->direct_buf_rx_module_unregister)
566 			dbr_tx_ops->direct_buf_rx_module_unregister
567 				(pdev, 0);
568 
569 		return QDF_STATUS_SUCCESS;
570 	}
571 
572 	return QDF_STATUS_E_FAILURE;
573 }
574 #else
575 QDF_STATUS
tgt_spectral_register_to_dbr(struct wlan_objmgr_pdev * pdev)576 tgt_spectral_register_to_dbr(struct wlan_objmgr_pdev *pdev)
577 {
578 	return QDF_STATUS_SUCCESS;
579 }
580 
581 QDF_STATUS
tgt_spectral_unregister_to_dbr(struct wlan_objmgr_pdev * pdev)582 tgt_spectral_unregister_to_dbr(struct wlan_objmgr_pdev *pdev)
583 {
584 	return QDF_STATUS_SUCCESS;
585 }
586 #endif /* DIRECT_BUF_RX_ENABLE */
587 
588 #ifdef DIRECT_BUF_RX_DEBUG
tgt_set_spectral_dma_debug(struct wlan_objmgr_pdev * pdev,enum spectral_dma_debug dma_debug_type,bool dma_debug_enable)589 QDF_STATUS tgt_set_spectral_dma_debug(struct wlan_objmgr_pdev *pdev,
590 				      enum spectral_dma_debug dma_debug_type,
591 				      bool dma_debug_enable)
592 {
593 	struct wlan_objmgr_psoc *psoc;
594 	struct wlan_lmac_if_tx_ops *tx_ops;
595 
596 	psoc = wlan_pdev_get_psoc(pdev);
597 	if (!psoc) {
598 		spectral_err("psoc is NULL!");
599 		return QDF_STATUS_E_FAILURE;
600 	}
601 
602 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
603 	if (!tx_ops) {
604 		spectral_err("tx_ops is NULL");
605 		return QDF_STATUS_E_FAILURE;
606 	}
607 
608 	return tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug(pdev, dma_debug_type,
609 			dma_debug_enable);
610 }
611 #else
tgt_set_spectral_dma_debug(struct wlan_objmgr_pdev * pdev,enum spectral_dma_debug dma_debug_type,bool dma_debug_enable)612 QDF_STATUS tgt_set_spectral_dma_debug(struct wlan_objmgr_pdev *pdev,
613 				      enum spectral_dma_debug dma_debug_type,
614 				      bool dma_debug_enable)
615 {
616 	return QDF_STATUS_SUCCESS;
617 }
618 #endif
619 
620 QDF_STATUS
tgt_spectral_register_events(struct wlan_objmgr_psoc * psoc)621 tgt_spectral_register_events(struct wlan_objmgr_psoc *psoc)
622 {
623 	struct wlan_lmac_if_tx_ops *tx_ops;
624 	struct wlan_lmac_if_sptrl_tx_ops *psptrl_tx_ops;
625 
626 	if (!psoc) {
627 		spectral_err("psoc is null");
628 		return QDF_STATUS_E_INVAL;
629 	}
630 
631 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
632 	if (!tx_ops) {
633 		spectral_err("tx_ops is NULL");
634 		return QDF_STATUS_E_INVAL;
635 	}
636 
637 	psptrl_tx_ops = &tx_ops->sptrl_tx_ops;
638 
639 	return psptrl_tx_ops->sptrlto_register_events(psoc);
640 }
641 
642 QDF_STATUS
tgt_spectral_unregister_events(struct wlan_objmgr_psoc * psoc)643 tgt_spectral_unregister_events(struct wlan_objmgr_psoc *psoc)
644 {
645 	struct wlan_lmac_if_tx_ops *tx_ops;
646 	struct wlan_lmac_if_sptrl_tx_ops *psptrl_tx_ops;
647 
648 	if (!psoc) {
649 		spectral_err("psoc is null");
650 		return QDF_STATUS_E_INVAL;
651 	}
652 
653 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
654 	if (!tx_ops) {
655 		spectral_err("tx_ops is NULL");
656 		return QDF_STATUS_E_INVAL;
657 	}
658 
659 	psptrl_tx_ops = &tx_ops->sptrl_tx_ops;
660 
661 	return psptrl_tx_ops->sptrlto_unregister_events(psoc);
662 }
663 
664 QDF_STATUS
tgt_spectral_init_pdev_feature_caps(struct wlan_objmgr_pdev * pdev)665 tgt_spectral_init_pdev_feature_caps(struct wlan_objmgr_pdev *pdev)
666 {
667 	struct wlan_lmac_if_sptrl_tx_ops *spectral_tx_ops;
668 
669 	if (!pdev) {
670 		spectral_err("pdev is NULL!");
671 		return QDF_STATUS_E_INVAL;
672 	}
673 
674 	spectral_tx_ops = wlan_spectral_pdev_get_lmac_if_txops(pdev);
675 	if (!spectral_tx_ops) {
676 		spectral_err("Spectral txops is null");
677 		return QDF_STATUS_E_FAILURE;
678 	}
679 
680 	return spectral_tx_ops->sptrlto_init_pdev_feature_caps(pdev);
681 }
682