1 /* 2 * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved. 3 * 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.h 22 * This file provides prototypes of the regulatory component 23 * service functions 24 */ 25 26 #ifndef __REG_SERVICES_COMMON_H_ 27 #define __REG_SERVICES_COMMON_H_ 28 29 #define IS_VALID_PSOC_REG_OBJ(psoc_priv_obj) (psoc_priv_obj) 30 #define IS_VALID_PDEV_REG_OBJ(pdev_priv_obj) (pdev_priv_obj) 31 32 #define REG_MIN_24GHZ_CH_NUM channel_map[MIN_24GHZ_CHANNEL].chan_num 33 #define REG_MAX_24GHZ_CH_NUM channel_map[MAX_24GHZ_CHANNEL].chan_num 34 #define REG_MIN_5GHZ_CH_NUM channel_map[MIN_5GHZ_CHANNEL].chan_num 35 #define REG_MAX_5GHZ_CH_NUM channel_map[MAX_5GHZ_CHANNEL].chan_num 36 37 #define REG_IS_24GHZ_CH(chan_num) \ 38 (((chan_num) >= REG_MIN_24GHZ_CH_NUM) && \ 39 ((chan_num) <= REG_MAX_24GHZ_CH_NUM)) 40 41 #define REG_MIN_24GHZ_CH_FREQ channel_map[MIN_24GHZ_CHANNEL].center_freq 42 #define REG_MAX_24GHZ_CH_FREQ channel_map[MAX_24GHZ_CHANNEL].center_freq 43 44 #define REG_IS_24GHZ_CH_FREQ(freq) \ 45 (((freq) >= REG_MIN_24GHZ_CH_FREQ) && \ 46 ((freq) <= REG_MAX_24GHZ_CH_FREQ)) 47 48 #ifndef CONFIG_LEGACY_CHAN_ENUM 49 #define REG_MIN_49GHZ_CH_FREQ channel_map[MIN_49GHZ_CHANNEL].center_freq 50 #define REG_MAX_49GHZ_CH_FREQ channel_map[MAX_49GHZ_CHANNEL].center_freq 51 52 #define REG_IS_49GHZ_FREQ(freq) \ 53 (((freq) >= REG_MIN_49GHZ_CH_FREQ) && \ 54 ((freq) <= REG_MAX_49GHZ_CH_FREQ)) 55 #endif 56 57 #define REG_IS_5GHZ_CH(chan_num) \ 58 (((chan_num) >= REG_MIN_5GHZ_CH_NUM) && \ 59 ((chan_num) <= REG_MAX_5GHZ_CH_NUM)) 60 61 #define REG_IS_5GHZ_FREQ(freq) \ 62 (((freq) >= channel_map[MIN_5GHZ_CHANNEL].center_freq) && \ 63 ((freq) <= channel_map[MAX_5GHZ_CHANNEL].center_freq)) 64 65 #define REG_CH_NUM(ch_enum) channel_map[ch_enum].chan_num 66 #define REG_CH_TO_FREQ(ch_enum) channel_map[ch_enum].center_freq 67 68 /* EEPROM setting is a country code */ 69 #define COUNTRY_ERD_FLAG 0x8000 70 71 extern const struct chan_map *channel_map; 72 73 /** 74 * reg_get_chan_enum() - Get channel enum for given channel number 75 * @chan_num: Channel number 76 * 77 * Return: Channel enum 78 */ 79 enum channel_enum reg_get_chan_enum(uint32_t chan_num); 80 81 /** 82 * reg_get_channel_list_with_power() - Provides the channel list with power 83 * @pdev: Pointer to pdev 84 * @ch_list: Pointer to the channel list. 85 * @num_chan: Pointer to save number of channels 86 * 87 * Return: QDF_STATUS 88 */ 89 QDF_STATUS reg_get_channel_list_with_power(struct wlan_objmgr_pdev *pdev, 90 struct channel_power *ch_list, 91 uint8_t *num_chan); 92 93 /** 94 * reg_get_channel_state() - Get channel state from regulatory 95 * @pdev: Pointer to pdev 96 * @ch: channel number. 97 * 98 * Return: channel state 99 */ 100 enum channel_state reg_get_channel_state(struct wlan_objmgr_pdev *pdev, 101 uint32_t ch); 102 103 /** 104 * reg_get_5g_bonded_channel_state() - Get channel state for 5G bonded channel 105 * @pdev: Pointer to pdev 106 * @ch: channel number. 107 * @bw: channel band width 108 * 109 * Return: channel state 110 */ 111 enum channel_state reg_get_5g_bonded_channel_state( 112 struct wlan_objmgr_pdev *pdev, uint8_t ch, 113 enum phy_ch_width bw); 114 115 /** 116 * reg_get_2g_bonded_channel_state() - Get channel state for 2G bonded channel 117 * @ch: channel number. 118 * @pdev: Pointer to pdev 119 * @oper_ch: Primary channel number 120 * @sec_ch: Secondary channel number 121 * @bw: channel band width 122 * 123 * Return: channel state 124 */ 125 enum channel_state reg_get_2g_bonded_channel_state( 126 struct wlan_objmgr_pdev *pdev, uint8_t oper_ch, uint8_t sec_ch, 127 enum phy_ch_width bw); 128 129 /** 130 * reg_set_channel_params () - Sets channel parameteres for given bandwidth 131 * @pdev: Pointer to pdev 132 * @ch: channel number. 133 * @sec_ch_2g: Secondary 2G channel 134 * @ch_params: pointer to the channel parameters. 135 * 136 * Return: None 137 */ 138 void reg_set_channel_params(struct wlan_objmgr_pdev *pdev, 139 uint8_t ch, uint8_t sec_ch_2g, 140 struct ch_params *ch_params); 141 142 /** 143 * reg_read_default_country() - Get the default regulatory country 144 * @psoc: The physical SoC to get default country from 145 * @country_code: the buffer to populate the country code into 146 * 147 * Return: QDF_STATUS 148 */ 149 QDF_STATUS reg_read_default_country(struct wlan_objmgr_psoc *psoc, 150 uint8_t *country_code); 151 152 /** 153 * reg_get_current_dfs_region () - Get the current dfs region 154 * @pdev: Pointer to pdev 155 * @dfs_reg: pointer to dfs region 156 * 157 * Return: None 158 */ 159 void reg_get_current_dfs_region(struct wlan_objmgr_pdev *pdev, 160 enum dfs_reg *dfs_reg); 161 162 /** 163 * reg_get_channel_reg_power() - Get the txpower for the given channel 164 * @pdev: Pointer to pdev 165 * @chan_num: Channel number 166 * 167 * Return: txpower 168 */ 169 uint32_t reg_get_channel_reg_power(struct wlan_objmgr_pdev *pdev, 170 uint32_t chan_num); 171 172 /** 173 * reg_get_channel_freq() - Get the channel frequency 174 * @pdev: Pointer to pdev 175 * @chan_num: Channel number 176 * 177 * Return: frequency 178 */ 179 uint32_t reg_get_channel_freq(struct wlan_objmgr_pdev *pdev, 180 uint32_t chan_num); 181 182 /** 183 * reg_get_bw_value() - give bandwidth value 184 * bw: bandwidth enum 185 * 186 * Return: uint16_t 187 */ 188 uint16_t reg_get_bw_value(enum phy_ch_width bw); 189 190 /** 191 * reg_set_dfs_region () - Set the current dfs region 192 * @pdev: Pointer to pdev 193 * @dfs_reg: pointer to dfs region 194 * 195 * Return: None 196 */ 197 void reg_set_dfs_region(struct wlan_objmgr_pdev *pdev, 198 enum dfs_reg dfs_reg); 199 200 /** 201 * reg_chan_to_band() - Get band from channel number 202 * @chan_num: channel number 203 * 204 * Return: band info 205 */ 206 enum band_info reg_chan_to_band(uint32_t chan_num); 207 208 /** 209 * reg_program_chan_list() - Set user country code and populate the channel list 210 * @pdev: Pointer to pdev 211 * @rd: Pointer to cc_regdmn_s structure 212 * 213 * Return: QDF_STATUS 214 */ 215 QDF_STATUS reg_program_chan_list(struct wlan_objmgr_pdev *pdev, 216 struct cc_regdmn_s *rd); 217 218 /** 219 * reg_update_nol_ch () - Updates NOL channels in current channel list 220 * @pdev: pointer to pdev object 221 * @ch_list: pointer to NOL channel list 222 * @num_ch: No.of channels in list 223 * @update_nol: set/reset the NOL status 224 * 225 * Return: None 226 */ 227 void reg_update_nol_ch(struct wlan_objmgr_pdev *pdev, uint8_t *chan_list, 228 uint8_t num_chan, bool nol_chan); 229 230 /** 231 * reg_is_dfs_ch () - Checks the channel state for DFS 232 * @pdev: pdev ptr 233 * @chan: channel 234 * 235 * Return: true or false 236 */ 237 bool reg_is_dfs_ch(struct wlan_objmgr_pdev *pdev, uint32_t chan); 238 239 /** 240 * reg_freq_to_chan() - Get channel number from frequency. 241 * @pdev: Pointer to pdev 242 * @freq: Channel frequency 243 * 244 * Return: Channel number 245 */ 246 uint32_t reg_freq_to_chan(struct wlan_objmgr_pdev *pdev, uint32_t freq); 247 248 /** 249 * reg_chan_to_freq() - Get frequency from channel number 250 * @pdev: Pointer to pdev 251 * @chan_num: Channel number 252 * 253 * Return: Channel frequency 254 */ 255 uint32_t reg_chan_to_freq(struct wlan_objmgr_pdev *pdev, uint32_t chan_num); 256 257 /** 258 * reg_chan_is_49ghz() - Check if the input channel number is 4.9GHz 259 * @pdev: Pdev pointer 260 * @chan_num: Input channel number 261 * 262 * Return: true if the channel is 4.9GHz else false. 263 */ 264 bool reg_chan_is_49ghz(struct wlan_objmgr_pdev *pdev, uint8_t chan_num); 265 266 /** 267 * reg_program_default_cc() - Program default country code 268 * @pdev: Pdev pointer 269 * @regdmn: Regdomain value 270 * 271 * Return: QDF_STATUS 272 */ 273 QDF_STATUS reg_program_default_cc(struct wlan_objmgr_pdev *pdev, 274 uint16_t regdmn); 275 276 /** 277 * reg_get_current_cc() - Get current country code 278 * @pdev: Pdev pointer 279 * @regdmn: Pointer to get current country values 280 * 281 * Return: QDF_STATUS 282 */ 283 QDF_STATUS reg_get_current_cc(struct wlan_objmgr_pdev *pdev, 284 struct cc_regdmn_s *rd); 285 286 /** 287 * reg_get_curr_band() - Get current band 288 * @pdev: Pdev pointer 289 * @band: Pointer to save the current band 290 * 291 * Return: QDF_STATUS 292 */ 293 QDF_STATUS reg_get_curr_band(struct wlan_objmgr_pdev *pdev, 294 enum band_info *band); 295 296 /** 297 * reg_set_regdb_offloaded() - set/clear regulatory offloaded flag 298 * 299 * @psoc: psoc pointer 300 * Return: Success or Failure 301 */ 302 QDF_STATUS reg_set_regdb_offloaded(struct wlan_objmgr_psoc *psoc, bool val); 303 304 /** 305 * reg_get_curr_regdomain() - Get current regdomain in use 306 * @pdev: pdev pointer 307 * @cur_regdmn: Current regdomain info 308 * 309 * Return: QDF status 310 */ 311 QDF_STATUS reg_get_curr_regdomain(struct wlan_objmgr_pdev *pdev, 312 struct cur_regdmn_info *cur_regdmn); 313 314 /** 315 * reg_modify_chan_144() - Enable/Disable channel 144 316 * @pdev: pdev pointer 317 * @en_chan_144: flag to disable/enable channel 144 318 * 319 * Return: Success or Failure 320 */ 321 QDF_STATUS reg_modify_chan_144(struct wlan_objmgr_pdev *pdev, bool en_chan_144); 322 323 /** 324 * reg_get_en_chan_144() - get en_chan_144 flag value 325 * @pdev: pdev pointer 326 * 327 * Return: en_chan_144 flag value 328 */ 329 bool reg_get_en_chan_144(struct wlan_objmgr_pdev *pdev); 330 331 /** 332 * reg_get_hal_reg_cap() - Get HAL REG capabilities 333 * @psoc: psoc for country information 334 * 335 * Return: hal reg cap pointer 336 */ 337 struct wlan_psoc_host_hal_reg_capabilities_ext *reg_get_hal_reg_cap( 338 struct wlan_objmgr_psoc *psoc); 339 340 /** 341 * reg_set_hal_reg_cap() - Set HAL REG capabilities 342 * @psoc: psoc for country information 343 * @reg_cap: Regulatory caps pointer 344 * @phy_cnt: number of phy 345 * 346 * Return: hal reg cap pointer 347 */ 348 QDF_STATUS reg_set_hal_reg_cap( 349 struct wlan_objmgr_psoc *psoc, 350 struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap, 351 uint16_t phy_cnt); 352 353 /** 354 * reg_chan_in_range() - Check if the given channel is in pdev's channel range 355 * @chan_list: Pointer to regulatory channel list. 356 * @low_freq_2g: Low frequency 2G. 357 * @high_freq_2g: High frequency 2G. 358 * @low_freq_5g: Low frequency 5G. 359 * @high_freq_5g: High frequency 5G. 360 * @ch_enum: Channel enum. 361 * 362 * Return: true if ch_enum is with in pdev's channel range, else false. 363 */ 364 bool reg_chan_in_range(struct regulatory_channel *chan_list, 365 uint32_t low_freq_2g, uint32_t high_freq_2g, 366 uint32_t low_freq_5g, uint32_t high_freq_5g, 367 enum channel_enum ch_enum); 368 369 /** 370 * reg_init_channel_map() - Initialize the channel list based on the dfs region. 371 * @dfs_region: Dfs region 372 */ 373 void reg_init_channel_map(enum dfs_reg dfs_region); 374 375 /** 376 * reg_get_psoc_tx_ops() - Get regdb tx ops 377 * @psoc: Pointer to psoc structure 378 */ 379 struct wlan_lmac_if_reg_tx_ops *reg_get_psoc_tx_ops( 380 struct wlan_objmgr_psoc *psoc); 381 382 /** 383 * reg_update_nol_history_ch() - Set nol-history flag for the channels in the 384 * list. 385 * @pdev: Pdev ptr. 386 * @ch_list: Input channel list. 387 * @num_ch: Number of channels. 388 * @nol_history_ch: NOL-History flag. 389 * 390 * Return: void 391 */ 392 void reg_update_nol_history_ch(struct wlan_objmgr_pdev *pdev, 393 uint8_t *chan_list, 394 uint8_t num_chan, 395 bool nol_history_chan); 396 397 /** 398 * reg_is_24ghz_ch() - Check if the given channel number is 2.4GHz 399 * @chan: Channel number 400 * 401 * Return: true if channel number is 2.4GHz, else false 402 */ 403 bool reg_is_24ghz_ch(uint32_t chan); 404 405 /** 406 * reg_is_5ghz_ch() - Check if the given channel number is 5GHz 407 * @chan: Channel number 408 * 409 * Return: true if channel number is 5GHz, else false 410 */ 411 bool reg_is_5ghz_ch(uint32_t chan); 412 413 /** 414 * reg_is_24ghz_ch_freq() - Check if the given channel frequency is 2.4GHz 415 * @freq: Channel frequency 416 * 417 * Return: true if channel frequency is 2.4GHz, else false 418 */ 419 bool reg_is_24ghz_ch_freq(uint32_t freq); 420 421 /** 422 * reg_is_5ghz_ch_freq() - Check if the given channel frequency is 5GHz 423 * @freq: Channel frequency 424 * 425 * Return: true if channel frequency is 5GHz, else false 426 */ 427 bool reg_is_5ghz_ch_freq(uint32_t chan); 428 429 #ifndef CONFIG_LEGACY_CHAN_ENUM 430 /** 431 * reg_is_49ghz_freq() - Check if the given channel frequency is 4.9GHz 432 * @freq: Channel frequency 433 * 434 * Return: true if channel frequency is 4.9GHz, else false 435 */ 436 bool reg_is_49ghz_freq(uint32_t freq); 437 #endif 438 439 /** 440 * reg_ch_num() - Get channel number from channel enum 441 * @ch_enum: Channel enum 442 * 443 * Return: channel number 444 */ 445 uint32_t reg_ch_num(uint32_t ch_enum); 446 447 /** 448 * reg_ch_to_freq() - Get channel frequency from channel enum 449 * @ch_enum: Channel enum 450 * 451 * Return: channel frequency 452 */ 453 uint32_t reg_ch_to_freq(uint32_t ch_enum); 454 455 /** 456 * reg_is_same_band_channels() - Check if given channel numbers have same band 457 * @chan_num1: Channel number1 458 * @chan_num2: Channel number2 459 * 460 * Return: true if both the channels has the same band. 461 */ 462 bool reg_is_same_band_channels(uint32_t chan_num1, uint32_t chan_num2); 463 464 /** 465 * reg_is_channel_valid_5g_sbs() Check if the given channel is 5G SBS. 466 * @curchan: current channel 467 * @newchan:new channel 468 * 469 * Return: true if the given channel is a valid 5G SBS 470 */ 471 bool reg_is_channel_valid_5g_sbs(uint32_t curchan, uint32_t newchan); 472 473 /** 474 * reg_min_24ghz_ch_num() - Get minimum 2.4GHz channel number 475 * 476 * Return: Minimum 2.4GHz channel number 477 */ 478 uint32_t reg_min_24ghz_ch_num(void); 479 480 /** 481 * reg_max_24ghz_ch_num() - Get maximum 2.4GHz channel number 482 * 483 * Return: Maximum 2.4GHz channel number 484 */ 485 uint32_t reg_max_24ghz_ch_num(void); 486 487 /** 488 * reg_min_5ghz_ch_num() - Get minimum 5GHz channel number 489 * 490 * Return: Minimum 5GHz channel number 491 */ 492 uint32_t reg_min_5ghz_ch_num(void); 493 494 /** 495 * reg_max_5ghz_ch_num() - Get maximum 5GHz channel number 496 * 497 * Return: Maximum 5GHz channel number 498 */ 499 uint32_t reg_max_5ghz_ch_num(void); 500 501 /** 502 * reg_enable_dfs_channels() - Enable the use of DFS channels 503 * @pdev: The physical dev to enable/disable DFS channels for 504 * 505 * Return: QDF_STATUS 506 */ 507 QDF_STATUS reg_enable_dfs_channels(struct wlan_objmgr_pdev *pdev, bool enable); 508 #endif 509