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