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