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