1 /* 2 * Copyright (c) 2017-2018 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 /** 19 * DOC: service_ready_util.c 20 * 21 * Public APIs implementation source file for accessing (ext)service ready 22 * data from psoc object 23 */ 24 #include "service_ready_util.h" 25 #include <wlan_reg_ucfg_api.h> 26 #include <target_type.h> 27 #include <qdf_module.h> 28 29 QDF_STATUS init_deinit_chainmask_table_alloc( 30 struct wlan_psoc_host_service_ext_param *ser_ext_par) 31 { 32 int i; 33 uint32_t alloc_size; 34 QDF_STATUS status; 35 36 if (ser_ext_par->num_chainmask_tables > 0) { 37 status = QDF_STATUS_SUCCESS; 38 for (i = 0; i < ser_ext_par->num_chainmask_tables; i++) { 39 alloc_size = 40 (sizeof(struct wlan_psoc_host_chainmask_capabilities) * 41 ser_ext_par->chainmask_table[i].num_valid_chainmasks); 42 43 ser_ext_par->chainmask_table[i].cap_list = 44 qdf_mem_alloc_outline(NULL, alloc_size); 45 if (!ser_ext_par->chainmask_table[i].cap_list) { 46 init_deinit_chainmask_table_free(ser_ext_par); 47 status = QDF_STATUS_E_NOMEM; 48 break; 49 } 50 } 51 } else { 52 status = QDF_STATUS_E_NOSUPPORT; 53 } 54 55 return status; 56 } 57 58 qdf_export_symbol(init_deinit_chainmask_table_alloc); 59 60 QDF_STATUS init_deinit_chainmask_table_free( 61 struct wlan_psoc_host_service_ext_param *ser_ext_par) 62 { 63 struct wlan_psoc_host_chainmask_table *table; 64 int i; 65 66 for (i = 0; i < ser_ext_par->num_chainmask_tables; i++) { 67 table = &(ser_ext_par->chainmask_table[i]); 68 if (table->cap_list) { 69 qdf_mem_free(table->cap_list); 70 table->cap_list = NULL; 71 } 72 } 73 74 return QDF_STATUS_SUCCESS; 75 } 76 77 qdf_export_symbol(init_deinit_chainmask_table_free); 78 79 int init_deinit_populate_service_bitmap(void *wmi_handle, uint8_t *event, 80 uint32_t *service_bitmap) 81 { 82 QDF_STATUS status; 83 84 status = wmi_save_service_bitmap(wmi_handle, event, service_bitmap); 85 if (QDF_IS_STATUS_ERROR(status)) { 86 target_if_err("failed to parse service bitmap"); 87 return qdf_status_to_os_return(status); 88 } 89 90 return 0; 91 } 92 93 int init_deinit_populate_fw_version_cmd(void *wmi_handle, uint8_t *event) 94 { 95 QDF_STATUS status; 96 97 status = wmi_unified_save_fw_version_cmd(wmi_handle, event); 98 if (QDF_IS_STATUS_ERROR(status)) 99 target_if_err("failed to save fw version"); 100 101 return 0; 102 } 103 104 int init_deinit_populate_target_cap(void *wmi_handle, uint8_t *event, 105 struct wlan_psoc_target_capability_info *cap) 106 { 107 QDF_STATUS status; 108 109 status = wmi_get_target_cap_from_service_ready(wmi_handle, event, cap); 110 if (QDF_IS_STATUS_ERROR(status)) { 111 target_if_err("failed to parse target cap"); 112 return qdf_status_to_os_return(status); 113 } 114 115 return 0; 116 } 117 118 int init_deinit_populate_service_ready_ext_param(void *handle, uint8_t *evt, 119 struct wlan_psoc_host_service_ext_param *param) 120 { 121 QDF_STATUS status; 122 123 status = wmi_extract_service_ready_ext(handle, evt, param); 124 if (QDF_IS_STATUS_ERROR(status)) { 125 target_if_err("failed to parse wmi service ready ext param"); 126 return qdf_status_to_os_return(status); 127 } 128 129 return 0; 130 } 131 132 int init_deinit_populate_chainmask_tables(void *handle, uint8_t *evt, 133 struct wlan_psoc_host_chainmask_table *param) 134 { 135 QDF_STATUS status; 136 137 status = wmi_extract_chainmask_tables(handle, evt, param); 138 if (QDF_IS_STATUS_ERROR(status)) { 139 target_if_err("failed to parse wmi service ready ext param"); 140 return qdf_status_to_os_return(status); 141 } 142 143 return 0; 144 } 145 146 int init_deinit_populate_mac_phy_capability(void *handle, uint8_t *evt, 147 struct wlan_psoc_host_hw_mode_caps *hw_cap, struct tgt_info *info) 148 { 149 QDF_STATUS status; 150 uint32_t hw_mode_id; 151 uint32_t phy_bit_map; 152 uint8_t mac_phy_id; 153 154 hw_mode_id = hw_cap->hw_mode_id; 155 phy_bit_map = hw_cap->phy_id_map; 156 target_if_info("hw_mode_id %d phy_bit_map 0x%x", 157 hw_mode_id, phy_bit_map); 158 159 mac_phy_id = 0; 160 while (phy_bit_map) { 161 if (info->total_mac_phy_cnt >= PSOC_MAX_MAC_PHY_CAP) { 162 target_if_err("total mac phy exceeds max limit %d", 163 info->total_mac_phy_cnt); 164 return -EINVAL; 165 } 166 167 status = wmi_extract_mac_phy_cap_service_ready_ext(handle, 168 evt, hw_mode_id, mac_phy_id, 169 &(info->mac_phy_cap[info->total_mac_phy_cnt])); 170 if (QDF_IS_STATUS_ERROR(status)) { 171 target_if_err("failed to parse mac phy capability"); 172 return qdf_status_to_os_return(status); 173 } 174 info->mac_phy_cap[info->total_mac_phy_cnt].hw_mode_config_type 175 = hw_cap->hw_mode_config_type; 176 info->total_mac_phy_cnt++; 177 phy_bit_map &= (phy_bit_map - 1); 178 mac_phy_id++; 179 } 180 target_if_info("total_mac_phy_cnt %d", info->total_mac_phy_cnt); 181 182 return 0; 183 } 184 185 static int get_hw_mode(void *handle, uint8_t *evt, uint8_t hw_idx, 186 struct wlan_psoc_host_hw_mode_caps *cap) 187 { 188 QDF_STATUS status; 189 190 status = wmi_extract_hw_mode_cap_service_ready_ext(handle, evt, 191 hw_idx, cap); 192 if (QDF_IS_STATUS_ERROR(status)) { 193 target_if_err("failed to parse hw mode capability"); 194 return qdf_status_to_os_return(status); 195 } 196 197 return 0; 198 } 199 200 int init_deinit_populate_hw_mode_capability(void *wmi_handle, 201 uint8_t *event, struct target_psoc_info *tgt_hdl) 202 { 203 QDF_STATUS status = QDF_STATUS_SUCCESS; 204 uint8_t hw_idx; 205 uint32_t num_hw_modes; 206 struct wlan_psoc_host_hw_mode_caps hw_mode_caps[PSOC_MAX_HW_MODE]; 207 uint32_t preferred_mode; 208 struct tgt_info *info; 209 210 info = &tgt_hdl->info; 211 num_hw_modes = info->service_ext_param.num_hw_modes; 212 if (num_hw_modes > PSOC_MAX_HW_MODE) { 213 target_if_err("invalid num_hw_modes %d", num_hw_modes); 214 return -EINVAL; 215 } 216 target_if_info("num_hw_modes %d", num_hw_modes); 217 218 qdf_mem_zero(&hw_mode_caps, sizeof(hw_mode_caps)); 219 220 preferred_mode = target_psoc_get_preferred_hw_mode(tgt_hdl); 221 for (hw_idx = 0; hw_idx < num_hw_modes; hw_idx++) { 222 status = get_hw_mode(wmi_handle, event, hw_idx, 223 &hw_mode_caps[hw_idx]); 224 if (status) 225 goto return_exit; 226 227 if ((preferred_mode != WMI_HOST_HW_MODE_MAX) && 228 (hw_mode_caps[hw_idx].hw_mode_id != preferred_mode)) 229 continue; 230 231 status = init_deinit_populate_mac_phy_capability(wmi_handle, 232 event, &hw_mode_caps[hw_idx], info); 233 if (status) 234 goto return_exit; 235 236 if ((preferred_mode != WMI_HOST_HW_MODE_MAX) && 237 (hw_mode_caps[hw_idx].hw_mode_id == preferred_mode)) { 238 info->num_radios = info->total_mac_phy_cnt; 239 target_if_info("num radios is %d\n", info->num_radios); 240 } 241 } 242 243 return_exit: 244 return qdf_status_to_os_return(status); 245 } 246 247 int init_deinit_populate_dbr_ring_cap(struct wlan_objmgr_psoc *psoc, 248 void *handle, uint8_t *event, struct tgt_info *info) 249 250 { 251 uint8_t cap_idx; 252 uint32_t num_dbr_ring_caps; 253 QDF_STATUS status = QDF_STATUS_SUCCESS; 254 255 num_dbr_ring_caps = info->service_ext_param.num_dbr_ring_caps; 256 257 target_if_info("Num DMA Capabilities = %d", num_dbr_ring_caps); 258 259 if (!num_dbr_ring_caps) 260 return 0; 261 262 info->dbr_ring_cap = qdf_mem_malloc( 263 sizeof(struct wlan_psoc_host_dbr_ring_caps) * 264 num_dbr_ring_caps); 265 266 if (!info->dbr_ring_cap) { 267 target_if_err("Mem alloc for DMA cap failed"); 268 return -EINVAL; 269 } 270 271 for (cap_idx = 0; cap_idx < num_dbr_ring_caps; cap_idx++) { 272 status = wmi_extract_dbr_ring_cap_service_ready_ext(handle, 273 event, cap_idx, 274 &(info->dbr_ring_cap[cap_idx])); 275 if (QDF_IS_STATUS_ERROR(status)) { 276 target_if_err("Extraction of DMA cap failed"); 277 goto free_and_return; 278 } 279 } 280 281 return 0; 282 283 free_and_return: 284 qdf_mem_free(info->dbr_ring_cap); 285 info->dbr_ring_cap = NULL; 286 287 return qdf_status_to_os_return(status); 288 } 289 290 int init_deinit_populate_phy_reg_cap(struct wlan_objmgr_psoc *psoc, 291 void *handle, uint8_t *event, 292 struct tgt_info *info, bool service_ready) 293 { 294 uint8_t reg_idx; 295 uint32_t num_phy_reg_cap; 296 QDF_STATUS status = QDF_STATUS_SUCCESS; 297 struct wlan_psoc_hal_reg_capability cap; 298 struct wlan_psoc_host_hal_reg_capabilities_ext 299 reg_cap[PSOC_MAX_PHY_REG_CAP]; 300 301 if (service_ready) { 302 status = wmi_extract_hal_reg_cap(handle, event, &cap); 303 if (QDF_IS_STATUS_ERROR(status)) { 304 target_if_err("failed to parse hal reg cap"); 305 return qdf_status_to_os_return(status); 306 } 307 info->service_ext_param.num_phy = 1; 308 num_phy_reg_cap = 1; 309 reg_cap[0].phy_id = 0; 310 qdf_mem_copy(&(reg_cap[0].eeprom_reg_domain), &cap, 311 sizeof(struct wlan_psoc_hal_reg_capability)); 312 target_if_info("FW wireless modes 0x%x", 313 reg_cap[0].wireless_modes); 314 } else { 315 num_phy_reg_cap = info->service_ext_param.num_phy; 316 if (num_phy_reg_cap > PSOC_MAX_PHY_REG_CAP) { 317 target_if_err("Invalid num_phy_reg_cap %d", 318 num_phy_reg_cap); 319 return -EINVAL; 320 } 321 target_if_info("num_phy_reg_cap %d", num_phy_reg_cap); 322 323 for (reg_idx = 0; reg_idx < num_phy_reg_cap; reg_idx++) { 324 status = wmi_extract_reg_cap_service_ready_ext(handle, 325 event, reg_idx, &(reg_cap[reg_idx])); 326 if (QDF_IS_STATUS_ERROR(status)) { 327 target_if_err("failed to parse reg cap"); 328 return qdf_status_to_os_return(status); 329 } 330 } 331 } 332 333 status = ucfg_reg_set_hal_reg_cap(psoc, reg_cap, num_phy_reg_cap); 334 335 return qdf_status_to_os_return(status); 336 } 337 338 static bool init_deinit_regdmn_160mhz_support( 339 struct wlan_psoc_host_hal_reg_capabilities_ext *hal_cap) 340 { 341 return ((hal_cap->wireless_modes & 342 WMI_HOST_REGDMN_MODE_11AC_VHT160) != 0); 343 } 344 345 static bool init_deinit_regdmn_80p80mhz_support( 346 struct wlan_psoc_host_hal_reg_capabilities_ext *hal_cap) 347 { 348 return ((hal_cap->wireless_modes & 349 WMI_HOST_REGDMN_MODE_11AC_VHT80_80) != 0); 350 } 351 352 static bool init_deinit_vht_160mhz_is_supported(uint32_t vhtcap) 353 { 354 return ((vhtcap & WLAN_VHTCAP_SUP_CHAN_WIDTH_160) != 0); 355 } 356 357 static bool init_deinit_vht_80p80mhz_is_supported(uint32_t vhtcap) 358 { 359 return ((vhtcap & WLAN_VHTCAP_SUP_CHAN_WIDTH_80_160) != 0); 360 } 361 362 static bool init_deinit_vht_160mhz_shortgi_is_supported(uint32_t vhtcap) 363 { 364 return ((vhtcap & WLAN_VHTCAP_SHORTGI_160) != 0); 365 } 366 367 QDF_STATUS init_deinit_validate_160_80p80_fw_caps( 368 struct wlan_objmgr_psoc *psoc, 369 struct target_psoc_info *tgt_hdl) 370 { 371 bool wireless_mode_160mhz = false; 372 bool wireless_mode_80p80mhz = false; 373 bool vhtcap_160mhz = false; 374 bool vhtcap_80p80_160mhz = false; 375 bool vhtcap_160mhz_sgi = false; 376 bool valid = false; 377 struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap; 378 void *wmi_handle; 379 380 if (!tgt_hdl) { 381 target_if_err( 382 "target_psoc_info is null in validate 160n80p80 cap check"); 383 return QDF_STATUS_E_INVAL; 384 } 385 386 wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl); 387 388 if ((tgt_hdl->info.target_type == TARGET_TYPE_QCA8074) || 389 (tgt_hdl->info.target_type == TARGET_TYPE_QCA6290)) { 390 /** 391 * Return true for now. This is not available in 392 * qca8074 fw yet 393 */ 394 return QDF_STATUS_SUCCESS; 395 } 396 397 reg_cap = ucfg_reg_get_hal_reg_cap(psoc); 398 if (reg_cap == NULL) { 399 target_if_err("reg cap is NULL"); 400 return QDF_STATUS_E_FAILURE; 401 } 402 403 /* NOTE: Host driver gets vht capability and supported channel 404 * width / channel frequency range from FW/HALPHY and obeys it. 405 * Host driver is unaware of any physical filters or any other 406 * hardware factors that can impact these capabilities. 407 * These need to be correctly determined by firmware. 408 */ 409 410 /*This table lists all valid and invalid combinations 411 * WMODE160 WMODE80_80 VHTCAP_160 VHTCAP_80+80_160 IsCombinationvalid? 412 * 0 0 0 0 YES 413 * 0 0 0 1 NO 414 * 0 0 1 0 NO 415 * 0 0 1 1 NO 416 * 0 1 0 0 NO 417 * 0 1 0 1 NO 418 * 0 1 1 0 NO 419 * 0 1 1 1 NO 420 * 1 0 0 0 NO 421 * 1 0 0 1 NO 422 * 1 0 1 0 YES 423 * 1 0 1 1 NO 424 * 1 1 0 0 NO 425 * 1 1 0 1 YES 426 * 1 1 1 0 NO 427 * 1 1 1 1 NO 428 */ 429 430 /* NOTE: Last row in above table is invalid because value corresponding 431 * to both VHTCAP_160 and VHTCAP_80+80_160 being set is reserved as per 432 * 802.11ac. Only one of them can be set at a time. 433 */ 434 435 wireless_mode_160mhz = init_deinit_regdmn_160mhz_support(reg_cap); 436 wireless_mode_80p80mhz = init_deinit_regdmn_80p80mhz_support(reg_cap); 437 vhtcap_160mhz = init_deinit_vht_160mhz_is_supported( 438 tgt_hdl->info.target_caps.vht_cap_info); 439 vhtcap_80p80_160mhz = init_deinit_vht_80p80mhz_is_supported( 440 tgt_hdl->info.target_caps.vht_cap_info); 441 vhtcap_160mhz_sgi = init_deinit_vht_160mhz_shortgi_is_supported( 442 tgt_hdl->info.target_caps.vht_cap_info); 443 444 if (!(wireless_mode_160mhz || wireless_mode_80p80mhz || 445 vhtcap_160mhz || vhtcap_80p80_160mhz)) { 446 valid = QDF_STATUS_SUCCESS; 447 } else if (wireless_mode_160mhz && !wireless_mode_80p80mhz && 448 vhtcap_160mhz && !vhtcap_80p80_160mhz) { 449 valid = QDF_STATUS_SUCCESS; 450 } else if (wireless_mode_160mhz && wireless_mode_80p80mhz && 451 !vhtcap_160mhz && vhtcap_160mhz_sgi) { 452 valid = QDF_STATUS_SUCCESS; 453 } 454 455 if (valid == QDF_STATUS_SUCCESS) { 456 /* 457 * Ensure short GI for 160 MHz is enabled 458 * only if 160/80+80 is supported. 459 */ 460 if (vhtcap_160mhz_sgi && 461 !(vhtcap_160mhz || vhtcap_80p80_160mhz)) { 462 valid = QDF_STATUS_E_FAILURE; 463 } 464 } 465 466 /* Invalid config specified by FW */ 467 if (valid != QDF_STATUS_SUCCESS) { 468 target_if_err("Invalid 160/80+80 MHz config specified by FW. Take care of it first"); 469 target_if_err("wireless_mode_160mhz: %d, wireless_mode_80p80mhz: %d", 470 wireless_mode_160mhz, wireless_mode_80p80mhz); 471 target_if_err("vhtcap_160mhz: %d, vhtcap_80p80_160mhz: %d,vhtcap_160mhz_sgi: %d", 472 vhtcap_160mhz, vhtcap_80p80_160mhz, 473 vhtcap_160mhz_sgi); 474 } 475 return valid; 476 } 477 478 void init_deinit_chainmask_config( 479 struct wlan_objmgr_psoc *psoc, 480 struct target_psoc_info *tgt_hdl) 481 { 482 tgt_hdl->info.wlan_res_cfg.tx_chain_mask = 483 ((1 << tgt_hdl->info.target_caps.num_rf_chains) - 1); 484 tgt_hdl->info.wlan_res_cfg.rx_chain_mask = 485 ((1 << tgt_hdl->info.target_caps.num_rf_chains) - 1); 486 } 487 488 QDF_STATUS init_deinit_is_service_ext_msg( 489 struct wlan_objmgr_psoc *psoc, 490 struct target_psoc_info *tgt_hdl) 491 { 492 void *wmi_handle; 493 494 if (!tgt_hdl) { 495 target_if_err( 496 "psoc target_psoc_info is null in service ext msg"); 497 return QDF_STATUS_E_INVAL; 498 } 499 500 wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl); 501 502 if (wmi_service_enabled(wmi_handle, wmi_service_ext_msg)) 503 return QDF_STATUS_SUCCESS; 504 else 505 return QDF_STATUS_E_FAILURE; 506 } 507 508 bool init_deinit_is_preferred_hw_mode_supported( 509 struct wlan_objmgr_psoc *psoc, 510 struct target_psoc_info *tgt_hdl) 511 { 512 uint16_t i; 513 struct tgt_info *info; 514 515 if (!tgt_hdl) { 516 target_if_err( 517 "psoc target_psoc_info is null in service ext msg"); 518 return FALSE; 519 } 520 521 info = &tgt_hdl->info; 522 523 if (info->preferred_hw_mode == WMI_HOST_HW_MODE_MAX) 524 return TRUE; 525 526 for (i = 0; i < target_psoc_get_total_mac_phy_cnt(tgt_hdl); i++) { 527 if (info->mac_phy_cap[i].hw_mode_id == info->preferred_hw_mode) 528 return TRUE; 529 } 530 531 return FALSE; 532 } 533 534 void init_deinit_wakeup_host_wait( 535 struct wlan_objmgr_psoc *psoc, 536 struct target_psoc_info *tgt_hdl) 537 { 538 if (!tgt_hdl) { 539 target_if_err("psoc target_psoc_info is null in target ready"); 540 return; 541 } 542 qdf_wake_up(&tgt_hdl->info.event_queue); 543 } 544