xref: /wlan-dirver/qca-wifi-host-cmn/target_if/cfr/src/target_if_cfr.c (revision 8b3dca18206e1a0461492f082fa6e270b092c035)
1 /*
2  * Copyright (c) 2019-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
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 <target_if_cfr.h>
21 #include <wlan_tgt_def_config.h>
22 #include <target_type.h>
23 #include <hif_hw_version.h>
24 #include <target_if.h>
25 #include <wlan_lmac_if_def.h>
26 #include <wlan_osif_priv.h>
27 #include <init_deinit_lmac.h>
28 #include <wlan_cfr_utils_api.h>
29 #include <wlan_objmgr_pdev_obj.h>
30 #include <target_if_cfr_enh.h>
31 #ifdef CFR_USE_FIXED_FOLDER
32 #include "target_if_cfr_6490.h"
33 #include "target_if_cfr_adrastea.h"
34 #include "wlan_reg_services_api.h"
35 #else
36 #include <target_if_cfr_dbr.h>
37 #endif
38 
39 int target_if_cfr_stop_capture(struct wlan_objmgr_pdev *pdev,
40 			       struct wlan_objmgr_peer *peer)
41 {
42 	struct peer_cfr *pe;
43 	struct peer_cfr_params param = {0};
44 	struct wmi_unified *pdev_wmi_handle = NULL;
45 	struct wlan_objmgr_vdev *vdev = {0};
46 	struct pdev_cfr *pdev_cfrobj;
47 	int retv = 0;
48 
49 	pe = wlan_objmgr_peer_get_comp_private_obj(peer, WLAN_UMAC_COMP_CFR);
50 	if (pe == NULL)
51 		return -EINVAL;
52 
53 	pdev_wmi_handle = lmac_get_pdev_wmi_handle(pdev);
54 	if (!pdev_wmi_handle) {
55 		cfr_err("pdev wmi handle NULL");
56 		return -EINVAL;
57 	}
58 	vdev = wlan_peer_get_vdev(peer);
59 
60 	qdf_mem_set(&param, sizeof(param), 0);
61 
62 	param.request = PEER_CFR_CAPTURE_DISABLE;
63 	param.macaddr = wlan_peer_get_macaddr(peer);
64 	param.vdev_id = wlan_vdev_get_id(vdev);
65 
66 	param.periodicity = pe->period;
67 	param.bandwidth = pe->bandwidth;
68 	param.capture_method = pe->capture_method;
69 
70 	retv = wmi_unified_send_peer_cfr_capture_cmd(pdev_wmi_handle, &param);
71 
72 	pdev_cfrobj = wlan_objmgr_pdev_get_comp_private_obj(pdev,
73 							    WLAN_UMAC_COMP_CFR);
74 	if (!pdev_cfrobj) {
75 		cfr_err("pdev object for CFR is null");
76 		return -EINVAL;
77 	}
78 	cfr_err("CFR capture stats for this capture:");
79 	cfr_err("DBR event count = %llu, Tx event count = %llu "
80 		"Release count = %llu",
81 		pdev_cfrobj->dbr_evt_cnt, pdev_cfrobj->tx_evt_cnt,
82 		pdev_cfrobj->release_cnt);
83 	cfr_err("tx_peer_status_cfr_fail = %llu",
84 		pdev_cfrobj->tx_peer_status_cfr_fail = 0);
85 	cfr_err("tx_evt_status_cfr_fail = %llu",
86 		pdev_cfrobj->tx_evt_status_cfr_fail);
87 	cfr_err("tx_dbr_cookie_lookup_fail = %llu",
88 		pdev_cfrobj->tx_dbr_cookie_lookup_fail);
89 
90 	pdev_cfrobj->dbr_evt_cnt = 0;
91 	pdev_cfrobj->tx_evt_cnt  = 0;
92 	pdev_cfrobj->release_cnt = 0;
93 	pdev_cfrobj->tx_peer_status_cfr_fail = 0;
94 	pdev_cfrobj->tx_evt_status_cfr_fail = 0;
95 	pdev_cfrobj->tx_dbr_cookie_lookup_fail = 0;
96 
97 	return retv;
98 }
99 
100 int target_if_cfr_start_capture(struct wlan_objmgr_pdev *pdev,
101 				struct wlan_objmgr_peer *peer,
102 				struct cfr_capture_params *cfr_params)
103 {
104 	struct peer_cfr_params param = {0};
105 	struct wmi_unified *pdev_wmi_handle = NULL;
106 	struct wlan_objmgr_vdev *vdev;
107 	int retv = 0;
108 
109 	pdev_wmi_handle = lmac_get_pdev_wmi_handle(pdev);
110 	if (!pdev_wmi_handle) {
111 		cfr_err("pdev wmi handle NULL");
112 		return -EINVAL;
113 	}
114 	vdev = wlan_peer_get_vdev(peer);
115 	qdf_mem_set(&param, sizeof(param), 0);
116 
117 	param.request = PEER_CFR_CAPTURE_ENABLE;
118 	param.macaddr = wlan_peer_get_macaddr(peer);
119 	param.vdev_id = wlan_vdev_get_id(vdev);
120 
121 	param.periodicity = cfr_params->period;
122 	param.bandwidth = cfr_params->bandwidth;
123 	param.capture_method = cfr_params->method;
124 
125 	retv = wmi_unified_send_peer_cfr_capture_cmd(pdev_wmi_handle, &param);
126 	return retv;
127 }
128 
129 #ifdef ENABLE_HOST_TO_TARGET_CONVERSION
130 int target_if_cfr_periodic_peer_cfr_enable(struct wlan_objmgr_pdev *pdev,
131 					   uint32_t param_value)
132 {
133 	struct pdev_params pparam;
134 	uint32_t pdev_id;
135 	struct wmi_unified *pdev_wmi_handle = NULL;
136 
137 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
138 	if (pdev_id < 0)
139 		return -EINVAL;
140 
141 	pdev_wmi_handle = lmac_get_pdev_wmi_handle(pdev);
142 	if (!pdev_wmi_handle) {
143 		cfr_err("pdev wmi handle NULL");
144 		return -EINVAL;
145 	}
146 	qdf_mem_set(&pparam, sizeof(pparam), 0);
147 	pparam.param_id = wmi_pdev_param_per_peer_prd_cfr_enable;
148 	pparam.param_value = param_value;
149 
150 	return wmi_unified_pdev_param_send(pdev_wmi_handle,
151 					   &pparam, pdev_id);
152 }
153 #else
154 int target_if_cfr_periodic_peer_cfr_enable(struct wlan_objmgr_pdev *pdev,
155 					   uint32_t param_value)
156 {
157 	struct pdev_params pparam;
158 	uint32_t pdev_id;
159 	struct wmi_unified *pdev_wmi_handle = NULL;
160 
161 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
162 	if (pdev_id < 0)
163 		return -EINVAL;
164 
165 	pdev_wmi_handle = lmac_get_pdev_wmi_handle(pdev);
166 	if (!pdev_wmi_handle) {
167 		cfr_err("pdev wmi handle NULL");
168 		return -EINVAL;
169 	}
170 	qdf_mem_set(&pparam, sizeof(pparam), 0);
171 	pparam.param_id = WMI_PDEV_PARAM_PER_PEER_PERIODIC_CFR_ENABLE;
172 	pparam.param_value = param_value;
173 
174 	return wmi_unified_pdev_param_send(pdev_wmi_handle,
175 					   &pparam, pdev_id);
176 }
177 #endif
178 
179 int target_if_cfr_enable_cfr_timer(struct wlan_objmgr_pdev *pdev,
180 				   uint32_t cfr_timer)
181 {
182 	struct pdev_cfr *pa;
183 	int retval;
184 
185 	pa = wlan_objmgr_pdev_get_comp_private_obj(pdev, WLAN_UMAC_COMP_CFR);
186 	if (pa == NULL)
187 		return QDF_STATUS_E_FAILURE;
188 
189 	if (!cfr_timer) {
190 	     /* disable periodic cfr capture */
191 		retval =
192 	target_if_cfr_periodic_peer_cfr_enable(pdev,
193 					       WMI_HOST_PEER_CFR_TIMER_DISABLE);
194 
195 		if (retval == QDF_STATUS_SUCCESS)
196 			pa->cfr_timer_enable = 0;
197 	} else {
198 	    /* enable periodic cfr capture (default base timer is 10ms ) */
199 		retval =
200 	target_if_cfr_periodic_peer_cfr_enable(pdev,
201 					       WMI_HOST_PEER_CFR_TIMER_ENABLE);
202 
203 		if (retval == QDF_STATUS_SUCCESS)
204 			pa->cfr_timer_enable = 1;
205 	}
206 
207 	return retval;
208 }
209 
210 int target_if_cfr_get_target_type(struct wlan_objmgr_psoc *psoc)
211 {
212 	uint32_t target_type = 0;
213 	struct wlan_lmac_if_target_tx_ops *target_type_tx_ops;
214 	struct wlan_lmac_if_tx_ops *tx_ops;
215 
216 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
217 	if (!tx_ops) {
218 		cfr_err("tx_ops is NULL");
219 		return target_type;
220 	}
221 	target_type_tx_ops = &tx_ops->target_tx_ops;
222 
223 	if (target_type_tx_ops->tgt_get_tgt_type)
224 		target_type = target_type_tx_ops->tgt_get_tgt_type(psoc);
225 
226 	return target_type;
227 }
228 
229 void target_if_cfr_fill_header(struct csi_cfr_header *hdr,
230 			       bool is_wifi_2_0,
231 			       uint32_t target_type,
232 			       bool is_rcc)
233 {
234 	hdr->cmn.start_magic_num = 0xDEADBEAF;
235 	hdr->cmn.vendorid = 0x8cfdf0;
236 	hdr->cmn.pltform_type = CFR_PLATFORM_TYPE_ARM;
237 	hdr->cmn.cfr_metadata_len = CFR_META_DATA_LEN;
238 	hdr->cmn.cfr_data_version = CFR_DATA_VERSION_1;
239 	hdr->cmn.host_real_ts = qdf_ktime_to_ns(qdf_ktime_real_get());
240 
241 	if (target_type == TARGET_TYPE_QCA8074V2) {
242 		hdr->cmn.cfr_metadata_version = CFR_META_VERSION_8;
243 		hdr->cmn.chip_type = CFR_CAPTURE_RADIO_HKV2;
244 	} else if (target_type == TARGET_TYPE_QCA9574) {
245 		hdr->cmn.cfr_metadata_version = CFR_META_VERSION_8;
246 		hdr->cmn.chip_type = CFR_CAPTURE_RADIO_ALDER;
247 	} else {
248 		if (target_type == TARGET_TYPE_QCN9000)
249 			hdr->cmn.cfr_metadata_version = CFR_META_VERSION_9;
250 		else if (target_type == TARGET_TYPE_QCN9224 ||
251 			 target_type == TARGET_TYPE_QCA5332 ||
252 			 target_type == TARGET_TYPE_QCA6490 ||
253 			 target_type == TARGET_TYPE_QCA6750 ||
254 			 target_type == TARGET_TYPE_KIWI ||
255 			 target_type == TARGET_TYPE_MANGO)
256 			hdr->cmn.cfr_metadata_version = CFR_META_VERSION_7;
257 		else if ((target_type == TARGET_TYPE_QCA6018) ||
258 			 ((target_type == TARGET_TYPE_QCA5018) && (!is_rcc)))
259 			hdr->cmn.cfr_metadata_version = CFR_META_VERSION_5;
260 		else
261 			hdr->cmn.cfr_metadata_version = CFR_META_VERSION_3;
262 
263 		if (target_type == TARGET_TYPE_QCN9000)
264 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_PINE;
265 		else if (target_type == TARGET_TYPE_QCA5018)
266 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_MAPLE;
267 		else if (target_type == TARGET_TYPE_QCN6122)
268 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_SPRUCE;
269 		else if (target_type == TARGET_TYPE_QCN9224)
270 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_WAIKIKI;
271 		else if (target_type == TARGET_TYPE_QCA5332)
272 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_MIAMI;
273 		else if (target_type == TARGET_TYPE_QCA6490)
274 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_HSP;
275 		else if (target_type == TARGET_TYPE_QCA6750)
276 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_MOSELLE;
277 		else if (target_type == TARGET_TYPE_KIWI)
278 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_KIWI;
279 		else if (target_type == TARGET_TYPE_MANGO)
280 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_MANGO;
281 		else
282 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_CYP;
283 	}
284 }
285 
286 #ifdef CFR_USE_FIXED_FOLDER
287 static QDF_STATUS target_if_cfr_init_target(struct wlan_objmgr_psoc *psoc,
288 					    struct wlan_objmgr_pdev *pdev,
289 					    uint32_t target)
290 {
291 	struct pdev_cfr *cfr_pdev;
292 	struct psoc_cfr *cfr_psoc;
293 	struct wmi_unified *wmi_handle = NULL;
294 	bool cfr_capable;
295 	QDF_STATUS status;
296 
297 	if (!psoc || !pdev) {
298 		cfr_err("null pdev or psoc");
299 		return QDF_STATUS_E_FAILURE;
300 	}
301 
302 	cfr_pdev = wlan_objmgr_pdev_get_comp_private_obj(pdev,
303 							 WLAN_UMAC_COMP_CFR);
304 	if (!cfr_pdev) {
305 		cfr_err("null pdev cfr");
306 		return QDF_STATUS_E_FAILURE;
307 	}
308 
309 	cfr_psoc = wlan_objmgr_psoc_get_comp_private_obj(psoc,
310 							 WLAN_UMAC_COMP_CFR);
311 
312 	if (!cfr_psoc) {
313 		cfr_err("null psoc cfr");
314 		return QDF_STATUS_E_FAILURE;
315 	}
316 
317 	wmi_handle = lmac_get_pdev_wmi_handle(pdev);
318 	if (!wmi_handle) {
319 		cfr_err("null wmi handle");
320 		return QDF_STATUS_E_FAILURE;
321 	}
322 
323 	if (wlan_cfr_is_feature_disabled(pdev)) {
324 		cfr_pdev->is_cfr_capable = 0;
325 		cfr_psoc->is_cfr_capable = 0;
326 		cfr_info("cfr disabled");
327 		return QDF_STATUS_SUCCESS;
328 	}
329 
330 	cfr_capable = wmi_service_enabled(wmi_handle,
331 					  wmi_service_cfr_capture_support);
332 	cfr_pdev->is_cfr_capable = cfr_capable;
333 	cfr_psoc->is_cfr_capable = cfr_capable;
334 	if (!cfr_capable) {
335 		cfr_err("FW doesn't support CFR");
336 		return QDF_STATUS_SUCCESS;
337 	}
338 
339 	status = cfr_enh_init_pdev(psoc, pdev);
340 	if (target == TARGET_TYPE_QCA6490)
341 		cfr_pdev->chip_type = CFR_CAPTURE_RADIO_HSP;
342 	else if (target == TARGET_TYPE_QCA6750)
343 		cfr_pdev->chip_type = CFR_CAPTURE_RADIO_MOSELLE;
344 	else if (target == TARGET_TYPE_KIWI)
345 		cfr_pdev->chip_type = CFR_CAPTURE_RADIO_KIWI;
346 	else if (target == TARGET_TYPE_MANGO)
347 		cfr_pdev->chip_type = CFR_CAPTURE_RADIO_MANGO;
348 
349 	return status;
350 }
351 
352 static QDF_STATUS target_if_cfr_deinit_target(struct wlan_objmgr_psoc *psoc,
353 					      struct wlan_objmgr_pdev *pdev)
354 {
355 	struct pdev_cfr *pcfr;
356 
357 	if (!psoc || !pdev) {
358 		cfr_err("null pdev or psoc");
359 		return QDF_STATUS_E_FAILURE;
360 	}
361 
362 	pcfr = wlan_objmgr_pdev_get_comp_private_obj(pdev,
363 						     WLAN_UMAC_COMP_CFR);
364 	if (!pcfr) {
365 		cfr_err("null pdev cfr");
366 		return QDF_STATUS_E_FAILURE;
367 	}
368 
369 	if (!pcfr->is_cfr_capable) {
370 		cfr_info("cfr disabled or FW not support");
371 		return QDF_STATUS_SUCCESS;
372 	}
373 
374 	return cfr_enh_deinit_pdev(psoc, pdev);
375 }
376 
377 QDF_STATUS
378 target_if_cfr_init_pdev(struct wlan_objmgr_psoc *psoc,
379 			struct wlan_objmgr_pdev *pdev)
380 {
381 	uint32_t target_type;
382 	QDF_STATUS status;
383 
384 	target_type = target_if_cfr_get_target_type(psoc);
385 
386 	if (target_type == TARGET_TYPE_QCA6490 ||
387 	    target_type == TARGET_TYPE_QCA6750 ||
388 	    target_type == TARGET_TYPE_KIWI ||
389 	    target_type == TARGET_TYPE_MANGO) {
390 		status = target_if_cfr_init_target(psoc,
391 						   pdev, target_type);
392 	} else if (target_type == TARGET_TYPE_ADRASTEA) {
393 		status = cfr_adrastea_init_pdev(psoc, pdev);
394 	} else {
395 		cfr_info("unsupport chip");
396 		status = QDF_STATUS_SUCCESS;
397 	}
398 
399 	return status;
400 }
401 
402 QDF_STATUS
403 target_if_cfr_deinit_pdev(struct wlan_objmgr_psoc *psoc,
404 			  struct wlan_objmgr_pdev *pdev)
405 {
406 	uint32_t target_type;
407 	QDF_STATUS status;
408 
409 	target_type = target_if_cfr_get_target_type(psoc);
410 
411 	if (target_type == TARGET_TYPE_QCA6490 ||
412 	    target_type == TARGET_TYPE_QCA6750 ||
413 	    target_type == TARGET_TYPE_KIWI ||
414 	    target_type == TARGET_TYPE_MANGO) {
415 		status = target_if_cfr_deinit_target(psoc, pdev);
416 	} else if (target_type == TARGET_TYPE_ADRASTEA) {
417 		status = cfr_adrastea_deinit_pdev(psoc, pdev);
418 	} else {
419 		cfr_info("unsupport chip");
420 		status = QDF_STATUS_SUCCESS;
421 	}
422 
423 	return status;
424 }
425 #else
426 QDF_STATUS
427 target_if_cfr_init_pdev(struct wlan_objmgr_psoc *psoc,
428 			struct wlan_objmgr_pdev *pdev)
429 {
430 	uint32_t target_type;
431 	struct pdev_cfr *pa;
432 	struct psoc_cfr *cfr_sc;
433 
434 	if (wlan_cfr_is_feature_disabled(pdev)) {
435 		cfr_err("cfr is disabled");
436 		return QDF_STATUS_E_NOSUPPORT;
437 	}
438 
439 	pa = wlan_objmgr_pdev_get_comp_private_obj(pdev, WLAN_UMAC_COMP_CFR);
440 	if (pa == NULL)
441 		return QDF_STATUS_E_FAILURE;
442 
443 	/* Reset unassociated entries for every init */
444 	qdf_mem_zero(&pa->unassoc_pool[0], MAX_CFR_ENABLED_CLIENTS *
445 		     sizeof(struct unassoc_pool_entry));
446 
447 	cfr_sc = wlan_objmgr_psoc_get_comp_private_obj(psoc,
448 						       WLAN_UMAC_COMP_CFR);
449 
450 	if (cfr_sc == NULL)
451 		return QDF_STATUS_E_FAILURE;
452 
453 	target_type = target_if_cfr_get_target_type(psoc);
454 
455 	if ((target_type == TARGET_TYPE_QCA8074V2) ||
456 	    (target_type == TARGET_TYPE_QCA9574)) {
457 		pa->is_cfr_capable = cfr_sc->is_cfr_capable;
458 		return cfr_dbr_init_pdev(psoc, pdev);
459 	} else if ((target_type == TARGET_TYPE_QCA6018) ||
460 		   (target_type == TARGET_TYPE_QCN9000) ||
461 		   (target_type == TARGET_TYPE_QCN6122) ||
462 		   (target_type == TARGET_TYPE_QCA5018) ||
463 		   (target_type == TARGET_TYPE_QCA5332) ||
464 		   (target_type == TARGET_TYPE_QCN9224)) {
465 		pa->is_cfr_capable = cfr_sc->is_cfr_capable;
466 		return cfr_enh_init_pdev(psoc, pdev);
467 	} else
468 		return QDF_STATUS_E_NOSUPPORT;
469 }
470 
471 QDF_STATUS
472 target_if_cfr_deinit_pdev(struct wlan_objmgr_psoc *psoc,
473 			  struct wlan_objmgr_pdev *pdev)
474 {
475 	uint32_t target_type;
476 
477 	if (wlan_cfr_is_feature_disabled(pdev)) {
478 		cfr_err("cfr is disabled");
479 		return QDF_STATUS_E_NOSUPPORT;
480 	}
481 
482 	target_type = target_if_cfr_get_target_type(psoc);
483 
484 	if ((target_type == TARGET_TYPE_QCA8074V2) ||
485 	    (target_type == TARGET_TYPE_QCA9574)) {
486 		return cfr_dbr_deinit_pdev(psoc, pdev);
487 	} else if ((target_type == TARGET_TYPE_QCA6018) ||
488 		   (target_type == TARGET_TYPE_QCN9000) ||
489 		   (target_type == TARGET_TYPE_QCN6122) ||
490 		   (target_type == TARGET_TYPE_QCA5018) ||
491 		   (target_type == TARGET_TYPE_QCA5332) ||
492 		   (target_type == TARGET_TYPE_QCN9224)) {
493 		return cfr_enh_deinit_pdev(psoc, pdev);
494 	} else
495 		return QDF_STATUS_E_NOSUPPORT;
496 }
497 #endif
498 
499 #ifdef WLAN_ENH_CFR_ENABLE
500 #if defined(QCA_WIFI_QCA6490) || defined(QCA_WIFI_KIWI)
501 static uint8_t target_if_cfr_get_mac_id(struct wlan_objmgr_pdev *pdev)
502 {
503 	struct wlan_objmgr_vdev *vdev;
504 	struct wlan_channel *bss_chan;
505 	struct pdev_cfr *pcfr;
506 	uint8_t mac_id = 0;
507 
508 	if (!pdev) {
509 		cfr_err("null pdev");
510 		return mac_id;
511 	}
512 
513 	mac_id = wlan_objmgr_pdev_get_pdev_id(pdev);
514 	pcfr = wlan_objmgr_pdev_get_comp_private_obj(pdev, WLAN_UMAC_COMP_CFR);
515 	if (!pcfr)  {
516 		cfr_err("null pcfr");
517 		return mac_id;
518 	}
519 
520 	if (pcfr->rcc_param.vdev_id == CFR_INVALID_VDEV_ID)
521 		return mac_id;
522 
523 	vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev,
524 						    pcfr->rcc_param.vdev_id,
525 						    WLAN_CFR_ID);
526 	if (!vdev) {
527 		cfr_err("null vdev");
528 		return mac_id;
529 	}
530 
531 	bss_chan = wlan_vdev_mlme_get_bss_chan(vdev);
532 	if (!bss_chan) {
533 		cfr_info("null bss chan");
534 		wlan_objmgr_vdev_release_ref(vdev, WLAN_CFR_ID);
535 		return mac_id;
536 	}
537 
538 	cfr_debug("bss freq %d", bss_chan->ch_freq);
539 	if (wlan_reg_is_24ghz_ch_freq(bss_chan->ch_freq))
540 		mac_id = CFR_MAC_ID_24G;
541 	else
542 		mac_id = CFR_MAC_ID_5G;
543 
544 	pcfr->rcc_param.srng_id = mac_id;
545 	wlan_objmgr_vdev_release_ref(vdev, WLAN_CFR_ID);
546 
547 	return mac_id;
548 }
549 
550 static uint8_t target_if_cfr_get_pdev_id(struct wlan_objmgr_pdev *pdev)
551 {
552 	return target_if_cfr_get_mac_id(pdev);
553 }
554 #else
555 static uint8_t target_if_cfr_get_pdev_id(struct wlan_objmgr_pdev *pdev)
556 {
557 	return wlan_objmgr_pdev_get_pdev_id(pdev);
558 }
559 #endif /* QCA_WIFI_QCA6490 || QCA_WIFI_KIWI */
560 
561 QDF_STATUS target_if_cfr_config_rcc(struct wlan_objmgr_pdev *pdev,
562 				    struct cfr_rcc_param *rcc_info)
563 {
564 	QDF_STATUS status;
565 	struct wmi_unified *pdev_wmi_handle = NULL;
566 
567 	pdev_wmi_handle = lmac_get_pdev_wmi_handle(pdev);
568 	if (!pdev_wmi_handle) {
569 		cfr_err("pdev_wmi_handle is null");
570 		return QDF_STATUS_E_NULL_VALUE;
571 	}
572 
573 	rcc_info->pdev_id = target_if_cfr_get_pdev_id(pdev);
574 	rcc_info->num_grp_tlvs =
575 		count_set_bits(rcc_info->modified_in_curr_session);
576 
577 	status = wmi_unified_send_cfr_rcc_cmd(pdev_wmi_handle, rcc_info);
578 	return status;
579 }
580 
581 void target_if_cfr_default_ta_ra_config(struct cfr_rcc_param *rcc_info,
582 					bool allvalid, uint16_t reset_cfg)
583 {
584 	struct ta_ra_cfr_cfg *curr_cfg = NULL;
585 	int grp_id;
586 	unsigned long bitmap = reset_cfg;
587 	uint8_t def_mac[QDF_MAC_ADDR_SIZE] = {0xFF, 0xFF, 0xFF,
588 		0xFF, 0xFF, 0xFF};
589 	uint8_t null_mac[QDF_MAC_ADDR_SIZE] = {0x00, 0x00, 0x00,
590 		0x00, 0x00, 0x00};
591 
592 	for (grp_id = 0; grp_id < MAX_TA_RA_ENTRIES; grp_id++) {
593 		if (qdf_test_bit(grp_id, &bitmap)) {
594 			curr_cfg = &rcc_info->curr[grp_id];
595 			qdf_mem_copy(curr_cfg->tx_addr,
596 				     null_mac, QDF_MAC_ADDR_SIZE);
597 			qdf_mem_copy(curr_cfg->tx_addr_mask,
598 				     def_mac, QDF_MAC_ADDR_SIZE);
599 			qdf_mem_copy(curr_cfg->rx_addr,
600 				     null_mac, QDF_MAC_ADDR_SIZE);
601 			qdf_mem_copy(curr_cfg->rx_addr_mask,
602 				     def_mac, QDF_MAC_ADDR_SIZE);
603 			curr_cfg->bw = 0xf;
604 			curr_cfg->nss = 0xff;
605 			curr_cfg->mgmt_subtype_filter = 0;
606 			curr_cfg->ctrl_subtype_filter = 0;
607 			curr_cfg->data_subtype_filter = 0;
608 			if (!allvalid) {
609 				curr_cfg->valid_ta = 0;
610 				curr_cfg->valid_ta_mask = 0;
611 				curr_cfg->valid_ra = 0;
612 				curr_cfg->valid_ra_mask = 0;
613 				curr_cfg->valid_bw_mask = 0;
614 				curr_cfg->valid_nss_mask = 0;
615 				curr_cfg->valid_mgmt_subtype = 0;
616 				curr_cfg->valid_ctrl_subtype = 0;
617 				curr_cfg->valid_data_subtype = 0;
618 			} else {
619 				curr_cfg->valid_ta = 1;
620 				curr_cfg->valid_ta_mask = 1;
621 				curr_cfg->valid_ra = 1;
622 				curr_cfg->valid_ra_mask = 1;
623 				curr_cfg->valid_bw_mask = 1;
624 				curr_cfg->valid_nss_mask = 1;
625 				curr_cfg->valid_mgmt_subtype = 1;
626 				curr_cfg->valid_ctrl_subtype = 1;
627 				curr_cfg->valid_data_subtype = 1;
628 			}
629 		}
630 	}
631 }
632 #endif
633 
634 #ifdef WLAN_ENH_CFR_ENABLE
635 #ifdef CFR_USE_FIXED_FOLDER
636 static void target_if_enh_cfr_add_ops(struct wlan_lmac_if_tx_ops *tx_ops)
637 {
638 	tx_ops->cfr_tx_ops.cfr_subscribe_ppdu_desc =
639 				target_if_cfr_subscribe_ppdu_desc;
640 }
641 #else
642 static void target_if_enh_cfr_add_ops(struct wlan_lmac_if_tx_ops *tx_ops)
643 {
644 }
645 #endif /* CFR_USE_FIXED_FOLDER */
646 static void target_if_enh_cfr_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
647 {
648 	tx_ops->cfr_tx_ops.cfr_config_rcc =
649 		target_if_cfr_config_rcc;
650 	tx_ops->cfr_tx_ops.cfr_start_lut_timer =
651 		target_if_cfr_start_lut_age_timer;
652 	tx_ops->cfr_tx_ops.cfr_stop_lut_timer =
653 		target_if_cfr_stop_lut_age_timer;
654 	tx_ops->cfr_tx_ops.cfr_default_ta_ra_cfg =
655 		target_if_cfr_default_ta_ra_config;
656 	tx_ops->cfr_tx_ops.cfr_dump_lut_enh =
657 		target_if_cfr_dump_lut_enh;
658 	tx_ops->cfr_tx_ops.cfr_rx_tlv_process =
659 		target_if_cfr_rx_tlv_process;
660 	tx_ops->cfr_tx_ops.cfr_update_global_cfg =
661 		target_if_cfr_update_global_cfg;
662 	target_if_enh_cfr_add_ops(tx_ops);
663 }
664 #else
665 static void target_if_enh_cfr_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
666 {
667 }
668 #endif
669 
670 void target_if_cfr_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
671 {
672 	tx_ops->cfr_tx_ops.cfr_init_pdev =
673 		target_if_cfr_init_pdev;
674 	tx_ops->cfr_tx_ops.cfr_deinit_pdev =
675 		target_if_cfr_deinit_pdev;
676 	tx_ops->cfr_tx_ops.cfr_enable_cfr_timer =
677 		target_if_cfr_enable_cfr_timer;
678 	tx_ops->cfr_tx_ops.cfr_start_capture =
679 		target_if_cfr_start_capture;
680 	tx_ops->cfr_tx_ops.cfr_stop_capture =
681 		target_if_cfr_stop_capture;
682 	target_if_enh_cfr_tx_ops(tx_ops);
683 }
684 
685 void target_if_cfr_set_cfr_support(struct wlan_objmgr_psoc *psoc,
686 				   uint8_t value)
687 {
688 	struct wlan_lmac_if_rx_ops *rx_ops;
689 
690 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
691 	if (!rx_ops) {
692 		cfr_err("rx_ops is NULL");
693 		return;
694 	}
695 	if (rx_ops->cfr_rx_ops.cfr_support_set)
696 		rx_ops->cfr_rx_ops.cfr_support_set(psoc, value);
697 }
698 
699 QDF_STATUS
700 target_if_cfr_set_capture_count_support(struct wlan_objmgr_psoc *psoc,
701 					uint8_t value)
702 {
703 	struct wlan_lmac_if_rx_ops *rx_ops;
704 
705 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
706 	if (!rx_ops) {
707 		cfr_err("rx_ops is NULL");
708 		return QDF_STATUS_E_INVAL;
709 	}
710 
711 	if (rx_ops->cfr_rx_ops.cfr_capture_count_support_set)
712 		return rx_ops->cfr_rx_ops.cfr_capture_count_support_set(
713 						psoc, value);
714 
715 	return QDF_STATUS_E_INVAL;
716 }
717 
718 QDF_STATUS
719 target_if_cfr_set_mo_marking_support(struct wlan_objmgr_psoc *psoc,
720 				     uint8_t value)
721 {
722 	struct wlan_lmac_if_rx_ops *rx_ops;
723 
724 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
725 	if (!rx_ops) {
726 		cfr_err("rx_ops is NULL");
727 		return QDF_STATUS_E_INVAL;
728 	}
729 
730 	if (rx_ops->cfr_rx_ops.cfr_mo_marking_support_set)
731 		return rx_ops->cfr_rx_ops.cfr_mo_marking_support_set(
732 						psoc, value);
733 
734 	return QDF_STATUS_E_INVAL;
735 }
736 
737 QDF_STATUS
738 target_if_cfr_set_aoa_for_rcc_support(struct wlan_objmgr_psoc *psoc,
739 				      uint8_t value)
740 {
741 	struct wlan_lmac_if_rx_ops *rx_ops;
742 
743 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
744 	if (!rx_ops) {
745 		cfr_err("rx_ops is NULL");
746 		return QDF_STATUS_E_INVAL;
747 	}
748 
749 	if (rx_ops->cfr_rx_ops.cfr_aoa_for_rcc_support_set)
750 		return rx_ops->cfr_rx_ops.cfr_aoa_for_rcc_support_set(
751 						psoc, value);
752 
753 	return QDF_STATUS_E_INVAL;
754 }
755 
756 void target_if_cfr_info_send(struct wlan_objmgr_pdev *pdev, void *head,
757 			     size_t hlen, void *data, size_t dlen, void *tail,
758 			     size_t tlen)
759 {
760 	struct wlan_objmgr_psoc *psoc;
761 	struct wlan_lmac_if_rx_ops *rx_ops;
762 
763 	psoc = wlan_pdev_get_psoc(pdev);
764 
765 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
766 	if (!rx_ops) {
767 		cfr_err("rx_ops is NULL");
768 		return;
769 	}
770 	if (rx_ops->cfr_rx_ops.cfr_info_send)
771 		rx_ops->cfr_rx_ops.cfr_info_send(pdev, head, hlen, data, dlen,
772 						 tail, tlen);
773 }
774