blob: 55609fc4e50e61fc8ff98325a9913eae9560ebbb [file] [log] [blame]
Kalle Valobdcd8172011-07-18 00:22:30 +03001/*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
Vasanthakumar Thiagarajan1b2df402012-02-06 20:15:53 +05303 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
Kalle Valobdcd8172011-07-18 00:22:30 +03004 *
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>
Luis R. Rodriguez1560ac72012-04-23 19:58:50 -070019#include <linux/in.h>
Kalle Valobdcd8172011-07-18 00:22:30 +030020#include "core.h"
21#include "debug.h"
Kalle Valo003353b0d2011-09-01 10:14:21 +030022#include "testmode.h"
Kalle Valo416cf0b2013-03-18 13:42:20 +020023#include "trace.h"
Vivek Natarajan06033762011-09-06 13:01:36 +053024#include "../regd.h"
25#include "../regd_common.h"
Kalle Valobdcd8172011-07-18 00:22:30 +030026
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +053027static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +030028
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
Jessica Wuc1d32d32014-06-17 12:41:10 +030062static const s32 wmi_rate_tbl_mcs15[][2] = {
63 /* {W/O SGI, with SGI} */
64 {1000, 1000},
65 {2000, 2000},
66 {5500, 5500},
67 {11000, 11000},
68 {6000, 6000},
69 {9000, 9000},
70 {12000, 12000},
71 {18000, 18000},
72 {24000, 24000},
73 {36000, 36000},
74 {48000, 48000},
75 {54000, 54000},
76 {6500, 7200}, /* HT 20, MCS 0 */
77 {13000, 14400},
78 {19500, 21700},
79 {26000, 28900},
80 {39000, 43300},
81 {52000, 57800},
82 {58500, 65000},
83 {65000, 72200},
84 {13000, 14400}, /* HT 20, MCS 8 */
85 {26000, 28900},
86 {39000, 43300},
87 {52000, 57800},
88 {78000, 86700},
89 {104000, 115600},
90 {117000, 130000},
91 {130000, 144400}, /* HT 20, MCS 15 */
92 {13500, 15000}, /*HT 40, MCS 0 */
93 {27000, 30000},
94 {40500, 45000},
95 {54000, 60000},
96 {81000, 90000},
97 {108000, 120000},
98 {121500, 135000},
99 {135000, 150000},
100 {27000, 30000}, /*HT 40, MCS 8 */
101 {54000, 60000},
102 {81000, 90000},
103 {108000, 120000},
104 {162000, 180000},
105 {216000, 240000},
106 {243000, 270000},
107 {270000, 300000}, /*HT 40, MCS 15 */
108 {0, 0}
109};
110
Kalle Valobdcd8172011-07-18 00:22:30 +0300111/* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
112static const u8 up_to_ac[] = {
113 WMM_AC_BE,
114 WMM_AC_BK,
115 WMM_AC_BK,
116 WMM_AC_BE,
117 WMM_AC_VI,
118 WMM_AC_VI,
119 WMM_AC_VO,
120 WMM_AC_VO,
121};
122
123void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
124{
125 if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
126 return;
127
128 wmi->ep_id = ep_id;
129}
130
131enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
132{
133 return wmi->ep_id;
134}
135
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +0530136struct ath6kl_vif *ath6kl_get_vif_by_index(struct ath6kl *ar, u8 if_idx)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530137{
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530138 struct ath6kl_vif *vif, *found = NULL;
139
Kalle Valo71f96ee2011-11-14 19:31:30 +0200140 if (WARN_ON(if_idx > (ar->vif_max - 1)))
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530141 return NULL;
142
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530143 /* FIXME: Locking */
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +0530144 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530145 list_for_each_entry(vif, &ar->vif_list, list) {
146 if (vif->fw_vif_idx == if_idx) {
147 found = vif;
148 break;
149 }
150 }
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +0530151 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530152
153 return found;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530154}
155
Kalle Valobdcd8172011-07-18 00:22:30 +0300156/* Performs DIX to 802.3 encapsulation for transmit packets.
Masahiro Yamadae1c05062015-07-07 10:14:59 +0900157 * Assumes the entire DIX header is contiguous and that there is
Kalle Valobdcd8172011-07-18 00:22:30 +0300158 * enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
159 */
160int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
161{
162 struct ath6kl_llc_snap_hdr *llc_hdr;
163 struct ethhdr *eth_hdr;
164 size_t new_len;
165 __be16 type;
166 u8 *datap;
167 u16 size;
168
169 if (WARN_ON(skb == NULL))
170 return -EINVAL;
171
172 size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
173 if (skb_headroom(skb) < size)
174 return -ENOMEM;
175
176 eth_hdr = (struct ethhdr *) skb->data;
177 type = eth_hdr->h_proto;
178
179 if (!is_ethertype(be16_to_cpu(type))) {
180 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +0200181 "%s: pkt is already in 802.3 format\n", __func__);
Kalle Valobdcd8172011-07-18 00:22:30 +0300182 return 0;
183 }
184
185 new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
186
187 skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
188 datap = skb->data;
189
190 eth_hdr->h_proto = cpu_to_be16(new_len);
191
192 memcpy(datap, eth_hdr, sizeof(*eth_hdr));
193
194 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
195 llc_hdr->dsap = 0xAA;
196 llc_hdr->ssap = 0xAA;
197 llc_hdr->cntl = 0x03;
198 llc_hdr->org_code[0] = 0x0;
199 llc_hdr->org_code[1] = 0x0;
200 llc_hdr->org_code[2] = 0x0;
201 llc_hdr->eth_type = type;
202
203 return 0;
204}
205
206static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
207 u8 *version, void *tx_meta_info)
208{
209 struct wmi_tx_meta_v1 *v1;
210 struct wmi_tx_meta_v2 *v2;
211
212 if (WARN_ON(skb == NULL || version == NULL))
213 return -EINVAL;
214
215 switch (*version) {
216 case WMI_META_VERSION_1:
217 skb_push(skb, WMI_MAX_TX_META_SZ);
218 v1 = (struct wmi_tx_meta_v1 *) skb->data;
219 v1->pkt_id = 0;
220 v1->rate_plcy_id = 0;
221 *version = WMI_META_VERSION_1;
222 break;
223 case WMI_META_VERSION_2:
224 skb_push(skb, WMI_MAX_TX_META_SZ);
225 v2 = (struct wmi_tx_meta_v2 *) skb->data;
226 memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
227 sizeof(struct wmi_tx_meta_v2));
228 break;
229 }
230
231 return 0;
232}
233
234int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530235 u8 msg_type, u32 flags,
Kalle Valobdcd8172011-07-18 00:22:30 +0300236 enum wmi_data_hdr_data_type data_type,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +0530237 u8 meta_ver, void *tx_meta_info, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +0300238{
239 struct wmi_data_hdr *data_hdr;
240 int ret;
241
Kalle Valo71f96ee2011-11-14 19:31:30 +0200242 if (WARN_ON(skb == NULL || (if_idx > wmi->parent_dev->vif_max - 1)))
Kalle Valobdcd8172011-07-18 00:22:30 +0300243 return -EINVAL;
244
Vasanthakumar Thiagarajan3ce6ff52011-08-22 20:40:21 +0530245 if (tx_meta_info) {
246 ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
247 if (ret)
248 return ret;
249 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300250
251 skb_push(skb, sizeof(struct wmi_data_hdr));
252
253 data_hdr = (struct wmi_data_hdr *)skb->data;
254 memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
255
256 data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
257 data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
258
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530259 if (flags & WMI_DATA_HDR_FLAGS_MORE)
260 data_hdr->info |= WMI_DATA_HDR_MORE;
Kalle Valobdcd8172011-07-18 00:22:30 +0300261
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530262 if (flags & WMI_DATA_HDR_FLAGS_EOSP)
263 data_hdr->info3 |= cpu_to_le16(WMI_DATA_HDR_EOSP);
264
265 data_hdr->info2 |= cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
266 data_hdr->info3 |= cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
Kalle Valobdcd8172011-07-18 00:22:30 +0300267
268 return 0;
269}
270
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530271u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
Kalle Valobdcd8172011-07-18 00:22:30 +0300272{
273 struct iphdr *ip_hdr = (struct iphdr *) pkt;
274 u8 ip_pri;
275
276 /*
277 * Determine IPTOS priority
278 *
279 * IP-TOS - 8bits
280 * : DSCP(6-bits) ECN(2-bits)
281 * : DSCP - P2 P1 P0 X X X
282 * where (P2 P1 P0) form 802.1D
283 */
284 ip_pri = ip_hdr->tos >> 5;
285 ip_pri &= 0x7;
286
287 if ((layer2_pri & 0x7) > ip_pri)
288 return (u8) layer2_pri & 0x7;
289 else
290 return ip_pri;
291}
292
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530293u8 ath6kl_wmi_get_traffic_class(u8 user_priority)
294{
295 return up_to_ac[user_priority & 0x7];
296}
297
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530298int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, u8 if_idx,
299 struct sk_buff *skb,
Kalle Valobdcd8172011-07-18 00:22:30 +0300300 u32 layer2_priority, bool wmm_enabled,
301 u8 *ac)
302{
303 struct wmi_data_hdr *data_hdr;
304 struct ath6kl_llc_snap_hdr *llc_hdr;
305 struct wmi_create_pstream_cmd cmd;
306 u32 meta_size, hdr_size;
307 u16 ip_type = IP_ETHERTYPE;
308 u8 stream_exist, usr_pri;
309 u8 traffic_class = WMM_AC_BE;
310 u8 *datap;
311
312 if (WARN_ON(skb == NULL))
313 return -EINVAL;
314
315 datap = skb->data;
316 data_hdr = (struct wmi_data_hdr *) datap;
317
318 meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
319 WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
320
321 if (!wmm_enabled) {
322 /* If WMM is disabled all traffic goes as BE traffic */
323 usr_pri = 0;
324 } else {
325 hdr_size = sizeof(struct ethhdr);
326
327 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
328 sizeof(struct
329 wmi_data_hdr) +
330 meta_size + hdr_size);
331
332 if (llc_hdr->eth_type == htons(ip_type)) {
333 /*
334 * Extract the endpoint info from the TOS field
335 * in the IP header.
336 */
337 usr_pri =
338 ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
339 sizeof(struct ath6kl_llc_snap_hdr),
340 layer2_priority);
Kalle Valoa5d8f9d2014-03-11 12:58:01 +0200341 } else {
Kalle Valobdcd8172011-07-18 00:22:30 +0300342 usr_pri = layer2_priority & 0x7;
Kalle Valoa5d8f9d2014-03-11 12:58:01 +0200343 }
Vivek Natarajanf3740572012-05-02 14:55:25 +0530344
345 /*
346 * Queue the EAPOL frames in the same WMM_AC_VO queue
347 * as that of management frames.
348 */
349 if (skb->protocol == cpu_to_be16(ETH_P_PAE))
350 usr_pri = WMI_VOICE_USER_PRIORITY;
Kalle Valobdcd8172011-07-18 00:22:30 +0300351 }
352
Kalle Valoa7f0c582011-10-05 12:23:05 +0300353 /*
354 * workaround for WMM S5
355 *
356 * FIXME: wmi->traffic_class is always 100 so this test doesn't
357 * make sense
358 */
Kalle Valobdcd8172011-07-18 00:22:30 +0300359 if ((wmi->traffic_class == WMM_AC_VI) &&
360 ((usr_pri == 5) || (usr_pri == 4)))
361 usr_pri = 1;
362
363 /* Convert user priority to traffic class */
364 traffic_class = up_to_ac[usr_pri & 0x7];
365
366 wmi_data_hdr_set_up(data_hdr, usr_pri);
367
368 spin_lock_bh(&wmi->lock);
369 stream_exist = wmi->fat_pipe_exist;
370 spin_unlock_bh(&wmi->lock);
371
372 if (!(stream_exist & (1 << traffic_class))) {
373 memset(&cmd, 0, sizeof(cmd));
374 cmd.traffic_class = traffic_class;
375 cmd.user_pri = usr_pri;
376 cmd.inactivity_int =
377 cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
378 /* Implicit streams are created with TSID 0xFF */
379 cmd.tsid = WMI_IMPLICIT_PSTREAM;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530380 ath6kl_wmi_create_pstream_cmd(wmi, if_idx, &cmd);
Kalle Valobdcd8172011-07-18 00:22:30 +0300381 }
382
383 *ac = traffic_class;
384
385 return 0;
386}
387
388int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
389{
390 struct ieee80211_hdr_3addr *pwh, wh;
391 struct ath6kl_llc_snap_hdr *llc_hdr;
392 struct ethhdr eth_hdr;
393 u32 hdr_size;
394 u8 *datap;
395 __le16 sub_type;
396
397 if (WARN_ON(skb == NULL))
398 return -EINVAL;
399
400 datap = skb->data;
401 pwh = (struct ieee80211_hdr_3addr *) datap;
402
403 sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
404
405 memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
406
407 /* Strip off the 802.11 header */
408 if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
409 hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
410 sizeof(u32));
411 skb_pull(skb, hdr_size);
Kalle Valoa5d8f9d2014-03-11 12:58:01 +0200412 } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA)) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300413 skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
Kalle Valoa5d8f9d2014-03-11 12:58:01 +0200414 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300415
416 datap = skb->data;
417 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
418
Raja Manic8790cb2011-07-19 19:27:32 +0530419 memset(&eth_hdr, 0, sizeof(eth_hdr));
Kalle Valobdcd8172011-07-18 00:22:30 +0300420 eth_hdr.h_proto = llc_hdr->eth_type;
Kalle Valobdcd8172011-07-18 00:22:30 +0300421
422 switch ((le16_to_cpu(wh.frame_control)) &
423 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
424 case 0:
425 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
426 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
427 break;
428 case IEEE80211_FCTL_TODS:
429 memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
430 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
431 break;
432 case IEEE80211_FCTL_FROMDS:
433 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
434 memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
435 break;
436 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
437 break;
438 }
439
440 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
441 skb_push(skb, sizeof(eth_hdr));
442
443 datap = skb->data;
444
445 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
446
447 return 0;
448}
449
450/*
451 * Performs 802.3 to DIX encapsulation for received packets.
Masahiro Yamadae1c05062015-07-07 10:14:59 +0900452 * Assumes the entire 802.3 header is contiguous.
Kalle Valobdcd8172011-07-18 00:22:30 +0300453 */
454int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
455{
456 struct ath6kl_llc_snap_hdr *llc_hdr;
457 struct ethhdr eth_hdr;
458 u8 *datap;
459
460 if (WARN_ON(skb == NULL))
461 return -EINVAL;
462
463 datap = skb->data;
464
465 memcpy(&eth_hdr, datap, sizeof(eth_hdr));
466
467 llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
468 eth_hdr.h_proto = llc_hdr->eth_type;
469
470 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
471 datap = skb->data;
472
473 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
474
475 return 0;
476}
477
Kalle Valobdcd8172011-07-18 00:22:30 +0300478static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
479{
480 struct tx_complete_msg_v1 *msg_v1;
481 struct wmi_tx_complete_event *evt;
482 int index;
483 u16 size;
484
485 evt = (struct wmi_tx_complete_event *) datap;
486
487 ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
488 evt->num_msg, evt->msg_len, evt->msg_type);
489
Kalle Valobdcd8172011-07-18 00:22:30 +0300490 for (index = 0; index < evt->num_msg; index++) {
491 size = sizeof(struct wmi_tx_complete_event) +
492 (index * sizeof(struct tx_complete_msg_v1));
493 msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
494
495 ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
496 msg_v1->status, msg_v1->pkt_id,
497 msg_v1->rate_idx, msg_v1->ack_failures);
498 }
499
500 return 0;
501}
502
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300503static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530504 int len, struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300505{
506 struct wmi_remain_on_chnl_event *ev;
507 u32 freq;
508 u32 dur;
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300509 struct ieee80211_channel *chan;
510 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen10522612011-10-27 16:00:13 +0300511 u32 id;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300512
513 if (len < sizeof(*ev))
514 return -EINVAL;
515
516 ev = (struct wmi_remain_on_chnl_event *) datap;
517 freq = le32_to_cpu(ev->freq);
518 dur = le32_to_cpu(ev->duration);
519 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
520 freq, dur);
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530521 chan = ieee80211_get_channel(ar->wiphy, freq);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300522 if (!chan) {
Kalle Valocdeb8602012-04-12 11:02:18 +0300523 ath6kl_dbg(ATH6KL_DBG_WMI,
524 "remain_on_chnl: Unknown channel (freq=%u)\n",
525 freq);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300526 return -EINVAL;
527 }
Jouni Malinen10522612011-10-27 16:00:13 +0300528 id = vif->last_roc_id;
Johannes Berg42d97a52012-11-08 18:31:02 +0100529 cfg80211_ready_on_channel(&vif->wdev, id, chan,
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300530 dur, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300531
532 return 0;
533}
534
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300535static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530536 u8 *datap, int len,
537 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300538{
539 struct wmi_cancel_remain_on_chnl_event *ev;
540 u32 freq;
541 u32 dur;
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300542 struct ieee80211_channel *chan;
543 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen10522612011-10-27 16:00:13 +0300544 u32 id;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300545
546 if (len < sizeof(*ev))
547 return -EINVAL;
548
549 ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
550 freq = le32_to_cpu(ev->freq);
551 dur = le32_to_cpu(ev->duration);
Kalle Valocdeb8602012-04-12 11:02:18 +0300552 ath6kl_dbg(ATH6KL_DBG_WMI,
553 "cancel_remain_on_chnl: freq=%u dur=%u status=%u\n",
554 freq, dur, ev->status);
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530555 chan = ieee80211_get_channel(ar->wiphy, freq);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300556 if (!chan) {
Kalle Valocdeb8602012-04-12 11:02:18 +0300557 ath6kl_dbg(ATH6KL_DBG_WMI,
558 "cancel_remain_on_chnl: Unknown channel (freq=%u)\n",
559 freq);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300560 return -EINVAL;
561 }
Jouni Malinen10522612011-10-27 16:00:13 +0300562 if (vif->last_cancel_roc_id &&
563 vif->last_cancel_roc_id + 1 == vif->last_roc_id)
564 id = vif->last_cancel_roc_id; /* event for cancel command */
565 else
566 id = vif->last_roc_id; /* timeout on uncanceled r-o-c */
567 vif->last_cancel_roc_id = 0;
Johannes Berg42d97a52012-11-08 18:31:02 +0100568 cfg80211_remain_on_channel_expired(&vif->wdev, id, chan, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300569
570 return 0;
571}
572
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530573static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len,
574 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300575{
576 struct wmi_tx_status_event *ev;
577 u32 id;
578
579 if (len < sizeof(*ev))
580 return -EINVAL;
581
582 ev = (struct wmi_tx_status_event *) datap;
583 id = le32_to_cpu(ev->id);
584 ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
585 id, ev->ack_status);
Jouni Malinena0df5db2011-08-30 21:58:02 +0300586 if (wmi->last_mgmt_tx_frame) {
Johannes Berg71bbc992012-06-15 15:30:18 +0200587 cfg80211_mgmt_tx_status(&vif->wdev, id,
Jouni Malinena0df5db2011-08-30 21:58:02 +0300588 wmi->last_mgmt_tx_frame,
589 wmi->last_mgmt_tx_frame_len,
590 !!ev->ack_status, GFP_ATOMIC);
591 kfree(wmi->last_mgmt_tx_frame);
592 wmi->last_mgmt_tx_frame = NULL;
593 wmi->last_mgmt_tx_frame_len = 0;
594 }
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300595
596 return 0;
597}
598
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530599static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len,
600 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300601{
602 struct wmi_p2p_rx_probe_req_event *ev;
Jouni Malinenae32c302011-08-30 21:58:01 +0300603 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300604 u16 dlen;
605
606 if (len < sizeof(*ev))
607 return -EINVAL;
608
609 ev = (struct wmi_p2p_rx_probe_req_event *) datap;
Jouni Malinenae32c302011-08-30 21:58:01 +0300610 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300611 dlen = le16_to_cpu(ev->len);
Jouni Malinenae32c302011-08-30 21:58:01 +0300612 if (datap + len < ev->data + dlen) {
Kalle Valocdeb8602012-04-12 11:02:18 +0300613 ath6kl_err("invalid wmi_p2p_rx_probe_req_event: len=%d dlen=%u\n",
614 len, dlen);
Jouni Malinenae32c302011-08-30 21:58:01 +0300615 return -EINVAL;
616 }
Kalle Valocdeb8602012-04-12 11:02:18 +0300617 ath6kl_dbg(ATH6KL_DBG_WMI,
618 "rx_probe_req: len=%u freq=%u probe_req_report=%d\n",
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530619 dlen, freq, vif->probe_req_report);
Jouni Malinenae32c302011-08-30 21:58:01 +0300620
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530621 if (vif->probe_req_report || vif->nw_type == AP_NETWORK)
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -0700622 cfg80211_rx_mgmt(&vif->wdev, freq, 0, ev->data, dlen, 0);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300623
624 return 0;
625}
626
627static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
628{
629 struct wmi_p2p_capabilities_event *ev;
630 u16 dlen;
631
632 if (len < sizeof(*ev))
633 return -EINVAL;
634
635 ev = (struct wmi_p2p_capabilities_event *) datap;
636 dlen = le16_to_cpu(ev->len);
637 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
638
639 return 0;
640}
641
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530642static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len,
643 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300644{
645 struct wmi_rx_action_event *ev;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300646 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300647 u16 dlen;
648
649 if (len < sizeof(*ev))
650 return -EINVAL;
651
652 ev = (struct wmi_rx_action_event *) datap;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300653 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300654 dlen = le16_to_cpu(ev->len);
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300655 if (datap + len < ev->data + dlen) {
Kalle Valocdeb8602012-04-12 11:02:18 +0300656 ath6kl_err("invalid wmi_rx_action_event: len=%d dlen=%u\n",
657 len, dlen);
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300658 return -EINVAL;
659 }
660 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -0700661 cfg80211_rx_mgmt(&vif->wdev, freq, 0, ev->data, dlen, 0);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300662
663 return 0;
664}
665
666static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
667{
668 struct wmi_p2p_info_event *ev;
669 u32 flags;
670 u16 dlen;
671
672 if (len < sizeof(*ev))
673 return -EINVAL;
674
675 ev = (struct wmi_p2p_info_event *) datap;
676 flags = le32_to_cpu(ev->info_req_flags);
677 dlen = le16_to_cpu(ev->len);
678 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
679
680 if (flags & P2P_FLAG_CAPABILITIES_REQ) {
681 struct wmi_p2p_capabilities *cap;
682 if (dlen < sizeof(*cap))
683 return -EINVAL;
684 cap = (struct wmi_p2p_capabilities *) ev->data;
685 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
686 cap->go_power_save);
687 }
688
689 if (flags & P2P_FLAG_MACADDR_REQ) {
690 struct wmi_p2p_macaddr *mac;
691 if (dlen < sizeof(*mac))
692 return -EINVAL;
693 mac = (struct wmi_p2p_macaddr *) ev->data;
694 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
695 mac->mac_addr);
696 }
697
698 if (flags & P2P_FLAG_HMODEL_REQ) {
699 struct wmi_p2p_hmodel *mod;
700 if (dlen < sizeof(*mod))
701 return -EINVAL;
702 mod = (struct wmi_p2p_hmodel *) ev->data;
703 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
704 mod->p2p_model,
705 mod->p2p_model ? "host" : "firmware");
706 }
707 return 0;
708}
709
Kalle Valobdcd8172011-07-18 00:22:30 +0300710static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
711{
712 struct sk_buff *skb;
713
714 skb = ath6kl_buf_alloc(size);
715 if (!skb)
716 return NULL;
717
718 skb_put(skb, size);
719 if (size)
720 memset(skb->data, 0, size);
721
722 return skb;
723}
724
725/* Send a "simple" wmi command -- one with no arguments */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530726static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx,
727 enum wmi_cmd_id cmd_id)
Kalle Valobdcd8172011-07-18 00:22:30 +0300728{
729 struct sk_buff *skb;
730 int ret;
731
732 skb = ath6kl_wmi_get_new_buf(0);
733 if (!skb)
734 return -ENOMEM;
735
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530736 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +0300737
738 return ret;
739}
740
741static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
742{
743 struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
744
745 if (len < sizeof(struct wmi_ready_event_2))
746 return -EINVAL;
747
Kalle Valobdcd8172011-07-18 00:22:30 +0300748 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
749 le32_to_cpu(ev->sw_version),
Thomas Pedersend92917e2012-04-19 15:31:56 -0700750 le32_to_cpu(ev->abi_version), ev->phy_cap);
Kalle Valobdcd8172011-07-18 00:22:30 +0300751
752 return 0;
753}
754
Vivek Natarajane5090442011-08-31 15:02:19 +0530755/*
756 * Mechanism to modify the roaming behavior in the firmware. The lower rssi
757 * at which the station has to roam can be passed with
758 * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
759 * in dBm.
760 */
761int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
762{
763 struct sk_buff *skb;
764 struct roam_ctrl_cmd *cmd;
765
766 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
767 if (!skb)
768 return -ENOMEM;
769
770 cmd = (struct roam_ctrl_cmd *) skb->data;
771
772 cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
773 cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
774 DEF_SCAN_FOR_ROAM_INTVL);
775 cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
776 cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
777 cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
778
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530779 ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
780 NO_SYNC_WMIFLAG);
Vivek Natarajane5090442011-08-31 15:02:19 +0530781
782 return 0;
783}
784
Jouni Malinen12618752011-10-11 17:31:55 +0300785int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
786{
787 struct sk_buff *skb;
788 struct roam_ctrl_cmd *cmd;
789
790 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
791 if (!skb)
792 return -ENOMEM;
793
794 cmd = (struct roam_ctrl_cmd *) skb->data;
Jouni Malinen12618752011-10-11 17:31:55 +0300795
796 memcpy(cmd->info.bssid, bssid, ETH_ALEN);
797 cmd->roam_ctrl = WMI_FORCE_ROAM;
798
799 ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530800 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
Jouni Malinen12618752011-10-11 17:31:55 +0300801 NO_SYNC_WMIFLAG);
802}
803
Mohammed Shafi Shajakhaneb922e42012-11-16 18:23:15 +0530804int ath6kl_wmi_ap_set_beacon_intvl_cmd(struct wmi *wmi, u8 if_idx,
805 u32 beacon_intvl)
806{
807 struct sk_buff *skb;
808 struct set_beacon_int_cmd *cmd;
809
810 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
811 if (!skb)
812 return -ENOMEM;
813
814 cmd = (struct set_beacon_int_cmd *) skb->data;
815
816 cmd->beacon_intvl = cpu_to_le32(beacon_intvl);
817 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
818 WMI_SET_BEACON_INT_CMDID, NO_SYNC_WMIFLAG);
819}
820
Etay Luzd154f322012-05-30 11:35:08 +0300821int ath6kl_wmi_ap_set_dtim_cmd(struct wmi *wmi, u8 if_idx, u32 dtim_period)
822{
823 struct sk_buff *skb;
824 struct set_dtim_cmd *cmd;
825
826 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
827 if (!skb)
828 return -ENOMEM;
829
830 cmd = (struct set_dtim_cmd *) skb->data;
831
832 cmd->dtim_period = cpu_to_le32(dtim_period);
833 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
834 WMI_AP_SET_DTIM_CMDID, NO_SYNC_WMIFLAG);
835}
836
Jouni Malinen12618752011-10-11 17:31:55 +0300837int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
838{
839 struct sk_buff *skb;
840 struct roam_ctrl_cmd *cmd;
841
842 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
843 if (!skb)
844 return -ENOMEM;
845
846 cmd = (struct roam_ctrl_cmd *) skb->data;
Jouni Malinen12618752011-10-11 17:31:55 +0300847
848 cmd->info.roam_mode = mode;
849 cmd->roam_ctrl = WMI_SET_ROAM_MODE;
850
851 ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530852 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
Jouni Malinen12618752011-10-11 17:31:55 +0300853 NO_SYNC_WMIFLAG);
854}
855
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530856static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len,
857 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300858{
859 struct wmi_connect_event *ev;
860 u8 *pie, *peie;
861
862 if (len < sizeof(struct wmi_connect_event))
863 return -EINVAL;
864
865 ev = (struct wmi_connect_event *) datap;
866
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530867 if (vif->nw_type == AP_NETWORK) {
Jouni Malinen572e27c2011-09-05 17:38:45 +0300868 /* AP mode start/STA connected event */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530869 struct net_device *dev = vif->ndev;
Jouni Malinen572e27c2011-09-05 17:38:45 +0300870 if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
Kalle Valocdeb8602012-04-12 11:02:18 +0300871 ath6kl_dbg(ATH6KL_DBG_WMI,
872 "%s: freq %d bssid %pM (AP started)\n",
Jouni Malinen572e27c2011-09-05 17:38:45 +0300873 __func__, le16_to_cpu(ev->u.ap_bss.ch),
874 ev->u.ap_bss.bssid);
875 ath6kl_connect_ap_mode_bss(
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530876 vif, le16_to_cpu(ev->u.ap_bss.ch));
Jouni Malinen572e27c2011-09-05 17:38:45 +0300877 } else {
Kalle Valocdeb8602012-04-12 11:02:18 +0300878 ath6kl_dbg(ATH6KL_DBG_WMI,
879 "%s: aid %u mac_addr %pM auth=%u keymgmt=%u cipher=%u apsd_info=%u (STA connected)\n",
Jouni Malinen572e27c2011-09-05 17:38:45 +0300880 __func__, ev->u.ap_sta.aid,
881 ev->u.ap_sta.mac_addr,
882 ev->u.ap_sta.auth,
883 ev->u.ap_sta.keymgmt,
884 le16_to_cpu(ev->u.ap_sta.cipher),
885 ev->u.ap_sta.apsd_info);
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530886
Jouni Malinen572e27c2011-09-05 17:38:45 +0300887 ath6kl_connect_ap_mode_sta(
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530888 vif, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300889 ev->u.ap_sta.keymgmt,
890 le16_to_cpu(ev->u.ap_sta.cipher),
891 ev->u.ap_sta.auth, ev->assoc_req_len,
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530892 ev->assoc_info + ev->beacon_ie_len,
893 ev->u.ap_sta.apsd_info);
Jouni Malinen572e27c2011-09-05 17:38:45 +0300894 }
895 return 0;
896 }
897
898 /* STA/IBSS mode connection event */
899
Kalle Valob9b6ee62011-09-27 14:31:21 +0300900 ath6kl_dbg(ATH6KL_DBG_WMI,
901 "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
902 le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
903 le16_to_cpu(ev->u.sta.listen_intvl),
904 le16_to_cpu(ev->u.sta.beacon_intvl),
905 le32_to_cpu(ev->u.sta.nw_type));
Kalle Valobdcd8172011-07-18 00:22:30 +0300906
Kalle Valobdcd8172011-07-18 00:22:30 +0300907 /* Start of assoc rsp IEs */
908 pie = ev->assoc_info + ev->beacon_ie_len +
909 ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
910
911 /* End of assoc rsp IEs */
912 peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
913 ev->assoc_resp_len;
914
915 while (pie < peie) {
916 switch (*pie) {
917 case WLAN_EID_VENDOR_SPECIFIC:
918 if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
919 pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
920 /* WMM OUT (00:50:F2) */
Kalle Valoddc3d772012-03-07 20:03:58 +0200921 if (pie[1] > 5 &&
922 pie[6] == WMM_PARAM_OUI_SUBTYPE)
Kalle Valobdcd8172011-07-18 00:22:30 +0300923 wmi->is_wmm_enabled = true;
924 }
925 break;
926 }
927
928 if (wmi->is_wmm_enabled)
929 break;
930
931 pie += pie[1] + 2;
932 }
933
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530934 ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch),
Jouni Malinen572e27c2011-09-05 17:38:45 +0300935 ev->u.sta.bssid,
936 le16_to_cpu(ev->u.sta.listen_intvl),
937 le16_to_cpu(ev->u.sta.beacon_intvl),
938 le32_to_cpu(ev->u.sta.nw_type),
Kalle Valobdcd8172011-07-18 00:22:30 +0300939 ev->beacon_ie_len, ev->assoc_req_len,
940 ev->assoc_resp_len, ev->assoc_info);
941
942 return 0;
943}
944
Vivek Natarajan06033762011-09-06 13:01:36 +0530945static struct country_code_to_enum_rd *
946ath6kl_regd_find_country(u16 countryCode)
947{
948 int i;
949
950 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
951 if (allCountries[i].countryCode == countryCode)
952 return &allCountries[i];
953 }
954
955 return NULL;
956}
957
958static struct reg_dmn_pair_mapping *
959ath6kl_get_regpair(u16 regdmn)
960{
961 int i;
962
963 if (regdmn == NO_ENUMRD)
964 return NULL;
965
966 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
Kalle Valoef8c0012014-02-13 18:13:12 +0200967 if (regDomainPairs[i].reg_domain == regdmn)
Vivek Natarajan06033762011-09-06 13:01:36 +0530968 return &regDomainPairs[i];
969 }
970
971 return NULL;
972}
973
974static struct country_code_to_enum_rd *
975ath6kl_regd_find_country_by_rd(u16 regdmn)
976{
977 int i;
978
979 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
980 if (allCountries[i].regDmnEnum == regdmn)
981 return &allCountries[i];
982 }
983
984 return NULL;
985}
986
987static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
988{
Vivek Natarajan06033762011-09-06 13:01:36 +0530989 struct ath6kl_wmi_regdomain *ev;
990 struct country_code_to_enum_rd *country = NULL;
991 struct reg_dmn_pair_mapping *regpair = NULL;
992 char alpha2[2];
993 u32 reg_code;
994
995 ev = (struct ath6kl_wmi_regdomain *) datap;
996 reg_code = le32_to_cpu(ev->reg_code);
997
Kalle Valoa5d8f9d2014-03-11 12:58:01 +0200998 if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG) {
Vivek Natarajan06033762011-09-06 13:01:36 +0530999 country = ath6kl_regd_find_country((u16) reg_code);
Kalle Valoa5d8f9d2014-03-11 12:58:01 +02001000 } else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
Vivek Natarajan06033762011-09-06 13:01:36 +05301001 regpair = ath6kl_get_regpair((u16) reg_code);
1002 country = ath6kl_regd_find_country_by_rd((u16) reg_code);
Raja Mani43a06b32012-09-21 15:08:53 +05301003 if (regpair)
1004 ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
Kalle Valoef8c0012014-02-13 18:13:12 +02001005 regpair->reg_domain);
Raja Mani43a06b32012-09-21 15:08:53 +05301006 else
1007 ath6kl_warn("Regpair not found reg_code 0x%0x\n",
1008 reg_code);
Vivek Natarajan06033762011-09-06 13:01:36 +05301009 }
1010
Vasanthakumar Thiagarajane5348a12012-02-25 14:43:17 +05301011 if (country && wmi->parent_dev->wiphy_registered) {
Vivek Natarajan06033762011-09-06 13:01:36 +05301012 alpha2[0] = country->isoName[0];
1013 alpha2[1] = country->isoName[1];
1014
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301015 regulatory_hint(wmi->parent_dev->wiphy, alpha2);
Vivek Natarajan06033762011-09-06 13:01:36 +05301016
Kalle Valob9b6ee62011-09-27 14:31:21 +03001017 ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
Kalle Valo96f1fad2012-03-07 20:03:57 +02001018 alpha2[0], alpha2[1]);
Vivek Natarajan06033762011-09-06 13:01:36 +05301019 }
1020}
1021
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301022static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len,
1023 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001024{
1025 struct wmi_disconnect_event *ev;
1026 wmi->traffic_class = 100;
1027
1028 if (len < sizeof(struct wmi_disconnect_event))
1029 return -EINVAL;
1030
1031 ev = (struct wmi_disconnect_event *) datap;
Kalle Valobdcd8172011-07-18 00:22:30 +03001032
Kalle Valob9b6ee62011-09-27 14:31:21 +03001033 ath6kl_dbg(ATH6KL_DBG_WMI,
1034 "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
1035 le16_to_cpu(ev->proto_reason_status), ev->bssid,
1036 ev->disconn_reason, ev->assoc_resp_len);
1037
Kalle Valobdcd8172011-07-18 00:22:30 +03001038 wmi->is_wmm_enabled = false;
Kalle Valobdcd8172011-07-18 00:22:30 +03001039
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301040 ath6kl_disconnect_event(vif, ev->disconn_reason,
Kalle Valobdcd8172011-07-18 00:22:30 +03001041 ev->bssid, ev->assoc_resp_len, ev->assoc_info,
1042 le16_to_cpu(ev->proto_reason_status));
1043
1044 return 0;
1045}
1046
1047static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
1048{
1049 struct wmi_peer_node_event *ev;
1050
1051 if (len < sizeof(struct wmi_peer_node_event))
1052 return -EINVAL;
1053
1054 ev = (struct wmi_peer_node_event *) datap;
1055
1056 if (ev->event_code == PEER_NODE_JOIN_EVENT)
1057 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
1058 ev->peer_mac_addr);
1059 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
1060 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
1061 ev->peer_mac_addr);
1062
1063 return 0;
1064}
1065
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301066static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
1067 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001068{
1069 struct wmi_tkip_micerr_event *ev;
1070
1071 if (len < sizeof(struct wmi_tkip_micerr_event))
1072 return -EINVAL;
1073
1074 ev = (struct wmi_tkip_micerr_event *) datap;
1075
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301076 ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
Kalle Valobdcd8172011-07-18 00:22:30 +03001077
1078 return 0;
1079}
1080
Kalle Valo10509f92011-12-13 14:52:07 +02001081void ath6kl_wmi_sscan_timer(unsigned long ptr)
1082{
1083 struct ath6kl_vif *vif = (struct ath6kl_vif *) ptr;
1084
1085 cfg80211_sched_scan_results(vif->ar->wiphy);
1086}
1087
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301088static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
1089 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001090{
Jouni Malinen82e14f52011-09-19 19:15:05 +03001091 struct wmi_bss_info_hdr2 *bih;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001092 u8 *buf;
1093 struct ieee80211_channel *channel;
1094 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001095 struct cfg80211_bss *bss;
Kalle Valobdcd8172011-07-18 00:22:30 +03001096
Jouni Malinen82e14f52011-09-19 19:15:05 +03001097 if (len <= sizeof(struct wmi_bss_info_hdr2))
Kalle Valobdcd8172011-07-18 00:22:30 +03001098 return -EINVAL;
1099
Jouni Malinen82e14f52011-09-19 19:15:05 +03001100 bih = (struct wmi_bss_info_hdr2 *) datap;
1101 buf = datap + sizeof(struct wmi_bss_info_hdr2);
1102 len -= sizeof(struct wmi_bss_info_hdr2);
Kalle Valobdcd8172011-07-18 00:22:30 +03001103
1104 ath6kl_dbg(ATH6KL_DBG_WMI,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001105 "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
1106 "frame_type=%d\n",
Jouni Malinen82e14f52011-09-19 19:15:05 +03001107 bih->ch, bih->snr, bih->snr - 95, bih->bssid,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001108 bih->frame_type);
Kalle Valobdcd8172011-07-18 00:22:30 +03001109
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001110 if (bih->frame_type != BEACON_FTYPE &&
1111 bih->frame_type != PROBERESP_FTYPE)
1112 return 0; /* Only update BSS table for now */
Kalle Valobdcd8172011-07-18 00:22:30 +03001113
Jouni Malinen551185c2011-09-19 19:15:06 +03001114 if (bih->frame_type == BEACON_FTYPE &&
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301115 test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
1116 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301117 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1118 NONE_BSS_FILTER, 0);
Jouni Malinen551185c2011-09-19 19:15:06 +03001119 }
1120
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301121 channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001122 if (channel == NULL)
1123 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001124
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001125 if (len < 8 + 2 + 2)
1126 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001127
Kalle Valoddc3d772012-03-07 20:03:58 +02001128 if (bih->frame_type == BEACON_FTYPE &&
1129 test_bit(CONNECTED, &vif->flags) &&
1130 memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
Jouni Malinen32c10872011-09-19 19:15:07 +03001131 const u8 *tim;
1132 tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
1133 len - 8 - 2 - 2);
1134 if (tim && tim[1] >= 2) {
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301135 vif->assoc_bss_dtim_period = tim[3];
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301136 set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
Jouni Malinen32c10872011-09-19 19:15:07 +03001137 }
1138 }
1139
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02001140 bss = cfg80211_inform_bss(ar->wiphy, channel,
1141 bih->frame_type == BEACON_FTYPE ?
1142 CFG80211_BSS_FTYPE_BEACON :
1143 CFG80211_BSS_FTYPE_PRESP,
1144 bih->bssid, get_unaligned_le64((__le64 *)buf),
1145 get_unaligned_le16(((__le16 *)buf) + 5),
1146 get_unaligned_le16(((__le16 *)buf) + 4),
1147 buf + 8 + 2 + 2, len - 8 - 2 - 2,
1148 (bih->snr - 95) * 100, GFP_ATOMIC);
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001149 if (bss == NULL)
Kalle Valobdcd8172011-07-18 00:22:30 +03001150 return -ENOMEM;
Johannes Berg5b112d32013-02-01 01:49:58 +01001151 cfg80211_put_bss(ar->wiphy, bss);
Kalle Valobdcd8172011-07-18 00:22:30 +03001152
Kalle Valo10509f92011-12-13 14:52:07 +02001153 /*
1154 * Firmware doesn't return any event when scheduled scan has
1155 * finished, so we need to use a timer to find out when there are
1156 * no more results.
1157 *
1158 * The timer is started from the first bss info received, otherwise
1159 * the timer would not ever fire if the scan interval is short
1160 * enough.
1161 */
Thomas Pedersenb1f47e32012-08-15 16:51:24 -07001162 if (test_bit(SCHED_SCANNING, &vif->flags) &&
Kalle Valo10509f92011-12-13 14:52:07 +02001163 !timer_pending(&vif->sched_scan_timer)) {
1164 mod_timer(&vif->sched_scan_timer, jiffies +
1165 msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY));
1166 }
1167
Kalle Valobdcd8172011-07-18 00:22:30 +03001168 return 0;
1169}
1170
Kalle Valobdcd8172011-07-18 00:22:30 +03001171/* Inactivity timeout of a fatpipe(pstream) at the target */
1172static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
1173 int len)
1174{
1175 struct wmi_pstream_timeout_event *ev;
1176
1177 if (len < sizeof(struct wmi_pstream_timeout_event))
1178 return -EINVAL;
1179
1180 ev = (struct wmi_pstream_timeout_event *) datap;
Dan Carpenter8e8b0ba2019-04-04 11:56:51 +03001181 if (ev->traffic_class >= WMM_NUM_AC) {
1182 ath6kl_err("invalid traffic class: %d\n", ev->traffic_class);
1183 return -EINVAL;
1184 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001185
1186 /*
1187 * When the pstream (fat pipe == AC) timesout, it means there were
1188 * no thinStreams within this pstream & it got implicitly created
1189 * due to data flow on this AC. We start the inactivity timer only
1190 * for implicitly created pstream. Just reset the host state.
1191 */
1192 spin_lock_bh(&wmi->lock);
1193 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1194 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1195 spin_unlock_bh(&wmi->lock);
1196
1197 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1198 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1199
1200 return 0;
1201}
1202
1203static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1204{
1205 struct wmi_bit_rate_reply *reply;
1206 s32 rate;
1207 u32 sgi, index;
1208
1209 if (len < sizeof(struct wmi_bit_rate_reply))
1210 return -EINVAL;
1211
1212 reply = (struct wmi_bit_rate_reply *) datap;
1213
1214 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1215
1216 if (reply->rate_index == (s8) RATE_AUTO) {
1217 rate = RATE_AUTO;
1218 } else {
1219 index = reply->rate_index & 0x7f;
Raja Manid54601b2012-09-21 15:08:54 +05301220 if (WARN_ON_ONCE(index > (RATE_MCS_7_40 + 1)))
1221 return -EINVAL;
1222
Kalle Valobdcd8172011-07-18 00:22:30 +03001223 sgi = (reply->rate_index & 0x80) ? 1 : 0;
1224 rate = wmi_rate_tbl[index][sgi];
1225 }
1226
1227 ath6kl_wakeup_event(wmi->parent_dev);
1228
1229 return 0;
1230}
1231
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08001232static int ath6kl_wmi_test_rx(struct wmi *wmi, u8 *datap, int len)
Kalle Valo003353b0d2011-09-01 10:14:21 +03001233{
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08001234 ath6kl_tm_rx_event(wmi->parent_dev, datap, len);
Kalle Valo003353b0d2011-09-01 10:14:21 +03001235
1236 return 0;
1237}
1238
Kalle Valobdcd8172011-07-18 00:22:30 +03001239static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1240{
1241 if (len < sizeof(struct wmi_fix_rates_reply))
1242 return -EINVAL;
1243
1244 ath6kl_wakeup_event(wmi->parent_dev);
1245
1246 return 0;
1247}
1248
1249static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1250{
1251 if (len < sizeof(struct wmi_channel_list_reply))
1252 return -EINVAL;
1253
1254 ath6kl_wakeup_event(wmi->parent_dev);
1255
1256 return 0;
1257}
1258
1259static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1260{
1261 struct wmi_tx_pwr_reply *reply;
1262
1263 if (len < sizeof(struct wmi_tx_pwr_reply))
1264 return -EINVAL;
1265
1266 reply = (struct wmi_tx_pwr_reply *) datap;
1267 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1268
1269 return 0;
1270}
1271
1272static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1273{
1274 if (len < sizeof(struct wmi_get_keepalive_cmd))
1275 return -EINVAL;
1276
1277 ath6kl_wakeup_event(wmi->parent_dev);
1278
1279 return 0;
1280}
1281
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301282static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
1283 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001284{
1285 struct wmi_scan_complete_event *ev;
1286
1287 ev = (struct wmi_scan_complete_event *) datap;
1288
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301289 ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
Kalle Valobdcd8172011-07-18 00:22:30 +03001290 wmi->is_probe_ssid = false;
1291
1292 return 0;
1293}
1294
Jouni Malinen86512132011-09-21 16:57:29 +03001295static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301296 int len, struct ath6kl_vif *vif)
Jouni Malinen86512132011-09-21 16:57:29 +03001297{
1298 struct wmi_neighbor_report_event *ev;
1299 u8 i;
1300
1301 if (len < sizeof(*ev))
1302 return -EINVAL;
1303 ev = (struct wmi_neighbor_report_event *) datap;
1304 if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
1305 > len) {
Kalle Valocdeb8602012-04-12 11:02:18 +03001306 ath6kl_dbg(ATH6KL_DBG_WMI,
1307 "truncated neighbor event (num=%d len=%d)\n",
1308 ev->num_neighbors, len);
Jouni Malinen86512132011-09-21 16:57:29 +03001309 return -EINVAL;
1310 }
1311 for (i = 0; i < ev->num_neighbors; i++) {
1312 ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
1313 i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
1314 ev->neighbor[i].bss_flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301315 cfg80211_pmksa_candidate_notify(vif->ndev, i,
Jouni Malinen86512132011-09-21 16:57:29 +03001316 ev->neighbor[i].bssid,
1317 !!(ev->neighbor[i].bss_flags &
1318 WMI_PREAUTH_CAPABLE_BSS),
1319 GFP_ATOMIC);
1320 }
1321
1322 return 0;
1323}
1324
Kalle Valobdcd8172011-07-18 00:22:30 +03001325/*
1326 * Target is reporting a programming error. This is for
1327 * developer aid only. Target only checks a few common violations
1328 * and it is responsibility of host to do all error checking.
1329 * Behavior of target after wmi error event is undefined.
1330 * A reset is recommended.
1331 */
1332static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1333{
1334 const char *type = "unknown error";
1335 struct wmi_cmd_error_event *ev;
1336 ev = (struct wmi_cmd_error_event *) datap;
1337
1338 switch (ev->err_code) {
1339 case INVALID_PARAM:
1340 type = "invalid parameter";
1341 break;
1342 case ILLEGAL_STATE:
1343 type = "invalid state";
1344 break;
1345 case INTERNAL_ERROR:
1346 type = "internal error";
1347 break;
1348 }
1349
1350 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1351 ev->cmd_id, type);
1352
1353 return 0;
1354}
1355
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301356static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
1357 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001358{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301359 ath6kl_tgt_stats_event(vif, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03001360
1361 return 0;
1362}
1363
1364static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1365 struct sq_threshold_params *sq_thresh,
1366 u32 size)
1367{
1368 u32 index;
1369 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1370
1371 /* The list is already in sorted order. Get the next lower value */
1372 for (index = 0; index < size; index++) {
1373 if (rssi < sq_thresh->upper_threshold[index]) {
1374 threshold = (u8) sq_thresh->upper_threshold[index];
1375 break;
1376 }
1377 }
1378
1379 return threshold;
1380}
1381
1382static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1383 struct sq_threshold_params *sq_thresh,
1384 u32 size)
1385{
1386 u32 index;
1387 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1388
1389 /* The list is already in sorted order. Get the next lower value */
1390 for (index = 0; index < size; index++) {
1391 if (rssi > sq_thresh->lower_threshold[index]) {
1392 threshold = (u8) sq_thresh->lower_threshold[index];
1393 break;
1394 }
1395 }
1396
1397 return threshold;
1398}
1399
1400static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1401 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1402{
1403 struct sk_buff *skb;
1404 struct wmi_rssi_threshold_params_cmd *cmd;
1405
1406 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1407 if (!skb)
1408 return -ENOMEM;
1409
1410 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1411 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1412
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301413 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001414 NO_SYNC_WMIFLAG);
1415}
1416
1417static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1418 int len)
1419{
1420 struct wmi_rssi_threshold_event *reply;
1421 struct wmi_rssi_threshold_params_cmd cmd;
1422 struct sq_threshold_params *sq_thresh;
1423 enum wmi_rssi_threshold_val new_threshold;
1424 u8 upper_rssi_threshold, lower_rssi_threshold;
1425 s16 rssi;
1426 int ret;
1427
1428 if (len < sizeof(struct wmi_rssi_threshold_event))
1429 return -EINVAL;
1430
1431 reply = (struct wmi_rssi_threshold_event *) datap;
1432 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1433 rssi = a_sle16_to_cpu(reply->rssi);
1434
1435 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1436
1437 /*
1438 * Identify the threshold breached and communicate that to the app.
1439 * After that install a new set of thresholds based on the signal
1440 * quality reported by the target
1441 */
1442 if (new_threshold) {
1443 /* Upper threshold breached */
1444 if (rssi < sq_thresh->upper_threshold[0]) {
1445 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001446 "spurious upper rssi threshold event: %d\n",
1447 rssi);
Kalle Valobdcd8172011-07-18 00:22:30 +03001448 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1449 (rssi >= sq_thresh->upper_threshold[0])) {
1450 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1451 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1452 (rssi >= sq_thresh->upper_threshold[1])) {
1453 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1454 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1455 (rssi >= sq_thresh->upper_threshold[2])) {
1456 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1457 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1458 (rssi >= sq_thresh->upper_threshold[3])) {
1459 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1460 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1461 (rssi >= sq_thresh->upper_threshold[4])) {
1462 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1463 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1464 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1465 }
1466 } else {
1467 /* Lower threshold breached */
1468 if (rssi > sq_thresh->lower_threshold[0]) {
1469 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001470 "spurious lower rssi threshold event: %d %d\n",
Kalle Valobdcd8172011-07-18 00:22:30 +03001471 rssi, sq_thresh->lower_threshold[0]);
1472 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1473 (rssi <= sq_thresh->lower_threshold[0])) {
1474 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1475 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1476 (rssi <= sq_thresh->lower_threshold[1])) {
1477 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1478 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1479 (rssi <= sq_thresh->lower_threshold[2])) {
1480 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1481 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1482 (rssi <= sq_thresh->lower_threshold[3])) {
1483 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1484 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1485 (rssi <= sq_thresh->lower_threshold[4])) {
1486 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1487 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1488 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1489 }
1490 }
1491
1492 /* Calculate and install the next set of thresholds */
1493 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1494 sq_thresh->lower_threshold_valid_count);
1495 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1496 sq_thresh->upper_threshold_valid_count);
1497
1498 /* Issue a wmi command to install the thresholds */
1499 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1500 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1501 cmd.weight = sq_thresh->weight;
1502 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1503
1504 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1505 if (ret) {
1506 ath6kl_err("unable to configure rssi thresholds\n");
1507 return -EIO;
1508 }
1509
1510 return 0;
1511}
1512
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301513static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
1514 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001515{
1516 struct wmi_cac_event *reply;
1517 struct ieee80211_tspec_ie *ts;
1518 u16 active_tsids, tsinfo;
1519 u8 tsid, index;
1520 u8 ts_id;
1521
1522 if (len < sizeof(struct wmi_cac_event))
1523 return -EINVAL;
1524
1525 reply = (struct wmi_cac_event *) datap;
Dan Carpenter8e8b0ba2019-04-04 11:56:51 +03001526 if (reply->ac >= WMM_NUM_AC) {
1527 ath6kl_err("invalid AC: %d\n", reply->ac);
1528 return -EINVAL;
1529 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001530
1531 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1532 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001533 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1534 tsinfo = le16_to_cpu(ts->tsinfo);
1535 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1536 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1537
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301538 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1539 reply->ac, tsid);
Kalle Valobdcd8172011-07-18 00:22:30 +03001540 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1541 /*
1542 * Following assumes that there is only one outstanding
1543 * ADDTS request when this event is received
1544 */
1545 spin_lock_bh(&wmi->lock);
1546 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1547 spin_unlock_bh(&wmi->lock);
1548
1549 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1550 if ((active_tsids >> index) & 1)
1551 break;
1552 }
1553 if (index < (sizeof(active_tsids) * 8))
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301554 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1555 reply->ac, index);
Kalle Valobdcd8172011-07-18 00:22:30 +03001556 }
1557
1558 /*
1559 * Clear active tsids and Add missing handling
1560 * for delete qos stream from AP
1561 */
1562 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001563 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1564 tsinfo = le16_to_cpu(ts->tsinfo);
1565 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1566 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1567
1568 spin_lock_bh(&wmi->lock);
1569 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1570 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1571 spin_unlock_bh(&wmi->lock);
1572
1573 /* Indicate stream inactivity to driver layer only if all tsids
1574 * within this AC are deleted.
1575 */
1576 if (!active_tsids) {
1577 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1578 false);
1579 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1580 }
1581 }
1582
1583 return 0;
1584}
1585
Thomas Pedersen279b2862012-07-17 19:39:55 -07001586static int ath6kl_wmi_txe_notify_event_rx(struct wmi *wmi, u8 *datap, int len,
1587 struct ath6kl_vif *vif)
1588{
1589 struct wmi_txe_notify_event *ev;
1590 u32 rate, pkts;
1591
1592 if (len < sizeof(*ev))
1593 return -EINVAL;
1594
Steve deRosierc9b260a2016-03-07 16:58:50 -08001595 if (vif->nw_type != INFRA_NETWORK ||
1596 !test_bit(ATH6KL_FW_CAPABILITY_TX_ERR_NOTIFY,
1597 vif->ar->fw_capabilities))
1598 return -EOPNOTSUPP;
1599
Thomas Pedersen279b2862012-07-17 19:39:55 -07001600 if (vif->sme_state != SME_CONNECTED)
1601 return -ENOTCONN;
1602
1603 ev = (struct wmi_txe_notify_event *) datap;
1604 rate = le32_to_cpu(ev->rate);
1605 pkts = le32_to_cpu(ev->pkts);
1606
1607 ath6kl_dbg(ATH6KL_DBG_WMI, "TXE notify event: peer %pM rate %d% pkts %d intvl %ds\n",
1608 vif->bssid, rate, pkts, vif->txe_intvl);
1609
1610 cfg80211_cqm_txe_notify(vif->ndev, vif->bssid, pkts,
1611 rate, vif->txe_intvl, GFP_KERNEL);
1612
1613 return 0;
1614}
1615
1616int ath6kl_wmi_set_txe_notify(struct wmi *wmi, u8 idx,
1617 u32 rate, u32 pkts, u32 intvl)
1618{
1619 struct sk_buff *skb;
1620 struct wmi_txe_notify_cmd *cmd;
1621
1622 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1623 if (!skb)
1624 return -ENOMEM;
1625
1626 cmd = (struct wmi_txe_notify_cmd *) skb->data;
1627 cmd->rate = cpu_to_le32(rate);
1628 cmd->pkts = cpu_to_le32(pkts);
1629 cmd->intvl = cpu_to_le32(intvl);
1630
1631 return ath6kl_wmi_cmd_send(wmi, idx, skb, WMI_SET_TXE_NOTIFY_CMDID,
1632 NO_SYNC_WMIFLAG);
1633}
1634
Thomas Pedersen85b20fc2012-06-21 12:50:08 -07001635int ath6kl_wmi_set_rssi_filter_cmd(struct wmi *wmi, u8 if_idx, s8 rssi)
1636{
1637 struct sk_buff *skb;
1638 struct wmi_set_rssi_filter_cmd *cmd;
1639 int ret;
1640
1641 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1642 if (!skb)
1643 return -ENOMEM;
1644
1645 cmd = (struct wmi_set_rssi_filter_cmd *) skb->data;
1646 cmd->rssi = rssi;
1647
1648 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_RSSI_FILTER_CMDID,
1649 NO_SYNC_WMIFLAG);
1650 return ret;
1651}
1652
Kalle Valobdcd8172011-07-18 00:22:30 +03001653static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1654 struct wmi_snr_threshold_params_cmd *snr_cmd)
1655{
1656 struct sk_buff *skb;
1657 struct wmi_snr_threshold_params_cmd *cmd;
1658
1659 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1660 if (!skb)
1661 return -ENOMEM;
1662
1663 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1664 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1665
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301666 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001667 NO_SYNC_WMIFLAG);
1668}
1669
1670static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1671 int len)
1672{
1673 struct wmi_snr_threshold_event *reply;
1674 struct sq_threshold_params *sq_thresh;
1675 struct wmi_snr_threshold_params_cmd cmd;
1676 enum wmi_snr_threshold_val new_threshold;
1677 u8 upper_snr_threshold, lower_snr_threshold;
1678 s16 snr;
1679 int ret;
1680
1681 if (len < sizeof(struct wmi_snr_threshold_event))
1682 return -EINVAL;
1683
1684 reply = (struct wmi_snr_threshold_event *) datap;
1685
1686 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1687 snr = reply->snr;
1688
1689 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1690
1691 /*
1692 * Identify the threshold breached and communicate that to the app.
1693 * After that install a new set of thresholds based on the signal
1694 * quality reported by the target.
1695 */
1696 if (new_threshold) {
1697 /* Upper threshold breached */
1698 if (snr < sq_thresh->upper_threshold[0]) {
1699 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001700 "spurious upper snr threshold event: %d\n",
1701 snr);
Kalle Valobdcd8172011-07-18 00:22:30 +03001702 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1703 (snr >= sq_thresh->upper_threshold[0])) {
1704 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1705 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1706 (snr >= sq_thresh->upper_threshold[1])) {
1707 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1708 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1709 (snr >= sq_thresh->upper_threshold[2])) {
1710 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1711 } else if (snr >= sq_thresh->upper_threshold[3]) {
1712 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1713 }
1714 } else {
1715 /* Lower threshold breached */
1716 if (snr > sq_thresh->lower_threshold[0]) {
1717 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001718 "spurious lower snr threshold event: %d\n",
1719 sq_thresh->lower_threshold[0]);
Kalle Valobdcd8172011-07-18 00:22:30 +03001720 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1721 (snr <= sq_thresh->lower_threshold[0])) {
1722 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1723 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1724 (snr <= sq_thresh->lower_threshold[1])) {
1725 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1726 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1727 (snr <= sq_thresh->lower_threshold[2])) {
1728 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1729 } else if (snr <= sq_thresh->lower_threshold[3]) {
1730 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1731 }
1732 }
1733
1734 /* Calculate and install the next set of thresholds */
1735 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1736 sq_thresh->lower_threshold_valid_count);
1737 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1738 sq_thresh->upper_threshold_valid_count);
1739
1740 /* Issue a wmi command to install the thresholds */
1741 cmd.thresh_above1_val = upper_snr_threshold;
1742 cmd.thresh_below1_val = lower_snr_threshold;
1743 cmd.weight = sq_thresh->weight;
1744 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1745
1746 ath6kl_dbg(ATH6KL_DBG_WMI,
1747 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1748 snr, new_threshold,
1749 lower_snr_threshold, upper_snr_threshold);
1750
1751 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1752 if (ret) {
1753 ath6kl_err("unable to configure snr threshold\n");
1754 return -EIO;
1755 }
1756
1757 return 0;
1758}
1759
1760static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1761{
1762 u16 ap_info_entry_size;
1763 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1764 struct wmi_ap_info_v1 *ap_info_v1;
1765 u8 index;
1766
1767 if (len < sizeof(struct wmi_aplist_event) ||
1768 ev->ap_list_ver != APLIST_VER1)
1769 return -EINVAL;
1770
1771 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1772 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1773
1774 ath6kl_dbg(ATH6KL_DBG_WMI,
1775 "number of APs in aplist event: %d\n", ev->num_ap);
1776
1777 if (len < (int) (sizeof(struct wmi_aplist_event) +
1778 (ev->num_ap - 1) * ap_info_entry_size))
1779 return -EINVAL;
1780
1781 /* AP list version 1 contents */
1782 for (index = 0; index < ev->num_ap; index++) {
1783 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1784 index, ap_info_v1->bssid, ap_info_v1->channel);
1785 ap_info_v1++;
1786 }
1787
1788 return 0;
1789}
1790
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301791int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
Kalle Valobdcd8172011-07-18 00:22:30 +03001792 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1793{
1794 struct wmi_cmd_hdr *cmd_hdr;
1795 enum htc_endpoint_id ep_id = wmi->ep_id;
1796 int ret;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301797 u16 info1;
Kalle Valobdcd8172011-07-18 00:22:30 +03001798
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05301799 if (WARN_ON(skb == NULL ||
1800 (if_idx > (wmi->parent_dev->vif_max - 1)))) {
1801 dev_kfree_skb(skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03001802 return -EINVAL;
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05301803 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001804
Kalle Valob9b6ee62011-09-27 14:31:21 +03001805 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
1806 cmd_id, skb->len, sync_flag);
1807 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
1808 skb->data, skb->len);
1809
Kalle Valobdcd8172011-07-18 00:22:30 +03001810 if (sync_flag >= END_WMIFLAG) {
1811 dev_kfree_skb(skb);
1812 return -EINVAL;
1813 }
1814
1815 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1816 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1817 /*
1818 * Make sure all data currently queued is transmitted before
1819 * the cmd execution. Establish a new sync point.
1820 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301821 ath6kl_wmi_sync_point(wmi, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001822 }
1823
1824 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1825
1826 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1827 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301828 info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
1829 cmd_hdr->info1 = cpu_to_le16(info1);
Kalle Valobdcd8172011-07-18 00:22:30 +03001830
1831 /* Only for OPT_TX_CMD, use BE endpoint. */
1832 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1833 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05301834 false, false, 0, NULL, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001835 if (ret) {
1836 dev_kfree_skb(skb);
1837 return ret;
1838 }
1839 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1840 }
1841
1842 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1843
1844 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1845 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1846 /*
1847 * Make sure all new data queued waits for the command to
1848 * execute. Establish a new sync point.
1849 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301850 ath6kl_wmi_sync_point(wmi, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001851 }
1852
1853 return 0;
1854}
1855
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301856int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
1857 enum network_type nw_type,
Kalle Valobdcd8172011-07-18 00:22:30 +03001858 enum dot11_auth_mode dot11_auth_mode,
1859 enum auth_mode auth_mode,
1860 enum crypto_type pairwise_crypto,
1861 u8 pairwise_crypto_len,
1862 enum crypto_type group_crypto,
1863 u8 group_crypto_len, int ssid_len, u8 *ssid,
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001864 u8 *bssid, u16 channel, u32 ctrl_flags,
1865 u8 nw_subtype)
Kalle Valobdcd8172011-07-18 00:22:30 +03001866{
1867 struct sk_buff *skb;
1868 struct wmi_connect_cmd *cc;
1869 int ret;
1870
Kalle Valob9b6ee62011-09-27 14:31:21 +03001871 ath6kl_dbg(ATH6KL_DBG_WMI,
1872 "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
1873 "type %d dot11_auth %d auth %d pairwise %d group %d\n",
1874 bssid, channel, ctrl_flags, ssid_len, nw_type,
1875 dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
1876 ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
1877
Kalle Valobdcd8172011-07-18 00:22:30 +03001878 wmi->traffic_class = 100;
1879
1880 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1881 return -EINVAL;
1882
1883 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1884 return -EINVAL;
1885
1886 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1887 if (!skb)
1888 return -ENOMEM;
1889
1890 cc = (struct wmi_connect_cmd *) skb->data;
1891
1892 if (ssid_len)
1893 memcpy(cc->ssid, ssid, ssid_len);
1894
1895 cc->ssid_len = ssid_len;
1896 cc->nw_type = nw_type;
1897 cc->dot11_auth_mode = dot11_auth_mode;
1898 cc->auth_mode = auth_mode;
1899 cc->prwise_crypto_type = pairwise_crypto;
1900 cc->prwise_crypto_len = pairwise_crypto_len;
1901 cc->grp_crypto_type = group_crypto;
1902 cc->grp_crypto_len = group_crypto_len;
1903 cc->ch = cpu_to_le16(channel);
1904 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001905 cc->nw_subtype = nw_subtype;
Kalle Valobdcd8172011-07-18 00:22:30 +03001906
1907 if (bssid != NULL)
1908 memcpy(cc->bssid, bssid, ETH_ALEN);
1909
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301910 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
1911 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03001912
1913 return ret;
1914}
1915
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301916int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
1917 u16 channel)
Kalle Valobdcd8172011-07-18 00:22:30 +03001918{
1919 struct sk_buff *skb;
1920 struct wmi_reconnect_cmd *cc;
1921 int ret;
1922
Kalle Valob9b6ee62011-09-27 14:31:21 +03001923 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
1924 bssid, channel);
1925
Kalle Valobdcd8172011-07-18 00:22:30 +03001926 wmi->traffic_class = 100;
1927
1928 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1929 if (!skb)
1930 return -ENOMEM;
1931
1932 cc = (struct wmi_reconnect_cmd *) skb->data;
1933 cc->channel = cpu_to_le16(channel);
1934
1935 if (bssid != NULL)
1936 memcpy(cc->bssid, bssid, ETH_ALEN);
1937
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301938 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001939 NO_SYNC_WMIFLAG);
1940
1941 return ret;
1942}
1943
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301944int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03001945{
1946 int ret;
1947
Kalle Valob9b6ee62011-09-27 14:31:21 +03001948 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
1949
Kalle Valobdcd8172011-07-18 00:22:30 +03001950 wmi->traffic_class = 100;
1951
1952 /* Disconnect command does not need to do a SYNC before. */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301953 ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03001954
1955 return ret;
1956}
1957
Kalle Valoc8c72b72012-07-19 16:00:40 +03001958/* ath6kl_wmi_start_scan_cmd is to be deprecated. Use
1959 * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P
1960 * mgmt operations using station interface.
1961 */
Kalle Valo11f0bfc2012-07-19 16:00:48 +03001962static int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
1963 enum wmi_scan_type scan_type,
1964 u32 force_fgscan, u32 is_legacy,
1965 u32 home_dwell_time,
1966 u32 force_scan_interval,
1967 s8 num_chan, u16 *ch_list)
Kalle Valoc8c72b72012-07-19 16:00:40 +03001968{
1969 struct sk_buff *skb;
1970 struct wmi_start_scan_cmd *sc;
1971 s8 size;
1972 int i, ret;
1973
1974 size = sizeof(struct wmi_start_scan_cmd);
1975
1976 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1977 return -EINVAL;
1978
1979 if (num_chan > WMI_MAX_CHANNELS)
1980 return -EINVAL;
1981
1982 if (num_chan)
1983 size += sizeof(u16) * (num_chan - 1);
1984
1985 skb = ath6kl_wmi_get_new_buf(size);
1986 if (!skb)
1987 return -ENOMEM;
1988
1989 sc = (struct wmi_start_scan_cmd *) skb->data;
1990 sc->scan_type = scan_type;
1991 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1992 sc->is_legacy = cpu_to_le32(is_legacy);
1993 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1994 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1995 sc->num_ch = num_chan;
1996
1997 for (i = 0; i < num_chan; i++)
1998 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
1999
2000 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
2001 NO_SYNC_WMIFLAG);
2002
2003 return ret;
2004}
2005
Kalle Valo11f0bfc2012-07-19 16:00:48 +03002006/*
2007 * beginscan supports (compared to old startscan) P2P mgmt operations using
2008 * station interface, send additional information like supported rates to
2009 * advertise and xmit rates for probe requests
2010 */
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002011int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx,
2012 enum wmi_scan_type scan_type,
2013 u32 force_fgscan, u32 is_legacy,
2014 u32 home_dwell_time, u32 force_scan_interval,
2015 s8 num_chan, u16 *ch_list, u32 no_cck, u32 *rates)
2016{
Thomas Pedersen03e20842012-04-24 12:50:41 -07002017 struct ieee80211_supported_band *sband;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002018 struct sk_buff *skb;
2019 struct wmi_begin_scan_cmd *sc;
Thomas Pedersen03e20842012-04-24 12:50:41 -07002020 s8 size, *supp_rates;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002021 int i, band, ret;
2022 struct ath6kl *ar = wmi->parent_dev;
2023 int num_rates;
Thomas Pedersen03e20842012-04-24 12:50:41 -07002024 u32 ratemask;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002025
Kalle Valo11f0bfc2012-07-19 16:00:48 +03002026 if (!test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
2027 ar->fw_capabilities)) {
2028 return ath6kl_wmi_startscan_cmd(wmi, if_idx,
2029 scan_type, force_fgscan,
2030 is_legacy, home_dwell_time,
2031 force_scan_interval,
2032 num_chan, ch_list);
2033 }
2034
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002035 size = sizeof(struct wmi_begin_scan_cmd);
2036
2037 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
2038 return -EINVAL;
2039
2040 if (num_chan > WMI_MAX_CHANNELS)
2041 return -EINVAL;
2042
2043 if (num_chan)
2044 size += sizeof(u16) * (num_chan - 1);
2045
2046 skb = ath6kl_wmi_get_new_buf(size);
2047 if (!skb)
2048 return -ENOMEM;
2049
2050 sc = (struct wmi_begin_scan_cmd *) skb->data;
2051 sc->scan_type = scan_type;
2052 sc->force_fg_scan = cpu_to_le32(force_fgscan);
2053 sc->is_legacy = cpu_to_le32(is_legacy);
2054 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
2055 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
2056 sc->no_cck = cpu_to_le32(no_cck);
2057 sc->num_ch = num_chan;
2058
Johannes Berg57fbcce2016-04-12 15:56:15 +02002059 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Thomas Pedersen03e20842012-04-24 12:50:41 -07002060 sband = ar->wiphy->bands[band];
2061
2062 if (!sband)
2063 continue;
2064
Kalle Valo99089ab2013-03-10 07:51:29 +02002065 if (WARN_ON(band >= ATH6KL_NUM_BANDS))
2066 break;
2067
Thomas Pedersen03e20842012-04-24 12:50:41 -07002068 ratemask = rates[band];
2069 supp_rates = sc->supp_rates[band].rates;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002070 num_rates = 0;
2071
2072 for (i = 0; i < sband->n_bitrates; i++) {
2073 if ((BIT(i) & ratemask) == 0)
2074 continue; /* skip rate */
2075 supp_rates[num_rates++] =
2076 (u8) (sband->bitrates[i].bitrate / 5);
2077 }
2078 sc->supp_rates[band].nrates = num_rates;
2079 }
2080
2081 for (i = 0; i < num_chan; i++)
2082 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
2083
2084 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID,
2085 NO_SYNC_WMIFLAG);
2086
2087 return ret;
2088}
2089
Thomas Pedersenb1f47e32012-08-15 16:51:24 -07002090int ath6kl_wmi_enable_sched_scan_cmd(struct wmi *wmi, u8 if_idx, bool enable)
2091{
2092 struct sk_buff *skb;
2093 struct wmi_enable_sched_scan_cmd *sc;
2094 int ret;
2095
2096 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
2097 if (!skb)
2098 return -ENOMEM;
2099
2100 ath6kl_dbg(ATH6KL_DBG_WMI, "%s scheduled scan on vif %d\n",
2101 enable ? "enabling" : "disabling", if_idx);
2102 sc = (struct wmi_enable_sched_scan_cmd *) skb->data;
2103 sc->enable = enable ? 1 : 0;
2104
2105 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2106 WMI_ENABLE_SCHED_SCAN_CMDID,
2107 NO_SYNC_WMIFLAG);
2108 return ret;
2109}
2110
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302111int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
2112 u16 fg_start_sec,
Kalle Valobdcd8172011-07-18 00:22:30 +03002113 u16 fg_end_sec, u16 bg_sec,
2114 u16 minact_chdw_msec, u16 maxact_chdw_msec,
2115 u16 pas_chdw_msec, u8 short_scan_ratio,
2116 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
2117 u16 maxact_scan_per_ssid)
2118{
2119 struct sk_buff *skb;
2120 struct wmi_scan_params_cmd *sc;
2121 int ret;
2122
2123 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
2124 if (!skb)
2125 return -ENOMEM;
2126
2127 sc = (struct wmi_scan_params_cmd *) skb->data;
2128 sc->fg_start_period = cpu_to_le16(fg_start_sec);
2129 sc->fg_end_period = cpu_to_le16(fg_end_sec);
2130 sc->bg_period = cpu_to_le16(bg_sec);
2131 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
2132 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
2133 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
2134 sc->short_scan_ratio = short_scan_ratio;
2135 sc->scan_ctrl_flags = scan_ctrl_flag;
2136 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
2137 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
2138
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302139 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002140 NO_SYNC_WMIFLAG);
2141 return ret;
2142}
2143
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302144int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
Kalle Valobdcd8172011-07-18 00:22:30 +03002145{
2146 struct sk_buff *skb;
2147 struct wmi_bss_filter_cmd *cmd;
2148 int ret;
2149
2150 if (filter >= LAST_BSS_FILTER)
2151 return -EINVAL;
2152
2153 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2154 if (!skb)
2155 return -ENOMEM;
2156
2157 cmd = (struct wmi_bss_filter_cmd *) skb->data;
2158 cmd->bss_filter = filter;
2159 cmd->ie_mask = cpu_to_le32(ie_mask);
2160
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302161 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002162 NO_SYNC_WMIFLAG);
2163 return ret;
2164}
2165
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302166int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
Kalle Valobdcd8172011-07-18 00:22:30 +03002167 u8 ssid_len, u8 *ssid)
2168{
2169 struct sk_buff *skb;
2170 struct wmi_probed_ssid_cmd *cmd;
2171 int ret;
2172
Jouni Malinen8ab54152012-05-09 22:14:51 +03002173 if (index >= MAX_PROBED_SSIDS)
Kalle Valobdcd8172011-07-18 00:22:30 +03002174 return -EINVAL;
2175
2176 if (ssid_len > sizeof(cmd->ssid))
2177 return -EINVAL;
2178
2179 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
2180 return -EINVAL;
2181
2182 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
2183 return -EINVAL;
2184
2185 if (flag & SPECIFIC_SSID_FLAG)
2186 wmi->is_probe_ssid = true;
2187
2188 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2189 if (!skb)
2190 return -ENOMEM;
2191
2192 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
2193 cmd->entry_index = index;
2194 cmd->flag = flag;
2195 cmd->ssid_len = ssid_len;
2196 memcpy(cmd->ssid, ssid, ssid_len);
2197
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302198 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002199 NO_SYNC_WMIFLAG);
2200 return ret;
2201}
2202
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302203int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
2204 u16 listen_interval,
Kalle Valobdcd8172011-07-18 00:22:30 +03002205 u16 listen_beacons)
2206{
2207 struct sk_buff *skb;
2208 struct wmi_listen_int_cmd *cmd;
2209 int ret;
2210
2211 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2212 if (!skb)
2213 return -ENOMEM;
2214
2215 cmd = (struct wmi_listen_int_cmd *) skb->data;
2216 cmd->listen_intvl = cpu_to_le16(listen_interval);
2217 cmd->num_beacons = cpu_to_le16(listen_beacons);
2218
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302219 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002220 NO_SYNC_WMIFLAG);
2221 return ret;
2222}
2223
Raja Manice0dc0c2012-02-20 19:08:08 +05302224int ath6kl_wmi_bmisstime_cmd(struct wmi *wmi, u8 if_idx,
2225 u16 bmiss_time, u16 num_beacons)
2226{
2227 struct sk_buff *skb;
2228 struct wmi_bmiss_time_cmd *cmd;
2229 int ret;
2230
2231 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2232 if (!skb)
2233 return -ENOMEM;
2234
2235 cmd = (struct wmi_bmiss_time_cmd *) skb->data;
2236 cmd->bmiss_time = cpu_to_le16(bmiss_time);
2237 cmd->num_beacons = cpu_to_le16(num_beacons);
2238
2239 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BMISS_TIME_CMDID,
2240 NO_SYNC_WMIFLAG);
2241 return ret;
2242}
2243
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302244int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
Kalle Valobdcd8172011-07-18 00:22:30 +03002245{
2246 struct sk_buff *skb;
2247 struct wmi_power_mode_cmd *cmd;
2248 int ret;
2249
2250 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2251 if (!skb)
2252 return -ENOMEM;
2253
2254 cmd = (struct wmi_power_mode_cmd *) skb->data;
2255 cmd->pwr_mode = pwr_mode;
2256 wmi->pwr_mode = pwr_mode;
2257
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302258 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002259 NO_SYNC_WMIFLAG);
2260 return ret;
2261}
2262
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302263int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
Kalle Valobdcd8172011-07-18 00:22:30 +03002264 u16 ps_poll_num, u16 dtim_policy,
2265 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
2266 u16 ps_fail_event_policy)
2267{
2268 struct sk_buff *skb;
2269 struct wmi_power_params_cmd *pm;
2270 int ret;
2271
2272 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
2273 if (!skb)
2274 return -ENOMEM;
2275
2276 pm = (struct wmi_power_params_cmd *)skb->data;
2277 pm->idle_period = cpu_to_le16(idle_period);
2278 pm->pspoll_number = cpu_to_le16(ps_poll_num);
2279 pm->dtim_policy = cpu_to_le16(dtim_policy);
2280 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
2281 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
2282 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
2283
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302284 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002285 NO_SYNC_WMIFLAG);
2286 return ret;
2287}
2288
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302289int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
Kalle Valobdcd8172011-07-18 00:22:30 +03002290{
2291 struct sk_buff *skb;
2292 struct wmi_disc_timeout_cmd *cmd;
2293 int ret;
2294
2295 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2296 if (!skb)
2297 return -ENOMEM;
2298
2299 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
2300 cmd->discon_timeout = timeout;
2301
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302302 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002303 NO_SYNC_WMIFLAG);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302304
Jouni Malinenff0b0072011-10-11 17:31:56 +03002305 if (ret == 0)
2306 ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302307
Kalle Valobdcd8172011-07-18 00:22:30 +03002308 return ret;
2309}
2310
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302311int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
Kalle Valobdcd8172011-07-18 00:22:30 +03002312 enum crypto_type key_type,
2313 u8 key_usage, u8 key_len,
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002314 u8 *key_rsc, unsigned int key_rsc_len,
2315 u8 *key_material,
Kalle Valobdcd8172011-07-18 00:22:30 +03002316 u8 key_op_ctrl, u8 *mac_addr,
2317 enum wmi_sync_flag sync_flag)
2318{
2319 struct sk_buff *skb;
2320 struct wmi_add_cipher_key_cmd *cmd;
2321 int ret;
2322
Kalle Valocdeb8602012-04-12 11:02:18 +03002323 ath6kl_dbg(ATH6KL_DBG_WMI,
2324 "addkey cmd: key_index=%u key_type=%d key_usage=%d key_len=%d key_op_ctrl=%d\n",
Jouni Malinen9a5b1312011-08-30 21:57:52 +03002325 key_index, key_type, key_usage, key_len, key_op_ctrl);
2326
Kalle Valobdcd8172011-07-18 00:22:30 +03002327 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002328 (key_material == NULL) || key_rsc_len > 8)
Kalle Valobdcd8172011-07-18 00:22:30 +03002329 return -EINVAL;
2330
2331 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
2332 return -EINVAL;
2333
2334 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2335 if (!skb)
2336 return -ENOMEM;
2337
2338 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
2339 cmd->key_index = key_index;
2340 cmd->key_type = key_type;
2341 cmd->key_usage = key_usage;
2342 cmd->key_len = key_len;
2343 memcpy(cmd->key, key_material, key_len);
2344
2345 if (key_rsc != NULL)
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002346 memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002347
2348 cmd->key_op_ctrl = key_op_ctrl;
2349
2350 if (mac_addr)
2351 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
2352
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302353 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002354 sync_flag);
2355
2356 return ret;
2357}
2358
Johannes Bergc1e5f472014-05-19 17:53:16 +02002359int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, const u8 *krk)
Kalle Valobdcd8172011-07-18 00:22:30 +03002360{
2361 struct sk_buff *skb;
2362 struct wmi_add_krk_cmd *cmd;
2363 int ret;
2364
2365 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2366 if (!skb)
2367 return -ENOMEM;
2368
2369 cmd = (struct wmi_add_krk_cmd *) skb->data;
2370 memcpy(cmd->krk, krk, WMI_KRK_LEN);
2371
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302372 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302373 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002374
2375 return ret;
2376}
2377
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302378int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
Kalle Valobdcd8172011-07-18 00:22:30 +03002379{
2380 struct sk_buff *skb;
2381 struct wmi_delete_cipher_key_cmd *cmd;
2382 int ret;
2383
2384 if (key_index > WMI_MAX_KEY_INDEX)
2385 return -EINVAL;
2386
2387 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2388 if (!skb)
2389 return -ENOMEM;
2390
2391 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
2392 cmd->key_index = key_index;
2393
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302394 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002395 NO_SYNC_WMIFLAG);
2396
2397 return ret;
2398}
2399
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302400int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03002401 const u8 *pmkid, bool set)
2402{
2403 struct sk_buff *skb;
2404 struct wmi_setpmkid_cmd *cmd;
2405 int ret;
2406
2407 if (bssid == NULL)
2408 return -EINVAL;
2409
2410 if (set && pmkid == NULL)
2411 return -EINVAL;
2412
2413 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2414 if (!skb)
2415 return -ENOMEM;
2416
2417 cmd = (struct wmi_setpmkid_cmd *) skb->data;
2418 memcpy(cmd->bssid, bssid, ETH_ALEN);
2419 if (set) {
2420 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2421 cmd->enable = PMKID_ENABLE;
2422 } else {
2423 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2424 cmd->enable = PMKID_DISABLE;
2425 }
2426
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302427 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002428 NO_SYNC_WMIFLAG);
2429
2430 return ret;
2431}
2432
2433static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302434 enum htc_endpoint_id ep_id, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002435{
2436 struct wmi_data_hdr *data_hdr;
2437 int ret;
2438
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302439 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id)) {
2440 dev_kfree_skb(skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03002441 return -EINVAL;
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302442 }
Kalle Valobdcd8172011-07-18 00:22:30 +03002443
2444 skb_push(skb, sizeof(struct wmi_data_hdr));
2445
2446 data_hdr = (struct wmi_data_hdr *) skb->data;
2447 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302448 data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
Kalle Valobdcd8172011-07-18 00:22:30 +03002449
2450 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2451
2452 return ret;
2453}
2454
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302455static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002456{
2457 struct sk_buff *skb;
2458 struct wmi_sync_cmd *cmd;
2459 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2460 enum htc_endpoint_id ep_id;
2461 u8 index, num_pri_streams = 0;
2462 int ret = 0;
2463
2464 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2465
2466 spin_lock_bh(&wmi->lock);
2467
2468 for (index = 0; index < WMM_NUM_AC; index++) {
2469 if (wmi->fat_pipe_exist & (1 << index)) {
2470 num_pri_streams++;
2471 data_sync_bufs[num_pri_streams - 1].traffic_class =
2472 index;
2473 }
2474 }
2475
2476 spin_unlock_bh(&wmi->lock);
2477
2478 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302479 if (!skb)
2480 return -ENOMEM;
Kalle Valobdcd8172011-07-18 00:22:30 +03002481
2482 cmd = (struct wmi_sync_cmd *) skb->data;
2483
2484 /*
2485 * In the SYNC cmd sent on the control Ep, send a bitmap
2486 * of the data eps on which the Data Sync will be sent
2487 */
2488 cmd->data_sync_map = wmi->fat_pipe_exist;
2489
2490 for (index = 0; index < num_pri_streams; index++) {
2491 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2492 if (data_sync_bufs[index].skb == NULL) {
2493 ret = -ENOMEM;
2494 break;
2495 }
2496 }
2497
2498 /*
2499 * If buffer allocation for any of the dataSync fails,
2500 * then do not send the Synchronize cmd on the control ep
2501 */
2502 if (ret)
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302503 goto free_cmd_skb;
Kalle Valobdcd8172011-07-18 00:22:30 +03002504
2505 /*
2506 * Send sync cmd followed by sync data messages on all
2507 * endpoints being used
2508 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302509 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002510 NO_SYNC_WMIFLAG);
2511
2512 if (ret)
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302513 goto free_data_skb;
Kalle Valobdcd8172011-07-18 00:22:30 +03002514
2515 for (index = 0; index < num_pri_streams; index++) {
Kalle Valobdcd8172011-07-18 00:22:30 +03002516 if (WARN_ON(!data_sync_bufs[index].skb))
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302517 goto free_data_skb;
Kalle Valobdcd8172011-07-18 00:22:30 +03002518
2519 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2520 data_sync_bufs[index].
2521 traffic_class);
2522 ret =
2523 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302524 ep_id, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03002525
Kalle Valobdcd8172011-07-18 00:22:30 +03002526 data_sync_bufs[index].skb = NULL;
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302527
2528 if (ret)
2529 goto free_data_skb;
Kalle Valobdcd8172011-07-18 00:22:30 +03002530 }
2531
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302532 return 0;
2533
2534free_cmd_skb:
Kalle Valobdcd8172011-07-18 00:22:30 +03002535 /* free up any resources left over (possibly due to an error) */
Mohammed Shafi Shajakhane16ccfe2012-11-16 18:22:22 +05302536 dev_kfree_skb(skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03002537
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302538free_data_skb:
Mohammed Shafi Shajakhane16ccfe2012-11-16 18:22:22 +05302539 for (index = 0; index < num_pri_streams; index++)
2540 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03002541
2542 return ret;
2543}
2544
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302545int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
Kalle Valobdcd8172011-07-18 00:22:30 +03002546 struct wmi_create_pstream_cmd *params)
2547{
2548 struct sk_buff *skb;
2549 struct wmi_create_pstream_cmd *cmd;
2550 u8 fatpipe_exist_for_ac = 0;
2551 s32 min_phy = 0;
2552 s32 nominal_phy = 0;
2553 int ret;
2554
Heinrich Schuchardt93b4a092016-05-18 02:24:17 +02002555 if (!((params->user_pri <= 0x7) &&
Kalle Valobdcd8172011-07-18 00:22:30 +03002556 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2557 (params->traffic_direc == UPLINK_TRAFFIC ||
2558 params->traffic_direc == DNLINK_TRAFFIC ||
2559 params->traffic_direc == BIDIR_TRAFFIC) &&
2560 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2561 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2562 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2563 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2564 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2565 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2566 params->tsid <= WMI_MAX_THINSTREAM))) {
2567 return -EINVAL;
2568 }
2569
2570 /*
2571 * Check nominal PHY rate is >= minimalPHY,
2572 * so that DUT can allow TSRS IE
2573 */
2574
2575 /* Get the physical rate (units of bps) */
2576 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2577
2578 /* Check minimal phy < nominal phy rate */
2579 if (params->nominal_phy >= min_phy) {
2580 /* unit of 500 kbps */
2581 nominal_phy = (params->nominal_phy * 1000) / 500;
2582 ath6kl_dbg(ATH6KL_DBG_WMI,
2583 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2584 min_phy, nominal_phy);
2585
2586 params->nominal_phy = nominal_phy;
2587 } else {
2588 params->nominal_phy = 0;
2589 }
2590
2591 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2592 if (!skb)
2593 return -ENOMEM;
2594
2595 ath6kl_dbg(ATH6KL_DBG_WMI,
2596 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2597 params->traffic_class, params->tsid);
2598
2599 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2600 memcpy(cmd, params, sizeof(*cmd));
2601
2602 /* This is an implicitly created Fat pipe */
2603 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2604 spin_lock_bh(&wmi->lock);
2605 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2606 (1 << params->traffic_class));
2607 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2608 spin_unlock_bh(&wmi->lock);
2609 } else {
2610 /* explicitly created thin stream within a fat pipe */
2611 spin_lock_bh(&wmi->lock);
2612 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2613 (1 << params->traffic_class));
2614 wmi->stream_exist_for_ac[params->traffic_class] |=
2615 (1 << params->tsid);
2616 /*
2617 * If a thinstream becomes active, the fat pipe automatically
2618 * becomes active
2619 */
2620 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2621 spin_unlock_bh(&wmi->lock);
2622 }
2623
2624 /*
2625 * Indicate activty change to driver layer only if this is the
2626 * first TSID to get created in this AC explicitly or an implicit
2627 * fat pipe is getting created.
2628 */
2629 if (!fatpipe_exist_for_ac)
2630 ath6kl_indicate_tx_activity(wmi->parent_dev,
2631 params->traffic_class, true);
2632
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302633 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002634 NO_SYNC_WMIFLAG);
2635 return ret;
2636}
2637
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302638int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
2639 u8 tsid)
Kalle Valobdcd8172011-07-18 00:22:30 +03002640{
2641 struct sk_buff *skb;
2642 struct wmi_delete_pstream_cmd *cmd;
2643 u16 active_tsids = 0;
2644 int ret;
2645
Dan Carpenter8e8b0ba2019-04-04 11:56:51 +03002646 if (traffic_class >= WMM_NUM_AC) {
Kalle Valobdcd8172011-07-18 00:22:30 +03002647 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2648 return -EINVAL;
2649 }
2650
2651 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2652 if (!skb)
2653 return -ENOMEM;
2654
2655 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2656 cmd->traffic_class = traffic_class;
2657 cmd->tsid = tsid;
2658
2659 spin_lock_bh(&wmi->lock);
2660 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2661 spin_unlock_bh(&wmi->lock);
2662
2663 if (!(active_tsids & (1 << tsid))) {
2664 dev_kfree_skb(skb);
2665 ath6kl_dbg(ATH6KL_DBG_WMI,
2666 "TSID %d doesn't exist for traffic class: %d\n",
2667 tsid, traffic_class);
2668 return -ENODATA;
2669 }
2670
2671 ath6kl_dbg(ATH6KL_DBG_WMI,
2672 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2673 traffic_class, tsid);
2674
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302675 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002676 SYNC_BEFORE_WMIFLAG);
2677
2678 spin_lock_bh(&wmi->lock);
2679 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2680 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2681 spin_unlock_bh(&wmi->lock);
2682
2683 /*
2684 * Indicate stream inactivity to driver layer only if all tsids
2685 * within this AC are deleted.
2686 */
2687 if (!active_tsids) {
2688 ath6kl_indicate_tx_activity(wmi->parent_dev,
2689 traffic_class, false);
2690 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2691 }
2692
2693 return ret;
2694}
2695
Raja Manica1d16a2011-12-16 14:24:23 +05302696int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, u8 if_idx,
2697 __be32 ips0, __be32 ips1)
Kalle Valobdcd8172011-07-18 00:22:30 +03002698{
2699 struct sk_buff *skb;
2700 struct wmi_set_ip_cmd *cmd;
2701 int ret;
2702
2703 /* Multicast address are not valid */
Raja Manica1d16a2011-12-16 14:24:23 +05302704 if (ipv4_is_multicast(ips0) ||
2705 ipv4_is_multicast(ips1))
Kalle Valobdcd8172011-07-18 00:22:30 +03002706 return -EINVAL;
2707
2708 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2709 if (!skb)
2710 return -ENOMEM;
2711
2712 cmd = (struct wmi_set_ip_cmd *) skb->data;
Raja Manica1d16a2011-12-16 14:24:23 +05302713 cmd->ips[0] = ips0;
2714 cmd->ips[1] = ips1;
Kalle Valobdcd8172011-07-18 00:22:30 +03002715
Raja Manica1d16a2011-12-16 14:24:23 +05302716 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IP_CMDID,
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302717 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002718 return ret;
2719}
2720
Raja Mani45cf1102011-11-07 22:52:45 +02002721static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
2722{
2723 u16 active_tsids;
2724 u8 stream_exist;
2725 int i;
2726
2727 /*
2728 * Relinquish credits from all implicitly created pstreams
2729 * since when we go to sleep. If user created explicit
2730 * thinstreams exists with in a fatpipe leave them intact
2731 * for the user to delete.
2732 */
2733 spin_lock_bh(&wmi->lock);
2734 stream_exist = wmi->fat_pipe_exist;
2735 spin_unlock_bh(&wmi->lock);
2736
2737 for (i = 0; i < WMM_NUM_AC; i++) {
2738 if (stream_exist & (1 << i)) {
Raja Mani45cf1102011-11-07 22:52:45 +02002739 /*
2740 * FIXME: Is this lock & unlock inside
2741 * for loop correct? may need rework.
2742 */
2743 spin_lock_bh(&wmi->lock);
2744 active_tsids = wmi->stream_exist_for_ac[i];
2745 spin_unlock_bh(&wmi->lock);
2746
2747 /*
2748 * If there are no user created thin streams
2749 * delete the fatpipe
2750 */
2751 if (!active_tsids) {
2752 stream_exist &= ~(1 << i);
2753 /*
2754 * Indicate inactivity to driver layer for
2755 * this fatpipe (pstream)
2756 */
2757 ath6kl_indicate_tx_activity(wmi->parent_dev,
2758 i, false);
2759 }
2760 }
2761 }
2762
2763 /* FIXME: Can we do this assignment without locking ? */
2764 spin_lock_bh(&wmi->lock);
2765 wmi->fat_pipe_exist = stream_exist;
2766 spin_unlock_bh(&wmi->lock);
2767}
2768
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302769static int ath6kl_set_bitrate_mask64(struct wmi *wmi, u8 if_idx,
2770 const struct cfg80211_bitrate_mask *mask)
2771{
2772 struct sk_buff *skb;
2773 int ret, mode, band;
Kalle Valof8c03052012-07-12 12:13:12 +03002774 u64 mcsrate, ratemask[ATH6KL_NUM_BANDS];
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302775 struct wmi_set_tx_select_rates64_cmd *cmd;
2776
2777 memset(&ratemask, 0, sizeof(ratemask));
Kalle Valof8c03052012-07-12 12:13:12 +03002778
2779 /* only check 2.4 and 5 GHz bands, skip the rest */
Johannes Berg57fbcce2016-04-12 15:56:15 +02002780 for (band = 0; band <= NL80211_BAND_5GHZ; band++) {
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302781 /* copy legacy rate mask */
2782 ratemask[band] = mask->control[band].legacy;
Johannes Berg57fbcce2016-04-12 15:56:15 +02002783 if (band == NL80211_BAND_5GHZ)
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302784 ratemask[band] =
2785 mask->control[band].legacy << 4;
2786
2787 /* copy mcs rate mask */
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01002788 mcsrate = mask->control[band].ht_mcs[1];
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302789 mcsrate <<= 8;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01002790 mcsrate |= mask->control[band].ht_mcs[0];
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302791 ratemask[band] |= mcsrate << 12;
2792 ratemask[band] |= mcsrate << 28;
2793 }
2794
2795 ath6kl_dbg(ATH6KL_DBG_WMI,
2796 "Ratemask 64 bit: 2.4:%llx 5:%llx\n",
2797 ratemask[0], ratemask[1]);
2798
2799 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
2800 if (!skb)
2801 return -ENOMEM;
2802
2803 cmd = (struct wmi_set_tx_select_rates64_cmd *) skb->data;
2804 for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
2805 /* A mode operate in 5GHZ band */
2806 if (mode == WMI_RATES_MODE_11A ||
2807 mode == WMI_RATES_MODE_11A_HT20 ||
2808 mode == WMI_RATES_MODE_11A_HT40)
Johannes Berg57fbcce2016-04-12 15:56:15 +02002809 band = NL80211_BAND_5GHZ;
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302810 else
Johannes Berg57fbcce2016-04-12 15:56:15 +02002811 band = NL80211_BAND_2GHZ;
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302812 cmd->ratemask[mode] = cpu_to_le64(ratemask[band]);
2813 }
2814
2815 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2816 WMI_SET_TX_SELECT_RATES_CMDID,
2817 NO_SYNC_WMIFLAG);
2818 return ret;
2819}
2820
2821static int ath6kl_set_bitrate_mask32(struct wmi *wmi, u8 if_idx,
2822 const struct cfg80211_bitrate_mask *mask)
2823{
2824 struct sk_buff *skb;
2825 int ret, mode, band;
Kalle Valof8c03052012-07-12 12:13:12 +03002826 u32 mcsrate, ratemask[ATH6KL_NUM_BANDS];
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302827 struct wmi_set_tx_select_rates32_cmd *cmd;
2828
2829 memset(&ratemask, 0, sizeof(ratemask));
Kalle Valof8c03052012-07-12 12:13:12 +03002830
2831 /* only check 2.4 and 5 GHz bands, skip the rest */
Johannes Berg57fbcce2016-04-12 15:56:15 +02002832 for (band = 0; band <= NL80211_BAND_5GHZ; band++) {
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302833 /* copy legacy rate mask */
2834 ratemask[band] = mask->control[band].legacy;
Johannes Berg57fbcce2016-04-12 15:56:15 +02002835 if (band == NL80211_BAND_5GHZ)
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302836 ratemask[band] =
2837 mask->control[band].legacy << 4;
2838
2839 /* copy mcs rate mask */
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01002840 mcsrate = mask->control[band].ht_mcs[0];
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302841 ratemask[band] |= mcsrate << 12;
2842 ratemask[band] |= mcsrate << 20;
2843 }
2844
2845 ath6kl_dbg(ATH6KL_DBG_WMI,
2846 "Ratemask 32 bit: 2.4:%x 5:%x\n",
2847 ratemask[0], ratemask[1]);
2848
2849 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
2850 if (!skb)
2851 return -ENOMEM;
2852
2853 cmd = (struct wmi_set_tx_select_rates32_cmd *) skb->data;
2854 for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
2855 /* A mode operate in 5GHZ band */
2856 if (mode == WMI_RATES_MODE_11A ||
2857 mode == WMI_RATES_MODE_11A_HT20 ||
2858 mode == WMI_RATES_MODE_11A_HT40)
Johannes Berg57fbcce2016-04-12 15:56:15 +02002859 band = NL80211_BAND_5GHZ;
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302860 else
Johannes Berg57fbcce2016-04-12 15:56:15 +02002861 band = NL80211_BAND_2GHZ;
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302862 cmd->ratemask[mode] = cpu_to_le32(ratemask[band]);
2863 }
2864
2865 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2866 WMI_SET_TX_SELECT_RATES_CMDID,
2867 NO_SYNC_WMIFLAG);
2868 return ret;
2869}
2870
2871int ath6kl_wmi_set_bitrate_mask(struct wmi *wmi, u8 if_idx,
2872 const struct cfg80211_bitrate_mask *mask)
2873{
2874 struct ath6kl *ar = wmi->parent_dev;
2875
Kalle Valoeba95bc2014-06-17 12:40:52 +03002876 if (test_bit(ATH6KL_FW_CAPABILITY_64BIT_RATES,
2877 ar->fw_capabilities))
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302878 return ath6kl_set_bitrate_mask64(wmi, if_idx, mask);
2879 else
2880 return ath6kl_set_bitrate_mask32(wmi, if_idx, mask);
2881}
2882
Raja Mani45cf1102011-11-07 22:52:45 +02002883int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
2884 enum ath6kl_host_mode host_mode)
2885{
2886 struct sk_buff *skb;
2887 struct wmi_set_host_sleep_mode_cmd *cmd;
2888 int ret;
2889
2890 if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
2891 (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
2892 ath6kl_err("invalid host sleep mode: %d\n", host_mode);
2893 return -EINVAL;
2894 }
2895
2896 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2897 if (!skb)
2898 return -ENOMEM;
2899
2900 cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
2901
2902 if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
2903 ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
2904 cmd->asleep = cpu_to_le32(1);
Kalle Valoa5d8f9d2014-03-11 12:58:01 +02002905 } else {
Raja Mani45cf1102011-11-07 22:52:45 +02002906 cmd->awake = cpu_to_le32(1);
Kalle Valoa5d8f9d2014-03-11 12:58:01 +02002907 }
Raja Mani45cf1102011-11-07 22:52:45 +02002908
2909 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2910 WMI_SET_HOST_SLEEP_MODE_CMDID,
2911 NO_SYNC_WMIFLAG);
2912 return ret;
2913}
2914
Raja Mani081c7a82012-01-30 17:13:11 +05302915/* This command has zero length payload */
2916static int ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(struct wmi *wmi,
2917 struct ath6kl_vif *vif)
2918{
2919 struct ath6kl *ar = wmi->parent_dev;
2920
2921 set_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
2922 wake_up(&ar->event_wq);
2923
2924 return 0;
2925}
2926
Raja Mani45cf1102011-11-07 22:52:45 +02002927int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
2928 enum ath6kl_wow_mode wow_mode,
2929 u32 filter, u16 host_req_delay)
2930{
2931 struct sk_buff *skb;
2932 struct wmi_set_wow_mode_cmd *cmd;
2933 int ret;
2934
2935 if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
Kalle Valo96f1fad2012-03-07 20:03:57 +02002936 wow_mode != ATH6KL_WOW_MODE_DISABLE) {
Raja Mani45cf1102011-11-07 22:52:45 +02002937 ath6kl_err("invalid wow mode: %d\n", wow_mode);
2938 return -EINVAL;
2939 }
2940
2941 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2942 if (!skb)
2943 return -ENOMEM;
2944
2945 cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
2946 cmd->enable_wow = cpu_to_le32(wow_mode);
2947 cmd->filter = cpu_to_le32(filter);
2948 cmd->host_req_delay = cpu_to_le16(host_req_delay);
2949
2950 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
2951 NO_SYNC_WMIFLAG);
2952 return ret;
2953}
2954
Raja Mani5c9b4fa2011-11-07 22:52:45 +02002955int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2956 u8 list_id, u8 filter_size,
Raja Manid91e8ee2012-01-30 17:13:10 +05302957 u8 filter_offset, const u8 *filter,
2958 const u8 *mask)
Raja Mani5c9b4fa2011-11-07 22:52:45 +02002959{
2960 struct sk_buff *skb;
2961 struct wmi_add_wow_pattern_cmd *cmd;
2962 u16 size;
2963 u8 *filter_mask;
2964 int ret;
2965
2966 /*
2967 * Allocate additional memory in the buffer to hold
2968 * filter and mask value, which is twice of filter_size.
2969 */
2970 size = sizeof(*cmd) + (2 * filter_size);
2971
2972 skb = ath6kl_wmi_get_new_buf(size);
2973 if (!skb)
2974 return -ENOMEM;
2975
2976 cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
2977 cmd->filter_list_id = list_id;
2978 cmd->filter_size = filter_size;
2979 cmd->filter_offset = filter_offset;
2980
2981 memcpy(cmd->filter, filter, filter_size);
2982
2983 filter_mask = (u8 *) (cmd->filter + filter_size);
2984 memcpy(filter_mask, mask, filter_size);
2985
2986 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
2987 NO_SYNC_WMIFLAG);
2988
2989 return ret;
2990}
2991
2992int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2993 u16 list_id, u16 filter_id)
2994{
2995 struct sk_buff *skb;
2996 struct wmi_del_wow_pattern_cmd *cmd;
2997 int ret;
2998
2999 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3000 if (!skb)
3001 return -ENOMEM;
3002
3003 cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
3004 cmd->filter_list_id = cpu_to_le16(list_id);
3005 cmd->filter_id = cpu_to_le16(filter_id);
3006
3007 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
3008 NO_SYNC_WMIFLAG);
3009 return ret;
3010}
3011
Kalle Valobdcd8172011-07-18 00:22:30 +03003012static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
3013 enum wmix_command_id cmd_id,
3014 enum wmi_sync_flag sync_flag)
3015{
3016 struct wmix_cmd_hdr *cmd_hdr;
3017 int ret;
3018
3019 skb_push(skb, sizeof(struct wmix_cmd_hdr));
3020
3021 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
3022 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
3023
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303024 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
Kalle Valobdcd8172011-07-18 00:22:30 +03003025
3026 return ret;
3027}
3028
3029int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
3030{
3031 struct sk_buff *skb;
3032 struct wmix_hb_challenge_resp_cmd *cmd;
3033 int ret;
3034
3035 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3036 if (!skb)
3037 return -ENOMEM;
3038
3039 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
3040 cmd->cookie = cpu_to_le32(cookie);
3041 cmd->source = cpu_to_le32(source);
3042
3043 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
3044 NO_SYNC_WMIFLAG);
3045 return ret;
3046}
3047
Kalle Valo939f1cc2011-09-02 10:32:04 +03003048int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
3049{
3050 struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
3051 struct sk_buff *skb;
3052 int ret;
3053
3054 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3055 if (!skb)
3056 return -ENOMEM;
3057
3058 cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
3059 cmd->valid = cpu_to_le32(valid);
3060 cmd->config = cpu_to_le32(config);
3061
3062 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
3063 NO_SYNC_WMIFLAG);
3064 return ret;
3065}
3066
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303067int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03003068{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303069 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03003070}
3071
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05303072int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
Kalle Valobdcd8172011-07-18 00:22:30 +03003073{
3074 struct sk_buff *skb;
3075 struct wmi_set_tx_pwr_cmd *cmd;
3076 int ret;
3077
3078 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
3079 if (!skb)
3080 return -ENOMEM;
3081
3082 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
3083 cmd->dbM = dbM;
3084
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05303085 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003086 NO_SYNC_WMIFLAG);
3087
3088 return ret;
3089}
3090
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05303091int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03003092{
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05303093 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03003094}
3095
Jouni Malinen4b28a802011-10-11 17:31:54 +03003096int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
3097{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303098 return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
Jouni Malinen4b28a802011-10-11 17:31:54 +03003099}
3100
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303101int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
3102 u8 preamble_policy)
Kalle Valobdcd8172011-07-18 00:22:30 +03003103{
3104 struct sk_buff *skb;
3105 struct wmi_set_lpreamble_cmd *cmd;
3106 int ret;
3107
3108 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
3109 if (!skb)
3110 return -ENOMEM;
3111
3112 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
3113 cmd->status = status;
3114 cmd->preamble_policy = preamble_policy;
3115
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303116 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003117 NO_SYNC_WMIFLAG);
3118 return ret;
3119}
3120
3121int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
3122{
3123 struct sk_buff *skb;
3124 struct wmi_set_rts_cmd *cmd;
3125 int ret;
3126
3127 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
3128 if (!skb)
3129 return -ENOMEM;
3130
3131 cmd = (struct wmi_set_rts_cmd *) skb->data;
3132 cmd->threshold = cpu_to_le16(threshold);
3133
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303134 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
3135 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03003136 return ret;
3137}
3138
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303139int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
Kalle Valobdcd8172011-07-18 00:22:30 +03003140{
3141 struct sk_buff *skb;
3142 struct wmi_set_wmm_txop_cmd *cmd;
3143 int ret;
3144
3145 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
3146 return -EINVAL;
3147
3148 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
3149 if (!skb)
3150 return -ENOMEM;
3151
3152 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
3153 cmd->txop_enable = cfg;
3154
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303155 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003156 NO_SYNC_WMIFLAG);
3157 return ret;
3158}
3159
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303160int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
3161 u8 keep_alive_intvl)
Kalle Valobdcd8172011-07-18 00:22:30 +03003162{
3163 struct sk_buff *skb;
3164 struct wmi_set_keepalive_cmd *cmd;
3165 int ret;
3166
3167 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3168 if (!skb)
3169 return -ENOMEM;
3170
3171 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
3172 cmd->keep_alive_intvl = keep_alive_intvl;
Kalle Valobdcd8172011-07-18 00:22:30 +03003173
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303174 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003175 NO_SYNC_WMIFLAG);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303176
Jouni Malinenff0b0072011-10-11 17:31:56 +03003177 if (ret == 0)
3178 ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303179
Kalle Valobdcd8172011-07-18 00:22:30 +03003180 return ret;
3181}
3182
Vasanthakumar Thiagarajandf90b362012-04-09 19:03:58 +05303183int ath6kl_wmi_set_htcap_cmd(struct wmi *wmi, u8 if_idx,
Johannes Berg57fbcce2016-04-12 15:56:15 +02003184 enum nl80211_band band,
Vasanthakumar Thiagarajandf90b362012-04-09 19:03:58 +05303185 struct ath6kl_htcap *htcap)
3186{
3187 struct sk_buff *skb;
3188 struct wmi_set_htcap_cmd *cmd;
3189
3190 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3191 if (!skb)
3192 return -ENOMEM;
3193
3194 cmd = (struct wmi_set_htcap_cmd *) skb->data;
3195
3196 /*
Johannes Berg57fbcce2016-04-12 15:56:15 +02003197 * NOTE: Band in firmware matches enum nl80211_band, it is unlikely
Vasanthakumar Thiagarajandf90b362012-04-09 19:03:58 +05303198 * this will be changed in firmware. If at all there is any change in
3199 * band value, the host needs to be fixed.
3200 */
3201 cmd->band = band;
3202 cmd->ht_enable = !!htcap->ht_enable;
3203 cmd->ht20_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_20);
3204 cmd->ht40_supported =
3205 !!(htcap->cap_info & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
3206 cmd->ht40_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_40);
3207 cmd->intolerant_40mhz =
3208 !!(htcap->cap_info & IEEE80211_HT_CAP_40MHZ_INTOLERANT);
3209 cmd->max_ampdu_len_exp = htcap->ampdu_factor;
3210
3211 ath6kl_dbg(ATH6KL_DBG_WMI,
3212 "Set htcap: band:%d ht_enable:%d 40mhz:%d sgi_20mhz:%d sgi_40mhz:%d 40mhz_intolerant:%d ampdu_len_exp:%d\n",
3213 cmd->band, cmd->ht_enable, cmd->ht40_supported,
3214 cmd->ht20_sgi, cmd->ht40_sgi, cmd->intolerant_40mhz,
3215 cmd->max_ampdu_len_exp);
3216 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_HT_CAP_CMDID,
3217 NO_SYNC_WMIFLAG);
3218}
3219
Kalle Valo003353b0d2011-09-01 10:14:21 +03003220int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
3221{
3222 struct sk_buff *skb;
3223 int ret;
3224
3225 skb = ath6kl_wmi_get_new_buf(len);
3226 if (!skb)
3227 return -ENOMEM;
3228
3229 memcpy(skb->data, buf, len);
3230
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303231 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
Kalle Valo003353b0d2011-09-01 10:14:21 +03003232
3233 return ret;
3234}
3235
Vasanthakumar Thiagarajan3f3c4ee2012-01-03 14:41:59 +05303236int ath6kl_wmi_mcast_filter_cmd(struct wmi *wmi, u8 if_idx, bool mc_all_on)
3237{
3238 struct sk_buff *skb;
3239 struct wmi_mcast_filter_cmd *cmd;
3240 int ret;
3241
3242 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3243 if (!skb)
3244 return -ENOMEM;
3245
3246 cmd = (struct wmi_mcast_filter_cmd *) skb->data;
3247 cmd->mcast_all_enable = mc_all_on;
3248
3249 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_MCAST_FILTER_CMDID,
3250 NO_SYNC_WMIFLAG);
3251 return ret;
3252}
Kalle Valo003353b0d2011-09-01 10:14:21 +03003253
Vasanthakumar Thiagarajanf914edd2012-01-03 14:42:00 +05303254int ath6kl_wmi_add_del_mcast_filter_cmd(struct wmi *wmi, u8 if_idx,
3255 u8 *filter, bool add_filter)
3256{
3257 struct sk_buff *skb;
3258 struct wmi_mcast_filter_add_del_cmd *cmd;
3259 int ret;
3260
3261 if ((filter[0] != 0x33 || filter[1] != 0x33) &&
3262 (filter[0] != 0x01 || filter[1] != 0x00 ||
3263 filter[2] != 0x5e || filter[3] > 0x7f)) {
3264 ath6kl_warn("invalid multicast filter address\n");
3265 return -EINVAL;
3266 }
3267
3268 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3269 if (!skb)
3270 return -ENOMEM;
3271
3272 cmd = (struct wmi_mcast_filter_add_del_cmd *) skb->data;
3273 memcpy(cmd->mcast_mac, filter, ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
3274 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3275 add_filter ? WMI_SET_MCAST_FILTER_CMDID :
3276 WMI_DEL_MCAST_FILTER_CMDID,
3277 NO_SYNC_WMIFLAG);
3278
3279 return ret;
3280}
3281
Thomas Pedersenc422d52d2012-05-15 00:09:23 -07003282int ath6kl_wmi_sta_bmiss_enhance_cmd(struct wmi *wmi, u8 if_idx, bool enhance)
3283{
3284 struct sk_buff *skb;
3285 struct wmi_sta_bmiss_enhance_cmd *cmd;
3286 int ret;
3287
3288 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3289 if (!skb)
3290 return -ENOMEM;
3291
3292 cmd = (struct wmi_sta_bmiss_enhance_cmd *) skb->data;
3293 cmd->enable = enhance ? 1 : 0;
3294
3295 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3296 WMI_STA_BMISS_ENHANCE_CMDID,
3297 NO_SYNC_WMIFLAG);
3298 return ret;
3299}
3300
Kalle Valo84841ba2012-07-19 16:00:56 +03003301int ath6kl_wmi_set_regdomain_cmd(struct wmi *wmi, const char *alpha2)
3302{
3303 struct sk_buff *skb;
3304 struct wmi_set_regdomain_cmd *cmd;
3305
3306 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3307 if (!skb)
3308 return -ENOMEM;
3309
3310 cmd = (struct wmi_set_regdomain_cmd *) skb->data;
3311 memcpy(cmd->iso_name, alpha2, 2);
3312
3313 return ath6kl_wmi_cmd_send(wmi, 0, skb,
3314 WMI_SET_REGDOMAIN_CMDID,
3315 NO_SYNC_WMIFLAG);
3316}
3317
Jessica Wuc1d32d32014-06-17 12:41:10 +03003318s32 ath6kl_wmi_get_rate(struct wmi *wmi, s8 rate_index)
Kalle Valobdcd8172011-07-18 00:22:30 +03003319{
Jessica Wuc1d32d32014-06-17 12:41:10 +03003320 struct ath6kl *ar = wmi->parent_dev;
Dengke Qiu83685092012-08-28 15:33:42 +08003321 u8 sgi = 0;
Jessica Wuc1d32d32014-06-17 12:41:10 +03003322 s32 ret;
Dengke Qiu83685092012-08-28 15:33:42 +08003323
Kalle Valobdcd8172011-07-18 00:22:30 +03003324 if (rate_index == RATE_AUTO)
3325 return 0;
3326
Dengke Qiu83685092012-08-28 15:33:42 +08003327 /* SGI is stored as the MSB of the rate_index */
3328 if (rate_index & RATE_INDEX_MSB) {
3329 rate_index &= RATE_INDEX_WITHOUT_SGI_MASK;
3330 sgi = 1;
3331 }
3332
Jessica Wuc1d32d32014-06-17 12:41:10 +03003333 if (test_bit(ATH6KL_FW_CAPABILITY_RATETABLE_MCS15,
3334 ar->fw_capabilities)) {
3335 if (WARN_ON(rate_index >= ARRAY_SIZE(wmi_rate_tbl_mcs15)))
3336 return 0;
Dengke Qiu83685092012-08-28 15:33:42 +08003337
Jessica Wuc1d32d32014-06-17 12:41:10 +03003338 ret = wmi_rate_tbl_mcs15[(u32) rate_index][sgi];
3339 } else {
3340 if (WARN_ON(rate_index >= ARRAY_SIZE(wmi_rate_tbl)))
3341 return 0;
3342
3343 ret = wmi_rate_tbl[(u32) rate_index][sgi];
3344 }
3345
3346 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +03003347}
3348
Kalle Valobdcd8172011-07-18 00:22:30 +03003349static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
3350 u32 len)
3351{
3352 struct wmi_pmkid_list_reply *reply;
3353 u32 expected_len;
3354
3355 if (len < sizeof(struct wmi_pmkid_list_reply))
3356 return -EINVAL;
3357
3358 reply = (struct wmi_pmkid_list_reply *)datap;
3359 expected_len = sizeof(reply->num_pmkid) +
3360 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
3361
3362 if (len < expected_len)
3363 return -EINVAL;
3364
3365 return 0;
3366}
3367
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303368static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
3369 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003370{
3371 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
3372
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303373 aggr_recv_addba_req_evt(vif, cmd->tid,
Kalle Valobdcd8172011-07-18 00:22:30 +03003374 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
3375
3376 return 0;
3377}
3378
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303379static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
3380 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003381{
3382 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
3383
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303384 aggr_recv_delba_req_evt(vif, cmd->tid);
Kalle Valobdcd8172011-07-18 00:22:30 +03003385
3386 return 0;
3387}
3388
3389/* AP mode functions */
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003390
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303391int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
3392 struct wmi_connect_cmd *p)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003393{
3394 struct sk_buff *skb;
3395 struct wmi_connect_cmd *cm;
3396 int res;
3397
3398 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
3399 if (!skb)
3400 return -ENOMEM;
3401
3402 cm = (struct wmi_connect_cmd *) skb->data;
3403 memcpy(cm, p, sizeof(*cm));
3404
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303405 res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003406 NO_SYNC_WMIFLAG);
Kalle Valocdeb8602012-04-12 11:02:18 +03003407 ath6kl_dbg(ATH6KL_DBG_WMI,
3408 "%s: nw_type=%u auth_mode=%u ch=%u ctrl_flags=0x%x-> res=%d\n",
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003409 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
3410 le32_to_cpu(p->ctrl_flags), res);
3411 return res;
3412}
3413
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303414int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
3415 u16 reason)
Jouni Malinen23875132011-08-30 21:57:53 +03003416{
3417 struct sk_buff *skb;
3418 struct wmi_ap_set_mlme_cmd *cm;
3419
3420 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
3421 if (!skb)
3422 return -ENOMEM;
3423
3424 cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
3425 memcpy(cm->mac, mac, ETH_ALEN);
3426 cm->reason = cpu_to_le16(reason);
3427 cm->cmd = cmd;
3428
Aarthi Thiruvengadam7397dde2012-03-15 14:36:11 -07003429 ath6kl_dbg(ATH6KL_DBG_WMI, "ap_set_mlme: cmd=%d reason=%d\n", cm->cmd,
3430 cm->reason);
3431
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303432 return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
Jouni Malinen23875132011-08-30 21:57:53 +03003433 NO_SYNC_WMIFLAG);
3434}
3435
Thomas Pedersen67cd22e2012-02-28 15:08:46 -08003436int ath6kl_wmi_ap_hidden_ssid(struct wmi *wmi, u8 if_idx, bool enable)
3437{
3438 struct sk_buff *skb;
3439 struct wmi_ap_hidden_ssid_cmd *cmd;
3440
3441 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3442 if (!skb)
3443 return -ENOMEM;
3444
3445 cmd = (struct wmi_ap_hidden_ssid_cmd *) skb->data;
3446 cmd->hidden_ssid = enable ? 1 : 0;
3447
3448 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_HIDDEN_SSID_CMDID,
3449 NO_SYNC_WMIFLAG);
3450}
3451
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +05303452/* This command will be used to enable/disable AP uAPSD feature */
3453int ath6kl_wmi_ap_set_apsd(struct wmi *wmi, u8 if_idx, u8 enable)
3454{
3455 struct wmi_ap_set_apsd_cmd *cmd;
3456 struct sk_buff *skb;
3457
3458 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3459 if (!skb)
3460 return -ENOMEM;
3461
3462 cmd = (struct wmi_ap_set_apsd_cmd *)skb->data;
3463 cmd->enable = enable;
3464
3465 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_APSD_CMDID,
3466 NO_SYNC_WMIFLAG);
3467}
3468
3469int ath6kl_wmi_set_apsd_bfrd_traf(struct wmi *wmi, u8 if_idx,
3470 u16 aid, u16 bitmap, u32 flags)
3471{
3472 struct wmi_ap_apsd_buffered_traffic_cmd *cmd;
3473 struct sk_buff *skb;
3474
3475 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3476 if (!skb)
3477 return -ENOMEM;
3478
3479 cmd = (struct wmi_ap_apsd_buffered_traffic_cmd *)skb->data;
3480 cmd->aid = cpu_to_le16(aid);
3481 cmd->bitmap = cpu_to_le16(bitmap);
3482 cmd->flags = cpu_to_le32(flags);
3483
3484 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3485 WMI_AP_APSD_BUFFERED_TRAFFIC_CMDID,
3486 NO_SYNC_WMIFLAG);
3487}
3488
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303489static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
3490 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003491{
3492 struct wmi_pspoll_event *ev;
3493
3494 if (len < sizeof(struct wmi_pspoll_event))
3495 return -EINVAL;
3496
3497 ev = (struct wmi_pspoll_event *) datap;
3498
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303499 ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
Kalle Valobdcd8172011-07-18 00:22:30 +03003500
3501 return 0;
3502}
3503
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303504static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
3505 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003506{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303507 ath6kl_dtimexpiry_event(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +03003508
3509 return 0;
3510}
3511
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303512int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
3513 bool flag)
Kalle Valobdcd8172011-07-18 00:22:30 +03003514{
3515 struct sk_buff *skb;
3516 struct wmi_ap_set_pvb_cmd *cmd;
3517 int ret;
3518
3519 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
3520 if (!skb)
3521 return -ENOMEM;
3522
3523 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
3524 cmd->aid = cpu_to_le16(aid);
Jouni Malinend6e51e62011-09-05 17:38:44 +03003525 cmd->rsvd = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +03003526 cmd->flag = cpu_to_le32(flag);
3527
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303528 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003529 NO_SYNC_WMIFLAG);
3530
Chaehyun Limb9301502016-09-18 15:30:24 +09003531 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +03003532}
3533
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303534int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
3535 u8 rx_meta_ver,
Kalle Valobdcd8172011-07-18 00:22:30 +03003536 bool rx_dot11_hdr, bool defrag_on_host)
3537{
3538 struct sk_buff *skb;
3539 struct wmi_rx_frame_format_cmd *cmd;
3540 int ret;
3541
3542 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3543 if (!skb)
3544 return -ENOMEM;
3545
3546 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
3547 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
3548 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
3549 cmd->meta_ver = rx_meta_ver;
3550
3551 /* Delete the local aggr state, on host */
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303552 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003553 NO_SYNC_WMIFLAG);
3554
3555 return ret;
3556}
3557
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303558int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
3559 const u8 *ie, u8 ie_len)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003560{
3561 struct sk_buff *skb;
3562 struct wmi_set_appie_cmd *p;
3563
3564 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
3565 if (!skb)
3566 return -ENOMEM;
3567
Kalle Valocdeb8602012-04-12 11:02:18 +03003568 ath6kl_dbg(ATH6KL_DBG_WMI,
3569 "set_appie_cmd: mgmt_frm_type=%u ie_len=%u\n",
3570 mgmt_frm_type, ie_len);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003571 p = (struct wmi_set_appie_cmd *) skb->data;
3572 p->mgmt_frm_type = mgmt_frm_type;
3573 p->ie_len = ie_len;
Kalle Valo10509f92011-12-13 14:52:07 +02003574
3575 if (ie != NULL && ie_len > 0)
3576 memcpy(p->ie_info, ie, ie_len);
3577
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303578 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003579 NO_SYNC_WMIFLAG);
3580}
3581
Vasanthakumar Thiagarajand97c1212012-04-09 20:51:20 +05303582int ath6kl_wmi_set_ie_cmd(struct wmi *wmi, u8 if_idx, u8 ie_id, u8 ie_field,
3583 const u8 *ie_info, u8 ie_len)
3584{
3585 struct sk_buff *skb;
3586 struct wmi_set_ie_cmd *p;
3587
3588 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
3589 if (!skb)
3590 return -ENOMEM;
3591
3592 ath6kl_dbg(ATH6KL_DBG_WMI, "set_ie_cmd: ie_id=%u ie_ie_field=%u ie_len=%u\n",
3593 ie_id, ie_field, ie_len);
3594 p = (struct wmi_set_ie_cmd *) skb->data;
3595 p->ie_id = ie_id;
3596 p->ie_field = ie_field;
3597 p->ie_len = ie_len;
3598 if (ie_info && ie_len > 0)
3599 memcpy(p->ie_info, ie_info, ie_len);
3600
3601 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IE_CMDID,
3602 NO_SYNC_WMIFLAG);
3603}
3604
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003605int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
3606{
3607 struct sk_buff *skb;
3608 struct wmi_disable_11b_rates_cmd *cmd;
3609
3610 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3611 if (!skb)
3612 return -ENOMEM;
3613
3614 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
3615 disable);
3616 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
3617 cmd->disable = disable ? 1 : 0;
3618
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303619 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003620 NO_SYNC_WMIFLAG);
3621}
3622
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303623int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003624{
3625 struct sk_buff *skb;
3626 struct wmi_remain_on_chnl_cmd *p;
3627
3628 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3629 if (!skb)
3630 return -ENOMEM;
3631
3632 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
3633 freq, dur);
3634 p = (struct wmi_remain_on_chnl_cmd *) skb->data;
3635 p->freq = cpu_to_le32(freq);
3636 p->duration = cpu_to_le32(dur);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303637 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003638 NO_SYNC_WMIFLAG);
3639}
3640
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08003641/* ath6kl_wmi_send_action_cmd is to be deprecated. Use
3642 * ath6kl_wmi_send_mgmt_cmd instead. The new function supports P2P
3643 * mgmt operations using station interface.
3644 */
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003645static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3646 u32 freq, u32 wait, const u8 *data,
3647 u16 data_len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003648{
3649 struct sk_buff *skb;
3650 struct wmi_send_action_cmd *p;
Jouni Malinena0df5db2011-08-30 21:58:02 +03003651 u8 *buf;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003652
3653 if (wait)
3654 return -EINVAL; /* Offload for wait not supported */
3655
Jouni Malinena0df5db2011-08-30 21:58:02 +03003656 buf = kmalloc(data_len, GFP_KERNEL);
3657 if (!buf)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003658 return -ENOMEM;
3659
Jouni Malinena0df5db2011-08-30 21:58:02 +03003660 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3661 if (!skb) {
3662 kfree(buf);
3663 return -ENOMEM;
3664 }
3665
3666 kfree(wmi->last_mgmt_tx_frame);
Aarthi Thiruvengadam3101ede2011-10-27 09:35:56 -07003667 memcpy(buf, data, data_len);
Jouni Malinena0df5db2011-08-30 21:58:02 +03003668 wmi->last_mgmt_tx_frame = buf;
3669 wmi->last_mgmt_tx_frame_len = data_len;
3670
Kalle Valocdeb8602012-04-12 11:02:18 +03003671 ath6kl_dbg(ATH6KL_DBG_WMI,
3672 "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
3673 id, freq, wait, data_len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003674 p = (struct wmi_send_action_cmd *) skb->data;
3675 p->id = cpu_to_le32(id);
3676 p->freq = cpu_to_le32(freq);
3677 p->wait = cpu_to_le32(wait);
3678 p->len = cpu_to_le16(data_len);
3679 memcpy(p->data, data, data_len);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303680 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003681 NO_SYNC_WMIFLAG);
3682}
3683
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003684static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3685 u32 freq, u32 wait, const u8 *data,
3686 u16 data_len, u32 no_cck)
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08003687{
3688 struct sk_buff *skb;
3689 struct wmi_send_mgmt_cmd *p;
3690 u8 *buf;
3691
3692 if (wait)
3693 return -EINVAL; /* Offload for wait not supported */
3694
3695 buf = kmalloc(data_len, GFP_KERNEL);
3696 if (!buf)
3697 return -ENOMEM;
3698
3699 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3700 if (!skb) {
3701 kfree(buf);
3702 return -ENOMEM;
3703 }
3704
3705 kfree(wmi->last_mgmt_tx_frame);
3706 memcpy(buf, data, data_len);
3707 wmi->last_mgmt_tx_frame = buf;
3708 wmi->last_mgmt_tx_frame_len = data_len;
3709
Kalle Valocdeb8602012-04-12 11:02:18 +03003710 ath6kl_dbg(ATH6KL_DBG_WMI,
3711 "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
3712 id, freq, wait, data_len);
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08003713 p = (struct wmi_send_mgmt_cmd *) skb->data;
3714 p->id = cpu_to_le32(id);
3715 p->freq = cpu_to_le32(freq);
3716 p->wait = cpu_to_le32(wait);
3717 p->no_cck = cpu_to_le32(no_cck);
3718 p->len = cpu_to_le16(data_len);
3719 memcpy(p->data, data, data_len);
3720 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID,
3721 NO_SYNC_WMIFLAG);
3722}
3723
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003724int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
3725 u32 wait, const u8 *data, u16 data_len,
3726 u32 no_cck)
3727{
3728 int status;
3729 struct ath6kl *ar = wmi->parent_dev;
3730
3731 if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
3732 ar->fw_capabilities)) {
3733 /*
3734 * If capable of doing P2P mgmt operations using
3735 * station interface, send additional information like
3736 * supported rates to advertise and xmit rates for
3737 * probe requests
3738 */
3739 status = __ath6kl_wmi_send_mgmt_cmd(ar->wmi, if_idx, id, freq,
3740 wait, data, data_len,
3741 no_cck);
3742 } else {
3743 status = ath6kl_wmi_send_action_cmd(ar->wmi, if_idx, id, freq,
3744 wait, data, data_len);
3745 }
3746
3747 return status;
3748}
3749
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303750int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
3751 const u8 *dst, const u8 *data,
3752 u16 data_len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003753{
3754 struct sk_buff *skb;
3755 struct wmi_p2p_probe_response_cmd *p;
Aarthi Thiruvengadambd24a502011-11-09 10:05:56 -08003756 size_t cmd_len = sizeof(*p) + data_len;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003757
Aarthi Thiruvengadambd24a502011-11-09 10:05:56 -08003758 if (data_len == 0)
3759 cmd_len++; /* work around target minimum length requirement */
3760
3761 skb = ath6kl_wmi_get_new_buf(cmd_len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003762 if (!skb)
3763 return -ENOMEM;
3764
Kalle Valocdeb8602012-04-12 11:02:18 +03003765 ath6kl_dbg(ATH6KL_DBG_WMI,
3766 "send_probe_response_cmd: freq=%u dst=%pM len=%u\n",
3767 freq, dst, data_len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003768 p = (struct wmi_p2p_probe_response_cmd *) skb->data;
3769 p->freq = cpu_to_le32(freq);
3770 memcpy(p->destination_addr, dst, ETH_ALEN);
3771 p->len = cpu_to_le16(data_len);
3772 memcpy(p->data, data, data_len);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303773 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3774 WMI_SEND_PROBE_RESPONSE_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003775 NO_SYNC_WMIFLAG);
3776}
3777
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303778int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003779{
3780 struct sk_buff *skb;
3781 struct wmi_probe_req_report_cmd *p;
3782
3783 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3784 if (!skb)
3785 return -ENOMEM;
3786
3787 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
3788 enable);
3789 p = (struct wmi_probe_req_report_cmd *) skb->data;
3790 p->enable = enable ? 1 : 0;
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303791 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003792 NO_SYNC_WMIFLAG);
3793}
3794
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303795int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003796{
3797 struct sk_buff *skb;
3798 struct wmi_get_p2p_info *p;
3799
3800 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3801 if (!skb)
3802 return -ENOMEM;
3803
3804 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
3805 info_req_flags);
3806 p = (struct wmi_get_p2p_info *) skb->data;
3807 p->info_req_flags = cpu_to_le32(info_req_flags);
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303808 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003809 NO_SYNC_WMIFLAG);
3810}
3811
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303812int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003813{
3814 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303815 return ath6kl_wmi_simple_cmd(wmi, if_idx,
3816 WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003817}
3818
Vasanthakumar Thiagarajan03bdeb02012-03-21 20:58:39 +05303819int ath6kl_wmi_set_inact_period(struct wmi *wmi, u8 if_idx, int inact_timeout)
3820{
3821 struct sk_buff *skb;
3822 struct wmi_set_inact_period_cmd *cmd;
3823
3824 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3825 if (!skb)
3826 return -ENOMEM;
3827
3828 cmd = (struct wmi_set_inact_period_cmd *) skb->data;
3829 cmd->inact_period = cpu_to_le32(inact_timeout);
3830 cmd->num_null_func = 0;
3831
3832 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_CONN_INACT_CMDID,
3833 NO_SYNC_WMIFLAG);
3834}
3835
Vasanthakumar Thiagarajan92332992012-08-29 19:40:27 +05303836static void ath6kl_wmi_hb_challenge_resp_event(struct wmi *wmi, u8 *datap,
3837 int len)
3838{
3839 struct wmix_hb_challenge_resp_cmd *cmd;
3840
3841 if (len < sizeof(struct wmix_hb_challenge_resp_cmd))
3842 return;
3843
3844 cmd = (struct wmix_hb_challenge_resp_cmd *) datap;
3845 ath6kl_recovery_hb_event(wmi->parent_dev,
3846 le32_to_cpu(cmd->cookie));
3847}
3848
Kalle Valobdcd8172011-07-18 00:22:30 +03003849static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
3850{
3851 struct wmix_cmd_hdr *cmd;
3852 u32 len;
3853 u16 id;
3854 u8 *datap;
3855 int ret = 0;
3856
3857 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
3858 ath6kl_err("bad packet 1\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03003859 return -EINVAL;
3860 }
3861
3862 cmd = (struct wmix_cmd_hdr *) skb->data;
3863 id = le32_to_cpu(cmd->cmd_id);
3864
3865 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
3866
3867 datap = skb->data;
3868 len = skb->len;
3869
3870 switch (id) {
3871 case WMIX_HB_CHALLENGE_RESP_EVENTID:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003872 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
Vasanthakumar Thiagarajan92332992012-08-29 19:40:27 +05303873 ath6kl_wmi_hb_challenge_resp_event(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003874 break;
3875 case WMIX_DBGLOG_EVENTID:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003876 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
Kalle Valobdf53962011-09-02 10:32:04 +03003877 ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003878 break;
3879 default:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003880 ath6kl_warn("unknown cmd id 0x%x\n", id);
Kalle Valobdcd8172011-07-18 00:22:30 +03003881 ret = -EINVAL;
3882 break;
3883 }
3884
3885 return ret;
3886}
3887
Jouni Malinen4b28a802011-10-11 17:31:54 +03003888static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
3889{
3890 return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
3891}
3892
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303893/* Process interface specific wmi events, caller would free the datap */
3894static int ath6kl_wmi_proc_events_vif(struct wmi *wmi, u16 if_idx, u16 cmd_id,
3895 u8 *datap, u32 len)
Kalle Valobdcd8172011-07-18 00:22:30 +03003896{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303897 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03003898
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303899 vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
3900 if (!vif) {
3901 ath6kl_dbg(ATH6KL_DBG_WMI,
3902 "Wmi event for unavailable vif, vif_index:%d\n",
3903 if_idx);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303904 return -EINVAL;
3905 }
3906
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303907 switch (cmd_id) {
3908 case WMI_CONNECT_EVENTID:
3909 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
3910 return ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
3911 case WMI_DISCONNECT_EVENTID:
3912 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
3913 return ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
3914 case WMI_TKIP_MICERR_EVENTID:
3915 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
3916 return ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
3917 case WMI_BSSINFO_EVENTID:
3918 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
3919 return ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
3920 case WMI_NEIGHBOR_REPORT_EVENTID:
3921 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
3922 return ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
3923 vif);
3924 case WMI_SCAN_COMPLETE_EVENTID:
3925 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
3926 return ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
3927 case WMI_REPORT_STATISTICS_EVENTID:
3928 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
3929 return ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
3930 case WMI_CAC_EVENTID:
3931 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
3932 return ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
3933 case WMI_PSPOLL_EVENTID:
3934 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
3935 return ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
3936 case WMI_DTIMEXPIRY_EVENTID:
3937 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
3938 return ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
3939 case WMI_ADDBA_REQ_EVENTID:
3940 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
3941 return ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
3942 case WMI_DELBA_REQ_EVENTID:
3943 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
3944 return ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
3945 case WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID:
3946 ath6kl_dbg(ATH6KL_DBG_WMI,
3947 "WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID");
3948 return ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(wmi, vif);
3949 case WMI_REMAIN_ON_CHNL_EVENTID:
3950 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
3951 return ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
3952 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
3953 ath6kl_dbg(ATH6KL_DBG_WMI,
3954 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
3955 return ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
3956 len, vif);
3957 case WMI_TX_STATUS_EVENTID:
3958 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
3959 return ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
3960 case WMI_RX_PROBE_REQ_EVENTID:
3961 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
3962 return ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
3963 case WMI_RX_ACTION_EVENTID:
3964 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
3965 return ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
Thomas Pedersen279b2862012-07-17 19:39:55 -07003966 case WMI_TXE_NOTIFY_EVENTID:
3967 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TXE_NOTIFY_EVENTID\n");
3968 return ath6kl_wmi_txe_notify_event_rx(wmi, datap, len, vif);
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303969 default:
3970 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", cmd_id);
3971 return -EINVAL;
3972 }
3973
3974 return 0;
3975}
3976
3977static int ath6kl_wmi_proc_events(struct wmi *wmi, struct sk_buff *skb)
3978{
3979 struct wmi_cmd_hdr *cmd;
3980 int ret = 0;
3981 u32 len;
3982 u16 id;
3983 u8 if_idx;
3984 u8 *datap;
3985
3986 cmd = (struct wmi_cmd_hdr *) skb->data;
3987 id = le16_to_cpu(cmd->cmd_id);
3988 if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
3989
3990 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
3991 datap = skb->data;
3992 len = skb->len;
3993
3994 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
3995 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
3996 datap, len);
3997
Kalle Valobdcd8172011-07-18 00:22:30 +03003998 switch (id) {
3999 case WMI_GET_BITRATE_CMDID:
4000 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
4001 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
4002 break;
4003 case WMI_GET_CHANNEL_LIST_CMDID:
4004 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
4005 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
4006 break;
4007 case WMI_GET_TX_PWR_CMDID:
4008 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
4009 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
4010 break;
4011 case WMI_READY_EVENTID:
4012 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
4013 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
4014 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03004015 case WMI_PEER_NODE_EVENTID:
4016 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
4017 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
4018 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03004019 case WMI_REGDOMAIN_EVENTID:
4020 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
Vivek Natarajan06033762011-09-06 13:01:36 +05304021 ath6kl_wmi_regdomain_event(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03004022 break;
4023 case WMI_PSTREAM_TIMEOUT_EVENTID:
4024 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
4025 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
4026 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03004027 case WMI_CMDERROR_EVENTID:
4028 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
4029 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
4030 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03004031 case WMI_RSSI_THRESHOLD_EVENTID:
4032 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
4033 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
4034 break;
4035 case WMI_ERROR_REPORT_EVENTID:
4036 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
4037 break;
4038 case WMI_OPT_RX_FRAME_EVENTID:
4039 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
Jouni Malinenf195d502011-09-19 19:15:00 +03004040 /* this event has been deprecated */
Kalle Valobdcd8172011-07-18 00:22:30 +03004041 break;
4042 case WMI_REPORT_ROAM_TBL_EVENTID:
4043 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
Jouni Malinen4b28a802011-10-11 17:31:54 +03004044 ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03004045 break;
4046 case WMI_EXTENSION_EVENTID:
4047 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
4048 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
4049 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03004050 case WMI_CHANNEL_CHANGE_EVENTID:
4051 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
4052 break;
4053 case WMI_REPORT_ROAM_DATA_EVENTID:
4054 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
4055 break;
Kalle Valo003353b0d2011-09-01 10:14:21 +03004056 case WMI_TEST_EVENTID:
4057 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08004058 ret = ath6kl_wmi_test_rx(wmi, datap, len);
Kalle Valo003353b0d2011-09-01 10:14:21 +03004059 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03004060 case WMI_GET_FIXRATES_CMDID:
4061 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
4062 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
4063 break;
4064 case WMI_TX_RETRY_ERR_EVENTID:
4065 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
4066 break;
4067 case WMI_SNR_THRESHOLD_EVENTID:
4068 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
4069 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
4070 break;
4071 case WMI_LQ_THRESHOLD_EVENTID:
4072 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
4073 break;
4074 case WMI_APLIST_EVENTID:
4075 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
4076 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
4077 break;
4078 case WMI_GET_KEEPALIVE_CMDID:
4079 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
4080 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
4081 break;
4082 case WMI_GET_WOW_LIST_EVENTID:
4083 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03004084 break;
4085 case WMI_GET_PMKID_LIST_EVENTID:
4086 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
4087 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
4088 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03004089 case WMI_SET_PARAMS_REPLY_EVENTID:
4090 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
4091 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03004092 case WMI_ADDBA_RESP_EVENTID:
4093 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
4094 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03004095 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
4096 ath6kl_dbg(ATH6KL_DBG_WMI,
4097 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
4098 break;
4099 case WMI_REPORT_BTCOEX_STATS_EVENTID:
4100 ath6kl_dbg(ATH6KL_DBG_WMI,
4101 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
4102 break;
4103 case WMI_TX_COMPLETE_EVENTID:
4104 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
4105 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
4106 break;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03004107 case WMI_P2P_CAPABILITIES_EVENTID:
4108 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
4109 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
4110 break;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03004111 case WMI_P2P_INFO_EVENTID:
4112 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
4113 ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
4114 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03004115 default:
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05304116 /* may be the event is interface specific */
4117 ret = ath6kl_wmi_proc_events_vif(wmi, if_idx, id, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03004118 break;
4119 }
4120
4121 dev_kfree_skb(skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03004122 return ret;
4123}
4124
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05304125/* Control Path */
4126int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
4127{
4128 if (WARN_ON(skb == NULL))
4129 return -EINVAL;
4130
4131 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
4132 ath6kl_err("bad packet 1\n");
4133 dev_kfree_skb(skb);
4134 return -EINVAL;
4135 }
4136
Kalle Valo416cf0b2013-03-18 13:42:20 +02004137 trace_ath6kl_wmi_event(skb->data, skb->len);
4138
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05304139 return ath6kl_wmi_proc_events(wmi, skb);
4140}
4141
Kalle Valoc89c5912011-10-27 18:48:00 +03004142void ath6kl_wmi_reset(struct wmi *wmi)
Kalle Valobdcd8172011-07-18 00:22:30 +03004143{
Kalle Valobdcd8172011-07-18 00:22:30 +03004144 spin_lock_bh(&wmi->lock);
4145
4146 wmi->fat_pipe_exist = 0;
4147 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
4148
4149 spin_unlock_bh(&wmi->lock);
4150}
4151
Vasanthakumar Thiagarajan28657852011-07-21 12:00:49 +05304152void *ath6kl_wmi_init(struct ath6kl *dev)
Kalle Valobdcd8172011-07-18 00:22:30 +03004153{
4154 struct wmi *wmi;
4155
4156 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
4157 if (!wmi)
4158 return NULL;
4159
4160 spin_lock_init(&wmi->lock);
4161
4162 wmi->parent_dev = dev;
4163
Kalle Valobdcd8172011-07-18 00:22:30 +03004164 wmi->pwr_mode = REC_POWER;
Kalle Valobdcd8172011-07-18 00:22:30 +03004165
Kalle Valoc89c5912011-10-27 18:48:00 +03004166 ath6kl_wmi_reset(wmi);
Kalle Valobdcd8172011-07-18 00:22:30 +03004167
4168 return wmi;
4169}
4170
4171void ath6kl_wmi_shutdown(struct wmi *wmi)
4172{
4173 if (!wmi)
4174 return;
4175
Jouni Malinena0df5db2011-08-30 21:58:02 +03004176 kfree(wmi->last_mgmt_tx_frame);
Kalle Valobdcd8172011-07-18 00:22:30 +03004177 kfree(wmi);
4178}