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