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