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