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