xref: /openbmc/linux/drivers/net/wireless/ath/ath6kl/wmi.c (revision 56f1257fdcc08778a76f03cbe97d602268fdfc51)
1bdcd8170SKalle Valo /*
2bdcd8170SKalle Valo  * Copyright (c) 2004-2011 Atheros Communications Inc.
31b2df407SVasanthakumar Thiagarajan  * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
4bdcd8170SKalle Valo  *
5bdcd8170SKalle Valo  * Permission to use, copy, modify, and/or distribute this software for any
6bdcd8170SKalle Valo  * purpose with or without fee is hereby granted, provided that the above
7bdcd8170SKalle Valo  * copyright notice and this permission notice appear in all copies.
8bdcd8170SKalle Valo  *
9bdcd8170SKalle Valo  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10bdcd8170SKalle Valo  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11bdcd8170SKalle Valo  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12bdcd8170SKalle Valo  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13bdcd8170SKalle Valo  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14bdcd8170SKalle Valo  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15bdcd8170SKalle Valo  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16bdcd8170SKalle Valo  */
17bdcd8170SKalle Valo 
18bdcd8170SKalle Valo #include <linux/ip.h>
191560ac7dSLuis R. Rodriguez #include <linux/in.h>
20bdcd8170SKalle Valo #include "core.h"
21bdcd8170SKalle Valo #include "debug.h"
22003353b0SKalle Valo #include "testmode.h"
23416cf0b4SKalle Valo #include "trace.h"
2406033760SVivek Natarajan #include "../regd.h"
2506033760SVivek Natarajan #include "../regd_common.h"
26bdcd8170SKalle Valo 
27240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx);
28bdcd8170SKalle Valo 
29bdcd8170SKalle Valo static const s32 wmi_rate_tbl[][2] = {
30bdcd8170SKalle Valo 	/* {W/O SGI, with SGI} */
31bdcd8170SKalle Valo 	{1000, 1000},
32bdcd8170SKalle Valo 	{2000, 2000},
33bdcd8170SKalle Valo 	{5500, 5500},
34bdcd8170SKalle Valo 	{11000, 11000},
35bdcd8170SKalle Valo 	{6000, 6000},
36bdcd8170SKalle Valo 	{9000, 9000},
37bdcd8170SKalle Valo 	{12000, 12000},
38bdcd8170SKalle Valo 	{18000, 18000},
39bdcd8170SKalle Valo 	{24000, 24000},
40bdcd8170SKalle Valo 	{36000, 36000},
41bdcd8170SKalle Valo 	{48000, 48000},
42bdcd8170SKalle Valo 	{54000, 54000},
43bdcd8170SKalle Valo 	{6500, 7200},
44bdcd8170SKalle Valo 	{13000, 14400},
45bdcd8170SKalle Valo 	{19500, 21700},
46bdcd8170SKalle Valo 	{26000, 28900},
47bdcd8170SKalle Valo 	{39000, 43300},
48bdcd8170SKalle Valo 	{52000, 57800},
49bdcd8170SKalle Valo 	{58500, 65000},
50bdcd8170SKalle Valo 	{65000, 72200},
51bdcd8170SKalle Valo 	{13500, 15000},
52bdcd8170SKalle Valo 	{27000, 30000},
53bdcd8170SKalle Valo 	{40500, 45000},
54bdcd8170SKalle Valo 	{54000, 60000},
55bdcd8170SKalle Valo 	{81000, 90000},
56bdcd8170SKalle Valo 	{108000, 120000},
57bdcd8170SKalle Valo 	{121500, 135000},
58bdcd8170SKalle Valo 	{135000, 150000},
59bdcd8170SKalle Valo 	{0, 0}
60bdcd8170SKalle Valo };
61bdcd8170SKalle Valo 
62c1d32d30SJessica Wu static const s32 wmi_rate_tbl_mcs15[][2] = {
63c1d32d30SJessica Wu 	/* {W/O SGI, with SGI} */
64c1d32d30SJessica Wu 	{1000, 1000},
65c1d32d30SJessica Wu 	{2000, 2000},
66c1d32d30SJessica Wu 	{5500, 5500},
67c1d32d30SJessica Wu 	{11000, 11000},
68c1d32d30SJessica Wu 	{6000, 6000},
69c1d32d30SJessica Wu 	{9000, 9000},
70c1d32d30SJessica Wu 	{12000, 12000},
71c1d32d30SJessica Wu 	{18000, 18000},
72c1d32d30SJessica Wu 	{24000, 24000},
73c1d32d30SJessica Wu 	{36000, 36000},
74c1d32d30SJessica Wu 	{48000, 48000},
75c1d32d30SJessica Wu 	{54000, 54000},
76c1d32d30SJessica Wu 	{6500, 7200},     /* HT 20, MCS 0 */
77c1d32d30SJessica Wu 	{13000, 14400},
78c1d32d30SJessica Wu 	{19500, 21700},
79c1d32d30SJessica Wu 	{26000, 28900},
80c1d32d30SJessica Wu 	{39000, 43300},
81c1d32d30SJessica Wu 	{52000, 57800},
82c1d32d30SJessica Wu 	{58500, 65000},
83c1d32d30SJessica Wu 	{65000, 72200},
84c1d32d30SJessica Wu 	{13000, 14400},   /* HT 20, MCS 8 */
85c1d32d30SJessica Wu 	{26000, 28900},
86c1d32d30SJessica Wu 	{39000, 43300},
87c1d32d30SJessica Wu 	{52000, 57800},
88c1d32d30SJessica Wu 	{78000, 86700},
89c1d32d30SJessica Wu 	{104000, 115600},
90c1d32d30SJessica Wu 	{117000, 130000},
91c1d32d30SJessica Wu 	{130000, 144400}, /* HT 20, MCS 15 */
92c1d32d30SJessica Wu 	{13500, 15000},   /*HT 40, MCS 0 */
93c1d32d30SJessica Wu 	{27000, 30000},
94c1d32d30SJessica Wu 	{40500, 45000},
95c1d32d30SJessica Wu 	{54000, 60000},
96c1d32d30SJessica Wu 	{81000, 90000},
97c1d32d30SJessica Wu 	{108000, 120000},
98c1d32d30SJessica Wu 	{121500, 135000},
99c1d32d30SJessica Wu 	{135000, 150000},
100c1d32d30SJessica Wu 	{27000, 30000},   /*HT 40, MCS 8 */
101c1d32d30SJessica Wu 	{54000, 60000},
102c1d32d30SJessica Wu 	{81000, 90000},
103c1d32d30SJessica Wu 	{108000, 120000},
104c1d32d30SJessica Wu 	{162000, 180000},
105c1d32d30SJessica Wu 	{216000, 240000},
106c1d32d30SJessica Wu 	{243000, 270000},
107c1d32d30SJessica Wu 	{270000, 300000}, /*HT 40, MCS 15 */
108c1d32d30SJessica Wu 	{0, 0}
109c1d32d30SJessica Wu };
110c1d32d30SJessica Wu 
111bdcd8170SKalle Valo /* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
112bdcd8170SKalle Valo static const u8 up_to_ac[] = {
113bdcd8170SKalle Valo 	WMM_AC_BE,
114bdcd8170SKalle Valo 	WMM_AC_BK,
115bdcd8170SKalle Valo 	WMM_AC_BK,
116bdcd8170SKalle Valo 	WMM_AC_BE,
117bdcd8170SKalle Valo 	WMM_AC_VI,
118bdcd8170SKalle Valo 	WMM_AC_VI,
119bdcd8170SKalle Valo 	WMM_AC_VO,
120bdcd8170SKalle Valo 	WMM_AC_VO,
121bdcd8170SKalle Valo };
122bdcd8170SKalle Valo 
123bdcd8170SKalle Valo void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
124bdcd8170SKalle Valo {
125bdcd8170SKalle Valo 	if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
126bdcd8170SKalle Valo 		return;
127bdcd8170SKalle Valo 
128bdcd8170SKalle Valo 	wmi->ep_id = ep_id;
129bdcd8170SKalle Valo }
130bdcd8170SKalle Valo 
131bdcd8170SKalle Valo enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
132bdcd8170SKalle Valo {
133bdcd8170SKalle Valo 	return wmi->ep_id;
134bdcd8170SKalle Valo }
135bdcd8170SKalle Valo 
1366765d0aaSVasanthakumar Thiagarajan struct ath6kl_vif *ath6kl_get_vif_by_index(struct ath6kl *ar, u8 if_idx)
137240d2799SVasanthakumar Thiagarajan {
138990bd915SVasanthakumar Thiagarajan 	struct ath6kl_vif *vif, *found = NULL;
139990bd915SVasanthakumar Thiagarajan 
14071f96ee6SKalle Valo 	if (WARN_ON(if_idx > (ar->vif_max - 1)))
141240d2799SVasanthakumar Thiagarajan 		return NULL;
142240d2799SVasanthakumar Thiagarajan 
143990bd915SVasanthakumar Thiagarajan 	/* FIXME: Locking */
14411f6e40dSVasanthakumar Thiagarajan 	spin_lock_bh(&ar->list_lock);
145990bd915SVasanthakumar Thiagarajan 	list_for_each_entry(vif, &ar->vif_list, list) {
146990bd915SVasanthakumar Thiagarajan 		if (vif->fw_vif_idx == if_idx) {
147990bd915SVasanthakumar Thiagarajan 			found = vif;
148990bd915SVasanthakumar Thiagarajan 			break;
149990bd915SVasanthakumar Thiagarajan 		}
150990bd915SVasanthakumar Thiagarajan 	}
15111f6e40dSVasanthakumar Thiagarajan 	spin_unlock_bh(&ar->list_lock);
152990bd915SVasanthakumar Thiagarajan 
153990bd915SVasanthakumar Thiagarajan 	return found;
154240d2799SVasanthakumar Thiagarajan }
155240d2799SVasanthakumar Thiagarajan 
156bdcd8170SKalle Valo /*  Performs DIX to 802.3 encapsulation for transmit packets.
157e1c05067SMasahiro Yamada  *  Assumes the entire DIX header is contiguous and that there is
158bdcd8170SKalle Valo  *  enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
159bdcd8170SKalle Valo  */
160bdcd8170SKalle Valo int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
161bdcd8170SKalle Valo {
162bdcd8170SKalle Valo 	struct ath6kl_llc_snap_hdr *llc_hdr;
163bdcd8170SKalle Valo 	struct ethhdr *eth_hdr;
164bdcd8170SKalle Valo 	size_t new_len;
165bdcd8170SKalle Valo 	__be16 type;
166bdcd8170SKalle Valo 	u8 *datap;
167bdcd8170SKalle Valo 	u16 size;
168bdcd8170SKalle Valo 
169bdcd8170SKalle Valo 	if (WARN_ON(skb == NULL))
170bdcd8170SKalle Valo 		return -EINVAL;
171bdcd8170SKalle Valo 
172bdcd8170SKalle Valo 	size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
173bdcd8170SKalle Valo 	if (skb_headroom(skb) < size)
174bdcd8170SKalle Valo 		return -ENOMEM;
175bdcd8170SKalle Valo 
176bdcd8170SKalle Valo 	eth_hdr = (struct ethhdr *) skb->data;
177bdcd8170SKalle Valo 	type = eth_hdr->h_proto;
178bdcd8170SKalle Valo 
179bdcd8170SKalle Valo 	if (!is_ethertype(be16_to_cpu(type))) {
180bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI,
181bdcd8170SKalle Valo 			   "%s: pkt is already in 802.3 format\n", __func__);
182bdcd8170SKalle Valo 		return 0;
183bdcd8170SKalle Valo 	}
184bdcd8170SKalle Valo 
185bdcd8170SKalle Valo 	new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
186bdcd8170SKalle Valo 
187bdcd8170SKalle Valo 	skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
188bdcd8170SKalle Valo 	datap = skb->data;
189bdcd8170SKalle Valo 
190bdcd8170SKalle Valo 	eth_hdr->h_proto = cpu_to_be16(new_len);
191bdcd8170SKalle Valo 
192bdcd8170SKalle Valo 	memcpy(datap, eth_hdr, sizeof(*eth_hdr));
193bdcd8170SKalle Valo 
194bdcd8170SKalle Valo 	llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
195bdcd8170SKalle Valo 	llc_hdr->dsap = 0xAA;
196bdcd8170SKalle Valo 	llc_hdr->ssap = 0xAA;
197bdcd8170SKalle Valo 	llc_hdr->cntl = 0x03;
198bdcd8170SKalle Valo 	llc_hdr->org_code[0] = 0x0;
199bdcd8170SKalle Valo 	llc_hdr->org_code[1] = 0x0;
200bdcd8170SKalle Valo 	llc_hdr->org_code[2] = 0x0;
201bdcd8170SKalle Valo 	llc_hdr->eth_type = type;
202bdcd8170SKalle Valo 
203bdcd8170SKalle Valo 	return 0;
204bdcd8170SKalle Valo }
205bdcd8170SKalle Valo 
206bdcd8170SKalle Valo static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
207bdcd8170SKalle Valo 			       u8 *version, void *tx_meta_info)
208bdcd8170SKalle Valo {
209bdcd8170SKalle Valo 	struct wmi_tx_meta_v1 *v1;
210bdcd8170SKalle Valo 	struct wmi_tx_meta_v2 *v2;
211bdcd8170SKalle Valo 
212bdcd8170SKalle Valo 	if (WARN_ON(skb == NULL || version == NULL))
213bdcd8170SKalle Valo 		return -EINVAL;
214bdcd8170SKalle Valo 
215bdcd8170SKalle Valo 	switch (*version) {
216bdcd8170SKalle Valo 	case WMI_META_VERSION_1:
217bdcd8170SKalle Valo 		skb_push(skb, WMI_MAX_TX_META_SZ);
218bdcd8170SKalle Valo 		v1 = (struct wmi_tx_meta_v1 *) skb->data;
219bdcd8170SKalle Valo 		v1->pkt_id = 0;
220bdcd8170SKalle Valo 		v1->rate_plcy_id = 0;
221bdcd8170SKalle Valo 		*version = WMI_META_VERSION_1;
222bdcd8170SKalle Valo 		break;
223bdcd8170SKalle Valo 	case WMI_META_VERSION_2:
224bdcd8170SKalle Valo 		skb_push(skb, WMI_MAX_TX_META_SZ);
225bdcd8170SKalle Valo 		v2 = (struct wmi_tx_meta_v2 *) skb->data;
226bdcd8170SKalle Valo 		memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
227bdcd8170SKalle Valo 		       sizeof(struct wmi_tx_meta_v2));
228bdcd8170SKalle Valo 		break;
229bdcd8170SKalle Valo 	}
230bdcd8170SKalle Valo 
231bdcd8170SKalle Valo 	return 0;
232bdcd8170SKalle Valo }
233bdcd8170SKalle Valo 
234bdcd8170SKalle Valo int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
235c1762a3fSThirumalai Pachamuthu 			    u8 msg_type, u32 flags,
236bdcd8170SKalle Valo 			    enum wmi_data_hdr_data_type data_type,
2376765d0aaSVasanthakumar Thiagarajan 			    u8 meta_ver, void *tx_meta_info, u8 if_idx)
238bdcd8170SKalle Valo {
239bdcd8170SKalle Valo 	struct wmi_data_hdr *data_hdr;
240bdcd8170SKalle Valo 	int ret;
241bdcd8170SKalle Valo 
24271f96ee6SKalle Valo 	if (WARN_ON(skb == NULL || (if_idx > wmi->parent_dev->vif_max - 1)))
243bdcd8170SKalle Valo 		return -EINVAL;
244bdcd8170SKalle Valo 
2453ce6ff50SVasanthakumar Thiagarajan 	if (tx_meta_info) {
246bdcd8170SKalle Valo 		ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
247bdcd8170SKalle Valo 		if (ret)
248bdcd8170SKalle Valo 			return ret;
2493ce6ff50SVasanthakumar Thiagarajan 	}
250bdcd8170SKalle Valo 
251bdcd8170SKalle Valo 	skb_push(skb, sizeof(struct wmi_data_hdr));
252bdcd8170SKalle Valo 
253bdcd8170SKalle Valo 	data_hdr = (struct wmi_data_hdr *)skb->data;
254bdcd8170SKalle Valo 	memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
255bdcd8170SKalle Valo 
256bdcd8170SKalle Valo 	data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
257bdcd8170SKalle Valo 	data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
258bdcd8170SKalle Valo 
259c1762a3fSThirumalai Pachamuthu 	if (flags & WMI_DATA_HDR_FLAGS_MORE)
260c1762a3fSThirumalai Pachamuthu 		data_hdr->info |= WMI_DATA_HDR_MORE;
261bdcd8170SKalle Valo 
262c1762a3fSThirumalai Pachamuthu 	if (flags & WMI_DATA_HDR_FLAGS_EOSP)
263c1762a3fSThirumalai Pachamuthu 		data_hdr->info3 |= cpu_to_le16(WMI_DATA_HDR_EOSP);
264c1762a3fSThirumalai Pachamuthu 
265c1762a3fSThirumalai Pachamuthu 	data_hdr->info2 |= cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
266c1762a3fSThirumalai Pachamuthu 	data_hdr->info3 |= cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
267bdcd8170SKalle Valo 
268bdcd8170SKalle Valo 	return 0;
269bdcd8170SKalle Valo }
270bdcd8170SKalle Valo 
271c1762a3fSThirumalai Pachamuthu u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
272bdcd8170SKalle Valo {
273bdcd8170SKalle Valo 	struct iphdr *ip_hdr = (struct iphdr *) pkt;
274bdcd8170SKalle Valo 	u8 ip_pri;
275bdcd8170SKalle Valo 
276bdcd8170SKalle Valo 	/*
277bdcd8170SKalle Valo 	 * Determine IPTOS priority
278bdcd8170SKalle Valo 	 *
279bdcd8170SKalle Valo 	 * IP-TOS - 8bits
280bdcd8170SKalle Valo 	 *          : DSCP(6-bits) ECN(2-bits)
281bdcd8170SKalle Valo 	 *          : DSCP - P2 P1 P0 X X X
282bdcd8170SKalle Valo 	 * where (P2 P1 P0) form 802.1D
283bdcd8170SKalle Valo 	 */
284bdcd8170SKalle Valo 	ip_pri = ip_hdr->tos >> 5;
285bdcd8170SKalle Valo 	ip_pri &= 0x7;
286bdcd8170SKalle Valo 
287bdcd8170SKalle Valo 	if ((layer2_pri & 0x7) > ip_pri)
288bdcd8170SKalle Valo 		return (u8) layer2_pri & 0x7;
289bdcd8170SKalle Valo 	else
290bdcd8170SKalle Valo 		return ip_pri;
291bdcd8170SKalle Valo }
292bdcd8170SKalle Valo 
293c1762a3fSThirumalai Pachamuthu u8 ath6kl_wmi_get_traffic_class(u8 user_priority)
294c1762a3fSThirumalai Pachamuthu {
295c1762a3fSThirumalai Pachamuthu 	return  up_to_ac[user_priority & 0x7];
296c1762a3fSThirumalai Pachamuthu }
297c1762a3fSThirumalai Pachamuthu 
298240d2799SVasanthakumar Thiagarajan int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, u8 if_idx,
299240d2799SVasanthakumar Thiagarajan 				       struct sk_buff *skb,
300bdcd8170SKalle Valo 				       u32 layer2_priority, bool wmm_enabled,
301bdcd8170SKalle Valo 				       u8 *ac)
302bdcd8170SKalle Valo {
303bdcd8170SKalle Valo 	struct wmi_data_hdr *data_hdr;
304bdcd8170SKalle Valo 	struct ath6kl_llc_snap_hdr *llc_hdr;
305bdcd8170SKalle Valo 	struct wmi_create_pstream_cmd cmd;
306bdcd8170SKalle Valo 	u32 meta_size, hdr_size;
307bdcd8170SKalle Valo 	u16 ip_type = IP_ETHERTYPE;
308bdcd8170SKalle Valo 	u8 stream_exist, usr_pri;
309bdcd8170SKalle Valo 	u8 traffic_class = WMM_AC_BE;
310bdcd8170SKalle Valo 	u8 *datap;
311bdcd8170SKalle Valo 
312bdcd8170SKalle Valo 	if (WARN_ON(skb == NULL))
313bdcd8170SKalle Valo 		return -EINVAL;
314bdcd8170SKalle Valo 
315bdcd8170SKalle Valo 	datap = skb->data;
316bdcd8170SKalle Valo 	data_hdr = (struct wmi_data_hdr *) datap;
317bdcd8170SKalle Valo 
318bdcd8170SKalle Valo 	meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
319bdcd8170SKalle Valo 		     WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
320bdcd8170SKalle Valo 
321bdcd8170SKalle Valo 	if (!wmm_enabled) {
322bdcd8170SKalle Valo 		/* If WMM is disabled all traffic goes as BE traffic */
323bdcd8170SKalle Valo 		usr_pri = 0;
324bdcd8170SKalle Valo 	} else {
325bdcd8170SKalle Valo 		hdr_size = sizeof(struct ethhdr);
326bdcd8170SKalle Valo 
327bdcd8170SKalle Valo 		llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
328bdcd8170SKalle Valo 							 sizeof(struct
329bdcd8170SKalle Valo 								wmi_data_hdr) +
330bdcd8170SKalle Valo 							 meta_size + hdr_size);
331bdcd8170SKalle Valo 
332bdcd8170SKalle Valo 		if (llc_hdr->eth_type == htons(ip_type)) {
333bdcd8170SKalle Valo 			/*
334bdcd8170SKalle Valo 			 * Extract the endpoint info from the TOS field
335bdcd8170SKalle Valo 			 * in the IP header.
336bdcd8170SKalle Valo 			 */
337bdcd8170SKalle Valo 			usr_pri =
338bdcd8170SKalle Valo 			   ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
339bdcd8170SKalle Valo 					sizeof(struct ath6kl_llc_snap_hdr),
340bdcd8170SKalle Valo 					layer2_priority);
341a5d8f9dfSKalle Valo 		} else {
342bdcd8170SKalle Valo 			usr_pri = layer2_priority & 0x7;
343a5d8f9dfSKalle Valo 		}
344f3740572SVivek Natarajan 
345f3740572SVivek Natarajan 		/*
346f3740572SVivek Natarajan 		 * Queue the EAPOL frames in the same WMM_AC_VO queue
347f3740572SVivek Natarajan 		 * as that of management frames.
348f3740572SVivek Natarajan 		 */
349f3740572SVivek Natarajan 		if (skb->protocol == cpu_to_be16(ETH_P_PAE))
350f3740572SVivek Natarajan 			usr_pri = WMI_VOICE_USER_PRIORITY;
351bdcd8170SKalle Valo 	}
352bdcd8170SKalle Valo 
353a7f0c58bSKalle Valo 	/*
354a7f0c58bSKalle Valo 	 * workaround for WMM S5
355a7f0c58bSKalle Valo 	 *
356a7f0c58bSKalle Valo 	 * FIXME: wmi->traffic_class is always 100 so this test doesn't
357a7f0c58bSKalle Valo 	 * make sense
358a7f0c58bSKalle Valo 	 */
359bdcd8170SKalle Valo 	if ((wmi->traffic_class == WMM_AC_VI) &&
360bdcd8170SKalle Valo 	    ((usr_pri == 5) || (usr_pri == 4)))
361bdcd8170SKalle Valo 		usr_pri = 1;
362bdcd8170SKalle Valo 
363bdcd8170SKalle Valo 	/* Convert user priority to traffic class */
364bdcd8170SKalle Valo 	traffic_class = up_to_ac[usr_pri & 0x7];
365bdcd8170SKalle Valo 
366bdcd8170SKalle Valo 	wmi_data_hdr_set_up(data_hdr, usr_pri);
367bdcd8170SKalle Valo 
368bdcd8170SKalle Valo 	spin_lock_bh(&wmi->lock);
369bdcd8170SKalle Valo 	stream_exist = wmi->fat_pipe_exist;
370bdcd8170SKalle Valo 	spin_unlock_bh(&wmi->lock);
371bdcd8170SKalle Valo 
372bdcd8170SKalle Valo 	if (!(stream_exist & (1 << traffic_class))) {
373bdcd8170SKalle Valo 		memset(&cmd, 0, sizeof(cmd));
374bdcd8170SKalle Valo 		cmd.traffic_class = traffic_class;
375bdcd8170SKalle Valo 		cmd.user_pri = usr_pri;
376bdcd8170SKalle Valo 		cmd.inactivity_int =
377bdcd8170SKalle Valo 			cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
378bdcd8170SKalle Valo 		/* Implicit streams are created with TSID 0xFF */
379bdcd8170SKalle Valo 		cmd.tsid = WMI_IMPLICIT_PSTREAM;
380240d2799SVasanthakumar Thiagarajan 		ath6kl_wmi_create_pstream_cmd(wmi, if_idx, &cmd);
381bdcd8170SKalle Valo 	}
382bdcd8170SKalle Valo 
383bdcd8170SKalle Valo 	*ac = traffic_class;
384bdcd8170SKalle Valo 
385bdcd8170SKalle Valo 	return 0;
386bdcd8170SKalle Valo }
387bdcd8170SKalle Valo 
388bdcd8170SKalle Valo int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
389bdcd8170SKalle Valo {
390bdcd8170SKalle Valo 	struct ieee80211_hdr_3addr *pwh, wh;
391bdcd8170SKalle Valo 	struct ath6kl_llc_snap_hdr *llc_hdr;
392bdcd8170SKalle Valo 	struct ethhdr eth_hdr;
393bdcd8170SKalle Valo 	u32 hdr_size;
394bdcd8170SKalle Valo 	u8 *datap;
395bdcd8170SKalle Valo 	__le16 sub_type;
396bdcd8170SKalle Valo 
397bdcd8170SKalle Valo 	if (WARN_ON(skb == NULL))
398bdcd8170SKalle Valo 		return -EINVAL;
399bdcd8170SKalle Valo 
400bdcd8170SKalle Valo 	datap = skb->data;
401bdcd8170SKalle Valo 	pwh = (struct ieee80211_hdr_3addr *) datap;
402bdcd8170SKalle Valo 
403bdcd8170SKalle Valo 	sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
404bdcd8170SKalle Valo 
405bdcd8170SKalle Valo 	memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
406bdcd8170SKalle Valo 
407bdcd8170SKalle Valo 	/* Strip off the 802.11 header */
408bdcd8170SKalle Valo 	if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
409bdcd8170SKalle Valo 		hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
410bdcd8170SKalle Valo 				   sizeof(u32));
411bdcd8170SKalle Valo 		skb_pull(skb, hdr_size);
412a5d8f9dfSKalle Valo 	} else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA)) {
413bdcd8170SKalle Valo 		skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
414a5d8f9dfSKalle Valo 	}
415bdcd8170SKalle Valo 
416bdcd8170SKalle Valo 	datap = skb->data;
417bdcd8170SKalle Valo 	llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
418bdcd8170SKalle Valo 
419c8790cbaSRaja Mani 	memset(&eth_hdr, 0, sizeof(eth_hdr));
420bdcd8170SKalle Valo 	eth_hdr.h_proto = llc_hdr->eth_type;
421bdcd8170SKalle Valo 
422bdcd8170SKalle Valo 	switch ((le16_to_cpu(wh.frame_control)) &
423bdcd8170SKalle Valo 		(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
424bdcd8170SKalle Valo 	case IEEE80211_FCTL_TODS:
425bdcd8170SKalle Valo 		memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
426bdcd8170SKalle Valo 		memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
427bdcd8170SKalle Valo 		break;
428bdcd8170SKalle Valo 	case IEEE80211_FCTL_FROMDS:
429bdcd8170SKalle Valo 		memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
430bdcd8170SKalle Valo 		memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
431bdcd8170SKalle Valo 		break;
432bdcd8170SKalle Valo 	case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
433bdcd8170SKalle Valo 		break;
43410f3366bSArnd Bergmann 	default:
43510f3366bSArnd Bergmann 		memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
43610f3366bSArnd Bergmann 		memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
43710f3366bSArnd Bergmann 		break;
438bdcd8170SKalle Valo 	}
439bdcd8170SKalle Valo 
440bdcd8170SKalle Valo 	skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
441bdcd8170SKalle Valo 	skb_push(skb, sizeof(eth_hdr));
442bdcd8170SKalle Valo 
443bdcd8170SKalle Valo 	datap = skb->data;
444bdcd8170SKalle Valo 
445bdcd8170SKalle Valo 	memcpy(datap, &eth_hdr, sizeof(eth_hdr));
446bdcd8170SKalle Valo 
447bdcd8170SKalle Valo 	return 0;
448bdcd8170SKalle Valo }
449bdcd8170SKalle Valo 
450bdcd8170SKalle Valo /*
451bdcd8170SKalle Valo  * Performs 802.3 to DIX encapsulation for received packets.
452e1c05067SMasahiro Yamada  * Assumes the entire 802.3 header is contiguous.
453bdcd8170SKalle Valo  */
454bdcd8170SKalle Valo int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
455bdcd8170SKalle Valo {
456bdcd8170SKalle Valo 	struct ath6kl_llc_snap_hdr *llc_hdr;
457bdcd8170SKalle Valo 	struct ethhdr eth_hdr;
458bdcd8170SKalle Valo 	u8 *datap;
459bdcd8170SKalle Valo 
460bdcd8170SKalle Valo 	if (WARN_ON(skb == NULL))
461bdcd8170SKalle Valo 		return -EINVAL;
462bdcd8170SKalle Valo 
463bdcd8170SKalle Valo 	datap = skb->data;
464bdcd8170SKalle Valo 
465bdcd8170SKalle Valo 	memcpy(&eth_hdr, datap, sizeof(eth_hdr));
466bdcd8170SKalle Valo 
467bdcd8170SKalle Valo 	llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
468bdcd8170SKalle Valo 	eth_hdr.h_proto = llc_hdr->eth_type;
469bdcd8170SKalle Valo 
470bdcd8170SKalle Valo 	skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
471bdcd8170SKalle Valo 	datap = skb->data;
472bdcd8170SKalle Valo 
473bdcd8170SKalle Valo 	memcpy(datap, &eth_hdr, sizeof(eth_hdr));
474bdcd8170SKalle Valo 
475bdcd8170SKalle Valo 	return 0;
476bdcd8170SKalle Valo }
477bdcd8170SKalle Valo 
478bdcd8170SKalle Valo static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
479bdcd8170SKalle Valo {
480bdcd8170SKalle Valo 	struct tx_complete_msg_v1 *msg_v1;
481bdcd8170SKalle Valo 	struct wmi_tx_complete_event *evt;
482bdcd8170SKalle Valo 	int index;
483bdcd8170SKalle Valo 	u16 size;
484bdcd8170SKalle Valo 
485bdcd8170SKalle Valo 	evt = (struct wmi_tx_complete_event *) datap;
486bdcd8170SKalle Valo 
487bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
488bdcd8170SKalle Valo 		   evt->num_msg, evt->msg_len, evt->msg_type);
489bdcd8170SKalle Valo 
490bdcd8170SKalle Valo 	for (index = 0; index < evt->num_msg; index++) {
491bdcd8170SKalle Valo 		size = sizeof(struct wmi_tx_complete_event) +
492bdcd8170SKalle Valo 		    (index * sizeof(struct tx_complete_msg_v1));
493bdcd8170SKalle Valo 		msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
494bdcd8170SKalle Valo 
495bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
496bdcd8170SKalle Valo 			   msg_v1->status, msg_v1->pkt_id,
497bdcd8170SKalle Valo 			   msg_v1->rate_idx, msg_v1->ack_failures);
498bdcd8170SKalle Valo 	}
499bdcd8170SKalle Valo 
500bdcd8170SKalle Valo 	return 0;
501bdcd8170SKalle Valo }
502bdcd8170SKalle Valo 
503f9e5f05cSJouni Malinen static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
504240d2799SVasanthakumar Thiagarajan 					      int len, struct ath6kl_vif *vif)
5056465ddcfSJouni Malinen {
5066465ddcfSJouni Malinen 	struct wmi_remain_on_chnl_event *ev;
5076465ddcfSJouni Malinen 	u32 freq;
5086465ddcfSJouni Malinen 	u32 dur;
509f9e5f05cSJouni Malinen 	struct ieee80211_channel *chan;
510f9e5f05cSJouni Malinen 	struct ath6kl *ar = wmi->parent_dev;
5111052261eSJouni Malinen 	u32 id;
5126465ddcfSJouni Malinen 
5136465ddcfSJouni Malinen 	if (len < sizeof(*ev))
5146465ddcfSJouni Malinen 		return -EINVAL;
5156465ddcfSJouni Malinen 
5166465ddcfSJouni Malinen 	ev = (struct wmi_remain_on_chnl_event *) datap;
5176465ddcfSJouni Malinen 	freq = le32_to_cpu(ev->freq);
5186465ddcfSJouni Malinen 	dur = le32_to_cpu(ev->duration);
5196465ddcfSJouni Malinen 	ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
5206465ddcfSJouni Malinen 		   freq, dur);
521be98e3a4SVasanthakumar Thiagarajan 	chan = ieee80211_get_channel(ar->wiphy, freq);
522f9e5f05cSJouni Malinen 	if (!chan) {
523cdeb8602SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI,
524cdeb8602SKalle Valo 			   "remain_on_chnl: Unknown channel (freq=%u)\n",
525cdeb8602SKalle Valo 			   freq);
526f9e5f05cSJouni Malinen 		return -EINVAL;
527f9e5f05cSJouni Malinen 	}
5281052261eSJouni Malinen 	id = vif->last_roc_id;
52942d97a59SJohannes Berg 	cfg80211_ready_on_channel(&vif->wdev, id, chan,
530f9e5f05cSJouni Malinen 				  dur, GFP_ATOMIC);
5316465ddcfSJouni Malinen 
5326465ddcfSJouni Malinen 	return 0;
5336465ddcfSJouni Malinen }
5346465ddcfSJouni Malinen 
535f9e5f05cSJouni Malinen static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
536240d2799SVasanthakumar Thiagarajan 						     u8 *datap, int len,
537240d2799SVasanthakumar Thiagarajan 						     struct ath6kl_vif *vif)
5386465ddcfSJouni Malinen {
5396465ddcfSJouni Malinen 	struct wmi_cancel_remain_on_chnl_event *ev;
5406465ddcfSJouni Malinen 	u32 freq;
5416465ddcfSJouni Malinen 	u32 dur;
542f9e5f05cSJouni Malinen 	struct ieee80211_channel *chan;
543f9e5f05cSJouni Malinen 	struct ath6kl *ar = wmi->parent_dev;
5441052261eSJouni Malinen 	u32 id;
5456465ddcfSJouni Malinen 
5466465ddcfSJouni Malinen 	if (len < sizeof(*ev))
5476465ddcfSJouni Malinen 		return -EINVAL;
5486465ddcfSJouni Malinen 
5496465ddcfSJouni Malinen 	ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
5506465ddcfSJouni Malinen 	freq = le32_to_cpu(ev->freq);
5516465ddcfSJouni Malinen 	dur = le32_to_cpu(ev->duration);
552cdeb8602SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
553cdeb8602SKalle Valo 		   "cancel_remain_on_chnl: freq=%u dur=%u status=%u\n",
554cdeb8602SKalle Valo 		   freq, dur, ev->status);
555be98e3a4SVasanthakumar Thiagarajan 	chan = ieee80211_get_channel(ar->wiphy, freq);
556f9e5f05cSJouni Malinen 	if (!chan) {
557cdeb8602SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI,
558cdeb8602SKalle Valo 			   "cancel_remain_on_chnl: Unknown channel (freq=%u)\n",
559cdeb8602SKalle Valo 			   freq);
560f9e5f05cSJouni Malinen 		return -EINVAL;
561f9e5f05cSJouni Malinen 	}
5621052261eSJouni Malinen 	if (vif->last_cancel_roc_id &&
5631052261eSJouni Malinen 	    vif->last_cancel_roc_id + 1 == vif->last_roc_id)
5641052261eSJouni Malinen 		id = vif->last_cancel_roc_id; /* event for cancel command */
5651052261eSJouni Malinen 	else
5661052261eSJouni Malinen 		id = vif->last_roc_id; /* timeout on uncanceled r-o-c */
5671052261eSJouni Malinen 	vif->last_cancel_roc_id = 0;
56842d97a59SJohannes Berg 	cfg80211_remain_on_channel_expired(&vif->wdev, id, chan, GFP_ATOMIC);
5696465ddcfSJouni Malinen 
5706465ddcfSJouni Malinen 	return 0;
5716465ddcfSJouni Malinen }
5726465ddcfSJouni Malinen 
573240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len,
574240d2799SVasanthakumar Thiagarajan 					 struct ath6kl_vif *vif)
5756465ddcfSJouni Malinen {
5766465ddcfSJouni Malinen 	struct wmi_tx_status_event *ev;
5776465ddcfSJouni Malinen 	u32 id;
5786465ddcfSJouni Malinen 
5796465ddcfSJouni Malinen 	if (len < sizeof(*ev))
5806465ddcfSJouni Malinen 		return -EINVAL;
5816465ddcfSJouni Malinen 
5826465ddcfSJouni Malinen 	ev = (struct wmi_tx_status_event *) datap;
5836465ddcfSJouni Malinen 	id = le32_to_cpu(ev->id);
5846465ddcfSJouni Malinen 	ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
5856465ddcfSJouni Malinen 		   id, ev->ack_status);
586a0df5db1SJouni Malinen 	if (wmi->last_mgmt_tx_frame) {
58771bbc994SJohannes Berg 		cfg80211_mgmt_tx_status(&vif->wdev, id,
588a0df5db1SJouni Malinen 					wmi->last_mgmt_tx_frame,
589a0df5db1SJouni Malinen 					wmi->last_mgmt_tx_frame_len,
590a0df5db1SJouni Malinen 					!!ev->ack_status, GFP_ATOMIC);
591a0df5db1SJouni Malinen 		kfree(wmi->last_mgmt_tx_frame);
592a0df5db1SJouni Malinen 		wmi->last_mgmt_tx_frame = NULL;
593a0df5db1SJouni Malinen 		wmi->last_mgmt_tx_frame_len = 0;
594a0df5db1SJouni Malinen 	}
5956465ddcfSJouni Malinen 
5966465ddcfSJouni Malinen 	return 0;
5976465ddcfSJouni Malinen }
5986465ddcfSJouni Malinen 
599240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len,
600240d2799SVasanthakumar Thiagarajan 					    struct ath6kl_vif *vif)
6016465ddcfSJouni Malinen {
6026465ddcfSJouni Malinen 	struct wmi_p2p_rx_probe_req_event *ev;
603ae32c30aSJouni Malinen 	u32 freq;
6046465ddcfSJouni Malinen 	u16 dlen;
6056465ddcfSJouni Malinen 
6066465ddcfSJouni Malinen 	if (len < sizeof(*ev))
6076465ddcfSJouni Malinen 		return -EINVAL;
6086465ddcfSJouni Malinen 
6096465ddcfSJouni Malinen 	ev = (struct wmi_p2p_rx_probe_req_event *) datap;
610ae32c30aSJouni Malinen 	freq = le32_to_cpu(ev->freq);
6116465ddcfSJouni Malinen 	dlen = le16_to_cpu(ev->len);
612ae32c30aSJouni Malinen 	if (datap + len < ev->data + dlen) {
613cdeb8602SKalle Valo 		ath6kl_err("invalid wmi_p2p_rx_probe_req_event: len=%d dlen=%u\n",
614cdeb8602SKalle Valo 			   len, dlen);
615ae32c30aSJouni Malinen 		return -EINVAL;
616ae32c30aSJouni Malinen 	}
617cdeb8602SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
618cdeb8602SKalle Valo 		   "rx_probe_req: len=%u freq=%u probe_req_report=%d\n",
619cf5333d7SVasanthakumar Thiagarajan 		   dlen, freq, vif->probe_req_report);
620ae32c30aSJouni Malinen 
621cf5333d7SVasanthakumar Thiagarajan 	if (vif->probe_req_report || vif->nw_type == AP_NETWORK)
622970fdfa8SVladimir Kondratiev 		cfg80211_rx_mgmt(&vif->wdev, freq, 0, ev->data, dlen, 0);
6236465ddcfSJouni Malinen 
6246465ddcfSJouni Malinen 	return 0;
6256465ddcfSJouni Malinen }
6266465ddcfSJouni Malinen 
6276465ddcfSJouni Malinen static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
6286465ddcfSJouni Malinen {
6296465ddcfSJouni Malinen 	struct wmi_p2p_capabilities_event *ev;
6306465ddcfSJouni Malinen 	u16 dlen;
6316465ddcfSJouni Malinen 
6326465ddcfSJouni Malinen 	if (len < sizeof(*ev))
6336465ddcfSJouni Malinen 		return -EINVAL;
6346465ddcfSJouni Malinen 
6356465ddcfSJouni Malinen 	ev = (struct wmi_p2p_capabilities_event *) datap;
6366465ddcfSJouni Malinen 	dlen = le16_to_cpu(ev->len);
6376465ddcfSJouni Malinen 	ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
6386465ddcfSJouni Malinen 
6396465ddcfSJouni Malinen 	return 0;
6406465ddcfSJouni Malinen }
6416465ddcfSJouni Malinen 
642240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len,
643240d2799SVasanthakumar Thiagarajan 					 struct ath6kl_vif *vif)
6446465ddcfSJouni Malinen {
6456465ddcfSJouni Malinen 	struct wmi_rx_action_event *ev;
6469809d8efSJouni Malinen 	u32 freq;
6476465ddcfSJouni Malinen 	u16 dlen;
6486465ddcfSJouni Malinen 
6496465ddcfSJouni Malinen 	if (len < sizeof(*ev))
6506465ddcfSJouni Malinen 		return -EINVAL;
6516465ddcfSJouni Malinen 
6526465ddcfSJouni Malinen 	ev = (struct wmi_rx_action_event *) datap;
6539809d8efSJouni Malinen 	freq = le32_to_cpu(ev->freq);
6546465ddcfSJouni Malinen 	dlen = le16_to_cpu(ev->len);
6559809d8efSJouni Malinen 	if (datap + len < ev->data + dlen) {
656cdeb8602SKalle Valo 		ath6kl_err("invalid wmi_rx_action_event: len=%d dlen=%u\n",
657cdeb8602SKalle Valo 			   len, dlen);
6589809d8efSJouni Malinen 		return -EINVAL;
6599809d8efSJouni Malinen 	}
6609809d8efSJouni Malinen 	ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
661970fdfa8SVladimir Kondratiev 	cfg80211_rx_mgmt(&vif->wdev, freq, 0, ev->data, dlen, 0);
6626465ddcfSJouni Malinen 
6636465ddcfSJouni Malinen 	return 0;
6646465ddcfSJouni Malinen }
6656465ddcfSJouni Malinen 
6666465ddcfSJouni Malinen static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
6676465ddcfSJouni Malinen {
6686465ddcfSJouni Malinen 	struct wmi_p2p_info_event *ev;
6696465ddcfSJouni Malinen 	u32 flags;
6706465ddcfSJouni Malinen 	u16 dlen;
6716465ddcfSJouni Malinen 
6726465ddcfSJouni Malinen 	if (len < sizeof(*ev))
6736465ddcfSJouni Malinen 		return -EINVAL;
6746465ddcfSJouni Malinen 
6756465ddcfSJouni Malinen 	ev = (struct wmi_p2p_info_event *) datap;
6766465ddcfSJouni Malinen 	flags = le32_to_cpu(ev->info_req_flags);
6776465ddcfSJouni Malinen 	dlen = le16_to_cpu(ev->len);
6786465ddcfSJouni Malinen 	ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
6796465ddcfSJouni Malinen 
6806465ddcfSJouni Malinen 	if (flags & P2P_FLAG_CAPABILITIES_REQ) {
6816465ddcfSJouni Malinen 		struct wmi_p2p_capabilities *cap;
6826465ddcfSJouni Malinen 		if (dlen < sizeof(*cap))
6836465ddcfSJouni Malinen 			return -EINVAL;
6846465ddcfSJouni Malinen 		cap = (struct wmi_p2p_capabilities *) ev->data;
6856465ddcfSJouni Malinen 		ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
6866465ddcfSJouni Malinen 			   cap->go_power_save);
6876465ddcfSJouni Malinen 	}
6886465ddcfSJouni Malinen 
6896465ddcfSJouni Malinen 	if (flags & P2P_FLAG_MACADDR_REQ) {
6906465ddcfSJouni Malinen 		struct wmi_p2p_macaddr *mac;
6916465ddcfSJouni Malinen 		if (dlen < sizeof(*mac))
6926465ddcfSJouni Malinen 			return -EINVAL;
6936465ddcfSJouni Malinen 		mac = (struct wmi_p2p_macaddr *) ev->data;
6946465ddcfSJouni Malinen 		ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
6956465ddcfSJouni Malinen 			   mac->mac_addr);
6966465ddcfSJouni Malinen 	}
6976465ddcfSJouni Malinen 
6986465ddcfSJouni Malinen 	if (flags & P2P_FLAG_HMODEL_REQ) {
6996465ddcfSJouni Malinen 		struct wmi_p2p_hmodel *mod;
7006465ddcfSJouni Malinen 		if (dlen < sizeof(*mod))
7016465ddcfSJouni Malinen 			return -EINVAL;
7026465ddcfSJouni Malinen 		mod = (struct wmi_p2p_hmodel *) ev->data;
7036465ddcfSJouni Malinen 		ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
7046465ddcfSJouni Malinen 			   mod->p2p_model,
7056465ddcfSJouni Malinen 			   mod->p2p_model ? "host" : "firmware");
7066465ddcfSJouni Malinen 	}
7076465ddcfSJouni Malinen 	return 0;
7086465ddcfSJouni Malinen }
7096465ddcfSJouni Malinen 
710bdcd8170SKalle Valo static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
711bdcd8170SKalle Valo {
712bdcd8170SKalle Valo 	struct sk_buff *skb;
713bdcd8170SKalle Valo 
714bdcd8170SKalle Valo 	skb = ath6kl_buf_alloc(size);
715bdcd8170SKalle Valo 	if (!skb)
716bdcd8170SKalle Valo 		return NULL;
717bdcd8170SKalle Valo 
718bdcd8170SKalle Valo 	skb_put(skb, size);
719bdcd8170SKalle Valo 	if (size)
720bdcd8170SKalle Valo 		memset(skb->data, 0, size);
721bdcd8170SKalle Valo 
722bdcd8170SKalle Valo 	return skb;
723bdcd8170SKalle Valo }
724bdcd8170SKalle Valo 
725bdcd8170SKalle Valo /* Send a "simple" wmi command -- one with no arguments */
726334234b5SVasanthakumar Thiagarajan static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx,
727334234b5SVasanthakumar Thiagarajan 				 enum wmi_cmd_id cmd_id)
728bdcd8170SKalle Valo {
729bdcd8170SKalle Valo 	struct sk_buff *skb;
730bdcd8170SKalle Valo 	int ret;
731bdcd8170SKalle Valo 
732bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(0);
733bdcd8170SKalle Valo 	if (!skb)
734bdcd8170SKalle Valo 		return -ENOMEM;
735bdcd8170SKalle Valo 
736334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
737bdcd8170SKalle Valo 
738bdcd8170SKalle Valo 	return ret;
739bdcd8170SKalle Valo }
740bdcd8170SKalle Valo 
741bdcd8170SKalle Valo static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
742bdcd8170SKalle Valo {
743bdcd8170SKalle Valo 	struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
744bdcd8170SKalle Valo 
745bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_ready_event_2))
746bdcd8170SKalle Valo 		return -EINVAL;
747bdcd8170SKalle Valo 
748bdcd8170SKalle Valo 	ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
749bdcd8170SKalle Valo 			   le32_to_cpu(ev->sw_version),
750d92917e4SThomas Pedersen 			   le32_to_cpu(ev->abi_version), ev->phy_cap);
751bdcd8170SKalle Valo 
752bdcd8170SKalle Valo 	return 0;
753bdcd8170SKalle Valo }
754bdcd8170SKalle Valo 
755e5090444SVivek Natarajan /*
756e5090444SVivek Natarajan  * Mechanism to modify the roaming behavior in the firmware. The lower rssi
757e5090444SVivek Natarajan  * at which the station has to roam can be passed with
758e5090444SVivek Natarajan  * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
759e5090444SVivek Natarajan  * in dBm.
760e5090444SVivek Natarajan  */
761e5090444SVivek Natarajan int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
762e5090444SVivek Natarajan {
763e5090444SVivek Natarajan 	struct sk_buff *skb;
764e5090444SVivek Natarajan 	struct roam_ctrl_cmd *cmd;
765e5090444SVivek Natarajan 
766e5090444SVivek Natarajan 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
767e5090444SVivek Natarajan 	if (!skb)
768e5090444SVivek Natarajan 		return -ENOMEM;
769e5090444SVivek Natarajan 
770e5090444SVivek Natarajan 	cmd = (struct roam_ctrl_cmd *) skb->data;
771e5090444SVivek Natarajan 
772e5090444SVivek Natarajan 	cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
773e5090444SVivek Natarajan 	cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
774e5090444SVivek Natarajan 						       DEF_SCAN_FOR_ROAM_INTVL);
775e5090444SVivek Natarajan 	cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
776e5090444SVivek Natarajan 	cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
777e5090444SVivek Natarajan 	cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
778e5090444SVivek Natarajan 
779fc6a6521SKangjie Lu 	return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
780334234b5SVasanthakumar Thiagarajan 			    NO_SYNC_WMIFLAG);
781e5090444SVivek Natarajan }
782e5090444SVivek Natarajan 
7831261875fSJouni Malinen int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
7841261875fSJouni Malinen {
7851261875fSJouni Malinen 	struct sk_buff *skb;
7861261875fSJouni Malinen 	struct roam_ctrl_cmd *cmd;
7871261875fSJouni Malinen 
7881261875fSJouni Malinen 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
7891261875fSJouni Malinen 	if (!skb)
7901261875fSJouni Malinen 		return -ENOMEM;
7911261875fSJouni Malinen 
7921261875fSJouni Malinen 	cmd = (struct roam_ctrl_cmd *) skb->data;
7931261875fSJouni Malinen 
7941261875fSJouni Malinen 	memcpy(cmd->info.bssid, bssid, ETH_ALEN);
7951261875fSJouni Malinen 	cmd->roam_ctrl = WMI_FORCE_ROAM;
7961261875fSJouni Malinen 
7971261875fSJouni Malinen 	ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
798334234b5SVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
7991261875fSJouni Malinen 				   NO_SYNC_WMIFLAG);
8001261875fSJouni Malinen }
8011261875fSJouni Malinen 
802eb922e4bSMohammed Shafi Shajakhan int ath6kl_wmi_ap_set_beacon_intvl_cmd(struct wmi *wmi, u8 if_idx,
803eb922e4bSMohammed Shafi Shajakhan 				       u32 beacon_intvl)
804eb922e4bSMohammed Shafi Shajakhan {
805eb922e4bSMohammed Shafi Shajakhan 	struct sk_buff *skb;
806eb922e4bSMohammed Shafi Shajakhan 	struct set_beacon_int_cmd *cmd;
807eb922e4bSMohammed Shafi Shajakhan 
808eb922e4bSMohammed Shafi Shajakhan 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
809eb922e4bSMohammed Shafi Shajakhan 	if (!skb)
810eb922e4bSMohammed Shafi Shajakhan 		return -ENOMEM;
811eb922e4bSMohammed Shafi Shajakhan 
812eb922e4bSMohammed Shafi Shajakhan 	cmd = (struct set_beacon_int_cmd *) skb->data;
813eb922e4bSMohammed Shafi Shajakhan 
814eb922e4bSMohammed Shafi Shajakhan 	cmd->beacon_intvl = cpu_to_le32(beacon_intvl);
815eb922e4bSMohammed Shafi Shajakhan 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
816eb922e4bSMohammed Shafi Shajakhan 				   WMI_SET_BEACON_INT_CMDID, NO_SYNC_WMIFLAG);
817eb922e4bSMohammed Shafi Shajakhan }
818eb922e4bSMohammed Shafi Shajakhan 
819d154f32eSEtay Luz int ath6kl_wmi_ap_set_dtim_cmd(struct wmi *wmi, u8 if_idx, u32 dtim_period)
820d154f32eSEtay Luz {
821d154f32eSEtay Luz 	struct sk_buff *skb;
822d154f32eSEtay Luz 	struct set_dtim_cmd *cmd;
823d154f32eSEtay Luz 
824d154f32eSEtay Luz 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
825d154f32eSEtay Luz 	if (!skb)
826d154f32eSEtay Luz 		return -ENOMEM;
827d154f32eSEtay Luz 
828d154f32eSEtay Luz 	cmd = (struct set_dtim_cmd *) skb->data;
829d154f32eSEtay Luz 
830d154f32eSEtay Luz 	cmd->dtim_period = cpu_to_le32(dtim_period);
831d154f32eSEtay Luz 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
832d154f32eSEtay Luz 				   WMI_AP_SET_DTIM_CMDID, NO_SYNC_WMIFLAG);
833d154f32eSEtay Luz }
834d154f32eSEtay Luz 
8351261875fSJouni Malinen int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
8361261875fSJouni Malinen {
8371261875fSJouni Malinen 	struct sk_buff *skb;
8381261875fSJouni Malinen 	struct roam_ctrl_cmd *cmd;
8391261875fSJouni Malinen 
8401261875fSJouni Malinen 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
8411261875fSJouni Malinen 	if (!skb)
8421261875fSJouni Malinen 		return -ENOMEM;
8431261875fSJouni Malinen 
8441261875fSJouni Malinen 	cmd = (struct roam_ctrl_cmd *) skb->data;
8451261875fSJouni Malinen 
8461261875fSJouni Malinen 	cmd->info.roam_mode = mode;
8471261875fSJouni Malinen 	cmd->roam_ctrl = WMI_SET_ROAM_MODE;
8481261875fSJouni Malinen 
8491261875fSJouni Malinen 	ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
850334234b5SVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
8511261875fSJouni Malinen 				   NO_SYNC_WMIFLAG);
8521261875fSJouni Malinen }
8531261875fSJouni Malinen 
854240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len,
855240d2799SVasanthakumar Thiagarajan 				       struct ath6kl_vif *vif)
856bdcd8170SKalle Valo {
857bdcd8170SKalle Valo 	struct wmi_connect_event *ev;
858bdcd8170SKalle Valo 	u8 *pie, *peie;
859bdcd8170SKalle Valo 
860bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_connect_event))
861bdcd8170SKalle Valo 		return -EINVAL;
862bdcd8170SKalle Valo 
863bdcd8170SKalle Valo 	ev = (struct wmi_connect_event *) datap;
864bdcd8170SKalle Valo 
865f5938f24SVasanthakumar Thiagarajan 	if (vif->nw_type == AP_NETWORK) {
866572e27c0SJouni Malinen 		/* AP mode start/STA connected event */
867240d2799SVasanthakumar Thiagarajan 		struct net_device *dev = vif->ndev;
868572e27c0SJouni Malinen 		if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
869cdeb8602SKalle Valo 			ath6kl_dbg(ATH6KL_DBG_WMI,
870cdeb8602SKalle Valo 				   "%s: freq %d bssid %pM (AP started)\n",
871572e27c0SJouni Malinen 				   __func__, le16_to_cpu(ev->u.ap_bss.ch),
872572e27c0SJouni Malinen 				   ev->u.ap_bss.bssid);
873572e27c0SJouni Malinen 			ath6kl_connect_ap_mode_bss(
874240d2799SVasanthakumar Thiagarajan 				vif, le16_to_cpu(ev->u.ap_bss.ch));
875572e27c0SJouni Malinen 		} else {
876cdeb8602SKalle Valo 			ath6kl_dbg(ATH6KL_DBG_WMI,
877cdeb8602SKalle Valo 				   "%s: aid %u mac_addr %pM auth=%u keymgmt=%u cipher=%u apsd_info=%u (STA connected)\n",
878572e27c0SJouni Malinen 				   __func__, ev->u.ap_sta.aid,
879572e27c0SJouni Malinen 				   ev->u.ap_sta.mac_addr,
880572e27c0SJouni Malinen 				   ev->u.ap_sta.auth,
881572e27c0SJouni Malinen 				   ev->u.ap_sta.keymgmt,
882572e27c0SJouni Malinen 				   le16_to_cpu(ev->u.ap_sta.cipher),
883572e27c0SJouni Malinen 				   ev->u.ap_sta.apsd_info);
884c1762a3fSThirumalai Pachamuthu 
885572e27c0SJouni Malinen 			ath6kl_connect_ap_mode_sta(
886240d2799SVasanthakumar Thiagarajan 				vif, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
887572e27c0SJouni Malinen 				ev->u.ap_sta.keymgmt,
888572e27c0SJouni Malinen 				le16_to_cpu(ev->u.ap_sta.cipher),
889572e27c0SJouni Malinen 				ev->u.ap_sta.auth, ev->assoc_req_len,
890c1762a3fSThirumalai Pachamuthu 				ev->assoc_info + ev->beacon_ie_len,
891c1762a3fSThirumalai Pachamuthu 				ev->u.ap_sta.apsd_info);
892572e27c0SJouni Malinen 		}
893572e27c0SJouni Malinen 		return 0;
894572e27c0SJouni Malinen 	}
895572e27c0SJouni Malinen 
896572e27c0SJouni Malinen 	/* STA/IBSS mode connection event */
897572e27c0SJouni Malinen 
898b9b6ee60SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
899b9b6ee60SKalle Valo 		   "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
900b9b6ee60SKalle Valo 		   le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
901b9b6ee60SKalle Valo 		   le16_to_cpu(ev->u.sta.listen_intvl),
902b9b6ee60SKalle Valo 		   le16_to_cpu(ev->u.sta.beacon_intvl),
903b9b6ee60SKalle Valo 		   le32_to_cpu(ev->u.sta.nw_type));
904bdcd8170SKalle Valo 
905bdcd8170SKalle Valo 	/* Start of assoc rsp IEs */
906bdcd8170SKalle Valo 	pie = ev->assoc_info + ev->beacon_ie_len +
907bdcd8170SKalle Valo 	      ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
908bdcd8170SKalle Valo 
909bdcd8170SKalle Valo 	/* End of assoc rsp IEs */
910bdcd8170SKalle Valo 	peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
911bdcd8170SKalle Valo 	    ev->assoc_resp_len;
912bdcd8170SKalle Valo 
913bdcd8170SKalle Valo 	while (pie < peie) {
914bdcd8170SKalle Valo 		switch (*pie) {
915bdcd8170SKalle Valo 		case WLAN_EID_VENDOR_SPECIFIC:
916bdcd8170SKalle Valo 			if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
917bdcd8170SKalle Valo 			    pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
918bdcd8170SKalle Valo 				/* WMM OUT (00:50:F2) */
919ddc3d77cSKalle Valo 				if (pie[1] > 5 &&
920ddc3d77cSKalle Valo 				    pie[6] == WMM_PARAM_OUI_SUBTYPE)
921bdcd8170SKalle Valo 					wmi->is_wmm_enabled = true;
922bdcd8170SKalle Valo 			}
923bdcd8170SKalle Valo 			break;
924bdcd8170SKalle Valo 		}
925bdcd8170SKalle Valo 
926bdcd8170SKalle Valo 		if (wmi->is_wmm_enabled)
927bdcd8170SKalle Valo 			break;
928bdcd8170SKalle Valo 
929bdcd8170SKalle Valo 		pie += pie[1] + 2;
930bdcd8170SKalle Valo 	}
931bdcd8170SKalle Valo 
932240d2799SVasanthakumar Thiagarajan 	ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch),
933572e27c0SJouni Malinen 			     ev->u.sta.bssid,
934572e27c0SJouni Malinen 			     le16_to_cpu(ev->u.sta.listen_intvl),
935572e27c0SJouni Malinen 			     le16_to_cpu(ev->u.sta.beacon_intvl),
936572e27c0SJouni Malinen 			     le32_to_cpu(ev->u.sta.nw_type),
937bdcd8170SKalle Valo 			     ev->beacon_ie_len, ev->assoc_req_len,
938bdcd8170SKalle Valo 			     ev->assoc_resp_len, ev->assoc_info);
939bdcd8170SKalle Valo 
940bdcd8170SKalle Valo 	return 0;
941bdcd8170SKalle Valo }
942bdcd8170SKalle Valo 
94306033760SVivek Natarajan static struct country_code_to_enum_rd *
94406033760SVivek Natarajan ath6kl_regd_find_country(u16 countryCode)
94506033760SVivek Natarajan {
94606033760SVivek Natarajan 	int i;
94706033760SVivek Natarajan 
94806033760SVivek Natarajan 	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
94906033760SVivek Natarajan 		if (allCountries[i].countryCode == countryCode)
95006033760SVivek Natarajan 			return &allCountries[i];
95106033760SVivek Natarajan 	}
95206033760SVivek Natarajan 
95306033760SVivek Natarajan 	return NULL;
95406033760SVivek Natarajan }
95506033760SVivek Natarajan 
95606033760SVivek Natarajan static struct reg_dmn_pair_mapping *
95706033760SVivek Natarajan ath6kl_get_regpair(u16 regdmn)
95806033760SVivek Natarajan {
95906033760SVivek Natarajan 	int i;
96006033760SVivek Natarajan 
96106033760SVivek Natarajan 	if (regdmn == NO_ENUMRD)
96206033760SVivek Natarajan 		return NULL;
96306033760SVivek Natarajan 
96406033760SVivek Natarajan 	for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
965ef8c0017SKalle Valo 		if (regDomainPairs[i].reg_domain == regdmn)
96606033760SVivek Natarajan 			return &regDomainPairs[i];
96706033760SVivek Natarajan 	}
96806033760SVivek Natarajan 
96906033760SVivek Natarajan 	return NULL;
97006033760SVivek Natarajan }
97106033760SVivek Natarajan 
97206033760SVivek Natarajan static struct country_code_to_enum_rd *
97306033760SVivek Natarajan ath6kl_regd_find_country_by_rd(u16 regdmn)
97406033760SVivek Natarajan {
97506033760SVivek Natarajan 	int i;
97606033760SVivek Natarajan 
97706033760SVivek Natarajan 	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
97806033760SVivek Natarajan 		if (allCountries[i].regDmnEnum == regdmn)
97906033760SVivek Natarajan 			return &allCountries[i];
98006033760SVivek Natarajan 	}
98106033760SVivek Natarajan 
98206033760SVivek Natarajan 	return NULL;
98306033760SVivek Natarajan }
98406033760SVivek Natarajan 
98506033760SVivek Natarajan static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
98606033760SVivek Natarajan {
98706033760SVivek Natarajan 	struct ath6kl_wmi_regdomain *ev;
98806033760SVivek Natarajan 	struct country_code_to_enum_rd *country = NULL;
98906033760SVivek Natarajan 	struct reg_dmn_pair_mapping *regpair = NULL;
99006033760SVivek Natarajan 	char alpha2[2];
99106033760SVivek Natarajan 	u32 reg_code;
99206033760SVivek Natarajan 
99306033760SVivek Natarajan 	ev = (struct ath6kl_wmi_regdomain *) datap;
99406033760SVivek Natarajan 	reg_code = le32_to_cpu(ev->reg_code);
99506033760SVivek Natarajan 
996a5d8f9dfSKalle Valo 	if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG) {
99706033760SVivek Natarajan 		country = ath6kl_regd_find_country((u16) reg_code);
998a5d8f9dfSKalle Valo 	} else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
99906033760SVivek Natarajan 		regpair = ath6kl_get_regpair((u16) reg_code);
100006033760SVivek Natarajan 		country = ath6kl_regd_find_country_by_rd((u16) reg_code);
100143a06b34SRaja Mani 		if (regpair)
1002b9b6ee60SKalle Valo 			ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
1003ef8c0017SKalle Valo 				   regpair->reg_domain);
100443a06b34SRaja Mani 		else
100543a06b34SRaja Mani 			ath6kl_warn("Regpair not found reg_code 0x%0x\n",
100643a06b34SRaja Mani 				    reg_code);
100706033760SVivek Natarajan 	}
100806033760SVivek Natarajan 
1009e5348a1eSVasanthakumar Thiagarajan 	if (country && wmi->parent_dev->wiphy_registered) {
101006033760SVivek Natarajan 		alpha2[0] = country->isoName[0];
101106033760SVivek Natarajan 		alpha2[1] = country->isoName[1];
101206033760SVivek Natarajan 
1013be98e3a4SVasanthakumar Thiagarajan 		regulatory_hint(wmi->parent_dev->wiphy, alpha2);
101406033760SVivek Natarajan 
1015b9b6ee60SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
101606033760SVivek Natarajan 			   alpha2[0], alpha2[1]);
101706033760SVivek Natarajan 	}
101806033760SVivek Natarajan }
101906033760SVivek Natarajan 
1020240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len,
1021240d2799SVasanthakumar Thiagarajan 					  struct ath6kl_vif *vif)
1022bdcd8170SKalle Valo {
1023bdcd8170SKalle Valo 	struct wmi_disconnect_event *ev;
1024bdcd8170SKalle Valo 	wmi->traffic_class = 100;
1025bdcd8170SKalle Valo 
1026bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_disconnect_event))
1027bdcd8170SKalle Valo 		return -EINVAL;
1028bdcd8170SKalle Valo 
1029bdcd8170SKalle Valo 	ev = (struct wmi_disconnect_event *) datap;
1030bdcd8170SKalle Valo 
1031b9b6ee60SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
1032b9b6ee60SKalle Valo 		   "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
1033b9b6ee60SKalle Valo 		   le16_to_cpu(ev->proto_reason_status), ev->bssid,
1034b9b6ee60SKalle Valo 		   ev->disconn_reason, ev->assoc_resp_len);
1035b9b6ee60SKalle Valo 
1036bdcd8170SKalle Valo 	wmi->is_wmm_enabled = false;
1037bdcd8170SKalle Valo 
1038240d2799SVasanthakumar Thiagarajan 	ath6kl_disconnect_event(vif, ev->disconn_reason,
1039bdcd8170SKalle Valo 				ev->bssid, ev->assoc_resp_len, ev->assoc_info,
1040bdcd8170SKalle Valo 				le16_to_cpu(ev->proto_reason_status));
1041bdcd8170SKalle Valo 
1042bdcd8170SKalle Valo 	return 0;
1043bdcd8170SKalle Valo }
1044bdcd8170SKalle Valo 
1045bdcd8170SKalle Valo static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
1046bdcd8170SKalle Valo {
1047bdcd8170SKalle Valo 	struct wmi_peer_node_event *ev;
1048bdcd8170SKalle Valo 
1049bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_peer_node_event))
1050bdcd8170SKalle Valo 		return -EINVAL;
1051bdcd8170SKalle Valo 
1052bdcd8170SKalle Valo 	ev = (struct wmi_peer_node_event *) datap;
1053bdcd8170SKalle Valo 
1054bdcd8170SKalle Valo 	if (ev->event_code == PEER_NODE_JOIN_EVENT)
1055bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
1056bdcd8170SKalle Valo 			   ev->peer_mac_addr);
1057bdcd8170SKalle Valo 	else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
1058bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
1059bdcd8170SKalle Valo 			   ev->peer_mac_addr);
1060bdcd8170SKalle Valo 
1061bdcd8170SKalle Valo 	return 0;
1062bdcd8170SKalle Valo }
1063bdcd8170SKalle Valo 
1064240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
1065240d2799SVasanthakumar Thiagarajan 					   struct ath6kl_vif *vif)
1066bdcd8170SKalle Valo {
1067bdcd8170SKalle Valo 	struct wmi_tkip_micerr_event *ev;
1068bdcd8170SKalle Valo 
1069bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_tkip_micerr_event))
1070bdcd8170SKalle Valo 		return -EINVAL;
1071bdcd8170SKalle Valo 
1072bdcd8170SKalle Valo 	ev = (struct wmi_tkip_micerr_event *) datap;
1073bdcd8170SKalle Valo 
1074240d2799SVasanthakumar Thiagarajan 	ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
1075bdcd8170SKalle Valo 
1076bdcd8170SKalle Valo 	return 0;
1077bdcd8170SKalle Valo }
1078bdcd8170SKalle Valo 
10797ac76764SKees Cook void ath6kl_wmi_sscan_timer(struct timer_list *t)
108010509f90SKalle Valo {
10817ac76764SKees Cook 	struct ath6kl_vif *vif = from_timer(vif, t, sched_scan_timer);
108210509f90SKalle Valo 
1083b34939b9SArend Van Spriel 	cfg80211_sched_scan_results(vif->ar->wiphy, 0);
108410509f90SKalle Valo }
108510509f90SKalle Valo 
1086240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
1087240d2799SVasanthakumar Thiagarajan 				       struct ath6kl_vif *vif)
1088bdcd8170SKalle Valo {
108982e14f56SJouni Malinen 	struct wmi_bss_info_hdr2 *bih;
10901aaa8c74SJouni Malinen 	u8 *buf;
10911aaa8c74SJouni Malinen 	struct ieee80211_channel *channel;
10921aaa8c74SJouni Malinen 	struct ath6kl *ar = wmi->parent_dev;
10931aaa8c74SJouni Malinen 	struct cfg80211_bss *bss;
1094bdcd8170SKalle Valo 
109582e14f56SJouni Malinen 	if (len <= sizeof(struct wmi_bss_info_hdr2))
1096bdcd8170SKalle Valo 		return -EINVAL;
1097bdcd8170SKalle Valo 
109882e14f56SJouni Malinen 	bih = (struct wmi_bss_info_hdr2 *) datap;
109982e14f56SJouni Malinen 	buf = datap + sizeof(struct wmi_bss_info_hdr2);
110082e14f56SJouni Malinen 	len -= sizeof(struct wmi_bss_info_hdr2);
1101bdcd8170SKalle Valo 
1102bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
11031aaa8c74SJouni Malinen 		   "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
11041aaa8c74SJouni Malinen 		   "frame_type=%d\n",
110582e14f56SJouni Malinen 		   bih->ch, bih->snr, bih->snr - 95, bih->bssid,
11061aaa8c74SJouni Malinen 		   bih->frame_type);
1107bdcd8170SKalle Valo 
11081aaa8c74SJouni Malinen 	if (bih->frame_type != BEACON_FTYPE &&
11091aaa8c74SJouni Malinen 	    bih->frame_type != PROBERESP_FTYPE)
11101aaa8c74SJouni Malinen 		return 0; /* Only update BSS table for now */
11111aaa8c74SJouni Malinen 
1112551185caSJouni Malinen 	if (bih->frame_type == BEACON_FTYPE &&
111359c98449SVasanthakumar Thiagarajan 	    test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
111459c98449SVasanthakumar Thiagarajan 		clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
1115240d2799SVasanthakumar Thiagarajan 		ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1116240d2799SVasanthakumar Thiagarajan 					 NONE_BSS_FILTER, 0);
1117551185caSJouni Malinen 	}
1118551185caSJouni Malinen 
1119be98e3a4SVasanthakumar Thiagarajan 	channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
11201aaa8c74SJouni Malinen 	if (channel == NULL)
11211aaa8c74SJouni Malinen 		return -EINVAL;
11221aaa8c74SJouni Malinen 
11231aaa8c74SJouni Malinen 	if (len < 8 + 2 + 2)
11241aaa8c74SJouni Malinen 		return -EINVAL;
1125bdcd8170SKalle Valo 
1126ddc3d77cSKalle Valo 	if (bih->frame_type == BEACON_FTYPE &&
1127ddc3d77cSKalle Valo 	    test_bit(CONNECTED, &vif->flags) &&
1128ddc3d77cSKalle Valo 	    memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
112932c10874SJouni Malinen 		const u8 *tim;
113032c10874SJouni Malinen 		tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
113132c10874SJouni Malinen 				       len - 8 - 2 - 2);
113232c10874SJouni Malinen 		if (tim && tim[1] >= 2) {
1133cf5333d7SVasanthakumar Thiagarajan 			vif->assoc_bss_dtim_period = tim[3];
113459c98449SVasanthakumar Thiagarajan 			set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
113532c10874SJouni Malinen 		}
113632c10874SJouni Malinen 	}
113732c10874SJouni Malinen 
11385bc8c1f2SJohannes Berg 	bss = cfg80211_inform_bss(ar->wiphy, channel,
11395bc8c1f2SJohannes Berg 				  bih->frame_type == BEACON_FTYPE ?
11405bc8c1f2SJohannes Berg 					CFG80211_BSS_FTYPE_BEACON :
11415bc8c1f2SJohannes Berg 					CFG80211_BSS_FTYPE_PRESP,
11425bc8c1f2SJohannes Berg 				  bih->bssid, get_unaligned_le64((__le64 *)buf),
11435bc8c1f2SJohannes Berg 				  get_unaligned_le16(((__le16 *)buf) + 5),
11445bc8c1f2SJohannes Berg 				  get_unaligned_le16(((__le16 *)buf) + 4),
11455bc8c1f2SJohannes Berg 				  buf + 8 + 2 + 2, len - 8 - 2 - 2,
11465bc8c1f2SJohannes Berg 				  (bih->snr - 95) * 100, GFP_ATOMIC);
11471aaa8c74SJouni Malinen 	if (bss == NULL)
1148bdcd8170SKalle Valo 		return -ENOMEM;
11495b112d3dSJohannes Berg 	cfg80211_put_bss(ar->wiphy, bss);
1150bdcd8170SKalle Valo 
115110509f90SKalle Valo 	/*
115210509f90SKalle Valo 	 * Firmware doesn't return any event when scheduled scan has
115310509f90SKalle Valo 	 * finished, so we need to use a timer to find out when there are
115410509f90SKalle Valo 	 * no more results.
115510509f90SKalle Valo 	 *
115610509f90SKalle Valo 	 * The timer is started from the first bss info received, otherwise
115710509f90SKalle Valo 	 * the timer would not ever fire if the scan interval is short
115810509f90SKalle Valo 	 * enough.
115910509f90SKalle Valo 	 */
1160b1f47e3aSThomas Pedersen 	if (test_bit(SCHED_SCANNING, &vif->flags) &&
116110509f90SKalle Valo 	    !timer_pending(&vif->sched_scan_timer)) {
116210509f90SKalle Valo 		mod_timer(&vif->sched_scan_timer, jiffies +
116310509f90SKalle Valo 			  msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY));
116410509f90SKalle Valo 	}
116510509f90SKalle Valo 
1166bdcd8170SKalle Valo 	return 0;
1167bdcd8170SKalle Valo }
1168bdcd8170SKalle Valo 
1169bdcd8170SKalle Valo /* Inactivity timeout of a fatpipe(pstream) at the target */
1170bdcd8170SKalle Valo static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
1171bdcd8170SKalle Valo 					       int len)
1172bdcd8170SKalle Valo {
1173bdcd8170SKalle Valo 	struct wmi_pstream_timeout_event *ev;
1174bdcd8170SKalle Valo 
1175bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_pstream_timeout_event))
1176bdcd8170SKalle Valo 		return -EINVAL;
1177bdcd8170SKalle Valo 
1178bdcd8170SKalle Valo 	ev = (struct wmi_pstream_timeout_event *) datap;
11795d6751eaSDan Carpenter 	if (ev->traffic_class >= WMM_NUM_AC) {
11805d6751eaSDan Carpenter 		ath6kl_err("invalid traffic class: %d\n", ev->traffic_class);
11815d6751eaSDan Carpenter 		return -EINVAL;
11825d6751eaSDan Carpenter 	}
1183bdcd8170SKalle Valo 
1184bdcd8170SKalle Valo 	/*
1185bdcd8170SKalle Valo 	 * When the pstream (fat pipe == AC) timesout, it means there were
1186bdcd8170SKalle Valo 	 * no thinStreams within this pstream & it got implicitly created
1187bdcd8170SKalle Valo 	 * due to data flow on this AC. We start the inactivity timer only
1188bdcd8170SKalle Valo 	 * for implicitly created pstream. Just reset the host state.
1189bdcd8170SKalle Valo 	 */
1190bdcd8170SKalle Valo 	spin_lock_bh(&wmi->lock);
1191bdcd8170SKalle Valo 	wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1192bdcd8170SKalle Valo 	wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1193bdcd8170SKalle Valo 	spin_unlock_bh(&wmi->lock);
1194bdcd8170SKalle Valo 
1195bdcd8170SKalle Valo 	/* Indicate inactivity to driver layer for this fatpipe (pstream) */
1196bdcd8170SKalle Valo 	ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1197bdcd8170SKalle Valo 
1198bdcd8170SKalle Valo 	return 0;
1199bdcd8170SKalle Valo }
1200bdcd8170SKalle Valo 
1201bdcd8170SKalle Valo static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1202bdcd8170SKalle Valo {
1203bdcd8170SKalle Valo 	struct wmi_bit_rate_reply *reply;
1204e5851849SLee Jones 	u32 index;
1205bdcd8170SKalle Valo 
1206bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_bit_rate_reply))
1207bdcd8170SKalle Valo 		return -EINVAL;
1208bdcd8170SKalle Valo 
1209bdcd8170SKalle Valo 	reply = (struct wmi_bit_rate_reply *) datap;
1210bdcd8170SKalle Valo 
1211bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1212bdcd8170SKalle Valo 
1213e5851849SLee Jones 	if (reply->rate_index != (s8) RATE_AUTO) {
1214bdcd8170SKalle Valo 		index = reply->rate_index & 0x7f;
1215d54601b9SRaja Mani 		if (WARN_ON_ONCE(index > (RATE_MCS_7_40 + 1)))
1216d54601b9SRaja Mani 			return -EINVAL;
1217bdcd8170SKalle Valo 	}
1218bdcd8170SKalle Valo 
1219bdcd8170SKalle Valo 	ath6kl_wakeup_event(wmi->parent_dev);
1220bdcd8170SKalle Valo 
1221bdcd8170SKalle Valo 	return 0;
1222bdcd8170SKalle Valo }
1223bdcd8170SKalle Valo 
12244f34daceSThomas Pedersen static int ath6kl_wmi_test_rx(struct wmi *wmi, u8 *datap, int len)
1225003353b0SKalle Valo {
12264f34daceSThomas Pedersen 	ath6kl_tm_rx_event(wmi->parent_dev, datap, len);
1227003353b0SKalle Valo 
1228003353b0SKalle Valo 	return 0;
1229003353b0SKalle Valo }
1230003353b0SKalle Valo 
1231bdcd8170SKalle Valo static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1232bdcd8170SKalle Valo {
1233bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_fix_rates_reply))
1234bdcd8170SKalle Valo 		return -EINVAL;
1235bdcd8170SKalle Valo 
1236bdcd8170SKalle Valo 	ath6kl_wakeup_event(wmi->parent_dev);
1237bdcd8170SKalle Valo 
1238bdcd8170SKalle Valo 	return 0;
1239bdcd8170SKalle Valo }
1240bdcd8170SKalle Valo 
1241bdcd8170SKalle Valo static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1242bdcd8170SKalle Valo {
1243bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_channel_list_reply))
1244bdcd8170SKalle Valo 		return -EINVAL;
1245bdcd8170SKalle Valo 
1246bdcd8170SKalle Valo 	ath6kl_wakeup_event(wmi->parent_dev);
1247bdcd8170SKalle Valo 
1248bdcd8170SKalle Valo 	return 0;
1249bdcd8170SKalle Valo }
1250bdcd8170SKalle Valo 
1251bdcd8170SKalle Valo static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1252bdcd8170SKalle Valo {
1253bdcd8170SKalle Valo 	struct wmi_tx_pwr_reply *reply;
1254bdcd8170SKalle Valo 
1255bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_tx_pwr_reply))
1256bdcd8170SKalle Valo 		return -EINVAL;
1257bdcd8170SKalle Valo 
1258bdcd8170SKalle Valo 	reply = (struct wmi_tx_pwr_reply *) datap;
1259bdcd8170SKalle Valo 	ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1260bdcd8170SKalle Valo 
1261bdcd8170SKalle Valo 	return 0;
1262bdcd8170SKalle Valo }
1263bdcd8170SKalle Valo 
1264bdcd8170SKalle Valo static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1265bdcd8170SKalle Valo {
1266bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_get_keepalive_cmd))
1267bdcd8170SKalle Valo 		return -EINVAL;
1268bdcd8170SKalle Valo 
1269bdcd8170SKalle Valo 	ath6kl_wakeup_event(wmi->parent_dev);
1270bdcd8170SKalle Valo 
1271bdcd8170SKalle Valo 	return 0;
1272bdcd8170SKalle Valo }
1273bdcd8170SKalle Valo 
1274240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
1275240d2799SVasanthakumar Thiagarajan 				       struct ath6kl_vif *vif)
1276bdcd8170SKalle Valo {
1277bdcd8170SKalle Valo 	struct wmi_scan_complete_event *ev;
1278bdcd8170SKalle Valo 
1279bdcd8170SKalle Valo 	ev = (struct wmi_scan_complete_event *) datap;
1280bdcd8170SKalle Valo 
1281240d2799SVasanthakumar Thiagarajan 	ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
1282bdcd8170SKalle Valo 	wmi->is_probe_ssid = false;
1283bdcd8170SKalle Valo 
1284bdcd8170SKalle Valo 	return 0;
1285bdcd8170SKalle Valo }
1286bdcd8170SKalle Valo 
128786512136SJouni Malinen static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
1288240d2799SVasanthakumar Thiagarajan 					       int len, struct ath6kl_vif *vif)
128986512136SJouni Malinen {
129086512136SJouni Malinen 	struct wmi_neighbor_report_event *ev;
129186512136SJouni Malinen 	u8 i;
129286512136SJouni Malinen 
129386512136SJouni Malinen 	if (len < sizeof(*ev))
129486512136SJouni Malinen 		return -EINVAL;
129586512136SJouni Malinen 	ev = (struct wmi_neighbor_report_event *) datap;
129683d9562bSGustavo A. R. Silva 	if (struct_size(ev, neighbor, ev->num_neighbors) > len) {
1297cdeb8602SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI,
1298cdeb8602SKalle Valo 			   "truncated neighbor event (num=%d len=%d)\n",
1299cdeb8602SKalle Valo 			   ev->num_neighbors, len);
130086512136SJouni Malinen 		return -EINVAL;
130186512136SJouni Malinen 	}
130286512136SJouni Malinen 	for (i = 0; i < ev->num_neighbors; i++) {
130386512136SJouni Malinen 		ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
130486512136SJouni Malinen 			   i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
130586512136SJouni Malinen 			   ev->neighbor[i].bss_flags);
1306240d2799SVasanthakumar Thiagarajan 		cfg80211_pmksa_candidate_notify(vif->ndev, i,
130786512136SJouni Malinen 						ev->neighbor[i].bssid,
130886512136SJouni Malinen 						!!(ev->neighbor[i].bss_flags &
130986512136SJouni Malinen 						   WMI_PREAUTH_CAPABLE_BSS),
131086512136SJouni Malinen 						GFP_ATOMIC);
131186512136SJouni Malinen 	}
131286512136SJouni Malinen 
131386512136SJouni Malinen 	return 0;
131486512136SJouni Malinen }
131586512136SJouni Malinen 
1316bdcd8170SKalle Valo /*
1317bdcd8170SKalle Valo  * Target is reporting a programming error.  This is for
1318bdcd8170SKalle Valo  * developer aid only.  Target only checks a few common violations
1319bdcd8170SKalle Valo  * and it is responsibility of host to do all error checking.
1320bdcd8170SKalle Valo  * Behavior of target after wmi error event is undefined.
1321bdcd8170SKalle Valo  * A reset is recommended.
1322bdcd8170SKalle Valo  */
1323bdcd8170SKalle Valo static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1324bdcd8170SKalle Valo {
1325bdcd8170SKalle Valo 	const char *type = "unknown error";
1326bdcd8170SKalle Valo 	struct wmi_cmd_error_event *ev;
1327bdcd8170SKalle Valo 	ev = (struct wmi_cmd_error_event *) datap;
1328bdcd8170SKalle Valo 
1329bdcd8170SKalle Valo 	switch (ev->err_code) {
1330bdcd8170SKalle Valo 	case INVALID_PARAM:
1331bdcd8170SKalle Valo 		type = "invalid parameter";
1332bdcd8170SKalle Valo 		break;
1333bdcd8170SKalle Valo 	case ILLEGAL_STATE:
1334bdcd8170SKalle Valo 		type = "invalid state";
1335bdcd8170SKalle Valo 		break;
1336bdcd8170SKalle Valo 	case INTERNAL_ERROR:
1337bdcd8170SKalle Valo 		type = "internal error";
1338bdcd8170SKalle Valo 		break;
1339bdcd8170SKalle Valo 	}
1340bdcd8170SKalle Valo 
1341bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1342bdcd8170SKalle Valo 		   ev->cmd_id, type);
1343bdcd8170SKalle Valo 
1344bdcd8170SKalle Valo 	return 0;
1345bdcd8170SKalle Valo }
1346bdcd8170SKalle Valo 
1347240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
1348240d2799SVasanthakumar Thiagarajan 				     struct ath6kl_vif *vif)
1349bdcd8170SKalle Valo {
1350240d2799SVasanthakumar Thiagarajan 	ath6kl_tgt_stats_event(vif, datap, len);
1351bdcd8170SKalle Valo 
1352bdcd8170SKalle Valo 	return 0;
1353bdcd8170SKalle Valo }
1354bdcd8170SKalle Valo 
1355bdcd8170SKalle Valo static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1356bdcd8170SKalle Valo 					 struct sq_threshold_params *sq_thresh,
1357bdcd8170SKalle Valo 					 u32 size)
1358bdcd8170SKalle Valo {
1359bdcd8170SKalle Valo 	u32 index;
1360bdcd8170SKalle Valo 	u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1361bdcd8170SKalle Valo 
1362bdcd8170SKalle Valo 	/* The list is already in sorted order. Get the next lower value */
1363bdcd8170SKalle Valo 	for (index = 0; index < size; index++) {
1364bdcd8170SKalle Valo 		if (rssi < sq_thresh->upper_threshold[index]) {
1365bdcd8170SKalle Valo 			threshold = (u8) sq_thresh->upper_threshold[index];
1366bdcd8170SKalle Valo 			break;
1367bdcd8170SKalle Valo 		}
1368bdcd8170SKalle Valo 	}
1369bdcd8170SKalle Valo 
1370bdcd8170SKalle Valo 	return threshold;
1371bdcd8170SKalle Valo }
1372bdcd8170SKalle Valo 
1373bdcd8170SKalle Valo static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1374bdcd8170SKalle Valo 					 struct sq_threshold_params *sq_thresh,
1375bdcd8170SKalle Valo 					 u32 size)
1376bdcd8170SKalle Valo {
1377bdcd8170SKalle Valo 	u32 index;
1378bdcd8170SKalle Valo 	u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1379bdcd8170SKalle Valo 
1380bdcd8170SKalle Valo 	/* The list is already in sorted order. Get the next lower value */
1381bdcd8170SKalle Valo 	for (index = 0; index < size; index++) {
1382bdcd8170SKalle Valo 		if (rssi > sq_thresh->lower_threshold[index]) {
1383bdcd8170SKalle Valo 			threshold = (u8) sq_thresh->lower_threshold[index];
1384bdcd8170SKalle Valo 			break;
1385bdcd8170SKalle Valo 		}
1386bdcd8170SKalle Valo 	}
1387bdcd8170SKalle Valo 
1388bdcd8170SKalle Valo 	return threshold;
1389bdcd8170SKalle Valo }
1390bdcd8170SKalle Valo 
1391bdcd8170SKalle Valo static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1392bdcd8170SKalle Valo 			struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1393bdcd8170SKalle Valo {
1394bdcd8170SKalle Valo 	struct sk_buff *skb;
1395bdcd8170SKalle Valo 	struct wmi_rssi_threshold_params_cmd *cmd;
1396bdcd8170SKalle Valo 
1397bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1398bdcd8170SKalle Valo 	if (!skb)
1399bdcd8170SKalle Valo 		return -ENOMEM;
1400bdcd8170SKalle Valo 
1401bdcd8170SKalle Valo 	cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1402bdcd8170SKalle Valo 	memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1403bdcd8170SKalle Valo 
1404334234b5SVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
1405bdcd8170SKalle Valo 				   NO_SYNC_WMIFLAG);
1406bdcd8170SKalle Valo }
1407bdcd8170SKalle Valo 
1408bdcd8170SKalle Valo static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1409bdcd8170SKalle Valo 					      int len)
1410bdcd8170SKalle Valo {
1411bdcd8170SKalle Valo 	struct wmi_rssi_threshold_event *reply;
1412bdcd8170SKalle Valo 	struct wmi_rssi_threshold_params_cmd cmd;
1413bdcd8170SKalle Valo 	struct sq_threshold_params *sq_thresh;
1414bdcd8170SKalle Valo 	enum wmi_rssi_threshold_val new_threshold;
1415bdcd8170SKalle Valo 	u8 upper_rssi_threshold, lower_rssi_threshold;
1416bdcd8170SKalle Valo 	s16 rssi;
1417bdcd8170SKalle Valo 	int ret;
1418bdcd8170SKalle Valo 
1419bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_rssi_threshold_event))
1420bdcd8170SKalle Valo 		return -EINVAL;
1421bdcd8170SKalle Valo 
1422bdcd8170SKalle Valo 	reply = (struct wmi_rssi_threshold_event *) datap;
1423bdcd8170SKalle Valo 	new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1424bdcd8170SKalle Valo 	rssi = a_sle16_to_cpu(reply->rssi);
1425bdcd8170SKalle Valo 
1426bdcd8170SKalle Valo 	sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1427bdcd8170SKalle Valo 
1428bdcd8170SKalle Valo 	/*
1429bdcd8170SKalle Valo 	 * Identify the threshold breached and communicate that to the app.
1430bdcd8170SKalle Valo 	 * After that install a new set of thresholds based on the signal
1431bdcd8170SKalle Valo 	 * quality reported by the target
1432bdcd8170SKalle Valo 	 */
1433bdcd8170SKalle Valo 	if (new_threshold) {
1434bdcd8170SKalle Valo 		/* Upper threshold breached */
1435bdcd8170SKalle Valo 		if (rssi < sq_thresh->upper_threshold[0]) {
1436bdcd8170SKalle Valo 			ath6kl_dbg(ATH6KL_DBG_WMI,
1437bdcd8170SKalle Valo 				   "spurious upper rssi threshold event: %d\n",
1438bdcd8170SKalle Valo 				   rssi);
1439bdcd8170SKalle Valo 		} else if ((rssi < sq_thresh->upper_threshold[1]) &&
1440bdcd8170SKalle Valo 			   (rssi >= sq_thresh->upper_threshold[0])) {
1441bdcd8170SKalle Valo 			new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1442bdcd8170SKalle Valo 		} else if ((rssi < sq_thresh->upper_threshold[2]) &&
1443bdcd8170SKalle Valo 			   (rssi >= sq_thresh->upper_threshold[1])) {
1444bdcd8170SKalle Valo 			new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1445bdcd8170SKalle Valo 		} else if ((rssi < sq_thresh->upper_threshold[3]) &&
1446bdcd8170SKalle Valo 			   (rssi >= sq_thresh->upper_threshold[2])) {
1447bdcd8170SKalle Valo 			new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1448bdcd8170SKalle Valo 		} else if ((rssi < sq_thresh->upper_threshold[4]) &&
1449bdcd8170SKalle Valo 			   (rssi >= sq_thresh->upper_threshold[3])) {
1450bdcd8170SKalle Valo 			new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1451bdcd8170SKalle Valo 		} else if ((rssi < sq_thresh->upper_threshold[5]) &&
1452bdcd8170SKalle Valo 			   (rssi >= sq_thresh->upper_threshold[4])) {
1453bdcd8170SKalle Valo 			new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1454bdcd8170SKalle Valo 		} else if (rssi >= sq_thresh->upper_threshold[5]) {
1455bdcd8170SKalle Valo 			new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1456bdcd8170SKalle Valo 		}
1457bdcd8170SKalle Valo 	} else {
1458bdcd8170SKalle Valo 		/* Lower threshold breached */
1459bdcd8170SKalle Valo 		if (rssi > sq_thresh->lower_threshold[0]) {
1460bdcd8170SKalle Valo 			ath6kl_dbg(ATH6KL_DBG_WMI,
1461bdcd8170SKalle Valo 				   "spurious lower rssi threshold event: %d %d\n",
1462bdcd8170SKalle Valo 				rssi, sq_thresh->lower_threshold[0]);
1463bdcd8170SKalle Valo 		} else if ((rssi > sq_thresh->lower_threshold[1]) &&
1464bdcd8170SKalle Valo 			   (rssi <= sq_thresh->lower_threshold[0])) {
1465bdcd8170SKalle Valo 			new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1466bdcd8170SKalle Valo 		} else if ((rssi > sq_thresh->lower_threshold[2]) &&
1467bdcd8170SKalle Valo 			   (rssi <= sq_thresh->lower_threshold[1])) {
1468bdcd8170SKalle Valo 			new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1469bdcd8170SKalle Valo 		} else if ((rssi > sq_thresh->lower_threshold[3]) &&
1470bdcd8170SKalle Valo 			   (rssi <= sq_thresh->lower_threshold[2])) {
1471bdcd8170SKalle Valo 			new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1472bdcd8170SKalle Valo 		} else if ((rssi > sq_thresh->lower_threshold[4]) &&
1473bdcd8170SKalle Valo 			   (rssi <= sq_thresh->lower_threshold[3])) {
1474bdcd8170SKalle Valo 			new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1475bdcd8170SKalle Valo 		} else if ((rssi > sq_thresh->lower_threshold[5]) &&
1476bdcd8170SKalle Valo 			   (rssi <= sq_thresh->lower_threshold[4])) {
1477bdcd8170SKalle Valo 			new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1478bdcd8170SKalle Valo 		} else if (rssi <= sq_thresh->lower_threshold[5]) {
1479bdcd8170SKalle Valo 			new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1480bdcd8170SKalle Valo 		}
1481bdcd8170SKalle Valo 	}
1482bdcd8170SKalle Valo 
1483bdcd8170SKalle Valo 	/* Calculate and install the next set of thresholds */
1484bdcd8170SKalle Valo 	lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1485bdcd8170SKalle Valo 				       sq_thresh->lower_threshold_valid_count);
1486bdcd8170SKalle Valo 	upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1487bdcd8170SKalle Valo 				       sq_thresh->upper_threshold_valid_count);
1488bdcd8170SKalle Valo 
1489bdcd8170SKalle Valo 	/* Issue a wmi command to install the thresholds */
1490bdcd8170SKalle Valo 	cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1491bdcd8170SKalle Valo 	cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1492bdcd8170SKalle Valo 	cmd.weight = sq_thresh->weight;
1493bdcd8170SKalle Valo 	cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1494bdcd8170SKalle Valo 
1495bdcd8170SKalle Valo 	ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1496bdcd8170SKalle Valo 	if (ret) {
1497bdcd8170SKalle Valo 		ath6kl_err("unable to configure rssi thresholds\n");
1498bdcd8170SKalle Valo 		return -EIO;
1499bdcd8170SKalle Valo 	}
1500bdcd8170SKalle Valo 
1501bdcd8170SKalle Valo 	return 0;
1502bdcd8170SKalle Valo }
1503bdcd8170SKalle Valo 
1504240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
1505240d2799SVasanthakumar Thiagarajan 				   struct ath6kl_vif *vif)
1506bdcd8170SKalle Valo {
1507bdcd8170SKalle Valo 	struct wmi_cac_event *reply;
1508bdcd8170SKalle Valo 	struct ieee80211_tspec_ie *ts;
1509bdcd8170SKalle Valo 	u16 active_tsids, tsinfo;
1510bdcd8170SKalle Valo 	u8 tsid, index;
1511bdcd8170SKalle Valo 	u8 ts_id;
1512bdcd8170SKalle Valo 
1513bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_cac_event))
1514bdcd8170SKalle Valo 		return -EINVAL;
1515bdcd8170SKalle Valo 
1516bdcd8170SKalle Valo 	reply = (struct wmi_cac_event *) datap;
15175d6751eaSDan Carpenter 	if (reply->ac >= WMM_NUM_AC) {
15185d6751eaSDan Carpenter 		ath6kl_err("invalid AC: %d\n", reply->ac);
15195d6751eaSDan Carpenter 		return -EINVAL;
15205d6751eaSDan Carpenter 	}
1521bdcd8170SKalle Valo 
1522bdcd8170SKalle Valo 	if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1523bdcd8170SKalle Valo 	    (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1524bdcd8170SKalle Valo 		ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1525bdcd8170SKalle Valo 		tsinfo = le16_to_cpu(ts->tsinfo);
1526bdcd8170SKalle Valo 		tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1527bdcd8170SKalle Valo 			IEEE80211_WMM_IE_TSPEC_TID_MASK;
1528bdcd8170SKalle Valo 
1529240d2799SVasanthakumar Thiagarajan 		ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1530240d2799SVasanthakumar Thiagarajan 					      reply->ac, tsid);
1531bdcd8170SKalle Valo 	} else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1532bdcd8170SKalle Valo 		/*
1533bdcd8170SKalle Valo 		 * Following assumes that there is only one outstanding
1534bdcd8170SKalle Valo 		 * ADDTS request when this event is received
1535bdcd8170SKalle Valo 		 */
1536bdcd8170SKalle Valo 		spin_lock_bh(&wmi->lock);
1537bdcd8170SKalle Valo 		active_tsids = wmi->stream_exist_for_ac[reply->ac];
1538bdcd8170SKalle Valo 		spin_unlock_bh(&wmi->lock);
1539bdcd8170SKalle Valo 
1540bdcd8170SKalle Valo 		for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1541bdcd8170SKalle Valo 			if ((active_tsids >> index) & 1)
1542bdcd8170SKalle Valo 				break;
1543bdcd8170SKalle Valo 		}
1544bdcd8170SKalle Valo 		if (index < (sizeof(active_tsids) * 8))
1545240d2799SVasanthakumar Thiagarajan 			ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1546240d2799SVasanthakumar Thiagarajan 						      reply->ac, index);
1547bdcd8170SKalle Valo 	}
1548bdcd8170SKalle Valo 
1549bdcd8170SKalle Valo 	/*
1550bdcd8170SKalle Valo 	 * Clear active tsids and Add missing handling
1551bdcd8170SKalle Valo 	 * for delete qos stream from AP
1552bdcd8170SKalle Valo 	 */
1553bdcd8170SKalle Valo 	else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1554bdcd8170SKalle Valo 		ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1555bdcd8170SKalle Valo 		tsinfo = le16_to_cpu(ts->tsinfo);
1556bdcd8170SKalle Valo 		ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1557bdcd8170SKalle Valo 			 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1558bdcd8170SKalle Valo 
1559bdcd8170SKalle Valo 		spin_lock_bh(&wmi->lock);
1560bdcd8170SKalle Valo 		wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1561bdcd8170SKalle Valo 		active_tsids = wmi->stream_exist_for_ac[reply->ac];
1562bdcd8170SKalle Valo 		spin_unlock_bh(&wmi->lock);
1563bdcd8170SKalle Valo 
1564bdcd8170SKalle Valo 		/* Indicate stream inactivity to driver layer only if all tsids
1565bdcd8170SKalle Valo 		 * within this AC are deleted.
1566bdcd8170SKalle Valo 		 */
1567bdcd8170SKalle Valo 		if (!active_tsids) {
1568bdcd8170SKalle Valo 			ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1569bdcd8170SKalle Valo 						    false);
1570bdcd8170SKalle Valo 			wmi->fat_pipe_exist &= ~(1 << reply->ac);
1571bdcd8170SKalle Valo 		}
1572bdcd8170SKalle Valo 	}
1573bdcd8170SKalle Valo 
1574bdcd8170SKalle Valo 	return 0;
1575bdcd8170SKalle Valo }
1576bdcd8170SKalle Valo 
1577279b2862SThomas Pedersen static int ath6kl_wmi_txe_notify_event_rx(struct wmi *wmi, u8 *datap, int len,
1578279b2862SThomas Pedersen 					  struct ath6kl_vif *vif)
1579279b2862SThomas Pedersen {
1580279b2862SThomas Pedersen 	struct wmi_txe_notify_event *ev;
1581279b2862SThomas Pedersen 	u32 rate, pkts;
1582279b2862SThomas Pedersen 
1583279b2862SThomas Pedersen 	if (len < sizeof(*ev))
1584279b2862SThomas Pedersen 		return -EINVAL;
1585279b2862SThomas Pedersen 
1586c9b260a6SSteve deRosier 	if (vif->nw_type != INFRA_NETWORK ||
1587c9b260a6SSteve deRosier 	    !test_bit(ATH6KL_FW_CAPABILITY_TX_ERR_NOTIFY,
1588c9b260a6SSteve deRosier 		      vif->ar->fw_capabilities))
1589c9b260a6SSteve deRosier 		return -EOPNOTSUPP;
1590c9b260a6SSteve deRosier 
1591279b2862SThomas Pedersen 	if (vif->sme_state != SME_CONNECTED)
1592279b2862SThomas Pedersen 		return -ENOTCONN;
1593279b2862SThomas Pedersen 
1594279b2862SThomas Pedersen 	ev = (struct wmi_txe_notify_event *) datap;
1595279b2862SThomas Pedersen 	rate = le32_to_cpu(ev->rate);
1596279b2862SThomas Pedersen 	pkts = le32_to_cpu(ev->pkts);
1597279b2862SThomas Pedersen 
1598169345d4SJoe Perches 	ath6kl_dbg(ATH6KL_DBG_WMI, "TXE notify event: peer %pM rate %d%% pkts %d intvl %ds\n",
1599279b2862SThomas Pedersen 		   vif->bssid, rate, pkts, vif->txe_intvl);
1600279b2862SThomas Pedersen 
1601279b2862SThomas Pedersen 	cfg80211_cqm_txe_notify(vif->ndev, vif->bssid, pkts,
1602279b2862SThomas Pedersen 				rate, vif->txe_intvl, GFP_KERNEL);
1603279b2862SThomas Pedersen 
1604279b2862SThomas Pedersen 	return 0;
1605279b2862SThomas Pedersen }
1606279b2862SThomas Pedersen 
1607279b2862SThomas Pedersen int ath6kl_wmi_set_txe_notify(struct wmi *wmi, u8 idx,
1608279b2862SThomas Pedersen 			      u32 rate, u32 pkts, u32 intvl)
1609279b2862SThomas Pedersen {
1610279b2862SThomas Pedersen 	struct sk_buff *skb;
1611279b2862SThomas Pedersen 	struct wmi_txe_notify_cmd *cmd;
1612279b2862SThomas Pedersen 
1613279b2862SThomas Pedersen 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1614279b2862SThomas Pedersen 	if (!skb)
1615279b2862SThomas Pedersen 		return -ENOMEM;
1616279b2862SThomas Pedersen 
1617279b2862SThomas Pedersen 	cmd = (struct wmi_txe_notify_cmd *) skb->data;
1618279b2862SThomas Pedersen 	cmd->rate = cpu_to_le32(rate);
1619279b2862SThomas Pedersen 	cmd->pkts = cpu_to_le32(pkts);
1620279b2862SThomas Pedersen 	cmd->intvl = cpu_to_le32(intvl);
1621279b2862SThomas Pedersen 
1622279b2862SThomas Pedersen 	return ath6kl_wmi_cmd_send(wmi, idx, skb, WMI_SET_TXE_NOTIFY_CMDID,
1623279b2862SThomas Pedersen 				   NO_SYNC_WMIFLAG);
1624279b2862SThomas Pedersen }
1625279b2862SThomas Pedersen 
162685b20fc2SThomas Pedersen int ath6kl_wmi_set_rssi_filter_cmd(struct wmi *wmi, u8 if_idx, s8 rssi)
162785b20fc2SThomas Pedersen {
162885b20fc2SThomas Pedersen 	struct sk_buff *skb;
162985b20fc2SThomas Pedersen 	struct wmi_set_rssi_filter_cmd *cmd;
163085b20fc2SThomas Pedersen 	int ret;
163185b20fc2SThomas Pedersen 
163285b20fc2SThomas Pedersen 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
163385b20fc2SThomas Pedersen 	if (!skb)
163485b20fc2SThomas Pedersen 		return -ENOMEM;
163585b20fc2SThomas Pedersen 
163685b20fc2SThomas Pedersen 	cmd = (struct wmi_set_rssi_filter_cmd *) skb->data;
163785b20fc2SThomas Pedersen 	cmd->rssi = rssi;
163885b20fc2SThomas Pedersen 
163985b20fc2SThomas Pedersen 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_RSSI_FILTER_CMDID,
164085b20fc2SThomas Pedersen 				  NO_SYNC_WMIFLAG);
164185b20fc2SThomas Pedersen 	return ret;
164285b20fc2SThomas Pedersen }
164385b20fc2SThomas Pedersen 
1644bdcd8170SKalle Valo static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1645bdcd8170SKalle Valo 			struct wmi_snr_threshold_params_cmd *snr_cmd)
1646bdcd8170SKalle Valo {
1647bdcd8170SKalle Valo 	struct sk_buff *skb;
1648bdcd8170SKalle Valo 	struct wmi_snr_threshold_params_cmd *cmd;
1649bdcd8170SKalle Valo 
1650bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1651bdcd8170SKalle Valo 	if (!skb)
1652bdcd8170SKalle Valo 		return -ENOMEM;
1653bdcd8170SKalle Valo 
1654bdcd8170SKalle Valo 	cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1655bdcd8170SKalle Valo 	memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1656bdcd8170SKalle Valo 
1657334234b5SVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
1658bdcd8170SKalle Valo 				   NO_SYNC_WMIFLAG);
1659bdcd8170SKalle Valo }
1660bdcd8170SKalle Valo 
1661bdcd8170SKalle Valo static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1662bdcd8170SKalle Valo 					     int len)
1663bdcd8170SKalle Valo {
1664bdcd8170SKalle Valo 	struct wmi_snr_threshold_event *reply;
1665bdcd8170SKalle Valo 	struct sq_threshold_params *sq_thresh;
1666bdcd8170SKalle Valo 	struct wmi_snr_threshold_params_cmd cmd;
1667bdcd8170SKalle Valo 	enum wmi_snr_threshold_val new_threshold;
1668bdcd8170SKalle Valo 	u8 upper_snr_threshold, lower_snr_threshold;
1669bdcd8170SKalle Valo 	s16 snr;
1670bdcd8170SKalle Valo 	int ret;
1671bdcd8170SKalle Valo 
1672bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_snr_threshold_event))
1673bdcd8170SKalle Valo 		return -EINVAL;
1674bdcd8170SKalle Valo 
1675bdcd8170SKalle Valo 	reply = (struct wmi_snr_threshold_event *) datap;
1676bdcd8170SKalle Valo 
1677bdcd8170SKalle Valo 	new_threshold = (enum wmi_snr_threshold_val) reply->range;
1678bdcd8170SKalle Valo 	snr = reply->snr;
1679bdcd8170SKalle Valo 
1680bdcd8170SKalle Valo 	sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1681bdcd8170SKalle Valo 
1682bdcd8170SKalle Valo 	/*
1683bdcd8170SKalle Valo 	 * Identify the threshold breached and communicate that to the app.
1684bdcd8170SKalle Valo 	 * After that install a new set of thresholds based on the signal
1685bdcd8170SKalle Valo 	 * quality reported by the target.
1686bdcd8170SKalle Valo 	 */
1687bdcd8170SKalle Valo 	if (new_threshold) {
1688bdcd8170SKalle Valo 		/* Upper threshold breached */
1689bdcd8170SKalle Valo 		if (snr < sq_thresh->upper_threshold[0]) {
1690bdcd8170SKalle Valo 			ath6kl_dbg(ATH6KL_DBG_WMI,
1691bdcd8170SKalle Valo 				   "spurious upper snr threshold event: %d\n",
1692bdcd8170SKalle Valo 				   snr);
1693bdcd8170SKalle Valo 		} else if ((snr < sq_thresh->upper_threshold[1]) &&
1694bdcd8170SKalle Valo 			   (snr >= sq_thresh->upper_threshold[0])) {
1695bdcd8170SKalle Valo 			new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1696bdcd8170SKalle Valo 		} else if ((snr < sq_thresh->upper_threshold[2]) &&
1697bdcd8170SKalle Valo 			   (snr >= sq_thresh->upper_threshold[1])) {
1698bdcd8170SKalle Valo 			new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1699bdcd8170SKalle Valo 		} else if ((snr < sq_thresh->upper_threshold[3]) &&
1700bdcd8170SKalle Valo 			   (snr >= sq_thresh->upper_threshold[2])) {
1701bdcd8170SKalle Valo 			new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1702bdcd8170SKalle Valo 		} else if (snr >= sq_thresh->upper_threshold[3]) {
1703bdcd8170SKalle Valo 			new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1704bdcd8170SKalle Valo 		}
1705bdcd8170SKalle Valo 	} else {
1706bdcd8170SKalle Valo 		/* Lower threshold breached */
1707bdcd8170SKalle Valo 		if (snr > sq_thresh->lower_threshold[0]) {
1708bdcd8170SKalle Valo 			ath6kl_dbg(ATH6KL_DBG_WMI,
1709bdcd8170SKalle Valo 				   "spurious lower snr threshold event: %d\n",
1710bdcd8170SKalle Valo 				   sq_thresh->lower_threshold[0]);
1711bdcd8170SKalle Valo 		} else if ((snr > sq_thresh->lower_threshold[1]) &&
1712bdcd8170SKalle Valo 			   (snr <= sq_thresh->lower_threshold[0])) {
1713bdcd8170SKalle Valo 			new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1714bdcd8170SKalle Valo 		} else if ((snr > sq_thresh->lower_threshold[2]) &&
1715bdcd8170SKalle Valo 			   (snr <= sq_thresh->lower_threshold[1])) {
1716bdcd8170SKalle Valo 			new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1717bdcd8170SKalle Valo 		} else if ((snr > sq_thresh->lower_threshold[3]) &&
1718bdcd8170SKalle Valo 			   (snr <= sq_thresh->lower_threshold[2])) {
1719bdcd8170SKalle Valo 			new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1720bdcd8170SKalle Valo 		} else if (snr <= sq_thresh->lower_threshold[3]) {
1721bdcd8170SKalle Valo 			new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1722bdcd8170SKalle Valo 		}
1723bdcd8170SKalle Valo 	}
1724bdcd8170SKalle Valo 
1725bdcd8170SKalle Valo 	/* Calculate and install the next set of thresholds */
1726bdcd8170SKalle Valo 	lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1727bdcd8170SKalle Valo 				       sq_thresh->lower_threshold_valid_count);
1728bdcd8170SKalle Valo 	upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1729bdcd8170SKalle Valo 				       sq_thresh->upper_threshold_valid_count);
1730bdcd8170SKalle Valo 
1731bdcd8170SKalle Valo 	/* Issue a wmi command to install the thresholds */
1732bdcd8170SKalle Valo 	cmd.thresh_above1_val = upper_snr_threshold;
1733bdcd8170SKalle Valo 	cmd.thresh_below1_val = lower_snr_threshold;
1734bdcd8170SKalle Valo 	cmd.weight = sq_thresh->weight;
1735bdcd8170SKalle Valo 	cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1736bdcd8170SKalle Valo 
1737bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
1738bdcd8170SKalle Valo 		   "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1739bdcd8170SKalle Valo 		   snr, new_threshold,
1740bdcd8170SKalle Valo 		   lower_snr_threshold, upper_snr_threshold);
1741bdcd8170SKalle Valo 
1742bdcd8170SKalle Valo 	ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1743bdcd8170SKalle Valo 	if (ret) {
1744bdcd8170SKalle Valo 		ath6kl_err("unable to configure snr threshold\n");
1745bdcd8170SKalle Valo 		return -EIO;
1746bdcd8170SKalle Valo 	}
1747bdcd8170SKalle Valo 
1748bdcd8170SKalle Valo 	return 0;
1749bdcd8170SKalle Valo }
1750bdcd8170SKalle Valo 
1751bdcd8170SKalle Valo static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1752bdcd8170SKalle Valo {
1753bdcd8170SKalle Valo 	u16 ap_info_entry_size;
1754bdcd8170SKalle Valo 	struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1755bdcd8170SKalle Valo 	struct wmi_ap_info_v1 *ap_info_v1;
1756bdcd8170SKalle Valo 	u8 index;
1757bdcd8170SKalle Valo 
1758bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_aplist_event) ||
1759bdcd8170SKalle Valo 	    ev->ap_list_ver != APLIST_VER1)
1760bdcd8170SKalle Valo 		return -EINVAL;
1761bdcd8170SKalle Valo 
1762bdcd8170SKalle Valo 	ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1763bdcd8170SKalle Valo 	ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1764bdcd8170SKalle Valo 
1765bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
1766bdcd8170SKalle Valo 		   "number of APs in aplist event: %d\n", ev->num_ap);
1767bdcd8170SKalle Valo 
1768bdcd8170SKalle Valo 	if (len < (int) (sizeof(struct wmi_aplist_event) +
1769bdcd8170SKalle Valo 			 (ev->num_ap - 1) * ap_info_entry_size))
1770bdcd8170SKalle Valo 		return -EINVAL;
1771bdcd8170SKalle Valo 
1772bdcd8170SKalle Valo 	/* AP list version 1 contents */
1773bdcd8170SKalle Valo 	for (index = 0; index < ev->num_ap; index++) {
1774bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1775bdcd8170SKalle Valo 			   index, ap_info_v1->bssid, ap_info_v1->channel);
1776bdcd8170SKalle Valo 		ap_info_v1++;
1777bdcd8170SKalle Valo 	}
1778bdcd8170SKalle Valo 
1779bdcd8170SKalle Valo 	return 0;
1780bdcd8170SKalle Valo }
1781bdcd8170SKalle Valo 
1782334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
1783bdcd8170SKalle Valo 			enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1784bdcd8170SKalle Valo {
1785bdcd8170SKalle Valo 	struct wmi_cmd_hdr *cmd_hdr;
1786bdcd8170SKalle Valo 	enum htc_endpoint_id ep_id = wmi->ep_id;
1787bdcd8170SKalle Valo 	int ret;
1788334234b5SVasanthakumar Thiagarajan 	u16 info1;
1789bdcd8170SKalle Valo 
17900616dc1fSVasanthakumar Thiagarajan 	if (WARN_ON(skb == NULL ||
17910616dc1fSVasanthakumar Thiagarajan 		    (if_idx > (wmi->parent_dev->vif_max - 1)))) {
17920616dc1fSVasanthakumar Thiagarajan 		dev_kfree_skb(skb);
1793bdcd8170SKalle Valo 		return -EINVAL;
17940616dc1fSVasanthakumar Thiagarajan 	}
1795bdcd8170SKalle Valo 
1796b9b6ee60SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
1797b9b6ee60SKalle Valo 		   cmd_id, skb->len, sync_flag);
1798b9b6ee60SKalle Valo 	ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
1799b9b6ee60SKalle Valo 			skb->data, skb->len);
1800b9b6ee60SKalle Valo 
1801bdcd8170SKalle Valo 	if (sync_flag >= END_WMIFLAG) {
1802bdcd8170SKalle Valo 		dev_kfree_skb(skb);
1803bdcd8170SKalle Valo 		return -EINVAL;
1804bdcd8170SKalle Valo 	}
1805bdcd8170SKalle Valo 
1806bdcd8170SKalle Valo 	if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1807bdcd8170SKalle Valo 	    (sync_flag == SYNC_BOTH_WMIFLAG)) {
1808bdcd8170SKalle Valo 		/*
1809bdcd8170SKalle Valo 		 * Make sure all data currently queued is transmitted before
1810bdcd8170SKalle Valo 		 * the cmd execution.  Establish a new sync point.
1811bdcd8170SKalle Valo 		 */
1812240d2799SVasanthakumar Thiagarajan 		ath6kl_wmi_sync_point(wmi, if_idx);
1813bdcd8170SKalle Valo 	}
1814bdcd8170SKalle Valo 
1815bdcd8170SKalle Valo 	skb_push(skb, sizeof(struct wmi_cmd_hdr));
1816bdcd8170SKalle Valo 
1817bdcd8170SKalle Valo 	cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1818bdcd8170SKalle Valo 	cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
1819334234b5SVasanthakumar Thiagarajan 	info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
1820334234b5SVasanthakumar Thiagarajan 	cmd_hdr->info1 = cpu_to_le16(info1);
1821bdcd8170SKalle Valo 
1822bdcd8170SKalle Valo 	/* Only for OPT_TX_CMD, use BE endpoint. */
1823bdcd8170SKalle Valo 	if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1824ce54bf5eSArnd Bergmann 		ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE, false,
1825ce54bf5eSArnd Bergmann 				WMI_DATA_HDR_DATA_TYPE_802_3, 0, NULL, if_idx);
1826bdcd8170SKalle Valo 		if (ret) {
1827bdcd8170SKalle Valo 			dev_kfree_skb(skb);
1828bdcd8170SKalle Valo 			return ret;
1829bdcd8170SKalle Valo 		}
1830bdcd8170SKalle Valo 		ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1831bdcd8170SKalle Valo 	}
1832bdcd8170SKalle Valo 
1833bdcd8170SKalle Valo 	ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1834bdcd8170SKalle Valo 
1835bdcd8170SKalle Valo 	if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1836bdcd8170SKalle Valo 	    (sync_flag == SYNC_BOTH_WMIFLAG)) {
1837bdcd8170SKalle Valo 		/*
1838bdcd8170SKalle Valo 		 * Make sure all new data queued waits for the command to
1839bdcd8170SKalle Valo 		 * execute. Establish a new sync point.
1840bdcd8170SKalle Valo 		 */
1841240d2799SVasanthakumar Thiagarajan 		ath6kl_wmi_sync_point(wmi, if_idx);
1842bdcd8170SKalle Valo 	}
1843bdcd8170SKalle Valo 
1844bdcd8170SKalle Valo 	return 0;
1845bdcd8170SKalle Valo }
1846bdcd8170SKalle Valo 
1847334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
1848334234b5SVasanthakumar Thiagarajan 			   enum network_type nw_type,
1849bdcd8170SKalle Valo 			   enum dot11_auth_mode dot11_auth_mode,
1850bdcd8170SKalle Valo 			   enum auth_mode auth_mode,
18513152a974SSagi Grimberg 			   enum ath6kl_crypto_type pairwise_crypto,
1852bdcd8170SKalle Valo 			   u8 pairwise_crypto_len,
18533152a974SSagi Grimberg 			   enum ath6kl_crypto_type group_crypto,
1854bdcd8170SKalle Valo 			   u8 group_crypto_len, int ssid_len, u8 *ssid,
18553ca9d1fcSAarthi Thiruvengadam 			   u8 *bssid, u16 channel, u32 ctrl_flags,
18563ca9d1fcSAarthi Thiruvengadam 			   u8 nw_subtype)
1857bdcd8170SKalle Valo {
1858bdcd8170SKalle Valo 	struct sk_buff *skb;
1859bdcd8170SKalle Valo 	struct wmi_connect_cmd *cc;
1860bdcd8170SKalle Valo 	int ret;
1861bdcd8170SKalle Valo 
1862b9b6ee60SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
1863b9b6ee60SKalle Valo 		   "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
1864b9b6ee60SKalle Valo 		   "type %d dot11_auth %d auth %d pairwise %d group %d\n",
1865b9b6ee60SKalle Valo 		   bssid, channel, ctrl_flags, ssid_len, nw_type,
1866b9b6ee60SKalle Valo 		   dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
1867b9b6ee60SKalle Valo 	ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
1868b9b6ee60SKalle Valo 
1869bdcd8170SKalle Valo 	wmi->traffic_class = 100;
1870bdcd8170SKalle Valo 
1871bdcd8170SKalle Valo 	if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1872bdcd8170SKalle Valo 		return -EINVAL;
1873bdcd8170SKalle Valo 
1874bdcd8170SKalle Valo 	if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1875bdcd8170SKalle Valo 		return -EINVAL;
1876bdcd8170SKalle Valo 
1877bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1878bdcd8170SKalle Valo 	if (!skb)
1879bdcd8170SKalle Valo 		return -ENOMEM;
1880bdcd8170SKalle Valo 
1881bdcd8170SKalle Valo 	cc = (struct wmi_connect_cmd *) skb->data;
1882bdcd8170SKalle Valo 
1883bdcd8170SKalle Valo 	if (ssid_len)
1884bdcd8170SKalle Valo 		memcpy(cc->ssid, ssid, ssid_len);
1885bdcd8170SKalle Valo 
1886bdcd8170SKalle Valo 	cc->ssid_len = ssid_len;
1887bdcd8170SKalle Valo 	cc->nw_type = nw_type;
1888bdcd8170SKalle Valo 	cc->dot11_auth_mode = dot11_auth_mode;
1889bdcd8170SKalle Valo 	cc->auth_mode = auth_mode;
1890bdcd8170SKalle Valo 	cc->prwise_crypto_type = pairwise_crypto;
1891bdcd8170SKalle Valo 	cc->prwise_crypto_len = pairwise_crypto_len;
1892bdcd8170SKalle Valo 	cc->grp_crypto_type = group_crypto;
1893bdcd8170SKalle Valo 	cc->grp_crypto_len = group_crypto_len;
1894bdcd8170SKalle Valo 	cc->ch = cpu_to_le16(channel);
1895bdcd8170SKalle Valo 	cc->ctrl_flags = cpu_to_le32(ctrl_flags);
18963ca9d1fcSAarthi Thiruvengadam 	cc->nw_subtype = nw_subtype;
1897bdcd8170SKalle Valo 
1898bdcd8170SKalle Valo 	if (bssid != NULL)
1899bdcd8170SKalle Valo 		memcpy(cc->bssid, bssid, ETH_ALEN);
1900bdcd8170SKalle Valo 
1901334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
1902334234b5SVasanthakumar Thiagarajan 				  NO_SYNC_WMIFLAG);
1903bdcd8170SKalle Valo 
1904bdcd8170SKalle Valo 	return ret;
1905bdcd8170SKalle Valo }
1906bdcd8170SKalle Valo 
1907334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
1908334234b5SVasanthakumar Thiagarajan 			     u16 channel)
1909bdcd8170SKalle Valo {
1910bdcd8170SKalle Valo 	struct sk_buff *skb;
1911bdcd8170SKalle Valo 	struct wmi_reconnect_cmd *cc;
1912bdcd8170SKalle Valo 	int ret;
1913bdcd8170SKalle Valo 
1914b9b6ee60SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
1915b9b6ee60SKalle Valo 		   bssid, channel);
1916b9b6ee60SKalle Valo 
1917bdcd8170SKalle Valo 	wmi->traffic_class = 100;
1918bdcd8170SKalle Valo 
1919bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1920bdcd8170SKalle Valo 	if (!skb)
1921bdcd8170SKalle Valo 		return -ENOMEM;
1922bdcd8170SKalle Valo 
1923bdcd8170SKalle Valo 	cc = (struct wmi_reconnect_cmd *) skb->data;
1924bdcd8170SKalle Valo 	cc->channel = cpu_to_le16(channel);
1925bdcd8170SKalle Valo 
1926bdcd8170SKalle Valo 	if (bssid != NULL)
1927bdcd8170SKalle Valo 		memcpy(cc->bssid, bssid, ETH_ALEN);
1928bdcd8170SKalle Valo 
1929334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
1930bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
1931bdcd8170SKalle Valo 
1932bdcd8170SKalle Valo 	return ret;
1933bdcd8170SKalle Valo }
1934bdcd8170SKalle Valo 
1935334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
1936bdcd8170SKalle Valo {
1937bdcd8170SKalle Valo 	int ret;
1938bdcd8170SKalle Valo 
1939b9b6ee60SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
1940b9b6ee60SKalle Valo 
1941bdcd8170SKalle Valo 	wmi->traffic_class = 100;
1942bdcd8170SKalle Valo 
1943bdcd8170SKalle Valo 	/* Disconnect command does not need to do a SYNC before. */
1944334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
1945bdcd8170SKalle Valo 
1946bdcd8170SKalle Valo 	return ret;
1947bdcd8170SKalle Valo }
1948bdcd8170SKalle Valo 
1949c8c72b74SKalle Valo /* ath6kl_wmi_start_scan_cmd is to be deprecated. Use
1950c8c72b74SKalle Valo  * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P
1951c8c72b74SKalle Valo  * mgmt operations using station interface.
1952c8c72b74SKalle Valo  */
195311f0bfcfSKalle Valo static int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
1954c8c72b74SKalle Valo 				    enum wmi_scan_type scan_type,
1955c8c72b74SKalle Valo 				    u32 force_fgscan, u32 is_legacy,
195611f0bfcfSKalle Valo 				    u32 home_dwell_time,
195711f0bfcfSKalle Valo 				    u32 force_scan_interval,
1958c8c72b74SKalle Valo 				    s8 num_chan, u16 *ch_list)
1959c8c72b74SKalle Valo {
1960c8c72b74SKalle Valo 	struct sk_buff *skb;
1961c8c72b74SKalle Valo 	struct wmi_start_scan_cmd *sc;
1962c8c72b74SKalle Valo 	int i, ret;
1963c8c72b74SKalle Valo 
1964c8c72b74SKalle Valo 	if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1965c8c72b74SKalle Valo 		return -EINVAL;
1966c8c72b74SKalle Valo 
1967c8c72b74SKalle Valo 	if (num_chan > WMI_MAX_CHANNELS)
1968c8c72b74SKalle Valo 		return -EINVAL;
1969c8c72b74SKalle Valo 
1970*56f1257fSGustavo A. R. Silva 	skb = ath6kl_wmi_get_new_buf(struct_size(sc, ch_list, num_chan));
1971c8c72b74SKalle Valo 	if (!skb)
1972c8c72b74SKalle Valo 		return -ENOMEM;
1973c8c72b74SKalle Valo 
1974c8c72b74SKalle Valo 	sc = (struct wmi_start_scan_cmd *) skb->data;
1975c8c72b74SKalle Valo 	sc->scan_type = scan_type;
1976c8c72b74SKalle Valo 	sc->force_fg_scan = cpu_to_le32(force_fgscan);
1977c8c72b74SKalle Valo 	sc->is_legacy = cpu_to_le32(is_legacy);
1978c8c72b74SKalle Valo 	sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1979c8c72b74SKalle Valo 	sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1980c8c72b74SKalle Valo 	sc->num_ch = num_chan;
1981c8c72b74SKalle Valo 
1982c8c72b74SKalle Valo 	for (i = 0; i < num_chan; i++)
1983c8c72b74SKalle Valo 		sc->ch_list[i] = cpu_to_le16(ch_list[i]);
1984c8c72b74SKalle Valo 
1985c8c72b74SKalle Valo 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
1986c8c72b74SKalle Valo 				  NO_SYNC_WMIFLAG);
1987c8c72b74SKalle Valo 
1988c8c72b74SKalle Valo 	return ret;
1989c8c72b74SKalle Valo }
1990c8c72b74SKalle Valo 
199111f0bfcfSKalle Valo /*
199211f0bfcfSKalle Valo  * beginscan supports (compared to old startscan) P2P mgmt operations using
199311f0bfcfSKalle Valo  * station interface, send additional information like supported rates to
199411f0bfcfSKalle Valo  * advertise and xmit rates for probe requests
199511f0bfcfSKalle Valo  */
19963ca9d1fcSAarthi Thiruvengadam int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx,
19973ca9d1fcSAarthi Thiruvengadam 			     enum wmi_scan_type scan_type,
19983ca9d1fcSAarthi Thiruvengadam 			     u32 force_fgscan, u32 is_legacy,
19993ca9d1fcSAarthi Thiruvengadam 			     u32 home_dwell_time, u32 force_scan_interval,
20003ca9d1fcSAarthi Thiruvengadam 			     s8 num_chan, u16 *ch_list, u32 no_cck, u32 *rates)
20013ca9d1fcSAarthi Thiruvengadam {
200203e2084aSThomas Pedersen 	struct ieee80211_supported_band *sband;
20033ca9d1fcSAarthi Thiruvengadam 	struct sk_buff *skb;
20043ca9d1fcSAarthi Thiruvengadam 	struct wmi_begin_scan_cmd *sc;
2005324edddfSGustavo A. R. Silva 	s8 *supp_rates;
20063ca9d1fcSAarthi Thiruvengadam 	int i, band, ret;
20073ca9d1fcSAarthi Thiruvengadam 	struct ath6kl *ar = wmi->parent_dev;
20083ca9d1fcSAarthi Thiruvengadam 	int num_rates;
200903e2084aSThomas Pedersen 	u32 ratemask;
20103ca9d1fcSAarthi Thiruvengadam 
201111f0bfcfSKalle Valo 	if (!test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
201211f0bfcfSKalle Valo 		      ar->fw_capabilities)) {
201311f0bfcfSKalle Valo 		return ath6kl_wmi_startscan_cmd(wmi, if_idx,
201411f0bfcfSKalle Valo 						scan_type, force_fgscan,
201511f0bfcfSKalle Valo 						is_legacy, home_dwell_time,
201611f0bfcfSKalle Valo 						force_scan_interval,
201711f0bfcfSKalle Valo 						num_chan, ch_list);
201811f0bfcfSKalle Valo 	}
201911f0bfcfSKalle Valo 
20203ca9d1fcSAarthi Thiruvengadam 	if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
20213ca9d1fcSAarthi Thiruvengadam 		return -EINVAL;
20223ca9d1fcSAarthi Thiruvengadam 
20233ca9d1fcSAarthi Thiruvengadam 	if (num_chan > WMI_MAX_CHANNELS)
20243ca9d1fcSAarthi Thiruvengadam 		return -EINVAL;
20253ca9d1fcSAarthi Thiruvengadam 
2026324edddfSGustavo A. R. Silva 	skb = ath6kl_wmi_get_new_buf(struct_size(sc, ch_list, num_chan));
20273ca9d1fcSAarthi Thiruvengadam 	if (!skb)
20283ca9d1fcSAarthi Thiruvengadam 		return -ENOMEM;
20293ca9d1fcSAarthi Thiruvengadam 
20303ca9d1fcSAarthi Thiruvengadam 	sc = (struct wmi_begin_scan_cmd *) skb->data;
20313ca9d1fcSAarthi Thiruvengadam 	sc->scan_type = scan_type;
20323ca9d1fcSAarthi Thiruvengadam 	sc->force_fg_scan = cpu_to_le32(force_fgscan);
20333ca9d1fcSAarthi Thiruvengadam 	sc->is_legacy = cpu_to_le32(is_legacy);
20343ca9d1fcSAarthi Thiruvengadam 	sc->home_dwell_time = cpu_to_le32(home_dwell_time);
20353ca9d1fcSAarthi Thiruvengadam 	sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
20363ca9d1fcSAarthi Thiruvengadam 	sc->no_cck = cpu_to_le32(no_cck);
20373ca9d1fcSAarthi Thiruvengadam 	sc->num_ch = num_chan;
20383ca9d1fcSAarthi Thiruvengadam 
203957fbcce3SJohannes Berg 	for (band = 0; band < NUM_NL80211_BANDS; band++) {
204003e2084aSThomas Pedersen 		sband = ar->wiphy->bands[band];
204103e2084aSThomas Pedersen 
204203e2084aSThomas Pedersen 		if (!sband)
204303e2084aSThomas Pedersen 			continue;
204403e2084aSThomas Pedersen 
204599089ab7SKalle Valo 		if (WARN_ON(band >= ATH6KL_NUM_BANDS))
204699089ab7SKalle Valo 			break;
204799089ab7SKalle Valo 
204803e2084aSThomas Pedersen 		ratemask = rates[band];
204903e2084aSThomas Pedersen 		supp_rates = sc->supp_rates[band].rates;
20503ca9d1fcSAarthi Thiruvengadam 		num_rates = 0;
20513ca9d1fcSAarthi Thiruvengadam 
20523ca9d1fcSAarthi Thiruvengadam 		for (i = 0; i < sband->n_bitrates; i++) {
20533ca9d1fcSAarthi Thiruvengadam 			if ((BIT(i) & ratemask) == 0)
20543ca9d1fcSAarthi Thiruvengadam 				continue; /* skip rate */
20553ca9d1fcSAarthi Thiruvengadam 			supp_rates[num_rates++] =
20563ca9d1fcSAarthi Thiruvengadam 			    (u8) (sband->bitrates[i].bitrate / 5);
20573ca9d1fcSAarthi Thiruvengadam 		}
20583ca9d1fcSAarthi Thiruvengadam 		sc->supp_rates[band].nrates = num_rates;
20593ca9d1fcSAarthi Thiruvengadam 	}
20603ca9d1fcSAarthi Thiruvengadam 
20613ca9d1fcSAarthi Thiruvengadam 	for (i = 0; i < num_chan; i++)
20623ca9d1fcSAarthi Thiruvengadam 		sc->ch_list[i] = cpu_to_le16(ch_list[i]);
20633ca9d1fcSAarthi Thiruvengadam 
20643ca9d1fcSAarthi Thiruvengadam 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID,
20653ca9d1fcSAarthi Thiruvengadam 				  NO_SYNC_WMIFLAG);
20663ca9d1fcSAarthi Thiruvengadam 
20673ca9d1fcSAarthi Thiruvengadam 	return ret;
20683ca9d1fcSAarthi Thiruvengadam }
20693ca9d1fcSAarthi Thiruvengadam 
2070b1f47e3aSThomas Pedersen int ath6kl_wmi_enable_sched_scan_cmd(struct wmi *wmi, u8 if_idx, bool enable)
2071b1f47e3aSThomas Pedersen {
2072b1f47e3aSThomas Pedersen 	struct sk_buff *skb;
2073b1f47e3aSThomas Pedersen 	struct wmi_enable_sched_scan_cmd *sc;
2074b1f47e3aSThomas Pedersen 	int ret;
2075b1f47e3aSThomas Pedersen 
2076b1f47e3aSThomas Pedersen 	skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
2077b1f47e3aSThomas Pedersen 	if (!skb)
2078b1f47e3aSThomas Pedersen 		return -ENOMEM;
2079b1f47e3aSThomas Pedersen 
2080b1f47e3aSThomas Pedersen 	ath6kl_dbg(ATH6KL_DBG_WMI, "%s scheduled scan on vif %d\n",
2081b1f47e3aSThomas Pedersen 		   enable ? "enabling" : "disabling", if_idx);
2082b1f47e3aSThomas Pedersen 	sc = (struct wmi_enable_sched_scan_cmd *) skb->data;
2083b1f47e3aSThomas Pedersen 	sc->enable = enable ? 1 : 0;
2084b1f47e3aSThomas Pedersen 
2085b1f47e3aSThomas Pedersen 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2086b1f47e3aSThomas Pedersen 				  WMI_ENABLE_SCHED_SCAN_CMDID,
2087b1f47e3aSThomas Pedersen 				  NO_SYNC_WMIFLAG);
2088b1f47e3aSThomas Pedersen 	return ret;
2089b1f47e3aSThomas Pedersen }
2090b1f47e3aSThomas Pedersen 
2091334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
2092334234b5SVasanthakumar Thiagarajan 			      u16 fg_start_sec,
2093bdcd8170SKalle Valo 			      u16 fg_end_sec, u16 bg_sec,
2094bdcd8170SKalle Valo 			      u16 minact_chdw_msec, u16 maxact_chdw_msec,
2095bdcd8170SKalle Valo 			      u16 pas_chdw_msec, u8 short_scan_ratio,
2096bdcd8170SKalle Valo 			      u8 scan_ctrl_flag, u32 max_dfsch_act_time,
2097bdcd8170SKalle Valo 			      u16 maxact_scan_per_ssid)
2098bdcd8170SKalle Valo {
2099bdcd8170SKalle Valo 	struct sk_buff *skb;
2100bdcd8170SKalle Valo 	struct wmi_scan_params_cmd *sc;
2101bdcd8170SKalle Valo 	int ret;
2102bdcd8170SKalle Valo 
2103bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
2104bdcd8170SKalle Valo 	if (!skb)
2105bdcd8170SKalle Valo 		return -ENOMEM;
2106bdcd8170SKalle Valo 
2107bdcd8170SKalle Valo 	sc = (struct wmi_scan_params_cmd *) skb->data;
2108bdcd8170SKalle Valo 	sc->fg_start_period = cpu_to_le16(fg_start_sec);
2109bdcd8170SKalle Valo 	sc->fg_end_period = cpu_to_le16(fg_end_sec);
2110bdcd8170SKalle Valo 	sc->bg_period = cpu_to_le16(bg_sec);
2111bdcd8170SKalle Valo 	sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
2112bdcd8170SKalle Valo 	sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
2113bdcd8170SKalle Valo 	sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
2114bdcd8170SKalle Valo 	sc->short_scan_ratio = short_scan_ratio;
2115bdcd8170SKalle Valo 	sc->scan_ctrl_flags = scan_ctrl_flag;
2116bdcd8170SKalle Valo 	sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
2117bdcd8170SKalle Valo 	sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
2118bdcd8170SKalle Valo 
2119334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
2120bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
2121bdcd8170SKalle Valo 	return ret;
2122bdcd8170SKalle Valo }
2123bdcd8170SKalle Valo 
2124240d2799SVasanthakumar Thiagarajan int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
2125bdcd8170SKalle Valo {
2126bdcd8170SKalle Valo 	struct sk_buff *skb;
2127bdcd8170SKalle Valo 	struct wmi_bss_filter_cmd *cmd;
2128bdcd8170SKalle Valo 	int ret;
2129bdcd8170SKalle Valo 
2130bdcd8170SKalle Valo 	if (filter >= LAST_BSS_FILTER)
2131bdcd8170SKalle Valo 		return -EINVAL;
2132bdcd8170SKalle Valo 
2133bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2134bdcd8170SKalle Valo 	if (!skb)
2135bdcd8170SKalle Valo 		return -ENOMEM;
2136bdcd8170SKalle Valo 
2137bdcd8170SKalle Valo 	cmd = (struct wmi_bss_filter_cmd *) skb->data;
2138bdcd8170SKalle Valo 	cmd->bss_filter = filter;
2139bdcd8170SKalle Valo 	cmd->ie_mask = cpu_to_le32(ie_mask);
2140bdcd8170SKalle Valo 
2141240d2799SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
2142bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
2143bdcd8170SKalle Valo 	return ret;
2144bdcd8170SKalle Valo }
2145bdcd8170SKalle Valo 
2146334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
2147bdcd8170SKalle Valo 			      u8 ssid_len, u8 *ssid)
2148bdcd8170SKalle Valo {
2149bdcd8170SKalle Valo 	struct sk_buff *skb;
2150bdcd8170SKalle Valo 	struct wmi_probed_ssid_cmd *cmd;
2151bdcd8170SKalle Valo 	int ret;
2152bdcd8170SKalle Valo 
21538ab5415dSJouni Malinen 	if (index >= MAX_PROBED_SSIDS)
2154bdcd8170SKalle Valo 		return -EINVAL;
2155bdcd8170SKalle Valo 
2156bdcd8170SKalle Valo 	if (ssid_len > sizeof(cmd->ssid))
2157bdcd8170SKalle Valo 		return -EINVAL;
2158bdcd8170SKalle Valo 
2159bdcd8170SKalle Valo 	if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
2160bdcd8170SKalle Valo 		return -EINVAL;
2161bdcd8170SKalle Valo 
2162bdcd8170SKalle Valo 	if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
2163bdcd8170SKalle Valo 		return -EINVAL;
2164bdcd8170SKalle Valo 
2165bdcd8170SKalle Valo 	if (flag & SPECIFIC_SSID_FLAG)
2166bdcd8170SKalle Valo 		wmi->is_probe_ssid = true;
2167bdcd8170SKalle Valo 
2168bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2169bdcd8170SKalle Valo 	if (!skb)
2170bdcd8170SKalle Valo 		return -ENOMEM;
2171bdcd8170SKalle Valo 
2172bdcd8170SKalle Valo 	cmd = (struct wmi_probed_ssid_cmd *) skb->data;
2173bdcd8170SKalle Valo 	cmd->entry_index = index;
2174bdcd8170SKalle Valo 	cmd->flag = flag;
2175bdcd8170SKalle Valo 	cmd->ssid_len = ssid_len;
2176bdcd8170SKalle Valo 	memcpy(cmd->ssid, ssid, ssid_len);
2177bdcd8170SKalle Valo 
2178334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
2179bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
2180bdcd8170SKalle Valo 	return ret;
2181bdcd8170SKalle Valo }
2182bdcd8170SKalle Valo 
2183334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
2184334234b5SVasanthakumar Thiagarajan 				  u16 listen_interval,
2185bdcd8170SKalle Valo 				  u16 listen_beacons)
2186bdcd8170SKalle Valo {
2187bdcd8170SKalle Valo 	struct sk_buff *skb;
2188bdcd8170SKalle Valo 	struct wmi_listen_int_cmd *cmd;
2189bdcd8170SKalle Valo 	int ret;
2190bdcd8170SKalle Valo 
2191bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2192bdcd8170SKalle Valo 	if (!skb)
2193bdcd8170SKalle Valo 		return -ENOMEM;
2194bdcd8170SKalle Valo 
2195bdcd8170SKalle Valo 	cmd = (struct wmi_listen_int_cmd *) skb->data;
2196bdcd8170SKalle Valo 	cmd->listen_intvl = cpu_to_le16(listen_interval);
2197bdcd8170SKalle Valo 	cmd->num_beacons = cpu_to_le16(listen_beacons);
2198bdcd8170SKalle Valo 
2199334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
2200bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
2201bdcd8170SKalle Valo 	return ret;
2202bdcd8170SKalle Valo }
2203bdcd8170SKalle Valo 
2204ce0dc0cfSRaja Mani int ath6kl_wmi_bmisstime_cmd(struct wmi *wmi, u8 if_idx,
2205ce0dc0cfSRaja Mani 			     u16 bmiss_time, u16 num_beacons)
2206ce0dc0cfSRaja Mani {
2207ce0dc0cfSRaja Mani 	struct sk_buff *skb;
2208ce0dc0cfSRaja Mani 	struct wmi_bmiss_time_cmd *cmd;
2209ce0dc0cfSRaja Mani 	int ret;
2210ce0dc0cfSRaja Mani 
2211ce0dc0cfSRaja Mani 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2212ce0dc0cfSRaja Mani 	if (!skb)
2213ce0dc0cfSRaja Mani 		return -ENOMEM;
2214ce0dc0cfSRaja Mani 
2215ce0dc0cfSRaja Mani 	cmd = (struct wmi_bmiss_time_cmd *) skb->data;
2216ce0dc0cfSRaja Mani 	cmd->bmiss_time = cpu_to_le16(bmiss_time);
2217ce0dc0cfSRaja Mani 	cmd->num_beacons = cpu_to_le16(num_beacons);
2218ce0dc0cfSRaja Mani 
2219ce0dc0cfSRaja Mani 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BMISS_TIME_CMDID,
2220ce0dc0cfSRaja Mani 				  NO_SYNC_WMIFLAG);
2221ce0dc0cfSRaja Mani 	return ret;
2222ce0dc0cfSRaja Mani }
2223ce0dc0cfSRaja Mani 
2224334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
2225bdcd8170SKalle Valo {
2226bdcd8170SKalle Valo 	struct sk_buff *skb;
2227bdcd8170SKalle Valo 	struct wmi_power_mode_cmd *cmd;
2228bdcd8170SKalle Valo 	int ret;
2229bdcd8170SKalle Valo 
2230bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2231bdcd8170SKalle Valo 	if (!skb)
2232bdcd8170SKalle Valo 		return -ENOMEM;
2233bdcd8170SKalle Valo 
2234bdcd8170SKalle Valo 	cmd = (struct wmi_power_mode_cmd *) skb->data;
2235bdcd8170SKalle Valo 	cmd->pwr_mode = pwr_mode;
2236bdcd8170SKalle Valo 	wmi->pwr_mode = pwr_mode;
2237bdcd8170SKalle Valo 
2238334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
2239bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
2240bdcd8170SKalle Valo 	return ret;
2241bdcd8170SKalle Valo }
2242bdcd8170SKalle Valo 
22430ce59445SVasanthakumar Thiagarajan int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
2244bdcd8170SKalle Valo 			    u16 ps_poll_num, u16 dtim_policy,
2245bdcd8170SKalle Valo 			    u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
2246bdcd8170SKalle Valo 			    u16 ps_fail_event_policy)
2247bdcd8170SKalle Valo {
2248bdcd8170SKalle Valo 	struct sk_buff *skb;
2249bdcd8170SKalle Valo 	struct wmi_power_params_cmd *pm;
2250bdcd8170SKalle Valo 	int ret;
2251bdcd8170SKalle Valo 
2252bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
2253bdcd8170SKalle Valo 	if (!skb)
2254bdcd8170SKalle Valo 		return -ENOMEM;
2255bdcd8170SKalle Valo 
2256bdcd8170SKalle Valo 	pm = (struct wmi_power_params_cmd *)skb->data;
2257bdcd8170SKalle Valo 	pm->idle_period = cpu_to_le16(idle_period);
2258bdcd8170SKalle Valo 	pm->pspoll_number = cpu_to_le16(ps_poll_num);
2259bdcd8170SKalle Valo 	pm->dtim_policy = cpu_to_le16(dtim_policy);
2260bdcd8170SKalle Valo 	pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
2261bdcd8170SKalle Valo 	pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
2262bdcd8170SKalle Valo 	pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
2263bdcd8170SKalle Valo 
22640ce59445SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
2265bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
2266bdcd8170SKalle Valo 	return ret;
2267bdcd8170SKalle Valo }
2268bdcd8170SKalle Valo 
22690ce59445SVasanthakumar Thiagarajan int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
2270bdcd8170SKalle Valo {
2271bdcd8170SKalle Valo 	struct sk_buff *skb;
2272bdcd8170SKalle Valo 	struct wmi_disc_timeout_cmd *cmd;
2273bdcd8170SKalle Valo 	int ret;
2274bdcd8170SKalle Valo 
2275bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2276bdcd8170SKalle Valo 	if (!skb)
2277bdcd8170SKalle Valo 		return -ENOMEM;
2278bdcd8170SKalle Valo 
2279bdcd8170SKalle Valo 	cmd = (struct wmi_disc_timeout_cmd *) skb->data;
2280bdcd8170SKalle Valo 	cmd->discon_timeout = timeout;
2281bdcd8170SKalle Valo 
22820ce59445SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
2283bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
2284334234b5SVasanthakumar Thiagarajan 
2285ff0b0075SJouni Malinen 	if (ret == 0)
2286ff0b0075SJouni Malinen 		ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
2287334234b5SVasanthakumar Thiagarajan 
2288bdcd8170SKalle Valo 	return ret;
2289bdcd8170SKalle Valo }
2290bdcd8170SKalle Valo 
2291334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
22923152a974SSagi Grimberg 			  enum ath6kl_crypto_type key_type,
2293bdcd8170SKalle Valo 			  u8 key_usage, u8 key_len,
2294f4bb9a6fSJouni Malinen 			  u8 *key_rsc, unsigned int key_rsc_len,
2295f4bb9a6fSJouni Malinen 			  u8 *key_material,
2296bdcd8170SKalle Valo 			  u8 key_op_ctrl, u8 *mac_addr,
2297bdcd8170SKalle Valo 			  enum wmi_sync_flag sync_flag)
2298bdcd8170SKalle Valo {
2299bdcd8170SKalle Valo 	struct sk_buff *skb;
2300bdcd8170SKalle Valo 	struct wmi_add_cipher_key_cmd *cmd;
2301bdcd8170SKalle Valo 	int ret;
2302bdcd8170SKalle Valo 
2303cdeb8602SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
2304cdeb8602SKalle Valo 		   "addkey cmd: key_index=%u key_type=%d key_usage=%d key_len=%d key_op_ctrl=%d\n",
23059a5b1318SJouni Malinen 		   key_index, key_type, key_usage, key_len, key_op_ctrl);
23069a5b1318SJouni Malinen 
2307bdcd8170SKalle Valo 	if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
2308f4bb9a6fSJouni Malinen 	    (key_material == NULL) || key_rsc_len > 8)
2309bdcd8170SKalle Valo 		return -EINVAL;
2310bdcd8170SKalle Valo 
2311bdcd8170SKalle Valo 	if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
2312bdcd8170SKalle Valo 		return -EINVAL;
2313bdcd8170SKalle Valo 
2314bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2315bdcd8170SKalle Valo 	if (!skb)
2316bdcd8170SKalle Valo 		return -ENOMEM;
2317bdcd8170SKalle Valo 
2318bdcd8170SKalle Valo 	cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
2319bdcd8170SKalle Valo 	cmd->key_index = key_index;
2320bdcd8170SKalle Valo 	cmd->key_type = key_type;
2321bdcd8170SKalle Valo 	cmd->key_usage = key_usage;
2322bdcd8170SKalle Valo 	cmd->key_len = key_len;
2323bdcd8170SKalle Valo 	memcpy(cmd->key, key_material, key_len);
2324bdcd8170SKalle Valo 
2325bdcd8170SKalle Valo 	if (key_rsc != NULL)
2326f4bb9a6fSJouni Malinen 		memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
2327bdcd8170SKalle Valo 
2328bdcd8170SKalle Valo 	cmd->key_op_ctrl = key_op_ctrl;
2329bdcd8170SKalle Valo 
2330bdcd8170SKalle Valo 	if (mac_addr)
2331bdcd8170SKalle Valo 		memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
2332bdcd8170SKalle Valo 
2333334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
2334bdcd8170SKalle Valo 				  sync_flag);
2335bdcd8170SKalle Valo 
2336bdcd8170SKalle Valo 	return ret;
2337bdcd8170SKalle Valo }
2338bdcd8170SKalle Valo 
2339c1e5f471SJohannes Berg int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, const u8 *krk)
2340bdcd8170SKalle Valo {
2341bdcd8170SKalle Valo 	struct sk_buff *skb;
2342bdcd8170SKalle Valo 	struct wmi_add_krk_cmd *cmd;
2343bdcd8170SKalle Valo 	int ret;
2344bdcd8170SKalle Valo 
2345bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2346bdcd8170SKalle Valo 	if (!skb)
2347bdcd8170SKalle Valo 		return -ENOMEM;
2348bdcd8170SKalle Valo 
2349bdcd8170SKalle Valo 	cmd = (struct wmi_add_krk_cmd *) skb->data;
2350bdcd8170SKalle Valo 	memcpy(cmd->krk, krk, WMI_KRK_LEN);
2351bdcd8170SKalle Valo 
2352240d2799SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
2353334234b5SVasanthakumar Thiagarajan 				  NO_SYNC_WMIFLAG);
2354bdcd8170SKalle Valo 
2355bdcd8170SKalle Valo 	return ret;
2356bdcd8170SKalle Valo }
2357bdcd8170SKalle Valo 
2358334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
2359bdcd8170SKalle Valo {
2360bdcd8170SKalle Valo 	struct sk_buff *skb;
2361bdcd8170SKalle Valo 	struct wmi_delete_cipher_key_cmd *cmd;
2362bdcd8170SKalle Valo 	int ret;
2363bdcd8170SKalle Valo 
2364bdcd8170SKalle Valo 	if (key_index > WMI_MAX_KEY_INDEX)
2365bdcd8170SKalle Valo 		return -EINVAL;
2366bdcd8170SKalle Valo 
2367bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2368bdcd8170SKalle Valo 	if (!skb)
2369bdcd8170SKalle Valo 		return -ENOMEM;
2370bdcd8170SKalle Valo 
2371bdcd8170SKalle Valo 	cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
2372bdcd8170SKalle Valo 	cmd->key_index = key_index;
2373bdcd8170SKalle Valo 
2374334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
2375bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
2376bdcd8170SKalle Valo 
2377bdcd8170SKalle Valo 	return ret;
2378bdcd8170SKalle Valo }
2379bdcd8170SKalle Valo 
2380334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
2381bdcd8170SKalle Valo 			    const u8 *pmkid, bool set)
2382bdcd8170SKalle Valo {
2383bdcd8170SKalle Valo 	struct sk_buff *skb;
2384bdcd8170SKalle Valo 	struct wmi_setpmkid_cmd *cmd;
2385bdcd8170SKalle Valo 	int ret;
2386bdcd8170SKalle Valo 
2387bdcd8170SKalle Valo 	if (bssid == NULL)
2388bdcd8170SKalle Valo 		return -EINVAL;
2389bdcd8170SKalle Valo 
2390bdcd8170SKalle Valo 	if (set && pmkid == NULL)
2391bdcd8170SKalle Valo 		return -EINVAL;
2392bdcd8170SKalle Valo 
2393bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2394bdcd8170SKalle Valo 	if (!skb)
2395bdcd8170SKalle Valo 		return -ENOMEM;
2396bdcd8170SKalle Valo 
2397bdcd8170SKalle Valo 	cmd = (struct wmi_setpmkid_cmd *) skb->data;
2398bdcd8170SKalle Valo 	memcpy(cmd->bssid, bssid, ETH_ALEN);
2399bdcd8170SKalle Valo 	if (set) {
2400bdcd8170SKalle Valo 		memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2401bdcd8170SKalle Valo 		cmd->enable = PMKID_ENABLE;
2402bdcd8170SKalle Valo 	} else {
2403bdcd8170SKalle Valo 		memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2404bdcd8170SKalle Valo 		cmd->enable = PMKID_DISABLE;
2405bdcd8170SKalle Valo 	}
2406bdcd8170SKalle Valo 
2407334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
2408bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
2409bdcd8170SKalle Valo 
2410bdcd8170SKalle Valo 	return ret;
2411bdcd8170SKalle Valo }
2412bdcd8170SKalle Valo 
2413bdcd8170SKalle Valo static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
24146765d0aaSVasanthakumar Thiagarajan 			      enum htc_endpoint_id ep_id, u8 if_idx)
2415bdcd8170SKalle Valo {
2416bdcd8170SKalle Valo 	struct wmi_data_hdr *data_hdr;
2417bdcd8170SKalle Valo 	int ret;
2418bdcd8170SKalle Valo 
24190616dc1fSVasanthakumar Thiagarajan 	if (WARN_ON(skb == NULL || ep_id == wmi->ep_id)) {
24200616dc1fSVasanthakumar Thiagarajan 		dev_kfree_skb(skb);
2421bdcd8170SKalle Valo 		return -EINVAL;
24220616dc1fSVasanthakumar Thiagarajan 	}
2423bdcd8170SKalle Valo 
2424bdcd8170SKalle Valo 	skb_push(skb, sizeof(struct wmi_data_hdr));
2425bdcd8170SKalle Valo 
2426bdcd8170SKalle Valo 	data_hdr = (struct wmi_data_hdr *) skb->data;
2427bdcd8170SKalle Valo 	data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
24286765d0aaSVasanthakumar Thiagarajan 	data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
2429bdcd8170SKalle Valo 
2430bdcd8170SKalle Valo 	ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2431bdcd8170SKalle Valo 
2432bdcd8170SKalle Valo 	return ret;
2433bdcd8170SKalle Valo }
2434bdcd8170SKalle Valo 
2435240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
2436bdcd8170SKalle Valo {
2437bdcd8170SKalle Valo 	struct sk_buff *skb;
2438bdcd8170SKalle Valo 	struct wmi_sync_cmd *cmd;
2439bdcd8170SKalle Valo 	struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2440bdcd8170SKalle Valo 	enum htc_endpoint_id ep_id;
2441bdcd8170SKalle Valo 	u8 index, num_pri_streams = 0;
2442bdcd8170SKalle Valo 	int ret = 0;
2443bdcd8170SKalle Valo 
2444bdcd8170SKalle Valo 	memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2445bdcd8170SKalle Valo 
2446bdcd8170SKalle Valo 	spin_lock_bh(&wmi->lock);
2447bdcd8170SKalle Valo 
2448bdcd8170SKalle Valo 	for (index = 0; index < WMM_NUM_AC; index++) {
2449bdcd8170SKalle Valo 		if (wmi->fat_pipe_exist & (1 << index)) {
2450bdcd8170SKalle Valo 			num_pri_streams++;
2451bdcd8170SKalle Valo 			data_sync_bufs[num_pri_streams - 1].traffic_class =
2452bdcd8170SKalle Valo 			    index;
2453bdcd8170SKalle Valo 		}
2454bdcd8170SKalle Valo 	}
2455bdcd8170SKalle Valo 
2456bdcd8170SKalle Valo 	spin_unlock_bh(&wmi->lock);
2457bdcd8170SKalle Valo 
2458bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
24590616dc1fSVasanthakumar Thiagarajan 	if (!skb)
24600616dc1fSVasanthakumar Thiagarajan 		return -ENOMEM;
2461bdcd8170SKalle Valo 
2462bdcd8170SKalle Valo 	cmd = (struct wmi_sync_cmd *) skb->data;
2463bdcd8170SKalle Valo 
2464bdcd8170SKalle Valo 	/*
2465bdcd8170SKalle Valo 	 * In the SYNC cmd sent on the control Ep, send a bitmap
2466bdcd8170SKalle Valo 	 * of the data eps on which the Data Sync will be sent
2467bdcd8170SKalle Valo 	 */
2468bdcd8170SKalle Valo 	cmd->data_sync_map = wmi->fat_pipe_exist;
2469bdcd8170SKalle Valo 
2470bdcd8170SKalle Valo 	for (index = 0; index < num_pri_streams; index++) {
2471bdcd8170SKalle Valo 		data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2472bdcd8170SKalle Valo 		if (data_sync_bufs[index].skb == NULL) {
2473bdcd8170SKalle Valo 			ret = -ENOMEM;
2474bdcd8170SKalle Valo 			break;
2475bdcd8170SKalle Valo 		}
2476bdcd8170SKalle Valo 	}
2477bdcd8170SKalle Valo 
2478bdcd8170SKalle Valo 	/*
2479bdcd8170SKalle Valo 	 * If buffer allocation for any of the dataSync fails,
2480bdcd8170SKalle Valo 	 * then do not send the Synchronize cmd on the control ep
2481bdcd8170SKalle Valo 	 */
2482bdcd8170SKalle Valo 	if (ret)
24830616dc1fSVasanthakumar Thiagarajan 		goto free_cmd_skb;
2484bdcd8170SKalle Valo 
2485bdcd8170SKalle Valo 	/*
2486bdcd8170SKalle Valo 	 * Send sync cmd followed by sync data messages on all
2487bdcd8170SKalle Valo 	 * endpoints being used
2488bdcd8170SKalle Valo 	 */
2489240d2799SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
2490bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
2491bdcd8170SKalle Valo 
2492bdcd8170SKalle Valo 	if (ret)
24930616dc1fSVasanthakumar Thiagarajan 		goto free_data_skb;
2494bdcd8170SKalle Valo 
2495bdcd8170SKalle Valo 	for (index = 0; index < num_pri_streams; index++) {
2496fd6729ecSDan Carpenter 		if (WARN_ON(!data_sync_bufs[index].skb)) {
2497fd6729ecSDan Carpenter 			ret = -ENOMEM;
24980616dc1fSVasanthakumar Thiagarajan 			goto free_data_skb;
2499fd6729ecSDan Carpenter 		}
2500bdcd8170SKalle Valo 
2501bdcd8170SKalle Valo 		ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2502bdcd8170SKalle Valo 					       data_sync_bufs[index].
2503bdcd8170SKalle Valo 					       traffic_class);
2504bdcd8170SKalle Valo 		ret =
2505bdcd8170SKalle Valo 		    ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
25066765d0aaSVasanthakumar Thiagarajan 					      ep_id, if_idx);
2507bdcd8170SKalle Valo 
2508bdcd8170SKalle Valo 		data_sync_bufs[index].skb = NULL;
25090616dc1fSVasanthakumar Thiagarajan 
25100616dc1fSVasanthakumar Thiagarajan 		if (ret)
25110616dc1fSVasanthakumar Thiagarajan 			goto free_data_skb;
2512bdcd8170SKalle Valo 	}
2513bdcd8170SKalle Valo 
25140616dc1fSVasanthakumar Thiagarajan 	return 0;
25150616dc1fSVasanthakumar Thiagarajan 
25160616dc1fSVasanthakumar Thiagarajan free_cmd_skb:
2517bdcd8170SKalle Valo 	/* free up any resources left over (possibly due to an error) */
2518bdcd8170SKalle Valo 	dev_kfree_skb(skb);
2519bdcd8170SKalle Valo 
25200616dc1fSVasanthakumar Thiagarajan free_data_skb:
2521e16ccfeeSMohammed Shafi Shajakhan 	for (index = 0; index < num_pri_streams; index++)
2522e16ccfeeSMohammed Shafi Shajakhan 		dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].skb);
2523bdcd8170SKalle Valo 
2524bdcd8170SKalle Valo 	return ret;
2525bdcd8170SKalle Valo }
2526bdcd8170SKalle Valo 
2527240d2799SVasanthakumar Thiagarajan int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
2528bdcd8170SKalle Valo 				  struct wmi_create_pstream_cmd *params)
2529bdcd8170SKalle Valo {
2530bdcd8170SKalle Valo 	struct sk_buff *skb;
2531bdcd8170SKalle Valo 	struct wmi_create_pstream_cmd *cmd;
2532bdcd8170SKalle Valo 	u8 fatpipe_exist_for_ac = 0;
2533bdcd8170SKalle Valo 	s32 min_phy = 0;
2534bdcd8170SKalle Valo 	s32 nominal_phy = 0;
2535bdcd8170SKalle Valo 	int ret;
2536bdcd8170SKalle Valo 
253793b4a09fSHeinrich Schuchardt 	if (!((params->user_pri <= 0x7) &&
2538bdcd8170SKalle Valo 	      (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2539bdcd8170SKalle Valo 	      (params->traffic_direc == UPLINK_TRAFFIC ||
2540bdcd8170SKalle Valo 	       params->traffic_direc == DNLINK_TRAFFIC ||
2541bdcd8170SKalle Valo 	       params->traffic_direc == BIDIR_TRAFFIC) &&
2542bdcd8170SKalle Valo 	      (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2543bdcd8170SKalle Valo 	       params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2544bdcd8170SKalle Valo 	      (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2545bdcd8170SKalle Valo 	       params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2546bdcd8170SKalle Valo 	       params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2547bdcd8170SKalle Valo 	      (params->tsid == WMI_IMPLICIT_PSTREAM ||
2548bdcd8170SKalle Valo 	       params->tsid <= WMI_MAX_THINSTREAM))) {
2549bdcd8170SKalle Valo 		return -EINVAL;
2550bdcd8170SKalle Valo 	}
2551bdcd8170SKalle Valo 
2552bdcd8170SKalle Valo 	/*
2553bdcd8170SKalle Valo 	 * Check nominal PHY rate is >= minimalPHY,
2554bdcd8170SKalle Valo 	 * so that DUT can allow TSRS IE
2555bdcd8170SKalle Valo 	 */
2556bdcd8170SKalle Valo 
2557bdcd8170SKalle Valo 	/* Get the physical rate (units of bps) */
2558bdcd8170SKalle Valo 	min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2559bdcd8170SKalle Valo 
2560bdcd8170SKalle Valo 	/* Check minimal phy < nominal phy rate */
2561bdcd8170SKalle Valo 	if (params->nominal_phy >= min_phy) {
2562bdcd8170SKalle Valo 		/* unit of 500 kbps */
2563bdcd8170SKalle Valo 		nominal_phy = (params->nominal_phy * 1000) / 500;
2564bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI,
2565bdcd8170SKalle Valo 			   "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2566bdcd8170SKalle Valo 			   min_phy, nominal_phy);
2567bdcd8170SKalle Valo 
2568bdcd8170SKalle Valo 		params->nominal_phy = nominal_phy;
2569bdcd8170SKalle Valo 	} else {
2570bdcd8170SKalle Valo 		params->nominal_phy = 0;
2571bdcd8170SKalle Valo 	}
2572bdcd8170SKalle Valo 
2573bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2574bdcd8170SKalle Valo 	if (!skb)
2575bdcd8170SKalle Valo 		return -ENOMEM;
2576bdcd8170SKalle Valo 
2577bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
2578bdcd8170SKalle Valo 		   "sending create_pstream_cmd: ac=%d  tsid:%d\n",
2579bdcd8170SKalle Valo 		   params->traffic_class, params->tsid);
2580bdcd8170SKalle Valo 
2581bdcd8170SKalle Valo 	cmd = (struct wmi_create_pstream_cmd *) skb->data;
2582bdcd8170SKalle Valo 	memcpy(cmd, params, sizeof(*cmd));
2583bdcd8170SKalle Valo 
2584bdcd8170SKalle Valo 	/* This is an implicitly created Fat pipe */
2585bdcd8170SKalle Valo 	if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2586bdcd8170SKalle Valo 		spin_lock_bh(&wmi->lock);
2587bdcd8170SKalle Valo 		fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2588bdcd8170SKalle Valo 					(1 << params->traffic_class));
2589bdcd8170SKalle Valo 		wmi->fat_pipe_exist |= (1 << params->traffic_class);
2590bdcd8170SKalle Valo 		spin_unlock_bh(&wmi->lock);
2591bdcd8170SKalle Valo 	} else {
2592bdcd8170SKalle Valo 		/* explicitly created thin stream within a fat pipe */
2593bdcd8170SKalle Valo 		spin_lock_bh(&wmi->lock);
2594bdcd8170SKalle Valo 		fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2595bdcd8170SKalle Valo 					(1 << params->traffic_class));
2596bdcd8170SKalle Valo 		wmi->stream_exist_for_ac[params->traffic_class] |=
2597bdcd8170SKalle Valo 		    (1 << params->tsid);
2598bdcd8170SKalle Valo 		/*
2599bdcd8170SKalle Valo 		 * If a thinstream becomes active, the fat pipe automatically
2600bdcd8170SKalle Valo 		 * becomes active
2601bdcd8170SKalle Valo 		 */
2602bdcd8170SKalle Valo 		wmi->fat_pipe_exist |= (1 << params->traffic_class);
2603bdcd8170SKalle Valo 		spin_unlock_bh(&wmi->lock);
2604bdcd8170SKalle Valo 	}
2605bdcd8170SKalle Valo 
2606bdcd8170SKalle Valo 	/*
2607bdcd8170SKalle Valo 	 * Indicate activty change to driver layer only if this is the
2608bdcd8170SKalle Valo 	 * first TSID to get created in this AC explicitly or an implicit
2609bdcd8170SKalle Valo 	 * fat pipe is getting created.
2610bdcd8170SKalle Valo 	 */
2611bdcd8170SKalle Valo 	if (!fatpipe_exist_for_ac)
2612bdcd8170SKalle Valo 		ath6kl_indicate_tx_activity(wmi->parent_dev,
2613bdcd8170SKalle Valo 					    params->traffic_class, true);
2614bdcd8170SKalle Valo 
2615240d2799SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
2616bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
2617bdcd8170SKalle Valo 	return ret;
2618bdcd8170SKalle Valo }
2619bdcd8170SKalle Valo 
2620240d2799SVasanthakumar Thiagarajan int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
2621240d2799SVasanthakumar Thiagarajan 				  u8 tsid)
2622bdcd8170SKalle Valo {
2623bdcd8170SKalle Valo 	struct sk_buff *skb;
2624bdcd8170SKalle Valo 	struct wmi_delete_pstream_cmd *cmd;
2625bdcd8170SKalle Valo 	u16 active_tsids = 0;
2626bdcd8170SKalle Valo 	int ret;
2627bdcd8170SKalle Valo 
26285d6751eaSDan Carpenter 	if (traffic_class >= WMM_NUM_AC) {
2629bdcd8170SKalle Valo 		ath6kl_err("invalid traffic class: %d\n", traffic_class);
2630bdcd8170SKalle Valo 		return -EINVAL;
2631bdcd8170SKalle Valo 	}
2632bdcd8170SKalle Valo 
26336a950755SDan Carpenter 	if (tsid >= 16) {
26346a950755SDan Carpenter 		ath6kl_err("invalid tsid: %d\n", tsid);
26356a950755SDan Carpenter 		return -EINVAL;
26366a950755SDan Carpenter 	}
26376a950755SDan Carpenter 
2638bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2639bdcd8170SKalle Valo 	if (!skb)
2640bdcd8170SKalle Valo 		return -ENOMEM;
2641bdcd8170SKalle Valo 
2642bdcd8170SKalle Valo 	cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2643bdcd8170SKalle Valo 	cmd->traffic_class = traffic_class;
2644bdcd8170SKalle Valo 	cmd->tsid = tsid;
2645bdcd8170SKalle Valo 
2646bdcd8170SKalle Valo 	spin_lock_bh(&wmi->lock);
2647bdcd8170SKalle Valo 	active_tsids = wmi->stream_exist_for_ac[traffic_class];
2648bdcd8170SKalle Valo 	spin_unlock_bh(&wmi->lock);
2649bdcd8170SKalle Valo 
2650bdcd8170SKalle Valo 	if (!(active_tsids & (1 << tsid))) {
2651bdcd8170SKalle Valo 		dev_kfree_skb(skb);
2652bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI,
2653bdcd8170SKalle Valo 			   "TSID %d doesn't exist for traffic class: %d\n",
2654bdcd8170SKalle Valo 			   tsid, traffic_class);
2655bdcd8170SKalle Valo 		return -ENODATA;
2656bdcd8170SKalle Valo 	}
2657bdcd8170SKalle Valo 
2658bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
2659bdcd8170SKalle Valo 		   "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2660bdcd8170SKalle Valo 		   traffic_class, tsid);
2661bdcd8170SKalle Valo 
2662240d2799SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
2663bdcd8170SKalle Valo 				  SYNC_BEFORE_WMIFLAG);
2664bdcd8170SKalle Valo 
2665bdcd8170SKalle Valo 	spin_lock_bh(&wmi->lock);
2666bdcd8170SKalle Valo 	wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2667bdcd8170SKalle Valo 	active_tsids = wmi->stream_exist_for_ac[traffic_class];
2668bdcd8170SKalle Valo 	spin_unlock_bh(&wmi->lock);
2669bdcd8170SKalle Valo 
2670bdcd8170SKalle Valo 	/*
2671bdcd8170SKalle Valo 	 * Indicate stream inactivity to driver layer only if all tsids
2672bdcd8170SKalle Valo 	 * within this AC are deleted.
2673bdcd8170SKalle Valo 	 */
2674bdcd8170SKalle Valo 	if (!active_tsids) {
2675bdcd8170SKalle Valo 		ath6kl_indicate_tx_activity(wmi->parent_dev,
2676bdcd8170SKalle Valo 					    traffic_class, false);
2677bdcd8170SKalle Valo 		wmi->fat_pipe_exist &= ~(1 << traffic_class);
2678bdcd8170SKalle Valo 	}
2679bdcd8170SKalle Valo 
2680bdcd8170SKalle Valo 	return ret;
2681bdcd8170SKalle Valo }
2682bdcd8170SKalle Valo 
2683ca1d16a0SRaja Mani int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, u8 if_idx,
2684ca1d16a0SRaja Mani 			  __be32 ips0, __be32 ips1)
2685bdcd8170SKalle Valo {
2686bdcd8170SKalle Valo 	struct sk_buff *skb;
2687bdcd8170SKalle Valo 	struct wmi_set_ip_cmd *cmd;
2688bdcd8170SKalle Valo 	int ret;
2689bdcd8170SKalle Valo 
2690bdcd8170SKalle Valo 	/* Multicast address are not valid */
2691ca1d16a0SRaja Mani 	if (ipv4_is_multicast(ips0) ||
2692ca1d16a0SRaja Mani 	    ipv4_is_multicast(ips1))
2693bdcd8170SKalle Valo 		return -EINVAL;
2694bdcd8170SKalle Valo 
2695bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2696bdcd8170SKalle Valo 	if (!skb)
2697bdcd8170SKalle Valo 		return -ENOMEM;
2698bdcd8170SKalle Valo 
2699bdcd8170SKalle Valo 	cmd = (struct wmi_set_ip_cmd *) skb->data;
2700ca1d16a0SRaja Mani 	cmd->ips[0] = ips0;
2701ca1d16a0SRaja Mani 	cmd->ips[1] = ips1;
2702bdcd8170SKalle Valo 
2703ca1d16a0SRaja Mani 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IP_CMDID,
2704334234b5SVasanthakumar Thiagarajan 				  NO_SYNC_WMIFLAG);
2705bdcd8170SKalle Valo 	return ret;
2706bdcd8170SKalle Valo }
2707bdcd8170SKalle Valo 
270845cf110bSRaja Mani static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
270945cf110bSRaja Mani {
271045cf110bSRaja Mani 	u16 active_tsids;
271145cf110bSRaja Mani 	u8 stream_exist;
271245cf110bSRaja Mani 	int i;
271345cf110bSRaja Mani 
271445cf110bSRaja Mani 	/*
271545cf110bSRaja Mani 	 * Relinquish credits from all implicitly created pstreams
271645cf110bSRaja Mani 	 * since when we go to sleep. If user created explicit
271745cf110bSRaja Mani 	 * thinstreams exists with in a fatpipe leave them intact
271845cf110bSRaja Mani 	 * for the user to delete.
271945cf110bSRaja Mani 	 */
272045cf110bSRaja Mani 	spin_lock_bh(&wmi->lock);
272145cf110bSRaja Mani 	stream_exist = wmi->fat_pipe_exist;
272245cf110bSRaja Mani 	spin_unlock_bh(&wmi->lock);
272345cf110bSRaja Mani 
272445cf110bSRaja Mani 	for (i = 0; i < WMM_NUM_AC; i++) {
272545cf110bSRaja Mani 		if (stream_exist & (1 << i)) {
272645cf110bSRaja Mani 			/*
272745cf110bSRaja Mani 			 * FIXME: Is this lock & unlock inside
272845cf110bSRaja Mani 			 * for loop correct? may need rework.
272945cf110bSRaja Mani 			 */
273045cf110bSRaja Mani 			spin_lock_bh(&wmi->lock);
273145cf110bSRaja Mani 			active_tsids = wmi->stream_exist_for_ac[i];
273245cf110bSRaja Mani 			spin_unlock_bh(&wmi->lock);
273345cf110bSRaja Mani 
273445cf110bSRaja Mani 			/*
273545cf110bSRaja Mani 			 * If there are no user created thin streams
273645cf110bSRaja Mani 			 * delete the fatpipe
273745cf110bSRaja Mani 			 */
273845cf110bSRaja Mani 			if (!active_tsids) {
273945cf110bSRaja Mani 				stream_exist &= ~(1 << i);
274045cf110bSRaja Mani 				/*
274145cf110bSRaja Mani 				 * Indicate inactivity to driver layer for
274245cf110bSRaja Mani 				 * this fatpipe (pstream)
274345cf110bSRaja Mani 				 */
274445cf110bSRaja Mani 				ath6kl_indicate_tx_activity(wmi->parent_dev,
274545cf110bSRaja Mani 							    i, false);
274645cf110bSRaja Mani 			}
274745cf110bSRaja Mani 		}
274845cf110bSRaja Mani 	}
274945cf110bSRaja Mani 
275045cf110bSRaja Mani 	/* FIXME: Can we do this assignment without locking ? */
275145cf110bSRaja Mani 	spin_lock_bh(&wmi->lock);
275245cf110bSRaja Mani 	wmi->fat_pipe_exist = stream_exist;
275345cf110bSRaja Mani 	spin_unlock_bh(&wmi->lock);
275445cf110bSRaja Mani }
275545cf110bSRaja Mani 
275606e360acSBala Shanmugam static int ath6kl_set_bitrate_mask64(struct wmi *wmi, u8 if_idx,
275706e360acSBala Shanmugam 				     const struct cfg80211_bitrate_mask *mask)
275806e360acSBala Shanmugam {
275906e360acSBala Shanmugam 	struct sk_buff *skb;
276006e360acSBala Shanmugam 	int ret, mode, band;
2761f8c03053SKalle Valo 	u64 mcsrate, ratemask[ATH6KL_NUM_BANDS];
276206e360acSBala Shanmugam 	struct wmi_set_tx_select_rates64_cmd *cmd;
276306e360acSBala Shanmugam 
276406e360acSBala Shanmugam 	memset(&ratemask, 0, sizeof(ratemask));
2765f8c03053SKalle Valo 
2766f8c03053SKalle Valo 	/* only check 2.4 and 5 GHz bands, skip the rest */
276757fbcce3SJohannes Berg 	for (band = 0; band <= NL80211_BAND_5GHZ; band++) {
276806e360acSBala Shanmugam 		/* copy legacy rate mask */
276906e360acSBala Shanmugam 		ratemask[band] = mask->control[band].legacy;
277057fbcce3SJohannes Berg 		if (band == NL80211_BAND_5GHZ)
277106e360acSBala Shanmugam 			ratemask[band] =
277206e360acSBala Shanmugam 				mask->control[band].legacy << 4;
277306e360acSBala Shanmugam 
277406e360acSBala Shanmugam 		/* copy mcs rate mask */
2775d1e33e65SJanusz Dziedzic 		mcsrate = mask->control[band].ht_mcs[1];
277606e360acSBala Shanmugam 		mcsrate <<= 8;
2777d1e33e65SJanusz Dziedzic 		mcsrate |= mask->control[band].ht_mcs[0];
277806e360acSBala Shanmugam 		ratemask[band] |= mcsrate << 12;
277906e360acSBala Shanmugam 		ratemask[band] |= mcsrate << 28;
278006e360acSBala Shanmugam 	}
278106e360acSBala Shanmugam 
278206e360acSBala Shanmugam 	ath6kl_dbg(ATH6KL_DBG_WMI,
278306e360acSBala Shanmugam 		   "Ratemask 64 bit: 2.4:%llx 5:%llx\n",
278406e360acSBala Shanmugam 		   ratemask[0], ratemask[1]);
278506e360acSBala Shanmugam 
278606e360acSBala Shanmugam 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
278706e360acSBala Shanmugam 	if (!skb)
278806e360acSBala Shanmugam 		return -ENOMEM;
278906e360acSBala Shanmugam 
279006e360acSBala Shanmugam 	cmd = (struct wmi_set_tx_select_rates64_cmd *) skb->data;
279106e360acSBala Shanmugam 	for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
279206e360acSBala Shanmugam 		/* A mode operate in 5GHZ band */
279306e360acSBala Shanmugam 		if (mode == WMI_RATES_MODE_11A ||
279406e360acSBala Shanmugam 		    mode == WMI_RATES_MODE_11A_HT20 ||
279506e360acSBala Shanmugam 		    mode == WMI_RATES_MODE_11A_HT40)
279657fbcce3SJohannes Berg 			band = NL80211_BAND_5GHZ;
279706e360acSBala Shanmugam 		else
279857fbcce3SJohannes Berg 			band = NL80211_BAND_2GHZ;
279906e360acSBala Shanmugam 		cmd->ratemask[mode] = cpu_to_le64(ratemask[band]);
280006e360acSBala Shanmugam 	}
280106e360acSBala Shanmugam 
280206e360acSBala Shanmugam 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
280306e360acSBala Shanmugam 				  WMI_SET_TX_SELECT_RATES_CMDID,
280406e360acSBala Shanmugam 				  NO_SYNC_WMIFLAG);
280506e360acSBala Shanmugam 	return ret;
280606e360acSBala Shanmugam }
280706e360acSBala Shanmugam 
280806e360acSBala Shanmugam static int ath6kl_set_bitrate_mask32(struct wmi *wmi, u8 if_idx,
280906e360acSBala Shanmugam 				     const struct cfg80211_bitrate_mask *mask)
281006e360acSBala Shanmugam {
281106e360acSBala Shanmugam 	struct sk_buff *skb;
281206e360acSBala Shanmugam 	int ret, mode, band;
2813f8c03053SKalle Valo 	u32 mcsrate, ratemask[ATH6KL_NUM_BANDS];
281406e360acSBala Shanmugam 	struct wmi_set_tx_select_rates32_cmd *cmd;
281506e360acSBala Shanmugam 
281606e360acSBala Shanmugam 	memset(&ratemask, 0, sizeof(ratemask));
2817f8c03053SKalle Valo 
2818f8c03053SKalle Valo 	/* only check 2.4 and 5 GHz bands, skip the rest */
281957fbcce3SJohannes Berg 	for (band = 0; band <= NL80211_BAND_5GHZ; band++) {
282006e360acSBala Shanmugam 		/* copy legacy rate mask */
282106e360acSBala Shanmugam 		ratemask[band] = mask->control[band].legacy;
282257fbcce3SJohannes Berg 		if (band == NL80211_BAND_5GHZ)
282306e360acSBala Shanmugam 			ratemask[band] =
282406e360acSBala Shanmugam 				mask->control[band].legacy << 4;
282506e360acSBala Shanmugam 
282606e360acSBala Shanmugam 		/* copy mcs rate mask */
2827d1e33e65SJanusz Dziedzic 		mcsrate = mask->control[band].ht_mcs[0];
282806e360acSBala Shanmugam 		ratemask[band] |= mcsrate << 12;
282906e360acSBala Shanmugam 		ratemask[band] |= mcsrate << 20;
283006e360acSBala Shanmugam 	}
283106e360acSBala Shanmugam 
283206e360acSBala Shanmugam 	ath6kl_dbg(ATH6KL_DBG_WMI,
283306e360acSBala Shanmugam 		   "Ratemask 32 bit: 2.4:%x 5:%x\n",
283406e360acSBala Shanmugam 		   ratemask[0], ratemask[1]);
283506e360acSBala Shanmugam 
283606e360acSBala Shanmugam 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
283706e360acSBala Shanmugam 	if (!skb)
283806e360acSBala Shanmugam 		return -ENOMEM;
283906e360acSBala Shanmugam 
284006e360acSBala Shanmugam 	cmd = (struct wmi_set_tx_select_rates32_cmd *) skb->data;
284106e360acSBala Shanmugam 	for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
284206e360acSBala Shanmugam 		/* A mode operate in 5GHZ band */
284306e360acSBala Shanmugam 		if (mode == WMI_RATES_MODE_11A ||
284406e360acSBala Shanmugam 		    mode == WMI_RATES_MODE_11A_HT20 ||
284506e360acSBala Shanmugam 		    mode == WMI_RATES_MODE_11A_HT40)
284657fbcce3SJohannes Berg 			band = NL80211_BAND_5GHZ;
284706e360acSBala Shanmugam 		else
284857fbcce3SJohannes Berg 			band = NL80211_BAND_2GHZ;
284906e360acSBala Shanmugam 		cmd->ratemask[mode] = cpu_to_le32(ratemask[band]);
285006e360acSBala Shanmugam 	}
285106e360acSBala Shanmugam 
285206e360acSBala Shanmugam 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
285306e360acSBala Shanmugam 				  WMI_SET_TX_SELECT_RATES_CMDID,
285406e360acSBala Shanmugam 				  NO_SYNC_WMIFLAG);
285506e360acSBala Shanmugam 	return ret;
285606e360acSBala Shanmugam }
285706e360acSBala Shanmugam 
285806e360acSBala Shanmugam int ath6kl_wmi_set_bitrate_mask(struct wmi *wmi, u8 if_idx,
285906e360acSBala Shanmugam 				const struct cfg80211_bitrate_mask *mask)
286006e360acSBala Shanmugam {
286106e360acSBala Shanmugam 	struct ath6kl *ar = wmi->parent_dev;
286206e360acSBala Shanmugam 
2863eba95bceSKalle Valo 	if (test_bit(ATH6KL_FW_CAPABILITY_64BIT_RATES,
2864eba95bceSKalle Valo 		     ar->fw_capabilities))
286506e360acSBala Shanmugam 		return ath6kl_set_bitrate_mask64(wmi, if_idx, mask);
286606e360acSBala Shanmugam 	else
286706e360acSBala Shanmugam 		return ath6kl_set_bitrate_mask32(wmi, if_idx, mask);
286806e360acSBala Shanmugam }
286906e360acSBala Shanmugam 
287045cf110bSRaja Mani int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
287145cf110bSRaja Mani 				       enum ath6kl_host_mode host_mode)
287245cf110bSRaja Mani {
287345cf110bSRaja Mani 	struct sk_buff *skb;
287445cf110bSRaja Mani 	struct wmi_set_host_sleep_mode_cmd *cmd;
287545cf110bSRaja Mani 	int ret;
287645cf110bSRaja Mani 
287745cf110bSRaja Mani 	if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
287845cf110bSRaja Mani 	    (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
287945cf110bSRaja Mani 		ath6kl_err("invalid host sleep mode: %d\n", host_mode);
288045cf110bSRaja Mani 		return -EINVAL;
288145cf110bSRaja Mani 	}
288245cf110bSRaja Mani 
288345cf110bSRaja Mani 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
288445cf110bSRaja Mani 	if (!skb)
288545cf110bSRaja Mani 		return -ENOMEM;
288645cf110bSRaja Mani 
288745cf110bSRaja Mani 	cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
288845cf110bSRaja Mani 
288945cf110bSRaja Mani 	if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
289045cf110bSRaja Mani 		ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
289145cf110bSRaja Mani 		cmd->asleep = cpu_to_le32(1);
2892a5d8f9dfSKalle Valo 	} else {
289345cf110bSRaja Mani 		cmd->awake = cpu_to_le32(1);
2894a5d8f9dfSKalle Valo 	}
289545cf110bSRaja Mani 
289645cf110bSRaja Mani 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
289745cf110bSRaja Mani 				  WMI_SET_HOST_SLEEP_MODE_CMDID,
289845cf110bSRaja Mani 				  NO_SYNC_WMIFLAG);
289945cf110bSRaja Mani 	return ret;
290045cf110bSRaja Mani }
290145cf110bSRaja Mani 
2902081c7a84SRaja Mani /* This command has zero length payload */
2903081c7a84SRaja Mani static int ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(struct wmi *wmi,
2904081c7a84SRaja Mani 						      struct ath6kl_vif *vif)
2905081c7a84SRaja Mani {
2906081c7a84SRaja Mani 	struct ath6kl *ar = wmi->parent_dev;
2907081c7a84SRaja Mani 
2908081c7a84SRaja Mani 	set_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
2909081c7a84SRaja Mani 	wake_up(&ar->event_wq);
2910081c7a84SRaja Mani 
2911081c7a84SRaja Mani 	return 0;
2912081c7a84SRaja Mani }
2913081c7a84SRaja Mani 
291445cf110bSRaja Mani int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
291545cf110bSRaja Mani 				enum ath6kl_wow_mode wow_mode,
291645cf110bSRaja Mani 				u32 filter, u16 host_req_delay)
291745cf110bSRaja Mani {
291845cf110bSRaja Mani 	struct sk_buff *skb;
291945cf110bSRaja Mani 	struct wmi_set_wow_mode_cmd *cmd;
292045cf110bSRaja Mani 	int ret;
292145cf110bSRaja Mani 
292245cf110bSRaja Mani 	if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
292345cf110bSRaja Mani 	    wow_mode != ATH6KL_WOW_MODE_DISABLE) {
292445cf110bSRaja Mani 		ath6kl_err("invalid wow mode: %d\n", wow_mode);
292545cf110bSRaja Mani 		return -EINVAL;
292645cf110bSRaja Mani 	}
292745cf110bSRaja Mani 
292845cf110bSRaja Mani 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
292945cf110bSRaja Mani 	if (!skb)
293045cf110bSRaja Mani 		return -ENOMEM;
293145cf110bSRaja Mani 
293245cf110bSRaja Mani 	cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
293345cf110bSRaja Mani 	cmd->enable_wow = cpu_to_le32(wow_mode);
293445cf110bSRaja Mani 	cmd->filter = cpu_to_le32(filter);
293545cf110bSRaja Mani 	cmd->host_req_delay = cpu_to_le16(host_req_delay);
293645cf110bSRaja Mani 
293745cf110bSRaja Mani 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
293845cf110bSRaja Mani 				  NO_SYNC_WMIFLAG);
293945cf110bSRaja Mani 	return ret;
294045cf110bSRaja Mani }
294145cf110bSRaja Mani 
29425c9b4fa1SRaja Mani int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
29435c9b4fa1SRaja Mani 				   u8 list_id, u8 filter_size,
2944d91e8eeeSRaja Mani 				   u8 filter_offset, const u8 *filter,
2945d91e8eeeSRaja Mani 				   const u8 *mask)
29465c9b4fa1SRaja Mani {
29475c9b4fa1SRaja Mani 	struct sk_buff *skb;
29485c9b4fa1SRaja Mani 	struct wmi_add_wow_pattern_cmd *cmd;
29495c9b4fa1SRaja Mani 	u16 size;
29505c9b4fa1SRaja Mani 	u8 *filter_mask;
29515c9b4fa1SRaja Mani 	int ret;
29525c9b4fa1SRaja Mani 
29535c9b4fa1SRaja Mani 	/*
29545c9b4fa1SRaja Mani 	 * Allocate additional memory in the buffer to hold
29555c9b4fa1SRaja Mani 	 * filter and mask value, which is twice of filter_size.
29565c9b4fa1SRaja Mani 	 */
29575c9b4fa1SRaja Mani 	size = sizeof(*cmd) + (2 * filter_size);
29585c9b4fa1SRaja Mani 
29595c9b4fa1SRaja Mani 	skb = ath6kl_wmi_get_new_buf(size);
29605c9b4fa1SRaja Mani 	if (!skb)
29615c9b4fa1SRaja Mani 		return -ENOMEM;
29625c9b4fa1SRaja Mani 
29635c9b4fa1SRaja Mani 	cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
29645c9b4fa1SRaja Mani 	cmd->filter_list_id = list_id;
29655c9b4fa1SRaja Mani 	cmd->filter_size = filter_size;
29665c9b4fa1SRaja Mani 	cmd->filter_offset = filter_offset;
29675c9b4fa1SRaja Mani 
29685c9b4fa1SRaja Mani 	memcpy(cmd->filter, filter, filter_size);
29695c9b4fa1SRaja Mani 
29705c9b4fa1SRaja Mani 	filter_mask = (u8 *) (cmd->filter + filter_size);
29715c9b4fa1SRaja Mani 	memcpy(filter_mask, mask, filter_size);
29725c9b4fa1SRaja Mani 
29735c9b4fa1SRaja Mani 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
29745c9b4fa1SRaja Mani 				  NO_SYNC_WMIFLAG);
29755c9b4fa1SRaja Mani 
29765c9b4fa1SRaja Mani 	return ret;
29775c9b4fa1SRaja Mani }
29785c9b4fa1SRaja Mani 
29795c9b4fa1SRaja Mani int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
29805c9b4fa1SRaja Mani 				   u16 list_id, u16 filter_id)
29815c9b4fa1SRaja Mani {
29825c9b4fa1SRaja Mani 	struct sk_buff *skb;
29835c9b4fa1SRaja Mani 	struct wmi_del_wow_pattern_cmd *cmd;
29845c9b4fa1SRaja Mani 	int ret;
29855c9b4fa1SRaja Mani 
29865c9b4fa1SRaja Mani 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
29875c9b4fa1SRaja Mani 	if (!skb)
29885c9b4fa1SRaja Mani 		return -ENOMEM;
29895c9b4fa1SRaja Mani 
29905c9b4fa1SRaja Mani 	cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
29915c9b4fa1SRaja Mani 	cmd->filter_list_id = cpu_to_le16(list_id);
29925c9b4fa1SRaja Mani 	cmd->filter_id = cpu_to_le16(filter_id);
29935c9b4fa1SRaja Mani 
29945c9b4fa1SRaja Mani 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
29955c9b4fa1SRaja Mani 				  NO_SYNC_WMIFLAG);
29965c9b4fa1SRaja Mani 	return ret;
29975c9b4fa1SRaja Mani }
29985c9b4fa1SRaja Mani 
2999bdcd8170SKalle Valo static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
3000bdcd8170SKalle Valo 				    enum wmix_command_id cmd_id,
3001bdcd8170SKalle Valo 				    enum wmi_sync_flag sync_flag)
3002bdcd8170SKalle Valo {
3003bdcd8170SKalle Valo 	struct wmix_cmd_hdr *cmd_hdr;
3004bdcd8170SKalle Valo 	int ret;
3005bdcd8170SKalle Valo 
3006bdcd8170SKalle Valo 	skb_push(skb, sizeof(struct wmix_cmd_hdr));
3007bdcd8170SKalle Valo 
3008bdcd8170SKalle Valo 	cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
3009bdcd8170SKalle Valo 	cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
3010bdcd8170SKalle Valo 
3011334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
3012bdcd8170SKalle Valo 
3013bdcd8170SKalle Valo 	return ret;
3014bdcd8170SKalle Valo }
3015bdcd8170SKalle Valo 
3016bdcd8170SKalle Valo int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
3017bdcd8170SKalle Valo {
3018bdcd8170SKalle Valo 	struct sk_buff *skb;
3019bdcd8170SKalle Valo 	struct wmix_hb_challenge_resp_cmd *cmd;
3020bdcd8170SKalle Valo 	int ret;
3021bdcd8170SKalle Valo 
3022bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3023bdcd8170SKalle Valo 	if (!skb)
3024bdcd8170SKalle Valo 		return -ENOMEM;
3025bdcd8170SKalle Valo 
3026bdcd8170SKalle Valo 	cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
3027bdcd8170SKalle Valo 	cmd->cookie = cpu_to_le32(cookie);
3028bdcd8170SKalle Valo 	cmd->source = cpu_to_le32(source);
3029bdcd8170SKalle Valo 
3030bdcd8170SKalle Valo 	ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
3031bdcd8170SKalle Valo 				       NO_SYNC_WMIFLAG);
3032bdcd8170SKalle Valo 	return ret;
3033bdcd8170SKalle Valo }
3034bdcd8170SKalle Valo 
3035939f1cceSKalle Valo int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
3036939f1cceSKalle Valo {
3037939f1cceSKalle Valo 	struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
3038939f1cceSKalle Valo 	struct sk_buff *skb;
3039939f1cceSKalle Valo 	int ret;
3040939f1cceSKalle Valo 
3041939f1cceSKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3042939f1cceSKalle Valo 	if (!skb)
3043939f1cceSKalle Valo 		return -ENOMEM;
3044939f1cceSKalle Valo 
3045939f1cceSKalle Valo 	cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
3046939f1cceSKalle Valo 	cmd->valid = cpu_to_le32(valid);
3047939f1cceSKalle Valo 	cmd->config = cpu_to_le32(config);
3048939f1cceSKalle Valo 
3049939f1cceSKalle Valo 	ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
3050939f1cceSKalle Valo 				       NO_SYNC_WMIFLAG);
3051939f1cceSKalle Valo 	return ret;
3052939f1cceSKalle Valo }
3053939f1cceSKalle Valo 
3054334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
3055bdcd8170SKalle Valo {
3056334234b5SVasanthakumar Thiagarajan 	return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
3057bdcd8170SKalle Valo }
3058bdcd8170SKalle Valo 
3059990bd915SVasanthakumar Thiagarajan int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
3060bdcd8170SKalle Valo {
3061bdcd8170SKalle Valo 	struct sk_buff *skb;
3062bdcd8170SKalle Valo 	struct wmi_set_tx_pwr_cmd *cmd;
3063bdcd8170SKalle Valo 	int ret;
3064bdcd8170SKalle Valo 
3065bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
3066bdcd8170SKalle Valo 	if (!skb)
3067bdcd8170SKalle Valo 		return -ENOMEM;
3068bdcd8170SKalle Valo 
3069bdcd8170SKalle Valo 	cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
3070bdcd8170SKalle Valo 	cmd->dbM = dbM;
3071bdcd8170SKalle Valo 
3072990bd915SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
3073bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
3074bdcd8170SKalle Valo 
3075bdcd8170SKalle Valo 	return ret;
3076bdcd8170SKalle Valo }
3077bdcd8170SKalle Valo 
3078990bd915SVasanthakumar Thiagarajan int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
3079bdcd8170SKalle Valo {
3080990bd915SVasanthakumar Thiagarajan 	return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
3081bdcd8170SKalle Valo }
3082bdcd8170SKalle Valo 
30834b28a80dSJouni Malinen int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
30844b28a80dSJouni Malinen {
3085334234b5SVasanthakumar Thiagarajan 	return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
30864b28a80dSJouni Malinen }
30874b28a80dSJouni Malinen 
30880ce59445SVasanthakumar Thiagarajan int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
30890ce59445SVasanthakumar Thiagarajan 				 u8 preamble_policy)
3090bdcd8170SKalle Valo {
3091bdcd8170SKalle Valo 	struct sk_buff *skb;
3092bdcd8170SKalle Valo 	struct wmi_set_lpreamble_cmd *cmd;
3093bdcd8170SKalle Valo 	int ret;
3094bdcd8170SKalle Valo 
3095bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
3096bdcd8170SKalle Valo 	if (!skb)
3097bdcd8170SKalle Valo 		return -ENOMEM;
3098bdcd8170SKalle Valo 
3099bdcd8170SKalle Valo 	cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
3100bdcd8170SKalle Valo 	cmd->status = status;
3101bdcd8170SKalle Valo 	cmd->preamble_policy = preamble_policy;
3102bdcd8170SKalle Valo 
31030ce59445SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
3104bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
3105bdcd8170SKalle Valo 	return ret;
3106bdcd8170SKalle Valo }
3107bdcd8170SKalle Valo 
3108bdcd8170SKalle Valo int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
3109bdcd8170SKalle Valo {
3110bdcd8170SKalle Valo 	struct sk_buff *skb;
3111bdcd8170SKalle Valo 	struct wmi_set_rts_cmd *cmd;
3112bdcd8170SKalle Valo 	int ret;
3113bdcd8170SKalle Valo 
3114bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
3115bdcd8170SKalle Valo 	if (!skb)
3116bdcd8170SKalle Valo 		return -ENOMEM;
3117bdcd8170SKalle Valo 
3118bdcd8170SKalle Valo 	cmd = (struct wmi_set_rts_cmd *) skb->data;
3119bdcd8170SKalle Valo 	cmd->threshold = cpu_to_le16(threshold);
3120bdcd8170SKalle Valo 
3121334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
3122334234b5SVasanthakumar Thiagarajan 				  NO_SYNC_WMIFLAG);
3123bdcd8170SKalle Valo 	return ret;
3124bdcd8170SKalle Valo }
3125bdcd8170SKalle Valo 
31260ce59445SVasanthakumar Thiagarajan int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
3127bdcd8170SKalle Valo {
3128bdcd8170SKalle Valo 	struct sk_buff *skb;
3129bdcd8170SKalle Valo 	struct wmi_set_wmm_txop_cmd *cmd;
3130bdcd8170SKalle Valo 	int ret;
3131bdcd8170SKalle Valo 
3132bdcd8170SKalle Valo 	if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
3133bdcd8170SKalle Valo 		return -EINVAL;
3134bdcd8170SKalle Valo 
3135bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
3136bdcd8170SKalle Valo 	if (!skb)
3137bdcd8170SKalle Valo 		return -ENOMEM;
3138bdcd8170SKalle Valo 
3139bdcd8170SKalle Valo 	cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
3140bdcd8170SKalle Valo 	cmd->txop_enable = cfg;
3141bdcd8170SKalle Valo 
31420ce59445SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
3143bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
3144bdcd8170SKalle Valo 	return ret;
3145bdcd8170SKalle Valo }
3146bdcd8170SKalle Valo 
31470ce59445SVasanthakumar Thiagarajan int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
31480ce59445SVasanthakumar Thiagarajan 				 u8 keep_alive_intvl)
3149bdcd8170SKalle Valo {
3150bdcd8170SKalle Valo 	struct sk_buff *skb;
3151bdcd8170SKalle Valo 	struct wmi_set_keepalive_cmd *cmd;
3152bdcd8170SKalle Valo 	int ret;
3153bdcd8170SKalle Valo 
3154bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3155bdcd8170SKalle Valo 	if (!skb)
3156bdcd8170SKalle Valo 		return -ENOMEM;
3157bdcd8170SKalle Valo 
3158bdcd8170SKalle Valo 	cmd = (struct wmi_set_keepalive_cmd *) skb->data;
3159bdcd8170SKalle Valo 	cmd->keep_alive_intvl = keep_alive_intvl;
3160bdcd8170SKalle Valo 
31610ce59445SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
3162bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
3163334234b5SVasanthakumar Thiagarajan 
3164ff0b0075SJouni Malinen 	if (ret == 0)
3165ff0b0075SJouni Malinen 		ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
3166334234b5SVasanthakumar Thiagarajan 
3167bdcd8170SKalle Valo 	return ret;
3168bdcd8170SKalle Valo }
3169bdcd8170SKalle Valo 
3170df90b369SVasanthakumar Thiagarajan int ath6kl_wmi_set_htcap_cmd(struct wmi *wmi, u8 if_idx,
317157fbcce3SJohannes Berg 			     enum nl80211_band band,
3172df90b369SVasanthakumar Thiagarajan 			     struct ath6kl_htcap *htcap)
3173df90b369SVasanthakumar Thiagarajan {
3174df90b369SVasanthakumar Thiagarajan 	struct sk_buff *skb;
3175df90b369SVasanthakumar Thiagarajan 	struct wmi_set_htcap_cmd *cmd;
3176df90b369SVasanthakumar Thiagarajan 
3177df90b369SVasanthakumar Thiagarajan 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3178df90b369SVasanthakumar Thiagarajan 	if (!skb)
3179df90b369SVasanthakumar Thiagarajan 		return -ENOMEM;
3180df90b369SVasanthakumar Thiagarajan 
3181df90b369SVasanthakumar Thiagarajan 	cmd = (struct wmi_set_htcap_cmd *) skb->data;
3182df90b369SVasanthakumar Thiagarajan 
3183df90b369SVasanthakumar Thiagarajan 	/*
318457fbcce3SJohannes Berg 	 * NOTE: Band in firmware matches enum nl80211_band, it is unlikely
3185df90b369SVasanthakumar Thiagarajan 	 * this will be changed in firmware. If at all there is any change in
3186df90b369SVasanthakumar Thiagarajan 	 * band value, the host needs to be fixed.
3187df90b369SVasanthakumar Thiagarajan 	 */
3188df90b369SVasanthakumar Thiagarajan 	cmd->band = band;
3189df90b369SVasanthakumar Thiagarajan 	cmd->ht_enable = !!htcap->ht_enable;
3190df90b369SVasanthakumar Thiagarajan 	cmd->ht20_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_20);
3191df90b369SVasanthakumar Thiagarajan 	cmd->ht40_supported =
3192df90b369SVasanthakumar Thiagarajan 		!!(htcap->cap_info & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
3193df90b369SVasanthakumar Thiagarajan 	cmd->ht40_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_40);
3194df90b369SVasanthakumar Thiagarajan 	cmd->intolerant_40mhz =
3195df90b369SVasanthakumar Thiagarajan 		!!(htcap->cap_info & IEEE80211_HT_CAP_40MHZ_INTOLERANT);
3196df90b369SVasanthakumar Thiagarajan 	cmd->max_ampdu_len_exp = htcap->ampdu_factor;
3197df90b369SVasanthakumar Thiagarajan 
3198df90b369SVasanthakumar Thiagarajan 	ath6kl_dbg(ATH6KL_DBG_WMI,
3199df90b369SVasanthakumar Thiagarajan 		   "Set htcap: band:%d ht_enable:%d 40mhz:%d sgi_20mhz:%d sgi_40mhz:%d 40mhz_intolerant:%d ampdu_len_exp:%d\n",
3200df90b369SVasanthakumar Thiagarajan 		   cmd->band, cmd->ht_enable, cmd->ht40_supported,
3201df90b369SVasanthakumar Thiagarajan 		   cmd->ht20_sgi, cmd->ht40_sgi, cmd->intolerant_40mhz,
3202df90b369SVasanthakumar Thiagarajan 		   cmd->max_ampdu_len_exp);
3203df90b369SVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_HT_CAP_CMDID,
3204df90b369SVasanthakumar Thiagarajan 				   NO_SYNC_WMIFLAG);
3205df90b369SVasanthakumar Thiagarajan }
3206df90b369SVasanthakumar Thiagarajan 
3207003353b0SKalle Valo int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
3208003353b0SKalle Valo {
3209003353b0SKalle Valo 	struct sk_buff *skb;
3210003353b0SKalle Valo 	int ret;
3211003353b0SKalle Valo 
3212003353b0SKalle Valo 	skb = ath6kl_wmi_get_new_buf(len);
3213003353b0SKalle Valo 	if (!skb)
3214003353b0SKalle Valo 		return -ENOMEM;
3215003353b0SKalle Valo 
3216003353b0SKalle Valo 	memcpy(skb->data, buf, len);
3217003353b0SKalle Valo 
3218334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
3219003353b0SKalle Valo 
3220003353b0SKalle Valo 	return ret;
3221003353b0SKalle Valo }
3222003353b0SKalle Valo 
32233f3c4ee7SVasanthakumar Thiagarajan int ath6kl_wmi_mcast_filter_cmd(struct wmi *wmi, u8 if_idx, bool mc_all_on)
32243f3c4ee7SVasanthakumar Thiagarajan {
32253f3c4ee7SVasanthakumar Thiagarajan 	struct sk_buff *skb;
32263f3c4ee7SVasanthakumar Thiagarajan 	struct wmi_mcast_filter_cmd *cmd;
32273f3c4ee7SVasanthakumar Thiagarajan 	int ret;
32283f3c4ee7SVasanthakumar Thiagarajan 
32293f3c4ee7SVasanthakumar Thiagarajan 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
32303f3c4ee7SVasanthakumar Thiagarajan 	if (!skb)
32313f3c4ee7SVasanthakumar Thiagarajan 		return -ENOMEM;
32323f3c4ee7SVasanthakumar Thiagarajan 
32333f3c4ee7SVasanthakumar Thiagarajan 	cmd = (struct wmi_mcast_filter_cmd *) skb->data;
32343f3c4ee7SVasanthakumar Thiagarajan 	cmd->mcast_all_enable = mc_all_on;
32353f3c4ee7SVasanthakumar Thiagarajan 
32363f3c4ee7SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_MCAST_FILTER_CMDID,
32373f3c4ee7SVasanthakumar Thiagarajan 				  NO_SYNC_WMIFLAG);
32383f3c4ee7SVasanthakumar Thiagarajan 	return ret;
32393f3c4ee7SVasanthakumar Thiagarajan }
3240003353b0SKalle Valo 
3241f914edd3SVasanthakumar Thiagarajan int ath6kl_wmi_add_del_mcast_filter_cmd(struct wmi *wmi, u8 if_idx,
3242f914edd3SVasanthakumar Thiagarajan 					u8 *filter, bool add_filter)
3243f914edd3SVasanthakumar Thiagarajan {
3244f914edd3SVasanthakumar Thiagarajan 	struct sk_buff *skb;
3245f914edd3SVasanthakumar Thiagarajan 	struct wmi_mcast_filter_add_del_cmd *cmd;
3246f914edd3SVasanthakumar Thiagarajan 	int ret;
3247f914edd3SVasanthakumar Thiagarajan 
3248f914edd3SVasanthakumar Thiagarajan 	if ((filter[0] != 0x33 || filter[1] != 0x33) &&
3249f914edd3SVasanthakumar Thiagarajan 	    (filter[0] != 0x01 || filter[1] != 0x00 ||
3250f914edd3SVasanthakumar Thiagarajan 	    filter[2] != 0x5e || filter[3] > 0x7f)) {
3251f914edd3SVasanthakumar Thiagarajan 		ath6kl_warn("invalid multicast filter address\n");
3252f914edd3SVasanthakumar Thiagarajan 		return -EINVAL;
3253f914edd3SVasanthakumar Thiagarajan 	}
3254f914edd3SVasanthakumar Thiagarajan 
3255f914edd3SVasanthakumar Thiagarajan 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3256f914edd3SVasanthakumar Thiagarajan 	if (!skb)
3257f914edd3SVasanthakumar Thiagarajan 		return -ENOMEM;
3258f914edd3SVasanthakumar Thiagarajan 
3259f914edd3SVasanthakumar Thiagarajan 	cmd = (struct wmi_mcast_filter_add_del_cmd *) skb->data;
3260f914edd3SVasanthakumar Thiagarajan 	memcpy(cmd->mcast_mac, filter, ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
3261f914edd3SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3262f914edd3SVasanthakumar Thiagarajan 				  add_filter ? WMI_SET_MCAST_FILTER_CMDID :
3263f914edd3SVasanthakumar Thiagarajan 				  WMI_DEL_MCAST_FILTER_CMDID,
3264f914edd3SVasanthakumar Thiagarajan 				  NO_SYNC_WMIFLAG);
3265f914edd3SVasanthakumar Thiagarajan 
3266f914edd3SVasanthakumar Thiagarajan 	return ret;
3267f914edd3SVasanthakumar Thiagarajan }
3268f914edd3SVasanthakumar Thiagarajan 
3269c422d52dSThomas Pedersen int ath6kl_wmi_sta_bmiss_enhance_cmd(struct wmi *wmi, u8 if_idx, bool enhance)
3270c422d52dSThomas Pedersen {
3271c422d52dSThomas Pedersen 	struct sk_buff *skb;
3272c422d52dSThomas Pedersen 	struct wmi_sta_bmiss_enhance_cmd *cmd;
3273c422d52dSThomas Pedersen 	int ret;
3274c422d52dSThomas Pedersen 
3275c422d52dSThomas Pedersen 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3276c422d52dSThomas Pedersen 	if (!skb)
3277c422d52dSThomas Pedersen 		return -ENOMEM;
3278c422d52dSThomas Pedersen 
3279c422d52dSThomas Pedersen 	cmd = (struct wmi_sta_bmiss_enhance_cmd *) skb->data;
3280c422d52dSThomas Pedersen 	cmd->enable = enhance ? 1 : 0;
3281c422d52dSThomas Pedersen 
3282c422d52dSThomas Pedersen 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3283c422d52dSThomas Pedersen 				  WMI_STA_BMISS_ENHANCE_CMDID,
3284c422d52dSThomas Pedersen 				  NO_SYNC_WMIFLAG);
3285c422d52dSThomas Pedersen 	return ret;
3286c422d52dSThomas Pedersen }
3287c422d52dSThomas Pedersen 
328884841ba2SKalle Valo int ath6kl_wmi_set_regdomain_cmd(struct wmi *wmi, const char *alpha2)
328984841ba2SKalle Valo {
329084841ba2SKalle Valo 	struct sk_buff *skb;
329184841ba2SKalle Valo 	struct wmi_set_regdomain_cmd *cmd;
329284841ba2SKalle Valo 
329384841ba2SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
329484841ba2SKalle Valo 	if (!skb)
329584841ba2SKalle Valo 		return -ENOMEM;
329684841ba2SKalle Valo 
329784841ba2SKalle Valo 	cmd = (struct wmi_set_regdomain_cmd *) skb->data;
329884841ba2SKalle Valo 	memcpy(cmd->iso_name, alpha2, 2);
329984841ba2SKalle Valo 
330084841ba2SKalle Valo 	return ath6kl_wmi_cmd_send(wmi, 0, skb,
330184841ba2SKalle Valo 				   WMI_SET_REGDOMAIN_CMDID,
330284841ba2SKalle Valo 				   NO_SYNC_WMIFLAG);
330384841ba2SKalle Valo }
330484841ba2SKalle Valo 
3305c1d32d30SJessica Wu s32 ath6kl_wmi_get_rate(struct wmi *wmi, s8 rate_index)
3306bdcd8170SKalle Valo {
3307c1d32d30SJessica Wu 	struct ath6kl *ar = wmi->parent_dev;
330883685091SDengke Qiu 	u8 sgi = 0;
3309c1d32d30SJessica Wu 	s32 ret;
331083685091SDengke Qiu 
3311bdcd8170SKalle Valo 	if (rate_index == RATE_AUTO)
3312bdcd8170SKalle Valo 		return 0;
3313bdcd8170SKalle Valo 
331483685091SDengke Qiu 	/* SGI is stored as the MSB of the rate_index */
331583685091SDengke Qiu 	if (rate_index & RATE_INDEX_MSB) {
331683685091SDengke Qiu 		rate_index &= RATE_INDEX_WITHOUT_SGI_MASK;
331783685091SDengke Qiu 		sgi = 1;
331883685091SDengke Qiu 	}
331983685091SDengke Qiu 
3320c1d32d30SJessica Wu 	if (test_bit(ATH6KL_FW_CAPABILITY_RATETABLE_MCS15,
3321c1d32d30SJessica Wu 		     ar->fw_capabilities)) {
3322c1d32d30SJessica Wu 		if (WARN_ON(rate_index >= ARRAY_SIZE(wmi_rate_tbl_mcs15)))
3323c1d32d30SJessica Wu 			return 0;
332483685091SDengke Qiu 
3325c1d32d30SJessica Wu 		ret = wmi_rate_tbl_mcs15[(u32) rate_index][sgi];
3326c1d32d30SJessica Wu 	} else {
3327c1d32d30SJessica Wu 		if (WARN_ON(rate_index >= ARRAY_SIZE(wmi_rate_tbl)))
3328c1d32d30SJessica Wu 			return 0;
3329c1d32d30SJessica Wu 
3330c1d32d30SJessica Wu 		ret = wmi_rate_tbl[(u32) rate_index][sgi];
3331c1d32d30SJessica Wu 	}
3332c1d32d30SJessica Wu 
3333c1d32d30SJessica Wu 	return ret;
3334bdcd8170SKalle Valo }
3335bdcd8170SKalle Valo 
3336bdcd8170SKalle Valo static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
3337bdcd8170SKalle Valo 					      u32 len)
3338bdcd8170SKalle Valo {
3339bdcd8170SKalle Valo 	struct wmi_pmkid_list_reply *reply;
3340bdcd8170SKalle Valo 	u32 expected_len;
3341bdcd8170SKalle Valo 
3342bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_pmkid_list_reply))
3343bdcd8170SKalle Valo 		return -EINVAL;
3344bdcd8170SKalle Valo 
3345bdcd8170SKalle Valo 	reply = (struct wmi_pmkid_list_reply *)datap;
3346bdcd8170SKalle Valo 	expected_len = sizeof(reply->num_pmkid) +
3347bdcd8170SKalle Valo 		le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
3348bdcd8170SKalle Valo 
3349bdcd8170SKalle Valo 	if (len < expected_len)
3350bdcd8170SKalle Valo 		return -EINVAL;
3351bdcd8170SKalle Valo 
3352bdcd8170SKalle Valo 	return 0;
3353bdcd8170SKalle Valo }
3354bdcd8170SKalle Valo 
3355240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
3356240d2799SVasanthakumar Thiagarajan 					 struct ath6kl_vif *vif)
3357bdcd8170SKalle Valo {
3358bdcd8170SKalle Valo 	struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
3359bdcd8170SKalle Valo 
3360240d2799SVasanthakumar Thiagarajan 	aggr_recv_addba_req_evt(vif, cmd->tid,
3361bdcd8170SKalle Valo 				le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
3362bdcd8170SKalle Valo 
3363bdcd8170SKalle Valo 	return 0;
3364bdcd8170SKalle Valo }
3365bdcd8170SKalle Valo 
3366240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
3367240d2799SVasanthakumar Thiagarajan 					 struct ath6kl_vif *vif)
3368bdcd8170SKalle Valo {
3369bdcd8170SKalle Valo 	struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
3370bdcd8170SKalle Valo 
3371240d2799SVasanthakumar Thiagarajan 	aggr_recv_delba_req_evt(vif, cmd->tid);
3372bdcd8170SKalle Valo 
3373bdcd8170SKalle Valo 	return 0;
3374bdcd8170SKalle Valo }
3375bdcd8170SKalle Valo 
3376bdcd8170SKalle Valo /*  AP mode functions */
33776a7c9badSJouni Malinen 
3378334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
3379334234b5SVasanthakumar Thiagarajan 				 struct wmi_connect_cmd *p)
33806a7c9badSJouni Malinen {
33816a7c9badSJouni Malinen 	struct sk_buff *skb;
33826a7c9badSJouni Malinen 	struct wmi_connect_cmd *cm;
33836a7c9badSJouni Malinen 	int res;
33846a7c9badSJouni Malinen 
33856a7c9badSJouni Malinen 	skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
33866a7c9badSJouni Malinen 	if (!skb)
33876a7c9badSJouni Malinen 		return -ENOMEM;
33886a7c9badSJouni Malinen 
33896a7c9badSJouni Malinen 	cm = (struct wmi_connect_cmd *) skb->data;
33906a7c9badSJouni Malinen 	memcpy(cm, p, sizeof(*cm));
33916a7c9badSJouni Malinen 
3392334234b5SVasanthakumar Thiagarajan 	res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
33936a7c9badSJouni Malinen 				  NO_SYNC_WMIFLAG);
3394cdeb8602SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
3395cdeb8602SKalle Valo 		   "%s: nw_type=%u auth_mode=%u ch=%u ctrl_flags=0x%x-> res=%d\n",
33966a7c9badSJouni Malinen 		   __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
33976a7c9badSJouni Malinen 		   le32_to_cpu(p->ctrl_flags), res);
33986a7c9badSJouni Malinen 	return res;
33996a7c9badSJouni Malinen }
34006a7c9badSJouni Malinen 
3401334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
3402334234b5SVasanthakumar Thiagarajan 			   u16 reason)
340323875136SJouni Malinen {
340423875136SJouni Malinen 	struct sk_buff *skb;
340523875136SJouni Malinen 	struct wmi_ap_set_mlme_cmd *cm;
340623875136SJouni Malinen 
340723875136SJouni Malinen 	skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
340823875136SJouni Malinen 	if (!skb)
340923875136SJouni Malinen 		return -ENOMEM;
341023875136SJouni Malinen 
341123875136SJouni Malinen 	cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
341223875136SJouni Malinen 	memcpy(cm->mac, mac, ETH_ALEN);
341323875136SJouni Malinen 	cm->reason = cpu_to_le16(reason);
341423875136SJouni Malinen 	cm->cmd = cmd;
341523875136SJouni Malinen 
34167397ddebSAarthi Thiruvengadam 	ath6kl_dbg(ATH6KL_DBG_WMI, "ap_set_mlme: cmd=%d reason=%d\n", cm->cmd,
34177397ddebSAarthi Thiruvengadam 		   cm->reason);
34187397ddebSAarthi Thiruvengadam 
3419334234b5SVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
342023875136SJouni Malinen 				   NO_SYNC_WMIFLAG);
342123875136SJouni Malinen }
342223875136SJouni Malinen 
342367cd22e4SThomas Pedersen int ath6kl_wmi_ap_hidden_ssid(struct wmi *wmi, u8 if_idx, bool enable)
342467cd22e4SThomas Pedersen {
342567cd22e4SThomas Pedersen 	struct sk_buff *skb;
342667cd22e4SThomas Pedersen 	struct wmi_ap_hidden_ssid_cmd *cmd;
342767cd22e4SThomas Pedersen 
342867cd22e4SThomas Pedersen 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
342967cd22e4SThomas Pedersen 	if (!skb)
343067cd22e4SThomas Pedersen 		return -ENOMEM;
343167cd22e4SThomas Pedersen 
343267cd22e4SThomas Pedersen 	cmd = (struct wmi_ap_hidden_ssid_cmd *) skb->data;
343367cd22e4SThomas Pedersen 	cmd->hidden_ssid = enable ? 1 : 0;
343467cd22e4SThomas Pedersen 
343567cd22e4SThomas Pedersen 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_HIDDEN_SSID_CMDID,
343667cd22e4SThomas Pedersen 				   NO_SYNC_WMIFLAG);
343767cd22e4SThomas Pedersen }
343867cd22e4SThomas Pedersen 
3439c1762a3fSThirumalai Pachamuthu /* This command will be used to enable/disable AP uAPSD feature */
3440c1762a3fSThirumalai Pachamuthu int ath6kl_wmi_ap_set_apsd(struct wmi *wmi, u8 if_idx, u8 enable)
3441c1762a3fSThirumalai Pachamuthu {
3442c1762a3fSThirumalai Pachamuthu 	struct wmi_ap_set_apsd_cmd *cmd;
3443c1762a3fSThirumalai Pachamuthu 	struct sk_buff *skb;
3444c1762a3fSThirumalai Pachamuthu 
3445c1762a3fSThirumalai Pachamuthu 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3446c1762a3fSThirumalai Pachamuthu 	if (!skb)
3447c1762a3fSThirumalai Pachamuthu 		return -ENOMEM;
3448c1762a3fSThirumalai Pachamuthu 
3449c1762a3fSThirumalai Pachamuthu 	cmd = (struct wmi_ap_set_apsd_cmd *)skb->data;
3450c1762a3fSThirumalai Pachamuthu 	cmd->enable = enable;
3451c1762a3fSThirumalai Pachamuthu 
3452c1762a3fSThirumalai Pachamuthu 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_APSD_CMDID,
3453c1762a3fSThirumalai Pachamuthu 				   NO_SYNC_WMIFLAG);
3454c1762a3fSThirumalai Pachamuthu }
3455c1762a3fSThirumalai Pachamuthu 
3456c1762a3fSThirumalai Pachamuthu int ath6kl_wmi_set_apsd_bfrd_traf(struct wmi *wmi, u8 if_idx,
3457c1762a3fSThirumalai Pachamuthu 					     u16 aid, u16 bitmap, u32 flags)
3458c1762a3fSThirumalai Pachamuthu {
3459c1762a3fSThirumalai Pachamuthu 	struct wmi_ap_apsd_buffered_traffic_cmd *cmd;
3460c1762a3fSThirumalai Pachamuthu 	struct sk_buff *skb;
3461c1762a3fSThirumalai Pachamuthu 
3462c1762a3fSThirumalai Pachamuthu 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3463c1762a3fSThirumalai Pachamuthu 	if (!skb)
3464c1762a3fSThirumalai Pachamuthu 		return -ENOMEM;
3465c1762a3fSThirumalai Pachamuthu 
3466c1762a3fSThirumalai Pachamuthu 	cmd = (struct wmi_ap_apsd_buffered_traffic_cmd *)skb->data;
3467c1762a3fSThirumalai Pachamuthu 	cmd->aid = cpu_to_le16(aid);
3468c1762a3fSThirumalai Pachamuthu 	cmd->bitmap = cpu_to_le16(bitmap);
3469c1762a3fSThirumalai Pachamuthu 	cmd->flags = cpu_to_le32(flags);
3470c1762a3fSThirumalai Pachamuthu 
3471c1762a3fSThirumalai Pachamuthu 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3472c1762a3fSThirumalai Pachamuthu 				   WMI_AP_APSD_BUFFERED_TRAFFIC_CMDID,
3473c1762a3fSThirumalai Pachamuthu 				   NO_SYNC_WMIFLAG);
3474c1762a3fSThirumalai Pachamuthu }
3475c1762a3fSThirumalai Pachamuthu 
3476240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
3477240d2799SVasanthakumar Thiagarajan 				      struct ath6kl_vif *vif)
3478bdcd8170SKalle Valo {
3479bdcd8170SKalle Valo 	struct wmi_pspoll_event *ev;
3480bdcd8170SKalle Valo 
3481bdcd8170SKalle Valo 	if (len < sizeof(struct wmi_pspoll_event))
3482bdcd8170SKalle Valo 		return -EINVAL;
3483bdcd8170SKalle Valo 
3484bdcd8170SKalle Valo 	ev = (struct wmi_pspoll_event *) datap;
3485bdcd8170SKalle Valo 
3486240d2799SVasanthakumar Thiagarajan 	ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
3487bdcd8170SKalle Valo 
3488bdcd8170SKalle Valo 	return 0;
3489bdcd8170SKalle Valo }
3490bdcd8170SKalle Valo 
3491240d2799SVasanthakumar Thiagarajan static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
3492240d2799SVasanthakumar Thiagarajan 					  struct ath6kl_vif *vif)
3493bdcd8170SKalle Valo {
3494240d2799SVasanthakumar Thiagarajan 	ath6kl_dtimexpiry_event(vif);
3495bdcd8170SKalle Valo 
3496bdcd8170SKalle Valo 	return 0;
3497bdcd8170SKalle Valo }
3498bdcd8170SKalle Valo 
3499334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
3500334234b5SVasanthakumar Thiagarajan 			   bool flag)
3501bdcd8170SKalle Valo {
3502bdcd8170SKalle Valo 	struct sk_buff *skb;
3503bdcd8170SKalle Valo 	struct wmi_ap_set_pvb_cmd *cmd;
3504bdcd8170SKalle Valo 	int ret;
3505bdcd8170SKalle Valo 
3506bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
3507bdcd8170SKalle Valo 	if (!skb)
3508bdcd8170SKalle Valo 		return -ENOMEM;
3509bdcd8170SKalle Valo 
3510bdcd8170SKalle Valo 	cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
3511bdcd8170SKalle Valo 	cmd->aid = cpu_to_le16(aid);
3512d6e51e6aSJouni Malinen 	cmd->rsvd = cpu_to_le16(0);
3513bdcd8170SKalle Valo 	cmd->flag = cpu_to_le32(flag);
3514bdcd8170SKalle Valo 
3515334234b5SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
3516bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
3517bdcd8170SKalle Valo 
3518b9301505SChaehyun Lim 	return ret;
3519bdcd8170SKalle Valo }
3520bdcd8170SKalle Valo 
35210ce59445SVasanthakumar Thiagarajan int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
35220ce59445SVasanthakumar Thiagarajan 				       u8 rx_meta_ver,
3523bdcd8170SKalle Valo 				       bool rx_dot11_hdr, bool defrag_on_host)
3524bdcd8170SKalle Valo {
3525bdcd8170SKalle Valo 	struct sk_buff *skb;
3526bdcd8170SKalle Valo 	struct wmi_rx_frame_format_cmd *cmd;
3527bdcd8170SKalle Valo 	int ret;
3528bdcd8170SKalle Valo 
3529bdcd8170SKalle Valo 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3530bdcd8170SKalle Valo 	if (!skb)
3531bdcd8170SKalle Valo 		return -ENOMEM;
3532bdcd8170SKalle Valo 
3533bdcd8170SKalle Valo 	cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
3534bdcd8170SKalle Valo 	cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
3535bdcd8170SKalle Valo 	cmd->defrag_on_host = defrag_on_host ? 1 : 0;
3536bdcd8170SKalle Valo 	cmd->meta_ver = rx_meta_ver;
3537bdcd8170SKalle Valo 
3538bdcd8170SKalle Valo 	/* Delete the local aggr state, on host */
35390ce59445SVasanthakumar Thiagarajan 	ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
3540bdcd8170SKalle Valo 				  NO_SYNC_WMIFLAG);
3541bdcd8170SKalle Valo 
3542bdcd8170SKalle Valo 	return ret;
3543bdcd8170SKalle Valo }
3544bdcd8170SKalle Valo 
3545334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
3546334234b5SVasanthakumar Thiagarajan 			     const u8 *ie, u8 ie_len)
35476a7c9badSJouni Malinen {
35486a7c9badSJouni Malinen 	struct sk_buff *skb;
35496a7c9badSJouni Malinen 	struct wmi_set_appie_cmd *p;
35506a7c9badSJouni Malinen 
35516a7c9badSJouni Malinen 	skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
35526a7c9badSJouni Malinen 	if (!skb)
35536a7c9badSJouni Malinen 		return -ENOMEM;
35546a7c9badSJouni Malinen 
3555cdeb8602SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
3556cdeb8602SKalle Valo 		   "set_appie_cmd: mgmt_frm_type=%u ie_len=%u\n",
3557cdeb8602SKalle Valo 		   mgmt_frm_type, ie_len);
35586a7c9badSJouni Malinen 	p = (struct wmi_set_appie_cmd *) skb->data;
35596a7c9badSJouni Malinen 	p->mgmt_frm_type = mgmt_frm_type;
35606a7c9badSJouni Malinen 	p->ie_len = ie_len;
356110509f90SKalle Valo 
356210509f90SKalle Valo 	if (ie != NULL && ie_len > 0)
35636a7c9badSJouni Malinen 		memcpy(p->ie_info, ie, ie_len);
356410509f90SKalle Valo 
3565334234b5SVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
35666a7c9badSJouni Malinen 				   NO_SYNC_WMIFLAG);
35676a7c9badSJouni Malinen }
35686a7c9badSJouni Malinen 
3569d97c121bSVasanthakumar Thiagarajan int ath6kl_wmi_set_ie_cmd(struct wmi *wmi, u8 if_idx, u8 ie_id, u8 ie_field,
3570d97c121bSVasanthakumar Thiagarajan 			  const u8 *ie_info, u8 ie_len)
3571d97c121bSVasanthakumar Thiagarajan {
3572d97c121bSVasanthakumar Thiagarajan 	struct sk_buff *skb;
3573d97c121bSVasanthakumar Thiagarajan 	struct wmi_set_ie_cmd *p;
3574d97c121bSVasanthakumar Thiagarajan 
3575d97c121bSVasanthakumar Thiagarajan 	skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
3576d97c121bSVasanthakumar Thiagarajan 	if (!skb)
3577d97c121bSVasanthakumar Thiagarajan 		return -ENOMEM;
3578d97c121bSVasanthakumar Thiagarajan 
3579d97c121bSVasanthakumar Thiagarajan 	ath6kl_dbg(ATH6KL_DBG_WMI, "set_ie_cmd: ie_id=%u ie_ie_field=%u ie_len=%u\n",
3580d97c121bSVasanthakumar Thiagarajan 		   ie_id, ie_field, ie_len);
3581d97c121bSVasanthakumar Thiagarajan 	p = (struct wmi_set_ie_cmd *) skb->data;
3582d97c121bSVasanthakumar Thiagarajan 	p->ie_id = ie_id;
3583d97c121bSVasanthakumar Thiagarajan 	p->ie_field = ie_field;
3584d97c121bSVasanthakumar Thiagarajan 	p->ie_len = ie_len;
3585d97c121bSVasanthakumar Thiagarajan 	if (ie_info && ie_len > 0)
3586d97c121bSVasanthakumar Thiagarajan 		memcpy(p->ie_info, ie_info, ie_len);
3587d97c121bSVasanthakumar Thiagarajan 
3588d97c121bSVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IE_CMDID,
3589d97c121bSVasanthakumar Thiagarajan 				   NO_SYNC_WMIFLAG);
3590d97c121bSVasanthakumar Thiagarajan }
3591d97c121bSVasanthakumar Thiagarajan 
35926465ddcfSJouni Malinen int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
35936465ddcfSJouni Malinen {
35946465ddcfSJouni Malinen 	struct sk_buff *skb;
35956465ddcfSJouni Malinen 	struct wmi_disable_11b_rates_cmd *cmd;
35966465ddcfSJouni Malinen 
35976465ddcfSJouni Malinen 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
35986465ddcfSJouni Malinen 	if (!skb)
35996465ddcfSJouni Malinen 		return -ENOMEM;
36006465ddcfSJouni Malinen 
36016465ddcfSJouni Malinen 	ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
36026465ddcfSJouni Malinen 		   disable);
36036465ddcfSJouni Malinen 	cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
36046465ddcfSJouni Malinen 	cmd->disable = disable ? 1 : 0;
36056465ddcfSJouni Malinen 
3606334234b5SVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
36076465ddcfSJouni Malinen 				   NO_SYNC_WMIFLAG);
36086465ddcfSJouni Malinen }
36096465ddcfSJouni Malinen 
3610334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
36116465ddcfSJouni Malinen {
36126465ddcfSJouni Malinen 	struct sk_buff *skb;
36136465ddcfSJouni Malinen 	struct wmi_remain_on_chnl_cmd *p;
36146465ddcfSJouni Malinen 
36156465ddcfSJouni Malinen 	skb = ath6kl_wmi_get_new_buf(sizeof(*p));
36166465ddcfSJouni Malinen 	if (!skb)
36176465ddcfSJouni Malinen 		return -ENOMEM;
36186465ddcfSJouni Malinen 
36196465ddcfSJouni Malinen 	ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
36206465ddcfSJouni Malinen 		   freq, dur);
36216465ddcfSJouni Malinen 	p = (struct wmi_remain_on_chnl_cmd *) skb->data;
36226465ddcfSJouni Malinen 	p->freq = cpu_to_le32(freq);
36236465ddcfSJouni Malinen 	p->duration = cpu_to_le32(dur);
3624334234b5SVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
36256465ddcfSJouni Malinen 				   NO_SYNC_WMIFLAG);
36266465ddcfSJouni Malinen }
36276465ddcfSJouni Malinen 
36283ca9d1fcSAarthi Thiruvengadam /* ath6kl_wmi_send_action_cmd is to be deprecated. Use
36293ca9d1fcSAarthi Thiruvengadam  * ath6kl_wmi_send_mgmt_cmd instead. The new function supports P2P
36303ca9d1fcSAarthi Thiruvengadam  * mgmt operations using station interface.
36313ca9d1fcSAarthi Thiruvengadam  */
3632d0ff7383SNaveen Gangadharan static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3633d0ff7383SNaveen Gangadharan 				      u32 freq, u32 wait, const u8 *data,
3634d0ff7383SNaveen Gangadharan 				      u16 data_len)
36356465ddcfSJouni Malinen {
36366465ddcfSJouni Malinen 	struct sk_buff *skb;
36376465ddcfSJouni Malinen 	struct wmi_send_action_cmd *p;
3638a0df5db1SJouni Malinen 	u8 *buf;
36396465ddcfSJouni Malinen 
36406465ddcfSJouni Malinen 	if (wait)
36416465ddcfSJouni Malinen 		return -EINVAL; /* Offload for wait not supported */
36426465ddcfSJouni Malinen 
3643ab8c31ddSFuqian Huang 	buf = kmemdup(data, data_len, GFP_KERNEL);
3644a0df5db1SJouni Malinen 	if (!buf)
36456465ddcfSJouni Malinen 		return -ENOMEM;
36466465ddcfSJouni Malinen 
3647a0df5db1SJouni Malinen 	skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3648a0df5db1SJouni Malinen 	if (!skb) {
3649a0df5db1SJouni Malinen 		kfree(buf);
3650a0df5db1SJouni Malinen 		return -ENOMEM;
3651a0df5db1SJouni Malinen 	}
3652a0df5db1SJouni Malinen 
3653a0df5db1SJouni Malinen 	kfree(wmi->last_mgmt_tx_frame);
3654a0df5db1SJouni Malinen 	wmi->last_mgmt_tx_frame = buf;
3655a0df5db1SJouni Malinen 	wmi->last_mgmt_tx_frame_len = data_len;
3656a0df5db1SJouni Malinen 
3657cdeb8602SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
3658cdeb8602SKalle Valo 		   "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
3659cdeb8602SKalle Valo 		   id, freq, wait, data_len);
36606465ddcfSJouni Malinen 	p = (struct wmi_send_action_cmd *) skb->data;
36616465ddcfSJouni Malinen 	p->id = cpu_to_le32(id);
36626465ddcfSJouni Malinen 	p->freq = cpu_to_le32(freq);
36636465ddcfSJouni Malinen 	p->wait = cpu_to_le32(wait);
36646465ddcfSJouni Malinen 	p->len = cpu_to_le16(data_len);
36656465ddcfSJouni Malinen 	memcpy(p->data, data, data_len);
3666334234b5SVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
36676465ddcfSJouni Malinen 				   NO_SYNC_WMIFLAG);
36686465ddcfSJouni Malinen }
36696465ddcfSJouni Malinen 
3670d0ff7383SNaveen Gangadharan static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3671d0ff7383SNaveen Gangadharan 				      u32 freq, u32 wait, const u8 *data,
3672d0ff7383SNaveen Gangadharan 				      u16 data_len, u32 no_cck)
36733ca9d1fcSAarthi Thiruvengadam {
36743ca9d1fcSAarthi Thiruvengadam 	struct sk_buff *skb;
36753ca9d1fcSAarthi Thiruvengadam 	struct wmi_send_mgmt_cmd *p;
36763ca9d1fcSAarthi Thiruvengadam 	u8 *buf;
36773ca9d1fcSAarthi Thiruvengadam 
36783ca9d1fcSAarthi Thiruvengadam 	if (wait)
36793ca9d1fcSAarthi Thiruvengadam 		return -EINVAL; /* Offload for wait not supported */
36803ca9d1fcSAarthi Thiruvengadam 
3681ab8c31ddSFuqian Huang 	buf = kmemdup(data, data_len, GFP_KERNEL);
36823ca9d1fcSAarthi Thiruvengadam 	if (!buf)
36833ca9d1fcSAarthi Thiruvengadam 		return -ENOMEM;
36843ca9d1fcSAarthi Thiruvengadam 
36853ca9d1fcSAarthi Thiruvengadam 	skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
36863ca9d1fcSAarthi Thiruvengadam 	if (!skb) {
36873ca9d1fcSAarthi Thiruvengadam 		kfree(buf);
36883ca9d1fcSAarthi Thiruvengadam 		return -ENOMEM;
36893ca9d1fcSAarthi Thiruvengadam 	}
36903ca9d1fcSAarthi Thiruvengadam 
36913ca9d1fcSAarthi Thiruvengadam 	kfree(wmi->last_mgmt_tx_frame);
36923ca9d1fcSAarthi Thiruvengadam 	wmi->last_mgmt_tx_frame = buf;
36933ca9d1fcSAarthi Thiruvengadam 	wmi->last_mgmt_tx_frame_len = data_len;
36943ca9d1fcSAarthi Thiruvengadam 
3695cdeb8602SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
3696cdeb8602SKalle Valo 		   "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
3697cdeb8602SKalle Valo 		   id, freq, wait, data_len);
36983ca9d1fcSAarthi Thiruvengadam 	p = (struct wmi_send_mgmt_cmd *) skb->data;
36993ca9d1fcSAarthi Thiruvengadam 	p->id = cpu_to_le32(id);
37003ca9d1fcSAarthi Thiruvengadam 	p->freq = cpu_to_le32(freq);
37013ca9d1fcSAarthi Thiruvengadam 	p->wait = cpu_to_le32(wait);
37023ca9d1fcSAarthi Thiruvengadam 	p->no_cck = cpu_to_le32(no_cck);
37033ca9d1fcSAarthi Thiruvengadam 	p->len = cpu_to_le16(data_len);
37043ca9d1fcSAarthi Thiruvengadam 	memcpy(p->data, data, data_len);
37053ca9d1fcSAarthi Thiruvengadam 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID,
37063ca9d1fcSAarthi Thiruvengadam 				   NO_SYNC_WMIFLAG);
37073ca9d1fcSAarthi Thiruvengadam }
37083ca9d1fcSAarthi Thiruvengadam 
3709d0ff7383SNaveen Gangadharan int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
3710d0ff7383SNaveen Gangadharan 				u32 wait, const u8 *data, u16 data_len,
3711d0ff7383SNaveen Gangadharan 				u32 no_cck)
3712d0ff7383SNaveen Gangadharan {
3713d0ff7383SNaveen Gangadharan 	int status;
3714d0ff7383SNaveen Gangadharan 	struct ath6kl *ar = wmi->parent_dev;
3715d0ff7383SNaveen Gangadharan 
3716d0ff7383SNaveen Gangadharan 	if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
3717d0ff7383SNaveen Gangadharan 		     ar->fw_capabilities)) {
3718d0ff7383SNaveen Gangadharan 		/*
3719d0ff7383SNaveen Gangadharan 		 * If capable of doing P2P mgmt operations using
3720d0ff7383SNaveen Gangadharan 		 * station interface, send additional information like
3721d0ff7383SNaveen Gangadharan 		 * supported rates to advertise and xmit rates for
3722d0ff7383SNaveen Gangadharan 		 * probe requests
3723d0ff7383SNaveen Gangadharan 		 */
3724d0ff7383SNaveen Gangadharan 		status = __ath6kl_wmi_send_mgmt_cmd(ar->wmi, if_idx, id, freq,
3725d0ff7383SNaveen Gangadharan 						    wait, data, data_len,
3726d0ff7383SNaveen Gangadharan 						    no_cck);
3727d0ff7383SNaveen Gangadharan 	} else {
3728d0ff7383SNaveen Gangadharan 		status = ath6kl_wmi_send_action_cmd(ar->wmi, if_idx, id, freq,
3729d0ff7383SNaveen Gangadharan 						    wait, data, data_len);
3730d0ff7383SNaveen Gangadharan 	}
3731d0ff7383SNaveen Gangadharan 
3732d0ff7383SNaveen Gangadharan 	return status;
3733d0ff7383SNaveen Gangadharan }
3734d0ff7383SNaveen Gangadharan 
3735334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
3736334234b5SVasanthakumar Thiagarajan 				       const u8 *dst, const u8 *data,
3737334234b5SVasanthakumar Thiagarajan 				       u16 data_len)
37386465ddcfSJouni Malinen {
37396465ddcfSJouni Malinen 	struct sk_buff *skb;
37406465ddcfSJouni Malinen 	struct wmi_p2p_probe_response_cmd *p;
3741bd24a50fSAarthi Thiruvengadam 	size_t cmd_len = sizeof(*p) + data_len;
37426465ddcfSJouni Malinen 
3743bd24a50fSAarthi Thiruvengadam 	if (data_len == 0)
3744bd24a50fSAarthi Thiruvengadam 		cmd_len++; /* work around target minimum length requirement */
3745bd24a50fSAarthi Thiruvengadam 
3746bd24a50fSAarthi Thiruvengadam 	skb = ath6kl_wmi_get_new_buf(cmd_len);
37476465ddcfSJouni Malinen 	if (!skb)
37486465ddcfSJouni Malinen 		return -ENOMEM;
37496465ddcfSJouni Malinen 
3750cdeb8602SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_WMI,
3751cdeb8602SKalle Valo 		   "send_probe_response_cmd: freq=%u dst=%pM len=%u\n",
3752cdeb8602SKalle Valo 		   freq, dst, data_len);
37536465ddcfSJouni Malinen 	p = (struct wmi_p2p_probe_response_cmd *) skb->data;
37546465ddcfSJouni Malinen 	p->freq = cpu_to_le32(freq);
37556465ddcfSJouni Malinen 	memcpy(p->destination_addr, dst, ETH_ALEN);
37566465ddcfSJouni Malinen 	p->len = cpu_to_le16(data_len);
37576465ddcfSJouni Malinen 	memcpy(p->data, data, data_len);
3758334234b5SVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3759334234b5SVasanthakumar Thiagarajan 				   WMI_SEND_PROBE_RESPONSE_CMDID,
37606465ddcfSJouni Malinen 				   NO_SYNC_WMIFLAG);
37616465ddcfSJouni Malinen }
37626465ddcfSJouni Malinen 
37630ce59445SVasanthakumar Thiagarajan int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
37646465ddcfSJouni Malinen {
37656465ddcfSJouni Malinen 	struct sk_buff *skb;
37666465ddcfSJouni Malinen 	struct wmi_probe_req_report_cmd *p;
37676465ddcfSJouni Malinen 
37686465ddcfSJouni Malinen 	skb = ath6kl_wmi_get_new_buf(sizeof(*p));
37696465ddcfSJouni Malinen 	if (!skb)
37706465ddcfSJouni Malinen 		return -ENOMEM;
37716465ddcfSJouni Malinen 
37726465ddcfSJouni Malinen 	ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
37736465ddcfSJouni Malinen 		   enable);
37746465ddcfSJouni Malinen 	p = (struct wmi_probe_req_report_cmd *) skb->data;
37756465ddcfSJouni Malinen 	p->enable = enable ? 1 : 0;
37760ce59445SVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
37776465ddcfSJouni Malinen 				   NO_SYNC_WMIFLAG);
37786465ddcfSJouni Malinen }
37796465ddcfSJouni Malinen 
37800ce59445SVasanthakumar Thiagarajan int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
37816465ddcfSJouni Malinen {
37826465ddcfSJouni Malinen 	struct sk_buff *skb;
37836465ddcfSJouni Malinen 	struct wmi_get_p2p_info *p;
37846465ddcfSJouni Malinen 
37856465ddcfSJouni Malinen 	skb = ath6kl_wmi_get_new_buf(sizeof(*p));
37866465ddcfSJouni Malinen 	if (!skb)
37876465ddcfSJouni Malinen 		return -ENOMEM;
37886465ddcfSJouni Malinen 
37896465ddcfSJouni Malinen 	ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
37906465ddcfSJouni Malinen 		   info_req_flags);
37916465ddcfSJouni Malinen 	p = (struct wmi_get_p2p_info *) skb->data;
37926465ddcfSJouni Malinen 	p->info_req_flags = cpu_to_le32(info_req_flags);
37930ce59445SVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
37946465ddcfSJouni Malinen 				   NO_SYNC_WMIFLAG);
37956465ddcfSJouni Malinen }
37966465ddcfSJouni Malinen 
3797334234b5SVasanthakumar Thiagarajan int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
37986465ddcfSJouni Malinen {
37996465ddcfSJouni Malinen 	ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
3800334234b5SVasanthakumar Thiagarajan 	return ath6kl_wmi_simple_cmd(wmi, if_idx,
3801334234b5SVasanthakumar Thiagarajan 				     WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
38026465ddcfSJouni Malinen }
38036465ddcfSJouni Malinen 
380403bdeb0dSVasanthakumar Thiagarajan int ath6kl_wmi_set_inact_period(struct wmi *wmi, u8 if_idx, int inact_timeout)
380503bdeb0dSVasanthakumar Thiagarajan {
380603bdeb0dSVasanthakumar Thiagarajan 	struct sk_buff *skb;
380703bdeb0dSVasanthakumar Thiagarajan 	struct wmi_set_inact_period_cmd *cmd;
380803bdeb0dSVasanthakumar Thiagarajan 
380903bdeb0dSVasanthakumar Thiagarajan 	skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
381003bdeb0dSVasanthakumar Thiagarajan 	if (!skb)
381103bdeb0dSVasanthakumar Thiagarajan 		return -ENOMEM;
381203bdeb0dSVasanthakumar Thiagarajan 
381303bdeb0dSVasanthakumar Thiagarajan 	cmd = (struct wmi_set_inact_period_cmd *) skb->data;
381403bdeb0dSVasanthakumar Thiagarajan 	cmd->inact_period = cpu_to_le32(inact_timeout);
381503bdeb0dSVasanthakumar Thiagarajan 	cmd->num_null_func = 0;
381603bdeb0dSVasanthakumar Thiagarajan 
381703bdeb0dSVasanthakumar Thiagarajan 	return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_CONN_INACT_CMDID,
381803bdeb0dSVasanthakumar Thiagarajan 				   NO_SYNC_WMIFLAG);
381903bdeb0dSVasanthakumar Thiagarajan }
382003bdeb0dSVasanthakumar Thiagarajan 
382192332993SVasanthakumar Thiagarajan static void ath6kl_wmi_hb_challenge_resp_event(struct wmi *wmi, u8 *datap,
382292332993SVasanthakumar Thiagarajan 					       int len)
382392332993SVasanthakumar Thiagarajan {
382492332993SVasanthakumar Thiagarajan 	struct wmix_hb_challenge_resp_cmd *cmd;
382592332993SVasanthakumar Thiagarajan 
382692332993SVasanthakumar Thiagarajan 	if (len < sizeof(struct wmix_hb_challenge_resp_cmd))
382792332993SVasanthakumar Thiagarajan 		return;
382892332993SVasanthakumar Thiagarajan 
382992332993SVasanthakumar Thiagarajan 	cmd = (struct wmix_hb_challenge_resp_cmd *) datap;
383092332993SVasanthakumar Thiagarajan 	ath6kl_recovery_hb_event(wmi->parent_dev,
383192332993SVasanthakumar Thiagarajan 				 le32_to_cpu(cmd->cookie));
383292332993SVasanthakumar Thiagarajan }
383392332993SVasanthakumar Thiagarajan 
3834bdcd8170SKalle Valo static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
3835bdcd8170SKalle Valo {
3836bdcd8170SKalle Valo 	struct wmix_cmd_hdr *cmd;
3837bdcd8170SKalle Valo 	u32 len;
3838bdcd8170SKalle Valo 	u16 id;
3839bdcd8170SKalle Valo 	u8 *datap;
3840bdcd8170SKalle Valo 	int ret = 0;
3841bdcd8170SKalle Valo 
3842bdcd8170SKalle Valo 	if (skb->len < sizeof(struct wmix_cmd_hdr)) {
3843bdcd8170SKalle Valo 		ath6kl_err("bad packet 1\n");
3844bdcd8170SKalle Valo 		return -EINVAL;
3845bdcd8170SKalle Valo 	}
3846bdcd8170SKalle Valo 
3847bdcd8170SKalle Valo 	cmd = (struct wmix_cmd_hdr *) skb->data;
3848bdcd8170SKalle Valo 	id = le32_to_cpu(cmd->cmd_id);
3849bdcd8170SKalle Valo 
3850bdcd8170SKalle Valo 	skb_pull(skb, sizeof(struct wmix_cmd_hdr));
3851bdcd8170SKalle Valo 
3852bdcd8170SKalle Valo 	datap = skb->data;
3853bdcd8170SKalle Valo 	len = skb->len;
3854bdcd8170SKalle Valo 
3855bdcd8170SKalle Valo 	switch (id) {
3856bdcd8170SKalle Valo 	case WMIX_HB_CHALLENGE_RESP_EVENTID:
3857b9b6ee60SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
385892332993SVasanthakumar Thiagarajan 		ath6kl_wmi_hb_challenge_resp_event(wmi, datap, len);
3859bdcd8170SKalle Valo 		break;
3860bdcd8170SKalle Valo 	case WMIX_DBGLOG_EVENTID:
3861b9b6ee60SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
3862bdf5396bSKalle Valo 		ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
3863bdcd8170SKalle Valo 		break;
3864bdcd8170SKalle Valo 	default:
3865b9b6ee60SKalle Valo 		ath6kl_warn("unknown cmd id 0x%x\n", id);
3866bdcd8170SKalle Valo 		ret = -EINVAL;
3867bdcd8170SKalle Valo 		break;
3868bdcd8170SKalle Valo 	}
3869bdcd8170SKalle Valo 
3870bdcd8170SKalle Valo 	return ret;
3871bdcd8170SKalle Valo }
3872bdcd8170SKalle Valo 
38734b28a80dSJouni Malinen static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
38744b28a80dSJouni Malinen {
38754b28a80dSJouni Malinen 	return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
38764b28a80dSJouni Malinen }
38774b28a80dSJouni Malinen 
38785dbc811fSVasanthakumar Thiagarajan /* Process interface specific wmi events, caller would free the datap */
38795dbc811fSVasanthakumar Thiagarajan static int ath6kl_wmi_proc_events_vif(struct wmi *wmi, u16 if_idx, u16 cmd_id,
38805dbc811fSVasanthakumar Thiagarajan 					u8 *datap, u32 len)
3881bdcd8170SKalle Valo {
3882240d2799SVasanthakumar Thiagarajan 	struct ath6kl_vif *vif;
3883bdcd8170SKalle Valo 
3884240d2799SVasanthakumar Thiagarajan 	vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
3885240d2799SVasanthakumar Thiagarajan 	if (!vif) {
3886240d2799SVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI,
3887240d2799SVasanthakumar Thiagarajan 			   "Wmi event for unavailable vif, vif_index:%d\n",
3888240d2799SVasanthakumar Thiagarajan 			    if_idx);
3889240d2799SVasanthakumar Thiagarajan 		return -EINVAL;
3890240d2799SVasanthakumar Thiagarajan 	}
3891240d2799SVasanthakumar Thiagarajan 
38925dbc811fSVasanthakumar Thiagarajan 	switch (cmd_id) {
38935dbc811fSVasanthakumar Thiagarajan 	case WMI_CONNECT_EVENTID:
38945dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
38955dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
38965dbc811fSVasanthakumar Thiagarajan 	case WMI_DISCONNECT_EVENTID:
38975dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
38985dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
38995dbc811fSVasanthakumar Thiagarajan 	case WMI_TKIP_MICERR_EVENTID:
39005dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
39015dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
39025dbc811fSVasanthakumar Thiagarajan 	case WMI_BSSINFO_EVENTID:
39035dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
39045dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
39055dbc811fSVasanthakumar Thiagarajan 	case WMI_NEIGHBOR_REPORT_EVENTID:
39065dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
39075dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
39085dbc811fSVasanthakumar Thiagarajan 							   vif);
39095dbc811fSVasanthakumar Thiagarajan 	case WMI_SCAN_COMPLETE_EVENTID:
39105dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
39115dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
39125dbc811fSVasanthakumar Thiagarajan 	case WMI_REPORT_STATISTICS_EVENTID:
39135dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
39145dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
39155dbc811fSVasanthakumar Thiagarajan 	case WMI_CAC_EVENTID:
39165dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
39175dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
39185dbc811fSVasanthakumar Thiagarajan 	case WMI_PSPOLL_EVENTID:
39195dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
39205dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
39215dbc811fSVasanthakumar Thiagarajan 	case WMI_DTIMEXPIRY_EVENTID:
39225dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
39235dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
39245dbc811fSVasanthakumar Thiagarajan 	case WMI_ADDBA_REQ_EVENTID:
39255dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
39265dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
39275dbc811fSVasanthakumar Thiagarajan 	case WMI_DELBA_REQ_EVENTID:
39285dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
39295dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
39305dbc811fSVasanthakumar Thiagarajan 	case WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID:
39315dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI,
39325dbc811fSVasanthakumar Thiagarajan 			   "WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID");
39335dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(wmi, vif);
39345dbc811fSVasanthakumar Thiagarajan 	case WMI_REMAIN_ON_CHNL_EVENTID:
39355dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
39365dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
39375dbc811fSVasanthakumar Thiagarajan 	case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
39385dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI,
39395dbc811fSVasanthakumar Thiagarajan 			   "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
39405dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
39415dbc811fSVasanthakumar Thiagarajan 								 len, vif);
39425dbc811fSVasanthakumar Thiagarajan 	case WMI_TX_STATUS_EVENTID:
39435dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
39445dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
39455dbc811fSVasanthakumar Thiagarajan 	case WMI_RX_PROBE_REQ_EVENTID:
39465dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
39475dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
39485dbc811fSVasanthakumar Thiagarajan 	case WMI_RX_ACTION_EVENTID:
39495dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
39505dbc811fSVasanthakumar Thiagarajan 		return ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
3951279b2862SThomas Pedersen 	case WMI_TXE_NOTIFY_EVENTID:
3952279b2862SThomas Pedersen 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TXE_NOTIFY_EVENTID\n");
3953279b2862SThomas Pedersen 		return ath6kl_wmi_txe_notify_event_rx(wmi, datap, len, vif);
39545dbc811fSVasanthakumar Thiagarajan 	default:
39555dbc811fSVasanthakumar Thiagarajan 		ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", cmd_id);
39565dbc811fSVasanthakumar Thiagarajan 		return -EINVAL;
39575dbc811fSVasanthakumar Thiagarajan 	}
39585dbc811fSVasanthakumar Thiagarajan 
39595dbc811fSVasanthakumar Thiagarajan 	return 0;
39605dbc811fSVasanthakumar Thiagarajan }
39615dbc811fSVasanthakumar Thiagarajan 
39625dbc811fSVasanthakumar Thiagarajan static int ath6kl_wmi_proc_events(struct wmi *wmi, struct sk_buff *skb)
39635dbc811fSVasanthakumar Thiagarajan {
39645dbc811fSVasanthakumar Thiagarajan 	struct wmi_cmd_hdr *cmd;
39655dbc811fSVasanthakumar Thiagarajan 	int ret = 0;
39665dbc811fSVasanthakumar Thiagarajan 	u32 len;
39675dbc811fSVasanthakumar Thiagarajan 	u16 id;
39685dbc811fSVasanthakumar Thiagarajan 	u8 if_idx;
39695dbc811fSVasanthakumar Thiagarajan 	u8 *datap;
39705dbc811fSVasanthakumar Thiagarajan 
39715dbc811fSVasanthakumar Thiagarajan 	cmd = (struct wmi_cmd_hdr *) skb->data;
39725dbc811fSVasanthakumar Thiagarajan 	id = le16_to_cpu(cmd->cmd_id);
39735dbc811fSVasanthakumar Thiagarajan 	if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
39745dbc811fSVasanthakumar Thiagarajan 
39755dbc811fSVasanthakumar Thiagarajan 	skb_pull(skb, sizeof(struct wmi_cmd_hdr));
39765dbc811fSVasanthakumar Thiagarajan 	datap = skb->data;
39775dbc811fSVasanthakumar Thiagarajan 	len = skb->len;
39785dbc811fSVasanthakumar Thiagarajan 
39795dbc811fSVasanthakumar Thiagarajan 	ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
39805dbc811fSVasanthakumar Thiagarajan 	ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
39815dbc811fSVasanthakumar Thiagarajan 			datap, len);
39825dbc811fSVasanthakumar Thiagarajan 
3983bdcd8170SKalle Valo 	switch (id) {
3984bdcd8170SKalle Valo 	case WMI_GET_BITRATE_CMDID:
3985bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
3986bdcd8170SKalle Valo 		ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
3987bdcd8170SKalle Valo 		break;
3988bdcd8170SKalle Valo 	case WMI_GET_CHANNEL_LIST_CMDID:
3989bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
3990bdcd8170SKalle Valo 		ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
3991bdcd8170SKalle Valo 		break;
3992bdcd8170SKalle Valo 	case WMI_GET_TX_PWR_CMDID:
3993bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
3994bdcd8170SKalle Valo 		ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
3995bdcd8170SKalle Valo 		break;
3996bdcd8170SKalle Valo 	case WMI_READY_EVENTID:
3997bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
3998bdcd8170SKalle Valo 		ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
3999bdcd8170SKalle Valo 		break;
4000bdcd8170SKalle Valo 	case WMI_PEER_NODE_EVENTID:
4001bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
4002bdcd8170SKalle Valo 		ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
4003bdcd8170SKalle Valo 		break;
4004bdcd8170SKalle Valo 	case WMI_REGDOMAIN_EVENTID:
4005bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
400606033760SVivek Natarajan 		ath6kl_wmi_regdomain_event(wmi, datap, len);
4007bdcd8170SKalle Valo 		break;
4008bdcd8170SKalle Valo 	case WMI_PSTREAM_TIMEOUT_EVENTID:
4009bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
4010bdcd8170SKalle Valo 		ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
4011bdcd8170SKalle Valo 		break;
4012bdcd8170SKalle Valo 	case WMI_CMDERROR_EVENTID:
4013bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
4014bdcd8170SKalle Valo 		ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
4015bdcd8170SKalle Valo 		break;
4016bdcd8170SKalle Valo 	case WMI_RSSI_THRESHOLD_EVENTID:
4017bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
4018bdcd8170SKalle Valo 		ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
4019bdcd8170SKalle Valo 		break;
4020bdcd8170SKalle Valo 	case WMI_ERROR_REPORT_EVENTID:
4021bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
4022bdcd8170SKalle Valo 		break;
4023bdcd8170SKalle Valo 	case WMI_OPT_RX_FRAME_EVENTID:
4024bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
4025f195d507SJouni Malinen 		/* this event has been deprecated */
4026bdcd8170SKalle Valo 		break;
4027bdcd8170SKalle Valo 	case WMI_REPORT_ROAM_TBL_EVENTID:
4028bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
40294b28a80dSJouni Malinen 		ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
4030bdcd8170SKalle Valo 		break;
4031bdcd8170SKalle Valo 	case WMI_EXTENSION_EVENTID:
4032bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
4033bdcd8170SKalle Valo 		ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
4034bdcd8170SKalle Valo 		break;
4035bdcd8170SKalle Valo 	case WMI_CHANNEL_CHANGE_EVENTID:
4036bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
4037bdcd8170SKalle Valo 		break;
4038bdcd8170SKalle Valo 	case WMI_REPORT_ROAM_DATA_EVENTID:
4039bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
4040bdcd8170SKalle Valo 		break;
4041003353b0SKalle Valo 	case WMI_TEST_EVENTID:
4042003353b0SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
40434f34daceSThomas Pedersen 		ret = ath6kl_wmi_test_rx(wmi, datap, len);
4044003353b0SKalle Valo 		break;
4045bdcd8170SKalle Valo 	case WMI_GET_FIXRATES_CMDID:
4046bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
4047bdcd8170SKalle Valo 		ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
4048bdcd8170SKalle Valo 		break;
4049bdcd8170SKalle Valo 	case WMI_TX_RETRY_ERR_EVENTID:
4050bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
4051bdcd8170SKalle Valo 		break;
4052bdcd8170SKalle Valo 	case WMI_SNR_THRESHOLD_EVENTID:
4053bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
4054bdcd8170SKalle Valo 		ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
4055bdcd8170SKalle Valo 		break;
4056bdcd8170SKalle Valo 	case WMI_LQ_THRESHOLD_EVENTID:
4057bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
4058bdcd8170SKalle Valo 		break;
4059bdcd8170SKalle Valo 	case WMI_APLIST_EVENTID:
4060bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
4061bdcd8170SKalle Valo 		ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
4062bdcd8170SKalle Valo 		break;
4063bdcd8170SKalle Valo 	case WMI_GET_KEEPALIVE_CMDID:
4064bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
4065bdcd8170SKalle Valo 		ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
4066bdcd8170SKalle Valo 		break;
4067bdcd8170SKalle Valo 	case WMI_GET_WOW_LIST_EVENTID:
4068bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
4069bdcd8170SKalle Valo 		break;
4070bdcd8170SKalle Valo 	case WMI_GET_PMKID_LIST_EVENTID:
4071bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
4072bdcd8170SKalle Valo 		ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
4073bdcd8170SKalle Valo 		break;
4074bdcd8170SKalle Valo 	case WMI_SET_PARAMS_REPLY_EVENTID:
4075bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
4076bdcd8170SKalle Valo 		break;
4077bdcd8170SKalle Valo 	case WMI_ADDBA_RESP_EVENTID:
4078bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
4079bdcd8170SKalle Valo 		break;
4080bdcd8170SKalle Valo 	case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
4081bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI,
4082bdcd8170SKalle Valo 			   "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
4083bdcd8170SKalle Valo 		break;
4084bdcd8170SKalle Valo 	case WMI_REPORT_BTCOEX_STATS_EVENTID:
4085bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI,
4086bdcd8170SKalle Valo 			   "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
4087bdcd8170SKalle Valo 		break;
4088bdcd8170SKalle Valo 	case WMI_TX_COMPLETE_EVENTID:
4089bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
4090bdcd8170SKalle Valo 		ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
4091bdcd8170SKalle Valo 		break;
40926465ddcfSJouni Malinen 	case WMI_P2P_CAPABILITIES_EVENTID:
40936465ddcfSJouni Malinen 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
40946465ddcfSJouni Malinen 		ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
40956465ddcfSJouni Malinen 		break;
40966465ddcfSJouni Malinen 	case WMI_P2P_INFO_EVENTID:
40976465ddcfSJouni Malinen 		ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
40986465ddcfSJouni Malinen 		ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
40996465ddcfSJouni Malinen 		break;
4100bdcd8170SKalle Valo 	default:
41015dbc811fSVasanthakumar Thiagarajan 		/* may be the event is interface specific */
41025dbc811fSVasanthakumar Thiagarajan 		ret = ath6kl_wmi_proc_events_vif(wmi, if_idx, id, datap, len);
4103bdcd8170SKalle Valo 		break;
4104bdcd8170SKalle Valo 	}
4105bdcd8170SKalle Valo 
4106bdcd8170SKalle Valo 	dev_kfree_skb(skb);
4107bdcd8170SKalle Valo 	return ret;
4108bdcd8170SKalle Valo }
4109bdcd8170SKalle Valo 
41105dbc811fSVasanthakumar Thiagarajan /* Control Path */
41115dbc811fSVasanthakumar Thiagarajan int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
41125dbc811fSVasanthakumar Thiagarajan {
41135dbc811fSVasanthakumar Thiagarajan 	if (WARN_ON(skb == NULL))
41145dbc811fSVasanthakumar Thiagarajan 		return -EINVAL;
41155dbc811fSVasanthakumar Thiagarajan 
41165dbc811fSVasanthakumar Thiagarajan 	if (skb->len < sizeof(struct wmi_cmd_hdr)) {
41175dbc811fSVasanthakumar Thiagarajan 		ath6kl_err("bad packet 1\n");
41185dbc811fSVasanthakumar Thiagarajan 		dev_kfree_skb(skb);
41195dbc811fSVasanthakumar Thiagarajan 		return -EINVAL;
41205dbc811fSVasanthakumar Thiagarajan 	}
41215dbc811fSVasanthakumar Thiagarajan 
4122416cf0b4SKalle Valo 	trace_ath6kl_wmi_event(skb->data, skb->len);
4123416cf0b4SKalle Valo 
41245dbc811fSVasanthakumar Thiagarajan 	return ath6kl_wmi_proc_events(wmi, skb);
41255dbc811fSVasanthakumar Thiagarajan }
41265dbc811fSVasanthakumar Thiagarajan 
4127c89c591dSKalle Valo void ath6kl_wmi_reset(struct wmi *wmi)
4128bdcd8170SKalle Valo {
4129bdcd8170SKalle Valo 	spin_lock_bh(&wmi->lock);
4130bdcd8170SKalle Valo 
4131bdcd8170SKalle Valo 	wmi->fat_pipe_exist = 0;
4132bdcd8170SKalle Valo 	memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
4133bdcd8170SKalle Valo 
4134bdcd8170SKalle Valo 	spin_unlock_bh(&wmi->lock);
4135bdcd8170SKalle Valo }
4136bdcd8170SKalle Valo 
41372865785eSVasanthakumar Thiagarajan void *ath6kl_wmi_init(struct ath6kl *dev)
4138bdcd8170SKalle Valo {
4139bdcd8170SKalle Valo 	struct wmi *wmi;
4140bdcd8170SKalle Valo 
4141bdcd8170SKalle Valo 	wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
4142bdcd8170SKalle Valo 	if (!wmi)
4143bdcd8170SKalle Valo 		return NULL;
4144bdcd8170SKalle Valo 
4145bdcd8170SKalle Valo 	spin_lock_init(&wmi->lock);
4146bdcd8170SKalle Valo 
4147bdcd8170SKalle Valo 	wmi->parent_dev = dev;
4148bdcd8170SKalle Valo 
4149bdcd8170SKalle Valo 	wmi->pwr_mode = REC_POWER;
4150bdcd8170SKalle Valo 
4151c89c591dSKalle Valo 	ath6kl_wmi_reset(wmi);
4152bdcd8170SKalle Valo 
4153bdcd8170SKalle Valo 	return wmi;
4154bdcd8170SKalle Valo }
4155bdcd8170SKalle Valo 
4156bdcd8170SKalle Valo void ath6kl_wmi_shutdown(struct wmi *wmi)
4157bdcd8170SKalle Valo {
4158bdcd8170SKalle Valo 	if (!wmi)
4159bdcd8170SKalle Valo 		return;
4160bdcd8170SKalle Valo 
4161a0df5db1SJouni Malinen 	kfree(wmi->last_mgmt_tx_frame);
4162bdcd8170SKalle Valo 	kfree(wmi);
4163bdcd8170SKalle Valo }
4164