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 #endif 4870 4871 #ifdef WLAN_FEATURE_11BE 4872 enum channel_state 4873 reg_get_chan_state_for_320(struct wlan_objmgr_pdev *pdev, 4874 uint16_t freq, 4875 qdf_freq_t band_center_320, 4876 enum phy_ch_width ch_width, 4877 const struct bonded_channel_freq 4878 **bonded_chan_ptr_ptr, 4879 enum supported_6g_pwr_types in_6g_pwr_type, 4880 bool treat_nol_chan_as_disabled) 4881 { 4882 uint8_t num_bonded_pairs; 4883 uint16_t array_size = 4884 QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq); 4885 const struct bonded_channel_freq *bonded_ch_ptr[2] = { 4886 NULL, NULL}; 4887 uint16_t punct_pattern; 4888 4889 /* For now sending band center freq as 0 */ 4890 num_bonded_pairs = 4891 reg_get_320_bonded_chan_array(pdev, freq, band_center_320, 4892 bonded_chan_320mhz_list_freq, 4893 array_size, bonded_ch_ptr); 4894 if (!num_bonded_pairs) { 4895 reg_info("No 320MHz bonded pair for freq %d", freq); 4896 return CHANNEL_STATE_INVALID; 4897 } 4898 /* Taking only first bonded pair */ 4899 *bonded_chan_ptr_ptr = bonded_ch_ptr[0]; 4900 4901 return reg_get_320_bonded_channel_state_for_pwrmode(pdev, freq, 4902 bonded_ch_ptr[0], 4903 ch_width, 4904 &punct_pattern, 4905 in_6g_pwr_type, 4906 treat_nol_chan_as_disabled); 4907 } 4908 #endif 4909 4910 #ifdef WLAN_FEATURE_11BE 4911 enum channel_state 4912 reg_get_320_bonded_channel_state_for_pwrmode(struct wlan_objmgr_pdev *pdev, 4913 qdf_freq_t freq, 4914 const struct bonded_channel_freq 4915 *bonded_chan_ptr, 4916 enum phy_ch_width bw, 4917 uint16_t *out_punc_bitmap, 4918 enum supported_6g_pwr_types 4919 in_6g_pwr_type, 4920 bool treat_nol_chan_as_disabled) 4921 { 4922 enum channel_state chan_state = CHANNEL_STATE_INVALID; 4923 enum channel_state temp_chan_state, prim_chan_state; 4924 uint16_t startchan_cfreq, endchan_cfreq; 4925 uint16_t max_cont_bw, i; 4926 4927 *out_punc_bitmap = ALL_SCHANS_PUNC; 4928 4929 if (!bonded_chan_ptr) 4930 return chan_state; 4931 4932 startchan_cfreq = bonded_chan_ptr->start_freq; 4933 endchan_cfreq = 4934 reg_get_endchan_cen_from_bandstart(startchan_cfreq, 4935 BW_320_MHZ); 4936 max_cont_bw = 0; 4937 i = 0; 4938 4939 while (startchan_cfreq <= endchan_cfreq) { 4940 temp_chan_state = 4941 reg_get_20mhz_channel_state_based_on_nol(pdev, 4942 startchan_cfreq, 4943 treat_nol_chan_as_disabled, 4944 in_6g_pwr_type); 4945 4946 if (reg_is_state_allowed(temp_chan_state)) { 4947 max_cont_bw += SUB_CHAN_BW; 4948 *out_punc_bitmap &= ~BIT(i); 4949 } 4950 4951 if (temp_chan_state < chan_state) 4952 chan_state = temp_chan_state; 4953 4954 startchan_cfreq = startchan_cfreq + SUB_CHAN_BW; 4955 i++; 4956 } 4957 4958 prim_chan_state = 4959 reg_get_20mhz_channel_state_based_on_nol(pdev, freq, 4960 treat_nol_chan_as_disabled, 4961 in_6g_pwr_type); 4962 4963 /* After iterating through all the subchannels, if the final channel 4964 * state is invalid/disable, it means all our subchannels are not 4965 * valid and we could not find a 320 MHZ channel. 4966 * If we have found a channel where the max width is: 4967 * 1. Less than 160: there is no puncturing needed. Hence return 4968 * the chan state as invalid. Or if the primary freq given is not 4969 * supported by regulatory, the channel cannot be enabled as a 4970 * punctured channel. So return channel state as invalid. 4971 * 2. If greater than 160: Mark the invalid channels as punctured. 4972 * and return channel state as ENABLE. 4973 */ 4974 if (REG_IS_TOT_CHAN_BW_BELOW_160(chan_state, max_cont_bw) || 4975 !reg_is_state_allowed(prim_chan_state)) 4976 return CHANNEL_STATE_INVALID; 4977 4978 return chan_state; 4979 } 4980 4981 static inline bool reg_is_pri_within_240mhz_chan(qdf_freq_t freq) 4982 { 4983 return (freq >= CHAN_FREQ_5660 && freq <= CHAN_FREQ_5720); 4984 } 4985 4986 /** 4987 * reg_fill_chan320mhz_seg0_center() - Fill the primary segment center 4988 * for a 320MHz channel in the given channel param. Primary segment center 4989 * of a 320MHZ is the 160MHZ segment center of the given freq. 4990 * @pdev: Pointer to struct wlan_objmgr_pdev. 4991 * @ch_param: channel params to be filled. 4992 * @freq: Input primary frequency in MHZ. 4993 * 4994 * Return: void. 4995 */ 4996 static void 4997 reg_fill_chan320mhz_seg0_center(struct wlan_objmgr_pdev *pdev, 4998 struct ch_params *ch_param, qdf_freq_t freq) 4999 { 5000 const struct bonded_channel_freq *t_bonded_ch_ptr; 5001 5002 t_bonded_ch_ptr = reg_get_bonded_chan_entry(freq, CH_WIDTH_160MHZ, 0); 5003 if (t_bonded_ch_ptr) { 5004 ch_param->mhz_freq_seg0 = 5005 (t_bonded_ch_ptr->start_freq + 5006 t_bonded_ch_ptr->end_freq) / 2; 5007 ch_param->center_freq_seg0 = 5008 reg_freq_to_chan(pdev, 5009 ch_param->mhz_freq_seg0); 5010 } else { 5011 /** 5012 * If we do not find a 160Mhz bonded pair, since it is 5013 * for a 320Mhz channel we need to also see if we can find a 5014 * pseudo 160Mhz channel for the special case of 5015 * 5Ghz 240Mhz channel. 5016 */ 5017 if (reg_is_pri_within_240mhz_chan(freq)) { 5018 ch_param->mhz_freq_seg0 = 5019 PRIM_SEG_FREQ_CENTER_240MHZ_5G_CHAN; 5020 ch_param->center_freq_seg0 = 5021 PRIM_SEG_IEEE_CENTER_240MHZ_5G_CHAN; 5022 } else { 5023 ch_param->ch_width = CH_WIDTH_INVALID; 5024 reg_err("Cannot find 160Mhz centers for freq %d", freq); 5025 } 5026 } 5027 } 5028 5029 /** 5030 * reg_fill_channel_list_for_320() - Fill 320MHZ channel list. If we 5031 * are unable to find a channel whose width is greater than 160MHZ and less 5032 * than 320 with the help of puncturing, using the given freq, set "update_bw" 5033 * variable to be true, lower the channel width and return to the caller. 5034 * The caller fetches a channel of reduced mode based on "update_bw" flag. 5035 * 5036 * If 320 band center is 0, return all the 320 channels 5037 * that match the primary frequency else return only channel 5038 * that matches 320 band center. 5039 * 5040 * @pdev: Pointer to struct wlan_objmgr_pdev. 5041 * @freq: Input frequency in MHZ. 5042 * @ch_width: Input channel width, if a channel of the given width is not 5043 * found, reduce the channel width to the next lower mode and pass it to the 5044 * caller. 5045 * @band_center_320: Center of 320MHZ channel. 5046 * @chan_list: Pointer to reg_channel_list to be filled. 5047 * @update_bw: Flag to hold if bw is updated. 5048 * @treat_nol_chan_as_disabled: Bool to treat NOL channels as disabled/enabled 5049 * 5050 * Return - None. 5051 */ 5052 static void 5053 reg_fill_channel_list_for_320(struct wlan_objmgr_pdev *pdev, 5054 qdf_freq_t freq, 5055 enum phy_ch_width *in_ch_width, 5056 qdf_freq_t band_center_320, 5057 struct reg_channel_list *chan_list, 5058 bool *update_bw, 5059 bool treat_nol_chan_as_disabled) 5060 { 5061 uint8_t num_bonded_pairs, i, num_ch_params; 5062 enum channel_state chan_state; 5063 uint16_t array_size = QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq); 5064 uint16_t out_punc_bitmap; 5065 uint16_t max_reg_bw; 5066 enum channel_enum chan_enum; 5067 const struct bonded_channel_freq *bonded_ch_ptr[2] = {NULL, NULL}; 5068 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5069 5070 *update_bw = false; 5071 5072 chan_enum = reg_get_chan_enum_for_freq(freq); 5073 if (reg_is_chan_enum_invalid(chan_enum)) { 5074 reg_err("chan freq is not valid"); 5075 return; 5076 } 5077 5078 pdev_priv_obj = reg_get_pdev_obj(pdev); 5079 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5080 reg_err("reg pdev priv obj is NULL"); 5081 return; 5082 } 5083 5084 /* Maximum bandwidth of the channel supported by regulatory for 5085 * the given freq. 5086 */ 5087 max_reg_bw = pdev_priv_obj->cur_chan_list[chan_enum].max_bw; 5088 5089 /* Regulatory does not support BW greater than 160. 5090 * Try finding a channel in a lower mode. 5091 */ 5092 if (max_reg_bw <= BW_160MHZ) { 5093 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5094 *update_bw = true; 5095 return; 5096 } 5097 5098 num_bonded_pairs = 5099 reg_get_320_bonded_chan_array(pdev, freq, band_center_320, 5100 bonded_chan_320mhz_list_freq, 5101 array_size, 5102 bonded_ch_ptr); 5103 5104 if (!num_bonded_pairs) { 5105 if (band_center_320) { 5106 reg_debug("No bonded pair for the given band_center\n"); 5107 chan_list->num_ch_params = 0; 5108 } else { 5109 /* Could not find a 320 MHZ bonded channel pair, 5110 * find a channel of lower BW. 5111 */ 5112 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5113 *update_bw = true; 5114 } 5115 return; 5116 } 5117 5118 for (i = 0, num_ch_params = 0 ; i < num_bonded_pairs; i++) { 5119 /* Chan_state to hold the channel state of bonding 5120 * pair of channels. 5121 */ 5122 chan_state = 5123 reg_get_320_bonded_channel_state_for_pwrmode( 5124 pdev, freq, 5125 bonded_ch_ptr[i], 5126 *in_ch_width, 5127 &out_punc_bitmap, 5128 REG_CURRENT_PWR_MODE, 5129 treat_nol_chan_as_disabled); 5130 5131 if (reg_is_state_allowed(chan_state)) { 5132 struct ch_params *t_chan_param = 5133 &chan_list->chan_param[num_ch_params]; 5134 5135 t_chan_param->mhz_freq_seg1 = 5136 (bonded_ch_ptr[i]->start_freq + 5137 bonded_ch_ptr[i]->end_freq) / 2; 5138 t_chan_param->center_freq_seg1 = 5139 reg_freq_to_chan(pdev, 5140 t_chan_param->mhz_freq_seg1); 5141 t_chan_param->ch_width = *in_ch_width; 5142 t_chan_param->reg_punc_bitmap = out_punc_bitmap; 5143 5144 reg_fill_chan320mhz_seg0_center(pdev, 5145 t_chan_param, 5146 freq); 5147 num_ch_params++; 5148 chan_list->num_ch_params = num_ch_params; 5149 } 5150 } 5151 5152 /* The bonded pairs could not create any channels, 5153 * lower the bandwidth to find a channel. 5154 */ 5155 if (!chan_list->num_ch_params) { 5156 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5157 *update_bw = true; 5158 } 5159 } 5160 5161 #ifdef CONFIG_REG_6G_PWRMODE 5162 /** 5163 * reg_fill_channel_list_for_320_for_pwrmode() - Fill 320MHZ channel list. If we 5164 * are unable to find a channel whose width is greater than 160MHZ and less 5165 * than 320 with the help of puncturing, using the given freq, set "update_bw" 5166 * variable to be true, lower the channel width and return to the caller. 5167 * The caller fetches a channel of reduced mode based on "update_bw" flag. 5168 * 5169 * If 320 band center is 0, return all the 320 channels 5170 * that match the primary frequency else return only channel 5171 * that matches 320 band center. 5172 * 5173 * @pdev: Pointer to struct wlan_objmgr_pdev. 5174 * @freq: Input frequency in MHZ. 5175 * @ch_width: Input channel width, if a channel of the given width is not 5176 * found, reduce the channel width to the next lower mode and pass it to the 5177 * caller. 5178 * @band_center_320: Center of 320MHZ channel. 5179 * @chan_list: Pointer to reg_channel_list to be filled. 5180 * @update_bw: Flag to hold if bw is updated. 5181 * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based 5182 * channel list will be chosen. 5183 * @treat_nol_chan_as_disabled: Bool to treat NOL channels as disabled/enabled 5184 * 5185 * Return - None. 5186 */ 5187 static void 5188 reg_fill_channel_list_for_320_for_pwrmode( 5189 struct wlan_objmgr_pdev *pdev, 5190 qdf_freq_t freq, 5191 enum phy_ch_width *in_ch_width, 5192 qdf_freq_t band_center_320, 5193 struct reg_channel_list *chan_list, 5194 bool *update_bw, 5195 enum supported_6g_pwr_types in_6g_pwr_mode, 5196 bool treat_nol_chan_as_disabled) 5197 { 5198 uint8_t num_bonded_pairs, i, num_ch_params; 5199 enum channel_state chan_state; 5200 uint16_t array_size = QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq); 5201 uint16_t out_punc_bitmap; 5202 uint16_t max_reg_bw; 5203 enum channel_enum chan_enum; 5204 const struct bonded_channel_freq *bonded_ch_ptr[2] = {NULL, NULL}; 5205 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5206 5207 *update_bw = false; 5208 5209 chan_enum = reg_get_chan_enum_for_freq(freq); 5210 if (reg_is_chan_enum_invalid(chan_enum)) { 5211 reg_err("chan freq is not valid"); 5212 return; 5213 } 5214 5215 pdev_priv_obj = reg_get_pdev_obj(pdev); 5216 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5217 reg_err("reg pdev priv obj is NULL"); 5218 return; 5219 } 5220 5221 /* Maximum bandwidth of the channel supported by regulatory for 5222 * the given freq. 5223 */ 5224 if (reg_get_min_max_bw_reg_chan_list(pdev, chan_enum, in_6g_pwr_mode, 5225 NULL, &max_reg_bw)) 5226 return; 5227 5228 /* Regulatory does not support BW greater than 160. 5229 * Try finding a channel in a lower mode. 5230 */ 5231 if (max_reg_bw <= BW_160MHZ) { 5232 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5233 *update_bw = true; 5234 return; 5235 } 5236 5237 num_bonded_pairs = 5238 reg_get_320_bonded_chan_array(pdev, freq, band_center_320, 5239 bonded_chan_320mhz_list_freq, 5240 array_size, 5241 bonded_ch_ptr); 5242 5243 if (!num_bonded_pairs) { 5244 if (band_center_320) { 5245 reg_debug("No bonded pair for the given band_center\n"); 5246 chan_list->num_ch_params = 0; 5247 } else { 5248 /* Could not find a 320 MHZ bonded channel pair, 5249 * find a channel of lower BW. 5250 */ 5251 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5252 *update_bw = true; 5253 } 5254 return; 5255 } 5256 5257 for (i = 0, num_ch_params = 0 ; i < num_bonded_pairs; i++) { 5258 /* Chan_state to hold the channel state of bonding 5259 * pair of channels. 5260 */ 5261 chan_state = 5262 reg_get_320_bonded_channel_state_for_pwrmode(pdev, freq, 5263 bonded_ch_ptr[i], 5264 *in_ch_width, 5265 &out_punc_bitmap, 5266 in_6g_pwr_mode, 5267 treat_nol_chan_as_disabled); 5268 5269 if (reg_is_state_allowed(chan_state)) { 5270 struct ch_params *t_chan_param = 5271 &chan_list->chan_param[num_ch_params]; 5272 qdf_freq_t start_freq = bonded_ch_ptr[i]->start_freq; 5273 5274 t_chan_param->mhz_freq_seg1 = 5275 reg_get_band_cen_from_bandstart(BW_320_MHZ, 5276 start_freq); 5277 t_chan_param->center_freq_seg1 = 5278 reg_freq_to_chan(pdev, 5279 t_chan_param->mhz_freq_seg1); 5280 t_chan_param->ch_width = *in_ch_width; 5281 t_chan_param->reg_punc_bitmap = out_punc_bitmap; 5282 5283 reg_fill_chan320mhz_seg0_center(pdev, 5284 t_chan_param, 5285 freq); 5286 num_ch_params++; 5287 chan_list->num_ch_params = num_ch_params; 5288 } 5289 } 5290 5291 /* The bonded pairs could not create any channels, 5292 * lower the bandwidth to find a channel. 5293 */ 5294 if (!chan_list->num_ch_params) { 5295 *in_ch_width = get_next_lower_bandwidth(*in_ch_width); 5296 *update_bw = true; 5297 } 5298 } 5299 #endif 5300 5301 /** 5302 * No subchannels are punctured 5303 * binary 1:- Punctured 0:- Not-Punctured. 5304 */ 5305 #define NO_SCHANS_PUNC 0x0000 5306 5307 /** 5308 * reg_fill_pre320mhz_channel() - Fill channel params for channel width 5309 * less than 320. 5310 * @pdev: Pointer to struct wlan_objmgr_pdev 5311 * @chan_list: Pointer to struct reg_channel_list 5312 * @ch_width: Channel width 5313 * @freq: Center frequency of the primary channel in MHz 5314 * @sec_ch_2g_freq: Secondary 2G channel frequency in MHZ 5315 * @treat_nol_chan_as_disabled: Bool to treat NOL channels as 5316 * disabled/enabled 5317 */ 5318 static void 5319 reg_fill_pre320mhz_channel(struct wlan_objmgr_pdev *pdev, 5320 struct reg_channel_list *chan_list, 5321 enum phy_ch_width ch_width, 5322 qdf_freq_t freq, 5323 qdf_freq_t sec_ch_2g_freq, 5324 bool treat_nol_chan_as_disabled) 5325 { 5326 chan_list->num_ch_params = 1; 5327 chan_list->chan_param[0].ch_width = ch_width; 5328 chan_list->chan_param[0].reg_punc_bitmap = NO_SCHANS_PUNC; 5329 reg_set_channel_params_for_freq(pdev, freq, sec_ch_2g_freq, 5330 &chan_list->chan_param[0], 5331 treat_nol_chan_as_disabled); 5332 } 5333 5334 #ifdef CONFIG_REG_6G_PWRMODE 5335 /** 5336 * reg_fill_pre320mhz_channel_for_pwrmode() - Fill channel params for channel 5337 * width less than 320. 5338 * @pdev: Pointer to struct wlan_objmgr_pdev 5339 * @chan_list: Pointer to struct reg_channel_list 5340 * @ch_width: Channel width 5341 * @freq: Center frequency of the primary channel in MHz 5342 * @sec_ch_2g_freq: Secondary 2G channel frequency in MHZ 5343 * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based 5344 * channel list will be chosen. 5345 * @treat_nol_chan_as_disabled: Bool to consider nol chan as enabled/disabled 5346 */ 5347 static void 5348 reg_fill_pre320mhz_channel_for_pwrmode( 5349 struct wlan_objmgr_pdev *pdev, 5350 struct reg_channel_list *chan_list, 5351 enum phy_ch_width ch_width, 5352 qdf_freq_t freq, 5353 qdf_freq_t sec_ch_2g_freq, 5354 enum supported_6g_pwr_types in_6g_pwr_mode, 5355 bool treat_nol_chan_as_disabled) 5356 { 5357 chan_list->num_ch_params = 1; 5358 chan_list->chan_param[0].ch_width = ch_width; 5359 chan_list->chan_param[0].reg_punc_bitmap = NO_SCHANS_PUNC; 5360 reg_set_channel_params_for_pwrmode(pdev, freq, sec_ch_2g_freq, 5361 &chan_list->chan_param[0], 5362 in_6g_pwr_mode, 5363 treat_nol_chan_as_disabled); 5364 } 5365 #endif 5366 5367 void 5368 reg_fill_channel_list(struct wlan_objmgr_pdev *pdev, 5369 qdf_freq_t freq, 5370 qdf_freq_t sec_ch_2g_freq, 5371 enum phy_ch_width in_ch_width, 5372 qdf_freq_t band_center_320, 5373 struct reg_channel_list *chan_list, 5374 bool treat_nol_chan_as_disabled) 5375 { 5376 bool update_bw; 5377 5378 if (!chan_list) { 5379 reg_err("channel params is NULL"); 5380 return; 5381 } 5382 5383 if (in_ch_width >= CH_WIDTH_MAX) 5384 in_ch_width = CH_WIDTH_320MHZ; 5385 5386 if (in_ch_width == CH_WIDTH_320MHZ) { 5387 update_bw = 0; 5388 reg_fill_channel_list_for_320(pdev, freq, &in_ch_width, 5389 band_center_320, chan_list, 5390 &update_bw, 5391 treat_nol_chan_as_disabled); 5392 if (!update_bw) 5393 return; 5394 } 5395 5396 /* A 320 channel is not available (or) user has not requested 5397 * for a 320MHZ channel, look for channels in lower modes, 5398 * reg_set_5g_channel_params_for_freq() finds for the 5399 * next available mode and fills ch_params. 5400 */ 5401 reg_fill_pre320mhz_channel(pdev, chan_list, in_ch_width, freq, 5402 sec_ch_2g_freq, 5403 treat_nol_chan_as_disabled); 5404 } 5405 5406 #ifdef CONFIG_REG_6G_PWRMODE 5407 void 5408 reg_fill_channel_list_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5409 qdf_freq_t freq, 5410 qdf_freq_t sec_ch_2g_freq, 5411 enum phy_ch_width in_ch_width, 5412 qdf_freq_t band_center_320, 5413 struct reg_channel_list *chan_list, 5414 enum supported_6g_pwr_types in_6g_pwr_mode, 5415 bool treat_nol_chan_as_disabled) 5416 { 5417 bool update_bw; 5418 5419 if (!chan_list) { 5420 reg_err("channel params is NULL"); 5421 return; 5422 } 5423 5424 if (in_ch_width >= CH_WIDTH_MAX) 5425 in_ch_width = CH_WIDTH_320MHZ; 5426 5427 if (in_ch_width == CH_WIDTH_320MHZ) { 5428 update_bw = 0; 5429 reg_fill_channel_list_for_320_for_pwrmode( 5430 pdev, freq, &in_ch_width, 5431 band_center_320, chan_list, 5432 &update_bw, in_6g_pwr_mode, 5433 treat_nol_chan_as_disabled); 5434 if (!update_bw) 5435 return; 5436 } 5437 5438 /* A 320 channel is not available (or) user has not requested 5439 * for a 320MHZ channel, look for channels in lower modes, 5440 * reg_set_5g_channel_params_for_freq() finds for the 5441 * next available mode and fills ch_params. 5442 */ 5443 reg_fill_pre320mhz_channel_for_pwrmode( 5444 pdev, chan_list, in_ch_width, freq, 5445 sec_ch_2g_freq, in_6g_pwr_mode, 5446 treat_nol_chan_as_disabled); 5447 } 5448 #endif 5449 #endif 5450 5451 enum channel_state 5452 reg_get_5g_bonded_channel_for_freq(struct wlan_objmgr_pdev *pdev, 5453 uint16_t freq, 5454 enum phy_ch_width ch_width, 5455 const struct bonded_channel_freq 5456 **bonded_chan_ptr_ptr) 5457 { 5458 if (ch_width == CH_WIDTH_20MHZ) 5459 return reg_get_channel_state_for_freq(pdev, freq); 5460 5461 if (reg_is_ch_width_320(ch_width)) { 5462 return reg_get_chan_state_for_320(pdev, freq, 0, 5463 ch_width, 5464 bonded_chan_ptr_ptr, 5465 REG_CURRENT_PWR_MODE, 5466 true); 5467 } else { 5468 *bonded_chan_ptr_ptr = reg_get_bonded_chan_entry(freq, 5469 ch_width, 0); 5470 if (!(*bonded_chan_ptr_ptr)) 5471 return CHANNEL_STATE_INVALID; 5472 5473 return reg_get_5g_bonded_chan_array_for_freq( 5474 pdev, freq, 5475 *bonded_chan_ptr_ptr); 5476 } 5477 } 5478 5479 #ifdef CONFIG_REG_6G_PWRMODE 5480 enum channel_state 5481 reg_get_5g_bonded_channel_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5482 uint16_t freq, 5483 enum phy_ch_width ch_width, 5484 const struct bonded_channel_freq 5485 **bonded_chan_ptr_ptr, 5486 enum supported_6g_pwr_types 5487 in_6g_pwr_mode) 5488 { 5489 if (ch_width == CH_WIDTH_20MHZ) 5490 return reg_get_channel_state_for_pwrmode(pdev, freq, 5491 in_6g_pwr_mode); 5492 5493 if (reg_is_ch_width_320(ch_width)) 5494 return reg_get_chan_state_for_320(pdev, freq, 0, 5495 ch_width, 5496 bonded_chan_ptr_ptr, 5497 in_6g_pwr_mode, true); 5498 /* Fetch the bonded_chan_ptr for width greater than 20MHZ. */ 5499 *bonded_chan_ptr_ptr = reg_get_bonded_chan_entry(freq, ch_width, 0); 5500 5501 if (!(*bonded_chan_ptr_ptr)) { 5502 reg_debug_rl("bonded_chan_ptr_ptr is NULL"); 5503 return CHANNEL_STATE_INVALID; 5504 } 5505 5506 return reg_get_5g_bonded_chan_array_for_pwrmode(pdev, freq, 5507 *bonded_chan_ptr_ptr, 5508 in_6g_pwr_mode); 5509 } 5510 #endif 5511 5512 #ifdef CONFIG_REG_6G_PWRMODE 5513 /** 5514 * reg_set_5g_channel_params_for_pwrmode()- Set channel parameters like center 5515 * frequency for a bonded channel state. Also return the maximum bandwidth 5516 * supported by the channel. 5517 * @pdev: Pointer to pdev. 5518 * @freq: Channel center frequency. 5519 * ch_params: Pointer to ch_params. 5520 * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based 5521 * channel list will be chosen. 5522 * @treat_nol_chan_as_disabled: Bool to treat NOL channels as disabled/enabled 5523 * 5524 * Return: void 5525 */ 5526 static void reg_set_5g_channel_params_for_pwrmode( 5527 struct wlan_objmgr_pdev *pdev, 5528 uint16_t freq, 5529 struct ch_params *ch_params, 5530 enum supported_6g_pwr_types 5531 in_6g_pwr_type, 5532 bool treat_nol_chan_as_disabled) 5533 { 5534 /* 5535 * Set channel parameters like center frequency for a bonded channel 5536 * state. Also return the maximum bandwidth supported by the channel. 5537 */ 5538 5539 enum channel_state chan_state = CHANNEL_STATE_ENABLE; 5540 enum channel_state chan_state2 = CHANNEL_STATE_ENABLE; 5541 const struct bonded_channel_freq *bonded_chan_ptr = NULL; 5542 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5543 enum channel_enum chan_enum, sec_5g_chan_enum; 5544 uint16_t bw_80 = 0; 5545 uint16_t max_bw, sec_5g_freq_max_bw = 0; 5546 5547 if (!ch_params) { 5548 reg_err("ch_params is NULL"); 5549 return; 5550 } 5551 5552 chan_enum = reg_get_chan_enum_for_freq(freq); 5553 if (reg_is_chan_enum_invalid(chan_enum)) { 5554 reg_err("chan freq is not valid"); 5555 return; 5556 } 5557 5558 pdev_priv_obj = reg_get_pdev_obj(pdev); 5559 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5560 reg_err("reg pdev priv obj is NULL"); 5561 return; 5562 } 5563 5564 if (ch_params->ch_width >= CH_WIDTH_MAX) { 5565 if (ch_params->mhz_freq_seg1 != 0) 5566 ch_params->ch_width = CH_WIDTH_80P80MHZ; 5567 else 5568 ch_params->ch_width = CH_WIDTH_160MHZ; 5569 } 5570 5571 if (reg_get_min_max_bw_reg_chan_list(pdev, chan_enum, in_6g_pwr_type, 5572 NULL, &max_bw)) 5573 return; 5574 5575 bw_80 = reg_get_bw_value(CH_WIDTH_80MHZ); 5576 5577 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 5578 sec_5g_chan_enum = 5579 reg_get_chan_enum_for_freq(ch_params->mhz_freq_seg1 - 5580 NEAREST_20MHZ_CHAN_FREQ_OFFSET); 5581 if (reg_is_chan_enum_invalid(sec_5g_chan_enum)) { 5582 reg_err("secondary channel freq is not valid"); 5583 return; 5584 } 5585 5586 if (reg_get_min_max_bw_reg_chan_list(pdev, sec_5g_chan_enum, 5587 in_6g_pwr_type, 5588 NULL, &sec_5g_freq_max_bw)) 5589 return; 5590 } 5591 5592 while (ch_params->ch_width != CH_WIDTH_INVALID) { 5593 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 5594 if ((max_bw < bw_80) || (sec_5g_freq_max_bw < bw_80)) 5595 goto update_bw; 5596 } else if (max_bw < reg_get_bw_value(ch_params->ch_width)) { 5597 goto update_bw; 5598 } 5599 5600 bonded_chan_ptr = NULL; 5601 chan_state = reg_get_5g_bonded_channel_for_pwrmode( 5602 pdev, freq, ch_params->ch_width, 5603 &bonded_chan_ptr, in_6g_pwr_type); 5604 chan_state = 5605 reg_get_ch_state_based_on_nol_flag(pdev, freq, 5606 ch_params, 5607 in_6g_pwr_type, 5608 treat_nol_chan_as_disabled); 5609 5610 if (ch_params->ch_width == CH_WIDTH_80P80MHZ) { 5611 struct ch_params temp_ch_params = {0}; 5612 5613 temp_ch_params.ch_width = CH_WIDTH_80MHZ; 5614 /* Puncturing patter is not needed for 80+80 */ 5615 reg_set_create_punc_bitmap(&temp_ch_params, false); 5616 chan_state2 = 5617 reg_get_ch_state_based_on_nol_flag(pdev, 5618 ch_params->mhz_freq_seg1 - 5619 NEAREST_20MHZ_CHAN_FREQ_OFFSET, 5620 &temp_ch_params, in_6g_pwr_type, 5621 treat_nol_chan_as_disabled); 5622 chan_state = reg_combine_channel_states( 5623 chan_state, chan_state2); 5624 } 5625 5626 if ((chan_state != CHANNEL_STATE_ENABLE) && 5627 (chan_state != CHANNEL_STATE_DFS)) 5628 goto update_bw; 5629 if (ch_params->ch_width <= CH_WIDTH_20MHZ) { 5630 ch_params->sec_ch_offset = NO_SEC_CH; 5631 ch_params->mhz_freq_seg0 = freq; 5632 ch_params->center_freq_seg0 = 5633 reg_freq_to_chan(pdev, 5634 ch_params->mhz_freq_seg0); 5635 break; 5636 } else if (ch_params->ch_width >= CH_WIDTH_40MHZ) { 5637 const struct bonded_channel_freq *bonded_chan_ptr2; 5638 5639 bonded_chan_ptr2 = 5640 reg_get_bonded_chan_entry( 5641 freq, 5642 CH_WIDTH_40MHZ, 5643 0); 5644 5645 if (!bonded_chan_ptr || !bonded_chan_ptr2) 5646 goto update_bw; 5647 if (freq == bonded_chan_ptr2->start_freq) 5648 ch_params->sec_ch_offset = LOW_PRIMARY_CH; 5649 else 5650 ch_params->sec_ch_offset = HIGH_PRIMARY_CH; 5651 5652 ch_params->mhz_freq_seg0 = 5653 (bonded_chan_ptr->start_freq + 5654 bonded_chan_ptr->end_freq) / 2; 5655 ch_params->center_freq_seg0 = 5656 reg_freq_to_chan(pdev, 5657 ch_params->mhz_freq_seg0); 5658 break; 5659 } 5660 update_bw: 5661 ch_params->ch_width = 5662 get_next_lower_bandwidth(ch_params->ch_width); 5663 } 5664 5665 if (ch_params->ch_width == CH_WIDTH_160MHZ) { 5666 ch_params->mhz_freq_seg1 = ch_params->mhz_freq_seg0; 5667 ch_params->center_freq_seg1 = 5668 reg_freq_to_chan(pdev, 5669 ch_params->mhz_freq_seg1); 5670 5671 chan_state = reg_get_5g_bonded_channel_for_pwrmode( 5672 pdev, freq, CH_WIDTH_80MHZ, &bonded_chan_ptr, 5673 in_6g_pwr_type); 5674 if (bonded_chan_ptr) { 5675 ch_params->mhz_freq_seg0 = 5676 (bonded_chan_ptr->start_freq + 5677 bonded_chan_ptr->end_freq) / 2; 5678 ch_params->center_freq_seg0 = 5679 reg_freq_to_chan(pdev, 5680 ch_params->mhz_freq_seg0); 5681 } 5682 } 5683 5684 /* Overwrite mhz_freq_seg1 to 0 for non 160 and 80+80 width */ 5685 if (!(ch_params->ch_width == CH_WIDTH_160MHZ || 5686 ch_params->ch_width == CH_WIDTH_80P80MHZ)) { 5687 ch_params->mhz_freq_seg1 = 0; 5688 ch_params->center_freq_seg1 = 0; 5689 } 5690 } 5691 #endif 5692 5693 #ifdef CONFIG_REG_CLIENT 5694 static qdf_freq_t reg_get_sec_ch_2g_freq(struct wlan_objmgr_pdev *pdev, 5695 qdf_freq_t primary_freq) 5696 { 5697 qdf_freq_t sec_ch_2g_freq = 0; 5698 5699 if (primary_freq >= TWOG_CHAN_1_IN_MHZ && 5700 primary_freq <= TWOG_CHAN_5_IN_MHZ) 5701 sec_ch_2g_freq = primary_freq + HT40_SEC_OFFSET; 5702 else if (primary_freq >= TWOG_CHAN_6_IN_MHZ && 5703 primary_freq <= TWOG_CHAN_13_IN_MHZ) 5704 sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET; 5705 5706 return sec_ch_2g_freq; 5707 } 5708 #else 5709 static qdf_freq_t reg_get_sec_ch_2g_freq(struct wlan_objmgr_pdev *pdev, 5710 qdf_freq_t primary_freq) 5711 { 5712 qdf_freq_t sec_ch_2g_freq; 5713 5714 if (primary_freq < TWOG_CHAN_1_IN_MHZ || 5715 primary_freq > TWOG_CHAN_13_IN_MHZ) 5716 return 0; 5717 5718 sec_ch_2g_freq = primary_freq + HT40_SEC_OFFSET; 5719 5720 /* For 2G primary frequencies > 2452 (IEEE9), return HT40-. */ 5721 if (primary_freq > TWOG_CHAN_9_IN_MHZ) 5722 sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET; 5723 5724 /* 5725 * For 2G primary frequencies <= 2452 (IEEE9), return HT40+ if 5726 * the secondary is available, else return HT40-. 5727 */ 5728 else if (!reg_is_freq_present_in_cur_chan_list(pdev, sec_ch_2g_freq)) 5729 sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET; 5730 5731 return sec_ch_2g_freq; 5732 } 5733 #endif 5734 5735 void reg_set_2g_channel_params_for_freq(struct wlan_objmgr_pdev *pdev, 5736 uint16_t oper_freq, 5737 struct ch_params *ch_params, 5738 uint16_t sec_ch_2g_freq) 5739 { 5740 enum channel_state chan_state = CHANNEL_STATE_ENABLE; 5741 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5742 enum channel_enum chan_enum; 5743 uint16_t max_bw; 5744 5745 chan_enum = reg_get_chan_enum_for_freq(oper_freq); 5746 if (reg_is_chan_enum_invalid(chan_enum)) { 5747 reg_err("chan freq is not valid"); 5748 return; 5749 } 5750 5751 pdev_priv_obj = reg_get_pdev_obj(pdev); 5752 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5753 reg_err("reg pdev priv obj is NULL"); 5754 return; 5755 } 5756 5757 if (ch_params->ch_width >= CH_WIDTH_MAX) 5758 ch_params->ch_width = CH_WIDTH_40MHZ; 5759 if ((reg_get_bw_value(ch_params->ch_width) > 20) && !sec_ch_2g_freq) 5760 sec_ch_2g_freq = reg_get_sec_ch_2g_freq(pdev, oper_freq); 5761 5762 max_bw = pdev_priv_obj->cur_chan_list[chan_enum].max_bw; 5763 5764 while (ch_params->ch_width != CH_WIDTH_INVALID) { 5765 if (max_bw < reg_get_bw_value(ch_params->ch_width)) 5766 goto update_bw; 5767 5768 chan_state = 5769 reg_get_2g_bonded_channel_state_for_freq(pdev, oper_freq, 5770 sec_ch_2g_freq, 5771 ch_params->ch_width); 5772 if ((chan_state == CHANNEL_STATE_ENABLE) || 5773 (chan_state == CHANNEL_STATE_DFS)) { 5774 if (ch_params->ch_width == CH_WIDTH_40MHZ) { 5775 if (oper_freq < sec_ch_2g_freq) 5776 ch_params->sec_ch_offset = 5777 LOW_PRIMARY_CH; 5778 else 5779 ch_params->sec_ch_offset = 5780 HIGH_PRIMARY_CH; 5781 ch_params->mhz_freq_seg0 = 5782 (oper_freq + sec_ch_2g_freq) / 2; 5783 if (ch_params->mhz_freq_seg0 == 5784 TWOG_CHAN_14_IN_MHZ) 5785 ch_params->center_freq_seg0 = 14; 5786 else 5787 ch_params->center_freq_seg0 = 5788 (ch_params->mhz_freq_seg0 - 5789 TWOG_STARTING_FREQ) / 5790 FREQ_TO_CHAN_SCALE; 5791 } else { 5792 ch_params->sec_ch_offset = NO_SEC_CH; 5793 ch_params->mhz_freq_seg0 = oper_freq; 5794 if (ch_params->mhz_freq_seg0 == 5795 TWOG_CHAN_14_IN_MHZ) 5796 ch_params->center_freq_seg0 = 14; 5797 else 5798 ch_params->center_freq_seg0 = 5799 (ch_params->mhz_freq_seg0 - 5800 TWOG_STARTING_FREQ) / 5801 FREQ_TO_CHAN_SCALE; 5802 } 5803 break; 5804 } 5805 update_bw: 5806 ch_params->ch_width = 5807 get_next_lower_bandwidth(ch_params->ch_width); 5808 } 5809 /* Overwrite mhz_freq_seg1 and center_freq_seg1 to 0 for 2.4 Ghz */ 5810 ch_params->mhz_freq_seg1 = 0; 5811 ch_params->center_freq_seg1 = 0; 5812 } 5813 5814 #ifdef WLAN_FEATURE_11BE 5815 static void reg_copy_ch_params(struct ch_params *ch_params, 5816 struct reg_channel_list chan_list) 5817 { 5818 ch_params->center_freq_seg0 = chan_list.chan_param[0].center_freq_seg0; 5819 ch_params->center_freq_seg1 = chan_list.chan_param[0].center_freq_seg1; 5820 ch_params->mhz_freq_seg0 = chan_list.chan_param[0].mhz_freq_seg0; 5821 ch_params->mhz_freq_seg1 = chan_list.chan_param[0].mhz_freq_seg1; 5822 ch_params->ch_width = chan_list.chan_param[0].ch_width; 5823 ch_params->sec_ch_offset = chan_list.chan_param[0].sec_ch_offset; 5824 ch_params->reg_punc_bitmap = chan_list.chan_param[0].reg_punc_bitmap; 5825 } 5826 5827 void reg_set_channel_params_for_freq(struct wlan_objmgr_pdev *pdev, 5828 qdf_freq_t freq, 5829 qdf_freq_t sec_ch_2g_freq, 5830 struct ch_params *ch_params, 5831 bool treat_nol_chan_as_disabled) 5832 { 5833 if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) { 5834 if (reg_is_ch_width_320(ch_params->ch_width)) { 5835 struct reg_channel_list chan_list; 5836 5837 qdf_mem_zero(&chan_list, sizeof(chan_list)); 5838 /* For now sending center freq as 0 */ 5839 reg_fill_channel_list(pdev, freq, sec_ch_2g_freq, 5840 ch_params->ch_width, 0, 5841 &chan_list, 5842 treat_nol_chan_as_disabled); 5843 reg_copy_ch_params(ch_params, chan_list); 5844 } else { 5845 reg_set_5g_channel_params_for_pwrmode( 5846 pdev, freq, 5847 ch_params, 5848 REG_CURRENT_PWR_MODE, 5849 treat_nol_chan_as_disabled); 5850 } 5851 } else if (reg_is_24ghz_ch_freq(freq)) { 5852 reg_set_2g_channel_params_for_freq(pdev, freq, ch_params, 5853 sec_ch_2g_freq); 5854 } 5855 } 5856 #else /* WLAN_FEATURE_11BE */ 5857 void reg_set_channel_params_for_freq(struct wlan_objmgr_pdev *pdev, 5858 qdf_freq_t freq, 5859 qdf_freq_t sec_ch_2g_freq, 5860 struct ch_params *ch_params, 5861 bool treat_nol_chan_as_disabled) 5862 { 5863 if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) 5864 reg_set_5g_channel_params_for_pwrmode( 5865 pdev, freq, ch_params, 5866 REG_CURRENT_PWR_MODE, 5867 treat_nol_chan_as_disabled); 5868 else if (reg_is_24ghz_ch_freq(freq)) 5869 reg_set_2g_channel_params_for_freq(pdev, freq, ch_params, 5870 sec_ch_2g_freq); 5871 } 5872 #endif /* WLAN_FEATURE_11BE */ 5873 5874 #ifdef CONFIG_REG_6G_PWRMODE 5875 #ifdef WLAN_FEATURE_11BE 5876 void 5877 reg_set_channel_params_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5878 qdf_freq_t freq, 5879 qdf_freq_t sec_ch_2g_freq, 5880 struct ch_params *ch_params, 5881 enum supported_6g_pwr_types in_6g_pwr_mode, 5882 bool is_treat_nol_dis) 5883 { 5884 if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) { 5885 if (reg_is_ch_width_320(ch_params->ch_width)) { 5886 struct reg_channel_list chan_list; 5887 5888 qdf_mem_zero(&chan_list, sizeof(chan_list)); 5889 /* For now sending center freq as 0 */ 5890 reg_fill_channel_list_for_pwrmode(pdev, freq, 5891 sec_ch_2g_freq, 5892 ch_params->ch_width, 5893 0, &chan_list, 5894 in_6g_pwr_mode, 5895 is_treat_nol_dis); 5896 reg_copy_ch_params(ch_params, chan_list); 5897 } else { 5898 reg_set_5g_channel_params_for_pwrmode(pdev, freq, 5899 ch_params, 5900 in_6g_pwr_mode, 5901 is_treat_nol_dis); 5902 } 5903 } else if (reg_is_24ghz_ch_freq(freq)) { 5904 reg_set_2g_channel_params_for_freq(pdev, freq, ch_params, 5905 sec_ch_2g_freq); 5906 } 5907 } 5908 #else 5909 void 5910 reg_set_channel_params_for_pwrmode(struct wlan_objmgr_pdev *pdev, 5911 qdf_freq_t freq, 5912 qdf_freq_t sec_ch_2g_freq, 5913 struct ch_params *ch_params, 5914 enum supported_6g_pwr_types in_6g_pwr_mode, 5915 bool is_treat_nol_dis) 5916 { 5917 if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) 5918 reg_set_5g_channel_params_for_pwrmode(pdev, freq, ch_params, 5919 in_6g_pwr_mode, 5920 is_treat_nol_dis); 5921 else if (reg_is_24ghz_ch_freq(freq)) 5922 reg_set_2g_channel_params_for_freq(pdev, freq, ch_params, 5923 sec_ch_2g_freq); 5924 } 5925 #endif 5926 #endif 5927 5928 uint8_t reg_get_channel_reg_power_for_freq(struct wlan_objmgr_pdev *pdev, 5929 qdf_freq_t freq) 5930 { 5931 enum channel_enum chan_enum; 5932 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 5933 struct regulatory_channel *reg_channels; 5934 5935 chan_enum = reg_get_chan_enum_for_freq(freq); 5936 5937 if (reg_is_chan_enum_invalid(chan_enum)) { 5938 reg_err("channel is invalid"); 5939 return REG_INVALID_TXPOWER; 5940 } 5941 5942 pdev_priv_obj = reg_get_pdev_obj(pdev); 5943 5944 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 5945 reg_err("reg pdev priv obj is NULL"); 5946 return REG_INVALID_TXPOWER; 5947 } 5948 5949 reg_channels = pdev_priv_obj->cur_chan_list; 5950 5951 return reg_channels[chan_enum].tx_power; 5952 } 5953 5954 bool reg_is_dfs_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 5955 { 5956 uint32_t chan_flags; 5957 5958 chan_flags = reg_get_channel_flags_for_freq(pdev, freq); 5959 5960 return chan_flags & REGULATORY_CHAN_RADAR; 5961 } 5962 5963 #ifdef CONFIG_REG_CLIENT 5964 bool reg_is_dfs_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev, 5965 qdf_freq_t freq) 5966 { 5967 uint32_t chan_flags; 5968 5969 chan_flags = reg_get_channel_flags_from_secondary_list_for_freq(pdev, 5970 freq); 5971 5972 return chan_flags & REGULATORY_CHAN_RADAR; 5973 } 5974 5975 /** 5976 * reg_get_psoc_mas_chan_list () - Get psoc master channel list 5977 * @pdev: pointer to pdev object 5978 * @psoc: pointer to psoc object 5979 * 5980 * Return: psoc master chanel list 5981 */ 5982 static struct regulatory_channel *reg_get_psoc_mas_chan_list( 5983 struct wlan_objmgr_pdev *pdev, 5984 struct wlan_objmgr_psoc *psoc) 5985 { 5986 struct wlan_regulatory_psoc_priv_obj *soc_reg; 5987 uint8_t pdev_id; 5988 uint8_t phy_id; 5989 struct wlan_lmac_if_reg_tx_ops *reg_tx_ops; 5990 5991 soc_reg = reg_get_psoc_obj(psoc); 5992 if (!soc_reg) { 5993 reg_err("reg psoc private obj is NULL"); 5994 return NULL; 5995 } 5996 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 5997 5998 reg_tx_ops = reg_get_psoc_tx_ops(psoc); 5999 if (reg_tx_ops->get_phy_id_from_pdev_id) 6000 reg_tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id); 6001 else 6002 phy_id = pdev_id; 6003 6004 return soc_reg->mas_chan_params[phy_id].mas_chan_list; 6005 } 6006 #else 6007 static inline struct regulatory_channel *reg_get_psoc_mas_chan_list( 6008 struct wlan_objmgr_pdev *pdev, 6009 struct wlan_objmgr_psoc *psoc) 6010 { 6011 return NULL; 6012 } 6013 #endif 6014 6015 void reg_update_nol_ch_for_freq(struct wlan_objmgr_pdev *pdev, 6016 uint16_t *chan_freq_list, 6017 uint8_t num_chan, 6018 bool nol_chan) 6019 { 6020 enum channel_enum chan_enum; 6021 struct regulatory_channel *mas_chan_list = NULL, *psoc_mas_chan_list; 6022 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6023 struct wlan_objmgr_psoc *psoc; 6024 uint16_t i; 6025 6026 if (!num_chan || !chan_freq_list) { 6027 reg_err("chan_freq_list or num_ch is NULL"); 6028 return; 6029 } 6030 6031 psoc = wlan_pdev_get_psoc(pdev); 6032 6033 6034 psoc_mas_chan_list = reg_get_psoc_mas_chan_list(pdev, psoc); 6035 pdev_priv_obj = reg_get_pdev_obj(pdev); 6036 6037 if (pdev_priv_obj) 6038 mas_chan_list = pdev_priv_obj->mas_chan_list; 6039 6040 for (i = 0; i < num_chan; i++) { 6041 chan_enum = reg_get_chan_enum_for_freq(chan_freq_list[i]); 6042 if (reg_is_chan_enum_invalid(chan_enum)) { 6043 reg_err("Invalid freq in nol list, freq %d", 6044 chan_freq_list[i]); 6045 continue; 6046 } 6047 if (mas_chan_list) 6048 mas_chan_list[chan_enum].nol_chan = nol_chan; 6049 if (psoc_mas_chan_list) 6050 psoc_mas_chan_list[chan_enum].nol_chan = nol_chan; 6051 } 6052 6053 if (!pdev_priv_obj) { 6054 reg_err("reg pdev private obj is NULL"); 6055 return; 6056 } 6057 6058 reg_compute_pdev_current_chan_list(pdev_priv_obj); 6059 6060 reg_send_scheduler_msg_sb(psoc, pdev); 6061 } 6062 6063 void reg_update_nol_history_ch_for_freq(struct wlan_objmgr_pdev *pdev, 6064 uint16_t *chan_list, 6065 uint8_t num_chan, 6066 bool nol_history_chan) 6067 { 6068 enum channel_enum chan_enum; 6069 struct regulatory_channel *mas_chan_list; 6070 struct regulatory_channel *cur_chan_list; 6071 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6072 uint16_t i; 6073 6074 if (!num_chan || !chan_list) { 6075 reg_err("chan_list or num_ch is NULL"); 6076 return; 6077 } 6078 6079 pdev_priv_obj = wlan_objmgr_pdev_get_comp_private_obj( 6080 pdev, WLAN_UMAC_COMP_REGULATORY); 6081 6082 if (!pdev_priv_obj) { 6083 reg_err("reg psoc private obj is NULL"); 6084 return; 6085 } 6086 6087 mas_chan_list = pdev_priv_obj->mas_chan_list; 6088 cur_chan_list = pdev_priv_obj->cur_chan_list; 6089 6090 for (i = 0; i < num_chan; i++) { 6091 chan_enum = reg_get_chan_enum_for_freq(chan_list[i]); 6092 if (reg_is_chan_enum_invalid(chan_enum)) { 6093 reg_err("Invalid ch in nol list, chan %d", 6094 chan_list[i]); 6095 continue; 6096 } 6097 mas_chan_list[chan_enum].nol_history = nol_history_chan; 6098 cur_chan_list[chan_enum].nol_history = nol_history_chan; 6099 } 6100 } 6101 6102 qdf_freq_t reg_min_chan_freq(void) 6103 { 6104 return channel_map[MIN_24GHZ_CHANNEL].center_freq; 6105 } 6106 6107 qdf_freq_t reg_max_chan_freq(void) 6108 { 6109 return channel_map[NUM_CHANNELS - 1].center_freq; 6110 } 6111 6112 bool reg_is_same_band_freqs(qdf_freq_t freq1, qdf_freq_t freq2) 6113 { 6114 return (freq1 && freq2 && ((REG_IS_6GHZ_FREQ(freq1) && 6115 REG_IS_6GHZ_FREQ(freq2)) || 6116 (REG_IS_5GHZ_FREQ(freq1) && 6117 REG_IS_5GHZ_FREQ(freq2)) || 6118 (REG_IS_24GHZ_CH_FREQ(freq1) && 6119 REG_IS_24GHZ_CH_FREQ(freq2)))); 6120 } 6121 6122 enum reg_wifi_band reg_freq_to_band(qdf_freq_t freq) 6123 { 6124 if (REG_IS_24GHZ_CH_FREQ(freq)) 6125 return REG_BAND_2G; 6126 else if (REG_IS_5GHZ_FREQ(freq) || REG_IS_49GHZ_FREQ(freq)) 6127 return REG_BAND_5G; 6128 else if (REG_IS_6GHZ_FREQ(freq)) 6129 return REG_BAND_6G; 6130 return REG_BAND_UNKNOWN; 6131 } 6132 6133 #ifdef CONFIG_REG_6G_PWRMODE 6134 bool reg_is_disable_for_pwrmode(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq, 6135 enum supported_6g_pwr_types in_6g_pwr_mode) 6136 { 6137 enum channel_state ch_state; 6138 6139 ch_state = reg_get_channel_state_for_pwrmode(pdev, 6140 freq, 6141 in_6g_pwr_mode); 6142 6143 return (ch_state == CHANNEL_STATE_DISABLE) || 6144 (ch_state == CHANNEL_STATE_INVALID); 6145 } 6146 #endif 6147 6148 #ifdef CONFIG_REG_CLIENT 6149 bool reg_is_disable_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev, 6150 qdf_freq_t freq) 6151 { 6152 enum channel_state ch_state; 6153 6154 ch_state = reg_get_channel_state_from_secondary_list_for_freq(pdev, 6155 freq); 6156 6157 return ch_state == CHANNEL_STATE_DISABLE; 6158 } 6159 6160 bool reg_is_enable_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev, 6161 qdf_freq_t freq) 6162 { 6163 enum channel_state ch_state; 6164 6165 ch_state = reg_get_channel_state_from_secondary_list_for_freq(pdev, 6166 freq); 6167 6168 return ch_state == CHANNEL_STATE_ENABLE; 6169 } 6170 6171 #ifdef CONFIG_BAND_6GHZ 6172 static uint8_t reg_get_max_tx_power_from_super_chan_list( 6173 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 6174 enum supported_6g_pwr_types in_6g_pwr_type) 6175 { 6176 struct super_chan_info *sc_entry; 6177 enum supported_6g_pwr_types pwr_type; 6178 uint8_t i, max_tx_power = 0; 6179 6180 pwr_type = in_6g_pwr_type; 6181 for (i = 0; i < NUM_6GHZ_CHANNELS; i++) { 6182 sc_entry = &pdev_priv_obj->super_chan_list[i]; 6183 6184 if (in_6g_pwr_type == REG_BEST_PWR_MODE) 6185 pwr_type = sc_entry->best_power_mode; 6186 6187 if (reg_is_supp_pwr_mode_invalid(pwr_type)) 6188 continue; 6189 6190 if (!reg_is_chan_disabled(sc_entry->chan_flags_arr[pwr_type], 6191 sc_entry->state_arr[pwr_type]) && 6192 (sc_entry->reg_chan_pwr[pwr_type].tx_power > max_tx_power)) 6193 max_tx_power = 6194 sc_entry->reg_chan_pwr[pwr_type].tx_power; 6195 } 6196 return max_tx_power; 6197 } 6198 #else 6199 static inline uint8_t reg_get_max_tx_power_from_super_chan_list( 6200 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 6201 enum supported_6g_pwr_types in_6g_pwr_type) 6202 { 6203 return 0; 6204 } 6205 #endif 6206 6207 uint8_t reg_get_max_tx_power_for_pwr_mode( 6208 struct wlan_objmgr_pdev *pdev, 6209 enum supported_6g_pwr_types in_6g_pwr_type) 6210 { 6211 uint8_t i, max_tx_power = 0, max_super_chan_power = 0; 6212 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6213 uint16_t max_curr_num_chan; 6214 6215 if (!pdev) { 6216 reg_err_rl("invalid pdev"); 6217 return QDF_STATUS_E_INVAL; 6218 } 6219 6220 pdev_priv_obj = reg_get_pdev_obj(pdev); 6221 6222 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6223 reg_err_rl("reg pdev priv obj is NULL"); 6224 return QDF_STATUS_E_INVAL; 6225 } 6226 6227 if (in_6g_pwr_type == REG_CURRENT_PWR_MODE) 6228 max_curr_num_chan = NUM_CHANNELS; 6229 else 6230 max_curr_num_chan = MAX_5GHZ_CHANNEL; 6231 6232 for (i = 0; i < max_curr_num_chan; i++) { 6233 if (!reg_is_chan_disabled( 6234 pdev_priv_obj->cur_chan_list[i].chan_flags, 6235 pdev_priv_obj->cur_chan_list[i].state) && 6236 (pdev_priv_obj->cur_chan_list[i].tx_power > max_tx_power)) 6237 max_tx_power = 6238 pdev_priv_obj->cur_chan_list[i].tx_power; 6239 } 6240 6241 if (in_6g_pwr_type == REG_CURRENT_PWR_MODE) 6242 goto return_max_tx_power; 6243 6244 max_super_chan_power = reg_get_max_tx_power_from_super_chan_list( 6245 pdev_priv_obj, 6246 in_6g_pwr_type); 6247 6248 if (max_super_chan_power > max_tx_power) 6249 max_tx_power = max_super_chan_power; 6250 6251 return_max_tx_power: 6252 6253 if (!max_tx_power) 6254 reg_err_rl("max_tx_power is zero"); 6255 6256 return max_tx_power; 6257 } 6258 #endif 6259 6260 bool reg_is_passive_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 6261 { 6262 uint32_t chan_flags; 6263 6264 chan_flags = reg_get_channel_flags_for_freq(pdev, freq); 6265 6266 return chan_flags & REGULATORY_CHAN_NO_IR; 6267 } 6268 #endif /* CONFIG_CHAN_FREQ_API */ 6269 6270 uint8_t reg_get_max_tx_power(struct wlan_objmgr_pdev *pdev) 6271 { 6272 struct regulatory_channel *cur_chan_list; 6273 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6274 uint8_t i, max_tx_power = 0; 6275 6276 pdev_priv_obj = reg_get_pdev_obj(pdev); 6277 6278 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6279 reg_err("reg pdev private obj is NULL"); 6280 return QDF_STATUS_E_FAILURE; 6281 } 6282 6283 cur_chan_list = pdev_priv_obj->cur_chan_list; 6284 6285 for (i = 0; i < NUM_CHANNELS; i++) { 6286 if (cur_chan_list[i].state != CHANNEL_STATE_DISABLE && 6287 cur_chan_list[i].chan_flags != REGULATORY_CHAN_DISABLED) { 6288 if (cur_chan_list[i].tx_power > max_tx_power) 6289 max_tx_power = cur_chan_list[i].tx_power; 6290 } 6291 } 6292 6293 if (!max_tx_power) 6294 reg_err_rl("max_tx_power is zero"); 6295 6296 return max_tx_power; 6297 } 6298 6299 QDF_STATUS reg_set_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc) 6300 { 6301 struct wlan_regulatory_psoc_priv_obj *psoc_reg; 6302 6303 psoc_reg = reg_get_psoc_obj(psoc); 6304 if (!IS_VALID_PSOC_REG_OBJ(psoc_reg)) { 6305 reg_err("psoc reg component is NULL"); 6306 return QDF_STATUS_E_INVAL; 6307 } 6308 6309 psoc_reg->ignore_fw_reg_offload_ind = true; 6310 return QDF_STATUS_SUCCESS; 6311 } 6312 6313 bool reg_get_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc) 6314 { 6315 struct wlan_regulatory_psoc_priv_obj *psoc_reg; 6316 6317 psoc_reg = reg_get_psoc_obj(psoc); 6318 if (!IS_VALID_PSOC_REG_OBJ(psoc_reg)) 6319 return false; 6320 6321 return psoc_reg->ignore_fw_reg_offload_ind; 6322 } 6323 6324 QDF_STATUS reg_set_6ghz_supported(struct wlan_objmgr_psoc *psoc, bool val) 6325 { 6326 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6327 6328 psoc_priv_obj = reg_get_psoc_obj(psoc); 6329 6330 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6331 reg_err("psoc reg component is NULL"); 6332 return QDF_STATUS_E_FAILURE; 6333 } 6334 6335 psoc_priv_obj->six_ghz_supported = val; 6336 6337 return QDF_STATUS_SUCCESS; 6338 } 6339 6340 QDF_STATUS 6341 reg_set_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc, bool val) 6342 { 6343 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6344 6345 psoc_priv_obj = reg_get_psoc_obj(psoc); 6346 6347 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6348 reg_err("psoc reg component is NULL"); 6349 return QDF_STATUS_E_FAILURE; 6350 } 6351 6352 psoc_priv_obj->five_dot_nine_ghz_supported = val; 6353 6354 return QDF_STATUS_SUCCESS; 6355 } 6356 6357 #ifdef CONFIG_REG_CLIENT 6358 bool reg_is_6ghz_supported(struct wlan_objmgr_psoc *psoc) 6359 { 6360 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6361 6362 psoc_priv_obj = reg_get_psoc_obj(psoc); 6363 6364 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6365 reg_err("psoc reg component is NULL"); 6366 return false; 6367 } 6368 6369 return psoc_priv_obj->six_ghz_supported; 6370 } 6371 #endif 6372 6373 bool reg_is_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc) 6374 { 6375 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6376 6377 psoc_priv_obj = reg_get_psoc_obj(psoc); 6378 6379 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6380 reg_err("psoc reg component is NULL"); 6381 return false; 6382 } 6383 6384 return psoc_priv_obj->five_dot_nine_ghz_supported; 6385 } 6386 6387 bool reg_is_fcc_regdmn(struct wlan_objmgr_pdev *pdev) 6388 { 6389 struct cur_regdmn_info cur_reg_dmn; 6390 QDF_STATUS status; 6391 6392 status = reg_get_curr_regdomain(pdev, &cur_reg_dmn); 6393 if (status != QDF_STATUS_SUCCESS) { 6394 reg_err_rl("Failed to get reg domain"); 6395 return false; 6396 } 6397 6398 return reg_fcc_regdmn(cur_reg_dmn.dmn_id_5g); 6399 } 6400 6401 bool reg_is_5dot9_ghz_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 6402 { 6403 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6404 6405 pdev_priv_obj = reg_get_pdev_obj(pdev); 6406 6407 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6408 reg_err("reg pdev priv obj is NULL"); 6409 return false; 6410 } 6411 6412 return (freq >= channel_map_us[MIN_5DOT9_CHANNEL].center_freq && 6413 freq <= channel_map_us[MAX_5DOT9_CHANNEL].center_freq); 6414 } 6415 6416 bool reg_is_5dot9_ghz_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev) 6417 { 6418 struct wlan_objmgr_psoc *psoc; 6419 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 6420 6421 if (!pdev) { 6422 reg_alert("pdev is NULL"); 6423 return true; 6424 } 6425 psoc = wlan_pdev_get_psoc(pdev); 6426 6427 psoc_priv_obj = reg_get_psoc_obj(psoc); 6428 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 6429 reg_alert("psoc reg component is NULL"); 6430 return true; 6431 } 6432 6433 return psoc_priv_obj->enable_5dot9_ghz_chan_in_master_mode; 6434 } 6435 6436 #ifdef DISABLE_UNII_SHARED_BANDS 6437 QDF_STATUS 6438 reg_get_unii_5g_bitmap(struct wlan_objmgr_pdev *pdev, uint8_t *bitmap) 6439 { 6440 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6441 6442 pdev_priv_obj = reg_get_pdev_obj(pdev); 6443 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6444 reg_err_rl("pdev reg component is NULL"); 6445 return QDF_STATUS_E_FAILURE; 6446 } 6447 *bitmap = pdev_priv_obj->unii_5g_bitmap; 6448 6449 return QDF_STATUS_SUCCESS; 6450 } 6451 #endif 6452 6453 #ifdef WLAN_FEATURE_11BE 6454 bool reg_is_phymode_unallowed(enum reg_phymode phy_in, uint32_t phymode_bitmap) 6455 { 6456 if (!phymode_bitmap) 6457 return false; 6458 6459 if (phy_in == REG_PHYMODE_11BE) 6460 return phymode_bitmap & REGULATORY_PHYMODE_NO11BE; 6461 else if (phy_in == REG_PHYMODE_11AX) 6462 return phymode_bitmap & REGULATORY_PHYMODE_NO11AX; 6463 else if (phy_in == REG_PHYMODE_11AC) 6464 return phymode_bitmap & REGULATORY_PHYMODE_NO11AC; 6465 else if (phy_in == REG_PHYMODE_11N) 6466 return phymode_bitmap & REGULATORY_CHAN_NO11N; 6467 else if (phy_in == REG_PHYMODE_11G) 6468 return phymode_bitmap & REGULATORY_PHYMODE_NO11G; 6469 else if (phy_in == REG_PHYMODE_11A) 6470 return phymode_bitmap & REGULATORY_PHYMODE_NO11A; 6471 else if (phy_in == REG_PHYMODE_11B) 6472 return phymode_bitmap & REGULATORY_PHYMODE_NO11B; 6473 else 6474 return true; 6475 } 6476 #else 6477 bool reg_is_phymode_unallowed(enum reg_phymode phy_in, uint32_t phymode_bitmap) 6478 { 6479 if (!phymode_bitmap) 6480 return false; 6481 6482 if (phy_in == REG_PHYMODE_11AX) 6483 return phymode_bitmap & REGULATORY_PHYMODE_NO11AX; 6484 else if (phy_in == REG_PHYMODE_11AC) 6485 return phymode_bitmap & REGULATORY_PHYMODE_NO11AC; 6486 else if (phy_in == REG_PHYMODE_11N) 6487 return phymode_bitmap & REGULATORY_CHAN_NO11N; 6488 else if (phy_in == REG_PHYMODE_11G) 6489 return phymode_bitmap & REGULATORY_PHYMODE_NO11G; 6490 else if (phy_in == REG_PHYMODE_11A) 6491 return phymode_bitmap & REGULATORY_PHYMODE_NO11A; 6492 else if (phy_in == REG_PHYMODE_11B) 6493 return phymode_bitmap & REGULATORY_PHYMODE_NO11B; 6494 else 6495 return true; 6496 } 6497 #endif 6498 6499 #ifdef CHECK_REG_PHYMODE 6500 enum reg_phymode reg_get_max_phymode(struct wlan_objmgr_pdev *pdev, 6501 enum reg_phymode phy_in, 6502 qdf_freq_t freq) 6503 { 6504 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6505 uint32_t phymode_bitmap; 6506 enum reg_phymode current_phymode = phy_in; 6507 6508 pdev_priv_obj = reg_get_pdev_obj(pdev); 6509 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6510 reg_err("pdev reg component is NULL"); 6511 return REG_PHYMODE_INVALID; 6512 } 6513 6514 phymode_bitmap = pdev_priv_obj->phybitmap; 6515 6516 while (1) { 6517 if (reg_is_phymode_unallowed(current_phymode, phymode_bitmap)) { 6518 if (current_phymode == REG_PHYMODE_11N) { 6519 if (REG_IS_24GHZ_CH_FREQ(freq)) 6520 current_phymode = REG_PHYMODE_11G; 6521 else 6522 current_phymode = REG_PHYMODE_11A; 6523 } else if (current_phymode == REG_PHYMODE_11A || 6524 current_phymode == REG_PHYMODE_11B) { 6525 reg_err("Couldn't find a suitable phymode"); 6526 return REG_PHYMODE_INVALID; 6527 } else if (current_phymode > REG_PHYMODE_MAX) { 6528 reg_err("Unknown phymode"); 6529 return REG_PHYMODE_INVALID; 6530 } else { 6531 current_phymode--; 6532 } 6533 } else { 6534 return current_phymode; 6535 } 6536 } 6537 } 6538 #endif /* CHECK_REG_PHYMODE */ 6539 6540 #ifdef CONFIG_REG_CLIENT 6541 enum band_info reg_band_bitmap_to_band_info(uint32_t band_bitmap) 6542 { 6543 if ((band_bitmap & BIT(REG_BAND_2G)) && 6544 (band_bitmap & BIT(REG_BAND_5G)) && 6545 (band_bitmap & BIT(REG_BAND_6G))) 6546 return BAND_ALL; 6547 else if ((band_bitmap & BIT(REG_BAND_5G)) && 6548 (band_bitmap & BIT(REG_BAND_6G))) 6549 return BAND_5G; 6550 else if ((band_bitmap & BIT(REG_BAND_2G)) && 6551 (band_bitmap & BIT(REG_BAND_6G))) 6552 return BAND_2G; 6553 else if ((band_bitmap & BIT(REG_BAND_2G)) && 6554 (band_bitmap & BIT(REG_BAND_5G))) 6555 return BAND_ALL; 6556 else if (band_bitmap & BIT(REG_BAND_2G)) 6557 return BAND_2G; 6558 else if (band_bitmap & BIT(REG_BAND_5G)) 6559 return BAND_5G; 6560 else if (band_bitmap & BIT(REG_BAND_6G)) 6561 return BAND_2G; 6562 else 6563 return BAND_UNKNOWN; 6564 } 6565 #endif 6566 6567 #if defined(CONFIG_BAND_6GHZ) 6568 QDF_STATUS 6569 reg_set_cur_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev, 6570 enum reg_6g_ap_type reg_cur_6g_ap_pwr_type) 6571 { 6572 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6573 6574 pdev_priv_obj = reg_get_pdev_obj(pdev); 6575 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6576 reg_err("pdev reg component is NULL"); 6577 return QDF_STATUS_E_FAILURE; 6578 } 6579 6580 if (reg_cur_6g_ap_pwr_type > REG_MAX_SUPP_AP_TYPE) { 6581 reg_err("Unsupported 6G AP power type"); 6582 return QDF_STATUS_E_FAILURE; 6583 } 6584 /* should we validate the input reg_cur_6g_ap_type? */ 6585 pdev_priv_obj->reg_cur_6g_ap_pwr_type = reg_cur_6g_ap_pwr_type; 6586 return QDF_STATUS_SUCCESS; 6587 } 6588 6589 QDF_STATUS 6590 reg_get_cur_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev, 6591 enum reg_6g_ap_type *reg_cur_6g_ap_pwr_type) 6592 { 6593 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 6594 6595 pdev_priv_obj = reg_get_pdev_obj(pdev); 6596 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 6597 reg_err("pdev reg component is NULL"); 6598 return QDF_STATUS_E_FAILURE; 6599 } 6600 6601 if (pdev_priv_obj->reg_cur_6g_ap_pwr_type >= REG_CURRENT_MAX_AP_TYPE) 6602 return QDF_STATUS_E_FAILURE; 6603 6604 *reg_cur_6g_ap_pwr_type = pdev_priv_obj->reg_cur_6g_ap_pwr_type; 6605 6606 return QDF_STATUS_SUCCESS; 6607 } 6608 6609 /** 6610 * get_reg_rules_for_pdev() - Get the pointer to the reg rules for the pdev 6611 * @pdev: Pointer to pdev 6612 * 6613 * Return: Pointer to Standard Power regulatory rules 6614 */ 6615 static struct reg_rule_info * 6616 reg_get_reg_rules_for_pdev(struct wlan_objmgr_pdev *pdev) 6617 { 6618 struct wlan_objmgr_psoc *psoc; 6619 struct wlan_regulatory_psoc_priv_obj *psoc_reg_priv; 6620 uint8_t phy_id; 6621 struct reg_rule_info *psoc_reg_rules; 6622 6623 psoc = wlan_pdev_get_psoc(pdev); 6624 psoc_reg_priv = reg_get_psoc_obj(psoc); 6625 6626 if (!psoc_reg_priv) { 6627 reg_debug("Regulatory psoc private object is NULL"); 6628 return NULL; 6629 } 6630 6631 phy_id = wlan_objmgr_pdev_get_pdev_id(pdev); 6632 psoc_reg_rules = &psoc_reg_priv->mas_chan_params[phy_id].reg_rules; 6633 6634 return psoc_reg_rules; 6635 } 6636 6637 /** 6638 * reg_get_num_rules_of_ap_pwr_type() - Get the number of reg rules present 6639 * for a given ap power type 6640 * @pdev: Pointer to pdev 6641 * @ap_pwr_type: AP power type 6642 * 6643 * Return: Return the number of reg rules for a given ap power type 6644 */ 6645 static uint8_t 6646 reg_get_num_rules_of_ap_pwr_type(struct wlan_objmgr_pdev *pdev, 6647 enum reg_6g_ap_type ap_pwr_type) 6648 { 6649 struct reg_rule_info *psoc_reg_rules = reg_get_reg_rules_for_pdev(pdev); 6650 6651 if (!psoc_reg_rules) { 6652 reg_debug("No psoc_reg_rules"); 6653 return 0; 6654 } 6655 6656 if (ap_pwr_type > REG_MAX_SUPP_AP_TYPE) { 6657 reg_err("Unsupported 6G AP power type"); 6658 return 0; 6659 } 6660 6661 return psoc_reg_rules->num_of_6g_ap_reg_rules[ap_pwr_type]; 6662 } 6663 6664 #ifdef CONFIG_AFC_SUPPORT 6665 /** 6666 * reg_is_empty_range() - If both left, right frquency edges in the input range 6667 * are zero then the range is empty, else not. 6668 * @in_range: Pointer to input range 6669 * 6670 * Return: True if the range is empty, else false 6671 */ 6672 static bool reg_is_empty_range(struct freq_range *in_range) 6673 { 6674 return !in_range->left && !in_range->right; 6675 } 6676 6677 struct freq_range 6678 reg_init_freq_range(qdf_freq_t left, qdf_freq_t right) 6679 { 6680 struct freq_range out_range; 6681 6682 out_range.left = left; 6683 out_range.right = right; 6684 6685 return out_range; 6686 } 6687 6688 /** 6689 * reg_assign_vars_with_range_vals() - Assign input variables with the values of 6690 * the range variable values 6691 * @in_range: Pointer to input range object 6692 * @left: Pointer to the first variable to get the value of left frequency edge 6693 * @right: Pointer to the second variable to get the value of right frequency 6694 * edge 6695 * 6696 * Return: void 6697 */ 6698 static void 6699 reg_assign_vars_with_range_vals(struct freq_range *in_range, 6700 qdf_freq_t *left, 6701 qdf_freq_t *right) 6702 { 6703 *left = in_range->left; 6704 *right = in_range->right; 6705 } 6706 6707 /** 6708 * reg_intersect_ranges() - Intersect two ranges and return the intesected range 6709 * @first: Pointer to first input range 6710 * @second: Pointer to second input range 6711 * 6712 * Return: Intersected output range 6713 */ 6714 static struct freq_range 6715 reg_intersect_ranges(struct freq_range *first_range, 6716 struct freq_range *second_range) 6717 { 6718 struct freq_range out_range; 6719 qdf_freq_t l_freq; 6720 qdf_freq_t r_freq; 6721 6722 /* validate if the ranges are proper */ 6723 6724 l_freq = QDF_MAX(first_range->left, second_range->left); 6725 r_freq = QDF_MIN(first_range->right, second_range->right); 6726 6727 if (l_freq > r_freq) { 6728 l_freq = 0; 6729 l_freq = 0; 6730 6731 reg_debug("Ranges do not overlap first= [%u, %u], second = [%u, %u]", 6732 first_range->left, 6733 first_range->right, 6734 second_range->left, 6735 second_range->right); 6736 } 6737 6738 out_range.left = l_freq; 6739 out_range.right = r_freq; 6740 6741 return out_range; 6742 } 6743 6744 /** 6745 * reg_act_sp_rule_cb - A function pointer type that calculate something 6746 * from the input frequency range 6747 * @rule_fr: Pointer to frequencey range 6748 * @arg: Pointer to generic argument (a.k.a. context) 6749 * 6750 * Return: Void 6751 */ 6752 typedef void (*reg_act_sp_rule_cb)(struct freq_range *rule_fr, 6753 void *arg); 6754 6755 /** 6756 * reg_iterate_sp_rules() - Iterate through the Standard Power reg rules, for 6757 * every reg rule call the call back function to take some action or calculate 6758 * something 6759 * @pdev: Pointer to pdev 6760 * @pdev_priv_obj: Pointer to pdev private object 6761 * @action_on_sp_rule: A function pointer to take some action or calculate 6762 * something for every sp rule 6763 * @arg: Pointer to opque object (argument/context) 6764 * 6765 * Return: Void 6766 */ 6767 static void reg_iterate_sp_rules(struct wlan_objmgr_pdev *pdev, 6768 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 6769 reg_act_sp_rule_cb sp_rule_action, 6770 void *arg) 6771 { 6772 struct cur_reg_rule *p_sp_reg_rule; 6773 struct reg_rule_info *psoc_reg_rules; 6774 uint8_t n_6g_sp_ap_reg_rules; 6775 qdf_freq_t low_5g; 6776 qdf_freq_t high_5g; 6777 uint8_t i; 6778 struct freq_range chip_range; 6779 6780 psoc_reg_rules = reg_get_reg_rules_for_pdev(pdev); 6781 6782 if (!psoc_reg_rules) { 6783 reg_debug("psoc reg rule pointer is NULL"); 6784 return; 6785 } 6786 6787 n_6g_sp_ap_reg_rules = psoc_reg_rules->num_of_6g_ap_reg_rules[REG_STANDARD_POWER_AP]; 6788 p_sp_reg_rule = psoc_reg_rules->reg_rules_6g_ap[REG_STANDARD_POWER_AP]; 6789 6790 low_5g = pdev_priv_obj->range_5g_low; 6791 high_5g = pdev_priv_obj->range_5g_high; 6792 6793 chip_range = reg_init_freq_range(low_5g, high_5g); 6794 6795 reg_debug("chip_range = [%u, %u]", low_5g, high_5g); 6796 reg_debug("Num_6g_rules = %u", n_6g_sp_ap_reg_rules); 6797 6798 for (i = 0; i < n_6g_sp_ap_reg_rules; i++) { 6799 struct freq_range sp_range; 6800 struct freq_range out_range; 6801 6802 sp_range = reg_init_freq_range(p_sp_reg_rule->start_freq, 6803 p_sp_reg_rule->end_freq); 6804 reg_debug("Rule:[%u, %u]", 6805 p_sp_reg_rule->start_freq, 6806 p_sp_reg_rule->end_freq); 6807 out_range = reg_intersect_ranges(&chip_range, &sp_range); 6808 6809 if (sp_rule_action) 6810 sp_rule_action(&out_range, arg); 6811 6812 p_sp_reg_rule++; 6813 } 6814 } 6815 6816 /** 6817 * reg_afc_incr_num_ranges() - Increment the number of frequency ranges 6818 * @p_range: Pointer to frequency range 6819 * @num_freq_ranges: Pointer to number of frequency ranges. This needs to be 6820 * (Actual type: uint8_t *num_freq_ranges) 6821 * incremented by the function 6822 * 6823 * Return: Void 6824 */ 6825 static void reg_afc_incr_num_ranges(struct freq_range *p_range, 6826 void *num_freq_ranges) 6827 { 6828 if (!reg_is_empty_range(p_range)) 6829 (*(uint8_t *)num_freq_ranges)++; 6830 } 6831 6832 /** 6833 * reg_get_num_sp_freq_ranges() - Find the number of reg rules from the Standard 6834 * power regulatory rules 6835 * @pdev: Pointer to pdev 6836 * 6837 * Return: number of frequency ranges 6838 */ 6839 static uint8_t reg_get_num_sp_freq_ranges(struct wlan_objmgr_pdev *pdev, 6840 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 6841 { 6842 uint8_t num_freq_ranges; 6843 6844 num_freq_ranges = 0; 6845 reg_iterate_sp_rules(pdev, 6846 pdev_priv_obj, 6847 reg_afc_incr_num_ranges, 6848 &num_freq_ranges); 6849 6850 reg_debug("Num_freq_ranges=%u", num_freq_ranges); 6851 return num_freq_ranges; 6852 } 6853 6854 /** 6855 * reg_afc_get_intersected_ranges() - Get the intersected range into range obj 6856 * @rule_fr: Pointer to the rule for frequency range 6857 * @arg: Pointer to opaque object (argument/context) 6858 * (Actual type: struct wlan_afc_freq_range_obj **p_range_obj) 6859 * incremented by the function 6860 * 6861 * Return: Void 6862 */ 6863 static void reg_afc_get_intersected_ranges(struct freq_range *rule_fr, 6864 void *arg) 6865 { 6866 struct wlan_afc_freq_range_obj *p_range; 6867 struct wlan_afc_freq_range_obj **pp_range; 6868 qdf_freq_t low, high; 6869 6870 pp_range = (struct wlan_afc_freq_range_obj **)arg; 6871 p_range = *pp_range; 6872 6873 if (!reg_is_empty_range(rule_fr)) { 6874 reg_assign_vars_with_range_vals(rule_fr, &low, &high); 6875 p_range->lowfreq = (uint16_t)low; 6876 p_range->highfreq = (uint16_t)high; 6877 reg_debug("Range = [%u, %u]", p_range->lowfreq, p_range->highfreq); 6878 (*pp_range)++; 6879 } 6880 } 6881 6882 /** 6883 * reg_cp_freq_ranges() - Copy frequency ranges from the Standard power 6884 * regulatory rules 6885 * @pdev: Pointer to pdev 6886 * @pdev_priv_obj: Pointer to pdev private object 6887 * @num_freq_ranges: Number of frequency ranges 6888 * @p_range_obj: Pointer to range object 6889 * 6890 * Return: void 6891 */ 6892 static void reg_cp_freq_ranges(struct wlan_objmgr_pdev *pdev, 6893 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 6894 uint8_t num_freq_ranges, 6895 struct wlan_afc_freq_range_obj *p_range_obj) 6896 { 6897 struct wlan_afc_freq_range_obj *p_range; 6898 6899 reg_debug("Num freq ranges = %u", num_freq_ranges); 6900 6901 p_range = p_range_obj; 6902 reg_iterate_sp_rules(pdev, 6903 pdev_priv_obj, 6904 reg_afc_get_intersected_ranges, 6905 &p_range); 6906 } 6907 6908 /** 6909 * reg_get_frange_list_len() - Calculate the length of the list of the 6910 * frequency ranges 6911 * @num_freq_ranges: Number of frequency ranges 6912 * 6913 * Return: Length of the frequency range list 6914 */ 6915 static uint16_t reg_get_frange_list_len(uint8_t num_freq_ranges) 6916 { 6917 uint16_t frange_lst_len; 6918 6919 if (!num_freq_ranges) 6920 reg_err("AFC:There is no freq ranges"); 6921 6922 frange_lst_len = 6923 sizeof(struct wlan_afc_frange_list) + 6924 sizeof(struct wlan_afc_freq_range_obj) * num_freq_ranges; 6925 6926 return frange_lst_len; 6927 } 6928 6929 /** 6930 * reg_get_opclasses_array_len() - Calculate the length of the array of 6931 * opclasses objects 6932 * @num_opclasses: The number of opclasses 6933 * @chansize_lst: The array of sizes of channel lists 6934 * 6935 * Return: Length of the array of opclass object 6936 */ 6937 static uint16_t reg_get_opclasses_array_len(struct wlan_objmgr_pdev *pdev, 6938 uint8_t num_opclasses, 6939 uint8_t *chansize_lst) 6940 { 6941 uint16_t opclasses_arr_len = 0; 6942 uint16_t i; 6943 6944 for (i = 0; i < num_opclasses; i++) { 6945 opclasses_arr_len += 6946 sizeof(struct wlan_afc_opclass_obj) + 6947 sizeof(uint8_t) * chansize_lst[i]; 6948 } 6949 6950 return opclasses_arr_len; 6951 } 6952 6953 /** 6954 * reg_get_afc_req_length() - Calculate the length of the AFC partial request 6955 * @num_opclasses: The number of opclasses 6956 * @num_freq_ranges: The number of frequency ranges 6957 * @chansize_lst: The array of sizes of channel lists 6958 * 6959 * Return: Length of the partial AFC request 6960 */ 6961 static uint16_t reg_get_afc_req_length(struct wlan_objmgr_pdev *pdev, 6962 uint8_t num_opclasses, 6963 uint8_t num_freq_ranges, 6964 uint8_t *chansize_lst) 6965 { 6966 uint16_t afc_req_len; 6967 uint16_t frange_lst_len; 6968 uint16_t fixed_param_len; 6969 uint16_t num_opclasses_len; 6970 uint16_t opclasses_arr_len; 6971 uint16_t afc_location_len; 6972 6973 fixed_param_len = sizeof(struct wlan_afc_host_req_fixed_params); 6974 frange_lst_len = reg_get_frange_list_len(num_freq_ranges); 6975 num_opclasses_len = sizeof(struct wlan_afc_num_opclasses); 6976 opclasses_arr_len = reg_get_opclasses_array_len(pdev, 6977 num_opclasses, 6978 chansize_lst); 6979 afc_location_len = sizeof(struct wlan_afc_location); 6980 6981 afc_req_len = 6982 fixed_param_len + 6983 frange_lst_len + 6984 num_opclasses_len + 6985 opclasses_arr_len + 6986 afc_location_len; 6987 6988 return afc_req_len; 6989 } 6990 6991 /** 6992 * reg_fill_afc_fixed_params() - Fill the AFC fixed params 6993 * @p_fixed_params: Pointer to afc fixed params object 6994 * @afc_req_len: Length of the partial AFC request 6995 * 6996 * Return: Void 6997 */ 6998 static inline void 6999 reg_fill_afc_fixed_params(struct wlan_afc_host_req_fixed_params *p_fixed_params, 7000 uint16_t afc_req_len) 7001 { 7002 p_fixed_params->req_length = afc_req_len; 7003 p_fixed_params->req_id = DEFAULT_REQ_ID; 7004 p_fixed_params->min_des_power = DEFAULT_MIN_POWER; 7005 } 7006 7007 /** 7008 * reg_fill_afc_freq_ranges() - Fill the AFC fixed params 7009 * @pdev: Pointer to pdev 7010 * @pdev_priv_obj: Pointer to pdev private object 7011 * @p_frange_lst: Pointer to frequency range list 7012 * @num_freq_ranges: Number of frequency ranges 7013 * 7014 * Return: Void 7015 */ 7016 static inline void 7017 reg_fill_afc_freq_ranges(struct wlan_objmgr_pdev *pdev, 7018 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 7019 struct wlan_afc_frange_list *p_frange_lst, 7020 uint8_t num_freq_ranges) 7021 { 7022 struct wlan_afc_freq_range_obj *p_range_obj; 7023 7024 p_frange_lst->num_ranges = num_freq_ranges; 7025 7026 p_range_obj = &p_frange_lst->range_objs[0]; 7027 7028 reg_cp_freq_ranges(pdev, pdev_priv_obj, num_freq_ranges, p_range_obj); 7029 } 7030 7031 /** 7032 * reg_fill_afc_opclass_obj() - Fill the opclass object and return pointer to 7033 * next AFC opclass object 7034 * @p_obj_opclass_obj: Pointer to opclass object 7035 * @opclass: Operating class 7036 * @num_chans: Number of channels in the opclass 7037 * @p_chan_lst: Pointer to channel list 7038 * 7039 * Return: Pointer to the next AFC opclass object 7040 */ 7041 static struct wlan_afc_opclass_obj * 7042 reg_fill_afc_opclass_obj(struct wlan_afc_opclass_obj *p_obj_opclass_obj, 7043 uint8_t opclass, 7044 uint8_t num_chans, 7045 uint8_t *p_chan_lst) 7046 { 7047 uint16_t len_obj; 7048 uint8_t *out_p; 7049 uint8_t *src, *dst; 7050 uint8_t copy_len; 7051 7052 p_obj_opclass_obj->opclass_num_cfis = num_chans; 7053 p_obj_opclass_obj->opclass = opclass; 7054 src = p_chan_lst; 7055 dst = p_obj_opclass_obj->cfis; 7056 copy_len = num_chans * sizeof(uint8_t); 7057 7058 qdf_mem_copy(dst, src, copy_len); 7059 7060 len_obj = sizeof(struct wlan_afc_opclass_obj) + copy_len; 7061 out_p = (uint8_t *)p_obj_opclass_obj + len_obj; 7062 7063 return (struct wlan_afc_opclass_obj *)out_p; 7064 } 7065 7066 /** 7067 * reg_fill_afc_opclasses_arr() - Fill the array of opclass objects 7068 * @num_opclasses: The number of opclasses 7069 * @opclass_lst: The array of Operating classes 7070 * @chansize_lst: The array of sizes of channel lists 7071 * @channel_lists: The array of channel lists 7072 * @p_opclass_obj_arr: Pointer to the first opclass object 7073 * 7074 * Return: Pointer to the end of last opclass object 7075 */ 7076 static inline struct wlan_afc_opclass_obj * 7077 reg_fill_afc_opclasses_arr(struct wlan_objmgr_pdev *pdev, 7078 uint8_t num_opclasses, 7079 uint8_t *opclass_lst, 7080 uint8_t *chansize_lst, 7081 uint8_t *channel_lists[], 7082 struct wlan_afc_opclass_obj *p_opclass_obj_arr) 7083 { 7084 uint16_t i; 7085 struct wlan_afc_opclass_obj *p_opclass_obj; 7086 7087 p_opclass_obj = p_opclass_obj_arr; 7088 7089 for (i = 0; i < num_opclasses; i++) { 7090 p_opclass_obj = reg_fill_afc_opclass_obj(p_opclass_obj, 7091 opclass_lst[i], 7092 chansize_lst[i], 7093 channel_lists[i]); 7094 } 7095 return p_opclass_obj; 7096 } 7097 7098 /** 7099 * reg_next_opcls_ptr() - Get the pointer to the next opclass object 7100 * @p_cur_opcls_obj: Pointer to the current operating class object 7101 * @num_cfis: number of center frequencey indices 7102 * 7103 * Return: Pointer to next opclss object 7104 */ 7105 static struct wlan_afc_opclass_obj * 7106 reg_next_opcls_ptr(struct wlan_afc_opclass_obj *p_cur_opcls_obj, 7107 uint8_t num_cfis) 7108 { 7109 uint8_t cur_obj_sz; 7110 uint8_t fixed_opcls_sz; 7111 struct wlan_afc_opclass_obj *p_next_opcls_obj; 7112 uint8_t *p_tmp_next; 7113 7114 fixed_opcls_sz = sizeof(struct wlan_afc_opclass_obj); 7115 cur_obj_sz = fixed_opcls_sz + num_cfis * sizeof(uint8_t); 7116 p_tmp_next = (uint8_t *)p_cur_opcls_obj + cur_obj_sz; 7117 p_next_opcls_obj = (struct wlan_afc_opclass_obj *)p_tmp_next; 7118 7119 return p_next_opcls_obj; 7120 } 7121 7122 void reg_print_partial_afc_req_info(struct wlan_objmgr_pdev *pdev, 7123 struct wlan_afc_host_partial_request *afc_req) 7124 { 7125 struct wlan_afc_host_req_fixed_params *p_fixed_params; 7126 struct wlan_afc_frange_list *p_frange_lst; 7127 struct wlan_afc_num_opclasses *p_num_opclasses; 7128 uint8_t i; 7129 uint8_t j; 7130 uint16_t frange_lst_len; 7131 uint8_t num_opclasses; 7132 struct wlan_afc_opclass_obj *p_obj_opclass_arr; 7133 struct wlan_afc_opclass_obj *p_opclass_obj; 7134 uint8_t num_freq_ranges; 7135 uint8_t *p_temp; 7136 struct wlan_afc_location *p_afc_location; 7137 uint8_t *deployment_type_str; 7138 7139 p_fixed_params = &afc_req->fixed_params; 7140 reg_debug("req_length=%hu", p_fixed_params->req_length); 7141 reg_debug("req_id=%llu", p_fixed_params->req_id); 7142 reg_debug("min_des_power=%hd", p_fixed_params->min_des_power); 7143 7144 p_temp = (uint8_t *)p_fixed_params; 7145 p_temp += sizeof(*p_fixed_params); 7146 p_frange_lst = (struct wlan_afc_frange_list *)p_temp; 7147 reg_debug("num_ranges=%hhu", p_frange_lst->num_ranges); 7148 for (i = 0; i < p_frange_lst->num_ranges; i++) { 7149 struct wlan_afc_freq_range_obj *p_range_obj; 7150 7151 p_range_obj = &p_frange_lst->range_objs[i]; 7152 reg_debug("lowfreq=%hu", p_range_obj->lowfreq); 7153 reg_debug("highfreq=%hu", p_range_obj->highfreq); 7154 } 7155 7156 num_freq_ranges = p_frange_lst->num_ranges; 7157 frange_lst_len = reg_get_frange_list_len(num_freq_ranges); 7158 p_temp += frange_lst_len; 7159 p_num_opclasses = (struct wlan_afc_num_opclasses *)p_temp; 7160 num_opclasses = p_num_opclasses->num_opclasses; 7161 reg_debug("num_opclasses=%hhu", num_opclasses); 7162 7163 p_temp += sizeof(*p_num_opclasses); 7164 p_obj_opclass_arr = (struct wlan_afc_opclass_obj *)p_temp; 7165 p_opclass_obj = p_obj_opclass_arr; 7166 for (i = 0; i < num_opclasses; i++) { 7167 uint8_t opclass = p_opclass_obj->opclass; 7168 uint8_t num_cfis = p_opclass_obj->opclass_num_cfis; 7169 uint8_t *cfis = p_opclass_obj->cfis; 7170 7171 reg_debug("opclass[%hhu]=%hhu", i, opclass); 7172 reg_debug("num_cfis[%hhu]=%hhu", i, num_cfis); 7173 reg_debug("["); 7174 for (j = 0; j < num_cfis; j++) 7175 reg_debug("%hhu,", cfis[j]); 7176 reg_debug("]"); 7177 7178 p_opclass_obj = reg_next_opcls_ptr(p_opclass_obj, num_cfis); 7179 } 7180 7181 p_afc_location = (struct wlan_afc_location *)p_opclass_obj; 7182 switch (p_afc_location->deployment_type) { 7183 case AFC_DEPLOYMENT_INDOOR: 7184 deployment_type_str = "Indoor"; 7185 break; 7186 case AFC_DEPLOYMENT_OUTDOOR: 7187 deployment_type_str = "Outdoor"; 7188 break; 7189 default: 7190 deployment_type_str = "Unknown"; 7191 } 7192 reg_debug("AFC location=%s", deployment_type_str); 7193 } 7194 7195 /** 7196 * reg_get_frange_filled_buf() - Allocate and fill the frange buffer and return 7197 * the buffer. Also return the number of frequence ranges 7198 * @pdev: Pointer to pdev 7199 * @pdev_priv_obj: Pointer to pdev private object 7200 * @num_freq_ranges: Pointer to number of frequency ranges (output param) 7201 * 7202 * Return: Pointer to the frange buffer 7203 */ 7204 static struct wlan_afc_frange_list * 7205 reg_get_frange_filled_buf(struct wlan_objmgr_pdev *pdev, 7206 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 7207 uint8_t *num_freq_ranges) 7208 { 7209 uint16_t frange_lst_len; 7210 struct wlan_afc_frange_list *p_frange_lst_local; 7211 7212 *num_freq_ranges = reg_get_num_sp_freq_ranges(pdev, pdev_priv_obj); 7213 frange_lst_len = reg_get_frange_list_len(*num_freq_ranges); 7214 7215 p_frange_lst_local = qdf_mem_malloc(frange_lst_len); 7216 if (!p_frange_lst_local) 7217 return NULL; 7218 7219 reg_fill_afc_freq_ranges(pdev, 7220 pdev_priv_obj, 7221 p_frange_lst_local, 7222 *num_freq_ranges); 7223 return p_frange_lst_local; 7224 } 7225 7226 QDF_STATUS 7227 reg_get_partial_afc_req_info(struct wlan_objmgr_pdev *pdev, 7228 struct wlan_afc_host_partial_request **afc_req) 7229 { 7230 /* allocate the memory for the partial request */ 7231 struct wlan_afc_host_partial_request *temp_afc_req; 7232 struct wlan_afc_host_req_fixed_params *p_fixed_params; 7233 struct wlan_afc_frange_list *p_frange_lst_local; 7234 struct wlan_afc_frange_list *p_frange_lst_afc; 7235 struct wlan_afc_num_opclasses *p_num_opclasses; 7236 uint16_t afc_req_len; 7237 uint16_t frange_lst_len; 7238 uint8_t num_freq_ranges; 7239 uint8_t num_opclasses; 7240 struct wlan_afc_opclass_obj *p_obj_opclass_arr; 7241 struct wlan_afc_location *p_afc_location; 7242 7243 uint8_t *opclass_lst; 7244 uint8_t *chansize_lst; 7245 uint8_t **channel_lists; 7246 QDF_STATUS status; 7247 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7248 7249 if (!afc_req) { 7250 reg_err("afc_req is NULL"); 7251 status = QDF_STATUS_E_INVAL; 7252 return status; 7253 } 7254 7255 temp_afc_req = NULL; 7256 pdev_priv_obj = reg_get_pdev_obj(pdev); 7257 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7258 reg_err("pdev reg component is NULL"); 7259 status = QDF_STATUS_E_INVAL; 7260 goto handle_invalid_priv_object; 7261 } 7262 7263 p_frange_lst_local = reg_get_frange_filled_buf(pdev, 7264 pdev_priv_obj, 7265 &num_freq_ranges); 7266 if (!p_frange_lst_local) { 7267 reg_err("Frange lst not allocated"); 7268 status = QDF_STATUS_E_NOMEM; 7269 goto handle_invalid_priv_object; 7270 } 7271 7272 status = reg_dmn_get_6g_opclasses_and_channels(pdev, 7273 p_frange_lst_local, 7274 &num_opclasses, 7275 &opclass_lst, 7276 &chansize_lst, 7277 &channel_lists); 7278 if (status != QDF_STATUS_SUCCESS) { 7279 reg_err("Opclasses and chans not allocated"); 7280 status = QDF_STATUS_E_NOMEM; 7281 goto free_frange_lst_local; 7282 } 7283 7284 afc_req_len = reg_get_afc_req_length(pdev, 7285 num_opclasses, 7286 num_freq_ranges, 7287 chansize_lst); 7288 7289 temp_afc_req = qdf_mem_malloc(afc_req_len); 7290 if (!temp_afc_req) { 7291 reg_err("AFC request not allocated"); 7292 status = QDF_STATUS_E_NOMEM; 7293 goto free_opcls_chan_mem; 7294 } 7295 7296 p_fixed_params = &temp_afc_req->fixed_params; 7297 reg_fill_afc_fixed_params(p_fixed_params, afc_req_len); 7298 7299 /* frange list is already filled just copy it */ 7300 frange_lst_len = reg_get_frange_list_len(num_freq_ranges); 7301 p_frange_lst_afc = (struct wlan_afc_frange_list *)&p_fixed_params[1]; 7302 qdf_mem_copy(p_frange_lst_afc, p_frange_lst_local, frange_lst_len); 7303 7304 p_num_opclasses = (struct wlan_afc_num_opclasses *) 7305 ((char *)(p_frange_lst_afc) + frange_lst_len); 7306 p_num_opclasses->num_opclasses = num_opclasses; 7307 7308 p_obj_opclass_arr = (struct wlan_afc_opclass_obj *)&p_num_opclasses[1]; 7309 p_obj_opclass_arr = reg_fill_afc_opclasses_arr(pdev, 7310 num_opclasses, 7311 opclass_lst, 7312 chansize_lst, 7313 channel_lists, 7314 p_obj_opclass_arr); 7315 7316 p_afc_location = (struct wlan_afc_location *)p_obj_opclass_arr; 7317 p_afc_location->deployment_type = 7318 pdev_priv_obj->reg_afc_dev_deployment_type; 7319 p_afc_location->afc_elem_type = AFC_OBJ_LOCATION; 7320 p_afc_location->afc_elem_len = 7321 sizeof(*p_afc_location) - 7322 sizeof(p_afc_location->afc_elem_type) - 7323 sizeof(p_afc_location->afc_elem_len); 7324 free_opcls_chan_mem: 7325 reg_dmn_free_6g_opclasses_and_channels(pdev, 7326 num_opclasses, 7327 opclass_lst, 7328 chansize_lst, 7329 channel_lists); 7330 7331 free_frange_lst_local: 7332 qdf_mem_free(p_frange_lst_local); 7333 7334 handle_invalid_priv_object: 7335 *afc_req = temp_afc_req; 7336 7337 return status; 7338 } 7339 7340 void reg_dmn_set_afc_req_id(struct wlan_afc_host_partial_request *afc_req, 7341 uint64_t req_id) 7342 { 7343 struct wlan_afc_host_req_fixed_params *p_fixed_params; 7344 7345 p_fixed_params = &afc_req->fixed_params; 7346 p_fixed_params->req_id = req_id; 7347 } 7348 7349 /** 7350 * reg_send_afc_partial_request() - Send AFC partial request to registered 7351 * recipient 7352 * @pdev: Pointer to pdev 7353 * @afc_req: Pointer to afc partial request 7354 * 7355 * Return: void 7356 */ 7357 static 7358 void reg_send_afc_partial_request(struct wlan_objmgr_pdev *pdev, 7359 struct wlan_afc_host_partial_request *afc_req) 7360 { 7361 afc_req_rx_evt_handler cbf; 7362 void *arg; 7363 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7364 7365 pdev_priv_obj = reg_get_pdev_obj(pdev); 7366 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7367 reg_err("pdev reg component is NULL"); 7368 return; 7369 } 7370 7371 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7372 cbf = pdev_priv_obj->afc_cb_obj.func; 7373 if (cbf) { 7374 arg = pdev_priv_obj->afc_cb_obj.arg; 7375 cbf(pdev, afc_req, arg); 7376 } 7377 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7378 } 7379 7380 QDF_STATUS reg_afc_start(struct wlan_objmgr_pdev *pdev, uint64_t req_id) 7381 { 7382 struct wlan_afc_host_partial_request *afc_req; 7383 QDF_STATUS status; 7384 7385 status = reg_get_partial_afc_req_info(pdev, &afc_req); 7386 if (status != QDF_STATUS_SUCCESS) { 7387 reg_err("Creating AFC Request failed"); 7388 return QDF_STATUS_E_FAILURE; 7389 } 7390 7391 QDF_TRACE(QDF_MODULE_ID_AFC, QDF_TRACE_LEVEL_DEBUG, 7392 "Processing AFC Start/Renew Expiry event"); 7393 7394 reg_dmn_set_afc_req_id(afc_req, req_id); 7395 7396 reg_print_partial_afc_req_info(pdev, afc_req); 7397 7398 reg_send_afc_partial_request(pdev, afc_req); 7399 7400 qdf_mem_free(afc_req); 7401 7402 return QDF_STATUS_SUCCESS; 7403 } 7404 7405 QDF_STATUS reg_send_afc_power_event(struct wlan_objmgr_pdev *pdev, 7406 struct reg_fw_afc_power_event *power_info) 7407 { 7408 afc_power_tx_evt_handler cbf; 7409 void *arg; 7410 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7411 7412 pdev_priv_obj = reg_get_pdev_obj(pdev); 7413 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7414 reg_err("pdev reg component is NULL"); 7415 return QDF_STATUS_E_FAILURE; 7416 } 7417 7418 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7419 cbf = pdev_priv_obj->afc_pow_evt_cb_obj.func; 7420 if (cbf) { 7421 arg = pdev_priv_obj->afc_pow_evt_cb_obj.arg; 7422 cbf(pdev, power_info, arg); 7423 } 7424 7425 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7426 7427 return QDF_STATUS_SUCCESS; 7428 } 7429 7430 QDF_STATUS reg_register_afc_req_rx_callback(struct wlan_objmgr_pdev *pdev, 7431 afc_req_rx_evt_handler cbf, 7432 void *arg) 7433 { 7434 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7435 7436 pdev_priv_obj = reg_get_pdev_obj(pdev); 7437 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7438 reg_err("pdev reg component is NULL"); 7439 return QDF_STATUS_E_FAILURE; 7440 } 7441 7442 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7443 pdev_priv_obj->afc_cb_obj.func = cbf; 7444 pdev_priv_obj->afc_cb_obj.arg = arg; 7445 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7446 reg_debug("afc_event_cb: 0x%pK, arg: 0x%pK", cbf, arg); 7447 7448 return QDF_STATUS_SUCCESS; 7449 } 7450 7451 QDF_STATUS reg_unregister_afc_req_rx_callback(struct wlan_objmgr_pdev *pdev, 7452 afc_req_rx_evt_handler cbf) 7453 { 7454 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7455 7456 pdev_priv_obj = reg_get_pdev_obj(pdev); 7457 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7458 reg_err("pdev reg component is NULL"); 7459 return QDF_STATUS_E_FAILURE; 7460 } 7461 7462 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7463 if (pdev_priv_obj->afc_cb_obj.func == cbf) { 7464 pdev_priv_obj->afc_cb_obj.func = NULL; 7465 pdev_priv_obj->afc_cb_obj.arg = NULL; 7466 } else { 7467 reg_err("cb function=0x%pK not found", cbf); 7468 } 7469 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7470 7471 return QDF_STATUS_SUCCESS; 7472 } 7473 7474 QDF_STATUS 7475 reg_register_afc_power_event_callback(struct wlan_objmgr_pdev *pdev, 7476 afc_power_tx_evt_handler cbf, 7477 void *arg) 7478 { 7479 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7480 7481 pdev_priv_obj = reg_get_pdev_obj(pdev); 7482 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7483 reg_err("pdev reg component is NULL"); 7484 return QDF_STATUS_E_FAILURE; 7485 } 7486 7487 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7488 pdev_priv_obj->afc_pow_evt_cb_obj.func = cbf; 7489 pdev_priv_obj->afc_pow_evt_cb_obj.arg = arg; 7490 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7491 reg_debug("afc_power_event_cb: 0x%pK, arg: 0x%pK", cbf, arg); 7492 7493 return QDF_STATUS_SUCCESS; 7494 } 7495 7496 QDF_STATUS 7497 reg_unregister_afc_power_event_callback(struct wlan_objmgr_pdev *pdev, 7498 afc_power_tx_evt_handler cbf) 7499 { 7500 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7501 7502 pdev_priv_obj = reg_get_pdev_obj(pdev); 7503 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7504 reg_err("pdev reg component is NULL"); 7505 return QDF_STATUS_E_FAILURE; 7506 } 7507 7508 qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock); 7509 if (pdev_priv_obj->afc_pow_evt_cb_obj.func == cbf) { 7510 pdev_priv_obj->afc_pow_evt_cb_obj.func = NULL; 7511 pdev_priv_obj->afc_pow_evt_cb_obj.arg = NULL; 7512 } else { 7513 reg_err("cb function=0x%pK not found", cbf); 7514 } 7515 qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock); 7516 7517 return QDF_STATUS_SUCCESS; 7518 } 7519 7520 QDF_STATUS 7521 reg_get_afc_dev_deploy_type(struct wlan_objmgr_pdev *pdev, 7522 enum reg_afc_dev_deploy_type *reg_afc_dev_type) 7523 { 7524 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7525 7526 pdev_priv_obj = reg_get_pdev_obj(pdev); 7527 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7528 reg_err("pdev reg component is NULL"); 7529 return QDF_STATUS_E_FAILURE; 7530 } 7531 7532 *reg_afc_dev_type = pdev_priv_obj->reg_afc_dev_deployment_type; 7533 7534 return QDF_STATUS_SUCCESS; 7535 } 7536 7537 bool 7538 reg_is_sta_connect_allowed(struct wlan_objmgr_pdev *pdev, 7539 enum reg_6g_ap_type root_ap_pwr_mode) 7540 { 7541 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7542 7543 pdev_priv_obj = reg_get_pdev_obj(pdev); 7544 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7545 reg_err("pdev reg component is NULL"); 7546 return false; 7547 } 7548 7549 if (reg_get_num_rules_of_ap_pwr_type(pdev, REG_STANDARD_POWER_AP) && 7550 (pdev_priv_obj->reg_afc_dev_deployment_type == AFC_DEPLOYMENT_OUTDOOR)) { 7551 if (root_ap_pwr_mode == REG_STANDARD_POWER_AP) 7552 return true; 7553 else 7554 return false; 7555 } 7556 7557 return true; 7558 } 7559 7560 QDF_STATUS reg_set_afc_soc_dev_type(struct wlan_objmgr_psoc *psoc, 7561 enum reg_afc_dev_deploy_type 7562 reg_afc_dev_type) 7563 { 7564 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7565 7566 psoc_priv_obj = reg_get_psoc_obj(psoc); 7567 7568 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 7569 reg_err("psoc reg component is NULL"); 7570 return QDF_STATUS_E_FAILURE; 7571 } 7572 7573 psoc_priv_obj->reg_afc_dev_type = reg_afc_dev_type; 7574 7575 return QDF_STATUS_SUCCESS; 7576 } 7577 7578 QDF_STATUS 7579 reg_get_afc_soc_dev_type(struct wlan_objmgr_psoc *psoc, 7580 enum reg_afc_dev_deploy_type *reg_afc_dev_type) 7581 { 7582 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7583 7584 psoc_priv_obj = reg_get_psoc_obj(psoc); 7585 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 7586 reg_err("psoc reg component is NULL"); 7587 return QDF_STATUS_E_FAILURE; 7588 } 7589 7590 *reg_afc_dev_type = psoc_priv_obj->reg_afc_dev_type; 7591 7592 return QDF_STATUS_SUCCESS; 7593 } 7594 #endif /* CONFIG_AFC_SUPPORT */ 7595 7596 QDF_STATUS 7597 reg_get_cur_6g_client_type(struct wlan_objmgr_pdev *pdev, 7598 enum reg_6g_client_type 7599 *reg_cur_6g_client_mobility_type) 7600 { 7601 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7602 7603 pdev_priv_obj = reg_get_pdev_obj(pdev); 7604 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7605 reg_err("pdev reg component is NULL"); 7606 return QDF_STATUS_E_FAILURE; 7607 } 7608 7609 if (pdev_priv_obj->reg_cur_6g_client_mobility_type >= 7610 REG_MAX_CLIENT_TYPE) 7611 return QDF_STATUS_E_FAILURE; 7612 7613 *reg_cur_6g_client_mobility_type = 7614 pdev_priv_obj->reg_cur_6g_client_mobility_type; 7615 7616 return QDF_STATUS_SUCCESS; 7617 } 7618 7619 QDF_STATUS reg_get_rnr_tpe_usable(struct wlan_objmgr_pdev *pdev, 7620 bool *reg_rnr_tpe_usable) 7621 { 7622 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7623 7624 pdev_priv_obj = reg_get_pdev_obj(pdev); 7625 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7626 reg_err("pdev reg component is NULL"); 7627 return QDF_STATUS_E_FAILURE; 7628 } 7629 *reg_rnr_tpe_usable = pdev_priv_obj->reg_rnr_tpe_usable; 7630 return QDF_STATUS_SUCCESS; 7631 } 7632 7633 QDF_STATUS reg_get_unspecified_ap_usable(struct wlan_objmgr_pdev *pdev, 7634 bool *reg_unspecified_ap_usable) 7635 { 7636 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7637 7638 pdev_priv_obj = reg_get_pdev_obj(pdev); 7639 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7640 reg_err("pdev reg component is NULL"); 7641 return QDF_STATUS_E_FAILURE; 7642 } 7643 *reg_unspecified_ap_usable = pdev_priv_obj->reg_unspecified_ap_usable; 7644 return QDF_STATUS_SUCCESS; 7645 } 7646 7647 QDF_STATUS 7648 reg_find_txpower_from_6g_list(qdf_freq_t freq, 7649 struct regulatory_channel *chan_list, 7650 uint16_t *txpower) 7651 { 7652 enum channel_enum chan_enum; 7653 7654 *txpower = 0; 7655 7656 for (chan_enum = 0; chan_enum < NUM_6GHZ_CHANNELS; chan_enum++) { 7657 if (chan_list[chan_enum].center_freq == freq) { 7658 *txpower = chan_list[chan_enum].tx_power; 7659 return QDF_STATUS_SUCCESS; 7660 } 7661 } 7662 7663 return QDF_STATUS_E_FAILURE; 7664 } 7665 7666 bool reg_is_6g_psd_power(struct wlan_objmgr_pdev *pdev) 7667 { 7668 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7669 struct regulatory_channel *cur_chan_list; 7670 enum channel_enum i; 7671 7672 if (!pdev) { 7673 reg_err("pdev is NULL"); 7674 return false; 7675 } 7676 7677 pdev_priv_obj = reg_get_pdev_obj(pdev); 7678 if (!pdev_priv_obj) { 7679 reg_err("pdev priv obj is NULL"); 7680 return false; 7681 } 7682 7683 cur_chan_list = pdev_priv_obj->cur_chan_list; 7684 7685 for (i = MIN_6GHZ_CHANNEL; i <= MAX_6GHZ_CHANNEL; i++) { 7686 if (!(cur_chan_list[i].chan_flags & REGULATORY_CHAN_DISABLED)) 7687 return cur_chan_list[i].psd_flag; 7688 } 7689 7690 return false; 7691 } 7692 7693 QDF_STATUS 7694 reg_get_6g_chan_psd_eirp_power(qdf_freq_t freq, 7695 struct regulatory_channel *mas_chan_list, 7696 uint16_t *eirp_psd_power) 7697 { 7698 uint16_t i; 7699 7700 for (i = 0; i < NUM_6GHZ_CHANNELS; i++) { 7701 if (freq == mas_chan_list[i].center_freq) { 7702 *eirp_psd_power = mas_chan_list[i].psd_eirp; 7703 return QDF_STATUS_SUCCESS; 7704 } 7705 } 7706 7707 return QDF_STATUS_E_FAILURE; 7708 } 7709 7710 QDF_STATUS reg_get_6g_chan_ap_power(struct wlan_objmgr_pdev *pdev, 7711 qdf_freq_t chan_freq, bool *is_psd, 7712 uint16_t *tx_power, 7713 uint16_t *eirp_psd_power) 7714 { 7715 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7716 struct regulatory_channel *master_chan_list; 7717 enum reg_6g_ap_type ap_pwr_type; 7718 QDF_STATUS status = QDF_STATUS_SUCCESS; 7719 7720 pdev_priv_obj = reg_get_pdev_obj(pdev); 7721 if (!pdev_priv_obj) { 7722 reg_err("pdev priv obj is NULL"); 7723 return QDF_STATUS_E_FAILURE; 7724 } 7725 7726 status = reg_get_cur_6g_ap_pwr_type(pdev, &ap_pwr_type); 7727 if (!QDF_IS_STATUS_SUCCESS(status)) 7728 return status; 7729 7730 master_chan_list = pdev_priv_obj->mas_chan_list_6g_ap[ap_pwr_type]; 7731 7732 reg_find_txpower_from_6g_list(chan_freq, master_chan_list, 7733 tx_power); 7734 7735 *is_psd = reg_is_6g_psd_power(pdev); 7736 if (*is_psd) 7737 status = reg_get_6g_chan_psd_eirp_power(chan_freq, 7738 master_chan_list, 7739 eirp_psd_power); 7740 7741 return status; 7742 } 7743 7744 QDF_STATUS reg_get_client_power_for_connecting_ap(struct wlan_objmgr_pdev *pdev, 7745 enum reg_6g_ap_type ap_type, 7746 qdf_freq_t chan_freq, 7747 bool is_psd, 7748 uint16_t *tx_power, 7749 uint16_t *eirp_psd_power) 7750 { 7751 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7752 enum reg_6g_client_type client_type; 7753 struct regulatory_channel *master_chan_list; 7754 QDF_STATUS status = QDF_STATUS_SUCCESS; 7755 7756 pdev_priv_obj = reg_get_pdev_obj(pdev); 7757 if (!pdev_priv_obj) { 7758 reg_err("pdev priv obj is NULL"); 7759 return QDF_STATUS_E_FAILURE; 7760 } 7761 7762 reg_get_cur_6g_client_type(pdev, &client_type); 7763 7764 master_chan_list = 7765 pdev_priv_obj->mas_chan_list_6g_client[ap_type][client_type]; 7766 7767 reg_find_txpower_from_6g_list(chan_freq, master_chan_list, 7768 tx_power); 7769 7770 if (is_psd) 7771 status = reg_get_6g_chan_psd_eirp_power(chan_freq, 7772 master_chan_list, 7773 eirp_psd_power); 7774 7775 return status; 7776 } 7777 7778 QDF_STATUS reg_get_client_power_for_6ghz_ap(struct wlan_objmgr_pdev *pdev, 7779 enum reg_6g_client_type client_type, 7780 qdf_freq_t chan_freq, 7781 bool *is_psd, uint16_t *tx_power, 7782 uint16_t *eirp_psd_power) 7783 { 7784 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7785 enum reg_6g_ap_type ap_pwr_type; 7786 struct regulatory_channel *master_chan_list; 7787 QDF_STATUS status = QDF_STATUS_SUCCESS; 7788 7789 status = reg_get_cur_6g_ap_pwr_type(pdev, &ap_pwr_type); 7790 if (!QDF_IS_STATUS_SUCCESS(status)) 7791 return status; 7792 7793 pdev_priv_obj = reg_get_pdev_obj(pdev); 7794 if (!pdev_priv_obj) { 7795 reg_err("pdev priv obj is NULL"); 7796 return QDF_STATUS_E_FAILURE; 7797 } 7798 7799 master_chan_list = pdev_priv_obj-> 7800 mas_chan_list_6g_client[ap_pwr_type][client_type]; 7801 7802 reg_find_txpower_from_6g_list(chan_freq, master_chan_list, 7803 tx_power); 7804 7805 *is_psd = reg_is_6g_psd_power(pdev); 7806 if (*is_psd) 7807 status = reg_get_6g_chan_psd_eirp_power(chan_freq, 7808 master_chan_list, 7809 eirp_psd_power); 7810 7811 return status; 7812 } 7813 7814 QDF_STATUS reg_set_ap_pwr_and_update_chan_list(struct wlan_objmgr_pdev *pdev, 7815 enum reg_6g_ap_type ap_pwr_type) 7816 { 7817 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7818 QDF_STATUS status; 7819 7820 pdev_priv_obj = reg_get_pdev_obj(pdev); 7821 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7822 reg_err("pdev reg component is NULL"); 7823 return QDF_STATUS_E_INVAL; 7824 } 7825 7826 if (!reg_get_num_rules_of_ap_pwr_type(pdev, ap_pwr_type)) 7827 return QDF_STATUS_E_FAILURE; 7828 7829 status = reg_set_cur_6g_ap_pwr_type(pdev, ap_pwr_type); 7830 if (QDF_IS_STATUS_ERROR(status)) { 7831 reg_debug("failed to set AP power type to %d", ap_pwr_type); 7832 return status; 7833 } 7834 7835 reg_compute_pdev_current_chan_list(pdev_priv_obj); 7836 7837 return QDF_STATUS_SUCCESS; 7838 } 7839 #endif 7840 7841 bool reg_is_regdb_offloaded(struct wlan_objmgr_psoc *psoc) 7842 { 7843 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7844 7845 psoc_priv_obj = reg_get_psoc_obj(psoc); 7846 if (!psoc_priv_obj) { 7847 reg_err("reg psoc private obj is NULL"); 7848 return false; 7849 } 7850 7851 return psoc_priv_obj->offload_enabled; 7852 } 7853 7854 QDF_STATUS 7855 reg_set_ext_tpc_supported(struct wlan_objmgr_psoc *psoc, bool val) 7856 { 7857 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7858 7859 psoc_priv_obj = reg_get_psoc_obj(psoc); 7860 7861 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 7862 reg_err("psoc reg component is NULL"); 7863 return QDF_STATUS_E_FAILURE; 7864 } 7865 7866 psoc_priv_obj->is_ext_tpc_supported = val; 7867 7868 return QDF_STATUS_SUCCESS; 7869 } 7870 7871 bool reg_is_ext_tpc_supported(struct wlan_objmgr_psoc *psoc) 7872 { 7873 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7874 7875 psoc_priv_obj = reg_get_psoc_obj(psoc); 7876 7877 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 7878 reg_err("psoc reg component is NULL"); 7879 return false; 7880 } 7881 7882 return psoc_priv_obj->is_ext_tpc_supported; 7883 } 7884 7885 #if defined(CONFIG_BAND_6GHZ) 7886 QDF_STATUS 7887 reg_set_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc, bool val) 7888 { 7889 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7890 7891 psoc_priv_obj = reg_get_psoc_obj(psoc); 7892 7893 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 7894 reg_err("psoc reg component is NULL"); 7895 return QDF_STATUS_E_FAILURE; 7896 } 7897 7898 psoc_priv_obj->is_lower_6g_edge_ch_supported = val; 7899 7900 return QDF_STATUS_SUCCESS; 7901 } 7902 7903 QDF_STATUS 7904 reg_set_disable_upper_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc, bool val) 7905 { 7906 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7907 7908 psoc_priv_obj = reg_get_psoc_obj(psoc); 7909 7910 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 7911 reg_err("psoc reg component is NULL"); 7912 return QDF_STATUS_E_FAILURE; 7913 } 7914 7915 psoc_priv_obj->is_upper_6g_edge_ch_disabled = val; 7916 7917 return QDF_STATUS_SUCCESS; 7918 } 7919 7920 bool reg_is_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc) 7921 { 7922 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7923 7924 psoc_priv_obj = reg_get_psoc_obj(psoc); 7925 7926 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 7927 reg_err("psoc reg component is NULL"); 7928 return false; 7929 } 7930 7931 return psoc_priv_obj->is_lower_6g_edge_ch_supported; 7932 } 7933 7934 bool reg_is_upper_6g_edge_ch_disabled(struct wlan_objmgr_psoc *psoc) 7935 { 7936 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 7937 7938 psoc_priv_obj = reg_get_psoc_obj(psoc); 7939 7940 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 7941 reg_err("psoc reg component is NULL"); 7942 return false; 7943 } 7944 7945 return psoc_priv_obj->is_upper_6g_edge_ch_disabled; 7946 } 7947 7948 static inline bool reg_is_within_range_inclusive(enum channel_enum left, 7949 enum channel_enum right, 7950 enum channel_enum idx) 7951 { 7952 return (idx >= left) && (idx <= right); 7953 } 7954 7955 uint16_t reg_convert_enum_to_6g_idx(enum channel_enum ch_idx) 7956 { 7957 if (!reg_is_within_range_inclusive(MIN_6GHZ_CHANNEL, 7958 MAX_6GHZ_CHANNEL, 7959 ch_idx)) 7960 return INVALID_CHANNEL; 7961 7962 return (ch_idx - MIN_6GHZ_CHANNEL); 7963 } 7964 7965 QDF_STATUS 7966 reg_get_superchan_entry(struct wlan_objmgr_pdev *pdev, 7967 enum channel_enum chan_enum, 7968 const struct super_chan_info **p_sup_chan_entry) 7969 { 7970 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 7971 uint16_t sup_idx; 7972 7973 sup_idx = reg_convert_enum_to_6g_idx(chan_enum); 7974 7975 if (reg_is_chan_enum_invalid(sup_idx)) { 7976 reg_debug("super channel idx is invalid for the chan_enum %d", 7977 chan_enum); 7978 return QDF_STATUS_E_INVAL; 7979 } 7980 7981 pdev_priv_obj = reg_get_pdev_obj(pdev); 7982 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 7983 reg_err_rl("pdev reg component is NULL"); 7984 return QDF_STATUS_E_INVAL; 7985 } 7986 7987 if (!p_sup_chan_entry) { 7988 reg_err_rl("p_sup_chan_entry is NULL"); 7989 return QDF_STATUS_E_INVAL; 7990 } 7991 7992 if (sup_idx >= NUM_6GHZ_CHANNELS) { 7993 reg_debug("sup_idx is out of bounds"); 7994 return QDF_STATUS_E_INVAL; 7995 } 7996 7997 *p_sup_chan_entry = &pdev_priv_obj->super_chan_list[sup_idx]; 7998 7999 return QDF_STATUS_SUCCESS; 8000 } 8001 #endif 8002 8003 #ifdef FEATURE_WLAN_CH_AVOID_EXT 8004 /** 8005 * reg_process_ch_avoid_freq_ext() - Update extended avoid frequencies in 8006 * psoc_priv_obj 8007 * @psoc: Pointer to psoc structure 8008 * @pdev: pointer to pdev object 8009 * 8010 * Return: None 8011 */ 8012 static QDF_STATUS 8013 reg_process_ch_avoid_freq_ext(struct wlan_objmgr_psoc *psoc, 8014 struct wlan_objmgr_pdev *pdev) 8015 { 8016 uint32_t i; 8017 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8018 uint8_t start_channel; 8019 uint8_t end_channel; 8020 int32_t txpower; 8021 bool is_valid_txpower; 8022 struct ch_avoid_freq_type *range; 8023 enum channel_enum ch_loop; 8024 enum channel_enum start_ch_idx; 8025 enum channel_enum end_ch_idx; 8026 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8027 uint32_t len; 8028 struct unsafe_ch_list *unsafe_ch_list; 8029 bool coex_unsafe_nb_user_prefer; 8030 8031 pdev_priv_obj = reg_get_pdev_obj(pdev); 8032 8033 if (!pdev_priv_obj) { 8034 reg_err("reg pdev private obj is NULL"); 8035 return QDF_STATUS_E_FAILURE; 8036 } 8037 psoc_priv_obj = reg_get_psoc_obj(psoc); 8038 if (!psoc_priv_obj) { 8039 reg_err("reg psoc private obj is NULL"); 8040 return QDF_STATUS_E_FAILURE; 8041 } 8042 8043 unsafe_ch_list = &psoc_priv_obj->unsafe_chan_list; 8044 coex_unsafe_nb_user_prefer = 8045 psoc_priv_obj->coex_unsafe_chan_nb_user_prefer; 8046 8047 if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt > 0) { 8048 len = sizeof(pdev_priv_obj->avoid_chan_ext_list.chan_freq_list); 8049 pdev_priv_obj->avoid_chan_ext_list.chan_cnt = 0; 8050 qdf_mem_zero(&pdev_priv_obj->avoid_chan_ext_list.chan_freq_list, 8051 len); 8052 } 8053 8054 if (unsafe_ch_list->chan_cnt > 0) { 8055 len = sizeof(unsafe_ch_list->chan_freq_list); 8056 unsafe_ch_list->chan_cnt = 0; 8057 qdf_mem_zero(unsafe_ch_list->chan_freq_list, len); 8058 } 8059 8060 for (i = 0; i < psoc_priv_obj->avoid_freq_ext_list.ch_avoid_range_cnt; 8061 i++) { 8062 if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt >= 8063 NUM_CHANNELS) { 8064 reg_debug("ext avoid channel list full"); 8065 break; 8066 } 8067 8068 if (unsafe_ch_list->chan_cnt >= NUM_CHANNELS) { 8069 reg_warn("LTE Coex unsafe channel list full"); 8070 break; 8071 } 8072 8073 start_ch_idx = INVALID_CHANNEL; 8074 end_ch_idx = INVALID_CHANNEL; 8075 range = &psoc_priv_obj->avoid_freq_ext_list.avoid_freq_range[i]; 8076 8077 start_channel = reg_freq_to_chan(pdev, range->start_freq); 8078 end_channel = reg_freq_to_chan(pdev, range->end_freq); 8079 txpower = range->txpower; 8080 is_valid_txpower = range->is_valid_txpower; 8081 8082 reg_debug("start: freq %d, ch %d, end: freq %d, ch %d txpower %d", 8083 range->start_freq, start_channel, range->end_freq, 8084 end_channel, txpower); 8085 8086 /* do not process frequency bands that are not mapped to 8087 * predefined channels 8088 */ 8089 if (start_channel == 0 || end_channel == 0) 8090 continue; 8091 8092 for (ch_loop = 0; ch_loop < NUM_CHANNELS; 8093 ch_loop++) { 8094 if (REG_CH_TO_FREQ(ch_loop) >= range->start_freq) { 8095 start_ch_idx = ch_loop; 8096 break; 8097 } 8098 } 8099 for (ch_loop = 0; ch_loop < NUM_CHANNELS; 8100 ch_loop++) { 8101 if (REG_CH_TO_FREQ(ch_loop) >= range->end_freq) { 8102 end_ch_idx = ch_loop; 8103 if (REG_CH_TO_FREQ(ch_loop) > range->end_freq) 8104 end_ch_idx--; 8105 break; 8106 } 8107 } 8108 8109 if (reg_is_chan_enum_invalid(start_ch_idx) || 8110 reg_is_chan_enum_invalid(end_ch_idx)) 8111 continue; 8112 8113 for (ch_loop = start_ch_idx; ch_loop <= end_ch_idx; 8114 ch_loop++) { 8115 pdev_priv_obj->avoid_chan_ext_list.chan_freq_list 8116 [pdev_priv_obj->avoid_chan_ext_list.chan_cnt++] = 8117 REG_CH_TO_FREQ(ch_loop); 8118 8119 if (coex_unsafe_nb_user_prefer) { 8120 if (unsafe_ch_list->chan_cnt >= 8121 NUM_CHANNELS) { 8122 reg_warn("LTECoex unsafe ch list full"); 8123 break; 8124 } 8125 unsafe_ch_list->txpower[ 8126 unsafe_ch_list->chan_cnt] = 8127 txpower; 8128 unsafe_ch_list->is_valid_txpower[ 8129 unsafe_ch_list->chan_cnt] = 8130 is_valid_txpower; 8131 unsafe_ch_list->chan_freq_list[ 8132 unsafe_ch_list->chan_cnt++] = 8133 REG_CH_TO_FREQ(ch_loop); 8134 } 8135 8136 if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt >= 8137 NUM_CHANNELS) { 8138 reg_debug("avoid freq ext list full"); 8139 break; 8140 } 8141 } 8142 /* if start == end for 5G, meanwhile it only have one valid 8143 * channel updated, then disable 20M by default around 8144 * this center freq. For example input [5805-5805], it 8145 * will disable 20Mhz around 5805, then the range change 8146 * to [5705-5815], otherwise, not sure about how many width 8147 * need to disabled for such case. 8148 */ 8149 if ((ch_loop - start_ch_idx) == 1 && 8150 (range->end_freq - range->start_freq == 0) && 8151 reg_is_5ghz_ch_freq(range->start_freq)) { 8152 range->start_freq = range->start_freq - HALF_20MHZ_BW; 8153 range->end_freq = range->end_freq + HALF_20MHZ_BW; 8154 } 8155 8156 for (ch_loop = 0; ch_loop < 8157 unsafe_ch_list->chan_cnt; ch_loop++) { 8158 if (ch_loop >= NUM_CHANNELS) 8159 break; 8160 reg_debug("Unsafe freq %d", 8161 unsafe_ch_list->chan_freq_list[ch_loop]); 8162 } 8163 } 8164 8165 return QDF_STATUS_SUCCESS; 8166 } 8167 8168 /** 8169 * reg_update_avoid_ch_ext() - Updates the current channel list that block out 8170 * by extended avoid frequency list 8171 * @psoc: Pointer to psoc structure 8172 * @object: Pointer to pdev structure 8173 * @arg: List of arguments 8174 * 8175 * Return: None 8176 */ 8177 static void 8178 reg_update_avoid_ch_ext(struct wlan_objmgr_psoc *psoc, 8179 void *object, void *arg) 8180 { 8181 struct wlan_objmgr_pdev *pdev = (struct wlan_objmgr_pdev *)object; 8182 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8183 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8184 QDF_STATUS status; 8185 8186 psoc_priv_obj = reg_get_psoc_obj(psoc); 8187 if (!psoc_priv_obj) { 8188 reg_err("reg psoc private obj is NULL"); 8189 return; 8190 } 8191 8192 pdev_priv_obj = reg_get_pdev_obj(pdev); 8193 8194 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8195 reg_err("reg pdev priv obj is NULL"); 8196 return; 8197 } 8198 8199 if (psoc_priv_obj->ch_avoid_ext_ind) { 8200 status = reg_process_ch_avoid_freq_ext(psoc, pdev); 8201 if (QDF_IS_STATUS_ERROR(status)) 8202 psoc_priv_obj->ch_avoid_ext_ind = false; 8203 } 8204 8205 reg_compute_pdev_current_chan_list(pdev_priv_obj); 8206 status = reg_send_scheduler_msg_sb(psoc, pdev); 8207 8208 if (QDF_IS_STATUS_ERROR(status)) 8209 reg_err("channel change msg schedule failed"); 8210 } 8211 8212 QDF_STATUS 8213 reg_process_ch_avoid_ext_event(struct wlan_objmgr_psoc *psoc, 8214 struct ch_avoid_ind_type *ch_avoid_event) 8215 { 8216 uint32_t i; 8217 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8218 QDF_STATUS status; 8219 struct ch_avoid_freq_type *range; 8220 8221 psoc_priv_obj = reg_get_psoc_obj(psoc); 8222 if (!psoc_priv_obj) { 8223 reg_err("reg psoc private obj is NULL"); 8224 return QDF_STATUS_E_FAILURE; 8225 } 8226 8227 reg_debug("freq range count %d", ch_avoid_event->ch_avoid_range_cnt); 8228 8229 qdf_mem_zero(&psoc_priv_obj->avoid_freq_ext_list, 8230 sizeof(struct ch_avoid_ind_type)); 8231 8232 for (i = 0; i < ch_avoid_event->ch_avoid_range_cnt; i++) { 8233 range = &psoc_priv_obj->avoid_freq_ext_list.avoid_freq_range[i]; 8234 range->start_freq = 8235 ch_avoid_event->avoid_freq_range[i].start_freq; 8236 range->end_freq = 8237 ch_avoid_event->avoid_freq_range[i].end_freq; 8238 range->txpower = 8239 ch_avoid_event->avoid_freq_range[i].txpower; 8240 range->is_valid_txpower = 8241 ch_avoid_event->avoid_freq_range[i].is_valid_txpower; 8242 } 8243 8244 psoc_priv_obj->avoid_freq_ext_list.restriction_mask = 8245 ch_avoid_event->restriction_mask; 8246 psoc_priv_obj->avoid_freq_ext_list.ch_avoid_range_cnt = 8247 ch_avoid_event->ch_avoid_range_cnt; 8248 8249 psoc_priv_obj->ch_avoid_ext_ind = true; 8250 8251 status = wlan_objmgr_psoc_try_get_ref(psoc, WLAN_REGULATORY_SB_ID); 8252 8253 if (QDF_IS_STATUS_ERROR(status)) { 8254 reg_err("error taking psoc ref cnt"); 8255 return status; 8256 } 8257 8258 status = wlan_objmgr_iterate_obj_list(psoc, WLAN_PDEV_OP, 8259 reg_update_avoid_ch_ext, 8260 NULL, 1, 8261 WLAN_REGULATORY_SB_ID); 8262 8263 wlan_objmgr_psoc_release_ref(psoc, WLAN_REGULATORY_SB_ID); 8264 8265 return status; 8266 } 8267 8268 bool reg_check_coex_unsafe_nb_user_prefer(struct wlan_objmgr_psoc *psoc) 8269 { 8270 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8271 8272 psoc_priv_obj = reg_get_psoc_obj(psoc); 8273 if (!psoc_priv_obj) { 8274 reg_err("reg psoc private obj is NULL"); 8275 return false; 8276 } 8277 8278 return psoc_priv_obj->coex_unsafe_chan_nb_user_prefer; 8279 } 8280 8281 bool reg_check_coex_unsafe_chan_reg_disable(struct wlan_objmgr_psoc *psoc) 8282 { 8283 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 8284 8285 psoc_priv_obj = reg_get_psoc_obj(psoc); 8286 if (!psoc_priv_obj) { 8287 reg_err("reg psoc private obj is NULL"); 8288 return false; 8289 } 8290 8291 return psoc_priv_obj->coex_unsafe_chan_reg_disable; 8292 } 8293 #endif 8294 8295 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ) 8296 QDF_STATUS reg_send_afc_cmd(struct wlan_objmgr_pdev *pdev, 8297 struct reg_afc_resp_rx_ind_info *afc_ind_obj) 8298 { 8299 uint8_t pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 8300 struct wlan_objmgr_psoc *psoc; 8301 struct wlan_lmac_if_reg_tx_ops *tx_ops; 8302 8303 psoc = wlan_pdev_get_psoc(pdev); 8304 if (!psoc) { 8305 reg_err("psoc is NULL"); 8306 return QDF_STATUS_E_INVAL; 8307 } 8308 8309 tx_ops = reg_get_psoc_tx_ops(psoc); 8310 if (tx_ops->send_afc_ind) 8311 return tx_ops->send_afc_ind(psoc, pdev_id, afc_ind_obj); 8312 8313 return QDF_STATUS_E_FAILURE; 8314 } 8315 8316 bool reg_is_afc_power_event_received(struct wlan_objmgr_pdev *pdev) 8317 { 8318 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8319 8320 pdev_priv_obj = reg_get_pdev_obj(pdev); 8321 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8322 reg_err("pdev reg component is NULL"); 8323 return false; 8324 } 8325 8326 return pdev_priv_obj->is_6g_afc_power_event_received; 8327 } 8328 8329 bool reg_is_afc_done(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 8330 { 8331 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8332 uint32_t chan_flags; 8333 8334 pdev_priv_obj = reg_get_pdev_obj(pdev); 8335 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8336 reg_err("pdev reg component is NULL"); 8337 return false; 8338 } 8339 8340 chan_flags = reg_get_channel_flags_for_freq(pdev, freq); 8341 8342 return !(chan_flags & REGULATORY_CHAN_AFC_NOT_DONE); 8343 } 8344 8345 QDF_STATUS reg_get_afc_req_id(struct wlan_objmgr_pdev *pdev, uint64_t *req_id) 8346 { 8347 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8348 8349 pdev_priv_obj = reg_get_pdev_obj(pdev); 8350 8351 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8352 reg_err("reg pdev priv obj is NULL"); 8353 return QDF_STATUS_E_FAILURE; 8354 } 8355 8356 *req_id = pdev_priv_obj->afc_request_id; 8357 8358 return QDF_STATUS_SUCCESS; 8359 } 8360 8361 bool reg_is_afc_expiry_event_received(struct wlan_objmgr_pdev *pdev) 8362 { 8363 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8364 8365 pdev_priv_obj = reg_get_pdev_obj(pdev); 8366 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8367 reg_err("pdev reg component is NULL"); 8368 return false; 8369 } 8370 8371 return pdev_priv_obj->is_6g_afc_expiry_event_received; 8372 } 8373 8374 bool reg_is_noaction_on_afc_pwr_evt(struct wlan_objmgr_pdev *pdev) 8375 { 8376 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8377 8378 pdev_priv_obj = reg_get_pdev_obj(pdev); 8379 8380 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8381 reg_err("reg pdev priv obj is NULL"); 8382 return QDF_STATUS_E_FAILURE; 8383 } 8384 8385 return pdev_priv_obj->is_reg_noaction_on_afc_pwr_evt; 8386 } 8387 #endif 8388 8389 /** 8390 * struct bw_wireless_modes_pair - structure containing bandwidth and wireless 8391 * modes corresponding to the bandwidth 8392 * @ch_width: channel width 8393 * @wireless_modes: wireless modes bitmap corresponding to @ch_width. This 8394 * bitmap is a combination of enum values HOST_REGDMN_MODE 8395 */ 8396 struct bw_wireless_modes_pair { 8397 enum phy_ch_width ch_width; 8398 uint64_t wireless_modes; 8399 }; 8400 8401 /* Mapping of bandwidth to wireless modes */ 8402 static const struct bw_wireless_modes_pair bw_wireless_modes_pair_map[] = { 8403 #ifdef WLAN_FEATURE_11BE 8404 {CH_WIDTH_320MHZ, WIRELESS_320_MODES}, 8405 #endif 8406 {CH_WIDTH_80P80MHZ, WIRELESS_80P80_MODES}, 8407 {CH_WIDTH_160MHZ, WIRELESS_160_MODES}, 8408 {CH_WIDTH_80MHZ, WIRELESS_80_MODES}, 8409 {CH_WIDTH_40MHZ, WIRELESS_40_MODES}, 8410 {CH_WIDTH_20MHZ, WIRELESS_20_MODES}, 8411 {CH_WIDTH_10MHZ, WIRELESS_10_MODES}, 8412 {CH_WIDTH_5MHZ, WIRELESS_5_MODES}, 8413 }; 8414 8415 QDF_STATUS reg_is_chwidth_supported(struct wlan_objmgr_pdev *pdev, 8416 enum phy_ch_width ch_width, 8417 bool *is_supported) 8418 { 8419 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8420 uint64_t wireless_modes; 8421 uint8_t num_bws, idx; 8422 8423 pdev_priv_obj = reg_get_pdev_obj(pdev); 8424 8425 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8426 reg_err("reg pdev priv obj is NULL"); 8427 return QDF_STATUS_E_FAILURE; 8428 } 8429 8430 *is_supported = false; 8431 8432 wireless_modes = pdev_priv_obj->wireless_modes; 8433 num_bws = QDF_ARRAY_SIZE(bw_wireless_modes_pair_map); 8434 8435 for (idx = 0; idx < num_bws; ++idx) { 8436 if (bw_wireless_modes_pair_map[idx].ch_width == ch_width) { 8437 *is_supported = !!(wireless_modes & 8438 bw_wireless_modes_pair_map[idx].wireless_modes); 8439 break; 8440 } 8441 } 8442 8443 return QDF_STATUS_SUCCESS; 8444 } 8445 8446 bool reg_is_state_allowed(enum channel_state chan_state) 8447 { 8448 return !((chan_state == CHANNEL_STATE_INVALID) || 8449 (chan_state == CHANNEL_STATE_DISABLE)); 8450 } 8451 8452 static bool 8453 reg_is_freq_idx_enabled_on_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 8454 *pdev_priv_obj, 8455 enum channel_enum freq_idx) 8456 { 8457 struct regulatory_channel *cur_chan_list; 8458 8459 if (freq_idx >= NUM_CHANNELS) 8460 return false; 8461 8462 cur_chan_list = pdev_priv_obj->cur_chan_list; 8463 8464 return !reg_is_chan_disabled_and_not_nol(&cur_chan_list[freq_idx]); 8465 } 8466 8467 static QDF_STATUS 8468 reg_get_min_max_bw_on_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 8469 *pdev_priv_obj, 8470 enum channel_enum freq_idx, 8471 uint16_t *min_bw, 8472 uint16_t *max_bw) 8473 { 8474 struct regulatory_channel *cur_chan_list; 8475 8476 if (freq_idx >= NUM_CHANNELS) 8477 return QDF_STATUS_E_FAILURE; 8478 8479 cur_chan_list = pdev_priv_obj->cur_chan_list; 8480 if (min_bw) 8481 *min_bw = cur_chan_list[freq_idx].min_bw; 8482 if (max_bw) 8483 *max_bw = cur_chan_list[freq_idx].max_bw; 8484 8485 return QDF_STATUS_SUCCESS; 8486 } 8487 8488 static enum channel_state 8489 reg_get_chan_state_on_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 8490 *pdev_priv_obj, 8491 enum channel_enum freq_idx) 8492 { 8493 struct regulatory_channel *cur_chan_list; 8494 enum channel_state chan_state; 8495 8496 if (freq_idx >= NUM_CHANNELS) 8497 return CHANNEL_STATE_INVALID; 8498 8499 cur_chan_list = pdev_priv_obj->cur_chan_list; 8500 chan_state = cur_chan_list[freq_idx].state; 8501 8502 return chan_state; 8503 } 8504 8505 static enum channel_state 8506 reg_get_chan_state_based_on_nol_flag_cur_chan_list(struct wlan_regulatory_pdev_priv_obj 8507 *pdev_priv_obj, 8508 enum channel_enum freq_idx) 8509 { 8510 struct regulatory_channel *cur_chan_list; 8511 enum channel_state chan_state; 8512 8513 if (freq_idx >= NUM_CHANNELS) 8514 return CHANNEL_STATE_INVALID; 8515 8516 cur_chan_list = pdev_priv_obj->cur_chan_list; 8517 chan_state = cur_chan_list[freq_idx].state; 8518 8519 if ((cur_chan_list[freq_idx].nol_chan || 8520 cur_chan_list[freq_idx].nol_history) && 8521 chan_state == CHANNEL_STATE_DISABLE) 8522 chan_state = CHANNEL_STATE_DFS; 8523 8524 return chan_state; 8525 } 8526 8527 #ifdef CONFIG_BAND_6GHZ 8528 static inline bool 8529 reg_is_supr_entry_mode_disabled(const struct super_chan_info *super_chan_ent, 8530 enum supported_6g_pwr_types in_6g_pwr_mode) 8531 { 8532 return ((super_chan_ent->chan_flags_arr[in_6g_pwr_mode] & 8533 REGULATORY_CHAN_DISABLED) && 8534 super_chan_ent->state_arr[in_6g_pwr_mode] == 8535 CHANNEL_STATE_DISABLE); 8536 } 8537 8538 static bool 8539 reg_is_freq_idx_enabled_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 8540 *pdev_priv_obj, 8541 enum channel_enum freq_idx, 8542 enum supported_6g_pwr_types 8543 in_6g_pwr_mode) 8544 { 8545 const struct super_chan_info *super_chan_ent; 8546 QDF_STATUS status; 8547 8548 if (freq_idx >= NUM_CHANNELS) 8549 return false; 8550 8551 if (freq_idx < MIN_6GHZ_CHANNEL) 8552 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 8553 freq_idx); 8554 8555 status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx, 8556 &super_chan_ent); 8557 if (QDF_IS_STATUS_ERROR(status)) { 8558 reg_debug("Failed to get super channel entry for freq_idx %d", 8559 freq_idx); 8560 return false; 8561 } 8562 8563 /* If the input 6G power mode is best power mode, get the best power 8564 * mode type from the super channel entry. 8565 */ 8566 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 8567 in_6g_pwr_mode = super_chan_ent->best_power_mode; 8568 8569 return !reg_is_supr_entry_mode_disabled(super_chan_ent, in_6g_pwr_mode); 8570 } 8571 8572 static QDF_STATUS 8573 reg_get_min_max_bw_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 8574 *pdev_priv_obj, 8575 enum channel_enum freq_idx, 8576 enum supported_6g_pwr_types 8577 in_6g_pwr_mode, 8578 uint16_t *min_bw, 8579 uint16_t *max_bw) 8580 { 8581 const struct super_chan_info *super_chan_ent; 8582 QDF_STATUS status; 8583 8584 if (freq_idx >= NUM_CHANNELS) 8585 return QDF_STATUS_E_FAILURE; 8586 8587 if (freq_idx < MIN_6GHZ_CHANNEL) 8588 return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj, 8589 freq_idx, 8590 min_bw, max_bw); 8591 8592 status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx, 8593 &super_chan_ent); 8594 if (QDF_IS_STATUS_ERROR(status)) { 8595 reg_debug("Failed to get super channel entry for freq_idx %d", 8596 freq_idx); 8597 return QDF_STATUS_E_FAILURE; 8598 } 8599 8600 /* If the input 6G power mode is best power mode, get the best power 8601 * mode type from the super channel entry. 8602 */ 8603 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 8604 in_6g_pwr_mode = super_chan_ent->best_power_mode; 8605 8606 if (reg_is_supp_pwr_mode_invalid(in_6g_pwr_mode)) { 8607 reg_debug("pwr_type invalid"); 8608 return QDF_STATUS_E_FAILURE; 8609 } 8610 8611 if (min_bw) 8612 *min_bw = super_chan_ent->min_bw[in_6g_pwr_mode]; 8613 if (max_bw) 8614 *max_bw = super_chan_ent->max_bw[in_6g_pwr_mode]; 8615 8616 return QDF_STATUS_SUCCESS; 8617 } 8618 8619 static enum channel_state 8620 reg_get_chan_state_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 8621 *pdev_priv_obj, 8622 enum channel_enum freq_idx, 8623 enum supported_6g_pwr_types 8624 in_6g_pwr_mode) 8625 { 8626 const struct super_chan_info *super_chan_ent; 8627 enum channel_state chan_state; 8628 QDF_STATUS status; 8629 8630 if (freq_idx >= NUM_CHANNELS) 8631 return CHANNEL_STATE_INVALID; 8632 8633 if (freq_idx < MIN_6GHZ_CHANNEL) 8634 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 8635 freq_idx); 8636 8637 status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx, 8638 &super_chan_ent); 8639 if (QDF_IS_STATUS_ERROR(status)) { 8640 reg_debug("Failed to get super channel entry for freq_idx %d", 8641 freq_idx); 8642 return CHANNEL_STATE_INVALID; 8643 } 8644 8645 /* If the input 6G power mode is best power mode, get the best power 8646 * mode type from the super channel entry. 8647 */ 8648 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 8649 in_6g_pwr_mode = super_chan_ent->best_power_mode; 8650 8651 if (reg_is_supp_pwr_mode_invalid(in_6g_pwr_mode)) { 8652 reg_debug("pwr_type invalid"); 8653 return CHANNEL_STATE_INVALID; 8654 } 8655 8656 chan_state = super_chan_ent->state_arr[in_6g_pwr_mode]; 8657 8658 return chan_state; 8659 } 8660 8661 enum supported_6g_pwr_types 8662 reg_get_best_6g_pwr_type(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq) 8663 { 8664 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8665 enum channel_enum freq_idx; 8666 enum channel_enum sixg_freq_idx; 8667 8668 pdev_priv_obj = reg_get_pdev_obj(pdev); 8669 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8670 reg_err_rl("pdev reg component is NULL"); 8671 return REG_INVALID_PWR_MODE; 8672 } 8673 8674 freq_idx = reg_get_chan_enum_for_freq(freq); 8675 8676 if (reg_is_chan_enum_invalid(freq_idx)) 8677 return REG_INVALID_PWR_MODE; 8678 8679 sixg_freq_idx = reg_convert_enum_to_6g_idx(freq_idx); 8680 if (reg_is_chan_enum_invalid(sixg_freq_idx) || 8681 sixg_freq_idx >= NUM_6GHZ_CHANNELS) 8682 return REG_INVALID_PWR_MODE; 8683 8684 return pdev_priv_obj->super_chan_list[sixg_freq_idx].best_power_mode; 8685 } 8686 8687 static inline bool reg_is_6g_ap_type_invalid(enum reg_6g_ap_type ap_pwr_type) 8688 { 8689 return ((ap_pwr_type < REG_INDOOR_AP) || 8690 (ap_pwr_type > REG_MAX_SUPP_AP_TYPE)); 8691 } 8692 8693 enum supported_6g_pwr_types 8694 reg_conv_6g_ap_type_to_supported_6g_pwr_types(enum reg_6g_ap_type ap_pwr_type) 8695 { 8696 static const enum supported_6g_pwr_types reg_enum_conv[] = { 8697 [REG_INDOOR_AP] = REG_AP_LPI, 8698 [REG_STANDARD_POWER_AP] = REG_AP_SP, 8699 [REG_VERY_LOW_POWER_AP] = REG_AP_VLP, 8700 }; 8701 8702 if (reg_is_6g_ap_type_invalid(ap_pwr_type)) 8703 return REG_INVALID_PWR_MODE; 8704 8705 return reg_enum_conv[ap_pwr_type]; 8706 } 8707 #else 8708 static inline bool 8709 reg_is_freq_idx_enabled_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 8710 *pdev_priv_obj, 8711 enum channel_enum freq_idx, 8712 enum supported_6g_pwr_types 8713 in_6g_pwr_mode) 8714 { 8715 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 8716 freq_idx); 8717 } 8718 8719 static inline QDF_STATUS 8720 reg_get_min_max_bw_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 8721 *pdev_priv_obj, 8722 enum channel_enum freq_idx, 8723 enum supported_6g_pwr_types 8724 in_6g_pwr_mode, 8725 uint16_t *min_bw, 8726 uint16_t *max_bw) 8727 { 8728 return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj, 8729 freq_idx, 8730 min_bw, max_bw); 8731 } 8732 8733 static inline enum channel_state 8734 reg_get_chan_state_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj 8735 *pdev_priv_obj, 8736 enum channel_enum freq_idx, 8737 enum supported_6g_pwr_types 8738 in_6g_pwr_mode) 8739 { 8740 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 8741 freq_idx); 8742 } 8743 #endif /* CONFIG_BAND_6GHZ */ 8744 8745 bool 8746 reg_is_freq_enabled(struct wlan_objmgr_pdev *pdev, 8747 qdf_freq_t freq, 8748 enum supported_6g_pwr_types in_6g_pwr_mode) 8749 { 8750 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8751 enum channel_enum freq_idx; 8752 8753 pdev_priv_obj = reg_get_pdev_obj(pdev); 8754 8755 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8756 reg_err("reg pdev private obj is NULL"); 8757 return false; 8758 } 8759 8760 freq_idx = reg_get_chan_enum_for_freq(freq); 8761 8762 if (reg_is_chan_enum_invalid(freq_idx)) 8763 return false; 8764 8765 return reg_is_freq_idx_enabled(pdev, freq_idx, in_6g_pwr_mode); 8766 } 8767 8768 bool reg_is_freq_idx_enabled(struct wlan_objmgr_pdev *pdev, 8769 enum channel_enum freq_idx, 8770 enum supported_6g_pwr_types in_6g_pwr_mode) 8771 { 8772 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8773 8774 pdev_priv_obj = reg_get_pdev_obj(pdev); 8775 8776 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8777 reg_err("reg pdev private obj is NULL"); 8778 return false; 8779 } 8780 8781 if (freq_idx < MIN_6GHZ_CHANNEL) 8782 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 8783 freq_idx); 8784 8785 switch (in_6g_pwr_mode) { 8786 case REG_CURRENT_PWR_MODE: 8787 return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj, 8788 freq_idx); 8789 8790 case REG_BEST_PWR_MODE: 8791 default: 8792 return reg_is_freq_idx_enabled_on_given_pwr_mode(pdev_priv_obj, 8793 freq_idx, 8794 in_6g_pwr_mode 8795 ); 8796 } 8797 } 8798 8799 QDF_STATUS reg_get_min_max_bw_reg_chan_list(struct wlan_objmgr_pdev *pdev, 8800 enum channel_enum freq_idx, 8801 enum supported_6g_pwr_types 8802 in_6g_pwr_mode, 8803 uint16_t *min_bw, 8804 uint16_t *max_bw) 8805 { 8806 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8807 8808 pdev_priv_obj = reg_get_pdev_obj(pdev); 8809 8810 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8811 reg_err("reg pdev private obj is NULL"); 8812 return QDF_STATUS_E_FAILURE; 8813 } 8814 8815 if (freq_idx < MIN_6GHZ_CHANNEL) 8816 return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj, 8817 freq_idx, 8818 min_bw, max_bw); 8819 8820 switch (in_6g_pwr_mode) { 8821 case REG_CURRENT_PWR_MODE: 8822 return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj, 8823 freq_idx, 8824 min_bw, max_bw); 8825 8826 case REG_BEST_PWR_MODE: 8827 default: 8828 return reg_get_min_max_bw_on_given_pwr_mode(pdev_priv_obj, 8829 freq_idx, 8830 in_6g_pwr_mode, 8831 min_bw, max_bw); 8832 } 8833 } 8834 8835 enum channel_state reg_get_chan_state(struct wlan_objmgr_pdev *pdev, 8836 enum channel_enum freq_idx, 8837 enum supported_6g_pwr_types 8838 in_6g_pwr_mode, 8839 bool treat_nol_chan_as_disabled) 8840 { 8841 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8842 8843 pdev_priv_obj = reg_get_pdev_obj(pdev); 8844 8845 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8846 reg_err("reg pdev private obj is NULL"); 8847 return CHANNEL_STATE_INVALID; 8848 } 8849 8850 if (freq_idx < MIN_6GHZ_CHANNEL) { 8851 if (treat_nol_chan_as_disabled) 8852 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 8853 freq_idx); 8854 else 8855 return reg_get_chan_state_based_on_nol_flag_cur_chan_list( 8856 pdev_priv_obj, 8857 freq_idx); 8858 } 8859 8860 switch (in_6g_pwr_mode) { 8861 case REG_CURRENT_PWR_MODE: 8862 return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj, 8863 freq_idx); 8864 8865 case REG_BEST_PWR_MODE: 8866 default: 8867 return reg_get_chan_state_on_given_pwr_mode(pdev_priv_obj, 8868 freq_idx, 8869 in_6g_pwr_mode 8870 ); 8871 } 8872 } 8873 8874 #ifdef WLAN_FEATURE_11BE 8875 enum phy_ch_width reg_find_chwidth_from_bw(uint16_t bw) 8876 { 8877 switch (bw) { 8878 case BW_5_MHZ: 8879 return CH_WIDTH_5MHZ; 8880 case BW_10_MHZ: 8881 return CH_WIDTH_10MHZ; 8882 case BW_20_MHZ: 8883 return CH_WIDTH_20MHZ; 8884 case BW_40_MHZ: 8885 return CH_WIDTH_40MHZ; 8886 case BW_80_MHZ: 8887 return CH_WIDTH_80MHZ; 8888 case BW_160_MHZ: 8889 return CH_WIDTH_160MHZ; 8890 case BW_320_MHZ: 8891 return CH_WIDTH_320MHZ; 8892 default: 8893 return CH_WIDTH_INVALID; 8894 } 8895 } 8896 #else 8897 enum phy_ch_width reg_find_chwidth_from_bw(uint16_t bw) 8898 { 8899 switch (bw) { 8900 case BW_5_MHZ: 8901 return CH_WIDTH_5MHZ; 8902 case BW_10_MHZ: 8903 return CH_WIDTH_10MHZ; 8904 case BW_20_MHZ: 8905 return CH_WIDTH_20MHZ; 8906 case BW_40_MHZ: 8907 return CH_WIDTH_40MHZ; 8908 case BW_80_MHZ: 8909 return CH_WIDTH_80MHZ; 8910 case BW_160_MHZ: 8911 return CH_WIDTH_160MHZ; 8912 default: 8913 return CH_WIDTH_INVALID; 8914 } 8915 } 8916 #endif 8917 8918 #ifdef CONFIG_BAND_6GHZ 8919 qdf_freq_t reg_get_thresh_priority_freq(struct wlan_objmgr_pdev *pdev) 8920 { 8921 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8922 8923 pdev_priv_obj = reg_get_pdev_obj(pdev); 8924 8925 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 8926 reg_err("reg pdev private obj is NULL"); 8927 return 0; 8928 } 8929 8930 return pdev_priv_obj->reg_6g_thresh_priority_freq; 8931 } 8932 8933 /** 8934 * reg_get_eirp_for_non_sp() - For the given power mode, using the bandwidth 8935 * and psd(from master channel entry), calculate an EIRP value. The minimum 8936 * of calculated EIRP and regulatory max EIRP is returned. 8937 * @pdev: Pointer to pdev 8938 * @freq: Frequency in mhz 8939 * @bw: Bandwidth in mhz 8940 * @ap_pwr_type: AP Power type 8941 * 8942 * Return: EIRP 8943 */ 8944 static uint8_t 8945 reg_get_eirp_for_non_sp(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq, 8946 uint16_t bw, enum reg_6g_ap_type ap_pwr_type) 8947 { 8948 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 8949 bool is_psd; 8950 struct regulatory_channel *master_chan_list; 8951 uint16_t txpower = 0; 8952 8953 pdev_priv_obj = reg_get_pdev_obj(pdev); 8954 if (!pdev_priv_obj) { 8955 reg_err("pdev priv obj is NULL"); 8956 return 0; 8957 } 8958 8959 if (!((ap_pwr_type == REG_INDOOR_AP) || 8960 (ap_pwr_type == REG_VERY_LOW_POWER_AP))) { 8961 reg_err("Only LPI and VLP are supported in this function "); 8962 return 0; 8963 } 8964 8965 master_chan_list = pdev_priv_obj->mas_chan_list_6g_ap[ap_pwr_type]; 8966 is_psd = reg_is_6g_psd_power(pdev); 8967 reg_find_txpower_from_6g_list(freq, master_chan_list, &txpower); 8968 8969 if (is_psd) { 8970 int16_t eirp = 0, psd = 0; 8971 8972 reg_get_6g_chan_psd_eirp_power(freq, master_chan_list, &psd); 8973 reg_psd_2_eirp(pdev, psd, bw, &eirp); 8974 return QDF_MIN(txpower, eirp); 8975 } 8976 8977 return txpower; 8978 } 8979 8980 #ifdef CONFIG_AFC_SUPPORT 8981 /** 8982 * reg_compute_6g_center_freq_from_cfi() - Given the IEEE value of the 8983 * 6 GHz center frequency, find the 6 GHz center frequency. 8984 * @ieee_6g_cfi: IEEE value of 6 GHz cfi 8985 * Return: Center frequency in MHz 8986 */ 8987 static qdf_freq_t 8988 reg_compute_6g_center_freq_from_cfi(uint8_t ieee_6g_cfi) 8989 { 8990 return (SIXG_START_FREQ + ieee_6g_cfi * FREQ_TO_CHAN_SCALE); 8991 } 8992 8993 #ifdef WLAN_FEATURE_11BE 8994 /** 8995 * reg_is_320_opclass: Find out if the opclass computed from freq and 8996 * width of 320 is same as the input op_class. 8997 * @freq: Frequency in MHz 8998 * @in_opclass: Input Opclass number 8999 * Return: true if opclass is 320 supported, false otherwise. 9000 */ 9001 static bool reg_is_320_opclass(qdf_freq_t freq, uint8_t in_opclass) 9002 { 9003 uint8_t local_op_class = 9004 reg_dmn_get_opclass_from_freq_width(NULL, freq, BW_320_MHZ, 9005 BIT(BEHAV_NONE)); 9006 return (in_opclass == local_op_class); 9007 } 9008 #else 9009 static inline bool reg_is_320_opclass(qdf_freq_t freq, uint8_t op_class) 9010 { 9011 return false; 9012 } 9013 #endif 9014 9015 /** 9016 * reg_find_eirp_in_afc_eirp_obj() - Get eirp power from the AFC eirp object 9017 * based on the channel center frequency and operating class 9018 * @pdev: Pointer to pdev 9019 * @eirp_obj: Pointer to eirp_obj 9020 * @freq: Frequency in MHz 9021 * @cen320: 320 MHz band center frequency 9022 * @op_class: Operating class 9023 * 9024 * Return: EIRP power 9025 */ 9026 static uint8_t reg_find_eirp_in_afc_eirp_obj(struct wlan_objmgr_pdev *pdev, 9027 struct chan_eirp_obj *eirp_obj, 9028 qdf_freq_t freq, 9029 qdf_freq_t cen320, 9030 uint8_t op_class) 9031 { 9032 uint8_t k; 9033 uint8_t subchannels[NUM_20_MHZ_CHAN_IN_320_MHZ_CHAN]; 9034 uint8_t nchans; 9035 9036 if (reg_is_320_opclass(freq, op_class)) { 9037 qdf_freq_t cfi_freq = 9038 reg_compute_6g_center_freq_from_cfi(eirp_obj->cfi); 9039 9040 if (cfi_freq == cen320) 9041 return eirp_obj->eirp_power / EIRP_PWR_SCALE; 9042 9043 return 0; 9044 } 9045 9046 nchans = reg_get_subchannels_for_opclass(eirp_obj->cfi, 9047 op_class, 9048 subchannels); 9049 9050 for (k = 0; k < nchans; k++) 9051 if (reg_chan_band_to_freq(pdev, subchannels[k], 9052 BIT(REG_BAND_6G)) == freq) 9053 return eirp_obj->eirp_power / EIRP_PWR_SCALE; 9054 9055 return 0; 9056 } 9057 9058 /** 9059 * reg_find_eirp_in_afc_chan_obj() - Get eirp power from the AFC channel 9060 * object based on the channel center frequency and operating class 9061 * @pdev: Pointer to pdev 9062 * @chan_obj: Pointer to chan_obj 9063 * @freq: Frequency in MHz 9064 * @cen320: 320 MHz band center frequency 9065 * @op_class: Operating class 9066 * 9067 * Return: EIRP power 9068 */ 9069 static uint8_t reg_find_eirp_in_afc_chan_obj(struct wlan_objmgr_pdev *pdev, 9070 struct afc_chan_obj *chan_obj, 9071 qdf_freq_t freq, 9072 qdf_freq_t cen320, 9073 uint8_t op_class) 9074 { 9075 uint8_t j; 9076 9077 if (chan_obj->global_opclass != op_class) 9078 return 0; 9079 9080 for (j = 0; j < chan_obj->num_chans; j++) { 9081 uint8_t afc_eirp; 9082 struct chan_eirp_obj *eirp_obj = &chan_obj->chan_eirp_info[j]; 9083 9084 afc_eirp = reg_find_eirp_in_afc_eirp_obj(pdev, eirp_obj, 9085 freq, cen320, 9086 op_class); 9087 9088 if (afc_eirp) 9089 return afc_eirp; 9090 } 9091 9092 return 0; 9093 } 9094 9095 /** 9096 * reg_get_sp_eirp() - For the given power mode, using the bandwidth, find the 9097 * corresponding EIRP values from the afc power info array. The minimum of found 9098 * EIRP and regulatory max EIRP is returned 9099 * @pdev: Pointer to pdev 9100 * @freq: Frequency in MHz 9101 * @cen320: 320 MHz band center frequency 9102 * @bw: Bandwidth in mhz 9103 * 9104 * Return: EIRP 9105 */ 9106 static uint8_t reg_get_sp_eirp(struct wlan_objmgr_pdev *pdev, 9107 qdf_freq_t freq, 9108 qdf_freq_t cen320, 9109 uint16_t bw) 9110 { 9111 uint8_t i, op_class = 0, chan_num = 0, afc_eirp_pwr = 0; 9112 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9113 struct regulatory_channel *sp_ap_master_chan_list; 9114 struct reg_fw_afc_power_event *power_info; 9115 uint16_t reg_sp_eirp_pwr = 0; 9116 9117 pdev_priv_obj = reg_get_pdev_obj(pdev); 9118 9119 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9120 reg_err("reg pdev priv obj is NULL"); 9121 return 0; 9122 } 9123 9124 if (!reg_is_afc_power_event_received(pdev)) 9125 return 0; 9126 9127 power_info = pdev_priv_obj->power_info; 9128 if (!power_info) { 9129 reg_err("power_info is NULL"); 9130 return 0; 9131 } 9132 9133 reg_freq_width_to_chan_op_class(pdev, 9134 freq, 9135 bw, 9136 true, 9137 BIT(BEHAV_NONE), 9138 &op_class, 9139 &chan_num); 9140 sp_ap_master_chan_list = 9141 pdev_priv_obj->mas_chan_list_6g_ap[REG_STANDARD_POWER_AP]; 9142 reg_find_txpower_from_6g_list(freq, sp_ap_master_chan_list, 9143 ®_sp_eirp_pwr); 9144 9145 if (!reg_sp_eirp_pwr) 9146 return 0; 9147 9148 for (i = 0; i < power_info->num_chan_objs; i++) { 9149 struct afc_chan_obj *chan_obj = &power_info->afc_chan_info[i]; 9150 9151 afc_eirp_pwr = reg_find_eirp_in_afc_chan_obj(pdev, 9152 chan_obj, 9153 freq, 9154 cen320, 9155 op_class); 9156 if (afc_eirp_pwr) 9157 break; 9158 } 9159 9160 if (afc_eirp_pwr) 9161 return QDF_MIN(afc_eirp_pwr, reg_sp_eirp_pwr); 9162 9163 return 0; 9164 } 9165 #else 9166 static uint8_t reg_get_sp_eirp(struct wlan_objmgr_pdev *pdev, 9167 qdf_freq_t freq, 9168 qdf_freq_t cen320, 9169 uint16_t bw) 9170 { 9171 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9172 struct regulatory_channel *sp_ap_master_chan_list; 9173 uint16_t reg_sp_eirp_pwr = 0; 9174 9175 pdev_priv_obj = reg_get_pdev_obj(pdev); 9176 9177 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9178 reg_err("reg pdev priv obj is NULL"); 9179 return 0; 9180 } 9181 9182 sp_ap_master_chan_list = 9183 pdev_priv_obj->mas_chan_list_6g_ap[REG_STANDARD_POWER_AP]; 9184 reg_find_txpower_from_6g_list(freq, sp_ap_master_chan_list, 9185 ®_sp_eirp_pwr); 9186 9187 return reg_sp_eirp_pwr; 9188 } 9189 #endif 9190 9191 /** 9192 * reg_get_best_pwr_mode_from_eirp_list() - Get best power mode from the input 9193 * EIRP list 9194 * @eirp_list: EIRP list 9195 * @size: Size of eirp list 9196 * 9197 * Return: Best power mode 9198 */ 9199 static enum reg_6g_ap_type 9200 reg_get_best_pwr_mode_from_eirp_list(uint8_t *eirp_list, uint8_t size) 9201 { 9202 uint8_t max = 0, i; 9203 enum reg_6g_ap_type best_pwr_mode = REG_INDOOR_AP; 9204 9205 for (i = 0; i < size; i++) { 9206 if (eirp_list[i] > max) { 9207 max = eirp_list[i]; 9208 best_pwr_mode = i; 9209 } 9210 } 9211 9212 return best_pwr_mode; 9213 } 9214 9215 uint8_t reg_get_eirp_pwr(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq, 9216 qdf_freq_t cen320, 9217 uint16_t bw, enum reg_6g_ap_type ap_pwr_type) 9218 { 9219 if (ap_pwr_type == REG_STANDARD_POWER_AP) 9220 return reg_get_sp_eirp(pdev, freq, cen320, bw); 9221 9222 return reg_get_eirp_for_non_sp(pdev, freq, bw, ap_pwr_type); 9223 } 9224 9225 enum reg_6g_ap_type reg_get_best_pwr_mode(struct wlan_objmgr_pdev *pdev, 9226 qdf_freq_t freq, 9227 qdf_freq_t cen320, 9228 uint16_t bw) 9229 { 9230 uint8_t eirp_list[REG_MAX_SUPP_AP_TYPE + 1]; 9231 enum reg_6g_ap_type ap_pwr_type; 9232 9233 for (ap_pwr_type = REG_INDOOR_AP; ap_pwr_type <= REG_VERY_LOW_POWER_AP; 9234 ap_pwr_type++) 9235 eirp_list[ap_pwr_type] = 9236 reg_get_eirp_pwr(pdev, freq, cen320, bw, 9237 ap_pwr_type); 9238 9239 return reg_get_best_pwr_mode_from_eirp_list(eirp_list, 9240 REG_MAX_SUPP_AP_TYPE + 1); 9241 } 9242 #endif 9243 9244 QDF_STATUS reg_get_regd_rules(struct wlan_objmgr_pdev *pdev, 9245 struct reg_rule_info *reg_rules) 9246 { 9247 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9248 9249 if (!pdev) { 9250 reg_err("pdev is NULL"); 9251 return QDF_STATUS_E_FAILURE; 9252 } 9253 9254 pdev_priv_obj = reg_get_pdev_obj(pdev); 9255 if (!pdev_priv_obj) { 9256 reg_err("pdev priv obj is NULL"); 9257 return QDF_STATUS_E_FAILURE; 9258 } 9259 9260 qdf_spin_lock_bh(&pdev_priv_obj->reg_rules_lock); 9261 qdf_mem_copy(reg_rules, &pdev_priv_obj->reg_rules, 9262 sizeof(struct reg_rule_info)); 9263 qdf_spin_unlock_bh(&pdev_priv_obj->reg_rules_lock); 9264 9265 return QDF_STATUS_SUCCESS; 9266 } 9267 9268 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ) 9269 bool 9270 reg_is_sup_chan_entry_afc_done(struct wlan_objmgr_pdev *pdev, 9271 enum channel_enum chan_idx, 9272 enum supported_6g_pwr_types in_6g_pwr_mode) 9273 { 9274 const struct super_chan_info *super_chan_ent; 9275 QDF_STATUS status; 9276 9277 status = reg_get_superchan_entry(pdev, chan_idx, 9278 &super_chan_ent); 9279 if (QDF_IS_STATUS_ERROR(status)) { 9280 reg_debug("Failed to get super channel entry for chan_idx %d", 9281 chan_idx); 9282 return false; 9283 } 9284 9285 if (in_6g_pwr_mode == REG_BEST_PWR_MODE) 9286 in_6g_pwr_mode = super_chan_ent->best_power_mode; 9287 9288 if (in_6g_pwr_mode != REG_AP_SP) 9289 return false; 9290 9291 return !(super_chan_ent->chan_flags_arr[in_6g_pwr_mode] & 9292 REGULATORY_CHAN_AFC_NOT_DONE); 9293 } 9294 #endif 9295 9296 #ifdef CONFIG_BAND_6GHZ 9297 QDF_STATUS 9298 reg_display_super_chan_list(struct wlan_objmgr_pdev *pdev) 9299 { 9300 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 9301 struct super_chan_info *super_chan_list; 9302 uint8_t i; 9303 9304 pdev_priv_obj = reg_get_pdev_obj(pdev); 9305 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 9306 reg_err_rl("pdev reg component is NULL"); 9307 return QDF_STATUS_E_FAILURE; 9308 } 9309 9310 super_chan_list = pdev_priv_obj->super_chan_list; 9311 for (i = 0; i < NUM_6GHZ_CHANNELS; i++) { 9312 struct super_chan_info *chan_info = &super_chan_list[i]; 9313 struct regulatory_channel cur_chan_list = 9314 pdev_priv_obj->cur_chan_list[MIN_6GHZ_CHANNEL + i]; 9315 uint8_t j; 9316 9317 qdf_print("Freq = %d\tPower types = 0x%x\t" 9318 "Best power mode = 0x%x\n", 9319 cur_chan_list.center_freq, chan_info->power_types, 9320 chan_info->best_power_mode); 9321 for (j = REG_AP_LPI; j <= REG_CLI_SUB_VLP; j++) { 9322 bool afc_not_done_bit; 9323 9324 afc_not_done_bit = chan_info->chan_flags_arr[j] & 9325 REGULATORY_CHAN_AFC_NOT_DONE; 9326 qdf_print("Power mode = %d\tPSD flag = %d\t" 9327 "PSD power = %d\tEIRP power = %d\t" 9328 "Chan flags = 0x%x\tChannel state = %d\t" 9329 "Min bw = %d\tMax bw = %d\t" 9330 "AFC_NOT_DONE = %d\n", 9331 j, chan_info->reg_chan_pwr[j].psd_flag, 9332 chan_info->reg_chan_pwr[j].psd_eirp, 9333 chan_info->reg_chan_pwr[j].tx_power, 9334 chan_info->chan_flags_arr[j], 9335 chan_info->state_arr[j], 9336 chan_info->min_bw[j], chan_info->max_bw[j], 9337 afc_not_done_bit); 9338 } 9339 } 9340 9341 return QDF_STATUS_SUCCESS; 9342 } 9343 #endif 9344