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: Left 80MHz punctured */ 290 0x3f, 291 0xcf, 292 0x30f, 293 0xc0f, 294 0x300f, 295 0xc00f, 296 /* 80+40Mhz puncturing pattern: Right 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 (reg_is_chan_enum_invalid(min_chan_range) || 1653 reg_is_chan_enum_invalid(max_chan_range)) { 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 (reg_is_chan_enum_invalid(min_chan_range) || 1743 reg_is_chan_enum_invalid(max_chan_range)) 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 (reg_is_chan_enum_invalid(chan_enum)) { 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 (reg_is_chan_enum_invalid(chan_enum)) { 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 && index < NUM_CHANNELS; 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_debug("avoid freq %d", 3799 chan_list[chan_enum].center_freq); 3800 reg_remove_freq(res_msg, chan_enum); 3801 } 3802 } 3803 } 3804 if (req_msg.iface_mode_mask & 1 << IFTYPE_AP || 3805 req_msg.iface_mode_mask & 1 << IFTYPE_P2P_GO || 3806 req_msg.iface_mode_mask & 1 << IFTYPE_NAN) 3807 status = 3808 reg_skip_invalid_chan_freq(pdev, res_msg, count, 3809 req_msg.iface_mode_mask); 3810 return status; 3811 } 3812 3813 /** 3814 * reg_calculate_mode_mask() - calculate valid mode mask 3815 * @iface_mode_mask: interface mode mask 3816 * 3817 * Return: Valid mode mask 3818 */ 3819 static uint32_t 3820 reg_calculate_mode_mask(uint32_t iface_mode_mask) 3821 { 3822 int mode_mask = 0; 3823 3824 mode_mask = (iface_mode_mask & 1 << IFTYPE_STATION) | 3825 (iface_mode_mask & 1 << IFTYPE_AP) | 3826 (iface_mode_mask & 1 << IFTYPE_P2P_GO) | 3827 (iface_mode_mask & 1 << IFTYPE_P2P_CLIENT) | 3828 (iface_mode_mask & 1 << IFTYPE_P2P_DEVICE) | 3829 (iface_mode_mask & 1 << IFTYPE_NAN); 3830 3831 return mode_mask; 3832 } 3833 3834 /** 3835 * reg_add_usable_channel_to_resp() - Add usable channels to resp structure 3836 * @pdev: Pointer to pdev 3837 * @res_msg: Response msg 3838 * @iface_mode_mask: interface mode mask 3839 * @chan_list: reg channel list 3840 * @count: no of usable channels 3841 * 3842 * Return: qdf status 3843 */ 3844 static QDF_STATUS 3845 reg_add_usable_channel_to_resp(struct wlan_objmgr_pdev *pdev, 3846 struct get_usable_chan_res_params *res_msg, 3847 uint32_t iface_mode_mask, 3848 struct regulatory_channel *chan_list, 3849 int *count) 3850 { 3851 enum channel_enum chan_enum; 3852 struct ch_params ch_params = {0}; 3853 QDF_STATUS status = QDF_STATUS_SUCCESS; 3854 uint32_t mode_mask = 0; 3855 3856 mode_mask = reg_calculate_mode_mask(iface_mode_mask); 3857 3858 for (chan_enum = 0; chan_enum < *count && 3859 chan_enum < NUM_CHANNELS; chan_enum++) { 3860 ch_params.ch_width = CH_WIDTH_MAX; 3861 reg_set_channel_params_for_freq( 3862 pdev, 3863 chan_list[chan_enum].center_freq, 3864 chan_list[chan_enum].max_bw, &ch_params, true); 3865 3866 res_msg[chan_enum].freq = chan_list[chan_enum].center_freq; 3867 res_msg[chan_enum].iface_mode_mask = mode_mask; 3868 if (!res_msg[chan_enum].iface_mode_mask) { 3869 reg_err("invalid iface mask"); 3870 return QDF_STATUS_E_FAILURE; 3871 } 3872 res_msg[chan_enum].bw = ch_params.ch_width; 3873 res_msg[chan_enum].state = chan_list[chan_enum].state; 3874 if (ch_params.center_freq_seg0) 3875 res_msg[chan_enum].seg0_freq = 3876 ch_params.center_freq_seg0; 3877 if (ch_params.center_freq_seg1) 3878 res_msg[chan_enum].seg1_freq = 3879 ch_params.center_freq_seg1; 3880 } 3881 3882 return status; 3883 } 3884 3885 QDF_STATUS 3886 wlan_reg_get_usable_channel(struct wlan_objmgr_pdev *pdev, 3887 struct get_usable_chan_req_params req_msg, 3888 struct get_usable_chan_res_params *res_msg, 3889 uint32_t *usable_channels) 3890 { 3891 struct regulatory_channel *chan_list; 3892 QDF_STATUS status = QDF_STATUS_SUCCESS; 3893 3894 chan_list = qdf_mem_malloc(NUM_CHANNELS * 3895 sizeof(*chan_list)); 3896 3897 if (!chan_list) { 3898 reg_err("chan_list invalid"); 3899 return QDF_STATUS_E_FAILURE; 3900 } 3901 3902 if ((req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX) || 3903 (!(req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX) && 3904 !(req_msg.filter_mask & 1 << FILTER_WLAN_CONCURRENCY))) { 3905 *usable_channels = reg_get_band_channel_list(pdev, 3906 req_msg.band_mask, 3907 chan_list); 3908 status = 3909 reg_add_usable_channel_to_resp(pdev, res_msg, 3910 req_msg.iface_mode_mask, 3911 chan_list, usable_channels); 3912 if (QDF_IS_STATUS_ERROR(status)) { 3913 qdf_mem_free(chan_list); 3914 return status; 3915 } 3916 } 3917 3918 if (req_msg.filter_mask & 1 << FILTER_WLAN_CONCURRENCY) 3919 status = 3920 reg_get_usable_channel_con_filter(pdev, req_msg, res_msg, 3921 usable_channels); 3922 3923 if (req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX) 3924 status = 3925 reg_get_usable_channel_coex_filter(pdev, req_msg, res_msg, 3926 chan_list, usable_channels); 3927 if (!(req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX) && 3928 !(req_msg.filter_mask & 1 << FILTER_WLAN_CONCURRENCY)) 3929 status = 3930 reg_get_usable_channel_no_filter(pdev, req_msg, res_msg, 3931 chan_list, usable_channels); 3932 reg_debug("usable chan count is %d", *usable_channels); 3933 3934 qdf_mem_free(chan_list); 3935 return status; 3936 } 3937 #endif 3938 3939 enum channel_state reg_get_channel_state_for_freq(struct wlan_objmgr_pdev *pdev, 3940 qdf_freq_t freq) 3941 { 3942 enum channel_enum ch_idx; 3943 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 3944 3945 ch_idx = reg_get_chan_enum_for_freq(freq); 3946 3947 if (reg_is_chan_enum_invalid(ch_idx)) 3948 return CHANNEL_STATE_INVALID; 3949 3950 pdev_priv_obj = reg_get_pdev_obj(pdev); 3951 3952 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 3953 reg_err("pdev reg obj is NULL"); 3954 return CHANNEL_STATE_INVALID; 3955 } 3956 3957 return pdev_priv_obj->cur_chan_list[ch_idx].state; 3958 } 3959 3960 /** 3961 * reg_get_nol_channel_state () - Get channel state from regulatory 3962 * and treat NOL channels as enabled channels 3963 * @pdev: Pointer to pdev 3964 * @freq: channel center frequency. 3965 * 3966 * Return: channel state 3967 */ 3968 static enum channel_state 3969 reg_get_nol_channel_state(struct wlan_objmgr_pdev *pdev, 3970 qdf_freq_t freq, 3971 enum supported_6g_pwr_types in_6g_pwr_mode) 3972 { 3973 enum channel_enum ch_idx; 3974 enum channel_state chan_state; 3975 3976 ch_idx = reg_get_chan_enum_for_freq(freq); 3977 3978 if (reg_is_chan_enum_invalid(ch_idx)) 3979 return CHANNEL_STATE_INVALID; 3980 3981 chan_state = reg_get_chan_state(pdev, ch_idx, in_6g_pwr_mode, false); 3982 3983 return chan_state; 3984 } 3985 3986 /** 3987 * reg_get_5g_bonded_chan_state()- Return the channel state for a 3988 * 5G or 6G channel frequency based on the bonded channel. 3989 * @pdev: Pointer to pdev. 3990 * @freq: Channel center frequency. 3991 * @bonded_chan_ptr: Pointer to bonded_channel_freq. 3992 * 3993 * Return: Channel State 3994 */ 3995 static enum channel_state 3996 reg_get_5g_bonded_chan_state(struct wlan_objmgr_pdev *pdev, 3997 uint16_t freq, 3998 const struct bonded_channel_freq *bonded_chan_ptr, 3999 enum supported_6g_pwr_types in_6g_pwr_mode) 4000 { 4001 uint16_t chan_cfreq; 4002 enum channel_state chan_state = CHANNEL_STATE_INVALID; 4003 enum channel_state temp_chan_state; 4004 4005 chan_cfreq = bonded_chan_ptr->start_freq; 4006 while (chan_cfreq <= bonded_chan_ptr->end_freq) { 4007 temp_chan_state = reg_get_nol_channel_state(pdev, chan_cfreq, 4008 in_6g_pwr_mode); 4009 if (temp_chan_state < chan_state) 4010 chan_state = temp_chan_state; 4011 chan_cfreq = chan_cfreq + 20; 4012 } 4013 4014 return chan_state; 4015 } 4016 4017 enum channel_state 4018 reg_get_5g_chan_state(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq, 4019 enum phy_ch_width bw, 4020 enum supported_6g_pwr_types in_6g_pwr_mode) 4021 { 4022 enum channel_enum ch_indx; 4023 enum channel_state chan_state; 4024 bool bw_enabled = false; 4025 const struct bonded_channel_freq *bonded_chan_ptr = NULL; 4026 uint16_t min_bw, max_bw; 4027 4028 if (bw > CH_WIDTH_80P80MHZ) { 4029 reg_err_rl("bw passed is not good"); 4030 return CHANNEL_STATE_INVALID; 4031 } 4032 4033 if (bw == CH_WIDTH_20MHZ) 4034 return reg_get_nol_channel_state(pdev, freq, in_6g_pwr_mode); 4035 4036 /* Fetch the bonded_chan_ptr for width greater than 20MHZ. */ 4037 bonded_chan_ptr = reg_get_bonded_chan_entry(freq, bw, 0); 4038 4039 if (!bonded_chan_ptr) 4040 return CHANNEL_STATE_INVALID; 4041 4042 chan_state = reg_get_5g_bonded_chan_state(pdev, freq, bonded_chan_ptr, 4043 in_6g_pwr_mode); 4044 4045 if ((chan_state == CHANNEL_STATE_INVALID) || 4046 (chan_state == CHANNEL_STATE_DISABLE)) 4047 return chan_state; 4048 4049 ch_indx = reg_get_chan_enum_for_freq(freq); 4050 if (reg_is_chan_enum_invalid(ch_indx)) 4051 return CHANNEL_STATE_INVALID; 4052 4053 if (reg_get_min_max_bw_reg_chan_list(pdev, ch_indx, in_6g_pwr_mode, 4054 &min_bw, &max_bw)) { 4055 return CHANNEL_STATE_INVALID; 4056 } 4057 4058 if (bw == CH_WIDTH_5MHZ) 4059 bw_enabled = true; 4060 else if (bw == CH_WIDTH_10MHZ) 4061 bw_enabled = (min_bw <= 10) && 4062 (max_bw >= 10); 4063 else if (bw == CH_WIDTH_20MHZ) 4064 bw_enabled = (min_bw <= 20) && 4065 (max_bw >= 20); 4066 else if (bw == CH_WIDTH_40MHZ) 4067 bw_enabled = (min_bw <= 40) && 4068 (max_bw >= 40); 4069 else if (bw == CH_WIDTH_80MHZ) 4070 bw_enabled = (min_bw <= 80) && 4071 (max_bw >= 80); 4072 else if (bw == CH_WIDTH_160MHZ) 4073 bw_enabled = (min_bw <= 160) && 4074 (max_bw >= 160); 4075 else if (bw == CH_WIDTH_80P80MHZ) 4076 bw_enabled = (min_bw <= 80) && 4077 (max_bw >= 80); 4078 4079 if (bw_enabled) 4080 return chan_state; 4081 else 4082 return CHANNEL_STATE_DISABLE; 4083 } 4084 4085 enum channel_state 4086 reg_get_ch_state_based_on_nol_flag(struct wlan_objmgr_pdev *pdev, 4087 qdf_freq_t freq, 4088 struct ch_params *ch_params, 4089 enum supported_6g_pwr_types 4090 in_6g_pwr_mode, 4091 bool treat_nol_chan_as_disabled) 4092 { 4093 if (treat_nol_chan_as_disabled) 4094 return wlan_reg_get_5g_bonded_channel_state_for_pwrmode(pdev, 4095 freq, 4096 ch_params, 4097 in_6g_pwr_mode); 4098 4099 return reg_get_5g_chan_state(pdev, freq, ch_params->ch_width, 4100 in_6g_pwr_mode); 4101 } 4102 4103 #ifdef WLAN_FEATURE_11BE 4104 bool reg_is_ch_width_320(enum phy_ch_width ch_width) 4105 { 4106 if (ch_width == CH_WIDTH_320MHZ) 4107 return true; 4108 return false; 4109 } 4110 #else 4111 bool reg_is_ch_width_320(enum phy_ch_width ch_width) 4112 { 4113 return false; 4114 } 4115 #endif 4116 4117 #ifdef CONFIG_REG_6G_PWRMODE 4118 enum channel_state 4119 reg_get_channel_state_for_pwrmode(struct wlan_objmgr_pdev *pdev, 4120 qdf_freq_t freq, 4121 enum supported_6g_pwr_types in_6g_pwr_type) 4122 { 4123 enum channel_enum ch_idx; 4124 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4125 enum channel_state state; 4126 4127 ch_idx = reg_get_chan_enum_for_freq(freq); 4128 4129 if (reg_is_chan_enum_invalid(ch_idx)) 4130 return CHANNEL_STATE_INVALID; 4131 4132 pdev_priv_obj = reg_get_pdev_obj(pdev); 4133 4134 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4135 reg_err("pdev reg obj is NULL"); 4136 return CHANNEL_STATE_INVALID; 4137 } 4138 4139 state = reg_get_chan_state(pdev, ch_idx, in_6g_pwr_type, true); 4140 return state; 4141 } 4142 #endif 4143 4144 static uint32_t reg_get_channel_flags_for_freq(struct wlan_objmgr_pdev *pdev, 4145 qdf_freq_t freq) 4146 { 4147 enum channel_enum chan_enum; 4148 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4149 4150 chan_enum = reg_get_chan_enum_for_freq(freq); 4151 4152 if (reg_is_chan_enum_invalid(chan_enum)) { 4153 reg_err("chan freq is not valid"); 4154 return REGULATORY_CHAN_INVALID; 4155 } 4156 4157 pdev_priv_obj = reg_get_pdev_obj(pdev); 4158 4159 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4160 reg_err("pdev reg obj is NULL"); 4161 return REGULATORY_CHAN_INVALID; 4162 } 4163 4164 return pdev_priv_obj->cur_chan_list[chan_enum].chan_flags; 4165 } 4166 4167 #ifdef CONFIG_REG_CLIENT 4168 enum channel_state reg_get_channel_state_from_secondary_list_for_freq( 4169 struct wlan_objmgr_pdev *pdev, 4170 qdf_freq_t freq) 4171 { 4172 enum channel_enum ch_idx; 4173 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4174 4175 ch_idx = reg_get_chan_enum_for_freq(freq); 4176 4177 if (reg_is_chan_enum_invalid(ch_idx)) 4178 return CHANNEL_STATE_INVALID; 4179 4180 pdev_priv_obj = reg_get_pdev_obj(pdev); 4181 4182 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4183 reg_err("pdev reg obj is NULL"); 4184 return CHANNEL_STATE_INVALID; 4185 } 4186 4187 return pdev_priv_obj->secondary_cur_chan_list[ch_idx].state; 4188 } 4189 4190 static uint32_t reg_get_channel_flags_from_secondary_list_for_freq( 4191 struct wlan_objmgr_pdev *pdev, 4192 qdf_freq_t freq) 4193 { 4194 enum channel_enum chan_enum; 4195 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4196 4197 chan_enum = reg_get_chan_enum_for_freq(freq); 4198 4199 if (reg_is_chan_enum_invalid(chan_enum)) { 4200 reg_err_rl("chan freq %u is not valid", freq); 4201 return REGULATORY_CHAN_INVALID; 4202 } 4203 4204 pdev_priv_obj = reg_get_pdev_obj(pdev); 4205 4206 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4207 reg_err("pdev reg obj is NULL"); 4208 return REGULATORY_CHAN_INVALID; 4209 } 4210 4211 return pdev_priv_obj->secondary_cur_chan_list[chan_enum].chan_flags; 4212 } 4213 #endif 4214 4215 /** 4216 * reg_get_5g_bonded_chan_array_for_freq()- Return the channel state for a 4217 * 5G or 6G channel frequency based on the bonded channel. 4218 * @pdev: Pointer to pdev. 4219 * @freq: Channel center frequency. 4220 * @bonded_chan_ptr: Pointer to bonded_channel_freq. 4221 * 4222 * Return: Channel State 4223 */ 4224 static enum channel_state 4225 reg_get_5g_bonded_chan_array_for_freq(struct wlan_objmgr_pdev *pdev, 4226 uint16_t freq, 4227 const struct bonded_channel_freq * 4228 bonded_chan_ptr) 4229 { 4230 uint16_t chan_cfreq; 4231 enum channel_state chan_state = CHANNEL_STATE_INVALID; 4232 enum channel_state temp_chan_state; 4233 4234 if (!bonded_chan_ptr) { 4235 reg_debug("bonded chan ptr is NULL"); 4236 return chan_state; 4237 } 4238 4239 chan_cfreq = bonded_chan_ptr->start_freq; 4240 while (chan_cfreq <= bonded_chan_ptr->end_freq) { 4241 temp_chan_state = reg_get_channel_state_for_freq(pdev, 4242 chan_cfreq); 4243 if (temp_chan_state < chan_state) 4244 chan_state = temp_chan_state; 4245 chan_cfreq = chan_cfreq + 20; 4246 } 4247 4248 return chan_state; 4249 } 4250 4251 #ifdef CONFIG_REG_6G_PWRMODE 4252 /** 4253 * reg_get_5g_bonded_chan_array_for_pwrmode()- Return the channel state for a 4254 * 5G or 6G channel frequency based on the bonded channel. 4255 * @pdev: Pointer to pdev. 4256 * @freq: Channel center frequency. 4257 * @bonded_chan_ptr: Pointer to bonded_channel_freq. 4258 * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based 4259 * channel list will be chosen. 4260 * 4261 * Return: Channel State 4262 */ 4263 static enum channel_state 4264 reg_get_5g_bonded_chan_array_for_pwrmode(struct wlan_objmgr_pdev *pdev, 4265 uint16_t freq, 4266 const struct bonded_channel_freq * 4267 bonded_chan_ptr, 4268 enum supported_6g_pwr_types 4269 in_6g_pwr_type) 4270 { 4271 uint16_t chan_cfreq; 4272 enum channel_state chan_state = CHANNEL_STATE_INVALID; 4273 enum channel_state temp_chan_state; 4274 4275 if (!bonded_chan_ptr) { 4276 reg_debug("bonded chan ptr is NULL"); 4277 return chan_state; 4278 } 4279 4280 chan_cfreq = bonded_chan_ptr->start_freq; 4281 while (chan_cfreq <= bonded_chan_ptr->end_freq) { 4282 temp_chan_state = reg_get_channel_state_for_pwrmode( 4283 pdev, 4284 chan_cfreq, 4285 in_6g_pwr_type); 4286 if (temp_chan_state < chan_state) 4287 chan_state = temp_chan_state; 4288 chan_cfreq = chan_cfreq + 20; 4289 } 4290 4291 return chan_state; 4292 } 4293 #endif 4294 4295 #ifdef WLAN_FEATURE_11BE 4296 4297 QDF_STATUS reg_extract_puncture_by_bw(enum phy_ch_width ori_bw, 4298 uint16_t ori_puncture_bitmap, 4299 qdf_freq_t freq, 4300 qdf_freq_t cen320_freq, 4301 enum phy_ch_width new_bw, 4302 uint16_t *new_puncture_bitmap) 4303 { 4304 const struct bonded_channel_freq *ori_bonded_chan; 4305 const struct bonded_channel_freq *new_bonded_chan; 4306 uint16_t chan_cfreq; 4307 uint16_t new_bit; 4308 4309 if (ori_bw < new_bw) { 4310 reg_err_rl("freq %d, ori bw %d can't be smaller than new bw %d", 4311 freq, ori_bw, new_bw); 4312 return QDF_STATUS_E_FAILURE; 4313 } 4314 4315 if (ori_bw == new_bw) { 4316 *new_puncture_bitmap = ori_puncture_bitmap; 4317 return QDF_STATUS_SUCCESS; 4318 } 4319 4320 ori_bonded_chan = reg_get_bonded_chan_entry(freq, ori_bw, cen320_freq); 4321 new_bonded_chan = reg_get_bonded_chan_entry(freq, new_bw, 0); 4322 if (!ori_bonded_chan) { 4323 reg_err_rl("bonded chan fails, freq %d, ori bw %d, new bw %d", 4324 freq, ori_bw, new_bw); 4325 return QDF_STATUS_E_FAILURE; 4326 } 4327 4328 new_bit = 0; 4329 *new_puncture_bitmap = 0; 4330 chan_cfreq = ori_bonded_chan->start_freq; 4331 while (chan_cfreq <= ori_bonded_chan->end_freq) { 4332 /* 4333 * If the "new_bw" is 20, then new_bonded_chan = NULL and the 4334 * output puncturing bitmap (*new_puncture_bitmap) as per spec 4335 * should be 0. However, if the "ori_puncture_bitmap" has 4336 * punctured the primary channel (the only channel in 20Mhz 4337 * case), then the output "(*ori_puncture_bitmap) should contain 4338 * the same so that the caller can recognize the error in the 4339 * input pattern. 4340 */ 4341 if (freq == chan_cfreq || 4342 (new_bonded_chan && 4343 chan_cfreq >= new_bonded_chan->start_freq && 4344 chan_cfreq <= new_bonded_chan->end_freq)) { 4345 /* this frequency is in new bw */ 4346 *new_puncture_bitmap |= 4347 (ori_puncture_bitmap & 1) << new_bit; 4348 new_bit++; 4349 } 4350 4351 ori_puncture_bitmap >>= 1; 4352 chan_cfreq = chan_cfreq + BW_20_MHZ; 4353 } 4354 4355 return QDF_STATUS_SUCCESS; 4356 } 4357 4358 void reg_set_create_punc_bitmap(struct ch_params *ch_params, 4359 bool is_create_punc_bitmap) 4360 { 4361 ch_params->is_create_punc_bitmap = is_create_punc_bitmap; 4362 } 4363 4364 bool reg_is_punc_bitmap_valid(enum phy_ch_width bw, uint16_t puncture_bitmap) 4365 { 4366 int i, num_bws; 4367 const uint16_t *bonded_puncture_bitmap = NULL; 4368 uint16_t array_size = 0; 4369 bool is_punc_bitmap_valid = false; 4370 4371 num_bws = QDF_ARRAY_SIZE(bw_puncture_bitmap_pair_map); 4372 for (i = 0; i < num_bws; i++) { 4373 if (bw == bw_puncture_bitmap_pair_map[i].chwidth) { 4374 bonded_puncture_bitmap = 4375 bw_puncture_bitmap_pair_map[i].puncture_bitmap_arr; 4376 array_size = bw_puncture_bitmap_pair_map[i].array_size; 4377 break; 4378 } 4379 } 4380 4381 if (array_size && bonded_puncture_bitmap) { 4382 for (i = 0; i < array_size; i++) { 4383 if (puncture_bitmap == bonded_puncture_bitmap[i]) { 4384 is_punc_bitmap_valid = true; 4385 break; 4386 } 4387 } 4388 } 4389 4390 return is_punc_bitmap_valid; 4391 } 4392 4393 #ifdef QCA_DFS_BW_PUNCTURE 4394 uint16_t reg_find_nearest_puncture_pattern(enum phy_ch_width bw, 4395 uint16_t proposed_bitmap) 4396 { 4397 int i, num_bws; 4398 const uint16_t *bonded_puncture_bitmap = NULL; 4399 uint16_t array_size; 4400 uint16_t final_bitmap; 4401 4402 /* An input pattern = 0 will match any pattern 4403 * Therefore, ignore '0' pattern and return '0', as '0' matches '0'. 4404 */ 4405 if (!proposed_bitmap) 4406 return 0; 4407 4408 array_size = 0; 4409 final_bitmap = 0; 4410 4411 num_bws = QDF_ARRAY_SIZE(bw_puncture_bitmap_pair_map); 4412 for (i = 0; i < num_bws; i++) { 4413 if (bw == bw_puncture_bitmap_pair_map[i].chwidth) { 4414 bonded_puncture_bitmap = 4415 bw_puncture_bitmap_pair_map[i].puncture_bitmap_arr; 4416 array_size = bw_puncture_bitmap_pair_map[i].array_size; 4417 break; 4418 } 4419 } 4420 4421 if (array_size && bonded_puncture_bitmap) { 4422 for (i = 0; i < array_size; i++) { 4423 uint16_t valid_bitmap = bonded_puncture_bitmap[i]; 4424 4425 if ((proposed_bitmap | valid_bitmap) == valid_bitmap) { 4426 final_bitmap = valid_bitmap; 4427 break; 4428 } 4429 } 4430 } 4431 4432 return final_bitmap; 4433 } 4434 #endif /* QCA_DFS_BW_PUNCTURE */ 4435 4436 /** 4437 * reg_update_5g_bonded_channel_state_punc_for_freq() - update channel state 4438 * with static puncturing feature 4439 * @pdev: pointer to pdev 4440 * @bonded_chan_ptr: Pointer to bonded_channel_freq. 4441 * @ch_params: pointer to ch_params 4442 * @chan_state: chan_state to be updated 4443 * 4444 * Return: void 4445 */ 4446 static void reg_update_5g_bonded_channel_state_punc_for_freq( 4447 struct wlan_objmgr_pdev *pdev, 4448 const struct bonded_channel_freq *bonded_chan_ptr, 4449 struct ch_params *ch_params, 4450 enum channel_state *chan_state) 4451 { 4452 qdf_freq_t chan_cfreq; 4453 enum channel_state temp_chan_state; 4454 uint16_t puncture_bitmap = 0; 4455 int i = 0; 4456 enum channel_state update_state = CHANNEL_STATE_ENABLE; 4457 4458 if (!pdev || !bonded_chan_ptr || !ch_params || !chan_state || 4459 !ch_params->is_create_punc_bitmap) 4460 return; 4461 4462 chan_cfreq = bonded_chan_ptr->start_freq; 4463 while (chan_cfreq <= bonded_chan_ptr->end_freq) { 4464 temp_chan_state = 4465 reg_get_channel_state_for_freq(pdev, 4466 chan_cfreq); 4467 if (!reg_is_state_allowed(temp_chan_state)) 4468 puncture_bitmap |= BIT(i); 4469 /* Remember of any of the sub20 channel is a DFS channel */ 4470 if (temp_chan_state == CHANNEL_STATE_DFS) 4471 update_state = CHANNEL_STATE_DFS; 4472 chan_cfreq = chan_cfreq + BW_20_MHZ; 4473 i++; 4474 } 4475 /* Validate puncture bitmap. Update channel state. */ 4476 if (reg_is_punc_bitmap_valid(ch_params->ch_width, puncture_bitmap)) { 4477 *chan_state = update_state; 4478 ch_params->reg_punc_bitmap = puncture_bitmap; 4479 } 4480 } 4481 4482 #ifdef CONFIG_REG_6G_PWRMODE 4483 /** 4484 * reg_update_5g_bonded_channel_state_punc_for_pwrmode() - update channel state 4485 * with static puncturing feature 4486 * @pdev: pointer to pdev 4487 * @bonded_chan_ptr: Pointer to bonded_channel_freq. 4488 * @ch_params: pointer to ch_params 4489 * @chan_state: chan_state to be updated 4490 * 4491 * Return: void 4492 */ 4493 static void reg_update_5g_bonded_channel_state_punc_for_pwrmode( 4494 struct wlan_objmgr_pdev *pdev, 4495 const struct bonded_channel_freq *bonded_chan_ptr, 4496 struct ch_params *ch_params, 4497 enum channel_state *chan_state, 4498 enum supported_6g_pwr_types in_6g_pwr_mode) 4499 { 4500 qdf_freq_t chan_cfreq; 4501 enum channel_state temp_chan_state; 4502 uint16_t puncture_bitmap = 0; 4503 int i = 0; 4504 enum channel_state update_state = CHANNEL_STATE_ENABLE; 4505 4506 if (!pdev || !bonded_chan_ptr || !ch_params || !chan_state || 4507 !ch_params->is_create_punc_bitmap) 4508 return; 4509 4510 chan_cfreq = bonded_chan_ptr->start_freq; 4511 while (chan_cfreq <= bonded_chan_ptr->end_freq) { 4512 temp_chan_state = 4513 reg_get_channel_state_for_pwrmode(pdev, chan_cfreq, 4514 in_6g_pwr_mode); 4515 if (!reg_is_state_allowed(temp_chan_state)) 4516 puncture_bitmap |= BIT(i); 4517 /* Remember of any of the sub20 channel is a DFS channel */ 4518 if (temp_chan_state == CHANNEL_STATE_DFS) 4519 update_state = CHANNEL_STATE_DFS; 4520 chan_cfreq = chan_cfreq + BW_20_MHZ; 4521 i++; 4522 } 4523 /* Validate puncture bitmap. Update channel state. */ 4524 if (reg_is_punc_bitmap_valid(ch_params->ch_width, puncture_bitmap)) { 4525 *chan_state = update_state; 4526 ch_params->reg_punc_bitmap = puncture_bitmap; 4527 } 4528 } 4529 #endif 4530 #else 4531 static void reg_update_5g_bonded_channel_state_punc_for_freq( 4532 struct wlan_objmgr_pdev *pdev, 4533 const struct bonded_channel_freq *bonded_chan_ptr, 4534 struct ch_params *ch_params, 4535 enum channel_state *chan_state) 4536 { 4537 } 4538 4539 static void reg_update_5g_bonded_channel_state_punc_for_pwrmode( 4540 struct wlan_objmgr_pdev *pdev, 4541 const struct bonded_channel_freq *bonded_chan_ptr, 4542 struct ch_params *ch_params, 4543 enum channel_state *chan_state, 4544 enum supported_6g_pwr_types in_6g_pwr_mode) 4545 { 4546 } 4547 #endif 4548 4549 enum channel_state 4550 reg_get_5g_bonded_channel_state_for_freq(struct wlan_objmgr_pdev *pdev, 4551 qdf_freq_t freq, 4552 struct ch_params *ch_params) 4553 { 4554 enum phy_ch_width bw; 4555 enum channel_enum ch_indx; 4556 enum channel_state chan_state; 4557 struct regulatory_channel *reg_channels; 4558 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4559 bool bw_enabled = false; 4560 const struct bonded_channel_freq *bonded_chan_ptr = NULL; 4561 4562 if (!ch_params) { 4563 reg_err_rl("Invalid ch_params"); 4564 return CHANNEL_STATE_INVALID; 4565 } 4566 bw = ch_params->ch_width; 4567 if (bw > CH_WIDTH_80P80MHZ) { 4568 reg_err_rl("bw (%d) passed is not good", bw); 4569 return CHANNEL_STATE_INVALID; 4570 } 4571 4572 chan_state = reg_get_5g_bonded_channel_for_freq(pdev, freq, bw, 4573 &bonded_chan_ptr); 4574 4575 reg_update_5g_bonded_channel_state_punc_for_freq(pdev, 4576 bonded_chan_ptr, 4577 ch_params, 4578 &chan_state); 4579 4580 if ((chan_state == CHANNEL_STATE_INVALID) || 4581 (chan_state == CHANNEL_STATE_DISABLE)) 4582 return chan_state; 4583 4584 pdev_priv_obj = reg_get_pdev_obj(pdev); 4585 4586 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4587 reg_err("pdev reg obj is NULL"); 4588 return CHANNEL_STATE_INVALID; 4589 } 4590 reg_channels = pdev_priv_obj->cur_chan_list; 4591 4592 ch_indx = reg_get_chan_enum_for_freq(freq); 4593 if (reg_is_chan_enum_invalid(ch_indx)) 4594 return CHANNEL_STATE_INVALID; 4595 if (bw == CH_WIDTH_5MHZ) 4596 bw_enabled = true; 4597 else if (bw == CH_WIDTH_10MHZ) 4598 bw_enabled = (reg_channels[ch_indx].min_bw <= 10) && 4599 (reg_channels[ch_indx].max_bw >= 10); 4600 else if (bw == CH_WIDTH_20MHZ) 4601 bw_enabled = (reg_channels[ch_indx].min_bw <= 20) && 4602 (reg_channels[ch_indx].max_bw >= 20); 4603 else if (bw == CH_WIDTH_40MHZ) 4604 bw_enabled = (reg_channels[ch_indx].min_bw <= 40) && 4605 (reg_channels[ch_indx].max_bw >= 40); 4606 else if (bw == CH_WIDTH_80MHZ) 4607 bw_enabled = (reg_channels[ch_indx].min_bw <= 80) && 4608 (reg_channels[ch_indx].max_bw >= 80); 4609 else if (bw == CH_WIDTH_160MHZ) 4610 bw_enabled = (reg_channels[ch_indx].min_bw <= 160) && 4611 (reg_channels[ch_indx].max_bw >= 160); 4612 else if (bw == CH_WIDTH_80P80MHZ) 4613 bw_enabled = (reg_channels[ch_indx].min_bw <= 80) && 4614 (reg_channels[ch_indx].max_bw >= 80); 4615 4616 if (bw_enabled) 4617 return chan_state; 4618 return CHANNEL_STATE_DISABLE; 4619 } 4620 4621 #ifdef CONFIG_REG_6G_PWRMODE 4622 enum channel_state 4623 reg_get_5g_bonded_channel_state_for_pwrmode(struct wlan_objmgr_pdev *pdev, 4624 qdf_freq_t freq, 4625 struct ch_params *ch_params, 4626 enum supported_6g_pwr_types 4627 in_6g_pwr_mode) 4628 { 4629 enum phy_ch_width bw; 4630 enum channel_enum ch_indx; 4631 enum channel_state chan_state; 4632 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4633 bool bw_enabled = false; 4634 const struct bonded_channel_freq *bonded_chan_ptr = NULL; 4635 uint16_t min_bw, max_bw; 4636 4637 if (!ch_params) { 4638 reg_err_rl("Invalid ch_params"); 4639 return CHANNEL_STATE_INVALID; 4640 } 4641 bw = ch_params->ch_width; 4642 if (bw > CH_WIDTH_80P80MHZ) { 4643 reg_err_rl("bw (%d) passed is not good", bw); 4644 return CHANNEL_STATE_INVALID; 4645 } 4646 4647 chan_state = reg_get_5g_bonded_channel_for_pwrmode(pdev, freq, bw, 4648 &bonded_chan_ptr, 4649 in_6g_pwr_mode); 4650 4651 reg_update_5g_bonded_channel_state_punc_for_pwrmode( 4652 pdev, bonded_chan_ptr, 4653 ch_params, &chan_state, 4654 in_6g_pwr_mode); 4655 4656 if ((chan_state == CHANNEL_STATE_INVALID) || 4657 (chan_state == CHANNEL_STATE_DISABLE)) 4658 return chan_state; 4659 4660 pdev_priv_obj = reg_get_pdev_obj(pdev); 4661 4662 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4663 reg_err("pdev reg obj is NULL"); 4664 return CHANNEL_STATE_INVALID; 4665 } 4666 4667 ch_indx = reg_get_chan_enum_for_freq(freq); 4668 if (reg_is_chan_enum_invalid(ch_indx)) 4669 return CHANNEL_STATE_INVALID; 4670 4671 if (reg_get_min_max_bw_reg_chan_list(pdev, ch_indx, in_6g_pwr_mode, 4672 &min_bw, &max_bw)) 4673 return CHANNEL_STATE_INVALID; 4674 4675 if (bw == CH_WIDTH_5MHZ) 4676 bw_enabled = true; 4677 else if (bw == CH_WIDTH_10MHZ) 4678 bw_enabled = (min_bw <= 10) && 4679 (max_bw >= 10); 4680 else if (bw == CH_WIDTH_20MHZ) 4681 bw_enabled = (min_bw <= 20) && 4682 (max_bw >= 20); 4683 else if (bw == CH_WIDTH_40MHZ) 4684 bw_enabled = (min_bw <= 40) && 4685 (max_bw >= 40); 4686 else if (bw == CH_WIDTH_80MHZ) 4687 bw_enabled = (min_bw <= 80) && 4688 (max_bw >= 80); 4689 else if (bw == CH_WIDTH_160MHZ) 4690 bw_enabled = (min_bw <= 160) && 4691 (max_bw >= 160); 4692 else if (bw == CH_WIDTH_80P80MHZ) 4693 bw_enabled = (min_bw <= 80) && 4694 (max_bw >= 80); 4695 4696 if (bw_enabled) 4697 return chan_state; 4698 return CHANNEL_STATE_DISABLE; 4699 } 4700 #endif 4701 4702 enum channel_state 4703 reg_get_2g_bonded_channel_state_for_freq(struct wlan_objmgr_pdev *pdev, 4704 qdf_freq_t oper_ch_freq, 4705 qdf_freq_t sec_ch_freq, 4706 enum phy_ch_width bw) 4707 { 4708 enum channel_enum chan_idx; 4709 enum channel_state chan_state; 4710 struct regulatory_channel *reg_channels; 4711 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 4712 bool bw_enabled = false; 4713 enum channel_state chan_state2 = CHANNEL_STATE_INVALID; 4714 4715 if (bw > CH_WIDTH_40MHZ) 4716 return CHANNEL_STATE_INVALID; 4717 4718 if (bw == CH_WIDTH_40MHZ) { 4719 if ((sec_ch_freq + 20 != oper_ch_freq) && 4720 (oper_ch_freq + 20 != sec_ch_freq)) 4721 return CHANNEL_STATE_INVALID; 4722 chan_state2 = 4723 reg_get_channel_state_for_pwrmode(pdev, 4724 sec_ch_freq, 4725 REG_CURRENT_PWR_MODE); 4726 if (chan_state2 == CHANNEL_STATE_INVALID) 4727 return chan_state2; 4728 } 4729 pdev_priv_obj = reg_get_pdev_obj(pdev); 4730 4731 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 4732 reg_err("reg pdev priv obj is NULL"); 4733 return CHANNEL_STATE_INVALID; 4734 } 4735 4736 reg_channels = pdev_priv_obj->cur_chan_list; 4737 4738 chan_state = reg_get_channel_state_for_pwrmode(pdev, 4739 oper_ch_freq, 4740 REG_CURRENT_PWR_MODE); 4741 if (chan_state2 < chan_state) 4742 chan_state = chan_state2; 4743 4744 if ((chan_state == CHANNEL_STATE_INVALID) || 4745 (chan_state == CHANNEL_STATE_DISABLE)) 4746 return chan_state; 4747 4748 chan_idx = reg_get_chan_enum_for_freq(oper_ch_freq); 4749 if (reg_is_chan_enum_invalid(chan_idx)) 4750 return CHANNEL_STATE_INVALID; 4751 if (bw == CH_WIDTH_5MHZ) 4752 bw_enabled = true; 4753 else if (bw == CH_WIDTH_10MHZ) 4754 bw_enabled = (reg_channels[chan_idx].min_bw <= 10) && 4755 (reg_channels[chan_idx].max_bw >= 10); 4756 else if (bw == CH_WIDTH_20MHZ) 4757 bw_enabled = (reg_channels[chan_idx].min_bw <= 20) && 4758 (reg_channels[chan_idx].max_bw >= 20); 4759 else if (bw == CH_WIDTH_40MHZ) 4760 bw_enabled = (reg_channels[chan_idx].min_bw <= 40) && 4761 (reg_channels[chan_idx].max_bw >= 40); 4762 4763 if (bw_enabled) 4764 return chan_state; 4765 else 4766 return CHANNEL_STATE_DISABLE; 4767 4768 return CHANNEL_STATE_ENABLE; 4769 } 4770 4771 #ifdef WLAN_FEATURE_11BE 4772 4773 /** 4774 * reg_get_20mhz_channel_state_based_on_nol() - Get channel state of the 4775 * given 20MHZ channel. If the freq is in NOL/NOL history, it is considered 4776 * as enabled if "treat_nol_chan_as_disabled" is false, else the state is 4777 * considered as "disabled". 4778 * @pdev: Pointer to struct wlan_objmgr_pdev 4779 * @freq: Primary frequency 4780 * @treat_nol_chan_as_disabled: Flag to treat nol chan as enabled/disabled 4781 * @in_6g_pwr_type: Input 6g power type 4782 * 4783 * Return - Channel state 4784 */ 4785 static enum channel_state 4786 reg_get_20mhz_channel_state_based_on_nol(struct wlan_objmgr_pdev *pdev, 4787 qdf_freq_t freq, 4788 bool treat_nol_chan_as_disabled, 4789 enum supported_6g_pwr_types in_6g_pwr_type) 4790 { 4791 if (treat_nol_chan_as_disabled) 4792 return reg_get_channel_state_for_pwrmode(pdev, freq, 4793 in_6g_pwr_type); 4794 return reg_get_nol_channel_state(pdev, freq, 4795 in_6g_pwr_type); 4796 } 4797 4798 /** 4799 * reg_get_320_bonded_chan_array() - Fetches a list of bonded channel pointers 4800 * for the given bonded channel array. If 320 band center is specified, 4801 * return the bonded channel pointer comprising of given band center else 4802 * return list of all available bonded channel pair. 4803 * 4804 * @pdev: Pointer to struct wlan_objmgr_pdev. 4805 * @freq: Input frequency in MHZ whose bonded channel pointer must be fetched. 4806 * @band_center_320: Channel center frequency of 320MHZ channel. 4807 * @bonded_chan_ar: Array of bonded channel list. 4808 * @array_size: Size of bonded channel array. 4809 * @bonded_chan_ptr: Pointer to hold the address of bonded_channel_freq index. 4810 * 4811 * Return: number of bonded channel arrays fetched. 4812 */ 4813 4814 #define MAX_NUM_BONDED_PAIR 2 4815 static uint8_t 4816 reg_get_320_bonded_chan_array(struct wlan_objmgr_pdev *pdev, 4817 qdf_freq_t freq, 4818 qdf_freq_t band_center_320, 4819 const struct bonded_channel_freq bonded_chan_ar[], 4820 uint16_t array_size, 4821 const struct bonded_channel_freq 4822 *bonded_chan_ptr[]) 4823 { 4824 int i; 4825 uint8_t num_bonded_pairs = 0; 4826 4827 /* Fetch all possible bonded channel pointers for the given freq */ 4828 if (!band_center_320) { 4829 for (i = 0 ; i < array_size && 4830 num_bonded_pairs < MAX_NUM_BONDED_PAIR; i++) { 4831 if ((freq >= bonded_chan_ar[i].start_freq) && 4832 (freq <= bonded_chan_ar[i].end_freq)) { 4833 bonded_chan_ptr[num_bonded_pairs] = 4834 &bonded_chan_ar[i]; 4835 num_bonded_pairs++; 4836 } 4837 } 4838 } else { 4839 /* Fetch the bonded channel pointer for the given band_center */ 4840 for (i = 0; i < array_size; i++) { 4841 qdf_freq_t bandstart = bonded_chan_ar[i].start_freq; 4842 4843 if (band_center_320 == 4844 reg_get_band_cen_from_bandstart(BW_320_MHZ, 4845 bandstart)) { 4846 bonded_chan_ptr[num_bonded_pairs] = 4847 &bonded_chan_ar[i]; 4848 num_bonded_pairs++; 4849 break; 4850 } 4851 } 4852 } 4853 return num_bonded_pairs; 4854 } 4855 4856 #define SUB_CHAN_BW 20 /* 20 MHZ */ 4857 #define BW_160MHZ 160 4858 #define REG_IS_TOT_CHAN_BW_BELOW_160(_x, _y) \ 4859 (reg_is_state_allowed((_x)) && (_y) < BW_160MHZ) 4860 4861 static inline qdf_freq_t 4862 reg_get_endchan_cen_from_bandstart(qdf_freq_t band_start, 4863 uint16_t bw) 4864 { 4865 uint16_t left_edge_freq = band_start - BW_10_MHZ; 4866 4867 return left_edge_freq + bw - BW_10_MHZ; 4868 } 4869 4870 /** 4871 * reg_get_320_bonded_channel_state() - Given a bonded channel 4872 * pointer and freq, determine if the subchannels of the bonded pair 4873 * are valid and supported by the current regulatory. 4874 * 4875 * @pdev: Pointer to struct wlan_objmgr_pdev. 4876 * @freq: Frequency in MHZ. 4877 * @bonded_chan_ptr: Pointer to const struct bonded_channel_freq. 4878 * @bw: channel bandwidth 4879 * @out_punc_bitmap: Output puncturing bitmap 4880 * @treat_nol_chan_as_disabled: Bool to treat nol as disabled/enabled 4881 * 4882 * Return - The channel state of the bonded pair. 4883 */ 4884 static enum channel_state 4885 reg_get_320_bonded_channel_state(struct wlan_objmgr_pdev *pdev, 4886 qdf_freq_t freq, 4887 const struct bonded_channel_freq 4888 *bonded_chan_ptr, 4889 enum phy_ch_width bw, 4890 uint16_t *out_punc_bitmap, 4891 bool treat_nol_chan_as_disabled) 4892 { 4893 enum channel_state chan_state = CHANNEL_STATE_INVALID; 4894 enum channel_state temp_chan_state, prim_chan_state; 4895 uint16_t startchan_cfreq, endchan_cfreq; 4896 uint16_t max_cont_bw, i; 4897 4898 *out_punc_bitmap = ALL_SCHANS_PUNC; 4899 4900 if (!bonded_chan_ptr) 4901 return chan_state; 4902 4903 startchan_cfreq = bonded_chan_ptr->start_freq; 4904 endchan_cfreq = 4905 reg_get_endchan_cen_from_bandstart(startchan_cfreq, 4906 BW_320_MHZ); 4907 max_cont_bw = 0; 4908 i = 0; 4909 4910 while (startchan_cfreq <= endchan_cfreq) { 4911 temp_chan_state = 4912 reg_get_20mhz_channel_state_based_on_nol(pdev, 4913 startchan_cfreq, 4914 treat_nol_chan_as_disabled, 4915 REG_CURRENT_PWR_MODE); 4916 4917 if (reg_is_state_allowed(temp_chan_state)) { 4918 max_cont_bw += SUB_CHAN_BW; 4919 *out_punc_bitmap &= ~BIT(i); 4920 } 4921 4922 if (temp_chan_state < chan_state) 4923 chan_state = temp_chan_state; 4924 4925 startchan_cfreq = startchan_cfreq + SUB_CHAN_BW; 4926 i++; 4927 } 4928 4929 prim_chan_state = 4930 reg_get_20mhz_channel_state_based_on_nol(pdev, 4931 freq, 4932 treat_nol_chan_as_disabled, 4933 REG_CURRENT_PWR_MODE); 4934 4935 /* After iterating through all the subchannels, if the final channel 4936 * state is invalid/disable, it means all our subchannels are not 4937 * valid and we could not find a 320 MHZ channel. 4938 * If we have found a channel where the max width is: 4939 * 1. Less than 160: there is no puncturing needed. Hence return 4940 * the chan state as invalid. Or if the primary freq given is not 4941 * supported by regulatory, the channel cannot be enabled as a 4942 * punctured channel. So return channel state as invalid. 4943 * 2. If greater than 160: Mark the invalid channels as punctured. 4944 * and return channel state as ENABLE. 4945 */ 4946 if (REG_IS_TOT_CHAN_BW_BELOW_160(chan_state, max_cont_bw) || 4947 !reg_is_state_allowed(prim_chan_state)) 4948 return CHANNEL_STATE_INVALID; 4949 4950 return chan_state; 4951 } 4952 #endif 4953 4954 #ifdef WLAN_FEATURE_11BE 4955 enum channel_state 4956 reg_get_chan_state_for_320(struct wlan_objmgr_pdev *pdev, 4957 uint16_t freq, 4958 qdf_freq_t band_center_320, 4959 enum phy_ch_width ch_width, 4960 const struct bonded_channel_freq 4961 **bonded_chan_ptr_ptr, 4962 enum supported_6g_pwr_types in_6g_pwr_type, 4963 bool treat_nol_chan_as_disabled) 4964 { 4965 uint8_t num_bonded_pairs; 4966 uint16_t array_size = 4967 QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq); 4968 const struct bonded_channel_freq *bonded_ch_ptr[2] = { 4969 NULL, NULL}; 4970 uint16_t punct_pattern; 4971 4972 /* For now sending band center freq as 0 */ 4973 num_bonded_pairs = 4974 reg_get_320_bonded_chan_array(pdev, freq, band_center_320, 4975 bonded_chan_320mhz_list_freq, 4976 array_size, bonded_ch_ptr); 4977 if (!num_bonded_pairs) { 4978 reg_info("No 320MHz bonded pair for freq %d", freq); 4979 return CHANNEL_STATE_INVALID; 4980 } 4981 /* Taking only first bonded pair */ 4982 *bonded_chan_ptr_ptr = bonded_ch_ptr[0]; 4983 4984 return reg_get_320_bonded_channel_state_for_pwrmode(pdev, freq, 4985 bonded_ch_ptr[0], 4986 ch_width, 4987 &punct_pattern, 4988 in_6g_pwr_type, 4989 treat_nol_chan_as_disabled); 4990 } 4991 #endif 4992 4993 #ifdef WLAN_FEATURE_11BE 4994 enum channel_state 4995 reg_get_320_bonded_channel_state_for_pwrmode(struct wlan_objmgr_pdev *pdev, 4996 qdf_freq_t freq, 4997 const struct bonded_channel_freq 4998 *bonded_chan_ptr, 4999 enum phy_ch_width bw, 5000 uint16_t *out_punc_bitmap, 5001 enum supported_6g_pwr_types 5002 in_6g_pwr_type, 5003 bool treat_nol_chan_as_disabled) 5004 { 5005 enum channel_state chan_state = CHANNEL_STATE_INVALID; 5006 enum channel_state temp_chan_state, prim_chan_state; 5007 uint16_t startchan_cfreq, endchan_cfreq; 5008 uint16_t max_cont_bw, i; 5009 5010 *out_punc_bitmap = ALL_SCHANS_PUNC; 5011 5012 if (!bonded_chan_ptr) 5013 return chan_state; 5014 5015 startchan_cfreq = bonded_chan_ptr->start_freq; 5016 endchan_cfreq = 5017 reg_get_endchan_cen_from_bandstart(startchan_cfreq, 5018 BW_320_MHZ); 5019 max_cont_bw = 0; 5020 i = 0; 5021 5022 while (startchan_cfreq <= endchan_cfreq) { 5023 temp_chan_state = 5024 reg_get_20mhz_channel_state_based_on_nol(pdev, 5025 startchan_cfreq, 5026 treat_nol_chan_as_disabled, 5027 in_6g_pwr_type); 5028 5029 if (reg_is_state_allowed(temp_chan_state)) { 5030 max_cont_bw += SUB_CHAN_BW; 5031 *out_punc_bitmap &= ~BIT(i); 5032 } 5033 5034 if (temp_chan_state < chan_state) 5035 chan_state = temp_chan_state; 5036 5037 startchan_cfreq = startchan_cfreq + SUB_CHAN_BW; 5038 i++; 5039 } 5040 5041 prim_chan_state = 5042 reg_get_20mhz_channel_state_based_on_nol(pdev, freq, 5043 treat_nol_chan_as_disabled, 5044 in_6g_pwr_type); 5045 5046 /* After iterating through all the subchannels, if the final channel 5047 * state is invalid/disable, it means all our subchannels are not 5048 * valid and we could not find a 320 MHZ channel. 5049 * If we have found a channel where the max width is: 5050 * 1. Less than 160: there is no puncturing needed. Hence return 5051 * the chan state as invalid. Or if the primary freq given is not 5052 * supported by regulatory, the channel cannot be enabled as a 5053 * punctured channel. So return channel state as invalid. 5054 * 2. If greater than 160: Mark the invalid channels as punctured. 5055 * and return channel state as ENABLE. 5056 */ 5057 if (REG_IS_TOT_CHAN_BW_BELOW_160(chan_state, max_cont_bw) || 5058 !reg_is_state_allowed(prim_chan_state)) 5059 return CHANNEL_STATE_INVALID; 5060 5061 return chan_state; 5062 } 5063 5064 static inline bool reg_is_pri_within_240mhz_chan(qdf_freq_t freq) 5065 { 5066 return (freq >= CHAN_FREQ_5660 && freq <= CHAN_FREQ_5720); 5067 } 5068 5069 /** 5070 * reg_fill_chan320mhz_seg0_center() - Fill the primary segment center 5071 * for a 320MHz channel in the given channel param. Primary segment center 5072 * of a 320MHZ is the 160MHZ segment center of the given freq. 5073 * @pdev: Pointer to struct wlan_objmgr_pdev. 5074 * @ch_param: channel params to be filled. 5075 * @freq: Input primary frequency in MHZ. 5076 * 5077 * Return: void. 5078 */ 5079 static void 5080 reg_fill_chan320mhz_seg0_center(struct wlan_objmgr_pdev *pdev, 5081 struct ch_params *ch_param, qdf_freq_t freq) 5082 { 5083 const struct bonded_channel_freq *t_bonded_ch_ptr; 5084 5085 t_bonded_ch_ptr = reg_get_bonded_chan_entry(freq, CH_WIDTH_160MHZ, 0); 5086 if (t_bonded_ch_ptr) { 5087 ch_param->mhz_freq_seg0 = 5088 (t_bonded_ch_ptr->start_freq + 5089 t_bonded_ch_ptr->end_freq) / 2; 5090 ch_param->center_freq_seg0 = 5091 reg_freq_to_chan(pdev, 5092 ch_param->mhz_freq_seg0); 5093 } else { 5094 /** 5095 * If we do not find a 160Mhz bonded pair, since it is 5096 * for a 320Mhz channel we need to also see if we can find a 5097 * pseudo 160Mhz channel for the special case of 5098 * 5Ghz 240Mhz channel. 5099 */ 5100 if (reg_is_pri_within_240mhz_chan(freq)) { 5101 ch_param->mhz_freq_seg0 = 5102 PRIM_SEG_FREQ_CENTER_240MHZ_5G_CHAN; 5103 ch_param->center_freq_seg0 = 5104 PRIM_SEG_IEEE_CENTER_240MHZ_5G_CHAN; 5105 } else { 5106 ch_param->ch_width = CH_WIDTH_INVALID; 5107 reg_err("Cannot find 160Mhz centers for freq %d", freq); 5108 } 5109 } 5110 } 5111 5112 /** 5113 * reg_fill_channel_list_for_320() - Fill 320MHZ channel list. If we 5114 * are unable to find a channel whose width is greater than 160MHZ and less 5115 * than 320 with the help of puncturing, using the given freq, set "update_bw" 5116 * variable to be true, lower the channel width and return to the caller. 5117 * The caller fetches a channel of reduced mode based on "update_bw" flag. 5118 * 5119 * If 320 band center is 0, return all the 320 channels 5120 * that match the primary frequency else return only channel 5121 * that matches 320 band center. 5122 * 5123 * @pdev: Pointer to struct wlan_objmgr_pdev. 5124 * @freq: Input frequency in MHZ. 5125 * @ch_width: Input channel width, if a channel of the given width is not 5126 * found, reduce the channel width to the next lower mode and pass it to the 5127 * caller. 5128 * @band_center_320: Center of 320MHZ channel. 5129 * @chan_list: Pointer to reg_channel_list to be filled. 5130 * @update_bw: Flag to hold if bw is updated. 5131 * @treat_nol_chan_as_disabled: Bool to treat NOL channels as disabled/enabled 5132 * 5133 * Return - None. 5134 */ 5135 static void 5136 reg_fill_channel_list_for_320(struct wlan_objmgr_pdev *pdev, 5137 qdf_freq_t freq, 5138 enum phy_ch_width *in_ch_width, 5139 qdf_freq_t band_center_320, 5140 struct reg_channel_list *chan_list, 5141 bool *update_bw, 5142 bool treat_nol_chan_as_disabled) 5143 { 5144 uint8_t num_bonded_pairs, i, num_ch_params; 5145 enum channel_state chan_state; 5146 uint16_t array_size = QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq); 5147 uint16_t out_punc_bitmap; 5148 uint16_t max_reg_bw; 5149 enum channel_enum chan_enum; 5150 const struct bonded_channel_freq *bonded_ch_ptr[2] = {NULL, NULL}; 5151 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5152 5153 *update_bw = false; 5154 5155 chan_enum = reg_get_chan_enum_for_freq(freq); 5156 if (reg_is_chan_enum_invalid(chan_enum)) { 5157 reg_err("chan freq is not valid"); 5158 return; 5159 } 5160 5161 pdev_priv_obj = reg_get_pdev_obj(pdev); 5162 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5163 reg_err("reg pdev priv obj is NULL"); 5164 return; 5165 } 5166 5167 /* Maximum bandwidth of the channel supported by regulatory for 5168 * the given freq. 5169 */ 5170 max_reg_bw = pdev_priv_obj->cur_chan_list[chan_enum].max_bw; 5171 5172 /* Regulatory does not support BW greater than 160. 5173 * Try finding a channel in a lower mode. 5174 */ 5175 if (max_reg_bw <= BW_160MHZ) { 5176 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5177 *update_bw = true; 5178 return; 5179 } 5180 5181 num_bonded_pairs = 5182 reg_get_320_bonded_chan_array(pdev, freq, band_center_320, 5183 bonded_chan_320mhz_list_freq, 5184 array_size, 5185 bonded_ch_ptr); 5186 5187 if (!num_bonded_pairs) { 5188 if (band_center_320) { 5189 reg_debug("No bonded pair for the given band_center\n"); 5190 chan_list->num_ch_params = 0; 5191 } else { 5192 /* Could not find a 320 MHZ bonded channel pair, 5193 * find a channel of lower BW. 5194 */ 5195 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5196 *update_bw = true; 5197 } 5198 return; 5199 } 5200 5201 for (i = 0, num_ch_params = 0 ; i < num_bonded_pairs; i++) { 5202 /* Chan_state to hold the channel state of bonding 5203 * pair of channels. 5204 */ 5205 chan_state = 5206 reg_get_320_bonded_channel_state(pdev, freq, 5207 bonded_ch_ptr[i], 5208 *in_ch_width, 5209 &out_punc_bitmap, 5210 treat_nol_chan_as_disabled); 5211 5212 if (reg_is_state_allowed(chan_state)) { 5213 struct ch_params *t_chan_param = 5214 &chan_list->chan_param[num_ch_params]; 5215 5216 t_chan_param->mhz_freq_seg1 = 5217 (bonded_ch_ptr[i]->start_freq + 5218 bonded_ch_ptr[i]->end_freq) / 2; 5219 t_chan_param->center_freq_seg1 = 5220 reg_freq_to_chan(pdev, 5221 t_chan_param->mhz_freq_seg1); 5222 t_chan_param->ch_width = *in_ch_width; 5223 t_chan_param->reg_punc_bitmap = out_punc_bitmap; 5224 5225 reg_fill_chan320mhz_seg0_center(pdev, 5226 t_chan_param, 5227 freq); 5228 num_ch_params++; 5229 chan_list->num_ch_params = num_ch_params; 5230 } 5231 } 5232 5233 /* The bonded pairs could not create any channels, 5234 * lower the bandwidth to find a channel. 5235 */ 5236 if (!chan_list->num_ch_params) { 5237 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5238 *update_bw = true; 5239 } 5240 } 5241 5242 #ifdef CONFIG_REG_6G_PWRMODE 5243 /** 5244 * reg_fill_channel_list_for_320_for_pwrmode() - Fill 320MHZ channel list. If we 5245 * are unable to find a channel whose width is greater than 160MHZ and less 5246 * than 320 with the help of puncturing, using the given freq, set "update_bw" 5247 * variable to be true, lower the channel width and return to the caller. 5248 * The caller fetches a channel of reduced mode based on "update_bw" flag. 5249 * 5250 * If 320 band center is 0, return all the 320 channels 5251 * that match the primary frequency else return only channel 5252 * that matches 320 band center. 5253 * 5254 * @pdev: Pointer to struct wlan_objmgr_pdev. 5255 * @freq: Input frequency in MHZ. 5256 * @ch_width: Input channel width, if a channel of the given width is not 5257 * found, reduce the channel width to the next lower mode and pass it to the 5258 * caller. 5259 * @band_center_320: Center of 320MHZ channel. 5260 * @chan_list: Pointer to reg_channel_list to be filled. 5261 * @update_bw: Flag to hold if bw is updated. 5262 * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based 5263 * channel list will be chosen. 5264 * @treat_nol_chan_as_disabled: Bool to treat NOL channels as disabled/enabled 5265 * 5266 * Return - None. 5267 */ 5268 static void 5269 reg_fill_channel_list_for_320_for_pwrmode( 5270 struct wlan_objmgr_pdev *pdev, 5271 qdf_freq_t freq, 5272 enum phy_ch_width *in_ch_width, 5273 qdf_freq_t band_center_320, 5274 struct reg_channel_list *chan_list, 5275 bool *update_bw, 5276 enum supported_6g_pwr_types in_6g_pwr_mode, 5277 bool treat_nol_chan_as_disabled) 5278 { 5279 uint8_t num_bonded_pairs, i, num_ch_params; 5280 enum channel_state chan_state; 5281 uint16_t array_size = QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq); 5282 uint16_t out_punc_bitmap; 5283 uint16_t max_reg_bw; 5284 enum channel_enum chan_enum; 5285 const struct bonded_channel_freq *bonded_ch_ptr[2] = {NULL, NULL}; 5286 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5287 5288 *update_bw = false; 5289 5290 chan_enum = reg_get_chan_enum_for_freq(freq); 5291 if (reg_is_chan_enum_invalid(chan_enum)) { 5292 reg_err("chan freq is not valid"); 5293 return; 5294 } 5295 5296 pdev_priv_obj = reg_get_pdev_obj(pdev); 5297 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5298 reg_err("reg pdev priv obj is NULL"); 5299 return; 5300 } 5301 5302 /* Maximum bandwidth of the channel supported by regulatory for 5303 * the given freq. 5304 */ 5305 if (reg_get_min_max_bw_reg_chan_list(pdev, chan_enum, in_6g_pwr_mode, 5306 NULL, &max_reg_bw)) 5307 return; 5308 5309 /* Regulatory does not support BW greater than 160. 5310 * Try finding a channel in a lower mode. 5311 */ 5312 if (max_reg_bw <= BW_160MHZ) { 5313 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5314 *update_bw = true; 5315 return; 5316 } 5317 5318 num_bonded_pairs = 5319 reg_get_320_bonded_chan_array(pdev, freq, band_center_320, 5320 bonded_chan_320mhz_list_freq, 5321 array_size, 5322 bonded_ch_ptr); 5323 5324 if (!num_bonded_pairs) { 5325 if (band_center_320) { 5326 reg_debug("No bonded pair for the given band_center\n"); 5327 chan_list->num_ch_params = 0; 5328 } else { 5329 /* Could not find a 320 MHZ bonded channel pair, 5330 * find a channel of lower BW. 5331 */ 5332 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5333 *update_bw = true; 5334 } 5335 return; 5336 } 5337 5338 for (i = 0, num_ch_params = 0 ; i < num_bonded_pairs; i++) { 5339 /* Chan_state to hold the channel state of bonding 5340 * pair of channels. 5341 */ 5342 chan_state = 5343 reg_get_320_bonded_channel_state_for_pwrmode(pdev, freq, 5344 bonded_ch_ptr[i], 5345 *in_ch_width, 5346 &out_punc_bitmap, 5347 in_6g_pwr_mode, 5348 treat_nol_chan_as_disabled); 5349 5350 if (reg_is_state_allowed(chan_state)) { 5351 struct ch_params *t_chan_param = 5352 &chan_list->chan_param[num_ch_params]; 5353 qdf_freq_t start_freq = bonded_ch_ptr[i]->start_freq; 5354 5355 t_chan_param->mhz_freq_seg1 = 5356 reg_get_band_cen_from_bandstart(BW_320_MHZ, 5357 start_freq); 5358 t_chan_param->center_freq_seg1 = 5359 reg_freq_to_chan(pdev, 5360 t_chan_param->mhz_freq_seg1); 5361 t_chan_param->ch_width = *in_ch_width; 5362 t_chan_param->reg_punc_bitmap = out_punc_bitmap; 5363 5364 reg_fill_chan320mhz_seg0_center(pdev, 5365 t_chan_param, 5366 freq); 5367 num_ch_params++; 5368 chan_list->num_ch_params = num_ch_params; 5369 } 5370 } 5371 5372 /* The bonded pairs could not create any channels, 5373 * lower the bandwidth to find a channel. 5374 */ 5375 if (!chan_list->num_ch_params) { 5376 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5377 *update_bw = true; 5378 } 5379 } 5380 #endif 5381 5382 /** 5383 * No subchannels are punctured 5384 * binary 1:- Punctured 0:- Not-Punctured. 5385 */ 5386 #define NO_SCHANS_PUNC 0x0000 5387 5388 /** 5389 * reg_fill_pre320mhz_channel() - Fill channel params for channel width 5390 * less than 320. 5391 * @pdev: Pointer to struct wlan_objmgr_pdev 5392 * @chan_list: Pointer to struct reg_channel_list 5393 * @ch_width: Channel width 5394 * @freq: Center frequency of the primary channel in MHz 5395 * @sec_ch_2g_freq: Secondary 2G channel frequency in MHZ 5396 * @treat_nol_chan_as_disabled: Bool to treat NOL channels as 5397 * disabled/enabled 5398 */ 5399 static void 5400 reg_fill_pre320mhz_channel(struct wlan_objmgr_pdev *pdev, 5401 struct reg_channel_list *chan_list, 5402 enum phy_ch_width ch_width, 5403 qdf_freq_t freq, 5404 qdf_freq_t sec_ch_2g_freq, 5405 bool treat_nol_chan_as_disabled) 5406 { 5407 chan_list->num_ch_params = 1; 5408 chan_list->chan_param[0].ch_width = ch_width; 5409 chan_list->chan_param[0].reg_punc_bitmap = NO_SCHANS_PUNC; 5410 reg_set_channel_params_for_freq(pdev, freq, sec_ch_2g_freq, 5411 &chan_list->chan_param[0], 5412 treat_nol_chan_as_disabled); 5413 } 5414 5415 #ifdef CONFIG_REG_6G_PWRMODE 5416 /** 5417 * reg_fill_pre320mhz_channel_for_pwrmode() - Fill channel params for channel 5418 * width less than 320. 5419 * @pdev: Pointer to struct wlan_objmgr_pdev 5420 * @chan_list: Pointer to struct reg_channel_list 5421 * @ch_width: Channel width 5422 * @freq: Center frequency of the primary channel in MHz 5423 * @sec_ch_2g_freq: Secondary 2G channel frequency in MHZ 5424 * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based 5425 * channel list will be chosen. 5426 * @treat_nol_chan_as_disabled: Bool to consider nol chan as enabled/disabled 5427 */ 5428 static void 5429 reg_fill_pre320mhz_channel_for_pwrmode( 5430 struct wlan_objmgr_pdev *pdev, 5431 struct reg_channel_list *chan_list, 5432 enum phy_ch_width ch_width, 5433 qdf_freq_t freq, 5434 qdf_freq_t sec_ch_2g_freq, 5435 enum supported_6g_pwr_types in_6g_pwr_mode, 5436 bool treat_nol_chan_as_disabled) 5437 { 5438 chan_list->num_ch_params = 1; 5439 chan_list->chan_param[0].ch_width = ch_width; 5440 chan_list->chan_param[0].reg_punc_bitmap = NO_SCHANS_PUNC; 5441 reg_set_channel_params_for_pwrmode(pdev, freq, sec_ch_2g_freq, 5442 &chan_list->chan_param[0], 5443 in_6g_pwr_mode, 5444 treat_nol_chan_as_disabled); 5445 } 5446 #endif 5447 5448 void 5449 reg_fill_channel_list(struct wlan_objmgr_pdev *pdev, 5450 qdf_freq_t freq, 5451 qdf_freq_t sec_ch_2g_freq, 5452 enum phy_ch_width in_ch_width, 5453 qdf_freq_t band_center_320, 5454 struct reg_channel_list *chan_list, 5455 bool treat_nol_chan_as_disabled) 5456 { 5457 bool update_bw; 5458 5459 if (!chan_list) { 5460 reg_err("channel params is NULL"); 5461 return; 5462 } 5463 5464 if (in_ch_width >= CH_WIDTH_MAX) 5465 in_ch_width = CH_WIDTH_320MHZ; 5466 5467 if (in_ch_width == CH_WIDTH_320MHZ) { 5468 update_bw = 0; 5469 reg_fill_channel_list_for_320(pdev, freq, &in_ch_width, 5470 band_center_320, chan_list, 5471 &update_bw, 5472 treat_nol_chan_as_disabled); 5473 if (!update_bw) 5474 return; 5475 } 5476 5477 /* A 320 channel is not available (or) user has not requested 5478 * for a 320MHZ channel, look for channels in lower modes, 5479 * reg_set_5g_channel_params_for_freq() finds for the 5480 * next available mode and fills ch_params. 5481 */ 5482 reg_fill_pre320mhz_channel(pdev, chan_list, in_ch_width, freq, 5483 sec_ch_2g_freq, 5484 treat_nol_chan_as_disabled); 5485 } 5486 5487 #ifdef CONFIG_REG_6G_PWRMODE 5488 void 5489 reg_fill_channel_list_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5490 qdf_freq_t freq, 5491 qdf_freq_t sec_ch_2g_freq, 5492 enum phy_ch_width in_ch_width, 5493 qdf_freq_t band_center_320, 5494 struct reg_channel_list *chan_list, 5495 enum supported_6g_pwr_types in_6g_pwr_mode, 5496 bool treat_nol_chan_as_disabled) 5497 { 5498 bool update_bw; 5499 5500 if (!chan_list) { 5501 reg_err("channel params is NULL"); 5502 return; 5503 } 5504 5505 if (in_ch_width >= CH_WIDTH_MAX) 5506 in_ch_width = CH_WIDTH_320MHZ; 5507 5508 if (in_ch_width == CH_WIDTH_320MHZ) { 5509 update_bw = 0; 5510 reg_fill_channel_list_for_320_for_pwrmode( 5511 pdev, freq, &in_ch_width, 5512 band_center_320, chan_list, 5513 &update_bw, in_6g_pwr_mode, 5514 treat_nol_chan_as_disabled); 5515 if (!update_bw) 5516 return; 5517 } 5518 5519 /* A 320 channel is not available (or) user has not requested 5520 * for a 320MHZ channel, look for channels in lower modes, 5521 * reg_set_5g_channel_params_for_freq() finds for the 5522 * next available mode and fills ch_params. 5523 */ 5524 reg_fill_pre320mhz_channel_for_pwrmode( 5525 pdev, chan_list, in_ch_width, freq, 5526 sec_ch_2g_freq, in_6g_pwr_mode, 5527 treat_nol_chan_as_disabled); 5528 } 5529 #endif 5530 #endif 5531 5532 enum channel_state 5533 reg_get_5g_bonded_channel_for_freq(struct wlan_objmgr_pdev *pdev, 5534 uint16_t freq, 5535 enum phy_ch_width ch_width, 5536 const struct bonded_channel_freq 5537 **bonded_chan_ptr_ptr) 5538 { 5539 if (ch_width == CH_WIDTH_20MHZ) 5540 return reg_get_channel_state_for_freq(pdev, freq); 5541 5542 if (reg_is_ch_width_320(ch_width)) { 5543 return reg_get_chan_state_for_320(pdev, freq, 0, 5544 ch_width, 5545 bonded_chan_ptr_ptr, 5546 REG_CURRENT_PWR_MODE, 5547 true); 5548 } else { 5549 *bonded_chan_ptr_ptr = reg_get_bonded_chan_entry(freq, 5550 ch_width, 0); 5551 if (!(*bonded_chan_ptr_ptr)) 5552 return CHANNEL_STATE_INVALID; 5553 5554 return reg_get_5g_bonded_chan_array_for_freq( 5555 pdev, freq, 5556 *bonded_chan_ptr_ptr); 5557 } 5558 } 5559 5560 #ifdef CONFIG_REG_6G_PWRMODE 5561 enum channel_state 5562 reg_get_5g_bonded_channel_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5563 uint16_t freq, 5564 enum phy_ch_width ch_width, 5565 const struct bonded_channel_freq 5566 **bonded_chan_ptr_ptr, 5567 enum supported_6g_pwr_types 5568 in_6g_pwr_mode) 5569 { 5570 if (ch_width == CH_WIDTH_20MHZ) 5571 return reg_get_channel_state_for_pwrmode(pdev, freq, 5572 in_6g_pwr_mode); 5573 5574 if (reg_is_ch_width_320(ch_width)) 5575 return reg_get_chan_state_for_320(pdev, freq, 0, 5576 ch_width, 5577 bonded_chan_ptr_ptr, 5578 in_6g_pwr_mode, true); 5579 /* Fetch the bonded_chan_ptr for width greater than 20MHZ. */ 5580 *bonded_chan_ptr_ptr = reg_get_bonded_chan_entry(freq, ch_width, 0); 5581 5582 if (!(*bonded_chan_ptr_ptr)) { 5583 reg_debug_rl("bonded_chan_ptr_ptr is NULL"); 5584 return CHANNEL_STATE_INVALID; 5585 } 5586 5587 return reg_get_5g_bonded_chan_array_for_pwrmode(pdev, freq, 5588 *bonded_chan_ptr_ptr, 5589 in_6g_pwr_mode); 5590 } 5591 #endif 5592 5593 /** 5594 * reg_set_5g_channel_params_for_freq()- Set channel parameters like center 5595 * frequency for a bonded channel state. Also return the maximum bandwidth 5596 * supported by the channel. 5597 * @pdev: Pointer to pdev. 5598 * @freq: Channel center frequency. 5599 * ch_params: Pointer to ch_params. 5600 * @treat_nol_chan_as_disabled: Flag to consider nol chan as enabled/disabled 5601 * 5602 * Return: void 5603 */ 5604 static void reg_set_5g_channel_params_for_freq(struct wlan_objmgr_pdev *pdev, 5605 uint16_t freq, 5606 struct ch_params *ch_params, 5607 bool treat_nol_chan_as_disabled) 5608 { 5609 /* 5610 * Set channel parameters like center frequency for a bonded channel 5611 * state. Also return the maximum bandwidth supported by the channel. 5612 */ 5613 5614 enum channel_state chan_state = CHANNEL_STATE_ENABLE; 5615 enum channel_state chan_state2 = CHANNEL_STATE_ENABLE; 5616 const struct bonded_channel_freq *bonded_chan_ptr = NULL; 5617 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5618 enum channel_enum chan_enum, sec_5g_chan_enum; 5619 uint16_t max_bw, bw_80, sec_5g_freq_max_bw = 0; 5620 5621 if (!ch_params) { 5622 reg_err("ch_params is NULL"); 5623 return; 5624 } 5625 5626 chan_enum = reg_get_chan_enum_for_freq(freq); 5627 if (reg_is_chan_enum_invalid(chan_enum)) { 5628 reg_err("chan freq is not valid"); 5629 return; 5630 } 5631 5632 pdev_priv_obj = reg_get_pdev_obj(pdev); 5633 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5634 reg_err("reg pdev priv obj is NULL"); 5635 return; 5636 } 5637 5638 if (ch_params->ch_width >= CH_WIDTH_MAX) { 5639 if (ch_params->mhz_freq_seg1 != 0) 5640 ch_params->ch_width = CH_WIDTH_80P80MHZ; 5641 else 5642 ch_params->ch_width = CH_WIDTH_160MHZ; 5643 } 5644 5645 max_bw = pdev_priv_obj->cur_chan_list[chan_enum].max_bw; 5646 bw_80 = reg_get_bw_value(CH_WIDTH_80MHZ); 5647 5648 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 5649 sec_5g_chan_enum = 5650 reg_get_chan_enum_for_freq(ch_params->mhz_freq_seg1 - 5651 NEAREST_20MHZ_CHAN_FREQ_OFFSET); 5652 if (reg_is_chan_enum_invalid(sec_5g_chan_enum)) { 5653 reg_err("secondary channel freq is not valid"); 5654 return; 5655 } 5656 5657 sec_5g_freq_max_bw = 5658 pdev_priv_obj->cur_chan_list[sec_5g_chan_enum].max_bw; 5659 } 5660 5661 while (ch_params->ch_width != CH_WIDTH_INVALID) { 5662 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 5663 if ((max_bw < bw_80) || (sec_5g_freq_max_bw < bw_80)) 5664 goto update_bw; 5665 } else if (max_bw < reg_get_bw_value(ch_params->ch_width)) { 5666 goto update_bw; 5667 } 5668 5669 bonded_chan_ptr = NULL; 5670 chan_state = reg_get_5g_bonded_channel_for_freq( 5671 pdev, freq, ch_params->ch_width, 5672 &bonded_chan_ptr); 5673 5674 chan_state = reg_get_ch_state_based_on_nol_flag(pdev, freq, 5675 ch_params, 5676 REG_CURRENT_PWR_MODE, 5677 treat_nol_chan_as_disabled); 5678 5679 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 5680 struct ch_params temp_ch_params = {0}; 5681 5682 temp_ch_params.ch_width = CH_WIDTH_80MHZ; 5683 /* Puncturing patter is not needed for 80+80 */ 5684 reg_set_create_punc_bitmap(&temp_ch_params, false); 5685 chan_state2 = 5686 reg_get_ch_state_based_on_nol_flag(pdev, 5687 ch_params->mhz_freq_seg1 - 5688 NEAREST_20MHZ_CHAN_FREQ_OFFSET, 5689 &temp_ch_params, REG_CURRENT_PWR_MODE, 5690 treat_nol_chan_as_disabled); 5691 chan_state = reg_combine_channel_states( 5692 chan_state, chan_state2); 5693 } 5694 5695 if ((chan_state != CHANNEL_STATE_ENABLE) && 5696 (chan_state != CHANNEL_STATE_DFS)) 5697 goto update_bw; 5698 if (ch_params->ch_width <= CH_WIDTH_20MHZ) { 5699 ch_params->sec_ch_offset = NO_SEC_CH; 5700 ch_params->mhz_freq_seg0 = freq; 5701 ch_params->center_freq_seg0 = 5702 reg_freq_to_chan(pdev, 5703 ch_params->mhz_freq_seg0); 5704 break; 5705 } else if (ch_params->ch_width >= CH_WIDTH_40MHZ) { 5706 const struct bonded_channel_freq *bonded_chan_ptr2; 5707 5708 bonded_chan_ptr2 = 5709 reg_get_bonded_chan_entry(freq, 5710 CH_WIDTH_40MHZ, 0); 5711 5712 if (!bonded_chan_ptr || !bonded_chan_ptr2) 5713 goto update_bw; 5714 if (freq == bonded_chan_ptr2->start_freq) 5715 ch_params->sec_ch_offset = LOW_PRIMARY_CH; 5716 else 5717 ch_params->sec_ch_offset = HIGH_PRIMARY_CH; 5718 5719 ch_params->mhz_freq_seg0 = 5720 (bonded_chan_ptr->start_freq + 5721 bonded_chan_ptr->end_freq) / 2; 5722 ch_params->center_freq_seg0 = 5723 reg_freq_to_chan(pdev, 5724 ch_params->mhz_freq_seg0); 5725 break; 5726 } 5727 update_bw: 5728 ch_params->ch_width = 5729 get_next_lower_bandwidth(ch_params->ch_width); 5730 } 5731 5732 if (ch_params->ch_width == CH_WIDTH_160MHZ) { 5733 ch_params->mhz_freq_seg1 = ch_params->mhz_freq_seg0; 5734 ch_params->center_freq_seg1 = 5735 reg_freq_to_chan(pdev, 5736 ch_params->mhz_freq_seg1); 5737 5738 chan_state = reg_get_5g_bonded_channel_for_freq( 5739 pdev, freq, CH_WIDTH_80MHZ, &bonded_chan_ptr); 5740 if (bonded_chan_ptr) { 5741 ch_params->mhz_freq_seg0 = 5742 (bonded_chan_ptr->start_freq + 5743 bonded_chan_ptr->end_freq) / 2; 5744 ch_params->center_freq_seg0 = 5745 reg_freq_to_chan(pdev, 5746 ch_params->mhz_freq_seg0); 5747 } 5748 } 5749 5750 /* Overwrite mhz_freq_seg1 to 0 for non 160 and 80+80 width */ 5751 if (!(ch_params->ch_width == CH_WIDTH_160MHZ || 5752 ch_params->ch_width == CH_WIDTH_80P80MHZ)) { 5753 ch_params->mhz_freq_seg1 = 0; 5754 ch_params->center_freq_seg1 = 0; 5755 } 5756 } 5757 5758 #ifdef CONFIG_REG_6G_PWRMODE 5759 /** 5760 * reg_set_5g_channel_params_for_pwrmode()- Set channel parameters like center 5761 * frequency for a bonded channel state. Also return the maximum bandwidth 5762 * supported by the channel. 5763 * @pdev: Pointer to pdev. 5764 * @freq: Channel center frequency. 5765 * ch_params: Pointer to ch_params. 5766 * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based 5767 * channel list will be chosen. 5768 * @treat_nol_chan_as_disabled: Bool to treat NOL channels as disabled/enabled 5769 * 5770 * Return: void 5771 */ 5772 static void reg_set_5g_channel_params_for_pwrmode( 5773 struct wlan_objmgr_pdev *pdev, 5774 uint16_t freq, 5775 struct ch_params *ch_params, 5776 enum supported_6g_pwr_types 5777 in_6g_pwr_type, 5778 bool treat_nol_chan_as_disabled) 5779 { 5780 /* 5781 * Set channel parameters like center frequency for a bonded channel 5782 * state. Also return the maximum bandwidth supported by the channel. 5783 */ 5784 5785 enum channel_state chan_state = CHANNEL_STATE_ENABLE; 5786 enum channel_state chan_state2 = CHANNEL_STATE_ENABLE; 5787 const struct bonded_channel_freq *bonded_chan_ptr = NULL; 5788 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5789 enum channel_enum chan_enum, sec_5g_chan_enum; 5790 uint16_t bw_80 = 0; 5791 uint16_t max_bw, sec_5g_freq_max_bw = 0; 5792 5793 if (!ch_params) { 5794 reg_err("ch_params is NULL"); 5795 return; 5796 } 5797 5798 chan_enum = reg_get_chan_enum_for_freq(freq); 5799 if (reg_is_chan_enum_invalid(chan_enum)) { 5800 reg_err("chan freq is not valid"); 5801 return; 5802 } 5803 5804 pdev_priv_obj = reg_get_pdev_obj(pdev); 5805 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5806 reg_err("reg pdev priv obj is NULL"); 5807 return; 5808 } 5809 5810 if (ch_params->ch_width >= CH_WIDTH_MAX) { 5811 if (ch_params->mhz_freq_seg1 != 0) 5812 ch_params->ch_width = CH_WIDTH_80P80MHZ; 5813 else 5814 ch_params->ch_width = CH_WIDTH_160MHZ; 5815 } 5816 5817 if (reg_get_min_max_bw_reg_chan_list(pdev, chan_enum, in_6g_pwr_type, 5818 NULL, &max_bw)) 5819 return; 5820 5821 bw_80 = reg_get_bw_value(CH_WIDTH_80MHZ); 5822 5823 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 5824 sec_5g_chan_enum = 5825 reg_get_chan_enum_for_freq(ch_params->mhz_freq_seg1 - 5826 NEAREST_20MHZ_CHAN_FREQ_OFFSET); 5827 if (reg_is_chan_enum_invalid(sec_5g_chan_enum)) { 5828 reg_err("secondary channel freq is not valid"); 5829 return; 5830 } 5831 5832 if (reg_get_min_max_bw_reg_chan_list(pdev, sec_5g_chan_enum, 5833 in_6g_pwr_type, 5834 NULL, &sec_5g_freq_max_bw)) 5835 return; 5836 } 5837 5838 while (ch_params->ch_width != CH_WIDTH_INVALID) { 5839 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 5840 if ((max_bw < bw_80) || (sec_5g_freq_max_bw < bw_80)) 5841 goto update_bw; 5842 } else if (max_bw < reg_get_bw_value(ch_params->ch_width)) { 5843 goto update_bw; 5844 } 5845 5846 bonded_chan_ptr = NULL; 5847 chan_state = reg_get_5g_bonded_channel_for_pwrmode( 5848 pdev, freq, ch_params->ch_width, 5849 &bonded_chan_ptr, in_6g_pwr_type); 5850 chan_state = 5851 reg_get_ch_state_based_on_nol_flag(pdev, freq, 5852 ch_params, 5853 in_6g_pwr_type, 5854 treat_nol_chan_as_disabled); 5855 5856 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 5857 struct ch_params temp_ch_params = {0}; 5858 5859 temp_ch_params.ch_width = CH_WIDTH_80MHZ; 5860 /* Puncturing patter is not needed for 80+80 */ 5861 reg_set_create_punc_bitmap(&temp_ch_params, false); 5862 chan_state2 = 5863 reg_get_ch_state_based_on_nol_flag(pdev, 5864 ch_params->mhz_freq_seg1 - 5865 NEAREST_20MHZ_CHAN_FREQ_OFFSET, 5866 &temp_ch_params, in_6g_pwr_type, 5867 treat_nol_chan_as_disabled); 5868 chan_state = reg_combine_channel_states( 5869 chan_state, chan_state2); 5870 } 5871 5872 if ((chan_state != CHANNEL_STATE_ENABLE) && 5873 (chan_state != CHANNEL_STATE_DFS)) 5874 goto update_bw; 5875 if (ch_params->ch_width <= CH_WIDTH_20MHZ) { 5876 ch_params->sec_ch_offset = NO_SEC_CH; 5877 ch_params->mhz_freq_seg0 = freq; 5878 ch_params->center_freq_seg0 = 5879 reg_freq_to_chan(pdev, 5880 ch_params->mhz_freq_seg0); 5881 break; 5882 } else if (ch_params->ch_width >= CH_WIDTH_40MHZ) { 5883 if (!bonded_chan_ptr) 5884 goto update_bw; 5885 if (freq == bonded_chan_ptr->start_freq) 5886 ch_params->sec_ch_offset = LOW_PRIMARY_CH; 5887 else 5888 ch_params->sec_ch_offset = HIGH_PRIMARY_CH; 5889 5890 ch_params->mhz_freq_seg0 = 5891 (bonded_chan_ptr->start_freq + 5892 bonded_chan_ptr->end_freq) / 2; 5893 ch_params->center_freq_seg0 = 5894 reg_freq_to_chan(pdev, 5895 ch_params->mhz_freq_seg0); 5896 break; 5897 } 5898 update_bw: 5899 ch_params->ch_width = 5900 get_next_lower_bandwidth(ch_params->ch_width); 5901 } 5902 5903 if (ch_params->ch_width == CH_WIDTH_160MHZ) { 5904 ch_params->mhz_freq_seg1 = ch_params->mhz_freq_seg0; 5905 ch_params->center_freq_seg1 = 5906 reg_freq_to_chan(pdev, 5907 ch_params->mhz_freq_seg1); 5908 5909 chan_state = reg_get_5g_bonded_channel_for_pwrmode( 5910 pdev, freq, CH_WIDTH_80MHZ, &bonded_chan_ptr, 5911 in_6g_pwr_type); 5912 if (bonded_chan_ptr) { 5913 ch_params->mhz_freq_seg0 = 5914 (bonded_chan_ptr->start_freq + 5915 bonded_chan_ptr->end_freq) / 2; 5916 ch_params->center_freq_seg0 = 5917 reg_freq_to_chan(pdev, 5918 ch_params->mhz_freq_seg0); 5919 } 5920 } 5921 5922 /* Overwrite mhz_freq_seg1 to 0 for non 160 and 80+80 width */ 5923 if (!(ch_params->ch_width == CH_WIDTH_160MHZ || 5924 ch_params->ch_width == CH_WIDTH_80P80MHZ)) { 5925 ch_params->mhz_freq_seg1 = 0; 5926 ch_params->center_freq_seg1 = 0; 5927 } 5928 } 5929 #endif 5930 5931 #ifdef CONFIG_REG_CLIENT 5932 static qdf_freq_t reg_get_sec_ch_2g_freq(struct wlan_objmgr_pdev *pdev, 5933 qdf_freq_t primary_freq) 5934 { 5935 qdf_freq_t sec_ch_2g_freq = 0; 5936 5937 if (primary_freq >= TWOG_CHAN_1_IN_MHZ && 5938 primary_freq <= TWOG_CHAN_5_IN_MHZ) 5939 sec_ch_2g_freq = primary_freq + HT40_SEC_OFFSET; 5940 else if (primary_freq >= TWOG_CHAN_6_IN_MHZ && 5941 primary_freq <= TWOG_CHAN_13_IN_MHZ) 5942 sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET; 5943 5944 return sec_ch_2g_freq; 5945 } 5946 #else 5947 static qdf_freq_t reg_get_sec_ch_2g_freq(struct wlan_objmgr_pdev *pdev, 5948 qdf_freq_t primary_freq) 5949 { 5950 qdf_freq_t sec_ch_2g_freq; 5951 5952 if (primary_freq < TWOG_CHAN_1_IN_MHZ || 5953 primary_freq > TWOG_CHAN_13_IN_MHZ) 5954 return 0; 5955 5956 sec_ch_2g_freq = primary_freq + HT40_SEC_OFFSET; 5957 5958 /* For 2G primary frequencies > 2452 (IEEE9), return HT40-. */ 5959 if (primary_freq > TWOG_CHAN_9_IN_MHZ) 5960 sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET; 5961 5962 /* 5963 * For 2G primary frequencies <= 2452 (IEEE9), return HT40+ if 5964 * the secondary is available, else return HT40-. 5965 */ 5966 else if (!reg_is_freq_present_in_cur_chan_list(pdev, sec_ch_2g_freq)) 5967 sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET; 5968 5969 return sec_ch_2g_freq; 5970 } 5971 #endif 5972 5973 void reg_set_2g_channel_params_for_freq(struct wlan_objmgr_pdev *pdev, 5974 uint16_t oper_freq, 5975 struct ch_params *ch_params, 5976 uint16_t sec_ch_2g_freq) 5977 { 5978 enum channel_state chan_state = CHANNEL_STATE_ENABLE; 5979 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5980 enum channel_enum chan_enum; 5981 uint16_t max_bw; 5982 5983 chan_enum = reg_get_chan_enum_for_freq(oper_freq); 5984 if (reg_is_chan_enum_invalid(chan_enum)) { 5985 reg_err("chan freq is not valid"); 5986 return; 5987 } 5988 5989 pdev_priv_obj = reg_get_pdev_obj(pdev); 5990 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5991 reg_err("reg pdev priv obj is NULL"); 5992 return; 5993 } 5994 5995 if (ch_params->ch_width >= CH_WIDTH_MAX) 5996 ch_params->ch_width = CH_WIDTH_40MHZ; 5997 if ((reg_get_bw_value(ch_params->ch_width) > 20) && !sec_ch_2g_freq) 5998 sec_ch_2g_freq = reg_get_sec_ch_2g_freq(pdev, oper_freq); 5999 6000 max_bw = pdev_priv_obj->cur_chan_list[chan_enum].max_bw; 6001 6002 while (ch_params->ch_width != CH_WIDTH_INVALID) { 6003 if (max_bw < reg_get_bw_value(ch_params->ch_width)) 6004 goto update_bw; 6005 6006 chan_state = 6007 reg_get_2g_bonded_channel_state_for_freq(pdev, oper_freq, 6008 sec_ch_2g_freq, 6009 ch_params->ch_width); 6010 if ((chan_state == CHANNEL_STATE_ENABLE) || 6011 (chan_state == CHANNEL_STATE_DFS)) { 6012 if (ch_params->ch_width == CH_WIDTH_40MHZ) { 6013 if (oper_freq < sec_ch_2g_freq) 6014 ch_params->sec_ch_offset = 6015 LOW_PRIMARY_CH; 6016 else 6017 ch_params->sec_ch_offset = 6018 HIGH_PRIMARY_CH; 6019 ch_params->mhz_freq_seg0 = 6020 (oper_freq + sec_ch_2g_freq) / 2; 6021 if (ch_params->mhz_freq_seg0 == 6022 TWOG_CHAN_14_IN_MHZ) 6023 ch_params->center_freq_seg0 = 14; 6024 else 6025 ch_params->center_freq_seg0 = 6026 (ch_params->mhz_freq_seg0 - 6027 TWOG_STARTING_FREQ) / 6028 FREQ_TO_CHAN_SCALE; 6029 } else { 6030 ch_params->sec_ch_offset = NO_SEC_CH; 6031 ch_params->mhz_freq_seg0 = oper_freq; 6032 if (ch_params->mhz_freq_seg0 == 6033 TWOG_CHAN_14_IN_MHZ) 6034 ch_params->center_freq_seg0 = 14; 6035 else 6036 ch_params->center_freq_seg0 = 6037 (ch_params->mhz_freq_seg0 - 6038 TWOG_STARTING_FREQ) / 6039 FREQ_TO_CHAN_SCALE; 6040 } 6041 break; 6042 } 6043 update_bw: 6044 ch_params->ch_width = 6045 get_next_lower_bandwidth(ch_params->ch_width); 6046 } 6047 /* Overwrite mhz_freq_seg1 and center_freq_seg1 to 0 for 2.4 Ghz */ 6048 ch_params->mhz_freq_seg1 = 0; 6049 ch_params->center_freq_seg1 = 0; 6050 } 6051 6052 #ifdef WLAN_FEATURE_11BE 6053 static void reg_copy_ch_params(struct ch_params *ch_params, 6054 struct reg_channel_list chan_list) 6055 { 6056 ch_params->center_freq_seg0 = chan_list.chan_param[0].center_freq_seg0; 6057 ch_params->center_freq_seg1 = chan_list.chan_param[0].center_freq_seg1; 6058 ch_params->mhz_freq_seg0 = chan_list.chan_param[0].mhz_freq_seg0; 6059 ch_params->mhz_freq_seg1 = chan_list.chan_param[0].mhz_freq_seg1; 6060 ch_params->ch_width = chan_list.chan_param[0].ch_width; 6061 ch_params->sec_ch_offset = chan_list.chan_param[0].sec_ch_offset; 6062 ch_params->reg_punc_bitmap = chan_list.chan_param[0].reg_punc_bitmap; 6063 } 6064 6065 void reg_set_channel_params_for_freq(struct wlan_objmgr_pdev *pdev, 6066 qdf_freq_t freq, 6067 qdf_freq_t sec_ch_2g_freq, 6068 struct ch_params *ch_params, 6069 bool treat_nol_chan_as_disabled) 6070 { 6071 if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) { 6072 if (reg_is_ch_width_320(ch_params->ch_width)) { 6073 struct reg_channel_list chan_list; 6074 6075 qdf_mem_zero(&chan_list, sizeof(chan_list)); 6076 /* For now sending center freq as 0 */ 6077 reg_fill_channel_list(pdev, freq, sec_ch_2g_freq, 6078 ch_params->ch_width, 0, 6079 &chan_list, 6080 treat_nol_chan_as_disabled); 6081 reg_copy_ch_params(ch_params, chan_list); 6082 } else { 6083 reg_set_5g_channel_params_for_freq(pdev, freq, 6084 ch_params, 6085 treat_nol_chan_as_disabled); 6086 } 6087 } else if (reg_is_24ghz_ch_freq(freq)) { 6088 reg_set_2g_channel_params_for_freq(pdev, freq, ch_params, 6089 sec_ch_2g_freq); 6090 } 6091 } 6092 #else /* WLAN_FEATURE_11BE */ 6093 void reg_set_channel_params_for_freq(struct wlan_objmgr_pdev *pdev, 6094 qdf_freq_t freq, 6095 qdf_freq_t sec_ch_2g_freq, 6096 struct ch_params *ch_params, 6097 bool treat_nol_chan_as_disabled) 6098 { 6099 if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) 6100 reg_set_5g_channel_params_for_freq(pdev, freq, ch_params, 6101 treat_nol_chan_as_disabled); 6102 else if (reg_is_24ghz_ch_freq(freq)) 6103 reg_set_2g_channel_params_for_freq(pdev, freq, ch_params, 6104 sec_ch_2g_freq); 6105 } 6106 #endif /* WLAN_FEATURE_11BE */ 6107 6108 #ifdef CONFIG_REG_6G_PWRMODE 6109 #ifdef WLAN_FEATURE_11BE 6110 void 6111 reg_set_channel_params_for_pwrmode(struct wlan_objmgr_pdev *pdev, 6112 qdf_freq_t freq, 6113 qdf_freq_t sec_ch_2g_freq, 6114 struct ch_params *ch_params, 6115 enum supported_6g_pwr_types in_6g_pwr_mode, 6116 bool is_treat_nol_dis) 6117 { 6118 if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) { 6119 if (reg_is_ch_width_320(ch_params->ch_width)) { 6120 struct reg_channel_list chan_list; 6121 6122 qdf_mem_zero(&chan_list, sizeof(chan_list)); 6123 /* For now sending center freq as 0 */ 6124 reg_fill_channel_list_for_pwrmode(pdev, freq, 6125 sec_ch_2g_freq, 6126 ch_params->ch_width, 6127 0, &chan_list, 6128 in_6g_pwr_mode, 6129 is_treat_nol_dis); 6130 reg_copy_ch_params(ch_params, chan_list); 6131 } else { 6132 reg_set_5g_channel_params_for_pwrmode(pdev, freq, 6133 ch_params, 6134 in_6g_pwr_mode, 6135 is_treat_nol_dis); 6136 } 6137 } else if (reg_is_24ghz_ch_freq(freq)) { 6138 reg_set_2g_channel_params_for_freq(pdev, freq, ch_params, 6139 sec_ch_2g_freq); 6140 } 6141 } 6142 #else 6143 void 6144 reg_set_channel_params_for_pwrmode(struct wlan_objmgr_pdev *pdev, 6145 qdf_freq_t freq, 6146 qdf_freq_t sec_ch_2g_freq, 6147 struct ch_params *ch_params, 6148 enum supported_6g_pwr_types in_6g_pwr_mode, 6149 bool is_treat_nol_dis) 6150 { 6151 if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) 6152 reg_set_5g_channel_params_for_pwrmode(pdev, freq, ch_params, 6153 in_6g_pwr_mode, 6154 is_treat_nol_dis); 6155 else if (reg_is_24ghz_ch_freq(freq)) 6156 reg_set_2g_channel_params_for_freq(pdev, freq, ch_params, 6157 sec_ch_2g_freq); 6158 } 6159 #endif 6160 #endif 6161 6162 uint8_t reg_get_channel_reg_power_for_freq(struct wlan_objmgr_pdev *pdev, 6163 qdf_freq_t freq) 6164 { 6165 enum channel_enum chan_enum; 6166 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6167 struct regulatory_channel *reg_channels; 6168 6169 chan_enum = reg_get_chan_enum_for_freq(freq); 6170 6171 if (reg_is_chan_enum_invalid(chan_enum)) { 6172 reg_err("channel is invalid"); 6173 return REG_INVALID_TXPOWER; 6174 } 6175 6176 pdev_priv_obj = reg_get_pdev_obj(pdev); 6177 6178 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6179 reg_err("reg pdev priv obj is NULL"); 6180 return REG_INVALID_TXPOWER; 6181 } 6182 6183 reg_channels = pdev_priv_obj->cur_chan_list; 6184 6185 return reg_channels[chan_enum].tx_power; 6186 } 6187 6188 bool reg_is_dfs_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 6189 { 6190 uint32_t chan_flags; 6191 6192 chan_flags = reg_get_channel_flags_for_freq(pdev, freq); 6193 6194 return chan_flags & REGULATORY_CHAN_RADAR; 6195 } 6196 6197 #ifdef CONFIG_REG_CLIENT 6198 bool reg_is_dfs_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev, 6199 qdf_freq_t freq) 6200 { 6201 uint32_t chan_flags; 6202 6203 chan_flags = reg_get_channel_flags_from_secondary_list_for_freq(pdev, 6204 freq); 6205 6206 return chan_flags & REGULATORY_CHAN_RADAR; 6207 } 6208 6209 /** 6210 * reg_get_psoc_mas_chan_list () - Get psoc master channel list 6211 * @pdev: pointer to pdev object 6212 * @psoc: pointer to psoc object 6213 * 6214 * Return: psoc master chanel list 6215 */ 6216 static struct regulatory_channel *reg_get_psoc_mas_chan_list( 6217 struct wlan_objmgr_pdev *pdev, 6218 struct wlan_objmgr_psoc *psoc) 6219 { 6220 struct wlan_regulatory_psoc_priv_obj *soc_reg; 6221 uint8_t pdev_id; 6222 uint8_t phy_id; 6223 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 6224 6225 soc_reg = reg_get_psoc_obj(psoc); 6226 if (!soc_reg) { 6227 reg_err("reg psoc private obj is NULL"); 6228 return NULL; 6229 } 6230 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 6231 6232 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 6233 if (reg_tx_ops->get_phy_id_from_pdev_id) 6234 reg_tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id); 6235 else 6236 phy_id = pdev_id; 6237 6238 return soc_reg->mas_chan_params[phy_id].mas_chan_list; 6239 } 6240 #else 6241 static inline struct regulatory_channel *reg_get_psoc_mas_chan_list( 6242 struct wlan_objmgr_pdev *pdev, 6243 struct wlan_objmgr_psoc *psoc) 6244 { 6245 return NULL; 6246 } 6247 #endif 6248 6249 void reg_update_nol_ch_for_freq(struct wlan_objmgr_pdev *pdev, 6250 uint16_t *chan_freq_list, 6251 uint8_t num_chan, 6252 bool nol_chan) 6253 { 6254 enum channel_enum chan_enum; 6255 struct regulatory_channel *mas_chan_list = NULL, *psoc_mas_chan_list; 6256 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6257 struct wlan_objmgr_psoc *psoc; 6258 uint16_t i; 6259 6260 if (!num_chan || !chan_freq_list) { 6261 reg_err("chan_freq_list or num_ch is NULL"); 6262 return; 6263 } 6264 6265 psoc = wlan_pdev_get_psoc(pdev); 6266 6267 6268 psoc_mas_chan_list = reg_get_psoc_mas_chan_list(pdev, psoc); 6269 pdev_priv_obj = reg_get_pdev_obj(pdev); 6270 6271 if (pdev_priv_obj) 6272 mas_chan_list = pdev_priv_obj->mas_chan_list; 6273 6274 for (i = 0; i < num_chan; i++) { 6275 chan_enum = reg_get_chan_enum_for_freq(chan_freq_list[i]); 6276 if (reg_is_chan_enum_invalid(chan_enum)) { 6277 reg_err("Invalid freq in nol list, freq %d", 6278 chan_freq_list[i]); 6279 continue; 6280 } 6281 if (mas_chan_list) 6282 mas_chan_list[chan_enum].nol_chan = nol_chan; 6283 if (psoc_mas_chan_list) 6284 psoc_mas_chan_list[chan_enum].nol_chan = nol_chan; 6285 } 6286 6287 if (!pdev_priv_obj) { 6288 reg_err("reg pdev private obj is NULL"); 6289 return; 6290 } 6291 6292 reg_compute_pdev_current_chan_list(pdev_priv_obj); 6293 6294 reg_send_scheduler_msg_sb(psoc, pdev); 6295 } 6296 6297 void reg_update_nol_history_ch_for_freq(struct wlan_objmgr_pdev *pdev, 6298 uint16_t *chan_list, 6299 uint8_t num_chan, 6300 bool nol_history_chan) 6301 { 6302 enum channel_enum chan_enum; 6303 struct regulatory_channel *mas_chan_list; 6304 struct regulatory_channel *cur_chan_list; 6305 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6306 uint16_t i; 6307 6308 if (!num_chan || !chan_list) { 6309 reg_err("chan_list or num_ch is NULL"); 6310 return; 6311 } 6312 6313 pdev_priv_obj = wlan_objmgr_pdev_get_comp_private_obj( 6314 pdev, WLAN_UMAC_COMP_REGULATORY); 6315 6316 if (!pdev_priv_obj) { 6317 reg_err("reg psoc private obj is NULL"); 6318 return; 6319 } 6320 6321 mas_chan_list = pdev_priv_obj->mas_chan_list; 6322 cur_chan_list = pdev_priv_obj->cur_chan_list; 6323 6324 for (i = 0; i < num_chan; i++) { 6325 chan_enum = reg_get_chan_enum_for_freq(chan_list[i]); 6326 if (reg_is_chan_enum_invalid(chan_enum)) { 6327 reg_err("Invalid ch in nol list, chan %d", 6328 chan_list[i]); 6329 continue; 6330 } 6331 mas_chan_list[chan_enum].nol_history = nol_history_chan; 6332 cur_chan_list[chan_enum].nol_history = nol_history_chan; 6333 } 6334 } 6335 6336 qdf_freq_t reg_min_chan_freq(void) 6337 { 6338 return channel_map[MIN_24GHZ_CHANNEL].center_freq; 6339 } 6340 6341 qdf_freq_t reg_max_chan_freq(void) 6342 { 6343 return channel_map[NUM_CHANNELS - 1].center_freq; 6344 } 6345 6346 bool reg_is_same_band_freqs(qdf_freq_t freq1, qdf_freq_t freq2) 6347 { 6348 return (freq1 && freq2 && ((REG_IS_6GHZ_FREQ(freq1) && 6349 REG_IS_6GHZ_FREQ(freq2)) || 6350 (REG_IS_5GHZ_FREQ(freq1) && 6351 REG_IS_5GHZ_FREQ(freq2)) || 6352 (REG_IS_24GHZ_CH_FREQ(freq1) && 6353 REG_IS_24GHZ_CH_FREQ(freq2)))); 6354 } 6355 6356 enum reg_wifi_band reg_freq_to_band(qdf_freq_t freq) 6357 { 6358 if (REG_IS_24GHZ_CH_FREQ(freq)) 6359 return REG_BAND_2G; 6360 else if (REG_IS_5GHZ_FREQ(freq) || REG_IS_49GHZ_FREQ(freq)) 6361 return REG_BAND_5G; 6362 else if (REG_IS_6GHZ_FREQ(freq)) 6363 return REG_BAND_6G; 6364 return REG_BAND_UNKNOWN; 6365 } 6366 6367 bool reg_is_disable_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 6368 { 6369 enum channel_state ch_state; 6370 6371 ch_state = reg_get_channel_state_for_freq(pdev, freq); 6372 6373 return ch_state == CHANNEL_STATE_DISABLE; 6374 } 6375 6376 #ifdef CONFIG_REG_6G_PWRMODE 6377 bool reg_is_disable_for_pwrmode(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq, 6378 enum supported_6g_pwr_types in_6g_pwr_mode) 6379 { 6380 enum channel_state ch_state; 6381 6382 ch_state = reg_get_channel_state_for_pwrmode(pdev, 6383 freq, 6384 in_6g_pwr_mode); 6385 6386 return ch_state == CHANNEL_STATE_DISABLE; 6387 } 6388 #endif 6389 6390 #ifdef CONFIG_REG_CLIENT 6391 bool reg_is_disable_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev, 6392 qdf_freq_t freq) 6393 { 6394 enum channel_state ch_state; 6395 6396 ch_state = reg_get_channel_state_from_secondary_list_for_freq(pdev, 6397 freq); 6398 6399 return ch_state == CHANNEL_STATE_DISABLE; 6400 } 6401 6402 bool reg_is_enable_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev, 6403 qdf_freq_t freq) 6404 { 6405 enum channel_state ch_state; 6406 6407 ch_state = reg_get_channel_state_from_secondary_list_for_freq(pdev, 6408 freq); 6409 6410 return ch_state == CHANNEL_STATE_ENABLE; 6411 } 6412 6413 #ifdef CONFIG_BAND_6GHZ 6414 static uint8_t reg_get_max_tx_power_from_super_chan_list( 6415 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 6416 enum supported_6g_pwr_types in_6g_pwr_type) 6417 { 6418 struct super_chan_info *sc_entry; 6419 enum supported_6g_pwr_types pwr_type; 6420 uint8_t i, max_tx_power = 0; 6421 6422 pwr_type = in_6g_pwr_type; 6423 for (i = 0; i < NUM_6GHZ_CHANNELS; i++) { 6424 sc_entry = &pdev_priv_obj->super_chan_list[i]; 6425 6426 if (in_6g_pwr_type == REG_BEST_PWR_MODE) 6427 pwr_type = sc_entry->best_power_mode; 6428 6429 if (reg_is_supp_pwr_mode_invalid(pwr_type)) 6430 continue; 6431 6432 if (!reg_is_chan_disabled(sc_entry->chan_flags_arr[pwr_type], 6433 sc_entry->state_arr[pwr_type]) && 6434 (sc_entry->reg_chan_pwr[pwr_type].tx_power > max_tx_power)) 6435 max_tx_power = 6436 sc_entry->reg_chan_pwr[pwr_type].tx_power; 6437 } 6438 return max_tx_power; 6439 } 6440 #else 6441 static inline uint8_t reg_get_max_tx_power_from_super_chan_list( 6442 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 6443 enum supported_6g_pwr_types in_6g_pwr_type) 6444 { 6445 return 0; 6446 } 6447 #endif 6448 6449 uint8_t reg_get_max_tx_power_for_pwr_mode( 6450 struct wlan_objmgr_pdev *pdev, 6451 enum supported_6g_pwr_types in_6g_pwr_type) 6452 { 6453 uint8_t i, max_tx_power = 0, max_super_chan_power = 0; 6454 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6455 uint16_t max_curr_num_chan; 6456 6457 if (!pdev) { 6458 reg_err_rl("invalid pdev"); 6459 return QDF_STATUS_E_INVAL; 6460 } 6461 6462 pdev_priv_obj = reg_get_pdev_obj(pdev); 6463 6464 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6465 reg_err_rl("reg pdev priv obj is NULL"); 6466 return QDF_STATUS_E_INVAL; 6467 } 6468 6469 if (in_6g_pwr_type == REG_CURRENT_PWR_MODE) 6470 max_curr_num_chan = NUM_CHANNELS; 6471 else 6472 max_curr_num_chan = MAX_5GHZ_CHANNEL; 6473 6474 for (i = 0; i < max_curr_num_chan; i++) { 6475 if (!reg_is_chan_disabled( 6476 pdev_priv_obj->cur_chan_list[i].chan_flags, 6477 pdev_priv_obj->cur_chan_list[i].state) && 6478 (pdev_priv_obj->cur_chan_list[i].tx_power > max_tx_power)) 6479 max_tx_power = 6480 pdev_priv_obj->cur_chan_list[i].tx_power; 6481 } 6482 6483 if (in_6g_pwr_type == REG_CURRENT_PWR_MODE) 6484 goto return_max_tx_power; 6485 6486 max_super_chan_power = reg_get_max_tx_power_from_super_chan_list( 6487 pdev_priv_obj, 6488 in_6g_pwr_type); 6489 6490 if (max_super_chan_power > max_tx_power) 6491 max_tx_power = max_super_chan_power; 6492 6493 return_max_tx_power: 6494 6495 if (!max_tx_power) 6496 reg_err_rl("max_tx_power is zero"); 6497 6498 return max_tx_power; 6499 } 6500 #endif 6501 6502 bool reg_is_passive_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 6503 { 6504 uint32_t chan_flags; 6505 6506 chan_flags = reg_get_channel_flags_for_freq(pdev, freq); 6507 6508 return chan_flags & REGULATORY_CHAN_NO_IR; 6509 } 6510 #endif /* CONFIG_CHAN_FREQ_API */ 6511 6512 uint8_t reg_get_max_tx_power(struct wlan_objmgr_pdev *pdev) 6513 { 6514 struct regulatory_channel *cur_chan_list; 6515 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6516 uint8_t i, max_tx_power = 0; 6517 6518 pdev_priv_obj = reg_get_pdev_obj(pdev); 6519 6520 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6521 reg_err("reg pdev private obj is NULL"); 6522 return QDF_STATUS_E_FAILURE; 6523 } 6524 6525 cur_chan_list = pdev_priv_obj->cur_chan_list; 6526 6527 for (i = 0; i < NUM_CHANNELS; i++) { 6528 if (cur_chan_list[i].state != CHANNEL_STATE_DISABLE && 6529 cur_chan_list[i].chan_flags != REGULATORY_CHAN_DISABLED) { 6530 if (cur_chan_list[i].tx_power > max_tx_power) 6531 max_tx_power = cur_chan_list[i].tx_power; 6532 } 6533 } 6534 6535 if (!max_tx_power) 6536 reg_err_rl("max_tx_power is zero"); 6537 6538 return max_tx_power; 6539 } 6540 6541 QDF_STATUS reg_set_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc) 6542 { 6543 struct wlan_regulatory_psoc_priv_obj *psoc_reg; 6544 6545 psoc_reg = reg_get_psoc_obj(psoc); 6546 if (!IS_VALID_PSOC_REG_OBJ(psoc_reg)) { 6547 reg_err("psoc reg component is NULL"); 6548 return QDF_STATUS_E_INVAL; 6549 } 6550 6551 psoc_reg->ignore_fw_reg_offload_ind = true; 6552 return QDF_STATUS_SUCCESS; 6553 } 6554 6555 bool reg_get_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc) 6556 { 6557 struct wlan_regulatory_psoc_priv_obj *psoc_reg; 6558 6559 psoc_reg = reg_get_psoc_obj(psoc); 6560 if (!IS_VALID_PSOC_REG_OBJ(psoc_reg)) 6561 return false; 6562 6563 return psoc_reg->ignore_fw_reg_offload_ind; 6564 } 6565 6566 QDF_STATUS reg_set_6ghz_supported(struct wlan_objmgr_psoc *psoc, bool val) 6567 { 6568 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6569 6570 psoc_priv_obj = reg_get_psoc_obj(psoc); 6571 6572 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6573 reg_err("psoc reg component is NULL"); 6574 return QDF_STATUS_E_FAILURE; 6575 } 6576 6577 psoc_priv_obj->six_ghz_supported = val; 6578 6579 return QDF_STATUS_SUCCESS; 6580 } 6581 6582 QDF_STATUS 6583 reg_set_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc, bool val) 6584 { 6585 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6586 6587 psoc_priv_obj = reg_get_psoc_obj(psoc); 6588 6589 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6590 reg_err("psoc reg component is NULL"); 6591 return QDF_STATUS_E_FAILURE; 6592 } 6593 6594 psoc_priv_obj->five_dot_nine_ghz_supported = val; 6595 6596 return QDF_STATUS_SUCCESS; 6597 } 6598 6599 #ifdef CONFIG_REG_CLIENT 6600 bool reg_is_6ghz_supported(struct wlan_objmgr_psoc *psoc) 6601 { 6602 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6603 6604 psoc_priv_obj = reg_get_psoc_obj(psoc); 6605 6606 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6607 reg_err("psoc reg component is NULL"); 6608 return false; 6609 } 6610 6611 return psoc_priv_obj->six_ghz_supported; 6612 } 6613 #endif 6614 6615 bool reg_is_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc) 6616 { 6617 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6618 6619 psoc_priv_obj = reg_get_psoc_obj(psoc); 6620 6621 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6622 reg_err("psoc reg component is NULL"); 6623 return false; 6624 } 6625 6626 return psoc_priv_obj->five_dot_nine_ghz_supported; 6627 } 6628 6629 bool reg_is_fcc_regdmn(struct wlan_objmgr_pdev *pdev) 6630 { 6631 struct cur_regdmn_info cur_reg_dmn; 6632 QDF_STATUS status; 6633 6634 status = reg_get_curr_regdomain(pdev, &cur_reg_dmn); 6635 if (status != QDF_STATUS_SUCCESS) { 6636 reg_err_rl("Failed to get reg domain"); 6637 return false; 6638 } 6639 6640 return reg_fcc_regdmn(cur_reg_dmn.dmn_id_5g); 6641 } 6642 6643 bool reg_is_5dot9_ghz_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 6644 { 6645 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6646 6647 pdev_priv_obj = reg_get_pdev_obj(pdev); 6648 6649 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6650 reg_err("reg pdev priv obj is NULL"); 6651 return false; 6652 } 6653 6654 return (freq >= channel_map_us[MIN_5DOT9_CHANNEL].center_freq && 6655 freq <= channel_map_us[MAX_5DOT9_CHANNEL].center_freq); 6656 } 6657 6658 bool reg_is_5dot9_ghz_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev) 6659 { 6660 struct wlan_objmgr_psoc *psoc; 6661 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6662 6663 if (!pdev) { 6664 reg_alert("pdev is NULL"); 6665 return true; 6666 } 6667 psoc = wlan_pdev_get_psoc(pdev); 6668 6669 psoc_priv_obj = reg_get_psoc_obj(psoc); 6670 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6671 reg_alert("psoc reg component is NULL"); 6672 return true; 6673 } 6674 6675 return psoc_priv_obj->enable_5dot9_ghz_chan_in_master_mode; 6676 } 6677 6678 #ifdef DISABLE_UNII_SHARED_BANDS 6679 QDF_STATUS 6680 reg_get_unii_5g_bitmap(struct wlan_objmgr_pdev *pdev, uint8_t *bitmap) 6681 { 6682 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6683 6684 pdev_priv_obj = reg_get_pdev_obj(pdev); 6685 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6686 reg_err_rl("pdev reg component is NULL"); 6687 return QDF_STATUS_E_FAILURE; 6688 } 6689 *bitmap = pdev_priv_obj->unii_5g_bitmap; 6690 6691 return QDF_STATUS_SUCCESS; 6692 } 6693 #endif 6694 6695 #ifdef WLAN_FEATURE_11BE 6696 bool reg_is_phymode_unallowed(enum reg_phymode phy_in, uint32_t phymode_bitmap) 6697 { 6698 if (!phymode_bitmap) 6699 return false; 6700 6701 if (phy_in == REG_PHYMODE_11BE) 6702 return phymode_bitmap & REGULATORY_PHYMODE_NO11BE; 6703 else if (phy_in == REG_PHYMODE_11AX) 6704 return phymode_bitmap & REGULATORY_PHYMODE_NO11AX; 6705 else if (phy_in == REG_PHYMODE_11AC) 6706 return phymode_bitmap & REGULATORY_PHYMODE_NO11AC; 6707 else if (phy_in == REG_PHYMODE_11N) 6708 return phymode_bitmap & REGULATORY_CHAN_NO11N; 6709 else if (phy_in == REG_PHYMODE_11G) 6710 return phymode_bitmap & REGULATORY_PHYMODE_NO11G; 6711 else if (phy_in == REG_PHYMODE_11A) 6712 return phymode_bitmap & REGULATORY_PHYMODE_NO11A; 6713 else if (phy_in == REG_PHYMODE_11B) 6714 return phymode_bitmap & REGULATORY_PHYMODE_NO11B; 6715 else 6716 return true; 6717 } 6718 #else 6719 bool reg_is_phymode_unallowed(enum reg_phymode phy_in, uint32_t phymode_bitmap) 6720 { 6721 if (!phymode_bitmap) 6722 return false; 6723 6724 if (phy_in == REG_PHYMODE_11AX) 6725 return phymode_bitmap & REGULATORY_PHYMODE_NO11AX; 6726 else if (phy_in == REG_PHYMODE_11AC) 6727 return phymode_bitmap & REGULATORY_PHYMODE_NO11AC; 6728 else if (phy_in == REG_PHYMODE_11N) 6729 return phymode_bitmap & REGULATORY_CHAN_NO11N; 6730 else if (phy_in == REG_PHYMODE_11G) 6731 return phymode_bitmap & REGULATORY_PHYMODE_NO11G; 6732 else if (phy_in == REG_PHYMODE_11A) 6733 return phymode_bitmap & REGULATORY_PHYMODE_NO11A; 6734 else if (phy_in == REG_PHYMODE_11B) 6735 return phymode_bitmap & REGULATORY_PHYMODE_NO11B; 6736 else 6737 return true; 6738 } 6739 #endif 6740 6741 #ifdef CHECK_REG_PHYMODE 6742 enum reg_phymode reg_get_max_phymode(struct wlan_objmgr_pdev *pdev, 6743 enum reg_phymode phy_in, 6744 qdf_freq_t freq) 6745 { 6746 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6747 uint32_t phymode_bitmap; 6748 enum reg_phymode current_phymode = phy_in; 6749 6750 pdev_priv_obj = reg_get_pdev_obj(pdev); 6751 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6752 reg_err("pdev reg component is NULL"); 6753 return REG_PHYMODE_INVALID; 6754 } 6755 6756 phymode_bitmap = pdev_priv_obj->phybitmap; 6757 6758 while (1) { 6759 if (reg_is_phymode_unallowed(current_phymode, phymode_bitmap)) { 6760 if (current_phymode == REG_PHYMODE_11N) { 6761 if (REG_IS_24GHZ_CH_FREQ(freq)) 6762 current_phymode = REG_PHYMODE_11G; 6763 else 6764 current_phymode = REG_PHYMODE_11A; 6765 } else if (current_phymode == REG_PHYMODE_11A || 6766 current_phymode == REG_PHYMODE_11B) { 6767 reg_err("Couldn't find a suitable phymode"); 6768 return REG_PHYMODE_INVALID; 6769 } else if (current_phymode > REG_PHYMODE_MAX) { 6770 reg_err("Unknown phymode"); 6771 return REG_PHYMODE_INVALID; 6772 } else { 6773 current_phymode--; 6774 } 6775 } else { 6776 return current_phymode; 6777 } 6778 } 6779 } 6780 #endif /* CHECK_REG_PHYMODE */ 6781 6782 #ifdef CONFIG_REG_CLIENT 6783 enum band_info reg_band_bitmap_to_band_info(uint32_t band_bitmap) 6784 { 6785 if ((band_bitmap & BIT(REG_BAND_2G)) && 6786 (band_bitmap & BIT(REG_BAND_5G)) && 6787 (band_bitmap & BIT(REG_BAND_6G))) 6788 return BAND_ALL; 6789 else if ((band_bitmap & BIT(REG_BAND_5G)) && 6790 (band_bitmap & BIT(REG_BAND_6G))) 6791 return BAND_5G; 6792 else if ((band_bitmap & BIT(REG_BAND_2G)) && 6793 (band_bitmap & BIT(REG_BAND_6G))) 6794 return BAND_2G; 6795 else if ((band_bitmap & BIT(REG_BAND_2G)) && 6796 (band_bitmap & BIT(REG_BAND_5G))) 6797 return BAND_ALL; 6798 else if (band_bitmap & BIT(REG_BAND_2G)) 6799 return BAND_2G; 6800 else if (band_bitmap & BIT(REG_BAND_5G)) 6801 return BAND_5G; 6802 else if (band_bitmap & BIT(REG_BAND_6G)) 6803 return BAND_2G; 6804 else 6805 return BAND_UNKNOWN; 6806 } 6807 #endif 6808 6809 #if defined(CONFIG_BAND_6GHZ) 6810 QDF_STATUS 6811 reg_set_cur_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev, 6812 enum reg_6g_ap_type reg_cur_6g_ap_pwr_type) 6813 { 6814 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6815 6816 pdev_priv_obj = reg_get_pdev_obj(pdev); 6817 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6818 reg_err("pdev reg component is NULL"); 6819 return QDF_STATUS_E_FAILURE; 6820 } 6821 6822 if (reg_cur_6g_ap_pwr_type > REG_MAX_SUPP_AP_TYPE) { 6823 reg_err("Unsupported 6G AP power type"); 6824 return QDF_STATUS_E_FAILURE; 6825 } 6826 /* should we validate the input reg_cur_6g_ap_type? */ 6827 pdev_priv_obj->reg_cur_6g_ap_pwr_type = reg_cur_6g_ap_pwr_type; 6828 return QDF_STATUS_SUCCESS; 6829 } 6830 6831 QDF_STATUS 6832 reg_get_cur_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev, 6833 enum reg_6g_ap_type *reg_cur_6g_ap_pwr_type) 6834 { 6835 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6836 6837 pdev_priv_obj = reg_get_pdev_obj(pdev); 6838 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6839 reg_err("pdev reg component is NULL"); 6840 return QDF_STATUS_E_FAILURE; 6841 } 6842 6843 if (pdev_priv_obj->reg_cur_6g_ap_pwr_type >= REG_CURRENT_MAX_AP_TYPE) 6844 return QDF_STATUS_E_FAILURE; 6845 6846 *reg_cur_6g_ap_pwr_type = pdev_priv_obj->reg_cur_6g_ap_pwr_type; 6847 6848 return QDF_STATUS_SUCCESS; 6849 } 6850 6851 /** 6852 * get_reg_rules_for_pdev() - Get the pointer to the reg rules for the pdev 6853 * @pdev: Pointer to pdev 6854 * 6855 * Return: Pointer to Standard Power regulatory rules 6856 */ 6857 static struct reg_rule_info * 6858 reg_get_reg_rules_for_pdev(struct wlan_objmgr_pdev *pdev) 6859 { 6860 struct wlan_objmgr_psoc *psoc; 6861 struct wlan_regulatory_psoc_priv_obj *psoc_reg_priv; 6862 uint8_t phy_id; 6863 struct reg_rule_info *psoc_reg_rules; 6864 6865 psoc = wlan_pdev_get_psoc(pdev); 6866 psoc_reg_priv = reg_get_psoc_obj(psoc); 6867 6868 if (!psoc_reg_priv) { 6869 reg_debug("Regulatory psoc private object is NULL"); 6870 return NULL; 6871 } 6872 6873 phy_id = wlan_objmgr_pdev_get_pdev_id(pdev); 6874 psoc_reg_rules = &psoc_reg_priv->mas_chan_params[phy_id].reg_rules; 6875 6876 return psoc_reg_rules; 6877 } 6878 6879 /** 6880 * reg_get_num_rules_of_ap_pwr_type() - Get the number of reg rules present 6881 * for a given ap power type 6882 * @pdev: Pointer to pdev 6883 * @ap_pwr_type: AP power type 6884 * 6885 * Return: Return the number of reg rules for a given ap power type 6886 */ 6887 static uint8_t 6888 reg_get_num_rules_of_ap_pwr_type(struct wlan_objmgr_pdev *pdev, 6889 enum reg_6g_ap_type ap_pwr_type) 6890 { 6891 struct reg_rule_info *psoc_reg_rules = reg_get_reg_rules_for_pdev(pdev); 6892 6893 if (!psoc_reg_rules) { 6894 reg_debug("No psoc_reg_rules"); 6895 return 0; 6896 } 6897 6898 if (ap_pwr_type > REG_MAX_SUPP_AP_TYPE) { 6899 reg_err("Unsupported 6G AP power type"); 6900 return 0; 6901 } 6902 6903 return psoc_reg_rules->num_of_6g_ap_reg_rules[ap_pwr_type]; 6904 } 6905 6906 #ifdef CONFIG_AFC_SUPPORT 6907 /** 6908 * reg_is_empty_range() - If both left, right frquency edges in the input range 6909 * are zero then the range is empty, else not. 6910 * @in_range: Pointer to input range 6911 * 6912 * Return: True if the range is empty, else false 6913 */ 6914 static bool reg_is_empty_range(struct freq_range *in_range) 6915 { 6916 return !in_range->left && !in_range->right; 6917 } 6918 6919 struct freq_range 6920 reg_init_freq_range(qdf_freq_t left, qdf_freq_t right) 6921 { 6922 struct freq_range out_range; 6923 6924 out_range.left = left; 6925 out_range.right = right; 6926 6927 return out_range; 6928 } 6929 6930 /** 6931 * reg_assign_vars_with_range_vals() - Assign input variables with the values of 6932 * the range variable values 6933 * @in_range: Pointer to input range object 6934 * @left: Pointer to the first variable to get the value of left frequency edge 6935 * @right: Pointer to the second variable to get the value of right frequency 6936 * edge 6937 * 6938 * Return: void 6939 */ 6940 static void 6941 reg_assign_vars_with_range_vals(struct freq_range *in_range, 6942 qdf_freq_t *left, 6943 qdf_freq_t *right) 6944 { 6945 *left = in_range->left; 6946 *right = in_range->right; 6947 } 6948 6949 /** 6950 * reg_intersect_ranges() - Intersect two ranges and return the intesected range 6951 * @first: Pointer to first input range 6952 * @second: Pointer to second input range 6953 * 6954 * Return: Intersected output range 6955 */ 6956 static struct freq_range 6957 reg_intersect_ranges(struct freq_range *first_range, 6958 struct freq_range *second_range) 6959 { 6960 struct freq_range out_range; 6961 qdf_freq_t l_freq; 6962 qdf_freq_t r_freq; 6963 6964 /* validate if the ranges are proper */ 6965 6966 l_freq = QDF_MAX(first_range->left, second_range->left); 6967 r_freq = QDF_MIN(first_range->right, second_range->right); 6968 6969 if (l_freq > r_freq) { 6970 l_freq = 0; 6971 l_freq = 0; 6972 6973 reg_debug("Ranges do not overlap first= [%u, %u], second = [%u, %u]", 6974 first_range->left, 6975 first_range->right, 6976 second_range->left, 6977 second_range->right); 6978 } 6979 6980 out_range.left = l_freq; 6981 out_range.right = r_freq; 6982 6983 return out_range; 6984 } 6985 6986 /** 6987 * reg_act_sp_rule_cb - A function pointer type that calculate something 6988 * from the input frequency range 6989 * @rule_fr: Pointer to frequencey range 6990 * @arg: Pointer to generic argument (a.k.a. context) 6991 * 6992 * Return: Void 6993 */ 6994 typedef void (*reg_act_sp_rule_cb)(struct freq_range *rule_fr, 6995 void *arg); 6996 6997 /** 6998 * reg_iterate_sp_rules() - Iterate through the Standard Power reg rules, for 6999 * every reg rule call the call back function to take some action or calculate 7000 * something 7001 * @pdev: Pointer to pdev 7002 * @pdev_priv_obj: Pointer to pdev private object 7003 * @action_on_sp_rule: A function pointer to take some action or calculate 7004 * something for every sp rule 7005 * @arg: Pointer to opque object (argument/context) 7006 * 7007 * Return: Void 7008 */ 7009 static void reg_iterate_sp_rules(struct wlan_objmgr_pdev *pdev, 7010 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 7011 reg_act_sp_rule_cb sp_rule_action, 7012 void *arg) 7013 { 7014 struct cur_reg_rule *p_sp_reg_rule; 7015 struct reg_rule_info *psoc_reg_rules; 7016 uint8_t n_6g_sp_ap_reg_rules; 7017 qdf_freq_t low_5g; 7018 qdf_freq_t high_5g; 7019 uint8_t i; 7020 struct freq_range chip_range; 7021 7022 psoc_reg_rules = reg_get_reg_rules_for_pdev(pdev); 7023 7024 if (!psoc_reg_rules) { 7025 reg_debug("psoc reg rule pointer is NULL"); 7026 return; 7027 } 7028 7029 n_6g_sp_ap_reg_rules = psoc_reg_rules->num_of_6g_ap_reg_rules[REG_STANDARD_POWER_AP]; 7030 p_sp_reg_rule = psoc_reg_rules->reg_rules_6g_ap[REG_STANDARD_POWER_AP]; 7031 7032 low_5g = pdev_priv_obj->range_5g_low; 7033 high_5g = pdev_priv_obj->range_5g_high; 7034 7035 chip_range = reg_init_freq_range(low_5g, high_5g); 7036 7037 reg_debug("chip_range = [%u, %u]", low_5g, high_5g); 7038 reg_debug("Num_6g_rules = %u", n_6g_sp_ap_reg_rules); 7039 7040 for (i = 0; i < n_6g_sp_ap_reg_rules; i++) { 7041 struct freq_range sp_range; 7042 struct freq_range out_range; 7043 7044 sp_range = reg_init_freq_range(p_sp_reg_rule->start_freq, 7045 p_sp_reg_rule->end_freq); 7046 reg_debug("Rule:[%u, %u]", 7047 p_sp_reg_rule->start_freq, 7048 p_sp_reg_rule->end_freq); 7049 out_range = reg_intersect_ranges(&chip_range, &sp_range); 7050 7051 if (sp_rule_action) 7052 sp_rule_action(&out_range, arg); 7053 7054 p_sp_reg_rule++; 7055 } 7056 } 7057 7058 /** 7059 * reg_afc_incr_num_ranges() - Increment the number of frequency ranges 7060 * @p_range: Pointer to frequency range 7061 * @num_freq_ranges: Pointer to number of frequency ranges. This needs to be 7062 * (Actual type: uint8_t *num_freq_ranges) 7063 * incremented by the function 7064 * 7065 * Return: Void 7066 */ 7067 static void reg_afc_incr_num_ranges(struct freq_range *p_range, 7068 void *num_freq_ranges) 7069 { 7070 if (!reg_is_empty_range(p_range)) 7071 (*(uint8_t *)num_freq_ranges)++; 7072 } 7073 7074 /** 7075 * reg_get_num_sp_freq_ranges() - Find the number of reg rules from the Standard 7076 * power regulatory rules 7077 * @pdev: Pointer to pdev 7078 * 7079 * Return: number of frequency ranges 7080 */ 7081 static uint8_t reg_get_num_sp_freq_ranges(struct wlan_objmgr_pdev *pdev, 7082 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 7083 { 7084 uint8_t num_freq_ranges; 7085 7086 num_freq_ranges = 0; 7087 reg_iterate_sp_rules(pdev, 7088 pdev_priv_obj, 7089 reg_afc_incr_num_ranges, 7090 &num_freq_ranges); 7091 7092 reg_debug("Num_freq_ranges=%u", num_freq_ranges); 7093 return num_freq_ranges; 7094 } 7095 7096 /** 7097 * reg_afc_get_intersected_ranges() - Get the intersected range into range obj 7098 * @rule_fr: Pointer to the rule for frequency range 7099 * @arg: Pointer to opaque object (argument/context) 7100 * (Actual type: struct wlan_afc_freq_range_obj **p_range_obj) 7101 * incremented by the function 7102 * 7103 * Return: Void 7104 */ 7105 static void reg_afc_get_intersected_ranges(struct freq_range *rule_fr, 7106 void *arg) 7107 { 7108 struct wlan_afc_freq_range_obj *p_range; 7109 struct wlan_afc_freq_range_obj **pp_range; 7110 qdf_freq_t low, high; 7111 7112 pp_range = (struct wlan_afc_freq_range_obj **)arg; 7113 p_range = *pp_range; 7114 7115 if (!reg_is_empty_range(rule_fr)) { 7116 reg_assign_vars_with_range_vals(rule_fr, &low, &high); 7117 p_range->lowfreq = (uint16_t)low; 7118 p_range->highfreq = (uint16_t)high; 7119 reg_debug("Range = [%u, %u]", p_range->lowfreq, p_range->highfreq); 7120 (*pp_range)++; 7121 } 7122 } 7123 7124 /** 7125 * reg_cp_freq_ranges() - Copy frequency ranges from the Standard power 7126 * regulatory rules 7127 * @pdev: Pointer to pdev 7128 * @pdev_priv_obj: Pointer to pdev private object 7129 * @num_freq_ranges: Number of frequency ranges 7130 * @p_range_obj: Pointer to range object 7131 * 7132 * Return: void 7133 */ 7134 static void reg_cp_freq_ranges(struct wlan_objmgr_pdev *pdev, 7135 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 7136 uint8_t num_freq_ranges, 7137 struct wlan_afc_freq_range_obj *p_range_obj) 7138 { 7139 struct wlan_afc_freq_range_obj *p_range; 7140 7141 reg_debug("Num freq ranges = %u", num_freq_ranges); 7142 7143 p_range = p_range_obj; 7144 reg_iterate_sp_rules(pdev, 7145 pdev_priv_obj, 7146 reg_afc_get_intersected_ranges, 7147 &p_range); 7148 } 7149 7150 /** 7151 * reg_get_frange_list_len() - Calculate the length of the list of the 7152 * frequency ranges 7153 * @num_freq_ranges: Number of frequency ranges 7154 * 7155 * Return: Length of the frequency range list 7156 */ 7157 static uint16_t reg_get_frange_list_len(uint8_t num_freq_ranges) 7158 { 7159 uint16_t frange_lst_len; 7160 7161 if (!num_freq_ranges) 7162 reg_err("AFC:There is no freq ranges"); 7163 7164 frange_lst_len = 7165 sizeof(struct wlan_afc_frange_list) + 7166 sizeof(struct wlan_afc_freq_range_obj) * num_freq_ranges; 7167 7168 return frange_lst_len; 7169 } 7170 7171 /** 7172 * reg_get_opclasses_array_len() - Calculate the length of the array of 7173 * opclasses objects 7174 * @num_opclasses: The number of opclasses 7175 * @chansize_lst: The array of sizes of channel lists 7176 * 7177 * Return: Length of the array of opclass object 7178 */ 7179 static uint16_t reg_get_opclasses_array_len(struct wlan_objmgr_pdev *pdev, 7180 uint8_t num_opclasses, 7181 uint8_t *chansize_lst) 7182 { 7183 uint16_t opclasses_arr_len = 0; 7184 uint16_t i; 7185 7186 for (i = 0; i < num_opclasses; i++) { 7187 opclasses_arr_len += 7188 sizeof(struct wlan_afc_opclass_obj) + 7189 sizeof(uint8_t) * chansize_lst[i]; 7190 } 7191 7192 return opclasses_arr_len; 7193 } 7194 7195 /** 7196 * reg_get_afc_req_length() - Calculate the length of the AFC partial request 7197 * @num_opclasses: The number of opclasses 7198 * @num_freq_ranges: The number of frequency ranges 7199 * @chansize_lst: The array of sizes of channel lists 7200 * 7201 * Return: Length of the partial AFC request 7202 */ 7203 static uint16_t reg_get_afc_req_length(struct wlan_objmgr_pdev *pdev, 7204 uint8_t num_opclasses, 7205 uint8_t num_freq_ranges, 7206 uint8_t *chansize_lst) 7207 { 7208 uint16_t afc_req_len; 7209 uint16_t frange_lst_len; 7210 uint16_t fixed_param_len; 7211 uint16_t num_opclasses_len; 7212 uint16_t opclasses_arr_len; 7213 uint16_t afc_location_len; 7214 7215 fixed_param_len = sizeof(struct wlan_afc_host_req_fixed_params); 7216 frange_lst_len = reg_get_frange_list_len(num_freq_ranges); 7217 num_opclasses_len = sizeof(struct wlan_afc_num_opclasses); 7218 opclasses_arr_len = reg_get_opclasses_array_len(pdev, 7219 num_opclasses, 7220 chansize_lst); 7221 afc_location_len = sizeof(struct wlan_afc_location); 7222 7223 afc_req_len = 7224 fixed_param_len + 7225 frange_lst_len + 7226 num_opclasses_len + 7227 opclasses_arr_len + 7228 afc_location_len; 7229 7230 return afc_req_len; 7231 } 7232 7233 /** 7234 * reg_fill_afc_fixed_params() - Fill the AFC fixed params 7235 * @p_fixed_params: Pointer to afc fixed params object 7236 * @afc_req_len: Length of the partial AFC request 7237 * 7238 * Return: Void 7239 */ 7240 static inline void 7241 reg_fill_afc_fixed_params(struct wlan_afc_host_req_fixed_params *p_fixed_params, 7242 uint16_t afc_req_len) 7243 { 7244 p_fixed_params->req_length = afc_req_len; 7245 p_fixed_params->req_id = DEFAULT_REQ_ID; 7246 p_fixed_params->min_des_power = DEFAULT_MIN_POWER; 7247 } 7248 7249 /** 7250 * reg_fill_afc_freq_ranges() - Fill the AFC fixed params 7251 * @pdev: Pointer to pdev 7252 * @pdev_priv_obj: Pointer to pdev private object 7253 * @p_frange_lst: Pointer to frequency range list 7254 * @num_freq_ranges: Number of frequency ranges 7255 * 7256 * Return: Void 7257 */ 7258 static inline void 7259 reg_fill_afc_freq_ranges(struct wlan_objmgr_pdev *pdev, 7260 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 7261 struct wlan_afc_frange_list *p_frange_lst, 7262 uint8_t num_freq_ranges) 7263 { 7264 struct wlan_afc_freq_range_obj *p_range_obj; 7265 7266 p_frange_lst->num_ranges = num_freq_ranges; 7267 7268 p_range_obj = &p_frange_lst->range_objs[0]; 7269 7270 reg_cp_freq_ranges(pdev, pdev_priv_obj, num_freq_ranges, p_range_obj); 7271 } 7272 7273 /** 7274 * reg_fill_afc_opclass_obj() - Fill the opclass object and return pointer to 7275 * next AFC opclass object 7276 * @p_obj_opclass_obj: Pointer to opclass object 7277 * @opclass: Operating class 7278 * @num_chans: Number of channels in the opclass 7279 * @p_chan_lst: Pointer to channel list 7280 * 7281 * Return: Pointer to the next AFC opclass object 7282 */ 7283 static struct wlan_afc_opclass_obj * 7284 reg_fill_afc_opclass_obj(struct wlan_afc_opclass_obj *p_obj_opclass_obj, 7285 uint8_t opclass, 7286 uint8_t num_chans, 7287 uint8_t *p_chan_lst) 7288 { 7289 uint16_t len_obj; 7290 uint8_t *out_p; 7291 uint8_t *src, *dst; 7292 uint8_t copy_len; 7293 7294 p_obj_opclass_obj->opclass_num_cfis = num_chans; 7295 p_obj_opclass_obj->opclass = opclass; 7296 src = p_chan_lst; 7297 dst = p_obj_opclass_obj->cfis; 7298 copy_len = num_chans * sizeof(uint8_t); 7299 7300 qdf_mem_copy(dst, src, copy_len); 7301 7302 len_obj = sizeof(struct wlan_afc_opclass_obj) + copy_len; 7303 out_p = (uint8_t *)p_obj_opclass_obj + len_obj; 7304 7305 return (struct wlan_afc_opclass_obj *)out_p; 7306 } 7307 7308 /** 7309 * reg_fill_afc_opclasses_arr() - Fill the array of opclass objects 7310 * @num_opclasses: The number of opclasses 7311 * @opclass_lst: The array of Operating classes 7312 * @chansize_lst: The array of sizes of channel lists 7313 * @channel_lists: The array of channel lists 7314 * @p_opclass_obj_arr: Pointer to the first opclass object 7315 * 7316 * Return: Pointer to the end of last opclass object 7317 */ 7318 static inline struct wlan_afc_opclass_obj * 7319 reg_fill_afc_opclasses_arr(struct wlan_objmgr_pdev *pdev, 7320 uint8_t num_opclasses, 7321 uint8_t *opclass_lst, 7322 uint8_t *chansize_lst, 7323 uint8_t *channel_lists[], 7324 struct wlan_afc_opclass_obj *p_opclass_obj_arr) 7325 { 7326 uint16_t i; 7327 struct wlan_afc_opclass_obj *p_opclass_obj; 7328 7329 p_opclass_obj = p_opclass_obj_arr; 7330 7331 for (i = 0; i < num_opclasses; i++) { 7332 p_opclass_obj = reg_fill_afc_opclass_obj(p_opclass_obj, 7333 opclass_lst[i], 7334 chansize_lst[i], 7335 channel_lists[i]); 7336 } 7337 return p_opclass_obj; 7338 } 7339 7340 /** 7341 * reg_next_opcls_ptr() - Get the pointer to the next opclass object 7342 * @p_cur_opcls_obj: Pointer to the current operating class object 7343 * @num_cfis: number of center frequencey indices 7344 * 7345 * Return: Pointer to next opclss object 7346 */ 7347 static struct wlan_afc_opclass_obj * 7348 reg_next_opcls_ptr(struct wlan_afc_opclass_obj *p_cur_opcls_obj, 7349 uint8_t num_cfis) 7350 { 7351 uint8_t cur_obj_sz; 7352 uint8_t fixed_opcls_sz; 7353 struct wlan_afc_opclass_obj *p_next_opcls_obj; 7354 uint8_t *p_tmp_next; 7355 7356 fixed_opcls_sz = sizeof(struct wlan_afc_opclass_obj); 7357 cur_obj_sz = fixed_opcls_sz + num_cfis * sizeof(uint8_t); 7358 p_tmp_next = (uint8_t *)p_cur_opcls_obj + cur_obj_sz; 7359 p_next_opcls_obj = (struct wlan_afc_opclass_obj *)p_tmp_next; 7360 7361 return p_next_opcls_obj; 7362 } 7363 7364 void reg_print_partial_afc_req_info(struct wlan_objmgr_pdev *pdev, 7365 struct wlan_afc_host_partial_request *afc_req) 7366 { 7367 struct wlan_afc_host_req_fixed_params *p_fixed_params; 7368 struct wlan_afc_frange_list *p_frange_lst; 7369 struct wlan_afc_num_opclasses *p_num_opclasses; 7370 uint8_t i; 7371 uint8_t j; 7372 uint16_t frange_lst_len; 7373 uint8_t num_opclasses; 7374 struct wlan_afc_opclass_obj *p_obj_opclass_arr; 7375 struct wlan_afc_opclass_obj *p_opclass_obj; 7376 uint8_t num_freq_ranges; 7377 uint8_t *p_temp; 7378 struct wlan_afc_location *p_afc_location; 7379 uint8_t *deployment_type_str; 7380 7381 p_fixed_params = &afc_req->fixed_params; 7382 reg_debug("req_length=%hu", p_fixed_params->req_length); 7383 reg_debug("req_id=%llu", p_fixed_params->req_id); 7384 reg_debug("min_des_power=%hd", p_fixed_params->min_des_power); 7385 7386 p_temp = (uint8_t *)p_fixed_params; 7387 p_temp += sizeof(*p_fixed_params); 7388 p_frange_lst = (struct wlan_afc_frange_list *)p_temp; 7389 reg_debug("num_ranges=%hhu", p_frange_lst->num_ranges); 7390 for (i = 0; i < p_frange_lst->num_ranges; i++) { 7391 struct wlan_afc_freq_range_obj *p_range_obj; 7392 7393 p_range_obj = &p_frange_lst->range_objs[i]; 7394 reg_debug("lowfreq=%hu", p_range_obj->lowfreq); 7395 reg_debug("highfreq=%hu", p_range_obj->highfreq); 7396 } 7397 7398 num_freq_ranges = p_frange_lst->num_ranges; 7399 frange_lst_len = reg_get_frange_list_len(num_freq_ranges); 7400 p_temp += frange_lst_len; 7401 p_num_opclasses = (struct wlan_afc_num_opclasses *)p_temp; 7402 num_opclasses = p_num_opclasses->num_opclasses; 7403 reg_debug("num_opclasses=%hhu", num_opclasses); 7404 7405 p_temp += sizeof(*p_num_opclasses); 7406 p_obj_opclass_arr = (struct wlan_afc_opclass_obj *)p_temp; 7407 p_opclass_obj = p_obj_opclass_arr; 7408 for (i = 0; i < num_opclasses; i++) { 7409 uint8_t opclass = p_opclass_obj->opclass; 7410 uint8_t num_cfis = p_opclass_obj->opclass_num_cfis; 7411 uint8_t *cfis = p_opclass_obj->cfis; 7412 7413 reg_debug("opclass[%hhu]=%hhu", i, opclass); 7414 reg_debug("num_cfis[%hhu]=%hhu", i, num_cfis); 7415 reg_debug("["); 7416 for (j = 0; j < num_cfis; j++) 7417 reg_debug("%hhu,", cfis[j]); 7418 reg_debug("]"); 7419 7420 p_opclass_obj = reg_next_opcls_ptr(p_opclass_obj, num_cfis); 7421 } 7422 7423 p_afc_location = (struct wlan_afc_location *)p_opclass_obj; 7424 switch (p_afc_location->deployment_type) { 7425 case AFC_DEPLOYMENT_INDOOR: 7426 deployment_type_str = "Indoor"; 7427 break; 7428 case AFC_DEPLOYMENT_OUTDOOR: 7429 deployment_type_str = "Outdoor"; 7430 break; 7431 default: 7432 deployment_type_str = "Unknown"; 7433 } 7434 reg_debug("AFC location=%s", deployment_type_str); 7435 } 7436 7437 /** 7438 * reg_get_frange_filled_buf() - Allocate and fill the frange buffer and return 7439 * the buffer. Also return the number of frequence ranges 7440 * @pdev: Pointer to pdev 7441 * @pdev_priv_obj: Pointer to pdev private object 7442 * @num_freq_ranges: Pointer to number of frequency ranges (output param) 7443 * 7444 * Return: Pointer to the frange buffer 7445 */ 7446 static struct wlan_afc_frange_list * 7447 reg_get_frange_filled_buf(struct wlan_objmgr_pdev *pdev, 7448 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 7449 uint8_t *num_freq_ranges) 7450 { 7451 uint16_t frange_lst_len; 7452 struct wlan_afc_frange_list *p_frange_lst_local; 7453 7454 *num_freq_ranges = reg_get_num_sp_freq_ranges(pdev, pdev_priv_obj); 7455 frange_lst_len = reg_get_frange_list_len(*num_freq_ranges); 7456 7457 p_frange_lst_local = qdf_mem_malloc(frange_lst_len); 7458 if (!p_frange_lst_local) 7459 return NULL; 7460 7461 reg_fill_afc_freq_ranges(pdev, 7462 pdev_priv_obj, 7463 p_frange_lst_local, 7464 *num_freq_ranges); 7465 return p_frange_lst_local; 7466 } 7467 7468 QDF_STATUS 7469 reg_get_partial_afc_req_info(struct wlan_objmgr_pdev *pdev, 7470 struct wlan_afc_host_partial_request **afc_req) 7471 { 7472 /* allocate the memory for the partial request */ 7473 struct wlan_afc_host_partial_request *temp_afc_req; 7474 struct wlan_afc_host_req_fixed_params *p_fixed_params; 7475 struct wlan_afc_frange_list *p_frange_lst_local; 7476 struct wlan_afc_frange_list *p_frange_lst_afc; 7477 struct wlan_afc_num_opclasses *p_num_opclasses; 7478 uint16_t afc_req_len; 7479 uint16_t frange_lst_len; 7480 uint8_t num_freq_ranges; 7481 uint8_t num_opclasses; 7482 struct wlan_afc_opclass_obj *p_obj_opclass_arr; 7483 struct wlan_afc_location *p_afc_location; 7484 7485 uint8_t *opclass_lst; 7486 uint8_t *chansize_lst; 7487 uint8_t **channel_lists; 7488 QDF_STATUS status; 7489 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7490 7491 if (!afc_req) { 7492 reg_err("afc_req is NULL"); 7493 status = QDF_STATUS_E_INVAL; 7494 return status; 7495 } 7496 7497 temp_afc_req = NULL; 7498 pdev_priv_obj = reg_get_pdev_obj(pdev); 7499 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7500 reg_err("pdev reg component is NULL"); 7501 status = QDF_STATUS_E_INVAL; 7502 goto handle_invalid_priv_object; 7503 } 7504 7505 p_frange_lst_local = reg_get_frange_filled_buf(pdev, 7506 pdev_priv_obj, 7507 &num_freq_ranges); 7508 if (!p_frange_lst_local) { 7509 reg_err("Frange lst not allocated"); 7510 status = QDF_STATUS_E_NOMEM; 7511 goto handle_invalid_priv_object; 7512 } 7513 7514 status = reg_dmn_get_6g_opclasses_and_channels(pdev, 7515 p_frange_lst_local, 7516 &num_opclasses, 7517 &opclass_lst, 7518 &chansize_lst, 7519 &channel_lists); 7520 if (status != QDF_STATUS_SUCCESS) { 7521 reg_err("Opclasses and chans not allocated"); 7522 status = QDF_STATUS_E_NOMEM; 7523 goto free_frange_lst_local; 7524 } 7525 7526 afc_req_len = reg_get_afc_req_length(pdev, 7527 num_opclasses, 7528 num_freq_ranges, 7529 chansize_lst); 7530 7531 temp_afc_req = qdf_mem_malloc(afc_req_len); 7532 if (!temp_afc_req) { 7533 reg_err("AFC request not allocated"); 7534 status = QDF_STATUS_E_NOMEM; 7535 goto free_opcls_chan_mem; 7536 } 7537 7538 p_fixed_params = &temp_afc_req->fixed_params; 7539 reg_fill_afc_fixed_params(p_fixed_params, afc_req_len); 7540 7541 /* frange list is already filled just copy it */ 7542 frange_lst_len = reg_get_frange_list_len(num_freq_ranges); 7543 p_frange_lst_afc = (struct wlan_afc_frange_list *)&p_fixed_params[1]; 7544 qdf_mem_copy(p_frange_lst_afc, p_frange_lst_local, frange_lst_len); 7545 7546 p_num_opclasses = (struct wlan_afc_num_opclasses *) 7547 ((char *)(p_frange_lst_afc) + frange_lst_len); 7548 p_num_opclasses->num_opclasses = num_opclasses; 7549 7550 p_obj_opclass_arr = (struct wlan_afc_opclass_obj *)&p_num_opclasses[1]; 7551 p_obj_opclass_arr = reg_fill_afc_opclasses_arr(pdev, 7552 num_opclasses, 7553 opclass_lst, 7554 chansize_lst, 7555 channel_lists, 7556 p_obj_opclass_arr); 7557 7558 p_afc_location = (struct wlan_afc_location *)p_obj_opclass_arr; 7559 p_afc_location->deployment_type = 7560 pdev_priv_obj->reg_afc_dev_deployment_type; 7561 p_afc_location->afc_elem_type = AFC_OBJ_LOCATION; 7562 p_afc_location->afc_elem_len = 7563 sizeof(*p_afc_location) - 7564 sizeof(p_afc_location->afc_elem_type) - 7565 sizeof(p_afc_location->afc_elem_len); 7566 free_opcls_chan_mem: 7567 reg_dmn_free_6g_opclasses_and_channels(pdev, 7568 num_opclasses, 7569 opclass_lst, 7570 chansize_lst, 7571 channel_lists); 7572 7573 free_frange_lst_local: 7574 qdf_mem_free(p_frange_lst_local); 7575 7576 handle_invalid_priv_object: 7577 *afc_req = temp_afc_req; 7578 7579 return status; 7580 } 7581 7582 void reg_dmn_set_afc_req_id(struct wlan_afc_host_partial_request *afc_req, 7583 uint64_t req_id) 7584 { 7585 struct wlan_afc_host_req_fixed_params *p_fixed_params; 7586 7587 p_fixed_params = &afc_req->fixed_params; 7588 p_fixed_params->req_id = req_id; 7589 } 7590 7591 /** 7592 * reg_send_afc_partial_request() - Send AFC partial request to registered 7593 * recipient 7594 * @pdev: Pointer to pdev 7595 * @afc_req: Pointer to afc partial request 7596 * 7597 * Return: void 7598 */ 7599 static 7600 void reg_send_afc_partial_request(struct wlan_objmgr_pdev *pdev, 7601 struct wlan_afc_host_partial_request *afc_req) 7602 { 7603 afc_req_rx_evt_handler cbf; 7604 void *arg; 7605 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7606 7607 pdev_priv_obj = reg_get_pdev_obj(pdev); 7608 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7609 reg_err("pdev reg component is NULL"); 7610 return; 7611 } 7612 7613 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7614 cbf = pdev_priv_obj->afc_cb_obj.func; 7615 if (cbf) { 7616 arg = pdev_priv_obj->afc_cb_obj.arg; 7617 cbf(pdev, afc_req, arg); 7618 } 7619 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7620 } 7621 7622 QDF_STATUS reg_afc_start(struct wlan_objmgr_pdev *pdev, uint64_t req_id) 7623 { 7624 struct wlan_afc_host_partial_request *afc_req; 7625 QDF_STATUS status; 7626 7627 status = reg_get_partial_afc_req_info(pdev, &afc_req); 7628 if (status != QDF_STATUS_SUCCESS) { 7629 reg_err("Creating AFC Request failed"); 7630 return QDF_STATUS_E_FAILURE; 7631 } 7632 7633 QDF_TRACE(QDF_MODULE_ID_AFC, QDF_TRACE_LEVEL_DEBUG, 7634 "Processing AFC Start/Renew Expiry event"); 7635 7636 reg_dmn_set_afc_req_id(afc_req, req_id); 7637 7638 reg_print_partial_afc_req_info(pdev, afc_req); 7639 7640 reg_send_afc_partial_request(pdev, afc_req); 7641 7642 qdf_mem_free(afc_req); 7643 7644 return QDF_STATUS_SUCCESS; 7645 } 7646 7647 QDF_STATUS reg_send_afc_power_event(struct wlan_objmgr_pdev *pdev, 7648 struct reg_fw_afc_power_event *power_info) 7649 { 7650 afc_power_tx_evt_handler cbf; 7651 void *arg; 7652 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7653 7654 pdev_priv_obj = reg_get_pdev_obj(pdev); 7655 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7656 reg_err("pdev reg component is NULL"); 7657 return QDF_STATUS_E_FAILURE; 7658 } 7659 7660 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7661 cbf = pdev_priv_obj->afc_pow_evt_cb_obj.func; 7662 if (cbf) { 7663 arg = pdev_priv_obj->afc_pow_evt_cb_obj.arg; 7664 cbf(pdev, power_info, arg); 7665 } 7666 7667 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7668 7669 return QDF_STATUS_SUCCESS; 7670 } 7671 7672 QDF_STATUS reg_register_afc_req_rx_callback(struct wlan_objmgr_pdev *pdev, 7673 afc_req_rx_evt_handler cbf, 7674 void *arg) 7675 { 7676 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7677 7678 pdev_priv_obj = reg_get_pdev_obj(pdev); 7679 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7680 reg_err("pdev reg component is NULL"); 7681 return QDF_STATUS_E_FAILURE; 7682 } 7683 7684 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7685 pdev_priv_obj->afc_cb_obj.func = cbf; 7686 pdev_priv_obj->afc_cb_obj.arg = arg; 7687 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7688 reg_debug("afc_event_cb: 0x%pK, arg: 0x%pK", cbf, arg); 7689 7690 return QDF_STATUS_SUCCESS; 7691 } 7692 7693 QDF_STATUS reg_unregister_afc_req_rx_callback(struct wlan_objmgr_pdev *pdev, 7694 afc_req_rx_evt_handler cbf) 7695 { 7696 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7697 7698 pdev_priv_obj = reg_get_pdev_obj(pdev); 7699 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7700 reg_err("pdev reg component is NULL"); 7701 return QDF_STATUS_E_FAILURE; 7702 } 7703 7704 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7705 if (pdev_priv_obj->afc_cb_obj.func == cbf) { 7706 pdev_priv_obj->afc_cb_obj.func = NULL; 7707 pdev_priv_obj->afc_cb_obj.arg = NULL; 7708 } else { 7709 reg_err("cb function=0x%pK not found", cbf); 7710 } 7711 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7712 7713 return QDF_STATUS_SUCCESS; 7714 } 7715 7716 QDF_STATUS 7717 reg_register_afc_power_event_callback(struct wlan_objmgr_pdev *pdev, 7718 afc_power_tx_evt_handler cbf, 7719 void *arg) 7720 { 7721 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7722 7723 pdev_priv_obj = reg_get_pdev_obj(pdev); 7724 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7725 reg_err("pdev reg component is NULL"); 7726 return QDF_STATUS_E_FAILURE; 7727 } 7728 7729 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7730 pdev_priv_obj->afc_pow_evt_cb_obj.func = cbf; 7731 pdev_priv_obj->afc_pow_evt_cb_obj.arg = arg; 7732 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7733 reg_debug("afc_power_event_cb: 0x%pK, arg: 0x%pK", cbf, arg); 7734 7735 return QDF_STATUS_SUCCESS; 7736 } 7737 7738 QDF_STATUS 7739 reg_unregister_afc_power_event_callback(struct wlan_objmgr_pdev *pdev, 7740 afc_power_tx_evt_handler cbf) 7741 { 7742 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7743 7744 pdev_priv_obj = reg_get_pdev_obj(pdev); 7745 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7746 reg_err("pdev reg component is NULL"); 7747 return QDF_STATUS_E_FAILURE; 7748 } 7749 7750 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7751 if (pdev_priv_obj->afc_pow_evt_cb_obj.func == cbf) { 7752 pdev_priv_obj->afc_pow_evt_cb_obj.func = NULL; 7753 pdev_priv_obj->afc_pow_evt_cb_obj.arg = NULL; 7754 } else { 7755 reg_err("cb function=0x%pK not found", cbf); 7756 } 7757 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7758 7759 return QDF_STATUS_SUCCESS; 7760 } 7761 7762 QDF_STATUS 7763 reg_get_afc_dev_deploy_type(struct wlan_objmgr_pdev *pdev, 7764 enum reg_afc_dev_deploy_type *reg_afc_dev_type) 7765 { 7766 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7767 7768 pdev_priv_obj = reg_get_pdev_obj(pdev); 7769 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7770 reg_err("pdev reg component is NULL"); 7771 return QDF_STATUS_E_FAILURE; 7772 } 7773 7774 *reg_afc_dev_type = pdev_priv_obj->reg_afc_dev_deployment_type; 7775 7776 return QDF_STATUS_SUCCESS; 7777 } 7778 7779 bool 7780 reg_is_sta_connect_allowed(struct wlan_objmgr_pdev *pdev, 7781 enum reg_6g_ap_type root_ap_pwr_mode) 7782 { 7783 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7784 7785 pdev_priv_obj = reg_get_pdev_obj(pdev); 7786 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7787 reg_err("pdev reg component is NULL"); 7788 return false; 7789 } 7790 7791 if (reg_get_num_rules_of_ap_pwr_type(pdev, REG_STANDARD_POWER_AP) && 7792 (pdev_priv_obj->reg_afc_dev_deployment_type == AFC_DEPLOYMENT_OUTDOOR)) { 7793 if (root_ap_pwr_mode == REG_STANDARD_POWER_AP) 7794 return true; 7795 else 7796 return false; 7797 } 7798 7799 return true; 7800 } 7801 7802 QDF_STATUS reg_set_afc_soc_dev_type(struct wlan_objmgr_psoc *psoc, 7803 enum reg_afc_dev_deploy_type 7804 reg_afc_dev_type) 7805 { 7806 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7807 7808 psoc_priv_obj = reg_get_psoc_obj(psoc); 7809 7810 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 7811 reg_err("psoc reg component is NULL"); 7812 return QDF_STATUS_E_FAILURE; 7813 } 7814 7815 psoc_priv_obj->reg_afc_dev_type = reg_afc_dev_type; 7816 7817 return QDF_STATUS_SUCCESS; 7818 } 7819 7820 QDF_STATUS 7821 reg_get_afc_soc_dev_type(struct wlan_objmgr_psoc *psoc, 7822 enum reg_afc_dev_deploy_type *reg_afc_dev_type) 7823 { 7824 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7825 7826 psoc_priv_obj = reg_get_psoc_obj(psoc); 7827 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 7828 reg_err("psoc reg component is NULL"); 7829 return QDF_STATUS_E_FAILURE; 7830 } 7831 7832 *reg_afc_dev_type = psoc_priv_obj->reg_afc_dev_type; 7833 7834 return QDF_STATUS_SUCCESS; 7835 } 7836 #endif /* CONFIG_AFC_SUPPORT */ 7837 7838 QDF_STATUS 7839 reg_get_cur_6g_client_type(struct wlan_objmgr_pdev *pdev, 7840 enum reg_6g_client_type 7841 *reg_cur_6g_client_mobility_type) 7842 { 7843 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7844 7845 pdev_priv_obj = reg_get_pdev_obj(pdev); 7846 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7847 reg_err("pdev reg component is NULL"); 7848 return QDF_STATUS_E_FAILURE; 7849 } 7850 7851 if (pdev_priv_obj->reg_cur_6g_client_mobility_type >= 7852 REG_MAX_CLIENT_TYPE) 7853 return QDF_STATUS_E_FAILURE; 7854 7855 *reg_cur_6g_client_mobility_type = 7856 pdev_priv_obj->reg_cur_6g_client_mobility_type; 7857 7858 return QDF_STATUS_SUCCESS; 7859 } 7860 7861 QDF_STATUS reg_get_rnr_tpe_usable(struct wlan_objmgr_pdev *pdev, 7862 bool *reg_rnr_tpe_usable) 7863 { 7864 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7865 7866 pdev_priv_obj = reg_get_pdev_obj(pdev); 7867 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7868 reg_err("pdev reg component is NULL"); 7869 return QDF_STATUS_E_FAILURE; 7870 } 7871 *reg_rnr_tpe_usable = pdev_priv_obj->reg_rnr_tpe_usable; 7872 return QDF_STATUS_SUCCESS; 7873 } 7874 7875 QDF_STATUS reg_get_unspecified_ap_usable(struct wlan_objmgr_pdev *pdev, 7876 bool *reg_unspecified_ap_usable) 7877 { 7878 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7879 7880 pdev_priv_obj = reg_get_pdev_obj(pdev); 7881 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7882 reg_err("pdev reg component is NULL"); 7883 return QDF_STATUS_E_FAILURE; 7884 } 7885 *reg_unspecified_ap_usable = pdev_priv_obj->reg_unspecified_ap_usable; 7886 return QDF_STATUS_SUCCESS; 7887 } 7888 7889 QDF_STATUS 7890 reg_find_txpower_from_6g_list(qdf_freq_t freq, 7891 struct regulatory_channel *chan_list, 7892 uint16_t *txpower) 7893 { 7894 enum channel_enum chan_enum; 7895 7896 *txpower = 0; 7897 7898 for (chan_enum = 0; chan_enum < NUM_6GHZ_CHANNELS; chan_enum++) { 7899 if (chan_list[chan_enum].center_freq == freq) { 7900 *txpower = chan_list[chan_enum].tx_power; 7901 return QDF_STATUS_SUCCESS; 7902 } 7903 } 7904 7905 return QDF_STATUS_E_FAILURE; 7906 } 7907 7908 bool reg_is_6g_psd_power(struct wlan_objmgr_pdev *pdev) 7909 { 7910 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7911 struct regulatory_channel *cur_chan_list; 7912 enum channel_enum i; 7913 7914 if (!pdev) { 7915 reg_err("pdev is NULL"); 7916 return false; 7917 } 7918 7919 pdev_priv_obj = reg_get_pdev_obj(pdev); 7920 if (!pdev_priv_obj) { 7921 reg_err("pdev priv obj is NULL"); 7922 return false; 7923 } 7924 7925 cur_chan_list = pdev_priv_obj->cur_chan_list; 7926 7927 for (i = MIN_6GHZ_CHANNEL; i <= MAX_6GHZ_CHANNEL; i++) { 7928 if (!(cur_chan_list[i].chan_flags & REGULATORY_CHAN_DISABLED)) 7929 return cur_chan_list[i].psd_flag; 7930 } 7931 7932 return false; 7933 } 7934 7935 QDF_STATUS 7936 reg_get_6g_chan_psd_eirp_power(qdf_freq_t freq, 7937 struct regulatory_channel *mas_chan_list, 7938 uint16_t *eirp_psd_power) 7939 { 7940 uint16_t i; 7941 7942 for (i = 0; i < NUM_6GHZ_CHANNELS; i++) { 7943 if (freq == mas_chan_list[i].center_freq) { 7944 *eirp_psd_power = mas_chan_list[i].psd_eirp; 7945 return QDF_STATUS_SUCCESS; 7946 } 7947 } 7948 7949 return QDF_STATUS_E_FAILURE; 7950 } 7951 7952 QDF_STATUS reg_get_6g_chan_ap_power(struct wlan_objmgr_pdev *pdev, 7953 qdf_freq_t chan_freq, bool *is_psd, 7954 uint16_t *tx_power, 7955 uint16_t *eirp_psd_power) 7956 { 7957 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7958 struct regulatory_channel *master_chan_list; 7959 enum reg_6g_ap_type ap_pwr_type; 7960 QDF_STATUS status = QDF_STATUS_SUCCESS; 7961 7962 pdev_priv_obj = reg_get_pdev_obj(pdev); 7963 if (!pdev_priv_obj) { 7964 reg_err("pdev priv obj is NULL"); 7965 return QDF_STATUS_E_FAILURE; 7966 } 7967 7968 status = reg_get_cur_6g_ap_pwr_type(pdev, &ap_pwr_type); 7969 if (!QDF_IS_STATUS_SUCCESS(status)) 7970 return status; 7971 7972 master_chan_list = pdev_priv_obj->mas_chan_list_6g_ap[ap_pwr_type]; 7973 7974 reg_find_txpower_from_6g_list(chan_freq, master_chan_list, 7975 tx_power); 7976 7977 *is_psd = reg_is_6g_psd_power(pdev); 7978 if (*is_psd) 7979 status = reg_get_6g_chan_psd_eirp_power(chan_freq, 7980 master_chan_list, 7981 eirp_psd_power); 7982 7983 return status; 7984 } 7985 7986 QDF_STATUS reg_get_client_power_for_connecting_ap(struct wlan_objmgr_pdev *pdev, 7987 enum reg_6g_ap_type ap_type, 7988 qdf_freq_t chan_freq, 7989 bool is_psd, 7990 uint16_t *tx_power, 7991 uint16_t *eirp_psd_power) 7992 { 7993 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7994 enum reg_6g_client_type client_type; 7995 struct regulatory_channel *master_chan_list; 7996 QDF_STATUS status = QDF_STATUS_SUCCESS; 7997 7998 pdev_priv_obj = reg_get_pdev_obj(pdev); 7999 if (!pdev_priv_obj) { 8000 reg_err("pdev priv obj is NULL"); 8001 return QDF_STATUS_E_FAILURE; 8002 } 8003 8004 reg_get_cur_6g_client_type(pdev, &client_type); 8005 8006 master_chan_list = 8007 pdev_priv_obj->mas_chan_list_6g_client[ap_type][client_type]; 8008 8009 reg_find_txpower_from_6g_list(chan_freq, master_chan_list, 8010 tx_power); 8011 8012 if (is_psd) 8013 status = reg_get_6g_chan_psd_eirp_power(chan_freq, 8014 master_chan_list, 8015 eirp_psd_power); 8016 8017 return status; 8018 } 8019 8020 QDF_STATUS reg_get_client_power_for_6ghz_ap(struct wlan_objmgr_pdev *pdev, 8021 enum reg_6g_client_type client_type, 8022 qdf_freq_t chan_freq, 8023 bool *is_psd, uint16_t *tx_power, 8024 uint16_t *eirp_psd_power) 8025 { 8026 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8027 enum reg_6g_ap_type ap_pwr_type; 8028 struct regulatory_channel *master_chan_list; 8029 QDF_STATUS status = QDF_STATUS_SUCCESS; 8030 8031 status = reg_get_cur_6g_ap_pwr_type(pdev, &ap_pwr_type); 8032 if (!QDF_IS_STATUS_SUCCESS(status)) 8033 return status; 8034 8035 pdev_priv_obj = reg_get_pdev_obj(pdev); 8036 if (!pdev_priv_obj) { 8037 reg_err("pdev priv obj is NULL"); 8038 return QDF_STATUS_E_FAILURE; 8039 } 8040 8041 master_chan_list = pdev_priv_obj-> 8042 mas_chan_list_6g_client[ap_pwr_type][client_type]; 8043 8044 reg_find_txpower_from_6g_list(chan_freq, master_chan_list, 8045 tx_power); 8046 8047 *is_psd = reg_is_6g_psd_power(pdev); 8048 if (*is_psd) 8049 status = reg_get_6g_chan_psd_eirp_power(chan_freq, 8050 master_chan_list, 8051 eirp_psd_power); 8052 8053 return status; 8054 } 8055 8056 QDF_STATUS reg_set_ap_pwr_and_update_chan_list(struct wlan_objmgr_pdev *pdev, 8057 enum reg_6g_ap_type ap_pwr_type) 8058 { 8059 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8060 QDF_STATUS status; 8061 8062 pdev_priv_obj = reg_get_pdev_obj(pdev); 8063 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8064 reg_err("pdev reg component is NULL"); 8065 return QDF_STATUS_E_INVAL; 8066 } 8067 8068 if (!reg_get_num_rules_of_ap_pwr_type(pdev, ap_pwr_type)) 8069 return QDF_STATUS_E_FAILURE; 8070 8071 status = reg_set_cur_6g_ap_pwr_type(pdev, ap_pwr_type); 8072 if (QDF_IS_STATUS_ERROR(status)) { 8073 reg_debug("failed to set AP power type to %d", ap_pwr_type); 8074 return status; 8075 } 8076 8077 reg_compute_pdev_current_chan_list(pdev_priv_obj); 8078 8079 return QDF_STATUS_SUCCESS; 8080 } 8081 #endif 8082 8083 bool reg_is_regdb_offloaded(struct wlan_objmgr_psoc *psoc) 8084 { 8085 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8086 8087 psoc_priv_obj = reg_get_psoc_obj(psoc); 8088 if (!psoc_priv_obj) { 8089 reg_err("reg psoc private obj is NULL"); 8090 return false; 8091 } 8092 8093 return psoc_priv_obj->offload_enabled; 8094 } 8095 8096 QDF_STATUS 8097 reg_set_ext_tpc_supported(struct wlan_objmgr_psoc *psoc, bool val) 8098 { 8099 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8100 8101 psoc_priv_obj = reg_get_psoc_obj(psoc); 8102 8103 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8104 reg_err("psoc reg component is NULL"); 8105 return QDF_STATUS_E_FAILURE; 8106 } 8107 8108 psoc_priv_obj->is_ext_tpc_supported = val; 8109 8110 return QDF_STATUS_SUCCESS; 8111 } 8112 8113 bool reg_is_ext_tpc_supported(struct wlan_objmgr_psoc *psoc) 8114 { 8115 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8116 8117 psoc_priv_obj = reg_get_psoc_obj(psoc); 8118 8119 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8120 reg_err("psoc reg component is NULL"); 8121 return false; 8122 } 8123 8124 return psoc_priv_obj->is_ext_tpc_supported; 8125 } 8126 8127 #if defined(CONFIG_BAND_6GHZ) 8128 QDF_STATUS 8129 reg_set_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc, bool val) 8130 { 8131 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8132 8133 psoc_priv_obj = reg_get_psoc_obj(psoc); 8134 8135 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8136 reg_err("psoc reg component is NULL"); 8137 return QDF_STATUS_E_FAILURE; 8138 } 8139 8140 psoc_priv_obj->is_lower_6g_edge_ch_supported = val; 8141 8142 return QDF_STATUS_SUCCESS; 8143 } 8144 8145 QDF_STATUS 8146 reg_set_disable_upper_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc, bool val) 8147 { 8148 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8149 8150 psoc_priv_obj = reg_get_psoc_obj(psoc); 8151 8152 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8153 reg_err("psoc reg component is NULL"); 8154 return QDF_STATUS_E_FAILURE; 8155 } 8156 8157 psoc_priv_obj->is_upper_6g_edge_ch_disabled = val; 8158 8159 return QDF_STATUS_SUCCESS; 8160 } 8161 8162 bool reg_is_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc) 8163 { 8164 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8165 8166 psoc_priv_obj = reg_get_psoc_obj(psoc); 8167 8168 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8169 reg_err("psoc reg component is NULL"); 8170 return false; 8171 } 8172 8173 return psoc_priv_obj->is_lower_6g_edge_ch_supported; 8174 } 8175 8176 bool reg_is_upper_6g_edge_ch_disabled(struct wlan_objmgr_psoc *psoc) 8177 { 8178 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8179 8180 psoc_priv_obj = reg_get_psoc_obj(psoc); 8181 8182 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 8183 reg_err("psoc reg component is NULL"); 8184 return false; 8185 } 8186 8187 return psoc_priv_obj->is_upper_6g_edge_ch_disabled; 8188 } 8189 8190 static inline bool reg_is_within_range_inclusive(enum channel_enum left, 8191 enum channel_enum right, 8192 enum channel_enum idx) 8193 { 8194 return (idx >= left) && (idx <= right); 8195 } 8196 8197 uint16_t reg_convert_enum_to_6g_idx(enum channel_enum ch_idx) 8198 { 8199 if (!reg_is_within_range_inclusive(MIN_6GHZ_CHANNEL, 8200 MAX_6GHZ_CHANNEL, 8201 ch_idx)) 8202 return INVALID_CHANNEL; 8203 8204 return (ch_idx - MIN_6GHZ_CHANNEL); 8205 } 8206 8207 QDF_STATUS 8208 reg_get_superchan_entry(struct wlan_objmgr_pdev *pdev, 8209 enum channel_enum chan_enum, 8210 const struct super_chan_info **p_sup_chan_entry) 8211 { 8212 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8213 uint16_t sup_idx; 8214 8215 sup_idx = reg_convert_enum_to_6g_idx(chan_enum); 8216 8217 if (reg_is_chan_enum_invalid(sup_idx)) { 8218 reg_debug("super channel idx is invalid for the chan_enum %d", 8219 chan_enum); 8220 return QDF_STATUS_E_INVAL; 8221 } 8222 8223 pdev_priv_obj = reg_get_pdev_obj(pdev); 8224 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8225 reg_err_rl("pdev reg component is NULL"); 8226 return QDF_STATUS_E_INVAL; 8227 } 8228 8229 if (!p_sup_chan_entry) { 8230 reg_err_rl("p_sup_chan_entry is NULL"); 8231 return QDF_STATUS_E_INVAL; 8232 } 8233 8234 if (sup_idx >= NUM_6GHZ_CHANNELS) { 8235 reg_debug("sup_idx is out of bounds"); 8236 return QDF_STATUS_E_INVAL; 8237 } 8238 8239 *p_sup_chan_entry = &pdev_priv_obj->super_chan_list[sup_idx]; 8240 8241 return QDF_STATUS_SUCCESS; 8242 } 8243 #endif 8244 8245 #ifdef FEATURE_WLAN_CH_AVOID_EXT 8246 /** 8247 * reg_process_ch_avoid_freq_ext() - Update extended avoid frequencies in 8248 * psoc_priv_obj 8249 * @psoc: Pointer to psoc structure 8250 * @pdev: pointer to pdev object 8251 * 8252 * Return: None 8253 */ 8254 static QDF_STATUS 8255 reg_process_ch_avoid_freq_ext(struct wlan_objmgr_psoc *psoc, 8256 struct wlan_objmgr_pdev *pdev) 8257 { 8258 uint32_t i; 8259 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8260 uint8_t start_channel; 8261 uint8_t end_channel; 8262 int32_t txpower; 8263 bool is_valid_txpower; 8264 struct ch_avoid_freq_type *range; 8265 enum channel_enum ch_loop; 8266 enum channel_enum start_ch_idx; 8267 enum channel_enum end_ch_idx; 8268 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8269 uint32_t len; 8270 struct unsafe_ch_list *unsafe_ch_list; 8271 bool coex_unsafe_nb_user_prefer; 8272 8273 pdev_priv_obj = reg_get_pdev_obj(pdev); 8274 8275 if (!pdev_priv_obj) { 8276 reg_err("reg pdev private obj is NULL"); 8277 return QDF_STATUS_E_FAILURE; 8278 } 8279 psoc_priv_obj = reg_get_psoc_obj(psoc); 8280 if (!psoc_priv_obj) { 8281 reg_err("reg psoc private obj is NULL"); 8282 return QDF_STATUS_E_FAILURE; 8283 } 8284 8285 unsafe_ch_list = &psoc_priv_obj->unsafe_chan_list; 8286 coex_unsafe_nb_user_prefer = 8287 psoc_priv_obj->coex_unsafe_chan_nb_user_prefer; 8288 8289 if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt > 0) { 8290 len = sizeof(pdev_priv_obj->avoid_chan_ext_list.chan_freq_list); 8291 pdev_priv_obj->avoid_chan_ext_list.chan_cnt = 0; 8292 qdf_mem_zero(&pdev_priv_obj->avoid_chan_ext_list.chan_freq_list, 8293 len); 8294 } 8295 8296 if (unsafe_ch_list->chan_cnt > 0) { 8297 len = sizeof(unsafe_ch_list->chan_freq_list); 8298 unsafe_ch_list->chan_cnt = 0; 8299 qdf_mem_zero(unsafe_ch_list->chan_freq_list, len); 8300 } 8301 8302 for (i = 0; i < psoc_priv_obj->avoid_freq_ext_list.ch_avoid_range_cnt; 8303 i++) { 8304 if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt >= 8305 NUM_CHANNELS) { 8306 reg_debug("ext avoid channel list full"); 8307 break; 8308 } 8309 8310 if (unsafe_ch_list->chan_cnt >= NUM_CHANNELS) { 8311 reg_warn("LTE Coex unsafe channel list full"); 8312 break; 8313 } 8314 8315 start_ch_idx = INVALID_CHANNEL; 8316 end_ch_idx = INVALID_CHANNEL; 8317 range = &psoc_priv_obj->avoid_freq_ext_list.avoid_freq_range[i]; 8318 8319 start_channel = reg_freq_to_chan(pdev, range->start_freq); 8320 end_channel = reg_freq_to_chan(pdev, range->end_freq); 8321 txpower = range->txpower; 8322 is_valid_txpower = range->is_valid_txpower; 8323 8324 reg_debug("start: freq %d, ch %d, end: freq %d, ch %d txpower %d", 8325 range->start_freq, start_channel, range->end_freq, 8326 end_channel, txpower); 8327 8328 /* do not process frequency bands that are not mapped to 8329 * predefined channels 8330 */ 8331 if (start_channel == 0 || end_channel == 0) 8332 continue; 8333 8334 for (ch_loop = 0; ch_loop < NUM_CHANNELS; 8335 ch_loop++) { 8336 if (REG_CH_TO_FREQ(ch_loop) >= range->start_freq) { 8337 start_ch_idx = ch_loop; 8338 break; 8339 } 8340 } 8341 for (ch_loop = 0; ch_loop < NUM_CHANNELS; 8342 ch_loop++) { 8343 if (REG_CH_TO_FREQ(ch_loop) >= range->end_freq) { 8344 end_ch_idx = ch_loop; 8345 if (REG_CH_TO_FREQ(ch_loop) > range->end_freq) 8346 end_ch_idx--; 8347 break; 8348 } 8349 } 8350 8351 if (reg_is_chan_enum_invalid(start_ch_idx) || 8352 reg_is_chan_enum_invalid(end_ch_idx)) 8353 continue; 8354 8355 for (ch_loop = start_ch_idx; ch_loop <= end_ch_idx; 8356 ch_loop++) { 8357 pdev_priv_obj->avoid_chan_ext_list.chan_freq_list 8358 [pdev_priv_obj->avoid_chan_ext_list.chan_cnt++] = 8359 REG_CH_TO_FREQ(ch_loop); 8360 8361 if (coex_unsafe_nb_user_prefer) { 8362 if (unsafe_ch_list->chan_cnt >= 8363 NUM_CHANNELS) { 8364 reg_warn("LTECoex unsafe ch list full"); 8365 break; 8366 } 8367 unsafe_ch_list->txpower[ 8368 unsafe_ch_list->chan_cnt] = 8369 txpower; 8370 unsafe_ch_list->is_valid_txpower[ 8371 unsafe_ch_list->chan_cnt] = 8372 is_valid_txpower; 8373 unsafe_ch_list->chan_freq_list[ 8374 unsafe_ch_list->chan_cnt++] = 8375 REG_CH_TO_FREQ(ch_loop); 8376 } 8377 8378 if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt >= 8379 NUM_CHANNELS) { 8380 reg_debug("avoid freq ext list full"); 8381 break; 8382 } 8383 } 8384 /* if start == end for 5G, meanwhile it only have one valid 8385 * channel updated, then disable 20M by default around 8386 * this center freq. For example input [5805-5805], it 8387 * will disable 20Mhz around 5805, then the range change 8388 * to [5705-5815], otherwise, not sure about how many width 8389 * need to disabled for such case. 8390 */ 8391 if ((ch_loop - start_ch_idx) == 1 && 8392 (range->end_freq - range->start_freq == 0) && 8393 reg_is_5ghz_ch_freq(range->start_freq)) { 8394 range->start_freq = range->start_freq - HALF_20MHZ_BW; 8395 range->end_freq = range->end_freq + HALF_20MHZ_BW; 8396 } 8397 8398 for (ch_loop = 0; ch_loop < 8399 unsafe_ch_list->chan_cnt; ch_loop++) { 8400 if (ch_loop >= NUM_CHANNELS) 8401 break; 8402 reg_debug("Unsafe freq %d", 8403 unsafe_ch_list->chan_freq_list[ch_loop]); 8404 } 8405 } 8406 8407 return QDF_STATUS_SUCCESS; 8408 } 8409 8410 /** 8411 * reg_update_avoid_ch_ext() - Updates the current channel list that block out 8412 * by extended avoid frequency list 8413 * @psoc: Pointer to psoc structure 8414 * @object: Pointer to pdev structure 8415 * @arg: List of arguments 8416 * 8417 * Return: None 8418 */ 8419 static void 8420 reg_update_avoid_ch_ext(struct wlan_objmgr_psoc *psoc, 8421 void *object, void *arg) 8422 { 8423 struct wlan_objmgr_pdev *pdev = (struct wlan_objmgr_pdev *)object; 8424 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8425 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8426 QDF_STATUS status; 8427 8428 psoc_priv_obj = reg_get_psoc_obj(psoc); 8429 if (!psoc_priv_obj) { 8430 reg_err("reg psoc private obj is NULL"); 8431 return; 8432 } 8433 8434 pdev_priv_obj = reg_get_pdev_obj(pdev); 8435 8436 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8437 reg_err("reg pdev priv obj is NULL"); 8438 return; 8439 } 8440 8441 if (psoc_priv_obj->ch_avoid_ext_ind) { 8442 status = reg_process_ch_avoid_freq_ext(psoc, pdev); 8443 if (QDF_IS_STATUS_ERROR(status)) 8444 psoc_priv_obj->ch_avoid_ext_ind = false; 8445 } 8446 8447 reg_compute_pdev_current_chan_list(pdev_priv_obj); 8448 status = reg_send_scheduler_msg_sb(psoc, pdev); 8449 8450 if (QDF_IS_STATUS_ERROR(status)) 8451 reg_err("channel change msg schedule failed"); 8452 } 8453 8454 QDF_STATUS 8455 reg_process_ch_avoid_ext_event(struct wlan_objmgr_psoc *psoc, 8456 struct ch_avoid_ind_type *ch_avoid_event) 8457 { 8458 uint32_t i; 8459 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8460 QDF_STATUS status; 8461 struct ch_avoid_freq_type *range; 8462 8463 psoc_priv_obj = reg_get_psoc_obj(psoc); 8464 if (!psoc_priv_obj) { 8465 reg_err("reg psoc private obj is NULL"); 8466 return QDF_STATUS_E_FAILURE; 8467 } 8468 8469 reg_debug("freq range count %d", ch_avoid_event->ch_avoid_range_cnt); 8470 8471 qdf_mem_zero(&psoc_priv_obj->avoid_freq_ext_list, 8472 sizeof(struct ch_avoid_ind_type)); 8473 8474 for (i = 0; i < ch_avoid_event->ch_avoid_range_cnt; i++) { 8475 range = &psoc_priv_obj->avoid_freq_ext_list.avoid_freq_range[i]; 8476 range->start_freq = 8477 ch_avoid_event->avoid_freq_range[i].start_freq; 8478 range->end_freq = 8479 ch_avoid_event->avoid_freq_range[i].end_freq; 8480 range->txpower = 8481 ch_avoid_event->avoid_freq_range[i].txpower; 8482 range->is_valid_txpower = 8483 ch_avoid_event->avoid_freq_range[i].is_valid_txpower; 8484 } 8485 8486 psoc_priv_obj->avoid_freq_ext_list.restriction_mask = 8487 ch_avoid_event->restriction_mask; 8488 psoc_priv_obj->avoid_freq_ext_list.ch_avoid_range_cnt = 8489 ch_avoid_event->ch_avoid_range_cnt; 8490 8491 psoc_priv_obj->ch_avoid_ext_ind = true; 8492 8493 status = wlan_objmgr_psoc_try_get_ref(psoc, WLAN_REGULATORY_SB_ID); 8494 8495 if (QDF_IS_STATUS_ERROR(status)) { 8496 reg_err("error taking psoc ref cnt"); 8497 return status; 8498 } 8499 8500 status = wlan_objmgr_iterate_obj_list(psoc, WLAN_PDEV_OP, 8501 reg_update_avoid_ch_ext, 8502 NULL, 1, 8503 WLAN_REGULATORY_SB_ID); 8504 8505 wlan_objmgr_psoc_release_ref(psoc, WLAN_REGULATORY_SB_ID); 8506 8507 return status; 8508 } 8509 8510 bool reg_check_coex_unsafe_nb_user_prefer(struct wlan_objmgr_psoc *psoc) 8511 { 8512 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8513 8514 psoc_priv_obj = reg_get_psoc_obj(psoc); 8515 if (!psoc_priv_obj) { 8516 reg_err("reg psoc private obj is NULL"); 8517 return false; 8518 } 8519 8520 return psoc_priv_obj->coex_unsafe_chan_nb_user_prefer; 8521 } 8522 8523 bool reg_check_coex_unsafe_chan_reg_disable(struct wlan_objmgr_psoc *psoc) 8524 { 8525 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8526 8527 psoc_priv_obj = reg_get_psoc_obj(psoc); 8528 if (!psoc_priv_obj) { 8529 reg_err("reg psoc private obj is NULL"); 8530 return false; 8531 } 8532 8533 return psoc_priv_obj->coex_unsafe_chan_reg_disable; 8534 } 8535 #endif 8536 8537 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ) 8538 QDF_STATUS reg_send_afc_cmd(struct wlan_objmgr_pdev *pdev, 8539 struct reg_afc_resp_rx_ind_info *afc_ind_obj) 8540 { 8541 uint8_t pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 8542 struct wlan_objmgr_psoc *psoc; 8543 struct wlan_lmac_if_reg_tx_ops *tx_ops; 8544 8545 psoc = wlan_pdev_get_psoc(pdev); 8546 if (!psoc) { 8547 reg_err("psoc is NULL"); 8548 return QDF_STATUS_E_INVAL; 8549 } 8550 8551 tx_ops = reg_get_psoc_tx_ops(psoc); 8552 if (tx_ops->send_afc_ind) 8553 return tx_ops->send_afc_ind(psoc, pdev_id, afc_ind_obj); 8554 8555 return QDF_STATUS_E_FAILURE; 8556 } 8557 8558 bool reg_is_afc_power_event_received(struct wlan_objmgr_pdev *pdev) 8559 { 8560 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8561 8562 pdev_priv_obj = reg_get_pdev_obj(pdev); 8563 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8564 reg_err("pdev reg component is NULL"); 8565 return false; 8566 } 8567 8568 return pdev_priv_obj->is_6g_afc_power_event_received; 8569 } 8570 8571 bool reg_is_afc_done(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 8572 { 8573 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8574 uint32_t chan_flags; 8575 8576 pdev_priv_obj = reg_get_pdev_obj(pdev); 8577 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8578 reg_err("pdev reg component is NULL"); 8579 return false; 8580 } 8581 8582 chan_flags = reg_get_channel_flags_for_freq(pdev, freq); 8583 8584 return !(chan_flags & REGULATORY_CHAN_AFC_NOT_DONE); 8585 } 8586 8587 QDF_STATUS reg_get_afc_req_id(struct wlan_objmgr_pdev *pdev, uint64_t *req_id) 8588 { 8589 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8590 8591 pdev_priv_obj = reg_get_pdev_obj(pdev); 8592 8593 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8594 reg_err("reg pdev priv obj is NULL"); 8595 return QDF_STATUS_E_FAILURE; 8596 } 8597 8598 *req_id = pdev_priv_obj->afc_request_id; 8599 8600 return QDF_STATUS_SUCCESS; 8601 } 8602 8603 bool reg_is_afc_expiry_event_received(struct wlan_objmgr_pdev *pdev) 8604 { 8605 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8606 8607 pdev_priv_obj = reg_get_pdev_obj(pdev); 8608 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8609 reg_err("pdev reg component is NULL"); 8610 return false; 8611 } 8612 8613 return pdev_priv_obj->is_6g_afc_expiry_event_received; 8614 } 8615 8616 bool reg_is_noaction_on_afc_pwr_evt(struct wlan_objmgr_pdev *pdev) 8617 { 8618 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8619 8620 pdev_priv_obj = reg_get_pdev_obj(pdev); 8621 8622 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8623 reg_err("reg pdev priv obj is NULL"); 8624 return QDF_STATUS_E_FAILURE; 8625 } 8626 8627 return pdev_priv_obj->is_reg_noaction_on_afc_pwr_evt; 8628 } 8629 #endif 8630 8631 /** 8632 * struct bw_wireless_modes_pair - structure containing bandwidth and wireless 8633 * modes corresponding to the bandwidth 8634 * @ch_width: channel width 8635 * @wireless_modes: wireless modes bitmap corresponding to @ch_width. This 8636 * bitmap is a combination of enum values HOST_REGDMN_MODE 8637 */ 8638 struct bw_wireless_modes_pair { 8639 enum phy_ch_width ch_width; 8640 uint64_t wireless_modes; 8641 }; 8642 8643 /* Mapping of bandwidth to wireless modes */ 8644 static const struct bw_wireless_modes_pair bw_wireless_modes_pair_map[] = { 8645 #ifdef WLAN_FEATURE_11BE 8646 {CH_WIDTH_320MHZ, WIRELESS_320_MODES}, 8647 #endif 8648 {CH_WIDTH_80P80MHZ, WIRELESS_80P80_MODES}, 8649 {CH_WIDTH_160MHZ, WIRELESS_160_MODES}, 8650 {CH_WIDTH_80MHZ, WIRELESS_80_MODES}, 8651 {CH_WIDTH_40MHZ, WIRELESS_40_MODES}, 8652 {CH_WIDTH_20MHZ, WIRELESS_20_MODES}, 8653 {CH_WIDTH_10MHZ, WIRELESS_10_MODES}, 8654 {CH_WIDTH_5MHZ, WIRELESS_5_MODES}, 8655 }; 8656 8657 QDF_STATUS reg_is_chwidth_supported(struct wlan_objmgr_pdev *pdev, 8658 enum phy_ch_width ch_width, 8659 bool *is_supported) 8660 { 8661 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8662 uint64_t wireless_modes; 8663 uint8_t num_bws, idx; 8664 8665 pdev_priv_obj = reg_get_pdev_obj(pdev); 8666 8667 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8668 reg_err("reg pdev priv obj is NULL"); 8669 return QDF_STATUS_E_FAILURE; 8670 } 8671 8672 *is_supported = false; 8673 8674 wireless_modes = pdev_priv_obj->wireless_modes; 8675 num_bws = QDF_ARRAY_SIZE(bw_wireless_modes_pair_map); 8676 8677 for (idx = 0; idx < num_bws; ++idx) { 8678 if (bw_wireless_modes_pair_map[idx].ch_width == ch_width) { 8679 *is_supported = !!(wireless_modes & 8680 bw_wireless_modes_pair_map[idx].wireless_modes); 8681 break; 8682 } 8683 } 8684 8685 return QDF_STATUS_SUCCESS; 8686 } 8687 8688 bool reg_is_state_allowed(enum channel_state chan_state) 8689 { 8690 return !((chan_state == CHANNEL_STATE_INVALID) || 8691 (chan_state == CHANNEL_STATE_DISABLE)); 8692 } 8693 8694 static bool 8695 reg_is_freq_idx_enabled_on_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 8696 *pdev_priv_obj, 8697 enum channel_enum freq_idx) 8698 { 8699 struct regulatory_channel *cur_chan_list; 8700 8701 if (freq_idx >= NUM_CHANNELS) 8702 return false; 8703 8704 cur_chan_list = pdev_priv_obj->cur_chan_list; 8705 8706 return !reg_is_chan_disabled_and_not_nol(&cur_chan_list[freq_idx]); 8707 } 8708 8709 static QDF_STATUS 8710 reg_get_min_max_bw_on_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 8711 *pdev_priv_obj, 8712 enum channel_enum freq_idx, 8713 uint16_t *min_bw, 8714 uint16_t *max_bw) 8715 { 8716 struct regulatory_channel *cur_chan_list; 8717 8718 if (freq_idx >= NUM_CHANNELS) 8719 return QDF_STATUS_E_FAILURE; 8720 8721 cur_chan_list = pdev_priv_obj->cur_chan_list; 8722 if (min_bw) 8723 *min_bw = cur_chan_list[freq_idx].min_bw; 8724 if (max_bw) 8725 *max_bw = cur_chan_list[freq_idx].max_bw; 8726 8727 return QDF_STATUS_SUCCESS; 8728 } 8729 8730 static enum channel_state 8731 reg_get_chan_state_on_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 8732 *pdev_priv_obj, 8733 enum channel_enum freq_idx) 8734 { 8735 struct regulatory_channel *cur_chan_list; 8736 enum channel_state chan_state; 8737 8738 if (freq_idx >= NUM_CHANNELS) 8739 return CHANNEL_STATE_INVALID; 8740 8741 cur_chan_list = pdev_priv_obj->cur_chan_list; 8742 chan_state = cur_chan_list[freq_idx].state; 8743 8744 return chan_state; 8745 } 8746 8747 static enum channel_state 8748 reg_get_chan_state_based_on_nol_flag_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 8749 *pdev_priv_obj, 8750 enum channel_enum freq_idx) 8751 { 8752 struct regulatory_channel *cur_chan_list; 8753 enum channel_state chan_state; 8754 8755 if (freq_idx >= NUM_CHANNELS) 8756 return CHANNEL_STATE_INVALID; 8757 8758 cur_chan_list = pdev_priv_obj->cur_chan_list; 8759 chan_state = cur_chan_list[freq_idx].state; 8760 8761 if ((cur_chan_list[freq_idx].nol_chan || 8762 cur_chan_list[freq_idx].nol_history) && 8763 chan_state == CHANNEL_STATE_DISABLE) 8764 chan_state = CHANNEL_STATE_DFS; 8765 8766 return chan_state; 8767 } 8768 8769 #ifdef CONFIG_BAND_6GHZ 8770 static inline bool 8771 reg_is_supr_entry_mode_disabled(const struct super_chan_info *super_chan_ent, 8772 enum supported_6g_pwr_types in_6g_pwr_mode) 8773 { 8774 return ((super_chan_ent->chan_flags_arr[in_6g_pwr_mode] & 8775 REGULATORY_CHAN_DISABLED) && 8776 super_chan_ent->state_arr[in_6g_pwr_mode] == 8777 CHANNEL_STATE_DISABLE); 8778 } 8779 8780 static bool 8781 reg_is_freq_idx_enabled_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 8782 *pdev_priv_obj, 8783 enum channel_enum freq_idx, 8784 enum supported_6g_pwr_types 8785 in_6g_pwr_mode) 8786 { 8787 const struct super_chan_info *super_chan_ent; 8788 QDF_STATUS status; 8789 8790 if (freq_idx >= NUM_CHANNELS) 8791 return false; 8792 8793 if (freq_idx < MIN_6GHZ_CHANNEL) 8794 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 8795 freq_idx); 8796 8797 status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx, 8798 &super_chan_ent); 8799 if (QDF_IS_STATUS_ERROR(status)) { 8800 reg_debug("Failed to get super channel entry for freq_idx %d", 8801 freq_idx); 8802 return false; 8803 } 8804 8805 /* If the input 6G power mode is best power mode, get the best power 8806 * mode type from the super channel entry. 8807 */ 8808 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 8809 in_6g_pwr_mode = super_chan_ent->best_power_mode; 8810 8811 return !reg_is_supr_entry_mode_disabled(super_chan_ent, in_6g_pwr_mode); 8812 } 8813 8814 static QDF_STATUS 8815 reg_get_min_max_bw_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 8816 *pdev_priv_obj, 8817 enum channel_enum freq_idx, 8818 enum supported_6g_pwr_types 8819 in_6g_pwr_mode, 8820 uint16_t *min_bw, 8821 uint16_t *max_bw) 8822 { 8823 const struct super_chan_info *super_chan_ent; 8824 QDF_STATUS status; 8825 8826 if (freq_idx >= NUM_CHANNELS) 8827 return QDF_STATUS_E_FAILURE; 8828 8829 if (freq_idx < MIN_6GHZ_CHANNEL) 8830 return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj, 8831 freq_idx, 8832 min_bw, max_bw); 8833 8834 status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx, 8835 &super_chan_ent); 8836 if (QDF_IS_STATUS_ERROR(status)) { 8837 reg_debug("Failed to get super channel entry for freq_idx %d", 8838 freq_idx); 8839 return QDF_STATUS_E_FAILURE; 8840 } 8841 8842 /* If the input 6G power mode is best power mode, get the best power 8843 * mode type from the super channel entry. 8844 */ 8845 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 8846 in_6g_pwr_mode = super_chan_ent->best_power_mode; 8847 8848 if (reg_is_supp_pwr_mode_invalid(in_6g_pwr_mode)) { 8849 reg_debug("pwr_type invalid"); 8850 return QDF_STATUS_E_FAILURE; 8851 } 8852 8853 if (min_bw) 8854 *min_bw = super_chan_ent->min_bw[in_6g_pwr_mode]; 8855 if (max_bw) 8856 *max_bw = super_chan_ent->max_bw[in_6g_pwr_mode]; 8857 8858 return QDF_STATUS_SUCCESS; 8859 } 8860 8861 static enum channel_state 8862 reg_get_chan_state_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 8863 *pdev_priv_obj, 8864 enum channel_enum freq_idx, 8865 enum supported_6g_pwr_types 8866 in_6g_pwr_mode) 8867 { 8868 const struct super_chan_info *super_chan_ent; 8869 enum channel_state chan_state; 8870 QDF_STATUS status; 8871 8872 if (freq_idx >= NUM_CHANNELS) 8873 return CHANNEL_STATE_INVALID; 8874 8875 if (freq_idx < MIN_6GHZ_CHANNEL) 8876 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 8877 freq_idx); 8878 8879 status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx, 8880 &super_chan_ent); 8881 if (QDF_IS_STATUS_ERROR(status)) { 8882 reg_debug("Failed to get super channel entry for freq_idx %d", 8883 freq_idx); 8884 return CHANNEL_STATE_INVALID; 8885 } 8886 8887 /* If the input 6G power mode is best power mode, get the best power 8888 * mode type from the super channel entry. 8889 */ 8890 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 8891 in_6g_pwr_mode = super_chan_ent->best_power_mode; 8892 8893 if (reg_is_supp_pwr_mode_invalid(in_6g_pwr_mode)) { 8894 reg_debug("pwr_type invalid"); 8895 return CHANNEL_STATE_INVALID; 8896 } 8897 8898 chan_state = super_chan_ent->state_arr[in_6g_pwr_mode]; 8899 8900 return chan_state; 8901 } 8902 8903 enum supported_6g_pwr_types 8904 reg_get_best_6g_pwr_type(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 8905 { 8906 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8907 enum channel_enum freq_idx; 8908 enum channel_enum sixg_freq_idx; 8909 8910 pdev_priv_obj = reg_get_pdev_obj(pdev); 8911 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8912 reg_err_rl("pdev reg component is NULL"); 8913 return REG_INVALID_PWR_MODE; 8914 } 8915 8916 freq_idx = reg_get_chan_enum_for_freq(freq); 8917 8918 if (reg_is_chan_enum_invalid(freq_idx)) 8919 return REG_INVALID_PWR_MODE; 8920 8921 sixg_freq_idx = reg_convert_enum_to_6g_idx(freq_idx); 8922 if (reg_is_chan_enum_invalid(sixg_freq_idx) || 8923 sixg_freq_idx >= NUM_6GHZ_CHANNELS) 8924 return REG_INVALID_PWR_MODE; 8925 8926 return pdev_priv_obj->super_chan_list[sixg_freq_idx].best_power_mode; 8927 } 8928 8929 static inline bool reg_is_6g_ap_type_invalid(enum reg_6g_ap_type ap_pwr_type) 8930 { 8931 return ((ap_pwr_type < REG_INDOOR_AP) || 8932 (ap_pwr_type > REG_MAX_SUPP_AP_TYPE)); 8933 } 8934 8935 enum supported_6g_pwr_types 8936 reg_conv_6g_ap_type_to_supported_6g_pwr_types(enum reg_6g_ap_type ap_pwr_type) 8937 { 8938 static const enum supported_6g_pwr_types reg_enum_conv[] = { 8939 [REG_INDOOR_AP] = REG_AP_LPI, 8940 [REG_STANDARD_POWER_AP] = REG_AP_SP, 8941 [REG_VERY_LOW_POWER_AP] = REG_AP_VLP, 8942 }; 8943 8944 if (reg_is_6g_ap_type_invalid(ap_pwr_type)) 8945 return REG_INVALID_PWR_MODE; 8946 8947 return reg_enum_conv[ap_pwr_type]; 8948 } 8949 #else 8950 static inline bool 8951 reg_is_freq_idx_enabled_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 8952 *pdev_priv_obj, 8953 enum channel_enum freq_idx, 8954 enum supported_6g_pwr_types 8955 in_6g_pwr_mode) 8956 { 8957 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 8958 freq_idx); 8959 } 8960 8961 static inline QDF_STATUS 8962 reg_get_min_max_bw_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 8963 *pdev_priv_obj, 8964 enum channel_enum freq_idx, 8965 enum supported_6g_pwr_types 8966 in_6g_pwr_mode, 8967 uint16_t *min_bw, 8968 uint16_t *max_bw) 8969 { 8970 return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj, 8971 freq_idx, 8972 min_bw, max_bw); 8973 } 8974 8975 static inline enum channel_state 8976 reg_get_chan_state_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 8977 *pdev_priv_obj, 8978 enum channel_enum freq_idx, 8979 enum supported_6g_pwr_types 8980 in_6g_pwr_mode) 8981 { 8982 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 8983 freq_idx); 8984 } 8985 #endif /* CONFIG_BAND_6GHZ */ 8986 8987 bool 8988 reg_is_freq_enabled(struct wlan_objmgr_pdev *pdev, 8989 qdf_freq_t freq, 8990 enum supported_6g_pwr_types in_6g_pwr_mode) 8991 { 8992 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8993 enum channel_enum freq_idx; 8994 8995 pdev_priv_obj = reg_get_pdev_obj(pdev); 8996 8997 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8998 reg_err("reg pdev private obj is NULL"); 8999 return false; 9000 } 9001 9002 freq_idx = reg_get_chan_enum_for_freq(freq); 9003 9004 if (reg_is_chan_enum_invalid(freq_idx)) 9005 return false; 9006 9007 return reg_is_freq_idx_enabled(pdev, freq_idx, in_6g_pwr_mode); 9008 } 9009 9010 bool reg_is_freq_idx_enabled(struct wlan_objmgr_pdev *pdev, 9011 enum channel_enum freq_idx, 9012 enum supported_6g_pwr_types in_6g_pwr_mode) 9013 { 9014 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9015 9016 pdev_priv_obj = reg_get_pdev_obj(pdev); 9017 9018 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9019 reg_err("reg pdev private obj is NULL"); 9020 return false; 9021 } 9022 9023 if (freq_idx < MIN_6GHZ_CHANNEL) 9024 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 9025 freq_idx); 9026 9027 switch (in_6g_pwr_mode) { 9028 case REG_CURRENT_PWR_MODE: 9029 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 9030 freq_idx); 9031 9032 case REG_BEST_PWR_MODE: 9033 default: 9034 return reg_is_freq_idx_enabled_on_given_pwr_mode(pdev_priv_obj, 9035 freq_idx, 9036 in_6g_pwr_mode 9037 ); 9038 } 9039 } 9040 9041 QDF_STATUS reg_get_min_max_bw_reg_chan_list(struct wlan_objmgr_pdev *pdev, 9042 enum channel_enum freq_idx, 9043 enum supported_6g_pwr_types 9044 in_6g_pwr_mode, 9045 uint16_t *min_bw, 9046 uint16_t *max_bw) 9047 { 9048 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9049 9050 pdev_priv_obj = reg_get_pdev_obj(pdev); 9051 9052 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9053 reg_err("reg pdev private obj is NULL"); 9054 return QDF_STATUS_E_FAILURE; 9055 } 9056 9057 if (freq_idx < MIN_6GHZ_CHANNEL) 9058 return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj, 9059 freq_idx, 9060 min_bw, max_bw); 9061 9062 switch (in_6g_pwr_mode) { 9063 case REG_CURRENT_PWR_MODE: 9064 return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj, 9065 freq_idx, 9066 min_bw, max_bw); 9067 9068 case REG_BEST_PWR_MODE: 9069 default: 9070 return reg_get_min_max_bw_on_given_pwr_mode(pdev_priv_obj, 9071 freq_idx, 9072 in_6g_pwr_mode, 9073 min_bw, max_bw); 9074 } 9075 } 9076 9077 enum channel_state reg_get_chan_state(struct wlan_objmgr_pdev *pdev, 9078 enum channel_enum freq_idx, 9079 enum supported_6g_pwr_types 9080 in_6g_pwr_mode, 9081 bool treat_nol_chan_as_disabled) 9082 { 9083 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9084 9085 pdev_priv_obj = reg_get_pdev_obj(pdev); 9086 9087 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9088 reg_err("reg pdev private obj is NULL"); 9089 return CHANNEL_STATE_INVALID; 9090 } 9091 9092 if (freq_idx < MIN_6GHZ_CHANNEL) { 9093 if (treat_nol_chan_as_disabled) 9094 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 9095 freq_idx); 9096 else 9097 return reg_get_chan_state_based_on_nol_flag_cur_chan_list( 9098 pdev_priv_obj, 9099 freq_idx); 9100 } 9101 9102 switch (in_6g_pwr_mode) { 9103 case REG_CURRENT_PWR_MODE: 9104 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 9105 freq_idx); 9106 9107 case REG_BEST_PWR_MODE: 9108 default: 9109 return reg_get_chan_state_on_given_pwr_mode(pdev_priv_obj, 9110 freq_idx, 9111 in_6g_pwr_mode 9112 ); 9113 } 9114 } 9115 9116 #ifdef WLAN_FEATURE_11BE 9117 enum phy_ch_width reg_find_chwidth_from_bw(uint16_t bw) 9118 { 9119 switch (bw) { 9120 case BW_5_MHZ: 9121 return CH_WIDTH_5MHZ; 9122 case BW_10_MHZ: 9123 return CH_WIDTH_10MHZ; 9124 case BW_20_MHZ: 9125 return CH_WIDTH_20MHZ; 9126 case BW_40_MHZ: 9127 return CH_WIDTH_40MHZ; 9128 case BW_80_MHZ: 9129 return CH_WIDTH_80MHZ; 9130 case BW_160_MHZ: 9131 return CH_WIDTH_160MHZ; 9132 case BW_320_MHZ: 9133 return CH_WIDTH_320MHZ; 9134 default: 9135 return CH_WIDTH_INVALID; 9136 } 9137 } 9138 #else 9139 enum phy_ch_width reg_find_chwidth_from_bw(uint16_t bw) 9140 { 9141 switch (bw) { 9142 case BW_5_MHZ: 9143 return CH_WIDTH_5MHZ; 9144 case BW_10_MHZ: 9145 return CH_WIDTH_10MHZ; 9146 case BW_20_MHZ: 9147 return CH_WIDTH_20MHZ; 9148 case BW_40_MHZ: 9149 return CH_WIDTH_40MHZ; 9150 case BW_80_MHZ: 9151 return CH_WIDTH_80MHZ; 9152 case BW_160_MHZ: 9153 return CH_WIDTH_160MHZ; 9154 default: 9155 return CH_WIDTH_INVALID; 9156 } 9157 } 9158 #endif 9159 9160 #ifdef CONFIG_BAND_6GHZ 9161 qdf_freq_t reg_get_thresh_priority_freq(struct wlan_objmgr_pdev *pdev) 9162 { 9163 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9164 9165 pdev_priv_obj = reg_get_pdev_obj(pdev); 9166 9167 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9168 reg_err("reg pdev private obj is NULL"); 9169 return 0; 9170 } 9171 9172 return pdev_priv_obj->reg_6g_thresh_priority_freq; 9173 } 9174 9175 /** 9176 * reg_get_eirp_for_non_sp() - For the given power mode, using the bandwidth 9177 * and psd(from master channel entry), calculate an EIRP value. The minimum 9178 * of calculated EIRP and regulatory max EIRP is returned. 9179 * @pdev: Pointer to pdev 9180 * @freq: Frequency in mhz 9181 * @bw: Bandwidth in mhz 9182 * @ap_pwr_type: AP Power type 9183 * 9184 * Return: EIRP 9185 */ 9186 static uint8_t 9187 reg_get_eirp_for_non_sp(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq, 9188 uint16_t bw, enum reg_6g_ap_type ap_pwr_type) 9189 { 9190 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9191 bool is_psd; 9192 struct regulatory_channel *master_chan_list; 9193 uint16_t txpower = 0; 9194 9195 pdev_priv_obj = reg_get_pdev_obj(pdev); 9196 if (!pdev_priv_obj) { 9197 reg_err("pdev priv obj is NULL"); 9198 return 0; 9199 } 9200 9201 if (!((ap_pwr_type == REG_INDOOR_AP) || 9202 (ap_pwr_type == REG_VERY_LOW_POWER_AP))) { 9203 reg_err("Only LPI and VLP are supported in this function "); 9204 return 0; 9205 } 9206 9207 master_chan_list = pdev_priv_obj->mas_chan_list_6g_ap[ap_pwr_type]; 9208 is_psd = reg_is_6g_psd_power(pdev); 9209 reg_find_txpower_from_6g_list(freq, master_chan_list, &txpower); 9210 9211 if (is_psd) { 9212 int16_t eirp = 0, psd = 0; 9213 9214 reg_get_6g_chan_psd_eirp_power(freq, master_chan_list, &psd); 9215 reg_psd_2_eirp(pdev, psd, bw, &eirp); 9216 return QDF_MIN(txpower, eirp); 9217 } 9218 9219 return txpower; 9220 } 9221 9222 #ifdef CONFIG_AFC_SUPPORT 9223 /** 9224 * reg_compute_6g_center_freq_from_cfi() - Given the IEEE value of the 9225 * 6 GHz center frequency, find the 6 GHz center frequency. 9226 * @ieee_6g_cfi: IEEE value of 6 GHz cfi 9227 * Return: Center frequency in MHz 9228 */ 9229 static qdf_freq_t 9230 reg_compute_6g_center_freq_from_cfi(uint8_t ieee_6g_cfi) 9231 { 9232 return (SIXG_START_FREQ + ieee_6g_cfi * FREQ_TO_CHAN_SCALE); 9233 } 9234 9235 #ifdef WLAN_FEATURE_11BE 9236 /** 9237 * reg_is_320_opclass: Find out if the opclass computed from freq and 9238 * width of 320 is same as the input op_class. 9239 * @freq: Frequency in MHz 9240 * @in_opclass: Input Opclass number 9241 * Return: true if opclass is 320 supported, false otherwise. 9242 */ 9243 static bool reg_is_320_opclass(qdf_freq_t freq, uint8_t in_opclass) 9244 { 9245 uint8_t local_op_class = 9246 reg_dmn_get_opclass_from_freq_width(NULL, freq, BW_320_MHZ, 9247 BIT(BEHAV_NONE)); 9248 return (in_opclass == local_op_class); 9249 } 9250 #else 9251 static inline bool reg_is_320_opclass(qdf_freq_t freq, uint8_t op_class) 9252 { 9253 return false; 9254 } 9255 #endif 9256 9257 /** 9258 * reg_find_eirp_in_afc_eirp_obj() - Get eirp power from the AFC eirp object 9259 * based on the channel center frequency and operating class 9260 * @pdev: Pointer to pdev 9261 * @eirp_obj: Pointer to eirp_obj 9262 * @freq: Frequency in MHz 9263 * @cen320: 320 MHz band center frequency 9264 * @op_class: Operating class 9265 * 9266 * Return: EIRP power 9267 */ 9268 static uint8_t reg_find_eirp_in_afc_eirp_obj(struct wlan_objmgr_pdev *pdev, 9269 struct chan_eirp_obj *eirp_obj, 9270 qdf_freq_t freq, 9271 qdf_freq_t cen320, 9272 uint8_t op_class) 9273 { 9274 uint8_t k; 9275 uint8_t subchannels[NUM_20_MHZ_CHAN_IN_320_MHZ_CHAN]; 9276 uint8_t nchans; 9277 9278 if (reg_is_320_opclass(freq, op_class)) { 9279 qdf_freq_t cfi_freq = 9280 reg_compute_6g_center_freq_from_cfi(eirp_obj->cfi); 9281 9282 if (cfi_freq == cen320) 9283 return eirp_obj->eirp_power / EIRP_PWR_SCALE; 9284 9285 return 0; 9286 } 9287 9288 nchans = reg_get_subchannels_for_opclass(eirp_obj->cfi, 9289 op_class, 9290 subchannels); 9291 9292 for (k = 0; k < nchans; k++) 9293 if (reg_chan_band_to_freq(pdev, subchannels[k], 9294 BIT(REG_BAND_6G)) == freq) 9295 return eirp_obj->eirp_power / EIRP_PWR_SCALE; 9296 9297 return 0; 9298 } 9299 9300 /** 9301 * reg_find_eirp_in_afc_chan_obj() - Get eirp power from the AFC channel 9302 * object based on the channel center frequency and operating class 9303 * @pdev: Pointer to pdev 9304 * @chan_obj: Pointer to chan_obj 9305 * @freq: Frequency in MHz 9306 * @cen320: 320 MHz band center frequency 9307 * @op_class: Operating class 9308 * 9309 * Return: EIRP power 9310 */ 9311 static uint8_t reg_find_eirp_in_afc_chan_obj(struct wlan_objmgr_pdev *pdev, 9312 struct afc_chan_obj *chan_obj, 9313 qdf_freq_t freq, 9314 qdf_freq_t cen320, 9315 uint8_t op_class) 9316 { 9317 uint8_t j; 9318 9319 if (chan_obj->global_opclass != op_class) 9320 return 0; 9321 9322 for (j = 0; j < chan_obj->num_chans; j++) { 9323 uint8_t afc_eirp; 9324 struct chan_eirp_obj *eirp_obj = &chan_obj->chan_eirp_info[j]; 9325 9326 afc_eirp = reg_find_eirp_in_afc_eirp_obj(pdev, eirp_obj, 9327 freq, cen320, 9328 op_class); 9329 9330 if (afc_eirp) 9331 return afc_eirp; 9332 } 9333 9334 return 0; 9335 } 9336 9337 /** 9338 * reg_get_sp_eirp() - For the given power mode, using the bandwidth, find the 9339 * corresponding EIRP values from the afc power info array. The minimum of found 9340 * EIRP and regulatory max EIRP is returned 9341 * @pdev: Pointer to pdev 9342 * @freq: Frequency in MHz 9343 * @cen320: 320 MHz band center frequency 9344 * @bw: Bandwidth in mhz 9345 * 9346 * Return: EIRP 9347 */ 9348 static uint8_t reg_get_sp_eirp(struct wlan_objmgr_pdev *pdev, 9349 qdf_freq_t freq, 9350 qdf_freq_t cen320, 9351 uint16_t bw) 9352 { 9353 uint8_t i, op_class = 0, chan_num = 0, afc_eirp_pwr = 0; 9354 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9355 struct regulatory_channel *sp_ap_master_chan_list; 9356 struct reg_fw_afc_power_event *power_info; 9357 uint16_t reg_sp_eirp_pwr = 0; 9358 9359 pdev_priv_obj = reg_get_pdev_obj(pdev); 9360 9361 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9362 reg_err("reg pdev priv obj is NULL"); 9363 return 0; 9364 } 9365 9366 if (!reg_is_afc_power_event_received(pdev)) 9367 return 0; 9368 9369 power_info = pdev_priv_obj->power_info; 9370 if (!power_info) { 9371 reg_err("power_info is NULL"); 9372 return 0; 9373 } 9374 9375 reg_freq_width_to_chan_op_class(pdev, 9376 freq, 9377 bw, 9378 true, 9379 BIT(BEHAV_NONE), 9380 &op_class, 9381 &chan_num); 9382 sp_ap_master_chan_list = 9383 pdev_priv_obj->mas_chan_list_6g_ap[REG_STANDARD_POWER_AP]; 9384 reg_find_txpower_from_6g_list(freq, sp_ap_master_chan_list, 9385 ®_sp_eirp_pwr); 9386 9387 if (!reg_sp_eirp_pwr) 9388 return 0; 9389 9390 for (i = 0; i < power_info->num_chan_objs; i++) { 9391 struct afc_chan_obj *chan_obj = &power_info->afc_chan_info[i]; 9392 9393 afc_eirp_pwr = reg_find_eirp_in_afc_chan_obj(pdev, 9394 chan_obj, 9395 freq, 9396 cen320, 9397 op_class); 9398 if (afc_eirp_pwr) 9399 break; 9400 } 9401 9402 if (afc_eirp_pwr) 9403 return QDF_MIN(afc_eirp_pwr, reg_sp_eirp_pwr); 9404 9405 return 0; 9406 } 9407 #else 9408 static uint8_t reg_get_sp_eirp(struct wlan_objmgr_pdev *pdev, 9409 qdf_freq_t freq, 9410 qdf_freq_t cen320, 9411 uint16_t bw) 9412 { 9413 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9414 struct regulatory_channel *sp_ap_master_chan_list; 9415 uint16_t reg_sp_eirp_pwr = 0; 9416 9417 pdev_priv_obj = reg_get_pdev_obj(pdev); 9418 9419 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9420 reg_err("reg pdev priv obj is NULL"); 9421 return 0; 9422 } 9423 9424 sp_ap_master_chan_list = 9425 pdev_priv_obj->mas_chan_list_6g_ap[REG_STANDARD_POWER_AP]; 9426 reg_find_txpower_from_6g_list(freq, sp_ap_master_chan_list, 9427 ®_sp_eirp_pwr); 9428 9429 return reg_sp_eirp_pwr; 9430 } 9431 #endif 9432 9433 /** 9434 * reg_get_best_pwr_mode_from_eirp_list() - Get best power mode from the input 9435 * EIRP list 9436 * @eirp_list: EIRP list 9437 * @size: Size of eirp list 9438 * 9439 * Return: Best power mode 9440 */ 9441 static enum reg_6g_ap_type 9442 reg_get_best_pwr_mode_from_eirp_list(uint8_t *eirp_list, uint8_t size) 9443 { 9444 uint8_t max = 0, i; 9445 enum reg_6g_ap_type best_pwr_mode = REG_INDOOR_AP; 9446 9447 for (i = 0; i < size; i++) { 9448 if (eirp_list[i] > max) { 9449 max = eirp_list[i]; 9450 best_pwr_mode = i; 9451 } 9452 } 9453 9454 return best_pwr_mode; 9455 } 9456 9457 uint8_t reg_get_eirp_pwr(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq, 9458 qdf_freq_t cen320, 9459 uint16_t bw, enum reg_6g_ap_type ap_pwr_type) 9460 { 9461 if (ap_pwr_type == REG_STANDARD_POWER_AP) 9462 return reg_get_sp_eirp(pdev, freq, cen320, bw); 9463 9464 return reg_get_eirp_for_non_sp(pdev, freq, bw, ap_pwr_type); 9465 } 9466 9467 enum reg_6g_ap_type reg_get_best_pwr_mode(struct wlan_objmgr_pdev *pdev, 9468 qdf_freq_t freq, 9469 qdf_freq_t cen320, 9470 uint16_t bw) 9471 { 9472 uint8_t eirp_list[REG_MAX_SUPP_AP_TYPE + 1]; 9473 enum reg_6g_ap_type ap_pwr_type; 9474 9475 for (ap_pwr_type = REG_INDOOR_AP; ap_pwr_type <= REG_VERY_LOW_POWER_AP; 9476 ap_pwr_type++) 9477 eirp_list[ap_pwr_type] = 9478 reg_get_eirp_pwr(pdev, freq, cen320, bw, 9479 ap_pwr_type); 9480 9481 return reg_get_best_pwr_mode_from_eirp_list(eirp_list, 9482 REG_MAX_SUPP_AP_TYPE + 1); 9483 } 9484 #endif 9485 9486 QDF_STATUS reg_get_regd_rules(struct wlan_objmgr_pdev *pdev, 9487 struct reg_rule_info *reg_rules) 9488 { 9489 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9490 9491 if (!pdev) { 9492 reg_err("pdev is NULL"); 9493 return QDF_STATUS_E_FAILURE; 9494 } 9495 9496 pdev_priv_obj = reg_get_pdev_obj(pdev); 9497 if (!pdev_priv_obj) { 9498 reg_err("pdev priv obj is NULL"); 9499 return QDF_STATUS_E_FAILURE; 9500 } 9501 9502 qdf_spin_lock_bh(&pdev_priv_obj->reg_rules_lock); 9503 qdf_mem_copy(reg_rules, &pdev_priv_obj->reg_rules, 9504 sizeof(struct reg_rule_info)); 9505 qdf_spin_unlock_bh(&pdev_priv_obj->reg_rules_lock); 9506 9507 return QDF_STATUS_SUCCESS; 9508 } 9509 9510 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ) 9511 bool 9512 reg_is_sup_chan_entry_afc_done(struct wlan_objmgr_pdev *pdev, 9513 enum channel_enum chan_idx, 9514 enum supported_6g_pwr_types in_6g_pwr_mode) 9515 { 9516 const struct super_chan_info *super_chan_ent; 9517 QDF_STATUS status; 9518 9519 status = reg_get_superchan_entry(pdev, chan_idx, 9520 &super_chan_ent); 9521 if (QDF_IS_STATUS_ERROR(status)) { 9522 reg_debug("Failed to get super channel entry for chan_idx %d", 9523 chan_idx); 9524 return false; 9525 } 9526 9527 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 9528 in_6g_pwr_mode = super_chan_ent->best_power_mode; 9529 9530 if (in_6g_pwr_mode != REG_AP_SP) 9531 return false; 9532 9533 return !(super_chan_ent->chan_flags_arr[in_6g_pwr_mode] & 9534 REGULATORY_CHAN_AFC_NOT_DONE); 9535 } 9536 #endif 9537 9538 #ifdef CONFIG_BAND_6GHZ 9539 QDF_STATUS 9540 reg_display_super_chan_list(struct wlan_objmgr_pdev *pdev) 9541 { 9542 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9543 struct super_chan_info *super_chan_list; 9544 uint8_t i; 9545 9546 pdev_priv_obj = reg_get_pdev_obj(pdev); 9547 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9548 reg_err_rl("pdev reg component is NULL"); 9549 return QDF_STATUS_E_FAILURE; 9550 } 9551 9552 super_chan_list = pdev_priv_obj->super_chan_list; 9553 for (i = 0; i < NUM_6GHZ_CHANNELS; i++) { 9554 struct super_chan_info *chan_info = &super_chan_list[i]; 9555 struct regulatory_channel cur_chan_list = 9556 pdev_priv_obj->cur_chan_list[MIN_6GHZ_CHANNEL + i]; 9557 uint8_t j; 9558 9559 qdf_print("Freq = %d\tPower types = 0x%x\t" 9560 "Best power mode = 0x%x\n", 9561 cur_chan_list.center_freq, chan_info->power_types, 9562 chan_info->best_power_mode); 9563 for (j = REG_AP_LPI; j <= REG_CLI_SUB_VLP; j++) { 9564 bool afc_not_done_bit; 9565 9566 afc_not_done_bit = chan_info->chan_flags_arr[j] & 9567 REGULATORY_CHAN_AFC_NOT_DONE; 9568 qdf_print("Power mode = %d\tPSD flag = %d\t" 9569 "PSD power = %d\tEIRP power = %d\t" 9570 "Chan flags = 0x%x\tChannel state = %d\t" 9571 "Min bw = %d\tMax bw = %d\t" 9572 "AFC_NOT_DONE = %d\n", 9573 j, chan_info->reg_chan_pwr[j].psd_flag, 9574 chan_info->reg_chan_pwr[j].psd_eirp, 9575 chan_info->reg_chan_pwr[j].tx_power, 9576 chan_info->chan_flags_arr[j], 9577 chan_info->state_arr[j], 9578 chan_info->min_bw[j], chan_info->max_bw[j], 9579 afc_not_done_bit); 9580 } 9581 } 9582 9583 return QDF_STATUS_SUCCESS; 9584 } 9585 #endif 9586