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", 425 freq, chwidth); 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_err("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_err("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 { 4427 const struct bonded_channel_freq *bonded_chan_ptr = NULL; 4428 enum channel_state state; 4429 qdf_freq_t start_freq; 4430 uint16_t tx_power, psd_eirp; 4431 uint32_t chan_flags, min_chan_flags = 0; 4432 bool first_time = true; 4433 4434 if (!reg_is_6ghz_chan_freq(freq)) 4435 return QDF_STATUS_E_INVAL; 4436 4437 if (!is_psd) { 4438 reg_err("is_psd pointer null"); 4439 return QDF_STATUS_E_INVAL; 4440 } 4441 if (!min_tx_power) { 4442 reg_err("min_tx_power pointer null"); 4443 return QDF_STATUS_E_INVAL; 4444 } 4445 if (!min_psd_eirp) { 4446 reg_err("min_psd_eirp pointer null"); 4447 return QDF_STATUS_E_INVAL; 4448 } 4449 if (!power_type) { 4450 reg_err("power_type pointer null"); 4451 return QDF_STATUS_E_INVAL; 4452 } 4453 4454 state = reg_get_5g_bonded_channel_for_freq(pdev, 4455 freq, 4456 bw, 4457 &bonded_chan_ptr); 4458 if (state != CHANNEL_STATE_ENABLE && 4459 state != CHANNEL_STATE_DFS) { 4460 reg_err("invalid channel state %d", state); 4461 return QDF_STATUS_E_INVAL; 4462 } 4463 4464 if (bw <= CH_WIDTH_20MHZ) { 4465 if (reg_get_channel_power_attr_from_secondary_list_for_freq( 4466 pdev, freq, is_psd, &tx_power, 4467 &psd_eirp, &chan_flags) != QDF_STATUS_SUCCESS) 4468 return QDF_STATUS_E_INVAL; 4469 *min_psd_eirp = (int16_t)psd_eirp; 4470 *min_tx_power = tx_power; 4471 min_chan_flags = chan_flags; 4472 goto decide_power_type; 4473 } 4474 4475 start_freq = bonded_chan_ptr->start_freq; 4476 while (start_freq <= bonded_chan_ptr->end_freq) { 4477 if (reg_get_channel_power_attr_from_secondary_list_for_freq( 4478 pdev, start_freq, is_psd, &tx_power, 4479 &psd_eirp, &chan_flags) != QDF_STATUS_SUCCESS) 4480 return QDF_STATUS_E_INVAL; 4481 4482 if (first_time) { 4483 *min_psd_eirp = (int16_t)psd_eirp; 4484 *min_tx_power = tx_power; 4485 min_chan_flags = chan_flags; 4486 first_time = false; 4487 } 4488 if ((int16_t)psd_eirp < *min_psd_eirp) 4489 *min_psd_eirp = (int16_t)psd_eirp; 4490 if (tx_power < *min_tx_power) 4491 *min_tx_power = tx_power; 4492 min_chan_flags |= (chan_flags & REGULATORY_CHAN_AFC); 4493 min_chan_flags |= (chan_flags & REGULATORY_CHAN_INDOOR_ONLY); 4494 start_freq += 20; 4495 } 4496 4497 decide_power_type: 4498 if ((min_chan_flags & REGULATORY_CHAN_AFC) && 4499 (min_chan_flags & REGULATORY_CHAN_INDOOR_ONLY)) 4500 *power_type = REG_INDOOR_AP; 4501 else if (min_chan_flags & REGULATORY_CHAN_AFC) 4502 *power_type = REG_STANDARD_POWER_AP; 4503 else if (min_chan_flags & REGULATORY_CHAN_INDOOR_ONLY) 4504 *power_type = REG_INDOOR_AP; 4505 else 4506 *power_type = REG_VERY_LOW_POWER_AP; 4507 4508 return QDF_STATUS_SUCCESS; 4509 } 4510 #endif 4511 #endif 4512 4513 /** 4514 * reg_get_5g_bonded_chan_array_for_freq()- Return the channel state for a 4515 * 5G or 6G channel frequency based on the bonded channel. 4516 * @pdev: Pointer to pdev. 4517 * @freq: Channel center frequency. 4518 * @bonded_chan_ptr: Pointer to bonded_channel_freq. 4519 * 4520 * Return: Channel State 4521 */ 4522 static enum channel_state 4523 reg_get_5g_bonded_chan_array_for_freq(struct wlan_objmgr_pdev *pdev, 4524 uint16_t freq, 4525 const struct bonded_channel_freq * 4526 bonded_chan_ptr) 4527 { 4528 uint16_t chan_cfreq; 4529 enum channel_state chan_state = CHANNEL_STATE_INVALID; 4530 enum channel_state temp_chan_state; 4531 4532 if (!bonded_chan_ptr) { 4533 reg_debug("bonded chan ptr is NULL"); 4534 return chan_state; 4535 } 4536 4537 chan_cfreq = bonded_chan_ptr->start_freq; 4538 while (chan_cfreq <= bonded_chan_ptr->end_freq) { 4539 temp_chan_state = reg_get_channel_state_for_pwrmode( 4540 pdev, chan_cfreq, 4541 REG_CURRENT_PWR_MODE); 4542 if (temp_chan_state < chan_state) 4543 chan_state = temp_chan_state; 4544 chan_cfreq = chan_cfreq + 20; 4545 } 4546 4547 return chan_state; 4548 } 4549 4550 #ifdef CONFIG_REG_6G_PWRMODE 4551 /** 4552 * reg_get_5g_bonded_chan_array_for_pwrmode()- Return the channel state for a 4553 * 5G or 6G channel frequency based on the bonded channel. 4554 * @pdev: Pointer to pdev. 4555 * @freq: Channel center frequency. 4556 * @bonded_chan_ptr: Pointer to bonded_channel_freq. 4557 * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based 4558 * channel list will be chosen. 4559 * @input_punc_bitmap: Input puncture bitmap 4560 * 4561 * Return: Channel State 4562 */ 4563 static enum channel_state 4564 reg_get_5g_bonded_chan_array_for_pwrmode(struct wlan_objmgr_pdev *pdev, 4565 uint16_t freq, 4566 const struct bonded_channel_freq * 4567 bonded_chan_ptr, 4568 enum supported_6g_pwr_types 4569 in_6g_pwr_type, 4570 uint16_t input_punc_bitmap) 4571 { 4572 uint16_t chan_cfreq; 4573 enum channel_state chan_state = CHANNEL_STATE_INVALID; 4574 enum channel_state temp_chan_state; 4575 uint8_t i = 0; 4576 4577 if (!bonded_chan_ptr) { 4578 reg_debug("bonded chan ptr is NULL"); 4579 return chan_state; 4580 } 4581 4582 chan_cfreq = bonded_chan_ptr->start_freq; 4583 while (chan_cfreq <= bonded_chan_ptr->end_freq) { 4584 if (!reg_is_chan_bit_punctured(input_punc_bitmap, i)) { 4585 temp_chan_state = 4586 reg_get_channel_state_for_pwrmode(pdev, 4587 chan_cfreq, 4588 in_6g_pwr_type); 4589 if (temp_chan_state < chan_state) 4590 chan_state = temp_chan_state; 4591 } 4592 chan_cfreq = chan_cfreq + 20; 4593 i++; 4594 } 4595 4596 return chan_state; 4597 } 4598 #endif 4599 4600 #ifdef WLAN_FEATURE_11BE 4601 4602 QDF_STATUS reg_extract_puncture_by_bw(enum phy_ch_width ori_bw, 4603 uint16_t ori_puncture_bitmap, 4604 qdf_freq_t freq, 4605 qdf_freq_t cen320_freq, 4606 enum phy_ch_width new_bw, 4607 uint16_t *new_puncture_bitmap) 4608 { 4609 const struct bonded_channel_freq *ori_bonded_chan; 4610 const struct bonded_channel_freq *new_bonded_chan; 4611 uint16_t chan_cfreq; 4612 uint16_t new_bit; 4613 4614 if (ori_bw < new_bw) { 4615 reg_err_rl("freq %d, ori bw %d can't be smaller than new bw %d", 4616 freq, ori_bw, new_bw); 4617 return QDF_STATUS_E_FAILURE; 4618 } 4619 4620 if (ori_bw == new_bw) { 4621 *new_puncture_bitmap = ori_puncture_bitmap; 4622 return QDF_STATUS_SUCCESS; 4623 } 4624 4625 ori_bonded_chan = reg_get_bonded_chan_entry(freq, ori_bw, cen320_freq); 4626 new_bonded_chan = reg_get_bonded_chan_entry(freq, new_bw, 0); 4627 if (!ori_bonded_chan) { 4628 reg_err_rl("bonded chan fails, freq %d, ori bw %d, new bw %d", 4629 freq, ori_bw, new_bw); 4630 return QDF_STATUS_E_FAILURE; 4631 } 4632 4633 new_bit = 0; 4634 *new_puncture_bitmap = 0; 4635 chan_cfreq = ori_bonded_chan->start_freq; 4636 while (chan_cfreq <= ori_bonded_chan->end_freq) { 4637 /* 4638 * If the "new_bw" is 20, then new_bonded_chan = NULL and the 4639 * output puncturing bitmap (*new_puncture_bitmap) as per spec 4640 * should be 0. However, if the "ori_puncture_bitmap" has 4641 * punctured the primary channel (the only channel in 20Mhz 4642 * case), then the output "(*ori_puncture_bitmap) should contain 4643 * the same so that the caller can recognize the error in the 4644 * input pattern. 4645 */ 4646 if (freq == chan_cfreq || 4647 (new_bonded_chan && 4648 chan_cfreq >= new_bonded_chan->start_freq && 4649 chan_cfreq <= new_bonded_chan->end_freq)) { 4650 /* this frequency is in new bw */ 4651 *new_puncture_bitmap |= 4652 (ori_puncture_bitmap & 1) << new_bit; 4653 new_bit++; 4654 } 4655 4656 ori_puncture_bitmap >>= 1; 4657 chan_cfreq = chan_cfreq + BW_20_MHZ; 4658 } 4659 4660 return QDF_STATUS_SUCCESS; 4661 } 4662 4663 void reg_set_create_punc_bitmap(struct ch_params *ch_params, 4664 bool is_create_punc_bitmap) 4665 { 4666 ch_params->is_create_punc_bitmap = is_create_punc_bitmap; 4667 } 4668 4669 bool reg_is_punc_bitmap_valid(enum phy_ch_width bw, uint16_t puncture_bitmap) 4670 { 4671 int i, num_bws; 4672 const uint16_t *bonded_puncture_bitmap = NULL; 4673 uint16_t array_size = 0; 4674 bool is_punc_bitmap_valid = false; 4675 4676 num_bws = QDF_ARRAY_SIZE(bw_puncture_bitmap_pair_map); 4677 for (i = 0; i < num_bws; i++) { 4678 if (bw == bw_puncture_bitmap_pair_map[i].chwidth) { 4679 bonded_puncture_bitmap = 4680 bw_puncture_bitmap_pair_map[i].puncture_bitmap_arr; 4681 array_size = bw_puncture_bitmap_pair_map[i].array_size; 4682 break; 4683 } 4684 } 4685 4686 if (array_size && bonded_puncture_bitmap) { 4687 for (i = 0; i < array_size; i++) { 4688 if (puncture_bitmap == bonded_puncture_bitmap[i]) { 4689 is_punc_bitmap_valid = true; 4690 break; 4691 } 4692 } 4693 } 4694 4695 return is_punc_bitmap_valid; 4696 } 4697 4698 #ifdef QCA_DFS_BW_PUNCTURE 4699 uint16_t reg_find_nearest_puncture_pattern(enum phy_ch_width bw, 4700 uint16_t proposed_bitmap) 4701 { 4702 int i, num_bws; 4703 const uint16_t *bonded_puncture_bitmap = NULL; 4704 uint16_t array_size; 4705 uint16_t final_bitmap; 4706 4707 /* An input pattern = 0 will match any pattern 4708 * Therefore, ignore '0' pattern and return '0', as '0' matches '0'. 4709 */ 4710 if (!proposed_bitmap) 4711 return 0; 4712 4713 array_size = 0; 4714 final_bitmap = 0; 4715 4716 num_bws = QDF_ARRAY_SIZE(bw_puncture_bitmap_pair_map); 4717 for (i = 0; i < num_bws; i++) { 4718 if (bw == bw_puncture_bitmap_pair_map[i].chwidth) { 4719 bonded_puncture_bitmap = 4720 bw_puncture_bitmap_pair_map[i].puncture_bitmap_arr; 4721 array_size = bw_puncture_bitmap_pair_map[i].array_size; 4722 break; 4723 } 4724 } 4725 4726 if (array_size && bonded_puncture_bitmap) { 4727 for (i = 0; i < array_size; i++) { 4728 uint16_t valid_bitmap = bonded_puncture_bitmap[i]; 4729 4730 if ((proposed_bitmap | valid_bitmap) == valid_bitmap) { 4731 final_bitmap = valid_bitmap; 4732 break; 4733 } 4734 } 4735 } 4736 4737 return final_bitmap; 4738 } 4739 #endif /* QCA_DFS_BW_PUNCTURE */ 4740 4741 /** 4742 * reg_update_5g_bonded_channel_state_punc_for_freq() - update channel state 4743 * with static puncturing feature 4744 * @pdev: pointer to pdev 4745 * @bonded_chan_ptr: Pointer to bonded_channel_freq. 4746 * @ch_params: pointer to ch_params 4747 * @chan_state: chan_state to be updated 4748 * 4749 * Return: void 4750 */ 4751 static void reg_update_5g_bonded_channel_state_punc_for_freq( 4752 struct wlan_objmgr_pdev *pdev, 4753 const struct bonded_channel_freq *bonded_chan_ptr, 4754 struct ch_params *ch_params, 4755 enum channel_state *chan_state) 4756 { 4757 qdf_freq_t chan_cfreq; 4758 enum channel_state temp_chan_state; 4759 uint16_t puncture_bitmap = 0; 4760 int i = 0; 4761 enum channel_state update_state = CHANNEL_STATE_ENABLE; 4762 4763 if (!pdev || !bonded_chan_ptr || !ch_params || !chan_state || 4764 !ch_params->is_create_punc_bitmap) 4765 return; 4766 4767 chan_cfreq = bonded_chan_ptr->start_freq; 4768 while (chan_cfreq <= bonded_chan_ptr->end_freq) { 4769 temp_chan_state = reg_get_channel_state_for_pwrmode( 4770 pdev, 4771 chan_cfreq, 4772 REG_CURRENT_PWR_MODE); 4773 if (!reg_is_state_allowed(temp_chan_state)) 4774 puncture_bitmap |= BIT(i); 4775 /* Remember of any of the sub20 channel is a DFS channel */ 4776 if (temp_chan_state == CHANNEL_STATE_DFS) 4777 update_state = CHANNEL_STATE_DFS; 4778 chan_cfreq = chan_cfreq + BW_20_MHZ; 4779 i++; 4780 } 4781 /* Validate puncture bitmap. Update channel state. */ 4782 if (reg_is_punc_bitmap_valid(ch_params->ch_width, puncture_bitmap)) { 4783 *chan_state = update_state; 4784 ch_params->reg_punc_bitmap = puncture_bitmap; 4785 } 4786 } 4787 4788 #ifdef CONFIG_REG_6G_PWRMODE 4789 /** 4790 * reg_update_5g_bonded_channel_state_punc_for_pwrmode() - update channel state 4791 * with static puncturing feature 4792 * @pdev: pointer to pdev 4793 * @bonded_chan_ptr: Pointer to bonded_channel_freq. 4794 * @ch_params: pointer to ch_params 4795 * @chan_state: chan_state to be updated 4796 * 4797 * Return: void 4798 */ 4799 static void reg_update_5g_bonded_channel_state_punc_for_pwrmode( 4800 struct wlan_objmgr_pdev *pdev, 4801 const struct bonded_channel_freq *bonded_chan_ptr, 4802 struct ch_params *ch_params, 4803 enum channel_state *chan_state, 4804 enum supported_6g_pwr_types in_6g_pwr_mode) 4805 { 4806 qdf_freq_t chan_cfreq; 4807 enum channel_state temp_chan_state; 4808 uint16_t puncture_bitmap = 0; 4809 int i = 0; 4810 enum channel_state update_state = CHANNEL_STATE_ENABLE; 4811 4812 if (!pdev || !bonded_chan_ptr || !ch_params || !chan_state || 4813 !ch_params->is_create_punc_bitmap) 4814 return; 4815 4816 chan_cfreq = bonded_chan_ptr->start_freq; 4817 while (chan_cfreq <= bonded_chan_ptr->end_freq) { 4818 temp_chan_state = 4819 reg_get_channel_state_for_pwrmode(pdev, chan_cfreq, 4820 in_6g_pwr_mode); 4821 if (!reg_is_state_allowed(temp_chan_state)) 4822 puncture_bitmap |= BIT(i); 4823 /* Remember of any of the sub20 channel is a DFS channel */ 4824 if (temp_chan_state == CHANNEL_STATE_DFS) 4825 update_state = CHANNEL_STATE_DFS; 4826 chan_cfreq = chan_cfreq + BW_20_MHZ; 4827 i++; 4828 } 4829 /* Validate puncture bitmap. Update channel state. */ 4830 if (reg_is_punc_bitmap_valid(ch_params->ch_width, puncture_bitmap)) { 4831 *chan_state = update_state; 4832 ch_params->reg_punc_bitmap = puncture_bitmap; 4833 } 4834 } 4835 #endif 4836 4837 #ifdef CONFIG_REG_CLIENT 4838 QDF_STATUS reg_apply_puncture(struct wlan_objmgr_pdev *pdev, 4839 uint16_t puncture_bitmap, 4840 qdf_freq_t freq, 4841 enum phy_ch_width bw, 4842 qdf_freq_t cen320_freq) 4843 { 4844 const struct bonded_channel_freq *bonded_chan; 4845 qdf_freq_t chan_cfreq; 4846 enum channel_enum chan_enum; 4847 struct regulatory_channel *mas_chan_list; 4848 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4849 bool is_puncture; 4850 uint16_t i = 0; 4851 4852 pdev_priv_obj = reg_get_pdev_obj(pdev); 4853 4854 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4855 reg_err_rl("pdev reg obj is NULL"); 4856 return QDF_STATUS_E_FAILURE; 4857 } 4858 4859 mas_chan_list = pdev_priv_obj->mas_chan_list; 4860 if (!mas_chan_list) { 4861 reg_err_rl("mas chan_list is NULL"); 4862 return QDF_STATUS_E_FAILURE; 4863 } 4864 bonded_chan = reg_get_bonded_chan_entry(freq, bw, cen320_freq); 4865 if (!bonded_chan) { 4866 reg_err_rl("bonded chan fails, freq %d, bw %d, cen320_freq %d", 4867 freq, bw, cen320_freq); 4868 return QDF_STATUS_E_FAILURE; 4869 } 4870 4871 chan_cfreq = bonded_chan->start_freq; 4872 while (chan_cfreq <= bonded_chan->end_freq) { 4873 is_puncture = BIT(i) & puncture_bitmap; 4874 if (is_puncture) { 4875 chan_enum = reg_get_chan_enum_for_freq(chan_cfreq); 4876 if (reg_is_chan_enum_invalid(chan_enum)) { 4877 reg_debug_rl("Invalid chan enum %d", chan_enum); 4878 return QDF_STATUS_E_FAILURE; 4879 } 4880 mas_chan_list[chan_enum].is_static_punctured = true; 4881 } 4882 i++; 4883 chan_cfreq = chan_cfreq + BW_20_MHZ; 4884 } 4885 4886 reg_compute_pdev_current_chan_list(pdev_priv_obj); 4887 4888 return QDF_STATUS_SUCCESS; 4889 } 4890 4891 QDF_STATUS reg_remove_puncture(struct wlan_objmgr_pdev *pdev) 4892 { 4893 enum channel_enum chan_enum; 4894 struct regulatory_channel *mas_chan_list; 4895 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4896 4897 pdev_priv_obj = reg_get_pdev_obj(pdev); 4898 4899 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4900 reg_err_rl("pdev reg obj is NULL"); 4901 return QDF_STATUS_E_FAILURE; 4902 } 4903 4904 mas_chan_list = pdev_priv_obj->mas_chan_list; 4905 if (!mas_chan_list) { 4906 reg_err_rl("mas chan_list is NULL"); 4907 return QDF_STATUS_E_FAILURE; 4908 } 4909 4910 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) 4911 if (mas_chan_list[chan_enum].is_static_punctured) 4912 mas_chan_list[chan_enum].is_static_punctured = false; 4913 4914 reg_compute_pdev_current_chan_list(pdev_priv_obj); 4915 4916 return QDF_STATUS_SUCCESS; 4917 } 4918 #endif 4919 4920 #else 4921 static void reg_update_5g_bonded_channel_state_punc_for_freq( 4922 struct wlan_objmgr_pdev *pdev, 4923 const struct bonded_channel_freq *bonded_chan_ptr, 4924 struct ch_params *ch_params, 4925 enum channel_state *chan_state) 4926 { 4927 } 4928 4929 static void reg_update_5g_bonded_channel_state_punc_for_pwrmode( 4930 struct wlan_objmgr_pdev *pdev, 4931 const struct bonded_channel_freq *bonded_chan_ptr, 4932 struct ch_params *ch_params, 4933 enum channel_state *chan_state, 4934 enum supported_6g_pwr_types in_6g_pwr_mode) 4935 { 4936 } 4937 #endif 4938 4939 enum channel_state 4940 reg_get_5g_bonded_channel_state_for_freq(struct wlan_objmgr_pdev *pdev, 4941 qdf_freq_t freq, 4942 struct ch_params *ch_params) 4943 { 4944 enum phy_ch_width bw; 4945 enum channel_enum ch_indx; 4946 enum channel_state chan_state; 4947 struct regulatory_channel *reg_channels; 4948 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4949 bool bw_enabled = false; 4950 const struct bonded_channel_freq *bonded_chan_ptr = NULL; 4951 4952 if (!ch_params) { 4953 reg_err_rl("Invalid ch_params"); 4954 return CHANNEL_STATE_INVALID; 4955 } 4956 bw = ch_params->ch_width; 4957 if (bw > CH_WIDTH_80P80MHZ) { 4958 reg_err_rl("bw (%d) passed is not good", bw); 4959 return CHANNEL_STATE_INVALID; 4960 } 4961 4962 chan_state = reg_get_5g_bonded_channel_for_freq(pdev, freq, bw, 4963 &bonded_chan_ptr); 4964 4965 reg_update_5g_bonded_channel_state_punc_for_freq(pdev, 4966 bonded_chan_ptr, 4967 ch_params, 4968 &chan_state); 4969 4970 if ((chan_state == CHANNEL_STATE_INVALID) || 4971 (chan_state == CHANNEL_STATE_DISABLE)) 4972 return chan_state; 4973 4974 pdev_priv_obj = reg_get_pdev_obj(pdev); 4975 4976 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4977 reg_err("pdev reg obj is NULL"); 4978 return CHANNEL_STATE_INVALID; 4979 } 4980 reg_channels = pdev_priv_obj->cur_chan_list; 4981 4982 ch_indx = reg_get_chan_enum_for_freq(freq); 4983 if (reg_is_chan_enum_invalid(ch_indx)) 4984 return CHANNEL_STATE_INVALID; 4985 if (bw == CH_WIDTH_5MHZ) 4986 bw_enabled = true; 4987 else if (bw == CH_WIDTH_10MHZ) 4988 bw_enabled = (reg_channels[ch_indx].min_bw <= 10) && 4989 (reg_channels[ch_indx].max_bw >= 10); 4990 else if (bw == CH_WIDTH_20MHZ) 4991 bw_enabled = (reg_channels[ch_indx].min_bw <= 20) && 4992 (reg_channels[ch_indx].max_bw >= 20); 4993 else if (bw == CH_WIDTH_40MHZ) 4994 bw_enabled = (reg_channels[ch_indx].min_bw <= 40) && 4995 (reg_channels[ch_indx].max_bw >= 40); 4996 else if (bw == CH_WIDTH_80MHZ) 4997 bw_enabled = (reg_channels[ch_indx].min_bw <= 80) && 4998 (reg_channels[ch_indx].max_bw >= 80); 4999 else if (bw == CH_WIDTH_160MHZ) 5000 bw_enabled = (reg_channels[ch_indx].min_bw <= 160) && 5001 (reg_channels[ch_indx].max_bw >= 160); 5002 else if (bw == CH_WIDTH_80P80MHZ) 5003 bw_enabled = (reg_channels[ch_indx].min_bw <= 80) && 5004 (reg_channels[ch_indx].max_bw >= 80); 5005 5006 if (bw_enabled) 5007 return chan_state; 5008 return CHANNEL_STATE_DISABLE; 5009 } 5010 5011 #ifdef CONFIG_REG_6G_PWRMODE 5012 enum channel_state 5013 reg_get_5g_bonded_channel_state_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5014 qdf_freq_t freq, 5015 struct ch_params *ch_params, 5016 enum supported_6g_pwr_types 5017 in_6g_pwr_mode) 5018 { 5019 enum phy_ch_width bw; 5020 enum channel_enum ch_indx; 5021 enum channel_state chan_state; 5022 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5023 bool bw_enabled = false; 5024 const struct bonded_channel_freq *bonded_chan_ptr = NULL; 5025 uint16_t min_bw, max_bw; 5026 uint16_t in_punc_bitmap = reg_fetch_punc_bitmap(ch_params); 5027 5028 if (!ch_params) { 5029 reg_err_rl("Invalid ch_params"); 5030 return CHANNEL_STATE_INVALID; 5031 } 5032 bw = ch_params->ch_width; 5033 if (bw > CH_WIDTH_80P80MHZ) { 5034 reg_err_rl("bw (%d) passed is not good", bw); 5035 return CHANNEL_STATE_INVALID; 5036 } 5037 5038 chan_state = reg_get_5g_bonded_channel_for_pwrmode(pdev, freq, bw, 5039 &bonded_chan_ptr, 5040 in_6g_pwr_mode, 5041 in_punc_bitmap); 5042 5043 reg_update_5g_bonded_channel_state_punc_for_pwrmode( 5044 pdev, bonded_chan_ptr, 5045 ch_params, &chan_state, 5046 in_6g_pwr_mode); 5047 5048 if ((chan_state == CHANNEL_STATE_INVALID) || 5049 (chan_state == CHANNEL_STATE_DISABLE)) 5050 return chan_state; 5051 5052 pdev_priv_obj = reg_get_pdev_obj(pdev); 5053 5054 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5055 reg_err("pdev reg obj is NULL"); 5056 return CHANNEL_STATE_INVALID; 5057 } 5058 5059 ch_indx = reg_get_chan_enum_for_freq(freq); 5060 if (reg_is_chan_enum_invalid(ch_indx)) 5061 return CHANNEL_STATE_INVALID; 5062 5063 if (reg_get_min_max_bw_reg_chan_list(pdev, ch_indx, in_6g_pwr_mode, 5064 &min_bw, &max_bw)) 5065 return CHANNEL_STATE_INVALID; 5066 5067 if (bw == CH_WIDTH_5MHZ) 5068 bw_enabled = true; 5069 else if (bw == CH_WIDTH_10MHZ) 5070 bw_enabled = (min_bw <= 10) && 5071 (max_bw >= 10); 5072 else if (bw == CH_WIDTH_20MHZ) 5073 bw_enabled = (min_bw <= 20) && 5074 (max_bw >= 20); 5075 else if (bw == CH_WIDTH_40MHZ) 5076 bw_enabled = (min_bw <= 40) && 5077 (max_bw >= 40); 5078 else if (bw == CH_WIDTH_80MHZ) 5079 bw_enabled = (min_bw <= 80) && 5080 (max_bw >= 80); 5081 else if (bw == CH_WIDTH_160MHZ) 5082 bw_enabled = (min_bw <= 160) && 5083 (max_bw >= 160); 5084 else if (bw == CH_WIDTH_80P80MHZ) 5085 bw_enabled = (min_bw <= 80) && 5086 (max_bw >= 80); 5087 5088 if (bw_enabled) 5089 return chan_state; 5090 return CHANNEL_STATE_DISABLE; 5091 } 5092 #endif 5093 5094 enum channel_state 5095 reg_get_2g_bonded_channel_state_for_freq(struct wlan_objmgr_pdev *pdev, 5096 qdf_freq_t oper_ch_freq, 5097 qdf_freq_t sec_ch_freq, 5098 enum phy_ch_width bw) 5099 { 5100 enum channel_enum chan_idx; 5101 enum channel_state chan_state; 5102 struct regulatory_channel *reg_channels; 5103 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5104 bool bw_enabled = false; 5105 enum channel_state chan_state2 = CHANNEL_STATE_INVALID; 5106 5107 if (bw > CH_WIDTH_40MHZ) 5108 return CHANNEL_STATE_INVALID; 5109 5110 if (bw == CH_WIDTH_40MHZ) { 5111 if ((sec_ch_freq + 20 != oper_ch_freq) && 5112 (oper_ch_freq + 20 != sec_ch_freq)) 5113 return CHANNEL_STATE_INVALID; 5114 chan_state2 = 5115 reg_get_channel_state_for_pwrmode(pdev, 5116 sec_ch_freq, 5117 REG_CURRENT_PWR_MODE); 5118 if (chan_state2 == CHANNEL_STATE_INVALID) 5119 return chan_state2; 5120 } 5121 pdev_priv_obj = reg_get_pdev_obj(pdev); 5122 5123 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5124 reg_err("reg pdev priv obj is NULL"); 5125 return CHANNEL_STATE_INVALID; 5126 } 5127 5128 reg_channels = pdev_priv_obj->cur_chan_list; 5129 5130 chan_state = reg_get_channel_state_for_pwrmode(pdev, 5131 oper_ch_freq, 5132 REG_CURRENT_PWR_MODE); 5133 if (chan_state2 < chan_state) 5134 chan_state = chan_state2; 5135 5136 if ((chan_state == CHANNEL_STATE_INVALID) || 5137 (chan_state == CHANNEL_STATE_DISABLE)) 5138 return chan_state; 5139 5140 chan_idx = reg_get_chan_enum_for_freq(oper_ch_freq); 5141 if (reg_is_chan_enum_invalid(chan_idx)) 5142 return CHANNEL_STATE_INVALID; 5143 if (bw == CH_WIDTH_5MHZ) 5144 bw_enabled = true; 5145 else if (bw == CH_WIDTH_10MHZ) 5146 bw_enabled = (reg_channels[chan_idx].min_bw <= 10) && 5147 (reg_channels[chan_idx].max_bw >= 10); 5148 else if (bw == CH_WIDTH_20MHZ) 5149 bw_enabled = (reg_channels[chan_idx].min_bw <= 20) && 5150 (reg_channels[chan_idx].max_bw >= 20); 5151 else if (bw == CH_WIDTH_40MHZ) 5152 bw_enabled = (reg_channels[chan_idx].min_bw <= 40) && 5153 (reg_channels[chan_idx].max_bw >= 40); 5154 5155 if (bw_enabled) 5156 return chan_state; 5157 else 5158 return CHANNEL_STATE_DISABLE; 5159 5160 return CHANNEL_STATE_ENABLE; 5161 } 5162 5163 #ifdef WLAN_FEATURE_11BE 5164 5165 /** 5166 * reg_get_20mhz_channel_state_based_on_nol() - Get channel state of the 5167 * given 20MHZ channel. If the freq is in NOL/NOL history, it is considered 5168 * as enabled if "treat_nol_chan_as_disabled" is false, else the state is 5169 * considered as "disabled". 5170 * @pdev: Pointer to struct wlan_objmgr_pdev 5171 * @freq: Primary frequency 5172 * @treat_nol_chan_as_disabled: Flag to treat nol chan as enabled/disabled 5173 * @in_6g_pwr_type: Input 6g power type 5174 * 5175 * Return - Channel state 5176 */ 5177 static enum channel_state 5178 reg_get_20mhz_channel_state_based_on_nol(struct wlan_objmgr_pdev *pdev, 5179 qdf_freq_t freq, 5180 bool treat_nol_chan_as_disabled, 5181 enum supported_6g_pwr_types in_6g_pwr_type) 5182 { 5183 if (treat_nol_chan_as_disabled) 5184 return reg_get_channel_state_for_pwrmode(pdev, freq, 5185 in_6g_pwr_type); 5186 return reg_get_nol_channel_state(pdev, freq, 5187 in_6g_pwr_type); 5188 } 5189 5190 /** 5191 * reg_get_320_bonded_chan_array() - Fetches a list of bonded channel pointers 5192 * for the given bonded channel array. If 320 band center is specified, 5193 * return the bonded channel pointer comprising of given band center else 5194 * return list of all available bonded channel pair. 5195 * 5196 * @pdev: Pointer to struct wlan_objmgr_pdev. 5197 * @freq: Input frequency in MHZ whose bonded channel pointer must be fetched. 5198 * @band_center_320: Channel center frequency of 320MHZ channel. 5199 * @bonded_chan_ar: Array of bonded channel list. 5200 * @array_size: Size of bonded channel array. 5201 * @bonded_chan_ptr: Pointer to hold the address of bonded_channel_freq index. 5202 * 5203 * Return: number of bonded channel arrays fetched. 5204 */ 5205 5206 #define MAX_NUM_BONDED_PAIR 2 5207 static uint8_t 5208 reg_get_320_bonded_chan_array(struct wlan_objmgr_pdev *pdev, 5209 qdf_freq_t freq, 5210 qdf_freq_t band_center_320, 5211 const struct bonded_channel_freq bonded_chan_ar[], 5212 uint16_t array_size, 5213 const struct bonded_channel_freq 5214 *bonded_chan_ptr[]) 5215 { 5216 int i; 5217 uint8_t num_bonded_pairs = 0; 5218 5219 /* Fetch all possible bonded channel pointers for the given freq */ 5220 if (!band_center_320) { 5221 for (i = 0 ; i < array_size && 5222 num_bonded_pairs < MAX_NUM_BONDED_PAIR; i++) { 5223 if ((freq >= bonded_chan_ar[i].start_freq) && 5224 (freq <= bonded_chan_ar[i].end_freq)) { 5225 bonded_chan_ptr[num_bonded_pairs] = 5226 &bonded_chan_ar[i]; 5227 num_bonded_pairs++; 5228 } 5229 } 5230 } else { 5231 /* Fetch the bonded channel pointer for the given band_center */ 5232 for (i = 0; i < array_size; i++) { 5233 qdf_freq_t bandstart = bonded_chan_ar[i].start_freq; 5234 5235 if (band_center_320 == 5236 reg_get_band_cen_from_bandstart(BW_320_MHZ, 5237 bandstart)) { 5238 bonded_chan_ptr[num_bonded_pairs] = 5239 &bonded_chan_ar[i]; 5240 num_bonded_pairs++; 5241 break; 5242 } 5243 } 5244 } 5245 return num_bonded_pairs; 5246 } 5247 5248 #define SUB_CHAN_BW 20 /* 20 MHZ */ 5249 #define BW_160MHZ 160 5250 #define REG_IS_TOT_CHAN_BW_BELOW_160(_x, _y) \ 5251 (reg_is_state_allowed((_x)) && (_y) < BW_160MHZ) 5252 5253 static inline qdf_freq_t 5254 reg_get_endchan_cen_from_bandstart(qdf_freq_t band_start, 5255 uint16_t bw) 5256 { 5257 uint16_t left_edge_freq = band_start - BW_10_MHZ; 5258 5259 return left_edge_freq + bw - BW_10_MHZ; 5260 } 5261 #endif 5262 5263 #ifdef WLAN_FEATURE_11BE 5264 enum channel_state 5265 reg_get_chan_state_for_320(struct wlan_objmgr_pdev *pdev, 5266 uint16_t freq, 5267 qdf_freq_t band_center_320, 5268 enum phy_ch_width ch_width, 5269 const struct bonded_channel_freq 5270 **bonded_chan_ptr_ptr, 5271 enum supported_6g_pwr_types in_6g_pwr_type, 5272 bool treat_nol_chan_as_disabled, 5273 uint16_t input_punc_bitmap) 5274 { 5275 uint8_t num_bonded_pairs; 5276 uint16_t array_size = 5277 QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq); 5278 const struct bonded_channel_freq *bonded_ch_ptr[2] = { 5279 NULL, NULL}; 5280 uint16_t punct_pattern; 5281 5282 /* For now sending band center freq as 0 */ 5283 num_bonded_pairs = 5284 reg_get_320_bonded_chan_array(pdev, freq, band_center_320, 5285 bonded_chan_320mhz_list_freq, 5286 array_size, bonded_ch_ptr); 5287 if (!num_bonded_pairs) { 5288 reg_info("No 320MHz bonded pair for freq %d", freq); 5289 return CHANNEL_STATE_INVALID; 5290 } 5291 /* Taking only first bonded pair */ 5292 *bonded_chan_ptr_ptr = bonded_ch_ptr[0]; 5293 5294 return reg_get_320_bonded_channel_state_for_pwrmode(pdev, freq, 5295 bonded_ch_ptr[0], 5296 ch_width, 5297 &punct_pattern, 5298 in_6g_pwr_type, 5299 treat_nol_chan_as_disabled, 5300 input_punc_bitmap); 5301 } 5302 #endif 5303 5304 #ifdef WLAN_FEATURE_11BE 5305 enum channel_state 5306 reg_get_320_bonded_channel_state_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5307 qdf_freq_t freq, 5308 const struct bonded_channel_freq 5309 *bonded_chan_ptr, 5310 enum phy_ch_width bw, 5311 uint16_t *out_punc_bitmap, 5312 enum supported_6g_pwr_types 5313 in_6g_pwr_type, 5314 bool treat_nol_chan_as_disabled, 5315 uint16_t input_punc_bitmap) 5316 { 5317 enum channel_state chan_state = CHANNEL_STATE_INVALID; 5318 enum channel_state temp_chan_state, prim_chan_state; 5319 uint16_t startchan_cfreq, endchan_cfreq; 5320 uint16_t max_cont_bw, i; 5321 enum channel_state update_state = CHANNEL_STATE_ENABLE; 5322 5323 *out_punc_bitmap = ALL_SCHANS_PUNC; 5324 5325 if (!bonded_chan_ptr) 5326 return chan_state; 5327 5328 startchan_cfreq = bonded_chan_ptr->start_freq; 5329 endchan_cfreq = 5330 reg_get_endchan_cen_from_bandstart(startchan_cfreq, 5331 BW_320_MHZ); 5332 max_cont_bw = 0; 5333 i = 0; 5334 5335 while (startchan_cfreq <= endchan_cfreq) { 5336 if (!reg_is_chan_bit_punctured(input_punc_bitmap, i)) { 5337 temp_chan_state = 5338 reg_get_20mhz_channel_state_based_on_nol(pdev, 5339 startchan_cfreq, 5340 treat_nol_chan_as_disabled, 5341 in_6g_pwr_type); 5342 5343 if (reg_is_state_allowed(temp_chan_state)) { 5344 max_cont_bw += SUB_CHAN_BW; 5345 *out_punc_bitmap &= ~BIT(i); 5346 /* Remember if sub20 channel is DFS channel */ 5347 if (temp_chan_state == CHANNEL_STATE_DFS) 5348 update_state = CHANNEL_STATE_DFS; 5349 } 5350 5351 if (temp_chan_state < chan_state) 5352 chan_state = temp_chan_state; 5353 } 5354 startchan_cfreq = startchan_cfreq + SUB_CHAN_BW; 5355 i++; 5356 } 5357 5358 /* Validate puncture bitmap. Update channel state. */ 5359 if (reg_is_punc_bitmap_valid(CH_WIDTH_320MHZ, *out_punc_bitmap)) { 5360 chan_state = update_state; 5361 } 5362 5363 prim_chan_state = 5364 reg_get_20mhz_channel_state_based_on_nol(pdev, freq, 5365 treat_nol_chan_as_disabled, 5366 in_6g_pwr_type); 5367 5368 /* After iterating through all the subchannels, if the final channel 5369 * state is invalid/disable, it means all our subchannels are not 5370 * valid and we could not find a 320 MHZ channel. 5371 * If we have found a channel where the max width is: 5372 * 1. Less than 160: there is no puncturing needed. Hence return 5373 * the chan state as invalid. Or if the primary freq given is not 5374 * supported by regulatory, the channel cannot be enabled as a 5375 * punctured channel. So return channel state as invalid. 5376 * 2. If greater than 160: Mark the invalid channels as punctured. 5377 * and return channel state as ENABLE. 5378 */ 5379 if (REG_IS_TOT_CHAN_BW_BELOW_160(chan_state, max_cont_bw) || 5380 !reg_is_state_allowed(prim_chan_state)) 5381 return CHANNEL_STATE_INVALID; 5382 5383 return chan_state; 5384 } 5385 5386 static inline bool reg_is_pri_within_240mhz_chan(qdf_freq_t freq) 5387 { 5388 return (freq >= CHAN_FREQ_5660 && freq <= CHAN_FREQ_5720); 5389 } 5390 5391 /** 5392 * reg_fill_chan320mhz_seg0_center() - Fill the primary segment center 5393 * for a 320MHz channel in the given channel param. Primary segment center 5394 * of a 320MHZ is the 160MHZ segment center of the given freq. 5395 * @pdev: Pointer to struct wlan_objmgr_pdev. 5396 * @ch_param: channel params to be filled. 5397 * @freq: Input primary frequency in MHZ. 5398 * 5399 * Return: void. 5400 */ 5401 static void 5402 reg_fill_chan320mhz_seg0_center(struct wlan_objmgr_pdev *pdev, 5403 struct ch_params *ch_param, qdf_freq_t freq) 5404 { 5405 const struct bonded_channel_freq *t_bonded_ch_ptr; 5406 5407 t_bonded_ch_ptr = reg_get_bonded_chan_entry(freq, CH_WIDTH_160MHZ, 0); 5408 if (t_bonded_ch_ptr) { 5409 ch_param->mhz_freq_seg0 = 5410 (t_bonded_ch_ptr->start_freq + 5411 t_bonded_ch_ptr->end_freq) / 2; 5412 ch_param->center_freq_seg0 = 5413 reg_freq_to_chan(pdev, 5414 ch_param->mhz_freq_seg0); 5415 } else { 5416 /** 5417 * If we do not find a 160Mhz bonded pair, since it is 5418 * for a 320Mhz channel we need to also see if we can find a 5419 * pseudo 160Mhz channel for the special case of 5420 * 5Ghz 240Mhz channel. 5421 */ 5422 if (reg_is_pri_within_240mhz_chan(freq)) { 5423 ch_param->mhz_freq_seg0 = 5424 PRIM_SEG_FREQ_CENTER_240MHZ_5G_CHAN; 5425 ch_param->center_freq_seg0 = 5426 PRIM_SEG_IEEE_CENTER_240MHZ_5G_CHAN; 5427 } else { 5428 ch_param->ch_width = CH_WIDTH_INVALID; 5429 reg_err("Cannot find 160Mhz centers for freq %d", freq); 5430 } 5431 } 5432 } 5433 5434 /** 5435 * reg_fill_channel_list_for_320() - Fill 320MHZ channel list. If we 5436 * are unable to find a channel whose width is greater than 160MHZ and less 5437 * than 320 with the help of puncturing, using the given freq, set "update_bw" 5438 * variable to be true, lower the channel width and return to the caller. 5439 * The caller fetches a channel of reduced mode based on "update_bw" flag. 5440 * 5441 * If 320 band center is 0, return all the 320 channels 5442 * that match the primary frequency else return only channel 5443 * that matches 320 band center. 5444 * 5445 * @pdev: Pointer to struct wlan_objmgr_pdev. 5446 * @freq: Input frequency in MHZ. 5447 * @ch_width: Input channel width, if a channel of the given width is not 5448 * found, reduce the channel width to the next lower mode and pass it to the 5449 * caller. 5450 * @band_center_320: Center of 320MHZ channel. 5451 * @chan_list: Pointer to reg_channel_list to be filled. 5452 * @update_bw: Flag to hold if bw is updated. 5453 * @treat_nol_chan_as_disabled: Bool to treat NOL channels as disabled/enabled 5454 * 5455 * Return - None. 5456 */ 5457 static void 5458 reg_fill_channel_list_for_320(struct wlan_objmgr_pdev *pdev, 5459 qdf_freq_t freq, 5460 enum phy_ch_width *in_ch_width, 5461 qdf_freq_t band_center_320, 5462 struct reg_channel_list *chan_list, 5463 bool *update_bw, 5464 bool treat_nol_chan_as_disabled) 5465 { 5466 uint8_t num_bonded_pairs, i, num_ch_params; 5467 enum channel_state chan_state; 5468 uint16_t array_size = QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq); 5469 uint16_t out_punc_bitmap; 5470 uint16_t max_reg_bw; 5471 enum channel_enum chan_enum; 5472 const struct bonded_channel_freq *bonded_ch_ptr[2] = {NULL, NULL}; 5473 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5474 5475 *update_bw = false; 5476 5477 chan_enum = reg_get_chan_enum_for_freq(freq); 5478 if (reg_is_chan_enum_invalid(chan_enum)) { 5479 reg_err("chan freq is not valid"); 5480 return; 5481 } 5482 5483 pdev_priv_obj = reg_get_pdev_obj(pdev); 5484 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5485 reg_err("reg pdev priv obj is NULL"); 5486 return; 5487 } 5488 5489 /* Maximum bandwidth of the channel supported by regulatory for 5490 * the given freq. 5491 */ 5492 max_reg_bw = pdev_priv_obj->cur_chan_list[chan_enum].max_bw; 5493 5494 /* Regulatory does not support BW greater than 160. 5495 * Try finding a channel in a lower mode. 5496 */ 5497 if (max_reg_bw <= BW_160MHZ) { 5498 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5499 *update_bw = true; 5500 return; 5501 } 5502 5503 num_bonded_pairs = 5504 reg_get_320_bonded_chan_array(pdev, freq, band_center_320, 5505 bonded_chan_320mhz_list_freq, 5506 array_size, 5507 bonded_ch_ptr); 5508 5509 if (!num_bonded_pairs) { 5510 if (band_center_320) { 5511 reg_debug("No bonded pair for the given band_center\n"); 5512 chan_list->num_ch_params = 0; 5513 } else { 5514 /* Could not find a 320 MHZ bonded channel pair, 5515 * find a channel of lower BW. 5516 */ 5517 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5518 *update_bw = true; 5519 } 5520 return; 5521 } 5522 5523 for (i = 0, num_ch_params = 0 ; i < num_bonded_pairs; i++) { 5524 /* Chan_state to hold the channel state of bonding 5525 * pair of channels. 5526 */ 5527 uint16_t in_punc_bitmap = 5528 chan_list->chan_param[i].input_punc_bitmap; 5529 5530 chan_state = 5531 reg_get_320_bonded_channel_state_for_pwrmode( 5532 pdev, freq, 5533 bonded_ch_ptr[i], 5534 *in_ch_width, 5535 &out_punc_bitmap, 5536 REG_CURRENT_PWR_MODE, 5537 treat_nol_chan_as_disabled, 5538 in_punc_bitmap); 5539 5540 if (reg_is_state_allowed(chan_state)) { 5541 struct ch_params *t_chan_param = 5542 &chan_list->chan_param[num_ch_params]; 5543 5544 t_chan_param->mhz_freq_seg1 = 5545 (bonded_ch_ptr[i]->start_freq + 5546 bonded_ch_ptr[i]->end_freq) / 2; 5547 t_chan_param->center_freq_seg1 = 5548 reg_freq_to_chan(pdev, 5549 t_chan_param->mhz_freq_seg1); 5550 t_chan_param->ch_width = *in_ch_width; 5551 t_chan_param->reg_punc_bitmap = out_punc_bitmap; 5552 5553 reg_fill_chan320mhz_seg0_center(pdev, 5554 t_chan_param, 5555 freq); 5556 num_ch_params++; 5557 chan_list->num_ch_params = num_ch_params; 5558 } 5559 } 5560 5561 /* The bonded pairs could not create any channels, 5562 * lower the bandwidth to find a channel. 5563 */ 5564 if (!chan_list->num_ch_params) { 5565 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5566 *update_bw = true; 5567 } 5568 } 5569 5570 #ifdef CONFIG_REG_6G_PWRMODE 5571 /** 5572 * reg_fill_channel_list_for_320_for_pwrmode() - Fill 320MHZ channel list. If we 5573 * are unable to find a channel whose width is greater than 160MHZ and less 5574 * than 320 with the help of puncturing, using the given freq, set "update_bw" 5575 * variable to be true, lower the channel width and return to the caller. 5576 * The caller fetches a channel of reduced mode based on "update_bw" flag. 5577 * 5578 * If 320 band center is 0, return all the 320 channels 5579 * that match the primary frequency else return only channel 5580 * that matches 320 band center. 5581 * 5582 * @pdev: Pointer to struct wlan_objmgr_pdev. 5583 * @freq: Input frequency in MHZ. 5584 * @ch_width: Input channel width, if a channel of the given width is not 5585 * found, reduce the channel width to the next lower mode and pass it to the 5586 * caller. 5587 * @band_center_320: Center of 320MHZ channel. 5588 * @chan_list: Pointer to reg_channel_list to be filled. 5589 * @update_bw: Flag to hold if bw is updated. 5590 * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based 5591 * channel list will be chosen. 5592 * @treat_nol_chan_as_disabled: Bool to treat NOL channels as disabled/enabled 5593 * 5594 * Return - None. 5595 */ 5596 static void 5597 reg_fill_channel_list_for_320_for_pwrmode( 5598 struct wlan_objmgr_pdev *pdev, 5599 qdf_freq_t freq, 5600 enum phy_ch_width *in_ch_width, 5601 qdf_freq_t band_center_320, 5602 struct reg_channel_list *chan_list, 5603 bool *update_bw, 5604 enum supported_6g_pwr_types in_6g_pwr_mode, 5605 bool treat_nol_chan_as_disabled) 5606 { 5607 uint8_t num_bonded_pairs, i, num_ch_params; 5608 enum channel_state chan_state; 5609 uint16_t array_size = QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq); 5610 uint16_t out_punc_bitmap; 5611 uint16_t max_reg_bw; 5612 enum channel_enum chan_enum; 5613 const struct bonded_channel_freq *bonded_ch_ptr[2] = {NULL, NULL}; 5614 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5615 5616 *update_bw = false; 5617 5618 chan_enum = reg_get_chan_enum_for_freq(freq); 5619 if (reg_is_chan_enum_invalid(chan_enum)) { 5620 reg_err("chan freq is not valid"); 5621 return; 5622 } 5623 5624 pdev_priv_obj = reg_get_pdev_obj(pdev); 5625 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5626 reg_err("reg pdev priv obj is NULL"); 5627 return; 5628 } 5629 5630 /* Maximum bandwidth of the channel supported by regulatory for 5631 * the given freq. 5632 */ 5633 if (reg_get_min_max_bw_reg_chan_list(pdev, chan_enum, in_6g_pwr_mode, 5634 NULL, &max_reg_bw)) 5635 return; 5636 5637 /* Regulatory does not support BW greater than 160. 5638 * Try finding a channel in a lower mode. 5639 */ 5640 if (max_reg_bw <= BW_160MHZ) { 5641 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5642 *update_bw = true; 5643 return; 5644 } 5645 5646 num_bonded_pairs = 5647 reg_get_320_bonded_chan_array(pdev, freq, band_center_320, 5648 bonded_chan_320mhz_list_freq, 5649 array_size, 5650 bonded_ch_ptr); 5651 5652 if (!num_bonded_pairs) { 5653 if (band_center_320) { 5654 reg_debug("No bonded pair for the given band_center\n"); 5655 chan_list->num_ch_params = 0; 5656 } else { 5657 /* Could not find a 320 MHZ bonded channel pair, 5658 * find a channel of lower BW. 5659 */ 5660 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5661 *update_bw = true; 5662 } 5663 return; 5664 } 5665 5666 for (i = 0, num_ch_params = 0 ; i < num_bonded_pairs; i++) { 5667 uint16_t in_punc_bitmap = 5668 chan_list->chan_param[i].input_punc_bitmap; 5669 5670 /* Chan_state to hold the channel state of bonding 5671 * pair of channels. 5672 */ 5673 chan_state = 5674 reg_get_320_bonded_channel_state_for_pwrmode(pdev, freq, 5675 bonded_ch_ptr[i], 5676 *in_ch_width, 5677 &out_punc_bitmap, 5678 in_6g_pwr_mode, 5679 treat_nol_chan_as_disabled, 5680 in_punc_bitmap); 5681 5682 if (reg_is_state_allowed(chan_state)) { 5683 struct ch_params *t_chan_param = 5684 &chan_list->chan_param[num_ch_params]; 5685 qdf_freq_t start_freq = bonded_ch_ptr[i]->start_freq; 5686 5687 t_chan_param->mhz_freq_seg1 = 5688 reg_get_band_cen_from_bandstart(BW_320_MHZ, 5689 start_freq); 5690 t_chan_param->center_freq_seg1 = 5691 reg_freq_to_chan(pdev, 5692 t_chan_param->mhz_freq_seg1); 5693 t_chan_param->ch_width = *in_ch_width; 5694 t_chan_param->reg_punc_bitmap = out_punc_bitmap; 5695 5696 reg_fill_chan320mhz_seg0_center(pdev, 5697 t_chan_param, 5698 freq); 5699 num_ch_params++; 5700 chan_list->num_ch_params = num_ch_params; 5701 } 5702 } 5703 5704 /* The bonded pairs could not create any channels, 5705 * lower the bandwidth to find a channel. 5706 */ 5707 if (!chan_list->num_ch_params) { 5708 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5709 *update_bw = true; 5710 } 5711 } 5712 #endif 5713 5714 /** 5715 * reg_fill_pre320mhz_channel() - Fill channel params for channel width 5716 * less than 320. 5717 * @pdev: Pointer to struct wlan_objmgr_pdev 5718 * @chan_list: Pointer to struct reg_channel_list 5719 * @ch_width: Channel width 5720 * @freq: Center frequency of the primary channel in MHz 5721 * @sec_ch_2g_freq: Secondary 2G channel frequency in MHZ 5722 * @treat_nol_chan_as_disabled: Bool to treat NOL channels as 5723 * disabled/enabled 5724 */ 5725 static void 5726 reg_fill_pre320mhz_channel(struct wlan_objmgr_pdev *pdev, 5727 struct reg_channel_list *chan_list, 5728 enum phy_ch_width ch_width, 5729 qdf_freq_t freq, 5730 qdf_freq_t sec_ch_2g_freq, 5731 bool treat_nol_chan_as_disabled) 5732 { 5733 chan_list->num_ch_params = 1; 5734 chan_list->chan_param[0].ch_width = ch_width; 5735 chan_list->chan_param[0].reg_punc_bitmap = NO_SCHANS_PUNC; 5736 reg_set_channel_params_for_freq(pdev, freq, sec_ch_2g_freq, 5737 &chan_list->chan_param[0], 5738 treat_nol_chan_as_disabled); 5739 } 5740 5741 #ifdef CONFIG_REG_6G_PWRMODE 5742 /** 5743 * reg_fill_pre320mhz_channel_for_pwrmode() - Fill channel params for channel 5744 * width less than 320. 5745 * @pdev: Pointer to struct wlan_objmgr_pdev 5746 * @chan_list: Pointer to struct reg_channel_list 5747 * @ch_width: Channel width 5748 * @freq: Center frequency of the primary channel in MHz 5749 * @sec_ch_2g_freq: Secondary 2G channel frequency in MHZ 5750 * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based 5751 * channel list will be chosen. 5752 * @treat_nol_chan_as_disabled: Bool to consider nol chan as enabled/disabled 5753 */ 5754 static void 5755 reg_fill_pre320mhz_channel_for_pwrmode( 5756 struct wlan_objmgr_pdev *pdev, 5757 struct reg_channel_list *chan_list, 5758 enum phy_ch_width ch_width, 5759 qdf_freq_t freq, 5760 qdf_freq_t sec_ch_2g_freq, 5761 enum supported_6g_pwr_types in_6g_pwr_mode, 5762 bool treat_nol_chan_as_disabled) 5763 { 5764 chan_list->num_ch_params = 1; 5765 chan_list->chan_param[0].ch_width = ch_width; 5766 chan_list->chan_param[0].reg_punc_bitmap = NO_SCHANS_PUNC; 5767 reg_set_channel_params_for_pwrmode(pdev, freq, sec_ch_2g_freq, 5768 &chan_list->chan_param[0], 5769 in_6g_pwr_mode, 5770 treat_nol_chan_as_disabled); 5771 } 5772 #endif 5773 5774 void 5775 reg_fill_channel_list(struct wlan_objmgr_pdev *pdev, 5776 qdf_freq_t freq, 5777 qdf_freq_t sec_ch_2g_freq, 5778 enum phy_ch_width in_ch_width, 5779 qdf_freq_t band_center_320, 5780 struct reg_channel_list *chan_list, 5781 bool treat_nol_chan_as_disabled) 5782 { 5783 bool update_bw; 5784 5785 if (!chan_list) { 5786 reg_err("channel params is NULL"); 5787 return; 5788 } 5789 5790 if (in_ch_width >= CH_WIDTH_MAX) 5791 in_ch_width = CH_WIDTH_320MHZ; 5792 5793 if (in_ch_width == CH_WIDTH_320MHZ) { 5794 update_bw = 0; 5795 reg_fill_channel_list_for_320(pdev, freq, &in_ch_width, 5796 band_center_320, chan_list, 5797 &update_bw, 5798 treat_nol_chan_as_disabled); 5799 if (!update_bw) 5800 return; 5801 } 5802 5803 /* A 320 channel is not available (or) user has not requested 5804 * for a 320MHZ channel, look for channels in lower modes, 5805 * reg_set_5g_channel_params_for_freq() finds for the 5806 * next available mode and fills ch_params. 5807 */ 5808 reg_fill_pre320mhz_channel(pdev, chan_list, in_ch_width, freq, 5809 sec_ch_2g_freq, 5810 treat_nol_chan_as_disabled); 5811 } 5812 5813 #ifdef CONFIG_REG_6G_PWRMODE 5814 void 5815 reg_fill_channel_list_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5816 qdf_freq_t freq, 5817 qdf_freq_t sec_ch_2g_freq, 5818 enum phy_ch_width in_ch_width, 5819 qdf_freq_t band_center_320, 5820 struct reg_channel_list *chan_list, 5821 enum supported_6g_pwr_types in_6g_pwr_mode, 5822 bool treat_nol_chan_as_disabled) 5823 { 5824 bool update_bw; 5825 5826 if (!chan_list) { 5827 reg_err("channel params is NULL"); 5828 return; 5829 } 5830 5831 if (in_ch_width >= CH_WIDTH_MAX) 5832 in_ch_width = CH_WIDTH_320MHZ; 5833 5834 if (in_ch_width == CH_WIDTH_320MHZ) { 5835 update_bw = 0; 5836 reg_fill_channel_list_for_320_for_pwrmode( 5837 pdev, freq, &in_ch_width, 5838 band_center_320, chan_list, 5839 &update_bw, in_6g_pwr_mode, 5840 treat_nol_chan_as_disabled); 5841 if (!update_bw) 5842 return; 5843 } 5844 5845 /* A 320 channel is not available (or) user has not requested 5846 * for a 320MHZ channel, look for channels in lower modes, 5847 * reg_set_5g_channel_params_for_freq() finds for the 5848 * next available mode and fills ch_params. 5849 */ 5850 reg_fill_pre320mhz_channel_for_pwrmode( 5851 pdev, chan_list, in_ch_width, freq, 5852 sec_ch_2g_freq, in_6g_pwr_mode, 5853 treat_nol_chan_as_disabled); 5854 } 5855 #endif 5856 #endif 5857 5858 enum channel_state 5859 reg_get_5g_bonded_channel_for_freq(struct wlan_objmgr_pdev *pdev, 5860 uint16_t freq, 5861 enum phy_ch_width ch_width, 5862 const struct bonded_channel_freq 5863 **bonded_chan_ptr_ptr) 5864 { 5865 if (ch_width == CH_WIDTH_20MHZ) 5866 return reg_get_channel_state_for_pwrmode(pdev, freq, 5867 REG_CURRENT_PWR_MODE); 5868 5869 if (reg_is_ch_width_320(ch_width)) { 5870 return reg_get_chan_state_for_320(pdev, freq, 0, 5871 ch_width, 5872 bonded_chan_ptr_ptr, 5873 REG_CURRENT_PWR_MODE, 5874 true, 5875 NO_SCHANS_PUNC); 5876 } else { 5877 *bonded_chan_ptr_ptr = reg_get_bonded_chan_entry(freq, 5878 ch_width, 0); 5879 if (!(*bonded_chan_ptr_ptr)) 5880 return CHANNEL_STATE_INVALID; 5881 5882 return reg_get_5g_bonded_chan_array_for_freq( 5883 pdev, freq, 5884 *bonded_chan_ptr_ptr); 5885 } 5886 } 5887 5888 #ifdef CONFIG_REG_6G_PWRMODE 5889 enum channel_state 5890 reg_get_5g_bonded_channel_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5891 uint16_t freq, 5892 enum phy_ch_width ch_width, 5893 const struct bonded_channel_freq 5894 **bonded_chan_ptr_ptr, 5895 enum supported_6g_pwr_types 5896 in_6g_pwr_mode, 5897 uint16_t input_punc_bitmap) 5898 { 5899 if (ch_width == CH_WIDTH_20MHZ) 5900 return reg_get_channel_state_for_pwrmode(pdev, freq, 5901 in_6g_pwr_mode); 5902 5903 if (reg_is_ch_width_320(ch_width)) 5904 return reg_get_chan_state_for_320(pdev, freq, 0, 5905 ch_width, 5906 bonded_chan_ptr_ptr, 5907 in_6g_pwr_mode, true, 5908 input_punc_bitmap); 5909 /* Fetch the bonded_chan_ptr for width greater than 20MHZ. */ 5910 *bonded_chan_ptr_ptr = reg_get_bonded_chan_entry(freq, ch_width, 0); 5911 5912 if (!(*bonded_chan_ptr_ptr)) { 5913 reg_debug_rl("bonded_chan_ptr_ptr is NULL"); 5914 return CHANNEL_STATE_INVALID; 5915 } 5916 5917 return reg_get_5g_bonded_chan_array_for_pwrmode(pdev, freq, 5918 *bonded_chan_ptr_ptr, 5919 in_6g_pwr_mode, 5920 input_punc_bitmap); 5921 } 5922 #endif 5923 5924 #ifdef CONFIG_REG_6G_PWRMODE 5925 /** 5926 * reg_set_5g_channel_params_for_pwrmode()- Set channel parameters like center 5927 * frequency for a bonded channel state. Also return the maximum bandwidth 5928 * supported by the channel. 5929 * @pdev: Pointer to pdev. 5930 * @freq: Channel center frequency. 5931 * ch_params: Pointer to ch_params. 5932 * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based 5933 * channel list will be chosen. 5934 * @treat_nol_chan_as_disabled: Bool to treat NOL channels as disabled/enabled 5935 * 5936 * Return: void 5937 */ 5938 static void reg_set_5g_channel_params_for_pwrmode( 5939 struct wlan_objmgr_pdev *pdev, 5940 uint16_t freq, 5941 struct ch_params *ch_params, 5942 enum supported_6g_pwr_types 5943 in_6g_pwr_type, 5944 bool treat_nol_chan_as_disabled) 5945 { 5946 /* 5947 * Set channel parameters like center frequency for a bonded channel 5948 * state. Also return the maximum bandwidth supported by the channel. 5949 */ 5950 5951 enum channel_state chan_state = CHANNEL_STATE_ENABLE; 5952 enum channel_state chan_state2 = CHANNEL_STATE_ENABLE; 5953 const struct bonded_channel_freq *bonded_chan_ptr = NULL; 5954 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5955 enum channel_enum chan_enum, sec_5g_chan_enum; 5956 uint16_t bw_80 = 0; 5957 uint16_t max_bw, sec_5g_freq_max_bw = 0; 5958 uint16_t in_punc_bitmap = reg_fetch_punc_bitmap(ch_params); 5959 5960 if (!ch_params) { 5961 reg_err("ch_params is NULL"); 5962 return; 5963 } 5964 5965 chan_enum = reg_get_chan_enum_for_freq(freq); 5966 if (reg_is_chan_enum_invalid(chan_enum)) { 5967 reg_err("chan freq is not valid"); 5968 return; 5969 } 5970 5971 pdev_priv_obj = reg_get_pdev_obj(pdev); 5972 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5973 reg_err("reg pdev priv obj is NULL"); 5974 return; 5975 } 5976 5977 if (ch_params->ch_width >= CH_WIDTH_MAX) { 5978 if (ch_params->mhz_freq_seg1 != 0) 5979 ch_params->ch_width = CH_WIDTH_80P80MHZ; 5980 else 5981 ch_params->ch_width = CH_WIDTH_160MHZ; 5982 } 5983 5984 if (reg_get_min_max_bw_reg_chan_list(pdev, chan_enum, in_6g_pwr_type, 5985 NULL, &max_bw)) 5986 return; 5987 5988 bw_80 = reg_get_bw_value(CH_WIDTH_80MHZ); 5989 5990 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 5991 sec_5g_chan_enum = 5992 reg_get_chan_enum_for_freq(ch_params->mhz_freq_seg1 - 5993 NEAREST_20MHZ_CHAN_FREQ_OFFSET); 5994 if (reg_is_chan_enum_invalid(sec_5g_chan_enum)) { 5995 reg_err("secondary channel freq is not valid"); 5996 return; 5997 } 5998 5999 if (reg_get_min_max_bw_reg_chan_list(pdev, sec_5g_chan_enum, 6000 in_6g_pwr_type, 6001 NULL, &sec_5g_freq_max_bw)) 6002 return; 6003 } 6004 6005 while (ch_params->ch_width != CH_WIDTH_INVALID) { 6006 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 6007 if ((max_bw < bw_80) || (sec_5g_freq_max_bw < bw_80)) 6008 goto update_bw; 6009 } else if (max_bw < reg_get_bw_value(ch_params->ch_width)) { 6010 goto update_bw; 6011 } 6012 6013 bonded_chan_ptr = NULL; 6014 chan_state = reg_get_5g_bonded_channel_for_pwrmode( 6015 pdev, freq, ch_params->ch_width, 6016 &bonded_chan_ptr, in_6g_pwr_type, 6017 in_punc_bitmap); 6018 chan_state = 6019 reg_get_ch_state_based_on_nol_flag(pdev, freq, 6020 ch_params, 6021 in_6g_pwr_type, 6022 treat_nol_chan_as_disabled); 6023 6024 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 6025 struct ch_params temp_ch_params = {0}; 6026 6027 temp_ch_params.ch_width = CH_WIDTH_80MHZ; 6028 /* Puncturing patter is not needed for 80+80 */ 6029 reg_set_create_punc_bitmap(&temp_ch_params, false); 6030 chan_state2 = 6031 reg_get_ch_state_based_on_nol_flag(pdev, 6032 ch_params->mhz_freq_seg1 - 6033 NEAREST_20MHZ_CHAN_FREQ_OFFSET, 6034 &temp_ch_params, in_6g_pwr_type, 6035 treat_nol_chan_as_disabled); 6036 chan_state = reg_combine_channel_states( 6037 chan_state, chan_state2); 6038 } 6039 6040 if ((chan_state != CHANNEL_STATE_ENABLE) && 6041 (chan_state != CHANNEL_STATE_DFS)) 6042 goto update_bw; 6043 if (ch_params->ch_width <= CH_WIDTH_20MHZ) { 6044 ch_params->sec_ch_offset = NO_SEC_CH; 6045 ch_params->mhz_freq_seg0 = freq; 6046 ch_params->center_freq_seg0 = 6047 reg_freq_to_chan(pdev, 6048 ch_params->mhz_freq_seg0); 6049 break; 6050 } else if (ch_params->ch_width >= CH_WIDTH_40MHZ) { 6051 const struct bonded_channel_freq *bonded_chan_ptr2; 6052 6053 bonded_chan_ptr2 = 6054 reg_get_bonded_chan_entry( 6055 freq, 6056 CH_WIDTH_40MHZ, 6057 0); 6058 6059 if (!bonded_chan_ptr || !bonded_chan_ptr2) 6060 goto update_bw; 6061 if (freq == bonded_chan_ptr2->start_freq) 6062 ch_params->sec_ch_offset = LOW_PRIMARY_CH; 6063 else 6064 ch_params->sec_ch_offset = HIGH_PRIMARY_CH; 6065 6066 ch_params->mhz_freq_seg0 = 6067 (bonded_chan_ptr->start_freq + 6068 bonded_chan_ptr->end_freq) / 2; 6069 ch_params->center_freq_seg0 = 6070 reg_freq_to_chan(pdev, 6071 ch_params->mhz_freq_seg0); 6072 break; 6073 } 6074 update_bw: 6075 ch_params->ch_width = 6076 get_next_lower_bandwidth(ch_params->ch_width); 6077 } 6078 6079 if (ch_params->ch_width == CH_WIDTH_160MHZ) { 6080 ch_params->mhz_freq_seg1 = ch_params->mhz_freq_seg0; 6081 ch_params->center_freq_seg1 = 6082 reg_freq_to_chan(pdev, 6083 ch_params->mhz_freq_seg1); 6084 6085 chan_state = reg_get_5g_bonded_channel_for_pwrmode( 6086 pdev, freq, CH_WIDTH_80MHZ, &bonded_chan_ptr, 6087 in_6g_pwr_type, 6088 in_punc_bitmap); 6089 if (bonded_chan_ptr) { 6090 ch_params->mhz_freq_seg0 = 6091 (bonded_chan_ptr->start_freq + 6092 bonded_chan_ptr->end_freq) / 2; 6093 ch_params->center_freq_seg0 = 6094 reg_freq_to_chan(pdev, 6095 ch_params->mhz_freq_seg0); 6096 } 6097 } 6098 6099 /* Overwrite mhz_freq_seg1 to 0 for non 160 and 80+80 width */ 6100 if (!(ch_params->ch_width == CH_WIDTH_160MHZ || 6101 ch_params->ch_width == CH_WIDTH_80P80MHZ)) { 6102 ch_params->mhz_freq_seg1 = 0; 6103 ch_params->center_freq_seg1 = 0; 6104 } 6105 } 6106 #endif 6107 6108 #ifdef CONFIG_REG_CLIENT 6109 static qdf_freq_t reg_get_sec_ch_2g_freq(struct wlan_objmgr_pdev *pdev, 6110 qdf_freq_t primary_freq) 6111 { 6112 qdf_freq_t sec_ch_2g_freq = 0; 6113 6114 if (primary_freq >= TWOG_CHAN_1_IN_MHZ && 6115 primary_freq <= TWOG_CHAN_5_IN_MHZ) 6116 sec_ch_2g_freq = primary_freq + HT40_SEC_OFFSET; 6117 else if (primary_freq >= TWOG_CHAN_6_IN_MHZ && 6118 primary_freq <= TWOG_CHAN_13_IN_MHZ) 6119 sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET; 6120 6121 return sec_ch_2g_freq; 6122 } 6123 #else 6124 static qdf_freq_t reg_get_sec_ch_2g_freq(struct wlan_objmgr_pdev *pdev, 6125 qdf_freq_t primary_freq) 6126 { 6127 qdf_freq_t sec_ch_2g_freq; 6128 6129 if (primary_freq < TWOG_CHAN_1_IN_MHZ || 6130 primary_freq > TWOG_CHAN_13_IN_MHZ) 6131 return 0; 6132 6133 sec_ch_2g_freq = primary_freq + HT40_SEC_OFFSET; 6134 6135 /* For 2G primary frequencies > 2452 (IEEE9), return HT40-. */ 6136 if (primary_freq > TWOG_CHAN_9_IN_MHZ) 6137 sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET; 6138 6139 /* 6140 * For 2G primary frequencies <= 2452 (IEEE9), return HT40+ if 6141 * the secondary is available, else return HT40-. 6142 */ 6143 else if (!reg_is_freq_present_in_cur_chan_list(pdev, sec_ch_2g_freq)) 6144 sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET; 6145 6146 return sec_ch_2g_freq; 6147 } 6148 #endif 6149 6150 void reg_set_2g_channel_params_for_freq(struct wlan_objmgr_pdev *pdev, 6151 uint16_t oper_freq, 6152 struct ch_params *ch_params, 6153 uint16_t sec_ch_2g_freq) 6154 { 6155 enum channel_state chan_state = CHANNEL_STATE_ENABLE; 6156 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6157 enum channel_enum chan_enum; 6158 uint16_t max_bw; 6159 6160 chan_enum = reg_get_chan_enum_for_freq(oper_freq); 6161 if (reg_is_chan_enum_invalid(chan_enum)) { 6162 reg_err("chan freq is not valid"); 6163 return; 6164 } 6165 6166 pdev_priv_obj = reg_get_pdev_obj(pdev); 6167 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6168 reg_err("reg pdev priv obj is NULL"); 6169 return; 6170 } 6171 6172 if (ch_params->ch_width >= CH_WIDTH_MAX) 6173 ch_params->ch_width = CH_WIDTH_40MHZ; 6174 if ((reg_get_bw_value(ch_params->ch_width) > 20) && !sec_ch_2g_freq) 6175 sec_ch_2g_freq = reg_get_sec_ch_2g_freq(pdev, oper_freq); 6176 6177 max_bw = pdev_priv_obj->cur_chan_list[chan_enum].max_bw; 6178 6179 while (ch_params->ch_width != CH_WIDTH_INVALID) { 6180 if (max_bw < reg_get_bw_value(ch_params->ch_width)) 6181 goto update_bw; 6182 6183 chan_state = 6184 reg_get_2g_bonded_channel_state_for_freq(pdev, oper_freq, 6185 sec_ch_2g_freq, 6186 ch_params->ch_width); 6187 if ((chan_state == CHANNEL_STATE_ENABLE) || 6188 (chan_state == CHANNEL_STATE_DFS)) { 6189 if (ch_params->ch_width == CH_WIDTH_40MHZ) { 6190 if (oper_freq < sec_ch_2g_freq) 6191 ch_params->sec_ch_offset = 6192 LOW_PRIMARY_CH; 6193 else 6194 ch_params->sec_ch_offset = 6195 HIGH_PRIMARY_CH; 6196 ch_params->mhz_freq_seg0 = 6197 (oper_freq + sec_ch_2g_freq) / 2; 6198 if (ch_params->mhz_freq_seg0 == 6199 TWOG_CHAN_14_IN_MHZ) 6200 ch_params->center_freq_seg0 = 14; 6201 else 6202 ch_params->center_freq_seg0 = 6203 (ch_params->mhz_freq_seg0 - 6204 TWOG_STARTING_FREQ) / 6205 FREQ_TO_CHAN_SCALE; 6206 } else { 6207 ch_params->sec_ch_offset = NO_SEC_CH; 6208 ch_params->mhz_freq_seg0 = oper_freq; 6209 if (ch_params->mhz_freq_seg0 == 6210 TWOG_CHAN_14_IN_MHZ) 6211 ch_params->center_freq_seg0 = 14; 6212 else 6213 ch_params->center_freq_seg0 = 6214 (ch_params->mhz_freq_seg0 - 6215 TWOG_STARTING_FREQ) / 6216 FREQ_TO_CHAN_SCALE; 6217 } 6218 break; 6219 } 6220 update_bw: 6221 ch_params->ch_width = 6222 get_next_lower_bandwidth(ch_params->ch_width); 6223 } 6224 /* Overwrite mhz_freq_seg1 and center_freq_seg1 to 0 for 2.4 Ghz */ 6225 ch_params->mhz_freq_seg1 = 0; 6226 ch_params->center_freq_seg1 = 0; 6227 } 6228 6229 #ifdef WLAN_FEATURE_11BE 6230 static void reg_copy_ch_params(struct ch_params *ch_params, 6231 struct reg_channel_list chan_list) 6232 { 6233 ch_params->center_freq_seg0 = chan_list.chan_param[0].center_freq_seg0; 6234 ch_params->center_freq_seg1 = chan_list.chan_param[0].center_freq_seg1; 6235 ch_params->mhz_freq_seg0 = chan_list.chan_param[0].mhz_freq_seg0; 6236 ch_params->mhz_freq_seg1 = chan_list.chan_param[0].mhz_freq_seg1; 6237 ch_params->ch_width = chan_list.chan_param[0].ch_width; 6238 ch_params->sec_ch_offset = chan_list.chan_param[0].sec_ch_offset; 6239 ch_params->reg_punc_bitmap = chan_list.chan_param[0].reg_punc_bitmap; 6240 } 6241 6242 void reg_set_channel_params_for_freq(struct wlan_objmgr_pdev *pdev, 6243 qdf_freq_t freq, 6244 qdf_freq_t sec_ch_2g_freq, 6245 struct ch_params *ch_params, 6246 bool treat_nol_chan_as_disabled) 6247 { 6248 if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) { 6249 if (reg_is_ch_width_320(ch_params->ch_width)) { 6250 struct reg_channel_list chan_list; 6251 6252 qdf_mem_zero(&chan_list, sizeof(chan_list)); 6253 /* For now sending center freq as 0 */ 6254 reg_fill_channel_list(pdev, freq, sec_ch_2g_freq, 6255 ch_params->ch_width, 0, 6256 &chan_list, 6257 treat_nol_chan_as_disabled); 6258 reg_copy_ch_params(ch_params, chan_list); 6259 } else { 6260 reg_set_5g_channel_params_for_pwrmode( 6261 pdev, freq, 6262 ch_params, 6263 REG_CURRENT_PWR_MODE, 6264 treat_nol_chan_as_disabled); 6265 } 6266 } else if (reg_is_24ghz_ch_freq(freq)) { 6267 reg_set_2g_channel_params_for_freq(pdev, freq, ch_params, 6268 sec_ch_2g_freq); 6269 } 6270 } 6271 #else /* WLAN_FEATURE_11BE */ 6272 void reg_set_channel_params_for_freq(struct wlan_objmgr_pdev *pdev, 6273 qdf_freq_t freq, 6274 qdf_freq_t sec_ch_2g_freq, 6275 struct ch_params *ch_params, 6276 bool treat_nol_chan_as_disabled) 6277 { 6278 if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) 6279 reg_set_5g_channel_params_for_pwrmode( 6280 pdev, freq, ch_params, 6281 REG_CURRENT_PWR_MODE, 6282 treat_nol_chan_as_disabled); 6283 else if (reg_is_24ghz_ch_freq(freq)) 6284 reg_set_2g_channel_params_for_freq(pdev, freq, ch_params, 6285 sec_ch_2g_freq); 6286 } 6287 #endif /* WLAN_FEATURE_11BE */ 6288 6289 #ifdef CONFIG_REG_6G_PWRMODE 6290 #ifdef WLAN_FEATURE_11BE 6291 void 6292 reg_set_channel_params_for_pwrmode(struct wlan_objmgr_pdev *pdev, 6293 qdf_freq_t freq, 6294 qdf_freq_t sec_ch_2g_freq, 6295 struct ch_params *ch_params, 6296 enum supported_6g_pwr_types in_6g_pwr_mode, 6297 bool is_treat_nol_dis) 6298 { 6299 if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) { 6300 if (reg_is_ch_width_320(ch_params->ch_width)) { 6301 struct reg_channel_list chan_list; 6302 uint8_t i; 6303 6304 qdf_mem_zero(&chan_list, sizeof(chan_list)); 6305 6306 for (i = 0; i < MAX_NUM_CHAN_PARAM; i++) { 6307 chan_list.chan_param[i].input_punc_bitmap = 6308 ch_params->input_punc_bitmap; 6309 } 6310 reg_fill_channel_list_for_pwrmode(pdev, freq, 6311 sec_ch_2g_freq, 6312 ch_params->ch_width, 6313 ch_params->mhz_freq_seg1, 6314 &chan_list, 6315 in_6g_pwr_mode, 6316 is_treat_nol_dis); 6317 reg_copy_ch_params(ch_params, chan_list); 6318 } else { 6319 reg_set_5g_channel_params_for_pwrmode(pdev, freq, 6320 ch_params, 6321 in_6g_pwr_mode, 6322 is_treat_nol_dis); 6323 } 6324 } else if (reg_is_24ghz_ch_freq(freq)) { 6325 reg_set_2g_channel_params_for_freq(pdev, freq, ch_params, 6326 sec_ch_2g_freq); 6327 } 6328 } 6329 #else 6330 void 6331 reg_set_channel_params_for_pwrmode(struct wlan_objmgr_pdev *pdev, 6332 qdf_freq_t freq, 6333 qdf_freq_t sec_ch_2g_freq, 6334 struct ch_params *ch_params, 6335 enum supported_6g_pwr_types in_6g_pwr_mode, 6336 bool is_treat_nol_dis) 6337 { 6338 if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) 6339 reg_set_5g_channel_params_for_pwrmode(pdev, freq, ch_params, 6340 in_6g_pwr_mode, 6341 is_treat_nol_dis); 6342 else if (reg_is_24ghz_ch_freq(freq)) 6343 reg_set_2g_channel_params_for_freq(pdev, freq, ch_params, 6344 sec_ch_2g_freq); 6345 } 6346 #endif 6347 #endif 6348 6349 uint8_t reg_get_channel_reg_power_for_freq(struct wlan_objmgr_pdev *pdev, 6350 qdf_freq_t freq) 6351 { 6352 enum channel_enum chan_enum; 6353 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6354 struct regulatory_channel *reg_channels; 6355 6356 chan_enum = reg_get_chan_enum_for_freq(freq); 6357 6358 if (reg_is_chan_enum_invalid(chan_enum)) { 6359 reg_err("channel is invalid"); 6360 return REG_INVALID_TXPOWER; 6361 } 6362 6363 pdev_priv_obj = reg_get_pdev_obj(pdev); 6364 6365 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6366 reg_err("reg pdev priv obj is NULL"); 6367 return REG_INVALID_TXPOWER; 6368 } 6369 6370 reg_channels = pdev_priv_obj->cur_chan_list; 6371 6372 return reg_channels[chan_enum].tx_power; 6373 } 6374 6375 bool reg_is_dfs_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 6376 { 6377 uint32_t chan_flags; 6378 6379 chan_flags = reg_get_channel_flags_for_freq(pdev, freq); 6380 6381 return chan_flags & REGULATORY_CHAN_RADAR; 6382 } 6383 6384 #ifdef CONFIG_REG_CLIENT 6385 bool reg_is_dfs_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev, 6386 qdf_freq_t freq) 6387 { 6388 uint32_t chan_flags; 6389 6390 chan_flags = reg_get_channel_flags_from_secondary_list_for_freq(pdev, 6391 freq); 6392 6393 return chan_flags & REGULATORY_CHAN_RADAR; 6394 } 6395 6396 /** 6397 * reg_get_psoc_mas_chan_list () - Get psoc master channel list 6398 * @pdev: pointer to pdev object 6399 * @psoc: pointer to psoc object 6400 * 6401 * Return: psoc master channel list 6402 */ 6403 static struct regulatory_channel *reg_get_psoc_mas_chan_list( 6404 struct wlan_objmgr_pdev *pdev, 6405 struct wlan_objmgr_psoc *psoc) 6406 { 6407 struct wlan_regulatory_psoc_priv_obj *soc_reg; 6408 uint8_t pdev_id; 6409 uint8_t phy_id; 6410 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 6411 6412 soc_reg = reg_get_psoc_obj(psoc); 6413 if (!soc_reg) { 6414 reg_err("reg psoc private obj is NULL"); 6415 return NULL; 6416 } 6417 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 6418 6419 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 6420 if (reg_tx_ops->get_phy_id_from_pdev_id) 6421 reg_tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id); 6422 else 6423 phy_id = pdev_id; 6424 6425 return soc_reg->mas_chan_params[phy_id].mas_chan_list; 6426 } 6427 #else 6428 static inline struct regulatory_channel *reg_get_psoc_mas_chan_list( 6429 struct wlan_objmgr_pdev *pdev, 6430 struct wlan_objmgr_psoc *psoc) 6431 { 6432 return NULL; 6433 } 6434 #endif 6435 6436 void reg_update_nol_ch_for_freq(struct wlan_objmgr_pdev *pdev, 6437 uint16_t *chan_freq_list, 6438 uint8_t num_chan, 6439 bool nol_chan) 6440 { 6441 enum channel_enum chan_enum; 6442 struct regulatory_channel *mas_chan_list = NULL, *psoc_mas_chan_list; 6443 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6444 struct wlan_objmgr_psoc *psoc; 6445 uint16_t i; 6446 6447 if (!num_chan || !chan_freq_list) { 6448 reg_err("chan_freq_list or num_ch is NULL"); 6449 return; 6450 } 6451 6452 psoc = wlan_pdev_get_psoc(pdev); 6453 6454 6455 psoc_mas_chan_list = reg_get_psoc_mas_chan_list(pdev, psoc); 6456 pdev_priv_obj = reg_get_pdev_obj(pdev); 6457 6458 if (pdev_priv_obj) 6459 mas_chan_list = pdev_priv_obj->mas_chan_list; 6460 6461 for (i = 0; i < num_chan; i++) { 6462 chan_enum = reg_get_chan_enum_for_freq(chan_freq_list[i]); 6463 if (reg_is_chan_enum_invalid(chan_enum)) { 6464 reg_err("Invalid freq in nol list, freq %d", 6465 chan_freq_list[i]); 6466 continue; 6467 } 6468 if (mas_chan_list) 6469 mas_chan_list[chan_enum].nol_chan = nol_chan; 6470 if (psoc_mas_chan_list) 6471 psoc_mas_chan_list[chan_enum].nol_chan = nol_chan; 6472 } 6473 6474 if (!pdev_priv_obj) { 6475 reg_err("reg pdev private obj is NULL"); 6476 return; 6477 } 6478 6479 reg_compute_pdev_current_chan_list(pdev_priv_obj); 6480 6481 reg_send_scheduler_msg_sb(psoc, pdev); 6482 } 6483 6484 void reg_update_nol_history_ch_for_freq(struct wlan_objmgr_pdev *pdev, 6485 uint16_t *chan_list, 6486 uint8_t num_chan, 6487 bool nol_history_chan) 6488 { 6489 enum channel_enum chan_enum; 6490 struct regulatory_channel *mas_chan_list; 6491 struct regulatory_channel *cur_chan_list; 6492 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6493 uint16_t i; 6494 6495 if (!num_chan || !chan_list) { 6496 reg_err("chan_list or num_ch is NULL"); 6497 return; 6498 } 6499 6500 pdev_priv_obj = wlan_objmgr_pdev_get_comp_private_obj( 6501 pdev, WLAN_UMAC_COMP_REGULATORY); 6502 6503 if (!pdev_priv_obj) { 6504 reg_err("reg psoc private obj is NULL"); 6505 return; 6506 } 6507 6508 mas_chan_list = pdev_priv_obj->mas_chan_list; 6509 cur_chan_list = pdev_priv_obj->cur_chan_list; 6510 6511 for (i = 0; i < num_chan; i++) { 6512 chan_enum = reg_get_chan_enum_for_freq(chan_list[i]); 6513 if (reg_is_chan_enum_invalid(chan_enum)) { 6514 reg_err("Invalid ch in nol list, chan %d", 6515 chan_list[i]); 6516 continue; 6517 } 6518 mas_chan_list[chan_enum].nol_history = nol_history_chan; 6519 cur_chan_list[chan_enum].nol_history = nol_history_chan; 6520 } 6521 } 6522 6523 qdf_freq_t reg_min_chan_freq(void) 6524 { 6525 return channel_map[MIN_24GHZ_CHANNEL].center_freq; 6526 } 6527 6528 qdf_freq_t reg_max_chan_freq(void) 6529 { 6530 return channel_map[NUM_CHANNELS - 1].center_freq; 6531 } 6532 6533 bool reg_is_same_band_freqs(qdf_freq_t freq1, qdf_freq_t freq2) 6534 { 6535 return (freq1 && freq2 && ((REG_IS_6GHZ_FREQ(freq1) && 6536 REG_IS_6GHZ_FREQ(freq2)) || 6537 (REG_IS_5GHZ_FREQ(freq1) && 6538 REG_IS_5GHZ_FREQ(freq2)) || 6539 (REG_IS_24GHZ_CH_FREQ(freq1) && 6540 REG_IS_24GHZ_CH_FREQ(freq2)))); 6541 } 6542 6543 enum reg_wifi_band reg_freq_to_band(qdf_freq_t freq) 6544 { 6545 if (REG_IS_24GHZ_CH_FREQ(freq)) 6546 return REG_BAND_2G; 6547 else if (REG_IS_5GHZ_FREQ(freq) || REG_IS_49GHZ_FREQ(freq)) 6548 return REG_BAND_5G; 6549 else if (REG_IS_6GHZ_FREQ(freq)) 6550 return REG_BAND_6G; 6551 return REG_BAND_UNKNOWN; 6552 } 6553 6554 #ifdef CONFIG_REG_6G_PWRMODE 6555 bool reg_is_disable_for_pwrmode(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq, 6556 enum supported_6g_pwr_types in_6g_pwr_mode) 6557 { 6558 enum channel_state ch_state; 6559 6560 ch_state = reg_get_channel_state_for_pwrmode(pdev, 6561 freq, 6562 in_6g_pwr_mode); 6563 6564 return (ch_state == CHANNEL_STATE_DISABLE) || 6565 (ch_state == CHANNEL_STATE_INVALID); 6566 } 6567 #endif 6568 6569 #ifdef CONFIG_REG_CLIENT 6570 bool reg_is_disable_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev, 6571 qdf_freq_t freq) 6572 { 6573 enum channel_state ch_state; 6574 6575 ch_state = reg_get_channel_state_from_secondary_list_for_freq(pdev, 6576 freq); 6577 6578 return ch_state == CHANNEL_STATE_DISABLE; 6579 } 6580 6581 bool reg_is_enable_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev, 6582 qdf_freq_t freq) 6583 { 6584 enum channel_state ch_state; 6585 6586 ch_state = reg_get_channel_state_from_secondary_list_for_freq(pdev, 6587 freq); 6588 6589 return ch_state == CHANNEL_STATE_ENABLE; 6590 } 6591 6592 #ifdef CONFIG_BAND_6GHZ 6593 static uint8_t reg_get_max_tx_power_from_super_chan_list( 6594 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 6595 enum supported_6g_pwr_types in_6g_pwr_type) 6596 { 6597 struct super_chan_info *sc_entry; 6598 enum supported_6g_pwr_types pwr_type; 6599 uint8_t i, max_tx_power = 0; 6600 6601 pwr_type = in_6g_pwr_type; 6602 for (i = 0; i < NUM_6GHZ_CHANNELS; i++) { 6603 sc_entry = &pdev_priv_obj->super_chan_list[i]; 6604 6605 if (in_6g_pwr_type == REG_BEST_PWR_MODE) 6606 pwr_type = sc_entry->best_power_mode; 6607 6608 if (reg_is_supp_pwr_mode_invalid(pwr_type)) 6609 continue; 6610 6611 if (!reg_is_chan_disabled(sc_entry->chan_flags_arr[pwr_type], 6612 sc_entry->state_arr[pwr_type]) && 6613 (sc_entry->reg_chan_pwr[pwr_type].tx_power > max_tx_power)) 6614 max_tx_power = 6615 sc_entry->reg_chan_pwr[pwr_type].tx_power; 6616 } 6617 return max_tx_power; 6618 } 6619 #else 6620 static inline uint8_t reg_get_max_tx_power_from_super_chan_list( 6621 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 6622 enum supported_6g_pwr_types in_6g_pwr_type) 6623 { 6624 return 0; 6625 } 6626 #endif 6627 6628 uint8_t reg_get_max_tx_power_for_pwr_mode( 6629 struct wlan_objmgr_pdev *pdev, 6630 enum supported_6g_pwr_types in_6g_pwr_type) 6631 { 6632 uint8_t i, max_tx_power = 0, max_super_chan_power = 0; 6633 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6634 uint16_t max_curr_num_chan; 6635 6636 if (!pdev) { 6637 reg_err_rl("invalid pdev"); 6638 return QDF_STATUS_E_INVAL; 6639 } 6640 6641 pdev_priv_obj = reg_get_pdev_obj(pdev); 6642 6643 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6644 reg_err_rl("reg pdev priv obj is NULL"); 6645 return QDF_STATUS_E_INVAL; 6646 } 6647 6648 if (in_6g_pwr_type == REG_CURRENT_PWR_MODE) 6649 max_curr_num_chan = NUM_CHANNELS; 6650 else 6651 max_curr_num_chan = MAX_5GHZ_CHANNEL; 6652 6653 for (i = 0; i < max_curr_num_chan; i++) { 6654 if (!reg_is_chan_disabled( 6655 pdev_priv_obj->cur_chan_list[i].chan_flags, 6656 pdev_priv_obj->cur_chan_list[i].state) && 6657 (pdev_priv_obj->cur_chan_list[i].tx_power > max_tx_power)) 6658 max_tx_power = 6659 pdev_priv_obj->cur_chan_list[i].tx_power; 6660 } 6661 6662 if (in_6g_pwr_type == REG_CURRENT_PWR_MODE) 6663 goto return_max_tx_power; 6664 6665 max_super_chan_power = reg_get_max_tx_power_from_super_chan_list( 6666 pdev_priv_obj, 6667 in_6g_pwr_type); 6668 6669 if (max_super_chan_power > max_tx_power) 6670 max_tx_power = max_super_chan_power; 6671 6672 return_max_tx_power: 6673 6674 if (!max_tx_power) 6675 reg_err_rl("max_tx_power is zero"); 6676 6677 return max_tx_power; 6678 } 6679 #endif 6680 6681 bool reg_is_passive_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 6682 { 6683 uint32_t chan_flags; 6684 6685 chan_flags = reg_get_channel_flags_for_freq(pdev, freq); 6686 6687 return chan_flags & REGULATORY_CHAN_NO_IR; 6688 } 6689 #endif /* CONFIG_CHAN_FREQ_API */ 6690 6691 uint8_t reg_get_max_tx_power(struct wlan_objmgr_pdev *pdev) 6692 { 6693 struct regulatory_channel *cur_chan_list; 6694 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6695 uint8_t i, max_tx_power = 0; 6696 6697 pdev_priv_obj = reg_get_pdev_obj(pdev); 6698 6699 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6700 reg_err("reg pdev private obj is NULL"); 6701 return QDF_STATUS_E_FAILURE; 6702 } 6703 6704 cur_chan_list = pdev_priv_obj->cur_chan_list; 6705 6706 for (i = 0; i < NUM_CHANNELS; i++) { 6707 if (cur_chan_list[i].state != CHANNEL_STATE_DISABLE && 6708 cur_chan_list[i].chan_flags != REGULATORY_CHAN_DISABLED) { 6709 if (cur_chan_list[i].tx_power > max_tx_power) 6710 max_tx_power = cur_chan_list[i].tx_power; 6711 } 6712 } 6713 6714 if (!max_tx_power) 6715 reg_err_rl("max_tx_power is zero"); 6716 6717 return max_tx_power; 6718 } 6719 6720 QDF_STATUS reg_set_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc) 6721 { 6722 struct wlan_regulatory_psoc_priv_obj *psoc_reg; 6723 6724 psoc_reg = reg_get_psoc_obj(psoc); 6725 if (!IS_VALID_PSOC_REG_OBJ(psoc_reg)) { 6726 reg_err("psoc reg component is NULL"); 6727 return QDF_STATUS_E_INVAL; 6728 } 6729 6730 psoc_reg->ignore_fw_reg_offload_ind = true; 6731 return QDF_STATUS_SUCCESS; 6732 } 6733 6734 bool reg_get_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc) 6735 { 6736 struct wlan_regulatory_psoc_priv_obj *psoc_reg; 6737 6738 psoc_reg = reg_get_psoc_obj(psoc); 6739 if (!IS_VALID_PSOC_REG_OBJ(psoc_reg)) 6740 return false; 6741 6742 return psoc_reg->ignore_fw_reg_offload_ind; 6743 } 6744 6745 QDF_STATUS reg_set_6ghz_supported(struct wlan_objmgr_psoc *psoc, bool val) 6746 { 6747 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6748 6749 psoc_priv_obj = reg_get_psoc_obj(psoc); 6750 6751 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6752 reg_err("psoc reg component is NULL"); 6753 return QDF_STATUS_E_FAILURE; 6754 } 6755 6756 psoc_priv_obj->six_ghz_supported = val; 6757 6758 return QDF_STATUS_SUCCESS; 6759 } 6760 6761 QDF_STATUS 6762 reg_set_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc, bool val) 6763 { 6764 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6765 6766 psoc_priv_obj = reg_get_psoc_obj(psoc); 6767 6768 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6769 reg_err("psoc reg component is NULL"); 6770 return QDF_STATUS_E_FAILURE; 6771 } 6772 6773 psoc_priv_obj->five_dot_nine_ghz_supported = val; 6774 6775 return QDF_STATUS_SUCCESS; 6776 } 6777 6778 #ifdef CONFIG_REG_CLIENT 6779 bool reg_is_6ghz_supported(struct wlan_objmgr_psoc *psoc) 6780 { 6781 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6782 6783 psoc_priv_obj = reg_get_psoc_obj(psoc); 6784 6785 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6786 reg_err("psoc reg component is NULL"); 6787 return false; 6788 } 6789 6790 return psoc_priv_obj->six_ghz_supported; 6791 } 6792 #endif 6793 6794 bool reg_is_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc) 6795 { 6796 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6797 6798 psoc_priv_obj = reg_get_psoc_obj(psoc); 6799 6800 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6801 reg_err("psoc reg component is NULL"); 6802 return false; 6803 } 6804 6805 return psoc_priv_obj->five_dot_nine_ghz_supported; 6806 } 6807 6808 bool reg_is_fcc_regdmn(struct wlan_objmgr_pdev *pdev) 6809 { 6810 struct cur_regdmn_info cur_reg_dmn; 6811 QDF_STATUS status; 6812 6813 status = reg_get_curr_regdomain(pdev, &cur_reg_dmn); 6814 if (status != QDF_STATUS_SUCCESS) { 6815 reg_debug_rl("Failed to get reg domain"); 6816 return false; 6817 } 6818 6819 return reg_fcc_regdmn(cur_reg_dmn.dmn_id_5g); 6820 } 6821 6822 bool reg_is_5dot9_ghz_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 6823 { 6824 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6825 6826 pdev_priv_obj = reg_get_pdev_obj(pdev); 6827 6828 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6829 reg_err("reg pdev priv obj is NULL"); 6830 return false; 6831 } 6832 6833 return (freq >= channel_map_us[MIN_5DOT9_CHANNEL].center_freq && 6834 freq <= channel_map_us[MAX_5DOT9_CHANNEL].center_freq); 6835 } 6836 6837 bool reg_is_5dot9_ghz_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev) 6838 { 6839 struct wlan_objmgr_psoc *psoc; 6840 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6841 6842 if (!pdev) { 6843 reg_alert("pdev is NULL"); 6844 return true; 6845 } 6846 psoc = wlan_pdev_get_psoc(pdev); 6847 6848 psoc_priv_obj = reg_get_psoc_obj(psoc); 6849 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6850 reg_alert("psoc reg component is NULL"); 6851 return true; 6852 } 6853 6854 return psoc_priv_obj->enable_5dot9_ghz_chan_in_master_mode; 6855 } 6856 6857 #ifdef DISABLE_UNII_SHARED_BANDS 6858 QDF_STATUS 6859 reg_get_unii_5g_bitmap(struct wlan_objmgr_pdev *pdev, uint8_t *bitmap) 6860 { 6861 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6862 6863 pdev_priv_obj = reg_get_pdev_obj(pdev); 6864 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6865 reg_err_rl("pdev reg component is NULL"); 6866 return QDF_STATUS_E_FAILURE; 6867 } 6868 *bitmap = pdev_priv_obj->unii_5g_bitmap; 6869 6870 return QDF_STATUS_SUCCESS; 6871 } 6872 #endif 6873 6874 #ifdef WLAN_FEATURE_11BE 6875 bool reg_is_phymode_unallowed(enum reg_phymode phy_in, uint32_t phymode_bitmap) 6876 { 6877 if (!phymode_bitmap) 6878 return false; 6879 6880 if (phy_in == REG_PHYMODE_11BE) 6881 return phymode_bitmap & REGULATORY_PHYMODE_NO11BE; 6882 else if (phy_in == REG_PHYMODE_11AX) 6883 return phymode_bitmap & REGULATORY_PHYMODE_NO11AX; 6884 else if (phy_in == REG_PHYMODE_11AC) 6885 return phymode_bitmap & REGULATORY_PHYMODE_NO11AC; 6886 else if (phy_in == REG_PHYMODE_11N) 6887 return phymode_bitmap & REGULATORY_CHAN_NO11N; 6888 else if (phy_in == REG_PHYMODE_11G) 6889 return phymode_bitmap & REGULATORY_PHYMODE_NO11G; 6890 else if (phy_in == REG_PHYMODE_11A) 6891 return phymode_bitmap & REGULATORY_PHYMODE_NO11A; 6892 else if (phy_in == REG_PHYMODE_11B) 6893 return phymode_bitmap & REGULATORY_PHYMODE_NO11B; 6894 else 6895 return true; 6896 } 6897 #else 6898 bool reg_is_phymode_unallowed(enum reg_phymode phy_in, uint32_t phymode_bitmap) 6899 { 6900 if (!phymode_bitmap) 6901 return false; 6902 6903 if (phy_in == REG_PHYMODE_11AX) 6904 return phymode_bitmap & REGULATORY_PHYMODE_NO11AX; 6905 else if (phy_in == REG_PHYMODE_11AC) 6906 return phymode_bitmap & REGULATORY_PHYMODE_NO11AC; 6907 else if (phy_in == REG_PHYMODE_11N) 6908 return phymode_bitmap & REGULATORY_CHAN_NO11N; 6909 else if (phy_in == REG_PHYMODE_11G) 6910 return phymode_bitmap & REGULATORY_PHYMODE_NO11G; 6911 else if (phy_in == REG_PHYMODE_11A) 6912 return phymode_bitmap & REGULATORY_PHYMODE_NO11A; 6913 else if (phy_in == REG_PHYMODE_11B) 6914 return phymode_bitmap & REGULATORY_PHYMODE_NO11B; 6915 else 6916 return true; 6917 } 6918 #endif 6919 6920 #ifdef CHECK_REG_PHYMODE 6921 enum reg_phymode reg_get_max_phymode(struct wlan_objmgr_pdev *pdev, 6922 enum reg_phymode phy_in, 6923 qdf_freq_t freq) 6924 { 6925 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6926 uint32_t phymode_bitmap; 6927 enum reg_phymode current_phymode = phy_in; 6928 6929 pdev_priv_obj = reg_get_pdev_obj(pdev); 6930 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6931 reg_err("pdev reg component is NULL"); 6932 return REG_PHYMODE_INVALID; 6933 } 6934 6935 phymode_bitmap = pdev_priv_obj->phybitmap; 6936 6937 while (1) { 6938 if (reg_is_phymode_unallowed(current_phymode, phymode_bitmap)) { 6939 if (current_phymode == REG_PHYMODE_11N) { 6940 if (REG_IS_24GHZ_CH_FREQ(freq)) 6941 current_phymode = REG_PHYMODE_11G; 6942 else 6943 current_phymode = REG_PHYMODE_11A; 6944 } else if (current_phymode == REG_PHYMODE_11A || 6945 current_phymode == REG_PHYMODE_11B) { 6946 reg_err("Couldn't find a suitable phymode"); 6947 return REG_PHYMODE_INVALID; 6948 } else if (current_phymode > REG_PHYMODE_MAX) { 6949 reg_err("Unknown phymode"); 6950 return REG_PHYMODE_INVALID; 6951 } else { 6952 current_phymode--; 6953 } 6954 } else { 6955 return current_phymode; 6956 } 6957 } 6958 } 6959 #endif /* CHECK_REG_PHYMODE */ 6960 6961 #ifdef CONFIG_REG_CLIENT 6962 enum band_info reg_band_bitmap_to_band_info(uint32_t band_bitmap) 6963 { 6964 if ((band_bitmap & BIT(REG_BAND_2G)) && 6965 (band_bitmap & BIT(REG_BAND_5G)) && 6966 (band_bitmap & BIT(REG_BAND_6G))) 6967 return BAND_ALL; 6968 else if ((band_bitmap & BIT(REG_BAND_5G)) && 6969 (band_bitmap & BIT(REG_BAND_6G))) 6970 return BAND_5G; 6971 else if ((band_bitmap & BIT(REG_BAND_2G)) && 6972 (band_bitmap & BIT(REG_BAND_6G))) 6973 return BAND_2G; 6974 else if ((band_bitmap & BIT(REG_BAND_2G)) && 6975 (band_bitmap & BIT(REG_BAND_5G))) 6976 return BAND_ALL; 6977 else if (band_bitmap & BIT(REG_BAND_2G)) 6978 return BAND_2G; 6979 else if (band_bitmap & BIT(REG_BAND_5G)) 6980 return BAND_5G; 6981 else if (band_bitmap & BIT(REG_BAND_6G)) 6982 return BAND_2G; 6983 else 6984 return BAND_UNKNOWN; 6985 } 6986 6987 QDF_STATUS 6988 reg_update_tx_power_on_ctry_change(struct wlan_objmgr_pdev *pdev, 6989 uint8_t vdev_id) 6990 { 6991 struct wlan_objmgr_psoc *psoc; 6992 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6993 reg_ctry_change_callback callback = NULL; 6994 6995 psoc = wlan_pdev_get_psoc(pdev); 6996 psoc_priv_obj = reg_get_psoc_obj(psoc); 6997 if (!psoc_priv_obj) { 6998 reg_err("reg psoc private obj is NULL"); 6999 return QDF_STATUS_E_FAILURE; 7000 } 7001 7002 qdf_spin_lock_bh(&psoc_priv_obj->cbk_list_lock); 7003 if (psoc_priv_obj->cc_cbk.cbk) 7004 callback = psoc_priv_obj->cc_cbk.cbk; 7005 qdf_spin_unlock_bh(&psoc_priv_obj->cbk_list_lock); 7006 if (callback) 7007 callback(vdev_id); 7008 7009 return QDF_STATUS_SUCCESS; 7010 } 7011 7012 QDF_STATUS 7013 reg_add_indoor_concurrency(struct wlan_objmgr_pdev *pdev, uint8_t vdev_id, 7014 uint32_t freq, enum phy_ch_width width) 7015 { 7016 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7017 struct indoor_concurrency_list *list; 7018 const struct bonded_channel_freq *range = NULL; 7019 uint8_t i = 0; 7020 7021 pdev_priv_obj = reg_get_pdev_obj(pdev); 7022 7023 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7024 reg_err("pdev reg component is NULL"); 7025 return QDF_STATUS_E_FAILURE; 7026 } 7027 7028 if (width > CH_WIDTH_20MHZ) 7029 range = wlan_reg_get_bonded_chan_entry(freq, width, 0); 7030 7031 list = &pdev_priv_obj->indoor_list[0]; 7032 for (i = 0; i < MAX_INDOOR_LIST_SIZE; i++, list++) { 7033 if (list->freq == 0 && list->vdev_id == INVALID_VDEV_ID) { 7034 list->freq = freq; 7035 list->vdev_id = vdev_id; 7036 list->chan_range = range; 7037 reg_debug("Added freq %d vdev %d width %d at idx %d", 7038 freq, vdev_id, width, i); 7039 return QDF_STATUS_SUCCESS; 7040 } 7041 } 7042 reg_err("Unable to add indoor concurrency for vdev %d freq %d width %d", 7043 vdev_id, freq, width); 7044 return QDF_STATUS_E_FAILURE; 7045 } 7046 7047 QDF_STATUS 7048 reg_remove_indoor_concurrency(struct wlan_objmgr_pdev *pdev, uint8_t vdev_id, 7049 uint32_t freq) 7050 { 7051 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7052 struct indoor_concurrency_list *list; 7053 uint8_t i = 0; 7054 7055 pdev_priv_obj = reg_get_pdev_obj(pdev); 7056 7057 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7058 reg_err("pdev reg component is NULL"); 7059 return QDF_STATUS_E_FAILURE; 7060 } 7061 7062 list = &pdev_priv_obj->indoor_list[0]; 7063 for (i = 0; i < MAX_INDOOR_LIST_SIZE; i++, list++) { 7064 if (list->freq == freq || 7065 (vdev_id != INVALID_VDEV_ID && list->vdev_id == vdev_id)) { 7066 reg_debug("Removed freq %d from idx %d", list->freq, i); 7067 list->freq = 0; 7068 list->vdev_id = INVALID_VDEV_ID; 7069 list->chan_range = NULL; 7070 return QDF_STATUS_SUCCESS; 7071 } 7072 continue; 7073 } 7074 7075 return QDF_STATUS_E_FAILURE; 7076 } 7077 7078 void 7079 reg_init_indoor_channel_list(struct wlan_objmgr_pdev *pdev) 7080 { 7081 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7082 struct indoor_concurrency_list *list; 7083 uint8_t i; 7084 7085 pdev_priv_obj = reg_get_pdev_obj(pdev); 7086 7087 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7088 reg_err("reg pdev priv obj is NULL"); 7089 return; 7090 } 7091 7092 list = pdev_priv_obj->indoor_list; 7093 for (i = 0; i < MAX_INDOOR_LIST_SIZE; i++, list++) { 7094 list->freq = 0; 7095 list->vdev_id = INVALID_VDEV_ID; 7096 list->chan_range = NULL; 7097 } 7098 } 7099 7100 QDF_STATUS 7101 reg_compute_indoor_list_on_cc_change(struct wlan_objmgr_psoc *psoc, 7102 struct wlan_objmgr_pdev *pdev) 7103 { 7104 struct wlan_objmgr_vdev *vdev; 7105 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7106 struct wlan_channel *des_chan; 7107 enum channel_enum chan_enum; 7108 uint8_t vdev_id; 7109 7110 pdev_priv_obj = reg_get_pdev_obj(pdev); 7111 7112 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7113 reg_err("reg pdev priv obj is NULL"); 7114 return QDF_STATUS_E_FAILURE; 7115 } 7116 7117 if (pdev_priv_obj->indoor_chan_enabled || 7118 !pdev_priv_obj->sta_sap_scc_on_indoor_channel) 7119 return QDF_STATUS_SUCCESS; 7120 7121 /* Iterate through VDEV list */ 7122 for (vdev_id = 0; vdev_id < WLAN_UMAC_PSOC_MAX_VDEVS; vdev_id++) { 7123 vdev = 7124 wlan_objmgr_get_vdev_by_id_from_psoc(psoc, vdev_id, 7125 WLAN_REGULATORY_SB_ID); 7126 if (!vdev) 7127 continue; 7128 7129 if (vdev->vdev_mlme.vdev_opmode != QDF_STA_MODE && 7130 vdev->vdev_mlme.vdev_opmode != QDF_P2P_CLIENT_MODE) 7131 goto next; 7132 7133 des_chan = vdev->vdev_mlme.des_chan; 7134 if (!des_chan) 7135 goto next; 7136 7137 if (!reg_is_5ghz_ch_freq(des_chan->ch_freq)) 7138 goto next; 7139 7140 chan_enum = reg_get_chan_enum_for_freq(des_chan->ch_freq); 7141 if (reg_is_chan_enum_invalid(chan_enum)) { 7142 reg_err_rl("Invalid chan enum %d", chan_enum); 7143 goto next; 7144 } 7145 7146 if (pdev_priv_obj->mas_chan_list[chan_enum].state != 7147 CHANNEL_STATE_DISABLE && 7148 pdev_priv_obj->mas_chan_list[chan_enum].chan_flags & 7149 REGULATORY_CHAN_INDOOR_ONLY) 7150 reg_add_indoor_concurrency(pdev, vdev_id, 7151 des_chan->ch_freq, 7152 des_chan->ch_width); 7153 7154 next: 7155 wlan_objmgr_vdev_release_ref(vdev, WLAN_REGULATORY_SB_ID); 7156 } 7157 7158 return QDF_STATUS_SUCCESS; 7159 } 7160 #endif 7161 7162 #if defined(CONFIG_BAND_6GHZ) 7163 QDF_STATUS 7164 reg_set_cur_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev, 7165 enum reg_6g_ap_type reg_cur_6g_ap_pwr_type) 7166 { 7167 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7168 7169 pdev_priv_obj = reg_get_pdev_obj(pdev); 7170 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7171 reg_err("pdev reg component is NULL"); 7172 return QDF_STATUS_E_FAILURE; 7173 } 7174 7175 if (reg_cur_6g_ap_pwr_type > REG_MAX_SUPP_AP_TYPE) { 7176 reg_err("Unsupported 6G AP power type"); 7177 return QDF_STATUS_E_FAILURE; 7178 } 7179 /* should we validate the input reg_cur_6g_ap_type? */ 7180 pdev_priv_obj->reg_cur_6g_ap_pwr_type = reg_cur_6g_ap_pwr_type; 7181 return QDF_STATUS_SUCCESS; 7182 } 7183 7184 QDF_STATUS 7185 reg_get_cur_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev, 7186 enum reg_6g_ap_type *reg_cur_6g_ap_pwr_type) 7187 { 7188 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7189 7190 pdev_priv_obj = reg_get_pdev_obj(pdev); 7191 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7192 reg_err("pdev reg component is NULL"); 7193 return QDF_STATUS_E_FAILURE; 7194 } 7195 7196 if (pdev_priv_obj->reg_cur_6g_ap_pwr_type >= REG_CURRENT_MAX_AP_TYPE) 7197 return QDF_STATUS_E_FAILURE; 7198 7199 *reg_cur_6g_ap_pwr_type = pdev_priv_obj->reg_cur_6g_ap_pwr_type; 7200 7201 return QDF_STATUS_SUCCESS; 7202 } 7203 7204 /** 7205 * get_reg_rules_for_pdev() - Get the pointer to the reg rules for the pdev 7206 * @pdev: Pointer to pdev 7207 * 7208 * Return: Pointer to Standard Power regulatory rules 7209 */ 7210 static struct reg_rule_info * 7211 reg_get_reg_rules_for_pdev(struct wlan_objmgr_pdev *pdev) 7212 { 7213 struct wlan_objmgr_psoc *psoc; 7214 struct wlan_regulatory_psoc_priv_obj *psoc_reg_priv; 7215 uint8_t phy_id; 7216 struct reg_rule_info *psoc_reg_rules; 7217 7218 psoc = wlan_pdev_get_psoc(pdev); 7219 psoc_reg_priv = reg_get_psoc_obj(psoc); 7220 7221 if (!psoc_reg_priv) { 7222 reg_debug("Regulatory psoc private object is NULL"); 7223 return NULL; 7224 } 7225 7226 phy_id = wlan_objmgr_pdev_get_pdev_id(pdev); 7227 psoc_reg_rules = &psoc_reg_priv->mas_chan_params[phy_id].reg_rules; 7228 7229 return psoc_reg_rules; 7230 } 7231 7232 uint8_t 7233 reg_get_num_rules_of_ap_pwr_type(struct wlan_objmgr_pdev *pdev, 7234 enum reg_6g_ap_type ap_pwr_type) 7235 { 7236 struct reg_rule_info *psoc_reg_rules = reg_get_reg_rules_for_pdev(pdev); 7237 7238 if (!psoc_reg_rules) { 7239 reg_debug("No psoc_reg_rules"); 7240 return 0; 7241 } 7242 7243 if (ap_pwr_type > REG_MAX_SUPP_AP_TYPE) { 7244 reg_err("Unsupported 6G AP power type"); 7245 return 0; 7246 } 7247 7248 return psoc_reg_rules->num_of_6g_ap_reg_rules[ap_pwr_type]; 7249 } 7250 7251 #ifdef CONFIG_AFC_SUPPORT 7252 /** 7253 * reg_is_empty_range() - If both left, right frquency edges in the input range 7254 * are zero then the range is empty, else not. 7255 * @in_range: Pointer to input range 7256 * 7257 * Return: True if the range is empty, else false 7258 */ 7259 static bool reg_is_empty_range(struct freq_range *in_range) 7260 { 7261 return !in_range->left && !in_range->right; 7262 } 7263 7264 struct freq_range 7265 reg_init_freq_range(qdf_freq_t left, qdf_freq_t right) 7266 { 7267 struct freq_range out_range; 7268 7269 out_range.left = left; 7270 out_range.right = right; 7271 7272 return out_range; 7273 } 7274 7275 /** 7276 * reg_assign_vars_with_range_vals() - Assign input variables with the values of 7277 * the range variable values 7278 * @in_range: Pointer to input range object 7279 * @left: Pointer to the first variable to get the value of left frequency edge 7280 * @right: Pointer to the second variable to get the value of right frequency 7281 * edge 7282 * 7283 * Return: void 7284 */ 7285 static void 7286 reg_assign_vars_with_range_vals(struct freq_range *in_range, 7287 qdf_freq_t *left, 7288 qdf_freq_t *right) 7289 { 7290 *left = in_range->left; 7291 *right = in_range->right; 7292 } 7293 7294 /** 7295 * reg_intersect_ranges() - Intersect two ranges and return the intesected range 7296 * @first: Pointer to first input range 7297 * @second: Pointer to second input range 7298 * 7299 * Return: Intersected output range 7300 */ 7301 static struct freq_range 7302 reg_intersect_ranges(struct freq_range *first_range, 7303 struct freq_range *second_range) 7304 { 7305 struct freq_range out_range; 7306 qdf_freq_t l_freq; 7307 qdf_freq_t r_freq; 7308 7309 /* validate if the ranges are proper */ 7310 7311 l_freq = QDF_MAX(first_range->left, second_range->left); 7312 r_freq = QDF_MIN(first_range->right, second_range->right); 7313 7314 if (l_freq > r_freq) { 7315 l_freq = 0; 7316 l_freq = 0; 7317 7318 reg_debug("Ranges do not overlap first= [%u, %u], second = [%u, %u]", 7319 first_range->left, 7320 first_range->right, 7321 second_range->left, 7322 second_range->right); 7323 } 7324 7325 out_range.left = l_freq; 7326 out_range.right = r_freq; 7327 7328 return out_range; 7329 } 7330 7331 /** 7332 * reg_act_sp_rule_cb - A function pointer type that calculate something 7333 * from the input frequency range 7334 * @rule_fr: Pointer to frequency range 7335 * @arg: Pointer to generic argument (a.k.a. context) 7336 * 7337 * Return: Void 7338 */ 7339 typedef void (*reg_act_sp_rule_cb)(struct freq_range *rule_fr, 7340 void *arg); 7341 7342 /** 7343 * reg_iterate_sp_rules() - Iterate through the Standard Power reg rules, for 7344 * every reg rule call the call back function to take some action or calculate 7345 * something 7346 * @pdev: Pointer to pdev 7347 * @pdev_priv_obj: Pointer to pdev private object 7348 * @action_on_sp_rule: A function pointer to take some action or calculate 7349 * something for every sp rule 7350 * @arg: Pointer to opque object (argument/context) 7351 * 7352 * Return: Void 7353 */ 7354 static void reg_iterate_sp_rules(struct wlan_objmgr_pdev *pdev, 7355 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 7356 reg_act_sp_rule_cb sp_rule_action, 7357 void *arg) 7358 { 7359 struct cur_reg_rule *p_sp_reg_rule; 7360 struct reg_rule_info *psoc_reg_rules; 7361 uint8_t n_6g_sp_ap_reg_rules; 7362 qdf_freq_t low_5g; 7363 qdf_freq_t high_5g; 7364 uint8_t i; 7365 struct freq_range chip_range; 7366 7367 psoc_reg_rules = reg_get_reg_rules_for_pdev(pdev); 7368 7369 if (!psoc_reg_rules) { 7370 reg_debug("psoc reg rule pointer is NULL"); 7371 return; 7372 } 7373 7374 n_6g_sp_ap_reg_rules = psoc_reg_rules->num_of_6g_ap_reg_rules[REG_STANDARD_POWER_AP]; 7375 p_sp_reg_rule = psoc_reg_rules->reg_rules_6g_ap[REG_STANDARD_POWER_AP]; 7376 7377 low_5g = pdev_priv_obj->range_5g_low; 7378 high_5g = pdev_priv_obj->range_5g_high; 7379 7380 chip_range = reg_init_freq_range(low_5g, high_5g); 7381 7382 reg_debug("chip_range = [%u, %u]", low_5g, high_5g); 7383 reg_debug("Num_6g_rules = %u", n_6g_sp_ap_reg_rules); 7384 7385 for (i = 0; i < n_6g_sp_ap_reg_rules; i++) { 7386 struct freq_range sp_range; 7387 struct freq_range out_range; 7388 7389 sp_range = reg_init_freq_range(p_sp_reg_rule->start_freq, 7390 p_sp_reg_rule->end_freq); 7391 reg_debug("Rule:[%u, %u]", 7392 p_sp_reg_rule->start_freq, 7393 p_sp_reg_rule->end_freq); 7394 out_range = reg_intersect_ranges(&chip_range, &sp_range); 7395 7396 if (sp_rule_action) 7397 sp_rule_action(&out_range, arg); 7398 7399 p_sp_reg_rule++; 7400 } 7401 } 7402 7403 /** 7404 * reg_afc_incr_num_ranges() - Increment the number of frequency ranges 7405 * @p_range: Pointer to frequency range 7406 * @num_freq_ranges: Pointer to number of frequency ranges. This needs to be 7407 * (Actual type: uint8_t *num_freq_ranges) 7408 * incremented by the function 7409 * 7410 * Return: Void 7411 */ 7412 static void reg_afc_incr_num_ranges(struct freq_range *p_range, 7413 void *num_freq_ranges) 7414 { 7415 if (!reg_is_empty_range(p_range)) 7416 (*(uint8_t *)num_freq_ranges)++; 7417 } 7418 7419 /** 7420 * reg_get_num_sp_freq_ranges() - Find the number of reg rules from the Standard 7421 * power regulatory rules 7422 * @pdev: Pointer to pdev 7423 * 7424 * Return: number of frequency ranges 7425 */ 7426 static uint8_t reg_get_num_sp_freq_ranges(struct wlan_objmgr_pdev *pdev, 7427 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 7428 { 7429 uint8_t num_freq_ranges; 7430 7431 num_freq_ranges = 0; 7432 reg_iterate_sp_rules(pdev, 7433 pdev_priv_obj, 7434 reg_afc_incr_num_ranges, 7435 &num_freq_ranges); 7436 7437 reg_debug("Num_freq_ranges=%u", num_freq_ranges); 7438 return num_freq_ranges; 7439 } 7440 7441 /** 7442 * reg_afc_get_intersected_ranges() - Get the intersected range into range obj 7443 * @rule_fr: Pointer to the rule for frequency range 7444 * @arg: Pointer to opaque object (argument/context) 7445 * (Actual type: struct wlan_afc_freq_range_obj **p_range_obj) 7446 * incremented by the function 7447 * 7448 * Return: Void 7449 */ 7450 static void reg_afc_get_intersected_ranges(struct freq_range *rule_fr, 7451 void *arg) 7452 { 7453 struct wlan_afc_freq_range_obj *p_range; 7454 struct wlan_afc_freq_range_obj **pp_range; 7455 qdf_freq_t low, high; 7456 7457 pp_range = (struct wlan_afc_freq_range_obj **)arg; 7458 p_range = *pp_range; 7459 7460 if (!reg_is_empty_range(rule_fr)) { 7461 reg_assign_vars_with_range_vals(rule_fr, &low, &high); 7462 p_range->lowfreq = (uint16_t)low; 7463 p_range->highfreq = (uint16_t)high; 7464 reg_debug("Range = [%u, %u]", p_range->lowfreq, p_range->highfreq); 7465 (*pp_range)++; 7466 } 7467 } 7468 7469 /** 7470 * reg_cp_freq_ranges() - Copy frequency ranges from the Standard power 7471 * regulatory rules 7472 * @pdev: Pointer to pdev 7473 * @pdev_priv_obj: Pointer to pdev private object 7474 * @num_freq_ranges: Number of frequency ranges 7475 * @p_range_obj: Pointer to range object 7476 * 7477 * Return: void 7478 */ 7479 static void reg_cp_freq_ranges(struct wlan_objmgr_pdev *pdev, 7480 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 7481 uint8_t num_freq_ranges, 7482 struct wlan_afc_freq_range_obj *p_range_obj) 7483 { 7484 struct wlan_afc_freq_range_obj *p_range; 7485 7486 reg_debug("Num freq ranges = %u", num_freq_ranges); 7487 7488 p_range = p_range_obj; 7489 reg_iterate_sp_rules(pdev, 7490 pdev_priv_obj, 7491 reg_afc_get_intersected_ranges, 7492 &p_range); 7493 } 7494 7495 /** 7496 * reg_get_frange_list_len() - Calculate the length of the list of the 7497 * frequency ranges 7498 * @num_freq_ranges: Number of frequency ranges 7499 * 7500 * Return: Length of the frequency range list 7501 */ 7502 static uint16_t reg_get_frange_list_len(uint8_t num_freq_ranges) 7503 { 7504 uint16_t frange_lst_len; 7505 7506 if (!num_freq_ranges) 7507 reg_err("AFC:There is no freq ranges"); 7508 7509 frange_lst_len = 7510 sizeof(struct wlan_afc_frange_list) + 7511 sizeof(struct wlan_afc_freq_range_obj) * num_freq_ranges; 7512 7513 return frange_lst_len; 7514 } 7515 7516 /** 7517 * reg_get_opclasses_array_len() - Calculate the length of the array of 7518 * opclasses objects 7519 * @num_opclasses: The number of opclasses 7520 * @chansize_lst: The array of sizes of channel lists 7521 * 7522 * Return: Length of the array of opclass object 7523 */ 7524 static uint16_t reg_get_opclasses_array_len(struct wlan_objmgr_pdev *pdev, 7525 uint8_t num_opclasses, 7526 uint8_t *chansize_lst) 7527 { 7528 uint16_t opclasses_arr_len = 0; 7529 uint16_t i; 7530 7531 for (i = 0; i < num_opclasses; i++) { 7532 opclasses_arr_len += 7533 sizeof(struct wlan_afc_opclass_obj) + 7534 sizeof(uint8_t) * chansize_lst[i]; 7535 } 7536 7537 return opclasses_arr_len; 7538 } 7539 7540 /** 7541 * reg_get_afc_req_length() - Calculate the length of the AFC partial request 7542 * @num_opclasses: The number of opclasses 7543 * @num_freq_ranges: The number of frequency ranges 7544 * @chansize_lst: The array of sizes of channel lists 7545 * 7546 * Return: Length of the partial AFC request 7547 */ 7548 static uint16_t reg_get_afc_req_length(struct wlan_objmgr_pdev *pdev, 7549 uint8_t num_opclasses, 7550 uint8_t num_freq_ranges, 7551 uint8_t *chansize_lst) 7552 { 7553 uint16_t afc_req_len; 7554 uint16_t frange_lst_len; 7555 uint16_t fixed_param_len; 7556 uint16_t num_opclasses_len; 7557 uint16_t opclasses_arr_len; 7558 uint16_t afc_location_len; 7559 7560 fixed_param_len = sizeof(struct wlan_afc_host_req_fixed_params); 7561 frange_lst_len = reg_get_frange_list_len(num_freq_ranges); 7562 num_opclasses_len = sizeof(struct wlan_afc_num_opclasses); 7563 opclasses_arr_len = reg_get_opclasses_array_len(pdev, 7564 num_opclasses, 7565 chansize_lst); 7566 afc_location_len = sizeof(struct wlan_afc_location); 7567 7568 afc_req_len = 7569 fixed_param_len + 7570 frange_lst_len + 7571 num_opclasses_len + 7572 opclasses_arr_len + 7573 afc_location_len; 7574 7575 return afc_req_len; 7576 } 7577 7578 /** 7579 * reg_fill_afc_fixed_params() - Fill the AFC fixed params 7580 * @p_fixed_params: Pointer to afc fixed params object 7581 * @afc_req_len: Length of the partial AFC request 7582 * 7583 * Return: Void 7584 */ 7585 static inline void 7586 reg_fill_afc_fixed_params(struct wlan_afc_host_req_fixed_params *p_fixed_params, 7587 uint16_t afc_req_len) 7588 { 7589 p_fixed_params->req_length = afc_req_len; 7590 p_fixed_params->req_id = DEFAULT_REQ_ID; 7591 p_fixed_params->min_des_power = DEFAULT_MIN_POWER; 7592 } 7593 7594 /** 7595 * reg_fill_afc_freq_ranges() - Fill the AFC fixed params 7596 * @pdev: Pointer to pdev 7597 * @pdev_priv_obj: Pointer to pdev private object 7598 * @p_frange_lst: Pointer to frequency range list 7599 * @num_freq_ranges: Number of frequency ranges 7600 * 7601 * Return: Void 7602 */ 7603 static inline void 7604 reg_fill_afc_freq_ranges(struct wlan_objmgr_pdev *pdev, 7605 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 7606 struct wlan_afc_frange_list *p_frange_lst, 7607 uint8_t num_freq_ranges) 7608 { 7609 struct wlan_afc_freq_range_obj *p_range_obj; 7610 7611 p_frange_lst->num_ranges = num_freq_ranges; 7612 7613 p_range_obj = &p_frange_lst->range_objs[0]; 7614 7615 reg_cp_freq_ranges(pdev, pdev_priv_obj, num_freq_ranges, p_range_obj); 7616 } 7617 7618 /** 7619 * reg_fill_afc_opclass_obj() - Fill the opclass object and return pointer to 7620 * next AFC opclass object 7621 * @p_obj_opclass_obj: Pointer to opclass object 7622 * @opclass: Operating class 7623 * @num_chans: Number of channels in the opclass 7624 * @p_chan_lst: Pointer to channel list 7625 * 7626 * Return: Pointer to the next AFC opclass object 7627 */ 7628 static struct wlan_afc_opclass_obj * 7629 reg_fill_afc_opclass_obj(struct wlan_afc_opclass_obj *p_obj_opclass_obj, 7630 uint8_t opclass, 7631 uint8_t num_chans, 7632 uint8_t *p_chan_lst) 7633 { 7634 uint16_t len_obj; 7635 uint8_t *out_p; 7636 uint8_t *src, *dst; 7637 uint8_t copy_len; 7638 7639 p_obj_opclass_obj->opclass_num_cfis = num_chans; 7640 p_obj_opclass_obj->opclass = opclass; 7641 src = p_chan_lst; 7642 dst = p_obj_opclass_obj->cfis; 7643 copy_len = num_chans * sizeof(uint8_t); 7644 7645 qdf_mem_copy(dst, src, copy_len); 7646 7647 len_obj = sizeof(struct wlan_afc_opclass_obj) + copy_len; 7648 out_p = (uint8_t *)p_obj_opclass_obj + len_obj; 7649 7650 return (struct wlan_afc_opclass_obj *)out_p; 7651 } 7652 7653 /** 7654 * reg_fill_afc_opclasses_arr() - Fill the array of opclass objects 7655 * @num_opclasses: The number of opclasses 7656 * @opclass_lst: The array of Operating classes 7657 * @chansize_lst: The array of sizes of channel lists 7658 * @channel_lists: The array of channel lists 7659 * @p_opclass_obj_arr: Pointer to the first opclass object 7660 * 7661 * Return: Pointer to the end of last opclass object 7662 */ 7663 static inline struct wlan_afc_opclass_obj * 7664 reg_fill_afc_opclasses_arr(struct wlan_objmgr_pdev *pdev, 7665 uint8_t num_opclasses, 7666 uint8_t *opclass_lst, 7667 uint8_t *chansize_lst, 7668 uint8_t *channel_lists[], 7669 struct wlan_afc_opclass_obj *p_opclass_obj_arr) 7670 { 7671 uint16_t i; 7672 struct wlan_afc_opclass_obj *p_opclass_obj; 7673 7674 p_opclass_obj = p_opclass_obj_arr; 7675 7676 for (i = 0; i < num_opclasses; i++) { 7677 p_opclass_obj = reg_fill_afc_opclass_obj(p_opclass_obj, 7678 opclass_lst[i], 7679 chansize_lst[i], 7680 channel_lists[i]); 7681 } 7682 return p_opclass_obj; 7683 } 7684 7685 /** 7686 * reg_next_opcls_ptr() - Get the pointer to the next opclass object 7687 * @p_cur_opcls_obj: Pointer to the current operating class object 7688 * @num_cfis: number of center frequency indices 7689 * 7690 * Return: Pointer to next opclss object 7691 */ 7692 static struct wlan_afc_opclass_obj * 7693 reg_next_opcls_ptr(struct wlan_afc_opclass_obj *p_cur_opcls_obj, 7694 uint8_t num_cfis) 7695 { 7696 uint8_t cur_obj_sz; 7697 uint8_t fixed_opcls_sz; 7698 struct wlan_afc_opclass_obj *p_next_opcls_obj; 7699 uint8_t *p_tmp_next; 7700 7701 fixed_opcls_sz = sizeof(struct wlan_afc_opclass_obj); 7702 cur_obj_sz = fixed_opcls_sz + num_cfis * sizeof(uint8_t); 7703 p_tmp_next = (uint8_t *)p_cur_opcls_obj + cur_obj_sz; 7704 p_next_opcls_obj = (struct wlan_afc_opclass_obj *)p_tmp_next; 7705 7706 return p_next_opcls_obj; 7707 } 7708 7709 void reg_print_partial_afc_req_info(struct wlan_objmgr_pdev *pdev, 7710 struct wlan_afc_host_partial_request *afc_req) 7711 { 7712 struct wlan_afc_host_req_fixed_params *p_fixed_params; 7713 struct wlan_afc_frange_list *p_frange_lst; 7714 struct wlan_afc_num_opclasses *p_num_opclasses; 7715 uint8_t i; 7716 uint8_t j; 7717 uint16_t frange_lst_len; 7718 uint8_t num_opclasses; 7719 struct wlan_afc_opclass_obj *p_obj_opclass_arr; 7720 struct wlan_afc_opclass_obj *p_opclass_obj; 7721 uint8_t num_freq_ranges; 7722 uint8_t *p_temp; 7723 struct wlan_afc_location *p_afc_location; 7724 uint8_t *deployment_type_str; 7725 7726 p_fixed_params = &afc_req->fixed_params; 7727 reg_debug("req_length=%hu", p_fixed_params->req_length); 7728 reg_debug("req_id=%llu", p_fixed_params->req_id); 7729 reg_debug("min_des_power=%hd", p_fixed_params->min_des_power); 7730 7731 p_temp = (uint8_t *)p_fixed_params; 7732 p_temp += sizeof(*p_fixed_params); 7733 p_frange_lst = (struct wlan_afc_frange_list *)p_temp; 7734 reg_debug("num_ranges=%hhu", p_frange_lst->num_ranges); 7735 for (i = 0; i < p_frange_lst->num_ranges; i++) { 7736 struct wlan_afc_freq_range_obj *p_range_obj; 7737 7738 p_range_obj = &p_frange_lst->range_objs[i]; 7739 reg_debug("lowfreq=%hu", p_range_obj->lowfreq); 7740 reg_debug("highfreq=%hu", p_range_obj->highfreq); 7741 } 7742 7743 num_freq_ranges = p_frange_lst->num_ranges; 7744 frange_lst_len = reg_get_frange_list_len(num_freq_ranges); 7745 p_temp += frange_lst_len; 7746 p_num_opclasses = (struct wlan_afc_num_opclasses *)p_temp; 7747 num_opclasses = p_num_opclasses->num_opclasses; 7748 reg_debug("num_opclasses=%hhu", num_opclasses); 7749 7750 p_temp += sizeof(*p_num_opclasses); 7751 p_obj_opclass_arr = (struct wlan_afc_opclass_obj *)p_temp; 7752 p_opclass_obj = p_obj_opclass_arr; 7753 for (i = 0; i < num_opclasses; i++) { 7754 uint8_t opclass = p_opclass_obj->opclass; 7755 uint8_t num_cfis = p_opclass_obj->opclass_num_cfis; 7756 uint8_t *cfis = p_opclass_obj->cfis; 7757 7758 reg_debug("opclass[%hhu]=%hhu", i, opclass); 7759 reg_debug("num_cfis[%hhu]=%hhu", i, num_cfis); 7760 reg_debug("["); 7761 for (j = 0; j < num_cfis; j++) 7762 reg_debug("%hhu,", cfis[j]); 7763 reg_debug("]"); 7764 7765 p_opclass_obj = reg_next_opcls_ptr(p_opclass_obj, num_cfis); 7766 } 7767 7768 p_afc_location = (struct wlan_afc_location *)p_opclass_obj; 7769 switch (p_afc_location->deployment_type) { 7770 case AFC_DEPLOYMENT_INDOOR: 7771 deployment_type_str = "Indoor"; 7772 break; 7773 case AFC_DEPLOYMENT_OUTDOOR: 7774 deployment_type_str = "Outdoor"; 7775 break; 7776 default: 7777 deployment_type_str = "Unknown"; 7778 } 7779 reg_debug("AFC location=%s", deployment_type_str); 7780 } 7781 7782 /** 7783 * reg_get_frange_filled_buf() - Allocate and fill the frange buffer and return 7784 * the buffer. Also return the number of frequence ranges 7785 * @pdev: Pointer to pdev 7786 * @pdev_priv_obj: Pointer to pdev private object 7787 * @num_freq_ranges: Pointer to number of frequency ranges (output param) 7788 * 7789 * Return: Pointer to the frange buffer 7790 */ 7791 static struct wlan_afc_frange_list * 7792 reg_get_frange_filled_buf(struct wlan_objmgr_pdev *pdev, 7793 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 7794 uint8_t *num_freq_ranges) 7795 { 7796 uint16_t frange_lst_len; 7797 struct wlan_afc_frange_list *p_frange_lst_local; 7798 7799 *num_freq_ranges = reg_get_num_sp_freq_ranges(pdev, pdev_priv_obj); 7800 frange_lst_len = reg_get_frange_list_len(*num_freq_ranges); 7801 7802 p_frange_lst_local = qdf_mem_malloc(frange_lst_len); 7803 if (!p_frange_lst_local) 7804 return NULL; 7805 7806 reg_fill_afc_freq_ranges(pdev, 7807 pdev_priv_obj, 7808 p_frange_lst_local, 7809 *num_freq_ranges); 7810 return p_frange_lst_local; 7811 } 7812 7813 QDF_STATUS 7814 reg_get_partial_afc_req_info(struct wlan_objmgr_pdev *pdev, 7815 struct wlan_afc_host_partial_request **afc_req) 7816 { 7817 /* allocate the memory for the partial request */ 7818 struct wlan_afc_host_partial_request *temp_afc_req; 7819 struct wlan_afc_host_req_fixed_params *p_fixed_params; 7820 struct wlan_afc_frange_list *p_frange_lst_local; 7821 struct wlan_afc_frange_list *p_frange_lst_afc; 7822 struct wlan_afc_num_opclasses *p_num_opclasses; 7823 uint16_t afc_req_len; 7824 uint16_t frange_lst_len; 7825 uint8_t num_freq_ranges; 7826 uint8_t num_opclasses; 7827 struct wlan_afc_opclass_obj *p_obj_opclass_arr; 7828 struct wlan_afc_location *p_afc_location; 7829 7830 uint8_t *opclass_lst; 7831 uint8_t *chansize_lst; 7832 uint8_t **channel_lists; 7833 QDF_STATUS status; 7834 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7835 7836 if (!afc_req) { 7837 reg_err("afc_req is NULL"); 7838 status = QDF_STATUS_E_INVAL; 7839 return status; 7840 } 7841 7842 temp_afc_req = NULL; 7843 pdev_priv_obj = reg_get_pdev_obj(pdev); 7844 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7845 reg_err("pdev reg component is NULL"); 7846 status = QDF_STATUS_E_INVAL; 7847 goto handle_invalid_priv_object; 7848 } 7849 7850 p_frange_lst_local = reg_get_frange_filled_buf(pdev, 7851 pdev_priv_obj, 7852 &num_freq_ranges); 7853 if (!p_frange_lst_local) { 7854 reg_err("Frange lst not allocated"); 7855 status = QDF_STATUS_E_NOMEM; 7856 goto handle_invalid_priv_object; 7857 } 7858 7859 status = reg_dmn_get_6g_opclasses_and_channels(pdev, 7860 p_frange_lst_local, 7861 &num_opclasses, 7862 &opclass_lst, 7863 &chansize_lst, 7864 &channel_lists); 7865 if (status != QDF_STATUS_SUCCESS) { 7866 reg_err("Opclasses and chans not allocated"); 7867 status = QDF_STATUS_E_NOMEM; 7868 goto free_frange_lst_local; 7869 } 7870 7871 afc_req_len = reg_get_afc_req_length(pdev, 7872 num_opclasses, 7873 num_freq_ranges, 7874 chansize_lst); 7875 7876 temp_afc_req = qdf_mem_malloc(afc_req_len); 7877 if (!temp_afc_req) { 7878 reg_err("AFC request not allocated"); 7879 status = QDF_STATUS_E_NOMEM; 7880 goto free_opcls_chan_mem; 7881 } 7882 7883 p_fixed_params = &temp_afc_req->fixed_params; 7884 reg_fill_afc_fixed_params(p_fixed_params, afc_req_len); 7885 7886 /* frange list is already filled just copy it */ 7887 frange_lst_len = reg_get_frange_list_len(num_freq_ranges); 7888 p_frange_lst_afc = (struct wlan_afc_frange_list *)&p_fixed_params[1]; 7889 qdf_mem_copy(p_frange_lst_afc, p_frange_lst_local, frange_lst_len); 7890 7891 p_num_opclasses = (struct wlan_afc_num_opclasses *) 7892 ((char *)(p_frange_lst_afc) + frange_lst_len); 7893 p_num_opclasses->num_opclasses = num_opclasses; 7894 7895 p_obj_opclass_arr = (struct wlan_afc_opclass_obj *)&p_num_opclasses[1]; 7896 p_obj_opclass_arr = reg_fill_afc_opclasses_arr(pdev, 7897 num_opclasses, 7898 opclass_lst, 7899 chansize_lst, 7900 channel_lists, 7901 p_obj_opclass_arr); 7902 7903 p_afc_location = (struct wlan_afc_location *)p_obj_opclass_arr; 7904 p_afc_location->deployment_type = 7905 pdev_priv_obj->reg_afc_dev_deployment_type; 7906 p_afc_location->afc_elem_type = AFC_OBJ_LOCATION; 7907 p_afc_location->afc_elem_len = 7908 sizeof(*p_afc_location) - 7909 sizeof(p_afc_location->afc_elem_type) - 7910 sizeof(p_afc_location->afc_elem_len); 7911 free_opcls_chan_mem: 7912 reg_dmn_free_6g_opclasses_and_channels(pdev, 7913 num_opclasses, 7914 opclass_lst, 7915 chansize_lst, 7916 channel_lists); 7917 7918 free_frange_lst_local: 7919 qdf_mem_free(p_frange_lst_local); 7920 7921 handle_invalid_priv_object: 7922 *afc_req = temp_afc_req; 7923 7924 return status; 7925 } 7926 7927 void reg_dmn_set_afc_req_id(struct wlan_afc_host_partial_request *afc_req, 7928 uint64_t req_id) 7929 { 7930 struct wlan_afc_host_req_fixed_params *p_fixed_params; 7931 7932 p_fixed_params = &afc_req->fixed_params; 7933 p_fixed_params->req_id = req_id; 7934 } 7935 7936 /** 7937 * reg_send_afc_partial_request() - Send AFC partial request to registered 7938 * recipient 7939 * @pdev: Pointer to pdev 7940 * @afc_req: Pointer to afc partial request 7941 * 7942 * Return: void 7943 */ 7944 static 7945 void reg_send_afc_partial_request(struct wlan_objmgr_pdev *pdev, 7946 struct wlan_afc_host_partial_request *afc_req) 7947 { 7948 afc_req_rx_evt_handler cbf; 7949 void *arg; 7950 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7951 7952 pdev_priv_obj = reg_get_pdev_obj(pdev); 7953 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7954 reg_err("pdev reg component is NULL"); 7955 return; 7956 } 7957 7958 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7959 cbf = pdev_priv_obj->afc_cb_obj.func; 7960 if (cbf) { 7961 arg = pdev_priv_obj->afc_cb_obj.arg; 7962 cbf(pdev, afc_req, arg); 7963 } 7964 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7965 } 7966 7967 QDF_STATUS reg_afc_start(struct wlan_objmgr_pdev *pdev, uint64_t req_id) 7968 { 7969 struct wlan_afc_host_partial_request *afc_req; 7970 QDF_STATUS status; 7971 7972 status = reg_get_partial_afc_req_info(pdev, &afc_req); 7973 if (status != QDF_STATUS_SUCCESS) { 7974 reg_err("Creating AFC Request failed"); 7975 return QDF_STATUS_E_FAILURE; 7976 } 7977 7978 QDF_TRACE(QDF_MODULE_ID_AFC, QDF_TRACE_LEVEL_DEBUG, 7979 "Processing AFC Start/Renew Expiry event"); 7980 7981 reg_dmn_set_afc_req_id(afc_req, req_id); 7982 7983 reg_print_partial_afc_req_info(pdev, afc_req); 7984 7985 reg_send_afc_partial_request(pdev, afc_req); 7986 7987 qdf_mem_free(afc_req); 7988 7989 return QDF_STATUS_SUCCESS; 7990 } 7991 7992 QDF_STATUS reg_send_afc_power_event(struct wlan_objmgr_pdev *pdev, 7993 struct reg_fw_afc_power_event *power_info) 7994 { 7995 afc_power_tx_evt_handler cbf; 7996 void *arg; 7997 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7998 7999 pdev_priv_obj = reg_get_pdev_obj(pdev); 8000 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8001 reg_err("pdev reg component is NULL"); 8002 return QDF_STATUS_E_FAILURE; 8003 } 8004 8005 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 8006 cbf = pdev_priv_obj->afc_pow_evt_cb_obj.func; 8007 if (cbf) { 8008 arg = pdev_priv_obj->afc_pow_evt_cb_obj.arg; 8009 cbf(pdev, power_info, arg); 8010 } 8011 8012 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 8013 8014 return QDF_STATUS_SUCCESS; 8015 } 8016 8017 QDF_STATUS reg_register_afc_req_rx_callback(struct wlan_objmgr_pdev *pdev, 8018 afc_req_rx_evt_handler cbf, 8019 void *arg) 8020 { 8021 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8022 8023 pdev_priv_obj = reg_get_pdev_obj(pdev); 8024 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8025 reg_err("pdev reg component is NULL"); 8026 return QDF_STATUS_E_FAILURE; 8027 } 8028 8029 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 8030 pdev_priv_obj->afc_cb_obj.func = cbf; 8031 pdev_priv_obj->afc_cb_obj.arg = arg; 8032 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 8033 reg_debug("afc_event_cb: 0x%pK, arg: 0x%pK", cbf, arg); 8034 8035 return QDF_STATUS_SUCCESS; 8036 } 8037 8038 QDF_STATUS reg_unregister_afc_req_rx_callback(struct wlan_objmgr_pdev *pdev, 8039 afc_req_rx_evt_handler cbf) 8040 { 8041 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8042 8043 pdev_priv_obj = reg_get_pdev_obj(pdev); 8044 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8045 reg_err("pdev reg component is NULL"); 8046 return QDF_STATUS_E_FAILURE; 8047 } 8048 8049 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 8050 if (pdev_priv_obj->afc_cb_obj.func == cbf) { 8051 pdev_priv_obj->afc_cb_obj.func = NULL; 8052 pdev_priv_obj->afc_cb_obj.arg = NULL; 8053 } else { 8054 reg_err("cb function=0x%pK not found", cbf); 8055 } 8056 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 8057 8058 return QDF_STATUS_SUCCESS; 8059 } 8060 8061 QDF_STATUS 8062 reg_register_afc_power_event_callback(struct wlan_objmgr_pdev *pdev, 8063 afc_power_tx_evt_handler cbf, 8064 void *arg) 8065 { 8066 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8067 8068 pdev_priv_obj = reg_get_pdev_obj(pdev); 8069 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8070 reg_err("pdev reg component is NULL"); 8071 return QDF_STATUS_E_FAILURE; 8072 } 8073 8074 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 8075 pdev_priv_obj->afc_pow_evt_cb_obj.func = cbf; 8076 pdev_priv_obj->afc_pow_evt_cb_obj.arg = arg; 8077 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 8078 reg_debug("afc_power_event_cb: 0x%pK, arg: 0x%pK", cbf, arg); 8079 8080 return QDF_STATUS_SUCCESS; 8081 } 8082 8083 QDF_STATUS 8084 reg_unregister_afc_power_event_callback(struct wlan_objmgr_pdev *pdev, 8085 afc_power_tx_evt_handler cbf) 8086 { 8087 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8088 8089 pdev_priv_obj = reg_get_pdev_obj(pdev); 8090 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8091 reg_err("pdev reg component is NULL"); 8092 return QDF_STATUS_E_FAILURE; 8093 } 8094 8095 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 8096 if (pdev_priv_obj->afc_pow_evt_cb_obj.func == cbf) { 8097 pdev_priv_obj->afc_pow_evt_cb_obj.func = NULL; 8098 pdev_priv_obj->afc_pow_evt_cb_obj.arg = NULL; 8099 } else { 8100 reg_err("cb function=0x%pK not found", cbf); 8101 } 8102 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 8103 8104 return QDF_STATUS_SUCCESS; 8105 } 8106 8107 QDF_STATUS 8108 reg_get_afc_dev_deploy_type(struct wlan_objmgr_pdev *pdev, 8109 enum reg_afc_dev_deploy_type *reg_afc_dev_type) 8110 { 8111 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8112 8113 pdev_priv_obj = reg_get_pdev_obj(pdev); 8114 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8115 reg_err("pdev reg component is NULL"); 8116 return QDF_STATUS_E_FAILURE; 8117 } 8118 8119 *reg_afc_dev_type = pdev_priv_obj->reg_afc_dev_deployment_type; 8120 8121 return QDF_STATUS_SUCCESS; 8122 } 8123 8124 bool 8125 reg_is_sta_connect_allowed(struct wlan_objmgr_pdev *pdev, 8126 enum reg_6g_ap_type root_ap_pwr_mode) 8127 { 8128 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8129 8130 pdev_priv_obj = reg_get_pdev_obj(pdev); 8131 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8132 reg_err("pdev reg component is NULL"); 8133 return false; 8134 } 8135 8136 if (reg_get_num_rules_of_ap_pwr_type(pdev, REG_STANDARD_POWER_AP) && 8137 (pdev_priv_obj->reg_afc_dev_deployment_type == AFC_DEPLOYMENT_OUTDOOR)) { 8138 if (root_ap_pwr_mode == REG_STANDARD_POWER_AP) 8139 return true; 8140 else 8141 return false; 8142 } 8143 8144 return true; 8145 } 8146 8147 QDF_STATUS reg_set_afc_soc_dev_type(struct wlan_objmgr_psoc *psoc, 8148 enum reg_afc_dev_deploy_type 8149 reg_afc_dev_type) 8150 { 8151 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8152 8153 psoc_priv_obj = reg_get_psoc_obj(psoc); 8154 8155 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8156 reg_err("psoc reg component is NULL"); 8157 return QDF_STATUS_E_FAILURE; 8158 } 8159 8160 psoc_priv_obj->reg_afc_dev_type = reg_afc_dev_type; 8161 8162 return QDF_STATUS_SUCCESS; 8163 } 8164 8165 QDF_STATUS 8166 reg_get_afc_soc_dev_type(struct wlan_objmgr_psoc *psoc, 8167 enum reg_afc_dev_deploy_type *reg_afc_dev_type) 8168 { 8169 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8170 8171 psoc_priv_obj = reg_get_psoc_obj(psoc); 8172 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8173 reg_err("psoc reg component is NULL"); 8174 return QDF_STATUS_E_FAILURE; 8175 } 8176 8177 *reg_afc_dev_type = psoc_priv_obj->reg_afc_dev_type; 8178 8179 return QDF_STATUS_SUCCESS; 8180 } 8181 8182 QDF_STATUS 8183 reg_set_eirp_preferred_support(struct wlan_objmgr_psoc *psoc, 8184 bool reg_is_eirp_support_preferred) 8185 { 8186 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8187 8188 psoc_priv_obj = reg_get_psoc_obj(psoc); 8189 8190 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8191 reg_err("psoc reg component is NULL"); 8192 return QDF_STATUS_E_FAILURE; 8193 } 8194 8195 psoc_priv_obj->reg_is_eirp_support_preferred = 8196 reg_is_eirp_support_preferred; 8197 8198 return QDF_STATUS_SUCCESS; 8199 } 8200 8201 QDF_STATUS 8202 reg_get_eirp_preferred_support(struct wlan_objmgr_psoc *psoc, 8203 bool *reg_is_eirp_support_preferred) 8204 { 8205 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8206 8207 psoc_priv_obj = reg_get_psoc_obj(psoc); 8208 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8209 reg_err("psoc reg component is NULL"); 8210 return QDF_STATUS_E_FAILURE; 8211 } 8212 8213 *reg_is_eirp_support_preferred = 8214 psoc_priv_obj->reg_is_eirp_support_preferred; 8215 8216 return QDF_STATUS_SUCCESS; 8217 } 8218 8219 #endif /* CONFIG_AFC_SUPPORT */ 8220 8221 QDF_STATUS 8222 reg_get_cur_6g_client_type(struct wlan_objmgr_pdev *pdev, 8223 enum reg_6g_client_type 8224 *reg_cur_6g_client_mobility_type) 8225 { 8226 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8227 8228 pdev_priv_obj = reg_get_pdev_obj(pdev); 8229 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8230 reg_err("pdev reg component is NULL"); 8231 return QDF_STATUS_E_FAILURE; 8232 } 8233 8234 if (pdev_priv_obj->reg_cur_6g_client_mobility_type >= 8235 REG_MAX_CLIENT_TYPE) 8236 return QDF_STATUS_E_FAILURE; 8237 8238 *reg_cur_6g_client_mobility_type = 8239 pdev_priv_obj->reg_cur_6g_client_mobility_type; 8240 8241 return QDF_STATUS_SUCCESS; 8242 } 8243 8244 QDF_STATUS 8245 reg_set_cur_6ghz_client_type(struct wlan_objmgr_pdev *pdev, 8246 enum reg_6g_client_type in_6ghz_client_type) 8247 { 8248 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8249 8250 pdev_priv_obj = reg_get_pdev_obj(pdev); 8251 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8252 reg_err("pdev reg component is NULL"); 8253 return QDF_STATUS_E_FAILURE; 8254 } 8255 8256 if (in_6ghz_client_type >= REG_MAX_CLIENT_TYPE) 8257 return QDF_STATUS_E_FAILURE; 8258 8259 pdev_priv_obj->reg_cur_6g_client_mobility_type = in_6ghz_client_type; 8260 8261 return QDF_STATUS_SUCCESS; 8262 } 8263 8264 QDF_STATUS 8265 reg_set_6ghz_client_type_from_target(struct wlan_objmgr_pdev *pdev) 8266 { 8267 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8268 8269 pdev_priv_obj = reg_get_pdev_obj(pdev); 8270 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8271 reg_err("pdev reg component is NULL"); 8272 return QDF_STATUS_E_FAILURE; 8273 } 8274 8275 pdev_priv_obj->reg_cur_6g_client_mobility_type = 8276 pdev_priv_obj->reg_target_client_type; 8277 8278 return QDF_STATUS_SUCCESS; 8279 } 8280 8281 QDF_STATUS reg_get_rnr_tpe_usable(struct wlan_objmgr_pdev *pdev, 8282 bool *reg_rnr_tpe_usable) 8283 { 8284 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8285 8286 pdev_priv_obj = reg_get_pdev_obj(pdev); 8287 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8288 reg_err("pdev reg component is NULL"); 8289 return QDF_STATUS_E_FAILURE; 8290 } 8291 *reg_rnr_tpe_usable = pdev_priv_obj->reg_rnr_tpe_usable; 8292 return QDF_STATUS_SUCCESS; 8293 } 8294 8295 QDF_STATUS reg_get_unspecified_ap_usable(struct wlan_objmgr_pdev *pdev, 8296 bool *reg_unspecified_ap_usable) 8297 { 8298 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8299 8300 pdev_priv_obj = reg_get_pdev_obj(pdev); 8301 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8302 reg_err("pdev reg component is NULL"); 8303 return QDF_STATUS_E_FAILURE; 8304 } 8305 *reg_unspecified_ap_usable = pdev_priv_obj->reg_unspecified_ap_usable; 8306 return QDF_STATUS_SUCCESS; 8307 } 8308 8309 QDF_STATUS 8310 reg_find_txpower_from_6g_list(qdf_freq_t freq, 8311 struct regulatory_channel *chan_list, 8312 uint16_t *txpower) 8313 { 8314 enum channel_enum chan_enum; 8315 8316 *txpower = 0; 8317 8318 for (chan_enum = 0; chan_enum < NUM_6GHZ_CHANNELS; chan_enum++) { 8319 if (chan_list[chan_enum].center_freq == freq) { 8320 *txpower = chan_list[chan_enum].tx_power; 8321 return QDF_STATUS_SUCCESS; 8322 } 8323 } 8324 8325 return QDF_STATUS_E_FAILURE; 8326 } 8327 8328 bool reg_is_6g_psd_power(struct wlan_objmgr_pdev *pdev) 8329 { 8330 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8331 struct regulatory_channel *cur_chan_list; 8332 enum channel_enum i; 8333 8334 if (!pdev) { 8335 reg_err("pdev is NULL"); 8336 return false; 8337 } 8338 8339 pdev_priv_obj = reg_get_pdev_obj(pdev); 8340 if (!pdev_priv_obj) { 8341 reg_err("pdev priv obj is NULL"); 8342 return false; 8343 } 8344 8345 cur_chan_list = pdev_priv_obj->cur_chan_list; 8346 8347 for (i = MIN_6GHZ_CHANNEL; i <= MAX_6GHZ_CHANNEL; i++) { 8348 if (!(cur_chan_list[i].chan_flags & REGULATORY_CHAN_DISABLED)) 8349 return cur_chan_list[i].psd_flag; 8350 } 8351 8352 return false; 8353 } 8354 8355 QDF_STATUS 8356 reg_get_6g_chan_psd_eirp_power(qdf_freq_t freq, 8357 struct regulatory_channel *mas_chan_list, 8358 uint16_t *eirp_psd_power) 8359 { 8360 uint16_t i; 8361 8362 if (!mas_chan_list) { 8363 reg_err_rl("mas_chan_list is NULL"); 8364 return QDF_STATUS_E_FAILURE; 8365 } 8366 8367 for (i = 0; i < NUM_6GHZ_CHANNELS; i++) { 8368 if (freq == mas_chan_list[i].center_freq) { 8369 *eirp_psd_power = mas_chan_list[i].psd_eirp; 8370 return QDF_STATUS_SUCCESS; 8371 } 8372 } 8373 8374 return QDF_STATUS_E_FAILURE; 8375 } 8376 8377 QDF_STATUS reg_get_6g_chan_ap_power(struct wlan_objmgr_pdev *pdev, 8378 qdf_freq_t chan_freq, bool *is_psd, 8379 uint16_t *tx_power, 8380 uint16_t *eirp_psd_power) 8381 { 8382 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8383 struct regulatory_channel *master_chan_list; 8384 enum reg_6g_ap_type ap_pwr_type; 8385 QDF_STATUS status = QDF_STATUS_SUCCESS; 8386 8387 pdev_priv_obj = reg_get_pdev_obj(pdev); 8388 if (!pdev_priv_obj) { 8389 reg_err("pdev priv obj is NULL"); 8390 return QDF_STATUS_E_FAILURE; 8391 } 8392 8393 status = reg_get_cur_6g_ap_pwr_type(pdev, &ap_pwr_type); 8394 if (!QDF_IS_STATUS_SUCCESS(status)) 8395 return status; 8396 8397 master_chan_list = pdev_priv_obj->mas_chan_list_6g_ap[ap_pwr_type]; 8398 8399 reg_find_txpower_from_6g_list(chan_freq, master_chan_list, 8400 tx_power); 8401 8402 *is_psd = reg_is_6g_psd_power(pdev); 8403 if (*is_psd) 8404 status = reg_get_6g_chan_psd_eirp_power(chan_freq, 8405 master_chan_list, 8406 eirp_psd_power); 8407 8408 return status; 8409 } 8410 8411 QDF_STATUS reg_get_client_power_for_connecting_ap(struct wlan_objmgr_pdev *pdev, 8412 enum reg_6g_ap_type ap_type, 8413 qdf_freq_t chan_freq, 8414 bool is_psd, 8415 uint16_t *tx_power, 8416 uint16_t *eirp_psd_power) 8417 { 8418 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8419 enum reg_6g_client_type client_type; 8420 struct regulatory_channel *master_chan_list; 8421 QDF_STATUS status = QDF_STATUS_SUCCESS; 8422 8423 pdev_priv_obj = reg_get_pdev_obj(pdev); 8424 if (!pdev_priv_obj) { 8425 reg_err("pdev priv obj is NULL"); 8426 return QDF_STATUS_E_FAILURE; 8427 } 8428 8429 reg_get_cur_6g_client_type(pdev, &client_type); 8430 8431 master_chan_list = 8432 pdev_priv_obj->mas_chan_list_6g_client[ap_type][client_type]; 8433 8434 reg_find_txpower_from_6g_list(chan_freq, master_chan_list, 8435 tx_power); 8436 8437 if (is_psd) 8438 status = reg_get_6g_chan_psd_eirp_power(chan_freq, 8439 master_chan_list, 8440 eirp_psd_power); 8441 8442 return status; 8443 } 8444 8445 QDF_STATUS reg_get_client_power_for_6ghz_ap(struct wlan_objmgr_pdev *pdev, 8446 enum reg_6g_client_type client_type, 8447 qdf_freq_t chan_freq, 8448 bool *is_psd, uint16_t *tx_power, 8449 uint16_t *eirp_psd_power) 8450 { 8451 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8452 enum reg_6g_ap_type ap_pwr_type; 8453 struct regulatory_channel *master_chan_list; 8454 QDF_STATUS status = QDF_STATUS_SUCCESS; 8455 8456 status = reg_get_cur_6g_ap_pwr_type(pdev, &ap_pwr_type); 8457 if (!QDF_IS_STATUS_SUCCESS(status)) 8458 return status; 8459 8460 pdev_priv_obj = reg_get_pdev_obj(pdev); 8461 if (!pdev_priv_obj) { 8462 reg_err("pdev priv obj is NULL"); 8463 return QDF_STATUS_E_FAILURE; 8464 } 8465 8466 master_chan_list = pdev_priv_obj-> 8467 mas_chan_list_6g_client[ap_pwr_type][client_type]; 8468 8469 reg_find_txpower_from_6g_list(chan_freq, master_chan_list, 8470 tx_power); 8471 8472 *is_psd = reg_is_6g_psd_power(pdev); 8473 if (*is_psd) 8474 status = reg_get_6g_chan_psd_eirp_power(chan_freq, 8475 master_chan_list, 8476 eirp_psd_power); 8477 8478 return status; 8479 } 8480 8481 QDF_STATUS reg_set_ap_pwr_and_update_chan_list(struct wlan_objmgr_pdev *pdev, 8482 enum reg_6g_ap_type ap_pwr_type) 8483 { 8484 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8485 QDF_STATUS status; 8486 8487 pdev_priv_obj = reg_get_pdev_obj(pdev); 8488 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8489 reg_err("pdev reg component is NULL"); 8490 return QDF_STATUS_E_INVAL; 8491 } 8492 8493 if (!reg_get_num_rules_of_ap_pwr_type(pdev, ap_pwr_type)) 8494 return QDF_STATUS_E_FAILURE; 8495 8496 status = reg_set_cur_6g_ap_pwr_type(pdev, ap_pwr_type); 8497 if (QDF_IS_STATUS_ERROR(status)) { 8498 reg_debug("failed to set AP power type to %d", ap_pwr_type); 8499 return status; 8500 } 8501 8502 reg_compute_pdev_current_chan_list(pdev_priv_obj); 8503 8504 return QDF_STATUS_SUCCESS; 8505 } 8506 #endif 8507 8508 bool reg_is_regdb_offloaded(struct wlan_objmgr_psoc *psoc) 8509 { 8510 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8511 8512 psoc_priv_obj = reg_get_psoc_obj(psoc); 8513 if (!psoc_priv_obj) { 8514 reg_err("reg psoc private obj is NULL"); 8515 return false; 8516 } 8517 8518 return psoc_priv_obj->offload_enabled; 8519 } 8520 8521 QDF_STATUS 8522 reg_set_ext_tpc_supported(struct wlan_objmgr_psoc *psoc, bool val) 8523 { 8524 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8525 8526 psoc_priv_obj = reg_get_psoc_obj(psoc); 8527 8528 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8529 reg_err("psoc reg component is NULL"); 8530 return QDF_STATUS_E_FAILURE; 8531 } 8532 8533 psoc_priv_obj->is_ext_tpc_supported = val; 8534 8535 return QDF_STATUS_SUCCESS; 8536 } 8537 8538 bool reg_is_ext_tpc_supported(struct wlan_objmgr_psoc *psoc) 8539 { 8540 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8541 8542 psoc_priv_obj = reg_get_psoc_obj(psoc); 8543 8544 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8545 reg_err("psoc reg component is NULL"); 8546 return false; 8547 } 8548 8549 return psoc_priv_obj->is_ext_tpc_supported; 8550 } 8551 8552 #if defined(CONFIG_BAND_6GHZ) 8553 QDF_STATUS 8554 reg_set_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc, bool val) 8555 { 8556 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8557 8558 psoc_priv_obj = reg_get_psoc_obj(psoc); 8559 8560 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8561 reg_err("psoc reg component is NULL"); 8562 return QDF_STATUS_E_FAILURE; 8563 } 8564 8565 psoc_priv_obj->is_lower_6g_edge_ch_supported = val; 8566 8567 return QDF_STATUS_SUCCESS; 8568 } 8569 8570 QDF_STATUS 8571 reg_set_disable_upper_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc, bool val) 8572 { 8573 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8574 8575 psoc_priv_obj = reg_get_psoc_obj(psoc); 8576 8577 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8578 reg_err("psoc reg component is NULL"); 8579 return QDF_STATUS_E_FAILURE; 8580 } 8581 8582 psoc_priv_obj->is_upper_6g_edge_ch_disabled = val; 8583 8584 return QDF_STATUS_SUCCESS; 8585 } 8586 8587 bool reg_is_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc) 8588 { 8589 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8590 8591 psoc_priv_obj = reg_get_psoc_obj(psoc); 8592 8593 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8594 reg_err("psoc reg component is NULL"); 8595 return false; 8596 } 8597 8598 return psoc_priv_obj->is_lower_6g_edge_ch_supported; 8599 } 8600 8601 bool reg_is_upper_6g_edge_ch_disabled(struct wlan_objmgr_psoc *psoc) 8602 { 8603 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8604 8605 psoc_priv_obj = reg_get_psoc_obj(psoc); 8606 8607 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8608 reg_err("psoc reg component is NULL"); 8609 return false; 8610 } 8611 8612 return psoc_priv_obj->is_upper_6g_edge_ch_disabled; 8613 } 8614 8615 static inline bool reg_is_within_range_inclusive(enum channel_enum left, 8616 enum channel_enum right, 8617 enum channel_enum idx) 8618 { 8619 return (idx >= left) && (idx <= right); 8620 } 8621 8622 uint16_t reg_convert_enum_to_6g_idx(enum channel_enum ch_idx) 8623 { 8624 if (!reg_is_within_range_inclusive(MIN_6GHZ_CHANNEL, 8625 MAX_6GHZ_CHANNEL, 8626 ch_idx)) 8627 return INVALID_CHANNEL; 8628 8629 return (ch_idx - MIN_6GHZ_CHANNEL); 8630 } 8631 8632 QDF_STATUS 8633 reg_get_superchan_entry(struct wlan_objmgr_pdev *pdev, 8634 enum channel_enum chan_enum, 8635 const struct super_chan_info **p_sup_chan_entry) 8636 { 8637 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8638 uint16_t sup_idx; 8639 8640 sup_idx = reg_convert_enum_to_6g_idx(chan_enum); 8641 8642 if (reg_is_chan_enum_invalid(sup_idx)) { 8643 reg_debug("super channel idx is invalid for the chan_enum %d", 8644 chan_enum); 8645 return QDF_STATUS_E_INVAL; 8646 } 8647 8648 pdev_priv_obj = reg_get_pdev_obj(pdev); 8649 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8650 reg_err_rl("pdev reg component is NULL"); 8651 return QDF_STATUS_E_INVAL; 8652 } 8653 8654 if (!p_sup_chan_entry) { 8655 reg_err_rl("p_sup_chan_entry is NULL"); 8656 return QDF_STATUS_E_INVAL; 8657 } 8658 8659 if (sup_idx >= NUM_6GHZ_CHANNELS) { 8660 reg_debug("sup_idx is out of bounds"); 8661 return QDF_STATUS_E_INVAL; 8662 } 8663 8664 *p_sup_chan_entry = &pdev_priv_obj->super_chan_list[sup_idx]; 8665 8666 return QDF_STATUS_SUCCESS; 8667 } 8668 #endif 8669 8670 #ifdef FEATURE_WLAN_CH_AVOID_EXT 8671 /** 8672 * reg_process_ch_avoid_freq_ext() - Update extended avoid frequencies in 8673 * psoc_priv_obj 8674 * @psoc: Pointer to psoc structure 8675 * @pdev: pointer to pdev object 8676 * 8677 * Return: None 8678 */ 8679 static QDF_STATUS 8680 reg_process_ch_avoid_freq_ext(struct wlan_objmgr_psoc *psoc, 8681 struct wlan_objmgr_pdev *pdev) 8682 { 8683 uint32_t i; 8684 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8685 uint8_t start_channel; 8686 uint8_t end_channel; 8687 int32_t txpower; 8688 bool is_valid_txpower; 8689 struct ch_avoid_freq_type *range; 8690 enum channel_enum ch_loop; 8691 enum channel_enum start_ch_idx; 8692 enum channel_enum end_ch_idx; 8693 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8694 uint32_t len; 8695 struct unsafe_ch_list *unsafe_ch_list; 8696 bool coex_unsafe_nb_user_prefer; 8697 8698 pdev_priv_obj = reg_get_pdev_obj(pdev); 8699 8700 if (!pdev_priv_obj) { 8701 reg_err("reg pdev private obj is NULL"); 8702 return QDF_STATUS_E_FAILURE; 8703 } 8704 psoc_priv_obj = reg_get_psoc_obj(psoc); 8705 if (!psoc_priv_obj) { 8706 reg_err("reg psoc private obj is NULL"); 8707 return QDF_STATUS_E_FAILURE; 8708 } 8709 8710 unsafe_ch_list = &psoc_priv_obj->unsafe_chan_list; 8711 coex_unsafe_nb_user_prefer = 8712 psoc_priv_obj->coex_unsafe_chan_nb_user_prefer; 8713 8714 if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt > 0) { 8715 len = sizeof(pdev_priv_obj->avoid_chan_ext_list.chan_freq_list); 8716 pdev_priv_obj->avoid_chan_ext_list.chan_cnt = 0; 8717 qdf_mem_zero(&pdev_priv_obj->avoid_chan_ext_list.chan_freq_list, 8718 len); 8719 } 8720 8721 if (unsafe_ch_list->chan_cnt > 0) { 8722 len = sizeof(unsafe_ch_list->chan_freq_list); 8723 unsafe_ch_list->chan_cnt = 0; 8724 qdf_mem_zero(unsafe_ch_list->chan_freq_list, len); 8725 } 8726 8727 for (i = 0; i < psoc_priv_obj->avoid_freq_ext_list.ch_avoid_range_cnt; 8728 i++) { 8729 if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt >= 8730 NUM_CHANNELS) { 8731 reg_debug("ext avoid channel list full"); 8732 break; 8733 } 8734 8735 if (unsafe_ch_list->chan_cnt >= NUM_CHANNELS) { 8736 reg_warn("LTE Coex unsafe channel list full"); 8737 break; 8738 } 8739 8740 start_ch_idx = INVALID_CHANNEL; 8741 end_ch_idx = INVALID_CHANNEL; 8742 range = &psoc_priv_obj->avoid_freq_ext_list.avoid_freq_range[i]; 8743 8744 start_channel = reg_freq_to_chan(pdev, range->start_freq); 8745 end_channel = reg_freq_to_chan(pdev, range->end_freq); 8746 txpower = range->txpower; 8747 is_valid_txpower = range->is_valid_txpower; 8748 8749 reg_debug("start: freq %d, ch %d, end: freq %d, ch %d txpower %d", 8750 range->start_freq, start_channel, range->end_freq, 8751 end_channel, txpower); 8752 8753 /* do not process frequency bands that are not mapped to 8754 * predefined channels 8755 */ 8756 if (start_channel == 0 || end_channel == 0) 8757 continue; 8758 8759 for (ch_loop = 0; ch_loop < NUM_CHANNELS; 8760 ch_loop++) { 8761 if (REG_CH_TO_FREQ(ch_loop) >= range->start_freq) { 8762 start_ch_idx = ch_loop; 8763 break; 8764 } 8765 } 8766 for (ch_loop = 0; ch_loop < NUM_CHANNELS; 8767 ch_loop++) { 8768 if (REG_CH_TO_FREQ(ch_loop) >= range->end_freq) { 8769 end_ch_idx = ch_loop; 8770 if (REG_CH_TO_FREQ(ch_loop) > range->end_freq) 8771 end_ch_idx--; 8772 break; 8773 } 8774 } 8775 8776 if (reg_is_chan_enum_invalid(start_ch_idx) || 8777 reg_is_chan_enum_invalid(end_ch_idx)) 8778 continue; 8779 8780 for (ch_loop = start_ch_idx; ch_loop <= end_ch_idx; 8781 ch_loop++) { 8782 pdev_priv_obj->avoid_chan_ext_list.chan_freq_list 8783 [pdev_priv_obj->avoid_chan_ext_list.chan_cnt++] = 8784 REG_CH_TO_FREQ(ch_loop); 8785 8786 if (coex_unsafe_nb_user_prefer) { 8787 if (unsafe_ch_list->chan_cnt >= 8788 NUM_CHANNELS) { 8789 reg_warn("LTECoex unsafe ch list full"); 8790 break; 8791 } 8792 unsafe_ch_list->txpower[ 8793 unsafe_ch_list->chan_cnt] = 8794 txpower; 8795 unsafe_ch_list->is_valid_txpower[ 8796 unsafe_ch_list->chan_cnt] = 8797 is_valid_txpower; 8798 unsafe_ch_list->chan_freq_list[ 8799 unsafe_ch_list->chan_cnt++] = 8800 REG_CH_TO_FREQ(ch_loop); 8801 } 8802 8803 if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt >= 8804 NUM_CHANNELS) { 8805 reg_debug("avoid freq ext list full"); 8806 break; 8807 } 8808 } 8809 /* if start == end for 5G, meanwhile it only have one valid 8810 * channel updated, then disable 20M by default around 8811 * this center freq. For example input [5805-5805], it 8812 * will disable 20Mhz around 5805, then the range change 8813 * to [5705-5815], otherwise, not sure about how many width 8814 * need to disabled for such case. 8815 */ 8816 if ((ch_loop - start_ch_idx) == 1 && 8817 (range->end_freq - range->start_freq == 0) && 8818 reg_is_5ghz_ch_freq(range->start_freq)) { 8819 range->start_freq = range->start_freq - HALF_20MHZ_BW; 8820 range->end_freq = range->end_freq + HALF_20MHZ_BW; 8821 } 8822 8823 for (ch_loop = 0; ch_loop < 8824 unsafe_ch_list->chan_cnt; ch_loop++) { 8825 if (ch_loop >= NUM_CHANNELS) 8826 break; 8827 reg_debug("Unsafe freq %d", 8828 unsafe_ch_list->chan_freq_list[ch_loop]); 8829 } 8830 } 8831 8832 return QDF_STATUS_SUCCESS; 8833 } 8834 8835 /** 8836 * reg_update_avoid_ch_ext() - Updates the current channel list that block out 8837 * by extended avoid frequency list 8838 * @psoc: Pointer to psoc structure 8839 * @object: Pointer to pdev structure 8840 * @arg: List of arguments 8841 * 8842 * Return: None 8843 */ 8844 static void 8845 reg_update_avoid_ch_ext(struct wlan_objmgr_psoc *psoc, 8846 void *object, void *arg) 8847 { 8848 struct wlan_objmgr_pdev *pdev = (struct wlan_objmgr_pdev *)object; 8849 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8850 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8851 QDF_STATUS status; 8852 8853 psoc_priv_obj = reg_get_psoc_obj(psoc); 8854 if (!psoc_priv_obj) { 8855 reg_err("reg psoc private obj is NULL"); 8856 return; 8857 } 8858 8859 pdev_priv_obj = reg_get_pdev_obj(pdev); 8860 8861 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8862 reg_err("reg pdev priv obj is NULL"); 8863 return; 8864 } 8865 8866 if (psoc_priv_obj->ch_avoid_ext_ind) { 8867 status = reg_process_ch_avoid_freq_ext(psoc, pdev); 8868 if (QDF_IS_STATUS_ERROR(status)) 8869 psoc_priv_obj->ch_avoid_ext_ind = false; 8870 } 8871 8872 reg_compute_pdev_current_chan_list(pdev_priv_obj); 8873 status = reg_send_scheduler_msg_sb(psoc, pdev); 8874 8875 if (QDF_IS_STATUS_ERROR(status)) 8876 reg_err("channel change msg schedule failed"); 8877 } 8878 8879 QDF_STATUS 8880 reg_process_ch_avoid_ext_event(struct wlan_objmgr_psoc *psoc, 8881 struct ch_avoid_ind_type *ch_avoid_event) 8882 { 8883 uint32_t i; 8884 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8885 QDF_STATUS status; 8886 struct ch_avoid_freq_type *range; 8887 8888 psoc_priv_obj = reg_get_psoc_obj(psoc); 8889 if (!psoc_priv_obj) { 8890 reg_err("reg psoc private obj is NULL"); 8891 return QDF_STATUS_E_FAILURE; 8892 } 8893 8894 reg_debug("freq range count %d", ch_avoid_event->ch_avoid_range_cnt); 8895 8896 qdf_mem_zero(&psoc_priv_obj->avoid_freq_ext_list, 8897 sizeof(struct ch_avoid_ind_type)); 8898 8899 for (i = 0; i < ch_avoid_event->ch_avoid_range_cnt; i++) { 8900 range = &psoc_priv_obj->avoid_freq_ext_list.avoid_freq_range[i]; 8901 range->start_freq = 8902 ch_avoid_event->avoid_freq_range[i].start_freq; 8903 range->end_freq = 8904 ch_avoid_event->avoid_freq_range[i].end_freq; 8905 range->txpower = 8906 ch_avoid_event->avoid_freq_range[i].txpower; 8907 range->is_valid_txpower = 8908 ch_avoid_event->avoid_freq_range[i].is_valid_txpower; 8909 } 8910 8911 psoc_priv_obj->avoid_freq_ext_list.restriction_mask = 8912 ch_avoid_event->restriction_mask; 8913 psoc_priv_obj->avoid_freq_ext_list.ch_avoid_range_cnt = 8914 ch_avoid_event->ch_avoid_range_cnt; 8915 8916 psoc_priv_obj->ch_avoid_ext_ind = true; 8917 8918 status = wlan_objmgr_psoc_try_get_ref(psoc, WLAN_REGULATORY_SB_ID); 8919 8920 if (QDF_IS_STATUS_ERROR(status)) { 8921 reg_err("error taking psoc ref cnt"); 8922 return status; 8923 } 8924 8925 status = wlan_objmgr_iterate_obj_list(psoc, WLAN_PDEV_OP, 8926 reg_update_avoid_ch_ext, 8927 NULL, 1, 8928 WLAN_REGULATORY_SB_ID); 8929 8930 wlan_objmgr_psoc_release_ref(psoc, WLAN_REGULATORY_SB_ID); 8931 8932 return status; 8933 } 8934 8935 bool reg_check_coex_unsafe_nb_user_prefer(struct wlan_objmgr_psoc *psoc) 8936 { 8937 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8938 8939 psoc_priv_obj = reg_get_psoc_obj(psoc); 8940 if (!psoc_priv_obj) { 8941 reg_err("reg psoc private obj is NULL"); 8942 return false; 8943 } 8944 8945 return psoc_priv_obj->coex_unsafe_chan_nb_user_prefer; 8946 } 8947 8948 bool reg_check_coex_unsafe_chan_reg_disable(struct wlan_objmgr_psoc *psoc) 8949 { 8950 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8951 8952 psoc_priv_obj = reg_get_psoc_obj(psoc); 8953 if (!psoc_priv_obj) { 8954 reg_err("reg psoc private obj is NULL"); 8955 return false; 8956 } 8957 8958 return psoc_priv_obj->coex_unsafe_chan_reg_disable; 8959 } 8960 #endif 8961 8962 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ) 8963 QDF_STATUS reg_send_afc_cmd(struct wlan_objmgr_pdev *pdev, 8964 struct reg_afc_resp_rx_ind_info *afc_ind_obj) 8965 { 8966 uint8_t pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 8967 struct wlan_objmgr_psoc *psoc; 8968 struct wlan_lmac_if_reg_tx_ops *tx_ops; 8969 8970 psoc = wlan_pdev_get_psoc(pdev); 8971 if (!psoc) { 8972 reg_err("psoc is NULL"); 8973 return QDF_STATUS_E_INVAL; 8974 } 8975 8976 tx_ops = reg_get_psoc_tx_ops(psoc); 8977 if (tx_ops->send_afc_ind) 8978 return tx_ops->send_afc_ind(psoc, pdev_id, afc_ind_obj); 8979 8980 return QDF_STATUS_E_FAILURE; 8981 } 8982 8983 bool reg_is_afc_power_event_received(struct wlan_objmgr_pdev *pdev) 8984 { 8985 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8986 8987 pdev_priv_obj = reg_get_pdev_obj(pdev); 8988 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8989 reg_err("pdev reg component is NULL"); 8990 return false; 8991 } 8992 8993 return pdev_priv_obj->is_6g_afc_power_event_received; 8994 } 8995 8996 bool reg_is_afc_done(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 8997 { 8998 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8999 uint32_t chan_flags; 9000 9001 pdev_priv_obj = reg_get_pdev_obj(pdev); 9002 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9003 reg_err("pdev reg component is NULL"); 9004 return false; 9005 } 9006 9007 chan_flags = reg_get_channel_flags_for_freq(pdev, freq); 9008 9009 return !(chan_flags & REGULATORY_CHAN_AFC_NOT_DONE); 9010 } 9011 9012 QDF_STATUS reg_get_afc_req_id(struct wlan_objmgr_pdev *pdev, uint64_t *req_id) 9013 { 9014 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9015 9016 pdev_priv_obj = reg_get_pdev_obj(pdev); 9017 9018 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9019 reg_err("reg pdev priv obj is NULL"); 9020 return QDF_STATUS_E_FAILURE; 9021 } 9022 9023 *req_id = pdev_priv_obj->afc_request_id; 9024 9025 return QDF_STATUS_SUCCESS; 9026 } 9027 9028 bool reg_is_afc_expiry_event_received(struct wlan_objmgr_pdev *pdev) 9029 { 9030 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9031 9032 pdev_priv_obj = reg_get_pdev_obj(pdev); 9033 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9034 reg_err("pdev reg component is NULL"); 9035 return false; 9036 } 9037 9038 return pdev_priv_obj->is_6g_afc_expiry_event_received; 9039 } 9040 9041 bool reg_is_noaction_on_afc_pwr_evt(struct wlan_objmgr_pdev *pdev) 9042 { 9043 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9044 9045 pdev_priv_obj = reg_get_pdev_obj(pdev); 9046 9047 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9048 reg_err("reg pdev priv obj is NULL"); 9049 return QDF_STATUS_E_FAILURE; 9050 } 9051 9052 return pdev_priv_obj->is_reg_noaction_on_afc_pwr_evt; 9053 } 9054 #endif 9055 9056 /** 9057 * struct bw_wireless_modes_pair - structure containing bandwidth and wireless 9058 * modes corresponding to the bandwidth 9059 * @ch_width: channel width 9060 * @wireless_modes: wireless modes bitmap corresponding to @ch_width. This 9061 * bitmap is a combination of enum values HOST_REGDMN_MODE 9062 */ 9063 struct bw_wireless_modes_pair { 9064 enum phy_ch_width ch_width; 9065 uint64_t wireless_modes; 9066 }; 9067 9068 /* Mapping of bandwidth to wireless modes */ 9069 static const struct bw_wireless_modes_pair bw_wireless_modes_pair_map[] = { 9070 #ifdef WLAN_FEATURE_11BE 9071 {CH_WIDTH_320MHZ, WIRELESS_320_MODES}, 9072 #endif 9073 {CH_WIDTH_80P80MHZ, WIRELESS_80P80_MODES}, 9074 {CH_WIDTH_160MHZ, WIRELESS_160_MODES}, 9075 {CH_WIDTH_80MHZ, WIRELESS_80_MODES}, 9076 {CH_WIDTH_40MHZ, WIRELESS_40_MODES}, 9077 {CH_WIDTH_20MHZ, WIRELESS_20_MODES}, 9078 {CH_WIDTH_10MHZ, WIRELESS_10_MODES}, 9079 {CH_WIDTH_5MHZ, WIRELESS_5_MODES}, 9080 }; 9081 9082 QDF_STATUS reg_is_chwidth_supported(struct wlan_objmgr_pdev *pdev, 9083 enum phy_ch_width ch_width, 9084 bool *is_supported) 9085 { 9086 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9087 uint64_t wireless_modes; 9088 uint8_t num_bws, idx; 9089 9090 pdev_priv_obj = reg_get_pdev_obj(pdev); 9091 9092 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9093 reg_err("reg pdev priv obj is NULL"); 9094 return QDF_STATUS_E_FAILURE; 9095 } 9096 9097 *is_supported = false; 9098 9099 wireless_modes = pdev_priv_obj->wireless_modes; 9100 num_bws = QDF_ARRAY_SIZE(bw_wireless_modes_pair_map); 9101 9102 for (idx = 0; idx < num_bws; ++idx) { 9103 if (bw_wireless_modes_pair_map[idx].ch_width == ch_width) { 9104 *is_supported = !!(wireless_modes & 9105 bw_wireless_modes_pair_map[idx].wireless_modes); 9106 break; 9107 } 9108 } 9109 9110 return QDF_STATUS_SUCCESS; 9111 } 9112 9113 bool reg_is_state_allowed(enum channel_state chan_state) 9114 { 9115 return !((chan_state == CHANNEL_STATE_INVALID) || 9116 (chan_state == CHANNEL_STATE_DISABLE)); 9117 } 9118 9119 static bool 9120 reg_is_freq_idx_enabled_on_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 9121 *pdev_priv_obj, 9122 enum channel_enum freq_idx) 9123 { 9124 struct regulatory_channel *cur_chan_list; 9125 9126 if (freq_idx >= NUM_CHANNELS) 9127 return false; 9128 9129 cur_chan_list = pdev_priv_obj->cur_chan_list; 9130 9131 return !reg_is_chan_disabled_and_not_nol(&cur_chan_list[freq_idx]); 9132 } 9133 9134 static QDF_STATUS 9135 reg_get_min_max_bw_on_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 9136 *pdev_priv_obj, 9137 enum channel_enum freq_idx, 9138 uint16_t *min_bw, 9139 uint16_t *max_bw) 9140 { 9141 struct regulatory_channel *cur_chan_list; 9142 9143 if (freq_idx >= NUM_CHANNELS) 9144 return QDF_STATUS_E_FAILURE; 9145 9146 cur_chan_list = pdev_priv_obj->cur_chan_list; 9147 if (min_bw) 9148 *min_bw = cur_chan_list[freq_idx].min_bw; 9149 if (max_bw) 9150 *max_bw = cur_chan_list[freq_idx].max_bw; 9151 9152 return QDF_STATUS_SUCCESS; 9153 } 9154 9155 static enum channel_state 9156 reg_get_chan_state_on_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 9157 *pdev_priv_obj, 9158 enum channel_enum freq_idx) 9159 { 9160 struct regulatory_channel *cur_chan_list; 9161 enum channel_state chan_state; 9162 9163 if (freq_idx >= NUM_CHANNELS) 9164 return CHANNEL_STATE_INVALID; 9165 9166 cur_chan_list = pdev_priv_obj->cur_chan_list; 9167 chan_state = cur_chan_list[freq_idx].state; 9168 9169 return chan_state; 9170 } 9171 9172 static enum channel_state 9173 reg_get_chan_state_based_on_nol_flag_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 9174 *pdev_priv_obj, 9175 enum channel_enum freq_idx) 9176 { 9177 struct regulatory_channel *cur_chan_list; 9178 enum channel_state chan_state; 9179 9180 if (freq_idx >= NUM_CHANNELS) 9181 return CHANNEL_STATE_INVALID; 9182 9183 cur_chan_list = pdev_priv_obj->cur_chan_list; 9184 chan_state = cur_chan_list[freq_idx].state; 9185 9186 if ((cur_chan_list[freq_idx].nol_chan || 9187 cur_chan_list[freq_idx].nol_history) && 9188 chan_state == CHANNEL_STATE_DISABLE) 9189 chan_state = CHANNEL_STATE_DFS; 9190 9191 return chan_state; 9192 } 9193 9194 #ifdef CONFIG_BAND_6GHZ 9195 static inline bool 9196 reg_is_supr_entry_mode_disabled(const struct super_chan_info *super_chan_ent, 9197 enum supported_6g_pwr_types in_6g_pwr_mode) 9198 { 9199 return ((super_chan_ent->chan_flags_arr[in_6g_pwr_mode] & 9200 REGULATORY_CHAN_DISABLED) && 9201 super_chan_ent->state_arr[in_6g_pwr_mode] == 9202 CHANNEL_STATE_DISABLE); 9203 } 9204 9205 static bool 9206 reg_is_freq_idx_enabled_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 9207 *pdev_priv_obj, 9208 enum channel_enum freq_idx, 9209 enum supported_6g_pwr_types 9210 in_6g_pwr_mode) 9211 { 9212 const struct super_chan_info *super_chan_ent; 9213 QDF_STATUS status; 9214 9215 if (freq_idx >= NUM_CHANNELS) 9216 return false; 9217 9218 if (freq_idx < MIN_6GHZ_CHANNEL) 9219 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 9220 freq_idx); 9221 9222 status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx, 9223 &super_chan_ent); 9224 if (QDF_IS_STATUS_ERROR(status)) { 9225 reg_debug("Failed to get super channel entry for freq_idx %d", 9226 freq_idx); 9227 return false; 9228 } 9229 9230 /* If the input 6G power mode is best power mode, get the best power 9231 * mode type from the super channel entry. 9232 */ 9233 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 9234 in_6g_pwr_mode = super_chan_ent->best_power_mode; 9235 9236 return !reg_is_supr_entry_mode_disabled(super_chan_ent, in_6g_pwr_mode); 9237 } 9238 9239 static QDF_STATUS 9240 reg_get_min_max_bw_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 9241 *pdev_priv_obj, 9242 enum channel_enum freq_idx, 9243 enum supported_6g_pwr_types 9244 in_6g_pwr_mode, 9245 uint16_t *min_bw, 9246 uint16_t *max_bw) 9247 { 9248 const struct super_chan_info *super_chan_ent; 9249 QDF_STATUS status; 9250 9251 if (freq_idx >= NUM_CHANNELS) 9252 return QDF_STATUS_E_FAILURE; 9253 9254 if (freq_idx < MIN_6GHZ_CHANNEL) 9255 return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj, 9256 freq_idx, 9257 min_bw, max_bw); 9258 9259 status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx, 9260 &super_chan_ent); 9261 if (QDF_IS_STATUS_ERROR(status)) { 9262 reg_debug("Failed to get super channel entry for freq_idx %d", 9263 freq_idx); 9264 return QDF_STATUS_E_FAILURE; 9265 } 9266 9267 /* If the input 6G power mode is best power mode, get the best power 9268 * mode type from the super channel entry. 9269 */ 9270 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 9271 in_6g_pwr_mode = super_chan_ent->best_power_mode; 9272 9273 if (reg_is_supp_pwr_mode_invalid(in_6g_pwr_mode)) { 9274 reg_debug("pwr_type invalid"); 9275 return QDF_STATUS_E_FAILURE; 9276 } 9277 9278 if (min_bw) 9279 *min_bw = super_chan_ent->min_bw[in_6g_pwr_mode]; 9280 if (max_bw) 9281 *max_bw = super_chan_ent->max_bw[in_6g_pwr_mode]; 9282 9283 return QDF_STATUS_SUCCESS; 9284 } 9285 9286 static enum channel_state 9287 reg_get_chan_state_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 9288 *pdev_priv_obj, 9289 enum channel_enum freq_idx, 9290 enum supported_6g_pwr_types 9291 in_6g_pwr_mode) 9292 { 9293 const struct super_chan_info *super_chan_ent; 9294 enum channel_state chan_state; 9295 QDF_STATUS status; 9296 9297 if (freq_idx >= NUM_CHANNELS) 9298 return CHANNEL_STATE_INVALID; 9299 9300 if (freq_idx < MIN_6GHZ_CHANNEL) 9301 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 9302 freq_idx); 9303 9304 status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx, 9305 &super_chan_ent); 9306 if (QDF_IS_STATUS_ERROR(status)) { 9307 reg_debug("Failed to get super channel entry for freq_idx %d", 9308 freq_idx); 9309 return CHANNEL_STATE_INVALID; 9310 } 9311 9312 /* If the input 6G power mode is best power mode, get the best power 9313 * mode type from the super channel entry. 9314 */ 9315 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 9316 in_6g_pwr_mode = super_chan_ent->best_power_mode; 9317 9318 if (reg_is_supp_pwr_mode_invalid(in_6g_pwr_mode)) { 9319 reg_debug("pwr_type invalid"); 9320 return CHANNEL_STATE_INVALID; 9321 } 9322 9323 chan_state = super_chan_ent->state_arr[in_6g_pwr_mode]; 9324 9325 return chan_state; 9326 } 9327 9328 enum supported_6g_pwr_types 9329 reg_get_best_6g_pwr_type(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 9330 { 9331 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9332 enum channel_enum freq_idx; 9333 enum channel_enum sixg_freq_idx; 9334 9335 pdev_priv_obj = reg_get_pdev_obj(pdev); 9336 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9337 reg_err_rl("pdev reg component is NULL"); 9338 return REG_INVALID_PWR_MODE; 9339 } 9340 9341 freq_idx = reg_get_chan_enum_for_freq(freq); 9342 9343 if (reg_is_chan_enum_invalid(freq_idx)) 9344 return REG_INVALID_PWR_MODE; 9345 9346 sixg_freq_idx = reg_convert_enum_to_6g_idx(freq_idx); 9347 if (reg_is_chan_enum_invalid(sixg_freq_idx) || 9348 sixg_freq_idx >= NUM_6GHZ_CHANNELS) 9349 return REG_INVALID_PWR_MODE; 9350 9351 return pdev_priv_obj->super_chan_list[sixg_freq_idx].best_power_mode; 9352 } 9353 9354 static inline bool reg_is_6g_ap_type_invalid(enum reg_6g_ap_type ap_pwr_type) 9355 { 9356 return ((ap_pwr_type < REG_INDOOR_AP) || 9357 (ap_pwr_type > REG_MAX_SUPP_AP_TYPE)); 9358 } 9359 9360 enum supported_6g_pwr_types 9361 reg_conv_6g_ap_type_to_supported_6g_pwr_types(enum reg_6g_ap_type ap_pwr_type) 9362 { 9363 static const enum supported_6g_pwr_types reg_enum_conv[] = { 9364 [REG_INDOOR_AP] = REG_AP_LPI, 9365 [REG_STANDARD_POWER_AP] = REG_AP_SP, 9366 [REG_VERY_LOW_POWER_AP] = REG_AP_VLP, 9367 }; 9368 9369 if (reg_is_6g_ap_type_invalid(ap_pwr_type)) 9370 return REG_INVALID_PWR_MODE; 9371 9372 return reg_enum_conv[ap_pwr_type]; 9373 } 9374 #else 9375 static inline bool 9376 reg_is_freq_idx_enabled_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 9377 *pdev_priv_obj, 9378 enum channel_enum freq_idx, 9379 enum supported_6g_pwr_types 9380 in_6g_pwr_mode) 9381 { 9382 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 9383 freq_idx); 9384 } 9385 9386 static inline QDF_STATUS 9387 reg_get_min_max_bw_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 9388 *pdev_priv_obj, 9389 enum channel_enum freq_idx, 9390 enum supported_6g_pwr_types 9391 in_6g_pwr_mode, 9392 uint16_t *min_bw, 9393 uint16_t *max_bw) 9394 { 9395 return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj, 9396 freq_idx, 9397 min_bw, max_bw); 9398 } 9399 9400 static inline enum channel_state 9401 reg_get_chan_state_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 9402 *pdev_priv_obj, 9403 enum channel_enum freq_idx, 9404 enum supported_6g_pwr_types 9405 in_6g_pwr_mode) 9406 { 9407 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 9408 freq_idx); 9409 } 9410 #endif /* CONFIG_BAND_6GHZ */ 9411 9412 bool 9413 reg_is_freq_enabled(struct wlan_objmgr_pdev *pdev, 9414 qdf_freq_t freq, 9415 enum supported_6g_pwr_types in_6g_pwr_mode) 9416 { 9417 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9418 enum channel_enum freq_idx; 9419 9420 pdev_priv_obj = reg_get_pdev_obj(pdev); 9421 9422 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9423 reg_err("reg pdev private obj is NULL"); 9424 return false; 9425 } 9426 9427 freq_idx = reg_get_chan_enum_for_freq(freq); 9428 9429 if (reg_is_chan_enum_invalid(freq_idx)) 9430 return false; 9431 9432 return reg_is_freq_idx_enabled(pdev, freq_idx, in_6g_pwr_mode); 9433 } 9434 9435 bool reg_is_freq_idx_enabled(struct wlan_objmgr_pdev *pdev, 9436 enum channel_enum freq_idx, 9437 enum supported_6g_pwr_types in_6g_pwr_mode) 9438 { 9439 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9440 9441 pdev_priv_obj = reg_get_pdev_obj(pdev); 9442 9443 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9444 reg_err("reg pdev private obj is NULL"); 9445 return false; 9446 } 9447 9448 if (freq_idx < MIN_6GHZ_CHANNEL) 9449 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 9450 freq_idx); 9451 9452 switch (in_6g_pwr_mode) { 9453 case REG_CURRENT_PWR_MODE: 9454 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 9455 freq_idx); 9456 9457 case REG_BEST_PWR_MODE: 9458 default: 9459 return reg_is_freq_idx_enabled_on_given_pwr_mode(pdev_priv_obj, 9460 freq_idx, 9461 in_6g_pwr_mode 9462 ); 9463 } 9464 } 9465 9466 QDF_STATUS reg_get_min_max_bw_reg_chan_list(struct wlan_objmgr_pdev *pdev, 9467 enum channel_enum freq_idx, 9468 enum supported_6g_pwr_types 9469 in_6g_pwr_mode, 9470 uint16_t *min_bw, 9471 uint16_t *max_bw) 9472 { 9473 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9474 9475 pdev_priv_obj = reg_get_pdev_obj(pdev); 9476 9477 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9478 reg_err("reg pdev private obj is NULL"); 9479 return QDF_STATUS_E_FAILURE; 9480 } 9481 9482 if (freq_idx < MIN_6GHZ_CHANNEL) 9483 return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj, 9484 freq_idx, 9485 min_bw, max_bw); 9486 9487 switch (in_6g_pwr_mode) { 9488 case REG_CURRENT_PWR_MODE: 9489 return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj, 9490 freq_idx, 9491 min_bw, max_bw); 9492 9493 case REG_BEST_PWR_MODE: 9494 default: 9495 return reg_get_min_max_bw_on_given_pwr_mode(pdev_priv_obj, 9496 freq_idx, 9497 in_6g_pwr_mode, 9498 min_bw, max_bw); 9499 } 9500 } 9501 9502 enum channel_state reg_get_chan_state(struct wlan_objmgr_pdev *pdev, 9503 enum channel_enum freq_idx, 9504 enum supported_6g_pwr_types 9505 in_6g_pwr_mode, 9506 bool treat_nol_chan_as_disabled) 9507 { 9508 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9509 9510 pdev_priv_obj = reg_get_pdev_obj(pdev); 9511 9512 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9513 reg_err("reg pdev private obj is NULL"); 9514 return CHANNEL_STATE_INVALID; 9515 } 9516 9517 if (freq_idx < MIN_6GHZ_CHANNEL) { 9518 if (treat_nol_chan_as_disabled) 9519 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 9520 freq_idx); 9521 else 9522 return reg_get_chan_state_based_on_nol_flag_cur_chan_list( 9523 pdev_priv_obj, 9524 freq_idx); 9525 } 9526 9527 switch (in_6g_pwr_mode) { 9528 case REG_CURRENT_PWR_MODE: 9529 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 9530 freq_idx); 9531 9532 case REG_BEST_PWR_MODE: 9533 default: 9534 return reg_get_chan_state_on_given_pwr_mode(pdev_priv_obj, 9535 freq_idx, 9536 in_6g_pwr_mode 9537 ); 9538 } 9539 } 9540 9541 #ifdef WLAN_FEATURE_11BE 9542 enum phy_ch_width reg_find_chwidth_from_bw(uint16_t bw) 9543 { 9544 switch (bw) { 9545 case BW_5_MHZ: 9546 return CH_WIDTH_5MHZ; 9547 case BW_10_MHZ: 9548 return CH_WIDTH_10MHZ; 9549 case BW_20_MHZ: 9550 return CH_WIDTH_20MHZ; 9551 case BW_40_MHZ: 9552 return CH_WIDTH_40MHZ; 9553 case BW_80_MHZ: 9554 return CH_WIDTH_80MHZ; 9555 case BW_160_MHZ: 9556 return CH_WIDTH_160MHZ; 9557 case BW_320_MHZ: 9558 return CH_WIDTH_320MHZ; 9559 default: 9560 return CH_WIDTH_INVALID; 9561 } 9562 } 9563 #else 9564 enum phy_ch_width reg_find_chwidth_from_bw(uint16_t bw) 9565 { 9566 switch (bw) { 9567 case BW_5_MHZ: 9568 return CH_WIDTH_5MHZ; 9569 case BW_10_MHZ: 9570 return CH_WIDTH_10MHZ; 9571 case BW_20_MHZ: 9572 return CH_WIDTH_20MHZ; 9573 case BW_40_MHZ: 9574 return CH_WIDTH_40MHZ; 9575 case BW_80_MHZ: 9576 return CH_WIDTH_80MHZ; 9577 case BW_160_MHZ: 9578 return CH_WIDTH_160MHZ; 9579 default: 9580 return CH_WIDTH_INVALID; 9581 } 9582 } 9583 #endif 9584 9585 #ifdef CONFIG_BAND_6GHZ 9586 qdf_freq_t reg_get_thresh_priority_freq(struct wlan_objmgr_pdev *pdev) 9587 { 9588 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9589 9590 pdev_priv_obj = reg_get_pdev_obj(pdev); 9591 9592 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9593 reg_err("reg pdev private obj is NULL"); 9594 return 0; 9595 } 9596 9597 return pdev_priv_obj->reg_6g_thresh_priority_freq; 9598 } 9599 9600 /** 9601 * reg_get_eirp_from_psd_and_reg_max_eirp() - Get the EIRP by the computing the 9602 * minimum(max regulatory EIRP, EIRP computed from regulatory PSD) 9603 * @pdev: Pointer to pdev 9604 * @master_chan_list: Pointer to master_chan_list 9605 * @freq: Frequency in mhz 9606 * @bw: Bandwidth in mhz 9607 * @reg_eirp_pwr: Pointer to reg_eirp_pwr 9608 * 9609 * Return: Void 9610 */ 9611 static void 9612 reg_get_eirp_from_psd_and_reg_max_eirp(struct wlan_objmgr_pdev *pdev, 9613 struct regulatory_channel *mas_chan_list, 9614 qdf_freq_t freq, 9615 uint16_t bw, 9616 uint16_t *reg_eirp_pwr) 9617 { 9618 int16_t eirp_from_psd = 0, psd = 0; 9619 9620 reg_get_6g_chan_psd_eirp_power(freq, mas_chan_list, &psd); 9621 reg_psd_2_eirp(pdev, psd, bw, &eirp_from_psd); 9622 *reg_eirp_pwr = QDF_MIN(*reg_eirp_pwr, eirp_from_psd); 9623 } 9624 9625 /** 9626 * reg_get_mas_chan_list_for_lookup() - Get the AP or client master_chan_list 9627 * based on the is_client_list_lookup_needed flag 9628 * @pdev: Pointer to pdev 9629 * @master_chan_list: Pointer to master_chan_list 9630 * @ap_pwr_type: AP Power type 9631 * @is_client_list_lookup_needed: Boolean to indicate if client list lookup is 9632 * needed 9633 * @client_type: Client power type 9634 * 9635 * Return: Void 9636 */ 9637 static void 9638 reg_get_mas_chan_list_for_lookup(struct wlan_objmgr_pdev *pdev, 9639 struct regulatory_channel **master_chan_list, 9640 enum reg_6g_ap_type ap_pwr_type, 9641 bool is_client_list_lookup_needed, 9642 enum reg_6g_client_type client_type) 9643 { 9644 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9645 9646 pdev_priv_obj = reg_get_pdev_obj(pdev); 9647 if (!pdev_priv_obj) { 9648 reg_err("pdev priv obj is NULL"); 9649 return; 9650 } 9651 9652 if (client_type > REG_MAX_CLIENT_TYPE) { 9653 reg_err("Invalid client type"); 9654 return; 9655 } 9656 9657 if (is_client_list_lookup_needed) 9658 *master_chan_list = 9659 pdev_priv_obj->mas_chan_list_6g_client[ap_pwr_type] 9660 [client_type]; 9661 else 9662 *master_chan_list = 9663 pdev_priv_obj->mas_chan_list_6g_ap[ap_pwr_type]; 9664 } 9665 9666 /** 9667 * reg_get_eirp_for_non_sp() - For the given power mode, using the bandwidth 9668 * and psd(from master channel entry), calculate an EIRP value. The minimum 9669 * of calculated EIRP and regulatory max EIRP is returned. 9670 * @pdev: Pointer to pdev 9671 * @freq: Frequency in mhz 9672 * @bw: Bandwidth in mhz 9673 * @ap_pwr_type: AP Power type 9674 * @is_client_list_lookup_needed: Boolean to indicate if client list lookup is 9675 * needed 9676 * @client_type: Client power type 9677 * 9678 * Return: EIRP 9679 */ 9680 static uint8_t 9681 reg_get_eirp_for_non_sp(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq, 9682 uint16_t bw, enum reg_6g_ap_type ap_pwr_type, 9683 bool is_client_list_lookup_needed, 9684 enum reg_6g_client_type client_type) 9685 { 9686 bool is_psd; 9687 struct regulatory_channel *master_chan_list = NULL; 9688 uint16_t txpower = 0; 9689 9690 if (!((ap_pwr_type == REG_INDOOR_AP) || 9691 (ap_pwr_type == REG_VERY_LOW_POWER_AP))) { 9692 reg_err("Only LPI and VLP are supported in this function "); 9693 return 0; 9694 } 9695 9696 reg_get_mas_chan_list_for_lookup(pdev, &master_chan_list, ap_pwr_type, 9697 is_client_list_lookup_needed, 9698 client_type); 9699 if (!master_chan_list) { 9700 reg_err("master_chan_list is NULL"); 9701 return 0; 9702 } 9703 9704 is_psd = reg_is_6g_psd_power(pdev); 9705 reg_find_txpower_from_6g_list(freq, master_chan_list, &txpower); 9706 9707 if (is_psd) 9708 reg_get_eirp_from_psd_and_reg_max_eirp(pdev, 9709 master_chan_list, 9710 freq, bw, 9711 &txpower); 9712 9713 return txpower; 9714 } 9715 9716 #ifdef CONFIG_AFC_SUPPORT 9717 /** 9718 * reg_compute_6g_center_freq_from_cfi() - Given the IEEE value of the 9719 * 6 GHz center frequency, find the 6 GHz center frequency. 9720 * @ieee_6g_cfi: IEEE value of 6 GHz cfi 9721 * Return: Center frequency in MHz 9722 */ 9723 static qdf_freq_t 9724 reg_compute_6g_center_freq_from_cfi(uint8_t ieee_6g_cfi) 9725 { 9726 return (SIXG_START_FREQ + ieee_6g_cfi * FREQ_TO_CHAN_SCALE); 9727 } 9728 9729 #ifdef WLAN_FEATURE_11BE 9730 /** 9731 * reg_is_320_opclass: Find out if the opclass computed from freq and 9732 * width of 320 is same as the input op_class. 9733 * @freq: Frequency in MHz 9734 * @in_opclass: Input Opclass number 9735 * Return: true if opclass is 320 supported, false otherwise. 9736 */ 9737 static bool reg_is_320_opclass(qdf_freq_t freq, uint8_t in_opclass) 9738 { 9739 uint8_t local_op_class = 9740 reg_dmn_get_opclass_from_freq_width(NULL, freq, BW_320_MHZ, 9741 BIT(BEHAV_NONE)); 9742 return (in_opclass == local_op_class); 9743 } 9744 #else 9745 static inline bool reg_is_320_opclass(qdf_freq_t freq, uint8_t op_class) 9746 { 9747 return false; 9748 } 9749 #endif 9750 9751 /** 9752 * reg_find_eirp_in_afc_eirp_obj() - Get eirp power from the AFC eirp object 9753 * based on the channel center frequency and operating class 9754 * @pdev: Pointer to pdev 9755 * @eirp_obj: Pointer to eirp_obj 9756 * @freq: Frequency in MHz 9757 * @cen320: 320 MHz band center frequency 9758 * @op_class: Operating class 9759 * 9760 * Return: EIRP power 9761 */ 9762 static uint8_t reg_find_eirp_in_afc_eirp_obj(struct wlan_objmgr_pdev *pdev, 9763 struct chan_eirp_obj *eirp_obj, 9764 qdf_freq_t freq, 9765 qdf_freq_t cen320, 9766 uint8_t op_class) 9767 { 9768 uint8_t k; 9769 uint8_t subchannels[NUM_20_MHZ_CHAN_IN_320_MHZ_CHAN]; 9770 uint8_t nchans; 9771 9772 if (reg_is_320_opclass(freq, op_class)) { 9773 qdf_freq_t cfi_freq = 9774 reg_compute_6g_center_freq_from_cfi(eirp_obj->cfi); 9775 9776 if (cfi_freq == cen320) 9777 return eirp_obj->eirp_power / EIRP_PWR_SCALE; 9778 9779 return 0; 9780 } 9781 9782 nchans = reg_get_subchannels_for_opclass(eirp_obj->cfi, 9783 op_class, 9784 subchannels); 9785 9786 for (k = 0; k < nchans; k++) 9787 if (reg_chan_band_to_freq(pdev, subchannels[k], 9788 BIT(REG_BAND_6G)) == freq) 9789 return eirp_obj->eirp_power / EIRP_PWR_SCALE; 9790 9791 return 0; 9792 } 9793 9794 /** 9795 * reg_find_eirp_in_afc_chan_obj() - Get eirp power from the AFC channel 9796 * object based on the channel center frequency and operating class 9797 * @pdev: Pointer to pdev 9798 * @chan_obj: Pointer to chan_obj 9799 * @freq: Frequency in MHz 9800 * @cen320: 320 MHz band center frequency 9801 * @op_class: Operating class 9802 * 9803 * Return: EIRP power 9804 */ 9805 static uint8_t reg_find_eirp_in_afc_chan_obj(struct wlan_objmgr_pdev *pdev, 9806 struct afc_chan_obj *chan_obj, 9807 qdf_freq_t freq, 9808 qdf_freq_t cen320, 9809 uint8_t op_class) 9810 { 9811 uint8_t j; 9812 9813 if (chan_obj->global_opclass != op_class) 9814 return 0; 9815 9816 for (j = 0; j < chan_obj->num_chans; j++) { 9817 uint8_t afc_eirp; 9818 struct chan_eirp_obj *eirp_obj = &chan_obj->chan_eirp_info[j]; 9819 9820 afc_eirp = reg_find_eirp_in_afc_eirp_obj(pdev, eirp_obj, 9821 freq, cen320, 9822 op_class); 9823 9824 if (afc_eirp) 9825 return afc_eirp; 9826 } 9827 9828 return 0; 9829 } 9830 9831 /** 9832 * reg_is_chan_punc() - Validates the input puncture pattern. 9833 * @in_punc_pattern: Input puncture pattern 9834 * @bw: Channel bandwidth in MHz 9835 * 9836 * If the in_punc_pattern has none of the subchans punctured, channel 9837 * is not considered as punctured. Also, if the input puncture bitmap 9838 * is invalid, do not consider the channel as punctured. 9839 * 9840 * Return: true if channel is punctured, false otherwise. 9841 */ 9842 #ifdef WLAN_FEATURE_11BE 9843 static bool 9844 reg_is_chan_punc(uint16_t in_punc_pattern, uint16_t bw) 9845 { 9846 enum phy_ch_width ch_width = reg_find_chwidth_from_bw(bw); 9847 9848 if (in_punc_pattern == NO_SCHANS_PUNC || 9849 !reg_is_punc_bitmap_valid(ch_width, in_punc_pattern)) 9850 return false; 9851 9852 return true; 9853 } 9854 #else 9855 static inline bool 9856 reg_is_chan_punc(uint16_t in_punc_pattern, uint16_t bw) 9857 { 9858 return false; 9859 } 9860 #endif 9861 9862 /** 9863 * reg_find_non_punctured_bw() - Given the input puncture pattern and the 9864 * total BW of the channel, find the non-punctured bandwidth. 9865 * @bw: Total bandwidth of the channel 9866 * @in_punc_pattern: Input puncture pattern 9867 * 9868 * Return: non-punctured bw in MHz 9869 */ 9870 static uint16_t 9871 reg_find_non_punctured_bw(uint16_t bw, uint16_t in_punc_pattern) 9872 { 9873 uint8_t num_punc_bw = 0; 9874 9875 while (in_punc_pattern) { 9876 if (in_punc_pattern & 1) 9877 ++num_punc_bw; 9878 in_punc_pattern >>= 1; 9879 } 9880 9881 if (bw <= num_punc_bw * 20) 9882 return 0; 9883 9884 return (bw - num_punc_bw * 20); 9885 } 9886 9887 /** 9888 * reg_get_sp_eirp_for_punc_chans() - Find the standard EIRP power for 9889 * punctured channels. 9890 * @pdev: Pointer to struct wlan_objmgr_pdev 9891 * @freq: Frequency in MHz 9892 * @cen320: Center of 320 MHz channel in Mhz 9893 * @bw: Bandwidth in MHz 9894 * @in_punc_pattern: Input puncture pattern 9895 * @reg_sp_eirp_pwr: Regulatory defined SP power for the input frequency 9896 * 9897 * Return: Regulatory and AFC intersected SP power of punctured channel 9898 */ 9899 static uint8_t 9900 reg_get_sp_eirp_for_punc_chans(struct wlan_objmgr_pdev *pdev, 9901 qdf_freq_t freq, 9902 qdf_freq_t cen320, 9903 uint16_t bw, 9904 uint16_t in_punc_pattern, 9905 uint16_t reg_sp_eirp_pwr) 9906 { 9907 int16_t min_psd = 0; 9908 uint16_t afc_eirp_pwr = 0; 9909 uint16_t non_punc_bw; 9910 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 9911 struct wlan_objmgr_psoc *psoc; 9912 QDF_STATUS status; 9913 9914 psoc = wlan_pdev_get_psoc(pdev); 9915 9916 if (!psoc) 9917 return 0; 9918 9919 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 9920 9921 if (!reg_tx_ops->reg_get_min_psd) 9922 return 0; 9923 9924 /* min_psd will be calculated here */ 9925 status = reg_tx_ops->reg_get_min_psd(pdev, freq, cen320, 9926 in_punc_pattern, bw, 9927 &min_psd); 9928 if (status != QDF_STATUS_SUCCESS) { 9929 reg_debug("Could not derive min_psd power for width %u, freq; %d, cen320: %d, in_punc: 0x%x\n", 9930 bw, freq, cen320, in_punc_pattern); 9931 return 0; 9932 } 9933 9934 non_punc_bw = reg_find_non_punctured_bw(bw, in_punc_pattern); 9935 9936 if (reg_psd_2_eirp(pdev, min_psd, non_punc_bw, &afc_eirp_pwr) != 9937 QDF_STATUS_SUCCESS) { 9938 reg_debug("Could not derive EIRP power for width %u, min_psd: %d\n", non_punc_bw, min_psd); 9939 return 0; 9940 } 9941 9942 reg_debug("freq = %u, bw: %u, cen320: %u, punc_pattern: 0x%x " 9943 "reg_sp_eirp: %d, min_psd: %d, non_punc_bw: %u, afc_eirp_pwr: %d\n", 9944 freq, bw, cen320, in_punc_pattern, reg_sp_eirp_pwr, min_psd, 9945 non_punc_bw, afc_eirp_pwr); 9946 9947 if (afc_eirp_pwr) 9948 return QDF_MIN(afc_eirp_pwr, reg_sp_eirp_pwr); 9949 9950 return 0; 9951 } 9952 9953 /** 9954 * reg_get_sp_eirp() - For the given power mode, using the bandwidth, find the 9955 * corresponding EIRP values from the afc power info array. The minimum of found 9956 * EIRP and regulatory max EIRP is returned 9957 * @pdev: Pointer to pdev 9958 * @freq: Frequency in MHz 9959 * @cen320: 320 MHz band center frequency 9960 * @bw: Bandwidth in MHz 9961 * @in_punc_pattern: Input puncture pattern 9962 * @is_client_list_lookup_needed: Boolean to indicate if client list lookup is 9963 * needed 9964 * @client_type: Client power type 9965 * 9966 * Return: EIRP 9967 */ 9968 static uint8_t reg_get_sp_eirp(struct wlan_objmgr_pdev *pdev, 9969 qdf_freq_t freq, 9970 qdf_freq_t cen320, 9971 uint16_t bw, 9972 uint16_t in_punc_pattern, 9973 bool is_client_list_lookup_needed, 9974 enum reg_6g_client_type client_type) 9975 { 9976 uint8_t i, op_class = 0, chan_num = 0, afc_eirp_pwr = 0; 9977 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9978 struct regulatory_channel *sp_master_chan_list = NULL; 9979 struct reg_fw_afc_power_event *power_info; 9980 uint16_t reg_sp_eirp_pwr = 0; 9981 bool is_psd; 9982 9983 pdev_priv_obj = reg_get_pdev_obj(pdev); 9984 9985 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9986 reg_err("reg pdev priv obj is NULL"); 9987 return 0; 9988 } 9989 9990 if (!reg_is_afc_power_event_received(pdev)) 9991 return 0; 9992 9993 sp_master_chan_list = 9994 pdev_priv_obj->mas_chan_list_6g_ap[REG_STANDARD_POWER_AP]; 9995 reg_find_txpower_from_6g_list(freq, sp_master_chan_list, 9996 ®_sp_eirp_pwr); 9997 9998 if (!reg_sp_eirp_pwr) 9999 return 0; 10000 10001 if (reg_is_chan_punc(in_punc_pattern, bw)) { 10002 reg_info("Computing SP EIRP with puncturing info"); 10003 return reg_get_sp_eirp_for_punc_chans(pdev, freq, cen320, bw, 10004 in_punc_pattern, 10005 reg_sp_eirp_pwr); 10006 } 10007 10008 power_info = pdev_priv_obj->power_info; 10009 if (!power_info) { 10010 reg_err("power_info is NULL"); 10011 return 0; 10012 } 10013 10014 reg_freq_width_to_chan_op_class(pdev, 10015 freq, 10016 bw, 10017 true, 10018 BIT(BEHAV_NONE), 10019 &op_class, 10020 &chan_num); 10021 reg_get_mas_chan_list_for_lookup(pdev, &sp_master_chan_list, 10022 REG_STANDARD_POWER_AP, 10023 is_client_list_lookup_needed, 10024 client_type); 10025 if (!sp_master_chan_list) { 10026 reg_err("sp_master_chan_list is NULL"); 10027 return 0; 10028 } 10029 10030 reg_find_txpower_from_6g_list(freq, sp_master_chan_list, 10031 ®_sp_eirp_pwr); 10032 10033 if (!reg_sp_eirp_pwr) 10034 return 0; 10035 10036 for (i = 0; i < power_info->num_chan_objs; i++) { 10037 struct afc_chan_obj *chan_obj = &power_info->afc_chan_info[i]; 10038 10039 afc_eirp_pwr = reg_find_eirp_in_afc_chan_obj(pdev, 10040 chan_obj, 10041 freq, 10042 cen320, 10043 op_class); 10044 if (afc_eirp_pwr) 10045 break; 10046 } 10047 10048 is_psd = reg_is_6g_psd_power(pdev); 10049 if (is_psd) 10050 reg_get_eirp_from_psd_and_reg_max_eirp(pdev, 10051 sp_master_chan_list, 10052 freq, bw, 10053 ®_sp_eirp_pwr); 10054 10055 if (afc_eirp_pwr) 10056 return QDF_MIN(afc_eirp_pwr, reg_sp_eirp_pwr); 10057 10058 return 0; 10059 } 10060 #else 10061 static uint8_t reg_get_sp_eirp(struct wlan_objmgr_pdev *pdev, 10062 qdf_freq_t freq, 10063 qdf_freq_t cen320, 10064 uint16_t bw, 10065 uint16_t in_punc_pattern, 10066 bool is_client_list_lookup_needed, 10067 enum reg_6g_client_type client_type) 10068 { 10069 struct regulatory_channel *sp_master_chan_list = NULL; 10070 uint16_t reg_sp_eirp_pwr = 0; 10071 bool is_psd; 10072 10073 reg_get_mas_chan_list_for_lookup(pdev, &sp_master_chan_list, 10074 REG_STANDARD_POWER_AP, 10075 is_client_list_lookup_needed, 10076 client_type); 10077 if (!sp_master_chan_list) { 10078 reg_err("sp_master_chan_list is NULL"); 10079 return 0; 10080 } 10081 10082 reg_find_txpower_from_6g_list(freq, sp_master_chan_list, 10083 ®_sp_eirp_pwr); 10084 is_psd = reg_is_6g_psd_power(pdev); 10085 if (is_psd) 10086 reg_get_eirp_from_psd_and_reg_max_eirp(pdev, 10087 sp_master_chan_list, 10088 freq, bw, 10089 ®_sp_eirp_pwr); 10090 10091 return reg_sp_eirp_pwr; 10092 } 10093 #endif 10094 10095 /** 10096 * reg_get_best_pwr_mode_from_eirp_list() - Get best power mode from the input 10097 * EIRP list 10098 * @eirp_list: EIRP list 10099 * @size: Size of eirp list 10100 * 10101 * Return: Best power mode 10102 */ 10103 static enum reg_6g_ap_type 10104 reg_get_best_pwr_mode_from_eirp_list(uint8_t *eirp_list, uint8_t size) 10105 { 10106 uint8_t max = 0, i; 10107 enum reg_6g_ap_type best_pwr_mode = REG_INDOOR_AP; 10108 10109 for (i = 0; i < size; i++) { 10110 if (eirp_list[i] > max) { 10111 max = eirp_list[i]; 10112 best_pwr_mode = i; 10113 } 10114 } 10115 10116 return best_pwr_mode; 10117 } 10118 10119 uint8_t reg_get_eirp_pwr(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq, 10120 qdf_freq_t cen320, 10121 uint16_t bw, enum reg_6g_ap_type ap_pwr_type, 10122 uint16_t in_punc_pattern, 10123 bool is_client_list_lookup_needed, 10124 enum reg_6g_client_type client_type) 10125 { 10126 if (ap_pwr_type == REG_STANDARD_POWER_AP) 10127 return reg_get_sp_eirp(pdev, freq, cen320, bw, in_punc_pattern, 10128 is_client_list_lookup_needed, 10129 client_type); 10130 10131 return reg_get_eirp_for_non_sp(pdev, freq, bw, ap_pwr_type, 10132 is_client_list_lookup_needed, 10133 client_type); 10134 } 10135 10136 enum reg_6g_ap_type reg_get_best_pwr_mode(struct wlan_objmgr_pdev *pdev, 10137 qdf_freq_t freq, 10138 qdf_freq_t cen320, 10139 uint16_t bw, 10140 uint16_t in_punc_pattern) 10141 { 10142 uint8_t eirp_list[REG_MAX_SUPP_AP_TYPE + 1]; 10143 enum reg_6g_ap_type ap_pwr_type; 10144 10145 for (ap_pwr_type = REG_INDOOR_AP; ap_pwr_type <= REG_VERY_LOW_POWER_AP; 10146 ap_pwr_type++) 10147 eirp_list[ap_pwr_type] = 10148 reg_get_eirp_pwr(pdev, freq, cen320, bw, 10149 ap_pwr_type, in_punc_pattern, 10150 false, 10151 REG_MAX_CLIENT_TYPE); 10152 10153 return reg_get_best_pwr_mode_from_eirp_list(eirp_list, 10154 REG_MAX_SUPP_AP_TYPE + 1); 10155 } 10156 #endif 10157 10158 QDF_STATUS reg_get_regd_rules(struct wlan_objmgr_pdev *pdev, 10159 struct reg_rule_info *reg_rules) 10160 { 10161 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 10162 10163 if (!pdev) { 10164 reg_err("pdev is NULL"); 10165 return QDF_STATUS_E_FAILURE; 10166 } 10167 10168 pdev_priv_obj = reg_get_pdev_obj(pdev); 10169 if (!pdev_priv_obj) { 10170 reg_err("pdev priv obj is NULL"); 10171 return QDF_STATUS_E_FAILURE; 10172 } 10173 10174 qdf_spin_lock_bh(&pdev_priv_obj->reg_rules_lock); 10175 qdf_mem_copy(reg_rules, &pdev_priv_obj->reg_rules, 10176 sizeof(struct reg_rule_info)); 10177 qdf_spin_unlock_bh(&pdev_priv_obj->reg_rules_lock); 10178 10179 return QDF_STATUS_SUCCESS; 10180 } 10181 10182 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ) 10183 bool 10184 reg_is_sup_chan_entry_afc_done(struct wlan_objmgr_pdev *pdev, 10185 enum channel_enum chan_idx, 10186 enum supported_6g_pwr_types in_6g_pwr_mode) 10187 { 10188 const struct super_chan_info *super_chan_ent; 10189 QDF_STATUS status; 10190 10191 status = reg_get_superchan_entry(pdev, chan_idx, 10192 &super_chan_ent); 10193 if (QDF_IS_STATUS_ERROR(status)) { 10194 reg_debug("Failed to get super channel entry for chan_idx %d", 10195 chan_idx); 10196 return false; 10197 } 10198 10199 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 10200 in_6g_pwr_mode = super_chan_ent->best_power_mode; 10201 10202 if (in_6g_pwr_mode != REG_AP_SP) 10203 return false; 10204 10205 return !(super_chan_ent->chan_flags_arr[in_6g_pwr_mode] & 10206 REGULATORY_CHAN_AFC_NOT_DONE); 10207 } 10208 10209 bool 10210 reg_is_6ghz_freq_txable(struct wlan_objmgr_pdev *pdev, 10211 qdf_freq_t freq, 10212 enum supported_6g_pwr_types in_6ghz_pwr_mode) 10213 { 10214 bool is_freq_enabled; 10215 enum reg_afc_dev_deploy_type reg_afc_deploy_type; 10216 10217 is_freq_enabled = reg_is_freq_enabled(pdev, freq, in_6ghz_pwr_mode); 10218 if (!is_freq_enabled) 10219 return false; 10220 10221 reg_get_afc_dev_deploy_type(pdev, ®_afc_deploy_type); 10222 10223 return (reg_afc_deploy_type != AFC_DEPLOYMENT_OUTDOOR) || 10224 reg_is_afc_done(pdev, freq); 10225 } 10226 #endif 10227 10228 #ifdef CONFIG_BAND_6GHZ 10229 QDF_STATUS 10230 reg_display_super_chan_list(struct wlan_objmgr_pdev *pdev) 10231 { 10232 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 10233 struct super_chan_info *super_chan_list; 10234 uint8_t i; 10235 10236 pdev_priv_obj = reg_get_pdev_obj(pdev); 10237 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 10238 reg_err_rl("pdev reg component is NULL"); 10239 return QDF_STATUS_E_FAILURE; 10240 } 10241 10242 super_chan_list = pdev_priv_obj->super_chan_list; 10243 for (i = 0; i < NUM_6GHZ_CHANNELS; i++) { 10244 struct super_chan_info *chan_info = &super_chan_list[i]; 10245 struct regulatory_channel cur_chan_list = 10246 pdev_priv_obj->cur_chan_list[MIN_6GHZ_CHANNEL + i]; 10247 uint8_t j; 10248 10249 qdf_print("Freq = %d\tPower types = 0x%x\t" 10250 "Best power mode = 0x%x\n", 10251 cur_chan_list.center_freq, chan_info->power_types, 10252 chan_info->best_power_mode); 10253 for (j = REG_AP_LPI; j <= REG_CLI_SUB_VLP; j++) { 10254 bool afc_not_done_bit; 10255 10256 afc_not_done_bit = chan_info->chan_flags_arr[j] & 10257 REGULATORY_CHAN_AFC_NOT_DONE; 10258 qdf_print("Power mode = %d\tPSD flag = %d\t" 10259 "PSD power = %d\tEIRP power = %d\t" 10260 "Chan flags = 0x%x\tChannel state = %d\t" 10261 "Min bw = %d\tMax bw = %d\t" 10262 "AFC_NOT_DONE = %d\n", 10263 j, chan_info->reg_chan_pwr[j].psd_flag, 10264 chan_info->reg_chan_pwr[j].psd_eirp, 10265 chan_info->reg_chan_pwr[j].tx_power, 10266 chan_info->chan_flags_arr[j], 10267 chan_info->state_arr[j], 10268 chan_info->min_bw[j], chan_info->max_bw[j], 10269 afc_not_done_bit); 10270 } 10271 } 10272 10273 return QDF_STATUS_SUCCESS; 10274 } 10275 10276 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ) 10277 QDF_STATUS 10278 reg_get_afc_freq_range_and_psd_limits(struct wlan_objmgr_pdev *pdev, 10279 uint8_t num_freq_obj, 10280 struct afc_freq_obj *afc_freq_info) 10281 { 10282 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 10283 struct reg_fw_afc_power_event *power_info; 10284 uint8_t i; 10285 10286 pdev_priv_obj = reg_get_pdev_obj(pdev); 10287 10288 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 10289 reg_err("reg pdev priv obj is NULL"); 10290 return QDF_STATUS_E_FAILURE; 10291 } 10292 10293 if (!reg_is_afc_power_event_received(pdev)) { 10294 reg_err("afc power event is not received\n"); 10295 return QDF_STATUS_E_FAILURE; 10296 } 10297 10298 power_info = pdev_priv_obj->power_info; 10299 if (!power_info) { 10300 reg_err("power_info is NULL"); 10301 return QDF_STATUS_E_FAILURE; 10302 } 10303 10304 if (!num_freq_obj) { 10305 reg_err("num freq objs cannot be zero"); 10306 return QDF_STATUS_E_FAILURE; 10307 } 10308 10309 if (!afc_freq_info) 10310 return QDF_STATUS_E_FAILURE; 10311 10312 for (i = 0; i < num_freq_obj; i++) { 10313 struct afc_freq_obj *reg_afc_info = 10314 &power_info->afc_freq_info[i]; 10315 10316 afc_freq_info[i].low_freq = reg_afc_info->low_freq; 10317 afc_freq_info[i].high_freq = reg_afc_info->high_freq; 10318 afc_freq_info[i].max_psd = reg_afc_info->max_psd; 10319 } 10320 return QDF_STATUS_SUCCESS; 10321 } 10322 10323 QDF_STATUS 10324 reg_get_num_afc_freq_obj(struct wlan_objmgr_pdev *pdev, uint8_t *num_freq_obj) 10325 { 10326 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 10327 struct reg_fw_afc_power_event *power_info; 10328 10329 pdev_priv_obj = reg_get_pdev_obj(pdev); 10330 10331 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 10332 reg_err("reg pdev priv obj is NULL"); 10333 return QDF_STATUS_E_FAILURE; 10334 } 10335 10336 if (!reg_is_afc_power_event_received(pdev)) { 10337 reg_err("afc power event is not received\n"); 10338 return QDF_STATUS_E_FAILURE; 10339 } 10340 10341 power_info = pdev_priv_obj->power_info; 10342 if (!power_info) { 10343 reg_err("power_info is NULL"); 10344 return QDF_STATUS_E_FAILURE; 10345 } 10346 10347 if (!power_info->num_freq_objs) { 10348 reg_err("num freq objs cannot be zero"); 10349 return QDF_STATUS_E_FAILURE; 10350 } 10351 10352 *num_freq_obj = power_info->num_freq_objs; 10353 10354 return QDF_STATUS_SUCCESS; 10355 } 10356 #endif 10357 10358 #endif 10359 10360 #ifdef CONFIG_AFC_SUPPORT 10361 QDF_STATUS reg_set_afc_power_event_received(struct wlan_objmgr_pdev *pdev, 10362 bool val) 10363 { 10364 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 10365 10366 pdev_priv_obj = reg_get_pdev_obj(pdev); 10367 if (!pdev_priv_obj) { 10368 reg_err("pdev priv obj is NULL"); 10369 return QDF_STATUS_E_FAILURE; 10370 } 10371 pdev_priv_obj->is_6g_afc_power_event_received = val; 10372 10373 return QDF_STATUS_SUCCESS; 10374 } 10375 #endif 10376