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