Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1 | /* |
gaurank kathpalia | 1dea75b | 2019-01-10 13:53:43 +0530 | [diff] [blame] | 2 | * Copyright (c) 2012-2019 The Linux Foundation. All rights reserved. |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 3 | * |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all |
| 7 | * copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 10 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 11 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 12 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 13 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 14 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 15 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 16 | * PERFORMANCE OF THIS SOFTWARE. |
| 17 | */ |
| 18 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 19 | /*=========================================================================== |
| 20 | |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 21 | s a p C h S e l e c t . C |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 22 | OVERVIEW: |
| 23 | |
| 24 | This software unit holds the implementation of the WLAN SAP modules |
| 25 | functions for channel selection. |
| 26 | |
| 27 | DEPENDENCIES: |
| 28 | |
| 29 | Are listed for each API below. |
| 30 | ===========================================================================*/ |
| 31 | |
| 32 | /*-------------------------------------------------------------------------- |
| 33 | Include Files |
| 34 | ------------------------------------------------------------------------*/ |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 35 | #include "qdf_trace.h" |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 36 | #include "csr_api.h" |
| 37 | #include "sme_api.h" |
| 38 | #include "sap_ch_select.h" |
| 39 | #include "sap_internal.h" |
| 40 | #ifdef ANI_OS_TYPE_QNX |
| 41 | #include "stdio.h" |
| 42 | #endif |
| 43 | #ifdef FEATURE_AP_MCC_CH_AVOIDANCE |
| 44 | #include "lim_utils.h" |
| 45 | #include "parser_api.h" |
jiad | 391c528 | 2018-11-26 16:21:04 +0800 | [diff] [blame] | 46 | #include <wlan_utility.h> |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 47 | #endif /* FEATURE_AP_MCC_CH_AVOIDANCE */ |
Deepthi Gowri | 48b8933 | 2016-08-30 18:43:05 +0530 | [diff] [blame] | 48 | #include "cds_utils.h" |
Yuanyuan Liu | 0e0aa93 | 2016-05-12 10:17:58 -0700 | [diff] [blame] | 49 | #include "pld_common.h" |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 50 | #include "wlan_reg_services_api.h" |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 51 | #include <wlan_scan_utils_api.h> |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 52 | |
| 53 | /*-------------------------------------------------------------------------- |
| 54 | Function definitions |
| 55 | --------------------------------------------------------------------------*/ |
| 56 | |
| 57 | /*-------------------------------------------------------------------------- |
| 58 | Defines |
| 59 | --------------------------------------------------------------------------*/ |
| 60 | #define SAP_DEBUG |
| 61 | |
| 62 | #define IS_RSSI_VALID(extRssi, rssi) \ |
| 63 | ( \ |
| 64 | ((extRssi < rssi) ? true : false) \ |
| 65 | ) |
| 66 | |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 67 | #define SET_ACS_BAND(acs_band, sap_ctx) \ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 68 | { \ |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 69 | if (sap_ctx->acs_cfg->start_ch <= 14 && \ |
| 70 | sap_ctx->acs_cfg->end_ch <= 14) \ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 71 | acs_band = eCSR_DOT11_MODE_11g; \ |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 72 | else if (sap_ctx->acs_cfg->start_ch >= 14)\ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 73 | acs_band = eCSR_DOT11_MODE_11a; \ |
| 74 | else \ |
| 75 | acs_band = eCSR_DOT11_MODE_abg; \ |
| 76 | } |
| 77 | |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 78 | #define ACS_WEIGHT_AMOUNT_LOCAL 240 |
| 79 | |
| 80 | #define ACS_WEIGHT_AMOUNT_CONFIG(weights) \ |
| 81 | (((weights) & 0xf) + \ |
| 82 | (((weights) & 0xf0) >> 4) + \ |
| 83 | (((weights) & 0xf00) >> 8) + \ |
| 84 | (((weights) & 0xf000) >> 12) + \ |
| 85 | (((weights) & 0xf0000) >> 16) + \ |
| 86 | (((weights) & 0xf00000) >> 20)) |
| 87 | |
| 88 | /* |
| 89 | * LSH/RSH 4 to enhance the accurate since |
| 90 | * need to do modulation to ACS_WEIGHT_AMOUNT_LOCAL. |
| 91 | */ |
| 92 | #define ACS_WEIGHT_COMPUTE(weights, weight, factor, base) \ |
| 93 | (((((((((weight) << 4) * ACS_WEIGHT_AMOUNT_LOCAL * (factor)) + \ |
| 94 | (ACS_WEIGHT_AMOUNT_CONFIG((weights)) >> 1)) / \ |
| 95 | ACS_WEIGHT_AMOUNT_CONFIG((weights))) + \ |
| 96 | ((base) >> 1)) / (base)) + 8) >> 4) |
| 97 | |
| 98 | #define ACS_WEIGHT_CFG_TO_LOCAL(weights, weight) \ |
| 99 | (((((((weight) << 4) * ACS_WEIGHT_AMOUNT_LOCAL) + \ |
| 100 | (ACS_WEIGHT_AMOUNT_CONFIG((weights)) >> 1)) / \ |
| 101 | ACS_WEIGHT_AMOUNT_CONFIG((weights))) + 8) >> 4) |
| 102 | |
| 103 | #define ACS_WEIGHT_SOFTAP_RSSI_CFG(weights) \ |
| 104 | ((weights) & 0xf) |
| 105 | |
| 106 | #define ACS_WEIGHT_SOFTAP_COUNT_CFG(weights) \ |
| 107 | (((weights) & 0xf0) >> 4) |
| 108 | |
| 109 | #define ACS_WEIGHT_SOFTAP_NOISE_FLOOR_CFG(weights) \ |
| 110 | (((weights) & 0xf00) >> 8) |
| 111 | |
| 112 | #define ACS_WEIGHT_SOFTAP_CHANNEL_FREE_CFG(weights) \ |
| 113 | (((weights) & 0xf000) >> 12) |
| 114 | |
| 115 | #define ACS_WEIGHT_SOFTAP_TX_POWER_RANGE_CFG(weights) \ |
| 116 | (((weights) & 0xf0000) >> 16) |
| 117 | |
| 118 | #define ACS_WEIGHT_SOFTAP_TX_POWER_THROUGHPUT_CFG(weights) \ |
| 119 | (((weights) & 0xf00000) >> 20) |
| 120 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 121 | #ifdef FEATURE_WLAN_CH_AVOID |
Amar Singhal | b8d4f15 | 2016-02-10 10:21:43 -0800 | [diff] [blame] | 122 | sapSafeChannelType safe_channels[NUM_CHANNELS] = { |
| 123 | {1, true}, |
| 124 | {2, true}, |
| 125 | {3, true}, |
| 126 | {4, true}, |
| 127 | {5, true}, |
| 128 | {6, true}, |
| 129 | {7, true}, |
| 130 | {8, true}, |
| 131 | {9, true}, |
| 132 | {10, true}, |
| 133 | {11, true}, |
| 134 | {12, true}, |
| 135 | {13, true}, |
| 136 | {14, true}, |
| 137 | {36, true}, |
| 138 | {40, true}, |
| 139 | {44, true}, |
| 140 | {48, true}, |
| 141 | {52, true}, |
| 142 | {56, true}, |
| 143 | {60, true}, |
| 144 | {64, true}, |
| 145 | {100, true}, |
| 146 | {104, true}, |
| 147 | {108, true}, |
| 148 | {112, true}, |
| 149 | {116, true}, |
| 150 | {120, true}, |
| 151 | {124, true}, |
| 152 | {128, true}, |
| 153 | {132, true}, |
| 154 | {136, true}, |
| 155 | {140, true}, |
| 156 | {144, true}, |
| 157 | {149, true}, |
| 158 | {153, true}, |
| 159 | {157, true}, |
| 160 | {161, true}, |
| 161 | {165, true}, |
Kiran Kumar Lokere | 1a43bcf | 2018-05-15 15:51:58 -0700 | [diff] [blame] | 162 | {169, true}, |
| 163 | {173, true}, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 164 | }; |
| 165 | #endif |
| 166 | |
| 167 | typedef struct { |
| 168 | uint16_t chStartNum; |
| 169 | uint32_t weight; |
| 170 | } sapAcsChannelInfo; |
| 171 | |
| 172 | sapAcsChannelInfo acs_ht40_channels5_g[] = { |
| 173 | {36, SAP_ACS_WEIGHT_MAX}, |
| 174 | {44, SAP_ACS_WEIGHT_MAX}, |
| 175 | {52, SAP_ACS_WEIGHT_MAX}, |
| 176 | {60, SAP_ACS_WEIGHT_MAX}, |
| 177 | {100, SAP_ACS_WEIGHT_MAX}, |
| 178 | {108, SAP_ACS_WEIGHT_MAX}, |
| 179 | {116, SAP_ACS_WEIGHT_MAX}, |
| 180 | {124, SAP_ACS_WEIGHT_MAX}, |
| 181 | {132, SAP_ACS_WEIGHT_MAX}, |
| 182 | {140, SAP_ACS_WEIGHT_MAX}, |
| 183 | {149, SAP_ACS_WEIGHT_MAX}, |
| 184 | {157, SAP_ACS_WEIGHT_MAX}, |
| 185 | }; |
| 186 | |
| 187 | sapAcsChannelInfo acs_ht80_channels[] = { |
| 188 | {36, SAP_ACS_WEIGHT_MAX}, |
| 189 | {52, SAP_ACS_WEIGHT_MAX}, |
| 190 | {100, SAP_ACS_WEIGHT_MAX}, |
| 191 | {116, SAP_ACS_WEIGHT_MAX}, |
| 192 | {132, SAP_ACS_WEIGHT_MAX}, |
| 193 | {149, SAP_ACS_WEIGHT_MAX}, |
| 194 | }; |
| 195 | |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 196 | sapAcsChannelInfo acs_vht160_channels[] = { |
| 197 | {36, SAP_ACS_WEIGHT_MAX}, |
| 198 | {100, SAP_ACS_WEIGHT_MAX}, |
| 199 | }; |
| 200 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 201 | sapAcsChannelInfo acs_ht40_channels24_g[] = { |
| 202 | {1, SAP_ACS_WEIGHT_MAX}, |
| 203 | {2, SAP_ACS_WEIGHT_MAX}, |
| 204 | {3, SAP_ACS_WEIGHT_MAX}, |
| 205 | {4, SAP_ACS_WEIGHT_MAX}, |
| 206 | {9, SAP_ACS_WEIGHT_MAX}, |
| 207 | }; |
| 208 | |
| 209 | #define CHANNEL_165 165 |
| 210 | |
| 211 | /* rssi discount for channels in PCL */ |
| 212 | #define PCL_RSSI_DISCOUNT 10 |
| 213 | |
| 214 | #ifdef FEATURE_AP_MCC_CH_AVOIDANCE |
| 215 | /** |
| 216 | * sap_check_n_add_channel() - checks and add given channel in sap context's |
| 217 | * avoid_channels_info struct |
| 218 | * @sap_ctx: sap context. |
| 219 | * @new_channel: channel to be added to sap_ctx's avoid ch info |
| 220 | * |
| 221 | * sap_ctx contains sap_avoid_ch_info strcut containing the list of channels on |
| 222 | * which MDM device's AP with MCC was detected. This function will add channels |
| 223 | * to that list after checking for duplicates. |
| 224 | * |
| 225 | * Return: true: if channel was added or already present |
| 226 | * else false: if channel list was already full. |
| 227 | */ |
Tang Yingying | 523322d | 2017-01-17 23:28:43 +0800 | [diff] [blame] | 228 | static bool |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 229 | sap_check_n_add_channel(struct sap_context *sap_ctx, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 230 | uint8_t new_channel) |
| 231 | { |
| 232 | uint8_t i = 0; |
| 233 | struct sap_avoid_channels_info *ie_info = |
| 234 | &sap_ctx->sap_detected_avoid_ch_ie; |
| 235 | |
| 236 | for (i = 0; i < sizeof(ie_info->channels); i++) { |
| 237 | if (ie_info->channels[i] == new_channel) |
| 238 | break; |
| 239 | |
| 240 | if (ie_info->channels[i] == 0) { |
| 241 | ie_info->channels[i] = new_channel; |
| 242 | break; |
| 243 | } |
| 244 | } |
| 245 | if (i == sizeof(ie_info->channels)) |
| 246 | return false; |
| 247 | else |
| 248 | return true; |
| 249 | } |
| 250 | /** |
| 251 | * sap_check_n_add_overlapped_chnls() - checks & add overlapped channels |
| 252 | * to primary channel in 2.4Ghz band. |
| 253 | * @sap_ctx: sap context. |
| 254 | * @primary_chnl: primary channel to be avoided. |
| 255 | * |
| 256 | * sap_ctx contains sap_avoid_ch_info struct containing the list of channels on |
| 257 | * which MDM device's AP with MCC was detected. This function will add channels |
| 258 | * to that list after checking for duplicates. |
| 259 | * |
| 260 | * Return: true: if channel was added or already present |
| 261 | * else false: if channel list was already full. |
| 262 | */ |
| 263 | static bool |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 264 | sap_check_n_add_overlapped_chnls(struct sap_context *sap_ctx, |
| 265 | uint8_t primary_channel) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 266 | { |
| 267 | uint8_t i = 0, j = 0, upper_chnl = 0, lower_chnl = 0; |
| 268 | struct sap_avoid_channels_info *ie_info = |
| 269 | &sap_ctx->sap_detected_avoid_ch_ie; |
| 270 | /* |
| 271 | * if primary channel less than channel 1 or out of 2g band then |
| 272 | * no further process is required. return true in this case. |
| 273 | */ |
| 274 | if (primary_channel < CHANNEL_1 || primary_channel > CHANNEL_14) |
| 275 | return true; |
| 276 | |
| 277 | /* lower channel is one channel right before primary channel */ |
| 278 | lower_chnl = primary_channel - 1; |
| 279 | /* upper channel is one channel right after primary channel */ |
| 280 | upper_chnl = primary_channel + 1; |
| 281 | |
| 282 | /* lower channel needs to be non-zero, zero is not valid channel */ |
| 283 | if (lower_chnl > (CHANNEL_1 - 1)) { |
| 284 | for (i = 0; i < sizeof(ie_info->channels); i++) { |
| 285 | if (ie_info->channels[i] == lower_chnl) |
| 286 | break; |
| 287 | if (ie_info->channels[i] == 0) { |
| 288 | ie_info->channels[i] = lower_chnl; |
| 289 | break; |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | /* upper channel needs to be atleast last channel in 2.4Ghz band */ |
| 294 | if (upper_chnl < (CHANNEL_14 + 1)) { |
| 295 | for (j = 0; j < sizeof(ie_info->channels); j++) { |
| 296 | if (ie_info->channels[j] == upper_chnl) |
| 297 | break; |
| 298 | if (ie_info->channels[j] == 0) { |
| 299 | ie_info->channels[j] = upper_chnl; |
| 300 | break; |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | if (i == sizeof(ie_info->channels) || j == sizeof(ie_info->channels)) |
| 305 | return false; |
| 306 | else |
| 307 | return true; |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * sap_process_avoid_ie() - processes the detected Q2Q IE |
| 312 | * context's avoid_channels_info struct |
Jeff Johnson | 7730fbb | 2018-11-08 13:48:27 -0800 | [diff] [blame] | 313 | * @mac_handle: opaque handle to the MAC context |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 314 | * @sap_ctx: sap context. |
| 315 | * @scan_result: scan results for ACS scan. |
| 316 | * @spect_info: spectrum weights array to update |
| 317 | * |
| 318 | * Detection of Q2Q IE indicates presence of another MDM device with its AP |
| 319 | * operating in MCC mode. This function parses the scan results and processes |
| 320 | * the Q2Q IE if found. It then extracts the channels and populates them in |
| 321 | * sap_ctx struct. It also increases the weights of those channels so that |
| 322 | * ACS logic will avoid those channels in its selection algorithm. |
| 323 | * |
| 324 | * Return: void |
| 325 | */ |
Jeff Johnson | 7730fbb | 2018-11-08 13:48:27 -0800 | [diff] [blame] | 326 | static void sap_process_avoid_ie(mac_handle_t mac_handle, |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 327 | struct sap_context *sap_ctx, |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 328 | qdf_list_t *scan_list, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 329 | tSapChSelSpectInfo *spect_info) |
| 330 | { |
jiad | 391c528 | 2018-11-26 16:21:04 +0800 | [diff] [blame] | 331 | const uint8_t *temp_ptr = NULL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 332 | uint8_t i = 0; |
| 333 | struct sAvoidChannelIE *avoid_ch_ie; |
Jeff Johnson | c59ef8b | 2018-12-02 12:01:21 -0800 | [diff] [blame] | 334 | struct mac_context *mac_ctx = NULL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 335 | tSapSpectChInfo *spect_ch = NULL; |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 336 | qdf_list_node_t *cur_lst = NULL, *next_lst = NULL; |
| 337 | struct scan_cache_node *cur_node = NULL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 338 | |
Jeff Johnson | a0619e4 | 2018-11-28 17:43:00 -0800 | [diff] [blame] | 339 | mac_ctx = MAC_CONTEXT(mac_handle); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 340 | spect_ch = spect_info->pSpectCh; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 341 | |
Rachit Kankane | 2dba675 | 2019-05-20 14:55:31 +0530 | [diff] [blame] | 342 | if (scan_list) |
| 343 | qdf_list_peek_front(scan_list, &cur_lst); |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 344 | while (cur_lst) { |
| 345 | cur_node = qdf_container_of(cur_lst, struct scan_cache_node, |
| 346 | node); |
| 347 | |
Naveen Rawat | 08db88f | 2017-09-08 15:07:48 -0700 | [diff] [blame] | 348 | temp_ptr = wlan_get_vendor_ie_ptr_from_oui( |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 349 | SIR_MAC_QCOM_VENDOR_OUI, |
| 350 | SIR_MAC_QCOM_VENDOR_SIZE, |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 351 | util_scan_entry_ie_data(cur_node->entry), |
| 352 | util_scan_entry_ie_len(cur_node->entry)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 353 | |
| 354 | if (temp_ptr) { |
| 355 | avoid_ch_ie = (struct sAvoidChannelIE *)temp_ptr; |
Will Huang | 55ba104 | 2017-03-22 10:43:30 +0800 | [diff] [blame] | 356 | if (avoid_ch_ie->type != |
| 357 | QCOM_VENDOR_IE_MCC_AVOID_CH) { |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 358 | qdf_list_peek_next(scan_list, |
| 359 | cur_lst, &next_lst); |
| 360 | cur_lst = next_lst; |
| 361 | next_lst = NULL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 362 | continue; |
Will Huang | 55ba104 | 2017-03-22 10:43:30 +0800 | [diff] [blame] | 363 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 364 | |
| 365 | sap_ctx->sap_detected_avoid_ch_ie.present = 1; |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 366 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 367 | QDF_TRACE_LEVEL_DEBUG, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 368 | "Q2Q IE - avoid ch %d", |
| 369 | avoid_ch_ie->channel); |
| 370 | /* add this channel to to_avoid channel list */ |
| 371 | sap_check_n_add_channel(sap_ctx, |
| 372 | avoid_ch_ie->channel); |
| 373 | sap_check_n_add_overlapped_chnls(sap_ctx, |
| 374 | avoid_ch_ie->channel); |
| 375 | /* |
| 376 | * Mark weight of these channel present in IE to MAX |
| 377 | * so that ACS logic will to avoid thse channels |
| 378 | */ |
| 379 | for (i = 0; i < spect_info->numSpectChans; i++) |
| 380 | if (spect_ch[i].chNum == avoid_ch_ie->channel) { |
| 381 | /* |
| 382 | * weight is set more than max so that, |
| 383 | * in the case of other channels being |
| 384 | * assigned max weight due to noise, |
| 385 | * they may be preferred over channels |
| 386 | * with Q2Q IE. |
| 387 | */ |
| 388 | spect_ch[i].weight = SAP_ACS_WEIGHT_MAX + 1; |
| 389 | spect_ch[i].weight_copy = |
| 390 | SAP_ACS_WEIGHT_MAX + 1; |
| 391 | break; |
| 392 | } |
| 393 | } /* if (temp_ptr) */ |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 394 | |
| 395 | qdf_list_peek_next(scan_list, cur_lst, &next_lst); |
| 396 | cur_lst = next_lst; |
| 397 | next_lst = NULL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | #endif /* FEATURE_AP_MCC_CH_AVOIDANCE */ |
| 401 | |
| 402 | #ifdef FEATURE_WLAN_CH_AVOID |
| 403 | /*========================================================================== |
| 404 | FUNCTION sap_update_unsafe_channel_list |
| 405 | |
| 406 | DESCRIPTION |
| 407 | Function Undate unsafe channel list table |
| 408 | |
| 409 | DEPENDENCIES |
| 410 | NA. |
| 411 | |
| 412 | IN |
| 413 | SapContext pointer |
| 414 | |
| 415 | RETURN VALUE |
| 416 | NULL |
| 417 | ============================================================================*/ |
Jeff Johnson | b91e2d9 | 2019-03-26 09:51:30 -0700 | [diff] [blame] | 418 | static void sap_update_unsafe_channel_list(mac_handle_t mac_handle, |
| 419 | struct sap_context *sap_ctx) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 420 | { |
| 421 | uint16_t i, j; |
Amar Singhal | b8d4f15 | 2016-02-10 10:21:43 -0800 | [diff] [blame] | 422 | uint16_t unsafe_channel_list[NUM_CHANNELS]; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 423 | uint16_t unsafe_channel_count = 0; |
Jeff Johnson | c59ef8b | 2018-12-02 12:01:21 -0800 | [diff] [blame] | 424 | struct mac_context *mac_ctx = NULL; |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 425 | |
Yuanyuan Liu | 0e0aa93 | 2016-05-12 10:17:58 -0700 | [diff] [blame] | 426 | qdf_device_t qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 427 | |
Yuanyuan Liu | 9736118 | 2016-06-06 09:38:04 -0700 | [diff] [blame] | 428 | if (!qdf_ctx) { |
| 429 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_FATAL, |
| 430 | "qdf_ctx is NULL"); |
| 431 | return; |
| 432 | } |
Jeff Johnson | a0619e4 | 2018-11-28 17:43:00 -0800 | [diff] [blame] | 433 | mac_ctx = MAC_CONTEXT(mac_handle); |
Yuanyuan Liu | 9736118 | 2016-06-06 09:38:04 -0700 | [diff] [blame] | 434 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 435 | /* Flush, default set all channel safe */ |
Amar Singhal | b8d4f15 | 2016-02-10 10:21:43 -0800 | [diff] [blame] | 436 | for (i = 0; i < NUM_CHANNELS; i++) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 437 | safe_channels[i].isSafe = true; |
| 438 | } |
| 439 | |
| 440 | /* Try to find unsafe channel */ |
Ryan Hsu | 4252a2f | 2016-01-05 11:18:24 -0800 | [diff] [blame] | 441 | #if defined(FEATURE_WLAN_STA_AP_MODE_DFS_DISABLE) |
Amar Singhal | b8d4f15 | 2016-02-10 10:21:43 -0800 | [diff] [blame] | 442 | for (i = 0; i < NUM_CHANNELS; i++) { |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 443 | if (sap_ctx->dfs_ch_disable == true) { |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 444 | if (wlan_reg_is_dfs_ch(mac_ctx->pdev, |
| 445 | safe_channels[i].channelNumber)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 446 | safe_channels[i].isSafe = false; |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 447 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 448 | QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 449 | "%s: DFS Ch %d is not safe in" |
| 450 | " Concurrent mode", |
| 451 | __func__, |
| 452 | safe_channels[i].channelNumber); |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | #endif |
Yuanyuan Liu | 0e0aa93 | 2016-05-12 10:17:58 -0700 | [diff] [blame] | 457 | pld_get_wlan_unsafe_channel(qdf_ctx->dev, |
| 458 | unsafe_channel_list, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 459 | &unsafe_channel_count, |
| 460 | sizeof(unsafe_channel_list)); |
| 461 | |
Jingxiang Ge | 37d878c | 2019-01-08 14:43:05 +0800 | [diff] [blame] | 462 | unsafe_channel_count = QDF_MIN(unsafe_channel_count, |
| 463 | (uint16_t)NUM_CHANNELS); |
| 464 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 465 | for (i = 0; i < unsafe_channel_count; i++) { |
Amar Singhal | b8d4f15 | 2016-02-10 10:21:43 -0800 | [diff] [blame] | 466 | for (j = 0; j < NUM_CHANNELS; j++) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 467 | if (safe_channels[j].channelNumber == |
| 468 | unsafe_channel_list[i]) { |
| 469 | /* Found unsafe channel, update it */ |
| 470 | safe_channels[j].isSafe = false; |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 471 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 472 | QDF_TRACE_LEVEL_ERROR, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 473 | FL("CH %d is not safe"), |
| 474 | unsafe_channel_list[i]); |
| 475 | break; |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | return; |
| 481 | } |
Jeff Johnson | b91e2d9 | 2019-03-26 09:51:30 -0700 | [diff] [blame] | 482 | #else |
| 483 | static void sap_update_unsafe_channel_list(mac_handle_t mac_handle, |
| 484 | struct sap_context *sap_ctx) |
| 485 | { |
| 486 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 487 | #endif /* FEATURE_WLAN_CH_AVOID */ |
| 488 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 489 | /** |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 490 | * sap_channel_in_acs_channel_list() - check if channel in acs channel list |
| 491 | * @channel_num: channel to check |
| 492 | * @sap_ctx: struct ptSapContext |
| 493 | * @spect_info_params: strcut tSapChSelSpectInfo |
| 494 | * |
| 495 | * This function checks if specified channel is in the configured ACS channel |
| 496 | * list. |
| 497 | * |
| 498 | * Return: channel number if in acs channel list or SAP_CHANNEL_NOT_SELECTED |
| 499 | */ |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 500 | uint8_t sap_channel_in_acs_channel_list(uint8_t channel_num, |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 501 | struct sap_context *sap_ctx, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 502 | tSapChSelSpectInfo *spect_info_params) |
| 503 | { |
| 504 | uint8_t i = 0; |
| 505 | |
Jeff Johnson | 4cfe6cc | 2019-03-18 13:40:27 -0700 | [diff] [blame] | 506 | if ((!sap_ctx->acs_cfg->ch_list) || |
| 507 | (!spect_info_params)) |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 508 | return channel_num; |
| 509 | |
| 510 | if (channel_num > 0 && channel_num <= 252) { |
| 511 | for (i = 0; i < sap_ctx->acs_cfg->ch_list_count; i++) { |
| 512 | if ((sap_ctx->acs_cfg->ch_list[i]) == channel_num) |
| 513 | return channel_num; |
| 514 | } |
| 515 | return SAP_CHANNEL_NOT_SELECTED; |
| 516 | } else { |
| 517 | return SAP_CHANNEL_NOT_SELECTED; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | /** |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 522 | * sap_select_preferred_channel_from_channel_list() - to calc best cahnnel |
| 523 | * @best_chnl: best channel already calculated among all the chanels |
| 524 | * @sap_ctx: sap context |
| 525 | * @spectinfo_param: Pointer to tSapChSelSpectInfo structure |
| 526 | * |
| 527 | * This function calculates the best channel among the configured channel list. |
| 528 | * If channel list not configured then returns the best channel calculated |
| 529 | * among all the channel list. |
| 530 | * |
| 531 | * Return: uint8_t best channel |
| 532 | */ |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 533 | static |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 534 | uint8_t sap_select_preferred_channel_from_channel_list(uint8_t best_chnl, |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 535 | struct sap_context *sap_ctx, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 536 | tSapChSelSpectInfo *spectinfo_param) |
| 537 | { |
| 538 | uint8_t i = 0; |
Jeff Johnson | c59ef8b | 2018-12-02 12:01:21 -0800 | [diff] [blame] | 539 | struct mac_context *mac_ctx = sme_get_mac_context(); |
Tushnim Bhattacharyya | 518e80f | 2017-08-30 17:35:33 -0700 | [diff] [blame] | 540 | |
Jeff Johnson | 4cfe6cc | 2019-03-18 13:40:27 -0700 | [diff] [blame] | 541 | if (!mac_ctx) { |
Tushnim Bhattacharyya | 518e80f | 2017-08-30 17:35:33 -0700 | [diff] [blame] | 542 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR, |
| 543 | "pmac Global Context is NULL"); |
| 544 | return SAP_CHANNEL_NOT_SELECTED; |
| 545 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 546 | |
| 547 | /* |
| 548 | * If Channel List is not Configured don't do anything |
| 549 | * Else return the Best Channel from the Channel List |
| 550 | */ |
Jeff Johnson | 4cfe6cc | 2019-03-18 13:40:27 -0700 | [diff] [blame] | 551 | if ((!sap_ctx->acs_cfg->ch_list) || |
| 552 | (!spectinfo_param) || |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 553 | (0 == sap_ctx->acs_cfg->ch_list_count)) |
| 554 | return best_chnl; |
| 555 | |
| 556 | if (best_chnl <= 0 || best_chnl > 252) |
| 557 | return SAP_CHANNEL_NOT_SELECTED; |
| 558 | |
| 559 | /* Select the best channel from allowed list */ |
| 560 | for (i = 0; i < sap_ctx->acs_cfg->ch_list_count; i++) { |
Tushnim Bhattacharyya | 518e80f | 2017-08-30 17:35:33 -0700 | [diff] [blame] | 561 | if ((sap_ctx->acs_cfg->ch_list[i] == best_chnl) && |
| 562 | !(wlan_reg_is_dfs_ch(mac_ctx->pdev, best_chnl) && |
| 563 | policy_mgr_disallow_mcc(mac_ctx->psoc, best_chnl))) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 564 | QDF_TRACE(QDF_MODULE_ID_SAP, |
Ravi Joshi | 9788fcd | 2018-02-13 15:12:22 -0800 | [diff] [blame] | 565 | QDF_TRACE_LEVEL_INFO, |
Naveen Rawat | bec64d9 | 2017-09-13 14:35:21 -0700 | [diff] [blame] | 566 | "Best channel so far is: %d", |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 567 | best_chnl); |
| 568 | return best_chnl; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | return SAP_CHANNEL_NOT_SELECTED; |
| 573 | } |
| 574 | |
Jeff Johnson | 7730fbb | 2018-11-08 13:48:27 -0800 | [diff] [blame] | 575 | /** |
| 576 | * sap_chan_sel_init() - Initialize channel select |
| 577 | * @mac_handle: Opaque handle to the global MAC context |
| 578 | * @pSpectInfoParams: Pointer to tSapChSelSpectInfo structure |
| 579 | * @sap_ctx: Pointer to SAP Context |
| 580 | * |
| 581 | * Function sap_chan_sel_init allocates the memory, initializes the |
| 582 | * structures used by the channel selection algorithm |
| 583 | * |
| 584 | * Return: bool Success or FAIL |
| 585 | */ |
| 586 | static bool sap_chan_sel_init(mac_handle_t mac_handle, |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 587 | tSapChSelSpectInfo *pSpectInfoParams, |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 588 | struct sap_context *sap_ctx) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 589 | { |
| 590 | tSapSpectChInfo *pSpectCh = NULL; |
| 591 | uint8_t *pChans = NULL; |
| 592 | uint16_t channelnum = 0; |
Jeff Johnson | c59ef8b | 2018-12-02 12:01:21 -0800 | [diff] [blame] | 593 | struct mac_context *mac = MAC_CONTEXT(mac_handle); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 594 | bool chSafe = true; |
| 595 | #ifdef FEATURE_WLAN_CH_AVOID |
| 596 | uint16_t i; |
| 597 | #endif |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 598 | bool include_dfs_ch = true; |
Himanshu Agarwal | fee2e36 | 2018-01-18 20:26:35 +0530 | [diff] [blame] | 599 | uint8_t chan_num; |
Bala Venkatesh | 2f25c81 | 2017-12-15 17:42:12 +0530 | [diff] [blame] | 600 | bool sta_sap_scc_on_dfs_chan = |
Jeff Johnson | b979444 | 2018-11-22 14:21:08 -0800 | [diff] [blame] | 601 | policy_mgr_is_sta_sap_scc_allowed_on_dfs_chan(mac->psoc); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 602 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 603 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, "In %s", |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 604 | __func__); |
| 605 | |
| 606 | pSpectInfoParams->numSpectChans = |
Jeff Johnson | b979444 | 2018-11-22 14:21:08 -0800 | [diff] [blame] | 607 | mac->scan.base_channels.numChannels; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 608 | |
| 609 | /* Allocate memory for weight computation of 2.4GHz */ |
Arif Hussain | 256cc28 | 2018-10-03 14:10:44 -0700 | [diff] [blame] | 610 | pSpectCh = qdf_mem_malloc((pSpectInfoParams->numSpectChans) * |
| 611 | sizeof(*pSpectCh)); |
| 612 | if (!pSpectCh) |
Srinivas Girigowda | 74a66d6 | 2017-06-21 23:28:25 -0700 | [diff] [blame] | 613 | return false; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 614 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 615 | /* Initialize the pointers in the DfsParams to the allocated memory */ |
| 616 | pSpectInfoParams->pSpectCh = pSpectCh; |
| 617 | |
Jeff Johnson | b979444 | 2018-11-22 14:21:08 -0800 | [diff] [blame] | 618 | pChans = mac->scan.base_channels.channelList; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 619 | |
Ryan Hsu | 4252a2f | 2016-01-05 11:18:24 -0800 | [diff] [blame] | 620 | #if defined(FEATURE_WLAN_STA_AP_MODE_DFS_DISABLE) |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 621 | if (sap_ctx->dfs_ch_disable == true) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 622 | include_dfs_ch = false; |
| 623 | #endif |
Jeff Johnson | b979444 | 2018-11-22 14:21:08 -0800 | [diff] [blame] | 624 | if (!mac->mlme_cfg->dfs_cfg.dfs_master_capable || |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 625 | ACS_DFS_MODE_DISABLE == sap_ctx->dfs_mode) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 626 | include_dfs_ch = false; |
| 627 | |
| 628 | /* Fill the channel number in the spectrum in the operating freq band */ |
| 629 | for (channelnum = 0; |
| 630 | channelnum < pSpectInfoParams->numSpectChans; |
Edhar, Mahesh Kumar | 4f66067 | 2015-10-30 11:53:26 +0530 | [diff] [blame] | 631 | channelnum++, pChans++, pSpectCh++) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 632 | chSafe = true; |
| 633 | |
Himanshu Agarwal | 052ce25 | 2018-06-18 17:18:59 +0530 | [diff] [blame] | 634 | pSpectCh->chNum = *pChans; |
| 635 | /* Initialise for all channels */ |
| 636 | pSpectCh->rssiAgr = SOFTAP_MIN_RSSI; |
| 637 | /* Initialise 20MHz for all the Channels */ |
| 638 | pSpectCh->channelWidth = SOFTAP_HT20_CHANNELWIDTH; |
| 639 | /* Initialise max ACS weight for all channels */ |
| 640 | pSpectCh->weight = SAP_ACS_WEIGHT_MAX; |
| 641 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 642 | /* check if the channel is in NOL blacklist */ |
Himanshu Agarwal | 052ce25 | 2018-06-18 17:18:59 +0530 | [diff] [blame] | 643 | if (sap_dfs_is_channel_in_nol_list( |
| 644 | sap_ctx, *pChans, |
| 645 | PHY_SINGLE_CHANNEL_CENTERED)) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 646 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 647 | "In %s, Ch %d is in NOL list", __func__, |
| 648 | *pChans); |
| 649 | chSafe = false; |
| 650 | continue; |
| 651 | } |
| 652 | |
Bala Venkatesh | 2f25c81 | 2017-12-15 17:42:12 +0530 | [diff] [blame] | 653 | if (!include_dfs_ch || sta_sap_scc_on_dfs_chan) { |
Jeff Johnson | b979444 | 2018-11-22 14:21:08 -0800 | [diff] [blame] | 654 | if (wlan_reg_is_dfs_ch(mac->pdev, *pChans)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 655 | chSafe = false; |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 656 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 657 | QDF_TRACE_LEVEL_INFO_HIGH, |
Bala Venkatesh | 2f25c81 | 2017-12-15 17:42:12 +0530 | [diff] [blame] | 658 | "In %s, DFS Ch %d not considered for ACS. include_dfs_ch %u, sta_sap_scc_on_dfs_chan %d", |
| 659 | __func__, *pChans, include_dfs_ch, |
| 660 | sta_sap_scc_on_dfs_chan); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 661 | continue; |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | #ifdef FEATURE_WLAN_CH_AVOID |
Amar Singhal | b8d4f15 | 2016-02-10 10:21:43 -0800 | [diff] [blame] | 666 | for (i = 0; i < NUM_CHANNELS; i++) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 667 | if ((safe_channels[i].channelNumber == *pChans) && |
| 668 | (false == safe_channels[i].isSafe)) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 669 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 670 | QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 671 | "In %s, Ch %d is not safe", __func__, |
| 672 | *pChans); |
| 673 | chSafe = false; |
| 674 | break; |
| 675 | } |
| 676 | } |
| 677 | #endif /* FEATURE_WLAN_CH_AVOID */ |
| 678 | |
| 679 | /* OFDM rates are not supported on channel 14 */ |
| 680 | if (*pChans == 14 && |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 681 | eCSR_DOT11_MODE_11b != sap_ctx->csr_roamProfile.phyMode) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 682 | continue; |
| 683 | } |
| 684 | |
Deepthi Gowri | 48b8933 | 2016-08-30 18:43:05 +0530 | [diff] [blame] | 685 | /* Skip DSRC channels */ |
Jeff Johnson | b979444 | 2018-11-22 14:21:08 -0800 | [diff] [blame] | 686 | if (wlan_reg_is_dsrc_chan(mac->pdev, *pChans)) |
Kiran Kumar Lokere | 1a43bcf | 2018-05-15 15:51:58 -0700 | [diff] [blame] | 687 | continue; |
| 688 | |
lifeng | 0b46ae5 | 2018-12-13 09:42:27 +0800 | [diff] [blame] | 689 | if (!mac->mlme_cfg->reg.etsi13_srd_chan_in_master_mode && |
Jeff Johnson | b979444 | 2018-11-22 14:21:08 -0800 | [diff] [blame] | 690 | wlan_reg_is_etsi13_srd_chan(mac->pdev, *pChans)) |
Deepthi Gowri | 48b8933 | 2016-08-30 18:43:05 +0530 | [diff] [blame] | 691 | continue; |
| 692 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 693 | if (true == chSafe) { |
Srinivas Girigowda | 74a66d6 | 2017-06-21 23:28:25 -0700 | [diff] [blame] | 694 | pSpectCh->valid = true; |
Himanshu Agarwal | fee2e36 | 2018-01-18 20:26:35 +0530 | [diff] [blame] | 695 | for (chan_num = 0; chan_num < sap_ctx->num_of_channel; |
| 696 | chan_num++) { |
| 697 | if (pSpectCh->chNum != |
Min Liu | 00956e8 | 2019-07-26 14:49:30 +0800 | [diff] [blame] | 698 | wlan_reg_freq_to_chan(mac->pdev, |
| 699 | sap_ctx->freq_list[chan_num])) |
Himanshu Agarwal | fee2e36 | 2018-01-18 20:26:35 +0530 | [diff] [blame] | 700 | continue; |
| 701 | |
| 702 | /* |
| 703 | * Initialize ACS weight to 0 for channels |
| 704 | * present in sap context scan channel list |
| 705 | */ |
| 706 | pSpectCh->weight = 0; |
| 707 | break; |
| 708 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 709 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 710 | } |
Srinivas Girigowda | 74a66d6 | 2017-06-21 23:28:25 -0700 | [diff] [blame] | 711 | return true; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 712 | } |
| 713 | |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 714 | /** |
| 715 | * sapweight_rssi_count() - calculates the channel weight due to rssi |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 716 | and data count(here number of BSS observed) |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 717 | * @sap_ctx : Softap context |
| 718 | * @rssi : Max signal strength receieved from a BSS for the channel |
| 719 | * @count : Number of BSS observed in the channel |
| 720 | * |
| 721 | * Return: uint32_t Calculated channel weight based on above two |
| 722 | */ |
| 723 | static |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 724 | uint32_t sapweight_rssi_count(struct sap_context *sap_ctx, int8_t rssi, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 725 | uint16_t count) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 726 | { |
| 727 | int32_t rssiWeight = 0; |
| 728 | int32_t countWeight = 0; |
| 729 | uint32_t rssicountWeight = 0; |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 730 | uint8_t softap_rssi_weight_cfg, softap_count_weight_cfg; |
| 731 | uint8_t softap_rssi_weight_local, softap_count_weight_local; |
| 732 | |
| 733 | softap_rssi_weight_cfg = |
| 734 | ACS_WEIGHT_SOFTAP_RSSI_CFG(sap_ctx->auto_channel_select_weight); |
| 735 | |
| 736 | softap_count_weight_cfg = |
| 737 | ACS_WEIGHT_SOFTAP_COUNT_CFG(sap_ctx->auto_channel_select_weight); |
| 738 | |
| 739 | softap_rssi_weight_local = |
| 740 | ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight, |
| 741 | softap_rssi_weight_cfg); |
| 742 | |
| 743 | softap_count_weight_local = |
| 744 | ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight, |
| 745 | softap_count_weight_cfg); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 746 | |
| 747 | /* Weight from RSSI */ |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 748 | rssiWeight = ACS_WEIGHT_COMPUTE(sap_ctx->auto_channel_select_weight, |
| 749 | softap_rssi_weight_cfg, |
| 750 | rssi - SOFTAP_MIN_RSSI, |
| 751 | SOFTAP_MAX_RSSI - SOFTAP_MIN_RSSI); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 752 | |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 753 | if (rssiWeight > softap_rssi_weight_local) |
| 754 | rssiWeight = softap_rssi_weight_local; |
| 755 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 756 | else if (rssiWeight < 0) |
| 757 | rssiWeight = 0; |
| 758 | |
| 759 | /* Weight from data count */ |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 760 | countWeight = ACS_WEIGHT_COMPUTE(sap_ctx->auto_channel_select_weight, |
| 761 | softap_count_weight_cfg, |
| 762 | count - SOFTAP_MIN_COUNT, |
| 763 | SOFTAP_MAX_COUNT - SOFTAP_MIN_COUNT); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 764 | |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 765 | if (countWeight > softap_count_weight_local) |
| 766 | countWeight = softap_count_weight_local; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 767 | |
| 768 | rssicountWeight = rssiWeight + countWeight; |
| 769 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 770 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 771 | "In %s, rssiWeight=%d, countWeight=%d, rssicountWeight=%d", |
| 772 | __func__, rssiWeight, countWeight, rssicountWeight); |
| 773 | |
| 774 | return rssicountWeight; |
| 775 | } |
| 776 | |
| 777 | /** |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 778 | * sap_get_channel_status() - get channel info via channel number |
| 779 | * @p_mac: Pointer to Global MAC structure |
| 780 | * @channel_id: channel id |
| 781 | * |
| 782 | * Return: chan status info |
| 783 | */ |
| 784 | static struct lim_channel_status *sap_get_channel_status |
Jeff Johnson | c59ef8b | 2018-12-02 12:01:21 -0800 | [diff] [blame] | 785 | (struct mac_context *p_mac, uint32_t channel_id) |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 786 | { |
| 787 | return csr_get_channel_status(p_mac, channel_id); |
| 788 | } |
| 789 | |
| 790 | /** |
| 791 | * sap_clear_channel_status() - clear chan info |
| 792 | * @p_mac: Pointer to Global MAC structure |
| 793 | * |
| 794 | * Return: none |
| 795 | */ |
Jeff Johnson | c59ef8b | 2018-12-02 12:01:21 -0800 | [diff] [blame] | 796 | static void sap_clear_channel_status(struct mac_context *p_mac) |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 797 | { |
| 798 | csr_clear_channel_status(p_mac); |
| 799 | } |
| 800 | |
| 801 | /** |
| 802 | * sap_weight_channel_noise_floor() - compute noise floor weight |
| 803 | * @sap_ctx: sap context |
| 804 | * @chn_stat: Pointer to chan status info |
| 805 | * |
| 806 | * Return: channel noise floor weight |
| 807 | */ |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 808 | static uint32_t sap_weight_channel_noise_floor(struct sap_context *sap_ctx, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 809 | struct lim_channel_status |
| 810 | *channel_stat) |
| 811 | { |
| 812 | uint32_t noise_floor_weight; |
| 813 | uint8_t softap_nf_weight_cfg; |
| 814 | uint8_t softap_nf_weight_local; |
| 815 | |
| 816 | softap_nf_weight_cfg = |
| 817 | ACS_WEIGHT_SOFTAP_NOISE_FLOOR_CFG |
| 818 | (sap_ctx->auto_channel_select_weight); |
| 819 | |
| 820 | softap_nf_weight_local = |
| 821 | ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight, |
| 822 | softap_nf_weight_cfg); |
| 823 | |
Jeff Johnson | 4cfe6cc | 2019-03-18 13:40:27 -0700 | [diff] [blame] | 824 | if (!channel_stat || channel_stat->channelfreq == 0) { |
Srinivas Girigowda | 80213e5 | 2018-01-23 14:51:33 -0800 | [diff] [blame] | 825 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 826 | "In %s, sanity check failed return max weight", |
| 827 | __func__); |
| 828 | return softap_nf_weight_local; |
| 829 | } |
| 830 | |
| 831 | noise_floor_weight = (channel_stat->noise_floor == 0) ? 0 : |
| 832 | (ACS_WEIGHT_COMPUTE( |
| 833 | sap_ctx->auto_channel_select_weight, |
| 834 | softap_nf_weight_cfg, |
| 835 | channel_stat->noise_floor - |
| 836 | SOFTAP_MIN_NF, |
| 837 | SOFTAP_MAX_NF - SOFTAP_MIN_NF)); |
| 838 | |
| 839 | if (noise_floor_weight > softap_nf_weight_local) |
| 840 | noise_floor_weight = softap_nf_weight_local; |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 841 | |
| 842 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 843 | "In %s, nf=%d, nfwc=%d, nfwl=%d, nfw=%d", |
| 844 | __func__, channel_stat->noise_floor, |
| 845 | softap_nf_weight_cfg, softap_nf_weight_local, |
| 846 | noise_floor_weight); |
| 847 | |
| 848 | return noise_floor_weight; |
| 849 | } |
| 850 | |
| 851 | /** |
| 852 | * sap_weight_channel_free() - compute channel free weight |
| 853 | * @sap_ctx: sap context |
| 854 | * @chn_stat: Pointer to chan status info |
| 855 | * |
| 856 | * Return: channel free weight |
| 857 | */ |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 858 | static uint32_t sap_weight_channel_free(struct sap_context *sap_ctx, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 859 | struct lim_channel_status |
| 860 | *channel_stat) |
| 861 | { |
| 862 | uint32_t channel_free_weight; |
| 863 | uint8_t softap_channel_free_weight_cfg; |
| 864 | uint8_t softap_channel_free_weight_local; |
| 865 | uint32_t rx_clear_count = 0; |
| 866 | uint32_t cycle_count = 0; |
| 867 | |
| 868 | softap_channel_free_weight_cfg = |
| 869 | ACS_WEIGHT_SOFTAP_CHANNEL_FREE_CFG |
| 870 | (sap_ctx->auto_channel_select_weight); |
| 871 | |
| 872 | softap_channel_free_weight_local = |
| 873 | ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight, |
| 874 | softap_channel_free_weight_cfg); |
| 875 | |
Jeff Johnson | 4cfe6cc | 2019-03-18 13:40:27 -0700 | [diff] [blame] | 876 | if (!channel_stat || channel_stat->channelfreq == 0) { |
Srinivas Girigowda | 80213e5 | 2018-01-23 14:51:33 -0800 | [diff] [blame] | 877 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 878 | "In %s, sanity check failed return max weight", |
| 879 | __func__); |
| 880 | return softap_channel_free_weight_local; |
| 881 | } |
| 882 | |
| 883 | rx_clear_count = channel_stat->rx_clear_count - |
| 884 | channel_stat->tx_frame_count - |
| 885 | channel_stat->rx_frame_count; |
| 886 | cycle_count = channel_stat->cycle_count; |
| 887 | |
| 888 | /* LSH 4, otherwise it is always 0. */ |
| 889 | channel_free_weight = (cycle_count == 0) ? 0 : |
| 890 | (ACS_WEIGHT_COMPUTE( |
| 891 | sap_ctx->auto_channel_select_weight, |
| 892 | softap_channel_free_weight_cfg, |
| 893 | ((rx_clear_count << 8) + |
| 894 | (cycle_count >> 1))/cycle_count - |
| 895 | (SOFTAP_MIN_CHNFREE << 8), |
| 896 | (SOFTAP_MAX_CHNFREE - |
| 897 | SOFTAP_MIN_CHNFREE) << 8)); |
| 898 | |
| 899 | if (channel_free_weight > softap_channel_free_weight_local) |
| 900 | channel_free_weight = softap_channel_free_weight_local; |
| 901 | |
| 902 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 903 | "In %s, rcc=%d, cc=%d, tc=%d, rc=%d, cfwc=%d, cfwl=%d, cfw=%d", |
| 904 | __func__, rx_clear_count, cycle_count, |
| 905 | channel_stat->tx_frame_count, |
| 906 | channel_stat->rx_frame_count, |
| 907 | softap_channel_free_weight_cfg, |
| 908 | softap_channel_free_weight_local, |
| 909 | channel_free_weight); |
| 910 | |
| 911 | return channel_free_weight; |
| 912 | } |
| 913 | |
| 914 | /** |
| 915 | * sap_weight_channel_txpwr_range() - compute channel tx power range weight |
| 916 | * @sap_ctx: sap context |
| 917 | * @chn_stat: Pointer to chan status info |
| 918 | * |
| 919 | * Return: tx power range weight |
| 920 | */ |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 921 | static uint32_t sap_weight_channel_txpwr_range(struct sap_context *sap_ctx, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 922 | struct lim_channel_status |
| 923 | *channel_stat) |
| 924 | { |
| 925 | uint32_t txpwr_weight_low_speed; |
| 926 | uint8_t softap_txpwr_range_weight_cfg; |
| 927 | uint8_t softap_txpwr_range_weight_local; |
| 928 | |
| 929 | softap_txpwr_range_weight_cfg = |
| 930 | ACS_WEIGHT_SOFTAP_TX_POWER_RANGE_CFG |
| 931 | (sap_ctx->auto_channel_select_weight); |
| 932 | |
| 933 | softap_txpwr_range_weight_local = |
| 934 | ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight, |
| 935 | softap_txpwr_range_weight_cfg); |
| 936 | |
Jeff Johnson | 4cfe6cc | 2019-03-18 13:40:27 -0700 | [diff] [blame] | 937 | if (!channel_stat || channel_stat->channelfreq == 0) { |
Srinivas Girigowda | 80213e5 | 2018-01-23 14:51:33 -0800 | [diff] [blame] | 938 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 939 | "In %s, sanity check failed return max weight", |
| 940 | __func__); |
| 941 | return softap_txpwr_range_weight_local; |
| 942 | } |
| 943 | |
| 944 | txpwr_weight_low_speed = (channel_stat->chan_tx_pwr_range == 0) ? 0 : |
| 945 | (ACS_WEIGHT_COMPUTE( |
| 946 | sap_ctx->auto_channel_select_weight, |
| 947 | softap_txpwr_range_weight_cfg, |
| 948 | SOFTAP_MAX_TXPWR - |
| 949 | channel_stat->chan_tx_pwr_range, |
| 950 | SOFTAP_MAX_TXPWR - SOFTAP_MIN_TXPWR)); |
| 951 | |
| 952 | if (txpwr_weight_low_speed > softap_txpwr_range_weight_local) |
| 953 | txpwr_weight_low_speed = softap_txpwr_range_weight_local; |
| 954 | |
| 955 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 956 | "In %s, tpr=%d, tprwc=%d, tprwl=%d, tprw=%d", |
| 957 | __func__, channel_stat->chan_tx_pwr_range, |
| 958 | softap_txpwr_range_weight_cfg, |
| 959 | softap_txpwr_range_weight_local, |
| 960 | txpwr_weight_low_speed); |
| 961 | |
| 962 | return txpwr_weight_low_speed; |
| 963 | } |
| 964 | |
| 965 | /** |
| 966 | * sap_weight_channel_txpwr_tput() - compute channel tx power |
| 967 | * throughput weight |
| 968 | * @sap_ctx: sap context |
| 969 | * @chn_stat: Pointer to chan status info |
| 970 | * |
| 971 | * Return: tx power throughput weight |
| 972 | */ |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 973 | static uint32_t sap_weight_channel_txpwr_tput(struct sap_context *sap_ctx, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 974 | struct lim_channel_status |
| 975 | *channel_stat) |
| 976 | { |
| 977 | uint32_t txpwr_weight_high_speed; |
| 978 | uint8_t softap_txpwr_tput_weight_cfg; |
| 979 | uint8_t softap_txpwr_tput_weight_local; |
| 980 | |
| 981 | softap_txpwr_tput_weight_cfg = |
| 982 | ACS_WEIGHT_SOFTAP_TX_POWER_THROUGHPUT_CFG |
| 983 | (sap_ctx->auto_channel_select_weight); |
| 984 | |
| 985 | softap_txpwr_tput_weight_local = |
| 986 | ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight, |
| 987 | softap_txpwr_tput_weight_cfg); |
| 988 | |
Jeff Johnson | 4cfe6cc | 2019-03-18 13:40:27 -0700 | [diff] [blame] | 989 | if (!channel_stat || channel_stat->channelfreq == 0) { |
Srinivas Girigowda | 80213e5 | 2018-01-23 14:51:33 -0800 | [diff] [blame] | 990 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 991 | "In %s, sanity check failed return max weight", |
| 992 | __func__); |
| 993 | return softap_txpwr_tput_weight_local; |
| 994 | } |
| 995 | |
| 996 | txpwr_weight_high_speed = (channel_stat->chan_tx_pwr_throughput == 0) |
| 997 | ? 0 : (ACS_WEIGHT_COMPUTE( |
| 998 | sap_ctx->auto_channel_select_weight, |
| 999 | softap_txpwr_tput_weight_cfg, |
| 1000 | SOFTAP_MAX_TXPWR - |
| 1001 | channel_stat->chan_tx_pwr_throughput, |
| 1002 | SOFTAP_MAX_TXPWR - SOFTAP_MIN_TXPWR)); |
| 1003 | |
| 1004 | if (txpwr_weight_high_speed > softap_txpwr_tput_weight_local) |
| 1005 | txpwr_weight_high_speed = softap_txpwr_tput_weight_local; |
| 1006 | |
| 1007 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 1008 | "In %s, tpt=%d, tptwc=%d, tptwl=%d, tptw=%d", |
| 1009 | __func__, channel_stat->chan_tx_pwr_throughput, |
| 1010 | softap_txpwr_tput_weight_cfg, |
| 1011 | softap_txpwr_tput_weight_local, |
| 1012 | txpwr_weight_high_speed); |
| 1013 | |
| 1014 | return txpwr_weight_high_speed; |
| 1015 | } |
| 1016 | |
| 1017 | /** |
| 1018 | * sap_weight_channel_status() - compute chan status weight |
| 1019 | * @sap_ctx: sap context |
| 1020 | * @chn_stat: Pointer to chan status info |
| 1021 | * |
| 1022 | * Return: chan status weight |
| 1023 | */ |
| 1024 | static |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 1025 | uint32_t sap_weight_channel_status(struct sap_context *sap_ctx, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 1026 | struct lim_channel_status *channel_stat) |
| 1027 | { |
| 1028 | return sap_weight_channel_noise_floor(sap_ctx, channel_stat) + |
| 1029 | sap_weight_channel_free(sap_ctx, channel_stat) + |
| 1030 | sap_weight_channel_txpwr_range(sap_ctx, channel_stat) + |
| 1031 | sap_weight_channel_txpwr_tput(sap_ctx, channel_stat); |
| 1032 | } |
| 1033 | |
| 1034 | /** |
Yeshwanth Sriram Guntuka | 273889e | 2018-02-16 17:11:46 +0530 | [diff] [blame] | 1035 | * sap_check_channels_same_band() - Check if two channels belong to same band |
| 1036 | * @ch_num1: channel number |
| 1037 | * @ch_num2: channel number |
| 1038 | * |
| 1039 | * Return: true if both channels belong to same band else false |
| 1040 | */ |
| 1041 | static bool sap_check_channels_same_band(uint16_t ch_num1, uint16_t ch_num2) |
| 1042 | { |
| 1043 | if ((ch_num1 <= SIR_11B_CHANNEL_END && |
| 1044 | ch_num2 <= SIR_11B_CHANNEL_END) || |
| 1045 | (ch_num1 >= SIR_11A_CHANNEL_BEGIN && |
| 1046 | ch_num2 >= SIR_11A_CHANNEL_BEGIN)) |
Srinivas Girigowda | eff16d9 | 2018-09-12 14:56:29 -0700 | [diff] [blame] | 1047 | return true; |
Yeshwanth Sriram Guntuka | 273889e | 2018-02-16 17:11:46 +0530 | [diff] [blame] | 1048 | |
| 1049 | return false; |
| 1050 | } |
| 1051 | |
| 1052 | /** |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1053 | * sap_update_rssi_bsscount() - updates bss count and rssi effect. |
| 1054 | * |
| 1055 | * @pSpectCh: Channel Information |
| 1056 | * @offset: Channel Offset |
| 1057 | * @sap_24g: Channel is in 2.4G or 5G |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1058 | * @spectch_start: the start of spect ch array |
| 1059 | * @spectch_end: the end of spect ch array |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1060 | * |
| 1061 | * sap_update_rssi_bsscount updates bss count and rssi effect based |
| 1062 | * on the channel offset. |
| 1063 | * |
| 1064 | * Return: None. |
| 1065 | */ |
| 1066 | |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1067 | static void sap_update_rssi_bsscount(tSapSpectChInfo *pSpectCh, int32_t offset, |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1068 | bool sap_24g, tSapSpectChInfo *spectch_start, |
| 1069 | tSapSpectChInfo *spectch_end) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1070 | { |
| 1071 | tSapSpectChInfo *pExtSpectCh = NULL; |
| 1072 | int32_t rssi, rsssi_effect; |
| 1073 | |
| 1074 | pExtSpectCh = (pSpectCh + offset); |
Jeff Johnson | 4cfe6cc | 2019-03-18 13:40:27 -0700 | [diff] [blame] | 1075 | if (pExtSpectCh && |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1076 | pExtSpectCh >= spectch_start && |
| 1077 | pExtSpectCh < spectch_end) { |
Yeshwanth Sriram Guntuka | 273889e | 2018-02-16 17:11:46 +0530 | [diff] [blame] | 1078 | if (!sap_check_channels_same_band(pSpectCh->chNum, |
| 1079 | pExtSpectCh->chNum)) |
| 1080 | return; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1081 | ++pExtSpectCh->bssCount; |
| 1082 | switch (offset) { |
| 1083 | case -1: |
| 1084 | case 1: |
| 1085 | rsssi_effect = sap_24g ? |
| 1086 | SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY : |
| 1087 | SAP_SUBBAND1_RSSI_EFFECT_PRIMARY; |
| 1088 | break; |
| 1089 | case -2: |
| 1090 | case 2: |
| 1091 | rsssi_effect = sap_24g ? |
| 1092 | SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY : |
| 1093 | SAP_SUBBAND2_RSSI_EFFECT_PRIMARY; |
| 1094 | break; |
| 1095 | case -3: |
| 1096 | case 3: |
| 1097 | rsssi_effect = sap_24g ? |
| 1098 | SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY : |
| 1099 | SAP_SUBBAND3_RSSI_EFFECT_PRIMARY; |
| 1100 | break; |
| 1101 | case -4: |
| 1102 | case 4: |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1103 | rsssi_effect = sap_24g ? |
| 1104 | SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY : |
| 1105 | SAP_SUBBAND4_RSSI_EFFECT_PRIMARY; |
| 1106 | break; |
| 1107 | case -5: |
| 1108 | case 5: |
| 1109 | rsssi_effect = SAP_SUBBAND5_RSSI_EFFECT_PRIMARY; |
| 1110 | break; |
| 1111 | case -6: |
| 1112 | case 6: |
| 1113 | rsssi_effect = SAP_SUBBAND6_RSSI_EFFECT_PRIMARY; |
| 1114 | break; |
| 1115 | case -7: |
| 1116 | case 7: |
| 1117 | rsssi_effect = SAP_SUBBAND7_RSSI_EFFECT_PRIMARY; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1118 | break; |
| 1119 | default: |
| 1120 | rsssi_effect = 0; |
| 1121 | break; |
| 1122 | } |
| 1123 | |
| 1124 | rssi = pSpectCh->rssiAgr + rsssi_effect; |
| 1125 | if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi)) |
| 1126 | pExtSpectCh->rssiAgr = rssi; |
| 1127 | if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI) |
| 1128 | pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI; |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | /** |
| 1133 | * sap_upd_chan_spec_params() - sap_upd_chan_spec_params |
| 1134 | * updates channel parameters obtained from Beacon |
| 1135 | * @pBeaconStruct Beacon strucutre populated by parse_beacon function |
| 1136 | * @channelWidth Channel width |
| 1137 | * @secondaryChannelOffset Secondary Channel Offset |
| 1138 | * @vhtSupport If channel supports VHT |
| 1139 | * @centerFreq Central frequency for the given channel. |
| 1140 | * |
| 1141 | * sap_upd_chan_spec_params updates the spectrum channels based on the |
| 1142 | * pBeaconStruct obtained from Beacon IE |
| 1143 | * |
| 1144 | * Return: NA. |
| 1145 | */ |
| 1146 | |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1147 | static void sap_upd_chan_spec_params(tSirProbeRespBeacon *pBeaconStruct, |
| 1148 | uint16_t *channelWidth, |
| 1149 | uint16_t *secondaryChannelOffset, |
| 1150 | uint16_t *vhtSupport, |
| 1151 | uint16_t *centerFreq, |
| 1152 | uint16_t *centerFreq_2) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1153 | { |
Jeff Johnson | 4cfe6cc | 2019-03-18 13:40:27 -0700 | [diff] [blame] | 1154 | if (!pBeaconStruct) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1155 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1156 | FL("pBeaconStruct is NULL")); |
| 1157 | return; |
| 1158 | } |
| 1159 | |
| 1160 | if (pBeaconStruct->HTCaps.present && pBeaconStruct->HTInfo.present) { |
| 1161 | *channelWidth = pBeaconStruct->HTCaps.supportedChannelWidthSet; |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1162 | *secondaryChannelOffset = |
| 1163 | pBeaconStruct->HTInfo.secondaryChannelOffset; |
| 1164 | if (!pBeaconStruct->VHTOperation.present) |
| 1165 | return; |
| 1166 | *vhtSupport = pBeaconStruct->VHTOperation.present; |
| 1167 | if (pBeaconStruct->VHTOperation.chanWidth) { |
| 1168 | *centerFreq = |
| 1169 | pBeaconStruct->VHTOperation.chanCenterFreqSeg1; |
| 1170 | *centerFreq_2 = |
| 1171 | pBeaconStruct->VHTOperation.chanCenterFreqSeg2; |
| 1172 | /* |
| 1173 | * LHS follows tSirMacHTChannelWidth, while RHS follows |
| 1174 | * WNI_CFG_VHT_CHANNEL_WIDTH_X format hence following |
| 1175 | * adjustment |
| 1176 | */ |
| 1177 | *channelWidth = |
| 1178 | pBeaconStruct->VHTOperation.chanWidth + 1; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1179 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1180 | } |
| 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | /** |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1185 | * sap_update_rssi_bsscount_vht_5G() - updates bss count and rssi effect. |
| 1186 | * |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1187 | * @spect_ch: Channel Information |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1188 | * @offset: Channel Offset |
| 1189 | * @num_ch: no.of channels |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1190 | * @spectch_start: the start of spect ch array |
| 1191 | * @spectch_end: the end of spect ch array |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1192 | * |
| 1193 | * sap_update_rssi_bsscount_vht_5G updates bss count and rssi effect based |
| 1194 | * on the channel offset. |
| 1195 | * |
| 1196 | * Return: None. |
| 1197 | */ |
| 1198 | |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1199 | static void sap_update_rssi_bsscount_vht_5G(tSapSpectChInfo *spect_ch, |
| 1200 | int32_t offset, |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1201 | uint16_t num_ch, |
| 1202 | tSapSpectChInfo *spectch_start, |
| 1203 | tSapSpectChInfo *spectch_end) |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1204 | { |
| 1205 | int32_t ch_offset; |
| 1206 | uint16_t i, cnt; |
| 1207 | |
| 1208 | if (!offset) |
| 1209 | return; |
| 1210 | if (offset > 0) |
| 1211 | cnt = num_ch; |
| 1212 | else |
| 1213 | cnt = num_ch + 1; |
| 1214 | for (i = 0; i < cnt; i++) { |
| 1215 | ch_offset = offset + i; |
| 1216 | if (ch_offset == 0) |
| 1217 | continue; |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1218 | sap_update_rssi_bsscount(spect_ch, ch_offset, false, |
| 1219 | spectch_start, spectch_end); |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1220 | } |
| 1221 | } |
| 1222 | /** |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1223 | * sap_interference_rssi_count_5G() - sap_interference_rssi_count |
| 1224 | * considers the Adjacent channel rssi and |
| 1225 | * data count(here number of BSS observed) |
| 1226 | * @spect_ch: Channel Information |
| 1227 | * @chan_width: Channel width parsed from beacon IE |
| 1228 | * @sec_chan_offset: Secondary Channel Offset |
| 1229 | * @center_freq: Central frequency for the given channel. |
| 1230 | * @channel_id: channel_id |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1231 | * @spectch_start: the start of spect ch array |
| 1232 | * @spectch_end: the end of spect ch array |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1233 | * |
| 1234 | * sap_interference_rssi_count_5G considers the Adjacent channel rssi |
| 1235 | * and data count(here number of BSS observed) |
| 1236 | * |
| 1237 | * Return: NA. |
| 1238 | */ |
| 1239 | |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1240 | static void sap_interference_rssi_count_5G(tSapSpectChInfo *spect_ch, |
| 1241 | uint16_t chan_width, |
| 1242 | uint16_t sec_chan_offset, |
| 1243 | uint16_t center_freq, |
| 1244 | uint16_t center_freq_2, |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1245 | uint8_t channel_id, |
| 1246 | tSapSpectChInfo *spectch_start, |
| 1247 | tSapSpectChInfo *spectch_end) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1248 | { |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1249 | uint16_t num_ch; |
| 1250 | int32_t offset = 0; |
Srinivas Girigowda | 4d65ebe | 2017-10-13 21:41:42 -0700 | [diff] [blame] | 1251 | |
Jeff Johnson | 4cfe6cc | 2019-03-18 13:40:27 -0700 | [diff] [blame] | 1252 | if (!spect_ch) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1253 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1254 | FL("spect_ch is NULL")); |
| 1255 | return; |
| 1256 | } |
| 1257 | |
| 1258 | /* Updating the received ChannelWidth */ |
| 1259 | if (spect_ch->channelWidth != chan_width) |
| 1260 | spect_ch->channelWidth = chan_width; |
| 1261 | /* If received ChannelWidth is other than HT20, |
| 1262 | * we need to update the extension channel Params as well |
| 1263 | * chan_width == 0, HT20 |
| 1264 | * chan_width == 1, HT40 |
| 1265 | * chan_width == 2, VHT80 |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1266 | * chan_width == 3, VHT160 |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1267 | */ |
| 1268 | |
| 1269 | switch (spect_ch->channelWidth) { |
| 1270 | case eHT_CHANNEL_WIDTH_40MHZ: /* HT40 */ |
| 1271 | switch (sec_chan_offset) { |
| 1272 | /* Above the Primary Channel */ |
| 1273 | case PHY_DOUBLE_CHANNEL_LOW_PRIMARY: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1274 | sap_update_rssi_bsscount(spect_ch, 1, false, |
| 1275 | spectch_start, spectch_end); |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1276 | return; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1277 | |
| 1278 | /* Below the Primary channel */ |
| 1279 | case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1280 | sap_update_rssi_bsscount(spect_ch, -1, false, |
| 1281 | spectch_start, spectch_end); |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1282 | return; |
| 1283 | } |
| 1284 | return; |
| 1285 | case eHT_CHANNEL_WIDTH_80MHZ: /* VHT80 */ |
| 1286 | num_ch = 3; |
| 1287 | if ((center_freq - channel_id) == 6) { |
| 1288 | offset = 1; |
| 1289 | } else if ((center_freq - channel_id) == 2) { |
| 1290 | offset = -1; |
| 1291 | } else if ((center_freq - channel_id) == -2) { |
| 1292 | offset = -2; |
| 1293 | } else if ((center_freq - channel_id) == -6) { |
| 1294 | offset = -3; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1295 | } |
| 1296 | break; |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1297 | case eHT_CHANNEL_WIDTH_160MHZ: /* VHT160 */ |
| 1298 | num_ch = 7; |
| 1299 | if ((center_freq - channel_id) == 14) |
| 1300 | offset = 1; |
| 1301 | else if ((center_freq - channel_id) == 10) |
| 1302 | offset = -1; |
| 1303 | else if ((center_freq - channel_id) == 6) |
| 1304 | offset = -2; |
| 1305 | else if ((center_freq - channel_id) == 2) |
| 1306 | offset = -3; |
| 1307 | else if ((center_freq - channel_id) == -2) |
| 1308 | offset = -4; |
| 1309 | else if ((center_freq - channel_id) == -6) |
| 1310 | offset = -5; |
| 1311 | else if ((center_freq - channel_id) == -10) |
| 1312 | offset = -6; |
| 1313 | else if ((center_freq - channel_id) == -14) |
| 1314 | offset = -7; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1315 | break; |
| 1316 | default: |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1317 | return; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1318 | } |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1319 | sap_update_rssi_bsscount_vht_5G(spect_ch, offset, num_ch, |
| 1320 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | /** |
| 1324 | * sap_interference_rssi_count() - sap_interference_rssi_count |
| 1325 | * considers the Adjacent channel rssi |
| 1326 | * and data count(here number of BSS observed) |
| 1327 | * @spect_ch Channel Information |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1328 | * @spectch_start: the start of spect ch array |
| 1329 | * @spectch_end: the end of spect ch array |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1330 | * |
| 1331 | * sap_interference_rssi_count considers the Adjacent channel rssi |
| 1332 | * and data count(here number of BSS observed) |
| 1333 | * |
| 1334 | * Return: None. |
| 1335 | */ |
| 1336 | |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1337 | static void sap_interference_rssi_count(tSapSpectChInfo *spect_ch, |
| 1338 | tSapSpectChInfo *spectch_start, |
| 1339 | tSapSpectChInfo *spectch_end) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1340 | { |
Jeff Johnson | 4cfe6cc | 2019-03-18 13:40:27 -0700 | [diff] [blame] | 1341 | if (!spect_ch) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1342 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1343 | "%s: spect_ch is NULL", __func__); |
| 1344 | return; |
| 1345 | } |
| 1346 | |
| 1347 | switch (spect_ch->chNum) { |
| 1348 | case CHANNEL_1: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1349 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1350 | spectch_start, spectch_end); |
| 1351 | sap_update_rssi_bsscount(spect_ch, 2, true, |
| 1352 | spectch_start, spectch_end); |
| 1353 | sap_update_rssi_bsscount(spect_ch, 3, true, |
| 1354 | spectch_start, spectch_end); |
| 1355 | sap_update_rssi_bsscount(spect_ch, 4, true, |
| 1356 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1357 | break; |
| 1358 | |
| 1359 | case CHANNEL_2: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1360 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1361 | spectch_start, spectch_end); |
| 1362 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1363 | spectch_start, spectch_end); |
| 1364 | sap_update_rssi_bsscount(spect_ch, 2, true, |
| 1365 | spectch_start, spectch_end); |
| 1366 | sap_update_rssi_bsscount(spect_ch, 3, true, |
| 1367 | spectch_start, spectch_end); |
| 1368 | sap_update_rssi_bsscount(spect_ch, 4, true, |
| 1369 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1370 | break; |
| 1371 | case CHANNEL_3: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1372 | sap_update_rssi_bsscount(spect_ch, -2, true, |
| 1373 | spectch_start, spectch_end); |
| 1374 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1375 | spectch_start, spectch_end); |
| 1376 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1377 | spectch_start, spectch_end); |
| 1378 | sap_update_rssi_bsscount(spect_ch, 2, true, |
| 1379 | spectch_start, spectch_end); |
| 1380 | sap_update_rssi_bsscount(spect_ch, 3, true, |
| 1381 | spectch_start, spectch_end); |
| 1382 | sap_update_rssi_bsscount(spect_ch, 4, true, |
| 1383 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1384 | break; |
| 1385 | case CHANNEL_4: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1386 | sap_update_rssi_bsscount(spect_ch, -3, true, |
| 1387 | spectch_start, spectch_end); |
| 1388 | sap_update_rssi_bsscount(spect_ch, -2, true, |
| 1389 | spectch_start, spectch_end); |
| 1390 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1391 | spectch_start, spectch_end); |
| 1392 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1393 | spectch_start, spectch_end); |
| 1394 | sap_update_rssi_bsscount(spect_ch, 2, true, |
| 1395 | spectch_start, spectch_end); |
| 1396 | sap_update_rssi_bsscount(spect_ch, 3, true, |
| 1397 | spectch_start, spectch_end); |
| 1398 | sap_update_rssi_bsscount(spect_ch, 4, true, |
| 1399 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1400 | break; |
| 1401 | |
| 1402 | case CHANNEL_5: |
| 1403 | case CHANNEL_6: |
| 1404 | case CHANNEL_7: |
| 1405 | case CHANNEL_8: |
| 1406 | case CHANNEL_9: |
| 1407 | case CHANNEL_10: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1408 | sap_update_rssi_bsscount(spect_ch, -4, true, |
| 1409 | spectch_start, spectch_end); |
| 1410 | sap_update_rssi_bsscount(spect_ch, -3, true, |
| 1411 | spectch_start, spectch_end); |
| 1412 | sap_update_rssi_bsscount(spect_ch, -2, true, |
| 1413 | spectch_start, spectch_end); |
| 1414 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1415 | spectch_start, spectch_end); |
| 1416 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1417 | spectch_start, spectch_end); |
| 1418 | sap_update_rssi_bsscount(spect_ch, 2, true, |
| 1419 | spectch_start, spectch_end); |
| 1420 | sap_update_rssi_bsscount(spect_ch, 3, true, |
| 1421 | spectch_start, spectch_end); |
| 1422 | sap_update_rssi_bsscount(spect_ch, 4, true, |
| 1423 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1424 | break; |
| 1425 | |
| 1426 | case CHANNEL_11: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1427 | sap_update_rssi_bsscount(spect_ch, -4, true, |
| 1428 | spectch_start, spectch_end); |
| 1429 | sap_update_rssi_bsscount(spect_ch, -3, true, |
| 1430 | spectch_start, spectch_end); |
| 1431 | sap_update_rssi_bsscount(spect_ch, -2, true, |
| 1432 | spectch_start, spectch_end); |
| 1433 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1434 | spectch_start, spectch_end); |
| 1435 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1436 | spectch_start, spectch_end); |
| 1437 | sap_update_rssi_bsscount(spect_ch, 2, true, |
| 1438 | spectch_start, spectch_end); |
| 1439 | sap_update_rssi_bsscount(spect_ch, 3, true, |
| 1440 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1441 | break; |
| 1442 | |
| 1443 | case CHANNEL_12: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1444 | sap_update_rssi_bsscount(spect_ch, -4, true, |
| 1445 | spectch_start, spectch_end); |
| 1446 | sap_update_rssi_bsscount(spect_ch, -3, true, |
| 1447 | spectch_start, spectch_end); |
| 1448 | sap_update_rssi_bsscount(spect_ch, -2, true, |
| 1449 | spectch_start, spectch_end); |
| 1450 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1451 | spectch_start, spectch_end); |
| 1452 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1453 | spectch_start, spectch_end); |
| 1454 | sap_update_rssi_bsscount(spect_ch, 2, true, |
| 1455 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1456 | break; |
| 1457 | |
| 1458 | case CHANNEL_13: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1459 | sap_update_rssi_bsscount(spect_ch, -4, true, |
| 1460 | spectch_start, spectch_end); |
| 1461 | sap_update_rssi_bsscount(spect_ch, -3, true, |
| 1462 | spectch_start, spectch_end); |
| 1463 | sap_update_rssi_bsscount(spect_ch, -2, true, |
| 1464 | spectch_start, spectch_end); |
| 1465 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1466 | spectch_start, spectch_end); |
| 1467 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1468 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1469 | break; |
| 1470 | |
| 1471 | case CHANNEL_14: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1472 | sap_update_rssi_bsscount(spect_ch, -4, true, |
| 1473 | spectch_start, spectch_end); |
| 1474 | sap_update_rssi_bsscount(spect_ch, -3, true, |
| 1475 | spectch_start, spectch_end); |
| 1476 | sap_update_rssi_bsscount(spect_ch, -2, true, |
| 1477 | spectch_start, spectch_end); |
| 1478 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1479 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1480 | break; |
| 1481 | |
| 1482 | default: |
| 1483 | break; |
| 1484 | } |
| 1485 | } |
| 1486 | |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1487 | /** |
| 1488 | * ch_in_pcl() - Is channel in the Preferred Channel List (PCL) |
| 1489 | * @sap_ctx: SAP context which contains the current PCL |
| 1490 | * @channel: Input channel number to be checked |
| 1491 | * |
| 1492 | * Check if a channel is in the preferred channel list |
| 1493 | * |
| 1494 | * Return: |
| 1495 | * true: channel is in PCL, |
| 1496 | * false: channel is not in PCL |
| 1497 | */ |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 1498 | static bool ch_in_pcl(struct sap_context *sap_ctx, uint8_t channel) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1499 | { |
| 1500 | uint32_t i; |
| 1501 | |
| 1502 | for (i = 0; i < sap_ctx->acs_cfg->pcl_ch_count; i++) { |
| 1503 | if (channel == sap_ctx->acs_cfg->pcl_channels[i]) |
| 1504 | return true; |
| 1505 | } |
| 1506 | |
| 1507 | return false; |
| 1508 | } |
| 1509 | |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1510 | /** |
| 1511 | * sap_compute_spect_weight() - Compute spectrum weight |
| 1512 | * @pSpectInfoParams: Pointer to the tSpectInfoParams structure |
Jeff Johnson | 7730fbb | 2018-11-08 13:48:27 -0800 | [diff] [blame] | 1513 | * @mac_handle: Opaque handle to the global MAC context |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1514 | * @pResult: Pointer to tScanResultHandle |
| 1515 | * @sap_ctx: Context of the SAP |
| 1516 | * |
| 1517 | * Main function for computing the weight of each channel in the |
| 1518 | * spectrum based on the RSSI value of the BSSes on the channel |
| 1519 | * and number of BSS |
| 1520 | */ |
| 1521 | static void sap_compute_spect_weight(tSapChSelSpectInfo *pSpectInfoParams, |
Jeff Johnson | 7730fbb | 2018-11-08 13:48:27 -0800 | [diff] [blame] | 1522 | mac_handle_t mac_handle, |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1523 | qdf_list_t *scan_list, |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 1524 | struct sap_context *sap_ctx) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1525 | { |
| 1526 | int8_t rssi = 0; |
| 1527 | uint8_t chn_num = 0; |
| 1528 | uint8_t channel_id = 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1529 | tSapSpectChInfo *pSpectCh = pSpectInfoParams->pSpectCh; |
| 1530 | uint32_t operatingBand; |
| 1531 | uint16_t channelWidth; |
| 1532 | uint16_t secondaryChannelOffset; |
| 1533 | uint16_t centerFreq; |
gaurank kathpalia | 859c936 | 2018-08-02 23:07:21 +0530 | [diff] [blame] | 1534 | uint8_t i; |
| 1535 | bool found; |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1536 | uint16_t centerFreq_2 = 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1537 | uint16_t vhtSupport; |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1538 | tSirProbeRespBeacon *bcn_struct; |
Jeff Johnson | c59ef8b | 2018-12-02 12:01:21 -0800 | [diff] [blame] | 1539 | struct mac_context *mac = MAC_CONTEXT(mac_handle); |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1540 | tSapSpectChInfo *spectch_start = pSpectInfoParams->pSpectCh; |
| 1541 | tSapSpectChInfo *spectch_end = pSpectInfoParams->pSpectCh + |
| 1542 | pSpectInfoParams->numSpectChans; |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1543 | qdf_list_node_t *cur_lst = NULL, *next_lst = NULL; |
| 1544 | struct scan_cache_node *cur_node = NULL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1545 | |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1546 | bcn_struct = qdf_mem_malloc(sizeof(tSirProbeRespBeacon)); |
| 1547 | if (!bcn_struct) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1548 | return; |
Arif Hussain | 256cc28 | 2018-10-03 14:10:44 -0700 | [diff] [blame] | 1549 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1550 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1551 | "In %s, Computing spectral weight", __func__); |
| 1552 | |
| 1553 | /** |
| 1554 | * Soft AP specific channel weight calculation using DFS formula |
| 1555 | */ |
| 1556 | SET_ACS_BAND(operatingBand, sap_ctx); |
| 1557 | |
Rachit Kankane | 2dba675 | 2019-05-20 14:55:31 +0530 | [diff] [blame] | 1558 | if (scan_list) |
| 1559 | qdf_list_peek_front(scan_list, &cur_lst); |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1560 | while (cur_lst) { |
| 1561 | uint32_t ie_len = 0; |
| 1562 | uint8_t *ie_ptr; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1563 | |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1564 | cur_node = qdf_container_of(cur_lst, struct scan_cache_node, |
| 1565 | node); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 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 | |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1573 | ie_len = util_scan_entry_ie_len(cur_node->entry); |
| 1574 | ie_ptr = util_scan_entry_ie_data(cur_node->entry); |
| 1575 | qdf_mem_zero((uint8_t *)bcn_struct, |
| 1576 | sizeof(tSirProbeRespBeacon)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1577 | |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1578 | if ((sir_parse_beacon_ie(mac, bcn_struct, ie_ptr, ie_len)) == |
| 1579 | QDF_STATUS_SUCCESS) |
Yingying Tang | 22facc1 | 2016-10-20 17:43:59 +0800 | [diff] [blame] | 1580 | sap_upd_chan_spec_params( |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1581 | bcn_struct, |
Yingying Tang | 22facc1 | 2016-10-20 17:43:59 +0800 | [diff] [blame] | 1582 | &channelWidth, |
| 1583 | &secondaryChannelOffset, |
| 1584 | &vhtSupport, ¢erFreq, |
| 1585 | ¢erFreq_2); |
| 1586 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1587 | /* Processing for each tCsrScanResultInfo in the tCsrScanResult DLink list */ |
| 1588 | for (chn_num = 0; chn_num < pSpectInfoParams->numSpectChans; |
| 1589 | chn_num++) { |
| 1590 | |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1591 | channel_id = |
| 1592 | util_scan_entry_channel_num(cur_node->entry); |
Himanshu Agarwal | cf5b893 | 2018-07-02 18:06:49 +0530 | [diff] [blame] | 1593 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1594 | if (pSpectCh && (channel_id == pSpectCh->chNum)) { |
| 1595 | if (pSpectCh->rssiAgr < |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1596 | cur_node->entry->rssi_raw) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1597 | pSpectCh->rssiAgr = |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1598 | cur_node->entry->rssi_raw; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1599 | |
| 1600 | ++pSpectCh->bssCount; /* Increment the count of BSS */ |
| 1601 | |
| 1602 | /* |
| 1603 | * Connsidering the Extension Channel |
| 1604 | * only in a channels |
| 1605 | */ |
| 1606 | switch (operatingBand) { |
| 1607 | case eCSR_DOT11_MODE_11a: |
| 1608 | sap_interference_rssi_count_5G( |
| 1609 | pSpectCh, channelWidth, |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1610 | secondaryChannelOffset, |
| 1611 | centerFreq, |
| 1612 | centerFreq_2, |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1613 | channel_id, |
| 1614 | spectch_start, |
| 1615 | spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1616 | break; |
| 1617 | |
| 1618 | case eCSR_DOT11_MODE_11g: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1619 | sap_interference_rssi_count(pSpectCh, |
| 1620 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1621 | break; |
| 1622 | |
| 1623 | case eCSR_DOT11_MODE_abg: |
Himanshu Agarwal | 4f503b8 | 2018-03-19 12:10:45 +0530 | [diff] [blame] | 1624 | if (pSpectCh->chNum >= |
| 1625 | SIR_11A_CHANNEL_BEGIN) |
| 1626 | sap_interference_rssi_count_5G( |
| 1627 | pSpectCh, channelWidth, |
| 1628 | secondaryChannelOffset, |
| 1629 | centerFreq, |
| 1630 | centerFreq_2, |
| 1631 | channel_id, |
| 1632 | spectch_start, |
| 1633 | spectch_end); |
| 1634 | else |
| 1635 | sap_interference_rssi_count( |
| 1636 | pSpectCh, |
| 1637 | spectch_start, |
| 1638 | spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1639 | break; |
| 1640 | } |
| 1641 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1642 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 1643 | QDF_TRACE_LEVEL_INFO_HIGH, |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1644 | "In %s, channel_id=%d, bssdes.rssi=%d, SpectCh.bssCount=%d, ChannelWidth %d, secondaryChanOffset %d, center frequency %d", |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1645 | __func__, |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1646 | channel_id, |
| 1647 | cur_node->entry->rssi_raw, |
| 1648 | pSpectCh->bssCount, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1649 | pSpectCh->channelWidth, |
| 1650 | secondaryChannelOffset, centerFreq); |
| 1651 | pSpectCh++; |
| 1652 | break; |
| 1653 | } else { |
| 1654 | pSpectCh++; |
| 1655 | } |
| 1656 | } |
| 1657 | |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1658 | qdf_list_peek_next(scan_list, cur_lst, &next_lst); |
| 1659 | cur_lst = next_lst; |
| 1660 | next_lst = NULL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1661 | } |
| 1662 | |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 1663 | qdf_mem_free(bcn_struct); |
| 1664 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1665 | /* Calculate the weights for all channels in the spectrum pSpectCh */ |
| 1666 | pSpectCh = pSpectInfoParams->pSpectCh; |
| 1667 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1668 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1669 | "In %s, Spectrum Channels Weight", __func__); |
| 1670 | |
| 1671 | for (chn_num = 0; chn_num < (pSpectInfoParams->numSpectChans); |
| 1672 | chn_num++) { |
| 1673 | |
| 1674 | /* |
| 1675 | rssi : Maximum received signal strength among all BSS on that channel |
| 1676 | bssCount : Number of BSS on that channel |
| 1677 | */ |
| 1678 | |
| 1679 | rssi = (int8_t) pSpectCh->rssiAgr; |
Himanshu Agarwal | 3697f94 | 2018-06-13 14:04:26 +0530 | [diff] [blame] | 1680 | if (ch_in_pcl(sap_ctx, pSpectCh->chNum)) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1681 | rssi -= PCL_RSSI_DISCOUNT; |
| 1682 | |
Himanshu Agarwal | 3697f94 | 2018-06-13 14:04:26 +0530 | [diff] [blame] | 1683 | if (rssi < SOFTAP_MIN_RSSI) |
| 1684 | rssi = SOFTAP_MIN_RSSI; |
| 1685 | |
hqu | b6441f2 | 2018-08-09 16:15:31 +0800 | [diff] [blame] | 1686 | if (pSpectCh->weight == SAP_ACS_WEIGHT_MAX) { |
| 1687 | pSpectCh->weight_copy = pSpectCh->weight; |
Himanshu Agarwal | fee2e36 | 2018-01-18 20:26:35 +0530 | [diff] [blame] | 1688 | goto debug_info; |
hqu | b6441f2 | 2018-08-09 16:15:31 +0800 | [diff] [blame] | 1689 | } |
Himanshu Agarwal | fee2e36 | 2018-01-18 20:26:35 +0530 | [diff] [blame] | 1690 | |
gaurank kathpalia | 859c936 | 2018-08-02 23:07:21 +0530 | [diff] [blame] | 1691 | /* There may be channels in scanlist, which were not sent to |
| 1692 | * FW for scanning as part of ACS scan list, but they do have an |
| 1693 | * effect on the neighbouring channels, so they help to find a |
| 1694 | * suitable channel, but there weight should be max as they were |
| 1695 | * and not meant to be included in the ACS scan results. |
| 1696 | * So just assign RSSI as -100, bsscount as 0, and weight as max |
| 1697 | * to them, so that they always stay low in sorting of best |
| 1698 | * channles which were included in ACS scan list |
| 1699 | */ |
| 1700 | found = false; |
| 1701 | for (i = 0; i < sap_ctx->num_of_channel; i++) { |
Min Liu | 00956e8 | 2019-07-26 14:49:30 +0800 | [diff] [blame] | 1702 | if (pSpectCh->chNum == wlan_reg_freq_to_chan(mac->pdev, |
| 1703 | sap_ctx->freq_list[i])) { |
gaurank kathpalia | 859c936 | 2018-08-02 23:07:21 +0530 | [diff] [blame] | 1704 | /* Scan channel was included in ACS scan list */ |
| 1705 | found = true; |
| 1706 | break; |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | if (found) |
| 1711 | pSpectCh->weight = |
| 1712 | SAPDFS_NORMALISE_1000 * |
| 1713 | (sapweight_rssi_count(sap_ctx, rssi, |
| 1714 | pSpectCh->bssCount) + sap_weight_channel_status( |
Jeff Johnson | b979444 | 2018-11-22 14:21:08 -0800 | [diff] [blame] | 1715 | sap_ctx, sap_get_channel_status(mac, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 1716 | pSpectCh->chNum))); |
gaurank kathpalia | 859c936 | 2018-08-02 23:07:21 +0530 | [diff] [blame] | 1717 | else { |
| 1718 | pSpectCh->weight = SAP_ACS_WEIGHT_MAX; |
| 1719 | pSpectCh->rssiAgr = SOFTAP_MIN_RSSI; |
| 1720 | rssi = SOFTAP_MIN_RSSI; |
| 1721 | pSpectCh->bssCount = SOFTAP_MIN_COUNT; |
| 1722 | } |
| 1723 | |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 1724 | if (pSpectCh->weight > SAP_ACS_WEIGHT_MAX) |
| 1725 | pSpectCh->weight = SAP_ACS_WEIGHT_MAX; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1726 | pSpectCh->weight_copy = pSpectCh->weight; |
| 1727 | |
Himanshu Agarwal | fee2e36 | 2018-01-18 20:26:35 +0530 | [diff] [blame] | 1728 | debug_info: |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1729 | /* ------ Debug Info ------ */ |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1730 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Himanshu Agarwal | 3697f94 | 2018-06-13 14:04:26 +0530 | [diff] [blame] | 1731 | "In %s, Chan=%d Weight= %d rssiAgr=%d rssi_pcl_discount: %d bssCount=%d", |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1732 | __func__, pSpectCh->chNum, pSpectCh->weight, |
Himanshu Agarwal | 3697f94 | 2018-06-13 14:04:26 +0530 | [diff] [blame] | 1733 | pSpectCh->rssiAgr, rssi, pSpectCh->bssCount); |
wadesong | cb0ded2 | 2018-02-02 17:57:20 +0800 | [diff] [blame] | 1734 | host_log_acs_chan_spect_weight(pSpectCh->chNum, |
| 1735 | (uint16_t)pSpectCh->weight, |
| 1736 | pSpectCh->rssiAgr, |
| 1737 | pSpectCh->bssCount); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1738 | /* ------ Debug Info ------ */ |
| 1739 | pSpectCh++; |
| 1740 | } |
Jeff Johnson | b979444 | 2018-11-22 14:21:08 -0800 | [diff] [blame] | 1741 | sap_clear_channel_status(mac); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | /*========================================================================== |
| 1745 | FUNCTION sap_chan_sel_exit |
| 1746 | |
| 1747 | DESCRIPTION |
| 1748 | Exit function for free out the allocated memory, to be called |
| 1749 | at the end of the dfsSelectChannel function |
| 1750 | |
| 1751 | DEPENDENCIES |
| 1752 | NA. |
| 1753 | |
| 1754 | PARAMETERS |
| 1755 | |
| 1756 | IN |
| 1757 | pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure |
| 1758 | |
| 1759 | RETURN VALUE |
| 1760 | void : NULL |
| 1761 | |
| 1762 | SIDE EFFECTS |
| 1763 | ============================================================================*/ |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1764 | static void sap_chan_sel_exit(tSapChSelSpectInfo *pSpectInfoParams) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1765 | { |
| 1766 | /* Free all the allocated memory */ |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1767 | qdf_mem_free(pSpectInfoParams->pSpectCh); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | /*========================================================================== |
| 1771 | FUNCTION sap_sort_chl_weight |
| 1772 | |
| 1773 | DESCRIPTION |
Jeff Johnson | c7e4d16 | 2018-05-12 16:20:34 -0700 | [diff] [blame] | 1774 | Function to sort the channels with the least weight first for 20MHz channels |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1775 | |
| 1776 | DEPENDENCIES |
| 1777 | NA. |
| 1778 | |
| 1779 | PARAMETERS |
| 1780 | |
| 1781 | IN |
| 1782 | pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure |
| 1783 | |
| 1784 | RETURN VALUE |
| 1785 | void : NULL |
| 1786 | |
| 1787 | SIDE EFFECTS |
| 1788 | ============================================================================*/ |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1789 | static void sap_sort_chl_weight(tSapChSelSpectInfo *pSpectInfoParams) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1790 | { |
| 1791 | tSapSpectChInfo temp; |
| 1792 | |
| 1793 | tSapSpectChInfo *pSpectCh = NULL; |
| 1794 | uint32_t i = 0, j = 0, minWeightIndex = 0; |
| 1795 | |
| 1796 | pSpectCh = pSpectInfoParams->pSpectCh; |
| 1797 | for (i = 0; i < pSpectInfoParams->numSpectChans; i++) { |
| 1798 | minWeightIndex = i; |
| 1799 | for (j = i + 1; j < pSpectInfoParams->numSpectChans; j++) { |
| 1800 | if (pSpectCh[j].weight < |
| 1801 | pSpectCh[minWeightIndex].weight) { |
| 1802 | minWeightIndex = j; |
Yeshwanth Sriram Guntuka | 273889e | 2018-02-16 17:11:46 +0530 | [diff] [blame] | 1803 | } else if (pSpectCh[j].weight == |
| 1804 | pSpectCh[minWeightIndex].weight) { |
| 1805 | if (pSpectCh[j].bssCount < |
| 1806 | pSpectCh[minWeightIndex].bssCount) |
| 1807 | minWeightIndex = j; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1808 | } |
| 1809 | } |
| 1810 | if (minWeightIndex != i) { |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1811 | qdf_mem_copy(&temp, &pSpectCh[minWeightIndex], |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1812 | sizeof(*pSpectCh)); |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1813 | qdf_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1814 | sizeof(*pSpectCh)); |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1815 | qdf_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1816 | } |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | /** |
Jeff Johnson | c7e4d16 | 2018-05-12 16:20:34 -0700 | [diff] [blame] | 1821 | * set_ht80_chl_bit() - to set available channel to ht80 channel bitmap |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 1822 | * @channel_bitmap: Pointer to the chan_bonding_bitmap structure |
| 1823 | * @spect_info_params: Pointer to the tSapChSelSpectInfo structure |
| 1824 | * |
| 1825 | * Return: none |
| 1826 | */ |
| 1827 | static void set_ht80_chl_bit(chan_bonding_bitmap *channel_bitmap, |
| 1828 | tSapChSelSpectInfo *spec_info_params) |
| 1829 | { |
| 1830 | uint8_t i, j; |
| 1831 | tSapSpectChInfo *spec_info; |
| 1832 | int start_channel = 0; |
| 1833 | |
| 1834 | channel_bitmap->chanBondingSet[0].startChannel = |
| 1835 | acs_ht80_channels[0].chStartNum; |
| 1836 | channel_bitmap->chanBondingSet[1].startChannel = |
| 1837 | acs_ht80_channels[1].chStartNum; |
| 1838 | channel_bitmap->chanBondingSet[2].startChannel = |
| 1839 | acs_ht80_channels[2].chStartNum; |
| 1840 | channel_bitmap->chanBondingSet[3].startChannel = |
| 1841 | acs_ht80_channels[3].chStartNum; |
| 1842 | channel_bitmap->chanBondingSet[4].startChannel = |
| 1843 | acs_ht80_channels[4].chStartNum; |
| 1844 | channel_bitmap->chanBondingSet[5].startChannel = |
| 1845 | acs_ht80_channels[5].chStartNum; |
| 1846 | |
| 1847 | spec_info = spec_info_params->pSpectCh; |
| 1848 | for (j = 0; j < spec_info_params->numSpectChans; j++) { |
| 1849 | for (i = 0; i < MAX_80MHZ_BANDS; i++) { |
| 1850 | start_channel = |
| 1851 | channel_bitmap->chanBondingSet[i].startChannel; |
| 1852 | if (spec_info[j].chNum >= start_channel && |
| 1853 | (spec_info[j].chNum <= start_channel + 12)) { |
| 1854 | channel_bitmap->chanBondingSet[i].channelMap |= |
| 1855 | 1 << ((spec_info[j].chNum - |
| 1856 | start_channel)/4); |
| 1857 | break; |
| 1858 | } |
| 1859 | } |
| 1860 | } |
| 1861 | } |
| 1862 | |
| 1863 | /** |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1864 | * sap_sort_chl_weight_ht80() - to sort the channels with the least weight |
| 1865 | * @pSpectInfoParams: Pointer to the tSapChSelSpectInfo structure |
| 1866 | * |
Jeff Johnson | c7e4d16 | 2018-05-12 16:20:34 -0700 | [diff] [blame] | 1867 | * Function to sort the channels with the least weight first for HT80 channels |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1868 | * |
| 1869 | * Return: none |
| 1870 | */ |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1871 | static void sap_sort_chl_weight_ht80(tSapChSelSpectInfo *pSpectInfoParams) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1872 | { |
| 1873 | uint8_t i, j, n; |
| 1874 | tSapSpectChInfo *pSpectInfo; |
| 1875 | uint8_t minIdx; |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 1876 | int start_channel = 0; |
| 1877 | chan_bonding_bitmap *channel_bitmap; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1878 | |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 1879 | channel_bitmap = qdf_mem_malloc(sizeof(chan_bonding_bitmap)); |
Arif Hussain | 256cc28 | 2018-10-03 14:10:44 -0700 | [diff] [blame] | 1880 | if (!channel_bitmap) |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 1881 | return; |
Arif Hussain | 256cc28 | 2018-10-03 14:10:44 -0700 | [diff] [blame] | 1882 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1883 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 1884 | /* for each HT80 channel, calculate the combined weight of the |
| 1885 | four 20MHz weight */ |
| 1886 | for (i = 0; i < ARRAY_SIZE(acs_ht80_channels); i++) { |
| 1887 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 1888 | if (pSpectInfo[j].chNum == |
| 1889 | acs_ht80_channels[i].chStartNum) |
| 1890 | break; |
| 1891 | } |
| 1892 | if (j == pSpectInfoParams->numSpectChans) |
| 1893 | continue; |
| 1894 | |
| 1895 | if (!(((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 1].chNum) && |
| 1896 | ((pSpectInfo[j].chNum + 8) == |
| 1897 | pSpectInfo[j + 2].chNum) && |
| 1898 | ((pSpectInfo[j].chNum + 12) == |
| 1899 | pSpectInfo[j + 3].chNum))) { |
| 1900 | /* |
| 1901 | * some channels does not exist in pSectInfo array, |
| 1902 | * skip this channel and those in the same HT80 width |
| 1903 | */ |
| 1904 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 4; |
| 1905 | if ((pSpectInfo[j].chNum + 4) == |
| 1906 | pSpectInfo[j + 1].chNum) |
| 1907 | pSpectInfo[j + 1].weight = |
| 1908 | SAP_ACS_WEIGHT_MAX * 4; |
| 1909 | if ((pSpectInfo[j].chNum + 8) == |
| 1910 | pSpectInfo[j + 2].chNum) |
| 1911 | pSpectInfo[j + 2].weight = |
| 1912 | SAP_ACS_WEIGHT_MAX * 4; |
| 1913 | if ((pSpectInfo[j].chNum + 12) == |
| 1914 | pSpectInfo[j + 3].chNum) |
| 1915 | pSpectInfo[j + 3].weight = |
| 1916 | SAP_ACS_WEIGHT_MAX * 4; |
| 1917 | continue; |
| 1918 | } |
| 1919 | /*found the channel, add the 4 adjacent channels' weight */ |
| 1920 | acs_ht80_channels[i].weight = pSpectInfo[j].weight + |
| 1921 | pSpectInfo[j + 1].weight + pSpectInfo[j + 2].weight + |
| 1922 | pSpectInfo[j + 3].weight; |
| 1923 | /* find best channel among 4 channels as the primary channel */ |
| 1924 | if ((pSpectInfo[j].weight + pSpectInfo[j + 1].weight) < |
| 1925 | (pSpectInfo[j + 2].weight + pSpectInfo[j + 3].weight)) { |
| 1926 | /* lower 2 channels are better choice */ |
| 1927 | if (pSpectInfo[j].weight < pSpectInfo[j + 1].weight) |
| 1928 | minIdx = 0; |
| 1929 | else |
| 1930 | minIdx = 1; |
| 1931 | } else if (pSpectInfo[j + 2].weight <= |
| 1932 | pSpectInfo[j + 3].weight) { |
| 1933 | /* upper 2 channels are better choice */ |
| 1934 | minIdx = 2; |
| 1935 | } else { |
| 1936 | minIdx = 3; |
| 1937 | } |
| 1938 | |
| 1939 | /* |
| 1940 | * set all 4 channels to max value first, then reset the |
| 1941 | * best channel as the selected primary channel, update its |
| 1942 | * weightage with the combined weight value |
| 1943 | */ |
| 1944 | for (n = 0; n < 4; n++) |
| 1945 | pSpectInfo[j + n].weight = SAP_ACS_WEIGHT_MAX * 4; |
| 1946 | |
| 1947 | pSpectInfo[j + minIdx].weight = acs_ht80_channels[i].weight; |
| 1948 | } |
| 1949 | |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 1950 | /* |
| 1951 | * mark the weight of the channel that can't satisfy 80MHZ |
| 1952 | * as max value, so that it will be sorted to the bottom |
| 1953 | */ |
| 1954 | set_ht80_chl_bit(channel_bitmap, pSpectInfoParams); |
| 1955 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 1956 | for (i = 0; i < MAX_80MHZ_BANDS; i++) { |
| 1957 | start_channel = |
| 1958 | channel_bitmap->chanBondingSet[i].startChannel; |
| 1959 | if (pSpectInfo[j].chNum >= start_channel && |
| 1960 | (pSpectInfo[j].chNum <= |
| 1961 | start_channel + 12) && |
| 1962 | channel_bitmap->chanBondingSet[i].channelMap != |
| 1963 | SAP_80MHZ_MASK) |
| 1964 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 4; |
| 1965 | } |
| 1966 | } |
| 1967 | |
Himanshu Agarwal | 75e7441 | 2018-02-01 20:51:47 +0530 | [diff] [blame] | 1968 | /* |
| 1969 | * Assign max weight(SAP_ACS_WEIGHT_MAX * 4) to 2.4 Ghz channels |
| 1970 | * and channel 165 as they cannot be part of a 80Mhz channel bonding. |
| 1971 | */ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1972 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 1973 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
Himanshu Agarwal | 75e7441 | 2018-02-01 20:51:47 +0530 | [diff] [blame] | 1974 | if ((pSpectInfo[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_1) && |
| 1975 | pSpectInfo[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_14)) || |
gaurank kathpalia | 1dea75b | 2019-01-10 13:53:43 +0530 | [diff] [blame] | 1976 | (pSpectInfo[j].chNum >= CHANNEL_165)) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1977 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 4; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1978 | } |
| 1979 | |
Manishekar Chandrasekaran | 44e334f | 2016-05-30 16:42:50 +0530 | [diff] [blame] | 1980 | sap_sort_chl_weight(pSpectInfoParams); |
| 1981 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1982 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 1983 | for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1984 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1985 | FL("Channel=%d Weight= %d rssi=%d bssCount=%d"), |
| 1986 | pSpectInfo->chNum, pSpectInfo->weight, |
| 1987 | pSpectInfo->rssiAgr, pSpectInfo->bssCount); |
| 1988 | pSpectInfo++; |
| 1989 | } |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 1990 | qdf_mem_free(channel_bitmap); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | /** |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1994 | * sap_sort_chl_weight_vht160() - to sort the channels with the least weight |
| 1995 | * @pSpectInfoParams: Pointer to the tSapChSelSpectInfo structure |
| 1996 | * |
Jeff Johnson | c7e4d16 | 2018-05-12 16:20:34 -0700 | [diff] [blame] | 1997 | * Function to sort the channels with the least weight first for VHT160 channels |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1998 | * |
| 1999 | * Return: none |
| 2000 | */ |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 2001 | static void sap_sort_chl_weight_vht160(tSapChSelSpectInfo *pSpectInfoParams) |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2002 | { |
| 2003 | uint8_t i, j, n, idx; |
| 2004 | tSapSpectChInfo *pSpectInfo; |
| 2005 | uint8_t minIdx; |
| 2006 | |
| 2007 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2008 | /* for each VHT160 channel, calculate the combined weight of the |
| 2009 | 8 20MHz weight */ |
| 2010 | for (i = 0; i < ARRAY_SIZE(acs_vht160_channels); i++) { |
| 2011 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 2012 | if (pSpectInfo[j].chNum == |
| 2013 | acs_vht160_channels[i].chStartNum) |
| 2014 | break; |
| 2015 | } |
| 2016 | if (j == pSpectInfoParams->numSpectChans) |
| 2017 | continue; |
| 2018 | |
| 2019 | if (!(((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 1].chNum) && |
| 2020 | ((pSpectInfo[j].chNum + 8) == |
| 2021 | pSpectInfo[j + 2].chNum) && |
| 2022 | ((pSpectInfo[j].chNum + 12) == |
| 2023 | pSpectInfo[j + 3].chNum) && |
| 2024 | ((pSpectInfo[j].chNum + 16) == |
| 2025 | pSpectInfo[j + 4].chNum) && |
| 2026 | ((pSpectInfo[j].chNum + 20) == |
| 2027 | pSpectInfo[j + 5].chNum) && |
| 2028 | ((pSpectInfo[j].chNum + 24) == |
| 2029 | pSpectInfo[j + 6].chNum) && |
| 2030 | ((pSpectInfo[j].chNum + 28) == |
| 2031 | pSpectInfo[j + 7].chNum))) { |
| 2032 | /* |
| 2033 | * some channels does not exist in pSectInfo array, |
| 2034 | * skip this channel and those in the same VHT160 width |
| 2035 | */ |
| 2036 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 8; |
| 2037 | if ((pSpectInfo[j].chNum + 4) == |
| 2038 | pSpectInfo[j + 1].chNum) |
| 2039 | pSpectInfo[j + 1].weight = |
| 2040 | SAP_ACS_WEIGHT_MAX * 8; |
| 2041 | if ((pSpectInfo[j].chNum + 8) == |
| 2042 | pSpectInfo[j + 2].chNum) |
| 2043 | pSpectInfo[j + 2].weight = |
| 2044 | SAP_ACS_WEIGHT_MAX * 8; |
| 2045 | if ((pSpectInfo[j].chNum + 12) == |
| 2046 | pSpectInfo[j + 3].chNum) |
| 2047 | pSpectInfo[j + 3].weight = |
| 2048 | SAP_ACS_WEIGHT_MAX * 8; |
| 2049 | if ((pSpectInfo[j].chNum + 16) == |
| 2050 | pSpectInfo[j + 4].chNum) |
| 2051 | pSpectInfo[j + 4].weight = |
| 2052 | SAP_ACS_WEIGHT_MAX * 8; |
| 2053 | if ((pSpectInfo[j].chNum + 20) == |
| 2054 | pSpectInfo[j + 5].chNum) |
| 2055 | pSpectInfo[j + 5].weight = |
| 2056 | SAP_ACS_WEIGHT_MAX * 8; |
| 2057 | if ((pSpectInfo[j].chNum + 24) == |
| 2058 | pSpectInfo[j + 6].chNum) |
| 2059 | pSpectInfo[j + 6].weight = |
| 2060 | SAP_ACS_WEIGHT_MAX * 8; |
| 2061 | if ((pSpectInfo[j].chNum + 28) == |
| 2062 | pSpectInfo[j + 7].chNum) |
| 2063 | pSpectInfo[j + 7].weight = |
| 2064 | SAP_ACS_WEIGHT_MAX * 8; |
| 2065 | continue; |
| 2066 | } |
| 2067 | /*found the channel, add the 7 adjacent channels' weight */ |
| 2068 | acs_vht160_channels[i].weight = pSpectInfo[j].weight + |
| 2069 | pSpectInfo[j + 1].weight + pSpectInfo[j + 2].weight + |
| 2070 | pSpectInfo[j + 3].weight + pSpectInfo[j + 4].weight + |
| 2071 | pSpectInfo[j + 5].weight + pSpectInfo[j + 6].weight + |
| 2072 | pSpectInfo[j + 7].weight; |
| 2073 | |
| 2074 | /* find best channel among 8 channels as the primary channel */ |
| 2075 | if ((pSpectInfo[j].weight + pSpectInfo[j + 1].weight + |
| 2076 | pSpectInfo[j + 2].weight + pSpectInfo[j + 3].weight) > |
| 2077 | (pSpectInfo[j + 4].weight + pSpectInfo[j + 5].weight + |
| 2078 | pSpectInfo[j + 6].weight + pSpectInfo[j + 7].weight)) |
| 2079 | idx = 4; |
| 2080 | else |
| 2081 | idx = 0; |
| 2082 | /* find best channel among 4 channels as the primary channel */ |
| 2083 | if ((pSpectInfo[j + idx].weight + |
| 2084 | pSpectInfo[j + idx + 1].weight) < |
| 2085 | (pSpectInfo[j + idx + 2].weight + |
| 2086 | pSpectInfo[j + idx + 3].weight)) { |
| 2087 | /* lower 2 channels are better choice */ |
| 2088 | if (pSpectInfo[j + idx].weight < |
| 2089 | pSpectInfo[j + idx + 1].weight) |
| 2090 | minIdx = 0 + idx; |
| 2091 | else |
| 2092 | minIdx = 1 + idx; |
| 2093 | } else if (pSpectInfo[j + idx + 2].weight <= |
| 2094 | pSpectInfo[j + idx + 3].weight) { |
| 2095 | /* upper 2 channels are better choice */ |
| 2096 | minIdx = 2 + idx; |
| 2097 | } else { |
| 2098 | minIdx = 3 + idx; |
| 2099 | } |
| 2100 | |
| 2101 | /* |
| 2102 | * set all 8 channels to max value first, then reset the |
| 2103 | * best channel as the selected primary channel, update its |
| 2104 | * weightage with the combined weight value |
| 2105 | */ |
| 2106 | for (n = 0; n < 8; n++) |
| 2107 | pSpectInfo[j + n].weight = SAP_ACS_WEIGHT_MAX * 8; |
| 2108 | |
| 2109 | pSpectInfo[j + minIdx].weight = acs_vht160_channels[i].weight; |
| 2110 | } |
| 2111 | |
Himanshu Agarwal | 75e7441 | 2018-02-01 20:51:47 +0530 | [diff] [blame] | 2112 | /* |
| 2113 | * Assign max weight(SAP_ACS_WEIGHT_MAX * 8) to 2.4 Ghz channels |
Kiran Kumar Lokere | 1a43bcf | 2018-05-15 15:51:58 -0700 | [diff] [blame] | 2114 | * and channel 132-173 as they cannot be part of a 160Mhz channel |
Himanshu Agarwal | 75e7441 | 2018-02-01 20:51:47 +0530 | [diff] [blame] | 2115 | * bonding. |
| 2116 | */ |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2117 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2118 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
Himanshu Agarwal | 75e7441 | 2018-02-01 20:51:47 +0530 | [diff] [blame] | 2119 | if ((pSpectInfo[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_1) && |
| 2120 | pSpectInfo[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_14)) || |
| 2121 | (pSpectInfo[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_132) && |
Kiran Kumar Lokere | 1a43bcf | 2018-05-15 15:51:58 -0700 | [diff] [blame] | 2122 | pSpectInfo[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_173))) |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2123 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 8; |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
Manishekar Chandrasekaran | 44e334f | 2016-05-30 16:42:50 +0530 | [diff] [blame] | 2126 | sap_sort_chl_weight(pSpectInfoParams); |
| 2127 | |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2128 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2129 | for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2130 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2131 | FL("Channel=%d Weight= %d rssi=%d bssCount=%d"), |
| 2132 | pSpectInfo->chNum, pSpectInfo->weight, |
| 2133 | pSpectInfo->rssiAgr, pSpectInfo->bssCount); |
| 2134 | pSpectInfo++; |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | /** |
Himanshu Agarwal | 91c5c0f | 2018-02-13 14:40:56 +0530 | [diff] [blame] | 2139 | * sap_allocate_max_weight_ht40_24_g() - allocate max weight for 40Mhz |
| 2140 | * to all 2.4Ghz channels |
| 2141 | * @spect_info_params: Pointer to the tSapChSelSpectInfo structure |
| 2142 | * |
| 2143 | * Return: none |
| 2144 | */ |
| 2145 | static void sap_allocate_max_weight_ht40_24_g( |
| 2146 | tSapChSelSpectInfo *spect_info_params) |
| 2147 | { |
| 2148 | tSapSpectChInfo *spect_info; |
| 2149 | uint8_t j; |
| 2150 | |
| 2151 | /* |
| 2152 | * Assign max weight for 40Mhz (SAP_ACS_WEIGHT_MAX * 2) to all |
| 2153 | * 2.4 Ghz channels |
| 2154 | */ |
| 2155 | spect_info = spect_info_params->pSpectCh; |
| 2156 | for (j = 0; j < spect_info_params->numSpectChans; j++) { |
| 2157 | if ((spect_info[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_1) && |
| 2158 | spect_info[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_14))) |
| 2159 | spect_info[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | /** |
| 2164 | * sap_allocate_max_weight_ht40_5_g() - allocate max weight for 40Mhz |
| 2165 | * to all 5Ghz channels |
| 2166 | * @spect_info_params: Pointer to the tSapChSelSpectInfo structure |
| 2167 | * |
| 2168 | * Return: none |
| 2169 | */ |
| 2170 | static void sap_allocate_max_weight_ht40_5_g( |
| 2171 | tSapChSelSpectInfo *spect_info_params) |
| 2172 | { |
| 2173 | tSapSpectChInfo *spect_info; |
| 2174 | uint8_t j; |
| 2175 | |
| 2176 | /* |
| 2177 | * Assign max weight for 40Mhz (SAP_ACS_WEIGHT_MAX * 2) to all |
| 2178 | * 5 Ghz channels |
| 2179 | */ |
| 2180 | spect_info = spect_info_params->pSpectCh; |
| 2181 | for (j = 0; j < spect_info_params->numSpectChans; j++) { |
| 2182 | if ((spect_info[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_36) && |
Kiran Kumar Lokere | 1a43bcf | 2018-05-15 15:51:58 -0700 | [diff] [blame] | 2183 | spect_info[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_173))) |
Himanshu Agarwal | 91c5c0f | 2018-02-13 14:40:56 +0530 | [diff] [blame] | 2184 | spect_info[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2185 | } |
| 2186 | } |
| 2187 | |
| 2188 | /** |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2189 | * sap_sort_chl_weight_ht40_24_g() - to sort channel with the least weight |
| 2190 | * @pSpectInfoParams: Pointer to the tSapChSelSpectInfo structure |
| 2191 | * |
Jeff Johnson | c7e4d16 | 2018-05-12 16:20:34 -0700 | [diff] [blame] | 2192 | * Function to sort the channels with the least weight first for HT40 channels |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2193 | * |
| 2194 | * Return: none |
| 2195 | */ |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2196 | static void sap_sort_chl_weight_ht40_24_g(tSapChSelSpectInfo *pSpectInfoParams, |
| 2197 | v_REGDOMAIN_t domain) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2198 | { |
| 2199 | uint8_t i, j; |
| 2200 | tSapSpectChInfo *pSpectInfo; |
| 2201 | uint32_t tmpWeight1, tmpWeight2; |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 2202 | uint32_t ht40plus2gendch = 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2203 | |
| 2204 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2205 | /* |
| 2206 | * for each HT40 channel, calculate the combined weight of the |
| 2207 | * two 20MHz weight |
| 2208 | */ |
| 2209 | for (i = 0; i < ARRAY_SIZE(acs_ht40_channels24_g); i++) { |
| 2210 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 2211 | if (pSpectInfo[j].chNum == |
| 2212 | acs_ht40_channels24_g[i].chStartNum) |
| 2213 | break; |
| 2214 | } |
| 2215 | if (j == pSpectInfoParams->numSpectChans) |
| 2216 | continue; |
| 2217 | |
| 2218 | if (!((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 4].chNum)) { |
| 2219 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2220 | continue; |
| 2221 | } |
| 2222 | /* |
| 2223 | * check if there is another channel combination possiblity |
| 2224 | * e.g., {1, 5} & {5, 9} |
| 2225 | */ |
| 2226 | if ((pSpectInfo[j + 4].chNum + 4) == pSpectInfo[j + 8].chNum) { |
| 2227 | /* need to compare two channel pairs */ |
| 2228 | tmpWeight1 = pSpectInfo[j].weight + |
| 2229 | pSpectInfo[j + 4].weight; |
| 2230 | tmpWeight2 = pSpectInfo[j + 4].weight + |
| 2231 | pSpectInfo[j + 8].weight; |
| 2232 | if (tmpWeight1 <= tmpWeight2) { |
| 2233 | if (pSpectInfo[j].weight <= |
| 2234 | pSpectInfo[j + 4].weight) { |
| 2235 | pSpectInfo[j].weight = |
| 2236 | tmpWeight1; |
| 2237 | pSpectInfo[j + 4].weight = |
| 2238 | SAP_ACS_WEIGHT_MAX * 2; |
| 2239 | pSpectInfo[j + 8].weight = |
| 2240 | SAP_ACS_WEIGHT_MAX * 2; |
| 2241 | } else { |
| 2242 | pSpectInfo[j + 4].weight = |
| 2243 | tmpWeight1; |
| 2244 | /* for secondary channel selection */ |
| 2245 | pSpectInfo[j].weight = |
| 2246 | SAP_ACS_WEIGHT_MAX * 2 |
| 2247 | - 1; |
| 2248 | pSpectInfo[j + 8].weight = |
| 2249 | SAP_ACS_WEIGHT_MAX * 2; |
| 2250 | } |
| 2251 | } else { |
| 2252 | if (pSpectInfo[j + 4].weight <= |
| 2253 | pSpectInfo[j + 8].weight) { |
| 2254 | pSpectInfo[j + 4].weight = |
| 2255 | tmpWeight2; |
| 2256 | pSpectInfo[j].weight = |
| 2257 | SAP_ACS_WEIGHT_MAX * 2; |
| 2258 | /* for secondary channel selection */ |
| 2259 | pSpectInfo[j + 8].weight = |
| 2260 | SAP_ACS_WEIGHT_MAX * 2 |
| 2261 | - 1; |
| 2262 | } else { |
| 2263 | pSpectInfo[j + 8].weight = |
| 2264 | tmpWeight2; |
| 2265 | pSpectInfo[j].weight = |
| 2266 | SAP_ACS_WEIGHT_MAX * 2; |
| 2267 | pSpectInfo[j + 4].weight = |
| 2268 | SAP_ACS_WEIGHT_MAX * 2; |
| 2269 | } |
| 2270 | } |
| 2271 | } else { |
bings | aa6f96a | 2017-09-11 09:49:43 +0800 | [diff] [blame] | 2272 | tmpWeight1 = pSpectInfo[j].weight_copy + |
| 2273 | pSpectInfo[j + 4].weight_copy; |
| 2274 | if (pSpectInfo[j].weight_copy <= |
| 2275 | pSpectInfo[j + 4].weight_copy) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2276 | pSpectInfo[j].weight = tmpWeight1; |
| 2277 | pSpectInfo[j + 4].weight = |
| 2278 | SAP_ACS_WEIGHT_MAX * 2; |
| 2279 | } else { |
| 2280 | pSpectInfo[j + 4].weight = tmpWeight1; |
| 2281 | pSpectInfo[j].weight = |
| 2282 | SAP_ACS_WEIGHT_MAX * 2; |
| 2283 | } |
| 2284 | } |
| 2285 | } |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 2286 | /* |
| 2287 | * Every channel should be checked. Add the check for the omissive |
| 2288 | * channel. Mark the channel whose combination can't satisfy 40MHZ |
| 2289 | * as max value, so that it will be sorted to the bottom. |
| 2290 | */ |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2291 | if (REGDOMAIN_FCC == domain) |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 2292 | ht40plus2gendch = HT40PLUS_2G_FCC_CH_END; |
| 2293 | else |
| 2294 | ht40plus2gendch = HT40PLUS_2G_EURJAP_CH_END; |
| 2295 | for (i = HT40MINUS_2G_CH_START; i <= ht40plus2gendch; i++) { |
| 2296 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 2297 | if (pSpectInfo[j].chNum == i && |
| 2298 | ((pSpectInfo[j].chNum + 4) != |
| 2299 | pSpectInfo[j+4].chNum) && |
| 2300 | ((pSpectInfo[j].chNum - 4) != |
| 2301 | pSpectInfo[j-4].chNum)) |
| 2302 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2303 | } |
| 2304 | } |
| 2305 | for (i = ht40plus2gendch + 1; i <= HT40MINUS_2G_CH_END; i++) { |
| 2306 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 2307 | if (pSpectInfo[j].chNum == i && |
| 2308 | (pSpectInfo[j].chNum - 4) != |
| 2309 | pSpectInfo[j-4].chNum) |
| 2310 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2311 | } |
| 2312 | } |
Himanshu Agarwal | 91c5c0f | 2018-02-13 14:40:56 +0530 | [diff] [blame] | 2313 | |
| 2314 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2315 | for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) { |
| 2316 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 2317 | "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d", |
| 2318 | __func__, pSpectInfo->chNum, pSpectInfo->weight, |
| 2319 | pSpectInfo->rssiAgr, pSpectInfo->bssCount); |
| 2320 | pSpectInfo++; |
| 2321 | } |
| 2322 | |
Manishekar Chandrasekaran | 44e334f | 2016-05-30 16:42:50 +0530 | [diff] [blame] | 2323 | sap_sort_chl_weight(pSpectInfoParams); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | /*========================================================================== |
| 2327 | FUNCTION sap_sort_chl_weight_ht40_5_g |
| 2328 | |
| 2329 | DESCRIPTION |
Jeff Johnson | c7e4d16 | 2018-05-12 16:20:34 -0700 | [diff] [blame] | 2330 | Function to sort the channels with the least weight first for HT40 channels |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2331 | |
| 2332 | DEPENDENCIES |
| 2333 | NA. |
| 2334 | |
| 2335 | PARAMETERS |
| 2336 | |
| 2337 | IN |
| 2338 | pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure |
| 2339 | |
| 2340 | RETURN VALUE |
| 2341 | void : NULL |
| 2342 | |
| 2343 | SIDE EFFECTS |
| 2344 | ============================================================================*/ |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 2345 | static void sap_sort_chl_weight_ht40_5_g(tSapChSelSpectInfo *pSpectInfoParams) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2346 | { |
| 2347 | uint8_t i, j; |
| 2348 | tSapSpectChInfo *pSpectInfo; |
| 2349 | |
| 2350 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2351 | /*for each HT40 channel, calculate the combined weight of the |
| 2352 | two 20MHz weight */ |
| 2353 | for (i = 0; i < ARRAY_SIZE(acs_ht40_channels5_g); i++) { |
| 2354 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 2355 | if (pSpectInfo[j].chNum == |
| 2356 | acs_ht40_channels5_g[i].chStartNum) |
| 2357 | break; |
| 2358 | } |
| 2359 | if (j == pSpectInfoParams->numSpectChans) |
| 2360 | continue; |
| 2361 | |
| 2362 | /* found the channel, add the two adjacent channels' weight */ |
| 2363 | if ((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 1].chNum) { |
| 2364 | acs_ht40_channels5_g[i].weight = pSpectInfo[j].weight + |
| 2365 | pSpectInfo[j + 1].weight; |
| 2366 | /* select better of the adjact channel as the primary channel */ |
| 2367 | if (pSpectInfo[j].weight <= pSpectInfo[j + 1].weight) { |
| 2368 | pSpectInfo[j].weight = |
| 2369 | acs_ht40_channels5_g[i].weight; |
| 2370 | /* mark the adjacent channel's weight as max value so |
| 2371 | that it will be sorted to the bottom */ |
| 2372 | pSpectInfo[j + 1].weight = |
| 2373 | SAP_ACS_WEIGHT_MAX * 2; |
| 2374 | } else { |
| 2375 | pSpectInfo[j + 1].weight = |
| 2376 | acs_ht40_channels5_g[i].weight; |
| 2377 | /* mark the adjacent channel's weight as max value so |
| 2378 | that it will be sorted to the bottom */ |
| 2379 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2380 | } |
| 2381 | |
| 2382 | } else |
| 2383 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2384 | } |
| 2385 | |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 2386 | /* |
| 2387 | *Every channel should be checked. Add the check for the omissive |
| 2388 | * channel. Mark the channel whose combination can't satisfy 40MHZ |
| 2389 | * as max value, so that it will be sorted to the bottom |
| 2390 | */ |
| 2391 | for (j = 1; j < pSpectInfoParams->numSpectChans; j++) { |
| 2392 | for (i = 0; i < ARRAY_SIZE(acs_ht40_channels5_g); i++) { |
| 2393 | if (pSpectInfo[j].chNum == |
| 2394 | (acs_ht40_channels5_g[i].chStartNum + |
| 2395 | 4) && |
| 2396 | pSpectInfo[j - 1].chNum != |
| 2397 | acs_ht40_channels5_g[i].chStartNum) { |
| 2398 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2399 | break; |
| 2400 | } |
| 2401 | } |
| 2402 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2403 | /* avoid channel 165 by setting its weight to max */ |
| 2404 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2405 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
gaurank kathpalia | 1dea75b | 2019-01-10 13:53:43 +0530 | [diff] [blame] | 2406 | if (pSpectInfo[j].chNum >= CHANNEL_165) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2407 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2408 | break; |
| 2409 | } |
| 2410 | } |
| 2411 | |
| 2412 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2413 | for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2414 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2415 | "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d", |
| 2416 | __func__, pSpectInfo->chNum, pSpectInfo->weight, |
| 2417 | pSpectInfo->rssiAgr, pSpectInfo->bssCount); |
| 2418 | pSpectInfo++; |
| 2419 | } |
| 2420 | |
| 2421 | sap_sort_chl_weight(pSpectInfoParams); |
| 2422 | } |
| 2423 | |
| 2424 | /*========================================================================== |
| 2425 | FUNCTION sap_sort_chl_weight_all |
| 2426 | |
| 2427 | DESCRIPTION |
Jeff Johnson | c7e4d16 | 2018-05-12 16:20:34 -0700 | [diff] [blame] | 2428 | Function to sort the channels with the least weight first |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2429 | |
| 2430 | DEPENDENCIES |
| 2431 | NA. |
| 2432 | |
| 2433 | PARAMETERS |
| 2434 | |
| 2435 | IN |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 2436 | sap_ctx : Pointer to the struct sap_context *structure |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2437 | pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure |
| 2438 | |
| 2439 | RETURN VALUE |
| 2440 | void : NULL |
| 2441 | |
| 2442 | SIDE EFFECTS |
| 2443 | ============================================================================*/ |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 2444 | static void sap_sort_chl_weight_all(struct sap_context *sap_ctx, |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 2445 | tSapChSelSpectInfo *pSpectInfoParams, |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2446 | uint32_t operatingBand, |
| 2447 | v_REGDOMAIN_t domain) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2448 | { |
| 2449 | tSapSpectChInfo *pSpectCh = NULL; |
| 2450 | uint32_t j = 0; |
| 2451 | #ifndef SOFTAP_CHANNEL_RANGE |
| 2452 | uint32_t i = 0; |
| 2453 | #endif |
| 2454 | |
| 2455 | pSpectCh = pSpectInfoParams->pSpectCh; |
| 2456 | #ifdef SOFTAP_CHANNEL_RANGE |
| 2457 | |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 2458 | switch (sap_ctx->acs_cfg->ch_width) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2459 | case CH_WIDTH_40MHZ: |
Himanshu Agarwal | 91c5c0f | 2018-02-13 14:40:56 +0530 | [diff] [blame] | 2460 | /* |
| 2461 | * Assign max weight to all 5Ghz channels when operating band |
| 2462 | * is 11g and to all 2.4Ghz channels when operating band is 11a |
| 2463 | * or 11abg to avoid selection in ACS algorithm for starting SAP |
| 2464 | */ |
| 2465 | if (eCSR_DOT11_MODE_11g == operatingBand) { |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2466 | sap_sort_chl_weight_ht40_24_g(pSpectInfoParams, domain); |
Himanshu Agarwal | 91c5c0f | 2018-02-13 14:40:56 +0530 | [diff] [blame] | 2467 | sap_allocate_max_weight_ht40_5_g(pSpectInfoParams); |
| 2468 | } else { |
| 2469 | sap_allocate_max_weight_ht40_24_g(pSpectInfoParams); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2470 | sap_sort_chl_weight_ht40_5_g(pSpectInfoParams); |
| 2471 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2472 | break; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2473 | case CH_WIDTH_80MHZ: |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2474 | case CH_WIDTH_80P80MHZ: |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2475 | sap_sort_chl_weight_ht80(pSpectInfoParams); |
| 2476 | break; |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2477 | case CH_WIDTH_160MHZ: |
| 2478 | sap_sort_chl_weight_vht160(pSpectInfoParams); |
| 2479 | break; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2480 | case CH_WIDTH_20MHZ: |
| 2481 | default: |
| 2482 | /* Sorting the channels as per weights as 20MHz channels */ |
| 2483 | sap_sort_chl_weight(pSpectInfoParams); |
| 2484 | } |
| 2485 | |
| 2486 | #else |
| 2487 | /* Sorting the channels as per weights */ |
| 2488 | for (i = 0; i < SPECT_24GHZ_CH_COUNT; i++) { |
| 2489 | minWeightIndex = i; |
| 2490 | for (j = i + 1; j < SPECT_24GHZ_CH_COUNT; j++) { |
| 2491 | if (pSpectCh[j].weight < |
| 2492 | pSpectCh[minWeightIndex].weight) { |
| 2493 | minWeightIndex = j; |
| 2494 | } |
| 2495 | } |
| 2496 | if (minWeightIndex != i) { |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 2497 | qdf_mem_copy(&temp, &pSpectCh[minWeightIndex], |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2498 | sizeof(*pSpectCh)); |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 2499 | qdf_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2500 | sizeof(*pSpectCh)); |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 2501 | qdf_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2502 | } |
| 2503 | } |
| 2504 | #endif |
| 2505 | |
| 2506 | /* For testing */ |
Ravi Joshi | 9788fcd | 2018-02-13 15:12:22 -0800 | [diff] [blame] | 2507 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2508 | "In %s, Sorted Spectrum Channels Weight", __func__); |
| 2509 | pSpectCh = pSpectInfoParams->pSpectCh; |
| 2510 | for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) { |
Ravi Joshi | 9788fcd | 2018-02-13 15:12:22 -0800 | [diff] [blame] | 2511 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2512 | "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d", |
| 2513 | __func__, pSpectCh->chNum, pSpectCh->weight, |
| 2514 | pSpectCh->rssiAgr, pSpectCh->bssCount); |
| 2515 | pSpectCh++; |
| 2516 | } |
| 2517 | |
| 2518 | } |
| 2519 | |
Naveen Rawat | bec64d9 | 2017-09-13 14:35:21 -0700 | [diff] [blame] | 2520 | /** |
| 2521 | * sap_is_ch_non_overlap() - returns true if non-overlapping channel |
| 2522 | * @sap_ctx: Sap context |
| 2523 | * @ch: channel number |
| 2524 | * |
| 2525 | * Returns: true if non-overlapping (1, 6, 11) channel, false otherwise |
| 2526 | */ |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 2527 | static bool sap_is_ch_non_overlap(struct sap_context *sap_ctx, uint16_t ch) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2528 | { |
Naveen Rawat | bec64d9 | 2017-09-13 14:35:21 -0700 | [diff] [blame] | 2529 | if (sap_ctx->enableOverLapCh) |
Srinivas Girigowda | 74a66d6 | 2017-06-21 23:28:25 -0700 | [diff] [blame] | 2530 | return true; |
Naveen Rawat | bec64d9 | 2017-09-13 14:35:21 -0700 | [diff] [blame] | 2531 | |
| 2532 | if ((ch == CHANNEL_1) || (ch == CHANNEL_6) || (ch == CHANNEL_11)) |
Srinivas Girigowda | 74a66d6 | 2017-06-21 23:28:25 -0700 | [diff] [blame] | 2533 | return true; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2534 | |
Srinivas Girigowda | 74a66d6 | 2017-06-21 23:28:25 -0700 | [diff] [blame] | 2535 | return false; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2536 | } |
| 2537 | |
Dustin Brown | 0ce56d3 | 2016-10-17 16:18:03 -0700 | [diff] [blame] | 2538 | #ifdef FEATURE_WLAN_CH_AVOID |
Rachit Kankane | 057097f | 2019-04-22 15:16:03 +0530 | [diff] [blame] | 2539 | static uint8_t get_channel_from_safe_channels(mac_handle_t mac_handle, |
| 2540 | struct sap_context *sap_ctx) |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2541 | { |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2542 | uint8_t i, first_safe_ch_in_range = SAP_CHANNEL_NOT_SELECTED; |
Rachit Kankane | 057097f | 2019-04-22 15:16:03 +0530 | [diff] [blame] | 2543 | enum channel_state ch_type; |
Dustin Brown | 0ce56d3 | 2016-10-17 16:18:03 -0700 | [diff] [blame] | 2544 | uint32_t start_ch_num = sap_ctx->acs_cfg->start_ch; |
| 2545 | uint32_t end_ch_num = sap_ctx->acs_cfg->end_ch; |
Rachit Kankane | 057097f | 2019-04-22 15:16:03 +0530 | [diff] [blame] | 2546 | struct mac_context *mac_ctx = MAC_CONTEXT(mac_handle); |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2547 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2548 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2549 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 2550 | if ((safe_channels[i].channelNumber < start_ch_num) || |
| 2551 | (safe_channels[i].channelNumber > end_ch_num)) |
| 2552 | continue; |
| 2553 | |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2554 | ch_type = wlan_reg_get_channel_state(mac_ctx->pdev, |
| 2555 | safe_channels[i].channelNumber); |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2556 | |
| 2557 | if ((ch_type == CHANNEL_STATE_DISABLE) || |
| 2558 | (ch_type == CHANNEL_STATE_INVALID)) |
| 2559 | continue; |
Arif Hussain | 88d1fdd | 2018-09-26 16:12:24 -0700 | [diff] [blame] | 2560 | if ((!mac_ctx->mlme_cfg->dfs_cfg.dfs_master_capable) && |
| 2561 | (CHANNEL_STATE_DFS == ch_type)) { |
Rachit Kankane | 057097f | 2019-04-22 15:16:03 +0530 | [diff] [blame] | 2562 | sap_debug("DFS master mode disabled. Skip DFS channel %d", |
| 2563 | safe_channels[i].channelNumber); |
Kondabattini, Ganesh | 13bb4b1 | 2016-09-04 16:16:53 +0530 | [diff] [blame] | 2564 | continue; |
| 2565 | } |
Agrawal Ashish | 6563461 | 2016-08-18 13:24:32 +0530 | [diff] [blame] | 2566 | if ((sap_ctx->dfs_mode == ACS_DFS_MODE_DISABLE) && |
| 2567 | (CHANNEL_STATE_DFS == ch_type)) |
| 2568 | continue; |
Kondabattini, Ganesh | 13bb4b1 | 2016-09-04 16:16:53 +0530 | [diff] [blame] | 2569 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2570 | if (safe_channels[i].isSafe == true) { |
Rachit Kankane | 057097f | 2019-04-22 15:16:03 +0530 | [diff] [blame] | 2571 | sap_debug("channel %d in the configuration is safe", |
| 2572 | safe_channels[i].channelNumber); |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2573 | first_safe_ch_in_range = safe_channels[i].channelNumber; |
| 2574 | break; |
| 2575 | } |
| 2576 | |
Rachit Kankane | 057097f | 2019-04-22 15:16:03 +0530 | [diff] [blame] | 2577 | sap_debug("channel %d in the configuration is unsafe", |
| 2578 | safe_channels[i].channelNumber); |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2579 | } |
| 2580 | |
| 2581 | /* if no channel selected return SAP_CHANNEL_NOT_SELECTED */ |
| 2582 | return first_safe_ch_in_range; |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2583 | } |
Dustin Brown | 0ce56d3 | 2016-10-17 16:18:03 -0700 | [diff] [blame] | 2584 | #else |
Rachit Kankane | 057097f | 2019-04-22 15:16:03 +0530 | [diff] [blame] | 2585 | static uint8_t get_channel_from_safe_channels(mac_handle_t mac_handle, |
| 2586 | struct sap_context *sap_ctx) |
Dustin Brown | 0ce56d3 | 2016-10-17 16:18:03 -0700 | [diff] [blame] | 2587 | { |
| 2588 | uint32_t start_ch_num = sap_ctx->acs_cfg->start_ch; |
| 2589 | |
Dustin Brown | 0ce56d3 | 2016-10-17 16:18:03 -0700 | [diff] [blame] | 2590 | sap_ctx->acs_cfg->pri_ch = start_ch_num; |
| 2591 | sap_ctx->acs_cfg->ht_sec_ch = 0; |
| 2592 | |
| 2593 | /* pick the first channel in configured range */ |
| 2594 | return start_ch_num; |
| 2595 | } |
| 2596 | #endif /* FEATURE_WLAN_CH_AVOID */ |
Rachit Kankane | 057097f | 2019-04-22 15:16:03 +0530 | [diff] [blame] | 2597 | /** |
| 2598 | * sap_select_channel_no_scan_result() - select SAP channel when no scan results |
| 2599 | * are available. |
| 2600 | * @sap_ctx: Sap context |
| 2601 | * |
| 2602 | * Returns: channel number if success, 0 otherwise |
| 2603 | */ |
| 2604 | static uint8_t sap_select_channel_no_scan_result(mac_handle_t mac_handle, |
| 2605 | struct sap_context *sap_ctx) |
| 2606 | { |
| 2607 | uint8_t i, channel = SAP_CHANNEL_NOT_SELECTED; |
| 2608 | uint32_t start_ch_num = sap_ctx->acs_cfg->start_ch; |
| 2609 | uint32_t end_ch_num = sap_ctx->acs_cfg->end_ch; |
| 2610 | |
| 2611 | sap_debug("start - end: %d - %d", start_ch_num, end_ch_num); |
| 2612 | /* get a channel in PCL and within the range */ |
| 2613 | for (i = 0; i < sap_ctx->acs_cfg->pcl_ch_count; i++) { |
| 2614 | if ((sap_ctx->acs_cfg->pcl_channels[i] < start_ch_num) || |
| 2615 | (sap_ctx->acs_cfg->pcl_channels[i] > end_ch_num)) |
| 2616 | continue; |
| 2617 | |
| 2618 | channel = sap_ctx->acs_cfg->pcl_channels[i]; |
| 2619 | break; |
| 2620 | } |
| 2621 | |
| 2622 | if (channel == SAP_CHANNEL_NOT_SELECTED) |
| 2623 | channel = get_channel_from_safe_channels(mac_handle, sap_ctx); |
| 2624 | |
| 2625 | return channel; |
| 2626 | } |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2627 | |
Jeff Johnson | 7730fbb | 2018-11-08 13:48:27 -0800 | [diff] [blame] | 2628 | uint8_t sap_select_channel(mac_handle_t mac_handle, |
| 2629 | struct sap_context *sap_ctx, |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 2630 | qdf_list_t *scan_list) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2631 | { |
| 2632 | /* DFS param object holding all the data req by the algo */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2633 | tSapChSelSpectInfo spect_info_obj = { NULL, 0 }; |
| 2634 | tSapChSelSpectInfo *spect_info = &spect_info_obj; |
| 2635 | uint8_t best_ch_num = SAP_CHANNEL_NOT_SELECTED; |
Jeff Johnson | 6c33683 | 2019-03-26 09:09:08 -0700 | [diff] [blame] | 2636 | uint32_t best_ch_weight = SAP_ACS_WEIGHT_MAX; |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 2637 | uint32_t ht40plus2gendch = 0; |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2638 | v_REGDOMAIN_t domain; |
Arif Hussain | 21ad434 | 2017-12-21 12:00:54 -0800 | [diff] [blame] | 2639 | uint8_t country[CDS_COUNTRY_CODE_LEN + 1]; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2640 | #ifdef SOFTAP_CHANNEL_RANGE |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2641 | uint8_t count; |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2642 | uint32_t start_ch_num, end_ch_num, tmp_ch_num, operating_band = 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2643 | #endif |
Jeff Johnson | c59ef8b | 2018-12-02 12:01:21 -0800 | [diff] [blame] | 2644 | struct mac_context *mac_ctx; |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2645 | |
Jeff Johnson | a0619e4 | 2018-11-28 17:43:00 -0800 | [diff] [blame] | 2646 | mac_ctx = MAC_CONTEXT(mac_handle); |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2647 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2648 | "In %s, Running SAP Ch Select", __func__); |
| 2649 | |
Jeff Johnson | 7730fbb | 2018-11-08 13:48:27 -0800 | [diff] [blame] | 2650 | sap_update_unsafe_channel_list(mac_handle, sap_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2651 | |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 2652 | /* |
| 2653 | * If ACS weight is not enabled on noise_floor/channel_free/tx_power, |
| 2654 | * then skip acs process if no bss found. |
| 2655 | */ |
Rachit Kankane | 2dba675 | 2019-05-20 14:55:31 +0530 | [diff] [blame] | 2656 | if ((!scan_list || !qdf_list_size(scan_list)) && |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 2657 | !(sap_ctx->auto_channel_select_weight & 0xffff00)) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2658 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2659 | FL("No external AP present")); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2660 | |
| 2661 | #ifndef SOFTAP_CHANNEL_RANGE |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2662 | return SAP_CHANNEL_NOT_SELECTED; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2663 | #else |
Jeff Johnson | 7730fbb | 2018-11-08 13:48:27 -0800 | [diff] [blame] | 2664 | return sap_select_channel_no_scan_result(mac_handle, sap_ctx); |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2665 | #endif |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2666 | } |
| 2667 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2668 | /* Initialize the structure pointed by spect_info */ |
Jeff Johnson | 7730fbb | 2018-11-08 13:48:27 -0800 | [diff] [blame] | 2669 | if (sap_chan_sel_init(mac_handle, spect_info, sap_ctx) != true) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2670 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR, |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2671 | FL("Ch Select initialization failed")); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2672 | return SAP_CHANNEL_NOT_SELECTED; |
| 2673 | } |
| 2674 | /* Compute the weight of the entire spectrum in the operating band */ |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 2675 | sap_compute_spect_weight(spect_info, mac_handle, scan_list, sap_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2676 | |
| 2677 | #ifdef FEATURE_AP_MCC_CH_AVOIDANCE |
| 2678 | /* process avoid channel IE to collect all channels to avoid */ |
Abhishek Singh | d1cd4ae | 2019-05-10 11:22:21 +0530 | [diff] [blame] | 2679 | sap_process_avoid_ie(mac_handle, sap_ctx, scan_list, spect_info); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2680 | #endif /* FEATURE_AP_MCC_CH_AVOIDANCE */ |
| 2681 | |
Paul Zhang | 0f85b41 | 2018-01-18 19:14:51 +0800 | [diff] [blame] | 2682 | wlan_reg_read_current_country(mac_ctx->psoc, country); |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2683 | wlan_reg_get_domain_from_country_code(&domain, country, SOURCE_DRIVER); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2684 | #ifdef SOFTAP_CHANNEL_RANGE |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2685 | start_ch_num = sap_ctx->acs_cfg->start_ch; |
| 2686 | end_ch_num = sap_ctx->acs_cfg->end_ch; |
| 2687 | SET_ACS_BAND(operating_band, sap_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2688 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2689 | /* Sort the ch lst as per the computed weights, lesser weight first. */ |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2690 | sap_sort_chl_weight_all(sap_ctx, spect_info, operating_band, domain); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2691 | |
| 2692 | /*Loop till get the best channel in the given range */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2693 | for (count = 0; count < spect_info->numSpectChans; count++) { |
| 2694 | if ((start_ch_num > spect_info->pSpectCh[count].chNum) || |
| 2695 | (end_ch_num < spect_info->pSpectCh[count].chNum)) |
| 2696 | continue; |
| 2697 | |
| 2698 | if (best_ch_num == SAP_CHANNEL_NOT_SELECTED) { |
| 2699 | best_ch_num = spect_info->pSpectCh[count].chNum; |
| 2700 | /* check if best_ch_num is in preferred channel list */ |
| 2701 | best_ch_num = |
| 2702 | sap_select_preferred_channel_from_channel_list( |
| 2703 | best_ch_num, sap_ctx, spect_info); |
| 2704 | /* if not in preferred ch lst, go to nxt best ch */ |
| 2705 | if (best_ch_num == SAP_CHANNEL_NOT_SELECTED) |
| 2706 | continue; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2707 | |
| 2708 | #ifdef FEATURE_AP_MCC_CH_AVOIDANCE |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2709 | /* |
| 2710 | * Weight of the channels(device's AP is operating) |
Jeff Johnson | 2cc31fd | 2018-05-05 23:54:23 -0700 | [diff] [blame] | 2711 | * increased to MAX+1 so that they will be chosen only |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2712 | * when there is no other best channel to choose |
| 2713 | */ |
| 2714 | if (sap_check_in_avoid_ch_list(sap_ctx, best_ch_num)) { |
| 2715 | best_ch_num = SAP_CHANNEL_NOT_SELECTED; |
| 2716 | continue; |
| 2717 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2718 | #endif |
| 2719 | |
Jeff Johnson | 6c33683 | 2019-03-26 09:09:08 -0700 | [diff] [blame] | 2720 | best_ch_weight = |
| 2721 | spect_info->pSpectCh[count].weight_copy; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2722 | } |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2723 | |
| 2724 | if (best_ch_num == SAP_CHANNEL_NOT_SELECTED) |
| 2725 | continue; |
| 2726 | |
Tushnim Bhattacharyya | 03103fd | 2017-06-23 10:48:52 -0700 | [diff] [blame] | 2727 | if (operating_band != eCSR_DOT11_MODE_11g) { |
| 2728 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 2729 | QDF_TRACE_LEVEL_INFO_HIGH, |
| 2730 | "operating_band %d", operating_band); |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2731 | continue; |
Tushnim Bhattacharyya | 03103fd | 2017-06-23 10:48:52 -0700 | [diff] [blame] | 2732 | } |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2733 | |
| 2734 | /* Give preference to Non-overlap channels */ |
Naveen Rawat | bec64d9 | 2017-09-13 14:35:21 -0700 | [diff] [blame] | 2735 | if (false == sap_is_ch_non_overlap(sap_ctx, |
Tushnim Bhattacharyya | 03103fd | 2017-06-23 10:48:52 -0700 | [diff] [blame] | 2736 | spect_info->pSpectCh[count].chNum)) { |
| 2737 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 2738 | QDF_TRACE_LEVEL_INFO_HIGH, |
Naveen Rawat | bec64d9 | 2017-09-13 14:35:21 -0700 | [diff] [blame] | 2739 | FL("ch: %d skipped as its overlapping ch"), |
| 2740 | spect_info->pSpectCh[count].chNum); |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2741 | continue; |
Tushnim Bhattacharyya | 03103fd | 2017-06-23 10:48:52 -0700 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | if (wlan_reg_is_dfs_ch(mac_ctx->pdev, |
| 2745 | spect_info->pSpectCh[count].chNum) && |
| 2746 | policy_mgr_disallow_mcc(mac_ctx->psoc, |
| 2747 | spect_info->pSpectCh[count].chNum)) { |
| 2748 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 2749 | QDF_TRACE_LEVEL_INFO_HIGH, |
| 2750 | "No DFS MCC"); |
| 2751 | continue; |
| 2752 | } |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2753 | |
Jeff Johnson | 6c33683 | 2019-03-26 09:09:08 -0700 | [diff] [blame] | 2754 | if (spect_info->pSpectCh[count].weight_copy > best_ch_weight) |
bings | 14d1d3b | 2017-08-03 11:14:29 +0800 | [diff] [blame] | 2755 | continue; |
| 2756 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2757 | tmp_ch_num = spect_info->pSpectCh[count].chNum; |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 2758 | tmp_ch_num = sap_channel_in_acs_channel_list( |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2759 | tmp_ch_num, sap_ctx, spect_info); |
| 2760 | if (tmp_ch_num == SAP_CHANNEL_NOT_SELECTED) |
| 2761 | continue; |
| 2762 | |
| 2763 | best_ch_num = tmp_ch_num; |
| 2764 | break; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2765 | } |
| 2766 | #else |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2767 | /* Sort the ch lst as per the computed weights, lesser weight first. */ |
Jeff Johnson | 7730fbb | 2018-11-08 13:48:27 -0800 | [diff] [blame] | 2768 | sap_sort_chl_weight_all(sap_ctx, mac_handle, spect_info); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2769 | /* Get the first channel in sorted array as best 20M Channel */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2770 | best_ch_num = (uint8_t) spect_info->pSpectCh[0].chNum; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2771 | /* Select Best Channel from Channel List if Configured */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2772 | best_ch_num = sap_select_preferred_channel_from_channel_list( |
| 2773 | best_ch_num, sap_ctx, spect_info); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2774 | #endif |
| 2775 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2776 | /* |
| 2777 | * in case the best channel seleted is not in PCL and there is another |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2778 | * channel which has same weightage and is in PCL, choose the one in |
| 2779 | * PCL |
| 2780 | */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2781 | for (count = 0; count < spect_info->numSpectChans; count++) { |
| 2782 | if (!ch_in_pcl(sap_ctx, spect_info->pSpectCh[count].chNum) || |
Jeff Johnson | 6c33683 | 2019-03-26 09:09:08 -0700 | [diff] [blame] | 2783 | (spect_info->pSpectCh[count].weight != best_ch_weight)) |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2784 | continue; |
| 2785 | |
| 2786 | if (sap_select_preferred_channel_from_channel_list( |
| 2787 | spect_info->pSpectCh[count].chNum, sap_ctx, spect_info) |
| 2788 | == SAP_CHANNEL_NOT_SELECTED) |
| 2789 | continue; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2790 | |
| 2791 | #ifdef FEATURE_AP_MCC_CH_AVOIDANCE |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2792 | if (sap_check_in_avoid_ch_list(sap_ctx, best_ch_num)) |
| 2793 | continue; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2794 | #endif |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2795 | best_ch_num = spect_info->pSpectCh[count].chNum; |
| 2796 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 2797 | FL("change best channel to %d in PCL"), best_ch_num); |
| 2798 | break; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2799 | } |
| 2800 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2801 | sap_ctx->acs_cfg->pri_ch = best_ch_num; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2802 | /* determine secondary channel for 2.4G channel 5, 6, 7 in HT40 */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2803 | if ((operating_band != eCSR_DOT11_MODE_11g) || |
| 2804 | (sap_ctx->acs_cfg->ch_width != CH_WIDTH_40MHZ)) |
| 2805 | goto sap_ch_sel_end; |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2806 | if (REGDOMAIN_FCC == domain) |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 2807 | ht40plus2gendch = HT40PLUS_2G_FCC_CH_END; |
| 2808 | else |
| 2809 | ht40plus2gendch = HT40PLUS_2G_EURJAP_CH_END; |
| 2810 | if ((best_ch_num >= HT40MINUS_2G_CH_START) && |
| 2811 | (best_ch_num <= ht40plus2gendch)) { |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2812 | int weight_below, weight_above, i; |
| 2813 | tSapSpectChInfo *pspect_info; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2814 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2815 | weight_below = weight_above = SAP_ACS_WEIGHT_MAX; |
| 2816 | pspect_info = spect_info->pSpectCh; |
| 2817 | for (i = 0; i < spect_info->numSpectChans; i++) { |
| 2818 | if (pspect_info[i].chNum == (best_ch_num - 4)) |
| 2819 | weight_below = pspect_info[i].weight; |
| 2820 | if (pspect_info[i].chNum == (best_ch_num + 4)) |
| 2821 | weight_above = pspect_info[i].weight; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2822 | } |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2823 | |
| 2824 | if (weight_below < weight_above) |
| 2825 | sap_ctx->acs_cfg->ht_sec_ch = |
| 2826 | sap_ctx->acs_cfg->pri_ch - 4; |
| 2827 | else |
| 2828 | sap_ctx->acs_cfg->ht_sec_ch = |
| 2829 | sap_ctx->acs_cfg->pri_ch + 4; |
| 2830 | } else if (best_ch_num >= 1 && best_ch_num <= 4) { |
| 2831 | sap_ctx->acs_cfg->ht_sec_ch = sap_ctx->acs_cfg->pri_ch + 4; |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 2832 | } else if (best_ch_num >= ht40plus2gendch && best_ch_num <= |
| 2833 | HT40MINUS_2G_CH_END) { |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2834 | sap_ctx->acs_cfg->ht_sec_ch = sap_ctx->acs_cfg->pri_ch - 4; |
| 2835 | } else if (best_ch_num == 14) { |
| 2836 | sap_ctx->acs_cfg->ht_sec_ch = 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2837 | } |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2838 | sap_ctx->secondary_ch = sap_ctx->acs_cfg->ht_sec_ch; |
| 2839 | |
| 2840 | sap_ch_sel_end: |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2841 | /* Free all the allocated memory */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2842 | sap_chan_sel_exit(spect_info); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2843 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2844 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2845 | FL("Running SAP Ch select Completed, Ch=%d"), best_ch_num); |
Jeff Johnson | 6c33683 | 2019-03-26 09:09:08 -0700 | [diff] [blame] | 2846 | host_log_acs_best_chan(best_ch_num, best_ch_weight); |
wadesong | cb0ded2 | 2018-02-02 17:57:20 +0800 | [diff] [blame] | 2847 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2848 | if (best_ch_num > 0 && best_ch_num <= 252) |
| 2849 | return best_ch_num; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2850 | else |
| 2851 | return SAP_CHANNEL_NOT_SELECTED; |
| 2852 | } |