1 /* 2 * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved. 3 * Copyright (c) 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_priv_objs.c 22 * This file defines the APIs to create regulatory private PSOC and PDEV 23 * objects. 24 */ 25 26 #include <wlan_cmn.h> 27 #include <reg_services_public_struct.h> 28 #include <wlan_objmgr_psoc_obj.h> 29 #include <wlan_objmgr_pdev_obj.h> 30 #include <qdf_lock.h> 31 #include "reg_priv_objs.h" 32 #include "reg_utils.h" 33 #include "reg_services_common.h" 34 #include "reg_build_chan_list.h" 35 #include "reg_host_11d.h" 36 #include "reg_callbacks.h" 37 #ifdef CONFIG_AFC_SUPPORT 38 #include <cfg_ucfg_api.h> 39 #endif 40 41 struct wlan_regulatory_psoc_priv_obj *reg_get_psoc_obj( 42 struct wlan_objmgr_psoc *psoc) 43 { 44 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 45 46 if (!psoc) { 47 reg_alert("psoc is NULL"); 48 return NULL; 49 } 50 psoc_priv_obj = wlan_objmgr_psoc_get_comp_private_obj( 51 psoc, WLAN_UMAC_COMP_REGULATORY); 52 53 return psoc_priv_obj; 54 } 55 56 struct wlan_regulatory_pdev_priv_obj *reg_get_pdev_obj( 57 struct wlan_objmgr_pdev *pdev) 58 { 59 struct wlan_regulatory_pdev_priv_obj *pdev_reg; 60 61 if (!pdev) { 62 reg_alert("pdev is NULL"); 63 return NULL; 64 } 65 66 pdev_reg = wlan_objmgr_pdev_get_comp_private_obj( 67 pdev, WLAN_UMAC_COMP_REGULATORY); 68 69 return pdev_reg; 70 } 71 72 /* 73 * reg_set_5dot9_ghz_chan_in_master_mode - Set 5.9GHz channels to operate 74 * in master mode. 75 * @soc_reg_obj - Pointer to soc_reg_obj. 76 * 77 * Return: void 78 * 79 */ 80 #ifdef CONFIG_REG_CLIENT 81 static void 82 reg_set_5dot9_ghz_chan_in_master_mode(struct wlan_regulatory_psoc_priv_obj 83 *soc_reg_obj) 84 { 85 soc_reg_obj->enable_5dot9_ghz_chan_in_master_mode = false; 86 } 87 #else 88 static void 89 reg_set_5dot9_ghz_chan_in_master_mode(struct wlan_regulatory_psoc_priv_obj 90 *soc_reg_obj) 91 { 92 soc_reg_obj->enable_5dot9_ghz_chan_in_master_mode = true; 93 } 94 #endif 95 96 QDF_STATUS wlan_regulatory_psoc_obj_created_notification( 97 struct wlan_objmgr_psoc *psoc, void *arg_list) 98 { 99 struct wlan_regulatory_psoc_priv_obj *soc_reg_obj; 100 struct regulatory_channel *mas_chan_list; 101 enum channel_enum chan_enum; 102 QDF_STATUS status; 103 uint8_t i; 104 uint8_t phy_cnt; 105 106 soc_reg_obj = qdf_mem_malloc(sizeof(*soc_reg_obj)); 107 if (!soc_reg_obj) 108 return QDF_STATUS_E_NOMEM; 109 110 soc_reg_obj->offload_enabled = false; 111 soc_reg_obj->psoc_ptr = psoc; 112 soc_reg_obj->dfs_enabled = true; 113 soc_reg_obj->band_capability = (BIT(REG_BAND_2G) | BIT(REG_BAND_5G) | 114 BIT(REG_BAND_6G)); 115 soc_reg_obj->enable_11d_supp = false; 116 soc_reg_obj->indoor_chan_enabled = true; 117 soc_reg_obj->force_ssc_disable_indoor_channel = false; 118 soc_reg_obj->master_vdev_cnt = 0; 119 soc_reg_obj->vdev_cnt_11d = 0; 120 soc_reg_obj->vdev_id_for_11d_scan = INVALID_VDEV_ID; 121 soc_reg_obj->restart_beaconing = CH_AVOID_RULE_RESTART; 122 soc_reg_obj->enable_srd_chan_in_master_mode = 0xFF; 123 soc_reg_obj->enable_11d_in_world_mode = false; 124 soc_reg_obj->five_dot_nine_ghz_supported = false; 125 reg_set_5dot9_ghz_chan_in_master_mode(soc_reg_obj); 126 soc_reg_obj->retain_nol_across_regdmn_update = false; 127 soc_reg_obj->is_ext_tpc_supported = false; 128 soc_reg_obj->sta_sap_scc_on_indoor_channel = true; 129 soc_reg_obj->set_fcc_channel = false; 130 131 for (i = 0; i < MAX_STA_VDEV_CNT; i++) 132 soc_reg_obj->vdev_ids_11d[i] = INVALID_VDEV_ID; 133 134 qdf_spinlock_create(&soc_reg_obj->cbk_list_lock); 135 136 for (phy_cnt = 0; phy_cnt < PSOC_MAX_PHY_REG_CAP; phy_cnt++) { 137 mas_chan_list = 138 soc_reg_obj->mas_chan_params[phy_cnt].mas_chan_list; 139 soc_reg_obj->chan_list_recvd[phy_cnt] = false; 140 141 for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) { 142 mas_chan_list[chan_enum].chan_flags |= 143 REGULATORY_CHAN_DISABLED; 144 mas_chan_list[chan_enum].state = CHANNEL_STATE_DISABLE; 145 mas_chan_list[chan_enum].nol_chan = false; 146 } 147 } 148 149 status = wlan_objmgr_psoc_component_obj_attach( 150 psoc, WLAN_UMAC_COMP_REGULATORY, soc_reg_obj, 151 QDF_STATUS_SUCCESS); 152 if (QDF_IS_STATUS_ERROR(status)) { 153 qdf_spinlock_destroy(&soc_reg_obj->cbk_list_lock); 154 qdf_mem_free(soc_reg_obj); 155 reg_err("Obj attach failed"); 156 return status; 157 } 158 159 reg_debug("reg psoc obj created with status %d", status); 160 161 return status; 162 } 163 164 QDF_STATUS wlan_regulatory_psoc_obj_destroyed_notification( 165 struct wlan_objmgr_psoc *psoc, void *arg_list) 166 { 167 QDF_STATUS status; 168 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 169 170 psoc_priv_obj = reg_get_psoc_obj(psoc); 171 if (!psoc_priv_obj) { 172 reg_err_rl("NULL reg psoc priv obj"); 173 return QDF_STATUS_E_FAULT; 174 } 175 176 psoc_priv_obj->psoc_ptr = NULL; 177 qdf_spinlock_destroy(&psoc_priv_obj->cbk_list_lock); 178 179 status = wlan_objmgr_psoc_component_obj_detach( 180 psoc, WLAN_UMAC_COMP_REGULATORY, psoc_priv_obj); 181 182 if (status != QDF_STATUS_SUCCESS) 183 reg_err_rl("psoc_priv_obj private obj detach failed"); 184 185 reg_debug("reg psoc obj detached"); 186 187 qdf_mem_free(psoc_priv_obj); 188 189 return status; 190 } 191 192 #ifdef DISABLE_UNII_SHARED_BANDS 193 /** 194 * reg_reset_unii_5g_bitmap() - Reset the value of unii_5g_bitmap. 195 * @pdev_priv_obj: pointer to wlan_regulatory_pdev_priv_obj. 196 * 197 * Return : void 198 */ 199 static void 200 reg_reset_unii_5g_bitmap(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 201 { 202 pdev_priv_obj->unii_5g_bitmap = 0x0; 203 } 204 #else 205 static void inline 206 reg_reset_unii_5g_bitmap(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 207 { 208 } 209 #endif 210 211 #if defined(CONFIG_BAND_6GHZ) 212 #if defined(CONFIG_REG_CLIENT) 213 /** 214 * reg_init_def_client_type() - Initialize the regulatory 6G client type. 215 * 216 * @pdev_priv_obj: pointer to wlan_regulatory_pdev_priv_obj. 217 * 218 * Return : void 219 */ 220 static void 221 reg_init_def_client_type(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 222 { 223 pdev_priv_obj->reg_cur_6g_client_mobility_type = REG_DEFAULT_CLIENT; 224 } 225 #else 226 static void 227 reg_init_def_client_type(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 228 { 229 pdev_priv_obj->reg_cur_6g_client_mobility_type = REG_SUBORDINATE_CLIENT; 230 } 231 #endif 232 233 /** 234 * reg_init_6g_vars() - Initialize the regulatory 6G variables viz. 235 * AP power type, client mobility type, rnr tpe usable and unspecified ap 236 * usable. 237 * @pdev_priv_obj: pointer to wlan_regulatory_pdev_priv_obj. 238 * 239 * Return : void 240 */ 241 static void 242 reg_init_6g_vars(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 243 { 244 reg_set_ap_pwr_type(pdev_priv_obj); 245 pdev_priv_obj->reg_rnr_tpe_usable = false; 246 pdev_priv_obj->reg_unspecified_ap_usable = false; 247 reg_init_def_client_type(pdev_priv_obj); 248 } 249 #else 250 static void 251 reg_init_6g_vars(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 252 { 253 } 254 #endif 255 256 #ifdef CONFIG_AFC_SUPPORT 257 static void 258 reg_create_afc_cb_spinlock(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 259 { 260 qdf_spinlock_create(&pdev_priv_obj->afc_cb_lock); 261 } 262 263 static void 264 reg_destroy_afc_cb_spinlock(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 265 { 266 qdf_spinlock_destroy(&pdev_priv_obj->afc_cb_lock); 267 } 268 269 static void 270 reg_init_afc_vars(struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj, 271 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 272 { 273 pdev_priv_obj->is_reg_noaction_on_afc_pwr_evt = 274 psoc_priv_obj->is_afc_reg_noaction; 275 } 276 277 static inline void 278 reg_set_pdev_afc_dev_type(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 279 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj) 280 { 281 pdev_priv_obj->reg_afc_dev_deployment_type = 282 psoc_priv_obj->reg_afc_dev_type; 283 } 284 #else 285 static inline void 286 reg_create_afc_cb_spinlock(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 287 { 288 } 289 290 static inline void 291 reg_destroy_afc_cb_spinlock(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 292 { 293 } 294 295 static void 296 reg_init_afc_vars(struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj, 297 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 298 { 299 } 300 301 static inline void 302 reg_set_pdev_afc_dev_type(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj, 303 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj) 304 { 305 } 306 #endif 307 308 QDF_STATUS wlan_regulatory_pdev_obj_created_notification( 309 struct wlan_objmgr_pdev *pdev, void *arg_list) 310 { 311 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 312 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 313 struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap_ptr; 314 struct wlan_objmgr_psoc *parent_psoc; 315 uint8_t pdev_id; 316 uint8_t phy_id; 317 uint32_t cnt; 318 uint32_t range_2g_low, range_2g_high; 319 uint32_t range_5g_low, range_5g_high; 320 QDF_STATUS status; 321 struct reg_rule_info *psoc_reg_rules; 322 struct wlan_lmac_if_reg_tx_ops *tx_ops; 323 324 pdev_priv_obj = qdf_mem_malloc(sizeof(*pdev_priv_obj)); 325 if (!pdev_priv_obj) 326 return QDF_STATUS_E_NOMEM; 327 328 parent_psoc = wlan_pdev_get_psoc(pdev); 329 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 330 tx_ops = reg_get_psoc_tx_ops(parent_psoc); 331 332 if (tx_ops->get_phy_id_from_pdev_id) 333 tx_ops->get_phy_id_from_pdev_id(parent_psoc, pdev_id, &phy_id); 334 else 335 phy_id = pdev_id; 336 337 psoc_priv_obj = reg_get_psoc_obj(parent_psoc); 338 if (!psoc_priv_obj) { 339 reg_err("reg psoc private obj is NULL"); 340 qdf_mem_free(pdev_priv_obj); 341 return QDF_STATUS_E_FAULT; 342 } 343 344 pdev_priv_obj->pdev_ptr = pdev; 345 pdev_priv_obj->dfs_enabled = psoc_priv_obj->dfs_enabled; 346 pdev_priv_obj->set_fcc_channel = psoc_priv_obj->set_fcc_channel; 347 pdev_priv_obj->band_capability = psoc_priv_obj->band_capability; 348 pdev_priv_obj->indoor_chan_enabled = 349 psoc_priv_obj->indoor_chan_enabled; 350 351 reg_set_pdev_afc_dev_type(pdev_priv_obj, psoc_priv_obj); 352 353 pdev_priv_obj->en_chan_144 = true; 354 reg_reset_unii_5g_bitmap(pdev_priv_obj); 355 356 qdf_spinlock_create(&pdev_priv_obj->reg_rules_lock); 357 reg_create_afc_cb_spinlock(pdev_priv_obj); 358 359 reg_cap_ptr = psoc_priv_obj->reg_cap; 360 pdev_priv_obj->force_ssc_disable_indoor_channel = 361 psoc_priv_obj->force_ssc_disable_indoor_channel; 362 pdev_priv_obj->sta_sap_scc_on_indoor_channel = 363 psoc_priv_obj->sta_sap_scc_on_indoor_channel; 364 365 for (cnt = 0; cnt < PSOC_MAX_PHY_REG_CAP; cnt++) { 366 if (!reg_cap_ptr) { 367 qdf_mem_free(pdev_priv_obj); 368 reg_err("reg cap ptr is NULL"); 369 return QDF_STATUS_E_FAULT; 370 } 371 372 if (reg_cap_ptr->phy_id == phy_id) 373 break; 374 reg_cap_ptr++; 375 } 376 377 if (cnt == PSOC_MAX_PHY_REG_CAP) { 378 qdf_mem_free(pdev_priv_obj); 379 reg_err("extended capabilities not found for pdev"); 380 return QDF_STATUS_E_FAULT; 381 } 382 383 range_2g_low = reg_cap_ptr->low_2ghz_chan; 384 range_2g_high = reg_cap_ptr->high_2ghz_chan; 385 range_5g_low = reg_cap_ptr->low_5ghz_chan; 386 range_5g_high = reg_cap_ptr->high_5ghz_chan; 387 388 pdev_priv_obj->range_2g_low = range_2g_low; 389 pdev_priv_obj->range_2g_high = range_2g_high; 390 pdev_priv_obj->range_5g_low = range_5g_low; 391 pdev_priv_obj->range_5g_high = range_5g_high; 392 pdev_priv_obj->wireless_modes = reg_cap_ptr->wireless_modes; 393 reg_init_6g_vars(pdev_priv_obj); 394 395 reg_init_pdev_mas_chan_list(pdev_priv_obj, 396 &psoc_priv_obj->mas_chan_params[phy_id]); 397 398 psoc_reg_rules = &psoc_priv_obj->mas_chan_params[phy_id].reg_rules; 399 reg_save_reg_rules_to_pdev(psoc_reg_rules, pdev_priv_obj); 400 pdev_priv_obj->chan_list_recvd = 401 psoc_priv_obj->chan_list_recvd[phy_id]; 402 403 reg_init_indoor_channel_list(pdev); 404 405 status = wlan_objmgr_pdev_component_obj_attach( 406 pdev, WLAN_UMAC_COMP_REGULATORY, pdev_priv_obj, 407 QDF_STATUS_SUCCESS); 408 if (QDF_IS_STATUS_ERROR(status)) { 409 reg_err("Obj attach failed"); 410 qdf_mem_free(pdev_priv_obj); 411 return status; 412 } 413 414 reg_compute_pdev_current_chan_list(pdev_priv_obj); 415 416 reg_init_afc_vars(psoc_priv_obj, pdev_priv_obj); 417 418 if (!psoc_priv_obj->is_11d_offloaded) 419 reg_11d_host_scan_init(parent_psoc); 420 421 reg_debug("reg pdev obj created with status %d", status); 422 423 return status; 424 } 425 426 #ifdef CONFIG_AFC_SUPPORT 427 /** 428 * reg_free_chan_obj() - Free the AFC chan object and chan eirp object 429 * information 430 * @afc_chan_info: Pointer to afc_chan_info 431 * 432 * Return: void 433 */ 434 static void reg_free_chan_obj(struct afc_chan_obj *afc_chan_info) 435 { 436 if (afc_chan_info->chan_eirp_info) 437 qdf_mem_free(afc_chan_info->chan_eirp_info); 438 } 439 440 /** 441 * reg_free_afc_pwr_info() - Free the AFC power information object 442 * @pdev_priv_obj: Pointer to pdev_priv_obj 443 * 444 * Return: void 445 */ 446 void 447 reg_free_afc_pwr_info(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 448 { 449 struct reg_fw_afc_power_event *power_info; 450 uint8_t i; 451 452 power_info = pdev_priv_obj->power_info; 453 if (!power_info) 454 return; 455 456 if (power_info->afc_freq_info) 457 qdf_mem_free(power_info->afc_freq_info); 458 459 if (!power_info->afc_chan_info) 460 return; 461 462 for (i = 0; i < power_info->num_chan_objs; i++) 463 reg_free_chan_obj(&power_info->afc_chan_info[i]); 464 465 if (power_info->afc_chan_info) 466 qdf_mem_free(power_info->afc_chan_info); 467 468 qdf_mem_free(power_info); 469 } 470 #endif 471 472 QDF_STATUS wlan_regulatory_pdev_obj_destroyed_notification( 473 struct wlan_objmgr_pdev *pdev, void *arg_list) 474 { 475 QDF_STATUS status; 476 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 477 struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj; 478 uint32_t pdev_id; 479 480 pdev_priv_obj = reg_get_pdev_obj(pdev); 481 482 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 483 484 if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) { 485 reg_err("reg pdev private obj is NULL"); 486 return QDF_STATUS_E_FAILURE; 487 } 488 489 psoc_priv_obj = reg_get_psoc_obj(wlan_pdev_get_psoc(pdev)); 490 if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) { 491 reg_err("reg psoc private obj is NULL"); 492 return QDF_STATUS_E_FAILURE; 493 } 494 495 if (!psoc_priv_obj->is_11d_offloaded) 496 reg_11d_host_scan_deinit(wlan_pdev_get_psoc(pdev)); 497 498 reg_free_afc_pwr_info(pdev_priv_obj); 499 pdev_priv_obj->pdev_ptr = NULL; 500 501 status = wlan_objmgr_pdev_component_obj_detach( 502 pdev, WLAN_UMAC_COMP_REGULATORY, pdev_priv_obj); 503 504 if (status != QDF_STATUS_SUCCESS) 505 reg_err("reg pdev private obj detach failed"); 506 507 reg_debug("reg pdev obj deleted"); 508 509 qdf_spin_lock_bh(&pdev_priv_obj->reg_rules_lock); 510 reg_reset_reg_rules(&pdev_priv_obj->reg_rules); 511 qdf_spin_unlock_bh(&pdev_priv_obj->reg_rules_lock); 512 513 reg_destroy_afc_cb_spinlock(pdev_priv_obj); 514 qdf_spinlock_destroy(&pdev_priv_obj->reg_rules_lock); 515 516 qdf_mem_free(pdev_priv_obj); 517 518 return status; 519 } 520