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