blob: 6f702a21233a34025c284f1eb446fc54cc60da31 [file] [log] [blame]
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001/*
Srinivas Dasaric9e048e2019-12-23 00:45:35 +05302 * Copyright (c) 2012-2020 The Linux Foundation. All rights reserved.
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003 *
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08004 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -080019/**
20 * DOC: wlan_policy_mgr_get_set_utils.c
21 *
22 * WLAN Concurrenct Connection Management APIs
23 *
24 */
25
26/* Include files */
Sourav Mohapatra0c1a7f62017-12-03 11:44:44 +053027#include "target_if.h"
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -080028#include "wlan_policy_mgr_api.h"
29#include "wlan_policy_mgr_i.h"
30#include "qdf_types.h"
31#include "qdf_trace.h"
32#include "wlan_objmgr_global_obj.h"
Ajit Pal Singhc65575e2017-04-17 16:49:01 +053033#include "wlan_objmgr_pdev_obj.h"
34#include "wlan_objmgr_vdev_obj.h"
Nachiket Kukadecf941602018-12-12 14:32:35 +053035#include "wlan_nan_api.h"
36#include "nan_public_structs.h"
Jianmin Zhue487f792019-10-15 13:34:34 +080037#include "wlan_reg_services_api.h"
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -080038
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -080039/* invalid channel id. */
40#define INVALID_CHANNEL_ID 0
41
Krunal Soni1680e412018-12-07 19:42:06 +080042QDF_STATUS
43policy_mgr_get_allow_mcc_go_diff_bi(struct wlan_objmgr_psoc *psoc,
44 uint8_t *allow_mcc_go_diff_bi)
45{
46 struct policy_mgr_psoc_priv_obj *pm_ctx;
47
48 pm_ctx = policy_mgr_get_context(psoc);
49 if (!pm_ctx) {
50 policy_mgr_err("pm_ctx is NULL");
51 return QDF_STATUS_E_FAILURE;
52 }
53 *allow_mcc_go_diff_bi = pm_ctx->cfg.allow_mcc_go_diff_bi;
54
55 return QDF_STATUS_SUCCESS;
56}
57
58QDF_STATUS
59policy_mgr_get_enable_overlap_chnl(struct wlan_objmgr_psoc *psoc,
60 uint8_t *enable_overlap_chnl)
61{
62 struct policy_mgr_psoc_priv_obj *pm_ctx;
63
64 pm_ctx = policy_mgr_get_context(psoc);
65 if (!pm_ctx) {
66 policy_mgr_err("pm_ctx is NULL");
67 return QDF_STATUS_E_FAILURE;
68 }
69 *enable_overlap_chnl = pm_ctx->cfg.enable_overlap_chnl;
70
71 return QDF_STATUS_SUCCESS;
72}
73
gaurank kathpaliae3140292019-11-12 16:44:31 +053074QDF_STATUS policy_mgr_set_dual_mac_feature(struct wlan_objmgr_psoc *psoc,
75 uint8_t dual_mac_feature)
76{
77 struct policy_mgr_psoc_priv_obj *pm_ctx;
78
79 pm_ctx = policy_mgr_get_context(psoc);
80 if (!pm_ctx) {
81 policy_mgr_err("pm_ctx is NULL");
82 return QDF_STATUS_E_FAILURE;
83 }
84
85 pm_ctx->cfg.dual_mac_feature = dual_mac_feature;
86
87 return QDF_STATUS_SUCCESS;
88}
89
Krunal Soni1680e412018-12-07 19:42:06 +080090QDF_STATUS policy_mgr_get_dual_mac_feature(struct wlan_objmgr_psoc *psoc,
91 uint8_t *dual_mac_feature)
92{
93 struct policy_mgr_psoc_priv_obj *pm_ctx;
94
95 pm_ctx = policy_mgr_get_context(psoc);
96 if (!pm_ctx) {
97 policy_mgr_err("pm_ctx is NULL");
98 return QDF_STATUS_E_FAILURE;
99 }
100 *dual_mac_feature = pm_ctx->cfg.dual_mac_feature;
101
102 return QDF_STATUS_SUCCESS;
103}
104
105QDF_STATUS policy_mgr_get_force_1x1(struct wlan_objmgr_psoc *psoc,
106 uint8_t *force_1x1)
107{
108 struct policy_mgr_psoc_priv_obj *pm_ctx;
109
110 pm_ctx = policy_mgr_get_context(psoc);
111 if (!pm_ctx) {
112 policy_mgr_err("pm_ctx is NULL");
113 return QDF_STATUS_E_FAILURE;
114 }
115 *force_1x1 = pm_ctx->cfg.is_force_1x1_enable;
116
117 return QDF_STATUS_SUCCESS;
118}
119
120QDF_STATUS
121policy_mgr_get_sta_sap_scc_on_dfs_chnl(struct wlan_objmgr_psoc *psoc,
122 uint8_t *sta_sap_scc_on_dfs_chnl)
123{
124 struct policy_mgr_psoc_priv_obj *pm_ctx;
125
126 pm_ctx = policy_mgr_get_context(psoc);
127 if (!pm_ctx) {
128 policy_mgr_err("pm_ctx is NULL");
129 return QDF_STATUS_E_FAILURE;
130 }
131 *sta_sap_scc_on_dfs_chnl = pm_ctx->cfg.sta_sap_scc_on_dfs_chnl;
132
133 return QDF_STATUS_SUCCESS;
134}
135
Liangwei Dong24e3f9b2019-04-22 04:35:36 -0400136bool
137policy_mgr_get_dfs_master_dynamic_enabled(
138 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
139{
140 struct policy_mgr_psoc_priv_obj *pm_ctx;
141 bool sta_on_5g = false;
142 bool sta_on_2g = false;
143 uint32_t i;
144 bool enable;
145
146 pm_ctx = policy_mgr_get_context(psoc);
147 if (!pm_ctx) {
148 policy_mgr_err("pm_ctx is NULL");
149 return true;
150 }
151
152 if (!pm_ctx->cfg.sta_sap_scc_on_dfs_chnl)
153 return true;
154 if (pm_ctx->cfg.sta_sap_scc_on_dfs_chnl ==
155 PM_STA_SAP_ON_DFS_MASTER_MODE_DISABLED)
156 return false;
157 if (pm_ctx->cfg.sta_sap_scc_on_dfs_chnl !=
158 PM_STA_SAP_ON_DFS_MASTER_MODE_FLEX) {
159 policy_mgr_debug("sta_sap_scc_on_dfs_chnl %d unknown",
160 pm_ctx->cfg.sta_sap_scc_on_dfs_chnl);
161 return true;
162 }
163
164 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
165 for (i = 0; i < MAX_NUMBER_OF_CONC_CONNECTIONS; i++) {
166 if (!((pm_conc_connection_list[i].vdev_id != vdev_id) &&
167 pm_conc_connection_list[i].in_use &&
168 (pm_conc_connection_list[i].mode == PM_STA_MODE ||
169 pm_conc_connection_list[i].mode == PM_P2P_CLIENT_MODE)))
170 continue;
Manikandan Mohan932c11e2019-08-14 14:09:08 -0700171 if (WLAN_REG_IS_5GHZ_CH_FREQ(pm_conc_connection_list[i].freq))
Liangwei Dong24e3f9b2019-04-22 04:35:36 -0400172 sta_on_5g = true;
173 else
174 sta_on_2g = true;
175 }
176 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
177
178 if (policy_mgr_is_hw_dbs_capable(psoc) && !sta_on_5g)
179 enable = true;
180 else if (!sta_on_5g && !sta_on_2g)
181 enable = true;
182 else
183 enable = false;
184 policy_mgr_debug("sta_sap_scc_on_dfs_chnl %d sta_on_2g %d sta_on_5g %d enable %d",
185 pm_ctx->cfg.sta_sap_scc_on_dfs_chnl, sta_on_2g,
186 sta_on_5g, enable);
187
188 return enable;
189}
190
Krunal Soni1680e412018-12-07 19:42:06 +0800191QDF_STATUS
192policy_mgr_get_sta_sap_scc_lte_coex_chnl(struct wlan_objmgr_psoc *psoc,
193 uint8_t *sta_sap_scc_lte_coex)
194{
195 struct policy_mgr_psoc_priv_obj *pm_ctx;
196
197 pm_ctx = policy_mgr_get_context(psoc);
198 if (!pm_ctx) {
199 policy_mgr_err("pm_ctx is NULL");
200 return QDF_STATUS_E_FAILURE;
201 }
202 *sta_sap_scc_lte_coex = pm_ctx->cfg.sta_sap_scc_on_lte_coex_chnl;
203
204 return QDF_STATUS_SUCCESS;
205}
206
207QDF_STATUS policy_mgr_get_sap_mandt_chnl(struct wlan_objmgr_psoc *psoc,
208 uint8_t *sap_mandt_chnl)
209{
210 struct policy_mgr_psoc_priv_obj *pm_ctx;
211
212 pm_ctx = policy_mgr_get_context(psoc);
213 if (!pm_ctx) {
214 policy_mgr_err("pm_ctx is NULL");
215 return QDF_STATUS_E_FAILURE;
216 }
217 *sap_mandt_chnl = pm_ctx->cfg.sap_mandatory_chnl_enable;
218
219 return QDF_STATUS_SUCCESS;
220}
221
222QDF_STATUS
223policy_mgr_get_indoor_chnl_marking(struct wlan_objmgr_psoc *psoc,
224 uint8_t *indoor_chnl_marking)
225{
226 struct policy_mgr_psoc_priv_obj *pm_ctx;
227
228 pm_ctx = policy_mgr_get_context(psoc);
229 if (!pm_ctx) {
230 policy_mgr_err("pm_ctx is NULL");
231 return QDF_STATUS_E_FAILURE;
232 }
233 *indoor_chnl_marking = pm_ctx->cfg.mark_indoor_chnl_disable;
234
235 return QDF_STATUS_SUCCESS;
236}
237
Krunal Soni42e98ab2018-09-27 18:35:21 -0700238QDF_STATUS policy_mgr_get_mcc_scc_switch(struct wlan_objmgr_psoc *psoc,
239 uint8_t *mcc_scc_switch)
240{
241 struct policy_mgr_psoc_priv_obj *pm_ctx;
242
243 pm_ctx = policy_mgr_get_context(psoc);
244 if (!pm_ctx) {
245 policy_mgr_err("pm_ctx is NULL");
246 return QDF_STATUS_E_FAILURE;
247 }
248 *mcc_scc_switch = pm_ctx->cfg.mcc_to_scc_switch;
249
250 return QDF_STATUS_SUCCESS;
251}
252
253QDF_STATUS policy_mgr_get_sys_pref(struct wlan_objmgr_psoc *psoc,
254 uint8_t *sys_pref)
255{
256 struct policy_mgr_psoc_priv_obj *pm_ctx;
257
258 pm_ctx = policy_mgr_get_context(psoc);
259 if (!pm_ctx) {
260 policy_mgr_err("pm_ctx is NULL");
261 return QDF_STATUS_E_FAILURE;
262 }
263 *sys_pref = pm_ctx->cfg.sys_pref;
264
265 return QDF_STATUS_SUCCESS;
266}
267
Krunal Soni6dd22082018-09-27 10:40:24 -0700268QDF_STATUS policy_mgr_set_sys_pref(struct wlan_objmgr_psoc *psoc,
269 uint8_t sys_pref)
270{
271 struct policy_mgr_psoc_priv_obj *pm_ctx;
272
273 pm_ctx = policy_mgr_get_context(psoc);
274 if (!pm_ctx) {
275 policy_mgr_err("pm_ctx is NULL");
276 return QDF_STATUS_E_FAILURE;
277 }
278 pm_ctx->cfg.sys_pref = sys_pref;
279
280 return QDF_STATUS_SUCCESS;
281}
282
Krunal Soni42e98ab2018-09-27 18:35:21 -0700283QDF_STATUS policy_mgr_get_conc_rule1(struct wlan_objmgr_psoc *psoc,
284 uint8_t *conc_rule1)
285{
286 struct policy_mgr_psoc_priv_obj *pm_ctx;
287
288 pm_ctx = policy_mgr_get_context(psoc);
289 if (!pm_ctx) {
290 policy_mgr_err("pm_ctx is NULL");
291 return QDF_STATUS_E_FAILURE;
292 }
293 *conc_rule1 = pm_ctx->cfg.conc_rule1;
294
295 return QDF_STATUS_SUCCESS;
296}
297
298QDF_STATUS policy_mgr_get_conc_rule2(struct wlan_objmgr_psoc *psoc,
299 uint8_t *conc_rule2)
300{
301 struct policy_mgr_psoc_priv_obj *pm_ctx;
302
303 pm_ctx = policy_mgr_get_context(psoc);
304 if (!pm_ctx) {
305 policy_mgr_err("pm_ctx is NULL");
306 return QDF_STATUS_E_FAILURE;
307 }
308 *conc_rule2 = pm_ctx->cfg.conc_rule2;
309
310 return QDF_STATUS_SUCCESS;
311}
312
Krunal Soni42e98ab2018-09-27 18:35:21 -0700313QDF_STATUS policy_mgr_get_chnl_select_plcy(struct wlan_objmgr_psoc *psoc,
gaurank kathpalia34fe0b62019-11-13 11:08:26 +0530314 uint32_t *chnl_select_plcy)
Krunal Soni42e98ab2018-09-27 18:35:21 -0700315{
316 struct policy_mgr_psoc_priv_obj *pm_ctx;
317
318 pm_ctx = policy_mgr_get_context(psoc);
319 if (!pm_ctx) {
320 policy_mgr_err("pm_ctx is NULL");
321 return QDF_STATUS_E_FAILURE;
322 }
323 *chnl_select_plcy = pm_ctx->cfg.chnl_select_plcy;
324
325 return QDF_STATUS_SUCCESS;
326}
327
gaurank kathpalia34fe0b62019-11-13 11:08:26 +0530328QDF_STATUS policy_mgr_set_ch_select_plcy(struct wlan_objmgr_psoc *psoc,
329 uint32_t ch_select_policy)
330{
331 struct policy_mgr_psoc_priv_obj *pm_ctx;
332
333 pm_ctx = policy_mgr_get_context(psoc);
334 if (!pm_ctx) {
335 policy_mgr_err("pm_ctx is NULL");
336 return QDF_STATUS_E_FAILURE;
337 }
338 pm_ctx->cfg.chnl_select_plcy = ch_select_policy;
339
340 return QDF_STATUS_SUCCESS;
341}
342
Krunal Sonic9af4062018-09-27 14:31:20 -0700343QDF_STATUS policy_mgr_get_mcc_adaptive_sch(struct wlan_objmgr_psoc *psoc,
344 uint8_t *enable_mcc_adaptive_sch)
345{
346 struct policy_mgr_psoc_priv_obj *pm_ctx;
347
348 pm_ctx = policy_mgr_get_context(psoc);
349 if (!pm_ctx) {
350 policy_mgr_err("pm_ctx is NULL");
351 return QDF_STATUS_E_FAILURE;
352 }
353 *enable_mcc_adaptive_sch = pm_ctx->cfg.enable_mcc_adaptive_sch;
354
355 return QDF_STATUS_SUCCESS;
356}
Krunal Soni42e98ab2018-09-27 18:35:21 -0700357
Krunal Sonidd8bf402018-09-27 17:34:25 -0700358QDF_STATUS policy_mgr_get_sta_cxn_5g_band(struct wlan_objmgr_psoc *psoc,
359 uint8_t *enable_sta_cxn_5g_band)
360{
361 struct policy_mgr_psoc_priv_obj *pm_ctx;
362
363 pm_ctx = policy_mgr_get_context(psoc);
364 if (!pm_ctx) {
365 policy_mgr_err("pm_ctx is NULL");
366 return QDF_STATUS_E_FAILURE;
367 }
368 *enable_sta_cxn_5g_band = pm_ctx->cfg.enable_sta_cxn_5g_band;
369
370 return QDF_STATUS_SUCCESS;
371}
372
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700373void policy_mgr_update_new_hw_mode_index(struct wlan_objmgr_psoc *psoc,
374 uint32_t new_hw_mode_index)
375{
376 struct policy_mgr_psoc_priv_obj *pm_ctx;
377
378 pm_ctx = policy_mgr_get_context(psoc);
379 if (!pm_ctx) {
380 policy_mgr_err("Invalid Context");
381 return;
382 }
383 pm_ctx->new_hw_mode_index = new_hw_mode_index;
384}
385
386void policy_mgr_update_old_hw_mode_index(struct wlan_objmgr_psoc *psoc,
387 uint32_t old_hw_mode_index)
388{
389 struct policy_mgr_psoc_priv_obj *pm_ctx;
390
391 pm_ctx = policy_mgr_get_context(psoc);
392 if (!pm_ctx) {
393 policy_mgr_err("Invalid Context");
394 return;
395 }
396 pm_ctx->old_hw_mode_index = old_hw_mode_index;
397}
398
399void policy_mgr_update_hw_mode_index(struct wlan_objmgr_psoc *psoc,
400 uint32_t new_hw_mode_index)
401{
402 struct policy_mgr_psoc_priv_obj *pm_ctx;
403
404 pm_ctx = policy_mgr_get_context(psoc);
405 if (!pm_ctx) {
406 policy_mgr_err("Invalid Context");
407 return;
408 }
409 if (POLICY_MGR_DEFAULT_HW_MODE_INDEX == pm_ctx->new_hw_mode_index) {
410 pm_ctx->new_hw_mode_index = new_hw_mode_index;
411 } else {
412 pm_ctx->old_hw_mode_index = pm_ctx->new_hw_mode_index;
413 pm_ctx->new_hw_mode_index = new_hw_mode_index;
414 }
415 policy_mgr_debug("Updated: old_hw_mode_index:%d new_hw_mode_index:%d",
416 pm_ctx->old_hw_mode_index, pm_ctx->new_hw_mode_index);
417}
418
419/**
420 * policy_mgr_get_num_of_setbits_from_bitmask() - to get num of
421 * setbits from bitmask
422 * @mask: given bitmask
423 *
424 * This helper function should return number of setbits from bitmask
425 *
426 * Return: number of setbits from bitmask
427 */
428static uint32_t policy_mgr_get_num_of_setbits_from_bitmask(uint32_t mask)
429{
430 uint32_t num_of_setbits = 0;
431
432 while (mask) {
433 mask &= (mask - 1);
434 num_of_setbits++;
435 }
436 return num_of_setbits;
437}
438
439/**
440 * policy_mgr_map_wmi_channel_width_to_hw_mode_bw() - returns
441 * bandwidth in terms of hw_mode_bandwidth
442 * @width: bandwidth in terms of wmi_channel_width
443 *
444 * This function returns the bandwidth in terms of hw_mode_bandwidth.
445 *
446 * Return: BW in terms of hw_mode_bandwidth.
447 */
448static enum hw_mode_bandwidth policy_mgr_map_wmi_channel_width_to_hw_mode_bw(
449 wmi_channel_width width)
450{
451 switch (width) {
452 case WMI_CHAN_WIDTH_20:
453 return HW_MODE_20_MHZ;
454 case WMI_CHAN_WIDTH_40:
455 return HW_MODE_40_MHZ;
456 case WMI_CHAN_WIDTH_80:
457 return HW_MODE_80_MHZ;
458 case WMI_CHAN_WIDTH_160:
459 return HW_MODE_160_MHZ;
460 case WMI_CHAN_WIDTH_80P80:
461 return HW_MODE_80_PLUS_80_MHZ;
462 case WMI_CHAN_WIDTH_5:
463 return HW_MODE_5_MHZ;
464 case WMI_CHAN_WIDTH_10:
465 return HW_MODE_10_MHZ;
466 default:
467 return HW_MODE_BW_NONE;
468 }
469
470 return HW_MODE_BW_NONE;
471}
472
Arunk Khandavalli24167fc2018-02-05 15:42:31 +0530473static void policy_mgr_get_hw_mode_params(
474 struct wlan_psoc_host_mac_phy_caps *caps,
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700475 struct policy_mgr_mac_ss_bw_info *info)
476{
477 if (!caps) {
478 policy_mgr_err("Invalid capabilities");
479 return;
480 }
481
482 info->mac_tx_stream = policy_mgr_get_num_of_setbits_from_bitmask(
483 QDF_MAX(caps->tx_chain_mask_2G,
484 caps->tx_chain_mask_5G));
485 info->mac_rx_stream = policy_mgr_get_num_of_setbits_from_bitmask(
486 QDF_MAX(caps->rx_chain_mask_2G,
487 caps->rx_chain_mask_5G));
488 info->mac_bw = policy_mgr_map_wmi_channel_width_to_hw_mode_bw(
489 QDF_MAX(caps->max_bw_supported_2G,
490 caps->max_bw_supported_5G));
Liangwei Donge57b6b72018-05-21 04:51:47 -0400491 info->mac_band_cap = caps->supported_bands;
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700492}
493
494/**
495 * policy_mgr_set_hw_mode_params() - sets TX-RX stream,
496 * bandwidth and DBS in hw_mode_list
497 * @wma_handle: pointer to wma global structure
498 * @mac0_ss_bw_info: TX-RX streams, BW for MAC0
499 * @mac1_ss_bw_info: TX-RX streams, BW for MAC1
Liangwei Donge57b6b72018-05-21 04:51:47 -0400500 * @pos: refers to hw_mode_list array index
501 * @hw_mode_id: hw mode id value used by firmware
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700502 * @dbs_mode: dbs_mode for the dbs_hw_mode
503 * @sbs_mode: sbs_mode for the sbs_hw_mode
504 *
505 * This function sets TX-RX stream, bandwidth and DBS mode in
506 * hw_mode_list.
507 *
508 * Return: none
509 */
510static void policy_mgr_set_hw_mode_params(struct wlan_objmgr_psoc *psoc,
511 struct policy_mgr_mac_ss_bw_info mac0_ss_bw_info,
512 struct policy_mgr_mac_ss_bw_info mac1_ss_bw_info,
Liangwei Donge57b6b72018-05-21 04:51:47 -0400513 uint32_t pos, uint32_t hw_mode_id, uint32_t dbs_mode,
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700514 uint32_t sbs_mode)
515{
516 struct policy_mgr_psoc_priv_obj *pm_ctx;
517
518 pm_ctx = policy_mgr_get_context(psoc);
519 if (!pm_ctx) {
520 policy_mgr_err("Invalid Context");
521 return;
522 }
523
524 POLICY_MGR_HW_MODE_MAC0_TX_STREAMS_SET(
525 pm_ctx->hw_mode.hw_mode_list[pos],
526 mac0_ss_bw_info.mac_tx_stream);
527 POLICY_MGR_HW_MODE_MAC0_RX_STREAMS_SET(
528 pm_ctx->hw_mode.hw_mode_list[pos],
529 mac0_ss_bw_info.mac_rx_stream);
530 POLICY_MGR_HW_MODE_MAC0_BANDWIDTH_SET(
531 pm_ctx->hw_mode.hw_mode_list[pos],
532 mac0_ss_bw_info.mac_bw);
533 POLICY_MGR_HW_MODE_MAC1_TX_STREAMS_SET(
534 pm_ctx->hw_mode.hw_mode_list[pos],
535 mac1_ss_bw_info.mac_tx_stream);
536 POLICY_MGR_HW_MODE_MAC1_RX_STREAMS_SET(
537 pm_ctx->hw_mode.hw_mode_list[pos],
538 mac1_ss_bw_info.mac_rx_stream);
539 POLICY_MGR_HW_MODE_MAC1_BANDWIDTH_SET(
540 pm_ctx->hw_mode.hw_mode_list[pos],
541 mac1_ss_bw_info.mac_bw);
542 POLICY_MGR_HW_MODE_DBS_MODE_SET(
543 pm_ctx->hw_mode.hw_mode_list[pos],
544 dbs_mode);
545 POLICY_MGR_HW_MODE_AGILE_DFS_SET(
546 pm_ctx->hw_mode.hw_mode_list[pos],
547 HW_MODE_AGILE_DFS_NONE);
548 POLICY_MGR_HW_MODE_SBS_MODE_SET(
549 pm_ctx->hw_mode.hw_mode_list[pos],
550 sbs_mode);
Liangwei Donge57b6b72018-05-21 04:51:47 -0400551 POLICY_MGR_HW_MODE_MAC0_BAND_SET(
552 pm_ctx->hw_mode.hw_mode_list[pos],
553 mac0_ss_bw_info.mac_band_cap);
554 POLICY_MGR_HW_MODE_ID_SET(
555 pm_ctx->hw_mode.hw_mode_list[pos],
556 hw_mode_id);
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700557}
558
559QDF_STATUS policy_mgr_update_hw_mode_list(struct wlan_objmgr_psoc *psoc,
Arunk Khandavalli24167fc2018-02-05 15:42:31 +0530560 struct target_psoc_info *tgt_hdl)
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700561{
Arunk Khandavalli24167fc2018-02-05 15:42:31 +0530562 struct wlan_psoc_host_mac_phy_caps *tmp;
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700563 uint32_t i, hw_config_type, j = 0;
564 uint32_t dbs_mode, sbs_mode;
565 struct policy_mgr_mac_ss_bw_info mac0_ss_bw_info = {0};
566 struct policy_mgr_mac_ss_bw_info mac1_ss_bw_info = {0};
567 struct policy_mgr_psoc_priv_obj *pm_ctx;
Arunk Khandavalli24167fc2018-02-05 15:42:31 +0530568 struct tgt_info *info;
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700569
570 pm_ctx = policy_mgr_get_context(psoc);
571 if (!pm_ctx) {
572 policy_mgr_err("Invalid Context");
573 return QDF_STATUS_E_FAILURE;
574 }
575
Arunk Khandavalli24167fc2018-02-05 15:42:31 +0530576 info = &tgt_hdl->info;
577 if (!info->service_ext_param.num_hw_modes) {
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700578 policy_mgr_err("Number of HW modes: %d",
Arunk Khandavalli24167fc2018-02-05 15:42:31 +0530579 info->service_ext_param.num_hw_modes);
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700580 return QDF_STATUS_E_FAILURE;
581 }
582
583 /*
584 * This list was updated as part of service ready event. Re-populate
585 * HW mode list from the device capabilities.
586 */
587 if (pm_ctx->hw_mode.hw_mode_list) {
588 qdf_mem_free(pm_ctx->hw_mode.hw_mode_list);
589 pm_ctx->hw_mode.hw_mode_list = NULL;
Tushnim Bhattacharyya8b60ebb2017-08-17 14:53:07 -0700590 policy_mgr_debug("DBS list is freed");
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700591 }
592
Arunk Khandavalli24167fc2018-02-05 15:42:31 +0530593 pm_ctx->num_dbs_hw_modes = info->service_ext_param.num_hw_modes;
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700594 pm_ctx->hw_mode.hw_mode_list =
595 qdf_mem_malloc(sizeof(*pm_ctx->hw_mode.hw_mode_list) *
596 pm_ctx->num_dbs_hw_modes);
597 if (!pm_ctx->hw_mode.hw_mode_list) {
598 policy_mgr_err("Memory allocation failed for DBS");
599 return QDF_STATUS_E_FAILURE;
600 }
601
Tushnim Bhattacharyya8b60ebb2017-08-17 14:53:07 -0700602 policy_mgr_debug("Updated HW mode list: Num modes:%d",
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700603 pm_ctx->num_dbs_hw_modes);
604
605 for (i = 0; i < pm_ctx->num_dbs_hw_modes; i++) {
606 /* Update for MAC0 */
Arunk Khandavalli24167fc2018-02-05 15:42:31 +0530607 tmp = &info->mac_phy_cap[j++];
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700608 policy_mgr_get_hw_mode_params(tmp, &mac0_ss_bw_info);
Arunk Khandavalli24167fc2018-02-05 15:42:31 +0530609 hw_config_type = tmp->hw_mode_config_type;
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700610 dbs_mode = HW_MODE_DBS_NONE;
611 sbs_mode = HW_MODE_SBS_NONE;
612 mac1_ss_bw_info.mac_tx_stream = 0;
613 mac1_ss_bw_info.mac_rx_stream = 0;
614 mac1_ss_bw_info.mac_bw = 0;
615
616 /* SBS and DBS have dual MAC. Upto 2 MACs are considered. */
617 if ((hw_config_type == WMI_HW_MODE_DBS) ||
618 (hw_config_type == WMI_HW_MODE_SBS_PASSIVE) ||
619 (hw_config_type == WMI_HW_MODE_SBS)) {
620 /* Update for MAC1 */
Arunk Khandavalli24167fc2018-02-05 15:42:31 +0530621 tmp = &info->mac_phy_cap[j++];
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700622 policy_mgr_get_hw_mode_params(tmp, &mac1_ss_bw_info);
623 if (hw_config_type == WMI_HW_MODE_DBS)
624 dbs_mode = HW_MODE_DBS;
625 if ((hw_config_type == WMI_HW_MODE_SBS_PASSIVE) ||
626 (hw_config_type == WMI_HW_MODE_SBS))
627 sbs_mode = HW_MODE_SBS;
628 }
629
630 /* Updating HW mode list */
631 policy_mgr_set_hw_mode_params(psoc, mac0_ss_bw_info,
Liangwei Donge57b6b72018-05-21 04:51:47 -0400632 mac1_ss_bw_info, i, tmp->hw_mode_id, dbs_mode,
633 sbs_mode);
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700634 }
635 return QDF_STATUS_SUCCESS;
636}
637
638void policy_mgr_init_dbs_hw_mode(struct wlan_objmgr_psoc *psoc,
639 uint32_t num_dbs_hw_modes,
640 uint32_t *ev_wlan_dbs_hw_mode_list)
641{
642 struct policy_mgr_psoc_priv_obj *pm_ctx;
643
644 pm_ctx = policy_mgr_get_context(psoc);
645 if (!pm_ctx) {
646 policy_mgr_err("Invalid Context");
647 return;
648 }
649
650 pm_ctx->num_dbs_hw_modes = num_dbs_hw_modes;
651 pm_ctx->hw_mode.hw_mode_list =
652 qdf_mem_malloc(sizeof(*pm_ctx->hw_mode.hw_mode_list) *
653 pm_ctx->num_dbs_hw_modes);
654 if (!pm_ctx->hw_mode.hw_mode_list) {
655 policy_mgr_err("Memory allocation failed for DBS");
656 return;
657 }
658 qdf_mem_copy(pm_ctx->hw_mode.hw_mode_list,
659 ev_wlan_dbs_hw_mode_list,
660 (sizeof(*pm_ctx->hw_mode.hw_mode_list) *
661 pm_ctx->num_dbs_hw_modes));
662}
663
664void policy_mgr_dump_dbs_hw_mode(struct wlan_objmgr_psoc *psoc)
665{
666 uint32_t i, param;
667 struct policy_mgr_psoc_priv_obj *pm_ctx;
668
669 pm_ctx = policy_mgr_get_context(psoc);
670 if (!pm_ctx) {
671 policy_mgr_err("Invalid Context");
672 return;
673 }
674
675 for (i = 0; i < pm_ctx->num_dbs_hw_modes; i++) {
676 param = pm_ctx->hw_mode.hw_mode_list[i];
Liangwei Donge57b6b72018-05-21 04:51:47 -0400677 policy_mgr_debug("[%d]-MAC0: tx_ss:%d rx_ss:%d bw_idx:%d band_cap:%d",
678 i,
679 POLICY_MGR_HW_MODE_MAC0_TX_STREAMS_GET(param),
680 POLICY_MGR_HW_MODE_MAC0_RX_STREAMS_GET(param),
681 POLICY_MGR_HW_MODE_MAC0_BANDWIDTH_GET(param),
682 POLICY_MGR_HW_MODE_MAC0_BAND_GET(param));
Tushnim Bhattacharyya8b60ebb2017-08-17 14:53:07 -0700683 policy_mgr_debug("[%d]-MAC1: tx_ss:%d rx_ss:%d bw_idx:%d",
Liangwei Donge57b6b72018-05-21 04:51:47 -0400684 i,
685 POLICY_MGR_HW_MODE_MAC1_TX_STREAMS_GET(param),
686 POLICY_MGR_HW_MODE_MAC1_RX_STREAMS_GET(param),
687 POLICY_MGR_HW_MODE_MAC1_BANDWIDTH_GET(param));
688 policy_mgr_debug("[%d] DBS:%d SBS:%d hw_mode_id:%d", i,
689 POLICY_MGR_HW_MODE_DBS_MODE_GET(param),
690 POLICY_MGR_HW_MODE_SBS_MODE_GET(param),
691 POLICY_MGR_HW_MODE_ID_GET(param));
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700692 }
693}
694
695void policy_mgr_init_dbs_config(struct wlan_objmgr_psoc *psoc,
696 uint32_t scan_config, uint32_t fw_config)
697{
698 struct policy_mgr_psoc_priv_obj *pm_ctx;
Bala Venkatesh9391de32019-01-25 12:57:20 +0530699 uint8_t dual_mac_feature;
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700700
701 pm_ctx = policy_mgr_get_context(psoc);
702 if (!pm_ctx) {
703 policy_mgr_err("Invalid Context");
704 return;
705 }
706 pm_ctx->dual_mac_cfg.cur_scan_config = 0;
707 pm_ctx->dual_mac_cfg.cur_fw_mode_config = 0;
708
Bala Venkatesh9391de32019-01-25 12:57:20 +0530709 dual_mac_feature = pm_ctx->cfg.dual_mac_feature;
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700710 /* If dual mac features are disabled in the INI, we
711 * need not proceed further
712 */
Bala Venkatesh9391de32019-01-25 12:57:20 +0530713 if (dual_mac_feature == DISABLE_DBS_CXN_AND_SCAN) {
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700714 policy_mgr_err("Disabling dual mac capabilities");
Jeff Johnson656fa9a2018-05-06 00:15:04 -0700715 /* All capabilities are initialized to 0. We can return */
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700716 goto done;
717 }
718
719 /* Initialize concurrent_scan_config_bits with default FW value */
Tushnim Bhattacharyyaecc6e102017-05-26 18:25:56 -0700720 WMI_DBS_CONC_SCAN_CFG_ASYNC_DBS_SCAN_SET(
721 pm_ctx->dual_mac_cfg.cur_scan_config,
722 WMI_DBS_CONC_SCAN_CFG_ASYNC_DBS_SCAN_GET(scan_config));
723 WMI_DBS_CONC_SCAN_CFG_SYNC_DBS_SCAN_SET(
724 pm_ctx->dual_mac_cfg.cur_scan_config,
725 WMI_DBS_CONC_SCAN_CFG_SYNC_DBS_SCAN_GET(scan_config));
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700726 WMI_DBS_CONC_SCAN_CFG_DBS_SCAN_SET(
727 pm_ctx->dual_mac_cfg.cur_scan_config,
728 WMI_DBS_CONC_SCAN_CFG_DBS_SCAN_GET(scan_config));
729 WMI_DBS_CONC_SCAN_CFG_AGILE_SCAN_SET(
730 pm_ctx->dual_mac_cfg.cur_scan_config,
731 WMI_DBS_CONC_SCAN_CFG_AGILE_SCAN_GET(scan_config));
732 WMI_DBS_CONC_SCAN_CFG_AGILE_DFS_SCAN_SET(
733 pm_ctx->dual_mac_cfg.cur_scan_config,
734 WMI_DBS_CONC_SCAN_CFG_AGILE_DFS_SCAN_GET(scan_config));
735
736 /* Initialize fw_mode_config_bits with default FW value */
737 WMI_DBS_FW_MODE_CFG_DBS_SET(
738 pm_ctx->dual_mac_cfg.cur_fw_mode_config,
739 WMI_DBS_FW_MODE_CFG_DBS_GET(fw_config));
740 WMI_DBS_FW_MODE_CFG_AGILE_DFS_SET(
741 pm_ctx->dual_mac_cfg.cur_fw_mode_config,
742 WMI_DBS_FW_MODE_CFG_AGILE_DFS_GET(fw_config));
Tushnim Bhattacharyyaecc6e102017-05-26 18:25:56 -0700743 WMI_DBS_FW_MODE_CFG_DBS_FOR_CXN_SET(
744 pm_ctx->dual_mac_cfg.cur_fw_mode_config,
745 WMI_DBS_FW_MODE_CFG_DBS_FOR_CXN_GET(fw_config));
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -0700746done:
747 /* Initialize the previous scan/fw mode config */
748 pm_ctx->dual_mac_cfg.prev_scan_config =
749 pm_ctx->dual_mac_cfg.cur_scan_config;
750 pm_ctx->dual_mac_cfg.prev_fw_mode_config =
751 pm_ctx->dual_mac_cfg.cur_fw_mode_config;
752
753 policy_mgr_debug("cur_scan_config:%x cur_fw_mode_config:%x",
754 pm_ctx->dual_mac_cfg.cur_scan_config,
755 pm_ctx->dual_mac_cfg.cur_fw_mode_config);
756}
757
758void policy_mgr_update_dbs_scan_config(struct wlan_objmgr_psoc *psoc)
759{
760 struct policy_mgr_psoc_priv_obj *pm_ctx;
761
762 pm_ctx = policy_mgr_get_context(psoc);
763 if (!pm_ctx) {
764 policy_mgr_err("Invalid Context");
765 return;
766 }
767
768 pm_ctx->dual_mac_cfg.prev_scan_config =
769 pm_ctx->dual_mac_cfg.cur_scan_config;
770 pm_ctx->dual_mac_cfg.cur_scan_config =
771 pm_ctx->dual_mac_cfg.req_scan_config;
772}
773
774void policy_mgr_update_dbs_fw_config(struct wlan_objmgr_psoc *psoc)
775{
776 struct policy_mgr_psoc_priv_obj *pm_ctx;
777
778 pm_ctx = policy_mgr_get_context(psoc);
779 if (!pm_ctx) {
780 policy_mgr_err("Invalid Context");
781 return;
782 }
783
784 pm_ctx->dual_mac_cfg.prev_fw_mode_config =
785 pm_ctx->dual_mac_cfg.cur_fw_mode_config;
786 pm_ctx->dual_mac_cfg.cur_fw_mode_config =
787 pm_ctx->dual_mac_cfg.req_fw_mode_config;
788}
789
790void policy_mgr_update_dbs_req_config(struct wlan_objmgr_psoc *psoc,
791 uint32_t scan_config, uint32_t fw_mode_config)
792{
793 struct policy_mgr_psoc_priv_obj *pm_ctx;
794
795 pm_ctx = policy_mgr_get_context(psoc);
796 if (!pm_ctx) {
797 policy_mgr_err("Invalid Context");
798 return;
799 }
800 pm_ctx->dual_mac_cfg.req_scan_config = scan_config;
801 pm_ctx->dual_mac_cfg.req_fw_mode_config = fw_mode_config;
802}
803
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -0800804bool policy_mgr_get_dbs_plus_agile_scan_config(struct wlan_objmgr_psoc *psoc)
805{
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800806 uint32_t scan_config;
807 struct policy_mgr_psoc_priv_obj *pm_ctx;
808
809 if (policy_mgr_is_dual_mac_disabled_in_ini(psoc))
810 return false;
811
812
813 pm_ctx = policy_mgr_get_context(psoc);
814 if (!pm_ctx) {
815 policy_mgr_err("Invalid Context");
816 /* We take that it is disabled and proceed */
817 return false;
818 }
819 scan_config = pm_ctx->dual_mac_cfg.cur_scan_config;
820
821 return WMI_DBS_CONC_SCAN_CFG_AGILE_SCAN_GET(scan_config);
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -0800822}
823
824bool policy_mgr_get_single_mac_scan_with_dfs_config(
825 struct wlan_objmgr_psoc *psoc)
826{
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800827 uint32_t scan_config;
828 struct policy_mgr_psoc_priv_obj *pm_ctx;
829
830 if (policy_mgr_is_dual_mac_disabled_in_ini(psoc))
831 return false;
832
833
834 pm_ctx = policy_mgr_get_context(psoc);
835 if (!pm_ctx) {
836 policy_mgr_err("Invalid Context");
837 /* We take that it is disabled and proceed */
838 return false;
839 }
840 scan_config = pm_ctx->dual_mac_cfg.cur_scan_config;
841
842 return WMI_DBS_CONC_SCAN_CFG_AGILE_DFS_SCAN_GET(scan_config);
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -0800843}
844
845int8_t policy_mgr_get_num_dbs_hw_modes(struct wlan_objmgr_psoc *psoc)
846{
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800847 struct policy_mgr_psoc_priv_obj *pm_ctx;
848
849 pm_ctx = policy_mgr_get_context(psoc);
850 if (!pm_ctx) {
851 policy_mgr_err("Invalid Context");
852 return -EINVAL;
853 }
854 return pm_ctx->num_dbs_hw_modes;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -0800855}
856
Krunal Sonie64b17e2018-12-13 16:00:02 -0800857bool policy_mgr_find_if_fw_supports_dbs(struct wlan_objmgr_psoc *psoc)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -0800858{
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800859 struct policy_mgr_psoc_priv_obj *pm_ctx;
Tushnim Bhattacharyya5dd541e2018-08-30 10:20:31 -0700860 struct wmi_unified *wmi_handle;
Krunal Sonie64b17e2018-12-13 16:00:02 -0800861 bool dbs_support;
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800862
863 pm_ctx = policy_mgr_get_context(psoc);
Sourav Mohapatra0c1a7f62017-12-03 11:44:44 +0530864
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800865 if (!pm_ctx) {
866 policy_mgr_err("Invalid Context");
867 return false;
868 }
Tushnim Bhattacharyya5dd541e2018-08-30 10:20:31 -0700869 wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
Sourav Mohapatra0c1a7f62017-12-03 11:44:44 +0530870 if (!wmi_handle) {
Tushnim Bhattacharyya5dd541e2018-08-30 10:20:31 -0700871 policy_mgr_debug("Invalid WMI handle");
Sourav Mohapatra0c1a7f62017-12-03 11:44:44 +0530872 return false;
873 }
Krunal Sonie64b17e2018-12-13 16:00:02 -0800874 dbs_support =
875 wmi_service_enabled(wmi_handle,
876 wmi_service_dual_band_simultaneous_support);
Sourav Mohapatra0c1a7f62017-12-03 11:44:44 +0530877
878 /* The agreement with FW is that: To know if the target is DBS
879 * capable, DBS needs to be supported both in the HW mode list
880 * and in the service ready event
881 */
Krunal Sonie64b17e2018-12-13 16:00:02 -0800882 if (!dbs_support)
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800883 return false;
884
Krunal Sonie64b17e2018-12-13 16:00:02 -0800885 return true;
886}
887
gaurank kathpaliae3140292019-11-12 16:44:31 +0530888bool policy_mgr_find_if_hwlist_has_dbs(struct wlan_objmgr_psoc *psoc)
Krunal Sonie64b17e2018-12-13 16:00:02 -0800889{
890 struct policy_mgr_psoc_priv_obj *pm_ctx;
891 uint32_t param, i, found = 0;
892
893 pm_ctx = policy_mgr_get_context(psoc);
894
895 if (!pm_ctx) {
896 policy_mgr_err("Invalid Context");
897 return false;
898 }
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800899 for (i = 0; i < pm_ctx->num_dbs_hw_modes; i++) {
900 param = pm_ctx->hw_mode.hw_mode_list[i];
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800901 if (POLICY_MGR_HW_MODE_DBS_MODE_GET(param)) {
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800902 found = 1;
903 break;
904 }
905 }
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800906 if (found)
907 return true;
908
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -0800909 return false;
910}
911
Krunal Sonie64b17e2018-12-13 16:00:02 -0800912static bool policy_mgr_find_if_hwlist_has_sbs(struct wlan_objmgr_psoc *psoc)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -0800913{
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800914 struct policy_mgr_psoc_priv_obj *pm_ctx;
Krunal Sonie64b17e2018-12-13 16:00:02 -0800915 uint32_t param, i, found = 0;
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800916
917 pm_ctx = policy_mgr_get_context(psoc);
Krunal Sonie64b17e2018-12-13 16:00:02 -0800918
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800919 if (!pm_ctx) {
920 policy_mgr_err("Invalid Context");
921 return false;
922 }
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800923 for (i = 0; i < pm_ctx->num_dbs_hw_modes; i++) {
924 param = pm_ctx->hw_mode.hw_mode_list[i];
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800925 if (POLICY_MGR_HW_MODE_SBS_MODE_GET(param)) {
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800926 found = 1;
927 break;
928 }
929 }
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -0800930 if (found)
931 return true;
932
Archana Ramachandran878422f2017-03-23 11:34:02 -0700933 return false;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -0800934}
935
gaurank kathpalia6ee1ab42019-06-19 14:00:30 +0530936bool policy_mgr_is_dbs_scan_allowed(struct wlan_objmgr_psoc *psoc)
937{
938 uint8_t dbs_type = DISABLE_DBS_CXN_AND_SCAN;
939 struct policy_mgr_psoc_priv_obj *pm_ctx;
940
941 pm_ctx = policy_mgr_get_context(psoc);
942 if (!pm_ctx) {
943 policy_mgr_err("Invalid Context");
944 return false;
945 }
946
947 if (!policy_mgr_find_if_fw_supports_dbs(psoc) ||
Abhishek Singh48175fd2020-01-29 17:03:49 +0530948 !policy_mgr_find_if_hwlist_has_dbs(psoc))
gaurank kathpalia6ee1ab42019-06-19 14:00:30 +0530949 return false;
gaurank kathpalia6ee1ab42019-06-19 14:00:30 +0530950
951 policy_mgr_get_dual_mac_feature(psoc, &dbs_type);
952 /*
953 * If DBS support for scan is disabled through INI then DBS is not
954 * supported for scan.
955 *
956 * For DBS scan check the INI value explicitly
957 */
958 switch (dbs_type) {
959 case DISABLE_DBS_CXN_AND_SCAN:
960 case ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN:
961 return false;
962 default:
963 return true;
964 }
965}
966
Krunal Sonie64b17e2018-12-13 16:00:02 -0800967bool policy_mgr_is_hw_dbs_capable(struct wlan_objmgr_psoc *psoc)
968{
Amruta Kulkarni447a3262020-02-05 14:57:04 -0800969 if (!policy_mgr_is_dbs_enable(psoc))
970 return false;
971
972 if (!policy_mgr_find_if_fw_supports_dbs(psoc))
973 return false;
974
975 if (!policy_mgr_find_if_hwlist_has_dbs(psoc)) {
976 policymgr_nofl_debug("HW mode list has no DBS");
Krunal Sonie64b17e2018-12-13 16:00:02 -0800977 return false;
978 }
979
Amruta Kulkarni447a3262020-02-05 14:57:04 -0800980 return true;
Krunal Sonie64b17e2018-12-13 16:00:02 -0800981}
982
983bool policy_mgr_is_hw_sbs_capable(struct wlan_objmgr_psoc *psoc)
984{
985 if (!policy_mgr_find_if_fw_supports_dbs(psoc)) {
Krunal Sonie64b17e2018-12-13 16:00:02 -0800986 return false;
987 }
988
Amruta Kulkarni447a3262020-02-05 14:57:04 -0800989 if (!policy_mgr_find_if_hwlist_has_sbs(psoc)) {
990 policymgr_nofl_debug("HW mode list has no SBS");
991 return false;
992 }
993
994 return true;
Krunal Sonie64b17e2018-12-13 16:00:02 -0800995}
996
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -0800997QDF_STATUS policy_mgr_get_dbs_hw_modes(struct wlan_objmgr_psoc *psoc,
998 bool *one_by_one_dbs, bool *two_by_two_dbs)
999{
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001000 struct policy_mgr_psoc_priv_obj *pm_ctx;
1001 uint32_t i;
1002 int8_t found_one_by_one = -EINVAL, found_two_by_two = -EINVAL;
1003 uint32_t conf1_tx_ss, conf1_rx_ss;
1004 uint32_t conf2_tx_ss, conf2_rx_ss;
1005
1006 *one_by_one_dbs = false;
1007 *two_by_two_dbs = false;
1008
1009 if (policy_mgr_is_hw_dbs_capable(psoc) == false) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05301010 policy_mgr_rl_debug("HW is not DBS capable");
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001011 /* Caller will understand that DBS is disabled */
1012 return QDF_STATUS_SUCCESS;
1013
1014 }
1015
1016 pm_ctx = policy_mgr_get_context(psoc);
1017 if (!pm_ctx) {
1018 policy_mgr_err("Invalid Context");
1019 return QDF_STATUS_E_FAILURE;
1020 }
1021
1022 /* To check 1x1 capability */
1023 policy_mgr_get_tx_rx_ss_from_config(HW_MODE_SS_1x1,
1024 &conf1_tx_ss, &conf1_rx_ss);
1025 /* To check 2x2 capability */
1026 policy_mgr_get_tx_rx_ss_from_config(HW_MODE_SS_2x2,
1027 &conf2_tx_ss, &conf2_rx_ss);
1028
1029 for (i = 0; i < pm_ctx->num_dbs_hw_modes; i++) {
1030 uint32_t t_conf0_tx_ss, t_conf0_rx_ss;
1031 uint32_t t_conf1_tx_ss, t_conf1_rx_ss;
1032 uint32_t dbs_mode;
1033
1034 t_conf0_tx_ss = POLICY_MGR_HW_MODE_MAC0_TX_STREAMS_GET(
1035 pm_ctx->hw_mode.hw_mode_list[i]);
1036 t_conf0_rx_ss = POLICY_MGR_HW_MODE_MAC0_RX_STREAMS_GET(
1037 pm_ctx->hw_mode.hw_mode_list[i]);
1038 t_conf1_tx_ss = POLICY_MGR_HW_MODE_MAC1_TX_STREAMS_GET(
1039 pm_ctx->hw_mode.hw_mode_list[i]);
1040 t_conf1_rx_ss = POLICY_MGR_HW_MODE_MAC1_RX_STREAMS_GET(
1041 pm_ctx->hw_mode.hw_mode_list[i]);
1042 dbs_mode = POLICY_MGR_HW_MODE_DBS_MODE_GET(
1043 pm_ctx->hw_mode.hw_mode_list[i]);
1044
1045 if (((((t_conf0_tx_ss == conf1_tx_ss) &&
1046 (t_conf0_rx_ss == conf1_rx_ss)) ||
1047 ((t_conf1_tx_ss == conf1_tx_ss) &&
1048 (t_conf1_rx_ss == conf1_rx_ss))) &&
1049 (dbs_mode == HW_MODE_DBS)) &&
1050 (found_one_by_one < 0)) {
1051 found_one_by_one = i;
Tushnim Bhattacharyya8b60ebb2017-08-17 14:53:07 -07001052 policy_mgr_debug("1x1 hw_mode index %d found", i);
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001053 /* Once an entry is found, need not check for 1x1
1054 * again
1055 */
1056 continue;
1057 }
1058
1059 if (((((t_conf0_tx_ss == conf2_tx_ss) &&
1060 (t_conf0_rx_ss == conf2_rx_ss)) ||
1061 ((t_conf1_tx_ss == conf2_tx_ss) &&
1062 (t_conf1_rx_ss == conf2_rx_ss))) &&
1063 (dbs_mode == HW_MODE_DBS)) &&
1064 (found_two_by_two < 0)) {
1065 found_two_by_two = i;
Tushnim Bhattacharyya8b60ebb2017-08-17 14:53:07 -07001066 policy_mgr_debug("2x2 hw_mode index %d found", i);
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001067 /* Once an entry is found, need not check for 2x2
1068 * again
1069 */
1070 continue;
1071 }
1072 }
1073
1074 if (found_one_by_one >= 0)
1075 *one_by_one_dbs = true;
1076 if (found_two_by_two >= 0)
1077 *two_by_two_dbs = true;
1078
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001079 return QDF_STATUS_SUCCESS;
1080}
1081
1082QDF_STATUS policy_mgr_get_current_hw_mode(struct wlan_objmgr_psoc *psoc,
1083 struct policy_mgr_hw_mode_params *hw_mode)
1084{
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001085 QDF_STATUS status;
1086 uint32_t old_hw_index = 0, new_hw_index = 0;
1087
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001088 status = policy_mgr_get_old_and_new_hw_index(psoc, &old_hw_index,
1089 &new_hw_index);
1090 if (QDF_STATUS_SUCCESS != status) {
1091 policy_mgr_err("Failed to get HW mode index");
1092 return QDF_STATUS_E_FAILURE;
1093 }
1094
1095 if (new_hw_index == POLICY_MGR_DEFAULT_HW_MODE_INDEX) {
1096 policy_mgr_err("HW mode is not yet initialized");
1097 return QDF_STATUS_E_FAILURE;
1098 }
1099
1100 status = policy_mgr_get_hw_mode_from_idx(psoc, new_hw_index, hw_mode);
1101 if (QDF_STATUS_SUCCESS != status) {
1102 policy_mgr_err("Failed to get HW mode index");
1103 return QDF_STATUS_E_FAILURE;
1104 }
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001105 return QDF_STATUS_SUCCESS;
1106}
1107
1108bool policy_mgr_is_current_hwmode_dbs(struct wlan_objmgr_psoc *psoc)
1109{
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001110 struct policy_mgr_hw_mode_params hw_mode;
1111
1112 if (!policy_mgr_is_hw_dbs_capable(psoc))
1113 return false;
1114 if (QDF_STATUS_SUCCESS !=
1115 policy_mgr_get_current_hw_mode(psoc, &hw_mode))
1116 return false;
1117 if (hw_mode.dbs_cap)
1118 return true;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001119 return false;
1120}
1121
1122bool policy_mgr_is_dbs_enable(struct wlan_objmgr_psoc *psoc)
1123{
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001124 struct policy_mgr_psoc_priv_obj *pm_ctx;
1125
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -07001126 if (policy_mgr_is_dual_mac_disabled_in_ini(psoc)) {
Amruta Kulkarni447a3262020-02-05 14:57:04 -08001127 policy_mgr_rl_debug("DBS is disabled from ini");
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001128 return false;
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -07001129 }
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001130
1131 pm_ctx = policy_mgr_get_context(psoc);
1132 if (!pm_ctx) {
1133 policy_mgr_err("Invalid Context");
1134 return false;
1135 }
1136
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001137 if (WMI_DBS_FW_MODE_CFG_DBS_GET(
1138 pm_ctx->dual_mac_cfg.cur_fw_mode_config))
1139 return true;
1140
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001141 return false;
1142}
1143
1144bool policy_mgr_is_hw_dbs_2x2_capable(struct wlan_objmgr_psoc *psoc)
1145{
Liangwei Dong897b4392019-11-05 19:16:02 +08001146 struct dbs_nss nss_dbs = {0};
Liangwei Dong18300132018-05-25 01:25:24 -04001147 uint32_t nss;
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001148
Liangwei Dong18300132018-05-25 01:25:24 -04001149 nss = policy_mgr_get_hw_dbs_nss(psoc, &nss_dbs);
1150 if (nss >= HW_MODE_SS_2x2 && (nss_dbs.mac0_ss == nss_dbs.mac1_ss))
1151 return true;
1152 else
1153 return false;
1154}
1155
Liangwei Dong897b4392019-11-05 19:16:02 +08001156bool policy_mgr_is_hw_dbs_required_for_band(struct wlan_objmgr_psoc *psoc,
1157 enum hw_mode_mac_band_cap band)
1158{
1159 struct dbs_nss nss_dbs = {0};
1160 uint32_t nss;
1161
1162 nss = policy_mgr_get_hw_dbs_nss(psoc, &nss_dbs);
1163 if (nss >= HW_MODE_SS_1x1 && nss_dbs.mac0_ss == nss_dbs.mac1_ss &&
1164 !(nss_dbs.single_mac0_band_cap & band))
1165 return true;
1166 else
1167 return false;
1168}
1169
1170bool policy_mgr_is_dp_hw_dbs_2x2_capable(struct wlan_objmgr_psoc *psoc)
1171{
1172 return policy_mgr_is_hw_dbs_2x2_capable(psoc) ||
1173 policy_mgr_is_hw_dbs_required_for_band(psoc,
1174 HW_MODE_MAC_BAND_2G);
1175}
1176
Liangwei Dong18300132018-05-25 01:25:24 -04001177/*
1178 * policy_mgr_is_2x2_1x1_dbs_capable() - check 2x2+1x1 DBS supported or not
1179 * @psoc: PSOC object data
1180 *
1181 * This routine is called to check 2x2 5G + 1x1 2G (DBS1) or
1182 * 2x2 2G + 1x1 5G (DBS2) support or not.
1183 * Either DBS1 or DBS2 supported
1184 *
1185 * Return: true/false
1186 */
1187bool policy_mgr_is_2x2_1x1_dbs_capable(struct wlan_objmgr_psoc *psoc)
1188{
1189 struct dbs_nss nss_dbs;
1190 uint32_t nss;
1191
1192 nss = policy_mgr_get_hw_dbs_nss(psoc, &nss_dbs);
1193 if (nss >= HW_MODE_SS_2x2 && (nss_dbs.mac0_ss > nss_dbs.mac1_ss))
1194 return true;
1195 else
1196 return false;
1197}
1198
1199/*
1200 * policy_mgr_is_2x2_5G_1x1_2G_dbs_capable() - check Genoa DBS1 enabled or not
1201 * @psoc: PSOC object data
1202 *
1203 * This routine is called to check support DBS1 or not.
1204 * Notes: DBS1: 2x2 5G + 1x1 2G.
1205 * This function will call policy_mgr_get_hw_mode_idx_from_dbs_hw_list to match
1206 * the HW mode from hw mode list. The parameters will also be matched to
1207 * 2x2 5G +2x2 2G HW mode. But firmware will not report 2x2 5G + 2x2 2G alone
1208 * with 2x2 5G + 1x1 2G at same time. So, it is safe to find DBS1 with
1209 * policy_mgr_get_hw_mode_idx_from_dbs_hw_list.
1210 *
1211 * Return: true/false
1212 */
1213bool policy_mgr_is_2x2_5G_1x1_2G_dbs_capable(struct wlan_objmgr_psoc *psoc)
1214{
1215 return policy_mgr_is_2x2_1x1_dbs_capable(psoc) &&
1216 (policy_mgr_get_hw_mode_idx_from_dbs_hw_list(
1217 psoc,
1218 HW_MODE_SS_2x2,
1219 HW_MODE_80_MHZ,
1220 HW_MODE_SS_1x1, HW_MODE_40_MHZ,
1221 HW_MODE_MAC_BAND_5G,
1222 HW_MODE_DBS,
1223 HW_MODE_AGILE_DFS_NONE,
1224 HW_MODE_SBS_NONE) >= 0);
1225}
1226
1227/*
1228 * policy_mgr_is_2x2_2G_1x1_5G_dbs_capable() - check Genoa DBS2 enabled or not
1229 * @psoc: PSOC object data
1230 *
1231 * This routine is called to check support DBS2 or not.
1232 * Notes: DBS2: 2x2 2G + 1x1 5G
1233 *
1234 * Return: true/false
1235 */
1236bool policy_mgr_is_2x2_2G_1x1_5G_dbs_capable(struct wlan_objmgr_psoc *psoc)
1237{
1238 return policy_mgr_is_2x2_1x1_dbs_capable(psoc) &&
1239 (policy_mgr_get_hw_mode_idx_from_dbs_hw_list(
1240 psoc,
1241 HW_MODE_SS_2x2,
1242 HW_MODE_40_MHZ,
1243 HW_MODE_SS_1x1, HW_MODE_40_MHZ,
1244 HW_MODE_MAC_BAND_2G,
1245 HW_MODE_DBS,
1246 HW_MODE_AGILE_DFS_NONE,
1247 HW_MODE_SBS_NONE) >= 0);
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001248}
1249
1250uint32_t policy_mgr_get_connection_count(struct wlan_objmgr_psoc *psoc)
1251{
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001252 uint32_t conn_index, count = 0;
1253 struct policy_mgr_psoc_priv_obj *pm_ctx;
1254
1255 pm_ctx = policy_mgr_get_context(psoc);
1256 if (!pm_ctx) {
1257 policy_mgr_err("Invalid Context");
1258 return count;
1259 }
1260
1261 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
1262 for (conn_index = 0; conn_index < MAX_NUMBER_OF_CONC_CONNECTIONS;
1263 conn_index++) {
1264 if (pm_conc_connection_list[conn_index].in_use)
1265 count++;
1266 }
1267 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
1268
1269 return count;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001270}
1271
Kabilan Kannan5125d0f2017-05-15 20:28:05 -07001272uint32_t policy_mgr_mode_specific_vdev_id(struct wlan_objmgr_psoc *psoc,
1273 enum policy_mgr_con_mode mode)
1274{
1275 uint32_t conn_index = 0;
1276 uint32_t vdev_id = WLAN_INVALID_VDEV_ID;
1277 struct policy_mgr_psoc_priv_obj *pm_ctx;
1278
1279 pm_ctx = policy_mgr_get_context(psoc);
1280 if (!pm_ctx) {
1281 policy_mgr_err("Invalid Context");
1282 return vdev_id;
1283 }
1284 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
1285 /*
1286 * Note: This gives you the first vdev id of the mode type in a
1287 * sta+sta or sap+sap or p2p + p2p case
1288 */
1289 for (conn_index = 0; conn_index < MAX_NUMBER_OF_CONC_CONNECTIONS;
1290 conn_index++) {
1291 if ((pm_conc_connection_list[conn_index].mode == mode) &&
1292 pm_conc_connection_list[conn_index].in_use) {
1293 vdev_id = pm_conc_connection_list[conn_index].vdev_id;
1294 break;
1295 }
1296 }
1297 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
1298
1299 return vdev_id;
1300}
1301
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001302uint32_t policy_mgr_mode_specific_connection_count(
1303 struct wlan_objmgr_psoc *psoc,
1304 enum policy_mgr_con_mode mode,
1305 uint32_t *list)
1306{
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001307 uint32_t conn_index = 0, count = 0;
1308 struct policy_mgr_psoc_priv_obj *pm_ctx;
1309
1310 pm_ctx = policy_mgr_get_context(psoc);
1311 if (!pm_ctx) {
1312 policy_mgr_err("Invalid Context");
1313 return count;
1314 }
1315 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
1316 for (conn_index = 0; conn_index < MAX_NUMBER_OF_CONC_CONNECTIONS;
1317 conn_index++) {
1318 if ((pm_conc_connection_list[conn_index].mode == mode) &&
1319 pm_conc_connection_list[conn_index].in_use) {
Jeff Johnsone79b53c2019-03-18 14:03:23 -07001320 if (list)
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001321 list[count] = conn_index;
1322 count++;
1323 }
1324 }
1325 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
1326
1327 return count;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001328}
1329
Nitesh Shahc26d3bd2017-06-07 15:25:07 +05301330QDF_STATUS policy_mgr_check_conn_with_mode_and_vdev_id(
1331 struct wlan_objmgr_psoc *psoc, enum policy_mgr_con_mode mode,
1332 uint32_t vdev_id)
1333{
1334 QDF_STATUS qdf_status = QDF_STATUS_E_FAILURE;
1335 uint32_t conn_index = 0;
1336 struct policy_mgr_psoc_priv_obj *pm_ctx;
1337
1338 pm_ctx = policy_mgr_get_context(psoc);
1339 if (!pm_ctx) {
1340 policy_mgr_err("Invalid Context");
1341 return qdf_status;
1342 }
1343
1344 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
1345 while (PM_CONC_CONNECTION_LIST_VALID_INDEX(conn_index)) {
1346 if ((pm_conc_connection_list[conn_index].mode == mode) &&
1347 (pm_conc_connection_list[conn_index].vdev_id == vdev_id)) {
1348 qdf_status = QDF_STATUS_SUCCESS;
1349 break;
1350 }
1351 conn_index++;
1352 }
1353 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
1354 return qdf_status;
1355}
1356
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001357void policy_mgr_soc_set_dual_mac_cfg_cb(enum set_hw_mode_status status,
1358 uint32_t scan_config,
1359 uint32_t fw_mode_config)
1360{
Tushnim Bhattacharyya8b60ebb2017-08-17 14:53:07 -07001361 policy_mgr_debug("Status:%d for scan_config:%x fw_mode_config:%x",
Srinivas Girigowdab031fa62018-02-15 14:30:05 -08001362 status, scan_config, fw_mode_config);
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001363}
1364
1365void policy_mgr_set_dual_mac_scan_config(struct wlan_objmgr_psoc *psoc,
1366 uint8_t dbs_val,
1367 uint8_t dbs_plus_agile_scan_val,
1368 uint8_t single_mac_scan_with_dbs_val)
1369{
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001370 struct policy_mgr_dual_mac_config cfg;
1371 QDF_STATUS status;
1372 struct policy_mgr_psoc_priv_obj *pm_ctx;
1373
1374 pm_ctx = policy_mgr_get_context(psoc);
1375 if (!pm_ctx) {
1376 policy_mgr_err("Invalid Context");
1377 return;
1378 }
1379
1380 /* Any non-zero positive value is treated as 1 */
1381 if (dbs_val != 0)
1382 dbs_val = 1;
1383 if (dbs_plus_agile_scan_val != 0)
1384 dbs_plus_agile_scan_val = 1;
1385 if (single_mac_scan_with_dbs_val != 0)
1386 single_mac_scan_with_dbs_val = 1;
1387
1388 status = policy_mgr_get_updated_scan_config(psoc, &cfg.scan_config,
1389 dbs_val,
1390 dbs_plus_agile_scan_val,
1391 single_mac_scan_with_dbs_val);
1392 if (status != QDF_STATUS_SUCCESS) {
1393 policy_mgr_err("policy_mgr_get_updated_scan_config failed %d",
1394 status);
1395 return;
1396 }
1397
1398 status = policy_mgr_get_updated_fw_mode_config(psoc,
1399 &cfg.fw_mode_config,
1400 policy_mgr_get_dbs_config(psoc),
1401 policy_mgr_get_agile_dfs_config(psoc));
1402 if (status != QDF_STATUS_SUCCESS) {
1403 policy_mgr_err("policy_mgr_get_updated_fw_mode_config failed %d",
1404 status);
1405 return;
1406 }
1407
Srinivas Girigowdab031fa62018-02-15 14:30:05 -08001408 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001409
Tushnim Bhattacharyya8b60ebb2017-08-17 14:53:07 -07001410 policy_mgr_debug("scan_config:%x fw_mode_config:%x",
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001411 cfg.scan_config, cfg.fw_mode_config);
1412
1413 status = pm_ctx->sme_cbacks.sme_soc_set_dual_mac_config(cfg);
1414 if (status != QDF_STATUS_SUCCESS)
1415 policy_mgr_err("sme_soc_set_dual_mac_config failed %d", status);
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001416}
1417
1418void policy_mgr_set_dual_mac_fw_mode_config(struct wlan_objmgr_psoc *psoc,
1419 uint8_t dbs, uint8_t dfs)
1420{
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001421 struct policy_mgr_dual_mac_config cfg;
1422 QDF_STATUS status;
1423 struct policy_mgr_psoc_priv_obj *pm_ctx;
1424
1425 pm_ctx = policy_mgr_get_context(psoc);
1426 if (!pm_ctx) {
1427 policy_mgr_err("Invalid Context");
1428 return;
1429 }
1430
1431 /* Any non-zero positive value is treated as 1 */
1432 if (dbs != 0)
1433 dbs = 1;
1434 if (dfs != 0)
1435 dfs = 1;
1436
1437 status = policy_mgr_get_updated_scan_config(psoc, &cfg.scan_config,
1438 policy_mgr_get_dbs_scan_config(psoc),
1439 policy_mgr_get_dbs_plus_agile_scan_config(psoc),
1440 policy_mgr_get_single_mac_scan_with_dfs_config(psoc));
1441 if (status != QDF_STATUS_SUCCESS) {
1442 policy_mgr_err("policy_mgr_get_updated_scan_config failed %d",
1443 status);
1444 return;
1445 }
1446
1447 status = policy_mgr_get_updated_fw_mode_config(psoc,
1448 &cfg.fw_mode_config, dbs, dfs);
1449 if (status != QDF_STATUS_SUCCESS) {
1450 policy_mgr_err("policy_mgr_get_updated_fw_mode_config failed %d",
1451 status);
1452 return;
1453 }
1454
Srinivas Girigowdab031fa62018-02-15 14:30:05 -08001455 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001456
Tushnim Bhattacharyya8b60ebb2017-08-17 14:53:07 -07001457 policy_mgr_debug("scan_config:%x fw_mode_config:%x",
Tushnim Bhattacharyya58a0b192017-03-08 09:56:33 -08001458 cfg.scan_config, cfg.fw_mode_config);
1459
1460 status = pm_ctx->sme_cbacks.sme_soc_set_dual_mac_config(cfg);
1461 if (status != QDF_STATUS_SUCCESS)
1462 policy_mgr_err("sme_soc_set_dual_mac_config failed %d", status);
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001463}
1464
1465bool policy_mgr_current_concurrency_is_mcc(struct wlan_objmgr_psoc *psoc)
1466{
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001467 uint32_t num_connections = 0;
1468 bool is_mcc = false;
1469
1470 num_connections = policy_mgr_get_connection_count(psoc);
1471
1472 switch (num_connections) {
1473 case 1:
1474 break;
1475 case 2:
Manikandan Mohan932c11e2019-08-14 14:09:08 -07001476 if (pm_conc_connection_list[0].freq !=
1477 pm_conc_connection_list[1].freq &&
1478 pm_conc_connection_list[0].mac ==
1479 pm_conc_connection_list[1].mac) {
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001480 is_mcc = true;
1481 }
1482 break;
1483 case 3:
Manikandan Mohan932c11e2019-08-14 14:09:08 -07001484 if (pm_conc_connection_list[0].freq !=
1485 pm_conc_connection_list[1].freq ||
1486 pm_conc_connection_list[0].freq !=
1487 pm_conc_connection_list[2].freq ||
1488 pm_conc_connection_list[1].freq !=
1489 pm_conc_connection_list[2].freq){
1490 is_mcc = true;
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001491 }
1492 break;
1493 default:
Arun Kumar Khandavallif4ed4062020-01-20 11:45:09 +05301494 policy_mgr_debug("unexpected num_connections value %d",
1495 num_connections);
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001496 break;
1497 }
1498
1499 return is_mcc;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001500}
1501
Krishna Reddy3c629902019-07-05 12:42:29 +05301502bool policy_mgr_is_sap_p2pgo_on_dfs(struct wlan_objmgr_psoc *psoc)
1503{
1504 int index, count;
1505 uint32_t list[MAX_NUMBER_OF_CONC_CONNECTIONS];
1506 struct policy_mgr_psoc_priv_obj *pm_ctx = NULL;
1507
1508 if (psoc)
1509 pm_ctx = policy_mgr_get_context(psoc);
1510
1511 if (!pm_ctx) {
1512 policy_mgr_err("Invalid Context");
1513 return false;
1514 }
1515
1516 index = 0;
1517 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
1518 count = policy_mgr_mode_specific_connection_count(psoc,
1519 PM_SAP_MODE,
1520 list);
1521 while (index < count) {
Kiran Kumar Lokere54140662019-11-01 18:42:09 -07001522 if (pm_conc_connection_list[list[index]].ch_flagext &
1523 (IEEE80211_CHAN_DFS | IEEE80211_CHAN_DFS_CFREQ2)) {
Krishna Reddy3c629902019-07-05 12:42:29 +05301524 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
1525 return true;
1526 }
1527 index++;
1528 }
1529 count = policy_mgr_mode_specific_connection_count(psoc,
1530 PM_P2P_GO_MODE,
1531 list);
1532 index = 0;
1533 while (index < count) {
Kiran Kumar Lokere54140662019-11-01 18:42:09 -07001534 if (pm_conc_connection_list[list[index]].ch_flagext &
1535 (IEEE80211_CHAN_DFS | IEEE80211_CHAN_DFS_CFREQ2)) {
Krishna Reddy3c629902019-07-05 12:42:29 +05301536 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
1537 return true;
1538 }
1539 index++;
1540 }
1541 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
1542 return false;
1543}
1544
Archana Ramachandran7abbf562017-03-02 13:14:34 -08001545/**
1546 * policy_mgr_set_concurrency_mode() - To set concurrency mode
1547 * @psoc: PSOC object data
1548 * @mode: device mode
1549 *
1550 * This routine is called to set the concurrency mode
1551 *
1552 * Return: NONE
1553 */
1554void policy_mgr_set_concurrency_mode(struct wlan_objmgr_psoc *psoc,
Jeff Johnson275208b2017-11-09 09:54:12 -08001555 enum QDF_OPMODE mode)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001556{
Archana Ramachandran7abbf562017-03-02 13:14:34 -08001557 struct policy_mgr_psoc_priv_obj *pm_ctx;
1558
1559 pm_ctx = policy_mgr_get_context(psoc);
1560 if (!pm_ctx) {
1561 policy_mgr_err("Invalid context");
1562 return;
1563 }
1564
1565 switch (mode) {
1566 case QDF_STA_MODE:
1567 case QDF_P2P_CLIENT_MODE:
1568 case QDF_P2P_GO_MODE:
1569 case QDF_SAP_MODE:
1570 case QDF_IBSS_MODE:
1571 case QDF_MONITOR_MODE:
1572 pm_ctx->concurrency_mode |= (1 << mode);
1573 pm_ctx->no_of_open_sessions[mode]++;
1574 break;
1575 default:
1576 break;
1577 }
1578
Arun Kumar Khandavallif4ed4062020-01-20 11:45:09 +05301579 policy_mgr_debug("concurrency_mode = 0x%x Number of open sessions for mode %d = %d",
1580 pm_ctx->concurrency_mode, mode,
Archana Ramachandran7abbf562017-03-02 13:14:34 -08001581 pm_ctx->no_of_open_sessions[mode]);
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001582}
1583
Archana Ramachandran7abbf562017-03-02 13:14:34 -08001584/**
1585 * policy_mgr_clear_concurrency_mode() - To clear concurrency mode
1586 * @psoc: PSOC object data
1587 * @mode: device mode
1588 *
1589 * This routine is called to clear the concurrency mode
1590 *
1591 * Return: NONE
1592 */
1593void policy_mgr_clear_concurrency_mode(struct wlan_objmgr_psoc *psoc,
Jeff Johnson275208b2017-11-09 09:54:12 -08001594 enum QDF_OPMODE mode)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001595{
Archana Ramachandran7abbf562017-03-02 13:14:34 -08001596 struct policy_mgr_psoc_priv_obj *pm_ctx;
1597
1598 pm_ctx = policy_mgr_get_context(psoc);
1599 if (!pm_ctx) {
1600 policy_mgr_err("Invalid context");
1601 return;
1602 }
1603
1604 switch (mode) {
1605 case QDF_STA_MODE:
1606 case QDF_P2P_CLIENT_MODE:
1607 case QDF_P2P_GO_MODE:
1608 case QDF_SAP_MODE:
1609 case QDF_MONITOR_MODE:
1610 pm_ctx->no_of_open_sessions[mode]--;
1611 if (!(pm_ctx->no_of_open_sessions[mode]))
1612 pm_ctx->concurrency_mode &= (~(1 << mode));
1613 break;
1614 default:
1615 break;
1616 }
1617
Arun Kumar Khandavallif4ed4062020-01-20 11:45:09 +05301618 policy_mgr_debug("concurrency_mode = 0x%x Number of open sessions for mode %d = %d",
1619 pm_ctx->concurrency_mode, mode,
1620 pm_ctx->no_of_open_sessions[mode]);
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001621}
1622
1623void policy_mgr_incr_active_session(struct wlan_objmgr_psoc *psoc,
Jeff Johnson275208b2017-11-09 09:54:12 -08001624 enum QDF_OPMODE mode,
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001625 uint8_t session_id)
1626{
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001627 struct policy_mgr_psoc_priv_obj *pm_ctx;
Liangwei Dong05276172019-12-27 10:31:46 +08001628 uint32_t conn_6ghz_flag = 0;
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001629
1630 pm_ctx = policy_mgr_get_context(psoc);
1631 if (!pm_ctx) {
1632 policy_mgr_err("Invalid Context");
1633 return;
1634 }
1635
1636 /*
1637 * Need to aquire mutex as entire functionality in this function
1638 * is in critical section
1639 */
1640 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
1641 switch (mode) {
1642 case QDF_STA_MODE:
1643 case QDF_P2P_CLIENT_MODE:
1644 case QDF_P2P_GO_MODE:
1645 case QDF_SAP_MODE:
1646 case QDF_IBSS_MODE:
Nachiket Kukadecf941602018-12-12 14:32:35 +05301647 case QDF_NAN_DISC_MODE:
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001648 pm_ctx->no_of_active_sessions[mode]++;
1649 break;
1650 default:
1651 break;
1652 }
1653
Nachiket Kukadecf941602018-12-12 14:32:35 +05301654 if (mode != QDF_NAN_DISC_MODE && pm_ctx->dp_cbacks.hdd_v2_flow_pool_map)
Manjunathappa Prakashcdf18132018-05-08 19:55:25 -07001655 pm_ctx->dp_cbacks.hdd_v2_flow_pool_map(session_id);
Liangwei Dong05276172019-12-27 10:31:46 +08001656 if (mode == QDF_SAP_MODE)
1657 policy_mgr_get_ap_6ghz_capable(psoc, session_id,
1658 &conn_6ghz_flag);
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001659
Tushnim Bhattacharyya8b60ebb2017-08-17 14:53:07 -07001660 policy_mgr_debug("No.# of active sessions for mode %d = %d",
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001661 mode, pm_ctx->no_of_active_sessions[mode]);
Srinivas Dasaric9e048e2019-12-23 00:45:35 +05301662 policy_mgr_incr_connection_count(psoc, session_id, mode);
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001663 if ((policy_mgr_mode_specific_connection_count(
1664 psoc, PM_STA_MODE, NULL) > 0) && (mode != QDF_STA_MODE)) {
1665 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
1666 policy_mgr_set_pcl_for_existing_combo(psoc, PM_STA_MODE);
1667 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
1668 }
1669
Kabilan Kannanc81d3752017-02-28 20:28:54 -08001670 /* Notify tdls */
1671 if (pm_ctx->tdls_cbacks.tdls_notify_increment_session)
1672 pm_ctx->tdls_cbacks.tdls_notify_increment_session(psoc);
1673
Manjunathappa Prakashfb828332017-04-05 15:59:49 -07001674 /*
Manjunathappa Prakashe51aba72018-04-15 00:42:41 -07001675 * Disable LRO/GRO if P2P or IBSS or SAP connection has come up or
Manjunathappa Prakashfb828332017-04-05 15:59:49 -07001676 * there are more than one STA connections
1677 */
1678 if ((policy_mgr_mode_specific_connection_count(psoc, PM_STA_MODE, NULL) > 1) ||
1679 (policy_mgr_mode_specific_connection_count(psoc, PM_SAP_MODE, NULL) > 0) ||
1680 (policy_mgr_mode_specific_connection_count(psoc, PM_P2P_CLIENT_MODE, NULL) >
1681 0) ||
1682 (policy_mgr_mode_specific_connection_count(psoc, PM_P2P_GO_MODE, NULL) > 0) ||
1683 (policy_mgr_mode_specific_connection_count(psoc, PM_IBSS_MODE, NULL) > 0)) {
Jeff Johnsone79b53c2019-03-18 14:03:23 -07001684 if (pm_ctx->dp_cbacks.hdd_disable_rx_ol_in_concurrency)
Manjunathappa Prakashe51aba72018-04-15 00:42:41 -07001685 pm_ctx->dp_cbacks.hdd_disable_rx_ol_in_concurrency(true);
Manjunathappa Prakashfb828332017-04-05 15:59:49 -07001686 };
1687
Yun Parkab131772017-09-26 16:39:17 -07001688 /* Enable RPS if SAP interface has come up */
1689 if (policy_mgr_mode_specific_connection_count(psoc, PM_SAP_MODE, NULL)
1690 == 1) {
Jeff Johnsone79b53c2019-03-18 14:03:23 -07001691 if (pm_ctx->dp_cbacks.hdd_set_rx_mode_rps_cb)
Yun Parkab131772017-09-26 16:39:17 -07001692 pm_ctx->dp_cbacks.hdd_set_rx_mode_rps_cb(true);
1693 }
Liangwei Dong05276172019-12-27 10:31:46 +08001694 if (mode == QDF_SAP_MODE)
1695 policy_mgr_init_ap_6ghz_capable(psoc, session_id,
1696 conn_6ghz_flag);
Yun Parkab131772017-09-26 16:39:17 -07001697
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001698 policy_mgr_dump_current_concurrency(psoc);
1699
1700 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001701}
1702
Nitesh Shahc26d3bd2017-06-07 15:25:07 +05301703QDF_STATUS policy_mgr_decr_active_session(struct wlan_objmgr_psoc *psoc,
Jeff Johnson275208b2017-11-09 09:54:12 -08001704 enum QDF_OPMODE mode,
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001705 uint8_t session_id)
1706{
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001707 struct policy_mgr_psoc_priv_obj *pm_ctx;
Nitesh Shahc26d3bd2017-06-07 15:25:07 +05301708 QDF_STATUS qdf_status;
jiadc8754ac2018-03-30 16:33:59 +08001709 bool mcc_mode;
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001710
1711 pm_ctx = policy_mgr_get_context(psoc);
1712 if (!pm_ctx) {
1713 policy_mgr_err("context is NULL");
Nitesh Shahc26d3bd2017-06-07 15:25:07 +05301714 return QDF_STATUS_E_EMPTY;
1715 }
1716
1717 qdf_status = policy_mgr_check_conn_with_mode_and_vdev_id(psoc,
1718 policy_mgr_convert_device_mode_to_qdf_type(mode),
1719 session_id);
1720 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Tushnim Bhattacharyyac05a1912018-09-18 15:53:50 -07001721 policy_mgr_debug("No connection with mode:%d vdev_id:%d",
Nitesh Shahc26d3bd2017-06-07 15:25:07 +05301722 policy_mgr_convert_device_mode_to_qdf_type(mode),
1723 session_id);
1724 return qdf_status;
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001725 }
1726
1727 switch (mode) {
1728 case QDF_STA_MODE:
1729 case QDF_P2P_CLIENT_MODE:
1730 case QDF_P2P_GO_MODE:
1731 case QDF_SAP_MODE:
1732 case QDF_IBSS_MODE:
Nachiket Kukadecf941602018-12-12 14:32:35 +05301733 case QDF_NAN_DISC_MODE:
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001734 if (pm_ctx->no_of_active_sessions[mode])
1735 pm_ctx->no_of_active_sessions[mode]--;
1736 break;
1737 default:
1738 break;
1739 }
1740
Nachiket Kukadecf941602018-12-12 14:32:35 +05301741 if (mode != QDF_NAN_DISC_MODE &&
1742 pm_ctx->dp_cbacks.hdd_v2_flow_pool_unmap)
Manjunathappa Prakashcdf18132018-05-08 19:55:25 -07001743 pm_ctx->dp_cbacks.hdd_v2_flow_pool_unmap(session_id);
1744
Tushnim Bhattacharyya8b60ebb2017-08-17 14:53:07 -07001745 policy_mgr_debug("No.# of active sessions for mode %d = %d",
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001746 mode, pm_ctx->no_of_active_sessions[mode]);
1747
1748 policy_mgr_decr_connection_count(psoc, session_id);
1749
Kabilan Kannanc81d3752017-02-28 20:28:54 -08001750 /* Notify tdls */
1751 if (pm_ctx->tdls_cbacks.tdls_notify_decrement_session)
1752 pm_ctx->tdls_cbacks.tdls_notify_decrement_session(psoc);
Manjunathappa Prakashe51aba72018-04-15 00:42:41 -07001753 /* Enable LRO/GRO if there no concurrency */
Manjunathappa Prakashfb828332017-04-05 15:59:49 -07001754 if ((policy_mgr_mode_specific_connection_count(psoc, PM_STA_MODE, NULL) == 1) &&
1755 (policy_mgr_mode_specific_connection_count(psoc, PM_SAP_MODE, NULL) == 0) &&
1756 (policy_mgr_mode_specific_connection_count(psoc, PM_P2P_CLIENT_MODE, NULL) ==
1757 0) &&
1758 (policy_mgr_mode_specific_connection_count(psoc, PM_P2P_GO_MODE, NULL) == 0) &&
1759 (policy_mgr_mode_specific_connection_count(psoc, PM_IBSS_MODE, NULL) == 0)) {
Jeff Johnsone79b53c2019-03-18 14:03:23 -07001760 if (pm_ctx->dp_cbacks.hdd_disable_rx_ol_in_concurrency)
Manjunathappa Prakashe51aba72018-04-15 00:42:41 -07001761 pm_ctx->dp_cbacks.hdd_disable_rx_ol_in_concurrency(false);
Manjunathappa Prakashfb828332017-04-05 15:59:49 -07001762 };
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001763
Yun Parkab131772017-09-26 16:39:17 -07001764 /* Disable RPS if SAP interface has come up */
1765 if (policy_mgr_mode_specific_connection_count(psoc, PM_SAP_MODE, NULL)
1766 == 0) {
Jeff Johnsone79b53c2019-03-18 14:03:23 -07001767 if (pm_ctx->dp_cbacks.hdd_set_rx_mode_rps_cb)
Yun Parkab131772017-09-26 16:39:17 -07001768 pm_ctx->dp_cbacks.hdd_set_rx_mode_rps_cb(false);
1769 }
1770
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001771 policy_mgr_dump_current_concurrency(psoc);
Nitesh Shahc26d3bd2017-06-07 15:25:07 +05301772
jiadc8754ac2018-03-30 16:33:59 +08001773 /*
1774 * Check mode of entry being removed. Update mcc_mode only when STA
1775 * or SAP since IPA only cares about these two
1776 */
1777 if (mode == QDF_STA_MODE || mode == QDF_SAP_MODE) {
1778 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
1779 mcc_mode = policy_mgr_current_concurrency_is_mcc(psoc);
1780 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
1781
1782 if (pm_ctx->dp_cbacks.hdd_ipa_set_mcc_mode_cb)
1783 pm_ctx->dp_cbacks.hdd_ipa_set_mcc_mode_cb(mcc_mode);
1784 }
Liangwei Dong11019a02019-05-08 23:32:37 -04001785 /*
1786 * When STA disconnected, we need to move DFS SAP
1787 * to Non-DFS if g_sta_sap_scc_on_dfs_chan enabled.
1788 * The same if g_sta_sap_scc_on_lte_coex_chan enabled,
1789 * need to move SAP on unsafe channel to safe channel.
1790 * The flag will be checked by
1791 * policy_mgr_is_sap_restart_required_after_sta_disconnect.
1792 */
1793 if (mode == QDF_STA_MODE || mode == QDF_P2P_CLIENT_MODE)
1794 pm_ctx->do_sap_unsafe_ch_check = true;
jiadc8754ac2018-03-30 16:33:59 +08001795
Nitesh Shahc26d3bd2017-06-07 15:25:07 +05301796 return qdf_status;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001797}
1798
Srinivas Dasaric9e048e2019-12-23 00:45:35 +05301799QDF_STATUS policy_mgr_incr_connection_count(struct wlan_objmgr_psoc *psoc,
1800 uint32_t vdev_id,
1801 enum QDF_OPMODE op_mode)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001802{
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001803 QDF_STATUS status = QDF_STATUS_E_FAILURE;
1804 uint32_t conn_index;
sheenam monga4a3f3412019-04-05 12:27:54 +05301805 struct policy_mgr_vdev_entry_info conn_table_entry = {0};
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001806 enum policy_mgr_chain_mode chain_mask = POLICY_MGR_ONE_ONE;
1807 uint8_t nss_2g = 0, nss_5g = 0;
1808 enum policy_mgr_con_mode mode;
Manikandan Mohan932c11e2019-08-14 14:09:08 -07001809 uint32_t ch_freq;
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001810 uint32_t nss = 0;
1811 struct policy_mgr_psoc_priv_obj *pm_ctx;
Yeshwanth Sriram Guntuka28542952018-06-13 11:43:46 +05301812 bool update_conn = true;
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001813
1814 pm_ctx = policy_mgr_get_context(psoc);
1815 if (!pm_ctx) {
1816 policy_mgr_err("context is NULL");
1817 return status;
1818 }
1819
1820 conn_index = policy_mgr_get_connection_count(psoc);
Krunal Soni1c7a1e92018-09-27 10:55:17 -07001821 if (pm_ctx->cfg.max_conc_cxns < conn_index) {
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001822 policy_mgr_err("exceeded max connection limit %d",
Krunal Soni1c7a1e92018-09-27 10:55:17 -07001823 pm_ctx->cfg.max_conc_cxns);
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001824 return status;
1825 }
Nachiket Kukadecf941602018-12-12 14:32:35 +05301826
Srinivas Dasaric9e048e2019-12-23 00:45:35 +05301827 if (op_mode == QDF_NAN_DISC_MODE) {
Nachiket Kukadecf941602018-12-12 14:32:35 +05301828 status = wlan_nan_get_connection_info(psoc, &conn_table_entry);
1829 if (QDF_IS_STATUS_ERROR(status)) {
1830 policy_mgr_err("Can't get NAN Connection info");
1831 return status;
1832 }
1833 } else if (pm_ctx->wma_cbacks.wma_get_connection_info) {
Tushnim Bhattacharyya00ccf112017-03-28 10:45:08 -07001834 status = pm_ctx->wma_cbacks.wma_get_connection_info(
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001835 vdev_id, &conn_table_entry);
Tushnim Bhattacharyya00ccf112017-03-28 10:45:08 -07001836 if (QDF_STATUS_SUCCESS != status) {
1837 policy_mgr_err("can't find vdev_id %d in connection table",
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001838 vdev_id);
Tushnim Bhattacharyya00ccf112017-03-28 10:45:08 -07001839 return status;
1840 }
1841 } else {
1842 policy_mgr_err("wma_get_connection_info is NULL");
1843 return QDF_STATUS_E_FAILURE;
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001844 }
Tushnim Bhattacharyya00ccf112017-03-28 10:45:08 -07001845
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001846 mode = policy_mgr_get_mode(conn_table_entry.type,
1847 conn_table_entry.sub_type);
Manikandan Mohan932c11e2019-08-14 14:09:08 -07001848 ch_freq = conn_table_entry.mhz;
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001849 status = policy_mgr_get_nss_for_vdev(psoc, mode, &nss_2g, &nss_5g);
1850 if (QDF_IS_STATUS_SUCCESS(status)) {
Manikandan Mohan932c11e2019-08-14 14:09:08 -07001851 if ((WLAN_REG_IS_24GHZ_CH_FREQ(ch_freq) && nss_2g > 1) ||
1852 (WLAN_REG_IS_5GHZ_CH_FREQ(ch_freq) && nss_5g > 1))
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001853 chain_mask = POLICY_MGR_TWO_TWO;
1854 else
1855 chain_mask = POLICY_MGR_ONE_ONE;
Manikandan Mohan932c11e2019-08-14 14:09:08 -07001856 nss = (WLAN_REG_IS_24GHZ_CH_FREQ(ch_freq)) ? nss_2g : nss_5g;
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001857 } else {
1858 policy_mgr_err("Error in getting nss");
1859 }
1860
Yeshwanth Sriram Guntuka28542952018-06-13 11:43:46 +05301861 if (mode == PM_STA_MODE || mode == PM_P2P_CLIENT_MODE)
1862 update_conn = false;
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001863
1864 /* add the entry */
1865 policy_mgr_update_conc_list(psoc, conn_index,
1866 mode,
Manikandan Mohan932c11e2019-08-14 14:09:08 -07001867 ch_freq,
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001868 policy_mgr_get_bw(conn_table_entry.chan_width),
1869 conn_table_entry.mac_id,
1870 chain_mask,
Kiran Kumar Lokere54140662019-11-01 18:42:09 -07001871 nss, vdev_id, true, update_conn,
1872 conn_table_entry.ch_flagext);
Tushnim Bhattacharyya8b60ebb2017-08-17 14:53:07 -07001873 policy_mgr_debug("Add at idx:%d vdev %d mac=%d",
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001874 conn_index, vdev_id,
1875 conn_table_entry.mac_id);
1876
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001877 return QDF_STATUS_SUCCESS;
1878}
1879
1880QDF_STATUS policy_mgr_decr_connection_count(struct wlan_objmgr_psoc *psoc,
1881 uint32_t vdev_id)
1882{
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001883 QDF_STATUS status = QDF_STATUS_E_FAILURE;
1884 uint32_t conn_index = 0, next_conn_index = 0;
1885 bool found = false;
1886 struct policy_mgr_psoc_priv_obj *pm_ctx;
1887
1888 pm_ctx = policy_mgr_get_context(psoc);
1889 if (!pm_ctx) {
1890 policy_mgr_err("Invalid Context");
1891 return status;
1892 }
1893
1894 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
1895 while (PM_CONC_CONNECTION_LIST_VALID_INDEX(conn_index)) {
1896 if (vdev_id == pm_conc_connection_list[conn_index].vdev_id) {
1897 /* debug msg */
1898 found = true;
1899 break;
1900 }
1901 conn_index++;
1902 }
1903 if (!found) {
1904 policy_mgr_err("can't find vdev_id %d in pm_conc_connection_list",
1905 vdev_id);
1906 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
1907 return status;
1908 }
1909 next_conn_index = conn_index + 1;
1910 while (PM_CONC_CONNECTION_LIST_VALID_INDEX(next_conn_index)) {
1911 pm_conc_connection_list[conn_index].vdev_id =
1912 pm_conc_connection_list[next_conn_index].vdev_id;
1913 pm_conc_connection_list[conn_index].mode =
1914 pm_conc_connection_list[next_conn_index].mode;
1915 pm_conc_connection_list[conn_index].mac =
1916 pm_conc_connection_list[next_conn_index].mac;
Manikandan Mohan932c11e2019-08-14 14:09:08 -07001917 pm_conc_connection_list[conn_index].freq =
1918 pm_conc_connection_list[next_conn_index].freq;
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001919 pm_conc_connection_list[conn_index].bw =
1920 pm_conc_connection_list[next_conn_index].bw;
1921 pm_conc_connection_list[conn_index].chain_mask =
1922 pm_conc_connection_list[next_conn_index].chain_mask;
1923 pm_conc_connection_list[conn_index].original_nss =
1924 pm_conc_connection_list[next_conn_index].original_nss;
1925 pm_conc_connection_list[conn_index].in_use =
1926 pm_conc_connection_list[next_conn_index].in_use;
Kiran Kumar Lokere54140662019-11-01 18:42:09 -07001927 pm_conc_connection_list[conn_index].ch_flagext =
1928 pm_conc_connection_list[next_conn_index].ch_flagext;
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001929 conn_index++;
1930 next_conn_index++;
1931 }
1932
1933 /* clean up the entry */
1934 qdf_mem_zero(&pm_conc_connection_list[next_conn_index - 1],
1935 sizeof(*pm_conc_connection_list));
1936 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
1937
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001938 return QDF_STATUS_SUCCESS;
1939}
1940
Jeff Johnson275208b2017-11-09 09:54:12 -08001941bool policy_mgr_map_concurrency_mode(enum QDF_OPMODE *old_mode,
1942 enum policy_mgr_con_mode *new_mode)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001943{
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001944 bool status = true;
1945
1946 switch (*old_mode) {
1947
1948 case QDF_STA_MODE:
1949 *new_mode = PM_STA_MODE;
1950 break;
1951 case QDF_SAP_MODE:
1952 *new_mode = PM_SAP_MODE;
1953 break;
1954 case QDF_P2P_CLIENT_MODE:
1955 *new_mode = PM_P2P_CLIENT_MODE;
1956 break;
1957 case QDF_P2P_GO_MODE:
1958 *new_mode = PM_P2P_GO_MODE;
1959 break;
1960 case QDF_IBSS_MODE:
1961 *new_mode = PM_IBSS_MODE;
1962 break;
Nachiket Kukadecf941602018-12-12 14:32:35 +05301963 case QDF_NAN_DISC_MODE:
1964 *new_mode = PM_NAN_DISC_MODE;
1965 break;
Nachiket Kukade413c5fa2019-02-19 17:57:19 +05301966 case QDF_NDI_MODE:
1967 *new_mode = PM_NDI_MODE;
1968 break;
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001969 default:
1970 *new_mode = PM_MAX_NUM_OF_MODE;
1971 status = false;
1972 break;
1973 }
1974
1975 return status;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001976}
1977
1978bool policy_mgr_is_ibss_conn_exist(struct wlan_objmgr_psoc *psoc,
Manikandan Mohan932c11e2019-08-14 14:09:08 -07001979 uint32_t *ibss_ch_freq)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08001980{
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001981 uint32_t count = 0, index = 0;
1982 uint32_t list[MAX_NUMBER_OF_CONC_CONNECTIONS];
1983 bool status = false;
1984 struct policy_mgr_psoc_priv_obj *pm_ctx;
1985
1986 pm_ctx = policy_mgr_get_context(psoc);
1987 if (!pm_ctx) {
1988 policy_mgr_err("Invalid Context");
1989 return status;
1990 }
Manikandan Mohan932c11e2019-08-14 14:09:08 -07001991 if (!ibss_ch_freq) {
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08001992 policy_mgr_err("Null pointer error");
1993 return false;
1994 }
1995 count = policy_mgr_mode_specific_connection_count(
1996 psoc, PM_IBSS_MODE, list);
1997 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
1998 if (count == 0) {
1999 /* No IBSS connection */
2000 status = false;
2001 } else if (count == 1) {
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002002 *ibss_ch_freq = pm_conc_connection_list[list[index]].freq;
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08002003 status = true;
2004 } else {
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002005 *ibss_ch_freq = pm_conc_connection_list[list[index]].freq;
Tushnim Bhattacharyya8b60ebb2017-08-17 14:53:07 -07002006 policy_mgr_debug("Multiple IBSS connections, picking first one");
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08002007 status = true;
2008 }
2009 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
2010
2011 return status;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002012}
2013
Manikandan Mohan19f36092019-08-15 15:54:02 -07002014uint32_t policy_mgr_get_mode_specific_conn_info(
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002015 struct wlan_objmgr_psoc *psoc,
2016 uint32_t *ch_freq_list, uint8_t *vdev_id,
2017 enum policy_mgr_con_mode mode)
Archana Ramachandran6199b642017-03-20 13:31:36 -07002018{
Ajit Pal Singhc65575e2017-04-17 16:49:01 +05302019
Rachit Kankanea07e4b92017-09-15 19:38:49 +05302020 uint32_t count = 0, index = 0;
Archana Ramachandran6199b642017-03-20 13:31:36 -07002021 uint32_t list[MAX_NUMBER_OF_CONC_CONNECTIONS];
Archana Ramachandran6199b642017-03-20 13:31:36 -07002022 struct policy_mgr_psoc_priv_obj *pm_ctx;
2023
2024 pm_ctx = policy_mgr_get_context(psoc);
2025 if (!pm_ctx) {
2026 policy_mgr_err("Invalid Context");
Rachit Kankanea07e4b92017-09-15 19:38:49 +05302027 return count;
Archana Ramachandran6199b642017-03-20 13:31:36 -07002028 }
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002029 if (!ch_freq_list || !vdev_id) {
Archana Ramachandran6199b642017-03-20 13:31:36 -07002030 policy_mgr_err("Null pointer error");
Rachit Kankanea07e4b92017-09-15 19:38:49 +05302031 return count;
Archana Ramachandran6199b642017-03-20 13:31:36 -07002032 }
2033
2034 count = policy_mgr_mode_specific_connection_count(
Ajit Pal Singhc65575e2017-04-17 16:49:01 +05302035 psoc, mode, list);
Archana Ramachandran6199b642017-03-20 13:31:36 -07002036 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
Amruta Kulkarni447a3262020-02-05 14:57:04 -08002037 if (count == 1) {
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002038 *ch_freq_list = pm_conc_connection_list[list[index]].freq;
Archana Ramachandran6199b642017-03-20 13:31:36 -07002039 *vdev_id =
2040 pm_conc_connection_list[list[index]].vdev_id;
Archana Ramachandran6199b642017-03-20 13:31:36 -07002041 } else {
Rachit Kankanea07e4b92017-09-15 19:38:49 +05302042 for (index = 0; index < count; index++) {
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002043 ch_freq_list[index] = pm_conc_connection_list[
2044 list[index]].freq;
Rachit Kankanea07e4b92017-09-15 19:38:49 +05302045
2046 vdev_id[index] =
Archana Ramachandran6199b642017-03-20 13:31:36 -07002047 pm_conc_connection_list[list[index]].vdev_id;
Rachit Kankanea07e4b92017-09-15 19:38:49 +05302048 }
Archana Ramachandran6199b642017-03-20 13:31:36 -07002049 }
2050 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
2051
Rachit Kankanea07e4b92017-09-15 19:38:49 +05302052 return count;
Archana Ramachandran6199b642017-03-20 13:31:36 -07002053}
2054
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002055bool policy_mgr_max_concurrent_connections_reached(
2056 struct wlan_objmgr_psoc *psoc)
2057{
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08002058 uint8_t i = 0, j = 0;
2059 struct policy_mgr_psoc_priv_obj *pm_ctx;
2060
2061 pm_ctx = policy_mgr_get_context(psoc);
Jeff Johnsone79b53c2019-03-18 14:03:23 -07002062 if (pm_ctx) {
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08002063 for (i = 0; i < QDF_MAX_NO_OF_MODE; i++)
2064 j += pm_ctx->no_of_active_sessions[i];
2065 return j >
Krunal Soni1c7a1e92018-09-27 10:55:17 -07002066 (pm_ctx->cfg.max_conc_cxns - 1);
Tushnim Bhattacharyya97670702017-03-08 10:06:58 -08002067 }
2068
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002069 return false;
2070}
2071
Tushnim Bhattacharyyad7655ca2017-04-26 12:58:42 -07002072static bool policy_mgr_is_sub_20_mhz_enabled(struct wlan_objmgr_psoc *psoc)
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002073{
Tushnim Bhattacharyyad7655ca2017-04-26 12:58:42 -07002074 struct policy_mgr_psoc_priv_obj *pm_ctx;
2075
2076 pm_ctx = policy_mgr_get_context(psoc);
2077 if (!pm_ctx) {
2078 policy_mgr_err("Invalid Context");
2079 return false;
2080 }
2081
2082 return pm_ctx->user_cfg.sub_20_mhz_enabled;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002083}
2084
Liangwei Dong1a18faf2018-07-16 06:39:29 -04002085/**
2086 * policy_mgr_check_privacy_for_new_conn() - Check privacy mode concurrency
2087 * @pm_ctx: policy_mgr_psoc_priv_obj policy mgr context
2088 *
2089 * This routine is called to check vdev security mode allowed in concurrency.
2090 * At present, WAPI security mode is not allowed to run concurrency with any
2091 * other vdev.
2092 *
2093 * Return: true - allow
2094 */
2095static bool policy_mgr_check_privacy_for_new_conn(
2096 struct policy_mgr_psoc_priv_obj *pm_ctx)
2097{
2098 if (!pm_ctx->hdd_cbacks.hdd_wapi_security_sta_exist)
2099 return true;
2100
2101 if (pm_ctx->hdd_cbacks.hdd_wapi_security_sta_exist() &&
2102 (policy_mgr_get_connection_count(pm_ctx->psoc) > 0))
2103 return false;
2104
2105 return true;
2106}
2107
Jianmin Zhucdb16bd2019-05-15 19:33:55 +08002108#ifdef FEATURE_FOURTH_CONNECTION
2109static bool policy_mgr_is_concurrency_allowed_4_port(
2110 struct wlan_objmgr_psoc *psoc,
2111 enum policy_mgr_con_mode mode,
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002112 uint32_t ch_freq,
Jianmin Zhucdb16bd2019-05-15 19:33:55 +08002113 struct policy_mgr_pcl_list pcl)
2114{
2115 uint32_t i;
2116 struct policy_mgr_psoc_priv_obj *pm_ctx;
gaurank kathpalia7fd92d92020-02-27 00:02:54 +05302117 uint8_t sap_cnt, go_cnt;
Jianmin Zhucdb16bd2019-05-15 19:33:55 +08002118
2119 /* new STA may just have ssid, no channel until bssid assigned */
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002120 if (ch_freq == 0 && mode == PM_STA_MODE)
Jianmin Zhucdb16bd2019-05-15 19:33:55 +08002121 return true;
2122
gaurank kathpalia7fd92d92020-02-27 00:02:54 +05302123 sap_cnt = policy_mgr_mode_specific_connection_count(psoc,
2124 PM_SAP_MODE, NULL);
2125
2126 go_cnt = policy_mgr_mode_specific_connection_count(psoc,
2127 PM_P2P_GO_MODE, NULL);
2128 if (sap_cnt || go_cnt) {
2129 pm_ctx = policy_mgr_get_context(psoc);
2130 if (!pm_ctx) {
2131 policy_mgr_err("context is NULL");
2132 return false;
2133 }
2134
2135 if (policy_mgr_get_mcc_to_scc_switch_mode(psoc) !=
2136 QDF_MCC_TO_SCC_SWITCH_FORCE_WITHOUT_DISCONNECTION) {
2137 policy_mgr_err("couldn't start 4th port for bad force scc cfg");
2138 return false;
2139 }
2140 if (pm_ctx->cfg.dual_mac_feature ||
2141 !pm_ctx->cfg.sta_sap_scc_on_dfs_chnl ||
2142 !pm_ctx->cfg.sta_sap_scc_on_lte_coex_chnl) {
2143 policy_mgr_err(
2144 "Couldn't start 4th port for bad cfg of dual mac, dfs scc, lte coex scc");
2145 return false;
2146 }
2147
2148 for (i = 0; i < pcl.pcl_len; i++)
2149 if (ch_freq == pcl.pcl_list[i])
2150 return true;
2151
2152 policy_mgr_err("4th port failed on ch freq %d with mode %d",
2153 ch_freq, mode);
2154
Jianmin Zhucdb16bd2019-05-15 19:33:55 +08002155 return false;
2156 }
2157
gaurank kathpalia7fd92d92020-02-27 00:02:54 +05302158 return true;
Jianmin Zhucdb16bd2019-05-15 19:33:55 +08002159}
2160#else
2161static inline bool policy_mgr_is_concurrency_allowed_4_port(
2162 struct wlan_objmgr_psoc *psoc,
2163 enum policy_mgr_con_mode mode,
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002164 uint32_t ch_freq,
2165 struct policy_mgr_pcl_list pcl)
2166{return false; }
Jianmin Zhucdb16bd2019-05-15 19:33:55 +08002167#endif
2168
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002169/**
2170 * policy_mgr_allow_multiple_sta_connections() - check whether multiple STA
2171 * concurrency is allowed and F/W supported
2172 * @psoc: Pointer to soc
2173 * @second_sta_freq: 2nd STA channel frequency
2174 * @first_sta_freq: 1st STA channel frequency
2175 *
2176 * Return: true if supports else false.
2177 */
2178static bool policy_mgr_allow_multiple_sta_connections(struct wlan_objmgr_psoc *psoc,
2179 uint32_t second_sta_freq,
2180 uint32_t first_sta_freq)
2181{
2182 struct wmi_unified *wmi_handle;
2183
2184 wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
2185 if (!wmi_handle) {
2186 policy_mgr_debug("Invalid WMI handle");
2187 return false;
2188 }
2189 if (!wmi_service_enabled(wmi_handle,
2190 wmi_service_sta_plus_sta_support))
2191 return false;
2192
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002193 return true;
2194}
2195
Liangwei Dongadbb5df2019-11-05 13:19:37 +08002196#if defined(CONFIG_BAND_6GHZ) && defined(WLAN_FEATURE_11AX)
2197bool policy_mgr_is_6ghz_conc_mode_supported(
2198 struct wlan_objmgr_psoc *psoc, enum policy_mgr_con_mode mode)
2199{
2200 if (mode == PM_STA_MODE || mode == PM_SAP_MODE)
2201 return true;
2202 else
2203 return false;
2204}
2205#endif
2206
Liangwei Dong05276172019-12-27 10:31:46 +08002207/**
2208 * policy_mgr_is_6g_channel_allowed() - Check new 6Ghz connection
2209 * allowed or not
2210 * @psoc: Pointer to soc
2211 * @mode: new connection mode
2212 * @ch_freq: channel freq
2213 *
2214 * 1. Only STA/SAP are allowed on 6Ghz.
2215 * 2. If there is DFS beacon entity existing on 5G band, 5G+6G MCC is not
2216 * allowed.
2217 *
2218 * Return: true if supports else false.
2219 */
2220static bool policy_mgr_is_6g_channel_allowed(
2221 struct wlan_objmgr_psoc *psoc, enum policy_mgr_con_mode mode,
2222 uint32_t ch_freq)
2223{
2224 uint32_t conn_index = 0;
2225 struct policy_mgr_psoc_priv_obj *pm_ctx;
2226 struct policy_mgr_conc_connection_info *conn;
2227 bool is_dfs;
2228
2229 pm_ctx = policy_mgr_get_context(psoc);
2230 if (!pm_ctx) {
2231 policy_mgr_err("Invalid Context");
2232 return false;
2233 }
2234 if (!WLAN_REG_IS_6GHZ_CHAN_FREQ(ch_freq))
2235 return true;
2236
2237 /* Only STA/SAP is supported on 6Ghz currently */
2238 if (!policy_mgr_is_6ghz_conc_mode_supported(psoc, mode))
2239 return false;
2240
2241 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
2242 for (conn_index = 0; conn_index < MAX_NUMBER_OF_CONC_CONNECTIONS;
2243 conn_index++) {
2244 conn = &pm_conc_connection_list[conn_index];
2245 if (!conn->in_use)
2246 continue;
2247 is_dfs = (conn->ch_flagext &
2248 (IEEE80211_CHAN_DFS | IEEE80211_CHAN_DFS_CFREQ2)) &&
2249 WLAN_REG_IS_5GHZ_CH_FREQ(conn->freq);
2250 if ((conn->mode == PM_SAP_MODE ||
2251 conn->mode == PM_P2P_GO_MODE) &&
2252 is_dfs && ch_freq != conn->freq) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302253 policy_mgr_rl_debug("don't allow MCC if SAP/GO on DFS channel");
Liangwei Dong05276172019-12-27 10:31:46 +08002254 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
2255 return false;
2256 }
2257 }
2258 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
2259
2260 return true;
2261}
2262
Tushnim Bhattacharyya0351f172018-07-31 12:24:57 -07002263bool policy_mgr_is_concurrency_allowed(struct wlan_objmgr_psoc *psoc,
2264 enum policy_mgr_con_mode mode,
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002265 uint32_t ch_freq,
Tushnim Bhattacharyya0351f172018-07-31 12:24:57 -07002266 enum hw_mode_bandwidth bw)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002267{
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002268 uint32_t num_connections = 0, count = 0, index = 0;
2269 bool status = false, match = false;
2270 uint32_t list[MAX_NUMBER_OF_CONC_CONNECTIONS];
2271 struct policy_mgr_psoc_priv_obj *pm_ctx;
Bala Venkatesh06a4e7c2018-06-09 20:19:18 +05302272 bool sta_sap_scc_on_dfs_chan;
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002273 uint32_t sta_freq;
Kiran Kumar Lokere54140662019-11-01 18:42:09 -07002274 enum channel_state chan_state;
2275 bool is_dfs_ch = false;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002276
2277 pm_ctx = policy_mgr_get_context(psoc);
2278 if (!pm_ctx) {
2279 policy_mgr_err("Invalid Context");
2280 return status;
2281 }
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002282 /* find the current connection state from pm_conc_connection_list*/
2283 num_connections = policy_mgr_get_connection_count(psoc);
2284
Tushnim Bhattacharyyad7655ca2017-04-26 12:58:42 -07002285 if (num_connections && policy_mgr_is_sub_20_mhz_enabled(psoc)) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302286 policy_mgr_rl_debug("dont allow concurrency if Sub 20 MHz is enabled");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002287 status = false;
2288 goto done;
2289 }
2290
2291 if (policy_mgr_max_concurrent_connections_reached(psoc)) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302292 policy_mgr_rl_debug("Reached max concurrent connections: %d",
2293 pm_ctx->cfg.max_conc_cxns);
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002294 goto done;
2295 }
2296
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002297 if (ch_freq) {
Kiran Kumar Lokere54140662019-11-01 18:42:09 -07002298 chan_state = wlan_reg_get_5g_bonded_channel_state_for_freq(
2299 pm_ctx->pdev, ch_freq,
2300 policy_mgr_get_ch_width(bw));
2301 if (chan_state == CHANNEL_STATE_DFS)
2302 is_dfs_ch = true;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002303 /* don't allow 3rd home channel on same MAC */
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002304 if (!policy_mgr_allow_new_home_channel(psoc, mode, ch_freq,
Kiran Kumar Lokere54140662019-11-01 18:42:09 -07002305 num_connections,
2306 is_dfs_ch))
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002307 goto done;
2308
2309 /*
2310 * 1) DFS MCC is not yet supported
2311 * 2) If you already have STA connection on 5G channel then
2312 * don't allow any other persona to make connection on DFS
2313 * channel because STA 5G + DFS MCC is not allowed.
2314 * 3) If STA is on 2G channel and SAP is coming up on
2315 * DFS channel then allow concurrency but make sure it is
2316 * going to DBS and send PCL to firmware indicating that
2317 * don't allow STA to roam to 5G channels.
Krishna Reddy3c629902019-07-05 12:42:29 +05302318 * 4) On a single MAC device, if a SAP/P2PGO is already on a DFS
2319 * channel, don't allow a 2 channel as it will result
2320 * in MCC which is not allowed.
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002321 */
2322 if (!policy_mgr_is_5g_channel_allowed(psoc,
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002323 ch_freq, list, PM_P2P_GO_MODE))
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002324 goto done;
2325 if (!policy_mgr_is_5g_channel_allowed(psoc,
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002326 ch_freq, list, PM_SAP_MODE))
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002327 goto done;
Liangwei Dong05276172019-12-27 10:31:46 +08002328 if (!policy_mgr_is_6g_channel_allowed(psoc, mode,
2329 ch_freq))
2330 goto done;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002331
Bala Venkatesh06a4e7c2018-06-09 20:19:18 +05302332 sta_sap_scc_on_dfs_chan =
2333 policy_mgr_is_sta_sap_scc_allowed_on_dfs_chan(psoc);
Bala Venkatesh06a4e7c2018-06-09 20:19:18 +05302334
2335 if (!sta_sap_scc_on_dfs_chan && ((mode == PM_P2P_GO_MODE) ||
2336 (mode == PM_SAP_MODE))) {
Kiran Kumar Lokere54140662019-11-01 18:42:09 -07002337 if (is_dfs_ch)
Manikandan Mohana0bbb512019-08-15 11:39:26 -07002338 match = policy_mgr_disallow_mcc(psoc,
2339 ch_freq);
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002340 }
2341 if (true == match) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302342 policy_mgr_rl_debug("No MCC, SAP/GO about to come up on DFS channel");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002343 goto done;
2344 }
Krishna Reddy3c629902019-07-05 12:42:29 +05302345 if ((policy_mgr_is_hw_dbs_capable(psoc) != true) &&
2346 num_connections) {
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002347 if (WLAN_REG_IS_24GHZ_CH_FREQ(ch_freq)) {
Krishna Reddy3c629902019-07-05 12:42:29 +05302348 if (policy_mgr_is_sap_p2pgo_on_dfs(psoc)) {
Amruta Kulkarni447a3262020-02-05 14:57:04 -08002349 policy_mgr_rl_debug("MCC not allowed: SAP/P2PGO on DFS");
Krishna Reddy3c629902019-07-05 12:42:29 +05302350 goto done;
2351 }
2352 }
2353 }
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002354 }
2355
Jianmin Zhue487f792019-10-15 13:34:34 +08002356 /* Check for STA+STA concurrency */
Rajeev Kumar Sirasanagandla02cf4c92019-04-02 16:29:30 +05302357 count = policy_mgr_mode_specific_connection_count(psoc, PM_STA_MODE,
2358 list);
Jianmin Zhue487f792019-10-15 13:34:34 +08002359 if (mode == PM_STA_MODE && count) {
2360 if (count >= 2) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302361 policy_mgr_rl_debug("3rd STA isn't permitted");
Jianmin Zhue487f792019-10-15 13:34:34 +08002362 goto done;
2363 }
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002364 sta_freq = pm_conc_connection_list[list[0]].freq;
2365 if (!policy_mgr_allow_multiple_sta_connections(psoc, ch_freq,
2366 sta_freq))
Jianmin Zhue487f792019-10-15 13:34:34 +08002367 goto done;
Rajeev Kumar Sirasanagandla02cf4c92019-04-02 16:29:30 +05302368 }
2369
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002370 /*
2371 * Check all IBSS+STA concurrencies
2372 *
2373 * don't allow IBSS + STA MCC
2374 * don't allow IBSS + STA SCC if IBSS is on DFS channel
2375 */
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002376 if ((PM_IBSS_MODE == mode) &&
2377 (policy_mgr_mode_specific_connection_count(psoc,
2378 PM_IBSS_MODE, list)) && count) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302379 policy_mgr_rl_debug("No 2nd IBSS, we already have STA + IBSS");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002380 goto done;
2381 }
2382 if ((PM_IBSS_MODE == mode) &&
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002383 (wlan_reg_is_dfs_for_freq(pm_ctx->pdev, ch_freq)) && count) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302384 policy_mgr_rl_debug("No IBSS + STA SCC/MCC, IBSS is on DFS channel");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002385 goto done;
2386 }
2387 if (PM_IBSS_MODE == mode) {
2388 if (policy_mgr_is_hw_dbs_capable(psoc) == true) {
2389 if (num_connections > 1) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302390 policy_mgr_rl_debug("No IBSS, we have concurrent connections already");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002391 goto done;
2392 }
2393 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
2394 if (PM_STA_MODE != pm_conc_connection_list[0].mode) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302395 policy_mgr_rl_debug("No IBSS, we've a non-STA connection");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002396 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
2397 goto done;
2398 }
2399 /*
2400 * This logic protects STA and IBSS to come up on same
2401 * band. If requirement changes then this condition
2402 * needs to be removed
2403 */
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002404 if (ch_freq &&
2405 pm_conc_connection_list[0].freq != ch_freq &&
2406 WLAN_REG_IS_SAME_BAND_FREQS(
2407 pm_conc_connection_list[0].freq, ch_freq)) {
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002408 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
Abhishek Singheb63fb92020-03-03 10:41:37 +05302409 policy_mgr_rl_debug("No IBSS + STA MCC");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002410 goto done;
2411 }
2412 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
2413 } else if (num_connections) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302414 policy_mgr_rl_debug("No IBSS, we have one connection already");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002415 goto done;
2416 }
2417 }
2418
2419 if ((PM_STA_MODE == mode) &&
2420 (policy_mgr_mode_specific_connection_count(psoc,
2421 PM_IBSS_MODE, list)) && count) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302422 policy_mgr_rl_debug("No 2nd STA, we already have STA + IBSS");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002423 goto done;
2424 }
2425
2426 if ((PM_STA_MODE == mode) &&
2427 (policy_mgr_mode_specific_connection_count(psoc,
2428 PM_IBSS_MODE, list))) {
2429 if (policy_mgr_is_hw_dbs_capable(psoc) == true) {
2430 if (num_connections > 1) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302431 policy_mgr_rl_debug("No 2nd STA, we already have IBSS concurrency");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002432 goto done;
2433 }
2434 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002435 if (ch_freq &&
2436 (wlan_reg_is_dfs_for_freq(pm_ctx->pdev,
2437 pm_conc_connection_list[0].freq)) &&
2438 (WLAN_REG_IS_5GHZ_CH_FREQ(ch_freq))) {
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002439 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
Abhishek Singheb63fb92020-03-03 10:41:37 +05302440 policy_mgr_rl_debug("No IBSS + STA SCC/MCC, IBSS is on DFS channel");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002441 goto done;
2442 }
2443 /*
2444 * This logic protects STA and IBSS to come up on same
2445 * band. If requirement changes then this condition
2446 * needs to be removed
2447 */
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002448 if (pm_conc_connection_list[0].freq != ch_freq &&
2449 WLAN_REG_IS_SAME_BAND_FREQS(
2450 pm_conc_connection_list[0].freq, ch_freq)) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302451 policy_mgr_rl_debug("No IBSS + STA MCC");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002452 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
2453 goto done;
2454 }
2455 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
2456 } else {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302457 policy_mgr_rl_debug("No STA, we have IBSS connection already");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002458 goto done;
2459 }
2460 }
2461
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002462 if (!policy_mgr_allow_sap_go_concurrency(psoc, mode, ch_freq,
Jianmin Zhue1ebfd02018-08-21 19:20:28 +08002463 WLAN_INVALID_VDEV_ID)) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302464 policy_mgr_rl_debug("This concurrency combination is not allowed");
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08002465 goto done;
2466 }
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002467 /* don't allow two P2P GO on same band */
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002468 if (ch_freq && mode == PM_P2P_GO_MODE && num_connections) {
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002469 index = 0;
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002470 count = policy_mgr_mode_specific_connection_count(
2471 psoc, PM_P2P_GO_MODE, list);
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002472 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
2473 while (index < count) {
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002474 if (WLAN_REG_IS_SAME_BAND_FREQS(
2475 ch_freq,
2476 pm_conc_connection_list[list[index]].freq)) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302477 policy_mgr_rl_debug("Don't allow P2P GO on same band");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002478 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
2479 goto done;
2480 }
2481 index++;
2482 }
2483 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
2484 }
2485
Liangwei Dong1a18faf2018-07-16 06:39:29 -04002486 if (!policy_mgr_check_privacy_for_new_conn(pm_ctx)) {
Abhishek Singheb63fb92020-03-03 10:41:37 +05302487 policy_mgr_rl_debug("Don't allow new conn when wapi security conn existing");
Liangwei Dong1a18faf2018-07-16 06:39:29 -04002488 goto done;
2489 }
2490
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002491 status = true;
2492
2493done:
2494 return status;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002495}
2496
Manikandan Mohan282c4b62019-08-14 17:42:22 -07002497bool policy_mgr_allow_concurrency(struct wlan_objmgr_psoc *psoc,
2498 enum policy_mgr_con_mode mode,
2499 uint32_t ch_freq,
2500 enum hw_mode_bandwidth bw)
Tushnim Bhattacharyya0351f172018-07-31 12:24:57 -07002501{
2502 QDF_STATUS status;
2503 struct policy_mgr_pcl_list pcl;
Jianmin Zhucdb16bd2019-05-15 19:33:55 +08002504 bool allowed;
Tushnim Bhattacharyya0351f172018-07-31 12:24:57 -07002505
2506 qdf_mem_zero(&pcl, sizeof(pcl));
Manikandan Mohan19f36092019-08-15 15:54:02 -07002507 status = policy_mgr_get_pcl(psoc, mode, pcl.pcl_list, &pcl.pcl_len,
2508 pcl.weight_list,
2509 QDF_ARRAY_SIZE(pcl.weight_list));
Tushnim Bhattacharyya0351f172018-07-31 12:24:57 -07002510 if (QDF_IS_STATUS_ERROR(status)) {
2511 policy_mgr_err("disallow connection:%d", status);
2512 return false;
2513 }
2514
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002515 allowed = policy_mgr_is_concurrency_allowed(psoc, mode, ch_freq, bw);
Jianmin Zhucdb16bd2019-05-15 19:33:55 +08002516
2517 /* Fourth connection concurrency check */
2518 if (allowed && policy_mgr_get_connection_count(psoc) == 3)
2519 allowed = policy_mgr_is_concurrency_allowed_4_port(
2520 psoc,
2521 mode,
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002522 ch_freq,
Jianmin Zhucdb16bd2019-05-15 19:33:55 +08002523 pcl);
2524 return allowed;
Tushnim Bhattacharyya0351f172018-07-31 12:24:57 -07002525}
2526
Manikandan Mohan282c4b62019-08-14 17:42:22 -07002527bool
2528policy_mgr_allow_concurrency_csa(struct wlan_objmgr_psoc *psoc,
2529 enum policy_mgr_con_mode mode,
2530 uint32_t ch_freq, uint32_t vdev_id,
2531 bool forced, enum sap_csa_reason_code reason)
Jianmin Zhu687602c2018-08-24 17:01:14 +08002532{
2533 bool allow = false;
Liangwei Dong86ff7102019-07-17 16:44:01 +08002534 struct policy_mgr_conc_connection_info
2535 info[MAX_NUMBER_OF_CONC_CONNECTIONS];
Jianmin Zhu687602c2018-08-24 17:01:14 +08002536 uint8_t num_cxn_del = 0;
Abhishek Singh424ca572019-03-26 11:48:38 +05302537 struct policy_mgr_psoc_priv_obj *pm_ctx;
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002538 uint32_t old_ch_freq;
Liangwei Dong86ff7102019-07-17 16:44:01 +08002539 QDF_STATUS status;
Abhishek Singh424ca572019-03-26 11:48:38 +05302540
2541 pm_ctx = policy_mgr_get_context(psoc);
2542 if (!pm_ctx) {
2543 policy_mgr_err("Invalid Context");
2544 return allow;
2545 }
Liangwei Dong86ff7102019-07-17 16:44:01 +08002546 policy_mgr_debug("check concurrency_csa vdev:%d ch %d, forced %d, reason %d",
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002547 vdev_id, ch_freq, forced, reason);
Liangwei Dong86ff7102019-07-17 16:44:01 +08002548
Manikandan Mohana0bbb512019-08-15 11:39:26 -07002549 status = policy_mgr_get_chan_by_session_id(psoc, vdev_id,
2550 &old_ch_freq);
Liangwei Dong86ff7102019-07-17 16:44:01 +08002551 if (QDF_IS_STATUS_ERROR(status)) {
2552 policy_mgr_err("Failed to get channel for vdev:%d",
2553 vdev_id);
2554 return allow;
2555 }
2556 qdf_mem_zero(info, sizeof(info));
Jianmin Zhu687602c2018-08-24 17:01:14 +08002557
2558 /*
2559 * Store the connection's parameter and temporarily delete it
2560 * from the concurrency table. This way the allow concurrency
2561 * check can be used as though a new connection is coming up,
2562 * after check, restore the connection to concurrency table.
Liangwei Dong86ff7102019-07-17 16:44:01 +08002563 *
2564 * In SAP+SAP SCC case, when LTE unsafe event processing,
2565 * we should remove the all SAP conn entry on the same ch before
2566 * do the concurrency check. Otherwise the left SAP on old channel
2567 * will cause the concurrency check failure because of dual beacon
2568 * MCC not supported. for the CSA request reason code,
2569 * PM_CSA_REASON_UNSAFE_CHANNEL, we remove all the SAP
2570 * entry on old channel before do concurrency check.
2571 *
2572 * The assumption is both SAP should move to the new channel later for
2573 * the reason code.
Jianmin Zhu687602c2018-08-24 17:01:14 +08002574 */
Abhishek Singh424ca572019-03-26 11:48:38 +05302575 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
Liangwei Dong86ff7102019-07-17 16:44:01 +08002576
2577 if (forced && reason == CSA_REASON_UNSAFE_CHANNEL)
2578 policy_mgr_store_and_del_conn_info_by_chan_and_mode(
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002579 psoc, old_ch_freq, mode, info, &num_cxn_del);
Liangwei Dong86ff7102019-07-17 16:44:01 +08002580 else
2581 policy_mgr_store_and_del_conn_info_by_vdev_id(
2582 psoc, vdev_id, info, &num_cxn_del);
2583
Manikandan Mohan282c4b62019-08-14 17:42:22 -07002584 allow = policy_mgr_allow_concurrency(psoc, mode, ch_freq,
2585 HW_MODE_20_MHZ);
Jianmin Zhu687602c2018-08-24 17:01:14 +08002586 /* Restore the connection entry */
2587 if (num_cxn_del > 0)
Liangwei Dong86ff7102019-07-17 16:44:01 +08002588 policy_mgr_restore_deleted_conn_info(psoc, info, num_cxn_del);
Abhishek Singh424ca572019-03-26 11:48:38 +05302589 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
2590
2591 if (!allow)
2592 policy_mgr_err("CSA concurrency check failed");
Jianmin Zhu687602c2018-08-24 17:01:14 +08002593
2594 return allow;
2595}
2596
Archana Ramachandran107d3782017-03-06 17:07:44 -08002597/**
2598 * policy_mgr_get_concurrency_mode() - return concurrency mode
2599 * @psoc: PSOC object information
2600 *
2601 * This routine is used to retrieve concurrency mode
2602 *
2603 * Return: uint32_t value of concurrency mask
2604 */
2605uint32_t policy_mgr_get_concurrency_mode(struct wlan_objmgr_psoc *psoc)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002606{
Archana Ramachandran107d3782017-03-06 17:07:44 -08002607 struct policy_mgr_psoc_priv_obj *pm_ctx;
2608
2609 pm_ctx = policy_mgr_get_context(psoc);
2610 if (!pm_ctx) {
2611 policy_mgr_err("Invalid context");
2612 return QDF_STA_MASK;
2613 }
2614
Arun Kumar Khandavallif4ed4062020-01-20 11:45:09 +05302615 policy_mgr_debug("concurrency_mode: 0x%x",
2616 pm_ctx->concurrency_mode);
Archana Ramachandran107d3782017-03-06 17:07:44 -08002617
2618 return pm_ctx->concurrency_mode;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002619}
2620
Archana Ramachandran0edce252017-03-06 14:36:29 -08002621/**
2622 * policy_mgr_get_channel_from_scan_result() - to get channel from scan result
2623 * @psoc: PSOC object information
2624 * @roam_profile: pointer to roam profile
2625 * @channel: channel to be filled
2626 *
2627 * This routine gets channel which most likely a candidate to which STA
2628 * will make connection.
2629 *
2630 * Return: QDF_STATUS
2631 */
Manikandan Mohan282c4b62019-08-14 17:42:22 -07002632QDF_STATUS policy_mgr_get_channel_from_scan_result(
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002633 struct wlan_objmgr_psoc *psoc,
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002634 void *roam_profile, uint32_t *ch_freq)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002635{
Tushnim Bhattacharyya42b80672017-08-21 13:01:21 -07002636 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Archana Ramachandran0edce252017-03-06 14:36:29 -08002637 void *scan_cache = NULL;
2638 struct policy_mgr_psoc_priv_obj *pm_ctx;
2639
2640 pm_ctx = policy_mgr_get_context(psoc);
2641 if (!pm_ctx) {
2642 policy_mgr_err("Invalid context");
2643 return QDF_STATUS_E_INVAL;
2644 }
2645
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002646 if (!roam_profile || !ch_freq) {
Archana Ramachandran0edce252017-03-06 14:36:29 -08002647 policy_mgr_err("Invalid input parameters");
2648 return QDF_STATUS_E_INVAL;
2649 }
2650
Archana Ramachandran658a48d2017-03-23 23:30:23 -07002651 if (pm_ctx->sme_cbacks.sme_get_ap_channel_from_scan) {
2652 status = pm_ctx->sme_cbacks.sme_get_ap_channel_from_scan
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002653 (roam_profile, &scan_cache, ch_freq);
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -07002654 if (status != QDF_STATUS_SUCCESS) {
2655 policy_mgr_err("Get AP channel failed");
2656 return status;
2657 }
Archana Ramachandran658a48d2017-03-23 23:30:23 -07002658 } else {
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -07002659 policy_mgr_err("sme_get_ap_channel_from_scan_cache NULL");
Tushnim Bhattacharyya42b80672017-08-21 13:01:21 -07002660 return QDF_STATUS_E_FAILURE;
Archana Ramachandran658a48d2017-03-23 23:30:23 -07002661 }
Archana Ramachandran0edce252017-03-06 14:36:29 -08002662
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -07002663 if (pm_ctx->sme_cbacks.sme_scan_result_purge)
2664 status = pm_ctx->sme_cbacks.sme_scan_result_purge(scan_cache);
2665 else
2666 policy_mgr_err("sme_scan_result_purge NULL");
Archana Ramachandran0edce252017-03-06 14:36:29 -08002667
2668 return status;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002669}
2670
Archana Ramachandran3d9b5cf2017-03-10 18:56:44 -08002671QDF_STATUS policy_mgr_set_user_cfg(struct wlan_objmgr_psoc *psoc,
2672 struct policy_mgr_user_cfg *user_cfg)
2673{
2674
2675 struct policy_mgr_psoc_priv_obj *pm_ctx;
2676
2677 pm_ctx = policy_mgr_get_context(psoc);
2678 if (!pm_ctx) {
2679 policy_mgr_err("Invalid context");
2680 return QDF_STATUS_E_FAILURE;
2681 }
Jeff Johnsone79b53c2019-03-18 14:03:23 -07002682 if (!user_cfg) {
Archana Ramachandran3d9b5cf2017-03-10 18:56:44 -08002683 policy_mgr_err("Invalid User Config");
2684 return QDF_STATUS_E_FAILURE;
2685 }
2686
2687 pm_ctx->user_cfg = *user_cfg;
Krunal Sonid4e542b2018-09-27 12:40:33 -07002688 policy_mgr_debug("dbs_selection_plcy 0x%x",
2689 pm_ctx->cfg.dbs_selection_plcy);
Liangwei Dongecbf1132018-05-25 05:24:12 -04002690 policy_mgr_debug("vdev_priority_list 0x%x",
Krunal Sonid4e542b2018-09-27 12:40:33 -07002691 pm_ctx->cfg.vdev_priority_list);
Krunal Soni6dd22082018-09-27 10:40:24 -07002692 pm_ctx->cur_conc_system_pref = pm_ctx->cfg.sys_pref;
Ganesh Kondabattini2a8c7b02017-07-10 17:34:36 +05302693
Archana Ramachandran3d9b5cf2017-03-10 18:56:44 -08002694 return QDF_STATUS_SUCCESS;
2695}
2696
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002697uint32_t policy_mgr_search_and_check_for_session_conc(
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002698 struct wlan_objmgr_psoc *psoc,
2699 uint8_t session_id,
2700 void *roam_profile)
2701{
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002702 uint32_t ch_freq = 0;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002703 QDF_STATUS status;
2704 enum policy_mgr_con_mode mode;
2705 bool ret;
Tushnim Bhattacharyya59cbe5c2017-03-24 14:13:52 -07002706 struct policy_mgr_psoc_priv_obj *pm_ctx;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002707
Tushnim Bhattacharyya59cbe5c2017-03-24 14:13:52 -07002708 pm_ctx = policy_mgr_get_context(psoc);
2709 if (!pm_ctx) {
2710 policy_mgr_err("Invalid Context");
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002711 return ch_freq;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002712 }
2713
Tushnim Bhattacharyya59cbe5c2017-03-24 14:13:52 -07002714 if (pm_ctx->hdd_cbacks.get_mode_for_non_connected_vdev) {
2715 mode = pm_ctx->hdd_cbacks.get_mode_for_non_connected_vdev(
2716 psoc, session_id);
2717 if (PM_MAX_NUM_OF_MODE == mode) {
2718 policy_mgr_err("Invalid mode");
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002719 return ch_freq;
Tushnim Bhattacharyya59cbe5c2017-03-24 14:13:52 -07002720 }
2721 } else
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002722 return ch_freq;
Tushnim Bhattacharyya59cbe5c2017-03-24 14:13:52 -07002723
Manikandan Mohan282c4b62019-08-14 17:42:22 -07002724 status = policy_mgr_get_channel_from_scan_result(
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002725 psoc, roam_profile, &ch_freq);
2726 if (QDF_STATUS_SUCCESS != status || ch_freq == 0) {
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002727 policy_mgr_err("%s error %d %d",
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002728 __func__, status, ch_freq);
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002729 return 0;
2730 }
2731
2732 /* Take care of 160MHz and 80+80Mhz later */
Manikandan Mohan282c4b62019-08-14 17:42:22 -07002733 ret = policy_mgr_allow_concurrency(psoc, mode, ch_freq,
2734 HW_MODE_20_MHZ);
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002735 if (false == ret) {
2736 policy_mgr_err("Connection failed due to conc check fail");
2737 return 0;
2738 }
2739
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002740 return ch_freq;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002741}
2742
Archana Ramachandran266613f2017-03-13 16:36:55 -07002743/**
2744 * policy_mgr_is_two_connection_mcc() - Check if MCC scenario
2745 * when there are two connections
2746 *
2747 * If if MCC scenario when there are two connections
2748 *
2749 * Return: true or false
2750 */
2751static bool policy_mgr_is_two_connection_mcc(void)
Archana Ramachandran107d3782017-03-06 17:07:44 -08002752{
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002753 return ((pm_conc_connection_list[0].freq !=
2754 pm_conc_connection_list[1].freq) &&
Archana Ramachandran266613f2017-03-13 16:36:55 -07002755 (pm_conc_connection_list[0].mac ==
2756 pm_conc_connection_list[1].mac) &&
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002757 (pm_conc_connection_list[0].freq <=
2758 WLAN_REG_MAX_24GHZ_CHAN_FREQ) &&
2759 (pm_conc_connection_list[1].freq <=
2760 WLAN_REG_MAX_24GHZ_CHAN_FREQ)) ? true : false;
Archana Ramachandran266613f2017-03-13 16:36:55 -07002761}
2762
2763/**
2764 * policy_mgr_is_three_connection_mcc() - Check if MCC scenario
2765 * when there are three connections
2766 *
2767 * If if MCC scenario when there are three connections
2768 *
2769 * Return: true or false
2770 */
2771static bool policy_mgr_is_three_connection_mcc(void)
2772{
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002773 return (((pm_conc_connection_list[0].freq !=
2774 pm_conc_connection_list[1].freq) ||
2775 (pm_conc_connection_list[0].freq !=
2776 pm_conc_connection_list[2].freq) ||
2777 (pm_conc_connection_list[1].freq !=
2778 pm_conc_connection_list[2].freq)) &&
2779 (pm_conc_connection_list[0].freq <=
2780 WLAN_REG_MAX_24GHZ_CHAN_FREQ) &&
2781 (pm_conc_connection_list[1].freq <=
2782 WLAN_REG_MAX_24GHZ_CHAN_FREQ) &&
2783 (pm_conc_connection_list[2].freq <=
2784 WLAN_REG_MAX_24GHZ_CHAN_FREQ)) ? true : false;
Archana Ramachandran266613f2017-03-13 16:36:55 -07002785}
2786
2787bool policy_mgr_is_mcc_in_24G(struct wlan_objmgr_psoc *psoc)
2788{
2789 uint32_t num_connections = 0;
2790 bool is_24G_mcc = false;
2791
2792 num_connections = policy_mgr_get_connection_count(psoc);
2793
2794 switch (num_connections) {
2795 case 1:
2796 break;
2797 case 2:
2798 if (policy_mgr_is_two_connection_mcc())
2799 is_24G_mcc = true;
2800 break;
2801 case 3:
2802 if (policy_mgr_is_three_connection_mcc())
2803 is_24G_mcc = true;
2804 break;
2805 default:
2806 policy_mgr_err("unexpected num_connections value %d",
2807 num_connections);
2808 break;
2809 }
2810
2811 return is_24G_mcc;
Archana Ramachandran107d3782017-03-06 17:07:44 -08002812}
2813
Manikandan Mohan7fdb0252019-08-14 16:49:02 -07002814bool policy_mgr_check_for_session_conc(struct wlan_objmgr_psoc *psoc,
2815 uint8_t session_id, uint32_t ch_freq)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002816{
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002817 enum policy_mgr_con_mode mode;
2818 bool ret;
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -07002819 struct policy_mgr_psoc_priv_obj *pm_ctx;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002820
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -07002821 pm_ctx = policy_mgr_get_context(psoc);
2822 if (!pm_ctx) {
2823 policy_mgr_err("Invalid Context");
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002824 return false;
2825 }
2826
Tushnim Bhattacharyya7051ad02017-03-23 11:16:40 -07002827 if (pm_ctx->hdd_cbacks.get_mode_for_non_connected_vdev) {
2828 mode = pm_ctx->hdd_cbacks.get_mode_for_non_connected_vdev(
2829 psoc, session_id);
2830 if (PM_MAX_NUM_OF_MODE == mode) {
2831 policy_mgr_err("Invalid mode");
2832 return false;
2833 }
2834 } else
2835 return false;
2836
Manikandan Mohan932c11e2019-08-14 14:09:08 -07002837 if (ch_freq == 0) {
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002838 policy_mgr_err("Invalid channel number 0");
2839 return false;
2840 }
2841
2842 /* Take care of 160MHz and 80+80Mhz later */
Manikandan Mohan282c4b62019-08-14 17:42:22 -07002843 ret = policy_mgr_allow_concurrency(psoc, mode, ch_freq, HW_MODE_20_MHZ);
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002844 if (false == ret) {
2845 policy_mgr_err("Connection failed due to conc check fail");
2846 return 0;
2847 }
2848
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002849 return true;
2850}
2851
Archana Ramachandran3d9b5cf2017-03-10 18:56:44 -08002852/**
2853 * policy_mgr_change_mcc_go_beacon_interval() - Change MCC beacon interval
2854 * @psoc: PSOC object information
2855 * @vdev_id: vdev id
2856 * @dev_mode: device mode
2857 *
2858 * Updates the beacon parameters of the GO in MCC scenario
2859 *
2860 * Return: Success or Failure depending on the overall function behavior
2861 */
Archana Ramachandran8e3ee362017-03-03 20:02:10 -08002862QDF_STATUS policy_mgr_change_mcc_go_beacon_interval(
2863 struct wlan_objmgr_psoc *psoc,
Jeff Johnson275208b2017-11-09 09:54:12 -08002864 uint8_t vdev_id, enum QDF_OPMODE dev_mode)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002865{
Archana Ramachandran8e3ee362017-03-03 20:02:10 -08002866 QDF_STATUS status;
Archana Ramachandran7abbf562017-03-02 13:14:34 -08002867 struct policy_mgr_psoc_priv_obj *pm_ctx;
Archana Ramachandran7abbf562017-03-02 13:14:34 -08002868
2869 pm_ctx = policy_mgr_get_context(psoc);
2870 if (!pm_ctx) {
2871 policy_mgr_err("Invalid context");
Archana Ramachandran8e3ee362017-03-03 20:02:10 -08002872 return QDF_STATUS_E_FAILURE;
Archana Ramachandran7abbf562017-03-02 13:14:34 -08002873 }
2874
Arun Kumar Khandavallif4ed4062020-01-20 11:45:09 +05302875 policy_mgr_debug("UPDATE Beacon Params");
Archana Ramachandran8e3ee362017-03-03 20:02:10 -08002876
2877 if (QDF_SAP_MODE == dev_mode) {
Archana Ramachandran658a48d2017-03-23 23:30:23 -07002878 if (pm_ctx->sme_cbacks.sme_change_mcc_beacon_interval
2879 ) {
2880 status = pm_ctx->sme_cbacks.
2881 sme_change_mcc_beacon_interval(vdev_id);
2882 if (status == QDF_STATUS_E_FAILURE) {
2883 policy_mgr_err("Failed to update Beacon Params");
2884 return QDF_STATUS_E_FAILURE;
2885 }
2886 } else {
Archana Ramachandran8e3ee362017-03-03 20:02:10 -08002887 policy_mgr_err("sme_change_mcc_beacon_interval callback is NULL");
2888 return QDF_STATUS_E_FAILURE;
Archana Ramachandran7abbf562017-03-02 13:14:34 -08002889 }
Archana Ramachandran7abbf562017-03-02 13:14:34 -08002890 }
2891
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002892 return QDF_STATUS_SUCCESS;
2893}
2894
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002895struct policy_mgr_conc_connection_info *policy_mgr_get_conn_info(uint32_t *len)
2896{
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002897 struct policy_mgr_conc_connection_info *conn_ptr =
2898 &pm_conc_connection_list[0];
2899 *len = MAX_NUMBER_OF_CONC_CONNECTIONS;
2900
2901 return conn_ptr;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002902}
2903
2904enum policy_mgr_con_mode policy_mgr_convert_device_mode_to_qdf_type(
Jeff Johnson275208b2017-11-09 09:54:12 -08002905 enum QDF_OPMODE device_mode)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002906{
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002907 enum policy_mgr_con_mode mode = PM_MAX_NUM_OF_MODE;
2908 switch (device_mode) {
2909 case QDF_STA_MODE:
2910 mode = PM_STA_MODE;
2911 break;
2912 case QDF_P2P_CLIENT_MODE:
2913 mode = PM_P2P_CLIENT_MODE;
2914 break;
2915 case QDF_P2P_GO_MODE:
2916 mode = PM_P2P_GO_MODE;
2917 break;
2918 case QDF_SAP_MODE:
2919 mode = PM_SAP_MODE;
2920 break;
2921 case QDF_IBSS_MODE:
2922 mode = PM_IBSS_MODE;
2923 break;
Nachiket Kukadecf941602018-12-12 14:32:35 +05302924 case QDF_NAN_DISC_MODE:
2925 mode = PM_NAN_DISC_MODE;
2926 break;
Nachiket Kukade413c5fa2019-02-19 17:57:19 +05302927 case QDF_NDI_MODE:
2928 mode = PM_NDI_MODE;
2929 break;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002930 default:
Tushnim Bhattacharyyac05a1912018-09-18 15:53:50 -07002931 policy_mgr_debug("Unsupported mode (%d)",
2932 device_mode);
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08002933 }
2934
2935 return mode;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08002936}
2937
Bala Venkatesh28477d32018-05-07 21:35:55 +05302938enum QDF_OPMODE policy_mgr_get_qdf_mode_from_pm(
2939 enum policy_mgr_con_mode device_mode)
2940{
2941 enum QDF_OPMODE mode = QDF_MAX_NO_OF_MODE;
2942
2943 switch (device_mode) {
2944 case PM_STA_MODE:
2945 mode = QDF_STA_MODE;
2946 break;
2947 case PM_SAP_MODE:
2948 mode = QDF_SAP_MODE;
2949 break;
2950 case PM_P2P_CLIENT_MODE:
2951 mode = QDF_P2P_CLIENT_MODE;
2952 break;
2953 case PM_P2P_GO_MODE:
2954 mode = QDF_P2P_GO_MODE;
2955 break;
2956 case PM_IBSS_MODE:
2957 mode = QDF_IBSS_MODE;
2958 break;
Nachiket Kukadecf941602018-12-12 14:32:35 +05302959 case PM_NAN_DISC_MODE:
2960 mode = QDF_NAN_DISC_MODE;
2961 break;
Nachiket Kukade413c5fa2019-02-19 17:57:19 +05302962 case PM_NDI_MODE:
2963 mode = QDF_NDI_MODE;
2964 break;
Bala Venkatesh28477d32018-05-07 21:35:55 +05302965 default:
Tushnim Bhattacharyyac05a1912018-09-18 15:53:50 -07002966 policy_mgr_debug("Unsupported policy mgr mode (%d)",
2967 device_mode);
Bala Venkatesh28477d32018-05-07 21:35:55 +05302968 }
2969 return mode;
2970}
2971
Himanshu Agarwal0c738b72018-01-10 14:21:53 +05302972QDF_STATUS policy_mgr_mode_specific_num_open_sessions(
2973 struct wlan_objmgr_psoc *psoc, enum QDF_OPMODE mode,
2974 uint8_t *num_sessions)
2975{
2976 struct policy_mgr_psoc_priv_obj *pm_ctx;
2977
2978 pm_ctx = policy_mgr_get_context(psoc);
2979 if (!pm_ctx) {
2980 policy_mgr_err("Invalid context");
2981 return QDF_STATUS_E_FAILURE;
2982 }
2983
2984 *num_sessions = pm_ctx->no_of_open_sessions[mode];
2985 return QDF_STATUS_SUCCESS;
2986}
2987
Himanshu Agarwal533baa32018-01-25 16:20:33 +05302988QDF_STATUS policy_mgr_mode_specific_num_active_sessions(
2989 struct wlan_objmgr_psoc *psoc, enum QDF_OPMODE mode,
2990 uint8_t *num_sessions)
2991{
2992 struct policy_mgr_psoc_priv_obj *pm_ctx;
2993
2994 pm_ctx = policy_mgr_get_context(psoc);
2995 if (!pm_ctx) {
2996 policy_mgr_err("Invalid context");
2997 return QDF_STATUS_E_FAILURE;
2998 }
2999
3000 *num_sessions = pm_ctx->no_of_active_sessions[mode];
3001 return QDF_STATUS_SUCCESS;
3002}
3003
Archana Ramachandran107d3782017-03-06 17:07:44 -08003004/**
3005 * policy_mgr_concurrent_open_sessions_running() - Checks for
3006 * concurrent open session
3007 * @psoc: PSOC object information
3008 *
3009 * Checks if more than one open session is running for all the allowed modes
3010 * in the driver
3011 *
3012 * Return: True if more than one open session exists, False otherwise
3013 */
3014bool policy_mgr_concurrent_open_sessions_running(
3015 struct wlan_objmgr_psoc *psoc)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003016{
Archana Ramachandran107d3782017-03-06 17:07:44 -08003017 uint8_t i = 0;
3018 uint8_t j = 0;
3019 struct policy_mgr_psoc_priv_obj *pm_ctx;
3020
3021 pm_ctx = policy_mgr_get_context(psoc);
3022 if (!pm_ctx) {
3023 policy_mgr_err("Invalid context");
3024 return false;
3025 }
3026
3027 for (i = 0; i < QDF_MAX_NO_OF_MODE; i++)
3028 j += pm_ctx->no_of_open_sessions[i];
3029
3030 return j > 1;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003031}
3032
Archana Ramachandran107d3782017-03-06 17:07:44 -08003033/**
3034 * policy_mgr_concurrent_beaconing_sessions_running() - Checks
3035 * for concurrent beaconing entities
3036 * @psoc: PSOC object information
3037 *
3038 * Checks if multiple beaconing sessions are running i.e., if SAP or GO or IBSS
3039 * are beaconing together
3040 *
3041 * Return: True if multiple entities are beaconing together, False otherwise
3042 */
3043bool policy_mgr_concurrent_beaconing_sessions_running(
3044 struct wlan_objmgr_psoc *psoc)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003045{
hqueb320632018-01-17 17:25:25 +08003046 struct policy_mgr_psoc_priv_obj *pm_ctx;
3047
3048 pm_ctx = policy_mgr_get_context(psoc);
3049 if (!pm_ctx) {
3050 policy_mgr_err("Invalid context");
3051 return false;
3052 }
3053
3054 return (pm_ctx->no_of_open_sessions[QDF_SAP_MODE] +
3055 pm_ctx->no_of_open_sessions[QDF_P2P_GO_MODE] +
3056 pm_ctx->no_of_open_sessions[QDF_IBSS_MODE] > 1) ? true : false;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003057}
3058
3059
3060void policy_mgr_clear_concurrent_session_count(struct wlan_objmgr_psoc *psoc)
3061{
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003062 uint8_t i = 0;
3063 struct policy_mgr_psoc_priv_obj *pm_ctx;
3064
3065 pm_ctx = policy_mgr_get_context(psoc);
Jeff Johnsone79b53c2019-03-18 14:03:23 -07003066 if (pm_ctx) {
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003067 for (i = 0; i < QDF_MAX_NO_OF_MODE; i++)
3068 pm_ctx->no_of_active_sessions[i] = 0;
3069 }
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003070}
3071
3072bool policy_mgr_is_multiple_active_sta_sessions(struct wlan_objmgr_psoc *psoc)
3073{
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003074 return policy_mgr_mode_specific_connection_count(
3075 psoc, PM_STA_MODE, NULL) > 1;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003076}
3077
Archana Ramachandran0edce252017-03-06 14:36:29 -08003078/**
3079 * policy_mgr_is_sta_active_connection_exists() - Check if a STA
3080 * connection is active
3081 * @psoc: PSOC object information
3082 *
3083 * Checks if there is atleast one active STA connection in the driver
3084 *
3085 * Return: True if an active STA session is present, False otherwise
3086 */
3087bool policy_mgr_is_sta_active_connection_exists(
3088 struct wlan_objmgr_psoc *psoc)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003089{
Archana Ramachandran0edce252017-03-06 14:36:29 -08003090 return (!policy_mgr_mode_specific_connection_count(
Yuanyuan Liu0d506a42018-03-28 18:05:30 -07003091 psoc, PM_STA_MODE, NULL)) ? false : true;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003092}
3093
3094bool policy_mgr_is_any_nondfs_chnl_present(struct wlan_objmgr_psoc *psoc,
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003095 uint32_t *ch_freq)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003096{
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003097 bool status = false;
3098 uint32_t conn_index = 0;
3099 struct policy_mgr_psoc_priv_obj *pm_ctx;
3100
3101 pm_ctx = policy_mgr_get_context(psoc);
3102 if (!pm_ctx) {
3103 policy_mgr_err("Invalid Context");
3104 return false;
3105 }
3106 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
3107 for (conn_index = 0; conn_index < MAX_NUMBER_OF_CONC_CONNECTIONS;
3108 conn_index++) {
3109 if (pm_conc_connection_list[conn_index].in_use &&
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003110 !wlan_reg_is_dfs_for_freq(pm_ctx->pdev,
3111 pm_conc_connection_list[conn_index].freq)) {
3112 *ch_freq = pm_conc_connection_list[conn_index].freq;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003113 status = true;
3114 }
3115 }
3116 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
3117
3118 return status;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003119}
3120
bings3d18e552019-08-21 18:26:47 +08003121uint32_t policy_mgr_get_dfs_beaconing_session_id(
3122 struct wlan_objmgr_psoc *psoc)
3123{
3124 uint32_t session_id = WLAN_UMAC_VDEV_ID_MAX;
3125 struct policy_mgr_conc_connection_info *conn_info;
3126 uint32_t conn_index = 0;
3127 struct policy_mgr_psoc_priv_obj *pm_ctx;
3128
3129 pm_ctx = policy_mgr_get_context(psoc);
3130 if (!pm_ctx) {
3131 policy_mgr_err("Invalid Context");
3132 return session_id;
3133 }
3134 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
3135 for (conn_index = 0; conn_index < MAX_NUMBER_OF_CONC_CONNECTIONS;
3136 conn_index++) {
3137 conn_info = &pm_conc_connection_list[conn_index];
3138 if (conn_info->in_use &&
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003139 wlan_reg_chan_has_dfs_attribute_for_freq(
3140 pm_ctx->pdev, conn_info->freq) &&
bings3d18e552019-08-21 18:26:47 +08003141 (conn_info->mode == PM_SAP_MODE ||
3142 conn_info->mode == PM_P2P_GO_MODE)) {
3143 session_id =
3144 pm_conc_connection_list[conn_index].vdev_id;
3145 break;
3146 }
3147 }
3148 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
3149
3150 return session_id;
3151}
3152
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003153bool policy_mgr_is_any_dfs_beaconing_session_present(
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003154 struct wlan_objmgr_psoc *psoc, uint32_t *ch_freq)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003155{
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003156 struct policy_mgr_conc_connection_info *conn_info;
3157 bool status = false;
3158 uint32_t conn_index = 0;
3159 struct policy_mgr_psoc_priv_obj *pm_ctx;
3160
3161 pm_ctx = policy_mgr_get_context(psoc);
3162 if (!pm_ctx) {
3163 policy_mgr_err("Invalid Context");
3164 return false;
3165 }
3166 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
3167 for (conn_index = 0; conn_index < MAX_NUMBER_OF_CONC_CONNECTIONS;
3168 conn_index++) {
3169 conn_info = &pm_conc_connection_list[conn_index];
3170 if (conn_info->in_use &&
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003171 wlan_reg_is_dfs_for_freq(pm_ctx->pdev, conn_info->freq) &&
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003172 (PM_SAP_MODE == conn_info->mode ||
3173 PM_P2P_GO_MODE == conn_info->mode)) {
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003174 *ch_freq = pm_conc_connection_list[conn_index].freq;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003175 status = true;
3176 }
3177 }
3178 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
3179
3180 return status;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003181}
3182
Liangwei Dongbb0b7f52019-05-08 23:41:16 -04003183bool policy_mgr_scan_trim_5g_chnls_for_dfs_ap(struct wlan_objmgr_psoc *psoc)
3184{
3185 struct policy_mgr_psoc_priv_obj *pm_ctx;
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003186 uint32_t ap_dfs_ch_freq = 0;
Liangwei Dongbb0b7f52019-05-08 23:41:16 -04003187
3188 pm_ctx = policy_mgr_get_context(psoc);
3189 if (!pm_ctx) {
3190 policy_mgr_err("Invalid Context");
3191 return false;
3192 }
3193
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003194 policy_mgr_is_any_dfs_beaconing_session_present(psoc, &ap_dfs_ch_freq);
3195 if (!ap_dfs_ch_freq)
Liangwei Dongbb0b7f52019-05-08 23:41:16 -04003196 return false;
3197 /*
3198 * 1) if agile & DFS scans are supportet
3199 * 2) if hardware is DBS capable
3200 * 3) if current hw mode is non-dbs
3201 * if all above 3 conditions are true then don't skip any
3202 * channel from scan list
3203 */
3204 if (policy_mgr_is_hw_dbs_capable(psoc) &&
3205 !policy_mgr_is_current_hwmode_dbs(psoc) &&
3206 policy_mgr_get_dbs_plus_agile_scan_config(psoc) &&
3207 policy_mgr_get_single_mac_scan_with_dfs_config(psoc))
3208 return false;
3209
Abhishek Singheb63fb92020-03-03 10:41:37 +05303210 policy_mgr_debug("scan skip 5g chan due to dfs ap(ch %d) present",
3211 ap_dfs_ch_freq);
Liangwei Dongbb0b7f52019-05-08 23:41:16 -04003212
3213 return true;
3214}
3215
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003216QDF_STATUS policy_mgr_get_nss_for_vdev(struct wlan_objmgr_psoc *psoc,
3217 enum policy_mgr_con_mode mode,
3218 uint8_t *nss_2g, uint8_t *nss_5g)
3219{
Jeff Johnson275208b2017-11-09 09:54:12 -08003220 enum QDF_OPMODE dev_mode;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003221 struct policy_mgr_psoc_priv_obj *pm_ctx;
3222
Bala Venkatesh28477d32018-05-07 21:35:55 +05303223 dev_mode = policy_mgr_get_qdf_mode_from_pm(mode);
3224 if (dev_mode == QDF_MAX_NO_OF_MODE)
3225 return QDF_STATUS_E_FAILURE;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003226 pm_ctx = policy_mgr_get_context(psoc);
3227 if (!pm_ctx) {
3228 policy_mgr_err("Invalid Context");
3229 return QDF_STATUS_E_FAILURE;
3230 }
3231
Archana Ramachandran658a48d2017-03-23 23:30:23 -07003232 if (pm_ctx->sme_cbacks.sme_get_nss_for_vdev) {
3233 pm_ctx->sme_cbacks.sme_get_nss_for_vdev(
3234 dev_mode, nss_2g, nss_5g);
3235
3236 } else {
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003237 policy_mgr_err("sme_get_nss_for_vdev callback is NULL");
3238 return QDF_STATUS_E_FAILURE;
3239 }
3240
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003241 return QDF_STATUS_SUCCESS;
3242}
3243
3244void policy_mgr_dump_connection_status_info(struct wlan_objmgr_psoc *psoc)
3245{
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003246 uint32_t i;
3247 struct policy_mgr_psoc_priv_obj *pm_ctx;
3248
3249 pm_ctx = policy_mgr_get_context(psoc);
3250 if (!pm_ctx) {
3251 policy_mgr_err("Invalid Context");
3252 return;
3253 }
3254
3255 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
3256 for (i = 0; i < MAX_NUMBER_OF_CONC_CONNECTIONS; i++) {
Kiran Kumar Lokere54140662019-11-01 18:42:09 -07003257 policy_mgr_debug("%d: use:%d vdev:%d mode:%d mac:%d freq:%d orig chainmask:%d orig nss:%d bw:%d, ch_flags %0X",
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003258 i, pm_conc_connection_list[i].in_use,
3259 pm_conc_connection_list[i].vdev_id,
3260 pm_conc_connection_list[i].mode,
3261 pm_conc_connection_list[i].mac,
3262 pm_conc_connection_list[i].freq,
3263 pm_conc_connection_list[i].chain_mask,
3264 pm_conc_connection_list[i].original_nss,
Kiran Kumar Lokere54140662019-11-01 18:42:09 -07003265 pm_conc_connection_list[i].bw,
3266 pm_conc_connection_list[i].ch_flagext);
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003267 }
3268 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003269}
3270
3271bool policy_mgr_is_any_mode_active_on_band_along_with_session(
3272 struct wlan_objmgr_psoc *psoc,
3273 uint8_t session_id,
3274 enum policy_mgr_band band)
3275{
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003276 uint32_t i;
3277 bool status = false;
3278 struct policy_mgr_psoc_priv_obj *pm_ctx;
3279
3280 pm_ctx = policy_mgr_get_context(psoc);
3281 if (!pm_ctx) {
3282 policy_mgr_err("Invalid Context");
3283 status = false;
3284 goto send_status;
3285 }
3286
3287 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
3288 for (i = 0; i < MAX_NUMBER_OF_CONC_CONNECTIONS; i++) {
3289 switch (band) {
3290 case POLICY_MGR_BAND_24:
3291 if ((pm_conc_connection_list[i].vdev_id != session_id)
3292 && (pm_conc_connection_list[i].in_use) &&
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003293 (WLAN_REG_IS_24GHZ_CH_FREQ(
3294 pm_conc_connection_list[i].freq))) {
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003295 status = true;
3296 goto release_mutex_and_send_status;
3297 }
3298 break;
3299 case POLICY_MGR_BAND_5:
3300 if ((pm_conc_connection_list[i].vdev_id != session_id)
3301 && (pm_conc_connection_list[i].in_use) &&
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003302 (WLAN_REG_IS_5GHZ_CH_FREQ(
3303 pm_conc_connection_list[i].freq))) {
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003304 status = true;
3305 goto release_mutex_and_send_status;
3306 }
3307 break;
3308 default:
3309 policy_mgr_err("Invalidband option:%d", band);
3310 status = false;
3311 goto release_mutex_and_send_status;
3312 }
3313 }
3314release_mutex_and_send_status:
3315 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
3316send_status:
3317 return status;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003318}
3319
Manikandan Mohana0bbb512019-08-15 11:39:26 -07003320QDF_STATUS policy_mgr_get_chan_by_session_id(struct wlan_objmgr_psoc *psoc,
3321 uint8_t session_id,
3322 uint32_t *ch_freq)
Nitesh Shah3ab43842017-04-26 20:02:34 +05303323{
3324 uint32_t i;
3325 struct policy_mgr_psoc_priv_obj *pm_ctx;
3326
3327 pm_ctx = policy_mgr_get_context(psoc);
3328 if (!pm_ctx) {
3329 policy_mgr_err("Invalid Context");
3330 return QDF_STATUS_E_FAILURE;
3331 }
3332
3333 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
3334 for (i = 0; i < MAX_NUMBER_OF_CONC_CONNECTIONS; i++) {
3335 if ((pm_conc_connection_list[i].vdev_id == session_id) &&
3336 (pm_conc_connection_list[i].in_use)) {
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003337 *ch_freq = pm_conc_connection_list[i].freq;
Nitesh Shah3ab43842017-04-26 20:02:34 +05303338 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
3339 return QDF_STATUS_SUCCESS;
3340 }
3341 }
3342 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
3343
3344 return QDF_STATUS_E_FAILURE;
3345}
3346
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003347QDF_STATUS policy_mgr_get_mac_id_by_session_id(struct wlan_objmgr_psoc *psoc,
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003348 uint8_t session_id,
3349 uint8_t *mac_id)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003350{
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003351 uint32_t i;
3352 struct policy_mgr_psoc_priv_obj *pm_ctx;
3353
3354 pm_ctx = policy_mgr_get_context(psoc);
3355 if (!pm_ctx) {
3356 policy_mgr_err("Invalid Context");
3357 return QDF_STATUS_E_FAILURE;
3358 }
3359
3360 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
3361 for (i = 0; i < MAX_NUMBER_OF_CONC_CONNECTIONS; i++) {
3362 if ((pm_conc_connection_list[i].vdev_id == session_id) &&
3363 (pm_conc_connection_list[i].in_use)) {
3364 *mac_id = pm_conc_connection_list[i].mac;
3365 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
3366 return QDF_STATUS_SUCCESS;
3367 }
3368 }
3369 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
3370
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003371 return QDF_STATUS_E_FAILURE;
3372}
3373
3374QDF_STATUS policy_mgr_get_mcc_session_id_on_mac(struct wlan_objmgr_psoc *psoc,
3375 uint8_t mac_id, uint8_t session_id,
3376 uint8_t *mcc_session_id)
3377{
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003378 uint32_t i, ch_freq;
Nitesh Shah3ab43842017-04-26 20:02:34 +05303379 QDF_STATUS status;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003380 struct policy_mgr_psoc_priv_obj *pm_ctx;
3381
3382 pm_ctx = policy_mgr_get_context(psoc);
3383 if (!pm_ctx) {
3384 policy_mgr_err("Invalid Context");
3385 return QDF_STATUS_E_FAILURE;
3386 }
3387
Manikandan Mohana0bbb512019-08-15 11:39:26 -07003388 status = policy_mgr_get_chan_by_session_id(psoc, session_id, &ch_freq);
Nitesh Shah3ab43842017-04-26 20:02:34 +05303389 if (QDF_IS_STATUS_ERROR(status)) {
3390 policy_mgr_err("Failed to get channel for session id:%d",
3391 session_id);
3392 return QDF_STATUS_E_FAILURE;
3393 }
3394
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003395 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
3396 for (i = 0; i < MAX_NUMBER_OF_CONC_CONNECTIONS; i++) {
3397 if (pm_conc_connection_list[i].mac != mac_id)
3398 continue;
3399 if (pm_conc_connection_list[i].vdev_id == session_id)
3400 continue;
3401 /* Inter band or intra band MCC */
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003402 if (pm_conc_connection_list[i].freq != ch_freq &&
3403 pm_conc_connection_list[i].in_use) {
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003404 *mcc_session_id = pm_conc_connection_list[i].vdev_id;
3405 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
3406 return QDF_STATUS_SUCCESS;
3407 }
3408 }
3409 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
3410
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003411 return QDF_STATUS_E_FAILURE;
3412}
3413
Manikandan Mohana0bbb512019-08-15 11:39:26 -07003414uint32_t policy_mgr_get_mcc_operating_channel(struct wlan_objmgr_psoc *psoc,
3415 uint8_t session_id)
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003416{
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003417 uint8_t mac_id, mcc_session_id;
3418 QDF_STATUS status;
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003419 uint32_t ch_freq;
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003420 struct policy_mgr_psoc_priv_obj *pm_ctx;
3421
3422 pm_ctx = policy_mgr_get_context(psoc);
3423 if (!pm_ctx) {
3424 policy_mgr_err("Invalid Context");
3425 return INVALID_CHANNEL_ID;
3426 }
3427
3428 status = policy_mgr_get_mac_id_by_session_id(psoc, session_id, &mac_id);
3429 if (QDF_IS_STATUS_ERROR(status)) {
3430 policy_mgr_err("failed to get MAC ID");
3431 return INVALID_CHANNEL_ID;
3432 }
3433
3434 status = policy_mgr_get_mcc_session_id_on_mac(psoc, mac_id, session_id,
3435 &mcc_session_id);
3436 if (QDF_IS_STATUS_ERROR(status)) {
3437 policy_mgr_err("failed to get MCC session ID");
3438 return INVALID_CHANNEL_ID;
3439 }
3440
Manikandan Mohana0bbb512019-08-15 11:39:26 -07003441 status = policy_mgr_get_chan_by_session_id(psoc, mcc_session_id,
3442 &ch_freq);
Nitesh Shah3ab43842017-04-26 20:02:34 +05303443 if (QDF_IS_STATUS_ERROR(status)) {
3444 policy_mgr_err("Failed to get channel for MCC session ID:%d",
3445 mcc_session_id);
3446 return INVALID_CHANNEL_ID;
3447 }
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003448
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003449 return ch_freq;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003450}
3451
3452void policy_mgr_set_do_hw_mode_change_flag(struct wlan_objmgr_psoc *psoc,
3453 bool flag)
3454{
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003455 struct policy_mgr_psoc_priv_obj *pm_ctx;
3456
3457 pm_ctx = policy_mgr_get_context(psoc);
3458 if (!pm_ctx) {
3459 policy_mgr_err("Invalid Context");
3460 return;
3461 }
3462
3463 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
3464 pm_ctx->do_hw_mode_change = flag;
3465 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
3466
3467 policy_mgr_debug("hw_mode_change_channel:%d", flag);
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003468}
3469
3470bool policy_mgr_is_hw_mode_change_after_vdev_up(struct wlan_objmgr_psoc *psoc)
3471{
Tushnim Bhattacharyya482d82b2017-03-08 10:26:14 -08003472 bool flag;
3473 struct policy_mgr_psoc_priv_obj *pm_ctx;
3474
3475 pm_ctx = policy_mgr_get_context(psoc);
3476 if (!pm_ctx) {
3477 policy_mgr_err("Invalid Context");
3478 return INVALID_CHANNEL_ID;
3479 }
3480
3481 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
3482 flag = pm_ctx->do_hw_mode_change;
3483 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
3484
3485 return flag;
Tushnim Bhattacharyya6a8f07f2017-02-15 16:59:48 -08003486}
Ajit Pal Singhc65575e2017-04-17 16:49:01 +05303487
Ajit Pal Singhc0af3e82017-05-24 11:58:09 +05303488bool policy_mgr_is_dnsc_set(struct wlan_objmgr_vdev *vdev)
Ajit Pal Singhc65575e2017-04-17 16:49:01 +05303489{
Ajit Pal Singhc0af3e82017-05-24 11:58:09 +05303490 bool roffchan;
3491
3492 if (!vdev) {
3493 policy_mgr_err("Invalid parameter");
3494 return false;
3495 }
3496
Ajit Pal Singhc0af3e82017-05-24 11:58:09 +05303497 roffchan = wlan_vdev_mlme_cap_get(vdev, WLAN_VDEV_C_RESTRICT_OFFCHAN);
Ajit Pal Singhc0af3e82017-05-24 11:58:09 +05303498
Amruta Kulkarni447a3262020-02-05 14:57:04 -08003499 if (roffchan)
3500 policy_mgr_debug("Restrict offchannel is set");
Ajit Pal Singhc0af3e82017-05-24 11:58:09 +05303501
3502 return roffchan;
Ajit Pal Singhc65575e2017-04-17 16:49:01 +05303503}
3504
Manikandan Mohana0bbb512019-08-15 11:39:26 -07003505QDF_STATUS policy_mgr_is_chan_ok_for_dnbs(struct wlan_objmgr_psoc *psoc,
3506 uint32_t ch_freq, bool *ok)
Ajit Pal Singhc65575e2017-04-17 16:49:01 +05303507{
Rachit Kankanea07e4b92017-09-15 19:38:49 +05303508 uint32_t cc_count = 0, i;
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003509 uint32_t op_ch_freq_list[MAX_NUMBER_OF_CONC_CONNECTIONS];
Rachit Kankanea07e4b92017-09-15 19:38:49 +05303510 uint8_t vdev_id[MAX_NUMBER_OF_CONC_CONNECTIONS];
Ajit Pal Singhc65575e2017-04-17 16:49:01 +05303511 struct wlan_objmgr_vdev *vdev;
3512
Wu Gao76b5ff52019-06-21 17:57:05 +08003513 if (!ok) {
Ajit Pal Singhc65575e2017-04-17 16:49:01 +05303514 policy_mgr_err("Invalid parameter");
3515 return QDF_STATUS_E_INVAL;
3516 }
3517
Manikandan Mohan19f36092019-08-15 15:54:02 -07003518 cc_count = policy_mgr_get_mode_specific_conn_info(
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003519 psoc, &op_ch_freq_list[cc_count],
3520 &vdev_id[cc_count], PM_SAP_MODE);
Li Fengdcf4f922019-08-07 18:28:07 +08003521
3522 if (cc_count < MAX_NUMBER_OF_CONC_CONNECTIONS)
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003523 cc_count = cc_count +
Manikandan Mohan19f36092019-08-15 15:54:02 -07003524 policy_mgr_get_mode_specific_conn_info(
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003525 psoc, &op_ch_freq_list[cc_count],
3526 &vdev_id[cc_count], PM_P2P_GO_MODE);
Amruta Kulkarni447a3262020-02-05 14:57:04 -08003527
Rachit Kankanea07e4b92017-09-15 19:38:49 +05303528 if (!cc_count) {
Ajit Pal Singhc65575e2017-04-17 16:49:01 +05303529 *ok = true;
3530 return QDF_STATUS_SUCCESS;
3531 }
3532
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003533 if (!ch_freq) {
Wu Gao76b5ff52019-06-21 17:57:05 +08003534 policy_mgr_err("channel is 0, cc count %d", cc_count);
3535 return QDF_STATUS_E_INVAL;
3536 }
3537
Li Fengdcf4f922019-08-07 18:28:07 +08003538 if (cc_count <= MAX_NUMBER_OF_CONC_CONNECTIONS) {
3539 for (i = 0; i < cc_count; i++) {
3540 vdev = wlan_objmgr_get_vdev_by_id_from_psoc(
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003541 psoc, vdev_id[i], WLAN_POLICY_MGR_ID);
Li Fengdcf4f922019-08-07 18:28:07 +08003542 if (!vdev) {
3543 policy_mgr_err("vdev for vdev_id:%d is NULL",
3544 vdev_id[i]);
3545 return QDF_STATUS_E_INVAL;
Rachit Kankanea07e4b92017-09-15 19:38:49 +05303546 }
Li Fengdcf4f922019-08-07 18:28:07 +08003547
3548 /**
3549 * If channel passed is same as AP/GO operating
3550 * channel, return true.
3551 *
3552 * If channel is different from operating channel but
3553 * in same band, return false.
3554 *
3555 * If operating channel in different band
3556 * (DBS capable), return true.
3557 *
3558 * If operating channel in different band
3559 * (not DBS capable), return false.
3560 */
3561 /* TODO: To be enhanced for SBS */
3562 if (policy_mgr_is_dnsc_set(vdev)) {
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003563 if (op_ch_freq_list[i] == ch_freq) {
Li Fengdcf4f922019-08-07 18:28:07 +08003564 *ok = true;
3565 wlan_objmgr_vdev_release_ref(
3566 vdev,
3567 WLAN_POLICY_MGR_ID);
3568 break;
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003569 } else if (WLAN_REG_IS_SAME_BAND_FREQS(
3570 op_ch_freq_list[i], ch_freq)) {
Li Fengdcf4f922019-08-07 18:28:07 +08003571 *ok = false;
3572 wlan_objmgr_vdev_release_ref(
3573 vdev,
3574 WLAN_POLICY_MGR_ID);
3575 break;
3576 } else if (policy_mgr_is_hw_dbs_capable(psoc)) {
3577 *ok = true;
3578 wlan_objmgr_vdev_release_ref(
3579 vdev,
3580 WLAN_POLICY_MGR_ID);
3581 break;
3582 } else {
3583 *ok = false;
3584 wlan_objmgr_vdev_release_ref(
3585 vdev,
3586 WLAN_POLICY_MGR_ID);
3587 break;
3588 }
3589 } else {
3590 *ok = true;
3591 }
3592 wlan_objmgr_vdev_release_ref(vdev, WLAN_POLICY_MGR_ID);
Rachit Kankanea07e4b92017-09-15 19:38:49 +05303593 }
Ajit Pal Singhc65575e2017-04-17 16:49:01 +05303594 }
Liangwei Dong76659b02017-12-28 00:34:42 -05003595
Ajit Pal Singhc65575e2017-04-17 16:49:01 +05303596 return QDF_STATUS_SUCCESS;
3597}
Vikrampal31eb12c2017-04-28 17:44:30 +05303598
Vikrampal7e4d4c22017-05-17 09:36:46 +05303599uint32_t policy_mgr_get_hw_dbs_nss(struct wlan_objmgr_psoc *psoc,
3600 struct dbs_nss *nss_dbs)
Vikrampal31eb12c2017-04-28 17:44:30 +05303601{
3602 int i, param;
Liangwei Dong897b4392019-11-05 19:16:02 +08003603 uint32_t dbs, sbs, tx_chain0, rx_chain0, tx_chain1, rx_chain1;
Vikrampal31eb12c2017-04-28 17:44:30 +05303604 uint32_t min_mac0_rf_chains, min_mac1_rf_chains;
Vikrampal7e4d4c22017-05-17 09:36:46 +05303605 uint32_t max_rf_chains, final_max_rf_chains = HW_MODE_SS_0x0;
Vikrampal31eb12c2017-04-28 17:44:30 +05303606 struct policy_mgr_psoc_priv_obj *pm_ctx;
3607
3608 pm_ctx = policy_mgr_get_context(psoc);
Varun Reddy Yeturue23b6bc2018-01-08 13:18:41 -08003609 if (!pm_ctx) {
Vikrampal31eb12c2017-04-28 17:44:30 +05303610 policy_mgr_err("Invalid Context");
Varun Reddy Yeturue23b6bc2018-01-08 13:18:41 -08003611 return final_max_rf_chains;
3612 }
Vikrampal31eb12c2017-04-28 17:44:30 +05303613
Liangwei Dong897b4392019-11-05 19:16:02 +08003614 nss_dbs->single_mac0_band_cap = 0;
Vikrampal31eb12c2017-04-28 17:44:30 +05303615 for (i = 0; i < pm_ctx->num_dbs_hw_modes; i++) {
3616 param = pm_ctx->hw_mode.hw_mode_list[i];
3617 dbs = POLICY_MGR_HW_MODE_DBS_MODE_GET(param);
Liangwei Dong897b4392019-11-05 19:16:02 +08003618 sbs = POLICY_MGR_HW_MODE_SBS_MODE_GET(param);
3619
3620 if (!dbs && !sbs && !nss_dbs->single_mac0_band_cap)
3621 nss_dbs->single_mac0_band_cap =
3622 POLICY_MGR_HW_MODE_MAC0_BAND_GET(param);
Vikrampal31eb12c2017-04-28 17:44:30 +05303623
3624 if (dbs) {
3625 tx_chain0
3626 = POLICY_MGR_HW_MODE_MAC0_TX_STREAMS_GET(param);
3627 rx_chain0
3628 = POLICY_MGR_HW_MODE_MAC0_RX_STREAMS_GET(param);
3629
3630 tx_chain1
3631 = POLICY_MGR_HW_MODE_MAC1_TX_STREAMS_GET(param);
3632 rx_chain1
3633 = POLICY_MGR_HW_MODE_MAC1_RX_STREAMS_GET(param);
3634
3635 min_mac0_rf_chains = QDF_MIN(tx_chain0, rx_chain0);
3636 min_mac1_rf_chains = QDF_MIN(tx_chain1, rx_chain1);
3637
Vikrampal7e4d4c22017-05-17 09:36:46 +05303638 max_rf_chains
3639 = QDF_MAX(min_mac0_rf_chains, min_mac1_rf_chains);
Vikrampal31eb12c2017-04-28 17:44:30 +05303640
Vikrampal7e4d4c22017-05-17 09:36:46 +05303641 if (final_max_rf_chains < max_rf_chains) {
3642 final_max_rf_chains
3643 = (max_rf_chains == 2)
3644 ? HW_MODE_SS_2x2 : HW_MODE_SS_1x1;
Vikrampal31eb12c2017-04-28 17:44:30 +05303645
Vikrampal7e4d4c22017-05-17 09:36:46 +05303646 nss_dbs->mac0_ss
3647 = (min_mac0_rf_chains == 2)
3648 ? HW_MODE_SS_2x2 : HW_MODE_SS_1x1;
3649
3650 nss_dbs->mac1_ss
3651 = (min_mac1_rf_chains == 2)
3652 ? HW_MODE_SS_2x2 : HW_MODE_SS_1x1;
3653 }
Vikrampal31eb12c2017-04-28 17:44:30 +05303654 } else {
3655 continue;
3656 }
3657 }
3658
Vikrampal7e4d4c22017-05-17 09:36:46 +05303659 return final_max_rf_chains;
Vikrampal31eb12c2017-04-28 17:44:30 +05303660}
Tushnim Bhattacharyyaecc6e102017-05-26 18:25:56 -07003661
3662bool policy_mgr_is_scan_simultaneous_capable(struct wlan_objmgr_psoc *psoc)
3663{
Bala Venkatesh9391de32019-01-25 12:57:20 +05303664 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
3665
3666 policy_mgr_get_dual_mac_feature(psoc, &dual_mac_feature);
3667 if ((dual_mac_feature == DISABLE_DBS_CXN_AND_SCAN) ||
3668 (dual_mac_feature == ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN) ||
3669 (dual_mac_feature ==
3670 ENABLE_DBS_CXN_AND_DISABLE_SIMULTANEOUS_SCAN) ||
Yeshwanth Sriram Guntuka2a4e0822018-10-29 19:45:57 +05303671 !policy_mgr_is_hw_dbs_capable(psoc))
Bala Venkatesh119ed6b2018-03-17 18:48:31 +05303672 return false;
Tushnim Bhattacharyyaecc6e102017-05-26 18:25:56 -07003673
Bala Venkatesh119ed6b2018-03-17 18:48:31 +05303674 return true;
Tushnim Bhattacharyyaecc6e102017-05-26 18:25:56 -07003675}
3676
Ganesh Kondabattini2a8c7b02017-07-10 17:34:36 +05303677void policy_mgr_set_cur_conc_system_pref(struct wlan_objmgr_psoc *psoc,
3678 uint8_t conc_system_pref)
3679{
3680 struct policy_mgr_psoc_priv_obj *pm_ctx;
3681
3682 pm_ctx = policy_mgr_get_context(psoc);
3683
3684 if (!pm_ctx) {
3685 policy_mgr_err("Invalid Context");
3686 return;
3687 }
3688
3689 policy_mgr_debug("conc_system_pref %hu", conc_system_pref);
3690 pm_ctx->cur_conc_system_pref = conc_system_pref;
3691}
3692
3693uint8_t policy_mgr_get_cur_conc_system_pref(struct wlan_objmgr_psoc *psoc)
3694{
3695 struct policy_mgr_psoc_priv_obj *pm_ctx;
3696
3697 pm_ctx = policy_mgr_get_context(psoc);
3698 if (!pm_ctx) {
3699 policy_mgr_err("Invalid Context");
3700 return PM_THROUGHPUT;
3701 }
3702
3703 policy_mgr_debug("conc_system_pref %hu", pm_ctx->cur_conc_system_pref);
3704 return pm_ctx->cur_conc_system_pref;
3705}
3706
Tushnim Bhattacharyyaecc6e102017-05-26 18:25:56 -07003707QDF_STATUS policy_mgr_get_updated_scan_and_fw_mode_config(
3708 struct wlan_objmgr_psoc *psoc, uint32_t *scan_config,
Yeshwanth Sriram Guntuka257a5d72018-02-12 12:24:06 +05303709 uint32_t *fw_mode_config, uint32_t dual_mac_disable_ini,
3710 uint32_t channel_select_logic_conc)
Tushnim Bhattacharyyaecc6e102017-05-26 18:25:56 -07003711{
3712 struct policy_mgr_psoc_priv_obj *pm_ctx;
3713
3714 pm_ctx = policy_mgr_get_context(psoc);
3715 if (!pm_ctx) {
3716 policy_mgr_err("Invalid Context");
3717 return QDF_STATUS_E_FAILURE;
3718 }
3719
3720 *scan_config = pm_ctx->dual_mac_cfg.cur_scan_config;
3721 *fw_mode_config = pm_ctx->dual_mac_cfg.cur_fw_mode_config;
3722 switch (dual_mac_disable_ini) {
3723 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
3724 policy_mgr_debug("dual_mac_disable_ini:%d async/dbs off",
3725 dual_mac_disable_ini);
3726 WMI_DBS_CONC_SCAN_CFG_ASYNC_DBS_SCAN_SET(*scan_config, 0);
3727 WMI_DBS_FW_MODE_CFG_DBS_FOR_CXN_SET(*fw_mode_config, 0);
3728 break;
3729 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
3730 policy_mgr_debug("dual_mac_disable_ini:%d dbs_cxn off",
3731 dual_mac_disable_ini);
3732 WMI_DBS_FW_MODE_CFG_DBS_FOR_CXN_SET(*fw_mode_config, 0);
3733 break;
3734 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
3735 policy_mgr_debug("dual_mac_disable_ini:%d async off",
3736 dual_mac_disable_ini);
3737 WMI_DBS_CONC_SCAN_CFG_ASYNC_DBS_SCAN_SET(*scan_config, 0);
3738 break;
Bala Venkatesh119ed6b2018-03-17 18:48:31 +05303739 case ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN:
3740 policy_mgr_debug("%s: dual_mac_disable_ini:%d ", __func__,
3741 dual_mac_disable_ini);
3742 WMI_DBS_CONC_SCAN_CFG_DBS_SCAN_SET(*scan_config, 0);
3743 break;
Tushnim Bhattacharyyaecc6e102017-05-26 18:25:56 -07003744 default:
3745 break;
3746 }
Yeshwanth Sriram Guntuka257a5d72018-02-12 12:24:06 +05303747
3748 WMI_DBS_FW_MODE_CFG_DBS_FOR_STA_PLUS_STA_SET(*fw_mode_config,
3749 PM_CHANNEL_SELECT_LOGIC_STA_STA_GET(channel_select_logic_conc));
3750 WMI_DBS_FW_MODE_CFG_DBS_FOR_STA_PLUS_P2P_SET(*fw_mode_config,
3751 PM_CHANNEL_SELECT_LOGIC_STA_P2P_GET(channel_select_logic_conc));
3752
Tushnim Bhattacharyyaecc6e102017-05-26 18:25:56 -07003753 policy_mgr_debug("*scan_config:%x ", *scan_config);
3754 policy_mgr_debug("*fw_mode_config:%x ", *fw_mode_config);
3755
3756 return QDF_STATUS_SUCCESS;
3757}
Tushnim Bhattacharyyaa2c3b622017-08-03 16:58:38 -07003758
3759bool policy_mgr_is_force_scc(struct wlan_objmgr_psoc *psoc)
3760{
3761 struct policy_mgr_psoc_priv_obj *pm_ctx;
3762
3763 pm_ctx = policy_mgr_get_context(psoc);
3764 if (!pm_ctx) {
3765 policy_mgr_err("Invalid Context");
3766 return 0;
3767 }
3768
Krunal Sonid36b2072018-09-26 17:02:14 -07003769 return ((pm_ctx->cfg.mcc_to_scc_switch ==
Tushnim Bhattacharyyaa2c3b622017-08-03 16:58:38 -07003770 QDF_MCC_TO_SCC_SWITCH_FORCE_WITHOUT_DISCONNECTION) ||
Krunal Sonid36b2072018-09-26 17:02:14 -07003771 (pm_ctx->cfg.mcc_to_scc_switch ==
Rachit Kankane758528a2017-09-15 16:36:33 +05303772 QDF_MCC_TO_SCC_SWITCH_WITH_FAVORITE_CHANNEL) ||
Krunal Sonid36b2072018-09-26 17:02:14 -07003773 (pm_ctx->cfg.mcc_to_scc_switch ==
Bala Venkatesh68bdbfa2018-06-14 12:28:10 +05303774 QDF_MCC_TO_SCC_SWITCH_FORCE_PREFERRED_WITHOUT_DISCONNECTION) ||
Krunal Sonid36b2072018-09-26 17:02:14 -07003775 (pm_ctx->cfg.mcc_to_scc_switch ==
Bala Venkatesh68bdbfa2018-06-14 12:28:10 +05303776 QDF_MCC_TO_SCC_WITH_PREFERRED_BAND));
Tushnim Bhattacharyyaa2c3b622017-08-03 16:58:38 -07003777}
Ganesh Kondabattini8a611c62017-11-21 15:01:31 +05303778
3779bool policy_mgr_is_sta_sap_scc_allowed_on_dfs_chan(
3780 struct wlan_objmgr_psoc *psoc)
3781{
3782 struct policy_mgr_psoc_priv_obj *pm_ctx;
Krunal Soni1680e412018-12-07 19:42:06 +08003783 uint8_t sta_sap_scc_on_dfs_chnl = 0;
Ganesh Kondabattini8a611c62017-11-21 15:01:31 +05303784 bool status = false;
3785
3786 pm_ctx = policy_mgr_get_context(psoc);
3787 if (!pm_ctx) {
3788 policy_mgr_err("Invalid Context");
3789 return status;
3790 }
3791
Krunal Soni1680e412018-12-07 19:42:06 +08003792 policy_mgr_get_sta_sap_scc_on_dfs_chnl(psoc,
3793 &sta_sap_scc_on_dfs_chnl);
3794 if (policy_mgr_is_force_scc(psoc) && sta_sap_scc_on_dfs_chnl)
Ganesh Kondabattini8a611c62017-11-21 15:01:31 +05303795 status = true;
3796
3797 return status;
3798}
Yeshwanth Sriram Guntuka067cd3e2017-12-14 17:56:04 +05303799
3800bool policy_mgr_is_sta_connected_2g(struct wlan_objmgr_psoc *psoc)
3801{
3802 struct policy_mgr_psoc_priv_obj *pm_ctx;
3803 uint32_t conn_index;
3804 bool ret = false;
3805
3806 pm_ctx = policy_mgr_get_context(psoc);
3807 if (!pm_ctx) {
3808 policy_mgr_err("Invalid Context");
3809 return ret;
3810 }
3811 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
3812 for (conn_index = 0; conn_index < MAX_NUMBER_OF_CONC_CONNECTIONS;
3813 conn_index++) {
3814 if (pm_conc_connection_list[conn_index].mode == PM_STA_MODE &&
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003815 pm_conc_connection_list[conn_index].freq <=
3816 WLAN_REG_MAX_24GHZ_CHAN_FREQ &&
Yeshwanth Sriram Guntuka067cd3e2017-12-14 17:56:04 +05303817 pm_conc_connection_list[conn_index].in_use)
3818 ret = true;
3819 }
3820 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
3821
3822 return ret;
3823}
Tushnim Bhattacharyyac7b97692018-02-21 13:37:00 -08003824
Yeshwanth Sriram Guntuka6a3be162018-02-23 12:14:46 +05303825uint32_t policy_mgr_get_connection_info(struct wlan_objmgr_psoc *psoc,
3826 struct connection_info *info)
3827{
3828 struct policy_mgr_psoc_priv_obj *pm_ctx;
3829 uint32_t conn_index, count = 0;
3830
3831 pm_ctx = policy_mgr_get_context(psoc);
3832 if (!pm_ctx) {
3833 policy_mgr_err("Invalid Context");
3834 return count;
3835 }
Liangwei Dong05276172019-12-27 10:31:46 +08003836 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
Yeshwanth Sriram Guntuka6a3be162018-02-23 12:14:46 +05303837 for (conn_index = 0; conn_index < MAX_NUMBER_OF_CONC_CONNECTIONS;
3838 conn_index++) {
3839 if (PM_CONC_CONNECTION_LIST_VALID_INDEX(conn_index)) {
3840 info[count].vdev_id =
3841 pm_conc_connection_list[conn_index].vdev_id;
3842 info[count].mac_id =
3843 pm_conc_connection_list[conn_index].mac;
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003844 info[count].channel = wlan_reg_freq_to_chan(
3845 pm_ctx->pdev,
3846 pm_conc_connection_list[conn_index].freq);
Liangwei Dong05276172019-12-27 10:31:46 +08003847 info[count].ch_freq =
3848 pm_conc_connection_list[conn_index].freq;
Yeshwanth Sriram Guntuka6a3be162018-02-23 12:14:46 +05303849 count++;
3850 }
3851 }
Liangwei Dong05276172019-12-27 10:31:46 +08003852 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
Yeshwanth Sriram Guntuka6a3be162018-02-23 12:14:46 +05303853
3854 return count;
3855}
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003856
3857bool policy_mgr_allow_sap_go_concurrency(struct wlan_objmgr_psoc *psoc,
3858 enum policy_mgr_con_mode mode,
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003859 uint32_t ch_freq,
Jianmin Zhue1ebfd02018-08-21 19:20:28 +08003860 uint32_t vdev_id)
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003861{
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003862 enum policy_mgr_con_mode con_mode;
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003863 int id;
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003864 uint32_t vdev, con_freq;
Jianmin Zhue1ebfd02018-08-21 19:20:28 +08003865 bool dbs;
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003866
Jianmin Zhue1ebfd02018-08-21 19:20:28 +08003867 if (mode != PM_SAP_MODE && mode != PM_P2P_GO_MODE)
3868 return true;
3869 if (policy_mgr_dual_beacon_on_single_mac_mcc_capable(psoc))
3870 return true;
3871 dbs = policy_mgr_is_hw_dbs_capable(psoc);
3872 for (id = 0; id < MAX_NUMBER_OF_CONC_CONNECTIONS; id++) {
3873 if (!pm_conc_connection_list[id].in_use)
3874 continue;
3875 vdev = pm_conc_connection_list[id].vdev_id;
3876 if (vdev_id == vdev)
3877 continue;
3878 con_mode = pm_conc_connection_list[id].mode;
3879 if (con_mode != PM_SAP_MODE && con_mode != PM_P2P_GO_MODE)
3880 continue;
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003881 con_freq = pm_conc_connection_list[id].freq;
Jianmin Zhue1ebfd02018-08-21 19:20:28 +08003882 if (policy_mgr_dual_beacon_on_single_mac_scc_capable(psoc) &&
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003883 (ch_freq == con_freq)) {
Jianmin Zhue1ebfd02018-08-21 19:20:28 +08003884 policy_mgr_debug("SCC enabled, 2 AP on same channel, allow 2nd AP");
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003885 return true;
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003886 }
Jianmin Zhue1ebfd02018-08-21 19:20:28 +08003887 if (!dbs) {
3888 policy_mgr_debug("DBS unsupported, mcc and scc unsupported too, don't allow 2nd AP");
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003889 return false;
3890 }
Manikandan Mohan932c11e2019-08-14 14:09:08 -07003891 if (WLAN_REG_IS_SAME_BAND_FREQS(ch_freq, con_freq)) {
Jianmin Zhue1ebfd02018-08-21 19:20:28 +08003892 policy_mgr_debug("DBS supported, 2 SAP on same band, reject 2nd AP");
3893 return false;
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003894 }
3895 }
3896
3897 /* Don't block the second interface */
3898 return true;
3899}
3900
3901bool policy_mgr_dual_beacon_on_single_mac_scc_capable(
3902 struct wlan_objmgr_psoc *psoc)
3903{
Tushnim Bhattacharyya5dd541e2018-08-30 10:20:31 -07003904 struct wmi_unified *wmi_handle;
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003905
Tushnim Bhattacharyya5dd541e2018-08-30 10:20:31 -07003906 wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003907 if (!wmi_handle) {
3908 policy_mgr_debug("Invalid WMI handle");
3909 return false;
3910 }
3911
3912 if (wmi_service_enabled(
3913 wmi_handle,
3914 wmi_service_dual_beacon_on_single_mac_scc_support)) {
gaurank kathpalia59d68af2018-08-02 21:23:58 +05303915 policy_mgr_debug("Dual beaconing on same channel on single MAC supported");
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003916 return true;
3917 }
gaurank kathpalia59d68af2018-08-02 21:23:58 +05303918 policy_mgr_debug("Dual beaconing on same channel on single MAC is not supported");
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003919 return false;
3920}
3921
3922bool policy_mgr_dual_beacon_on_single_mac_mcc_capable(
3923 struct wlan_objmgr_psoc *psoc)
3924{
Tushnim Bhattacharyya5dd541e2018-08-30 10:20:31 -07003925 struct wmi_unified *wmi_handle;
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003926
Tushnim Bhattacharyya5dd541e2018-08-30 10:20:31 -07003927 wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003928 if (!wmi_handle) {
3929 policy_mgr_debug("Invalid WMI handle");
3930 return false;
3931 }
3932
3933 if (wmi_service_enabled(
3934 wmi_handle,
3935 wmi_service_dual_beacon_on_single_mac_mcc_support)) {
gaurank kathpalia59d68af2018-08-02 21:23:58 +05303936 policy_mgr_debug("Dual beaconing on different channel on single MAC supported");
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003937 return true;
3938 }
gaurank kathpalia59d68af2018-08-02 21:23:58 +05303939 policy_mgr_debug("Dual beaconing on different channel on single MAC is not supported");
Zhu Jianmin7f8d1df2018-04-19 17:55:30 +08003940 return false;
3941}
Zhu Jianmin5ac66ef2018-06-11 19:03:39 +08003942
3943bool policy_mgr_sta_sap_scc_on_lte_coex_chan(
3944 struct wlan_objmgr_psoc *psoc)
3945{
3946 struct policy_mgr_psoc_priv_obj *pm_ctx;
Krunal Soni1680e412018-12-07 19:42:06 +08003947 uint8_t scc_lte_coex = 0;
Zhu Jianmin5ac66ef2018-06-11 19:03:39 +08003948
3949 pm_ctx = policy_mgr_get_context(psoc);
3950 if (!pm_ctx) {
3951 policy_mgr_err("Invalid Context");
3952 return false;
3953 }
Krunal Soni1680e412018-12-07 19:42:06 +08003954 policy_mgr_get_sta_sap_scc_lte_coex_chnl(psoc, &scc_lte_coex);
3955
3956 return scc_lte_coex;
Zhu Jianmin5ac66ef2018-06-11 19:03:39 +08003957}
Bala Venkatesh85b42f42018-06-08 12:38:35 +05303958
Liangwei Dong05276172019-12-27 10:31:46 +08003959#if defined(CONFIG_BAND_6GHZ) && defined(WLAN_FEATURE_11AX)
3960void policy_mgr_init_ap_6ghz_capable(struct wlan_objmgr_psoc *psoc,
3961 uint8_t vdev_id,
3962 enum conn_6ghz_flag ap_6ghz_capable)
3963{
3964 struct policy_mgr_conc_connection_info *conn_info;
3965 uint32_t conn_index;
3966 struct policy_mgr_psoc_priv_obj *pm_ctx;
3967 enum conn_6ghz_flag conn_6ghz_flag = 0;
3968
3969 pm_ctx = policy_mgr_get_context(psoc);
3970 if (!pm_ctx) {
3971 policy_mgr_err("Invalid Context");
3972 return;
3973 }
3974 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
3975 for (conn_index = 0; conn_index < MAX_NUMBER_OF_CONC_CONNECTIONS;
3976 conn_index++) {
3977 conn_info = &pm_conc_connection_list[conn_index];
3978 if (conn_info->in_use && PM_SAP_MODE == conn_info->mode &&
3979 vdev_id == conn_info->vdev_id) {
3980 conn_info->conn_6ghz_flag = ap_6ghz_capable;
3981 conn_info->conn_6ghz_flag |= CONN_6GHZ_FLAG_VALID;
3982 conn_6ghz_flag = conn_info->conn_6ghz_flag;
3983 break;
3984 }
3985 }
3986 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
3987 policy_mgr_debug("vdev %d init conn_6ghz_flag %x new %x",
3988 vdev_id, ap_6ghz_capable, conn_6ghz_flag);
3989}
3990
3991void policy_mgr_set_ap_6ghz_capable(struct wlan_objmgr_psoc *psoc,
3992 uint8_t vdev_id,
3993 bool set,
3994 enum conn_6ghz_flag ap_6ghz_capable)
3995{
3996 struct policy_mgr_conc_connection_info *conn_info;
3997 uint32_t conn_index;
3998 struct policy_mgr_psoc_priv_obj *pm_ctx;
3999 enum conn_6ghz_flag conn_6ghz_flag = 0;
4000
4001 pm_ctx = policy_mgr_get_context(psoc);
4002 if (!pm_ctx) {
4003 policy_mgr_err("Invalid Context");
4004 return;
4005 }
4006 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
4007 for (conn_index = 0; conn_index < MAX_NUMBER_OF_CONC_CONNECTIONS;
4008 conn_index++) {
4009 conn_info = &pm_conc_connection_list[conn_index];
4010 if (conn_info->in_use && PM_SAP_MODE == conn_info->mode &&
4011 vdev_id == conn_info->vdev_id) {
4012 if (set)
4013 conn_info->conn_6ghz_flag |= ap_6ghz_capable;
4014 else
4015 conn_info->conn_6ghz_flag &= ~ap_6ghz_capable;
4016 conn_info->conn_6ghz_flag |= CONN_6GHZ_FLAG_VALID;
4017 conn_6ghz_flag = conn_info->conn_6ghz_flag;
4018 break;
4019 }
4020 }
4021 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
4022 policy_mgr_debug("vdev %d %s conn_6ghz_flag %x new %x",
4023 vdev_id, set ? "set" : "clr",
4024 ap_6ghz_capable, conn_6ghz_flag);
4025}
4026
4027bool policy_mgr_get_ap_6ghz_capable(struct wlan_objmgr_psoc *psoc,
4028 uint8_t vdev_id,
4029 uint32_t *conn_flag)
4030{
4031 struct policy_mgr_conc_connection_info *conn_info;
4032 uint32_t conn_index;
4033 struct policy_mgr_psoc_priv_obj *pm_ctx;
4034 enum conn_6ghz_flag conn_6ghz_flag = 0;
4035 bool is_6g_allowed = false;
4036
4037 if (conn_flag)
4038 *conn_flag = 0;
4039 pm_ctx = policy_mgr_get_context(psoc);
4040 if (!pm_ctx) {
4041 policy_mgr_err("Invalid Context");
4042 return false;
4043 }
4044 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
4045 for (conn_index = 0; conn_index < MAX_NUMBER_OF_CONC_CONNECTIONS;
4046 conn_index++) {
4047 conn_info = &pm_conc_connection_list[conn_index];
4048 if (conn_info->in_use && PM_SAP_MODE == conn_info->mode &&
4049 vdev_id == conn_info->vdev_id) {
4050 conn_6ghz_flag = conn_info->conn_6ghz_flag;
4051 break;
4052 }
4053 }
4054 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
4055
4056 /* If the vdev connection is not active, policy mgr will query legacy
4057 * hdd to get sap acs and security information.
4058 * The assumption is no legacy client connected for non active
4059 * connection.
4060 */
4061 if (!(conn_6ghz_flag & CONN_6GHZ_FLAG_VALID) &&
4062 pm_ctx->hdd_cbacks.hdd_get_ap_6ghz_capable)
4063 conn_6ghz_flag = pm_ctx->hdd_cbacks.hdd_get_ap_6ghz_capable(
4064 psoc, vdev_id) |
4065 CONN_6GHZ_FLAG_NO_LEGACY_CLIENT;
4066
4067 if ((conn_6ghz_flag & CONN_6GHZ_CAPABLIE) == CONN_6GHZ_CAPABLIE)
4068 is_6g_allowed = true;
4069 policy_mgr_debug("vdev %d conn_6ghz_flag %x 6ghz %s", vdev_id,
4070 conn_6ghz_flag, is_6g_allowed ? "allowed" : "deny");
4071 if (conn_flag)
4072 *conn_flag = conn_6ghz_flag;
4073
4074 return is_6g_allowed;
4075}
4076#endif
4077
Manikandan Mohana0bbb512019-08-15 11:39:26 -07004078bool policy_mgr_is_valid_for_channel_switch(struct wlan_objmgr_psoc *psoc,
4079 uint32_t ch_freq)
Bala Venkatesh85b42f42018-06-08 12:38:35 +05304080{
4081 uint32_t sta_sap_scc_on_dfs_chan;
4082 uint32_t sap_count;
4083 enum channel_state state;
4084 struct policy_mgr_psoc_priv_obj *pm_ctx;
4085
4086 pm_ctx = policy_mgr_get_context(psoc);
4087 if (!pm_ctx) {
4088 policy_mgr_err("Invalid Context");
4089 return false;
4090 }
4091
4092 sta_sap_scc_on_dfs_chan =
4093 policy_mgr_is_sta_sap_scc_allowed_on_dfs_chan(psoc);
4094 sap_count = policy_mgr_mode_specific_connection_count(psoc,
4095 PM_SAP_MODE,
4096 NULL);
Manikandan Mohan932c11e2019-08-14 14:09:08 -07004097 state = wlan_reg_get_channel_state_for_freq(pm_ctx->pdev, ch_freq);
Bala Venkatesh85b42f42018-06-08 12:38:35 +05304098
Manikandan Mohan932c11e2019-08-14 14:09:08 -07004099 policy_mgr_debug("sta_sap_scc_on_dfs_chan %u, sap_count %u, ch freq %u, state %u",
4100 sta_sap_scc_on_dfs_chan, sap_count, ch_freq, state);
Bala Venkatesh85b42f42018-06-08 12:38:35 +05304101
4102 if ((state == CHANNEL_STATE_ENABLE) || (sap_count == 0) ||
4103 ((state == CHANNEL_STATE_DFS) && sta_sap_scc_on_dfs_chan)) {
4104 policy_mgr_debug("Valid channel for channel switch");
4105 return true;
4106 }
4107
4108 policy_mgr_debug("Invalid channel for channel switch");
4109 return false;
4110}
Tushnim Bhattacharyya9b1636d2018-06-27 13:27:11 -07004111
Manikandan Mohana0bbb512019-08-15 11:39:26 -07004112bool policy_mgr_is_sta_sap_scc(struct wlan_objmgr_psoc *psoc,
4113 uint32_t sap_freq)
Tushnim Bhattacharyya9b1636d2018-06-27 13:27:11 -07004114{
4115 uint32_t conn_index;
4116 bool is_scc = false;
4117 struct policy_mgr_psoc_priv_obj *pm_ctx;
4118
4119 pm_ctx = policy_mgr_get_context(psoc);
4120 if (!pm_ctx) {
4121 policy_mgr_err("Invalid Context");
4122 return is_scc;
4123 }
4124
4125 if (!policy_mgr_mode_specific_connection_count(
4126 psoc, PM_STA_MODE, NULL)) {
4127 policy_mgr_debug("There is no STA+SAP conc");
4128 return is_scc;
4129 }
4130
4131 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
4132 for (conn_index = 0; conn_index < MAX_NUMBER_OF_CONC_CONNECTIONS;
4133 conn_index++) {
4134 if (pm_conc_connection_list[conn_index].in_use &&
Manikandan Mohan932c11e2019-08-14 14:09:08 -07004135 (pm_conc_connection_list[conn_index].mode ==
4136 PM_STA_MODE) && (sap_freq ==
4137 pm_conc_connection_list[conn_index].freq)) {
Tushnim Bhattacharyya9b1636d2018-06-27 13:27:11 -07004138 is_scc = true;
4139 break;
4140 }
4141 }
4142 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
4143
4144 return is_scc;
4145}
Nachiket Kukadecf941602018-12-12 14:32:35 +05304146
Liangwei Dongd8ecec32019-05-09 04:47:47 -04004147bool policy_mgr_go_scc_enforced(struct wlan_objmgr_psoc *psoc)
4148{
4149 uint32_t mcc_to_scc_switch;
4150 struct policy_mgr_psoc_priv_obj *pm_ctx;
4151
4152 pm_ctx = policy_mgr_get_context(psoc);
4153 if (!pm_ctx) {
4154 policy_mgr_err("Invalid Context");
4155 return false;
4156 }
4157 mcc_to_scc_switch = policy_mgr_get_mcc_to_scc_switch_mode(psoc);
4158 if (mcc_to_scc_switch ==
4159 QDF_MCC_TO_SCC_SWITCH_FORCE_PREFERRED_WITHOUT_DISCONNECTION)
4160 return true;
4161
4162 if (pm_ctx->cfg.go_force_scc && policy_mgr_is_force_scc(psoc))
4163 return true;
4164
4165 return false;
4166}
4167
Nachiket Kukadecf941602018-12-12 14:32:35 +05304168QDF_STATUS policy_mgr_update_nan_vdev_mac_info(struct wlan_objmgr_psoc *psoc,
4169 uint8_t nan_vdev_id,
4170 uint8_t mac_id)
4171{
4172 struct policy_mgr_hw_mode_params hw_mode = {0};
4173 struct policy_mgr_vdev_mac_map vdev_mac_map = {0};
4174 QDF_STATUS status;
4175
4176 vdev_mac_map.vdev_id = nan_vdev_id;
4177 vdev_mac_map.mac_id = mac_id;
4178
4179 status = policy_mgr_get_current_hw_mode(psoc, &hw_mode);
4180
4181 if (QDF_IS_STATUS_SUCCESS(status))
4182 policy_mgr_update_hw_mode_conn_info(psoc, 1, &vdev_mac_map,
4183 hw_mode);
4184
4185 return status;
4186}
Amruta Kulkarni59f63502019-11-27 16:45:12 -08004187
4188bool policy_mgr_is_sap_go_on_2g(struct wlan_objmgr_psoc *psoc)
4189{
4190 struct policy_mgr_psoc_priv_obj *pm_ctx;
4191 uint32_t conn_index;
4192 bool ret = false;
4193
4194 pm_ctx = policy_mgr_get_context(psoc);
4195 if (!pm_ctx) {
4196 policy_mgr_err("Invalid Context");
4197 return ret;
4198 }
4199
4200 qdf_mutex_acquire(&pm_ctx->qdf_conc_list_lock);
4201 for (conn_index = 0; conn_index < MAX_NUMBER_OF_CONC_CONNECTIONS;
4202 conn_index++) {
4203 if ((pm_conc_connection_list[conn_index].mode == PM_SAP_MODE ||
4204 pm_conc_connection_list[conn_index].mode == PM_P2P_GO_MODE) &&
4205 pm_conc_connection_list[conn_index].freq <=
4206 WLAN_REG_MAX_24GHZ_CHAN_FREQ &&
4207 pm_conc_connection_list[conn_index].in_use)
4208 ret = true;
4209 }
4210 qdf_mutex_release(&pm_ctx->qdf_conc_list_lock);
4211
4212 return ret;
4213}
4214
bings00c391f2019-12-19 14:58:57 +08004215bool policy_mgr_get_5g_scc_prefer(
4216 struct wlan_objmgr_psoc *psoc, enum policy_mgr_con_mode mode)
4217{
4218 struct policy_mgr_psoc_priv_obj *pm_ctx;
4219
4220 pm_ctx = policy_mgr_get_context(psoc);
4221 if (!pm_ctx) {
4222 policy_mgr_err("Invalid Context");
4223 return false;
4224 }
4225
4226 return pm_ctx->cfg.prefer_5g_scc_to_dbs & (1 << mode);
4227}