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