linux/drivers/net/wireless/ath/ath10k/wmi-tlv.c
<<
>>
Prefs
   1// SPDX-License-Identifier: ISC
   2/*
   3 * Copyright (c) 2005-2011 Atheros Communications Inc.
   4 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
   5 * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
   6 */
   7#include "core.h"
   8#include "debug.h"
   9#include "mac.h"
  10#include "hw.h"
  11#include "wmi.h"
  12#include "wmi-ops.h"
  13#include "wmi-tlv.h"
  14#include "p2p.h"
  15#include "testmode.h"
  16#include <linux/bitfield.h>
  17
  18/***************/
  19/* TLV helpers */
  20/**************/
  21
  22struct wmi_tlv_policy {
  23        size_t min_len;
  24};
  25
  26static const struct wmi_tlv_policy wmi_tlv_policies[] = {
  27        [WMI_TLV_TAG_ARRAY_BYTE]
  28                = { .min_len = 0 },
  29        [WMI_TLV_TAG_ARRAY_UINT32]
  30                = { .min_len = 0 },
  31        [WMI_TLV_TAG_STRUCT_SCAN_EVENT]
  32                = { .min_len = sizeof(struct wmi_scan_event) },
  33        [WMI_TLV_TAG_STRUCT_MGMT_RX_HDR]
  34                = { .min_len = sizeof(struct wmi_tlv_mgmt_rx_ev) },
  35        [WMI_TLV_TAG_STRUCT_CHAN_INFO_EVENT]
  36                = { .min_len = sizeof(struct wmi_chan_info_event) },
  37        [WMI_TLV_TAG_STRUCT_VDEV_START_RESPONSE_EVENT]
  38                = { .min_len = sizeof(struct wmi_vdev_start_response_event) },
  39        [WMI_TLV_TAG_STRUCT_PEER_STA_KICKOUT_EVENT]
  40                = { .min_len = sizeof(struct wmi_peer_sta_kickout_event) },
  41        [WMI_TLV_TAG_STRUCT_HOST_SWBA_EVENT]
  42                = { .min_len = sizeof(struct wmi_host_swba_event) },
  43        [WMI_TLV_TAG_STRUCT_TIM_INFO]
  44                = { .min_len = sizeof(struct wmi_tim_info) },
  45        [WMI_TLV_TAG_STRUCT_P2P_NOA_INFO]
  46                = { .min_len = sizeof(struct wmi_p2p_noa_info) },
  47        [WMI_TLV_TAG_STRUCT_SERVICE_READY_EVENT]
  48                = { .min_len = sizeof(struct wmi_tlv_svc_rdy_ev) },
  49        [WMI_TLV_TAG_STRUCT_HAL_REG_CAPABILITIES]
  50                = { .min_len = sizeof(struct hal_reg_capabilities) },
  51        [WMI_TLV_TAG_STRUCT_WLAN_HOST_MEM_REQ]
  52                = { .min_len = sizeof(struct wlan_host_mem_req) },
  53        [WMI_TLV_TAG_STRUCT_READY_EVENT]
  54                = { .min_len = sizeof(struct wmi_tlv_rdy_ev) },
  55        [WMI_TLV_TAG_STRUCT_OFFLOAD_BCN_TX_STATUS_EVENT]
  56                = { .min_len = sizeof(struct wmi_tlv_bcn_tx_status_ev) },
  57        [WMI_TLV_TAG_STRUCT_DIAG_DATA_CONTAINER_EVENT]
  58                = { .min_len = sizeof(struct wmi_tlv_diag_data_ev) },
  59        [WMI_TLV_TAG_STRUCT_P2P_NOA_EVENT]
  60                = { .min_len = sizeof(struct wmi_tlv_p2p_noa_ev) },
  61        [WMI_TLV_TAG_STRUCT_ROAM_EVENT]
  62                = { .min_len = sizeof(struct wmi_tlv_roam_ev) },
  63        [WMI_TLV_TAG_STRUCT_WOW_EVENT_INFO]
  64                = { .min_len = sizeof(struct wmi_tlv_wow_event_info) },
  65        [WMI_TLV_TAG_STRUCT_TX_PAUSE_EVENT]
  66                = { .min_len = sizeof(struct wmi_tlv_tx_pause_ev) },
  67};
  68
  69static int
  70ath10k_wmi_tlv_iter(struct ath10k *ar, const void *ptr, size_t len,
  71                    int (*iter)(struct ath10k *ar, u16 tag, u16 len,
  72                                const void *ptr, void *data),
  73                    void *data)
  74{
  75        const void *begin = ptr;
  76        const struct wmi_tlv *tlv;
  77        u16 tlv_tag, tlv_len;
  78        int ret;
  79
  80        while (len > 0) {
  81                if (len < sizeof(*tlv)) {
  82                        ath10k_dbg(ar, ATH10K_DBG_WMI,
  83                                   "wmi tlv parse failure at byte %zd (%zu bytes left, %zu expected)\n",
  84                                   ptr - begin, len, sizeof(*tlv));
  85                        return -EINVAL;
  86                }
  87
  88                tlv = ptr;
  89                tlv_tag = __le16_to_cpu(tlv->tag);
  90                tlv_len = __le16_to_cpu(tlv->len);
  91                ptr += sizeof(*tlv);
  92                len -= sizeof(*tlv);
  93
  94                if (tlv_len > len) {
  95                        ath10k_dbg(ar, ATH10K_DBG_WMI,
  96                                   "wmi tlv parse failure of tag %hhu at byte %zd (%zu bytes left, %hhu expected)\n",
  97                                   tlv_tag, ptr - begin, len, tlv_len);
  98                        return -EINVAL;
  99                }
 100
 101                if (tlv_tag < ARRAY_SIZE(wmi_tlv_policies) &&
 102                    wmi_tlv_policies[tlv_tag].min_len &&
 103                    wmi_tlv_policies[tlv_tag].min_len > tlv_len) {
 104                        ath10k_dbg(ar, ATH10K_DBG_WMI,
 105                                   "wmi tlv parse failure of tag %hhu at byte %zd (%hhu bytes is less than min length %zu)\n",
 106                                   tlv_tag, ptr - begin, tlv_len,
 107                                   wmi_tlv_policies[tlv_tag].min_len);
 108                        return -EINVAL;
 109                }
 110
 111                ret = iter(ar, tlv_tag, tlv_len, ptr, data);
 112                if (ret)
 113                        return ret;
 114
 115                ptr += tlv_len;
 116                len -= tlv_len;
 117        }
 118
 119        return 0;
 120}
 121
 122static int ath10k_wmi_tlv_iter_parse(struct ath10k *ar, u16 tag, u16 len,
 123                                     const void *ptr, void *data)
 124{
 125        const void **tb = data;
 126
 127        if (tag < WMI_TLV_TAG_MAX)
 128                tb[tag] = ptr;
 129
 130        return 0;
 131}
 132
 133static int ath10k_wmi_tlv_parse(struct ath10k *ar, const void **tb,
 134                                const void *ptr, size_t len)
 135{
 136        return ath10k_wmi_tlv_iter(ar, ptr, len, ath10k_wmi_tlv_iter_parse,
 137                                   (void *)tb);
 138}
 139
 140static const void **
 141ath10k_wmi_tlv_parse_alloc(struct ath10k *ar, const void *ptr,
 142                           size_t len, gfp_t gfp)
 143{
 144        const void **tb;
 145        int ret;
 146
 147        tb = kcalloc(WMI_TLV_TAG_MAX, sizeof(*tb), gfp);
 148        if (!tb)
 149                return ERR_PTR(-ENOMEM);
 150
 151        ret = ath10k_wmi_tlv_parse(ar, tb, ptr, len);
 152        if (ret) {
 153                kfree(tb);
 154                return ERR_PTR(ret);
 155        }
 156
 157        return tb;
 158}
 159
 160static u16 ath10k_wmi_tlv_len(const void *ptr)
 161{
 162        return __le16_to_cpu((((const struct wmi_tlv *)ptr) - 1)->len);
 163}
 164
 165/**************/
 166/* TLV events */
 167/**************/
 168static int ath10k_wmi_tlv_event_bcn_tx_status(struct ath10k *ar,
 169                                              struct sk_buff *skb)
 170{
 171        const void **tb;
 172        const struct wmi_tlv_bcn_tx_status_ev *ev;
 173        struct ath10k_vif *arvif;
 174        u32 vdev_id, tx_status;
 175        int ret;
 176
 177        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
 178        if (IS_ERR(tb)) {
 179                ret = PTR_ERR(tb);
 180                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
 181                return ret;
 182        }
 183
 184        ev = tb[WMI_TLV_TAG_STRUCT_OFFLOAD_BCN_TX_STATUS_EVENT];
 185        if (!ev) {
 186                kfree(tb);
 187                return -EPROTO;
 188        }
 189
 190        tx_status = __le32_to_cpu(ev->tx_status);
 191        vdev_id = __le32_to_cpu(ev->vdev_id);
 192
 193        switch (tx_status) {
 194        case WMI_TLV_BCN_TX_STATUS_OK:
 195                break;
 196        case WMI_TLV_BCN_TX_STATUS_XRETRY:
 197        case WMI_TLV_BCN_TX_STATUS_DROP:
 198        case WMI_TLV_BCN_TX_STATUS_FILTERED:
 199                /* FIXME: It's probably worth telling mac80211 to stop the
 200                 * interface as it is crippled.
 201                 */
 202                ath10k_warn(ar, "received bcn tmpl tx status on vdev %i: %d",
 203                            vdev_id, tx_status);
 204                break;
 205        }
 206
 207        arvif = ath10k_get_arvif(ar, vdev_id);
 208        if (arvif && arvif->is_up && arvif->vif->csa_active)
 209                ieee80211_queue_work(ar->hw, &arvif->ap_csa_work);
 210
 211        kfree(tb);
 212        return 0;
 213}
 214
 215static void ath10k_wmi_tlv_event_vdev_delete_resp(struct ath10k *ar,
 216                                                  struct sk_buff *skb)
 217{
 218        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_DELETE_RESP_EVENTID\n");
 219        complete(&ar->vdev_delete_done);
 220}
 221
 222static int ath10k_wmi_tlv_parse_peer_stats_info(struct ath10k *ar, u16 tag, u16 len,
 223                                                const void *ptr, void *data)
 224{
 225        const struct wmi_tlv_peer_stats_info *stat = ptr;
 226        struct ieee80211_sta *sta;
 227        struct ath10k_sta *arsta;
 228
 229        if (tag != WMI_TLV_TAG_STRUCT_PEER_STATS_INFO)
 230                return -EPROTO;
 231
 232        ath10k_dbg(ar, ATH10K_DBG_WMI,
 233                   "wmi tlv stats peer addr %pMF rx rate code 0x%x bit rate %d kbps\n",
 234                   stat->peer_macaddr.addr,
 235                   __le32_to_cpu(stat->last_rx_rate_code),
 236                   __le32_to_cpu(stat->last_rx_bitrate_kbps));
 237
 238        ath10k_dbg(ar, ATH10K_DBG_WMI,
 239                   "wmi tlv stats tx rate code 0x%x bit rate %d kbps\n",
 240                   __le32_to_cpu(stat->last_tx_rate_code),
 241                   __le32_to_cpu(stat->last_tx_bitrate_kbps));
 242
 243        sta = ieee80211_find_sta_by_ifaddr(ar->hw, stat->peer_macaddr.addr, NULL);
 244        if (!sta) {
 245                ath10k_warn(ar, "not found station for peer stats\n");
 246                return -EINVAL;
 247        }
 248
 249        arsta = (struct ath10k_sta *)sta->drv_priv;
 250        arsta->rx_rate_code = __le32_to_cpu(stat->last_rx_rate_code);
 251        arsta->rx_bitrate_kbps = __le32_to_cpu(stat->last_rx_bitrate_kbps);
 252        arsta->tx_rate_code = __le32_to_cpu(stat->last_tx_rate_code);
 253        arsta->tx_bitrate_kbps = __le32_to_cpu(stat->last_tx_bitrate_kbps);
 254
 255        return 0;
 256}
 257
 258static int ath10k_wmi_tlv_op_pull_peer_stats_info(struct ath10k *ar,
 259                                                  struct sk_buff *skb)
 260{
 261        const void **tb;
 262        const struct wmi_tlv_peer_stats_info_ev *ev;
 263        const void *data;
 264        u32 num_peer_stats;
 265        int ret;
 266
 267        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
 268        if (IS_ERR(tb)) {
 269                ret = PTR_ERR(tb);
 270                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
 271                return ret;
 272        }
 273
 274        ev = tb[WMI_TLV_TAG_STRUCT_PEER_STATS_INFO_EVENT];
 275        data = tb[WMI_TLV_TAG_ARRAY_STRUCT];
 276
 277        if (!ev || !data) {
 278                kfree(tb);
 279                return -EPROTO;
 280        }
 281
 282        num_peer_stats = __le32_to_cpu(ev->num_peers);
 283
 284        ath10k_dbg(ar, ATH10K_DBG_WMI,
 285                   "wmi tlv peer stats info update peer vdev id %d peers %i more data %d\n",
 286                   __le32_to_cpu(ev->vdev_id),
 287                   num_peer_stats,
 288                   __le32_to_cpu(ev->more_data));
 289
 290        ret = ath10k_wmi_tlv_iter(ar, data, ath10k_wmi_tlv_len(data),
 291                                  ath10k_wmi_tlv_parse_peer_stats_info, NULL);
 292        if (ret)
 293                ath10k_warn(ar, "failed to parse stats info tlv: %d\n", ret);
 294
 295        kfree(tb);
 296        return 0;
 297}
 298
 299static void ath10k_wmi_tlv_event_peer_stats_info(struct ath10k *ar,
 300                                                 struct sk_buff *skb)
 301{
 302        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PEER_STATS_INFO_EVENTID\n");
 303        ath10k_wmi_tlv_op_pull_peer_stats_info(ar, skb);
 304        complete(&ar->peer_stats_info_complete);
 305}
 306
 307static int ath10k_wmi_tlv_event_diag_data(struct ath10k *ar,
 308                                          struct sk_buff *skb)
 309{
 310        const void **tb;
 311        const struct wmi_tlv_diag_data_ev *ev;
 312        const struct wmi_tlv_diag_item *item;
 313        const void *data;
 314        int ret, num_items, len;
 315
 316        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
 317        if (IS_ERR(tb)) {
 318                ret = PTR_ERR(tb);
 319                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
 320                return ret;
 321        }
 322
 323        ev = tb[WMI_TLV_TAG_STRUCT_DIAG_DATA_CONTAINER_EVENT];
 324        data = tb[WMI_TLV_TAG_ARRAY_BYTE];
 325        if (!ev || !data) {
 326                kfree(tb);
 327                return -EPROTO;
 328        }
 329
 330        num_items = __le32_to_cpu(ev->num_items);
 331        len = ath10k_wmi_tlv_len(data);
 332
 333        while (num_items--) {
 334                if (len == 0)
 335                        break;
 336                if (len < sizeof(*item)) {
 337                        ath10k_warn(ar, "failed to parse diag data: can't fit item header\n");
 338                        break;
 339                }
 340
 341                item = data;
 342
 343                if (len < sizeof(*item) + __le16_to_cpu(item->len)) {
 344                        ath10k_warn(ar, "failed to parse diag data: item is too long\n");
 345                        break;
 346                }
 347
 348                trace_ath10k_wmi_diag_container(ar,
 349                                                item->type,
 350                                                __le32_to_cpu(item->timestamp),
 351                                                __le32_to_cpu(item->code),
 352                                                __le16_to_cpu(item->len),
 353                                                item->payload);
 354
 355                len -= sizeof(*item);
 356                len -= roundup(__le16_to_cpu(item->len), 4);
 357
 358                data += sizeof(*item);
 359                data += roundup(__le16_to_cpu(item->len), 4);
 360        }
 361
 362        if (num_items != -1 || len != 0)
 363                ath10k_warn(ar, "failed to parse diag data event: num_items %d len %d\n",
 364                            num_items, len);
 365
 366        kfree(tb);
 367        return 0;
 368}
 369
 370static int ath10k_wmi_tlv_event_diag(struct ath10k *ar,
 371                                     struct sk_buff *skb)
 372{
 373        const void **tb;
 374        const void *data;
 375        int ret, len;
 376
 377        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
 378        if (IS_ERR(tb)) {
 379                ret = PTR_ERR(tb);
 380                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
 381                return ret;
 382        }
 383
 384        data = tb[WMI_TLV_TAG_ARRAY_BYTE];
 385        if (!data) {
 386                kfree(tb);
 387                return -EPROTO;
 388        }
 389        len = ath10k_wmi_tlv_len(data);
 390
 391        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv diag event len %d\n", len);
 392        trace_ath10k_wmi_diag(ar, data, len);
 393
 394        kfree(tb);
 395        return 0;
 396}
 397
 398static int ath10k_wmi_tlv_event_p2p_noa(struct ath10k *ar,
 399                                        struct sk_buff *skb)
 400{
 401        const void **tb;
 402        const struct wmi_tlv_p2p_noa_ev *ev;
 403        const struct wmi_p2p_noa_info *noa;
 404        int ret, vdev_id;
 405
 406        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
 407        if (IS_ERR(tb)) {
 408                ret = PTR_ERR(tb);
 409                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
 410                return ret;
 411        }
 412
 413        ev = tb[WMI_TLV_TAG_STRUCT_P2P_NOA_EVENT];
 414        noa = tb[WMI_TLV_TAG_STRUCT_P2P_NOA_INFO];
 415
 416        if (!ev || !noa) {
 417                kfree(tb);
 418                return -EPROTO;
 419        }
 420
 421        vdev_id = __le32_to_cpu(ev->vdev_id);
 422
 423        ath10k_dbg(ar, ATH10K_DBG_WMI,
 424                   "wmi tlv p2p noa vdev_id %i descriptors %hhu\n",
 425                   vdev_id, noa->num_descriptors);
 426
 427        ath10k_p2p_noa_update_by_vdev_id(ar, vdev_id, noa);
 428        kfree(tb);
 429        return 0;
 430}
 431
 432static int ath10k_wmi_tlv_event_tx_pause(struct ath10k *ar,
 433                                         struct sk_buff *skb)
 434{
 435        const void **tb;
 436        const struct wmi_tlv_tx_pause_ev *ev;
 437        int ret, vdev_id;
 438        u32 pause_id, action, vdev_map, peer_id, tid_map;
 439
 440        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
 441        if (IS_ERR(tb)) {
 442                ret = PTR_ERR(tb);
 443                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
 444                return ret;
 445        }
 446
 447        ev = tb[WMI_TLV_TAG_STRUCT_TX_PAUSE_EVENT];
 448        if (!ev) {
 449                kfree(tb);
 450                return -EPROTO;
 451        }
 452
 453        pause_id = __le32_to_cpu(ev->pause_id);
 454        action = __le32_to_cpu(ev->action);
 455        vdev_map = __le32_to_cpu(ev->vdev_map);
 456        peer_id = __le32_to_cpu(ev->peer_id);
 457        tid_map = __le32_to_cpu(ev->tid_map);
 458
 459        ath10k_dbg(ar, ATH10K_DBG_WMI,
 460                   "wmi tlv tx pause pause_id %u action %u vdev_map 0x%08x peer_id %u tid_map 0x%08x\n",
 461                   pause_id, action, vdev_map, peer_id, tid_map);
 462
 463        switch (pause_id) {
 464        case WMI_TLV_TX_PAUSE_ID_MCC:
 465        case WMI_TLV_TX_PAUSE_ID_P2P_CLI_NOA:
 466        case WMI_TLV_TX_PAUSE_ID_P2P_GO_PS:
 467        case WMI_TLV_TX_PAUSE_ID_AP_PS:
 468        case WMI_TLV_TX_PAUSE_ID_IBSS_PS:
 469                for (vdev_id = 0; vdev_map; vdev_id++) {
 470                        if (!(vdev_map & BIT(vdev_id)))
 471                                continue;
 472
 473                        vdev_map &= ~BIT(vdev_id);
 474                        ath10k_mac_handle_tx_pause_vdev(ar, vdev_id, pause_id,
 475                                                        action);
 476                }
 477                break;
 478        case WMI_TLV_TX_PAUSE_ID_AP_PEER_PS:
 479        case WMI_TLV_TX_PAUSE_ID_AP_PEER_UAPSD:
 480        case WMI_TLV_TX_PAUSE_ID_STA_ADD_BA:
 481        case WMI_TLV_TX_PAUSE_ID_HOST:
 482                ath10k_dbg(ar, ATH10K_DBG_MAC,
 483                           "mac ignoring unsupported tx pause id %d\n",
 484                           pause_id);
 485                break;
 486        default:
 487                ath10k_dbg(ar, ATH10K_DBG_MAC,
 488                           "mac ignoring unknown tx pause vdev %d\n",
 489                           pause_id);
 490                break;
 491        }
 492
 493        kfree(tb);
 494        return 0;
 495}
 496
 497static void ath10k_wmi_tlv_event_rfkill_state_change(struct ath10k *ar,
 498                                                     struct sk_buff *skb)
 499{
 500        const struct wmi_tlv_rfkill_state_change_ev *ev;
 501        const void **tb;
 502        bool radio;
 503        int ret;
 504
 505        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
 506        if (IS_ERR(tb)) {
 507                ret = PTR_ERR(tb);
 508                ath10k_warn(ar,
 509                            "failed to parse rfkill state change event: %d\n",
 510                            ret);
 511                return;
 512        }
 513
 514        ev = tb[WMI_TLV_TAG_STRUCT_RFKILL_EVENT];
 515        if (!ev) {
 516                kfree(tb);
 517                return;
 518        }
 519
 520        ath10k_dbg(ar, ATH10K_DBG_MAC,
 521                   "wmi tlv rfkill state change gpio %d type %d radio_state %d\n",
 522                   __le32_to_cpu(ev->gpio_pin_num),
 523                   __le32_to_cpu(ev->int_type),
 524                   __le32_to_cpu(ev->radio_state));
 525
 526        radio = (__le32_to_cpu(ev->radio_state) == WMI_TLV_RFKILL_RADIO_STATE_ON);
 527
 528        spin_lock_bh(&ar->data_lock);
 529
 530        if (!radio)
 531                ar->hw_rfkill_on = true;
 532
 533        spin_unlock_bh(&ar->data_lock);
 534
 535        /* notify cfg80211 radio state change */
 536        ath10k_mac_rfkill_enable_radio(ar, radio);
 537        wiphy_rfkill_set_hw_state(ar->hw->wiphy, !radio);
 538}
 539
 540static int ath10k_wmi_tlv_event_temperature(struct ath10k *ar,
 541                                            struct sk_buff *skb)
 542{
 543        const struct wmi_tlv_pdev_temperature_event *ev;
 544
 545        ev = (struct wmi_tlv_pdev_temperature_event *)skb->data;
 546        if (WARN_ON(skb->len < sizeof(*ev)))
 547                return -EPROTO;
 548
 549        ath10k_thermal_event_temperature(ar, __le32_to_cpu(ev->temperature));
 550        return 0;
 551}
 552
 553static void ath10k_wmi_event_tdls_peer(struct ath10k *ar, struct sk_buff *skb)
 554{
 555        struct ieee80211_sta *station;
 556        const struct wmi_tlv_tdls_peer_event *ev;
 557        const void **tb;
 558        struct ath10k_vif *arvif;
 559
 560        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
 561        if (IS_ERR(tb)) {
 562                ath10k_warn(ar, "tdls peer failed to parse tlv");
 563                return;
 564        }
 565        ev = tb[WMI_TLV_TAG_STRUCT_TDLS_PEER_EVENT];
 566        if (!ev) {
 567                kfree(tb);
 568                ath10k_warn(ar, "tdls peer NULL event");
 569                return;
 570        }
 571
 572        switch (__le32_to_cpu(ev->peer_reason)) {
 573        case WMI_TDLS_TEARDOWN_REASON_TX:
 574        case WMI_TDLS_TEARDOWN_REASON_RSSI:
 575        case WMI_TDLS_TEARDOWN_REASON_PTR_TIMEOUT:
 576                station = ieee80211_find_sta_by_ifaddr(ar->hw,
 577                                                       ev->peer_macaddr.addr,
 578                                                       NULL);
 579                if (!station) {
 580                        ath10k_warn(ar, "did not find station from tdls peer event");
 581                        kfree(tb);
 582                        return;
 583                }
 584                arvif = ath10k_get_arvif(ar, __le32_to_cpu(ev->vdev_id));
 585                ieee80211_tdls_oper_request(
 586                                        arvif->vif, station->addr,
 587                                        NL80211_TDLS_TEARDOWN,
 588                                        WLAN_REASON_TDLS_TEARDOWN_UNREACHABLE,
 589                                        GFP_ATOMIC
 590                                        );
 591                break;
 592        }
 593        kfree(tb);
 594}
 595
 596static int ath10k_wmi_tlv_event_peer_delete_resp(struct ath10k *ar,
 597                                                 struct sk_buff *skb)
 598{
 599        struct wmi_peer_delete_resp_ev_arg *arg;
 600        struct wmi_tlv *tlv_hdr;
 601
 602        tlv_hdr = (struct wmi_tlv *)skb->data;
 603        arg = (struct wmi_peer_delete_resp_ev_arg *)tlv_hdr->value;
 604
 605        ath10k_dbg(ar, ATH10K_DBG_WMI, "vdev id %d", arg->vdev_id);
 606        ath10k_dbg(ar, ATH10K_DBG_WMI, "peer mac addr %pM", &arg->peer_addr);
 607        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer delete response\n");
 608
 609        complete(&ar->peer_delete_done);
 610
 611        return 0;
 612}
 613
 614/***********/
 615/* TLV ops */
 616/***********/
 617
 618static void ath10k_wmi_tlv_op_rx(struct ath10k *ar, struct sk_buff *skb)
 619{
 620        struct wmi_cmd_hdr *cmd_hdr;
 621        enum wmi_tlv_event_id id;
 622        bool consumed;
 623
 624        cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
 625        id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
 626
 627        if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
 628                goto out;
 629
 630        trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
 631
 632        consumed = ath10k_tm_event_wmi(ar, id, skb);
 633
 634        /* Ready event must be handled normally also in UTF mode so that we
 635         * know the UTF firmware has booted, others we are just bypass WMI
 636         * events to testmode.
 637         */
 638        if (consumed && id != WMI_TLV_READY_EVENTID) {
 639                ath10k_dbg(ar, ATH10K_DBG_WMI,
 640                           "wmi tlv testmode consumed 0x%x\n", id);
 641                goto out;
 642        }
 643
 644        switch (id) {
 645        case WMI_TLV_MGMT_RX_EVENTID:
 646                ath10k_wmi_event_mgmt_rx(ar, skb);
 647                /* mgmt_rx() owns the skb now! */
 648                return;
 649        case WMI_TLV_SCAN_EVENTID:
 650                ath10k_wmi_event_scan(ar, skb);
 651                break;
 652        case WMI_TLV_CHAN_INFO_EVENTID:
 653                ath10k_wmi_event_chan_info(ar, skb);
 654                break;
 655        case WMI_TLV_ECHO_EVENTID:
 656                ath10k_wmi_event_echo(ar, skb);
 657                break;
 658        case WMI_TLV_DEBUG_MESG_EVENTID:
 659                ath10k_wmi_event_debug_mesg(ar, skb);
 660                break;
 661        case WMI_TLV_UPDATE_STATS_EVENTID:
 662                ath10k_wmi_event_update_stats(ar, skb);
 663                break;
 664        case WMI_TLV_PEER_STATS_INFO_EVENTID:
 665                ath10k_wmi_tlv_event_peer_stats_info(ar, skb);
 666                break;
 667        case WMI_TLV_VDEV_START_RESP_EVENTID:
 668                ath10k_wmi_event_vdev_start_resp(ar, skb);
 669                break;
 670        case WMI_TLV_VDEV_STOPPED_EVENTID:
 671                ath10k_wmi_event_vdev_stopped(ar, skb);
 672                break;
 673        case WMI_TLV_VDEV_DELETE_RESP_EVENTID:
 674                ath10k_wmi_tlv_event_vdev_delete_resp(ar, skb);
 675                break;
 676        case WMI_TLV_PEER_STA_KICKOUT_EVENTID:
 677                ath10k_wmi_event_peer_sta_kickout(ar, skb);
 678                break;
 679        case WMI_TLV_HOST_SWBA_EVENTID:
 680                ath10k_wmi_event_host_swba(ar, skb);
 681                break;
 682        case WMI_TLV_TBTTOFFSET_UPDATE_EVENTID:
 683                ath10k_wmi_event_tbttoffset_update(ar, skb);
 684                break;
 685        case WMI_TLV_PHYERR_EVENTID:
 686                ath10k_wmi_event_phyerr(ar, skb);
 687                break;
 688        case WMI_TLV_ROAM_EVENTID:
 689                ath10k_wmi_event_roam(ar, skb);
 690                break;
 691        case WMI_TLV_PROFILE_MATCH:
 692                ath10k_wmi_event_profile_match(ar, skb);
 693                break;
 694        case WMI_TLV_DEBUG_PRINT_EVENTID:
 695                ath10k_wmi_event_debug_print(ar, skb);
 696                break;
 697        case WMI_TLV_PDEV_QVIT_EVENTID:
 698                ath10k_wmi_event_pdev_qvit(ar, skb);
 699                break;
 700        case WMI_TLV_WLAN_PROFILE_DATA_EVENTID:
 701                ath10k_wmi_event_wlan_profile_data(ar, skb);
 702                break;
 703        case WMI_TLV_RTT_MEASUREMENT_REPORT_EVENTID:
 704                ath10k_wmi_event_rtt_measurement_report(ar, skb);
 705                break;
 706        case WMI_TLV_TSF_MEASUREMENT_REPORT_EVENTID:
 707                ath10k_wmi_event_tsf_measurement_report(ar, skb);
 708                break;
 709        case WMI_TLV_RTT_ERROR_REPORT_EVENTID:
 710                ath10k_wmi_event_rtt_error_report(ar, skb);
 711                break;
 712        case WMI_TLV_WOW_WAKEUP_HOST_EVENTID:
 713                ath10k_wmi_event_wow_wakeup_host(ar, skb);
 714                break;
 715        case WMI_TLV_DCS_INTERFERENCE_EVENTID:
 716                ath10k_wmi_event_dcs_interference(ar, skb);
 717                break;
 718        case WMI_TLV_PDEV_TPC_CONFIG_EVENTID:
 719                ath10k_wmi_event_pdev_tpc_config(ar, skb);
 720                break;
 721        case WMI_TLV_PDEV_FTM_INTG_EVENTID:
 722                ath10k_wmi_event_pdev_ftm_intg(ar, skb);
 723                break;
 724        case WMI_TLV_GTK_OFFLOAD_STATUS_EVENTID:
 725                ath10k_wmi_event_gtk_offload_status(ar, skb);
 726                break;
 727        case WMI_TLV_GTK_REKEY_FAIL_EVENTID:
 728                ath10k_wmi_event_gtk_rekey_fail(ar, skb);
 729                break;
 730        case WMI_TLV_TX_DELBA_COMPLETE_EVENTID:
 731                ath10k_wmi_event_delba_complete(ar, skb);
 732                break;
 733        case WMI_TLV_TX_ADDBA_COMPLETE_EVENTID:
 734                ath10k_wmi_event_addba_complete(ar, skb);
 735                break;
 736        case WMI_TLV_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
 737                ath10k_wmi_event_vdev_install_key_complete(ar, skb);
 738                break;
 739        case WMI_TLV_SERVICE_READY_EVENTID:
 740                ath10k_wmi_event_service_ready(ar, skb);
 741                return;
 742        case WMI_TLV_READY_EVENTID:
 743                ath10k_wmi_event_ready(ar, skb);
 744                break;
 745        case WMI_TLV_SERVICE_AVAILABLE_EVENTID:
 746                ath10k_wmi_event_service_available(ar, skb);
 747                break;
 748        case WMI_TLV_OFFLOAD_BCN_TX_STATUS_EVENTID:
 749                ath10k_wmi_tlv_event_bcn_tx_status(ar, skb);
 750                break;
 751        case WMI_TLV_DIAG_DATA_CONTAINER_EVENTID:
 752                ath10k_wmi_tlv_event_diag_data(ar, skb);
 753                break;
 754        case WMI_TLV_DIAG_EVENTID:
 755                ath10k_wmi_tlv_event_diag(ar, skb);
 756                break;
 757        case WMI_TLV_P2P_NOA_EVENTID:
 758                ath10k_wmi_tlv_event_p2p_noa(ar, skb);
 759                break;
 760        case WMI_TLV_TX_PAUSE_EVENTID:
 761                ath10k_wmi_tlv_event_tx_pause(ar, skb);
 762                break;
 763        case WMI_TLV_RFKILL_STATE_CHANGE_EVENTID:
 764                ath10k_wmi_tlv_event_rfkill_state_change(ar, skb);
 765                break;
 766        case WMI_TLV_PDEV_TEMPERATURE_EVENTID:
 767                ath10k_wmi_tlv_event_temperature(ar, skb);
 768                break;
 769        case WMI_TLV_TDLS_PEER_EVENTID:
 770                ath10k_wmi_event_tdls_peer(ar, skb);
 771                break;
 772        case WMI_TLV_PEER_DELETE_RESP_EVENTID:
 773                ath10k_wmi_tlv_event_peer_delete_resp(ar, skb);
 774                break;
 775        case WMI_TLV_MGMT_TX_COMPLETION_EVENTID:
 776                ath10k_wmi_event_mgmt_tx_compl(ar, skb);
 777                break;
 778        case WMI_TLV_MGMT_TX_BUNDLE_COMPLETION_EVENTID:
 779                ath10k_wmi_event_mgmt_tx_bundle_compl(ar, skb);
 780                break;
 781        default:
 782                ath10k_dbg(ar, ATH10K_DBG_WMI, "Unknown eventid: %d\n", id);
 783                break;
 784        }
 785
 786out:
 787        dev_kfree_skb(skb);
 788}
 789
 790static int ath10k_wmi_tlv_op_pull_scan_ev(struct ath10k *ar,
 791                                          struct sk_buff *skb,
 792                                          struct wmi_scan_ev_arg *arg)
 793{
 794        const void **tb;
 795        const struct wmi_scan_event *ev;
 796        int ret;
 797
 798        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
 799        if (IS_ERR(tb)) {
 800                ret = PTR_ERR(tb);
 801                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
 802                return ret;
 803        }
 804
 805        ev = tb[WMI_TLV_TAG_STRUCT_SCAN_EVENT];
 806        if (!ev) {
 807                kfree(tb);
 808                return -EPROTO;
 809        }
 810
 811        arg->event_type = ev->event_type;
 812        arg->reason = ev->reason;
 813        arg->channel_freq = ev->channel_freq;
 814        arg->scan_req_id = ev->scan_req_id;
 815        arg->scan_id = ev->scan_id;
 816        arg->vdev_id = ev->vdev_id;
 817
 818        kfree(tb);
 819        return 0;
 820}
 821
 822static int
 823ath10k_wmi_tlv_op_pull_mgmt_tx_compl_ev(struct ath10k *ar, struct sk_buff *skb,
 824                                        struct wmi_tlv_mgmt_tx_compl_ev_arg *arg)
 825{
 826        const void **tb;
 827        const struct wmi_tlv_mgmt_tx_compl_ev *ev;
 828        int ret;
 829
 830        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
 831        if (IS_ERR(tb)) {
 832                ret = PTR_ERR(tb);
 833                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
 834                return ret;
 835        }
 836
 837        ev = tb[WMI_TLV_TAG_STRUCT_MGMT_TX_COMPL_EVENT];
 838
 839        arg->desc_id = ev->desc_id;
 840        arg->status = ev->status;
 841        arg->pdev_id = ev->pdev_id;
 842        arg->ppdu_id = ev->ppdu_id;
 843
 844        if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map))
 845                arg->ack_rssi = ev->ack_rssi;
 846
 847        kfree(tb);
 848        return 0;
 849}
 850
 851struct wmi_tlv_tx_bundle_compl_parse {
 852        const __le32 *num_reports;
 853        const __le32 *desc_ids;
 854        const __le32 *status;
 855        const __le32 *ppdu_ids;
 856        const __le32 *ack_rssi;
 857        bool desc_ids_done;
 858        bool status_done;
 859        bool ppdu_ids_done;
 860        bool ack_rssi_done;
 861};
 862
 863static int
 864ath10k_wmi_tlv_mgmt_tx_bundle_compl_parse(struct ath10k *ar, u16 tag, u16 len,
 865                                          const void *ptr, void *data)
 866{
 867        struct wmi_tlv_tx_bundle_compl_parse *bundle_tx_compl = data;
 868
 869        switch (tag) {
 870        case WMI_TLV_TAG_STRUCT_MGMT_TX_COMPL_BUNDLE_EVENT:
 871                bundle_tx_compl->num_reports = ptr;
 872                break;
 873        case WMI_TLV_TAG_ARRAY_UINT32:
 874                if (!bundle_tx_compl->desc_ids_done) {
 875                        bundle_tx_compl->desc_ids_done = true;
 876                        bundle_tx_compl->desc_ids = ptr;
 877                } else if (!bundle_tx_compl->status_done) {
 878                        bundle_tx_compl->status_done = true;
 879                        bundle_tx_compl->status = ptr;
 880                } else if (!bundle_tx_compl->ppdu_ids_done) {
 881                        bundle_tx_compl->ppdu_ids_done = true;
 882                        bundle_tx_compl->ppdu_ids = ptr;
 883                } else if (!bundle_tx_compl->ack_rssi_done) {
 884                        bundle_tx_compl->ack_rssi_done = true;
 885                        bundle_tx_compl->ack_rssi = ptr;
 886                }
 887                break;
 888        default:
 889                break;
 890        }
 891        return 0;
 892}
 893
 894static int ath10k_wmi_tlv_op_pull_mgmt_tx_bundle_compl_ev(
 895                                struct ath10k *ar, struct sk_buff *skb,
 896                                struct wmi_tlv_mgmt_tx_bundle_compl_ev_arg *arg)
 897{
 898        struct wmi_tlv_tx_bundle_compl_parse bundle_tx_compl = { };
 899        int ret;
 900
 901        ret = ath10k_wmi_tlv_iter(ar, skb->data, skb->len,
 902                                  ath10k_wmi_tlv_mgmt_tx_bundle_compl_parse,
 903                                  &bundle_tx_compl);
 904        if (ret) {
 905                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
 906                return ret;
 907        }
 908
 909        if (!bundle_tx_compl.num_reports || !bundle_tx_compl.desc_ids ||
 910            !bundle_tx_compl.status)
 911                return -EPROTO;
 912
 913        arg->num_reports = *bundle_tx_compl.num_reports;
 914        arg->desc_ids = bundle_tx_compl.desc_ids;
 915        arg->status = bundle_tx_compl.status;
 916        arg->ppdu_ids = bundle_tx_compl.ppdu_ids;
 917
 918        if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map))
 919                arg->ack_rssi = bundle_tx_compl.ack_rssi;
 920
 921        return 0;
 922}
 923
 924static int ath10k_wmi_tlv_op_pull_mgmt_rx_ev(struct ath10k *ar,
 925                                             struct sk_buff *skb,
 926                                             struct wmi_mgmt_rx_ev_arg *arg)
 927{
 928        const void **tb;
 929        const struct wmi_tlv_mgmt_rx_ev *ev;
 930        const u8 *frame;
 931        u32 msdu_len;
 932        int ret, i;
 933
 934        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
 935        if (IS_ERR(tb)) {
 936                ret = PTR_ERR(tb);
 937                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
 938                return ret;
 939        }
 940
 941        ev = tb[WMI_TLV_TAG_STRUCT_MGMT_RX_HDR];
 942        frame = tb[WMI_TLV_TAG_ARRAY_BYTE];
 943
 944        if (!ev || !frame) {
 945                kfree(tb);
 946                return -EPROTO;
 947        }
 948
 949        arg->channel = ev->channel;
 950        arg->buf_len = ev->buf_len;
 951        arg->status = ev->status;
 952        arg->snr = ev->snr;
 953        arg->phy_mode = ev->phy_mode;
 954        arg->rate = ev->rate;
 955
 956        for (i = 0; i < ARRAY_SIZE(ev->rssi); i++)
 957                arg->rssi[i] = ev->rssi[i];
 958
 959        msdu_len = __le32_to_cpu(arg->buf_len);
 960
 961        if (skb->len < (frame - skb->data) + msdu_len) {
 962                kfree(tb);
 963                return -EPROTO;
 964        }
 965
 966        /* shift the sk_buff to point to `frame` */
 967        skb_trim(skb, 0);
 968        skb_put(skb, frame - skb->data);
 969        skb_pull(skb, frame - skb->data);
 970        skb_put(skb, msdu_len);
 971
 972        kfree(tb);
 973        return 0;
 974}
 975
 976static int ath10k_wmi_tlv_op_pull_ch_info_ev(struct ath10k *ar,
 977                                             struct sk_buff *skb,
 978                                             struct wmi_ch_info_ev_arg *arg)
 979{
 980        const void **tb;
 981        const struct wmi_tlv_chan_info_event *ev;
 982        int ret;
 983
 984        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
 985        if (IS_ERR(tb)) {
 986                ret = PTR_ERR(tb);
 987                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
 988                return ret;
 989        }
 990
 991        ev = tb[WMI_TLV_TAG_STRUCT_CHAN_INFO_EVENT];
 992        if (!ev) {
 993                kfree(tb);
 994                return -EPROTO;
 995        }
 996
 997        arg->err_code = ev->err_code;
 998        arg->freq = ev->freq;
 999        arg->cmd_flags = ev->cmd_flags;
1000        arg->noise_floor = ev->noise_floor;
1001        arg->rx_clear_count = ev->rx_clear_count;
1002        arg->cycle_count = ev->cycle_count;
1003        if (test_bit(ATH10K_FW_FEATURE_SINGLE_CHAN_INFO_PER_CHANNEL,
1004                     ar->running_fw->fw_file.fw_features))
1005                arg->mac_clk_mhz = ev->mac_clk_mhz;
1006
1007        kfree(tb);
1008        return 0;
1009}
1010
1011static int
1012ath10k_wmi_tlv_op_pull_vdev_start_ev(struct ath10k *ar, struct sk_buff *skb,
1013                                     struct wmi_vdev_start_ev_arg *arg)
1014{
1015        const void **tb;
1016        const struct wmi_vdev_start_response_event *ev;
1017        int ret;
1018
1019        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1020        if (IS_ERR(tb)) {
1021                ret = PTR_ERR(tb);
1022                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1023                return ret;
1024        }
1025
1026        ev = tb[WMI_TLV_TAG_STRUCT_VDEV_START_RESPONSE_EVENT];
1027        if (!ev) {
1028                kfree(tb);
1029                return -EPROTO;
1030        }
1031
1032        skb_pull(skb, sizeof(*ev));
1033        arg->vdev_id = ev->vdev_id;
1034        arg->req_id = ev->req_id;
1035        arg->resp_type = ev->resp_type;
1036        arg->status = ev->status;
1037
1038        kfree(tb);
1039        return 0;
1040}
1041
1042static int ath10k_wmi_tlv_op_pull_peer_kick_ev(struct ath10k *ar,
1043                                               struct sk_buff *skb,
1044                                               struct wmi_peer_kick_ev_arg *arg)
1045{
1046        const void **tb;
1047        const struct wmi_peer_sta_kickout_event *ev;
1048        int ret;
1049
1050        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1051        if (IS_ERR(tb)) {
1052                ret = PTR_ERR(tb);
1053                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1054                return ret;
1055        }
1056
1057        ev = tb[WMI_TLV_TAG_STRUCT_PEER_STA_KICKOUT_EVENT];
1058        if (!ev) {
1059                kfree(tb);
1060                return -EPROTO;
1061        }
1062
1063        arg->mac_addr = ev->peer_macaddr.addr;
1064
1065        kfree(tb);
1066        return 0;
1067}
1068
1069struct wmi_tlv_swba_parse {
1070        const struct wmi_host_swba_event *ev;
1071        bool tim_done;
1072        bool noa_done;
1073        size_t n_tim;
1074        size_t n_noa;
1075        struct wmi_swba_ev_arg *arg;
1076};
1077
1078static int ath10k_wmi_tlv_swba_tim_parse(struct ath10k *ar, u16 tag, u16 len,
1079                                         const void *ptr, void *data)
1080{
1081        struct wmi_tlv_swba_parse *swba = data;
1082        struct wmi_tim_info_arg *tim_info_arg;
1083        const struct wmi_tim_info *tim_info_ev = ptr;
1084
1085        if (tag != WMI_TLV_TAG_STRUCT_TIM_INFO)
1086                return -EPROTO;
1087
1088        if (swba->n_tim >= ARRAY_SIZE(swba->arg->tim_info))
1089                return -ENOBUFS;
1090
1091        if (__le32_to_cpu(tim_info_ev->tim_len) >
1092             sizeof(tim_info_ev->tim_bitmap)) {
1093                ath10k_warn(ar, "refusing to parse invalid swba structure\n");
1094                return -EPROTO;
1095        }
1096
1097        tim_info_arg = &swba->arg->tim_info[swba->n_tim];
1098        tim_info_arg->tim_len = tim_info_ev->tim_len;
1099        tim_info_arg->tim_mcast = tim_info_ev->tim_mcast;
1100        tim_info_arg->tim_bitmap = tim_info_ev->tim_bitmap;
1101        tim_info_arg->tim_changed = tim_info_ev->tim_changed;
1102        tim_info_arg->tim_num_ps_pending = tim_info_ev->tim_num_ps_pending;
1103
1104        swba->n_tim++;
1105
1106        return 0;
1107}
1108
1109static int ath10k_wmi_tlv_swba_noa_parse(struct ath10k *ar, u16 tag, u16 len,
1110                                         const void *ptr, void *data)
1111{
1112        struct wmi_tlv_swba_parse *swba = data;
1113
1114        if (tag != WMI_TLV_TAG_STRUCT_P2P_NOA_INFO)
1115                return -EPROTO;
1116
1117        if (swba->n_noa >= ARRAY_SIZE(swba->arg->noa_info))
1118                return -ENOBUFS;
1119
1120        swba->arg->noa_info[swba->n_noa++] = ptr;
1121        return 0;
1122}
1123
1124static int ath10k_wmi_tlv_swba_parse(struct ath10k *ar, u16 tag, u16 len,
1125                                     const void *ptr, void *data)
1126{
1127        struct wmi_tlv_swba_parse *swba = data;
1128        int ret;
1129
1130        switch (tag) {
1131        case WMI_TLV_TAG_STRUCT_HOST_SWBA_EVENT:
1132                swba->ev = ptr;
1133                break;
1134        case WMI_TLV_TAG_ARRAY_STRUCT:
1135                if (!swba->tim_done) {
1136                        swba->tim_done = true;
1137                        ret = ath10k_wmi_tlv_iter(ar, ptr, len,
1138                                                  ath10k_wmi_tlv_swba_tim_parse,
1139                                                  swba);
1140                        if (ret)
1141                                return ret;
1142                } else if (!swba->noa_done) {
1143                        swba->noa_done = true;
1144                        ret = ath10k_wmi_tlv_iter(ar, ptr, len,
1145                                                  ath10k_wmi_tlv_swba_noa_parse,
1146                                                  swba);
1147                        if (ret)
1148                                return ret;
1149                }
1150                break;
1151        default:
1152                break;
1153        }
1154        return 0;
1155}
1156
1157static int ath10k_wmi_tlv_op_pull_swba_ev(struct ath10k *ar,
1158                                          struct sk_buff *skb,
1159                                          struct wmi_swba_ev_arg *arg)
1160{
1161        struct wmi_tlv_swba_parse swba = { .arg = arg };
1162        u32 map;
1163        size_t n_vdevs;
1164        int ret;
1165
1166        ret = ath10k_wmi_tlv_iter(ar, skb->data, skb->len,
1167                                  ath10k_wmi_tlv_swba_parse, &swba);
1168        if (ret) {
1169                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1170                return ret;
1171        }
1172
1173        if (!swba.ev)
1174                return -EPROTO;
1175
1176        arg->vdev_map = swba.ev->vdev_map;
1177
1178        for (map = __le32_to_cpu(arg->vdev_map), n_vdevs = 0; map; map >>= 1)
1179                if (map & BIT(0))
1180                        n_vdevs++;
1181
1182        if (n_vdevs != swba.n_tim ||
1183            n_vdevs != swba.n_noa)
1184                return -EPROTO;
1185
1186        return 0;
1187}
1188
1189static int ath10k_wmi_tlv_op_pull_phyerr_ev_hdr(struct ath10k *ar,
1190                                                struct sk_buff *skb,
1191                                                struct wmi_phyerr_hdr_arg *arg)
1192{
1193        const void **tb;
1194        const struct wmi_tlv_phyerr_ev *ev;
1195        const void *phyerrs;
1196        int ret;
1197
1198        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1199        if (IS_ERR(tb)) {
1200                ret = PTR_ERR(tb);
1201                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1202                return ret;
1203        }
1204
1205        ev = tb[WMI_TLV_TAG_STRUCT_COMB_PHYERR_RX_HDR];
1206        phyerrs = tb[WMI_TLV_TAG_ARRAY_BYTE];
1207
1208        if (!ev || !phyerrs) {
1209                kfree(tb);
1210                return -EPROTO;
1211        }
1212
1213        arg->num_phyerrs  = __le32_to_cpu(ev->num_phyerrs);
1214        arg->tsf_l32 = __le32_to_cpu(ev->tsf_l32);
1215        arg->tsf_u32 = __le32_to_cpu(ev->tsf_u32);
1216        arg->buf_len = __le32_to_cpu(ev->buf_len);
1217        arg->phyerrs = phyerrs;
1218
1219        kfree(tb);
1220        return 0;
1221}
1222
1223#define WMI_TLV_ABI_VER_NS0 0x5F414351
1224#define WMI_TLV_ABI_VER_NS1 0x00004C4D
1225#define WMI_TLV_ABI_VER_NS2 0x00000000
1226#define WMI_TLV_ABI_VER_NS3 0x00000000
1227
1228#define WMI_TLV_ABI_VER0_MAJOR 1
1229#define WMI_TLV_ABI_VER0_MINOR 0
1230#define WMI_TLV_ABI_VER0 ((((WMI_TLV_ABI_VER0_MAJOR) << 24) & 0xFF000000) | \
1231                          (((WMI_TLV_ABI_VER0_MINOR) <<  0) & 0x00FFFFFF))
1232#define WMI_TLV_ABI_VER1 53
1233
1234static int
1235ath10k_wmi_tlv_parse_mem_reqs(struct ath10k *ar, u16 tag, u16 len,
1236                              const void *ptr, void *data)
1237{
1238        struct wmi_svc_rdy_ev_arg *arg = data;
1239        int i;
1240
1241        if (tag != WMI_TLV_TAG_STRUCT_WLAN_HOST_MEM_REQ)
1242                return -EPROTO;
1243
1244        for (i = 0; i < ARRAY_SIZE(arg->mem_reqs); i++) {
1245                if (!arg->mem_reqs[i]) {
1246                        arg->mem_reqs[i] = ptr;
1247                        return 0;
1248                }
1249        }
1250
1251        return -ENOMEM;
1252}
1253
1254struct wmi_tlv_svc_rdy_parse {
1255        const struct hal_reg_capabilities *reg;
1256        const struct wmi_tlv_svc_rdy_ev *ev;
1257        const __le32 *svc_bmap;
1258        const struct wlan_host_mem_req *mem_reqs;
1259        bool svc_bmap_done;
1260        bool dbs_hw_mode_done;
1261};
1262
1263static int ath10k_wmi_tlv_svc_rdy_parse(struct ath10k *ar, u16 tag, u16 len,
1264                                        const void *ptr, void *data)
1265{
1266        struct wmi_tlv_svc_rdy_parse *svc_rdy = data;
1267
1268        switch (tag) {
1269        case WMI_TLV_TAG_STRUCT_SERVICE_READY_EVENT:
1270                svc_rdy->ev = ptr;
1271                break;
1272        case WMI_TLV_TAG_STRUCT_HAL_REG_CAPABILITIES:
1273                svc_rdy->reg = ptr;
1274                break;
1275        case WMI_TLV_TAG_ARRAY_STRUCT:
1276                svc_rdy->mem_reqs = ptr;
1277                break;
1278        case WMI_TLV_TAG_ARRAY_UINT32:
1279                if (!svc_rdy->svc_bmap_done) {
1280                        svc_rdy->svc_bmap_done = true;
1281                        svc_rdy->svc_bmap = ptr;
1282                } else if (!svc_rdy->dbs_hw_mode_done) {
1283                        svc_rdy->dbs_hw_mode_done = true;
1284                }
1285                break;
1286        default:
1287                break;
1288        }
1289        return 0;
1290}
1291
1292static int ath10k_wmi_tlv_op_pull_svc_rdy_ev(struct ath10k *ar,
1293                                             struct sk_buff *skb,
1294                                             struct wmi_svc_rdy_ev_arg *arg)
1295{
1296        const struct hal_reg_capabilities *reg;
1297        const struct wmi_tlv_svc_rdy_ev *ev;
1298        const __le32 *svc_bmap;
1299        const struct wlan_host_mem_req *mem_reqs;
1300        struct wmi_tlv_svc_rdy_parse svc_rdy = { };
1301        int ret;
1302
1303        ret = ath10k_wmi_tlv_iter(ar, skb->data, skb->len,
1304                                  ath10k_wmi_tlv_svc_rdy_parse, &svc_rdy);
1305        if (ret) {
1306                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1307                return ret;
1308        }
1309
1310        ev = svc_rdy.ev;
1311        reg = svc_rdy.reg;
1312        svc_bmap = svc_rdy.svc_bmap;
1313        mem_reqs = svc_rdy.mem_reqs;
1314
1315        if (!ev || !reg || !svc_bmap || !mem_reqs)
1316                return -EPROTO;
1317
1318        /* This is an internal ABI compatibility check for WMI TLV so check it
1319         * here instead of the generic WMI code.
1320         */
1321        ath10k_dbg(ar, ATH10K_DBG_WMI,
1322                   "wmi tlv abi 0x%08x ?= 0x%08x, 0x%08x ?= 0x%08x, 0x%08x ?= 0x%08x, 0x%08x ?= 0x%08x, 0x%08x ?= 0x%08x\n",
1323                   __le32_to_cpu(ev->abi.abi_ver0), WMI_TLV_ABI_VER0,
1324                   __le32_to_cpu(ev->abi.abi_ver_ns0), WMI_TLV_ABI_VER_NS0,
1325                   __le32_to_cpu(ev->abi.abi_ver_ns1), WMI_TLV_ABI_VER_NS1,
1326                   __le32_to_cpu(ev->abi.abi_ver_ns2), WMI_TLV_ABI_VER_NS2,
1327                   __le32_to_cpu(ev->abi.abi_ver_ns3), WMI_TLV_ABI_VER_NS3);
1328
1329        if (__le32_to_cpu(ev->abi.abi_ver0) != WMI_TLV_ABI_VER0 ||
1330            __le32_to_cpu(ev->abi.abi_ver_ns0) != WMI_TLV_ABI_VER_NS0 ||
1331            __le32_to_cpu(ev->abi.abi_ver_ns1) != WMI_TLV_ABI_VER_NS1 ||
1332            __le32_to_cpu(ev->abi.abi_ver_ns2) != WMI_TLV_ABI_VER_NS2 ||
1333            __le32_to_cpu(ev->abi.abi_ver_ns3) != WMI_TLV_ABI_VER_NS3) {
1334                return -ENOTSUPP;
1335        }
1336
1337        arg->min_tx_power = ev->hw_min_tx_power;
1338        arg->max_tx_power = ev->hw_max_tx_power;
1339        arg->ht_cap = ev->ht_cap_info;
1340        arg->vht_cap = ev->vht_cap_info;
1341        arg->vht_supp_mcs = ev->vht_supp_mcs;
1342        arg->sw_ver0 = ev->abi.abi_ver0;
1343        arg->sw_ver1 = ev->abi.abi_ver1;
1344        arg->fw_build = ev->fw_build_vers;
1345        arg->phy_capab = ev->phy_capability;
1346        arg->num_rf_chains = ev->num_rf_chains;
1347        arg->eeprom_rd = reg->eeprom_rd;
1348        arg->low_2ghz_chan = reg->low_2ghz_chan;
1349        arg->high_2ghz_chan = reg->high_2ghz_chan;
1350        arg->low_5ghz_chan = reg->low_5ghz_chan;
1351        arg->high_5ghz_chan = reg->high_5ghz_chan;
1352        arg->num_mem_reqs = ev->num_mem_reqs;
1353        arg->service_map = svc_bmap;
1354        arg->service_map_len = ath10k_wmi_tlv_len(svc_bmap);
1355        arg->sys_cap_info = ev->sys_cap_info;
1356
1357        ret = ath10k_wmi_tlv_iter(ar, mem_reqs, ath10k_wmi_tlv_len(mem_reqs),
1358                                  ath10k_wmi_tlv_parse_mem_reqs, arg);
1359        if (ret) {
1360                ath10k_warn(ar, "failed to parse mem_reqs tlv: %d\n", ret);
1361                return ret;
1362        }
1363
1364        return 0;
1365}
1366
1367static int ath10k_wmi_tlv_op_pull_rdy_ev(struct ath10k *ar,
1368                                         struct sk_buff *skb,
1369                                         struct wmi_rdy_ev_arg *arg)
1370{
1371        const void **tb;
1372        const struct wmi_tlv_rdy_ev *ev;
1373        int ret;
1374
1375        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1376        if (IS_ERR(tb)) {
1377                ret = PTR_ERR(tb);
1378                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1379                return ret;
1380        }
1381
1382        ev = tb[WMI_TLV_TAG_STRUCT_READY_EVENT];
1383        if (!ev) {
1384                kfree(tb);
1385                return -EPROTO;
1386        }
1387
1388        arg->sw_version = ev->abi.abi_ver0;
1389        arg->abi_version = ev->abi.abi_ver1;
1390        arg->status = ev->status;
1391        arg->mac_addr = ev->mac_addr.addr;
1392
1393        kfree(tb);
1394        return 0;
1395}
1396
1397static int ath10k_wmi_tlv_svc_avail_parse(struct ath10k *ar, u16 tag, u16 len,
1398                                          const void *ptr, void *data)
1399{
1400        struct wmi_svc_avail_ev_arg *arg = data;
1401
1402        switch (tag) {
1403        case WMI_TLV_TAG_STRUCT_SERVICE_AVAILABLE_EVENT:
1404                arg->service_map_ext_len = *(__le32 *)ptr;
1405                arg->service_map_ext = ptr + sizeof(__le32);
1406                return 0;
1407        default:
1408                break;
1409        }
1410        return -EPROTO;
1411}
1412
1413static int ath10k_wmi_tlv_op_pull_svc_avail(struct ath10k *ar,
1414                                            struct sk_buff *skb,
1415                                            struct wmi_svc_avail_ev_arg *arg)
1416{
1417        int ret;
1418
1419        ret = ath10k_wmi_tlv_iter(ar, skb->data, skb->len,
1420                                  ath10k_wmi_tlv_svc_avail_parse, arg);
1421
1422        if (ret) {
1423                ath10k_warn(ar, "failed to parse svc_avail tlv: %d\n", ret);
1424                return ret;
1425        }
1426
1427        return 0;
1428}
1429
1430static void ath10k_wmi_tlv_pull_vdev_stats(const struct wmi_tlv_vdev_stats *src,
1431                                           struct ath10k_fw_stats_vdev *dst)
1432{
1433        int i;
1434
1435        dst->vdev_id = __le32_to_cpu(src->vdev_id);
1436        dst->beacon_snr = __le32_to_cpu(src->beacon_snr);
1437        dst->data_snr = __le32_to_cpu(src->data_snr);
1438        dst->num_rx_frames = __le32_to_cpu(src->num_rx_frames);
1439        dst->num_rts_fail = __le32_to_cpu(src->num_rts_fail);
1440        dst->num_rts_success = __le32_to_cpu(src->num_rts_success);
1441        dst->num_rx_err = __le32_to_cpu(src->num_rx_err);
1442        dst->num_rx_discard = __le32_to_cpu(src->num_rx_discard);
1443        dst->num_tx_not_acked = __le32_to_cpu(src->num_tx_not_acked);
1444
1445        for (i = 0; i < ARRAY_SIZE(src->num_tx_frames); i++)
1446                dst->num_tx_frames[i] =
1447                        __le32_to_cpu(src->num_tx_frames[i]);
1448
1449        for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_retries); i++)
1450                dst->num_tx_frames_retries[i] =
1451                        __le32_to_cpu(src->num_tx_frames_retries[i]);
1452
1453        for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_failures); i++)
1454                dst->num_tx_frames_failures[i] =
1455                        __le32_to_cpu(src->num_tx_frames_failures[i]);
1456
1457        for (i = 0; i < ARRAY_SIZE(src->tx_rate_history); i++)
1458                dst->tx_rate_history[i] =
1459                        __le32_to_cpu(src->tx_rate_history[i]);
1460
1461        for (i = 0; i < ARRAY_SIZE(src->beacon_rssi_history); i++)
1462                dst->beacon_rssi_history[i] =
1463                        __le32_to_cpu(src->beacon_rssi_history[i]);
1464}
1465
1466static int ath10k_wmi_tlv_op_pull_fw_stats(struct ath10k *ar,
1467                                           struct sk_buff *skb,
1468                                           struct ath10k_fw_stats *stats)
1469{
1470        const void **tb;
1471        const struct wmi_tlv_stats_ev *ev;
1472        u32 num_peer_stats_extd;
1473        const void *data;
1474        u32 num_pdev_stats;
1475        u32 num_vdev_stats;
1476        u32 num_peer_stats;
1477        u32 num_bcnflt_stats;
1478        u32 num_chan_stats;
1479        size_t data_len;
1480        u32 stats_id;
1481        int ret;
1482        int i;
1483
1484        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1485        if (IS_ERR(tb)) {
1486                ret = PTR_ERR(tb);
1487                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1488                return ret;
1489        }
1490
1491        ev = tb[WMI_TLV_TAG_STRUCT_STATS_EVENT];
1492        data = tb[WMI_TLV_TAG_ARRAY_BYTE];
1493
1494        if (!ev || !data) {
1495                kfree(tb);
1496                return -EPROTO;
1497        }
1498
1499        data_len = ath10k_wmi_tlv_len(data);
1500        num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
1501        num_vdev_stats = __le32_to_cpu(ev->num_vdev_stats);
1502        num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
1503        num_bcnflt_stats = __le32_to_cpu(ev->num_bcnflt_stats);
1504        num_chan_stats = __le32_to_cpu(ev->num_chan_stats);
1505        stats_id = __le32_to_cpu(ev->stats_id);
1506        num_peer_stats_extd = __le32_to_cpu(ev->num_peer_stats_extd);
1507
1508        ath10k_dbg(ar, ATH10K_DBG_WMI,
1509                   "wmi tlv stats update pdev %i vdev %i peer %i bcnflt %i chan %i peer_extd %i\n",
1510                   num_pdev_stats, num_vdev_stats, num_peer_stats,
1511                   num_bcnflt_stats, num_chan_stats, num_peer_stats_extd);
1512
1513        for (i = 0; i < num_pdev_stats; i++) {
1514                const struct wmi_pdev_stats *src;
1515                struct ath10k_fw_stats_pdev *dst;
1516
1517                src = data;
1518                if (data_len < sizeof(*src)) {
1519                        kfree(tb);
1520                        return -EPROTO;
1521                }
1522
1523                data += sizeof(*src);
1524                data_len -= sizeof(*src);
1525
1526                dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
1527                if (!dst)
1528                        continue;
1529
1530                ath10k_wmi_pull_pdev_stats_base(&src->base, dst);
1531                ath10k_wmi_pull_pdev_stats_tx(&src->tx, dst);
1532                ath10k_wmi_pull_pdev_stats_rx(&src->rx, dst);
1533                list_add_tail(&dst->list, &stats->pdevs);
1534        }
1535
1536        for (i = 0; i < num_vdev_stats; i++) {
1537                const struct wmi_tlv_vdev_stats *src;
1538                struct ath10k_fw_stats_vdev *dst;
1539
1540                src = data;
1541                if (data_len < sizeof(*src)) {
1542                        kfree(tb);
1543                        return -EPROTO;
1544                }
1545
1546                data += sizeof(*src);
1547                data_len -= sizeof(*src);
1548
1549                dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
1550                if (!dst)
1551                        continue;
1552
1553                ath10k_wmi_tlv_pull_vdev_stats(src, dst);
1554                list_add_tail(&dst->list, &stats->vdevs);
1555        }
1556
1557        for (i = 0; i < num_peer_stats; i++) {
1558                const struct wmi_10x_peer_stats *src;
1559                struct ath10k_fw_stats_peer *dst;
1560
1561                src = data;
1562                if (data_len < sizeof(*src)) {
1563                        kfree(tb);
1564                        return -EPROTO;
1565                }
1566
1567                data += sizeof(*src);
1568                data_len -= sizeof(*src);
1569
1570                dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
1571                if (!dst)
1572                        continue;
1573
1574                ath10k_wmi_pull_peer_stats(&src->old, dst);
1575                dst->peer_rx_rate = __le32_to_cpu(src->peer_rx_rate);
1576
1577                if (stats_id & WMI_TLV_STAT_PEER_EXTD) {
1578                        const struct wmi_tlv_peer_stats_extd *extd;
1579                        unsigned long rx_duration_high;
1580
1581                        extd = data + sizeof(*src) * (num_peer_stats - i - 1)
1582                               + sizeof(*extd) * i;
1583
1584                        dst->rx_duration = __le32_to_cpu(extd->rx_duration);
1585                        rx_duration_high = __le32_to_cpu
1586                                                (extd->rx_duration_high);
1587
1588                        if (test_bit(WMI_TLV_PEER_RX_DURATION_HIGH_VALID_BIT,
1589                                     &rx_duration_high)) {
1590                                rx_duration_high =
1591                                        FIELD_GET(WMI_TLV_PEER_RX_DURATION_HIGH_MASK,
1592                                                  rx_duration_high);
1593                                dst->rx_duration |= (u64)rx_duration_high <<
1594                                                    WMI_TLV_PEER_RX_DURATION_SHIFT;
1595                        }
1596                }
1597
1598                list_add_tail(&dst->list, &stats->peers);
1599        }
1600
1601        kfree(tb);
1602        return 0;
1603}
1604
1605static int ath10k_wmi_tlv_op_pull_roam_ev(struct ath10k *ar,
1606                                          struct sk_buff *skb,
1607                                          struct wmi_roam_ev_arg *arg)
1608{
1609        const void **tb;
1610        const struct wmi_tlv_roam_ev *ev;
1611        int ret;
1612
1613        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1614        if (IS_ERR(tb)) {
1615                ret = PTR_ERR(tb);
1616                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1617                return ret;
1618        }
1619
1620        ev = tb[WMI_TLV_TAG_STRUCT_ROAM_EVENT];
1621        if (!ev) {
1622                kfree(tb);
1623                return -EPROTO;
1624        }
1625
1626        arg->vdev_id = ev->vdev_id;
1627        arg->reason = ev->reason;
1628        arg->rssi = ev->rssi;
1629
1630        kfree(tb);
1631        return 0;
1632}
1633
1634static int
1635ath10k_wmi_tlv_op_pull_wow_ev(struct ath10k *ar, struct sk_buff *skb,
1636                              struct wmi_wow_ev_arg *arg)
1637{
1638        const void **tb;
1639        const struct wmi_tlv_wow_event_info *ev;
1640        int ret;
1641
1642        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1643        if (IS_ERR(tb)) {
1644                ret = PTR_ERR(tb);
1645                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1646                return ret;
1647        }
1648
1649        ev = tb[WMI_TLV_TAG_STRUCT_WOW_EVENT_INFO];
1650        if (!ev) {
1651                kfree(tb);
1652                return -EPROTO;
1653        }
1654
1655        arg->vdev_id = __le32_to_cpu(ev->vdev_id);
1656        arg->flag = __le32_to_cpu(ev->flag);
1657        arg->wake_reason = __le32_to_cpu(ev->wake_reason);
1658        arg->data_len = __le32_to_cpu(ev->data_len);
1659
1660        kfree(tb);
1661        return 0;
1662}
1663
1664static int ath10k_wmi_tlv_op_pull_echo_ev(struct ath10k *ar,
1665                                          struct sk_buff *skb,
1666                                          struct wmi_echo_ev_arg *arg)
1667{
1668        const void **tb;
1669        const struct wmi_echo_event *ev;
1670        int ret;
1671
1672        tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1673        if (IS_ERR(tb)) {
1674                ret = PTR_ERR(tb);
1675                ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1676                return ret;
1677        }
1678
1679        ev = tb[WMI_TLV_TAG_STRUCT_ECHO_EVENT];
1680        if (!ev) {
1681                kfree(tb);
1682                return -EPROTO;
1683        }
1684
1685        arg->value = ev->value;
1686
1687        kfree(tb);
1688        return 0;
1689}
1690
1691static struct sk_buff *
1692ath10k_wmi_tlv_op_gen_pdev_suspend(struct ath10k *ar, u32 opt)
1693{
1694        struct wmi_tlv_pdev_suspend *cmd;
1695        struct wmi_tlv *tlv;
1696        struct sk_buff *skb;
1697
1698        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1699        if (!skb)
1700                return ERR_PTR(-ENOMEM);
1701
1702        tlv = (void *)skb->data;
1703        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_SUSPEND_CMD);
1704        tlv->len = __cpu_to_le16(sizeof(*cmd));
1705        cmd = (void *)tlv->value;
1706        cmd->opt = __cpu_to_le32(opt);
1707
1708        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev suspend\n");
1709        return skb;
1710}
1711
1712static struct sk_buff *
1713ath10k_wmi_tlv_op_gen_pdev_resume(struct ath10k *ar)
1714{
1715        struct wmi_tlv_resume_cmd *cmd;
1716        struct wmi_tlv *tlv;
1717        struct sk_buff *skb;
1718
1719        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1720        if (!skb)
1721                return ERR_PTR(-ENOMEM);
1722
1723        tlv = (void *)skb->data;
1724        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_RESUME_CMD);
1725        tlv->len = __cpu_to_le16(sizeof(*cmd));
1726        cmd = (void *)tlv->value;
1727        cmd->reserved = __cpu_to_le32(0);
1728
1729        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev resume\n");
1730        return skb;
1731}
1732
1733static struct sk_buff *
1734ath10k_wmi_tlv_op_gen_pdev_set_rd(struct ath10k *ar,
1735                                  u16 rd, u16 rd2g, u16 rd5g,
1736                                  u16 ctl2g, u16 ctl5g,
1737                                  enum wmi_dfs_region dfs_reg)
1738{
1739        struct wmi_tlv_pdev_set_rd_cmd *cmd;
1740        struct wmi_tlv *tlv;
1741        struct sk_buff *skb;
1742
1743        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1744        if (!skb)
1745                return ERR_PTR(-ENOMEM);
1746
1747        tlv = (void *)skb->data;
1748        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_SET_REGDOMAIN_CMD);
1749        tlv->len = __cpu_to_le16(sizeof(*cmd));
1750        cmd = (void *)tlv->value;
1751        cmd->regd = __cpu_to_le32(rd);
1752        cmd->regd_2ghz = __cpu_to_le32(rd2g);
1753        cmd->regd_5ghz = __cpu_to_le32(rd5g);
1754        cmd->conform_limit_2ghz = __cpu_to_le32(ctl2g);
1755        cmd->conform_limit_5ghz = __cpu_to_le32(ctl5g);
1756
1757        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev set rd\n");
1758        return skb;
1759}
1760
1761static enum wmi_txbf_conf ath10k_wmi_tlv_txbf_conf_scheme(struct ath10k *ar)
1762{
1763        return WMI_TXBF_CONF_AFTER_ASSOC;
1764}
1765
1766static struct sk_buff *
1767ath10k_wmi_tlv_op_gen_pdev_set_param(struct ath10k *ar, u32 param_id,
1768                                     u32 param_value)
1769{
1770        struct wmi_tlv_pdev_set_param_cmd *cmd;
1771        struct wmi_tlv *tlv;
1772        struct sk_buff *skb;
1773
1774        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1775        if (!skb)
1776                return ERR_PTR(-ENOMEM);
1777
1778        tlv = (void *)skb->data;
1779        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_SET_PARAM_CMD);
1780        tlv->len = __cpu_to_le16(sizeof(*cmd));
1781        cmd = (void *)tlv->value;
1782        cmd->param_id = __cpu_to_le32(param_id);
1783        cmd->param_value = __cpu_to_le32(param_value);
1784
1785        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev set param %d value 0x%x\n",
1786                   param_id, param_value);
1787        return skb;
1788}
1789
1790static void
1791ath10k_wmi_tlv_put_host_mem_chunks(struct ath10k *ar, void *host_mem_chunks)
1792{
1793        struct host_memory_chunk_tlv *chunk;
1794        struct wmi_tlv *tlv;
1795        dma_addr_t paddr;
1796        int i;
1797        __le16 tlv_len, tlv_tag;
1798
1799        tlv_tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WLAN_HOST_MEMORY_CHUNK);
1800        tlv_len = __cpu_to_le16(sizeof(*chunk));
1801        for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
1802                tlv = host_mem_chunks;
1803                tlv->tag = tlv_tag;
1804                tlv->len = tlv_len;
1805                chunk = (void *)tlv->value;
1806
1807                chunk->ptr = __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
1808                chunk->size = __cpu_to_le32(ar->wmi.mem_chunks[i].len);
1809                chunk->req_id = __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
1810
1811                if (test_bit(WMI_SERVICE_SUPPORT_EXTEND_ADDRESS,
1812                             ar->wmi.svc_map)) {
1813                        paddr = ar->wmi.mem_chunks[i].paddr;
1814                        chunk->ptr_high = __cpu_to_le32(upper_32_bits(paddr));
1815                }
1816
1817                ath10k_dbg(ar, ATH10K_DBG_WMI,
1818                           "wmi-tlv chunk %d len %d, addr 0x%llx, id 0x%x\n",
1819                           i,
1820                           ar->wmi.mem_chunks[i].len,
1821                           (unsigned long long)ar->wmi.mem_chunks[i].paddr,
1822                           ar->wmi.mem_chunks[i].req_id);
1823
1824                host_mem_chunks += sizeof(*tlv);
1825                host_mem_chunks += sizeof(*chunk);
1826        }
1827}
1828
1829static struct sk_buff *ath10k_wmi_tlv_op_gen_init(struct ath10k *ar)
1830{
1831        struct sk_buff *skb;
1832        struct wmi_tlv *tlv;
1833        struct wmi_tlv_init_cmd *cmd;
1834        struct wmi_tlv_resource_config *cfg;
1835        void *chunks;
1836        size_t len, chunks_len;
1837        void *ptr;
1838
1839        chunks_len = ar->wmi.num_mem_chunks *
1840                     (sizeof(struct host_memory_chunk_tlv) + sizeof(*tlv));
1841        len = (sizeof(*tlv) + sizeof(*cmd)) +
1842              (sizeof(*tlv) + sizeof(*cfg)) +
1843              (sizeof(*tlv) + chunks_len);
1844
1845        skb = ath10k_wmi_alloc_skb(ar, len);
1846        if (!skb)
1847                return ERR_PTR(-ENOMEM);
1848
1849        ptr = skb->data;
1850
1851        tlv = ptr;
1852        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_INIT_CMD);
1853        tlv->len = __cpu_to_le16(sizeof(*cmd));
1854        cmd = (void *)tlv->value;
1855        ptr += sizeof(*tlv);
1856        ptr += sizeof(*cmd);
1857
1858        tlv = ptr;
1859        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_RESOURCE_CONFIG);
1860        tlv->len = __cpu_to_le16(sizeof(*cfg));
1861        cfg = (void *)tlv->value;
1862        ptr += sizeof(*tlv);
1863        ptr += sizeof(*cfg);
1864
1865        tlv = ptr;
1866        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
1867        tlv->len = __cpu_to_le16(chunks_len);
1868        chunks = (void *)tlv->value;
1869
1870        ptr += sizeof(*tlv);
1871        ptr += chunks_len;
1872
1873        cmd->abi.abi_ver0 = __cpu_to_le32(WMI_TLV_ABI_VER0);
1874        cmd->abi.abi_ver1 = __cpu_to_le32(WMI_TLV_ABI_VER1);
1875        cmd->abi.abi_ver_ns0 = __cpu_to_le32(WMI_TLV_ABI_VER_NS0);
1876        cmd->abi.abi_ver_ns1 = __cpu_to_le32(WMI_TLV_ABI_VER_NS1);
1877        cmd->abi.abi_ver_ns2 = __cpu_to_le32(WMI_TLV_ABI_VER_NS2);
1878        cmd->abi.abi_ver_ns3 = __cpu_to_le32(WMI_TLV_ABI_VER_NS3);
1879        cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
1880
1881        cfg->num_vdevs = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1882
1883        if (ar->hw_params.num_peers)
1884                cfg->num_peers = __cpu_to_le32(ar->hw_params.num_peers);
1885        else
1886                cfg->num_peers = __cpu_to_le32(TARGET_TLV_NUM_PEERS);
1887        cfg->ast_skid_limit = __cpu_to_le32(ar->hw_params.ast_skid_limit);
1888        cfg->num_wds_entries = __cpu_to_le32(ar->hw_params.num_wds_entries);
1889
1890        if (test_bit(WMI_SERVICE_RX_FULL_REORDER, ar->wmi.svc_map)) {
1891                cfg->num_offload_peers = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1892                cfg->num_offload_reorder_bufs = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1893        } else {
1894                cfg->num_offload_peers = __cpu_to_le32(0);
1895                cfg->num_offload_reorder_bufs = __cpu_to_le32(0);
1896        }
1897
1898        cfg->num_peer_keys = __cpu_to_le32(2);
1899        if (ar->hw_params.num_peers)
1900                cfg->num_tids = __cpu_to_le32(ar->hw_params.num_peers * 2);
1901        else
1902                cfg->num_tids = __cpu_to_le32(TARGET_TLV_NUM_TIDS);
1903        cfg->tx_chain_mask = __cpu_to_le32(0x7);
1904        cfg->rx_chain_mask = __cpu_to_le32(0x7);
1905        cfg->rx_timeout_pri[0] = __cpu_to_le32(0x64);
1906        cfg->rx_timeout_pri[1] = __cpu_to_le32(0x64);
1907        cfg->rx_timeout_pri[2] = __cpu_to_le32(0x64);
1908        cfg->rx_timeout_pri[3] = __cpu_to_le32(0x28);
1909        cfg->rx_decap_mode = __cpu_to_le32(ar->wmi.rx_decap_mode);
1910        cfg->scan_max_pending_reqs = __cpu_to_le32(4);
1911        cfg->bmiss_offload_max_vdev = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1912        cfg->roam_offload_max_vdev = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1913        cfg->roam_offload_max_ap_profiles = __cpu_to_le32(8);
1914        cfg->num_mcast_groups = __cpu_to_le32(0);
1915        cfg->num_mcast_table_elems = __cpu_to_le32(0);
1916        cfg->mcast2ucast_mode = __cpu_to_le32(0);
1917        cfg->tx_dbg_log_size = __cpu_to_le32(0x400);
1918        cfg->dma_burst_size = __cpu_to_le32(0);
1919        cfg->mac_aggr_delim = __cpu_to_le32(0);
1920        cfg->rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(0);
1921        cfg->vow_config = __cpu_to_le32(0);
1922        cfg->gtk_offload_max_vdev = __cpu_to_le32(2);
1923        cfg->num_msdu_desc = __cpu_to_le32(ar->htt.max_num_pending_tx);
1924        cfg->max_frag_entries = __cpu_to_le32(2);
1925        cfg->num_tdls_vdevs = __cpu_to_le32(TARGET_TLV_NUM_TDLS_VDEVS);
1926        cfg->num_tdls_conn_table_entries = __cpu_to_le32(0x20);
1927        cfg->beacon_tx_offload_max_vdev = __cpu_to_le32(2);
1928        cfg->num_multicast_filter_entries = __cpu_to_le32(5);
1929        cfg->num_wow_filters = __cpu_to_le32(ar->wow.max_num_patterns);
1930        cfg->num_keep_alive_pattern = __cpu_to_le32(6);
1931        cfg->keep_alive_pattern_size = __cpu_to_le32(0);
1932        cfg->max_tdls_concurrent_sleep_sta = __cpu_to_le32(1);
1933        cfg->max_tdls_concurrent_buffer_sta = __cpu_to_le32(1);
1934        cfg->wmi_send_separate = __cpu_to_le32(0);
1935        cfg->num_ocb_vdevs = __cpu_to_le32(0);
1936        cfg->num_ocb_channels = __cpu_to_le32(0);
1937        cfg->num_ocb_schedules = __cpu_to_le32(0);
1938        cfg->host_capab = __cpu_to_le32(WMI_TLV_FLAG_MGMT_BUNDLE_TX_COMPL);
1939
1940        if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map))
1941                cfg->host_capab |= __cpu_to_le32(WMI_RSRC_CFG_FLAG_TX_ACK_RSSI);
1942
1943        ath10k_wmi_tlv_put_host_mem_chunks(ar, chunks);
1944
1945        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv init\n");
1946        return skb;
1947}
1948
1949static struct sk_buff *
1950ath10k_wmi_tlv_op_gen_start_scan(struct ath10k *ar,
1951                                 const struct wmi_start_scan_arg *arg)
1952{
1953        struct wmi_tlv_start_scan_cmd *cmd;
1954        struct wmi_tlv *tlv;
1955        struct sk_buff *skb;
1956        size_t len, chan_len, ssid_len, bssid_len, ie_len;
1957        __le32 *chans;
1958        struct wmi_ssid *ssids;
1959        struct wmi_mac_addr *addrs;
1960        void *ptr;
1961        int i, ret;
1962
1963        ret = ath10k_wmi_start_scan_verify(arg);
1964        if (ret)
1965                return ERR_PTR(ret);
1966
1967        chan_len = arg->n_channels * sizeof(__le32);
1968        ssid_len = arg->n_ssids * sizeof(struct wmi_ssid);
1969        bssid_len = arg->n_bssids * sizeof(struct wmi_mac_addr);
1970        ie_len = roundup(arg->ie_len, 4);
1971        len = (sizeof(*tlv) + sizeof(*cmd)) +
1972              sizeof(*tlv) + chan_len +
1973              sizeof(*tlv) + ssid_len +
1974              sizeof(*tlv) + bssid_len +
1975              sizeof(*tlv) + ie_len;
1976
1977        skb = ath10k_wmi_alloc_skb(ar, len);
1978        if (!skb)
1979                return ERR_PTR(-ENOMEM);
1980
1981        ptr = (void *)skb->data;
1982        tlv = ptr;
1983        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_START_SCAN_CMD);
1984        tlv->len = __cpu_to_le16(sizeof(*cmd));
1985        cmd = (void *)tlv->value;
1986
1987        ath10k_wmi_put_start_scan_common(&cmd->common, arg);
1988        cmd->burst_duration_ms = __cpu_to_le32(arg->burst_duration_ms);
1989        cmd->num_channels = __cpu_to_le32(arg->n_channels);
1990        cmd->num_ssids = __cpu_to_le32(arg->n_ssids);
1991        cmd->num_bssids = __cpu_to_le32(arg->n_bssids);
1992        cmd->ie_len = __cpu_to_le32(arg->ie_len);
1993        cmd->num_probes = __cpu_to_le32(3);
1994        ether_addr_copy(cmd->mac_addr.addr, arg->mac_addr.addr);
1995        ether_addr_copy(cmd->mac_mask.addr, arg->mac_mask.addr);
1996
1997        /* FIXME: There are some scan flag inconsistencies across firmwares,
1998         * e.g. WMI-TLV inverts the logic behind the following flag.
1999         */
2000        cmd->common.scan_ctrl_flags ^= __cpu_to_le32(WMI_SCAN_FILTER_PROBE_REQ);
2001
2002        ptr += sizeof(*tlv);
2003        ptr += sizeof(*cmd);
2004
2005        tlv = ptr;
2006        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
2007        tlv->len = __cpu_to_le16(chan_len);
2008        chans = (void *)tlv->value;
2009        for (i = 0; i < arg->n_channels; i++)
2010                chans[i] = __cpu_to_le32(arg->channels[i]);
2011
2012        ptr += sizeof(*tlv);
2013        ptr += chan_len;
2014
2015        tlv = ptr;
2016        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_FIXED_STRUCT);
2017        tlv->len = __cpu_to_le16(ssid_len);
2018        ssids = (void *)tlv->value;
2019        for (i = 0; i < arg->n_ssids; i++) {
2020                ssids[i].ssid_len = __cpu_to_le32(arg->ssids[i].len);
2021                memcpy(ssids[i].ssid, arg->ssids[i].ssid, arg->ssids[i].len);
2022        }
2023
2024        ptr += sizeof(*tlv);
2025        ptr += ssid_len;
2026
2027        tlv = ptr;
2028        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_FIXED_STRUCT);
2029        tlv->len = __cpu_to_le16(bssid_len);
2030        addrs = (void *)tlv->value;
2031        for (i = 0; i < arg->n_bssids; i++)
2032                ether_addr_copy(addrs[i].addr, arg->bssids[i].bssid);
2033
2034        ptr += sizeof(*tlv);
2035        ptr += bssid_len;
2036
2037        tlv = ptr;
2038        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
2039        tlv->len = __cpu_to_le16(ie_len);
2040        memcpy(tlv->value, arg->ie, arg->ie_len);
2041
2042        ptr += sizeof(*tlv);
2043        ptr += ie_len;
2044
2045        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv start scan\n");
2046        return skb;
2047}
2048
2049static struct sk_buff *
2050ath10k_wmi_tlv_op_gen_stop_scan(struct ath10k *ar,
2051                                const struct wmi_stop_scan_arg *arg)
2052{
2053        struct wmi_stop_scan_cmd *cmd;
2054        struct wmi_tlv *tlv;
2055        struct sk_buff *skb;
2056        u32 scan_id;
2057        u32 req_id;
2058
2059        if (arg->req_id > 0xFFF)
2060                return ERR_PTR(-EINVAL);
2061        if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
2062                return ERR_PTR(-EINVAL);
2063
2064        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2065        if (!skb)
2066                return ERR_PTR(-ENOMEM);
2067
2068        scan_id = arg->u.scan_id;
2069        scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
2070
2071        req_id = arg->req_id;
2072        req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
2073
2074        tlv = (void *)skb->data;
2075        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STOP_SCAN_CMD);
2076        tlv->len = __cpu_to_le16(sizeof(*cmd));
2077        cmd = (void *)tlv->value;
2078        cmd->req_type = __cpu_to_le32(arg->req_type);
2079        cmd->vdev_id = __cpu_to_le32(arg->u.vdev_id);
2080        cmd->scan_id = __cpu_to_le32(scan_id);
2081        cmd->scan_req_id = __cpu_to_le32(req_id);
2082
2083        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv stop scan\n");
2084        return skb;
2085}
2086
2087static int ath10k_wmi_tlv_op_get_vdev_subtype(struct ath10k *ar,
2088                                              enum wmi_vdev_subtype subtype)
2089{
2090        switch (subtype) {
2091        case WMI_VDEV_SUBTYPE_NONE:
2092                return WMI_TLV_VDEV_SUBTYPE_NONE;
2093        case WMI_VDEV_SUBTYPE_P2P_DEVICE:
2094                return WMI_TLV_VDEV_SUBTYPE_P2P_DEV;
2095        case WMI_VDEV_SUBTYPE_P2P_CLIENT:
2096                return WMI_TLV_VDEV_SUBTYPE_P2P_CLI;
2097        case WMI_VDEV_SUBTYPE_P2P_GO:
2098                return WMI_TLV_VDEV_SUBTYPE_P2P_GO;
2099        case WMI_VDEV_SUBTYPE_PROXY_STA:
2100                return WMI_TLV_VDEV_SUBTYPE_PROXY_STA;
2101        case WMI_VDEV_SUBTYPE_MESH_11S:
2102                return WMI_TLV_VDEV_SUBTYPE_MESH_11S;
2103        case WMI_VDEV_SUBTYPE_MESH_NON_11S:
2104                return -ENOTSUPP;
2105        }
2106        return -ENOTSUPP;
2107}
2108
2109static struct sk_buff *
2110ath10k_wmi_tlv_op_gen_vdev_create(struct ath10k *ar,
2111                                  u32 vdev_id,
2112                                  enum wmi_vdev_type vdev_type,
2113                                  enum wmi_vdev_subtype vdev_subtype,
2114                                  const u8 mac_addr[ETH_ALEN])
2115{
2116        struct wmi_vdev_create_cmd *cmd;
2117        struct wmi_tlv *tlv;
2118        struct sk_buff *skb;
2119
2120        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2121        if (!skb)
2122                return ERR_PTR(-ENOMEM);
2123
2124        tlv = (void *)skb->data;
2125        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_CREATE_CMD);
2126        tlv->len = __cpu_to_le16(sizeof(*cmd));
2127        cmd = (void *)tlv->value;
2128        cmd->vdev_id = __cpu_to_le32(vdev_id);
2129        cmd->vdev_type = __cpu_to_le32(vdev_type);
2130        cmd->vdev_subtype = __cpu_to_le32(vdev_subtype);
2131        ether_addr_copy(cmd->vdev_macaddr.addr, mac_addr);
2132
2133        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev create\n");
2134        return skb;
2135}
2136
2137static struct sk_buff *
2138ath10k_wmi_tlv_op_gen_vdev_delete(struct ath10k *ar, u32 vdev_id)
2139{
2140        struct wmi_vdev_delete_cmd *cmd;
2141        struct wmi_tlv *tlv;
2142        struct sk_buff *skb;
2143
2144        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2145        if (!skb)
2146                return ERR_PTR(-ENOMEM);
2147
2148        tlv = (void *)skb->data;
2149        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_DELETE_CMD);
2150        tlv->len = __cpu_to_le16(sizeof(*cmd));
2151        cmd = (void *)tlv->value;
2152        cmd->vdev_id = __cpu_to_le32(vdev_id);
2153
2154        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev delete\n");
2155        return skb;
2156}
2157
2158static struct sk_buff *
2159ath10k_wmi_tlv_op_gen_vdev_start(struct ath10k *ar,
2160                                 const struct wmi_vdev_start_request_arg *arg,
2161                                 bool restart)
2162{
2163        struct wmi_tlv_vdev_start_cmd *cmd;
2164        struct wmi_channel *ch;
2165        struct wmi_tlv *tlv;
2166        struct sk_buff *skb;
2167        size_t len;
2168        void *ptr;
2169        u32 flags = 0;
2170
2171        if (WARN_ON(arg->hidden_ssid && !arg->ssid))
2172                return ERR_PTR(-EINVAL);
2173        if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
2174                return ERR_PTR(-EINVAL);
2175
2176        len = (sizeof(*tlv) + sizeof(*cmd)) +
2177              (sizeof(*tlv) + sizeof(*ch)) +
2178              (sizeof(*tlv) + 0);
2179        skb = ath10k_wmi_alloc_skb(ar, len);
2180        if (!skb)
2181                return ERR_PTR(-ENOMEM);
2182
2183        if (arg->hidden_ssid)
2184                flags |= WMI_VDEV_START_HIDDEN_SSID;
2185        if (arg->pmf_enabled)
2186                flags |= WMI_VDEV_START_PMF_ENABLED;
2187
2188        ptr = (void *)skb->data;
2189
2190        tlv = ptr;
2191        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_START_REQUEST_CMD);
2192        tlv->len = __cpu_to_le16(sizeof(*cmd));
2193        cmd = (void *)tlv->value;
2194        cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
2195        cmd->bcn_intval = __cpu_to_le32(arg->bcn_intval);
2196        cmd->dtim_period = __cpu_to_le32(arg->dtim_period);
2197        cmd->flags = __cpu_to_le32(flags);
2198        cmd->bcn_tx_rate = __cpu_to_le32(arg->bcn_tx_rate);
2199        cmd->bcn_tx_power = __cpu_to_le32(arg->bcn_tx_power);
2200        cmd->disable_hw_ack = __cpu_to_le32(arg->disable_hw_ack);
2201
2202        if (arg->ssid) {
2203                cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
2204                memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
2205        }
2206
2207        ptr += sizeof(*tlv);
2208        ptr += sizeof(*cmd);
2209
2210        tlv = ptr;
2211        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_CHANNEL);
2212        tlv->len = __cpu_to_le16(sizeof(*ch));
2213        ch = (void *)tlv->value;
2214        ath10k_wmi_put_wmi_channel(ar, ch, &arg->channel);
2215
2216        ptr += sizeof(*tlv);
2217        ptr += sizeof(*ch);
2218
2219        tlv = ptr;
2220        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
2221        tlv->len = 0;
2222
2223        /* Note: This is a nested TLV containing:
2224         * [wmi_tlv][wmi_p2p_noa_descriptor][wmi_tlv]..
2225         */
2226
2227        ptr += sizeof(*tlv);
2228        ptr += 0;
2229
2230        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev start\n");
2231        return skb;
2232}
2233
2234static struct sk_buff *
2235ath10k_wmi_tlv_op_gen_vdev_stop(struct ath10k *ar, u32 vdev_id)
2236{
2237        struct wmi_vdev_stop_cmd *cmd;
2238        struct wmi_tlv *tlv;
2239        struct sk_buff *skb;
2240
2241        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2242        if (!skb)
2243                return ERR_PTR(-ENOMEM);
2244
2245        tlv = (void *)skb->data;
2246        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_STOP_CMD);
2247        tlv->len = __cpu_to_le16(sizeof(*cmd));
2248        cmd = (void *)tlv->value;
2249        cmd->vdev_id = __cpu_to_le32(vdev_id);
2250
2251        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev stop\n");
2252        return skb;
2253}
2254
2255static struct sk_buff *
2256ath10k_wmi_tlv_op_gen_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid,
2257                              const u8 *bssid)
2258
2259{
2260        struct wmi_vdev_up_cmd *cmd;
2261        struct wmi_tlv *tlv;
2262        struct sk_buff *skb;
2263
2264        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2265        if (!skb)
2266                return ERR_PTR(-ENOMEM);
2267
2268        tlv = (void *)skb->data;
2269        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_UP_CMD);
2270        tlv->len = __cpu_to_le16(sizeof(*cmd));
2271        cmd = (void *)tlv->value;
2272        cmd->vdev_id = __cpu_to_le32(vdev_id);
2273        cmd->vdev_assoc_id = __cpu_to_le32(aid);
2274        ether_addr_copy(cmd->vdev_bssid.addr, bssid);
2275
2276        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev up\n");
2277        return skb;
2278}
2279
2280static struct sk_buff *
2281ath10k_wmi_tlv_op_gen_vdev_down(struct ath10k *ar, u32 vdev_id)
2282{
2283        struct wmi_vdev_down_cmd *cmd;
2284        struct wmi_tlv *tlv;
2285        struct sk_buff *skb;
2286
2287        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2288        if (!skb)
2289                return ERR_PTR(-ENOMEM);
2290
2291        tlv = (void *)skb->data;
2292        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_DOWN_CMD);
2293        tlv->len = __cpu_to_le16(sizeof(*cmd));
2294        cmd = (void *)tlv->value;
2295        cmd->vdev_id = __cpu_to_le32(vdev_id);
2296
2297        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev down\n");
2298        return skb;
2299}
2300
2301static struct sk_buff *
2302ath10k_wmi_tlv_op_gen_vdev_set_param(struct ath10k *ar, u32 vdev_id,
2303                                     u32 param_id, u32 param_value)
2304{
2305        struct wmi_vdev_set_param_cmd *cmd;
2306        struct wmi_tlv *tlv;
2307        struct sk_buff *skb;
2308
2309        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2310        if (!skb)
2311                return ERR_PTR(-ENOMEM);
2312
2313        tlv = (void *)skb->data;
2314        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_SET_PARAM_CMD);
2315        tlv->len = __cpu_to_le16(sizeof(*cmd));
2316        cmd = (void *)tlv->value;
2317        cmd->vdev_id = __cpu_to_le32(vdev_id);
2318        cmd->param_id = __cpu_to_le32(param_id);
2319        cmd->param_value = __cpu_to_le32(param_value);
2320
2321        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev %d set param %d value 0x%x\n",
2322                   vdev_id, param_id, param_value);
2323        return skb;
2324}
2325
2326static struct sk_buff *
2327ath10k_wmi_tlv_op_gen_vdev_install_key(struct ath10k *ar,
2328                                       const struct wmi_vdev_install_key_arg *arg)
2329{
2330        struct wmi_vdev_install_key_cmd *cmd;
2331        struct wmi_tlv *tlv;
2332        struct sk_buff *skb;
2333        size_t len;
2334        void *ptr;
2335
2336        if (arg->key_cipher == ar->wmi_key_cipher[WMI_CIPHER_NONE] &&
2337            arg->key_data)
2338                return ERR_PTR(-EINVAL);
2339        if (arg->key_cipher != ar->wmi_key_cipher[WMI_CIPHER_NONE] &&
2340            !arg->key_data)
2341                return ERR_PTR(-EINVAL);
2342
2343        len = sizeof(*tlv) + sizeof(*cmd) +
2344              sizeof(*tlv) + roundup(arg->key_len, sizeof(__le32));
2345        skb = ath10k_wmi_alloc_skb(ar, len);
2346        if (!skb)
2347                return ERR_PTR(-ENOMEM);
2348
2349        ptr = (void *)skb->data;
2350        tlv = ptr;
2351        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_INSTALL_KEY_CMD);
2352        tlv->len = __cpu_to_le16(sizeof(*cmd));
2353        cmd = (void *)tlv->value;
2354        cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
2355        cmd->key_idx = __cpu_to_le32(arg->key_idx);
2356        cmd->key_flags = __cpu_to_le32(arg->key_flags);
2357        cmd->key_cipher = __cpu_to_le32(arg->key_cipher);
2358        cmd->key_len = __cpu_to_le32(arg->key_len);
2359        cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
2360        cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
2361
2362        if (arg->macaddr)
2363                ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr);
2364
2365        ptr += sizeof(*tlv);
2366        ptr += sizeof(*cmd);
2367
2368        tlv = ptr;
2369        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
2370        tlv->len = __cpu_to_le16(roundup(arg->key_len, sizeof(__le32)));
2371        if (arg->key_data)
2372                memcpy(tlv->value, arg->key_data, arg->key_len);
2373
2374        ptr += sizeof(*tlv);
2375        ptr += roundup(arg->key_len, sizeof(__le32));
2376
2377        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev install key\n");
2378        return skb;
2379}
2380
2381static void *ath10k_wmi_tlv_put_uapsd_ac(struct ath10k *ar, void *ptr,
2382                                         const struct wmi_sta_uapsd_auto_trig_arg *arg)
2383{
2384        struct wmi_sta_uapsd_auto_trig_param *ac;
2385        struct wmi_tlv *tlv;
2386
2387        tlv = ptr;
2388        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_UAPSD_AUTO_TRIG_PARAM);
2389        tlv->len = __cpu_to_le16(sizeof(*ac));
2390        ac = (void *)tlv->value;
2391
2392        ac->wmm_ac = __cpu_to_le32(arg->wmm_ac);
2393        ac->user_priority = __cpu_to_le32(arg->user_priority);
2394        ac->service_interval = __cpu_to_le32(arg->service_interval);
2395        ac->suspend_interval = __cpu_to_le32(arg->suspend_interval);
2396        ac->delay_interval = __cpu_to_le32(arg->delay_interval);
2397
2398        ath10k_dbg(ar, ATH10K_DBG_WMI,
2399                   "wmi tlv vdev sta uapsd auto trigger ac %d prio %d svc int %d susp int %d delay int %d\n",
2400                   ac->wmm_ac, ac->user_priority, ac->service_interval,
2401                   ac->suspend_interval, ac->delay_interval);
2402
2403        return ptr + sizeof(*tlv) + sizeof(*ac);
2404}
2405
2406static struct sk_buff *
2407ath10k_wmi_tlv_op_gen_vdev_sta_uapsd(struct ath10k *ar, u32 vdev_id,
2408                                     const u8 peer_addr[ETH_ALEN],
2409                                     const struct wmi_sta_uapsd_auto_trig_arg *args,
2410                                     u32 num_ac)
2411{
2412        struct wmi_sta_uapsd_auto_trig_cmd_fixed_param *cmd;
2413        struct wmi_sta_uapsd_auto_trig_param *ac;
2414        struct wmi_tlv *tlv;
2415        struct sk_buff *skb;
2416        size_t len;
2417        size_t ac_tlv_len;
2418        void *ptr;
2419        int i;
2420
2421        ac_tlv_len = num_ac * (sizeof(*tlv) + sizeof(*ac));
2422        len = sizeof(*tlv) + sizeof(*cmd) +
2423              sizeof(*tlv) + ac_tlv_len;
2424        skb = ath10k_wmi_alloc_skb(ar, len);
2425        if (!skb)
2426                return ERR_PTR(-ENOMEM);
2427
2428        ptr = (void *)skb->data;
2429        tlv = ptr;
2430        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_UAPSD_AUTO_TRIG_CMD);
2431        tlv->len = __cpu_to_le16(sizeof(*cmd));
2432        cmd = (void *)tlv->value;
2433        cmd->vdev_id = __cpu_to_le32(vdev_id);
2434        cmd->num_ac = __cpu_to_le32(num_ac);
2435        ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
2436
2437        ptr += sizeof(*tlv);
2438        ptr += sizeof(*cmd);
2439
2440        tlv = ptr;
2441        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
2442        tlv->len = __cpu_to_le16(ac_tlv_len);
2443        ac = (void *)tlv->value;
2444
2445        ptr += sizeof(*tlv);
2446        for (i = 0; i < num_ac; i++)
2447                ptr = ath10k_wmi_tlv_put_uapsd_ac(ar, ptr, &args[i]);
2448
2449        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev sta uapsd auto trigger\n");
2450        return skb;
2451}
2452
2453static void *ath10k_wmi_tlv_put_wmm(void *ptr,
2454                                    const struct wmi_wmm_params_arg *arg)
2455{
2456        struct wmi_wmm_params *wmm;
2457        struct wmi_tlv *tlv;
2458
2459        tlv = ptr;
2460        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WMM_PARAMS);
2461        tlv->len = __cpu_to_le16(sizeof(*wmm));
2462        wmm = (void *)tlv->value;
2463        ath10k_wmi_set_wmm_param(wmm, arg);
2464
2465        return ptr + sizeof(*tlv) + sizeof(*wmm);
2466}
2467
2468static struct sk_buff *
2469ath10k_wmi_tlv_op_gen_vdev_wmm_conf(struct ath10k *ar, u32 vdev_id,
2470                                    const struct wmi_wmm_params_all_arg *arg)
2471{
2472        struct wmi_tlv_vdev_set_wmm_cmd *cmd;
2473        struct wmi_tlv *tlv;
2474        struct sk_buff *skb;
2475        size_t len;
2476        void *ptr;
2477
2478        len = sizeof(*tlv) + sizeof(*cmd);
2479        skb = ath10k_wmi_alloc_skb(ar, len);
2480        if (!skb)
2481                return ERR_PTR(-ENOMEM);
2482
2483        ptr = (void *)skb->data;
2484        tlv = ptr;
2485        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_SET_WMM_PARAMS_CMD);
2486        tlv->len = __cpu_to_le16(sizeof(*cmd));
2487        cmd = (void *)tlv->value;
2488        cmd->vdev_id = __cpu_to_le32(vdev_id);
2489
2490        ath10k_wmi_set_wmm_param(&cmd->vdev_wmm_params[0].params, &arg->ac_be);
2491        ath10k_wmi_set_wmm_param(&cmd->vdev_wmm_params[1].params, &arg->ac_bk);
2492        ath10k_wmi_set_wmm_param(&cmd->vdev_wmm_params[2].params, &arg->ac_vi);
2493        ath10k_wmi_set_wmm_param(&cmd->vdev_wmm_params[3].params, &arg->ac_vo);
2494
2495        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev wmm conf\n");
2496        return skb;
2497}
2498
2499static struct sk_buff *
2500ath10k_wmi_tlv_op_gen_sta_keepalive(struct ath10k *ar,
2501                                    const struct wmi_sta_keepalive_arg *arg)
2502{
2503        struct wmi_tlv_sta_keepalive_cmd *cmd;
2504        struct wmi_sta_keepalive_arp_resp *arp;
2505        struct sk_buff *skb;
2506        struct wmi_tlv *tlv;
2507        void *ptr;
2508        size_t len;
2509
2510        len = sizeof(*tlv) + sizeof(*cmd) +
2511              sizeof(*tlv) + sizeof(*arp);
2512        skb = ath10k_wmi_alloc_skb(ar, len);
2513        if (!skb)
2514                return ERR_PTR(-ENOMEM);
2515
2516        ptr = (void *)skb->data;
2517        tlv = ptr;
2518        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_KEEPALIVE_CMD);
2519        tlv->len = __cpu_to_le16(sizeof(*cmd));
2520        cmd = (void *)tlv->value;
2521        cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
2522        cmd->enabled = __cpu_to_le32(arg->enabled);
2523        cmd->method = __cpu_to_le32(arg->method);
2524        cmd->interval = __cpu_to_le32(arg->interval);
2525
2526        ptr += sizeof(*tlv);
2527        ptr += sizeof(*cmd);
2528
2529        tlv = ptr;
2530        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_KEEPALVE_ARP_RESPONSE);
2531        tlv->len = __cpu_to_le16(sizeof(*arp));
2532        arp = (void *)tlv->value;
2533
2534        arp->src_ip4_addr = arg->src_ip4_addr;
2535        arp->dest_ip4_addr = arg->dest_ip4_addr;
2536        ether_addr_copy(arp->dest_mac_addr.addr, arg->dest_mac_addr);
2537
2538        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv sta keepalive vdev %d enabled %d method %d interval %d\n",
2539                   arg->vdev_id, arg->enabled, arg->method, arg->interval);
2540        return skb;
2541}
2542
2543static struct sk_buff *
2544ath10k_wmi_tlv_op_gen_peer_create(struct ath10k *ar, u32 vdev_id,
2545                                  const u8 peer_addr[ETH_ALEN],
2546                                  enum wmi_peer_type peer_type)
2547{
2548        struct wmi_tlv_peer_create_cmd *cmd;
2549        struct wmi_tlv *tlv;
2550        struct sk_buff *skb;
2551
2552        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2553        if (!skb)
2554                return ERR_PTR(-ENOMEM);
2555
2556        tlv = (void *)skb->data;
2557        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_CREATE_CMD);
2558        tlv->len = __cpu_to_le16(sizeof(*cmd));
2559        cmd = (void *)tlv->value;
2560        cmd->vdev_id = __cpu_to_le32(vdev_id);
2561        cmd->peer_type = __cpu_to_le32(peer_type);
2562        ether_addr_copy(cmd->peer_addr.addr, peer_addr);
2563
2564        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer create\n");
2565        return skb;
2566}
2567
2568static struct sk_buff *
2569ath10k_wmi_tlv_op_gen_peer_delete(struct ath10k *ar, u32 vdev_id,
2570                                  const u8 peer_addr[ETH_ALEN])
2571{
2572        struct wmi_peer_delete_cmd *cmd;
2573        struct wmi_tlv *tlv;
2574        struct sk_buff *skb;
2575
2576        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2577        if (!skb)
2578                return ERR_PTR(-ENOMEM);
2579
2580        tlv = (void *)skb->data;
2581        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_DELETE_CMD);
2582        tlv->len = __cpu_to_le16(sizeof(*cmd));
2583        cmd = (void *)tlv->value;
2584        cmd->vdev_id = __cpu_to_le32(vdev_id);
2585        ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
2586
2587        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer delete\n");
2588        return skb;
2589}
2590
2591static struct sk_buff *
2592ath10k_wmi_tlv_op_gen_peer_flush(struct ath10k *ar, u32 vdev_id,
2593                                 const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
2594{
2595        struct wmi_peer_flush_tids_cmd *cmd;
2596        struct wmi_tlv *tlv;
2597        struct sk_buff *skb;
2598
2599        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2600        if (!skb)
2601                return ERR_PTR(-ENOMEM);
2602
2603        tlv = (void *)skb->data;
2604        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_FLUSH_TIDS_CMD);
2605        tlv->len = __cpu_to_le16(sizeof(*cmd));
2606        cmd = (void *)tlv->value;
2607        cmd->vdev_id = __cpu_to_le32(vdev_id);
2608        cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
2609        ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
2610
2611        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer flush\n");
2612        return skb;
2613}
2614
2615static struct sk_buff *
2616ath10k_wmi_tlv_op_gen_peer_set_param(struct ath10k *ar, u32 vdev_id,
2617                                     const u8 *peer_addr,
2618                                     enum wmi_peer_param param_id,
2619                                     u32 param_value)
2620{
2621        struct wmi_peer_set_param_cmd *cmd;
2622        struct wmi_tlv *tlv;
2623        struct sk_buff *skb;
2624
2625        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2626        if (!skb)
2627                return ERR_PTR(-ENOMEM);
2628
2629        tlv = (void *)skb->data;
2630        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_SET_PARAM_CMD);
2631        tlv->len = __cpu_to_le16(sizeof(*cmd));
2632        cmd = (void *)tlv->value;
2633        cmd->vdev_id = __cpu_to_le32(vdev_id);
2634        cmd->param_id = __cpu_to_le32(param_id);
2635        cmd->param_value = __cpu_to_le32(param_value);
2636        ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
2637
2638        ath10k_dbg(ar, ATH10K_DBG_WMI,
2639                   "wmi tlv vdev %d peer %pM set param %d value 0x%x\n",
2640                   vdev_id, peer_addr, param_id, param_value);
2641        return skb;
2642}
2643
2644static struct sk_buff *
2645ath10k_wmi_tlv_op_gen_peer_assoc(struct ath10k *ar,
2646                                 const struct wmi_peer_assoc_complete_arg *arg)
2647{
2648        struct wmi_tlv_peer_assoc_cmd *cmd;
2649        struct wmi_vht_rate_set *vht_rate;
2650        struct wmi_tlv *tlv;
2651        struct sk_buff *skb;
2652        size_t len, legacy_rate_len, ht_rate_len;
2653        void *ptr;
2654
2655        if (arg->peer_mpdu_density > 16)
2656                return ERR_PTR(-EINVAL);
2657        if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
2658                return ERR_PTR(-EINVAL);
2659        if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
2660                return ERR_PTR(-EINVAL);
2661
2662        legacy_rate_len = roundup(arg->peer_legacy_rates.num_rates,
2663                                  sizeof(__le32));
2664        ht_rate_len = roundup(arg->peer_ht_rates.num_rates, sizeof(__le32));
2665        len = (sizeof(*tlv) + sizeof(*cmd)) +
2666              (sizeof(*tlv) + legacy_rate_len) +
2667              (sizeof(*tlv) + ht_rate_len) +
2668              (sizeof(*tlv) + sizeof(*vht_rate));
2669        skb = ath10k_wmi_alloc_skb(ar, len);
2670        if (!skb)
2671                return ERR_PTR(-ENOMEM);
2672
2673        ptr = (void *)skb->data;
2674        tlv = ptr;
2675        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_ASSOC_COMPLETE_CMD);
2676        tlv->len = __cpu_to_le16(sizeof(*cmd));
2677        cmd = (void *)tlv->value;
2678
2679        cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
2680        cmd->new_assoc = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
2681        cmd->assoc_id = __cpu_to_le32(arg->peer_aid);
2682        cmd->flags = __cpu_to_le32(arg->peer_flags);
2683        cmd->caps = __cpu_to_le32(arg->peer_caps);
2684        cmd->listen_intval = __cpu_to_le32(arg->peer_listen_intval);
2685        cmd->ht_caps = __cpu_to_le32(arg->peer_ht_caps);
2686        cmd->max_mpdu = __cpu_to_le32(arg->peer_max_mpdu);
2687        cmd->mpdu_density = __cpu_to_le32(arg->peer_mpdu_density);
2688        cmd->rate_caps = __cpu_to_le32(arg->peer_rate_caps);
2689        cmd->nss = __cpu_to_le32(arg->peer_num_spatial_streams);
2690        cmd->vht_caps = __cpu_to_le32(arg->peer_vht_caps);
2691        cmd->phy_mode = __cpu_to_le32(arg->peer_phymode);
2692        cmd->num_legacy_rates = __cpu_to_le32(arg->peer_legacy_rates.num_rates);
2693        cmd->num_ht_rates = __cpu_to_le32(arg->peer_ht_rates.num_rates);
2694        ether_addr_copy(cmd->mac_addr.addr, arg->addr);
2695
2696        ptr += sizeof(*tlv);
2697        ptr += sizeof(*cmd);
2698
2699        tlv = ptr;
2700        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
2701        tlv->len = __cpu_to_le16(legacy_rate_len);
2702        memcpy(tlv->value, arg->peer_legacy_rates.rates,
2703               arg->peer_legacy_rates.num_rates);
2704
2705        ptr += sizeof(*tlv);
2706        ptr += legacy_rate_len;
2707
2708        tlv = ptr;
2709        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
2710        tlv->len = __cpu_to_le16(ht_rate_len);
2711        memcpy(tlv->value, arg->peer_ht_rates.rates,
2712               arg->peer_ht_rates.num_rates);
2713
2714        ptr += sizeof(*tlv);
2715        ptr += ht_rate_len;
2716
2717        tlv = ptr;
2718        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VHT_RATE_SET);
2719        tlv->len = __cpu_to_le16(sizeof(*vht_rate));
2720        vht_rate = (void *)tlv->value;
2721
2722        vht_rate->rx_max_rate = __cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
2723        vht_rate->rx_mcs_set = __cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
2724        vht_rate->tx_max_rate = __cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
2725        vht_rate->tx_mcs_set = __cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
2726
2727        ptr += sizeof(*tlv);
2728        ptr += sizeof(*vht_rate);
2729
2730        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer assoc\n");
2731        return skb;
2732}
2733
2734static struct sk_buff *
2735ath10k_wmi_tlv_op_gen_set_psmode(struct ath10k *ar, u32 vdev_id,
2736                                 enum wmi_sta_ps_mode psmode)
2737{
2738        struct wmi_sta_powersave_mode_cmd *cmd;
2739        struct wmi_tlv *tlv;
2740        struct sk_buff *skb;
2741
2742        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2743        if (!skb)
2744                return ERR_PTR(-ENOMEM);
2745
2746        tlv = (void *)skb->data;
2747        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_POWERSAVE_MODE_CMD);
2748        tlv->len = __cpu_to_le16(sizeof(*cmd));
2749        cmd = (void *)tlv->value;
2750        cmd->vdev_id = __cpu_to_le32(vdev_id);
2751        cmd->sta_ps_mode = __cpu_to_le32(psmode);
2752
2753        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv set psmode\n");
2754        return skb;
2755}
2756
2757static struct sk_buff *
2758ath10k_wmi_tlv_op_gen_set_sta_ps(struct ath10k *ar, u32 vdev_id,
2759                                 enum wmi_sta_powersave_param param_id,
2760                                 u32 param_value)
2761{
2762        struct wmi_sta_powersave_param_cmd *cmd;
2763        struct wmi_tlv *tlv;
2764        struct sk_buff *skb;
2765
2766        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2767        if (!skb)
2768                return ERR_PTR(-ENOMEM);
2769
2770        tlv = (void *)skb->data;
2771        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_POWERSAVE_PARAM_CMD);
2772        tlv->len = __cpu_to_le16(sizeof(*cmd));
2773        cmd = (void *)tlv->value;
2774        cmd->vdev_id = __cpu_to_le32(vdev_id);
2775        cmd->param_id = __cpu_to_le32(param_id);
2776        cmd->param_value = __cpu_to_le32(param_value);
2777
2778        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv set sta ps\n");
2779        return skb;
2780}
2781
2782static struct sk_buff *
2783ath10k_wmi_tlv_op_gen_set_ap_ps(struct ath10k *ar, u32 vdev_id, const u8 *mac,
2784                                enum wmi_ap_ps_peer_param param_id, u32 value)
2785{
2786        struct wmi_ap_ps_peer_cmd *cmd;
2787        struct wmi_tlv *tlv;
2788        struct sk_buff *skb;
2789
2790        if (!mac)
2791                return ERR_PTR(-EINVAL);
2792
2793        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2794        if (!skb)
2795                return ERR_PTR(-ENOMEM);
2796
2797        tlv = (void *)skb->data;
2798        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_AP_PS_PEER_CMD);
2799        tlv->len = __cpu_to_le16(sizeof(*cmd));
2800        cmd = (void *)tlv->value;
2801        cmd->vdev_id = __cpu_to_le32(vdev_id);
2802        cmd->param_id = __cpu_to_le32(param_id);
2803        cmd->param_value = __cpu_to_le32(value);
2804        ether_addr_copy(cmd->peer_macaddr.addr, mac);
2805
2806        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv ap ps param\n");
2807        return skb;
2808}
2809
2810static struct sk_buff *
2811ath10k_wmi_tlv_op_gen_scan_chan_list(struct ath10k *ar,
2812                                     const struct wmi_scan_chan_list_arg *arg)
2813{
2814        struct wmi_tlv_scan_chan_list_cmd *cmd;
2815        struct wmi_channel *ci;
2816        struct wmi_channel_arg *ch;
2817        struct wmi_tlv *tlv;
2818        struct sk_buff *skb;
2819        size_t chans_len, len;
2820        int i;
2821        void *ptr, *chans;
2822
2823        chans_len = arg->n_channels * (sizeof(*tlv) + sizeof(*ci));
2824        len = (sizeof(*tlv) + sizeof(*cmd)) +
2825              (sizeof(*tlv) + chans_len);
2826
2827        skb = ath10k_wmi_alloc_skb(ar, len);
2828        if (!skb)
2829                return ERR_PTR(-ENOMEM);
2830
2831        ptr = (void *)skb->data;
2832        tlv = ptr;
2833        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_SCAN_CHAN_LIST_CMD);
2834        tlv->len = __cpu_to_le16(sizeof(*cmd));
2835        cmd = (void *)tlv->value;
2836        cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
2837
2838        ptr += sizeof(*tlv);
2839        ptr += sizeof(*cmd);
2840
2841        tlv = ptr;
2842        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
2843        tlv->len = __cpu_to_le16(chans_len);
2844        chans = (void *)tlv->value;
2845
2846        for (i = 0; i < arg->n_channels; i++) {
2847                ch = &arg->channels[i];
2848
2849                tlv = chans;
2850                tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_CHANNEL);
2851                tlv->len = __cpu_to_le16(sizeof(*ci));
2852                ci = (void *)tlv->value;
2853
2854                ath10k_wmi_put_wmi_channel(ar, ci, ch);
2855
2856                chans += sizeof(*tlv);
2857                chans += sizeof(*ci);
2858        }
2859
2860        ptr += sizeof(*tlv);
2861        ptr += chans_len;
2862
2863        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv scan chan list\n");
2864        return skb;
2865}
2866
2867static struct sk_buff *
2868ath10k_wmi_tlv_op_gen_scan_prob_req_oui(struct ath10k *ar, u32 prob_req_oui)
2869{
2870        struct wmi_scan_prob_req_oui_cmd *cmd;
2871        struct wmi_tlv *tlv;
2872        struct sk_buff *skb;
2873
2874        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2875        if (!skb)
2876                return ERR_PTR(-ENOMEM);
2877
2878        tlv = (void *)skb->data;
2879        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_SCAN_PROB_REQ_OUI_CMD);
2880        tlv->len = __cpu_to_le16(sizeof(*cmd));
2881        cmd = (void *)tlv->value;
2882        cmd->prob_req_oui = __cpu_to_le32(prob_req_oui);
2883
2884        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv scan prob req oui\n");
2885        return skb;
2886}
2887
2888static struct sk_buff *
2889ath10k_wmi_tlv_op_gen_beacon_dma(struct ath10k *ar, u32 vdev_id,
2890                                 const void *bcn, size_t bcn_len,
2891                                 u32 bcn_paddr, bool dtim_zero,
2892                                 bool deliver_cab)
2893
2894{
2895        struct wmi_bcn_tx_ref_cmd *cmd;
2896        struct wmi_tlv *tlv;
2897        struct sk_buff *skb;
2898        struct ieee80211_hdr *hdr;
2899        u16 fc;
2900
2901        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2902        if (!skb)
2903                return ERR_PTR(-ENOMEM);
2904
2905        hdr = (struct ieee80211_hdr *)bcn;
2906        fc = le16_to_cpu(hdr->frame_control);
2907
2908        tlv = (void *)skb->data;
2909        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_BCN_SEND_FROM_HOST_CMD);
2910        tlv->len = __cpu_to_le16(sizeof(*cmd));
2911        cmd = (void *)tlv->value;
2912        cmd->vdev_id = __cpu_to_le32(vdev_id);
2913        cmd->data_len = __cpu_to_le32(bcn_len);
2914        cmd->data_ptr = __cpu_to_le32(bcn_paddr);
2915        cmd->msdu_id = 0;
2916        cmd->frame_control = __cpu_to_le32(fc);
2917        cmd->flags = 0;
2918
2919        if (dtim_zero)
2920                cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DTIM_ZERO);
2921
2922        if (deliver_cab)
2923                cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DELIVER_CAB);
2924
2925        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv beacon dma\n");
2926        return skb;
2927}
2928
2929static struct sk_buff *
2930ath10k_wmi_tlv_op_gen_pdev_set_wmm(struct ath10k *ar,
2931                                   const struct wmi_wmm_params_all_arg *arg)
2932{
2933        struct wmi_tlv_pdev_set_wmm_cmd *cmd;
2934        struct wmi_wmm_params *wmm;
2935        struct wmi_tlv *tlv;
2936        struct sk_buff *skb;
2937        size_t len;
2938        void *ptr;
2939
2940        len = (sizeof(*tlv) + sizeof(*cmd)) +
2941              (4 * (sizeof(*tlv) + sizeof(*wmm)));
2942        skb = ath10k_wmi_alloc_skb(ar, len);
2943        if (!skb)
2944                return ERR_PTR(-ENOMEM);
2945
2946        ptr = (void *)skb->data;
2947
2948        tlv = ptr;
2949        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_SET_WMM_PARAMS_CMD);
2950        tlv->len = __cpu_to_le16(sizeof(*cmd));
2951        cmd = (void *)tlv->value;
2952
2953        /* nothing to set here */
2954
2955        ptr += sizeof(*tlv);
2956        ptr += sizeof(*cmd);
2957
2958        ptr = ath10k_wmi_tlv_put_wmm(ptr, &arg->ac_be);
2959        ptr = ath10k_wmi_tlv_put_wmm(ptr, &arg->ac_bk);
2960        ptr = ath10k_wmi_tlv_put_wmm(ptr, &arg->ac_vi);
2961        ptr = ath10k_wmi_tlv_put_wmm(ptr, &arg->ac_vo);
2962
2963        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev set wmm\n");
2964        return skb;
2965}
2966
2967static struct sk_buff *
2968ath10k_wmi_tlv_op_gen_request_stats(struct ath10k *ar, u32 stats_mask)
2969{
2970        struct wmi_request_stats_cmd *cmd;
2971        struct wmi_tlv *tlv;
2972        struct sk_buff *skb;
2973
2974        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2975        if (!skb)
2976                return ERR_PTR(-ENOMEM);
2977
2978        tlv = (void *)skb->data;
2979        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_REQUEST_STATS_CMD);
2980        tlv->len = __cpu_to_le16(sizeof(*cmd));
2981        cmd = (void *)tlv->value;
2982        cmd->stats_id = __cpu_to_le32(stats_mask);
2983
2984        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv request stats\n");
2985        return skb;
2986}
2987
2988static struct sk_buff *
2989ath10k_wmi_tlv_op_gen_request_peer_stats_info(struct ath10k *ar,
2990                                              u32 vdev_id,
2991                                              enum wmi_peer_stats_info_request_type type,
2992                                              u8 *addr,
2993                                              u32 reset)
2994{
2995        struct wmi_tlv_request_peer_stats_info *cmd;
2996        struct wmi_tlv *tlv;
2997        struct sk_buff *skb;
2998
2999        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
3000        if (!skb)
3001                return ERR_PTR(-ENOMEM);
3002
3003        tlv = (void *)skb->data;
3004        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_REQUEST_PEER_STATS_INFO_CMD);
3005        tlv->len = __cpu_to_le16(sizeof(*cmd));
3006        cmd = (void *)tlv->value;
3007        cmd->vdev_id = __cpu_to_le32(vdev_id);
3008        cmd->request_type = __cpu_to_le32(type);
3009
3010        if (type == WMI_REQUEST_ONE_PEER_STATS_INFO)
3011                ether_addr_copy(cmd->peer_macaddr.addr, addr);
3012
3013        cmd->reset_after_request = __cpu_to_le32(reset);
3014        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv request peer stats info\n");
3015        return skb;
3016}
3017
3018static int
3019ath10k_wmi_tlv_op_cleanup_mgmt_tx_send(struct ath10k *ar,
3020                                       struct sk_buff *msdu)
3021{
3022        struct ath10k_skb_cb *cb = ATH10K_SKB_CB(msdu);
3023        struct ath10k_wmi *wmi = &ar->wmi;
3024
3025        idr_remove(&wmi->mgmt_pending_tx, cb->msdu_id);
3026
3027        return 0;
3028}
3029
3030static int
3031ath10k_wmi_mgmt_tx_alloc_msdu_id(struct ath10k *ar, struct sk_buff *skb,
3032                                 dma_addr_t paddr)
3033{
3034        struct ath10k_wmi *wmi = &ar->wmi;
3035        struct ath10k_mgmt_tx_pkt_addr *pkt_addr;
3036        int ret;
3037
3038        pkt_addr = kmalloc(sizeof(*pkt_addr), GFP_ATOMIC);
3039        if (!pkt_addr)
3040                return -ENOMEM;
3041
3042        pkt_addr->vaddr = skb;
3043        pkt_addr->paddr = paddr;
3044
3045        spin_lock_bh(&ar->data_lock);
3046        ret = idr_alloc(&wmi->mgmt_pending_tx, pkt_addr, 0,
3047                        wmi->mgmt_max_num_pending_tx, GFP_ATOMIC);
3048        spin_unlock_bh(&ar->data_lock);
3049
3050        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi mgmt tx alloc msdu_id ret %d\n", ret);
3051        return ret;
3052}
3053
3054static struct sk_buff *
3055ath10k_wmi_tlv_op_gen_mgmt_tx_send(struct ath10k *ar, struct sk_buff *msdu,
3056                                   dma_addr_t paddr)
3057{
3058        struct ath10k_skb_cb *cb = ATH10K_SKB_CB(msdu);
3059        struct wmi_tlv_mgmt_tx_cmd *cmd;
3060        struct ieee80211_hdr *hdr;
3061        struct ath10k_vif *arvif;
3062        u32 buf_len = msdu->len;
3063        struct wmi_tlv *tlv;
3064        struct sk_buff *skb;
3065        int len, desc_id;
3066        u32 vdev_id;
3067        void *ptr;
3068
3069        if (!cb->vif)
3070                return ERR_PTR(-EINVAL);
3071
3072        hdr = (struct ieee80211_hdr *)msdu->data;
3073        arvif = (void *)cb->vif->drv_priv;
3074        vdev_id = arvif->vdev_id;
3075
3076        if (WARN_ON_ONCE(!ieee80211_is_mgmt(hdr->frame_control) &&
3077                         (!(ieee80211_is_nullfunc(hdr->frame_control) ||
3078                         ieee80211_is_qos_nullfunc(hdr->frame_control)))))
3079                return ERR_PTR(-EINVAL);
3080
3081        len = sizeof(*cmd) + 2 * sizeof(*tlv);
3082
3083        if ((ieee80211_is_action(hdr->frame_control) ||
3084             ieee80211_is_deauth(hdr->frame_control) ||
3085             ieee80211_is_disassoc(hdr->frame_control)) &&
3086             ieee80211_has_protected(hdr->frame_control)) {
3087                skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
3088                buf_len += IEEE80211_CCMP_MIC_LEN;
3089        }
3090
3091        buf_len = min_t(u32, buf_len, WMI_TLV_MGMT_TX_FRAME_MAX_LEN);
3092        buf_len = round_up(buf_len, 4);
3093
3094        len += buf_len;
3095        len = round_up(len, 4);
3096        skb = ath10k_wmi_alloc_skb(ar, len);
3097        if (!skb)
3098                return ERR_PTR(-ENOMEM);
3099
3100        desc_id = ath10k_wmi_mgmt_tx_alloc_msdu_id(ar, msdu, paddr);
3101        if (desc_id < 0)
3102                goto err_free_skb;
3103
3104        cb->msdu_id = desc_id;
3105
3106        ptr = (void *)skb->data;
3107        tlv = ptr;
3108        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_MGMT_TX_CMD);
3109        tlv->len = __cpu_to_le16(sizeof(*cmd));
3110        cmd = (void *)tlv->value;
3111        cmd->vdev_id = __cpu_to_le32(vdev_id);
3112        cmd->desc_id = __cpu_to_le32(desc_id);
3113        cmd->chanfreq = 0;
3114        cmd->buf_len = __cpu_to_le32(buf_len);
3115        cmd->frame_len = __cpu_to_le32(msdu->len);
3116        cmd->paddr = __cpu_to_le64(paddr);
3117
3118        ptr += sizeof(*tlv);
3119        ptr += sizeof(*cmd);
3120
3121        tlv = ptr;
3122        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
3123        tlv->len = __cpu_to_le16(buf_len);
3124
3125        ptr += sizeof(*tlv);
3126        memcpy(ptr, msdu->data, buf_len);
3127
3128        return skb;
3129
3130err_free_skb:
3131        dev_kfree_skb(skb);
3132        return ERR_PTR(desc_id);
3133}
3134
3135static struct sk_buff *
3136ath10k_wmi_tlv_op_gen_force_fw_hang(struct ath10k *ar,
3137                                    enum wmi_force_fw_hang_type type,
3138                                    u32 delay_ms)
3139{
3140        struct wmi_force_fw_hang_cmd *cmd;
3141        struct wmi_tlv *tlv;
3142        struct sk_buff *skb;
3143
3144        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
3145        if (!skb)
3146                return ERR_PTR(-ENOMEM);
3147
3148        tlv = (void *)skb->data;
3149        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_FORCE_FW_HANG_CMD);
3150        tlv->len = __cpu_to_le16(sizeof(*cmd));
3151        cmd = (void *)tlv->value;
3152        cmd->type = __cpu_to_le32(type);
3153        cmd->delay_ms = __cpu_to_le32(delay_ms);
3154
3155        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv force fw hang\n");
3156        return skb;
3157}
3158
3159static struct sk_buff *
3160ath10k_wmi_tlv_op_gen_dbglog_cfg(struct ath10k *ar, u64 module_enable,
3161                                 u32 log_level)
3162{
3163        struct wmi_tlv_dbglog_cmd *cmd;
3164        struct wmi_tlv *tlv;
3165        struct sk_buff *skb;
3166        size_t len, bmap_len;
3167        u32 value;
3168        void *ptr;
3169
3170        if (module_enable) {
3171                value = WMI_TLV_DBGLOG_LOG_LEVEL_VALUE(
3172                                module_enable,
3173                                WMI_TLV_DBGLOG_LOG_LEVEL_VERBOSE);
3174        } else {
3175                value = WMI_TLV_DBGLOG_LOG_LEVEL_VALUE(
3176                                WMI_TLV_DBGLOG_ALL_MODULES,
3177                                WMI_TLV_DBGLOG_LOG_LEVEL_WARN);
3178        }
3179
3180        bmap_len = 0;
3181        len = sizeof(*tlv) + sizeof(*cmd) + sizeof(*tlv) + bmap_len;
3182        skb = ath10k_wmi_alloc_skb(ar, len);
3183        if (!skb)
3184                return ERR_PTR(-ENOMEM);
3185
3186        ptr = (void *)skb->data;
3187
3188        tlv = ptr;
3189        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_DEBUG_LOG_CONFIG_CMD);
3190        tlv->len = __cpu_to_le16(sizeof(*cmd));
3191        cmd = (void *)tlv->value;
3192        cmd->param = __cpu_to_le32(WMI_TLV_DBGLOG_PARAM_LOG_LEVEL);
3193        cmd->value = __cpu_to_le32(value);
3194
3195        ptr += sizeof(*tlv);
3196        ptr += sizeof(*cmd);
3197
3198        tlv = ptr;
3199        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
3200        tlv->len = __cpu_to_le16(bmap_len);
3201
3202        /* nothing to do here */
3203
3204        ptr += sizeof(*tlv);
3205        ptr += sizeof(bmap_len);
3206
3207        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv dbglog value 0x%08x\n", value);
3208        return skb;
3209}
3210
3211static struct sk_buff *
3212ath10k_wmi_tlv_op_gen_pktlog_enable(struct ath10k *ar, u32 filter)
3213{
3214        struct wmi_tlv_pktlog_enable *cmd;
3215        struct wmi_tlv *tlv;
3216        struct sk_buff *skb;
3217        void *ptr;
3218        size_t len;
3219
3220        len = sizeof(*tlv) + sizeof(*cmd);
3221        skb = ath10k_wmi_alloc_skb(ar, len);
3222        if (!skb)
3223                return ERR_PTR(-ENOMEM);
3224
3225        ptr = (void *)skb->data;
3226        tlv = ptr;
3227        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_PKTLOG_ENABLE_CMD);
3228        tlv->len = __cpu_to_le16(sizeof(*cmd));
3229        cmd = (void *)tlv->value;
3230        cmd->filter = __cpu_to_le32(filter);
3231
3232        ptr += sizeof(*tlv);
3233        ptr += sizeof(*cmd);
3234
3235        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pktlog enable filter 0x%08x\n",
3236                   filter);
3237        return skb;
3238}
3239
3240static struct sk_buff *
3241ath10k_wmi_tlv_op_gen_pdev_get_temperature(struct ath10k *ar)
3242{
3243        struct wmi_tlv_pdev_get_temp_cmd *cmd;
3244        struct wmi_tlv *tlv;
3245        struct sk_buff *skb;
3246
3247        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
3248        if (!skb)
3249                return ERR_PTR(-ENOMEM);
3250
3251        tlv = (void *)skb->data;
3252        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_GET_TEMPERATURE_CMD);
3253        tlv->len = __cpu_to_le16(sizeof(*cmd));
3254        cmd = (void *)tlv->value;
3255        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev get temperature tlv\n");
3256        return skb;
3257}
3258
3259static struct sk_buff *
3260ath10k_wmi_tlv_op_gen_pktlog_disable(struct ath10k *ar)
3261{
3262        struct wmi_tlv_pktlog_disable *cmd;
3263        struct wmi_tlv *tlv;
3264        struct sk_buff *skb;
3265        void *ptr;
3266        size_t len;
3267
3268        len = sizeof(*tlv) + sizeof(*cmd);
3269        skb = ath10k_wmi_alloc_skb(ar, len);
3270        if (!skb)
3271                return ERR_PTR(-ENOMEM);
3272
3273        ptr = (void *)skb->data;
3274        tlv = ptr;
3275        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_PKTLOG_DISABLE_CMD);
3276        tlv->len = __cpu_to_le16(sizeof(*cmd));
3277        cmd = (void *)tlv->value;
3278
3279        ptr += sizeof(*tlv);
3280        ptr += sizeof(*cmd);
3281
3282        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pktlog disable\n");
3283        return skb;
3284}
3285
3286static struct sk_buff *
3287ath10k_wmi_tlv_op_gen_bcn_tmpl(struct ath10k *ar, u32 vdev_id,
3288                               u32 tim_ie_offset, struct sk_buff *bcn,
3289                               u32 prb_caps, u32 prb_erp, void *prb_ies,
3290                               size_t prb_ies_len)
3291{
3292        struct wmi_tlv_bcn_tmpl_cmd *cmd;
3293        struct wmi_tlv_bcn_prb_info *info;
3294        struct wmi_tlv *tlv;
3295        struct sk_buff *skb;
3296        void *ptr;
3297        size_t len;
3298
3299        if (WARN_ON(prb_ies_len > 0 && !prb_ies))
3300                return ERR_PTR(-EINVAL);
3301
3302        len = sizeof(*tlv) + sizeof(*cmd) +
3303              sizeof(*tlv) + sizeof(*info) + prb_ies_len +
3304              sizeof(*tlv) + roundup(bcn->len, 4);
3305        skb = ath10k_wmi_alloc_skb(ar, len);
3306        if (!skb)
3307                return ERR_PTR(-ENOMEM);
3308
3309        ptr = (void *)skb->data;
3310        tlv = ptr;
3311        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_BCN_TMPL_CMD);
3312        tlv->len = __cpu_to_le16(sizeof(*cmd));
3313        cmd = (void *)tlv->value;
3314        cmd->vdev_id = __cpu_to_le32(vdev_id);
3315        cmd->tim_ie_offset = __cpu_to_le32(tim_ie_offset);
3316        cmd->buf_len = __cpu_to_le32(bcn->len);
3317
3318        ptr += sizeof(*tlv);
3319        ptr += sizeof(*cmd);
3320
3321        /* FIXME: prb_ies_len should be probably aligned to 4byte boundary but
3322         * then it is then impossible to pass original ie len.
3323         * This chunk is not used yet so if setting probe resp template yields
3324         * problems with beaconing or crashes firmware look here.
3325         */
3326        tlv = ptr;
3327        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_BCN_PRB_INFO);
3328        tlv->len = __cpu_to_le16(sizeof(*info) + prb_ies_len);
3329        info = (void *)tlv->value;
3330        info->caps = __cpu_to_le32(prb_caps);
3331        info->erp = __cpu_to_le32(prb_erp);
3332        memcpy(info->ies, prb_ies, prb_ies_len);
3333
3334        ptr += sizeof(*tlv);
3335        ptr += sizeof(*info);
3336        ptr += prb_ies_len;
3337
3338        tlv = ptr;
3339        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
3340        tlv->len = __cpu_to_le16(roundup(bcn->len, 4));
3341        memcpy(tlv->value, bcn->data, bcn->len);
3342
3343        /* FIXME: Adjust TSF? */
3344
3345        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv bcn tmpl vdev_id %i\n",
3346                   vdev_id);
3347        return skb;
3348}
3349
3350static struct sk_buff *
3351ath10k_wmi_tlv_op_gen_prb_tmpl(struct ath10k *ar, u32 vdev_id,
3352                               struct sk_buff *prb)
3353{
3354        struct wmi_tlv_prb_tmpl_cmd *cmd;
3355        struct wmi_tlv_bcn_prb_info *info;
3356        struct wmi_tlv *tlv;
3357        struct sk_buff *skb;
3358        void *ptr;
3359        size_t len;
3360
3361        len = sizeof(*tlv) + sizeof(*cmd) +
3362              sizeof(*tlv) + sizeof(*info) +
3363              sizeof(*tlv) + roundup(prb->len, 4);
3364        skb = ath10k_wmi_alloc_skb(ar, len);
3365        if (!skb)
3366                return ERR_PTR(-ENOMEM);
3367
3368        ptr = (void *)skb->data;
3369        tlv = ptr;
3370        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PRB_TMPL_CMD);
3371        tlv->len = __cpu_to_le16(sizeof(*cmd));
3372        cmd = (void *)tlv->value;
3373        cmd->vdev_id = __cpu_to_le32(vdev_id);
3374        cmd->buf_len = __cpu_to_le32(prb->len);
3375
3376        ptr += sizeof(*tlv);
3377        ptr += sizeof(*cmd);
3378
3379        tlv = ptr;
3380        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_BCN_PRB_INFO);
3381        tlv->len = __cpu_to_le16(sizeof(*info));
3382        info = (void *)tlv->value;
3383        info->caps = 0;
3384        info->erp = 0;
3385
3386        ptr += sizeof(*tlv);
3387        ptr += sizeof(*info);
3388
3389        tlv = ptr;
3390        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
3391        tlv->len = __cpu_to_le16(roundup(prb->len, 4));
3392        memcpy(tlv->value, prb->data, prb->len);
3393
3394        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv prb tmpl vdev_id %i\n",
3395                   vdev_id);
3396        return skb;
3397}
3398
3399static struct sk_buff *
3400ath10k_wmi_tlv_op_gen_p2p_go_bcn_ie(struct ath10k *ar, u32 vdev_id,
3401                                    const u8 *p2p_ie)
3402{
3403        struct wmi_tlv_p2p_go_bcn_ie *cmd;
3404        struct wmi_tlv *tlv;
3405        struct sk_buff *skb;
3406        void *ptr;
3407        size_t len;
3408
3409        len = sizeof(*tlv) + sizeof(*cmd) +
3410              sizeof(*tlv) + roundup(p2p_ie[1] + 2, 4);
3411        skb = ath10k_wmi_alloc_skb(ar, len);
3412        if (!skb)
3413                return ERR_PTR(-ENOMEM);
3414
3415        ptr = (void *)skb->data;
3416        tlv = ptr;
3417        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_P2P_GO_SET_BEACON_IE);
3418        tlv->len = __cpu_to_le16(sizeof(*cmd));
3419        cmd = (void *)tlv->value;
3420        cmd->vdev_id = __cpu_to_le32(vdev_id);
3421        cmd->ie_len = __cpu_to_le32(p2p_ie[1] + 2);
3422
3423        ptr += sizeof(*tlv);
3424        ptr += sizeof(*cmd);
3425
3426        tlv = ptr;
3427        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
3428        tlv->len = __cpu_to_le16(roundup(p2p_ie[1] + 2, 4));
3429        memcpy(tlv->value, p2p_ie, p2p_ie[1] + 2);
3430
3431        ptr += sizeof(*tlv);
3432        ptr += roundup(p2p_ie[1] + 2, 4);
3433
3434        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv p2p go bcn ie for vdev %i\n",
3435                   vdev_id);
3436        return skb;
3437}
3438
3439static struct sk_buff *
3440ath10k_wmi_tlv_op_gen_update_fw_tdls_state(struct ath10k *ar, u32 vdev_id,
3441                                           enum wmi_tdls_state state)
3442{
3443        struct wmi_tdls_set_state_cmd *cmd;
3444        struct wmi_tlv *tlv;
3445        struct sk_buff *skb;
3446        void *ptr;
3447        size_t len;
3448        /* Set to options from wmi_tlv_tdls_options,
3449         * for now none of them are enabled.
3450         */
3451        u32 options = 0;
3452
3453        if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA, ar->wmi.svc_map))
3454                options |=  WMI_TLV_TDLS_BUFFER_STA_EN;
3455
3456        /* WMI_TDLS_ENABLE_ACTIVE_EXTERNAL_CONTROL means firm will handle TDLS
3457         * link inactivity detecting logic.
3458         */
3459        if (state == WMI_TDLS_ENABLE_ACTIVE)
3460                state = WMI_TDLS_ENABLE_ACTIVE_EXTERNAL_CONTROL;
3461
3462        len = sizeof(*tlv) + sizeof(*cmd);
3463        skb = ath10k_wmi_alloc_skb(ar, len);
3464        if (!skb)
3465                return ERR_PTR(-ENOMEM);
3466
3467        ptr = (void *)skb->data;
3468        tlv = ptr;
3469        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_TDLS_SET_STATE_CMD);
3470        tlv->len = __cpu_to_le16(sizeof(*cmd));
3471
3472        cmd = (void *)tlv->value;
3473        cmd->vdev_id = __cpu_to_le32(vdev_id);
3474        cmd->state = __cpu_to_le32(state);
3475        cmd->notification_interval_ms = __cpu_to_le32(5000);
3476        cmd->tx_discovery_threshold = __cpu_to_le32(100);
3477        cmd->tx_teardown_threshold = __cpu_to_le32(5);
3478        cmd->rssi_teardown_threshold = __cpu_to_le32(-75);
3479        cmd->rssi_delta = __cpu_to_le32(-20);
3480        cmd->tdls_options = __cpu_to_le32(options);
3481        cmd->tdls_peer_traffic_ind_window = __cpu_to_le32(2);
3482        cmd->tdls_peer_traffic_response_timeout_ms = __cpu_to_le32(5000);
3483        cmd->tdls_puapsd_mask = __cpu_to_le32(0xf);
3484        cmd->tdls_puapsd_inactivity_time_ms = __cpu_to_le32(0);
3485        cmd->tdls_puapsd_rx_frame_threshold = __cpu_to_le32(10);
3486
3487        ptr += sizeof(*tlv);
3488        ptr += sizeof(*cmd);
3489
3490        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv update fw tdls state %d for vdev %i\n",
3491                   state, vdev_id);
3492        return skb;
3493}
3494
3495static u32 ath10k_wmi_tlv_prepare_peer_qos(u8 uapsd_queues, u8 sp)
3496{
3497        u32 peer_qos = 0;
3498
3499        if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
3500                peer_qos |= WMI_TLV_TDLS_PEER_QOS_AC_VO;
3501        if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
3502                peer_qos |= WMI_TLV_TDLS_PEER_QOS_AC_VI;
3503        if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
3504                peer_qos |= WMI_TLV_TDLS_PEER_QOS_AC_BK;
3505        if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
3506                peer_qos |= WMI_TLV_TDLS_PEER_QOS_AC_BE;
3507
3508        peer_qos |= SM(sp, WMI_TLV_TDLS_PEER_SP);
3509
3510        return peer_qos;
3511}
3512
3513static struct sk_buff *
3514ath10k_wmi_tlv_op_gen_tdls_peer_update(struct ath10k *ar,
3515                                       const struct wmi_tdls_peer_update_cmd_arg *arg,
3516                                       const struct wmi_tdls_peer_capab_arg *cap,
3517                                       const struct wmi_channel_arg *chan_arg)
3518{
3519        struct wmi_tdls_peer_update_cmd *cmd;
3520        struct wmi_tdls_peer_capab *peer_cap;
3521        struct wmi_channel *chan;
3522        struct wmi_tlv *tlv;
3523        struct sk_buff *skb;
3524        u32 peer_qos;
3525        void *ptr;
3526        int len;
3527        int i;
3528
3529        len = sizeof(*tlv) + sizeof(*cmd) +
3530              sizeof(*tlv) + sizeof(*peer_cap) +
3531              sizeof(*tlv) + cap->peer_chan_len * sizeof(*chan);
3532
3533        skb = ath10k_wmi_alloc_skb(ar, len);
3534        if (!skb)
3535                return ERR_PTR(-ENOMEM);
3536
3537        ptr = (void *)skb->data;
3538        tlv = ptr;
3539        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_TDLS_PEER_UPDATE_CMD);
3540        tlv->len = __cpu_to_le16(sizeof(*cmd));
3541
3542        cmd = (void *)tlv->value;
3543        cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3544        ether_addr_copy(cmd->peer_macaddr.addr, arg->addr);
3545        cmd->peer_state = __cpu_to_le32(arg->peer_state);
3546
3547        ptr += sizeof(*tlv);
3548        ptr += sizeof(*cmd);
3549
3550        tlv = ptr;
3551        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_TDLS_PEER_CAPABILITIES);
3552        tlv->len = __cpu_to_le16(sizeof(*peer_cap));
3553        peer_cap = (void *)tlv->value;
3554        peer_qos = ath10k_wmi_tlv_prepare_peer_qos(cap->peer_uapsd_queues,
3555                                                   cap->peer_max_sp);
3556        peer_cap->peer_qos = __cpu_to_le32(peer_qos);
3557        peer_cap->buff_sta_support = __cpu_to_le32(cap->buff_sta_support);
3558        peer_cap->off_chan_support = __cpu_to_le32(cap->off_chan_support);
3559        peer_cap->peer_curr_operclass = __cpu_to_le32(cap->peer_curr_operclass);
3560        peer_cap->self_curr_operclass = __cpu_to_le32(cap->self_curr_operclass);
3561        peer_cap->peer_chan_len = __cpu_to_le32(cap->peer_chan_len);
3562        peer_cap->peer_operclass_len = __cpu_to_le32(cap->peer_operclass_len);
3563
3564        for (i = 0; i < WMI_TDLS_MAX_SUPP_OPER_CLASSES; i++)
3565                peer_cap->peer_operclass[i] = cap->peer_operclass[i];
3566
3567        peer_cap->is_peer_responder = __cpu_to_le32(cap->is_peer_responder);
3568        peer_cap->pref_offchan_num = __cpu_to_le32(cap->pref_offchan_num);
3569        peer_cap->pref_offchan_bw = __cpu_to_le32(cap->pref_offchan_bw);
3570
3571        ptr += sizeof(*tlv);
3572        ptr += sizeof(*peer_cap);
3573
3574        tlv = ptr;
3575        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
3576        tlv->len = __cpu_to_le16(cap->peer_chan_len * sizeof(*chan));
3577
3578        ptr += sizeof(*tlv);
3579
3580        for (i = 0; i < cap->peer_chan_len; i++) {
3581                tlv = ptr;
3582                tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_CHANNEL);
3583                tlv->len = __cpu_to_le16(sizeof(*chan));
3584                chan = (void *)tlv->value;
3585                ath10k_wmi_put_wmi_channel(ar, chan, &chan_arg[i]);
3586
3587                ptr += sizeof(*tlv);
3588                ptr += sizeof(*chan);
3589        }
3590
3591        ath10k_dbg(ar, ATH10K_DBG_WMI,
3592                   "wmi tlv tdls peer update vdev %i state %d n_chans %u\n",
3593                   arg->vdev_id, arg->peer_state, cap->peer_chan_len);
3594        return skb;
3595}
3596
3597static struct sk_buff *
3598ath10k_wmi_tlv_op_gen_pdev_set_quiet_mode(struct ath10k *ar, u32 period,
3599                                          u32 duration, u32 next_offset,
3600                                          u32 enabled)
3601{
3602        struct wmi_tlv_set_quiet_cmd *cmd;
3603        struct wmi_tlv *tlv;
3604        struct sk_buff *skb;
3605
3606        skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
3607        if (!skb)
3608                return ERR_PTR(-ENOMEM);
3609
3610        tlv = (void *)skb->data;
3611        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_SET_QUIET_CMD);
3612        tlv->len = __cpu_to_le16(sizeof(*cmd));
3613        cmd = (void *)tlv->value;
3614
3615        /* vdev_id is not in use, set to 0 */
3616        cmd->vdev_id = __cpu_to_le32(0);
3617        cmd->period = __cpu_to_le32(period);
3618        cmd->duration = __cpu_to_le32(duration);
3619        cmd->next_start = __cpu_to_le32(next_offset);
3620        cmd->enabled = __cpu_to_le32(enabled);
3621
3622        ath10k_dbg(ar, ATH10K_DBG_WMI,
3623                   "wmi tlv quiet param: period %u duration %u enabled %d\n",
3624                   period, duration, enabled);
3625        return skb;
3626}
3627
3628static struct sk_buff *
3629ath10k_wmi_tlv_op_gen_wow_enable(struct ath10k *ar)
3630{
3631        struct wmi_tlv_wow_enable_cmd *cmd;
3632        struct wmi_tlv *tlv;
3633        struct sk_buff *skb;
3634        size_t len;
3635
3636        len = sizeof(*tlv) + sizeof(*cmd);
3637        skb = ath10k_wmi_alloc_skb(ar, len);
3638        if (!skb)
3639                return ERR_PTR(-ENOMEM);
3640
3641        tlv = (struct wmi_tlv *)skb->data;
3642        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_ENABLE_CMD);
3643        tlv->len = __cpu_to_le16(sizeof(*cmd));
3644        cmd = (void *)tlv->value;
3645
3646        cmd->enable = __cpu_to_le32(1);
3647        if (!ar->bus_param.link_can_suspend)
3648                cmd->pause_iface_config = __cpu_to_le32(WOW_IFACE_PAUSE_DISABLED);
3649
3650        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow enable\n");
3651        return skb;
3652}
3653
3654static struct sk_buff *
3655ath10k_wmi_tlv_op_gen_wow_add_wakeup_event(struct ath10k *ar,
3656                                           u32 vdev_id,
3657                                           enum wmi_wow_wakeup_event event,
3658                                           u32 enable)
3659{
3660        struct wmi_tlv_wow_add_del_event_cmd *cmd;
3661        struct wmi_tlv *tlv;
3662        struct sk_buff *skb;
3663        size_t len;
3664
3665        len = sizeof(*tlv) + sizeof(*cmd);
3666        skb = ath10k_wmi_alloc_skb(ar, len);
3667        if (!skb)
3668                return ERR_PTR(-ENOMEM);
3669
3670        tlv = (struct wmi_tlv *)skb->data;
3671        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_ADD_DEL_EVT_CMD);
3672        tlv->len = __cpu_to_le16(sizeof(*cmd));
3673        cmd = (void *)tlv->value;
3674
3675        cmd->vdev_id = __cpu_to_le32(vdev_id);
3676        cmd->is_add = __cpu_to_le32(enable);
3677        cmd->event_bitmap = __cpu_to_le32(1 << event);
3678
3679        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow add wakeup event %s enable %d vdev_id %d\n",
3680                   wow_wakeup_event(event), enable, vdev_id);
3681        return skb;
3682}
3683
3684static struct sk_buff *
3685ath10k_wmi_tlv_gen_wow_host_wakeup_ind(struct ath10k *ar)
3686{
3687        struct wmi_tlv_wow_host_wakeup_ind *cmd;
3688        struct wmi_tlv *tlv;
3689        struct sk_buff *skb;
3690        size_t len;
3691
3692        len = sizeof(*tlv) + sizeof(*cmd);
3693        skb = ath10k_wmi_alloc_skb(ar, len);
3694        if (!skb)
3695                return ERR_PTR(-ENOMEM);
3696
3697        tlv = (struct wmi_tlv *)skb->data;
3698        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_HOSTWAKEUP_FROM_SLEEP_CMD);
3699        tlv->len = __cpu_to_le16(sizeof(*cmd));
3700        cmd = (void *)tlv->value;
3701
3702        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow host wakeup ind\n");
3703        return skb;
3704}
3705
3706static struct sk_buff *
3707ath10k_wmi_tlv_op_gen_wow_add_pattern(struct ath10k *ar, u32 vdev_id,
3708                                      u32 pattern_id, const u8 *pattern,
3709                                      const u8 *bitmask, int pattern_len,
3710                                      int pattern_offset)
3711{
3712        struct wmi_tlv_wow_add_pattern_cmd *cmd;
3713        struct wmi_tlv_wow_bitmap_pattern *bitmap;
3714        struct wmi_tlv *tlv;
3715        struct sk_buff *skb;
3716        void *ptr;
3717        size_t len;
3718
3719        len = sizeof(*tlv) + sizeof(*cmd) +
3720              sizeof(*tlv) +                    /* array struct */
3721              sizeof(*tlv) + sizeof(*bitmap) +  /* bitmap */
3722              sizeof(*tlv) +                    /* empty ipv4 sync */
3723              sizeof(*tlv) +                    /* empty ipv6 sync */
3724              sizeof(*tlv) +                    /* empty magic */
3725              sizeof(*tlv) +                    /* empty info timeout */
3726              sizeof(*tlv) + sizeof(u32);       /* ratelimit interval */
3727
3728        skb = ath10k_wmi_alloc_skb(ar, len);
3729        if (!skb)
3730                return ERR_PTR(-ENOMEM);
3731
3732        /* cmd */
3733        ptr = (void *)skb->data;
3734        tlv = ptr;
3735        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_ADD_PATTERN_CMD);
3736        tlv->len = __cpu_to_le16(sizeof(*cmd));
3737        cmd = (void *)tlv->value;
3738
3739        cmd->vdev_id = __cpu_to_le32(vdev_id);
3740        cmd->pattern_id = __cpu_to_le32(pattern_id);
3741        cmd->pattern_type = __cpu_to_le32(WOW_BITMAP_PATTERN);
3742
3743        ptr += sizeof(*tlv);
3744        ptr += sizeof(*cmd);
3745
3746        /* bitmap */
3747        tlv = ptr;
3748        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
3749        tlv->len = __cpu_to_le16(sizeof(*tlv) + sizeof(*bitmap));
3750
3751        ptr += sizeof(*tlv);
3752
3753        tlv = ptr;
3754        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_BITMAP_PATTERN_T);
3755        tlv->len = __cpu_to_le16(sizeof(*bitmap));
3756        bitmap = (void *)tlv->value;
3757
3758        memcpy(bitmap->patternbuf, pattern, pattern_len);
3759        memcpy(bitmap->bitmaskbuf, bitmask, pattern_len);
3760        bitmap->pattern_offset = __cpu_to_le32(pattern_offset);
3761        bitmap->pattern_len = __cpu_to_le32(pattern_len);
3762        bitmap->bitmask_len = __cpu_to_le32(pattern_len);
3763        bitmap->pattern_id = __cpu_to_le32(pattern_id);
3764
3765        ptr += sizeof(*tlv);
3766        ptr += sizeof(*bitmap);
3767
3768        /* ipv4 sync */
3769        tlv = ptr;
3770        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
3771        tlv->len = __cpu_to_le16(0);
3772
3773        ptr += sizeof(*tlv);
3774
3775        /* ipv6 sync */
3776        tlv = ptr;
3777        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
3778        tlv->len = __cpu_to_le16(0);
3779
3780        ptr += sizeof(*tlv);
3781
3782        /* magic */
3783        tlv = ptr;
3784        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
3785        tlv->len = __cpu_to_le16(0);
3786
3787        ptr += sizeof(*tlv);
3788
3789        /* pattern info timeout */
3790        tlv = ptr;
3791        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
3792        tlv->len = __cpu_to_le16(0);
3793
3794        ptr += sizeof(*tlv);
3795
3796        /* ratelimit interval */
3797        tlv = ptr;
3798        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
3799        tlv->len = __cpu_to_le16(sizeof(u32));
3800
3801        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow add pattern vdev_id %d pattern_id %d, pattern_offset %d\n",
3802                   vdev_id, pattern_id, pattern_offset);
3803        return skb;
3804}
3805
3806static struct sk_buff *
3807ath10k_wmi_tlv_op_gen_wow_del_pattern(struct ath10k *ar, u32 vdev_id,
3808                                      u32 pattern_id)
3809{
3810        struct wmi_tlv_wow_del_pattern_cmd *cmd;
3811        struct wmi_tlv *tlv;
3812        struct sk_buff *skb;
3813        size_t len;
3814
3815        len = sizeof(*tlv) + sizeof(*cmd);
3816        skb = ath10k_wmi_alloc_skb(ar, len);
3817        if (!skb)
3818                return ERR_PTR(-ENOMEM);
3819
3820        tlv = (struct wmi_tlv *)skb->data;
3821        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_DEL_PATTERN_CMD);
3822        tlv->len = __cpu_to_le16(sizeof(*cmd));
3823        cmd = (void *)tlv->value;
3824
3825        cmd->vdev_id = __cpu_to_le32(vdev_id);
3826        cmd->pattern_id = __cpu_to_le32(pattern_id);
3827        cmd->pattern_type = __cpu_to_le32(WOW_BITMAP_PATTERN);
3828
3829        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow del pattern vdev_id %d pattern_id %d\n",
3830                   vdev_id, pattern_id);
3831        return skb;
3832}
3833
3834/* Request FW to start PNO operation */
3835static struct sk_buff *
3836ath10k_wmi_tlv_op_gen_config_pno_start(struct ath10k *ar,
3837                                       u32 vdev_id,
3838                                       struct wmi_pno_scan_req *pno)
3839{
3840        struct nlo_configured_parameters *nlo_list;
3841        struct wmi_tlv_wow_nlo_config_cmd *cmd;
3842        struct wmi_tlv *tlv;
3843        struct sk_buff *skb;
3844        __le32 *channel_list;
3845        u16 tlv_len;
3846        size_t len;
3847        void *ptr;
3848        u32 i;
3849
3850        len = sizeof(*tlv) + sizeof(*cmd) +
3851              sizeof(*tlv) +
3852              /* TLV place holder for array of structures
3853               * nlo_configured_parameters(nlo_list)
3854               */
3855              sizeof(*tlv);
3856              /* TLV place holder for array of uint32 channel_list */
3857
3858        len += sizeof(u32) * min_t(u8, pno->a_networks[0].channel_count,
3859                                   WMI_NLO_MAX_CHAN);
3860        len += sizeof(struct nlo_configured_parameters) *
3861                                min_t(u8, pno->uc_networks_count, WMI_NLO_MAX_SSIDS);
3862
3863        skb = ath10k_wmi_alloc_skb(ar, len);
3864        if (!skb)
3865                return ERR_PTR(-ENOMEM);
3866
3867        ptr = (void *)skb->data;
3868        tlv = ptr;
3869        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_NLO_CONFIG_CMD);
3870        tlv->len = __cpu_to_le16(sizeof(*cmd));
3871        cmd = (void *)tlv->value;
3872
3873        /* wmi_tlv_wow_nlo_config_cmd parameters*/
3874        cmd->vdev_id = __cpu_to_le32(pno->vdev_id);
3875        cmd->flags = __cpu_to_le32(WMI_NLO_CONFIG_START | WMI_NLO_CONFIG_SSID_HIDE_EN);
3876
3877        /* current FW does not support min-max range for dwell time */
3878        cmd->active_dwell_time = __cpu_to_le32(pno->active_max_time);
3879        cmd->passive_dwell_time = __cpu_to_le32(pno->passive_max_time);
3880
3881        if (pno->do_passive_scan)
3882                cmd->flags |= __cpu_to_le32(WMI_NLO_CONFIG_SCAN_PASSIVE);
3883
3884        /* copy scan interval */
3885        cmd->fast_scan_period = __cpu_to_le32(pno->fast_scan_period);
3886        cmd->slow_scan_period = __cpu_to_le32(pno->slow_scan_period);
3887        cmd->fast_scan_max_cycles = __cpu_to_le32(pno->fast_scan_max_cycles);
3888        cmd->delay_start_time = __cpu_to_le32(pno->delay_start_time);
3889
3890        if (pno->enable_pno_scan_randomization) {
3891                cmd->flags |= __cpu_to_le32(WMI_NLO_CONFIG_SPOOFED_MAC_IN_PROBE_REQ |
3892                                WMI_NLO_CONFIG_RANDOM_SEQ_NO_IN_PROBE_REQ);
3893                ether_addr_copy(cmd->mac_addr.addr, pno->mac_addr);
3894                ether_addr_copy(cmd->mac_mask.addr, pno->mac_addr_mask);
3895        }
3896
3897        ptr += sizeof(*tlv);
3898        ptr += sizeof(*cmd);
3899
3900        /* nlo_configured_parameters(nlo_list) */
3901        cmd->no_of_ssids = __cpu_to_le32(min_t(u8, pno->uc_networks_count,
3902                                               WMI_NLO_MAX_SSIDS));
3903        tlv_len = __le32_to_cpu(cmd->no_of_ssids) *
3904                sizeof(struct nlo_configured_parameters);
3905
3906        tlv = ptr;
3907        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
3908        tlv->len = __cpu_to_le16(tlv_len);
3909
3910        ptr += sizeof(*tlv);
3911        nlo_list = ptr;
3912        for (i = 0; i < __le32_to_cpu(cmd->no_of_ssids); i++) {
3913                tlv = (struct wmi_tlv *)(&nlo_list[i].tlv_header);
3914                tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
3915                tlv->len = __cpu_to_le16(sizeof(struct nlo_configured_parameters) -
3916                                         sizeof(*tlv));
3917
3918                /* copy ssid and it's length */
3919                nlo_list[i].ssid.valid = __cpu_to_le32(true);
3920                nlo_list[i].ssid.ssid.ssid_len = pno->a_networks[i].ssid.ssid_len;
3921                memcpy(nlo_list[i].ssid.ssid.ssid,
3922                       pno->a_networks[i].ssid.ssid,
3923                       __le32_to_cpu(nlo_list[i].ssid.ssid.ssid_len));
3924
3925                /* copy rssi threshold */
3926                if (pno->a_networks[i].rssi_threshold &&
3927                    pno->a_networks[i].rssi_threshold > -300) {
3928                        nlo_list[i].rssi_cond.valid = __cpu_to_le32(true);
3929                        nlo_list[i].rssi_cond.rssi =
3930                                __cpu_to_le32(pno->a_networks[i].rssi_threshold);
3931                }
3932
3933                nlo_list[i].bcast_nw_type.valid = __cpu_to_le32(true);
3934                nlo_list[i].bcast_nw_type.bcast_nw_type =
3935                        __cpu_to_le32(pno->a_networks[i].bcast_nw_type);
3936        }
3937
3938        ptr += __le32_to_cpu(cmd->no_of_ssids) * sizeof(struct nlo_configured_parameters);
3939
3940        /* copy channel info */
3941        cmd->num_of_channels = __cpu_to_le32(min_t(u8,
3942                                                   pno->a_networks[0].channel_count,
3943                                                   WMI_NLO_MAX_CHAN));
3944
3945        tlv = ptr;
3946        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
3947        tlv->len = __cpu_to_le16(__le32_to_cpu(cmd->num_of_channels) *
3948                                 sizeof(u_int32_t));
3949        ptr += sizeof(*tlv);
3950
3951        channel_list = (__le32 *)ptr;
3952        for (i = 0; i < __le32_to_cpu(cmd->num_of_channels); i++)
3953                channel_list[i] = __cpu_to_le32(pno->a_networks[0].channels[i]);
3954
3955        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv start pno config vdev_id %d\n",
3956                   vdev_id);
3957
3958        return skb;
3959}
3960
3961/* Request FW to stop ongoing PNO operation */
3962static struct sk_buff *ath10k_wmi_tlv_op_gen_config_pno_stop(struct ath10k *ar,
3963                                                             u32 vdev_id)
3964{
3965        struct wmi_tlv_wow_nlo_config_cmd *cmd;
3966        struct wmi_tlv *tlv;
3967        struct sk_buff *skb;
3968        void *ptr;
3969        size_t len;
3970
3971        len = sizeof(*tlv) + sizeof(*cmd) +
3972              sizeof(*tlv) +
3973              /* TLV place holder for array of structures
3974               * nlo_configured_parameters(nlo_list)
3975               */
3976              sizeof(*tlv);
3977              /* TLV place holder for array of uint32 channel_list */
3978        skb = ath10k_wmi_alloc_skb(ar, len);
3979        if (!skb)
3980                return ERR_PTR(-ENOMEM);
3981
3982        ptr = (void *)skb->data;
3983        tlv = ptr;
3984        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_NLO_CONFIG_CMD);
3985        tlv->len = __cpu_to_le16(sizeof(*cmd));
3986        cmd = (void *)tlv->value;
3987
3988        cmd->vdev_id = __cpu_to_le32(vdev_id);
3989        cmd->flags = __cpu_to_le32(WMI_NLO_CONFIG_STOP);
3990
3991        ptr += sizeof(*tlv);
3992        ptr += sizeof(*cmd);
3993
3994        /* nlo_configured_parameters(nlo_list) */
3995        tlv = ptr;
3996        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
3997        tlv->len = __cpu_to_le16(0);
3998
3999        ptr += sizeof(*tlv);
4000
4001        /* channel list */
4002        tlv = ptr;
4003        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
4004        tlv->len = __cpu_to_le16(0);
4005
4006        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv stop pno config vdev_id %d\n", vdev_id);
4007        return skb;
4008}
4009
4010static struct sk_buff *
4011ath10k_wmi_tlv_op_gen_config_pno(struct ath10k *ar, u32 vdev_id,
4012                                 struct wmi_pno_scan_req *pno_scan)
4013{
4014        if (pno_scan->enable)
4015                return ath10k_wmi_tlv_op_gen_config_pno_start(ar, vdev_id, pno_scan);
4016        else
4017                return ath10k_wmi_tlv_op_gen_config_pno_stop(ar, vdev_id);
4018}
4019
4020static struct sk_buff *
4021ath10k_wmi_tlv_op_gen_adaptive_qcs(struct ath10k *ar, bool enable)
4022{
4023        struct wmi_tlv_adaptive_qcs *cmd;
4024        struct wmi_tlv *tlv;
4025        struct sk_buff *skb;
4026        void *ptr;
4027        size_t len;
4028
4029        len = sizeof(*tlv) + sizeof(*cmd);
4030        skb = ath10k_wmi_alloc_skb(ar, len);
4031        if (!skb)
4032                return ERR_PTR(-ENOMEM);
4033
4034        ptr = (void *)skb->data;
4035        tlv = ptr;
4036        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_RESMGR_ADAPTIVE_OCS_CMD);
4037        tlv->len = __cpu_to_le16(sizeof(*cmd));
4038        cmd = (void *)tlv->value;
4039        cmd->enable = __cpu_to_le32(enable ? 1 : 0);
4040
4041        ptr += sizeof(*tlv);
4042        ptr += sizeof(*cmd);
4043
4044        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv adaptive qcs %d\n", enable);
4045        return skb;
4046}
4047
4048static struct sk_buff *
4049ath10k_wmi_tlv_op_gen_echo(struct ath10k *ar, u32 value)
4050{
4051        struct wmi_echo_cmd *cmd;
4052        struct wmi_tlv *tlv;
4053        struct sk_buff *skb;
4054        void *ptr;
4055        size_t len;
4056
4057        len = sizeof(*tlv) + sizeof(*cmd);
4058        skb = ath10k_wmi_alloc_skb(ar, len);
4059        if (!skb)
4060                return ERR_PTR(-ENOMEM);
4061
4062        ptr = (void *)skb->data;
4063        tlv = ptr;
4064        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_ECHO_CMD);
4065        tlv->len = __cpu_to_le16(sizeof(*cmd));
4066        cmd = (void *)tlv->value;
4067        cmd->value = cpu_to_le32(value);
4068
4069        ptr += sizeof(*tlv);
4070        ptr += sizeof(*cmd);
4071
4072        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv echo value 0x%08x\n", value);
4073        return skb;
4074}
4075
4076static struct sk_buff *
4077ath10k_wmi_tlv_op_gen_vdev_spectral_conf(struct ath10k *ar,
4078                                         const struct wmi_vdev_spectral_conf_arg *arg)
4079{
4080        struct wmi_vdev_spectral_conf_cmd *cmd;
4081        struct sk_buff *skb;
4082        struct wmi_tlv *tlv;
4083        void *ptr;
4084        size_t len;
4085
4086        len = sizeof(*tlv) + sizeof(*cmd);
4087        skb = ath10k_wmi_alloc_skb(ar, len);
4088        if (!skb)
4089                return ERR_PTR(-ENOMEM);
4090
4091        ptr = (void *)skb->data;
4092        tlv = ptr;
4093        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_SPECTRAL_CONFIGURE_CMD);
4094        tlv->len = __cpu_to_le16(sizeof(*cmd));
4095        cmd = (void *)tlv->value;
4096        cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
4097        cmd->scan_count = __cpu_to_le32(arg->scan_count);
4098        cmd->scan_period = __cpu_to_le32(arg->scan_period);
4099        cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
4100        cmd->scan_fft_size = __cpu_to_le32(arg->scan_fft_size);
4101        cmd->scan_gc_ena = __cpu_to_le32(arg->scan_gc_ena);
4102        cmd->scan_restart_ena = __cpu_to_le32(arg->scan_restart_ena);
4103        cmd->scan_noise_floor_ref = __cpu_to_le32(arg->scan_noise_floor_ref);
4104        cmd->scan_init_delay = __cpu_to_le32(arg->scan_init_delay);
4105        cmd->scan_nb_tone_thr = __cpu_to_le32(arg->scan_nb_tone_thr);
4106        cmd->scan_str_bin_thr = __cpu_to_le32(arg->scan_str_bin_thr);
4107        cmd->scan_wb_rpt_mode = __cpu_to_le32(arg->scan_wb_rpt_mode);
4108        cmd->scan_rssi_rpt_mode = __cpu_to_le32(arg->scan_rssi_rpt_mode);
4109        cmd->scan_rssi_thr = __cpu_to_le32(arg->scan_rssi_thr);
4110        cmd->scan_pwr_format = __cpu_to_le32(arg->scan_pwr_format);
4111        cmd->scan_rpt_mode = __cpu_to_le32(arg->scan_rpt_mode);
4112        cmd->scan_bin_scale = __cpu_to_le32(arg->scan_bin_scale);
4113        cmd->scan_dbm_adj = __cpu_to_le32(arg->scan_dbm_adj);
4114        cmd->scan_chn_mask = __cpu_to_le32(arg->scan_chn_mask);
4115
4116        return skb;
4117}
4118
4119static struct sk_buff *
4120ath10k_wmi_tlv_op_gen_vdev_spectral_enable(struct ath10k *ar, u32 vdev_id,
4121                                           u32 trigger, u32 enable)
4122{
4123        struct wmi_vdev_spectral_enable_cmd *cmd;
4124        struct sk_buff *skb;
4125        struct wmi_tlv *tlv;
4126        void *ptr;
4127        size_t len;
4128
4129        len = sizeof(*tlv) + sizeof(*cmd);
4130        skb = ath10k_wmi_alloc_skb(ar, len);
4131        if (!skb)
4132                return ERR_PTR(-ENOMEM);
4133
4134        ptr = (void *)skb->data;
4135        tlv = ptr;
4136        tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_SPECTRAL_ENABLE_CMD);
4137        tlv->len = __cpu_to_le16(sizeof(*cmd));
4138        cmd = (void *)tlv->value;
4139        cmd->vdev_id = __cpu_to_le32(vdev_id);
4140        cmd->trigger_cmd = __cpu_to_le32(trigger);
4141        cmd->enable_cmd = __cpu_to_le32(enable);
4142
4143        return skb;
4144}
4145
4146/****************/
4147/* TLV mappings */
4148/****************/
4149
4150static struct wmi_cmd_map wmi_tlv_cmd_map = {
4151        .init_cmdid = WMI_TLV_INIT_CMDID,
4152        .start_scan_cmdid = WMI_TLV_START_SCAN_CMDID,
4153        .stop_scan_cmdid = WMI_TLV_STOP_SCAN_CMDID,
4154        .scan_chan_list_cmdid = WMI_TLV_SCAN_CHAN_LIST_CMDID,
4155        .scan_sch_prio_tbl_cmdid = WMI_TLV_SCAN_SCH_PRIO_TBL_CMDID,
4156        .scan_prob_req_oui_cmdid = WMI_TLV_SCAN_PROB_REQ_OUI_CMDID,
4157        .pdev_set_regdomain_cmdid = WMI_TLV_PDEV_SET_REGDOMAIN_CMDID,
4158        .pdev_set_channel_cmdid = WMI_TLV_PDEV_SET_CHANNEL_CMDID,
4159        .pdev_set_param_cmdid = WMI_TLV_PDEV_SET_PARAM_CMDID,
4160        .pdev_pktlog_enable_cmdid = WMI_TLV_PDEV_PKTLOG_ENABLE_CMDID,
4161        .pdev_pktlog_disable_cmdid = WMI_TLV_PDEV_PKTLOG_DISABLE_CMDID,
4162        .pdev_set_wmm_params_cmdid = WMI_TLV_PDEV_SET_WMM_PARAMS_CMDID,
4163        .pdev_set_ht_cap_ie_cmdid = WMI_TLV_PDEV_SET_HT_CAP_IE_CMDID,
4164        .pdev_set_vht_cap_ie_cmdid = WMI_TLV_PDEV_SET_VHT_CAP_IE_CMDID,
4165        .pdev_set_dscp_tid_map_cmdid = WMI_TLV_PDEV_SET_DSCP_TID_MAP_CMDID,
4166        .pdev_set_quiet_mode_cmdid = WMI_TLV_PDEV_SET_QUIET_MODE_CMDID,
4167        .pdev_green_ap_ps_enable_cmdid = WMI_TLV_PDEV_GREEN_AP_PS_ENABLE_CMDID,
4168        .pdev_get_tpc_config_cmdid = WMI_TLV_PDEV_GET_TPC_CONFIG_CMDID,
4169        .pdev_set_base_macaddr_cmdid = WMI_TLV_PDEV_SET_BASE_MACADDR_CMDID,
4170        .vdev_create_cmdid = WMI_TLV_VDEV_CREATE_CMDID,
4171        .vdev_delete_cmdid = WMI_TLV_VDEV_DELETE_CMDID,
4172        .vdev_start_request_cmdid = WMI_TLV_VDEV_START_REQUEST_CMDID,
4173        .vdev_restart_request_cmdid = WMI_TLV_VDEV_RESTART_REQUEST_CMDID,
4174        .vdev_up_cmdid = WMI_TLV_VDEV_UP_CMDID,
4175        .vdev_stop_cmdid = WMI_TLV_VDEV_STOP_CMDID,
4176        .vdev_down_cmdid = WMI_TLV_VDEV_DOWN_CMDID,
4177        .vdev_set_param_cmdid = WMI_TLV_VDEV_SET_PARAM_CMDID,
4178        .vdev_install_key_cmdid = WMI_TLV_VDEV_INSTALL_KEY_CMDID,
4179        .peer_create_cmdid = WMI_TLV_PEER_CREATE_CMDID,
4180        .peer_delete_cmdid = WMI_TLV_PEER_DELETE_CMDID,
4181        .peer_flush_tids_cmdid = WMI_TLV_PEER_FLUSH_TIDS_CMDID,
4182        .peer_set_param_cmdid = WMI_TLV_PEER_SET_PARAM_CMDID,
4183        .peer_assoc_cmdid = WMI_TLV_PEER_ASSOC_CMDID,
4184        .peer_add_wds_entry_cmdid = WMI_TLV_PEER_ADD_WDS_ENTRY_CMDID,
4185        .peer_remove_wds_entry_cmdid = WMI_TLV_PEER_REMOVE_WDS_ENTRY_CMDID,
4186        .peer_mcast_group_cmdid = WMI_TLV_PEER_MCAST_GROUP_CMDID,
4187        .bcn_tx_cmdid = WMI_TLV_BCN_TX_CMDID,
4188        .pdev_send_bcn_cmdid = WMI_TLV_PDEV_SEND_BCN_CMDID,
4189        .bcn_tmpl_cmdid = WMI_TLV_BCN_TMPL_CMDID,
4190        .bcn_filter_rx_cmdid = WMI_TLV_BCN_FILTER_RX_CMDID,
4191        .prb_req_filter_rx_cmdid = WMI_TLV_PRB_REQ_FILTER_RX_CMDID,
4192        .mgmt_tx_cmdid = WMI_TLV_MGMT_TX_CMDID,
4193        .mgmt_tx_send_cmdid = WMI_TLV_MGMT_TX_SEND_CMD,
4194        .prb_tmpl_cmdid = WMI_TLV_PRB_TMPL_CMDID,
4195        .addba_clear_resp_cmdid = WMI_TLV_ADDBA_CLEAR_RESP_CMDID,
4196        .addba_send_cmdid = WMI_TLV_ADDBA_SEND_CMDID,
4197        .addba_status_cmdid = WMI_TLV_ADDBA_STATUS_CMDID,
4198        .delba_send_cmdid = WMI_TLV_DELBA_SEND_CMDID,
4199        .addba_set_resp_cmdid = WMI_TLV_ADDBA_SET_RESP_CMDID,
4200        .send_singleamsdu_cmdid = WMI_TLV_SEND_SINGLEAMSDU_CMDID,
4201        .sta_powersave_mode_cmdid = WMI_TLV_STA_POWERSAVE_MODE_CMDID,
4202        .sta_powersave_param_cmdid = WMI_TLV_STA_POWERSAVE_PARAM_CMDID,
4203        .sta_mimo_ps_mode_cmdid = WMI_TLV_STA_MIMO_PS_MODE_CMDID,
4204        .pdev_dfs_enable_cmdid = WMI_TLV_PDEV_DFS_ENABLE_CMDID,
4205        .pdev_dfs_disable_cmdid = WMI_TLV_PDEV_DFS_DISABLE_CMDID,
4206        .roam_scan_mode = WMI_TLV_ROAM_SCAN_MODE,
4207        .roam_scan_rssi_threshold = WMI_TLV_ROAM_SCAN_RSSI_THRESHOLD,
4208        .roam_scan_period = WMI_TLV_ROAM_SCAN_PERIOD,
4209        .roam_scan_rssi_change_threshold =
4210                                WMI_TLV_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
4211        .roam_ap_profile = WMI_TLV_ROAM_AP_PROFILE,
4212        .ofl_scan_add_ap_profile = WMI_TLV_ROAM_AP_PROFILE,
4213        .ofl_scan_remove_ap_profile = WMI_TLV_OFL_SCAN_REMOVE_AP_PROFILE,
4214        .ofl_scan_period = WMI_TLV_OFL_SCAN_PERIOD,
4215        .p2p_dev_set_device_info = WMI_TLV_P2P_DEV_SET_DEVICE_INFO,
4216        .p2p_dev_set_discoverability = WMI_TLV_P2P_DEV_SET_DISCOVERABILITY,
4217        .p2p_go_set_beacon_ie = WMI_TLV_P2P_GO_SET_BEACON_IE,
4218        .p2p_go_set_probe_resp_ie = WMI_TLV_P2P_GO_SET_PROBE_RESP_IE,
4219        .p2p_set_vendor_ie_data_cmdid = WMI_TLV_P2P_SET_VENDOR_IE_DATA_CMDID,
4220        .ap_ps_peer_param_cmdid = WMI_TLV_AP_PS_PEER_PARAM_CMDID,
4221        .ap_ps_peer_uapsd_coex_cmdid = WMI_TLV_AP_PS_PEER_UAPSD_COEX_CMDID,
4222        .peer_rate_retry_sched_cmdid = WMI_TLV_PEER_RATE_RETRY_SCHED_CMDID,
4223        .wlan_profile_trigger_cmdid = WMI_TLV_WLAN_PROFILE_TRIGGER_CMDID,
4224        .wlan_profile_set_hist_intvl_cmdid =
4225                                WMI_TLV_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
4226        .wlan_profile_get_profile_data_cmdid =
4227                                WMI_TLV_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
4228        .wlan_profile_enable_profile_id_cmdid =
4229                                WMI_TLV_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
4230        .wlan_profile_list_profile_id_cmdid =
4231                                WMI_TLV_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
4232        .pdev_suspend_cmdid = WMI_TLV_PDEV_SUSPEND_CMDID,
4233        .pdev_resume_cmdid = WMI_TLV_PDEV_RESUME_CMDID,
4234        .add_bcn_filter_cmdid = WMI_TLV_ADD_BCN_FILTER_CMDID,
4235        .rmv_bcn_filter_cmdid = WMI_TLV_RMV_BCN_FILTER_CMDID,
4236        .wow_add_wake_pattern_cmdid = WMI_TLV_WOW_ADD_WAKE_PATTERN_CMDID,
4237        .wow_del_wake_pattern_cmdid = WMI_TLV_WOW_DEL_WAKE_PATTERN_CMDID,
4238        .wow_enable_disable_wake_event_cmdid =
4239                                WMI_TLV_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
4240        .wow_enable_cmdid = WMI_TLV_WOW_ENABLE_CMDID,
4241        .wow_hostwakeup_from_sleep_cmdid =
4242                                WMI_TLV_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
4243        .rtt_measreq_cmdid = WMI_TLV_RTT_MEASREQ_CMDID,
4244        .rtt_tsf_cmdid = WMI_TLV_RTT_TSF_CMDID,
4245        .vdev_spectral_scan_configure_cmdid = WMI_TLV_SPECTRAL_SCAN_CONF_CMDID,
4246        .vdev_spectral_scan_enable_cmdid = WMI_TLV_SPECTRAL_SCAN_ENABLE_CMDID,
4247        .request_stats_cmdid = WMI_TLV_REQUEST_STATS_CMDID,
4248        .request_peer_stats_info_cmdid = WMI_TLV_REQUEST_PEER_STATS_INFO_CMDID,
4249        .set_arp_ns_offload_cmdid = WMI_TLV_SET_ARP_NS_OFFLOAD_CMDID,
4250        .network_list_offload_config_cmdid =
4251                                WMI_TLV_NETWORK_LIST_OFFLOAD_CONFIG_CMDID,
4252        .gtk_offload_cmdid = WMI_TLV_GTK_OFFLOAD_CMDID,
4253        .csa_offload_enable_cmdid = WMI_TLV_CSA_OFFLOAD_ENABLE_CMDID,
4254        .csa_offload_chanswitch_cmdid = WMI_TLV_CSA_OFFLOAD_CHANSWITCH_CMDID,
4255        .chatter_set_mode_cmdid = WMI_TLV_CHATTER_SET_MODE_CMDID,
4256        .peer_tid_addba_cmdid = WMI_TLV_PEER_TID_ADDBA_CMDID,
4257        .peer_tid_delba_cmdid = WMI_TLV_PEER_TID_DELBA_CMDID,
4258        .sta_dtim_ps_method_cmdid = WMI_TLV_STA_DTIM_PS_METHOD_CMDID,
4259        .sta_uapsd_auto_trig_cmdid = WMI_TLV_STA_UAPSD_AUTO_TRIG_CMDID,
4260        .sta_keepalive_cmd = WMI_TLV_STA_KEEPALIVE_CMDID,
4261        .echo_cmdid = WMI_TLV_ECHO_CMDID,
4262        .pdev_utf_cmdid = WMI_TLV_PDEV_UTF_CMDID,
4263        .dbglog_cfg_cmdid = WMI_TLV_DBGLOG_CFG_CMDID,
4264        .pdev_qvit_cmdid = WMI_TLV_PDEV_QVIT_CMDID,
4265        .pdev_ftm_intg_cmdid = WMI_TLV_PDEV_FTM_INTG_CMDID,
4266        .vdev_set_keepalive_cmdid = WMI_TLV_VDEV_SET_KEEPALIVE_CMDID,
4267        .vdev_get_keepalive_cmdid = WMI_TLV_VDEV_GET_KEEPALIVE_CMDID,
4268        .force_fw_hang_cmdid = WMI_TLV_FORCE_FW_HANG_CMDID,
4269        .gpio_config_cmdid = WMI_TLV_GPIO_CONFIG_CMDID,
4270        .gpio_output_cmdid = WMI_TLV_GPIO_OUTPUT_CMDID,
4271        .pdev_get_temperature_cmdid = WMI_TLV_PDEV_GET_TEMPERATURE_CMDID,
4272        .vdev_set_wmm_params_cmdid = WMI_TLV_VDEV_SET_WMM_PARAMS_CMDID,
4273        .tdls_set_state_cmdid = WMI_TLV_TDLS_SET_STATE_CMDID,
4274        .tdls_peer_update_cmdid = WMI_TLV_TDLS_PEER_UPDATE_CMDID,
4275        .adaptive_qcs_cmdid = WMI_TLV_RESMGR_ADAPTIVE_OCS_CMDID,
4276        .scan_update_request_cmdid = WMI_CMD_UNSUPPORTED,
4277        .vdev_standby_response_cmdid = WMI_CMD_UNSUPPORTED,
4278        .vdev_resume_response_cmdid = WMI_CMD_UNSUPPORTED,
4279        .wlan_peer_caching_add_peer_cmdid = WMI_CMD_UNSUPPORTED,
4280        .wlan_peer_caching_evict_peer_cmdid = WMI_CMD_UNSUPPORTED,
4281        .wlan_peer_caching_restore_peer_cmdid = WMI_CMD_UNSUPPORTED,
4282        .wlan_peer_caching_print_all_peers_info_cmdid = WMI_CMD_UNSUPPORTED,
4283        .peer_update_wds_entry_cmdid = WMI_CMD_UNSUPPORTED,
4284        .peer_add_proxy_sta_entry_cmdid = WMI_CMD_UNSUPPORTED,
4285        .rtt_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
4286        .oem_req_cmdid = WMI_CMD_UNSUPPORTED,
4287        .nan_cmdid = WMI_CMD_UNSUPPORTED,
4288        .vdev_ratemask_cmdid = WMI_CMD_UNSUPPORTED,
4289        .qboost_cfg_cmdid = WMI_CMD_UNSUPPORTED,
4290        .pdev_smart_ant_enable_cmdid = WMI_CMD_UNSUPPORTED,
4291        .pdev_smart_ant_set_rx_antenna_cmdid = WMI_CMD_UNSUPPORTED,
4292        .peer_smart_ant_set_tx_antenna_cmdid = WMI_CMD_UNSUPPORTED,
4293        .peer_smart_ant_set_train_info_cmdid = WMI_CMD_UNSUPPORTED,
4294        .peer_smart_ant_set_node_config_ops_cmdid = WMI_CMD_UNSUPPORTED,
4295        .pdev_set_antenna_switch_table_cmdid = WMI_CMD_UNSUPPORTED,
4296        .pdev_set_ctl_table_cmdid = WMI_CMD_UNSUPPORTED,
4297        .pdev_set_mimogain_table_cmdid = WMI_CMD_UNSUPPORTED,
4298        .pdev_ratepwr_table_cmdid = WMI_CMD_UNSUPPORTED,
4299        .pdev_ratepwr_chainmsk_table_cmdid = WMI_CMD_UNSUPPORTED,
4300        .pdev_fips_cmdid = WMI_CMD_UNSUPPORTED,
4301        .tt_set_conf_cmdid = WMI_CMD_UNSUPPORTED,
4302        .fwtest_cmdid = WMI_CMD_UNSUPPORTED,
4303        .vdev_atf_request_cmdid = WMI_CMD_UNSUPPORTED,
4304        .peer_atf_request_cmdid = WMI_CMD_UNSUPPORTED,
4305        .pdev_get_ani_cck_config_cmdid = WMI_CMD_UNSUPPORTED,
4306        .pdev_get_ani_ofdm_config_cmdid = WMI_CMD_UNSUPPORTED,
4307        .pdev_reserve_ast_entry_cmdid = WMI_CMD_UNSUPPORTED,
4308};
4309
4310static struct wmi_pdev_param_map wmi_tlv_pdev_param_map = {
4311        .tx_chain_mask = WMI_TLV_PDEV_PARAM_TX_CHAIN_MASK,
4312        .rx_chain_mask = WMI_TLV_PDEV_PARAM_RX_CHAIN_MASK,
4313        .txpower_limit2g = WMI_TLV_PDEV_PARAM_TXPOWER_LIMIT2G,
4314        .txpower_limit5g = WMI_TLV_PDEV_PARAM_TXPOWER_LIMIT5G,
4315        .txpower_scale = WMI_TLV_PDEV_PARAM_TXPOWER_SCALE,
4316        .beacon_gen_mode = WMI_TLV_PDEV_PARAM_BEACON_GEN_MODE,
4317        .beacon_tx_mode = WMI_TLV_PDEV_PARAM_BEACON_TX_MODE,
4318        .resmgr_offchan_mode = WMI_TLV_PDEV_PARAM_RESMGR_OFFCHAN_MODE,
4319        .protection_mode = WMI_TLV_PDEV_PARAM_PROTECTION_MODE,
4320        .dynamic_bw = WMI_TLV_PDEV_PARAM_DYNAMIC_BW,
4321        .non_agg_sw_retry_th = WMI_TLV_PDEV_PARAM_NON_AGG_SW_RETRY_TH,
4322        .agg_sw_retry_th = WMI_TLV_PDEV_PARAM_AGG_SW_RETRY_TH,
4323        .sta_kickout_th = WMI_TLV_PDEV_PARAM_STA_KICKOUT_TH,
4324        .ac_aggrsize_scaling = WMI_TLV_PDEV_PARAM_AC_AGGRSIZE_SCALING,
4325        .ltr_enable = WMI_TLV_PDEV_PARAM_LTR_ENABLE,
4326        .ltr_ac_latency_be = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_BE,
4327        .ltr_ac_latency_bk = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_BK,
4328        .ltr_ac_latency_vi = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_VI,
4329        .ltr_ac_latency_vo = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_VO,
4330        .ltr_ac_latency_timeout = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_TIMEOUT,
4331        .ltr_sleep_override = WMI_TLV_PDEV_PARAM_LTR_SLEEP_OVERRIDE,
4332        .ltr_rx_override = WMI_TLV_PDEV_PARAM_LTR_RX_OVERRIDE,
4333        .ltr_tx_activity_timeout = WMI_TLV_PDEV_PARAM_LTR_TX_ACTIVITY_TIMEOUT,
4334        .l1ss_enable = WMI_TLV_PDEV_PARAM_L1SS_ENABLE,
4335        .dsleep_enable = WMI_TLV_PDEV_PARAM_DSLEEP_ENABLE,
4336        .pcielp_txbuf_flush = WMI_TLV_PDEV_PARAM_PCIELP_TXBUF_FLUSH,
4337        .pcielp_txbuf_watermark = WMI_TLV_PDEV_PARAM_PCIELP_TXBUF_TMO_EN,
4338        .pcielp_txbuf_tmo_en = WMI_TLV_PDEV_PARAM_PCIELP_TXBUF_TMO_EN,
4339        .pcielp_txbuf_tmo_value = WMI_TLV_PDEV_PARAM_PCIELP_TXBUF_TMO_VALUE,
4340        .pdev_stats_update_period = WMI_TLV_PDEV_PARAM_PDEV_STATS_UPDATE_PERIOD,
4341        .vdev_stats_update_period = WMI_TLV_PDEV_PARAM_VDEV_STATS_UPDATE_PERIOD,
4342        .peer_stats_update_period = WMI_TLV_PDEV_PARAM_PEER_STATS_UPDATE_PERIOD,
4343        .bcnflt_stats_update_period =
4344                                WMI_TLV_PDEV_PARAM_BCNFLT_STATS_UPDATE_PERIOD,
4345        .pmf_qos = WMI_TLV_PDEV_PARAM_PMF_QOS,
4346        .arp_ac_override = WMI_TLV_PDEV_PARAM_ARP_AC_OVERRIDE,
4347        .dcs = WMI_TLV_PDEV_PARAM_DCS,
4348        .ani_enable = WMI_TLV_PDEV_PARAM_ANI_ENABLE,
4349        .ani_poll_period = WMI_TLV_PDEV_PARAM_ANI_POLL_PERIOD,
4350        .ani_listen_period = WMI_TLV_PDEV_PARAM_ANI_LISTEN_PERIOD,
4351        .ani_ofdm_level = WMI_TLV_PDEV_PARAM_ANI_OFDM_LEVEL,
4352        .ani_cck_level = WMI_TLV_PDEV_PARAM_ANI_CCK_LEVEL,
4353        .dyntxchain = WMI_TLV_PDEV_PARAM_DYNTXCHAIN,
4354        .proxy_sta = WMI_TLV_PDEV_PARAM_PROXY_STA,
4355        .idle_ps_config = WMI_TLV_PDEV_PARAM_IDLE_PS_CONFIG,
4356        .power_gating_sleep = WMI_TLV_PDEV_PARAM_POWER_GATING_SLEEP,
4357        .fast_channel_reset = WMI_TLV_PDEV_PARAM_UNSUPPORTED,
4358        .burst_dur = WMI_TLV_PDEV_PARAM_BURST_DUR,
4359        .burst_enable = WMI_TLV_PDEV_PARAM_BURST_ENABLE,
4360        .cal_period = WMI_PDEV_PARAM_UNSUPPORTED,
4361        .aggr_burst = WMI_PDEV_PARAM_UNSUPPORTED,
4362        .rx_decap_mode = WMI_PDEV_PARAM_UNSUPPORTED,
4363        .smart_antenna_default_antenna = WMI_PDEV_PARAM_UNSUPPORTED,
4364        .igmpmld_override = WMI_PDEV_PARAM_UNSUPPORTED,
4365        .igmpmld_tid = WMI_PDEV_PARAM_UNSUPPORTED,
4366        .antenna_gain = WMI_PDEV_PARAM_UNSUPPORTED,
4367        .rx_filter = WMI_PDEV_PARAM_UNSUPPORTED,
4368        .set_mcast_to_ucast_tid = WMI_PDEV_PARAM_UNSUPPORTED,
4369        .proxy_sta_mode = WMI_PDEV_PARAM_UNSUPPORTED,
4370        .set_mcast2ucast_mode = WMI_PDEV_PARAM_UNSUPPORTED,
4371        .set_mcast2ucast_buffer = WMI_PDEV_PARAM_UNSUPPORTED,
4372        .remove_mcast2ucast_buffer = WMI_PDEV_PARAM_UNSUPPORTED,
4373        .peer_sta_ps_statechg_enable = WMI_PDEV_PARAM_UNSUPPORTED,
4374        .igmpmld_ac_override = WMI_PDEV_PARAM_UNSUPPORTED,
4375        .block_interbss = WMI_PDEV_PARAM_UNSUPPORTED,
4376        .set_disable_reset_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
4377        .set_msdu_ttl_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
4378        .set_ppdu_duration_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
4379        .txbf_sound_period_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
4380        .set_promisc_mode_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
4381        .set_burst_mode_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
4382        .en_stats = WMI_PDEV_PARAM_UNSUPPORTED,
4383        .mu_group_policy = WMI_PDEV_PARAM_UNSUPPORTED,
4384        .noise_detection = WMI_PDEV_PARAM_UNSUPPORTED,
4385        .noise_threshold = WMI_PDEV_PARAM_UNSUPPORTED,
4386        .dpd_enable = WMI_PDEV_PARAM_UNSUPPORTED,
4387        .set_mcast_bcast_echo = WMI_PDEV_PARAM_UNSUPPORTED,
4388        .atf_strict_sch = WMI_PDEV_PARAM_UNSUPPORTED,
4389        .atf_sched_duration = WMI_PDEV_PARAM_UNSUPPORTED,
4390        .ant_plzn = WMI_PDEV_PARAM_UNSUPPORTED,
4391        .mgmt_retry_limit = WMI_PDEV_PARAM_UNSUPPORTED,
4392        .sensitivity_level = WMI_PDEV_PARAM_UNSUPPORTED,
4393        .signed_txpower_2g = WMI_PDEV_PARAM_UNSUPPORTED,
4394        .signed_txpower_5g = WMI_PDEV_PARAM_UNSUPPORTED,
4395        .enable_per_tid_amsdu = WMI_PDEV_PARAM_UNSUPPORTED,
4396        .enable_per_tid_ampdu = WMI_PDEV_PARAM_UNSUPPORTED,
4397        .cca_threshold = WMI_PDEV_PARAM_UNSUPPORTED,
4398        .rts_fixed_rate = WMI_PDEV_PARAM_UNSUPPORTED,
4399        .pdev_reset = WMI_PDEV_PARAM_UNSUPPORTED,
4400        .wapi_mbssid_offset = WMI_PDEV_PARAM_UNSUPPORTED,
4401        .arp_srcaddr = WMI_PDEV_PARAM_UNSUPPORTED,
4402        .arp_dstaddr = WMI_PDEV_PARAM_UNSUPPORTED,
4403        .rfkill_config = WMI_TLV_PDEV_PARAM_HW_RFKILL_CONFIG,
4404        .rfkill_enable = WMI_TLV_PDEV_PARAM_RFKILL_ENABLE,
4405        .peer_stats_info_enable = WMI_TLV_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
4406};
4407
4408static struct wmi_peer_param_map wmi_tlv_peer_param_map = {
4409        .smps_state = WMI_TLV_PEER_SMPS_STATE,
4410        .ampdu = WMI_TLV_PEER_AMPDU,
4411        .authorize = WMI_TLV_PEER_AUTHORIZE,
4412        .chan_width = WMI_TLV_PEER_CHAN_WIDTH,
4413        .nss = WMI_TLV_PEER_NSS,
4414        .use_4addr = WMI_TLV_PEER_USE_4ADDR,
4415        .membership = WMI_TLV_PEER_MEMBERSHIP,
4416        .user_pos = WMI_TLV_PEER_USERPOS,
4417        .crit_proto_hint_enabled = WMI_TLV_PEER_CRIT_PROTO_HINT_ENABLED,
4418        .tx_fail_cnt_thr = WMI_TLV_PEER_TX_FAIL_CNT_THR,
4419        .set_hw_retry_cts2s = WMI_TLV_PEER_SET_HW_RETRY_CTS2S,
4420        .ibss_atim_win_len = WMI_TLV_PEER_IBSS_ATIM_WINDOW_LENGTH,
4421        .phymode = WMI_TLV_PEER_PHYMODE,
4422        .use_fixed_power = WMI_TLV_PEER_USE_FIXED_PWR,
4423        .dummy_var = WMI_TLV_PEER_DUMMY_VAR,
4424};
4425
4426static struct wmi_vdev_param_map wmi_tlv_vdev_param_map = {
4427        .rts_threshold = WMI_TLV_VDEV_PARAM_RTS_THRESHOLD,
4428        .fragmentation_threshold = WMI_TLV_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
4429        .beacon_interval = WMI_TLV_VDEV_PARAM_BEACON_INTERVAL,
4430        .listen_interval = WMI_TLV_VDEV_PARAM_LISTEN_INTERVAL,
4431        .multicast_rate = WMI_TLV_VDEV_PARAM_MULTICAST_RATE,
4432        .mgmt_tx_rate = WMI_TLV_VDEV_PARAM_MGMT_TX_RATE,
4433        .slot_time = WMI_TLV_VDEV_PARAM_SLOT_TIME,
4434        .preamble = WMI_TLV_VDEV_PARAM_PREAMBLE,
4435        .swba_time = WMI_TLV_VDEV_PARAM_SWBA_TIME,
4436        .wmi_vdev_stats_update_period = WMI_TLV_VDEV_STATS_UPDATE_PERIOD,
4437        .wmi_vdev_pwrsave_ageout_time = WMI_TLV_VDEV_PWRSAVE_AGEOUT_TIME,
4438        .wmi_vdev_host_swba_interval = WMI_TLV_VDEV_HOST_SWBA_INTERVAL,
4439        .dtim_period = WMI_TLV_VDEV_PARAM_DTIM_PERIOD,
4440        .wmi_vdev_oc_scheduler_air_time_limit =
4441                                WMI_TLV_VDEV_OC_SCHEDULER_AIR_TIME_LIMIT,
4442        .wds = WMI_TLV_VDEV_PARAM_WDS,
4443        .atim_window = WMI_TLV_VDEV_PARAM_ATIM_WINDOW,
4444        .bmiss_count_max = WMI_TLV_VDEV_PARAM_BMISS_COUNT_MAX,
4445        .bmiss_first_bcnt = WMI_TLV_VDEV_PARAM_BMISS_FIRST_BCNT,
4446        .bmiss_final_bcnt = WMI_TLV_VDEV_PARAM_BMISS_FINAL_BCNT,
4447        .feature_wmm = WMI_TLV_VDEV_PARAM_FEATURE_WMM,
4448        .chwidth = WMI_TLV_VDEV_PARAM_CHWIDTH,
4449        .chextoffset = WMI_TLV_VDEV_PARAM_CHEXTOFFSET,
4450        .disable_htprotection = WMI_TLV_VDEV_PARAM_DISABLE_HTPROTECTION,
4451        .sta_quickkickout = WMI_TLV_VDEV_PARAM_STA_QUICKKICKOUT,
4452        .mgmt_rate = WMI_TLV_VDEV_PARAM_MGMT_RATE,
4453        .protection_mode = WMI_TLV_VDEV_PARAM_PROTECTION_MODE,
4454        .fixed_rate = WMI_TLV_VDEV_PARAM_FIXED_RATE,
4455        .sgi = WMI_TLV_VDEV_PARAM_SGI,
4456        .ldpc = WMI_TLV_VDEV_PARAM_LDPC,
4457        .tx_stbc = WMI_TLV_VDEV_PARAM_TX_STBC,
4458        .rx_stbc = WMI_TLV_VDEV_PARAM_RX_STBC,
4459        .intra_bss_fwd = WMI_TLV_VDEV_PARAM_INTRA_BSS_FWD,
4460        .def_keyid = WMI_TLV_VDEV_PARAM_DEF_KEYID,
4461        .nss = WMI_TLV_VDEV_PARAM_NSS,
4462        .bcast_data_rate = WMI_TLV_VDEV_PARAM_BCAST_DATA_RATE,
4463        .mcast_data_rate = WMI_TLV_VDEV_PARAM_MCAST_DATA_RATE,
4464        .mcast_indicate = WMI_TLV_VDEV_PARAM_MCAST_INDICATE,
4465        .dhcp_indicate = WMI_TLV_VDEV_PARAM_DHCP_INDICATE,
4466        .unknown_dest_indicate = WMI_TLV_VDEV_PARAM_UNKNOWN_DEST_INDICATE,
4467        .ap_keepalive_min_idle_inactive_time_secs =
4468                WMI_TLV_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS,
4469        .ap_keepalive_max_idle_inactive_time_secs =
4470                WMI_TLV_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS,
4471        .ap_keepalive_max_unresponsive_time_secs =
4472                WMI_TLV_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS,
4473        .ap_enable_nawds = WMI_TLV_VDEV_PARAM_AP_ENABLE_NAWDS,
4474        .mcast2ucast_set = WMI_TLV_VDEV_PARAM_UNSUPPORTED,
4475        .enable_rtscts = WMI_TLV_VDEV_PARAM_ENABLE_RTSCTS,
4476        .txbf = WMI_TLV_VDEV_PARAM_TXBF,
4477        .packet_powersave = WMI_TLV_VDEV_PARAM_PACKET_POWERSAVE,
4478        .drop_unencry = WMI_TLV_VDEV_PARAM_DROP_UNENCRY,
4479        .tx_encap_type = WMI_TLV_VDEV_PARAM_TX_ENCAP_TYPE,
4480        .ap_detect_out_of_sync_sleeping_sta_time_secs =
4481                                        WMI_TLV_VDEV_PARAM_UNSUPPORTED,
4482        .rc_num_retries = WMI_VDEV_PARAM_UNSUPPORTED,
4483        .cabq_maxdur = WMI_VDEV_PARAM_UNSUPPORTED,
4484        .mfptest_set = WMI_VDEV_PARAM_UNSUPPORTED,
4485        .rts_fixed_rate = WMI_VDEV_PARAM_UNSUPPORTED,
4486        .vht_sgimask = WMI_VDEV_PARAM_UNSUPPORTED,
4487        .vht80_ratemask = WMI_VDEV_PARAM_UNSUPPORTED,
4488        .early_rx_adjust_enable = WMI_VDEV_PARAM_UNSUPPORTED,
4489        .early_rx_tgt_bmiss_num = WMI_VDEV_PARAM_UNSUPPORTED,
4490        .early_rx_bmiss_sample_cycle = WMI_VDEV_PARAM_UNSUPPORTED,
4491        .early_rx_slop_step = WMI_VDEV_PARAM_UNSUPPORTED,
4492        .early_rx_init_slop = WMI_VDEV_PARAM_UNSUPPORTED,
4493        .early_rx_adjust_pause = WMI_VDEV_PARAM_UNSUPPORTED,
4494        .proxy_sta = WMI_VDEV_PARAM_UNSUPPORTED,
4495        .meru_vc = WMI_VDEV_PARAM_UNSUPPORTED,
4496        .rx_decap_type = WMI_VDEV_PARAM_UNSUPPORTED,
4497        .bw_nss_ratemask = WMI_VDEV_PARAM_UNSUPPORTED,
4498};
4499
4500static const struct wmi_ops wmi_tlv_ops = {
4501        .rx = ath10k_wmi_tlv_op_rx,
4502        .map_svc = wmi_tlv_svc_map,
4503        .map_svc_ext = wmi_tlv_svc_map_ext,
4504
4505        .pull_scan = ath10k_wmi_tlv_op_pull_scan_ev,
4506        .pull_mgmt_rx = ath10k_wmi_tlv_op_pull_mgmt_rx_ev,
4507        .pull_mgmt_tx_compl = ath10k_wmi_tlv_op_pull_mgmt_tx_compl_ev,
4508        .pull_mgmt_tx_bundle_compl = ath10k_wmi_tlv_op_pull_mgmt_tx_bundle_compl_ev,
4509        .pull_ch_info = ath10k_wmi_tlv_op_pull_ch_info_ev,
4510        .pull_vdev_start = ath10k_wmi_tlv_op_pull_vdev_start_ev,
4511        .pull_peer_kick = ath10k_wmi_tlv_op_pull_peer_kick_ev,
4512        .pull_swba = ath10k_wmi_tlv_op_pull_swba_ev,
4513        .pull_phyerr_hdr = ath10k_wmi_tlv_op_pull_phyerr_ev_hdr,
4514        .pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
4515        .pull_svc_rdy = ath10k_wmi_tlv_op_pull_svc_rdy_ev,
4516        .pull_rdy = ath10k_wmi_tlv_op_pull_rdy_ev,
4517        .pull_svc_avail = ath10k_wmi_tlv_op_pull_svc_avail,
4518        .pull_fw_stats = ath10k_wmi_tlv_op_pull_fw_stats,
4519        .pull_roam_ev = ath10k_wmi_tlv_op_pull_roam_ev,
4520        .pull_wow_event = ath10k_wmi_tlv_op_pull_wow_ev,
4521        .pull_echo_ev = ath10k_wmi_tlv_op_pull_echo_ev,
4522        .get_txbf_conf_scheme = ath10k_wmi_tlv_txbf_conf_scheme,
4523
4524        .gen_pdev_suspend = ath10k_wmi_tlv_op_gen_pdev_suspend,
4525        .gen_pdev_resume = ath10k_wmi_tlv_op_gen_pdev_resume,
4526        .gen_pdev_set_rd = ath10k_wmi_tlv_op_gen_pdev_set_rd,
4527        .gen_pdev_set_param = ath10k_wmi_tlv_op_gen_pdev_set_param,
4528        .gen_init = ath10k_wmi_tlv_op_gen_init,
4529        .gen_start_scan = ath10k_wmi_tlv_op_gen_start_scan,
4530        .gen_stop_scan = ath10k_wmi_tlv_op_gen_stop_scan,
4531        .gen_vdev_create = ath10k_wmi_tlv_op_gen_vdev_create,
4532        .gen_vdev_delete = ath10k_wmi_tlv_op_gen_vdev_delete,
4533        .gen_vdev_start = ath10k_wmi_tlv_op_gen_vdev_start,
4534        .gen_vdev_stop = ath10k_wmi_tlv_op_gen_vdev_stop,
4535        .gen_vdev_up = ath10k_wmi_tlv_op_gen_vdev_up,
4536        .gen_vdev_down = ath10k_wmi_tlv_op_gen_vdev_down,
4537        .gen_vdev_set_param = ath10k_wmi_tlv_op_gen_vdev_set_param,
4538        .gen_vdev_install_key = ath10k_wmi_tlv_op_gen_vdev_install_key,
4539        .gen_vdev_wmm_conf = ath10k_wmi_tlv_op_gen_vdev_wmm_conf,
4540        .gen_peer_create = ath10k_wmi_tlv_op_gen_peer_create,
4541        .gen_peer_delete = ath10k_wmi_tlv_op_gen_peer_delete,
4542        .gen_peer_flush = ath10k_wmi_tlv_op_gen_peer_flush,
4543        .gen_peer_set_param = ath10k_wmi_tlv_op_gen_peer_set_param,
4544        .gen_peer_assoc = ath10k_wmi_tlv_op_gen_peer_assoc,
4545        .gen_set_psmode = ath10k_wmi_tlv_op_gen_set_psmode,
4546        .gen_set_sta_ps = ath10k_wmi_tlv_op_gen_set_sta_ps,
4547        .gen_set_ap_ps = ath10k_wmi_tlv_op_gen_set_ap_ps,
4548        .gen_scan_chan_list = ath10k_wmi_tlv_op_gen_scan_chan_list,
4549        .gen_scan_prob_req_oui = ath10k_wmi_tlv_op_gen_scan_prob_req_oui,
4550        .gen_beacon_dma = ath10k_wmi_tlv_op_gen_beacon_dma,
4551        .gen_pdev_set_wmm = ath10k_wmi_tlv_op_gen_pdev_set_wmm,
4552        .gen_request_stats = ath10k_wmi_tlv_op_gen_request_stats,
4553        .gen_request_peer_stats_info = ath10k_wmi_tlv_op_gen_request_peer_stats_info,
4554        .gen_force_fw_hang = ath10k_wmi_tlv_op_gen_force_fw_hang,
4555        /* .gen_mgmt_tx = not implemented; HTT is used */
4556        .gen_mgmt_tx_send = ath10k_wmi_tlv_op_gen_mgmt_tx_send,
4557        .cleanup_mgmt_tx_send = ath10k_wmi_tlv_op_cleanup_mgmt_tx_send,
4558        .gen_dbglog_cfg = ath10k_wmi_tlv_op_gen_dbglog_cfg,
4559        .gen_pktlog_enable = ath10k_wmi_tlv_op_gen_pktlog_enable,
4560        .gen_pktlog_disable = ath10k_wmi_tlv_op_gen_pktlog_disable,
4561        .gen_pdev_set_quiet_mode = ath10k_wmi_tlv_op_gen_pdev_set_quiet_mode,
4562        .gen_pdev_get_temperature = ath10k_wmi_tlv_op_gen_pdev_get_temperature,
4563        /* .gen_addba_clear_resp not implemented */
4564        /* .gen_addba_send not implemented */
4565        /* .gen_addba_set_resp not implemented */
4566        /* .gen_delba_send not implemented */
4567        .gen_bcn_tmpl = ath10k_wmi_tlv_op_gen_bcn_tmpl,
4568        .gen_prb_tmpl = ath10k_wmi_tlv_op_gen_prb_tmpl,
4569        .gen_p2p_go_bcn_ie = ath10k_wmi_tlv_op_gen_p2p_go_bcn_ie,
4570        .gen_vdev_sta_uapsd = ath10k_wmi_tlv_op_gen_vdev_sta_uapsd,
4571        .gen_sta_keepalive = ath10k_wmi_tlv_op_gen_sta_keepalive,
4572        .gen_wow_enable = ath10k_wmi_tlv_op_gen_wow_enable,
4573        .gen_wow_add_wakeup_event = ath10k_wmi_tlv_op_gen_wow_add_wakeup_event,
4574        .gen_wow_host_wakeup_ind = ath10k_wmi_tlv_gen_wow_host_wakeup_ind,
4575        .gen_wow_add_pattern = ath10k_wmi_tlv_op_gen_wow_add_pattern,
4576        .gen_wow_del_pattern = ath10k_wmi_tlv_op_gen_wow_del_pattern,
4577        .gen_wow_config_pno = ath10k_wmi_tlv_op_gen_config_pno,
4578        .gen_update_fw_tdls_state = ath10k_wmi_tlv_op_gen_update_fw_tdls_state,
4579        .gen_tdls_peer_update = ath10k_wmi_tlv_op_gen_tdls_peer_update,
4580        .gen_adaptive_qcs = ath10k_wmi_tlv_op_gen_adaptive_qcs,
4581        .fw_stats_fill = ath10k_wmi_main_op_fw_stats_fill,
4582        .get_vdev_subtype = ath10k_wmi_tlv_op_get_vdev_subtype,
4583        .gen_echo = ath10k_wmi_tlv_op_gen_echo,
4584        .gen_vdev_spectral_conf = ath10k_wmi_tlv_op_gen_vdev_spectral_conf,
4585        .gen_vdev_spectral_enable = ath10k_wmi_tlv_op_gen_vdev_spectral_enable,
4586};
4587
4588static const struct wmi_peer_flags_map wmi_tlv_peer_flags_map = {
4589        .auth = WMI_TLV_PEER_AUTH,
4590        .qos = WMI_TLV_PEER_QOS,
4591        .need_ptk_4_way = WMI_TLV_PEER_NEED_PTK_4_WAY,
4592        .need_gtk_2_way = WMI_TLV_PEER_NEED_GTK_2_WAY,
4593        .apsd = WMI_TLV_PEER_APSD,
4594        .ht = WMI_TLV_PEER_HT,
4595        .bw40 = WMI_TLV_PEER_40MHZ,
4596        .stbc = WMI_TLV_PEER_STBC,
4597        .ldbc = WMI_TLV_PEER_LDPC,
4598        .dyn_mimops = WMI_TLV_PEER_DYN_MIMOPS,
4599        .static_mimops = WMI_TLV_PEER_STATIC_MIMOPS,
4600        .spatial_mux = WMI_TLV_PEER_SPATIAL_MUX,
4601        .vht = WMI_TLV_PEER_VHT,
4602        .bw80 = WMI_TLV_PEER_80MHZ,
4603        .pmf = WMI_TLV_PEER_PMF,
4604        .bw160 = WMI_TLV_PEER_160MHZ,
4605};
4606
4607/************/
4608/* TLV init */
4609/************/
4610
4611void ath10k_wmi_tlv_attach(struct ath10k *ar)
4612{
4613        ar->wmi.cmd = &wmi_tlv_cmd_map;
4614        ar->wmi.vdev_param = &wmi_tlv_vdev_param_map;
4615        ar->wmi.pdev_param = &wmi_tlv_pdev_param_map;
4616        ar->wmi.peer_param = &wmi_tlv_peer_param_map;
4617        ar->wmi.ops = &wmi_tlv_ops;
4618        ar->wmi.peer_flags = &wmi_tlv_peer_flags_map;
4619}
4620