blob: 281d2f00d85a95c054925767d3c73984329035dd [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Himanshu Agarwalfee2e362018-01-18 20:26:35 +05302 * Copyright (c) 2012-2018 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/*===========================================================================
29
Anurag Chouhan6d760662016-02-20 16:05:43 +053030 s a p C h S e l e c t . C
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080031 OVERVIEW:
32
33 This software unit holds the implementation of the WLAN SAP modules
34 functions for channel selection.
35
36 DEPENDENCIES:
37
38 Are listed for each API below.
39 ===========================================================================*/
40
41/*--------------------------------------------------------------------------
42 Include Files
43 ------------------------------------------------------------------------*/
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053044#include "qdf_trace.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080045#include "csr_api.h"
46#include "sme_api.h"
47#include "sap_ch_select.h"
48#include "sap_internal.h"
49#ifdef ANI_OS_TYPE_QNX
50#include "stdio.h"
51#endif
52#ifdef FEATURE_AP_MCC_CH_AVOIDANCE
53#include "lim_utils.h"
54#include "parser_api.h"
55#endif /* FEATURE_AP_MCC_CH_AVOIDANCE */
Deepthi Gowri48b89332016-08-30 18:43:05 +053056#include "cds_utils.h"
Yuanyuan Liu0e0aa932016-05-12 10:17:58 -070057#include "pld_common.h"
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070058#include "wlan_reg_services_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080059
60/*--------------------------------------------------------------------------
61 Function definitions
62 --------------------------------------------------------------------------*/
63
64/*--------------------------------------------------------------------------
65 Defines
66 --------------------------------------------------------------------------*/
67#define SAP_DEBUG
68
69#define IS_RSSI_VALID(extRssi, rssi) \
70 ( \
71 ((extRssi < rssi) ? true : false) \
72 )
73
Jeff Johnsone13d8062017-09-28 06:54:55 -070074#define SET_ACS_BAND(acs_band, sap_ctx) \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080075{ \
Jeff Johnsone13d8062017-09-28 06:54:55 -070076 if (sap_ctx->acs_cfg->start_ch <= 14 && \
77 sap_ctx->acs_cfg->end_ch <= 14) \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080078 acs_band = eCSR_DOT11_MODE_11g; \
Jeff Johnsone13d8062017-09-28 06:54:55 -070079 else if (sap_ctx->acs_cfg->start_ch >= 14)\
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080080 acs_band = eCSR_DOT11_MODE_11a; \
81 else \
82 acs_band = eCSR_DOT11_MODE_abg; \
83}
84
gaoleze5108942017-03-31 16:56:42 +080085#define ACS_WEIGHT_AMOUNT_LOCAL 240
86
87#define ACS_WEIGHT_AMOUNT_CONFIG(weights) \
88 (((weights) & 0xf) + \
89 (((weights) & 0xf0) >> 4) + \
90 (((weights) & 0xf00) >> 8) + \
91 (((weights) & 0xf000) >> 12) + \
92 (((weights) & 0xf0000) >> 16) + \
93 (((weights) & 0xf00000) >> 20))
94
95/*
96 * LSH/RSH 4 to enhance the accurate since
97 * need to do modulation to ACS_WEIGHT_AMOUNT_LOCAL.
98 */
99#define ACS_WEIGHT_COMPUTE(weights, weight, factor, base) \
100 (((((((((weight) << 4) * ACS_WEIGHT_AMOUNT_LOCAL * (factor)) + \
101 (ACS_WEIGHT_AMOUNT_CONFIG((weights)) >> 1)) / \
102 ACS_WEIGHT_AMOUNT_CONFIG((weights))) + \
103 ((base) >> 1)) / (base)) + 8) >> 4)
104
105#define ACS_WEIGHT_CFG_TO_LOCAL(weights, weight) \
106 (((((((weight) << 4) * ACS_WEIGHT_AMOUNT_LOCAL) + \
107 (ACS_WEIGHT_AMOUNT_CONFIG((weights)) >> 1)) / \
108 ACS_WEIGHT_AMOUNT_CONFIG((weights))) + 8) >> 4)
109
110#define ACS_WEIGHT_SOFTAP_RSSI_CFG(weights) \
111 ((weights) & 0xf)
112
113#define ACS_WEIGHT_SOFTAP_COUNT_CFG(weights) \
114 (((weights) & 0xf0) >> 4)
115
116#define ACS_WEIGHT_SOFTAP_NOISE_FLOOR_CFG(weights) \
117 (((weights) & 0xf00) >> 8)
118
119#define ACS_WEIGHT_SOFTAP_CHANNEL_FREE_CFG(weights) \
120 (((weights) & 0xf000) >> 12)
121
122#define ACS_WEIGHT_SOFTAP_TX_POWER_RANGE_CFG(weights) \
123 (((weights) & 0xf0000) >> 16)
124
125#define ACS_WEIGHT_SOFTAP_TX_POWER_THROUGHPUT_CFG(weights) \
126 (((weights) & 0xf00000) >> 20)
127
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800128#ifdef FEATURE_WLAN_CH_AVOID
Amar Singhalb8d4f152016-02-10 10:21:43 -0800129sapSafeChannelType safe_channels[NUM_CHANNELS] = {
130 {1, true},
131 {2, true},
132 {3, true},
133 {4, true},
134 {5, true},
135 {6, true},
136 {7, true},
137 {8, true},
138 {9, true},
139 {10, true},
140 {11, true},
141 {12, true},
142 {13, true},
143 {14, true},
144 {36, true},
145 {40, true},
146 {44, true},
147 {48, true},
148 {52, true},
149 {56, true},
150 {60, true},
151 {64, true},
152 {100, true},
153 {104, true},
154 {108, true},
155 {112, true},
156 {116, true},
157 {120, true},
158 {124, true},
159 {128, true},
160 {132, true},
161 {136, true},
162 {140, true},
163 {144, true},
164 {149, true},
165 {153, true},
166 {157, true},
167 {161, true},
168 {165, true},
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800169};
170#endif
171
172typedef struct {
173 uint16_t chStartNum;
174 uint32_t weight;
175} sapAcsChannelInfo;
176
177sapAcsChannelInfo acs_ht40_channels5_g[] = {
178 {36, SAP_ACS_WEIGHT_MAX},
179 {44, SAP_ACS_WEIGHT_MAX},
180 {52, SAP_ACS_WEIGHT_MAX},
181 {60, SAP_ACS_WEIGHT_MAX},
182 {100, SAP_ACS_WEIGHT_MAX},
183 {108, SAP_ACS_WEIGHT_MAX},
184 {116, SAP_ACS_WEIGHT_MAX},
185 {124, SAP_ACS_WEIGHT_MAX},
186 {132, SAP_ACS_WEIGHT_MAX},
187 {140, SAP_ACS_WEIGHT_MAX},
188 {149, SAP_ACS_WEIGHT_MAX},
189 {157, SAP_ACS_WEIGHT_MAX},
190};
191
192sapAcsChannelInfo acs_ht80_channels[] = {
193 {36, SAP_ACS_WEIGHT_MAX},
194 {52, SAP_ACS_WEIGHT_MAX},
195 {100, SAP_ACS_WEIGHT_MAX},
196 {116, SAP_ACS_WEIGHT_MAX},
197 {132, SAP_ACS_WEIGHT_MAX},
198 {149, SAP_ACS_WEIGHT_MAX},
199};
200
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700201sapAcsChannelInfo acs_vht160_channels[] = {
202 {36, SAP_ACS_WEIGHT_MAX},
203 {100, SAP_ACS_WEIGHT_MAX},
204};
205
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800206sapAcsChannelInfo acs_ht40_channels24_g[] = {
207 {1, SAP_ACS_WEIGHT_MAX},
208 {2, SAP_ACS_WEIGHT_MAX},
209 {3, SAP_ACS_WEIGHT_MAX},
210 {4, SAP_ACS_WEIGHT_MAX},
211 {9, SAP_ACS_WEIGHT_MAX},
212};
213
214#define CHANNEL_165 165
215
216/* rssi discount for channels in PCL */
217#define PCL_RSSI_DISCOUNT 10
218
219#ifdef FEATURE_AP_MCC_CH_AVOIDANCE
220/**
221 * sap_check_n_add_channel() - checks and add given channel in sap context's
222 * avoid_channels_info struct
223 * @sap_ctx: sap context.
224 * @new_channel: channel to be added to sap_ctx's avoid ch info
225 *
226 * sap_ctx contains sap_avoid_ch_info strcut containing the list of channels on
227 * which MDM device's AP with MCC was detected. This function will add channels
228 * to that list after checking for duplicates.
229 *
230 * Return: true: if channel was added or already present
231 * else false: if channel list was already full.
232 */
Tang Yingying523322d2017-01-17 23:28:43 +0800233static bool
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -0700234sap_check_n_add_channel(struct sap_context *sap_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800235 uint8_t new_channel)
236{
237 uint8_t i = 0;
238 struct sap_avoid_channels_info *ie_info =
239 &sap_ctx->sap_detected_avoid_ch_ie;
240
241 for (i = 0; i < sizeof(ie_info->channels); i++) {
242 if (ie_info->channels[i] == new_channel)
243 break;
244
245 if (ie_info->channels[i] == 0) {
246 ie_info->channels[i] = new_channel;
247 break;
248 }
249 }
250 if (i == sizeof(ie_info->channels))
251 return false;
252 else
253 return true;
254}
255/**
256 * sap_check_n_add_overlapped_chnls() - checks & add overlapped channels
257 * to primary channel in 2.4Ghz band.
258 * @sap_ctx: sap context.
259 * @primary_chnl: primary channel to be avoided.
260 *
261 * sap_ctx contains sap_avoid_ch_info struct containing the list of channels on
262 * which MDM device's AP with MCC was detected. This function will add channels
263 * to that list after checking for duplicates.
264 *
265 * Return: true: if channel was added or already present
266 * else false: if channel list was already full.
267 */
268static bool
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -0700269sap_check_n_add_overlapped_chnls(struct sap_context *sap_ctx,
270 uint8_t primary_channel)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800271{
272 uint8_t i = 0, j = 0, upper_chnl = 0, lower_chnl = 0;
273 struct sap_avoid_channels_info *ie_info =
274 &sap_ctx->sap_detected_avoid_ch_ie;
275 /*
276 * if primary channel less than channel 1 or out of 2g band then
277 * no further process is required. return true in this case.
278 */
279 if (primary_channel < CHANNEL_1 || primary_channel > CHANNEL_14)
280 return true;
281
282 /* lower channel is one channel right before primary channel */
283 lower_chnl = primary_channel - 1;
284 /* upper channel is one channel right after primary channel */
285 upper_chnl = primary_channel + 1;
286
287 /* lower channel needs to be non-zero, zero is not valid channel */
288 if (lower_chnl > (CHANNEL_1 - 1)) {
289 for (i = 0; i < sizeof(ie_info->channels); i++) {
290 if (ie_info->channels[i] == lower_chnl)
291 break;
292 if (ie_info->channels[i] == 0) {
293 ie_info->channels[i] = lower_chnl;
294 break;
295 }
296 }
297 }
298 /* upper channel needs to be atleast last channel in 2.4Ghz band */
299 if (upper_chnl < (CHANNEL_14 + 1)) {
300 for (j = 0; j < sizeof(ie_info->channels); j++) {
301 if (ie_info->channels[j] == upper_chnl)
302 break;
303 if (ie_info->channels[j] == 0) {
304 ie_info->channels[j] = upper_chnl;
305 break;
306 }
307 }
308 }
309 if (i == sizeof(ie_info->channels) || j == sizeof(ie_info->channels))
310 return false;
311 else
312 return true;
313}
314
315/**
316 * sap_process_avoid_ie() - processes the detected Q2Q IE
317 * context's avoid_channels_info struct
318 * @hal: hal handle
319 * @sap_ctx: sap context.
320 * @scan_result: scan results for ACS scan.
321 * @spect_info: spectrum weights array to update
322 *
323 * Detection of Q2Q IE indicates presence of another MDM device with its AP
324 * operating in MCC mode. This function parses the scan results and processes
325 * the Q2Q IE if found. It then extracts the channels and populates them in
326 * sap_ctx struct. It also increases the weights of those channels so that
327 * ACS logic will avoid those channels in its selection algorithm.
328 *
329 * Return: void
330 */
Tang Yingying523322d2017-01-17 23:28:43 +0800331static void sap_process_avoid_ie(tHalHandle hal,
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -0700332 struct sap_context *sap_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800333 tScanResultHandle scan_result,
334 tSapChSelSpectInfo *spect_info)
335{
336 uint32_t total_ie_len = 0;
337 uint8_t *temp_ptr = NULL;
338 uint8_t i = 0;
339 struct sAvoidChannelIE *avoid_ch_ie;
340 tCsrScanResultInfo *node = NULL;
341 tpAniSirGlobal mac_ctx = NULL;
342 tSapSpectChInfo *spect_ch = NULL;
343
344 mac_ctx = PMAC_STRUCT(hal);
345 spect_ch = spect_info->pSpectCh;
346 node = sme_scan_result_get_first(hal, scan_result);
347
348 while (node) {
Abhishek Singh34a4d862016-10-26 16:01:51 +0530349 total_ie_len =
Jeff Johnson38e38a82017-10-06 10:32:31 -0700350 GET_IE_LEN_IN_BSS(node->BssDescriptor.length);
Naveen Rawat08db88f2017-09-08 15:07:48 -0700351 temp_ptr = wlan_get_vendor_ie_ptr_from_oui(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800352 SIR_MAC_QCOM_VENDOR_OUI,
353 SIR_MAC_QCOM_VENDOR_SIZE,
354 ((uint8_t *)&node->BssDescriptor.ieFields),
355 total_ie_len);
356
357 if (temp_ptr) {
358 avoid_ch_ie = (struct sAvoidChannelIE *)temp_ptr;
Will Huang55ba1042017-03-22 10:43:30 +0800359 if (avoid_ch_ie->type !=
360 QCOM_VENDOR_IE_MCC_AVOID_CH) {
361 node = sme_scan_result_get_next(hal,
362 scan_result);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800363 continue;
Will Huang55ba1042017-03-22 10:43:30 +0800364 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800365
366 sap_ctx->sap_detected_avoid_ch_ie.present = 1;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530367 QDF_TRACE(QDF_MODULE_ID_SAP,
368 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800369 "Q2Q IE - avoid ch %d",
370 avoid_ch_ie->channel);
371 /* add this channel to to_avoid channel list */
372 sap_check_n_add_channel(sap_ctx,
373 avoid_ch_ie->channel);
374 sap_check_n_add_overlapped_chnls(sap_ctx,
375 avoid_ch_ie->channel);
376 /*
377 * Mark weight of these channel present in IE to MAX
378 * so that ACS logic will to avoid thse channels
379 */
380 for (i = 0; i < spect_info->numSpectChans; i++)
381 if (spect_ch[i].chNum == avoid_ch_ie->channel) {
382 /*
383 * weight is set more than max so that,
384 * in the case of other channels being
385 * assigned max weight due to noise,
386 * they may be preferred over channels
387 * with Q2Q IE.
388 */
389 spect_ch[i].weight = SAP_ACS_WEIGHT_MAX + 1;
390 spect_ch[i].weight_copy =
391 SAP_ACS_WEIGHT_MAX + 1;
392 break;
393 }
394 } /* if (temp_ptr) */
395 node = sme_scan_result_get_next(hal, scan_result);
396 }
397}
398#endif /* FEATURE_AP_MCC_CH_AVOIDANCE */
399
400#ifdef FEATURE_WLAN_CH_AVOID
401/*==========================================================================
402 FUNCTION sap_update_unsafe_channel_list
403
404 DESCRIPTION
405 Function Undate unsafe channel list table
406
407 DEPENDENCIES
408 NA.
409
410 IN
411 SapContext pointer
412
413 RETURN VALUE
414 NULL
415 ============================================================================*/
Jeff Johnsone13d8062017-09-28 06:54:55 -0700416void sap_update_unsafe_channel_list(tHalHandle hal, struct sap_context *sap_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800417{
418 uint16_t i, j;
Amar Singhalb8d4f152016-02-10 10:21:43 -0800419 uint16_t unsafe_channel_list[NUM_CHANNELS];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800420 uint16_t unsafe_channel_count = 0;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700421 tpAniSirGlobal mac_ctx = NULL;
422
Yuanyuan Liu0e0aa932016-05-12 10:17:58 -0700423 qdf_device_t qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800424
Yuanyuan Liu97361182016-06-06 09:38:04 -0700425 if (!qdf_ctx) {
426 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_FATAL,
427 "qdf_ctx is NULL");
428 return;
429 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700430 mac_ctx = PMAC_STRUCT(hal);
431 if (!mac_ctx) {
432 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_FATAL,
433 "mac_ctx is NULL");
434 return;
435 }
Yuanyuan Liu97361182016-06-06 09:38:04 -0700436
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800437 /* Flush, default set all channel safe */
Amar Singhalb8d4f152016-02-10 10:21:43 -0800438 for (i = 0; i < NUM_CHANNELS; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800439 safe_channels[i].isSafe = true;
440 }
441
442 /* Try to find unsafe channel */
Ryan Hsu4252a2f2016-01-05 11:18:24 -0800443#if defined(FEATURE_WLAN_STA_AP_MODE_DFS_DISABLE)
Amar Singhalb8d4f152016-02-10 10:21:43 -0800444 for (i = 0; i < NUM_CHANNELS; i++) {
Jeff Johnsone13d8062017-09-28 06:54:55 -0700445 if (sap_ctx->dfs_ch_disable == true) {
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700446 if (wlan_reg_is_dfs_ch(mac_ctx->pdev,
447 safe_channels[i].channelNumber)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800448 safe_channels[i].isSafe = false;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530449 QDF_TRACE(QDF_MODULE_ID_SAP,
450 QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800451 "%s: DFS Ch %d is not safe in"
452 " Concurrent mode",
453 __func__,
454 safe_channels[i].channelNumber);
455 }
456 }
457 }
458#endif
Yuanyuan Liu0e0aa932016-05-12 10:17:58 -0700459 pld_get_wlan_unsafe_channel(qdf_ctx->dev,
460 unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800461 &unsafe_channel_count,
462 sizeof(unsafe_channel_list));
463
464 for (i = 0; i < unsafe_channel_count; i++) {
Amar Singhalb8d4f152016-02-10 10:21:43 -0800465 for (j = 0; j < NUM_CHANNELS; j++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800466 if (safe_channels[j].channelNumber ==
467 unsafe_channel_list[i]) {
468 /* Found unsafe channel, update it */
469 safe_channels[j].isSafe = false;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530470 QDF_TRACE(QDF_MODULE_ID_SAP,
471 QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800472 FL("CH %d is not safe"),
473 unsafe_channel_list[i]);
474 break;
475 }
476 }
477 }
478
479 return;
480}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800481
482#endif /* FEATURE_WLAN_CH_AVOID */
483
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800484/**
gaoleze5108942017-03-31 16:56:42 +0800485 * sap_channel_in_acs_channel_list() - check if channel in acs channel list
486 * @channel_num: channel to check
487 * @sap_ctx: struct ptSapContext
488 * @spect_info_params: strcut tSapChSelSpectInfo
489 *
490 * This function checks if specified channel is in the configured ACS channel
491 * list.
492 *
493 * Return: channel number if in acs channel list or SAP_CHANNEL_NOT_SELECTED
494 */
gaoleze5108942017-03-31 16:56:42 +0800495uint8_t sap_channel_in_acs_channel_list(uint8_t channel_num,
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -0700496 struct sap_context *sap_ctx,
gaoleze5108942017-03-31 16:56:42 +0800497 tSapChSelSpectInfo *spect_info_params)
498{
499 uint8_t i = 0;
500
501 if ((NULL == sap_ctx->acs_cfg->ch_list) ||
502 (NULL == spect_info_params))
503 return channel_num;
504
505 if (channel_num > 0 && channel_num <= 252) {
506 for (i = 0; i < sap_ctx->acs_cfg->ch_list_count; i++) {
507 if ((sap_ctx->acs_cfg->ch_list[i]) == channel_num)
508 return channel_num;
509 }
510 return SAP_CHANNEL_NOT_SELECTED;
511 } else {
512 return SAP_CHANNEL_NOT_SELECTED;
513 }
514}
515
516/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800517 * sap_select_preferred_channel_from_channel_list() - to calc best cahnnel
518 * @best_chnl: best channel already calculated among all the chanels
519 * @sap_ctx: sap context
520 * @spectinfo_param: Pointer to tSapChSelSpectInfo structure
521 *
522 * This function calculates the best channel among the configured channel list.
523 * If channel list not configured then returns the best channel calculated
524 * among all the channel list.
525 *
526 * Return: uint8_t best channel
527 */
Jeff Johnson464f7ea2016-10-07 10:21:26 -0700528static
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800529uint8_t sap_select_preferred_channel_from_channel_list(uint8_t best_chnl,
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -0700530 struct sap_context *sap_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800531 tSapChSelSpectInfo *spectinfo_param)
532{
533 uint8_t i = 0;
Tushnim Bhattacharyya518e80f2017-08-30 17:35:33 -0700534 tpAniSirGlobal mac_ctx = sme_get_mac_context();
535
536 if (NULL == mac_ctx) {
537 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR,
538 "pmac Global Context is NULL");
539 return SAP_CHANNEL_NOT_SELECTED;
540 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800541
542 /*
543 * If Channel List is not Configured don't do anything
544 * Else return the Best Channel from the Channel List
545 */
546 if ((NULL == sap_ctx->acs_cfg->ch_list) ||
547 (NULL == spectinfo_param) ||
548 (0 == sap_ctx->acs_cfg->ch_list_count))
549 return best_chnl;
550
551 if (best_chnl <= 0 || best_chnl > 252)
552 return SAP_CHANNEL_NOT_SELECTED;
553
554 /* Select the best channel from allowed list */
555 for (i = 0; i < sap_ctx->acs_cfg->ch_list_count; i++) {
Tushnim Bhattacharyya518e80f2017-08-30 17:35:33 -0700556 if ((sap_ctx->acs_cfg->ch_list[i] == best_chnl) &&
557 !(wlan_reg_is_dfs_ch(mac_ctx->pdev, best_chnl) &&
558 policy_mgr_disallow_mcc(mac_ctx->psoc, best_chnl))) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530559 QDF_TRACE(QDF_MODULE_ID_SAP,
560 QDF_TRACE_LEVEL_INFO_HIGH,
Naveen Rawatbec64d92017-09-13 14:35:21 -0700561 "Best channel so far is: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800562 best_chnl);
563 return best_chnl;
564 }
565 }
566
567 return SAP_CHANNEL_NOT_SELECTED;
568}
569
570/*==========================================================================
571 FUNCTION sap_chan_sel_init
572
573 DESCRIPTION
574 Function sap_chan_sel_init allocates the memory, intializes the
Anurag Chouhan6d760662016-02-20 16:05:43 +0530575 structures used by the channel selection algorithm
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800576
577 DEPENDENCIES
578 NA.
579
580 PARAMETERS
581
582 IN
583 halHandle : Pointer to tHalHandle
584 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
Jeff Johnsone13d8062017-09-28 06:54:55 -0700585 sap_ctx : Pointer to SAP Context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800586
587 RETURN VALUE
588 bool: Success or FAIL
589
590 SIDE EFFECTS
591 ============================================================================*/
Jeff Johnson464f7ea2016-10-07 10:21:26 -0700592static bool sap_chan_sel_init(tHalHandle halHandle,
593 tSapChSelSpectInfo *pSpectInfoParams,
Jeff Johnsone13d8062017-09-28 06:54:55 -0700594 struct sap_context *sap_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800595{
596 tSapSpectChInfo *pSpectCh = NULL;
597 uint8_t *pChans = NULL;
598 uint16_t channelnum = 0;
599 tpAniSirGlobal pMac = PMAC_STRUCT(halHandle);
600 bool chSafe = true;
601#ifdef FEATURE_WLAN_CH_AVOID
602 uint16_t i;
603#endif
604 uint32_t dfs_master_cap_enabled;
605 bool include_dfs_ch = true;
Himanshu Agarwalfee2e362018-01-18 20:26:35 +0530606 uint8_t chan_num;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800607
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530608 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, "In %s",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800609 __func__);
610
611 pSpectInfoParams->numSpectChans =
612 pMac->scan.base_channels.numChannels;
613
614 /* Allocate memory for weight computation of 2.4GHz */
615 pSpectCh =
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530616 (tSapSpectChInfo *) qdf_mem_malloc((pSpectInfoParams->numSpectChans)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800617 * sizeof(*pSpectCh));
618
619 if (pSpectCh == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530620 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR,
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530621 "In %s, QDF_MALLOC_ERR", __func__);
Srinivas Girigowda74a66d62017-06-21 23:28:25 -0700622 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800623 }
624
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800625 /* Initialize the pointers in the DfsParams to the allocated memory */
626 pSpectInfoParams->pSpectCh = pSpectCh;
627
628 pChans = pMac->scan.base_channels.channelList;
629
Ryan Hsu4252a2f2016-01-05 11:18:24 -0800630#if defined(FEATURE_WLAN_STA_AP_MODE_DFS_DISABLE)
Jeff Johnsone13d8062017-09-28 06:54:55 -0700631 if (sap_ctx->dfs_ch_disable == true)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800632 include_dfs_ch = false;
633#endif
634 sme_cfg_get_int(halHandle, WNI_CFG_DFS_MASTER_ENABLED,
635 &dfs_master_cap_enabled);
Agrawal Ashish65634612016-08-18 13:24:32 +0530636 if (dfs_master_cap_enabled == 0 ||
Jeff Johnsone13d8062017-09-28 06:54:55 -0700637 ACS_DFS_MODE_DISABLE == sap_ctx->dfs_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800638 include_dfs_ch = false;
639
640 /* Fill the channel number in the spectrum in the operating freq band */
641 for (channelnum = 0;
642 channelnum < pSpectInfoParams->numSpectChans;
Edhar, Mahesh Kumar4f660672015-10-30 11:53:26 +0530643 channelnum++, pChans++, pSpectCh++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800644 chSafe = true;
645
646 /* check if the channel is in NOL blacklist */
Jeff Johnsone13d8062017-09-28 06:54:55 -0700647 if (sap_dfs_is_channel_in_nol_list(sap_ctx, *pChans,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800648 PHY_SINGLE_CHANNEL_CENTERED)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530649 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800650 "In %s, Ch %d is in NOL list", __func__,
651 *pChans);
652 chSafe = false;
653 continue;
654 }
655
656 if (include_dfs_ch == false) {
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700657 if (wlan_reg_is_dfs_ch(pMac->pdev, *pChans)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800658 chSafe = false;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530659 QDF_TRACE(QDF_MODULE_ID_SAP,
660 QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800661 "In %s, DFS Ch %d not considered for ACS",
662 __func__, *pChans);
663 continue;
664 }
665 }
666
667#ifdef FEATURE_WLAN_CH_AVOID
Amar Singhalb8d4f152016-02-10 10:21:43 -0800668 for (i = 0; i < NUM_CHANNELS; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800669 if ((safe_channels[i].channelNumber == *pChans) &&
670 (false == safe_channels[i].isSafe)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530671 QDF_TRACE(QDF_MODULE_ID_SAP,
672 QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800673 "In %s, Ch %d is not safe", __func__,
674 *pChans);
675 chSafe = false;
676 break;
677 }
678 }
679#endif /* FEATURE_WLAN_CH_AVOID */
680
681 /* OFDM rates are not supported on channel 14 */
682 if (*pChans == 14 &&
Jeff Johnsone13d8062017-09-28 06:54:55 -0700683 eCSR_DOT11_MODE_11b != sap_ctx->csr_roamProfile.phyMode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800684 continue;
685 }
686
Deepthi Gowri48b89332016-08-30 18:43:05 +0530687 /* Skip DSRC channels */
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700688 if (WLAN_REG_IS_11P_CH(*pChans))
Deepthi Gowri48b89332016-08-30 18:43:05 +0530689 continue;
690
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800691 if (true == chSafe) {
692 pSpectCh->chNum = *pChans;
Srinivas Girigowda74a66d62017-06-21 23:28:25 -0700693 pSpectCh->valid = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800694 pSpectCh->rssiAgr = SOFTAP_MIN_RSSI; /* Initialise for all channels */
695 pSpectCh->channelWidth = SOFTAP_HT20_CHANNELWIDTH; /* Initialise 20MHz for all the Channels */
Himanshu Agarwalfee2e362018-01-18 20:26:35 +0530696 /* Initialise max ACS weight for all channels */
697 pSpectCh->weight = SAP_ACS_WEIGHT_MAX;
698 for (chan_num = 0; chan_num < sap_ctx->num_of_channel;
699 chan_num++) {
700 if (pSpectCh->chNum !=
701 sap_ctx->channelList[chan_num])
702 continue;
703
704 /*
705 * Initialize ACS weight to 0 for channels
706 * present in sap context scan channel list
707 */
708 pSpectCh->weight = 0;
709 break;
710 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800711 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800712 }
Srinivas Girigowda74a66d62017-06-21 23:28:25 -0700713 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800714}
715
gaoleze5108942017-03-31 16:56:42 +0800716/**
717 * sapweight_rssi_count() - calculates the channel weight due to rssi
Anurag Chouhan6d760662016-02-20 16:05:43 +0530718 and data count(here number of BSS observed)
gaoleze5108942017-03-31 16:56:42 +0800719 * @sap_ctx : Softap context
720 * @rssi : Max signal strength receieved from a BSS for the channel
721 * @count : Number of BSS observed in the channel
722 *
723 * Return: uint32_t Calculated channel weight based on above two
724 */
725static
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -0700726uint32_t sapweight_rssi_count(struct sap_context *sap_ctx, int8_t rssi,
gaoleze5108942017-03-31 16:56:42 +0800727 uint16_t count)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800728{
729 int32_t rssiWeight = 0;
730 int32_t countWeight = 0;
731 uint32_t rssicountWeight = 0;
gaoleze5108942017-03-31 16:56:42 +0800732 uint8_t softap_rssi_weight_cfg, softap_count_weight_cfg;
733 uint8_t softap_rssi_weight_local, softap_count_weight_local;
734
735 softap_rssi_weight_cfg =
736 ACS_WEIGHT_SOFTAP_RSSI_CFG(sap_ctx->auto_channel_select_weight);
737
738 softap_count_weight_cfg =
739 ACS_WEIGHT_SOFTAP_COUNT_CFG(sap_ctx->auto_channel_select_weight);
740
741 softap_rssi_weight_local =
742 ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight,
743 softap_rssi_weight_cfg);
744
745 softap_count_weight_local =
746 ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight,
747 softap_count_weight_cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800748
749 /* Weight from RSSI */
gaoleze5108942017-03-31 16:56:42 +0800750 rssiWeight = ACS_WEIGHT_COMPUTE(sap_ctx->auto_channel_select_weight,
751 softap_rssi_weight_cfg,
752 rssi - SOFTAP_MIN_RSSI,
753 SOFTAP_MAX_RSSI - SOFTAP_MIN_RSSI);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800754
gaoleze5108942017-03-31 16:56:42 +0800755 if (rssiWeight > softap_rssi_weight_local)
756 rssiWeight = softap_rssi_weight_local;
757
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758 else if (rssiWeight < 0)
759 rssiWeight = 0;
760
761 /* Weight from data count */
gaoleze5108942017-03-31 16:56:42 +0800762 countWeight = ACS_WEIGHT_COMPUTE(sap_ctx->auto_channel_select_weight,
763 softap_count_weight_cfg,
764 count - SOFTAP_MIN_COUNT,
765 SOFTAP_MAX_COUNT - SOFTAP_MIN_COUNT);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800766
gaoleze5108942017-03-31 16:56:42 +0800767 if (countWeight > softap_count_weight_local)
768 countWeight = softap_count_weight_local;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800769
770 rssicountWeight = rssiWeight + countWeight;
771
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530772 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800773 "In %s, rssiWeight=%d, countWeight=%d, rssicountWeight=%d",
774 __func__, rssiWeight, countWeight, rssicountWeight);
775
776 return rssicountWeight;
777}
778
779/**
gaoleze5108942017-03-31 16:56:42 +0800780 * sap_get_channel_status() - get channel info via channel number
781 * @p_mac: Pointer to Global MAC structure
782 * @channel_id: channel id
783 *
784 * Return: chan status info
785 */
786static struct lim_channel_status *sap_get_channel_status
787 (tpAniSirGlobal p_mac, uint32_t channel_id)
788{
789 return csr_get_channel_status(p_mac, channel_id);
790}
791
792/**
793 * sap_clear_channel_status() - clear chan info
794 * @p_mac: Pointer to Global MAC structure
795 *
796 * Return: none
797 */
798static void sap_clear_channel_status(tpAniSirGlobal p_mac)
799{
800 csr_clear_channel_status(p_mac);
801}
802
803/**
804 * sap_weight_channel_noise_floor() - compute noise floor weight
805 * @sap_ctx: sap context
806 * @chn_stat: Pointer to chan status info
807 *
808 * Return: channel noise floor weight
809 */
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -0700810static uint32_t sap_weight_channel_noise_floor(struct sap_context *sap_ctx,
gaoleze5108942017-03-31 16:56:42 +0800811 struct lim_channel_status
812 *channel_stat)
813{
814 uint32_t noise_floor_weight;
815 uint8_t softap_nf_weight_cfg;
816 uint8_t softap_nf_weight_local;
817
818 softap_nf_weight_cfg =
819 ACS_WEIGHT_SOFTAP_NOISE_FLOOR_CFG
820 (sap_ctx->auto_channel_select_weight);
821
822 softap_nf_weight_local =
823 ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight,
824 softap_nf_weight_cfg);
825
826 if (channel_stat == NULL || channel_stat->channelfreq == 0) {
Srinivas Girigowda80213e52018-01-23 14:51:33 -0800827 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG,
gaoleze5108942017-03-31 16:56:42 +0800828 "In %s, sanity check failed return max weight",
829 __func__);
830 return softap_nf_weight_local;
831 }
832
833 noise_floor_weight = (channel_stat->noise_floor == 0) ? 0 :
834 (ACS_WEIGHT_COMPUTE(
835 sap_ctx->auto_channel_select_weight,
836 softap_nf_weight_cfg,
837 channel_stat->noise_floor -
838 SOFTAP_MIN_NF,
839 SOFTAP_MAX_NF - SOFTAP_MIN_NF));
840
841 if (noise_floor_weight > softap_nf_weight_local)
842 noise_floor_weight = softap_nf_weight_local;
843 else if (noise_floor_weight < 0)
844 noise_floor_weight = 0;
845
846 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
847 "In %s, nf=%d, nfwc=%d, nfwl=%d, nfw=%d",
848 __func__, channel_stat->noise_floor,
849 softap_nf_weight_cfg, softap_nf_weight_local,
850 noise_floor_weight);
851
852 return noise_floor_weight;
853}
854
855/**
856 * sap_weight_channel_free() - compute channel free weight
857 * @sap_ctx: sap context
858 * @chn_stat: Pointer to chan status info
859 *
860 * Return: channel free weight
861 */
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -0700862static uint32_t sap_weight_channel_free(struct sap_context *sap_ctx,
gaoleze5108942017-03-31 16:56:42 +0800863 struct lim_channel_status
864 *channel_stat)
865{
866 uint32_t channel_free_weight;
867 uint8_t softap_channel_free_weight_cfg;
868 uint8_t softap_channel_free_weight_local;
869 uint32_t rx_clear_count = 0;
870 uint32_t cycle_count = 0;
871
872 softap_channel_free_weight_cfg =
873 ACS_WEIGHT_SOFTAP_CHANNEL_FREE_CFG
874 (sap_ctx->auto_channel_select_weight);
875
876 softap_channel_free_weight_local =
877 ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight,
878 softap_channel_free_weight_cfg);
879
880 if (channel_stat == NULL || channel_stat->channelfreq == 0) {
Srinivas Girigowda80213e52018-01-23 14:51:33 -0800881 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG,
gaoleze5108942017-03-31 16:56:42 +0800882 "In %s, sanity check failed return max weight",
883 __func__);
884 return softap_channel_free_weight_local;
885 }
886
887 rx_clear_count = channel_stat->rx_clear_count -
888 channel_stat->tx_frame_count -
889 channel_stat->rx_frame_count;
890 cycle_count = channel_stat->cycle_count;
891
892 /* LSH 4, otherwise it is always 0. */
893 channel_free_weight = (cycle_count == 0) ? 0 :
894 (ACS_WEIGHT_COMPUTE(
895 sap_ctx->auto_channel_select_weight,
896 softap_channel_free_weight_cfg,
897 ((rx_clear_count << 8) +
898 (cycle_count >> 1))/cycle_count -
899 (SOFTAP_MIN_CHNFREE << 8),
900 (SOFTAP_MAX_CHNFREE -
901 SOFTAP_MIN_CHNFREE) << 8));
902
903 if (channel_free_weight > softap_channel_free_weight_local)
904 channel_free_weight = softap_channel_free_weight_local;
905
906 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
907 "In %s, rcc=%d, cc=%d, tc=%d, rc=%d, cfwc=%d, cfwl=%d, cfw=%d",
908 __func__, rx_clear_count, cycle_count,
909 channel_stat->tx_frame_count,
910 channel_stat->rx_frame_count,
911 softap_channel_free_weight_cfg,
912 softap_channel_free_weight_local,
913 channel_free_weight);
914
915 return channel_free_weight;
916}
917
918/**
919 * sap_weight_channel_txpwr_range() - compute channel tx power range weight
920 * @sap_ctx: sap context
921 * @chn_stat: Pointer to chan status info
922 *
923 * Return: tx power range weight
924 */
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -0700925static uint32_t sap_weight_channel_txpwr_range(struct sap_context *sap_ctx,
gaoleze5108942017-03-31 16:56:42 +0800926 struct lim_channel_status
927 *channel_stat)
928{
929 uint32_t txpwr_weight_low_speed;
930 uint8_t softap_txpwr_range_weight_cfg;
931 uint8_t softap_txpwr_range_weight_local;
932
933 softap_txpwr_range_weight_cfg =
934 ACS_WEIGHT_SOFTAP_TX_POWER_RANGE_CFG
935 (sap_ctx->auto_channel_select_weight);
936
937 softap_txpwr_range_weight_local =
938 ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight,
939 softap_txpwr_range_weight_cfg);
940
941 if (channel_stat == NULL || channel_stat->channelfreq == 0) {
Srinivas Girigowda80213e52018-01-23 14:51:33 -0800942 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG,
gaoleze5108942017-03-31 16:56:42 +0800943 "In %s, sanity check failed return max weight",
944 __func__);
945 return softap_txpwr_range_weight_local;
946 }
947
948 txpwr_weight_low_speed = (channel_stat->chan_tx_pwr_range == 0) ? 0 :
949 (ACS_WEIGHT_COMPUTE(
950 sap_ctx->auto_channel_select_weight,
951 softap_txpwr_range_weight_cfg,
952 SOFTAP_MAX_TXPWR -
953 channel_stat->chan_tx_pwr_range,
954 SOFTAP_MAX_TXPWR - SOFTAP_MIN_TXPWR));
955
956 if (txpwr_weight_low_speed > softap_txpwr_range_weight_local)
957 txpwr_weight_low_speed = softap_txpwr_range_weight_local;
958
959 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
960 "In %s, tpr=%d, tprwc=%d, tprwl=%d, tprw=%d",
961 __func__, channel_stat->chan_tx_pwr_range,
962 softap_txpwr_range_weight_cfg,
963 softap_txpwr_range_weight_local,
964 txpwr_weight_low_speed);
965
966 return txpwr_weight_low_speed;
967}
968
969/**
970 * sap_weight_channel_txpwr_tput() - compute channel tx power
971 * throughput weight
972 * @sap_ctx: sap context
973 * @chn_stat: Pointer to chan status info
974 *
975 * Return: tx power throughput weight
976 */
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -0700977static uint32_t sap_weight_channel_txpwr_tput(struct sap_context *sap_ctx,
gaoleze5108942017-03-31 16:56:42 +0800978 struct lim_channel_status
979 *channel_stat)
980{
981 uint32_t txpwr_weight_high_speed;
982 uint8_t softap_txpwr_tput_weight_cfg;
983 uint8_t softap_txpwr_tput_weight_local;
984
985 softap_txpwr_tput_weight_cfg =
986 ACS_WEIGHT_SOFTAP_TX_POWER_THROUGHPUT_CFG
987 (sap_ctx->auto_channel_select_weight);
988
989 softap_txpwr_tput_weight_local =
990 ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight,
991 softap_txpwr_tput_weight_cfg);
992
993 if (channel_stat == NULL || channel_stat->channelfreq == 0) {
Srinivas Girigowda80213e52018-01-23 14:51:33 -0800994 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG,
gaoleze5108942017-03-31 16:56:42 +0800995 "In %s, sanity check failed return max weight",
996 __func__);
997 return softap_txpwr_tput_weight_local;
998 }
999
1000 txpwr_weight_high_speed = (channel_stat->chan_tx_pwr_throughput == 0)
1001 ? 0 : (ACS_WEIGHT_COMPUTE(
1002 sap_ctx->auto_channel_select_weight,
1003 softap_txpwr_tput_weight_cfg,
1004 SOFTAP_MAX_TXPWR -
1005 channel_stat->chan_tx_pwr_throughput,
1006 SOFTAP_MAX_TXPWR - SOFTAP_MIN_TXPWR));
1007
1008 if (txpwr_weight_high_speed > softap_txpwr_tput_weight_local)
1009 txpwr_weight_high_speed = softap_txpwr_tput_weight_local;
1010
1011 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
1012 "In %s, tpt=%d, tptwc=%d, tptwl=%d, tptw=%d",
1013 __func__, channel_stat->chan_tx_pwr_throughput,
1014 softap_txpwr_tput_weight_cfg,
1015 softap_txpwr_tput_weight_local,
1016 txpwr_weight_high_speed);
1017
1018 return txpwr_weight_high_speed;
1019}
1020
1021/**
1022 * sap_weight_channel_status() - compute chan status weight
1023 * @sap_ctx: sap context
1024 * @chn_stat: Pointer to chan status info
1025 *
1026 * Return: chan status weight
1027 */
1028static
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -07001029uint32_t sap_weight_channel_status(struct sap_context *sap_ctx,
gaoleze5108942017-03-31 16:56:42 +08001030 struct lim_channel_status *channel_stat)
1031{
1032 return sap_weight_channel_noise_floor(sap_ctx, channel_stat) +
1033 sap_weight_channel_free(sap_ctx, channel_stat) +
1034 sap_weight_channel_txpwr_range(sap_ctx, channel_stat) +
1035 sap_weight_channel_txpwr_tput(sap_ctx, channel_stat);
1036}
1037
1038/**
Yeshwanth Sriram Guntuka273889e2018-02-16 17:11:46 +05301039 * sap_check_channels_same_band() - Check if two channels belong to same band
1040 * @ch_num1: channel number
1041 * @ch_num2: channel number
1042 *
1043 * Return: true if both channels belong to same band else false
1044 */
1045static bool sap_check_channels_same_band(uint16_t ch_num1, uint16_t ch_num2)
1046{
1047 if ((ch_num1 <= SIR_11B_CHANNEL_END &&
1048 ch_num2 <= SIR_11B_CHANNEL_END) ||
1049 (ch_num1 >= SIR_11A_CHANNEL_BEGIN &&
1050 ch_num2 >= SIR_11A_CHANNEL_BEGIN))
1051 return true;
1052
1053 return false;
1054}
1055
1056/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001057 * sap_update_rssi_bsscount() - updates bss count and rssi effect.
1058 *
1059 * @pSpectCh: Channel Information
1060 * @offset: Channel Offset
1061 * @sap_24g: Channel is in 2.4G or 5G
Liangwei Dong71ed6502016-10-20 03:40:45 -04001062 * @spectch_start: the start of spect ch array
1063 * @spectch_end: the end of spect ch array
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001064 *
1065 * sap_update_rssi_bsscount updates bss count and rssi effect based
1066 * on the channel offset.
1067 *
1068 * Return: None.
1069 */
1070
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001071static void sap_update_rssi_bsscount(tSapSpectChInfo *pSpectCh, int32_t offset,
Liangwei Dong71ed6502016-10-20 03:40:45 -04001072 bool sap_24g, tSapSpectChInfo *spectch_start,
1073 tSapSpectChInfo *spectch_end)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074{
1075 tSapSpectChInfo *pExtSpectCh = NULL;
1076 int32_t rssi, rsssi_effect;
1077
1078 pExtSpectCh = (pSpectCh + offset);
Liangwei Dong71ed6502016-10-20 03:40:45 -04001079 if (pExtSpectCh != NULL &&
1080 pExtSpectCh >= spectch_start &&
1081 pExtSpectCh < spectch_end) {
Yeshwanth Sriram Guntuka273889e2018-02-16 17:11:46 +05301082 if (!sap_check_channels_same_band(pSpectCh->chNum,
1083 pExtSpectCh->chNum))
1084 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001085 ++pExtSpectCh->bssCount;
1086 switch (offset) {
1087 case -1:
1088 case 1:
1089 rsssi_effect = sap_24g ?
1090 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY :
1091 SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1092 break;
1093 case -2:
1094 case 2:
1095 rsssi_effect = sap_24g ?
1096 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY :
1097 SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1098 break;
1099 case -3:
1100 case 3:
1101 rsssi_effect = sap_24g ?
1102 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY :
1103 SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
1104 break;
1105 case -4:
1106 case 4:
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001107 rsssi_effect = sap_24g ?
1108 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY :
1109 SAP_SUBBAND4_RSSI_EFFECT_PRIMARY;
1110 break;
1111 case -5:
1112 case 5:
1113 rsssi_effect = SAP_SUBBAND5_RSSI_EFFECT_PRIMARY;
1114 break;
1115 case -6:
1116 case 6:
1117 rsssi_effect = SAP_SUBBAND6_RSSI_EFFECT_PRIMARY;
1118 break;
1119 case -7:
1120 case 7:
1121 rsssi_effect = SAP_SUBBAND7_RSSI_EFFECT_PRIMARY;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001122 break;
1123 default:
1124 rsssi_effect = 0;
1125 break;
1126 }
1127
1128 rssi = pSpectCh->rssiAgr + rsssi_effect;
1129 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1130 pExtSpectCh->rssiAgr = rssi;
1131 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1132 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1133 }
1134}
1135
1136/**
1137 * sap_upd_chan_spec_params() - sap_upd_chan_spec_params
1138 * updates channel parameters obtained from Beacon
1139 * @pBeaconStruct Beacon strucutre populated by parse_beacon function
1140 * @channelWidth Channel width
1141 * @secondaryChannelOffset Secondary Channel Offset
1142 * @vhtSupport If channel supports VHT
1143 * @centerFreq Central frequency for the given channel.
1144 *
1145 * sap_upd_chan_spec_params updates the spectrum channels based on the
1146 * pBeaconStruct obtained from Beacon IE
1147 *
1148 * Return: NA.
1149 */
1150
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001151static void sap_upd_chan_spec_params(tSirProbeRespBeacon *pBeaconStruct,
1152 uint16_t *channelWidth,
1153 uint16_t *secondaryChannelOffset,
1154 uint16_t *vhtSupport,
1155 uint16_t *centerFreq,
1156 uint16_t *centerFreq_2)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001157{
1158 if (NULL == pBeaconStruct) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301159 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001160 FL("pBeaconStruct is NULL"));
1161 return;
1162 }
1163
1164 if (pBeaconStruct->HTCaps.present && pBeaconStruct->HTInfo.present) {
1165 *channelWidth = pBeaconStruct->HTCaps.supportedChannelWidthSet;
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001166 *secondaryChannelOffset =
1167 pBeaconStruct->HTInfo.secondaryChannelOffset;
1168 if (!pBeaconStruct->VHTOperation.present)
1169 return;
1170 *vhtSupport = pBeaconStruct->VHTOperation.present;
1171 if (pBeaconStruct->VHTOperation.chanWidth) {
1172 *centerFreq =
1173 pBeaconStruct->VHTOperation.chanCenterFreqSeg1;
1174 *centerFreq_2 =
1175 pBeaconStruct->VHTOperation.chanCenterFreqSeg2;
1176 /*
1177 * LHS follows tSirMacHTChannelWidth, while RHS follows
1178 * WNI_CFG_VHT_CHANNEL_WIDTH_X format hence following
1179 * adjustment
1180 */
1181 *channelWidth =
1182 pBeaconStruct->VHTOperation.chanWidth + 1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001183
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001184 }
1185 }
1186}
1187
1188/**
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001189 * sap_update_rssi_bsscount_vht_5G() - updates bss count and rssi effect.
1190 *
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001191 * @spect_ch: Channel Information
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001192 * @offset: Channel Offset
1193 * @num_ch: no.of channels
Liangwei Dong71ed6502016-10-20 03:40:45 -04001194 * @spectch_start: the start of spect ch array
1195 * @spectch_end: the end of spect ch array
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001196 *
1197 * sap_update_rssi_bsscount_vht_5G updates bss count and rssi effect based
1198 * on the channel offset.
1199 *
1200 * Return: None.
1201 */
1202
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001203static void sap_update_rssi_bsscount_vht_5G(tSapSpectChInfo *spect_ch,
1204 int32_t offset,
Liangwei Dong71ed6502016-10-20 03:40:45 -04001205 uint16_t num_ch,
1206 tSapSpectChInfo *spectch_start,
1207 tSapSpectChInfo *spectch_end)
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001208{
1209 int32_t ch_offset;
1210 uint16_t i, cnt;
1211
1212 if (!offset)
1213 return;
1214 if (offset > 0)
1215 cnt = num_ch;
1216 else
1217 cnt = num_ch + 1;
1218 for (i = 0; i < cnt; i++) {
1219 ch_offset = offset + i;
1220 if (ch_offset == 0)
1221 continue;
Liangwei Dong71ed6502016-10-20 03:40:45 -04001222 sap_update_rssi_bsscount(spect_ch, ch_offset, false,
1223 spectch_start, spectch_end);
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001224 }
1225}
1226/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001227 * sap_interference_rssi_count_5G() - sap_interference_rssi_count
1228 * considers the Adjacent channel rssi and
1229 * data count(here number of BSS observed)
1230 * @spect_ch: Channel Information
1231 * @chan_width: Channel width parsed from beacon IE
1232 * @sec_chan_offset: Secondary Channel Offset
1233 * @center_freq: Central frequency for the given channel.
1234 * @channel_id: channel_id
Liangwei Dong71ed6502016-10-20 03:40:45 -04001235 * @spectch_start: the start of spect ch array
1236 * @spectch_end: the end of spect ch array
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001237 *
1238 * sap_interference_rssi_count_5G considers the Adjacent channel rssi
1239 * and data count(here number of BSS observed)
1240 *
1241 * Return: NA.
1242 */
1243
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001244static void sap_interference_rssi_count_5G(tSapSpectChInfo *spect_ch,
1245 uint16_t chan_width,
1246 uint16_t sec_chan_offset,
1247 uint16_t center_freq,
1248 uint16_t center_freq_2,
Liangwei Dong71ed6502016-10-20 03:40:45 -04001249 uint8_t channel_id,
1250 tSapSpectChInfo *spectch_start,
1251 tSapSpectChInfo *spectch_end)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001252{
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001253 uint16_t num_ch;
1254 int32_t offset = 0;
Srinivas Girigowda4d65ebe2017-10-13 21:41:42 -07001255
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001256 if (NULL == spect_ch) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301257 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001258 FL("spect_ch is NULL"));
1259 return;
1260 }
1261
1262 /* Updating the received ChannelWidth */
1263 if (spect_ch->channelWidth != chan_width)
1264 spect_ch->channelWidth = chan_width;
1265 /* If received ChannelWidth is other than HT20,
1266 * we need to update the extension channel Params as well
1267 * chan_width == 0, HT20
1268 * chan_width == 1, HT40
1269 * chan_width == 2, VHT80
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001270 * chan_width == 3, VHT160
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001271 */
1272
1273 switch (spect_ch->channelWidth) {
1274 case eHT_CHANNEL_WIDTH_40MHZ: /* HT40 */
1275 switch (sec_chan_offset) {
1276 /* Above the Primary Channel */
1277 case PHY_DOUBLE_CHANNEL_LOW_PRIMARY:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001278 sap_update_rssi_bsscount(spect_ch, 1, false,
1279 spectch_start, spectch_end);
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001280 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001281
1282 /* Below the Primary channel */
1283 case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001284 sap_update_rssi_bsscount(spect_ch, -1, false,
1285 spectch_start, spectch_end);
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001286 return;
1287 }
1288 return;
1289 case eHT_CHANNEL_WIDTH_80MHZ: /* VHT80 */
1290 num_ch = 3;
1291 if ((center_freq - channel_id) == 6) {
1292 offset = 1;
1293 } else if ((center_freq - channel_id) == 2) {
1294 offset = -1;
1295 } else if ((center_freq - channel_id) == -2) {
1296 offset = -2;
1297 } else if ((center_freq - channel_id) == -6) {
1298 offset = -3;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001299 }
1300 break;
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001301 case eHT_CHANNEL_WIDTH_160MHZ: /* VHT160 */
1302 num_ch = 7;
1303 if ((center_freq - channel_id) == 14)
1304 offset = 1;
1305 else if ((center_freq - channel_id) == 10)
1306 offset = -1;
1307 else if ((center_freq - channel_id) == 6)
1308 offset = -2;
1309 else if ((center_freq - channel_id) == 2)
1310 offset = -3;
1311 else if ((center_freq - channel_id) == -2)
1312 offset = -4;
1313 else if ((center_freq - channel_id) == -6)
1314 offset = -5;
1315 else if ((center_freq - channel_id) == -10)
1316 offset = -6;
1317 else if ((center_freq - channel_id) == -14)
1318 offset = -7;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001319 break;
1320 default:
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001321 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001322 }
Liangwei Dong71ed6502016-10-20 03:40:45 -04001323 sap_update_rssi_bsscount_vht_5G(spect_ch, offset, num_ch,
1324 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001325}
1326
1327/**
1328 * sap_interference_rssi_count() - sap_interference_rssi_count
1329 * considers the Adjacent channel rssi
1330 * and data count(here number of BSS observed)
1331 * @spect_ch Channel Information
Liangwei Dong71ed6502016-10-20 03:40:45 -04001332 * @spectch_start: the start of spect ch array
1333 * @spectch_end: the end of spect ch array
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001334 *
1335 * sap_interference_rssi_count considers the Adjacent channel rssi
1336 * and data count(here number of BSS observed)
1337 *
1338 * Return: None.
1339 */
1340
Liangwei Dong71ed6502016-10-20 03:40:45 -04001341static void sap_interference_rssi_count(tSapSpectChInfo *spect_ch,
1342 tSapSpectChInfo *spectch_start,
1343 tSapSpectChInfo *spectch_end)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001344{
1345 if (NULL == spect_ch) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301346 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001347 "%s: spect_ch is NULL", __func__);
1348 return;
1349 }
1350
1351 switch (spect_ch->chNum) {
1352 case CHANNEL_1:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001353 sap_update_rssi_bsscount(spect_ch, 1, true,
1354 spectch_start, spectch_end);
1355 sap_update_rssi_bsscount(spect_ch, 2, true,
1356 spectch_start, spectch_end);
1357 sap_update_rssi_bsscount(spect_ch, 3, true,
1358 spectch_start, spectch_end);
1359 sap_update_rssi_bsscount(spect_ch, 4, true,
1360 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361 break;
1362
1363 case CHANNEL_2:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001364 sap_update_rssi_bsscount(spect_ch, -1, true,
1365 spectch_start, spectch_end);
1366 sap_update_rssi_bsscount(spect_ch, 1, true,
1367 spectch_start, spectch_end);
1368 sap_update_rssi_bsscount(spect_ch, 2, true,
1369 spectch_start, spectch_end);
1370 sap_update_rssi_bsscount(spect_ch, 3, true,
1371 spectch_start, spectch_end);
1372 sap_update_rssi_bsscount(spect_ch, 4, true,
1373 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374 break;
1375 case CHANNEL_3:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001376 sap_update_rssi_bsscount(spect_ch, -2, true,
1377 spectch_start, spectch_end);
1378 sap_update_rssi_bsscount(spect_ch, -1, true,
1379 spectch_start, spectch_end);
1380 sap_update_rssi_bsscount(spect_ch, 1, true,
1381 spectch_start, spectch_end);
1382 sap_update_rssi_bsscount(spect_ch, 2, true,
1383 spectch_start, spectch_end);
1384 sap_update_rssi_bsscount(spect_ch, 3, true,
1385 spectch_start, spectch_end);
1386 sap_update_rssi_bsscount(spect_ch, 4, true,
1387 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001388 break;
1389 case CHANNEL_4:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001390 sap_update_rssi_bsscount(spect_ch, -3, true,
1391 spectch_start, spectch_end);
1392 sap_update_rssi_bsscount(spect_ch, -2, true,
1393 spectch_start, spectch_end);
1394 sap_update_rssi_bsscount(spect_ch, -1, true,
1395 spectch_start, spectch_end);
1396 sap_update_rssi_bsscount(spect_ch, 1, true,
1397 spectch_start, spectch_end);
1398 sap_update_rssi_bsscount(spect_ch, 2, true,
1399 spectch_start, spectch_end);
1400 sap_update_rssi_bsscount(spect_ch, 3, true,
1401 spectch_start, spectch_end);
1402 sap_update_rssi_bsscount(spect_ch, 4, true,
1403 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001404 break;
1405
1406 case CHANNEL_5:
1407 case CHANNEL_6:
1408 case CHANNEL_7:
1409 case CHANNEL_8:
1410 case CHANNEL_9:
1411 case CHANNEL_10:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001412 sap_update_rssi_bsscount(spect_ch, -4, true,
1413 spectch_start, spectch_end);
1414 sap_update_rssi_bsscount(spect_ch, -3, true,
1415 spectch_start, spectch_end);
1416 sap_update_rssi_bsscount(spect_ch, -2, true,
1417 spectch_start, spectch_end);
1418 sap_update_rssi_bsscount(spect_ch, -1, true,
1419 spectch_start, spectch_end);
1420 sap_update_rssi_bsscount(spect_ch, 1, true,
1421 spectch_start, spectch_end);
1422 sap_update_rssi_bsscount(spect_ch, 2, true,
1423 spectch_start, spectch_end);
1424 sap_update_rssi_bsscount(spect_ch, 3, true,
1425 spectch_start, spectch_end);
1426 sap_update_rssi_bsscount(spect_ch, 4, true,
1427 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428 break;
1429
1430 case CHANNEL_11:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001431 sap_update_rssi_bsscount(spect_ch, -4, true,
1432 spectch_start, spectch_end);
1433 sap_update_rssi_bsscount(spect_ch, -3, true,
1434 spectch_start, spectch_end);
1435 sap_update_rssi_bsscount(spect_ch, -2, true,
1436 spectch_start, spectch_end);
1437 sap_update_rssi_bsscount(spect_ch, -1, true,
1438 spectch_start, spectch_end);
1439 sap_update_rssi_bsscount(spect_ch, 1, true,
1440 spectch_start, spectch_end);
1441 sap_update_rssi_bsscount(spect_ch, 2, true,
1442 spectch_start, spectch_end);
1443 sap_update_rssi_bsscount(spect_ch, 3, true,
1444 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001445 break;
1446
1447 case CHANNEL_12:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001448 sap_update_rssi_bsscount(spect_ch, -4, true,
1449 spectch_start, spectch_end);
1450 sap_update_rssi_bsscount(spect_ch, -3, true,
1451 spectch_start, spectch_end);
1452 sap_update_rssi_bsscount(spect_ch, -2, true,
1453 spectch_start, spectch_end);
1454 sap_update_rssi_bsscount(spect_ch, -1, true,
1455 spectch_start, spectch_end);
1456 sap_update_rssi_bsscount(spect_ch, 1, true,
1457 spectch_start, spectch_end);
1458 sap_update_rssi_bsscount(spect_ch, 2, true,
1459 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001460 break;
1461
1462 case CHANNEL_13:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001463 sap_update_rssi_bsscount(spect_ch, -4, true,
1464 spectch_start, spectch_end);
1465 sap_update_rssi_bsscount(spect_ch, -3, true,
1466 spectch_start, spectch_end);
1467 sap_update_rssi_bsscount(spect_ch, -2, true,
1468 spectch_start, spectch_end);
1469 sap_update_rssi_bsscount(spect_ch, -1, true,
1470 spectch_start, spectch_end);
1471 sap_update_rssi_bsscount(spect_ch, 1, true,
1472 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001473 break;
1474
1475 case CHANNEL_14:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001476 sap_update_rssi_bsscount(spect_ch, -4, true,
1477 spectch_start, spectch_end);
1478 sap_update_rssi_bsscount(spect_ch, -3, true,
1479 spectch_start, spectch_end);
1480 sap_update_rssi_bsscount(spect_ch, -2, true,
1481 spectch_start, spectch_end);
1482 sap_update_rssi_bsscount(spect_ch, -1, true,
1483 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001484 break;
1485
1486 default:
1487 break;
1488 }
1489}
1490
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001491/**
1492 * ch_in_pcl() - Is channel in the Preferred Channel List (PCL)
1493 * @sap_ctx: SAP context which contains the current PCL
1494 * @channel: Input channel number to be checked
1495 *
1496 * Check if a channel is in the preferred channel list
1497 *
1498 * Return:
1499 * true: channel is in PCL,
1500 * false: channel is not in PCL
1501 */
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -07001502static bool ch_in_pcl(struct sap_context *sap_ctx, uint8_t channel)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001503{
1504 uint32_t i;
1505
1506 for (i = 0; i < sap_ctx->acs_cfg->pcl_ch_count; i++) {
1507 if (channel == sap_ctx->acs_cfg->pcl_channels[i])
1508 return true;
1509 }
1510
1511 return false;
1512}
1513
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001514/**
1515 * sap_compute_spect_weight() - Compute spectrum weight
1516 * @pSpectInfoParams: Pointer to the tSpectInfoParams structure
1517 * @halHandle: Pointer to HAL handle
1518 * @pResult: Pointer to tScanResultHandle
1519 * @sap_ctx: Context of the SAP
1520 *
1521 * Main function for computing the weight of each channel in the
1522 * spectrum based on the RSSI value of the BSSes on the channel
1523 * and number of BSS
1524 */
1525static void sap_compute_spect_weight(tSapChSelSpectInfo *pSpectInfoParams,
1526 tHalHandle halHandle,
1527 tScanResultHandle pResult,
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -07001528 struct sap_context *sap_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001529{
1530 int8_t rssi = 0;
1531 uint8_t chn_num = 0;
1532 uint8_t channel_id = 0;
1533
1534 tCsrScanResultInfo *pScanResult;
1535 tSapSpectChInfo *pSpectCh = pSpectInfoParams->pSpectCh;
1536 uint32_t operatingBand;
1537 uint16_t channelWidth;
1538 uint16_t secondaryChannelOffset;
1539 uint16_t centerFreq;
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001540 uint16_t centerFreq_2 = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001541 uint16_t vhtSupport;
1542 uint32_t ieLen = 0;
1543 tSirProbeRespBeacon *pBeaconStruct;
1544 tpAniSirGlobal pMac = (tpAniSirGlobal) halHandle;
Liangwei Dong71ed6502016-10-20 03:40:45 -04001545 tSapSpectChInfo *spectch_start = pSpectInfoParams->pSpectCh;
1546 tSapSpectChInfo *spectch_end = pSpectInfoParams->pSpectCh +
1547 pSpectInfoParams->numSpectChans;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001548
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301549 pBeaconStruct = qdf_mem_malloc(sizeof(tSirProbeRespBeacon));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001550 if (NULL == pBeaconStruct) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301551 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Kaushik, Sushantee3ed032016-08-04 16:40:46 +05301552 "Unable to allocate memory in sap_compute_spect_weight");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001553 return;
1554 }
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301555 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001556 "In %s, Computing spectral weight", __func__);
1557
1558 /**
1559 * Soft AP specific channel weight calculation using DFS formula
1560 */
1561 SET_ACS_BAND(operatingBand, sap_ctx);
1562
1563 pScanResult = sme_scan_result_get_first(halHandle, pResult);
1564
1565 while (pScanResult) {
1566 pSpectCh = pSpectInfoParams->pSpectCh;
1567 /* Defining the default values, so that any value will hold the default values */
1568 channelWidth = eHT_CHANNEL_WIDTH_20MHZ;
1569 secondaryChannelOffset = PHY_SINGLE_CHANNEL_CENTERED;
1570 vhtSupport = 0;
1571 centerFreq = 0;
1572
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001573
Yingying Tang22facc12016-10-20 17:43:59 +08001574 ieLen = GET_IE_LEN_IN_BSS(
1575 pScanResult->BssDescriptor.length);
1576 qdf_mem_set((uint8_t *) pBeaconStruct,
1577 sizeof(tSirProbeRespBeacon), 0);
1578
1579
1580 if ((sir_parse_beacon_ie
1581 (pMac, pBeaconStruct, (uint8_t *)
1582 (pScanResult->BssDescriptor.ieFields),
1583 ieLen)) == eSIR_SUCCESS)
1584 sap_upd_chan_spec_params(
1585 pBeaconStruct,
1586 &channelWidth,
1587 &secondaryChannelOffset,
1588 &vhtSupport, &centerFreq,
1589 &centerFreq_2);
1590
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001591 /* Processing for each tCsrScanResultInfo in the tCsrScanResult DLink list */
1592 for (chn_num = 0; chn_num < pSpectInfoParams->numSpectChans;
1593 chn_num++) {
1594
1595 /*
1596 * if the Beacon has channel ID, use it other wise we will
1597 * rely on the channelIdSelf
1598 */
1599 if (pScanResult->BssDescriptor.channelId == 0)
1600 channel_id =
1601 pScanResult->BssDescriptor.channelIdSelf;
1602 else
1603 channel_id =
1604 pScanResult->BssDescriptor.channelId;
1605
1606 if (pSpectCh && (channel_id == pSpectCh->chNum)) {
1607 if (pSpectCh->rssiAgr <
1608 pScanResult->BssDescriptor.rssi)
1609 pSpectCh->rssiAgr =
1610 pScanResult->BssDescriptor.rssi;
1611
1612 ++pSpectCh->bssCount; /* Increment the count of BSS */
1613
1614 /*
1615 * Connsidering the Extension Channel
1616 * only in a channels
1617 */
1618 switch (operatingBand) {
1619 case eCSR_DOT11_MODE_11a:
1620 sap_interference_rssi_count_5G(
1621 pSpectCh, channelWidth,
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001622 secondaryChannelOffset,
1623 centerFreq,
1624 centerFreq_2,
Liangwei Dong71ed6502016-10-20 03:40:45 -04001625 channel_id,
1626 spectch_start,
1627 spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001628 break;
1629
1630 case eCSR_DOT11_MODE_11g:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001631 sap_interference_rssi_count(pSpectCh,
1632 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001633 break;
1634
1635 case eCSR_DOT11_MODE_abg:
1636 sap_interference_rssi_count_5G(
1637 pSpectCh, channelWidth,
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001638 secondaryChannelOffset,
1639 centerFreq,
1640 centerFreq_2,
Liangwei Dong71ed6502016-10-20 03:40:45 -04001641 channel_id,
1642 spectch_start,
1643 spectch_end);
1644 sap_interference_rssi_count(pSpectCh,
1645 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001646 break;
1647 }
1648
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301649 QDF_TRACE(QDF_MODULE_ID_SAP,
1650 QDF_TRACE_LEVEL_INFO_HIGH,
Jeff Johnsona7c0ddb2017-09-18 08:14:12 -07001651 "In %s, bssdes.ch_self=%d, bssdes.ch_ID=%d, bssdes.rssi=%d, SpectCh.bssCount=%d, pScanResult=%pK, ChannelWidth %d, secondaryChanOffset %d, center frequency %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001652 __func__,
1653 pScanResult->BssDescriptor.
1654 channelIdSelf,
1655 pScanResult->BssDescriptor.channelId,
1656 pScanResult->BssDescriptor.rssi,
1657 pSpectCh->bssCount, pScanResult,
1658 pSpectCh->channelWidth,
1659 secondaryChannelOffset, centerFreq);
1660 pSpectCh++;
1661 break;
1662 } else {
1663 pSpectCh++;
1664 }
1665 }
1666
1667 pScanResult = sme_scan_result_get_next(halHandle, pResult);
1668 }
1669
1670 /* Calculate the weights for all channels in the spectrum pSpectCh */
1671 pSpectCh = pSpectInfoParams->pSpectCh;
1672
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301673 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001674 "In %s, Spectrum Channels Weight", __func__);
1675
1676 for (chn_num = 0; chn_num < (pSpectInfoParams->numSpectChans);
1677 chn_num++) {
1678
1679 /*
1680 rssi : Maximum received signal strength among all BSS on that channel
1681 bssCount : Number of BSS on that channel
1682 */
1683
1684 rssi = (int8_t) pSpectCh->rssiAgr;
1685 if (ch_in_pcl(sap_ctx, chn_num))
1686 rssi -= PCL_RSSI_DISCOUNT;
1687
Himanshu Agarwalfee2e362018-01-18 20:26:35 +05301688 if (pSpectCh->weight == SAP_ACS_WEIGHT_MAX)
1689 goto debug_info;
1690
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001691 pSpectCh->weight =
gaoleze5108942017-03-31 16:56:42 +08001692 SAPDFS_NORMALISE_1000 *
1693 (sapweight_rssi_count(sap_ctx, rssi,
1694 pSpectCh->bssCount) + sap_weight_channel_status(
1695 sap_ctx, sap_get_channel_status(pMac,
1696 pSpectCh->chNum)));
1697 if (pSpectCh->weight > SAP_ACS_WEIGHT_MAX)
1698 pSpectCh->weight = SAP_ACS_WEIGHT_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001699 pSpectCh->weight_copy = pSpectCh->weight;
1700
Himanshu Agarwalfee2e362018-01-18 20:26:35 +05301701debug_info:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001702 /* ------ Debug Info ------ */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301703 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001704 "In %s, Chan=%d Weight= %d rssiAgr=%d bssCount=%d",
1705 __func__, pSpectCh->chNum, pSpectCh->weight,
1706 pSpectCh->rssiAgr, pSpectCh->bssCount);
1707 /* ------ Debug Info ------ */
1708 pSpectCh++;
1709 }
gaoleze5108942017-03-31 16:56:42 +08001710 sap_clear_channel_status(pMac);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301711 qdf_mem_free(pBeaconStruct);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001712}
1713
1714/*==========================================================================
1715 FUNCTION sap_chan_sel_exit
1716
1717 DESCRIPTION
1718 Exit function for free out the allocated memory, to be called
1719 at the end of the dfsSelectChannel function
1720
1721 DEPENDENCIES
1722 NA.
1723
1724 PARAMETERS
1725
1726 IN
1727 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1728
1729 RETURN VALUE
1730 void : NULL
1731
1732 SIDE EFFECTS
1733 ============================================================================*/
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001734static void sap_chan_sel_exit(tSapChSelSpectInfo *pSpectInfoParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001735{
1736 /* Free all the allocated memory */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301737 qdf_mem_free(pSpectInfoParams->pSpectCh);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001738}
1739
1740/*==========================================================================
1741 FUNCTION sap_sort_chl_weight
1742
1743 DESCRIPTION
1744 Funtion to sort the channels with the least weight first for 20MHz channels
1745
1746 DEPENDENCIES
1747 NA.
1748
1749 PARAMETERS
1750
1751 IN
1752 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1753
1754 RETURN VALUE
1755 void : NULL
1756
1757 SIDE EFFECTS
1758 ============================================================================*/
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001759static void sap_sort_chl_weight(tSapChSelSpectInfo *pSpectInfoParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001760{
1761 tSapSpectChInfo temp;
1762
1763 tSapSpectChInfo *pSpectCh = NULL;
1764 uint32_t i = 0, j = 0, minWeightIndex = 0;
1765
1766 pSpectCh = pSpectInfoParams->pSpectCh;
1767 for (i = 0; i < pSpectInfoParams->numSpectChans; i++) {
1768 minWeightIndex = i;
1769 for (j = i + 1; j < pSpectInfoParams->numSpectChans; j++) {
1770 if (pSpectCh[j].weight <
1771 pSpectCh[minWeightIndex].weight) {
1772 minWeightIndex = j;
Yeshwanth Sriram Guntuka273889e2018-02-16 17:11:46 +05301773 } else if (pSpectCh[j].weight ==
1774 pSpectCh[minWeightIndex].weight) {
1775 if (pSpectCh[j].bssCount <
1776 pSpectCh[minWeightIndex].bssCount)
1777 minWeightIndex = j;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001778 }
1779 }
1780 if (minWeightIndex != i) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301781 qdf_mem_copy(&temp, &pSpectCh[minWeightIndex],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001782 sizeof(*pSpectCh));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301783 qdf_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001784 sizeof(*pSpectCh));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301785 qdf_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001786 }
1787 }
1788}
1789
1790/**
bingse2782382017-03-23 10:34:52 +08001791 * set_ht80_chl_bit() - to set availabe channel to ht80 channel bitmap
1792 * @channel_bitmap: Pointer to the chan_bonding_bitmap structure
1793 * @spect_info_params: Pointer to the tSapChSelSpectInfo structure
1794 *
1795 * Return: none
1796 */
1797static void set_ht80_chl_bit(chan_bonding_bitmap *channel_bitmap,
1798 tSapChSelSpectInfo *spec_info_params)
1799{
1800 uint8_t i, j;
1801 tSapSpectChInfo *spec_info;
1802 int start_channel = 0;
1803
1804 channel_bitmap->chanBondingSet[0].startChannel =
1805 acs_ht80_channels[0].chStartNum;
1806 channel_bitmap->chanBondingSet[1].startChannel =
1807 acs_ht80_channels[1].chStartNum;
1808 channel_bitmap->chanBondingSet[2].startChannel =
1809 acs_ht80_channels[2].chStartNum;
1810 channel_bitmap->chanBondingSet[3].startChannel =
1811 acs_ht80_channels[3].chStartNum;
1812 channel_bitmap->chanBondingSet[4].startChannel =
1813 acs_ht80_channels[4].chStartNum;
1814 channel_bitmap->chanBondingSet[5].startChannel =
1815 acs_ht80_channels[5].chStartNum;
1816
1817 spec_info = spec_info_params->pSpectCh;
1818 for (j = 0; j < spec_info_params->numSpectChans; j++) {
1819 for (i = 0; i < MAX_80MHZ_BANDS; i++) {
1820 start_channel =
1821 channel_bitmap->chanBondingSet[i].startChannel;
1822 if (spec_info[j].chNum >= start_channel &&
1823 (spec_info[j].chNum <= start_channel + 12)) {
1824 channel_bitmap->chanBondingSet[i].channelMap |=
1825 1 << ((spec_info[j].chNum -
1826 start_channel)/4);
1827 break;
1828 }
1829 }
1830 }
1831}
1832
1833/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001834 * sap_sort_chl_weight_ht80() - to sort the channels with the least weight
1835 * @pSpectInfoParams: Pointer to the tSapChSelSpectInfo structure
1836 *
1837 * Funtion to sort the channels with the least weight first for HT80 channels
1838 *
1839 * Return: none
1840 */
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001841static void sap_sort_chl_weight_ht80(tSapChSelSpectInfo *pSpectInfoParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001842{
1843 uint8_t i, j, n;
1844 tSapSpectChInfo *pSpectInfo;
1845 uint8_t minIdx;
bingse2782382017-03-23 10:34:52 +08001846 int start_channel = 0;
1847 chan_bonding_bitmap *channel_bitmap;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001848
bingse2782382017-03-23 10:34:52 +08001849 channel_bitmap = qdf_mem_malloc(sizeof(chan_bonding_bitmap));
1850 if (NULL == channel_bitmap) {
1851 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG,
1852 "%s: Failed to allocate memory", __func__);
1853 return;
1854 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001855 pSpectInfo = pSpectInfoParams->pSpectCh;
1856 /* for each HT80 channel, calculate the combined weight of the
1857 four 20MHz weight */
1858 for (i = 0; i < ARRAY_SIZE(acs_ht80_channels); i++) {
1859 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
1860 if (pSpectInfo[j].chNum ==
1861 acs_ht80_channels[i].chStartNum)
1862 break;
1863 }
1864 if (j == pSpectInfoParams->numSpectChans)
1865 continue;
1866
1867 if (!(((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 1].chNum) &&
1868 ((pSpectInfo[j].chNum + 8) ==
1869 pSpectInfo[j + 2].chNum) &&
1870 ((pSpectInfo[j].chNum + 12) ==
1871 pSpectInfo[j + 3].chNum))) {
1872 /*
1873 * some channels does not exist in pSectInfo array,
1874 * skip this channel and those in the same HT80 width
1875 */
1876 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 4;
1877 if ((pSpectInfo[j].chNum + 4) ==
1878 pSpectInfo[j + 1].chNum)
1879 pSpectInfo[j + 1].weight =
1880 SAP_ACS_WEIGHT_MAX * 4;
1881 if ((pSpectInfo[j].chNum + 8) ==
1882 pSpectInfo[j + 2].chNum)
1883 pSpectInfo[j + 2].weight =
1884 SAP_ACS_WEIGHT_MAX * 4;
1885 if ((pSpectInfo[j].chNum + 12) ==
1886 pSpectInfo[j + 3].chNum)
1887 pSpectInfo[j + 3].weight =
1888 SAP_ACS_WEIGHT_MAX * 4;
1889 continue;
1890 }
1891 /*found the channel, add the 4 adjacent channels' weight */
1892 acs_ht80_channels[i].weight = pSpectInfo[j].weight +
1893 pSpectInfo[j + 1].weight + pSpectInfo[j + 2].weight +
1894 pSpectInfo[j + 3].weight;
1895 /* find best channel among 4 channels as the primary channel */
1896 if ((pSpectInfo[j].weight + pSpectInfo[j + 1].weight) <
1897 (pSpectInfo[j + 2].weight + pSpectInfo[j + 3].weight)) {
1898 /* lower 2 channels are better choice */
1899 if (pSpectInfo[j].weight < pSpectInfo[j + 1].weight)
1900 minIdx = 0;
1901 else
1902 minIdx = 1;
1903 } else if (pSpectInfo[j + 2].weight <=
1904 pSpectInfo[j + 3].weight) {
1905 /* upper 2 channels are better choice */
1906 minIdx = 2;
1907 } else {
1908 minIdx = 3;
1909 }
1910
1911 /*
1912 * set all 4 channels to max value first, then reset the
1913 * best channel as the selected primary channel, update its
1914 * weightage with the combined weight value
1915 */
1916 for (n = 0; n < 4; n++)
1917 pSpectInfo[j + n].weight = SAP_ACS_WEIGHT_MAX * 4;
1918
1919 pSpectInfo[j + minIdx].weight = acs_ht80_channels[i].weight;
1920 }
1921
bingse2782382017-03-23 10:34:52 +08001922 /*
1923 * mark the weight of the channel that can't satisfy 80MHZ
1924 * as max value, so that it will be sorted to the bottom
1925 */
1926 set_ht80_chl_bit(channel_bitmap, pSpectInfoParams);
1927 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
1928 for (i = 0; i < MAX_80MHZ_BANDS; i++) {
1929 start_channel =
1930 channel_bitmap->chanBondingSet[i].startChannel;
1931 if (pSpectInfo[j].chNum >= start_channel &&
1932 (pSpectInfo[j].chNum <=
1933 start_channel + 12) &&
1934 channel_bitmap->chanBondingSet[i].channelMap !=
1935 SAP_80MHZ_MASK)
1936 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 4;
1937 }
1938 }
1939
Himanshu Agarwal75e74412018-02-01 20:51:47 +05301940 /*
1941 * Assign max weight(SAP_ACS_WEIGHT_MAX * 4) to 2.4 Ghz channels
1942 * and channel 165 as they cannot be part of a 80Mhz channel bonding.
1943 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001944 pSpectInfo = pSpectInfoParams->pSpectCh;
1945 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
Himanshu Agarwal75e74412018-02-01 20:51:47 +05301946 if ((pSpectInfo[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_1) &&
1947 pSpectInfo[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_14)) ||
1948 (CHANNEL_165 == pSpectInfo[j].chNum))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001949 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 4;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001950 }
1951
Manishekar Chandrasekaran44e334f2016-05-30 16:42:50 +05301952 sap_sort_chl_weight(pSpectInfoParams);
1953
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001954 pSpectInfo = pSpectInfoParams->pSpectCh;
1955 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301956 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001957 FL("Channel=%d Weight= %d rssi=%d bssCount=%d"),
1958 pSpectInfo->chNum, pSpectInfo->weight,
1959 pSpectInfo->rssiAgr, pSpectInfo->bssCount);
1960 pSpectInfo++;
1961 }
bingse2782382017-03-23 10:34:52 +08001962 qdf_mem_free(channel_bitmap);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001963}
1964
1965/**
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001966 * sap_sort_chl_weight_vht160() - to sort the channels with the least weight
1967 * @pSpectInfoParams: Pointer to the tSapChSelSpectInfo structure
1968 *
1969 * Funtion to sort the channels with the least weight first for VHT160 channels
1970 *
1971 * Return: none
1972 */
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001973static void sap_sort_chl_weight_vht160(tSapChSelSpectInfo *pSpectInfoParams)
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001974{
1975 uint8_t i, j, n, idx;
1976 tSapSpectChInfo *pSpectInfo;
1977 uint8_t minIdx;
1978
1979 pSpectInfo = pSpectInfoParams->pSpectCh;
1980 /* for each VHT160 channel, calculate the combined weight of the
1981 8 20MHz weight */
1982 for (i = 0; i < ARRAY_SIZE(acs_vht160_channels); i++) {
1983 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
1984 if (pSpectInfo[j].chNum ==
1985 acs_vht160_channels[i].chStartNum)
1986 break;
1987 }
1988 if (j == pSpectInfoParams->numSpectChans)
1989 continue;
1990
1991 if (!(((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 1].chNum) &&
1992 ((pSpectInfo[j].chNum + 8) ==
1993 pSpectInfo[j + 2].chNum) &&
1994 ((pSpectInfo[j].chNum + 12) ==
1995 pSpectInfo[j + 3].chNum) &&
1996 ((pSpectInfo[j].chNum + 16) ==
1997 pSpectInfo[j + 4].chNum) &&
1998 ((pSpectInfo[j].chNum + 20) ==
1999 pSpectInfo[j + 5].chNum) &&
2000 ((pSpectInfo[j].chNum + 24) ==
2001 pSpectInfo[j + 6].chNum) &&
2002 ((pSpectInfo[j].chNum + 28) ==
2003 pSpectInfo[j + 7].chNum))) {
2004 /*
2005 * some channels does not exist in pSectInfo array,
2006 * skip this channel and those in the same VHT160 width
2007 */
2008 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 8;
2009 if ((pSpectInfo[j].chNum + 4) ==
2010 pSpectInfo[j + 1].chNum)
2011 pSpectInfo[j + 1].weight =
2012 SAP_ACS_WEIGHT_MAX * 8;
2013 if ((pSpectInfo[j].chNum + 8) ==
2014 pSpectInfo[j + 2].chNum)
2015 pSpectInfo[j + 2].weight =
2016 SAP_ACS_WEIGHT_MAX * 8;
2017 if ((pSpectInfo[j].chNum + 12) ==
2018 pSpectInfo[j + 3].chNum)
2019 pSpectInfo[j + 3].weight =
2020 SAP_ACS_WEIGHT_MAX * 8;
2021 if ((pSpectInfo[j].chNum + 16) ==
2022 pSpectInfo[j + 4].chNum)
2023 pSpectInfo[j + 4].weight =
2024 SAP_ACS_WEIGHT_MAX * 8;
2025 if ((pSpectInfo[j].chNum + 20) ==
2026 pSpectInfo[j + 5].chNum)
2027 pSpectInfo[j + 5].weight =
2028 SAP_ACS_WEIGHT_MAX * 8;
2029 if ((pSpectInfo[j].chNum + 24) ==
2030 pSpectInfo[j + 6].chNum)
2031 pSpectInfo[j + 6].weight =
2032 SAP_ACS_WEIGHT_MAX * 8;
2033 if ((pSpectInfo[j].chNum + 28) ==
2034 pSpectInfo[j + 7].chNum)
2035 pSpectInfo[j + 7].weight =
2036 SAP_ACS_WEIGHT_MAX * 8;
2037 continue;
2038 }
2039 /*found the channel, add the 7 adjacent channels' weight */
2040 acs_vht160_channels[i].weight = pSpectInfo[j].weight +
2041 pSpectInfo[j + 1].weight + pSpectInfo[j + 2].weight +
2042 pSpectInfo[j + 3].weight + pSpectInfo[j + 4].weight +
2043 pSpectInfo[j + 5].weight + pSpectInfo[j + 6].weight +
2044 pSpectInfo[j + 7].weight;
2045
2046 /* find best channel among 8 channels as the primary channel */
2047 if ((pSpectInfo[j].weight + pSpectInfo[j + 1].weight +
2048 pSpectInfo[j + 2].weight + pSpectInfo[j + 3].weight) >
2049 (pSpectInfo[j + 4].weight + pSpectInfo[j + 5].weight +
2050 pSpectInfo[j + 6].weight + pSpectInfo[j + 7].weight))
2051 idx = 4;
2052 else
2053 idx = 0;
2054 /* find best channel among 4 channels as the primary channel */
2055 if ((pSpectInfo[j + idx].weight +
2056 pSpectInfo[j + idx + 1].weight) <
2057 (pSpectInfo[j + idx + 2].weight +
2058 pSpectInfo[j + idx + 3].weight)) {
2059 /* lower 2 channels are better choice */
2060 if (pSpectInfo[j + idx].weight <
2061 pSpectInfo[j + idx + 1].weight)
2062 minIdx = 0 + idx;
2063 else
2064 minIdx = 1 + idx;
2065 } else if (pSpectInfo[j + idx + 2].weight <=
2066 pSpectInfo[j + idx + 3].weight) {
2067 /* upper 2 channels are better choice */
2068 minIdx = 2 + idx;
2069 } else {
2070 minIdx = 3 + idx;
2071 }
2072
2073 /*
2074 * set all 8 channels to max value first, then reset the
2075 * best channel as the selected primary channel, update its
2076 * weightage with the combined weight value
2077 */
2078 for (n = 0; n < 8; n++)
2079 pSpectInfo[j + n].weight = SAP_ACS_WEIGHT_MAX * 8;
2080
2081 pSpectInfo[j + minIdx].weight = acs_vht160_channels[i].weight;
2082 }
2083
Himanshu Agarwal75e74412018-02-01 20:51:47 +05302084 /*
2085 * Assign max weight(SAP_ACS_WEIGHT_MAX * 8) to 2.4 Ghz channels
2086 * and channel 132-165 as they cannot be part of a 160Mhz channel
2087 * bonding.
2088 */
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07002089 pSpectInfo = pSpectInfoParams->pSpectCh;
2090 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
Himanshu Agarwal75e74412018-02-01 20:51:47 +05302091 if ((pSpectInfo[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_1) &&
2092 pSpectInfo[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_14)) ||
2093 (pSpectInfo[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_132) &&
2094 pSpectInfo[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_165)))
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07002095 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 8;
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07002096 }
2097
Manishekar Chandrasekaran44e334f2016-05-30 16:42:50 +05302098 sap_sort_chl_weight(pSpectInfoParams);
2099
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07002100 pSpectInfo = pSpectInfoParams->pSpectCh;
2101 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302102 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07002103 FL("Channel=%d Weight= %d rssi=%d bssCount=%d"),
2104 pSpectInfo->chNum, pSpectInfo->weight,
2105 pSpectInfo->rssiAgr, pSpectInfo->bssCount);
2106 pSpectInfo++;
2107 }
2108}
2109
2110/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002111 * sap_sort_chl_weight_ht40_24_g() - to sort channel with the least weight
2112 * @pSpectInfoParams: Pointer to the tSapChSelSpectInfo structure
2113 *
2114 * Funtion to sort the channels with the least weight first for HT40 channels
2115 *
2116 * Return: none
2117 */
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002118static void sap_sort_chl_weight_ht40_24_g(tSapChSelSpectInfo *pSpectInfoParams,
2119 v_REGDOMAIN_t domain)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002120{
2121 uint8_t i, j;
2122 tSapSpectChInfo *pSpectInfo;
2123 uint32_t tmpWeight1, tmpWeight2;
bingse2782382017-03-23 10:34:52 +08002124 uint32_t ht40plus2gendch = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002125
2126 pSpectInfo = pSpectInfoParams->pSpectCh;
2127 /*
2128 * for each HT40 channel, calculate the combined weight of the
2129 * two 20MHz weight
2130 */
2131 for (i = 0; i < ARRAY_SIZE(acs_ht40_channels24_g); i++) {
2132 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
2133 if (pSpectInfo[j].chNum ==
2134 acs_ht40_channels24_g[i].chStartNum)
2135 break;
2136 }
2137 if (j == pSpectInfoParams->numSpectChans)
2138 continue;
2139
2140 if (!((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 4].chNum)) {
2141 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
2142 continue;
2143 }
2144 /*
2145 * check if there is another channel combination possiblity
2146 * e.g., {1, 5} & {5, 9}
2147 */
2148 if ((pSpectInfo[j + 4].chNum + 4) == pSpectInfo[j + 8].chNum) {
2149 /* need to compare two channel pairs */
2150 tmpWeight1 = pSpectInfo[j].weight +
2151 pSpectInfo[j + 4].weight;
2152 tmpWeight2 = pSpectInfo[j + 4].weight +
2153 pSpectInfo[j + 8].weight;
2154 if (tmpWeight1 <= tmpWeight2) {
2155 if (pSpectInfo[j].weight <=
2156 pSpectInfo[j + 4].weight) {
2157 pSpectInfo[j].weight =
2158 tmpWeight1;
2159 pSpectInfo[j + 4].weight =
2160 SAP_ACS_WEIGHT_MAX * 2;
2161 pSpectInfo[j + 8].weight =
2162 SAP_ACS_WEIGHT_MAX * 2;
2163 } else {
2164 pSpectInfo[j + 4].weight =
2165 tmpWeight1;
2166 /* for secondary channel selection */
2167 pSpectInfo[j].weight =
2168 SAP_ACS_WEIGHT_MAX * 2
2169 - 1;
2170 pSpectInfo[j + 8].weight =
2171 SAP_ACS_WEIGHT_MAX * 2;
2172 }
2173 } else {
2174 if (pSpectInfo[j + 4].weight <=
2175 pSpectInfo[j + 8].weight) {
2176 pSpectInfo[j + 4].weight =
2177 tmpWeight2;
2178 pSpectInfo[j].weight =
2179 SAP_ACS_WEIGHT_MAX * 2;
2180 /* for secondary channel selection */
2181 pSpectInfo[j + 8].weight =
2182 SAP_ACS_WEIGHT_MAX * 2
2183 - 1;
2184 } else {
2185 pSpectInfo[j + 8].weight =
2186 tmpWeight2;
2187 pSpectInfo[j].weight =
2188 SAP_ACS_WEIGHT_MAX * 2;
2189 pSpectInfo[j + 4].weight =
2190 SAP_ACS_WEIGHT_MAX * 2;
2191 }
2192 }
2193 } else {
bingsaa6f96a2017-09-11 09:49:43 +08002194 tmpWeight1 = pSpectInfo[j].weight_copy +
2195 pSpectInfo[j + 4].weight_copy;
2196 if (pSpectInfo[j].weight_copy <=
2197 pSpectInfo[j + 4].weight_copy) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002198 pSpectInfo[j].weight = tmpWeight1;
2199 pSpectInfo[j + 4].weight =
2200 SAP_ACS_WEIGHT_MAX * 2;
2201 } else {
2202 pSpectInfo[j + 4].weight = tmpWeight1;
2203 pSpectInfo[j].weight =
2204 SAP_ACS_WEIGHT_MAX * 2;
2205 }
2206 }
2207 }
bingse2782382017-03-23 10:34:52 +08002208 /*
2209 * Every channel should be checked. Add the check for the omissive
2210 * channel. Mark the channel whose combination can't satisfy 40MHZ
2211 * as max value, so that it will be sorted to the bottom.
2212 */
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002213 if (REGDOMAIN_FCC == domain)
bingse2782382017-03-23 10:34:52 +08002214 ht40plus2gendch = HT40PLUS_2G_FCC_CH_END;
2215 else
2216 ht40plus2gendch = HT40PLUS_2G_EURJAP_CH_END;
2217 for (i = HT40MINUS_2G_CH_START; i <= ht40plus2gendch; i++) {
2218 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
2219 if (pSpectInfo[j].chNum == i &&
2220 ((pSpectInfo[j].chNum + 4) !=
2221 pSpectInfo[j+4].chNum) &&
2222 ((pSpectInfo[j].chNum - 4) !=
2223 pSpectInfo[j-4].chNum))
2224 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
2225 }
2226 }
2227 for (i = ht40plus2gendch + 1; i <= HT40MINUS_2G_CH_END; i++) {
2228 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
2229 if (pSpectInfo[j].chNum == i &&
2230 (pSpectInfo[j].chNum - 4) !=
2231 pSpectInfo[j-4].chNum)
2232 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
2233 }
2234 }
Manishekar Chandrasekaran44e334f2016-05-30 16:42:50 +05302235 sap_sort_chl_weight(pSpectInfoParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002236}
2237
2238/*==========================================================================
2239 FUNCTION sap_sort_chl_weight_ht40_5_g
2240
2241 DESCRIPTION
2242 Funtion to sort the channels with the least weight first for HT40 channels
2243
2244 DEPENDENCIES
2245 NA.
2246
2247 PARAMETERS
2248
2249 IN
2250 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
2251
2252 RETURN VALUE
2253 void : NULL
2254
2255 SIDE EFFECTS
2256 ============================================================================*/
Jeff Johnson464f7ea2016-10-07 10:21:26 -07002257static void sap_sort_chl_weight_ht40_5_g(tSapChSelSpectInfo *pSpectInfoParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002258{
2259 uint8_t i, j;
2260 tSapSpectChInfo *pSpectInfo;
2261
2262 pSpectInfo = pSpectInfoParams->pSpectCh;
2263 /*for each HT40 channel, calculate the combined weight of the
2264 two 20MHz weight */
2265 for (i = 0; i < ARRAY_SIZE(acs_ht40_channels5_g); i++) {
2266 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
2267 if (pSpectInfo[j].chNum ==
2268 acs_ht40_channels5_g[i].chStartNum)
2269 break;
2270 }
2271 if (j == pSpectInfoParams->numSpectChans)
2272 continue;
2273
2274 /* found the channel, add the two adjacent channels' weight */
2275 if ((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 1].chNum) {
2276 acs_ht40_channels5_g[i].weight = pSpectInfo[j].weight +
2277 pSpectInfo[j + 1].weight;
2278 /* select better of the adjact channel as the primary channel */
2279 if (pSpectInfo[j].weight <= pSpectInfo[j + 1].weight) {
2280 pSpectInfo[j].weight =
2281 acs_ht40_channels5_g[i].weight;
2282 /* mark the adjacent channel's weight as max value so
2283 that it will be sorted to the bottom */
2284 pSpectInfo[j + 1].weight =
2285 SAP_ACS_WEIGHT_MAX * 2;
2286 } else {
2287 pSpectInfo[j + 1].weight =
2288 acs_ht40_channels5_g[i].weight;
2289 /* mark the adjacent channel's weight as max value so
2290 that it will be sorted to the bottom */
2291 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
2292 }
2293
2294 } else
2295 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
2296 }
2297
bingse2782382017-03-23 10:34:52 +08002298 /*
2299 *Every channel should be checked. Add the check for the omissive
2300 * channel. Mark the channel whose combination can't satisfy 40MHZ
2301 * as max value, so that it will be sorted to the bottom
2302 */
2303 for (j = 1; j < pSpectInfoParams->numSpectChans; j++) {
2304 for (i = 0; i < ARRAY_SIZE(acs_ht40_channels5_g); i++) {
2305 if (pSpectInfo[j].chNum ==
2306 (acs_ht40_channels5_g[i].chStartNum +
2307 4) &&
2308 pSpectInfo[j - 1].chNum !=
2309 acs_ht40_channels5_g[i].chStartNum) {
2310 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
2311 break;
2312 }
2313 }
2314 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002315 /* avoid channel 165 by setting its weight to max */
2316 pSpectInfo = pSpectInfoParams->pSpectCh;
2317 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
2318 if (CHANNEL_165 == pSpectInfo[j].chNum) {
2319 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
2320 break;
2321 }
2322 }
2323
2324 pSpectInfo = pSpectInfoParams->pSpectCh;
2325 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302326 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002327 "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d",
2328 __func__, pSpectInfo->chNum, pSpectInfo->weight,
2329 pSpectInfo->rssiAgr, pSpectInfo->bssCount);
2330 pSpectInfo++;
2331 }
2332
2333 sap_sort_chl_weight(pSpectInfoParams);
2334}
2335
2336/*==========================================================================
2337 FUNCTION sap_sort_chl_weight_all
2338
2339 DESCRIPTION
2340 Funtion to sort the channels with the least weight first
2341
2342 DEPENDENCIES
2343 NA.
2344
2345 PARAMETERS
2346
2347 IN
Jeff Johnsone13d8062017-09-28 06:54:55 -07002348 sap_ctx : Pointer to the struct sap_context *structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002349 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
2350
2351 RETURN VALUE
2352 void : NULL
2353
2354 SIDE EFFECTS
2355 ============================================================================*/
Jeff Johnsone13d8062017-09-28 06:54:55 -07002356static void sap_sort_chl_weight_all(struct sap_context *sap_ctx,
Jeff Johnson464f7ea2016-10-07 10:21:26 -07002357 tSapChSelSpectInfo *pSpectInfoParams,
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002358 uint32_t operatingBand,
2359 v_REGDOMAIN_t domain)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002360{
2361 tSapSpectChInfo *pSpectCh = NULL;
2362 uint32_t j = 0;
2363#ifndef SOFTAP_CHANNEL_RANGE
2364 uint32_t i = 0;
2365#endif
2366
2367 pSpectCh = pSpectInfoParams->pSpectCh;
2368#ifdef SOFTAP_CHANNEL_RANGE
2369
Jeff Johnsone13d8062017-09-28 06:54:55 -07002370 switch (sap_ctx->acs_cfg->ch_width) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002371 case CH_WIDTH_40MHZ:
2372 if (eCSR_DOT11_MODE_11g == operatingBand)
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002373 sap_sort_chl_weight_ht40_24_g(pSpectInfoParams, domain);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002374 else if (eCSR_DOT11_MODE_11a == operatingBand)
2375 sap_sort_chl_weight_ht40_5_g(pSpectInfoParams);
2376 else {
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002377 sap_sort_chl_weight_ht40_24_g(pSpectInfoParams, domain);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002378 sap_sort_chl_weight_ht40_5_g(pSpectInfoParams);
2379 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002380 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002381 case CH_WIDTH_80MHZ:
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07002382 case CH_WIDTH_80P80MHZ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002383 sap_sort_chl_weight_ht80(pSpectInfoParams);
2384 break;
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07002385 case CH_WIDTH_160MHZ:
2386 sap_sort_chl_weight_vht160(pSpectInfoParams);
2387 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002388 case CH_WIDTH_20MHZ:
2389 default:
2390 /* Sorting the channels as per weights as 20MHz channels */
2391 sap_sort_chl_weight(pSpectInfoParams);
2392 }
2393
2394#else
2395 /* Sorting the channels as per weights */
2396 for (i = 0; i < SPECT_24GHZ_CH_COUNT; i++) {
2397 minWeightIndex = i;
2398 for (j = i + 1; j < SPECT_24GHZ_CH_COUNT; j++) {
2399 if (pSpectCh[j].weight <
2400 pSpectCh[minWeightIndex].weight) {
2401 minWeightIndex = j;
2402 }
2403 }
2404 if (minWeightIndex != i) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302405 qdf_mem_copy(&temp, &pSpectCh[minWeightIndex],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002406 sizeof(*pSpectCh));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302407 qdf_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002408 sizeof(*pSpectCh));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302409 qdf_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002410 }
2411 }
2412#endif
2413
2414 /* For testing */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302415 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002416 "In %s, Sorted Spectrum Channels Weight", __func__);
2417 pSpectCh = pSpectInfoParams->pSpectCh;
2418 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302419 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002420 "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d",
2421 __func__, pSpectCh->chNum, pSpectCh->weight,
2422 pSpectCh->rssiAgr, pSpectCh->bssCount);
2423 pSpectCh++;
2424 }
2425
2426}
2427
Naveen Rawatbec64d92017-09-13 14:35:21 -07002428/**
2429 * sap_is_ch_non_overlap() - returns true if non-overlapping channel
2430 * @sap_ctx: Sap context
2431 * @ch: channel number
2432 *
2433 * Returns: true if non-overlapping (1, 6, 11) channel, false otherwise
2434 */
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -07002435static bool sap_is_ch_non_overlap(struct sap_context *sap_ctx, uint16_t ch)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002436{
Naveen Rawatbec64d92017-09-13 14:35:21 -07002437 if (sap_ctx->enableOverLapCh)
Srinivas Girigowda74a66d62017-06-21 23:28:25 -07002438 return true;
Naveen Rawatbec64d92017-09-13 14:35:21 -07002439
2440 if ((ch == CHANNEL_1) || (ch == CHANNEL_6) || (ch == CHANNEL_11))
Srinivas Girigowda74a66d62017-06-21 23:28:25 -07002441 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002442
Srinivas Girigowda74a66d62017-06-21 23:28:25 -07002443 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002444}
2445
Dustin Brown0ce56d32016-10-17 16:18:03 -07002446#ifdef FEATURE_WLAN_CH_AVOID
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002447/**
2448 * sap_select_channel_no_scan_result() - select SAP channel when no scan results
2449 * are available.
2450 * @sap_ctx: Sap context
2451 *
2452 * Returns: channel number if success, 0 otherwise
2453 */
Kondabattini, Ganesh13bb4b12016-09-04 16:16:53 +05302454static uint8_t sap_select_channel_no_scan_result(tHalHandle hal,
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -07002455 struct sap_context *sap_ctx)
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002456{
Mohit Khanna841044f2016-03-25 16:16:24 -07002457 enum channel_state ch_type;
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002458 uint8_t i, first_safe_ch_in_range = SAP_CHANNEL_NOT_SELECTED;
Kondabattini, Ganesh13bb4b12016-09-04 16:16:53 +05302459 uint32_t dfs_master_cap_enabled;
Dustin Brown0ce56d32016-10-17 16:18:03 -07002460 uint32_t start_ch_num = sap_ctx->acs_cfg->start_ch;
2461 uint32_t end_ch_num = sap_ctx->acs_cfg->end_ch;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002462 tpAniSirGlobal mac_ctx = NULL;
2463
2464 mac_ctx = PMAC_STRUCT(hal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002465
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002466 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
2467 FL("start - end: %d - %d"), start_ch_num, end_ch_num);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002468
Kondabattini, Ganesh13bb4b12016-09-04 16:16:53 +05302469 sme_cfg_get_int(hal, WNI_CFG_DFS_MASTER_ENABLED,
2470 &dfs_master_cap_enabled);
2471
2472 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
2473 "%s: dfs_master %x", __func__, dfs_master_cap_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002474
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002475 /* get a channel in PCL and within the range */
2476 for (i = 0; i < sap_ctx->acs_cfg->pcl_ch_count; i++) {
2477 if ((sap_ctx->acs_cfg->pcl_channels[i] < start_ch_num) ||
2478 (sap_ctx->acs_cfg->pcl_channels[i] > end_ch_num))
2479 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002480
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002481 first_safe_ch_in_range = sap_ctx->acs_cfg->pcl_channels[i];
2482 break;
2483 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002484
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002485 if (SAP_CHANNEL_NOT_SELECTED != first_safe_ch_in_range)
2486 return first_safe_ch_in_range;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002487
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002488 for (i = 0; i < NUM_CHANNELS; i++) {
2489 if ((safe_channels[i].channelNumber < start_ch_num) ||
2490 (safe_channels[i].channelNumber > end_ch_num))
2491 continue;
2492
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002493 ch_type = wlan_reg_get_channel_state(mac_ctx->pdev,
2494 safe_channels[i].channelNumber);
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002495
2496 if ((ch_type == CHANNEL_STATE_DISABLE) ||
2497 (ch_type == CHANNEL_STATE_INVALID))
2498 continue;
Kondabattini, Ganesh13bb4b12016-09-04 16:16:53 +05302499 if ((!dfs_master_cap_enabled) &&
2500 (CHANNEL_STATE_DFS == ch_type)) {
2501 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
2502 "%s: DFS master mode disabled. Skip DFS channel %d",
2503 __func__, safe_channels[i].channelNumber);
2504 continue;
2505 }
Agrawal Ashish65634612016-08-18 13:24:32 +05302506 if ((sap_ctx->dfs_mode == ACS_DFS_MODE_DISABLE) &&
2507 (CHANNEL_STATE_DFS == ch_type))
2508 continue;
Kondabattini, Ganesh13bb4b12016-09-04 16:16:53 +05302509
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002510 if (safe_channels[i].isSafe == true) {
2511 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
2512 FL("channel %d in the configuration is safe"),
2513 safe_channels[i].channelNumber);
2514 first_safe_ch_in_range = safe_channels[i].channelNumber;
2515 break;
2516 }
2517
2518 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
2519 FL("channel %d in the configuration is unsafe"),
2520 safe_channels[i].channelNumber);
2521 }
2522
2523 /* if no channel selected return SAP_CHANNEL_NOT_SELECTED */
2524 return first_safe_ch_in_range;
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002525}
Dustin Brown0ce56d32016-10-17 16:18:03 -07002526#else
2527static uint8_t sap_select_channel_no_scan_result(tHalHandle hal,
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -07002528 struct sap_context *sap_ctx)
Dustin Brown0ce56d32016-10-17 16:18:03 -07002529{
2530 uint32_t start_ch_num = sap_ctx->acs_cfg->start_ch;
2531
2532 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
2533 FL("start - end: %d - %d"),
2534 start_ch_num,
2535 sap_ctx->acs_cfg->end_ch);
2536
2537 sap_ctx->acs_cfg->pri_ch = start_ch_num;
2538 sap_ctx->acs_cfg->ht_sec_ch = 0;
2539
2540 /* pick the first channel in configured range */
2541 return start_ch_num;
2542}
2543#endif /* FEATURE_WLAN_CH_AVOID */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002544
2545/**
2546 * sap_select_channel() - select SAP channel
2547 * @hal: Pointer to HAL handle
2548 * @sap_ctx: Sap context
2549 * @scan_result: Pointer to tScanResultHandle
2550 *
2551 * Runs a algorithm to select the best channel to operate in based on BSS
2552 * rssi and bss count on each channel
2553 *
2554 * Returns: channel number if success, 0 otherwise
2555 */
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -07002556uint8_t sap_select_channel(tHalHandle hal, struct sap_context *sap_ctx,
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002557 tScanResultHandle scan_result)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002558{
2559 /* DFS param object holding all the data req by the algo */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002560 tSapChSelSpectInfo spect_info_obj = { NULL, 0 };
2561 tSapChSelSpectInfo *spect_info = &spect_info_obj;
2562 uint8_t best_ch_num = SAP_CHANNEL_NOT_SELECTED;
bingse2782382017-03-23 10:34:52 +08002563 uint32_t ht40plus2gendch = 0;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002564 v_REGDOMAIN_t domain;
Arif Hussain21ad4342017-12-21 12:00:54 -08002565 uint8_t country[CDS_COUNTRY_CODE_LEN + 1];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002566#ifdef SOFTAP_CHANNEL_RANGE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002567 uint8_t count;
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002568 uint32_t start_ch_num, end_ch_num, tmp_ch_num, operating_band = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002569#endif
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002570 tpAniSirGlobal mac_ctx;
2571
2572 mac_ctx = PMAC_STRUCT(hal);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302573 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002574 "In %s, Running SAP Ch Select", __func__);
2575
2576#ifdef FEATURE_WLAN_CH_AVOID
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002577 sap_update_unsafe_channel_list(hal, sap_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002578#endif
2579
gaoleze5108942017-03-31 16:56:42 +08002580 /*
2581 * If ACS weight is not enabled on noise_floor/channel_free/tx_power,
2582 * then skip acs process if no bss found.
2583 */
2584 if (NULL == scan_result &&
2585 !(sap_ctx->auto_channel_select_weight & 0xffff00)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302586 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002587 FL("No external AP present"));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002588
2589#ifndef SOFTAP_CHANNEL_RANGE
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002590 return SAP_CHANNEL_NOT_SELECTED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002591#else
Kondabattini, Ganesh13bb4b12016-09-04 16:16:53 +05302592 return sap_select_channel_no_scan_result(hal, sap_ctx);
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002593#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002594 }
2595
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002596 /* Initialize the structure pointed by spect_info */
Srinivas Girigowda74a66d62017-06-21 23:28:25 -07002597 if (sap_chan_sel_init(hal, spect_info, sap_ctx) != true) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302598 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR,
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002599 FL("Ch Select initialization failed"));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002600 return SAP_CHANNEL_NOT_SELECTED;
2601 }
2602 /* Compute the weight of the entire spectrum in the operating band */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002603 sap_compute_spect_weight(spect_info, hal, scan_result, sap_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002604
2605#ifdef FEATURE_AP_MCC_CH_AVOIDANCE
2606 /* process avoid channel IE to collect all channels to avoid */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002607 sap_process_avoid_ie(hal, sap_ctx, scan_result, spect_info);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002608#endif /* FEATURE_AP_MCC_CH_AVOIDANCE */
2609
Paul Zhang0f85b412018-01-18 19:14:51 +08002610 wlan_reg_read_current_country(mac_ctx->psoc, country);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002611 wlan_reg_get_domain_from_country_code(&domain, country, SOURCE_DRIVER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002612#ifdef SOFTAP_CHANNEL_RANGE
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002613 start_ch_num = sap_ctx->acs_cfg->start_ch;
2614 end_ch_num = sap_ctx->acs_cfg->end_ch;
2615 SET_ACS_BAND(operating_band, sap_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002616
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002617 sap_ctx->acsBestChannelInfo.channelNum = 0;
2618 sap_ctx->acsBestChannelInfo.weight = SAP_ACS_WEIGHT_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002619
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002620 /* Sort the ch lst as per the computed weights, lesser weight first. */
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002621 sap_sort_chl_weight_all(sap_ctx, spect_info, operating_band, domain);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002622
2623 /*Loop till get the best channel in the given range */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002624 for (count = 0; count < spect_info->numSpectChans; count++) {
2625 if ((start_ch_num > spect_info->pSpectCh[count].chNum) ||
2626 (end_ch_num < spect_info->pSpectCh[count].chNum))
2627 continue;
2628
2629 if (best_ch_num == SAP_CHANNEL_NOT_SELECTED) {
2630 best_ch_num = spect_info->pSpectCh[count].chNum;
2631 /* check if best_ch_num is in preferred channel list */
2632 best_ch_num =
2633 sap_select_preferred_channel_from_channel_list(
2634 best_ch_num, sap_ctx, spect_info);
2635 /* if not in preferred ch lst, go to nxt best ch */
2636 if (best_ch_num == SAP_CHANNEL_NOT_SELECTED)
2637 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002638
2639#ifdef FEATURE_AP_MCC_CH_AVOIDANCE
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002640 /*
2641 * Weight of the channels(device's AP is operating)
2642 * increased to MAX+1 so that they will be choosen only
2643 * when there is no other best channel to choose
2644 */
2645 if (sap_check_in_avoid_ch_list(sap_ctx, best_ch_num)) {
2646 best_ch_num = SAP_CHANNEL_NOT_SELECTED;
2647 continue;
2648 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002649#endif
2650
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002651 sap_ctx->acsBestChannelInfo.channelNum = best_ch_num;
2652 sap_ctx->acsBestChannelInfo.weight =
2653 spect_info->pSpectCh[count].weight_copy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002654 }
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002655
2656 if (best_ch_num == SAP_CHANNEL_NOT_SELECTED)
2657 continue;
2658
Tushnim Bhattacharyya03103fd2017-06-23 10:48:52 -07002659 if (operating_band != eCSR_DOT11_MODE_11g) {
2660 QDF_TRACE(QDF_MODULE_ID_SAP,
2661 QDF_TRACE_LEVEL_INFO_HIGH,
2662 "operating_band %d", operating_band);
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002663 continue;
Tushnim Bhattacharyya03103fd2017-06-23 10:48:52 -07002664 }
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002665
2666 /* Give preference to Non-overlap channels */
Naveen Rawatbec64d92017-09-13 14:35:21 -07002667 if (false == sap_is_ch_non_overlap(sap_ctx,
Tushnim Bhattacharyya03103fd2017-06-23 10:48:52 -07002668 spect_info->pSpectCh[count].chNum)) {
2669 QDF_TRACE(QDF_MODULE_ID_SAP,
2670 QDF_TRACE_LEVEL_INFO_HIGH,
Naveen Rawatbec64d92017-09-13 14:35:21 -07002671 FL("ch: %d skipped as its overlapping ch"),
2672 spect_info->pSpectCh[count].chNum);
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002673 continue;
Tushnim Bhattacharyya03103fd2017-06-23 10:48:52 -07002674 }
2675
2676 if (wlan_reg_is_dfs_ch(mac_ctx->pdev,
2677 spect_info->pSpectCh[count].chNum) &&
2678 policy_mgr_disallow_mcc(mac_ctx->psoc,
2679 spect_info->pSpectCh[count].chNum)) {
2680 QDF_TRACE(QDF_MODULE_ID_SAP,
2681 QDF_TRACE_LEVEL_INFO_HIGH,
2682 "No DFS MCC");
2683 continue;
2684 }
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002685
bings14d1d3b2017-08-03 11:14:29 +08002686 if (spect_info->pSpectCh[count].weight_copy >
2687 sap_ctx->acsBestChannelInfo.weight)
2688 continue;
2689
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002690 tmp_ch_num = spect_info->pSpectCh[count].chNum;
gaoleze5108942017-03-31 16:56:42 +08002691 tmp_ch_num = sap_channel_in_acs_channel_list(
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002692 tmp_ch_num, sap_ctx, spect_info);
2693 if (tmp_ch_num == SAP_CHANNEL_NOT_SELECTED)
2694 continue;
2695
2696 best_ch_num = tmp_ch_num;
2697 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002698 }
2699#else
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002700 /* Sort the ch lst as per the computed weights, lesser weight first. */
2701 sap_sort_chl_weight_all(sap_ctx, hal, spect_info);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002702 /* Get the first channel in sorted array as best 20M Channel */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002703 best_ch_num = (uint8_t) spect_info->pSpectCh[0].chNum;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002704 /* Select Best Channel from Channel List if Configured */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002705 best_ch_num = sap_select_preferred_channel_from_channel_list(
2706 best_ch_num, sap_ctx, spect_info);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002707#endif
2708
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002709 /*
2710 * in case the best channel seleted is not in PCL and there is another
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002711 * channel which has same weightage and is in PCL, choose the one in
2712 * PCL
2713 */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002714 for (count = 0; count < spect_info->numSpectChans; count++) {
2715 if (!ch_in_pcl(sap_ctx, spect_info->pSpectCh[count].chNum) ||
2716 (spect_info->pSpectCh[count].weight !=
2717 sap_ctx->acsBestChannelInfo.weight))
2718 continue;
2719
2720 if (sap_select_preferred_channel_from_channel_list(
2721 spect_info->pSpectCh[count].chNum, sap_ctx, spect_info)
2722 == SAP_CHANNEL_NOT_SELECTED)
2723 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002724
2725#ifdef FEATURE_AP_MCC_CH_AVOIDANCE
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002726 if (sap_check_in_avoid_ch_list(sap_ctx, best_ch_num))
2727 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002728#endif
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002729 best_ch_num = spect_info->pSpectCh[count].chNum;
2730 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
2731 FL("change best channel to %d in PCL"), best_ch_num);
2732 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002733 }
2734
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002735 sap_ctx->acs_cfg->pri_ch = best_ch_num;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002736 /* determine secondary channel for 2.4G channel 5, 6, 7 in HT40 */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002737 if ((operating_band != eCSR_DOT11_MODE_11g) ||
2738 (sap_ctx->acs_cfg->ch_width != CH_WIDTH_40MHZ))
2739 goto sap_ch_sel_end;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002740 if (REGDOMAIN_FCC == domain)
bingse2782382017-03-23 10:34:52 +08002741 ht40plus2gendch = HT40PLUS_2G_FCC_CH_END;
2742 else
2743 ht40plus2gendch = HT40PLUS_2G_EURJAP_CH_END;
2744 if ((best_ch_num >= HT40MINUS_2G_CH_START) &&
2745 (best_ch_num <= ht40plus2gendch)) {
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002746 int weight_below, weight_above, i;
2747 tSapSpectChInfo *pspect_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002748
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002749 weight_below = weight_above = SAP_ACS_WEIGHT_MAX;
2750 pspect_info = spect_info->pSpectCh;
2751 for (i = 0; i < spect_info->numSpectChans; i++) {
2752 if (pspect_info[i].chNum == (best_ch_num - 4))
2753 weight_below = pspect_info[i].weight;
2754 if (pspect_info[i].chNum == (best_ch_num + 4))
2755 weight_above = pspect_info[i].weight;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002756 }
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002757
2758 if (weight_below < weight_above)
2759 sap_ctx->acs_cfg->ht_sec_ch =
2760 sap_ctx->acs_cfg->pri_ch - 4;
2761 else
2762 sap_ctx->acs_cfg->ht_sec_ch =
2763 sap_ctx->acs_cfg->pri_ch + 4;
2764 } else if (best_ch_num >= 1 && best_ch_num <= 4) {
2765 sap_ctx->acs_cfg->ht_sec_ch = sap_ctx->acs_cfg->pri_ch + 4;
bingse2782382017-03-23 10:34:52 +08002766 } else if (best_ch_num >= ht40plus2gendch && best_ch_num <=
2767 HT40MINUS_2G_CH_END) {
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002768 sap_ctx->acs_cfg->ht_sec_ch = sap_ctx->acs_cfg->pri_ch - 4;
2769 } else if (best_ch_num == 14) {
2770 sap_ctx->acs_cfg->ht_sec_ch = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002771 }
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002772 sap_ctx->secondary_ch = sap_ctx->acs_cfg->ht_sec_ch;
2773
2774sap_ch_sel_end:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002775 /* Free all the allocated memory */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002776 sap_chan_sel_exit(spect_info);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002777
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302778 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002779 FL("Running SAP Ch select Completed, Ch=%d"), best_ch_num);
2780 if (best_ch_num > 0 && best_ch_num <= 252)
2781 return best_ch_num;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002782 else
2783 return SAP_CHANNEL_NOT_SELECTED;
2784}