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