xref: /linux/drivers/net/wireless/ath/ath10k/wmi-tlv.c (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
1 /*
2  * Copyright (c) 2005-2011 Atheros Communications Inc.
3  * Copyright (c) 2011-2014 Qualcomm Atheros, Inc.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 #include "core.h"
18 #include "debug.h"
19 #include "mac.h"
20 #include "hw.h"
21 #include "mac.h"
22 #include "wmi.h"
23 #include "wmi-ops.h"
24 #include "wmi-tlv.h"
25 #include "p2p.h"
26 
27 /***************/
28 /* TLV helpers */
29 /**************/
30 
31 struct wmi_tlv_policy {
32 	size_t min_len;
33 };
34 
35 static const struct wmi_tlv_policy wmi_tlv_policies[] = {
36 	[WMI_TLV_TAG_ARRAY_BYTE]
37 		= { .min_len = 0 },
38 	[WMI_TLV_TAG_ARRAY_UINT32]
39 		= { .min_len = 0 },
40 	[WMI_TLV_TAG_STRUCT_SCAN_EVENT]
41 		= { .min_len = sizeof(struct wmi_scan_event) },
42 	[WMI_TLV_TAG_STRUCT_MGMT_RX_HDR]
43 		= { .min_len = sizeof(struct wmi_tlv_mgmt_rx_ev) },
44 	[WMI_TLV_TAG_STRUCT_CHAN_INFO_EVENT]
45 		= { .min_len = sizeof(struct wmi_chan_info_event) },
46 	[WMI_TLV_TAG_STRUCT_VDEV_START_RESPONSE_EVENT]
47 		= { .min_len = sizeof(struct wmi_vdev_start_response_event) },
48 	[WMI_TLV_TAG_STRUCT_PEER_STA_KICKOUT_EVENT]
49 		= { .min_len = sizeof(struct wmi_peer_sta_kickout_event) },
50 	[WMI_TLV_TAG_STRUCT_HOST_SWBA_EVENT]
51 		= { .min_len = sizeof(struct wmi_host_swba_event) },
52 	[WMI_TLV_TAG_STRUCT_TIM_INFO]
53 		= { .min_len = sizeof(struct wmi_tim_info) },
54 	[WMI_TLV_TAG_STRUCT_P2P_NOA_INFO]
55 		= { .min_len = sizeof(struct wmi_p2p_noa_info) },
56 	[WMI_TLV_TAG_STRUCT_SERVICE_READY_EVENT]
57 		= { .min_len = sizeof(struct wmi_tlv_svc_rdy_ev) },
58 	[WMI_TLV_TAG_STRUCT_HAL_REG_CAPABILITIES]
59 		= { .min_len = sizeof(struct hal_reg_capabilities) },
60 	[WMI_TLV_TAG_STRUCT_WLAN_HOST_MEM_REQ]
61 		= { .min_len = sizeof(struct wlan_host_mem_req) },
62 	[WMI_TLV_TAG_STRUCT_READY_EVENT]
63 		= { .min_len = sizeof(struct wmi_tlv_rdy_ev) },
64 	[WMI_TLV_TAG_STRUCT_OFFLOAD_BCN_TX_STATUS_EVENT]
65 		= { .min_len = sizeof(struct wmi_tlv_bcn_tx_status_ev) },
66 	[WMI_TLV_TAG_STRUCT_DIAG_DATA_CONTAINER_EVENT]
67 		= { .min_len = sizeof(struct wmi_tlv_diag_data_ev) },
68 	[WMI_TLV_TAG_STRUCT_P2P_NOA_EVENT]
69 		= { .min_len = sizeof(struct wmi_tlv_p2p_noa_ev) },
70 	[WMI_TLV_TAG_STRUCT_ROAM_EVENT]
71 		= { .min_len = sizeof(struct wmi_tlv_roam_ev) },
72 	[WMI_TLV_TAG_STRUCT_WOW_EVENT_INFO]
73 		= { .min_len = sizeof(struct wmi_tlv_wow_event_info) },
74 	[WMI_TLV_TAG_STRUCT_TX_PAUSE_EVENT]
75 		= { .min_len = sizeof(struct wmi_tlv_tx_pause_ev) },
76 };
77 
78 static int
79 ath10k_wmi_tlv_iter(struct ath10k *ar, const void *ptr, size_t len,
80 		    int (*iter)(struct ath10k *ar, u16 tag, u16 len,
81 				const void *ptr, void *data),
82 		    void *data)
83 {
84 	const void *begin = ptr;
85 	const struct wmi_tlv *tlv;
86 	u16 tlv_tag, tlv_len;
87 	int ret;
88 
89 	while (len > 0) {
90 		if (len < sizeof(*tlv)) {
91 			ath10k_dbg(ar, ATH10K_DBG_WMI,
92 				   "wmi tlv parse failure at byte %zd (%zu bytes left, %zu expected)\n",
93 				   ptr - begin, len, sizeof(*tlv));
94 			return -EINVAL;
95 		}
96 
97 		tlv = ptr;
98 		tlv_tag = __le16_to_cpu(tlv->tag);
99 		tlv_len = __le16_to_cpu(tlv->len);
100 		ptr += sizeof(*tlv);
101 		len -= sizeof(*tlv);
102 
103 		if (tlv_len > len) {
104 			ath10k_dbg(ar, ATH10K_DBG_WMI,
105 				   "wmi tlv parse failure of tag %hhu at byte %zd (%zu bytes left, %hhu expected)\n",
106 				   tlv_tag, ptr - begin, len, tlv_len);
107 			return -EINVAL;
108 		}
109 
110 		if (tlv_tag < ARRAY_SIZE(wmi_tlv_policies) &&
111 		    wmi_tlv_policies[tlv_tag].min_len &&
112 		    wmi_tlv_policies[tlv_tag].min_len > tlv_len) {
113 			ath10k_dbg(ar, ATH10K_DBG_WMI,
114 				   "wmi tlv parse failure of tag %hhu at byte %zd (%hhu bytes is less than min length %zu)\n",
115 				   tlv_tag, ptr - begin, tlv_len,
116 				   wmi_tlv_policies[tlv_tag].min_len);
117 			return -EINVAL;
118 		}
119 
120 		ret = iter(ar, tlv_tag, tlv_len, ptr, data);
121 		if (ret)
122 			return ret;
123 
124 		ptr += tlv_len;
125 		len -= tlv_len;
126 	}
127 
128 	return 0;
129 }
130 
131 static int ath10k_wmi_tlv_iter_parse(struct ath10k *ar, u16 tag, u16 len,
132 				     const void *ptr, void *data)
133 {
134 	const void **tb = data;
135 
136 	if (tag < WMI_TLV_TAG_MAX)
137 		tb[tag] = ptr;
138 
139 	return 0;
140 }
141 
142 static int ath10k_wmi_tlv_parse(struct ath10k *ar, const void **tb,
143 				const void *ptr, size_t len)
144 {
145 	return ath10k_wmi_tlv_iter(ar, ptr, len, ath10k_wmi_tlv_iter_parse,
146 				   (void *)tb);
147 }
148 
149 static const void **
150 ath10k_wmi_tlv_parse_alloc(struct ath10k *ar, const void *ptr,
151 			   size_t len, gfp_t gfp)
152 {
153 	const void **tb;
154 	int ret;
155 
156 	tb = kzalloc(sizeof(*tb) * WMI_TLV_TAG_MAX, gfp);
157 	if (!tb)
158 		return ERR_PTR(-ENOMEM);
159 
160 	ret = ath10k_wmi_tlv_parse(ar, tb, ptr, len);
161 	if (ret) {
162 		kfree(tb);
163 		return ERR_PTR(ret);
164 	}
165 
166 	return tb;
167 }
168 
169 static u16 ath10k_wmi_tlv_len(const void *ptr)
170 {
171 	return __le16_to_cpu((((const struct wmi_tlv *)ptr) - 1)->len);
172 }
173 
174 /**************/
175 /* TLV events */
176 /**************/
177 static int ath10k_wmi_tlv_event_bcn_tx_status(struct ath10k *ar,
178 					      struct sk_buff *skb)
179 {
180 	const void **tb;
181 	const struct wmi_tlv_bcn_tx_status_ev *ev;
182 	struct ath10k_vif *arvif;
183 	u32 vdev_id, tx_status;
184 	int ret;
185 
186 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
187 	if (IS_ERR(tb)) {
188 		ret = PTR_ERR(tb);
189 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
190 		return ret;
191 	}
192 
193 	ev = tb[WMI_TLV_TAG_STRUCT_OFFLOAD_BCN_TX_STATUS_EVENT];
194 	if (!ev) {
195 		kfree(tb);
196 		return -EPROTO;
197 	}
198 
199 	tx_status = __le32_to_cpu(ev->tx_status);
200 	vdev_id = __le32_to_cpu(ev->vdev_id);
201 
202 	switch (tx_status) {
203 	case WMI_TLV_BCN_TX_STATUS_OK:
204 		break;
205 	case WMI_TLV_BCN_TX_STATUS_XRETRY:
206 	case WMI_TLV_BCN_TX_STATUS_DROP:
207 	case WMI_TLV_BCN_TX_STATUS_FILTERED:
208 		/* FIXME: It's probably worth telling mac80211 to stop the
209 		 * interface as it is crippled.
210 		 */
211 		ath10k_warn(ar, "received bcn tmpl tx status on vdev %i: %d",
212 			    vdev_id, tx_status);
213 		break;
214 	}
215 
216 	arvif = ath10k_get_arvif(ar, vdev_id);
217 	if (arvif && arvif->is_up && arvif->vif->csa_active)
218 		ieee80211_queue_work(ar->hw, &arvif->ap_csa_work);
219 
220 	kfree(tb);
221 	return 0;
222 }
223 
224 static int ath10k_wmi_tlv_event_diag_data(struct ath10k *ar,
225 					  struct sk_buff *skb)
226 {
227 	const void **tb;
228 	const struct wmi_tlv_diag_data_ev *ev;
229 	const struct wmi_tlv_diag_item *item;
230 	const void *data;
231 	int ret, num_items, len;
232 
233 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
234 	if (IS_ERR(tb)) {
235 		ret = PTR_ERR(tb);
236 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
237 		return ret;
238 	}
239 
240 	ev = tb[WMI_TLV_TAG_STRUCT_DIAG_DATA_CONTAINER_EVENT];
241 	data = tb[WMI_TLV_TAG_ARRAY_BYTE];
242 	if (!ev || !data) {
243 		kfree(tb);
244 		return -EPROTO;
245 	}
246 
247 	num_items = __le32_to_cpu(ev->num_items);
248 	len = ath10k_wmi_tlv_len(data);
249 
250 	while (num_items--) {
251 		if (len == 0)
252 			break;
253 		if (len < sizeof(*item)) {
254 			ath10k_warn(ar, "failed to parse diag data: can't fit item header\n");
255 			break;
256 		}
257 
258 		item = data;
259 
260 		if (len < sizeof(*item) + __le16_to_cpu(item->len)) {
261 			ath10k_warn(ar, "failed to parse diag data: item is too long\n");
262 			break;
263 		}
264 
265 		trace_ath10k_wmi_diag_container(ar,
266 						item->type,
267 						__le32_to_cpu(item->timestamp),
268 						__le32_to_cpu(item->code),
269 						__le16_to_cpu(item->len),
270 						item->payload);
271 
272 		len -= sizeof(*item);
273 		len -= roundup(__le16_to_cpu(item->len), 4);
274 
275 		data += sizeof(*item);
276 		data += roundup(__le16_to_cpu(item->len), 4);
277 	}
278 
279 	if (num_items != -1 || len != 0)
280 		ath10k_warn(ar, "failed to parse diag data event: num_items %d len %d\n",
281 			    num_items, len);
282 
283 	kfree(tb);
284 	return 0;
285 }
286 
287 static int ath10k_wmi_tlv_event_diag(struct ath10k *ar,
288 				     struct sk_buff *skb)
289 {
290 	const void **tb;
291 	const void *data;
292 	int ret, len;
293 
294 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
295 	if (IS_ERR(tb)) {
296 		ret = PTR_ERR(tb);
297 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
298 		return ret;
299 	}
300 
301 	data = tb[WMI_TLV_TAG_ARRAY_BYTE];
302 	if (!data) {
303 		kfree(tb);
304 		return -EPROTO;
305 	}
306 	len = ath10k_wmi_tlv_len(data);
307 
308 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv diag event len %d\n", len);
309 	trace_ath10k_wmi_diag(ar, data, len);
310 
311 	kfree(tb);
312 	return 0;
313 }
314 
315 static int ath10k_wmi_tlv_event_p2p_noa(struct ath10k *ar,
316 					struct sk_buff *skb)
317 {
318 	const void **tb;
319 	const struct wmi_tlv_p2p_noa_ev *ev;
320 	const struct wmi_p2p_noa_info *noa;
321 	int ret, vdev_id;
322 
323 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
324 	if (IS_ERR(tb)) {
325 		ret = PTR_ERR(tb);
326 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
327 		return ret;
328 	}
329 
330 	ev = tb[WMI_TLV_TAG_STRUCT_P2P_NOA_EVENT];
331 	noa = tb[WMI_TLV_TAG_STRUCT_P2P_NOA_INFO];
332 
333 	if (!ev || !noa) {
334 		kfree(tb);
335 		return -EPROTO;
336 	}
337 
338 	vdev_id = __le32_to_cpu(ev->vdev_id);
339 
340 	ath10k_dbg(ar, ATH10K_DBG_WMI,
341 		   "wmi tlv p2p noa vdev_id %i descriptors %hhu\n",
342 		   vdev_id, noa->num_descriptors);
343 
344 	ath10k_p2p_noa_update_by_vdev_id(ar, vdev_id, noa);
345 	kfree(tb);
346 	return 0;
347 }
348 
349 static int ath10k_wmi_tlv_event_tx_pause(struct ath10k *ar,
350 					 struct sk_buff *skb)
351 {
352 	const void **tb;
353 	const struct wmi_tlv_tx_pause_ev *ev;
354 	int ret, vdev_id;
355 	u32 pause_id, action, vdev_map, peer_id, tid_map;
356 
357 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
358 	if (IS_ERR(tb)) {
359 		ret = PTR_ERR(tb);
360 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
361 		return ret;
362 	}
363 
364 	ev = tb[WMI_TLV_TAG_STRUCT_TX_PAUSE_EVENT];
365 	if (!ev) {
366 		kfree(tb);
367 		return -EPROTO;
368 	}
369 
370 	pause_id = __le32_to_cpu(ev->pause_id);
371 	action = __le32_to_cpu(ev->action);
372 	vdev_map = __le32_to_cpu(ev->vdev_map);
373 	peer_id = __le32_to_cpu(ev->peer_id);
374 	tid_map = __le32_to_cpu(ev->tid_map);
375 
376 	ath10k_dbg(ar, ATH10K_DBG_WMI,
377 		   "wmi tlv tx pause pause_id %u action %u vdev_map 0x%08x peer_id %u tid_map 0x%08x\n",
378 		   pause_id, action, vdev_map, peer_id, tid_map);
379 
380 	switch (pause_id) {
381 	case WMI_TLV_TX_PAUSE_ID_MCC:
382 	case WMI_TLV_TX_PAUSE_ID_P2P_CLI_NOA:
383 	case WMI_TLV_TX_PAUSE_ID_P2P_GO_PS:
384 	case WMI_TLV_TX_PAUSE_ID_AP_PS:
385 	case WMI_TLV_TX_PAUSE_ID_IBSS_PS:
386 		for (vdev_id = 0; vdev_map; vdev_id++) {
387 			if (!(vdev_map & BIT(vdev_id)))
388 				continue;
389 
390 			vdev_map &= ~BIT(vdev_id);
391 			ath10k_mac_handle_tx_pause_vdev(ar, vdev_id, pause_id,
392 							action);
393 		}
394 		break;
395 	case WMI_TLV_TX_PAUSE_ID_AP_PEER_PS:
396 	case WMI_TLV_TX_PAUSE_ID_AP_PEER_UAPSD:
397 	case WMI_TLV_TX_PAUSE_ID_STA_ADD_BA:
398 	case WMI_TLV_TX_PAUSE_ID_HOST:
399 		ath10k_dbg(ar, ATH10K_DBG_MAC,
400 			   "mac ignoring unsupported tx pause id %d\n",
401 			   pause_id);
402 		break;
403 	default:
404 		ath10k_dbg(ar, ATH10K_DBG_MAC,
405 			   "mac ignoring unknown tx pause vdev %d\n",
406 			   pause_id);
407 		break;
408 	}
409 
410 	kfree(tb);
411 	return 0;
412 }
413 
414 /***********/
415 /* TLV ops */
416 /***********/
417 
418 static void ath10k_wmi_tlv_op_rx(struct ath10k *ar, struct sk_buff *skb)
419 {
420 	struct wmi_cmd_hdr *cmd_hdr;
421 	enum wmi_tlv_event_id id;
422 
423 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
424 	id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
425 
426 	if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
427 		goto out;
428 
429 	trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
430 
431 	switch (id) {
432 	case WMI_TLV_MGMT_RX_EVENTID:
433 		ath10k_wmi_event_mgmt_rx(ar, skb);
434 		/* mgmt_rx() owns the skb now! */
435 		return;
436 	case WMI_TLV_SCAN_EVENTID:
437 		ath10k_wmi_event_scan(ar, skb);
438 		break;
439 	case WMI_TLV_CHAN_INFO_EVENTID:
440 		ath10k_wmi_event_chan_info(ar, skb);
441 		break;
442 	case WMI_TLV_ECHO_EVENTID:
443 		ath10k_wmi_event_echo(ar, skb);
444 		break;
445 	case WMI_TLV_DEBUG_MESG_EVENTID:
446 		ath10k_wmi_event_debug_mesg(ar, skb);
447 		break;
448 	case WMI_TLV_UPDATE_STATS_EVENTID:
449 		ath10k_wmi_event_update_stats(ar, skb);
450 		break;
451 	case WMI_TLV_VDEV_START_RESP_EVENTID:
452 		ath10k_wmi_event_vdev_start_resp(ar, skb);
453 		break;
454 	case WMI_TLV_VDEV_STOPPED_EVENTID:
455 		ath10k_wmi_event_vdev_stopped(ar, skb);
456 		break;
457 	case WMI_TLV_PEER_STA_KICKOUT_EVENTID:
458 		ath10k_wmi_event_peer_sta_kickout(ar, skb);
459 		break;
460 	case WMI_TLV_HOST_SWBA_EVENTID:
461 		ath10k_wmi_event_host_swba(ar, skb);
462 		break;
463 	case WMI_TLV_TBTTOFFSET_UPDATE_EVENTID:
464 		ath10k_wmi_event_tbttoffset_update(ar, skb);
465 		break;
466 	case WMI_TLV_PHYERR_EVENTID:
467 		ath10k_wmi_event_phyerr(ar, skb);
468 		break;
469 	case WMI_TLV_ROAM_EVENTID:
470 		ath10k_wmi_event_roam(ar, skb);
471 		break;
472 	case WMI_TLV_PROFILE_MATCH:
473 		ath10k_wmi_event_profile_match(ar, skb);
474 		break;
475 	case WMI_TLV_DEBUG_PRINT_EVENTID:
476 		ath10k_wmi_event_debug_print(ar, skb);
477 		break;
478 	case WMI_TLV_PDEV_QVIT_EVENTID:
479 		ath10k_wmi_event_pdev_qvit(ar, skb);
480 		break;
481 	case WMI_TLV_WLAN_PROFILE_DATA_EVENTID:
482 		ath10k_wmi_event_wlan_profile_data(ar, skb);
483 		break;
484 	case WMI_TLV_RTT_MEASUREMENT_REPORT_EVENTID:
485 		ath10k_wmi_event_rtt_measurement_report(ar, skb);
486 		break;
487 	case WMI_TLV_TSF_MEASUREMENT_REPORT_EVENTID:
488 		ath10k_wmi_event_tsf_measurement_report(ar, skb);
489 		break;
490 	case WMI_TLV_RTT_ERROR_REPORT_EVENTID:
491 		ath10k_wmi_event_rtt_error_report(ar, skb);
492 		break;
493 	case WMI_TLV_WOW_WAKEUP_HOST_EVENTID:
494 		ath10k_wmi_event_wow_wakeup_host(ar, skb);
495 		break;
496 	case WMI_TLV_DCS_INTERFERENCE_EVENTID:
497 		ath10k_wmi_event_dcs_interference(ar, skb);
498 		break;
499 	case WMI_TLV_PDEV_TPC_CONFIG_EVENTID:
500 		ath10k_wmi_event_pdev_tpc_config(ar, skb);
501 		break;
502 	case WMI_TLV_PDEV_FTM_INTG_EVENTID:
503 		ath10k_wmi_event_pdev_ftm_intg(ar, skb);
504 		break;
505 	case WMI_TLV_GTK_OFFLOAD_STATUS_EVENTID:
506 		ath10k_wmi_event_gtk_offload_status(ar, skb);
507 		break;
508 	case WMI_TLV_GTK_REKEY_FAIL_EVENTID:
509 		ath10k_wmi_event_gtk_rekey_fail(ar, skb);
510 		break;
511 	case WMI_TLV_TX_DELBA_COMPLETE_EVENTID:
512 		ath10k_wmi_event_delba_complete(ar, skb);
513 		break;
514 	case WMI_TLV_TX_ADDBA_COMPLETE_EVENTID:
515 		ath10k_wmi_event_addba_complete(ar, skb);
516 		break;
517 	case WMI_TLV_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
518 		ath10k_wmi_event_vdev_install_key_complete(ar, skb);
519 		break;
520 	case WMI_TLV_SERVICE_READY_EVENTID:
521 		ath10k_wmi_event_service_ready(ar, skb);
522 		return;
523 	case WMI_TLV_READY_EVENTID:
524 		ath10k_wmi_event_ready(ar, skb);
525 		break;
526 	case WMI_TLV_OFFLOAD_BCN_TX_STATUS_EVENTID:
527 		ath10k_wmi_tlv_event_bcn_tx_status(ar, skb);
528 		break;
529 	case WMI_TLV_DIAG_DATA_CONTAINER_EVENTID:
530 		ath10k_wmi_tlv_event_diag_data(ar, skb);
531 		break;
532 	case WMI_TLV_DIAG_EVENTID:
533 		ath10k_wmi_tlv_event_diag(ar, skb);
534 		break;
535 	case WMI_TLV_P2P_NOA_EVENTID:
536 		ath10k_wmi_tlv_event_p2p_noa(ar, skb);
537 		break;
538 	case WMI_TLV_TX_PAUSE_EVENTID:
539 		ath10k_wmi_tlv_event_tx_pause(ar, skb);
540 		break;
541 	default:
542 		ath10k_warn(ar, "Unknown eventid: %d\n", id);
543 		break;
544 	}
545 
546 out:
547 	dev_kfree_skb(skb);
548 }
549 
550 static int ath10k_wmi_tlv_op_pull_scan_ev(struct ath10k *ar,
551 					  struct sk_buff *skb,
552 					  struct wmi_scan_ev_arg *arg)
553 {
554 	const void **tb;
555 	const struct wmi_scan_event *ev;
556 	int ret;
557 
558 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
559 	if (IS_ERR(tb)) {
560 		ret = PTR_ERR(tb);
561 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
562 		return ret;
563 	}
564 
565 	ev = tb[WMI_TLV_TAG_STRUCT_SCAN_EVENT];
566 	if (!ev) {
567 		kfree(tb);
568 		return -EPROTO;
569 	}
570 
571 	arg->event_type = ev->event_type;
572 	arg->reason = ev->reason;
573 	arg->channel_freq = ev->channel_freq;
574 	arg->scan_req_id = ev->scan_req_id;
575 	arg->scan_id = ev->scan_id;
576 	arg->vdev_id = ev->vdev_id;
577 
578 	kfree(tb);
579 	return 0;
580 }
581 
582 static int ath10k_wmi_tlv_op_pull_mgmt_rx_ev(struct ath10k *ar,
583 					     struct sk_buff *skb,
584 					     struct wmi_mgmt_rx_ev_arg *arg)
585 {
586 	const void **tb;
587 	const struct wmi_tlv_mgmt_rx_ev *ev;
588 	const u8 *frame;
589 	u32 msdu_len;
590 	int ret;
591 
592 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
593 	if (IS_ERR(tb)) {
594 		ret = PTR_ERR(tb);
595 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
596 		return ret;
597 	}
598 
599 	ev = tb[WMI_TLV_TAG_STRUCT_MGMT_RX_HDR];
600 	frame = tb[WMI_TLV_TAG_ARRAY_BYTE];
601 
602 	if (!ev || !frame) {
603 		kfree(tb);
604 		return -EPROTO;
605 	}
606 
607 	arg->channel = ev->channel;
608 	arg->buf_len = ev->buf_len;
609 	arg->status = ev->status;
610 	arg->snr = ev->snr;
611 	arg->phy_mode = ev->phy_mode;
612 	arg->rate = ev->rate;
613 
614 	msdu_len = __le32_to_cpu(arg->buf_len);
615 
616 	if (skb->len < (frame - skb->data) + msdu_len) {
617 		kfree(tb);
618 		return -EPROTO;
619 	}
620 
621 	/* shift the sk_buff to point to `frame` */
622 	skb_trim(skb, 0);
623 	skb_put(skb, frame - skb->data);
624 	skb_pull(skb, frame - skb->data);
625 	skb_put(skb, msdu_len);
626 
627 	kfree(tb);
628 	return 0;
629 }
630 
631 static int ath10k_wmi_tlv_op_pull_ch_info_ev(struct ath10k *ar,
632 					     struct sk_buff *skb,
633 					     struct wmi_ch_info_ev_arg *arg)
634 {
635 	const void **tb;
636 	const struct wmi_chan_info_event *ev;
637 	int ret;
638 
639 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
640 	if (IS_ERR(tb)) {
641 		ret = PTR_ERR(tb);
642 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
643 		return ret;
644 	}
645 
646 	ev = tb[WMI_TLV_TAG_STRUCT_CHAN_INFO_EVENT];
647 	if (!ev) {
648 		kfree(tb);
649 		return -EPROTO;
650 	}
651 
652 	arg->err_code = ev->err_code;
653 	arg->freq = ev->freq;
654 	arg->cmd_flags = ev->cmd_flags;
655 	arg->noise_floor = ev->noise_floor;
656 	arg->rx_clear_count = ev->rx_clear_count;
657 	arg->cycle_count = ev->cycle_count;
658 
659 	kfree(tb);
660 	return 0;
661 }
662 
663 static int
664 ath10k_wmi_tlv_op_pull_vdev_start_ev(struct ath10k *ar, struct sk_buff *skb,
665 				     struct wmi_vdev_start_ev_arg *arg)
666 {
667 	const void **tb;
668 	const struct wmi_vdev_start_response_event *ev;
669 	int ret;
670 
671 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
672 	if (IS_ERR(tb)) {
673 		ret = PTR_ERR(tb);
674 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
675 		return ret;
676 	}
677 
678 	ev = tb[WMI_TLV_TAG_STRUCT_VDEV_START_RESPONSE_EVENT];
679 	if (!ev) {
680 		kfree(tb);
681 		return -EPROTO;
682 	}
683 
684 	skb_pull(skb, sizeof(*ev));
685 	arg->vdev_id = ev->vdev_id;
686 	arg->req_id = ev->req_id;
687 	arg->resp_type = ev->resp_type;
688 	arg->status = ev->status;
689 
690 	kfree(tb);
691 	return 0;
692 }
693 
694 static int ath10k_wmi_tlv_op_pull_peer_kick_ev(struct ath10k *ar,
695 					       struct sk_buff *skb,
696 					       struct wmi_peer_kick_ev_arg *arg)
697 {
698 	const void **tb;
699 	const struct wmi_peer_sta_kickout_event *ev;
700 	int ret;
701 
702 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
703 	if (IS_ERR(tb)) {
704 		ret = PTR_ERR(tb);
705 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
706 		return ret;
707 	}
708 
709 	ev = tb[WMI_TLV_TAG_STRUCT_PEER_STA_KICKOUT_EVENT];
710 	if (!ev) {
711 		kfree(tb);
712 		return -EPROTO;
713 	}
714 
715 	arg->mac_addr = ev->peer_macaddr.addr;
716 
717 	kfree(tb);
718 	return 0;
719 }
720 
721 struct wmi_tlv_swba_parse {
722 	const struct wmi_host_swba_event *ev;
723 	bool tim_done;
724 	bool noa_done;
725 	size_t n_tim;
726 	size_t n_noa;
727 	struct wmi_swba_ev_arg *arg;
728 };
729 
730 static int ath10k_wmi_tlv_swba_tim_parse(struct ath10k *ar, u16 tag, u16 len,
731 					 const void *ptr, void *data)
732 {
733 	struct wmi_tlv_swba_parse *swba = data;
734 	struct wmi_tim_info_arg *tim_info_arg;
735 	const struct wmi_tim_info *tim_info_ev = ptr;
736 
737 	if (tag != WMI_TLV_TAG_STRUCT_TIM_INFO)
738 		return -EPROTO;
739 
740 	if (swba->n_tim >= ARRAY_SIZE(swba->arg->tim_info))
741 		return -ENOBUFS;
742 
743 	if (__le32_to_cpu(tim_info_ev->tim_len) >
744 	     sizeof(tim_info_ev->tim_bitmap)) {
745 		ath10k_warn(ar, "refusing to parse invalid swba structure\n");
746 		return -EPROTO;
747 	}
748 
749 	tim_info_arg = &swba->arg->tim_info[swba->n_tim];
750 	tim_info_arg->tim_len = tim_info_ev->tim_len;
751 	tim_info_arg->tim_mcast = tim_info_ev->tim_mcast;
752 	tim_info_arg->tim_bitmap = tim_info_ev->tim_bitmap;
753 	tim_info_arg->tim_changed = tim_info_ev->tim_changed;
754 	tim_info_arg->tim_num_ps_pending = tim_info_ev->tim_num_ps_pending;
755 
756 	swba->n_tim++;
757 
758 	return 0;
759 }
760 
761 static int ath10k_wmi_tlv_swba_noa_parse(struct ath10k *ar, u16 tag, u16 len,
762 					 const void *ptr, void *data)
763 {
764 	struct wmi_tlv_swba_parse *swba = data;
765 
766 	if (tag != WMI_TLV_TAG_STRUCT_P2P_NOA_INFO)
767 		return -EPROTO;
768 
769 	if (swba->n_noa >= ARRAY_SIZE(swba->arg->noa_info))
770 		return -ENOBUFS;
771 
772 	swba->arg->noa_info[swba->n_noa++] = ptr;
773 	return 0;
774 }
775 
776 static int ath10k_wmi_tlv_swba_parse(struct ath10k *ar, u16 tag, u16 len,
777 				     const void *ptr, void *data)
778 {
779 	struct wmi_tlv_swba_parse *swba = data;
780 	int ret;
781 
782 	switch (tag) {
783 	case WMI_TLV_TAG_STRUCT_HOST_SWBA_EVENT:
784 		swba->ev = ptr;
785 		break;
786 	case WMI_TLV_TAG_ARRAY_STRUCT:
787 		if (!swba->tim_done) {
788 			swba->tim_done = true;
789 			ret = ath10k_wmi_tlv_iter(ar, ptr, len,
790 						  ath10k_wmi_tlv_swba_tim_parse,
791 						  swba);
792 			if (ret)
793 				return ret;
794 		} else if (!swba->noa_done) {
795 			swba->noa_done = true;
796 			ret = ath10k_wmi_tlv_iter(ar, ptr, len,
797 						  ath10k_wmi_tlv_swba_noa_parse,
798 						  swba);
799 			if (ret)
800 				return ret;
801 		}
802 		break;
803 	default:
804 		break;
805 	}
806 	return 0;
807 }
808 
809 static int ath10k_wmi_tlv_op_pull_swba_ev(struct ath10k *ar,
810 					  struct sk_buff *skb,
811 					  struct wmi_swba_ev_arg *arg)
812 {
813 	struct wmi_tlv_swba_parse swba = { .arg = arg };
814 	u32 map;
815 	size_t n_vdevs;
816 	int ret;
817 
818 	ret = ath10k_wmi_tlv_iter(ar, skb->data, skb->len,
819 				  ath10k_wmi_tlv_swba_parse, &swba);
820 	if (ret) {
821 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
822 		return ret;
823 	}
824 
825 	if (!swba.ev)
826 		return -EPROTO;
827 
828 	arg->vdev_map = swba.ev->vdev_map;
829 
830 	for (map = __le32_to_cpu(arg->vdev_map), n_vdevs = 0; map; map >>= 1)
831 		if (map & BIT(0))
832 			n_vdevs++;
833 
834 	if (n_vdevs != swba.n_tim ||
835 	    n_vdevs != swba.n_noa)
836 		return -EPROTO;
837 
838 	return 0;
839 }
840 
841 static int ath10k_wmi_tlv_op_pull_phyerr_ev_hdr(struct ath10k *ar,
842 						struct sk_buff *skb,
843 						struct wmi_phyerr_hdr_arg *arg)
844 {
845 	const void **tb;
846 	const struct wmi_tlv_phyerr_ev *ev;
847 	const void *phyerrs;
848 	int ret;
849 
850 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
851 	if (IS_ERR(tb)) {
852 		ret = PTR_ERR(tb);
853 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
854 		return ret;
855 	}
856 
857 	ev = tb[WMI_TLV_TAG_STRUCT_COMB_PHYERR_RX_HDR];
858 	phyerrs = tb[WMI_TLV_TAG_ARRAY_BYTE];
859 
860 	if (!ev || !phyerrs) {
861 		kfree(tb);
862 		return -EPROTO;
863 	}
864 
865 	arg->num_phyerrs  = __le32_to_cpu(ev->num_phyerrs);
866 	arg->tsf_l32 = __le32_to_cpu(ev->tsf_l32);
867 	arg->tsf_u32 = __le32_to_cpu(ev->tsf_u32);
868 	arg->buf_len = __le32_to_cpu(ev->buf_len);
869 	arg->phyerrs = phyerrs;
870 
871 	kfree(tb);
872 	return 0;
873 }
874 
875 #define WMI_TLV_ABI_VER_NS0 0x5F414351
876 #define WMI_TLV_ABI_VER_NS1 0x00004C4D
877 #define WMI_TLV_ABI_VER_NS2 0x00000000
878 #define WMI_TLV_ABI_VER_NS3 0x00000000
879 
880 #define WMI_TLV_ABI_VER0_MAJOR 1
881 #define WMI_TLV_ABI_VER0_MINOR 0
882 #define WMI_TLV_ABI_VER0 ((((WMI_TLV_ABI_VER0_MAJOR) << 24) & 0xFF000000) | \
883 			  (((WMI_TLV_ABI_VER0_MINOR) <<  0) & 0x00FFFFFF))
884 #define WMI_TLV_ABI_VER1 53
885 
886 static int
887 ath10k_wmi_tlv_parse_mem_reqs(struct ath10k *ar, u16 tag, u16 len,
888 			      const void *ptr, void *data)
889 {
890 	struct wmi_svc_rdy_ev_arg *arg = data;
891 	int i;
892 
893 	if (tag != WMI_TLV_TAG_STRUCT_WLAN_HOST_MEM_REQ)
894 		return -EPROTO;
895 
896 	for (i = 0; i < ARRAY_SIZE(arg->mem_reqs); i++) {
897 		if (!arg->mem_reqs[i]) {
898 			arg->mem_reqs[i] = ptr;
899 			return 0;
900 		}
901 	}
902 
903 	return -ENOMEM;
904 }
905 
906 static int ath10k_wmi_tlv_op_pull_svc_rdy_ev(struct ath10k *ar,
907 					     struct sk_buff *skb,
908 					     struct wmi_svc_rdy_ev_arg *arg)
909 {
910 	const void **tb;
911 	const struct hal_reg_capabilities *reg;
912 	const struct wmi_tlv_svc_rdy_ev *ev;
913 	const __le32 *svc_bmap;
914 	const struct wlan_host_mem_req *mem_reqs;
915 	int ret;
916 
917 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
918 	if (IS_ERR(tb)) {
919 		ret = PTR_ERR(tb);
920 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
921 		return ret;
922 	}
923 
924 	ev = tb[WMI_TLV_TAG_STRUCT_SERVICE_READY_EVENT];
925 	reg = tb[WMI_TLV_TAG_STRUCT_HAL_REG_CAPABILITIES];
926 	svc_bmap = tb[WMI_TLV_TAG_ARRAY_UINT32];
927 	mem_reqs = tb[WMI_TLV_TAG_ARRAY_STRUCT];
928 
929 	if (!ev || !reg || !svc_bmap || !mem_reqs) {
930 		kfree(tb);
931 		return -EPROTO;
932 	}
933 
934 	/* This is an internal ABI compatibility check for WMI TLV so check it
935 	 * here instead of the generic WMI code.
936 	 */
937 	ath10k_dbg(ar, ATH10K_DBG_WMI,
938 		   "wmi tlv abi 0x%08x ?= 0x%08x, 0x%08x ?= 0x%08x, 0x%08x ?= 0x%08x, 0x%08x ?= 0x%08x, 0x%08x ?= 0x%08x\n",
939 		   __le32_to_cpu(ev->abi.abi_ver0), WMI_TLV_ABI_VER0,
940 		   __le32_to_cpu(ev->abi.abi_ver_ns0), WMI_TLV_ABI_VER_NS0,
941 		   __le32_to_cpu(ev->abi.abi_ver_ns1), WMI_TLV_ABI_VER_NS1,
942 		   __le32_to_cpu(ev->abi.abi_ver_ns2), WMI_TLV_ABI_VER_NS2,
943 		   __le32_to_cpu(ev->abi.abi_ver_ns3), WMI_TLV_ABI_VER_NS3);
944 
945 	if (__le32_to_cpu(ev->abi.abi_ver0) != WMI_TLV_ABI_VER0 ||
946 	    __le32_to_cpu(ev->abi.abi_ver_ns0) != WMI_TLV_ABI_VER_NS0 ||
947 	    __le32_to_cpu(ev->abi.abi_ver_ns1) != WMI_TLV_ABI_VER_NS1 ||
948 	    __le32_to_cpu(ev->abi.abi_ver_ns2) != WMI_TLV_ABI_VER_NS2 ||
949 	    __le32_to_cpu(ev->abi.abi_ver_ns3) != WMI_TLV_ABI_VER_NS3) {
950 		kfree(tb);
951 		return -ENOTSUPP;
952 	}
953 
954 	arg->min_tx_power = ev->hw_min_tx_power;
955 	arg->max_tx_power = ev->hw_max_tx_power;
956 	arg->ht_cap = ev->ht_cap_info;
957 	arg->vht_cap = ev->vht_cap_info;
958 	arg->sw_ver0 = ev->abi.abi_ver0;
959 	arg->sw_ver1 = ev->abi.abi_ver1;
960 	arg->fw_build = ev->fw_build_vers;
961 	arg->phy_capab = ev->phy_capability;
962 	arg->num_rf_chains = ev->num_rf_chains;
963 	arg->eeprom_rd = reg->eeprom_rd;
964 	arg->num_mem_reqs = ev->num_mem_reqs;
965 	arg->service_map = svc_bmap;
966 	arg->service_map_len = ath10k_wmi_tlv_len(svc_bmap);
967 
968 	ret = ath10k_wmi_tlv_iter(ar, mem_reqs, ath10k_wmi_tlv_len(mem_reqs),
969 				  ath10k_wmi_tlv_parse_mem_reqs, arg);
970 	if (ret) {
971 		kfree(tb);
972 		ath10k_warn(ar, "failed to parse mem_reqs tlv: %d\n", ret);
973 		return ret;
974 	}
975 
976 	kfree(tb);
977 	return 0;
978 }
979 
980 static int ath10k_wmi_tlv_op_pull_rdy_ev(struct ath10k *ar,
981 					 struct sk_buff *skb,
982 					 struct wmi_rdy_ev_arg *arg)
983 {
984 	const void **tb;
985 	const struct wmi_tlv_rdy_ev *ev;
986 	int ret;
987 
988 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
989 	if (IS_ERR(tb)) {
990 		ret = PTR_ERR(tb);
991 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
992 		return ret;
993 	}
994 
995 	ev = tb[WMI_TLV_TAG_STRUCT_READY_EVENT];
996 	if (!ev) {
997 		kfree(tb);
998 		return -EPROTO;
999 	}
1000 
1001 	arg->sw_version = ev->abi.abi_ver0;
1002 	arg->abi_version = ev->abi.abi_ver1;
1003 	arg->status = ev->status;
1004 	arg->mac_addr = ev->mac_addr.addr;
1005 
1006 	kfree(tb);
1007 	return 0;
1008 }
1009 
1010 static void ath10k_wmi_tlv_pull_vdev_stats(const struct wmi_tlv_vdev_stats *src,
1011 					   struct ath10k_fw_stats_vdev *dst)
1012 {
1013 	int i;
1014 
1015 	dst->vdev_id = __le32_to_cpu(src->vdev_id);
1016 	dst->beacon_snr = __le32_to_cpu(src->beacon_snr);
1017 	dst->data_snr = __le32_to_cpu(src->data_snr);
1018 	dst->num_rx_frames = __le32_to_cpu(src->num_rx_frames);
1019 	dst->num_rts_fail = __le32_to_cpu(src->num_rts_fail);
1020 	dst->num_rts_success = __le32_to_cpu(src->num_rts_success);
1021 	dst->num_rx_err = __le32_to_cpu(src->num_rx_err);
1022 	dst->num_rx_discard = __le32_to_cpu(src->num_rx_discard);
1023 	dst->num_tx_not_acked = __le32_to_cpu(src->num_tx_not_acked);
1024 
1025 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames); i++)
1026 		dst->num_tx_frames[i] =
1027 			__le32_to_cpu(src->num_tx_frames[i]);
1028 
1029 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_retries); i++)
1030 		dst->num_tx_frames_retries[i] =
1031 			__le32_to_cpu(src->num_tx_frames_retries[i]);
1032 
1033 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_failures); i++)
1034 		dst->num_tx_frames_failures[i] =
1035 			__le32_to_cpu(src->num_tx_frames_failures[i]);
1036 
1037 	for (i = 0; i < ARRAY_SIZE(src->tx_rate_history); i++)
1038 		dst->tx_rate_history[i] =
1039 			__le32_to_cpu(src->tx_rate_history[i]);
1040 
1041 	for (i = 0; i < ARRAY_SIZE(src->beacon_rssi_history); i++)
1042 		dst->beacon_rssi_history[i] =
1043 			__le32_to_cpu(src->beacon_rssi_history[i]);
1044 }
1045 
1046 static int ath10k_wmi_tlv_op_pull_fw_stats(struct ath10k *ar,
1047 					   struct sk_buff *skb,
1048 					   struct ath10k_fw_stats *stats)
1049 {
1050 	const void **tb;
1051 	const struct wmi_tlv_stats_ev *ev;
1052 	const void *data;
1053 	u32 num_pdev_stats;
1054 	u32 num_vdev_stats;
1055 	u32 num_peer_stats;
1056 	u32 num_bcnflt_stats;
1057 	u32 num_chan_stats;
1058 	size_t data_len;
1059 	int ret;
1060 	int i;
1061 
1062 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1063 	if (IS_ERR(tb)) {
1064 		ret = PTR_ERR(tb);
1065 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1066 		return ret;
1067 	}
1068 
1069 	ev = tb[WMI_TLV_TAG_STRUCT_STATS_EVENT];
1070 	data = tb[WMI_TLV_TAG_ARRAY_BYTE];
1071 
1072 	if (!ev || !data) {
1073 		kfree(tb);
1074 		return -EPROTO;
1075 	}
1076 
1077 	data_len = ath10k_wmi_tlv_len(data);
1078 	num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
1079 	num_vdev_stats = __le32_to_cpu(ev->num_vdev_stats);
1080 	num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
1081 	num_bcnflt_stats = __le32_to_cpu(ev->num_bcnflt_stats);
1082 	num_chan_stats = __le32_to_cpu(ev->num_chan_stats);
1083 
1084 	ath10k_dbg(ar, ATH10K_DBG_WMI,
1085 		   "wmi tlv stats update pdev %i vdev %i peer %i bcnflt %i chan %i\n",
1086 		   num_pdev_stats, num_vdev_stats, num_peer_stats,
1087 		   num_bcnflt_stats, num_chan_stats);
1088 
1089 	for (i = 0; i < num_pdev_stats; i++) {
1090 		const struct wmi_pdev_stats *src;
1091 		struct ath10k_fw_stats_pdev *dst;
1092 
1093 		src = data;
1094 		if (data_len < sizeof(*src))
1095 			return -EPROTO;
1096 
1097 		data += sizeof(*src);
1098 		data_len -= sizeof(*src);
1099 
1100 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
1101 		if (!dst)
1102 			continue;
1103 
1104 		ath10k_wmi_pull_pdev_stats_base(&src->base, dst);
1105 		ath10k_wmi_pull_pdev_stats_tx(&src->tx, dst);
1106 		ath10k_wmi_pull_pdev_stats_rx(&src->rx, dst);
1107 		list_add_tail(&dst->list, &stats->pdevs);
1108 	}
1109 
1110 	for (i = 0; i < num_vdev_stats; i++) {
1111 		const struct wmi_tlv_vdev_stats *src;
1112 		struct ath10k_fw_stats_vdev *dst;
1113 
1114 		src = data;
1115 		if (data_len < sizeof(*src))
1116 			return -EPROTO;
1117 
1118 		data += sizeof(*src);
1119 		data_len -= sizeof(*src);
1120 
1121 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
1122 		if (!dst)
1123 			continue;
1124 
1125 		ath10k_wmi_tlv_pull_vdev_stats(src, dst);
1126 		list_add_tail(&dst->list, &stats->vdevs);
1127 	}
1128 
1129 	for (i = 0; i < num_peer_stats; i++) {
1130 		const struct wmi_10x_peer_stats *src;
1131 		struct ath10k_fw_stats_peer *dst;
1132 
1133 		src = data;
1134 		if (data_len < sizeof(*src))
1135 			return -EPROTO;
1136 
1137 		data += sizeof(*src);
1138 		data_len -= sizeof(*src);
1139 
1140 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
1141 		if (!dst)
1142 			continue;
1143 
1144 		ath10k_wmi_pull_peer_stats(&src->old, dst);
1145 		dst->peer_rx_rate = __le32_to_cpu(src->peer_rx_rate);
1146 		list_add_tail(&dst->list, &stats->peers);
1147 	}
1148 
1149 	kfree(tb);
1150 	return 0;
1151 }
1152 
1153 static int ath10k_wmi_tlv_op_pull_roam_ev(struct ath10k *ar,
1154 					  struct sk_buff *skb,
1155 					  struct wmi_roam_ev_arg *arg)
1156 {
1157 	const void **tb;
1158 	const struct wmi_tlv_roam_ev *ev;
1159 	int ret;
1160 
1161 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1162 	if (IS_ERR(tb)) {
1163 		ret = PTR_ERR(tb);
1164 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1165 		return ret;
1166 	}
1167 
1168 	ev = tb[WMI_TLV_TAG_STRUCT_ROAM_EVENT];
1169 	if (!ev) {
1170 		kfree(tb);
1171 		return -EPROTO;
1172 	}
1173 
1174 	arg->vdev_id = ev->vdev_id;
1175 	arg->reason = ev->reason;
1176 	arg->rssi = ev->rssi;
1177 
1178 	kfree(tb);
1179 	return 0;
1180 }
1181 
1182 static int
1183 ath10k_wmi_tlv_op_pull_wow_ev(struct ath10k *ar, struct sk_buff *skb,
1184 			      struct wmi_wow_ev_arg *arg)
1185 {
1186 	const void **tb;
1187 	const struct wmi_tlv_wow_event_info *ev;
1188 	int ret;
1189 
1190 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1191 	if (IS_ERR(tb)) {
1192 		ret = PTR_ERR(tb);
1193 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1194 		return ret;
1195 	}
1196 
1197 	ev = tb[WMI_TLV_TAG_STRUCT_WOW_EVENT_INFO];
1198 	if (!ev) {
1199 		kfree(tb);
1200 		return -EPROTO;
1201 	}
1202 
1203 	arg->vdev_id = __le32_to_cpu(ev->vdev_id);
1204 	arg->flag = __le32_to_cpu(ev->flag);
1205 	arg->wake_reason = __le32_to_cpu(ev->wake_reason);
1206 	arg->data_len = __le32_to_cpu(ev->data_len);
1207 
1208 	kfree(tb);
1209 	return 0;
1210 }
1211 
1212 static struct sk_buff *
1213 ath10k_wmi_tlv_op_gen_pdev_suspend(struct ath10k *ar, u32 opt)
1214 {
1215 	struct wmi_tlv_pdev_suspend *cmd;
1216 	struct wmi_tlv *tlv;
1217 	struct sk_buff *skb;
1218 
1219 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1220 	if (!skb)
1221 		return ERR_PTR(-ENOMEM);
1222 
1223 	tlv = (void *)skb->data;
1224 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_SUSPEND_CMD);
1225 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1226 	cmd = (void *)tlv->value;
1227 	cmd->opt = __cpu_to_le32(opt);
1228 
1229 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev suspend\n");
1230 	return skb;
1231 }
1232 
1233 static struct sk_buff *
1234 ath10k_wmi_tlv_op_gen_pdev_resume(struct ath10k *ar)
1235 {
1236 	struct wmi_tlv_resume_cmd *cmd;
1237 	struct wmi_tlv *tlv;
1238 	struct sk_buff *skb;
1239 
1240 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1241 	if (!skb)
1242 		return ERR_PTR(-ENOMEM);
1243 
1244 	tlv = (void *)skb->data;
1245 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_RESUME_CMD);
1246 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1247 	cmd = (void *)tlv->value;
1248 	cmd->reserved = __cpu_to_le32(0);
1249 
1250 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev resume\n");
1251 	return skb;
1252 }
1253 
1254 static struct sk_buff *
1255 ath10k_wmi_tlv_op_gen_pdev_set_rd(struct ath10k *ar,
1256 				  u16 rd, u16 rd2g, u16 rd5g,
1257 				  u16 ctl2g, u16 ctl5g,
1258 				  enum wmi_dfs_region dfs_reg)
1259 {
1260 	struct wmi_tlv_pdev_set_rd_cmd *cmd;
1261 	struct wmi_tlv *tlv;
1262 	struct sk_buff *skb;
1263 
1264 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1265 	if (!skb)
1266 		return ERR_PTR(-ENOMEM);
1267 
1268 	tlv = (void *)skb->data;
1269 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_SET_REGDOMAIN_CMD);
1270 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1271 	cmd = (void *)tlv->value;
1272 	cmd->regd = __cpu_to_le32(rd);
1273 	cmd->regd_2ghz = __cpu_to_le32(rd2g);
1274 	cmd->regd_5ghz = __cpu_to_le32(rd5g);
1275 	cmd->conform_limit_2ghz = __cpu_to_le32(rd2g);
1276 	cmd->conform_limit_5ghz = __cpu_to_le32(rd5g);
1277 
1278 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev set rd\n");
1279 	return skb;
1280 }
1281 
1282 static enum wmi_txbf_conf ath10k_wmi_tlv_txbf_conf_scheme(struct ath10k *ar)
1283 {
1284 	return WMI_TXBF_CONF_AFTER_ASSOC;
1285 }
1286 
1287 static struct sk_buff *
1288 ath10k_wmi_tlv_op_gen_pdev_set_param(struct ath10k *ar, u32 param_id,
1289 				     u32 param_value)
1290 {
1291 	struct wmi_tlv_pdev_set_param_cmd *cmd;
1292 	struct wmi_tlv *tlv;
1293 	struct sk_buff *skb;
1294 
1295 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1296 	if (!skb)
1297 		return ERR_PTR(-ENOMEM);
1298 
1299 	tlv = (void *)skb->data;
1300 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_SET_PARAM_CMD);
1301 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1302 	cmd = (void *)tlv->value;
1303 	cmd->param_id = __cpu_to_le32(param_id);
1304 	cmd->param_value = __cpu_to_le32(param_value);
1305 
1306 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev set param\n");
1307 	return skb;
1308 }
1309 
1310 static struct sk_buff *ath10k_wmi_tlv_op_gen_init(struct ath10k *ar)
1311 {
1312 	struct sk_buff *skb;
1313 	struct wmi_tlv *tlv;
1314 	struct wmi_tlv_init_cmd *cmd;
1315 	struct wmi_tlv_resource_config *cfg;
1316 	struct wmi_host_mem_chunks *chunks;
1317 	size_t len, chunks_len;
1318 	void *ptr;
1319 
1320 	chunks_len = ar->wmi.num_mem_chunks * sizeof(struct host_memory_chunk);
1321 	len = (sizeof(*tlv) + sizeof(*cmd)) +
1322 	      (sizeof(*tlv) + sizeof(*cfg)) +
1323 	      (sizeof(*tlv) + chunks_len);
1324 
1325 	skb = ath10k_wmi_alloc_skb(ar, len);
1326 	if (!skb)
1327 		return ERR_PTR(-ENOMEM);
1328 
1329 	ptr = skb->data;
1330 
1331 	tlv = ptr;
1332 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_INIT_CMD);
1333 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1334 	cmd = (void *)tlv->value;
1335 	ptr += sizeof(*tlv);
1336 	ptr += sizeof(*cmd);
1337 
1338 	tlv = ptr;
1339 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_RESOURCE_CONFIG);
1340 	tlv->len = __cpu_to_le16(sizeof(*cfg));
1341 	cfg = (void *)tlv->value;
1342 	ptr += sizeof(*tlv);
1343 	ptr += sizeof(*cfg);
1344 
1345 	tlv = ptr;
1346 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
1347 	tlv->len = __cpu_to_le16(chunks_len);
1348 	chunks = (void *)tlv->value;
1349 
1350 	ptr += sizeof(*tlv);
1351 	ptr += chunks_len;
1352 
1353 	cmd->abi.abi_ver0 = __cpu_to_le32(WMI_TLV_ABI_VER0);
1354 	cmd->abi.abi_ver1 = __cpu_to_le32(WMI_TLV_ABI_VER1);
1355 	cmd->abi.abi_ver_ns0 = __cpu_to_le32(WMI_TLV_ABI_VER_NS0);
1356 	cmd->abi.abi_ver_ns1 = __cpu_to_le32(WMI_TLV_ABI_VER_NS1);
1357 	cmd->abi.abi_ver_ns2 = __cpu_to_le32(WMI_TLV_ABI_VER_NS2);
1358 	cmd->abi.abi_ver_ns3 = __cpu_to_le32(WMI_TLV_ABI_VER_NS3);
1359 	cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
1360 
1361 	cfg->num_vdevs = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1362 	cfg->num_peers = __cpu_to_le32(TARGET_TLV_NUM_PEERS);
1363 
1364 	if (test_bit(WMI_SERVICE_RX_FULL_REORDER, ar->wmi.svc_map)) {
1365 		cfg->num_offload_peers = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1366 		cfg->num_offload_reorder_bufs = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1367 	} else {
1368 		cfg->num_offload_peers = __cpu_to_le32(0);
1369 		cfg->num_offload_reorder_bufs = __cpu_to_le32(0);
1370 	}
1371 
1372 	cfg->num_peer_keys = __cpu_to_le32(2);
1373 	cfg->num_tids = __cpu_to_le32(TARGET_TLV_NUM_TIDS);
1374 	cfg->ast_skid_limit = __cpu_to_le32(0x10);
1375 	cfg->tx_chain_mask = __cpu_to_le32(0x7);
1376 	cfg->rx_chain_mask = __cpu_to_le32(0x7);
1377 	cfg->rx_timeout_pri[0] = __cpu_to_le32(0x64);
1378 	cfg->rx_timeout_pri[1] = __cpu_to_le32(0x64);
1379 	cfg->rx_timeout_pri[2] = __cpu_to_le32(0x64);
1380 	cfg->rx_timeout_pri[3] = __cpu_to_le32(0x28);
1381 	cfg->rx_decap_mode = __cpu_to_le32(ar->wmi.rx_decap_mode);
1382 	cfg->scan_max_pending_reqs = __cpu_to_le32(4);
1383 	cfg->bmiss_offload_max_vdev = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1384 	cfg->roam_offload_max_vdev = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1385 	cfg->roam_offload_max_ap_profiles = __cpu_to_le32(8);
1386 	cfg->num_mcast_groups = __cpu_to_le32(0);
1387 	cfg->num_mcast_table_elems = __cpu_to_le32(0);
1388 	cfg->mcast2ucast_mode = __cpu_to_le32(0);
1389 	cfg->tx_dbg_log_size = __cpu_to_le32(0x400);
1390 	cfg->num_wds_entries = __cpu_to_le32(0x20);
1391 	cfg->dma_burst_size = __cpu_to_le32(0);
1392 	cfg->mac_aggr_delim = __cpu_to_le32(0);
1393 	cfg->rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(0);
1394 	cfg->vow_config = __cpu_to_le32(0);
1395 	cfg->gtk_offload_max_vdev = __cpu_to_le32(2);
1396 	cfg->num_msdu_desc = __cpu_to_le32(TARGET_TLV_NUM_MSDU_DESC);
1397 	cfg->max_frag_entries = __cpu_to_le32(2);
1398 	cfg->num_tdls_vdevs = __cpu_to_le32(TARGET_TLV_NUM_TDLS_VDEVS);
1399 	cfg->num_tdls_conn_table_entries = __cpu_to_le32(0x20);
1400 	cfg->beacon_tx_offload_max_vdev = __cpu_to_le32(2);
1401 	cfg->num_multicast_filter_entries = __cpu_to_le32(5);
1402 	cfg->num_wow_filters = __cpu_to_le32(ar->wow.max_num_patterns);
1403 	cfg->num_keep_alive_pattern = __cpu_to_le32(6);
1404 	cfg->keep_alive_pattern_size = __cpu_to_le32(0);
1405 	cfg->max_tdls_concurrent_sleep_sta = __cpu_to_le32(1);
1406 	cfg->max_tdls_concurrent_buffer_sta = __cpu_to_le32(1);
1407 
1408 	ath10k_wmi_put_host_mem_chunks(ar, chunks);
1409 
1410 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv init\n");
1411 	return skb;
1412 }
1413 
1414 static struct sk_buff *
1415 ath10k_wmi_tlv_op_gen_start_scan(struct ath10k *ar,
1416 				 const struct wmi_start_scan_arg *arg)
1417 {
1418 	struct wmi_tlv_start_scan_cmd *cmd;
1419 	struct wmi_tlv *tlv;
1420 	struct sk_buff *skb;
1421 	size_t len, chan_len, ssid_len, bssid_len, ie_len;
1422 	__le32 *chans;
1423 	struct wmi_ssid *ssids;
1424 	struct wmi_mac_addr *addrs;
1425 	void *ptr;
1426 	int i, ret;
1427 
1428 	ret = ath10k_wmi_start_scan_verify(arg);
1429 	if (ret)
1430 		return ERR_PTR(ret);
1431 
1432 	chan_len = arg->n_channels * sizeof(__le32);
1433 	ssid_len = arg->n_ssids * sizeof(struct wmi_ssid);
1434 	bssid_len = arg->n_bssids * sizeof(struct wmi_mac_addr);
1435 	ie_len = roundup(arg->ie_len, 4);
1436 	len = (sizeof(*tlv) + sizeof(*cmd)) +
1437 	      (arg->n_channels ? sizeof(*tlv) + chan_len : 0) +
1438 	      (arg->n_ssids ? sizeof(*tlv) + ssid_len : 0) +
1439 	      (arg->n_bssids ? sizeof(*tlv) + bssid_len : 0) +
1440 	      (arg->ie_len ? sizeof(*tlv) + ie_len : 0);
1441 
1442 	skb = ath10k_wmi_alloc_skb(ar, len);
1443 	if (!skb)
1444 		return ERR_PTR(-ENOMEM);
1445 
1446 	ptr = (void *)skb->data;
1447 	tlv = ptr;
1448 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_START_SCAN_CMD);
1449 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1450 	cmd = (void *)tlv->value;
1451 
1452 	ath10k_wmi_put_start_scan_common(&cmd->common, arg);
1453 	cmd->burst_duration_ms = __cpu_to_le32(arg->burst_duration_ms);
1454 	cmd->num_channels = __cpu_to_le32(arg->n_channels);
1455 	cmd->num_ssids = __cpu_to_le32(arg->n_ssids);
1456 	cmd->num_bssids = __cpu_to_le32(arg->n_bssids);
1457 	cmd->ie_len = __cpu_to_le32(arg->ie_len);
1458 	cmd->num_probes = __cpu_to_le32(3);
1459 
1460 	/* FIXME: There are some scan flag inconsistencies across firmwares,
1461 	 * e.g. WMI-TLV inverts the logic behind the following flag.
1462 	 */
1463 	cmd->common.scan_ctrl_flags ^= __cpu_to_le32(WMI_SCAN_FILTER_PROBE_REQ);
1464 
1465 	ptr += sizeof(*tlv);
1466 	ptr += sizeof(*cmd);
1467 
1468 	tlv = ptr;
1469 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
1470 	tlv->len = __cpu_to_le16(chan_len);
1471 	chans = (void *)tlv->value;
1472 	for (i = 0; i < arg->n_channels; i++)
1473 		chans[i] = __cpu_to_le32(arg->channels[i]);
1474 
1475 	ptr += sizeof(*tlv);
1476 	ptr += chan_len;
1477 
1478 	tlv = ptr;
1479 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_FIXED_STRUCT);
1480 	tlv->len = __cpu_to_le16(ssid_len);
1481 	ssids = (void *)tlv->value;
1482 	for (i = 0; i < arg->n_ssids; i++) {
1483 		ssids[i].ssid_len = __cpu_to_le32(arg->ssids[i].len);
1484 		memcpy(ssids[i].ssid, arg->ssids[i].ssid, arg->ssids[i].len);
1485 	}
1486 
1487 	ptr += sizeof(*tlv);
1488 	ptr += ssid_len;
1489 
1490 	tlv = ptr;
1491 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_FIXED_STRUCT);
1492 	tlv->len = __cpu_to_le16(bssid_len);
1493 	addrs = (void *)tlv->value;
1494 	for (i = 0; i < arg->n_bssids; i++)
1495 		ether_addr_copy(addrs[i].addr, arg->bssids[i].bssid);
1496 
1497 	ptr += sizeof(*tlv);
1498 	ptr += bssid_len;
1499 
1500 	tlv = ptr;
1501 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
1502 	tlv->len = __cpu_to_le16(ie_len);
1503 	memcpy(tlv->value, arg->ie, arg->ie_len);
1504 
1505 	ptr += sizeof(*tlv);
1506 	ptr += ie_len;
1507 
1508 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv start scan\n");
1509 	return skb;
1510 }
1511 
1512 static struct sk_buff *
1513 ath10k_wmi_tlv_op_gen_stop_scan(struct ath10k *ar,
1514 				const struct wmi_stop_scan_arg *arg)
1515 {
1516 	struct wmi_stop_scan_cmd *cmd;
1517 	struct wmi_tlv *tlv;
1518 	struct sk_buff *skb;
1519 	u32 scan_id;
1520 	u32 req_id;
1521 
1522 	if (arg->req_id > 0xFFF)
1523 		return ERR_PTR(-EINVAL);
1524 	if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
1525 		return ERR_PTR(-EINVAL);
1526 
1527 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1528 	if (!skb)
1529 		return ERR_PTR(-ENOMEM);
1530 
1531 	scan_id = arg->u.scan_id;
1532 	scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
1533 
1534 	req_id = arg->req_id;
1535 	req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
1536 
1537 	tlv = (void *)skb->data;
1538 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STOP_SCAN_CMD);
1539 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1540 	cmd = (void *)tlv->value;
1541 	cmd->req_type = __cpu_to_le32(arg->req_type);
1542 	cmd->vdev_id = __cpu_to_le32(arg->u.vdev_id);
1543 	cmd->scan_id = __cpu_to_le32(scan_id);
1544 	cmd->scan_req_id = __cpu_to_le32(req_id);
1545 
1546 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv stop scan\n");
1547 	return skb;
1548 }
1549 
1550 static struct sk_buff *
1551 ath10k_wmi_tlv_op_gen_vdev_create(struct ath10k *ar,
1552 				  u32 vdev_id,
1553 				  enum wmi_vdev_type vdev_type,
1554 				  enum wmi_vdev_subtype vdev_subtype,
1555 				  const u8 mac_addr[ETH_ALEN])
1556 {
1557 	struct wmi_vdev_create_cmd *cmd;
1558 	struct wmi_tlv *tlv;
1559 	struct sk_buff *skb;
1560 
1561 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1562 	if (!skb)
1563 		return ERR_PTR(-ENOMEM);
1564 
1565 	tlv = (void *)skb->data;
1566 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_CREATE_CMD);
1567 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1568 	cmd = (void *)tlv->value;
1569 	cmd->vdev_id = __cpu_to_le32(vdev_id);
1570 	cmd->vdev_type = __cpu_to_le32(vdev_type);
1571 	cmd->vdev_subtype = __cpu_to_le32(vdev_subtype);
1572 	ether_addr_copy(cmd->vdev_macaddr.addr, mac_addr);
1573 
1574 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev create\n");
1575 	return skb;
1576 }
1577 
1578 static struct sk_buff *
1579 ath10k_wmi_tlv_op_gen_vdev_delete(struct ath10k *ar, u32 vdev_id)
1580 {
1581 	struct wmi_vdev_delete_cmd *cmd;
1582 	struct wmi_tlv *tlv;
1583 	struct sk_buff *skb;
1584 
1585 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1586 	if (!skb)
1587 		return ERR_PTR(-ENOMEM);
1588 
1589 	tlv = (void *)skb->data;
1590 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_DELETE_CMD);
1591 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1592 	cmd = (void *)tlv->value;
1593 	cmd->vdev_id = __cpu_to_le32(vdev_id);
1594 
1595 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev delete\n");
1596 	return skb;
1597 }
1598 
1599 static struct sk_buff *
1600 ath10k_wmi_tlv_op_gen_vdev_start(struct ath10k *ar,
1601 				 const struct wmi_vdev_start_request_arg *arg,
1602 				 bool restart)
1603 {
1604 	struct wmi_tlv_vdev_start_cmd *cmd;
1605 	struct wmi_channel *ch;
1606 	struct wmi_p2p_noa_descriptor *noa;
1607 	struct wmi_tlv *tlv;
1608 	struct sk_buff *skb;
1609 	size_t len;
1610 	void *ptr;
1611 	u32 flags = 0;
1612 
1613 	if (WARN_ON(arg->hidden_ssid && !arg->ssid))
1614 		return ERR_PTR(-EINVAL);
1615 	if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
1616 		return ERR_PTR(-EINVAL);
1617 
1618 	len = (sizeof(*tlv) + sizeof(*cmd)) +
1619 	      (sizeof(*tlv) + sizeof(*ch)) +
1620 	      (sizeof(*tlv) + 0);
1621 	skb = ath10k_wmi_alloc_skb(ar, len);
1622 	if (!skb)
1623 		return ERR_PTR(-ENOMEM);
1624 
1625 	if (arg->hidden_ssid)
1626 		flags |= WMI_VDEV_START_HIDDEN_SSID;
1627 	if (arg->pmf_enabled)
1628 		flags |= WMI_VDEV_START_PMF_ENABLED;
1629 
1630 	ptr = (void *)skb->data;
1631 
1632 	tlv = ptr;
1633 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_START_REQUEST_CMD);
1634 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1635 	cmd = (void *)tlv->value;
1636 	cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
1637 	cmd->bcn_intval = __cpu_to_le32(arg->bcn_intval);
1638 	cmd->dtim_period = __cpu_to_le32(arg->dtim_period);
1639 	cmd->flags = __cpu_to_le32(flags);
1640 	cmd->bcn_tx_rate = __cpu_to_le32(arg->bcn_tx_rate);
1641 	cmd->bcn_tx_power = __cpu_to_le32(arg->bcn_tx_power);
1642 	cmd->disable_hw_ack = __cpu_to_le32(arg->disable_hw_ack);
1643 
1644 	if (arg->ssid) {
1645 		cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
1646 		memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
1647 	}
1648 
1649 	ptr += sizeof(*tlv);
1650 	ptr += sizeof(*cmd);
1651 
1652 	tlv = ptr;
1653 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_CHANNEL);
1654 	tlv->len = __cpu_to_le16(sizeof(*ch));
1655 	ch = (void *)tlv->value;
1656 	ath10k_wmi_put_wmi_channel(ch, &arg->channel);
1657 
1658 	ptr += sizeof(*tlv);
1659 	ptr += sizeof(*ch);
1660 
1661 	tlv = ptr;
1662 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
1663 	tlv->len = 0;
1664 	noa = (void *)tlv->value;
1665 
1666 	/* Note: This is a nested TLV containing:
1667 	 * [wmi_tlv][wmi_p2p_noa_descriptor][wmi_tlv]..
1668 	 */
1669 
1670 	ptr += sizeof(*tlv);
1671 	ptr += 0;
1672 
1673 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev start\n");
1674 	return skb;
1675 }
1676 
1677 static struct sk_buff *
1678 ath10k_wmi_tlv_op_gen_vdev_stop(struct ath10k *ar, u32 vdev_id)
1679 {
1680 	struct wmi_vdev_stop_cmd *cmd;
1681 	struct wmi_tlv *tlv;
1682 	struct sk_buff *skb;
1683 
1684 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1685 	if (!skb)
1686 		return ERR_PTR(-ENOMEM);
1687 
1688 	tlv = (void *)skb->data;
1689 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_STOP_CMD);
1690 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1691 	cmd = (void *)tlv->value;
1692 	cmd->vdev_id = __cpu_to_le32(vdev_id);
1693 
1694 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev stop\n");
1695 	return skb;
1696 }
1697 
1698 static struct sk_buff *
1699 ath10k_wmi_tlv_op_gen_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid,
1700 			      const u8 *bssid)
1701 
1702 {
1703 	struct wmi_vdev_up_cmd *cmd;
1704 	struct wmi_tlv *tlv;
1705 	struct sk_buff *skb;
1706 
1707 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1708 	if (!skb)
1709 		return ERR_PTR(-ENOMEM);
1710 
1711 	tlv = (void *)skb->data;
1712 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_UP_CMD);
1713 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1714 	cmd = (void *)tlv->value;
1715 	cmd->vdev_id = __cpu_to_le32(vdev_id);
1716 	cmd->vdev_assoc_id = __cpu_to_le32(aid);
1717 	ether_addr_copy(cmd->vdev_bssid.addr, bssid);
1718 
1719 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev up\n");
1720 	return skb;
1721 }
1722 
1723 static struct sk_buff *
1724 ath10k_wmi_tlv_op_gen_vdev_down(struct ath10k *ar, u32 vdev_id)
1725 {
1726 	struct wmi_vdev_down_cmd *cmd;
1727 	struct wmi_tlv *tlv;
1728 	struct sk_buff *skb;
1729 
1730 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1731 	if (!skb)
1732 		return ERR_PTR(-ENOMEM);
1733 
1734 	tlv = (void *)skb->data;
1735 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_DOWN_CMD);
1736 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1737 	cmd = (void *)tlv->value;
1738 	cmd->vdev_id = __cpu_to_le32(vdev_id);
1739 
1740 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev down\n");
1741 	return skb;
1742 }
1743 
1744 static struct sk_buff *
1745 ath10k_wmi_tlv_op_gen_vdev_set_param(struct ath10k *ar, u32 vdev_id,
1746 				     u32 param_id, u32 param_value)
1747 {
1748 	struct wmi_vdev_set_param_cmd *cmd;
1749 	struct wmi_tlv *tlv;
1750 	struct sk_buff *skb;
1751 
1752 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1753 	if (!skb)
1754 		return ERR_PTR(-ENOMEM);
1755 
1756 	tlv = (void *)skb->data;
1757 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_SET_PARAM_CMD);
1758 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1759 	cmd = (void *)tlv->value;
1760 	cmd->vdev_id = __cpu_to_le32(vdev_id);
1761 	cmd->param_id = __cpu_to_le32(param_id);
1762 	cmd->param_value = __cpu_to_le32(param_value);
1763 
1764 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev set param\n");
1765 	return skb;
1766 }
1767 
1768 static struct sk_buff *
1769 ath10k_wmi_tlv_op_gen_vdev_install_key(struct ath10k *ar,
1770 				       const struct wmi_vdev_install_key_arg *arg)
1771 {
1772 	struct wmi_vdev_install_key_cmd *cmd;
1773 	struct wmi_tlv *tlv;
1774 	struct sk_buff *skb;
1775 	size_t len;
1776 	void *ptr;
1777 
1778 	if (arg->key_cipher == WMI_CIPHER_NONE && arg->key_data != NULL)
1779 		return ERR_PTR(-EINVAL);
1780 	if (arg->key_cipher != WMI_CIPHER_NONE && arg->key_data == NULL)
1781 		return ERR_PTR(-EINVAL);
1782 
1783 	len = sizeof(*tlv) + sizeof(*cmd) +
1784 	      sizeof(*tlv) + roundup(arg->key_len, sizeof(__le32));
1785 	skb = ath10k_wmi_alloc_skb(ar, len);
1786 	if (!skb)
1787 		return ERR_PTR(-ENOMEM);
1788 
1789 	ptr = (void *)skb->data;
1790 	tlv = ptr;
1791 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_INSTALL_KEY_CMD);
1792 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1793 	cmd = (void *)tlv->value;
1794 	cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
1795 	cmd->key_idx = __cpu_to_le32(arg->key_idx);
1796 	cmd->key_flags = __cpu_to_le32(arg->key_flags);
1797 	cmd->key_cipher = __cpu_to_le32(arg->key_cipher);
1798 	cmd->key_len = __cpu_to_le32(arg->key_len);
1799 	cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
1800 	cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
1801 
1802 	if (arg->macaddr)
1803 		ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr);
1804 
1805 	ptr += sizeof(*tlv);
1806 	ptr += sizeof(*cmd);
1807 
1808 	tlv = ptr;
1809 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
1810 	tlv->len = __cpu_to_le16(roundup(arg->key_len, sizeof(__le32)));
1811 	if (arg->key_data)
1812 		memcpy(tlv->value, arg->key_data, arg->key_len);
1813 
1814 	ptr += sizeof(*tlv);
1815 	ptr += roundup(arg->key_len, sizeof(__le32));
1816 
1817 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev install key\n");
1818 	return skb;
1819 }
1820 
1821 static void *ath10k_wmi_tlv_put_uapsd_ac(struct ath10k *ar, void *ptr,
1822 					 const struct wmi_sta_uapsd_auto_trig_arg *arg)
1823 {
1824 	struct wmi_sta_uapsd_auto_trig_param *ac;
1825 	struct wmi_tlv *tlv;
1826 
1827 	tlv = ptr;
1828 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_UAPSD_AUTO_TRIG_PARAM);
1829 	tlv->len = __cpu_to_le16(sizeof(*ac));
1830 	ac = (void *)tlv->value;
1831 
1832 	ac->wmm_ac = __cpu_to_le32(arg->wmm_ac);
1833 	ac->user_priority = __cpu_to_le32(arg->user_priority);
1834 	ac->service_interval = __cpu_to_le32(arg->service_interval);
1835 	ac->suspend_interval = __cpu_to_le32(arg->suspend_interval);
1836 	ac->delay_interval = __cpu_to_le32(arg->delay_interval);
1837 
1838 	ath10k_dbg(ar, ATH10K_DBG_WMI,
1839 		   "wmi tlv vdev sta uapsd auto trigger ac %d prio %d svc int %d susp int %d delay int %d\n",
1840 		   ac->wmm_ac, ac->user_priority, ac->service_interval,
1841 		   ac->suspend_interval, ac->delay_interval);
1842 
1843 	return ptr + sizeof(*tlv) + sizeof(*ac);
1844 }
1845 
1846 static struct sk_buff *
1847 ath10k_wmi_tlv_op_gen_vdev_sta_uapsd(struct ath10k *ar, u32 vdev_id,
1848 				     const u8 peer_addr[ETH_ALEN],
1849 				     const struct wmi_sta_uapsd_auto_trig_arg *args,
1850 				     u32 num_ac)
1851 {
1852 	struct wmi_sta_uapsd_auto_trig_cmd_fixed_param *cmd;
1853 	struct wmi_sta_uapsd_auto_trig_param *ac;
1854 	struct wmi_tlv *tlv;
1855 	struct sk_buff *skb;
1856 	size_t len;
1857 	size_t ac_tlv_len;
1858 	void *ptr;
1859 	int i;
1860 
1861 	ac_tlv_len = num_ac * (sizeof(*tlv) + sizeof(*ac));
1862 	len = sizeof(*tlv) + sizeof(*cmd) +
1863 	      sizeof(*tlv) + ac_tlv_len;
1864 	skb = ath10k_wmi_alloc_skb(ar, len);
1865 	if (!skb)
1866 		return ERR_PTR(-ENOMEM);
1867 
1868 	ptr = (void *)skb->data;
1869 	tlv = ptr;
1870 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_UAPSD_AUTO_TRIG_CMD);
1871 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1872 	cmd = (void *)tlv->value;
1873 	cmd->vdev_id = __cpu_to_le32(vdev_id);
1874 	cmd->num_ac = __cpu_to_le32(num_ac);
1875 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1876 
1877 	ptr += sizeof(*tlv);
1878 	ptr += sizeof(*cmd);
1879 
1880 	tlv = ptr;
1881 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
1882 	tlv->len = __cpu_to_le16(ac_tlv_len);
1883 	ac = (void *)tlv->value;
1884 
1885 	ptr += sizeof(*tlv);
1886 	for (i = 0; i < num_ac; i++)
1887 		ptr = ath10k_wmi_tlv_put_uapsd_ac(ar, ptr, &args[i]);
1888 
1889 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev sta uapsd auto trigger\n");
1890 	return skb;
1891 }
1892 
1893 static void *ath10k_wmi_tlv_put_wmm(void *ptr,
1894 				    const struct wmi_wmm_params_arg *arg)
1895 {
1896 	struct wmi_wmm_params *wmm;
1897 	struct wmi_tlv *tlv;
1898 
1899 	tlv = ptr;
1900 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WMM_PARAMS);
1901 	tlv->len = __cpu_to_le16(sizeof(*wmm));
1902 	wmm = (void *)tlv->value;
1903 	ath10k_wmi_set_wmm_param(wmm, arg);
1904 
1905 	return ptr + sizeof(*tlv) + sizeof(*wmm);
1906 }
1907 
1908 static struct sk_buff *
1909 ath10k_wmi_tlv_op_gen_vdev_wmm_conf(struct ath10k *ar, u32 vdev_id,
1910 				    const struct wmi_wmm_params_all_arg *arg)
1911 {
1912 	struct wmi_tlv_vdev_set_wmm_cmd *cmd;
1913 	struct wmi_tlv *tlv;
1914 	struct sk_buff *skb;
1915 	size_t len;
1916 	void *ptr;
1917 
1918 	len = sizeof(*tlv) + sizeof(*cmd);
1919 	skb = ath10k_wmi_alloc_skb(ar, len);
1920 	if (!skb)
1921 		return ERR_PTR(-ENOMEM);
1922 
1923 	ptr = (void *)skb->data;
1924 	tlv = ptr;
1925 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_SET_WMM_PARAMS_CMD);
1926 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1927 	cmd = (void *)tlv->value;
1928 	cmd->vdev_id = __cpu_to_le32(vdev_id);
1929 
1930 	ath10k_wmi_set_wmm_param(&cmd->vdev_wmm_params[0].params, &arg->ac_be);
1931 	ath10k_wmi_set_wmm_param(&cmd->vdev_wmm_params[1].params, &arg->ac_bk);
1932 	ath10k_wmi_set_wmm_param(&cmd->vdev_wmm_params[2].params, &arg->ac_vi);
1933 	ath10k_wmi_set_wmm_param(&cmd->vdev_wmm_params[3].params, &arg->ac_vo);
1934 
1935 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev wmm conf\n");
1936 	return skb;
1937 }
1938 
1939 static struct sk_buff *
1940 ath10k_wmi_tlv_op_gen_sta_keepalive(struct ath10k *ar,
1941 				    const struct wmi_sta_keepalive_arg *arg)
1942 {
1943 	struct wmi_tlv_sta_keepalive_cmd *cmd;
1944 	struct wmi_sta_keepalive_arp_resp *arp;
1945 	struct sk_buff *skb;
1946 	struct wmi_tlv *tlv;
1947 	void *ptr;
1948 	size_t len;
1949 
1950 	len = sizeof(*tlv) + sizeof(*cmd) +
1951 	      sizeof(*tlv) + sizeof(*arp);
1952 	skb = ath10k_wmi_alloc_skb(ar, len);
1953 	if (!skb)
1954 		return ERR_PTR(-ENOMEM);
1955 
1956 	ptr = (void *)skb->data;
1957 	tlv = ptr;
1958 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_KEEPALIVE_CMD);
1959 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1960 	cmd = (void *)tlv->value;
1961 	cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
1962 	cmd->enabled = __cpu_to_le32(arg->enabled);
1963 	cmd->method = __cpu_to_le32(arg->method);
1964 	cmd->interval = __cpu_to_le32(arg->interval);
1965 
1966 	ptr += sizeof(*tlv);
1967 	ptr += sizeof(*cmd);
1968 
1969 	tlv = ptr;
1970 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_KEEPALVE_ARP_RESPONSE);
1971 	tlv->len = __cpu_to_le16(sizeof(*arp));
1972 	arp = (void *)tlv->value;
1973 
1974 	arp->src_ip4_addr = arg->src_ip4_addr;
1975 	arp->dest_ip4_addr = arg->dest_ip4_addr;
1976 	ether_addr_copy(arp->dest_mac_addr.addr, arg->dest_mac_addr);
1977 
1978 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv sta keepalive vdev %d enabled %d method %d inverval %d\n",
1979 		   arg->vdev_id, arg->enabled, arg->method, arg->interval);
1980 	return skb;
1981 }
1982 
1983 static struct sk_buff *
1984 ath10k_wmi_tlv_op_gen_peer_create(struct ath10k *ar, u32 vdev_id,
1985 				  const u8 peer_addr[ETH_ALEN],
1986 				  enum wmi_peer_type peer_type)
1987 {
1988 	struct wmi_tlv_peer_create_cmd *cmd;
1989 	struct wmi_tlv *tlv;
1990 	struct sk_buff *skb;
1991 
1992 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1993 	if (!skb)
1994 		return ERR_PTR(-ENOMEM);
1995 
1996 	tlv = (void *)skb->data;
1997 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_CREATE_CMD);
1998 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1999 	cmd = (void *)tlv->value;
2000 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2001 	cmd->peer_type = __cpu_to_le32(peer_type);
2002 	ether_addr_copy(cmd->peer_addr.addr, peer_addr);
2003 
2004 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer create\n");
2005 	return skb;
2006 }
2007 
2008 static struct sk_buff *
2009 ath10k_wmi_tlv_op_gen_peer_delete(struct ath10k *ar, u32 vdev_id,
2010 				  const u8 peer_addr[ETH_ALEN])
2011 {
2012 	struct wmi_peer_delete_cmd *cmd;
2013 	struct wmi_tlv *tlv;
2014 	struct sk_buff *skb;
2015 
2016 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2017 	if (!skb)
2018 		return ERR_PTR(-ENOMEM);
2019 
2020 	tlv = (void *)skb->data;
2021 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_DELETE_CMD);
2022 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2023 	cmd = (void *)tlv->value;
2024 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2025 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
2026 
2027 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer delete\n");
2028 	return skb;
2029 }
2030 
2031 static struct sk_buff *
2032 ath10k_wmi_tlv_op_gen_peer_flush(struct ath10k *ar, u32 vdev_id,
2033 				 const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
2034 {
2035 	struct wmi_peer_flush_tids_cmd *cmd;
2036 	struct wmi_tlv *tlv;
2037 	struct sk_buff *skb;
2038 
2039 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2040 	if (!skb)
2041 		return ERR_PTR(-ENOMEM);
2042 
2043 	tlv = (void *)skb->data;
2044 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_FLUSH_TIDS_CMD);
2045 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2046 	cmd = (void *)tlv->value;
2047 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2048 	cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
2049 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
2050 
2051 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer flush\n");
2052 	return skb;
2053 }
2054 
2055 static struct sk_buff *
2056 ath10k_wmi_tlv_op_gen_peer_set_param(struct ath10k *ar, u32 vdev_id,
2057 				     const u8 *peer_addr,
2058 				     enum wmi_peer_param param_id,
2059 				     u32 param_value)
2060 {
2061 	struct wmi_peer_set_param_cmd *cmd;
2062 	struct wmi_tlv *tlv;
2063 	struct sk_buff *skb;
2064 
2065 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2066 	if (!skb)
2067 		return ERR_PTR(-ENOMEM);
2068 
2069 	tlv = (void *)skb->data;
2070 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_SET_PARAM_CMD);
2071 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2072 	cmd = (void *)tlv->value;
2073 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2074 	cmd->param_id = __cpu_to_le32(param_id);
2075 	cmd->param_value = __cpu_to_le32(param_value);
2076 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
2077 
2078 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer set param\n");
2079 	return skb;
2080 }
2081 
2082 static struct sk_buff *
2083 ath10k_wmi_tlv_op_gen_peer_assoc(struct ath10k *ar,
2084 				 const struct wmi_peer_assoc_complete_arg *arg)
2085 {
2086 	struct wmi_tlv_peer_assoc_cmd *cmd;
2087 	struct wmi_vht_rate_set *vht_rate;
2088 	struct wmi_tlv *tlv;
2089 	struct sk_buff *skb;
2090 	size_t len, legacy_rate_len, ht_rate_len;
2091 	void *ptr;
2092 
2093 	if (arg->peer_mpdu_density > 16)
2094 		return ERR_PTR(-EINVAL);
2095 	if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
2096 		return ERR_PTR(-EINVAL);
2097 	if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
2098 		return ERR_PTR(-EINVAL);
2099 
2100 	legacy_rate_len = roundup(arg->peer_legacy_rates.num_rates,
2101 				  sizeof(__le32));
2102 	ht_rate_len = roundup(arg->peer_ht_rates.num_rates, sizeof(__le32));
2103 	len = (sizeof(*tlv) + sizeof(*cmd)) +
2104 	      (sizeof(*tlv) + legacy_rate_len) +
2105 	      (sizeof(*tlv) + ht_rate_len) +
2106 	      (sizeof(*tlv) + sizeof(*vht_rate));
2107 	skb = ath10k_wmi_alloc_skb(ar, len);
2108 	if (!skb)
2109 		return ERR_PTR(-ENOMEM);
2110 
2111 	ptr = (void *)skb->data;
2112 	tlv = ptr;
2113 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_ASSOC_COMPLETE_CMD);
2114 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2115 	cmd = (void *)tlv->value;
2116 
2117 	cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
2118 	cmd->new_assoc = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
2119 	cmd->assoc_id = __cpu_to_le32(arg->peer_aid);
2120 	cmd->flags = __cpu_to_le32(arg->peer_flags);
2121 	cmd->caps = __cpu_to_le32(arg->peer_caps);
2122 	cmd->listen_intval = __cpu_to_le32(arg->peer_listen_intval);
2123 	cmd->ht_caps = __cpu_to_le32(arg->peer_ht_caps);
2124 	cmd->max_mpdu = __cpu_to_le32(arg->peer_max_mpdu);
2125 	cmd->mpdu_density = __cpu_to_le32(arg->peer_mpdu_density);
2126 	cmd->rate_caps = __cpu_to_le32(arg->peer_rate_caps);
2127 	cmd->nss = __cpu_to_le32(arg->peer_num_spatial_streams);
2128 	cmd->vht_caps = __cpu_to_le32(arg->peer_vht_caps);
2129 	cmd->phy_mode = __cpu_to_le32(arg->peer_phymode);
2130 	cmd->num_legacy_rates = __cpu_to_le32(arg->peer_legacy_rates.num_rates);
2131 	cmd->num_ht_rates = __cpu_to_le32(arg->peer_ht_rates.num_rates);
2132 	ether_addr_copy(cmd->mac_addr.addr, arg->addr);
2133 
2134 	ptr += sizeof(*tlv);
2135 	ptr += sizeof(*cmd);
2136 
2137 	tlv = ptr;
2138 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
2139 	tlv->len = __cpu_to_le16(legacy_rate_len);
2140 	memcpy(tlv->value, arg->peer_legacy_rates.rates,
2141 	       arg->peer_legacy_rates.num_rates);
2142 
2143 	ptr += sizeof(*tlv);
2144 	ptr += legacy_rate_len;
2145 
2146 	tlv = ptr;
2147 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
2148 	tlv->len = __cpu_to_le16(ht_rate_len);
2149 	memcpy(tlv->value, arg->peer_ht_rates.rates,
2150 	       arg->peer_ht_rates.num_rates);
2151 
2152 	ptr += sizeof(*tlv);
2153 	ptr += ht_rate_len;
2154 
2155 	tlv = ptr;
2156 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VHT_RATE_SET);
2157 	tlv->len = __cpu_to_le16(sizeof(*vht_rate));
2158 	vht_rate = (void *)tlv->value;
2159 
2160 	vht_rate->rx_max_rate = __cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
2161 	vht_rate->rx_mcs_set = __cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
2162 	vht_rate->tx_max_rate = __cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
2163 	vht_rate->tx_mcs_set = __cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
2164 
2165 	ptr += sizeof(*tlv);
2166 	ptr += sizeof(*vht_rate);
2167 
2168 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer assoc\n");
2169 	return skb;
2170 }
2171 
2172 static struct sk_buff *
2173 ath10k_wmi_tlv_op_gen_set_psmode(struct ath10k *ar, u32 vdev_id,
2174 				 enum wmi_sta_ps_mode psmode)
2175 {
2176 	struct wmi_sta_powersave_mode_cmd *cmd;
2177 	struct wmi_tlv *tlv;
2178 	struct sk_buff *skb;
2179 
2180 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2181 	if (!skb)
2182 		return ERR_PTR(-ENOMEM);
2183 
2184 	tlv = (void *)skb->data;
2185 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_POWERSAVE_MODE_CMD);
2186 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2187 	cmd = (void *)tlv->value;
2188 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2189 	cmd->sta_ps_mode = __cpu_to_le32(psmode);
2190 
2191 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv set psmode\n");
2192 	return skb;
2193 }
2194 
2195 static struct sk_buff *
2196 ath10k_wmi_tlv_op_gen_set_sta_ps(struct ath10k *ar, u32 vdev_id,
2197 				 enum wmi_sta_powersave_param param_id,
2198 				 u32 param_value)
2199 {
2200 	struct wmi_sta_powersave_param_cmd *cmd;
2201 	struct wmi_tlv *tlv;
2202 	struct sk_buff *skb;
2203 
2204 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2205 	if (!skb)
2206 		return ERR_PTR(-ENOMEM);
2207 
2208 	tlv = (void *)skb->data;
2209 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_POWERSAVE_PARAM_CMD);
2210 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2211 	cmd = (void *)tlv->value;
2212 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2213 	cmd->param_id = __cpu_to_le32(param_id);
2214 	cmd->param_value = __cpu_to_le32(param_value);
2215 
2216 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv set sta ps\n");
2217 	return skb;
2218 }
2219 
2220 static struct sk_buff *
2221 ath10k_wmi_tlv_op_gen_set_ap_ps(struct ath10k *ar, u32 vdev_id, const u8 *mac,
2222 				enum wmi_ap_ps_peer_param param_id, u32 value)
2223 {
2224 	struct wmi_ap_ps_peer_cmd *cmd;
2225 	struct wmi_tlv *tlv;
2226 	struct sk_buff *skb;
2227 
2228 	if (!mac)
2229 		return ERR_PTR(-EINVAL);
2230 
2231 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2232 	if (!skb)
2233 		return ERR_PTR(-ENOMEM);
2234 
2235 	tlv = (void *)skb->data;
2236 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_AP_PS_PEER_CMD);
2237 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2238 	cmd = (void *)tlv->value;
2239 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2240 	cmd->param_id = __cpu_to_le32(param_id);
2241 	cmd->param_value = __cpu_to_le32(value);
2242 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
2243 
2244 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv ap ps param\n");
2245 	return skb;
2246 }
2247 
2248 static struct sk_buff *
2249 ath10k_wmi_tlv_op_gen_scan_chan_list(struct ath10k *ar,
2250 				     const struct wmi_scan_chan_list_arg *arg)
2251 {
2252 	struct wmi_tlv_scan_chan_list_cmd *cmd;
2253 	struct wmi_channel *ci;
2254 	struct wmi_channel_arg *ch;
2255 	struct wmi_tlv *tlv;
2256 	struct sk_buff *skb;
2257 	size_t chans_len, len;
2258 	int i;
2259 	void *ptr, *chans;
2260 
2261 	chans_len = arg->n_channels * (sizeof(*tlv) + sizeof(*ci));
2262 	len = (sizeof(*tlv) + sizeof(*cmd)) +
2263 	      (sizeof(*tlv) + chans_len);
2264 
2265 	skb = ath10k_wmi_alloc_skb(ar, len);
2266 	if (!skb)
2267 		return ERR_PTR(-ENOMEM);
2268 
2269 	ptr = (void *)skb->data;
2270 	tlv = ptr;
2271 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_SCAN_CHAN_LIST_CMD);
2272 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2273 	cmd = (void *)tlv->value;
2274 	cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
2275 
2276 	ptr += sizeof(*tlv);
2277 	ptr += sizeof(*cmd);
2278 
2279 	tlv = ptr;
2280 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
2281 	tlv->len = __cpu_to_le16(chans_len);
2282 	chans = (void *)tlv->value;
2283 
2284 	for (i = 0; i < arg->n_channels; i++) {
2285 		ch = &arg->channels[i];
2286 
2287 		tlv = chans;
2288 		tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_CHANNEL);
2289 		tlv->len = __cpu_to_le16(sizeof(*ci));
2290 		ci = (void *)tlv->value;
2291 
2292 		ath10k_wmi_put_wmi_channel(ci, ch);
2293 
2294 		chans += sizeof(*tlv);
2295 		chans += sizeof(*ci);
2296 	}
2297 
2298 	ptr += sizeof(*tlv);
2299 	ptr += chans_len;
2300 
2301 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv scan chan list\n");
2302 	return skb;
2303 }
2304 
2305 static struct sk_buff *
2306 ath10k_wmi_tlv_op_gen_beacon_dma(struct ath10k *ar, u32 vdev_id,
2307 				 const void *bcn, size_t bcn_len,
2308 				 u32 bcn_paddr, bool dtim_zero,
2309 				 bool deliver_cab)
2310 
2311 {
2312 	struct wmi_bcn_tx_ref_cmd *cmd;
2313 	struct wmi_tlv *tlv;
2314 	struct sk_buff *skb;
2315 	struct ieee80211_hdr *hdr;
2316 	u16 fc;
2317 
2318 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2319 	if (!skb)
2320 		return ERR_PTR(-ENOMEM);
2321 
2322 	hdr = (struct ieee80211_hdr *)bcn;
2323 	fc = le16_to_cpu(hdr->frame_control);
2324 
2325 	tlv = (void *)skb->data;
2326 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_BCN_SEND_FROM_HOST_CMD);
2327 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2328 	cmd = (void *)tlv->value;
2329 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2330 	cmd->data_len = __cpu_to_le32(bcn_len);
2331 	cmd->data_ptr = __cpu_to_le32(bcn_paddr);
2332 	cmd->msdu_id = 0;
2333 	cmd->frame_control = __cpu_to_le32(fc);
2334 	cmd->flags = 0;
2335 
2336 	if (dtim_zero)
2337 		cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DTIM_ZERO);
2338 
2339 	if (deliver_cab)
2340 		cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DELIVER_CAB);
2341 
2342 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv beacon dma\n");
2343 	return skb;
2344 }
2345 
2346 static struct sk_buff *
2347 ath10k_wmi_tlv_op_gen_pdev_set_wmm(struct ath10k *ar,
2348 				   const struct wmi_wmm_params_all_arg *arg)
2349 {
2350 	struct wmi_tlv_pdev_set_wmm_cmd *cmd;
2351 	struct wmi_wmm_params *wmm;
2352 	struct wmi_tlv *tlv;
2353 	struct sk_buff *skb;
2354 	size_t len;
2355 	void *ptr;
2356 
2357 	len = (sizeof(*tlv) + sizeof(*cmd)) +
2358 	      (4 * (sizeof(*tlv) + sizeof(*wmm)));
2359 	skb = ath10k_wmi_alloc_skb(ar, len);
2360 	if (!skb)
2361 		return ERR_PTR(-ENOMEM);
2362 
2363 	ptr = (void *)skb->data;
2364 
2365 	tlv = ptr;
2366 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_SET_WMM_PARAMS_CMD);
2367 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2368 	cmd = (void *)tlv->value;
2369 
2370 	/* nothing to set here */
2371 
2372 	ptr += sizeof(*tlv);
2373 	ptr += sizeof(*cmd);
2374 
2375 	ptr = ath10k_wmi_tlv_put_wmm(ptr, &arg->ac_be);
2376 	ptr = ath10k_wmi_tlv_put_wmm(ptr, &arg->ac_bk);
2377 	ptr = ath10k_wmi_tlv_put_wmm(ptr, &arg->ac_vi);
2378 	ptr = ath10k_wmi_tlv_put_wmm(ptr, &arg->ac_vo);
2379 
2380 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev set wmm\n");
2381 	return skb;
2382 }
2383 
2384 static struct sk_buff *
2385 ath10k_wmi_tlv_op_gen_request_stats(struct ath10k *ar, u32 stats_mask)
2386 {
2387 	struct wmi_request_stats_cmd *cmd;
2388 	struct wmi_tlv *tlv;
2389 	struct sk_buff *skb;
2390 
2391 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2392 	if (!skb)
2393 		return ERR_PTR(-ENOMEM);
2394 
2395 	tlv = (void *)skb->data;
2396 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_REQUEST_STATS_CMD);
2397 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2398 	cmd = (void *)tlv->value;
2399 	cmd->stats_id = __cpu_to_le32(stats_mask);
2400 
2401 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv request stats\n");
2402 	return skb;
2403 }
2404 
2405 static struct sk_buff *
2406 ath10k_wmi_tlv_op_gen_force_fw_hang(struct ath10k *ar,
2407 				    enum wmi_force_fw_hang_type type,
2408 				    u32 delay_ms)
2409 {
2410 	struct wmi_force_fw_hang_cmd *cmd;
2411 	struct wmi_tlv *tlv;
2412 	struct sk_buff *skb;
2413 
2414 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2415 	if (!skb)
2416 		return ERR_PTR(-ENOMEM);
2417 
2418 	tlv = (void *)skb->data;
2419 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_FORCE_FW_HANG_CMD);
2420 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2421 	cmd = (void *)tlv->value;
2422 	cmd->type = __cpu_to_le32(type);
2423 	cmd->delay_ms = __cpu_to_le32(delay_ms);
2424 
2425 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv force fw hang\n");
2426 	return skb;
2427 }
2428 
2429 static struct sk_buff *
2430 ath10k_wmi_tlv_op_gen_dbglog_cfg(struct ath10k *ar, u32 module_enable,
2431 				 u32 log_level) {
2432 	struct wmi_tlv_dbglog_cmd *cmd;
2433 	struct wmi_tlv *tlv;
2434 	struct sk_buff *skb;
2435 	size_t len, bmap_len;
2436 	u32 value;
2437 	void *ptr;
2438 
2439 	if (module_enable) {
2440 		value = WMI_TLV_DBGLOG_LOG_LEVEL_VALUE(
2441 				module_enable,
2442 				WMI_TLV_DBGLOG_LOG_LEVEL_VERBOSE);
2443 	} else {
2444 		value = WMI_TLV_DBGLOG_LOG_LEVEL_VALUE(
2445 				WMI_TLV_DBGLOG_ALL_MODULES,
2446 				WMI_TLV_DBGLOG_LOG_LEVEL_WARN);
2447 	}
2448 
2449 	bmap_len = 0;
2450 	len = sizeof(*tlv) + sizeof(*cmd) + sizeof(*tlv) + bmap_len;
2451 	skb = ath10k_wmi_alloc_skb(ar, len);
2452 	if (!skb)
2453 		return ERR_PTR(-ENOMEM);
2454 
2455 	ptr = (void *)skb->data;
2456 
2457 	tlv = ptr;
2458 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_DEBUG_LOG_CONFIG_CMD);
2459 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2460 	cmd = (void *)tlv->value;
2461 	cmd->param = __cpu_to_le32(WMI_TLV_DBGLOG_PARAM_LOG_LEVEL);
2462 	cmd->value = __cpu_to_le32(value);
2463 
2464 	ptr += sizeof(*tlv);
2465 	ptr += sizeof(*cmd);
2466 
2467 	tlv = ptr;
2468 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
2469 	tlv->len = __cpu_to_le16(bmap_len);
2470 
2471 	/* nothing to do here */
2472 
2473 	ptr += sizeof(*tlv);
2474 	ptr += sizeof(bmap_len);
2475 
2476 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv dbglog value 0x%08x\n", value);
2477 	return skb;
2478 }
2479 
2480 static struct sk_buff *
2481 ath10k_wmi_tlv_op_gen_pktlog_enable(struct ath10k *ar, u32 filter)
2482 {
2483 	struct wmi_tlv_pktlog_enable *cmd;
2484 	struct wmi_tlv *tlv;
2485 	struct sk_buff *skb;
2486 	void *ptr;
2487 	size_t len;
2488 
2489 	len = sizeof(*tlv) + sizeof(*cmd);
2490 	skb = ath10k_wmi_alloc_skb(ar, len);
2491 	if (!skb)
2492 		return ERR_PTR(-ENOMEM);
2493 
2494 	ptr = (void *)skb->data;
2495 	tlv = ptr;
2496 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_PKTLOG_ENABLE_CMD);
2497 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2498 	cmd = (void *)tlv->value;
2499 	cmd->filter = __cpu_to_le32(filter);
2500 
2501 	ptr += sizeof(*tlv);
2502 	ptr += sizeof(*cmd);
2503 
2504 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pktlog enable filter 0x%08x\n",
2505 		   filter);
2506 	return skb;
2507 }
2508 
2509 static struct sk_buff *
2510 ath10k_wmi_tlv_op_gen_pktlog_disable(struct ath10k *ar)
2511 {
2512 	struct wmi_tlv_pktlog_disable *cmd;
2513 	struct wmi_tlv *tlv;
2514 	struct sk_buff *skb;
2515 	void *ptr;
2516 	size_t len;
2517 
2518 	len = sizeof(*tlv) + sizeof(*cmd);
2519 	skb = ath10k_wmi_alloc_skb(ar, len);
2520 	if (!skb)
2521 		return ERR_PTR(-ENOMEM);
2522 
2523 	ptr = (void *)skb->data;
2524 	tlv = ptr;
2525 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_PKTLOG_DISABLE_CMD);
2526 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2527 	cmd = (void *)tlv->value;
2528 
2529 	ptr += sizeof(*tlv);
2530 	ptr += sizeof(*cmd);
2531 
2532 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pktlog disable\n");
2533 	return skb;
2534 }
2535 
2536 static struct sk_buff *
2537 ath10k_wmi_tlv_op_gen_bcn_tmpl(struct ath10k *ar, u32 vdev_id,
2538 			       u32 tim_ie_offset, struct sk_buff *bcn,
2539 			       u32 prb_caps, u32 prb_erp, void *prb_ies,
2540 			       size_t prb_ies_len)
2541 {
2542 	struct wmi_tlv_bcn_tmpl_cmd *cmd;
2543 	struct wmi_tlv_bcn_prb_info *info;
2544 	struct wmi_tlv *tlv;
2545 	struct sk_buff *skb;
2546 	void *ptr;
2547 	size_t len;
2548 
2549 	if (WARN_ON(prb_ies_len > 0 && !prb_ies))
2550 		return ERR_PTR(-EINVAL);
2551 
2552 	len = sizeof(*tlv) + sizeof(*cmd) +
2553 	      sizeof(*tlv) + sizeof(*info) + prb_ies_len +
2554 	      sizeof(*tlv) + roundup(bcn->len, 4);
2555 	skb = ath10k_wmi_alloc_skb(ar, len);
2556 	if (!skb)
2557 		return ERR_PTR(-ENOMEM);
2558 
2559 	ptr = (void *)skb->data;
2560 	tlv = ptr;
2561 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_BCN_TMPL_CMD);
2562 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2563 	cmd = (void *)tlv->value;
2564 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2565 	cmd->tim_ie_offset = __cpu_to_le32(tim_ie_offset);
2566 	cmd->buf_len = __cpu_to_le32(bcn->len);
2567 
2568 	ptr += sizeof(*tlv);
2569 	ptr += sizeof(*cmd);
2570 
2571 	/* FIXME: prb_ies_len should be probably aligned to 4byte boundary but
2572 	 * then it is then impossible to pass original ie len.
2573 	 * This chunk is not used yet so if setting probe resp template yields
2574 	 * problems with beaconing or crashes firmware look here.
2575 	 */
2576 	tlv = ptr;
2577 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_BCN_PRB_INFO);
2578 	tlv->len = __cpu_to_le16(sizeof(*info) + prb_ies_len);
2579 	info = (void *)tlv->value;
2580 	info->caps = __cpu_to_le32(prb_caps);
2581 	info->erp = __cpu_to_le32(prb_erp);
2582 	memcpy(info->ies, prb_ies, prb_ies_len);
2583 
2584 	ptr += sizeof(*tlv);
2585 	ptr += sizeof(*info);
2586 	ptr += prb_ies_len;
2587 
2588 	tlv = ptr;
2589 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
2590 	tlv->len = __cpu_to_le16(roundup(bcn->len, 4));
2591 	memcpy(tlv->value, bcn->data, bcn->len);
2592 
2593 	/* FIXME: Adjust TSF? */
2594 
2595 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv bcn tmpl vdev_id %i\n",
2596 		   vdev_id);
2597 	return skb;
2598 }
2599 
2600 static struct sk_buff *
2601 ath10k_wmi_tlv_op_gen_prb_tmpl(struct ath10k *ar, u32 vdev_id,
2602 			       struct sk_buff *prb)
2603 {
2604 	struct wmi_tlv_prb_tmpl_cmd *cmd;
2605 	struct wmi_tlv_bcn_prb_info *info;
2606 	struct wmi_tlv *tlv;
2607 	struct sk_buff *skb;
2608 	void *ptr;
2609 	size_t len;
2610 
2611 	len = sizeof(*tlv) + sizeof(*cmd) +
2612 	      sizeof(*tlv) + sizeof(*info) +
2613 	      sizeof(*tlv) + roundup(prb->len, 4);
2614 	skb = ath10k_wmi_alloc_skb(ar, len);
2615 	if (!skb)
2616 		return ERR_PTR(-ENOMEM);
2617 
2618 	ptr = (void *)skb->data;
2619 	tlv = ptr;
2620 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PRB_TMPL_CMD);
2621 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2622 	cmd = (void *)tlv->value;
2623 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2624 	cmd->buf_len = __cpu_to_le32(prb->len);
2625 
2626 	ptr += sizeof(*tlv);
2627 	ptr += sizeof(*cmd);
2628 
2629 	tlv = ptr;
2630 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_BCN_PRB_INFO);
2631 	tlv->len = __cpu_to_le16(sizeof(*info));
2632 	info = (void *)tlv->value;
2633 	info->caps = 0;
2634 	info->erp = 0;
2635 
2636 	ptr += sizeof(*tlv);
2637 	ptr += sizeof(*info);
2638 
2639 	tlv = ptr;
2640 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
2641 	tlv->len = __cpu_to_le16(roundup(prb->len, 4));
2642 	memcpy(tlv->value, prb->data, prb->len);
2643 
2644 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv prb tmpl vdev_id %i\n",
2645 		   vdev_id);
2646 	return skb;
2647 }
2648 
2649 static struct sk_buff *
2650 ath10k_wmi_tlv_op_gen_p2p_go_bcn_ie(struct ath10k *ar, u32 vdev_id,
2651 				    const u8 *p2p_ie)
2652 {
2653 	struct wmi_tlv_p2p_go_bcn_ie *cmd;
2654 	struct wmi_tlv *tlv;
2655 	struct sk_buff *skb;
2656 	void *ptr;
2657 	size_t len;
2658 
2659 	len = sizeof(*tlv) + sizeof(*cmd) +
2660 	      sizeof(*tlv) + roundup(p2p_ie[1] + 2, 4);
2661 	skb = ath10k_wmi_alloc_skb(ar, len);
2662 	if (!skb)
2663 		return ERR_PTR(-ENOMEM);
2664 
2665 	ptr = (void *)skb->data;
2666 	tlv = ptr;
2667 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_P2P_GO_SET_BEACON_IE);
2668 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2669 	cmd = (void *)tlv->value;
2670 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2671 	cmd->ie_len = __cpu_to_le32(p2p_ie[1] + 2);
2672 
2673 	ptr += sizeof(*tlv);
2674 	ptr += sizeof(*cmd);
2675 
2676 	tlv = ptr;
2677 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
2678 	tlv->len = __cpu_to_le16(roundup(p2p_ie[1] + 2, 4));
2679 	memcpy(tlv->value, p2p_ie, p2p_ie[1] + 2);
2680 
2681 	ptr += sizeof(*tlv);
2682 	ptr += roundup(p2p_ie[1] + 2, 4);
2683 
2684 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv p2p go bcn ie for vdev %i\n",
2685 		   vdev_id);
2686 	return skb;
2687 }
2688 
2689 static struct sk_buff *
2690 ath10k_wmi_tlv_op_gen_update_fw_tdls_state(struct ath10k *ar, u32 vdev_id,
2691 					   enum wmi_tdls_state state)
2692 {
2693 	struct wmi_tdls_set_state_cmd *cmd;
2694 	struct wmi_tlv *tlv;
2695 	struct sk_buff *skb;
2696 	void *ptr;
2697 	size_t len;
2698 	/* Set to options from wmi_tlv_tdls_options,
2699 	 * for now none of them are enabled.
2700 	 */
2701 	u32 options = 0;
2702 
2703 	len = sizeof(*tlv) + sizeof(*cmd);
2704 	skb = ath10k_wmi_alloc_skb(ar, len);
2705 	if (!skb)
2706 		return ERR_PTR(-ENOMEM);
2707 
2708 	ptr = (void *)skb->data;
2709 	tlv = ptr;
2710 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_TDLS_SET_STATE_CMD);
2711 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2712 
2713 	cmd = (void *)tlv->value;
2714 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2715 	cmd->state = __cpu_to_le32(state);
2716 	cmd->notification_interval_ms = __cpu_to_le32(5000);
2717 	cmd->tx_discovery_threshold = __cpu_to_le32(100);
2718 	cmd->tx_teardown_threshold = __cpu_to_le32(5);
2719 	cmd->rssi_teardown_threshold = __cpu_to_le32(-75);
2720 	cmd->rssi_delta = __cpu_to_le32(-20);
2721 	cmd->tdls_options = __cpu_to_le32(options);
2722 	cmd->tdls_peer_traffic_ind_window = __cpu_to_le32(2);
2723 	cmd->tdls_peer_traffic_response_timeout_ms = __cpu_to_le32(5000);
2724 	cmd->tdls_puapsd_mask = __cpu_to_le32(0xf);
2725 	cmd->tdls_puapsd_inactivity_time_ms = __cpu_to_le32(0);
2726 	cmd->tdls_puapsd_rx_frame_threshold = __cpu_to_le32(10);
2727 
2728 	ptr += sizeof(*tlv);
2729 	ptr += sizeof(*cmd);
2730 
2731 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv update fw tdls state %d for vdev %i\n",
2732 		   state, vdev_id);
2733 	return skb;
2734 }
2735 
2736 static u32 ath10k_wmi_tlv_prepare_peer_qos(u8 uapsd_queues, u8 sp)
2737 {
2738 	u32 peer_qos = 0;
2739 
2740 	if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2741 		peer_qos |= WMI_TLV_TDLS_PEER_QOS_AC_VO;
2742 	if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2743 		peer_qos |= WMI_TLV_TDLS_PEER_QOS_AC_VI;
2744 	if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2745 		peer_qos |= WMI_TLV_TDLS_PEER_QOS_AC_BK;
2746 	if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2747 		peer_qos |= WMI_TLV_TDLS_PEER_QOS_AC_BE;
2748 
2749 	peer_qos |= SM(sp, WMI_TLV_TDLS_PEER_SP);
2750 
2751 	return peer_qos;
2752 }
2753 
2754 static struct sk_buff *
2755 ath10k_wmi_tlv_op_gen_tdls_peer_update(struct ath10k *ar,
2756 				       const struct wmi_tdls_peer_update_cmd_arg *arg,
2757 				       const struct wmi_tdls_peer_capab_arg *cap,
2758 				       const struct wmi_channel_arg *chan_arg)
2759 {
2760 	struct wmi_tdls_peer_update_cmd *cmd;
2761 	struct wmi_tdls_peer_capab *peer_cap;
2762 	struct wmi_channel *chan;
2763 	struct wmi_tlv *tlv;
2764 	struct sk_buff *skb;
2765 	u32 peer_qos;
2766 	void *ptr;
2767 	int len;
2768 	int i;
2769 
2770 	len = sizeof(*tlv) + sizeof(*cmd) +
2771 	      sizeof(*tlv) + sizeof(*peer_cap) +
2772 	      sizeof(*tlv) + cap->peer_chan_len * sizeof(*chan);
2773 
2774 	skb = ath10k_wmi_alloc_skb(ar, len);
2775 	if (!skb)
2776 		return ERR_PTR(-ENOMEM);
2777 
2778 	ptr = (void *)skb->data;
2779 	tlv = ptr;
2780 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_TDLS_PEER_UPDATE_CMD);
2781 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2782 
2783 	cmd = (void *)tlv->value;
2784 	cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
2785 	ether_addr_copy(cmd->peer_macaddr.addr, arg->addr);
2786 	cmd->peer_state = __cpu_to_le32(arg->peer_state);
2787 
2788 	ptr += sizeof(*tlv);
2789 	ptr += sizeof(*cmd);
2790 
2791 	tlv = ptr;
2792 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_TDLS_PEER_CAPABILITIES);
2793 	tlv->len = __cpu_to_le16(sizeof(*peer_cap));
2794 	peer_cap = (void *)tlv->value;
2795 	peer_qos = ath10k_wmi_tlv_prepare_peer_qos(cap->peer_uapsd_queues,
2796 						   cap->peer_max_sp);
2797 	peer_cap->peer_qos = __cpu_to_le32(peer_qos);
2798 	peer_cap->buff_sta_support = __cpu_to_le32(cap->buff_sta_support);
2799 	peer_cap->off_chan_support = __cpu_to_le32(cap->off_chan_support);
2800 	peer_cap->peer_curr_operclass = __cpu_to_le32(cap->peer_curr_operclass);
2801 	peer_cap->self_curr_operclass = __cpu_to_le32(cap->self_curr_operclass);
2802 	peer_cap->peer_chan_len = __cpu_to_le32(cap->peer_chan_len);
2803 	peer_cap->peer_operclass_len = __cpu_to_le32(cap->peer_operclass_len);
2804 
2805 	for (i = 0; i < WMI_TDLS_MAX_SUPP_OPER_CLASSES; i++)
2806 		peer_cap->peer_operclass[i] = cap->peer_operclass[i];
2807 
2808 	peer_cap->is_peer_responder = __cpu_to_le32(cap->is_peer_responder);
2809 	peer_cap->pref_offchan_num = __cpu_to_le32(cap->pref_offchan_num);
2810 	peer_cap->pref_offchan_bw = __cpu_to_le32(cap->pref_offchan_bw);
2811 
2812 	ptr += sizeof(*tlv);
2813 	ptr += sizeof(*peer_cap);
2814 
2815 	tlv = ptr;
2816 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
2817 	tlv->len = __cpu_to_le16(cap->peer_chan_len * sizeof(*chan));
2818 
2819 	ptr += sizeof(*tlv);
2820 
2821 	for (i = 0; i < cap->peer_chan_len; i++) {
2822 		tlv = ptr;
2823 		tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_CHANNEL);
2824 		tlv->len = __cpu_to_le16(sizeof(*chan));
2825 		chan = (void *)tlv->value;
2826 		ath10k_wmi_put_wmi_channel(chan, &chan_arg[i]);
2827 
2828 		ptr += sizeof(*tlv);
2829 		ptr += sizeof(*chan);
2830 	}
2831 
2832 	ath10k_dbg(ar, ATH10K_DBG_WMI,
2833 		   "wmi tlv tdls peer update vdev %i state %d n_chans %u\n",
2834 		   arg->vdev_id, arg->peer_state, cap->peer_chan_len);
2835 	return skb;
2836 }
2837 
2838 static struct sk_buff *
2839 ath10k_wmi_tlv_op_gen_wow_enable(struct ath10k *ar)
2840 {
2841 	struct wmi_tlv_wow_enable_cmd *cmd;
2842 	struct wmi_tlv *tlv;
2843 	struct sk_buff *skb;
2844 	size_t len;
2845 
2846 	len = sizeof(*tlv) + sizeof(*cmd);
2847 	skb = ath10k_wmi_alloc_skb(ar, len);
2848 	if (!skb)
2849 		return ERR_PTR(-ENOMEM);
2850 
2851 	tlv = (struct wmi_tlv *)skb->data;
2852 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_ENABLE_CMD);
2853 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2854 	cmd = (void *)tlv->value;
2855 
2856 	cmd->enable = __cpu_to_le32(1);
2857 
2858 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow enable\n");
2859 	return skb;
2860 }
2861 
2862 static struct sk_buff *
2863 ath10k_wmi_tlv_op_gen_wow_add_wakeup_event(struct ath10k *ar,
2864 					   u32 vdev_id,
2865 					   enum wmi_wow_wakeup_event event,
2866 					   u32 enable)
2867 {
2868 	struct wmi_tlv_wow_add_del_event_cmd *cmd;
2869 	struct wmi_tlv *tlv;
2870 	struct sk_buff *skb;
2871 	size_t len;
2872 
2873 	len = sizeof(*tlv) + sizeof(*cmd);
2874 	skb = ath10k_wmi_alloc_skb(ar, len);
2875 	if (!skb)
2876 		return ERR_PTR(-ENOMEM);
2877 
2878 	tlv = (struct wmi_tlv *)skb->data;
2879 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_ADD_DEL_EVT_CMD);
2880 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2881 	cmd = (void *)tlv->value;
2882 
2883 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2884 	cmd->is_add = __cpu_to_le32(enable);
2885 	cmd->event_bitmap = __cpu_to_le32(1 << event);
2886 
2887 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow add wakeup event %s enable %d vdev_id %d\n",
2888 		   wow_wakeup_event(event), enable, vdev_id);
2889 	return skb;
2890 }
2891 
2892 static struct sk_buff *
2893 ath10k_wmi_tlv_gen_wow_host_wakeup_ind(struct ath10k *ar)
2894 {
2895 	struct wmi_tlv_wow_host_wakeup_ind *cmd;
2896 	struct wmi_tlv *tlv;
2897 	struct sk_buff *skb;
2898 	size_t len;
2899 
2900 	len = sizeof(*tlv) + sizeof(*cmd);
2901 	skb = ath10k_wmi_alloc_skb(ar, len);
2902 	if (!skb)
2903 		return ERR_PTR(-ENOMEM);
2904 
2905 	tlv = (struct wmi_tlv *)skb->data;
2906 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_HOSTWAKEUP_FROM_SLEEP_CMD);
2907 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2908 	cmd = (void *)tlv->value;
2909 
2910 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow host wakeup ind\n");
2911 	return skb;
2912 }
2913 
2914 static struct sk_buff *
2915 ath10k_wmi_tlv_op_gen_wow_add_pattern(struct ath10k *ar, u32 vdev_id,
2916 				      u32 pattern_id, const u8 *pattern,
2917 				      const u8 *bitmask, int pattern_len,
2918 				      int pattern_offset)
2919 {
2920 	struct wmi_tlv_wow_add_pattern_cmd *cmd;
2921 	struct wmi_tlv_wow_bitmap_pattern *bitmap;
2922 	struct wmi_tlv *tlv;
2923 	struct sk_buff *skb;
2924 	void *ptr;
2925 	size_t len;
2926 
2927 	len = sizeof(*tlv) + sizeof(*cmd) +
2928 	      sizeof(*tlv) +			/* array struct */
2929 	      sizeof(*tlv) + sizeof(*bitmap) +  /* bitmap */
2930 	      sizeof(*tlv) +			/* empty ipv4 sync */
2931 	      sizeof(*tlv) +			/* empty ipv6 sync */
2932 	      sizeof(*tlv) +			/* empty magic */
2933 	      sizeof(*tlv) +			/* empty info timeout */
2934 	      sizeof(*tlv) + sizeof(u32);	/* ratelimit interval */
2935 
2936 	skb = ath10k_wmi_alloc_skb(ar, len);
2937 	if (!skb)
2938 		return ERR_PTR(-ENOMEM);
2939 
2940 	/* cmd */
2941 	ptr = (void *)skb->data;
2942 	tlv = ptr;
2943 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_ADD_PATTERN_CMD);
2944 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2945 	cmd = (void *)tlv->value;
2946 
2947 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2948 	cmd->pattern_id = __cpu_to_le32(pattern_id);
2949 	cmd->pattern_type = __cpu_to_le32(WOW_BITMAP_PATTERN);
2950 
2951 	ptr += sizeof(*tlv);
2952 	ptr += sizeof(*cmd);
2953 
2954 	/* bitmap */
2955 	tlv = ptr;
2956 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
2957 	tlv->len = __cpu_to_le16(sizeof(*tlv) + sizeof(*bitmap));
2958 
2959 	ptr += sizeof(*tlv);
2960 
2961 	tlv = ptr;
2962 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_BITMAP_PATTERN_T);
2963 	tlv->len = __cpu_to_le16(sizeof(*bitmap));
2964 	bitmap = (void *)tlv->value;
2965 
2966 	memcpy(bitmap->patternbuf, pattern, pattern_len);
2967 	memcpy(bitmap->bitmaskbuf, bitmask, pattern_len);
2968 	bitmap->pattern_offset = __cpu_to_le32(pattern_offset);
2969 	bitmap->pattern_len = __cpu_to_le32(pattern_len);
2970 	bitmap->bitmask_len = __cpu_to_le32(pattern_len);
2971 	bitmap->pattern_id = __cpu_to_le32(pattern_id);
2972 
2973 	ptr += sizeof(*tlv);
2974 	ptr += sizeof(*bitmap);
2975 
2976 	/* ipv4 sync */
2977 	tlv = ptr;
2978 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
2979 	tlv->len = __cpu_to_le16(0);
2980 
2981 	ptr += sizeof(*tlv);
2982 
2983 	/* ipv6 sync */
2984 	tlv = ptr;
2985 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
2986 	tlv->len = __cpu_to_le16(0);
2987 
2988 	ptr += sizeof(*tlv);
2989 
2990 	/* magic */
2991 	tlv = ptr;
2992 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
2993 	tlv->len = __cpu_to_le16(0);
2994 
2995 	ptr += sizeof(*tlv);
2996 
2997 	/* pattern info timeout */
2998 	tlv = ptr;
2999 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
3000 	tlv->len = __cpu_to_le16(0);
3001 
3002 	ptr += sizeof(*tlv);
3003 
3004 	/* ratelimit interval */
3005 	tlv = ptr;
3006 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
3007 	tlv->len = __cpu_to_le16(sizeof(u32));
3008 
3009 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow add pattern vdev_id %d pattern_id %d, pattern_offset %d\n",
3010 		   vdev_id, pattern_id, pattern_offset);
3011 	return skb;
3012 }
3013 
3014 static struct sk_buff *
3015 ath10k_wmi_tlv_op_gen_wow_del_pattern(struct ath10k *ar, u32 vdev_id,
3016 				      u32 pattern_id)
3017 {
3018 	struct wmi_tlv_wow_del_pattern_cmd *cmd;
3019 	struct wmi_tlv *tlv;
3020 	struct sk_buff *skb;
3021 	size_t len;
3022 
3023 	len = sizeof(*tlv) + sizeof(*cmd);
3024 	skb = ath10k_wmi_alloc_skb(ar, len);
3025 	if (!skb)
3026 		return ERR_PTR(-ENOMEM);
3027 
3028 	tlv = (struct wmi_tlv *)skb->data;
3029 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_DEL_PATTERN_CMD);
3030 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3031 	cmd = (void *)tlv->value;
3032 
3033 	cmd->vdev_id = __cpu_to_le32(vdev_id);
3034 	cmd->pattern_id = __cpu_to_le32(pattern_id);
3035 	cmd->pattern_type = __cpu_to_le32(WOW_BITMAP_PATTERN);
3036 
3037 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow del pattern vdev_id %d pattern_id %d\n",
3038 		   vdev_id, pattern_id);
3039 	return skb;
3040 }
3041 
3042 static struct sk_buff *
3043 ath10k_wmi_tlv_op_gen_adaptive_qcs(struct ath10k *ar, bool enable)
3044 {
3045 	struct wmi_tlv_adaptive_qcs *cmd;
3046 	struct wmi_tlv *tlv;
3047 	struct sk_buff *skb;
3048 	void *ptr;
3049 	size_t len;
3050 
3051 	len = sizeof(*tlv) + sizeof(*cmd);
3052 	skb = ath10k_wmi_alloc_skb(ar, len);
3053 	if (!skb)
3054 		return ERR_PTR(-ENOMEM);
3055 
3056 	ptr = (void *)skb->data;
3057 	tlv = ptr;
3058 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_RESMGR_ADAPTIVE_OCS_CMD);
3059 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3060 	cmd = (void *)tlv->value;
3061 	cmd->enable = __cpu_to_le32(enable ? 1 : 0);
3062 
3063 	ptr += sizeof(*tlv);
3064 	ptr += sizeof(*cmd);
3065 
3066 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv adaptive qcs %d\n", enable);
3067 	return skb;
3068 }
3069 
3070 /****************/
3071 /* TLV mappings */
3072 /****************/
3073 
3074 static struct wmi_cmd_map wmi_tlv_cmd_map = {
3075 	.init_cmdid = WMI_TLV_INIT_CMDID,
3076 	.start_scan_cmdid = WMI_TLV_START_SCAN_CMDID,
3077 	.stop_scan_cmdid = WMI_TLV_STOP_SCAN_CMDID,
3078 	.scan_chan_list_cmdid = WMI_TLV_SCAN_CHAN_LIST_CMDID,
3079 	.scan_sch_prio_tbl_cmdid = WMI_TLV_SCAN_SCH_PRIO_TBL_CMDID,
3080 	.pdev_set_regdomain_cmdid = WMI_TLV_PDEV_SET_REGDOMAIN_CMDID,
3081 	.pdev_set_channel_cmdid = WMI_TLV_PDEV_SET_CHANNEL_CMDID,
3082 	.pdev_set_param_cmdid = WMI_TLV_PDEV_SET_PARAM_CMDID,
3083 	.pdev_pktlog_enable_cmdid = WMI_TLV_PDEV_PKTLOG_ENABLE_CMDID,
3084 	.pdev_pktlog_disable_cmdid = WMI_TLV_PDEV_PKTLOG_DISABLE_CMDID,
3085 	.pdev_set_wmm_params_cmdid = WMI_TLV_PDEV_SET_WMM_PARAMS_CMDID,
3086 	.pdev_set_ht_cap_ie_cmdid = WMI_TLV_PDEV_SET_HT_CAP_IE_CMDID,
3087 	.pdev_set_vht_cap_ie_cmdid = WMI_TLV_PDEV_SET_VHT_CAP_IE_CMDID,
3088 	.pdev_set_dscp_tid_map_cmdid = WMI_TLV_PDEV_SET_DSCP_TID_MAP_CMDID,
3089 	.pdev_set_quiet_mode_cmdid = WMI_TLV_PDEV_SET_QUIET_MODE_CMDID,
3090 	.pdev_green_ap_ps_enable_cmdid = WMI_TLV_PDEV_GREEN_AP_PS_ENABLE_CMDID,
3091 	.pdev_get_tpc_config_cmdid = WMI_TLV_PDEV_GET_TPC_CONFIG_CMDID,
3092 	.pdev_set_base_macaddr_cmdid = WMI_TLV_PDEV_SET_BASE_MACADDR_CMDID,
3093 	.vdev_create_cmdid = WMI_TLV_VDEV_CREATE_CMDID,
3094 	.vdev_delete_cmdid = WMI_TLV_VDEV_DELETE_CMDID,
3095 	.vdev_start_request_cmdid = WMI_TLV_VDEV_START_REQUEST_CMDID,
3096 	.vdev_restart_request_cmdid = WMI_TLV_VDEV_RESTART_REQUEST_CMDID,
3097 	.vdev_up_cmdid = WMI_TLV_VDEV_UP_CMDID,
3098 	.vdev_stop_cmdid = WMI_TLV_VDEV_STOP_CMDID,
3099 	.vdev_down_cmdid = WMI_TLV_VDEV_DOWN_CMDID,
3100 	.vdev_set_param_cmdid = WMI_TLV_VDEV_SET_PARAM_CMDID,
3101 	.vdev_install_key_cmdid = WMI_TLV_VDEV_INSTALL_KEY_CMDID,
3102 	.peer_create_cmdid = WMI_TLV_PEER_CREATE_CMDID,
3103 	.peer_delete_cmdid = WMI_TLV_PEER_DELETE_CMDID,
3104 	.peer_flush_tids_cmdid = WMI_TLV_PEER_FLUSH_TIDS_CMDID,
3105 	.peer_set_param_cmdid = WMI_TLV_PEER_SET_PARAM_CMDID,
3106 	.peer_assoc_cmdid = WMI_TLV_PEER_ASSOC_CMDID,
3107 	.peer_add_wds_entry_cmdid = WMI_TLV_PEER_ADD_WDS_ENTRY_CMDID,
3108 	.peer_remove_wds_entry_cmdid = WMI_TLV_PEER_REMOVE_WDS_ENTRY_CMDID,
3109 	.peer_mcast_group_cmdid = WMI_TLV_PEER_MCAST_GROUP_CMDID,
3110 	.bcn_tx_cmdid = WMI_TLV_BCN_TX_CMDID,
3111 	.pdev_send_bcn_cmdid = WMI_TLV_PDEV_SEND_BCN_CMDID,
3112 	.bcn_tmpl_cmdid = WMI_TLV_BCN_TMPL_CMDID,
3113 	.bcn_filter_rx_cmdid = WMI_TLV_BCN_FILTER_RX_CMDID,
3114 	.prb_req_filter_rx_cmdid = WMI_TLV_PRB_REQ_FILTER_RX_CMDID,
3115 	.mgmt_tx_cmdid = WMI_TLV_MGMT_TX_CMDID,
3116 	.prb_tmpl_cmdid = WMI_TLV_PRB_TMPL_CMDID,
3117 	.addba_clear_resp_cmdid = WMI_TLV_ADDBA_CLEAR_RESP_CMDID,
3118 	.addba_send_cmdid = WMI_TLV_ADDBA_SEND_CMDID,
3119 	.addba_status_cmdid = WMI_TLV_ADDBA_STATUS_CMDID,
3120 	.delba_send_cmdid = WMI_TLV_DELBA_SEND_CMDID,
3121 	.addba_set_resp_cmdid = WMI_TLV_ADDBA_SET_RESP_CMDID,
3122 	.send_singleamsdu_cmdid = WMI_TLV_SEND_SINGLEAMSDU_CMDID,
3123 	.sta_powersave_mode_cmdid = WMI_TLV_STA_POWERSAVE_MODE_CMDID,
3124 	.sta_powersave_param_cmdid = WMI_TLV_STA_POWERSAVE_PARAM_CMDID,
3125 	.sta_mimo_ps_mode_cmdid = WMI_TLV_STA_MIMO_PS_MODE_CMDID,
3126 	.pdev_dfs_enable_cmdid = WMI_TLV_PDEV_DFS_ENABLE_CMDID,
3127 	.pdev_dfs_disable_cmdid = WMI_TLV_PDEV_DFS_DISABLE_CMDID,
3128 	.roam_scan_mode = WMI_TLV_ROAM_SCAN_MODE,
3129 	.roam_scan_rssi_threshold = WMI_TLV_ROAM_SCAN_RSSI_THRESHOLD,
3130 	.roam_scan_period = WMI_TLV_ROAM_SCAN_PERIOD,
3131 	.roam_scan_rssi_change_threshold =
3132 				WMI_TLV_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
3133 	.roam_ap_profile = WMI_TLV_ROAM_AP_PROFILE,
3134 	.ofl_scan_add_ap_profile = WMI_TLV_ROAM_AP_PROFILE,
3135 	.ofl_scan_remove_ap_profile = WMI_TLV_OFL_SCAN_REMOVE_AP_PROFILE,
3136 	.ofl_scan_period = WMI_TLV_OFL_SCAN_PERIOD,
3137 	.p2p_dev_set_device_info = WMI_TLV_P2P_DEV_SET_DEVICE_INFO,
3138 	.p2p_dev_set_discoverability = WMI_TLV_P2P_DEV_SET_DISCOVERABILITY,
3139 	.p2p_go_set_beacon_ie = WMI_TLV_P2P_GO_SET_BEACON_IE,
3140 	.p2p_go_set_probe_resp_ie = WMI_TLV_P2P_GO_SET_PROBE_RESP_IE,
3141 	.p2p_set_vendor_ie_data_cmdid = WMI_TLV_P2P_SET_VENDOR_IE_DATA_CMDID,
3142 	.ap_ps_peer_param_cmdid = WMI_TLV_AP_PS_PEER_PARAM_CMDID,
3143 	.ap_ps_peer_uapsd_coex_cmdid = WMI_TLV_AP_PS_PEER_UAPSD_COEX_CMDID,
3144 	.peer_rate_retry_sched_cmdid = WMI_TLV_PEER_RATE_RETRY_SCHED_CMDID,
3145 	.wlan_profile_trigger_cmdid = WMI_TLV_WLAN_PROFILE_TRIGGER_CMDID,
3146 	.wlan_profile_set_hist_intvl_cmdid =
3147 				WMI_TLV_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
3148 	.wlan_profile_get_profile_data_cmdid =
3149 				WMI_TLV_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
3150 	.wlan_profile_enable_profile_id_cmdid =
3151 				WMI_TLV_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
3152 	.wlan_profile_list_profile_id_cmdid =
3153 				WMI_TLV_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
3154 	.pdev_suspend_cmdid = WMI_TLV_PDEV_SUSPEND_CMDID,
3155 	.pdev_resume_cmdid = WMI_TLV_PDEV_RESUME_CMDID,
3156 	.add_bcn_filter_cmdid = WMI_TLV_ADD_BCN_FILTER_CMDID,
3157 	.rmv_bcn_filter_cmdid = WMI_TLV_RMV_BCN_FILTER_CMDID,
3158 	.wow_add_wake_pattern_cmdid = WMI_TLV_WOW_ADD_WAKE_PATTERN_CMDID,
3159 	.wow_del_wake_pattern_cmdid = WMI_TLV_WOW_DEL_WAKE_PATTERN_CMDID,
3160 	.wow_enable_disable_wake_event_cmdid =
3161 				WMI_TLV_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
3162 	.wow_enable_cmdid = WMI_TLV_WOW_ENABLE_CMDID,
3163 	.wow_hostwakeup_from_sleep_cmdid =
3164 				WMI_TLV_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
3165 	.rtt_measreq_cmdid = WMI_TLV_RTT_MEASREQ_CMDID,
3166 	.rtt_tsf_cmdid = WMI_TLV_RTT_TSF_CMDID,
3167 	.vdev_spectral_scan_configure_cmdid = WMI_TLV_SPECTRAL_SCAN_CONF_CMDID,
3168 	.vdev_spectral_scan_enable_cmdid = WMI_TLV_SPECTRAL_SCAN_ENABLE_CMDID,
3169 	.request_stats_cmdid = WMI_TLV_REQUEST_STATS_CMDID,
3170 	.set_arp_ns_offload_cmdid = WMI_TLV_SET_ARP_NS_OFFLOAD_CMDID,
3171 	.network_list_offload_config_cmdid =
3172 				WMI_TLV_NETWORK_LIST_OFFLOAD_CONFIG_CMDID,
3173 	.gtk_offload_cmdid = WMI_TLV_GTK_OFFLOAD_CMDID,
3174 	.csa_offload_enable_cmdid = WMI_TLV_CSA_OFFLOAD_ENABLE_CMDID,
3175 	.csa_offload_chanswitch_cmdid = WMI_TLV_CSA_OFFLOAD_CHANSWITCH_CMDID,
3176 	.chatter_set_mode_cmdid = WMI_TLV_CHATTER_SET_MODE_CMDID,
3177 	.peer_tid_addba_cmdid = WMI_TLV_PEER_TID_ADDBA_CMDID,
3178 	.peer_tid_delba_cmdid = WMI_TLV_PEER_TID_DELBA_CMDID,
3179 	.sta_dtim_ps_method_cmdid = WMI_TLV_STA_DTIM_PS_METHOD_CMDID,
3180 	.sta_uapsd_auto_trig_cmdid = WMI_TLV_STA_UAPSD_AUTO_TRIG_CMDID,
3181 	.sta_keepalive_cmd = WMI_TLV_STA_KEEPALIVE_CMDID,
3182 	.echo_cmdid = WMI_TLV_ECHO_CMDID,
3183 	.pdev_utf_cmdid = WMI_TLV_PDEV_UTF_CMDID,
3184 	.dbglog_cfg_cmdid = WMI_TLV_DBGLOG_CFG_CMDID,
3185 	.pdev_qvit_cmdid = WMI_TLV_PDEV_QVIT_CMDID,
3186 	.pdev_ftm_intg_cmdid = WMI_TLV_PDEV_FTM_INTG_CMDID,
3187 	.vdev_set_keepalive_cmdid = WMI_TLV_VDEV_SET_KEEPALIVE_CMDID,
3188 	.vdev_get_keepalive_cmdid = WMI_TLV_VDEV_GET_KEEPALIVE_CMDID,
3189 	.force_fw_hang_cmdid = WMI_TLV_FORCE_FW_HANG_CMDID,
3190 	.gpio_config_cmdid = WMI_TLV_GPIO_CONFIG_CMDID,
3191 	.gpio_output_cmdid = WMI_TLV_GPIO_OUTPUT_CMDID,
3192 	.pdev_get_temperature_cmdid = WMI_TLV_CMD_UNSUPPORTED,
3193 	.vdev_set_wmm_params_cmdid = WMI_TLV_VDEV_SET_WMM_PARAMS_CMDID,
3194 	.tdls_set_state_cmdid = WMI_TLV_TDLS_SET_STATE_CMDID,
3195 	.tdls_peer_update_cmdid = WMI_TLV_TDLS_PEER_UPDATE_CMDID,
3196 	.adaptive_qcs_cmdid = WMI_TLV_RESMGR_ADAPTIVE_OCS_CMDID,
3197 	.scan_update_request_cmdid = WMI_CMD_UNSUPPORTED,
3198 	.vdev_standby_response_cmdid = WMI_CMD_UNSUPPORTED,
3199 	.vdev_resume_response_cmdid = WMI_CMD_UNSUPPORTED,
3200 	.wlan_peer_caching_add_peer_cmdid = WMI_CMD_UNSUPPORTED,
3201 	.wlan_peer_caching_evict_peer_cmdid = WMI_CMD_UNSUPPORTED,
3202 	.wlan_peer_caching_restore_peer_cmdid = WMI_CMD_UNSUPPORTED,
3203 	.wlan_peer_caching_print_all_peers_info_cmdid = WMI_CMD_UNSUPPORTED,
3204 	.peer_update_wds_entry_cmdid = WMI_CMD_UNSUPPORTED,
3205 	.peer_add_proxy_sta_entry_cmdid = WMI_CMD_UNSUPPORTED,
3206 	.rtt_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
3207 	.oem_req_cmdid = WMI_CMD_UNSUPPORTED,
3208 	.nan_cmdid = WMI_CMD_UNSUPPORTED,
3209 	.vdev_ratemask_cmdid = WMI_CMD_UNSUPPORTED,
3210 	.qboost_cfg_cmdid = WMI_CMD_UNSUPPORTED,
3211 	.pdev_smart_ant_enable_cmdid = WMI_CMD_UNSUPPORTED,
3212 	.pdev_smart_ant_set_rx_antenna_cmdid = WMI_CMD_UNSUPPORTED,
3213 	.peer_smart_ant_set_tx_antenna_cmdid = WMI_CMD_UNSUPPORTED,
3214 	.peer_smart_ant_set_train_info_cmdid = WMI_CMD_UNSUPPORTED,
3215 	.peer_smart_ant_set_node_config_ops_cmdid = WMI_CMD_UNSUPPORTED,
3216 	.pdev_set_antenna_switch_table_cmdid = WMI_CMD_UNSUPPORTED,
3217 	.pdev_set_ctl_table_cmdid = WMI_CMD_UNSUPPORTED,
3218 	.pdev_set_mimogain_table_cmdid = WMI_CMD_UNSUPPORTED,
3219 	.pdev_ratepwr_table_cmdid = WMI_CMD_UNSUPPORTED,
3220 	.pdev_ratepwr_chainmsk_table_cmdid = WMI_CMD_UNSUPPORTED,
3221 	.pdev_fips_cmdid = WMI_CMD_UNSUPPORTED,
3222 	.tt_set_conf_cmdid = WMI_CMD_UNSUPPORTED,
3223 	.fwtest_cmdid = WMI_CMD_UNSUPPORTED,
3224 	.vdev_atf_request_cmdid = WMI_CMD_UNSUPPORTED,
3225 	.peer_atf_request_cmdid = WMI_CMD_UNSUPPORTED,
3226 	.pdev_get_ani_cck_config_cmdid = WMI_CMD_UNSUPPORTED,
3227 	.pdev_get_ani_ofdm_config_cmdid = WMI_CMD_UNSUPPORTED,
3228 	.pdev_reserve_ast_entry_cmdid = WMI_CMD_UNSUPPORTED,
3229 };
3230 
3231 static struct wmi_pdev_param_map wmi_tlv_pdev_param_map = {
3232 	.tx_chain_mask = WMI_TLV_PDEV_PARAM_TX_CHAIN_MASK,
3233 	.rx_chain_mask = WMI_TLV_PDEV_PARAM_RX_CHAIN_MASK,
3234 	.txpower_limit2g = WMI_TLV_PDEV_PARAM_TXPOWER_LIMIT2G,
3235 	.txpower_limit5g = WMI_TLV_PDEV_PARAM_TXPOWER_LIMIT5G,
3236 	.txpower_scale = WMI_TLV_PDEV_PARAM_TXPOWER_SCALE,
3237 	.beacon_gen_mode = WMI_TLV_PDEV_PARAM_BEACON_GEN_MODE,
3238 	.beacon_tx_mode = WMI_TLV_PDEV_PARAM_BEACON_TX_MODE,
3239 	.resmgr_offchan_mode = WMI_TLV_PDEV_PARAM_RESMGR_OFFCHAN_MODE,
3240 	.protection_mode = WMI_TLV_PDEV_PARAM_PROTECTION_MODE,
3241 	.dynamic_bw = WMI_TLV_PDEV_PARAM_DYNAMIC_BW,
3242 	.non_agg_sw_retry_th = WMI_TLV_PDEV_PARAM_NON_AGG_SW_RETRY_TH,
3243 	.agg_sw_retry_th = WMI_TLV_PDEV_PARAM_AGG_SW_RETRY_TH,
3244 	.sta_kickout_th = WMI_TLV_PDEV_PARAM_STA_KICKOUT_TH,
3245 	.ac_aggrsize_scaling = WMI_TLV_PDEV_PARAM_AC_AGGRSIZE_SCALING,
3246 	.ltr_enable = WMI_TLV_PDEV_PARAM_LTR_ENABLE,
3247 	.ltr_ac_latency_be = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_BE,
3248 	.ltr_ac_latency_bk = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_BK,
3249 	.ltr_ac_latency_vi = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_VI,
3250 	.ltr_ac_latency_vo = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_VO,
3251 	.ltr_ac_latency_timeout = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_TIMEOUT,
3252 	.ltr_sleep_override = WMI_TLV_PDEV_PARAM_LTR_SLEEP_OVERRIDE,
3253 	.ltr_rx_override = WMI_TLV_PDEV_PARAM_LTR_RX_OVERRIDE,
3254 	.ltr_tx_activity_timeout = WMI_TLV_PDEV_PARAM_LTR_TX_ACTIVITY_TIMEOUT,
3255 	.l1ss_enable = WMI_TLV_PDEV_PARAM_L1SS_ENABLE,
3256 	.dsleep_enable = WMI_TLV_PDEV_PARAM_DSLEEP_ENABLE,
3257 	.pcielp_txbuf_flush = WMI_TLV_PDEV_PARAM_PCIELP_TXBUF_FLUSH,
3258 	.pcielp_txbuf_watermark = WMI_TLV_PDEV_PARAM_PCIELP_TXBUF_TMO_EN,
3259 	.pcielp_txbuf_tmo_en = WMI_TLV_PDEV_PARAM_PCIELP_TXBUF_TMO_EN,
3260 	.pcielp_txbuf_tmo_value = WMI_TLV_PDEV_PARAM_PCIELP_TXBUF_TMO_VALUE,
3261 	.pdev_stats_update_period = WMI_TLV_PDEV_PARAM_PDEV_STATS_UPDATE_PERIOD,
3262 	.vdev_stats_update_period = WMI_TLV_PDEV_PARAM_VDEV_STATS_UPDATE_PERIOD,
3263 	.peer_stats_update_period = WMI_TLV_PDEV_PARAM_PEER_STATS_UPDATE_PERIOD,
3264 	.bcnflt_stats_update_period =
3265 				WMI_TLV_PDEV_PARAM_BCNFLT_STATS_UPDATE_PERIOD,
3266 	.pmf_qos = WMI_TLV_PDEV_PARAM_PMF_QOS,
3267 	.arp_ac_override = WMI_TLV_PDEV_PARAM_ARP_AC_OVERRIDE,
3268 	.dcs = WMI_TLV_PDEV_PARAM_DCS,
3269 	.ani_enable = WMI_TLV_PDEV_PARAM_ANI_ENABLE,
3270 	.ani_poll_period = WMI_TLV_PDEV_PARAM_ANI_POLL_PERIOD,
3271 	.ani_listen_period = WMI_TLV_PDEV_PARAM_ANI_LISTEN_PERIOD,
3272 	.ani_ofdm_level = WMI_TLV_PDEV_PARAM_ANI_OFDM_LEVEL,
3273 	.ani_cck_level = WMI_TLV_PDEV_PARAM_ANI_CCK_LEVEL,
3274 	.dyntxchain = WMI_TLV_PDEV_PARAM_DYNTXCHAIN,
3275 	.proxy_sta = WMI_TLV_PDEV_PARAM_PROXY_STA,
3276 	.idle_ps_config = WMI_TLV_PDEV_PARAM_IDLE_PS_CONFIG,
3277 	.power_gating_sleep = WMI_TLV_PDEV_PARAM_POWER_GATING_SLEEP,
3278 	.fast_channel_reset = WMI_TLV_PDEV_PARAM_UNSUPPORTED,
3279 	.burst_dur = WMI_TLV_PDEV_PARAM_BURST_DUR,
3280 	.burst_enable = WMI_TLV_PDEV_PARAM_BURST_ENABLE,
3281 	.cal_period = WMI_PDEV_PARAM_UNSUPPORTED,
3282 	.aggr_burst = WMI_PDEV_PARAM_UNSUPPORTED,
3283 	.rx_decap_mode = WMI_PDEV_PARAM_UNSUPPORTED,
3284 	.smart_antenna_default_antenna = WMI_PDEV_PARAM_UNSUPPORTED,
3285 	.igmpmld_override = WMI_PDEV_PARAM_UNSUPPORTED,
3286 	.igmpmld_tid = WMI_PDEV_PARAM_UNSUPPORTED,
3287 	.antenna_gain = WMI_PDEV_PARAM_UNSUPPORTED,
3288 	.rx_filter = WMI_PDEV_PARAM_UNSUPPORTED,
3289 	.set_mcast_to_ucast_tid = WMI_PDEV_PARAM_UNSUPPORTED,
3290 	.proxy_sta_mode = WMI_PDEV_PARAM_UNSUPPORTED,
3291 	.set_mcast2ucast_mode = WMI_PDEV_PARAM_UNSUPPORTED,
3292 	.set_mcast2ucast_buffer = WMI_PDEV_PARAM_UNSUPPORTED,
3293 	.remove_mcast2ucast_buffer = WMI_PDEV_PARAM_UNSUPPORTED,
3294 	.peer_sta_ps_statechg_enable = WMI_PDEV_PARAM_UNSUPPORTED,
3295 	.igmpmld_ac_override = WMI_PDEV_PARAM_UNSUPPORTED,
3296 	.block_interbss = WMI_PDEV_PARAM_UNSUPPORTED,
3297 	.set_disable_reset_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
3298 	.set_msdu_ttl_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
3299 	.set_ppdu_duration_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
3300 	.txbf_sound_period_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
3301 	.set_promisc_mode_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
3302 	.set_burst_mode_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
3303 	.en_stats = WMI_PDEV_PARAM_UNSUPPORTED,
3304 	.mu_group_policy = WMI_PDEV_PARAM_UNSUPPORTED,
3305 	.noise_detection = WMI_PDEV_PARAM_UNSUPPORTED,
3306 	.noise_threshold = WMI_PDEV_PARAM_UNSUPPORTED,
3307 	.dpd_enable = WMI_PDEV_PARAM_UNSUPPORTED,
3308 	.set_mcast_bcast_echo = WMI_PDEV_PARAM_UNSUPPORTED,
3309 	.atf_strict_sch = WMI_PDEV_PARAM_UNSUPPORTED,
3310 	.atf_sched_duration = WMI_PDEV_PARAM_UNSUPPORTED,
3311 	.ant_plzn = WMI_PDEV_PARAM_UNSUPPORTED,
3312 	.mgmt_retry_limit = WMI_PDEV_PARAM_UNSUPPORTED,
3313 	.sensitivity_level = WMI_PDEV_PARAM_UNSUPPORTED,
3314 	.signed_txpower_2g = WMI_PDEV_PARAM_UNSUPPORTED,
3315 	.signed_txpower_5g = WMI_PDEV_PARAM_UNSUPPORTED,
3316 	.enable_per_tid_amsdu = WMI_PDEV_PARAM_UNSUPPORTED,
3317 	.enable_per_tid_ampdu = WMI_PDEV_PARAM_UNSUPPORTED,
3318 	.cca_threshold = WMI_PDEV_PARAM_UNSUPPORTED,
3319 	.rts_fixed_rate = WMI_PDEV_PARAM_UNSUPPORTED,
3320 	.pdev_reset = WMI_PDEV_PARAM_UNSUPPORTED,
3321 	.wapi_mbssid_offset = WMI_PDEV_PARAM_UNSUPPORTED,
3322 	.arp_srcaddr = WMI_PDEV_PARAM_UNSUPPORTED,
3323 	.arp_dstaddr = WMI_PDEV_PARAM_UNSUPPORTED,
3324 };
3325 
3326 static struct wmi_vdev_param_map wmi_tlv_vdev_param_map = {
3327 	.rts_threshold = WMI_TLV_VDEV_PARAM_RTS_THRESHOLD,
3328 	.fragmentation_threshold = WMI_TLV_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
3329 	.beacon_interval = WMI_TLV_VDEV_PARAM_BEACON_INTERVAL,
3330 	.listen_interval = WMI_TLV_VDEV_PARAM_LISTEN_INTERVAL,
3331 	.multicast_rate = WMI_TLV_VDEV_PARAM_MULTICAST_RATE,
3332 	.mgmt_tx_rate = WMI_TLV_VDEV_PARAM_MGMT_TX_RATE,
3333 	.slot_time = WMI_TLV_VDEV_PARAM_SLOT_TIME,
3334 	.preamble = WMI_TLV_VDEV_PARAM_PREAMBLE,
3335 	.swba_time = WMI_TLV_VDEV_PARAM_SWBA_TIME,
3336 	.wmi_vdev_stats_update_period = WMI_TLV_VDEV_STATS_UPDATE_PERIOD,
3337 	.wmi_vdev_pwrsave_ageout_time = WMI_TLV_VDEV_PWRSAVE_AGEOUT_TIME,
3338 	.wmi_vdev_host_swba_interval = WMI_TLV_VDEV_HOST_SWBA_INTERVAL,
3339 	.dtim_period = WMI_TLV_VDEV_PARAM_DTIM_PERIOD,
3340 	.wmi_vdev_oc_scheduler_air_time_limit =
3341 				WMI_TLV_VDEV_OC_SCHEDULER_AIR_TIME_LIMIT,
3342 	.wds = WMI_TLV_VDEV_PARAM_WDS,
3343 	.atim_window = WMI_TLV_VDEV_PARAM_ATIM_WINDOW,
3344 	.bmiss_count_max = WMI_TLV_VDEV_PARAM_BMISS_COUNT_MAX,
3345 	.bmiss_first_bcnt = WMI_TLV_VDEV_PARAM_BMISS_FIRST_BCNT,
3346 	.bmiss_final_bcnt = WMI_TLV_VDEV_PARAM_BMISS_FINAL_BCNT,
3347 	.feature_wmm = WMI_TLV_VDEV_PARAM_FEATURE_WMM,
3348 	.chwidth = WMI_TLV_VDEV_PARAM_CHWIDTH,
3349 	.chextoffset = WMI_TLV_VDEV_PARAM_CHEXTOFFSET,
3350 	.disable_htprotection =	WMI_TLV_VDEV_PARAM_DISABLE_HTPROTECTION,
3351 	.sta_quickkickout = WMI_TLV_VDEV_PARAM_STA_QUICKKICKOUT,
3352 	.mgmt_rate = WMI_TLV_VDEV_PARAM_MGMT_RATE,
3353 	.protection_mode = WMI_TLV_VDEV_PARAM_PROTECTION_MODE,
3354 	.fixed_rate = WMI_TLV_VDEV_PARAM_FIXED_RATE,
3355 	.sgi = WMI_TLV_VDEV_PARAM_SGI,
3356 	.ldpc = WMI_TLV_VDEV_PARAM_LDPC,
3357 	.tx_stbc = WMI_TLV_VDEV_PARAM_TX_STBC,
3358 	.rx_stbc = WMI_TLV_VDEV_PARAM_RX_STBC,
3359 	.intra_bss_fwd = WMI_TLV_VDEV_PARAM_INTRA_BSS_FWD,
3360 	.def_keyid = WMI_TLV_VDEV_PARAM_DEF_KEYID,
3361 	.nss = WMI_TLV_VDEV_PARAM_NSS,
3362 	.bcast_data_rate = WMI_TLV_VDEV_PARAM_BCAST_DATA_RATE,
3363 	.mcast_data_rate = WMI_TLV_VDEV_PARAM_MCAST_DATA_RATE,
3364 	.mcast_indicate = WMI_TLV_VDEV_PARAM_MCAST_INDICATE,
3365 	.dhcp_indicate = WMI_TLV_VDEV_PARAM_DHCP_INDICATE,
3366 	.unknown_dest_indicate = WMI_TLV_VDEV_PARAM_UNKNOWN_DEST_INDICATE,
3367 	.ap_keepalive_min_idle_inactive_time_secs =
3368 		WMI_TLV_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS,
3369 	.ap_keepalive_max_idle_inactive_time_secs =
3370 		WMI_TLV_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS,
3371 	.ap_keepalive_max_unresponsive_time_secs =
3372 		WMI_TLV_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS,
3373 	.ap_enable_nawds = WMI_TLV_VDEV_PARAM_AP_ENABLE_NAWDS,
3374 	.mcast2ucast_set = WMI_TLV_VDEV_PARAM_UNSUPPORTED,
3375 	.enable_rtscts = WMI_TLV_VDEV_PARAM_ENABLE_RTSCTS,
3376 	.txbf = WMI_TLV_VDEV_PARAM_TXBF,
3377 	.packet_powersave = WMI_TLV_VDEV_PARAM_PACKET_POWERSAVE,
3378 	.drop_unencry = WMI_TLV_VDEV_PARAM_DROP_UNENCRY,
3379 	.tx_encap_type = WMI_TLV_VDEV_PARAM_TX_ENCAP_TYPE,
3380 	.ap_detect_out_of_sync_sleeping_sta_time_secs =
3381 					WMI_TLV_VDEV_PARAM_UNSUPPORTED,
3382 	.rc_num_retries = WMI_VDEV_PARAM_UNSUPPORTED,
3383 	.cabq_maxdur = WMI_VDEV_PARAM_UNSUPPORTED,
3384 	.mfptest_set = WMI_VDEV_PARAM_UNSUPPORTED,
3385 	.rts_fixed_rate = WMI_VDEV_PARAM_UNSUPPORTED,
3386 	.vht_sgimask = WMI_VDEV_PARAM_UNSUPPORTED,
3387 	.vht80_ratemask = WMI_VDEV_PARAM_UNSUPPORTED,
3388 	.early_rx_adjust_enable = WMI_VDEV_PARAM_UNSUPPORTED,
3389 	.early_rx_tgt_bmiss_num = WMI_VDEV_PARAM_UNSUPPORTED,
3390 	.early_rx_bmiss_sample_cycle = WMI_VDEV_PARAM_UNSUPPORTED,
3391 	.early_rx_slop_step = WMI_VDEV_PARAM_UNSUPPORTED,
3392 	.early_rx_init_slop = WMI_VDEV_PARAM_UNSUPPORTED,
3393 	.early_rx_adjust_pause = WMI_VDEV_PARAM_UNSUPPORTED,
3394 	.proxy_sta = WMI_VDEV_PARAM_UNSUPPORTED,
3395 	.meru_vc = WMI_VDEV_PARAM_UNSUPPORTED,
3396 	.rx_decap_type = WMI_VDEV_PARAM_UNSUPPORTED,
3397 	.bw_nss_ratemask = WMI_VDEV_PARAM_UNSUPPORTED,
3398 };
3399 
3400 static const struct wmi_ops wmi_tlv_ops = {
3401 	.rx = ath10k_wmi_tlv_op_rx,
3402 	.map_svc = wmi_tlv_svc_map,
3403 
3404 	.pull_scan = ath10k_wmi_tlv_op_pull_scan_ev,
3405 	.pull_mgmt_rx = ath10k_wmi_tlv_op_pull_mgmt_rx_ev,
3406 	.pull_ch_info = ath10k_wmi_tlv_op_pull_ch_info_ev,
3407 	.pull_vdev_start = ath10k_wmi_tlv_op_pull_vdev_start_ev,
3408 	.pull_peer_kick = ath10k_wmi_tlv_op_pull_peer_kick_ev,
3409 	.pull_swba = ath10k_wmi_tlv_op_pull_swba_ev,
3410 	.pull_phyerr_hdr = ath10k_wmi_tlv_op_pull_phyerr_ev_hdr,
3411 	.pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
3412 	.pull_svc_rdy = ath10k_wmi_tlv_op_pull_svc_rdy_ev,
3413 	.pull_rdy = ath10k_wmi_tlv_op_pull_rdy_ev,
3414 	.pull_fw_stats = ath10k_wmi_tlv_op_pull_fw_stats,
3415 	.pull_roam_ev = ath10k_wmi_tlv_op_pull_roam_ev,
3416 	.pull_wow_event = ath10k_wmi_tlv_op_pull_wow_ev,
3417 	.get_txbf_conf_scheme = ath10k_wmi_tlv_txbf_conf_scheme,
3418 
3419 	.gen_pdev_suspend = ath10k_wmi_tlv_op_gen_pdev_suspend,
3420 	.gen_pdev_resume = ath10k_wmi_tlv_op_gen_pdev_resume,
3421 	.gen_pdev_set_rd = ath10k_wmi_tlv_op_gen_pdev_set_rd,
3422 	.gen_pdev_set_param = ath10k_wmi_tlv_op_gen_pdev_set_param,
3423 	.gen_init = ath10k_wmi_tlv_op_gen_init,
3424 	.gen_start_scan = ath10k_wmi_tlv_op_gen_start_scan,
3425 	.gen_stop_scan = ath10k_wmi_tlv_op_gen_stop_scan,
3426 	.gen_vdev_create = ath10k_wmi_tlv_op_gen_vdev_create,
3427 	.gen_vdev_delete = ath10k_wmi_tlv_op_gen_vdev_delete,
3428 	.gen_vdev_start = ath10k_wmi_tlv_op_gen_vdev_start,
3429 	.gen_vdev_stop = ath10k_wmi_tlv_op_gen_vdev_stop,
3430 	.gen_vdev_up = ath10k_wmi_tlv_op_gen_vdev_up,
3431 	.gen_vdev_down = ath10k_wmi_tlv_op_gen_vdev_down,
3432 	.gen_vdev_set_param = ath10k_wmi_tlv_op_gen_vdev_set_param,
3433 	.gen_vdev_install_key = ath10k_wmi_tlv_op_gen_vdev_install_key,
3434 	.gen_vdev_wmm_conf = ath10k_wmi_tlv_op_gen_vdev_wmm_conf,
3435 	.gen_peer_create = ath10k_wmi_tlv_op_gen_peer_create,
3436 	.gen_peer_delete = ath10k_wmi_tlv_op_gen_peer_delete,
3437 	.gen_peer_flush = ath10k_wmi_tlv_op_gen_peer_flush,
3438 	.gen_peer_set_param = ath10k_wmi_tlv_op_gen_peer_set_param,
3439 	.gen_peer_assoc = ath10k_wmi_tlv_op_gen_peer_assoc,
3440 	.gen_set_psmode = ath10k_wmi_tlv_op_gen_set_psmode,
3441 	.gen_set_sta_ps = ath10k_wmi_tlv_op_gen_set_sta_ps,
3442 	.gen_set_ap_ps = ath10k_wmi_tlv_op_gen_set_ap_ps,
3443 	.gen_scan_chan_list = ath10k_wmi_tlv_op_gen_scan_chan_list,
3444 	.gen_beacon_dma = ath10k_wmi_tlv_op_gen_beacon_dma,
3445 	.gen_pdev_set_wmm = ath10k_wmi_tlv_op_gen_pdev_set_wmm,
3446 	.gen_request_stats = ath10k_wmi_tlv_op_gen_request_stats,
3447 	.gen_force_fw_hang = ath10k_wmi_tlv_op_gen_force_fw_hang,
3448 	/* .gen_mgmt_tx = not implemented; HTT is used */
3449 	.gen_dbglog_cfg = ath10k_wmi_tlv_op_gen_dbglog_cfg,
3450 	.gen_pktlog_enable = ath10k_wmi_tlv_op_gen_pktlog_enable,
3451 	.gen_pktlog_disable = ath10k_wmi_tlv_op_gen_pktlog_disable,
3452 	/* .gen_pdev_set_quiet_mode not implemented */
3453 	/* .gen_pdev_get_temperature not implemented */
3454 	/* .gen_addba_clear_resp not implemented */
3455 	/* .gen_addba_send not implemented */
3456 	/* .gen_addba_set_resp not implemented */
3457 	/* .gen_delba_send not implemented */
3458 	.gen_bcn_tmpl = ath10k_wmi_tlv_op_gen_bcn_tmpl,
3459 	.gen_prb_tmpl = ath10k_wmi_tlv_op_gen_prb_tmpl,
3460 	.gen_p2p_go_bcn_ie = ath10k_wmi_tlv_op_gen_p2p_go_bcn_ie,
3461 	.gen_vdev_sta_uapsd = ath10k_wmi_tlv_op_gen_vdev_sta_uapsd,
3462 	.gen_sta_keepalive = ath10k_wmi_tlv_op_gen_sta_keepalive,
3463 	.gen_wow_enable = ath10k_wmi_tlv_op_gen_wow_enable,
3464 	.gen_wow_add_wakeup_event = ath10k_wmi_tlv_op_gen_wow_add_wakeup_event,
3465 	.gen_wow_host_wakeup_ind = ath10k_wmi_tlv_gen_wow_host_wakeup_ind,
3466 	.gen_wow_add_pattern = ath10k_wmi_tlv_op_gen_wow_add_pattern,
3467 	.gen_wow_del_pattern = ath10k_wmi_tlv_op_gen_wow_del_pattern,
3468 	.gen_update_fw_tdls_state = ath10k_wmi_tlv_op_gen_update_fw_tdls_state,
3469 	.gen_tdls_peer_update = ath10k_wmi_tlv_op_gen_tdls_peer_update,
3470 	.gen_adaptive_qcs = ath10k_wmi_tlv_op_gen_adaptive_qcs,
3471 };
3472 
3473 /************/
3474 /* TLV init */
3475 /************/
3476 
3477 void ath10k_wmi_tlv_attach(struct ath10k *ar)
3478 {
3479 	ar->wmi.cmd = &wmi_tlv_cmd_map;
3480 	ar->wmi.vdev_param = &wmi_tlv_vdev_param_map;
3481 	ar->wmi.pdev_param = &wmi_tlv_pdev_param_map;
3482 	ar->wmi.ops = &wmi_tlv_ops;
3483 }
3484