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