1 // SPDX-License-Identifier: BSD-3-Clause-Clear 2 /* 3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. 4 */ 5 #include <linux/skbuff.h> 6 #include <linux/ctype.h> 7 #include <net/mac80211.h> 8 #include <net/cfg80211.h> 9 #include <linux/completion.h> 10 #include <linux/if_ether.h> 11 #include <linux/types.h> 12 #include <linux/pci.h> 13 #include <linux/uuid.h> 14 #include <linux/time.h> 15 #include <linux/of.h> 16 #include "core.h" 17 #include "debug.h" 18 #include "mac.h" 19 #include "hw.h" 20 #include "peer.h" 21 22 struct wmi_tlv_policy { 23 size_t min_len; 24 }; 25 26 struct wmi_tlv_svc_ready_parse { 27 bool wmi_svc_bitmap_done; 28 }; 29 30 struct wmi_tlv_dma_ring_caps_parse { 31 struct wmi_dma_ring_capabilities *dma_ring_caps; 32 u32 n_dma_ring_caps; 33 }; 34 35 struct wmi_tlv_svc_rdy_ext_parse { 36 struct ath11k_service_ext_param param; 37 struct wmi_soc_mac_phy_hw_mode_caps *hw_caps; 38 struct wmi_hw_mode_capabilities *hw_mode_caps; 39 u32 n_hw_mode_caps; 40 u32 tot_phy_id; 41 struct wmi_hw_mode_capabilities pref_hw_mode_caps; 42 struct wmi_mac_phy_capabilities *mac_phy_caps; 43 u32 n_mac_phy_caps; 44 struct wmi_soc_hal_reg_capabilities *soc_hal_reg_caps; 45 struct wmi_hal_reg_capabilities_ext *ext_hal_reg_caps; 46 u32 n_ext_hal_reg_caps; 47 struct wmi_tlv_dma_ring_caps_parse dma_caps_parse; 48 bool hw_mode_done; 49 bool mac_phy_done; 50 bool ext_hal_reg_done; 51 bool mac_phy_chainmask_combo_done; 52 bool mac_phy_chainmask_cap_done; 53 bool oem_dma_ring_cap_done; 54 bool dma_ring_cap_done; 55 }; 56 57 struct wmi_tlv_svc_rdy_ext2_parse { 58 struct wmi_tlv_dma_ring_caps_parse dma_caps_parse; 59 bool dma_ring_cap_done; 60 }; 61 62 struct wmi_tlv_rdy_parse { 63 u32 num_extra_mac_addr; 64 }; 65 66 struct wmi_tlv_dma_buf_release_parse { 67 struct ath11k_wmi_dma_buf_release_fixed_param fixed; 68 struct wmi_dma_buf_release_entry *buf_entry; 69 struct wmi_dma_buf_release_meta_data *meta_data; 70 u32 num_buf_entry; 71 u32 num_meta; 72 bool buf_entry_done; 73 bool meta_data_done; 74 }; 75 76 static const struct wmi_tlv_policy wmi_tlv_policies[] = { 77 [WMI_TAG_ARRAY_BYTE] 78 = { .min_len = 0 }, 79 [WMI_TAG_ARRAY_UINT32] 80 = { .min_len = 0 }, 81 [WMI_TAG_SERVICE_READY_EVENT] 82 = { .min_len = sizeof(struct wmi_service_ready_event) }, 83 [WMI_TAG_SERVICE_READY_EXT_EVENT] 84 = { .min_len = sizeof(struct wmi_service_ready_ext_event) }, 85 [WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS] 86 = { .min_len = sizeof(struct wmi_soc_mac_phy_hw_mode_caps) }, 87 [WMI_TAG_SOC_HAL_REG_CAPABILITIES] 88 = { .min_len = sizeof(struct wmi_soc_hal_reg_capabilities) }, 89 [WMI_TAG_VDEV_START_RESPONSE_EVENT] 90 = { .min_len = sizeof(struct wmi_vdev_start_resp_event) }, 91 [WMI_TAG_PEER_DELETE_RESP_EVENT] 92 = { .min_len = sizeof(struct wmi_peer_delete_resp_event) }, 93 [WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT] 94 = { .min_len = sizeof(struct wmi_bcn_tx_status_event) }, 95 [WMI_TAG_VDEV_STOPPED_EVENT] 96 = { .min_len = sizeof(struct wmi_vdev_stopped_event) }, 97 [WMI_TAG_REG_CHAN_LIST_CC_EVENT] 98 = { .min_len = sizeof(struct wmi_reg_chan_list_cc_event) }, 99 [WMI_TAG_MGMT_RX_HDR] 100 = { .min_len = sizeof(struct wmi_mgmt_rx_hdr) }, 101 [WMI_TAG_MGMT_TX_COMPL_EVENT] 102 = { .min_len = sizeof(struct wmi_mgmt_tx_compl_event) }, 103 [WMI_TAG_SCAN_EVENT] 104 = { .min_len = sizeof(struct wmi_scan_event) }, 105 [WMI_TAG_PEER_STA_KICKOUT_EVENT] 106 = { .min_len = sizeof(struct wmi_peer_sta_kickout_event) }, 107 [WMI_TAG_ROAM_EVENT] 108 = { .min_len = sizeof(struct wmi_roam_event) }, 109 [WMI_TAG_CHAN_INFO_EVENT] 110 = { .min_len = sizeof(struct wmi_chan_info_event) }, 111 [WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT] 112 = { .min_len = sizeof(struct wmi_pdev_bss_chan_info_event) }, 113 [WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT] 114 = { .min_len = sizeof(struct wmi_vdev_install_key_compl_event) }, 115 [WMI_TAG_READY_EVENT] = { 116 .min_len = sizeof(struct wmi_ready_event_min) }, 117 [WMI_TAG_SERVICE_AVAILABLE_EVENT] 118 = {.min_len = sizeof(struct wmi_service_available_event) }, 119 [WMI_TAG_PEER_ASSOC_CONF_EVENT] 120 = { .min_len = sizeof(struct wmi_peer_assoc_conf_event) }, 121 [WMI_TAG_STATS_EVENT] 122 = { .min_len = sizeof(struct wmi_stats_event) }, 123 [WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT] 124 = { .min_len = sizeof(struct wmi_pdev_ctl_failsafe_chk_event) }, 125 }; 126 127 #define PRIMAP(_hw_mode_) \ 128 [_hw_mode_] = _hw_mode_##_PRI 129 130 static const int ath11k_hw_mode_pri_map[] = { 131 PRIMAP(WMI_HOST_HW_MODE_SINGLE), 132 PRIMAP(WMI_HOST_HW_MODE_DBS), 133 PRIMAP(WMI_HOST_HW_MODE_SBS_PASSIVE), 134 PRIMAP(WMI_HOST_HW_MODE_SBS), 135 PRIMAP(WMI_HOST_HW_MODE_DBS_SBS), 136 PRIMAP(WMI_HOST_HW_MODE_DBS_OR_SBS), 137 /* keep last */ 138 PRIMAP(WMI_HOST_HW_MODE_MAX), 139 }; 140 141 static int 142 ath11k_wmi_tlv_iter(struct ath11k_base *ab, const void *ptr, size_t len, 143 int (*iter)(struct ath11k_base *ab, u16 tag, u16 len, 144 const void *ptr, void *data), 145 void *data) 146 { 147 const void *begin = ptr; 148 const struct wmi_tlv *tlv; 149 u16 tlv_tag, tlv_len; 150 int ret; 151 152 while (len > 0) { 153 if (len < sizeof(*tlv)) { 154 ath11k_err(ab, "wmi tlv parse failure at byte %zd (%zu bytes left, %zu expected)\n", 155 ptr - begin, len, sizeof(*tlv)); 156 return -EINVAL; 157 } 158 159 tlv = ptr; 160 tlv_tag = FIELD_GET(WMI_TLV_TAG, tlv->header); 161 tlv_len = FIELD_GET(WMI_TLV_LEN, tlv->header); 162 ptr += sizeof(*tlv); 163 len -= sizeof(*tlv); 164 165 if (tlv_len > len) { 166 ath11k_err(ab, "wmi tlv parse failure of tag %hhu at byte %zd (%zu bytes left, %hhu expected)\n", 167 tlv_tag, ptr - begin, len, tlv_len); 168 return -EINVAL; 169 } 170 171 if (tlv_tag < ARRAY_SIZE(wmi_tlv_policies) && 172 wmi_tlv_policies[tlv_tag].min_len && 173 wmi_tlv_policies[tlv_tag].min_len > tlv_len) { 174 ath11k_err(ab, "wmi tlv parse failure of tag %hhu at byte %zd (%hhu bytes is less than min length %zu)\n", 175 tlv_tag, ptr - begin, tlv_len, 176 wmi_tlv_policies[tlv_tag].min_len); 177 return -EINVAL; 178 } 179 180 ret = iter(ab, tlv_tag, tlv_len, ptr, data); 181 if (ret) 182 return ret; 183 184 ptr += tlv_len; 185 len -= tlv_len; 186 } 187 188 return 0; 189 } 190 191 static int ath11k_wmi_tlv_iter_parse(struct ath11k_base *ab, u16 tag, u16 len, 192 const void *ptr, void *data) 193 { 194 const void **tb = data; 195 196 if (tag < WMI_TAG_MAX) 197 tb[tag] = ptr; 198 199 return 0; 200 } 201 202 static int ath11k_wmi_tlv_parse(struct ath11k_base *ar, const void **tb, 203 const void *ptr, size_t len) 204 { 205 return ath11k_wmi_tlv_iter(ar, ptr, len, ath11k_wmi_tlv_iter_parse, 206 (void *)tb); 207 } 208 209 static const void ** 210 ath11k_wmi_tlv_parse_alloc(struct ath11k_base *ab, const void *ptr, 211 size_t len, gfp_t gfp) 212 { 213 const void **tb; 214 int ret; 215 216 tb = kcalloc(WMI_TAG_MAX, sizeof(*tb), gfp); 217 if (!tb) 218 return ERR_PTR(-ENOMEM); 219 220 ret = ath11k_wmi_tlv_parse(ab, tb, ptr, len); 221 if (ret) { 222 kfree(tb); 223 return ERR_PTR(ret); 224 } 225 226 return tb; 227 } 228 229 static int ath11k_wmi_cmd_send_nowait(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb, 230 u32 cmd_id) 231 { 232 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb); 233 struct ath11k_base *ab = wmi->wmi_ab->ab; 234 struct wmi_cmd_hdr *cmd_hdr; 235 int ret; 236 u32 cmd = 0; 237 238 if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL) 239 return -ENOMEM; 240 241 cmd |= FIELD_PREP(WMI_CMD_HDR_CMD_ID, cmd_id); 242 243 cmd_hdr = (struct wmi_cmd_hdr *)skb->data; 244 cmd_hdr->cmd_id = cmd; 245 246 memset(skb_cb, 0, sizeof(*skb_cb)); 247 ret = ath11k_htc_send(&ab->htc, wmi->eid, skb); 248 249 if (ret) 250 goto err_pull; 251 252 return 0; 253 254 err_pull: 255 skb_pull(skb, sizeof(struct wmi_cmd_hdr)); 256 return ret; 257 } 258 259 int ath11k_wmi_cmd_send(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb, 260 u32 cmd_id) 261 { 262 struct ath11k_wmi_base *wmi_sc = wmi->wmi_ab; 263 int ret = -EOPNOTSUPP; 264 265 might_sleep(); 266 267 wait_event_timeout(wmi_sc->tx_credits_wq, ({ 268 ret = ath11k_wmi_cmd_send_nowait(wmi, skb, cmd_id); 269 270 if (ret && test_bit(ATH11K_FLAG_CRASH_FLUSH, &wmi_sc->ab->dev_flags)) 271 ret = -ESHUTDOWN; 272 273 (ret != -EAGAIN); 274 }), WMI_SEND_TIMEOUT_HZ); 275 276 if (ret == -EAGAIN) 277 ath11k_warn(wmi_sc->ab, "wmi command %d timeout\n", cmd_id); 278 279 return ret; 280 } 281 282 static int ath11k_pull_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle, 283 const void *ptr, 284 struct ath11k_service_ext_param *param) 285 { 286 const struct wmi_service_ready_ext_event *ev = ptr; 287 288 if (!ev) 289 return -EINVAL; 290 291 /* Move this to host based bitmap */ 292 param->default_conc_scan_config_bits = ev->default_conc_scan_config_bits; 293 param->default_fw_config_bits = ev->default_fw_config_bits; 294 param->he_cap_info = ev->he_cap_info; 295 param->mpdu_density = ev->mpdu_density; 296 param->max_bssid_rx_filters = ev->max_bssid_rx_filters; 297 memcpy(¶m->ppet, &ev->ppet, sizeof(param->ppet)); 298 299 return 0; 300 } 301 302 static int 303 ath11k_pull_mac_phy_cap_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle, 304 struct wmi_soc_mac_phy_hw_mode_caps *hw_caps, 305 struct wmi_hw_mode_capabilities *wmi_hw_mode_caps, 306 struct wmi_soc_hal_reg_capabilities *hal_reg_caps, 307 struct wmi_mac_phy_capabilities *wmi_mac_phy_caps, 308 u8 hw_mode_id, u8 phy_id, 309 struct ath11k_pdev *pdev) 310 { 311 struct wmi_mac_phy_capabilities *mac_phy_caps; 312 struct ath11k_band_cap *cap_band; 313 struct ath11k_pdev_cap *pdev_cap = &pdev->cap; 314 u32 phy_map; 315 u32 hw_idx, phy_idx = 0; 316 317 if (!hw_caps || !wmi_hw_mode_caps || !hal_reg_caps) 318 return -EINVAL; 319 320 for (hw_idx = 0; hw_idx < hw_caps->num_hw_modes; hw_idx++) { 321 if (hw_mode_id == wmi_hw_mode_caps[hw_idx].hw_mode_id) 322 break; 323 324 phy_map = wmi_hw_mode_caps[hw_idx].phy_id_map; 325 while (phy_map) { 326 phy_map >>= 1; 327 phy_idx++; 328 } 329 } 330 331 if (hw_idx == hw_caps->num_hw_modes) 332 return -EINVAL; 333 334 phy_idx += phy_id; 335 if (phy_id >= hal_reg_caps->num_phy) 336 return -EINVAL; 337 338 mac_phy_caps = wmi_mac_phy_caps + phy_idx; 339 340 pdev->pdev_id = mac_phy_caps->pdev_id; 341 pdev_cap->supported_bands |= mac_phy_caps->supported_bands; 342 pdev_cap->ampdu_density = mac_phy_caps->ampdu_density; 343 344 /* Take non-zero tx/rx chainmask. If tx/rx chainmask differs from 345 * band to band for a single radio, need to see how this should be 346 * handled. 347 */ 348 if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) { 349 pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_2g; 350 pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_2g; 351 } else if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) { 352 pdev_cap->vht_cap = mac_phy_caps->vht_cap_info_5g; 353 pdev_cap->vht_mcs = mac_phy_caps->vht_supp_mcs_5g; 354 pdev_cap->he_mcs = mac_phy_caps->he_supp_mcs_5g; 355 pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_5g; 356 pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_5g; 357 } else { 358 return -EINVAL; 359 } 360 361 /* tx/rx chainmask reported from fw depends on the actual hw chains used, 362 * For example, for 4x4 capable macphys, first 4 chains can be used for first 363 * mac and the remaing 4 chains can be used for the second mac or vice-versa. 364 * In this case, tx/rx chainmask 0xf will be advertised for first mac and 0xf0 365 * will be advertised for second mac or vice-versa. Compute the shift value for 366 * for tx/rx chainmask which will be used to advertise supported ht/vht rates to 367 * mac80211. 368 */ 369 pdev_cap->tx_chain_mask_shift = 370 find_first_bit((unsigned long *)&pdev_cap->tx_chain_mask, 32); 371 pdev_cap->rx_chain_mask_shift = 372 find_first_bit((unsigned long *)&pdev_cap->rx_chain_mask, 32); 373 374 if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) { 375 cap_band = &pdev_cap->band[NL80211_BAND_2GHZ]; 376 cap_band->phy_id = mac_phy_caps->phy_id; 377 cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_2g; 378 cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_2g; 379 cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_2g; 380 cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_2g_ext; 381 cap_band->he_mcs = mac_phy_caps->he_supp_mcs_2g; 382 memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_2g, 383 sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE); 384 memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet2g, 385 sizeof(struct ath11k_ppe_threshold)); 386 } 387 388 if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) { 389 cap_band = &pdev_cap->band[NL80211_BAND_5GHZ]; 390 cap_band->phy_id = mac_phy_caps->phy_id; 391 cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g; 392 cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g; 393 cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g; 394 cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext; 395 cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g; 396 memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g, 397 sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE); 398 memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g, 399 sizeof(struct ath11k_ppe_threshold)); 400 } 401 402 cap_band = &pdev_cap->band[NL80211_BAND_6GHZ]; 403 cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g; 404 cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g; 405 cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g; 406 cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext; 407 cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g; 408 memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g, 409 sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE); 410 memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g, 411 sizeof(struct ath11k_ppe_threshold)); 412 413 return 0; 414 } 415 416 static int 417 ath11k_pull_reg_cap_svc_rdy_ext(struct ath11k_pdev_wmi *wmi_handle, 418 struct wmi_soc_hal_reg_capabilities *reg_caps, 419 struct wmi_hal_reg_capabilities_ext *wmi_ext_reg_cap, 420 u8 phy_idx, 421 struct ath11k_hal_reg_capabilities_ext *param) 422 { 423 struct wmi_hal_reg_capabilities_ext *ext_reg_cap; 424 425 if (!reg_caps || !wmi_ext_reg_cap) 426 return -EINVAL; 427 428 if (phy_idx >= reg_caps->num_phy) 429 return -EINVAL; 430 431 ext_reg_cap = &wmi_ext_reg_cap[phy_idx]; 432 433 param->phy_id = ext_reg_cap->phy_id; 434 param->eeprom_reg_domain = ext_reg_cap->eeprom_reg_domain; 435 param->eeprom_reg_domain_ext = 436 ext_reg_cap->eeprom_reg_domain_ext; 437 param->regcap1 = ext_reg_cap->regcap1; 438 param->regcap2 = ext_reg_cap->regcap2; 439 /* check if param->wireless_mode is needed */ 440 param->low_2ghz_chan = ext_reg_cap->low_2ghz_chan; 441 param->high_2ghz_chan = ext_reg_cap->high_2ghz_chan; 442 param->low_5ghz_chan = ext_reg_cap->low_5ghz_chan; 443 param->high_5ghz_chan = ext_reg_cap->high_5ghz_chan; 444 445 return 0; 446 } 447 448 static int ath11k_pull_service_ready_tlv(struct ath11k_base *ab, 449 const void *evt_buf, 450 struct ath11k_targ_cap *cap) 451 { 452 const struct wmi_service_ready_event *ev = evt_buf; 453 454 if (!ev) { 455 ath11k_err(ab, "%s: failed by NULL param\n", 456 __func__); 457 return -EINVAL; 458 } 459 460 cap->phy_capability = ev->phy_capability; 461 cap->max_frag_entry = ev->max_frag_entry; 462 cap->num_rf_chains = ev->num_rf_chains; 463 cap->ht_cap_info = ev->ht_cap_info; 464 cap->vht_cap_info = ev->vht_cap_info; 465 cap->vht_supp_mcs = ev->vht_supp_mcs; 466 cap->hw_min_tx_power = ev->hw_min_tx_power; 467 cap->hw_max_tx_power = ev->hw_max_tx_power; 468 cap->sys_cap_info = ev->sys_cap_info; 469 cap->min_pkt_size_enable = ev->min_pkt_size_enable; 470 cap->max_bcn_ie_size = ev->max_bcn_ie_size; 471 cap->max_num_scan_channels = ev->max_num_scan_channels; 472 cap->max_supported_macs = ev->max_supported_macs; 473 cap->wmi_fw_sub_feat_caps = ev->wmi_fw_sub_feat_caps; 474 cap->txrx_chainmask = ev->txrx_chainmask; 475 cap->default_dbs_hw_mode_index = ev->default_dbs_hw_mode_index; 476 cap->num_msdu_desc = ev->num_msdu_desc; 477 478 return 0; 479 } 480 481 /* Save the wmi_service_bitmap into a linear bitmap. The wmi_services in 482 * wmi_service ready event are advertised in b0-b3 (LSB 4-bits) of each 483 * 4-byte word. 484 */ 485 static void ath11k_wmi_service_bitmap_copy(struct ath11k_pdev_wmi *wmi, 486 const u32 *wmi_svc_bm) 487 { 488 int i, j; 489 490 for (i = 0, j = 0; i < WMI_SERVICE_BM_SIZE && j < WMI_MAX_SERVICE; i++) { 491 do { 492 if (wmi_svc_bm[i] & BIT(j % WMI_SERVICE_BITS_IN_SIZE32)) 493 set_bit(j, wmi->wmi_ab->svc_map); 494 } while (++j % WMI_SERVICE_BITS_IN_SIZE32); 495 } 496 } 497 498 static int ath11k_wmi_tlv_svc_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len, 499 const void *ptr, void *data) 500 { 501 struct wmi_tlv_svc_ready_parse *svc_ready = data; 502 struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0]; 503 u16 expect_len; 504 505 switch (tag) { 506 case WMI_TAG_SERVICE_READY_EVENT: 507 if (ath11k_pull_service_ready_tlv(ab, ptr, &ab->target_caps)) 508 return -EINVAL; 509 break; 510 511 case WMI_TAG_ARRAY_UINT32: 512 if (!svc_ready->wmi_svc_bitmap_done) { 513 expect_len = WMI_SERVICE_BM_SIZE * sizeof(u32); 514 if (len < expect_len) { 515 ath11k_warn(ab, "invalid len %d for the tag 0x%x\n", 516 len, tag); 517 return -EINVAL; 518 } 519 520 ath11k_wmi_service_bitmap_copy(wmi_handle, ptr); 521 522 svc_ready->wmi_svc_bitmap_done = true; 523 } 524 break; 525 default: 526 break; 527 } 528 529 return 0; 530 } 531 532 static int ath11k_service_ready_event(struct ath11k_base *ab, struct sk_buff *skb) 533 { 534 struct wmi_tlv_svc_ready_parse svc_ready = { }; 535 int ret; 536 537 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len, 538 ath11k_wmi_tlv_svc_rdy_parse, 539 &svc_ready); 540 if (ret) { 541 ath11k_warn(ab, "failed to parse tlv %d\n", ret); 542 return ret; 543 } 544 545 return 0; 546 } 547 548 struct sk_buff *ath11k_wmi_alloc_skb(struct ath11k_wmi_base *wmi_sc, u32 len) 549 { 550 struct sk_buff *skb; 551 struct ath11k_base *ab = wmi_sc->ab; 552 u32 round_len = roundup(len, 4); 553 554 skb = ath11k_htc_alloc_skb(ab, WMI_SKB_HEADROOM + round_len); 555 if (!skb) 556 return NULL; 557 558 skb_reserve(skb, WMI_SKB_HEADROOM); 559 if (!IS_ALIGNED((unsigned long)skb->data, 4)) 560 ath11k_warn(ab, "unaligned WMI skb data\n"); 561 562 skb_put(skb, round_len); 563 memset(skb->data, 0, round_len); 564 565 return skb; 566 } 567 568 int ath11k_wmi_mgmt_send(struct ath11k *ar, u32 vdev_id, u32 buf_id, 569 struct sk_buff *frame) 570 { 571 struct ath11k_pdev_wmi *wmi = ar->wmi; 572 struct wmi_mgmt_send_cmd *cmd; 573 struct wmi_tlv *frame_tlv; 574 struct sk_buff *skb; 575 u32 buf_len; 576 int ret, len; 577 578 buf_len = frame->len < WMI_MGMT_SEND_DOWNLD_LEN ? 579 frame->len : WMI_MGMT_SEND_DOWNLD_LEN; 580 581 len = sizeof(*cmd) + sizeof(*frame_tlv) + roundup(buf_len, 4); 582 583 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 584 if (!skb) 585 return -ENOMEM; 586 587 cmd = (struct wmi_mgmt_send_cmd *)skb->data; 588 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_MGMT_TX_SEND_CMD) | 589 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 590 cmd->vdev_id = vdev_id; 591 cmd->desc_id = buf_id; 592 cmd->chanfreq = 0; 593 cmd->paddr_lo = lower_32_bits(ATH11K_SKB_CB(frame)->paddr); 594 cmd->paddr_hi = upper_32_bits(ATH11K_SKB_CB(frame)->paddr); 595 cmd->frame_len = frame->len; 596 cmd->buf_len = buf_len; 597 cmd->tx_params_valid = 0; 598 599 frame_tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd)); 600 frame_tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) | 601 FIELD_PREP(WMI_TLV_LEN, buf_len); 602 603 memcpy(frame_tlv->value, frame->data, buf_len); 604 605 ath11k_ce_byte_swap(frame_tlv->value, buf_len); 606 607 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_MGMT_TX_SEND_CMDID); 608 if (ret) { 609 ath11k_warn(ar->ab, 610 "failed to submit WMI_MGMT_TX_SEND_CMDID cmd\n"); 611 dev_kfree_skb(skb); 612 } 613 614 return ret; 615 } 616 617 int ath11k_wmi_vdev_create(struct ath11k *ar, u8 *macaddr, 618 struct vdev_create_params *param) 619 { 620 struct ath11k_pdev_wmi *wmi = ar->wmi; 621 struct wmi_vdev_create_cmd *cmd; 622 struct sk_buff *skb; 623 struct wmi_vdev_txrx_streams *txrx_streams; 624 struct wmi_tlv *tlv; 625 int ret, len; 626 void *ptr; 627 628 /* It can be optimized my sending tx/rx chain configuration 629 * only for supported bands instead of always sending it for 630 * both the bands. 631 */ 632 len = sizeof(*cmd) + TLV_HDR_SIZE + 633 (WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams)); 634 635 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 636 if (!skb) 637 return -ENOMEM; 638 639 cmd = (struct wmi_vdev_create_cmd *)skb->data; 640 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_CREATE_CMD) | 641 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 642 643 cmd->vdev_id = param->if_id; 644 cmd->vdev_type = param->type; 645 cmd->vdev_subtype = param->subtype; 646 cmd->num_cfg_txrx_streams = WMI_NUM_SUPPORTED_BAND_MAX; 647 cmd->pdev_id = param->pdev_id; 648 ether_addr_copy(cmd->vdev_macaddr.addr, macaddr); 649 650 ptr = skb->data + sizeof(*cmd); 651 len = WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams); 652 653 tlv = ptr; 654 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 655 FIELD_PREP(WMI_TLV_LEN, len); 656 657 ptr += TLV_HDR_SIZE; 658 txrx_streams = ptr; 659 len = sizeof(*txrx_streams); 660 txrx_streams->tlv_header = 661 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) | 662 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 663 txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_2G; 664 txrx_streams->supported_tx_streams = 665 param->chains[NL80211_BAND_2GHZ].tx; 666 txrx_streams->supported_rx_streams = 667 param->chains[NL80211_BAND_2GHZ].rx; 668 669 txrx_streams++; 670 txrx_streams->tlv_header = 671 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) | 672 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 673 txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_5G; 674 txrx_streams->supported_tx_streams = 675 param->chains[NL80211_BAND_5GHZ].tx; 676 txrx_streams->supported_rx_streams = 677 param->chains[NL80211_BAND_5GHZ].rx; 678 679 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_CREATE_CMDID); 680 if (ret) { 681 ath11k_warn(ar->ab, 682 "failed to submit WMI_VDEV_CREATE_CMDID\n"); 683 dev_kfree_skb(skb); 684 } 685 686 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 687 "WMI vdev create: id %d type %d subtype %d macaddr %pM pdevid %d\n", 688 param->if_id, param->type, param->subtype, 689 macaddr, param->pdev_id); 690 691 return ret; 692 } 693 694 int ath11k_wmi_vdev_delete(struct ath11k *ar, u8 vdev_id) 695 { 696 struct ath11k_pdev_wmi *wmi = ar->wmi; 697 struct wmi_vdev_delete_cmd *cmd; 698 struct sk_buff *skb; 699 int ret; 700 701 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 702 if (!skb) 703 return -ENOMEM; 704 705 cmd = (struct wmi_vdev_delete_cmd *)skb->data; 706 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DELETE_CMD) | 707 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 708 cmd->vdev_id = vdev_id; 709 710 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DELETE_CMDID); 711 if (ret) { 712 ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DELETE_CMDID\n"); 713 dev_kfree_skb(skb); 714 } 715 716 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev delete id %d\n", vdev_id); 717 718 return ret; 719 } 720 721 int ath11k_wmi_vdev_stop(struct ath11k *ar, u8 vdev_id) 722 { 723 struct ath11k_pdev_wmi *wmi = ar->wmi; 724 struct wmi_vdev_stop_cmd *cmd; 725 struct sk_buff *skb; 726 int ret; 727 728 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 729 if (!skb) 730 return -ENOMEM; 731 732 cmd = (struct wmi_vdev_stop_cmd *)skb->data; 733 734 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_STOP_CMD) | 735 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 736 cmd->vdev_id = vdev_id; 737 738 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_STOP_CMDID); 739 if (ret) { 740 ath11k_warn(ar->ab, "failed to submit WMI_VDEV_STOP cmd\n"); 741 dev_kfree_skb(skb); 742 } 743 744 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev stop id 0x%x\n", vdev_id); 745 746 return ret; 747 } 748 749 int ath11k_wmi_vdev_down(struct ath11k *ar, u8 vdev_id) 750 { 751 struct ath11k_pdev_wmi *wmi = ar->wmi; 752 struct wmi_vdev_down_cmd *cmd; 753 struct sk_buff *skb; 754 int ret; 755 756 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 757 if (!skb) 758 return -ENOMEM; 759 760 cmd = (struct wmi_vdev_down_cmd *)skb->data; 761 762 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DOWN_CMD) | 763 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 764 cmd->vdev_id = vdev_id; 765 766 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DOWN_CMDID); 767 if (ret) { 768 ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DOWN cmd\n"); 769 dev_kfree_skb(skb); 770 } 771 772 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev down id 0x%x\n", vdev_id); 773 774 return ret; 775 } 776 777 static void ath11k_wmi_put_wmi_channel(struct wmi_channel *chan, 778 struct wmi_vdev_start_req_arg *arg) 779 { 780 memset(chan, 0, sizeof(*chan)); 781 782 chan->mhz = arg->channel.freq; 783 chan->band_center_freq1 = arg->channel.band_center_freq1; 784 if (arg->channel.mode == MODE_11AC_VHT80_80) 785 chan->band_center_freq2 = arg->channel.band_center_freq2; 786 else 787 chan->band_center_freq2 = 0; 788 789 chan->info |= FIELD_PREP(WMI_CHAN_INFO_MODE, arg->channel.mode); 790 if (arg->channel.passive) 791 chan->info |= WMI_CHAN_INFO_PASSIVE; 792 if (arg->channel.allow_ibss) 793 chan->info |= WMI_CHAN_INFO_ADHOC_ALLOWED; 794 if (arg->channel.allow_ht) 795 chan->info |= WMI_CHAN_INFO_ALLOW_HT; 796 if (arg->channel.allow_vht) 797 chan->info |= WMI_CHAN_INFO_ALLOW_VHT; 798 if (arg->channel.allow_he) 799 chan->info |= WMI_CHAN_INFO_ALLOW_HE; 800 if (arg->channel.ht40plus) 801 chan->info |= WMI_CHAN_INFO_HT40_PLUS; 802 if (arg->channel.chan_radar) 803 chan->info |= WMI_CHAN_INFO_DFS; 804 if (arg->channel.freq2_radar) 805 chan->info |= WMI_CHAN_INFO_DFS_FREQ2; 806 807 chan->reg_info_1 = FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR, 808 arg->channel.max_power) | 809 FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR, 810 arg->channel.max_reg_power); 811 812 chan->reg_info_2 = FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX, 813 arg->channel.max_antenna_gain) | 814 FIELD_PREP(WMI_CHAN_REG_INFO2_MAX_TX_PWR, 815 arg->channel.max_power); 816 } 817 818 int ath11k_wmi_vdev_start(struct ath11k *ar, struct wmi_vdev_start_req_arg *arg, 819 bool restart) 820 { 821 struct ath11k_pdev_wmi *wmi = ar->wmi; 822 struct wmi_vdev_start_request_cmd *cmd; 823 struct sk_buff *skb; 824 struct wmi_channel *chan; 825 struct wmi_tlv *tlv; 826 void *ptr; 827 int ret, len; 828 829 if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid))) 830 return -EINVAL; 831 832 len = sizeof(*cmd) + sizeof(*chan) + TLV_HDR_SIZE; 833 834 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 835 if (!skb) 836 return -ENOMEM; 837 838 cmd = (struct wmi_vdev_start_request_cmd *)skb->data; 839 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 840 WMI_TAG_VDEV_START_REQUEST_CMD) | 841 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 842 cmd->vdev_id = arg->vdev_id; 843 cmd->beacon_interval = arg->bcn_intval; 844 cmd->bcn_tx_rate = arg->bcn_tx_rate; 845 cmd->dtim_period = arg->dtim_period; 846 cmd->num_noa_descriptors = arg->num_noa_descriptors; 847 cmd->preferred_rx_streams = arg->pref_rx_streams; 848 cmd->preferred_tx_streams = arg->pref_tx_streams; 849 cmd->cac_duration_ms = arg->cac_duration_ms; 850 cmd->regdomain = arg->regdomain; 851 cmd->he_ops = arg->he_ops; 852 853 if (!restart) { 854 if (arg->ssid) { 855 cmd->ssid.ssid_len = arg->ssid_len; 856 memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len); 857 } 858 if (arg->hidden_ssid) 859 cmd->flags |= WMI_VDEV_START_HIDDEN_SSID; 860 if (arg->pmf_enabled) 861 cmd->flags |= WMI_VDEV_START_PMF_ENABLED; 862 } 863 864 cmd->flags |= WMI_VDEV_START_LDPC_RX_ENABLED; 865 866 ptr = skb->data + sizeof(*cmd); 867 chan = ptr; 868 869 ath11k_wmi_put_wmi_channel(chan, arg); 870 871 chan->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_CHANNEL) | 872 FIELD_PREP(WMI_TLV_LEN, 873 sizeof(*chan) - TLV_HDR_SIZE); 874 ptr += sizeof(*chan); 875 876 tlv = ptr; 877 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 878 FIELD_PREP(WMI_TLV_LEN, 0); 879 880 /* Note: This is a nested TLV containing: 881 * [wmi_tlv][wmi_p2p_noa_descriptor][wmi_tlv].. 882 */ 883 884 ptr += sizeof(*tlv); 885 886 if (restart) 887 ret = ath11k_wmi_cmd_send(wmi, skb, 888 WMI_VDEV_RESTART_REQUEST_CMDID); 889 else 890 ret = ath11k_wmi_cmd_send(wmi, skb, 891 WMI_VDEV_START_REQUEST_CMDID); 892 if (ret) { 893 ath11k_warn(ar->ab, "failed to submit vdev_%s cmd\n", 894 restart ? "restart" : "start"); 895 dev_kfree_skb(skb); 896 } 897 898 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "vdev %s id 0x%x freq 0x%x mode 0x%x\n", 899 restart ? "restart" : "start", arg->vdev_id, 900 arg->channel.freq, arg->channel.mode); 901 902 return ret; 903 } 904 905 int ath11k_wmi_vdev_up(struct ath11k *ar, u32 vdev_id, u32 aid, const u8 *bssid) 906 { 907 struct ath11k_pdev_wmi *wmi = ar->wmi; 908 struct wmi_vdev_up_cmd *cmd; 909 struct sk_buff *skb; 910 int ret; 911 912 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 913 if (!skb) 914 return -ENOMEM; 915 916 cmd = (struct wmi_vdev_up_cmd *)skb->data; 917 918 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_UP_CMD) | 919 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 920 cmd->vdev_id = vdev_id; 921 cmd->vdev_assoc_id = aid; 922 923 ether_addr_copy(cmd->vdev_bssid.addr, bssid); 924 925 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_UP_CMDID); 926 if (ret) { 927 ath11k_warn(ar->ab, "failed to submit WMI_VDEV_UP cmd\n"); 928 dev_kfree_skb(skb); 929 } 930 931 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 932 "WMI mgmt vdev up id 0x%x assoc id %d bssid %pM\n", 933 vdev_id, aid, bssid); 934 935 return ret; 936 } 937 938 int ath11k_wmi_send_peer_create_cmd(struct ath11k *ar, 939 struct peer_create_params *param) 940 { 941 struct ath11k_pdev_wmi *wmi = ar->wmi; 942 struct wmi_peer_create_cmd *cmd; 943 struct sk_buff *skb; 944 int ret; 945 946 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 947 if (!skb) 948 return -ENOMEM; 949 950 cmd = (struct wmi_peer_create_cmd *)skb->data; 951 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_CREATE_CMD) | 952 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 953 954 ether_addr_copy(cmd->peer_macaddr.addr, param->peer_addr); 955 cmd->peer_type = param->peer_type; 956 cmd->vdev_id = param->vdev_id; 957 958 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_CREATE_CMDID); 959 if (ret) { 960 ath11k_warn(ar->ab, "failed to submit WMI_PEER_CREATE cmd\n"); 961 dev_kfree_skb(skb); 962 } 963 964 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 965 "WMI peer create vdev_id %d peer_addr %pM\n", 966 param->vdev_id, param->peer_addr); 967 968 return ret; 969 } 970 971 int ath11k_wmi_send_peer_delete_cmd(struct ath11k *ar, 972 const u8 *peer_addr, u8 vdev_id) 973 { 974 struct ath11k_pdev_wmi *wmi = ar->wmi; 975 struct wmi_peer_delete_cmd *cmd; 976 struct sk_buff *skb; 977 int ret; 978 979 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 980 if (!skb) 981 return -ENOMEM; 982 983 cmd = (struct wmi_peer_delete_cmd *)skb->data; 984 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_DELETE_CMD) | 985 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 986 987 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr); 988 cmd->vdev_id = vdev_id; 989 990 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 991 "WMI peer delete vdev_id %d peer_addr %pM\n", 992 vdev_id, peer_addr); 993 994 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_DELETE_CMDID); 995 if (ret) { 996 ath11k_warn(ar->ab, "failed to send WMI_PEER_DELETE cmd\n"); 997 dev_kfree_skb(skb); 998 } 999 1000 return ret; 1001 } 1002 1003 int ath11k_wmi_send_pdev_set_regdomain(struct ath11k *ar, 1004 struct pdev_set_regdomain_params *param) 1005 { 1006 struct ath11k_pdev_wmi *wmi = ar->wmi; 1007 struct wmi_pdev_set_regdomain_cmd *cmd; 1008 struct sk_buff *skb; 1009 int ret; 1010 1011 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1012 if (!skb) 1013 return -ENOMEM; 1014 1015 cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data; 1016 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1017 WMI_TAG_PDEV_SET_REGDOMAIN_CMD) | 1018 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1019 1020 cmd->reg_domain = param->current_rd_in_use; 1021 cmd->reg_domain_2g = param->current_rd_2g; 1022 cmd->reg_domain_5g = param->current_rd_5g; 1023 cmd->conformance_test_limit_2g = param->ctl_2g; 1024 cmd->conformance_test_limit_5g = param->ctl_5g; 1025 cmd->dfs_domain = param->dfs_domain; 1026 cmd->pdev_id = param->pdev_id; 1027 1028 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1029 "WMI pdev regd rd %d rd2g %d rd5g %d domain %d pdev id %d\n", 1030 param->current_rd_in_use, param->current_rd_2g, 1031 param->current_rd_5g, param->dfs_domain, param->pdev_id); 1032 1033 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_REGDOMAIN_CMDID); 1034 if (ret) { 1035 ath11k_warn(ar->ab, 1036 "failed to send WMI_PDEV_SET_REGDOMAIN cmd\n"); 1037 dev_kfree_skb(skb); 1038 } 1039 1040 return ret; 1041 } 1042 1043 int ath11k_wmi_set_peer_param(struct ath11k *ar, const u8 *peer_addr, 1044 u32 vdev_id, u32 param_id, u32 param_val) 1045 { 1046 struct ath11k_pdev_wmi *wmi = ar->wmi; 1047 struct wmi_peer_set_param_cmd *cmd; 1048 struct sk_buff *skb; 1049 int ret; 1050 1051 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1052 if (!skb) 1053 return -ENOMEM; 1054 1055 cmd = (struct wmi_peer_set_param_cmd *)skb->data; 1056 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_SET_PARAM_CMD) | 1057 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1058 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr); 1059 cmd->vdev_id = vdev_id; 1060 cmd->param_id = param_id; 1061 cmd->param_value = param_val; 1062 1063 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_SET_PARAM_CMDID); 1064 if (ret) { 1065 ath11k_warn(ar->ab, "failed to send WMI_PEER_SET_PARAM cmd\n"); 1066 dev_kfree_skb(skb); 1067 } 1068 1069 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1070 "WMI vdev %d peer 0x%pM set param %d value %d\n", 1071 vdev_id, peer_addr, param_id, param_val); 1072 1073 return ret; 1074 } 1075 1076 int ath11k_wmi_send_peer_flush_tids_cmd(struct ath11k *ar, 1077 u8 peer_addr[ETH_ALEN], 1078 struct peer_flush_params *param) 1079 { 1080 struct ath11k_pdev_wmi *wmi = ar->wmi; 1081 struct wmi_peer_flush_tids_cmd *cmd; 1082 struct sk_buff *skb; 1083 int ret; 1084 1085 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1086 if (!skb) 1087 return -ENOMEM; 1088 1089 cmd = (struct wmi_peer_flush_tids_cmd *)skb->data; 1090 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_FLUSH_TIDS_CMD) | 1091 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1092 1093 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr); 1094 cmd->peer_tid_bitmap = param->peer_tid_bitmap; 1095 cmd->vdev_id = param->vdev_id; 1096 1097 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_FLUSH_TIDS_CMDID); 1098 if (ret) { 1099 ath11k_warn(ar->ab, 1100 "failed to send WMI_PEER_FLUSH_TIDS cmd\n"); 1101 dev_kfree_skb(skb); 1102 } 1103 1104 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1105 "WMI peer flush vdev_id %d peer_addr %pM tids %08x\n", 1106 param->vdev_id, peer_addr, param->peer_tid_bitmap); 1107 1108 return ret; 1109 } 1110 1111 int ath11k_wmi_peer_rx_reorder_queue_setup(struct ath11k *ar, 1112 int vdev_id, const u8 *addr, 1113 dma_addr_t paddr, u8 tid, 1114 u8 ba_window_size_valid, 1115 u32 ba_window_size) 1116 { 1117 struct wmi_peer_reorder_queue_setup_cmd *cmd; 1118 struct sk_buff *skb; 1119 int ret; 1120 1121 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd)); 1122 if (!skb) 1123 return -ENOMEM; 1124 1125 cmd = (struct wmi_peer_reorder_queue_setup_cmd *)skb->data; 1126 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1127 WMI_TAG_REORDER_QUEUE_SETUP_CMD) | 1128 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1129 1130 ether_addr_copy(cmd->peer_macaddr.addr, addr); 1131 cmd->vdev_id = vdev_id; 1132 cmd->tid = tid; 1133 cmd->queue_ptr_lo = lower_32_bits(paddr); 1134 cmd->queue_ptr_hi = upper_32_bits(paddr); 1135 cmd->queue_no = tid; 1136 cmd->ba_window_size_valid = ba_window_size_valid; 1137 cmd->ba_window_size = ba_window_size; 1138 1139 ret = ath11k_wmi_cmd_send(ar->wmi, skb, 1140 WMI_PEER_REORDER_QUEUE_SETUP_CMDID); 1141 if (ret) { 1142 ath11k_warn(ar->ab, 1143 "failed to send WMI_PEER_REORDER_QUEUE_SETUP\n"); 1144 dev_kfree_skb(skb); 1145 } 1146 1147 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1148 "wmi rx reorder queue setup addr %pM vdev_id %d tid %d\n", 1149 addr, vdev_id, tid); 1150 1151 return ret; 1152 } 1153 1154 int 1155 ath11k_wmi_rx_reord_queue_remove(struct ath11k *ar, 1156 struct rx_reorder_queue_remove_params *param) 1157 { 1158 struct ath11k_pdev_wmi *wmi = ar->wmi; 1159 struct wmi_peer_reorder_queue_remove_cmd *cmd; 1160 struct sk_buff *skb; 1161 int ret; 1162 1163 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1164 if (!skb) 1165 return -ENOMEM; 1166 1167 cmd = (struct wmi_peer_reorder_queue_remove_cmd *)skb->data; 1168 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1169 WMI_TAG_REORDER_QUEUE_REMOVE_CMD) | 1170 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1171 1172 ether_addr_copy(cmd->peer_macaddr.addr, param->peer_macaddr); 1173 cmd->vdev_id = param->vdev_id; 1174 cmd->tid_mask = param->peer_tid_bitmap; 1175 1176 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1177 "%s: peer_macaddr %pM vdev_id %d, tid_map %d", __func__, 1178 param->peer_macaddr, param->vdev_id, param->peer_tid_bitmap); 1179 1180 ret = ath11k_wmi_cmd_send(wmi, skb, 1181 WMI_PEER_REORDER_QUEUE_REMOVE_CMDID); 1182 if (ret) { 1183 ath11k_warn(ar->ab, 1184 "failed to send WMI_PEER_REORDER_QUEUE_REMOVE_CMDID"); 1185 dev_kfree_skb(skb); 1186 } 1187 1188 return ret; 1189 } 1190 1191 int ath11k_wmi_pdev_set_param(struct ath11k *ar, u32 param_id, 1192 u32 param_value, u8 pdev_id) 1193 { 1194 struct ath11k_pdev_wmi *wmi = ar->wmi; 1195 struct wmi_pdev_set_param_cmd *cmd; 1196 struct sk_buff *skb; 1197 int ret; 1198 1199 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1200 if (!skb) 1201 return -ENOMEM; 1202 1203 cmd = (struct wmi_pdev_set_param_cmd *)skb->data; 1204 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_PARAM_CMD) | 1205 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1206 cmd->pdev_id = pdev_id; 1207 cmd->param_id = param_id; 1208 cmd->param_value = param_value; 1209 1210 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_PARAM_CMDID); 1211 if (ret) { 1212 ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n"); 1213 dev_kfree_skb(skb); 1214 } 1215 1216 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1217 "WMI pdev set param %d pdev id %d value %d\n", 1218 param_id, pdev_id, param_value); 1219 1220 return ret; 1221 } 1222 1223 int ath11k_wmi_pdev_set_ps_mode(struct ath11k *ar, int vdev_id, u32 enable) 1224 { 1225 struct ath11k_pdev_wmi *wmi = ar->wmi; 1226 struct wmi_pdev_set_ps_mode_cmd *cmd; 1227 struct sk_buff *skb; 1228 int ret; 1229 1230 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1231 if (!skb) 1232 return -ENOMEM; 1233 1234 cmd = (struct wmi_pdev_set_ps_mode_cmd *)skb->data; 1235 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STA_POWERSAVE_MODE_CMD) | 1236 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1237 cmd->vdev_id = vdev_id; 1238 cmd->sta_ps_mode = enable; 1239 1240 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_MODE_CMDID); 1241 if (ret) { 1242 ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n"); 1243 dev_kfree_skb(skb); 1244 } 1245 1246 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1247 "WMI vdev set psmode %d vdev id %d\n", 1248 enable, vdev_id); 1249 1250 return ret; 1251 } 1252 1253 int ath11k_wmi_pdev_suspend(struct ath11k *ar, u32 suspend_opt, 1254 u32 pdev_id) 1255 { 1256 struct ath11k_pdev_wmi *wmi = ar->wmi; 1257 struct wmi_pdev_suspend_cmd *cmd; 1258 struct sk_buff *skb; 1259 int ret; 1260 1261 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1262 if (!skb) 1263 return -ENOMEM; 1264 1265 cmd = (struct wmi_pdev_suspend_cmd *)skb->data; 1266 1267 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SUSPEND_CMD) | 1268 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1269 1270 cmd->suspend_opt = suspend_opt; 1271 cmd->pdev_id = pdev_id; 1272 1273 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SUSPEND_CMDID); 1274 if (ret) { 1275 ath11k_warn(ar->ab, "failed to send WMI_PDEV_SUSPEND cmd\n"); 1276 dev_kfree_skb(skb); 1277 } 1278 1279 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1280 "WMI pdev suspend pdev_id %d\n", pdev_id); 1281 1282 return ret; 1283 } 1284 1285 int ath11k_wmi_pdev_resume(struct ath11k *ar, u32 pdev_id) 1286 { 1287 struct ath11k_pdev_wmi *wmi = ar->wmi; 1288 struct wmi_pdev_resume_cmd *cmd; 1289 struct sk_buff *skb; 1290 int ret; 1291 1292 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1293 if (!skb) 1294 return -ENOMEM; 1295 1296 cmd = (struct wmi_pdev_resume_cmd *)skb->data; 1297 1298 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_RESUME_CMD) | 1299 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1300 cmd->pdev_id = pdev_id; 1301 1302 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1303 "WMI pdev resume pdev id %d\n", pdev_id); 1304 1305 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_RESUME_CMDID); 1306 if (ret) { 1307 ath11k_warn(ar->ab, "failed to send WMI_PDEV_RESUME cmd\n"); 1308 dev_kfree_skb(skb); 1309 } 1310 1311 return ret; 1312 } 1313 1314 /* TODO FW Support for the cmd is not available yet. 1315 * Can be tested once the command and corresponding 1316 * event is implemented in FW 1317 */ 1318 int ath11k_wmi_pdev_bss_chan_info_request(struct ath11k *ar, 1319 enum wmi_bss_chan_info_req_type type) 1320 { 1321 struct ath11k_pdev_wmi *wmi = ar->wmi; 1322 struct wmi_pdev_bss_chan_info_req_cmd *cmd; 1323 struct sk_buff *skb; 1324 int ret; 1325 1326 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1327 if (!skb) 1328 return -ENOMEM; 1329 1330 cmd = (struct wmi_pdev_bss_chan_info_req_cmd *)skb->data; 1331 1332 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1333 WMI_TAG_PDEV_BSS_CHAN_INFO_REQUEST) | 1334 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1335 cmd->req_type = type; 1336 1337 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1338 "WMI bss chan info req type %d\n", type); 1339 1340 ret = ath11k_wmi_cmd_send(wmi, skb, 1341 WMI_PDEV_BSS_CHAN_INFO_REQUEST_CMDID); 1342 if (ret) { 1343 ath11k_warn(ar->ab, 1344 "failed to send WMI_PDEV_BSS_CHAN_INFO_REQUEST cmd\n"); 1345 dev_kfree_skb(skb); 1346 } 1347 1348 return ret; 1349 } 1350 1351 int ath11k_wmi_send_set_ap_ps_param_cmd(struct ath11k *ar, u8 *peer_addr, 1352 struct ap_ps_params *param) 1353 { 1354 struct ath11k_pdev_wmi *wmi = ar->wmi; 1355 struct wmi_ap_ps_peer_cmd *cmd; 1356 struct sk_buff *skb; 1357 int ret; 1358 1359 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1360 if (!skb) 1361 return -ENOMEM; 1362 1363 cmd = (struct wmi_ap_ps_peer_cmd *)skb->data; 1364 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_AP_PS_PEER_CMD) | 1365 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1366 1367 cmd->vdev_id = param->vdev_id; 1368 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr); 1369 cmd->param = param->param; 1370 cmd->value = param->value; 1371 1372 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_AP_PS_PEER_PARAM_CMDID); 1373 if (ret) { 1374 ath11k_warn(ar->ab, 1375 "failed to send WMI_AP_PS_PEER_PARAM_CMDID\n"); 1376 dev_kfree_skb(skb); 1377 } 1378 1379 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1380 "WMI set ap ps vdev id %d peer %pM param %d value %d\n", 1381 param->vdev_id, peer_addr, param->param, param->value); 1382 1383 return ret; 1384 } 1385 1386 int ath11k_wmi_set_sta_ps_param(struct ath11k *ar, u32 vdev_id, 1387 u32 param, u32 param_value) 1388 { 1389 struct ath11k_pdev_wmi *wmi = ar->wmi; 1390 struct wmi_sta_powersave_param_cmd *cmd; 1391 struct sk_buff *skb; 1392 int ret; 1393 1394 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1395 if (!skb) 1396 return -ENOMEM; 1397 1398 cmd = (struct wmi_sta_powersave_param_cmd *)skb->data; 1399 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1400 WMI_TAG_STA_POWERSAVE_PARAM_CMD) | 1401 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1402 1403 cmd->vdev_id = vdev_id; 1404 cmd->param = param; 1405 cmd->value = param_value; 1406 1407 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1408 "WMI set sta ps vdev_id %d param %d value %d\n", 1409 vdev_id, param, param_value); 1410 1411 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_PARAM_CMDID); 1412 if (ret) { 1413 ath11k_warn(ar->ab, "failed to send WMI_STA_POWERSAVE_PARAM_CMDID"); 1414 dev_kfree_skb(skb); 1415 } 1416 1417 return ret; 1418 } 1419 1420 int ath11k_wmi_force_fw_hang_cmd(struct ath11k *ar, u32 type, u32 delay_time_ms) 1421 { 1422 struct ath11k_pdev_wmi *wmi = ar->wmi; 1423 struct wmi_force_fw_hang_cmd *cmd; 1424 struct sk_buff *skb; 1425 int ret, len; 1426 1427 len = sizeof(*cmd); 1428 1429 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 1430 if (!skb) 1431 return -ENOMEM; 1432 1433 cmd = (struct wmi_force_fw_hang_cmd *)skb->data; 1434 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_FORCE_FW_HANG_CMD) | 1435 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 1436 1437 cmd->type = type; 1438 cmd->delay_time_ms = delay_time_ms; 1439 1440 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_FORCE_FW_HANG_CMDID); 1441 1442 if (ret) { 1443 ath11k_warn(ar->ab, "Failed to send WMI_FORCE_FW_HANG_CMDID"); 1444 dev_kfree_skb(skb); 1445 } 1446 return ret; 1447 } 1448 1449 int ath11k_wmi_vdev_set_param_cmd(struct ath11k *ar, u32 vdev_id, 1450 u32 param_id, u32 param_value) 1451 { 1452 struct ath11k_pdev_wmi *wmi = ar->wmi; 1453 struct wmi_vdev_set_param_cmd *cmd; 1454 struct sk_buff *skb; 1455 int ret; 1456 1457 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1458 if (!skb) 1459 return -ENOMEM; 1460 1461 cmd = (struct wmi_vdev_set_param_cmd *)skb->data; 1462 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_SET_PARAM_CMD) | 1463 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1464 1465 cmd->vdev_id = vdev_id; 1466 cmd->param_id = param_id; 1467 cmd->param_value = param_value; 1468 1469 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_SET_PARAM_CMDID); 1470 if (ret) { 1471 ath11k_warn(ar->ab, 1472 "failed to send WMI_VDEV_SET_PARAM_CMDID\n"); 1473 dev_kfree_skb(skb); 1474 } 1475 1476 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1477 "WMI vdev id 0x%x set param %d value %d\n", 1478 vdev_id, param_id, param_value); 1479 1480 return ret; 1481 } 1482 1483 int ath11k_wmi_send_stats_request_cmd(struct ath11k *ar, 1484 struct stats_request_params *param) 1485 { 1486 struct ath11k_pdev_wmi *wmi = ar->wmi; 1487 struct wmi_request_stats_cmd *cmd; 1488 struct sk_buff *skb; 1489 int ret; 1490 1491 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1492 if (!skb) 1493 return -ENOMEM; 1494 1495 cmd = (struct wmi_request_stats_cmd *)skb->data; 1496 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_REQUEST_STATS_CMD) | 1497 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1498 1499 cmd->stats_id = param->stats_id; 1500 cmd->vdev_id = param->vdev_id; 1501 cmd->pdev_id = param->pdev_id; 1502 1503 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_REQUEST_STATS_CMDID); 1504 if (ret) { 1505 ath11k_warn(ar->ab, "failed to send WMI_REQUEST_STATS cmd\n"); 1506 dev_kfree_skb(skb); 1507 } 1508 1509 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1510 "WMI request stats 0x%x vdev id %d pdev id %d\n", 1511 param->stats_id, param->vdev_id, param->pdev_id); 1512 1513 return ret; 1514 } 1515 1516 int ath11k_wmi_send_pdev_temperature_cmd(struct ath11k *ar) 1517 { 1518 struct ath11k_pdev_wmi *wmi = ar->wmi; 1519 struct wmi_get_pdev_temperature_cmd *cmd; 1520 struct sk_buff *skb; 1521 int ret; 1522 1523 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1524 if (!skb) 1525 return -ENOMEM; 1526 1527 cmd = (struct wmi_get_pdev_temperature_cmd *)skb->data; 1528 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_GET_TEMPERATURE_CMD) | 1529 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1530 cmd->pdev_id = ar->pdev->pdev_id; 1531 1532 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_GET_TEMPERATURE_CMDID); 1533 if (ret) { 1534 ath11k_warn(ar->ab, "failed to send WMI_PDEV_GET_TEMPERATURE cmd\n"); 1535 dev_kfree_skb(skb); 1536 } 1537 1538 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1539 "WMI pdev get temperature for pdev_id %d\n", ar->pdev->pdev_id); 1540 1541 return ret; 1542 } 1543 1544 int ath11k_wmi_send_bcn_offload_control_cmd(struct ath11k *ar, 1545 u32 vdev_id, u32 bcn_ctrl_op) 1546 { 1547 struct ath11k_pdev_wmi *wmi = ar->wmi; 1548 struct wmi_bcn_offload_ctrl_cmd *cmd; 1549 struct sk_buff *skb; 1550 int ret; 1551 1552 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1553 if (!skb) 1554 return -ENOMEM; 1555 1556 cmd = (struct wmi_bcn_offload_ctrl_cmd *)skb->data; 1557 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1558 WMI_TAG_BCN_OFFLOAD_CTRL_CMD) | 1559 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1560 1561 cmd->vdev_id = vdev_id; 1562 cmd->bcn_ctrl_op = bcn_ctrl_op; 1563 1564 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1565 "WMI bcn ctrl offload vdev id %d ctrl_op %d\n", 1566 vdev_id, bcn_ctrl_op); 1567 1568 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_OFFLOAD_CTRL_CMDID); 1569 if (ret) { 1570 ath11k_warn(ar->ab, 1571 "failed to send WMI_BCN_OFFLOAD_CTRL_CMDID\n"); 1572 dev_kfree_skb(skb); 1573 } 1574 1575 return ret; 1576 } 1577 1578 int ath11k_wmi_bcn_tmpl(struct ath11k *ar, u32 vdev_id, 1579 struct ieee80211_mutable_offsets *offs, 1580 struct sk_buff *bcn) 1581 { 1582 struct ath11k_pdev_wmi *wmi = ar->wmi; 1583 struct wmi_bcn_tmpl_cmd *cmd; 1584 struct wmi_bcn_prb_info *bcn_prb_info; 1585 struct wmi_tlv *tlv; 1586 struct sk_buff *skb; 1587 void *ptr; 1588 int ret, len; 1589 size_t aligned_len = roundup(bcn->len, 4); 1590 1591 len = sizeof(*cmd) + sizeof(*bcn_prb_info) + TLV_HDR_SIZE + aligned_len; 1592 1593 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 1594 if (!skb) 1595 return -ENOMEM; 1596 1597 cmd = (struct wmi_bcn_tmpl_cmd *)skb->data; 1598 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BCN_TMPL_CMD) | 1599 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1600 cmd->vdev_id = vdev_id; 1601 cmd->tim_ie_offset = offs->tim_offset; 1602 cmd->csa_switch_count_offset = offs->cntdwn_counter_offs[0]; 1603 cmd->ext_csa_switch_count_offset = offs->cntdwn_counter_offs[1]; 1604 cmd->buf_len = bcn->len; 1605 1606 ptr = skb->data + sizeof(*cmd); 1607 1608 bcn_prb_info = ptr; 1609 len = sizeof(*bcn_prb_info); 1610 bcn_prb_info->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1611 WMI_TAG_BCN_PRB_INFO) | 1612 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 1613 bcn_prb_info->caps = 0; 1614 bcn_prb_info->erp = 0; 1615 1616 ptr += sizeof(*bcn_prb_info); 1617 1618 tlv = ptr; 1619 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) | 1620 FIELD_PREP(WMI_TLV_LEN, aligned_len); 1621 memcpy(tlv->value, bcn->data, bcn->len); 1622 1623 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_TMPL_CMDID); 1624 if (ret) { 1625 ath11k_warn(ar->ab, "failed to send WMI_BCN_TMPL_CMDID\n"); 1626 dev_kfree_skb(skb); 1627 } 1628 1629 return ret; 1630 } 1631 1632 int ath11k_wmi_vdev_install_key(struct ath11k *ar, 1633 struct wmi_vdev_install_key_arg *arg) 1634 { 1635 struct ath11k_pdev_wmi *wmi = ar->wmi; 1636 struct wmi_vdev_install_key_cmd *cmd; 1637 struct wmi_tlv *tlv; 1638 struct sk_buff *skb; 1639 int ret, len; 1640 int key_len_aligned = roundup(arg->key_len, sizeof(uint32_t)); 1641 1642 len = sizeof(*cmd) + TLV_HDR_SIZE + key_len_aligned; 1643 1644 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 1645 if (!skb) 1646 return -ENOMEM; 1647 1648 cmd = (struct wmi_vdev_install_key_cmd *)skb->data; 1649 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_INSTALL_KEY_CMD) | 1650 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1651 cmd->vdev_id = arg->vdev_id; 1652 ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr); 1653 cmd->key_idx = arg->key_idx; 1654 cmd->key_flags = arg->key_flags; 1655 cmd->key_cipher = arg->key_cipher; 1656 cmd->key_len = arg->key_len; 1657 cmd->key_txmic_len = arg->key_txmic_len; 1658 cmd->key_rxmic_len = arg->key_rxmic_len; 1659 1660 if (arg->key_rsc_counter) 1661 memcpy(&cmd->key_rsc_counter, &arg->key_rsc_counter, 1662 sizeof(struct wmi_key_seq_counter)); 1663 1664 tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd)); 1665 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) | 1666 FIELD_PREP(WMI_TLV_LEN, key_len_aligned); 1667 memcpy(tlv->value, (u8 *)arg->key_data, key_len_aligned); 1668 1669 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_INSTALL_KEY_CMDID); 1670 if (ret) { 1671 ath11k_warn(ar->ab, 1672 "failed to send WMI_VDEV_INSTALL_KEY cmd\n"); 1673 dev_kfree_skb(skb); 1674 } 1675 1676 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1677 "WMI vdev install key idx %d cipher %d len %d\n", 1678 arg->key_idx, arg->key_cipher, arg->key_len); 1679 1680 return ret; 1681 } 1682 1683 static inline void 1684 ath11k_wmi_copy_peer_flags(struct wmi_peer_assoc_complete_cmd *cmd, 1685 struct peer_assoc_params *param) 1686 { 1687 cmd->peer_flags = 0; 1688 1689 if (param->is_wme_set) { 1690 if (param->qos_flag) 1691 cmd->peer_flags |= WMI_PEER_QOS; 1692 if (param->apsd_flag) 1693 cmd->peer_flags |= WMI_PEER_APSD; 1694 if (param->ht_flag) 1695 cmd->peer_flags |= WMI_PEER_HT; 1696 if (param->bw_40) 1697 cmd->peer_flags |= WMI_PEER_40MHZ; 1698 if (param->bw_80) 1699 cmd->peer_flags |= WMI_PEER_80MHZ; 1700 if (param->bw_160) 1701 cmd->peer_flags |= WMI_PEER_160MHZ; 1702 1703 /* Typically if STBC is enabled for VHT it should be enabled 1704 * for HT as well 1705 **/ 1706 if (param->stbc_flag) 1707 cmd->peer_flags |= WMI_PEER_STBC; 1708 1709 /* Typically if LDPC is enabled for VHT it should be enabled 1710 * for HT as well 1711 **/ 1712 if (param->ldpc_flag) 1713 cmd->peer_flags |= WMI_PEER_LDPC; 1714 1715 if (param->static_mimops_flag) 1716 cmd->peer_flags |= WMI_PEER_STATIC_MIMOPS; 1717 if (param->dynamic_mimops_flag) 1718 cmd->peer_flags |= WMI_PEER_DYN_MIMOPS; 1719 if (param->spatial_mux_flag) 1720 cmd->peer_flags |= WMI_PEER_SPATIAL_MUX; 1721 if (param->vht_flag) 1722 cmd->peer_flags |= WMI_PEER_VHT; 1723 if (param->he_flag) 1724 cmd->peer_flags |= WMI_PEER_HE; 1725 if (param->twt_requester) 1726 cmd->peer_flags |= WMI_PEER_TWT_REQ; 1727 if (param->twt_responder) 1728 cmd->peer_flags |= WMI_PEER_TWT_RESP; 1729 } 1730 1731 /* Suppress authorization for all AUTH modes that need 4-way handshake 1732 * (during re-association). 1733 * Authorization will be done for these modes on key installation. 1734 */ 1735 if (param->auth_flag) 1736 cmd->peer_flags |= WMI_PEER_AUTH; 1737 if (param->need_ptk_4_way) { 1738 cmd->peer_flags |= WMI_PEER_NEED_PTK_4_WAY; 1739 cmd->peer_flags &= ~WMI_PEER_AUTH; 1740 } 1741 if (param->need_gtk_2_way) 1742 cmd->peer_flags |= WMI_PEER_NEED_GTK_2_WAY; 1743 /* safe mode bypass the 4-way handshake */ 1744 if (param->safe_mode_enabled) 1745 cmd->peer_flags &= ~(WMI_PEER_NEED_PTK_4_WAY | 1746 WMI_PEER_NEED_GTK_2_WAY); 1747 1748 if (param->is_pmf_enabled) 1749 cmd->peer_flags |= WMI_PEER_PMF; 1750 1751 /* Disable AMSDU for station transmit, if user configures it */ 1752 /* Disable AMSDU for AP transmit to 11n Stations, if user configures 1753 * it 1754 * if (param->amsdu_disable) Add after FW support 1755 **/ 1756 1757 /* Target asserts if node is marked HT and all MCS is set to 0. 1758 * Mark the node as non-HT if all the mcs rates are disabled through 1759 * iwpriv 1760 **/ 1761 if (param->peer_ht_rates.num_rates == 0) 1762 cmd->peer_flags &= ~WMI_PEER_HT; 1763 } 1764 1765 int ath11k_wmi_send_peer_assoc_cmd(struct ath11k *ar, 1766 struct peer_assoc_params *param) 1767 { 1768 struct ath11k_pdev_wmi *wmi = ar->wmi; 1769 struct wmi_peer_assoc_complete_cmd *cmd; 1770 struct wmi_vht_rate_set *mcs; 1771 struct wmi_he_rate_set *he_mcs; 1772 struct sk_buff *skb; 1773 struct wmi_tlv *tlv; 1774 void *ptr; 1775 u32 peer_legacy_rates_align; 1776 u32 peer_ht_rates_align; 1777 int i, ret, len; 1778 1779 peer_legacy_rates_align = roundup(param->peer_legacy_rates.num_rates, 1780 sizeof(u32)); 1781 peer_ht_rates_align = roundup(param->peer_ht_rates.num_rates, 1782 sizeof(u32)); 1783 1784 len = sizeof(*cmd) + 1785 TLV_HDR_SIZE + (peer_legacy_rates_align * sizeof(u8)) + 1786 TLV_HDR_SIZE + (peer_ht_rates_align * sizeof(u8)) + 1787 sizeof(*mcs) + TLV_HDR_SIZE + 1788 (sizeof(*he_mcs) * param->peer_he_mcs_count); 1789 1790 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 1791 if (!skb) 1792 return -ENOMEM; 1793 1794 ptr = skb->data; 1795 1796 cmd = ptr; 1797 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1798 WMI_TAG_PEER_ASSOC_COMPLETE_CMD) | 1799 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1800 1801 cmd->vdev_id = param->vdev_id; 1802 1803 cmd->peer_new_assoc = param->peer_new_assoc; 1804 cmd->peer_associd = param->peer_associd; 1805 1806 ath11k_wmi_copy_peer_flags(cmd, param); 1807 1808 ether_addr_copy(cmd->peer_macaddr.addr, param->peer_mac); 1809 1810 cmd->peer_rate_caps = param->peer_rate_caps; 1811 cmd->peer_caps = param->peer_caps; 1812 cmd->peer_listen_intval = param->peer_listen_intval; 1813 cmd->peer_ht_caps = param->peer_ht_caps; 1814 cmd->peer_max_mpdu = param->peer_max_mpdu; 1815 cmd->peer_mpdu_density = param->peer_mpdu_density; 1816 cmd->peer_vht_caps = param->peer_vht_caps; 1817 cmd->peer_phymode = param->peer_phymode; 1818 1819 /* Update 11ax capabilities */ 1820 cmd->peer_he_cap_info = param->peer_he_cap_macinfo[0]; 1821 cmd->peer_he_cap_info_ext = param->peer_he_cap_macinfo[1]; 1822 cmd->peer_he_cap_info_internal = param->peer_he_cap_macinfo_internal; 1823 cmd->peer_he_caps_6ghz = param->peer_he_caps_6ghz; 1824 cmd->peer_he_ops = param->peer_he_ops; 1825 memcpy(&cmd->peer_he_cap_phy, ¶m->peer_he_cap_phyinfo, 1826 sizeof(param->peer_he_cap_phyinfo)); 1827 memcpy(&cmd->peer_ppet, ¶m->peer_ppet, 1828 sizeof(param->peer_ppet)); 1829 1830 /* Update peer legacy rate information */ 1831 ptr += sizeof(*cmd); 1832 1833 tlv = ptr; 1834 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) | 1835 FIELD_PREP(WMI_TLV_LEN, peer_legacy_rates_align); 1836 1837 ptr += TLV_HDR_SIZE; 1838 1839 cmd->num_peer_legacy_rates = param->peer_legacy_rates.num_rates; 1840 memcpy(ptr, param->peer_legacy_rates.rates, 1841 param->peer_legacy_rates.num_rates); 1842 1843 /* Update peer HT rate information */ 1844 ptr += peer_legacy_rates_align; 1845 1846 tlv = ptr; 1847 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) | 1848 FIELD_PREP(WMI_TLV_LEN, peer_ht_rates_align); 1849 ptr += TLV_HDR_SIZE; 1850 cmd->num_peer_ht_rates = param->peer_ht_rates.num_rates; 1851 memcpy(ptr, param->peer_ht_rates.rates, 1852 param->peer_ht_rates.num_rates); 1853 1854 /* VHT Rates */ 1855 ptr += peer_ht_rates_align; 1856 1857 mcs = ptr; 1858 1859 mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VHT_RATE_SET) | 1860 FIELD_PREP(WMI_TLV_LEN, sizeof(*mcs) - TLV_HDR_SIZE); 1861 1862 cmd->peer_nss = param->peer_nss; 1863 1864 /* Update bandwidth-NSS mapping */ 1865 cmd->peer_bw_rxnss_override = 0; 1866 cmd->peer_bw_rxnss_override |= param->peer_bw_rxnss_override; 1867 1868 if (param->vht_capable) { 1869 mcs->rx_max_rate = param->rx_max_rate; 1870 mcs->rx_mcs_set = param->rx_mcs_set; 1871 mcs->tx_max_rate = param->tx_max_rate; 1872 mcs->tx_mcs_set = param->tx_mcs_set; 1873 } 1874 1875 /* HE Rates */ 1876 cmd->peer_he_mcs = param->peer_he_mcs_count; 1877 cmd->min_data_rate = param->min_data_rate; 1878 1879 ptr += sizeof(*mcs); 1880 1881 len = param->peer_he_mcs_count * sizeof(*he_mcs); 1882 1883 tlv = ptr; 1884 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 1885 FIELD_PREP(WMI_TLV_LEN, len); 1886 ptr += TLV_HDR_SIZE; 1887 1888 /* Loop through the HE rate set */ 1889 for (i = 0; i < param->peer_he_mcs_count; i++) { 1890 he_mcs = ptr; 1891 he_mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1892 WMI_TAG_HE_RATE_SET) | 1893 FIELD_PREP(WMI_TLV_LEN, 1894 sizeof(*he_mcs) - TLV_HDR_SIZE); 1895 1896 he_mcs->rx_mcs_set = param->peer_he_rx_mcs_set[i]; 1897 he_mcs->tx_mcs_set = param->peer_he_tx_mcs_set[i]; 1898 ptr += sizeof(*he_mcs); 1899 } 1900 1901 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_ASSOC_CMDID); 1902 if (ret) { 1903 ath11k_warn(ar->ab, 1904 "failed to send WMI_PEER_ASSOC_CMDID\n"); 1905 dev_kfree_skb(skb); 1906 } 1907 1908 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1909 "wmi peer assoc vdev id %d assoc id %d peer mac %pM peer_flags %x rate_caps %x peer_caps %x listen_intval %d ht_caps %x max_mpdu %d nss %d phymode %d peer_mpdu_density %d vht_caps %x he cap_info %x he ops %x he cap_info_ext %x he phy %x %x %x peer_bw_rxnss_override %x\n", 1910 cmd->vdev_id, cmd->peer_associd, param->peer_mac, 1911 cmd->peer_flags, cmd->peer_rate_caps, cmd->peer_caps, 1912 cmd->peer_listen_intval, cmd->peer_ht_caps, 1913 cmd->peer_max_mpdu, cmd->peer_nss, cmd->peer_phymode, 1914 cmd->peer_mpdu_density, 1915 cmd->peer_vht_caps, cmd->peer_he_cap_info, 1916 cmd->peer_he_ops, cmd->peer_he_cap_info_ext, 1917 cmd->peer_he_cap_phy[0], cmd->peer_he_cap_phy[1], 1918 cmd->peer_he_cap_phy[2], 1919 cmd->peer_bw_rxnss_override); 1920 1921 return ret; 1922 } 1923 1924 void ath11k_wmi_start_scan_init(struct ath11k *ar, 1925 struct scan_req_params *arg) 1926 { 1927 /* setup commonly used values */ 1928 arg->scan_req_id = 1; 1929 arg->scan_priority = WMI_SCAN_PRIORITY_LOW; 1930 arg->dwell_time_active = 50; 1931 arg->dwell_time_active_2g = 0; 1932 arg->dwell_time_passive = 150; 1933 arg->dwell_time_active_6g = 40; 1934 arg->dwell_time_passive_6g = 30; 1935 arg->min_rest_time = 50; 1936 arg->max_rest_time = 500; 1937 arg->repeat_probe_time = 0; 1938 arg->probe_spacing_time = 0; 1939 arg->idle_time = 0; 1940 arg->max_scan_time = 20000; 1941 arg->probe_delay = 5; 1942 arg->notify_scan_events = WMI_SCAN_EVENT_STARTED | 1943 WMI_SCAN_EVENT_COMPLETED | 1944 WMI_SCAN_EVENT_BSS_CHANNEL | 1945 WMI_SCAN_EVENT_FOREIGN_CHAN | 1946 WMI_SCAN_EVENT_DEQUEUED; 1947 arg->scan_flags |= WMI_SCAN_CHAN_STAT_EVENT; 1948 arg->num_bssid = 1; 1949 } 1950 1951 static inline void 1952 ath11k_wmi_copy_scan_event_cntrl_flags(struct wmi_start_scan_cmd *cmd, 1953 struct scan_req_params *param) 1954 { 1955 /* Scan events subscription */ 1956 if (param->scan_ev_started) 1957 cmd->notify_scan_events |= WMI_SCAN_EVENT_STARTED; 1958 if (param->scan_ev_completed) 1959 cmd->notify_scan_events |= WMI_SCAN_EVENT_COMPLETED; 1960 if (param->scan_ev_bss_chan) 1961 cmd->notify_scan_events |= WMI_SCAN_EVENT_BSS_CHANNEL; 1962 if (param->scan_ev_foreign_chan) 1963 cmd->notify_scan_events |= WMI_SCAN_EVENT_FOREIGN_CHAN; 1964 if (param->scan_ev_dequeued) 1965 cmd->notify_scan_events |= WMI_SCAN_EVENT_DEQUEUED; 1966 if (param->scan_ev_preempted) 1967 cmd->notify_scan_events |= WMI_SCAN_EVENT_PREEMPTED; 1968 if (param->scan_ev_start_failed) 1969 cmd->notify_scan_events |= WMI_SCAN_EVENT_START_FAILED; 1970 if (param->scan_ev_restarted) 1971 cmd->notify_scan_events |= WMI_SCAN_EVENT_RESTARTED; 1972 if (param->scan_ev_foreign_chn_exit) 1973 cmd->notify_scan_events |= WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT; 1974 if (param->scan_ev_suspended) 1975 cmd->notify_scan_events |= WMI_SCAN_EVENT_SUSPENDED; 1976 if (param->scan_ev_resumed) 1977 cmd->notify_scan_events |= WMI_SCAN_EVENT_RESUMED; 1978 1979 /** Set scan control flags */ 1980 cmd->scan_ctrl_flags = 0; 1981 if (param->scan_f_passive) 1982 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; 1983 if (param->scan_f_strict_passive_pch) 1984 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_STRICT_PASSIVE_ON_PCHN; 1985 if (param->scan_f_promisc_mode) 1986 cmd->scan_ctrl_flags |= WMI_SCAN_FILTER_PROMISCUOS; 1987 if (param->scan_f_capture_phy_err) 1988 cmd->scan_ctrl_flags |= WMI_SCAN_CAPTURE_PHY_ERROR; 1989 if (param->scan_f_half_rate) 1990 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_HALF_RATE_SUPPORT; 1991 if (param->scan_f_quarter_rate) 1992 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_QUARTER_RATE_SUPPORT; 1993 if (param->scan_f_cck_rates) 1994 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES; 1995 if (param->scan_f_ofdm_rates) 1996 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_OFDM_RATES; 1997 if (param->scan_f_chan_stat_evnt) 1998 cmd->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT; 1999 if (param->scan_f_filter_prb_req) 2000 cmd->scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ; 2001 if (param->scan_f_bcast_probe) 2002 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_BCAST_PROBE_REQ; 2003 if (param->scan_f_offchan_mgmt_tx) 2004 cmd->scan_ctrl_flags |= WMI_SCAN_OFFCHAN_MGMT_TX; 2005 if (param->scan_f_offchan_data_tx) 2006 cmd->scan_ctrl_flags |= WMI_SCAN_OFFCHAN_DATA_TX; 2007 if (param->scan_f_force_active_dfs_chn) 2008 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_FORCE_ACTIVE_ON_DFS; 2009 if (param->scan_f_add_tpc_ie_in_probe) 2010 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_TPC_IE_IN_PROBE_REQ; 2011 if (param->scan_f_add_ds_ie_in_probe) 2012 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_DS_IE_IN_PROBE_REQ; 2013 if (param->scan_f_add_spoofed_mac_in_probe) 2014 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_SPOOF_MAC_IN_PROBE_REQ; 2015 if (param->scan_f_add_rand_seq_in_probe) 2016 cmd->scan_ctrl_flags |= WMI_SCAN_RANDOM_SEQ_NO_IN_PROBE_REQ; 2017 if (param->scan_f_en_ie_whitelist_in_probe) 2018 cmd->scan_ctrl_flags |= 2019 WMI_SCAN_ENABLE_IE_WHTELIST_IN_PROBE_REQ; 2020 2021 /* for adaptive scan mode using 3 bits (21 - 23 bits) */ 2022 WMI_SCAN_SET_DWELL_MODE(cmd->scan_ctrl_flags, 2023 param->adaptive_dwell_time_mode); 2024 } 2025 2026 int ath11k_wmi_send_scan_start_cmd(struct ath11k *ar, 2027 struct scan_req_params *params) 2028 { 2029 struct ath11k_pdev_wmi *wmi = ar->wmi; 2030 struct wmi_start_scan_cmd *cmd; 2031 struct wmi_ssid *ssid = NULL; 2032 struct wmi_mac_addr *bssid; 2033 struct sk_buff *skb; 2034 struct wmi_tlv *tlv; 2035 void *ptr; 2036 int i, ret, len; 2037 u32 *tmp_ptr; 2038 u8 extraie_len_with_pad = 0; 2039 struct hint_short_ssid *s_ssid = NULL; 2040 struct hint_bssid *hint_bssid = NULL; 2041 2042 len = sizeof(*cmd); 2043 2044 len += TLV_HDR_SIZE; 2045 if (params->num_chan) 2046 len += params->num_chan * sizeof(u32); 2047 2048 len += TLV_HDR_SIZE; 2049 if (params->num_ssids) 2050 len += params->num_ssids * sizeof(*ssid); 2051 2052 len += TLV_HDR_SIZE; 2053 if (params->num_bssid) 2054 len += sizeof(*bssid) * params->num_bssid; 2055 2056 len += TLV_HDR_SIZE; 2057 if (params->extraie.len) 2058 extraie_len_with_pad = 2059 roundup(params->extraie.len, sizeof(u32)); 2060 len += extraie_len_with_pad; 2061 2062 if (params->num_hint_bssid) 2063 len += TLV_HDR_SIZE + 2064 params->num_hint_bssid * sizeof(struct hint_bssid); 2065 2066 if (params->num_hint_s_ssid) 2067 len += TLV_HDR_SIZE + 2068 params->num_hint_s_ssid * sizeof(struct hint_short_ssid); 2069 2070 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 2071 if (!skb) 2072 return -ENOMEM; 2073 2074 ptr = skb->data; 2075 2076 cmd = ptr; 2077 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_START_SCAN_CMD) | 2078 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2079 2080 cmd->scan_id = params->scan_id; 2081 cmd->scan_req_id = params->scan_req_id; 2082 cmd->vdev_id = params->vdev_id; 2083 cmd->scan_priority = params->scan_priority; 2084 cmd->notify_scan_events = params->notify_scan_events; 2085 2086 ath11k_wmi_copy_scan_event_cntrl_flags(cmd, params); 2087 2088 cmd->dwell_time_active = params->dwell_time_active; 2089 cmd->dwell_time_active_2g = params->dwell_time_active_2g; 2090 cmd->dwell_time_passive = params->dwell_time_passive; 2091 cmd->dwell_time_active_6g = params->dwell_time_active_6g; 2092 cmd->dwell_time_passive_6g = params->dwell_time_passive_6g; 2093 cmd->min_rest_time = params->min_rest_time; 2094 cmd->max_rest_time = params->max_rest_time; 2095 cmd->repeat_probe_time = params->repeat_probe_time; 2096 cmd->probe_spacing_time = params->probe_spacing_time; 2097 cmd->idle_time = params->idle_time; 2098 cmd->max_scan_time = params->max_scan_time; 2099 cmd->probe_delay = params->probe_delay; 2100 cmd->burst_duration = params->burst_duration; 2101 cmd->num_chan = params->num_chan; 2102 cmd->num_bssid = params->num_bssid; 2103 cmd->num_ssids = params->num_ssids; 2104 cmd->ie_len = params->extraie.len; 2105 cmd->n_probes = params->n_probes; 2106 2107 ptr += sizeof(*cmd); 2108 2109 len = params->num_chan * sizeof(u32); 2110 2111 tlv = ptr; 2112 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) | 2113 FIELD_PREP(WMI_TLV_LEN, len); 2114 ptr += TLV_HDR_SIZE; 2115 tmp_ptr = (u32 *)ptr; 2116 2117 for (i = 0; i < params->num_chan; ++i) 2118 tmp_ptr[i] = params->chan_list[i]; 2119 2120 ptr += len; 2121 2122 len = params->num_ssids * sizeof(*ssid); 2123 tlv = ptr; 2124 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) | 2125 FIELD_PREP(WMI_TLV_LEN, len); 2126 2127 ptr += TLV_HDR_SIZE; 2128 2129 if (params->num_ssids) { 2130 ssid = ptr; 2131 for (i = 0; i < params->num_ssids; ++i) { 2132 ssid->ssid_len = params->ssid[i].length; 2133 memcpy(ssid->ssid, params->ssid[i].ssid, 2134 params->ssid[i].length); 2135 ssid++; 2136 } 2137 } 2138 2139 ptr += (params->num_ssids * sizeof(*ssid)); 2140 len = params->num_bssid * sizeof(*bssid); 2141 tlv = ptr; 2142 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) | 2143 FIELD_PREP(WMI_TLV_LEN, len); 2144 2145 ptr += TLV_HDR_SIZE; 2146 bssid = ptr; 2147 2148 if (params->num_bssid) { 2149 for (i = 0; i < params->num_bssid; ++i) { 2150 ether_addr_copy(bssid->addr, 2151 params->bssid_list[i].addr); 2152 bssid++; 2153 } 2154 } 2155 2156 ptr += params->num_bssid * sizeof(*bssid); 2157 2158 len = extraie_len_with_pad; 2159 tlv = ptr; 2160 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) | 2161 FIELD_PREP(WMI_TLV_LEN, len); 2162 ptr += TLV_HDR_SIZE; 2163 2164 if (params->extraie.len) 2165 memcpy(ptr, params->extraie.ptr, 2166 params->extraie.len); 2167 2168 ptr += extraie_len_with_pad; 2169 2170 if (params->num_hint_s_ssid) { 2171 len = params->num_hint_s_ssid * sizeof(struct hint_short_ssid); 2172 tlv = ptr; 2173 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) | 2174 FIELD_PREP(WMI_TLV_LEN, len); 2175 ptr += TLV_HDR_SIZE; 2176 s_ssid = ptr; 2177 for (i = 0; i < params->num_hint_s_ssid; ++i) { 2178 s_ssid->freq_flags = params->hint_s_ssid[i].freq_flags; 2179 s_ssid->short_ssid = params->hint_s_ssid[i].short_ssid; 2180 s_ssid++; 2181 } 2182 ptr += len; 2183 } 2184 2185 if (params->num_hint_bssid) { 2186 len = params->num_hint_bssid * sizeof(struct hint_bssid); 2187 tlv = ptr; 2188 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) | 2189 FIELD_PREP(WMI_TLV_LEN, len); 2190 ptr += TLV_HDR_SIZE; 2191 hint_bssid = ptr; 2192 for (i = 0; i < params->num_hint_bssid; ++i) { 2193 hint_bssid->freq_flags = 2194 params->hint_bssid[i].freq_flags; 2195 ether_addr_copy(¶ms->hint_bssid[i].bssid.addr[0], 2196 &hint_bssid->bssid.addr[0]); 2197 hint_bssid++; 2198 } 2199 } 2200 2201 len = params->num_hint_s_ssid * sizeof(struct hint_short_ssid); 2202 tlv = ptr; 2203 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) | 2204 FIELD_PREP(WMI_TLV_LEN, len); 2205 ptr += TLV_HDR_SIZE; 2206 if (params->num_hint_s_ssid) { 2207 s_ssid = ptr; 2208 for (i = 0; i < params->num_hint_s_ssid; ++i) { 2209 s_ssid->freq_flags = params->hint_s_ssid[i].freq_flags; 2210 s_ssid->short_ssid = params->hint_s_ssid[i].short_ssid; 2211 s_ssid++; 2212 } 2213 } 2214 ptr += len; 2215 2216 len = params->num_hint_bssid * sizeof(struct hint_bssid); 2217 tlv = ptr; 2218 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) | 2219 FIELD_PREP(WMI_TLV_LEN, len); 2220 ptr += TLV_HDR_SIZE; 2221 if (params->num_hint_bssid) { 2222 hint_bssid = ptr; 2223 for (i = 0; i < params->num_hint_bssid; ++i) { 2224 hint_bssid->freq_flags = 2225 params->hint_bssid[i].freq_flags; 2226 ether_addr_copy(¶ms->hint_bssid[i].bssid.addr[0], 2227 &hint_bssid->bssid.addr[0]); 2228 hint_bssid++; 2229 } 2230 } 2231 2232 ret = ath11k_wmi_cmd_send(wmi, skb, 2233 WMI_START_SCAN_CMDID); 2234 if (ret) { 2235 ath11k_warn(ar->ab, "failed to send WMI_START_SCAN_CMDID\n"); 2236 dev_kfree_skb(skb); 2237 } 2238 2239 return ret; 2240 } 2241 2242 int ath11k_wmi_send_scan_stop_cmd(struct ath11k *ar, 2243 struct scan_cancel_param *param) 2244 { 2245 struct ath11k_pdev_wmi *wmi = ar->wmi; 2246 struct wmi_stop_scan_cmd *cmd; 2247 struct sk_buff *skb; 2248 int ret; 2249 2250 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2251 if (!skb) 2252 return -ENOMEM; 2253 2254 cmd = (struct wmi_stop_scan_cmd *)skb->data; 2255 2256 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STOP_SCAN_CMD) | 2257 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2258 2259 cmd->vdev_id = param->vdev_id; 2260 cmd->requestor = param->requester; 2261 cmd->scan_id = param->scan_id; 2262 cmd->pdev_id = param->pdev_id; 2263 /* stop the scan with the corresponding scan_id */ 2264 if (param->req_type == WLAN_SCAN_CANCEL_PDEV_ALL) { 2265 /* Cancelling all scans */ 2266 cmd->req_type = WMI_SCAN_STOP_ALL; 2267 } else if (param->req_type == WLAN_SCAN_CANCEL_VDEV_ALL) { 2268 /* Cancelling VAP scans */ 2269 cmd->req_type = WMI_SCN_STOP_VAP_ALL; 2270 } else if (param->req_type == WLAN_SCAN_CANCEL_SINGLE) { 2271 /* Cancelling specific scan */ 2272 cmd->req_type = WMI_SCAN_STOP_ONE; 2273 } else { 2274 ath11k_warn(ar->ab, "invalid scan cancel param %d", 2275 param->req_type); 2276 dev_kfree_skb(skb); 2277 return -EINVAL; 2278 } 2279 2280 ret = ath11k_wmi_cmd_send(wmi, skb, 2281 WMI_STOP_SCAN_CMDID); 2282 if (ret) { 2283 ath11k_warn(ar->ab, "failed to send WMI_STOP_SCAN_CMDID\n"); 2284 dev_kfree_skb(skb); 2285 } 2286 2287 return ret; 2288 } 2289 2290 int ath11k_wmi_send_scan_chan_list_cmd(struct ath11k *ar, 2291 struct scan_chan_list_params *chan_list) 2292 { 2293 struct ath11k_pdev_wmi *wmi = ar->wmi; 2294 struct wmi_scan_chan_list_cmd *cmd; 2295 struct sk_buff *skb; 2296 struct wmi_channel *chan_info; 2297 struct channel_param *tchan_info; 2298 struct wmi_tlv *tlv; 2299 void *ptr; 2300 int i, ret, len; 2301 u16 num_send_chans, num_sends = 0, max_chan_limit = 0; 2302 u32 *reg1, *reg2; 2303 2304 tchan_info = &chan_list->ch_param[0]; 2305 while (chan_list->nallchans) { 2306 len = sizeof(*cmd) + TLV_HDR_SIZE; 2307 max_chan_limit = (wmi->wmi_ab->max_msg_len[ar->pdev_idx] - len) / 2308 sizeof(*chan_info); 2309 2310 if (chan_list->nallchans > max_chan_limit) 2311 num_send_chans = max_chan_limit; 2312 else 2313 num_send_chans = chan_list->nallchans; 2314 2315 chan_list->nallchans -= num_send_chans; 2316 len += sizeof(*chan_info) * num_send_chans; 2317 2318 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 2319 if (!skb) 2320 return -ENOMEM; 2321 2322 cmd = (struct wmi_scan_chan_list_cmd *)skb->data; 2323 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_SCAN_CHAN_LIST_CMD) | 2324 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2325 cmd->pdev_id = chan_list->pdev_id; 2326 cmd->num_scan_chans = num_send_chans; 2327 if (num_sends) 2328 cmd->flags |= WMI_APPEND_TO_EXISTING_CHAN_LIST_FLAG; 2329 2330 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 2331 "WMI no.of chan = %d len = %d pdev_id = %d num_sends = %d\n", 2332 num_send_chans, len, cmd->pdev_id, num_sends); 2333 2334 ptr = skb->data + sizeof(*cmd); 2335 2336 len = sizeof(*chan_info) * num_send_chans; 2337 tlv = ptr; 2338 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 2339 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 2340 ptr += TLV_HDR_SIZE; 2341 2342 for (i = 0; i < num_send_chans; ++i) { 2343 chan_info = ptr; 2344 memset(chan_info, 0, sizeof(*chan_info)); 2345 len = sizeof(*chan_info); 2346 chan_info->tlv_header = FIELD_PREP(WMI_TLV_TAG, 2347 WMI_TAG_CHANNEL) | 2348 FIELD_PREP(WMI_TLV_LEN, 2349 len - TLV_HDR_SIZE); 2350 2351 reg1 = &chan_info->reg_info_1; 2352 reg2 = &chan_info->reg_info_2; 2353 chan_info->mhz = tchan_info->mhz; 2354 chan_info->band_center_freq1 = tchan_info->cfreq1; 2355 chan_info->band_center_freq2 = tchan_info->cfreq2; 2356 2357 if (tchan_info->is_chan_passive) 2358 chan_info->info |= WMI_CHAN_INFO_PASSIVE; 2359 if (tchan_info->allow_he) 2360 chan_info->info |= WMI_CHAN_INFO_ALLOW_HE; 2361 else if (tchan_info->allow_vht) 2362 chan_info->info |= WMI_CHAN_INFO_ALLOW_VHT; 2363 else if (tchan_info->allow_ht) 2364 chan_info->info |= WMI_CHAN_INFO_ALLOW_HT; 2365 if (tchan_info->half_rate) 2366 chan_info->info |= WMI_CHAN_INFO_HALF_RATE; 2367 if (tchan_info->quarter_rate) 2368 chan_info->info |= WMI_CHAN_INFO_QUARTER_RATE; 2369 if (tchan_info->psc_channel) 2370 chan_info->info |= WMI_CHAN_INFO_PSC; 2371 2372 chan_info->info |= FIELD_PREP(WMI_CHAN_INFO_MODE, 2373 tchan_info->phy_mode); 2374 *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MIN_PWR, 2375 tchan_info->minpower); 2376 *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR, 2377 tchan_info->maxpower); 2378 *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR, 2379 tchan_info->maxregpower); 2380 *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_REG_CLS, 2381 tchan_info->reg_class_id); 2382 *reg2 |= FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX, 2383 tchan_info->antennamax); 2384 2385 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 2386 "WMI chan scan list chan[%d] = %u, chan_info->info %8x\n", 2387 i, chan_info->mhz, chan_info->info); 2388 2389 ptr += sizeof(*chan_info); 2390 2391 tchan_info++; 2392 } 2393 2394 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_SCAN_CHAN_LIST_CMDID); 2395 if (ret) { 2396 ath11k_warn(ar->ab, "failed to send WMI_SCAN_CHAN_LIST cmd\n"); 2397 dev_kfree_skb(skb); 2398 return ret; 2399 } 2400 2401 num_sends++; 2402 } 2403 2404 return 0; 2405 } 2406 2407 int ath11k_wmi_send_wmm_update_cmd_tlv(struct ath11k *ar, u32 vdev_id, 2408 struct wmi_wmm_params_all_arg *param) 2409 { 2410 struct ath11k_pdev_wmi *wmi = ar->wmi; 2411 struct wmi_vdev_set_wmm_params_cmd *cmd; 2412 struct wmi_wmm_params *wmm_param; 2413 struct wmi_wmm_params_arg *wmi_wmm_arg; 2414 struct sk_buff *skb; 2415 int ret, ac; 2416 2417 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2418 if (!skb) 2419 return -ENOMEM; 2420 2421 cmd = (struct wmi_vdev_set_wmm_params_cmd *)skb->data; 2422 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 2423 WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) | 2424 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2425 2426 cmd->vdev_id = vdev_id; 2427 cmd->wmm_param_type = 0; 2428 2429 for (ac = 0; ac < WME_NUM_AC; ac++) { 2430 switch (ac) { 2431 case WME_AC_BE: 2432 wmi_wmm_arg = ¶m->ac_be; 2433 break; 2434 case WME_AC_BK: 2435 wmi_wmm_arg = ¶m->ac_bk; 2436 break; 2437 case WME_AC_VI: 2438 wmi_wmm_arg = ¶m->ac_vi; 2439 break; 2440 case WME_AC_VO: 2441 wmi_wmm_arg = ¶m->ac_vo; 2442 break; 2443 } 2444 2445 wmm_param = (struct wmi_wmm_params *)&cmd->wmm_params[ac]; 2446 wmm_param->tlv_header = 2447 FIELD_PREP(WMI_TLV_TAG, 2448 WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) | 2449 FIELD_PREP(WMI_TLV_LEN, 2450 sizeof(*wmm_param) - TLV_HDR_SIZE); 2451 2452 wmm_param->aifs = wmi_wmm_arg->aifs; 2453 wmm_param->cwmin = wmi_wmm_arg->cwmin; 2454 wmm_param->cwmax = wmi_wmm_arg->cwmax; 2455 wmm_param->txoplimit = wmi_wmm_arg->txop; 2456 wmm_param->acm = wmi_wmm_arg->acm; 2457 wmm_param->no_ack = wmi_wmm_arg->no_ack; 2458 2459 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 2460 "wmi wmm set ac %d aifs %d cwmin %d cwmax %d txop %d acm %d no_ack %d\n", 2461 ac, wmm_param->aifs, wmm_param->cwmin, 2462 wmm_param->cwmax, wmm_param->txoplimit, 2463 wmm_param->acm, wmm_param->no_ack); 2464 } 2465 ret = ath11k_wmi_cmd_send(wmi, skb, 2466 WMI_VDEV_SET_WMM_PARAMS_CMDID); 2467 if (ret) { 2468 ath11k_warn(ar->ab, 2469 "failed to send WMI_VDEV_SET_WMM_PARAMS_CMDID"); 2470 dev_kfree_skb(skb); 2471 } 2472 2473 return ret; 2474 } 2475 2476 int ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(struct ath11k *ar, 2477 u32 pdev_id) 2478 { 2479 struct ath11k_pdev_wmi *wmi = ar->wmi; 2480 struct wmi_dfs_phyerr_offload_cmd *cmd; 2481 struct sk_buff *skb; 2482 int ret; 2483 2484 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2485 if (!skb) 2486 return -ENOMEM; 2487 2488 cmd = (struct wmi_dfs_phyerr_offload_cmd *)skb->data; 2489 cmd->tlv_header = 2490 FIELD_PREP(WMI_TLV_TAG, 2491 WMI_TAG_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMD) | 2492 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2493 2494 cmd->pdev_id = pdev_id; 2495 2496 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 2497 "WMI dfs phy err offload enable pdev id %d\n", pdev_id); 2498 2499 ret = ath11k_wmi_cmd_send(wmi, skb, 2500 WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMDID); 2501 if (ret) { 2502 ath11k_warn(ar->ab, 2503 "failed to send WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE cmd\n"); 2504 dev_kfree_skb(skb); 2505 } 2506 2507 return ret; 2508 } 2509 2510 int ath11k_wmi_delba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac, 2511 u32 tid, u32 initiator, u32 reason) 2512 { 2513 struct ath11k_pdev_wmi *wmi = ar->wmi; 2514 struct wmi_delba_send_cmd *cmd; 2515 struct sk_buff *skb; 2516 int ret; 2517 2518 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2519 if (!skb) 2520 return -ENOMEM; 2521 2522 cmd = (struct wmi_delba_send_cmd *)skb->data; 2523 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DELBA_SEND_CMD) | 2524 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2525 cmd->vdev_id = vdev_id; 2526 ether_addr_copy(cmd->peer_macaddr.addr, mac); 2527 cmd->tid = tid; 2528 cmd->initiator = initiator; 2529 cmd->reasoncode = reason; 2530 2531 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 2532 "wmi delba send vdev_id 0x%X mac_addr %pM tid %u initiator %u reason %u\n", 2533 vdev_id, mac, tid, initiator, reason); 2534 2535 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_DELBA_SEND_CMDID); 2536 2537 if (ret) { 2538 ath11k_warn(ar->ab, 2539 "failed to send WMI_DELBA_SEND_CMDID cmd\n"); 2540 dev_kfree_skb(skb); 2541 } 2542 2543 return ret; 2544 } 2545 2546 int ath11k_wmi_addba_set_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac, 2547 u32 tid, u32 status) 2548 { 2549 struct ath11k_pdev_wmi *wmi = ar->wmi; 2550 struct wmi_addba_setresponse_cmd *cmd; 2551 struct sk_buff *skb; 2552 int ret; 2553 2554 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2555 if (!skb) 2556 return -ENOMEM; 2557 2558 cmd = (struct wmi_addba_setresponse_cmd *)skb->data; 2559 cmd->tlv_header = 2560 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SETRESPONSE_CMD) | 2561 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2562 cmd->vdev_id = vdev_id; 2563 ether_addr_copy(cmd->peer_macaddr.addr, mac); 2564 cmd->tid = tid; 2565 cmd->statuscode = status; 2566 2567 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 2568 "wmi addba set resp vdev_id 0x%X mac_addr %pM tid %u status %u\n", 2569 vdev_id, mac, tid, status); 2570 2571 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SET_RESP_CMDID); 2572 2573 if (ret) { 2574 ath11k_warn(ar->ab, 2575 "failed to send WMI_ADDBA_SET_RESP_CMDID cmd\n"); 2576 dev_kfree_skb(skb); 2577 } 2578 2579 return ret; 2580 } 2581 2582 int ath11k_wmi_addba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac, 2583 u32 tid, u32 buf_size) 2584 { 2585 struct ath11k_pdev_wmi *wmi = ar->wmi; 2586 struct wmi_addba_send_cmd *cmd; 2587 struct sk_buff *skb; 2588 int ret; 2589 2590 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2591 if (!skb) 2592 return -ENOMEM; 2593 2594 cmd = (struct wmi_addba_send_cmd *)skb->data; 2595 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SEND_CMD) | 2596 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2597 cmd->vdev_id = vdev_id; 2598 ether_addr_copy(cmd->peer_macaddr.addr, mac); 2599 cmd->tid = tid; 2600 cmd->buffersize = buf_size; 2601 2602 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 2603 "wmi addba send vdev_id 0x%X mac_addr %pM tid %u bufsize %u\n", 2604 vdev_id, mac, tid, buf_size); 2605 2606 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SEND_CMDID); 2607 2608 if (ret) { 2609 ath11k_warn(ar->ab, 2610 "failed to send WMI_ADDBA_SEND_CMDID cmd\n"); 2611 dev_kfree_skb(skb); 2612 } 2613 2614 return ret; 2615 } 2616 2617 int ath11k_wmi_addba_clear_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac) 2618 { 2619 struct ath11k_pdev_wmi *wmi = ar->wmi; 2620 struct wmi_addba_clear_resp_cmd *cmd; 2621 struct sk_buff *skb; 2622 int ret; 2623 2624 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2625 if (!skb) 2626 return -ENOMEM; 2627 2628 cmd = (struct wmi_addba_clear_resp_cmd *)skb->data; 2629 cmd->tlv_header = 2630 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_CLEAR_RESP_CMD) | 2631 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2632 cmd->vdev_id = vdev_id; 2633 ether_addr_copy(cmd->peer_macaddr.addr, mac); 2634 2635 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 2636 "wmi addba clear resp vdev_id 0x%X mac_addr %pM\n", 2637 vdev_id, mac); 2638 2639 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_CLEAR_RESP_CMDID); 2640 2641 if (ret) { 2642 ath11k_warn(ar->ab, 2643 "failed to send WMI_ADDBA_CLEAR_RESP_CMDID cmd\n"); 2644 dev_kfree_skb(skb); 2645 } 2646 2647 return ret; 2648 } 2649 2650 int ath11k_wmi_pdev_peer_pktlog_filter(struct ath11k *ar, u8 *addr, u8 enable) 2651 { 2652 struct ath11k_pdev_wmi *wmi = ar->wmi; 2653 struct wmi_pdev_pktlog_filter_cmd *cmd; 2654 struct wmi_pdev_pktlog_filter_info *info; 2655 struct sk_buff *skb; 2656 struct wmi_tlv *tlv; 2657 void *ptr; 2658 int ret, len; 2659 2660 len = sizeof(*cmd) + sizeof(*info) + TLV_HDR_SIZE; 2661 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 2662 if (!skb) 2663 return -ENOMEM; 2664 2665 cmd = (struct wmi_pdev_pktlog_filter_cmd *)skb->data; 2666 2667 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_CMD) | 2668 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2669 2670 cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id); 2671 cmd->num_mac = 1; 2672 cmd->enable = enable; 2673 2674 ptr = skb->data + sizeof(*cmd); 2675 2676 tlv = ptr; 2677 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 2678 FIELD_PREP(WMI_TLV_LEN, sizeof(*info)); 2679 2680 ptr += TLV_HDR_SIZE; 2681 info = ptr; 2682 2683 ether_addr_copy(info->peer_macaddr.addr, addr); 2684 info->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_INFO) | 2685 FIELD_PREP(WMI_TLV_LEN, 2686 sizeof(*info) - TLV_HDR_SIZE); 2687 2688 ret = ath11k_wmi_cmd_send(wmi, skb, 2689 WMI_PDEV_PKTLOG_FILTER_CMDID); 2690 if (ret) { 2691 ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n"); 2692 dev_kfree_skb(skb); 2693 } 2694 2695 return ret; 2696 } 2697 2698 int 2699 ath11k_wmi_send_init_country_cmd(struct ath11k *ar, 2700 struct wmi_init_country_params init_cc_params) 2701 { 2702 struct ath11k_pdev_wmi *wmi = ar->wmi; 2703 struct wmi_init_country_cmd *cmd; 2704 struct sk_buff *skb; 2705 int ret; 2706 2707 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2708 if (!skb) 2709 return -ENOMEM; 2710 2711 cmd = (struct wmi_init_country_cmd *)skb->data; 2712 cmd->tlv_header = 2713 FIELD_PREP(WMI_TLV_TAG, 2714 WMI_TAG_SET_INIT_COUNTRY_CMD) | 2715 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2716 2717 cmd->pdev_id = ar->pdev->pdev_id; 2718 2719 switch (init_cc_params.flags) { 2720 case ALPHA_IS_SET: 2721 cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_ALPHA; 2722 memcpy((u8 *)&cmd->cc_info.alpha2, 2723 init_cc_params.cc_info.alpha2, 3); 2724 break; 2725 case CC_IS_SET: 2726 cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_COUNTRY_CODE; 2727 cmd->cc_info.country_code = init_cc_params.cc_info.country_code; 2728 break; 2729 case REGDMN_IS_SET: 2730 cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_REGDOMAIN; 2731 cmd->cc_info.regdom_id = init_cc_params.cc_info.regdom_id; 2732 break; 2733 default: 2734 ret = -EINVAL; 2735 goto out; 2736 } 2737 2738 ret = ath11k_wmi_cmd_send(wmi, skb, 2739 WMI_SET_INIT_COUNTRY_CMDID); 2740 2741 out: 2742 if (ret) { 2743 ath11k_warn(ar->ab, 2744 "failed to send WMI_SET_INIT_COUNTRY CMD :%d\n", 2745 ret); 2746 dev_kfree_skb(skb); 2747 } 2748 2749 return ret; 2750 } 2751 2752 int 2753 ath11k_wmi_send_thermal_mitigation_param_cmd(struct ath11k *ar, 2754 struct thermal_mitigation_params *param) 2755 { 2756 struct ath11k_pdev_wmi *wmi = ar->wmi; 2757 struct wmi_therm_throt_config_request_cmd *cmd; 2758 struct wmi_therm_throt_level_config_info *lvl_conf; 2759 struct wmi_tlv *tlv; 2760 struct sk_buff *skb; 2761 int i, ret, len; 2762 2763 len = sizeof(*cmd) + TLV_HDR_SIZE + 2764 THERMAL_LEVELS * sizeof(struct wmi_therm_throt_level_config_info); 2765 2766 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 2767 if (!skb) 2768 return -ENOMEM; 2769 2770 cmd = (struct wmi_therm_throt_config_request_cmd *)skb->data; 2771 2772 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_CONFIG_REQUEST) | 2773 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2774 2775 cmd->pdev_id = ar->pdev->pdev_id; 2776 cmd->enable = param->enable; 2777 cmd->dc = param->dc; 2778 cmd->dc_per_event = param->dc_per_event; 2779 cmd->therm_throt_levels = THERMAL_LEVELS; 2780 2781 tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd)); 2782 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 2783 FIELD_PREP(WMI_TLV_LEN, 2784 (THERMAL_LEVELS * 2785 sizeof(struct wmi_therm_throt_level_config_info))); 2786 2787 lvl_conf = (struct wmi_therm_throt_level_config_info *)(skb->data + 2788 sizeof(*cmd) + 2789 TLV_HDR_SIZE); 2790 for (i = 0; i < THERMAL_LEVELS; i++) { 2791 lvl_conf->tlv_header = 2792 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_LEVEL_CONFIG_INFO) | 2793 FIELD_PREP(WMI_TLV_LEN, sizeof(*lvl_conf) - TLV_HDR_SIZE); 2794 2795 lvl_conf->temp_lwm = param->levelconf[i].tmplwm; 2796 lvl_conf->temp_hwm = param->levelconf[i].tmphwm; 2797 lvl_conf->dc_off_percent = param->levelconf[i].dcoffpercent; 2798 lvl_conf->prio = param->levelconf[i].priority; 2799 lvl_conf++; 2800 } 2801 2802 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_THERM_THROT_SET_CONF_CMDID); 2803 if (ret) { 2804 ath11k_warn(ar->ab, "failed to send THERM_THROT_SET_CONF cmd\n"); 2805 dev_kfree_skb(skb); 2806 } 2807 2808 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 2809 "WMI vdev set thermal throt pdev_id %d enable %d dc %d dc_per_event %x levels %d\n", 2810 ar->pdev->pdev_id, param->enable, param->dc, 2811 param->dc_per_event, THERMAL_LEVELS); 2812 2813 return ret; 2814 } 2815 2816 int ath11k_wmi_pdev_pktlog_enable(struct ath11k *ar, u32 pktlog_filter) 2817 { 2818 struct ath11k_pdev_wmi *wmi = ar->wmi; 2819 struct wmi_pktlog_enable_cmd *cmd; 2820 struct sk_buff *skb; 2821 int ret; 2822 2823 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2824 if (!skb) 2825 return -ENOMEM; 2826 2827 cmd = (struct wmi_pktlog_enable_cmd *)skb->data; 2828 2829 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_ENABLE_CMD) | 2830 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2831 2832 cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id); 2833 cmd->evlist = pktlog_filter; 2834 cmd->enable = ATH11K_WMI_PKTLOG_ENABLE_FORCE; 2835 2836 ret = ath11k_wmi_cmd_send(wmi, skb, 2837 WMI_PDEV_PKTLOG_ENABLE_CMDID); 2838 if (ret) { 2839 ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n"); 2840 dev_kfree_skb(skb); 2841 } 2842 2843 return ret; 2844 } 2845 2846 int ath11k_wmi_pdev_pktlog_disable(struct ath11k *ar) 2847 { 2848 struct ath11k_pdev_wmi *wmi = ar->wmi; 2849 struct wmi_pktlog_disable_cmd *cmd; 2850 struct sk_buff *skb; 2851 int ret; 2852 2853 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2854 if (!skb) 2855 return -ENOMEM; 2856 2857 cmd = (struct wmi_pktlog_disable_cmd *)skb->data; 2858 2859 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_DISABLE_CMD) | 2860 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2861 2862 cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id); 2863 2864 ret = ath11k_wmi_cmd_send(wmi, skb, 2865 WMI_PDEV_PKTLOG_DISABLE_CMDID); 2866 if (ret) { 2867 ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n"); 2868 dev_kfree_skb(skb); 2869 } 2870 2871 return ret; 2872 } 2873 2874 int 2875 ath11k_wmi_send_twt_enable_cmd(struct ath11k *ar, u32 pdev_id) 2876 { 2877 struct ath11k_pdev_wmi *wmi = ar->wmi; 2878 struct ath11k_base *ab = wmi->wmi_ab->ab; 2879 struct wmi_twt_enable_params_cmd *cmd; 2880 struct sk_buff *skb; 2881 int ret, len; 2882 2883 len = sizeof(*cmd); 2884 2885 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 2886 if (!skb) 2887 return -ENOMEM; 2888 2889 cmd = (struct wmi_twt_enable_params_cmd *)skb->data; 2890 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_ENABLE_CMD) | 2891 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 2892 cmd->pdev_id = pdev_id; 2893 cmd->sta_cong_timer_ms = ATH11K_TWT_DEF_STA_CONG_TIMER_MS; 2894 cmd->default_slot_size = ATH11K_TWT_DEF_DEFAULT_SLOT_SIZE; 2895 cmd->congestion_thresh_setup = ATH11K_TWT_DEF_CONGESTION_THRESH_SETUP; 2896 cmd->congestion_thresh_teardown = 2897 ATH11K_TWT_DEF_CONGESTION_THRESH_TEARDOWN; 2898 cmd->congestion_thresh_critical = 2899 ATH11K_TWT_DEF_CONGESTION_THRESH_CRITICAL; 2900 cmd->interference_thresh_teardown = 2901 ATH11K_TWT_DEF_INTERFERENCE_THRESH_TEARDOWN; 2902 cmd->interference_thresh_setup = 2903 ATH11K_TWT_DEF_INTERFERENCE_THRESH_SETUP; 2904 cmd->min_no_sta_setup = ATH11K_TWT_DEF_MIN_NO_STA_SETUP; 2905 cmd->min_no_sta_teardown = ATH11K_TWT_DEF_MIN_NO_STA_TEARDOWN; 2906 cmd->no_of_bcast_mcast_slots = ATH11K_TWT_DEF_NO_OF_BCAST_MCAST_SLOTS; 2907 cmd->min_no_twt_slots = ATH11K_TWT_DEF_MIN_NO_TWT_SLOTS; 2908 cmd->max_no_sta_twt = ATH11K_TWT_DEF_MAX_NO_STA_TWT; 2909 cmd->mode_check_interval = ATH11K_TWT_DEF_MODE_CHECK_INTERVAL; 2910 cmd->add_sta_slot_interval = ATH11K_TWT_DEF_ADD_STA_SLOT_INTERVAL; 2911 cmd->remove_sta_slot_interval = 2912 ATH11K_TWT_DEF_REMOVE_STA_SLOT_INTERVAL; 2913 /* TODO add MBSSID support */ 2914 cmd->mbss_support = 0; 2915 2916 ret = ath11k_wmi_cmd_send(wmi, skb, 2917 WMI_TWT_ENABLE_CMDID); 2918 if (ret) { 2919 ath11k_warn(ab, "Failed to send WMI_TWT_ENABLE_CMDID"); 2920 dev_kfree_skb(skb); 2921 } 2922 return ret; 2923 } 2924 2925 int 2926 ath11k_wmi_send_twt_disable_cmd(struct ath11k *ar, u32 pdev_id) 2927 { 2928 struct ath11k_pdev_wmi *wmi = ar->wmi; 2929 struct ath11k_base *ab = wmi->wmi_ab->ab; 2930 struct wmi_twt_disable_params_cmd *cmd; 2931 struct sk_buff *skb; 2932 int ret, len; 2933 2934 len = sizeof(*cmd); 2935 2936 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 2937 if (!skb) 2938 return -ENOMEM; 2939 2940 cmd = (struct wmi_twt_disable_params_cmd *)skb->data; 2941 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_DISABLE_CMD) | 2942 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 2943 cmd->pdev_id = pdev_id; 2944 2945 ret = ath11k_wmi_cmd_send(wmi, skb, 2946 WMI_TWT_DISABLE_CMDID); 2947 if (ret) { 2948 ath11k_warn(ab, "Failed to send WMI_TWT_DISABLE_CMDID"); 2949 dev_kfree_skb(skb); 2950 } 2951 return ret; 2952 } 2953 2954 int 2955 ath11k_wmi_send_obss_spr_cmd(struct ath11k *ar, u32 vdev_id, 2956 struct ieee80211_he_obss_pd *he_obss_pd) 2957 { 2958 struct ath11k_pdev_wmi *wmi = ar->wmi; 2959 struct ath11k_base *ab = wmi->wmi_ab->ab; 2960 struct wmi_obss_spatial_reuse_params_cmd *cmd; 2961 struct sk_buff *skb; 2962 int ret, len; 2963 2964 len = sizeof(*cmd); 2965 2966 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 2967 if (!skb) 2968 return -ENOMEM; 2969 2970 cmd = (struct wmi_obss_spatial_reuse_params_cmd *)skb->data; 2971 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 2972 WMI_TAG_OBSS_SPATIAL_REUSE_SET_CMD) | 2973 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 2974 cmd->vdev_id = vdev_id; 2975 cmd->enable = he_obss_pd->enable; 2976 cmd->obss_min = he_obss_pd->min_offset; 2977 cmd->obss_max = he_obss_pd->max_offset; 2978 2979 ret = ath11k_wmi_cmd_send(wmi, skb, 2980 WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID); 2981 if (ret) { 2982 ath11k_warn(ab, 2983 "Failed to send WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID"); 2984 dev_kfree_skb(skb); 2985 } 2986 return ret; 2987 } 2988 2989 int 2990 ath11k_wmi_send_obss_color_collision_cfg_cmd(struct ath11k *ar, u32 vdev_id, 2991 u8 bss_color, u32 period, 2992 bool enable) 2993 { 2994 struct ath11k_pdev_wmi *wmi = ar->wmi; 2995 struct ath11k_base *ab = wmi->wmi_ab->ab; 2996 struct wmi_obss_color_collision_cfg_params_cmd *cmd; 2997 struct sk_buff *skb; 2998 int ret, len; 2999 3000 len = sizeof(*cmd); 3001 3002 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 3003 if (!skb) 3004 return -ENOMEM; 3005 3006 cmd = (struct wmi_obss_color_collision_cfg_params_cmd *)skb->data; 3007 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 3008 WMI_TAG_OBSS_COLOR_COLLISION_DET_CONFIG) | 3009 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 3010 cmd->vdev_id = vdev_id; 3011 cmd->evt_type = enable ? ATH11K_OBSS_COLOR_COLLISION_DETECTION : 3012 ATH11K_OBSS_COLOR_COLLISION_DETECTION_DISABLE; 3013 cmd->current_bss_color = bss_color; 3014 cmd->detection_period_ms = period; 3015 cmd->scan_period_ms = ATH11K_BSS_COLOR_COLLISION_SCAN_PERIOD_MS; 3016 cmd->free_slot_expiry_time_ms = 0; 3017 cmd->flags = 0; 3018 3019 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3020 "wmi_send_obss_color_collision_cfg id %d type %d bss_color %d detect_period %d scan_period %d\n", 3021 cmd->vdev_id, cmd->evt_type, cmd->current_bss_color, 3022 cmd->detection_period_ms, cmd->scan_period_ms); 3023 3024 ret = ath11k_wmi_cmd_send(wmi, skb, 3025 WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID); 3026 if (ret) { 3027 ath11k_warn(ab, "Failed to send WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID"); 3028 dev_kfree_skb(skb); 3029 } 3030 return ret; 3031 } 3032 3033 int ath11k_wmi_send_bss_color_change_enable_cmd(struct ath11k *ar, u32 vdev_id, 3034 bool enable) 3035 { 3036 struct ath11k_pdev_wmi *wmi = ar->wmi; 3037 struct ath11k_base *ab = wmi->wmi_ab->ab; 3038 struct wmi_bss_color_change_enable_params_cmd *cmd; 3039 struct sk_buff *skb; 3040 int ret, len; 3041 3042 len = sizeof(*cmd); 3043 3044 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 3045 if (!skb) 3046 return -ENOMEM; 3047 3048 cmd = (struct wmi_bss_color_change_enable_params_cmd *)skb->data; 3049 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BSS_COLOR_CHANGE_ENABLE) | 3050 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 3051 cmd->vdev_id = vdev_id; 3052 cmd->enable = enable ? 1 : 0; 3053 3054 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3055 "wmi_send_bss_color_change_enable id %d enable %d\n", 3056 cmd->vdev_id, cmd->enable); 3057 3058 ret = ath11k_wmi_cmd_send(wmi, skb, 3059 WMI_BSS_COLOR_CHANGE_ENABLE_CMDID); 3060 if (ret) { 3061 ath11k_warn(ab, "Failed to send WMI_BSS_COLOR_CHANGE_ENABLE_CMDID"); 3062 dev_kfree_skb(skb); 3063 } 3064 return ret; 3065 } 3066 3067 static void 3068 ath11k_fill_band_to_mac_param(struct ath11k_base *soc, 3069 struct wmi_host_pdev_band_to_mac *band_to_mac) 3070 { 3071 u8 i; 3072 struct ath11k_hal_reg_capabilities_ext *hal_reg_cap; 3073 struct ath11k_pdev *pdev; 3074 3075 for (i = 0; i < soc->num_radios; i++) { 3076 pdev = &soc->pdevs[i]; 3077 hal_reg_cap = &soc->hal_reg_cap[i]; 3078 band_to_mac[i].pdev_id = pdev->pdev_id; 3079 3080 switch (pdev->cap.supported_bands) { 3081 case WMI_HOST_WLAN_2G_5G_CAP: 3082 band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan; 3083 band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan; 3084 break; 3085 case WMI_HOST_WLAN_2G_CAP: 3086 band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan; 3087 band_to_mac[i].end_freq = hal_reg_cap->high_2ghz_chan; 3088 break; 3089 case WMI_HOST_WLAN_5G_CAP: 3090 band_to_mac[i].start_freq = hal_reg_cap->low_5ghz_chan; 3091 band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan; 3092 break; 3093 default: 3094 break; 3095 } 3096 } 3097 } 3098 3099 static void 3100 ath11k_wmi_copy_resource_config(struct wmi_resource_config *wmi_cfg, 3101 struct target_resource_config *tg_cfg) 3102 { 3103 wmi_cfg->num_vdevs = tg_cfg->num_vdevs; 3104 wmi_cfg->num_peers = tg_cfg->num_peers; 3105 wmi_cfg->num_offload_peers = tg_cfg->num_offload_peers; 3106 wmi_cfg->num_offload_reorder_buffs = tg_cfg->num_offload_reorder_buffs; 3107 wmi_cfg->num_peer_keys = tg_cfg->num_peer_keys; 3108 wmi_cfg->num_tids = tg_cfg->num_tids; 3109 wmi_cfg->ast_skid_limit = tg_cfg->ast_skid_limit; 3110 wmi_cfg->tx_chain_mask = tg_cfg->tx_chain_mask; 3111 wmi_cfg->rx_chain_mask = tg_cfg->rx_chain_mask; 3112 wmi_cfg->rx_timeout_pri[0] = tg_cfg->rx_timeout_pri[0]; 3113 wmi_cfg->rx_timeout_pri[1] = tg_cfg->rx_timeout_pri[1]; 3114 wmi_cfg->rx_timeout_pri[2] = tg_cfg->rx_timeout_pri[2]; 3115 wmi_cfg->rx_timeout_pri[3] = tg_cfg->rx_timeout_pri[3]; 3116 wmi_cfg->rx_decap_mode = tg_cfg->rx_decap_mode; 3117 wmi_cfg->scan_max_pending_req = tg_cfg->scan_max_pending_req; 3118 wmi_cfg->bmiss_offload_max_vdev = tg_cfg->bmiss_offload_max_vdev; 3119 wmi_cfg->roam_offload_max_vdev = tg_cfg->roam_offload_max_vdev; 3120 wmi_cfg->roam_offload_max_ap_profiles = 3121 tg_cfg->roam_offload_max_ap_profiles; 3122 wmi_cfg->num_mcast_groups = tg_cfg->num_mcast_groups; 3123 wmi_cfg->num_mcast_table_elems = tg_cfg->num_mcast_table_elems; 3124 wmi_cfg->mcast2ucast_mode = tg_cfg->mcast2ucast_mode; 3125 wmi_cfg->tx_dbg_log_size = tg_cfg->tx_dbg_log_size; 3126 wmi_cfg->num_wds_entries = tg_cfg->num_wds_entries; 3127 wmi_cfg->dma_burst_size = tg_cfg->dma_burst_size; 3128 wmi_cfg->mac_aggr_delim = tg_cfg->mac_aggr_delim; 3129 wmi_cfg->rx_skip_defrag_timeout_dup_detection_check = 3130 tg_cfg->rx_skip_defrag_timeout_dup_detection_check; 3131 wmi_cfg->vow_config = tg_cfg->vow_config; 3132 wmi_cfg->gtk_offload_max_vdev = tg_cfg->gtk_offload_max_vdev; 3133 wmi_cfg->num_msdu_desc = tg_cfg->num_msdu_desc; 3134 wmi_cfg->max_frag_entries = tg_cfg->max_frag_entries; 3135 wmi_cfg->num_tdls_vdevs = tg_cfg->num_tdls_vdevs; 3136 wmi_cfg->num_tdls_conn_table_entries = 3137 tg_cfg->num_tdls_conn_table_entries; 3138 wmi_cfg->beacon_tx_offload_max_vdev = 3139 tg_cfg->beacon_tx_offload_max_vdev; 3140 wmi_cfg->num_multicast_filter_entries = 3141 tg_cfg->num_multicast_filter_entries; 3142 wmi_cfg->num_wow_filters = tg_cfg->num_wow_filters; 3143 wmi_cfg->num_keep_alive_pattern = tg_cfg->num_keep_alive_pattern; 3144 wmi_cfg->keep_alive_pattern_size = tg_cfg->keep_alive_pattern_size; 3145 wmi_cfg->max_tdls_concurrent_sleep_sta = 3146 tg_cfg->max_tdls_concurrent_sleep_sta; 3147 wmi_cfg->max_tdls_concurrent_buffer_sta = 3148 tg_cfg->max_tdls_concurrent_buffer_sta; 3149 wmi_cfg->wmi_send_separate = tg_cfg->wmi_send_separate; 3150 wmi_cfg->num_ocb_vdevs = tg_cfg->num_ocb_vdevs; 3151 wmi_cfg->num_ocb_channels = tg_cfg->num_ocb_channels; 3152 wmi_cfg->num_ocb_schedules = tg_cfg->num_ocb_schedules; 3153 wmi_cfg->bpf_instruction_size = tg_cfg->bpf_instruction_size; 3154 wmi_cfg->max_bssid_rx_filters = tg_cfg->max_bssid_rx_filters; 3155 wmi_cfg->use_pdev_id = tg_cfg->use_pdev_id; 3156 wmi_cfg->flag1 = tg_cfg->atf_config; 3157 wmi_cfg->peer_map_unmap_v2_support = tg_cfg->peer_map_unmap_v2_support; 3158 wmi_cfg->sched_params = tg_cfg->sched_params; 3159 wmi_cfg->twt_ap_pdev_count = tg_cfg->twt_ap_pdev_count; 3160 wmi_cfg->twt_ap_sta_count = tg_cfg->twt_ap_sta_count; 3161 } 3162 3163 static int ath11k_init_cmd_send(struct ath11k_pdev_wmi *wmi, 3164 struct wmi_init_cmd_param *param) 3165 { 3166 struct ath11k_base *ab = wmi->wmi_ab->ab; 3167 struct sk_buff *skb; 3168 struct wmi_init_cmd *cmd; 3169 struct wmi_resource_config *cfg; 3170 struct wmi_pdev_set_hw_mode_cmd_param *hw_mode; 3171 struct wmi_pdev_band_to_mac *band_to_mac; 3172 struct wlan_host_mem_chunk *host_mem_chunks; 3173 struct wmi_tlv *tlv; 3174 size_t ret, len; 3175 void *ptr; 3176 u32 hw_mode_len = 0; 3177 u16 idx; 3178 3179 if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX) 3180 hw_mode_len = sizeof(*hw_mode) + TLV_HDR_SIZE + 3181 (param->num_band_to_mac * sizeof(*band_to_mac)); 3182 3183 len = sizeof(*cmd) + TLV_HDR_SIZE + sizeof(*cfg) + hw_mode_len + 3184 (param->num_mem_chunks ? (sizeof(*host_mem_chunks) * WMI_MAX_MEM_REQS) : 0); 3185 3186 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 3187 if (!skb) 3188 return -ENOMEM; 3189 3190 cmd = (struct wmi_init_cmd *)skb->data; 3191 3192 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_INIT_CMD) | 3193 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 3194 3195 ptr = skb->data + sizeof(*cmd); 3196 cfg = ptr; 3197 3198 ath11k_wmi_copy_resource_config(cfg, param->res_cfg); 3199 3200 cfg->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_RESOURCE_CONFIG) | 3201 FIELD_PREP(WMI_TLV_LEN, sizeof(*cfg) - TLV_HDR_SIZE); 3202 3203 ptr += sizeof(*cfg); 3204 host_mem_chunks = ptr + TLV_HDR_SIZE; 3205 len = sizeof(struct wlan_host_mem_chunk); 3206 3207 for (idx = 0; idx < param->num_mem_chunks; ++idx) { 3208 host_mem_chunks[idx].tlv_header = 3209 FIELD_PREP(WMI_TLV_TAG, 3210 WMI_TAG_WLAN_HOST_MEMORY_CHUNK) | 3211 FIELD_PREP(WMI_TLV_LEN, len); 3212 3213 host_mem_chunks[idx].ptr = param->mem_chunks[idx].paddr; 3214 host_mem_chunks[idx].size = param->mem_chunks[idx].len; 3215 host_mem_chunks[idx].req_id = param->mem_chunks[idx].req_id; 3216 3217 ath11k_dbg(ab, ATH11K_DBG_WMI, 3218 "WMI host mem chunk req_id %d paddr 0x%llx len %d\n", 3219 param->mem_chunks[idx].req_id, 3220 (u64)param->mem_chunks[idx].paddr, 3221 param->mem_chunks[idx].len); 3222 } 3223 cmd->num_host_mem_chunks = param->num_mem_chunks; 3224 len = sizeof(struct wlan_host_mem_chunk) * param->num_mem_chunks; 3225 3226 /* num_mem_chunks is zero */ 3227 tlv = ptr; 3228 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 3229 FIELD_PREP(WMI_TLV_LEN, len); 3230 ptr += TLV_HDR_SIZE + len; 3231 3232 if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX) { 3233 hw_mode = (struct wmi_pdev_set_hw_mode_cmd_param *)ptr; 3234 hw_mode->tlv_header = FIELD_PREP(WMI_TLV_TAG, 3235 WMI_TAG_PDEV_SET_HW_MODE_CMD) | 3236 FIELD_PREP(WMI_TLV_LEN, 3237 sizeof(*hw_mode) - TLV_HDR_SIZE); 3238 3239 hw_mode->hw_mode_index = param->hw_mode_id; 3240 hw_mode->num_band_to_mac = param->num_band_to_mac; 3241 3242 ptr += sizeof(*hw_mode); 3243 3244 len = param->num_band_to_mac * sizeof(*band_to_mac); 3245 tlv = ptr; 3246 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 3247 FIELD_PREP(WMI_TLV_LEN, len); 3248 3249 ptr += TLV_HDR_SIZE; 3250 len = sizeof(*band_to_mac); 3251 3252 for (idx = 0; idx < param->num_band_to_mac; idx++) { 3253 band_to_mac = (void *)ptr; 3254 3255 band_to_mac->tlv_header = FIELD_PREP(WMI_TLV_TAG, 3256 WMI_TAG_PDEV_BAND_TO_MAC) | 3257 FIELD_PREP(WMI_TLV_LEN, 3258 len - TLV_HDR_SIZE); 3259 band_to_mac->pdev_id = param->band_to_mac[idx].pdev_id; 3260 band_to_mac->start_freq = 3261 param->band_to_mac[idx].start_freq; 3262 band_to_mac->end_freq = 3263 param->band_to_mac[idx].end_freq; 3264 ptr += sizeof(*band_to_mac); 3265 } 3266 } 3267 3268 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_INIT_CMDID); 3269 if (ret) { 3270 ath11k_warn(ab, "failed to send WMI_INIT_CMDID\n"); 3271 dev_kfree_skb(skb); 3272 } 3273 3274 return ret; 3275 } 3276 3277 int ath11k_wmi_pdev_lro_cfg(struct ath11k *ar, 3278 int pdev_id) 3279 { 3280 struct ath11k_wmi_pdev_lro_config_cmd *cmd; 3281 struct sk_buff *skb; 3282 int ret; 3283 3284 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd)); 3285 if (!skb) 3286 return -ENOMEM; 3287 3288 cmd = (struct ath11k_wmi_pdev_lro_config_cmd *)skb->data; 3289 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_LRO_INFO_CMD) | 3290 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 3291 3292 get_random_bytes(cmd->th_4, sizeof(uint32_t) * ATH11K_IPV4_TH_SEED_SIZE); 3293 get_random_bytes(cmd->th_6, sizeof(uint32_t) * ATH11K_IPV6_TH_SEED_SIZE); 3294 3295 cmd->pdev_id = pdev_id; 3296 3297 ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_LRO_CONFIG_CMDID); 3298 if (ret) { 3299 ath11k_warn(ar->ab, 3300 "failed to send lro cfg req wmi cmd\n"); 3301 goto err; 3302 } 3303 3304 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3305 "WMI lro cfg cmd pdev_id 0x%x\n", pdev_id); 3306 return 0; 3307 err: 3308 dev_kfree_skb(skb); 3309 return ret; 3310 } 3311 3312 int ath11k_wmi_wait_for_service_ready(struct ath11k_base *ab) 3313 { 3314 unsigned long time_left; 3315 3316 time_left = wait_for_completion_timeout(&ab->wmi_ab.service_ready, 3317 WMI_SERVICE_READY_TIMEOUT_HZ); 3318 if (!time_left) 3319 return -ETIMEDOUT; 3320 3321 return 0; 3322 } 3323 3324 int ath11k_wmi_wait_for_unified_ready(struct ath11k_base *ab) 3325 { 3326 unsigned long time_left; 3327 3328 time_left = wait_for_completion_timeout(&ab->wmi_ab.unified_ready, 3329 WMI_SERVICE_READY_TIMEOUT_HZ); 3330 if (!time_left) 3331 return -ETIMEDOUT; 3332 3333 return 0; 3334 } 3335 3336 int ath11k_wmi_cmd_init(struct ath11k_base *ab) 3337 { 3338 struct ath11k_wmi_base *wmi_sc = &ab->wmi_ab; 3339 struct wmi_init_cmd_param init_param; 3340 struct target_resource_config config; 3341 3342 memset(&init_param, 0, sizeof(init_param)); 3343 memset(&config, 0, sizeof(config)); 3344 3345 ab->hw_params.hw_ops->wmi_init_config(ab, &config); 3346 3347 memcpy(&wmi_sc->wlan_resource_config, &config, sizeof(config)); 3348 3349 init_param.res_cfg = &wmi_sc->wlan_resource_config; 3350 init_param.num_mem_chunks = wmi_sc->num_mem_chunks; 3351 init_param.hw_mode_id = wmi_sc->preferred_hw_mode; 3352 init_param.mem_chunks = wmi_sc->mem_chunks; 3353 3354 if (wmi_sc->preferred_hw_mode == WMI_HOST_HW_MODE_SINGLE) 3355 init_param.hw_mode_id = WMI_HOST_HW_MODE_MAX; 3356 3357 if (ab->hw_params.needs_band_to_mac) { 3358 init_param.num_band_to_mac = ab->num_radios; 3359 ath11k_fill_band_to_mac_param(ab, init_param.band_to_mac); 3360 } 3361 3362 return ath11k_init_cmd_send(&wmi_sc->wmi[0], &init_param); 3363 } 3364 3365 int ath11k_wmi_vdev_spectral_conf(struct ath11k *ar, 3366 struct ath11k_wmi_vdev_spectral_conf_param *param) 3367 { 3368 struct ath11k_wmi_vdev_spectral_conf_cmd *cmd; 3369 struct sk_buff *skb; 3370 int ret; 3371 3372 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd)); 3373 if (!skb) 3374 return -ENOMEM; 3375 3376 cmd = (struct ath11k_wmi_vdev_spectral_conf_cmd *)skb->data; 3377 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 3378 WMI_TAG_VDEV_SPECTRAL_CONFIGURE_CMD) | 3379 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 3380 3381 memcpy(&cmd->param, param, sizeof(*param)); 3382 3383 ret = ath11k_wmi_cmd_send(ar->wmi, skb, 3384 WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID); 3385 if (ret) { 3386 ath11k_warn(ar->ab, 3387 "failed to send spectral scan config wmi cmd\n"); 3388 goto err; 3389 } 3390 3391 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3392 "WMI spectral scan config cmd vdev_id 0x%x\n", 3393 param->vdev_id); 3394 3395 return 0; 3396 err: 3397 dev_kfree_skb(skb); 3398 return ret; 3399 } 3400 3401 int ath11k_wmi_vdev_spectral_enable(struct ath11k *ar, u32 vdev_id, 3402 u32 trigger, u32 enable) 3403 { 3404 struct ath11k_wmi_vdev_spectral_enable_cmd *cmd; 3405 struct sk_buff *skb; 3406 int ret; 3407 3408 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd)); 3409 if (!skb) 3410 return -ENOMEM; 3411 3412 cmd = (struct ath11k_wmi_vdev_spectral_enable_cmd *)skb->data; 3413 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 3414 WMI_TAG_VDEV_SPECTRAL_ENABLE_CMD) | 3415 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 3416 3417 cmd->vdev_id = vdev_id; 3418 cmd->trigger_cmd = trigger; 3419 cmd->enable_cmd = enable; 3420 3421 ret = ath11k_wmi_cmd_send(ar->wmi, skb, 3422 WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID); 3423 if (ret) { 3424 ath11k_warn(ar->ab, 3425 "failed to send spectral enable wmi cmd\n"); 3426 goto err; 3427 } 3428 3429 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3430 "WMI spectral enable cmd vdev id 0x%x\n", 3431 vdev_id); 3432 3433 return 0; 3434 err: 3435 dev_kfree_skb(skb); 3436 return ret; 3437 } 3438 3439 int ath11k_wmi_pdev_dma_ring_cfg(struct ath11k *ar, 3440 struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *param) 3441 { 3442 struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *cmd; 3443 struct sk_buff *skb; 3444 int ret; 3445 3446 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd)); 3447 if (!skb) 3448 return -ENOMEM; 3449 3450 cmd = (struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *)skb->data; 3451 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DMA_RING_CFG_REQ) | 3452 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 3453 3454 cmd->pdev_id = param->pdev_id; 3455 cmd->module_id = param->module_id; 3456 cmd->base_paddr_lo = param->base_paddr_lo; 3457 cmd->base_paddr_hi = param->base_paddr_hi; 3458 cmd->head_idx_paddr_lo = param->head_idx_paddr_lo; 3459 cmd->head_idx_paddr_hi = param->head_idx_paddr_hi; 3460 cmd->tail_idx_paddr_lo = param->tail_idx_paddr_lo; 3461 cmd->tail_idx_paddr_hi = param->tail_idx_paddr_hi; 3462 cmd->num_elems = param->num_elems; 3463 cmd->buf_size = param->buf_size; 3464 cmd->num_resp_per_event = param->num_resp_per_event; 3465 cmd->event_timeout_ms = param->event_timeout_ms; 3466 3467 ret = ath11k_wmi_cmd_send(ar->wmi, skb, 3468 WMI_PDEV_DMA_RING_CFG_REQ_CMDID); 3469 if (ret) { 3470 ath11k_warn(ar->ab, 3471 "failed to send dma ring cfg req wmi cmd\n"); 3472 goto err; 3473 } 3474 3475 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3476 "WMI DMA ring cfg req cmd pdev_id 0x%x\n", 3477 param->pdev_id); 3478 3479 return 0; 3480 err: 3481 dev_kfree_skb(skb); 3482 return ret; 3483 } 3484 3485 static int ath11k_wmi_tlv_dma_buf_entry_parse(struct ath11k_base *soc, 3486 u16 tag, u16 len, 3487 const void *ptr, void *data) 3488 { 3489 struct wmi_tlv_dma_buf_release_parse *parse = data; 3490 3491 if (tag != WMI_TAG_DMA_BUF_RELEASE_ENTRY) 3492 return -EPROTO; 3493 3494 if (parse->num_buf_entry >= parse->fixed.num_buf_release_entry) 3495 return -ENOBUFS; 3496 3497 parse->num_buf_entry++; 3498 return 0; 3499 } 3500 3501 static int ath11k_wmi_tlv_dma_buf_meta_parse(struct ath11k_base *soc, 3502 u16 tag, u16 len, 3503 const void *ptr, void *data) 3504 { 3505 struct wmi_tlv_dma_buf_release_parse *parse = data; 3506 3507 if (tag != WMI_TAG_DMA_BUF_RELEASE_SPECTRAL_META_DATA) 3508 return -EPROTO; 3509 3510 if (parse->num_meta >= parse->fixed.num_meta_data_entry) 3511 return -ENOBUFS; 3512 3513 parse->num_meta++; 3514 return 0; 3515 } 3516 3517 static int ath11k_wmi_tlv_dma_buf_parse(struct ath11k_base *ab, 3518 u16 tag, u16 len, 3519 const void *ptr, void *data) 3520 { 3521 struct wmi_tlv_dma_buf_release_parse *parse = data; 3522 int ret; 3523 3524 switch (tag) { 3525 case WMI_TAG_DMA_BUF_RELEASE: 3526 memcpy(&parse->fixed, ptr, 3527 sizeof(struct ath11k_wmi_dma_buf_release_fixed_param)); 3528 parse->fixed.pdev_id = DP_HW2SW_MACID(parse->fixed.pdev_id); 3529 break; 3530 case WMI_TAG_ARRAY_STRUCT: 3531 if (!parse->buf_entry_done) { 3532 parse->num_buf_entry = 0; 3533 parse->buf_entry = (struct wmi_dma_buf_release_entry *)ptr; 3534 3535 ret = ath11k_wmi_tlv_iter(ab, ptr, len, 3536 ath11k_wmi_tlv_dma_buf_entry_parse, 3537 parse); 3538 if (ret) { 3539 ath11k_warn(ab, "failed to parse dma buf entry tlv %d\n", 3540 ret); 3541 return ret; 3542 } 3543 3544 parse->buf_entry_done = true; 3545 } else if (!parse->meta_data_done) { 3546 parse->num_meta = 0; 3547 parse->meta_data = (struct wmi_dma_buf_release_meta_data *)ptr; 3548 3549 ret = ath11k_wmi_tlv_iter(ab, ptr, len, 3550 ath11k_wmi_tlv_dma_buf_meta_parse, 3551 parse); 3552 if (ret) { 3553 ath11k_warn(ab, "failed to parse dma buf meta tlv %d\n", 3554 ret); 3555 return ret; 3556 } 3557 3558 parse->meta_data_done = true; 3559 } 3560 break; 3561 default: 3562 break; 3563 } 3564 return 0; 3565 } 3566 3567 static void ath11k_wmi_pdev_dma_ring_buf_release_event(struct ath11k_base *ab, 3568 struct sk_buff *skb) 3569 { 3570 struct wmi_tlv_dma_buf_release_parse parse = { }; 3571 struct ath11k_dbring_buf_release_event param; 3572 int ret; 3573 3574 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len, 3575 ath11k_wmi_tlv_dma_buf_parse, 3576 &parse); 3577 if (ret) { 3578 ath11k_warn(ab, "failed to parse dma buf release tlv %d\n", ret); 3579 return; 3580 } 3581 3582 param.fixed = parse.fixed; 3583 param.buf_entry = parse.buf_entry; 3584 param.num_buf_entry = parse.num_buf_entry; 3585 param.meta_data = parse.meta_data; 3586 param.num_meta = parse.num_meta; 3587 3588 ret = ath11k_dbring_buffer_release_event(ab, ¶m); 3589 if (ret) { 3590 ath11k_warn(ab, "failed to handle dma buf release event %d\n", ret); 3591 return; 3592 } 3593 } 3594 3595 static int ath11k_wmi_tlv_hw_mode_caps_parse(struct ath11k_base *soc, 3596 u16 tag, u16 len, 3597 const void *ptr, void *data) 3598 { 3599 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data; 3600 struct wmi_hw_mode_capabilities *hw_mode_cap; 3601 u32 phy_map = 0; 3602 3603 if (tag != WMI_TAG_HW_MODE_CAPABILITIES) 3604 return -EPROTO; 3605 3606 if (svc_rdy_ext->n_hw_mode_caps >= svc_rdy_ext->param.num_hw_modes) 3607 return -ENOBUFS; 3608 3609 hw_mode_cap = container_of(ptr, struct wmi_hw_mode_capabilities, 3610 hw_mode_id); 3611 svc_rdy_ext->n_hw_mode_caps++; 3612 3613 phy_map = hw_mode_cap->phy_id_map; 3614 while (phy_map) { 3615 svc_rdy_ext->tot_phy_id++; 3616 phy_map = phy_map >> 1; 3617 } 3618 3619 return 0; 3620 } 3621 3622 static int ath11k_wmi_tlv_hw_mode_caps(struct ath11k_base *soc, 3623 u16 len, const void *ptr, void *data) 3624 { 3625 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data; 3626 struct wmi_hw_mode_capabilities *hw_mode_caps; 3627 enum wmi_host_hw_mode_config_type mode, pref; 3628 u32 i; 3629 int ret; 3630 3631 svc_rdy_ext->n_hw_mode_caps = 0; 3632 svc_rdy_ext->hw_mode_caps = (struct wmi_hw_mode_capabilities *)ptr; 3633 3634 ret = ath11k_wmi_tlv_iter(soc, ptr, len, 3635 ath11k_wmi_tlv_hw_mode_caps_parse, 3636 svc_rdy_ext); 3637 if (ret) { 3638 ath11k_warn(soc, "failed to parse tlv %d\n", ret); 3639 return ret; 3640 } 3641 3642 i = 0; 3643 while (i < svc_rdy_ext->n_hw_mode_caps) { 3644 hw_mode_caps = &svc_rdy_ext->hw_mode_caps[i]; 3645 mode = hw_mode_caps->hw_mode_id; 3646 pref = soc->wmi_ab.preferred_hw_mode; 3647 3648 if (ath11k_hw_mode_pri_map[mode] < ath11k_hw_mode_pri_map[pref]) { 3649 svc_rdy_ext->pref_hw_mode_caps = *hw_mode_caps; 3650 soc->wmi_ab.preferred_hw_mode = mode; 3651 } 3652 i++; 3653 } 3654 3655 ath11k_dbg(soc, ATH11K_DBG_WMI, "preferred_hw_mode:%d\n", 3656 soc->wmi_ab.preferred_hw_mode); 3657 if (soc->wmi_ab.preferred_hw_mode == WMI_HOST_HW_MODE_MAX) 3658 return -EINVAL; 3659 3660 return 0; 3661 } 3662 3663 static int ath11k_wmi_tlv_mac_phy_caps_parse(struct ath11k_base *soc, 3664 u16 tag, u16 len, 3665 const void *ptr, void *data) 3666 { 3667 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data; 3668 3669 if (tag != WMI_TAG_MAC_PHY_CAPABILITIES) 3670 return -EPROTO; 3671 3672 if (svc_rdy_ext->n_mac_phy_caps >= svc_rdy_ext->tot_phy_id) 3673 return -ENOBUFS; 3674 3675 len = min_t(u16, len, sizeof(struct wmi_mac_phy_capabilities)); 3676 if (!svc_rdy_ext->n_mac_phy_caps) { 3677 svc_rdy_ext->mac_phy_caps = kzalloc((svc_rdy_ext->tot_phy_id) * len, 3678 GFP_ATOMIC); 3679 if (!svc_rdy_ext->mac_phy_caps) 3680 return -ENOMEM; 3681 } 3682 3683 memcpy(svc_rdy_ext->mac_phy_caps + svc_rdy_ext->n_mac_phy_caps, ptr, len); 3684 svc_rdy_ext->n_mac_phy_caps++; 3685 return 0; 3686 } 3687 3688 static int ath11k_wmi_tlv_ext_hal_reg_caps_parse(struct ath11k_base *soc, 3689 u16 tag, u16 len, 3690 const void *ptr, void *data) 3691 { 3692 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data; 3693 3694 if (tag != WMI_TAG_HAL_REG_CAPABILITIES_EXT) 3695 return -EPROTO; 3696 3697 if (svc_rdy_ext->n_ext_hal_reg_caps >= svc_rdy_ext->param.num_phy) 3698 return -ENOBUFS; 3699 3700 svc_rdy_ext->n_ext_hal_reg_caps++; 3701 return 0; 3702 } 3703 3704 static int ath11k_wmi_tlv_ext_hal_reg_caps(struct ath11k_base *soc, 3705 u16 len, const void *ptr, void *data) 3706 { 3707 struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0]; 3708 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data; 3709 struct ath11k_hal_reg_capabilities_ext reg_cap; 3710 int ret; 3711 u32 i; 3712 3713 svc_rdy_ext->n_ext_hal_reg_caps = 0; 3714 svc_rdy_ext->ext_hal_reg_caps = (struct wmi_hal_reg_capabilities_ext *)ptr; 3715 ret = ath11k_wmi_tlv_iter(soc, ptr, len, 3716 ath11k_wmi_tlv_ext_hal_reg_caps_parse, 3717 svc_rdy_ext); 3718 if (ret) { 3719 ath11k_warn(soc, "failed to parse tlv %d\n", ret); 3720 return ret; 3721 } 3722 3723 for (i = 0; i < svc_rdy_ext->param.num_phy; i++) { 3724 ret = ath11k_pull_reg_cap_svc_rdy_ext(wmi_handle, 3725 svc_rdy_ext->soc_hal_reg_caps, 3726 svc_rdy_ext->ext_hal_reg_caps, i, 3727 ®_cap); 3728 if (ret) { 3729 ath11k_warn(soc, "failed to extract reg cap %d\n", i); 3730 return ret; 3731 } 3732 3733 memcpy(&soc->hal_reg_cap[reg_cap.phy_id], 3734 ®_cap, sizeof(reg_cap)); 3735 } 3736 return 0; 3737 } 3738 3739 static int ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(struct ath11k_base *soc, 3740 u16 len, const void *ptr, 3741 void *data) 3742 { 3743 struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0]; 3744 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data; 3745 u8 hw_mode_id = svc_rdy_ext->pref_hw_mode_caps.hw_mode_id; 3746 u32 phy_id_map; 3747 int pdev_index = 0; 3748 int ret; 3749 3750 svc_rdy_ext->soc_hal_reg_caps = (struct wmi_soc_hal_reg_capabilities *)ptr; 3751 svc_rdy_ext->param.num_phy = svc_rdy_ext->soc_hal_reg_caps->num_phy; 3752 3753 soc->num_radios = 0; 3754 phy_id_map = svc_rdy_ext->pref_hw_mode_caps.phy_id_map; 3755 3756 while (phy_id_map && soc->num_radios < MAX_RADIOS) { 3757 ret = ath11k_pull_mac_phy_cap_svc_ready_ext(wmi_handle, 3758 svc_rdy_ext->hw_caps, 3759 svc_rdy_ext->hw_mode_caps, 3760 svc_rdy_ext->soc_hal_reg_caps, 3761 svc_rdy_ext->mac_phy_caps, 3762 hw_mode_id, soc->num_radios, 3763 &soc->pdevs[pdev_index]); 3764 if (ret) { 3765 ath11k_warn(soc, "failed to extract mac caps, idx :%d\n", 3766 soc->num_radios); 3767 return ret; 3768 } 3769 3770 soc->num_radios++; 3771 3772 /* For QCA6390, save mac_phy capability in the same pdev */ 3773 if (soc->hw_params.single_pdev_only) 3774 pdev_index = 0; 3775 else 3776 pdev_index = soc->num_radios; 3777 3778 /* TODO: mac_phy_cap prints */ 3779 phy_id_map >>= 1; 3780 } 3781 3782 /* For QCA6390, set num_radios to 1 because host manages 3783 * both 2G and 5G radio in one pdev. 3784 * Set pdev_id = 0 and 0 means soc level. 3785 */ 3786 if (soc->hw_params.single_pdev_only) { 3787 soc->num_radios = 1; 3788 soc->pdevs[0].pdev_id = 0; 3789 } 3790 3791 return 0; 3792 } 3793 3794 static int ath11k_wmi_tlv_dma_ring_caps_parse(struct ath11k_base *soc, 3795 u16 tag, u16 len, 3796 const void *ptr, void *data) 3797 { 3798 struct wmi_tlv_dma_ring_caps_parse *parse = data; 3799 3800 if (tag != WMI_TAG_DMA_RING_CAPABILITIES) 3801 return -EPROTO; 3802 3803 parse->n_dma_ring_caps++; 3804 return 0; 3805 } 3806 3807 static int ath11k_wmi_alloc_dbring_caps(struct ath11k_base *ab, 3808 u32 num_cap) 3809 { 3810 size_t sz; 3811 void *ptr; 3812 3813 sz = num_cap * sizeof(struct ath11k_dbring_cap); 3814 ptr = kzalloc(sz, GFP_ATOMIC); 3815 if (!ptr) 3816 return -ENOMEM; 3817 3818 ab->db_caps = ptr; 3819 ab->num_db_cap = num_cap; 3820 3821 return 0; 3822 } 3823 3824 static void ath11k_wmi_free_dbring_caps(struct ath11k_base *ab) 3825 { 3826 kfree(ab->db_caps); 3827 ab->db_caps = NULL; 3828 } 3829 3830 static int ath11k_wmi_tlv_dma_ring_caps(struct ath11k_base *ab, 3831 u16 len, const void *ptr, void *data) 3832 { 3833 struct wmi_tlv_dma_ring_caps_parse *dma_caps_parse = data; 3834 struct wmi_dma_ring_capabilities *dma_caps; 3835 struct ath11k_dbring_cap *dir_buff_caps; 3836 int ret; 3837 u32 i; 3838 3839 dma_caps_parse->n_dma_ring_caps = 0; 3840 dma_caps = (struct wmi_dma_ring_capabilities *)ptr; 3841 ret = ath11k_wmi_tlv_iter(ab, ptr, len, 3842 ath11k_wmi_tlv_dma_ring_caps_parse, 3843 dma_caps_parse); 3844 if (ret) { 3845 ath11k_warn(ab, "failed to parse dma ring caps tlv %d\n", ret); 3846 return ret; 3847 } 3848 3849 if (!dma_caps_parse->n_dma_ring_caps) 3850 return 0; 3851 3852 if (ab->num_db_cap) { 3853 ath11k_warn(ab, "Already processed, so ignoring dma ring caps\n"); 3854 return 0; 3855 } 3856 3857 ret = ath11k_wmi_alloc_dbring_caps(ab, dma_caps_parse->n_dma_ring_caps); 3858 if (ret) 3859 return ret; 3860 3861 dir_buff_caps = ab->db_caps; 3862 for (i = 0; i < dma_caps_parse->n_dma_ring_caps; i++) { 3863 if (dma_caps[i].module_id >= WMI_DIRECT_BUF_MAX) { 3864 ath11k_warn(ab, "Invalid module id %d\n", dma_caps[i].module_id); 3865 ret = -EINVAL; 3866 goto free_dir_buff; 3867 } 3868 3869 dir_buff_caps[i].id = dma_caps[i].module_id; 3870 dir_buff_caps[i].pdev_id = DP_HW2SW_MACID(dma_caps[i].pdev_id); 3871 dir_buff_caps[i].min_elem = dma_caps[i].min_elem; 3872 dir_buff_caps[i].min_buf_sz = dma_caps[i].min_buf_sz; 3873 dir_buff_caps[i].min_buf_align = dma_caps[i].min_buf_align; 3874 } 3875 3876 return 0; 3877 3878 free_dir_buff: 3879 ath11k_wmi_free_dbring_caps(ab); 3880 return ret; 3881 } 3882 3883 static int ath11k_wmi_tlv_svc_rdy_ext_parse(struct ath11k_base *ab, 3884 u16 tag, u16 len, 3885 const void *ptr, void *data) 3886 { 3887 struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0]; 3888 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data; 3889 int ret; 3890 3891 switch (tag) { 3892 case WMI_TAG_SERVICE_READY_EXT_EVENT: 3893 ret = ath11k_pull_svc_ready_ext(wmi_handle, ptr, 3894 &svc_rdy_ext->param); 3895 if (ret) { 3896 ath11k_warn(ab, "unable to extract ext params\n"); 3897 return ret; 3898 } 3899 break; 3900 3901 case WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS: 3902 svc_rdy_ext->hw_caps = (struct wmi_soc_mac_phy_hw_mode_caps *)ptr; 3903 svc_rdy_ext->param.num_hw_modes = svc_rdy_ext->hw_caps->num_hw_modes; 3904 break; 3905 3906 case WMI_TAG_SOC_HAL_REG_CAPABILITIES: 3907 ret = ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(ab, len, ptr, 3908 svc_rdy_ext); 3909 if (ret) 3910 return ret; 3911 break; 3912 3913 case WMI_TAG_ARRAY_STRUCT: 3914 if (!svc_rdy_ext->hw_mode_done) { 3915 ret = ath11k_wmi_tlv_hw_mode_caps(ab, len, ptr, 3916 svc_rdy_ext); 3917 if (ret) 3918 return ret; 3919 3920 svc_rdy_ext->hw_mode_done = true; 3921 } else if (!svc_rdy_ext->mac_phy_done) { 3922 svc_rdy_ext->n_mac_phy_caps = 0; 3923 ret = ath11k_wmi_tlv_iter(ab, ptr, len, 3924 ath11k_wmi_tlv_mac_phy_caps_parse, 3925 svc_rdy_ext); 3926 if (ret) { 3927 ath11k_warn(ab, "failed to parse tlv %d\n", ret); 3928 return ret; 3929 } 3930 3931 svc_rdy_ext->mac_phy_done = true; 3932 } else if (!svc_rdy_ext->ext_hal_reg_done) { 3933 ret = ath11k_wmi_tlv_ext_hal_reg_caps(ab, len, ptr, 3934 svc_rdy_ext); 3935 if (ret) 3936 return ret; 3937 3938 svc_rdy_ext->ext_hal_reg_done = true; 3939 } else if (!svc_rdy_ext->mac_phy_chainmask_combo_done) { 3940 svc_rdy_ext->mac_phy_chainmask_combo_done = true; 3941 } else if (!svc_rdy_ext->mac_phy_chainmask_cap_done) { 3942 svc_rdy_ext->mac_phy_chainmask_cap_done = true; 3943 } else if (!svc_rdy_ext->oem_dma_ring_cap_done) { 3944 svc_rdy_ext->oem_dma_ring_cap_done = true; 3945 } else if (!svc_rdy_ext->dma_ring_cap_done) { 3946 ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr, 3947 &svc_rdy_ext->dma_caps_parse); 3948 if (ret) 3949 return ret; 3950 3951 svc_rdy_ext->dma_ring_cap_done = true; 3952 } 3953 break; 3954 3955 default: 3956 break; 3957 } 3958 return 0; 3959 } 3960 3961 static int ath11k_service_ready_ext_event(struct ath11k_base *ab, 3962 struct sk_buff *skb) 3963 { 3964 struct wmi_tlv_svc_rdy_ext_parse svc_rdy_ext = { }; 3965 int ret; 3966 3967 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len, 3968 ath11k_wmi_tlv_svc_rdy_ext_parse, 3969 &svc_rdy_ext); 3970 if (ret) { 3971 ath11k_warn(ab, "failed to parse tlv %d\n", ret); 3972 goto err; 3973 } 3974 3975 if (!test_bit(WMI_TLV_SERVICE_EXT2_MSG, ab->wmi_ab.svc_map)) 3976 complete(&ab->wmi_ab.service_ready); 3977 3978 kfree(svc_rdy_ext.mac_phy_caps); 3979 return 0; 3980 3981 err: 3982 ath11k_wmi_free_dbring_caps(ab); 3983 return ret; 3984 } 3985 3986 static int ath11k_wmi_tlv_svc_rdy_ext2_parse(struct ath11k_base *ab, 3987 u16 tag, u16 len, 3988 const void *ptr, void *data) 3989 { 3990 struct wmi_tlv_svc_rdy_ext2_parse *parse = data; 3991 int ret; 3992 3993 switch (tag) { 3994 case WMI_TAG_ARRAY_STRUCT: 3995 if (!parse->dma_ring_cap_done) { 3996 ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr, 3997 &parse->dma_caps_parse); 3998 if (ret) 3999 return ret; 4000 4001 parse->dma_ring_cap_done = true; 4002 } 4003 break; 4004 default: 4005 break; 4006 } 4007 4008 return 0; 4009 } 4010 4011 static int ath11k_service_ready_ext2_event(struct ath11k_base *ab, 4012 struct sk_buff *skb) 4013 { 4014 struct wmi_tlv_svc_rdy_ext2_parse svc_rdy_ext2 = { }; 4015 int ret; 4016 4017 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len, 4018 ath11k_wmi_tlv_svc_rdy_ext2_parse, 4019 &svc_rdy_ext2); 4020 if (ret) { 4021 ath11k_warn(ab, "failed to parse ext2 event tlv %d\n", ret); 4022 goto err; 4023 } 4024 4025 complete(&ab->wmi_ab.service_ready); 4026 4027 return 0; 4028 4029 err: 4030 ath11k_wmi_free_dbring_caps(ab); 4031 return ret; 4032 } 4033 4034 static int ath11k_pull_vdev_start_resp_tlv(struct ath11k_base *ab, struct sk_buff *skb, 4035 struct wmi_vdev_start_resp_event *vdev_rsp) 4036 { 4037 const void **tb; 4038 const struct wmi_vdev_start_resp_event *ev; 4039 int ret; 4040 4041 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4042 if (IS_ERR(tb)) { 4043 ret = PTR_ERR(tb); 4044 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4045 return ret; 4046 } 4047 4048 ev = tb[WMI_TAG_VDEV_START_RESPONSE_EVENT]; 4049 if (!ev) { 4050 ath11k_warn(ab, "failed to fetch vdev start resp ev"); 4051 kfree(tb); 4052 return -EPROTO; 4053 } 4054 4055 memset(vdev_rsp, 0, sizeof(*vdev_rsp)); 4056 4057 vdev_rsp->vdev_id = ev->vdev_id; 4058 vdev_rsp->requestor_id = ev->requestor_id; 4059 vdev_rsp->resp_type = ev->resp_type; 4060 vdev_rsp->status = ev->status; 4061 vdev_rsp->chain_mask = ev->chain_mask; 4062 vdev_rsp->smps_mode = ev->smps_mode; 4063 vdev_rsp->mac_id = ev->mac_id; 4064 vdev_rsp->cfgd_tx_streams = ev->cfgd_tx_streams; 4065 vdev_rsp->cfgd_rx_streams = ev->cfgd_rx_streams; 4066 4067 kfree(tb); 4068 return 0; 4069 } 4070 4071 static struct cur_reg_rule 4072 *create_reg_rules_from_wmi(u32 num_reg_rules, 4073 struct wmi_regulatory_rule_struct *wmi_reg_rule) 4074 { 4075 struct cur_reg_rule *reg_rule_ptr; 4076 u32 count; 4077 4078 reg_rule_ptr = kzalloc((num_reg_rules * sizeof(*reg_rule_ptr)), 4079 GFP_ATOMIC); 4080 4081 if (!reg_rule_ptr) 4082 return NULL; 4083 4084 for (count = 0; count < num_reg_rules; count++) { 4085 reg_rule_ptr[count].start_freq = 4086 FIELD_GET(REG_RULE_START_FREQ, 4087 wmi_reg_rule[count].freq_info); 4088 reg_rule_ptr[count].end_freq = 4089 FIELD_GET(REG_RULE_END_FREQ, 4090 wmi_reg_rule[count].freq_info); 4091 reg_rule_ptr[count].max_bw = 4092 FIELD_GET(REG_RULE_MAX_BW, 4093 wmi_reg_rule[count].bw_pwr_info); 4094 reg_rule_ptr[count].reg_power = 4095 FIELD_GET(REG_RULE_REG_PWR, 4096 wmi_reg_rule[count].bw_pwr_info); 4097 reg_rule_ptr[count].ant_gain = 4098 FIELD_GET(REG_RULE_ANT_GAIN, 4099 wmi_reg_rule[count].bw_pwr_info); 4100 reg_rule_ptr[count].flags = 4101 FIELD_GET(REG_RULE_FLAGS, 4102 wmi_reg_rule[count].flag_info); 4103 } 4104 4105 return reg_rule_ptr; 4106 } 4107 4108 static int ath11k_pull_reg_chan_list_update_ev(struct ath11k_base *ab, 4109 struct sk_buff *skb, 4110 struct cur_regulatory_info *reg_info) 4111 { 4112 const void **tb; 4113 const struct wmi_reg_chan_list_cc_event *chan_list_event_hdr; 4114 struct wmi_regulatory_rule_struct *wmi_reg_rule; 4115 u32 num_2g_reg_rules, num_5g_reg_rules; 4116 int ret; 4117 4118 ath11k_dbg(ab, ATH11K_DBG_WMI, "processing regulatory channel list\n"); 4119 4120 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4121 if (IS_ERR(tb)) { 4122 ret = PTR_ERR(tb); 4123 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4124 return ret; 4125 } 4126 4127 chan_list_event_hdr = tb[WMI_TAG_REG_CHAN_LIST_CC_EVENT]; 4128 if (!chan_list_event_hdr) { 4129 ath11k_warn(ab, "failed to fetch reg chan list update ev\n"); 4130 kfree(tb); 4131 return -EPROTO; 4132 } 4133 4134 reg_info->num_2g_reg_rules = chan_list_event_hdr->num_2g_reg_rules; 4135 reg_info->num_5g_reg_rules = chan_list_event_hdr->num_5g_reg_rules; 4136 4137 if (!(reg_info->num_2g_reg_rules + reg_info->num_5g_reg_rules)) { 4138 ath11k_warn(ab, "No regulatory rules available in the event info\n"); 4139 kfree(tb); 4140 return -EINVAL; 4141 } 4142 4143 memcpy(reg_info->alpha2, &chan_list_event_hdr->alpha2, 4144 REG_ALPHA2_LEN); 4145 reg_info->dfs_region = chan_list_event_hdr->dfs_region; 4146 reg_info->phybitmap = chan_list_event_hdr->phybitmap; 4147 reg_info->num_phy = chan_list_event_hdr->num_phy; 4148 reg_info->phy_id = chan_list_event_hdr->phy_id; 4149 reg_info->ctry_code = chan_list_event_hdr->country_id; 4150 reg_info->reg_dmn_pair = chan_list_event_hdr->domain_code; 4151 if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_PASS) 4152 reg_info->status_code = REG_SET_CC_STATUS_PASS; 4153 else if (chan_list_event_hdr->status_code == WMI_REG_CURRENT_ALPHA2_NOT_FOUND) 4154 reg_info->status_code = REG_CURRENT_ALPHA2_NOT_FOUND; 4155 else if (chan_list_event_hdr->status_code == WMI_REG_INIT_ALPHA2_NOT_FOUND) 4156 reg_info->status_code = REG_INIT_ALPHA2_NOT_FOUND; 4157 else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_CHANGE_NOT_ALLOWED) 4158 reg_info->status_code = REG_SET_CC_CHANGE_NOT_ALLOWED; 4159 else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_NO_MEMORY) 4160 reg_info->status_code = REG_SET_CC_STATUS_NO_MEMORY; 4161 else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_FAIL) 4162 reg_info->status_code = REG_SET_CC_STATUS_FAIL; 4163 4164 reg_info->min_bw_2g = chan_list_event_hdr->min_bw_2g; 4165 reg_info->max_bw_2g = chan_list_event_hdr->max_bw_2g; 4166 reg_info->min_bw_5g = chan_list_event_hdr->min_bw_5g; 4167 reg_info->max_bw_5g = chan_list_event_hdr->max_bw_5g; 4168 4169 num_2g_reg_rules = reg_info->num_2g_reg_rules; 4170 num_5g_reg_rules = reg_info->num_5g_reg_rules; 4171 4172 ath11k_dbg(ab, ATH11K_DBG_WMI, 4173 "%s:cc %s dsf %d BW: min_2g %d max_2g %d min_5g %d max_5g %d", 4174 __func__, reg_info->alpha2, reg_info->dfs_region, 4175 reg_info->min_bw_2g, reg_info->max_bw_2g, 4176 reg_info->min_bw_5g, reg_info->max_bw_5g); 4177 4178 ath11k_dbg(ab, ATH11K_DBG_WMI, 4179 "%s: num_2g_reg_rules %d num_5g_reg_rules %d", __func__, 4180 num_2g_reg_rules, num_5g_reg_rules); 4181 4182 wmi_reg_rule = 4183 (struct wmi_regulatory_rule_struct *)((u8 *)chan_list_event_hdr 4184 + sizeof(*chan_list_event_hdr) 4185 + sizeof(struct wmi_tlv)); 4186 4187 if (num_2g_reg_rules) { 4188 reg_info->reg_rules_2g_ptr = create_reg_rules_from_wmi(num_2g_reg_rules, 4189 wmi_reg_rule); 4190 if (!reg_info->reg_rules_2g_ptr) { 4191 kfree(tb); 4192 ath11k_warn(ab, "Unable to Allocate memory for 2g rules\n"); 4193 return -ENOMEM; 4194 } 4195 } 4196 4197 if (num_5g_reg_rules) { 4198 wmi_reg_rule += num_2g_reg_rules; 4199 reg_info->reg_rules_5g_ptr = create_reg_rules_from_wmi(num_5g_reg_rules, 4200 wmi_reg_rule); 4201 if (!reg_info->reg_rules_5g_ptr) { 4202 kfree(tb); 4203 ath11k_warn(ab, "Unable to Allocate memory for 5g rules\n"); 4204 return -ENOMEM; 4205 } 4206 } 4207 4208 ath11k_dbg(ab, ATH11K_DBG_WMI, "processed regulatory channel list\n"); 4209 4210 kfree(tb); 4211 return 0; 4212 } 4213 4214 static int ath11k_pull_peer_del_resp_ev(struct ath11k_base *ab, struct sk_buff *skb, 4215 struct wmi_peer_delete_resp_event *peer_del_resp) 4216 { 4217 const void **tb; 4218 const struct wmi_peer_delete_resp_event *ev; 4219 int ret; 4220 4221 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4222 if (IS_ERR(tb)) { 4223 ret = PTR_ERR(tb); 4224 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4225 return ret; 4226 } 4227 4228 ev = tb[WMI_TAG_PEER_DELETE_RESP_EVENT]; 4229 if (!ev) { 4230 ath11k_warn(ab, "failed to fetch peer delete resp ev"); 4231 kfree(tb); 4232 return -EPROTO; 4233 } 4234 4235 memset(peer_del_resp, 0, sizeof(*peer_del_resp)); 4236 4237 peer_del_resp->vdev_id = ev->vdev_id; 4238 ether_addr_copy(peer_del_resp->peer_macaddr.addr, 4239 ev->peer_macaddr.addr); 4240 4241 kfree(tb); 4242 return 0; 4243 } 4244 4245 static int ath11k_pull_bcn_tx_status_ev(struct ath11k_base *ab, void *evt_buf, 4246 u32 len, u32 *vdev_id, 4247 u32 *tx_status) 4248 { 4249 const void **tb; 4250 const struct wmi_bcn_tx_status_event *ev; 4251 int ret; 4252 4253 tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC); 4254 if (IS_ERR(tb)) { 4255 ret = PTR_ERR(tb); 4256 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4257 return ret; 4258 } 4259 4260 ev = tb[WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT]; 4261 if (!ev) { 4262 ath11k_warn(ab, "failed to fetch bcn tx status ev"); 4263 kfree(tb); 4264 return -EPROTO; 4265 } 4266 4267 *vdev_id = ev->vdev_id; 4268 *tx_status = ev->tx_status; 4269 4270 kfree(tb); 4271 return 0; 4272 } 4273 4274 static int ath11k_pull_vdev_stopped_param_tlv(struct ath11k_base *ab, struct sk_buff *skb, 4275 u32 *vdev_id) 4276 { 4277 const void **tb; 4278 const struct wmi_vdev_stopped_event *ev; 4279 int ret; 4280 4281 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4282 if (IS_ERR(tb)) { 4283 ret = PTR_ERR(tb); 4284 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4285 return ret; 4286 } 4287 4288 ev = tb[WMI_TAG_VDEV_STOPPED_EVENT]; 4289 if (!ev) { 4290 ath11k_warn(ab, "failed to fetch vdev stop ev"); 4291 kfree(tb); 4292 return -EPROTO; 4293 } 4294 4295 *vdev_id = ev->vdev_id; 4296 4297 kfree(tb); 4298 return 0; 4299 } 4300 4301 static int ath11k_pull_mgmt_rx_params_tlv(struct ath11k_base *ab, 4302 struct sk_buff *skb, 4303 struct mgmt_rx_event_params *hdr) 4304 { 4305 const void **tb; 4306 const struct wmi_mgmt_rx_hdr *ev; 4307 const u8 *frame; 4308 int ret; 4309 4310 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4311 if (IS_ERR(tb)) { 4312 ret = PTR_ERR(tb); 4313 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4314 return ret; 4315 } 4316 4317 ev = tb[WMI_TAG_MGMT_RX_HDR]; 4318 frame = tb[WMI_TAG_ARRAY_BYTE]; 4319 4320 if (!ev || !frame) { 4321 ath11k_warn(ab, "failed to fetch mgmt rx hdr"); 4322 kfree(tb); 4323 return -EPROTO; 4324 } 4325 4326 hdr->pdev_id = ev->pdev_id; 4327 hdr->chan_freq = ev->chan_freq; 4328 hdr->channel = ev->channel; 4329 hdr->snr = ev->snr; 4330 hdr->rate = ev->rate; 4331 hdr->phy_mode = ev->phy_mode; 4332 hdr->buf_len = ev->buf_len; 4333 hdr->status = ev->status; 4334 hdr->flags = ev->flags; 4335 hdr->rssi = ev->rssi; 4336 hdr->tsf_delta = ev->tsf_delta; 4337 memcpy(hdr->rssi_ctl, ev->rssi_ctl, sizeof(hdr->rssi_ctl)); 4338 4339 if (skb->len < (frame - skb->data) + hdr->buf_len) { 4340 ath11k_warn(ab, "invalid length in mgmt rx hdr ev"); 4341 kfree(tb); 4342 return -EPROTO; 4343 } 4344 4345 /* shift the sk_buff to point to `frame` */ 4346 skb_trim(skb, 0); 4347 skb_put(skb, frame - skb->data); 4348 skb_pull(skb, frame - skb->data); 4349 skb_put(skb, hdr->buf_len); 4350 4351 ath11k_ce_byte_swap(skb->data, hdr->buf_len); 4352 4353 kfree(tb); 4354 return 0; 4355 } 4356 4357 static int wmi_process_mgmt_tx_comp(struct ath11k *ar, u32 desc_id, 4358 u32 status) 4359 { 4360 struct sk_buff *msdu; 4361 struct ieee80211_tx_info *info; 4362 struct ath11k_skb_cb *skb_cb; 4363 4364 spin_lock_bh(&ar->txmgmt_idr_lock); 4365 msdu = idr_find(&ar->txmgmt_idr, desc_id); 4366 4367 if (!msdu) { 4368 ath11k_warn(ar->ab, "received mgmt tx compl for invalid msdu_id: %d\n", 4369 desc_id); 4370 spin_unlock_bh(&ar->txmgmt_idr_lock); 4371 return -ENOENT; 4372 } 4373 4374 idr_remove(&ar->txmgmt_idr, desc_id); 4375 spin_unlock_bh(&ar->txmgmt_idr_lock); 4376 4377 skb_cb = ATH11K_SKB_CB(msdu); 4378 dma_unmap_single(ar->ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE); 4379 4380 info = IEEE80211_SKB_CB(msdu); 4381 if ((!(info->flags & IEEE80211_TX_CTL_NO_ACK)) && !status) 4382 info->flags |= IEEE80211_TX_STAT_ACK; 4383 4384 ieee80211_tx_status_irqsafe(ar->hw, msdu); 4385 4386 /* WARN when we received this event without doing any mgmt tx */ 4387 if (atomic_dec_if_positive(&ar->num_pending_mgmt_tx) < 0) 4388 WARN_ON_ONCE(1); 4389 4390 return 0; 4391 } 4392 4393 static int ath11k_pull_mgmt_tx_compl_param_tlv(struct ath11k_base *ab, 4394 struct sk_buff *skb, 4395 struct wmi_mgmt_tx_compl_event *param) 4396 { 4397 const void **tb; 4398 const struct wmi_mgmt_tx_compl_event *ev; 4399 int ret; 4400 4401 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4402 if (IS_ERR(tb)) { 4403 ret = PTR_ERR(tb); 4404 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4405 return ret; 4406 } 4407 4408 ev = tb[WMI_TAG_MGMT_TX_COMPL_EVENT]; 4409 if (!ev) { 4410 ath11k_warn(ab, "failed to fetch mgmt tx compl ev"); 4411 kfree(tb); 4412 return -EPROTO; 4413 } 4414 4415 param->pdev_id = ev->pdev_id; 4416 param->desc_id = ev->desc_id; 4417 param->status = ev->status; 4418 4419 kfree(tb); 4420 return 0; 4421 } 4422 4423 static void ath11k_wmi_event_scan_started(struct ath11k *ar) 4424 { 4425 lockdep_assert_held(&ar->data_lock); 4426 4427 switch (ar->scan.state) { 4428 case ATH11K_SCAN_IDLE: 4429 case ATH11K_SCAN_RUNNING: 4430 case ATH11K_SCAN_ABORTING: 4431 ath11k_warn(ar->ab, "received scan started event in an invalid scan state: %s (%d)\n", 4432 ath11k_scan_state_str(ar->scan.state), 4433 ar->scan.state); 4434 break; 4435 case ATH11K_SCAN_STARTING: 4436 ar->scan.state = ATH11K_SCAN_RUNNING; 4437 complete(&ar->scan.started); 4438 break; 4439 } 4440 } 4441 4442 static void ath11k_wmi_event_scan_start_failed(struct ath11k *ar) 4443 { 4444 lockdep_assert_held(&ar->data_lock); 4445 4446 switch (ar->scan.state) { 4447 case ATH11K_SCAN_IDLE: 4448 case ATH11K_SCAN_RUNNING: 4449 case ATH11K_SCAN_ABORTING: 4450 ath11k_warn(ar->ab, "received scan start failed event in an invalid scan state: %s (%d)\n", 4451 ath11k_scan_state_str(ar->scan.state), 4452 ar->scan.state); 4453 break; 4454 case ATH11K_SCAN_STARTING: 4455 complete(&ar->scan.started); 4456 __ath11k_mac_scan_finish(ar); 4457 break; 4458 } 4459 } 4460 4461 static void ath11k_wmi_event_scan_completed(struct ath11k *ar) 4462 { 4463 lockdep_assert_held(&ar->data_lock); 4464 4465 switch (ar->scan.state) { 4466 case ATH11K_SCAN_IDLE: 4467 case ATH11K_SCAN_STARTING: 4468 /* One suspected reason scan can be completed while starting is 4469 * if firmware fails to deliver all scan events to the host, 4470 * e.g. when transport pipe is full. This has been observed 4471 * with spectral scan phyerr events starving wmi transport 4472 * pipe. In such case the "scan completed" event should be (and 4473 * is) ignored by the host as it may be just firmware's scan 4474 * state machine recovering. 4475 */ 4476 ath11k_warn(ar->ab, "received scan completed event in an invalid scan state: %s (%d)\n", 4477 ath11k_scan_state_str(ar->scan.state), 4478 ar->scan.state); 4479 break; 4480 case ATH11K_SCAN_RUNNING: 4481 case ATH11K_SCAN_ABORTING: 4482 __ath11k_mac_scan_finish(ar); 4483 break; 4484 } 4485 } 4486 4487 static void ath11k_wmi_event_scan_bss_chan(struct ath11k *ar) 4488 { 4489 lockdep_assert_held(&ar->data_lock); 4490 4491 switch (ar->scan.state) { 4492 case ATH11K_SCAN_IDLE: 4493 case ATH11K_SCAN_STARTING: 4494 ath11k_warn(ar->ab, "received scan bss chan event in an invalid scan state: %s (%d)\n", 4495 ath11k_scan_state_str(ar->scan.state), 4496 ar->scan.state); 4497 break; 4498 case ATH11K_SCAN_RUNNING: 4499 case ATH11K_SCAN_ABORTING: 4500 ar->scan_channel = NULL; 4501 break; 4502 } 4503 } 4504 4505 static void ath11k_wmi_event_scan_foreign_chan(struct ath11k *ar, u32 freq) 4506 { 4507 lockdep_assert_held(&ar->data_lock); 4508 4509 switch (ar->scan.state) { 4510 case ATH11K_SCAN_IDLE: 4511 case ATH11K_SCAN_STARTING: 4512 ath11k_warn(ar->ab, "received scan foreign chan event in an invalid scan state: %s (%d)\n", 4513 ath11k_scan_state_str(ar->scan.state), 4514 ar->scan.state); 4515 break; 4516 case ATH11K_SCAN_RUNNING: 4517 case ATH11K_SCAN_ABORTING: 4518 ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq); 4519 break; 4520 } 4521 } 4522 4523 static const char * 4524 ath11k_wmi_event_scan_type_str(enum wmi_scan_event_type type, 4525 enum wmi_scan_completion_reason reason) 4526 { 4527 switch (type) { 4528 case WMI_SCAN_EVENT_STARTED: 4529 return "started"; 4530 case WMI_SCAN_EVENT_COMPLETED: 4531 switch (reason) { 4532 case WMI_SCAN_REASON_COMPLETED: 4533 return "completed"; 4534 case WMI_SCAN_REASON_CANCELLED: 4535 return "completed [cancelled]"; 4536 case WMI_SCAN_REASON_PREEMPTED: 4537 return "completed [preempted]"; 4538 case WMI_SCAN_REASON_TIMEDOUT: 4539 return "completed [timedout]"; 4540 case WMI_SCAN_REASON_INTERNAL_FAILURE: 4541 return "completed [internal err]"; 4542 case WMI_SCAN_REASON_MAX: 4543 break; 4544 } 4545 return "completed [unknown]"; 4546 case WMI_SCAN_EVENT_BSS_CHANNEL: 4547 return "bss channel"; 4548 case WMI_SCAN_EVENT_FOREIGN_CHAN: 4549 return "foreign channel"; 4550 case WMI_SCAN_EVENT_DEQUEUED: 4551 return "dequeued"; 4552 case WMI_SCAN_EVENT_PREEMPTED: 4553 return "preempted"; 4554 case WMI_SCAN_EVENT_START_FAILED: 4555 return "start failed"; 4556 case WMI_SCAN_EVENT_RESTARTED: 4557 return "restarted"; 4558 case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT: 4559 return "foreign channel exit"; 4560 default: 4561 return "unknown"; 4562 } 4563 } 4564 4565 static int ath11k_pull_scan_ev(struct ath11k_base *ab, struct sk_buff *skb, 4566 struct wmi_scan_event *scan_evt_param) 4567 { 4568 const void **tb; 4569 const struct wmi_scan_event *ev; 4570 int ret; 4571 4572 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4573 if (IS_ERR(tb)) { 4574 ret = PTR_ERR(tb); 4575 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4576 return ret; 4577 } 4578 4579 ev = tb[WMI_TAG_SCAN_EVENT]; 4580 if (!ev) { 4581 ath11k_warn(ab, "failed to fetch scan ev"); 4582 kfree(tb); 4583 return -EPROTO; 4584 } 4585 4586 scan_evt_param->event_type = ev->event_type; 4587 scan_evt_param->reason = ev->reason; 4588 scan_evt_param->channel_freq = ev->channel_freq; 4589 scan_evt_param->scan_req_id = ev->scan_req_id; 4590 scan_evt_param->scan_id = ev->scan_id; 4591 scan_evt_param->vdev_id = ev->vdev_id; 4592 scan_evt_param->tsf_timestamp = ev->tsf_timestamp; 4593 4594 kfree(tb); 4595 return 0; 4596 } 4597 4598 static int ath11k_pull_peer_sta_kickout_ev(struct ath11k_base *ab, struct sk_buff *skb, 4599 struct wmi_peer_sta_kickout_arg *arg) 4600 { 4601 const void **tb; 4602 const struct wmi_peer_sta_kickout_event *ev; 4603 int ret; 4604 4605 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4606 if (IS_ERR(tb)) { 4607 ret = PTR_ERR(tb); 4608 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4609 return ret; 4610 } 4611 4612 ev = tb[WMI_TAG_PEER_STA_KICKOUT_EVENT]; 4613 if (!ev) { 4614 ath11k_warn(ab, "failed to fetch peer sta kickout ev"); 4615 kfree(tb); 4616 return -EPROTO; 4617 } 4618 4619 arg->mac_addr = ev->peer_macaddr.addr; 4620 4621 kfree(tb); 4622 return 0; 4623 } 4624 4625 static int ath11k_pull_roam_ev(struct ath11k_base *ab, struct sk_buff *skb, 4626 struct wmi_roam_event *roam_ev) 4627 { 4628 const void **tb; 4629 const struct wmi_roam_event *ev; 4630 int ret; 4631 4632 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4633 if (IS_ERR(tb)) { 4634 ret = PTR_ERR(tb); 4635 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4636 return ret; 4637 } 4638 4639 ev = tb[WMI_TAG_ROAM_EVENT]; 4640 if (!ev) { 4641 ath11k_warn(ab, "failed to fetch roam ev"); 4642 kfree(tb); 4643 return -EPROTO; 4644 } 4645 4646 roam_ev->vdev_id = ev->vdev_id; 4647 roam_ev->reason = ev->reason; 4648 roam_ev->rssi = ev->rssi; 4649 4650 kfree(tb); 4651 return 0; 4652 } 4653 4654 static int freq_to_idx(struct ath11k *ar, int freq) 4655 { 4656 struct ieee80211_supported_band *sband; 4657 int band, ch, idx = 0; 4658 4659 for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) { 4660 sband = ar->hw->wiphy->bands[band]; 4661 if (!sband) 4662 continue; 4663 4664 for (ch = 0; ch < sband->n_channels; ch++, idx++) 4665 if (sband->channels[ch].center_freq == freq) 4666 goto exit; 4667 } 4668 4669 exit: 4670 return idx; 4671 } 4672 4673 static int ath11k_pull_chan_info_ev(struct ath11k_base *ab, u8 *evt_buf, 4674 u32 len, struct wmi_chan_info_event *ch_info_ev) 4675 { 4676 const void **tb; 4677 const struct wmi_chan_info_event *ev; 4678 int ret; 4679 4680 tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC); 4681 if (IS_ERR(tb)) { 4682 ret = PTR_ERR(tb); 4683 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4684 return ret; 4685 } 4686 4687 ev = tb[WMI_TAG_CHAN_INFO_EVENT]; 4688 if (!ev) { 4689 ath11k_warn(ab, "failed to fetch chan info ev"); 4690 kfree(tb); 4691 return -EPROTO; 4692 } 4693 4694 ch_info_ev->err_code = ev->err_code; 4695 ch_info_ev->freq = ev->freq; 4696 ch_info_ev->cmd_flags = ev->cmd_flags; 4697 ch_info_ev->noise_floor = ev->noise_floor; 4698 ch_info_ev->rx_clear_count = ev->rx_clear_count; 4699 ch_info_ev->cycle_count = ev->cycle_count; 4700 ch_info_ev->chan_tx_pwr_range = ev->chan_tx_pwr_range; 4701 ch_info_ev->chan_tx_pwr_tp = ev->chan_tx_pwr_tp; 4702 ch_info_ev->rx_frame_count = ev->rx_frame_count; 4703 ch_info_ev->tx_frame_cnt = ev->tx_frame_cnt; 4704 ch_info_ev->mac_clk_mhz = ev->mac_clk_mhz; 4705 ch_info_ev->vdev_id = ev->vdev_id; 4706 4707 kfree(tb); 4708 return 0; 4709 } 4710 4711 static int 4712 ath11k_pull_pdev_bss_chan_info_ev(struct ath11k_base *ab, struct sk_buff *skb, 4713 struct wmi_pdev_bss_chan_info_event *bss_ch_info_ev) 4714 { 4715 const void **tb; 4716 const struct wmi_pdev_bss_chan_info_event *ev; 4717 int ret; 4718 4719 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4720 if (IS_ERR(tb)) { 4721 ret = PTR_ERR(tb); 4722 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4723 return ret; 4724 } 4725 4726 ev = tb[WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT]; 4727 if (!ev) { 4728 ath11k_warn(ab, "failed to fetch pdev bss chan info ev"); 4729 kfree(tb); 4730 return -EPROTO; 4731 } 4732 4733 bss_ch_info_ev->pdev_id = ev->pdev_id; 4734 bss_ch_info_ev->freq = ev->freq; 4735 bss_ch_info_ev->noise_floor = ev->noise_floor; 4736 bss_ch_info_ev->rx_clear_count_low = ev->rx_clear_count_low; 4737 bss_ch_info_ev->rx_clear_count_high = ev->rx_clear_count_high; 4738 bss_ch_info_ev->cycle_count_low = ev->cycle_count_low; 4739 bss_ch_info_ev->cycle_count_high = ev->cycle_count_high; 4740 bss_ch_info_ev->tx_cycle_count_low = ev->tx_cycle_count_low; 4741 bss_ch_info_ev->tx_cycle_count_high = ev->tx_cycle_count_high; 4742 bss_ch_info_ev->rx_cycle_count_low = ev->rx_cycle_count_low; 4743 bss_ch_info_ev->rx_cycle_count_high = ev->rx_cycle_count_high; 4744 bss_ch_info_ev->rx_bss_cycle_count_low = ev->rx_bss_cycle_count_low; 4745 bss_ch_info_ev->rx_bss_cycle_count_high = ev->rx_bss_cycle_count_high; 4746 4747 kfree(tb); 4748 return 0; 4749 } 4750 4751 static int 4752 ath11k_pull_vdev_install_key_compl_ev(struct ath11k_base *ab, struct sk_buff *skb, 4753 struct wmi_vdev_install_key_complete_arg *arg) 4754 { 4755 const void **tb; 4756 const struct wmi_vdev_install_key_compl_event *ev; 4757 int ret; 4758 4759 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4760 if (IS_ERR(tb)) { 4761 ret = PTR_ERR(tb); 4762 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4763 return ret; 4764 } 4765 4766 ev = tb[WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT]; 4767 if (!ev) { 4768 ath11k_warn(ab, "failed to fetch vdev install key compl ev"); 4769 kfree(tb); 4770 return -EPROTO; 4771 } 4772 4773 arg->vdev_id = ev->vdev_id; 4774 arg->macaddr = ev->peer_macaddr.addr; 4775 arg->key_idx = ev->key_idx; 4776 arg->key_flags = ev->key_flags; 4777 arg->status = ev->status; 4778 4779 kfree(tb); 4780 return 0; 4781 } 4782 4783 static int ath11k_pull_peer_assoc_conf_ev(struct ath11k_base *ab, struct sk_buff *skb, 4784 struct wmi_peer_assoc_conf_arg *peer_assoc_conf) 4785 { 4786 const void **tb; 4787 const struct wmi_peer_assoc_conf_event *ev; 4788 int ret; 4789 4790 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4791 if (IS_ERR(tb)) { 4792 ret = PTR_ERR(tb); 4793 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4794 return ret; 4795 } 4796 4797 ev = tb[WMI_TAG_PEER_ASSOC_CONF_EVENT]; 4798 if (!ev) { 4799 ath11k_warn(ab, "failed to fetch peer assoc conf ev"); 4800 kfree(tb); 4801 return -EPROTO; 4802 } 4803 4804 peer_assoc_conf->vdev_id = ev->vdev_id; 4805 peer_assoc_conf->macaddr = ev->peer_macaddr.addr; 4806 4807 kfree(tb); 4808 return 0; 4809 } 4810 4811 static void ath11k_wmi_pull_pdev_stats_base(const struct wmi_pdev_stats_base *src, 4812 struct ath11k_fw_stats_pdev *dst) 4813 { 4814 dst->ch_noise_floor = src->chan_nf; 4815 dst->tx_frame_count = src->tx_frame_count; 4816 dst->rx_frame_count = src->rx_frame_count; 4817 dst->rx_clear_count = src->rx_clear_count; 4818 dst->cycle_count = src->cycle_count; 4819 dst->phy_err_count = src->phy_err_count; 4820 dst->chan_tx_power = src->chan_tx_pwr; 4821 } 4822 4823 static void 4824 ath11k_wmi_pull_pdev_stats_tx(const struct wmi_pdev_stats_tx *src, 4825 struct ath11k_fw_stats_pdev *dst) 4826 { 4827 dst->comp_queued = src->comp_queued; 4828 dst->comp_delivered = src->comp_delivered; 4829 dst->msdu_enqued = src->msdu_enqued; 4830 dst->mpdu_enqued = src->mpdu_enqued; 4831 dst->wmm_drop = src->wmm_drop; 4832 dst->local_enqued = src->local_enqued; 4833 dst->local_freed = src->local_freed; 4834 dst->hw_queued = src->hw_queued; 4835 dst->hw_reaped = src->hw_reaped; 4836 dst->underrun = src->underrun; 4837 dst->tx_abort = src->tx_abort; 4838 dst->mpdus_requed = src->mpdus_requed; 4839 dst->tx_ko = src->tx_ko; 4840 dst->data_rc = src->data_rc; 4841 dst->self_triggers = src->self_triggers; 4842 dst->sw_retry_failure = src->sw_retry_failure; 4843 dst->illgl_rate_phy_err = src->illgl_rate_phy_err; 4844 dst->pdev_cont_xretry = src->pdev_cont_xretry; 4845 dst->pdev_tx_timeout = src->pdev_tx_timeout; 4846 dst->pdev_resets = src->pdev_resets; 4847 dst->stateless_tid_alloc_failure = src->stateless_tid_alloc_failure; 4848 dst->phy_underrun = src->phy_underrun; 4849 dst->txop_ovf = src->txop_ovf; 4850 } 4851 4852 static void ath11k_wmi_pull_pdev_stats_rx(const struct wmi_pdev_stats_rx *src, 4853 struct ath11k_fw_stats_pdev *dst) 4854 { 4855 dst->mid_ppdu_route_change = src->mid_ppdu_route_change; 4856 dst->status_rcvd = src->status_rcvd; 4857 dst->r0_frags = src->r0_frags; 4858 dst->r1_frags = src->r1_frags; 4859 dst->r2_frags = src->r2_frags; 4860 dst->r3_frags = src->r3_frags; 4861 dst->htt_msdus = src->htt_msdus; 4862 dst->htt_mpdus = src->htt_mpdus; 4863 dst->loc_msdus = src->loc_msdus; 4864 dst->loc_mpdus = src->loc_mpdus; 4865 dst->oversize_amsdu = src->oversize_amsdu; 4866 dst->phy_errs = src->phy_errs; 4867 dst->phy_err_drop = src->phy_err_drop; 4868 dst->mpdu_errs = src->mpdu_errs; 4869 } 4870 4871 static void 4872 ath11k_wmi_pull_vdev_stats(const struct wmi_vdev_stats *src, 4873 struct ath11k_fw_stats_vdev *dst) 4874 { 4875 int i; 4876 4877 dst->vdev_id = src->vdev_id; 4878 dst->beacon_snr = src->beacon_snr; 4879 dst->data_snr = src->data_snr; 4880 dst->num_rx_frames = src->num_rx_frames; 4881 dst->num_rts_fail = src->num_rts_fail; 4882 dst->num_rts_success = src->num_rts_success; 4883 dst->num_rx_err = src->num_rx_err; 4884 dst->num_rx_discard = src->num_rx_discard; 4885 dst->num_tx_not_acked = src->num_tx_not_acked; 4886 4887 for (i = 0; i < ARRAY_SIZE(src->num_tx_frames); i++) 4888 dst->num_tx_frames[i] = src->num_tx_frames[i]; 4889 4890 for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_retries); i++) 4891 dst->num_tx_frames_retries[i] = src->num_tx_frames_retries[i]; 4892 4893 for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_failures); i++) 4894 dst->num_tx_frames_failures[i] = src->num_tx_frames_failures[i]; 4895 4896 for (i = 0; i < ARRAY_SIZE(src->tx_rate_history); i++) 4897 dst->tx_rate_history[i] = src->tx_rate_history[i]; 4898 4899 for (i = 0; i < ARRAY_SIZE(src->beacon_rssi_history); i++) 4900 dst->beacon_rssi_history[i] = src->beacon_rssi_history[i]; 4901 } 4902 4903 static void 4904 ath11k_wmi_pull_bcn_stats(const struct wmi_bcn_stats *src, 4905 struct ath11k_fw_stats_bcn *dst) 4906 { 4907 dst->vdev_id = src->vdev_id; 4908 dst->tx_bcn_succ_cnt = src->tx_bcn_succ_cnt; 4909 dst->tx_bcn_outage_cnt = src->tx_bcn_outage_cnt; 4910 } 4911 4912 int ath11k_wmi_pull_fw_stats(struct ath11k_base *ab, struct sk_buff *skb, 4913 struct ath11k_fw_stats *stats) 4914 { 4915 const void **tb; 4916 const struct wmi_stats_event *ev; 4917 const void *data; 4918 int i, ret; 4919 u32 len = skb->len; 4920 4921 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, len, GFP_ATOMIC); 4922 if (IS_ERR(tb)) { 4923 ret = PTR_ERR(tb); 4924 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4925 return ret; 4926 } 4927 4928 ev = tb[WMI_TAG_STATS_EVENT]; 4929 data = tb[WMI_TAG_ARRAY_BYTE]; 4930 if (!ev || !data) { 4931 ath11k_warn(ab, "failed to fetch update stats ev"); 4932 kfree(tb); 4933 return -EPROTO; 4934 } 4935 4936 ath11k_dbg(ab, ATH11K_DBG_WMI, 4937 "wmi stats update ev pdev_id %d pdev %i vdev %i bcn %i\n", 4938 ev->pdev_id, 4939 ev->num_pdev_stats, ev->num_vdev_stats, 4940 ev->num_bcn_stats); 4941 4942 stats->pdev_id = ev->pdev_id; 4943 stats->stats_id = 0; 4944 4945 for (i = 0; i < ev->num_pdev_stats; i++) { 4946 const struct wmi_pdev_stats *src; 4947 struct ath11k_fw_stats_pdev *dst; 4948 4949 src = data; 4950 if (len < sizeof(*src)) { 4951 kfree(tb); 4952 return -EPROTO; 4953 } 4954 4955 stats->stats_id = WMI_REQUEST_PDEV_STAT; 4956 4957 data += sizeof(*src); 4958 len -= sizeof(*src); 4959 4960 dst = kzalloc(sizeof(*dst), GFP_ATOMIC); 4961 if (!dst) 4962 continue; 4963 4964 ath11k_wmi_pull_pdev_stats_base(&src->base, dst); 4965 ath11k_wmi_pull_pdev_stats_tx(&src->tx, dst); 4966 ath11k_wmi_pull_pdev_stats_rx(&src->rx, dst); 4967 list_add_tail(&dst->list, &stats->pdevs); 4968 } 4969 4970 for (i = 0; i < ev->num_vdev_stats; i++) { 4971 const struct wmi_vdev_stats *src; 4972 struct ath11k_fw_stats_vdev *dst; 4973 4974 src = data; 4975 if (len < sizeof(*src)) { 4976 kfree(tb); 4977 return -EPROTO; 4978 } 4979 4980 stats->stats_id = WMI_REQUEST_VDEV_STAT; 4981 4982 data += sizeof(*src); 4983 len -= sizeof(*src); 4984 4985 dst = kzalloc(sizeof(*dst), GFP_ATOMIC); 4986 if (!dst) 4987 continue; 4988 4989 ath11k_wmi_pull_vdev_stats(src, dst); 4990 list_add_tail(&dst->list, &stats->vdevs); 4991 } 4992 4993 for (i = 0; i < ev->num_bcn_stats; i++) { 4994 const struct wmi_bcn_stats *src; 4995 struct ath11k_fw_stats_bcn *dst; 4996 4997 src = data; 4998 if (len < sizeof(*src)) { 4999 kfree(tb); 5000 return -EPROTO; 5001 } 5002 5003 stats->stats_id = WMI_REQUEST_BCN_STAT; 5004 5005 data += sizeof(*src); 5006 len -= sizeof(*src); 5007 5008 dst = kzalloc(sizeof(*dst), GFP_ATOMIC); 5009 if (!dst) 5010 continue; 5011 5012 ath11k_wmi_pull_bcn_stats(src, dst); 5013 list_add_tail(&dst->list, &stats->bcn); 5014 } 5015 5016 kfree(tb); 5017 return 0; 5018 } 5019 5020 static int 5021 ath11k_pull_pdev_temp_ev(struct ath11k_base *ab, u8 *evt_buf, 5022 u32 len, const struct wmi_pdev_temperature_event *ev) 5023 { 5024 const void **tb; 5025 int ret; 5026 5027 tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC); 5028 if (IS_ERR(tb)) { 5029 ret = PTR_ERR(tb); 5030 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 5031 return ret; 5032 } 5033 5034 ev = tb[WMI_TAG_PDEV_TEMPERATURE_EVENT]; 5035 if (!ev) { 5036 ath11k_warn(ab, "failed to fetch pdev temp ev"); 5037 kfree(tb); 5038 return -EPROTO; 5039 } 5040 5041 kfree(tb); 5042 return 0; 5043 } 5044 5045 size_t ath11k_wmi_fw_stats_num_vdevs(struct list_head *head) 5046 { 5047 struct ath11k_fw_stats_vdev *i; 5048 size_t num = 0; 5049 5050 list_for_each_entry(i, head, list) 5051 ++num; 5052 5053 return num; 5054 } 5055 5056 static size_t ath11k_wmi_fw_stats_num_bcn(struct list_head *head) 5057 { 5058 struct ath11k_fw_stats_bcn *i; 5059 size_t num = 0; 5060 5061 list_for_each_entry(i, head, list) 5062 ++num; 5063 5064 return num; 5065 } 5066 5067 static void 5068 ath11k_wmi_fw_pdev_base_stats_fill(const struct ath11k_fw_stats_pdev *pdev, 5069 char *buf, u32 *length) 5070 { 5071 u32 len = *length; 5072 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE; 5073 5074 len += scnprintf(buf + len, buf_len - len, "\n"); 5075 len += scnprintf(buf + len, buf_len - len, "%30s\n", 5076 "ath11k PDEV stats"); 5077 len += scnprintf(buf + len, buf_len - len, "%30s\n\n", 5078 "================="); 5079 5080 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5081 "Channel noise floor", pdev->ch_noise_floor); 5082 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5083 "Channel TX power", pdev->chan_tx_power); 5084 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5085 "TX frame count", pdev->tx_frame_count); 5086 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5087 "RX frame count", pdev->rx_frame_count); 5088 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5089 "RX clear count", pdev->rx_clear_count); 5090 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5091 "Cycle count", pdev->cycle_count); 5092 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5093 "PHY error count", pdev->phy_err_count); 5094 5095 *length = len; 5096 } 5097 5098 static void 5099 ath11k_wmi_fw_pdev_tx_stats_fill(const struct ath11k_fw_stats_pdev *pdev, 5100 char *buf, u32 *length) 5101 { 5102 u32 len = *length; 5103 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE; 5104 5105 len += scnprintf(buf + len, buf_len - len, "\n%30s\n", 5106 "ath11k PDEV TX stats"); 5107 len += scnprintf(buf + len, buf_len - len, "%30s\n\n", 5108 "===================="); 5109 5110 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5111 "HTT cookies queued", pdev->comp_queued); 5112 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5113 "HTT cookies disp.", pdev->comp_delivered); 5114 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5115 "MSDU queued", pdev->msdu_enqued); 5116 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5117 "MPDU queued", pdev->mpdu_enqued); 5118 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5119 "MSDUs dropped", pdev->wmm_drop); 5120 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5121 "Local enqued", pdev->local_enqued); 5122 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5123 "Local freed", pdev->local_freed); 5124 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5125 "HW queued", pdev->hw_queued); 5126 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5127 "PPDUs reaped", pdev->hw_reaped); 5128 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5129 "Num underruns", pdev->underrun); 5130 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5131 "PPDUs cleaned", pdev->tx_abort); 5132 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5133 "MPDUs requed", pdev->mpdus_requed); 5134 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5135 "Excessive retries", pdev->tx_ko); 5136 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5137 "HW rate", pdev->data_rc); 5138 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5139 "Sched self triggers", pdev->self_triggers); 5140 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5141 "Dropped due to SW retries", 5142 pdev->sw_retry_failure); 5143 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5144 "Illegal rate phy errors", 5145 pdev->illgl_rate_phy_err); 5146 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5147 "PDEV continuous xretry", pdev->pdev_cont_xretry); 5148 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5149 "TX timeout", pdev->pdev_tx_timeout); 5150 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5151 "PDEV resets", pdev->pdev_resets); 5152 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5153 "Stateless TIDs alloc failures", 5154 pdev->stateless_tid_alloc_failure); 5155 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5156 "PHY underrun", pdev->phy_underrun); 5157 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5158 "MPDU is more than txop limit", pdev->txop_ovf); 5159 *length = len; 5160 } 5161 5162 static void 5163 ath11k_wmi_fw_pdev_rx_stats_fill(const struct ath11k_fw_stats_pdev *pdev, 5164 char *buf, u32 *length) 5165 { 5166 u32 len = *length; 5167 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE; 5168 5169 len += scnprintf(buf + len, buf_len - len, "\n%30s\n", 5170 "ath11k PDEV RX stats"); 5171 len += scnprintf(buf + len, buf_len - len, "%30s\n\n", 5172 "===================="); 5173 5174 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5175 "Mid PPDU route change", 5176 pdev->mid_ppdu_route_change); 5177 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5178 "Tot. number of statuses", pdev->status_rcvd); 5179 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5180 "Extra frags on rings 0", pdev->r0_frags); 5181 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5182 "Extra frags on rings 1", pdev->r1_frags); 5183 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5184 "Extra frags on rings 2", pdev->r2_frags); 5185 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5186 "Extra frags on rings 3", pdev->r3_frags); 5187 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5188 "MSDUs delivered to HTT", pdev->htt_msdus); 5189 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5190 "MPDUs delivered to HTT", pdev->htt_mpdus); 5191 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5192 "MSDUs delivered to stack", pdev->loc_msdus); 5193 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5194 "MPDUs delivered to stack", pdev->loc_mpdus); 5195 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5196 "Oversized AMSUs", pdev->oversize_amsdu); 5197 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5198 "PHY errors", pdev->phy_errs); 5199 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5200 "PHY errors drops", pdev->phy_err_drop); 5201 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5202 "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs); 5203 *length = len; 5204 } 5205 5206 static void 5207 ath11k_wmi_fw_vdev_stats_fill(struct ath11k *ar, 5208 const struct ath11k_fw_stats_vdev *vdev, 5209 char *buf, u32 *length) 5210 { 5211 u32 len = *length; 5212 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE; 5213 struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, vdev->vdev_id); 5214 u8 *vif_macaddr; 5215 int i; 5216 5217 /* VDEV stats has all the active VDEVs of other PDEVs as well, 5218 * ignoring those not part of requested PDEV 5219 */ 5220 if (!arvif) 5221 return; 5222 5223 vif_macaddr = arvif->vif->addr; 5224 5225 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5226 "VDEV ID", vdev->vdev_id); 5227 len += scnprintf(buf + len, buf_len - len, "%30s %pM\n", 5228 "VDEV MAC address", vif_macaddr); 5229 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5230 "beacon snr", vdev->beacon_snr); 5231 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5232 "data snr", vdev->data_snr); 5233 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5234 "num rx frames", vdev->num_rx_frames); 5235 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5236 "num rts fail", vdev->num_rts_fail); 5237 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5238 "num rts success", vdev->num_rts_success); 5239 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5240 "num rx err", vdev->num_rx_err); 5241 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5242 "num rx discard", vdev->num_rx_discard); 5243 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5244 "num tx not acked", vdev->num_tx_not_acked); 5245 5246 for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames); i++) 5247 len += scnprintf(buf + len, buf_len - len, 5248 "%25s [%02d] %u\n", 5249 "num tx frames", i, 5250 vdev->num_tx_frames[i]); 5251 5252 for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_retries); i++) 5253 len += scnprintf(buf + len, buf_len - len, 5254 "%25s [%02d] %u\n", 5255 "num tx frames retries", i, 5256 vdev->num_tx_frames_retries[i]); 5257 5258 for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_failures); i++) 5259 len += scnprintf(buf + len, buf_len - len, 5260 "%25s [%02d] %u\n", 5261 "num tx frames failures", i, 5262 vdev->num_tx_frames_failures[i]); 5263 5264 for (i = 0 ; i < ARRAY_SIZE(vdev->tx_rate_history); i++) 5265 len += scnprintf(buf + len, buf_len - len, 5266 "%25s [%02d] 0x%08x\n", 5267 "tx rate history", i, 5268 vdev->tx_rate_history[i]); 5269 5270 for (i = 0 ; i < ARRAY_SIZE(vdev->beacon_rssi_history); i++) 5271 len += scnprintf(buf + len, buf_len - len, 5272 "%25s [%02d] %u\n", 5273 "beacon rssi history", i, 5274 vdev->beacon_rssi_history[i]); 5275 5276 len += scnprintf(buf + len, buf_len - len, "\n"); 5277 *length = len; 5278 } 5279 5280 static void 5281 ath11k_wmi_fw_bcn_stats_fill(struct ath11k *ar, 5282 const struct ath11k_fw_stats_bcn *bcn, 5283 char *buf, u32 *length) 5284 { 5285 u32 len = *length; 5286 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE; 5287 struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, bcn->vdev_id); 5288 u8 *vdev_macaddr; 5289 5290 if (!arvif) { 5291 ath11k_warn(ar->ab, "invalid vdev id %d in bcn stats", 5292 bcn->vdev_id); 5293 return; 5294 } 5295 5296 vdev_macaddr = arvif->vif->addr; 5297 5298 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5299 "VDEV ID", bcn->vdev_id); 5300 len += scnprintf(buf + len, buf_len - len, "%30s %pM\n", 5301 "VDEV MAC address", vdev_macaddr); 5302 len += scnprintf(buf + len, buf_len - len, "%30s\n\n", 5303 "================"); 5304 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5305 "Num of beacon tx success", bcn->tx_bcn_succ_cnt); 5306 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5307 "Num of beacon tx failures", bcn->tx_bcn_outage_cnt); 5308 5309 len += scnprintf(buf + len, buf_len - len, "\n"); 5310 *length = len; 5311 } 5312 5313 void ath11k_wmi_fw_stats_fill(struct ath11k *ar, 5314 struct ath11k_fw_stats *fw_stats, 5315 u32 stats_id, char *buf) 5316 { 5317 u32 len = 0; 5318 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE; 5319 const struct ath11k_fw_stats_pdev *pdev; 5320 const struct ath11k_fw_stats_vdev *vdev; 5321 const struct ath11k_fw_stats_bcn *bcn; 5322 size_t num_bcn; 5323 5324 spin_lock_bh(&ar->data_lock); 5325 5326 if (stats_id == WMI_REQUEST_PDEV_STAT) { 5327 pdev = list_first_entry_or_null(&fw_stats->pdevs, 5328 struct ath11k_fw_stats_pdev, list); 5329 if (!pdev) { 5330 ath11k_warn(ar->ab, "failed to get pdev stats\n"); 5331 goto unlock; 5332 } 5333 5334 ath11k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len); 5335 ath11k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len); 5336 ath11k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len); 5337 } 5338 5339 if (stats_id == WMI_REQUEST_VDEV_STAT) { 5340 len += scnprintf(buf + len, buf_len - len, "\n"); 5341 len += scnprintf(buf + len, buf_len - len, "%30s\n", 5342 "ath11k VDEV stats"); 5343 len += scnprintf(buf + len, buf_len - len, "%30s\n\n", 5344 "================="); 5345 5346 list_for_each_entry(vdev, &fw_stats->vdevs, list) 5347 ath11k_wmi_fw_vdev_stats_fill(ar, vdev, buf, &len); 5348 } 5349 5350 if (stats_id == WMI_REQUEST_BCN_STAT) { 5351 num_bcn = ath11k_wmi_fw_stats_num_bcn(&fw_stats->bcn); 5352 5353 len += scnprintf(buf + len, buf_len - len, "\n"); 5354 len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n", 5355 "ath11k Beacon stats", num_bcn); 5356 len += scnprintf(buf + len, buf_len - len, "%30s\n\n", 5357 "==================="); 5358 5359 list_for_each_entry(bcn, &fw_stats->bcn, list) 5360 ath11k_wmi_fw_bcn_stats_fill(ar, bcn, buf, &len); 5361 } 5362 5363 unlock: 5364 spin_unlock_bh(&ar->data_lock); 5365 5366 if (len >= buf_len) 5367 buf[len - 1] = 0; 5368 else 5369 buf[len] = 0; 5370 } 5371 5372 static void ath11k_wmi_op_ep_tx_credits(struct ath11k_base *ab) 5373 { 5374 /* try to send pending beacons first. they take priority */ 5375 wake_up(&ab->wmi_ab.tx_credits_wq); 5376 } 5377 5378 static void ath11k_wmi_htc_tx_complete(struct ath11k_base *ab, 5379 struct sk_buff *skb) 5380 { 5381 dev_kfree_skb(skb); 5382 } 5383 5384 static bool ath11k_reg_is_world_alpha(char *alpha) 5385 { 5386 return alpha[0] == '0' && alpha[1] == '0'; 5387 } 5388 5389 static int ath11k_reg_chan_list_event(struct ath11k_base *ab, struct sk_buff *skb) 5390 { 5391 struct cur_regulatory_info *reg_info = NULL; 5392 struct ieee80211_regdomain *regd = NULL; 5393 bool intersect = false; 5394 int ret = 0, pdev_idx; 5395 struct ath11k *ar; 5396 5397 reg_info = kzalloc(sizeof(*reg_info), GFP_ATOMIC); 5398 if (!reg_info) { 5399 ret = -ENOMEM; 5400 goto fallback; 5401 } 5402 5403 ret = ath11k_pull_reg_chan_list_update_ev(ab, skb, reg_info); 5404 if (ret) { 5405 ath11k_warn(ab, "failed to extract regulatory info from received event\n"); 5406 goto fallback; 5407 } 5408 5409 if (reg_info->status_code != REG_SET_CC_STATUS_PASS) { 5410 /* In case of failure to set the requested ctry, 5411 * fw retains the current regd. We print a failure info 5412 * and return from here. 5413 */ 5414 ath11k_warn(ab, "Failed to set the requested Country regulatory setting\n"); 5415 goto mem_free; 5416 } 5417 5418 pdev_idx = reg_info->phy_id; 5419 5420 if (pdev_idx >= ab->num_radios) { 5421 /* Process the event for phy0 only if single_pdev_only 5422 * is true. If pdev_idx is valid but not 0, discard the 5423 * event. Otherwise, it goes to fallback. 5424 */ 5425 if (ab->hw_params.single_pdev_only && 5426 pdev_idx < ab->hw_params.num_rxmda_per_pdev) 5427 goto mem_free; 5428 else 5429 goto fallback; 5430 } 5431 5432 /* Avoid multiple overwrites to default regd, during core 5433 * stop-start after mac registration. 5434 */ 5435 if (ab->default_regd[pdev_idx] && !ab->new_regd[pdev_idx] && 5436 !memcmp((char *)ab->default_regd[pdev_idx]->alpha2, 5437 (char *)reg_info->alpha2, 2)) 5438 goto mem_free; 5439 5440 /* Intersect new rules with default regd if a new country setting was 5441 * requested, i.e a default regd was already set during initialization 5442 * and the regd coming from this event has a valid country info. 5443 */ 5444 if (ab->default_regd[pdev_idx] && 5445 !ath11k_reg_is_world_alpha((char *) 5446 ab->default_regd[pdev_idx]->alpha2) && 5447 !ath11k_reg_is_world_alpha((char *)reg_info->alpha2)) 5448 intersect = true; 5449 5450 regd = ath11k_reg_build_regd(ab, reg_info, intersect); 5451 if (!regd) { 5452 ath11k_warn(ab, "failed to build regd from reg_info\n"); 5453 goto fallback; 5454 } 5455 5456 spin_lock(&ab->base_lock); 5457 if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags)) { 5458 /* Once mac is registered, ar is valid and all CC events from 5459 * fw is considered to be received due to user requests 5460 * currently. 5461 * Free previously built regd before assigning the newly 5462 * generated regd to ar. NULL pointer handling will be 5463 * taken care by kfree itself. 5464 */ 5465 ar = ab->pdevs[pdev_idx].ar; 5466 kfree(ab->new_regd[pdev_idx]); 5467 ab->new_regd[pdev_idx] = regd; 5468 ieee80211_queue_work(ar->hw, &ar->regd_update_work); 5469 } else { 5470 /* Multiple events for the same *ar is not expected. But we 5471 * can still clear any previously stored default_regd if we 5472 * are receiving this event for the same radio by mistake. 5473 * NULL pointer handling will be taken care by kfree itself. 5474 */ 5475 kfree(ab->default_regd[pdev_idx]); 5476 /* This regd would be applied during mac registration */ 5477 ab->default_regd[pdev_idx] = regd; 5478 } 5479 ab->dfs_region = reg_info->dfs_region; 5480 spin_unlock(&ab->base_lock); 5481 5482 goto mem_free; 5483 5484 fallback: 5485 /* Fallback to older reg (by sending previous country setting 5486 * again if fw has succeded and we failed to process here. 5487 * The Regdomain should be uniform across driver and fw. Since the 5488 * FW has processed the command and sent a success status, we expect 5489 * this function to succeed as well. If it doesn't, CTRY needs to be 5490 * reverted at the fw and the old SCAN_CHAN_LIST cmd needs to be sent. 5491 */ 5492 /* TODO: This is rare, but still should also be handled */ 5493 WARN_ON(1); 5494 mem_free: 5495 if (reg_info) { 5496 kfree(reg_info->reg_rules_2g_ptr); 5497 kfree(reg_info->reg_rules_5g_ptr); 5498 kfree(reg_info); 5499 } 5500 return ret; 5501 } 5502 5503 static int ath11k_wmi_tlv_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len, 5504 const void *ptr, void *data) 5505 { 5506 struct wmi_tlv_rdy_parse *rdy_parse = data; 5507 struct wmi_ready_event fixed_param; 5508 struct wmi_mac_addr *addr_list; 5509 struct ath11k_pdev *pdev; 5510 u32 num_mac_addr; 5511 int i; 5512 5513 switch (tag) { 5514 case WMI_TAG_READY_EVENT: 5515 memset(&fixed_param, 0, sizeof(fixed_param)); 5516 memcpy(&fixed_param, (struct wmi_ready_event *)ptr, 5517 min_t(u16, sizeof(fixed_param), len)); 5518 ab->wlan_init_status = fixed_param.ready_event_min.status; 5519 rdy_parse->num_extra_mac_addr = 5520 fixed_param.ready_event_min.num_extra_mac_addr; 5521 5522 ether_addr_copy(ab->mac_addr, 5523 fixed_param.ready_event_min.mac_addr.addr); 5524 ab->pktlog_defs_checksum = fixed_param.pktlog_defs_checksum; 5525 ab->wmi_ready = true; 5526 break; 5527 case WMI_TAG_ARRAY_FIXED_STRUCT: 5528 addr_list = (struct wmi_mac_addr *)ptr; 5529 num_mac_addr = rdy_parse->num_extra_mac_addr; 5530 5531 if (!(ab->num_radios > 1 && num_mac_addr >= ab->num_radios)) 5532 break; 5533 5534 for (i = 0; i < ab->num_radios; i++) { 5535 pdev = &ab->pdevs[i]; 5536 ether_addr_copy(pdev->mac_addr, addr_list[i].addr); 5537 } 5538 ab->pdevs_macaddr_valid = true; 5539 break; 5540 default: 5541 break; 5542 } 5543 5544 return 0; 5545 } 5546 5547 static int ath11k_ready_event(struct ath11k_base *ab, struct sk_buff *skb) 5548 { 5549 struct wmi_tlv_rdy_parse rdy_parse = { }; 5550 int ret; 5551 5552 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len, 5553 ath11k_wmi_tlv_rdy_parse, &rdy_parse); 5554 if (ret) { 5555 ath11k_warn(ab, "failed to parse tlv %d\n", ret); 5556 return ret; 5557 } 5558 5559 complete(&ab->wmi_ab.unified_ready); 5560 return 0; 5561 } 5562 5563 static void ath11k_peer_delete_resp_event(struct ath11k_base *ab, struct sk_buff *skb) 5564 { 5565 struct wmi_peer_delete_resp_event peer_del_resp; 5566 5567 if (ath11k_pull_peer_del_resp_ev(ab, skb, &peer_del_resp) != 0) { 5568 ath11k_warn(ab, "failed to extract peer delete resp"); 5569 return; 5570 } 5571 5572 /* TODO: Do we need to validate whether ath11k_peer_find() return NULL 5573 * Why this is needed when there is HTT event for peer delete 5574 */ 5575 } 5576 5577 static inline const char *ath11k_wmi_vdev_resp_print(u32 vdev_resp_status) 5578 { 5579 switch (vdev_resp_status) { 5580 case WMI_VDEV_START_RESPONSE_INVALID_VDEVID: 5581 return "invalid vdev id"; 5582 case WMI_VDEV_START_RESPONSE_NOT_SUPPORTED: 5583 return "not supported"; 5584 case WMI_VDEV_START_RESPONSE_DFS_VIOLATION: 5585 return "dfs violation"; 5586 case WMI_VDEV_START_RESPONSE_INVALID_REGDOMAIN: 5587 return "invalid regdomain"; 5588 default: 5589 return "unknown"; 5590 } 5591 } 5592 5593 static void ath11k_vdev_start_resp_event(struct ath11k_base *ab, struct sk_buff *skb) 5594 { 5595 struct wmi_vdev_start_resp_event vdev_start_resp; 5596 struct ath11k *ar; 5597 u32 status; 5598 5599 if (ath11k_pull_vdev_start_resp_tlv(ab, skb, &vdev_start_resp) != 0) { 5600 ath11k_warn(ab, "failed to extract vdev start resp"); 5601 return; 5602 } 5603 5604 rcu_read_lock(); 5605 ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_start_resp.vdev_id); 5606 if (!ar) { 5607 ath11k_warn(ab, "invalid vdev id in vdev start resp ev %d", 5608 vdev_start_resp.vdev_id); 5609 rcu_read_unlock(); 5610 return; 5611 } 5612 5613 ar->last_wmi_vdev_start_status = 0; 5614 5615 status = vdev_start_resp.status; 5616 5617 if (WARN_ON_ONCE(status)) { 5618 ath11k_warn(ab, "vdev start resp error status %d (%s)\n", 5619 status, ath11k_wmi_vdev_resp_print(status)); 5620 ar->last_wmi_vdev_start_status = status; 5621 } 5622 5623 complete(&ar->vdev_setup_done); 5624 5625 rcu_read_unlock(); 5626 5627 ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev start resp for vdev id %d", 5628 vdev_start_resp.vdev_id); 5629 } 5630 5631 static void ath11k_bcn_tx_status_event(struct ath11k_base *ab, struct sk_buff *skb) 5632 { 5633 u32 vdev_id, tx_status; 5634 5635 if (ath11k_pull_bcn_tx_status_ev(ab, skb->data, skb->len, 5636 &vdev_id, &tx_status) != 0) { 5637 ath11k_warn(ab, "failed to extract bcn tx status"); 5638 return; 5639 } 5640 } 5641 5642 static void ath11k_vdev_stopped_event(struct ath11k_base *ab, struct sk_buff *skb) 5643 { 5644 struct ath11k *ar; 5645 u32 vdev_id = 0; 5646 5647 if (ath11k_pull_vdev_stopped_param_tlv(ab, skb, &vdev_id) != 0) { 5648 ath11k_warn(ab, "failed to extract vdev stopped event"); 5649 return; 5650 } 5651 5652 rcu_read_lock(); 5653 ar = ath11k_mac_get_ar_vdev_stop_status(ab, vdev_id); 5654 if (!ar) { 5655 ath11k_warn(ab, "invalid vdev id in vdev stopped ev %d", 5656 vdev_id); 5657 rcu_read_unlock(); 5658 return; 5659 } 5660 5661 complete(&ar->vdev_setup_done); 5662 5663 rcu_read_unlock(); 5664 5665 ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev stopped for vdev id %d", vdev_id); 5666 } 5667 5668 static void ath11k_mgmt_rx_event(struct ath11k_base *ab, struct sk_buff *skb) 5669 { 5670 struct mgmt_rx_event_params rx_ev = {0}; 5671 struct ath11k *ar; 5672 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); 5673 struct ieee80211_hdr *hdr; 5674 u16 fc; 5675 struct ieee80211_supported_band *sband; 5676 5677 if (ath11k_pull_mgmt_rx_params_tlv(ab, skb, &rx_ev) != 0) { 5678 ath11k_warn(ab, "failed to extract mgmt rx event"); 5679 dev_kfree_skb(skb); 5680 return; 5681 } 5682 5683 memset(status, 0, sizeof(*status)); 5684 5685 ath11k_dbg(ab, ATH11K_DBG_MGMT, "mgmt rx event status %08x\n", 5686 rx_ev.status); 5687 5688 rcu_read_lock(); 5689 ar = ath11k_mac_get_ar_by_pdev_id(ab, rx_ev.pdev_id); 5690 5691 if (!ar) { 5692 ath11k_warn(ab, "invalid pdev_id %d in mgmt_rx_event\n", 5693 rx_ev.pdev_id); 5694 dev_kfree_skb(skb); 5695 goto exit; 5696 } 5697 5698 if ((test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) || 5699 (rx_ev.status & (WMI_RX_STATUS_ERR_DECRYPT | 5700 WMI_RX_STATUS_ERR_KEY_CACHE_MISS | WMI_RX_STATUS_ERR_CRC))) { 5701 dev_kfree_skb(skb); 5702 goto exit; 5703 } 5704 5705 if (rx_ev.status & WMI_RX_STATUS_ERR_MIC) 5706 status->flag |= RX_FLAG_MMIC_ERROR; 5707 5708 if (rx_ev.chan_freq >= ATH11K_MIN_6G_FREQ) { 5709 status->band = NL80211_BAND_6GHZ; 5710 } else if (rx_ev.channel >= 1 && rx_ev.channel <= 14) { 5711 status->band = NL80211_BAND_2GHZ; 5712 } else if (rx_ev.channel >= 36 && rx_ev.channel <= ATH11K_MAX_5G_CHAN) { 5713 status->band = NL80211_BAND_5GHZ; 5714 } else { 5715 /* Shouldn't happen unless list of advertised channels to 5716 * mac80211 has been changed. 5717 */ 5718 WARN_ON_ONCE(1); 5719 dev_kfree_skb(skb); 5720 goto exit; 5721 } 5722 5723 if (rx_ev.phy_mode == MODE_11B && 5724 (status->band == NL80211_BAND_5GHZ || status->band == NL80211_BAND_6GHZ)) 5725 ath11k_dbg(ab, ATH11K_DBG_WMI, 5726 "wmi mgmt rx 11b (CCK) on 5/6GHz, band = %d\n", status->band); 5727 5728 sband = &ar->mac.sbands[status->band]; 5729 5730 status->freq = ieee80211_channel_to_frequency(rx_ev.channel, 5731 status->band); 5732 status->signal = rx_ev.snr + ATH11K_DEFAULT_NOISE_FLOOR; 5733 status->rate_idx = ath11k_mac_bitrate_to_idx(sband, rx_ev.rate / 100); 5734 5735 hdr = (struct ieee80211_hdr *)skb->data; 5736 fc = le16_to_cpu(hdr->frame_control); 5737 5738 /* Firmware is guaranteed to report all essential management frames via 5739 * WMI while it can deliver some extra via HTT. Since there can be 5740 * duplicates split the reporting wrt monitor/sniffing. 5741 */ 5742 status->flag |= RX_FLAG_SKIP_MONITOR; 5743 5744 /* In case of PMF, FW delivers decrypted frames with Protected Bit set. 5745 * Don't clear that. Also, FW delivers broadcast management frames 5746 * (ex: group privacy action frames in mesh) as encrypted payload. 5747 */ 5748 if (ieee80211_has_protected(hdr->frame_control) && 5749 !is_multicast_ether_addr(ieee80211_get_DA(hdr))) { 5750 status->flag |= RX_FLAG_DECRYPTED; 5751 5752 if (!ieee80211_is_robust_mgmt_frame(skb)) { 5753 status->flag |= RX_FLAG_IV_STRIPPED | 5754 RX_FLAG_MMIC_STRIPPED; 5755 hdr->frame_control = __cpu_to_le16(fc & 5756 ~IEEE80211_FCTL_PROTECTED); 5757 } 5758 } 5759 5760 /* TODO: Pending handle beacon implementation 5761 *if (ieee80211_is_beacon(hdr->frame_control)) 5762 * ath11k_mac_handle_beacon(ar, skb); 5763 */ 5764 5765 ath11k_dbg(ab, ATH11K_DBG_MGMT, 5766 "event mgmt rx skb %pK len %d ftype %02x stype %02x\n", 5767 skb, skb->len, 5768 fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE); 5769 5770 ath11k_dbg(ab, ATH11K_DBG_MGMT, 5771 "event mgmt rx freq %d band %d snr %d, rate_idx %d\n", 5772 status->freq, status->band, status->signal, 5773 status->rate_idx); 5774 5775 ieee80211_rx_ni(ar->hw, skb); 5776 5777 exit: 5778 rcu_read_unlock(); 5779 } 5780 5781 static void ath11k_mgmt_tx_compl_event(struct ath11k_base *ab, struct sk_buff *skb) 5782 { 5783 struct wmi_mgmt_tx_compl_event tx_compl_param = {0}; 5784 struct ath11k *ar; 5785 5786 if (ath11k_pull_mgmt_tx_compl_param_tlv(ab, skb, &tx_compl_param) != 0) { 5787 ath11k_warn(ab, "failed to extract mgmt tx compl event"); 5788 return; 5789 } 5790 5791 rcu_read_lock(); 5792 ar = ath11k_mac_get_ar_by_pdev_id(ab, tx_compl_param.pdev_id); 5793 if (!ar) { 5794 ath11k_warn(ab, "invalid pdev id %d in mgmt_tx_compl_event\n", 5795 tx_compl_param.pdev_id); 5796 goto exit; 5797 } 5798 5799 wmi_process_mgmt_tx_comp(ar, tx_compl_param.desc_id, 5800 tx_compl_param.status); 5801 5802 ath11k_dbg(ab, ATH11K_DBG_MGMT, 5803 "mgmt tx compl ev pdev_id %d, desc_id %d, status %d", 5804 tx_compl_param.pdev_id, tx_compl_param.desc_id, 5805 tx_compl_param.status); 5806 5807 exit: 5808 rcu_read_unlock(); 5809 } 5810 5811 static struct ath11k *ath11k_get_ar_on_scan_abort(struct ath11k_base *ab, 5812 u32 vdev_id) 5813 { 5814 int i; 5815 struct ath11k_pdev *pdev; 5816 struct ath11k *ar; 5817 5818 for (i = 0; i < ab->num_radios; i++) { 5819 pdev = rcu_dereference(ab->pdevs_active[i]); 5820 if (pdev && pdev->ar) { 5821 ar = pdev->ar; 5822 5823 spin_lock_bh(&ar->data_lock); 5824 if (ar->scan.state == ATH11K_SCAN_ABORTING && 5825 ar->scan.vdev_id == vdev_id) { 5826 spin_unlock_bh(&ar->data_lock); 5827 return ar; 5828 } 5829 spin_unlock_bh(&ar->data_lock); 5830 } 5831 } 5832 return NULL; 5833 } 5834 5835 static void ath11k_scan_event(struct ath11k_base *ab, struct sk_buff *skb) 5836 { 5837 struct ath11k *ar; 5838 struct wmi_scan_event scan_ev = {0}; 5839 5840 if (ath11k_pull_scan_ev(ab, skb, &scan_ev) != 0) { 5841 ath11k_warn(ab, "failed to extract scan event"); 5842 return; 5843 } 5844 5845 rcu_read_lock(); 5846 5847 /* In case the scan was cancelled, ex. during interface teardown, 5848 * the interface will not be found in active interfaces. 5849 * Rather, in such scenarios, iterate over the active pdev's to 5850 * search 'ar' if the corresponding 'ar' scan is ABORTING and the 5851 * aborting scan's vdev id matches this event info. 5852 */ 5853 if (scan_ev.event_type == WMI_SCAN_EVENT_COMPLETED && 5854 scan_ev.reason == WMI_SCAN_REASON_CANCELLED) 5855 ar = ath11k_get_ar_on_scan_abort(ab, scan_ev.vdev_id); 5856 else 5857 ar = ath11k_mac_get_ar_by_vdev_id(ab, scan_ev.vdev_id); 5858 5859 if (!ar) { 5860 ath11k_warn(ab, "Received scan event for unknown vdev"); 5861 rcu_read_unlock(); 5862 return; 5863 } 5864 5865 spin_lock_bh(&ar->data_lock); 5866 5867 ath11k_dbg(ab, ATH11K_DBG_WMI, 5868 "scan event %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n", 5869 ath11k_wmi_event_scan_type_str(scan_ev.event_type, scan_ev.reason), 5870 scan_ev.event_type, scan_ev.reason, scan_ev.channel_freq, 5871 scan_ev.scan_req_id, scan_ev.scan_id, scan_ev.vdev_id, 5872 ath11k_scan_state_str(ar->scan.state), ar->scan.state); 5873 5874 switch (scan_ev.event_type) { 5875 case WMI_SCAN_EVENT_STARTED: 5876 ath11k_wmi_event_scan_started(ar); 5877 break; 5878 case WMI_SCAN_EVENT_COMPLETED: 5879 ath11k_wmi_event_scan_completed(ar); 5880 break; 5881 case WMI_SCAN_EVENT_BSS_CHANNEL: 5882 ath11k_wmi_event_scan_bss_chan(ar); 5883 break; 5884 case WMI_SCAN_EVENT_FOREIGN_CHAN: 5885 ath11k_wmi_event_scan_foreign_chan(ar, scan_ev.channel_freq); 5886 break; 5887 case WMI_SCAN_EVENT_START_FAILED: 5888 ath11k_warn(ab, "received scan start failure event\n"); 5889 ath11k_wmi_event_scan_start_failed(ar); 5890 break; 5891 case WMI_SCAN_EVENT_DEQUEUED: 5892 case WMI_SCAN_EVENT_PREEMPTED: 5893 case WMI_SCAN_EVENT_RESTARTED: 5894 case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT: 5895 default: 5896 break; 5897 } 5898 5899 spin_unlock_bh(&ar->data_lock); 5900 5901 rcu_read_unlock(); 5902 } 5903 5904 static void ath11k_peer_sta_kickout_event(struct ath11k_base *ab, struct sk_buff *skb) 5905 { 5906 struct wmi_peer_sta_kickout_arg arg = {}; 5907 struct ieee80211_sta *sta; 5908 struct ath11k_peer *peer; 5909 struct ath11k *ar; 5910 5911 if (ath11k_pull_peer_sta_kickout_ev(ab, skb, &arg) != 0) { 5912 ath11k_warn(ab, "failed to extract peer sta kickout event"); 5913 return; 5914 } 5915 5916 rcu_read_lock(); 5917 5918 spin_lock_bh(&ab->base_lock); 5919 5920 peer = ath11k_peer_find_by_addr(ab, arg.mac_addr); 5921 5922 if (!peer) { 5923 ath11k_warn(ab, "peer not found %pM\n", 5924 arg.mac_addr); 5925 goto exit; 5926 } 5927 5928 ar = ath11k_mac_get_ar_by_vdev_id(ab, peer->vdev_id); 5929 if (!ar) { 5930 ath11k_warn(ab, "invalid vdev id in peer sta kickout ev %d", 5931 peer->vdev_id); 5932 goto exit; 5933 } 5934 5935 sta = ieee80211_find_sta_by_ifaddr(ar->hw, 5936 arg.mac_addr, NULL); 5937 if (!sta) { 5938 ath11k_warn(ab, "Spurious quick kickout for STA %pM\n", 5939 arg.mac_addr); 5940 goto exit; 5941 } 5942 5943 ath11k_dbg(ab, ATH11K_DBG_WMI, "peer sta kickout event %pM", 5944 arg.mac_addr); 5945 5946 ieee80211_report_low_ack(sta, 10); 5947 5948 exit: 5949 spin_unlock_bh(&ab->base_lock); 5950 rcu_read_unlock(); 5951 } 5952 5953 static void ath11k_roam_event(struct ath11k_base *ab, struct sk_buff *skb) 5954 { 5955 struct wmi_roam_event roam_ev = {}; 5956 struct ath11k *ar; 5957 5958 if (ath11k_pull_roam_ev(ab, skb, &roam_ev) != 0) { 5959 ath11k_warn(ab, "failed to extract roam event"); 5960 return; 5961 } 5962 5963 ath11k_dbg(ab, ATH11K_DBG_WMI, 5964 "wmi roam event vdev %u reason 0x%08x rssi %d\n", 5965 roam_ev.vdev_id, roam_ev.reason, roam_ev.rssi); 5966 5967 rcu_read_lock(); 5968 ar = ath11k_mac_get_ar_by_vdev_id(ab, roam_ev.vdev_id); 5969 if (!ar) { 5970 ath11k_warn(ab, "invalid vdev id in roam ev %d", 5971 roam_ev.vdev_id); 5972 rcu_read_unlock(); 5973 return; 5974 } 5975 5976 if (roam_ev.reason >= WMI_ROAM_REASON_MAX) 5977 ath11k_warn(ab, "ignoring unknown roam event reason %d on vdev %i\n", 5978 roam_ev.reason, roam_ev.vdev_id); 5979 5980 switch (roam_ev.reason) { 5981 case WMI_ROAM_REASON_BEACON_MISS: 5982 /* TODO: Pending beacon miss and connection_loss_work 5983 * implementation 5984 * ath11k_mac_handle_beacon_miss(ar, vdev_id); 5985 */ 5986 break; 5987 case WMI_ROAM_REASON_BETTER_AP: 5988 case WMI_ROAM_REASON_LOW_RSSI: 5989 case WMI_ROAM_REASON_SUITABLE_AP_FOUND: 5990 case WMI_ROAM_REASON_HO_FAILED: 5991 ath11k_warn(ab, "ignoring not implemented roam event reason %d on vdev %i\n", 5992 roam_ev.reason, roam_ev.vdev_id); 5993 break; 5994 } 5995 5996 rcu_read_unlock(); 5997 } 5998 5999 static void ath11k_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb) 6000 { 6001 struct wmi_chan_info_event ch_info_ev = {0}; 6002 struct ath11k *ar; 6003 struct survey_info *survey; 6004 int idx; 6005 /* HW channel counters frequency value in hertz */ 6006 u32 cc_freq_hz = ab->cc_freq_hz; 6007 6008 if (ath11k_pull_chan_info_ev(ab, skb->data, skb->len, &ch_info_ev) != 0) { 6009 ath11k_warn(ab, "failed to extract chan info event"); 6010 return; 6011 } 6012 6013 ath11k_dbg(ab, ATH11K_DBG_WMI, 6014 "chan info vdev_id %d err_code %d freq %d cmd_flags %d noise_floor %d rx_clear_count %d cycle_count %d mac_clk_mhz %d\n", 6015 ch_info_ev.vdev_id, ch_info_ev.err_code, ch_info_ev.freq, 6016 ch_info_ev.cmd_flags, ch_info_ev.noise_floor, 6017 ch_info_ev.rx_clear_count, ch_info_ev.cycle_count, 6018 ch_info_ev.mac_clk_mhz); 6019 6020 if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_END_RESP) { 6021 ath11k_dbg(ab, ATH11K_DBG_WMI, "chan info report completed\n"); 6022 return; 6023 } 6024 6025 rcu_read_lock(); 6026 ar = ath11k_mac_get_ar_by_vdev_id(ab, ch_info_ev.vdev_id); 6027 if (!ar) { 6028 ath11k_warn(ab, "invalid vdev id in chan info ev %d", 6029 ch_info_ev.vdev_id); 6030 rcu_read_unlock(); 6031 return; 6032 } 6033 spin_lock_bh(&ar->data_lock); 6034 6035 switch (ar->scan.state) { 6036 case ATH11K_SCAN_IDLE: 6037 case ATH11K_SCAN_STARTING: 6038 ath11k_warn(ab, "received chan info event without a scan request, ignoring\n"); 6039 goto exit; 6040 case ATH11K_SCAN_RUNNING: 6041 case ATH11K_SCAN_ABORTING: 6042 break; 6043 } 6044 6045 idx = freq_to_idx(ar, ch_info_ev.freq); 6046 if (idx >= ARRAY_SIZE(ar->survey)) { 6047 ath11k_warn(ab, "chan info: invalid frequency %d (idx %d out of bounds)\n", 6048 ch_info_ev.freq, idx); 6049 goto exit; 6050 } 6051 6052 /* If FW provides MAC clock frequency in Mhz, overriding the initialized 6053 * HW channel counters frequency value 6054 */ 6055 if (ch_info_ev.mac_clk_mhz) 6056 cc_freq_hz = (ch_info_ev.mac_clk_mhz * 1000); 6057 6058 if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_START_RESP) { 6059 survey = &ar->survey[idx]; 6060 memset(survey, 0, sizeof(*survey)); 6061 survey->noise = ch_info_ev.noise_floor; 6062 survey->filled = SURVEY_INFO_NOISE_DBM | SURVEY_INFO_TIME | 6063 SURVEY_INFO_TIME_BUSY; 6064 survey->time = div_u64(ch_info_ev.cycle_count, cc_freq_hz); 6065 survey->time_busy = div_u64(ch_info_ev.rx_clear_count, cc_freq_hz); 6066 } 6067 exit: 6068 spin_unlock_bh(&ar->data_lock); 6069 rcu_read_unlock(); 6070 } 6071 6072 static void 6073 ath11k_pdev_bss_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb) 6074 { 6075 struct wmi_pdev_bss_chan_info_event bss_ch_info_ev = {}; 6076 struct survey_info *survey; 6077 struct ath11k *ar; 6078 u32 cc_freq_hz = ab->cc_freq_hz; 6079 u64 busy, total, tx, rx, rx_bss; 6080 int idx; 6081 6082 if (ath11k_pull_pdev_bss_chan_info_ev(ab, skb, &bss_ch_info_ev) != 0) { 6083 ath11k_warn(ab, "failed to extract pdev bss chan info event"); 6084 return; 6085 } 6086 6087 busy = (u64)(bss_ch_info_ev.rx_clear_count_high) << 32 | 6088 bss_ch_info_ev.rx_clear_count_low; 6089 6090 total = (u64)(bss_ch_info_ev.cycle_count_high) << 32 | 6091 bss_ch_info_ev.cycle_count_low; 6092 6093 tx = (u64)(bss_ch_info_ev.tx_cycle_count_high) << 32 | 6094 bss_ch_info_ev.tx_cycle_count_low; 6095 6096 rx = (u64)(bss_ch_info_ev.rx_cycle_count_high) << 32 | 6097 bss_ch_info_ev.rx_cycle_count_low; 6098 6099 rx_bss = (u64)(bss_ch_info_ev.rx_bss_cycle_count_high) << 32 | 6100 bss_ch_info_ev.rx_bss_cycle_count_low; 6101 6102 ath11k_dbg(ab, ATH11K_DBG_WMI, 6103 "pdev bss chan info:\n pdev_id: %d freq: %d noise: %d cycle: busy %llu total %llu tx %llu rx %llu rx_bss %llu\n", 6104 bss_ch_info_ev.pdev_id, bss_ch_info_ev.freq, 6105 bss_ch_info_ev.noise_floor, busy, total, 6106 tx, rx, rx_bss); 6107 6108 rcu_read_lock(); 6109 ar = ath11k_mac_get_ar_by_pdev_id(ab, bss_ch_info_ev.pdev_id); 6110 6111 if (!ar) { 6112 ath11k_warn(ab, "invalid pdev id %d in bss_chan_info event\n", 6113 bss_ch_info_ev.pdev_id); 6114 rcu_read_unlock(); 6115 return; 6116 } 6117 6118 spin_lock_bh(&ar->data_lock); 6119 idx = freq_to_idx(ar, bss_ch_info_ev.freq); 6120 if (idx >= ARRAY_SIZE(ar->survey)) { 6121 ath11k_warn(ab, "bss chan info: invalid frequency %d (idx %d out of bounds)\n", 6122 bss_ch_info_ev.freq, idx); 6123 goto exit; 6124 } 6125 6126 survey = &ar->survey[idx]; 6127 6128 survey->noise = bss_ch_info_ev.noise_floor; 6129 survey->time = div_u64(total, cc_freq_hz); 6130 survey->time_busy = div_u64(busy, cc_freq_hz); 6131 survey->time_rx = div_u64(rx_bss, cc_freq_hz); 6132 survey->time_tx = div_u64(tx, cc_freq_hz); 6133 survey->filled |= (SURVEY_INFO_NOISE_DBM | 6134 SURVEY_INFO_TIME | 6135 SURVEY_INFO_TIME_BUSY | 6136 SURVEY_INFO_TIME_RX | 6137 SURVEY_INFO_TIME_TX); 6138 exit: 6139 spin_unlock_bh(&ar->data_lock); 6140 complete(&ar->bss_survey_done); 6141 6142 rcu_read_unlock(); 6143 } 6144 6145 static void ath11k_vdev_install_key_compl_event(struct ath11k_base *ab, 6146 struct sk_buff *skb) 6147 { 6148 struct wmi_vdev_install_key_complete_arg install_key_compl = {0}; 6149 struct ath11k *ar; 6150 6151 if (ath11k_pull_vdev_install_key_compl_ev(ab, skb, &install_key_compl) != 0) { 6152 ath11k_warn(ab, "failed to extract install key compl event"); 6153 return; 6154 } 6155 6156 ath11k_dbg(ab, ATH11K_DBG_WMI, 6157 "vdev install key ev idx %d flags %08x macaddr %pM status %d\n", 6158 install_key_compl.key_idx, install_key_compl.key_flags, 6159 install_key_compl.macaddr, install_key_compl.status); 6160 6161 rcu_read_lock(); 6162 ar = ath11k_mac_get_ar_by_vdev_id(ab, install_key_compl.vdev_id); 6163 if (!ar) { 6164 ath11k_warn(ab, "invalid vdev id in install key compl ev %d", 6165 install_key_compl.vdev_id); 6166 rcu_read_unlock(); 6167 return; 6168 } 6169 6170 ar->install_key_status = 0; 6171 6172 if (install_key_compl.status != WMI_VDEV_INSTALL_KEY_COMPL_STATUS_SUCCESS) { 6173 ath11k_warn(ab, "install key failed for %pM status %d\n", 6174 install_key_compl.macaddr, install_key_compl.status); 6175 ar->install_key_status = install_key_compl.status; 6176 } 6177 6178 complete(&ar->install_key_done); 6179 rcu_read_unlock(); 6180 } 6181 6182 static void ath11k_service_available_event(struct ath11k_base *ab, struct sk_buff *skb) 6183 { 6184 const void **tb; 6185 const struct wmi_service_available_event *ev; 6186 int ret; 6187 int i, j; 6188 6189 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 6190 if (IS_ERR(tb)) { 6191 ret = PTR_ERR(tb); 6192 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 6193 return; 6194 } 6195 6196 ev = tb[WMI_TAG_SERVICE_AVAILABLE_EVENT]; 6197 if (!ev) { 6198 ath11k_warn(ab, "failed to fetch svc available ev"); 6199 kfree(tb); 6200 return; 6201 } 6202 6203 /* TODO: Use wmi_service_segment_offset information to get the service 6204 * especially when more services are advertised in multiple sevice 6205 * available events. 6206 */ 6207 for (i = 0, j = WMI_MAX_SERVICE; 6208 i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT_SERVICE; 6209 i++) { 6210 do { 6211 if (ev->wmi_service_segment_bitmap[i] & 6212 BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32)) 6213 set_bit(j, ab->wmi_ab.svc_map); 6214 } while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32); 6215 } 6216 6217 ath11k_dbg(ab, ATH11K_DBG_WMI, 6218 "wmi_ext_service_bitmap 0:0x%x, 1:0x%x, 2:0x%x, 3:0x%x", 6219 ev->wmi_service_segment_bitmap[0], ev->wmi_service_segment_bitmap[1], 6220 ev->wmi_service_segment_bitmap[2], ev->wmi_service_segment_bitmap[3]); 6221 6222 kfree(tb); 6223 } 6224 6225 static void ath11k_peer_assoc_conf_event(struct ath11k_base *ab, struct sk_buff *skb) 6226 { 6227 struct wmi_peer_assoc_conf_arg peer_assoc_conf = {0}; 6228 struct ath11k *ar; 6229 6230 if (ath11k_pull_peer_assoc_conf_ev(ab, skb, &peer_assoc_conf) != 0) { 6231 ath11k_warn(ab, "failed to extract peer assoc conf event"); 6232 return; 6233 } 6234 6235 ath11k_dbg(ab, ATH11K_DBG_WMI, 6236 "peer assoc conf ev vdev id %d macaddr %pM\n", 6237 peer_assoc_conf.vdev_id, peer_assoc_conf.macaddr); 6238 6239 rcu_read_lock(); 6240 ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_assoc_conf.vdev_id); 6241 6242 if (!ar) { 6243 ath11k_warn(ab, "invalid vdev id in peer assoc conf ev %d", 6244 peer_assoc_conf.vdev_id); 6245 rcu_read_unlock(); 6246 return; 6247 } 6248 6249 complete(&ar->peer_assoc_done); 6250 rcu_read_unlock(); 6251 } 6252 6253 static void ath11k_update_stats_event(struct ath11k_base *ab, struct sk_buff *skb) 6254 { 6255 ath11k_debugfs_fw_stats_process(ab, skb); 6256 } 6257 6258 /* PDEV_CTL_FAILSAFE_CHECK_EVENT is received from FW when the frequency scanned 6259 * is not part of BDF CTL(Conformance test limits) table entries. 6260 */ 6261 static void ath11k_pdev_ctl_failsafe_check_event(struct ath11k_base *ab, 6262 struct sk_buff *skb) 6263 { 6264 const void **tb; 6265 const struct wmi_pdev_ctl_failsafe_chk_event *ev; 6266 int ret; 6267 6268 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 6269 if (IS_ERR(tb)) { 6270 ret = PTR_ERR(tb); 6271 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 6272 return; 6273 } 6274 6275 ev = tb[WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT]; 6276 if (!ev) { 6277 ath11k_warn(ab, "failed to fetch pdev ctl failsafe check ev"); 6278 kfree(tb); 6279 return; 6280 } 6281 6282 ath11k_dbg(ab, ATH11K_DBG_WMI, 6283 "pdev ctl failsafe check ev status %d\n", 6284 ev->ctl_failsafe_status); 6285 6286 /* If ctl_failsafe_status is set to 1 FW will max out the Transmit power 6287 * to 10 dBm else the CTL power entry in the BDF would be picked up. 6288 */ 6289 if (ev->ctl_failsafe_status != 0) 6290 ath11k_warn(ab, "pdev ctl failsafe failure status %d", 6291 ev->ctl_failsafe_status); 6292 6293 kfree(tb); 6294 } 6295 6296 static void 6297 ath11k_wmi_process_csa_switch_count_event(struct ath11k_base *ab, 6298 const struct wmi_pdev_csa_switch_ev *ev, 6299 const u32 *vdev_ids) 6300 { 6301 int i; 6302 struct ath11k_vif *arvif; 6303 6304 /* Finish CSA once the switch count becomes NULL */ 6305 if (ev->current_switch_count) 6306 return; 6307 6308 rcu_read_lock(); 6309 for (i = 0; i < ev->num_vdevs; i++) { 6310 arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_ids[i]); 6311 6312 if (!arvif) { 6313 ath11k_warn(ab, "Recvd csa status for unknown vdev %d", 6314 vdev_ids[i]); 6315 continue; 6316 } 6317 6318 if (arvif->is_up && arvif->vif->csa_active) 6319 ieee80211_csa_finish(arvif->vif); 6320 } 6321 rcu_read_unlock(); 6322 } 6323 6324 static void 6325 ath11k_wmi_pdev_csa_switch_count_status_event(struct ath11k_base *ab, 6326 struct sk_buff *skb) 6327 { 6328 const void **tb; 6329 const struct wmi_pdev_csa_switch_ev *ev; 6330 const u32 *vdev_ids; 6331 int ret; 6332 6333 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 6334 if (IS_ERR(tb)) { 6335 ret = PTR_ERR(tb); 6336 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 6337 return; 6338 } 6339 6340 ev = tb[WMI_TAG_PDEV_CSA_SWITCH_COUNT_STATUS_EVENT]; 6341 vdev_ids = tb[WMI_TAG_ARRAY_UINT32]; 6342 6343 if (!ev || !vdev_ids) { 6344 ath11k_warn(ab, "failed to fetch pdev csa switch count ev"); 6345 kfree(tb); 6346 return; 6347 } 6348 6349 ath11k_dbg(ab, ATH11K_DBG_WMI, 6350 "pdev csa switch count %d for pdev %d, num_vdevs %d", 6351 ev->current_switch_count, ev->pdev_id, 6352 ev->num_vdevs); 6353 6354 ath11k_wmi_process_csa_switch_count_event(ab, ev, vdev_ids); 6355 6356 kfree(tb); 6357 } 6358 6359 static void 6360 ath11k_wmi_pdev_dfs_radar_detected_event(struct ath11k_base *ab, struct sk_buff *skb) 6361 { 6362 const void **tb; 6363 const struct wmi_pdev_radar_ev *ev; 6364 struct ath11k *ar; 6365 int ret; 6366 6367 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 6368 if (IS_ERR(tb)) { 6369 ret = PTR_ERR(tb); 6370 ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 6371 return; 6372 } 6373 6374 ev = tb[WMI_TAG_PDEV_DFS_RADAR_DETECTION_EVENT]; 6375 6376 if (!ev) { 6377 ath11k_warn(ab, "failed to fetch pdev dfs radar detected ev"); 6378 kfree(tb); 6379 return; 6380 } 6381 6382 ath11k_dbg(ab, ATH11K_DBG_WMI, 6383 "pdev dfs radar detected on pdev %d, detection mode %d, chan freq %d, chan_width %d, detector id %d, seg id %d, timestamp %d, chirp %d, freq offset %d, sidx %d", 6384 ev->pdev_id, ev->detection_mode, ev->chan_freq, ev->chan_width, 6385 ev->detector_id, ev->segment_id, ev->timestamp, ev->is_chirp, 6386 ev->freq_offset, ev->sidx); 6387 6388 ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id); 6389 6390 if (!ar) { 6391 ath11k_warn(ab, "radar detected in invalid pdev %d\n", 6392 ev->pdev_id); 6393 goto exit; 6394 } 6395 6396 ath11k_dbg(ar->ab, ATH11K_DBG_REG, "DFS Radar Detected in pdev %d\n", 6397 ev->pdev_id); 6398 6399 if (ar->dfs_block_radar_events) 6400 ath11k_info(ab, "DFS Radar detected, but ignored as requested\n"); 6401 else 6402 ieee80211_radar_detected(ar->hw); 6403 6404 exit: 6405 kfree(tb); 6406 } 6407 6408 static void 6409 ath11k_wmi_pdev_temperature_event(struct ath11k_base *ab, 6410 struct sk_buff *skb) 6411 { 6412 struct ath11k *ar; 6413 struct wmi_pdev_temperature_event ev = {0}; 6414 6415 if (ath11k_pull_pdev_temp_ev(ab, skb->data, skb->len, &ev) != 0) { 6416 ath11k_warn(ab, "failed to extract pdev temperature event"); 6417 return; 6418 } 6419 6420 ath11k_dbg(ab, ATH11K_DBG_WMI, 6421 "pdev temperature ev temp %d pdev_id %d\n", ev.temp, ev.pdev_id); 6422 6423 ar = ath11k_mac_get_ar_by_pdev_id(ab, ev.pdev_id); 6424 if (!ar) { 6425 ath11k_warn(ab, "invalid pdev id in pdev temperature ev %d", ev.pdev_id); 6426 return; 6427 } 6428 6429 ath11k_thermal_event_temperature(ar, ev.temp); 6430 } 6431 6432 static void ath11k_wmi_tlv_op_rx(struct ath11k_base *ab, struct sk_buff *skb) 6433 { 6434 struct wmi_cmd_hdr *cmd_hdr; 6435 enum wmi_tlv_event_id id; 6436 6437 cmd_hdr = (struct wmi_cmd_hdr *)skb->data; 6438 id = FIELD_GET(WMI_CMD_HDR_CMD_ID, (cmd_hdr->cmd_id)); 6439 6440 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL) 6441 goto out; 6442 6443 switch (id) { 6444 /* Process all the WMI events here */ 6445 case WMI_SERVICE_READY_EVENTID: 6446 ath11k_service_ready_event(ab, skb); 6447 break; 6448 case WMI_SERVICE_READY_EXT_EVENTID: 6449 ath11k_service_ready_ext_event(ab, skb); 6450 break; 6451 case WMI_SERVICE_READY_EXT2_EVENTID: 6452 ath11k_service_ready_ext2_event(ab, skb); 6453 break; 6454 case WMI_REG_CHAN_LIST_CC_EVENTID: 6455 ath11k_reg_chan_list_event(ab, skb); 6456 break; 6457 case WMI_READY_EVENTID: 6458 ath11k_ready_event(ab, skb); 6459 break; 6460 case WMI_PEER_DELETE_RESP_EVENTID: 6461 ath11k_peer_delete_resp_event(ab, skb); 6462 break; 6463 case WMI_VDEV_START_RESP_EVENTID: 6464 ath11k_vdev_start_resp_event(ab, skb); 6465 break; 6466 case WMI_OFFLOAD_BCN_TX_STATUS_EVENTID: 6467 ath11k_bcn_tx_status_event(ab, skb); 6468 break; 6469 case WMI_VDEV_STOPPED_EVENTID: 6470 ath11k_vdev_stopped_event(ab, skb); 6471 break; 6472 case WMI_MGMT_RX_EVENTID: 6473 ath11k_mgmt_rx_event(ab, skb); 6474 /* mgmt_rx_event() owns the skb now! */ 6475 return; 6476 case WMI_MGMT_TX_COMPLETION_EVENTID: 6477 ath11k_mgmt_tx_compl_event(ab, skb); 6478 break; 6479 case WMI_SCAN_EVENTID: 6480 ath11k_scan_event(ab, skb); 6481 break; 6482 case WMI_PEER_STA_KICKOUT_EVENTID: 6483 ath11k_peer_sta_kickout_event(ab, skb); 6484 break; 6485 case WMI_ROAM_EVENTID: 6486 ath11k_roam_event(ab, skb); 6487 break; 6488 case WMI_CHAN_INFO_EVENTID: 6489 ath11k_chan_info_event(ab, skb); 6490 break; 6491 case WMI_PDEV_BSS_CHAN_INFO_EVENTID: 6492 ath11k_pdev_bss_chan_info_event(ab, skb); 6493 break; 6494 case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID: 6495 ath11k_vdev_install_key_compl_event(ab, skb); 6496 break; 6497 case WMI_SERVICE_AVAILABLE_EVENTID: 6498 ath11k_service_available_event(ab, skb); 6499 break; 6500 case WMI_PEER_ASSOC_CONF_EVENTID: 6501 ath11k_peer_assoc_conf_event(ab, skb); 6502 break; 6503 case WMI_UPDATE_STATS_EVENTID: 6504 ath11k_update_stats_event(ab, skb); 6505 break; 6506 case WMI_PDEV_CTL_FAILSAFE_CHECK_EVENTID: 6507 ath11k_pdev_ctl_failsafe_check_event(ab, skb); 6508 break; 6509 case WMI_PDEV_CSA_SWITCH_COUNT_STATUS_EVENTID: 6510 ath11k_wmi_pdev_csa_switch_count_status_event(ab, skb); 6511 break; 6512 case WMI_PDEV_TEMPERATURE_EVENTID: 6513 ath11k_wmi_pdev_temperature_event(ab, skb); 6514 break; 6515 case WMI_PDEV_DMA_RING_BUF_RELEASE_EVENTID: 6516 ath11k_wmi_pdev_dma_ring_buf_release_event(ab, skb); 6517 break; 6518 /* add Unsupported events here */ 6519 case WMI_TBTTOFFSET_EXT_UPDATE_EVENTID: 6520 case WMI_VDEV_DELETE_RESP_EVENTID: 6521 case WMI_PEER_OPER_MODE_CHANGE_EVENTID: 6522 case WMI_TWT_ENABLE_EVENTID: 6523 case WMI_TWT_DISABLE_EVENTID: 6524 case WMI_PDEV_DMA_RING_CFG_RSP_EVENTID: 6525 ath11k_dbg(ab, ATH11K_DBG_WMI, 6526 "ignoring unsupported event 0x%x\n", id); 6527 break; 6528 case WMI_PDEV_DFS_RADAR_DETECTION_EVENTID: 6529 ath11k_wmi_pdev_dfs_radar_detected_event(ab, skb); 6530 break; 6531 /* TODO: Add remaining events */ 6532 default: 6533 ath11k_warn(ab, "Unknown eventid: 0x%x\n", id); 6534 break; 6535 } 6536 6537 out: 6538 dev_kfree_skb(skb); 6539 } 6540 6541 static int ath11k_connect_pdev_htc_service(struct ath11k_base *ab, 6542 u32 pdev_idx) 6543 { 6544 int status; 6545 u32 svc_id[] = { ATH11K_HTC_SVC_ID_WMI_CONTROL, 6546 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1, 6547 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 }; 6548 6549 struct ath11k_htc_svc_conn_req conn_req; 6550 struct ath11k_htc_svc_conn_resp conn_resp; 6551 6552 memset(&conn_req, 0, sizeof(conn_req)); 6553 memset(&conn_resp, 0, sizeof(conn_resp)); 6554 6555 /* these fields are the same for all service endpoints */ 6556 conn_req.ep_ops.ep_tx_complete = ath11k_wmi_htc_tx_complete; 6557 conn_req.ep_ops.ep_rx_complete = ath11k_wmi_tlv_op_rx; 6558 conn_req.ep_ops.ep_tx_credits = ath11k_wmi_op_ep_tx_credits; 6559 6560 /* connect to control service */ 6561 conn_req.service_id = svc_id[pdev_idx]; 6562 6563 status = ath11k_htc_connect_service(&ab->htc, &conn_req, &conn_resp); 6564 if (status) { 6565 ath11k_warn(ab, "failed to connect to WMI CONTROL service status: %d\n", 6566 status); 6567 return status; 6568 } 6569 6570 ab->wmi_ab.wmi_endpoint_id[pdev_idx] = conn_resp.eid; 6571 ab->wmi_ab.wmi[pdev_idx].eid = conn_resp.eid; 6572 ab->wmi_ab.max_msg_len[pdev_idx] = conn_resp.max_msg_len; 6573 6574 return 0; 6575 } 6576 6577 static int 6578 ath11k_wmi_send_unit_test_cmd(struct ath11k *ar, 6579 struct wmi_unit_test_cmd ut_cmd, 6580 u32 *test_args) 6581 { 6582 struct ath11k_pdev_wmi *wmi = ar->wmi; 6583 struct wmi_unit_test_cmd *cmd; 6584 struct sk_buff *skb; 6585 struct wmi_tlv *tlv; 6586 void *ptr; 6587 u32 *ut_cmd_args; 6588 int buf_len, arg_len; 6589 int ret; 6590 int i; 6591 6592 arg_len = sizeof(u32) * ut_cmd.num_args; 6593 buf_len = sizeof(ut_cmd) + arg_len + TLV_HDR_SIZE; 6594 6595 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, buf_len); 6596 if (!skb) 6597 return -ENOMEM; 6598 6599 cmd = (struct wmi_unit_test_cmd *)skb->data; 6600 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_UNIT_TEST_CMD) | 6601 FIELD_PREP(WMI_TLV_LEN, sizeof(ut_cmd) - TLV_HDR_SIZE); 6602 6603 cmd->vdev_id = ut_cmd.vdev_id; 6604 cmd->module_id = ut_cmd.module_id; 6605 cmd->num_args = ut_cmd.num_args; 6606 cmd->diag_token = ut_cmd.diag_token; 6607 6608 ptr = skb->data + sizeof(ut_cmd); 6609 6610 tlv = ptr; 6611 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) | 6612 FIELD_PREP(WMI_TLV_LEN, arg_len); 6613 6614 ptr += TLV_HDR_SIZE; 6615 6616 ut_cmd_args = ptr; 6617 for (i = 0; i < ut_cmd.num_args; i++) 6618 ut_cmd_args[i] = test_args[i]; 6619 6620 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_UNIT_TEST_CMDID); 6621 6622 if (ret) { 6623 ath11k_warn(ar->ab, "failed to send WMI_UNIT_TEST CMD :%d\n", 6624 ret); 6625 dev_kfree_skb(skb); 6626 } 6627 6628 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 6629 "WMI unit test : module %d vdev %d n_args %d token %d\n", 6630 cmd->module_id, cmd->vdev_id, cmd->num_args, 6631 cmd->diag_token); 6632 6633 return ret; 6634 } 6635 6636 int ath11k_wmi_simulate_radar(struct ath11k *ar) 6637 { 6638 struct ath11k_vif *arvif; 6639 u32 dfs_args[DFS_MAX_TEST_ARGS]; 6640 struct wmi_unit_test_cmd wmi_ut; 6641 bool arvif_found = false; 6642 6643 list_for_each_entry(arvif, &ar->arvifs, list) { 6644 if (arvif->is_started && arvif->vdev_type == WMI_VDEV_TYPE_AP) { 6645 arvif_found = true; 6646 break; 6647 } 6648 } 6649 6650 if (!arvif_found) 6651 return -EINVAL; 6652 6653 dfs_args[DFS_TEST_CMDID] = 0; 6654 dfs_args[DFS_TEST_PDEV_ID] = ar->pdev->pdev_id; 6655 /* Currently we could pass segment_id(b0 - b1), chirp(b2) 6656 * freq offset (b3 - b10) to unit test. For simulation 6657 * purpose this can be set to 0 which is valid. 6658 */ 6659 dfs_args[DFS_TEST_RADAR_PARAM] = 0; 6660 6661 wmi_ut.vdev_id = arvif->vdev_id; 6662 wmi_ut.module_id = DFS_UNIT_TEST_MODULE; 6663 wmi_ut.num_args = DFS_MAX_TEST_ARGS; 6664 wmi_ut.diag_token = DFS_UNIT_TEST_TOKEN; 6665 6666 ath11k_dbg(ar->ab, ATH11K_DBG_REG, "Triggering Radar Simulation\n"); 6667 6668 return ath11k_wmi_send_unit_test_cmd(ar, wmi_ut, dfs_args); 6669 } 6670 6671 int ath11k_wmi_connect(struct ath11k_base *ab) 6672 { 6673 u32 i; 6674 u8 wmi_ep_count; 6675 6676 wmi_ep_count = ab->htc.wmi_ep_count; 6677 if (wmi_ep_count > ab->hw_params.max_radios) 6678 return -1; 6679 6680 for (i = 0; i < wmi_ep_count; i++) 6681 ath11k_connect_pdev_htc_service(ab, i); 6682 6683 return 0; 6684 } 6685 6686 static void ath11k_wmi_pdev_detach(struct ath11k_base *ab, u8 pdev_id) 6687 { 6688 if (WARN_ON(pdev_id >= MAX_RADIOS)) 6689 return; 6690 6691 /* TODO: Deinit any pdev specific wmi resource */ 6692 } 6693 6694 int ath11k_wmi_pdev_attach(struct ath11k_base *ab, 6695 u8 pdev_id) 6696 { 6697 struct ath11k_pdev_wmi *wmi_handle; 6698 6699 if (pdev_id >= ab->hw_params.max_radios) 6700 return -EINVAL; 6701 6702 wmi_handle = &ab->wmi_ab.wmi[pdev_id]; 6703 6704 wmi_handle->wmi_ab = &ab->wmi_ab; 6705 6706 ab->wmi_ab.ab = ab; 6707 /* TODO: Init remaining resource specific to pdev */ 6708 6709 return 0; 6710 } 6711 6712 int ath11k_wmi_attach(struct ath11k_base *ab) 6713 { 6714 int ret; 6715 6716 ret = ath11k_wmi_pdev_attach(ab, 0); 6717 if (ret) 6718 return ret; 6719 6720 ab->wmi_ab.ab = ab; 6721 ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_MAX; 6722 6723 /* It's overwritten when service_ext_ready is handled */ 6724 if (ab->hw_params.single_pdev_only) 6725 ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_SINGLE; 6726 6727 /* TODO: Init remaining wmi soc resources required */ 6728 init_completion(&ab->wmi_ab.service_ready); 6729 init_completion(&ab->wmi_ab.unified_ready); 6730 6731 return 0; 6732 } 6733 6734 void ath11k_wmi_detach(struct ath11k_base *ab) 6735 { 6736 int i; 6737 6738 /* TODO: Deinit wmi resource specific to SOC as required */ 6739 6740 for (i = 0; i < ab->htc.wmi_ep_count; i++) 6741 ath11k_wmi_pdev_detach(ab, i); 6742 6743 ath11k_wmi_free_dbring_caps(ab); 6744 } 6745