1 /*
2  * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /**
19  * DOC: This file contains definitions for target_if roaming offload.
20  */
21 
22 #include "qdf_types.h"
23 #include "target_if_cm_roam_offload.h"
24 #include "target_if.h"
25 #include "wmi_unified_sta_api.h"
26 #include "wlan_mlme_dbg.h"
27 #include "wlan_mlme_api.h"
28 #include "wlan_crypto_global_api.h"
29 #include "wlan_mlme_main.h"
30 #include "wlan_cm_roam_api.h"
31 #include <target_if_vdev_mgr_rx_ops.h>
32 #include <target_if_vdev_mgr_tx_ops.h>
33 #include "target_if_cm_roam_event.h"
34 #include <target_if_psoc_wake_lock.h>
35 #include "wlan_psoc_mlme_api.h"
36 
37 static struct wmi_unified
target_if_cm_roam_get_wmi_handle_from_vdev(struct wlan_objmgr_vdev * vdev)38 *target_if_cm_roam_get_wmi_handle_from_vdev(struct wlan_objmgr_vdev *vdev)
39 {
40 	struct wlan_objmgr_pdev *pdev;
41 	struct wmi_unified *wmi_handle;
42 
43 	pdev = wlan_vdev_get_pdev(vdev);
44 	if (!pdev) {
45 		target_if_err("PDEV is NULL");
46 		return NULL;
47 	}
48 
49 	wmi_handle = get_wmi_unified_hdl_from_pdev(pdev);
50 	if (!wmi_handle) {
51 		target_if_err("wmi_handle is null");
52 		return NULL;
53 	}
54 
55 	return wmi_handle;
56 }
57 
58 #ifdef WLAN_FEATURE_ROAM_OFFLOAD
59 /**
60  * target_if_cm_roam_send_vdev_set_pcl_cmd  - Send set vdev pcl
61  * command to wmi.
62  * @vdev: VDEV object pointer
63  * @req:  Pointer to the pcl request msg
64  *
65  * Return: QDF_STATUS
66  */
67 static QDF_STATUS
target_if_cm_roam_send_vdev_set_pcl_cmd(struct wlan_objmgr_vdev * vdev,struct set_pcl_req * req)68 target_if_cm_roam_send_vdev_set_pcl_cmd(struct wlan_objmgr_vdev *vdev,
69 					struct set_pcl_req *req)
70 {
71 	wmi_unified_t wmi_handle;
72 	struct set_pcl_cmd_params params;
73 
74 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
75 	if (!wmi_handle)
76 		return QDF_STATUS_E_FAILURE;
77 
78 	params.weights = &req->chan_weights;
79 	params.vdev_id = req->vdev_id;
80 
81 	return wmi_unified_vdev_set_pcl_cmd(wmi_handle, &params);
82 }
83 
84 /**
85  * target_if_cm_roam_send_roam_invoke_cmd  - Send roam invoke command to wmi.
86  * @vdev: VDEV object pointer
87  * @req:  Pointer to the roam invoke request msg
88  *
89  * Return: QDF_STATUS
90  */
91 static QDF_STATUS
target_if_cm_roam_send_roam_invoke_cmd(struct wlan_objmgr_vdev * vdev,struct roam_invoke_req * req)92 target_if_cm_roam_send_roam_invoke_cmd(struct wlan_objmgr_vdev *vdev,
93 				       struct roam_invoke_req *req)
94 {
95 	wmi_unified_t wmi_handle;
96 
97 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
98 	if (!wmi_handle)
99 		return QDF_STATUS_E_FAILURE;
100 
101 	return wmi_unified_roam_invoke_cmd(wmi_handle, req);
102 }
103 
104 /**
105  * target_if_cm_roam_send_roam_sync_complete  - Send roam sync complete to wmi.
106  * @vdev: VDEV object pointer
107  *
108  * Return: QDF_STATUS
109  */
110 static QDF_STATUS
target_if_cm_roam_send_roam_sync_complete(struct wlan_objmgr_vdev * vdev)111 target_if_cm_roam_send_roam_sync_complete(struct wlan_objmgr_vdev *vdev)
112 {
113 	wmi_unified_t wmi_handle;
114 	QDF_STATUS status;
115 	struct wlan_objmgr_psoc *psoc;
116 
117 	psoc = wlan_vdev_get_psoc(vdev);
118 	if (!psoc) {
119 		target_if_err("psoc handle is NULL");
120 		return QDF_STATUS_E_FAILURE;
121 	}
122 
123 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
124 	if (!wmi_handle)
125 		return QDF_STATUS_E_FAILURE;
126 
127 	status = wmi_unified_roam_synch_complete_cmd(wmi_handle,
128 						     wlan_vdev_get_id(vdev));
129 	target_if_allow_pm_after_roam_sync(psoc);
130 
131 	return status;
132 }
133 
134 /**
135  * target_if_roam_set_param() - set roam params in fw
136  * @wmi_handle: wmi handle
137  * @vdev_id: vdev id
138  * @param_id: parameter id
139  * @param_value: parameter value
140  *
141  * Return: QDF_STATUS_SUCCESS for success or error code
142  */
143 static QDF_STATUS
target_if_roam_set_param(wmi_unified_t wmi_handle,uint8_t vdev_id,uint32_t param_id,uint32_t param_value)144 target_if_roam_set_param(wmi_unified_t wmi_handle, uint8_t vdev_id,
145 			 uint32_t param_id, uint32_t param_value)
146 {
147 	struct vdev_set_params roam_param = {0};
148 
149 	roam_param.vdev_id = vdev_id;
150 	roam_param.param_id = param_id;
151 	roam_param.param_value = param_value;
152 
153 	return wmi_unified_roam_set_param_send(wmi_handle, &roam_param);
154 }
155 
156 /**
157  * target_if_cm_roam_rt_stats_config() - Send enable/disable roam event stats
158  * commands to wmi
159  * @vdev: vdev object
160  * @vdev_id: vdev id
161  * @rstats_config: roam event stats config parameters
162  *
163  * Return: QDF_STATUS
164  */
165 static QDF_STATUS
target_if_cm_roam_rt_stats_config(struct wlan_objmgr_vdev * vdev,uint8_t vdev_id,uint8_t rstats_config)166 target_if_cm_roam_rt_stats_config(struct wlan_objmgr_vdev *vdev,
167 				  uint8_t vdev_id, uint8_t rstats_config)
168 {
169 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
170 	wmi_unified_t wmi_handle;
171 
172 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
173 	if (!wmi_handle)
174 		return status;
175 
176 	status = target_if_roam_set_param(wmi_handle,
177 					  vdev_id,
178 					  WMI_ROAM_PARAM_ROAM_EVENTS_CONFIG,
179 					  rstats_config);
180 
181 	if (QDF_IS_STATUS_ERROR(status))
182 		target_if_err("Failed to set "
183 			      "WMI_ROAM_PARAM_ROAM_EVENTS_CONFIG");
184 
185 	return status;
186 }
187 
188 /**
189  * target_if_cm_roam_mcc_disallow() - Send enable/disable roam mcc disallow
190  * commands to wmi
191  * @vdev: vdev object
192  * @vdev_id: vdev id
193  * @is_mcc_disallowed: is mcc disallowed
194  *
195  * Return: QDF_STATUS
196  */
197 static QDF_STATUS
target_if_cm_roam_mcc_disallow(struct wlan_objmgr_vdev * vdev,uint8_t vdev_id,uint8_t is_mcc_disallowed)198 target_if_cm_roam_mcc_disallow(struct wlan_objmgr_vdev *vdev,
199 			       uint8_t vdev_id, uint8_t is_mcc_disallowed)
200 {
201 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
202 	wmi_unified_t wmi_handle;
203 
204 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
205 	if (!wmi_handle)
206 		return status;
207 
208 	status = target_if_roam_set_param(wmi_handle,
209 					  vdev_id,
210 					  WMI_ROAM_PARAM_ROAM_MCC_DISALLOW,
211 					  is_mcc_disallowed);
212 
213 	if (QDF_IS_STATUS_ERROR(status))
214 		target_if_err("Failed to set roam mcc disallow");
215 
216 	return status;
217 }
218 
219 #ifdef FEATURE_RX_LINKSPEED_ROAM_TRIGGER
220 /**
221  * target_if_cm_roam_linkspeed_state() - Send link speed state for roaming
222  * commands to wmi
223  * @vdev: vdev object
224  * @vdev_id: vdev id
225  * @is_linkspeed_good: true, don't need low rssi roaming
226  *
227  * Return: QDF_STATUS
228  */
229 static QDF_STATUS
target_if_cm_roam_linkspeed_state(struct wlan_objmgr_vdev * vdev,uint8_t vdev_id,bool is_linkspeed_good)230 target_if_cm_roam_linkspeed_state(struct wlan_objmgr_vdev *vdev,
231 				  uint8_t vdev_id, bool is_linkspeed_good)
232 {
233 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
234 	wmi_unified_t wmi_handle;
235 
236 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
237 	if (!wmi_handle)
238 		return status;
239 
240 	status = target_if_roam_set_param(wmi_handle,
241 					  vdev_id,
242 					  WMI_ROAM_PARAM_LINKSPEED_STATE,
243 					  is_linkspeed_good);
244 
245 	if (QDF_IS_STATUS_ERROR(status))
246 		target_if_err("Failed to set WMI_ROAM_PARAM_LINKSPEED_STATE");
247 
248 	return status;
249 }
250 #else
251 static inline QDF_STATUS
target_if_cm_roam_linkspeed_state(struct wlan_objmgr_vdev * vdev,uint8_t vdev_id,bool is_linkspeed_good)252 target_if_cm_roam_linkspeed_state(struct wlan_objmgr_vdev *vdev,
253 				  uint8_t vdev_id, bool is_linkspeed_good)
254 {
255 	return QDF_STATUS_SUCCESS;
256 }
257 #endif
258 
259 #ifdef WLAN_VENDOR_HANDOFF_CONTROL
260 /**
261  * target_if_cm_roam_vendor_handoff_config() - Send vendor handoff config
262  * command to fw
263  * @vdev: vdev object
264  * @vdev_id: vdev id
265  * @param_id: param id
266  *
267  * Return: QDF_STATUS
268  */
269 static QDF_STATUS
target_if_cm_roam_vendor_handoff_config(struct wlan_objmgr_vdev * vdev,uint8_t vdev_id,uint32_t param_id)270 target_if_cm_roam_vendor_handoff_config(struct wlan_objmgr_vdev *vdev,
271 					uint8_t vdev_id, uint32_t param_id)
272 {
273 	wmi_unified_t wmi_handle;
274 
275 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
276 	if (!wmi_handle)
277 		return QDF_STATUS_E_FAILURE;
278 
279 	return wmi_unified_roam_vendor_handoff_req_cmd(wmi_handle,
280 						       vdev_id, param_id);
281 }
282 
283 /**
284  * target_if_cm_roam_register_vendor_handoff_ops() - Register tx ops to send
285  * vendor handoff config command to fw
286  * @tx_ops: structure of tx function pointers for roaming related commands
287  *
288  * Return: none
289  */
target_if_cm_roam_register_vendor_handoff_ops(struct wlan_cm_roam_tx_ops * tx_ops)290 static void target_if_cm_roam_register_vendor_handoff_ops(
291 					struct wlan_cm_roam_tx_ops *tx_ops)
292 {
293 	tx_ops->send_roam_vendor_handoff_config =
294 				target_if_cm_roam_vendor_handoff_config;
295 }
296 #else
target_if_cm_roam_register_vendor_handoff_ops(struct wlan_cm_roam_tx_ops * tx_ops)297 static inline void target_if_cm_roam_register_vendor_handoff_ops(
298 					struct wlan_cm_roam_tx_ops *tx_ops)
299 {
300 }
301 #endif
302 
303 #ifdef FEATURE_RX_LINKSPEED_ROAM_TRIGGER
304 /**
305  * target_if_cm_roam_register_linkspeed_state() - Register tx ops to send
306  * roam link speed state command to fw
307  * @tx_ops: structure of tx function pointers for roaming related commands
308  *
309  * Return: none
310  */
311 static inline void
target_if_cm_roam_register_linkspeed_state(struct wlan_cm_roam_tx_ops * tx_ops)312 target_if_cm_roam_register_linkspeed_state(struct wlan_cm_roam_tx_ops *tx_ops)
313 {
314 	tx_ops->send_roam_linkspeed_state =
315 				target_if_cm_roam_linkspeed_state;
316 }
317 #else
318 static inline void
target_if_cm_roam_register_linkspeed_state(struct wlan_cm_roam_tx_ops * tx_ops)319 target_if_cm_roam_register_linkspeed_state(struct wlan_cm_roam_tx_ops *tx_ops)
320 {
321 }
322 #endif
323 
324 /**
325  * target_if_cm_roam_ho_delay_config() - Send roam HO delay value to wmi
326  * @vdev: vdev object
327  * @vdev_id: vdev id
328  * @roam_ho_delay: roam hand-off delay value
329  *
330  * Return: QDF_STATUS
331  */
332 static QDF_STATUS
target_if_cm_roam_ho_delay_config(struct wlan_objmgr_vdev * vdev,uint8_t vdev_id,uint16_t roam_ho_delay)333 target_if_cm_roam_ho_delay_config(struct wlan_objmgr_vdev *vdev,
334 				  uint8_t vdev_id, uint16_t roam_ho_delay)
335 {
336 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
337 	wmi_unified_t wmi_handle;
338 
339 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
340 	if (!wmi_handle)
341 		return status;
342 
343 	status = target_if_roam_set_param(
344 				wmi_handle,
345 				vdev_id,
346 				WMI_ROAM_PARAM_ROAM_HO_DELAY_RUNTIME_CONFIG,
347 				roam_ho_delay);
348 
349 	if (QDF_IS_STATUS_ERROR(status))
350 		target_if_err("Failed to set "
351 			      "WMI_ROAM_PARAM_ROAM_HO_DELAY_RUNTIME_CONFIG");
352 
353 	return status;
354 }
355 
356 /**
357  * target_if_cm_exclude_rm_partial_scan_freq() - Indicate to FW whether to
358  * exclude the channels in roam full scan that are already scanned as part of
359  * partial scan or not.
360  * @vdev: vdev object
361  * @exclude_rm_partial_scan_freq: Include/exclude the channels in roam full scan
362  * that are already scanned as part of partial scan.
363  *
364  * Return: QDF_STATUS
365  */
366 static QDF_STATUS
target_if_cm_exclude_rm_partial_scan_freq(struct wlan_objmgr_vdev * vdev,uint8_t exclude_rm_partial_scan_freq)367 target_if_cm_exclude_rm_partial_scan_freq(struct wlan_objmgr_vdev *vdev,
368 					  uint8_t exclude_rm_partial_scan_freq)
369 {
370 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
371 	uint8_t vdev_id;
372 	wmi_unified_t wmi_handle;
373 
374 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
375 	if (!wmi_handle)
376 		return status;
377 
378 	vdev_id = wlan_vdev_get_id(vdev);
379 	status = target_if_roam_set_param(
380 				wmi_handle, vdev_id,
381 				WMI_ROAM_PARAM_ROAM_CONTROL_FULL_SCAN_CHANNEL_OPTIMIZATION,
382 				exclude_rm_partial_scan_freq);
383 
384 	if (QDF_IS_STATUS_ERROR(status))
385 		target_if_err("Failed to set WMI_ROAM_PARAM_ROAM_CONTROL_FULL_SCAN_CHANNEL_OPTIMIZATION");
386 
387 	return status;
388 }
389 
390 /**
391  * target_if_cm_roam_full_scan_6ghz_on_disc() - Indicate to FW whether to
392  * include the 6 GHz channels in roam full scan only on prior discovery of any
393  * 6 GHz support in the environment or by default.
394  * @vdev: vdev object
395  * @roam_full_scan_6ghz_on_disc: Include the 6 GHz channels in roam full scan:
396  * 1 - Include only on prior discovery of any 6 GHz support in the environment
397  * 0 - Include all the supported 6 GHz channels by default
398  *
399  * Return: QDF_STATUS
400  */
401 static QDF_STATUS
target_if_cm_roam_full_scan_6ghz_on_disc(struct wlan_objmgr_vdev * vdev,uint8_t roam_full_scan_6ghz_on_disc)402 target_if_cm_roam_full_scan_6ghz_on_disc(struct wlan_objmgr_vdev *vdev,
403 					 uint8_t roam_full_scan_6ghz_on_disc)
404 {
405 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
406 	uint8_t vdev_id;
407 	wmi_unified_t wmi_handle;
408 
409 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
410 	if (!wmi_handle)
411 		return status;
412 
413 	vdev_id = wlan_vdev_get_id(vdev);
414 	status = target_if_roam_set_param(wmi_handle, vdev_id,
415 					  WMI_ROAM_PARAM_ROAM_CONTROL_FULL_SCAN_6GHZ_PSC_ONLY_WITH_RNR,
416 					  roam_full_scan_6ghz_on_disc);
417 
418 	if (QDF_IS_STATUS_ERROR(status))
419 		target_if_err("Failed to set WMI_ROAM_PARAM_ROAM_CONTROL_FULL_SCAN_6GHZ_PSC_ONLY_WITH_RNR");
420 
421 	return status;
422 }
423 
424 /**
425  * target_if_cm_roam_rssi_diff_6ghz() - Send the roam RSSI diff value to FW
426  * which is used to decide how better the RSSI of the new/roamable 6GHz AP
427  * should be for roaming.
428  * @vdev: vdev object
429  * @roam_rssi_diff_6ghz: RSSI diff value to be used for roaming to 6 GHz AP
430  *
431  * Return: QDF_STATUS
432  */
433 static QDF_STATUS
target_if_cm_roam_rssi_diff_6ghz(struct wlan_objmgr_vdev * vdev,uint8_t roam_rssi_diff_6ghz)434 target_if_cm_roam_rssi_diff_6ghz(struct wlan_objmgr_vdev *vdev,
435 				 uint8_t roam_rssi_diff_6ghz)
436 {
437 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
438 	uint8_t vdev_id;
439 	wmi_unified_t wmi_handle;
440 
441 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
442 	if (!wmi_handle)
443 		return status;
444 
445 	vdev_id = wlan_vdev_get_id(vdev);
446 	status = target_if_roam_set_param(
447 				wmi_handle, vdev_id,
448 				WMI_ROAM_PARAM_ROAM_RSSI_BOOST_FOR_6GHZ_CAND_AP,
449 				roam_rssi_diff_6ghz);
450 
451 	if (QDF_IS_STATUS_ERROR(status))
452 		target_if_err("Failed to set WMI_ROAM_PARAM_ROAM_RSSI_BOOST_FOR_6GHZ_CAND_AP");
453 
454 	return status;
455 }
456 
457 static QDF_STATUS
458 target_if_cm_roam_scan_offload_rssi_thresh(
459 				wmi_unified_t wmi_handle,
460 				struct wlan_roam_offload_scan_rssi_params *req);
461 
462 /**
463  * target_if_cm_roam_scan_offload_rssi_params() - Set the RSSI parameters
464  * for roam offload scan
465  * @vdev: vdev object
466  * @roam_rssi_params: structure containing parameters for roam offload scan
467  * based on RSSI
468  *
469  * Return: QDF_STATUS
470  */
471 static QDF_STATUS
target_if_cm_roam_scan_offload_rssi_params(struct wlan_objmgr_vdev * vdev,struct wlan_roam_offload_scan_rssi_params * roam_rssi_params)472 target_if_cm_roam_scan_offload_rssi_params(
473 		struct wlan_objmgr_vdev *vdev,
474 		struct wlan_roam_offload_scan_rssi_params *roam_rssi_params)
475 {
476 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
477 	wmi_unified_t wmi_handle;
478 
479 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
480 	if (!wmi_handle)
481 		return status;
482 
483 	status = target_if_cm_roam_scan_offload_rssi_thresh(wmi_handle,
484 							    roam_rssi_params);
485 
486 	return status;
487 }
488 
489 static void
target_if_check_hi_rssi_5ghz_support(wmi_unified_t wmi_handle,struct wlan_roam_offload_scan_rssi_params * roam_rssi_params)490 target_if_check_hi_rssi_5ghz_support(
491 		wmi_unified_t wmi_handle,
492 		struct wlan_roam_offload_scan_rssi_params *roam_rssi_params)
493 {
494 	if ((roam_rssi_params->flags &
495 	     ROAM_SCAN_RSSI_THRESHOLD_FLAG_ROAM_HI_RSSI_EN_ON_5G) &&
496 	    wmi_service_enabled(wmi_handle,
497 				wmi_service_5ghz_hi_rssi_roam_support)) {
498 		target_if_debug("FW supports Hi RSSI roam in 5 GHz");
499 		roam_rssi_params->flags |=
500 			WMI_ROAM_SCAN_RSSI_THRESHOLD_FLAG_ROAM_HI_RSSI_EN_ON_5G;
501 	} else {
502 		roam_rssi_params->flags &=
503 			~ROAM_SCAN_RSSI_THRESHOLD_FLAG_ROAM_HI_RSSI_EN_ON_5G;
504 	}
505 }
506 
507 static void
target_if_cm_roam_register_lfr3_ops(struct wlan_cm_roam_tx_ops * tx_ops)508 target_if_cm_roam_register_lfr3_ops(struct wlan_cm_roam_tx_ops *tx_ops)
509 {
510 	tx_ops->send_vdev_set_pcl_cmd = target_if_cm_roam_send_vdev_set_pcl_cmd;
511 	tx_ops->send_roam_invoke_cmd = target_if_cm_roam_send_roam_invoke_cmd;
512 	tx_ops->send_roam_sync_complete_cmd = target_if_cm_roam_send_roam_sync_complete;
513 	tx_ops->send_roam_rt_stats_config = target_if_cm_roam_rt_stats_config;
514 	tx_ops->send_roam_ho_delay_config = target_if_cm_roam_ho_delay_config;
515 	tx_ops->send_roam_mcc_disallow = target_if_cm_roam_mcc_disallow;
516 	tx_ops->send_exclude_rm_partial_scan_freq =
517 				target_if_cm_exclude_rm_partial_scan_freq;
518 	tx_ops->send_roam_full_scan_6ghz_on_disc =
519 				target_if_cm_roam_full_scan_6ghz_on_disc;
520 	tx_ops->send_roam_scan_offload_rssi_params =
521 				target_if_cm_roam_scan_offload_rssi_params;
522 	target_if_cm_roam_register_vendor_handoff_ops(tx_ops);
523 	target_if_cm_roam_register_linkspeed_state(tx_ops);
524 }
525 #else
526 static inline void
target_if_cm_roam_register_lfr3_ops(struct wlan_cm_roam_tx_ops * tx_ops)527 target_if_cm_roam_register_lfr3_ops(struct wlan_cm_roam_tx_ops *tx_ops)
528 {}
529 
530 static QDF_STATUS
target_if_cm_roam_rt_stats_config(struct wlan_objmgr_vdev * vdev,uint8_t vdev_id,uint8_t rstats_config)531 target_if_cm_roam_rt_stats_config(struct wlan_objmgr_vdev *vdev,
532 				  uint8_t vdev_id, uint8_t rstats_config)
533 {
534 	return QDF_STATUS_E_NOSUPPORT;
535 }
536 
537 static QDF_STATUS
target_if_cm_roam_ho_delay_config(struct wlan_objmgr_vdev * vdev,uint8_t vdev_id,uint16_t roam_ho_delay)538 target_if_cm_roam_ho_delay_config(struct wlan_objmgr_vdev *vdev,
539 				  uint8_t vdev_id, uint16_t roam_ho_delay)
540 {
541 	return QDF_STATUS_E_NOSUPPORT;
542 }
543 
544 static QDF_STATUS
target_if_cm_roam_mcc_disallow(struct wlan_objmgr_vdev * vdev,uint8_t vdev_id,uint8_t is_mcc_disallowed)545 target_if_cm_roam_mcc_disallow(struct wlan_objmgr_vdev *vdev,
546 			       uint8_t vdev_id, uint8_t is_mcc_disallowed)
547 {
548 	return QDF_STATUS_E_NOSUPPORT;
549 }
550 
551 static QDF_STATUS
target_if_cm_exclude_rm_partial_scan_freq(struct wlan_objmgr_vdev * vdev,uint8_t exclude_rm_partial_scan_freq)552 target_if_cm_exclude_rm_partial_scan_freq(struct wlan_objmgr_vdev *vdev,
553 					  uint8_t exclude_rm_partial_scan_freq)
554 {
555 	return QDF_STATUS_E_NOSUPPORT;
556 }
557 
558 static QDF_STATUS
target_if_cm_roam_full_scan_6ghz_on_disc(struct wlan_objmgr_vdev * vdev,uint8_t roam_full_scan_6ghz_on_disc)559 target_if_cm_roam_full_scan_6ghz_on_disc(struct wlan_objmgr_vdev *vdev,
560 					 uint8_t roam_full_scan_6ghz_on_disc)
561 {
562 	return QDF_STATUS_E_NOSUPPORT;
563 }
564 
565 static QDF_STATUS
target_if_cm_roam_rssi_diff_6ghz(struct wlan_objmgr_vdev * vdev,uint8_t roam_rssi_diff_6ghz)566 target_if_cm_roam_rssi_diff_6ghz(struct wlan_objmgr_vdev *vdev,
567 				 uint8_t roam_rssi_diff_6ghz)
568 {
569 	return QDF_STATUS_E_NOSUPPORT;
570 }
571 
572 static inline void
target_if_check_hi_rssi_5ghz_support(wmi_unified_t wmi_handle,struct wlan_roam_offload_scan_rssi_params * roam_rssi_params)573 target_if_check_hi_rssi_5ghz_support(
574 		wmi_unified_t wmi_handle,
575 		struct wlan_roam_offload_scan_rssi_params *roam_rssi_params)
576 {}
577 #endif
578 
579 /**
580  * target_if_vdev_set_param() - set per vdev params in fw
581  * @wmi_handle: wmi handle
582  * @vdev_id: vdev id
583  * @param_id: parameter id
584  * @param_value: parameter value
585  *
586  * Return: QDF_STATUS_SUCCESS for success or error code
587  */
588 static QDF_STATUS
target_if_vdev_set_param(wmi_unified_t wmi_handle,uint32_t vdev_id,uint32_t param_id,uint32_t param_value)589 target_if_vdev_set_param(wmi_unified_t wmi_handle, uint32_t vdev_id,
590 			 uint32_t param_id, uint32_t param_value)
591 {
592 	struct vdev_set_params param = {0};
593 
594 	if (!target_if_is_vdev_valid(vdev_id)) {
595 		target_if_err("vdev_id: %d is invalid, reject the req: param id %d val %d",
596 			      vdev_id, param_id, param_value);
597 		return QDF_STATUS_E_INVAL;
598 	}
599 
600 	param.vdev_id = vdev_id;
601 	param.param_id = param_id;
602 	param.param_value = param_value;
603 
604 	return wmi_unified_vdev_set_param_send(wmi_handle, &param);
605 }
606 
target_if_cm_roam_scan_offload_mode(wmi_unified_t wmi_handle,struct wlan_roam_scan_offload_params * rso_mode_cfg)607 static QDF_STATUS target_if_cm_roam_scan_offload_mode(
608 			wmi_unified_t wmi_handle,
609 			struct wlan_roam_scan_offload_params *rso_mode_cfg)
610 {
611 	return wmi_unified_roam_scan_offload_mode_cmd(wmi_handle,
612 						      rso_mode_cfg);
613 }
614 
615 static
target_if_check_index_setparam(struct dev_set_param * param,uint32_t paramid,uint32_t paramvalue,uint8_t index,uint8_t n_params)616 QDF_STATUS target_if_check_index_setparam(struct dev_set_param *param,
617 					  uint32_t paramid,
618 					  uint32_t paramvalue,
619 					  uint8_t index, uint8_t n_params)
620 {
621 	if (index >= n_params) {
622 		target_if_err("Index:%d OOB to fill param", index);
623 		return QDF_STATUS_E_FAILURE;
624 	}
625 	param[index].param_id = paramid;
626 	param[index].param_value = paramvalue;
627 	return QDF_STATUS_SUCCESS;
628 }
629 
630 #define MAX_PARAMS_CM_ROAM_SCAN_BMISS 2
631 /*
632  * params being sent:
633  * wmi_vdev_param_bmiss_first_bcnt
634  * wmi_vdev_param_bmiss_final_bcnt
635  */
636 
637 /**
638  * target_if_cm_roam_scan_bmiss_cnt() - set bmiss count to fw
639  * @wmi_handle: wmi handle
640  * @req: bmiss count parameters
641  *
642  * Set first & final bmiss count to fw.
643  *
644  * Return: QDF status
645  */
646 static QDF_STATUS
target_if_cm_roam_scan_bmiss_cnt(wmi_unified_t wmi_handle,struct wlan_roam_beacon_miss_cnt * req)647 target_if_cm_roam_scan_bmiss_cnt(wmi_unified_t wmi_handle,
648 				 struct wlan_roam_beacon_miss_cnt *req)
649 {
650 	QDF_STATUS status;
651 	struct dev_set_param setparam[MAX_PARAMS_CM_ROAM_SCAN_BMISS];
652 	struct set_multiple_pdev_vdev_param params = {};
653 	uint8_t index = 0;
654 
655 	target_if_debug("vdev_id:%d, first_bcnt: %d, final_bcnt: %d",
656 			req->vdev_id, req->roam_bmiss_first_bcnt,
657 			req->roam_bmiss_final_bcnt);
658 
659 	status = target_if_check_index_setparam(
660 					   setparam,
661 					   wmi_vdev_param_bmiss_first_bcnt,
662 					   req->roam_bmiss_first_bcnt,
663 					   index++,
664 					   MAX_PARAMS_CM_ROAM_SCAN_BMISS);
665 	if (QDF_IS_STATUS_ERROR(status))
666 		goto error;
667 
668 	status = target_if_check_index_setparam(
669 					   setparam,
670 					   wmi_vdev_param_bmiss_final_bcnt,
671 					   req->roam_bmiss_final_bcnt, index++,
672 					   MAX_PARAMS_CM_ROAM_SCAN_BMISS);
673 	if (QDF_IS_STATUS_ERROR(status))
674 		goto error;
675 
676 	params.param_type = MLME_VDEV_SETPARAM;
677 	params.dev_id = req->vdev_id;
678 	params.n_params = index;
679 	params.params = setparam;
680 
681 	status = wmi_unified_multiple_vdev_param_send(wmi_handle, &params);
682 	if (QDF_IS_STATUS_ERROR(status))
683 		target_if_err("failed to set bmiss first,final bcntset params");
684 
685 error:
686 	return status;
687 }
688 
689 #define MAX_PARAMS_CM_ROAM_SCAN_BMISS_TIMEOUT 2
690 /*
691  * params being sent:
692  * wmi_vdev_param_bmiss_first_bcnt
693  * wmi_vdev_param_bmiss_final_bcnt
694  */
695 
696 /**
697  * target_if_cm_roam_scan_bmiss_timeout() - set conbmiss timeout to fw
698  * @wmi_handle: wmi handle
699  * @req: bmiss timeout parameters
700  *
701  * Set bmiss timeout to fw.
702  *
703  * Return: QDF status
704  */
705 static QDF_STATUS
target_if_cm_roam_scan_bmiss_timeout(wmi_unified_t wmi_handle,struct wlan_roam_bmiss_timeout * req)706 target_if_cm_roam_scan_bmiss_timeout(wmi_unified_t wmi_handle,
707 				     struct wlan_roam_bmiss_timeout *req)
708 {
709 	QDF_STATUS status;
710 	uint32_t vdev_id;
711 	uint8_t bmiss_timeout_onwakeup;
712 	uint8_t bmiss_timeout_onsleep;
713 	struct dev_set_param setparam[MAX_PARAMS_CM_ROAM_SCAN_BMISS_TIMEOUT];
714 	struct set_multiple_pdev_vdev_param params = {};
715 	uint8_t index = 0;
716 
717 	vdev_id = req->vdev_id;
718 	bmiss_timeout_onwakeup = req->bmiss_timeout_onwakeup;
719 	bmiss_timeout_onsleep = req->bmiss_timeout_onsleep;
720 
721 	target_if_debug("vdev_id %d bmiss_timeout_onwakeup: %dsec, bmiss_timeout_onsleep: %dsec", vdev_id,
722 			bmiss_timeout_onwakeup, bmiss_timeout_onsleep);
723 	status = target_if_check_index_setparam(
724 					setparam,
725 					wmi_vdev_param_final_bmiss_time_sec,
726 					req->bmiss_timeout_onwakeup, index++,
727 					MAX_PARAMS_CM_ROAM_SCAN_BMISS_TIMEOUT);
728 	if (QDF_IS_STATUS_ERROR(status))
729 		goto error;
730 
731 	status = target_if_check_index_setparam(
732 					setparam,
733 					wmi_vdev_param_final_bmiss_time_wow_sec,
734 					req->bmiss_timeout_onsleep, index++,
735 					MAX_PARAMS_CM_ROAM_SCAN_BMISS_TIMEOUT);
736 	if (QDF_IS_STATUS_ERROR(status))
737 		goto error;
738 
739 	params.param_type = MLME_VDEV_SETPARAM;
740 	params.dev_id = req->vdev_id;
741 	params.n_params = index;
742 	params.params = setparam;
743 	status = wmi_unified_multiple_vdev_param_send(wmi_handle, &params);
744 	if (QDF_IS_STATUS_ERROR(status))
745 		target_if_err("failed to set bmiss first,final bcntset params");
746 
747 error:
748 	return status;
749 }
750 
751 #ifdef WLAN_FEATURE_ROAM_OFFLOAD
752 /**
753  * target_if_cm_roam_reason_vsie() - set vdev param
754  * wmi_vdev_param_enable_disable_roam_reason_vsie
755  * @wmi_handle: handle to WMI
756  * @req: roam reason vsie enable parameters
757  *
758  * Return: void
759  */
760 static void
target_if_cm_roam_reason_vsie(wmi_unified_t wmi_handle,struct wlan_roam_reason_vsie_enable * req)761 target_if_cm_roam_reason_vsie(wmi_unified_t wmi_handle,
762 			      struct wlan_roam_reason_vsie_enable *req)
763 {
764 	QDF_STATUS status;
765 
766 	status = target_if_vdev_set_param(
767 				wmi_handle,
768 				req->vdev_id,
769 				wmi_vdev_param_enable_disable_roam_reason_vsie,
770 				req->enable_roam_reason_vsie);
771 
772 	if (QDF_IS_STATUS_ERROR(status))
773 		target_if_err("Failed to set vdev param %d",
774 			      wmi_vdev_param_enable_disable_roam_reason_vsie);
775 }
776 
777 /**
778  * target_if_cm_roam_triggers() - send roam triggers to WMI
779  * @vdev: vdev
780  * @req: roam triggers parameters
781  *
782  * Return: QDF status
783  */
784 static QDF_STATUS
target_if_cm_roam_triggers(struct wlan_objmgr_vdev * vdev,struct wlan_roam_triggers * req)785 target_if_cm_roam_triggers(struct wlan_objmgr_vdev *vdev,
786 			   struct wlan_roam_triggers *req)
787 {
788 	wmi_unified_t wmi_handle;
789 
790 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
791 	if (!wmi_handle)
792 		return QDF_STATUS_E_FAILURE;
793 
794 	if (!target_if_is_vdev_valid(req->vdev_id))
795 		return QDF_STATUS_E_INVAL;
796 
797 	return wmi_unified_set_roam_triggers(wmi_handle, req);
798 }
799 
800 /**
801  * target_if_cm_roam_scan_get_cckm_mode() - Get the CCKM auth mode
802  * @vdev: vdev object
803  * @auth_mode: Auth mode to be converted
804  *
805  * Based on LFR2.0 or LFR3.0, return the proper auth type
806  *
807  * Return: if LFR2.0, then return WMI_AUTH_CCKM for backward compatibility
808  *         if LFR3.0 then return the appropriate auth type
809  */
810 static uint32_t
target_if_cm_roam_scan_get_cckm_mode(struct wlan_objmgr_vdev * vdev,uint32_t auth_mode)811 target_if_cm_roam_scan_get_cckm_mode(struct wlan_objmgr_vdev *vdev,
812 				     uint32_t auth_mode)
813 {
814 	struct wlan_objmgr_psoc *psoc;
815 	bool roam_offload_enable;
816 
817 	psoc = wlan_vdev_get_psoc(vdev);
818 	if (!psoc) {
819 		target_if_err("psoc handle is NULL");
820 		return WMI_AUTH_CCKM;
821 	}
822 
823 	wlan_mlme_get_roaming_offload(psoc, &roam_offload_enable);
824 	if (roam_offload_enable)
825 		return auth_mode;
826 	else
827 		return WMI_AUTH_CCKM;
828 }
829 
830 /* target_if_cm_roam_disconnect_params(): Send the disconnect roam parameters
831  * to wmi
832  * @wmi_handle: handle to WMI
833  * @command: rso command
834  * @req: disconnect roam parameters
835  *
836  * Return: void
837  */
838 static void
target_if_cm_roam_disconnect_params(wmi_unified_t wmi_handle,uint8_t command,struct wlan_roam_disconnect_params * req)839 target_if_cm_roam_disconnect_params(wmi_unified_t wmi_handle, uint8_t command,
840 				    struct wlan_roam_disconnect_params *req)
841 {
842 	QDF_STATUS status;
843 
844 	switch (command) {
845 	case ROAM_SCAN_OFFLOAD_START:
846 	case ROAM_SCAN_OFFLOAD_UPDATE_CFG:
847 		if (!req->enable)
848 			return;
849 		break;
850 	case ROAM_SCAN_OFFLOAD_STOP:
851 		req->enable = false;
852 		break;
853 	default:
854 		break;
855 	}
856 
857 	status = wmi_unified_send_disconnect_roam_params(wmi_handle, req);
858 	if (QDF_IS_STATUS_ERROR(status))
859 		target_if_err("failed to send disconnect roam parameters");
860 }
861 
862 /* target_if_cm_roam_idle_params(): Send the roam idle parameters to wmi
863  * @wmi_handle: handle to WMI
864  * @command: rso command
865  * @req: roam idle parameters
866  *
867  * Return: void
868  */
869 static void
target_if_cm_roam_idle_params(wmi_unified_t wmi_handle,uint8_t command,struct wlan_roam_idle_params * req)870 target_if_cm_roam_idle_params(wmi_unified_t wmi_handle, uint8_t command,
871 			      struct wlan_roam_idle_params *req)
872 {
873 	QDF_STATUS status;
874 	bool db2dbm_enabled;
875 
876 	switch (command) {
877 	case ROAM_SCAN_OFFLOAD_START:
878 	case ROAM_SCAN_OFFLOAD_UPDATE_CFG:
879 		break;
880 	case ROAM_SCAN_OFFLOAD_STOP:
881 		req->enable = false;
882 		break;
883 	default:
884 		break;
885 	}
886 
887 	db2dbm_enabled = wmi_service_enabled(wmi_handle,
888 					     wmi_service_hw_db2dbm_support);
889 	if (!db2dbm_enabled) {
890 		req->conn_ap_min_rssi -= NOISE_FLOOR_DBM_DEFAULT;
891 		req->conn_ap_min_rssi &= 0x000000ff;
892 	}
893 
894 	status = wmi_unified_send_idle_roam_params(wmi_handle, req);
895 	if (QDF_IS_STATUS_ERROR(status))
896 		target_if_err("failed to send idle roam parameters");
897 }
898 #else
899 static void
target_if_cm_roam_reason_vsie(wmi_unified_t wmi_handle,struct wlan_roam_reason_vsie_enable * req)900 target_if_cm_roam_reason_vsie(wmi_unified_t wmi_handle,
901 			      struct wlan_roam_reason_vsie_enable *req)
902 {
903 }
904 
905 static QDF_STATUS
target_if_cm_roam_triggers(struct wlan_objmgr_vdev * vdev,struct wlan_roam_triggers * req)906 target_if_cm_roam_triggers(struct wlan_objmgr_vdev *vdev,
907 			   struct wlan_roam_triggers *req)
908 {
909 	return QDF_STATUS_E_NOSUPPORT;
910 }
911 
912 static uint32_t
target_if_cm_roam_scan_get_cckm_mode(struct wlan_objmgr_vdev * vdev,uint32_t auth_mode)913 target_if_cm_roam_scan_get_cckm_mode(struct wlan_objmgr_vdev *vdev,
914 				     uint32_t auth_mode)
915 {
916 	return WMI_AUTH_CCKM;
917 }
918 
919 static void
target_if_cm_roam_disconnect_params(wmi_unified_t wmi_handle,uint8_t command,struct wlan_roam_disconnect_params * req)920 target_if_cm_roam_disconnect_params(wmi_unified_t wmi_handle, uint8_t command,
921 				    struct wlan_roam_disconnect_params *req)
922 {
923 }
924 
925 static void
target_if_cm_roam_idle_params(wmi_unified_t wmi_handle,uint8_t command,struct wlan_roam_idle_params * req)926 target_if_cm_roam_idle_params(wmi_unified_t wmi_handle, uint8_t command,
927 			      struct wlan_roam_idle_params *req)
928 {
929 }
930 #endif
931 
932 /**
933  * target_if_cm_roam_scan_offload_rssi_thresh() - Send roam scan rssi threshold
934  * commands to wmi
935  * @wmi_handle: wmi handle
936  * @req: roam scan rssi threshold related parameters
937  *
938  * This function fills some parameters @req and send down roam scan rssi
939  * threshold command to wmi
940  *
941  * Return: QDF_STATUS
942  */
943 static QDF_STATUS
target_if_cm_roam_scan_offload_rssi_thresh(wmi_unified_t wmi_handle,struct wlan_roam_offload_scan_rssi_params * req)944 target_if_cm_roam_scan_offload_rssi_thresh(
945 				wmi_unified_t wmi_handle,
946 				struct wlan_roam_offload_scan_rssi_params *req)
947 {
948 	QDF_STATUS status = QDF_STATUS_SUCCESS;
949 	bool db2dbm_enabled;
950 
951 	db2dbm_enabled = wmi_service_enabled(wmi_handle,
952 					     wmi_service_hw_db2dbm_support);
953 	if (!db2dbm_enabled) {
954 		req->rssi_thresh -= NOISE_FLOOR_DBM_DEFAULT;
955 		req->rssi_thresh &= 0x000000ff;
956 		req->hi_rssi_scan_rssi_ub -= NOISE_FLOOR_DBM_DEFAULT;
957 		req->bg_scan_bad_rssi_thresh -= NOISE_FLOOR_DBM_DEFAULT;
958 		req->roam_data_rssi_threshold -= NOISE_FLOOR_DBM_DEFAULT;
959 		req->good_rssi_threshold -= NOISE_FLOOR_DBM_DEFAULT;
960 		req->good_rssi_threshold &= 0x000000ff;
961 	}
962 
963 	req->hi_rssi_scan_rssi_ub &= 0x000000ff;
964 	/*
965 	 * The current Noise floor in firmware is -96dBm. Penalty/Boost
966 	 * threshold is applied on a weaker signal to make it even more weaker.
967 	 * So, there is a chance that the user may configure a very low
968 	 * Penalty/Boost threshold beyond the noise floor. If that is the case,
969 	 * then suppress the penalty/boost threshold to the noise floor.
970 	 */
971 	if (req->raise_rssi_thresh_5g < NOISE_FLOOR_DBM_DEFAULT) {
972 		if (db2dbm_enabled) {
973 			req->penalty_threshold_5g = RSSI_MIN_VALUE;
974 			req->boost_threshold_5g = RSSI_MAX_VALUE;
975 		} else {
976 			req->penalty_threshold_5g = 0;
977 		}
978 	} else {
979 		if (db2dbm_enabled) {
980 			req->boost_threshold_5g = req->raise_rssi_thresh_5g;
981 		} else {
982 			req->boost_threshold_5g =
983 				(req->raise_rssi_thresh_5g -
984 					NOISE_FLOOR_DBM_DEFAULT) & 0x000000ff;
985 		}
986 	}
987 
988 	if (req->drop_rssi_thresh_5g < NOISE_FLOOR_DBM_DEFAULT) {
989 		if (db2dbm_enabled)
990 			req->penalty_threshold_5g = RSSI_MIN_VALUE;
991 		else
992 			req->penalty_threshold_5g = 0;
993 	} else {
994 		if (db2dbm_enabled) {
995 			req->penalty_threshold_5g = req->drop_rssi_thresh_5g;
996 		} else {
997 			req->penalty_threshold_5g =
998 				(req->drop_rssi_thresh_5g -
999 					NOISE_FLOOR_DBM_DEFAULT) & 0x000000ff;
1000 		}
1001 	}
1002 
1003 	if (req->early_stop_scan_enable) {
1004 		if (!db2dbm_enabled) {
1005 			req->roam_earlystop_thres_min -=
1006 						NOISE_FLOOR_DBM_DEFAULT;
1007 			req->roam_earlystop_thres_max -=
1008 						NOISE_FLOOR_DBM_DEFAULT;
1009 		}
1010 	} else {
1011 		if (db2dbm_enabled) {
1012 			req->roam_earlystop_thres_min = RSSI_MIN_VALUE;
1013 			req->roam_earlystop_thres_max = RSSI_MIN_VALUE;
1014 		} else {
1015 			req->roam_earlystop_thres_min = 0;
1016 			req->roam_earlystop_thres_max = 0;
1017 		}
1018 	}
1019 
1020 	if (req->hi_rssi_scan_rssi_delta)
1021 		target_if_check_hi_rssi_5ghz_support(wmi_handle, req);
1022 
1023 	target_if_debug("RSO_CFG: vdev %d: db2dbm enabled:%d, good_rssi_threshold:%d, early_stop_thresholds en:%d, min:%d, max:%d, roam_scan_rssi_thresh:%d, roam_rssi_thresh_diff:%d",
1024 			req->vdev_id, db2dbm_enabled, req->good_rssi_threshold,
1025 			req->early_stop_scan_enable,
1026 			req->roam_earlystop_thres_min,
1027 			req->roam_earlystop_thres_max, req->rssi_thresh,
1028 			req->rssi_thresh_diff);
1029 	target_if_debug("RSO_CFG: hirssi max cnt:%d, delta:%d, hirssi upper bound:%d, dense rssi thresh offset:%d, dense min aps cnt:%d, traffic_threshold:%d, dense_status:%d",
1030 			req->hi_rssi_scan_max_count,
1031 			req->hi_rssi_scan_rssi_delta,
1032 			req->hi_rssi_scan_rssi_ub,
1033 			req->dense_rssi_thresh_offset,
1034 			req->dense_min_aps_cnt,
1035 			req->traffic_threshold,
1036 			req->initial_dense_status);
1037 	target_if_debug("RSO_CFG: raise rssi threshold 5g:%d, drop rssi threshold 5g:%d, penalty threshold 5g:%d, boost threshold 5g:%d",
1038 			req->raise_rssi_thresh_5g,
1039 			req->drop_rssi_thresh_5g,
1040 			req->penalty_threshold_5g,
1041 			req->boost_threshold_5g);
1042 	target_if_debug("RSO_CFG: raise factor 5g:%d, drop factor 5g:%d, max raise rssi 5g:%d, max drop rssi 5g:%d, rssi threshold offset 5g:%d",
1043 			req->raise_factor_5g,
1044 			req->raise_factor_5g,
1045 			req->max_raise_rssi_5g,
1046 			req->max_drop_rssi_5g,
1047 			req->rssi_thresh_offset_5g);
1048 	target_if_debug("RSO_CFG: BG Scan Bad RSSI:%d, bitmap:0x%x Offset for 2G to 5G Roam:%d",
1049 			req->bg_scan_bad_rssi_thresh,
1050 			req->bg_scan_client_bitmap,
1051 			req->roam_bad_rssi_thresh_offset_2g);
1052 	target_if_debug("RSO_CFG: Roam data rssi triggers:0x%x, threshold:%d, rx time:%d",
1053 			req->roam_data_rssi_threshold_triggers,
1054 			req->roam_data_rssi_threshold,
1055 			req->rx_data_inactivity_time);
1056 
1057 	status = wmi_unified_roam_scan_offload_rssi_thresh_cmd(wmi_handle, req);
1058 	if (QDF_IS_STATUS_ERROR(status)) {
1059 		target_if_err("roam_scan_offload_rssi_thresh_cmd failed %d",
1060 			      status);
1061 		return status;
1062 	}
1063 
1064 	return status;
1065 }
1066 
1067 /**
1068  * target_if_cm_roam_scan_offload_scan_period() - set roam offload scan period
1069  * @wmi_handle: wmi handle
1070  * @req:  roam scan period parameters
1071  *
1072  * Send WMI_ROAM_SCAN_PERIOD parameters to fw.
1073  *
1074  * Return: QDF status
1075  */
1076 static QDF_STATUS
target_if_cm_roam_scan_offload_scan_period(wmi_unified_t wmi_handle,struct wlan_roam_scan_period_params * req)1077 target_if_cm_roam_scan_offload_scan_period(
1078 				wmi_unified_t wmi_handle,
1079 				struct wlan_roam_scan_period_params *req)
1080 {
1081 	if (!target_if_is_vdev_valid(req->vdev_id)) {
1082 		target_if_err("Invalid vdev id:%d", req->vdev_id);
1083 		return QDF_STATUS_E_FAILURE;
1084 	}
1085 
1086 	return wmi_unified_roam_scan_offload_scan_period(wmi_handle, req);
1087 }
1088 
1089 /**
1090  * target_if_cm_roam_scan_offload_ap_profile() - send roam ap profile to
1091  * firmware
1092  * @vdev: vdev object
1093  * @wmi_handle: wmi handle
1094  * @req: roam ap profile parameters
1095  *
1096  * Send WMI_ROAM_AP_PROFILE parameters to firmware
1097  *
1098  * Return: QDF status
1099  */
1100 static QDF_STATUS
target_if_cm_roam_scan_offload_ap_profile(struct wlan_objmgr_vdev * vdev,wmi_unified_t wmi_handle,struct ap_profile_params * req)1101 target_if_cm_roam_scan_offload_ap_profile(
1102 				struct wlan_objmgr_vdev *vdev,
1103 				wmi_unified_t wmi_handle,
1104 				struct ap_profile_params *req)
1105 {
1106 	uint32_t rsn_authmode;
1107 	bool db2dbm_enabled;
1108 
1109 	if (!target_if_is_vdev_valid(req->vdev_id)) {
1110 		target_if_err("Invalid vdev id:%d", req->vdev_id);
1111 		return QDF_STATUS_E_FAILURE;
1112 	}
1113 
1114 	rsn_authmode = req->profile.rsn_authmode;
1115 	if (rsn_authmode == WMI_AUTH_CCKM_WPA ||
1116 	    rsn_authmode == WMI_AUTH_CCKM_RSNA)
1117 		req->profile.rsn_authmode =
1118 		target_if_cm_roam_scan_get_cckm_mode(vdev, rsn_authmode);
1119 
1120 	db2dbm_enabled = wmi_service_enabled(wmi_handle,
1121 					     wmi_service_hw_db2dbm_support);
1122 	if (!req->profile.rssi_abs_thresh) {
1123 		if (db2dbm_enabled)
1124 			req->profile.rssi_abs_thresh = RSSI_MIN_VALUE;
1125 	} else {
1126 		if (!db2dbm_enabled)
1127 			req->profile.rssi_abs_thresh -=
1128 						NOISE_FLOOR_DBM_DEFAULT;
1129 	}
1130 
1131 	if (!db2dbm_enabled) {
1132 		req->min_rssi_params[DEAUTH_MIN_RSSI].min_rssi -=
1133 						NOISE_FLOOR_DBM_DEFAULT;
1134 		req->min_rssi_params[DEAUTH_MIN_RSSI].min_rssi &= 0x000000ff;
1135 
1136 		req->min_rssi_params[BMISS_MIN_RSSI].min_rssi -=
1137 						NOISE_FLOOR_DBM_DEFAULT;
1138 		req->min_rssi_params[BMISS_MIN_RSSI].min_rssi &= 0x000000ff;
1139 
1140 		req->min_rssi_params[MIN_RSSI_2G_TO_5G_ROAM].min_rssi -=
1141 						NOISE_FLOOR_DBM_DEFAULT;
1142 		req->min_rssi_params[MIN_RSSI_2G_TO_5G_ROAM].min_rssi &=
1143 						0x000000ff;
1144 
1145 	}
1146 
1147 	return wmi_unified_send_roam_scan_offload_ap_cmd(wmi_handle, req);
1148 }
1149 
1150 /**
1151  * target_if_cm_roam_scan_mawc_params() - send roam macw to
1152  * firmware
1153  * @wmi_handle: wmi handle
1154  * @req: roam macw parameters
1155  *
1156  * Send WMI_ROAM_CONFIGURE_MAWC_CMDID parameters to firmware
1157  *
1158  * Return: QDF status
1159  */
1160 static QDF_STATUS
target_if_cm_roam_scan_mawc_params(wmi_unified_t wmi_handle,struct wlan_roam_mawc_params * req)1161 target_if_cm_roam_scan_mawc_params(wmi_unified_t wmi_handle,
1162 				   struct wlan_roam_mawc_params *req)
1163 {
1164 	if (!wmi_service_enabled(wmi_handle, wmi_service_hw_db2dbm_support))
1165 		req->best_ap_rssi_threshold -= NOISE_FLOOR_DBM_DEFAULT;
1166 
1167 	return wmi_unified_roam_mawc_params_cmd(wmi_handle, req);
1168 }
1169 
1170 /**
1171  * target_if_cm_roam_scan_filter() - send roam scan filter to firmware
1172  * @wmi_handle: wmi handle
1173  * @command: rso command
1174  * @req: roam scan filter parameters
1175  *
1176  * Send WMI_ROAM_FILTER_CMDID parameters to firmware
1177  *
1178  * Return: QDF status
1179  */
1180 static QDF_STATUS
target_if_cm_roam_scan_filter(wmi_unified_t wmi_handle,uint8_t command,struct wlan_roam_scan_filter_params * req)1181 target_if_cm_roam_scan_filter(wmi_unified_t wmi_handle, uint8_t command,
1182 			      struct wlan_roam_scan_filter_params *req)
1183 {
1184 	QDF_STATUS status = QDF_STATUS_SUCCESS;
1185 
1186 	if (!target_if_is_vdev_valid(req->filter_params.vdev_id)) {
1187 		target_if_err("Invalid vdev id:%d",
1188 			      req->filter_params.vdev_id);
1189 		return QDF_STATUS_E_FAILURE;
1190 	}
1191 
1192 	if (command != ROAM_SCAN_OFFLOAD_STOP) {
1193 		switch (req->reason) {
1194 		case REASON_ROAM_SET_DENYLIST_BSSID:
1195 		case REASON_ROAM_SET_SSID_ALLOWED:
1196 		case REASON_ROAM_SET_FAVORED_BSSID:
1197 			break;
1198 		case REASON_CTX_INIT:
1199 			if (command == ROAM_SCAN_OFFLOAD_START) {
1200 				req->filter_params.op_bitmap |=
1201 				ROAM_FILTER_OP_BITMAP_LCA_DISALLOW |
1202 				ROAM_FILTER_OP_BITMAP_RSSI_REJECTION_OCE;
1203 			} else {
1204 				target_if_debug("Roam Filter need not be sent");
1205 				return QDF_STATUS_SUCCESS;
1206 			}
1207 			break;
1208 		default:
1209 			if (command != ROAM_SCAN_OFFLOAD_START) {
1210 				target_if_debug("Roam Filter need not be sent");
1211 				return QDF_STATUS_SUCCESS;
1212 			}
1213 		}
1214 	}
1215 
1216 	target_if_debug("RSO_CFG: vdev %d op_bitmap:0x%x num_rssi_rejection_ap:%d delta_rssi:%d",
1217 			req->filter_params.vdev_id,
1218 			req->filter_params.op_bitmap,
1219 			req->filter_params.num_rssi_rejection_ap,
1220 			req->filter_params.delta_rssi);
1221 	status = wmi_unified_roam_scan_filter_cmd(wmi_handle,
1222 						  &req->filter_params);
1223 	return status;
1224 }
1225 
1226 /**
1227  * target_if_cm_roam_scan_btm_offload() - send roam scan btm offload to firmware
1228  * @wmi_handle: wmi handle
1229  * @req: roam scan btm offload parameters
1230  *
1231  * Send WMI_ROAM_BTM_CONFIG_CMDID parameters to firmware
1232  *
1233  * Return: QDF status
1234  */
1235 static QDF_STATUS
target_if_cm_roam_scan_btm_offload(wmi_unified_t wmi_handle,struct wlan_roam_btm_config * req)1236 target_if_cm_roam_scan_btm_offload(wmi_unified_t wmi_handle,
1237 				   struct wlan_roam_btm_config *req)
1238 {
1239 	return wmi_unified_send_btm_config(wmi_handle, req);
1240 }
1241 
1242 /**
1243  * target_if_cm_roam_offload_11k_params() - send 11k offload params to firmware
1244  * @wmi_handle: wmi handle
1245  * @req: 11k offload parameters
1246  *
1247  * Send WMI_11K_OFFLOAD_REPORT_CMDID parameters to firmware
1248  *
1249  * Return: QDF status
1250  */
1251 static QDF_STATUS
target_if_cm_roam_offload_11k_params(wmi_unified_t wmi_handle,struct wlan_roam_11k_offload_params * req)1252 target_if_cm_roam_offload_11k_params(wmi_unified_t wmi_handle,
1253 				     struct wlan_roam_11k_offload_params *req)
1254 {
1255 	QDF_STATUS status;
1256 
1257 	if (!wmi_service_enabled(wmi_handle,
1258 				 wmi_service_11k_neighbour_report_support)) {
1259 		target_if_err("FW doesn't support 11k offload");
1260 		return QDF_STATUS_SUCCESS;
1261 	}
1262 
1263 	/* If 11k enable command and ssid length is 0, drop it */
1264 	if (req->offload_11k_bitmask &&
1265 	    !req->neighbor_report_params.ssid.length) {
1266 		target_if_debug("SSID Len 0");
1267 		return QDF_STATUS_SUCCESS;
1268 	}
1269 
1270 	status = wmi_unified_offload_11k_cmd(wmi_handle, req);
1271 
1272 	if (status != QDF_STATUS_SUCCESS)
1273 		target_if_err("failed to send 11k offload command");
1274 
1275 	return status;
1276 }
1277 
1278 /**
1279  * target_if_cm_roam_bss_load_config() - send bss load config params to firmware
1280  * @wmi_handle: wmi handle
1281  * @req: bss load config parameters
1282  *
1283  * Send WMI_ROAM_BSS_LOAD_CONFIG_CMDID parameters to firmware
1284  *
1285  * Return: QDF status
1286  */
1287 static void
target_if_cm_roam_bss_load_config(wmi_unified_t wmi_handle,struct wlan_roam_bss_load_config * req)1288 target_if_cm_roam_bss_load_config(wmi_unified_t wmi_handle,
1289 				  struct wlan_roam_bss_load_config *req)
1290 {
1291 	QDF_STATUS status;
1292 	bool db2dbm_enabled;
1293 
1294 	db2dbm_enabled = wmi_service_enabled(wmi_handle,
1295 					     wmi_service_hw_db2dbm_support);
1296 	if (!db2dbm_enabled) {
1297 		req->rssi_threshold_6ghz -= NOISE_FLOOR_DBM_DEFAULT;
1298 		req->rssi_threshold_6ghz &= 0x000000ff;
1299 
1300 		req->rssi_threshold_5ghz -= NOISE_FLOOR_DBM_DEFAULT;
1301 		req->rssi_threshold_5ghz &= 0x000000ff;
1302 
1303 		req->rssi_threshold_24ghz -= NOISE_FLOOR_DBM_DEFAULT;
1304 		req->rssi_threshold_24ghz &= 0x000000ff;
1305 	}
1306 
1307 	target_if_debug("RSO_CFG: bss load trig params vdev_id:%u threshold:%u sample_time:%u 5Ghz RSSI threshold:%d 2.4G rssi threshold:%d",
1308 			req->vdev_id, req->bss_load_threshold,
1309 			req->bss_load_sample_time, req->rssi_threshold_5ghz,
1310 			req->rssi_threshold_24ghz);
1311 
1312 	status = wmi_unified_send_bss_load_config(wmi_handle, req);
1313 	if (QDF_IS_STATUS_ERROR(status))
1314 		target_if_err("failed to send bss load trigger config command");
1315 }
1316 
1317 static uint32_t
target_if_get_wmi_roam_offload_flag(uint32_t flag)1318 target_if_get_wmi_roam_offload_flag(uint32_t flag)
1319 {
1320 	uint32_t roam_offload_flag = 0;
1321 
1322 	if (flag & WLAN_ROAM_FW_OFFLOAD_ENABLE)
1323 		roam_offload_flag |= WMI_ROAM_FW_OFFLOAD_ENABLE_FLAG;
1324 
1325 	if (flag & WLAN_ROAM_BMISS_FINAL_SCAN_ENABLE)
1326 		roam_offload_flag |= WMI_ROAM_BMISS_FINAL_SCAN_ENABLE_FLAG;
1327 
1328 	if (flag & WLAN_ROAM_SKIP_EAPOL_4WAY_HANDSHAKE)
1329 		roam_offload_flag |=
1330 			wmi_vdev_param_skip_roam_eapol_4way_handshake;
1331 
1332 	if (flag & WLAN_ROAM_BMISS_FINAL_SCAN_TYPE)
1333 		roam_offload_flag |= WMI_ROAM_BMISS_FINAL_SCAN_TYPE_FLAG;
1334 
1335 	if (flag & WLAN_ROAM_SKIP_SAE_ROAM_4WAY_HANDSHAKE)
1336 		roam_offload_flag |=
1337 				wmi_vdev_param_skip_sae_roam_4way_handshake;
1338 
1339 	return roam_offload_flag;
1340 }
1341 
1342 /**
1343  * target_if_cm_roam_send_roam_init  - Send roam module init/deinit to firmware
1344  * @vdev:  Pointer to Objmgr vdev
1345  * @params: Roam offload init params
1346  *
1347  * Return: QDF_STATUS
1348  */
1349 static QDF_STATUS
target_if_cm_roam_send_roam_init(struct wlan_objmgr_vdev * vdev,struct wlan_roam_offload_init_params * params)1350 target_if_cm_roam_send_roam_init(struct wlan_objmgr_vdev *vdev,
1351 				 struct wlan_roam_offload_init_params *params)
1352 {
1353 	QDF_STATUS status;
1354 	wmi_unified_t wmi_handle;
1355 	uint32_t flag;
1356 
1357 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
1358 	if (!wmi_handle)
1359 		return QDF_STATUS_E_FAILURE;
1360 
1361 	flag = target_if_get_wmi_roam_offload_flag(params->roam_offload_flag);
1362 	status = target_if_vdev_set_param(wmi_handle, params->vdev_id,
1363 					  wmi_vdev_param_roam_fw_offload, flag);
1364 
1365 	return status;
1366 }
1367 
1368 /**
1369  * target_if_cm_roam_scan_rssi_change_cmd()  - Send WMI_ROAM_SCAN_RSSI_CHANGE
1370  * command to firmware
1371  * @wmi_handle: WMI handle
1372  * @params: RSSI change parameters
1373  *
1374  * Return: QDF_STATUS
1375  */
target_if_cm_roam_scan_rssi_change_cmd(wmi_unified_t wmi_handle,struct wlan_roam_rssi_change_params * params)1376 static QDF_STATUS target_if_cm_roam_scan_rssi_change_cmd(
1377 			wmi_unified_t wmi_handle,
1378 			struct wlan_roam_rssi_change_params *params)
1379 {
1380 	/*
1381 	 * Start new rssi triggered scan only if it changes by
1382 	 * RoamRssiDiff value. Beacon weight of 14 means average rssi
1383 	 * is taken over 14 previous samples + 2 times the current
1384 	 * beacon's rssi.
1385 	 */
1386 	return wmi_unified_roam_scan_offload_rssi_change_cmd(wmi_handle,
1387 							     params);
1388 }
1389 
1390 /**
1391  * target_if_cm_roam_offload_chan_list  - Send WMI_ROAM_CHAN_LIST command to
1392  * firmware
1393  * @wmi_handle: Pointer to wmi handle
1394  * @rso_chan_info: RSO channel list info
1395  *
1396  * Return: QDF_STATUS
1397  */
target_if_cm_roam_offload_chan_list(wmi_unified_t wmi_handle,struct wlan_roam_scan_channel_list * rso_chan_info)1398 static QDF_STATUS target_if_cm_roam_offload_chan_list(
1399 		wmi_unified_t wmi_handle,
1400 		struct wlan_roam_scan_channel_list *rso_chan_info)
1401 {
1402 	return wmi_unified_roam_scan_offload_chan_list_cmd(wmi_handle,
1403 							   rso_chan_info);
1404 }
1405 
1406 /**
1407  * target_if_cm_roam_send_time_sync_cmd  - Send time of the day in millisecs
1408  * to firmware.
1409  * @wmi_handle: WMI handle
1410  *
1411  * Return: None
1412  */
1413 static void
target_if_cm_roam_send_time_sync_cmd(wmi_unified_t wmi_handle)1414 target_if_cm_roam_send_time_sync_cmd(wmi_unified_t wmi_handle)
1415 {
1416 	return wmi_send_time_stamp_sync_cmd_tlv(wmi_handle);
1417 }
1418 
1419 #ifdef WLAN_FEATURE_11BE
1420 static QDF_STATUS
target_if_cm_roam_oem_eht_mlo_bitmap(struct wlan_objmgr_vdev * vdev)1421 target_if_cm_roam_oem_eht_mlo_bitmap(struct wlan_objmgr_vdev *vdev)
1422 {
1423 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
1424 	wmi_unified_t wmi_handle;
1425 	uint32_t oem_eht_bitmap;
1426 	struct wlan_objmgr_psoc *psoc;
1427 
1428 	psoc = wlan_vdev_get_psoc(vdev);
1429 	if (!psoc) {
1430 		target_if_err("psoc handle is NULL");
1431 		return QDF_STATUS_E_NULL_VALUE;
1432 	}
1433 
1434 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
1435 	if (!wmi_handle)
1436 		return status;
1437 
1438 	status = wlan_mlme_get_oem_eht_mlo_config(psoc, &oem_eht_bitmap);
1439 	if (QDF_IS_STATUS_ERROR(status))
1440 		return status;
1441 
1442 	status = target_if_roam_set_param(wmi_handle,
1443 					  wlan_vdev_get_id(vdev),
1444 					  WMI_ROAM_PARAM_CRYPTO_EHT_CONFIG,
1445 					  oem_eht_bitmap);
1446 
1447 	if (QDF_IS_STATUS_ERROR(status))
1448 		target_if_err("Failed to set roam oem eht bitmap");
1449 
1450 	return status;
1451 }
1452 #else
1453 static inline QDF_STATUS
target_if_cm_roam_oem_eht_mlo_bitmap(struct wlan_objmgr_vdev * vdev)1454 target_if_cm_roam_oem_eht_mlo_bitmap(struct wlan_objmgr_vdev *vdev)
1455 {
1456 	return QDF_STATUS_SUCCESS;
1457 }
1458 #endif
1459 
1460 #ifdef WLAN_FEATURE_11BE_MLO
1461 /**
1462  * target_if_cm_roam_send_mlo_config() - Send roam mlo related commands
1463  * to wmi
1464  * @vdev: vdev object
1465  * @req: roam mlo config parameters
1466  *
1467  * This function is used to send roam mlo related commands to wmi
1468  *
1469  * Return: QDF_STATUS
1470  */
1471 static QDF_STATUS
target_if_cm_roam_send_mlo_config(struct wlan_objmgr_vdev * vdev,struct wlan_roam_mlo_config * req)1472 target_if_cm_roam_send_mlo_config(struct wlan_objmgr_vdev *vdev,
1473 				  struct wlan_roam_mlo_config *req)
1474 {
1475 	QDF_STATUS status;
1476 	wmi_unified_t wmi_handle;
1477 
1478 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
1479 	if (!wmi_handle)
1480 		return QDF_STATUS_E_FAILURE;
1481 
1482 	status = wmi_unified_roam_mlo_config_cmd(wmi_handle, req);
1483 
1484 	if (status != QDF_STATUS_SUCCESS)
1485 		target_if_err("failed to send WMI_ROAM_MLO_CONFIG_CMDID command");
1486 
1487 	return status;
1488 }
1489 
1490 static void
target_if_cm_roam_register_mlo_req_ops(struct wlan_cm_roam_tx_ops * tx_ops)1491 target_if_cm_roam_register_mlo_req_ops(struct wlan_cm_roam_tx_ops *tx_ops)
1492 {
1493 	tx_ops->send_roam_mlo_config = target_if_cm_roam_send_mlo_config;
1494 }
1495 #else
1496 static QDF_STATUS
target_if_cm_roam_send_mlo_config(struct wlan_objmgr_vdev * vdev,struct wlan_roam_mlo_config * req)1497 target_if_cm_roam_send_mlo_config(struct wlan_objmgr_vdev *vdev,
1498 				  struct wlan_roam_mlo_config *req)
1499 {
1500 	return QDF_STATUS_SUCCESS;
1501 }
1502 
1503 static void
target_if_cm_roam_register_mlo_req_ops(struct wlan_cm_roam_tx_ops * tx_ops)1504 target_if_cm_roam_register_mlo_req_ops(struct wlan_cm_roam_tx_ops *tx_ops)
1505 {
1506 }
1507 #endif
1508 
1509 /**
1510  * target_if_cm_roam_send_start() - Send roam start related commands
1511  * to wmi
1512  * @vdev: vdev object
1513  * @req: roam start config parameters
1514  *
1515  * This function is used to send roam start related commands to wmi
1516  *
1517  * Return: QDF_STATUS
1518  */
1519 static QDF_STATUS
target_if_cm_roam_send_start(struct wlan_objmgr_vdev * vdev,struct wlan_roam_start_config * req)1520 target_if_cm_roam_send_start(struct wlan_objmgr_vdev *vdev,
1521 			     struct wlan_roam_start_config *req)
1522 {
1523 	QDF_STATUS status = QDF_STATUS_SUCCESS;
1524 	wmi_unified_t wmi_handle;
1525 	struct wlan_objmgr_psoc *psoc;
1526 	uint8_t vdev_id;
1527 	bool bss_load_enabled;
1528 	bool eht_capab = false;
1529 	bool is_mcc_disallowed;
1530 
1531 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
1532 	if (!wmi_handle)
1533 		return QDF_STATUS_E_FAILURE;
1534 
1535 	target_if_cm_roam_send_time_sync_cmd(wmi_handle);
1536 
1537 	status = target_if_cm_roam_scan_offload_rssi_thresh(
1538 							wmi_handle,
1539 							&req->rssi_params);
1540 	if (QDF_IS_STATUS_ERROR(status)) {
1541 		target_if_err("Sending roam scan offload rssi thresh failed");
1542 		goto end;
1543 	}
1544 
1545 	status = target_if_cm_roam_scan_bmiss_cnt(wmi_handle,
1546 						  &req->beacon_miss_cnt);
1547 	if (QDF_IS_STATUS_ERROR(status)) {
1548 		target_if_err("vdev set bmiss bcnt param failed");
1549 		goto end;
1550 	}
1551 	status = target_if_cm_roam_scan_bmiss_timeout(wmi_handle,
1552 						      &req->bmiss_timeout);
1553 	if (QDF_IS_STATUS_ERROR(status)) {
1554 		target_if_err("vdev set bmiss timeout param failed");
1555 		goto end;
1556 	}
1557 
1558 	target_if_cm_roam_reason_vsie(wmi_handle, &req->reason_vsie_enable);
1559 
1560 	target_if_cm_roam_triggers(vdev, &req->roam_triggers);
1561 
1562 	/* Opportunistic scan runs on a timer, value set by
1563 	 * empty_scan_refresh_period. Age out the entries after 3 such
1564 	 * cycles.
1565 	 */
1566 	if (req->scan_period_params.empty_scan_refresh_period > 0) {
1567 		status = target_if_cm_roam_scan_offload_scan_period(
1568 						wmi_handle,
1569 						&req->scan_period_params);
1570 		if (QDF_IS_STATUS_ERROR(status))
1571 			goto end;
1572 	}
1573 
1574 	status = target_if_cm_roam_scan_rssi_change_cmd(
1575 			wmi_handle, &req->rssi_change_params);
1576 	if (QDF_IS_STATUS_ERROR(status)) {
1577 		target_if_err("vdev:%d Sending rssi change threshold failed",
1578 			      req->rssi_change_params.vdev_id);
1579 		goto end;
1580 	}
1581 
1582 	status = target_if_cm_roam_scan_offload_ap_profile(
1583 							vdev, wmi_handle,
1584 							&req->profile_params);
1585 	if (QDF_IS_STATUS_ERROR(status))
1586 		goto end;
1587 
1588 	status = target_if_cm_roam_offload_chan_list(wmi_handle,
1589 						     &req->rso_chan_info);
1590 	if (QDF_IS_STATUS_ERROR(status)) {
1591 		target_if_err("vdev:%d Send channel list command failed",
1592 			      req->rso_chan_info.vdev_id);
1593 		goto end;
1594 	}
1595 
1596 	if (wmi_service_enabled(wmi_handle, wmi_service_mawc_support)) {
1597 		status = target_if_cm_roam_scan_mawc_params(wmi_handle,
1598 							    &req->mawc_params);
1599 		if (QDF_IS_STATUS_ERROR(status)) {
1600 			target_if_err("Sending roaming MAWC params failed");
1601 			goto end;
1602 		}
1603 	} else {
1604 		target_if_debug("MAWC roaming not supported by firmware");
1605 	}
1606 
1607 	status = target_if_cm_roam_scan_offload_mode(wmi_handle,
1608 						     &req->rso_config);
1609 	if (QDF_IS_STATUS_ERROR(status)) {
1610 		target_if_err("vdev:%d Send RSO mode cmd failed",
1611 			      req->rso_config.vdev_id);
1612 		goto end;
1613 	}
1614 
1615 	status = target_if_cm_roam_scan_filter(wmi_handle,
1616 					       ROAM_SCAN_OFFLOAD_START,
1617 					       &req->scan_filter_params);
1618 	if (QDF_IS_STATUS_ERROR(status)) {
1619 		target_if_err("Sending start for roam scan filter failed");
1620 		goto end;
1621 	}
1622 
1623 	status = target_if_cm_roam_scan_btm_offload(wmi_handle,
1624 						    &req->btm_config);
1625 	if (QDF_IS_STATUS_ERROR(status)) {
1626 		target_if_err("Sending BTM config to fw failed");
1627 		goto end;
1628 	}
1629 
1630 	/*
1631 	 * Send 11k offload enable and bss load trigger parameters
1632 	 * to FW as part of RSO Start
1633 	 */
1634 	status = target_if_cm_roam_offload_11k_params(wmi_handle,
1635 						      &req->roam_11k_params);
1636 	if (QDF_IS_STATUS_ERROR(status)) {
1637 		target_if_err("11k offload enable not sent, status %d", status);
1638 		goto end;
1639 	}
1640 
1641 	psoc = wlan_vdev_get_psoc(vdev);
1642 	if (!psoc) {
1643 		target_if_err("psoc handle is NULL");
1644 		return QDF_STATUS_E_INVAL;
1645 	}
1646 
1647 	wlan_mlme_get_bss_load_enabled(psoc, &bss_load_enabled);
1648 	if (bss_load_enabled)
1649 		target_if_cm_roam_bss_load_config(wmi_handle,
1650 						  &req->bss_load_config);
1651 
1652 	target_if_cm_roam_disconnect_params(wmi_handle, ROAM_SCAN_OFFLOAD_START,
1653 					    &req->disconnect_params);
1654 
1655 	target_if_cm_roam_idle_params(wmi_handle, ROAM_SCAN_OFFLOAD_START,
1656 				      &req->idle_params);
1657 	wlan_psoc_mlme_get_11be_capab(psoc, &eht_capab);
1658 	if (eht_capab)
1659 		target_if_cm_roam_send_mlo_config(vdev, &req->roam_mlo_params);
1660 
1661 	vdev_id = wlan_vdev_get_id(vdev);
1662 	if (req->wlan_roam_rt_stats_config)
1663 		target_if_cm_roam_rt_stats_config(vdev, vdev_id,
1664 						req->wlan_roam_rt_stats_config);
1665 
1666 	if (req->wlan_roam_ho_delay_config)
1667 		target_if_cm_roam_ho_delay_config(
1668 				vdev, vdev_id, req->wlan_roam_ho_delay_config);
1669 
1670 	if (req->wlan_exclude_rm_partial_scan_freq)
1671 		target_if_cm_exclude_rm_partial_scan_freq(
1672 				vdev, req->wlan_exclude_rm_partial_scan_freq);
1673 
1674 	if (req->wlan_roam_full_scan_6ghz_on_disc)
1675 		target_if_cm_roam_full_scan_6ghz_on_disc(
1676 				vdev, req->wlan_roam_full_scan_6ghz_on_disc);
1677 
1678 	is_mcc_disallowed = !wlan_cm_same_band_sta_allowed(psoc);
1679 	target_if_cm_roam_mcc_disallow(vdev, vdev_id, is_mcc_disallowed);
1680 
1681 	if (req->wlan_roam_rssi_diff_6ghz)
1682 		target_if_cm_roam_rssi_diff_6ghz(vdev,
1683 						 req->wlan_roam_rssi_diff_6ghz);
1684 
1685 	status = target_if_cm_roam_oem_eht_mlo_bitmap(vdev);
1686 	/* add other wmi commands */
1687 end:
1688 	return status;
1689 }
1690 
1691 #ifdef WLAN_FEATURE_11BE_MLO
1692 static QDF_STATUS
target_if_start_rso_stop_timer(struct wlan_objmgr_vdev * vdev)1693 target_if_start_rso_stop_timer(struct wlan_objmgr_vdev *vdev)
1694 {
1695 	struct wlan_objmgr_psoc *psoc;
1696 	uint8_t vdev_id;
1697 	struct wlan_lmac_if_mlme_rx_ops *rx_ops;
1698 	struct vdev_response_timer *vdev_rsp;
1699 
1700 	psoc = wlan_vdev_get_psoc(vdev);
1701 	if (!psoc) {
1702 		target_if_err("psoc handle is NULL");
1703 		return QDF_STATUS_E_INVAL;
1704 	}
1705 
1706 	vdev_id = wlan_vdev_get_id(vdev);
1707 	rx_ops = target_if_vdev_mgr_get_rx_ops(psoc);
1708 	if (!rx_ops || !rx_ops->psoc_get_vdev_response_timer_info) {
1709 		mlme_err("VEV_%d: PSOC_%d No Rx Ops", vdev_id,
1710 			 wlan_psoc_get_id(psoc));
1711 		return QDF_STATUS_E_INVAL;
1712 	}
1713 
1714 	vdev_rsp = rx_ops->psoc_get_vdev_response_timer_info(psoc, vdev_id);
1715 	if (!vdev_rsp) {
1716 		mlme_err("VDEV_%d: PSOC_%d No vdev rsp timer", vdev_id,
1717 			 wlan_psoc_get_id(psoc));
1718 		return QDF_STATUS_E_INVAL;
1719 	}
1720 
1721 	vdev_rsp->expire_time = RSO_STOP_RESPONSE_TIMER;
1722 
1723 	return target_if_vdev_mgr_rsp_timer_start(psoc, vdev_rsp,
1724 						  RSO_STOP_RESPONSE_BIT);
1725 }
1726 
1727 static bool
target_if_is_vdev_rsp_valid(struct wlan_objmgr_psoc * psoc,struct vdev_response_timer ** vdev_rsp,struct wlan_lmac_if_mlme_rx_ops * rx_ops,uint8_t vdev_id)1728 target_if_is_vdev_rsp_valid(struct wlan_objmgr_psoc *psoc,
1729 			    struct vdev_response_timer **vdev_rsp,
1730 			    struct wlan_lmac_if_mlme_rx_ops *rx_ops,
1731 			    uint8_t vdev_id)
1732 {
1733 	*vdev_rsp = rx_ops->psoc_get_vdev_response_timer_info(psoc, vdev_id);
1734 	if (!*vdev_rsp) {
1735 		mlme_err("MLO_ROAM: vdev rsp not found for vdev:%d", vdev_id);
1736 		return false;
1737 	}
1738 
1739 	if (qdf_atomic_test_bit(RSO_STOP_RESPONSE_BIT,
1740 				&((*vdev_rsp)->rsp_status))) {
1741 		mlme_debug("MLO_ROAM: RSO bit set on vdev id %d",
1742 			   (*vdev_rsp)->vdev_id);
1743 		return true;
1744 	}
1745 
1746 	/* Failure case vdev_rsp is set to NULL */
1747 	*vdev_rsp = NULL;
1748 
1749 	return false;
1750 }
1751 
1752 /**
1753  * target_if_find_active_rso_stop_rsp() - Iterate through ml vdevs to find
1754  * the vdev rsp for which RSO_STOP_RESPONSE_BIT is set.
1755  * @roam_event: Roam event data
1756  *
1757  * This is needed when for e.g.: host sends rso stop on vdev id 0, fw response
1758  * is received on vdev 1.
1759  * Since the timer is vdev specific, this function will iterate through ml vdevs
1760  * to find the vdev_rsp on which RSO_STOP_RESPONSE_BIT is set.
1761  *
1762  * Return: struct vdev_response_timer for success, NULL for failure
1763  */
1764 static struct vdev_response_timer *
target_if_find_active_rso_stop_rsp(struct roam_offload_roam_event * roam_event)1765 target_if_find_active_rso_stop_rsp(struct roam_offload_roam_event *roam_event)
1766 {
1767 	struct vdev_response_timer *vdev_rsp = NULL;
1768 	struct wlan_lmac_if_mlme_rx_ops *rx_ops;
1769 	struct wlan_objmgr_vdev *vdev;
1770 	struct wlan_mlo_dev_context *mlo_dev_ctx;
1771 	uint8_t i;
1772 	QDF_STATUS status;
1773 
1774 	rx_ops = target_if_vdev_mgr_get_rx_ops(roam_event->psoc);
1775 	if (!rx_ops || !rx_ops->psoc_get_vdev_response_timer_info) {
1776 		mlme_err("No Rx Ops");
1777 		return NULL;
1778 	}
1779 
1780 	vdev = wlan_objmgr_get_vdev_by_id_from_psoc(roam_event->psoc,
1781 						    roam_event->vdev_id,
1782 						    WLAN_MLME_SB_ID);
1783 	if (!vdev)
1784 		return NULL;
1785 
1786 	/* For legacy case use the incoming vdev */
1787 	if (target_if_is_vdev_rsp_valid(roam_event->psoc, &vdev_rsp,
1788 					rx_ops, roam_event->vdev_id))
1789 		goto end;
1790 
1791 	mlo_dev_ctx = vdev->mlo_dev_ctx;
1792 	if (!mlo_dev_ctx)
1793 		goto end;
1794 
1795 	/*
1796 	 * if vdev_rsp with RSO_STOP_RESPONSE bit is not set then check for
1797 	 * the same on other ML vdevs
1798 	 */
1799 	for (i = 0; i < WLAN_UMAC_MLO_MAX_VDEVS; i++) {
1800 		if (!mlo_dev_ctx->wlan_vdev_list[i])
1801 			continue;
1802 
1803 		status = wlan_objmgr_vdev_try_get_ref(mlo_dev_ctx->wlan_vdev_list[i],
1804 						      WLAN_MLO_MGR_ID);
1805 		if (QDF_IS_STATUS_ERROR(status))
1806 			continue;
1807 
1808 		if (target_if_is_vdev_rsp_valid(roam_event->psoc, &vdev_rsp,
1809 						rx_ops,
1810 						wlan_vdev_get_id(mlo_dev_ctx->wlan_vdev_list[i]))) {
1811 			mlo_release_vdev_ref(mlo_dev_ctx->wlan_vdev_list[i]);
1812 			goto end;
1813 		}
1814 
1815 		mlo_release_vdev_ref(mlo_dev_ctx->wlan_vdev_list[i]);
1816 	}
1817 
1818 	if (i == WLAN_UMAC_MLO_MAX_VDEVS) {
1819 		mlme_err("RSO bit not set on any mlo vdev");
1820 		goto end;
1821 	}
1822 
1823 end:
1824 	if (vdev)
1825 		wlan_objmgr_vdev_release_ref(vdev, WLAN_MLME_SB_ID);
1826 
1827 	return vdev_rsp;
1828 }
1829 
1830 QDF_STATUS
target_if_stop_rso_stop_timer(struct roam_offload_roam_event * roam_event)1831 target_if_stop_rso_stop_timer(struct roam_offload_roam_event *roam_event)
1832 {
1833 	QDF_STATUS status = QDF_STATUS_SUCCESS;
1834 	struct vdev_response_timer *vdev_rsp;
1835 
1836 	roam_event->rso_timer_stopped = false;
1837 	if (roam_event->reason == ROAM_REASON_RSO_STATUS &&
1838 	    roam_event->notif == CM_ROAM_NOTIF_HO_FAIL) {
1839 		mlme_debug("HO_FAIL happened, wait for HO_FAIL event vdev_id: %u",
1840 			   roam_event->vdev_id);
1841 	}
1842 
1843 	vdev_rsp = target_if_find_active_rso_stop_rsp(roam_event);
1844 	if (!vdev_rsp) {
1845 		mlme_err("vdev response timer is null VDEV_%d PSOC_%d",
1846 			 roam_event->vdev_id,
1847 			 wlan_psoc_get_id(roam_event->psoc));
1848 		return QDF_STATUS_E_INVAL;
1849 	}
1850 
1851 	switch (roam_event->reason) {
1852 	case ROAM_REASON_RSO_STATUS:
1853 		if (roam_event->notif != CM_ROAM_NOTIF_SCAN_MODE_SUCCESS &&
1854 		    roam_event->notif != CM_ROAM_NOTIF_SCAN_MODE_FAIL)
1855 			break;
1856 
1857 		/*
1858 		 * fallthrough if notif == CM_ROAM_NOTIF_SCAN_MODE_SUCCESS or
1859 		 * notif == CM_ROAM_NOTIF_SCAN_MODE_FAIL
1860 		 */
1861 		fallthrough;
1862 	case ROAM_REASON_HO_FAILED:
1863 		status = target_if_vdev_mgr_rsp_timer_stop(roam_event->psoc,
1864 							   vdev_rsp,
1865 							   RSO_STOP_RESPONSE_BIT);
1866 		roam_event->rso_timer_stopped = true;
1867 		if (QDF_IS_STATUS_ERROR(status)) {
1868 			roam_event->rso_timer_stopped = false;
1869 			mlme_err("PSOC_%d VDEV_%d: VDEV MGR RSO Stop RSP Timer stop failed",
1870 				 roam_event->psoc->soc_objmgr.psoc_id,
1871 				 roam_event->vdev_id);
1872 		}
1873 		break;
1874 	default:
1875 		return status;
1876 	}
1877 
1878 	return status;
1879 }
1880 #else
1881 static inline QDF_STATUS
target_if_start_rso_stop_timer(struct wlan_objmgr_vdev * vdev)1882 target_if_start_rso_stop_timer(struct wlan_objmgr_vdev *vdev)
1883 {
1884 	return QDF_STATUS_E_NOSUPPORT;
1885 }
1886 #endif
1887 
1888 #ifdef WLAN_FEATURE_ROAM_OFFLOAD
1889 QDF_STATUS
target_if_cm_send_rso_stop_failure_rsp(struct wlan_objmgr_psoc * psoc,uint8_t vdev_id)1890 target_if_cm_send_rso_stop_failure_rsp(struct wlan_objmgr_psoc *psoc,
1891 				       uint8_t vdev_id)
1892 {
1893 	struct wlan_cm_roam_rx_ops *roam_rx_ops;
1894 	struct roam_offload_roam_event roam_event = {0};
1895 
1896 	roam_event.vdev_id = vdev_id;
1897 	roam_event.psoc = psoc;
1898 	roam_event.reason = ROAM_REASON_RSO_STATUS;
1899 	roam_event.notif = CM_ROAM_NOTIF_SCAN_MODE_FAIL;
1900 	roam_event.rso_timer_stopped = true;
1901 
1902 	roam_rx_ops = target_if_cm_get_roam_rx_ops(psoc);
1903 	if (!roam_rx_ops || !roam_rx_ops->roam_event_rx) {
1904 		target_if_err("No valid roam rx ops");
1905 		return QDF_STATUS_E_INVAL;
1906 	}
1907 	roam_rx_ops->roam_event_rx(&roam_event);
1908 
1909 	return QDF_STATUS_SUCCESS;
1910 }
1911 #endif
1912 
1913 static QDF_STATUS
target_if_cm_roam_abort_rso_stop_timer(struct wlan_objmgr_psoc * psoc,uint8_t vdev_id)1914 target_if_cm_roam_abort_rso_stop_timer(struct wlan_objmgr_psoc *psoc,
1915 				       uint8_t vdev_id)
1916 {
1917 	struct vdev_response_timer *vdev_rsp;
1918 	struct wlan_lmac_if_mlme_rx_ops *rx_ops;
1919 
1920 	rx_ops = target_if_vdev_mgr_get_rx_ops(psoc);
1921 	if (!rx_ops || !rx_ops->vdev_mgr_start_response) {
1922 		mlme_err("No Rx Ops");
1923 		return QDF_STATUS_E_INVAL;
1924 	}
1925 	vdev_rsp = rx_ops->psoc_get_vdev_response_timer_info(psoc, vdev_id);
1926 	if (!vdev_rsp) {
1927 		mlme_err("vdev response timer is null VDEV_%d PSOC_%d",
1928 			 vdev_id, wlan_psoc_get_id(psoc));
1929 		return QDF_STATUS_E_INVAL;
1930 	}
1931 
1932 	return target_if_vdev_mgr_rsp_timer_stop(psoc, vdev_rsp,
1933 						 RSO_STOP_RESPONSE_BIT);
1934 }
1935 
1936 /**
1937  * target_if_cm_roam_send_stop() - Send roam stop related commands
1938  * to wmi
1939  * @vdev: vdev object
1940  * @req: roam stop config parameters
1941  *
1942  * This function is used to send roam stop related commands to wmi
1943  *
1944  * Return: QDF_STATUS
1945  */
1946 static QDF_STATUS
target_if_cm_roam_send_stop(struct wlan_objmgr_vdev * vdev,struct wlan_roam_stop_config * req)1947 target_if_cm_roam_send_stop(struct wlan_objmgr_vdev *vdev,
1948 			    struct wlan_roam_stop_config *req)
1949 {
1950 	QDF_STATUS status = QDF_STATUS_SUCCESS;
1951 	QDF_STATUS timer_start_status = QDF_STATUS_E_NOSUPPORT;
1952 	QDF_STATUS rso_stop_status = QDF_STATUS_E_INVAL;
1953 	wmi_unified_t wmi_handle;
1954 	struct wlan_objmgr_psoc *psoc;
1955 	uint8_t vdev_id;
1956 
1957 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
1958 	if (!wmi_handle)
1959 		return QDF_STATUS_E_FAILURE;
1960 
1961 	psoc = wlan_vdev_get_psoc(vdev);
1962 	if (!psoc) {
1963 		target_if_err("psoc handle is NULL");
1964 		return QDF_STATUS_E_INVAL;
1965 	}
1966 
1967 	/* Send 11k offload disable command to FW as part of RSO Stop */
1968 	status = target_if_cm_roam_offload_11k_params(wmi_handle,
1969 						      &req->roam_11k_params);
1970 	if (QDF_IS_STATUS_ERROR(status)) {
1971 		target_if_err("11k offload disable not sent, status %d",
1972 			      status);
1973 		goto end;
1974 	}
1975 
1976 	/* Send BTM config as disabled during RSO Stop */
1977 	status = target_if_cm_roam_scan_btm_offload(wmi_handle,
1978 						    &req->btm_config);
1979 	if (QDF_IS_STATUS_ERROR(status)) {
1980 		target_if_err("Sending BTM config to fw failed");
1981 		goto end;
1982 	}
1983 
1984 	if (req->start_rso_stop_timer)
1985 		timer_start_status = target_if_start_rso_stop_timer(vdev);
1986 
1987 	rso_stop_status = target_if_cm_roam_scan_offload_mode(wmi_handle,
1988 							      &req->rso_config);
1989 	if (QDF_IS_STATUS_ERROR(rso_stop_status)) {
1990 		target_if_err("vdev:%d Send RSO mode cmd failed",
1991 			      req->rso_config.vdev_id);
1992 		goto end;
1993 	}
1994 
1995 	/*
1996 	 * After sending the roam scan mode because of a disconnect,
1997 	 * clear the scan bitmap client as well by sending
1998 	 * the following command
1999 	 */
2000 	target_if_cm_roam_scan_offload_rssi_thresh(wmi_handle,
2001 						   &req->rssi_params);
2002 
2003 	/*
2004 	 * If the STOP command is due to a disconnect, then
2005 	 * send the filter command to clear all the filter
2006 	 * entries. If it is roaming scenario, then do not
2007 	 * send the cleared entries.
2008 	 */
2009 	if (!req->middle_of_roaming) {
2010 		status = target_if_cm_roam_scan_filter(
2011 					wmi_handle, ROAM_SCAN_OFFLOAD_STOP,
2012 					&req->scan_filter_params);
2013 		if (QDF_IS_STATUS_ERROR(status)) {
2014 			target_if_err("clear for roam scan filter failed");
2015 			goto end;
2016 		}
2017 	}
2018 
2019 	target_if_cm_roam_disconnect_params(wmi_handle, ROAM_SCAN_OFFLOAD_STOP,
2020 					    &req->disconnect_params);
2021 
2022 	target_if_cm_roam_idle_params(wmi_handle, ROAM_SCAN_OFFLOAD_STOP,
2023 				      &req->idle_params);
2024 	/*
2025 	 * Disable all roaming triggers if RSO stop is as part of
2026 	 * disconnect
2027 	 */
2028 	vdev_id = wlan_vdev_get_id(vdev);
2029 	if (req->rso_config.rso_mode_info.roam_scan_mode ==
2030 	    WMI_ROAM_SCAN_MODE_NONE) {
2031 		req->roam_triggers.vdev_id = vdev_id;
2032 		req->roam_triggers.trigger_bitmap = 0;
2033 		req->roam_triggers.roam_scan_scheme_bitmap = 0;
2034 		target_if_cm_roam_triggers(vdev, &req->roam_triggers);
2035 	}
2036 end:
2037 	if (QDF_IS_STATUS_SUCCESS(timer_start_status)) {
2038 		if (QDF_IS_STATUS_SUCCESS(rso_stop_status)) {
2039 			/*
2040 			 * Started the timer and send RSO stop to firmware
2041 			 * successfully. Wait for RSO STOP response from fw.
2042 			 */
2043 			req->send_rso_stop_resp = false;
2044 		} else {
2045 			/*
2046 			 * Started the timer and but failed to send RSO stop to
2047 			 * firmware. Stop the timer and let the response be
2048 			 * poseted from CM.
2049 			 */
2050 			target_if_cm_roam_abort_rso_stop_timer(psoc,
2051 						wlan_vdev_get_id(vdev));
2052 		}
2053 	}
2054 
2055 	return status;
2056 }
2057 
2058 /**
2059  * target_if_cm_roam_send_update_config() - Send roam update config related
2060  * commands to wmi
2061  * @vdev: vdev object
2062  * @req: roam update config parameters
2063  *
2064  * Return: QDF_STATUS
2065  */
2066 static QDF_STATUS
target_if_cm_roam_send_update_config(struct wlan_objmgr_vdev * vdev,struct wlan_roam_update_config * req)2067 target_if_cm_roam_send_update_config(struct wlan_objmgr_vdev *vdev,
2068 				     struct wlan_roam_update_config *req)
2069 {
2070 	QDF_STATUS status = QDF_STATUS_SUCCESS;
2071 	wmi_unified_t wmi_handle;
2072 	struct wlan_objmgr_psoc *psoc;
2073 	uint8_t vdev_id;
2074 	bool is_mcc_disallowed;
2075 
2076 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
2077 	if (!wmi_handle)
2078 		return QDF_STATUS_E_FAILURE;
2079 
2080 	status = target_if_cm_roam_scan_bmiss_cnt(wmi_handle,
2081 						  &req->beacon_miss_cnt);
2082 	if (QDF_IS_STATUS_ERROR(status)) {
2083 		target_if_err("vdev set bmiss bcnt param failed");
2084 		goto end;
2085 	}
2086 
2087 	status = target_if_cm_roam_scan_bmiss_timeout(wmi_handle,
2088 						      &req->bmiss_timeout);
2089 	if (QDF_IS_STATUS_ERROR(status)) {
2090 		target_if_err("vdev set bmiss timeout param failed");
2091 		goto end;
2092 	}
2093 
2094 	status = target_if_cm_roam_scan_filter(wmi_handle,
2095 					       ROAM_SCAN_OFFLOAD_UPDATE_CFG,
2096 					       &req->scan_filter_params);
2097 	if (QDF_IS_STATUS_ERROR(status)) {
2098 		target_if_err("Sending update for roam scan filter failed");
2099 		goto end;
2100 	}
2101 
2102 	status = target_if_cm_roam_scan_offload_rssi_thresh(
2103 							wmi_handle,
2104 							&req->rssi_params);
2105 	if (QDF_IS_STATUS_ERROR(status)) {
2106 		target_if_err("Sending roam scan offload rssi thresh failed");
2107 		goto end;
2108 	}
2109 
2110 	if (req->scan_period_params.empty_scan_refresh_period > 0) {
2111 		status = target_if_cm_roam_scan_offload_scan_period(
2112 						wmi_handle,
2113 						&req->scan_period_params);
2114 		if (QDF_IS_STATUS_ERROR(status))
2115 			goto end;
2116 	}
2117 
2118 	status = target_if_cm_roam_scan_rssi_change_cmd(
2119 			wmi_handle, &req->rssi_change_params);
2120 	if (QDF_IS_STATUS_ERROR(status)) {
2121 		target_if_err("vdev:%d Sending rssi change threshold failed",
2122 			      req->rssi_change_params.vdev_id);
2123 		goto end;
2124 	}
2125 
2126 	status = target_if_cm_roam_scan_offload_ap_profile(
2127 							vdev, wmi_handle,
2128 							&req->profile_params);
2129 	if (QDF_IS_STATUS_ERROR(status))
2130 		goto end;
2131 
2132 	status = target_if_cm_roam_offload_chan_list(wmi_handle,
2133 						     &req->rso_chan_info);
2134 	if (QDF_IS_STATUS_ERROR(status)) {
2135 		target_if_err("vdev:%d Send channel list command failed",
2136 			      req->rso_chan_info.vdev_id);
2137 		goto end;
2138 	}
2139 
2140 	psoc = wlan_vdev_get_psoc(vdev);
2141 	if (!psoc) {
2142 		target_if_err("psoc handle is NULL");
2143 		return QDF_STATUS_E_INVAL;
2144 	}
2145 	vdev_id = wlan_vdev_get_id(vdev);
2146 
2147 	if (MLME_IS_ROAM_STATE_RSO_ENABLED(psoc, vdev_id)) {
2148 		status = target_if_cm_roam_scan_offload_mode(wmi_handle,
2149 							     &req->rso_config);
2150 		if (QDF_IS_STATUS_ERROR(status)) {
2151 			target_if_err("vdev:%d Send RSO mode cmd failed",
2152 				      req->rso_config.vdev_id);
2153 			goto end;
2154 		}
2155 
2156 		target_if_cm_roam_disconnect_params(
2157 				wmi_handle, ROAM_SCAN_OFFLOAD_UPDATE_CFG,
2158 				&req->disconnect_params);
2159 
2160 		target_if_cm_roam_idle_params(
2161 				wmi_handle, ROAM_SCAN_OFFLOAD_UPDATE_CFG,
2162 				&req->idle_params);
2163 		target_if_cm_roam_triggers(vdev, &req->roam_triggers);
2164 
2165 		if (req->wlan_roam_rt_stats_config)
2166 			target_if_cm_roam_rt_stats_config(
2167 						vdev, vdev_id,
2168 						req->wlan_roam_rt_stats_config);
2169 
2170 		if (req->wlan_roam_ho_delay_config)
2171 			target_if_cm_roam_ho_delay_config(
2172 						vdev, vdev_id,
2173 						req->wlan_roam_ho_delay_config);
2174 
2175 		if (req->wlan_exclude_rm_partial_scan_freq)
2176 			target_if_cm_exclude_rm_partial_scan_freq(
2177 				vdev, req->wlan_exclude_rm_partial_scan_freq);
2178 
2179 		if (req->wlan_roam_full_scan_6ghz_on_disc)
2180 			target_if_cm_roam_full_scan_6ghz_on_disc(
2181 				vdev, req->wlan_roam_full_scan_6ghz_on_disc);
2182 
2183 		is_mcc_disallowed = !wlan_cm_same_band_sta_allowed(psoc);
2184 		target_if_cm_roam_mcc_disallow(vdev, vdev_id,
2185 					       is_mcc_disallowed);
2186 
2187 		if (req->wlan_roam_rssi_diff_6ghz)
2188 			target_if_cm_roam_rssi_diff_6ghz(
2189 					vdev, req->wlan_roam_rssi_diff_6ghz);
2190 
2191 		status = target_if_cm_roam_oem_eht_mlo_bitmap(vdev);
2192 	}
2193 end:
2194 	return status;
2195 }
2196 
2197 /**
2198  * target_if_cm_roam_update_freqs() - Send roam frequencies to fw
2199  * @vdev: vdev object
2200  * @req: roam channels to update to firmware
2201  *
2202  * Return: QDF_STATUS
2203  */
2204 static QDF_STATUS
target_if_cm_roam_update_freqs(struct wlan_objmgr_vdev * vdev,struct wlan_roam_scan_channel_list * req)2205 target_if_cm_roam_update_freqs(struct wlan_objmgr_vdev *vdev,
2206 			       struct wlan_roam_scan_channel_list *req)
2207 {
2208 	QDF_STATUS status = QDF_STATUS_SUCCESS;
2209 	wmi_unified_t wmi_handle;
2210 
2211 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
2212 	if (!wmi_handle)
2213 		return QDF_STATUS_E_FAILURE;
2214 
2215 	status = target_if_cm_roam_offload_chan_list(wmi_handle, req);
2216 	if (QDF_IS_STATUS_ERROR(status))
2217 		target_if_err("vdev:%d Send channel list command failed",
2218 			      req->vdev_id);
2219 
2220 	return status;
2221 }
2222 
2223 /**
2224  * target_if_cm_roam_abort() - Send roam abort to wmi
2225  * @vdev: vdev object
2226  * @vdev_id: vdev id
2227  *
2228  * Return: QDF_STATUS
2229  */
2230 static QDF_STATUS
target_if_cm_roam_abort(struct wlan_objmgr_vdev * vdev,uint8_t vdev_id)2231 target_if_cm_roam_abort(struct wlan_objmgr_vdev *vdev, uint8_t vdev_id)
2232 {
2233 	wmi_unified_t wmi_handle;
2234 
2235 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
2236 	if (!wmi_handle)
2237 		return QDF_STATUS_E_FAILURE;
2238 
2239 	if (!target_if_is_vdev_valid(vdev_id)) {
2240 		target_if_err("Invalid vdev id:%d", vdev_id);
2241 		return QDF_STATUS_E_FAILURE;
2242 	}
2243 	return wmi_unified_roam_scan_offload_cmd(wmi_handle,
2244 						 WMI_ROAM_SCAN_STOP_CMD,
2245 						 vdev_id);
2246 }
2247 
2248 /**
2249  * target_if_cm_roam_per_config() - Send roam per config related
2250  * commands to wmi
2251  * @vdev: vdev object
2252  * @req: roam per config parameters
2253  *
2254  * Return: QDF_STATUS
2255  */
2256 static QDF_STATUS
target_if_cm_roam_per_config(struct wlan_objmgr_vdev * vdev,struct wlan_per_roam_config_req * req)2257 target_if_cm_roam_per_config(struct wlan_objmgr_vdev *vdev,
2258 			     struct wlan_per_roam_config_req *req)
2259 {
2260 	wmi_unified_t wmi_handle;
2261 
2262 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
2263 	if (!wmi_handle)
2264 		return QDF_STATUS_E_FAILURE;
2265 
2266 	return wmi_unified_set_per_roam_config(wmi_handle, req);
2267 }
2268 
2269 /**
2270  * target_if_cm_roam_send_disable_config() - Send roam disable config related
2271  * commands to wmi
2272  * @vdev: vdev object
2273  * @req: roam disable config parameters
2274  *
2275  * Return: QDF_STATUS
2276  */
2277 static QDF_STATUS
target_if_cm_roam_send_disable_config(struct wlan_objmgr_vdev * vdev,struct roam_disable_cfg * req)2278 target_if_cm_roam_send_disable_config(struct wlan_objmgr_vdev *vdev,
2279 				      struct roam_disable_cfg *req)
2280 {
2281 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
2282 	wmi_unified_t wmi_handle;
2283 	struct vdev_mlme_obj *vdev_mlme;
2284 
2285 	vdev_mlme = wlan_vdev_mlme_get_cmpt_obj(vdev);
2286 	if (!vdev_mlme) {
2287 		target_if_err("Failed to get vdev mlme obj!");
2288 		goto end;
2289 	}
2290 
2291 	if (vdev_mlme->mgmt.generic.type != WMI_VDEV_TYPE_STA ||
2292 	    vdev_mlme->mgmt.generic.subtype != 0) {
2293 		target_if_err("This isn't a STA: %d", req->vdev_id);
2294 		goto end;
2295 	}
2296 
2297 	wmi_handle = target_if_cm_roam_get_wmi_handle_from_vdev(vdev);
2298 	if (!wmi_handle)
2299 		goto end;
2300 
2301 	status = target_if_vdev_set_param(
2302 				wmi_handle,
2303 				req->vdev_id,
2304 				wmi_vdev_param_roam_11kv_ctrl,
2305 				req->cfg);
2306 
2307 	if (QDF_IS_STATUS_ERROR(status))
2308 		target_if_err("Failed to set wmi_vdev_param_roam_11kv_ctrl");
2309 
2310 end:
2311 	return status;
2312 }
2313 
2314 /**
2315  * target_if_cm_roam_register_rso_req_ops() - Register rso req tx ops functions
2316  * @tx_ops: tx ops
2317  *
2318  * This function is used to register rso req tx ops functions
2319  *
2320  * Return: none
2321  */
2322 static void
target_if_cm_roam_register_rso_req_ops(struct wlan_cm_roam_tx_ops * tx_ops)2323 target_if_cm_roam_register_rso_req_ops(struct wlan_cm_roam_tx_ops *tx_ops)
2324 {
2325 	tx_ops->send_roam_offload_init_req = target_if_cm_roam_send_roam_init;
2326 	tx_ops->send_roam_start_req = target_if_cm_roam_send_start;
2327 	tx_ops->send_roam_stop_offload = target_if_cm_roam_send_stop;
2328 	tx_ops->send_roam_update_config = target_if_cm_roam_send_update_config;
2329 	tx_ops->send_roam_abort = target_if_cm_roam_abort;
2330 	tx_ops->send_roam_per_config = target_if_cm_roam_per_config;
2331 	tx_ops->send_roam_triggers = target_if_cm_roam_triggers;
2332 	tx_ops->send_roam_disable_config =
2333 					target_if_cm_roam_send_disable_config;
2334 	tx_ops->send_roam_frequencies = target_if_cm_roam_update_freqs;
2335 	target_if_cm_roam_register_mlo_req_ops(tx_ops);
2336 }
2337 
target_if_cm_roam_register_tx_ops(struct wlan_cm_roam_tx_ops * tx_ops)2338 QDF_STATUS target_if_cm_roam_register_tx_ops(struct wlan_cm_roam_tx_ops *tx_ops)
2339 {
2340 	if (!tx_ops) {
2341 		target_if_err("target if tx ops is NULL!");
2342 		return QDF_STATUS_E_INVAL;
2343 	}
2344 
2345 	target_if_cm_roam_register_lfr3_ops(tx_ops);
2346 	target_if_cm_roam_register_rso_req_ops(tx_ops);
2347 
2348 	return QDF_STATUS_SUCCESS;
2349 }
2350