xref: /freebsd/sys/contrib/dev/athk/ath10k/wmi-tlv.c (revision 19fae0f66023a97a9b464b3beeeabb2081f575b3)
1 // SPDX-License-Identifier: ISC
2 /*
3  * Copyright (c) 2005-2011 Atheros Communications Inc.
4  * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
5  * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
6  */
7 #include "core.h"
8 #include "debug.h"
9 #include "mac.h"
10 #include "hw.h"
11 #include "wmi.h"
12 #include "wmi-ops.h"
13 #include "wmi-tlv.h"
14 #include "p2p.h"
15 #include "testmode.h"
16 #include <linux/bitfield.h>
17 
18 /***************/
19 /* TLV helpers */
20 /**************/
21 
22 struct wmi_tlv_policy {
23 	size_t min_len;
24 };
25 
26 static const struct wmi_tlv_policy wmi_tlv_policies[] = {
27 	[WMI_TLV_TAG_ARRAY_BYTE]
28 		= { .min_len = 0 },
29 	[WMI_TLV_TAG_ARRAY_UINT32]
30 		= { .min_len = 0 },
31 	[WMI_TLV_TAG_STRUCT_SCAN_EVENT]
32 		= { .min_len = sizeof(struct wmi_scan_event) },
33 	[WMI_TLV_TAG_STRUCT_MGMT_RX_HDR]
34 		= { .min_len = sizeof(struct wmi_tlv_mgmt_rx_ev) },
35 	[WMI_TLV_TAG_STRUCT_CHAN_INFO_EVENT]
36 		= { .min_len = sizeof(struct wmi_chan_info_event) },
37 	[WMI_TLV_TAG_STRUCT_VDEV_START_RESPONSE_EVENT]
38 		= { .min_len = sizeof(struct wmi_vdev_start_response_event) },
39 	[WMI_TLV_TAG_STRUCT_PEER_STA_KICKOUT_EVENT]
40 		= { .min_len = sizeof(struct wmi_peer_sta_kickout_event) },
41 	[WMI_TLV_TAG_STRUCT_HOST_SWBA_EVENT]
42 		= { .min_len = sizeof(struct wmi_host_swba_event) },
43 	[WMI_TLV_TAG_STRUCT_TIM_INFO]
44 		= { .min_len = sizeof(struct wmi_tim_info) },
45 	[WMI_TLV_TAG_STRUCT_P2P_NOA_INFO]
46 		= { .min_len = sizeof(struct wmi_p2p_noa_info) },
47 	[WMI_TLV_TAG_STRUCT_SERVICE_READY_EVENT]
48 		= { .min_len = sizeof(struct wmi_tlv_svc_rdy_ev) },
49 	[WMI_TLV_TAG_STRUCT_HAL_REG_CAPABILITIES]
50 		= { .min_len = sizeof(struct hal_reg_capabilities) },
51 	[WMI_TLV_TAG_STRUCT_WLAN_HOST_MEM_REQ]
52 		= { .min_len = sizeof(struct wlan_host_mem_req) },
53 	[WMI_TLV_TAG_STRUCT_READY_EVENT]
54 		= { .min_len = sizeof(struct wmi_tlv_rdy_ev) },
55 	[WMI_TLV_TAG_STRUCT_OFFLOAD_BCN_TX_STATUS_EVENT]
56 		= { .min_len = sizeof(struct wmi_tlv_bcn_tx_status_ev) },
57 	[WMI_TLV_TAG_STRUCT_DIAG_DATA_CONTAINER_EVENT]
58 		= { .min_len = sizeof(struct wmi_tlv_diag_data_ev) },
59 	[WMI_TLV_TAG_STRUCT_P2P_NOA_EVENT]
60 		= { .min_len = sizeof(struct wmi_tlv_p2p_noa_ev) },
61 	[WMI_TLV_TAG_STRUCT_ROAM_EVENT]
62 		= { .min_len = sizeof(struct wmi_tlv_roam_ev) },
63 	[WMI_TLV_TAG_STRUCT_WOW_EVENT_INFO]
64 		= { .min_len = sizeof(struct wmi_tlv_wow_event_info) },
65 	[WMI_TLV_TAG_STRUCT_TX_PAUSE_EVENT]
66 		= { .min_len = sizeof(struct wmi_tlv_tx_pause_ev) },
67 };
68 
69 static int
70 #if defined(__linux__)
71 ath10k_wmi_tlv_iter(struct ath10k *ar, const void *ptr, size_t len,
72 #elif defined(__FreeBSD__)
73 ath10k_wmi_tlv_iter(struct ath10k *ar, const u8 *ptr, size_t len,
74 #endif
75 		    int (*iter)(struct ath10k *ar, u16 tag, u16 len,
76 				const void *ptr, void *data),
77 		    void *data)
78 {
79 #if defined(__linux__)
80 	const void *begin = ptr;
81 #elif defined(__FreeBSD__)
82 	const u8 *begin = ptr;
83 #endif
84 	const struct wmi_tlv *tlv;
85 	u16 tlv_tag, tlv_len;
86 	int ret;
87 
88 	while (len > 0) {
89 		if (len < sizeof(*tlv)) {
90 			ath10k_dbg(ar, ATH10K_DBG_WMI,
91 				   "wmi tlv parse failure at byte %zd (%zu bytes left, %zu expected)\n",
92 				   ptr - begin, len, sizeof(*tlv));
93 			return -EINVAL;
94 		}
95 
96 #if defined(__linux__)
97 		tlv = ptr;
98 #elif defined(__FreeBSD__)
99 		tlv = (const void *)ptr;
100 #endif
101 		tlv_tag = __le16_to_cpu(tlv->tag);
102 		tlv_len = __le16_to_cpu(tlv->len);
103 		ptr += sizeof(*tlv);
104 		len -= sizeof(*tlv);
105 
106 		if (tlv_len > len) {
107 			ath10k_dbg(ar, ATH10K_DBG_WMI,
108 				   "wmi tlv parse failure of tag %u at byte %zd (%zu bytes left, %u expected)\n",
109 				   tlv_tag, ptr - begin, len, tlv_len);
110 			return -EINVAL;
111 		}
112 
113 		if (tlv_tag < ARRAY_SIZE(wmi_tlv_policies) &&
114 		    wmi_tlv_policies[tlv_tag].min_len &&
115 		    wmi_tlv_policies[tlv_tag].min_len > tlv_len) {
116 			ath10k_dbg(ar, ATH10K_DBG_WMI,
117 				   "wmi tlv parse failure of tag %u at byte %zd (%u bytes is less than min length %zu)\n",
118 				   tlv_tag, ptr - begin, tlv_len,
119 				   wmi_tlv_policies[tlv_tag].min_len);
120 			return -EINVAL;
121 		}
122 
123 		ret = iter(ar, tlv_tag, tlv_len, ptr, data);
124 		if (ret)
125 			return ret;
126 
127 		ptr += tlv_len;
128 		len -= tlv_len;
129 	}
130 
131 	return 0;
132 }
133 
134 static int ath10k_wmi_tlv_iter_parse(struct ath10k *ar, u16 tag, u16 len,
135 				     const void *ptr, void *data)
136 {
137 	const void **tb = data;
138 
139 	if (tag < WMI_TLV_TAG_MAX)
140 		tb[tag] = ptr;
141 
142 	return 0;
143 }
144 
145 static int ath10k_wmi_tlv_parse(struct ath10k *ar, const void **tb,
146 				const void *ptr, size_t len)
147 {
148 	return ath10k_wmi_tlv_iter(ar, ptr, len, ath10k_wmi_tlv_iter_parse,
149 				   (void *)tb);
150 }
151 
152 static const void **
153 ath10k_wmi_tlv_parse_alloc(struct ath10k *ar, const void *ptr,
154 			   size_t len, gfp_t gfp)
155 {
156 	const void **tb;
157 	int ret;
158 
159 	tb = kcalloc(WMI_TLV_TAG_MAX, sizeof(*tb), gfp);
160 	if (!tb)
161 		return ERR_PTR(-ENOMEM);
162 
163 	ret = ath10k_wmi_tlv_parse(ar, tb, ptr, len);
164 	if (ret) {
165 		kfree(tb);
166 		return ERR_PTR(ret);
167 	}
168 
169 	return tb;
170 }
171 
172 static u16 ath10k_wmi_tlv_len(const void *ptr)
173 {
174 	return __le16_to_cpu((((const struct wmi_tlv *)ptr) - 1)->len);
175 }
176 
177 /**************/
178 /* TLV events */
179 /**************/
180 static int ath10k_wmi_tlv_event_bcn_tx_status(struct ath10k *ar,
181 					      struct sk_buff *skb)
182 {
183 	const void **tb;
184 	const struct wmi_tlv_bcn_tx_status_ev *ev;
185 	struct ath10k_vif *arvif;
186 	u32 vdev_id, tx_status;
187 	int ret;
188 
189 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
190 	if (IS_ERR(tb)) {
191 		ret = PTR_ERR(tb);
192 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
193 		return ret;
194 	}
195 
196 	ev = tb[WMI_TLV_TAG_STRUCT_OFFLOAD_BCN_TX_STATUS_EVENT];
197 	if (!ev) {
198 		kfree(tb);
199 		return -EPROTO;
200 	}
201 
202 	tx_status = __le32_to_cpu(ev->tx_status);
203 	vdev_id = __le32_to_cpu(ev->vdev_id);
204 
205 	switch (tx_status) {
206 	case WMI_TLV_BCN_TX_STATUS_OK:
207 		break;
208 	case WMI_TLV_BCN_TX_STATUS_XRETRY:
209 	case WMI_TLV_BCN_TX_STATUS_DROP:
210 	case WMI_TLV_BCN_TX_STATUS_FILTERED:
211 		/* FIXME: It's probably worth telling mac80211 to stop the
212 		 * interface as it is crippled.
213 		 */
214 		ath10k_warn(ar, "received bcn tmpl tx status on vdev %i: %d",
215 			    vdev_id, tx_status);
216 		break;
217 	}
218 
219 	arvif = ath10k_get_arvif(ar, vdev_id);
220 	if (arvif && arvif->is_up && arvif->vif->csa_active)
221 		ieee80211_queue_work(ar->hw, &arvif->ap_csa_work);
222 
223 	kfree(tb);
224 	return 0;
225 }
226 
227 static void ath10k_wmi_tlv_event_vdev_delete_resp(struct ath10k *ar,
228 						  struct sk_buff *skb)
229 {
230 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_DELETE_RESP_EVENTID\n");
231 	complete(&ar->vdev_delete_done);
232 }
233 
234 static int ath10k_wmi_tlv_parse_peer_stats_info(struct ath10k *ar, u16 tag, u16 len,
235 						const void *ptr, void *data)
236 {
237 	const struct wmi_tlv_peer_stats_info *stat = ptr;
238 	struct ieee80211_sta *sta;
239 	struct ath10k_sta *arsta;
240 
241 	if (tag != WMI_TLV_TAG_STRUCT_PEER_STATS_INFO)
242 		return -EPROTO;
243 
244 	ath10k_dbg(ar, ATH10K_DBG_WMI,
245 		   "wmi tlv stats peer addr %pMF rx rate code 0x%x bit rate %d kbps\n",
246 		   stat->peer_macaddr.addr,
247 		   __le32_to_cpu(stat->last_rx_rate_code),
248 		   __le32_to_cpu(stat->last_rx_bitrate_kbps));
249 
250 	ath10k_dbg(ar, ATH10K_DBG_WMI,
251 		   "wmi tlv stats tx rate code 0x%x bit rate %d kbps\n",
252 		   __le32_to_cpu(stat->last_tx_rate_code),
253 		   __le32_to_cpu(stat->last_tx_bitrate_kbps));
254 
255 	rcu_read_lock();
256 	sta = ieee80211_find_sta_by_ifaddr(ar->hw, stat->peer_macaddr.addr, NULL);
257 	if (!sta) {
258 		rcu_read_unlock();
259 		ath10k_warn(ar, "not found station for peer stats\n");
260 		return -EINVAL;
261 	}
262 
263 	arsta = (struct ath10k_sta *)sta->drv_priv;
264 	arsta->rx_rate_code = __le32_to_cpu(stat->last_rx_rate_code);
265 	arsta->rx_bitrate_kbps = __le32_to_cpu(stat->last_rx_bitrate_kbps);
266 	arsta->tx_rate_code = __le32_to_cpu(stat->last_tx_rate_code);
267 	arsta->tx_bitrate_kbps = __le32_to_cpu(stat->last_tx_bitrate_kbps);
268 	rcu_read_unlock();
269 
270 	return 0;
271 }
272 
273 static int ath10k_wmi_tlv_op_pull_peer_stats_info(struct ath10k *ar,
274 						  struct sk_buff *skb)
275 {
276 	const void **tb;
277 	const struct wmi_tlv_peer_stats_info_ev *ev;
278 	const void *data;
279 	u32 num_peer_stats;
280 	int ret;
281 
282 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
283 	if (IS_ERR(tb)) {
284 		ret = PTR_ERR(tb);
285 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
286 		return ret;
287 	}
288 
289 	ev = tb[WMI_TLV_TAG_STRUCT_PEER_STATS_INFO_EVENT];
290 	data = tb[WMI_TLV_TAG_ARRAY_STRUCT];
291 
292 	if (!ev || !data) {
293 		kfree(tb);
294 		return -EPROTO;
295 	}
296 
297 	num_peer_stats = __le32_to_cpu(ev->num_peers);
298 
299 	ath10k_dbg(ar, ATH10K_DBG_WMI,
300 		   "wmi tlv peer stats info update peer vdev id %d peers %i more data %d\n",
301 		   __le32_to_cpu(ev->vdev_id),
302 		   num_peer_stats,
303 		   __le32_to_cpu(ev->more_data));
304 
305 	ret = ath10k_wmi_tlv_iter(ar, data, ath10k_wmi_tlv_len(data),
306 				  ath10k_wmi_tlv_parse_peer_stats_info, NULL);
307 	if (ret)
308 		ath10k_warn(ar, "failed to parse stats info tlv: %d\n", ret);
309 
310 	kfree(tb);
311 	return 0;
312 }
313 
314 static void ath10k_wmi_tlv_event_peer_stats_info(struct ath10k *ar,
315 						 struct sk_buff *skb)
316 {
317 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PEER_STATS_INFO_EVENTID\n");
318 	ath10k_wmi_tlv_op_pull_peer_stats_info(ar, skb);
319 	complete(&ar->peer_stats_info_complete);
320 }
321 
322 static int ath10k_wmi_tlv_event_diag_data(struct ath10k *ar,
323 					  struct sk_buff *skb)
324 {
325 	const void **tb;
326 	const struct wmi_tlv_diag_data_ev *ev;
327 	const struct wmi_tlv_diag_item *item;
328 #if defined(__linux__)
329 	const void *data;
330 #elif defined(__FreeBSD__)
331 	const u8 *data;
332 #endif
333 	int ret, num_items, len;
334 
335 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
336 	if (IS_ERR(tb)) {
337 		ret = PTR_ERR(tb);
338 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
339 		return ret;
340 	}
341 
342 	ev = tb[WMI_TLV_TAG_STRUCT_DIAG_DATA_CONTAINER_EVENT];
343 	data = tb[WMI_TLV_TAG_ARRAY_BYTE];
344 	if (!ev || !data) {
345 		kfree(tb);
346 		return -EPROTO;
347 	}
348 
349 	num_items = __le32_to_cpu(ev->num_items);
350 	len = ath10k_wmi_tlv_len(data);
351 
352 	while (num_items--) {
353 		if (len == 0)
354 			break;
355 		if (len < sizeof(*item)) {
356 			ath10k_warn(ar, "failed to parse diag data: can't fit item header\n");
357 			break;
358 		}
359 
360 #if defined(__linux__)
361 		item = data;
362 #elif defined(__FreeBSD__)
363 		item = (const void *)data;
364 #endif
365 
366 		if (len < sizeof(*item) + __le16_to_cpu(item->len)) {
367 			ath10k_warn(ar, "failed to parse diag data: item is too long\n");
368 			break;
369 		}
370 
371 		trace_ath10k_wmi_diag_container(ar,
372 						item->type,
373 						__le32_to_cpu(item->timestamp),
374 						__le32_to_cpu(item->code),
375 						__le16_to_cpu(item->len),
376 						item->payload);
377 
378 		len -= sizeof(*item);
379 		len -= roundup(__le16_to_cpu(item->len), 4);
380 
381 		data += sizeof(*item);
382 		data += roundup(__le16_to_cpu(item->len), 4);
383 	}
384 
385 	if (num_items != -1 || len != 0)
386 		ath10k_warn(ar, "failed to parse diag data event: num_items %d len %d\n",
387 			    num_items, len);
388 
389 	kfree(tb);
390 	return 0;
391 }
392 
393 static int ath10k_wmi_tlv_event_diag(struct ath10k *ar,
394 				     struct sk_buff *skb)
395 {
396 	const void **tb;
397 	const void *data;
398 	int ret, len;
399 
400 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
401 	if (IS_ERR(tb)) {
402 		ret = PTR_ERR(tb);
403 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
404 		return ret;
405 	}
406 
407 	data = tb[WMI_TLV_TAG_ARRAY_BYTE];
408 	if (!data) {
409 		kfree(tb);
410 		return -EPROTO;
411 	}
412 	len = ath10k_wmi_tlv_len(data);
413 
414 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv diag event len %d\n", len);
415 	trace_ath10k_wmi_diag(ar, data, len);
416 
417 	kfree(tb);
418 	return 0;
419 }
420 
421 static int ath10k_wmi_tlv_event_p2p_noa(struct ath10k *ar,
422 					struct sk_buff *skb)
423 {
424 	const void **tb;
425 	const struct wmi_tlv_p2p_noa_ev *ev;
426 	const struct wmi_p2p_noa_info *noa;
427 	int ret, vdev_id;
428 
429 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
430 	if (IS_ERR(tb)) {
431 		ret = PTR_ERR(tb);
432 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
433 		return ret;
434 	}
435 
436 	ev = tb[WMI_TLV_TAG_STRUCT_P2P_NOA_EVENT];
437 	noa = tb[WMI_TLV_TAG_STRUCT_P2P_NOA_INFO];
438 
439 	if (!ev || !noa) {
440 		kfree(tb);
441 		return -EPROTO;
442 	}
443 
444 	vdev_id = __le32_to_cpu(ev->vdev_id);
445 
446 	ath10k_dbg(ar, ATH10K_DBG_WMI,
447 		   "wmi tlv p2p noa vdev_id %i descriptors %u\n",
448 		   vdev_id, noa->num_descriptors);
449 
450 	ath10k_p2p_noa_update_by_vdev_id(ar, vdev_id, noa);
451 	kfree(tb);
452 	return 0;
453 }
454 
455 static int ath10k_wmi_tlv_event_tx_pause(struct ath10k *ar,
456 					 struct sk_buff *skb)
457 {
458 	const void **tb;
459 	const struct wmi_tlv_tx_pause_ev *ev;
460 	int ret, vdev_id;
461 	u32 pause_id, action, vdev_map, peer_id, tid_map;
462 
463 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
464 	if (IS_ERR(tb)) {
465 		ret = PTR_ERR(tb);
466 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
467 		return ret;
468 	}
469 
470 	ev = tb[WMI_TLV_TAG_STRUCT_TX_PAUSE_EVENT];
471 	if (!ev) {
472 		kfree(tb);
473 		return -EPROTO;
474 	}
475 
476 	pause_id = __le32_to_cpu(ev->pause_id);
477 	action = __le32_to_cpu(ev->action);
478 	vdev_map = __le32_to_cpu(ev->vdev_map);
479 	peer_id = __le32_to_cpu(ev->peer_id);
480 	tid_map = __le32_to_cpu(ev->tid_map);
481 
482 	ath10k_dbg(ar, ATH10K_DBG_WMI,
483 		   "wmi tlv tx pause pause_id %u action %u vdev_map 0x%08x peer_id %u tid_map 0x%08x\n",
484 		   pause_id, action, vdev_map, peer_id, tid_map);
485 
486 	switch (pause_id) {
487 	case WMI_TLV_TX_PAUSE_ID_MCC:
488 	case WMI_TLV_TX_PAUSE_ID_P2P_CLI_NOA:
489 	case WMI_TLV_TX_PAUSE_ID_P2P_GO_PS:
490 	case WMI_TLV_TX_PAUSE_ID_AP_PS:
491 	case WMI_TLV_TX_PAUSE_ID_IBSS_PS:
492 		for (vdev_id = 0; vdev_map; vdev_id++) {
493 			if (!(vdev_map & BIT(vdev_id)))
494 				continue;
495 
496 			vdev_map &= ~BIT(vdev_id);
497 			ath10k_mac_handle_tx_pause_vdev(ar, vdev_id, pause_id,
498 							action);
499 		}
500 		break;
501 	case WMI_TLV_TX_PAUSE_ID_AP_PEER_PS:
502 	case WMI_TLV_TX_PAUSE_ID_AP_PEER_UAPSD:
503 	case WMI_TLV_TX_PAUSE_ID_STA_ADD_BA:
504 	case WMI_TLV_TX_PAUSE_ID_HOST:
505 		ath10k_dbg(ar, ATH10K_DBG_MAC,
506 			   "mac ignoring unsupported tx pause id %d\n",
507 			   pause_id);
508 		break;
509 	default:
510 		ath10k_dbg(ar, ATH10K_DBG_MAC,
511 			   "mac ignoring unknown tx pause vdev %d\n",
512 			   pause_id);
513 		break;
514 	}
515 
516 	kfree(tb);
517 	return 0;
518 }
519 
520 static void ath10k_wmi_tlv_event_rfkill_state_change(struct ath10k *ar,
521 						     struct sk_buff *skb)
522 {
523 	const struct wmi_tlv_rfkill_state_change_ev *ev;
524 	const void **tb;
525 	bool radio;
526 	int ret;
527 
528 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
529 	if (IS_ERR(tb)) {
530 		ret = PTR_ERR(tb);
531 		ath10k_warn(ar,
532 			    "failed to parse rfkill state change event: %d\n",
533 			    ret);
534 		return;
535 	}
536 
537 	ev = tb[WMI_TLV_TAG_STRUCT_RFKILL_EVENT];
538 	if (!ev) {
539 		kfree(tb);
540 		return;
541 	}
542 
543 	ath10k_dbg(ar, ATH10K_DBG_MAC,
544 		   "wmi tlv rfkill state change gpio %d type %d radio_state %d\n",
545 		   __le32_to_cpu(ev->gpio_pin_num),
546 		   __le32_to_cpu(ev->int_type),
547 		   __le32_to_cpu(ev->radio_state));
548 
549 	radio = (__le32_to_cpu(ev->radio_state) == WMI_TLV_RFKILL_RADIO_STATE_ON);
550 
551 	spin_lock_bh(&ar->data_lock);
552 
553 	if (!radio)
554 		ar->hw_rfkill_on = true;
555 
556 	spin_unlock_bh(&ar->data_lock);
557 
558 	/* notify cfg80211 radio state change */
559 	ath10k_mac_rfkill_enable_radio(ar, radio);
560 	wiphy_rfkill_set_hw_state(ar->hw->wiphy, !radio);
561 }
562 
563 static int ath10k_wmi_tlv_event_temperature(struct ath10k *ar,
564 					    struct sk_buff *skb)
565 {
566 	const struct wmi_tlv_pdev_temperature_event *ev;
567 
568 	ev = (struct wmi_tlv_pdev_temperature_event *)skb->data;
569 	if (WARN_ON(skb->len < sizeof(*ev)))
570 		return -EPROTO;
571 
572 	ath10k_thermal_event_temperature(ar, __le32_to_cpu(ev->temperature));
573 	return 0;
574 }
575 
576 static void ath10k_wmi_event_tdls_peer(struct ath10k *ar, struct sk_buff *skb)
577 {
578 	struct ieee80211_sta *station;
579 	const struct wmi_tlv_tdls_peer_event *ev;
580 	const void **tb;
581 	struct ath10k_vif *arvif;
582 
583 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
584 	if (IS_ERR(tb)) {
585 		ath10k_warn(ar, "tdls peer failed to parse tlv");
586 		return;
587 	}
588 	ev = tb[WMI_TLV_TAG_STRUCT_TDLS_PEER_EVENT];
589 	if (!ev) {
590 		kfree(tb);
591 		ath10k_warn(ar, "tdls peer NULL event");
592 		return;
593 	}
594 
595 	switch (__le32_to_cpu(ev->peer_reason)) {
596 	case WMI_TDLS_TEARDOWN_REASON_TX:
597 	case WMI_TDLS_TEARDOWN_REASON_RSSI:
598 	case WMI_TDLS_TEARDOWN_REASON_PTR_TIMEOUT:
599 		rcu_read_lock();
600 		station = ieee80211_find_sta_by_ifaddr(ar->hw,
601 						       ev->peer_macaddr.addr,
602 						       NULL);
603 		if (!station) {
604 			ath10k_warn(ar, "did not find station from tdls peer event");
605 			goto exit;
606 		}
607 		arvif = ath10k_get_arvif(ar, __le32_to_cpu(ev->vdev_id));
608 		ieee80211_tdls_oper_request(
609 					arvif->vif, station->addr,
610 					NL80211_TDLS_TEARDOWN,
611 					WLAN_REASON_TDLS_TEARDOWN_UNREACHABLE,
612 					GFP_ATOMIC
613 					);
614 		break;
615 	default:
616 		kfree(tb);
617 		return;
618 	}
619 
620 exit:
621 	rcu_read_unlock();
622 	kfree(tb);
623 }
624 
625 static int ath10k_wmi_tlv_event_peer_delete_resp(struct ath10k *ar,
626 						 struct sk_buff *skb)
627 {
628 	struct wmi_peer_delete_resp_ev_arg *arg;
629 	struct wmi_tlv *tlv_hdr;
630 
631 	tlv_hdr = (struct wmi_tlv *)skb->data;
632 	arg = (struct wmi_peer_delete_resp_ev_arg *)tlv_hdr->value;
633 
634 	ath10k_dbg(ar, ATH10K_DBG_WMI, "vdev id %d", arg->vdev_id);
635 	ath10k_dbg(ar, ATH10K_DBG_WMI, "peer mac addr %pM", &arg->peer_addr);
636 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer delete response\n");
637 
638 	complete(&ar->peer_delete_done);
639 
640 	return 0;
641 }
642 
643 /***********/
644 /* TLV ops */
645 /***********/
646 
647 static void ath10k_wmi_tlv_op_rx(struct ath10k *ar, struct sk_buff *skb)
648 {
649 	struct wmi_cmd_hdr *cmd_hdr;
650 	enum wmi_tlv_event_id id;
651 	bool consumed;
652 
653 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
654 	id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
655 
656 	if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
657 		goto out;
658 
659 	trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
660 
661 	consumed = ath10k_tm_event_wmi(ar, id, skb);
662 
663 	/* Ready event must be handled normally also in UTF mode so that we
664 	 * know the UTF firmware has booted, others we are just bypass WMI
665 	 * events to testmode.
666 	 */
667 	if (consumed && id != WMI_TLV_READY_EVENTID) {
668 		ath10k_dbg(ar, ATH10K_DBG_WMI,
669 			   "wmi tlv testmode consumed 0x%x\n", id);
670 		goto out;
671 	}
672 
673 	switch (id) {
674 	case WMI_TLV_MGMT_RX_EVENTID:
675 		ath10k_wmi_event_mgmt_rx(ar, skb);
676 		/* mgmt_rx() owns the skb now! */
677 		return;
678 	case WMI_TLV_SCAN_EVENTID:
679 		ath10k_wmi_event_scan(ar, skb);
680 		break;
681 	case WMI_TLV_CHAN_INFO_EVENTID:
682 		ath10k_wmi_event_chan_info(ar, skb);
683 		break;
684 	case WMI_TLV_ECHO_EVENTID:
685 		ath10k_wmi_event_echo(ar, skb);
686 		break;
687 	case WMI_TLV_DEBUG_MESG_EVENTID:
688 		ath10k_wmi_event_debug_mesg(ar, skb);
689 		break;
690 	case WMI_TLV_UPDATE_STATS_EVENTID:
691 		ath10k_wmi_event_update_stats(ar, skb);
692 		break;
693 	case WMI_TLV_PEER_STATS_INFO_EVENTID:
694 		ath10k_wmi_tlv_event_peer_stats_info(ar, skb);
695 		break;
696 	case WMI_TLV_VDEV_START_RESP_EVENTID:
697 		ath10k_wmi_event_vdev_start_resp(ar, skb);
698 		break;
699 	case WMI_TLV_VDEV_STOPPED_EVENTID:
700 		ath10k_wmi_event_vdev_stopped(ar, skb);
701 		break;
702 	case WMI_TLV_VDEV_DELETE_RESP_EVENTID:
703 		ath10k_wmi_tlv_event_vdev_delete_resp(ar, skb);
704 		break;
705 	case WMI_TLV_PEER_STA_KICKOUT_EVENTID:
706 		ath10k_wmi_event_peer_sta_kickout(ar, skb);
707 		break;
708 	case WMI_TLV_HOST_SWBA_EVENTID:
709 		ath10k_wmi_event_host_swba(ar, skb);
710 		break;
711 	case WMI_TLV_TBTTOFFSET_UPDATE_EVENTID:
712 		ath10k_wmi_event_tbttoffset_update(ar, skb);
713 		break;
714 	case WMI_TLV_PHYERR_EVENTID:
715 		ath10k_wmi_event_phyerr(ar, skb);
716 		break;
717 	case WMI_TLV_ROAM_EVENTID:
718 		ath10k_wmi_event_roam(ar, skb);
719 		break;
720 	case WMI_TLV_PROFILE_MATCH:
721 		ath10k_wmi_event_profile_match(ar, skb);
722 		break;
723 	case WMI_TLV_DEBUG_PRINT_EVENTID:
724 		ath10k_wmi_event_debug_print(ar, skb);
725 		break;
726 	case WMI_TLV_PDEV_QVIT_EVENTID:
727 		ath10k_wmi_event_pdev_qvit(ar, skb);
728 		break;
729 	case WMI_TLV_WLAN_PROFILE_DATA_EVENTID:
730 		ath10k_wmi_event_wlan_profile_data(ar, skb);
731 		break;
732 	case WMI_TLV_RTT_MEASUREMENT_REPORT_EVENTID:
733 		ath10k_wmi_event_rtt_measurement_report(ar, skb);
734 		break;
735 	case WMI_TLV_TSF_MEASUREMENT_REPORT_EVENTID:
736 		ath10k_wmi_event_tsf_measurement_report(ar, skb);
737 		break;
738 	case WMI_TLV_RTT_ERROR_REPORT_EVENTID:
739 		ath10k_wmi_event_rtt_error_report(ar, skb);
740 		break;
741 	case WMI_TLV_WOW_WAKEUP_HOST_EVENTID:
742 		ath10k_wmi_event_wow_wakeup_host(ar, skb);
743 		break;
744 	case WMI_TLV_DCS_INTERFERENCE_EVENTID:
745 		ath10k_wmi_event_dcs_interference(ar, skb);
746 		break;
747 	case WMI_TLV_PDEV_TPC_CONFIG_EVENTID:
748 		ath10k_wmi_event_pdev_tpc_config(ar, skb);
749 		break;
750 	case WMI_TLV_PDEV_FTM_INTG_EVENTID:
751 		ath10k_wmi_event_pdev_ftm_intg(ar, skb);
752 		break;
753 	case WMI_TLV_GTK_OFFLOAD_STATUS_EVENTID:
754 		ath10k_wmi_event_gtk_offload_status(ar, skb);
755 		break;
756 	case WMI_TLV_GTK_REKEY_FAIL_EVENTID:
757 		ath10k_wmi_event_gtk_rekey_fail(ar, skb);
758 		break;
759 	case WMI_TLV_TX_DELBA_COMPLETE_EVENTID:
760 		ath10k_wmi_event_delba_complete(ar, skb);
761 		break;
762 	case WMI_TLV_TX_ADDBA_COMPLETE_EVENTID:
763 		ath10k_wmi_event_addba_complete(ar, skb);
764 		break;
765 	case WMI_TLV_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
766 		ath10k_wmi_event_vdev_install_key_complete(ar, skb);
767 		break;
768 	case WMI_TLV_SERVICE_READY_EVENTID:
769 		ath10k_wmi_event_service_ready(ar, skb);
770 		return;
771 	case WMI_TLV_READY_EVENTID:
772 		ath10k_wmi_event_ready(ar, skb);
773 		break;
774 	case WMI_TLV_SERVICE_AVAILABLE_EVENTID:
775 		ath10k_wmi_event_service_available(ar, skb);
776 		break;
777 	case WMI_TLV_OFFLOAD_BCN_TX_STATUS_EVENTID:
778 		ath10k_wmi_tlv_event_bcn_tx_status(ar, skb);
779 		break;
780 	case WMI_TLV_DIAG_DATA_CONTAINER_EVENTID:
781 		ath10k_wmi_tlv_event_diag_data(ar, skb);
782 		break;
783 	case WMI_TLV_DIAG_EVENTID:
784 		ath10k_wmi_tlv_event_diag(ar, skb);
785 		break;
786 	case WMI_TLV_P2P_NOA_EVENTID:
787 		ath10k_wmi_tlv_event_p2p_noa(ar, skb);
788 		break;
789 	case WMI_TLV_TX_PAUSE_EVENTID:
790 		ath10k_wmi_tlv_event_tx_pause(ar, skb);
791 		break;
792 	case WMI_TLV_RFKILL_STATE_CHANGE_EVENTID:
793 		ath10k_wmi_tlv_event_rfkill_state_change(ar, skb);
794 		break;
795 	case WMI_TLV_PDEV_TEMPERATURE_EVENTID:
796 		ath10k_wmi_tlv_event_temperature(ar, skb);
797 		break;
798 	case WMI_TLV_TDLS_PEER_EVENTID:
799 		ath10k_wmi_event_tdls_peer(ar, skb);
800 		break;
801 	case WMI_TLV_PEER_DELETE_RESP_EVENTID:
802 		ath10k_wmi_tlv_event_peer_delete_resp(ar, skb);
803 		break;
804 	case WMI_TLV_MGMT_TX_COMPLETION_EVENTID:
805 		ath10k_wmi_event_mgmt_tx_compl(ar, skb);
806 		break;
807 	case WMI_TLV_MGMT_TX_BUNDLE_COMPLETION_EVENTID:
808 		ath10k_wmi_event_mgmt_tx_bundle_compl(ar, skb);
809 		break;
810 	default:
811 		ath10k_dbg(ar, ATH10K_DBG_WMI, "Unknown eventid: %d\n", id);
812 		break;
813 	}
814 
815 out:
816 	dev_kfree_skb(skb);
817 }
818 
819 static int ath10k_wmi_tlv_op_pull_scan_ev(struct ath10k *ar,
820 					  struct sk_buff *skb,
821 					  struct wmi_scan_ev_arg *arg)
822 {
823 	const void **tb;
824 	const struct wmi_scan_event *ev;
825 	int ret;
826 
827 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
828 	if (IS_ERR(tb)) {
829 		ret = PTR_ERR(tb);
830 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
831 		return ret;
832 	}
833 
834 	ev = tb[WMI_TLV_TAG_STRUCT_SCAN_EVENT];
835 	if (!ev) {
836 		kfree(tb);
837 		return -EPROTO;
838 	}
839 
840 	arg->event_type = ev->event_type;
841 	arg->reason = ev->reason;
842 	arg->channel_freq = ev->channel_freq;
843 	arg->scan_req_id = ev->scan_req_id;
844 	arg->scan_id = ev->scan_id;
845 	arg->vdev_id = ev->vdev_id;
846 
847 	kfree(tb);
848 	return 0;
849 }
850 
851 static int
852 ath10k_wmi_tlv_op_pull_mgmt_tx_compl_ev(struct ath10k *ar, struct sk_buff *skb,
853 					struct wmi_tlv_mgmt_tx_compl_ev_arg *arg)
854 {
855 	const void **tb;
856 	const struct wmi_tlv_mgmt_tx_compl_ev *ev;
857 	int ret;
858 
859 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
860 	if (IS_ERR(tb)) {
861 		ret = PTR_ERR(tb);
862 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
863 		return ret;
864 	}
865 
866 	ev = tb[WMI_TLV_TAG_STRUCT_MGMT_TX_COMPL_EVENT];
867 
868 	arg->desc_id = ev->desc_id;
869 	arg->status = ev->status;
870 	arg->pdev_id = ev->pdev_id;
871 	arg->ppdu_id = ev->ppdu_id;
872 
873 	if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map))
874 		arg->ack_rssi = ev->ack_rssi;
875 
876 	kfree(tb);
877 	return 0;
878 }
879 
880 struct wmi_tlv_tx_bundle_compl_parse {
881 	const __le32 *num_reports;
882 	const __le32 *desc_ids;
883 	const __le32 *status;
884 	const __le32 *ppdu_ids;
885 	const __le32 *ack_rssi;
886 	bool desc_ids_done;
887 	bool status_done;
888 	bool ppdu_ids_done;
889 	bool ack_rssi_done;
890 };
891 
892 static int
893 ath10k_wmi_tlv_mgmt_tx_bundle_compl_parse(struct ath10k *ar, u16 tag, u16 len,
894 					  const void *ptr, void *data)
895 {
896 	struct wmi_tlv_tx_bundle_compl_parse *bundle_tx_compl = data;
897 
898 	switch (tag) {
899 	case WMI_TLV_TAG_STRUCT_MGMT_TX_COMPL_BUNDLE_EVENT:
900 		bundle_tx_compl->num_reports = ptr;
901 		break;
902 	case WMI_TLV_TAG_ARRAY_UINT32:
903 		if (!bundle_tx_compl->desc_ids_done) {
904 			bundle_tx_compl->desc_ids_done = true;
905 			bundle_tx_compl->desc_ids = ptr;
906 		} else if (!bundle_tx_compl->status_done) {
907 			bundle_tx_compl->status_done = true;
908 			bundle_tx_compl->status = ptr;
909 		} else if (!bundle_tx_compl->ppdu_ids_done) {
910 			bundle_tx_compl->ppdu_ids_done = true;
911 			bundle_tx_compl->ppdu_ids = ptr;
912 		} else if (!bundle_tx_compl->ack_rssi_done) {
913 			bundle_tx_compl->ack_rssi_done = true;
914 			bundle_tx_compl->ack_rssi = ptr;
915 		}
916 		break;
917 	default:
918 		break;
919 	}
920 	return 0;
921 }
922 
923 static int ath10k_wmi_tlv_op_pull_mgmt_tx_bundle_compl_ev(
924 				struct ath10k *ar, struct sk_buff *skb,
925 				struct wmi_tlv_mgmt_tx_bundle_compl_ev_arg *arg)
926 {
927 	struct wmi_tlv_tx_bundle_compl_parse bundle_tx_compl = { };
928 	int ret;
929 
930 	ret = ath10k_wmi_tlv_iter(ar, skb->data, skb->len,
931 				  ath10k_wmi_tlv_mgmt_tx_bundle_compl_parse,
932 				  &bundle_tx_compl);
933 	if (ret) {
934 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
935 		return ret;
936 	}
937 
938 	if (!bundle_tx_compl.num_reports || !bundle_tx_compl.desc_ids ||
939 	    !bundle_tx_compl.status)
940 		return -EPROTO;
941 
942 	arg->num_reports = *bundle_tx_compl.num_reports;
943 	arg->desc_ids = bundle_tx_compl.desc_ids;
944 	arg->status = bundle_tx_compl.status;
945 	arg->ppdu_ids = bundle_tx_compl.ppdu_ids;
946 
947 	if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map))
948 		arg->ack_rssi = bundle_tx_compl.ack_rssi;
949 
950 	return 0;
951 }
952 
953 static int ath10k_wmi_tlv_op_pull_mgmt_rx_ev(struct ath10k *ar,
954 					     struct sk_buff *skb,
955 					     struct wmi_mgmt_rx_ev_arg *arg)
956 {
957 	const void **tb;
958 	const struct wmi_tlv_mgmt_rx_ev *ev;
959 	const u8 *frame;
960 	u32 msdu_len;
961 	int ret, i;
962 
963 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
964 	if (IS_ERR(tb)) {
965 		ret = PTR_ERR(tb);
966 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
967 		return ret;
968 	}
969 
970 	ev = tb[WMI_TLV_TAG_STRUCT_MGMT_RX_HDR];
971 	frame = tb[WMI_TLV_TAG_ARRAY_BYTE];
972 
973 	if (!ev || !frame) {
974 		kfree(tb);
975 		return -EPROTO;
976 	}
977 
978 	arg->channel = ev->channel;
979 	arg->buf_len = ev->buf_len;
980 	arg->status = ev->status;
981 	arg->snr = ev->snr;
982 	arg->phy_mode = ev->phy_mode;
983 	arg->rate = ev->rate;
984 
985 	for (i = 0; i < ARRAY_SIZE(ev->rssi); i++)
986 		arg->rssi[i] = ev->rssi[i];
987 
988 	msdu_len = __le32_to_cpu(arg->buf_len);
989 
990 	if (skb->len < (frame - skb->data) + msdu_len) {
991 		kfree(tb);
992 		return -EPROTO;
993 	}
994 
995 	/* shift the sk_buff to point to `frame` */
996 	skb_trim(skb, 0);
997 	skb_put(skb, frame - skb->data);
998 	skb_pull(skb, frame - skb->data);
999 	skb_put(skb, msdu_len);
1000 
1001 	kfree(tb);
1002 	return 0;
1003 }
1004 
1005 static int ath10k_wmi_tlv_op_pull_ch_info_ev(struct ath10k *ar,
1006 					     struct sk_buff *skb,
1007 					     struct wmi_ch_info_ev_arg *arg)
1008 {
1009 	const void **tb;
1010 	const struct wmi_tlv_chan_info_event *ev;
1011 	int ret;
1012 
1013 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1014 	if (IS_ERR(tb)) {
1015 		ret = PTR_ERR(tb);
1016 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1017 		return ret;
1018 	}
1019 
1020 	ev = tb[WMI_TLV_TAG_STRUCT_CHAN_INFO_EVENT];
1021 	if (!ev) {
1022 		kfree(tb);
1023 		return -EPROTO;
1024 	}
1025 
1026 	arg->err_code = ev->err_code;
1027 	arg->freq = ev->freq;
1028 	arg->cmd_flags = ev->cmd_flags;
1029 	arg->noise_floor = ev->noise_floor;
1030 	arg->rx_clear_count = ev->rx_clear_count;
1031 	arg->cycle_count = ev->cycle_count;
1032 	if (test_bit(ATH10K_FW_FEATURE_SINGLE_CHAN_INFO_PER_CHANNEL,
1033 		     ar->running_fw->fw_file.fw_features))
1034 		arg->mac_clk_mhz = ev->mac_clk_mhz;
1035 
1036 	kfree(tb);
1037 	return 0;
1038 }
1039 
1040 static int
1041 ath10k_wmi_tlv_op_pull_vdev_start_ev(struct ath10k *ar, struct sk_buff *skb,
1042 				     struct wmi_vdev_start_ev_arg *arg)
1043 {
1044 	const void **tb;
1045 	const struct wmi_vdev_start_response_event *ev;
1046 	int ret;
1047 
1048 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1049 	if (IS_ERR(tb)) {
1050 		ret = PTR_ERR(tb);
1051 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1052 		return ret;
1053 	}
1054 
1055 	ev = tb[WMI_TLV_TAG_STRUCT_VDEV_START_RESPONSE_EVENT];
1056 	if (!ev) {
1057 		kfree(tb);
1058 		return -EPROTO;
1059 	}
1060 
1061 	skb_pull(skb, sizeof(*ev));
1062 	arg->vdev_id = ev->vdev_id;
1063 	arg->req_id = ev->req_id;
1064 	arg->resp_type = ev->resp_type;
1065 	arg->status = ev->status;
1066 
1067 	kfree(tb);
1068 	return 0;
1069 }
1070 
1071 static int ath10k_wmi_tlv_op_pull_peer_kick_ev(struct ath10k *ar,
1072 					       struct sk_buff *skb,
1073 					       struct wmi_peer_kick_ev_arg *arg)
1074 {
1075 	const void **tb;
1076 	const struct wmi_peer_sta_kickout_event *ev;
1077 	int ret;
1078 
1079 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1080 	if (IS_ERR(tb)) {
1081 		ret = PTR_ERR(tb);
1082 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1083 		return ret;
1084 	}
1085 
1086 	ev = tb[WMI_TLV_TAG_STRUCT_PEER_STA_KICKOUT_EVENT];
1087 	if (!ev) {
1088 		kfree(tb);
1089 		return -EPROTO;
1090 	}
1091 
1092 	arg->mac_addr = ev->peer_macaddr.addr;
1093 
1094 	kfree(tb);
1095 	return 0;
1096 }
1097 
1098 struct wmi_tlv_swba_parse {
1099 	const struct wmi_host_swba_event *ev;
1100 	bool tim_done;
1101 	bool noa_done;
1102 	size_t n_tim;
1103 	size_t n_noa;
1104 	struct wmi_swba_ev_arg *arg;
1105 };
1106 
1107 static int ath10k_wmi_tlv_swba_tim_parse(struct ath10k *ar, u16 tag, u16 len,
1108 					 const void *ptr, void *data)
1109 {
1110 	struct wmi_tlv_swba_parse *swba = data;
1111 	struct wmi_tim_info_arg *tim_info_arg;
1112 	const struct wmi_tim_info *tim_info_ev = ptr;
1113 
1114 	if (tag != WMI_TLV_TAG_STRUCT_TIM_INFO)
1115 		return -EPROTO;
1116 
1117 	if (swba->n_tim >= ARRAY_SIZE(swba->arg->tim_info))
1118 		return -ENOBUFS;
1119 
1120 	if (__le32_to_cpu(tim_info_ev->tim_len) >
1121 	     sizeof(tim_info_ev->tim_bitmap)) {
1122 		ath10k_warn(ar, "refusing to parse invalid swba structure\n");
1123 		return -EPROTO;
1124 	}
1125 
1126 	tim_info_arg = &swba->arg->tim_info[swba->n_tim];
1127 	tim_info_arg->tim_len = tim_info_ev->tim_len;
1128 	tim_info_arg->tim_mcast = tim_info_ev->tim_mcast;
1129 	tim_info_arg->tim_bitmap = tim_info_ev->tim_bitmap;
1130 	tim_info_arg->tim_changed = tim_info_ev->tim_changed;
1131 	tim_info_arg->tim_num_ps_pending = tim_info_ev->tim_num_ps_pending;
1132 
1133 	swba->n_tim++;
1134 
1135 	return 0;
1136 }
1137 
1138 static int ath10k_wmi_tlv_swba_noa_parse(struct ath10k *ar, u16 tag, u16 len,
1139 					 const void *ptr, void *data)
1140 {
1141 	struct wmi_tlv_swba_parse *swba = data;
1142 
1143 	if (tag != WMI_TLV_TAG_STRUCT_P2P_NOA_INFO)
1144 		return -EPROTO;
1145 
1146 	if (swba->n_noa >= ARRAY_SIZE(swba->arg->noa_info))
1147 		return -ENOBUFS;
1148 
1149 	swba->arg->noa_info[swba->n_noa++] = ptr;
1150 	return 0;
1151 }
1152 
1153 static int ath10k_wmi_tlv_swba_parse(struct ath10k *ar, u16 tag, u16 len,
1154 				     const void *ptr, void *data)
1155 {
1156 	struct wmi_tlv_swba_parse *swba = data;
1157 	int ret;
1158 
1159 	switch (tag) {
1160 	case WMI_TLV_TAG_STRUCT_HOST_SWBA_EVENT:
1161 		swba->ev = ptr;
1162 		break;
1163 	case WMI_TLV_TAG_ARRAY_STRUCT:
1164 		if (!swba->tim_done) {
1165 			swba->tim_done = true;
1166 			ret = ath10k_wmi_tlv_iter(ar, ptr, len,
1167 						  ath10k_wmi_tlv_swba_tim_parse,
1168 						  swba);
1169 			if (ret)
1170 				return ret;
1171 		} else if (!swba->noa_done) {
1172 			swba->noa_done = true;
1173 			ret = ath10k_wmi_tlv_iter(ar, ptr, len,
1174 						  ath10k_wmi_tlv_swba_noa_parse,
1175 						  swba);
1176 			if (ret)
1177 				return ret;
1178 		}
1179 		break;
1180 	default:
1181 		break;
1182 	}
1183 	return 0;
1184 }
1185 
1186 static int ath10k_wmi_tlv_op_pull_swba_ev(struct ath10k *ar,
1187 					  struct sk_buff *skb,
1188 					  struct wmi_swba_ev_arg *arg)
1189 {
1190 	struct wmi_tlv_swba_parse swba = { .arg = arg };
1191 	u32 map;
1192 	size_t n_vdevs;
1193 	int ret;
1194 
1195 	ret = ath10k_wmi_tlv_iter(ar, skb->data, skb->len,
1196 				  ath10k_wmi_tlv_swba_parse, &swba);
1197 	if (ret) {
1198 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1199 		return ret;
1200 	}
1201 
1202 	if (!swba.ev)
1203 		return -EPROTO;
1204 
1205 	arg->vdev_map = swba.ev->vdev_map;
1206 
1207 	for (map = __le32_to_cpu(arg->vdev_map), n_vdevs = 0; map; map >>= 1)
1208 		if (map & BIT(0))
1209 			n_vdevs++;
1210 
1211 	if (n_vdevs != swba.n_tim ||
1212 	    n_vdevs != swba.n_noa)
1213 		return -EPROTO;
1214 
1215 	return 0;
1216 }
1217 
1218 static int ath10k_wmi_tlv_op_pull_phyerr_ev_hdr(struct ath10k *ar,
1219 						struct sk_buff *skb,
1220 						struct wmi_phyerr_hdr_arg *arg)
1221 {
1222 	const void **tb;
1223 	const struct wmi_tlv_phyerr_ev *ev;
1224 	const void *phyerrs;
1225 	int ret;
1226 
1227 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1228 	if (IS_ERR(tb)) {
1229 		ret = PTR_ERR(tb);
1230 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1231 		return ret;
1232 	}
1233 
1234 	ev = tb[WMI_TLV_TAG_STRUCT_COMB_PHYERR_RX_HDR];
1235 	phyerrs = tb[WMI_TLV_TAG_ARRAY_BYTE];
1236 
1237 	if (!ev || !phyerrs) {
1238 		kfree(tb);
1239 		return -EPROTO;
1240 	}
1241 
1242 	arg->num_phyerrs  = __le32_to_cpu(ev->num_phyerrs);
1243 	arg->tsf_l32 = __le32_to_cpu(ev->tsf_l32);
1244 	arg->tsf_u32 = __le32_to_cpu(ev->tsf_u32);
1245 	arg->buf_len = __le32_to_cpu(ev->buf_len);
1246 	arg->phyerrs = phyerrs;
1247 
1248 	kfree(tb);
1249 	return 0;
1250 }
1251 
1252 #define WMI_TLV_ABI_VER_NS0 0x5F414351
1253 #define WMI_TLV_ABI_VER_NS1 0x00004C4D
1254 #define WMI_TLV_ABI_VER_NS2 0x00000000
1255 #define WMI_TLV_ABI_VER_NS3 0x00000000
1256 
1257 #define WMI_TLV_ABI_VER0_MAJOR 1
1258 #define WMI_TLV_ABI_VER0_MINOR 0
1259 #define WMI_TLV_ABI_VER0 ((((WMI_TLV_ABI_VER0_MAJOR) << 24) & 0xFF000000) | \
1260 			  (((WMI_TLV_ABI_VER0_MINOR) <<  0) & 0x00FFFFFF))
1261 #define WMI_TLV_ABI_VER1 53
1262 
1263 static int
1264 ath10k_wmi_tlv_parse_mem_reqs(struct ath10k *ar, u16 tag, u16 len,
1265 			      const void *ptr, void *data)
1266 {
1267 	struct wmi_svc_rdy_ev_arg *arg = data;
1268 	int i;
1269 
1270 	if (tag != WMI_TLV_TAG_STRUCT_WLAN_HOST_MEM_REQ)
1271 		return -EPROTO;
1272 
1273 	for (i = 0; i < ARRAY_SIZE(arg->mem_reqs); i++) {
1274 		if (!arg->mem_reqs[i]) {
1275 			arg->mem_reqs[i] = ptr;
1276 			return 0;
1277 		}
1278 	}
1279 
1280 	return -ENOMEM;
1281 }
1282 
1283 struct wmi_tlv_svc_rdy_parse {
1284 	const struct hal_reg_capabilities *reg;
1285 	const struct wmi_tlv_svc_rdy_ev *ev;
1286 	const __le32 *svc_bmap;
1287 	const struct wlan_host_mem_req *mem_reqs;
1288 	bool svc_bmap_done;
1289 	bool dbs_hw_mode_done;
1290 };
1291 
1292 static int ath10k_wmi_tlv_svc_rdy_parse(struct ath10k *ar, u16 tag, u16 len,
1293 					const void *ptr, void *data)
1294 {
1295 	struct wmi_tlv_svc_rdy_parse *svc_rdy = data;
1296 
1297 	switch (tag) {
1298 	case WMI_TLV_TAG_STRUCT_SERVICE_READY_EVENT:
1299 		svc_rdy->ev = ptr;
1300 		break;
1301 	case WMI_TLV_TAG_STRUCT_HAL_REG_CAPABILITIES:
1302 		svc_rdy->reg = ptr;
1303 		break;
1304 	case WMI_TLV_TAG_ARRAY_STRUCT:
1305 		svc_rdy->mem_reqs = ptr;
1306 		break;
1307 	case WMI_TLV_TAG_ARRAY_UINT32:
1308 		if (!svc_rdy->svc_bmap_done) {
1309 			svc_rdy->svc_bmap_done = true;
1310 			svc_rdy->svc_bmap = ptr;
1311 		} else if (!svc_rdy->dbs_hw_mode_done) {
1312 			svc_rdy->dbs_hw_mode_done = true;
1313 		}
1314 		break;
1315 	default:
1316 		break;
1317 	}
1318 	return 0;
1319 }
1320 
1321 static int ath10k_wmi_tlv_op_pull_svc_rdy_ev(struct ath10k *ar,
1322 					     struct sk_buff *skb,
1323 					     struct wmi_svc_rdy_ev_arg *arg)
1324 {
1325 	const struct hal_reg_capabilities *reg;
1326 	const struct wmi_tlv_svc_rdy_ev *ev;
1327 	const __le32 *svc_bmap;
1328 	const struct wlan_host_mem_req *mem_reqs;
1329 	struct wmi_tlv_svc_rdy_parse svc_rdy = { };
1330 	int ret;
1331 
1332 	ret = ath10k_wmi_tlv_iter(ar, skb->data, skb->len,
1333 				  ath10k_wmi_tlv_svc_rdy_parse, &svc_rdy);
1334 	if (ret) {
1335 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1336 		return ret;
1337 	}
1338 
1339 	ev = svc_rdy.ev;
1340 	reg = svc_rdy.reg;
1341 	svc_bmap = svc_rdy.svc_bmap;
1342 	mem_reqs = svc_rdy.mem_reqs;
1343 
1344 	if (!ev || !reg || !svc_bmap || !mem_reqs)
1345 		return -EPROTO;
1346 
1347 	/* This is an internal ABI compatibility check for WMI TLV so check it
1348 	 * here instead of the generic WMI code.
1349 	 */
1350 	ath10k_dbg(ar, ATH10K_DBG_WMI,
1351 		   "wmi tlv abi 0x%08x ?= 0x%08x, 0x%08x ?= 0x%08x, 0x%08x ?= 0x%08x, 0x%08x ?= 0x%08x, 0x%08x ?= 0x%08x\n",
1352 		   __le32_to_cpu(ev->abi.abi_ver0), WMI_TLV_ABI_VER0,
1353 		   __le32_to_cpu(ev->abi.abi_ver_ns0), WMI_TLV_ABI_VER_NS0,
1354 		   __le32_to_cpu(ev->abi.abi_ver_ns1), WMI_TLV_ABI_VER_NS1,
1355 		   __le32_to_cpu(ev->abi.abi_ver_ns2), WMI_TLV_ABI_VER_NS2,
1356 		   __le32_to_cpu(ev->abi.abi_ver_ns3), WMI_TLV_ABI_VER_NS3);
1357 
1358 	if (__le32_to_cpu(ev->abi.abi_ver0) != WMI_TLV_ABI_VER0 ||
1359 	    __le32_to_cpu(ev->abi.abi_ver_ns0) != WMI_TLV_ABI_VER_NS0 ||
1360 	    __le32_to_cpu(ev->abi.abi_ver_ns1) != WMI_TLV_ABI_VER_NS1 ||
1361 	    __le32_to_cpu(ev->abi.abi_ver_ns2) != WMI_TLV_ABI_VER_NS2 ||
1362 	    __le32_to_cpu(ev->abi.abi_ver_ns3) != WMI_TLV_ABI_VER_NS3) {
1363 		return -ENOTSUPP;
1364 	}
1365 
1366 	arg->min_tx_power = ev->hw_min_tx_power;
1367 	arg->max_tx_power = ev->hw_max_tx_power;
1368 	arg->ht_cap = ev->ht_cap_info;
1369 	arg->vht_cap = ev->vht_cap_info;
1370 	arg->vht_supp_mcs = ev->vht_supp_mcs;
1371 	arg->sw_ver0 = ev->abi.abi_ver0;
1372 	arg->sw_ver1 = ev->abi.abi_ver1;
1373 	arg->fw_build = ev->fw_build_vers;
1374 	arg->phy_capab = ev->phy_capability;
1375 	arg->num_rf_chains = ev->num_rf_chains;
1376 	arg->eeprom_rd = reg->eeprom_rd;
1377 	arg->low_2ghz_chan = reg->low_2ghz_chan;
1378 	arg->high_2ghz_chan = reg->high_2ghz_chan;
1379 	arg->low_5ghz_chan = reg->low_5ghz_chan;
1380 	arg->high_5ghz_chan = reg->high_5ghz_chan;
1381 	arg->num_mem_reqs = ev->num_mem_reqs;
1382 	arg->service_map = svc_bmap;
1383 	arg->service_map_len = ath10k_wmi_tlv_len(svc_bmap);
1384 	arg->sys_cap_info = ev->sys_cap_info;
1385 
1386 #if defined(__linux__)
1387 	ret = ath10k_wmi_tlv_iter(ar, mem_reqs, ath10k_wmi_tlv_len(mem_reqs),
1388 #elif defined(__FreeBSD__)
1389 	ret = ath10k_wmi_tlv_iter(ar, (const u8 *)mem_reqs, ath10k_wmi_tlv_len(mem_reqs),
1390 #endif
1391 				  ath10k_wmi_tlv_parse_mem_reqs, arg);
1392 	if (ret) {
1393 		ath10k_warn(ar, "failed to parse mem_reqs tlv: %d\n", ret);
1394 		return ret;
1395 	}
1396 
1397 	return 0;
1398 }
1399 
1400 static int ath10k_wmi_tlv_op_pull_rdy_ev(struct ath10k *ar,
1401 					 struct sk_buff *skb,
1402 					 struct wmi_rdy_ev_arg *arg)
1403 {
1404 	const void **tb;
1405 	const struct wmi_tlv_rdy_ev *ev;
1406 	int ret;
1407 
1408 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1409 	if (IS_ERR(tb)) {
1410 		ret = PTR_ERR(tb);
1411 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1412 		return ret;
1413 	}
1414 
1415 	ev = tb[WMI_TLV_TAG_STRUCT_READY_EVENT];
1416 	if (!ev) {
1417 		kfree(tb);
1418 		return -EPROTO;
1419 	}
1420 
1421 	arg->sw_version = ev->abi.abi_ver0;
1422 	arg->abi_version = ev->abi.abi_ver1;
1423 	arg->status = ev->status;
1424 	arg->mac_addr = ev->mac_addr.addr;
1425 
1426 	kfree(tb);
1427 	return 0;
1428 }
1429 
1430 static int ath10k_wmi_tlv_svc_avail_parse(struct ath10k *ar, u16 tag, u16 len,
1431 					  const void *ptr, void *data)
1432 {
1433 	struct wmi_svc_avail_ev_arg *arg = data;
1434 
1435 	switch (tag) {
1436 	case WMI_TLV_TAG_STRUCT_SERVICE_AVAILABLE_EVENT:
1437 		arg->service_map_ext_valid = true;
1438 #if defined(__linux__)
1439 		arg->service_map_ext_len = *(__le32 *)ptr;
1440 		arg->service_map_ext = ptr + sizeof(__le32);
1441 #elif defined(__FreeBSD__)
1442 		arg->service_map_ext_len = *(const __le32 *)ptr;
1443 		arg->service_map_ext = (const __le32 *)((const u8 *)ptr + sizeof(__le32));
1444 #endif
1445 		return 0;
1446 	default:
1447 		break;
1448 	}
1449 
1450 	return 0;
1451 }
1452 
1453 static int ath10k_wmi_tlv_op_pull_svc_avail(struct ath10k *ar,
1454 					    struct sk_buff *skb,
1455 					    struct wmi_svc_avail_ev_arg *arg)
1456 {
1457 	int ret;
1458 
1459 	ret = ath10k_wmi_tlv_iter(ar, skb->data, skb->len,
1460 				  ath10k_wmi_tlv_svc_avail_parse, arg);
1461 
1462 	if (ret) {
1463 		ath10k_warn(ar, "failed to parse svc_avail tlv: %d\n", ret);
1464 		return ret;
1465 	}
1466 
1467 	return 0;
1468 }
1469 
1470 static void ath10k_wmi_tlv_pull_vdev_stats(const struct wmi_tlv_vdev_stats *src,
1471 					   struct ath10k_fw_stats_vdev *dst)
1472 {
1473 	int i;
1474 
1475 	dst->vdev_id = __le32_to_cpu(src->vdev_id);
1476 	dst->beacon_snr = __le32_to_cpu(src->beacon_snr);
1477 	dst->data_snr = __le32_to_cpu(src->data_snr);
1478 	dst->num_rx_frames = __le32_to_cpu(src->num_rx_frames);
1479 	dst->num_rts_fail = __le32_to_cpu(src->num_rts_fail);
1480 	dst->num_rts_success = __le32_to_cpu(src->num_rts_success);
1481 	dst->num_rx_err = __le32_to_cpu(src->num_rx_err);
1482 	dst->num_rx_discard = __le32_to_cpu(src->num_rx_discard);
1483 	dst->num_tx_not_acked = __le32_to_cpu(src->num_tx_not_acked);
1484 
1485 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames); i++)
1486 		dst->num_tx_frames[i] =
1487 			__le32_to_cpu(src->num_tx_frames[i]);
1488 
1489 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_retries); i++)
1490 		dst->num_tx_frames_retries[i] =
1491 			__le32_to_cpu(src->num_tx_frames_retries[i]);
1492 
1493 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_failures); i++)
1494 		dst->num_tx_frames_failures[i] =
1495 			__le32_to_cpu(src->num_tx_frames_failures[i]);
1496 
1497 	for (i = 0; i < ARRAY_SIZE(src->tx_rate_history); i++)
1498 		dst->tx_rate_history[i] =
1499 			__le32_to_cpu(src->tx_rate_history[i]);
1500 
1501 	for (i = 0; i < ARRAY_SIZE(src->beacon_rssi_history); i++)
1502 		dst->beacon_rssi_history[i] =
1503 			__le32_to_cpu(src->beacon_rssi_history[i]);
1504 }
1505 
1506 static int ath10k_wmi_tlv_op_pull_fw_stats(struct ath10k *ar,
1507 					   struct sk_buff *skb,
1508 					   struct ath10k_fw_stats *stats)
1509 {
1510 	const void **tb;
1511 	const struct wmi_tlv_stats_ev *ev;
1512 	u32 num_peer_stats_extd;
1513 #if defined(__linux__)
1514 	const void *data;
1515 #elif defined(__FreeBSD__)
1516 	const u8 *data;
1517 #endif
1518 	u32 num_pdev_stats;
1519 	u32 num_vdev_stats;
1520 	u32 num_peer_stats;
1521 	u32 num_bcnflt_stats;
1522 	u32 num_chan_stats;
1523 	size_t data_len;
1524 	u32 stats_id;
1525 	int ret;
1526 	int i;
1527 
1528 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1529 	if (IS_ERR(tb)) {
1530 		ret = PTR_ERR(tb);
1531 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1532 		return ret;
1533 	}
1534 
1535 	ev = tb[WMI_TLV_TAG_STRUCT_STATS_EVENT];
1536 	data = tb[WMI_TLV_TAG_ARRAY_BYTE];
1537 
1538 	if (!ev || !data) {
1539 		kfree(tb);
1540 		return -EPROTO;
1541 	}
1542 
1543 	data_len = ath10k_wmi_tlv_len(data);
1544 	num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
1545 	num_vdev_stats = __le32_to_cpu(ev->num_vdev_stats);
1546 	num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
1547 	num_bcnflt_stats = __le32_to_cpu(ev->num_bcnflt_stats);
1548 	num_chan_stats = __le32_to_cpu(ev->num_chan_stats);
1549 	stats_id = __le32_to_cpu(ev->stats_id);
1550 	num_peer_stats_extd = __le32_to_cpu(ev->num_peer_stats_extd);
1551 
1552 	ath10k_dbg(ar, ATH10K_DBG_WMI,
1553 		   "wmi tlv stats update pdev %i vdev %i peer %i bcnflt %i chan %i peer_extd %i\n",
1554 		   num_pdev_stats, num_vdev_stats, num_peer_stats,
1555 		   num_bcnflt_stats, num_chan_stats, num_peer_stats_extd);
1556 
1557 	for (i = 0; i < num_pdev_stats; i++) {
1558 		const struct wmi_pdev_stats *src;
1559 		struct ath10k_fw_stats_pdev *dst;
1560 
1561 #if defined(__linux__)
1562 		src = data;
1563 #elif defined(__FreeBSD__)
1564 		src = (const void *)data;
1565 #endif
1566 		if (data_len < sizeof(*src)) {
1567 			kfree(tb);
1568 			return -EPROTO;
1569 		}
1570 
1571 		data += sizeof(*src);
1572 		data_len -= sizeof(*src);
1573 
1574 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
1575 		if (!dst)
1576 			continue;
1577 
1578 		ath10k_wmi_pull_pdev_stats_base(&src->base, dst);
1579 		ath10k_wmi_pull_pdev_stats_tx(&src->tx, dst);
1580 		ath10k_wmi_pull_pdev_stats_rx(&src->rx, dst);
1581 		list_add_tail(&dst->list, &stats->pdevs);
1582 	}
1583 
1584 	for (i = 0; i < num_vdev_stats; i++) {
1585 		const struct wmi_tlv_vdev_stats *src;
1586 		struct ath10k_fw_stats_vdev *dst;
1587 
1588 #if defined(__linux__)
1589 		src = data;
1590 #elif defined(__FreeBSD__)
1591 		src = (const void *)data;
1592 #endif
1593 		if (data_len < sizeof(*src)) {
1594 			kfree(tb);
1595 			return -EPROTO;
1596 		}
1597 
1598 		data += sizeof(*src);
1599 		data_len -= sizeof(*src);
1600 
1601 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
1602 		if (!dst)
1603 			continue;
1604 
1605 		ath10k_wmi_tlv_pull_vdev_stats(src, dst);
1606 		list_add_tail(&dst->list, &stats->vdevs);
1607 	}
1608 
1609 	for (i = 0; i < num_peer_stats; i++) {
1610 		const struct wmi_10x_peer_stats *src;
1611 		struct ath10k_fw_stats_peer *dst;
1612 
1613 #if defined(__linux__)
1614 		src = data;
1615 #elif defined(__FreeBSD__)
1616 		src = (const void *)data;
1617 #endif
1618 		if (data_len < sizeof(*src)) {
1619 			kfree(tb);
1620 			return -EPROTO;
1621 		}
1622 
1623 		data += sizeof(*src);
1624 		data_len -= sizeof(*src);
1625 
1626 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
1627 		if (!dst)
1628 			continue;
1629 
1630 		ath10k_wmi_pull_peer_stats(&src->old, dst);
1631 		dst->peer_rx_rate = __le32_to_cpu(src->peer_rx_rate);
1632 
1633 		if (stats_id & WMI_TLV_STAT_PEER_EXTD) {
1634 			const struct wmi_tlv_peer_stats_extd *extd;
1635 			unsigned long rx_duration_high;
1636 
1637 #if defined(__linux__)
1638 			extd = data + sizeof(*src) * (num_peer_stats - i - 1)
1639 			       + sizeof(*extd) * i;
1640 #elif defined(__FreeBSD__)
1641 			extd = (const void *)(data + sizeof(*src) * (num_peer_stats - i - 1)
1642 			       + sizeof(*extd) * i);
1643 #endif
1644 
1645 			dst->rx_duration = __le32_to_cpu(extd->rx_duration);
1646 			rx_duration_high = __le32_to_cpu
1647 						(extd->rx_duration_high);
1648 
1649 			if (test_bit(WMI_TLV_PEER_RX_DURATION_HIGH_VALID_BIT,
1650 				     &rx_duration_high)) {
1651 				rx_duration_high =
1652 					FIELD_GET(WMI_TLV_PEER_RX_DURATION_HIGH_MASK,
1653 						  rx_duration_high);
1654 				dst->rx_duration |= (u64)rx_duration_high <<
1655 						    WMI_TLV_PEER_RX_DURATION_SHIFT;
1656 			}
1657 		}
1658 
1659 		list_add_tail(&dst->list, &stats->peers);
1660 	}
1661 
1662 	kfree(tb);
1663 	return 0;
1664 }
1665 
1666 static int ath10k_wmi_tlv_op_pull_roam_ev(struct ath10k *ar,
1667 					  struct sk_buff *skb,
1668 					  struct wmi_roam_ev_arg *arg)
1669 {
1670 	const void **tb;
1671 	const struct wmi_tlv_roam_ev *ev;
1672 	int ret;
1673 
1674 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1675 	if (IS_ERR(tb)) {
1676 		ret = PTR_ERR(tb);
1677 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1678 		return ret;
1679 	}
1680 
1681 	ev = tb[WMI_TLV_TAG_STRUCT_ROAM_EVENT];
1682 	if (!ev) {
1683 		kfree(tb);
1684 		return -EPROTO;
1685 	}
1686 
1687 	arg->vdev_id = ev->vdev_id;
1688 	arg->reason = ev->reason;
1689 	arg->rssi = ev->rssi;
1690 
1691 	kfree(tb);
1692 	return 0;
1693 }
1694 
1695 static int
1696 ath10k_wmi_tlv_op_pull_wow_ev(struct ath10k *ar, struct sk_buff *skb,
1697 			      struct wmi_wow_ev_arg *arg)
1698 {
1699 	const void **tb;
1700 	const struct wmi_tlv_wow_event_info *ev;
1701 	int ret;
1702 
1703 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1704 	if (IS_ERR(tb)) {
1705 		ret = PTR_ERR(tb);
1706 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1707 		return ret;
1708 	}
1709 
1710 	ev = tb[WMI_TLV_TAG_STRUCT_WOW_EVENT_INFO];
1711 	if (!ev) {
1712 		kfree(tb);
1713 		return -EPROTO;
1714 	}
1715 
1716 	arg->vdev_id = __le32_to_cpu(ev->vdev_id);
1717 	arg->flag = __le32_to_cpu(ev->flag);
1718 	arg->wake_reason = __le32_to_cpu(ev->wake_reason);
1719 	arg->data_len = __le32_to_cpu(ev->data_len);
1720 
1721 	kfree(tb);
1722 	return 0;
1723 }
1724 
1725 static int ath10k_wmi_tlv_op_pull_echo_ev(struct ath10k *ar,
1726 					  struct sk_buff *skb,
1727 					  struct wmi_echo_ev_arg *arg)
1728 {
1729 	const void **tb;
1730 	const struct wmi_echo_event *ev;
1731 	int ret;
1732 
1733 	tb = ath10k_wmi_tlv_parse_alloc(ar, skb->data, skb->len, GFP_ATOMIC);
1734 	if (IS_ERR(tb)) {
1735 		ret = PTR_ERR(tb);
1736 		ath10k_warn(ar, "failed to parse tlv: %d\n", ret);
1737 		return ret;
1738 	}
1739 
1740 	ev = tb[WMI_TLV_TAG_STRUCT_ECHO_EVENT];
1741 	if (!ev) {
1742 		kfree(tb);
1743 		return -EPROTO;
1744 	}
1745 
1746 	arg->value = ev->value;
1747 
1748 	kfree(tb);
1749 	return 0;
1750 }
1751 
1752 static struct sk_buff *
1753 ath10k_wmi_tlv_op_gen_pdev_suspend(struct ath10k *ar, u32 opt)
1754 {
1755 	struct wmi_tlv_pdev_suspend *cmd;
1756 	struct wmi_tlv *tlv;
1757 	struct sk_buff *skb;
1758 
1759 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1760 	if (!skb)
1761 		return ERR_PTR(-ENOMEM);
1762 
1763 	tlv = (void *)skb->data;
1764 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_SUSPEND_CMD);
1765 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1766 	cmd = (void *)tlv->value;
1767 	cmd->opt = __cpu_to_le32(opt);
1768 
1769 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev suspend\n");
1770 	return skb;
1771 }
1772 
1773 static struct sk_buff *
1774 ath10k_wmi_tlv_op_gen_pdev_resume(struct ath10k *ar)
1775 {
1776 	struct wmi_tlv_resume_cmd *cmd;
1777 	struct wmi_tlv *tlv;
1778 	struct sk_buff *skb;
1779 
1780 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1781 	if (!skb)
1782 		return ERR_PTR(-ENOMEM);
1783 
1784 	tlv = (void *)skb->data;
1785 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_RESUME_CMD);
1786 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1787 	cmd = (void *)tlv->value;
1788 	cmd->reserved = __cpu_to_le32(0);
1789 
1790 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev resume\n");
1791 	return skb;
1792 }
1793 
1794 static struct sk_buff *
1795 ath10k_wmi_tlv_op_gen_pdev_set_rd(struct ath10k *ar,
1796 				  u16 rd, u16 rd2g, u16 rd5g,
1797 				  u16 ctl2g, u16 ctl5g,
1798 				  enum wmi_dfs_region dfs_reg)
1799 {
1800 	struct wmi_tlv_pdev_set_rd_cmd *cmd;
1801 	struct wmi_tlv *tlv;
1802 	struct sk_buff *skb;
1803 
1804 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1805 	if (!skb)
1806 		return ERR_PTR(-ENOMEM);
1807 
1808 	tlv = (void *)skb->data;
1809 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_SET_REGDOMAIN_CMD);
1810 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1811 	cmd = (void *)tlv->value;
1812 	cmd->regd = __cpu_to_le32(rd);
1813 	cmd->regd_2ghz = __cpu_to_le32(rd2g);
1814 	cmd->regd_5ghz = __cpu_to_le32(rd5g);
1815 	cmd->conform_limit_2ghz = __cpu_to_le32(ctl2g);
1816 	cmd->conform_limit_5ghz = __cpu_to_le32(ctl5g);
1817 
1818 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev set rd\n");
1819 	return skb;
1820 }
1821 
1822 static enum wmi_txbf_conf ath10k_wmi_tlv_txbf_conf_scheme(struct ath10k *ar)
1823 {
1824 	return WMI_TXBF_CONF_AFTER_ASSOC;
1825 }
1826 
1827 static struct sk_buff *
1828 ath10k_wmi_tlv_op_gen_pdev_set_param(struct ath10k *ar, u32 param_id,
1829 				     u32 param_value)
1830 {
1831 	struct wmi_tlv_pdev_set_param_cmd *cmd;
1832 	struct wmi_tlv *tlv;
1833 	struct sk_buff *skb;
1834 
1835 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
1836 	if (!skb)
1837 		return ERR_PTR(-ENOMEM);
1838 
1839 	tlv = (void *)skb->data;
1840 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_SET_PARAM_CMD);
1841 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1842 	cmd = (void *)tlv->value;
1843 	cmd->param_id = __cpu_to_le32(param_id);
1844 	cmd->param_value = __cpu_to_le32(param_value);
1845 
1846 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev set param %d value 0x%x\n",
1847 		   param_id, param_value);
1848 	return skb;
1849 }
1850 
1851 static void
1852 #if defined(__linux__)
1853 ath10k_wmi_tlv_put_host_mem_chunks(struct ath10k *ar, void *host_mem_chunks)
1854 #elif defined(__FreeBSD__)
1855 ath10k_wmi_tlv_put_host_mem_chunks(struct ath10k *ar, u8 *host_mem_chunks)
1856 #endif
1857 {
1858 	struct host_memory_chunk_tlv *chunk;
1859 	struct wmi_tlv *tlv;
1860 	dma_addr_t paddr;
1861 	int i;
1862 	__le16 tlv_len, tlv_tag;
1863 
1864 	tlv_tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WLAN_HOST_MEMORY_CHUNK);
1865 	tlv_len = __cpu_to_le16(sizeof(*chunk));
1866 	for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
1867 #if defined(__linux__)
1868 		tlv = host_mem_chunks;
1869 #elif defined(__FreeBSD__)
1870 		tlv = (void *)host_mem_chunks;
1871 #endif
1872 		tlv->tag = tlv_tag;
1873 		tlv->len = tlv_len;
1874 		chunk = (void *)tlv->value;
1875 
1876 		chunk->ptr = __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
1877 		chunk->size = __cpu_to_le32(ar->wmi.mem_chunks[i].len);
1878 		chunk->req_id = __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
1879 
1880 		if (test_bit(WMI_SERVICE_SUPPORT_EXTEND_ADDRESS,
1881 			     ar->wmi.svc_map)) {
1882 			paddr = ar->wmi.mem_chunks[i].paddr;
1883 			chunk->ptr_high = __cpu_to_le32(upper_32_bits(paddr));
1884 		}
1885 
1886 		ath10k_dbg(ar, ATH10K_DBG_WMI,
1887 			   "wmi-tlv chunk %d len %d, addr 0x%llx, id 0x%x\n",
1888 			   i,
1889 			   ar->wmi.mem_chunks[i].len,
1890 			   (unsigned long long)ar->wmi.mem_chunks[i].paddr,
1891 			   ar->wmi.mem_chunks[i].req_id);
1892 
1893 		host_mem_chunks += sizeof(*tlv);
1894 		host_mem_chunks += sizeof(*chunk);
1895 	}
1896 }
1897 
1898 static struct sk_buff *ath10k_wmi_tlv_op_gen_init(struct ath10k *ar)
1899 {
1900 	struct sk_buff *skb;
1901 	struct wmi_tlv *tlv;
1902 	struct wmi_tlv_init_cmd *cmd;
1903 	struct wmi_tlv_resource_config *cfg;
1904 	void *chunks;
1905 	size_t len, chunks_len;
1906 #if defined(__linux__)
1907 	void *ptr;
1908 #elif defined(__FreeBSD__)
1909 	u8 *ptr;
1910 #endif
1911 
1912 	chunks_len = ar->wmi.num_mem_chunks *
1913 		     (sizeof(struct host_memory_chunk_tlv) + sizeof(*tlv));
1914 	len = (sizeof(*tlv) + sizeof(*cmd)) +
1915 	      (sizeof(*tlv) + sizeof(*cfg)) +
1916 	      (sizeof(*tlv) + chunks_len);
1917 
1918 	skb = ath10k_wmi_alloc_skb(ar, len);
1919 	if (!skb)
1920 		return ERR_PTR(-ENOMEM);
1921 
1922 #if defined(__linux__)
1923 	ptr = skb->data;
1924 
1925 	tlv = ptr;
1926 #elif defined(__FreeBSD__)
1927 	ptr = (u8 *)skb->data;
1928 	tlv = (void *)ptr;
1929 #endif
1930 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_INIT_CMD);
1931 	tlv->len = __cpu_to_le16(sizeof(*cmd));
1932 	cmd = (void *)tlv->value;
1933 	ptr += sizeof(*tlv);
1934 	ptr += sizeof(*cmd);
1935 
1936 #if defined(__linux__)
1937 	tlv = ptr;
1938 #elif defined(__FreeBSD__)
1939 	tlv = (void *)ptr;
1940 #endif
1941 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_RESOURCE_CONFIG);
1942 	tlv->len = __cpu_to_le16(sizeof(*cfg));
1943 	cfg = (void *)tlv->value;
1944 	ptr += sizeof(*tlv);
1945 	ptr += sizeof(*cfg);
1946 
1947 #if defined(__linux__)
1948 	tlv = ptr;
1949 #elif defined(__FreeBSD__)
1950 	tlv = (void *)ptr;
1951 #endif
1952 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
1953 	tlv->len = __cpu_to_le16(chunks_len);
1954 	chunks = (void *)tlv->value;
1955 
1956 	ptr += sizeof(*tlv);
1957 	ptr += chunks_len;
1958 
1959 	cmd->abi.abi_ver0 = __cpu_to_le32(WMI_TLV_ABI_VER0);
1960 	cmd->abi.abi_ver1 = __cpu_to_le32(WMI_TLV_ABI_VER1);
1961 	cmd->abi.abi_ver_ns0 = __cpu_to_le32(WMI_TLV_ABI_VER_NS0);
1962 	cmd->abi.abi_ver_ns1 = __cpu_to_le32(WMI_TLV_ABI_VER_NS1);
1963 	cmd->abi.abi_ver_ns2 = __cpu_to_le32(WMI_TLV_ABI_VER_NS2);
1964 	cmd->abi.abi_ver_ns3 = __cpu_to_le32(WMI_TLV_ABI_VER_NS3);
1965 	cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
1966 
1967 	cfg->num_vdevs = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1968 
1969 	if (ar->hw_params.num_peers)
1970 		cfg->num_peers = __cpu_to_le32(ar->hw_params.num_peers);
1971 	else
1972 		cfg->num_peers = __cpu_to_le32(TARGET_TLV_NUM_PEERS);
1973 	cfg->ast_skid_limit = __cpu_to_le32(ar->hw_params.ast_skid_limit);
1974 	cfg->num_wds_entries = __cpu_to_le32(ar->hw_params.num_wds_entries);
1975 
1976 	if (test_bit(WMI_SERVICE_RX_FULL_REORDER, ar->wmi.svc_map)) {
1977 		cfg->num_offload_peers = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1978 		cfg->num_offload_reorder_bufs = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1979 	} else {
1980 		cfg->num_offload_peers = __cpu_to_le32(0);
1981 		cfg->num_offload_reorder_bufs = __cpu_to_le32(0);
1982 	}
1983 
1984 	cfg->num_peer_keys = __cpu_to_le32(2);
1985 	if (ar->hw_params.num_peers)
1986 		cfg->num_tids = __cpu_to_le32(ar->hw_params.num_peers * 2);
1987 	else
1988 		cfg->num_tids = __cpu_to_le32(TARGET_TLV_NUM_TIDS);
1989 	cfg->tx_chain_mask = __cpu_to_le32(0x7);
1990 	cfg->rx_chain_mask = __cpu_to_le32(0x7);
1991 	cfg->rx_timeout_pri[0] = __cpu_to_le32(0x64);
1992 	cfg->rx_timeout_pri[1] = __cpu_to_le32(0x64);
1993 	cfg->rx_timeout_pri[2] = __cpu_to_le32(0x64);
1994 	cfg->rx_timeout_pri[3] = __cpu_to_le32(0x28);
1995 	cfg->rx_decap_mode = __cpu_to_le32(ar->wmi.rx_decap_mode);
1996 	cfg->scan_max_pending_reqs = __cpu_to_le32(4);
1997 	cfg->bmiss_offload_max_vdev = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1998 	cfg->roam_offload_max_vdev = __cpu_to_le32(TARGET_TLV_NUM_VDEVS);
1999 	cfg->roam_offload_max_ap_profiles = __cpu_to_le32(8);
2000 	cfg->num_mcast_groups = __cpu_to_le32(0);
2001 	cfg->num_mcast_table_elems = __cpu_to_le32(0);
2002 	cfg->mcast2ucast_mode = __cpu_to_le32(0);
2003 	cfg->tx_dbg_log_size = __cpu_to_le32(0x400);
2004 	cfg->dma_burst_size = __cpu_to_le32(0);
2005 	cfg->mac_aggr_delim = __cpu_to_le32(0);
2006 	cfg->rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(0);
2007 	cfg->vow_config = __cpu_to_le32(0);
2008 	cfg->gtk_offload_max_vdev = __cpu_to_le32(2);
2009 	cfg->num_msdu_desc = __cpu_to_le32(ar->htt.max_num_pending_tx);
2010 	cfg->max_frag_entries = __cpu_to_le32(2);
2011 	cfg->num_tdls_vdevs = __cpu_to_le32(TARGET_TLV_NUM_TDLS_VDEVS);
2012 	cfg->num_tdls_conn_table_entries = __cpu_to_le32(0x20);
2013 	cfg->beacon_tx_offload_max_vdev = __cpu_to_le32(2);
2014 	cfg->num_multicast_filter_entries = __cpu_to_le32(5);
2015 	cfg->num_wow_filters = __cpu_to_le32(ar->wow.max_num_patterns);
2016 	cfg->num_keep_alive_pattern = __cpu_to_le32(6);
2017 	cfg->keep_alive_pattern_size = __cpu_to_le32(0);
2018 	cfg->max_tdls_concurrent_sleep_sta = __cpu_to_le32(1);
2019 	cfg->max_tdls_concurrent_buffer_sta = __cpu_to_le32(1);
2020 	cfg->wmi_send_separate = __cpu_to_le32(0);
2021 	cfg->num_ocb_vdevs = __cpu_to_le32(0);
2022 	cfg->num_ocb_channels = __cpu_to_le32(0);
2023 	cfg->num_ocb_schedules = __cpu_to_le32(0);
2024 	cfg->host_capab = __cpu_to_le32(WMI_TLV_FLAG_MGMT_BUNDLE_TX_COMPL);
2025 
2026 	if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map))
2027 		cfg->host_capab |= __cpu_to_le32(WMI_RSRC_CFG_FLAG_TX_ACK_RSSI);
2028 
2029 	ath10k_wmi_tlv_put_host_mem_chunks(ar, chunks);
2030 
2031 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv init\n");
2032 	return skb;
2033 }
2034 
2035 static struct sk_buff *
2036 ath10k_wmi_tlv_op_gen_start_scan(struct ath10k *ar,
2037 				 const struct wmi_start_scan_arg *arg)
2038 {
2039 	struct wmi_tlv_start_scan_cmd *cmd;
2040 	struct wmi_tlv *tlv;
2041 	struct sk_buff *skb;
2042 	size_t len, chan_len, ssid_len, bssid_len, ie_len;
2043 	__le32 *chans;
2044 	struct wmi_ssid *ssids;
2045 	struct wmi_mac_addr *addrs;
2046 #if defined(__linux__)
2047 	void *ptr;
2048 #elif defined(__FreeBSD__)
2049 	u8 *ptr;
2050 #endif
2051 	int i, ret;
2052 
2053 	ret = ath10k_wmi_start_scan_verify(arg);
2054 	if (ret)
2055 		return ERR_PTR(ret);
2056 
2057 	chan_len = arg->n_channels * sizeof(__le32);
2058 	ssid_len = arg->n_ssids * sizeof(struct wmi_ssid);
2059 	bssid_len = arg->n_bssids * sizeof(struct wmi_mac_addr);
2060 	ie_len = roundup(arg->ie_len, 4);
2061 	len = (sizeof(*tlv) + sizeof(*cmd)) +
2062 	      sizeof(*tlv) + chan_len +
2063 	      sizeof(*tlv) + ssid_len +
2064 	      sizeof(*tlv) + bssid_len +
2065 	      sizeof(*tlv) + ie_len;
2066 
2067 	skb = ath10k_wmi_alloc_skb(ar, len);
2068 	if (!skb)
2069 		return ERR_PTR(-ENOMEM);
2070 
2071 #if defined(__linux__)
2072 	ptr = (void *)skb->data;
2073 	tlv = ptr;
2074 #elif defined(__FreeBSD__)
2075 	ptr = (u8 *)skb->data;
2076 	tlv = (void *)ptr;
2077 #endif
2078 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_START_SCAN_CMD);
2079 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2080 	cmd = (void *)tlv->value;
2081 
2082 	ath10k_wmi_put_start_scan_common(&cmd->common, arg);
2083 	cmd->burst_duration_ms = __cpu_to_le32(arg->burst_duration_ms);
2084 	cmd->num_channels = __cpu_to_le32(arg->n_channels);
2085 	cmd->num_ssids = __cpu_to_le32(arg->n_ssids);
2086 	cmd->num_bssids = __cpu_to_le32(arg->n_bssids);
2087 	cmd->ie_len = __cpu_to_le32(arg->ie_len);
2088 	cmd->num_probes = __cpu_to_le32(3);
2089 	ether_addr_copy(cmd->mac_addr.addr, arg->mac_addr.addr);
2090 	ether_addr_copy(cmd->mac_mask.addr, arg->mac_mask.addr);
2091 
2092 	/* FIXME: There are some scan flag inconsistencies across firmwares,
2093 	 * e.g. WMI-TLV inverts the logic behind the following flag.
2094 	 */
2095 	cmd->common.scan_ctrl_flags ^= __cpu_to_le32(WMI_SCAN_FILTER_PROBE_REQ);
2096 
2097 	ptr += sizeof(*tlv);
2098 	ptr += sizeof(*cmd);
2099 
2100 #if defined(__linux__)
2101 	tlv = ptr;
2102 #elif defined(__FreeBSD__)
2103 	tlv = (void *)ptr;
2104 #endif
2105 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
2106 	tlv->len = __cpu_to_le16(chan_len);
2107 	chans = (void *)tlv->value;
2108 	for (i = 0; i < arg->n_channels; i++)
2109 		chans[i] = __cpu_to_le32(arg->channels[i]);
2110 
2111 	ptr += sizeof(*tlv);
2112 	ptr += chan_len;
2113 
2114 #if defined(__linux__)
2115 	tlv = ptr;
2116 #elif defined(__FreeBSD__)
2117 	tlv = (void *)ptr;
2118 #endif
2119 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_FIXED_STRUCT);
2120 	tlv->len = __cpu_to_le16(ssid_len);
2121 	ssids = (void *)tlv->value;
2122 	for (i = 0; i < arg->n_ssids; i++) {
2123 		ssids[i].ssid_len = __cpu_to_le32(arg->ssids[i].len);
2124 		memcpy(ssids[i].ssid, arg->ssids[i].ssid, arg->ssids[i].len);
2125 	}
2126 
2127 	ptr += sizeof(*tlv);
2128 	ptr += ssid_len;
2129 
2130 #if defined(__linux__)
2131 	tlv = ptr;
2132 #elif defined(__FreeBSD__)
2133 	tlv = (void *)ptr;
2134 #endif
2135 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_FIXED_STRUCT);
2136 	tlv->len = __cpu_to_le16(bssid_len);
2137 	addrs = (void *)tlv->value;
2138 	for (i = 0; i < arg->n_bssids; i++)
2139 		ether_addr_copy(addrs[i].addr, arg->bssids[i].bssid);
2140 
2141 	ptr += sizeof(*tlv);
2142 	ptr += bssid_len;
2143 
2144 #if defined(__linux__)
2145 	tlv = ptr;
2146 #elif defined(__FreeBSD__)
2147 	tlv = (void *)ptr;
2148 #endif
2149 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
2150 	tlv->len = __cpu_to_le16(ie_len);
2151 	memcpy(tlv->value, arg->ie, arg->ie_len);
2152 
2153 #if defined(__linux__)
2154 	ptr += sizeof(*tlv);
2155 	ptr += ie_len;
2156 #endif
2157 
2158 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv start scan\n");
2159 	return skb;
2160 }
2161 
2162 static struct sk_buff *
2163 ath10k_wmi_tlv_op_gen_stop_scan(struct ath10k *ar,
2164 				const struct wmi_stop_scan_arg *arg)
2165 {
2166 	struct wmi_stop_scan_cmd *cmd;
2167 	struct wmi_tlv *tlv;
2168 	struct sk_buff *skb;
2169 	u32 scan_id;
2170 	u32 req_id;
2171 
2172 	if (arg->req_id > 0xFFF)
2173 		return ERR_PTR(-EINVAL);
2174 	if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
2175 		return ERR_PTR(-EINVAL);
2176 
2177 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2178 	if (!skb)
2179 		return ERR_PTR(-ENOMEM);
2180 
2181 	scan_id = arg->u.scan_id;
2182 	scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
2183 
2184 	req_id = arg->req_id;
2185 	req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
2186 
2187 	tlv = (void *)skb->data;
2188 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STOP_SCAN_CMD);
2189 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2190 	cmd = (void *)tlv->value;
2191 	cmd->req_type = __cpu_to_le32(arg->req_type);
2192 	cmd->vdev_id = __cpu_to_le32(arg->u.vdev_id);
2193 	cmd->scan_id = __cpu_to_le32(scan_id);
2194 	cmd->scan_req_id = __cpu_to_le32(req_id);
2195 
2196 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv stop scan\n");
2197 	return skb;
2198 }
2199 
2200 static int ath10k_wmi_tlv_op_get_vdev_subtype(struct ath10k *ar,
2201 					      enum wmi_vdev_subtype subtype)
2202 {
2203 	switch (subtype) {
2204 	case WMI_VDEV_SUBTYPE_NONE:
2205 		return WMI_TLV_VDEV_SUBTYPE_NONE;
2206 	case WMI_VDEV_SUBTYPE_P2P_DEVICE:
2207 		return WMI_TLV_VDEV_SUBTYPE_P2P_DEV;
2208 	case WMI_VDEV_SUBTYPE_P2P_CLIENT:
2209 		return WMI_TLV_VDEV_SUBTYPE_P2P_CLI;
2210 	case WMI_VDEV_SUBTYPE_P2P_GO:
2211 		return WMI_TLV_VDEV_SUBTYPE_P2P_GO;
2212 	case WMI_VDEV_SUBTYPE_PROXY_STA:
2213 		return WMI_TLV_VDEV_SUBTYPE_PROXY_STA;
2214 	case WMI_VDEV_SUBTYPE_MESH_11S:
2215 		return WMI_TLV_VDEV_SUBTYPE_MESH_11S;
2216 	case WMI_VDEV_SUBTYPE_MESH_NON_11S:
2217 		return -ENOTSUPP;
2218 	}
2219 	return -ENOTSUPP;
2220 }
2221 
2222 static struct sk_buff *
2223 ath10k_wmi_tlv_op_gen_vdev_create(struct ath10k *ar,
2224 				  u32 vdev_id,
2225 				  enum wmi_vdev_type vdev_type,
2226 				  enum wmi_vdev_subtype vdev_subtype,
2227 				  const u8 mac_addr[ETH_ALEN])
2228 {
2229 	struct wmi_vdev_create_cmd *cmd;
2230 	struct wmi_tlv *tlv;
2231 	struct sk_buff *skb;
2232 
2233 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2234 	if (!skb)
2235 		return ERR_PTR(-ENOMEM);
2236 
2237 	tlv = (void *)skb->data;
2238 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_CREATE_CMD);
2239 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2240 	cmd = (void *)tlv->value;
2241 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2242 	cmd->vdev_type = __cpu_to_le32(vdev_type);
2243 	cmd->vdev_subtype = __cpu_to_le32(vdev_subtype);
2244 	ether_addr_copy(cmd->vdev_macaddr.addr, mac_addr);
2245 
2246 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev create\n");
2247 	return skb;
2248 }
2249 
2250 static struct sk_buff *
2251 ath10k_wmi_tlv_op_gen_vdev_delete(struct ath10k *ar, u32 vdev_id)
2252 {
2253 	struct wmi_vdev_delete_cmd *cmd;
2254 	struct wmi_tlv *tlv;
2255 	struct sk_buff *skb;
2256 
2257 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2258 	if (!skb)
2259 		return ERR_PTR(-ENOMEM);
2260 
2261 	tlv = (void *)skb->data;
2262 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_DELETE_CMD);
2263 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2264 	cmd = (void *)tlv->value;
2265 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2266 
2267 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev delete\n");
2268 	return skb;
2269 }
2270 
2271 static struct sk_buff *
2272 ath10k_wmi_tlv_op_gen_vdev_start(struct ath10k *ar,
2273 				 const struct wmi_vdev_start_request_arg *arg,
2274 				 bool restart)
2275 {
2276 	struct wmi_tlv_vdev_start_cmd *cmd;
2277 	struct wmi_channel *ch;
2278 	struct wmi_tlv *tlv;
2279 	struct sk_buff *skb;
2280 	size_t len;
2281 #if defined(__linux__)
2282 	void *ptr;
2283 #elif defined(__FreeBSD__)
2284 	u8 *ptr;
2285 #endif
2286 	u32 flags = 0;
2287 
2288 	if (WARN_ON(arg->hidden_ssid && !arg->ssid))
2289 		return ERR_PTR(-EINVAL);
2290 	if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
2291 		return ERR_PTR(-EINVAL);
2292 
2293 	len = (sizeof(*tlv) + sizeof(*cmd)) +
2294 	      (sizeof(*tlv) + sizeof(*ch)) +
2295 	      (sizeof(*tlv) + 0);
2296 	skb = ath10k_wmi_alloc_skb(ar, len);
2297 	if (!skb)
2298 		return ERR_PTR(-ENOMEM);
2299 
2300 	if (arg->hidden_ssid)
2301 		flags |= WMI_VDEV_START_HIDDEN_SSID;
2302 	if (arg->pmf_enabled)
2303 		flags |= WMI_VDEV_START_PMF_ENABLED;
2304 
2305 #if defined(__linux__)
2306 	ptr = (void *)skb->data;
2307 
2308 	tlv = ptr;
2309 #elif defined(__FreeBSD__)
2310 	ptr = (u8 *)skb->data;
2311 	tlv = (void *)ptr;
2312 #endif
2313 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_START_REQUEST_CMD);
2314 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2315 	cmd = (void *)tlv->value;
2316 	cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
2317 	cmd->bcn_intval = __cpu_to_le32(arg->bcn_intval);
2318 	cmd->dtim_period = __cpu_to_le32(arg->dtim_period);
2319 	cmd->flags = __cpu_to_le32(flags);
2320 	cmd->bcn_tx_rate = __cpu_to_le32(arg->bcn_tx_rate);
2321 	cmd->bcn_tx_power = __cpu_to_le32(arg->bcn_tx_power);
2322 	cmd->disable_hw_ack = __cpu_to_le32(arg->disable_hw_ack);
2323 
2324 	if (arg->ssid) {
2325 		cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
2326 		memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
2327 	}
2328 
2329 	ptr += sizeof(*tlv);
2330 	ptr += sizeof(*cmd);
2331 
2332 #if defined(__linux__)
2333 	tlv = ptr;
2334 #elif defined(__FreeBSD__)
2335 	tlv = (void *)ptr;
2336 #endif
2337 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_CHANNEL);
2338 	tlv->len = __cpu_to_le16(sizeof(*ch));
2339 	ch = (void *)tlv->value;
2340 	ath10k_wmi_put_wmi_channel(ar, ch, &arg->channel);
2341 
2342 	ptr += sizeof(*tlv);
2343 	ptr += sizeof(*ch);
2344 
2345 #if defined(__linux__)
2346 	tlv = ptr;
2347 #elif defined(__FreeBSD__)
2348 	tlv = (void *)ptr;
2349 #endif
2350 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
2351 	tlv->len = 0;
2352 
2353 	/* Note: This is a nested TLV containing:
2354 	 * [wmi_tlv][wmi_p2p_noa_descriptor][wmi_tlv]..
2355 	 */
2356 
2357 #if defined(__linux__)
2358 	ptr += sizeof(*tlv);
2359 	ptr += 0;
2360 #endif
2361 
2362 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev start\n");
2363 	return skb;
2364 }
2365 
2366 static struct sk_buff *
2367 ath10k_wmi_tlv_op_gen_vdev_stop(struct ath10k *ar, u32 vdev_id)
2368 {
2369 	struct wmi_vdev_stop_cmd *cmd;
2370 	struct wmi_tlv *tlv;
2371 	struct sk_buff *skb;
2372 
2373 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2374 	if (!skb)
2375 		return ERR_PTR(-ENOMEM);
2376 
2377 	tlv = (void *)skb->data;
2378 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_STOP_CMD);
2379 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2380 	cmd = (void *)tlv->value;
2381 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2382 
2383 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev stop\n");
2384 	return skb;
2385 }
2386 
2387 static struct sk_buff *
2388 ath10k_wmi_tlv_op_gen_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid,
2389 			      const u8 *bssid)
2390 
2391 {
2392 	struct wmi_vdev_up_cmd *cmd;
2393 	struct wmi_tlv *tlv;
2394 	struct sk_buff *skb;
2395 
2396 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2397 	if (!skb)
2398 		return ERR_PTR(-ENOMEM);
2399 
2400 	tlv = (void *)skb->data;
2401 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_UP_CMD);
2402 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2403 	cmd = (void *)tlv->value;
2404 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2405 	cmd->vdev_assoc_id = __cpu_to_le32(aid);
2406 	ether_addr_copy(cmd->vdev_bssid.addr, bssid);
2407 
2408 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev up\n");
2409 	return skb;
2410 }
2411 
2412 static struct sk_buff *
2413 ath10k_wmi_tlv_op_gen_vdev_down(struct ath10k *ar, u32 vdev_id)
2414 {
2415 	struct wmi_vdev_down_cmd *cmd;
2416 	struct wmi_tlv *tlv;
2417 	struct sk_buff *skb;
2418 
2419 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2420 	if (!skb)
2421 		return ERR_PTR(-ENOMEM);
2422 
2423 	tlv = (void *)skb->data;
2424 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_DOWN_CMD);
2425 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2426 	cmd = (void *)tlv->value;
2427 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2428 
2429 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev down\n");
2430 	return skb;
2431 }
2432 
2433 static struct sk_buff *
2434 ath10k_wmi_tlv_op_gen_vdev_set_param(struct ath10k *ar, u32 vdev_id,
2435 				     u32 param_id, u32 param_value)
2436 {
2437 	struct wmi_vdev_set_param_cmd *cmd;
2438 	struct wmi_tlv *tlv;
2439 	struct sk_buff *skb;
2440 
2441 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2442 	if (!skb)
2443 		return ERR_PTR(-ENOMEM);
2444 
2445 	tlv = (void *)skb->data;
2446 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_SET_PARAM_CMD);
2447 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2448 	cmd = (void *)tlv->value;
2449 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2450 	cmd->param_id = __cpu_to_le32(param_id);
2451 	cmd->param_value = __cpu_to_le32(param_value);
2452 
2453 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev %d set param %d value 0x%x\n",
2454 		   vdev_id, param_id, param_value);
2455 	return skb;
2456 }
2457 
2458 static struct sk_buff *
2459 ath10k_wmi_tlv_op_gen_vdev_install_key(struct ath10k *ar,
2460 				       const struct wmi_vdev_install_key_arg *arg)
2461 {
2462 	struct wmi_vdev_install_key_cmd *cmd;
2463 	struct wmi_tlv *tlv;
2464 	struct sk_buff *skb;
2465 	size_t len;
2466 #if defined(__linux__)
2467 	void *ptr;
2468 #elif defined(__FreeBSD__)
2469 	u8 *ptr;
2470 #endif
2471 
2472 	if (arg->key_cipher == ar->wmi_key_cipher[WMI_CIPHER_NONE] &&
2473 	    arg->key_data)
2474 		return ERR_PTR(-EINVAL);
2475 	if (arg->key_cipher != ar->wmi_key_cipher[WMI_CIPHER_NONE] &&
2476 	    !arg->key_data)
2477 		return ERR_PTR(-EINVAL);
2478 
2479 	len = sizeof(*tlv) + sizeof(*cmd) +
2480 	      sizeof(*tlv) + roundup(arg->key_len, sizeof(__le32));
2481 	skb = ath10k_wmi_alloc_skb(ar, len);
2482 	if (!skb)
2483 		return ERR_PTR(-ENOMEM);
2484 
2485 #if defined(__linux__)
2486 	ptr = (void *)skb->data;
2487 	tlv = ptr;
2488 #elif defined(__FreeBSD__)
2489 	ptr = (u8 *)skb->data;
2490 	tlv = (void *)ptr;
2491 #endif
2492 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_INSTALL_KEY_CMD);
2493 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2494 	cmd = (void *)tlv->value;
2495 	cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
2496 	cmd->key_idx = __cpu_to_le32(arg->key_idx);
2497 	cmd->key_flags = __cpu_to_le32(arg->key_flags);
2498 	cmd->key_cipher = __cpu_to_le32(arg->key_cipher);
2499 	cmd->key_len = __cpu_to_le32(arg->key_len);
2500 	cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
2501 	cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
2502 
2503 	if (arg->macaddr)
2504 		ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr);
2505 
2506 	ptr += sizeof(*tlv);
2507 	ptr += sizeof(*cmd);
2508 
2509 #if defined(__linux__)
2510 	tlv = ptr;
2511 #elif defined(__FreeBSD__)
2512 	tlv = (void *)ptr;
2513 #endif
2514 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
2515 	tlv->len = __cpu_to_le16(roundup(arg->key_len, sizeof(__le32)));
2516 	if (arg->key_data)
2517 		memcpy(tlv->value, arg->key_data, arg->key_len);
2518 
2519 #if defined(__linux__)
2520 	ptr += sizeof(*tlv);
2521 	ptr += roundup(arg->key_len, sizeof(__le32));
2522 #endif
2523 
2524 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev install key\n");
2525 	return skb;
2526 }
2527 
2528 static void *ath10k_wmi_tlv_put_uapsd_ac(struct ath10k *ar, void *ptr,
2529 					 const struct wmi_sta_uapsd_auto_trig_arg *arg)
2530 {
2531 	struct wmi_sta_uapsd_auto_trig_param *ac;
2532 	struct wmi_tlv *tlv;
2533 
2534 	tlv = ptr;
2535 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_UAPSD_AUTO_TRIG_PARAM);
2536 	tlv->len = __cpu_to_le16(sizeof(*ac));
2537 	ac = (void *)tlv->value;
2538 
2539 	ac->wmm_ac = __cpu_to_le32(arg->wmm_ac);
2540 	ac->user_priority = __cpu_to_le32(arg->user_priority);
2541 	ac->service_interval = __cpu_to_le32(arg->service_interval);
2542 	ac->suspend_interval = __cpu_to_le32(arg->suspend_interval);
2543 	ac->delay_interval = __cpu_to_le32(arg->delay_interval);
2544 
2545 	ath10k_dbg(ar, ATH10K_DBG_WMI,
2546 		   "wmi tlv vdev sta uapsd auto trigger ac %d prio %d svc int %d susp int %d delay int %d\n",
2547 		   ac->wmm_ac, ac->user_priority, ac->service_interval,
2548 		   ac->suspend_interval, ac->delay_interval);
2549 
2550 #if defined(__linux__)
2551 	return ptr + sizeof(*tlv) + sizeof(*ac);
2552 #elif defined(__FreeBSD__)
2553 	return (u8 *)ptr + sizeof(*tlv) + sizeof(*ac);
2554 #endif
2555 }
2556 
2557 static struct sk_buff *
2558 ath10k_wmi_tlv_op_gen_vdev_sta_uapsd(struct ath10k *ar, u32 vdev_id,
2559 				     const u8 peer_addr[ETH_ALEN],
2560 				     const struct wmi_sta_uapsd_auto_trig_arg *args,
2561 				     u32 num_ac)
2562 {
2563 	struct wmi_sta_uapsd_auto_trig_cmd_fixed_param *cmd;
2564 	struct wmi_sta_uapsd_auto_trig_param *ac;
2565 	struct wmi_tlv *tlv;
2566 	struct sk_buff *skb;
2567 	size_t len;
2568 	size_t ac_tlv_len;
2569 #if defined(__linux__)
2570 	void *ptr;
2571 #elif defined(__FreeBSD__)
2572 	u8 *ptr;
2573 #endif
2574 	int i;
2575 
2576 	ac_tlv_len = num_ac * (sizeof(*tlv) + sizeof(*ac));
2577 	len = sizeof(*tlv) + sizeof(*cmd) +
2578 	      sizeof(*tlv) + ac_tlv_len;
2579 	skb = ath10k_wmi_alloc_skb(ar, len);
2580 	if (!skb)
2581 		return ERR_PTR(-ENOMEM);
2582 
2583 #if defined(__linux__)
2584 	ptr = (void *)skb->data;
2585 	tlv = ptr;
2586 #elif defined(__FreeBSD__)
2587 	ptr = (u8 *)skb->data;
2588 	tlv = (void *)ptr;
2589 #endif
2590 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_UAPSD_AUTO_TRIG_CMD);
2591 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2592 	cmd = (void *)tlv->value;
2593 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2594 	cmd->num_ac = __cpu_to_le32(num_ac);
2595 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
2596 
2597 	ptr += sizeof(*tlv);
2598 	ptr += sizeof(*cmd);
2599 
2600 #if defined(__linux__)
2601 	tlv = ptr;
2602 #elif defined(__FreeBSD__)
2603 	tlv = (void *)ptr;
2604 #endif
2605 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
2606 	tlv->len = __cpu_to_le16(ac_tlv_len);
2607 	ac = (void *)tlv->value;
2608 
2609 	ptr += sizeof(*tlv);
2610 	for (i = 0; i < num_ac; i++)
2611 		ptr = ath10k_wmi_tlv_put_uapsd_ac(ar, ptr, &args[i]);
2612 
2613 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev sta uapsd auto trigger\n");
2614 	return skb;
2615 }
2616 
2617 static void *ath10k_wmi_tlv_put_wmm(void *ptr,
2618 				    const struct wmi_wmm_params_arg *arg)
2619 {
2620 	struct wmi_wmm_params *wmm;
2621 	struct wmi_tlv *tlv;
2622 
2623 	tlv = ptr;
2624 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WMM_PARAMS);
2625 	tlv->len = __cpu_to_le16(sizeof(*wmm));
2626 	wmm = (void *)tlv->value;
2627 	ath10k_wmi_set_wmm_param(wmm, arg);
2628 
2629 #if defined(__linux__)
2630 	return ptr + sizeof(*tlv) + sizeof(*wmm);
2631 #elif defined(__FreeBSD__)
2632 	return (u8 *)ptr + sizeof(*tlv) + sizeof(*wmm);
2633 #endif
2634 }
2635 
2636 static struct sk_buff *
2637 ath10k_wmi_tlv_op_gen_vdev_wmm_conf(struct ath10k *ar, u32 vdev_id,
2638 				    const struct wmi_wmm_params_all_arg *arg)
2639 {
2640 	struct wmi_tlv_vdev_set_wmm_cmd *cmd;
2641 	struct wmi_tlv *tlv;
2642 	struct sk_buff *skb;
2643 	size_t len;
2644 	void *ptr;
2645 
2646 	len = sizeof(*tlv) + sizeof(*cmd);
2647 	skb = ath10k_wmi_alloc_skb(ar, len);
2648 	if (!skb)
2649 		return ERR_PTR(-ENOMEM);
2650 
2651 	ptr = (void *)skb->data;
2652 	tlv = ptr;
2653 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_SET_WMM_PARAMS_CMD);
2654 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2655 	cmd = (void *)tlv->value;
2656 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2657 
2658 	ath10k_wmi_set_wmm_param(&cmd->vdev_wmm_params[0].params, &arg->ac_be);
2659 	ath10k_wmi_set_wmm_param(&cmd->vdev_wmm_params[1].params, &arg->ac_bk);
2660 	ath10k_wmi_set_wmm_param(&cmd->vdev_wmm_params[2].params, &arg->ac_vi);
2661 	ath10k_wmi_set_wmm_param(&cmd->vdev_wmm_params[3].params, &arg->ac_vo);
2662 
2663 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv vdev wmm conf\n");
2664 	return skb;
2665 }
2666 
2667 static struct sk_buff *
2668 ath10k_wmi_tlv_op_gen_sta_keepalive(struct ath10k *ar,
2669 				    const struct wmi_sta_keepalive_arg *arg)
2670 {
2671 	struct wmi_tlv_sta_keepalive_cmd *cmd;
2672 	struct wmi_sta_keepalive_arp_resp *arp;
2673 	struct sk_buff *skb;
2674 	struct wmi_tlv *tlv;
2675 #if defined(__linux__)
2676 	void *ptr;
2677 #elif defined(__FreeBSD__)
2678 	u8 *ptr;
2679 #endif
2680 	size_t len;
2681 
2682 	len = sizeof(*tlv) + sizeof(*cmd) +
2683 	      sizeof(*tlv) + sizeof(*arp);
2684 	skb = ath10k_wmi_alloc_skb(ar, len);
2685 	if (!skb)
2686 		return ERR_PTR(-ENOMEM);
2687 
2688 #if defined(__linux__)
2689 	ptr = (void *)skb->data;
2690 	tlv = ptr;
2691 #elif defined(__FreeBSD__)
2692 	ptr = (u8 *)skb->data;
2693 	tlv = (void *)ptr;
2694 #endif
2695 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_KEEPALIVE_CMD);
2696 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2697 	cmd = (void *)tlv->value;
2698 	cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
2699 	cmd->enabled = __cpu_to_le32(arg->enabled);
2700 	cmd->method = __cpu_to_le32(arg->method);
2701 	cmd->interval = __cpu_to_le32(arg->interval);
2702 
2703 	ptr += sizeof(*tlv);
2704 	ptr += sizeof(*cmd);
2705 
2706 #if defined(__linux__)
2707 	tlv = ptr;
2708 #elif defined(__FreeBSD__)
2709 	tlv = (void *)ptr;
2710 #endif
2711 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_KEEPALVE_ARP_RESPONSE);
2712 	tlv->len = __cpu_to_le16(sizeof(*arp));
2713 	arp = (void *)tlv->value;
2714 
2715 	arp->src_ip4_addr = arg->src_ip4_addr;
2716 	arp->dest_ip4_addr = arg->dest_ip4_addr;
2717 	ether_addr_copy(arp->dest_mac_addr.addr, arg->dest_mac_addr);
2718 
2719 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv sta keepalive vdev %d enabled %d method %d interval %d\n",
2720 		   arg->vdev_id, arg->enabled, arg->method, arg->interval);
2721 	return skb;
2722 }
2723 
2724 static struct sk_buff *
2725 ath10k_wmi_tlv_op_gen_peer_create(struct ath10k *ar, u32 vdev_id,
2726 				  const u8 peer_addr[ETH_ALEN],
2727 				  enum wmi_peer_type peer_type)
2728 {
2729 	struct wmi_tlv_peer_create_cmd *cmd;
2730 	struct wmi_tlv *tlv;
2731 	struct sk_buff *skb;
2732 
2733 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2734 	if (!skb)
2735 		return ERR_PTR(-ENOMEM);
2736 
2737 	tlv = (void *)skb->data;
2738 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_CREATE_CMD);
2739 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2740 	cmd = (void *)tlv->value;
2741 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2742 	cmd->peer_type = __cpu_to_le32(peer_type);
2743 	ether_addr_copy(cmd->peer_addr.addr, peer_addr);
2744 
2745 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer create\n");
2746 	return skb;
2747 }
2748 
2749 static struct sk_buff *
2750 ath10k_wmi_tlv_op_gen_peer_delete(struct ath10k *ar, u32 vdev_id,
2751 				  const u8 peer_addr[ETH_ALEN])
2752 {
2753 	struct wmi_peer_delete_cmd *cmd;
2754 	struct wmi_tlv *tlv;
2755 	struct sk_buff *skb;
2756 
2757 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2758 	if (!skb)
2759 		return ERR_PTR(-ENOMEM);
2760 
2761 	tlv = (void *)skb->data;
2762 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_DELETE_CMD);
2763 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2764 	cmd = (void *)tlv->value;
2765 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2766 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
2767 
2768 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer delete\n");
2769 	return skb;
2770 }
2771 
2772 static struct sk_buff *
2773 ath10k_wmi_tlv_op_gen_peer_flush(struct ath10k *ar, u32 vdev_id,
2774 				 const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
2775 {
2776 	struct wmi_peer_flush_tids_cmd *cmd;
2777 	struct wmi_tlv *tlv;
2778 	struct sk_buff *skb;
2779 
2780 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2781 	if (!skb)
2782 		return ERR_PTR(-ENOMEM);
2783 
2784 	tlv = (void *)skb->data;
2785 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_FLUSH_TIDS_CMD);
2786 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2787 	cmd = (void *)tlv->value;
2788 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2789 	cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
2790 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
2791 
2792 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer flush\n");
2793 	return skb;
2794 }
2795 
2796 static struct sk_buff *
2797 ath10k_wmi_tlv_op_gen_peer_set_param(struct ath10k *ar, u32 vdev_id,
2798 				     const u8 *peer_addr,
2799 				     enum wmi_peer_param param_id,
2800 				     u32 param_value)
2801 {
2802 	struct wmi_peer_set_param_cmd *cmd;
2803 	struct wmi_tlv *tlv;
2804 	struct sk_buff *skb;
2805 
2806 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2807 	if (!skb)
2808 		return ERR_PTR(-ENOMEM);
2809 
2810 	tlv = (void *)skb->data;
2811 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_SET_PARAM_CMD);
2812 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2813 	cmd = (void *)tlv->value;
2814 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2815 	cmd->param_id = __cpu_to_le32(param_id);
2816 	cmd->param_value = __cpu_to_le32(param_value);
2817 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
2818 
2819 	ath10k_dbg(ar, ATH10K_DBG_WMI,
2820 		   "wmi tlv vdev %d peer %pM set param %d value 0x%x\n",
2821 		   vdev_id, peer_addr, param_id, param_value);
2822 	return skb;
2823 }
2824 
2825 static struct sk_buff *
2826 ath10k_wmi_tlv_op_gen_peer_assoc(struct ath10k *ar,
2827 				 const struct wmi_peer_assoc_complete_arg *arg)
2828 {
2829 	struct wmi_tlv_peer_assoc_cmd *cmd;
2830 	struct wmi_vht_rate_set *vht_rate;
2831 	struct wmi_tlv *tlv;
2832 	struct sk_buff *skb;
2833 	size_t len, legacy_rate_len, ht_rate_len;
2834 #if defined(__linux__)
2835 	void *ptr;
2836 #elif defined(__FreeBSD__)
2837 	u8 *ptr;
2838 #endif
2839 
2840 	if (arg->peer_mpdu_density > 16)
2841 		return ERR_PTR(-EINVAL);
2842 	if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
2843 		return ERR_PTR(-EINVAL);
2844 	if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
2845 		return ERR_PTR(-EINVAL);
2846 
2847 	legacy_rate_len = roundup(arg->peer_legacy_rates.num_rates,
2848 				  sizeof(__le32));
2849 	ht_rate_len = roundup(arg->peer_ht_rates.num_rates, sizeof(__le32));
2850 	len = (sizeof(*tlv) + sizeof(*cmd)) +
2851 	      (sizeof(*tlv) + legacy_rate_len) +
2852 	      (sizeof(*tlv) + ht_rate_len) +
2853 	      (sizeof(*tlv) + sizeof(*vht_rate));
2854 	skb = ath10k_wmi_alloc_skb(ar, len);
2855 	if (!skb)
2856 		return ERR_PTR(-ENOMEM);
2857 
2858 #if defined(__linux__)
2859 	ptr = (void *)skb->data;
2860 	tlv = ptr;
2861 #elif defined(__FreeBSD__)
2862 	ptr = (u8 *)skb->data;
2863 	tlv = (void *)ptr;
2864 #endif
2865 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PEER_ASSOC_COMPLETE_CMD);
2866 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2867 	cmd = (void *)tlv->value;
2868 
2869 	cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
2870 	cmd->new_assoc = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
2871 	cmd->assoc_id = __cpu_to_le32(arg->peer_aid);
2872 	cmd->flags = __cpu_to_le32(arg->peer_flags);
2873 	cmd->caps = __cpu_to_le32(arg->peer_caps);
2874 	cmd->listen_intval = __cpu_to_le32(arg->peer_listen_intval);
2875 	cmd->ht_caps = __cpu_to_le32(arg->peer_ht_caps);
2876 	cmd->max_mpdu = __cpu_to_le32(arg->peer_max_mpdu);
2877 	cmd->mpdu_density = __cpu_to_le32(arg->peer_mpdu_density);
2878 	cmd->rate_caps = __cpu_to_le32(arg->peer_rate_caps);
2879 	cmd->nss = __cpu_to_le32(arg->peer_num_spatial_streams);
2880 	cmd->vht_caps = __cpu_to_le32(arg->peer_vht_caps);
2881 	cmd->phy_mode = __cpu_to_le32(arg->peer_phymode);
2882 	cmd->num_legacy_rates = __cpu_to_le32(arg->peer_legacy_rates.num_rates);
2883 	cmd->num_ht_rates = __cpu_to_le32(arg->peer_ht_rates.num_rates);
2884 	ether_addr_copy(cmd->mac_addr.addr, arg->addr);
2885 
2886 	ptr += sizeof(*tlv);
2887 	ptr += sizeof(*cmd);
2888 
2889 #if defined(__linux__)
2890 	tlv = ptr;
2891 #elif defined(__FreeBSD__)
2892 	tlv = (void *)ptr;
2893 #endif
2894 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
2895 	tlv->len = __cpu_to_le16(legacy_rate_len);
2896 	memcpy(tlv->value, arg->peer_legacy_rates.rates,
2897 	       arg->peer_legacy_rates.num_rates);
2898 
2899 	ptr += sizeof(*tlv);
2900 	ptr += legacy_rate_len;
2901 
2902 #if defined(__linux__)
2903 	tlv = ptr;
2904 #elif defined(__FreeBSD__)
2905 	tlv = (void *)ptr;
2906 #endif
2907 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
2908 	tlv->len = __cpu_to_le16(ht_rate_len);
2909 	memcpy(tlv->value, arg->peer_ht_rates.rates,
2910 	       arg->peer_ht_rates.num_rates);
2911 
2912 	ptr += sizeof(*tlv);
2913 	ptr += ht_rate_len;
2914 
2915 #if defined(__linux__)
2916 	tlv = ptr;
2917 #elif defined(__FreeBSD__)
2918 	tlv = (void *)ptr;
2919 #endif
2920 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VHT_RATE_SET);
2921 	tlv->len = __cpu_to_le16(sizeof(*vht_rate));
2922 	vht_rate = (void *)tlv->value;
2923 
2924 	vht_rate->rx_max_rate = __cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
2925 	vht_rate->rx_mcs_set = __cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
2926 	vht_rate->tx_max_rate = __cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
2927 	vht_rate->tx_mcs_set = __cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
2928 
2929 #if defined(__linux__)
2930 	ptr += sizeof(*tlv);
2931 	ptr += sizeof(*vht_rate);
2932 #endif
2933 
2934 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv peer assoc\n");
2935 	return skb;
2936 }
2937 
2938 static struct sk_buff *
2939 ath10k_wmi_tlv_op_gen_set_psmode(struct ath10k *ar, u32 vdev_id,
2940 				 enum wmi_sta_ps_mode psmode)
2941 {
2942 	struct wmi_sta_powersave_mode_cmd *cmd;
2943 	struct wmi_tlv *tlv;
2944 	struct sk_buff *skb;
2945 
2946 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2947 	if (!skb)
2948 		return ERR_PTR(-ENOMEM);
2949 
2950 	tlv = (void *)skb->data;
2951 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_POWERSAVE_MODE_CMD);
2952 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2953 	cmd = (void *)tlv->value;
2954 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2955 	cmd->sta_ps_mode = __cpu_to_le32(psmode);
2956 
2957 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv set psmode\n");
2958 	return skb;
2959 }
2960 
2961 static struct sk_buff *
2962 ath10k_wmi_tlv_op_gen_set_sta_ps(struct ath10k *ar, u32 vdev_id,
2963 				 enum wmi_sta_powersave_param param_id,
2964 				 u32 param_value)
2965 {
2966 	struct wmi_sta_powersave_param_cmd *cmd;
2967 	struct wmi_tlv *tlv;
2968 	struct sk_buff *skb;
2969 
2970 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2971 	if (!skb)
2972 		return ERR_PTR(-ENOMEM);
2973 
2974 	tlv = (void *)skb->data;
2975 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_STA_POWERSAVE_PARAM_CMD);
2976 	tlv->len = __cpu_to_le16(sizeof(*cmd));
2977 	cmd = (void *)tlv->value;
2978 	cmd->vdev_id = __cpu_to_le32(vdev_id);
2979 	cmd->param_id = __cpu_to_le32(param_id);
2980 	cmd->param_value = __cpu_to_le32(param_value);
2981 
2982 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv set sta ps\n");
2983 	return skb;
2984 }
2985 
2986 static struct sk_buff *
2987 ath10k_wmi_tlv_op_gen_set_ap_ps(struct ath10k *ar, u32 vdev_id, const u8 *mac,
2988 				enum wmi_ap_ps_peer_param param_id, u32 value)
2989 {
2990 	struct wmi_ap_ps_peer_cmd *cmd;
2991 	struct wmi_tlv *tlv;
2992 	struct sk_buff *skb;
2993 
2994 	if (!mac)
2995 		return ERR_PTR(-EINVAL);
2996 
2997 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
2998 	if (!skb)
2999 		return ERR_PTR(-ENOMEM);
3000 
3001 	tlv = (void *)skb->data;
3002 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_AP_PS_PEER_CMD);
3003 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3004 	cmd = (void *)tlv->value;
3005 	cmd->vdev_id = __cpu_to_le32(vdev_id);
3006 	cmd->param_id = __cpu_to_le32(param_id);
3007 	cmd->param_value = __cpu_to_le32(value);
3008 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
3009 
3010 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv ap ps param\n");
3011 	return skb;
3012 }
3013 
3014 static struct sk_buff *
3015 ath10k_wmi_tlv_op_gen_scan_chan_list(struct ath10k *ar,
3016 				     const struct wmi_scan_chan_list_arg *arg)
3017 {
3018 	struct wmi_tlv_scan_chan_list_cmd *cmd;
3019 	struct wmi_channel *ci;
3020 	struct wmi_channel_arg *ch;
3021 	struct wmi_tlv *tlv;
3022 	struct sk_buff *skb;
3023 	size_t chans_len, len;
3024 	int i;
3025 #if defined(__linux__)
3026 	void *ptr, *chans;
3027 #elif defined(__FreeBSD__)
3028 	u8 *ptr, *chans;
3029 #endif
3030 
3031 	chans_len = arg->n_channels * (sizeof(*tlv) + sizeof(*ci));
3032 	len = (sizeof(*tlv) + sizeof(*cmd)) +
3033 	      (sizeof(*tlv) + chans_len);
3034 
3035 	skb = ath10k_wmi_alloc_skb(ar, len);
3036 	if (!skb)
3037 		return ERR_PTR(-ENOMEM);
3038 
3039 #if defined(__linux__)
3040 	ptr = (void *)skb->data;
3041 	tlv = ptr;
3042 #elif defined(__FreeBSD__)
3043 	ptr = (u8 *)skb->data;
3044 	tlv = (void *)ptr;
3045 #endif
3046 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_SCAN_CHAN_LIST_CMD);
3047 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3048 	cmd = (void *)tlv->value;
3049 	cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
3050 
3051 	ptr += sizeof(*tlv);
3052 	ptr += sizeof(*cmd);
3053 
3054 #if defined(__linux__)
3055 	tlv = ptr;
3056 #elif defined(__FreeBSD__)
3057 	tlv = (void *)ptr;
3058 #endif
3059 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
3060 	tlv->len = __cpu_to_le16(chans_len);
3061 	chans = (void *)tlv->value;
3062 
3063 	for (i = 0; i < arg->n_channels; i++) {
3064 		ch = &arg->channels[i];
3065 
3066 #if defined(__linux__)
3067 		tlv = chans;
3068 #elif defined(__FreeBSD__)
3069 		tlv = (void *)chans;
3070 #endif
3071 		tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_CHANNEL);
3072 		tlv->len = __cpu_to_le16(sizeof(*ci));
3073 		ci = (void *)tlv->value;
3074 
3075 		ath10k_wmi_put_wmi_channel(ar, ci, ch);
3076 
3077 		chans += sizeof(*tlv);
3078 		chans += sizeof(*ci);
3079 	}
3080 
3081 #if defined(__linux__)
3082 	ptr += sizeof(*tlv);
3083 	ptr += chans_len;
3084 #endif
3085 
3086 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv scan chan list\n");
3087 	return skb;
3088 }
3089 
3090 static struct sk_buff *
3091 ath10k_wmi_tlv_op_gen_scan_prob_req_oui(struct ath10k *ar, u32 prob_req_oui)
3092 {
3093 	struct wmi_scan_prob_req_oui_cmd *cmd;
3094 	struct wmi_tlv *tlv;
3095 	struct sk_buff *skb;
3096 
3097 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
3098 	if (!skb)
3099 		return ERR_PTR(-ENOMEM);
3100 
3101 	tlv = (void *)skb->data;
3102 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_SCAN_PROB_REQ_OUI_CMD);
3103 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3104 	cmd = (void *)tlv->value;
3105 	cmd->prob_req_oui = __cpu_to_le32(prob_req_oui);
3106 
3107 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv scan prob req oui\n");
3108 	return skb;
3109 }
3110 
3111 static struct sk_buff *
3112 ath10k_wmi_tlv_op_gen_beacon_dma(struct ath10k *ar, u32 vdev_id,
3113 				 const void *bcn, size_t bcn_len,
3114 				 u32 bcn_paddr, bool dtim_zero,
3115 				 bool deliver_cab)
3116 
3117 {
3118 	struct wmi_bcn_tx_ref_cmd *cmd;
3119 	struct wmi_tlv *tlv;
3120 	struct sk_buff *skb;
3121 #if defined(__linux__)
3122 	struct ieee80211_hdr *hdr;
3123 #elif defined(__FreeBSD__)
3124 	const struct ieee80211_hdr *hdr;
3125 #endif
3126 	u16 fc;
3127 
3128 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
3129 	if (!skb)
3130 		return ERR_PTR(-ENOMEM);
3131 
3132 #if defined(__linux__)
3133 	hdr = (struct ieee80211_hdr *)bcn;
3134 #elif defined(__FreeBSD__)
3135 	hdr = (const struct ieee80211_hdr *)bcn;
3136 #endif
3137 	fc = le16_to_cpu(hdr->frame_control);
3138 
3139 	tlv = (void *)skb->data;
3140 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_BCN_SEND_FROM_HOST_CMD);
3141 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3142 	cmd = (void *)tlv->value;
3143 	cmd->vdev_id = __cpu_to_le32(vdev_id);
3144 	cmd->data_len = __cpu_to_le32(bcn_len);
3145 	cmd->data_ptr = __cpu_to_le32(bcn_paddr);
3146 	cmd->msdu_id = 0;
3147 	cmd->frame_control = __cpu_to_le32(fc);
3148 	cmd->flags = 0;
3149 
3150 	if (dtim_zero)
3151 		cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DTIM_ZERO);
3152 
3153 	if (deliver_cab)
3154 		cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DELIVER_CAB);
3155 
3156 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv beacon dma\n");
3157 	return skb;
3158 }
3159 
3160 static struct sk_buff *
3161 ath10k_wmi_tlv_op_gen_pdev_set_wmm(struct ath10k *ar,
3162 				   const struct wmi_wmm_params_all_arg *arg)
3163 {
3164 	struct wmi_tlv_pdev_set_wmm_cmd *cmd;
3165 	struct wmi_wmm_params *wmm;
3166 	struct wmi_tlv *tlv;
3167 	struct sk_buff *skb;
3168 	size_t len;
3169 #if defined(__linux__)
3170 	void *ptr;
3171 #elif defined(__FreeBSD__)
3172 	u8 *ptr;
3173 #endif
3174 
3175 	len = (sizeof(*tlv) + sizeof(*cmd)) +
3176 	      (4 * (sizeof(*tlv) + sizeof(*wmm)));
3177 	skb = ath10k_wmi_alloc_skb(ar, len);
3178 	if (!skb)
3179 		return ERR_PTR(-ENOMEM);
3180 
3181 #if defined(__linux__)
3182 	ptr = (void *)skb->data;
3183 
3184 	tlv = ptr;
3185 #elif defined(__FreeBSD__)
3186 	ptr = (u8 *)skb->data;
3187 	tlv = (void *)ptr;
3188 #endif
3189 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_SET_WMM_PARAMS_CMD);
3190 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3191 	cmd = (void *)tlv->value;
3192 
3193 	/* nothing to set here */
3194 
3195 	ptr += sizeof(*tlv);
3196 	ptr += sizeof(*cmd);
3197 
3198 	ptr = ath10k_wmi_tlv_put_wmm(ptr, &arg->ac_be);
3199 	ptr = ath10k_wmi_tlv_put_wmm(ptr, &arg->ac_bk);
3200 	ptr = ath10k_wmi_tlv_put_wmm(ptr, &arg->ac_vi);
3201 	ptr = ath10k_wmi_tlv_put_wmm(ptr, &arg->ac_vo);
3202 
3203 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pdev set wmm\n");
3204 	return skb;
3205 }
3206 
3207 static struct sk_buff *
3208 ath10k_wmi_tlv_op_gen_request_stats(struct ath10k *ar, u32 stats_mask)
3209 {
3210 	struct wmi_request_stats_cmd *cmd;
3211 	struct wmi_tlv *tlv;
3212 	struct sk_buff *skb;
3213 
3214 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
3215 	if (!skb)
3216 		return ERR_PTR(-ENOMEM);
3217 
3218 	tlv = (void *)skb->data;
3219 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_REQUEST_STATS_CMD);
3220 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3221 	cmd = (void *)tlv->value;
3222 	cmd->stats_id = __cpu_to_le32(stats_mask);
3223 
3224 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv request stats\n");
3225 	return skb;
3226 }
3227 
3228 static struct sk_buff *
3229 ath10k_wmi_tlv_op_gen_request_peer_stats_info(struct ath10k *ar,
3230 					      u32 vdev_id,
3231 					      enum wmi_peer_stats_info_request_type type,
3232 					      u8 *addr,
3233 					      u32 reset)
3234 {
3235 	struct wmi_tlv_request_peer_stats_info *cmd;
3236 	struct wmi_tlv *tlv;
3237 	struct sk_buff *skb;
3238 
3239 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
3240 	if (!skb)
3241 		return ERR_PTR(-ENOMEM);
3242 
3243 	tlv = (void *)skb->data;
3244 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_REQUEST_PEER_STATS_INFO_CMD);
3245 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3246 	cmd = (void *)tlv->value;
3247 	cmd->vdev_id = __cpu_to_le32(vdev_id);
3248 	cmd->request_type = __cpu_to_le32(type);
3249 
3250 	if (type == WMI_REQUEST_ONE_PEER_STATS_INFO)
3251 		ether_addr_copy(cmd->peer_macaddr.addr, addr);
3252 
3253 	cmd->reset_after_request = __cpu_to_le32(reset);
3254 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv request peer stats info\n");
3255 	return skb;
3256 }
3257 
3258 static int
3259 ath10k_wmi_tlv_op_cleanup_mgmt_tx_send(struct ath10k *ar,
3260 				       struct sk_buff *msdu)
3261 {
3262 	struct ath10k_skb_cb *cb = ATH10K_SKB_CB(msdu);
3263 	struct ath10k_wmi *wmi = &ar->wmi;
3264 
3265 	idr_remove(&wmi->mgmt_pending_tx, cb->msdu_id);
3266 
3267 	return 0;
3268 }
3269 
3270 static int
3271 ath10k_wmi_mgmt_tx_alloc_msdu_id(struct ath10k *ar, struct sk_buff *skb,
3272 				 dma_addr_t paddr)
3273 {
3274 	struct ath10k_wmi *wmi = &ar->wmi;
3275 	struct ath10k_mgmt_tx_pkt_addr *pkt_addr;
3276 	int ret;
3277 
3278 	pkt_addr = kmalloc(sizeof(*pkt_addr), GFP_ATOMIC);
3279 	if (!pkt_addr)
3280 		return -ENOMEM;
3281 
3282 	pkt_addr->vaddr = skb;
3283 	pkt_addr->paddr = paddr;
3284 
3285 	spin_lock_bh(&ar->data_lock);
3286 	ret = idr_alloc(&wmi->mgmt_pending_tx, pkt_addr, 0,
3287 			wmi->mgmt_max_num_pending_tx, GFP_ATOMIC);
3288 	spin_unlock_bh(&ar->data_lock);
3289 
3290 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi mgmt tx alloc msdu_id ret %d\n", ret);
3291 	return ret;
3292 }
3293 
3294 static struct sk_buff *
3295 ath10k_wmi_tlv_op_gen_mgmt_tx_send(struct ath10k *ar, struct sk_buff *msdu,
3296 				   dma_addr_t paddr)
3297 {
3298 	struct ath10k_skb_cb *cb = ATH10K_SKB_CB(msdu);
3299 	struct wmi_tlv_mgmt_tx_cmd *cmd;
3300 	struct ieee80211_hdr *hdr;
3301 	struct ath10k_vif *arvif;
3302 	u32 buf_len = msdu->len;
3303 	struct wmi_tlv *tlv;
3304 	struct sk_buff *skb;
3305 	int len, desc_id;
3306 	u32 vdev_id;
3307 #if defined(__linux__)
3308 	void *ptr;
3309 #elif defined(__FreeBSD__)
3310 	u8 *ptr;
3311 #endif
3312 
3313 	if (!cb->vif)
3314 		return ERR_PTR(-EINVAL);
3315 
3316 	hdr = (struct ieee80211_hdr *)msdu->data;
3317 	arvif = (void *)cb->vif->drv_priv;
3318 	vdev_id = arvif->vdev_id;
3319 
3320 	if (WARN_ON_ONCE(!ieee80211_is_mgmt(hdr->frame_control) &&
3321 			 (!(ieee80211_is_nullfunc(hdr->frame_control) ||
3322 			 ieee80211_is_qos_nullfunc(hdr->frame_control)))))
3323 		return ERR_PTR(-EINVAL);
3324 
3325 	len = sizeof(*cmd) + 2 * sizeof(*tlv);
3326 
3327 	if ((ieee80211_is_action(hdr->frame_control) ||
3328 	     ieee80211_is_deauth(hdr->frame_control) ||
3329 	     ieee80211_is_disassoc(hdr->frame_control)) &&
3330 	     ieee80211_has_protected(hdr->frame_control)) {
3331 		skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
3332 		buf_len += IEEE80211_CCMP_MIC_LEN;
3333 	}
3334 
3335 	buf_len = min_t(u32, buf_len, WMI_TLV_MGMT_TX_FRAME_MAX_LEN);
3336 	buf_len = round_up(buf_len, 4);
3337 
3338 	len += buf_len;
3339 	len = round_up(len, 4);
3340 	skb = ath10k_wmi_alloc_skb(ar, len);
3341 	if (!skb)
3342 		return ERR_PTR(-ENOMEM);
3343 
3344 	desc_id = ath10k_wmi_mgmt_tx_alloc_msdu_id(ar, msdu, paddr);
3345 	if (desc_id < 0)
3346 		goto err_free_skb;
3347 
3348 	cb->msdu_id = desc_id;
3349 
3350 #if defined(__linux__)
3351 	ptr = (void *)skb->data;
3352 	tlv = ptr;
3353 #elif defined(__FreeBSD__)
3354 	ptr = (u8 *)skb->data;
3355 	tlv = (void *)ptr;
3356 #endif
3357 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_MGMT_TX_CMD);
3358 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3359 	cmd = (void *)tlv->value;
3360 	cmd->vdev_id = __cpu_to_le32(vdev_id);
3361 	cmd->desc_id = __cpu_to_le32(desc_id);
3362 	cmd->chanfreq = 0;
3363 	cmd->buf_len = __cpu_to_le32(buf_len);
3364 	cmd->frame_len = __cpu_to_le32(msdu->len);
3365 	cmd->paddr = __cpu_to_le64(paddr);
3366 
3367 	ptr += sizeof(*tlv);
3368 	ptr += sizeof(*cmd);
3369 
3370 #if defined(__linux__)
3371 	tlv = ptr;
3372 #elif defined(__FreeBSD__)
3373 	tlv = (void *)ptr;
3374 #endif
3375 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
3376 	tlv->len = __cpu_to_le16(buf_len);
3377 
3378 	ptr += sizeof(*tlv);
3379 	memcpy(ptr, msdu->data, buf_len);
3380 
3381 	return skb;
3382 
3383 err_free_skb:
3384 	dev_kfree_skb(skb);
3385 	return ERR_PTR(desc_id);
3386 }
3387 
3388 static struct sk_buff *
3389 ath10k_wmi_tlv_op_gen_force_fw_hang(struct ath10k *ar,
3390 				    enum wmi_force_fw_hang_type type,
3391 				    u32 delay_ms)
3392 {
3393 	struct wmi_force_fw_hang_cmd *cmd;
3394 	struct wmi_tlv *tlv;
3395 	struct sk_buff *skb;
3396 
3397 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
3398 	if (!skb)
3399 		return ERR_PTR(-ENOMEM);
3400 
3401 	tlv = (void *)skb->data;
3402 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_FORCE_FW_HANG_CMD);
3403 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3404 	cmd = (void *)tlv->value;
3405 	cmd->type = __cpu_to_le32(type);
3406 	cmd->delay_ms = __cpu_to_le32(delay_ms);
3407 
3408 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv force fw hang\n");
3409 	return skb;
3410 }
3411 
3412 static struct sk_buff *
3413 ath10k_wmi_tlv_op_gen_dbglog_cfg(struct ath10k *ar, u64 module_enable,
3414 				 u32 log_level)
3415 {
3416 	struct wmi_tlv_dbglog_cmd *cmd;
3417 	struct wmi_tlv *tlv;
3418 	struct sk_buff *skb;
3419 	size_t len, bmap_len;
3420 	u32 value;
3421 #if defined(__linux__)
3422 	void *ptr;
3423 #elif defined(__FreeBSD__)
3424 	u8 *ptr;
3425 #endif
3426 
3427 	if (module_enable) {
3428 		value = WMI_TLV_DBGLOG_LOG_LEVEL_VALUE(
3429 				module_enable,
3430 				WMI_TLV_DBGLOG_LOG_LEVEL_VERBOSE);
3431 	} else {
3432 		value = WMI_TLV_DBGLOG_LOG_LEVEL_VALUE(
3433 				WMI_TLV_DBGLOG_ALL_MODULES,
3434 				WMI_TLV_DBGLOG_LOG_LEVEL_WARN);
3435 	}
3436 
3437 	bmap_len = 0;
3438 	len = sizeof(*tlv) + sizeof(*cmd) + sizeof(*tlv) + bmap_len;
3439 	skb = ath10k_wmi_alloc_skb(ar, len);
3440 	if (!skb)
3441 		return ERR_PTR(-ENOMEM);
3442 
3443 #if defined(__linux__)
3444 	ptr = (void *)skb->data;
3445 
3446 	tlv = ptr;
3447 #elif defined(__FreeBSD__)
3448 	ptr = (u8 *)skb->data;
3449 	tlv = (void *)ptr;
3450 #endif
3451 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_DEBUG_LOG_CONFIG_CMD);
3452 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3453 	cmd = (void *)tlv->value;
3454 	cmd->param = __cpu_to_le32(WMI_TLV_DBGLOG_PARAM_LOG_LEVEL);
3455 	cmd->value = __cpu_to_le32(value);
3456 
3457 	ptr += sizeof(*tlv);
3458 	ptr += sizeof(*cmd);
3459 
3460 #if defined(__linux__)
3461 	tlv = ptr;
3462 #elif defined(__FreeBSD__)
3463 	tlv = (void *)ptr;
3464 #endif
3465 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
3466 	tlv->len = __cpu_to_le16(bmap_len);
3467 
3468 	/* nothing to do here */
3469 
3470 #if defined(__linux__)
3471 	ptr += sizeof(*tlv);
3472 	ptr += sizeof(bmap_len);
3473 #endif
3474 
3475 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv dbglog value 0x%08x\n", value);
3476 	return skb;
3477 }
3478 
3479 static struct sk_buff *
3480 ath10k_wmi_tlv_op_gen_pktlog_enable(struct ath10k *ar, u32 filter)
3481 {
3482 	struct wmi_tlv_pktlog_enable *cmd;
3483 	struct wmi_tlv *tlv;
3484 	struct sk_buff *skb;
3485 #if defined(__linux__)
3486 	void *ptr;
3487 #elif defined(__FreeBSD__)
3488 	u8 *ptr;
3489 #endif
3490 	size_t len;
3491 
3492 	len = sizeof(*tlv) + sizeof(*cmd);
3493 	skb = ath10k_wmi_alloc_skb(ar, len);
3494 	if (!skb)
3495 		return ERR_PTR(-ENOMEM);
3496 
3497 #if defined(__linux__)
3498 	ptr = (void *)skb->data;
3499 	tlv = ptr;
3500 #elif defined(__FreeBSD__)
3501 	ptr = (u8 *)skb->data;
3502 	tlv = (void *)ptr;
3503 #endif
3504 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_PKTLOG_ENABLE_CMD);
3505 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3506 	cmd = (void *)tlv->value;
3507 	cmd->filter = __cpu_to_le32(filter);
3508 
3509 #if defined(__linux__)
3510 	ptr += sizeof(*tlv);
3511 	ptr += sizeof(*cmd);
3512 #endif
3513 
3514 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pktlog enable filter 0x%08x\n",
3515 		   filter);
3516 	return skb;
3517 }
3518 
3519 static struct sk_buff *
3520 ath10k_wmi_tlv_op_gen_pdev_get_temperature(struct ath10k *ar)
3521 {
3522 	struct wmi_tlv_pdev_get_temp_cmd *cmd;
3523 	struct wmi_tlv *tlv;
3524 	struct sk_buff *skb;
3525 
3526 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
3527 	if (!skb)
3528 		return ERR_PTR(-ENOMEM);
3529 
3530 	tlv = (void *)skb->data;
3531 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_GET_TEMPERATURE_CMD);
3532 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3533 	cmd = (void *)tlv->value;
3534 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev get temperature tlv\n");
3535 	return skb;
3536 }
3537 
3538 static struct sk_buff *
3539 ath10k_wmi_tlv_op_gen_pktlog_disable(struct ath10k *ar)
3540 {
3541 	struct wmi_tlv_pktlog_disable *cmd;
3542 	struct wmi_tlv *tlv;
3543 	struct sk_buff *skb;
3544 #if defined(__linux__)
3545 	void *ptr;
3546 #elif defined(__FreeBSD__)
3547 	u8 *ptr;
3548 #endif
3549 	size_t len;
3550 
3551 	len = sizeof(*tlv) + sizeof(*cmd);
3552 	skb = ath10k_wmi_alloc_skb(ar, len);
3553 	if (!skb)
3554 		return ERR_PTR(-ENOMEM);
3555 
3556 #if defined(__linux__)
3557 	ptr = (void *)skb->data;
3558 	tlv = ptr;
3559 #elif defined(__FreeBSD__)
3560 	ptr = (u8 *)skb->data;
3561 	tlv = (void *)ptr;
3562 #endif
3563 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_PKTLOG_DISABLE_CMD);
3564 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3565 	cmd = (void *)tlv->value;
3566 
3567 #if defined(__linux__)
3568 	ptr += sizeof(*tlv);
3569 	ptr += sizeof(*cmd);
3570 #endif
3571 
3572 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv pktlog disable\n");
3573 	return skb;
3574 }
3575 
3576 static struct sk_buff *
3577 ath10k_wmi_tlv_op_gen_bcn_tmpl(struct ath10k *ar, u32 vdev_id,
3578 			       u32 tim_ie_offset, struct sk_buff *bcn,
3579 			       u32 prb_caps, u32 prb_erp, void *prb_ies,
3580 			       size_t prb_ies_len)
3581 {
3582 	struct wmi_tlv_bcn_tmpl_cmd *cmd;
3583 	struct wmi_tlv_bcn_prb_info *info;
3584 	struct wmi_tlv *tlv;
3585 	struct sk_buff *skb;
3586 #if defined(__linux__)
3587 	void *ptr;
3588 #elif defined(__FreeBSD__)
3589 	u8 *ptr;
3590 #endif
3591 	size_t len;
3592 
3593 	if (WARN_ON(prb_ies_len > 0 && !prb_ies))
3594 		return ERR_PTR(-EINVAL);
3595 
3596 	len = sizeof(*tlv) + sizeof(*cmd) +
3597 	      sizeof(*tlv) + sizeof(*info) + prb_ies_len +
3598 	      sizeof(*tlv) + roundup(bcn->len, 4);
3599 	skb = ath10k_wmi_alloc_skb(ar, len);
3600 	if (!skb)
3601 		return ERR_PTR(-ENOMEM);
3602 
3603 #if defined(__linux__)
3604 	ptr = (void *)skb->data;
3605 	tlv = ptr;
3606 #elif defined(__FreeBSD__)
3607 	ptr = (u8 *)skb->data;
3608 	tlv = (void *)ptr;
3609 #endif
3610 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_BCN_TMPL_CMD);
3611 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3612 	cmd = (void *)tlv->value;
3613 	cmd->vdev_id = __cpu_to_le32(vdev_id);
3614 	cmd->tim_ie_offset = __cpu_to_le32(tim_ie_offset);
3615 	cmd->buf_len = __cpu_to_le32(bcn->len);
3616 
3617 	ptr += sizeof(*tlv);
3618 	ptr += sizeof(*cmd);
3619 
3620 	/* FIXME: prb_ies_len should be probably aligned to 4byte boundary but
3621 	 * then it is then impossible to pass original ie len.
3622 	 * This chunk is not used yet so if setting probe resp template yields
3623 	 * problems with beaconing or crashes firmware look here.
3624 	 */
3625 #if defined(__linux__)
3626 	tlv = ptr;
3627 #elif defined(__FreeBSD__)
3628 	tlv = (void *)ptr;
3629 #endif
3630 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_BCN_PRB_INFO);
3631 	tlv->len = __cpu_to_le16(sizeof(*info) + prb_ies_len);
3632 	info = (void *)tlv->value;
3633 	info->caps = __cpu_to_le32(prb_caps);
3634 	info->erp = __cpu_to_le32(prb_erp);
3635 	memcpy(info->ies, prb_ies, prb_ies_len);
3636 
3637 	ptr += sizeof(*tlv);
3638 	ptr += sizeof(*info);
3639 	ptr += prb_ies_len;
3640 
3641 #if defined(__linux__)
3642 	tlv = ptr;
3643 #elif defined(__FreeBSD__)
3644 	tlv = (void *)ptr;
3645 #endif
3646 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
3647 	tlv->len = __cpu_to_le16(roundup(bcn->len, 4));
3648 	memcpy(tlv->value, bcn->data, bcn->len);
3649 
3650 	/* FIXME: Adjust TSF? */
3651 
3652 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv bcn tmpl vdev_id %i\n",
3653 		   vdev_id);
3654 	return skb;
3655 }
3656 
3657 static struct sk_buff *
3658 ath10k_wmi_tlv_op_gen_prb_tmpl(struct ath10k *ar, u32 vdev_id,
3659 			       struct sk_buff *prb)
3660 {
3661 	struct wmi_tlv_prb_tmpl_cmd *cmd;
3662 	struct wmi_tlv_bcn_prb_info *info;
3663 	struct wmi_tlv *tlv;
3664 	struct sk_buff *skb;
3665 #if defined(__linux__)
3666 	void *ptr;
3667 #elif defined(__FreeBSD__)
3668 	u8 *ptr;
3669 #endif
3670 	size_t len;
3671 
3672 	len = sizeof(*tlv) + sizeof(*cmd) +
3673 	      sizeof(*tlv) + sizeof(*info) +
3674 	      sizeof(*tlv) + roundup(prb->len, 4);
3675 	skb = ath10k_wmi_alloc_skb(ar, len);
3676 	if (!skb)
3677 		return ERR_PTR(-ENOMEM);
3678 
3679 #if defined(__linux__)
3680 	ptr = (void *)skb->data;
3681 	tlv = ptr;
3682 #elif defined(__FreeBSD__)
3683 	ptr = (u8 *)skb->data;
3684 	tlv = (void *)ptr;
3685 #endif
3686 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PRB_TMPL_CMD);
3687 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3688 	cmd = (void *)tlv->value;
3689 	cmd->vdev_id = __cpu_to_le32(vdev_id);
3690 	cmd->buf_len = __cpu_to_le32(prb->len);
3691 
3692 	ptr += sizeof(*tlv);
3693 	ptr += sizeof(*cmd);
3694 
3695 #if defined(__linux__)
3696 	tlv = ptr;
3697 #elif defined(__FreeBSD__)
3698 	tlv = (void *)ptr;
3699 #endif
3700 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_BCN_PRB_INFO);
3701 	tlv->len = __cpu_to_le16(sizeof(*info));
3702 	info = (void *)tlv->value;
3703 	info->caps = 0;
3704 	info->erp = 0;
3705 
3706 	ptr += sizeof(*tlv);
3707 	ptr += sizeof(*info);
3708 
3709 #if defined(__linux__)
3710 	tlv = ptr;
3711 #elif defined(__FreeBSD__)
3712 	tlv = (void *)ptr;
3713 #endif
3714 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
3715 	tlv->len = __cpu_to_le16(roundup(prb->len, 4));
3716 	memcpy(tlv->value, prb->data, prb->len);
3717 
3718 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv prb tmpl vdev_id %i\n",
3719 		   vdev_id);
3720 	return skb;
3721 }
3722 
3723 static struct sk_buff *
3724 ath10k_wmi_tlv_op_gen_p2p_go_bcn_ie(struct ath10k *ar, u32 vdev_id,
3725 				    const u8 *p2p_ie)
3726 {
3727 	struct wmi_tlv_p2p_go_bcn_ie *cmd;
3728 	struct wmi_tlv *tlv;
3729 	struct sk_buff *skb;
3730 #if defined(__linux__)
3731 	void *ptr;
3732 #elif defined(__FreeBSD__)
3733 	u8 *ptr;
3734 #endif
3735 	size_t len;
3736 
3737 	len = sizeof(*tlv) + sizeof(*cmd) +
3738 	      sizeof(*tlv) + roundup(p2p_ie[1] + 2, 4);
3739 	skb = ath10k_wmi_alloc_skb(ar, len);
3740 	if (!skb)
3741 		return ERR_PTR(-ENOMEM);
3742 
3743 #if defined(__linux__)
3744 	ptr = (void *)skb->data;
3745 	tlv = ptr;
3746 #elif defined(__FreeBSD__)
3747 	ptr = (u8 *)skb->data;
3748 	tlv = (void *)ptr;
3749 #endif
3750 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_P2P_GO_SET_BEACON_IE);
3751 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3752 	cmd = (void *)tlv->value;
3753 	cmd->vdev_id = __cpu_to_le32(vdev_id);
3754 	cmd->ie_len = __cpu_to_le32(p2p_ie[1] + 2);
3755 
3756 	ptr += sizeof(*tlv);
3757 	ptr += sizeof(*cmd);
3758 
3759 #if defined(__linux__)
3760 	tlv = ptr;
3761 #elif defined(__FreeBSD__)
3762 	tlv = (void *)ptr;
3763 #endif
3764 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
3765 	tlv->len = __cpu_to_le16(roundup(p2p_ie[1] + 2, 4));
3766 	memcpy(tlv->value, p2p_ie, p2p_ie[1] + 2);
3767 
3768 #if defined(__linux__)
3769 	ptr += sizeof(*tlv);
3770 	ptr += roundup(p2p_ie[1] + 2, 4);
3771 #endif
3772 
3773 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv p2p go bcn ie for vdev %i\n",
3774 		   vdev_id);
3775 	return skb;
3776 }
3777 
3778 static struct sk_buff *
3779 ath10k_wmi_tlv_op_gen_update_fw_tdls_state(struct ath10k *ar, u32 vdev_id,
3780 					   enum wmi_tdls_state state)
3781 {
3782 	struct wmi_tdls_set_state_cmd *cmd;
3783 	struct wmi_tlv *tlv;
3784 	struct sk_buff *skb;
3785 #if defined(__linux__)
3786 	void *ptr;
3787 #elif defined(__FreeBSD__)
3788 	u8 *ptr;
3789 #endif
3790 	size_t len;
3791 	/* Set to options from wmi_tlv_tdls_options,
3792 	 * for now none of them are enabled.
3793 	 */
3794 	u32 options = 0;
3795 
3796 	if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA, ar->wmi.svc_map))
3797 		options |=  WMI_TLV_TDLS_BUFFER_STA_EN;
3798 
3799 	/* WMI_TDLS_ENABLE_ACTIVE_EXTERNAL_CONTROL means firm will handle TDLS
3800 	 * link inactivity detecting logic.
3801 	 */
3802 	if (state == WMI_TDLS_ENABLE_ACTIVE)
3803 		state = WMI_TDLS_ENABLE_ACTIVE_EXTERNAL_CONTROL;
3804 
3805 	len = sizeof(*tlv) + sizeof(*cmd);
3806 	skb = ath10k_wmi_alloc_skb(ar, len);
3807 	if (!skb)
3808 		return ERR_PTR(-ENOMEM);
3809 
3810 #if defined(__linux__)
3811 	ptr = (void *)skb->data;
3812 	tlv = ptr;
3813 #elif defined(__FreeBSD__)
3814 	ptr = (u8 *)skb->data;
3815 	tlv = (void *)ptr;
3816 #endif
3817 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_TDLS_SET_STATE_CMD);
3818 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3819 
3820 	cmd = (void *)tlv->value;
3821 	cmd->vdev_id = __cpu_to_le32(vdev_id);
3822 	cmd->state = __cpu_to_le32(state);
3823 	cmd->notification_interval_ms = __cpu_to_le32(5000);
3824 	cmd->tx_discovery_threshold = __cpu_to_le32(100);
3825 	cmd->tx_teardown_threshold = __cpu_to_le32(5);
3826 	cmd->rssi_teardown_threshold = __cpu_to_le32(-75);
3827 	cmd->rssi_delta = __cpu_to_le32(-20);
3828 	cmd->tdls_options = __cpu_to_le32(options);
3829 	cmd->tdls_peer_traffic_ind_window = __cpu_to_le32(2);
3830 	cmd->tdls_peer_traffic_response_timeout_ms = __cpu_to_le32(5000);
3831 	cmd->tdls_puapsd_mask = __cpu_to_le32(0xf);
3832 	cmd->tdls_puapsd_inactivity_time_ms = __cpu_to_le32(0);
3833 	cmd->tdls_puapsd_rx_frame_threshold = __cpu_to_le32(10);
3834 
3835 #if defined(__linux__)
3836 	ptr += sizeof(*tlv);
3837 	ptr += sizeof(*cmd);
3838 #endif
3839 
3840 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv update fw tdls state %d for vdev %i\n",
3841 		   state, vdev_id);
3842 	return skb;
3843 }
3844 
3845 static u32 ath10k_wmi_tlv_prepare_peer_qos(u8 uapsd_queues, u8 sp)
3846 {
3847 	u32 peer_qos = 0;
3848 
3849 	if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
3850 		peer_qos |= WMI_TLV_TDLS_PEER_QOS_AC_VO;
3851 	if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
3852 		peer_qos |= WMI_TLV_TDLS_PEER_QOS_AC_VI;
3853 	if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
3854 		peer_qos |= WMI_TLV_TDLS_PEER_QOS_AC_BK;
3855 	if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
3856 		peer_qos |= WMI_TLV_TDLS_PEER_QOS_AC_BE;
3857 
3858 	peer_qos |= SM(sp, WMI_TLV_TDLS_PEER_SP);
3859 
3860 	return peer_qos;
3861 }
3862 
3863 static struct sk_buff *
3864 ath10k_wmi_tlv_op_gen_tdls_peer_update(struct ath10k *ar,
3865 				       const struct wmi_tdls_peer_update_cmd_arg *arg,
3866 				       const struct wmi_tdls_peer_capab_arg *cap,
3867 				       const struct wmi_channel_arg *chan_arg)
3868 {
3869 	struct wmi_tdls_peer_update_cmd *cmd;
3870 	struct wmi_tdls_peer_capab *peer_cap;
3871 	struct wmi_channel *chan;
3872 	struct wmi_tlv *tlv;
3873 	struct sk_buff *skb;
3874 	u32 peer_qos;
3875 #if defined(__linux__)
3876 	void *ptr;
3877 #elif defined(__FreeBSD__)
3878 	u8 *ptr;
3879 #endif
3880 	int len;
3881 	int i;
3882 
3883 	len = sizeof(*tlv) + sizeof(*cmd) +
3884 	      sizeof(*tlv) + sizeof(*peer_cap) +
3885 	      sizeof(*tlv) + cap->peer_chan_len * sizeof(*chan);
3886 
3887 	skb = ath10k_wmi_alloc_skb(ar, len);
3888 	if (!skb)
3889 		return ERR_PTR(-ENOMEM);
3890 
3891 #if defined(__linux__)
3892 	ptr = (void *)skb->data;
3893 	tlv = ptr;
3894 #elif defined(__FreeBSD__)
3895 	ptr = (u8 *)skb->data;
3896 	tlv = (void *)ptr;
3897 #endif
3898 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_TDLS_PEER_UPDATE_CMD);
3899 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3900 
3901 	cmd = (void *)tlv->value;
3902 	cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3903 	ether_addr_copy(cmd->peer_macaddr.addr, arg->addr);
3904 	cmd->peer_state = __cpu_to_le32(arg->peer_state);
3905 
3906 	ptr += sizeof(*tlv);
3907 	ptr += sizeof(*cmd);
3908 
3909 #if defined(__linux__)
3910 	tlv = ptr;
3911 #elif defined(__FreeBSD__)
3912 	tlv = (void *)ptr;
3913 #endif
3914 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_TDLS_PEER_CAPABILITIES);
3915 	tlv->len = __cpu_to_le16(sizeof(*peer_cap));
3916 	peer_cap = (void *)tlv->value;
3917 	peer_qos = ath10k_wmi_tlv_prepare_peer_qos(cap->peer_uapsd_queues,
3918 						   cap->peer_max_sp);
3919 	peer_cap->peer_qos = __cpu_to_le32(peer_qos);
3920 	peer_cap->buff_sta_support = __cpu_to_le32(cap->buff_sta_support);
3921 	peer_cap->off_chan_support = __cpu_to_le32(cap->off_chan_support);
3922 	peer_cap->peer_curr_operclass = __cpu_to_le32(cap->peer_curr_operclass);
3923 	peer_cap->self_curr_operclass = __cpu_to_le32(cap->self_curr_operclass);
3924 	peer_cap->peer_chan_len = __cpu_to_le32(cap->peer_chan_len);
3925 	peer_cap->peer_operclass_len = __cpu_to_le32(cap->peer_operclass_len);
3926 
3927 	for (i = 0; i < WMI_TDLS_MAX_SUPP_OPER_CLASSES; i++)
3928 		peer_cap->peer_operclass[i] = cap->peer_operclass[i];
3929 
3930 	peer_cap->is_peer_responder = __cpu_to_le32(cap->is_peer_responder);
3931 	peer_cap->pref_offchan_num = __cpu_to_le32(cap->pref_offchan_num);
3932 	peer_cap->pref_offchan_bw = __cpu_to_le32(cap->pref_offchan_bw);
3933 
3934 	ptr += sizeof(*tlv);
3935 	ptr += sizeof(*peer_cap);
3936 
3937 #if defined(__linux__)
3938 	tlv = ptr;
3939 #elif defined(__FreeBSD__)
3940 	tlv = (void *)ptr;
3941 #endif
3942 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
3943 	tlv->len = __cpu_to_le16(cap->peer_chan_len * sizeof(*chan));
3944 
3945 	ptr += sizeof(*tlv);
3946 
3947 	for (i = 0; i < cap->peer_chan_len; i++) {
3948 #if defined(__linux__)
3949 		tlv = ptr;
3950 #elif defined(__FreeBSD__)
3951 		tlv = (void *)ptr;
3952 #endif
3953 		tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_CHANNEL);
3954 		tlv->len = __cpu_to_le16(sizeof(*chan));
3955 		chan = (void *)tlv->value;
3956 		ath10k_wmi_put_wmi_channel(ar, chan, &chan_arg[i]);
3957 
3958 		ptr += sizeof(*tlv);
3959 		ptr += sizeof(*chan);
3960 	}
3961 
3962 	ath10k_dbg(ar, ATH10K_DBG_WMI,
3963 		   "wmi tlv tdls peer update vdev %i state %d n_chans %u\n",
3964 		   arg->vdev_id, arg->peer_state, cap->peer_chan_len);
3965 	return skb;
3966 }
3967 
3968 static struct sk_buff *
3969 ath10k_wmi_tlv_op_gen_pdev_set_quiet_mode(struct ath10k *ar, u32 period,
3970 					  u32 duration, u32 next_offset,
3971 					  u32 enabled)
3972 {
3973 	struct wmi_tlv_set_quiet_cmd *cmd;
3974 	struct wmi_tlv *tlv;
3975 	struct sk_buff *skb;
3976 
3977 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*tlv) + sizeof(*cmd));
3978 	if (!skb)
3979 		return ERR_PTR(-ENOMEM);
3980 
3981 	tlv = (void *)skb->data;
3982 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_PDEV_SET_QUIET_CMD);
3983 	tlv->len = __cpu_to_le16(sizeof(*cmd));
3984 	cmd = (void *)tlv->value;
3985 
3986 	/* vdev_id is not in use, set to 0 */
3987 	cmd->vdev_id = __cpu_to_le32(0);
3988 	cmd->period = __cpu_to_le32(period);
3989 	cmd->duration = __cpu_to_le32(duration);
3990 	cmd->next_start = __cpu_to_le32(next_offset);
3991 	cmd->enabled = __cpu_to_le32(enabled);
3992 
3993 	ath10k_dbg(ar, ATH10K_DBG_WMI,
3994 		   "wmi tlv quiet param: period %u duration %u enabled %d\n",
3995 		   period, duration, enabled);
3996 	return skb;
3997 }
3998 
3999 static struct sk_buff *
4000 ath10k_wmi_tlv_op_gen_wow_enable(struct ath10k *ar)
4001 {
4002 	struct wmi_tlv_wow_enable_cmd *cmd;
4003 	struct wmi_tlv *tlv;
4004 	struct sk_buff *skb;
4005 	size_t len;
4006 
4007 	len = sizeof(*tlv) + sizeof(*cmd);
4008 	skb = ath10k_wmi_alloc_skb(ar, len);
4009 	if (!skb)
4010 		return ERR_PTR(-ENOMEM);
4011 
4012 	tlv = (struct wmi_tlv *)skb->data;
4013 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_ENABLE_CMD);
4014 	tlv->len = __cpu_to_le16(sizeof(*cmd));
4015 	cmd = (void *)tlv->value;
4016 
4017 	cmd->enable = __cpu_to_le32(1);
4018 	if (!ar->bus_param.link_can_suspend)
4019 		cmd->pause_iface_config = __cpu_to_le32(WOW_IFACE_PAUSE_DISABLED);
4020 
4021 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow enable\n");
4022 	return skb;
4023 }
4024 
4025 static struct sk_buff *
4026 ath10k_wmi_tlv_op_gen_wow_add_wakeup_event(struct ath10k *ar,
4027 					   u32 vdev_id,
4028 					   enum wmi_wow_wakeup_event event,
4029 					   u32 enable)
4030 {
4031 	struct wmi_tlv_wow_add_del_event_cmd *cmd;
4032 	struct wmi_tlv *tlv;
4033 	struct sk_buff *skb;
4034 	size_t len;
4035 
4036 	len = sizeof(*tlv) + sizeof(*cmd);
4037 	skb = ath10k_wmi_alloc_skb(ar, len);
4038 	if (!skb)
4039 		return ERR_PTR(-ENOMEM);
4040 
4041 	tlv = (struct wmi_tlv *)skb->data;
4042 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_ADD_DEL_EVT_CMD);
4043 	tlv->len = __cpu_to_le16(sizeof(*cmd));
4044 	cmd = (void *)tlv->value;
4045 
4046 	cmd->vdev_id = __cpu_to_le32(vdev_id);
4047 	cmd->is_add = __cpu_to_le32(enable);
4048 	cmd->event_bitmap = __cpu_to_le32(1 << event);
4049 
4050 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow add wakeup event %s enable %d vdev_id %d\n",
4051 		   wow_wakeup_event(event), enable, vdev_id);
4052 	return skb;
4053 }
4054 
4055 static struct sk_buff *
4056 ath10k_wmi_tlv_gen_wow_host_wakeup_ind(struct ath10k *ar)
4057 {
4058 	struct wmi_tlv_wow_host_wakeup_ind *cmd;
4059 	struct wmi_tlv *tlv;
4060 	struct sk_buff *skb;
4061 	size_t len;
4062 
4063 	len = sizeof(*tlv) + sizeof(*cmd);
4064 	skb = ath10k_wmi_alloc_skb(ar, len);
4065 	if (!skb)
4066 		return ERR_PTR(-ENOMEM);
4067 
4068 	tlv = (struct wmi_tlv *)skb->data;
4069 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_HOSTWAKEUP_FROM_SLEEP_CMD);
4070 	tlv->len = __cpu_to_le16(sizeof(*cmd));
4071 	cmd = (void *)tlv->value;
4072 
4073 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow host wakeup ind\n");
4074 	return skb;
4075 }
4076 
4077 static struct sk_buff *
4078 ath10k_wmi_tlv_op_gen_wow_add_pattern(struct ath10k *ar, u32 vdev_id,
4079 				      u32 pattern_id, const u8 *pattern,
4080 				      const u8 *bitmask, int pattern_len,
4081 				      int pattern_offset)
4082 {
4083 	struct wmi_tlv_wow_add_pattern_cmd *cmd;
4084 	struct wmi_tlv_wow_bitmap_pattern *bitmap;
4085 	struct wmi_tlv *tlv;
4086 	struct sk_buff *skb;
4087 #if defined(__linux__)
4088 	void *ptr;
4089 #elif defined(__FreeBSD__)
4090 	u8 *ptr;
4091 #endif
4092 	size_t len;
4093 
4094 	len = sizeof(*tlv) + sizeof(*cmd) +
4095 	      sizeof(*tlv) +			/* array struct */
4096 	      sizeof(*tlv) + sizeof(*bitmap) +  /* bitmap */
4097 	      sizeof(*tlv) +			/* empty ipv4 sync */
4098 	      sizeof(*tlv) +			/* empty ipv6 sync */
4099 	      sizeof(*tlv) +			/* empty magic */
4100 	      sizeof(*tlv) +			/* empty info timeout */
4101 	      sizeof(*tlv) + sizeof(u32);	/* ratelimit interval */
4102 
4103 	skb = ath10k_wmi_alloc_skb(ar, len);
4104 	if (!skb)
4105 		return ERR_PTR(-ENOMEM);
4106 
4107 	/* cmd */
4108 #if defined(__linux__)
4109 	ptr = (void *)skb->data;
4110 	tlv = ptr;
4111 #elif defined(__FreeBSD__)
4112 	ptr = (u8 *)skb->data;
4113 	tlv = (void *)ptr;
4114 #endif
4115 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_ADD_PATTERN_CMD);
4116 	tlv->len = __cpu_to_le16(sizeof(*cmd));
4117 	cmd = (void *)tlv->value;
4118 
4119 	cmd->vdev_id = __cpu_to_le32(vdev_id);
4120 	cmd->pattern_id = __cpu_to_le32(pattern_id);
4121 	cmd->pattern_type = __cpu_to_le32(WOW_BITMAP_PATTERN);
4122 
4123 	ptr += sizeof(*tlv);
4124 	ptr += sizeof(*cmd);
4125 
4126 	/* bitmap */
4127 #if defined(__linux__)
4128 	tlv = ptr;
4129 #elif defined(__FreeBSD__)
4130 	tlv = (void *)ptr;
4131 #endif
4132 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
4133 	tlv->len = __cpu_to_le16(sizeof(*tlv) + sizeof(*bitmap));
4134 
4135 	ptr += sizeof(*tlv);
4136 
4137 #if defined(__linux__)
4138 	tlv = ptr;
4139 #elif defined(__FreeBSD__)
4140 	tlv = (void *)ptr;
4141 #endif
4142 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_BITMAP_PATTERN_T);
4143 	tlv->len = __cpu_to_le16(sizeof(*bitmap));
4144 	bitmap = (void *)tlv->value;
4145 
4146 	memcpy(bitmap->patternbuf, pattern, pattern_len);
4147 	memcpy(bitmap->bitmaskbuf, bitmask, pattern_len);
4148 	bitmap->pattern_offset = __cpu_to_le32(pattern_offset);
4149 	bitmap->pattern_len = __cpu_to_le32(pattern_len);
4150 	bitmap->bitmask_len = __cpu_to_le32(pattern_len);
4151 	bitmap->pattern_id = __cpu_to_le32(pattern_id);
4152 
4153 	ptr += sizeof(*tlv);
4154 	ptr += sizeof(*bitmap);
4155 
4156 	/* ipv4 sync */
4157 #if defined(__linux__)
4158 	tlv = ptr;
4159 #elif defined(__FreeBSD__)
4160 	tlv = (void *)ptr;
4161 #endif
4162 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
4163 	tlv->len = __cpu_to_le16(0);
4164 
4165 	ptr += sizeof(*tlv);
4166 
4167 	/* ipv6 sync */
4168 #if defined(__linux__)
4169 	tlv = ptr;
4170 #elif defined(__FreeBSD__)
4171 	tlv = (void *)ptr;
4172 #endif
4173 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
4174 	tlv->len = __cpu_to_le16(0);
4175 
4176 	ptr += sizeof(*tlv);
4177 
4178 	/* magic */
4179 #if defined(__linux__)
4180 	tlv = ptr;
4181 #elif defined(__FreeBSD__)
4182 	tlv = (void *)ptr;
4183 #endif
4184 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
4185 	tlv->len = __cpu_to_le16(0);
4186 
4187 	ptr += sizeof(*tlv);
4188 
4189 	/* pattern info timeout */
4190 #if defined(__linux__)
4191 	tlv = ptr;
4192 #elif defined(__FreeBSD__)
4193 	tlv = (void *)ptr;
4194 #endif
4195 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
4196 	tlv->len = __cpu_to_le16(0);
4197 
4198 	ptr += sizeof(*tlv);
4199 
4200 	/* ratelimit interval */
4201 #if defined(__linux__)
4202 	tlv = ptr;
4203 #elif defined(__FreeBSD__)
4204 	tlv = (void *)ptr;
4205 #endif
4206 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
4207 	tlv->len = __cpu_to_le16(sizeof(u32));
4208 
4209 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow add pattern vdev_id %d pattern_id %d, pattern_offset %d\n",
4210 		   vdev_id, pattern_id, pattern_offset);
4211 	return skb;
4212 }
4213 
4214 static struct sk_buff *
4215 ath10k_wmi_tlv_op_gen_wow_del_pattern(struct ath10k *ar, u32 vdev_id,
4216 				      u32 pattern_id)
4217 {
4218 	struct wmi_tlv_wow_del_pattern_cmd *cmd;
4219 	struct wmi_tlv *tlv;
4220 	struct sk_buff *skb;
4221 	size_t len;
4222 
4223 	len = sizeof(*tlv) + sizeof(*cmd);
4224 	skb = ath10k_wmi_alloc_skb(ar, len);
4225 	if (!skb)
4226 		return ERR_PTR(-ENOMEM);
4227 
4228 	tlv = (struct wmi_tlv *)skb->data;
4229 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_WOW_DEL_PATTERN_CMD);
4230 	tlv->len = __cpu_to_le16(sizeof(*cmd));
4231 	cmd = (void *)tlv->value;
4232 
4233 	cmd->vdev_id = __cpu_to_le32(vdev_id);
4234 	cmd->pattern_id = __cpu_to_le32(pattern_id);
4235 	cmd->pattern_type = __cpu_to_le32(WOW_BITMAP_PATTERN);
4236 
4237 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv wow del pattern vdev_id %d pattern_id %d\n",
4238 		   vdev_id, pattern_id);
4239 	return skb;
4240 }
4241 
4242 /* Request FW to start PNO operation */
4243 static struct sk_buff *
4244 ath10k_wmi_tlv_op_gen_config_pno_start(struct ath10k *ar,
4245 				       u32 vdev_id,
4246 				       struct wmi_pno_scan_req *pno)
4247 {
4248 	struct nlo_configured_parameters *nlo_list;
4249 	struct wmi_tlv_wow_nlo_config_cmd *cmd;
4250 	struct wmi_tlv *tlv;
4251 	struct sk_buff *skb;
4252 	__le32 *channel_list;
4253 	u16 tlv_len;
4254 	size_t len;
4255 #if defined(__linux__)
4256 	void *ptr;
4257 #elif defined(__FreeBSD__)
4258 	u8 *ptr;
4259 #endif
4260 	u32 i;
4261 
4262 	len = sizeof(*tlv) + sizeof(*cmd) +
4263 	      sizeof(*tlv) +
4264 	      /* TLV place holder for array of structures
4265 	       * nlo_configured_parameters(nlo_list)
4266 	       */
4267 	      sizeof(*tlv);
4268 	      /* TLV place holder for array of uint32 channel_list */
4269 
4270 	len += sizeof(u32) * min_t(u8, pno->a_networks[0].channel_count,
4271 				   WMI_NLO_MAX_CHAN);
4272 	len += sizeof(struct nlo_configured_parameters) *
4273 				min_t(u8, pno->uc_networks_count, WMI_NLO_MAX_SSIDS);
4274 
4275 	skb = ath10k_wmi_alloc_skb(ar, len);
4276 	if (!skb)
4277 		return ERR_PTR(-ENOMEM);
4278 
4279 #if defined(__linux__)
4280 	ptr = (void *)skb->data;
4281 	tlv = ptr;
4282 #elif defined(__FreeBSD__)
4283 	ptr = (u8 *)skb->data;
4284 	tlv = (void *)ptr;
4285 #endif
4286 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_NLO_CONFIG_CMD);
4287 	tlv->len = __cpu_to_le16(sizeof(*cmd));
4288 	cmd = (void *)tlv->value;
4289 
4290 	/* wmi_tlv_wow_nlo_config_cmd parameters*/
4291 	cmd->vdev_id = __cpu_to_le32(pno->vdev_id);
4292 	cmd->flags = __cpu_to_le32(WMI_NLO_CONFIG_START | WMI_NLO_CONFIG_SSID_HIDE_EN);
4293 
4294 	/* current FW does not support min-max range for dwell time */
4295 	cmd->active_dwell_time = __cpu_to_le32(pno->active_max_time);
4296 	cmd->passive_dwell_time = __cpu_to_le32(pno->passive_max_time);
4297 
4298 	if (pno->do_passive_scan)
4299 		cmd->flags |= __cpu_to_le32(WMI_NLO_CONFIG_SCAN_PASSIVE);
4300 
4301 	/* copy scan interval */
4302 	cmd->fast_scan_period = __cpu_to_le32(pno->fast_scan_period);
4303 	cmd->slow_scan_period = __cpu_to_le32(pno->slow_scan_period);
4304 	cmd->fast_scan_max_cycles = __cpu_to_le32(pno->fast_scan_max_cycles);
4305 	cmd->delay_start_time = __cpu_to_le32(pno->delay_start_time);
4306 
4307 	if (pno->enable_pno_scan_randomization) {
4308 		cmd->flags |= __cpu_to_le32(WMI_NLO_CONFIG_SPOOFED_MAC_IN_PROBE_REQ |
4309 				WMI_NLO_CONFIG_RANDOM_SEQ_NO_IN_PROBE_REQ);
4310 		ether_addr_copy(cmd->mac_addr.addr, pno->mac_addr);
4311 		ether_addr_copy(cmd->mac_mask.addr, pno->mac_addr_mask);
4312 	}
4313 
4314 	ptr += sizeof(*tlv);
4315 	ptr += sizeof(*cmd);
4316 
4317 	/* nlo_configured_parameters(nlo_list) */
4318 	cmd->no_of_ssids = __cpu_to_le32(min_t(u8, pno->uc_networks_count,
4319 					       WMI_NLO_MAX_SSIDS));
4320 	tlv_len = __le32_to_cpu(cmd->no_of_ssids) *
4321 		sizeof(struct nlo_configured_parameters);
4322 
4323 #if defined(__linux__)
4324 	tlv = ptr;
4325 #elif defined(__FreeBSD__)
4326 	tlv = (void *)ptr;
4327 #endif
4328 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
4329 	tlv->len = __cpu_to_le16(tlv_len);
4330 
4331 	ptr += sizeof(*tlv);
4332 #if defined(__linux__)
4333 	nlo_list = ptr;
4334 #elif defined(__FreeBSD__)
4335 	nlo_list = (void *)ptr;
4336 #endif
4337 	for (i = 0; i < __le32_to_cpu(cmd->no_of_ssids); i++) {
4338 		tlv = (struct wmi_tlv *)(&nlo_list[i].tlv_header);
4339 		tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_BYTE);
4340 		tlv->len = __cpu_to_le16(sizeof(struct nlo_configured_parameters) -
4341 					 sizeof(*tlv));
4342 
4343 		/* copy ssid and it's length */
4344 		nlo_list[i].ssid.valid = __cpu_to_le32(true);
4345 		nlo_list[i].ssid.ssid.ssid_len = pno->a_networks[i].ssid.ssid_len;
4346 		memcpy(nlo_list[i].ssid.ssid.ssid,
4347 		       pno->a_networks[i].ssid.ssid,
4348 		       __le32_to_cpu(nlo_list[i].ssid.ssid.ssid_len));
4349 
4350 		/* copy rssi threshold */
4351 		if (pno->a_networks[i].rssi_threshold &&
4352 		    pno->a_networks[i].rssi_threshold > -300) {
4353 			nlo_list[i].rssi_cond.valid = __cpu_to_le32(true);
4354 			nlo_list[i].rssi_cond.rssi =
4355 				__cpu_to_le32(pno->a_networks[i].rssi_threshold);
4356 		}
4357 
4358 		nlo_list[i].bcast_nw_type.valid = __cpu_to_le32(true);
4359 		nlo_list[i].bcast_nw_type.bcast_nw_type =
4360 			__cpu_to_le32(pno->a_networks[i].bcast_nw_type);
4361 	}
4362 
4363 	ptr += __le32_to_cpu(cmd->no_of_ssids) * sizeof(struct nlo_configured_parameters);
4364 
4365 	/* copy channel info */
4366 	cmd->num_of_channels = __cpu_to_le32(min_t(u8,
4367 						   pno->a_networks[0].channel_count,
4368 						   WMI_NLO_MAX_CHAN));
4369 
4370 #if defined(__linux__)
4371 	tlv = ptr;
4372 #elif defined(__FreeBSD__)
4373 	tlv = (void *)ptr;
4374 #endif
4375 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
4376 	tlv->len = __cpu_to_le16(__le32_to_cpu(cmd->num_of_channels) *
4377 				 sizeof(u_int32_t));
4378 	ptr += sizeof(*tlv);
4379 
4380 	channel_list = (__le32 *)ptr;
4381 	for (i = 0; i < __le32_to_cpu(cmd->num_of_channels); i++)
4382 		channel_list[i] = __cpu_to_le32(pno->a_networks[0].channels[i]);
4383 
4384 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv start pno config vdev_id %d\n",
4385 		   vdev_id);
4386 
4387 	return skb;
4388 }
4389 
4390 /* Request FW to stop ongoing PNO operation */
4391 static struct sk_buff *ath10k_wmi_tlv_op_gen_config_pno_stop(struct ath10k *ar,
4392 							     u32 vdev_id)
4393 {
4394 	struct wmi_tlv_wow_nlo_config_cmd *cmd;
4395 	struct wmi_tlv *tlv;
4396 	struct sk_buff *skb;
4397 #if defined(__linux__)
4398 	void *ptr;
4399 #elif defined(__FreeBSD__)
4400 	u8 *ptr;
4401 #endif
4402 	size_t len;
4403 
4404 	len = sizeof(*tlv) + sizeof(*cmd) +
4405 	      sizeof(*tlv) +
4406 	      /* TLV place holder for array of structures
4407 	       * nlo_configured_parameters(nlo_list)
4408 	       */
4409 	      sizeof(*tlv);
4410 	      /* TLV place holder for array of uint32 channel_list */
4411 	skb = ath10k_wmi_alloc_skb(ar, len);
4412 	if (!skb)
4413 		return ERR_PTR(-ENOMEM);
4414 
4415 #if defined(__linux__)
4416 	ptr = (void *)skb->data;
4417 	tlv = ptr;
4418 #elif defined(__FreeBSD__)
4419 	ptr = (u8 *)skb->data;
4420 	tlv = (void *)ptr;
4421 #endif
4422 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_NLO_CONFIG_CMD);
4423 	tlv->len = __cpu_to_le16(sizeof(*cmd));
4424 	cmd = (void *)tlv->value;
4425 
4426 	cmd->vdev_id = __cpu_to_le32(vdev_id);
4427 	cmd->flags = __cpu_to_le32(WMI_NLO_CONFIG_STOP);
4428 
4429 	ptr += sizeof(*tlv);
4430 	ptr += sizeof(*cmd);
4431 
4432 	/* nlo_configured_parameters(nlo_list) */
4433 #if defined(__linux__)
4434 	tlv = ptr;
4435 #elif defined(__FreeBSD__)
4436 	tlv = (void *)ptr;
4437 #endif
4438 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_STRUCT);
4439 	tlv->len = __cpu_to_le16(0);
4440 
4441 	ptr += sizeof(*tlv);
4442 
4443 	/* channel list */
4444 #if defined(__linux__)
4445 	tlv = ptr;
4446 #elif defined(__FreeBSD__)
4447 	tlv = (void *)ptr;
4448 #endif
4449 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_ARRAY_UINT32);
4450 	tlv->len = __cpu_to_le16(0);
4451 
4452 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv stop pno config vdev_id %d\n", vdev_id);
4453 	return skb;
4454 }
4455 
4456 static struct sk_buff *
4457 ath10k_wmi_tlv_op_gen_config_pno(struct ath10k *ar, u32 vdev_id,
4458 				 struct wmi_pno_scan_req *pno_scan)
4459 {
4460 	if (pno_scan->enable)
4461 		return ath10k_wmi_tlv_op_gen_config_pno_start(ar, vdev_id, pno_scan);
4462 	else
4463 		return ath10k_wmi_tlv_op_gen_config_pno_stop(ar, vdev_id);
4464 }
4465 
4466 static struct sk_buff *
4467 ath10k_wmi_tlv_op_gen_adaptive_qcs(struct ath10k *ar, bool enable)
4468 {
4469 	struct wmi_tlv_adaptive_qcs *cmd;
4470 	struct wmi_tlv *tlv;
4471 	struct sk_buff *skb;
4472 	void *ptr;
4473 	size_t len;
4474 
4475 	len = sizeof(*tlv) + sizeof(*cmd);
4476 	skb = ath10k_wmi_alloc_skb(ar, len);
4477 	if (!skb)
4478 		return ERR_PTR(-ENOMEM);
4479 
4480 	ptr = (void *)skb->data;
4481 	tlv = ptr;
4482 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_RESMGR_ADAPTIVE_OCS_CMD);
4483 	tlv->len = __cpu_to_le16(sizeof(*cmd));
4484 	cmd = (void *)tlv->value;
4485 	cmd->enable = __cpu_to_le32(enable ? 1 : 0);
4486 
4487 #if defined(__linux__)
4488 	ptr += sizeof(*tlv);
4489 	ptr += sizeof(*cmd);
4490 #endif
4491 
4492 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv adaptive qcs %d\n", enable);
4493 	return skb;
4494 }
4495 
4496 static struct sk_buff *
4497 ath10k_wmi_tlv_op_gen_echo(struct ath10k *ar, u32 value)
4498 {
4499 	struct wmi_echo_cmd *cmd;
4500 	struct wmi_tlv *tlv;
4501 	struct sk_buff *skb;
4502 	void *ptr;
4503 	size_t len;
4504 
4505 	len = sizeof(*tlv) + sizeof(*cmd);
4506 	skb = ath10k_wmi_alloc_skb(ar, len);
4507 	if (!skb)
4508 		return ERR_PTR(-ENOMEM);
4509 
4510 	ptr = (void *)skb->data;
4511 	tlv = ptr;
4512 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_ECHO_CMD);
4513 	tlv->len = __cpu_to_le16(sizeof(*cmd));
4514 	cmd = (void *)tlv->value;
4515 	cmd->value = cpu_to_le32(value);
4516 
4517 #if defined(__linux__)
4518 	ptr += sizeof(*tlv);
4519 	ptr += sizeof(*cmd);
4520 #endif
4521 
4522 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv echo value 0x%08x\n", value);
4523 	return skb;
4524 }
4525 
4526 static struct sk_buff *
4527 ath10k_wmi_tlv_op_gen_vdev_spectral_conf(struct ath10k *ar,
4528 					 const struct wmi_vdev_spectral_conf_arg *arg)
4529 {
4530 	struct wmi_vdev_spectral_conf_cmd *cmd;
4531 	struct sk_buff *skb;
4532 	struct wmi_tlv *tlv;
4533 	void *ptr;
4534 	size_t len;
4535 
4536 	len = sizeof(*tlv) + sizeof(*cmd);
4537 	skb = ath10k_wmi_alloc_skb(ar, len);
4538 	if (!skb)
4539 		return ERR_PTR(-ENOMEM);
4540 
4541 	ptr = (void *)skb->data;
4542 	tlv = ptr;
4543 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_SPECTRAL_CONFIGURE_CMD);
4544 	tlv->len = __cpu_to_le16(sizeof(*cmd));
4545 	cmd = (void *)tlv->value;
4546 	cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
4547 	cmd->scan_count = __cpu_to_le32(arg->scan_count);
4548 	cmd->scan_period = __cpu_to_le32(arg->scan_period);
4549 	cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
4550 	cmd->scan_fft_size = __cpu_to_le32(arg->scan_fft_size);
4551 	cmd->scan_gc_ena = __cpu_to_le32(arg->scan_gc_ena);
4552 	cmd->scan_restart_ena = __cpu_to_le32(arg->scan_restart_ena);
4553 	cmd->scan_noise_floor_ref = __cpu_to_le32(arg->scan_noise_floor_ref);
4554 	cmd->scan_init_delay = __cpu_to_le32(arg->scan_init_delay);
4555 	cmd->scan_nb_tone_thr = __cpu_to_le32(arg->scan_nb_tone_thr);
4556 	cmd->scan_str_bin_thr = __cpu_to_le32(arg->scan_str_bin_thr);
4557 	cmd->scan_wb_rpt_mode = __cpu_to_le32(arg->scan_wb_rpt_mode);
4558 	cmd->scan_rssi_rpt_mode = __cpu_to_le32(arg->scan_rssi_rpt_mode);
4559 	cmd->scan_rssi_thr = __cpu_to_le32(arg->scan_rssi_thr);
4560 	cmd->scan_pwr_format = __cpu_to_le32(arg->scan_pwr_format);
4561 	cmd->scan_rpt_mode = __cpu_to_le32(arg->scan_rpt_mode);
4562 	cmd->scan_bin_scale = __cpu_to_le32(arg->scan_bin_scale);
4563 	cmd->scan_dbm_adj = __cpu_to_le32(arg->scan_dbm_adj);
4564 	cmd->scan_chn_mask = __cpu_to_le32(arg->scan_chn_mask);
4565 
4566 	return skb;
4567 }
4568 
4569 static struct sk_buff *
4570 ath10k_wmi_tlv_op_gen_vdev_spectral_enable(struct ath10k *ar, u32 vdev_id,
4571 					   u32 trigger, u32 enable)
4572 {
4573 	struct wmi_vdev_spectral_enable_cmd *cmd;
4574 	struct sk_buff *skb;
4575 	struct wmi_tlv *tlv;
4576 	void *ptr;
4577 	size_t len;
4578 
4579 	len = sizeof(*tlv) + sizeof(*cmd);
4580 	skb = ath10k_wmi_alloc_skb(ar, len);
4581 	if (!skb)
4582 		return ERR_PTR(-ENOMEM);
4583 
4584 	ptr = (void *)skb->data;
4585 	tlv = ptr;
4586 	tlv->tag = __cpu_to_le16(WMI_TLV_TAG_STRUCT_VDEV_SPECTRAL_ENABLE_CMD);
4587 	tlv->len = __cpu_to_le16(sizeof(*cmd));
4588 	cmd = (void *)tlv->value;
4589 	cmd->vdev_id = __cpu_to_le32(vdev_id);
4590 	cmd->trigger_cmd = __cpu_to_le32(trigger);
4591 	cmd->enable_cmd = __cpu_to_le32(enable);
4592 
4593 	return skb;
4594 }
4595 
4596 /****************/
4597 /* TLV mappings */
4598 /****************/
4599 
4600 static struct wmi_cmd_map wmi_tlv_cmd_map = {
4601 	.init_cmdid = WMI_TLV_INIT_CMDID,
4602 	.start_scan_cmdid = WMI_TLV_START_SCAN_CMDID,
4603 	.stop_scan_cmdid = WMI_TLV_STOP_SCAN_CMDID,
4604 	.scan_chan_list_cmdid = WMI_TLV_SCAN_CHAN_LIST_CMDID,
4605 	.scan_sch_prio_tbl_cmdid = WMI_TLV_SCAN_SCH_PRIO_TBL_CMDID,
4606 	.scan_prob_req_oui_cmdid = WMI_TLV_SCAN_PROB_REQ_OUI_CMDID,
4607 	.pdev_set_regdomain_cmdid = WMI_TLV_PDEV_SET_REGDOMAIN_CMDID,
4608 	.pdev_set_channel_cmdid = WMI_TLV_PDEV_SET_CHANNEL_CMDID,
4609 	.pdev_set_param_cmdid = WMI_TLV_PDEV_SET_PARAM_CMDID,
4610 	.pdev_pktlog_enable_cmdid = WMI_TLV_PDEV_PKTLOG_ENABLE_CMDID,
4611 	.pdev_pktlog_disable_cmdid = WMI_TLV_PDEV_PKTLOG_DISABLE_CMDID,
4612 	.pdev_set_wmm_params_cmdid = WMI_TLV_PDEV_SET_WMM_PARAMS_CMDID,
4613 	.pdev_set_ht_cap_ie_cmdid = WMI_TLV_PDEV_SET_HT_CAP_IE_CMDID,
4614 	.pdev_set_vht_cap_ie_cmdid = WMI_TLV_PDEV_SET_VHT_CAP_IE_CMDID,
4615 	.pdev_set_dscp_tid_map_cmdid = WMI_TLV_PDEV_SET_DSCP_TID_MAP_CMDID,
4616 	.pdev_set_quiet_mode_cmdid = WMI_TLV_PDEV_SET_QUIET_MODE_CMDID,
4617 	.pdev_green_ap_ps_enable_cmdid = WMI_TLV_PDEV_GREEN_AP_PS_ENABLE_CMDID,
4618 	.pdev_get_tpc_config_cmdid = WMI_TLV_PDEV_GET_TPC_CONFIG_CMDID,
4619 	.pdev_set_base_macaddr_cmdid = WMI_TLV_PDEV_SET_BASE_MACADDR_CMDID,
4620 	.vdev_create_cmdid = WMI_TLV_VDEV_CREATE_CMDID,
4621 	.vdev_delete_cmdid = WMI_TLV_VDEV_DELETE_CMDID,
4622 	.vdev_start_request_cmdid = WMI_TLV_VDEV_START_REQUEST_CMDID,
4623 	.vdev_restart_request_cmdid = WMI_TLV_VDEV_RESTART_REQUEST_CMDID,
4624 	.vdev_up_cmdid = WMI_TLV_VDEV_UP_CMDID,
4625 	.vdev_stop_cmdid = WMI_TLV_VDEV_STOP_CMDID,
4626 	.vdev_down_cmdid = WMI_TLV_VDEV_DOWN_CMDID,
4627 	.vdev_set_param_cmdid = WMI_TLV_VDEV_SET_PARAM_CMDID,
4628 	.vdev_install_key_cmdid = WMI_TLV_VDEV_INSTALL_KEY_CMDID,
4629 	.peer_create_cmdid = WMI_TLV_PEER_CREATE_CMDID,
4630 	.peer_delete_cmdid = WMI_TLV_PEER_DELETE_CMDID,
4631 	.peer_flush_tids_cmdid = WMI_TLV_PEER_FLUSH_TIDS_CMDID,
4632 	.peer_set_param_cmdid = WMI_TLV_PEER_SET_PARAM_CMDID,
4633 	.peer_assoc_cmdid = WMI_TLV_PEER_ASSOC_CMDID,
4634 	.peer_add_wds_entry_cmdid = WMI_TLV_PEER_ADD_WDS_ENTRY_CMDID,
4635 	.peer_remove_wds_entry_cmdid = WMI_TLV_PEER_REMOVE_WDS_ENTRY_CMDID,
4636 	.peer_mcast_group_cmdid = WMI_TLV_PEER_MCAST_GROUP_CMDID,
4637 	.bcn_tx_cmdid = WMI_TLV_BCN_TX_CMDID,
4638 	.pdev_send_bcn_cmdid = WMI_TLV_PDEV_SEND_BCN_CMDID,
4639 	.bcn_tmpl_cmdid = WMI_TLV_BCN_TMPL_CMDID,
4640 	.bcn_filter_rx_cmdid = WMI_TLV_BCN_FILTER_RX_CMDID,
4641 	.prb_req_filter_rx_cmdid = WMI_TLV_PRB_REQ_FILTER_RX_CMDID,
4642 	.mgmt_tx_cmdid = WMI_TLV_MGMT_TX_CMDID,
4643 	.mgmt_tx_send_cmdid = WMI_TLV_MGMT_TX_SEND_CMD,
4644 	.prb_tmpl_cmdid = WMI_TLV_PRB_TMPL_CMDID,
4645 	.addba_clear_resp_cmdid = WMI_TLV_ADDBA_CLEAR_RESP_CMDID,
4646 	.addba_send_cmdid = WMI_TLV_ADDBA_SEND_CMDID,
4647 	.addba_status_cmdid = WMI_TLV_ADDBA_STATUS_CMDID,
4648 	.delba_send_cmdid = WMI_TLV_DELBA_SEND_CMDID,
4649 	.addba_set_resp_cmdid = WMI_TLV_ADDBA_SET_RESP_CMDID,
4650 	.send_singleamsdu_cmdid = WMI_TLV_SEND_SINGLEAMSDU_CMDID,
4651 	.sta_powersave_mode_cmdid = WMI_TLV_STA_POWERSAVE_MODE_CMDID,
4652 	.sta_powersave_param_cmdid = WMI_TLV_STA_POWERSAVE_PARAM_CMDID,
4653 	.sta_mimo_ps_mode_cmdid = WMI_TLV_STA_MIMO_PS_MODE_CMDID,
4654 	.pdev_dfs_enable_cmdid = WMI_TLV_PDEV_DFS_ENABLE_CMDID,
4655 	.pdev_dfs_disable_cmdid = WMI_TLV_PDEV_DFS_DISABLE_CMDID,
4656 	.roam_scan_mode = WMI_TLV_ROAM_SCAN_MODE,
4657 	.roam_scan_rssi_threshold = WMI_TLV_ROAM_SCAN_RSSI_THRESHOLD,
4658 	.roam_scan_period = WMI_TLV_ROAM_SCAN_PERIOD,
4659 	.roam_scan_rssi_change_threshold =
4660 				WMI_TLV_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
4661 	.roam_ap_profile = WMI_TLV_ROAM_AP_PROFILE,
4662 	.ofl_scan_add_ap_profile = WMI_TLV_ROAM_AP_PROFILE,
4663 	.ofl_scan_remove_ap_profile = WMI_TLV_OFL_SCAN_REMOVE_AP_PROFILE,
4664 	.ofl_scan_period = WMI_TLV_OFL_SCAN_PERIOD,
4665 	.p2p_dev_set_device_info = WMI_TLV_P2P_DEV_SET_DEVICE_INFO,
4666 	.p2p_dev_set_discoverability = WMI_TLV_P2P_DEV_SET_DISCOVERABILITY,
4667 	.p2p_go_set_beacon_ie = WMI_TLV_P2P_GO_SET_BEACON_IE,
4668 	.p2p_go_set_probe_resp_ie = WMI_TLV_P2P_GO_SET_PROBE_RESP_IE,
4669 	.p2p_set_vendor_ie_data_cmdid = WMI_TLV_P2P_SET_VENDOR_IE_DATA_CMDID,
4670 	.ap_ps_peer_param_cmdid = WMI_TLV_AP_PS_PEER_PARAM_CMDID,
4671 	.ap_ps_peer_uapsd_coex_cmdid = WMI_TLV_AP_PS_PEER_UAPSD_COEX_CMDID,
4672 	.peer_rate_retry_sched_cmdid = WMI_TLV_PEER_RATE_RETRY_SCHED_CMDID,
4673 	.wlan_profile_trigger_cmdid = WMI_TLV_WLAN_PROFILE_TRIGGER_CMDID,
4674 	.wlan_profile_set_hist_intvl_cmdid =
4675 				WMI_TLV_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
4676 	.wlan_profile_get_profile_data_cmdid =
4677 				WMI_TLV_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
4678 	.wlan_profile_enable_profile_id_cmdid =
4679 				WMI_TLV_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
4680 	.wlan_profile_list_profile_id_cmdid =
4681 				WMI_TLV_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
4682 	.pdev_suspend_cmdid = WMI_TLV_PDEV_SUSPEND_CMDID,
4683 	.pdev_resume_cmdid = WMI_TLV_PDEV_RESUME_CMDID,
4684 	.add_bcn_filter_cmdid = WMI_TLV_ADD_BCN_FILTER_CMDID,
4685 	.rmv_bcn_filter_cmdid = WMI_TLV_RMV_BCN_FILTER_CMDID,
4686 	.wow_add_wake_pattern_cmdid = WMI_TLV_WOW_ADD_WAKE_PATTERN_CMDID,
4687 	.wow_del_wake_pattern_cmdid = WMI_TLV_WOW_DEL_WAKE_PATTERN_CMDID,
4688 	.wow_enable_disable_wake_event_cmdid =
4689 				WMI_TLV_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
4690 	.wow_enable_cmdid = WMI_TLV_WOW_ENABLE_CMDID,
4691 	.wow_hostwakeup_from_sleep_cmdid =
4692 				WMI_TLV_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
4693 	.rtt_measreq_cmdid = WMI_TLV_RTT_MEASREQ_CMDID,
4694 	.rtt_tsf_cmdid = WMI_TLV_RTT_TSF_CMDID,
4695 	.vdev_spectral_scan_configure_cmdid = WMI_TLV_SPECTRAL_SCAN_CONF_CMDID,
4696 	.vdev_spectral_scan_enable_cmdid = WMI_TLV_SPECTRAL_SCAN_ENABLE_CMDID,
4697 	.request_stats_cmdid = WMI_TLV_REQUEST_STATS_CMDID,
4698 	.request_peer_stats_info_cmdid = WMI_TLV_REQUEST_PEER_STATS_INFO_CMDID,
4699 	.set_arp_ns_offload_cmdid = WMI_TLV_SET_ARP_NS_OFFLOAD_CMDID,
4700 	.network_list_offload_config_cmdid =
4701 				WMI_TLV_NETWORK_LIST_OFFLOAD_CONFIG_CMDID,
4702 	.gtk_offload_cmdid = WMI_TLV_GTK_OFFLOAD_CMDID,
4703 	.csa_offload_enable_cmdid = WMI_TLV_CSA_OFFLOAD_ENABLE_CMDID,
4704 	.csa_offload_chanswitch_cmdid = WMI_TLV_CSA_OFFLOAD_CHANSWITCH_CMDID,
4705 	.chatter_set_mode_cmdid = WMI_TLV_CHATTER_SET_MODE_CMDID,
4706 	.peer_tid_addba_cmdid = WMI_TLV_PEER_TID_ADDBA_CMDID,
4707 	.peer_tid_delba_cmdid = WMI_TLV_PEER_TID_DELBA_CMDID,
4708 	.sta_dtim_ps_method_cmdid = WMI_TLV_STA_DTIM_PS_METHOD_CMDID,
4709 	.sta_uapsd_auto_trig_cmdid = WMI_TLV_STA_UAPSD_AUTO_TRIG_CMDID,
4710 	.sta_keepalive_cmd = WMI_TLV_STA_KEEPALIVE_CMDID,
4711 	.echo_cmdid = WMI_TLV_ECHO_CMDID,
4712 	.pdev_utf_cmdid = WMI_TLV_PDEV_UTF_CMDID,
4713 	.dbglog_cfg_cmdid = WMI_TLV_DBGLOG_CFG_CMDID,
4714 	.pdev_qvit_cmdid = WMI_TLV_PDEV_QVIT_CMDID,
4715 	.pdev_ftm_intg_cmdid = WMI_TLV_PDEV_FTM_INTG_CMDID,
4716 	.vdev_set_keepalive_cmdid = WMI_TLV_VDEV_SET_KEEPALIVE_CMDID,
4717 	.vdev_get_keepalive_cmdid = WMI_TLV_VDEV_GET_KEEPALIVE_CMDID,
4718 	.force_fw_hang_cmdid = WMI_TLV_FORCE_FW_HANG_CMDID,
4719 	.gpio_config_cmdid = WMI_TLV_GPIO_CONFIG_CMDID,
4720 	.gpio_output_cmdid = WMI_TLV_GPIO_OUTPUT_CMDID,
4721 	.pdev_get_temperature_cmdid = WMI_TLV_PDEV_GET_TEMPERATURE_CMDID,
4722 	.vdev_set_wmm_params_cmdid = WMI_TLV_VDEV_SET_WMM_PARAMS_CMDID,
4723 	.tdls_set_state_cmdid = WMI_TLV_TDLS_SET_STATE_CMDID,
4724 	.tdls_peer_update_cmdid = WMI_TLV_TDLS_PEER_UPDATE_CMDID,
4725 	.adaptive_qcs_cmdid = WMI_TLV_RESMGR_ADAPTIVE_OCS_CMDID,
4726 	.scan_update_request_cmdid = WMI_CMD_UNSUPPORTED,
4727 	.vdev_standby_response_cmdid = WMI_CMD_UNSUPPORTED,
4728 	.vdev_resume_response_cmdid = WMI_CMD_UNSUPPORTED,
4729 	.wlan_peer_caching_add_peer_cmdid = WMI_CMD_UNSUPPORTED,
4730 	.wlan_peer_caching_evict_peer_cmdid = WMI_CMD_UNSUPPORTED,
4731 	.wlan_peer_caching_restore_peer_cmdid = WMI_CMD_UNSUPPORTED,
4732 	.wlan_peer_caching_print_all_peers_info_cmdid = WMI_CMD_UNSUPPORTED,
4733 	.peer_update_wds_entry_cmdid = WMI_CMD_UNSUPPORTED,
4734 	.peer_add_proxy_sta_entry_cmdid = WMI_CMD_UNSUPPORTED,
4735 	.rtt_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
4736 	.oem_req_cmdid = WMI_CMD_UNSUPPORTED,
4737 	.nan_cmdid = WMI_CMD_UNSUPPORTED,
4738 	.vdev_ratemask_cmdid = WMI_CMD_UNSUPPORTED,
4739 	.qboost_cfg_cmdid = WMI_CMD_UNSUPPORTED,
4740 	.pdev_smart_ant_enable_cmdid = WMI_CMD_UNSUPPORTED,
4741 	.pdev_smart_ant_set_rx_antenna_cmdid = WMI_CMD_UNSUPPORTED,
4742 	.peer_smart_ant_set_tx_antenna_cmdid = WMI_CMD_UNSUPPORTED,
4743 	.peer_smart_ant_set_train_info_cmdid = WMI_CMD_UNSUPPORTED,
4744 	.peer_smart_ant_set_node_config_ops_cmdid = WMI_CMD_UNSUPPORTED,
4745 	.pdev_set_antenna_switch_table_cmdid = WMI_CMD_UNSUPPORTED,
4746 	.pdev_set_ctl_table_cmdid = WMI_CMD_UNSUPPORTED,
4747 	.pdev_set_mimogain_table_cmdid = WMI_CMD_UNSUPPORTED,
4748 	.pdev_ratepwr_table_cmdid = WMI_CMD_UNSUPPORTED,
4749 	.pdev_ratepwr_chainmsk_table_cmdid = WMI_CMD_UNSUPPORTED,
4750 	.pdev_fips_cmdid = WMI_CMD_UNSUPPORTED,
4751 	.tt_set_conf_cmdid = WMI_CMD_UNSUPPORTED,
4752 	.fwtest_cmdid = WMI_CMD_UNSUPPORTED,
4753 	.vdev_atf_request_cmdid = WMI_CMD_UNSUPPORTED,
4754 	.peer_atf_request_cmdid = WMI_CMD_UNSUPPORTED,
4755 	.pdev_get_ani_cck_config_cmdid = WMI_CMD_UNSUPPORTED,
4756 	.pdev_get_ani_ofdm_config_cmdid = WMI_CMD_UNSUPPORTED,
4757 	.pdev_reserve_ast_entry_cmdid = WMI_CMD_UNSUPPORTED,
4758 };
4759 
4760 static struct wmi_pdev_param_map wmi_tlv_pdev_param_map = {
4761 	.tx_chain_mask = WMI_TLV_PDEV_PARAM_TX_CHAIN_MASK,
4762 	.rx_chain_mask = WMI_TLV_PDEV_PARAM_RX_CHAIN_MASK,
4763 	.txpower_limit2g = WMI_TLV_PDEV_PARAM_TXPOWER_LIMIT2G,
4764 	.txpower_limit5g = WMI_TLV_PDEV_PARAM_TXPOWER_LIMIT5G,
4765 	.txpower_scale = WMI_TLV_PDEV_PARAM_TXPOWER_SCALE,
4766 	.beacon_gen_mode = WMI_TLV_PDEV_PARAM_BEACON_GEN_MODE,
4767 	.beacon_tx_mode = WMI_TLV_PDEV_PARAM_BEACON_TX_MODE,
4768 	.resmgr_offchan_mode = WMI_TLV_PDEV_PARAM_RESMGR_OFFCHAN_MODE,
4769 	.protection_mode = WMI_TLV_PDEV_PARAM_PROTECTION_MODE,
4770 	.dynamic_bw = WMI_TLV_PDEV_PARAM_DYNAMIC_BW,
4771 	.non_agg_sw_retry_th = WMI_TLV_PDEV_PARAM_NON_AGG_SW_RETRY_TH,
4772 	.agg_sw_retry_th = WMI_TLV_PDEV_PARAM_AGG_SW_RETRY_TH,
4773 	.sta_kickout_th = WMI_TLV_PDEV_PARAM_STA_KICKOUT_TH,
4774 	.ac_aggrsize_scaling = WMI_TLV_PDEV_PARAM_AC_AGGRSIZE_SCALING,
4775 	.ltr_enable = WMI_TLV_PDEV_PARAM_LTR_ENABLE,
4776 	.ltr_ac_latency_be = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_BE,
4777 	.ltr_ac_latency_bk = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_BK,
4778 	.ltr_ac_latency_vi = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_VI,
4779 	.ltr_ac_latency_vo = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_VO,
4780 	.ltr_ac_latency_timeout = WMI_TLV_PDEV_PARAM_LTR_AC_LATENCY_TIMEOUT,
4781 	.ltr_sleep_override = WMI_TLV_PDEV_PARAM_LTR_SLEEP_OVERRIDE,
4782 	.ltr_rx_override = WMI_TLV_PDEV_PARAM_LTR_RX_OVERRIDE,
4783 	.ltr_tx_activity_timeout = WMI_TLV_PDEV_PARAM_LTR_TX_ACTIVITY_TIMEOUT,
4784 	.l1ss_enable = WMI_TLV_PDEV_PARAM_L1SS_ENABLE,
4785 	.dsleep_enable = WMI_TLV_PDEV_PARAM_DSLEEP_ENABLE,
4786 	.pcielp_txbuf_flush = WMI_TLV_PDEV_PARAM_PCIELP_TXBUF_FLUSH,
4787 	.pcielp_txbuf_watermark = WMI_TLV_PDEV_PARAM_PCIELP_TXBUF_TMO_EN,
4788 	.pcielp_txbuf_tmo_en = WMI_TLV_PDEV_PARAM_PCIELP_TXBUF_TMO_EN,
4789 	.pcielp_txbuf_tmo_value = WMI_TLV_PDEV_PARAM_PCIELP_TXBUF_TMO_VALUE,
4790 	.pdev_stats_update_period = WMI_TLV_PDEV_PARAM_PDEV_STATS_UPDATE_PERIOD,
4791 	.vdev_stats_update_period = WMI_TLV_PDEV_PARAM_VDEV_STATS_UPDATE_PERIOD,
4792 	.peer_stats_update_period = WMI_TLV_PDEV_PARAM_PEER_STATS_UPDATE_PERIOD,
4793 	.bcnflt_stats_update_period =
4794 				WMI_TLV_PDEV_PARAM_BCNFLT_STATS_UPDATE_PERIOD,
4795 	.pmf_qos = WMI_TLV_PDEV_PARAM_PMF_QOS,
4796 	.arp_ac_override = WMI_TLV_PDEV_PARAM_ARP_AC_OVERRIDE,
4797 	.dcs = WMI_TLV_PDEV_PARAM_DCS,
4798 	.ani_enable = WMI_TLV_PDEV_PARAM_ANI_ENABLE,
4799 	.ani_poll_period = WMI_TLV_PDEV_PARAM_ANI_POLL_PERIOD,
4800 	.ani_listen_period = WMI_TLV_PDEV_PARAM_ANI_LISTEN_PERIOD,
4801 	.ani_ofdm_level = WMI_TLV_PDEV_PARAM_ANI_OFDM_LEVEL,
4802 	.ani_cck_level = WMI_TLV_PDEV_PARAM_ANI_CCK_LEVEL,
4803 	.dyntxchain = WMI_TLV_PDEV_PARAM_DYNTXCHAIN,
4804 	.proxy_sta = WMI_TLV_PDEV_PARAM_PROXY_STA,
4805 	.idle_ps_config = WMI_TLV_PDEV_PARAM_IDLE_PS_CONFIG,
4806 	.power_gating_sleep = WMI_TLV_PDEV_PARAM_POWER_GATING_SLEEP,
4807 	.fast_channel_reset = WMI_TLV_PDEV_PARAM_UNSUPPORTED,
4808 	.burst_dur = WMI_TLV_PDEV_PARAM_BURST_DUR,
4809 	.burst_enable = WMI_TLV_PDEV_PARAM_BURST_ENABLE,
4810 	.cal_period = WMI_PDEV_PARAM_UNSUPPORTED,
4811 	.aggr_burst = WMI_PDEV_PARAM_UNSUPPORTED,
4812 	.rx_decap_mode = WMI_PDEV_PARAM_UNSUPPORTED,
4813 	.smart_antenna_default_antenna = WMI_PDEV_PARAM_UNSUPPORTED,
4814 	.igmpmld_override = WMI_PDEV_PARAM_UNSUPPORTED,
4815 	.igmpmld_tid = WMI_PDEV_PARAM_UNSUPPORTED,
4816 	.antenna_gain = WMI_PDEV_PARAM_UNSUPPORTED,
4817 	.rx_filter = WMI_PDEV_PARAM_UNSUPPORTED,
4818 	.set_mcast_to_ucast_tid = WMI_PDEV_PARAM_UNSUPPORTED,
4819 	.proxy_sta_mode = WMI_PDEV_PARAM_UNSUPPORTED,
4820 	.set_mcast2ucast_mode = WMI_PDEV_PARAM_UNSUPPORTED,
4821 	.set_mcast2ucast_buffer = WMI_PDEV_PARAM_UNSUPPORTED,
4822 	.remove_mcast2ucast_buffer = WMI_PDEV_PARAM_UNSUPPORTED,
4823 	.peer_sta_ps_statechg_enable = WMI_PDEV_PARAM_UNSUPPORTED,
4824 	.igmpmld_ac_override = WMI_PDEV_PARAM_UNSUPPORTED,
4825 	.block_interbss = WMI_PDEV_PARAM_UNSUPPORTED,
4826 	.set_disable_reset_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
4827 	.set_msdu_ttl_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
4828 	.set_ppdu_duration_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
4829 	.txbf_sound_period_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
4830 	.set_promisc_mode_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
4831 	.set_burst_mode_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
4832 	.en_stats = WMI_PDEV_PARAM_UNSUPPORTED,
4833 	.mu_group_policy = WMI_PDEV_PARAM_UNSUPPORTED,
4834 	.noise_detection = WMI_PDEV_PARAM_UNSUPPORTED,
4835 	.noise_threshold = WMI_PDEV_PARAM_UNSUPPORTED,
4836 	.dpd_enable = WMI_PDEV_PARAM_UNSUPPORTED,
4837 	.set_mcast_bcast_echo = WMI_PDEV_PARAM_UNSUPPORTED,
4838 	.atf_strict_sch = WMI_PDEV_PARAM_UNSUPPORTED,
4839 	.atf_sched_duration = WMI_PDEV_PARAM_UNSUPPORTED,
4840 	.ant_plzn = WMI_PDEV_PARAM_UNSUPPORTED,
4841 	.mgmt_retry_limit = WMI_PDEV_PARAM_UNSUPPORTED,
4842 	.sensitivity_level = WMI_PDEV_PARAM_UNSUPPORTED,
4843 	.signed_txpower_2g = WMI_PDEV_PARAM_UNSUPPORTED,
4844 	.signed_txpower_5g = WMI_PDEV_PARAM_UNSUPPORTED,
4845 	.enable_per_tid_amsdu = WMI_PDEV_PARAM_UNSUPPORTED,
4846 	.enable_per_tid_ampdu = WMI_PDEV_PARAM_UNSUPPORTED,
4847 	.cca_threshold = WMI_PDEV_PARAM_UNSUPPORTED,
4848 	.rts_fixed_rate = WMI_PDEV_PARAM_UNSUPPORTED,
4849 	.pdev_reset = WMI_PDEV_PARAM_UNSUPPORTED,
4850 	.wapi_mbssid_offset = WMI_PDEV_PARAM_UNSUPPORTED,
4851 	.arp_srcaddr = WMI_PDEV_PARAM_UNSUPPORTED,
4852 	.arp_dstaddr = WMI_PDEV_PARAM_UNSUPPORTED,
4853 	.rfkill_config = WMI_TLV_PDEV_PARAM_HW_RFKILL_CONFIG,
4854 	.rfkill_enable = WMI_TLV_PDEV_PARAM_RFKILL_ENABLE,
4855 	.peer_stats_info_enable = WMI_TLV_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
4856 };
4857 
4858 static struct wmi_peer_param_map wmi_tlv_peer_param_map = {
4859 	.smps_state = WMI_TLV_PEER_SMPS_STATE,
4860 	.ampdu = WMI_TLV_PEER_AMPDU,
4861 	.authorize = WMI_TLV_PEER_AUTHORIZE,
4862 	.chan_width = WMI_TLV_PEER_CHAN_WIDTH,
4863 	.nss = WMI_TLV_PEER_NSS,
4864 	.use_4addr = WMI_TLV_PEER_USE_4ADDR,
4865 	.membership = WMI_TLV_PEER_MEMBERSHIP,
4866 	.user_pos = WMI_TLV_PEER_USERPOS,
4867 	.crit_proto_hint_enabled = WMI_TLV_PEER_CRIT_PROTO_HINT_ENABLED,
4868 	.tx_fail_cnt_thr = WMI_TLV_PEER_TX_FAIL_CNT_THR,
4869 	.set_hw_retry_cts2s = WMI_TLV_PEER_SET_HW_RETRY_CTS2S,
4870 	.ibss_atim_win_len = WMI_TLV_PEER_IBSS_ATIM_WINDOW_LENGTH,
4871 	.phymode = WMI_TLV_PEER_PHYMODE,
4872 	.use_fixed_power = WMI_TLV_PEER_USE_FIXED_PWR,
4873 	.dummy_var = WMI_TLV_PEER_DUMMY_VAR,
4874 };
4875 
4876 static struct wmi_vdev_param_map wmi_tlv_vdev_param_map = {
4877 	.rts_threshold = WMI_TLV_VDEV_PARAM_RTS_THRESHOLD,
4878 	.fragmentation_threshold = WMI_TLV_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
4879 	.beacon_interval = WMI_TLV_VDEV_PARAM_BEACON_INTERVAL,
4880 	.listen_interval = WMI_TLV_VDEV_PARAM_LISTEN_INTERVAL,
4881 	.multicast_rate = WMI_TLV_VDEV_PARAM_MULTICAST_RATE,
4882 	.mgmt_tx_rate = WMI_TLV_VDEV_PARAM_MGMT_TX_RATE,
4883 	.slot_time = WMI_TLV_VDEV_PARAM_SLOT_TIME,
4884 	.preamble = WMI_TLV_VDEV_PARAM_PREAMBLE,
4885 	.swba_time = WMI_TLV_VDEV_PARAM_SWBA_TIME,
4886 	.wmi_vdev_stats_update_period = WMI_TLV_VDEV_STATS_UPDATE_PERIOD,
4887 	.wmi_vdev_pwrsave_ageout_time = WMI_TLV_VDEV_PWRSAVE_AGEOUT_TIME,
4888 	.wmi_vdev_host_swba_interval = WMI_TLV_VDEV_HOST_SWBA_INTERVAL,
4889 	.dtim_period = WMI_TLV_VDEV_PARAM_DTIM_PERIOD,
4890 	.wmi_vdev_oc_scheduler_air_time_limit =
4891 				WMI_TLV_VDEV_OC_SCHEDULER_AIR_TIME_LIMIT,
4892 	.wds = WMI_TLV_VDEV_PARAM_WDS,
4893 	.atim_window = WMI_TLV_VDEV_PARAM_ATIM_WINDOW,
4894 	.bmiss_count_max = WMI_TLV_VDEV_PARAM_BMISS_COUNT_MAX,
4895 	.bmiss_first_bcnt = WMI_TLV_VDEV_PARAM_BMISS_FIRST_BCNT,
4896 	.bmiss_final_bcnt = WMI_TLV_VDEV_PARAM_BMISS_FINAL_BCNT,
4897 	.feature_wmm = WMI_TLV_VDEV_PARAM_FEATURE_WMM,
4898 	.chwidth = WMI_TLV_VDEV_PARAM_CHWIDTH,
4899 	.chextoffset = WMI_TLV_VDEV_PARAM_CHEXTOFFSET,
4900 	.disable_htprotection =	WMI_TLV_VDEV_PARAM_DISABLE_HTPROTECTION,
4901 	.sta_quickkickout = WMI_TLV_VDEV_PARAM_STA_QUICKKICKOUT,
4902 	.mgmt_rate = WMI_TLV_VDEV_PARAM_MGMT_RATE,
4903 	.protection_mode = WMI_TLV_VDEV_PARAM_PROTECTION_MODE,
4904 	.fixed_rate = WMI_TLV_VDEV_PARAM_FIXED_RATE,
4905 	.sgi = WMI_TLV_VDEV_PARAM_SGI,
4906 	.ldpc = WMI_TLV_VDEV_PARAM_LDPC,
4907 	.tx_stbc = WMI_TLV_VDEV_PARAM_TX_STBC,
4908 	.rx_stbc = WMI_TLV_VDEV_PARAM_RX_STBC,
4909 	.intra_bss_fwd = WMI_TLV_VDEV_PARAM_INTRA_BSS_FWD,
4910 	.def_keyid = WMI_TLV_VDEV_PARAM_DEF_KEYID,
4911 	.nss = WMI_TLV_VDEV_PARAM_NSS,
4912 	.bcast_data_rate = WMI_TLV_VDEV_PARAM_BCAST_DATA_RATE,
4913 	.mcast_data_rate = WMI_TLV_VDEV_PARAM_MCAST_DATA_RATE,
4914 	.mcast_indicate = WMI_TLV_VDEV_PARAM_MCAST_INDICATE,
4915 	.dhcp_indicate = WMI_TLV_VDEV_PARAM_DHCP_INDICATE,
4916 	.unknown_dest_indicate = WMI_TLV_VDEV_PARAM_UNKNOWN_DEST_INDICATE,
4917 	.ap_keepalive_min_idle_inactive_time_secs =
4918 		WMI_TLV_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS,
4919 	.ap_keepalive_max_idle_inactive_time_secs =
4920 		WMI_TLV_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS,
4921 	.ap_keepalive_max_unresponsive_time_secs =
4922 		WMI_TLV_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS,
4923 	.ap_enable_nawds = WMI_TLV_VDEV_PARAM_AP_ENABLE_NAWDS,
4924 	.mcast2ucast_set = WMI_TLV_VDEV_PARAM_UNSUPPORTED,
4925 	.enable_rtscts = WMI_TLV_VDEV_PARAM_ENABLE_RTSCTS,
4926 	.txbf = WMI_TLV_VDEV_PARAM_TXBF,
4927 	.packet_powersave = WMI_TLV_VDEV_PARAM_PACKET_POWERSAVE,
4928 	.drop_unencry = WMI_TLV_VDEV_PARAM_DROP_UNENCRY,
4929 	.tx_encap_type = WMI_TLV_VDEV_PARAM_TX_ENCAP_TYPE,
4930 	.ap_detect_out_of_sync_sleeping_sta_time_secs =
4931 					WMI_TLV_VDEV_PARAM_UNSUPPORTED,
4932 	.rc_num_retries = WMI_VDEV_PARAM_UNSUPPORTED,
4933 	.cabq_maxdur = WMI_VDEV_PARAM_UNSUPPORTED,
4934 	.mfptest_set = WMI_VDEV_PARAM_UNSUPPORTED,
4935 	.rts_fixed_rate = WMI_VDEV_PARAM_UNSUPPORTED,
4936 	.vht_sgimask = WMI_VDEV_PARAM_UNSUPPORTED,
4937 	.vht80_ratemask = WMI_VDEV_PARAM_UNSUPPORTED,
4938 	.early_rx_adjust_enable = WMI_VDEV_PARAM_UNSUPPORTED,
4939 	.early_rx_tgt_bmiss_num = WMI_VDEV_PARAM_UNSUPPORTED,
4940 	.early_rx_bmiss_sample_cycle = WMI_VDEV_PARAM_UNSUPPORTED,
4941 	.early_rx_slop_step = WMI_VDEV_PARAM_UNSUPPORTED,
4942 	.early_rx_init_slop = WMI_VDEV_PARAM_UNSUPPORTED,
4943 	.early_rx_adjust_pause = WMI_VDEV_PARAM_UNSUPPORTED,
4944 	.proxy_sta = WMI_VDEV_PARAM_UNSUPPORTED,
4945 	.meru_vc = WMI_VDEV_PARAM_UNSUPPORTED,
4946 	.rx_decap_type = WMI_VDEV_PARAM_UNSUPPORTED,
4947 	.bw_nss_ratemask = WMI_VDEV_PARAM_UNSUPPORTED,
4948 };
4949 
4950 static const struct wmi_ops wmi_tlv_ops = {
4951 	.rx = ath10k_wmi_tlv_op_rx,
4952 	.map_svc = wmi_tlv_svc_map,
4953 	.map_svc_ext = wmi_tlv_svc_map_ext,
4954 
4955 	.pull_scan = ath10k_wmi_tlv_op_pull_scan_ev,
4956 	.pull_mgmt_rx = ath10k_wmi_tlv_op_pull_mgmt_rx_ev,
4957 	.pull_mgmt_tx_compl = ath10k_wmi_tlv_op_pull_mgmt_tx_compl_ev,
4958 	.pull_mgmt_tx_bundle_compl = ath10k_wmi_tlv_op_pull_mgmt_tx_bundle_compl_ev,
4959 	.pull_ch_info = ath10k_wmi_tlv_op_pull_ch_info_ev,
4960 	.pull_vdev_start = ath10k_wmi_tlv_op_pull_vdev_start_ev,
4961 	.pull_peer_kick = ath10k_wmi_tlv_op_pull_peer_kick_ev,
4962 	.pull_swba = ath10k_wmi_tlv_op_pull_swba_ev,
4963 	.pull_phyerr_hdr = ath10k_wmi_tlv_op_pull_phyerr_ev_hdr,
4964 	.pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
4965 	.pull_svc_rdy = ath10k_wmi_tlv_op_pull_svc_rdy_ev,
4966 	.pull_rdy = ath10k_wmi_tlv_op_pull_rdy_ev,
4967 	.pull_svc_avail = ath10k_wmi_tlv_op_pull_svc_avail,
4968 	.pull_fw_stats = ath10k_wmi_tlv_op_pull_fw_stats,
4969 	.pull_roam_ev = ath10k_wmi_tlv_op_pull_roam_ev,
4970 	.pull_wow_event = ath10k_wmi_tlv_op_pull_wow_ev,
4971 	.pull_echo_ev = ath10k_wmi_tlv_op_pull_echo_ev,
4972 	.get_txbf_conf_scheme = ath10k_wmi_tlv_txbf_conf_scheme,
4973 
4974 	.gen_pdev_suspend = ath10k_wmi_tlv_op_gen_pdev_suspend,
4975 	.gen_pdev_resume = ath10k_wmi_tlv_op_gen_pdev_resume,
4976 	.gen_pdev_set_rd = ath10k_wmi_tlv_op_gen_pdev_set_rd,
4977 	.gen_pdev_set_param = ath10k_wmi_tlv_op_gen_pdev_set_param,
4978 	.gen_init = ath10k_wmi_tlv_op_gen_init,
4979 	.gen_start_scan = ath10k_wmi_tlv_op_gen_start_scan,
4980 	.gen_stop_scan = ath10k_wmi_tlv_op_gen_stop_scan,
4981 	.gen_vdev_create = ath10k_wmi_tlv_op_gen_vdev_create,
4982 	.gen_vdev_delete = ath10k_wmi_tlv_op_gen_vdev_delete,
4983 	.gen_vdev_start = ath10k_wmi_tlv_op_gen_vdev_start,
4984 	.gen_vdev_stop = ath10k_wmi_tlv_op_gen_vdev_stop,
4985 	.gen_vdev_up = ath10k_wmi_tlv_op_gen_vdev_up,
4986 	.gen_vdev_down = ath10k_wmi_tlv_op_gen_vdev_down,
4987 	.gen_vdev_set_param = ath10k_wmi_tlv_op_gen_vdev_set_param,
4988 	.gen_vdev_install_key = ath10k_wmi_tlv_op_gen_vdev_install_key,
4989 	.gen_vdev_wmm_conf = ath10k_wmi_tlv_op_gen_vdev_wmm_conf,
4990 	.gen_peer_create = ath10k_wmi_tlv_op_gen_peer_create,
4991 	.gen_peer_delete = ath10k_wmi_tlv_op_gen_peer_delete,
4992 	.gen_peer_flush = ath10k_wmi_tlv_op_gen_peer_flush,
4993 	.gen_peer_set_param = ath10k_wmi_tlv_op_gen_peer_set_param,
4994 	.gen_peer_assoc = ath10k_wmi_tlv_op_gen_peer_assoc,
4995 	.gen_set_psmode = ath10k_wmi_tlv_op_gen_set_psmode,
4996 	.gen_set_sta_ps = ath10k_wmi_tlv_op_gen_set_sta_ps,
4997 	.gen_set_ap_ps = ath10k_wmi_tlv_op_gen_set_ap_ps,
4998 	.gen_scan_chan_list = ath10k_wmi_tlv_op_gen_scan_chan_list,
4999 	.gen_scan_prob_req_oui = ath10k_wmi_tlv_op_gen_scan_prob_req_oui,
5000 	.gen_beacon_dma = ath10k_wmi_tlv_op_gen_beacon_dma,
5001 	.gen_pdev_set_wmm = ath10k_wmi_tlv_op_gen_pdev_set_wmm,
5002 	.gen_request_stats = ath10k_wmi_tlv_op_gen_request_stats,
5003 	.gen_request_peer_stats_info = ath10k_wmi_tlv_op_gen_request_peer_stats_info,
5004 	.gen_force_fw_hang = ath10k_wmi_tlv_op_gen_force_fw_hang,
5005 	/* .gen_mgmt_tx = not implemented; HTT is used */
5006 	.gen_mgmt_tx_send = ath10k_wmi_tlv_op_gen_mgmt_tx_send,
5007 	.cleanup_mgmt_tx_send = ath10k_wmi_tlv_op_cleanup_mgmt_tx_send,
5008 	.gen_dbglog_cfg = ath10k_wmi_tlv_op_gen_dbglog_cfg,
5009 	.gen_pktlog_enable = ath10k_wmi_tlv_op_gen_pktlog_enable,
5010 	.gen_pktlog_disable = ath10k_wmi_tlv_op_gen_pktlog_disable,
5011 	.gen_pdev_set_quiet_mode = ath10k_wmi_tlv_op_gen_pdev_set_quiet_mode,
5012 	.gen_pdev_get_temperature = ath10k_wmi_tlv_op_gen_pdev_get_temperature,
5013 	/* .gen_addba_clear_resp not implemented */
5014 	/* .gen_addba_send not implemented */
5015 	/* .gen_addba_set_resp not implemented */
5016 	/* .gen_delba_send not implemented */
5017 	.gen_bcn_tmpl = ath10k_wmi_tlv_op_gen_bcn_tmpl,
5018 	.gen_prb_tmpl = ath10k_wmi_tlv_op_gen_prb_tmpl,
5019 	.gen_p2p_go_bcn_ie = ath10k_wmi_tlv_op_gen_p2p_go_bcn_ie,
5020 	.gen_vdev_sta_uapsd = ath10k_wmi_tlv_op_gen_vdev_sta_uapsd,
5021 	.gen_sta_keepalive = ath10k_wmi_tlv_op_gen_sta_keepalive,
5022 	.gen_wow_enable = ath10k_wmi_tlv_op_gen_wow_enable,
5023 	.gen_wow_add_wakeup_event = ath10k_wmi_tlv_op_gen_wow_add_wakeup_event,
5024 	.gen_wow_host_wakeup_ind = ath10k_wmi_tlv_gen_wow_host_wakeup_ind,
5025 	.gen_wow_add_pattern = ath10k_wmi_tlv_op_gen_wow_add_pattern,
5026 	.gen_wow_del_pattern = ath10k_wmi_tlv_op_gen_wow_del_pattern,
5027 	.gen_wow_config_pno = ath10k_wmi_tlv_op_gen_config_pno,
5028 	.gen_update_fw_tdls_state = ath10k_wmi_tlv_op_gen_update_fw_tdls_state,
5029 	.gen_tdls_peer_update = ath10k_wmi_tlv_op_gen_tdls_peer_update,
5030 	.gen_adaptive_qcs = ath10k_wmi_tlv_op_gen_adaptive_qcs,
5031 	.fw_stats_fill = ath10k_wmi_main_op_fw_stats_fill,
5032 	.get_vdev_subtype = ath10k_wmi_tlv_op_get_vdev_subtype,
5033 	.gen_echo = ath10k_wmi_tlv_op_gen_echo,
5034 	.gen_vdev_spectral_conf = ath10k_wmi_tlv_op_gen_vdev_spectral_conf,
5035 	.gen_vdev_spectral_enable = ath10k_wmi_tlv_op_gen_vdev_spectral_enable,
5036 };
5037 
5038 static const struct wmi_peer_flags_map wmi_tlv_peer_flags_map = {
5039 	.auth = WMI_TLV_PEER_AUTH,
5040 	.qos = WMI_TLV_PEER_QOS,
5041 	.need_ptk_4_way = WMI_TLV_PEER_NEED_PTK_4_WAY,
5042 	.need_gtk_2_way = WMI_TLV_PEER_NEED_GTK_2_WAY,
5043 	.apsd = WMI_TLV_PEER_APSD,
5044 	.ht = WMI_TLV_PEER_HT,
5045 	.bw40 = WMI_TLV_PEER_40MHZ,
5046 	.stbc = WMI_TLV_PEER_STBC,
5047 	.ldbc = WMI_TLV_PEER_LDPC,
5048 	.dyn_mimops = WMI_TLV_PEER_DYN_MIMOPS,
5049 	.static_mimops = WMI_TLV_PEER_STATIC_MIMOPS,
5050 	.spatial_mux = WMI_TLV_PEER_SPATIAL_MUX,
5051 	.vht = WMI_TLV_PEER_VHT,
5052 	.bw80 = WMI_TLV_PEER_80MHZ,
5053 	.pmf = WMI_TLV_PEER_PMF,
5054 	.bw160 = WMI_TLV_PEER_160MHZ,
5055 };
5056 
5057 /************/
5058 /* TLV init */
5059 /************/
5060 
5061 void ath10k_wmi_tlv_attach(struct ath10k *ar)
5062 {
5063 	ar->wmi.cmd = &wmi_tlv_cmd_map;
5064 	ar->wmi.vdev_param = &wmi_tlv_vdev_param_map;
5065 	ar->wmi.pdev_param = &wmi_tlv_pdev_param_map;
5066 	ar->wmi.peer_param = &wmi_tlv_peer_param_map;
5067 	ar->wmi.ops = &wmi_tlv_ops;
5068 	ar->wmi.peer_flags = &wmi_tlv_peer_flags_map;
5069 }
5070