xref: /wlan-dirver/qca-wifi-host-cmn/target_if/cfr/src/target_if_cfr.c (revision 901120c066e139c7f8a2c8e4820561fdd83c67ef)
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_QCN9160)
270 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_YORK;
271 		else if (target_type == TARGET_TYPE_QCN9224)
272 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_WAIKIKI;
273 		else if (target_type == TARGET_TYPE_QCA5332)
274 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_MIAMI;
275 		else if (target_type == TARGET_TYPE_QCA6490)
276 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_HSP;
277 		else if (target_type == TARGET_TYPE_QCA6750)
278 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_MOSELLE;
279 		else if (target_type == TARGET_TYPE_KIWI)
280 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_KIWI;
281 		else if (target_type == TARGET_TYPE_MANGO)
282 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_MANGO;
283 		else
284 			hdr->cmn.chip_type = CFR_CAPTURE_RADIO_CYP;
285 	}
286 }
287 
288 #ifdef CFR_USE_FIXED_FOLDER
289 static QDF_STATUS target_if_cfr_init_target(struct wlan_objmgr_psoc *psoc,
290 					    struct wlan_objmgr_pdev *pdev,
291 					    uint32_t target)
292 {
293 	struct pdev_cfr *cfr_pdev;
294 	struct psoc_cfr *cfr_psoc;
295 	struct wmi_unified *wmi_handle = NULL;
296 	bool cfr_capable;
297 	QDF_STATUS status;
298 
299 	if (!psoc || !pdev) {
300 		cfr_err("null pdev or psoc");
301 		return QDF_STATUS_E_FAILURE;
302 	}
303 
304 	cfr_pdev = wlan_objmgr_pdev_get_comp_private_obj(pdev,
305 							 WLAN_UMAC_COMP_CFR);
306 	if (!cfr_pdev) {
307 		cfr_err("null pdev cfr");
308 		return QDF_STATUS_E_FAILURE;
309 	}
310 
311 	cfr_psoc = wlan_objmgr_psoc_get_comp_private_obj(psoc,
312 							 WLAN_UMAC_COMP_CFR);
313 
314 	if (!cfr_psoc) {
315 		cfr_err("null psoc cfr");
316 		return QDF_STATUS_E_FAILURE;
317 	}
318 
319 	wmi_handle = lmac_get_pdev_wmi_handle(pdev);
320 	if (!wmi_handle) {
321 		cfr_err("null wmi handle");
322 		return QDF_STATUS_E_FAILURE;
323 	}
324 
325 	if (wlan_cfr_is_feature_disabled(pdev)) {
326 		cfr_pdev->is_cfr_capable = 0;
327 		cfr_psoc->is_cfr_capable = 0;
328 		cfr_info("cfr disabled");
329 		return QDF_STATUS_SUCCESS;
330 	}
331 
332 	cfr_capable = wmi_service_enabled(wmi_handle,
333 					  wmi_service_cfr_capture_support);
334 	cfr_pdev->is_cfr_capable = cfr_capable;
335 	cfr_psoc->is_cfr_capable = cfr_capable;
336 	if (!cfr_capable) {
337 		cfr_err("FW doesn't support CFR");
338 		return QDF_STATUS_SUCCESS;
339 	}
340 
341 	status = cfr_enh_init_pdev(psoc, pdev);
342 	if (target == TARGET_TYPE_QCA6490)
343 		cfr_pdev->chip_type = CFR_CAPTURE_RADIO_HSP;
344 	else if (target == TARGET_TYPE_QCA6750)
345 		cfr_pdev->chip_type = CFR_CAPTURE_RADIO_MOSELLE;
346 	else if (target == TARGET_TYPE_KIWI)
347 		cfr_pdev->chip_type = CFR_CAPTURE_RADIO_KIWI;
348 	else if (target == TARGET_TYPE_MANGO)
349 		cfr_pdev->chip_type = CFR_CAPTURE_RADIO_MANGO;
350 
351 	return status;
352 }
353 
354 static QDF_STATUS target_if_cfr_deinit_target(struct wlan_objmgr_psoc *psoc,
355 					      struct wlan_objmgr_pdev *pdev)
356 {
357 	struct pdev_cfr *pcfr;
358 
359 	if (!psoc || !pdev) {
360 		cfr_err("null pdev or psoc");
361 		return QDF_STATUS_E_FAILURE;
362 	}
363 
364 	pcfr = wlan_objmgr_pdev_get_comp_private_obj(pdev,
365 						     WLAN_UMAC_COMP_CFR);
366 	if (!pcfr) {
367 		cfr_err("null pdev cfr");
368 		return QDF_STATUS_E_FAILURE;
369 	}
370 
371 	if (!pcfr->is_cfr_capable) {
372 		cfr_info("cfr disabled or FW not support");
373 		return QDF_STATUS_SUCCESS;
374 	}
375 
376 	return cfr_enh_deinit_pdev(psoc, pdev);
377 }
378 
379 QDF_STATUS
380 target_if_cfr_init_pdev(struct wlan_objmgr_psoc *psoc,
381 			struct wlan_objmgr_pdev *pdev)
382 {
383 	uint32_t target_type;
384 	QDF_STATUS status;
385 
386 	target_type = target_if_cfr_get_target_type(psoc);
387 
388 	if (target_type == TARGET_TYPE_QCA6490 ||
389 	    target_type == TARGET_TYPE_QCA6750 ||
390 	    target_type == TARGET_TYPE_KIWI ||
391 	    target_type == TARGET_TYPE_MANGO) {
392 		status = target_if_cfr_init_target(psoc,
393 						   pdev, target_type);
394 	} else if (target_type == TARGET_TYPE_ADRASTEA) {
395 		status = cfr_adrastea_init_pdev(psoc, pdev);
396 	} else {
397 		cfr_info("unsupported chip");
398 		status = QDF_STATUS_SUCCESS;
399 	}
400 
401 	return status;
402 }
403 
404 QDF_STATUS
405 target_if_cfr_deinit_pdev(struct wlan_objmgr_psoc *psoc,
406 			  struct wlan_objmgr_pdev *pdev)
407 {
408 	uint32_t target_type;
409 	QDF_STATUS status;
410 
411 	target_type = target_if_cfr_get_target_type(psoc);
412 
413 	if (target_type == TARGET_TYPE_QCA6490 ||
414 	    target_type == TARGET_TYPE_QCA6750 ||
415 	    target_type == TARGET_TYPE_KIWI ||
416 	    target_type == TARGET_TYPE_MANGO) {
417 		status = target_if_cfr_deinit_target(psoc, pdev);
418 	} else if (target_type == TARGET_TYPE_ADRASTEA) {
419 		status = cfr_adrastea_deinit_pdev(psoc, pdev);
420 	} else {
421 		cfr_info("unsupported chip");
422 		status = QDF_STATUS_SUCCESS;
423 	}
424 
425 	return status;
426 }
427 #else
428 QDF_STATUS
429 target_if_cfr_init_pdev(struct wlan_objmgr_psoc *psoc,
430 			struct wlan_objmgr_pdev *pdev)
431 {
432 	uint32_t target_type;
433 	struct pdev_cfr *pa;
434 	struct psoc_cfr *cfr_sc;
435 
436 	if (wlan_cfr_is_feature_disabled(pdev)) {
437 		cfr_err("cfr is disabled");
438 		return QDF_STATUS_E_NOSUPPORT;
439 	}
440 
441 	pa = wlan_objmgr_pdev_get_comp_private_obj(pdev, WLAN_UMAC_COMP_CFR);
442 	if (pa == NULL)
443 		return QDF_STATUS_E_FAILURE;
444 
445 	/* Reset unassociated entries for every init */
446 	qdf_mem_zero(&pa->unassoc_pool[0], MAX_CFR_ENABLED_CLIENTS *
447 		     sizeof(struct unassoc_pool_entry));
448 
449 	cfr_sc = wlan_objmgr_psoc_get_comp_private_obj(psoc,
450 						       WLAN_UMAC_COMP_CFR);
451 
452 	if (cfr_sc == NULL)
453 		return QDF_STATUS_E_FAILURE;
454 
455 	target_type = target_if_cfr_get_target_type(psoc);
456 
457 	if ((target_type == TARGET_TYPE_QCA8074V2) ||
458 	    (target_type == TARGET_TYPE_QCA9574)) {
459 		pa->is_cfr_capable = cfr_sc->is_cfr_capable;
460 		return cfr_dbr_init_pdev(psoc, pdev);
461 	} else if ((target_type == TARGET_TYPE_QCA6018) ||
462 		   (target_type == TARGET_TYPE_QCN9000) ||
463 		   (target_type == TARGET_TYPE_QCN6122) ||
464 		   (target_type == TARGET_TYPE_QCA5018) ||
465 		   (target_type == TARGET_TYPE_QCA5332) ||
466 		   (target_type == TARGET_TYPE_QCN9224) ||
467 		   (target_type == TARGET_TYPE_QCN9160)) {
468 		pa->is_cfr_capable = cfr_sc->is_cfr_capable;
469 		return cfr_enh_init_pdev(psoc, pdev);
470 	} else
471 		return QDF_STATUS_E_NOSUPPORT;
472 }
473 
474 QDF_STATUS
475 target_if_cfr_deinit_pdev(struct wlan_objmgr_psoc *psoc,
476 			  struct wlan_objmgr_pdev *pdev)
477 {
478 	uint32_t target_type;
479 
480 	if (wlan_cfr_is_feature_disabled(pdev)) {
481 		cfr_err("cfr is disabled");
482 		return QDF_STATUS_E_NOSUPPORT;
483 	}
484 
485 	target_type = target_if_cfr_get_target_type(psoc);
486 
487 	if ((target_type == TARGET_TYPE_QCA8074V2) ||
488 	    (target_type == TARGET_TYPE_QCA9574)) {
489 		return cfr_dbr_deinit_pdev(psoc, pdev);
490 	} else if ((target_type == TARGET_TYPE_QCA6018) ||
491 		   (target_type == TARGET_TYPE_QCN9000) ||
492 		   (target_type == TARGET_TYPE_QCN6122) ||
493 		   (target_type == TARGET_TYPE_QCA5018) ||
494 		   (target_type == TARGET_TYPE_QCA5332) ||
495 		   (target_type == TARGET_TYPE_QCN9224) ||
496 		   (target_type == TARGET_TYPE_QCN9160)) {
497 		return cfr_enh_deinit_pdev(psoc, pdev);
498 	} else
499 		return QDF_STATUS_E_NOSUPPORT;
500 }
501 #endif
502 
503 #ifdef WLAN_ENH_CFR_ENABLE
504 #if defined(QCA_WIFI_QCA6490) || defined(QCA_WIFI_KIWI)
505 static uint8_t target_if_cfr_get_mac_id(struct wlan_objmgr_pdev *pdev)
506 {
507 	struct wlan_objmgr_vdev *vdev;
508 	struct wlan_channel *bss_chan;
509 	struct pdev_cfr *pcfr;
510 	uint8_t mac_id = 0;
511 
512 	if (!pdev) {
513 		cfr_err("null pdev");
514 		return mac_id;
515 	}
516 
517 	mac_id = wlan_objmgr_pdev_get_pdev_id(pdev);
518 	pcfr = wlan_objmgr_pdev_get_comp_private_obj(pdev, WLAN_UMAC_COMP_CFR);
519 	if (!pcfr)  {
520 		cfr_err("null pcfr");
521 		return mac_id;
522 	}
523 
524 	if (pcfr->rcc_param.vdev_id == CFR_INVALID_VDEV_ID)
525 		return mac_id;
526 
527 	vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev,
528 						    pcfr->rcc_param.vdev_id,
529 						    WLAN_CFR_ID);
530 	if (!vdev) {
531 		cfr_err("null vdev");
532 		return mac_id;
533 	}
534 
535 	bss_chan = wlan_vdev_mlme_get_bss_chan(vdev);
536 	if (!bss_chan) {
537 		cfr_info("null bss chan");
538 		wlan_objmgr_vdev_release_ref(vdev, WLAN_CFR_ID);
539 		return mac_id;
540 	}
541 
542 	cfr_debug("bss freq %d", bss_chan->ch_freq);
543 	if (wlan_reg_is_24ghz_ch_freq(bss_chan->ch_freq))
544 		mac_id = CFR_MAC_ID_24G;
545 	else
546 		mac_id = CFR_MAC_ID_5G;
547 
548 	pcfr->rcc_param.srng_id = mac_id;
549 	wlan_objmgr_vdev_release_ref(vdev, WLAN_CFR_ID);
550 
551 	return mac_id;
552 }
553 
554 static uint8_t target_if_cfr_get_pdev_id(struct wlan_objmgr_pdev *pdev)
555 {
556 	return target_if_cfr_get_mac_id(pdev);
557 }
558 #else
559 static uint8_t target_if_cfr_get_pdev_id(struct wlan_objmgr_pdev *pdev)
560 {
561 	return wlan_objmgr_pdev_get_pdev_id(pdev);
562 }
563 #endif /* QCA_WIFI_QCA6490 || QCA_WIFI_KIWI */
564 
565 QDF_STATUS target_if_cfr_config_rcc(struct wlan_objmgr_pdev *pdev,
566 				    struct cfr_rcc_param *rcc_info)
567 {
568 	QDF_STATUS status;
569 	struct wmi_unified *pdev_wmi_handle = NULL;
570 
571 	pdev_wmi_handle = lmac_get_pdev_wmi_handle(pdev);
572 	if (!pdev_wmi_handle) {
573 		cfr_err("pdev_wmi_handle is null");
574 		return QDF_STATUS_E_NULL_VALUE;
575 	}
576 
577 	rcc_info->pdev_id = target_if_cfr_get_pdev_id(pdev);
578 	rcc_info->num_grp_tlvs =
579 		count_set_bits(rcc_info->modified_in_curr_session);
580 
581 	status = wmi_unified_send_cfr_rcc_cmd(pdev_wmi_handle, rcc_info);
582 	return status;
583 }
584 
585 void target_if_cfr_default_ta_ra_config(struct cfr_rcc_param *rcc_info,
586 					bool allvalid, uint16_t reset_cfg)
587 {
588 	struct ta_ra_cfr_cfg *curr_cfg = NULL;
589 	int grp_id;
590 	unsigned long bitmap = reset_cfg;
591 	uint8_t def_mac[QDF_MAC_ADDR_SIZE] = {0xFF, 0xFF, 0xFF,
592 		0xFF, 0xFF, 0xFF};
593 	uint8_t null_mac[QDF_MAC_ADDR_SIZE] = {0x00, 0x00, 0x00,
594 		0x00, 0x00, 0x00};
595 
596 	for (grp_id = 0; grp_id < MAX_TA_RA_ENTRIES; grp_id++) {
597 		if (qdf_test_bit(grp_id, &bitmap)) {
598 			curr_cfg = &rcc_info->curr[grp_id];
599 			qdf_mem_copy(curr_cfg->tx_addr,
600 				     null_mac, QDF_MAC_ADDR_SIZE);
601 			qdf_mem_copy(curr_cfg->tx_addr_mask,
602 				     def_mac, QDF_MAC_ADDR_SIZE);
603 			qdf_mem_copy(curr_cfg->rx_addr,
604 				     null_mac, QDF_MAC_ADDR_SIZE);
605 			qdf_mem_copy(curr_cfg->rx_addr_mask,
606 				     def_mac, QDF_MAC_ADDR_SIZE);
607 			curr_cfg->bw = 0xf;
608 			curr_cfg->nss = 0xff;
609 			curr_cfg->mgmt_subtype_filter = 0;
610 			curr_cfg->ctrl_subtype_filter = 0;
611 			curr_cfg->data_subtype_filter = 0;
612 			if (!allvalid) {
613 				curr_cfg->valid_ta = 0;
614 				curr_cfg->valid_ta_mask = 0;
615 				curr_cfg->valid_ra = 0;
616 				curr_cfg->valid_ra_mask = 0;
617 				curr_cfg->valid_bw_mask = 0;
618 				curr_cfg->valid_nss_mask = 0;
619 				curr_cfg->valid_mgmt_subtype = 0;
620 				curr_cfg->valid_ctrl_subtype = 0;
621 				curr_cfg->valid_data_subtype = 0;
622 			} else {
623 				curr_cfg->valid_ta = 1;
624 				curr_cfg->valid_ta_mask = 1;
625 				curr_cfg->valid_ra = 1;
626 				curr_cfg->valid_ra_mask = 1;
627 				curr_cfg->valid_bw_mask = 1;
628 				curr_cfg->valid_nss_mask = 1;
629 				curr_cfg->valid_mgmt_subtype = 1;
630 				curr_cfg->valid_ctrl_subtype = 1;
631 				curr_cfg->valid_data_subtype = 1;
632 			}
633 		}
634 	}
635 }
636 #endif
637 
638 #ifdef WLAN_ENH_CFR_ENABLE
639 #ifdef CFR_USE_FIXED_FOLDER
640 static void target_if_enh_cfr_add_ops(struct wlan_lmac_if_tx_ops *tx_ops)
641 {
642 	tx_ops->cfr_tx_ops.cfr_subscribe_ppdu_desc =
643 				target_if_cfr_subscribe_ppdu_desc;
644 }
645 #else
646 static void target_if_enh_cfr_add_ops(struct wlan_lmac_if_tx_ops *tx_ops)
647 {
648 }
649 #endif /* CFR_USE_FIXED_FOLDER */
650 static void target_if_enh_cfr_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
651 {
652 	tx_ops->cfr_tx_ops.cfr_config_rcc =
653 		target_if_cfr_config_rcc;
654 	tx_ops->cfr_tx_ops.cfr_start_lut_timer =
655 		target_if_cfr_start_lut_age_timer;
656 	tx_ops->cfr_tx_ops.cfr_stop_lut_timer =
657 		target_if_cfr_stop_lut_age_timer;
658 	tx_ops->cfr_tx_ops.cfr_default_ta_ra_cfg =
659 		target_if_cfr_default_ta_ra_config;
660 	tx_ops->cfr_tx_ops.cfr_dump_lut_enh =
661 		target_if_cfr_dump_lut_enh;
662 	tx_ops->cfr_tx_ops.cfr_rx_tlv_process =
663 		target_if_cfr_rx_tlv_process;
664 	tx_ops->cfr_tx_ops.cfr_update_global_cfg =
665 		target_if_cfr_update_global_cfg;
666 	target_if_enh_cfr_add_ops(tx_ops);
667 }
668 #else
669 static void target_if_enh_cfr_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
670 {
671 }
672 #endif
673 
674 void target_if_cfr_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
675 {
676 	tx_ops->cfr_tx_ops.cfr_init_pdev =
677 		target_if_cfr_init_pdev;
678 	tx_ops->cfr_tx_ops.cfr_deinit_pdev =
679 		target_if_cfr_deinit_pdev;
680 	tx_ops->cfr_tx_ops.cfr_enable_cfr_timer =
681 		target_if_cfr_enable_cfr_timer;
682 	tx_ops->cfr_tx_ops.cfr_start_capture =
683 		target_if_cfr_start_capture;
684 	tx_ops->cfr_tx_ops.cfr_stop_capture =
685 		target_if_cfr_stop_capture;
686 	target_if_enh_cfr_tx_ops(tx_ops);
687 }
688 
689 void target_if_cfr_set_cfr_support(struct wlan_objmgr_psoc *psoc,
690 				   uint8_t value)
691 {
692 	struct wlan_lmac_if_rx_ops *rx_ops;
693 
694 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
695 	if (!rx_ops) {
696 		cfr_err("rx_ops is NULL");
697 		return;
698 	}
699 	if (rx_ops->cfr_rx_ops.cfr_support_set)
700 		rx_ops->cfr_rx_ops.cfr_support_set(psoc, value);
701 }
702 
703 QDF_STATUS
704 target_if_cfr_set_capture_count_support(struct wlan_objmgr_psoc *psoc,
705 					uint8_t value)
706 {
707 	struct wlan_lmac_if_rx_ops *rx_ops;
708 
709 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
710 	if (!rx_ops) {
711 		cfr_err("rx_ops is NULL");
712 		return QDF_STATUS_E_INVAL;
713 	}
714 
715 	if (rx_ops->cfr_rx_ops.cfr_capture_count_support_set)
716 		return rx_ops->cfr_rx_ops.cfr_capture_count_support_set(
717 						psoc, value);
718 
719 	return QDF_STATUS_E_INVAL;
720 }
721 
722 QDF_STATUS
723 target_if_cfr_set_mo_marking_support(struct wlan_objmgr_psoc *psoc,
724 				     uint8_t value)
725 {
726 	struct wlan_lmac_if_rx_ops *rx_ops;
727 
728 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
729 	if (!rx_ops) {
730 		cfr_err("rx_ops is NULL");
731 		return QDF_STATUS_E_INVAL;
732 	}
733 
734 	if (rx_ops->cfr_rx_ops.cfr_mo_marking_support_set)
735 		return rx_ops->cfr_rx_ops.cfr_mo_marking_support_set(
736 						psoc, value);
737 
738 	return QDF_STATUS_E_INVAL;
739 }
740 
741 QDF_STATUS
742 target_if_cfr_set_aoa_for_rcc_support(struct wlan_objmgr_psoc *psoc,
743 				      uint8_t value)
744 {
745 	struct wlan_lmac_if_rx_ops *rx_ops;
746 
747 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
748 	if (!rx_ops) {
749 		cfr_err("rx_ops is NULL");
750 		return QDF_STATUS_E_INVAL;
751 	}
752 
753 	if (rx_ops->cfr_rx_ops.cfr_aoa_for_rcc_support_set)
754 		return rx_ops->cfr_rx_ops.cfr_aoa_for_rcc_support_set(
755 						psoc, value);
756 
757 	return QDF_STATUS_E_INVAL;
758 }
759 
760 void target_if_cfr_info_send(struct wlan_objmgr_pdev *pdev, void *head,
761 			     size_t hlen, void *data, size_t dlen, void *tail,
762 			     size_t tlen)
763 {
764 	struct wlan_objmgr_psoc *psoc;
765 	struct wlan_lmac_if_rx_ops *rx_ops;
766 
767 	psoc = wlan_pdev_get_psoc(pdev);
768 
769 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
770 	if (!rx_ops) {
771 		cfr_err("rx_ops is NULL");
772 		return;
773 	}
774 	if (rx_ops->cfr_rx_ops.cfr_info_send)
775 		rx_ops->cfr_rx_ops.cfr_info_send(pdev, head, hlen, data, dlen,
776 						 tail, tlen);
777 }
778