1 /* 2 * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /** 21 * DOC: reg_services_common.c 22 * This file defines regulatory component service functions 23 */ 24 25 #include <wlan_cmn.h> 26 #include <reg_services_public_struct.h> 27 #include <wlan_reg_services_api.h> 28 #ifdef CONFIG_AFC_SUPPORT 29 #include "reg_opclass.h" 30 #endif 31 #include <wlan_objmgr_psoc_obj.h> 32 #include <qdf_lock.h> 33 #include "reg_priv_objs.h" 34 #include "reg_utils.h" 35 #include "reg_callbacks.h" 36 #include "reg_services_common.h" 37 #include <wlan_objmgr_psoc_obj.h> 38 #include "reg_db.h" 39 #include "reg_db_parser.h" 40 #include "reg_build_chan_list.h" 41 #include <wlan_objmgr_pdev_obj.h> 42 #include <target_if.h> 43 #ifdef WLAN_FEATURE_GET_USABLE_CHAN_LIST 44 #include "wlan_mlme_ucfg_api.h" 45 #include "wlan_nan_api.h" 46 #endif 47 #ifndef CONFIG_REG_CLIENT 48 #include <wlan_reg_channel_api.h> 49 #endif 50 51 const struct chan_map *channel_map; 52 uint8_t g_reg_max_5g_chan_num; 53 54 #ifdef WLAN_FEATURE_11BE 55 static bool reg_is_chan_bit_punctured(uint16_t input_punc_bitmap, 56 uint8_t chan_idx) 57 { 58 return input_punc_bitmap & BIT(chan_idx); 59 } 60 #else 61 static bool reg_is_chan_bit_punctured(uint16_t in_punc_bitmap, 62 uint8_t chan_idx) 63 { 64 return false; 65 } 66 #endif 67 68 #ifdef CONFIG_CHAN_FREQ_API 69 /* bonded_chan_40mhz_list_freq - List of 40MHz bonnded channel frequencies */ 70 static const struct bonded_channel_freq bonded_chan_40mhz_list_freq[] = { 71 {5180, 5200}, 72 {5220, 5240}, 73 {5260, 5280}, 74 {5300, 5320}, 75 {5500, 5520}, 76 {5540, 5560}, 77 {5580, 5600}, 78 {5620, 5640}, 79 {5660, 5680}, 80 {5700, 5720}, 81 {5745, 5765}, 82 {5785, 5805}, 83 {5825, 5845}, 84 {5865, 5885}, 85 #ifdef CONFIG_BAND_6GHZ 86 {5955, 5975}, 87 {5995, 6015}, 88 {6035, 6055}, 89 {6075, 6095}, 90 {6115, 6135}, 91 {6155, 6175}, 92 {6195, 6215}, 93 {6235, 6255}, 94 {6275, 6295}, 95 {6315, 6335}, 96 {6355, 6375}, 97 {6395, 6415}, 98 {6435, 6455}, 99 {6475, 6495}, 100 {6515, 6535}, 101 {6555, 6575}, 102 {6595, 6615}, 103 {6635, 6655}, 104 {6675, 6695}, 105 {6715, 6735}, 106 {6755, 6775}, 107 {6795, 6815}, 108 {6835, 6855}, 109 {6875, 6895}, 110 {6915, 6935}, 111 {6955, 6975}, 112 {6995, 7015}, 113 {7035, 7055}, 114 {7075, 7095} 115 #endif /*CONFIG_BAND_6GHZ*/ 116 }; 117 118 /* bonded_chan_80mhz_list_freq - List of 80MHz bonnded channel frequencies */ 119 static const struct bonded_channel_freq bonded_chan_80mhz_list_freq[] = { 120 {5180, 5240}, 121 {5260, 5320}, 122 {5500, 5560}, 123 {5580, 5640}, 124 {5660, 5720}, 125 {5745, 5805}, 126 {5825, 5885}, 127 #ifdef CONFIG_BAND_6GHZ 128 {5955, 6015}, 129 {6035, 6095}, 130 {6115, 6175}, 131 {6195, 6255}, 132 {6275, 6335}, 133 {6355, 6415}, 134 {6435, 6495}, 135 {6515, 6575}, 136 {6595, 6655}, 137 {6675, 6735}, 138 {6755, 6815}, 139 {6835, 6895}, 140 {6915, 6975}, 141 {6995, 7055} 142 #endif /*CONFIG_BAND_6GHZ*/ 143 }; 144 145 /* bonded_chan_160mhz_list_freq - List of 160MHz bonnded channel frequencies */ 146 static const struct bonded_channel_freq bonded_chan_160mhz_list_freq[] = { 147 {5180, 5320}, 148 {5500, 5640}, 149 {5745, 5885}, 150 #ifdef CONFIG_BAND_6GHZ 151 {5955, 6095}, 152 {6115, 6255}, 153 {6275, 6415}, 154 {6435, 6575}, 155 {6595, 6735}, 156 {6755, 6895}, 157 {6915, 7055} 158 #endif /*CONFIG_BAND_6GHZ*/ 159 }; 160 161 #ifdef WLAN_FEATURE_11BE 162 /* bonded_chan_320mhz_list_freq - List of 320MHz bonnded channel frequencies */ 163 static const struct bonded_channel_freq bonded_chan_320mhz_list_freq[] = { 164 {5500, 5720}, /* center freq: 5650: The 5Ghz 240MHz chan */ 165 #ifdef CONFIG_BAND_6GHZ 166 {5955, 6255}, /* center freq: 6105 */ 167 {6115, 6415}, /* center freq: 6265 */ 168 {6275, 6575}, /* center freq: 6425 */ 169 {6435, 6735}, /* center freq: 6585 */ 170 {6595, 6895}, /* center freq: 6745 */ 171 {6755, 7055} /* center freq: 6905 */ 172 #endif /*CONFIG_BAND_6GHZ*/ 173 }; 174 #endif 175 176 /** 177 * struct bw_bonded_array_pair - Structure containing bandwidth, bonded_array 178 * corresponding to bandwidth and the size of the bonded array. 179 * @chwidth: channel width 180 * @bonded_chan_arr: bonded array corresponding to chwidth. 181 * @array_size: size of the bonded_chan_arr. 182 */ 183 struct bw_bonded_array_pair { 184 enum phy_ch_width chwidth; 185 const struct bonded_channel_freq *bonded_chan_arr; 186 uint16_t array_size; 187 }; 188 189 /* Mapping of chwidth to bonded array and size of bonded array */ 190 static const 191 struct bw_bonded_array_pair bw_bonded_array_pair_map[] = { 192 #ifdef WLAN_FEATURE_11BE 193 {CH_WIDTH_320MHZ, bonded_chan_320mhz_list_freq, 194 QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq)}, 195 #endif 196 {CH_WIDTH_160MHZ, bonded_chan_160mhz_list_freq, 197 QDF_ARRAY_SIZE(bonded_chan_160mhz_list_freq)}, 198 {CH_WIDTH_80P80MHZ, bonded_chan_80mhz_list_freq, 199 QDF_ARRAY_SIZE(bonded_chan_80mhz_list_freq)}, 200 {CH_WIDTH_80MHZ, bonded_chan_80mhz_list_freq, 201 QDF_ARRAY_SIZE(bonded_chan_80mhz_list_freq)}, 202 {CH_WIDTH_40MHZ, bonded_chan_40mhz_list_freq, 203 QDF_ARRAY_SIZE(bonded_chan_40mhz_list_freq)}, 204 }; 205 206 #ifdef WLAN_FEATURE_11BE 207 /** Binary bitmap pattern 208 * 1: Punctured 20Mhz chan 0:non-Punctured 20Mhz Chan 209 * 210 * Band: 80MHz Puncturing Unit: 20Mhz 211 * B0001 = 0x1 : BIT(0) 212 * B0010 = 0x2 : BIT(1) 213 * B0100 = 0x4 : BIT(2) 214 * B1000 = 0x8 : BIT(3) 215 * 216 * Band: 160MHz Puncturing Unit: 20Mhz 217 * B0000_0001 = 0x01 : BIT(0) 218 * B0000_0010 = 0x02 : BIT(1) 219 * B0000_0100 = 0x04 : BIT(2) 220 * B0000_1000 = 0x08 : BIT(3) 221 * B0001_0000 = 0x10 : BIT(4) 222 * B0010_0000 = 0x20 : BIT(5) 223 * B0100_0000 = 0x40 : BIT(6) 224 * B1000_0000 = 0x80 : BIT(7) 225 * 226 * Band: 160MHz Puncturing Unit: 40Mhz 227 * B0000_0011 = 0x03 : BIT(0) | BIT(1) 228 * B0000_1100 = 0x0C : BIT(2) | BIT(3) 229 * B0011_0000 = 0x30 : BIT(4) | BIT(5) 230 * B1100_0000 = 0xC0 : BIT(6) | BIT(7) 231 * 232 * Band: 320MHz Puncturing Unit: 40Mhz 233 * B0000_0000_0000_0011 = 0x0003 : BIT(0) | BIT(1) 234 * B0000_0000_0000_1100 = 0x000C : BIT(2) | BIT(3) 235 * B0000_0000_0011_0000 = 0x0030 : BIT(4) | BIT(5) 236 * B0000_0000_1100_0000 = 0x00C0 : BIT(6) | BIT(7) 237 * B0000_0011_0000_0000 = 0x0300 : BIT(8) | BIT(9) 238 * B0000_1100_0000_0000 = 0x0C00 : BIT(10) | BIT(11) 239 * B0011_0000_0000_0000 = 0x3000 : BIT(12) | BIT(13) 240 * B1100_0000_0000_0000 = 0xC000 : BIT(13) | BIT(15) 241 * 242 * Band: 320MHz Puncturing Unit: 80Mhz 243 * B0000_0000_0000_1111 = 0x000F : BIT(0) | BIT(1) | BIT(2) | BIT(3) 244 * B0000_0000_1111_0000 = 0x00F0 : BIT(4) | BIT(5) | BIT(6) | BIT(7) 245 * B0000_1111_0000_0000 = 0x0F00 : BIT(8) | BIT(9) | BIT(10) | BIT(11) 246 * B1111_0000_0000_0000 = 0xF000 : BIT(12) | BIT(13) | BIT(14) | BIT(15) 247 * 248 * Band: 320MHz Puncturing Unit: 80Mhz+40Mhz (Right 80Mhz punctured) 249 * B0000_0000_0011_1111 = 0x003F : BIT(4) | BIT(5) [right 80MHz: BIT(0) | BIT(1) | BIT(2) | BIT(3)] 250 * B0000_0000_1100_1111 = 0x00CF : BIT(6) | BIT(7) [right 80MHz: BIT(0) | BIT(1) | BIT(2) | BIT(3)] 251 * B0000_0011_0000_1111 = 0x030F : BIT(8) | BIT(9) [right 80MHz: BIT(0) | BIT(1) | BIT(2) | BIT(3)] 252 * B0000_1100_0000_1111 = 0x0C0F : BIT(10) | BIT(11) [right 80MHz: BIT(0) | BIT(1) | BIT(2) | BIT(3)] 253 * B0011_0000_0000_1111 = 0x300F : BIT(12) | BIT(13) [right 80MHz: BIT(0) | BIT(1) | BIT(2) | BIT(3)] 254 * B1100_0000_0000_1111 = 0xC00F : BIT(14) | BIT(15) [right 80MHz: BIT(0) | BIT(1) | BIT(2) | BIT(3)] 255 * 256 * Band: 320MHz Puncturing Unit: 80Mhz+40Mhz (Left 80Mhz punctured) 257 * B1111_0000_0000_0011 = 0xF003 : BIT(4) | BIT(5) [left 80MHz: BIT(12) | BIT(13) | BIT(14) | BIT(15)] 258 * B1111_0000_0000_1100 = 0xF00C : BIT(6) | BIT(7) [left 80MHz: BIT(12) | BIT(13) | BIT(14) | BIT(15)] 259 * B1111_0000_0011_0000 = 0xF030 : BIT(8) | BIT(9) [left 80MHz: BIT(12) | BIT(13) | BIT(14) | BIT(15)] 260 * B1111_0000_1100_0000 = 0xF0C0 : BIT(10) | BIT(11) [left 80MHz: BIT(12) | BIT(13) | BIT(14) | BIT(15)] 261 * B1111_0011_0000_0000 = 0xF300 : BIT(12) | BIT(13) [left 80MHz: BIT(12) | BIT(13) | BIT(14) | BIT(15)] 262 * B1111_1100_0000_0000 = 0xFC00 : BIT(14) | BIT(15) [left 80MHz: BIT(12) | BIT(13) | BIT(14) | BIT(15)] 263 */ 264 static const uint16_t chan_80mhz_puncture_bitmap[] = { 265 /* 20Mhz puncturing pattern */ 266 0x1, 267 0x2, 268 0x4, 269 0x8 270 }; 271 272 static const uint16_t chan_160mhz_puncture_bitmap[] = { 273 /* 20Mhz puncturing pattern */ 274 0x1, 275 0x2, 276 0x4, 277 0x8, 278 0x10, 279 0x20, 280 0x40, 281 0x80, 282 /* 40Mhz puncturing pattern */ 283 0x3, 284 0xc, 285 0x30, 286 0xc0 287 }; 288 289 static const uint16_t chan_320mhz_puncture_bitmap[] = { 290 /* 40Mhz puncturing pattern */ 291 0x3, 292 0xc, 293 0x30, 294 0xc0, 295 0x300, 296 0xc00, 297 0x3000, 298 0xc000, 299 /* 80Mhz puncturing pattern */ 300 0xf, 301 0xf0, 302 0xf00, 303 0xf000, 304 /* 80+40Mhz puncturing pattern: Left 80MHz punctured */ 305 0x3f, 306 0xcf, 307 0x30f, 308 0xc0f, 309 0x300f, 310 0xc00f, 311 /* 80+40Mhz puncturing pattern: Right 80MHz punctured */ 312 0xf003, 313 0xf00c, 314 0xf030, 315 0xf0c0, 316 0xf300, 317 0xfc00 318 }; 319 320 struct bw_puncture_bitmap_pair { 321 enum phy_ch_width chwidth; 322 const uint16_t *puncture_bitmap_arr; 323 uint16_t array_size; 324 }; 325 326 static const 327 struct bw_puncture_bitmap_pair bw_puncture_bitmap_pair_map[] = { 328 {CH_WIDTH_320MHZ, chan_320mhz_puncture_bitmap, 329 QDF_ARRAY_SIZE(chan_320mhz_puncture_bitmap)}, 330 {CH_WIDTH_160MHZ, chan_160mhz_puncture_bitmap, 331 QDF_ARRAY_SIZE(chan_160mhz_puncture_bitmap)}, 332 {CH_WIDTH_80MHZ, chan_80mhz_puncture_bitmap, 333 QDF_ARRAY_SIZE(chan_80mhz_puncture_bitmap)}, 334 }; 335 336 static inline qdf_freq_t 337 reg_get_band_cen_from_bandstart(uint16_t bw, qdf_freq_t bandstart) 338 { 339 return bandstart - BW_10_MHZ + bw / 2; 340 } 341 342 #ifdef WLAN_FEATURE_11BE 343 uint16_t 344 reg_fetch_punc_bitmap(struct ch_params *ch_params) 345 { 346 if (!ch_params) 347 return NO_SCHANS_PUNC; 348 349 return ch_params->input_punc_bitmap; 350 } 351 #endif 352 353 #else /* WLAN_FEATURE_11BE */ 354 static inline qdf_freq_t 355 reg_get_band_cen_from_bandstart(uint16_t bw, qdf_freq_t bandstart) 356 { 357 return 0; 358 } 359 360 #endif /* WLAN_FEATURE_11BE */ 361 362 static bool reg_is_freq_within_bonded_chan( 363 qdf_freq_t freq, 364 const struct bonded_channel_freq *bonded_chan_arr, 365 enum phy_ch_width chwidth, qdf_freq_t cen320_freq) 366 { 367 qdf_freq_t band_center; 368 369 if (reg_is_ch_width_320(chwidth) && cen320_freq) { 370 /* 371 * For the 5GHz 320/240 MHz channel, bonded pair ends are not 372 * symmetric around the center of the channel. Use the start 373 * frequency of the bonded channel to calculate the center 374 */ 375 if (REG_IS_5GHZ_FREQ(freq)) { 376 qdf_freq_t start_freq = bonded_chan_arr->start_freq; 377 uint16_t bw = reg_get_bw_value(chwidth); 378 379 band_center = 380 reg_get_band_cen_from_bandstart(bw, 381 start_freq); 382 } else 383 band_center = (bonded_chan_arr->start_freq + 384 bonded_chan_arr->end_freq) >> 1; 385 if (band_center != cen320_freq) 386 return false; 387 } 388 389 if (freq >= bonded_chan_arr->start_freq && 390 freq <= bonded_chan_arr->end_freq) 391 return true; 392 393 return false; 394 } 395 396 const struct bonded_channel_freq * 397 reg_get_bonded_chan_entry(qdf_freq_t freq, 398 enum phy_ch_width chwidth, 399 qdf_freq_t cen320_freq) 400 { 401 const struct bonded_channel_freq *bonded_chan_arr; 402 uint16_t array_size, i, num_bws; 403 404 num_bws = QDF_ARRAY_SIZE(bw_bonded_array_pair_map); 405 for (i = 0; i < num_bws; i++) { 406 if (chwidth == bw_bonded_array_pair_map[i].chwidth) { 407 bonded_chan_arr = 408 bw_bonded_array_pair_map[i].bonded_chan_arr; 409 array_size = bw_bonded_array_pair_map[i].array_size; 410 break; 411 } 412 } 413 if (i == num_bws) { 414 reg_debug("Could not find bonded_chan_array for chwidth %d", 415 chwidth); 416 return NULL; 417 } 418 419 for (i = 0; i < array_size; i++) { 420 if (reg_is_freq_within_bonded_chan(freq, &bonded_chan_arr[i], 421 chwidth, cen320_freq)) 422 return &bonded_chan_arr[i]; 423 } 424 425 reg_debug("Could not find a bonded pair for freq %d and width %d cen320_freq %u", 426 freq, chwidth, cen320_freq); 427 return NULL; 428 } 429 430 #endif /*CONFIG_CHAN_FREQ_API*/ 431 432 enum phy_ch_width get_next_lower_bandwidth(enum phy_ch_width ch_width) 433 { 434 static const enum phy_ch_width get_next_lower_bw[] = { 435 /* 80+80 mode not supported in chips that support 320 mode */ 436 #ifdef WLAN_FEATURE_11BE 437 [CH_WIDTH_320MHZ] = CH_WIDTH_160MHZ, 438 #endif 439 [CH_WIDTH_80P80MHZ] = CH_WIDTH_160MHZ, 440 [CH_WIDTH_160MHZ] = CH_WIDTH_80MHZ, 441 [CH_WIDTH_80MHZ] = CH_WIDTH_40MHZ, 442 [CH_WIDTH_40MHZ] = CH_WIDTH_20MHZ, 443 [CH_WIDTH_20MHZ] = CH_WIDTH_10MHZ, 444 [CH_WIDTH_10MHZ] = CH_WIDTH_5MHZ, 445 [CH_WIDTH_5MHZ] = CH_WIDTH_INVALID 446 }; 447 448 return get_next_lower_bw[ch_width]; 449 } 450 451 const struct chan_map channel_map_us[NUM_CHANNELS] = { 452 [CHAN_ENUM_2412] = {2412, 1, 20, 40}, 453 [CHAN_ENUM_2417] = {2417, 2, 20, 40}, 454 [CHAN_ENUM_2422] = {2422, 3, 20, 40}, 455 [CHAN_ENUM_2427] = {2427, 4, 20, 40}, 456 [CHAN_ENUM_2432] = {2432, 5, 20, 40}, 457 [CHAN_ENUM_2437] = {2437, 6, 20, 40}, 458 [CHAN_ENUM_2442] = {2442, 7, 20, 40}, 459 [CHAN_ENUM_2447] = {2447, 8, 20, 40}, 460 [CHAN_ENUM_2452] = {2452, 9, 20, 40}, 461 [CHAN_ENUM_2457] = {2457, 10, 20, 40}, 462 [CHAN_ENUM_2462] = {2462, 11, 20, 40}, 463 [CHAN_ENUM_2467] = {2467, 12, 20, 40}, 464 [CHAN_ENUM_2472] = {2472, 13, 20, 40}, 465 [CHAN_ENUM_2484] = {2484, 14, 20, 20}, 466 #ifdef CONFIG_49GHZ_CHAN 467 [CHAN_ENUM_4912] = {4912, INVALID_CHANNEL_NUM, 2, 20}, 468 [CHAN_ENUM_4915] = {4915, INVALID_CHANNEL_NUM, 2, 20}, 469 [CHAN_ENUM_4917] = {4917, INVALID_CHANNEL_NUM, 2, 20}, 470 [CHAN_ENUM_4920] = {4920, INVALID_CHANNEL_NUM, 2, 20}, 471 [CHAN_ENUM_4922] = {4922, INVALID_CHANNEL_NUM, 2, 20}, 472 [CHAN_ENUM_4925] = {4925, INVALID_CHANNEL_NUM, 2, 20}, 473 [CHAN_ENUM_4927] = {4927, INVALID_CHANNEL_NUM, 2, 20}, 474 [CHAN_ENUM_4932] = {4932, INVALID_CHANNEL_NUM, 2, 20}, 475 [CHAN_ENUM_4935] = {4935, INVALID_CHANNEL_NUM, 2, 20}, 476 [CHAN_ENUM_4937] = {4937, INVALID_CHANNEL_NUM, 2, 20}, 477 [CHAN_ENUM_4940] = {4940, INVALID_CHANNEL_NUM, 2, 20}, 478 [CHAN_ENUM_4942] = {4942, 1, 5, 5}, 479 [CHAN_ENUM_4945] = {4945, 11, 10, 10}, 480 [CHAN_ENUM_4947] = {4947, 2, 5, 5}, 481 [CHAN_ENUM_4950] = {4950, 20, 10, 20}, 482 [CHAN_ENUM_4952] = {4952, 3, 5, 5}, 483 [CHAN_ENUM_4955] = {4955, 21, 10, 20}, 484 [CHAN_ENUM_4957] = {4957, 4, 5, 5}, 485 [CHAN_ENUM_4960] = {4960, 22, 10, 20}, 486 [CHAN_ENUM_4962] = {4962, 5, 5, 5}, 487 [CHAN_ENUM_4965] = {4965, 23, 10, 20}, 488 [CHAN_ENUM_4967] = {4967, 6, 5, 5}, 489 [CHAN_ENUM_4970] = {4970, 24, 10, 20}, 490 [CHAN_ENUM_4972] = {4972, 7, 5, 5}, 491 [CHAN_ENUM_4975] = {4975, 25, 10, 20}, 492 [CHAN_ENUM_4977] = {4977, 8, 5, 5}, 493 [CHAN_ENUM_4980] = {4980, 26, 10, 20}, 494 [CHAN_ENUM_4982] = {4982, 9, 5, 5}, 495 [CHAN_ENUM_4985] = {4985, 19, 10, 10}, 496 [CHAN_ENUM_4987] = {4987, 10, 5, 5}, 497 [CHAN_ENUM_5032] = {5032, INVALID_CHANNEL_NUM, 2, 20}, 498 [CHAN_ENUM_5035] = {5035, INVALID_CHANNEL_NUM, 2, 20}, 499 [CHAN_ENUM_5037] = {5037, INVALID_CHANNEL_NUM, 2, 20}, 500 [CHAN_ENUM_5040] = {5040, INVALID_CHANNEL_NUM, 2, 20}, 501 [CHAN_ENUM_5042] = {5042, INVALID_CHANNEL_NUM, 2, 20}, 502 [CHAN_ENUM_5045] = {5045, INVALID_CHANNEL_NUM, 2, 20}, 503 [CHAN_ENUM_5047] = {5047, INVALID_CHANNEL_NUM, 2, 20}, 504 [CHAN_ENUM_5052] = {5052, INVALID_CHANNEL_NUM, 2, 20}, 505 [CHAN_ENUM_5055] = {5055, INVALID_CHANNEL_NUM, 2, 20}, 506 [CHAN_ENUM_5057] = {5057, INVALID_CHANNEL_NUM, 2, 20}, 507 [CHAN_ENUM_5060] = {5060, INVALID_CHANNEL_NUM, 2, 20}, 508 [CHAN_ENUM_5080] = {5080, INVALID_CHANNEL_NUM, 2, 20}, 509 #endif /* CONFIG_49GHZ_CHAN */ 510 [CHAN_ENUM_5180] = {5180, 36, 2, 160}, 511 [CHAN_ENUM_5200] = {5200, 40, 2, 160}, 512 [CHAN_ENUM_5220] = {5220, 44, 2, 160}, 513 [CHAN_ENUM_5240] = {5240, 48, 2, 160}, 514 [CHAN_ENUM_5260] = {5260, 52, 2, 160}, 515 [CHAN_ENUM_5280] = {5280, 56, 2, 160}, 516 [CHAN_ENUM_5300] = {5300, 60, 2, 160}, 517 [CHAN_ENUM_5320] = {5320, 64, 2, 160}, 518 [CHAN_ENUM_5500] = {5500, 100, 2, 240}, 519 [CHAN_ENUM_5520] = {5520, 104, 2, 240}, 520 [CHAN_ENUM_5540] = {5540, 108, 2, 240}, 521 [CHAN_ENUM_5560] = {5560, 112, 2, 240}, 522 [CHAN_ENUM_5580] = {5580, 116, 2, 240}, 523 [CHAN_ENUM_5600] = {5600, 120, 2, 240}, 524 [CHAN_ENUM_5620] = {5620, 124, 2, 240}, 525 [CHAN_ENUM_5640] = {5640, 128, 2, 240}, 526 [CHAN_ENUM_5660] = {5660, 132, 2, 240}, 527 [CHAN_ENUM_5680] = {5680, 136, 2, 240}, 528 [CHAN_ENUM_5700] = {5700, 140, 2, 240}, 529 [CHAN_ENUM_5720] = {5720, 144, 2, 240}, 530 [CHAN_ENUM_5745] = {5745, 149, 2, 160}, 531 [CHAN_ENUM_5765] = {5765, 153, 2, 160}, 532 [CHAN_ENUM_5785] = {5785, 157, 2, 160}, 533 [CHAN_ENUM_5805] = {5805, 161, 2, 160}, 534 [CHAN_ENUM_5825] = {5825, 165, 2, 160}, 535 [CHAN_ENUM_5845] = {5845, 169, 2, 160}, 536 #ifdef WLAN_FEATURE_DSRC 537 [CHAN_ENUM_5850] = {5850, 170, 2, 160}, 538 [CHAN_ENUM_5855] = {5855, 171, 2, 160}, 539 [CHAN_ENUM_5860] = {5860, 172, 2, 160}, 540 #endif 541 [CHAN_ENUM_5865] = {5865, 173, 2, 160}, 542 #ifdef WLAN_FEATURE_DSRC 543 [CHAN_ENUM_5870] = {5870, 174, 2, 160}, 544 [CHAN_ENUM_5875] = {5875, 175, 2, 160}, 545 [CHAN_ENUM_5880] = {5880, 176, 2, 160}, 546 #endif 547 [CHAN_ENUM_5885] = {5885, 177, 2, 160}, 548 #ifdef WLAN_FEATURE_DSRC 549 [CHAN_ENUM_5890] = {5890, 178, 2, 160}, 550 [CHAN_ENUM_5895] = {5895, 179, 2, 160}, 551 [CHAN_ENUM_5900] = {5900, 180, 2, 160}, 552 [CHAN_ENUM_5905] = {5905, 181, 2, 160}, 553 [CHAN_ENUM_5910] = {5910, 182, 2, 160}, 554 [CHAN_ENUM_5915] = {5915, 183, 2, 160}, 555 [CHAN_ENUM_5920] = {5920, 184, 2, 160}, 556 #endif /* WLAN_FEATURE_DSRC */ 557 #ifdef CONFIG_BAND_6GHZ 558 [CHAN_ENUM_5935] = {5935, 2, 2, 20}, 559 [CHAN_ENUM_5955] = {5955, 1, 2, 320}, 560 [CHAN_ENUM_5975] = {5975, 5, 2, 320}, 561 [CHAN_ENUM_5995] = {5995, 9, 2, 320}, 562 [CHAN_ENUM_6015] = {6015, 13, 2, 320}, 563 [CHAN_ENUM_6035] = {6035, 17, 2, 320}, 564 [CHAN_ENUM_6055] = {6055, 21, 2, 320}, 565 [CHAN_ENUM_6075] = {6075, 25, 2, 320}, 566 [CHAN_ENUM_6095] = {6095, 29, 2, 320}, 567 [CHAN_ENUM_6115] = {6115, 33, 2, 320}, 568 [CHAN_ENUM_6135] = {6135, 37, 2, 320}, 569 [CHAN_ENUM_6155] = {6155, 41, 2, 320}, 570 [CHAN_ENUM_6175] = {6175, 45, 2, 320}, 571 [CHAN_ENUM_6195] = {6195, 49, 2, 320}, 572 [CHAN_ENUM_6215] = {6215, 53, 2, 320}, 573 [CHAN_ENUM_6235] = {6235, 57, 2, 320}, 574 [CHAN_ENUM_6255] = {6255, 61, 2, 320}, 575 [CHAN_ENUM_6275] = {6275, 65, 2, 320}, 576 [CHAN_ENUM_6295] = {6295, 69, 2, 320}, 577 [CHAN_ENUM_6315] = {6315, 73, 2, 320}, 578 [CHAN_ENUM_6335] = {6335, 77, 2, 320}, 579 [CHAN_ENUM_6355] = {6355, 81, 2, 320}, 580 [CHAN_ENUM_6375] = {6375, 85, 2, 320}, 581 [CHAN_ENUM_6395] = {6395, 89, 2, 320}, 582 [CHAN_ENUM_6415] = {6415, 93, 2, 320}, 583 [CHAN_ENUM_6435] = {6435, 97, 2, 320}, 584 [CHAN_ENUM_6455] = {6455, 101, 2, 320}, 585 [CHAN_ENUM_6475] = {6475, 105, 2, 320}, 586 [CHAN_ENUM_6495] = {6495, 109, 2, 320}, 587 [CHAN_ENUM_6515] = {6515, 113, 2, 320}, 588 [CHAN_ENUM_6535] = {6535, 117, 2, 320}, 589 [CHAN_ENUM_6555] = {6555, 121, 2, 320}, 590 [CHAN_ENUM_6575] = {6575, 125, 2, 320}, 591 [CHAN_ENUM_6595] = {6595, 129, 2, 320}, 592 [CHAN_ENUM_6615] = {6615, 133, 2, 320}, 593 [CHAN_ENUM_6635] = {6635, 137, 2, 320}, 594 [CHAN_ENUM_6655] = {6655, 141, 2, 320}, 595 [CHAN_ENUM_6675] = {6675, 145, 2, 320}, 596 [CHAN_ENUM_6695] = {6695, 149, 2, 320}, 597 [CHAN_ENUM_6715] = {6715, 153, 2, 320}, 598 [CHAN_ENUM_6735] = {6735, 157, 2, 320}, 599 [CHAN_ENUM_6755] = {6755, 161, 2, 320}, 600 [CHAN_ENUM_6775] = {6775, 165, 2, 320}, 601 [CHAN_ENUM_6795] = {6795, 169, 2, 320}, 602 [CHAN_ENUM_6815] = {6815, 173, 2, 320}, 603 [CHAN_ENUM_6835] = {6835, 177, 2, 320}, 604 [CHAN_ENUM_6855] = {6855, 181, 2, 320}, 605 [CHAN_ENUM_6875] = {6875, 185, 2, 320}, 606 [CHAN_ENUM_6895] = {6895, 189, 2, 320}, 607 [CHAN_ENUM_6915] = {6915, 193, 2, 320}, 608 [CHAN_ENUM_6935] = {6935, 197, 2, 320}, 609 [CHAN_ENUM_6955] = {6955, 201, 2, 320}, 610 [CHAN_ENUM_6975] = {6975, 205, 2, 320}, 611 [CHAN_ENUM_6995] = {6995, 209, 2, 320}, 612 [CHAN_ENUM_7015] = {7015, 213, 2, 320}, 613 [CHAN_ENUM_7035] = {7035, 217, 2, 320}, 614 [CHAN_ENUM_7055] = {7055, 221, 2, 320}, 615 [CHAN_ENUM_7075] = {7075, 225, 2, 160}, 616 [CHAN_ENUM_7095] = {7095, 229, 2, 160}, 617 [CHAN_ENUM_7115] = {7115, 233, 2, 160} 618 #endif /* CONFIG_BAND_6GHZ */ 619 }; 620 621 const struct chan_map channel_map_eu[NUM_CHANNELS] = { 622 [CHAN_ENUM_2412] = {2412, 1, 20, 40}, 623 [CHAN_ENUM_2417] = {2417, 2, 20, 40}, 624 [CHAN_ENUM_2422] = {2422, 3, 20, 40}, 625 [CHAN_ENUM_2427] = {2427, 4, 20, 40}, 626 [CHAN_ENUM_2432] = {2432, 5, 20, 40}, 627 [CHAN_ENUM_2437] = {2437, 6, 20, 40}, 628 [CHAN_ENUM_2442] = {2442, 7, 20, 40}, 629 [CHAN_ENUM_2447] = {2447, 8, 20, 40}, 630 [CHAN_ENUM_2452] = {2452, 9, 20, 40}, 631 [CHAN_ENUM_2457] = {2457, 10, 20, 40}, 632 [CHAN_ENUM_2462] = {2462, 11, 20, 40}, 633 [CHAN_ENUM_2467] = {2467, 12, 20, 40}, 634 [CHAN_ENUM_2472] = {2472, 13, 20, 40}, 635 [CHAN_ENUM_2484] = {2484, 14, 20, 20}, 636 #ifdef CONFIG_49GHZ_CHAN 637 [CHAN_ENUM_4912] = {4912, INVALID_CHANNEL_NUM, 2, 20}, 638 [CHAN_ENUM_4915] = {4915, INVALID_CHANNEL_NUM, 2, 20}, 639 [CHAN_ENUM_4917] = {4917, INVALID_CHANNEL_NUM, 2, 20}, 640 [CHAN_ENUM_4920] = {4920, INVALID_CHANNEL_NUM, 2, 20}, 641 [CHAN_ENUM_4922] = {4922, INVALID_CHANNEL_NUM, 2, 20}, 642 [CHAN_ENUM_4925] = {4925, INVALID_CHANNEL_NUM, 2, 20}, 643 [CHAN_ENUM_4927] = {4927, INVALID_CHANNEL_NUM, 2, 20}, 644 [CHAN_ENUM_4932] = {4932, INVALID_CHANNEL_NUM, 2, 20}, 645 [CHAN_ENUM_4935] = {4935, INVALID_CHANNEL_NUM, 2, 20}, 646 [CHAN_ENUM_4937] = {4937, INVALID_CHANNEL_NUM, 2, 20}, 647 [CHAN_ENUM_4940] = {4940, INVALID_CHANNEL_NUM, 2, 20}, 648 [CHAN_ENUM_4942] = {4942, INVALID_CHANNEL_NUM, 2, 20}, 649 [CHAN_ENUM_4945] = {4945, INVALID_CHANNEL_NUM, 2, 20}, 650 [CHAN_ENUM_4947] = {4947, INVALID_CHANNEL_NUM, 2, 20}, 651 [CHAN_ENUM_4950] = {4950, INVALID_CHANNEL_NUM, 2, 20}, 652 [CHAN_ENUM_4952] = {4952, INVALID_CHANNEL_NUM, 2, 20}, 653 [CHAN_ENUM_4955] = {4955, INVALID_CHANNEL_NUM, 2, 20}, 654 [CHAN_ENUM_4957] = {4957, INVALID_CHANNEL_NUM, 2, 20}, 655 [CHAN_ENUM_4960] = {4960, INVALID_CHANNEL_NUM, 2, 20}, 656 [CHAN_ENUM_4962] = {4962, INVALID_CHANNEL_NUM, 2, 20}, 657 [CHAN_ENUM_4965] = {4965, INVALID_CHANNEL_NUM, 2, 20}, 658 [CHAN_ENUM_4967] = {4967, INVALID_CHANNEL_NUM, 2, 20}, 659 [CHAN_ENUM_4970] = {4970, INVALID_CHANNEL_NUM, 2, 20}, 660 [CHAN_ENUM_4972] = {4972, INVALID_CHANNEL_NUM, 2, 20}, 661 [CHAN_ENUM_4975] = {4975, INVALID_CHANNEL_NUM, 2, 20}, 662 [CHAN_ENUM_4977] = {4977, INVALID_CHANNEL_NUM, 2, 20}, 663 [CHAN_ENUM_4980] = {4980, INVALID_CHANNEL_NUM, 2, 20}, 664 [CHAN_ENUM_4982] = {4982, INVALID_CHANNEL_NUM, 2, 20}, 665 [CHAN_ENUM_4985] = {4985, INVALID_CHANNEL_NUM, 2, 20}, 666 [CHAN_ENUM_4987] = {4987, INVALID_CHANNEL_NUM, 2, 20}, 667 [CHAN_ENUM_5032] = {5032, INVALID_CHANNEL_NUM, 2, 20}, 668 [CHAN_ENUM_5035] = {5035, INVALID_CHANNEL_NUM, 2, 20}, 669 [CHAN_ENUM_5037] = {5037, INVALID_CHANNEL_NUM, 2, 20}, 670 [CHAN_ENUM_5040] = {5040, INVALID_CHANNEL_NUM, 2, 20}, 671 [CHAN_ENUM_5042] = {5042, INVALID_CHANNEL_NUM, 2, 20}, 672 [CHAN_ENUM_5045] = {5045, INVALID_CHANNEL_NUM, 2, 20}, 673 [CHAN_ENUM_5047] = {5047, INVALID_CHANNEL_NUM, 2, 20}, 674 [CHAN_ENUM_5052] = {5052, INVALID_CHANNEL_NUM, 2, 20}, 675 [CHAN_ENUM_5055] = {5055, INVALID_CHANNEL_NUM, 2, 20}, 676 [CHAN_ENUM_5057] = {5057, INVALID_CHANNEL_NUM, 2, 20}, 677 [CHAN_ENUM_5060] = {5060, INVALID_CHANNEL_NUM, 2, 20}, 678 [CHAN_ENUM_5080] = {5080, INVALID_CHANNEL_NUM, 2, 20}, 679 #endif /* CONFIG_49GHZ_CHAN */ 680 [CHAN_ENUM_5180] = {5180, 36, 2, 160}, 681 [CHAN_ENUM_5200] = {5200, 40, 2, 160}, 682 [CHAN_ENUM_5220] = {5220, 44, 2, 160}, 683 [CHAN_ENUM_5240] = {5240, 48, 2, 160}, 684 [CHAN_ENUM_5260] = {5260, 52, 2, 160}, 685 [CHAN_ENUM_5280] = {5280, 56, 2, 160}, 686 [CHAN_ENUM_5300] = {5300, 60, 2, 160}, 687 [CHAN_ENUM_5320] = {5320, 64, 2, 160}, 688 [CHAN_ENUM_5500] = {5500, 100, 2, 240}, 689 [CHAN_ENUM_5520] = {5520, 104, 2, 240}, 690 [CHAN_ENUM_5540] = {5540, 108, 2, 240}, 691 [CHAN_ENUM_5560] = {5560, 112, 2, 240}, 692 [CHAN_ENUM_5580] = {5580, 116, 2, 240}, 693 [CHAN_ENUM_5600] = {5600, 120, 2, 240}, 694 [CHAN_ENUM_5620] = {5620, 124, 2, 240}, 695 [CHAN_ENUM_5640] = {5640, 128, 2, 240}, 696 [CHAN_ENUM_5660] = {5660, 132, 2, 240}, 697 [CHAN_ENUM_5680] = {5680, 136, 2, 240}, 698 [CHAN_ENUM_5700] = {5700, 140, 2, 240}, 699 [CHAN_ENUM_5720] = {5720, 144, 2, 240}, 700 [CHAN_ENUM_5745] = {5745, 149, 2, 160}, 701 [CHAN_ENUM_5765] = {5765, 153, 2, 160}, 702 [CHAN_ENUM_5785] = {5785, 157, 2, 160}, 703 [CHAN_ENUM_5805] = {5805, 161, 2, 160}, 704 [CHAN_ENUM_5825] = {5825, 165, 2, 160}, 705 [CHAN_ENUM_5845] = {5845, 169, 2, 160}, 706 #ifdef WLAN_FEATURE_DSRC 707 [CHAN_ENUM_5850] = {5850, INVALID_CHANNEL_NUM, 2, 160}, 708 [CHAN_ENUM_5855] = {5855, INVALID_CHANNEL_NUM, 2, 160}, 709 [CHAN_ENUM_5860] = {5860, INVALID_CHANNEL_NUM, 2, 160}, 710 #endif 711 [CHAN_ENUM_5865] = {5865, 173, 2, 160}, 712 #ifdef WLAN_FEATURE_DSRC 713 [CHAN_ENUM_5870] = {5870, INVALID_CHANNEL_NUM, 2, 160}, 714 [CHAN_ENUM_5875] = {5875, 175, 2, 160}, 715 [CHAN_ENUM_5880] = {5880, 176, 2, 160}, 716 #endif 717 [CHAN_ENUM_5885] = {5885, 177, 2, 160}, 718 #ifdef WLAN_FEATURE_DSRC 719 [CHAN_ENUM_5890] = {5890, 178, 2, 160}, 720 [CHAN_ENUM_5895] = {5895, 179, 2, 160}, 721 [CHAN_ENUM_5900] = {5900, 180, 2, 160}, 722 [CHAN_ENUM_5905] = {5905, 181, 2, 160}, 723 [CHAN_ENUM_5910] = {5910, 182, 2, 160}, 724 [CHAN_ENUM_5915] = {5915, 183, 2, 160}, 725 [CHAN_ENUM_5920] = {5920, 184, 2, 160}, 726 #endif /* WLAN_FEATURE_DSRC */ 727 #ifdef CONFIG_BAND_6GHZ 728 [CHAN_ENUM_5935] = {5935, 2, 2, 20}, 729 [CHAN_ENUM_5955] = {5955, 1, 2, 320}, 730 [CHAN_ENUM_5975] = {5975, 5, 2, 320}, 731 [CHAN_ENUM_5995] = {5995, 9, 2, 320}, 732 [CHAN_ENUM_6015] = {6015, 13, 2, 320}, 733 [CHAN_ENUM_6035] = {6035, 17, 2, 320}, 734 [CHAN_ENUM_6055] = {6055, 21, 2, 320}, 735 [CHAN_ENUM_6075] = {6075, 25, 2, 320}, 736 [CHAN_ENUM_6095] = {6095, 29, 2, 320}, 737 [CHAN_ENUM_6115] = {6115, 33, 2, 320}, 738 [CHAN_ENUM_6135] = {6135, 37, 2, 320}, 739 [CHAN_ENUM_6155] = {6155, 41, 2, 320}, 740 [CHAN_ENUM_6175] = {6175, 45, 2, 320}, 741 [CHAN_ENUM_6195] = {6195, 49, 2, 320}, 742 [CHAN_ENUM_6215] = {6215, 53, 2, 320}, 743 [CHAN_ENUM_6235] = {6235, 57, 2, 320}, 744 [CHAN_ENUM_6255] = {6255, 61, 2, 320}, 745 [CHAN_ENUM_6275] = {6275, 65, 2, 320}, 746 [CHAN_ENUM_6295] = {6295, 69, 2, 320}, 747 [CHAN_ENUM_6315] = {6315, 73, 2, 320}, 748 [CHAN_ENUM_6335] = {6335, 77, 2, 320}, 749 [CHAN_ENUM_6355] = {6355, 81, 2, 320}, 750 [CHAN_ENUM_6375] = {6375, 85, 2, 320}, 751 [CHAN_ENUM_6395] = {6395, 89, 2, 320}, 752 [CHAN_ENUM_6415] = {6415, 93, 2, 320}, 753 [CHAN_ENUM_6435] = {6435, 97, 2, 320}, 754 [CHAN_ENUM_6455] = {6455, 101, 2, 320}, 755 [CHAN_ENUM_6475] = {6475, 105, 2, 320}, 756 [CHAN_ENUM_6495] = {6495, 109, 2, 320}, 757 [CHAN_ENUM_6515] = {6515, 113, 2, 320}, 758 [CHAN_ENUM_6535] = {6535, 117, 2, 320}, 759 [CHAN_ENUM_6555] = {6555, 121, 2, 320}, 760 [CHAN_ENUM_6575] = {6575, 125, 2, 320}, 761 [CHAN_ENUM_6595] = {6595, 129, 2, 320}, 762 [CHAN_ENUM_6615] = {6615, 133, 2, 320}, 763 [CHAN_ENUM_6635] = {6635, 137, 2, 320}, 764 [CHAN_ENUM_6655] = {6655, 141, 2, 320}, 765 [CHAN_ENUM_6675] = {6675, 145, 2, 320}, 766 [CHAN_ENUM_6695] = {6695, 149, 2, 320}, 767 [CHAN_ENUM_6715] = {6715, 153, 2, 320}, 768 [CHAN_ENUM_6735] = {6735, 157, 2, 320}, 769 [CHAN_ENUM_6755] = {6755, 161, 2, 320}, 770 [CHAN_ENUM_6775] = {6775, 165, 2, 320}, 771 [CHAN_ENUM_6795] = {6795, 169, 2, 320}, 772 [CHAN_ENUM_6815] = {6815, 173, 2, 320}, 773 [CHAN_ENUM_6835] = {6835, 177, 2, 320}, 774 [CHAN_ENUM_6855] = {6855, 181, 2, 320}, 775 [CHAN_ENUM_6875] = {6875, 185, 2, 320}, 776 [CHAN_ENUM_6895] = {6895, 189, 2, 320}, 777 [CHAN_ENUM_6915] = {6915, 193, 2, 320}, 778 [CHAN_ENUM_6935] = {6935, 197, 2, 320}, 779 [CHAN_ENUM_6955] = {6955, 201, 2, 320}, 780 [CHAN_ENUM_6975] = {6975, 205, 2, 320}, 781 [CHAN_ENUM_6995] = {6995, 209, 2, 320}, 782 [CHAN_ENUM_7015] = {7015, 213, 2, 320}, 783 [CHAN_ENUM_7035] = {7035, 217, 2, 320}, 784 [CHAN_ENUM_7055] = {7055, 221, 2, 320}, 785 [CHAN_ENUM_7075] = {7075, 225, 2, 160}, 786 [CHAN_ENUM_7095] = {7095, 229, 2, 160}, 787 [CHAN_ENUM_7115] = {7115, 233, 2, 160} 788 #endif /* CONFIG_BAND_6GHZ */ 789 }; 790 791 const struct chan_map channel_map_jp[NUM_CHANNELS] = { 792 [CHAN_ENUM_2412] = {2412, 1, 20, 40}, 793 [CHAN_ENUM_2417] = {2417, 2, 20, 40}, 794 [CHAN_ENUM_2422] = {2422, 3, 20, 40}, 795 [CHAN_ENUM_2427] = {2427, 4, 20, 40}, 796 [CHAN_ENUM_2432] = {2432, 5, 20, 40}, 797 [CHAN_ENUM_2437] = {2437, 6, 20, 40}, 798 [CHAN_ENUM_2442] = {2442, 7, 20, 40}, 799 [CHAN_ENUM_2447] = {2447, 8, 20, 40}, 800 [CHAN_ENUM_2452] = {2452, 9, 20, 40}, 801 [CHAN_ENUM_2457] = {2457, 10, 20, 40}, 802 [CHAN_ENUM_2462] = {2462, 11, 20, 40}, 803 [CHAN_ENUM_2467] = {2467, 12, 20, 40}, 804 [CHAN_ENUM_2472] = {2472, 13, 20, 40}, 805 [CHAN_ENUM_2484] = {2484, 14, 20, 20}, 806 #ifdef CONFIG_49GHZ_CHAN 807 [CHAN_ENUM_4912] = {4912, 182, 5, 5}, 808 [CHAN_ENUM_4915] = {4915, 183, 10, 10}, 809 [CHAN_ENUM_4917] = {4917, 183, 5, 5}, 810 [CHAN_ENUM_4920] = {4920, 184, 10, 20}, 811 [CHAN_ENUM_4922] = {4922, 184, 5, 5}, 812 [CHAN_ENUM_4925] = {4925, 185, 10, 10}, 813 [CHAN_ENUM_4927] = {4927, 185, 5, 5}, 814 [CHAN_ENUM_4932] = {4932, 186, 5, 5}, 815 [CHAN_ENUM_4935] = {4935, 187, 10, 10}, 816 [CHAN_ENUM_4937] = {4937, 187, 5, 5}, 817 [CHAN_ENUM_4940] = {4940, 188, 10, 20}, 818 [CHAN_ENUM_4942] = {4942, 188, 5, 5}, 819 [CHAN_ENUM_4945] = {4945, 189, 10, 10}, 820 [CHAN_ENUM_4947] = {4947, 189, 5, 5}, 821 [CHAN_ENUM_4950] = {4950, INVALID_CHANNEL_NUM, 2, 20}, 822 [CHAN_ENUM_4952] = {4952, INVALID_CHANNEL_NUM, 2, 20}, 823 [CHAN_ENUM_4955] = {4955, INVALID_CHANNEL_NUM, 2, 20}, 824 [CHAN_ENUM_4957] = {4957, INVALID_CHANNEL_NUM, 2, 20}, 825 [CHAN_ENUM_4960] = {4960, 192, 20, 20}, 826 [CHAN_ENUM_4962] = {4962, INVALID_CHANNEL_NUM, 2, 20}, 827 [CHAN_ENUM_4965] = {4965, INVALID_CHANNEL_NUM, 2, 20}, 828 [CHAN_ENUM_4967] = {4967, INVALID_CHANNEL_NUM, 2, 20}, 829 [CHAN_ENUM_4970] = {4970, INVALID_CHANNEL_NUM, 2, 20}, 830 [CHAN_ENUM_4972] = {4972, INVALID_CHANNEL_NUM, 2, 20}, 831 [CHAN_ENUM_4975] = {4975, INVALID_CHANNEL_NUM, 2, 20}, 832 [CHAN_ENUM_4977] = {4977, INVALID_CHANNEL_NUM, 2, 20}, 833 [CHAN_ENUM_4980] = {4980, 196, 20, 20}, 834 [CHAN_ENUM_4982] = {4982, INVALID_CHANNEL_NUM, 2, 20}, 835 [CHAN_ENUM_4985] = {4985, INVALID_CHANNEL_NUM, 2, 20}, 836 [CHAN_ENUM_4987] = {4987, INVALID_CHANNEL_NUM, 2, 20}, 837 [CHAN_ENUM_5032] = {5032, 6, 5, 5}, 838 [CHAN_ENUM_5035] = {5035, 7, 10, 10}, 839 [CHAN_ENUM_5037] = {5037, 7, 5, 5}, 840 [CHAN_ENUM_5040] = {5040, 8, 10, 20}, 841 [CHAN_ENUM_5042] = {5042, 8, 5, 5}, 842 [CHAN_ENUM_5045] = {5045, 9, 10, 10}, 843 [CHAN_ENUM_5047] = {5047, 9, 5, 5}, 844 [CHAN_ENUM_5052] = {5052, 10, 5, 5}, 845 [CHAN_ENUM_5055] = {5055, 11, 10, 10}, 846 [CHAN_ENUM_5057] = {5057, 11, 5, 5}, 847 [CHAN_ENUM_5060] = {5060, 12, 20, 20}, 848 [CHAN_ENUM_5080] = {5080, 16, 20, 20}, 849 #endif /* CONFIG_49GHZ_CHAN */ 850 [CHAN_ENUM_5180] = {5180, 36, 2, 160}, 851 [CHAN_ENUM_5200] = {5200, 40, 2, 160}, 852 [CHAN_ENUM_5220] = {5220, 44, 2, 160}, 853 [CHAN_ENUM_5240] = {5240, 48, 2, 160}, 854 [CHAN_ENUM_5260] = {5260, 52, 2, 160}, 855 [CHAN_ENUM_5280] = {5280, 56, 2, 160}, 856 [CHAN_ENUM_5300] = {5300, 60, 2, 160}, 857 [CHAN_ENUM_5320] = {5320, 64, 2, 160}, 858 [CHAN_ENUM_5500] = {5500, 100, 2, 240}, 859 [CHAN_ENUM_5520] = {5520, 104, 2, 240}, 860 [CHAN_ENUM_5540] = {5540, 108, 2, 240}, 861 [CHAN_ENUM_5560] = {5560, 112, 2, 240}, 862 [CHAN_ENUM_5580] = {5580, 116, 2, 240}, 863 [CHAN_ENUM_5600] = {5600, 120, 2, 240}, 864 [CHAN_ENUM_5620] = {5620, 124, 2, 240}, 865 [CHAN_ENUM_5640] = {5640, 128, 2, 240}, 866 [CHAN_ENUM_5660] = {5660, 132, 2, 240}, 867 [CHAN_ENUM_5680] = {5680, 136, 2, 240}, 868 [CHAN_ENUM_5700] = {5700, 140, 2, 240}, 869 [CHAN_ENUM_5720] = {5720, 144, 2, 240}, 870 [CHAN_ENUM_5745] = {5745, 149, 2, 160}, 871 [CHAN_ENUM_5765] = {5765, 153, 2, 160}, 872 [CHAN_ENUM_5785] = {5785, 157, 2, 160}, 873 [CHAN_ENUM_5805] = {5805, 161, 2, 160}, 874 [CHAN_ENUM_5825] = {5825, 165, 2, 160}, 875 [CHAN_ENUM_5845] = {5845, 169, 2, 160}, 876 #ifdef WLAN_FEATURE_DSRC 877 [CHAN_ENUM_5850] = {5850, INVALID_CHANNEL_NUM, 2, 160}, 878 [CHAN_ENUM_5855] = {5855, INVALID_CHANNEL_NUM, 2, 160}, 879 [CHAN_ENUM_5860] = {5860, INVALID_CHANNEL_NUM, 2, 160}, 880 #endif 881 [CHAN_ENUM_5865] = {5865, INVALID_CHANNEL_NUM, 2, 160}, 882 #ifdef WLAN_FEATURE_DSRC 883 [CHAN_ENUM_5870] = {5870, INVALID_CHANNEL_NUM, 2, 160}, 884 [CHAN_ENUM_5875] = {5875, INVALID_CHANNEL_NUM, 2, 160}, 885 [CHAN_ENUM_5880] = {5880, INVALID_CHANNEL_NUM, 2, 160}, 886 #endif 887 [CHAN_ENUM_5885] = {5885, INVALID_CHANNEL_NUM, 2, 160}, 888 #ifdef WLAN_FEATURE_DSRC 889 [CHAN_ENUM_5890] = {5890, INVALID_CHANNEL_NUM, 2, 160}, 890 [CHAN_ENUM_5895] = {5895, INVALID_CHANNEL_NUM, 2, 160}, 891 [CHAN_ENUM_5900] = {5900, INVALID_CHANNEL_NUM, 2, 160}, 892 [CHAN_ENUM_5905] = {5905, INVALID_CHANNEL_NUM, 2, 160}, 893 [CHAN_ENUM_5910] = {5910, INVALID_CHANNEL_NUM, 2, 160}, 894 [CHAN_ENUM_5915] = {5915, INVALID_CHANNEL_NUM, 2, 160}, 895 [CHAN_ENUM_5920] = {5920, INVALID_CHANNEL_NUM, 2, 160}, 896 #endif /* WLAN_FEATURE_DSRC */ 897 #ifdef CONFIG_BAND_6GHZ 898 [CHAN_ENUM_5935] = {5935, 2, 2, 20}, 899 [CHAN_ENUM_5955] = {5955, 1, 2, 320}, 900 [CHAN_ENUM_5975] = {5975, 5, 2, 320}, 901 [CHAN_ENUM_5995] = {5995, 9, 2, 320}, 902 [CHAN_ENUM_6015] = {6015, 13, 2, 320}, 903 [CHAN_ENUM_6035] = {6035, 17, 2, 320}, 904 [CHAN_ENUM_6055] = {6055, 21, 2, 320}, 905 [CHAN_ENUM_6075] = {6075, 25, 2, 320}, 906 [CHAN_ENUM_6095] = {6095, 29, 2, 320}, 907 [CHAN_ENUM_6115] = {6115, 33, 2, 320}, 908 [CHAN_ENUM_6135] = {6135, 37, 2, 320}, 909 [CHAN_ENUM_6155] = {6155, 41, 2, 320}, 910 [CHAN_ENUM_6175] = {6175, 45, 2, 320}, 911 [CHAN_ENUM_6195] = {6195, 49, 2, 320}, 912 [CHAN_ENUM_6215] = {6215, 53, 2, 320}, 913 [CHAN_ENUM_6235] = {6235, 57, 2, 320}, 914 [CHAN_ENUM_6255] = {6255, 61, 2, 320}, 915 [CHAN_ENUM_6275] = {6275, 65, 2, 320}, 916 [CHAN_ENUM_6295] = {6295, 69, 2, 320}, 917 [CHAN_ENUM_6315] = {6315, 73, 2, 320}, 918 [CHAN_ENUM_6335] = {6335, 77, 2, 320}, 919 [CHAN_ENUM_6355] = {6355, 81, 2, 320}, 920 [CHAN_ENUM_6375] = {6375, 85, 2, 320}, 921 [CHAN_ENUM_6395] = {6395, 89, 2, 320}, 922 [CHAN_ENUM_6415] = {6415, 93, 2, 320}, 923 [CHAN_ENUM_6435] = {6435, 97, 2, 320}, 924 [CHAN_ENUM_6455] = {6455, 101, 2, 320}, 925 [CHAN_ENUM_6475] = {6475, 105, 2, 320}, 926 [CHAN_ENUM_6495] = {6495, 109, 2, 320}, 927 [CHAN_ENUM_6515] = {6515, 113, 2, 320}, 928 [CHAN_ENUM_6535] = {6535, 117, 2, 320}, 929 [CHAN_ENUM_6555] = {6555, 121, 2, 320}, 930 [CHAN_ENUM_6575] = {6575, 125, 2, 320}, 931 [CHAN_ENUM_6595] = {6595, 129, 2, 320}, 932 [CHAN_ENUM_6615] = {6615, 133, 2, 320}, 933 [CHAN_ENUM_6635] = {6635, 137, 2, 320}, 934 [CHAN_ENUM_6655] = {6655, 141, 2, 320}, 935 [CHAN_ENUM_6675] = {6675, 145, 2, 320}, 936 [CHAN_ENUM_6695] = {6695, 149, 2, 320}, 937 [CHAN_ENUM_6715] = {6715, 153, 2, 320}, 938 [CHAN_ENUM_6735] = {6735, 157, 2, 320}, 939 [CHAN_ENUM_6755] = {6755, 161, 2, 320}, 940 [CHAN_ENUM_6775] = {6775, 165, 2, 320}, 941 [CHAN_ENUM_6795] = {6795, 169, 2, 320}, 942 [CHAN_ENUM_6815] = {6815, 173, 2, 320}, 943 [CHAN_ENUM_6835] = {6835, 177, 2, 320}, 944 [CHAN_ENUM_6855] = {6855, 181, 2, 320}, 945 [CHAN_ENUM_6875] = {6875, 185, 2, 320}, 946 [CHAN_ENUM_6895] = {6895, 189, 2, 320}, 947 [CHAN_ENUM_6915] = {6915, 193, 2, 320}, 948 [CHAN_ENUM_6935] = {6935, 197, 2, 320}, 949 [CHAN_ENUM_6955] = {6955, 201, 2, 320}, 950 [CHAN_ENUM_6975] = {6975, 205, 2, 320}, 951 [CHAN_ENUM_6995] = {6995, 209, 2, 320}, 952 [CHAN_ENUM_7015] = {7015, 213, 2, 320}, 953 [CHAN_ENUM_7035] = {7035, 217, 2, 320}, 954 [CHAN_ENUM_7055] = {7055, 221, 2, 320}, 955 [CHAN_ENUM_7075] = {7075, 225, 2, 160}, 956 [CHAN_ENUM_7095] = {7095, 229, 2, 160}, 957 [CHAN_ENUM_7115] = {7115, 233, 2, 160} 958 #endif /* CONFIG_BAND_6GHZ */ 959 }; 960 961 const struct chan_map channel_map_global[NUM_CHANNELS] = { 962 [CHAN_ENUM_2412] = {2412, 1, 20, 40}, 963 [CHAN_ENUM_2417] = {2417, 2, 20, 40}, 964 [CHAN_ENUM_2422] = {2422, 3, 20, 40}, 965 [CHAN_ENUM_2427] = {2427, 4, 20, 40}, 966 [CHAN_ENUM_2432] = {2432, 5, 20, 40}, 967 [CHAN_ENUM_2437] = {2437, 6, 20, 40}, 968 [CHAN_ENUM_2442] = {2442, 7, 20, 40}, 969 [CHAN_ENUM_2447] = {2447, 8, 20, 40}, 970 [CHAN_ENUM_2452] = {2452, 9, 20, 40}, 971 [CHAN_ENUM_2457] = {2457, 10, 20, 40}, 972 [CHAN_ENUM_2462] = {2462, 11, 20, 40}, 973 [CHAN_ENUM_2467] = {2467, 12, 20, 40}, 974 [CHAN_ENUM_2472] = {2472, 13, 20, 40}, 975 [CHAN_ENUM_2484] = {2484, 14, 20, 20}, 976 #ifdef CONFIG_49GHZ_CHAN 977 [CHAN_ENUM_4912] = {4912, INVALID_CHANNEL_NUM, 2, 20}, 978 [CHAN_ENUM_4915] = {4915, INVALID_CHANNEL_NUM, 2, 20}, 979 [CHAN_ENUM_4917] = {4917, INVALID_CHANNEL_NUM, 2, 20}, 980 [CHAN_ENUM_4920] = {4920, INVALID_CHANNEL_NUM, 2, 20}, 981 [CHAN_ENUM_4922] = {4922, INVALID_CHANNEL_NUM, 2, 20}, 982 [CHAN_ENUM_4925] = {4925, INVALID_CHANNEL_NUM, 2, 20}, 983 [CHAN_ENUM_4927] = {4927, INVALID_CHANNEL_NUM, 2, 20}, 984 [CHAN_ENUM_4932] = {4932, INVALID_CHANNEL_NUM, 2, 20}, 985 [CHAN_ENUM_4935] = {4935, INVALID_CHANNEL_NUM, 2, 20}, 986 [CHAN_ENUM_4937] = {4937, INVALID_CHANNEL_NUM, 2, 20}, 987 [CHAN_ENUM_4940] = {4940, INVALID_CHANNEL_NUM, 2, 20}, 988 [CHAN_ENUM_4942] = {4942, INVALID_CHANNEL_NUM, 2, 20}, 989 [CHAN_ENUM_4945] = {4945, INVALID_CHANNEL_NUM, 2, 20}, 990 [CHAN_ENUM_4947] = {4947, INVALID_CHANNEL_NUM, 2, 20}, 991 [CHAN_ENUM_4950] = {4950, INVALID_CHANNEL_NUM, 2, 20}, 992 [CHAN_ENUM_4952] = {4952, INVALID_CHANNEL_NUM, 2, 20}, 993 [CHAN_ENUM_4955] = {4955, INVALID_CHANNEL_NUM, 2, 20}, 994 [CHAN_ENUM_4957] = {4957, INVALID_CHANNEL_NUM, 2, 20}, 995 [CHAN_ENUM_4960] = {4960, INVALID_CHANNEL_NUM, 2, 20}, 996 [CHAN_ENUM_4962] = {4962, INVALID_CHANNEL_NUM, 2, 20}, 997 [CHAN_ENUM_4965] = {4965, INVALID_CHANNEL_NUM, 2, 20}, 998 [CHAN_ENUM_4967] = {4967, INVALID_CHANNEL_NUM, 2, 20}, 999 [CHAN_ENUM_4970] = {4970, INVALID_CHANNEL_NUM, 2, 20}, 1000 [CHAN_ENUM_4972] = {4972, INVALID_CHANNEL_NUM, 2, 20}, 1001 [CHAN_ENUM_4975] = {4975, INVALID_CHANNEL_NUM, 2, 20}, 1002 [CHAN_ENUM_4977] = {4977, INVALID_CHANNEL_NUM, 2, 20}, 1003 [CHAN_ENUM_4980] = {4980, INVALID_CHANNEL_NUM, 2, 20}, 1004 [CHAN_ENUM_4982] = {4982, INVALID_CHANNEL_NUM, 2, 20}, 1005 [CHAN_ENUM_4985] = {4985, INVALID_CHANNEL_NUM, 2, 20}, 1006 [CHAN_ENUM_4987] = {4987, INVALID_CHANNEL_NUM, 2, 20}, 1007 [CHAN_ENUM_5032] = {5032, INVALID_CHANNEL_NUM, 2, 20}, 1008 [CHAN_ENUM_5035] = {5035, INVALID_CHANNEL_NUM, 2, 20}, 1009 [CHAN_ENUM_5037] = {5037, INVALID_CHANNEL_NUM, 2, 20}, 1010 [CHAN_ENUM_5040] = {5040, INVALID_CHANNEL_NUM, 2, 20}, 1011 [CHAN_ENUM_5042] = {5042, INVALID_CHANNEL_NUM, 2, 20}, 1012 [CHAN_ENUM_5045] = {5045, INVALID_CHANNEL_NUM, 2, 20}, 1013 [CHAN_ENUM_5047] = {5047, INVALID_CHANNEL_NUM, 2, 20}, 1014 [CHAN_ENUM_5052] = {5052, INVALID_CHANNEL_NUM, 2, 20}, 1015 [CHAN_ENUM_5055] = {5055, INVALID_CHANNEL_NUM, 2, 20}, 1016 [CHAN_ENUM_5057] = {5057, INVALID_CHANNEL_NUM, 2, 20}, 1017 [CHAN_ENUM_5060] = {5060, INVALID_CHANNEL_NUM, 2, 20}, 1018 [CHAN_ENUM_5080] = {5080, INVALID_CHANNEL_NUM, 2, 20}, 1019 #endif /* CONFIG_49GHZ_CHAN */ 1020 [CHAN_ENUM_5180] = {5180, 36, 2, 160}, 1021 [CHAN_ENUM_5200] = {5200, 40, 2, 160}, 1022 [CHAN_ENUM_5220] = {5220, 44, 2, 160}, 1023 [CHAN_ENUM_5240] = {5240, 48, 2, 160}, 1024 [CHAN_ENUM_5260] = {5260, 52, 2, 160}, 1025 [CHAN_ENUM_5280] = {5280, 56, 2, 160}, 1026 [CHAN_ENUM_5300] = {5300, 60, 2, 160}, 1027 [CHAN_ENUM_5320] = {5320, 64, 2, 160}, 1028 [CHAN_ENUM_5500] = {5500, 100, 2, 240}, 1029 [CHAN_ENUM_5520] = {5520, 104, 2, 240}, 1030 [CHAN_ENUM_5540] = {5540, 108, 2, 240}, 1031 [CHAN_ENUM_5560] = {5560, 112, 2, 240}, 1032 [CHAN_ENUM_5580] = {5580, 116, 2, 240}, 1033 [CHAN_ENUM_5600] = {5600, 120, 2, 240}, 1034 [CHAN_ENUM_5620] = {5620, 124, 2, 240}, 1035 [CHAN_ENUM_5640] = {5640, 128, 2, 240}, 1036 [CHAN_ENUM_5660] = {5660, 132, 2, 240}, 1037 [CHAN_ENUM_5680] = {5680, 136, 2, 240}, 1038 [CHAN_ENUM_5700] = {5700, 140, 2, 240}, 1039 [CHAN_ENUM_5720] = {5720, 144, 2, 240}, 1040 [CHAN_ENUM_5745] = {5745, 149, 2, 160}, 1041 [CHAN_ENUM_5765] = {5765, 153, 2, 160}, 1042 [CHAN_ENUM_5785] = {5785, 157, 2, 160}, 1043 [CHAN_ENUM_5805] = {5805, 161, 2, 160}, 1044 [CHAN_ENUM_5825] = {5825, 165, 2, 160}, 1045 [CHAN_ENUM_5845] = {5845, 169, 2, 160}, 1046 #ifdef WLAN_FEATURE_DSRC 1047 [CHAN_ENUM_5850] = {5850, INVALID_CHANNEL_NUM, 2, 160}, 1048 [CHAN_ENUM_5855] = {5855, INVALID_CHANNEL_NUM, 2, 160}, 1049 [CHAN_ENUM_5860] = {5860, INVALID_CHANNEL_NUM, 2, 160}, 1050 #endif 1051 [CHAN_ENUM_5865] = {5865, 173, 2, 160}, 1052 #ifdef WLAN_FEATURE_DSRC 1053 [CHAN_ENUM_5870] = {5870, INVALID_CHANNEL_NUM, 2, 160}, 1054 [CHAN_ENUM_5875] = {5875, INVALID_CHANNEL_NUM, 2, 160}, 1055 [CHAN_ENUM_5880] = {5880, INVALID_CHANNEL_NUM, 2, 160}, 1056 #endif 1057 [CHAN_ENUM_5885] = {5885, INVALID_CHANNEL_NUM, 2, 160}, 1058 #ifdef WLAN_FEATURE_DSRC 1059 [CHAN_ENUM_5890] = {5890, INVALID_CHANNEL_NUM, 2, 160}, 1060 [CHAN_ENUM_5895] = {5895, INVALID_CHANNEL_NUM, 2, 160}, 1061 [CHAN_ENUM_5900] = {5900, INVALID_CHANNEL_NUM, 2, 160}, 1062 [CHAN_ENUM_5905] = {5905, INVALID_CHANNEL_NUM, 2, 160}, 1063 [CHAN_ENUM_5910] = {5910, INVALID_CHANNEL_NUM, 2, 160}, 1064 [CHAN_ENUM_5915] = {5915, INVALID_CHANNEL_NUM, 2, 160}, 1065 [CHAN_ENUM_5920] = {5920, INVALID_CHANNEL_NUM, 2, 160}, 1066 #endif /* WLAN_FEATURE_DSRC */ 1067 #ifdef CONFIG_BAND_6GHZ 1068 [CHAN_ENUM_5935] = {5935, 2, 2, 20}, 1069 [CHAN_ENUM_5955] = {5955, 1, 2, 320}, 1070 [CHAN_ENUM_5975] = {5975, 5, 2, 320}, 1071 [CHAN_ENUM_5995] = {5995, 9, 2, 320}, 1072 [CHAN_ENUM_6015] = {6015, 13, 2, 320}, 1073 [CHAN_ENUM_6035] = {6035, 17, 2, 320}, 1074 [CHAN_ENUM_6055] = {6055, 21, 2, 320}, 1075 [CHAN_ENUM_6075] = {6075, 25, 2, 320}, 1076 [CHAN_ENUM_6095] = {6095, 29, 2, 320}, 1077 [CHAN_ENUM_6115] = {6115, 33, 2, 320}, 1078 [CHAN_ENUM_6135] = {6135, 37, 2, 320}, 1079 [CHAN_ENUM_6155] = {6155, 41, 2, 320}, 1080 [CHAN_ENUM_6175] = {6175, 45, 2, 320}, 1081 [CHAN_ENUM_6195] = {6195, 49, 2, 320}, 1082 [CHAN_ENUM_6215] = {6215, 53, 2, 320}, 1083 [CHAN_ENUM_6235] = {6235, 57, 2, 320}, 1084 [CHAN_ENUM_6255] = {6255, 61, 2, 320}, 1085 [CHAN_ENUM_6275] = {6275, 65, 2, 320}, 1086 [CHAN_ENUM_6295] = {6295, 69, 2, 320}, 1087 [CHAN_ENUM_6315] = {6315, 73, 2, 320}, 1088 [CHAN_ENUM_6335] = {6335, 77, 2, 320}, 1089 [CHAN_ENUM_6355] = {6355, 81, 2, 320}, 1090 [CHAN_ENUM_6375] = {6375, 85, 2, 320}, 1091 [CHAN_ENUM_6395] = {6395, 89, 2, 320}, 1092 [CHAN_ENUM_6415] = {6415, 93, 2, 320}, 1093 [CHAN_ENUM_6435] = {6435, 97, 2, 320}, 1094 [CHAN_ENUM_6455] = {6455, 101, 2, 320}, 1095 [CHAN_ENUM_6475] = {6475, 105, 2, 320}, 1096 [CHAN_ENUM_6495] = {6495, 109, 2, 320}, 1097 [CHAN_ENUM_6515] = {6515, 113, 2, 320}, 1098 [CHAN_ENUM_6535] = {6535, 117, 2, 320}, 1099 [CHAN_ENUM_6555] = {6555, 121, 2, 320}, 1100 [CHAN_ENUM_6575] = {6575, 125, 2, 320}, 1101 [CHAN_ENUM_6595] = {6595, 129, 2, 320}, 1102 [CHAN_ENUM_6615] = {6615, 133, 2, 320}, 1103 [CHAN_ENUM_6635] = {6635, 137, 2, 320}, 1104 [CHAN_ENUM_6655] = {6655, 141, 2, 320}, 1105 [CHAN_ENUM_6675] = {6675, 145, 2, 320}, 1106 [CHAN_ENUM_6695] = {6695, 149, 2, 320}, 1107 [CHAN_ENUM_6715] = {6715, 153, 2, 320}, 1108 [CHAN_ENUM_6735] = {6735, 157, 2, 320}, 1109 [CHAN_ENUM_6755] = {6755, 161, 2, 320}, 1110 [CHAN_ENUM_6775] = {6775, 165, 2, 320}, 1111 [CHAN_ENUM_6795] = {6795, 169, 2, 320}, 1112 [CHAN_ENUM_6815] = {6815, 173, 2, 320}, 1113 [CHAN_ENUM_6835] = {6835, 177, 2, 320}, 1114 [CHAN_ENUM_6855] = {6855, 181, 2, 320}, 1115 [CHAN_ENUM_6875] = {6875, 185, 2, 320}, 1116 [CHAN_ENUM_6895] = {6895, 189, 2, 320}, 1117 [CHAN_ENUM_6915] = {6915, 193, 2, 320}, 1118 [CHAN_ENUM_6935] = {6935, 197, 2, 320}, 1119 [CHAN_ENUM_6955] = {6955, 201, 2, 320}, 1120 [CHAN_ENUM_6975] = {6975, 205, 2, 320}, 1121 [CHAN_ENUM_6995] = {6995, 209, 2, 320}, 1122 [CHAN_ENUM_7015] = {7015, 213, 2, 320}, 1123 [CHAN_ENUM_7035] = {7035, 217, 2, 320}, 1124 [CHAN_ENUM_7055] = {7055, 221, 2, 320}, 1125 [CHAN_ENUM_7075] = {7075, 225, 2, 160}, 1126 [CHAN_ENUM_7095] = {7095, 229, 2, 160}, 1127 [CHAN_ENUM_7115] = {7115, 233, 2, 160} 1128 #endif /* CONFIG_BAND_6GHZ */ 1129 }; 1130 1131 const struct chan_map channel_map_china[NUM_CHANNELS] = { 1132 [CHAN_ENUM_2412] = {2412, 1, 20, 40}, 1133 [CHAN_ENUM_2417] = {2417, 2, 20, 40}, 1134 [CHAN_ENUM_2422] = {2422, 3, 20, 40}, 1135 [CHAN_ENUM_2427] = {2427, 4, 20, 40}, 1136 [CHAN_ENUM_2432] = {2432, 5, 20, 40}, 1137 [CHAN_ENUM_2437] = {2437, 6, 20, 40}, 1138 [CHAN_ENUM_2442] = {2442, 7, 20, 40}, 1139 [CHAN_ENUM_2447] = {2447, 8, 20, 40}, 1140 [CHAN_ENUM_2452] = {2452, 9, 20, 40}, 1141 [CHAN_ENUM_2457] = {2457, 10, 20, 40}, 1142 [CHAN_ENUM_2462] = {2462, 11, 20, 40}, 1143 [CHAN_ENUM_2467] = {2467, 12, 20, 40}, 1144 [CHAN_ENUM_2472] = {2472, 13, 20, 40}, 1145 [CHAN_ENUM_2484] = {2484, 14, 20, 20}, 1146 #ifdef CONFIG_49GHZ_CHAN 1147 [CHAN_ENUM_4912] = {4912, INVALID_CHANNEL_NUM, 2, 20}, 1148 [CHAN_ENUM_4915] = {4915, INVALID_CHANNEL_NUM, 2, 20}, 1149 [CHAN_ENUM_4917] = {4917, INVALID_CHANNEL_NUM, 2, 20}, 1150 [CHAN_ENUM_4920] = {4920, INVALID_CHANNEL_NUM, 2, 20}, 1151 [CHAN_ENUM_4922] = {4922, INVALID_CHANNEL_NUM, 2, 20}, 1152 [CHAN_ENUM_4925] = {4925, INVALID_CHANNEL_NUM, 2, 20}, 1153 [CHAN_ENUM_4927] = {4927, INVALID_CHANNEL_NUM, 2, 20}, 1154 [CHAN_ENUM_4932] = {4932, INVALID_CHANNEL_NUM, 2, 20}, 1155 [CHAN_ENUM_4935] = {4935, INVALID_CHANNEL_NUM, 2, 20}, 1156 [CHAN_ENUM_4937] = {4937, INVALID_CHANNEL_NUM, 2, 20}, 1157 [CHAN_ENUM_4940] = {4940, INVALID_CHANNEL_NUM, 2, 20}, 1158 [CHAN_ENUM_4942] = {4942, INVALID_CHANNEL_NUM, 2, 20}, 1159 [CHAN_ENUM_4945] = {4945, INVALID_CHANNEL_NUM, 2, 20}, 1160 [CHAN_ENUM_4947] = {4947, INVALID_CHANNEL_NUM, 2, 20}, 1161 [CHAN_ENUM_4950] = {4950, INVALID_CHANNEL_NUM, 2, 20}, 1162 [CHAN_ENUM_4952] = {4952, INVALID_CHANNEL_NUM, 2, 20}, 1163 [CHAN_ENUM_4955] = {4955, INVALID_CHANNEL_NUM, 2, 20}, 1164 [CHAN_ENUM_4957] = {4957, INVALID_CHANNEL_NUM, 2, 20}, 1165 [CHAN_ENUM_4960] = {4960, INVALID_CHANNEL_NUM, 2, 20}, 1166 [CHAN_ENUM_4962] = {4962, INVALID_CHANNEL_NUM, 2, 20}, 1167 [CHAN_ENUM_4965] = {4965, INVALID_CHANNEL_NUM, 2, 20}, 1168 [CHAN_ENUM_4967] = {4967, INVALID_CHANNEL_NUM, 2, 20}, 1169 [CHAN_ENUM_4970] = {4970, INVALID_CHANNEL_NUM, 2, 20}, 1170 [CHAN_ENUM_4972] = {4972, INVALID_CHANNEL_NUM, 2, 20}, 1171 [CHAN_ENUM_4975] = {4975, INVALID_CHANNEL_NUM, 2, 20}, 1172 [CHAN_ENUM_4977] = {4977, INVALID_CHANNEL_NUM, 2, 20}, 1173 [CHAN_ENUM_4980] = {4980, INVALID_CHANNEL_NUM, 2, 20}, 1174 [CHAN_ENUM_4982] = {4982, INVALID_CHANNEL_NUM, 2, 20}, 1175 [CHAN_ENUM_4985] = {4985, INVALID_CHANNEL_NUM, 2, 20}, 1176 [CHAN_ENUM_4987] = {4987, INVALID_CHANNEL_NUM, 2, 20}, 1177 [CHAN_ENUM_5032] = {5032, INVALID_CHANNEL_NUM, 2, 20}, 1178 [CHAN_ENUM_5035] = {5035, INVALID_CHANNEL_NUM, 2, 20}, 1179 [CHAN_ENUM_5037] = {5037, INVALID_CHANNEL_NUM, 2, 20}, 1180 [CHAN_ENUM_5040] = {5040, INVALID_CHANNEL_NUM, 2, 20}, 1181 [CHAN_ENUM_5042] = {5042, INVALID_CHANNEL_NUM, 2, 20}, 1182 [CHAN_ENUM_5045] = {5045, INVALID_CHANNEL_NUM, 2, 20}, 1183 [CHAN_ENUM_5047] = {5047, INVALID_CHANNEL_NUM, 2, 20}, 1184 [CHAN_ENUM_5052] = {5052, INVALID_CHANNEL_NUM, 2, 20}, 1185 [CHAN_ENUM_5055] = {5055, INVALID_CHANNEL_NUM, 2, 20}, 1186 [CHAN_ENUM_5057] = {5057, INVALID_CHANNEL_NUM, 2, 20}, 1187 [CHAN_ENUM_5060] = {5060, INVALID_CHANNEL_NUM, 2, 20}, 1188 [CHAN_ENUM_5080] = {5080, INVALID_CHANNEL_NUM, 2, 20}, 1189 #endif /* CONFIG_49GHZ_CHAN */ 1190 [CHAN_ENUM_5180] = {5180, 36, 2, 160}, 1191 [CHAN_ENUM_5200] = {5200, 40, 2, 160}, 1192 [CHAN_ENUM_5220] = {5220, 44, 2, 160}, 1193 [CHAN_ENUM_5240] = {5240, 48, 2, 160}, 1194 [CHAN_ENUM_5260] = {5260, 52, 2, 160}, 1195 [CHAN_ENUM_5280] = {5280, 56, 2, 160}, 1196 [CHAN_ENUM_5300] = {5300, 60, 2, 160}, 1197 [CHAN_ENUM_5320] = {5320, 64, 2, 160}, 1198 [CHAN_ENUM_5500] = {5500, 100, 2, 240}, 1199 [CHAN_ENUM_5520] = {5520, 104, 2, 240}, 1200 [CHAN_ENUM_5540] = {5540, 108, 2, 240}, 1201 [CHAN_ENUM_5560] = {5560, 112, 2, 240}, 1202 [CHAN_ENUM_5580] = {5580, 116, 2, 240}, 1203 [CHAN_ENUM_5600] = {5600, 120, 2, 240}, 1204 [CHAN_ENUM_5620] = {5620, 124, 2, 240}, 1205 [CHAN_ENUM_5640] = {5640, 128, 2, 240}, 1206 [CHAN_ENUM_5660] = {5660, 132, 2, 240}, 1207 [CHAN_ENUM_5680] = {5680, 136, 2, 240}, 1208 [CHAN_ENUM_5700] = {5700, 140, 2, 240}, 1209 [CHAN_ENUM_5720] = {5720, 144, 2, 240}, 1210 [CHAN_ENUM_5745] = {5745, 149, 2, 160}, 1211 [CHAN_ENUM_5765] = {5765, 153, 2, 160}, 1212 [CHAN_ENUM_5785] = {5785, 157, 2, 160}, 1213 [CHAN_ENUM_5805] = {5805, 161, 2, 160}, 1214 [CHAN_ENUM_5825] = {5825, 165, 2, 160}, 1215 [CHAN_ENUM_5845] = {5845, 169, 2, 160}, 1216 #ifdef WLAN_FEATURE_DSRC 1217 [CHAN_ENUM_5850] = {5850, INVALID_CHANNEL_NUM, 2, 160}, 1218 [CHAN_ENUM_5855] = {5855, INVALID_CHANNEL_NUM, 2, 160}, 1219 [CHAN_ENUM_5860] = {5860, INVALID_CHANNEL_NUM, 2, 160}, 1220 #endif 1221 [CHAN_ENUM_5865] = {5865, INVALID_CHANNEL_NUM, 2, 160}, 1222 #ifdef WLAN_FEATURE_DSRC 1223 [CHAN_ENUM_5870] = {5870, INVALID_CHANNEL_NUM, 2, 160}, 1224 [CHAN_ENUM_5875] = {5875, INVALID_CHANNEL_NUM, 2, 160}, 1225 [CHAN_ENUM_5880] = {5880, INVALID_CHANNEL_NUM, 2, 160}, 1226 #endif 1227 [CHAN_ENUM_5885] = {5885, INVALID_CHANNEL_NUM, 2, 160}, 1228 #ifdef WLAN_FEATURE_DSRC 1229 [CHAN_ENUM_5890] = {5890, INVALID_CHANNEL_NUM, 2, 160}, 1230 [CHAN_ENUM_5895] = {5895, INVALID_CHANNEL_NUM, 2, 160}, 1231 [CHAN_ENUM_5900] = {5900, INVALID_CHANNEL_NUM, 2, 160}, 1232 [CHAN_ENUM_5905] = {5905, INVALID_CHANNEL_NUM, 2, 160}, 1233 [CHAN_ENUM_5910] = {5910, INVALID_CHANNEL_NUM, 2, 160}, 1234 [CHAN_ENUM_5915] = {5915, INVALID_CHANNEL_NUM, 2, 160}, 1235 [CHAN_ENUM_5920] = {5920, INVALID_CHANNEL_NUM, 2, 160}, 1236 #endif /* WLAN_FEATURE_DSRC */ 1237 #ifdef CONFIG_BAND_6GHZ 1238 [CHAN_ENUM_5935] = {5935, 2, 2, 20}, 1239 [CHAN_ENUM_5955] = {5955, 1, 2, 320}, 1240 [CHAN_ENUM_5975] = {5975, 5, 2, 320}, 1241 [CHAN_ENUM_5995] = {5995, 9, 2, 320}, 1242 [CHAN_ENUM_6015] = {6015, 13, 2, 320}, 1243 [CHAN_ENUM_6035] = {6035, 17, 2, 320}, 1244 [CHAN_ENUM_6055] = {6055, 21, 2, 320}, 1245 [CHAN_ENUM_6075] = {6075, 25, 2, 320}, 1246 [CHAN_ENUM_6095] = {6095, 29, 2, 320}, 1247 [CHAN_ENUM_6115] = {6115, 33, 2, 320}, 1248 [CHAN_ENUM_6135] = {6135, 37, 2, 320}, 1249 [CHAN_ENUM_6155] = {6155, 41, 2, 320}, 1250 [CHAN_ENUM_6175] = {6175, 45, 2, 320}, 1251 [CHAN_ENUM_6195] = {6195, 49, 2, 320}, 1252 [CHAN_ENUM_6215] = {6215, 53, 2, 320}, 1253 [CHAN_ENUM_6235] = {6235, 57, 2, 320}, 1254 [CHAN_ENUM_6255] = {6255, 61, 2, 320}, 1255 [CHAN_ENUM_6275] = {6275, 65, 2, 320}, 1256 [CHAN_ENUM_6295] = {6295, 69, 2, 320}, 1257 [CHAN_ENUM_6315] = {6315, 73, 2, 320}, 1258 [CHAN_ENUM_6335] = {6335, 77, 2, 320}, 1259 [CHAN_ENUM_6355] = {6355, 81, 2, 320}, 1260 [CHAN_ENUM_6375] = {6375, 85, 2, 320}, 1261 [CHAN_ENUM_6395] = {6395, 89, 2, 320}, 1262 [CHAN_ENUM_6415] = {6415, 93, 2, 320}, 1263 [CHAN_ENUM_6435] = {6435, 97, 2, 320}, 1264 [CHAN_ENUM_6455] = {6455, 101, 2, 320}, 1265 [CHAN_ENUM_6475] = {6475, 105, 2, 320}, 1266 [CHAN_ENUM_6495] = {6495, 109, 2, 320}, 1267 [CHAN_ENUM_6515] = {6515, 113, 2, 320}, 1268 [CHAN_ENUM_6535] = {6535, 117, 2, 320}, 1269 [CHAN_ENUM_6555] = {6555, 121, 2, 320}, 1270 [CHAN_ENUM_6575] = {6575, 125, 2, 320}, 1271 [CHAN_ENUM_6595] = {6595, 129, 2, 320}, 1272 [CHAN_ENUM_6615] = {6615, 133, 2, 320}, 1273 [CHAN_ENUM_6635] = {6635, 137, 2, 320}, 1274 [CHAN_ENUM_6655] = {6655, 141, 2, 320}, 1275 [CHAN_ENUM_6675] = {6675, 145, 2, 320}, 1276 [CHAN_ENUM_6695] = {6695, 149, 2, 320}, 1277 [CHAN_ENUM_6715] = {6715, 153, 2, 320}, 1278 [CHAN_ENUM_6735] = {6735, 157, 2, 320}, 1279 [CHAN_ENUM_6755] = {6755, 161, 2, 320}, 1280 [CHAN_ENUM_6775] = {6775, 165, 2, 320}, 1281 [CHAN_ENUM_6795] = {6795, 169, 2, 320}, 1282 [CHAN_ENUM_6815] = {6815, 173, 2, 320}, 1283 [CHAN_ENUM_6835] = {6835, 177, 2, 320}, 1284 [CHAN_ENUM_6855] = {6855, 181, 2, 320}, 1285 [CHAN_ENUM_6875] = {6875, 185, 2, 320}, 1286 [CHAN_ENUM_6895] = {6895, 189, 2, 320}, 1287 [CHAN_ENUM_6915] = {6915, 193, 2, 320}, 1288 [CHAN_ENUM_6935] = {6935, 197, 2, 320}, 1289 [CHAN_ENUM_6955] = {6955, 201, 2, 320}, 1290 [CHAN_ENUM_6975] = {6975, 205, 2, 320}, 1291 [CHAN_ENUM_6995] = {6995, 209, 2, 320}, 1292 [CHAN_ENUM_7015] = {7015, 213, 2, 320}, 1293 [CHAN_ENUM_7035] = {7035, 217, 2, 320}, 1294 [CHAN_ENUM_7055] = {7055, 221, 2, 320}, 1295 [CHAN_ENUM_7075] = {7075, 225, 2, 160}, 1296 [CHAN_ENUM_7095] = {7095, 229, 2, 160}, 1297 [CHAN_ENUM_7115] = {7115, 233, 2, 160} 1298 #endif /* CONFIG_BAND_6GHZ */ 1299 }; 1300 1301 static uint8_t reg_calculate_max_5gh_enum(void) 1302 { 1303 int16_t idx; 1304 uint8_t max_valid_ieee_chan = INVALID_CHANNEL_NUM; 1305 1306 for (idx = MAX_5GHZ_CHANNEL; idx >= 0; idx--) { 1307 if (channel_map[idx].chan_num != INVALID_CHANNEL_NUM) { 1308 max_valid_ieee_chan = channel_map[idx].chan_num; 1309 break; 1310 } 1311 } 1312 1313 return max_valid_ieee_chan; 1314 } 1315 1316 void reg_init_channel_map(enum dfs_reg dfs_region) 1317 { 1318 switch (dfs_region) { 1319 case DFS_UNINIT_REGION: 1320 case DFS_UNDEF_REGION: 1321 channel_map = channel_map_global; 1322 break; 1323 case DFS_FCC_REGION: 1324 channel_map = channel_map_us; 1325 break; 1326 case DFS_ETSI_REGION: 1327 channel_map = channel_map_eu; 1328 break; 1329 case DFS_MKK_REGION: 1330 case DFS_MKKN_REGION: 1331 channel_map = channel_map_jp; 1332 break; 1333 case DFS_CN_REGION: 1334 channel_map = channel_map_china; 1335 break; 1336 case DFS_KR_REGION: 1337 channel_map = channel_map_global; 1338 break; 1339 } 1340 1341 g_reg_max_5g_chan_num = reg_calculate_max_5gh_enum(); 1342 } 1343 1344 #ifdef WLAN_FEATURE_11BE 1345 uint16_t reg_get_bw_value(enum phy_ch_width bw) 1346 { 1347 switch (bw) { 1348 case CH_WIDTH_20MHZ: 1349 return 20; 1350 case CH_WIDTH_40MHZ: 1351 return 40; 1352 case CH_WIDTH_80MHZ: 1353 return 80; 1354 case CH_WIDTH_160MHZ: 1355 return 160; 1356 case CH_WIDTH_80P80MHZ: 1357 return 160; 1358 case CH_WIDTH_INVALID: 1359 return 0; 1360 case CH_WIDTH_5MHZ: 1361 return 5; 1362 case CH_WIDTH_10MHZ: 1363 return 10; 1364 case CH_WIDTH_320MHZ: 1365 case CH_WIDTH_MAX: 1366 return 320; 1367 default: 1368 return 0; 1369 } 1370 } 1371 #else 1372 uint16_t reg_get_bw_value(enum phy_ch_width bw) 1373 { 1374 switch (bw) { 1375 case CH_WIDTH_20MHZ: 1376 return 20; 1377 case CH_WIDTH_40MHZ: 1378 return 40; 1379 case CH_WIDTH_80MHZ: 1380 return 80; 1381 case CH_WIDTH_160MHZ: 1382 return 160; 1383 case CH_WIDTH_80P80MHZ: 1384 return 160; 1385 case CH_WIDTH_INVALID: 1386 return 0; 1387 case CH_WIDTH_5MHZ: 1388 return 5; 1389 case CH_WIDTH_10MHZ: 1390 return 10; 1391 case CH_WIDTH_MAX: 1392 return 160; 1393 default: 1394 return 0; 1395 } 1396 } 1397 #endif 1398 1399 struct wlan_lmac_if_reg_tx_ops *reg_get_psoc_tx_ops( 1400 struct wlan_objmgr_psoc *psoc) 1401 { 1402 struct wlan_lmac_if_tx_ops *tx_ops; 1403 1404 tx_ops = wlan_psoc_get_lmac_if_txops(psoc); 1405 if (!tx_ops) { 1406 reg_err("tx_ops is NULL"); 1407 return NULL; 1408 } 1409 1410 return &tx_ops->reg_ops; 1411 } 1412 1413 /** 1414 * reg_combine_channel_states() - Get minimum of channel state1 and state2 1415 * @chan_state1: Channel state1 1416 * @chan_state2: Channel state2 1417 * 1418 * Return: Channel state 1419 */ 1420 enum channel_state reg_combine_channel_states(enum channel_state chan_state1, 1421 enum channel_state chan_state2) 1422 { 1423 if ((chan_state1 == CHANNEL_STATE_INVALID) || 1424 (chan_state2 == CHANNEL_STATE_INVALID)) 1425 return CHANNEL_STATE_INVALID; 1426 else 1427 return min(chan_state1, chan_state2); 1428 } 1429 1430 QDF_STATUS reg_read_default_country(struct wlan_objmgr_psoc *psoc, 1431 uint8_t *country_code) 1432 { 1433 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 1434 1435 if (!country_code) { 1436 reg_err("country_code is NULL"); 1437 return QDF_STATUS_E_INVAL; 1438 } 1439 1440 psoc_priv_obj = reg_get_psoc_obj(psoc); 1441 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 1442 reg_err("psoc reg component is NULL"); 1443 return QDF_STATUS_E_INVAL; 1444 } 1445 1446 qdf_mem_copy(country_code, psoc_priv_obj->def_country, 1447 REG_ALPHA2_LEN + 1); 1448 1449 return QDF_STATUS_SUCCESS; 1450 } 1451 1452 #ifdef WLAN_REG_PARTIAL_OFFLOAD 1453 QDF_STATUS reg_get_max_5g_bw_from_country_code(struct wlan_objmgr_pdev *pdev, 1454 uint16_t cc, 1455 uint16_t *max_bw_5g) 1456 { 1457 uint16_t i; 1458 int num_countries; 1459 1460 *max_bw_5g = 0; 1461 reg_get_num_countries(&num_countries); 1462 1463 for (i = 0; i < num_countries; i++) { 1464 if (g_all_countries[i].country_code == cc) 1465 break; 1466 } 1467 1468 if (i == num_countries) 1469 return QDF_STATUS_E_FAILURE; 1470 1471 *max_bw_5g = g_all_countries[i].max_bw_5g; 1472 1473 return QDF_STATUS_SUCCESS; 1474 } 1475 1476 QDF_STATUS reg_get_max_5g_bw_from_regdomain(struct wlan_objmgr_pdev *pdev, 1477 uint16_t regdmn, 1478 uint16_t *max_bw_5g) 1479 { 1480 uint16_t i; 1481 int num_reg_dmn; 1482 1483 *max_bw_5g = 0; 1484 reg_get_num_reg_dmn_pairs(&num_reg_dmn); 1485 1486 for (i = 0; i < num_reg_dmn; i++) { 1487 if (g_reg_dmn_pairs[i].reg_dmn_pair_id == regdmn) 1488 break; 1489 } 1490 1491 if (i == num_reg_dmn) 1492 return QDF_STATUS_E_FAILURE; 1493 1494 *max_bw_5g = regdomains_5g[g_reg_dmn_pairs[i].dmn_id_5g].max_bw; 1495 1496 return QDF_STATUS_SUCCESS; 1497 } 1498 #else 1499 1500 QDF_STATUS reg_get_max_5g_bw_from_country_code(struct wlan_objmgr_pdev *pdev, 1501 uint16_t cc, 1502 uint16_t *max_bw_5g) 1503 { 1504 *max_bw_5g = reg_get_max_bw_5G_for_fo(pdev); 1505 1506 return QDF_STATUS_SUCCESS; 1507 } 1508 1509 QDF_STATUS reg_get_max_5g_bw_from_regdomain(struct wlan_objmgr_pdev *pdev, 1510 uint16_t regdmn, 1511 uint16_t *max_bw_5g) 1512 { 1513 *max_bw_5g = reg_get_max_bw_5G_for_fo(pdev); 1514 1515 return QDF_STATUS_SUCCESS; 1516 } 1517 #endif 1518 1519 uint16_t reg_get_max_bw_5G_for_fo(struct wlan_objmgr_pdev *pdev) 1520 { 1521 struct wlan_objmgr_psoc *psoc = wlan_pdev_get_psoc(pdev); 1522 struct wlan_regulatory_psoc_priv_obj *soc_reg; 1523 uint8_t pdev_id; 1524 uint8_t phy_id; 1525 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 1526 1527 soc_reg = reg_get_psoc_obj(psoc); 1528 if (!soc_reg) { 1529 reg_err("soc_reg is NULL"); 1530 return 0; 1531 } 1532 1533 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 1534 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 1535 if (reg_tx_ops->get_phy_id_from_pdev_id) 1536 reg_tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id); 1537 else 1538 phy_id = pdev_id; 1539 1540 return soc_reg->mas_chan_params[phy_id].max_bw_5g; 1541 } 1542 1543 void reg_get_current_dfs_region(struct wlan_objmgr_pdev *pdev, 1544 enum dfs_reg *dfs_reg) 1545 { 1546 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 1547 1548 pdev_priv_obj = reg_get_pdev_obj(pdev); 1549 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 1550 reg_err("reg component pdev priv is NULL"); 1551 return; 1552 } 1553 1554 *dfs_reg = pdev_priv_obj->dfs_region; 1555 } 1556 1557 void reg_set_dfs_region(struct wlan_objmgr_pdev *pdev, 1558 enum dfs_reg dfs_reg) 1559 { 1560 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 1561 1562 pdev_priv_obj = reg_get_pdev_obj(pdev); 1563 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 1564 reg_err("psoc reg component is NULL"); 1565 return; 1566 } 1567 1568 pdev_priv_obj->dfs_region = dfs_reg; 1569 1570 reg_init_channel_map(dfs_reg); 1571 } 1572 1573 static uint8_t reg_freq_to_chan_direct(qdf_freq_t freq) 1574 { 1575 if (freq >= TWOG_CHAN_1_IN_MHZ && freq <= TWOG_CHAN_13_IN_MHZ) 1576 return IEEE_2GHZ_CH1 + 1577 (freq - TWOG_CHAN_1_IN_MHZ) / IEEE_CH_SEP; 1578 1579 if (freq == TWOG_CHAN_14_IN_MHZ) 1580 return IEEE_2GHZ_CH14; 1581 1582 if (freq >= FIVEG_CHAN_36_IN_MHZ && freq <= FIVEG_CHAN_177_IN_MHZ) 1583 return IEEE_5GHZ_CH36 + 1584 (freq - FIVEG_CHAN_36_IN_MHZ) / IEEE_CH_SEP; 1585 1586 if (freq == SIXG_CHAN_2_IN_MHZ) 1587 return IEEE_6GHZ_CH2; 1588 1589 if (freq >= SIXG_CHAN_1_IN_MHZ && freq <= SIXG_CHAN_233_IN_MHZ) 1590 return IEEE_6GHZ_CH1 + 1591 (freq - SIXG_CHAN_1_IN_MHZ) / IEEE_CH_SEP; 1592 1593 return 0; 1594 } 1595 1596 static uint8_t 1597 reg_freq_to_chan_for_chlist(struct regulatory_channel *chan_list, 1598 qdf_freq_t freq, 1599 enum channel_enum num_chans) 1600 { 1601 uint32_t count; 1602 uint8_t chan_ieee; 1603 1604 if (num_chans > NUM_CHANNELS) { 1605 reg_err_rl("invalid num_chans"); 1606 return 0; 1607 } 1608 1609 chan_ieee = reg_freq_to_chan_direct(freq); 1610 if (chan_ieee) 1611 return chan_ieee; 1612 1613 for (count = 0; count < num_chans; count++) { 1614 if (chan_list[count].center_freq >= freq) 1615 break; 1616 } 1617 1618 if (count == num_chans) 1619 goto end; 1620 1621 if (chan_list[count].center_freq == freq) 1622 return chan_list[count].chan_num; 1623 1624 if (count == 0) 1625 goto end; 1626 1627 if ((chan_list[count - 1].chan_num == INVALID_CHANNEL_NUM) || 1628 (chan_list[count].chan_num == INVALID_CHANNEL_NUM)) { 1629 reg_err("Frequency %d invalid in current reg domain", freq); 1630 return 0; 1631 } 1632 1633 return (chan_list[count - 1].chan_num + 1634 (freq - chan_list[count - 1].center_freq) / 5); 1635 1636 end: 1637 reg_err_rl("invalid frequency %d", freq); 1638 return 0; 1639 } 1640 1641 uint8_t reg_freq_to_chan(struct wlan_objmgr_pdev *pdev, 1642 qdf_freq_t freq) 1643 { 1644 struct regulatory_channel *chan_list; 1645 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 1646 uint8_t chan; 1647 enum supported_6g_pwr_types input_6g_pwr_mode = REG_AP_LPI; 1648 1649 if (freq == 0) { 1650 reg_debug_rl("Invalid freq %d", freq); 1651 return 0; 1652 } 1653 1654 pdev_priv_obj = reg_get_pdev_obj(pdev); 1655 1656 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 1657 reg_err("reg pdev priv obj is NULL"); 1658 return 0; 1659 } 1660 1661 chan_list = pdev_priv_obj->mas_chan_list; 1662 chan = reg_freq_to_chan_for_chlist(chan_list, freq, NUM_CHANNELS); 1663 1664 if (chan) 1665 return chan; 1666 1667 if (!REG_IS_6GHZ_FREQ(freq)) 1668 return chan; 1669 1670 input_6g_pwr_mode = REG_AP_LPI; 1671 1672 while (input_6g_pwr_mode < REG_INVALID_PWR_MODE) { 1673 chan_list = reg_get_reg_maschan_lst_frm_6g_pwr_mode( 1674 input_6g_pwr_mode, 1675 pdev_priv_obj, 0); 1676 if (!chan_list) 1677 return 0; 1678 1679 chan = reg_freq_to_chan_for_chlist(chan_list, freq, 1680 NUM_6GHZ_CHANNELS); 1681 if (chan) 1682 break; 1683 input_6g_pwr_mode++; 1684 } 1685 1686 return chan; 1687 } 1688 1689 static uint16_t 1690 reg_compute_chan_to_freq_for_chlist(struct regulatory_channel *chan_list, 1691 uint8_t chan_num, 1692 enum channel_enum min_chan_range, 1693 enum channel_enum max_chan_range) 1694 { 1695 uint16_t count; 1696 1697 if (reg_is_chan_enum_invalid(min_chan_range) || 1698 reg_is_chan_enum_invalid(max_chan_range)) { 1699 reg_debug_rl("Invalid channel range: min_chan_range: 0x%X max_chan_range: 0x%X", 1700 min_chan_range, 1701 max_chan_range); 1702 return 0; 1703 } 1704 1705 for (count = min_chan_range; count <= max_chan_range; count++) { 1706 if ((chan_list[count].state != CHANNEL_STATE_DISABLE) && 1707 !(chan_list[count].chan_flags & REGULATORY_CHAN_DISABLED)) { 1708 if (REG_IS_49GHZ_FREQ(chan_list[count].center_freq)) { 1709 if (chan_list[count].chan_num == chan_num) 1710 break; 1711 continue; 1712 } else if ((chan_list[count].chan_num >= chan_num) && 1713 (chan_list[count].chan_num != 1714 INVALID_CHANNEL_NUM)) 1715 break; 1716 } 1717 } 1718 1719 if (count == max_chan_range + 1) 1720 goto end; 1721 1722 if (chan_list[count].chan_num == chan_num) { 1723 if (chan_list[count].chan_flags & REGULATORY_CHAN_DISABLED) 1724 reg_err("Channel %d disabled in current reg domain", 1725 chan_num); 1726 return chan_list[count].center_freq; 1727 } 1728 1729 if (count == min_chan_range) 1730 goto end; 1731 1732 if ((chan_list[count - 1].chan_num == INVALID_CHANNEL_NUM) || 1733 REG_IS_49GHZ_FREQ(chan_list[count - 1].center_freq) || 1734 (chan_list[count].chan_num == INVALID_CHANNEL_NUM)) { 1735 reg_err("Channel %d invalid in current reg domain", 1736 chan_num); 1737 return 0; 1738 } 1739 1740 return (chan_list[count - 1].center_freq + 1741 (chan_num - chan_list[count - 1].chan_num) * 5); 1742 1743 end: 1744 1745 reg_debug_rl("Invalid channel %d", chan_num); 1746 return 0; 1747 } 1748 1749 static uint16_t reg_compute_chan_to_freq(struct wlan_objmgr_pdev *pdev, 1750 uint8_t chan_num, 1751 enum channel_enum min_chan_range, 1752 enum channel_enum max_chan_range) 1753 { 1754 struct regulatory_channel *chan_list; 1755 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 1756 uint16_t freq; 1757 enum supported_6g_pwr_types input_6g_pwr_mode; 1758 1759 pdev_priv_obj = reg_get_pdev_obj(pdev); 1760 1761 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 1762 reg_err("reg pdev priv obj is NULL"); 1763 return 0; 1764 } 1765 1766 if (min_chan_range < MIN_CHANNEL || max_chan_range > MAX_CHANNEL) { 1767 reg_err_rl("Channel range is invalid"); 1768 return 0; 1769 } 1770 1771 chan_list = pdev_priv_obj->mas_chan_list; 1772 1773 freq = reg_compute_chan_to_freq_for_chlist(chan_list, chan_num, 1774 min_chan_range, 1775 max_chan_range); 1776 1777 /* If the frequency is a 2G or 5G frequency, then it should be found 1778 * in the regulatory mas_chan_list. 1779 * If a valid 6G frequency has been returned with the current power mode 1780 * itself, then return the freq computed. 1781 */ 1782 if (freq) 1783 return freq; 1784 1785 min_chan_range = reg_convert_enum_to_6g_idx(min_chan_range); 1786 max_chan_range = reg_convert_enum_to_6g_idx(max_chan_range); 1787 if (reg_is_chan_enum_invalid(min_chan_range) || 1788 reg_is_chan_enum_invalid(max_chan_range)) 1789 return freq; 1790 1791 /* If a valid 6G frequency has not been found, then search in a 1792 * power mode's master channel list. 1793 */ 1794 input_6g_pwr_mode = REG_AP_LPI; 1795 while (input_6g_pwr_mode <= REG_CLI_SUB_VLP) { 1796 chan_list = reg_get_reg_maschan_lst_frm_6g_pwr_mode( 1797 input_6g_pwr_mode, 1798 pdev_priv_obj, 0); 1799 if (!chan_list) 1800 return 0; 1801 1802 freq = reg_compute_chan_to_freq_for_chlist(chan_list, chan_num, 1803 min_chan_range, 1804 max_chan_range); 1805 if (freq) 1806 break; 1807 input_6g_pwr_mode++; 1808 } 1809 1810 return freq; 1811 } 1812 1813 uint16_t reg_legacy_chan_to_freq(struct wlan_objmgr_pdev *pdev, 1814 uint8_t chan_num) 1815 { 1816 uint16_t min_chan_range = MIN_24GHZ_CHANNEL; 1817 uint16_t max_chan_range = MAX_5GHZ_CHANNEL; 1818 1819 if (chan_num == 0) { 1820 reg_debug_rl("Invalid channel %d", chan_num); 1821 return 0; 1822 } 1823 1824 return reg_compute_chan_to_freq(pdev, chan_num, 1825 min_chan_range, 1826 max_chan_range); 1827 } 1828 1829 #ifdef WLAN_REG_PARTIAL_OFFLOAD 1830 QDF_STATUS reg_program_default_cc(struct wlan_objmgr_pdev *pdev, 1831 uint16_t regdmn) 1832 { 1833 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 1834 struct cur_regulatory_info *reg_info; 1835 uint16_t cc = -1; 1836 uint16_t country_index = -1, regdmn_pair = -1; 1837 struct wlan_objmgr_psoc *psoc; 1838 QDF_STATUS err; 1839 1840 pdev_priv_obj = reg_get_pdev_obj(pdev); 1841 if (!pdev_priv_obj) { 1842 reg_err("reg soc is NULL"); 1843 return QDF_STATUS_E_FAILURE; 1844 } 1845 1846 reg_info = (struct cur_regulatory_info *)qdf_mem_malloc 1847 (sizeof(struct cur_regulatory_info)); 1848 if (!reg_info) 1849 return QDF_STATUS_E_NOMEM; 1850 1851 psoc = wlan_pdev_get_psoc(pdev); 1852 if (!psoc) { 1853 reg_err("psoc is NULL"); 1854 return QDF_STATUS_E_INVAL; 1855 } 1856 1857 reg_info->psoc = psoc; 1858 reg_info->phy_id = wlan_objmgr_pdev_get_pdev_id(pdev); 1859 reg_info->num_phy = 1; 1860 1861 if (regdmn == 0) { 1862 reg_get_default_country(®dmn); 1863 regdmn |= COUNTRY_ERD_FLAG; 1864 } 1865 1866 if (regdmn & COUNTRY_ERD_FLAG) { 1867 cc = regdmn & ~COUNTRY_ERD_FLAG; 1868 1869 reg_get_rdpair_from_country_code(cc, 1870 &country_index, 1871 ®dmn_pair); 1872 1873 err = reg_get_cur_reginfo(reg_info, country_index, regdmn_pair); 1874 if (err == QDF_STATUS_E_FAILURE) { 1875 reg_err("Unable to set country code\n"); 1876 qdf_mem_free(reg_info->reg_rules_2g_ptr); 1877 qdf_mem_free(reg_info->reg_rules_5g_ptr); 1878 qdf_mem_free(reg_info); 1879 return QDF_STATUS_E_FAILURE; 1880 } 1881 1882 pdev_priv_obj->ctry_code = cc; 1883 1884 } else { 1885 err = reg_get_rdpair_from_regdmn_id(regdmn, ®dmn_pair); 1886 if (err == QDF_STATUS_E_FAILURE) { 1887 reg_err("Failed to get regdmn idx for regdmn pair: %x", 1888 regdmn); 1889 qdf_mem_free(reg_info->reg_rules_2g_ptr); 1890 qdf_mem_free(reg_info->reg_rules_5g_ptr); 1891 qdf_mem_free(reg_info); 1892 return QDF_STATUS_E_FAILURE; 1893 } 1894 1895 err = reg_get_cur_reginfo(reg_info, country_index, regdmn_pair); 1896 if (err == QDF_STATUS_E_FAILURE) { 1897 reg_err("Unable to set country code\n"); 1898 qdf_mem_free(reg_info->reg_rules_2g_ptr); 1899 qdf_mem_free(reg_info->reg_rules_5g_ptr); 1900 qdf_mem_free(reg_info); 1901 return QDF_STATUS_E_FAILURE; 1902 } 1903 1904 pdev_priv_obj->reg_dmn_pair = regdmn; 1905 } 1906 1907 reg_info->offload_enabled = false; 1908 reg_process_master_chan_list(reg_info); 1909 1910 qdf_mem_free(reg_info->reg_rules_2g_ptr); 1911 qdf_mem_free(reg_info->reg_rules_5g_ptr); 1912 qdf_mem_free(reg_info); 1913 1914 return QDF_STATUS_SUCCESS; 1915 } 1916 1917 /** 1918 * reg_program_chan_list_po() - API to program channel list in Partial Offload 1919 * @psoc: Pointer to psoc object manager 1920 * @pdev: Pointer to pdev object 1921 * @rd: Pointer to cc_regdmn_s structure 1922 * 1923 * Return: QDF_STATUS 1924 */ 1925 static QDF_STATUS reg_program_chan_list_po(struct wlan_objmgr_psoc *psoc, 1926 struct wlan_objmgr_pdev *pdev, 1927 struct cc_regdmn_s *rd) 1928 { 1929 struct cur_regulatory_info *reg_info; 1930 uint16_t country_index = -1, regdmn_pair = -1; 1931 QDF_STATUS err; 1932 1933 reg_info = (struct cur_regulatory_info *)qdf_mem_malloc 1934 (sizeof(struct cur_regulatory_info)); 1935 if (!reg_info) 1936 return QDF_STATUS_E_NOMEM; 1937 1938 reg_info->psoc = psoc; 1939 reg_info->phy_id = wlan_objmgr_pdev_get_pdev_id(pdev); 1940 1941 if (rd->flags == CC_IS_SET) { 1942 reg_get_rdpair_from_country_code(rd->cc.country_code, 1943 &country_index, 1944 ®dmn_pair); 1945 } else if (rd->flags == ALPHA_IS_SET) { 1946 reg_get_rdpair_from_country_iso(rd->cc.alpha, 1947 &country_index, 1948 ®dmn_pair); 1949 } else if (rd->flags == REGDMN_IS_SET) { 1950 err = reg_get_rdpair_from_regdmn_id( 1951 rd->cc.regdmn.reg_2g_5g_pair_id, 1952 ®dmn_pair); 1953 if (err == QDF_STATUS_E_FAILURE) { 1954 reg_err("Failed to get regdmn idx for regdmn pair: %x", 1955 rd->cc.regdmn.reg_2g_5g_pair_id); 1956 qdf_mem_free(reg_info->reg_rules_2g_ptr); 1957 qdf_mem_free(reg_info->reg_rules_5g_ptr); 1958 qdf_mem_free(reg_info); 1959 return QDF_STATUS_E_FAILURE; 1960 } 1961 } 1962 1963 err = reg_get_cur_reginfo(reg_info, country_index, regdmn_pair); 1964 if (err == QDF_STATUS_E_FAILURE) { 1965 reg_err("Unable to set country code\n"); 1966 qdf_mem_free(reg_info->reg_rules_2g_ptr); 1967 qdf_mem_free(reg_info->reg_rules_5g_ptr); 1968 qdf_mem_free(reg_info); 1969 return QDF_STATUS_E_FAILURE; 1970 } 1971 1972 reg_info->offload_enabled = false; 1973 reg_process_master_chan_list(reg_info); 1974 1975 qdf_mem_free(reg_info->reg_rules_2g_ptr); 1976 qdf_mem_free(reg_info->reg_rules_5g_ptr); 1977 qdf_mem_free(reg_info); 1978 1979 return QDF_STATUS_SUCCESS; 1980 } 1981 #else 1982 static QDF_STATUS reg_program_chan_list_po(struct wlan_objmgr_psoc *psoc, 1983 struct wlan_objmgr_pdev *pdev, 1984 struct cc_regdmn_s *rd) 1985 { 1986 return QDF_STATUS_SUCCESS; 1987 } 1988 #endif /* WLAN_REG_PARTIAL_OFFLOAD */ 1989 1990 QDF_STATUS reg_program_chan_list(struct wlan_objmgr_pdev *pdev, 1991 struct cc_regdmn_s *rd) 1992 { 1993 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 1994 struct wlan_objmgr_psoc *psoc; 1995 struct wlan_lmac_if_reg_tx_ops *tx_ops; 1996 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 1997 uint8_t pdev_id; 1998 uint8_t phy_id; 1999 2000 pdev_priv_obj = reg_get_pdev_obj(pdev); 2001 if (!pdev_priv_obj) { 2002 reg_err(" pdev priv obj is NULL"); 2003 return QDF_STATUS_E_FAILURE; 2004 } 2005 2006 psoc = wlan_pdev_get_psoc(pdev); 2007 if (!psoc) { 2008 reg_err("psoc is NULL"); 2009 return QDF_STATUS_E_INVAL; 2010 } 2011 2012 psoc_priv_obj = reg_get_psoc_obj(psoc); 2013 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2014 reg_err("psoc reg component is NULL"); 2015 return QDF_STATUS_E_FAILURE; 2016 } 2017 2018 if (psoc_priv_obj->offload_enabled) { 2019 if ((rd->flags == ALPHA_IS_SET) && (rd->cc.alpha[2] == 'O')) 2020 pdev_priv_obj->indoor_chan_enabled = false; 2021 else 2022 pdev_priv_obj->indoor_chan_enabled = true; 2023 2024 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 2025 tx_ops = reg_get_psoc_tx_ops(psoc); 2026 2027 if (tx_ops->get_phy_id_from_pdev_id) 2028 tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id); 2029 else 2030 phy_id = pdev_id; 2031 2032 if (tx_ops->set_user_country_code) { 2033 psoc_priv_obj->new_init_ctry_pending[phy_id] = true; 2034 return tx_ops->set_user_country_code(psoc, pdev_id, rd); 2035 } 2036 2037 return QDF_STATUS_E_FAILURE; 2038 } 2039 2040 return reg_program_chan_list_po(psoc, pdev, rd); 2041 } 2042 2043 QDF_STATUS reg_get_current_cc(struct wlan_objmgr_pdev *pdev, 2044 struct cc_regdmn_s *rd) 2045 { 2046 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 2047 2048 pdev_priv_obj = reg_get_pdev_obj(pdev); 2049 if (!pdev_priv_obj) { 2050 reg_err("reg pdev priv is NULL"); 2051 return QDF_STATUS_E_FAILURE; 2052 } 2053 2054 if (rd->flags == CC_IS_SET) { 2055 rd->cc.country_code = pdev_priv_obj->ctry_code; 2056 } else if (rd->flags == ALPHA_IS_SET) { 2057 qdf_mem_copy(rd->cc.alpha, pdev_priv_obj->current_country, 2058 sizeof(rd->cc.alpha)); 2059 } else if (rd->flags == REGDMN_IS_SET) { 2060 rd->cc.regdmn.reg_2g_5g_pair_id = pdev_priv_obj->reg_dmn_pair; 2061 rd->cc.regdmn.sixg_superdmn_id = pdev_priv_obj->reg_6g_superid; 2062 } 2063 2064 return QDF_STATUS_SUCCESS; 2065 } 2066 2067 QDF_STATUS reg_set_regdb_offloaded(struct wlan_objmgr_psoc *psoc, bool val) 2068 { 2069 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2070 2071 psoc_priv_obj = reg_get_psoc_obj(psoc); 2072 2073 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2074 reg_err("psoc reg component is NULL"); 2075 return QDF_STATUS_E_FAILURE; 2076 } 2077 2078 psoc_priv_obj->offload_enabled = val; 2079 2080 return QDF_STATUS_SUCCESS; 2081 } 2082 2083 QDF_STATUS reg_get_curr_regdomain(struct wlan_objmgr_pdev *pdev, 2084 struct cur_regdmn_info *cur_regdmn) 2085 { 2086 struct wlan_objmgr_psoc *psoc; 2087 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2088 uint16_t index; 2089 int num_reg_dmn; 2090 uint8_t phy_id; 2091 uint8_t pdev_id; 2092 struct wlan_lmac_if_reg_tx_ops *tx_ops; 2093 2094 psoc = wlan_pdev_get_psoc(pdev); 2095 psoc_priv_obj = reg_get_psoc_obj(psoc); 2096 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2097 reg_err("soc reg component is NULL"); 2098 return QDF_STATUS_E_INVAL; 2099 } 2100 2101 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 2102 2103 tx_ops = reg_get_psoc_tx_ops(psoc); 2104 if (tx_ops->get_phy_id_from_pdev_id) 2105 tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id); 2106 else 2107 phy_id = pdev_id; 2108 2109 cur_regdmn->regdmn_pair_id = 2110 psoc_priv_obj->mas_chan_params[phy_id].reg_dmn_pair; 2111 2112 reg_get_num_reg_dmn_pairs(&num_reg_dmn); 2113 for (index = 0; index < num_reg_dmn; index++) { 2114 if (g_reg_dmn_pairs[index].reg_dmn_pair_id == 2115 cur_regdmn->regdmn_pair_id) 2116 break; 2117 } 2118 2119 if (index == num_reg_dmn) { 2120 reg_debug_rl("invalid regdomain"); 2121 return QDF_STATUS_E_FAILURE; 2122 } 2123 2124 cur_regdmn->dmn_id_2g = g_reg_dmn_pairs[index].dmn_id_2g; 2125 cur_regdmn->dmn_id_5g = g_reg_dmn_pairs[index].dmn_id_5g; 2126 cur_regdmn->ctl_2g = regdomains_2g[cur_regdmn->dmn_id_2g].ctl_val; 2127 cur_regdmn->ctl_5g = regdomains_5g[cur_regdmn->dmn_id_5g].ctl_val; 2128 cur_regdmn->dfs_region = 2129 regdomains_5g[cur_regdmn->dmn_id_5g].dfs_region; 2130 2131 return QDF_STATUS_SUCCESS; 2132 } 2133 2134 QDF_STATUS reg_modify_chan_144(struct wlan_objmgr_pdev *pdev, 2135 bool enable_ch_144) 2136 { 2137 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2138 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 2139 struct wlan_objmgr_psoc *psoc; 2140 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 2141 QDF_STATUS status; 2142 2143 pdev_priv_obj = reg_get_pdev_obj(pdev); 2144 2145 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 2146 reg_err("pdev reg component is NULL"); 2147 return QDF_STATUS_E_INVAL; 2148 } 2149 2150 if (pdev_priv_obj->en_chan_144 == enable_ch_144) { 2151 reg_info("chan 144 is already %d", enable_ch_144); 2152 return QDF_STATUS_SUCCESS; 2153 } 2154 2155 psoc = wlan_pdev_get_psoc(pdev); 2156 if (!psoc) { 2157 reg_err("psoc is NULL"); 2158 return QDF_STATUS_E_INVAL; 2159 } 2160 2161 psoc_priv_obj = reg_get_psoc_obj(psoc); 2162 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2163 reg_err("psoc reg component is NULL"); 2164 return QDF_STATUS_E_INVAL; 2165 } 2166 2167 reg_debug("setting chan 144: %d", enable_ch_144); 2168 pdev_priv_obj->en_chan_144 = enable_ch_144; 2169 2170 reg_compute_pdev_current_chan_list(pdev_priv_obj); 2171 2172 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 2173 if (reg_tx_ops->fill_umac_legacy_chanlist) 2174 reg_tx_ops->fill_umac_legacy_chanlist(pdev, 2175 pdev_priv_obj->cur_chan_list); 2176 2177 status = reg_send_scheduler_msg_sb(psoc, pdev); 2178 2179 return status; 2180 } 2181 2182 bool reg_get_en_chan_144(struct wlan_objmgr_pdev *pdev) 2183 { 2184 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 2185 2186 pdev_priv_obj = reg_get_pdev_obj(pdev); 2187 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 2188 reg_err("pdev reg component is NULL"); 2189 return false; 2190 } 2191 2192 return pdev_priv_obj->en_chan_144; 2193 } 2194 2195 struct wlan_psoc_host_hal_reg_capabilities_ext *reg_get_hal_reg_cap( 2196 struct wlan_objmgr_psoc *psoc) 2197 { 2198 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2199 2200 psoc_priv_obj = reg_get_psoc_obj(psoc); 2201 2202 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2203 reg_err("psoc reg component is NULL"); 2204 return NULL; 2205 } 2206 2207 return psoc_priv_obj->reg_cap; 2208 } 2209 2210 QDF_STATUS reg_set_hal_reg_cap( 2211 struct wlan_objmgr_psoc *psoc, 2212 struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap, 2213 uint16_t phy_cnt) 2214 { 2215 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2216 2217 psoc_priv_obj = reg_get_psoc_obj(psoc); 2218 2219 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2220 reg_err("psoc reg component is NULL"); 2221 return QDF_STATUS_E_FAILURE; 2222 } 2223 2224 if (phy_cnt > PSOC_MAX_PHY_REG_CAP) { 2225 reg_err("phy cnt:%d is more than %d", phy_cnt, 2226 PSOC_MAX_PHY_REG_CAP); 2227 return QDF_STATUS_E_FAILURE; 2228 } 2229 2230 qdf_mem_copy(psoc_priv_obj->reg_cap, reg_cap, 2231 phy_cnt * 2232 sizeof(struct wlan_psoc_host_hal_reg_capabilities_ext)); 2233 2234 return QDF_STATUS_SUCCESS; 2235 } 2236 2237 QDF_STATUS reg_update_hal_cap_wireless_modes(struct wlan_objmgr_psoc *psoc, 2238 uint64_t wireless_modes, uint8_t phy_id) 2239 { 2240 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2241 2242 if (!psoc) { 2243 reg_err("psoc is null"); 2244 return QDF_STATUS_E_FAILURE; 2245 } 2246 2247 psoc_priv_obj = reg_get_psoc_obj(psoc); 2248 2249 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2250 reg_err("psoc reg component is NULL"); 2251 return QDF_STATUS_E_FAILURE; 2252 } 2253 2254 psoc_priv_obj->reg_cap[phy_id].wireless_modes |= wireless_modes; 2255 2256 return QDF_STATUS_SUCCESS; 2257 } 2258 2259 QDF_STATUS reg_update_hal_reg_range_caps(struct wlan_objmgr_psoc *psoc, 2260 uint32_t low_2g_chan, 2261 uint32_t high_2g_chan, 2262 uint32_t low_5g_chan, 2263 uint32_t high_5g_chan, 2264 uint8_t phy_id) 2265 { 2266 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2267 struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap; 2268 2269 if (!psoc) { 2270 reg_err("psoc is null"); 2271 return QDF_STATUS_E_FAILURE; 2272 } 2273 2274 psoc_priv_obj = reg_get_psoc_obj(psoc); 2275 2276 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2277 reg_err("psoc reg component is NULL"); 2278 return QDF_STATUS_E_FAILURE; 2279 } 2280 2281 reg_cap = &psoc_priv_obj->reg_cap[phy_id]; 2282 reg_cap->low_2ghz_chan = low_2g_chan; 2283 reg_cap->high_2ghz_chan = high_2g_chan; 2284 reg_cap->low_5ghz_chan = low_5g_chan; 2285 reg_cap->high_5ghz_chan = high_5g_chan; 2286 2287 return QDF_STATUS_SUCCESS; 2288 } 2289 2290 #if defined(CONFIG_BAND_6GHZ) && defined(CONFIG_AFC_SUPPORT) 2291 bool reg_get_enable_6ghz_sp_mode_support(struct wlan_objmgr_psoc *psoc) 2292 { 2293 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2294 2295 psoc_priv_obj = reg_get_psoc_obj(psoc); 2296 2297 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2298 reg_err("psoc reg component is NULL"); 2299 return false; 2300 } 2301 2302 return psoc_priv_obj->enable_6ghz_sp_pwrmode_supp; 2303 } 2304 2305 void reg_set_enable_6ghz_sp_mode_support(struct wlan_objmgr_psoc *psoc, 2306 bool value) 2307 { 2308 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2309 2310 psoc_priv_obj = reg_get_psoc_obj(psoc); 2311 2312 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2313 reg_err("psoc reg component is NULL"); 2314 return; 2315 } 2316 2317 psoc_priv_obj->enable_6ghz_sp_pwrmode_supp = value; 2318 } 2319 2320 bool reg_get_afc_disable_timer_check(struct wlan_objmgr_psoc *psoc) 2321 { 2322 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2323 2324 psoc_priv_obj = reg_get_psoc_obj(psoc); 2325 2326 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2327 reg_err("psoc reg component is NULL"); 2328 return false; 2329 } 2330 2331 return psoc_priv_obj->afc_disable_timer_check; 2332 } 2333 2334 void reg_set_afc_disable_timer_check(struct wlan_objmgr_psoc *psoc, 2335 bool value) 2336 { 2337 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2338 2339 psoc_priv_obj = reg_get_psoc_obj(psoc); 2340 2341 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2342 reg_err("psoc reg component is NULL"); 2343 return; 2344 } 2345 2346 psoc_priv_obj->afc_disable_timer_check = value; 2347 } 2348 2349 bool reg_get_afc_disable_request_id_check(struct wlan_objmgr_psoc *psoc) 2350 { 2351 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2352 2353 psoc_priv_obj = reg_get_psoc_obj(psoc); 2354 2355 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2356 reg_err("psoc reg component is NULL"); 2357 return false; 2358 } 2359 2360 return psoc_priv_obj->afc_disable_request_id_check; 2361 } 2362 2363 void reg_set_afc_disable_request_id_check(struct wlan_objmgr_psoc *psoc, 2364 bool value) 2365 { 2366 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2367 2368 psoc_priv_obj = reg_get_psoc_obj(psoc); 2369 2370 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2371 reg_err("psoc reg component is NULL"); 2372 return; 2373 } 2374 2375 psoc_priv_obj->afc_disable_request_id_check = value; 2376 } 2377 2378 bool reg_get_afc_noaction(struct wlan_objmgr_psoc *psoc) 2379 { 2380 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2381 2382 psoc_priv_obj = reg_get_psoc_obj(psoc); 2383 2384 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2385 reg_err("psoc reg component is NULL"); 2386 return false; 2387 } 2388 2389 return psoc_priv_obj->is_afc_reg_noaction; 2390 } 2391 2392 void reg_set_afc_noaction(struct wlan_objmgr_psoc *psoc, bool value) 2393 { 2394 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 2395 2396 psoc_priv_obj = reg_get_psoc_obj(psoc); 2397 2398 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 2399 reg_err("psoc reg component is NULL"); 2400 return; 2401 } 2402 2403 psoc_priv_obj->is_afc_reg_noaction = value; 2404 } 2405 #endif 2406 2407 bool reg_chan_in_range(struct regulatory_channel *chan_list, 2408 qdf_freq_t low_freq_2g, qdf_freq_t high_freq_2g, 2409 qdf_freq_t low_freq_5g, qdf_freq_t high_freq_5g, 2410 enum channel_enum ch_enum) 2411 { 2412 uint32_t low_limit_2g = NUM_CHANNELS; 2413 uint32_t high_limit_2g = NUM_CHANNELS; 2414 uint32_t low_limit_5g = NUM_CHANNELS; 2415 uint32_t high_limit_5g = NUM_CHANNELS; 2416 bool chan_in_range; 2417 enum channel_enum chan_enum; 2418 uint16_t min_bw; 2419 qdf_freq_t center_freq; 2420 2421 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) { 2422 min_bw = chan_list[chan_enum].min_bw; 2423 center_freq = chan_list[chan_enum].center_freq; 2424 2425 if ((center_freq - min_bw / 2) >= low_freq_2g) { 2426 low_limit_2g = chan_enum; 2427 break; 2428 } 2429 } 2430 2431 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) { 2432 min_bw = chan_list[chan_enum].min_bw; 2433 center_freq = chan_list[chan_enum].center_freq; 2434 2435 if ((center_freq - min_bw / 2) >= low_freq_5g) { 2436 low_limit_5g = chan_enum; 2437 break; 2438 } 2439 } 2440 2441 for (chan_enum = NUM_CHANNELS - 1; chan_enum >= 0; chan_enum--) { 2442 min_bw = chan_list[chan_enum].min_bw; 2443 center_freq = chan_list[chan_enum].center_freq; 2444 2445 if (center_freq + min_bw / 2 <= high_freq_2g) { 2446 high_limit_2g = chan_enum; 2447 break; 2448 } 2449 if (chan_enum == 0) 2450 break; 2451 } 2452 2453 for (chan_enum = NUM_CHANNELS - 1; chan_enum >= 0; chan_enum--) { 2454 min_bw = chan_list[chan_enum].min_bw; 2455 center_freq = chan_list[chan_enum].center_freq; 2456 2457 if (center_freq + min_bw / 2 <= high_freq_5g) { 2458 high_limit_5g = chan_enum; 2459 break; 2460 } 2461 if (chan_enum == 0) 2462 break; 2463 } 2464 2465 chan_in_range = false; 2466 if ((low_limit_2g <= ch_enum) && 2467 (high_limit_2g >= ch_enum) && 2468 (low_limit_2g != NUM_CHANNELS) && 2469 (high_limit_2g != NUM_CHANNELS)) 2470 chan_in_range = true; 2471 if ((low_limit_5g <= ch_enum) && 2472 (high_limit_5g >= ch_enum) && 2473 (low_limit_5g != NUM_CHANNELS) && 2474 (high_limit_5g != NUM_CHANNELS)) 2475 chan_in_range = true; 2476 2477 if (chan_in_range) 2478 return true; 2479 else 2480 return false; 2481 } 2482 2483 bool reg_is_24ghz_ch_freq(uint32_t freq) 2484 { 2485 return REG_IS_24GHZ_CH_FREQ(freq); 2486 } 2487 2488 bool reg_is_5ghz_ch_freq(uint32_t freq) 2489 { 2490 return REG_IS_5GHZ_FREQ(freq); 2491 } 2492 2493 /** 2494 * BAND_2G_PRESENT() - Check if REG_BAND_2G is set in the band_mask 2495 * @band_mask: Bitmask for bands 2496 * 2497 * Return: True if REG_BAND_2G is set in the band_mask, else false 2498 */ 2499 static inline bool BAND_2G_PRESENT(uint8_t band_mask) 2500 { 2501 return !!(band_mask & (BIT(REG_BAND_2G))); 2502 } 2503 2504 /** 2505 * BAND_5G_PRESENT() - Check if REG_BAND_5G is set in the band_mask 2506 * @band_mask: Bitmask for bands 2507 * 2508 * Return: True if REG_BAND_5G is set in the band_mask, else false 2509 */ 2510 static inline bool BAND_5G_PRESENT(uint8_t band_mask) 2511 { 2512 return !!(band_mask & (BIT(REG_BAND_5G))); 2513 } 2514 2515 /** 2516 * reg_is_freq_in_between() - Check whether freq falls within low_freq and 2517 * high_freq, inclusively. 2518 * @low_freq: Low frequency. 2519 * @high_freq: High frequency. 2520 * @freq: Frequency to be checked. 2521 * 2522 * Return: True if freq falls within low_freq and high_freq, else false. 2523 */ 2524 static bool reg_is_freq_in_between(qdf_freq_t low_freq, qdf_freq_t high_freq, 2525 qdf_freq_t freq) 2526 { 2527 return (low_freq <= freq && freq <= high_freq); 2528 } 2529 2530 static bool reg_is_ranges_overlap(qdf_freq_t low_freq, qdf_freq_t high_freq, 2531 qdf_freq_t start_edge_freq, 2532 qdf_freq_t end_edge_freq) 2533 { 2534 return (reg_is_freq_in_between(start_edge_freq, 2535 end_edge_freq, 2536 low_freq) || 2537 reg_is_freq_in_between(start_edge_freq, 2538 end_edge_freq, 2539 high_freq) || 2540 reg_is_freq_in_between(low_freq, 2541 high_freq, 2542 start_edge_freq) || 2543 reg_is_freq_in_between(low_freq, 2544 high_freq, 2545 end_edge_freq)); 2546 } 2547 2548 bool reg_is_range_overlap_2g(qdf_freq_t low_freq, qdf_freq_t high_freq) 2549 { 2550 return reg_is_ranges_overlap(low_freq, high_freq, 2551 TWO_GIG_STARTING_EDGE_FREQ, 2552 TWO_GIG_ENDING_EDGE_FREQ); 2553 } 2554 2555 bool reg_is_range_overlap_5g(qdf_freq_t low_freq, qdf_freq_t high_freq) 2556 { 2557 return reg_is_ranges_overlap(low_freq, high_freq, 2558 FIVE_GIG_STARTING_EDGE_FREQ, 2559 FIVE_GIG_ENDING_EDGE_FREQ); 2560 } 2561 2562 static struct regulatory_channel * 2563 reg_get_reg_chan(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 2564 { 2565 struct regulatory_channel *cur_chan_list; 2566 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 2567 enum channel_enum chan_enum; 2568 2569 pdev_priv_obj = reg_get_pdev_obj(pdev); 2570 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 2571 reg_err("reg pdev priv obj is NULL"); 2572 return NULL; 2573 } 2574 2575 chan_enum = reg_get_chan_enum_for_freq(freq); 2576 if (reg_is_chan_enum_invalid(chan_enum)) { 2577 reg_err_rl("Invalid chan enum %d", chan_enum); 2578 return NULL; 2579 } 2580 2581 cur_chan_list = pdev_priv_obj->cur_chan_list; 2582 if (cur_chan_list[chan_enum].state == CHANNEL_STATE_DISABLE) { 2583 reg_err("Channel %u is not enabled for this pdev", freq); 2584 return NULL; 2585 } 2586 2587 return &cur_chan_list[chan_enum]; 2588 } 2589 2590 bool reg_is_freq_indoor(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 2591 { 2592 struct regulatory_channel *reg_chan; 2593 2594 reg_chan = reg_get_reg_chan(pdev, freq); 2595 2596 if (!reg_chan) { 2597 reg_err("reg channel is NULL"); 2598 return false; 2599 } 2600 2601 return (reg_chan->chan_flags & 2602 REGULATORY_CHAN_INDOOR_ONLY); 2603 } 2604 2605 uint16_t reg_get_min_chwidth(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 2606 { 2607 struct regulatory_channel *reg_chan; 2608 2609 reg_chan = reg_get_reg_chan(pdev, freq); 2610 2611 if (!reg_chan) { 2612 reg_err("reg channel is NULL"); 2613 return 0; 2614 } 2615 2616 return reg_chan->min_bw; 2617 } 2618 2619 uint16_t reg_get_max_chwidth(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 2620 { 2621 struct regulatory_channel *reg_chan; 2622 2623 reg_chan = reg_get_reg_chan(pdev, freq); 2624 2625 if (!reg_chan) { 2626 reg_err("reg channel is NULL"); 2627 return 0; 2628 } 2629 2630 return reg_chan->max_bw; 2631 } 2632 2633 #ifdef CONFIG_REG_CLIENT 2634 bool reg_is_freq_indoor_in_secondary_list(struct wlan_objmgr_pdev *pdev, 2635 qdf_freq_t freq) 2636 { 2637 struct regulatory_channel *secondary_cur_chan_list; 2638 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 2639 enum channel_enum chan_enum; 2640 2641 pdev_priv_obj = reg_get_pdev_obj(pdev); 2642 2643 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 2644 reg_err("reg pdev priv obj is NULL"); 2645 return false; 2646 } 2647 2648 chan_enum = reg_get_chan_enum_for_freq(freq); 2649 2650 if (reg_is_chan_enum_invalid(chan_enum)) { 2651 reg_err_rl("Invalid chan enum %d", chan_enum); 2652 return false; 2653 } 2654 2655 secondary_cur_chan_list = pdev_priv_obj->secondary_cur_chan_list; 2656 2657 return (secondary_cur_chan_list[chan_enum].chan_flags & 2658 REGULATORY_CHAN_INDOOR_ONLY); 2659 } 2660 #endif 2661 2662 #ifdef CONFIG_BAND_6GHZ 2663 bool reg_is_6ghz_chan_freq(uint16_t freq) 2664 { 2665 return REG_IS_6GHZ_FREQ(freq); 2666 } 2667 2668 #ifdef CONFIG_6G_FREQ_OVERLAP 2669 bool reg_is_range_overlap_6g(qdf_freq_t low_freq, qdf_freq_t high_freq) 2670 { 2671 return reg_is_ranges_overlap(low_freq, high_freq, 2672 SIX_GIG_STARTING_EDGE_FREQ, 2673 SIX_GIG_ENDING_EDGE_FREQ); 2674 } 2675 2676 bool reg_is_range_only6g(qdf_freq_t low_freq, qdf_freq_t high_freq) 2677 { 2678 if (low_freq >= high_freq) { 2679 reg_err_rl("Low freq is greater than or equal to high freq"); 2680 return false; 2681 } 2682 2683 if (reg_is_range_overlap_6g(low_freq, high_freq) && 2684 !reg_is_range_overlap_5g(low_freq, high_freq)) { 2685 reg_debug_rl("The device is 6G only"); 2686 return true; 2687 } 2688 2689 reg_debug_rl("The device is not 6G only"); 2690 2691 return false; 2692 } 2693 #endif 2694 2695 uint16_t reg_min_6ghz_chan_freq(void) 2696 { 2697 return REG_MIN_6GHZ_CHAN_FREQ; 2698 } 2699 2700 uint16_t reg_max_6ghz_chan_freq(void) 2701 { 2702 return REG_MAX_6GHZ_CHAN_FREQ; 2703 } 2704 2705 bool reg_is_6ghz_psc_chan_freq(uint16_t freq) 2706 { 2707 if (!REG_IS_6GHZ_FREQ(freq)) { 2708 reg_debug(" Channel frequency is not a 6GHz frequency"); 2709 return false; 2710 } 2711 2712 if (!(((freq - SIX_GHZ_NON_ORPHAN_START_FREQ) + FREQ_LEFT_SHIFT) % 2713 (FREQ_TO_CHAN_SCALE * NUM_80MHZ_BAND_IN_6G))) { 2714 return true; 2715 } 2716 2717 reg_debug_rl("Channel freq %d MHz is not a 6GHz PSC frequency", freq); 2718 2719 return false; 2720 } 2721 2722 bool reg_is_6g_freq_indoor(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 2723 { 2724 return (REG_IS_6GHZ_FREQ(freq) && reg_is_freq_indoor(pdev, freq)); 2725 } 2726 2727 /** 2728 * reg_get_max_psd() - Get max PSD. 2729 * @freq: Channel frequency. 2730 * @bw: Channel bandwidth. 2731 * @reg_ap: Regulatory 6G AP type. 2732 * @reg_client: Regulatory 6G client type. 2733 * @tx_power: Pointer to tx-power. 2734 * 2735 * Return: Return QDF_STATUS_SUCCESS, if PSD is filled for 6G TPE IE 2736 * else return QDF_STATUS_E_FAILURE. 2737 */ 2738 static QDF_STATUS reg_get_max_psd(qdf_freq_t freq, 2739 uint16_t bw, 2740 enum reg_6g_ap_type reg_ap, 2741 enum reg_6g_client_type reg_client, 2742 uint8_t *tx_power) 2743 { 2744 if (reg_ap == REG_INDOOR_AP || 2745 reg_ap == REG_VERY_LOW_POWER_AP) { 2746 switch (reg_client) { 2747 case REG_DEFAULT_CLIENT: 2748 *tx_power = REG_PSD_MAX_TXPOWER_FOR_DEFAULT_CLIENT; 2749 return QDF_STATUS_SUCCESS; 2750 case REG_SUBORDINATE_CLIENT: 2751 *tx_power = REG_PSD_MAX_TXPOWER_FOR_SUBORDINATE_CLIENT; 2752 return QDF_STATUS_SUCCESS; 2753 default: 2754 reg_err_rl("Invalid client type"); 2755 return QDF_STATUS_E_FAILURE; 2756 } 2757 } 2758 2759 return QDF_STATUS_E_FAILURE; 2760 } 2761 2762 /** 2763 * reg_get_max_eirp() - Get max EIRP. 2764 * @pdev: Pointer to pdev. 2765 * @freq: Channel frequency. 2766 * @bw: Channel bandwidth. 2767 * @reg_ap: Regulatory 6G AP type. 2768 * @reg_client: Regulatory client type. 2769 * @tx_power: Pointer to tx-power. 2770 * 2771 * Return: Return QDF_STATUS_SUCCESS, if EIRP is filled for 6G TPE IE 2772 * else return QDF_STATUS_E_FAILURE. 2773 */ 2774 static QDF_STATUS reg_get_max_eirp(struct wlan_objmgr_pdev *pdev, 2775 qdf_freq_t freq, 2776 uint16_t bw, 2777 enum reg_6g_ap_type reg_ap, 2778 enum reg_6g_client_type reg_client, 2779 uint8_t *tx_power) 2780 { 2781 if (reg_ap == REG_INDOOR_AP || 2782 reg_ap == REG_VERY_LOW_POWER_AP) { 2783 switch (reg_client) { 2784 case REG_DEFAULT_CLIENT: 2785 *tx_power = reg_get_channel_reg_power_for_freq(pdev, 2786 freq); 2787 return QDF_STATUS_SUCCESS; 2788 case REG_SUBORDINATE_CLIENT: 2789 *tx_power = REG_EIRP_MAX_TXPOWER_FOR_SUBORDINATE_CLIENT; 2790 return QDF_STATUS_SUCCESS; 2791 default: 2792 reg_err_rl("Invalid client type"); 2793 return QDF_STATUS_E_FAILURE; 2794 } 2795 } 2796 2797 return QDF_STATUS_E_FAILURE; 2798 } 2799 2800 QDF_STATUS reg_get_max_txpower_for_6g_tpe(struct wlan_objmgr_pdev *pdev, 2801 qdf_freq_t freq, uint8_t bw, 2802 enum reg_6g_ap_type reg_ap, 2803 enum reg_6g_client_type reg_client, 2804 bool is_psd, 2805 uint8_t *tx_power) 2806 { 2807 if (!REG_IS_6GHZ_FREQ(freq)) { 2808 reg_err_rl("%d is not a 6G channel frequency", freq); 2809 return QDF_STATUS_E_FAILURE; 2810 } 2811 2812 /* 2813 * For now, there is support only for Indoor AP and we have only 2814 * LPI power values. 2815 */ 2816 if (is_psd) 2817 return reg_get_max_psd(freq, bw, reg_ap, reg_client, tx_power); 2818 2819 return reg_get_max_eirp(pdev, freq, bw, reg_ap, reg_client, tx_power); 2820 } 2821 2822 #define MIN_UNII_5_BAND_CHANNEL 5935 2823 #define MAX_UNII_5_BAND_CHANNEL 6415 2824 bool reg_is_6ghz_unii5_chan_freq(qdf_freq_t freq) 2825 { 2826 if (!REG_IS_6GHZ_FREQ(freq)) 2827 return false; 2828 2829 if (freq >= MIN_UNII_5_BAND_CHANNEL && freq <= MAX_UNII_5_BAND_CHANNEL) 2830 return true; 2831 2832 return false; 2833 } 2834 2835 /** 2836 * BAND_6G_PRESENT() - Check if REG_BAND_6G is set in the band_mask 2837 * @band_mask: Bitmask for bands 2838 * 2839 * Return: True if REG_BAND_6G is set in the band_mask, else false 2840 */ 2841 static inline bool BAND_6G_PRESENT(uint8_t band_mask) 2842 { 2843 return !!(band_mask & (BIT(REG_BAND_6G))); 2844 } 2845 #else 2846 static inline bool BAND_6G_PRESENT(uint8_t band_mask) 2847 { 2848 return false; 2849 } 2850 #endif /* CONFIG_BAND_6GHZ */ 2851 2852 /** 2853 * reg_get_band_from_cur_chan_list() - Get channel list and number of channels 2854 * @pdev: pdev ptr 2855 * @band_mask: Input bitmap with band set 2856 * @channel_list: Pointer to Channel List 2857 * @cur_chan_list: Pointer to primary current channel list for non-beaconing 2858 * entities (STA, p2p client) and secondary channel list for beaconing entities 2859 * (SAP, p2p GO) 2860 * 2861 * Get the given channel list and number of channels from the current channel 2862 * list based on input band bitmap. 2863 * 2864 * Return: Number of channels, else 0 to indicate error 2865 */ 2866 static uint16_t 2867 reg_get_band_from_cur_chan_list(struct wlan_objmgr_pdev *pdev, 2868 uint8_t band_mask, 2869 struct regulatory_channel *channel_list, 2870 struct regulatory_channel *cur_chan_list) 2871 { 2872 uint16_t i, num_channels = 0; 2873 2874 if (BAND_2G_PRESENT(band_mask)) { 2875 for (i = MIN_24GHZ_CHANNEL; i <= MAX_24GHZ_CHANNEL; i++) { 2876 if ((cur_chan_list[i].state != CHANNEL_STATE_DISABLE) && 2877 !(cur_chan_list[i].chan_flags & 2878 REGULATORY_CHAN_DISABLED)) { 2879 channel_list[num_channels] = cur_chan_list[i]; 2880 num_channels++; 2881 } 2882 } 2883 } 2884 if (BAND_5G_PRESENT(band_mask)) { 2885 for (i = BAND_5GHZ_START_CHANNEL; i <= MAX_5GHZ_CHANNEL; i++) { 2886 if ((cur_chan_list[i].state != CHANNEL_STATE_DISABLE) && 2887 !(cur_chan_list[i].chan_flags & 2888 REGULATORY_CHAN_DISABLED)) { 2889 channel_list[num_channels] = cur_chan_list[i]; 2890 num_channels++; 2891 } 2892 } 2893 } 2894 if (BAND_6G_PRESENT(band_mask)) { 2895 for (i = MIN_6GHZ_CHANNEL; i <= MAX_6GHZ_CHANNEL; i++) { 2896 if ((cur_chan_list[i].state != CHANNEL_STATE_DISABLE) && 2897 !(cur_chan_list[i].chan_flags & 2898 REGULATORY_CHAN_DISABLED)) { 2899 channel_list[num_channels] = cur_chan_list[i]; 2900 num_channels++; 2901 } 2902 } 2903 } 2904 2905 if (!num_channels) { 2906 reg_err("Failed to retrieve the channel list"); 2907 return 0; 2908 } 2909 2910 return num_channels; 2911 } 2912 2913 uint16_t 2914 reg_get_band_channel_list(struct wlan_objmgr_pdev *pdev, 2915 uint8_t band_mask, 2916 struct regulatory_channel *channel_list) 2917 { 2918 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 2919 2920 pdev_priv_obj = reg_get_pdev_obj(pdev); 2921 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 2922 reg_err("reg pdev priv obj is NULL"); 2923 return 0; 2924 } 2925 2926 return reg_get_band_from_cur_chan_list(pdev, band_mask, channel_list, 2927 pdev_priv_obj->cur_chan_list); 2928 } 2929 2930 #ifdef CONFIG_REG_6G_PWRMODE 2931 uint16_t 2932 reg_get_band_channel_list_for_pwrmode(struct wlan_objmgr_pdev *pdev, 2933 uint8_t band_mask, 2934 struct regulatory_channel *channel_list, 2935 enum supported_6g_pwr_types 2936 in_6g_pwr_mode) 2937 { 2938 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 2939 struct regulatory_channel *reg_chan_list; 2940 uint16_t nchan = 0; 2941 2942 reg_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*reg_chan_list)); 2943 2944 if (!reg_chan_list) 2945 return 0; 2946 2947 pdev_priv_obj = reg_get_pdev_obj(pdev); 2948 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 2949 reg_err("reg pdev priv obj is NULL"); 2950 goto err; 2951 } 2952 2953 if (reg_get_pwrmode_chan_list(pdev, reg_chan_list, in_6g_pwr_mode)) { 2954 reg_debug_rl("Unable to get powermode channel list"); 2955 goto err; 2956 } 2957 2958 nchan = reg_get_band_from_cur_chan_list(pdev, band_mask, channel_list, 2959 reg_chan_list); 2960 err: 2961 qdf_mem_free(reg_chan_list); 2962 return nchan; 2963 } 2964 #endif 2965 2966 #ifdef CONFIG_REG_CLIENT 2967 uint16_t 2968 reg_get_secondary_band_channel_list(struct wlan_objmgr_pdev *pdev, 2969 uint8_t band_mask, 2970 struct regulatory_channel *channel_list) 2971 { 2972 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 2973 2974 pdev_priv_obj = reg_get_pdev_obj(pdev); 2975 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 2976 reg_err("reg pdev priv obj is NULL"); 2977 return 0; 2978 } 2979 2980 return reg_get_band_from_cur_chan_list( 2981 pdev, band_mask, channel_list, 2982 pdev_priv_obj->secondary_cur_chan_list); 2983 } 2984 #endif 2985 2986 qdf_freq_t reg_chan_band_to_freq(struct wlan_objmgr_pdev *pdev, 2987 uint8_t chan_num, 2988 uint8_t band_mask) 2989 { 2990 enum channel_enum min_chan, max_chan; 2991 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 2992 uint16_t freq; 2993 2994 if (chan_num == 0) { 2995 reg_debug_rl("Invalid channel %d", chan_num); 2996 return 0; 2997 } 2998 2999 pdev_priv_obj = reg_get_pdev_obj(pdev); 3000 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 3001 reg_err("reg pdev priv obj is NULL"); 3002 return 0; 3003 } 3004 3005 if (BAND_6G_PRESENT(band_mask)) { 3006 if (BAND_2G_PRESENT(band_mask) || 3007 BAND_5G_PRESENT(band_mask)) { 3008 reg_err_rl("Incorrect band_mask %x", band_mask); 3009 return 0; 3010 } 3011 3012 /* Handle 6G channel 2 as a special case as it does not follow 3013 * the regular increasing order of channel numbers 3014 */ 3015 if (chan_num == SIXG_CHAN_2) { 3016 struct regulatory_channel *mas_chan_list; 3017 3018 mas_chan_list = pdev_priv_obj->mas_chan_list; 3019 /* Check if chan 2 is in the master list */ 3020 if ((mas_chan_list[CHAN_ENUM_SIXG_2].state != 3021 CHANNEL_STATE_DISABLE) && 3022 !(mas_chan_list[CHAN_ENUM_SIXG_2].chan_flags & 3023 REGULATORY_CHAN_DISABLED)) 3024 return mas_chan_list[CHAN_ENUM_SIXG_2]. 3025 center_freq; 3026 else 3027 return 0; 3028 } 3029 3030 /* MIN_6GHZ_CHANNEL corresponds to CHAN_ENUM_5935 3031 * ( a.k.a SIXG_CHAN_2). Skip it from the search space 3032 */ 3033 min_chan = MIN_6GHZ_CHANNEL + 1; 3034 max_chan = MAX_6GHZ_CHANNEL; 3035 return reg_compute_chan_to_freq(pdev, chan_num, 3036 min_chan, 3037 max_chan); 3038 } else { 3039 if (BAND_2G_PRESENT(band_mask)) { 3040 min_chan = MIN_24GHZ_CHANNEL; 3041 max_chan = MAX_24GHZ_CHANNEL; 3042 freq = reg_compute_chan_to_freq(pdev, chan_num, 3043 min_chan, 3044 max_chan); 3045 if (freq != 0) 3046 return freq; 3047 } 3048 3049 if (BAND_5G_PRESENT(band_mask)) { 3050 min_chan = BAND_5GHZ_START_CHANNEL; 3051 max_chan = MAX_5GHZ_CHANNEL; 3052 3053 return reg_compute_chan_to_freq(pdev, chan_num, 3054 min_chan, 3055 max_chan); 3056 } 3057 3058 reg_err_rl("Incorrect band_mask %x", band_mask); 3059 return 0; 3060 } 3061 } 3062 3063 #ifdef CONFIG_49GHZ_CHAN 3064 bool reg_is_49ghz_freq(qdf_freq_t freq) 3065 { 3066 return REG_IS_49GHZ_FREQ(freq); 3067 } 3068 #endif /* CONFIG_49GHZ_CHAN */ 3069 3070 qdf_freq_t reg_ch_num(uint32_t ch_enum) 3071 { 3072 return REG_CH_NUM(ch_enum); 3073 } 3074 3075 qdf_freq_t reg_ch_to_freq(uint32_t ch_enum) 3076 { 3077 return REG_CH_TO_FREQ(ch_enum); 3078 } 3079 3080 uint8_t reg_max_5ghz_ch_num(void) 3081 { 3082 return g_reg_max_5g_chan_num; 3083 } 3084 3085 #ifdef CONFIG_CHAN_FREQ_API 3086 qdf_freq_t reg_min_24ghz_chan_freq(void) 3087 { 3088 return REG_MIN_24GHZ_CH_FREQ; 3089 } 3090 3091 qdf_freq_t reg_max_24ghz_chan_freq(void) 3092 { 3093 return REG_MAX_24GHZ_CH_FREQ; 3094 } 3095 3096 qdf_freq_t reg_min_5ghz_chan_freq(void) 3097 { 3098 return REG_MIN_5GHZ_CH_FREQ; 3099 } 3100 3101 qdf_freq_t reg_max_5ghz_chan_freq(void) 3102 { 3103 return REG_MAX_5GHZ_CH_FREQ; 3104 } 3105 #endif /* CONFIG_CHAN_FREQ_API */ 3106 3107 QDF_STATUS reg_enable_dfs_channels(struct wlan_objmgr_pdev *pdev, 3108 bool enable) 3109 { 3110 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 3111 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 3112 struct wlan_objmgr_psoc *psoc; 3113 QDF_STATUS status; 3114 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 3115 3116 pdev_priv_obj = reg_get_pdev_obj(pdev); 3117 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 3118 reg_err("pdev reg component is NULL"); 3119 return QDF_STATUS_E_INVAL; 3120 } 3121 3122 if (pdev_priv_obj->dfs_enabled == enable) { 3123 reg_info("dfs_enabled is already set to %d", enable); 3124 return QDF_STATUS_SUCCESS; 3125 } 3126 3127 psoc = wlan_pdev_get_psoc(pdev); 3128 if (!psoc) { 3129 reg_err("psoc is NULL"); 3130 return QDF_STATUS_E_INVAL; 3131 } 3132 3133 psoc_priv_obj = reg_get_psoc_obj(psoc); 3134 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 3135 reg_err("psoc reg component is NULL"); 3136 return QDF_STATUS_E_INVAL; 3137 } 3138 3139 reg_info("set dfs_enabled: %d", enable); 3140 3141 pdev_priv_obj->dfs_enabled = enable; 3142 3143 reg_compute_pdev_current_chan_list(pdev_priv_obj); 3144 3145 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 3146 3147 /* Fill the ic channel list with the updated current channel 3148 * chan list. 3149 */ 3150 if (reg_tx_ops->fill_umac_legacy_chanlist) 3151 reg_tx_ops->fill_umac_legacy_chanlist(pdev, 3152 pdev_priv_obj->cur_chan_list); 3153 3154 status = reg_send_scheduler_msg_sb(psoc, pdev); 3155 3156 return status; 3157 } 3158 3159 #ifdef WLAN_REG_PARTIAL_OFFLOAD 3160 bool reg_is_regdmn_en302502_applicable(struct wlan_objmgr_pdev *pdev) 3161 { 3162 struct cur_regdmn_info cur_reg_dmn; 3163 QDF_STATUS status; 3164 3165 status = reg_get_curr_regdomain(pdev, &cur_reg_dmn); 3166 if (status != QDF_STATUS_SUCCESS) { 3167 reg_err("Failed to get reg domain"); 3168 return false; 3169 } 3170 3171 return reg_en302_502_regdmn(cur_reg_dmn.regdmn_pair_id); 3172 } 3173 #endif 3174 3175 QDF_STATUS reg_get_phybitmap(struct wlan_objmgr_pdev *pdev, 3176 uint16_t *phybitmap) 3177 { 3178 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 3179 3180 pdev_priv_obj = reg_get_pdev_obj(pdev); 3181 3182 if (!pdev_priv_obj) { 3183 reg_err("reg pdev private obj is NULL"); 3184 return QDF_STATUS_E_FAULT; 3185 } 3186 3187 *phybitmap = pdev_priv_obj->phybitmap; 3188 3189 return QDF_STATUS_SUCCESS; 3190 } 3191 3192 QDF_STATUS reg_update_channel_ranges(struct wlan_objmgr_pdev *pdev) 3193 { 3194 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 3195 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 3196 struct wlan_objmgr_psoc *psoc; 3197 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 3198 struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap_ptr; 3199 uint32_t cnt; 3200 uint8_t phy_id; 3201 uint8_t pdev_id; 3202 QDF_STATUS status = QDF_STATUS_SUCCESS; 3203 3204 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 3205 3206 pdev_priv_obj = reg_get_pdev_obj(pdev); 3207 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 3208 reg_err("pdev reg component is NULL"); 3209 return QDF_STATUS_E_INVAL; 3210 } 3211 3212 psoc = wlan_pdev_get_psoc(pdev); 3213 if (!psoc) { 3214 reg_err("psoc is NULL"); 3215 return QDF_STATUS_E_INVAL; 3216 } 3217 3218 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 3219 if (reg_tx_ops->get_phy_id_from_pdev_id) 3220 reg_tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id); 3221 else 3222 phy_id = pdev_id; 3223 3224 psoc_priv_obj = reg_get_psoc_obj(psoc); 3225 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 3226 reg_err("psoc reg component is NULL"); 3227 return QDF_STATUS_E_INVAL; 3228 } 3229 3230 reg_cap_ptr = psoc_priv_obj->reg_cap; 3231 3232 for (cnt = 0; cnt < PSOC_MAX_PHY_REG_CAP; cnt++) { 3233 if (!reg_cap_ptr) { 3234 qdf_mem_free(pdev_priv_obj); 3235 reg_err("reg cap ptr is NULL"); 3236 return QDF_STATUS_E_FAULT; 3237 } 3238 3239 if (reg_cap_ptr->phy_id == phy_id) 3240 break; 3241 reg_cap_ptr++; 3242 } 3243 3244 if (cnt == PSOC_MAX_PHY_REG_CAP) { 3245 qdf_mem_free(pdev_priv_obj); 3246 reg_err("extended capabilities not found for pdev"); 3247 return QDF_STATUS_E_FAULT; 3248 } 3249 pdev_priv_obj->range_2g_low = reg_cap_ptr->low_2ghz_chan; 3250 pdev_priv_obj->range_2g_high = reg_cap_ptr->high_2ghz_chan; 3251 pdev_priv_obj->range_5g_low = reg_cap_ptr->low_5ghz_chan; 3252 pdev_priv_obj->range_5g_high = reg_cap_ptr->high_5ghz_chan; 3253 pdev_priv_obj->wireless_modes = reg_cap_ptr->wireless_modes; 3254 3255 return status; 3256 } 3257 3258 QDF_STATUS reg_modify_pdev_chan_range(struct wlan_objmgr_pdev *pdev) 3259 { 3260 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 3261 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 3262 struct wlan_objmgr_psoc *psoc; 3263 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 3264 enum direction dir; 3265 QDF_STATUS status; 3266 3267 status = reg_update_channel_ranges(pdev); 3268 if (status != QDF_STATUS_SUCCESS) 3269 return status; 3270 3271 pdev_priv_obj = reg_get_pdev_obj(pdev); 3272 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 3273 reg_err("pdev reg component is NULL"); 3274 return QDF_STATUS_E_INVAL; 3275 } 3276 3277 psoc = wlan_pdev_get_psoc(pdev); 3278 if (!psoc) { 3279 reg_err("psoc is NULL"); 3280 return QDF_STATUS_E_INVAL; 3281 } 3282 3283 psoc_priv_obj = reg_get_psoc_obj(psoc); 3284 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 3285 reg_err("psoc reg component is NULL"); 3286 return QDF_STATUS_E_INVAL; 3287 } 3288 3289 if (psoc_priv_obj->offload_enabled) { 3290 dir = NORTHBOUND; 3291 } else { 3292 dir = SOUTHBOUND; 3293 } 3294 3295 reg_compute_pdev_current_chan_list(pdev_priv_obj); 3296 3297 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 3298 3299 /* Fill the ic channel list with the updated current channel 3300 * chan list. 3301 */ 3302 if (reg_tx_ops->fill_umac_legacy_chanlist) { 3303 reg_tx_ops->fill_umac_legacy_chanlist(pdev, 3304 pdev_priv_obj->cur_chan_list); 3305 3306 } else { 3307 if (dir == NORTHBOUND) 3308 status = reg_send_scheduler_msg_nb(psoc, pdev); 3309 else 3310 status = reg_send_scheduler_msg_sb(psoc, pdev); 3311 } 3312 3313 return status; 3314 } 3315 3316 QDF_STATUS reg_update_pdev_wireless_modes(struct wlan_objmgr_pdev *pdev, 3317 uint64_t wireless_modes) 3318 { 3319 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 3320 3321 pdev_priv_obj = wlan_objmgr_pdev_get_comp_private_obj(pdev, 3322 WLAN_UMAC_COMP_REGULATORY); 3323 3324 if (!pdev_priv_obj) { 3325 reg_err("reg pdev private obj is NULL"); 3326 return QDF_STATUS_E_INVAL; 3327 } 3328 3329 pdev_priv_obj->wireless_modes = wireless_modes; 3330 3331 return QDF_STATUS_SUCCESS; 3332 } 3333 3334 #ifdef DISABLE_UNII_SHARED_BANDS 3335 /** 3336 * reg_is_reg_unii_band_1_or_reg_unii_band_2a() - Check the input bitmap 3337 * @unii_5g_bitmap: 5G UNII band bitmap 3338 * 3339 * This function checks if either REG_UNII_BAND_1 or REG_UNII_BAND_2A, 3340 * are present in the 5G UNII band bitmap. 3341 * 3342 * Return: Return true if REG_UNII_BAND_1 or REG_UNII_BAND_2A, are present in 3343 * the UNII 5g bitmap else return false. 3344 */ 3345 static bool 3346 reg_is_reg_unii_band_1_or_reg_unii_band_2a(uint8_t unii_5g_bitmap) 3347 { 3348 if (!unii_5g_bitmap) 3349 return false; 3350 3351 return ((unii_5g_bitmap & (BIT(REG_UNII_BAND_1) | 3352 BIT(REG_UNII_BAND_2A))) == unii_5g_bitmap); 3353 } 3354 3355 QDF_STATUS reg_disable_chan_coex(struct wlan_objmgr_pdev *pdev, 3356 uint8_t unii_5g_bitmap) 3357 { 3358 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 3359 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 3360 struct wlan_objmgr_psoc *psoc; 3361 3362 psoc = wlan_pdev_get_psoc(pdev); 3363 if (!psoc) { 3364 reg_err("psoc is NULL"); 3365 return QDF_STATUS_E_INVAL; 3366 } 3367 3368 pdev_priv_obj = reg_get_pdev_obj(pdev); 3369 3370 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 3371 reg_err_rl("reg pdev priv obj is NULL"); 3372 return QDF_STATUS_E_FAILURE; 3373 } 3374 3375 if (unii_5g_bitmap && 3376 !reg_is_reg_unii_band_1_or_reg_unii_band_2a(unii_5g_bitmap)) { 3377 reg_err_rl("Invalid unii_5g_bitmap = %d", unii_5g_bitmap); 3378 return QDF_STATUS_E_FAILURE; 3379 } 3380 3381 if (pdev_priv_obj->unii_5g_bitmap == unii_5g_bitmap) { 3382 reg_debug_rl("UNII bitmask for 5G channels is already set %d", 3383 unii_5g_bitmap); 3384 return QDF_STATUS_SUCCESS; 3385 } 3386 3387 reg_debug_rl("Setting UNII bitmask for 5G: %d", unii_5g_bitmap); 3388 pdev_priv_obj->unii_5g_bitmap = unii_5g_bitmap; 3389 3390 reg_compute_pdev_current_chan_list(pdev_priv_obj); 3391 3392 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 3393 3394 if (reg_tx_ops->fill_umac_legacy_chanlist) { 3395 reg_tx_ops->fill_umac_legacy_chanlist(pdev, 3396 pdev_priv_obj->cur_chan_list); 3397 } 3398 3399 return QDF_STATUS_SUCCESS; 3400 } 3401 #endif 3402 3403 bool reg_is_chan_disabled(uint32_t chan_flags, enum channel_state chan_state) 3404 { 3405 return (REGULATORY_CHAN_DISABLED & chan_flags || 3406 chan_state == CHANNEL_STATE_DISABLE); 3407 } 3408 3409 #ifdef CONFIG_REG_CLIENT 3410 #ifdef CONFIG_BAND_6GHZ 3411 static void reg_append_6g_channel_list_with_power( 3412 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 3413 struct channel_power *ch_list, 3414 uint8_t *count, 3415 enum supported_6g_pwr_types in_6g_pwr_type) 3416 { 3417 struct super_chan_info *sc_entry; 3418 enum supported_6g_pwr_types pwr_type; 3419 uint8_t i, count_6g = *count; 3420 3421 pwr_type = in_6g_pwr_type; 3422 for (i = 0; i < NUM_6GHZ_CHANNELS; i++) { 3423 sc_entry = &pdev_priv_obj->super_chan_list[i]; 3424 3425 if (in_6g_pwr_type == REG_BEST_PWR_MODE) 3426 pwr_type = sc_entry->best_power_mode; 3427 3428 if (reg_is_supp_pwr_mode_invalid(pwr_type)) 3429 continue; 3430 3431 if (!reg_is_chan_disabled(sc_entry->chan_flags_arr[pwr_type], 3432 sc_entry->state_arr[pwr_type])) { 3433 ch_list[count_6g].center_freq = 3434 reg_ch_to_freq(i + MIN_6GHZ_CHANNEL); 3435 ch_list[count_6g].chan_num = 3436 reg_ch_num(i + MIN_6GHZ_CHANNEL); 3437 ch_list[count_6g++].tx_power = 3438 sc_entry->reg_chan_pwr[pwr_type].tx_power; 3439 } 3440 } 3441 *count = count_6g; 3442 } 3443 #else 3444 static inline void reg_append_6g_channel_list_with_power( 3445 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 3446 struct channel_power *ch_list, 3447 uint8_t *count, 3448 enum supported_6g_pwr_types in_6g_pwr_type) 3449 { 3450 } 3451 #endif 3452 3453 QDF_STATUS reg_get_channel_list_with_power( 3454 struct wlan_objmgr_pdev *pdev, 3455 struct channel_power *ch_list, 3456 uint8_t *num_chan, 3457 enum supported_6g_pwr_types in_6g_pwr_type) 3458 { 3459 uint8_t i, count; 3460 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 3461 uint8_t max_curr_num_chan; 3462 3463 if (!pdev) { 3464 reg_err_rl("invalid pdev"); 3465 return QDF_STATUS_E_INVAL; 3466 } 3467 3468 pdev_priv_obj = reg_get_pdev_obj(pdev); 3469 3470 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 3471 reg_err_rl("reg pdev priv obj is NULL"); 3472 return QDF_STATUS_E_INVAL; 3473 } 3474 3475 if (!num_chan || !ch_list) { 3476 reg_err("chan_list or num_ch is NULL"); 3477 return QDF_STATUS_E_FAILURE; 3478 } 3479 3480 *num_chan = 0; 3481 3482 if (in_6g_pwr_type == REG_CURRENT_PWR_MODE) 3483 max_curr_num_chan = NUM_CHANNELS; 3484 else 3485 max_curr_num_chan = MAX_5GHZ_CHANNEL; 3486 3487 for (i = 0, count = 0; i < max_curr_num_chan; i++) { 3488 if (!reg_is_chan_disabled( 3489 pdev_priv_obj->cur_chan_list[i].chan_flags, 3490 pdev_priv_obj->cur_chan_list[i].state)) { 3491 ch_list[count].center_freq = 3492 pdev_priv_obj->cur_chan_list[i].center_freq; 3493 ch_list[count].chan_num = 3494 pdev_priv_obj->cur_chan_list[i].chan_num; 3495 ch_list[count++].tx_power = 3496 pdev_priv_obj->cur_chan_list[i].tx_power; 3497 } 3498 } 3499 3500 if (in_6g_pwr_type == REG_CURRENT_PWR_MODE) { 3501 *num_chan = count; 3502 return QDF_STATUS_SUCCESS; 3503 } 3504 3505 reg_append_6g_channel_list_with_power(pdev_priv_obj, ch_list, &count, 3506 in_6g_pwr_type); 3507 *num_chan = count; 3508 3509 return QDF_STATUS_SUCCESS; 3510 } 3511 #endif 3512 3513 #ifdef CONFIG_CHAN_FREQ_API 3514 QDF_STATUS reg_get_channel_list_with_power_for_freq(struct wlan_objmgr_pdev 3515 *pdev, 3516 struct channel_power 3517 *ch_list, 3518 uint8_t *num_chan) 3519 { 3520 int i, count; 3521 struct regulatory_channel *reg_channels; 3522 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 3523 3524 if (!num_chan || !ch_list) { 3525 reg_err("chan_list or num_ch is NULL"); 3526 return QDF_STATUS_E_FAILURE; 3527 } 3528 3529 pdev_priv_obj = reg_get_pdev_obj(pdev); 3530 3531 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 3532 reg_err("reg pdev priv obj is NULL"); 3533 return QDF_STATUS_E_FAILURE; 3534 } 3535 3536 /* set the current channel list */ 3537 reg_channels = pdev_priv_obj->cur_chan_list; 3538 3539 for (i = 0, count = 0; i < NUM_CHANNELS; i++) { 3540 if (reg_channels[i].state && 3541 !(reg_channels[i].chan_flags & REGULATORY_CHAN_DISABLED)) { 3542 ch_list[count].center_freq = 3543 reg_channels[i].center_freq; 3544 ch_list[count].chan_num = reg_channels[i].chan_num; 3545 ch_list[count++].tx_power = 3546 reg_channels[i].tx_power; 3547 } 3548 } 3549 3550 *num_chan = count; 3551 3552 return QDF_STATUS_SUCCESS; 3553 } 3554 3555 enum channel_enum reg_get_chan_enum_for_freq(qdf_freq_t freq) 3556 { 3557 int16_t start = 0; 3558 int16_t end = NUM_CHANNELS - 1; 3559 3560 while (start <= end) { 3561 int16_t middle = (start + end) / 2; 3562 qdf_freq_t mid_freq_elem = channel_map[middle].center_freq; 3563 3564 if (freq == mid_freq_elem) 3565 return middle; 3566 if (freq > mid_freq_elem) 3567 start = middle + 1; 3568 else 3569 end = middle - 1; 3570 } 3571 3572 reg_debug_rl("invalid channel center frequency %d", freq); 3573 3574 return INVALID_CHANNEL; 3575 } 3576 3577 bool 3578 reg_is_freq_present_in_cur_chan_list(struct wlan_objmgr_pdev *pdev, 3579 qdf_freq_t freq) 3580 { 3581 enum channel_enum chan_enum; 3582 struct regulatory_channel *cur_chan_list; 3583 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 3584 3585 pdev_priv_obj = reg_get_pdev_obj(pdev); 3586 3587 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 3588 reg_err_rl("pdev reg obj is NULL"); 3589 return false; 3590 } 3591 3592 cur_chan_list = pdev_priv_obj->cur_chan_list; 3593 3594 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) 3595 if (cur_chan_list[chan_enum].center_freq == freq) 3596 if ((cur_chan_list[chan_enum].state != 3597 CHANNEL_STATE_DISABLE) && 3598 !(cur_chan_list[chan_enum].chan_flags & 3599 REGULATORY_CHAN_DISABLED)) 3600 return true; 3601 3602 reg_debug_rl("Channel center frequency %d not found", freq); 3603 3604 return false; 3605 } 3606 3607 #ifdef WLAN_FEATURE_GET_USABLE_CHAN_LIST 3608 /** 3609 * is_freq_present_in_resp_list() - is freq present in resp list 3610 * 3611 * @pcl_ch: pcl ch 3612 * @res_msg: Response msg 3613 * @count: no of usable channels 3614 * 3615 * Return: void 3616 */ 3617 static bool 3618 is_freq_present_in_resp_list(uint32_t pcl_ch, 3619 struct get_usable_chan_res_params *res_msg, 3620 int count) 3621 { 3622 int i; 3623 3624 for (i = 0; i < count; i++) { 3625 if (res_msg[i].freq == pcl_ch) 3626 return true; 3627 } 3628 return false; 3629 } 3630 3631 /** 3632 * reg_update_usable_chan_resp() - Update response msg 3633 * @pdev: Pointer to pdev 3634 * @res_msg: Response msg 3635 * @pcl_ch: pcl channel 3636 * @len: calculated pcl len 3637 * @iface_mode_mask: interface type 3638 * @band_mask: requested band mask 3639 * @count: no of usable channels 3640 * @in_6g_pwr_mode: Input 6GHz power mode 3641 * 3642 * Return: void 3643 */ 3644 static void 3645 reg_update_usable_chan_resp(struct wlan_objmgr_pdev *pdev, 3646 struct get_usable_chan_res_params *res_msg, 3647 uint32_t *pcl_ch, uint32_t len, 3648 uint32_t iface_mode_mask, 3649 uint32_t band_mask, int *count, 3650 enum supported_6g_pwr_types in_6g_pwr_mode) 3651 { 3652 int i; 3653 struct ch_params ch_params = {0}; 3654 int index = *count; 3655 3656 for (i = 0; i < len && index < NUM_CHANNELS; i++) { 3657 /* In case usable channels are required for multiple filter 3658 * mask, Some frequencies may present in res_msg . To avoid 3659 * frequency duplication, only mode mask is updated for 3660 * existing frequency. 3661 */ 3662 if (is_freq_present_in_resp_list(pcl_ch[i], res_msg, *count)) 3663 continue; 3664 3665 if (!(band_mask & 1 << wlan_reg_freq_to_band(pcl_ch[i]))) 3666 continue; 3667 3668 ch_params.ch_width = CH_WIDTH_MAX; 3669 reg_set_channel_params_for_pwrmode( 3670 pdev, 3671 pcl_ch[i], 3672 0, &ch_params, in_6g_pwr_mode, true); 3673 res_msg[index].freq = (qdf_freq_t)pcl_ch[i]; 3674 res_msg[index].iface_mode_mask |= 1 << iface_mode_mask; 3675 res_msg[index].bw = ch_params.ch_width; 3676 if (ch_params.center_freq_seg0) 3677 res_msg[index].seg0_freq = 3678 ch_params.center_freq_seg0; 3679 if (ch_params.center_freq_seg1) 3680 res_msg[index].seg1_freq = 3681 ch_params.center_freq_seg1; 3682 index++; 3683 } 3684 3685 *count = index; 3686 } 3687 3688 /** 3689 * reg_update_conn_chan_list() - Get usable channels with conn filter 3690 * and policy mgr mask 3691 * @pdev: Pointer to pdev 3692 * @res_msg: Response msg 3693 * @mode: policy mgr mode 3694 * @iftype: interface type 3695 * @band_mask: requested band mask 3696 * @count: no of usable channels 3697 * @in_6g_pwr_mode: Input 6GHz power mode 3698 * 3699 * Return: qdf status 3700 */ 3701 static QDF_STATUS 3702 reg_update_conn_chan_list(struct wlan_objmgr_pdev *pdev, 3703 struct get_usable_chan_res_params *res_msg, 3704 enum policy_mgr_con_mode mode, 3705 uint32_t iftype, 3706 uint32_t band_mask, 3707 uint32_t *count, 3708 enum supported_6g_pwr_types in_6g_pwr_mode) 3709 { 3710 uint32_t *pcl_ch; 3711 uint8_t *weight_list; 3712 uint32_t len; 3713 uint32_t weight_len; 3714 struct wlan_objmgr_psoc *psoc; 3715 QDF_STATUS status = QDF_STATUS_SUCCESS; 3716 3717 pcl_ch = qdf_mem_malloc(NUM_CHANNELS * 3718 sizeof(uint32_t)); 3719 3720 if (!pcl_ch) { 3721 reg_err("pcl_ch invalid"); 3722 return QDF_STATUS_E_FAILURE; 3723 } 3724 3725 weight_list = qdf_mem_malloc(NUM_CHANNELS * 3726 sizeof(uint8_t)); 3727 3728 if (!weight_list) { 3729 reg_err("weight_list invalid"); 3730 qdf_mem_free(pcl_ch); 3731 return QDF_STATUS_E_FAILURE; 3732 } 3733 3734 psoc = wlan_pdev_get_psoc(pdev); 3735 if (!psoc) { 3736 reg_err("invalid psoc"); 3737 status = QDF_STATUS_E_FAILURE; 3738 goto err; 3739 } 3740 3741 len = NUM_CHANNELS; 3742 weight_len = NUM_CHANNELS; 3743 3744 status = policy_mgr_get_pcl(psoc, mode, pcl_ch, &len, 3745 weight_list, weight_len, 3746 WLAN_INVALID_VDEV_ID); 3747 if (QDF_IS_STATUS_ERROR(status)) { 3748 reg_err("get pcl failed for mode: %d", mode); 3749 goto err; 3750 } 3751 reg_update_usable_chan_resp(pdev, res_msg, pcl_ch, len, 3752 iftype, band_mask, count, 3753 in_6g_pwr_mode); 3754 err: 3755 qdf_mem_free(pcl_ch); 3756 qdf_mem_free(weight_list); 3757 return status; 3758 } 3759 3760 /** 3761 * reg_get_usable_channel_con_filter() - Get usable channel with con filter mask 3762 * @pdev: Pointer to pdev 3763 * @req_msg: Request msg 3764 * @res_msg: Response msg 3765 * @count: no of usable channels 3766 * @in_6g_pwr_mode: Input 6GHz power mode 3767 * 3768 * Return: qdf status 3769 */ 3770 static QDF_STATUS 3771 reg_get_usable_channel_con_filter(struct wlan_objmgr_pdev *pdev, 3772 struct get_usable_chan_req_params req_msg, 3773 struct get_usable_chan_res_params *res_msg, 3774 int *count, 3775 enum supported_6g_pwr_types in_6g_pwr_mode) 3776 { 3777 QDF_STATUS status = QDF_STATUS_SUCCESS; 3778 uint32_t iface_mode_mask = req_msg.iface_mode_mask; 3779 3780 while (iface_mode_mask) { 3781 if (iface_mode_mask & 1 << IFTYPE_AP) { 3782 status = 3783 reg_update_conn_chan_list(pdev, res_msg, PM_SAP_MODE, 3784 IFTYPE_AP, req_msg.band_mask, 3785 count, in_6g_pwr_mode); 3786 iface_mode_mask &= ~(1 << IFTYPE_AP); 3787 } else if (iface_mode_mask & 1 << IFTYPE_STATION) { 3788 status = 3789 reg_update_conn_chan_list(pdev, res_msg, PM_STA_MODE, 3790 IFTYPE_STATION, 3791 req_msg.band_mask, count, 3792 in_6g_pwr_mode); 3793 iface_mode_mask &= ~(1 << IFTYPE_STATION); 3794 } else if (iface_mode_mask & 1 << IFTYPE_P2P_GO) { 3795 status = 3796 reg_update_conn_chan_list(pdev, res_msg, PM_P2P_GO_MODE, 3797 IFTYPE_P2P_GO, 3798 req_msg.band_mask, count, 3799 in_6g_pwr_mode); 3800 iface_mode_mask &= ~(1 << IFTYPE_P2P_GO); 3801 } else if (iface_mode_mask & 1 << IFTYPE_P2P_CLIENT) { 3802 status = 3803 reg_update_conn_chan_list(pdev, res_msg, 3804 PM_P2P_CLIENT_MODE, 3805 IFTYPE_P2P_CLIENT, 3806 req_msg.band_mask, count, 3807 in_6g_pwr_mode); 3808 iface_mode_mask &= ~(1 << IFTYPE_P2P_CLIENT); 3809 } else if (iface_mode_mask & 1 << IFTYPE_NAN) { 3810 status = 3811 reg_update_conn_chan_list(pdev, res_msg, 3812 PM_NAN_DISC_MODE, IFTYPE_NAN, 3813 req_msg.band_mask, count, 3814 in_6g_pwr_mode); 3815 iface_mode_mask &= ~(1 << IFTYPE_NAN); 3816 } else { 3817 reg_err("invalid mode"); 3818 break; 3819 } 3820 } 3821 return status; 3822 } 3823 3824 /** 3825 * reg_remove_freq() - Remove invalid freq 3826 * @res_msg: Response msg 3827 * @index: index of freq that needs to be removed 3828 * 3829 * Return: void 3830 */ 3831 static void 3832 reg_remove_freq(struct get_usable_chan_res_params *res_msg, 3833 int index) 3834 { 3835 reg_debug("removing freq %d", res_msg[index].freq); 3836 qdf_mem_zero(&res_msg[index], 3837 sizeof(struct get_usable_chan_res_params)); 3838 } 3839 3840 /** 3841 * reg_skip_invalid_chan_freq() - Remove invalid freq for SAP, P2P GO 3842 * and NAN 3843 * @pdev: Pointer to pdev 3844 * @res_msg: Response msg 3845 * @no_usable_channels: no of usable channels 3846 * @iface_mode_mask: interface mode mask 3847 * 3848 * Return: qdf status 3849 */ 3850 static QDF_STATUS 3851 reg_skip_invalid_chan_freq(struct wlan_objmgr_pdev *pdev, 3852 struct get_usable_chan_res_params *res_msg, 3853 uint32_t *no_usable_channels, 3854 uint32_t iface_mode_mask) 3855 { 3856 uint32_t chan_enum, iface_mode = 0; 3857 QDF_STATUS status = QDF_STATUS_SUCCESS; 3858 bool include_indoor_channel, dfs_master_capable; 3859 uint8_t enable_srd_chan, srd_mask = 0; 3860 struct wlan_objmgr_psoc *psoc; 3861 psoc = wlan_pdev_get_psoc(pdev); 3862 if (!psoc) { 3863 reg_err("invalid psoc"); 3864 return QDF_STATUS_E_FAILURE; 3865 } 3866 3867 status = ucfg_mlme_get_indoor_channel_support(psoc, 3868 &include_indoor_channel); 3869 if (QDF_IS_STATUS_ERROR(status)) { 3870 reg_err("failed to get indoor channel skip info"); 3871 return QDF_STATUS_E_FAILURE; 3872 } 3873 3874 ucfg_mlme_get_etsi_srd_chan_in_master_mode(psoc, 3875 &enable_srd_chan); 3876 if (QDF_IS_STATUS_ERROR(status)) { 3877 reg_err("failed to get srd chan info"); 3878 return QDF_STATUS_E_FAILURE; 3879 } 3880 3881 status = ucfg_mlme_get_dfs_master_capability(psoc, &dfs_master_capable); 3882 if (QDF_IS_STATUS_ERROR(status)) { 3883 reg_err("failed to get dfs master capable"); 3884 return status; 3885 } 3886 3887 while (iface_mode_mask) { 3888 if (iface_mode_mask & (1 << IFTYPE_AP)) { 3889 srd_mask = 1; 3890 iface_mode = 1 << IFTYPE_AP; 3891 } else if (iface_mode_mask & (1 << IFTYPE_P2P_GO)) { 3892 srd_mask = 2; 3893 iface_mode = 1 << IFTYPE_P2P_GO; 3894 } else if (iface_mode_mask & (1 << IFTYPE_NAN)) { 3895 iface_mode = 1 << IFTYPE_NAN; 3896 } else { 3897 break; 3898 } 3899 for (chan_enum = 0; chan_enum < *no_usable_channels; 3900 chan_enum++) { 3901 if (iface_mode_mask & (1 << IFTYPE_NAN)) { 3902 if (!wlan_is_nan_allowed_on_freq(pdev, 3903 res_msg[chan_enum].freq)) 3904 res_msg[chan_enum].iface_mode_mask &= 3905 ~(iface_mode); 3906 if (!res_msg[chan_enum].iface_mode_mask) 3907 reg_remove_freq(res_msg, chan_enum); 3908 } else { 3909 if (wlan_reg_is_freq_indoor( 3910 pdev, res_msg[chan_enum].freq) && 3911 !include_indoor_channel) { 3912 res_msg[chan_enum].iface_mode_mask &= 3913 ~(iface_mode); 3914 if (!res_msg[chan_enum].iface_mode_mask) 3915 reg_remove_freq(res_msg, 3916 chan_enum); 3917 } 3918 3919 if (!(enable_srd_chan & srd_mask) && 3920 reg_is_etsi_srd_chan_for_freq( 3921 pdev, res_msg[chan_enum].freq)) { 3922 res_msg[chan_enum].iface_mode_mask &= 3923 ~(iface_mode); 3924 if (!res_msg[chan_enum].iface_mode_mask) 3925 reg_remove_freq(res_msg, 3926 chan_enum); 3927 } 3928 3929 if (!dfs_master_capable && 3930 wlan_reg_is_dfs_for_freq(pdev, 3931 res_msg[chan_enum].freq)) { 3932 res_msg[chan_enum].iface_mode_mask &= 3933 ~(iface_mode); 3934 if (!res_msg[chan_enum].iface_mode_mask) 3935 reg_remove_freq(res_msg, 3936 chan_enum); 3937 } 3938 } 3939 } 3940 3941 iface_mode_mask &= ~iface_mode; 3942 } 3943 3944 return status; 3945 } 3946 3947 /** 3948 * reg_get_usable_channel_no_filter() - Get usable channel with no filter mask 3949 * @pdev: Pointer to pdev 3950 * @req_msg: Request msg 3951 * @res_msg: Response msg 3952 * @chan_list: reg channel list 3953 * @count: no of usable channels 3954 * 3955 * Return: qdf status 3956 */ 3957 static QDF_STATUS 3958 reg_get_usable_channel_no_filter(struct wlan_objmgr_pdev *pdev, 3959 struct get_usable_chan_req_params req_msg, 3960 struct get_usable_chan_res_params *res_msg, 3961 struct regulatory_channel *chan_list, 3962 int *count) 3963 { 3964 QDF_STATUS status = QDF_STATUS_SUCCESS; 3965 3966 status = 3967 reg_skip_invalid_chan_freq(pdev, res_msg, 3968 count, req_msg.iface_mode_mask); 3969 return status; 3970 } 3971 3972 /** 3973 * reg_get_usable_channel_coex_filter() - Get usable channel with coex filter 3974 * @pdev: Pointer to pdev 3975 * @req_msg: Request msg 3976 * @res_msg: Response msg 3977 * @chan_list: reg channel list 3978 * @count: no of usable channels 3979 * 3980 * Return: qdf status 3981 */ 3982 static QDF_STATUS 3983 reg_get_usable_channel_coex_filter(struct wlan_objmgr_pdev *pdev, 3984 struct get_usable_chan_req_params req_msg, 3985 struct get_usable_chan_res_params *res_msg, 3986 struct regulatory_channel *chan_list, 3987 int *count) 3988 { 3989 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 3990 enum channel_enum chan_enum; 3991 uint32_t i = 0; 3992 struct ch_avoid_freq_type freq_range; 3993 struct wlan_objmgr_psoc *psoc; 3994 QDF_STATUS status = QDF_STATUS_SUCCESS; 3995 3996 psoc = wlan_pdev_get_psoc(pdev); 3997 if (!psoc) { 3998 reg_err("invalid psoc"); 3999 return QDF_STATUS_E_FAILURE; 4000 } 4001 4002 psoc_priv_obj = reg_get_psoc_obj(psoc); 4003 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 4004 reg_alert("psoc reg component is NULL"); 4005 return QDF_STATUS_E_FAILURE; 4006 } 4007 for (chan_enum = 0; chan_enum < *count; chan_enum++) { 4008 for (i = 0; i < 4009 psoc_priv_obj->avoid_freq_list.ch_avoid_range_cnt; i++) { 4010 freq_range = 4011 psoc_priv_obj->avoid_freq_list.avoid_freq_range[i]; 4012 4013 if (freq_range.start_freq <= 4014 chan_list[chan_enum].center_freq && 4015 freq_range.end_freq >= 4016 chan_list[chan_enum].center_freq) { 4017 reg_debug("avoid freq %d", 4018 chan_list[chan_enum].center_freq); 4019 reg_remove_freq(res_msg, chan_enum); 4020 } 4021 } 4022 } 4023 if (req_msg.iface_mode_mask & 1 << IFTYPE_AP || 4024 req_msg.iface_mode_mask & 1 << IFTYPE_P2P_GO || 4025 req_msg.iface_mode_mask & 1 << IFTYPE_NAN) 4026 status = 4027 reg_skip_invalid_chan_freq(pdev, res_msg, count, 4028 req_msg.iface_mode_mask); 4029 return status; 4030 } 4031 4032 /** 4033 * reg_calculate_mode_mask() - calculate valid mode mask 4034 * @iface_mode_mask: interface mode mask 4035 * 4036 * Return: Valid mode mask 4037 */ 4038 static uint32_t 4039 reg_calculate_mode_mask(uint32_t iface_mode_mask) 4040 { 4041 int mode_mask = 0; 4042 4043 mode_mask = (iface_mode_mask & 1 << IFTYPE_STATION) | 4044 (iface_mode_mask & 1 << IFTYPE_AP) | 4045 (iface_mode_mask & 1 << IFTYPE_P2P_GO) | 4046 (iface_mode_mask & 1 << IFTYPE_P2P_CLIENT) | 4047 (iface_mode_mask & 1 << IFTYPE_P2P_DEVICE) | 4048 (iface_mode_mask & 1 << IFTYPE_NAN); 4049 4050 return mode_mask; 4051 } 4052 4053 /** 4054 * reg_add_usable_channel_to_resp() - Add usable channels to resp structure 4055 * @pdev: Pointer to pdev 4056 * @res_msg: Response msg 4057 * @iface_mode_mask: interface mode mask 4058 * @chan_list: reg channel list 4059 * @count: no of usable channels 4060 * @in_6g_pwr_mode: Input 6GHz power mode 4061 * 4062 * Return: qdf status 4063 */ 4064 static QDF_STATUS 4065 reg_add_usable_channel_to_resp(struct wlan_objmgr_pdev *pdev, 4066 struct get_usable_chan_res_params *res_msg, 4067 uint32_t iface_mode_mask, 4068 struct regulatory_channel *chan_list, 4069 int *count, 4070 enum supported_6g_pwr_types in_6g_pwr_mode) 4071 { 4072 enum channel_enum chan_enum; 4073 struct ch_params ch_params = {0}; 4074 QDF_STATUS status = QDF_STATUS_SUCCESS; 4075 uint32_t mode_mask = 0; 4076 4077 mode_mask = reg_calculate_mode_mask(iface_mode_mask); 4078 4079 for (chan_enum = 0; chan_enum < *count && 4080 chan_enum < NUM_CHANNELS; chan_enum++) { 4081 ch_params.ch_width = CH_WIDTH_MAX; 4082 reg_set_channel_params_for_pwrmode( 4083 pdev, 4084 chan_list[chan_enum].center_freq, 4085 chan_list[chan_enum].max_bw, &ch_params, 4086 in_6g_pwr_mode, true); 4087 4088 res_msg[chan_enum].freq = chan_list[chan_enum].center_freq; 4089 res_msg[chan_enum].iface_mode_mask = mode_mask; 4090 if (!res_msg[chan_enum].iface_mode_mask) { 4091 reg_err("invalid iface mask"); 4092 return QDF_STATUS_E_FAILURE; 4093 } 4094 res_msg[chan_enum].bw = ch_params.ch_width; 4095 res_msg[chan_enum].state = chan_list[chan_enum].state; 4096 if (ch_params.center_freq_seg0) 4097 res_msg[chan_enum].seg0_freq = 4098 ch_params.center_freq_seg0; 4099 if (ch_params.center_freq_seg1) 4100 res_msg[chan_enum].seg1_freq = 4101 ch_params.center_freq_seg1; 4102 } 4103 4104 return status; 4105 } 4106 4107 QDF_STATUS 4108 wlan_reg_get_usable_channel(struct wlan_objmgr_pdev *pdev, 4109 struct get_usable_chan_req_params req_msg, 4110 struct get_usable_chan_res_params *res_msg, 4111 uint32_t *usable_channels, 4112 enum supported_6g_pwr_types in_6g_pwr_mode) 4113 { 4114 struct regulatory_channel *chan_list; 4115 QDF_STATUS status = QDF_STATUS_SUCCESS; 4116 4117 chan_list = qdf_mem_malloc(NUM_CHANNELS * 4118 sizeof(*chan_list)); 4119 4120 if (!chan_list) { 4121 reg_err("chan_list invalid"); 4122 return QDF_STATUS_E_FAILURE; 4123 } 4124 4125 if ((req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX) || 4126 (!(req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX) && 4127 !(req_msg.filter_mask & 1 << FILTER_WLAN_CONCURRENCY))) { 4128 *usable_channels = reg_get_band_channel_list(pdev, 4129 req_msg.band_mask, 4130 chan_list); 4131 status = 4132 reg_add_usable_channel_to_resp(pdev, res_msg, 4133 req_msg.iface_mode_mask, 4134 chan_list, usable_channels, 4135 in_6g_pwr_mode); 4136 if (QDF_IS_STATUS_ERROR(status)) { 4137 qdf_mem_free(chan_list); 4138 return status; 4139 } 4140 } 4141 4142 if (req_msg.filter_mask & 1 << FILTER_WLAN_CONCURRENCY) 4143 status = 4144 reg_get_usable_channel_con_filter(pdev, req_msg, res_msg, 4145 usable_channels, 4146 in_6g_pwr_mode); 4147 4148 if (req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX) 4149 status = 4150 reg_get_usable_channel_coex_filter(pdev, req_msg, res_msg, 4151 chan_list, usable_channels); 4152 if (!(req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX) && 4153 !(req_msg.filter_mask & 1 << FILTER_WLAN_CONCURRENCY)) 4154 status = 4155 reg_get_usable_channel_no_filter(pdev, req_msg, res_msg, 4156 chan_list, usable_channels); 4157 reg_debug("usable chan count is %d", *usable_channels); 4158 4159 qdf_mem_free(chan_list); 4160 return status; 4161 } 4162 #endif 4163 4164 /** 4165 * reg_get_nol_channel_state() - Get channel state from regulatory 4166 * and treat NOL channels as enabled channels 4167 * @pdev: Pointer to pdev 4168 * @freq: channel center frequency. 4169 * @in_6g_pwr_mode: Input 6 GHz power mode 4170 * 4171 * Return: channel state 4172 */ 4173 static enum channel_state 4174 reg_get_nol_channel_state(struct wlan_objmgr_pdev *pdev, 4175 qdf_freq_t freq, 4176 enum supported_6g_pwr_types in_6g_pwr_mode) 4177 { 4178 enum channel_enum ch_idx; 4179 enum channel_state chan_state; 4180 4181 ch_idx = reg_get_chan_enum_for_freq(freq); 4182 4183 if (reg_is_chan_enum_invalid(ch_idx)) 4184 return CHANNEL_STATE_INVALID; 4185 4186 chan_state = reg_get_chan_state(pdev, ch_idx, in_6g_pwr_mode, false); 4187 4188 return chan_state; 4189 } 4190 4191 /** 4192 * reg_get_5g_bonded_chan_state()- Return the channel state for a 4193 * 5G or 6G channel frequency based on the bonded channel. 4194 * @pdev: Pointer to pdev. 4195 * @freq: Channel center frequency. 4196 * @bonded_chan_ptr: Pointer to bonded_channel_freq. 4197 * @in_6g_pwr_mode: Input 6 GHz power mode 4198 * @input_punc_bitmap: input puncture bitmap 4199 * 4200 * Return: Channel State 4201 */ 4202 static enum channel_state 4203 reg_get_5g_bonded_chan_state(struct wlan_objmgr_pdev *pdev, 4204 uint16_t freq, 4205 const struct bonded_channel_freq *bonded_chan_ptr, 4206 enum supported_6g_pwr_types in_6g_pwr_mode, 4207 uint16_t input_punc_bitmap) 4208 { 4209 uint16_t chan_cfreq; 4210 enum channel_state chan_state = CHANNEL_STATE_INVALID; 4211 enum channel_state temp_chan_state; 4212 uint8_t i = 0; 4213 4214 chan_cfreq = bonded_chan_ptr->start_freq; 4215 while (chan_cfreq <= bonded_chan_ptr->end_freq) { 4216 if (!reg_is_chan_bit_punctured(input_punc_bitmap, i)) { 4217 temp_chan_state = 4218 reg_get_nol_channel_state(pdev, chan_cfreq, 4219 in_6g_pwr_mode); 4220 if (temp_chan_state < chan_state) 4221 chan_state = temp_chan_state; 4222 } 4223 chan_cfreq = chan_cfreq + 20; 4224 i++; 4225 } 4226 4227 return chan_state; 4228 } 4229 4230 enum channel_state 4231 reg_get_5g_chan_state(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq, 4232 enum phy_ch_width bw, 4233 enum supported_6g_pwr_types in_6g_pwr_mode, 4234 uint16_t input_punc_bitmap) 4235 { 4236 enum channel_enum ch_indx; 4237 enum channel_state chan_state; 4238 bool bw_enabled = false; 4239 const struct bonded_channel_freq *bonded_chan_ptr = NULL; 4240 uint16_t min_bw, max_bw; 4241 4242 if (bw > CH_WIDTH_80P80MHZ) { 4243 reg_err_rl("bw passed is not good"); 4244 return CHANNEL_STATE_INVALID; 4245 } 4246 4247 if (bw == CH_WIDTH_20MHZ) 4248 return reg_get_nol_channel_state(pdev, freq, in_6g_pwr_mode); 4249 4250 /* Fetch the bonded_chan_ptr for width greater than 20MHZ. */ 4251 bonded_chan_ptr = reg_get_bonded_chan_entry(freq, bw, 0); 4252 4253 if (!bonded_chan_ptr) 4254 return CHANNEL_STATE_INVALID; 4255 4256 chan_state = reg_get_5g_bonded_chan_state(pdev, freq, bonded_chan_ptr, 4257 in_6g_pwr_mode, 4258 input_punc_bitmap); 4259 4260 if ((chan_state == CHANNEL_STATE_INVALID) || 4261 (chan_state == CHANNEL_STATE_DISABLE)) 4262 return chan_state; 4263 4264 ch_indx = reg_get_chan_enum_for_freq(freq); 4265 if (reg_is_chan_enum_invalid(ch_indx)) 4266 return CHANNEL_STATE_INVALID; 4267 4268 if (reg_get_min_max_bw_reg_chan_list(pdev, ch_indx, in_6g_pwr_mode, 4269 &min_bw, &max_bw)) { 4270 return CHANNEL_STATE_INVALID; 4271 } 4272 4273 if (bw == CH_WIDTH_5MHZ) 4274 bw_enabled = true; 4275 else if (bw == CH_WIDTH_10MHZ) 4276 bw_enabled = (min_bw <= 10) && 4277 (max_bw >= 10); 4278 else if (bw == CH_WIDTH_20MHZ) 4279 bw_enabled = (min_bw <= 20) && 4280 (max_bw >= 20); 4281 else if (bw == CH_WIDTH_40MHZ) 4282 bw_enabled = (min_bw <= 40) && 4283 (max_bw >= 40); 4284 else if (bw == CH_WIDTH_80MHZ) 4285 bw_enabled = (min_bw <= 80) && 4286 (max_bw >= 80); 4287 else if (bw == CH_WIDTH_160MHZ) 4288 bw_enabled = (min_bw <= 160) && 4289 (max_bw >= 160); 4290 else if (bw == CH_WIDTH_80P80MHZ) 4291 bw_enabled = (min_bw <= 80) && 4292 (max_bw >= 80); 4293 4294 if (bw_enabled) 4295 return chan_state; 4296 else 4297 return CHANNEL_STATE_DISABLE; 4298 } 4299 4300 enum channel_state 4301 reg_get_ch_state_based_on_nol_flag(struct wlan_objmgr_pdev *pdev, 4302 qdf_freq_t freq, 4303 struct ch_params *ch_params, 4304 enum supported_6g_pwr_types 4305 in_6g_pwr_mode, 4306 bool treat_nol_chan_as_disabled) 4307 { 4308 uint16_t input_punc_bitmap = reg_fetch_punc_bitmap(ch_params); 4309 4310 if (treat_nol_chan_as_disabled) 4311 return wlan_reg_get_5g_bonded_channel_state_for_pwrmode(pdev, 4312 freq, 4313 ch_params, 4314 in_6g_pwr_mode); 4315 4316 return reg_get_5g_chan_state(pdev, freq, ch_params->ch_width, 4317 in_6g_pwr_mode, 4318 input_punc_bitmap); 4319 } 4320 4321 #ifdef WLAN_FEATURE_11BE 4322 bool reg_is_ch_width_320(enum phy_ch_width ch_width) 4323 { 4324 if (ch_width == CH_WIDTH_320MHZ) 4325 return true; 4326 return false; 4327 } 4328 #else 4329 bool reg_is_ch_width_320(enum phy_ch_width ch_width) 4330 { 4331 return false; 4332 } 4333 #endif 4334 4335 #ifdef CONFIG_REG_6G_PWRMODE 4336 enum channel_state 4337 reg_get_channel_state_for_pwrmode(struct wlan_objmgr_pdev *pdev, 4338 qdf_freq_t freq, 4339 enum supported_6g_pwr_types in_6g_pwr_type) 4340 { 4341 enum channel_enum ch_idx; 4342 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4343 enum channel_state state; 4344 4345 ch_idx = reg_get_chan_enum_for_freq(freq); 4346 4347 if (reg_is_chan_enum_invalid(ch_idx)) 4348 return CHANNEL_STATE_INVALID; 4349 4350 pdev_priv_obj = reg_get_pdev_obj(pdev); 4351 4352 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4353 reg_err("pdev reg obj is NULL"); 4354 return CHANNEL_STATE_INVALID; 4355 } 4356 4357 state = reg_get_chan_state(pdev, ch_idx, in_6g_pwr_type, true); 4358 return state; 4359 } 4360 #endif 4361 4362 static uint32_t reg_get_channel_flags_for_freq(struct wlan_objmgr_pdev *pdev, 4363 qdf_freq_t freq) 4364 { 4365 enum channel_enum chan_enum; 4366 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4367 4368 chan_enum = reg_get_chan_enum_for_freq(freq); 4369 4370 if (reg_is_chan_enum_invalid(chan_enum)) { 4371 reg_debug("chan freq is not valid"); 4372 return REGULATORY_CHAN_INVALID; 4373 } 4374 4375 pdev_priv_obj = reg_get_pdev_obj(pdev); 4376 4377 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4378 reg_debug("pdev reg obj is NULL"); 4379 return REGULATORY_CHAN_INVALID; 4380 } 4381 4382 return pdev_priv_obj->cur_chan_list[chan_enum].chan_flags; 4383 } 4384 4385 #ifdef CONFIG_REG_CLIENT 4386 enum channel_state reg_get_channel_state_from_secondary_list_for_freq( 4387 struct wlan_objmgr_pdev *pdev, 4388 qdf_freq_t freq) 4389 { 4390 enum channel_enum ch_idx; 4391 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4392 4393 ch_idx = reg_get_chan_enum_for_freq(freq); 4394 4395 if (reg_is_chan_enum_invalid(ch_idx)) 4396 return CHANNEL_STATE_INVALID; 4397 4398 pdev_priv_obj = reg_get_pdev_obj(pdev); 4399 4400 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4401 reg_err("pdev reg obj is NULL"); 4402 return CHANNEL_STATE_INVALID; 4403 } 4404 4405 return pdev_priv_obj->secondary_cur_chan_list[ch_idx].state; 4406 } 4407 4408 static uint32_t reg_get_channel_flags_from_secondary_list_for_freq( 4409 struct wlan_objmgr_pdev *pdev, 4410 qdf_freq_t freq) 4411 { 4412 enum channel_enum chan_enum; 4413 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4414 4415 chan_enum = reg_get_chan_enum_for_freq(freq); 4416 4417 if (reg_is_chan_enum_invalid(chan_enum)) { 4418 reg_err_rl("chan freq %u is not valid", freq); 4419 return REGULATORY_CHAN_INVALID; 4420 } 4421 4422 pdev_priv_obj = reg_get_pdev_obj(pdev); 4423 4424 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4425 reg_err("pdev reg obj is NULL"); 4426 return REGULATORY_CHAN_INVALID; 4427 } 4428 4429 return pdev_priv_obj->secondary_cur_chan_list[chan_enum].chan_flags; 4430 } 4431 4432 #ifdef CONFIG_BAND_6GHZ 4433 /** 4434 * reg_get_psd_power() - Function to get PSD power for 6 GHz channel 4435 * @chan: Pointer to channel object 4436 * @is_psd: Pointer to whether it is PSD power 4437 * 4438 * Return: Channel PSD power value if it is PSD type. 4439 */ 4440 static uint16_t reg_get_psd_power(struct regulatory_channel *chan, bool *is_psd) 4441 { 4442 if (is_psd) 4443 *is_psd = chan->psd_flag; 4444 return chan->psd_eirp; 4445 } 4446 #else 4447 static uint16_t reg_get_psd_power(struct regulatory_channel *chan, bool *is_psd) 4448 { 4449 if (is_psd) 4450 *is_psd = false; 4451 return 0; 4452 } 4453 #endif 4454 4455 QDF_STATUS 4456 reg_get_channel_power_attr_from_secondary_list_for_freq( 4457 struct wlan_objmgr_pdev *pdev, 4458 qdf_freq_t freq, bool *is_psd, 4459 uint16_t *tx_power, uint16_t *psd_eirp, uint32_t *flags) 4460 { 4461 enum channel_enum chan_enum; 4462 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4463 struct regulatory_channel *chan; 4464 4465 if (!is_psd && !tx_power && !psd_eirp && !flags) { 4466 reg_err("all pointers null"); 4467 return QDF_STATUS_E_FAILURE; 4468 } 4469 4470 pdev_priv_obj = reg_get_pdev_obj(pdev); 4471 if (!pdev_priv_obj) { 4472 reg_err("pdev priv obj is NULL"); 4473 return QDF_STATUS_E_FAILURE; 4474 } 4475 4476 chan_enum = reg_get_chan_enum_for_freq(freq); 4477 if (chan_enum == INVALID_CHANNEL) { 4478 reg_err_rl("chan freq %u is not valid", freq); 4479 return QDF_STATUS_E_FAILURE; 4480 } 4481 4482 chan = &pdev_priv_obj->secondary_cur_chan_list[chan_enum]; 4483 4484 if (chan->state == CHANNEL_STATE_DISABLE || 4485 chan->state == CHANNEL_STATE_INVALID) { 4486 reg_err_rl("invalid channel state %d", chan->state); 4487 return QDF_STATUS_E_FAILURE; 4488 } 4489 4490 if (tx_power) 4491 *tx_power = chan->tx_power; 4492 if (psd_eirp) 4493 *psd_eirp = reg_get_psd_power(chan, is_psd); 4494 if (flags) 4495 *flags = chan->chan_flags; 4496 4497 return QDF_STATUS_SUCCESS; 4498 } 4499 4500 #ifdef CONFIG_BAND_6GHZ 4501 QDF_STATUS 4502 reg_decide_6ghz_power_within_bw_for_freq(struct wlan_objmgr_pdev *pdev, 4503 qdf_freq_t freq, enum phy_ch_width bw, 4504 bool *is_psd, uint16_t *min_tx_power, 4505 int16_t *min_psd_eirp, 4506 enum reg_6g_ap_type *power_type, 4507 enum supported_6g_pwr_types pwr_mode, 4508 uint16_t input_punc_bitmap) 4509 { 4510 const struct bonded_channel_freq *bonded_chan_ptr = NULL; 4511 enum channel_state state; 4512 qdf_freq_t start_freq; 4513 uint16_t tx_power, psd_eirp; 4514 uint32_t chan_flags, min_chan_flags = 0; 4515 bool first_time = true; 4516 4517 if (!reg_is_6ghz_chan_freq(freq)) 4518 return QDF_STATUS_E_INVAL; 4519 4520 if (!is_psd) { 4521 reg_err("is_psd pointer null"); 4522 return QDF_STATUS_E_INVAL; 4523 } 4524 if (!min_tx_power) { 4525 reg_err("min_tx_power pointer null"); 4526 return QDF_STATUS_E_INVAL; 4527 } 4528 if (!min_psd_eirp) { 4529 reg_err("min_psd_eirp pointer null"); 4530 return QDF_STATUS_E_INVAL; 4531 } 4532 if (!power_type) { 4533 reg_err("power_type pointer null"); 4534 return QDF_STATUS_E_INVAL; 4535 } 4536 4537 state = reg_get_5g_bonded_channel_for_pwrmode(pdev, 4538 freq, 4539 bw, 4540 &bonded_chan_ptr, 4541 pwr_mode, 4542 input_punc_bitmap); 4543 if (state != CHANNEL_STATE_ENABLE && 4544 state != CHANNEL_STATE_DFS) { 4545 reg_err("invalid channel state %d", state); 4546 return QDF_STATUS_E_INVAL; 4547 } 4548 4549 if (bw <= CH_WIDTH_20MHZ) { 4550 if (reg_get_channel_power_attr_from_secondary_list_for_freq( 4551 pdev, freq, is_psd, &tx_power, 4552 &psd_eirp, &chan_flags) != QDF_STATUS_SUCCESS) 4553 return QDF_STATUS_E_INVAL; 4554 *min_psd_eirp = (int16_t)psd_eirp; 4555 *min_tx_power = tx_power; 4556 min_chan_flags = chan_flags; 4557 goto decide_power_type; 4558 } 4559 4560 start_freq = bonded_chan_ptr->start_freq; 4561 while (start_freq <= bonded_chan_ptr->end_freq) { 4562 if (reg_get_channel_power_attr_from_secondary_list_for_freq( 4563 pdev, start_freq, is_psd, &tx_power, 4564 &psd_eirp, &chan_flags) != QDF_STATUS_SUCCESS) 4565 return QDF_STATUS_E_INVAL; 4566 4567 if (first_time) { 4568 *min_psd_eirp = (int16_t)psd_eirp; 4569 *min_tx_power = tx_power; 4570 min_chan_flags = chan_flags; 4571 first_time = false; 4572 } 4573 if ((int16_t)psd_eirp < *min_psd_eirp) 4574 *min_psd_eirp = (int16_t)psd_eirp; 4575 if (tx_power < *min_tx_power) 4576 *min_tx_power = tx_power; 4577 min_chan_flags |= (chan_flags & REGULATORY_CHAN_AFC); 4578 min_chan_flags |= (chan_flags & REGULATORY_CHAN_INDOOR_ONLY); 4579 start_freq += 20; 4580 } 4581 4582 decide_power_type: 4583 if ((min_chan_flags & REGULATORY_CHAN_AFC) && 4584 (min_chan_flags & REGULATORY_CHAN_INDOOR_ONLY)) 4585 *power_type = REG_INDOOR_AP; 4586 else if (min_chan_flags & REGULATORY_CHAN_AFC) 4587 *power_type = REG_STANDARD_POWER_AP; 4588 else if (min_chan_flags & REGULATORY_CHAN_INDOOR_ONLY) 4589 *power_type = REG_INDOOR_AP; 4590 else 4591 *power_type = REG_VERY_LOW_POWER_AP; 4592 4593 return QDF_STATUS_SUCCESS; 4594 } 4595 #endif 4596 #endif 4597 4598 /** 4599 * reg_get_5g_bonded_chan_array_for_pwrmode()- Return the channel state for a 4600 * 5G or 6G channel frequency based on the bonded channel. 4601 * @pdev: Pointer to pdev. 4602 * @freq: Channel center frequency. 4603 * @bonded_chan_ptr: Pointer to bonded_channel_freq. 4604 * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based 4605 * channel list will be chosen. 4606 * @input_punc_bitmap: Input puncture bitmap 4607 * 4608 * Return: Channel State 4609 */ 4610 static enum channel_state 4611 reg_get_5g_bonded_chan_array_for_pwrmode(struct wlan_objmgr_pdev *pdev, 4612 uint16_t freq, 4613 const struct bonded_channel_freq * 4614 bonded_chan_ptr, 4615 enum supported_6g_pwr_types 4616 in_6g_pwr_type, 4617 uint16_t input_punc_bitmap) 4618 { 4619 uint16_t chan_cfreq; 4620 enum channel_state chan_state = CHANNEL_STATE_INVALID; 4621 enum channel_state temp_chan_state; 4622 uint8_t i = 0; 4623 4624 if (!bonded_chan_ptr) { 4625 reg_debug("bonded chan ptr is NULL"); 4626 return chan_state; 4627 } 4628 4629 chan_cfreq = bonded_chan_ptr->start_freq; 4630 while (chan_cfreq <= bonded_chan_ptr->end_freq) { 4631 if (!reg_is_chan_bit_punctured(input_punc_bitmap, i)) { 4632 temp_chan_state = 4633 reg_get_channel_state_for_pwrmode(pdev, 4634 chan_cfreq, 4635 in_6g_pwr_type); 4636 if (temp_chan_state < chan_state) 4637 chan_state = temp_chan_state; 4638 } 4639 chan_cfreq = chan_cfreq + 20; 4640 i++; 4641 } 4642 4643 return chan_state; 4644 } 4645 4646 #ifdef WLAN_FEATURE_11BE 4647 4648 QDF_STATUS reg_extract_puncture_by_bw(enum phy_ch_width ori_bw, 4649 uint16_t ori_puncture_bitmap, 4650 qdf_freq_t freq, 4651 qdf_freq_t cen320_freq, 4652 enum phy_ch_width new_bw, 4653 uint16_t *new_puncture_bitmap) 4654 { 4655 const struct bonded_channel_freq *ori_bonded_chan; 4656 const struct bonded_channel_freq *new_bonded_chan; 4657 uint16_t chan_cfreq; 4658 uint16_t new_bit; 4659 4660 if (ori_bw < new_bw) { 4661 reg_err_rl("freq %d, ori bw %d can't be smaller than new bw %d", 4662 freq, ori_bw, new_bw); 4663 return QDF_STATUS_E_FAILURE; 4664 } 4665 4666 if (ori_bw == new_bw) { 4667 *new_puncture_bitmap = ori_puncture_bitmap; 4668 return QDF_STATUS_SUCCESS; 4669 } 4670 4671 ori_bonded_chan = reg_get_bonded_chan_entry(freq, ori_bw, cen320_freq); 4672 new_bonded_chan = reg_get_bonded_chan_entry(freq, new_bw, 0); 4673 if (!ori_bonded_chan) { 4674 reg_err_rl("bonded chan fails, freq %d, ori bw %d, new bw %d", 4675 freq, ori_bw, new_bw); 4676 return QDF_STATUS_E_FAILURE; 4677 } 4678 4679 new_bit = 0; 4680 *new_puncture_bitmap = 0; 4681 chan_cfreq = ori_bonded_chan->start_freq; 4682 while (chan_cfreq <= ori_bonded_chan->end_freq) { 4683 /* 4684 * If the "new_bw" is 20, then new_bonded_chan = NULL and the 4685 * output puncturing bitmap (*new_puncture_bitmap) as per spec 4686 * should be 0. However, if the "ori_puncture_bitmap" has 4687 * punctured the primary channel (the only channel in 20Mhz 4688 * case), then the output "(*ori_puncture_bitmap) should contain 4689 * the same so that the caller can recognize the error in the 4690 * input pattern. 4691 */ 4692 if (freq == chan_cfreq || 4693 (new_bonded_chan && 4694 chan_cfreq >= new_bonded_chan->start_freq && 4695 chan_cfreq <= new_bonded_chan->end_freq)) { 4696 /* this frequency is in new bw */ 4697 *new_puncture_bitmap |= 4698 (ori_puncture_bitmap & 1) << new_bit; 4699 new_bit++; 4700 } 4701 4702 ori_puncture_bitmap >>= 1; 4703 chan_cfreq = chan_cfreq + BW_20_MHZ; 4704 } 4705 4706 return QDF_STATUS_SUCCESS; 4707 } 4708 4709 void reg_set_create_punc_bitmap(struct ch_params *ch_params, 4710 bool is_create_punc_bitmap) 4711 { 4712 ch_params->is_create_punc_bitmap = is_create_punc_bitmap; 4713 } 4714 4715 bool reg_is_punc_bitmap_valid(enum phy_ch_width bw, uint16_t puncture_bitmap) 4716 { 4717 int i, num_bws; 4718 const uint16_t *bonded_puncture_bitmap = NULL; 4719 uint16_t array_size = 0; 4720 bool is_punc_bitmap_valid = false; 4721 4722 num_bws = QDF_ARRAY_SIZE(bw_puncture_bitmap_pair_map); 4723 for (i = 0; i < num_bws; i++) { 4724 if (bw == bw_puncture_bitmap_pair_map[i].chwidth) { 4725 bonded_puncture_bitmap = 4726 bw_puncture_bitmap_pair_map[i].puncture_bitmap_arr; 4727 array_size = bw_puncture_bitmap_pair_map[i].array_size; 4728 break; 4729 } 4730 } 4731 4732 if (array_size && bonded_puncture_bitmap) { 4733 for (i = 0; i < array_size; i++) { 4734 if (puncture_bitmap == bonded_puncture_bitmap[i]) { 4735 is_punc_bitmap_valid = true; 4736 break; 4737 } 4738 } 4739 } 4740 4741 return is_punc_bitmap_valid; 4742 } 4743 4744 uint16_t reg_find_nearest_puncture_pattern(enum phy_ch_width bw, 4745 uint16_t proposed_bitmap) 4746 { 4747 int i, num_bws; 4748 const uint16_t *bonded_puncture_bitmap = NULL; 4749 uint16_t array_size; 4750 uint16_t final_bitmap; 4751 4752 /* An input pattern = 0 will match any pattern 4753 * Therefore, ignore '0' pattern and return '0', as '0' matches '0'. 4754 */ 4755 if (!proposed_bitmap) 4756 return 0; 4757 4758 array_size = 0; 4759 final_bitmap = 0; 4760 4761 num_bws = QDF_ARRAY_SIZE(bw_puncture_bitmap_pair_map); 4762 for (i = 0; i < num_bws; i++) { 4763 if (bw == bw_puncture_bitmap_pair_map[i].chwidth) { 4764 bonded_puncture_bitmap = 4765 bw_puncture_bitmap_pair_map[i].puncture_bitmap_arr; 4766 array_size = bw_puncture_bitmap_pair_map[i].array_size; 4767 break; 4768 } 4769 } 4770 4771 if (array_size && bonded_puncture_bitmap) { 4772 for (i = 0; i < array_size; i++) { 4773 uint16_t valid_bitmap = bonded_puncture_bitmap[i]; 4774 4775 if ((proposed_bitmap | valid_bitmap) == valid_bitmap) { 4776 final_bitmap = valid_bitmap; 4777 break; 4778 } 4779 } 4780 } 4781 4782 return final_bitmap; 4783 } 4784 4785 /** 4786 * reg_update_5g_bonded_channel_state_punc_for_pwrmode() - update channel state 4787 * with static puncturing feature 4788 * @pdev: pointer to pdev 4789 * @bonded_chan_ptr: Pointer to bonded_channel_freq. 4790 * @ch_params: pointer to ch_params 4791 * @chan_state: chan_state to be updated 4792 * @in_6g_pwr_mode: Input 6 GHz power mode 4793 * 4794 * Return: void 4795 */ 4796 static void reg_update_5g_bonded_channel_state_punc_for_pwrmode( 4797 struct wlan_objmgr_pdev *pdev, 4798 const struct bonded_channel_freq *bonded_chan_ptr, 4799 struct ch_params *ch_params, 4800 enum channel_state *chan_state, 4801 enum supported_6g_pwr_types in_6g_pwr_mode) 4802 { 4803 qdf_freq_t chan_cfreq; 4804 enum channel_state temp_chan_state; 4805 uint16_t puncture_bitmap = 0; 4806 uint16_t final_bitmap; 4807 int i = 0; 4808 enum channel_state update_state = CHANNEL_STATE_ENABLE; 4809 4810 if (!pdev || !bonded_chan_ptr || !ch_params || !chan_state || 4811 !ch_params->is_create_punc_bitmap) 4812 return; 4813 4814 chan_cfreq = bonded_chan_ptr->start_freq; 4815 while (chan_cfreq <= bonded_chan_ptr->end_freq) { 4816 temp_chan_state = 4817 reg_get_channel_state_for_pwrmode(pdev, chan_cfreq, 4818 in_6g_pwr_mode); 4819 if (!reg_is_state_allowed(temp_chan_state)) 4820 puncture_bitmap |= BIT(i); 4821 /* Remember of any of the sub20 channel is a DFS channel */ 4822 if (temp_chan_state == CHANNEL_STATE_DFS) 4823 update_state = CHANNEL_STATE_DFS; 4824 chan_cfreq = chan_cfreq + BW_20_MHZ; 4825 i++; 4826 } 4827 /* Validate puncture bitmap. Update channel state. */ 4828 final_bitmap = reg_find_nearest_puncture_pattern(ch_params->ch_width, 4829 puncture_bitmap); 4830 if (final_bitmap) { 4831 *chan_state = update_state; 4832 ch_params->reg_punc_bitmap = final_bitmap; 4833 } 4834 } 4835 4836 #ifdef CONFIG_REG_CLIENT 4837 QDF_STATUS reg_apply_puncture(struct wlan_objmgr_pdev *pdev, 4838 uint16_t puncture_bitmap, 4839 qdf_freq_t freq, 4840 enum phy_ch_width bw, 4841 qdf_freq_t cen320_freq) 4842 { 4843 const struct bonded_channel_freq *bonded_chan; 4844 qdf_freq_t chan_cfreq; 4845 enum channel_enum chan_enum; 4846 struct regulatory_channel *mas_chan_list; 4847 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4848 bool is_puncture; 4849 uint16_t i = 0; 4850 4851 pdev_priv_obj = reg_get_pdev_obj(pdev); 4852 4853 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4854 reg_err_rl("pdev reg obj is NULL"); 4855 return QDF_STATUS_E_FAILURE; 4856 } 4857 4858 mas_chan_list = pdev_priv_obj->mas_chan_list; 4859 if (!mas_chan_list) { 4860 reg_err_rl("mas chan_list is NULL"); 4861 return QDF_STATUS_E_FAILURE; 4862 } 4863 bonded_chan = reg_get_bonded_chan_entry(freq, bw, cen320_freq); 4864 if (!bonded_chan) { 4865 reg_err_rl("bonded chan fails, freq %d, bw %d, cen320_freq %d", 4866 freq, bw, cen320_freq); 4867 return QDF_STATUS_E_FAILURE; 4868 } 4869 4870 chan_cfreq = bonded_chan->start_freq; 4871 while (chan_cfreq <= bonded_chan->end_freq) { 4872 is_puncture = BIT(i) & puncture_bitmap; 4873 if (is_puncture) { 4874 chan_enum = reg_get_chan_enum_for_freq(chan_cfreq); 4875 if (reg_is_chan_enum_invalid(chan_enum)) { 4876 reg_debug_rl("Invalid chan enum %d", chan_enum); 4877 return QDF_STATUS_E_FAILURE; 4878 } 4879 mas_chan_list[chan_enum].is_static_punctured = true; 4880 } 4881 i++; 4882 chan_cfreq = chan_cfreq + BW_20_MHZ; 4883 } 4884 4885 reg_compute_pdev_current_chan_list(pdev_priv_obj); 4886 4887 return QDF_STATUS_SUCCESS; 4888 } 4889 4890 QDF_STATUS reg_remove_puncture(struct wlan_objmgr_pdev *pdev) 4891 { 4892 enum channel_enum chan_enum; 4893 struct regulatory_channel *mas_chan_list; 4894 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4895 4896 pdev_priv_obj = reg_get_pdev_obj(pdev); 4897 4898 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4899 reg_err_rl("pdev reg obj is NULL"); 4900 return QDF_STATUS_E_FAILURE; 4901 } 4902 4903 mas_chan_list = pdev_priv_obj->mas_chan_list; 4904 if (!mas_chan_list) { 4905 reg_err_rl("mas chan_list is NULL"); 4906 return QDF_STATUS_E_FAILURE; 4907 } 4908 4909 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) 4910 if (mas_chan_list[chan_enum].is_static_punctured) 4911 mas_chan_list[chan_enum].is_static_punctured = false; 4912 4913 reg_compute_pdev_current_chan_list(pdev_priv_obj); 4914 4915 return QDF_STATUS_SUCCESS; 4916 } 4917 #endif 4918 4919 #else 4920 static void reg_update_5g_bonded_channel_state_punc_for_pwrmode( 4921 struct wlan_objmgr_pdev *pdev, 4922 const struct bonded_channel_freq *bonded_chan_ptr, 4923 struct ch_params *ch_params, 4924 enum channel_state *chan_state, 4925 enum supported_6g_pwr_types in_6g_pwr_mode) 4926 { 4927 } 4928 #endif 4929 4930 #ifdef CONFIG_REG_6G_PWRMODE 4931 enum channel_state 4932 reg_get_5g_bonded_channel_state_for_pwrmode(struct wlan_objmgr_pdev *pdev, 4933 qdf_freq_t freq, 4934 struct ch_params *ch_params, 4935 enum supported_6g_pwr_types 4936 in_6g_pwr_mode) 4937 { 4938 enum phy_ch_width bw; 4939 enum channel_enum ch_indx; 4940 enum channel_state chan_state; 4941 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4942 bool bw_enabled = false; 4943 const struct bonded_channel_freq *bonded_chan_ptr = NULL; 4944 uint16_t min_bw, max_bw; 4945 uint16_t in_punc_bitmap = reg_fetch_punc_bitmap(ch_params); 4946 4947 if (!ch_params) { 4948 reg_err_rl("Invalid ch_params"); 4949 return CHANNEL_STATE_INVALID; 4950 } 4951 bw = ch_params->ch_width; 4952 if (bw > CH_WIDTH_80P80MHZ) { 4953 reg_err_rl("bw (%d) passed is not good", bw); 4954 return CHANNEL_STATE_INVALID; 4955 } 4956 4957 chan_state = reg_get_5g_bonded_channel_for_pwrmode(pdev, freq, bw, 4958 &bonded_chan_ptr, 4959 in_6g_pwr_mode, 4960 in_punc_bitmap); 4961 4962 reg_update_5g_bonded_channel_state_punc_for_pwrmode( 4963 pdev, bonded_chan_ptr, 4964 ch_params, &chan_state, 4965 in_6g_pwr_mode); 4966 4967 if ((chan_state == CHANNEL_STATE_INVALID) || 4968 (chan_state == CHANNEL_STATE_DISABLE)) 4969 return chan_state; 4970 4971 pdev_priv_obj = reg_get_pdev_obj(pdev); 4972 4973 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4974 reg_err("pdev reg obj is NULL"); 4975 return CHANNEL_STATE_INVALID; 4976 } 4977 4978 ch_indx = reg_get_chan_enum_for_freq(freq); 4979 if (reg_is_chan_enum_invalid(ch_indx)) 4980 return CHANNEL_STATE_INVALID; 4981 4982 if (reg_get_min_max_bw_reg_chan_list(pdev, ch_indx, in_6g_pwr_mode, 4983 &min_bw, &max_bw)) 4984 return CHANNEL_STATE_INVALID; 4985 4986 if (bw == CH_WIDTH_5MHZ) 4987 bw_enabled = true; 4988 else if (bw == CH_WIDTH_10MHZ) 4989 bw_enabled = (min_bw <= 10) && 4990 (max_bw >= 10); 4991 else if (bw == CH_WIDTH_20MHZ) 4992 bw_enabled = (min_bw <= 20) && 4993 (max_bw >= 20); 4994 else if (bw == CH_WIDTH_40MHZ) 4995 bw_enabled = (min_bw <= 40) && 4996 (max_bw >= 40); 4997 else if (bw == CH_WIDTH_80MHZ) 4998 bw_enabled = (min_bw <= 80) && 4999 (max_bw >= 80); 5000 else if (bw == CH_WIDTH_160MHZ) 5001 bw_enabled = (min_bw <= 160) && 5002 (max_bw >= 160); 5003 else if (bw == CH_WIDTH_80P80MHZ) 5004 bw_enabled = (min_bw <= 80) && 5005 (max_bw >= 80); 5006 5007 if (bw_enabled) 5008 return chan_state; 5009 return CHANNEL_STATE_DISABLE; 5010 } 5011 #endif 5012 5013 enum channel_state 5014 reg_get_2g_bonded_channel_state_for_freq(struct wlan_objmgr_pdev *pdev, 5015 qdf_freq_t oper_ch_freq, 5016 qdf_freq_t sec_ch_freq, 5017 enum phy_ch_width bw) 5018 { 5019 enum channel_enum chan_idx; 5020 enum channel_state chan_state; 5021 struct regulatory_channel *reg_channels; 5022 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5023 bool bw_enabled = false; 5024 enum channel_state chan_state2 = CHANNEL_STATE_INVALID; 5025 5026 if (bw > CH_WIDTH_40MHZ) 5027 return CHANNEL_STATE_INVALID; 5028 5029 if (bw == CH_WIDTH_40MHZ) { 5030 if ((sec_ch_freq + 20 != oper_ch_freq) && 5031 (oper_ch_freq + 20 != sec_ch_freq)) 5032 return CHANNEL_STATE_INVALID; 5033 chan_state2 = 5034 reg_get_channel_state_for_pwrmode(pdev, 5035 sec_ch_freq, 5036 REG_CURRENT_PWR_MODE); 5037 if (chan_state2 == CHANNEL_STATE_INVALID) 5038 return chan_state2; 5039 } 5040 pdev_priv_obj = reg_get_pdev_obj(pdev); 5041 5042 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5043 reg_err("reg pdev priv obj is NULL"); 5044 return CHANNEL_STATE_INVALID; 5045 } 5046 5047 reg_channels = pdev_priv_obj->cur_chan_list; 5048 5049 chan_state = reg_get_channel_state_for_pwrmode(pdev, 5050 oper_ch_freq, 5051 REG_CURRENT_PWR_MODE); 5052 if (chan_state2 < chan_state) 5053 chan_state = chan_state2; 5054 5055 if ((chan_state == CHANNEL_STATE_INVALID) || 5056 (chan_state == CHANNEL_STATE_DISABLE)) 5057 return chan_state; 5058 5059 chan_idx = reg_get_chan_enum_for_freq(oper_ch_freq); 5060 if (reg_is_chan_enum_invalid(chan_idx)) 5061 return CHANNEL_STATE_INVALID; 5062 if (bw == CH_WIDTH_5MHZ) 5063 bw_enabled = true; 5064 else if (bw == CH_WIDTH_10MHZ) 5065 bw_enabled = (reg_channels[chan_idx].min_bw <= 10) && 5066 (reg_channels[chan_idx].max_bw >= 10); 5067 else if (bw == CH_WIDTH_20MHZ) 5068 bw_enabled = (reg_channels[chan_idx].min_bw <= 20) && 5069 (reg_channels[chan_idx].max_bw >= 20); 5070 else if (bw == CH_WIDTH_40MHZ) 5071 bw_enabled = (reg_channels[chan_idx].min_bw <= 40) && 5072 (reg_channels[chan_idx].max_bw >= 40); 5073 5074 if (bw_enabled) 5075 return chan_state; 5076 else 5077 return CHANNEL_STATE_DISABLE; 5078 5079 return CHANNEL_STATE_ENABLE; 5080 } 5081 5082 #ifdef WLAN_FEATURE_11BE 5083 5084 /** 5085 * reg_get_20mhz_channel_state_based_on_nol() - Get channel state of the 5086 * given 20MHZ channel. If the freq is in NOL/NOL history, it is considered 5087 * as enabled if "treat_nol_chan_as_disabled" is false, else the state is 5088 * considered as "disabled". 5089 * @pdev: Pointer to struct wlan_objmgr_pdev 5090 * @freq: Primary frequency 5091 * @treat_nol_chan_as_disabled: Flag to treat nol chan as enabled/disabled 5092 * @in_6g_pwr_type: Input 6g power type 5093 * 5094 * Return - Channel state 5095 */ 5096 static enum channel_state 5097 reg_get_20mhz_channel_state_based_on_nol(struct wlan_objmgr_pdev *pdev, 5098 qdf_freq_t freq, 5099 bool treat_nol_chan_as_disabled, 5100 enum supported_6g_pwr_types in_6g_pwr_type) 5101 { 5102 if (treat_nol_chan_as_disabled) 5103 return reg_get_channel_state_for_pwrmode(pdev, freq, 5104 in_6g_pwr_type); 5105 return reg_get_nol_channel_state(pdev, freq, 5106 in_6g_pwr_type); 5107 } 5108 5109 #define MAX_NUM_BONDED_PAIR 2 5110 5111 /** 5112 * reg_get_320_bonded_chan_array() - Fetches a list of bonded channel pointers 5113 * for the given bonded channel array. If 320 band center is specified, 5114 * return the bonded channel pointer comprising of given band center else 5115 * return list of all available bonded channel pair. 5116 * 5117 * @pdev: Pointer to struct wlan_objmgr_pdev. 5118 * @freq: Input frequency in MHZ whose bonded channel pointer must be fetched. 5119 * @band_center_320: Channel center frequency of 320MHZ channel. 5120 * @bonded_chan_ar: Array of bonded channel list. 5121 * @array_size: Size of bonded channel array. 5122 * @bonded_chan_ptr: Pointer to hold the address of bonded_channel_freq index. 5123 * 5124 * Return: number of bonded channel arrays fetched. 5125 */ 5126 static uint8_t 5127 reg_get_320_bonded_chan_array(struct wlan_objmgr_pdev *pdev, 5128 qdf_freq_t freq, 5129 qdf_freq_t band_center_320, 5130 const struct bonded_channel_freq bonded_chan_ar[], 5131 uint16_t array_size, 5132 const struct bonded_channel_freq 5133 *bonded_chan_ptr[]) 5134 { 5135 int i; 5136 uint8_t num_bonded_pairs = 0; 5137 5138 /* Fetch all possible bonded channel pointers for the given freq */ 5139 if (!band_center_320) { 5140 for (i = 0 ; i < array_size && 5141 num_bonded_pairs < MAX_NUM_BONDED_PAIR; i++) { 5142 if ((freq >= bonded_chan_ar[i].start_freq) && 5143 (freq <= bonded_chan_ar[i].end_freq)) { 5144 bonded_chan_ptr[num_bonded_pairs] = 5145 &bonded_chan_ar[i]; 5146 num_bonded_pairs++; 5147 } 5148 } 5149 } else { 5150 /* Fetch the bonded channel pointer for the given band_center */ 5151 for (i = 0; i < array_size; i++) { 5152 qdf_freq_t bandstart = bonded_chan_ar[i].start_freq; 5153 5154 if (band_center_320 == 5155 reg_get_band_cen_from_bandstart(BW_320_MHZ, 5156 bandstart)) { 5157 bonded_chan_ptr[num_bonded_pairs] = 5158 &bonded_chan_ar[i]; 5159 num_bonded_pairs++; 5160 break; 5161 } 5162 } 5163 } 5164 return num_bonded_pairs; 5165 } 5166 5167 #define SUB_CHAN_BW 20 /* 20 MHZ */ 5168 #define BW_160MHZ 160 5169 #define REG_IS_TOT_CHAN_BW_BELOW_160(_x, _y) \ 5170 (reg_is_state_allowed((_x)) && (_y) < BW_160MHZ) 5171 #endif 5172 5173 qdf_freq_t 5174 reg_get_endchan_cen_from_bandstart(qdf_freq_t band_start, 5175 uint16_t bw) 5176 { 5177 uint16_t left_edge_freq = band_start - BW_10_MHZ; 5178 5179 return left_edge_freq + bw - BW_10_MHZ; 5180 } 5181 5182 #ifdef WLAN_FEATURE_11BE 5183 enum channel_state 5184 reg_get_chan_state_for_320(struct wlan_objmgr_pdev *pdev, 5185 uint16_t freq, 5186 qdf_freq_t band_center_320, 5187 enum phy_ch_width ch_width, 5188 const struct bonded_channel_freq 5189 **bonded_chan_ptr_ptr, 5190 enum supported_6g_pwr_types in_6g_pwr_type, 5191 bool treat_nol_chan_as_disabled, 5192 uint16_t input_punc_bitmap) 5193 { 5194 uint8_t num_bonded_pairs; 5195 uint16_t array_size = 5196 QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq); 5197 const struct bonded_channel_freq *bonded_ch_ptr[2] = { 5198 NULL, NULL}; 5199 uint16_t punct_pattern; 5200 5201 /* For now sending band center freq as 0 */ 5202 num_bonded_pairs = 5203 reg_get_320_bonded_chan_array(pdev, freq, band_center_320, 5204 bonded_chan_320mhz_list_freq, 5205 array_size, bonded_ch_ptr); 5206 if (!num_bonded_pairs) { 5207 reg_info("No 320MHz bonded pair for freq %d", freq); 5208 return CHANNEL_STATE_INVALID; 5209 } 5210 /* Taking only first bonded pair */ 5211 *bonded_chan_ptr_ptr = bonded_ch_ptr[0]; 5212 5213 return reg_get_320_bonded_channel_state_for_pwrmode(pdev, freq, 5214 bonded_ch_ptr[0], 5215 ch_width, 5216 &punct_pattern, 5217 in_6g_pwr_type, 5218 treat_nol_chan_as_disabled, 5219 input_punc_bitmap); 5220 } 5221 #endif 5222 5223 #ifdef WLAN_FEATURE_11BE 5224 #ifdef CONFIG_REG_CLIENT 5225 static void 5226 reg_verify_punc_for_320_and_set_channel_state(uint16_t punc_bitmap, 5227 enum channel_state *chan_state, 5228 enum channel_state update_state) 5229 { 5230 if (reg_is_punc_bitmap_valid(CH_WIDTH_320MHZ, punc_bitmap)) { 5231 *chan_state = update_state; 5232 } 5233 } 5234 #else /* CONFIG_REG_CLIENT */ 5235 static inline void 5236 reg_verify_punc_for_320_and_set_channel_state(uint16_t punc_bitmap, 5237 enum channel_state *chan_state, 5238 enum channel_state update_state) 5239 { 5240 } 5241 #endif /* CONFIG_REG_CLIENT */ 5242 5243 enum channel_state 5244 reg_get_320_bonded_channel_state_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5245 qdf_freq_t freq, 5246 const struct bonded_channel_freq 5247 *bonded_chan_ptr, 5248 enum phy_ch_width bw, 5249 uint16_t *out_punc_bitmap, 5250 enum supported_6g_pwr_types 5251 in_6g_pwr_type, 5252 bool treat_nol_chan_as_disabled, 5253 uint16_t input_punc_bitmap) 5254 { 5255 enum channel_state chan_state = CHANNEL_STATE_INVALID; 5256 enum channel_state temp_chan_state, prim_chan_state; 5257 uint16_t startchan_cfreq, endchan_cfreq; 5258 uint16_t max_cont_bw, i; 5259 enum channel_state update_state = CHANNEL_STATE_ENABLE; 5260 5261 *out_punc_bitmap = ALL_SCHANS_PUNC; 5262 5263 if (!bonded_chan_ptr) 5264 return chan_state; 5265 5266 startchan_cfreq = bonded_chan_ptr->start_freq; 5267 endchan_cfreq = 5268 reg_get_endchan_cen_from_bandstart(startchan_cfreq, 5269 BW_320_MHZ); 5270 max_cont_bw = 0; 5271 i = 0; 5272 5273 while (startchan_cfreq <= endchan_cfreq) { 5274 if (!reg_is_chan_bit_punctured(input_punc_bitmap, i)) { 5275 temp_chan_state = 5276 reg_get_20mhz_channel_state_based_on_nol(pdev, 5277 startchan_cfreq, 5278 treat_nol_chan_as_disabled, 5279 in_6g_pwr_type); 5280 5281 if (reg_is_state_allowed(temp_chan_state)) { 5282 max_cont_bw += SUB_CHAN_BW; 5283 *out_punc_bitmap &= ~BIT(i); 5284 /* Remember if sub20 channel is DFS channel */ 5285 if (temp_chan_state == CHANNEL_STATE_DFS) 5286 update_state = CHANNEL_STATE_DFS; 5287 } 5288 5289 if (temp_chan_state < chan_state) 5290 chan_state = temp_chan_state; 5291 } 5292 startchan_cfreq = startchan_cfreq + SUB_CHAN_BW; 5293 i++; 5294 } 5295 5296 /* Validate puncture bitmap. Update channel state. */ 5297 reg_verify_punc_for_320_and_set_channel_state(*out_punc_bitmap, 5298 &chan_state, 5299 update_state); 5300 5301 prim_chan_state = 5302 reg_get_20mhz_channel_state_based_on_nol(pdev, freq, 5303 treat_nol_chan_as_disabled, 5304 in_6g_pwr_type); 5305 5306 /* After iterating through all the subchannels, if the final channel 5307 * state is invalid/disable, it means all our subchannels are not 5308 * valid and we could not find a 320 MHZ channel. 5309 * If we have found a channel where the max width is: 5310 * 1. Less than 160: there is no puncturing needed. Hence return 5311 * the chan state as invalid. Or if the primary freq given is not 5312 * supported by regulatory, the channel cannot be enabled as a 5313 * punctured channel. So return channel state as invalid. 5314 * 2. If greater than 160: Mark the invalid channels as punctured. 5315 * and return channel state as ENABLE. 5316 */ 5317 if (REG_IS_TOT_CHAN_BW_BELOW_160(chan_state, max_cont_bw) || 5318 !reg_is_state_allowed(prim_chan_state)) 5319 return CHANNEL_STATE_INVALID; 5320 5321 return chan_state; 5322 } 5323 5324 static inline bool reg_is_pri_within_240mhz_chan(qdf_freq_t freq) 5325 { 5326 return (freq >= CHAN_FREQ_5660 && freq <= CHAN_FREQ_5720); 5327 } 5328 5329 /** 5330 * reg_fill_chan320mhz_seg0_center() - Fill the primary segment center 5331 * for a 320MHz channel in the given channel param. Primary segment center 5332 * of a 320MHZ is the 160MHZ segment center of the given freq. 5333 * @pdev: Pointer to struct wlan_objmgr_pdev. 5334 * @ch_param: channel params to be filled. 5335 * @freq: Input primary frequency in MHZ. 5336 * 5337 * Return: void. 5338 */ 5339 static void 5340 reg_fill_chan320mhz_seg0_center(struct wlan_objmgr_pdev *pdev, 5341 struct ch_params *ch_param, qdf_freq_t freq) 5342 { 5343 const struct bonded_channel_freq *t_bonded_ch_ptr; 5344 5345 t_bonded_ch_ptr = reg_get_bonded_chan_entry(freq, CH_WIDTH_160MHZ, 0); 5346 if (t_bonded_ch_ptr) { 5347 ch_param->mhz_freq_seg0 = 5348 (t_bonded_ch_ptr->start_freq + 5349 t_bonded_ch_ptr->end_freq) / 2; 5350 ch_param->center_freq_seg0 = 5351 reg_freq_to_chan(pdev, 5352 ch_param->mhz_freq_seg0); 5353 } else { 5354 /** 5355 * If we do not find a 160Mhz bonded pair, since it is 5356 * for a 320Mhz channel we need to also see if we can find a 5357 * pseudo 160Mhz channel for the special case of 5358 * 5Ghz 240Mhz channel. 5359 */ 5360 if (reg_is_pri_within_240mhz_chan(freq)) { 5361 ch_param->mhz_freq_seg0 = 5362 PRIM_SEG_FREQ_CENTER_240MHZ_5G_CHAN; 5363 ch_param->center_freq_seg0 = 5364 PRIM_SEG_IEEE_CENTER_240MHZ_5G_CHAN; 5365 } else { 5366 ch_param->ch_width = CH_WIDTH_INVALID; 5367 reg_debug("Cannot find 160 MHz centers for freq %d", 5368 freq); 5369 } 5370 } 5371 } 5372 5373 /** 5374 * reg_fill_channel_list_for_320_for_pwrmode() - Fill 320MHZ channel list. 5375 * @pdev: Pointer to struct wlan_objmgr_pdev. 5376 * @freq: Input frequency in MHz. 5377 * @in_ch_width: Input channel width, if a channel of the given width is not 5378 * found, reduce the channel width to the next lower mode and pass it to the 5379 * caller. 5380 * @band_center_320: Center of 320 MHz channel. 5381 * @chan_list: Pointer to reg_channel_list to be filled. 5382 * @update_bw: Flag to hold if bw is updated. 5383 * @in_6g_pwr_mode: Input 6g power mode which decides the which power mode based 5384 * channel list will be chosen. 5385 * @treat_nol_chan_as_disabled: Bool to treat NOL channels as disabled/enabled 5386 * 5387 * If we are unable to find a channel whose width is greater than 5388 * 160 MHz and less than 320 with the help of puncturing, using the 5389 * given freq, set "update_bw" variable to be true, lower the channel 5390 * width and return to the caller. The caller fetches a channel of 5391 * reduced mode based on "update_bw" flag. 5392 * 5393 * If 320 band center is 0, return all the 320 channels 5394 * that match the primary frequency else return only channel 5395 * that matches 320 band center. 5396 * 5397 * 5398 * Return - None. 5399 */ 5400 static void 5401 reg_fill_channel_list_for_320_for_pwrmode( 5402 struct wlan_objmgr_pdev *pdev, 5403 qdf_freq_t freq, 5404 enum phy_ch_width *in_ch_width, 5405 qdf_freq_t band_center_320, 5406 struct reg_channel_list *chan_list, 5407 bool *update_bw, 5408 enum supported_6g_pwr_types in_6g_pwr_mode, 5409 bool treat_nol_chan_as_disabled) 5410 { 5411 uint8_t num_bonded_pairs, i, num_ch_params; 5412 enum channel_state chan_state; 5413 uint16_t array_size = QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq); 5414 uint16_t out_punc_bitmap; 5415 uint16_t max_reg_bw; 5416 enum channel_enum chan_enum; 5417 const struct bonded_channel_freq *bonded_ch_ptr[2] = {NULL, NULL}; 5418 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5419 5420 *update_bw = false; 5421 5422 chan_enum = reg_get_chan_enum_for_freq(freq); 5423 if (reg_is_chan_enum_invalid(chan_enum)) { 5424 reg_err("chan freq is not valid"); 5425 return; 5426 } 5427 5428 pdev_priv_obj = reg_get_pdev_obj(pdev); 5429 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5430 reg_err("reg pdev priv obj is NULL"); 5431 return; 5432 } 5433 5434 /* Maximum bandwidth of the channel supported by regulatory for 5435 * the given freq. 5436 */ 5437 if (reg_get_min_max_bw_reg_chan_list(pdev, chan_enum, in_6g_pwr_mode, 5438 NULL, &max_reg_bw)) 5439 return; 5440 5441 /* Regulatory does not support BW greater than 160. 5442 * Try finding a channel in a lower mode. 5443 */ 5444 if (max_reg_bw <= BW_160MHZ) { 5445 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5446 *update_bw = true; 5447 return; 5448 } 5449 5450 num_bonded_pairs = 5451 reg_get_320_bonded_chan_array(pdev, freq, band_center_320, 5452 bonded_chan_320mhz_list_freq, 5453 array_size, 5454 bonded_ch_ptr); 5455 5456 if (!num_bonded_pairs) { 5457 if (band_center_320) { 5458 reg_debug("No bonded pair for the given band_center\n"); 5459 chan_list->num_ch_params = 0; 5460 } else { 5461 /* Could not find a 320 MHZ bonded channel pair, 5462 * find a channel of lower BW. 5463 */ 5464 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5465 *update_bw = true; 5466 } 5467 return; 5468 } 5469 5470 for (i = 0, num_ch_params = 0 ; i < num_bonded_pairs; i++) { 5471 uint16_t in_punc_bitmap = 5472 chan_list->chan_param[i].input_punc_bitmap; 5473 5474 /* Chan_state to hold the channel state of bonding 5475 * pair of channels. 5476 */ 5477 chan_state = 5478 reg_get_320_bonded_channel_state_for_pwrmode(pdev, freq, 5479 bonded_ch_ptr[i], 5480 *in_ch_width, 5481 &out_punc_bitmap, 5482 in_6g_pwr_mode, 5483 treat_nol_chan_as_disabled, 5484 in_punc_bitmap); 5485 5486 if (reg_is_state_allowed(chan_state)) { 5487 struct ch_params *t_chan_param = 5488 &chan_list->chan_param[num_ch_params]; 5489 qdf_freq_t start_freq = bonded_ch_ptr[i]->start_freq; 5490 5491 t_chan_param->mhz_freq_seg1 = 5492 reg_get_band_cen_from_bandstart(BW_320_MHZ, 5493 start_freq); 5494 t_chan_param->center_freq_seg1 = 5495 reg_freq_to_chan(pdev, 5496 t_chan_param->mhz_freq_seg1); 5497 t_chan_param->ch_width = *in_ch_width; 5498 t_chan_param->reg_punc_bitmap = out_punc_bitmap; 5499 5500 reg_fill_chan320mhz_seg0_center(pdev, 5501 t_chan_param, 5502 freq); 5503 num_ch_params++; 5504 chan_list->num_ch_params = num_ch_params; 5505 } 5506 } 5507 5508 /* The bonded pairs could not create any channels, 5509 * lower the bandwidth to find a channel. 5510 */ 5511 if (!chan_list->num_ch_params) { 5512 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5513 *update_bw = true; 5514 } 5515 } 5516 5517 /** 5518 * reg_fill_pre320mhz_channel_for_pwrmode() - Fill channel params for channel 5519 * width less than 320. 5520 * @pdev: Pointer to struct wlan_objmgr_pdev 5521 * @chan_list: Pointer to struct reg_channel_list 5522 * @ch_width: Channel width 5523 * @freq: Center frequency of the primary channel in MHz 5524 * @sec_ch_2g_freq: Secondary 2G channel frequency in MHZ 5525 * @in_6g_pwr_mode: Input 6g power mode which decides the which power mode based 5526 * channel list will be chosen. 5527 * @treat_nol_chan_as_disabled: Bool to consider nol chan as enabled/disabled 5528 */ 5529 static void 5530 reg_fill_pre320mhz_channel_for_pwrmode( 5531 struct wlan_objmgr_pdev *pdev, 5532 struct reg_channel_list *chan_list, 5533 enum phy_ch_width ch_width, 5534 qdf_freq_t freq, 5535 qdf_freq_t sec_ch_2g_freq, 5536 enum supported_6g_pwr_types in_6g_pwr_mode, 5537 bool treat_nol_chan_as_disabled) 5538 { 5539 chan_list->num_ch_params = 1; 5540 chan_list->chan_param[0].ch_width = ch_width; 5541 chan_list->chan_param[0].reg_punc_bitmap = NO_SCHANS_PUNC; 5542 reg_set_channel_params_for_pwrmode(pdev, freq, sec_ch_2g_freq, 5543 &chan_list->chan_param[0], 5544 in_6g_pwr_mode, 5545 treat_nol_chan_as_disabled); 5546 } 5547 5548 void 5549 reg_fill_channel_list_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5550 qdf_freq_t freq, 5551 qdf_freq_t sec_ch_2g_freq, 5552 enum phy_ch_width in_ch_width, 5553 qdf_freq_t band_center_320, 5554 struct reg_channel_list *chan_list, 5555 enum supported_6g_pwr_types in_6g_pwr_mode, 5556 bool treat_nol_chan_as_disabled) 5557 { 5558 bool update_bw; 5559 5560 if (!chan_list) { 5561 reg_err("channel params is NULL"); 5562 return; 5563 } 5564 5565 if (in_ch_width >= CH_WIDTH_MAX) 5566 in_ch_width = CH_WIDTH_320MHZ; 5567 5568 if (in_ch_width == CH_WIDTH_320MHZ) { 5569 update_bw = 0; 5570 reg_fill_channel_list_for_320_for_pwrmode( 5571 pdev, freq, &in_ch_width, 5572 band_center_320, chan_list, 5573 &update_bw, in_6g_pwr_mode, 5574 treat_nol_chan_as_disabled); 5575 if (!update_bw) 5576 return; 5577 } 5578 5579 /* A 320 channel is not available (or) user has not requested 5580 * for a 320MHZ channel, look for channels in lower modes, 5581 * reg_set_5g_channel_params_for_freq() finds for the 5582 * next available mode and fills ch_params. 5583 */ 5584 reg_fill_pre320mhz_channel_for_pwrmode( 5585 pdev, chan_list, in_ch_width, freq, 5586 sec_ch_2g_freq, in_6g_pwr_mode, 5587 treat_nol_chan_as_disabled); 5588 } 5589 #endif 5590 5591 enum channel_state 5592 reg_get_5g_bonded_channel_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5593 uint16_t freq, 5594 enum phy_ch_width ch_width, 5595 const struct bonded_channel_freq 5596 **bonded_chan_ptr_ptr, 5597 enum supported_6g_pwr_types 5598 in_6g_pwr_mode, 5599 uint16_t input_punc_bitmap) 5600 { 5601 if (ch_width == CH_WIDTH_20MHZ) 5602 return reg_get_channel_state_for_pwrmode(pdev, freq, 5603 in_6g_pwr_mode); 5604 5605 if (reg_is_ch_width_320(ch_width)) 5606 return reg_get_chan_state_for_320(pdev, freq, 0, 5607 ch_width, 5608 bonded_chan_ptr_ptr, 5609 in_6g_pwr_mode, true, 5610 input_punc_bitmap); 5611 /* Fetch the bonded_chan_ptr for width greater than 20MHZ. */ 5612 *bonded_chan_ptr_ptr = reg_get_bonded_chan_entry(freq, ch_width, 0); 5613 5614 if (!(*bonded_chan_ptr_ptr)) { 5615 reg_debug_rl("bonded_chan_ptr_ptr is NULL"); 5616 return CHANNEL_STATE_INVALID; 5617 } 5618 5619 return reg_get_5g_bonded_chan_array_for_pwrmode(pdev, freq, 5620 *bonded_chan_ptr_ptr, 5621 in_6g_pwr_mode, 5622 input_punc_bitmap); 5623 } 5624 5625 #ifdef CONFIG_REG_6G_PWRMODE 5626 /** 5627 * reg_set_5g_channel_params_for_pwrmode()- Set channel parameters like center 5628 * frequency for a bonded channel state. Also return the maximum bandwidth 5629 * supported by the channel. 5630 * @pdev: Pointer to pdev. 5631 * @freq: Channel center frequency. 5632 * @ch_params: Pointer to ch_params. 5633 * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based 5634 * channel list will be chosen. 5635 * @treat_nol_chan_as_disabled: Bool to treat NOL channels as disabled/enabled 5636 * 5637 * Return: void 5638 */ 5639 static void reg_set_5g_channel_params_for_pwrmode( 5640 struct wlan_objmgr_pdev *pdev, 5641 uint16_t freq, 5642 struct ch_params *ch_params, 5643 enum supported_6g_pwr_types 5644 in_6g_pwr_type, 5645 bool treat_nol_chan_as_disabled) 5646 { 5647 /* 5648 * Set channel parameters like center frequency for a bonded channel 5649 * state. Also return the maximum bandwidth supported by the channel. 5650 */ 5651 5652 enum channel_state chan_state = CHANNEL_STATE_ENABLE; 5653 enum channel_state chan_state2 = CHANNEL_STATE_ENABLE; 5654 const struct bonded_channel_freq *bonded_chan_ptr = NULL; 5655 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5656 enum channel_enum chan_enum, sec_5g_chan_enum; 5657 uint16_t bw_80 = 0; 5658 uint16_t max_bw, sec_5g_freq_max_bw = 0; 5659 uint16_t in_punc_bitmap = reg_fetch_punc_bitmap(ch_params); 5660 5661 if (!ch_params) { 5662 reg_err("ch_params is NULL"); 5663 return; 5664 } 5665 5666 chan_enum = reg_get_chan_enum_for_freq(freq); 5667 if (reg_is_chan_enum_invalid(chan_enum)) { 5668 reg_err("chan freq is not valid"); 5669 return; 5670 } 5671 5672 pdev_priv_obj = reg_get_pdev_obj(pdev); 5673 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5674 reg_err("reg pdev priv obj is NULL"); 5675 return; 5676 } 5677 5678 if (ch_params->ch_width >= CH_WIDTH_MAX) { 5679 if (ch_params->mhz_freq_seg1 != 0) 5680 ch_params->ch_width = CH_WIDTH_80P80MHZ; 5681 else 5682 ch_params->ch_width = CH_WIDTH_160MHZ; 5683 } 5684 5685 if (reg_get_min_max_bw_reg_chan_list(pdev, chan_enum, in_6g_pwr_type, 5686 NULL, &max_bw)) 5687 return; 5688 5689 bw_80 = reg_get_bw_value(CH_WIDTH_80MHZ); 5690 5691 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 5692 sec_5g_chan_enum = 5693 reg_get_chan_enum_for_freq(ch_params->mhz_freq_seg1 - 5694 NEAREST_20MHZ_CHAN_FREQ_OFFSET); 5695 if (reg_is_chan_enum_invalid(sec_5g_chan_enum)) { 5696 reg_err("secondary channel freq is not valid"); 5697 return; 5698 } 5699 5700 if (reg_get_min_max_bw_reg_chan_list(pdev, sec_5g_chan_enum, 5701 in_6g_pwr_type, 5702 NULL, &sec_5g_freq_max_bw)) 5703 return; 5704 } 5705 5706 while (ch_params->ch_width != CH_WIDTH_INVALID) { 5707 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 5708 if ((max_bw < bw_80) || (sec_5g_freq_max_bw < bw_80)) 5709 goto update_bw; 5710 } else if (max_bw < reg_get_bw_value(ch_params->ch_width)) { 5711 goto update_bw; 5712 } 5713 5714 bonded_chan_ptr = NULL; 5715 chan_state = reg_get_5g_bonded_channel_for_pwrmode( 5716 pdev, freq, ch_params->ch_width, 5717 &bonded_chan_ptr, in_6g_pwr_type, 5718 in_punc_bitmap); 5719 chan_state = 5720 reg_get_ch_state_based_on_nol_flag(pdev, freq, 5721 ch_params, 5722 in_6g_pwr_type, 5723 treat_nol_chan_as_disabled); 5724 5725 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 5726 struct ch_params temp_ch_params = {0}; 5727 5728 temp_ch_params.ch_width = CH_WIDTH_80MHZ; 5729 /* Puncturing pattern is not needed for 80+80 */ 5730 reg_set_create_punc_bitmap(&temp_ch_params, false); 5731 chan_state2 = 5732 reg_get_ch_state_based_on_nol_flag(pdev, 5733 ch_params->mhz_freq_seg1 - 5734 NEAREST_20MHZ_CHAN_FREQ_OFFSET, 5735 &temp_ch_params, in_6g_pwr_type, 5736 treat_nol_chan_as_disabled); 5737 chan_state = reg_combine_channel_states( 5738 chan_state, chan_state2); 5739 } 5740 5741 if ((chan_state != CHANNEL_STATE_ENABLE) && 5742 (chan_state != CHANNEL_STATE_DFS)) 5743 goto update_bw; 5744 if (ch_params->ch_width <= CH_WIDTH_20MHZ) { 5745 ch_params->sec_ch_offset = NO_SEC_CH; 5746 ch_params->mhz_freq_seg0 = freq; 5747 ch_params->center_freq_seg0 = 5748 reg_freq_to_chan(pdev, 5749 ch_params->mhz_freq_seg0); 5750 break; 5751 } else if (ch_params->ch_width >= CH_WIDTH_40MHZ) { 5752 const struct bonded_channel_freq *bonded_chan_ptr2; 5753 5754 bonded_chan_ptr2 = 5755 reg_get_bonded_chan_entry( 5756 freq, 5757 CH_WIDTH_40MHZ, 5758 0); 5759 5760 if (!bonded_chan_ptr || !bonded_chan_ptr2) 5761 goto update_bw; 5762 if (freq == bonded_chan_ptr2->start_freq) 5763 ch_params->sec_ch_offset = LOW_PRIMARY_CH; 5764 else 5765 ch_params->sec_ch_offset = HIGH_PRIMARY_CH; 5766 5767 ch_params->mhz_freq_seg0 = 5768 (bonded_chan_ptr->start_freq + 5769 bonded_chan_ptr->end_freq) / 2; 5770 ch_params->center_freq_seg0 = 5771 reg_freq_to_chan(pdev, 5772 ch_params->mhz_freq_seg0); 5773 break; 5774 } 5775 update_bw: 5776 ch_params->ch_width = 5777 get_next_lower_bandwidth(ch_params->ch_width); 5778 } 5779 5780 if (ch_params->ch_width == CH_WIDTH_160MHZ) { 5781 ch_params->mhz_freq_seg1 = ch_params->mhz_freq_seg0; 5782 ch_params->center_freq_seg1 = 5783 reg_freq_to_chan(pdev, 5784 ch_params->mhz_freq_seg1); 5785 5786 chan_state = reg_get_5g_bonded_channel_for_pwrmode( 5787 pdev, freq, CH_WIDTH_80MHZ, &bonded_chan_ptr, 5788 in_6g_pwr_type, 5789 in_punc_bitmap); 5790 if (bonded_chan_ptr) { 5791 ch_params->mhz_freq_seg0 = 5792 (bonded_chan_ptr->start_freq + 5793 bonded_chan_ptr->end_freq) / 2; 5794 ch_params->center_freq_seg0 = 5795 reg_freq_to_chan(pdev, 5796 ch_params->mhz_freq_seg0); 5797 } 5798 } 5799 5800 /* Overwrite mhz_freq_seg1 to 0 for non 160 and 80+80 width */ 5801 if (!(ch_params->ch_width == CH_WIDTH_160MHZ || 5802 ch_params->ch_width == CH_WIDTH_80P80MHZ)) { 5803 ch_params->mhz_freq_seg1 = 0; 5804 ch_params->center_freq_seg1 = 0; 5805 } 5806 } 5807 #endif 5808 5809 #ifdef CONFIG_REG_CLIENT 5810 static qdf_freq_t reg_get_sec_ch_2g_freq(struct wlan_objmgr_pdev *pdev, 5811 qdf_freq_t primary_freq) 5812 { 5813 qdf_freq_t sec_ch_2g_freq = 0; 5814 5815 if (primary_freq >= TWOG_CHAN_1_IN_MHZ && 5816 primary_freq <= TWOG_CHAN_5_IN_MHZ) 5817 sec_ch_2g_freq = primary_freq + HT40_SEC_OFFSET; 5818 else if (primary_freq >= TWOG_CHAN_6_IN_MHZ && 5819 primary_freq <= TWOG_CHAN_13_IN_MHZ) 5820 sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET; 5821 5822 return sec_ch_2g_freq; 5823 } 5824 #else 5825 static qdf_freq_t reg_get_sec_ch_2g_freq(struct wlan_objmgr_pdev *pdev, 5826 qdf_freq_t primary_freq) 5827 { 5828 qdf_freq_t sec_ch_2g_freq; 5829 5830 if (primary_freq < TWOG_CHAN_1_IN_MHZ || 5831 primary_freq > TWOG_CHAN_13_IN_MHZ) 5832 return 0; 5833 5834 sec_ch_2g_freq = primary_freq + HT40_SEC_OFFSET; 5835 5836 /* For 2G primary frequencies > 2452 (IEEE9), return HT40-. */ 5837 if (primary_freq > TWOG_CHAN_9_IN_MHZ) 5838 sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET; 5839 5840 /* 5841 * For 2G primary frequencies <= 2452 (IEEE9), return HT40+ if 5842 * the secondary is available, else return HT40-. 5843 */ 5844 else if (!reg_is_freq_present_in_cur_chan_list(pdev, sec_ch_2g_freq)) 5845 sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET; 5846 5847 return sec_ch_2g_freq; 5848 } 5849 #endif 5850 5851 void reg_set_2g_channel_params_for_freq(struct wlan_objmgr_pdev *pdev, 5852 uint16_t oper_freq, 5853 struct ch_params *ch_params, 5854 uint16_t sec_ch_2g_freq) 5855 { 5856 enum channel_state chan_state = CHANNEL_STATE_ENABLE; 5857 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5858 enum channel_enum chan_enum; 5859 uint16_t max_bw; 5860 5861 chan_enum = reg_get_chan_enum_for_freq(oper_freq); 5862 if (reg_is_chan_enum_invalid(chan_enum)) { 5863 reg_err("chan freq is not valid"); 5864 return; 5865 } 5866 5867 pdev_priv_obj = reg_get_pdev_obj(pdev); 5868 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5869 reg_err("reg pdev priv obj is NULL"); 5870 return; 5871 } 5872 5873 if (ch_params->ch_width >= CH_WIDTH_MAX) 5874 ch_params->ch_width = CH_WIDTH_40MHZ; 5875 if ((reg_get_bw_value(ch_params->ch_width) > 20) && !sec_ch_2g_freq) 5876 sec_ch_2g_freq = reg_get_sec_ch_2g_freq(pdev, oper_freq); 5877 5878 max_bw = pdev_priv_obj->cur_chan_list[chan_enum].max_bw; 5879 5880 while (ch_params->ch_width != CH_WIDTH_INVALID) { 5881 if (max_bw < reg_get_bw_value(ch_params->ch_width)) 5882 goto update_bw; 5883 5884 chan_state = 5885 reg_get_2g_bonded_channel_state_for_freq(pdev, oper_freq, 5886 sec_ch_2g_freq, 5887 ch_params->ch_width); 5888 if ((chan_state == CHANNEL_STATE_ENABLE) || 5889 (chan_state == CHANNEL_STATE_DFS)) { 5890 if (ch_params->ch_width == CH_WIDTH_40MHZ) { 5891 if (oper_freq < sec_ch_2g_freq) 5892 ch_params->sec_ch_offset = 5893 LOW_PRIMARY_CH; 5894 else 5895 ch_params->sec_ch_offset = 5896 HIGH_PRIMARY_CH; 5897 ch_params->mhz_freq_seg0 = 5898 (oper_freq + sec_ch_2g_freq) / 2; 5899 if (ch_params->mhz_freq_seg0 == 5900 TWOG_CHAN_14_IN_MHZ) 5901 ch_params->center_freq_seg0 = 14; 5902 else 5903 ch_params->center_freq_seg0 = 5904 (ch_params->mhz_freq_seg0 - 5905 TWOG_STARTING_FREQ) / 5906 FREQ_TO_CHAN_SCALE; 5907 } else { 5908 ch_params->sec_ch_offset = NO_SEC_CH; 5909 ch_params->mhz_freq_seg0 = oper_freq; 5910 if (ch_params->mhz_freq_seg0 == 5911 TWOG_CHAN_14_IN_MHZ) 5912 ch_params->center_freq_seg0 = 14; 5913 else 5914 ch_params->center_freq_seg0 = 5915 (ch_params->mhz_freq_seg0 - 5916 TWOG_STARTING_FREQ) / 5917 FREQ_TO_CHAN_SCALE; 5918 } 5919 break; 5920 } 5921 update_bw: 5922 ch_params->ch_width = 5923 get_next_lower_bandwidth(ch_params->ch_width); 5924 } 5925 /* Overwrite mhz_freq_seg1 and center_freq_seg1 to 0 for 2.4 Ghz */ 5926 ch_params->mhz_freq_seg1 = 0; 5927 ch_params->center_freq_seg1 = 0; 5928 } 5929 5930 #ifdef WLAN_FEATURE_11BE 5931 static void reg_copy_ch_params(struct ch_params *ch_params, 5932 struct reg_channel_list chan_list) 5933 { 5934 ch_params->center_freq_seg0 = chan_list.chan_param[0].center_freq_seg0; 5935 ch_params->center_freq_seg1 = chan_list.chan_param[0].center_freq_seg1; 5936 ch_params->mhz_freq_seg0 = chan_list.chan_param[0].mhz_freq_seg0; 5937 ch_params->mhz_freq_seg1 = chan_list.chan_param[0].mhz_freq_seg1; 5938 ch_params->ch_width = chan_list.chan_param[0].ch_width; 5939 ch_params->sec_ch_offset = chan_list.chan_param[0].sec_ch_offset; 5940 ch_params->reg_punc_bitmap = chan_list.chan_param[0].reg_punc_bitmap; 5941 } 5942 #endif /* WLAN_FEATURE_11BE */ 5943 5944 #ifdef CONFIG_REG_6G_PWRMODE 5945 #ifdef WLAN_FEATURE_11BE 5946 void 5947 reg_set_channel_params_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5948 qdf_freq_t freq, 5949 qdf_freq_t sec_ch_2g_freq, 5950 struct ch_params *ch_params, 5951 enum supported_6g_pwr_types in_6g_pwr_mode, 5952 bool is_treat_nol_dis) 5953 { 5954 if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) { 5955 if (reg_is_ch_width_320(ch_params->ch_width)) { 5956 struct reg_channel_list chan_list; 5957 uint8_t i; 5958 5959 qdf_mem_zero(&chan_list, sizeof(chan_list)); 5960 5961 for (i = 0; i < MAX_NUM_CHAN_PARAM; i++) { 5962 chan_list.chan_param[i].input_punc_bitmap = 5963 ch_params->input_punc_bitmap; 5964 } 5965 reg_fill_channel_list_for_pwrmode(pdev, freq, 5966 sec_ch_2g_freq, 5967 ch_params->ch_width, 5968 ch_params->mhz_freq_seg1, 5969 &chan_list, 5970 in_6g_pwr_mode, 5971 is_treat_nol_dis); 5972 reg_copy_ch_params(ch_params, chan_list); 5973 } else { 5974 reg_set_5g_channel_params_for_pwrmode(pdev, freq, 5975 ch_params, 5976 in_6g_pwr_mode, 5977 is_treat_nol_dis); 5978 } 5979 } else if (reg_is_24ghz_ch_freq(freq)) { 5980 reg_set_2g_channel_params_for_freq(pdev, freq, ch_params, 5981 sec_ch_2g_freq); 5982 } 5983 } 5984 #else 5985 void 5986 reg_set_channel_params_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5987 qdf_freq_t freq, 5988 qdf_freq_t sec_ch_2g_freq, 5989 struct ch_params *ch_params, 5990 enum supported_6g_pwr_types in_6g_pwr_mode, 5991 bool is_treat_nol_dis) 5992 { 5993 if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) 5994 reg_set_5g_channel_params_for_pwrmode(pdev, freq, ch_params, 5995 in_6g_pwr_mode, 5996 is_treat_nol_dis); 5997 else if (reg_is_24ghz_ch_freq(freq)) 5998 reg_set_2g_channel_params_for_freq(pdev, freq, ch_params, 5999 sec_ch_2g_freq); 6000 } 6001 #endif 6002 #endif 6003 6004 uint8_t reg_get_channel_reg_power_for_freq(struct wlan_objmgr_pdev *pdev, 6005 qdf_freq_t freq) 6006 { 6007 enum channel_enum chan_enum; 6008 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6009 struct regulatory_channel *reg_channels; 6010 6011 chan_enum = reg_get_chan_enum_for_freq(freq); 6012 6013 if (reg_is_chan_enum_invalid(chan_enum)) { 6014 reg_err("channel is invalid"); 6015 return REG_INVALID_TXPOWER; 6016 } 6017 6018 pdev_priv_obj = reg_get_pdev_obj(pdev); 6019 6020 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6021 reg_err("reg pdev priv obj is NULL"); 6022 return REG_INVALID_TXPOWER; 6023 } 6024 6025 reg_channels = pdev_priv_obj->cur_chan_list; 6026 6027 return reg_channels[chan_enum].tx_power; 6028 } 6029 6030 bool reg_is_dfs_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 6031 { 6032 uint32_t chan_flags; 6033 6034 chan_flags = reg_get_channel_flags_for_freq(pdev, freq); 6035 6036 return chan_flags & REGULATORY_CHAN_RADAR; 6037 } 6038 6039 #ifdef CONFIG_REG_CLIENT 6040 bool reg_is_dfs_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev, 6041 qdf_freq_t freq) 6042 { 6043 uint32_t chan_flags; 6044 6045 chan_flags = reg_get_channel_flags_from_secondary_list_for_freq(pdev, 6046 freq); 6047 6048 return chan_flags & REGULATORY_CHAN_RADAR; 6049 } 6050 6051 /** 6052 * reg_get_psoc_mas_chan_list() - Get psoc master channel list 6053 * @pdev: pointer to pdev object 6054 * @psoc: pointer to psoc object 6055 * 6056 * Return: psoc master channel list 6057 */ 6058 static struct regulatory_channel *reg_get_psoc_mas_chan_list( 6059 struct wlan_objmgr_pdev *pdev, 6060 struct wlan_objmgr_psoc *psoc) 6061 { 6062 struct wlan_regulatory_psoc_priv_obj *soc_reg; 6063 uint8_t pdev_id; 6064 uint8_t phy_id; 6065 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 6066 6067 soc_reg = reg_get_psoc_obj(psoc); 6068 if (!soc_reg) { 6069 reg_err("reg psoc private obj is NULL"); 6070 return NULL; 6071 } 6072 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 6073 6074 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 6075 if (reg_tx_ops->get_phy_id_from_pdev_id) 6076 reg_tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id); 6077 else 6078 phy_id = pdev_id; 6079 6080 return soc_reg->mas_chan_params[phy_id].mas_chan_list; 6081 } 6082 #else 6083 static inline struct regulatory_channel *reg_get_psoc_mas_chan_list( 6084 struct wlan_objmgr_pdev *pdev, 6085 struct wlan_objmgr_psoc *psoc) 6086 { 6087 return NULL; 6088 } 6089 #endif 6090 6091 void reg_update_nol_ch_for_freq(struct wlan_objmgr_pdev *pdev, 6092 uint16_t *chan_freq_list, 6093 uint8_t num_chan, 6094 bool nol_chan) 6095 { 6096 enum channel_enum chan_enum; 6097 struct regulatory_channel *mas_chan_list = NULL, *psoc_mas_chan_list; 6098 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6099 struct wlan_objmgr_psoc *psoc; 6100 uint16_t i; 6101 6102 if (!num_chan || !chan_freq_list) { 6103 reg_err("chan_freq_list or num_ch is NULL"); 6104 return; 6105 } 6106 6107 psoc = wlan_pdev_get_psoc(pdev); 6108 6109 6110 psoc_mas_chan_list = reg_get_psoc_mas_chan_list(pdev, psoc); 6111 pdev_priv_obj = reg_get_pdev_obj(pdev); 6112 6113 if (pdev_priv_obj) 6114 mas_chan_list = pdev_priv_obj->mas_chan_list; 6115 6116 for (i = 0; i < num_chan; i++) { 6117 chan_enum = reg_get_chan_enum_for_freq(chan_freq_list[i]); 6118 if (reg_is_chan_enum_invalid(chan_enum)) { 6119 reg_err("Invalid freq in nol list, freq %d", 6120 chan_freq_list[i]); 6121 continue; 6122 } 6123 if (mas_chan_list) 6124 mas_chan_list[chan_enum].nol_chan = nol_chan; 6125 if (psoc_mas_chan_list) 6126 psoc_mas_chan_list[chan_enum].nol_chan = nol_chan; 6127 } 6128 6129 if (!pdev_priv_obj) { 6130 reg_err("reg pdev private obj is NULL"); 6131 return; 6132 } 6133 6134 reg_compute_pdev_current_chan_list(pdev_priv_obj); 6135 6136 reg_send_scheduler_msg_sb(psoc, pdev); 6137 } 6138 6139 void reg_update_nol_history_ch_for_freq(struct wlan_objmgr_pdev *pdev, 6140 uint16_t *chan_list, 6141 uint8_t num_chan, 6142 bool nol_history_chan) 6143 { 6144 enum channel_enum chan_enum; 6145 struct regulatory_channel *mas_chan_list; 6146 struct regulatory_channel *cur_chan_list; 6147 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6148 uint16_t i; 6149 6150 if (!num_chan || !chan_list) { 6151 reg_err("chan_list or num_ch is NULL"); 6152 return; 6153 } 6154 6155 pdev_priv_obj = wlan_objmgr_pdev_get_comp_private_obj( 6156 pdev, WLAN_UMAC_COMP_REGULATORY); 6157 6158 if (!pdev_priv_obj) { 6159 reg_err("reg psoc private obj is NULL"); 6160 return; 6161 } 6162 6163 mas_chan_list = pdev_priv_obj->mas_chan_list; 6164 cur_chan_list = pdev_priv_obj->cur_chan_list; 6165 6166 for (i = 0; i < num_chan; i++) { 6167 chan_enum = reg_get_chan_enum_for_freq(chan_list[i]); 6168 if (reg_is_chan_enum_invalid(chan_enum)) { 6169 reg_err("Invalid ch in nol list, chan %d", 6170 chan_list[i]); 6171 continue; 6172 } 6173 mas_chan_list[chan_enum].nol_history = nol_history_chan; 6174 cur_chan_list[chan_enum].nol_history = nol_history_chan; 6175 } 6176 } 6177 6178 qdf_freq_t reg_min_chan_freq(void) 6179 { 6180 return channel_map[MIN_24GHZ_CHANNEL].center_freq; 6181 } 6182 6183 qdf_freq_t reg_max_chan_freq(void) 6184 { 6185 return channel_map[NUM_CHANNELS - 1].center_freq; 6186 } 6187 6188 bool reg_is_same_band_freqs(qdf_freq_t freq1, qdf_freq_t freq2) 6189 { 6190 return (freq1 && freq2 && ((REG_IS_6GHZ_FREQ(freq1) && 6191 REG_IS_6GHZ_FREQ(freq2)) || 6192 (REG_IS_5GHZ_FREQ(freq1) && 6193 REG_IS_5GHZ_FREQ(freq2)) || 6194 (REG_IS_24GHZ_CH_FREQ(freq1) && 6195 REG_IS_24GHZ_CH_FREQ(freq2)))); 6196 } 6197 6198 enum reg_wifi_band reg_freq_to_band(qdf_freq_t freq) 6199 { 6200 if (!freq) 6201 return REG_BAND_UNKNOWN; 6202 6203 if (REG_IS_24GHZ_CH_FREQ(freq)) 6204 return REG_BAND_2G; 6205 else if (REG_IS_5GHZ_FREQ(freq) || REG_IS_49GHZ_FREQ(freq)) 6206 return REG_BAND_5G; 6207 else if (REG_IS_6GHZ_FREQ(freq)) 6208 return REG_BAND_6G; 6209 return REG_BAND_UNKNOWN; 6210 } 6211 6212 #ifdef CONFIG_REG_6G_PWRMODE 6213 bool reg_is_disable_for_pwrmode(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq, 6214 enum supported_6g_pwr_types in_6g_pwr_mode) 6215 { 6216 enum channel_state ch_state; 6217 6218 ch_state = reg_get_channel_state_for_pwrmode(pdev, 6219 freq, 6220 in_6g_pwr_mode); 6221 6222 return (ch_state == CHANNEL_STATE_DISABLE) || 6223 (ch_state == CHANNEL_STATE_INVALID); 6224 } 6225 #endif 6226 6227 #ifdef CONFIG_REG_CLIENT 6228 bool reg_is_disable_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev, 6229 qdf_freq_t freq) 6230 { 6231 enum channel_state ch_state; 6232 6233 ch_state = reg_get_channel_state_from_secondary_list_for_freq(pdev, 6234 freq); 6235 6236 return ch_state == CHANNEL_STATE_DISABLE; 6237 } 6238 6239 bool reg_is_enable_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev, 6240 qdf_freq_t freq) 6241 { 6242 enum channel_state ch_state; 6243 6244 ch_state = reg_get_channel_state_from_secondary_list_for_freq(pdev, 6245 freq); 6246 6247 return ch_state == CHANNEL_STATE_ENABLE; 6248 } 6249 6250 #ifdef CONFIG_BAND_6GHZ 6251 static uint8_t reg_get_max_tx_power_from_super_chan_list( 6252 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 6253 enum supported_6g_pwr_types in_6g_pwr_type) 6254 { 6255 struct super_chan_info *sc_entry; 6256 enum supported_6g_pwr_types pwr_type; 6257 uint8_t i, max_tx_power = 0; 6258 6259 pwr_type = in_6g_pwr_type; 6260 for (i = 0; i < NUM_6GHZ_CHANNELS; i++) { 6261 sc_entry = &pdev_priv_obj->super_chan_list[i]; 6262 6263 if (in_6g_pwr_type == REG_BEST_PWR_MODE) 6264 pwr_type = sc_entry->best_power_mode; 6265 6266 if (reg_is_supp_pwr_mode_invalid(pwr_type)) 6267 continue; 6268 6269 if (!reg_is_chan_disabled(sc_entry->chan_flags_arr[pwr_type], 6270 sc_entry->state_arr[pwr_type]) && 6271 (sc_entry->reg_chan_pwr[pwr_type].tx_power > max_tx_power)) 6272 max_tx_power = 6273 sc_entry->reg_chan_pwr[pwr_type].tx_power; 6274 } 6275 return max_tx_power; 6276 } 6277 #else 6278 static inline uint8_t reg_get_max_tx_power_from_super_chan_list( 6279 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 6280 enum supported_6g_pwr_types in_6g_pwr_type) 6281 { 6282 return 0; 6283 } 6284 #endif 6285 6286 uint8_t reg_get_max_tx_power_for_pwr_mode( 6287 struct wlan_objmgr_pdev *pdev, 6288 enum supported_6g_pwr_types in_6g_pwr_type) 6289 { 6290 uint8_t i, max_tx_power = 0, max_super_chan_power = 0; 6291 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6292 uint16_t max_curr_num_chan; 6293 6294 if (!pdev) { 6295 reg_err_rl("invalid pdev"); 6296 return QDF_STATUS_E_INVAL; 6297 } 6298 6299 pdev_priv_obj = reg_get_pdev_obj(pdev); 6300 6301 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6302 reg_err_rl("reg pdev priv obj is NULL"); 6303 return QDF_STATUS_E_INVAL; 6304 } 6305 6306 if (in_6g_pwr_type == REG_CURRENT_PWR_MODE) 6307 max_curr_num_chan = NUM_CHANNELS; 6308 else 6309 max_curr_num_chan = MAX_5GHZ_CHANNEL; 6310 6311 for (i = 0; i < max_curr_num_chan; i++) { 6312 if (!reg_is_chan_disabled( 6313 pdev_priv_obj->cur_chan_list[i].chan_flags, 6314 pdev_priv_obj->cur_chan_list[i].state) && 6315 (pdev_priv_obj->cur_chan_list[i].tx_power > max_tx_power)) 6316 max_tx_power = 6317 pdev_priv_obj->cur_chan_list[i].tx_power; 6318 } 6319 6320 if (in_6g_pwr_type == REG_CURRENT_PWR_MODE) 6321 goto return_max_tx_power; 6322 6323 max_super_chan_power = reg_get_max_tx_power_from_super_chan_list( 6324 pdev_priv_obj, 6325 in_6g_pwr_type); 6326 6327 if (max_super_chan_power > max_tx_power) 6328 max_tx_power = max_super_chan_power; 6329 6330 return_max_tx_power: 6331 6332 if (!max_tx_power) 6333 reg_err_rl("max_tx_power is zero"); 6334 6335 return max_tx_power; 6336 } 6337 #endif 6338 6339 bool reg_is_passive_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 6340 { 6341 uint32_t chan_flags; 6342 6343 chan_flags = reg_get_channel_flags_for_freq(pdev, freq); 6344 6345 return chan_flags & REGULATORY_CHAN_NO_IR; 6346 } 6347 #endif /* CONFIG_CHAN_FREQ_API */ 6348 6349 uint8_t reg_get_max_tx_power(struct wlan_objmgr_pdev *pdev) 6350 { 6351 struct regulatory_channel *cur_chan_list; 6352 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6353 uint8_t i, max_tx_power = 0; 6354 6355 pdev_priv_obj = reg_get_pdev_obj(pdev); 6356 6357 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6358 reg_err("reg pdev private obj is NULL"); 6359 return QDF_STATUS_E_FAILURE; 6360 } 6361 6362 cur_chan_list = pdev_priv_obj->cur_chan_list; 6363 6364 for (i = 0; i < NUM_CHANNELS; i++) { 6365 if (cur_chan_list[i].state != CHANNEL_STATE_DISABLE && 6366 cur_chan_list[i].chan_flags != REGULATORY_CHAN_DISABLED) { 6367 if (cur_chan_list[i].tx_power > max_tx_power) 6368 max_tx_power = cur_chan_list[i].tx_power; 6369 } 6370 } 6371 6372 if (!max_tx_power) 6373 reg_err_rl("max_tx_power is zero"); 6374 6375 return max_tx_power; 6376 } 6377 6378 QDF_STATUS reg_set_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc) 6379 { 6380 struct wlan_regulatory_psoc_priv_obj *psoc_reg; 6381 6382 psoc_reg = reg_get_psoc_obj(psoc); 6383 if (!IS_VALID_PSOC_REG_OBJ(psoc_reg)) { 6384 reg_err("psoc reg component is NULL"); 6385 return QDF_STATUS_E_INVAL; 6386 } 6387 6388 psoc_reg->ignore_fw_reg_offload_ind = true; 6389 return QDF_STATUS_SUCCESS; 6390 } 6391 6392 bool reg_get_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc) 6393 { 6394 struct wlan_regulatory_psoc_priv_obj *psoc_reg; 6395 6396 psoc_reg = reg_get_psoc_obj(psoc); 6397 if (!IS_VALID_PSOC_REG_OBJ(psoc_reg)) 6398 return false; 6399 6400 return psoc_reg->ignore_fw_reg_offload_ind; 6401 } 6402 6403 QDF_STATUS reg_set_6ghz_supported(struct wlan_objmgr_psoc *psoc, bool val) 6404 { 6405 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6406 6407 psoc_priv_obj = reg_get_psoc_obj(psoc); 6408 6409 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6410 reg_err("psoc reg component is NULL"); 6411 return QDF_STATUS_E_FAILURE; 6412 } 6413 6414 psoc_priv_obj->six_ghz_supported = val; 6415 6416 return QDF_STATUS_SUCCESS; 6417 } 6418 6419 QDF_STATUS 6420 reg_set_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc, bool val) 6421 { 6422 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6423 6424 psoc_priv_obj = reg_get_psoc_obj(psoc); 6425 6426 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6427 reg_err("psoc reg component is NULL"); 6428 return QDF_STATUS_E_FAILURE; 6429 } 6430 6431 psoc_priv_obj->five_dot_nine_ghz_supported = val; 6432 6433 return QDF_STATUS_SUCCESS; 6434 } 6435 6436 #ifdef CONFIG_REG_CLIENT 6437 bool reg_is_6ghz_supported(struct wlan_objmgr_psoc *psoc) 6438 { 6439 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6440 6441 psoc_priv_obj = reg_get_psoc_obj(psoc); 6442 6443 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6444 reg_err("psoc reg component is NULL"); 6445 return false; 6446 } 6447 6448 return psoc_priv_obj->six_ghz_supported; 6449 } 6450 #endif 6451 6452 bool reg_is_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc) 6453 { 6454 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6455 6456 psoc_priv_obj = reg_get_psoc_obj(psoc); 6457 6458 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6459 reg_err("psoc reg component is NULL"); 6460 return false; 6461 } 6462 6463 return psoc_priv_obj->five_dot_nine_ghz_supported; 6464 } 6465 6466 bool reg_is_fcc_regdmn(struct wlan_objmgr_pdev *pdev) 6467 { 6468 struct cur_regdmn_info cur_reg_dmn; 6469 QDF_STATUS status; 6470 6471 status = reg_get_curr_regdomain(pdev, &cur_reg_dmn); 6472 if (status != QDF_STATUS_SUCCESS) { 6473 reg_debug_rl("Failed to get reg domain"); 6474 return false; 6475 } 6476 6477 return reg_fcc_regdmn(cur_reg_dmn.dmn_id_5g); 6478 } 6479 6480 bool reg_is_5dot9_ghz_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 6481 { 6482 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6483 6484 pdev_priv_obj = reg_get_pdev_obj(pdev); 6485 6486 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6487 reg_err("reg pdev priv obj is NULL"); 6488 return false; 6489 } 6490 6491 return (freq >= channel_map_us[MIN_5DOT9_CHANNEL].center_freq && 6492 freq <= channel_map_us[MAX_5DOT9_CHANNEL].center_freq); 6493 } 6494 6495 bool reg_is_5dot9_ghz_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev) 6496 { 6497 struct wlan_objmgr_psoc *psoc; 6498 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6499 6500 if (!pdev) { 6501 reg_alert("pdev is NULL"); 6502 return true; 6503 } 6504 psoc = wlan_pdev_get_psoc(pdev); 6505 6506 psoc_priv_obj = reg_get_psoc_obj(psoc); 6507 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6508 reg_alert("psoc reg component is NULL"); 6509 return true; 6510 } 6511 6512 return psoc_priv_obj->enable_5dot9_ghz_chan_in_master_mode; 6513 } 6514 6515 #ifdef DISABLE_UNII_SHARED_BANDS 6516 QDF_STATUS 6517 reg_get_unii_5g_bitmap(struct wlan_objmgr_pdev *pdev, uint8_t *bitmap) 6518 { 6519 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6520 6521 pdev_priv_obj = reg_get_pdev_obj(pdev); 6522 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6523 reg_err_rl("pdev reg component is NULL"); 6524 return QDF_STATUS_E_FAILURE; 6525 } 6526 *bitmap = pdev_priv_obj->unii_5g_bitmap; 6527 6528 return QDF_STATUS_SUCCESS; 6529 } 6530 #endif 6531 6532 #ifdef WLAN_FEATURE_11BE 6533 bool reg_is_phymode_unallowed(enum reg_phymode phy_in, uint32_t phymode_bitmap) 6534 { 6535 if (!phymode_bitmap) 6536 return false; 6537 6538 if (phy_in == REG_PHYMODE_11BE) 6539 return phymode_bitmap & REGULATORY_PHYMODE_NO11BE; 6540 else if (phy_in == REG_PHYMODE_11AX) 6541 return phymode_bitmap & REGULATORY_PHYMODE_NO11AX; 6542 else if (phy_in == REG_PHYMODE_11AC) 6543 return phymode_bitmap & REGULATORY_PHYMODE_NO11AC; 6544 else if (phy_in == REG_PHYMODE_11N) 6545 return phymode_bitmap & REGULATORY_CHAN_NO11N; 6546 else if (phy_in == REG_PHYMODE_11G) 6547 return phymode_bitmap & REGULATORY_PHYMODE_NO11G; 6548 else if (phy_in == REG_PHYMODE_11A) 6549 return phymode_bitmap & REGULATORY_PHYMODE_NO11A; 6550 else if (phy_in == REG_PHYMODE_11B) 6551 return phymode_bitmap & REGULATORY_PHYMODE_NO11B; 6552 else 6553 return true; 6554 } 6555 #else 6556 bool reg_is_phymode_unallowed(enum reg_phymode phy_in, uint32_t phymode_bitmap) 6557 { 6558 if (!phymode_bitmap) 6559 return false; 6560 6561 if (phy_in == REG_PHYMODE_11AX) 6562 return phymode_bitmap & REGULATORY_PHYMODE_NO11AX; 6563 else if (phy_in == REG_PHYMODE_11AC) 6564 return phymode_bitmap & REGULATORY_PHYMODE_NO11AC; 6565 else if (phy_in == REG_PHYMODE_11N) 6566 return phymode_bitmap & REGULATORY_CHAN_NO11N; 6567 else if (phy_in == REG_PHYMODE_11G) 6568 return phymode_bitmap & REGULATORY_PHYMODE_NO11G; 6569 else if (phy_in == REG_PHYMODE_11A) 6570 return phymode_bitmap & REGULATORY_PHYMODE_NO11A; 6571 else if (phy_in == REG_PHYMODE_11B) 6572 return phymode_bitmap & REGULATORY_PHYMODE_NO11B; 6573 else 6574 return true; 6575 } 6576 #endif 6577 6578 #ifdef CHECK_REG_PHYMODE 6579 enum reg_phymode reg_get_max_phymode(struct wlan_objmgr_pdev *pdev, 6580 enum reg_phymode phy_in, 6581 qdf_freq_t freq) 6582 { 6583 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6584 uint32_t phymode_bitmap; 6585 enum reg_phymode current_phymode = phy_in; 6586 6587 pdev_priv_obj = reg_get_pdev_obj(pdev); 6588 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6589 reg_err("pdev reg component is NULL"); 6590 return REG_PHYMODE_INVALID; 6591 } 6592 6593 phymode_bitmap = pdev_priv_obj->phybitmap; 6594 6595 while (1) { 6596 if (reg_is_phymode_unallowed(current_phymode, phymode_bitmap)) { 6597 if (current_phymode == REG_PHYMODE_11N) { 6598 if (REG_IS_24GHZ_CH_FREQ(freq)) 6599 current_phymode = REG_PHYMODE_11G; 6600 else 6601 current_phymode = REG_PHYMODE_11A; 6602 } else if (current_phymode == REG_PHYMODE_11A || 6603 current_phymode == REG_PHYMODE_11B) { 6604 reg_err("Couldn't find a suitable phymode"); 6605 return REG_PHYMODE_INVALID; 6606 } else if (current_phymode > REG_PHYMODE_MAX) { 6607 reg_err("Unknown phymode"); 6608 return REG_PHYMODE_INVALID; 6609 } else { 6610 current_phymode--; 6611 } 6612 } else { 6613 return current_phymode; 6614 } 6615 } 6616 } 6617 #endif /* CHECK_REG_PHYMODE */ 6618 6619 #ifdef CONFIG_REG_CLIENT 6620 enum band_info reg_band_bitmap_to_band_info(uint32_t band_bitmap) 6621 { 6622 if ((band_bitmap & BIT(REG_BAND_2G)) && 6623 (band_bitmap & BIT(REG_BAND_5G)) && 6624 (band_bitmap & BIT(REG_BAND_6G))) 6625 return BAND_ALL; 6626 else if ((band_bitmap & BIT(REG_BAND_5G)) && 6627 (band_bitmap & BIT(REG_BAND_6G))) 6628 return BAND_5G; 6629 else if ((band_bitmap & BIT(REG_BAND_2G)) && 6630 (band_bitmap & BIT(REG_BAND_6G))) 6631 return BAND_2G; 6632 else if ((band_bitmap & BIT(REG_BAND_2G)) && 6633 (band_bitmap & BIT(REG_BAND_5G))) 6634 return BAND_ALL; 6635 else if (band_bitmap & BIT(REG_BAND_2G)) 6636 return BAND_2G; 6637 else if (band_bitmap & BIT(REG_BAND_5G)) 6638 return BAND_5G; 6639 else if (band_bitmap & BIT(REG_BAND_6G)) 6640 return BAND_2G; 6641 else 6642 return BAND_UNKNOWN; 6643 } 6644 6645 QDF_STATUS 6646 reg_update_tx_power_on_ctry_change(struct wlan_objmgr_pdev *pdev, 6647 uint8_t vdev_id) 6648 { 6649 struct wlan_objmgr_psoc *psoc; 6650 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6651 reg_ctry_change_callback callback = NULL; 6652 6653 psoc = wlan_pdev_get_psoc(pdev); 6654 psoc_priv_obj = reg_get_psoc_obj(psoc); 6655 if (!psoc_priv_obj) { 6656 reg_err("reg psoc private obj is NULL"); 6657 return QDF_STATUS_E_FAILURE; 6658 } 6659 6660 qdf_spin_lock_bh(&psoc_priv_obj->cbk_list_lock); 6661 if (psoc_priv_obj->cc_cbk.cbk) 6662 callback = psoc_priv_obj->cc_cbk.cbk; 6663 qdf_spin_unlock_bh(&psoc_priv_obj->cbk_list_lock); 6664 if (callback) 6665 callback(vdev_id); 6666 6667 return QDF_STATUS_SUCCESS; 6668 } 6669 6670 QDF_STATUS 6671 reg_add_indoor_concurrency(struct wlan_objmgr_pdev *pdev, uint8_t vdev_id, 6672 uint32_t freq, enum phy_ch_width width) 6673 { 6674 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6675 struct indoor_concurrency_list *list; 6676 const struct bonded_channel_freq *range = NULL; 6677 uint8_t i = 0; 6678 6679 pdev_priv_obj = reg_get_pdev_obj(pdev); 6680 6681 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6682 reg_err("pdev reg component is NULL"); 6683 return QDF_STATUS_E_FAILURE; 6684 } 6685 6686 if (width > CH_WIDTH_20MHZ) 6687 range = wlan_reg_get_bonded_chan_entry(freq, width, 0); 6688 6689 list = &pdev_priv_obj->indoor_list[0]; 6690 for (i = 0; i < MAX_INDOOR_LIST_SIZE; i++, list++) { 6691 if (list->freq == 0 && list->vdev_id == INVALID_VDEV_ID) { 6692 list->freq = freq; 6693 list->vdev_id = vdev_id; 6694 list->chan_range = range; 6695 reg_debug("Added freq %d vdev %d width %d at idx %d", 6696 freq, vdev_id, width, i); 6697 return QDF_STATUS_SUCCESS; 6698 } 6699 } 6700 reg_err("Unable to add indoor concurrency for vdev %d freq %d width %d", 6701 vdev_id, freq, width); 6702 return QDF_STATUS_E_FAILURE; 6703 } 6704 6705 QDF_STATUS 6706 reg_remove_indoor_concurrency(struct wlan_objmgr_pdev *pdev, uint8_t vdev_id, 6707 uint32_t freq) 6708 { 6709 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6710 struct indoor_concurrency_list *list; 6711 uint8_t i = 0; 6712 6713 pdev_priv_obj = reg_get_pdev_obj(pdev); 6714 6715 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6716 reg_err("pdev reg component is NULL"); 6717 return QDF_STATUS_E_FAILURE; 6718 } 6719 6720 list = &pdev_priv_obj->indoor_list[0]; 6721 for (i = 0; i < MAX_INDOOR_LIST_SIZE; i++, list++) { 6722 if (list->freq == freq || 6723 (vdev_id != INVALID_VDEV_ID && list->vdev_id == vdev_id)) { 6724 reg_debug("Removed freq %d from idx %d", list->freq, i); 6725 list->freq = 0; 6726 list->vdev_id = INVALID_VDEV_ID; 6727 list->chan_range = NULL; 6728 return QDF_STATUS_SUCCESS; 6729 } 6730 continue; 6731 } 6732 6733 return QDF_STATUS_E_FAILURE; 6734 } 6735 6736 void 6737 reg_init_indoor_channel_list(struct wlan_objmgr_pdev *pdev) 6738 { 6739 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6740 struct indoor_concurrency_list *list; 6741 uint8_t i; 6742 6743 pdev_priv_obj = reg_get_pdev_obj(pdev); 6744 6745 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6746 reg_debug("reg pdev priv obj is NULL"); 6747 return; 6748 } 6749 6750 list = pdev_priv_obj->indoor_list; 6751 for (i = 0; i < MAX_INDOOR_LIST_SIZE; i++, list++) { 6752 list->freq = 0; 6753 list->vdev_id = INVALID_VDEV_ID; 6754 list->chan_range = NULL; 6755 } 6756 } 6757 6758 QDF_STATUS 6759 reg_compute_indoor_list_on_cc_change(struct wlan_objmgr_psoc *psoc, 6760 struct wlan_objmgr_pdev *pdev) 6761 { 6762 struct wlan_objmgr_vdev *vdev; 6763 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6764 struct wlan_channel *des_chan; 6765 enum channel_enum chan_enum; 6766 uint8_t vdev_id; 6767 6768 pdev_priv_obj = reg_get_pdev_obj(pdev); 6769 6770 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6771 reg_err("reg pdev priv obj is NULL"); 6772 return QDF_STATUS_E_FAILURE; 6773 } 6774 6775 if (pdev_priv_obj->indoor_chan_enabled || 6776 !pdev_priv_obj->sta_sap_scc_on_indoor_channel) 6777 return QDF_STATUS_SUCCESS; 6778 6779 /* Iterate through VDEV list */ 6780 for (vdev_id = 0; vdev_id < WLAN_UMAC_PSOC_MAX_VDEVS; vdev_id++) { 6781 vdev = 6782 wlan_objmgr_get_vdev_by_id_from_psoc(psoc, vdev_id, 6783 WLAN_REGULATORY_SB_ID); 6784 if (!vdev) 6785 continue; 6786 6787 if (vdev->vdev_mlme.vdev_opmode != QDF_STA_MODE && 6788 vdev->vdev_mlme.vdev_opmode != QDF_P2P_CLIENT_MODE) 6789 goto next; 6790 6791 des_chan = vdev->vdev_mlme.des_chan; 6792 if (!des_chan) 6793 goto next; 6794 6795 if (!reg_is_5ghz_ch_freq(des_chan->ch_freq)) 6796 goto next; 6797 6798 chan_enum = reg_get_chan_enum_for_freq(des_chan->ch_freq); 6799 if (reg_is_chan_enum_invalid(chan_enum)) { 6800 reg_err_rl("Invalid chan enum %d", chan_enum); 6801 goto next; 6802 } 6803 6804 if (pdev_priv_obj->mas_chan_list[chan_enum].state != 6805 CHANNEL_STATE_DISABLE && 6806 pdev_priv_obj->mas_chan_list[chan_enum].chan_flags & 6807 REGULATORY_CHAN_INDOOR_ONLY) 6808 reg_add_indoor_concurrency(pdev, vdev_id, 6809 des_chan->ch_freq, 6810 des_chan->ch_width); 6811 6812 next: 6813 wlan_objmgr_vdev_release_ref(vdev, WLAN_REGULATORY_SB_ID); 6814 } 6815 6816 return QDF_STATUS_SUCCESS; 6817 } 6818 #endif 6819 6820 #if defined(CONFIG_BAND_6GHZ) 6821 QDF_STATUS 6822 reg_set_cur_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev, 6823 enum reg_6g_ap_type reg_cur_6g_ap_pwr_type) 6824 { 6825 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6826 6827 pdev_priv_obj = reg_get_pdev_obj(pdev); 6828 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6829 reg_err("pdev reg component is NULL"); 6830 return QDF_STATUS_E_FAILURE; 6831 } 6832 6833 if (reg_cur_6g_ap_pwr_type > REG_MAX_SUPP_AP_TYPE) { 6834 reg_err("Unsupported 6G AP power type"); 6835 return QDF_STATUS_E_FAILURE; 6836 } 6837 /* should we validate the input reg_cur_6g_ap_type? */ 6838 pdev_priv_obj->reg_cur_6g_ap_pwr_type = reg_cur_6g_ap_pwr_type; 6839 return QDF_STATUS_SUCCESS; 6840 } 6841 6842 QDF_STATUS 6843 reg_get_cur_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev, 6844 enum reg_6g_ap_type *reg_cur_6g_ap_pwr_type) 6845 { 6846 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6847 6848 pdev_priv_obj = reg_get_pdev_obj(pdev); 6849 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6850 reg_err("pdev reg component is NULL"); 6851 return QDF_STATUS_E_FAILURE; 6852 } 6853 6854 if (pdev_priv_obj->reg_cur_6g_ap_pwr_type >= REG_CURRENT_MAX_AP_TYPE) 6855 return QDF_STATUS_E_FAILURE; 6856 6857 *reg_cur_6g_ap_pwr_type = pdev_priv_obj->reg_cur_6g_ap_pwr_type; 6858 6859 return QDF_STATUS_SUCCESS; 6860 } 6861 6862 /** 6863 * reg_get_reg_rules_for_pdev() - Get the pointer to the reg rules for the pdev 6864 * @pdev: Pointer to pdev 6865 * 6866 * Return: Pointer to Standard Power regulatory rules 6867 */ 6868 static struct reg_rule_info * 6869 reg_get_reg_rules_for_pdev(struct wlan_objmgr_pdev *pdev) 6870 { 6871 struct wlan_objmgr_psoc *psoc; 6872 struct wlan_regulatory_psoc_priv_obj *psoc_reg_priv; 6873 uint8_t phy_id; 6874 struct reg_rule_info *psoc_reg_rules; 6875 6876 psoc = wlan_pdev_get_psoc(pdev); 6877 psoc_reg_priv = reg_get_psoc_obj(psoc); 6878 6879 if (!psoc_reg_priv) { 6880 reg_debug("Regulatory psoc private object is NULL"); 6881 return NULL; 6882 } 6883 6884 phy_id = wlan_objmgr_pdev_get_pdev_id(pdev); 6885 psoc_reg_rules = &psoc_reg_priv->mas_chan_params[phy_id].reg_rules; 6886 6887 return psoc_reg_rules; 6888 } 6889 6890 uint8_t 6891 reg_get_num_rules_of_ap_pwr_type(struct wlan_objmgr_pdev *pdev, 6892 enum reg_6g_ap_type ap_pwr_type) 6893 { 6894 struct reg_rule_info *psoc_reg_rules = reg_get_reg_rules_for_pdev(pdev); 6895 6896 if (!psoc_reg_rules) { 6897 reg_debug("No psoc_reg_rules"); 6898 return 0; 6899 } 6900 6901 if (ap_pwr_type > REG_MAX_SUPP_AP_TYPE) { 6902 reg_err("Unsupported 6G AP power type"); 6903 return 0; 6904 } 6905 6906 return psoc_reg_rules->num_of_6g_ap_reg_rules[ap_pwr_type]; 6907 } 6908 6909 #ifdef CONFIG_AFC_SUPPORT 6910 /** 6911 * reg_is_empty_range() - If both left, right frquency edges in the input range 6912 * are zero then the range is empty, else not. 6913 * @in_range: Pointer to input range 6914 * 6915 * Return: True if the range is empty, else false 6916 */ 6917 static bool reg_is_empty_range(struct freq_range *in_range) 6918 { 6919 return !in_range->left && !in_range->right; 6920 } 6921 6922 struct freq_range 6923 reg_init_freq_range(qdf_freq_t left, qdf_freq_t right) 6924 { 6925 struct freq_range out_range; 6926 6927 out_range.left = left; 6928 out_range.right = right; 6929 6930 return out_range; 6931 } 6932 6933 /** 6934 * reg_assign_vars_with_range_vals() - Assign input variables with the values of 6935 * the range variable values 6936 * @in_range: Pointer to input range object 6937 * @left: Pointer to the first variable to get the value of left frequency edge 6938 * @right: Pointer to the second variable to get the value of right frequency 6939 * edge 6940 * 6941 * Return: void 6942 */ 6943 static void 6944 reg_assign_vars_with_range_vals(struct freq_range *in_range, 6945 qdf_freq_t *left, 6946 qdf_freq_t *right) 6947 { 6948 *left = in_range->left; 6949 *right = in_range->right; 6950 } 6951 6952 /** 6953 * reg_intersect_ranges() - Intersect two ranges and return the intesected range 6954 * @first_range: Pointer to first input range 6955 * @second_range: Pointer to second input range 6956 * 6957 * Return: Intersected output range 6958 */ 6959 static struct freq_range 6960 reg_intersect_ranges(struct freq_range *first_range, 6961 struct freq_range *second_range) 6962 { 6963 struct freq_range out_range; 6964 qdf_freq_t l_freq; 6965 qdf_freq_t r_freq; 6966 6967 /* validate if the ranges are proper */ 6968 6969 l_freq = QDF_MAX(first_range->left, second_range->left); 6970 r_freq = QDF_MIN(first_range->right, second_range->right); 6971 6972 if (l_freq > r_freq) { 6973 l_freq = 0; 6974 r_freq = 0; 6975 6976 reg_debug("Ranges do not overlap first= [%u, %u], second = [%u, %u]", 6977 first_range->left, 6978 first_range->right, 6979 second_range->left, 6980 second_range->right); 6981 } 6982 6983 out_range.left = l_freq; 6984 out_range.right = r_freq; 6985 6986 return out_range; 6987 } 6988 6989 /** 6990 * typedef reg_act_sp_rule_cb() - A function pointer type that calculates 6991 * something from the input frequency range 6992 * @rule_fr: Pointer to frequency range 6993 * @arg: Pointer to generic argument (a.k.a. context) 6994 * 6995 * Return: Void 6996 */ 6997 typedef void (*reg_act_sp_rule_cb)(struct freq_range *rule_fr, 6998 void *arg); 6999 7000 /** 7001 * reg_iterate_sp_rules() - Iterate through the Standard Power reg rules, for 7002 * every reg rule call the call back function to take some action or calculate 7003 * something 7004 * @pdev: Pointer to pdev 7005 * @pdev_priv_obj: Pointer to pdev private object 7006 * @sp_rule_action: A function pointer to take some action or calculate 7007 * something for every sp rule 7008 * @arg: Pointer to opque object (argument/context) 7009 * 7010 * Return: Void 7011 */ 7012 static void reg_iterate_sp_rules(struct wlan_objmgr_pdev *pdev, 7013 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 7014 reg_act_sp_rule_cb sp_rule_action, 7015 void *arg) 7016 { 7017 struct cur_reg_rule *p_sp_reg_rule; 7018 struct reg_rule_info *psoc_reg_rules; 7019 uint8_t n_6g_sp_ap_reg_rules; 7020 qdf_freq_t low_5g; 7021 qdf_freq_t high_5g; 7022 uint8_t i; 7023 struct freq_range chip_range; 7024 7025 psoc_reg_rules = reg_get_reg_rules_for_pdev(pdev); 7026 7027 if (!psoc_reg_rules) { 7028 reg_debug("psoc reg rule pointer is NULL"); 7029 return; 7030 } 7031 7032 n_6g_sp_ap_reg_rules = psoc_reg_rules->num_of_6g_ap_reg_rules[REG_STANDARD_POWER_AP]; 7033 p_sp_reg_rule = psoc_reg_rules->reg_rules_6g_ap[REG_STANDARD_POWER_AP]; 7034 7035 low_5g = pdev_priv_obj->range_5g_low; 7036 high_5g = pdev_priv_obj->range_5g_high; 7037 7038 chip_range = reg_init_freq_range(low_5g, high_5g); 7039 7040 reg_debug("chip_range = [%u, %u]", low_5g, high_5g); 7041 reg_debug("Num_6g_rules = %u", n_6g_sp_ap_reg_rules); 7042 7043 for (i = 0; i < n_6g_sp_ap_reg_rules; i++) { 7044 struct freq_range sp_range; 7045 struct freq_range out_range; 7046 7047 sp_range = reg_init_freq_range(p_sp_reg_rule->start_freq, 7048 p_sp_reg_rule->end_freq); 7049 reg_debug("Rule:[%u, %u]", 7050 p_sp_reg_rule->start_freq, 7051 p_sp_reg_rule->end_freq); 7052 out_range = reg_intersect_ranges(&chip_range, &sp_range); 7053 7054 if (sp_rule_action) 7055 sp_rule_action(&out_range, arg); 7056 7057 p_sp_reg_rule++; 7058 } 7059 } 7060 7061 /** 7062 * reg_afc_incr_num_ranges() - Increment the number of frequency ranges 7063 * @p_range: Pointer to frequency range 7064 * @num_freq_ranges: Pointer to number of frequency ranges. This needs to be 7065 * (Actual type: uint8_t *num_freq_ranges) 7066 * incremented by the function 7067 * 7068 * Return: Void 7069 */ 7070 static void reg_afc_incr_num_ranges(struct freq_range *p_range, 7071 void *num_freq_ranges) 7072 { 7073 if (!reg_is_empty_range(p_range)) 7074 (*(uint8_t *)num_freq_ranges)++; 7075 } 7076 7077 /** 7078 * reg_get_num_sp_freq_ranges() - Find the number of reg rules from the Standard 7079 * power regulatory rules 7080 * @pdev: Pointer to pdev 7081 * @pdev_priv_obj: Pointer to pdev private object 7082 * 7083 * Return: number of frequency ranges 7084 */ 7085 static uint8_t reg_get_num_sp_freq_ranges(struct wlan_objmgr_pdev *pdev, 7086 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 7087 { 7088 uint8_t num_freq_ranges; 7089 7090 num_freq_ranges = 0; 7091 reg_iterate_sp_rules(pdev, 7092 pdev_priv_obj, 7093 reg_afc_incr_num_ranges, 7094 &num_freq_ranges); 7095 7096 reg_debug("Num_freq_ranges=%u", num_freq_ranges); 7097 return num_freq_ranges; 7098 } 7099 7100 /** 7101 * reg_afc_get_intersected_ranges() - Get the intersected range into range obj 7102 * @rule_fr: Pointer to the rule for frequency range 7103 * @arg: Pointer to opaque object (argument/context) 7104 * (Actual type: struct wlan_afc_freq_range_obj **p_range_obj) 7105 * incremented by the function 7106 * 7107 * Return: Void 7108 */ 7109 static void reg_afc_get_intersected_ranges(struct freq_range *rule_fr, 7110 void *arg) 7111 { 7112 struct wlan_afc_freq_range_obj *p_range; 7113 struct wlan_afc_freq_range_obj **pp_range; 7114 qdf_freq_t low, high; 7115 7116 pp_range = (struct wlan_afc_freq_range_obj **)arg; 7117 p_range = *pp_range; 7118 7119 if (!reg_is_empty_range(rule_fr)) { 7120 reg_assign_vars_with_range_vals(rule_fr, &low, &high); 7121 p_range->lowfreq = (uint16_t)low; 7122 p_range->highfreq = (uint16_t)high; 7123 reg_debug("Range = [%u, %u]", p_range->lowfreq, p_range->highfreq); 7124 (*pp_range)++; 7125 } 7126 } 7127 7128 /** 7129 * reg_cp_freq_ranges() - Copy frequency ranges from the Standard power 7130 * regulatory rules 7131 * @pdev: Pointer to pdev 7132 * @pdev_priv_obj: Pointer to pdev private object 7133 * @num_freq_ranges: Number of frequency ranges 7134 * @p_range_obj: Pointer to range object 7135 * 7136 * Return: void 7137 */ 7138 static void reg_cp_freq_ranges(struct wlan_objmgr_pdev *pdev, 7139 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 7140 uint8_t num_freq_ranges, 7141 struct wlan_afc_freq_range_obj *p_range_obj) 7142 { 7143 struct wlan_afc_freq_range_obj *p_range; 7144 7145 reg_debug("Num freq ranges = %u", num_freq_ranges); 7146 7147 p_range = p_range_obj; 7148 reg_iterate_sp_rules(pdev, 7149 pdev_priv_obj, 7150 reg_afc_get_intersected_ranges, 7151 &p_range); 7152 } 7153 7154 /** 7155 * reg_fill_afc_freq_ranges() - Allocate memory for and fill the AFC frequency 7156 * range lists. 7157 * @pdev: Pointer to pdev 7158 * @pdev_priv_obj: Pointer to pdev private object 7159 * @p_frange_lst: Pointer to frequency range list 7160 * @num_freq_ranges: Number of frequency ranges 7161 * 7162 * Return: QDF_STATUS 7163 */ 7164 static inline QDF_STATUS 7165 reg_fill_afc_freq_ranges(struct wlan_objmgr_pdev *pdev, 7166 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 7167 struct wlan_afc_frange_list *p_frange_lst, 7168 uint8_t num_freq_ranges) 7169 { 7170 struct wlan_afc_freq_range_obj *p_range_obj; 7171 7172 p_frange_lst->num_ranges = num_freq_ranges; 7173 if (!num_freq_ranges) 7174 return QDF_STATUS_E_INVAL; 7175 7176 p_range_obj = qdf_mem_malloc(num_freq_ranges * sizeof(*p_range_obj)); 7177 if (!p_range_obj) 7178 return QDF_STATUS_E_NOMEM; 7179 7180 reg_cp_freq_ranges(pdev, pdev_priv_obj, num_freq_ranges, p_range_obj); 7181 7182 p_frange_lst->range_objs = p_range_obj; 7183 7184 return QDF_STATUS_SUCCESS; 7185 } 7186 7187 /** 7188 * reg_fill_afc_opclass_obj() - Fill the opclass object and return pointer to 7189 * next AFC opclass object 7190 * @p_obj_opclass_obj: Pointer to opclass object 7191 * @opclass: Operating class 7192 * @num_chans: Number of channels in the opclass 7193 * @p_chan_lst: Pointer to channel list 7194 * 7195 * Return: QDF_STATUS 7196 */ 7197 static QDF_STATUS 7198 reg_fill_afc_opclass_obj(struct wlan_afc_opclass_obj *p_obj_opclass_obj, 7199 uint8_t opclass, 7200 uint8_t num_chans, 7201 uint8_t *p_chan_lst) 7202 { 7203 uint8_t *src, *dst; 7204 uint8_t copy_len; 7205 7206 p_obj_opclass_obj->opclass_num_cfis = num_chans; 7207 p_obj_opclass_obj->opclass = opclass; 7208 /* Zero CFIs(opclass_num_cfis / num_chans) is a valid case */ 7209 if (!num_chans) 7210 return QDF_STATUS_SUCCESS; 7211 7212 src = p_chan_lst; 7213 copy_len = num_chans * sizeof(uint8_t); 7214 dst = qdf_mem_malloc(copy_len); 7215 if (!dst) 7216 return QDF_STATUS_E_NOMEM; 7217 7218 qdf_mem_copy(dst, src, copy_len); 7219 p_obj_opclass_obj->cfis = dst; 7220 7221 return QDF_STATUS_SUCCESS; 7222 } 7223 7224 /** 7225 * reg_free_afc_opclass_objs() - Free the memory allocated for AFC opclass 7226 * object. Each opclass object also contains a cfi array. Free the memory 7227 * allocated for the cfi array. 7228 * @opclass_objs: Pointer to opclass objects array. 7229 * @num_opclass_objs: Number of opclass objects. 7230 * 7231 * Return: void 7232 */ 7233 static void 7234 reg_free_afc_opclass_objs(struct wlan_afc_opclass_obj *opclass_objs, 7235 uint8_t num_opclass_objs) 7236 { 7237 uint8_t i; 7238 7239 for (i = 0; i < num_opclass_objs; i++) { 7240 struct wlan_afc_opclass_obj *opclass_obj; 7241 7242 opclass_obj = &opclass_objs[i]; 7243 qdf_mem_free(opclass_obj->cfis); 7244 } 7245 qdf_mem_free(opclass_objs); 7246 } 7247 7248 /** 7249 * reg_fill_afc_opclasses_arr() - Fill the array of opclass objects 7250 * @pdev: Pointer to pdev 7251 * @num_opclasses: The number of opclasses 7252 * @opclass_lst: The array of Operating classes 7253 * @chansize_lst: The array of sizes of channel lists 7254 * @channel_lists: The array of channel lists 7255 * @p_opclass_obj_arr: Pointer to the first opclass object 7256 * 7257 * Return: QDF_STATUS 7258 */ 7259 static QDF_STATUS 7260 reg_fill_afc_opclasses_arr(struct wlan_objmgr_pdev *pdev, 7261 uint8_t num_opclasses, 7262 uint8_t *opclass_lst, 7263 uint8_t *chansize_lst, 7264 uint8_t *channel_lists[], 7265 struct wlan_afc_opclass_obj *p_opclass_obj_arr) 7266 { 7267 uint16_t i; 7268 QDF_STATUS status; 7269 7270 for (i = 0; i < num_opclasses; i++) { 7271 struct wlan_afc_opclass_obj *p_opclass_obj; 7272 7273 p_opclass_obj = &p_opclass_obj_arr[i]; 7274 status = reg_fill_afc_opclass_obj(p_opclass_obj, 7275 opclass_lst[i], 7276 chansize_lst[i], 7277 channel_lists[i]); 7278 if (QDF_IS_STATUS_ERROR(status)) { 7279 reg_free_afc_opclass_objs(p_opclass_obj_arr, 7280 num_opclasses); 7281 return status; 7282 } 7283 } 7284 return QDF_STATUS_SUCCESS; 7285 } 7286 7287 /** 7288 * reg_print_afc_req_info_header_params() - Print the fixed param portion of the 7289 * AFC request information. 7290 * @afc_req: Pointer to AFC request 7291 * 7292 * Return: Void 7293 */ 7294 static void 7295 reg_print_afc_req_info_header_params(struct wlan_afc_host_request *afc_req) 7296 { 7297 reg_debug("req_id=%llu", afc_req->req_id); 7298 reg_debug("version_minor=%u", afc_req->version_minor); 7299 reg_debug("version_major=%u", afc_req->version_major); 7300 reg_debug("min_des_power=%hd", afc_req->min_des_power); 7301 } 7302 7303 /** 7304 * reg_print_afc_req_info_frange_list() - Print the list of frequency ranges 7305 * portion of the AFC request information. 7306 * @afc_req: Pointer to AFC request 7307 * 7308 * Return: Void 7309 */ 7310 static void 7311 reg_print_afc_req_info_frange_list(struct wlan_afc_host_request *afc_req) 7312 { 7313 struct wlan_afc_frange_list *p_frange_lst; 7314 uint8_t i; 7315 7316 p_frange_lst = afc_req->freq_lst; 7317 if (!p_frange_lst) { 7318 reg_debug("p_frange_lst is NULL"); 7319 return; 7320 } 7321 7322 reg_debug("num_ranges=%hhu", p_frange_lst->num_ranges); 7323 for (i = 0; i < p_frange_lst->num_ranges; i++) { 7324 struct wlan_afc_freq_range_obj *p_range_obj; 7325 7326 p_range_obj = &p_frange_lst->range_objs[i]; 7327 reg_debug("lowfreq=%hu", p_range_obj->lowfreq); 7328 reg_debug("highfreq=%hu", p_range_obj->highfreq); 7329 } 7330 } 7331 7332 /** 7333 * reg_print_afc_req_info_opclass_list() - Print the list of opclasses 7334 * and the corresponding CFIs supported in those opclasses. 7335 * @afc_req: Pointer to AFC request 7336 * 7337 * Return: Void 7338 */ 7339 static void 7340 reg_print_afc_req_info_opclass_list(struct wlan_afc_host_request *afc_req) 7341 { 7342 uint8_t i; 7343 uint8_t num_opclasses; 7344 struct wlan_afc_opclass_obj_list *p_opclass_obj_lst; 7345 struct wlan_afc_opclass_obj *p_opclass_obj; 7346 7347 p_opclass_obj_lst = afc_req->opclass_obj_lst; 7348 if (!p_opclass_obj_lst) { 7349 reg_debug("p_opclass_obj_lst is NULL"); 7350 return; 7351 } 7352 7353 num_opclasses = p_opclass_obj_lst->num_opclass_objs; 7354 reg_debug("num_opclasses=%hhu", num_opclasses); 7355 p_opclass_obj = p_opclass_obj_lst->opclass_objs; 7356 for (i = 0; i < num_opclasses; i++) { 7357 uint8_t opclass = p_opclass_obj[i].opclass; 7358 uint8_t num_cfis = p_opclass_obj[i].opclass_num_cfis; 7359 uint8_t *cfis = p_opclass_obj[i].cfis; 7360 uint8_t j; 7361 7362 reg_debug("opclass[%hhu]=%hhu", i, opclass); 7363 reg_debug("num_cfis[%hhu]=%hhu", i, num_cfis); 7364 reg_debug("["); 7365 for (j = 0; j < num_cfis; j++) 7366 reg_debug("%hhu,", cfis[j]); 7367 reg_debug("]"); 7368 } 7369 } 7370 7371 /** 7372 * reg_print_afc_req_info_location() - Print the location information in the afc 7373 * request. 7374 * @afc_req: Pointer to AFC request 7375 * 7376 * Return: Void 7377 */ 7378 static void 7379 reg_print_afc_req_info_location(struct wlan_afc_host_request *afc_req) 7380 { 7381 struct wlan_afc_location *p_afc_location; 7382 uint8_t *deployment_type_str; 7383 7384 p_afc_location = afc_req->afc_location; 7385 if (!p_afc_location) { 7386 reg_debug("p_afc_location is NULL"); 7387 return; 7388 } 7389 7390 switch (p_afc_location->deployment_type) { 7391 case AFC_DEPLOYMENT_INDOOR: 7392 deployment_type_str = "Indoor"; 7393 break; 7394 case AFC_DEPLOYMENT_OUTDOOR: 7395 deployment_type_str = "Outdoor"; 7396 break; 7397 default: 7398 deployment_type_str = "Unknown"; 7399 } 7400 reg_debug("AFC location=%s", deployment_type_str); 7401 } 7402 7403 void reg_print_afc_req_info(struct wlan_objmgr_pdev *pdev, 7404 struct wlan_afc_host_request *afc_req) 7405 { 7406 if (!afc_req) { 7407 reg_debug("afc_req is NULL"); 7408 return; 7409 } 7410 7411 reg_print_afc_req_info_header_params(afc_req); 7412 reg_print_afc_req_info_frange_list(afc_req); 7413 reg_print_afc_req_info_opclass_list(afc_req); 7414 reg_print_afc_req_info_location(afc_req); 7415 } 7416 7417 /** 7418 * reg_free_afc_freq_list() - Free the memory allocated for AFC frequency list 7419 * pointer and range object. 7420 * @freq_lst: Pointer to AFC frequency list structure. 7421 * 7422 * Return: void 7423 */ 7424 static void reg_free_afc_freq_list(struct wlan_afc_frange_list *freq_lst) 7425 { 7426 if (freq_lst) { 7427 qdf_mem_free(freq_lst->range_objs); 7428 qdf_mem_free(freq_lst); 7429 } 7430 } 7431 7432 /** 7433 * reg_free_afc_opclass_list() - Free the memory allocated for AFC opclass list 7434 * pointer and opclass objects. 7435 * @opclass_obj_lst: Pointer to AFC opclass object list structure. 7436 * 7437 * Return: void 7438 */ 7439 static void 7440 reg_free_afc_opclass_list(struct wlan_afc_opclass_obj_list *opclass_obj_lst) 7441 { 7442 uint8_t num_opclass_objs; 7443 7444 if (!opclass_obj_lst) 7445 return; 7446 7447 num_opclass_objs = opclass_obj_lst->num_opclass_objs; 7448 if (opclass_obj_lst->opclass_objs) 7449 reg_free_afc_opclass_objs(opclass_obj_lst->opclass_objs, 7450 num_opclass_objs); 7451 qdf_mem_free(opclass_obj_lst); 7452 } 7453 7454 /** 7455 * reg_fill_freq_lst() - Allocate and fill the frange buffer and return 7456 * the buffer. Also return the number of frequence ranges 7457 * @pdev: Pointer to pdev 7458 * @pdev_priv_obj: Pointer to pdev private object 7459 * 7460 * Return: Pointer to the frange buffer 7461 */ 7462 static struct wlan_afc_frange_list * 7463 reg_fill_freq_lst(struct wlan_objmgr_pdev *pdev, 7464 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 7465 { 7466 uint8_t num_freq_ranges; 7467 struct wlan_afc_frange_list *p_frange_lst_local; 7468 QDF_STATUS status; 7469 7470 num_freq_ranges = reg_get_num_sp_freq_ranges(pdev, pdev_priv_obj); 7471 p_frange_lst_local = qdf_mem_malloc(sizeof(*p_frange_lst_local)); 7472 if (!p_frange_lst_local) 7473 return NULL; 7474 7475 status = reg_fill_afc_freq_ranges(pdev, 7476 pdev_priv_obj, 7477 p_frange_lst_local, 7478 num_freq_ranges); 7479 if (QDF_IS_STATUS_ERROR(status)) { 7480 reg_free_afc_freq_list(p_frange_lst_local); 7481 return NULL; 7482 } 7483 7484 return p_frange_lst_local; 7485 } 7486 7487 void reg_free_afc_req(struct wlan_objmgr_pdev *pdev, 7488 struct wlan_afc_host_request *afc_req) 7489 { 7490 if (!afc_req) 7491 return; 7492 7493 reg_free_afc_freq_list(afc_req->freq_lst); 7494 reg_free_afc_opclass_list(afc_req->opclass_obj_lst); 7495 qdf_mem_free(afc_req->afc_location); 7496 qdf_mem_free(afc_req); 7497 } 7498 7499 /** 7500 * reg_fill_afc_opclass_obj_lst() - Allocate and fill the opclass object list 7501 * pointer and return the pointer. 7502 * @pdev: Pointer to pdev 7503 * @p_afc_req: Pointer to AFC request. 7504 * 7505 * Return: Pointer to the opclass object list. 7506 */ 7507 static struct wlan_afc_opclass_obj_list * 7508 reg_fill_afc_opclass_obj_lst(struct wlan_objmgr_pdev *pdev, 7509 struct wlan_afc_host_request *p_afc_req) 7510 { 7511 uint8_t num_opclasses; 7512 uint8_t *opclass_lst; 7513 uint8_t *chansize_lst; 7514 uint8_t **channel_lists; 7515 struct wlan_afc_opclass_obj_list *opclass_obj_lst; 7516 struct wlan_afc_opclass_obj *l_opclass_objs; 7517 QDF_STATUS status; 7518 7519 status = reg_dmn_get_6g_opclasses_and_channels(pdev, 7520 p_afc_req->freq_lst, 7521 &num_opclasses, 7522 &opclass_lst, 7523 &chansize_lst, 7524 &channel_lists); 7525 if (status != QDF_STATUS_SUCCESS) { 7526 reg_err("Opclasses and chans not allocated"); 7527 return NULL; 7528 } 7529 7530 opclass_obj_lst = qdf_mem_malloc(sizeof(*opclass_obj_lst)); 7531 if (!opclass_obj_lst) { 7532 reg_dmn_free_6g_opclasses_and_channels(pdev, num_opclasses, 7533 opclass_lst, 7534 chansize_lst, 7535 channel_lists); 7536 return NULL; 7537 } 7538 7539 if (!num_opclasses) 7540 return NULL; 7541 7542 opclass_obj_lst->num_opclass_objs = num_opclasses; 7543 l_opclass_objs = qdf_mem_malloc(num_opclasses * 7544 sizeof(struct wlan_afc_opclass_obj)); 7545 if (!l_opclass_objs) { 7546 reg_dmn_free_6g_opclasses_and_channels(pdev, num_opclasses, 7547 opclass_lst, 7548 chansize_lst, 7549 channel_lists); 7550 reg_free_afc_opclass_list(opclass_obj_lst); 7551 return NULL; 7552 } 7553 7554 status = reg_fill_afc_opclasses_arr(pdev, num_opclasses, opclass_lst, 7555 chansize_lst, channel_lists, 7556 l_opclass_objs); 7557 if (QDF_IS_STATUS_ERROR(status)) { 7558 reg_dmn_free_6g_opclasses_and_channels(pdev, num_opclasses, 7559 opclass_lst, 7560 chansize_lst, 7561 channel_lists); 7562 reg_free_afc_opclass_list(opclass_obj_lst); 7563 return NULL; 7564 } 7565 7566 opclass_obj_lst->opclass_objs = l_opclass_objs; 7567 reg_dmn_free_6g_opclasses_and_channels(pdev, num_opclasses, 7568 opclass_lst, 7569 chansize_lst, 7570 channel_lists); 7571 return opclass_obj_lst; 7572 } 7573 7574 /** 7575 * reg_fill_afc_location_obj() - Allocate and fill the AFC location object 7576 * pointer and return the pointer. 7577 * @pdev_priv_obj: Pointer to pdev private object 7578 * @afc_req: Pointer to AFC request. 7579 * 7580 * Return: Pointer to the AFC location object. 7581 */ 7582 static struct wlan_afc_location * 7583 reg_fill_afc_location_obj(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 7584 struct wlan_afc_host_request *afc_req) 7585 { 7586 struct wlan_afc_location *p_afc_location; 7587 7588 p_afc_location = qdf_mem_malloc(sizeof(*p_afc_location)); 7589 if (!p_afc_location) 7590 return NULL; 7591 7592 p_afc_location->deployment_type = 7593 pdev_priv_obj->reg_afc_dev_deployment_type; 7594 return p_afc_location; 7595 } 7596 7597 QDF_STATUS 7598 reg_get_afc_req_info(struct wlan_objmgr_pdev *pdev, 7599 struct wlan_afc_host_request **afc_req) 7600 { 7601 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7602 struct wlan_afc_host_request *p_afc_req; 7603 7604 pdev_priv_obj = reg_get_pdev_obj(pdev); 7605 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7606 reg_err("pdev reg component is NULL"); 7607 return QDF_STATUS_E_INVAL; 7608 } 7609 7610 if (!afc_req) { 7611 reg_err("afc_req is NULL"); 7612 return QDF_STATUS_E_INVAL; 7613 } 7614 7615 *afc_req = qdf_mem_malloc(sizeof(struct wlan_afc_host_request)); 7616 if (!*afc_req) 7617 return QDF_STATUS_E_NOMEM; 7618 7619 p_afc_req = *afc_req; 7620 p_afc_req->req_id = DEFAULT_REQ_ID; 7621 p_afc_req->min_des_power = DEFAULT_MIN_POWER; 7622 7623 p_afc_req->freq_lst = reg_fill_freq_lst(pdev, pdev_priv_obj); 7624 if (!p_afc_req->freq_lst) { 7625 reg_err("Frange lst not allocated"); 7626 reg_free_afc_req(pdev, p_afc_req); 7627 return QDF_STATUS_E_NOMEM; 7628 } 7629 7630 p_afc_req->opclass_obj_lst = reg_fill_afc_opclass_obj_lst(pdev, 7631 p_afc_req); 7632 if (!p_afc_req->opclass_obj_lst) { 7633 reg_err("opclass object lst not allocated"); 7634 reg_free_afc_req(pdev, p_afc_req); 7635 return QDF_STATUS_E_NOMEM; 7636 } 7637 7638 p_afc_req->afc_location = reg_fill_afc_location_obj(pdev_priv_obj, 7639 p_afc_req); 7640 if (!p_afc_req->afc_location) { 7641 reg_err("AFC location not allocated"); 7642 reg_free_afc_req(pdev, p_afc_req); 7643 return QDF_STATUS_E_NOMEM; 7644 } 7645 7646 return QDF_STATUS_SUCCESS; 7647 } 7648 7649 void reg_dmn_set_afc_req_id(struct wlan_afc_host_request *afc_req, 7650 uint64_t req_id) 7651 { 7652 7653 afc_req->req_id = req_id; 7654 } 7655 7656 /** 7657 * reg_send_afc_request() - Send AFC request to registered recipient 7658 * @pdev: Pointer to pdev 7659 * @afc_req: Pointer to afc request 7660 * 7661 * Return: void 7662 */ 7663 static 7664 void reg_send_afc_request(struct wlan_objmgr_pdev *pdev, 7665 struct wlan_afc_host_request *afc_req) 7666 { 7667 afc_req_rx_evt_handler cbf; 7668 void *arg; 7669 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7670 7671 pdev_priv_obj = reg_get_pdev_obj(pdev); 7672 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7673 reg_err("pdev reg component is NULL"); 7674 return; 7675 } 7676 7677 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7678 cbf = pdev_priv_obj->afc_cb_obj.func; 7679 if (cbf) { 7680 arg = pdev_priv_obj->afc_cb_obj.arg; 7681 cbf(pdev, afc_req, arg); 7682 } 7683 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7684 } 7685 7686 QDF_STATUS reg_afc_start(struct wlan_objmgr_pdev *pdev, uint64_t req_id) 7687 { 7688 struct wlan_afc_host_request *afc_req; 7689 QDF_STATUS status; 7690 7691 status = reg_get_afc_req_info(pdev, &afc_req); 7692 if (status != QDF_STATUS_SUCCESS) { 7693 reg_err("Creating AFC Request failed"); 7694 return QDF_STATUS_E_FAILURE; 7695 } 7696 7697 QDF_TRACE(QDF_MODULE_ID_AFC, QDF_TRACE_LEVEL_DEBUG, 7698 "Processing AFC Start/Renew Expiry event"); 7699 7700 reg_dmn_set_afc_req_id(afc_req, req_id); 7701 7702 reg_print_afc_req_info(pdev, afc_req); 7703 7704 reg_send_afc_request(pdev, afc_req); 7705 7706 reg_free_afc_req(pdev, afc_req); 7707 7708 return QDF_STATUS_SUCCESS; 7709 } 7710 7711 QDF_STATUS reg_send_afc_power_event(struct wlan_objmgr_pdev *pdev, 7712 struct reg_fw_afc_power_event *power_info) 7713 { 7714 afc_power_tx_evt_handler cbf; 7715 void *arg; 7716 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7717 7718 pdev_priv_obj = reg_get_pdev_obj(pdev); 7719 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7720 reg_err("pdev reg component is NULL"); 7721 return QDF_STATUS_E_FAILURE; 7722 } 7723 7724 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7725 cbf = pdev_priv_obj->afc_pow_evt_cb_obj.func; 7726 if (cbf) { 7727 arg = pdev_priv_obj->afc_pow_evt_cb_obj.arg; 7728 cbf(pdev, power_info, arg); 7729 } 7730 7731 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7732 7733 return QDF_STATUS_SUCCESS; 7734 } 7735 7736 QDF_STATUS reg_send_afc_payload_reset_event(struct wlan_objmgr_pdev *pdev) 7737 { 7738 afc_payload_reset_tx_evt_handler cbf; 7739 void *arg; 7740 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7741 7742 pdev_priv_obj = reg_get_pdev_obj(pdev); 7743 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7744 reg_err("pdev reg component is NULL"); 7745 return QDF_STATUS_E_FAILURE; 7746 } 7747 7748 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7749 cbf = pdev_priv_obj->afc_payload_reset_evt_cb_obj.func; 7750 if (cbf) { 7751 arg = pdev_priv_obj->afc_payload_reset_evt_cb_obj.arg; 7752 cbf(pdev, arg); 7753 } 7754 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7755 7756 return QDF_STATUS_SUCCESS; 7757 } 7758 7759 QDF_STATUS reg_register_afc_req_rx_callback(struct wlan_objmgr_pdev *pdev, 7760 afc_req_rx_evt_handler cbf, 7761 void *arg) 7762 { 7763 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7764 7765 pdev_priv_obj = reg_get_pdev_obj(pdev); 7766 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7767 reg_err("pdev reg component is NULL"); 7768 return QDF_STATUS_E_FAILURE; 7769 } 7770 7771 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7772 pdev_priv_obj->afc_cb_obj.func = cbf; 7773 pdev_priv_obj->afc_cb_obj.arg = arg; 7774 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7775 reg_debug("afc_event_cb: 0x%pK, arg: 0x%pK", cbf, arg); 7776 7777 return QDF_STATUS_SUCCESS; 7778 } 7779 7780 QDF_STATUS reg_unregister_afc_req_rx_callback(struct wlan_objmgr_pdev *pdev, 7781 afc_req_rx_evt_handler cbf) 7782 { 7783 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7784 7785 pdev_priv_obj = reg_get_pdev_obj(pdev); 7786 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7787 reg_err("pdev reg component is NULL"); 7788 return QDF_STATUS_E_FAILURE; 7789 } 7790 7791 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7792 if (pdev_priv_obj->afc_cb_obj.func == cbf) { 7793 pdev_priv_obj->afc_cb_obj.func = NULL; 7794 pdev_priv_obj->afc_cb_obj.arg = NULL; 7795 } else { 7796 reg_err("cb function=0x%pK not found", cbf); 7797 } 7798 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7799 7800 return QDF_STATUS_SUCCESS; 7801 } 7802 7803 QDF_STATUS 7804 reg_register_afc_power_event_callback(struct wlan_objmgr_pdev *pdev, 7805 afc_power_tx_evt_handler cbf, 7806 void *arg) 7807 { 7808 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7809 7810 pdev_priv_obj = reg_get_pdev_obj(pdev); 7811 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7812 reg_err("pdev reg component is NULL"); 7813 return QDF_STATUS_E_FAILURE; 7814 } 7815 7816 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7817 pdev_priv_obj->afc_pow_evt_cb_obj.func = cbf; 7818 pdev_priv_obj->afc_pow_evt_cb_obj.arg = arg; 7819 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7820 reg_debug("afc_power_event_cb: 0x%pK, arg: 0x%pK", cbf, arg); 7821 7822 return QDF_STATUS_SUCCESS; 7823 } 7824 7825 QDF_STATUS 7826 reg_unregister_afc_power_event_callback(struct wlan_objmgr_pdev *pdev, 7827 afc_power_tx_evt_handler cbf) 7828 { 7829 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7830 7831 pdev_priv_obj = reg_get_pdev_obj(pdev); 7832 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7833 reg_err("pdev reg component is NULL"); 7834 return QDF_STATUS_E_FAILURE; 7835 } 7836 7837 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7838 if (pdev_priv_obj->afc_pow_evt_cb_obj.func == cbf) { 7839 pdev_priv_obj->afc_pow_evt_cb_obj.func = NULL; 7840 pdev_priv_obj->afc_pow_evt_cb_obj.arg = NULL; 7841 } else { 7842 reg_err("cb function=0x%pK not found", cbf); 7843 } 7844 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7845 7846 return QDF_STATUS_SUCCESS; 7847 } 7848 7849 QDF_STATUS 7850 reg_register_afc_payload_reset_event_callback(struct wlan_objmgr_pdev *pdev, 7851 afc_payload_reset_tx_evt_handler cbf, 7852 void *arg) 7853 { 7854 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7855 7856 pdev_priv_obj = reg_get_pdev_obj(pdev); 7857 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7858 reg_err("pdev reg component is NULL"); 7859 return QDF_STATUS_E_FAILURE; 7860 } 7861 7862 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7863 pdev_priv_obj->afc_payload_reset_evt_cb_obj.func = cbf; 7864 pdev_priv_obj->afc_payload_reset_evt_cb_obj.arg = arg; 7865 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7866 reg_debug("afc_payload_reset_event_cb: 0x%pK, arg: 0x%pK", cbf, arg); 7867 7868 return QDF_STATUS_SUCCESS; 7869 } 7870 7871 QDF_STATUS 7872 reg_unregister_afc_payload_reset_event_callback(struct wlan_objmgr_pdev *pdev, 7873 afc_payload_reset_tx_evt_handler cbf) 7874 { 7875 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7876 7877 pdev_priv_obj = reg_get_pdev_obj(pdev); 7878 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7879 reg_err("pdev reg component is NULL"); 7880 return QDF_STATUS_E_FAILURE; 7881 } 7882 7883 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7884 if (pdev_priv_obj->afc_payload_reset_evt_cb_obj.func == cbf) { 7885 pdev_priv_obj->afc_payload_reset_evt_cb_obj.func = NULL; 7886 pdev_priv_obj->afc_payload_reset_evt_cb_obj.arg = NULL; 7887 } else { 7888 reg_err("cb function=0x%pK not found", cbf); 7889 } 7890 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7891 7892 return QDF_STATUS_SUCCESS; 7893 } 7894 7895 QDF_STATUS 7896 reg_get_afc_dev_deploy_type(struct wlan_objmgr_pdev *pdev, 7897 enum reg_afc_dev_deploy_type *reg_afc_dev_type) 7898 { 7899 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7900 7901 pdev_priv_obj = reg_get_pdev_obj(pdev); 7902 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7903 reg_err("pdev reg component is NULL"); 7904 return QDF_STATUS_E_FAILURE; 7905 } 7906 7907 *reg_afc_dev_type = pdev_priv_obj->reg_afc_dev_deployment_type; 7908 7909 return QDF_STATUS_SUCCESS; 7910 } 7911 7912 bool 7913 reg_is_sta_connect_allowed(struct wlan_objmgr_pdev *pdev, 7914 enum reg_6g_ap_type root_ap_pwr_mode) 7915 { 7916 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7917 7918 pdev_priv_obj = reg_get_pdev_obj(pdev); 7919 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7920 reg_err("pdev reg component is NULL"); 7921 return false; 7922 } 7923 7924 if (reg_get_num_rules_of_ap_pwr_type(pdev, REG_STANDARD_POWER_AP) && 7925 (pdev_priv_obj->reg_afc_dev_deployment_type == AFC_DEPLOYMENT_OUTDOOR)) { 7926 if (root_ap_pwr_mode == REG_STANDARD_POWER_AP) 7927 return true; 7928 else 7929 return false; 7930 } 7931 7932 return true; 7933 } 7934 7935 QDF_STATUS reg_set_afc_soc_dev_type(struct wlan_objmgr_psoc *psoc, 7936 enum reg_afc_dev_deploy_type 7937 reg_afc_dev_type) 7938 { 7939 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7940 7941 psoc_priv_obj = reg_get_psoc_obj(psoc); 7942 7943 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 7944 reg_err("psoc reg component is NULL"); 7945 return QDF_STATUS_E_FAILURE; 7946 } 7947 7948 psoc_priv_obj->reg_afc_dev_type = reg_afc_dev_type; 7949 7950 return QDF_STATUS_SUCCESS; 7951 } 7952 7953 QDF_STATUS 7954 reg_get_afc_soc_dev_type(struct wlan_objmgr_psoc *psoc, 7955 enum reg_afc_dev_deploy_type *reg_afc_dev_type) 7956 { 7957 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7958 7959 psoc_priv_obj = reg_get_psoc_obj(psoc); 7960 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 7961 reg_err("psoc reg component is NULL"); 7962 return QDF_STATUS_E_FAILURE; 7963 } 7964 7965 *reg_afc_dev_type = psoc_priv_obj->reg_afc_dev_type; 7966 7967 return QDF_STATUS_SUCCESS; 7968 } 7969 7970 QDF_STATUS 7971 reg_set_eirp_preferred_support(struct wlan_objmgr_psoc *psoc, 7972 bool reg_is_eirp_support_preferred) 7973 { 7974 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7975 7976 psoc_priv_obj = reg_get_psoc_obj(psoc); 7977 7978 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 7979 reg_err("psoc reg component is NULL"); 7980 return QDF_STATUS_E_FAILURE; 7981 } 7982 7983 psoc_priv_obj->reg_is_eirp_support_preferred = 7984 reg_is_eirp_support_preferred; 7985 7986 return QDF_STATUS_SUCCESS; 7987 } 7988 7989 QDF_STATUS 7990 reg_get_eirp_preferred_support(struct wlan_objmgr_psoc *psoc, 7991 bool *reg_is_eirp_support_preferred) 7992 { 7993 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7994 7995 psoc_priv_obj = reg_get_psoc_obj(psoc); 7996 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 7997 reg_err("psoc reg component is NULL"); 7998 return QDF_STATUS_E_FAILURE; 7999 } 8000 8001 *reg_is_eirp_support_preferred = 8002 psoc_priv_obj->reg_is_eirp_support_preferred; 8003 8004 return QDF_STATUS_SUCCESS; 8005 } 8006 8007 #endif /* CONFIG_AFC_SUPPORT */ 8008 8009 QDF_STATUS 8010 reg_get_cur_6g_client_type(struct wlan_objmgr_pdev *pdev, 8011 enum reg_6g_client_type 8012 *reg_cur_6g_client_mobility_type) 8013 { 8014 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8015 8016 pdev_priv_obj = reg_get_pdev_obj(pdev); 8017 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8018 reg_err("pdev reg component is NULL"); 8019 return QDF_STATUS_E_FAILURE; 8020 } 8021 8022 if (pdev_priv_obj->reg_cur_6g_client_mobility_type >= 8023 REG_MAX_CLIENT_TYPE) 8024 return QDF_STATUS_E_FAILURE; 8025 8026 *reg_cur_6g_client_mobility_type = 8027 pdev_priv_obj->reg_cur_6g_client_mobility_type; 8028 8029 return QDF_STATUS_SUCCESS; 8030 } 8031 8032 QDF_STATUS 8033 reg_set_cur_6ghz_client_type(struct wlan_objmgr_pdev *pdev, 8034 enum reg_6g_client_type in_6ghz_client_type) 8035 { 8036 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8037 8038 pdev_priv_obj = reg_get_pdev_obj(pdev); 8039 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8040 reg_err("pdev reg component is NULL"); 8041 return QDF_STATUS_E_FAILURE; 8042 } 8043 8044 if (in_6ghz_client_type >= REG_MAX_CLIENT_TYPE) 8045 return QDF_STATUS_E_FAILURE; 8046 8047 pdev_priv_obj->reg_cur_6g_client_mobility_type = in_6ghz_client_type; 8048 8049 return QDF_STATUS_SUCCESS; 8050 } 8051 8052 QDF_STATUS 8053 reg_set_6ghz_client_type_from_target(struct wlan_objmgr_pdev *pdev) 8054 { 8055 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8056 8057 pdev_priv_obj = reg_get_pdev_obj(pdev); 8058 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8059 reg_err("pdev reg component is NULL"); 8060 return QDF_STATUS_E_FAILURE; 8061 } 8062 8063 pdev_priv_obj->reg_cur_6g_client_mobility_type = 8064 pdev_priv_obj->reg_target_client_type; 8065 8066 return QDF_STATUS_SUCCESS; 8067 } 8068 8069 QDF_STATUS reg_get_rnr_tpe_usable(struct wlan_objmgr_pdev *pdev, 8070 bool *reg_rnr_tpe_usable) 8071 { 8072 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8073 8074 pdev_priv_obj = reg_get_pdev_obj(pdev); 8075 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8076 reg_err("pdev reg component is NULL"); 8077 return QDF_STATUS_E_FAILURE; 8078 } 8079 *reg_rnr_tpe_usable = pdev_priv_obj->reg_rnr_tpe_usable; 8080 return QDF_STATUS_SUCCESS; 8081 } 8082 8083 QDF_STATUS reg_get_unspecified_ap_usable(struct wlan_objmgr_pdev *pdev, 8084 bool *reg_unspecified_ap_usable) 8085 { 8086 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8087 8088 pdev_priv_obj = reg_get_pdev_obj(pdev); 8089 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8090 reg_err("pdev reg component is NULL"); 8091 return QDF_STATUS_E_FAILURE; 8092 } 8093 *reg_unspecified_ap_usable = pdev_priv_obj->reg_unspecified_ap_usable; 8094 return QDF_STATUS_SUCCESS; 8095 } 8096 8097 QDF_STATUS 8098 reg_find_txpower_from_6g_list(qdf_freq_t freq, 8099 struct regulatory_channel *chan_list, 8100 int16_t *txpower) 8101 { 8102 enum channel_enum chan_enum; 8103 8104 *txpower = 0; 8105 8106 for (chan_enum = 0; chan_enum < NUM_6GHZ_CHANNELS; chan_enum++) { 8107 if (chan_list[chan_enum].center_freq == freq) { 8108 *txpower = chan_list[chan_enum].tx_power; 8109 return QDF_STATUS_SUCCESS; 8110 } 8111 } 8112 8113 return QDF_STATUS_E_FAILURE; 8114 } 8115 8116 bool reg_is_6g_psd_power(struct wlan_objmgr_pdev *pdev) 8117 { 8118 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8119 struct regulatory_channel *cur_chan_list; 8120 enum channel_enum i; 8121 8122 if (!pdev) { 8123 reg_err("pdev is NULL"); 8124 return false; 8125 } 8126 8127 pdev_priv_obj = reg_get_pdev_obj(pdev); 8128 if (!pdev_priv_obj) { 8129 reg_err("pdev priv obj is NULL"); 8130 return false; 8131 } 8132 8133 cur_chan_list = pdev_priv_obj->cur_chan_list; 8134 8135 for (i = MIN_6GHZ_CHANNEL; i <= MAX_6GHZ_CHANNEL; i++) { 8136 if (!(cur_chan_list[i].chan_flags & REGULATORY_CHAN_DISABLED)) 8137 return cur_chan_list[i].psd_flag; 8138 } 8139 8140 return false; 8141 } 8142 8143 QDF_STATUS 8144 reg_get_6g_chan_psd_eirp_power(qdf_freq_t freq, 8145 struct regulatory_channel *mas_chan_list, 8146 int16_t *eirp_psd_power) 8147 { 8148 uint16_t i; 8149 8150 if (!mas_chan_list) { 8151 reg_err_rl("mas_chan_list is NULL"); 8152 return QDF_STATUS_E_FAILURE; 8153 } 8154 8155 for (i = 0; i < NUM_6GHZ_CHANNELS; i++) { 8156 if (freq == mas_chan_list[i].center_freq) { 8157 *eirp_psd_power = mas_chan_list[i].psd_eirp; 8158 return QDF_STATUS_SUCCESS; 8159 } 8160 } 8161 8162 return QDF_STATUS_E_FAILURE; 8163 } 8164 8165 QDF_STATUS reg_get_6g_chan_ap_power(struct wlan_objmgr_pdev *pdev, 8166 qdf_freq_t chan_freq, bool *is_psd, 8167 int16_t *tx_power, 8168 int16_t *eirp_psd_power) 8169 { 8170 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8171 struct regulatory_channel *master_chan_list; 8172 enum reg_6g_ap_type ap_pwr_type; 8173 QDF_STATUS status = QDF_STATUS_SUCCESS; 8174 8175 pdev_priv_obj = reg_get_pdev_obj(pdev); 8176 if (!pdev_priv_obj) { 8177 reg_err("pdev priv obj is NULL"); 8178 return QDF_STATUS_E_FAILURE; 8179 } 8180 8181 status = reg_get_cur_6g_ap_pwr_type(pdev, &ap_pwr_type); 8182 if (!QDF_IS_STATUS_SUCCESS(status)) 8183 return status; 8184 8185 master_chan_list = pdev_priv_obj->mas_chan_list_6g_ap[ap_pwr_type]; 8186 8187 reg_find_txpower_from_6g_list(chan_freq, master_chan_list, 8188 tx_power); 8189 8190 *is_psd = reg_is_6g_psd_power(pdev); 8191 if (*is_psd) 8192 status = reg_get_6g_chan_psd_eirp_power(chan_freq, 8193 master_chan_list, 8194 eirp_psd_power); 8195 8196 return status; 8197 } 8198 8199 QDF_STATUS reg_get_client_power_for_connecting_ap(struct wlan_objmgr_pdev *pdev, 8200 enum reg_6g_ap_type ap_type, 8201 qdf_freq_t chan_freq, 8202 bool is_psd, 8203 uint16_t *tx_power, 8204 uint16_t *eirp_psd_power) 8205 { 8206 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8207 enum reg_6g_client_type client_type; 8208 struct regulatory_channel *master_chan_list; 8209 QDF_STATUS status = QDF_STATUS_SUCCESS; 8210 8211 pdev_priv_obj = reg_get_pdev_obj(pdev); 8212 if (!pdev_priv_obj) { 8213 reg_err("pdev priv obj is NULL"); 8214 return QDF_STATUS_E_FAILURE; 8215 } 8216 8217 reg_get_cur_6g_client_type(pdev, &client_type); 8218 8219 master_chan_list = 8220 pdev_priv_obj->mas_chan_list_6g_client[ap_type][client_type]; 8221 8222 reg_find_txpower_from_6g_list(chan_freq, master_chan_list, 8223 tx_power); 8224 8225 if (is_psd) 8226 status = reg_get_6g_chan_psd_eirp_power(chan_freq, 8227 master_chan_list, 8228 eirp_psd_power); 8229 8230 return status; 8231 } 8232 8233 QDF_STATUS reg_get_client_power_for_6ghz_ap(struct wlan_objmgr_pdev *pdev, 8234 enum reg_6g_client_type client_type, 8235 qdf_freq_t chan_freq, 8236 bool *is_psd, uint16_t *tx_power, 8237 uint16_t *eirp_psd_power) 8238 { 8239 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8240 enum reg_6g_ap_type ap_pwr_type; 8241 struct regulatory_channel *master_chan_list; 8242 QDF_STATUS status = QDF_STATUS_SUCCESS; 8243 8244 status = reg_get_cur_6g_ap_pwr_type(pdev, &ap_pwr_type); 8245 if (!QDF_IS_STATUS_SUCCESS(status)) 8246 return status; 8247 8248 pdev_priv_obj = reg_get_pdev_obj(pdev); 8249 if (!pdev_priv_obj) { 8250 reg_err("pdev priv obj is NULL"); 8251 return QDF_STATUS_E_FAILURE; 8252 } 8253 8254 master_chan_list = pdev_priv_obj-> 8255 mas_chan_list_6g_client[ap_pwr_type][client_type]; 8256 8257 reg_find_txpower_from_6g_list(chan_freq, master_chan_list, 8258 tx_power); 8259 8260 *is_psd = reg_is_6g_psd_power(pdev); 8261 if (*is_psd) 8262 status = reg_get_6g_chan_psd_eirp_power(chan_freq, 8263 master_chan_list, 8264 eirp_psd_power); 8265 8266 return status; 8267 } 8268 8269 QDF_STATUS reg_set_ap_pwr_and_update_chan_list(struct wlan_objmgr_pdev *pdev, 8270 enum reg_6g_ap_type ap_pwr_type) 8271 { 8272 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8273 QDF_STATUS status; 8274 8275 pdev_priv_obj = reg_get_pdev_obj(pdev); 8276 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8277 reg_err("pdev reg component is NULL"); 8278 return QDF_STATUS_E_INVAL; 8279 } 8280 8281 if (ap_pwr_type != REG_CURRENT_MAX_AP_TYPE) { 8282 if (!reg_get_num_rules_of_ap_pwr_type(pdev, ap_pwr_type)) 8283 return QDF_STATUS_E_FAILURE; 8284 8285 status = reg_set_cur_6g_ap_pwr_type(pdev, ap_pwr_type); 8286 if (QDF_IS_STATUS_ERROR(status)) { 8287 reg_debug("failed to set AP power type to %d", 8288 ap_pwr_type); 8289 return status; 8290 } 8291 } 8292 8293 reg_compute_pdev_current_chan_list(pdev_priv_obj); 8294 8295 return QDF_STATUS_SUCCESS; 8296 } 8297 #endif 8298 8299 bool reg_is_regdb_offloaded(struct wlan_objmgr_psoc *psoc) 8300 { 8301 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8302 8303 psoc_priv_obj = reg_get_psoc_obj(psoc); 8304 if (!psoc_priv_obj) { 8305 reg_err("reg psoc private obj is NULL"); 8306 return false; 8307 } 8308 8309 return psoc_priv_obj->offload_enabled; 8310 } 8311 8312 QDF_STATUS 8313 reg_set_ext_tpc_supported(struct wlan_objmgr_psoc *psoc, bool val) 8314 { 8315 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8316 8317 psoc_priv_obj = reg_get_psoc_obj(psoc); 8318 8319 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8320 reg_err("psoc reg component is NULL"); 8321 return QDF_STATUS_E_FAILURE; 8322 } 8323 8324 psoc_priv_obj->is_ext_tpc_supported = val; 8325 8326 return QDF_STATUS_SUCCESS; 8327 } 8328 8329 bool reg_is_ext_tpc_supported(struct wlan_objmgr_psoc *psoc) 8330 { 8331 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8332 8333 psoc_priv_obj = reg_get_psoc_obj(psoc); 8334 8335 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8336 reg_err("psoc reg component is NULL"); 8337 return false; 8338 } 8339 8340 return psoc_priv_obj->is_ext_tpc_supported; 8341 } 8342 8343 #if defined(CONFIG_BAND_6GHZ) 8344 QDF_STATUS 8345 reg_set_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc, bool val) 8346 { 8347 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8348 8349 psoc_priv_obj = reg_get_psoc_obj(psoc); 8350 8351 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8352 reg_err("psoc reg component is NULL"); 8353 return QDF_STATUS_E_FAILURE; 8354 } 8355 8356 psoc_priv_obj->is_lower_6g_edge_ch_supported = val; 8357 8358 return QDF_STATUS_SUCCESS; 8359 } 8360 8361 QDF_STATUS 8362 reg_set_disable_upper_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc, bool val) 8363 { 8364 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8365 8366 psoc_priv_obj = reg_get_psoc_obj(psoc); 8367 8368 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8369 reg_err("psoc reg component is NULL"); 8370 return QDF_STATUS_E_FAILURE; 8371 } 8372 8373 psoc_priv_obj->is_upper_6g_edge_ch_disabled = val; 8374 8375 return QDF_STATUS_SUCCESS; 8376 } 8377 8378 bool reg_is_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc) 8379 { 8380 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8381 8382 psoc_priv_obj = reg_get_psoc_obj(psoc); 8383 8384 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8385 reg_err("psoc reg component is NULL"); 8386 return false; 8387 } 8388 8389 return psoc_priv_obj->is_lower_6g_edge_ch_supported; 8390 } 8391 8392 bool reg_is_upper_6g_edge_ch_disabled(struct wlan_objmgr_psoc *psoc) 8393 { 8394 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8395 8396 psoc_priv_obj = reg_get_psoc_obj(psoc); 8397 8398 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8399 reg_err("psoc reg component is NULL"); 8400 return false; 8401 } 8402 8403 return psoc_priv_obj->is_upper_6g_edge_ch_disabled; 8404 } 8405 8406 static inline bool reg_is_within_range_inclusive(enum channel_enum left, 8407 enum channel_enum right, 8408 enum channel_enum idx) 8409 { 8410 return (idx >= left) && (idx <= right); 8411 } 8412 8413 uint16_t reg_convert_enum_to_6g_idx(enum channel_enum ch_idx) 8414 { 8415 if (!reg_is_within_range_inclusive(MIN_6GHZ_CHANNEL, 8416 MAX_6GHZ_CHANNEL, 8417 ch_idx)) 8418 return INVALID_CHANNEL; 8419 8420 return (ch_idx - MIN_6GHZ_CHANNEL); 8421 } 8422 8423 QDF_STATUS 8424 reg_get_superchan_entry(struct wlan_objmgr_pdev *pdev, 8425 enum channel_enum chan_enum, 8426 const struct super_chan_info **p_sup_chan_entry) 8427 { 8428 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8429 uint16_t sup_idx; 8430 8431 sup_idx = reg_convert_enum_to_6g_idx(chan_enum); 8432 8433 if (reg_is_chan_enum_invalid(sup_idx)) { 8434 reg_debug("super channel idx is invalid for the chan_enum %d", 8435 chan_enum); 8436 return QDF_STATUS_E_INVAL; 8437 } 8438 8439 pdev_priv_obj = reg_get_pdev_obj(pdev); 8440 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8441 reg_err_rl("pdev reg component is NULL"); 8442 return QDF_STATUS_E_INVAL; 8443 } 8444 8445 if (!p_sup_chan_entry) { 8446 reg_err_rl("p_sup_chan_entry is NULL"); 8447 return QDF_STATUS_E_INVAL; 8448 } 8449 8450 if (sup_idx >= NUM_6GHZ_CHANNELS) { 8451 reg_debug("sup_idx is out of bounds"); 8452 return QDF_STATUS_E_INVAL; 8453 } 8454 8455 *p_sup_chan_entry = &pdev_priv_obj->super_chan_list[sup_idx]; 8456 8457 return QDF_STATUS_SUCCESS; 8458 } 8459 #endif 8460 8461 #ifdef FEATURE_WLAN_CH_AVOID_EXT 8462 /** 8463 * reg_process_ch_avoid_freq_ext() - Update extended avoid frequencies in 8464 * psoc_priv_obj 8465 * @psoc: Pointer to psoc structure 8466 * @pdev: pointer to pdev object 8467 * 8468 * Return: None 8469 */ 8470 static QDF_STATUS 8471 reg_process_ch_avoid_freq_ext(struct wlan_objmgr_psoc *psoc, 8472 struct wlan_objmgr_pdev *pdev) 8473 { 8474 uint32_t i; 8475 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8476 uint8_t start_channel; 8477 uint8_t end_channel; 8478 int32_t txpower; 8479 bool is_valid_txpower; 8480 struct ch_avoid_freq_type *range; 8481 enum channel_enum ch_loop; 8482 enum channel_enum start_ch_idx; 8483 enum channel_enum end_ch_idx; 8484 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8485 uint32_t len; 8486 struct unsafe_ch_list *unsafe_ch_list; 8487 bool coex_unsafe_nb_user_prefer; 8488 8489 pdev_priv_obj = reg_get_pdev_obj(pdev); 8490 8491 if (!pdev_priv_obj) { 8492 reg_err("reg pdev private obj is NULL"); 8493 return QDF_STATUS_E_FAILURE; 8494 } 8495 psoc_priv_obj = reg_get_psoc_obj(psoc); 8496 if (!psoc_priv_obj) { 8497 reg_err("reg psoc private obj is NULL"); 8498 return QDF_STATUS_E_FAILURE; 8499 } 8500 8501 unsafe_ch_list = &psoc_priv_obj->unsafe_chan_list; 8502 coex_unsafe_nb_user_prefer = 8503 psoc_priv_obj->coex_unsafe_chan_nb_user_prefer; 8504 8505 if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt > 0) { 8506 len = sizeof(pdev_priv_obj->avoid_chan_ext_list.chan_freq_list); 8507 pdev_priv_obj->avoid_chan_ext_list.chan_cnt = 0; 8508 qdf_mem_zero(&pdev_priv_obj->avoid_chan_ext_list.chan_freq_list, 8509 len); 8510 } 8511 8512 if (unsafe_ch_list->chan_cnt > 0) { 8513 len = sizeof(unsafe_ch_list->chan_freq_list); 8514 unsafe_ch_list->chan_cnt = 0; 8515 qdf_mem_zero(unsafe_ch_list->chan_freq_list, len); 8516 } 8517 8518 for (i = 0; i < psoc_priv_obj->avoid_freq_ext_list.ch_avoid_range_cnt; 8519 i++) { 8520 if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt >= 8521 NUM_CHANNELS) { 8522 reg_debug("ext avoid channel list full"); 8523 break; 8524 } 8525 8526 if (unsafe_ch_list->chan_cnt >= NUM_CHANNELS) { 8527 reg_warn("LTE Coex unsafe channel list full"); 8528 break; 8529 } 8530 8531 start_ch_idx = INVALID_CHANNEL; 8532 end_ch_idx = INVALID_CHANNEL; 8533 range = &psoc_priv_obj->avoid_freq_ext_list.avoid_freq_range[i]; 8534 8535 start_channel = reg_freq_to_chan(pdev, range->start_freq); 8536 end_channel = reg_freq_to_chan(pdev, range->end_freq); 8537 txpower = range->txpower; 8538 is_valid_txpower = range->is_valid_txpower; 8539 8540 reg_debug("start: freq %d, ch %d, end: freq %d, ch %d txpower %d", 8541 range->start_freq, start_channel, range->end_freq, 8542 end_channel, txpower); 8543 8544 /* do not process frequency bands that are not mapped to 8545 * predefined channels 8546 */ 8547 if (start_channel == 0 || end_channel == 0) 8548 continue; 8549 8550 for (ch_loop = 0; ch_loop < NUM_CHANNELS; 8551 ch_loop++) { 8552 if (REG_CH_TO_FREQ(ch_loop) >= range->start_freq) { 8553 start_ch_idx = ch_loop; 8554 break; 8555 } 8556 } 8557 for (ch_loop = 0; ch_loop < NUM_CHANNELS; 8558 ch_loop++) { 8559 if (REG_CH_TO_FREQ(ch_loop) >= range->end_freq) { 8560 end_ch_idx = ch_loop; 8561 if (REG_CH_TO_FREQ(ch_loop) > range->end_freq) 8562 end_ch_idx--; 8563 break; 8564 } 8565 } 8566 8567 if (reg_is_chan_enum_invalid(start_ch_idx) || 8568 reg_is_chan_enum_invalid(end_ch_idx)) 8569 continue; 8570 8571 for (ch_loop = start_ch_idx; ch_loop <= end_ch_idx; 8572 ch_loop++) { 8573 pdev_priv_obj->avoid_chan_ext_list.chan_freq_list 8574 [pdev_priv_obj->avoid_chan_ext_list.chan_cnt++] = 8575 REG_CH_TO_FREQ(ch_loop); 8576 8577 if (coex_unsafe_nb_user_prefer) { 8578 if (unsafe_ch_list->chan_cnt >= 8579 NUM_CHANNELS) { 8580 reg_warn("LTECoex unsafe ch list full"); 8581 break; 8582 } 8583 unsafe_ch_list->txpower[ 8584 unsafe_ch_list->chan_cnt] = 8585 txpower; 8586 unsafe_ch_list->is_valid_txpower[ 8587 unsafe_ch_list->chan_cnt] = 8588 is_valid_txpower; 8589 unsafe_ch_list->chan_freq_list[ 8590 unsafe_ch_list->chan_cnt++] = 8591 REG_CH_TO_FREQ(ch_loop); 8592 } 8593 8594 if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt >= 8595 NUM_CHANNELS) { 8596 reg_debug("avoid freq ext list full"); 8597 break; 8598 } 8599 } 8600 /* if start == end for 5G, meanwhile it only have one valid 8601 * channel updated, then disable 20M by default around 8602 * this center freq. For example input [5805-5805], it 8603 * will disable 20Mhz around 5805, then the range change 8604 * to [5705-5815], otherwise, not sure about how many width 8605 * need to disabled for such case. 8606 */ 8607 if ((ch_loop - start_ch_idx) == 1 && 8608 (range->end_freq - range->start_freq == 0) && 8609 reg_is_5ghz_ch_freq(range->start_freq)) { 8610 range->start_freq = range->start_freq - HALF_20MHZ_BW; 8611 range->end_freq = range->end_freq + HALF_20MHZ_BW; 8612 } 8613 8614 for (ch_loop = 0; ch_loop < 8615 unsafe_ch_list->chan_cnt; ch_loop++) { 8616 if (ch_loop >= NUM_CHANNELS) 8617 break; 8618 reg_debug("Unsafe freq %d", 8619 unsafe_ch_list->chan_freq_list[ch_loop]); 8620 } 8621 } 8622 8623 return QDF_STATUS_SUCCESS; 8624 } 8625 8626 /** 8627 * reg_update_avoid_ch_ext() - Updates the current channel list that block out 8628 * by extended avoid frequency list 8629 * @psoc: Pointer to psoc structure 8630 * @object: Pointer to pdev structure 8631 * @arg: List of arguments 8632 * 8633 * Return: None 8634 */ 8635 static void 8636 reg_update_avoid_ch_ext(struct wlan_objmgr_psoc *psoc, 8637 void *object, void *arg) 8638 { 8639 struct wlan_objmgr_pdev *pdev = (struct wlan_objmgr_pdev *)object; 8640 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8641 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8642 QDF_STATUS status; 8643 8644 psoc_priv_obj = reg_get_psoc_obj(psoc); 8645 if (!psoc_priv_obj) { 8646 reg_err("reg psoc private obj is NULL"); 8647 return; 8648 } 8649 8650 pdev_priv_obj = reg_get_pdev_obj(pdev); 8651 8652 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8653 reg_err("reg pdev priv obj is NULL"); 8654 return; 8655 } 8656 8657 if (psoc_priv_obj->ch_avoid_ext_ind) { 8658 status = reg_process_ch_avoid_freq_ext(psoc, pdev); 8659 if (QDF_IS_STATUS_ERROR(status)) 8660 psoc_priv_obj->ch_avoid_ext_ind = false; 8661 } 8662 8663 reg_compute_pdev_current_chan_list(pdev_priv_obj); 8664 status = reg_send_scheduler_msg_sb(psoc, pdev); 8665 8666 if (QDF_IS_STATUS_ERROR(status)) 8667 reg_err("channel change msg schedule failed"); 8668 } 8669 8670 QDF_STATUS 8671 reg_process_ch_avoid_ext_event(struct wlan_objmgr_psoc *psoc, 8672 struct ch_avoid_ind_type *ch_avoid_event) 8673 { 8674 uint32_t i; 8675 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8676 QDF_STATUS status; 8677 struct ch_avoid_freq_type *range; 8678 8679 psoc_priv_obj = reg_get_psoc_obj(psoc); 8680 if (!psoc_priv_obj) { 8681 reg_err("reg psoc private obj is NULL"); 8682 return QDF_STATUS_E_FAILURE; 8683 } 8684 8685 reg_debug("freq range count %d", ch_avoid_event->ch_avoid_range_cnt); 8686 8687 qdf_mem_zero(&psoc_priv_obj->avoid_freq_ext_list, 8688 sizeof(struct ch_avoid_ind_type)); 8689 8690 for (i = 0; i < ch_avoid_event->ch_avoid_range_cnt; i++) { 8691 range = &psoc_priv_obj->avoid_freq_ext_list.avoid_freq_range[i]; 8692 range->start_freq = 8693 ch_avoid_event->avoid_freq_range[i].start_freq; 8694 range->end_freq = 8695 ch_avoid_event->avoid_freq_range[i].end_freq; 8696 range->txpower = 8697 ch_avoid_event->avoid_freq_range[i].txpower; 8698 range->is_valid_txpower = 8699 ch_avoid_event->avoid_freq_range[i].is_valid_txpower; 8700 } 8701 8702 psoc_priv_obj->avoid_freq_ext_list.restriction_mask = 8703 ch_avoid_event->restriction_mask; 8704 psoc_priv_obj->avoid_freq_ext_list.ch_avoid_range_cnt = 8705 ch_avoid_event->ch_avoid_range_cnt; 8706 8707 psoc_priv_obj->ch_avoid_ext_ind = true; 8708 8709 status = wlan_objmgr_psoc_try_get_ref(psoc, WLAN_REGULATORY_SB_ID); 8710 8711 if (QDF_IS_STATUS_ERROR(status)) { 8712 reg_err("error taking psoc ref cnt"); 8713 return status; 8714 } 8715 8716 status = wlan_objmgr_iterate_obj_list(psoc, WLAN_PDEV_OP, 8717 reg_update_avoid_ch_ext, 8718 NULL, 1, 8719 WLAN_REGULATORY_SB_ID); 8720 8721 wlan_objmgr_psoc_release_ref(psoc, WLAN_REGULATORY_SB_ID); 8722 8723 return status; 8724 } 8725 8726 bool reg_check_coex_unsafe_nb_user_prefer(struct wlan_objmgr_psoc *psoc) 8727 { 8728 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8729 8730 psoc_priv_obj = reg_get_psoc_obj(psoc); 8731 if (!psoc_priv_obj) { 8732 reg_err("reg psoc private obj is NULL"); 8733 return false; 8734 } 8735 8736 return psoc_priv_obj->coex_unsafe_chan_nb_user_prefer; 8737 } 8738 8739 bool reg_check_coex_unsafe_chan_reg_disable(struct wlan_objmgr_psoc *psoc) 8740 { 8741 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8742 8743 psoc_priv_obj = reg_get_psoc_obj(psoc); 8744 if (!psoc_priv_obj) { 8745 reg_err("reg psoc private obj is NULL"); 8746 return false; 8747 } 8748 8749 return psoc_priv_obj->coex_unsafe_chan_reg_disable; 8750 } 8751 #endif 8752 8753 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ) 8754 QDF_STATUS reg_send_afc_cmd(struct wlan_objmgr_pdev *pdev, 8755 struct reg_afc_resp_rx_ind_info *afc_ind_obj) 8756 { 8757 uint8_t pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 8758 struct wlan_objmgr_psoc *psoc; 8759 struct wlan_lmac_if_reg_tx_ops *tx_ops; 8760 8761 psoc = wlan_pdev_get_psoc(pdev); 8762 if (!psoc) { 8763 reg_err("psoc is NULL"); 8764 return QDF_STATUS_E_INVAL; 8765 } 8766 8767 tx_ops = reg_get_psoc_tx_ops(psoc); 8768 if (tx_ops->send_afc_ind) 8769 return tx_ops->send_afc_ind(psoc, pdev_id, afc_ind_obj); 8770 8771 return QDF_STATUS_E_FAILURE; 8772 } 8773 8774 bool reg_is_afc_power_event_received(struct wlan_objmgr_pdev *pdev) 8775 { 8776 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8777 8778 pdev_priv_obj = reg_get_pdev_obj(pdev); 8779 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8780 reg_err("pdev reg component is NULL"); 8781 return false; 8782 } 8783 8784 return pdev_priv_obj->is_6g_afc_power_event_received; 8785 } 8786 8787 bool reg_is_afc_done(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 8788 { 8789 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8790 uint32_t chan_flags; 8791 8792 pdev_priv_obj = reg_get_pdev_obj(pdev); 8793 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8794 reg_err("pdev reg component is NULL"); 8795 return false; 8796 } 8797 8798 chan_flags = reg_get_channel_flags_for_freq(pdev, freq); 8799 8800 return !(chan_flags & REGULATORY_CHAN_AFC_NOT_DONE); 8801 } 8802 8803 QDF_STATUS reg_get_afc_req_id(struct wlan_objmgr_pdev *pdev, uint64_t *req_id) 8804 { 8805 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8806 8807 pdev_priv_obj = reg_get_pdev_obj(pdev); 8808 8809 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8810 reg_err("reg pdev priv obj is NULL"); 8811 return QDF_STATUS_E_FAILURE; 8812 } 8813 8814 *req_id = pdev_priv_obj->afc_request_id; 8815 8816 return QDF_STATUS_SUCCESS; 8817 } 8818 8819 bool reg_is_afc_expiry_event_received(struct wlan_objmgr_pdev *pdev) 8820 { 8821 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8822 8823 pdev_priv_obj = reg_get_pdev_obj(pdev); 8824 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8825 reg_err("pdev reg component is NULL"); 8826 return false; 8827 } 8828 8829 return pdev_priv_obj->is_6g_afc_expiry_event_received; 8830 } 8831 8832 bool reg_is_noaction_on_afc_pwr_evt(struct wlan_objmgr_pdev *pdev) 8833 { 8834 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8835 8836 pdev_priv_obj = reg_get_pdev_obj(pdev); 8837 8838 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8839 reg_err("reg pdev priv obj is NULL"); 8840 return QDF_STATUS_E_FAILURE; 8841 } 8842 8843 return pdev_priv_obj->is_reg_noaction_on_afc_pwr_evt; 8844 } 8845 #endif 8846 8847 /** 8848 * struct bw_wireless_modes_pair - structure containing bandwidth and wireless 8849 * modes corresponding to the bandwidth 8850 * @ch_width: channel width 8851 * @wireless_modes: wireless modes bitmap corresponding to @ch_width. This 8852 * bitmap is a combination of enum values HOST_REGDMN_MODE 8853 */ 8854 struct bw_wireless_modes_pair { 8855 enum phy_ch_width ch_width; 8856 uint64_t wireless_modes; 8857 }; 8858 8859 /* Mapping of bandwidth to wireless modes */ 8860 static const struct bw_wireless_modes_pair bw_wireless_modes_pair_map[] = { 8861 #ifdef WLAN_FEATURE_11BE 8862 {CH_WIDTH_320MHZ, WIRELESS_320_MODES}, 8863 #endif 8864 {CH_WIDTH_80P80MHZ, WIRELESS_80P80_MODES}, 8865 {CH_WIDTH_160MHZ, WIRELESS_160_MODES}, 8866 {CH_WIDTH_80MHZ, WIRELESS_80_MODES}, 8867 {CH_WIDTH_40MHZ, WIRELESS_40_MODES}, 8868 {CH_WIDTH_20MHZ, WIRELESS_20_MODES}, 8869 {CH_WIDTH_10MHZ, WIRELESS_10_MODES}, 8870 {CH_WIDTH_5MHZ, WIRELESS_5_MODES}, 8871 }; 8872 8873 QDF_STATUS reg_is_chwidth_supported(struct wlan_objmgr_pdev *pdev, 8874 enum phy_ch_width ch_width, 8875 bool *is_supported) 8876 { 8877 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8878 uint64_t wireless_modes; 8879 uint8_t num_bws, idx; 8880 8881 pdev_priv_obj = reg_get_pdev_obj(pdev); 8882 8883 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8884 reg_err("reg pdev priv obj is NULL"); 8885 return QDF_STATUS_E_FAILURE; 8886 } 8887 8888 *is_supported = false; 8889 8890 wireless_modes = pdev_priv_obj->wireless_modes; 8891 num_bws = QDF_ARRAY_SIZE(bw_wireless_modes_pair_map); 8892 8893 for (idx = 0; idx < num_bws; ++idx) { 8894 if (bw_wireless_modes_pair_map[idx].ch_width == ch_width) { 8895 *is_supported = !!(wireless_modes & 8896 bw_wireless_modes_pair_map[idx].wireless_modes); 8897 break; 8898 } 8899 } 8900 8901 return QDF_STATUS_SUCCESS; 8902 } 8903 8904 bool reg_is_state_allowed(enum channel_state chan_state) 8905 { 8906 return !((chan_state == CHANNEL_STATE_INVALID) || 8907 (chan_state == CHANNEL_STATE_DISABLE)); 8908 } 8909 8910 static bool 8911 reg_is_freq_idx_enabled_on_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 8912 *pdev_priv_obj, 8913 enum channel_enum freq_idx) 8914 { 8915 struct regulatory_channel *cur_chan_list; 8916 8917 if (freq_idx >= NUM_CHANNELS) 8918 return false; 8919 8920 cur_chan_list = pdev_priv_obj->cur_chan_list; 8921 8922 return !reg_is_chan_disabled_and_not_nol(&cur_chan_list[freq_idx]); 8923 } 8924 8925 QDF_STATUS 8926 reg_get_min_max_bw_on_cur_chan_list(struct wlan_objmgr_pdev *pdev, 8927 enum channel_enum freq_idx, 8928 uint16_t *min_bw, 8929 uint16_t *max_bw) 8930 { 8931 struct regulatory_channel *cur_chan_list; 8932 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8933 8934 pdev_priv_obj = reg_get_pdev_obj(pdev); 8935 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8936 reg_err("reg pdev private obj is NULL"); 8937 return QDF_STATUS_E_FAILURE; 8938 } 8939 if (freq_idx >= NUM_CHANNELS) 8940 return QDF_STATUS_E_FAILURE; 8941 8942 cur_chan_list = pdev_priv_obj->cur_chan_list; 8943 if (min_bw) 8944 *min_bw = cur_chan_list[freq_idx].min_bw; 8945 if (max_bw) 8946 *max_bw = cur_chan_list[freq_idx].max_bw; 8947 8948 return QDF_STATUS_SUCCESS; 8949 } 8950 8951 static enum channel_state 8952 reg_get_chan_state_on_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 8953 *pdev_priv_obj, 8954 enum channel_enum freq_idx) 8955 { 8956 struct regulatory_channel *cur_chan_list; 8957 enum channel_state chan_state; 8958 8959 if (freq_idx >= NUM_CHANNELS) 8960 return CHANNEL_STATE_INVALID; 8961 8962 cur_chan_list = pdev_priv_obj->cur_chan_list; 8963 chan_state = cur_chan_list[freq_idx].state; 8964 8965 return chan_state; 8966 } 8967 8968 static enum channel_state 8969 reg_get_chan_state_based_on_nol_flag_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 8970 *pdev_priv_obj, 8971 enum channel_enum freq_idx) 8972 { 8973 struct regulatory_channel *cur_chan_list; 8974 enum channel_state chan_state; 8975 8976 if (freq_idx >= NUM_CHANNELS) 8977 return CHANNEL_STATE_INVALID; 8978 8979 cur_chan_list = pdev_priv_obj->cur_chan_list; 8980 chan_state = cur_chan_list[freq_idx].state; 8981 8982 if ((cur_chan_list[freq_idx].nol_chan || 8983 cur_chan_list[freq_idx].nol_history) && 8984 chan_state == CHANNEL_STATE_DISABLE) 8985 chan_state = CHANNEL_STATE_DFS; 8986 8987 return chan_state; 8988 } 8989 8990 #ifdef CONFIG_BAND_6GHZ 8991 static inline bool 8992 reg_is_supr_entry_mode_disabled(const struct super_chan_info *super_chan_ent, 8993 enum supported_6g_pwr_types in_6g_pwr_mode) 8994 { 8995 return ((super_chan_ent->chan_flags_arr[in_6g_pwr_mode] & 8996 REGULATORY_CHAN_DISABLED) && 8997 super_chan_ent->state_arr[in_6g_pwr_mode] == 8998 CHANNEL_STATE_DISABLE); 8999 } 9000 9001 static bool 9002 reg_is_freq_idx_enabled_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 9003 *pdev_priv_obj, 9004 enum channel_enum freq_idx, 9005 enum supported_6g_pwr_types 9006 in_6g_pwr_mode) 9007 { 9008 const struct super_chan_info *super_chan_ent; 9009 QDF_STATUS status; 9010 9011 if (freq_idx >= NUM_CHANNELS) 9012 return false; 9013 9014 if (freq_idx < MIN_6GHZ_CHANNEL) 9015 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 9016 freq_idx); 9017 9018 status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx, 9019 &super_chan_ent); 9020 if (QDF_IS_STATUS_ERROR(status)) { 9021 reg_debug("Failed to get super channel entry for freq_idx %d", 9022 freq_idx); 9023 return false; 9024 } 9025 9026 /* If the input 6G power mode is best power mode, get the best power 9027 * mode type from the super channel entry. 9028 */ 9029 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 9030 in_6g_pwr_mode = super_chan_ent->best_power_mode; 9031 9032 return !reg_is_supr_entry_mode_disabled(super_chan_ent, in_6g_pwr_mode); 9033 } 9034 9035 static QDF_STATUS 9036 reg_get_min_max_bw_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 9037 *pdev_priv_obj, 9038 enum channel_enum freq_idx, 9039 enum supported_6g_pwr_types 9040 in_6g_pwr_mode, 9041 uint16_t *min_bw, 9042 uint16_t *max_bw) 9043 { 9044 const struct super_chan_info *super_chan_ent; 9045 QDF_STATUS status; 9046 9047 if (freq_idx >= NUM_CHANNELS) 9048 return QDF_STATUS_E_FAILURE; 9049 9050 if (freq_idx < MIN_6GHZ_CHANNEL) 9051 return reg_get_min_max_bw_on_cur_chan_list( 9052 pdev_priv_obj->pdev_ptr, 9053 freq_idx, 9054 min_bw, max_bw); 9055 9056 status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx, 9057 &super_chan_ent); 9058 if (QDF_IS_STATUS_ERROR(status)) { 9059 reg_debug("Failed to get super channel entry for freq_idx %d", 9060 freq_idx); 9061 return QDF_STATUS_E_FAILURE; 9062 } 9063 9064 /* If the input 6G power mode is best power mode, get the best power 9065 * mode type from the super channel entry. 9066 */ 9067 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 9068 in_6g_pwr_mode = super_chan_ent->best_power_mode; 9069 9070 if (reg_is_supp_pwr_mode_invalid(in_6g_pwr_mode)) { 9071 reg_debug("pwr_type invalid"); 9072 return QDF_STATUS_E_FAILURE; 9073 } 9074 9075 if (min_bw) 9076 *min_bw = super_chan_ent->min_bw[in_6g_pwr_mode]; 9077 if (max_bw) 9078 *max_bw = super_chan_ent->max_bw[in_6g_pwr_mode]; 9079 9080 return QDF_STATUS_SUCCESS; 9081 } 9082 9083 static enum channel_state 9084 reg_get_chan_state_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 9085 *pdev_priv_obj, 9086 enum channel_enum freq_idx, 9087 enum supported_6g_pwr_types 9088 in_6g_pwr_mode) 9089 { 9090 const struct super_chan_info *super_chan_ent; 9091 enum channel_state chan_state; 9092 QDF_STATUS status; 9093 9094 if (freq_idx >= NUM_CHANNELS) 9095 return CHANNEL_STATE_INVALID; 9096 9097 if (freq_idx < MIN_6GHZ_CHANNEL) 9098 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 9099 freq_idx); 9100 9101 status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx, 9102 &super_chan_ent); 9103 if (QDF_IS_STATUS_ERROR(status)) { 9104 reg_debug("Failed to get super channel entry for freq_idx %d", 9105 freq_idx); 9106 return CHANNEL_STATE_INVALID; 9107 } 9108 9109 /* If the input 6G power mode is best power mode, get the best power 9110 * mode type from the super channel entry. 9111 */ 9112 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 9113 in_6g_pwr_mode = super_chan_ent->best_power_mode; 9114 9115 if (reg_is_supp_pwr_mode_invalid(in_6g_pwr_mode)) { 9116 reg_debug("pwr_type invalid"); 9117 return CHANNEL_STATE_INVALID; 9118 } 9119 9120 chan_state = super_chan_ent->state_arr[in_6g_pwr_mode]; 9121 9122 return chan_state; 9123 } 9124 9125 enum supported_6g_pwr_types 9126 reg_get_best_6g_pwr_type(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 9127 { 9128 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9129 enum channel_enum freq_idx; 9130 enum channel_enum sixg_freq_idx; 9131 9132 pdev_priv_obj = reg_get_pdev_obj(pdev); 9133 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9134 reg_err_rl("pdev reg component is NULL"); 9135 return REG_INVALID_PWR_MODE; 9136 } 9137 9138 freq_idx = reg_get_chan_enum_for_freq(freq); 9139 9140 if (reg_is_chan_enum_invalid(freq_idx)) 9141 return REG_INVALID_PWR_MODE; 9142 9143 sixg_freq_idx = reg_convert_enum_to_6g_idx(freq_idx); 9144 if (reg_is_chan_enum_invalid(sixg_freq_idx) || 9145 sixg_freq_idx >= NUM_6GHZ_CHANNELS) 9146 return REG_INVALID_PWR_MODE; 9147 9148 return pdev_priv_obj->super_chan_list[sixg_freq_idx].best_power_mode; 9149 } 9150 9151 static inline bool reg_is_6g_ap_type_invalid(enum reg_6g_ap_type ap_pwr_type) 9152 { 9153 return ((ap_pwr_type < REG_INDOOR_AP) || 9154 (ap_pwr_type > REG_MAX_SUPP_AP_TYPE)); 9155 } 9156 9157 enum supported_6g_pwr_types 9158 reg_conv_6g_ap_type_to_supported_6g_pwr_types(enum reg_6g_ap_type ap_pwr_type) 9159 { 9160 static const enum supported_6g_pwr_types reg_enum_conv[] = { 9161 [REG_INDOOR_AP] = REG_AP_LPI, 9162 [REG_STANDARD_POWER_AP] = REG_AP_SP, 9163 [REG_VERY_LOW_POWER_AP] = REG_AP_VLP, 9164 }; 9165 9166 if (reg_is_6g_ap_type_invalid(ap_pwr_type)) 9167 return REG_INVALID_PWR_MODE; 9168 9169 return reg_enum_conv[ap_pwr_type]; 9170 } 9171 #else 9172 static inline bool 9173 reg_is_freq_idx_enabled_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 9174 *pdev_priv_obj, 9175 enum channel_enum freq_idx, 9176 enum supported_6g_pwr_types 9177 in_6g_pwr_mode) 9178 { 9179 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 9180 freq_idx); 9181 } 9182 9183 static inline QDF_STATUS 9184 reg_get_min_max_bw_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 9185 *pdev_priv_obj, 9186 enum channel_enum freq_idx, 9187 enum supported_6g_pwr_types 9188 in_6g_pwr_mode, 9189 uint16_t *min_bw, 9190 uint16_t *max_bw) 9191 { 9192 return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj->pdev_ptr, 9193 freq_idx, 9194 min_bw, max_bw); 9195 } 9196 9197 static inline enum channel_state 9198 reg_get_chan_state_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 9199 *pdev_priv_obj, 9200 enum channel_enum freq_idx, 9201 enum supported_6g_pwr_types 9202 in_6g_pwr_mode) 9203 { 9204 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 9205 freq_idx); 9206 } 9207 #endif /* CONFIG_BAND_6GHZ */ 9208 9209 bool 9210 reg_is_freq_enabled(struct wlan_objmgr_pdev *pdev, 9211 qdf_freq_t freq, 9212 enum supported_6g_pwr_types in_6g_pwr_mode) 9213 { 9214 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9215 enum channel_enum freq_idx; 9216 9217 pdev_priv_obj = reg_get_pdev_obj(pdev); 9218 9219 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9220 reg_err("reg pdev private obj is NULL"); 9221 return false; 9222 } 9223 9224 freq_idx = reg_get_chan_enum_for_freq(freq); 9225 9226 if (reg_is_chan_enum_invalid(freq_idx)) 9227 return false; 9228 9229 return reg_is_freq_idx_enabled(pdev, freq_idx, in_6g_pwr_mode); 9230 } 9231 9232 bool reg_is_freq_idx_enabled(struct wlan_objmgr_pdev *pdev, 9233 enum channel_enum freq_idx, 9234 enum supported_6g_pwr_types in_6g_pwr_mode) 9235 { 9236 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9237 9238 pdev_priv_obj = reg_get_pdev_obj(pdev); 9239 9240 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9241 reg_err("reg pdev private obj is NULL"); 9242 return false; 9243 } 9244 9245 if (freq_idx < MIN_6GHZ_CHANNEL) 9246 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 9247 freq_idx); 9248 9249 switch (in_6g_pwr_mode) { 9250 case REG_CURRENT_PWR_MODE: 9251 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 9252 freq_idx); 9253 9254 case REG_BEST_PWR_MODE: 9255 default: 9256 return reg_is_freq_idx_enabled_on_given_pwr_mode(pdev_priv_obj, 9257 freq_idx, 9258 in_6g_pwr_mode 9259 ); 9260 } 9261 } 9262 9263 QDF_STATUS reg_get_min_max_bw_reg_chan_list(struct wlan_objmgr_pdev *pdev, 9264 enum channel_enum freq_idx, 9265 enum supported_6g_pwr_types 9266 in_6g_pwr_mode, 9267 uint16_t *min_bw, 9268 uint16_t *max_bw) 9269 { 9270 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9271 9272 pdev_priv_obj = reg_get_pdev_obj(pdev); 9273 9274 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9275 reg_err("reg pdev private obj is NULL"); 9276 return QDF_STATUS_E_FAILURE; 9277 } 9278 9279 if (freq_idx < MIN_6GHZ_CHANNEL) 9280 return reg_get_min_max_bw_on_cur_chan_list( 9281 pdev, 9282 freq_idx, 9283 min_bw, max_bw); 9284 9285 switch (in_6g_pwr_mode) { 9286 case REG_CURRENT_PWR_MODE: 9287 return reg_get_min_max_bw_on_cur_chan_list( 9288 pdev, 9289 freq_idx, 9290 min_bw, max_bw); 9291 9292 case REG_BEST_PWR_MODE: 9293 default: 9294 return reg_get_min_max_bw_on_given_pwr_mode(pdev_priv_obj, 9295 freq_idx, 9296 in_6g_pwr_mode, 9297 min_bw, max_bw); 9298 } 9299 } 9300 9301 enum channel_state reg_get_chan_state(struct wlan_objmgr_pdev *pdev, 9302 enum channel_enum freq_idx, 9303 enum supported_6g_pwr_types 9304 in_6g_pwr_mode, 9305 bool treat_nol_chan_as_disabled) 9306 { 9307 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9308 9309 pdev_priv_obj = reg_get_pdev_obj(pdev); 9310 9311 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9312 reg_err("reg pdev private obj is NULL"); 9313 return CHANNEL_STATE_INVALID; 9314 } 9315 9316 if (freq_idx < MIN_6GHZ_CHANNEL) { 9317 if (treat_nol_chan_as_disabled) 9318 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 9319 freq_idx); 9320 else 9321 return reg_get_chan_state_based_on_nol_flag_cur_chan_list( 9322 pdev_priv_obj, 9323 freq_idx); 9324 } 9325 9326 switch (in_6g_pwr_mode) { 9327 case REG_CURRENT_PWR_MODE: 9328 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 9329 freq_idx); 9330 9331 case REG_BEST_PWR_MODE: 9332 default: 9333 return reg_get_chan_state_on_given_pwr_mode(pdev_priv_obj, 9334 freq_idx, 9335 in_6g_pwr_mode 9336 ); 9337 } 9338 } 9339 9340 #ifdef WLAN_FEATURE_11BE 9341 enum phy_ch_width reg_find_chwidth_from_bw(uint16_t bw) 9342 { 9343 switch (bw) { 9344 case BW_5_MHZ: 9345 return CH_WIDTH_5MHZ; 9346 case BW_10_MHZ: 9347 return CH_WIDTH_10MHZ; 9348 case BW_20_MHZ: 9349 return CH_WIDTH_20MHZ; 9350 case BW_40_MHZ: 9351 return CH_WIDTH_40MHZ; 9352 case BW_80_MHZ: 9353 return CH_WIDTH_80MHZ; 9354 case BW_160_MHZ: 9355 return CH_WIDTH_160MHZ; 9356 case BW_320_MHZ: 9357 return CH_WIDTH_320MHZ; 9358 default: 9359 return CH_WIDTH_INVALID; 9360 } 9361 } 9362 #else 9363 enum phy_ch_width reg_find_chwidth_from_bw(uint16_t bw) 9364 { 9365 switch (bw) { 9366 case BW_5_MHZ: 9367 return CH_WIDTH_5MHZ; 9368 case BW_10_MHZ: 9369 return CH_WIDTH_10MHZ; 9370 case BW_20_MHZ: 9371 return CH_WIDTH_20MHZ; 9372 case BW_40_MHZ: 9373 return CH_WIDTH_40MHZ; 9374 case BW_80_MHZ: 9375 return CH_WIDTH_80MHZ; 9376 case BW_160_MHZ: 9377 return CH_WIDTH_160MHZ; 9378 default: 9379 return CH_WIDTH_INVALID; 9380 } 9381 } 9382 #endif 9383 9384 #ifdef CONFIG_BAND_6GHZ 9385 qdf_freq_t reg_get_thresh_priority_freq(struct wlan_objmgr_pdev *pdev) 9386 { 9387 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9388 9389 pdev_priv_obj = reg_get_pdev_obj(pdev); 9390 9391 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9392 reg_err("reg pdev private obj is NULL"); 9393 return 0; 9394 } 9395 9396 return pdev_priv_obj->reg_6g_thresh_priority_freq; 9397 } 9398 9399 /** 9400 * reg_get_eirp_from_psd_and_reg_max_eirp() - Get the EIRP by the computing the 9401 * minimum(max regulatory EIRP, EIRP computed from regulatory PSD) 9402 * @pdev: Pointer to pdev 9403 * @mas_chan_list: Pointer to master_chan_list 9404 * @freq: Frequency in mhz 9405 * @bw: Bandwidth in mhz 9406 * @reg_eirp_pwr: Pointer to reg_eirp_pwr 9407 * 9408 * Return: Void 9409 */ 9410 static void 9411 reg_get_eirp_from_psd_and_reg_max_eirp(struct wlan_objmgr_pdev *pdev, 9412 struct regulatory_channel *mas_chan_list, 9413 qdf_freq_t freq, 9414 uint16_t bw, 9415 int16_t *reg_eirp_pwr) 9416 { 9417 int16_t eirp_from_psd = 0, psd = 0; 9418 9419 reg_get_6g_chan_psd_eirp_power(freq, mas_chan_list, &psd); 9420 reg_psd_2_eirp(pdev, psd, bw, &eirp_from_psd); 9421 *reg_eirp_pwr = QDF_MIN(*reg_eirp_pwr, eirp_from_psd); 9422 } 9423 9424 /** 9425 * reg_get_mas_chan_list_for_lookup() - Get the AP or client master_chan_list 9426 * based on the is_client_list_lookup_needed flag 9427 * @pdev: Pointer to pdev 9428 * @master_chan_list: Pointer to master_chan_list 9429 * @ap_pwr_type: AP Power type 9430 * @is_client_list_lookup_needed: Boolean to indicate if client list lookup is 9431 * needed 9432 * @client_type: Client power type 9433 * 9434 * Return: Void 9435 */ 9436 static void 9437 reg_get_mas_chan_list_for_lookup(struct wlan_objmgr_pdev *pdev, 9438 struct regulatory_channel **master_chan_list, 9439 enum reg_6g_ap_type ap_pwr_type, 9440 bool is_client_list_lookup_needed, 9441 enum reg_6g_client_type client_type) 9442 { 9443 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9444 9445 pdev_priv_obj = reg_get_pdev_obj(pdev); 9446 if (!pdev_priv_obj) { 9447 reg_err("pdev priv obj is NULL"); 9448 return; 9449 } 9450 9451 if (client_type > REG_MAX_CLIENT_TYPE) { 9452 reg_err("Invalid client type"); 9453 return; 9454 } 9455 9456 if (is_client_list_lookup_needed) 9457 *master_chan_list = 9458 pdev_priv_obj->mas_chan_list_6g_client[ap_pwr_type] 9459 [client_type]; 9460 else 9461 *master_chan_list = 9462 pdev_priv_obj->mas_chan_list_6g_ap[ap_pwr_type]; 9463 } 9464 9465 /** 9466 * reg_get_eirp_from_mas_chan_list() - For the given power mode, using the bandwidth 9467 * and psd(from master channel entry), calculate an EIRP value. The minimum 9468 * of calculated EIRP and regulatory max EIRP is returned. 9469 * @pdev: Pointer to pdev 9470 * @freq: Frequency in mhz 9471 * @bw: Bandwidth in mhz 9472 * @ap_pwr_type: AP Power type 9473 * @is_client_list_lookup_needed: Boolean to indicate if client list lookup is 9474 * needed 9475 * @client_type: Client power type 9476 * 9477 * Return: EIRP 9478 */ 9479 static int8_t 9480 reg_get_eirp_from_mas_chan_list(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq, 9481 uint16_t bw, enum reg_6g_ap_type ap_pwr_type, 9482 bool is_client_list_lookup_needed, 9483 enum reg_6g_client_type client_type) 9484 { 9485 bool is_psd; 9486 struct regulatory_channel *master_chan_list = NULL; 9487 int16_t txpower = 0; 9488 9489 reg_get_mas_chan_list_for_lookup(pdev, &master_chan_list, ap_pwr_type, 9490 is_client_list_lookup_needed, 9491 client_type); 9492 if (!master_chan_list) { 9493 reg_err("master_chan_list is NULL"); 9494 return 0; 9495 } 9496 9497 is_psd = reg_is_6g_psd_power(pdev); 9498 reg_find_txpower_from_6g_list(freq, master_chan_list, &txpower); 9499 9500 if (is_psd) 9501 reg_get_eirp_from_psd_and_reg_max_eirp(pdev, 9502 master_chan_list, 9503 freq, bw, 9504 &txpower); 9505 9506 return txpower; 9507 } 9508 9509 qdf_freq_t reg_compute_6g_center_freq_from_cfi(uint8_t ieee_6g_cfi) 9510 { 9511 return (SIXG_START_FREQ + ieee_6g_cfi * FREQ_TO_CHAN_SCALE); 9512 } 9513 9514 #ifdef CONFIG_AFC_SUPPORT 9515 #ifdef WLAN_FEATURE_11BE 9516 /** 9517 * reg_is_320_opclass: Find out if the opclass computed from freq and 9518 * width of 320 is same as the input op_class. 9519 * @freq: Frequency in MHz 9520 * @in_opclass: Input Opclass number 9521 * Return: true if opclass is 320 supported, false otherwise. 9522 */ 9523 static bool reg_is_320_opclass(qdf_freq_t freq, uint8_t in_opclass) 9524 { 9525 uint8_t local_op_class = 9526 reg_dmn_get_opclass_from_freq_width(NULL, freq, BW_320_MHZ, 9527 BIT(BEHAV_NONE)); 9528 return (in_opclass == local_op_class); 9529 } 9530 #else 9531 static inline bool reg_is_320_opclass(qdf_freq_t freq, uint8_t op_class) 9532 { 9533 return false; 9534 } 9535 #endif 9536 9537 /** 9538 * reg_find_eirp_in_afc_eirp_obj() - Get eirp power from the AFC eirp object 9539 * based on the channel center frequency and operating class 9540 * @pdev: Pointer to pdev 9541 * @eirp_obj: Pointer to eirp_obj 9542 * @freq: Frequency in MHz 9543 * @cen320: 320 MHz band center frequency 9544 * @op_class: Operating class 9545 * 9546 * Return: EIRP power 9547 */ 9548 static int8_t reg_find_eirp_in_afc_eirp_obj(struct wlan_objmgr_pdev *pdev, 9549 struct chan_eirp_obj *eirp_obj, 9550 qdf_freq_t freq, 9551 qdf_freq_t cen320, 9552 uint8_t op_class) 9553 { 9554 uint8_t k; 9555 uint8_t subchannels[NUM_20_MHZ_CHAN_IN_320_MHZ_CHAN]; 9556 uint8_t nchans; 9557 9558 if (reg_is_320_opclass(freq, op_class)) { 9559 qdf_freq_t cfi_freq = 9560 reg_compute_6g_center_freq_from_cfi(eirp_obj->cfi); 9561 9562 if (cfi_freq == cen320) 9563 return eirp_obj->eirp_power / EIRP_PWR_SCALE; 9564 9565 return 0; 9566 } 9567 9568 nchans = reg_get_subchannels_for_opclass(eirp_obj->cfi, 9569 op_class, 9570 subchannels); 9571 9572 for (k = 0; k < nchans; k++) 9573 if (reg_chan_band_to_freq(pdev, subchannels[k], 9574 BIT(REG_BAND_6G)) == freq) 9575 return eirp_obj->eirp_power / EIRP_PWR_SCALE; 9576 9577 return 0; 9578 } 9579 9580 /** 9581 * reg_find_eirp_in_afc_chan_obj() - Get eirp power from the AFC channel 9582 * object based on the channel center frequency and operating class 9583 * @pdev: Pointer to pdev 9584 * @chan_obj: Pointer to chan_obj 9585 * @freq: Frequency in MHz 9586 * @cen320: 320 MHz band center frequency 9587 * @op_class: Operating class 9588 * 9589 * Return: EIRP power 9590 */ 9591 static int8_t reg_find_eirp_in_afc_chan_obj(struct wlan_objmgr_pdev *pdev, 9592 struct afc_chan_obj *chan_obj, 9593 qdf_freq_t freq, 9594 qdf_freq_t cen320, 9595 uint8_t op_class) 9596 { 9597 uint8_t j; 9598 9599 if (chan_obj->global_opclass != op_class) 9600 return 0; 9601 9602 for (j = 0; j < chan_obj->num_chans; j++) { 9603 int8_t afc_eirp; 9604 struct chan_eirp_obj *eirp_obj = &chan_obj->chan_eirp_info[j]; 9605 9606 afc_eirp = reg_find_eirp_in_afc_eirp_obj(pdev, eirp_obj, 9607 freq, cen320, 9608 op_class); 9609 9610 if (afc_eirp) 9611 return afc_eirp; 9612 } 9613 9614 return 0; 9615 } 9616 9617 /** 9618 * reg_is_chan_punc() - Validates the input puncture pattern. 9619 * @in_punc_pattern: Input puncture pattern 9620 * @bw: Channel bandwidth in MHz 9621 * 9622 * If the in_punc_pattern has none of the subchans punctured, channel 9623 * is not considered as punctured. Also, if the input puncture bitmap 9624 * is invalid, do not consider the channel as punctured. 9625 * 9626 * Return: true if channel is punctured, false otherwise. 9627 */ 9628 #ifdef WLAN_FEATURE_11BE 9629 static bool 9630 reg_is_chan_punc(uint16_t in_punc_pattern, uint16_t bw) 9631 { 9632 enum phy_ch_width ch_width = reg_find_chwidth_from_bw(bw); 9633 9634 if (in_punc_pattern == NO_SCHANS_PUNC || 9635 !reg_is_punc_bitmap_valid(ch_width, in_punc_pattern)) 9636 return false; 9637 9638 return true; 9639 } 9640 #else 9641 static inline bool 9642 reg_is_chan_punc(uint16_t in_punc_pattern, uint16_t bw) 9643 { 9644 return false; 9645 } 9646 #endif 9647 9648 /** 9649 * reg_find_non_punctured_bw() - Given the input puncture pattern and the 9650 * total BW of the channel, find the non-punctured bandwidth. 9651 * @bw: Total bandwidth of the channel 9652 * @in_punc_pattern: Input puncture pattern 9653 * 9654 * Return: non-punctured bw in MHz 9655 */ 9656 static uint16_t 9657 reg_find_non_punctured_bw(uint16_t bw, uint16_t in_punc_pattern) 9658 { 9659 uint8_t num_punc_bw = 0; 9660 9661 while (in_punc_pattern) { 9662 if (in_punc_pattern & 1) 9663 ++num_punc_bw; 9664 in_punc_pattern >>= 1; 9665 } 9666 9667 if (bw <= num_punc_bw * 20) 9668 return 0; 9669 9670 return (bw - num_punc_bw * 20); 9671 } 9672 9673 /** 9674 * reg_get_sp_eirp_for_punc_chans() - Find the standard EIRP power for 9675 * punctured channels. 9676 * @pdev: Pointer to struct wlan_objmgr_pdev 9677 * @freq: Frequency in MHz 9678 * @cen320: Center of 320 MHz channel in Mhz 9679 * @bw: Bandwidth in MHz 9680 * @in_punc_pattern: Input puncture pattern 9681 * @reg_sp_eirp_pwr: Regulatory defined SP power for the input frequency 9682 * 9683 * Return: Regulatory and AFC intersected SP power of punctured channel 9684 */ 9685 static int8_t 9686 reg_get_sp_eirp_for_punc_chans(struct wlan_objmgr_pdev *pdev, 9687 qdf_freq_t freq, 9688 qdf_freq_t cen320, 9689 uint16_t bw, 9690 uint16_t in_punc_pattern, 9691 int16_t reg_sp_eirp_pwr) 9692 { 9693 int16_t min_psd = REG_MIN_POWER; 9694 int16_t afc_eirp_pwr = REG_MIN_POWER; 9695 int16_t non_punc_bw; 9696 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 9697 struct wlan_objmgr_psoc *psoc; 9698 QDF_STATUS status; 9699 9700 psoc = wlan_pdev_get_psoc(pdev); 9701 9702 if (!psoc) 9703 return 0; 9704 9705 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 9706 9707 if (!reg_tx_ops->reg_get_min_psd) 9708 return 0; 9709 9710 /* min_psd will be calculated here */ 9711 status = reg_tx_ops->reg_get_min_psd(pdev, freq, cen320, 9712 in_punc_pattern, bw, 9713 &min_psd); 9714 if (status != QDF_STATUS_SUCCESS) { 9715 reg_debug("Could not derive min_psd power for width %u, freq; %d, cen320: %d, in_punc: 0x%x\n", 9716 bw, freq, cen320, in_punc_pattern); 9717 return 0; 9718 } 9719 9720 non_punc_bw = reg_find_non_punctured_bw(bw, in_punc_pattern); 9721 9722 if (reg_psd_2_eirp(pdev, min_psd, non_punc_bw, &afc_eirp_pwr) != 9723 QDF_STATUS_SUCCESS) { 9724 reg_debug("Could not derive EIRP power for width %u, min_psd: %d\n", non_punc_bw, min_psd); 9725 return 0; 9726 } 9727 9728 reg_debug("freq = %u, bw: %u, cen320: %u, punc_pattern: 0x%x " 9729 "reg_sp_eirp: %d, min_psd: %d, non_punc_bw: %u, afc_eirp_pwr: %d\n", 9730 freq, bw, cen320, in_punc_pattern, reg_sp_eirp_pwr, min_psd, 9731 non_punc_bw, afc_eirp_pwr); 9732 9733 if (afc_eirp_pwr) 9734 return QDF_MIN(afc_eirp_pwr, reg_sp_eirp_pwr); 9735 9736 return 0; 9737 } 9738 9739 /** 9740 * reg_get_sp_eirp_before_afc_resp_rx() - Before the AFC response is received 9741 * from the target, for a given input frequency and bw, find the EIRP values 9742 * based on the deployment type and, the presence of SP AP and VLP AP reg rules. 9743 * @pdev: Pointer to pdev 9744 * @freq: Frequency in MHz 9745 * @bw: Bandwidth in MHz 9746 * @is_client_list_lookup_needed: Boolean to indicate if client list lookup is 9747 * needed 9748 * @client_type: Client power type 9749 * 9750 * Return: EIRP 9751 */ 9752 static int8_t 9753 reg_get_sp_eirp_before_afc_resp_rx(struct wlan_objmgr_pdev *pdev, 9754 qdf_freq_t freq, 9755 uint16_t bw, 9756 bool is_client_list_lookup_needed, 9757 enum reg_6g_client_type client_type) 9758 { 9759 enum reg_afc_dev_deploy_type reg_afc_dev_type; 9760 struct wlan_objmgr_psoc *psoc; 9761 uint8_t num_ap_sp_rules, num_ap_vlp_rules; 9762 9763 psoc = wlan_pdev_get_psoc(pdev); 9764 9765 if (!psoc) { 9766 reg_err("psoc is NULL"); 9767 return 0; 9768 } 9769 9770 reg_get_afc_soc_dev_type(psoc, ®_afc_dev_type); 9771 num_ap_sp_rules = 9772 reg_get_num_rules_of_ap_pwr_type(pdev, REG_STANDARD_POWER_AP); 9773 num_ap_vlp_rules = 9774 reg_get_num_rules_of_ap_pwr_type(pdev, REG_VERY_LOW_POWER_AP); 9775 9776 if (reg_afc_dev_type == AFC_DEPLOYMENT_OUTDOOR && num_ap_sp_rules && 9777 !num_ap_vlp_rules) 9778 return reg_get_eirp_from_mas_chan_list(pdev, freq, bw, 9779 REG_STANDARD_POWER_AP, 9780 is_client_list_lookup_needed, 9781 client_type); 9782 else 9783 return 0; 9784 } 9785 9786 /** 9787 * reg_get_sp_eirp() - For the given power mode, using the bandwidth, find the 9788 * corresponding EIRP values from the afc power info array. The minimum of found 9789 * EIRP and regulatory max EIRP is returned 9790 * @pdev: Pointer to pdev 9791 * @freq: Frequency in MHz 9792 * @cen320: 320 MHz band center frequency 9793 * @bw: Bandwidth in MHz 9794 * @in_punc_pattern: Input puncture pattern 9795 * @is_client_list_lookup_needed: Boolean to indicate if client list lookup is 9796 * needed 9797 * @client_type: Client power type 9798 * 9799 * Return: EIRP 9800 */ 9801 static int8_t reg_get_sp_eirp(struct wlan_objmgr_pdev *pdev, 9802 qdf_freq_t freq, 9803 qdf_freq_t cen320, 9804 uint16_t bw, 9805 uint16_t in_punc_pattern, 9806 bool is_client_list_lookup_needed, 9807 enum reg_6g_client_type client_type) 9808 { 9809 uint8_t i, op_class = 0, chan_num = 0; 9810 int8_t afc_eirp_pwr = 0; 9811 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9812 struct regulatory_channel *sp_master_chan_list = NULL; 9813 struct reg_fw_afc_power_event *power_info; 9814 int16_t reg_sp_eirp_pwr = 0; 9815 bool is_psd; 9816 9817 pdev_priv_obj = reg_get_pdev_obj(pdev); 9818 9819 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9820 reg_err("reg pdev priv obj is NULL"); 9821 return 0; 9822 } 9823 9824 if (!reg_is_afc_power_event_received(pdev)) 9825 return reg_get_sp_eirp_before_afc_resp_rx(pdev, freq, bw, 9826 is_client_list_lookup_needed, 9827 client_type); 9828 9829 sp_master_chan_list = 9830 pdev_priv_obj->mas_chan_list_6g_ap[REG_STANDARD_POWER_AP]; 9831 reg_find_txpower_from_6g_list(freq, sp_master_chan_list, 9832 ®_sp_eirp_pwr); 9833 9834 if (!reg_sp_eirp_pwr) 9835 return 0; 9836 9837 if (reg_is_chan_punc(in_punc_pattern, bw)) { 9838 reg_info("Computing SP EIRP with puncturing info"); 9839 return reg_get_sp_eirp_for_punc_chans(pdev, freq, cen320, bw, 9840 in_punc_pattern, 9841 reg_sp_eirp_pwr); 9842 } 9843 9844 power_info = pdev_priv_obj->power_info; 9845 if (!power_info) { 9846 reg_err("power_info is NULL"); 9847 return 0; 9848 } 9849 9850 reg_freq_width_to_chan_op_class(pdev, 9851 freq, 9852 bw, 9853 true, 9854 BIT(BEHAV_NONE), 9855 &op_class, 9856 &chan_num); 9857 reg_get_mas_chan_list_for_lookup(pdev, &sp_master_chan_list, 9858 REG_STANDARD_POWER_AP, 9859 is_client_list_lookup_needed, 9860 client_type); 9861 if (!sp_master_chan_list) { 9862 reg_err("sp_master_chan_list is NULL"); 9863 return 0; 9864 } 9865 9866 reg_find_txpower_from_6g_list(freq, sp_master_chan_list, 9867 ®_sp_eirp_pwr); 9868 9869 if (!reg_sp_eirp_pwr) 9870 return 0; 9871 9872 for (i = 0; i < power_info->num_chan_objs; i++) { 9873 struct afc_chan_obj *chan_obj = &power_info->afc_chan_info[i]; 9874 9875 afc_eirp_pwr = reg_find_eirp_in_afc_chan_obj(pdev, 9876 chan_obj, 9877 freq, 9878 cen320, 9879 op_class); 9880 if (afc_eirp_pwr) 9881 break; 9882 } 9883 9884 is_psd = reg_is_6g_psd_power(pdev); 9885 if (is_psd) 9886 reg_get_eirp_from_psd_and_reg_max_eirp(pdev, 9887 sp_master_chan_list, 9888 freq, bw, 9889 ®_sp_eirp_pwr); 9890 9891 if (afc_eirp_pwr) 9892 return QDF_MIN(afc_eirp_pwr, (int8_t)reg_sp_eirp_pwr); 9893 9894 return 0; 9895 } 9896 #else 9897 static int8_t reg_get_sp_eirp(struct wlan_objmgr_pdev *pdev, 9898 qdf_freq_t freq, 9899 qdf_freq_t cen320, 9900 uint16_t bw, 9901 uint16_t in_punc_pattern, 9902 bool is_client_list_lookup_needed, 9903 enum reg_6g_client_type client_type) 9904 { 9905 return reg_get_eirp_from_mas_chan_list(pdev, freq, bw, REG_STANDARD_POWER_AP, 9906 is_client_list_lookup_needed, 9907 client_type); 9908 } 9909 #endif 9910 9911 /** 9912 * reg_get_best_pwr_mode_from_eirp_list() - Get best power mode from the input 9913 * EIRP list 9914 * @eirp_list: EIRP list 9915 * @size: Size of eirp list 9916 * 9917 * Return: Best power mode 9918 */ 9919 static enum reg_6g_ap_type 9920 reg_get_best_pwr_mode_from_eirp_list(int8_t *eirp_list, uint8_t size) 9921 { 9922 int8_t max = 0; 9923 uint8_t i; 9924 enum reg_6g_ap_type best_pwr_mode = REG_CURRENT_MAX_AP_TYPE; 9925 9926 for (i = 0; i < size; i++) { 9927 /* Assuming the eirp = 0 means the mode is not available, 9928 * skip the mode. 9929 * EIRP = 0 may be a valid value. We need to fix this in 9930 * future by setting the min negative value (-128) to 9931 * the channels for which power mode is not available. 9932 */ 9933 if (!eirp_list[i]) 9934 continue; 9935 if (eirp_list[i] > max) { 9936 max = eirp_list[i]; 9937 best_pwr_mode = i; 9938 } 9939 } 9940 9941 return best_pwr_mode; 9942 } 9943 9944 int8_t reg_get_eirp_pwr(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq, 9945 qdf_freq_t cen320, 9946 uint16_t bw, enum reg_6g_ap_type ap_pwr_type, 9947 uint16_t in_punc_pattern, 9948 bool is_client_list_lookup_needed, 9949 enum reg_6g_client_type client_type) 9950 { 9951 if (ap_pwr_type == REG_STANDARD_POWER_AP) 9952 return reg_get_sp_eirp(pdev, freq, cen320, bw, in_punc_pattern, 9953 is_client_list_lookup_needed, 9954 client_type); 9955 9956 return reg_get_eirp_from_mas_chan_list(pdev, freq, bw, ap_pwr_type, 9957 is_client_list_lookup_needed, 9958 client_type); 9959 } 9960 9961 enum reg_6g_ap_type reg_get_best_pwr_mode(struct wlan_objmgr_pdev *pdev, 9962 qdf_freq_t freq, 9963 qdf_freq_t cen320, 9964 uint16_t bw, 9965 uint16_t in_punc_pattern) 9966 { 9967 int8_t eirp_list[REG_MAX_SUPP_AP_TYPE + 1]; 9968 enum reg_6g_ap_type ap_pwr_type; 9969 9970 for (ap_pwr_type = REG_INDOOR_AP; ap_pwr_type <= REG_VERY_LOW_POWER_AP; 9971 ap_pwr_type++) 9972 eirp_list[ap_pwr_type] = 9973 reg_get_eirp_pwr(pdev, freq, cen320, bw, 9974 ap_pwr_type, in_punc_pattern, 9975 false, 9976 REG_MAX_CLIENT_TYPE); 9977 9978 return reg_get_best_pwr_mode_from_eirp_list(eirp_list, 9979 REG_MAX_SUPP_AP_TYPE + 1); 9980 } 9981 #endif 9982 9983 QDF_STATUS reg_get_regd_rules(struct wlan_objmgr_pdev *pdev, 9984 struct reg_rule_info *reg_rules) 9985 { 9986 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9987 9988 if (!pdev) { 9989 reg_err("pdev is NULL"); 9990 return QDF_STATUS_E_FAILURE; 9991 } 9992 9993 pdev_priv_obj = reg_get_pdev_obj(pdev); 9994 if (!pdev_priv_obj) { 9995 reg_err("pdev priv obj is NULL"); 9996 return QDF_STATUS_E_FAILURE; 9997 } 9998 9999 qdf_spin_lock_bh(&pdev_priv_obj->reg_rules_lock); 10000 qdf_mem_copy(reg_rules, &pdev_priv_obj->reg_rules, 10001 sizeof(struct reg_rule_info)); 10002 qdf_spin_unlock_bh(&pdev_priv_obj->reg_rules_lock); 10003 10004 return QDF_STATUS_SUCCESS; 10005 } 10006 10007 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ) 10008 bool 10009 reg_is_sup_chan_entry_afc_done(struct wlan_objmgr_pdev *pdev, 10010 enum channel_enum chan_idx, 10011 enum supported_6g_pwr_types in_6g_pwr_mode) 10012 { 10013 const struct super_chan_info *super_chan_ent; 10014 QDF_STATUS status; 10015 10016 status = reg_get_superchan_entry(pdev, chan_idx, 10017 &super_chan_ent); 10018 if (QDF_IS_STATUS_ERROR(status)) { 10019 reg_debug("Failed to get super channel entry for chan_idx %d", 10020 chan_idx); 10021 return false; 10022 } 10023 10024 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 10025 in_6g_pwr_mode = super_chan_ent->best_power_mode; 10026 10027 if (in_6g_pwr_mode != REG_AP_SP) 10028 return false; 10029 10030 return !(super_chan_ent->chan_flags_arr[in_6g_pwr_mode] & 10031 REGULATORY_CHAN_AFC_NOT_DONE); 10032 } 10033 #endif 10034 10035 #ifdef CONFIG_BAND_6GHZ 10036 QDF_STATUS 10037 reg_display_super_chan_list(struct wlan_objmgr_pdev *pdev) 10038 { 10039 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 10040 struct super_chan_info *super_chan_list; 10041 uint8_t i; 10042 10043 pdev_priv_obj = reg_get_pdev_obj(pdev); 10044 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 10045 reg_err_rl("pdev reg component is NULL"); 10046 return QDF_STATUS_E_FAILURE; 10047 } 10048 10049 super_chan_list = pdev_priv_obj->super_chan_list; 10050 for (i = 0; i < NUM_6GHZ_CHANNELS; i++) { 10051 struct super_chan_info *chan_info = &super_chan_list[i]; 10052 struct regulatory_channel cur_chan_list = 10053 pdev_priv_obj->cur_chan_list[MIN_6GHZ_CHANNEL + i]; 10054 uint8_t j; 10055 10056 qdf_print("Freq = %d\tPower types = 0x%x\t" 10057 "Best power mode = 0x%x\n", 10058 cur_chan_list.center_freq, chan_info->power_types, 10059 chan_info->best_power_mode); 10060 for (j = REG_AP_LPI; j <= REG_CLI_SUB_VLP; j++) { 10061 bool afc_not_done_bit; 10062 10063 afc_not_done_bit = chan_info->chan_flags_arr[j] & 10064 REGULATORY_CHAN_AFC_NOT_DONE; 10065 qdf_print("Power mode = %d\tPSD flag = %d\t" 10066 "PSD power = %d\tEIRP power = %d\t" 10067 "Chan flags = 0x%x\tChannel state = %d\t" 10068 "Min bw = %d\tMax bw = %d\t" 10069 "AFC_NOT_DONE = %d\n", 10070 j, chan_info->reg_chan_pwr[j].psd_flag, 10071 chan_info->reg_chan_pwr[j].psd_eirp, 10072 chan_info->reg_chan_pwr[j].tx_power, 10073 chan_info->chan_flags_arr[j], 10074 chan_info->state_arr[j], 10075 chan_info->min_bw[j], chan_info->max_bw[j], 10076 afc_not_done_bit); 10077 } 10078 } 10079 10080 return QDF_STATUS_SUCCESS; 10081 } 10082 10083 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ) 10084 QDF_STATUS 10085 reg_get_afc_freq_range_and_psd_limits(struct wlan_objmgr_pdev *pdev, 10086 uint8_t num_freq_obj, 10087 struct afc_freq_obj *afc_freq_info) 10088 { 10089 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 10090 struct reg_fw_afc_power_event *power_info; 10091 uint8_t i; 10092 10093 pdev_priv_obj = reg_get_pdev_obj(pdev); 10094 10095 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 10096 reg_err("reg pdev priv obj is NULL"); 10097 return QDF_STATUS_E_FAILURE; 10098 } 10099 10100 if (!reg_is_afc_power_event_received(pdev)) { 10101 reg_err("afc power event is not received\n"); 10102 return QDF_STATUS_E_FAILURE; 10103 } 10104 10105 power_info = pdev_priv_obj->power_info; 10106 if (!power_info) { 10107 reg_err("power_info is NULL"); 10108 return QDF_STATUS_E_FAILURE; 10109 } 10110 10111 if (!num_freq_obj) { 10112 reg_err("num freq objs cannot be zero"); 10113 return QDF_STATUS_E_FAILURE; 10114 } 10115 10116 if (!afc_freq_info) 10117 return QDF_STATUS_E_FAILURE; 10118 10119 for (i = 0; i < num_freq_obj; i++) { 10120 struct afc_freq_obj *reg_afc_info = 10121 &power_info->afc_freq_info[i]; 10122 10123 afc_freq_info[i].low_freq = reg_afc_info->low_freq; 10124 afc_freq_info[i].high_freq = reg_afc_info->high_freq; 10125 afc_freq_info[i].max_psd = reg_afc_info->max_psd; 10126 } 10127 return QDF_STATUS_SUCCESS; 10128 } 10129 10130 QDF_STATUS 10131 reg_get_num_afc_freq_obj(struct wlan_objmgr_pdev *pdev, uint8_t *num_freq_obj) 10132 { 10133 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 10134 struct reg_fw_afc_power_event *power_info; 10135 10136 pdev_priv_obj = reg_get_pdev_obj(pdev); 10137 10138 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 10139 reg_err("reg pdev priv obj is NULL"); 10140 return QDF_STATUS_E_FAILURE; 10141 } 10142 10143 if (!reg_is_afc_power_event_received(pdev)) { 10144 reg_err("afc power event is not received\n"); 10145 return QDF_STATUS_E_FAILURE; 10146 } 10147 10148 power_info = pdev_priv_obj->power_info; 10149 if (!power_info) { 10150 reg_err("power_info is NULL"); 10151 return QDF_STATUS_E_FAILURE; 10152 } 10153 10154 if (!power_info->num_freq_objs) { 10155 reg_err("num freq objs cannot be zero"); 10156 return QDF_STATUS_E_FAILURE; 10157 } 10158 10159 *num_freq_obj = power_info->num_freq_objs; 10160 10161 return QDF_STATUS_SUCCESS; 10162 } 10163 #endif 10164 10165 #endif 10166 10167 #ifdef CONFIG_AFC_SUPPORT 10168 QDF_STATUS reg_set_afc_power_event_received(struct wlan_objmgr_pdev *pdev, 10169 bool val) 10170 { 10171 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 10172 10173 pdev_priv_obj = reg_get_pdev_obj(pdev); 10174 if (!pdev_priv_obj) { 10175 reg_err("pdev priv obj is NULL"); 10176 return QDF_STATUS_E_FAILURE; 10177 } 10178 pdev_priv_obj->is_6g_afc_power_event_received = val; 10179 10180 return QDF_STATUS_SUCCESS; 10181 } 10182 #endif 10183 10184 QDF_STATUS reg_process_r2p_table_update_response(struct wlan_objmgr_psoc *psoc, 10185 uint32_t pdev_id) 10186 { 10187 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 10188 QDF_STATUS status = QDF_STATUS_E_FAILURE; 10189 10190 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 10191 if (reg_tx_ops->end_r2p_table_update_wait) 10192 status = reg_tx_ops->end_r2p_table_update_wait(psoc, pdev_id); 10193 10194 return status; 10195 } 10196 10197 #ifndef CONFIG_REG_CLIENT 10198 bool reg_is_dev_supports_80p80(struct wlan_objmgr_pdev *pdev) 10199 { 10200 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 10201 struct wlan_objmgr_psoc *psoc; 10202 10203 psoc = wlan_pdev_get_psoc(pdev); 10204 if (!psoc) { 10205 reg_err("psoc is NULL"); 10206 return false; 10207 } 10208 10209 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 10210 if (!reg_tx_ops) { 10211 reg_err("reg_tx_ops is NULL"); 10212 return false; 10213 } 10214 10215 if (reg_tx_ops->is_80p80_supported) 10216 return reg_tx_ops->is_80p80_supported(pdev); 10217 10218 return false; 10219 } 10220 #endif 10221