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