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