linux/drivers/net/wireless/ath/ath6kl/wmi.c
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2004-2011 Atheros Communications Inc.
   3 *
   4 * Permission to use, copy, modify, and/or distribute this software for any
   5 * purpose with or without fee is hereby granted, provided that the above
   6 * copyright notice and this permission notice appear in all copies.
   7 *
   8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15 */
  16
  17#include <linux/ip.h>
  18#include "core.h"
  19#include "debug.h"
  20#include "testmode.h"
  21#include "../regd.h"
  22#include "../regd_common.h"
  23
  24static int ath6kl_wmi_sync_point(struct wmi *wmi);
  25
  26static const s32 wmi_rate_tbl[][2] = {
  27        /* {W/O SGI, with SGI} */
  28        {1000, 1000},
  29        {2000, 2000},
  30        {5500, 5500},
  31        {11000, 11000},
  32        {6000, 6000},
  33        {9000, 9000},
  34        {12000, 12000},
  35        {18000, 18000},
  36        {24000, 24000},
  37        {36000, 36000},
  38        {48000, 48000},
  39        {54000, 54000},
  40        {6500, 7200},
  41        {13000, 14400},
  42        {19500, 21700},
  43        {26000, 28900},
  44        {39000, 43300},
  45        {52000, 57800},
  46        {58500, 65000},
  47        {65000, 72200},
  48        {13500, 15000},
  49        {27000, 30000},
  50        {40500, 45000},
  51        {54000, 60000},
  52        {81000, 90000},
  53        {108000, 120000},
  54        {121500, 135000},
  55        {135000, 150000},
  56        {0, 0}
  57};
  58
  59/* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
  60static const u8 up_to_ac[] = {
  61        WMM_AC_BE,
  62        WMM_AC_BK,
  63        WMM_AC_BK,
  64        WMM_AC_BE,
  65        WMM_AC_VI,
  66        WMM_AC_VI,
  67        WMM_AC_VO,
  68        WMM_AC_VO,
  69};
  70
  71void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
  72{
  73        if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
  74                return;
  75
  76        wmi->ep_id = ep_id;
  77}
  78
  79enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
  80{
  81        return wmi->ep_id;
  82}
  83
  84/*  Performs DIX to 802.3 encapsulation for transmit packets.
  85 *  Assumes the entire DIX header is contigous and that there is
  86 *  enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
  87 */
  88int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
  89{
  90        struct ath6kl_llc_snap_hdr *llc_hdr;
  91        struct ethhdr *eth_hdr;
  92        size_t new_len;
  93        __be16 type;
  94        u8 *datap;
  95        u16 size;
  96
  97        if (WARN_ON(skb == NULL))
  98                return -EINVAL;
  99
 100        size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
 101        if (skb_headroom(skb) < size)
 102                return -ENOMEM;
 103
 104        eth_hdr = (struct ethhdr *) skb->data;
 105        type = eth_hdr->h_proto;
 106
 107        if (!is_ethertype(be16_to_cpu(type))) {
 108                ath6kl_dbg(ATH6KL_DBG_WMI,
 109                        "%s: pkt is already in 802.3 format\n", __func__);
 110                return 0;
 111        }
 112
 113        new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
 114
 115        skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
 116        datap = skb->data;
 117
 118        eth_hdr->h_proto = cpu_to_be16(new_len);
 119
 120        memcpy(datap, eth_hdr, sizeof(*eth_hdr));
 121
 122        llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
 123        llc_hdr->dsap = 0xAA;
 124        llc_hdr->ssap = 0xAA;
 125        llc_hdr->cntl = 0x03;
 126        llc_hdr->org_code[0] = 0x0;
 127        llc_hdr->org_code[1] = 0x0;
 128        llc_hdr->org_code[2] = 0x0;
 129        llc_hdr->eth_type = type;
 130
 131        return 0;
 132}
 133
 134static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
 135                               u8 *version, void *tx_meta_info)
 136{
 137        struct wmi_tx_meta_v1 *v1;
 138        struct wmi_tx_meta_v2 *v2;
 139
 140        if (WARN_ON(skb == NULL || version == NULL))
 141                return -EINVAL;
 142
 143        switch (*version) {
 144        case WMI_META_VERSION_1:
 145                skb_push(skb, WMI_MAX_TX_META_SZ);
 146                v1 = (struct wmi_tx_meta_v1 *) skb->data;
 147                v1->pkt_id = 0;
 148                v1->rate_plcy_id = 0;
 149                *version = WMI_META_VERSION_1;
 150                break;
 151        case WMI_META_VERSION_2:
 152                skb_push(skb, WMI_MAX_TX_META_SZ);
 153                v2 = (struct wmi_tx_meta_v2 *) skb->data;
 154                memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
 155                       sizeof(struct wmi_tx_meta_v2));
 156                break;
 157        }
 158
 159        return 0;
 160}
 161
 162int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
 163                            u8 msg_type, bool more_data,
 164                            enum wmi_data_hdr_data_type data_type,
 165                            u8 meta_ver, void *tx_meta_info)
 166{
 167        struct wmi_data_hdr *data_hdr;
 168        int ret;
 169
 170        if (WARN_ON(skb == NULL))
 171                return -EINVAL;
 172
 173        if (tx_meta_info) {
 174                ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
 175                if (ret)
 176                        return ret;
 177        }
 178
 179        skb_push(skb, sizeof(struct wmi_data_hdr));
 180
 181        data_hdr = (struct wmi_data_hdr *)skb->data;
 182        memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
 183
 184        data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
 185        data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
 186
 187        if (more_data)
 188                data_hdr->info |=
 189                    WMI_DATA_HDR_MORE_MASK << WMI_DATA_HDR_MORE_SHIFT;
 190
 191        data_hdr->info2 = cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
 192        data_hdr->info3 = 0;
 193
 194        return 0;
 195}
 196
 197static u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
 198{
 199        struct iphdr *ip_hdr = (struct iphdr *) pkt;
 200        u8 ip_pri;
 201
 202        /*
 203         * Determine IPTOS priority
 204         *
 205         * IP-TOS - 8bits
 206         *          : DSCP(6-bits) ECN(2-bits)
 207         *          : DSCP - P2 P1 P0 X X X
 208         * where (P2 P1 P0) form 802.1D
 209         */
 210        ip_pri = ip_hdr->tos >> 5;
 211        ip_pri &= 0x7;
 212
 213        if ((layer2_pri & 0x7) > ip_pri)
 214                return (u8) layer2_pri & 0x7;
 215        else
 216                return ip_pri;
 217}
 218
 219int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, struct sk_buff *skb,
 220                                       u32 layer2_priority, bool wmm_enabled,
 221                                       u8 *ac)
 222{
 223        struct wmi_data_hdr *data_hdr;
 224        struct ath6kl_llc_snap_hdr *llc_hdr;
 225        struct wmi_create_pstream_cmd cmd;
 226        u32 meta_size, hdr_size;
 227        u16 ip_type = IP_ETHERTYPE;
 228        u8 stream_exist, usr_pri;
 229        u8 traffic_class = WMM_AC_BE;
 230        u8 *datap;
 231
 232        if (WARN_ON(skb == NULL))
 233                return -EINVAL;
 234
 235        datap = skb->data;
 236        data_hdr = (struct wmi_data_hdr *) datap;
 237
 238        meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
 239                     WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
 240
 241        if (!wmm_enabled) {
 242                /* If WMM is disabled all traffic goes as BE traffic */
 243                usr_pri = 0;
 244        } else {
 245                hdr_size = sizeof(struct ethhdr);
 246
 247                llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
 248                                                         sizeof(struct
 249                                                                wmi_data_hdr) +
 250                                                         meta_size + hdr_size);
 251
 252                if (llc_hdr->eth_type == htons(ip_type)) {
 253                        /*
 254                         * Extract the endpoint info from the TOS field
 255                         * in the IP header.
 256                         */
 257                        usr_pri =
 258                           ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
 259                                        sizeof(struct ath6kl_llc_snap_hdr),
 260                                        layer2_priority);
 261                } else
 262                        usr_pri = layer2_priority & 0x7;
 263        }
 264
 265        /* workaround for WMM S5 */
 266        if ((wmi->traffic_class == WMM_AC_VI) &&
 267            ((usr_pri == 5) || (usr_pri == 4)))
 268                usr_pri = 1;
 269
 270        /* Convert user priority to traffic class */
 271        traffic_class = up_to_ac[usr_pri & 0x7];
 272
 273        wmi_data_hdr_set_up(data_hdr, usr_pri);
 274
 275        spin_lock_bh(&wmi->lock);
 276        stream_exist = wmi->fat_pipe_exist;
 277        spin_unlock_bh(&wmi->lock);
 278
 279        if (!(stream_exist & (1 << traffic_class))) {
 280                memset(&cmd, 0, sizeof(cmd));
 281                cmd.traffic_class = traffic_class;
 282                cmd.user_pri = usr_pri;
 283                cmd.inactivity_int =
 284                        cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
 285                /* Implicit streams are created with TSID 0xFF */
 286                cmd.tsid = WMI_IMPLICIT_PSTREAM;
 287                ath6kl_wmi_create_pstream_cmd(wmi, &cmd);
 288        }
 289
 290        *ac = traffic_class;
 291
 292        return 0;
 293}
 294
 295int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
 296{
 297        struct ieee80211_hdr_3addr *pwh, wh;
 298        struct ath6kl_llc_snap_hdr *llc_hdr;
 299        struct ethhdr eth_hdr;
 300        u32 hdr_size;
 301        u8 *datap;
 302        __le16 sub_type;
 303
 304        if (WARN_ON(skb == NULL))
 305                return -EINVAL;
 306
 307        datap = skb->data;
 308        pwh = (struct ieee80211_hdr_3addr *) datap;
 309
 310        sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
 311
 312        memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
 313
 314        /* Strip off the 802.11 header */
 315        if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
 316                hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
 317                                   sizeof(u32));
 318                skb_pull(skb, hdr_size);
 319        } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA))
 320                skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
 321
 322        datap = skb->data;
 323        llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
 324
 325        memset(&eth_hdr, 0, sizeof(eth_hdr));
 326        eth_hdr.h_proto = llc_hdr->eth_type;
 327
 328        switch ((le16_to_cpu(wh.frame_control)) &
 329                (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
 330        case 0:
 331                memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
 332                memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
 333                break;
 334        case IEEE80211_FCTL_TODS:
 335                memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
 336                memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
 337                break;
 338        case IEEE80211_FCTL_FROMDS:
 339                memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
 340                memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
 341                break;
 342        case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
 343                break;
 344        }
 345
 346        skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
 347        skb_push(skb, sizeof(eth_hdr));
 348
 349        datap = skb->data;
 350
 351        memcpy(datap, &eth_hdr, sizeof(eth_hdr));
 352
 353        return 0;
 354}
 355
 356/*
 357 * Performs 802.3 to DIX encapsulation for received packets.
 358 * Assumes the entire 802.3 header is contigous.
 359 */
 360int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
 361{
 362        struct ath6kl_llc_snap_hdr *llc_hdr;
 363        struct ethhdr eth_hdr;
 364        u8 *datap;
 365
 366        if (WARN_ON(skb == NULL))
 367                return -EINVAL;
 368
 369        datap = skb->data;
 370
 371        memcpy(&eth_hdr, datap, sizeof(eth_hdr));
 372
 373        llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
 374        eth_hdr.h_proto = llc_hdr->eth_type;
 375
 376        skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
 377        datap = skb->data;
 378
 379        memcpy(datap, &eth_hdr, sizeof(eth_hdr));
 380
 381        return 0;
 382}
 383
 384static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
 385{
 386        struct tx_complete_msg_v1 *msg_v1;
 387        struct wmi_tx_complete_event *evt;
 388        int index;
 389        u16 size;
 390
 391        evt = (struct wmi_tx_complete_event *) datap;
 392
 393        ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
 394                   evt->num_msg, evt->msg_len, evt->msg_type);
 395
 396        if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_WMI))
 397                return 0;
 398
 399        for (index = 0; index < evt->num_msg; index++) {
 400                size = sizeof(struct wmi_tx_complete_event) +
 401                    (index * sizeof(struct tx_complete_msg_v1));
 402                msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
 403
 404                ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
 405                           msg_v1->status, msg_v1->pkt_id,
 406                           msg_v1->rate_idx, msg_v1->ack_failures);
 407        }
 408
 409        return 0;
 410}
 411
 412static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
 413                                              int len)
 414{
 415        struct wmi_remain_on_chnl_event *ev;
 416        u32 freq;
 417        u32 dur;
 418        struct ieee80211_channel *chan;
 419        struct ath6kl *ar = wmi->parent_dev;
 420
 421        if (len < sizeof(*ev))
 422                return -EINVAL;
 423
 424        ev = (struct wmi_remain_on_chnl_event *) datap;
 425        freq = le32_to_cpu(ev->freq);
 426        dur = le32_to_cpu(ev->duration);
 427        ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
 428                   freq, dur);
 429        chan = ieee80211_get_channel(ar->wdev->wiphy, freq);
 430        if (!chan) {
 431                ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: Unknown channel "
 432                           "(freq=%u)\n", freq);
 433                return -EINVAL;
 434        }
 435        cfg80211_ready_on_channel(ar->net_dev, 1, chan, NL80211_CHAN_NO_HT,
 436                                  dur, GFP_ATOMIC);
 437
 438        return 0;
 439}
 440
 441static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
 442                                                     u8 *datap, int len)
 443{
 444        struct wmi_cancel_remain_on_chnl_event *ev;
 445        u32 freq;
 446        u32 dur;
 447        struct ieee80211_channel *chan;
 448        struct ath6kl *ar = wmi->parent_dev;
 449
 450        if (len < sizeof(*ev))
 451                return -EINVAL;
 452
 453        ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
 454        freq = le32_to_cpu(ev->freq);
 455        dur = le32_to_cpu(ev->duration);
 456        ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: freq=%u dur=%u "
 457                   "status=%u\n", freq, dur, ev->status);
 458        chan = ieee80211_get_channel(ar->wdev->wiphy, freq);
 459        if (!chan) {
 460                ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: Unknown "
 461                           "channel (freq=%u)\n", freq);
 462                return -EINVAL;
 463        }
 464        cfg80211_remain_on_channel_expired(ar->net_dev, 1, chan,
 465                                           NL80211_CHAN_NO_HT, GFP_ATOMIC);
 466
 467        return 0;
 468}
 469
 470static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len)
 471{
 472        struct wmi_tx_status_event *ev;
 473        u32 id;
 474        struct ath6kl *ar = wmi->parent_dev;
 475
 476        if (len < sizeof(*ev))
 477                return -EINVAL;
 478
 479        ev = (struct wmi_tx_status_event *) datap;
 480        id = le32_to_cpu(ev->id);
 481        ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
 482                   id, ev->ack_status);
 483        if (wmi->last_mgmt_tx_frame) {
 484                cfg80211_mgmt_tx_status(ar->net_dev, id,
 485                                        wmi->last_mgmt_tx_frame,
 486                                        wmi->last_mgmt_tx_frame_len,
 487                                        !!ev->ack_status, GFP_ATOMIC);
 488                kfree(wmi->last_mgmt_tx_frame);
 489                wmi->last_mgmt_tx_frame = NULL;
 490                wmi->last_mgmt_tx_frame_len = 0;
 491        }
 492
 493        return 0;
 494}
 495
 496static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len)
 497{
 498        struct wmi_p2p_rx_probe_req_event *ev;
 499        u32 freq;
 500        u16 dlen;
 501        struct ath6kl *ar = wmi->parent_dev;
 502
 503        if (len < sizeof(*ev))
 504                return -EINVAL;
 505
 506        ev = (struct wmi_p2p_rx_probe_req_event *) datap;
 507        freq = le32_to_cpu(ev->freq);
 508        dlen = le16_to_cpu(ev->len);
 509        if (datap + len < ev->data + dlen) {
 510                ath6kl_err("invalid wmi_p2p_rx_probe_req_event: "
 511                           "len=%d dlen=%u\n", len, dlen);
 512                return -EINVAL;
 513        }
 514        ath6kl_dbg(ATH6KL_DBG_WMI, "rx_probe_req: len=%u freq=%u "
 515                   "probe_req_report=%d\n",
 516                   dlen, freq, ar->probe_req_report);
 517
 518        if (ar->probe_req_report || ar->nw_type == AP_NETWORK)
 519                cfg80211_rx_mgmt(ar->net_dev, freq, ev->data, dlen, GFP_ATOMIC);
 520
 521        return 0;
 522}
 523
 524static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
 525{
 526        struct wmi_p2p_capabilities_event *ev;
 527        u16 dlen;
 528
 529        if (len < sizeof(*ev))
 530                return -EINVAL;
 531
 532        ev = (struct wmi_p2p_capabilities_event *) datap;
 533        dlen = le16_to_cpu(ev->len);
 534        ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
 535
 536        return 0;
 537}
 538
 539static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len)
 540{
 541        struct wmi_rx_action_event *ev;
 542        u32 freq;
 543        u16 dlen;
 544        struct ath6kl *ar = wmi->parent_dev;
 545
 546        if (len < sizeof(*ev))
 547                return -EINVAL;
 548
 549        ev = (struct wmi_rx_action_event *) datap;
 550        freq = le32_to_cpu(ev->freq);
 551        dlen = le16_to_cpu(ev->len);
 552        if (datap + len < ev->data + dlen) {
 553                ath6kl_err("invalid wmi_rx_action_event: "
 554                           "len=%d dlen=%u\n", len, dlen);
 555                return -EINVAL;
 556        }
 557        ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
 558        cfg80211_rx_mgmt(ar->net_dev, freq, ev->data, dlen, GFP_ATOMIC);
 559
 560        return 0;
 561}
 562
 563static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
 564{
 565        struct wmi_p2p_info_event *ev;
 566        u32 flags;
 567        u16 dlen;
 568
 569        if (len < sizeof(*ev))
 570                return -EINVAL;
 571
 572        ev = (struct wmi_p2p_info_event *) datap;
 573        flags = le32_to_cpu(ev->info_req_flags);
 574        dlen = le16_to_cpu(ev->len);
 575        ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
 576
 577        if (flags & P2P_FLAG_CAPABILITIES_REQ) {
 578                struct wmi_p2p_capabilities *cap;
 579                if (dlen < sizeof(*cap))
 580                        return -EINVAL;
 581                cap = (struct wmi_p2p_capabilities *) ev->data;
 582                ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
 583                           cap->go_power_save);
 584        }
 585
 586        if (flags & P2P_FLAG_MACADDR_REQ) {
 587                struct wmi_p2p_macaddr *mac;
 588                if (dlen < sizeof(*mac))
 589                        return -EINVAL;
 590                mac = (struct wmi_p2p_macaddr *) ev->data;
 591                ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
 592                           mac->mac_addr);
 593        }
 594
 595        if (flags & P2P_FLAG_HMODEL_REQ) {
 596                struct wmi_p2p_hmodel *mod;
 597                if (dlen < sizeof(*mod))
 598                        return -EINVAL;
 599                mod = (struct wmi_p2p_hmodel *) ev->data;
 600                ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
 601                           mod->p2p_model,
 602                           mod->p2p_model ? "host" : "firmware");
 603        }
 604        return 0;
 605}
 606
 607static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
 608{
 609        struct sk_buff *skb;
 610
 611        skb = ath6kl_buf_alloc(size);
 612        if (!skb)
 613                return NULL;
 614
 615        skb_put(skb, size);
 616        if (size)
 617                memset(skb->data, 0, size);
 618
 619        return skb;
 620}
 621
 622/* Send a "simple" wmi command -- one with no arguments */
 623static int ath6kl_wmi_simple_cmd(struct wmi *wmi, enum wmi_cmd_id cmd_id)
 624{
 625        struct sk_buff *skb;
 626        int ret;
 627
 628        skb = ath6kl_wmi_get_new_buf(0);
 629        if (!skb)
 630                return -ENOMEM;
 631
 632        ret = ath6kl_wmi_cmd_send(wmi, skb, cmd_id, NO_SYNC_WMIFLAG);
 633
 634        return ret;
 635}
 636
 637static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
 638{
 639        struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
 640
 641        if (len < sizeof(struct wmi_ready_event_2))
 642                return -EINVAL;
 643
 644        wmi->ready = true;
 645        ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
 646                           le32_to_cpu(ev->sw_version),
 647                           le32_to_cpu(ev->abi_version));
 648
 649        return 0;
 650}
 651
 652/*
 653 * Mechanism to modify the roaming behavior in the firmware. The lower rssi
 654 * at which the station has to roam can be passed with
 655 * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
 656 * in dBm.
 657 */
 658int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
 659{
 660        struct sk_buff *skb;
 661        struct roam_ctrl_cmd *cmd;
 662
 663        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
 664        if (!skb)
 665                return -ENOMEM;
 666
 667        cmd = (struct roam_ctrl_cmd *) skb->data;
 668
 669        cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
 670        cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
 671                                                       DEF_SCAN_FOR_ROAM_INTVL);
 672        cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
 673        cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
 674        cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
 675
 676        ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_ROAM_CTRL_CMDID, NO_SYNC_WMIFLAG);
 677
 678        return 0;
 679}
 680
 681static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len)
 682{
 683        struct wmi_connect_event *ev;
 684        u8 *pie, *peie;
 685        struct ath6kl *ar = wmi->parent_dev;
 686
 687        if (len < sizeof(struct wmi_connect_event))
 688                return -EINVAL;
 689
 690        ev = (struct wmi_connect_event *) datap;
 691
 692        if (ar->nw_type == AP_NETWORK) {
 693                /* AP mode start/STA connected event */
 694                struct net_device *dev = ar->net_dev;
 695                if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
 696                        ath6kl_dbg(ATH6KL_DBG_WMI, "%s: freq %d bssid %pM "
 697                                   "(AP started)\n",
 698                                   __func__, le16_to_cpu(ev->u.ap_bss.ch),
 699                                   ev->u.ap_bss.bssid);
 700                        ath6kl_connect_ap_mode_bss(
 701                                ar, le16_to_cpu(ev->u.ap_bss.ch));
 702                } else {
 703                        ath6kl_dbg(ATH6KL_DBG_WMI, "%s: aid %u mac_addr %pM "
 704                                   "auth=%u keymgmt=%u cipher=%u apsd_info=%u "
 705                                   "(STA connected)\n",
 706                                   __func__, ev->u.ap_sta.aid,
 707                                   ev->u.ap_sta.mac_addr,
 708                                   ev->u.ap_sta.auth,
 709                                   ev->u.ap_sta.keymgmt,
 710                                   le16_to_cpu(ev->u.ap_sta.cipher),
 711                                   ev->u.ap_sta.apsd_info);
 712                        ath6kl_connect_ap_mode_sta(
 713                                ar, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
 714                                ev->u.ap_sta.keymgmt,
 715                                le16_to_cpu(ev->u.ap_sta.cipher),
 716                                ev->u.ap_sta.auth, ev->assoc_req_len,
 717                                ev->assoc_info + ev->beacon_ie_len);
 718                }
 719                return 0;
 720        }
 721
 722        /* STA/IBSS mode connection event */
 723
 724        ath6kl_dbg(ATH6KL_DBG_WMI,
 725                   "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
 726                   le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
 727                   le16_to_cpu(ev->u.sta.listen_intvl),
 728                   le16_to_cpu(ev->u.sta.beacon_intvl),
 729                   le32_to_cpu(ev->u.sta.nw_type));
 730
 731        /* Start of assoc rsp IEs */
 732        pie = ev->assoc_info + ev->beacon_ie_len +
 733              ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
 734
 735        /* End of assoc rsp IEs */
 736        peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
 737            ev->assoc_resp_len;
 738
 739        while (pie < peie) {
 740                switch (*pie) {
 741                case WLAN_EID_VENDOR_SPECIFIC:
 742                        if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
 743                            pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
 744                                /* WMM OUT (00:50:F2) */
 745                                if (pie[1] > 5
 746                                    && pie[6] == WMM_PARAM_OUI_SUBTYPE)
 747                                        wmi->is_wmm_enabled = true;
 748                        }
 749                        break;
 750                }
 751
 752                if (wmi->is_wmm_enabled)
 753                        break;
 754
 755                pie += pie[1] + 2;
 756        }
 757
 758        ath6kl_connect_event(wmi->parent_dev, le16_to_cpu(ev->u.sta.ch),
 759                             ev->u.sta.bssid,
 760                             le16_to_cpu(ev->u.sta.listen_intvl),
 761                             le16_to_cpu(ev->u.sta.beacon_intvl),
 762                             le32_to_cpu(ev->u.sta.nw_type),
 763                             ev->beacon_ie_len, ev->assoc_req_len,
 764                             ev->assoc_resp_len, ev->assoc_info);
 765
 766        return 0;
 767}
 768
 769static struct country_code_to_enum_rd *
 770ath6kl_regd_find_country(u16 countryCode)
 771{
 772        int i;
 773
 774        for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
 775                if (allCountries[i].countryCode == countryCode)
 776                        return &allCountries[i];
 777        }
 778
 779        return NULL;
 780}
 781
 782static struct reg_dmn_pair_mapping *
 783ath6kl_get_regpair(u16 regdmn)
 784{
 785        int i;
 786
 787        if (regdmn == NO_ENUMRD)
 788                return NULL;
 789
 790        for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
 791                if (regDomainPairs[i].regDmnEnum == regdmn)
 792                        return &regDomainPairs[i];
 793        }
 794
 795        return NULL;
 796}
 797
 798static struct country_code_to_enum_rd *
 799ath6kl_regd_find_country_by_rd(u16 regdmn)
 800{
 801        int i;
 802
 803        for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
 804                if (allCountries[i].regDmnEnum == regdmn)
 805                        return &allCountries[i];
 806        }
 807
 808        return NULL;
 809}
 810
 811static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
 812{
 813
 814        struct ath6kl_wmi_regdomain *ev;
 815        struct country_code_to_enum_rd *country = NULL;
 816        struct reg_dmn_pair_mapping *regpair = NULL;
 817        char alpha2[2];
 818        u32 reg_code;
 819
 820        ev = (struct ath6kl_wmi_regdomain *) datap;
 821        reg_code = le32_to_cpu(ev->reg_code);
 822
 823        if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG)
 824                country = ath6kl_regd_find_country((u16) reg_code);
 825        else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
 826
 827                regpair = ath6kl_get_regpair((u16) reg_code);
 828                country = ath6kl_regd_find_country_by_rd((u16) reg_code);
 829                ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
 830                                regpair->regDmnEnum);
 831        }
 832
 833        if (country) {
 834                alpha2[0] = country->isoName[0];
 835                alpha2[1] = country->isoName[1];
 836
 837                regulatory_hint(wmi->parent_dev->wdev->wiphy, alpha2);
 838
 839                ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
 840                                alpha2[0], alpha2[1]);
 841        }
 842}
 843
 844static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len)
 845{
 846        struct wmi_disconnect_event *ev;
 847        wmi->traffic_class = 100;
 848
 849        if (len < sizeof(struct wmi_disconnect_event))
 850                return -EINVAL;
 851
 852        ev = (struct wmi_disconnect_event *) datap;
 853
 854        ath6kl_dbg(ATH6KL_DBG_WMI,
 855                   "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
 856                   le16_to_cpu(ev->proto_reason_status), ev->bssid,
 857                   ev->disconn_reason, ev->assoc_resp_len);
 858
 859        wmi->is_wmm_enabled = false;
 860        wmi->pair_crypto_type = NONE_CRYPT;
 861        wmi->grp_crypto_type = NONE_CRYPT;
 862
 863        ath6kl_disconnect_event(wmi->parent_dev, ev->disconn_reason,
 864                                ev->bssid, ev->assoc_resp_len, ev->assoc_info,
 865                                le16_to_cpu(ev->proto_reason_status));
 866
 867        return 0;
 868}
 869
 870static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
 871{
 872        struct wmi_peer_node_event *ev;
 873
 874        if (len < sizeof(struct wmi_peer_node_event))
 875                return -EINVAL;
 876
 877        ev = (struct wmi_peer_node_event *) datap;
 878
 879        if (ev->event_code == PEER_NODE_JOIN_EVENT)
 880                ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
 881                           ev->peer_mac_addr);
 882        else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
 883                ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
 884                           ev->peer_mac_addr);
 885
 886        return 0;
 887}
 888
 889static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len)
 890{
 891        struct wmi_tkip_micerr_event *ev;
 892
 893        if (len < sizeof(struct wmi_tkip_micerr_event))
 894                return -EINVAL;
 895
 896        ev = (struct wmi_tkip_micerr_event *) datap;
 897
 898        ath6kl_tkip_micerr_event(wmi->parent_dev, ev->key_id, ev->is_mcast);
 899
 900        return 0;
 901}
 902
 903static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len)
 904{
 905        struct wmi_bss_info_hdr2 *bih;
 906        u8 *buf;
 907        struct ieee80211_channel *channel;
 908        struct ath6kl *ar = wmi->parent_dev;
 909        struct ieee80211_mgmt *mgmt;
 910        struct cfg80211_bss *bss;
 911
 912        if (len <= sizeof(struct wmi_bss_info_hdr2))
 913                return -EINVAL;
 914
 915        bih = (struct wmi_bss_info_hdr2 *) datap;
 916        buf = datap + sizeof(struct wmi_bss_info_hdr2);
 917        len -= sizeof(struct wmi_bss_info_hdr2);
 918
 919        ath6kl_dbg(ATH6KL_DBG_WMI,
 920                   "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
 921                   "frame_type=%d\n",
 922                   bih->ch, bih->snr, bih->snr - 95, bih->bssid,
 923                   bih->frame_type);
 924
 925        if (bih->frame_type != BEACON_FTYPE &&
 926            bih->frame_type != PROBERESP_FTYPE)
 927                return 0; /* Only update BSS table for now */
 928
 929        if (bih->frame_type == BEACON_FTYPE &&
 930            test_bit(CLEAR_BSSFILTER_ON_BEACON, &ar->flag)) {
 931                clear_bit(CLEAR_BSSFILTER_ON_BEACON, &ar->flag);
 932                ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0);
 933        }
 934
 935        channel = ieee80211_get_channel(ar->wdev->wiphy, le16_to_cpu(bih->ch));
 936        if (channel == NULL)
 937                return -EINVAL;
 938
 939        if (len < 8 + 2 + 2)
 940                return -EINVAL;
 941
 942        if (bih->frame_type == BEACON_FTYPE && test_bit(CONNECTED, &ar->flag) &&
 943            memcmp(bih->bssid, ar->bssid, ETH_ALEN) == 0) {
 944                const u8 *tim;
 945                tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
 946                                       len - 8 - 2 - 2);
 947                if (tim && tim[1] >= 2) {
 948                        ar->assoc_bss_dtim_period = tim[3];
 949                        set_bit(DTIM_PERIOD_AVAIL, &ar->flag);
 950                }
 951        }
 952
 953        /*
 954         * In theory, use of cfg80211_inform_bss() would be more natural here
 955         * since we do not have the full frame. However, at least for now,
 956         * cfg80211 can only distinguish Beacon and Probe Response frames from
 957         * each other when using cfg80211_inform_bss_frame(), so let's build a
 958         * fake IEEE 802.11 header to be able to take benefit of this.
 959         */
 960        mgmt = kmalloc(24 + len, GFP_ATOMIC);
 961        if (mgmt == NULL)
 962                return -EINVAL;
 963
 964        if (bih->frame_type == BEACON_FTYPE) {
 965                mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
 966                                                  IEEE80211_STYPE_BEACON);
 967                memset(mgmt->da, 0xff, ETH_ALEN);
 968        } else {
 969                struct net_device *dev = ar->net_dev;
 970
 971                mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
 972                                                  IEEE80211_STYPE_PROBE_RESP);
 973                memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
 974        }
 975        mgmt->duration = cpu_to_le16(0);
 976        memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
 977        memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
 978        mgmt->seq_ctrl = cpu_to_le16(0);
 979
 980        memcpy(&mgmt->u.beacon, buf, len);
 981
 982        bss = cfg80211_inform_bss_frame(ar->wdev->wiphy, channel, mgmt,
 983                                        24 + len, (bih->snr - 95) * 100,
 984                                        GFP_ATOMIC);
 985        kfree(mgmt);
 986        if (bss == NULL)
 987                return -ENOMEM;
 988        cfg80211_put_bss(bss);
 989
 990        return 0;
 991}
 992
 993/* Inactivity timeout of a fatpipe(pstream) at the target */
 994static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
 995                                               int len)
 996{
 997        struct wmi_pstream_timeout_event *ev;
 998
 999        if (len < sizeof(struct wmi_pstream_timeout_event))
1000                return -EINVAL;
1001
1002        ev = (struct wmi_pstream_timeout_event *) datap;
1003
1004        /*
1005         * When the pstream (fat pipe == AC) timesout, it means there were
1006         * no thinStreams within this pstream & it got implicitly created
1007         * due to data flow on this AC. We start the inactivity timer only
1008         * for implicitly created pstream. Just reset the host state.
1009         */
1010        spin_lock_bh(&wmi->lock);
1011        wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1012        wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1013        spin_unlock_bh(&wmi->lock);
1014
1015        /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1016        ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1017
1018        return 0;
1019}
1020
1021static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1022{
1023        struct wmi_bit_rate_reply *reply;
1024        s32 rate;
1025        u32 sgi, index;
1026
1027        if (len < sizeof(struct wmi_bit_rate_reply))
1028                return -EINVAL;
1029
1030        reply = (struct wmi_bit_rate_reply *) datap;
1031
1032        ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1033
1034        if (reply->rate_index == (s8) RATE_AUTO) {
1035                rate = RATE_AUTO;
1036        } else {
1037                index = reply->rate_index & 0x7f;
1038                sgi = (reply->rate_index & 0x80) ? 1 : 0;
1039                rate = wmi_rate_tbl[index][sgi];
1040        }
1041
1042        ath6kl_wakeup_event(wmi->parent_dev);
1043
1044        return 0;
1045}
1046
1047static int ath6kl_wmi_tcmd_test_report_rx(struct wmi *wmi, u8 *datap, int len)
1048{
1049        ath6kl_tm_rx_report_event(wmi->parent_dev, datap, len);
1050
1051        return 0;
1052}
1053
1054static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1055{
1056        if (len < sizeof(struct wmi_fix_rates_reply))
1057                return -EINVAL;
1058
1059        ath6kl_wakeup_event(wmi->parent_dev);
1060
1061        return 0;
1062}
1063
1064static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1065{
1066        if (len < sizeof(struct wmi_channel_list_reply))
1067                return -EINVAL;
1068
1069        ath6kl_wakeup_event(wmi->parent_dev);
1070
1071        return 0;
1072}
1073
1074static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1075{
1076        struct wmi_tx_pwr_reply *reply;
1077
1078        if (len < sizeof(struct wmi_tx_pwr_reply))
1079                return -EINVAL;
1080
1081        reply = (struct wmi_tx_pwr_reply *) datap;
1082        ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1083
1084        return 0;
1085}
1086
1087static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1088{
1089        if (len < sizeof(struct wmi_get_keepalive_cmd))
1090                return -EINVAL;
1091
1092        ath6kl_wakeup_event(wmi->parent_dev);
1093
1094        return 0;
1095}
1096
1097static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len)
1098{
1099        struct wmi_scan_complete_event *ev;
1100
1101        ev = (struct wmi_scan_complete_event *) datap;
1102
1103        ath6kl_scan_complete_evt(wmi->parent_dev, a_sle32_to_cpu(ev->status));
1104        wmi->is_probe_ssid = false;
1105
1106        return 0;
1107}
1108
1109static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
1110                                               int len)
1111{
1112        struct wmi_neighbor_report_event *ev;
1113        u8 i;
1114
1115        if (len < sizeof(*ev))
1116                return -EINVAL;
1117        ev = (struct wmi_neighbor_report_event *) datap;
1118        if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
1119            > len) {
1120                ath6kl_dbg(ATH6KL_DBG_WMI, "truncated neighbor event "
1121                           "(num=%d len=%d)\n", ev->num_neighbors, len);
1122                return -EINVAL;
1123        }
1124        for (i = 0; i < ev->num_neighbors; i++) {
1125                ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
1126                           i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
1127                           ev->neighbor[i].bss_flags);
1128                cfg80211_pmksa_candidate_notify(wmi->parent_dev->net_dev, i,
1129                                                ev->neighbor[i].bssid,
1130                                                !!(ev->neighbor[i].bss_flags &
1131                                                   WMI_PREAUTH_CAPABLE_BSS),
1132                                                GFP_ATOMIC);
1133        }
1134
1135        return 0;
1136}
1137
1138/*
1139 * Target is reporting a programming error.  This is for
1140 * developer aid only.  Target only checks a few common violations
1141 * and it is responsibility of host to do all error checking.
1142 * Behavior of target after wmi error event is undefined.
1143 * A reset is recommended.
1144 */
1145static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1146{
1147        const char *type = "unknown error";
1148        struct wmi_cmd_error_event *ev;
1149        ev = (struct wmi_cmd_error_event *) datap;
1150
1151        switch (ev->err_code) {
1152        case INVALID_PARAM:
1153                type = "invalid parameter";
1154                break;
1155        case ILLEGAL_STATE:
1156                type = "invalid state";
1157                break;
1158        case INTERNAL_ERROR:
1159                type = "internal error";
1160                break;
1161        }
1162
1163        ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1164                   ev->cmd_id, type);
1165
1166        return 0;
1167}
1168
1169static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len)
1170{
1171        ath6kl_tgt_stats_event(wmi->parent_dev, datap, len);
1172
1173        return 0;
1174}
1175
1176static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1177                                         struct sq_threshold_params *sq_thresh,
1178                                         u32 size)
1179{
1180        u32 index;
1181        u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1182
1183        /* The list is already in sorted order. Get the next lower value */
1184        for (index = 0; index < size; index++) {
1185                if (rssi < sq_thresh->upper_threshold[index]) {
1186                        threshold = (u8) sq_thresh->upper_threshold[index];
1187                        break;
1188                }
1189        }
1190
1191        return threshold;
1192}
1193
1194static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1195                                         struct sq_threshold_params *sq_thresh,
1196                                         u32 size)
1197{
1198        u32 index;
1199        u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1200
1201        /* The list is already in sorted order. Get the next lower value */
1202        for (index = 0; index < size; index++) {
1203                if (rssi > sq_thresh->lower_threshold[index]) {
1204                        threshold = (u8) sq_thresh->lower_threshold[index];
1205                        break;
1206                }
1207        }
1208
1209        return threshold;
1210}
1211
1212static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1213                        struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1214{
1215        struct sk_buff *skb;
1216        struct wmi_rssi_threshold_params_cmd *cmd;
1217
1218        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1219        if (!skb)
1220                return -ENOMEM;
1221
1222        cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1223        memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1224
1225        return ath6kl_wmi_cmd_send(wmi, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
1226                                   NO_SYNC_WMIFLAG);
1227}
1228
1229static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1230                                              int len)
1231{
1232        struct wmi_rssi_threshold_event *reply;
1233        struct wmi_rssi_threshold_params_cmd cmd;
1234        struct sq_threshold_params *sq_thresh;
1235        enum wmi_rssi_threshold_val new_threshold;
1236        u8 upper_rssi_threshold, lower_rssi_threshold;
1237        s16 rssi;
1238        int ret;
1239
1240        if (len < sizeof(struct wmi_rssi_threshold_event))
1241                return -EINVAL;
1242
1243        reply = (struct wmi_rssi_threshold_event *) datap;
1244        new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1245        rssi = a_sle16_to_cpu(reply->rssi);
1246
1247        sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1248
1249        /*
1250         * Identify the threshold breached and communicate that to the app.
1251         * After that install a new set of thresholds based on the signal
1252         * quality reported by the target
1253         */
1254        if (new_threshold) {
1255                /* Upper threshold breached */
1256                if (rssi < sq_thresh->upper_threshold[0]) {
1257                        ath6kl_dbg(ATH6KL_DBG_WMI,
1258                                "spurious upper rssi threshold event: %d\n",
1259                                rssi);
1260                } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1261                           (rssi >= sq_thresh->upper_threshold[0])) {
1262                        new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1263                } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1264                           (rssi >= sq_thresh->upper_threshold[1])) {
1265                        new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1266                } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1267                           (rssi >= sq_thresh->upper_threshold[2])) {
1268                        new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1269                } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1270                           (rssi >= sq_thresh->upper_threshold[3])) {
1271                        new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1272                } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1273                           (rssi >= sq_thresh->upper_threshold[4])) {
1274                        new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1275                } else if (rssi >= sq_thresh->upper_threshold[5]) {
1276                        new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1277                }
1278        } else {
1279                /* Lower threshold breached */
1280                if (rssi > sq_thresh->lower_threshold[0]) {
1281                        ath6kl_dbg(ATH6KL_DBG_WMI,
1282                                "spurious lower rssi threshold event: %d %d\n",
1283                                rssi, sq_thresh->lower_threshold[0]);
1284                } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1285                           (rssi <= sq_thresh->lower_threshold[0])) {
1286                        new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1287                } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1288                           (rssi <= sq_thresh->lower_threshold[1])) {
1289                        new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1290                } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1291                           (rssi <= sq_thresh->lower_threshold[2])) {
1292                        new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1293                } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1294                           (rssi <= sq_thresh->lower_threshold[3])) {
1295                        new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1296                } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1297                           (rssi <= sq_thresh->lower_threshold[4])) {
1298                        new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1299                } else if (rssi <= sq_thresh->lower_threshold[5]) {
1300                        new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1301                }
1302        }
1303
1304        /* Calculate and install the next set of thresholds */
1305        lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1306                                       sq_thresh->lower_threshold_valid_count);
1307        upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1308                                       sq_thresh->upper_threshold_valid_count);
1309
1310        /* Issue a wmi command to install the thresholds */
1311        cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1312        cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1313        cmd.weight = sq_thresh->weight;
1314        cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1315
1316        ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1317        if (ret) {
1318                ath6kl_err("unable to configure rssi thresholds\n");
1319                return -EIO;
1320        }
1321
1322        return 0;
1323}
1324
1325static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len)
1326{
1327        struct wmi_cac_event *reply;
1328        struct ieee80211_tspec_ie *ts;
1329        u16 active_tsids, tsinfo;
1330        u8 tsid, index;
1331        u8 ts_id;
1332
1333        if (len < sizeof(struct wmi_cac_event))
1334                return -EINVAL;
1335
1336        reply = (struct wmi_cac_event *) datap;
1337
1338        if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1339            (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1340
1341                ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1342                tsinfo = le16_to_cpu(ts->tsinfo);
1343                tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1344                        IEEE80211_WMM_IE_TSPEC_TID_MASK;
1345
1346                ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, tsid);
1347        } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1348                /*
1349                 * Following assumes that there is only one outstanding
1350                 * ADDTS request when this event is received
1351                 */
1352                spin_lock_bh(&wmi->lock);
1353                active_tsids = wmi->stream_exist_for_ac[reply->ac];
1354                spin_unlock_bh(&wmi->lock);
1355
1356                for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1357                        if ((active_tsids >> index) & 1)
1358                                break;
1359                }
1360                if (index < (sizeof(active_tsids) * 8))
1361                        ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, index);
1362        }
1363
1364        /*
1365         * Clear active tsids and Add missing handling
1366         * for delete qos stream from AP
1367         */
1368        else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1369
1370                ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1371                tsinfo = le16_to_cpu(ts->tsinfo);
1372                ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1373                         IEEE80211_WMM_IE_TSPEC_TID_MASK);
1374
1375                spin_lock_bh(&wmi->lock);
1376                wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1377                active_tsids = wmi->stream_exist_for_ac[reply->ac];
1378                spin_unlock_bh(&wmi->lock);
1379
1380                /* Indicate stream inactivity to driver layer only if all tsids
1381                 * within this AC are deleted.
1382                 */
1383                if (!active_tsids) {
1384                        ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1385                                                    false);
1386                        wmi->fat_pipe_exist &= ~(1 << reply->ac);
1387                }
1388        }
1389
1390        return 0;
1391}
1392
1393static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1394                        struct wmi_snr_threshold_params_cmd *snr_cmd)
1395{
1396        struct sk_buff *skb;
1397        struct wmi_snr_threshold_params_cmd *cmd;
1398
1399        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1400        if (!skb)
1401                return -ENOMEM;
1402
1403        cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1404        memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1405
1406        return ath6kl_wmi_cmd_send(wmi, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
1407                                   NO_SYNC_WMIFLAG);
1408}
1409
1410static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1411                                             int len)
1412{
1413        struct wmi_snr_threshold_event *reply;
1414        struct sq_threshold_params *sq_thresh;
1415        struct wmi_snr_threshold_params_cmd cmd;
1416        enum wmi_snr_threshold_val new_threshold;
1417        u8 upper_snr_threshold, lower_snr_threshold;
1418        s16 snr;
1419        int ret;
1420
1421        if (len < sizeof(struct wmi_snr_threshold_event))
1422                return -EINVAL;
1423
1424        reply = (struct wmi_snr_threshold_event *) datap;
1425
1426        new_threshold = (enum wmi_snr_threshold_val) reply->range;
1427        snr = reply->snr;
1428
1429        sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1430
1431        /*
1432         * Identify the threshold breached and communicate that to the app.
1433         * After that install a new set of thresholds based on the signal
1434         * quality reported by the target.
1435         */
1436        if (new_threshold) {
1437                /* Upper threshold breached */
1438                if (snr < sq_thresh->upper_threshold[0]) {
1439                        ath6kl_dbg(ATH6KL_DBG_WMI,
1440                                "spurious upper snr threshold event: %d\n",
1441                                snr);
1442                } else if ((snr < sq_thresh->upper_threshold[1]) &&
1443                           (snr >= sq_thresh->upper_threshold[0])) {
1444                        new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1445                } else if ((snr < sq_thresh->upper_threshold[2]) &&
1446                           (snr >= sq_thresh->upper_threshold[1])) {
1447                        new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1448                } else if ((snr < sq_thresh->upper_threshold[3]) &&
1449                           (snr >= sq_thresh->upper_threshold[2])) {
1450                        new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1451                } else if (snr >= sq_thresh->upper_threshold[3]) {
1452                        new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1453                }
1454        } else {
1455                /* Lower threshold breached */
1456                if (snr > sq_thresh->lower_threshold[0]) {
1457                        ath6kl_dbg(ATH6KL_DBG_WMI,
1458                                "spurious lower snr threshold event: %d\n",
1459                                sq_thresh->lower_threshold[0]);
1460                } else if ((snr > sq_thresh->lower_threshold[1]) &&
1461                           (snr <= sq_thresh->lower_threshold[0])) {
1462                        new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1463                } else if ((snr > sq_thresh->lower_threshold[2]) &&
1464                           (snr <= sq_thresh->lower_threshold[1])) {
1465                        new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1466                } else if ((snr > sq_thresh->lower_threshold[3]) &&
1467                           (snr <= sq_thresh->lower_threshold[2])) {
1468                        new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1469                } else if (snr <= sq_thresh->lower_threshold[3]) {
1470                        new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1471                }
1472        }
1473
1474        /* Calculate and install the next set of thresholds */
1475        lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1476                                       sq_thresh->lower_threshold_valid_count);
1477        upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1478                                       sq_thresh->upper_threshold_valid_count);
1479
1480        /* Issue a wmi command to install the thresholds */
1481        cmd.thresh_above1_val = upper_snr_threshold;
1482        cmd.thresh_below1_val = lower_snr_threshold;
1483        cmd.weight = sq_thresh->weight;
1484        cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1485
1486        ath6kl_dbg(ATH6KL_DBG_WMI,
1487                   "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1488                   snr, new_threshold,
1489                   lower_snr_threshold, upper_snr_threshold);
1490
1491        ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1492        if (ret) {
1493                ath6kl_err("unable to configure snr threshold\n");
1494                return -EIO;
1495        }
1496
1497        return 0;
1498}
1499
1500static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1501{
1502        u16 ap_info_entry_size;
1503        struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1504        struct wmi_ap_info_v1 *ap_info_v1;
1505        u8 index;
1506
1507        if (len < sizeof(struct wmi_aplist_event) ||
1508            ev->ap_list_ver != APLIST_VER1)
1509                return -EINVAL;
1510
1511        ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1512        ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1513
1514        ath6kl_dbg(ATH6KL_DBG_WMI,
1515                   "number of APs in aplist event: %d\n", ev->num_ap);
1516
1517        if (len < (int) (sizeof(struct wmi_aplist_event) +
1518                         (ev->num_ap - 1) * ap_info_entry_size))
1519                return -EINVAL;
1520
1521        /* AP list version 1 contents */
1522        for (index = 0; index < ev->num_ap; index++) {
1523                ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1524                           index, ap_info_v1->bssid, ap_info_v1->channel);
1525                ap_info_v1++;
1526        }
1527
1528        return 0;
1529}
1530
1531int ath6kl_wmi_cmd_send(struct wmi *wmi, struct sk_buff *skb,
1532                        enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1533{
1534        struct wmi_cmd_hdr *cmd_hdr;
1535        enum htc_endpoint_id ep_id = wmi->ep_id;
1536        int ret;
1537
1538        if (WARN_ON(skb == NULL))
1539                return -EINVAL;
1540
1541        ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
1542                   cmd_id, skb->len, sync_flag);
1543        ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
1544                        skb->data, skb->len);
1545
1546        if (sync_flag >= END_WMIFLAG) {
1547                dev_kfree_skb(skb);
1548                return -EINVAL;
1549        }
1550
1551        if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1552            (sync_flag == SYNC_BOTH_WMIFLAG)) {
1553                /*
1554                 * Make sure all data currently queued is transmitted before
1555                 * the cmd execution.  Establish a new sync point.
1556                 */
1557                ath6kl_wmi_sync_point(wmi);
1558        }
1559
1560        skb_push(skb, sizeof(struct wmi_cmd_hdr));
1561
1562        cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1563        cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
1564        cmd_hdr->info1 = 0;     /* added for virtual interface */
1565
1566        /* Only for OPT_TX_CMD, use BE endpoint. */
1567        if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1568                ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
1569                                              false, false, 0, NULL);
1570                if (ret) {
1571                        dev_kfree_skb(skb);
1572                        return ret;
1573                }
1574                ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1575        }
1576
1577        ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1578
1579        if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1580            (sync_flag == SYNC_BOTH_WMIFLAG)) {
1581                /*
1582                 * Make sure all new data queued waits for the command to
1583                 * execute. Establish a new sync point.
1584                 */
1585                ath6kl_wmi_sync_point(wmi);
1586        }
1587
1588        return 0;
1589}
1590
1591int ath6kl_wmi_connect_cmd(struct wmi *wmi, enum network_type nw_type,
1592                           enum dot11_auth_mode dot11_auth_mode,
1593                           enum auth_mode auth_mode,
1594                           enum crypto_type pairwise_crypto,
1595                           u8 pairwise_crypto_len,
1596                           enum crypto_type group_crypto,
1597                           u8 group_crypto_len, int ssid_len, u8 *ssid,
1598                           u8 *bssid, u16 channel, u32 ctrl_flags)
1599{
1600        struct sk_buff *skb;
1601        struct wmi_connect_cmd *cc;
1602        int ret;
1603
1604        ath6kl_dbg(ATH6KL_DBG_WMI,
1605                   "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
1606                   "type %d dot11_auth %d auth %d pairwise %d group %d\n",
1607                   bssid, channel, ctrl_flags, ssid_len, nw_type,
1608                   dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
1609        ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
1610
1611        wmi->traffic_class = 100;
1612
1613        if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1614                return -EINVAL;
1615
1616        if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1617                return -EINVAL;
1618
1619        skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1620        if (!skb)
1621                return -ENOMEM;
1622
1623        cc = (struct wmi_connect_cmd *) skb->data;
1624
1625        if (ssid_len)
1626                memcpy(cc->ssid, ssid, ssid_len);
1627
1628        cc->ssid_len = ssid_len;
1629        cc->nw_type = nw_type;
1630        cc->dot11_auth_mode = dot11_auth_mode;
1631        cc->auth_mode = auth_mode;
1632        cc->prwise_crypto_type = pairwise_crypto;
1633        cc->prwise_crypto_len = pairwise_crypto_len;
1634        cc->grp_crypto_type = group_crypto;
1635        cc->grp_crypto_len = group_crypto_len;
1636        cc->ch = cpu_to_le16(channel);
1637        cc->ctrl_flags = cpu_to_le32(ctrl_flags);
1638
1639        if (bssid != NULL)
1640                memcpy(cc->bssid, bssid, ETH_ALEN);
1641
1642        wmi->pair_crypto_type = pairwise_crypto;
1643        wmi->grp_crypto_type = group_crypto;
1644
1645        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CONNECT_CMDID, NO_SYNC_WMIFLAG);
1646
1647        return ret;
1648}
1649
1650int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 *bssid, u16 channel)
1651{
1652        struct sk_buff *skb;
1653        struct wmi_reconnect_cmd *cc;
1654        int ret;
1655
1656        ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
1657                   bssid, channel);
1658
1659        wmi->traffic_class = 100;
1660
1661        skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1662        if (!skb)
1663                return -ENOMEM;
1664
1665        cc = (struct wmi_reconnect_cmd *) skb->data;
1666        cc->channel = cpu_to_le16(channel);
1667
1668        if (bssid != NULL)
1669                memcpy(cc->bssid, bssid, ETH_ALEN);
1670
1671        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RECONNECT_CMDID,
1672                                  NO_SYNC_WMIFLAG);
1673
1674        return ret;
1675}
1676
1677int ath6kl_wmi_disconnect_cmd(struct wmi *wmi)
1678{
1679        int ret;
1680
1681        ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
1682
1683        wmi->traffic_class = 100;
1684
1685        /* Disconnect command does not need to do a SYNC before. */
1686        ret = ath6kl_wmi_simple_cmd(wmi, WMI_DISCONNECT_CMDID);
1687
1688        return ret;
1689}
1690
1691int ath6kl_wmi_startscan_cmd(struct wmi *wmi, enum wmi_scan_type scan_type,
1692                             u32 force_fgscan, u32 is_legacy,
1693                             u32 home_dwell_time, u32 force_scan_interval,
1694                             s8 num_chan, u16 *ch_list)
1695{
1696        struct sk_buff *skb;
1697        struct wmi_start_scan_cmd *sc;
1698        s8 size;
1699        int i, ret;
1700
1701        size = sizeof(struct wmi_start_scan_cmd);
1702
1703        if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1704                return -EINVAL;
1705
1706        if (num_chan > WMI_MAX_CHANNELS)
1707                return -EINVAL;
1708
1709        if (num_chan)
1710                size += sizeof(u16) * (num_chan - 1);
1711
1712        skb = ath6kl_wmi_get_new_buf(size);
1713        if (!skb)
1714                return -ENOMEM;
1715
1716        sc = (struct wmi_start_scan_cmd *) skb->data;
1717        sc->scan_type = scan_type;
1718        sc->force_fg_scan = cpu_to_le32(force_fgscan);
1719        sc->is_legacy = cpu_to_le32(is_legacy);
1720        sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1721        sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1722        sc->num_ch = num_chan;
1723
1724        for (i = 0; i < num_chan; i++)
1725                sc->ch_list[i] = cpu_to_le16(ch_list[i]);
1726
1727        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_START_SCAN_CMDID,
1728                                  NO_SYNC_WMIFLAG);
1729
1730        return ret;
1731}
1732
1733int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u16 fg_start_sec,
1734                              u16 fg_end_sec, u16 bg_sec,
1735                              u16 minact_chdw_msec, u16 maxact_chdw_msec,
1736                              u16 pas_chdw_msec, u8 short_scan_ratio,
1737                              u8 scan_ctrl_flag, u32 max_dfsch_act_time,
1738                              u16 maxact_scan_per_ssid)
1739{
1740        struct sk_buff *skb;
1741        struct wmi_scan_params_cmd *sc;
1742        int ret;
1743
1744        skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
1745        if (!skb)
1746                return -ENOMEM;
1747
1748        sc = (struct wmi_scan_params_cmd *) skb->data;
1749        sc->fg_start_period = cpu_to_le16(fg_start_sec);
1750        sc->fg_end_period = cpu_to_le16(fg_end_sec);
1751        sc->bg_period = cpu_to_le16(bg_sec);
1752        sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
1753        sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
1754        sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
1755        sc->short_scan_ratio = short_scan_ratio;
1756        sc->scan_ctrl_flags = scan_ctrl_flag;
1757        sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
1758        sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
1759
1760        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_SCAN_PARAMS_CMDID,
1761                                  NO_SYNC_WMIFLAG);
1762        return ret;
1763}
1764
1765int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 filter, u32 ie_mask)
1766{
1767        struct sk_buff *skb;
1768        struct wmi_bss_filter_cmd *cmd;
1769        int ret;
1770
1771        if (filter >= LAST_BSS_FILTER)
1772                return -EINVAL;
1773
1774        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1775        if (!skb)
1776                return -ENOMEM;
1777
1778        cmd = (struct wmi_bss_filter_cmd *) skb->data;
1779        cmd->bss_filter = filter;
1780        cmd->ie_mask = cpu_to_le32(ie_mask);
1781
1782        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_BSS_FILTER_CMDID,
1783                                  NO_SYNC_WMIFLAG);
1784        return ret;
1785}
1786
1787int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 index, u8 flag,
1788                              u8 ssid_len, u8 *ssid)
1789{
1790        struct sk_buff *skb;
1791        struct wmi_probed_ssid_cmd *cmd;
1792        int ret;
1793
1794        if (index > MAX_PROBED_SSID_INDEX)
1795                return -EINVAL;
1796
1797        if (ssid_len > sizeof(cmd->ssid))
1798                return -EINVAL;
1799
1800        if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
1801                return -EINVAL;
1802
1803        if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
1804                return -EINVAL;
1805
1806        if (flag & SPECIFIC_SSID_FLAG)
1807                wmi->is_probe_ssid = true;
1808
1809        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1810        if (!skb)
1811                return -ENOMEM;
1812
1813        cmd = (struct wmi_probed_ssid_cmd *) skb->data;
1814        cmd->entry_index = index;
1815        cmd->flag = flag;
1816        cmd->ssid_len = ssid_len;
1817        memcpy(cmd->ssid, ssid, ssid_len);
1818
1819        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PROBED_SSID_CMDID,
1820                                  NO_SYNC_WMIFLAG);
1821        return ret;
1822}
1823
1824int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u16 listen_interval,
1825                                  u16 listen_beacons)
1826{
1827        struct sk_buff *skb;
1828        struct wmi_listen_int_cmd *cmd;
1829        int ret;
1830
1831        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1832        if (!skb)
1833                return -ENOMEM;
1834
1835        cmd = (struct wmi_listen_int_cmd *) skb->data;
1836        cmd->listen_intvl = cpu_to_le16(listen_interval);
1837        cmd->num_beacons = cpu_to_le16(listen_beacons);
1838
1839        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LISTEN_INT_CMDID,
1840                                  NO_SYNC_WMIFLAG);
1841        return ret;
1842}
1843
1844int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 pwr_mode)
1845{
1846        struct sk_buff *skb;
1847        struct wmi_power_mode_cmd *cmd;
1848        int ret;
1849
1850        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1851        if (!skb)
1852                return -ENOMEM;
1853
1854        cmd = (struct wmi_power_mode_cmd *) skb->data;
1855        cmd->pwr_mode = pwr_mode;
1856        wmi->pwr_mode = pwr_mode;
1857
1858        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_MODE_CMDID,
1859                                  NO_SYNC_WMIFLAG);
1860        return ret;
1861}
1862
1863int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u16 idle_period,
1864                            u16 ps_poll_num, u16 dtim_policy,
1865                            u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
1866                            u16 ps_fail_event_policy)
1867{
1868        struct sk_buff *skb;
1869        struct wmi_power_params_cmd *pm;
1870        int ret;
1871
1872        skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
1873        if (!skb)
1874                return -ENOMEM;
1875
1876        pm = (struct wmi_power_params_cmd *)skb->data;
1877        pm->idle_period = cpu_to_le16(idle_period);
1878        pm->pspoll_number = cpu_to_le16(ps_poll_num);
1879        pm->dtim_policy = cpu_to_le16(dtim_policy);
1880        pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
1881        pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
1882        pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
1883
1884        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_PARAMS_CMDID,
1885                                  NO_SYNC_WMIFLAG);
1886        return ret;
1887}
1888
1889int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 timeout)
1890{
1891        struct sk_buff *skb;
1892        struct wmi_disc_timeout_cmd *cmd;
1893        int ret;
1894
1895        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1896        if (!skb)
1897                return -ENOMEM;
1898
1899        cmd = (struct wmi_disc_timeout_cmd *) skb->data;
1900        cmd->discon_timeout = timeout;
1901
1902        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_DISC_TIMEOUT_CMDID,
1903                                  NO_SYNC_WMIFLAG);
1904        return ret;
1905}
1906
1907int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 key_index,
1908                          enum crypto_type key_type,
1909                          u8 key_usage, u8 key_len,
1910                          u8 *key_rsc, u8 *key_material,
1911                          u8 key_op_ctrl, u8 *mac_addr,
1912                          enum wmi_sync_flag sync_flag)
1913{
1914        struct sk_buff *skb;
1915        struct wmi_add_cipher_key_cmd *cmd;
1916        int ret;
1917
1918        ath6kl_dbg(ATH6KL_DBG_WMI, "addkey cmd: key_index=%u key_type=%d "
1919                   "key_usage=%d key_len=%d key_op_ctrl=%d\n",
1920                   key_index, key_type, key_usage, key_len, key_op_ctrl);
1921
1922        if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
1923            (key_material == NULL))
1924                return -EINVAL;
1925
1926        if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
1927                return -EINVAL;
1928
1929        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1930        if (!skb)
1931                return -ENOMEM;
1932
1933        cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
1934        cmd->key_index = key_index;
1935        cmd->key_type = key_type;
1936        cmd->key_usage = key_usage;
1937        cmd->key_len = key_len;
1938        memcpy(cmd->key, key_material, key_len);
1939
1940        if (key_rsc != NULL)
1941                memcpy(cmd->key_rsc, key_rsc, sizeof(cmd->key_rsc));
1942
1943        cmd->key_op_ctrl = key_op_ctrl;
1944
1945        if (mac_addr)
1946                memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
1947
1948        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_CIPHER_KEY_CMDID,
1949                                  sync_flag);
1950
1951        return ret;
1952}
1953
1954int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 *krk)
1955{
1956        struct sk_buff *skb;
1957        struct wmi_add_krk_cmd *cmd;
1958        int ret;
1959
1960        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1961        if (!skb)
1962                return -ENOMEM;
1963
1964        cmd = (struct wmi_add_krk_cmd *) skb->data;
1965        memcpy(cmd->krk, krk, WMI_KRK_LEN);
1966
1967        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_KRK_CMDID, NO_SYNC_WMIFLAG);
1968
1969        return ret;
1970}
1971
1972int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 key_index)
1973{
1974        struct sk_buff *skb;
1975        struct wmi_delete_cipher_key_cmd *cmd;
1976        int ret;
1977
1978        if (key_index > WMI_MAX_KEY_INDEX)
1979                return -EINVAL;
1980
1981        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1982        if (!skb)
1983                return -ENOMEM;
1984
1985        cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
1986        cmd->key_index = key_index;
1987
1988        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_CIPHER_KEY_CMDID,
1989                                  NO_SYNC_WMIFLAG);
1990
1991        return ret;
1992}
1993
1994int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, const u8 *bssid,
1995                            const u8 *pmkid, bool set)
1996{
1997        struct sk_buff *skb;
1998        struct wmi_setpmkid_cmd *cmd;
1999        int ret;
2000
2001        if (bssid == NULL)
2002                return -EINVAL;
2003
2004        if (set && pmkid == NULL)
2005                return -EINVAL;
2006
2007        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2008        if (!skb)
2009                return -ENOMEM;
2010
2011        cmd = (struct wmi_setpmkid_cmd *) skb->data;
2012        memcpy(cmd->bssid, bssid, ETH_ALEN);
2013        if (set) {
2014                memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2015                cmd->enable = PMKID_ENABLE;
2016        } else {
2017                memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2018                cmd->enable = PMKID_DISABLE;
2019        }
2020
2021        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PMKID_CMDID,
2022                                  NO_SYNC_WMIFLAG);
2023
2024        return ret;
2025}
2026
2027static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
2028                              enum htc_endpoint_id ep_id)
2029{
2030        struct wmi_data_hdr *data_hdr;
2031        int ret;
2032
2033        if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
2034                return -EINVAL;
2035
2036        skb_push(skb, sizeof(struct wmi_data_hdr));
2037
2038        data_hdr = (struct wmi_data_hdr *) skb->data;
2039        data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
2040        data_hdr->info3 = 0;
2041
2042        ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2043
2044        return ret;
2045}
2046
2047static int ath6kl_wmi_sync_point(struct wmi *wmi)
2048{
2049        struct sk_buff *skb;
2050        struct wmi_sync_cmd *cmd;
2051        struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2052        enum htc_endpoint_id ep_id;
2053        u8 index, num_pri_streams = 0;
2054        int ret = 0;
2055
2056        memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2057
2058        spin_lock_bh(&wmi->lock);
2059
2060        for (index = 0; index < WMM_NUM_AC; index++) {
2061                if (wmi->fat_pipe_exist & (1 << index)) {
2062                        num_pri_streams++;
2063                        data_sync_bufs[num_pri_streams - 1].traffic_class =
2064                            index;
2065                }
2066        }
2067
2068        spin_unlock_bh(&wmi->lock);
2069
2070        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2071        if (!skb) {
2072                ret = -ENOMEM;
2073                goto free_skb;
2074        }
2075
2076        cmd = (struct wmi_sync_cmd *) skb->data;
2077
2078        /*
2079         * In the SYNC cmd sent on the control Ep, send a bitmap
2080         * of the data eps on which the Data Sync will be sent
2081         */
2082        cmd->data_sync_map = wmi->fat_pipe_exist;
2083
2084        for (index = 0; index < num_pri_streams; index++) {
2085                data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2086                if (data_sync_bufs[index].skb == NULL) {
2087                        ret = -ENOMEM;
2088                        break;
2089                }
2090        }
2091
2092        /*
2093         * If buffer allocation for any of the dataSync fails,
2094         * then do not send the Synchronize cmd on the control ep
2095         */
2096        if (ret)
2097                goto free_skb;
2098
2099        /*
2100         * Send sync cmd followed by sync data messages on all
2101         * endpoints being used
2102         */
2103        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SYNCHRONIZE_CMDID,
2104                                  NO_SYNC_WMIFLAG);
2105
2106        if (ret)
2107                goto free_skb;
2108
2109        /* cmd buffer sent, we no longer own it */
2110        skb = NULL;
2111
2112        for (index = 0; index < num_pri_streams; index++) {
2113
2114                if (WARN_ON(!data_sync_bufs[index].skb))
2115                        break;
2116
2117                ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2118                                               data_sync_bufs[index].
2119                                               traffic_class);
2120                ret =
2121                    ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
2122                                              ep_id);
2123
2124                if (ret)
2125                        break;
2126
2127                data_sync_bufs[index].skb = NULL;
2128        }
2129
2130free_skb:
2131        /* free up any resources left over (possibly due to an error) */
2132        if (skb)
2133                dev_kfree_skb(skb);
2134
2135        for (index = 0; index < num_pri_streams; index++) {
2136                if (data_sync_bufs[index].skb != NULL) {
2137                        dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
2138                                      skb);
2139                }
2140        }
2141
2142        return ret;
2143}
2144
2145int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi,
2146                                  struct wmi_create_pstream_cmd *params)
2147{
2148        struct sk_buff *skb;
2149        struct wmi_create_pstream_cmd *cmd;
2150        u8 fatpipe_exist_for_ac = 0;
2151        s32 min_phy = 0;
2152        s32 nominal_phy = 0;
2153        int ret;
2154
2155        if (!((params->user_pri < 8) &&
2156              (params->user_pri <= 0x7) &&
2157              (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2158              (params->traffic_direc == UPLINK_TRAFFIC ||
2159               params->traffic_direc == DNLINK_TRAFFIC ||
2160               params->traffic_direc == BIDIR_TRAFFIC) &&
2161              (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2162               params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2163              (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2164               params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2165               params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2166              (params->tsid == WMI_IMPLICIT_PSTREAM ||
2167               params->tsid <= WMI_MAX_THINSTREAM))) {
2168                return -EINVAL;
2169        }
2170
2171        /*
2172         * Check nominal PHY rate is >= minimalPHY,
2173         * so that DUT can allow TSRS IE
2174         */
2175
2176        /* Get the physical rate (units of bps) */
2177        min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2178
2179        /* Check minimal phy < nominal phy rate */
2180        if (params->nominal_phy >= min_phy) {
2181                /* unit of 500 kbps */
2182                nominal_phy = (params->nominal_phy * 1000) / 500;
2183                ath6kl_dbg(ATH6KL_DBG_WMI,
2184                           "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2185                           min_phy, nominal_phy);
2186
2187                params->nominal_phy = nominal_phy;
2188        } else {
2189                params->nominal_phy = 0;
2190        }
2191
2192        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2193        if (!skb)
2194                return -ENOMEM;
2195
2196        ath6kl_dbg(ATH6KL_DBG_WMI,
2197                   "sending create_pstream_cmd: ac=%d  tsid:%d\n",
2198                   params->traffic_class, params->tsid);
2199
2200        cmd = (struct wmi_create_pstream_cmd *) skb->data;
2201        memcpy(cmd, params, sizeof(*cmd));
2202
2203        /* This is an implicitly created Fat pipe */
2204        if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2205                spin_lock_bh(&wmi->lock);
2206                fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2207                                        (1 << params->traffic_class));
2208                wmi->fat_pipe_exist |= (1 << params->traffic_class);
2209                spin_unlock_bh(&wmi->lock);
2210        } else {
2211                /* explicitly created thin stream within a fat pipe */
2212                spin_lock_bh(&wmi->lock);
2213                fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2214                                        (1 << params->traffic_class));
2215                wmi->stream_exist_for_ac[params->traffic_class] |=
2216                    (1 << params->tsid);
2217                /*
2218                 * If a thinstream becomes active, the fat pipe automatically
2219                 * becomes active
2220                 */
2221                wmi->fat_pipe_exist |= (1 << params->traffic_class);
2222                spin_unlock_bh(&wmi->lock);
2223        }
2224
2225        /*
2226         * Indicate activty change to driver layer only if this is the
2227         * first TSID to get created in this AC explicitly or an implicit
2228         * fat pipe is getting created.
2229         */
2230        if (!fatpipe_exist_for_ac)
2231                ath6kl_indicate_tx_activity(wmi->parent_dev,
2232                                            params->traffic_class, true);
2233
2234        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CREATE_PSTREAM_CMDID,
2235                                  NO_SYNC_WMIFLAG);
2236        return ret;
2237}
2238
2239int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 traffic_class, u8 tsid)
2240{
2241        struct sk_buff *skb;
2242        struct wmi_delete_pstream_cmd *cmd;
2243        u16 active_tsids = 0;
2244        int ret;
2245
2246        if (traffic_class > 3) {
2247                ath6kl_err("invalid traffic class: %d\n", traffic_class);
2248                return -EINVAL;
2249        }
2250
2251        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2252        if (!skb)
2253                return -ENOMEM;
2254
2255        cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2256        cmd->traffic_class = traffic_class;
2257        cmd->tsid = tsid;
2258
2259        spin_lock_bh(&wmi->lock);
2260        active_tsids = wmi->stream_exist_for_ac[traffic_class];
2261        spin_unlock_bh(&wmi->lock);
2262
2263        if (!(active_tsids & (1 << tsid))) {
2264                dev_kfree_skb(skb);
2265                ath6kl_dbg(ATH6KL_DBG_WMI,
2266                           "TSID %d doesn't exist for traffic class: %d\n",
2267                           tsid, traffic_class);
2268                return -ENODATA;
2269        }
2270
2271        ath6kl_dbg(ATH6KL_DBG_WMI,
2272                   "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2273                   traffic_class, tsid);
2274
2275        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_PSTREAM_CMDID,
2276                                  SYNC_BEFORE_WMIFLAG);
2277
2278        spin_lock_bh(&wmi->lock);
2279        wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2280        active_tsids = wmi->stream_exist_for_ac[traffic_class];
2281        spin_unlock_bh(&wmi->lock);
2282
2283        /*
2284         * Indicate stream inactivity to driver layer only if all tsids
2285         * within this AC are deleted.
2286         */
2287        if (!active_tsids) {
2288                ath6kl_indicate_tx_activity(wmi->parent_dev,
2289                                            traffic_class, false);
2290                wmi->fat_pipe_exist &= ~(1 << traffic_class);
2291        }
2292
2293        return ret;
2294}
2295
2296int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, struct wmi_set_ip_cmd *ip_cmd)
2297{
2298        struct sk_buff *skb;
2299        struct wmi_set_ip_cmd *cmd;
2300        int ret;
2301
2302        /* Multicast address are not valid */
2303        if ((*((u8 *) &ip_cmd->ips[0]) >= 0xE0) ||
2304            (*((u8 *) &ip_cmd->ips[1]) >= 0xE0))
2305                return -EINVAL;
2306
2307        skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2308        if (!skb)
2309                return -ENOMEM;
2310
2311        cmd = (struct wmi_set_ip_cmd *) skb->data;
2312        memcpy(cmd, ip_cmd, sizeof(struct wmi_set_ip_cmd));
2313
2314        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_IP_CMDID, NO_SYNC_WMIFLAG);
2315        return ret;
2316}
2317
2318static int ath6kl_wmi_get_wow_list_event_rx(struct wmi *wmi, u8 * datap,
2319                                            int len)
2320{
2321        if (len < sizeof(struct wmi_get_wow_list_reply))
2322                return -EINVAL;
2323
2324        return 0;
2325}
2326
2327static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2328                                    enum wmix_command_id cmd_id,
2329                                    enum wmi_sync_flag sync_flag)
2330{
2331        struct wmix_cmd_hdr *cmd_hdr;
2332        int ret;
2333
2334        skb_push(skb, sizeof(struct wmix_cmd_hdr));
2335
2336        cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2337        cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2338
2339        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_EXTENSION_CMDID, sync_flag);
2340
2341        return ret;
2342}
2343
2344int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2345{
2346        struct sk_buff *skb;
2347        struct wmix_hb_challenge_resp_cmd *cmd;
2348        int ret;
2349
2350        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2351        if (!skb)
2352                return -ENOMEM;
2353
2354        cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2355        cmd->cookie = cpu_to_le32(cookie);
2356        cmd->source = cpu_to_le32(source);
2357
2358        ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2359                                       NO_SYNC_WMIFLAG);
2360        return ret;
2361}
2362
2363int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
2364{
2365        struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
2366        struct sk_buff *skb;
2367        int ret;
2368
2369        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2370        if (!skb)
2371                return -ENOMEM;
2372
2373        cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
2374        cmd->valid = cpu_to_le32(valid);
2375        cmd->config = cpu_to_le32(config);
2376
2377        ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
2378                                       NO_SYNC_WMIFLAG);
2379        return ret;
2380}
2381
2382int ath6kl_wmi_get_stats_cmd(struct wmi *wmi)
2383{
2384        return ath6kl_wmi_simple_cmd(wmi, WMI_GET_STATISTICS_CMDID);
2385}
2386
2387int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 dbM)
2388{
2389        struct sk_buff *skb;
2390        struct wmi_set_tx_pwr_cmd *cmd;
2391        int ret;
2392
2393        skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
2394        if (!skb)
2395                return -ENOMEM;
2396
2397        cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
2398        cmd->dbM = dbM;
2399
2400        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_TX_PWR_CMDID,
2401                                  NO_SYNC_WMIFLAG);
2402
2403        return ret;
2404}
2405
2406int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi)
2407{
2408        return ath6kl_wmi_simple_cmd(wmi, WMI_GET_TX_PWR_CMDID);
2409}
2410
2411int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 status, u8 preamble_policy)
2412{
2413        struct sk_buff *skb;
2414        struct wmi_set_lpreamble_cmd *cmd;
2415        int ret;
2416
2417        skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
2418        if (!skb)
2419                return -ENOMEM;
2420
2421        cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
2422        cmd->status = status;
2423        cmd->preamble_policy = preamble_policy;
2424
2425        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LPREAMBLE_CMDID,
2426                                  NO_SYNC_WMIFLAG);
2427        return ret;
2428}
2429
2430int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
2431{
2432        struct sk_buff *skb;
2433        struct wmi_set_rts_cmd *cmd;
2434        int ret;
2435
2436        skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
2437        if (!skb)
2438                return -ENOMEM;
2439
2440        cmd = (struct wmi_set_rts_cmd *) skb->data;
2441        cmd->threshold = cpu_to_le16(threshold);
2442
2443        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_RTS_CMDID, NO_SYNC_WMIFLAG);
2444        return ret;
2445}
2446
2447int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, enum wmi_txop_cfg cfg)
2448{
2449        struct sk_buff *skb;
2450        struct wmi_set_wmm_txop_cmd *cmd;
2451        int ret;
2452
2453        if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
2454                return -EINVAL;
2455
2456        skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
2457        if (!skb)
2458                return -ENOMEM;
2459
2460        cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
2461        cmd->txop_enable = cfg;
2462
2463        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_WMM_TXOP_CMDID,
2464                                  NO_SYNC_WMIFLAG);
2465        return ret;
2466}
2467
2468int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 keep_alive_intvl)
2469{
2470        struct sk_buff *skb;
2471        struct wmi_set_keepalive_cmd *cmd;
2472        int ret;
2473
2474        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2475        if (!skb)
2476                return -ENOMEM;
2477
2478        cmd = (struct wmi_set_keepalive_cmd *) skb->data;
2479        cmd->keep_alive_intvl = keep_alive_intvl;
2480        wmi->keep_alive_intvl = keep_alive_intvl;
2481
2482        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_KEEPALIVE_CMDID,
2483                                  NO_SYNC_WMIFLAG);
2484        return ret;
2485}
2486
2487int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
2488{
2489        struct sk_buff *skb;
2490        int ret;
2491
2492        skb = ath6kl_wmi_get_new_buf(len);
2493        if (!skb)
2494                return -ENOMEM;
2495
2496        memcpy(skb->data, buf, len);
2497
2498        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
2499
2500        return ret;
2501}
2502
2503
2504s32 ath6kl_wmi_get_rate(s8 rate_index)
2505{
2506        if (rate_index == RATE_AUTO)
2507                return 0;
2508
2509        return wmi_rate_tbl[(u32) rate_index][0];
2510}
2511
2512static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
2513                                              u32 len)
2514{
2515        struct wmi_pmkid_list_reply *reply;
2516        u32 expected_len;
2517
2518        if (len < sizeof(struct wmi_pmkid_list_reply))
2519                return -EINVAL;
2520
2521        reply = (struct wmi_pmkid_list_reply *)datap;
2522        expected_len = sizeof(reply->num_pmkid) +
2523                le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
2524
2525        if (len < expected_len)
2526                return -EINVAL;
2527
2528        return 0;
2529}
2530
2531static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
2532{
2533        struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
2534
2535        aggr_recv_addba_req_evt(wmi->parent_dev, cmd->tid,
2536                                le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
2537
2538        return 0;
2539}
2540
2541static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
2542{
2543        struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
2544
2545        aggr_recv_delba_req_evt(wmi->parent_dev, cmd->tid);
2546
2547        return 0;
2548}
2549
2550/*  AP mode functions */
2551
2552int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, struct wmi_connect_cmd *p)
2553{
2554        struct sk_buff *skb;
2555        struct wmi_connect_cmd *cm;
2556        int res;
2557
2558        skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2559        if (!skb)
2560                return -ENOMEM;
2561
2562        cm = (struct wmi_connect_cmd *) skb->data;
2563        memcpy(cm, p, sizeof(*cm));
2564
2565        res = ath6kl_wmi_cmd_send(wmip, skb, WMI_AP_CONFIG_COMMIT_CMDID,
2566                                  NO_SYNC_WMIFLAG);
2567        ath6kl_dbg(ATH6KL_DBG_WMI, "%s: nw_type=%u auth_mode=%u ch=%u "
2568                   "ctrl_flags=0x%x-> res=%d\n",
2569                   __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
2570                   le32_to_cpu(p->ctrl_flags), res);
2571        return res;
2572}
2573
2574int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 cmd, const u8 *mac, u16 reason)
2575{
2576        struct sk_buff *skb;
2577        struct wmi_ap_set_mlme_cmd *cm;
2578
2579        skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2580        if (!skb)
2581                return -ENOMEM;
2582
2583        cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
2584        memcpy(cm->mac, mac, ETH_ALEN);
2585        cm->reason = cpu_to_le16(reason);
2586        cm->cmd = cmd;
2587
2588        return ath6kl_wmi_cmd_send(wmip, skb, WMI_AP_SET_MLME_CMDID,
2589                                   NO_SYNC_WMIFLAG);
2590}
2591
2592static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len)
2593{
2594        struct wmi_pspoll_event *ev;
2595
2596        if (len < sizeof(struct wmi_pspoll_event))
2597                return -EINVAL;
2598
2599        ev = (struct wmi_pspoll_event *) datap;
2600
2601        ath6kl_pspoll_event(wmi->parent_dev, le16_to_cpu(ev->aid));
2602
2603        return 0;
2604}
2605
2606static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len)
2607{
2608        ath6kl_dtimexpiry_event(wmi->parent_dev);
2609
2610        return 0;
2611}
2612
2613int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u16 aid, bool flag)
2614{
2615        struct sk_buff *skb;
2616        struct wmi_ap_set_pvb_cmd *cmd;
2617        int ret;
2618
2619        skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
2620        if (!skb)
2621                return -ENOMEM;
2622
2623        cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
2624        cmd->aid = cpu_to_le16(aid);
2625        cmd->rsvd = cpu_to_le16(0);
2626        cmd->flag = cpu_to_le32(flag);
2627
2628        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_AP_SET_PVB_CMDID,
2629                                  NO_SYNC_WMIFLAG);
2630
2631        return 0;
2632}
2633
2634int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 rx_meta_ver,
2635                                       bool rx_dot11_hdr, bool defrag_on_host)
2636{
2637        struct sk_buff *skb;
2638        struct wmi_rx_frame_format_cmd *cmd;
2639        int ret;
2640
2641        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2642        if (!skb)
2643                return -ENOMEM;
2644
2645        cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
2646        cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
2647        cmd->defrag_on_host = defrag_on_host ? 1 : 0;
2648        cmd->meta_ver = rx_meta_ver;
2649
2650        /* Delete the local aggr state, on host */
2651        ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RX_FRAME_FORMAT_CMDID,
2652                                  NO_SYNC_WMIFLAG);
2653
2654        return ret;
2655}
2656
2657int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 mgmt_frm_type, const u8 *ie,
2658                             u8 ie_len)
2659{
2660        struct sk_buff *skb;
2661        struct wmi_set_appie_cmd *p;
2662
2663        skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
2664        if (!skb)
2665                return -ENOMEM;
2666
2667        ath6kl_dbg(ATH6KL_DBG_WMI, "set_appie_cmd: mgmt_frm_type=%u "
2668                   "ie_len=%u\n", mgmt_frm_type, ie_len);
2669        p = (struct wmi_set_appie_cmd *) skb->data;
2670        p->mgmt_frm_type = mgmt_frm_type;
2671        p->ie_len = ie_len;
2672        memcpy(p->ie_info, ie, ie_len);
2673        return ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_APPIE_CMDID,
2674                                   NO_SYNC_WMIFLAG);
2675}
2676
2677int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
2678{
2679        struct sk_buff *skb;
2680        struct wmi_disable_11b_rates_cmd *cmd;
2681
2682        skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2683        if (!skb)
2684                return -ENOMEM;
2685
2686        ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
2687                   disable);
2688        cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
2689        cmd->disable = disable ? 1 : 0;
2690
2691        return ath6kl_wmi_cmd_send(wmi, skb, WMI_DISABLE_11B_RATES_CMDID,
2692                                   NO_SYNC_WMIFLAG);
2693}
2694
2695int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u32 freq, u32 dur)
2696{
2697        struct sk_buff *skb;
2698        struct wmi_remain_on_chnl_cmd *p;
2699
2700        skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2701        if (!skb)
2702                return -ENOMEM;
2703
2704        ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
2705                   freq, dur);
2706        p = (struct wmi_remain_on_chnl_cmd *) skb->data;
2707        p->freq = cpu_to_le32(freq);
2708        p->duration = cpu_to_le32(dur);
2709        return ath6kl_wmi_cmd_send(wmi, skb, WMI_REMAIN_ON_CHNL_CMDID,
2710                                   NO_SYNC_WMIFLAG);
2711}
2712
2713int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u32 id, u32 freq, u32 wait,
2714                               const u8 *data, u16 data_len)
2715{
2716        struct sk_buff *skb;
2717        struct wmi_send_action_cmd *p;
2718        u8 *buf;
2719
2720        if (wait)
2721                return -EINVAL; /* Offload for wait not supported */
2722
2723        buf = kmalloc(data_len, GFP_KERNEL);
2724        if (!buf)
2725                return -ENOMEM;
2726
2727        skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
2728        if (!skb) {
2729                kfree(buf);
2730                return -ENOMEM;
2731        }
2732
2733        kfree(wmi->last_mgmt_tx_frame);
2734        wmi->last_mgmt_tx_frame = buf;
2735        wmi->last_mgmt_tx_frame_len = data_len;
2736
2737        ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
2738                   "len=%u\n", id, freq, wait, data_len);
2739        p = (struct wmi_send_action_cmd *) skb->data;
2740        p->id = cpu_to_le32(id);
2741        p->freq = cpu_to_le32(freq);
2742        p->wait = cpu_to_le32(wait);
2743        p->len = cpu_to_le16(data_len);
2744        memcpy(p->data, data, data_len);
2745        return ath6kl_wmi_cmd_send(wmi, skb, WMI_SEND_ACTION_CMDID,
2746                                   NO_SYNC_WMIFLAG);
2747}
2748
2749int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u32 freq,
2750                                       const u8 *dst,
2751                                       const u8 *data, u16 data_len)
2752{
2753        struct sk_buff *skb;
2754        struct wmi_p2p_probe_response_cmd *p;
2755
2756        skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
2757        if (!skb)
2758                return -ENOMEM;
2759
2760        ath6kl_dbg(ATH6KL_DBG_WMI, "send_probe_response_cmd: freq=%u dst=%pM "
2761                   "len=%u\n", freq, dst, data_len);
2762        p = (struct wmi_p2p_probe_response_cmd *) skb->data;
2763        p->freq = cpu_to_le32(freq);
2764        memcpy(p->destination_addr, dst, ETH_ALEN);
2765        p->len = cpu_to_le16(data_len);
2766        memcpy(p->data, data, data_len);
2767        return ath6kl_wmi_cmd_send(wmi, skb, WMI_SEND_PROBE_RESPONSE_CMDID,
2768                                   NO_SYNC_WMIFLAG);
2769}
2770
2771int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, bool enable)
2772{
2773        struct sk_buff *skb;
2774        struct wmi_probe_req_report_cmd *p;
2775
2776        skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2777        if (!skb)
2778                return -ENOMEM;
2779
2780        ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
2781                   enable);
2782        p = (struct wmi_probe_req_report_cmd *) skb->data;
2783        p->enable = enable ? 1 : 0;
2784        return ath6kl_wmi_cmd_send(wmi, skb, WMI_PROBE_REQ_REPORT_CMDID,
2785                                   NO_SYNC_WMIFLAG);
2786}
2787
2788int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u32 info_req_flags)
2789{
2790        struct sk_buff *skb;
2791        struct wmi_get_p2p_info *p;
2792
2793        skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2794        if (!skb)
2795                return -ENOMEM;
2796
2797        ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
2798                   info_req_flags);
2799        p = (struct wmi_get_p2p_info *) skb->data;
2800        p->info_req_flags = cpu_to_le32(info_req_flags);
2801        return ath6kl_wmi_cmd_send(wmi, skb, WMI_GET_P2P_INFO_CMDID,
2802                                   NO_SYNC_WMIFLAG);
2803}
2804
2805int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi)
2806{
2807        ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
2808        return ath6kl_wmi_simple_cmd(wmi, WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
2809}
2810
2811static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
2812{
2813        struct wmix_cmd_hdr *cmd;
2814        u32 len;
2815        u16 id;
2816        u8 *datap;
2817        int ret = 0;
2818
2819        if (skb->len < sizeof(struct wmix_cmd_hdr)) {
2820                ath6kl_err("bad packet 1\n");
2821                wmi->stat.cmd_len_err++;
2822                return -EINVAL;
2823        }
2824
2825        cmd = (struct wmix_cmd_hdr *) skb->data;
2826        id = le32_to_cpu(cmd->cmd_id);
2827
2828        skb_pull(skb, sizeof(struct wmix_cmd_hdr));
2829
2830        datap = skb->data;
2831        len = skb->len;
2832
2833        switch (id) {
2834        case WMIX_HB_CHALLENGE_RESP_EVENTID:
2835                ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
2836                break;
2837        case WMIX_DBGLOG_EVENTID:
2838                ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
2839                ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
2840                break;
2841        default:
2842                ath6kl_warn("unknown cmd id 0x%x\n", id);
2843                wmi->stat.cmd_id_err++;
2844                ret = -EINVAL;
2845                break;
2846        }
2847
2848        return ret;
2849}
2850
2851/* Control Path */
2852int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
2853{
2854        struct wmi_cmd_hdr *cmd;
2855        u32 len;
2856        u16 id;
2857        u8 *datap;
2858        int ret = 0;
2859
2860        if (WARN_ON(skb == NULL))
2861                return -EINVAL;
2862
2863        if (skb->len < sizeof(struct wmi_cmd_hdr)) {
2864                ath6kl_err("bad packet 1\n");
2865                dev_kfree_skb(skb);
2866                wmi->stat.cmd_len_err++;
2867                return -EINVAL;
2868        }
2869
2870        cmd = (struct wmi_cmd_hdr *) skb->data;
2871        id = le16_to_cpu(cmd->cmd_id);
2872
2873        skb_pull(skb, sizeof(struct wmi_cmd_hdr));
2874
2875        datap = skb->data;
2876        len = skb->len;
2877
2878        ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
2879        ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
2880                        datap, len);
2881
2882        switch (id) {
2883        case WMI_GET_BITRATE_CMDID:
2884                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
2885                ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
2886                break;
2887        case WMI_GET_CHANNEL_LIST_CMDID:
2888                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
2889                ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
2890                break;
2891        case WMI_GET_TX_PWR_CMDID:
2892                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
2893                ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
2894                break;
2895        case WMI_READY_EVENTID:
2896                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
2897                ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
2898                break;
2899        case WMI_CONNECT_EVENTID:
2900                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
2901                ret = ath6kl_wmi_connect_event_rx(wmi, datap, len);
2902                break;
2903        case WMI_DISCONNECT_EVENTID:
2904                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
2905                ret = ath6kl_wmi_disconnect_event_rx(wmi, datap, len);
2906                break;
2907        case WMI_PEER_NODE_EVENTID:
2908                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
2909                ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
2910                break;
2911        case WMI_TKIP_MICERR_EVENTID:
2912                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
2913                ret = ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len);
2914                break;
2915        case WMI_BSSINFO_EVENTID:
2916                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
2917                ret = ath6kl_wmi_bssinfo_event_rx(wmi, datap, len);
2918                break;
2919        case WMI_REGDOMAIN_EVENTID:
2920                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
2921                ath6kl_wmi_regdomain_event(wmi, datap, len);
2922                break;
2923        case WMI_PSTREAM_TIMEOUT_EVENTID:
2924                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
2925                ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
2926                break;
2927        case WMI_NEIGHBOR_REPORT_EVENTID:
2928                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
2929                ret = ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len);
2930                break;
2931        case WMI_SCAN_COMPLETE_EVENTID:
2932                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
2933                ret = ath6kl_wmi_scan_complete_rx(wmi, datap, len);
2934                break;
2935        case WMI_CMDERROR_EVENTID:
2936                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
2937                ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
2938                break;
2939        case WMI_REPORT_STATISTICS_EVENTID:
2940                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
2941                ret = ath6kl_wmi_stats_event_rx(wmi, datap, len);
2942                break;
2943        case WMI_RSSI_THRESHOLD_EVENTID:
2944                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
2945                ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
2946                break;
2947        case WMI_ERROR_REPORT_EVENTID:
2948                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
2949                break;
2950        case WMI_OPT_RX_FRAME_EVENTID:
2951                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
2952                /* this event has been deprecated */
2953                break;
2954        case WMI_REPORT_ROAM_TBL_EVENTID:
2955                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
2956                break;
2957        case WMI_EXTENSION_EVENTID:
2958                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
2959                ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
2960                break;
2961        case WMI_CAC_EVENTID:
2962                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
2963                ret = ath6kl_wmi_cac_event_rx(wmi, datap, len);
2964                break;
2965        case WMI_CHANNEL_CHANGE_EVENTID:
2966                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
2967                break;
2968        case WMI_REPORT_ROAM_DATA_EVENTID:
2969                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
2970                break;
2971        case WMI_TEST_EVENTID:
2972                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
2973                ret = ath6kl_wmi_tcmd_test_report_rx(wmi, datap, len);
2974                break;
2975        case WMI_GET_FIXRATES_CMDID:
2976                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
2977                ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
2978                break;
2979        case WMI_TX_RETRY_ERR_EVENTID:
2980                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
2981                break;
2982        case WMI_SNR_THRESHOLD_EVENTID:
2983                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
2984                ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
2985                break;
2986        case WMI_LQ_THRESHOLD_EVENTID:
2987                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
2988                break;
2989        case WMI_APLIST_EVENTID:
2990                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
2991                ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
2992                break;
2993        case WMI_GET_KEEPALIVE_CMDID:
2994                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
2995                ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
2996                break;
2997        case WMI_GET_WOW_LIST_EVENTID:
2998                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
2999                ret = ath6kl_wmi_get_wow_list_event_rx(wmi, datap, len);
3000                break;
3001        case WMI_GET_PMKID_LIST_EVENTID:
3002                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
3003                ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
3004                break;
3005        case WMI_PSPOLL_EVENTID:
3006                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
3007                ret = ath6kl_wmi_pspoll_event_rx(wmi, datap, len);
3008                break;
3009        case WMI_DTIMEXPIRY_EVENTID:
3010                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
3011                ret = ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len);
3012                break;
3013        case WMI_SET_PARAMS_REPLY_EVENTID:
3014                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
3015                break;
3016        case WMI_ADDBA_REQ_EVENTID:
3017                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
3018                ret = ath6kl_wmi_addba_req_event_rx(wmi, datap, len);
3019                break;
3020        case WMI_ADDBA_RESP_EVENTID:
3021                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
3022                break;
3023        case WMI_DELBA_REQ_EVENTID:
3024                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
3025                ret = ath6kl_wmi_delba_req_event_rx(wmi, datap, len);
3026                break;
3027        case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
3028                ath6kl_dbg(ATH6KL_DBG_WMI,
3029                           "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
3030                break;
3031        case WMI_REPORT_BTCOEX_STATS_EVENTID:
3032                ath6kl_dbg(ATH6KL_DBG_WMI,
3033                           "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
3034                break;
3035        case WMI_TX_COMPLETE_EVENTID:
3036                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
3037                ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
3038                break;
3039        case WMI_REMAIN_ON_CHNL_EVENTID:
3040                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
3041                ret = ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len);
3042                break;
3043        case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
3044                ath6kl_dbg(ATH6KL_DBG_WMI,
3045                           "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
3046                ret = ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
3047                                                                len);
3048                break;
3049        case WMI_TX_STATUS_EVENTID:
3050                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
3051                ret = ath6kl_wmi_tx_status_event_rx(wmi, datap, len);
3052                break;
3053        case WMI_RX_PROBE_REQ_EVENTID:
3054                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
3055                ret = ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len);
3056                break;
3057        case WMI_P2P_CAPABILITIES_EVENTID:
3058                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
3059                ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
3060                break;
3061        case WMI_RX_ACTION_EVENTID:
3062                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
3063                ret = ath6kl_wmi_rx_action_event_rx(wmi, datap, len);
3064                break;
3065        case WMI_P2P_INFO_EVENTID:
3066                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
3067                ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
3068                break;
3069        default:
3070                ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", id);
3071                wmi->stat.cmd_id_err++;
3072                ret = -EINVAL;
3073                break;
3074        }
3075
3076        dev_kfree_skb(skb);
3077
3078        return ret;
3079}
3080
3081static void ath6kl_wmi_qos_state_init(struct wmi *wmi)
3082{
3083        if (!wmi)
3084                return;
3085
3086        spin_lock_bh(&wmi->lock);
3087
3088        wmi->fat_pipe_exist = 0;
3089        memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
3090
3091        spin_unlock_bh(&wmi->lock);
3092}
3093
3094void *ath6kl_wmi_init(struct ath6kl *dev)
3095{
3096        struct wmi *wmi;
3097
3098        wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
3099        if (!wmi)
3100                return NULL;
3101
3102        spin_lock_init(&wmi->lock);
3103
3104        wmi->parent_dev = dev;
3105
3106        ath6kl_wmi_qos_state_init(wmi);
3107
3108        wmi->pwr_mode = REC_POWER;
3109        wmi->phy_mode = WMI_11G_MODE;
3110
3111        wmi->pair_crypto_type = NONE_CRYPT;
3112        wmi->grp_crypto_type = NONE_CRYPT;
3113
3114        wmi->ht_allowed[A_BAND_24GHZ] = 1;
3115        wmi->ht_allowed[A_BAND_5GHZ] = 1;
3116
3117        return wmi;
3118}
3119
3120void ath6kl_wmi_shutdown(struct wmi *wmi)
3121{
3122        if (!wmi)
3123                return;
3124
3125        kfree(wmi->last_mgmt_tx_frame);
3126        kfree(wmi);
3127}
3128
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.