1 /* 2 * Copyright (c) 2014-2020 The Linux Foundation. All rights reserved. 3 * 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 19 /** 20 * DOC: reg_build_chan_list.c 21 * This file defines the API to build master and current channel list. 22 */ 23 24 #include <wlan_cmn.h> 25 #include <reg_services_public_struct.h> 26 #include <wlan_objmgr_psoc_obj.h> 27 #include <wlan_objmgr_pdev_obj.h> 28 #include "reg_priv_objs.h" 29 #include "reg_utils.h" 30 #include "reg_callbacks.h" 31 #include "reg_services_common.h" 32 #include "reg_db.h" 33 #include "reg_db_parser.h" 34 #include "reg_offload_11d_scan.h" 35 #include <scheduler_api.h> 36 #include "reg_build_chan_list.h" 37 #include <qdf_platform.h> 38 39 #define MAX_PWR_FCC_CHAN_12 8 40 #define MAX_PWR_FCC_CHAN_13 2 41 #define CHAN_144_CENT_FREQ 5720 42 43 /** 44 * reg_fill_channel_info() - Populate TX power, antenna gain, channel state, 45 * channel flags, min and max bandwidth to master channel list. 46 * @chan_enum: Channel enum. 47 * @reg_rule: Pointer to regulatory rule which has tx power and antenna gain. 48 * @master_list: Pointer to master channel list. 49 * @min_bw: minimum bandwidth to be used for given channel. 50 */ 51 static void reg_fill_channel_info(enum channel_enum chan_enum, 52 struct cur_reg_rule *reg_rule, 53 struct regulatory_channel *master_list, 54 uint16_t min_bw) 55 { 56 master_list[chan_enum].chan_flags &= ~REGULATORY_CHAN_DISABLED; 57 58 master_list[chan_enum].tx_power = reg_rule->reg_power; 59 master_list[chan_enum].ant_gain = reg_rule->ant_gain; 60 master_list[chan_enum].state = CHANNEL_STATE_ENABLE; 61 62 if (reg_rule->flags & REGULATORY_CHAN_NO_IR) { 63 master_list[chan_enum].chan_flags |= REGULATORY_CHAN_NO_IR; 64 master_list[chan_enum].state = CHANNEL_STATE_DFS; 65 } 66 67 if (reg_rule->flags & REGULATORY_CHAN_RADAR) { 68 master_list[chan_enum].chan_flags |= REGULATORY_CHAN_RADAR; 69 master_list[chan_enum].state = CHANNEL_STATE_DFS; 70 } 71 72 if (reg_rule->flags & REGULATORY_CHAN_INDOOR_ONLY) 73 master_list[chan_enum].chan_flags |= 74 REGULATORY_CHAN_INDOOR_ONLY; 75 76 if (reg_rule->flags & REGULATORY_CHAN_NO_OFDM) 77 master_list[chan_enum].chan_flags |= REGULATORY_CHAN_NO_OFDM; 78 79 master_list[chan_enum].min_bw = min_bw; 80 if (master_list[chan_enum].max_bw == 20) 81 master_list[chan_enum].max_bw = reg_rule->max_bw; 82 } 83 84 /** 85 * reg_populate_band_channels() - For all the valid regdb channels in the master 86 * channel list, find the regulatory rules and call reg_fill_channel_info() to 87 * populate master channel list with txpower, antennagain, BW info, etc. 88 * @start_chan: Start channel enum. 89 * @end_chan: End channel enum. 90 * @rule_start_ptr: Pointer to regulatory rules. 91 * @num_reg_rules: Number of regulatory rules. 92 * @min_reg_bw: Minimum regulatory bandwidth. 93 * @mas_chan_list: Pointer to master channel list. 94 */ 95 static void reg_populate_band_channels(enum channel_enum start_chan, 96 enum channel_enum end_chan, 97 struct cur_reg_rule *rule_start_ptr, 98 uint32_t num_reg_rules, 99 uint16_t min_reg_bw, 100 struct regulatory_channel *mas_chan_list) 101 { 102 struct cur_reg_rule *found_rule_ptr; 103 struct cur_reg_rule *cur_rule_ptr; 104 struct regulatory_channel; 105 enum channel_enum chan_enum; 106 uint32_t rule_num, bw; 107 uint16_t max_bw; 108 uint16_t min_bw; 109 110 for (chan_enum = start_chan; chan_enum <= end_chan; chan_enum++) { 111 found_rule_ptr = NULL; 112 113 max_bw = QDF_MIN((uint16_t)20, channel_map[chan_enum].max_bw); 114 min_bw = QDF_MAX(min_reg_bw, channel_map[chan_enum].min_bw); 115 116 if (channel_map[chan_enum].chan_num == INVALID_CHANNEL_NUM) 117 continue; 118 119 for (bw = max_bw; bw >= min_bw; bw = bw / 2) { 120 for (rule_num = 0, cur_rule_ptr = rule_start_ptr; 121 rule_num < num_reg_rules; 122 cur_rule_ptr++, rule_num++) { 123 if ((cur_rule_ptr->start_freq <= 124 mas_chan_list[chan_enum].center_freq - 125 bw / 2) && 126 (cur_rule_ptr->end_freq >= 127 mas_chan_list[chan_enum].center_freq + 128 bw / 2) && (min_bw <= bw)) { 129 found_rule_ptr = cur_rule_ptr; 130 break; 131 } 132 } 133 134 if (found_rule_ptr) 135 break; 136 } 137 138 if (found_rule_ptr) { 139 mas_chan_list[chan_enum].max_bw = bw; 140 reg_fill_channel_info(chan_enum, found_rule_ptr, 141 mas_chan_list, min_bw); 142 /* Disable 2.4 Ghz channels that dont have 20 mhz bw */ 143 if (start_chan == MIN_24GHZ_CHANNEL && 144 mas_chan_list[chan_enum].max_bw < 20) { 145 mas_chan_list[chan_enum].chan_flags |= 146 REGULATORY_CHAN_DISABLED; 147 mas_chan_list[chan_enum].state = 148 CHANNEL_STATE_DISABLE; 149 } 150 } 151 } 152 } 153 154 /** 155 * reg_update_max_bw_per_rule() - Update max bandwidth value for given regrules. 156 * @num_reg_rules: Number of regulatory rules. 157 * @reg_rule_start: Pointer to regulatory rules. 158 * @max_bw: Maximum bandwidth 159 */ 160 static void reg_update_max_bw_per_rule(uint32_t num_reg_rules, 161 struct cur_reg_rule *reg_rule_start, 162 uint16_t max_bw) 163 { 164 uint32_t count; 165 166 for (count = 0; count < num_reg_rules; count++) 167 reg_rule_start[count].max_bw = 168 min(reg_rule_start[count].max_bw, max_bw); 169 } 170 171 /** 172 * reg_do_auto_bw_correction() - Calculate and update the maximum bandwidth 173 * value. 174 * @num_reg_rules: Number of regulatory rules. 175 * @reg_rule_ptr: Pointer to regulatory rules. 176 * @max_bw: Maximum bandwidth 177 */ 178 static void reg_do_auto_bw_correction(uint32_t num_reg_rules, 179 struct cur_reg_rule *reg_rule_ptr, 180 uint16_t max_bw) 181 { 182 uint32_t count; 183 uint16_t new_bw; 184 185 for (count = 0; count < num_reg_rules - 1; count++) { 186 if (reg_rule_ptr[count].end_freq == 187 reg_rule_ptr[count + 1].start_freq) { 188 new_bw = QDF_MIN(max_bw, reg_rule_ptr[count].max_bw + 189 reg_rule_ptr[count + 1].max_bw); 190 reg_rule_ptr[count].max_bw = new_bw; 191 reg_rule_ptr[count + 1].max_bw = new_bw; 192 } 193 } 194 } 195 196 /** 197 * reg_modify_chan_list_for_dfs_channels() - disable the DFS channels if 198 * dfs_enable set to false. 199 * @chan_list: Pointer to regulatory channel list. 200 * @dfs_enabled: if false, then disable the DFS channels. 201 */ 202 static void reg_modify_chan_list_for_dfs_channels( 203 struct regulatory_channel *chan_list, bool dfs_enabled) 204 { 205 enum channel_enum chan_enum; 206 207 if (dfs_enabled) 208 return; 209 210 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) { 211 if (chan_list[chan_enum].state == CHANNEL_STATE_DFS) { 212 chan_list[chan_enum].state = CHANNEL_STATE_DISABLE; 213 chan_list[chan_enum].chan_flags |= 214 REGULATORY_CHAN_DISABLED; 215 } 216 } 217 } 218 219 /** 220 * reg_modify_chan_list_for_indoor_channels() - Disable the indoor channels if 221 * indoor_chan_enabled flag is set to false. 222 * @pdev_priv_obj: Pointer to regulatory private pdev structure. 223 */ 224 static void reg_modify_chan_list_for_indoor_channels( 225 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 226 { 227 enum channel_enum chan_enum; 228 struct regulatory_channel *chan_list = pdev_priv_obj->cur_chan_list; 229 230 if (!pdev_priv_obj->indoor_chan_enabled) { 231 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) { 232 if (REGULATORY_CHAN_INDOOR_ONLY & 233 chan_list[chan_enum].chan_flags) { 234 chan_list[chan_enum].state = 235 CHANNEL_STATE_DFS; 236 chan_list[chan_enum].chan_flags |= 237 REGULATORY_CHAN_NO_IR; 238 } 239 } 240 } 241 242 if (pdev_priv_obj->force_ssc_disable_indoor_channel && 243 pdev_priv_obj->sap_state) { 244 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) { 245 if (REGULATORY_CHAN_INDOOR_ONLY & 246 chan_list[chan_enum].chan_flags) { 247 chan_list[chan_enum].state = 248 CHANNEL_STATE_DISABLE; 249 chan_list[chan_enum].chan_flags |= 250 REGULATORY_CHAN_DISABLED; 251 } 252 } 253 } 254 } 255 256 #ifdef CONFIG_BAND_6GHZ 257 static void reg_modify_chan_list_for_band_6G( 258 struct regulatory_channel *chan_list) 259 { 260 enum channel_enum chan_enum; 261 262 reg_debug("disabling 6G"); 263 for (chan_enum = MIN_6GHZ_CHANNEL; 264 chan_enum <= MAX_6GHZ_CHANNEL; chan_enum++) { 265 chan_list[chan_enum].chan_flags |= 266 REGULATORY_CHAN_DISABLED; 267 chan_list[chan_enum].state = CHANNEL_STATE_DISABLE; 268 } 269 } 270 #else 271 static inline void reg_modify_chan_list_for_band_6G( 272 struct regulatory_channel *chan_list) 273 { 274 } 275 #endif 276 277 /** 278 * reg_modify_chan_list_for_band() - Based on the input band bitmap, either 279 * disable 2GHz, 5GHz, or 6GHz channels. 280 * @chan_list: Pointer to regulatory channel list. 281 * @band_bitmap: Input bitmap of reg_wifi_band values. 282 */ 283 static void reg_modify_chan_list_for_band(struct regulatory_channel *chan_list, 284 uint32_t band_bitmap) 285 { 286 enum channel_enum chan_enum; 287 288 if (!band_bitmap) 289 return; 290 291 if (!(band_bitmap & BIT(REG_BAND_5G))) { 292 reg_debug("disabling 5G"); 293 for (chan_enum = MIN_5GHZ_CHANNEL; 294 chan_enum <= MAX_5GHZ_CHANNEL; chan_enum++) { 295 chan_list[chan_enum].chan_flags |= 296 REGULATORY_CHAN_DISABLED; 297 chan_list[chan_enum].state = CHANNEL_STATE_DISABLE; 298 } 299 } 300 301 if (!(band_bitmap & BIT(REG_BAND_2G))) { 302 reg_debug("disabling 2G"); 303 for (chan_enum = MIN_24GHZ_CHANNEL; 304 chan_enum <= MAX_24GHZ_CHANNEL; chan_enum++) { 305 chan_list[chan_enum].chan_flags |= 306 REGULATORY_CHAN_DISABLED; 307 chan_list[chan_enum].state = CHANNEL_STATE_DISABLE; 308 } 309 } 310 311 if (!(band_bitmap & BIT(REG_BAND_6G))) 312 reg_modify_chan_list_for_band_6G(chan_list); 313 314 } 315 316 /** 317 * reg_modify_chan_list_for_fcc_channel() - Set maximum FCC txpower for channel 318 * 12 and 13 if set_fcc_channel flag is set to true. 319 * @chan_list: Pointer to regulatory channel list. 320 * @set_fcc_channel: If this flag is set to true, then set the max FCC txpower 321 * for channel 12 and 13. 322 */ 323 static void reg_modify_chan_list_for_fcc_channel( 324 struct regulatory_channel *chan_list, bool set_fcc_channel) 325 { 326 enum channel_enum chan_enum; 327 328 if (!set_fcc_channel) 329 return; 330 331 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) { 332 if (chan_list[chan_enum].center_freq == CHAN_12_CENT_FREQ) 333 chan_list[chan_enum].tx_power = MAX_PWR_FCC_CHAN_12; 334 335 if (chan_list[chan_enum].center_freq == CHAN_13_CENT_FREQ) 336 chan_list[chan_enum].tx_power = MAX_PWR_FCC_CHAN_13; 337 } 338 } 339 340 /** 341 * reg_modify_chan_list_for_chan_144() - Disable channel 144 if en_chan_144 flag 342 * is set to false. 343 * @chan_list: Pointer to regulatory channel list. 344 * @en_chan_144: if false, then disable channel 144. 345 */ 346 static void reg_modify_chan_list_for_chan_144( 347 struct regulatory_channel *chan_list, bool en_chan_144) 348 { 349 enum channel_enum chan_enum; 350 351 if (en_chan_144) 352 return; 353 354 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) { 355 if (chan_list[chan_enum].center_freq == CHAN_144_CENT_FREQ) { 356 chan_list[chan_enum].chan_flags |= 357 REGULATORY_CHAN_DISABLED; 358 chan_list[chan_enum].state = CHANNEL_STATE_DISABLE; 359 } 360 } 361 } 362 363 /** 364 * reg_modify_chan_list_for_nol_list() - Disable the channel if nol_chan flag is 365 * set. 366 * @chan_list: Pointer to regulatory channel list. 367 */ 368 static void reg_modify_chan_list_for_nol_list( 369 struct regulatory_channel *chan_list) 370 { 371 enum channel_enum chan_enum; 372 373 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) { 374 if (chan_list[chan_enum].nol_chan) { 375 chan_list[chan_enum].state = CHANNEL_STATE_DISABLE; 376 chan_list[chan_enum].chan_flags |= 377 REGULATORY_CHAN_DISABLED; 378 } 379 } 380 } 381 382 /** 383 * reg_find_low_limit_chan_enum() - Find low limit 2G and 5G channel enums. 384 * @chan_list: Pointer to regulatory channel list. 385 * @low_freq: low limit frequency. 386 * @low_limit: pointer to output low limit enum. 387 * 388 * Return: None 389 */ 390 static void reg_find_low_limit_chan_enum( 391 struct regulatory_channel *chan_list, qdf_freq_t low_freq, 392 uint32_t *low_limit) 393 { 394 enum channel_enum chan_enum; 395 uint16_t min_bw; 396 uint16_t max_bw; 397 qdf_freq_t center_freq; 398 399 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) { 400 min_bw = chan_list[chan_enum].min_bw; 401 max_bw = chan_list[chan_enum].max_bw; 402 center_freq = chan_list[chan_enum].center_freq; 403 404 if ((center_freq - min_bw / 2) >= low_freq) { 405 if ((center_freq - max_bw / 2) < low_freq) { 406 if (max_bw <= 20) 407 max_bw = ((center_freq - low_freq) * 2); 408 if (max_bw < min_bw) 409 max_bw = min_bw; 410 chan_list[chan_enum].max_bw = max_bw; 411 } 412 *low_limit = chan_enum; 413 break; 414 } 415 } 416 } 417 418 /** 419 * reg_find_high_limit_chan_enum() - Find high limit 2G and 5G channel enums. 420 * @chan_list: Pointer to regulatory channel list. 421 * @high_freq: high limit frequency. 422 * @high_limit: pointer to output high limit enum. 423 * 424 * Return: None 425 */ 426 static void reg_find_high_limit_chan_enum( 427 struct regulatory_channel *chan_list, qdf_freq_t high_freq, 428 uint32_t *high_limit) 429 { 430 enum channel_enum chan_enum; 431 uint16_t min_bw; 432 uint16_t max_bw; 433 qdf_freq_t center_freq; 434 435 for (chan_enum = NUM_CHANNELS - 1; chan_enum >= 0; chan_enum--) { 436 min_bw = chan_list[chan_enum].min_bw; 437 max_bw = chan_list[chan_enum].max_bw; 438 center_freq = chan_list[chan_enum].center_freq; 439 440 if (center_freq + min_bw / 2 <= high_freq) { 441 if ((center_freq + max_bw / 2) > high_freq) { 442 if (max_bw <= 20) 443 max_bw = ((high_freq - 444 center_freq) * 2); 445 if (max_bw < min_bw) 446 max_bw = min_bw; 447 chan_list[chan_enum].max_bw = max_bw; 448 } 449 *high_limit = chan_enum; 450 break; 451 } 452 453 if (chan_enum == 0) 454 break; 455 } 456 } 457 458 #ifdef REG_DISABLE_JP_CH144 459 /** 460 * reg_modify_chan_list_for_japan() - Disable channel 144 for MKK17_MKKC 461 * regdomain by default. 462 * @pdev: Pointer to pdev 463 * 464 * Return: None 465 */ 466 static void 467 reg_modify_chan_list_for_japan(struct wlan_objmgr_pdev *pdev) 468 { 469 #define MKK17_MKKC 0xE1 470 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 471 472 pdev_priv_obj = reg_get_pdev_obj(pdev); 473 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 474 reg_err("reg pdev priv obj is NULL"); 475 return; 476 } 477 478 if (pdev_priv_obj->reg_dmn_pair == MKK17_MKKC) 479 pdev_priv_obj->en_chan_144 = false; 480 481 #undef MKK17_MKKC 482 } 483 #else 484 static inline void 485 reg_modify_chan_list_for_japan(struct wlan_objmgr_pdev *pdev) 486 { 487 } 488 #endif 489 /** 490 * reg_modify_chan_list_for_freq_range() - Modify channel list for the given low 491 * and high frequency range. 492 * @chan_list: Pointer to regulatory channel list. 493 * @low_freq_2g: Low frequency 2G. 494 * @high_freq_2g: High frequency 2G. 495 * @low_freq_5g: Low frequency 5G. 496 * @high_freq_5g: High frequency 5G. 497 * 498 * Return: None 499 */ 500 static void 501 reg_modify_chan_list_for_freq_range(struct regulatory_channel *chan_list, 502 qdf_freq_t low_freq_2g, 503 qdf_freq_t high_freq_2g, 504 qdf_freq_t low_freq_5g, 505 qdf_freq_t high_freq_5g) 506 { 507 uint32_t low_limit_2g = NUM_CHANNELS; 508 uint32_t high_limit_2g = NUM_CHANNELS; 509 uint32_t low_limit_5g = NUM_CHANNELS; 510 uint32_t high_limit_5g = NUM_CHANNELS; 511 enum channel_enum chan_enum; 512 bool chan_in_range; 513 514 reg_find_low_limit_chan_enum(chan_list, low_freq_2g, &low_limit_2g); 515 reg_find_low_limit_chan_enum(chan_list, low_freq_5g, &low_limit_5g); 516 reg_find_high_limit_chan_enum(chan_list, high_freq_2g, &high_limit_2g); 517 reg_find_high_limit_chan_enum(chan_list, high_freq_5g, &high_limit_5g); 518 519 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) { 520 chan_in_range = false; 521 if ((low_limit_2g <= chan_enum) && 522 (high_limit_2g >= chan_enum) && 523 (low_limit_2g != NUM_CHANNELS) && 524 (high_limit_2g != NUM_CHANNELS)) 525 chan_in_range = true; 526 527 if ((low_limit_5g <= chan_enum) && 528 (high_limit_5g >= chan_enum) && 529 (low_limit_5g != NUM_CHANNELS) && 530 (high_limit_5g != NUM_CHANNELS)) 531 chan_in_range = true; 532 533 if (!chan_in_range) { 534 chan_list[chan_enum].chan_flags |= 535 REGULATORY_CHAN_DISABLED; 536 chan_list[chan_enum].state = CHANNEL_STATE_DISABLE; 537 } 538 } 539 } 540 541 void reg_init_pdev_mas_chan_list( 542 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 543 struct mas_chan_params *mas_chan_params) 544 { 545 qdf_mem_copy(pdev_priv_obj->mas_chan_list, 546 mas_chan_params->mas_chan_list, 547 NUM_CHANNELS * sizeof(struct regulatory_channel)); 548 549 pdev_priv_obj->dfs_region = mas_chan_params->dfs_region; 550 551 pdev_priv_obj->phybitmap = mas_chan_params->phybitmap; 552 553 pdev_priv_obj->reg_dmn_pair = mas_chan_params->reg_dmn_pair; 554 pdev_priv_obj->ctry_code = mas_chan_params->ctry_code; 555 556 pdev_priv_obj->def_region_domain = mas_chan_params->reg_dmn_pair; 557 pdev_priv_obj->def_country_code = mas_chan_params->ctry_code; 558 559 qdf_mem_copy(pdev_priv_obj->default_country, 560 mas_chan_params->default_country, REG_ALPHA2_LEN + 1); 561 562 qdf_mem_copy(pdev_priv_obj->current_country, 563 mas_chan_params->current_country, REG_ALPHA2_LEN + 1); 564 } 565 566 /** 567 * reg_modify_chan_list_for_cached_channels() - If num_cache_channels are 568 * non-zero, then disable the pdev channels which is given in 569 * cache_disable_chan_list. 570 * @pdev_priv_obj: Pointer to regulatory pdev private object. 571 */ 572 #ifdef DISABLE_CHANNEL_LIST 573 static void reg_modify_chan_list_for_cached_channels( 574 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 575 { 576 uint32_t i, j; 577 uint32_t num_cache_channels = pdev_priv_obj->num_cache_channels; 578 struct regulatory_channel *chan_list = pdev_priv_obj->cur_chan_list; 579 struct regulatory_channel *cache_chan_list = 580 pdev_priv_obj->cache_disable_chan_list; 581 582 if (!num_cache_channels) 583 return; 584 585 if (pdev_priv_obj->disable_cached_channels) { 586 for (i = 0; i < num_cache_channels; i++) 587 for (j = 0; j < NUM_CHANNELS; j++) 588 if (cache_chan_list[i].chan_num == 589 chan_list[j].chan_num) { 590 chan_list[j].state = 591 CHANNEL_STATE_DISABLE; 592 chan_list[j].chan_flags |= 593 REGULATORY_CHAN_DISABLED; 594 } 595 } 596 } 597 #else 598 static void reg_modify_chan_list_for_cached_channels( 599 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 600 { 601 } 602 #endif 603 604 #ifdef CONFIG_REG_CLIENT 605 /** 606 * reg_modify_chan_list_for_srd_channels() - Modify SRD channels in ETSI13 607 * @pdev: Pointer to pdev object 608 * @chan_list: Current channel list 609 * 610 * This function converts SRD channels to passive in ETSI13 regulatory domain 611 * when enable_srd_chan_in_master_mode is not set. 612 */ 613 static void 614 reg_modify_chan_list_for_srd_channels(struct wlan_objmgr_pdev *pdev, 615 struct regulatory_channel *chan_list) 616 { 617 enum channel_enum chan_enum; 618 619 if (!reg_is_etsi13_regdmn(pdev)) 620 return; 621 622 if (reg_is_etsi13_srd_chan_allowed_master_mode(pdev)) 623 return; 624 625 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) { 626 if (chan_list[chan_enum].chan_flags & REGULATORY_CHAN_DISABLED) 627 continue; 628 629 if (reg_is_etsi13_srd_chan(pdev, 630 chan_list[chan_enum].chan_num)) { 631 chan_list[chan_enum].state = 632 CHANNEL_STATE_DFS; 633 chan_list[chan_enum].chan_flags |= 634 REGULATORY_CHAN_NO_IR; 635 } 636 } 637 } 638 #else 639 static inline void 640 reg_modify_chan_list_for_srd_channels(struct wlan_objmgr_pdev *pdev, 641 struct regulatory_channel *chan_list) 642 { 643 } 644 #endif 645 646 /** 647 * reg_modify_chan_list_for_5dot9_ghz_channels() - Modify 5.9 GHz channels 648 * in FCC 649 * @pdev: Pointer to pdev object 650 * @chan_list: Current channel list 651 * 652 * This function disables 5.9 GHz channels if service bit 653 * wmi_service_5dot9_ghz_support is not set or the reg db is not offloaded 654 * to FW. If service bit is set but ini enable_5dot9_ghz_chan_in_master_mode 655 * is not set, it converts these channels to passive in FCC regulatory domain. 656 * If both service bit and ini are set, the channels remain enabled. 657 */ 658 static void 659 reg_modify_chan_list_for_5dot9_ghz_channels(struct wlan_objmgr_pdev *pdev, 660 struct regulatory_channel 661 *chan_list) 662 { 663 enum channel_enum chan_enum; 664 struct wlan_objmgr_psoc *psoc; 665 666 psoc = wlan_pdev_get_psoc(pdev); 667 668 if (!reg_is_fcc_regdmn(pdev)) 669 return; 670 671 if (!reg_is_5dot9_ghz_supported(psoc) || 672 !reg_is_regdb_offloaded(psoc)) { 673 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) { 674 if (reg_is_5dot9_ghz_freq(pdev, chan_list[chan_enum]. 675 center_freq)) { 676 chan_list[chan_enum].state = 677 CHANNEL_STATE_DISABLE; 678 chan_list[chan_enum].chan_flags = 679 REGULATORY_CHAN_DISABLED; 680 } 681 } 682 return; 683 } 684 685 if (reg_is_5dot9_ghz_chan_allowed_master_mode(pdev)) 686 return; 687 688 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) { 689 if (chan_list[chan_enum].chan_flags & REGULATORY_CHAN_DISABLED) 690 continue; 691 692 if (reg_is_5dot9_ghz_freq(pdev, 693 chan_list[chan_enum].center_freq)) { 694 chan_list[chan_enum].state = 695 CHANNEL_STATE_DFS; 696 chan_list[chan_enum].chan_flags |= 697 REGULATORY_CHAN_NO_IR; 698 } 699 } 700 } 701 702 #ifdef DISABLE_UNII_SHARED_BANDS 703 /** 704 * reg_is_reg_unii_band_1_set() - Check UNII bitmap 705 * @unii_bitmap: 5G UNII band bitmap 706 * 707 * This function checks the input bitmap to disable UNII-1 band channels. 708 * 709 * Return: Return true if UNII-1 channels need to be disabled, 710 * else return false. 711 */ 712 static bool reg_is_reg_unii_band_1_set(uint8_t unii_bitmap) 713 { 714 return !!(unii_bitmap & BIT(REG_UNII_BAND_1)); 715 } 716 717 /** 718 * reg_is_reg_unii_band_2a_set() - Check UNII bitmap 719 * @unii_bitmap: 5G UNII band bitmap 720 * 721 * This function checks the input bitmap to disable UNII-2A band channels. 722 * 723 * Return: Return true if UNII-2A channels need to be disabled, 724 * else return false. 725 */ 726 static bool reg_is_reg_unii_band_2a_set(uint8_t unii_bitmap) 727 { 728 return !!(unii_bitmap & BIT(REG_UNII_BAND_2A)); 729 } 730 731 /** 732 * reg_is_5g_enum() - Check if channel enum is a 5G channel enum 733 * @chan_enum: channel enum 734 * 735 * Return: Return true if the input channel enum is 5G, else return false. 736 */ 737 static bool reg_is_5g_enum(enum channel_enum chan_enum) 738 { 739 return (chan_enum >= MIN_5GHZ_CHANNEL && chan_enum <= MAX_5GHZ_CHANNEL); 740 } 741 742 /** 743 * reg_remove_unii_chan_from_chan_list() - Remove UNII band channels 744 * @chan_list: Pointer to current channel list 745 * @start_enum: starting enum value 746 * @end_enum: ending enum value 747 * 748 * Remove channels in a unii band based in on the input start_enum and end_enum. 749 * Disable the state and flags. Set disable_coex flag to true. 750 * 751 * return: void. 752 */ 753 static void 754 reg_remove_unii_chan_from_chan_list(struct regulatory_channel *chan_list, 755 enum channel_enum start_enum, 756 enum channel_enum end_enum) 757 { 758 enum channel_enum chan_enum; 759 760 if (!(reg_is_5g_enum(start_enum) && reg_is_5g_enum(end_enum))) { 761 reg_err_rl("start_enum or end_enum is invalid"); 762 return; 763 } 764 765 for (chan_enum = start_enum; chan_enum <= end_enum; chan_enum++) { 766 chan_list[chan_enum].state = CHANNEL_STATE_DISABLE; 767 chan_list[chan_enum].chan_flags |= REGULATORY_CHAN_DISABLED; 768 } 769 } 770 771 /** 772 * reg_modify_disable_chan_list_for_unii1_and_unii2a() - Disable UNII-1 and 773 * UNII2A band 774 * @pdev_priv_obj: Pointer to pdev private object 775 * 776 * This function disables the UNII-1 and UNII-2A band channels 777 * based on input unii_5g_bitmap. 778 * 779 * Return: void. 780 */ 781 static void 782 reg_modify_disable_chan_list_for_unii1_and_unii2a( 783 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 784 { 785 uint8_t unii_bitmap = pdev_priv_obj->unii_5g_bitmap; 786 struct regulatory_channel *chan_list = pdev_priv_obj->cur_chan_list; 787 788 if (reg_is_reg_unii_band_1_set(unii_bitmap)) { 789 reg_remove_unii_chan_from_chan_list(chan_list, 790 MIN_UNII_1_BAND_CHANNEL, 791 MAX_UNII_1_BAND_CHANNEL); 792 } 793 794 if (reg_is_reg_unii_band_2a_set(unii_bitmap)) { 795 reg_remove_unii_chan_from_chan_list(chan_list, 796 MIN_UNII_2A_BAND_CHANNEL, 797 MAX_UNII_2A_BAND_CHANNEL); 798 } 799 } 800 #else 801 static inline bool reg_is_reg_unii_band_1_set(uint8_t unii_bitmap) 802 { 803 return false; 804 } 805 806 static inline bool reg_is_reg_unii_band_2a_set(uint8_t unii_bitmap) 807 { 808 return false; 809 } 810 811 static inline bool reg_is_5g_enum(enum channel_enum chan_enum) 812 { 813 return false; 814 } 815 816 static inline void 817 reg_remove_unii_chan_from_chan_list(struct regulatory_channel *chan_list, 818 enum channel_enum start_enum, 819 enum channel_enum end_enum) 820 { 821 } 822 823 static inline void 824 reg_modify_disable_chan_list_for_unii1_and_unii2a( 825 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 826 { 827 } 828 #endif 829 830 void reg_compute_pdev_current_chan_list(struct wlan_regulatory_pdev_priv_obj 831 *pdev_priv_obj) 832 { 833 qdf_mem_copy(pdev_priv_obj->cur_chan_list, pdev_priv_obj->mas_chan_list, 834 NUM_CHANNELS * sizeof(struct regulatory_channel)); 835 836 reg_modify_chan_list_for_freq_range(pdev_priv_obj->cur_chan_list, 837 pdev_priv_obj->range_2g_low, 838 pdev_priv_obj->range_2g_high, 839 pdev_priv_obj->range_5g_low, 840 pdev_priv_obj->range_5g_high); 841 842 reg_modify_chan_list_for_band(pdev_priv_obj->cur_chan_list, 843 pdev_priv_obj->band_capability); 844 845 reg_modify_disable_chan_list_for_unii1_and_unii2a(pdev_priv_obj); 846 847 reg_modify_chan_list_for_dfs_channels(pdev_priv_obj->cur_chan_list, 848 pdev_priv_obj->dfs_enabled); 849 850 reg_modify_chan_list_for_nol_list(pdev_priv_obj->cur_chan_list); 851 852 reg_modify_chan_list_for_indoor_channels(pdev_priv_obj); 853 854 reg_modify_chan_list_for_fcc_channel(pdev_priv_obj->cur_chan_list, 855 pdev_priv_obj->set_fcc_channel); 856 857 reg_modify_chan_list_for_chan_144(pdev_priv_obj->cur_chan_list, 858 pdev_priv_obj->en_chan_144); 859 860 reg_modify_chan_list_for_cached_channels(pdev_priv_obj); 861 862 reg_modify_chan_list_for_srd_channels(pdev_priv_obj->pdev_ptr, 863 pdev_priv_obj->cur_chan_list); 864 865 reg_modify_chan_list_for_5dot9_ghz_channels(pdev_priv_obj->pdev_ptr, 866 pdev_priv_obj-> 867 cur_chan_list); 868 } 869 870 void reg_reset_reg_rules(struct reg_rule_info *reg_rules) 871 { 872 qdf_mem_zero(reg_rules, sizeof(*reg_rules)); 873 } 874 875 void reg_save_reg_rules_to_pdev( 876 struct reg_rule_info *psoc_reg_rules, 877 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 878 { 879 uint32_t reg_rule_len; 880 struct reg_rule_info *pdev_reg_rules; 881 882 qdf_spin_lock_bh(&pdev_priv_obj->reg_rules_lock); 883 884 pdev_reg_rules = &pdev_priv_obj->reg_rules; 885 reg_reset_reg_rules(pdev_reg_rules); 886 887 pdev_reg_rules->num_of_reg_rules = psoc_reg_rules->num_of_reg_rules; 888 if (!pdev_reg_rules->num_of_reg_rules) { 889 qdf_spin_unlock_bh(&pdev_priv_obj->reg_rules_lock); 890 reg_err("no reg rules in psoc"); 891 return; 892 } 893 894 reg_rule_len = pdev_reg_rules->num_of_reg_rules * 895 sizeof(struct cur_reg_rule); 896 qdf_mem_copy(pdev_reg_rules->reg_rules, psoc_reg_rules->reg_rules, 897 reg_rule_len); 898 899 qdf_mem_copy(pdev_reg_rules->alpha2, pdev_priv_obj->current_country, 900 REG_ALPHA2_LEN + 1); 901 pdev_reg_rules->dfs_region = pdev_priv_obj->dfs_region; 902 903 qdf_spin_unlock_bh(&pdev_priv_obj->reg_rules_lock); 904 } 905 906 void reg_propagate_mas_chan_list_to_pdev(struct wlan_objmgr_psoc *psoc, 907 void *object, void *arg) 908 { 909 struct wlan_objmgr_pdev *pdev = (struct wlan_objmgr_pdev *)object; 910 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 911 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 912 enum direction *dir = arg; 913 uint8_t pdev_id; 914 uint8_t phy_id; 915 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 916 struct reg_rule_info *psoc_reg_rules; 917 918 psoc_priv_obj = (struct wlan_regulatory_psoc_priv_obj *) 919 wlan_objmgr_psoc_get_comp_private_obj( 920 psoc, WLAN_UMAC_COMP_REGULATORY); 921 922 if (!psoc_priv_obj) { 923 reg_err("psoc priv obj is NULL"); 924 return; 925 } 926 927 pdev_priv_obj = reg_get_pdev_obj(pdev); 928 929 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 930 reg_err("reg pdev priv obj is NULL"); 931 return; 932 } 933 934 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 935 936 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 937 if (reg_tx_ops->get_phy_id_from_pdev_id) 938 reg_tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id); 939 else 940 phy_id = pdev_id; 941 942 reg_init_pdev_mas_chan_list( 943 pdev_priv_obj, 944 &psoc_priv_obj->mas_chan_params[phy_id]); 945 psoc_reg_rules = &psoc_priv_obj->mas_chan_params[phy_id].reg_rules; 946 reg_save_reg_rules_to_pdev(psoc_reg_rules, pdev_priv_obj); 947 reg_modify_chan_list_for_japan(pdev); 948 pdev_priv_obj->chan_list_recvd = 949 psoc_priv_obj->chan_list_recvd[phy_id]; 950 reg_compute_pdev_current_chan_list(pdev_priv_obj); 951 952 if (reg_tx_ops->fill_umac_legacy_chanlist) { 953 reg_tx_ops->fill_umac_legacy_chanlist( 954 pdev, pdev_priv_obj->cur_chan_list); 955 } else { 956 if (*dir == NORTHBOUND) 957 reg_send_scheduler_msg_nb(psoc, pdev); 958 else 959 reg_send_scheduler_msg_sb(psoc, pdev); 960 } 961 } 962 963 /** 964 * reg_populate_49g_band_channels() - For all the valid 4.9GHz regdb channels 965 * in the master channel list, find the regulatory rules and call 966 * reg_fill_channel_info() to populate master channel list with txpower, 967 * antennagain, BW info, etc. 968 * @reg_rule_5g: Pointer to regulatory rule. 969 * @num_5g_reg_rules: Number of regulatory rules. 970 * @min_bw_5g: Minimum regulatory bandwidth. 971 * @mas_chan_list: Pointer to the master channel list. 972 */ 973 #ifdef CONFIG_49GHZ_CHAN 974 static void 975 reg_populate_49g_band_channels(struct cur_reg_rule *reg_rule_5g, 976 uint32_t num_5g_reg_rules, 977 uint16_t min_bw_5g, 978 struct regulatory_channel *mas_chan_list) 979 { 980 reg_populate_band_channels(MIN_49GHZ_CHANNEL, 981 MAX_49GHZ_CHANNEL, 982 reg_rule_5g, 983 num_5g_reg_rules, 984 min_bw_5g, 985 mas_chan_list); 986 } 987 #else 988 static void 989 reg_populate_49g_band_channels(struct cur_reg_rule *reg_rule_5g, 990 uint32_t num_5g_reg_rules, 991 uint16_t min_bw_5g, 992 struct regulatory_channel *mas_chan_list) 993 { 994 } 995 #endif /* CONFIG_49GHZ_CHAN */ 996 997 /** 998 * reg_populate_6g_band_channels() - For all the valid 6GHz regdb channels 999 * in the master channel list, find the regulatory rules and call 1000 * reg_fill_channel_info() to populate master channel list with txpower, 1001 * antennagain, BW info, etc. 1002 * @reg_rule_5g: Pointer to regulatory rule. 1003 * @num_5g_reg_rules: Number of regulatory rules. 1004 * @min_bw_5g: Minimum regulatory bandwidth. 1005 * @mas_chan_list: Pointer to the master channel list. 1006 */ 1007 #ifdef CONFIG_BAND_6GHZ 1008 static void 1009 reg_populate_6g_band_channels(struct cur_reg_rule *reg_rule_5g, 1010 uint32_t num_5g_reg_rules, 1011 uint16_t min_bw_5g, 1012 struct regulatory_channel *mas_chan_list) 1013 { 1014 reg_populate_band_channels(MIN_6GHZ_CHANNEL, 1015 MAX_6GHZ_CHANNEL, 1016 reg_rule_5g, 1017 num_5g_reg_rules, 1018 min_bw_5g, 1019 mas_chan_list); 1020 } 1021 #else 1022 static void 1023 reg_populate_6g_band_channels(struct cur_reg_rule *reg_rule_5g, 1024 uint32_t num_5g_reg_rules, 1025 uint16_t min_bw_5g, 1026 struct regulatory_channel *mas_chan_list) 1027 { 1028 } 1029 #endif /* CONFIG_BAND_6GHZ */ 1030 1031 #ifdef CONFIG_REG_CLIENT 1032 /** 1033 * reg_send_ctl_info() - Send CTL info to firmware when regdb is not offloaded 1034 * @soc_reg: soc private object for regulatory 1035 * @regulatory_info: regulatory info 1036 * @tx_ops: send operations for regulatory component 1037 * 1038 * Return: QDF_STATUS 1039 */ 1040 static QDF_STATUS 1041 reg_send_ctl_info(struct wlan_regulatory_psoc_priv_obj *soc_reg, 1042 struct cur_regulatory_info *regulatory_info, 1043 struct wlan_lmac_if_reg_tx_ops *tx_ops) 1044 { 1045 struct wlan_objmgr_psoc *psoc = regulatory_info->psoc; 1046 struct reg_ctl_params params = {0}; 1047 QDF_STATUS status; 1048 uint16_t regd_index; 1049 uint32_t index_2g, index_5g; 1050 1051 if (soc_reg->offload_enabled) 1052 return QDF_STATUS_SUCCESS; 1053 1054 if (!tx_ops || !tx_ops->send_ctl_info) { 1055 reg_err("No regulatory tx_ops"); 1056 return QDF_STATUS_E_FAULT; 1057 } 1058 1059 status = reg_get_rdpair_from_regdmn_id(regulatory_info->reg_dmn_pair, 1060 ®d_index); 1061 if (QDF_IS_STATUS_ERROR(status)) { 1062 reg_err("Failed to get regdomain index for regdomain pair: %x", 1063 regulatory_info->reg_dmn_pair); 1064 return status; 1065 } 1066 1067 index_2g = g_reg_dmn_pairs[regd_index].dmn_id_2g; 1068 index_5g = g_reg_dmn_pairs[regd_index].dmn_id_5g; 1069 params.ctl_2g = regdomains_2g[index_2g].ctl_val; 1070 params.ctl_5g = regdomains_5g[index_5g].ctl_val; 1071 params.regd_2g = reg_2g_sub_dmn_code[index_2g]; 1072 params.regd_5g = reg_5g_sub_dmn_code[index_5g]; 1073 1074 if (reg_is_world_ctry_code(regulatory_info->reg_dmn_pair)) 1075 params.regd = regulatory_info->reg_dmn_pair; 1076 else 1077 params.regd = regulatory_info->ctry_code | COUNTRY_ERD_FLAG; 1078 1079 reg_debug("regdomain pair = %u, regdomain index = %u", 1080 regulatory_info->reg_dmn_pair, regd_index); 1081 reg_debug("index_2g = %u, index_5g = %u, ctl_2g = %x, ctl_5g = %x", 1082 index_2g, index_5g, params.ctl_2g, params.ctl_5g); 1083 reg_debug("regd_2g = %x, regd_5g = %x, regd = %x", 1084 params.regd_2g, params.regd_5g, params.regd); 1085 1086 status = tx_ops->send_ctl_info(psoc, ¶ms); 1087 if (QDF_IS_STATUS_ERROR(status)) 1088 reg_err("Failed to send CTL info to firmware"); 1089 1090 return status; 1091 } 1092 #else 1093 static QDF_STATUS 1094 reg_send_ctl_info(struct wlan_regulatory_psoc_priv_obj *soc_reg, 1095 struct cur_regulatory_info *regulatory_info, 1096 struct wlan_lmac_if_reg_tx_ops *tx_ops) 1097 { 1098 return QDF_STATUS_SUCCESS; 1099 } 1100 #endif 1101 1102 QDF_STATUS reg_process_master_chan_list( 1103 struct cur_regulatory_info *regulat_info) 1104 { 1105 struct wlan_regulatory_psoc_priv_obj *soc_reg; 1106 uint32_t num_2g_reg_rules, num_5g_reg_rules; 1107 struct cur_reg_rule *reg_rule_2g, *reg_rule_5g; 1108 uint16_t min_bw_2g, max_bw_2g, min_bw_5g, max_bw_5g; 1109 struct regulatory_channel *mas_chan_list; 1110 struct wlan_objmgr_psoc *psoc; 1111 enum channel_enum chan_enum; 1112 wlan_objmgr_ref_dbgid dbg_id; 1113 enum direction dir; 1114 uint8_t phy_id; 1115 uint8_t pdev_id; 1116 struct wlan_objmgr_pdev *pdev; 1117 struct wlan_lmac_if_reg_tx_ops *tx_ops; 1118 struct reg_rule_info *reg_rules; 1119 QDF_STATUS status; 1120 1121 psoc = regulat_info->psoc; 1122 soc_reg = reg_get_psoc_obj(psoc); 1123 1124 if (!IS_VALID_PSOC_REG_OBJ(soc_reg)) { 1125 reg_err("psoc reg component is NULL"); 1126 return QDF_STATUS_E_FAILURE; 1127 } 1128 1129 tx_ops = reg_get_psoc_tx_ops(psoc); 1130 phy_id = regulat_info->phy_id; 1131 1132 if (tx_ops->get_pdev_id_from_phy_id) 1133 tx_ops->get_pdev_id_from_phy_id(psoc, phy_id, &pdev_id); 1134 else 1135 pdev_id = phy_id; 1136 1137 if (reg_ignore_default_country(soc_reg, regulat_info)) { 1138 status = reg_set_curr_country(soc_reg, regulat_info, tx_ops); 1139 if (QDF_IS_STATUS_SUCCESS(status)) { 1140 reg_debug("WLAN restart - Ignore default CC for phy_id: %u", 1141 phy_id); 1142 return QDF_STATUS_SUCCESS; 1143 } 1144 } 1145 1146 reg_debug("process reg master chan list"); 1147 1148 if (soc_reg->offload_enabled) { 1149 dbg_id = WLAN_REGULATORY_NB_ID; 1150 dir = NORTHBOUND; 1151 } else { 1152 dbg_id = WLAN_REGULATORY_SB_ID; 1153 dir = SOUTHBOUND; 1154 } 1155 1156 if (regulat_info->status_code != REG_SET_CC_STATUS_PASS) { 1157 reg_err("Set country code failed, status code %d", 1158 regulat_info->status_code); 1159 1160 pdev = wlan_objmgr_get_pdev_by_id(psoc, phy_id, dbg_id); 1161 if (!pdev) { 1162 reg_err("pdev is NULL"); 1163 return QDF_STATUS_E_FAILURE; 1164 } 1165 1166 if (tx_ops->set_country_failed) 1167 tx_ops->set_country_failed(pdev); 1168 1169 wlan_objmgr_pdev_release_ref(pdev, dbg_id); 1170 1171 if (regulat_info->status_code != REG_CURRENT_ALPHA2_NOT_FOUND) 1172 return QDF_STATUS_E_FAILURE; 1173 1174 soc_reg->new_user_ctry_pending[phy_id] = false; 1175 soc_reg->new_11d_ctry_pending[phy_id] = false; 1176 soc_reg->world_country_pending[phy_id] = true; 1177 } 1178 1179 mas_chan_list = soc_reg->mas_chan_params[phy_id].mas_chan_list; 1180 1181 reg_init_channel_map(regulat_info->dfs_region); 1182 1183 for (chan_enum = 0; chan_enum < NUM_CHANNELS; 1184 chan_enum++) { 1185 mas_chan_list[chan_enum].chan_num = 1186 channel_map[chan_enum].chan_num; 1187 mas_chan_list[chan_enum].center_freq = 1188 channel_map[chan_enum].center_freq; 1189 mas_chan_list[chan_enum].chan_flags = 1190 REGULATORY_CHAN_DISABLED; 1191 mas_chan_list[chan_enum].state = 1192 CHANNEL_STATE_DISABLE; 1193 if (!soc_reg->retain_nol_across_regdmn_update) 1194 mas_chan_list[chan_enum].nol_chan = false; 1195 } 1196 1197 soc_reg->num_phy = regulat_info->num_phy; 1198 soc_reg->mas_chan_params[phy_id].phybitmap = 1199 regulat_info->phybitmap; 1200 soc_reg->mas_chan_params[phy_id].dfs_region = 1201 regulat_info->dfs_region; 1202 soc_reg->mas_chan_params[phy_id].ctry_code = 1203 regulat_info->ctry_code; 1204 soc_reg->mas_chan_params[phy_id].reg_dmn_pair = 1205 regulat_info->reg_dmn_pair; 1206 qdf_mem_copy(soc_reg->mas_chan_params[phy_id].current_country, 1207 regulat_info->alpha2, 1208 REG_ALPHA2_LEN + 1); 1209 qdf_mem_copy(soc_reg->cur_country, 1210 regulat_info->alpha2, 1211 REG_ALPHA2_LEN + 1); 1212 reg_debug("set cur_country %.2s", soc_reg->cur_country); 1213 1214 min_bw_2g = regulat_info->min_bw_2g; 1215 max_bw_2g = regulat_info->max_bw_2g; 1216 reg_rule_2g = regulat_info->reg_rules_2g_ptr; 1217 num_2g_reg_rules = regulat_info->num_2g_reg_rules; 1218 reg_update_max_bw_per_rule(num_2g_reg_rules, 1219 reg_rule_2g, max_bw_2g); 1220 1221 min_bw_5g = regulat_info->min_bw_5g; 1222 max_bw_5g = regulat_info->max_bw_5g; 1223 reg_rule_5g = regulat_info->reg_rules_5g_ptr; 1224 num_5g_reg_rules = regulat_info->num_5g_reg_rules; 1225 reg_update_max_bw_per_rule(num_5g_reg_rules, 1226 reg_rule_5g, max_bw_5g); 1227 1228 reg_rules = &soc_reg->mas_chan_params[phy_id].reg_rules; 1229 reg_reset_reg_rules(reg_rules); 1230 1231 reg_rules->num_of_reg_rules = num_5g_reg_rules + num_2g_reg_rules; 1232 if (reg_rules->num_of_reg_rules > MAX_REG_RULES) { 1233 reg_err("number of reg rules exceeds limit"); 1234 return QDF_STATUS_E_FAILURE; 1235 } 1236 1237 if (reg_rules->num_of_reg_rules) { 1238 if (num_2g_reg_rules) 1239 qdf_mem_copy(reg_rules->reg_rules, 1240 reg_rule_2g, num_2g_reg_rules * 1241 sizeof(struct cur_reg_rule)); 1242 if (num_5g_reg_rules) 1243 qdf_mem_copy(reg_rules->reg_rules + 1244 num_2g_reg_rules, reg_rule_5g, 1245 num_5g_reg_rules * 1246 sizeof(struct cur_reg_rule)); 1247 } 1248 1249 if (num_5g_reg_rules != 0) 1250 reg_do_auto_bw_correction(num_5g_reg_rules, 1251 reg_rule_5g, max_bw_5g); 1252 1253 if (num_2g_reg_rules != 0) 1254 reg_populate_band_channels(MIN_24GHZ_CHANNEL, MAX_24GHZ_CHANNEL, 1255 reg_rule_2g, num_2g_reg_rules, 1256 min_bw_2g, mas_chan_list); 1257 1258 if (num_5g_reg_rules != 0) { 1259 reg_populate_band_channels(MIN_5GHZ_CHANNEL, MAX_5GHZ_CHANNEL, 1260 reg_rule_5g, num_5g_reg_rules, 1261 min_bw_5g, mas_chan_list); 1262 reg_populate_49g_band_channels(reg_rule_5g, 1263 num_5g_reg_rules, 1264 min_bw_5g, 1265 mas_chan_list); 1266 reg_populate_6g_band_channels(reg_rule_5g, 1267 num_5g_reg_rules, 1268 min_bw_5g, 1269 mas_chan_list); 1270 } 1271 1272 soc_reg->chan_list_recvd[phy_id] = true; 1273 status = reg_send_ctl_info(soc_reg, regulat_info, tx_ops); 1274 if (!QDF_IS_STATUS_SUCCESS(status)) 1275 return status; 1276 1277 if (soc_reg->new_user_ctry_pending[phy_id]) { 1278 soc_reg->new_user_ctry_pending[phy_id] = false; 1279 soc_reg->cc_src = SOURCE_USERSPACE; 1280 soc_reg->user_ctry_set = true; 1281 reg_debug("new user country is set"); 1282 reg_run_11d_state_machine(psoc); 1283 } else if (soc_reg->new_init_ctry_pending[phy_id]) { 1284 soc_reg->new_init_ctry_pending[phy_id] = false; 1285 soc_reg->cc_src = SOURCE_USERSPACE; 1286 reg_debug("new init country is set"); 1287 } else if (soc_reg->new_11d_ctry_pending[phy_id]) { 1288 soc_reg->new_11d_ctry_pending[phy_id] = false; 1289 soc_reg->cc_src = SOURCE_11D; 1290 soc_reg->user_ctry_set = false; 1291 reg_run_11d_state_machine(psoc); 1292 } else if (soc_reg->world_country_pending[phy_id]) { 1293 soc_reg->world_country_pending[phy_id] = false; 1294 soc_reg->cc_src = SOURCE_CORE; 1295 soc_reg->user_ctry_set = false; 1296 reg_run_11d_state_machine(psoc); 1297 } else { 1298 if (soc_reg->cc_src == SOURCE_UNKNOWN && 1299 soc_reg->num_phy == phy_id + 1) 1300 soc_reg->cc_src = SOURCE_DRIVER; 1301 1302 qdf_mem_copy(soc_reg->mas_chan_params[phy_id].default_country, 1303 regulat_info->alpha2, 1304 REG_ALPHA2_LEN + 1); 1305 1306 soc_reg->mas_chan_params[phy_id].def_country_code = 1307 regulat_info->ctry_code; 1308 soc_reg->mas_chan_params[phy_id].def_region_domain = 1309 regulat_info->reg_dmn_pair; 1310 1311 if (soc_reg->cc_src == SOURCE_DRIVER) { 1312 qdf_mem_copy(soc_reg->def_country, 1313 regulat_info->alpha2, 1314 REG_ALPHA2_LEN + 1); 1315 1316 soc_reg->def_country_code = regulat_info->ctry_code; 1317 soc_reg->def_region_domain = 1318 regulat_info->reg_dmn_pair; 1319 1320 if (reg_is_world_alpha2(regulat_info->alpha2)) { 1321 soc_reg->cc_src = SOURCE_CORE; 1322 reg_run_11d_state_machine(psoc); 1323 } 1324 } 1325 } 1326 1327 pdev = wlan_objmgr_get_pdev_by_id(psoc, pdev_id, dbg_id); 1328 if (pdev) { 1329 reg_propagate_mas_chan_list_to_pdev(psoc, pdev, &dir); 1330 wlan_objmgr_pdev_release_ref(pdev, dbg_id); 1331 } 1332 1333 return QDF_STATUS_SUCCESS; 1334 } 1335 1336 QDF_STATUS reg_get_current_chan_list(struct wlan_objmgr_pdev *pdev, 1337 struct regulatory_channel *chan_list) 1338 { 1339 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 1340 1341 pdev_priv_obj = reg_get_pdev_obj(pdev); 1342 1343 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 1344 reg_err("reg pdev private obj is NULL"); 1345 return QDF_STATUS_E_FAILURE; 1346 } 1347 1348 qdf_mem_copy(chan_list, pdev_priv_obj->cur_chan_list, 1349 NUM_CHANNELS * sizeof(struct regulatory_channel)); 1350 1351 return QDF_STATUS_SUCCESS; 1352 } 1353