xref: /freebsd/sys/contrib/dev/athk/ath10k/htt.h (revision 911f0260390e18cf85f3dbf2c719b593efdc1e3c)
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, The Linux Foundation. All rights reserved.
6  */
7 
8 #ifndef _HTT_H_
9 #define _HTT_H_
10 
11 #include <linux/bug.h>
12 #include <linux/interrupt.h>
13 #include <linux/dmapool.h>
14 #include <linux/hashtable.h>
15 #include <linux/kfifo.h>
16 #include <net/mac80211.h>
17 #if defined(__FreeBSD__)
18 #include <linux/wait.h>
19 #endif
20 
21 #include "htc.h"
22 #include "hw.h"
23 #include "rx_desc.h"
24 
25 enum htt_dbg_stats_type {
26 	HTT_DBG_STATS_WAL_PDEV_TXRX = 1 << 0,
27 	HTT_DBG_STATS_RX_REORDER    = 1 << 1,
28 	HTT_DBG_STATS_RX_RATE_INFO  = 1 << 2,
29 	HTT_DBG_STATS_TX_PPDU_LOG   = 1 << 3,
30 	HTT_DBG_STATS_TX_RATE_INFO  = 1 << 4,
31 	/* bits 5-23 currently reserved */
32 
33 	HTT_DBG_NUM_STATS /* keep this last */
34 };
35 
36 enum htt_h2t_msg_type { /* host-to-target */
37 	HTT_H2T_MSG_TYPE_VERSION_REQ        = 0,
38 	HTT_H2T_MSG_TYPE_TX_FRM             = 1,
39 	HTT_H2T_MSG_TYPE_RX_RING_CFG        = 2,
40 	HTT_H2T_MSG_TYPE_STATS_REQ          = 3,
41 	HTT_H2T_MSG_TYPE_SYNC               = 4,
42 	HTT_H2T_MSG_TYPE_AGGR_CFG           = 5,
43 	HTT_H2T_MSG_TYPE_FRAG_DESC_BANK_CFG = 6,
44 
45 	/* This command is used for sending management frames in HTT < 3.0.
46 	 * HTT >= 3.0 uses TX_FRM for everything.
47 	 */
48 	HTT_H2T_MSG_TYPE_MGMT_TX            = 7,
49 	HTT_H2T_MSG_TYPE_TX_FETCH_RESP      = 11,
50 
51 	HTT_H2T_NUM_MSGS /* keep this last */
52 };
53 
54 struct htt_cmd_hdr {
55 	u8 msg_type;
56 } __packed;
57 
58 struct htt_ver_req {
59 	u8 pad[sizeof(u32) - sizeof(struct htt_cmd_hdr)];
60 } __packed;
61 
62 /*
63  * HTT tx MSDU descriptor
64  *
65  * The HTT tx MSDU descriptor is created by the host HTT SW for each
66  * tx MSDU.  The HTT tx MSDU descriptor contains the information that
67  * the target firmware needs for the FW's tx processing, particularly
68  * for creating the HW msdu descriptor.
69  * The same HTT tx descriptor is used for HL and LL systems, though
70  * a few fields within the tx descriptor are used only by LL or
71  * only by HL.
72  * The HTT tx descriptor is defined in two manners: by a struct with
73  * bitfields, and by a series of [dword offset, bit mask, bit shift]
74  * definitions.
75  * The target should use the struct def, for simplicitly and clarity,
76  * but the host shall use the bit-mast + bit-shift defs, to be endian-
77  * neutral.  Specifically, the host shall use the get/set macros built
78  * around the mask + shift defs.
79  */
80 struct htt_data_tx_desc_frag {
81 	union {
82 		struct double_word_addr {
83 			__le32 paddr;
84 			__le32 len;
85 		} __packed dword_addr;
86 		struct triple_word_addr {
87 			__le32 paddr_lo;
88 			__le16 paddr_hi;
89 			__le16 len_16;
90 		} __packed tword_addr;
91 	} __packed;
92 } __packed;
93 
94 struct htt_msdu_ext_desc {
95 	__le32 tso_flag[3];
96 	__le16 ip_identification;
97 	u8 flags;
98 	u8 reserved;
99 	struct htt_data_tx_desc_frag frags[6];
100 };
101 
102 struct htt_msdu_ext_desc_64 {
103 	__le32 tso_flag[5];
104 	__le16 ip_identification;
105 	u8 flags;
106 	u8 reserved;
107 	struct htt_data_tx_desc_frag frags[6];
108 };
109 
110 #define	HTT_MSDU_EXT_DESC_FLAG_IPV4_CSUM_ENABLE		BIT(0)
111 #define	HTT_MSDU_EXT_DESC_FLAG_UDP_IPV4_CSUM_ENABLE	BIT(1)
112 #define	HTT_MSDU_EXT_DESC_FLAG_UDP_IPV6_CSUM_ENABLE	BIT(2)
113 #define	HTT_MSDU_EXT_DESC_FLAG_TCP_IPV4_CSUM_ENABLE	BIT(3)
114 #define	HTT_MSDU_EXT_DESC_FLAG_TCP_IPV6_CSUM_ENABLE	BIT(4)
115 
116 #define HTT_MSDU_CHECKSUM_ENABLE (HTT_MSDU_EXT_DESC_FLAG_IPV4_CSUM_ENABLE \
117 				 | HTT_MSDU_EXT_DESC_FLAG_UDP_IPV4_CSUM_ENABLE \
118 				 | HTT_MSDU_EXT_DESC_FLAG_UDP_IPV6_CSUM_ENABLE \
119 				 | HTT_MSDU_EXT_DESC_FLAG_TCP_IPV4_CSUM_ENABLE \
120 				 | HTT_MSDU_EXT_DESC_FLAG_TCP_IPV6_CSUM_ENABLE)
121 
122 #define HTT_MSDU_EXT_DESC_FLAG_IPV4_CSUM_ENABLE_64		BIT(16)
123 #define HTT_MSDU_EXT_DESC_FLAG_UDP_IPV4_CSUM_ENABLE_64		BIT(17)
124 #define HTT_MSDU_EXT_DESC_FLAG_UDP_IPV6_CSUM_ENABLE_64		BIT(18)
125 #define HTT_MSDU_EXT_DESC_FLAG_TCP_IPV4_CSUM_ENABLE_64		BIT(19)
126 #define HTT_MSDU_EXT_DESC_FLAG_TCP_IPV6_CSUM_ENABLE_64		BIT(20)
127 #define HTT_MSDU_EXT_DESC_FLAG_PARTIAL_CSUM_ENABLE_64		BIT(21)
128 
129 #define HTT_MSDU_CHECKSUM_ENABLE_64  (HTT_MSDU_EXT_DESC_FLAG_IPV4_CSUM_ENABLE_64 \
130 				     | HTT_MSDU_EXT_DESC_FLAG_UDP_IPV4_CSUM_ENABLE_64 \
131 				     | HTT_MSDU_EXT_DESC_FLAG_UDP_IPV6_CSUM_ENABLE_64 \
132 				     | HTT_MSDU_EXT_DESC_FLAG_TCP_IPV4_CSUM_ENABLE_64 \
133 				     | HTT_MSDU_EXT_DESC_FLAG_TCP_IPV6_CSUM_ENABLE_64)
134 
135 enum htt_data_tx_desc_flags0 {
136 	HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT = 1 << 0,
137 	HTT_DATA_TX_DESC_FLAGS0_NO_AGGR         = 1 << 1,
138 	HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT      = 1 << 2,
139 	HTT_DATA_TX_DESC_FLAGS0_NO_CLASSIFY     = 1 << 3,
140 	HTT_DATA_TX_DESC_FLAGS0_RSVD0           = 1 << 4
141 #define HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE_MASK 0xE0
142 #define HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE_LSB 5
143 };
144 
145 enum htt_data_tx_desc_flags1 {
146 #define HTT_DATA_TX_DESC_FLAGS1_VDEV_ID_BITS 6
147 #define HTT_DATA_TX_DESC_FLAGS1_VDEV_ID_MASK 0x003F
148 #define HTT_DATA_TX_DESC_FLAGS1_VDEV_ID_LSB  0
149 #define HTT_DATA_TX_DESC_FLAGS1_EXT_TID_BITS 5
150 #define HTT_DATA_TX_DESC_FLAGS1_EXT_TID_MASK 0x07C0
151 #define HTT_DATA_TX_DESC_FLAGS1_EXT_TID_LSB  6
152 	HTT_DATA_TX_DESC_FLAGS1_POSTPONED        = 1 << 11,
153 	HTT_DATA_TX_DESC_FLAGS1_MORE_IN_BATCH    = 1 << 12,
154 	HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD = 1 << 13,
155 	HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD = 1 << 14,
156 	HTT_DATA_TX_DESC_FLAGS1_TX_COMPLETE      = 1 << 15
157 };
158 
159 #define HTT_TX_CREDIT_DELTA_ABS_M      0xffff0000
160 #define HTT_TX_CREDIT_DELTA_ABS_S      16
161 #define HTT_TX_CREDIT_DELTA_ABS_GET(word) \
162 	    (((word) & HTT_TX_CREDIT_DELTA_ABS_M) >> HTT_TX_CREDIT_DELTA_ABS_S)
163 
164 #define HTT_TX_CREDIT_SIGN_BIT_M       0x00000100
165 #define HTT_TX_CREDIT_SIGN_BIT_S       8
166 #define HTT_TX_CREDIT_SIGN_BIT_GET(word) \
167 	    (((word) & HTT_TX_CREDIT_SIGN_BIT_M) >> HTT_TX_CREDIT_SIGN_BIT_S)
168 
169 enum htt_data_tx_ext_tid {
170 	HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST = 16,
171 	HTT_DATA_TX_EXT_TID_MGMT                = 17,
172 	HTT_DATA_TX_EXT_TID_INVALID             = 31
173 };
174 
175 #define HTT_INVALID_PEERID 0xFFFF
176 
177 /*
178  * htt_data_tx_desc - used for data tx path
179  *
180  * Note: vdev_id irrelevant for pkt_type == raw and no_classify == 1.
181  *       ext_tid: for qos-data frames (0-15), see %HTT_DATA_TX_EXT_TID_
182  *                for special kinds of tids
183  *       postponed: only for HL hosts. indicates if this is a resend
184  *                  (HL hosts manage queues on the host )
185  *       more_in_batch: only for HL hosts. indicates if more packets are
186  *                      pending. this allows target to wait and aggregate
187  *       freq: 0 means home channel of given vdev. intended for offchannel
188  */
189 struct htt_data_tx_desc {
190 	u8 flags0; /* %HTT_DATA_TX_DESC_FLAGS0_ */
191 	__le16 flags1; /* %HTT_DATA_TX_DESC_FLAGS1_ */
192 	__le16 len;
193 	__le16 id;
194 	__le32 frags_paddr;
195 	union {
196 		__le32 peerid;
197 		struct {
198 			__le16 peerid;
199 			__le16 freq;
200 		} __packed offchan_tx;
201 	} __packed;
202 	u8 prefetch[0]; /* start of frame, for FW classification engine */
203 } __packed;
204 
205 struct htt_data_tx_desc_64 {
206 	u8 flags0; /* %HTT_DATA_TX_DESC_FLAGS0_ */
207 	__le16 flags1; /* %HTT_DATA_TX_DESC_FLAGS1_ */
208 	__le16 len;
209 	__le16 id;
210 	__le64 frags_paddr;
211 	union {
212 		__le32 peerid;
213 		struct {
214 			__le16 peerid;
215 			__le16 freq;
216 		} __packed offchan_tx;
217 	} __packed;
218 	u8 prefetch[0]; /* start of frame, for FW classification engine */
219 } __packed;
220 
221 enum htt_rx_ring_flags {
222 	HTT_RX_RING_FLAGS_MAC80211_HDR = 1 << 0,
223 	HTT_RX_RING_FLAGS_MSDU_PAYLOAD = 1 << 1,
224 	HTT_RX_RING_FLAGS_PPDU_START   = 1 << 2,
225 	HTT_RX_RING_FLAGS_PPDU_END     = 1 << 3,
226 	HTT_RX_RING_FLAGS_MPDU_START   = 1 << 4,
227 	HTT_RX_RING_FLAGS_MPDU_END     = 1 << 5,
228 	HTT_RX_RING_FLAGS_MSDU_START   = 1 << 6,
229 	HTT_RX_RING_FLAGS_MSDU_END     = 1 << 7,
230 	HTT_RX_RING_FLAGS_RX_ATTENTION = 1 << 8,
231 	HTT_RX_RING_FLAGS_FRAG_INFO    = 1 << 9,
232 	HTT_RX_RING_FLAGS_UNICAST_RX   = 1 << 10,
233 	HTT_RX_RING_FLAGS_MULTICAST_RX = 1 << 11,
234 	HTT_RX_RING_FLAGS_CTRL_RX      = 1 << 12,
235 	HTT_RX_RING_FLAGS_MGMT_RX      = 1 << 13,
236 	HTT_RX_RING_FLAGS_NULL_RX      = 1 << 14,
237 	HTT_RX_RING_FLAGS_PHY_DATA_RX  = 1 << 15
238 };
239 
240 #define HTT_RX_RING_SIZE_MIN 128
241 #define HTT_RX_RING_SIZE_MAX 2048
242 #define HTT_RX_RING_SIZE HTT_RX_RING_SIZE_MAX
243 #define HTT_RX_RING_FILL_LEVEL (((HTT_RX_RING_SIZE) / 2) - 1)
244 #define HTT_RX_RING_FILL_LEVEL_DUAL_MAC (HTT_RX_RING_SIZE - 1)
245 
246 struct htt_rx_ring_rx_desc_offsets {
247 	/* the following offsets are in 4-byte units */
248 	__le16 mac80211_hdr_offset;
249 	__le16 msdu_payload_offset;
250 	__le16 ppdu_start_offset;
251 	__le16 ppdu_end_offset;
252 	__le16 mpdu_start_offset;
253 	__le16 mpdu_end_offset;
254 	__le16 msdu_start_offset;
255 	__le16 msdu_end_offset;
256 	__le16 rx_attention_offset;
257 	__le16 frag_info_offset;
258 } __packed;
259 
260 struct htt_rx_ring_setup_ring32 {
261 	__le32 fw_idx_shadow_reg_paddr;
262 	__le32 rx_ring_base_paddr;
263 	__le16 rx_ring_len; /* in 4-byte words */
264 	__le16 rx_ring_bufsize; /* rx skb size - in bytes */
265 	__le16 flags; /* %HTT_RX_RING_FLAGS_ */
266 	__le16 fw_idx_init_val;
267 
268 	struct htt_rx_ring_rx_desc_offsets offsets;
269 } __packed;
270 
271 struct htt_rx_ring_setup_ring64 {
272 	__le64 fw_idx_shadow_reg_paddr;
273 	__le64 rx_ring_base_paddr;
274 	__le16 rx_ring_len; /* in 4-byte words */
275 	__le16 rx_ring_bufsize; /* rx skb size - in bytes */
276 	__le16 flags; /* %HTT_RX_RING_FLAGS_ */
277 	__le16 fw_idx_init_val;
278 
279 	struct htt_rx_ring_rx_desc_offsets offsets;
280 } __packed;
281 
282 struct htt_rx_ring_setup_hdr {
283 	u8 num_rings; /* supported values: 1, 2 */
284 	__le16 rsvd0;
285 } __packed;
286 
287 struct htt_rx_ring_setup_32 {
288 	struct htt_rx_ring_setup_hdr hdr;
289 	struct htt_rx_ring_setup_ring32 rings[];
290 } __packed;
291 
292 struct htt_rx_ring_setup_64 {
293 	struct htt_rx_ring_setup_hdr hdr;
294 	struct htt_rx_ring_setup_ring64 rings[];
295 } __packed;
296 
297 /*
298  * htt_stats_req - request target to send specified statistics
299  *
300  * @msg_type: hardcoded %HTT_H2T_MSG_TYPE_STATS_REQ
301  * @upload_types: see %htt_dbg_stats_type. this is 24bit field actually
302  *	so make sure its little-endian.
303  * @reset_types: see %htt_dbg_stats_type. this is 24bit field actually
304  *	so make sure its little-endian.
305  * @cfg_val: stat_type specific configuration
306  * @stat_type: see %htt_dbg_stats_type
307  * @cookie_lsb: used for confirmation message from target->host
308  * @cookie_msb: ditto as %cookie
309  */
310 struct htt_stats_req {
311 	u8 upload_types[3];
312 	u8 rsvd0;
313 	u8 reset_types[3];
314 	struct {
315 		u8 mpdu_bytes;
316 		u8 mpdu_num_msdus;
317 		u8 msdu_bytes;
318 	} __packed;
319 	u8 stat_type;
320 	__le32 cookie_lsb;
321 	__le32 cookie_msb;
322 } __packed;
323 
324 #define HTT_STATS_REQ_CFG_STAT_TYPE_INVALID 0xff
325 #define HTT_STATS_BIT_MASK GENMASK(16, 0)
326 
327 /*
328  * htt_oob_sync_req - request out-of-band sync
329  *
330  * The HTT SYNC tells the target to suspend processing of subsequent
331  * HTT host-to-target messages until some other target agent locally
332  * informs the target HTT FW that the current sync counter is equal to
333  * or greater than (in a modulo sense) the sync counter specified in
334  * the SYNC message.
335  *
336  * This allows other host-target components to synchronize their operation
337  * with HTT, e.g. to ensure that tx frames don't get transmitted until a
338  * security key has been downloaded to and activated by the target.
339  * In the absence of any explicit synchronization counter value
340  * specification, the target HTT FW will use zero as the default current
341  * sync value.
342  *
343  * The HTT target FW will suspend its host->target message processing as long
344  * as 0 < (in-band sync counter - out-of-band sync counter) & 0xff < 128.
345  */
346 struct htt_oob_sync_req {
347 	u8 sync_count;
348 	__le16 rsvd0;
349 } __packed;
350 
351 struct htt_aggr_conf {
352 	u8 max_num_ampdu_subframes;
353 	/* amsdu_subframes is limited by 0x1F mask */
354 	u8 max_num_amsdu_subframes;
355 } __packed;
356 
357 struct htt_aggr_conf_v2 {
358 	u8 max_num_ampdu_subframes;
359 	/* amsdu_subframes is limited by 0x1F mask */
360 	u8 max_num_amsdu_subframes;
361 	u8 reserved;
362 } __packed;
363 
364 #define HTT_MGMT_FRM_HDR_DOWNLOAD_LEN 32
365 struct htt_mgmt_tx_desc_qca99x0 {
366 	__le32 rate;
367 } __packed;
368 
369 struct htt_mgmt_tx_desc {
370 	u8 pad[sizeof(u32) - sizeof(struct htt_cmd_hdr)];
371 	__le32 msdu_paddr;
372 	__le32 desc_id;
373 	__le32 len;
374 	__le32 vdev_id;
375 	u8 hdr[HTT_MGMT_FRM_HDR_DOWNLOAD_LEN];
376 	union {
377 		struct htt_mgmt_tx_desc_qca99x0 qca99x0;
378 	} __packed;
379 } __packed;
380 
381 enum htt_mgmt_tx_status {
382 	HTT_MGMT_TX_STATUS_OK    = 0,
383 	HTT_MGMT_TX_STATUS_RETRY = 1,
384 	HTT_MGMT_TX_STATUS_DROP  = 2
385 };
386 
387 /*=== target -> host messages ===============================================*/
388 
389 enum htt_main_t2h_msg_type {
390 	HTT_MAIN_T2H_MSG_TYPE_VERSION_CONF             = 0x0,
391 	HTT_MAIN_T2H_MSG_TYPE_RX_IND                   = 0x1,
392 	HTT_MAIN_T2H_MSG_TYPE_RX_FLUSH                 = 0x2,
393 	HTT_MAIN_T2H_MSG_TYPE_PEER_MAP                 = 0x3,
394 	HTT_MAIN_T2H_MSG_TYPE_PEER_UNMAP               = 0x4,
395 	HTT_MAIN_T2H_MSG_TYPE_RX_ADDBA                 = 0x5,
396 	HTT_MAIN_T2H_MSG_TYPE_RX_DELBA                 = 0x6,
397 	HTT_MAIN_T2H_MSG_TYPE_TX_COMPL_IND             = 0x7,
398 	HTT_MAIN_T2H_MSG_TYPE_PKTLOG                   = 0x8,
399 	HTT_MAIN_T2H_MSG_TYPE_STATS_CONF               = 0x9,
400 	HTT_MAIN_T2H_MSG_TYPE_RX_FRAG_IND              = 0xa,
401 	HTT_MAIN_T2H_MSG_TYPE_SEC_IND                  = 0xb,
402 	HTT_MAIN_T2H_MSG_TYPE_TX_INSPECT_IND           = 0xd,
403 	HTT_MAIN_T2H_MSG_TYPE_MGMT_TX_COMPL_IND        = 0xe,
404 	HTT_MAIN_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND     = 0xf,
405 	HTT_MAIN_T2H_MSG_TYPE_RX_PN_IND                = 0x10,
406 	HTT_MAIN_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND   = 0x11,
407 	HTT_MAIN_T2H_MSG_TYPE_TEST,
408 	/* keep this last */
409 	HTT_MAIN_T2H_NUM_MSGS
410 };
411 
412 enum htt_10x_t2h_msg_type {
413 	HTT_10X_T2H_MSG_TYPE_VERSION_CONF              = 0x0,
414 	HTT_10X_T2H_MSG_TYPE_RX_IND                    = 0x1,
415 	HTT_10X_T2H_MSG_TYPE_RX_FLUSH                  = 0x2,
416 	HTT_10X_T2H_MSG_TYPE_PEER_MAP                  = 0x3,
417 	HTT_10X_T2H_MSG_TYPE_PEER_UNMAP                = 0x4,
418 	HTT_10X_T2H_MSG_TYPE_RX_ADDBA                  = 0x5,
419 	HTT_10X_T2H_MSG_TYPE_RX_DELBA                  = 0x6,
420 	HTT_10X_T2H_MSG_TYPE_TX_COMPL_IND              = 0x7,
421 	HTT_10X_T2H_MSG_TYPE_PKTLOG                    = 0x8,
422 	HTT_10X_T2H_MSG_TYPE_STATS_CONF                = 0x9,
423 	HTT_10X_T2H_MSG_TYPE_RX_FRAG_IND               = 0xa,
424 	HTT_10X_T2H_MSG_TYPE_SEC_IND                   = 0xb,
425 	HTT_10X_T2H_MSG_TYPE_RC_UPDATE_IND             = 0xc,
426 	HTT_10X_T2H_MSG_TYPE_TX_INSPECT_IND            = 0xd,
427 	HTT_10X_T2H_MSG_TYPE_TEST                      = 0xe,
428 	HTT_10X_T2H_MSG_TYPE_CHAN_CHANGE               = 0xf,
429 	HTT_10X_T2H_MSG_TYPE_AGGR_CONF                 = 0x11,
430 	HTT_10X_T2H_MSG_TYPE_STATS_NOUPLOAD            = 0x12,
431 	HTT_10X_T2H_MSG_TYPE_MGMT_TX_COMPL_IND         = 0x13,
432 	/* keep this last */
433 	HTT_10X_T2H_NUM_MSGS
434 };
435 
436 enum htt_tlv_t2h_msg_type {
437 	HTT_TLV_T2H_MSG_TYPE_VERSION_CONF              = 0x0,
438 	HTT_TLV_T2H_MSG_TYPE_RX_IND                    = 0x1,
439 	HTT_TLV_T2H_MSG_TYPE_RX_FLUSH                  = 0x2,
440 	HTT_TLV_T2H_MSG_TYPE_PEER_MAP                  = 0x3,
441 	HTT_TLV_T2H_MSG_TYPE_PEER_UNMAP                = 0x4,
442 	HTT_TLV_T2H_MSG_TYPE_RX_ADDBA                  = 0x5,
443 	HTT_TLV_T2H_MSG_TYPE_RX_DELBA                  = 0x6,
444 	HTT_TLV_T2H_MSG_TYPE_TX_COMPL_IND              = 0x7,
445 	HTT_TLV_T2H_MSG_TYPE_PKTLOG                    = 0x8,
446 	HTT_TLV_T2H_MSG_TYPE_STATS_CONF                = 0x9,
447 	HTT_TLV_T2H_MSG_TYPE_RX_FRAG_IND               = 0xa,
448 	HTT_TLV_T2H_MSG_TYPE_SEC_IND                   = 0xb,
449 	HTT_TLV_T2H_MSG_TYPE_RC_UPDATE_IND             = 0xc, /* deprecated */
450 	HTT_TLV_T2H_MSG_TYPE_TX_INSPECT_IND            = 0xd,
451 	HTT_TLV_T2H_MSG_TYPE_MGMT_TX_COMPL_IND         = 0xe,
452 	HTT_TLV_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND      = 0xf,
453 	HTT_TLV_T2H_MSG_TYPE_RX_PN_IND                 = 0x10,
454 	HTT_TLV_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND    = 0x11,
455 	HTT_TLV_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND       = 0x12,
456 	/* 0x13 reservd */
457 	HTT_TLV_T2H_MSG_TYPE_WDI_IPA_OP_RESPONSE       = 0x14,
458 	HTT_TLV_T2H_MSG_TYPE_CHAN_CHANGE               = 0x15,
459 	HTT_TLV_T2H_MSG_TYPE_RX_OFLD_PKT_ERR           = 0x16,
460 	HTT_TLV_T2H_MSG_TYPE_TEST,
461 	/* keep this last */
462 	HTT_TLV_T2H_NUM_MSGS
463 };
464 
465 enum htt_10_4_t2h_msg_type {
466 	HTT_10_4_T2H_MSG_TYPE_VERSION_CONF           = 0x0,
467 	HTT_10_4_T2H_MSG_TYPE_RX_IND                 = 0x1,
468 	HTT_10_4_T2H_MSG_TYPE_RX_FLUSH               = 0x2,
469 	HTT_10_4_T2H_MSG_TYPE_PEER_MAP               = 0x3,
470 	HTT_10_4_T2H_MSG_TYPE_PEER_UNMAP             = 0x4,
471 	HTT_10_4_T2H_MSG_TYPE_RX_ADDBA               = 0x5,
472 	HTT_10_4_T2H_MSG_TYPE_RX_DELBA               = 0x6,
473 	HTT_10_4_T2H_MSG_TYPE_TX_COMPL_IND           = 0x7,
474 	HTT_10_4_T2H_MSG_TYPE_PKTLOG                 = 0x8,
475 	HTT_10_4_T2H_MSG_TYPE_STATS_CONF             = 0x9,
476 	HTT_10_4_T2H_MSG_TYPE_RX_FRAG_IND            = 0xa,
477 	HTT_10_4_T2H_MSG_TYPE_SEC_IND                = 0xb,
478 	HTT_10_4_T2H_MSG_TYPE_RC_UPDATE_IND          = 0xc,
479 	HTT_10_4_T2H_MSG_TYPE_TX_INSPECT_IND         = 0xd,
480 	HTT_10_4_T2H_MSG_TYPE_MGMT_TX_COMPL_IND      = 0xe,
481 	HTT_10_4_T2H_MSG_TYPE_CHAN_CHANGE            = 0xf,
482 	HTT_10_4_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND   = 0x10,
483 	HTT_10_4_T2H_MSG_TYPE_RX_PN_IND              = 0x11,
484 	HTT_10_4_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND = 0x12,
485 	HTT_10_4_T2H_MSG_TYPE_TEST                   = 0x13,
486 	HTT_10_4_T2H_MSG_TYPE_EN_STATS               = 0x14,
487 	HTT_10_4_T2H_MSG_TYPE_AGGR_CONF              = 0x15,
488 	HTT_10_4_T2H_MSG_TYPE_TX_FETCH_IND           = 0x16,
489 	HTT_10_4_T2H_MSG_TYPE_TX_FETCH_CONFIRM       = 0x17,
490 	HTT_10_4_T2H_MSG_TYPE_STATS_NOUPLOAD         = 0x18,
491 	/* 0x19 to 0x2f are reserved */
492 	HTT_10_4_T2H_MSG_TYPE_TX_MODE_SWITCH_IND     = 0x30,
493 	HTT_10_4_T2H_MSG_TYPE_PEER_STATS	     = 0x31,
494 	/* keep this last */
495 	HTT_10_4_T2H_NUM_MSGS
496 };
497 
498 enum htt_t2h_msg_type {
499 	HTT_T2H_MSG_TYPE_VERSION_CONF,
500 	HTT_T2H_MSG_TYPE_RX_IND,
501 	HTT_T2H_MSG_TYPE_RX_FLUSH,
502 	HTT_T2H_MSG_TYPE_PEER_MAP,
503 	HTT_T2H_MSG_TYPE_PEER_UNMAP,
504 	HTT_T2H_MSG_TYPE_RX_ADDBA,
505 	HTT_T2H_MSG_TYPE_RX_DELBA,
506 	HTT_T2H_MSG_TYPE_TX_COMPL_IND,
507 	HTT_T2H_MSG_TYPE_PKTLOG,
508 	HTT_T2H_MSG_TYPE_STATS_CONF,
509 	HTT_T2H_MSG_TYPE_RX_FRAG_IND,
510 	HTT_T2H_MSG_TYPE_SEC_IND,
511 	HTT_T2H_MSG_TYPE_RC_UPDATE_IND,
512 	HTT_T2H_MSG_TYPE_TX_INSPECT_IND,
513 	HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION,
514 	HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND,
515 	HTT_T2H_MSG_TYPE_RX_PN_IND,
516 	HTT_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND,
517 	HTT_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND,
518 	HTT_T2H_MSG_TYPE_WDI_IPA_OP_RESPONSE,
519 	HTT_T2H_MSG_TYPE_CHAN_CHANGE,
520 	HTT_T2H_MSG_TYPE_RX_OFLD_PKT_ERR,
521 	HTT_T2H_MSG_TYPE_AGGR_CONF,
522 	HTT_T2H_MSG_TYPE_STATS_NOUPLOAD,
523 	HTT_T2H_MSG_TYPE_TEST,
524 	HTT_T2H_MSG_TYPE_EN_STATS,
525 	HTT_T2H_MSG_TYPE_TX_FETCH_IND,
526 	HTT_T2H_MSG_TYPE_TX_FETCH_CONFIRM,
527 	HTT_T2H_MSG_TYPE_TX_MODE_SWITCH_IND,
528 	HTT_T2H_MSG_TYPE_PEER_STATS,
529 	/* keep this last */
530 	HTT_T2H_NUM_MSGS
531 };
532 
533 /*
534  * htt_resp_hdr - header for target-to-host messages
535  *
536  * msg_type: see htt_t2h_msg_type
537  */
538 struct htt_resp_hdr {
539 	u8 msg_type;
540 } __packed;
541 
542 #define HTT_RESP_HDR_MSG_TYPE_OFFSET 0
543 #define HTT_RESP_HDR_MSG_TYPE_MASK   0xff
544 #define HTT_RESP_HDR_MSG_TYPE_LSB    0
545 
546 /* htt_ver_resp - response sent for htt_ver_req */
547 struct htt_ver_resp {
548 	u8 minor;
549 	u8 major;
550 	u8 rsvd0;
551 } __packed;
552 
553 #define HTT_MGMT_TX_CMPL_FLAG_ACK_RSSI BIT(0)
554 
555 #define HTT_MGMT_TX_CMPL_INFO_ACK_RSSI_MASK	GENMASK(7, 0)
556 
557 struct htt_mgmt_tx_completion {
558 	u8 rsvd0;
559 	u8 rsvd1;
560 	u8 flags;
561 	__le32 desc_id;
562 	__le32 status;
563 	__le32 ppdu_id;
564 	__le32 info;
565 } __packed;
566 
567 #define HTT_RX_INDICATION_INFO0_EXT_TID_MASK  (0x1F)
568 #define HTT_RX_INDICATION_INFO0_EXT_TID_LSB   (0)
569 #define HTT_RX_INDICATION_INFO0_FLUSH_VALID   (1 << 5)
570 #define HTT_RX_INDICATION_INFO0_RELEASE_VALID (1 << 6)
571 #define HTT_RX_INDICATION_INFO0_PPDU_DURATION BIT(7)
572 
573 #define HTT_RX_INDICATION_INFO1_FLUSH_START_SEQNO_MASK   0x0000003F
574 #define HTT_RX_INDICATION_INFO1_FLUSH_START_SEQNO_LSB    0
575 #define HTT_RX_INDICATION_INFO1_FLUSH_END_SEQNO_MASK     0x00000FC0
576 #define HTT_RX_INDICATION_INFO1_FLUSH_END_SEQNO_LSB      6
577 #define HTT_RX_INDICATION_INFO1_RELEASE_START_SEQNO_MASK 0x0003F000
578 #define HTT_RX_INDICATION_INFO1_RELEASE_START_SEQNO_LSB  12
579 #define HTT_RX_INDICATION_INFO1_RELEASE_END_SEQNO_MASK   0x00FC0000
580 #define HTT_RX_INDICATION_INFO1_RELEASE_END_SEQNO_LSB    18
581 #define HTT_RX_INDICATION_INFO1_NUM_MPDU_RANGES_MASK     0xFF000000
582 #define HTT_RX_INDICATION_INFO1_NUM_MPDU_RANGES_LSB      24
583 
584 #define HTT_TX_CMPL_FLAG_DATA_RSSI		BIT(0)
585 #define HTT_TX_CMPL_FLAG_PPID_PRESENT		BIT(1)
586 #define HTT_TX_CMPL_FLAG_PA_PRESENT		BIT(2)
587 #define HTT_TX_CMPL_FLAG_PPDU_DURATION_PRESENT	BIT(3)
588 
589 #define HTT_TX_DATA_RSSI_ENABLE_WCN3990 BIT(3)
590 #define HTT_TX_DATA_APPEND_RETRIES BIT(0)
591 #define HTT_TX_DATA_APPEND_TIMESTAMP BIT(1)
592 
593 struct htt_rx_indication_hdr {
594 	u8 info0; /* %HTT_RX_INDICATION_INFO0_ */
595 	__le16 peer_id;
596 	__le32 info1; /* %HTT_RX_INDICATION_INFO1_ */
597 } __packed;
598 
599 #define HTT_RX_INDICATION_INFO0_PHY_ERR_VALID    (1 << 0)
600 #define HTT_RX_INDICATION_INFO0_LEGACY_RATE_MASK (0x1E)
601 #define HTT_RX_INDICATION_INFO0_LEGACY_RATE_LSB  (1)
602 #define HTT_RX_INDICATION_INFO0_LEGACY_RATE_CCK  (1 << 5)
603 #define HTT_RX_INDICATION_INFO0_END_VALID        (1 << 6)
604 #define HTT_RX_INDICATION_INFO0_START_VALID      (1 << 7)
605 
606 #define HTT_RX_INDICATION_INFO1_VHT_SIG_A1_MASK    0x00FFFFFF
607 #define HTT_RX_INDICATION_INFO1_VHT_SIG_A1_LSB     0
608 #define HTT_RX_INDICATION_INFO1_PREAMBLE_TYPE_MASK 0xFF000000
609 #define HTT_RX_INDICATION_INFO1_PREAMBLE_TYPE_LSB  24
610 
611 #define HTT_RX_INDICATION_INFO2_VHT_SIG_A1_MASK 0x00FFFFFF
612 #define HTT_RX_INDICATION_INFO2_VHT_SIG_A1_LSB  0
613 #define HTT_RX_INDICATION_INFO2_SERVICE_MASK    0xFF000000
614 #define HTT_RX_INDICATION_INFO2_SERVICE_LSB     24
615 
616 enum htt_rx_legacy_rate {
617 	HTT_RX_OFDM_48 = 0,
618 	HTT_RX_OFDM_24 = 1,
619 	HTT_RX_OFDM_12,
620 	HTT_RX_OFDM_6,
621 	HTT_RX_OFDM_54,
622 	HTT_RX_OFDM_36,
623 	HTT_RX_OFDM_18,
624 	HTT_RX_OFDM_9,
625 
626 	/* long preamble */
627 	HTT_RX_CCK_11_LP = 0,
628 	HTT_RX_CCK_5_5_LP = 1,
629 	HTT_RX_CCK_2_LP,
630 	HTT_RX_CCK_1_LP,
631 	/* short preamble */
632 	HTT_RX_CCK_11_SP,
633 	HTT_RX_CCK_5_5_SP,
634 	HTT_RX_CCK_2_SP
635 };
636 
637 enum htt_rx_legacy_rate_type {
638 	HTT_RX_LEGACY_RATE_OFDM = 0,
639 	HTT_RX_LEGACY_RATE_CCK
640 };
641 
642 enum htt_rx_preamble_type {
643 	HTT_RX_LEGACY        = 0x4,
644 	HTT_RX_HT            = 0x8,
645 	HTT_RX_HT_WITH_TXBF  = 0x9,
646 	HTT_RX_VHT           = 0xC,
647 	HTT_RX_VHT_WITH_TXBF = 0xD,
648 };
649 
650 /*
651  * Fields: phy_err_valid, phy_err_code, tsf,
652  * usec_timestamp, sub_usec_timestamp
653  * ..are valid only if end_valid == 1.
654  *
655  * Fields: rssi_chains, legacy_rate_type,
656  * legacy_rate_cck, preamble_type, service,
657  * vht_sig_*
658  * ..are valid only if start_valid == 1;
659  */
660 struct htt_rx_indication_ppdu {
661 	u8 combined_rssi;
662 	u8 sub_usec_timestamp;
663 	u8 phy_err_code;
664 	u8 info0; /* HTT_RX_INDICATION_INFO0_ */
665 	struct {
666 		u8 pri20_db;
667 		u8 ext20_db;
668 		u8 ext40_db;
669 		u8 ext80_db;
670 	} __packed rssi_chains[4];
671 	__le32 tsf;
672 	__le32 usec_timestamp;
673 	__le32 info1; /* HTT_RX_INDICATION_INFO1_ */
674 	__le32 info2; /* HTT_RX_INDICATION_INFO2_ */
675 } __packed;
676 
677 enum htt_rx_mpdu_status {
678 	HTT_RX_IND_MPDU_STATUS_UNKNOWN = 0x0,
679 	HTT_RX_IND_MPDU_STATUS_OK,
680 	HTT_RX_IND_MPDU_STATUS_ERR_FCS,
681 	HTT_RX_IND_MPDU_STATUS_ERR_DUP,
682 	HTT_RX_IND_MPDU_STATUS_ERR_REPLAY,
683 	HTT_RX_IND_MPDU_STATUS_ERR_INV_PEER,
684 	/* only accept EAPOL frames */
685 	HTT_RX_IND_MPDU_STATUS_UNAUTH_PEER,
686 	HTT_RX_IND_MPDU_STATUS_OUT_OF_SYNC,
687 	/* Non-data in promiscuous mode */
688 	HTT_RX_IND_MPDU_STATUS_MGMT_CTRL,
689 	HTT_RX_IND_MPDU_STATUS_TKIP_MIC_ERR,
690 	HTT_RX_IND_MPDU_STATUS_DECRYPT_ERR,
691 	HTT_RX_IND_MPDU_STATUS_MPDU_LENGTH_ERR,
692 	HTT_RX_IND_MPDU_STATUS_ENCRYPT_REQUIRED_ERR,
693 	HTT_RX_IND_MPDU_STATUS_PRIVACY_ERR,
694 
695 	/*
696 	 * MISC: discard for unspecified reasons.
697 	 * Leave this enum value last.
698 	 */
699 	HTT_RX_IND_MPDU_STATUS_ERR_MISC = 0xFF
700 };
701 
702 struct htt_rx_indication_mpdu_range {
703 	u8 mpdu_count;
704 	u8 mpdu_range_status; /* %htt_rx_mpdu_status */
705 	u8 pad0;
706 	u8 pad1;
707 } __packed;
708 
709 struct htt_rx_indication_prefix {
710 	__le16 fw_rx_desc_bytes;
711 	u8 pad0;
712 	u8 pad1;
713 };
714 
715 struct htt_rx_indication {
716 	struct htt_rx_indication_hdr hdr;
717 	struct htt_rx_indication_ppdu ppdu;
718 	struct htt_rx_indication_prefix prefix;
719 
720 	/*
721 	 * the following fields are both dynamically sized, so
722 	 * take care addressing them
723 	 */
724 
725 	/* the size of this is %fw_rx_desc_bytes */
726 	struct fw_rx_desc_base fw_desc;
727 
728 	/*
729 	 * %mpdu_ranges starts after &%prefix + roundup(%fw_rx_desc_bytes, 4)
730 	 * and has %num_mpdu_ranges elements.
731 	 */
732 	struct htt_rx_indication_mpdu_range mpdu_ranges[];
733 } __packed;
734 
735 /* High latency version of the RX indication */
736 struct htt_rx_indication_hl {
737 	struct htt_rx_indication_hdr hdr;
738 	struct htt_rx_indication_ppdu ppdu;
739 	struct htt_rx_indication_prefix prefix;
740 	struct fw_rx_desc_hl fw_desc;
741 	struct htt_rx_indication_mpdu_range mpdu_ranges[];
742 } __packed;
743 
744 struct htt_hl_rx_desc {
745 	__le32 info;
746 	__le32 pn_31_0;
747 	union {
748 		struct {
749 			__le16 pn_47_32;
750 			__le16 pn_63_48;
751 		} pn16;
752 		__le32 pn_63_32;
753 	} u0;
754 	__le32 pn_95_64;
755 	__le32 pn_127_96;
756 } __packed;
757 
758 static inline struct htt_rx_indication_mpdu_range *
759 		htt_rx_ind_get_mpdu_ranges(struct htt_rx_indication *rx_ind)
760 {
761 #if defined(__linux__)
762 	void *ptr = rx_ind;
763 #elif defined(__FreeBSD__)
764 	u8 *ptr = (void *)rx_ind;
765 #endif
766 
767 	ptr += sizeof(rx_ind->hdr)
768 	     + sizeof(rx_ind->ppdu)
769 	     + sizeof(rx_ind->prefix)
770 	     + roundup(__le16_to_cpu(rx_ind->prefix.fw_rx_desc_bytes), 4);
771 #if defined(__linux__)
772 	return ptr;
773 #elif defined(__FreeBSD__)
774 	return ((void *)ptr);
775 #endif
776 }
777 
778 static inline struct htt_rx_indication_mpdu_range *
779 	htt_rx_ind_get_mpdu_ranges_hl(struct htt_rx_indication_hl *rx_ind)
780 {
781 #if defined(__linux__)
782 	void *ptr = rx_ind;
783 #elif defined(__FreeBSD__)
784 	u8 *ptr = (void *)rx_ind;
785 #endif
786 
787 	ptr += sizeof(rx_ind->hdr)
788 	     + sizeof(rx_ind->ppdu)
789 	     + sizeof(rx_ind->prefix)
790 	     + sizeof(rx_ind->fw_desc);
791 #if defined(__linux__)
792 	return ptr;
793 #elif defined(__FreeBSD__)
794 	return ((void *)ptr);
795 #endif
796 }
797 
798 enum htt_rx_flush_mpdu_status {
799 	HTT_RX_FLUSH_MPDU_DISCARD = 0,
800 	HTT_RX_FLUSH_MPDU_REORDER = 1,
801 };
802 
803 /*
804  * htt_rx_flush - discard or reorder given range of mpdus
805  *
806  * Note: host must check if all sequence numbers between
807  *	[seq_num_start, seq_num_end-1] are valid.
808  */
809 struct htt_rx_flush {
810 	__le16 peer_id;
811 	u8 tid;
812 	u8 rsvd0;
813 	u8 mpdu_status; /* %htt_rx_flush_mpdu_status */
814 	u8 seq_num_start; /* it is 6 LSBs of 802.11 seq no */
815 	u8 seq_num_end; /* it is 6 LSBs of 802.11 seq no */
816 };
817 
818 struct htt_rx_peer_map {
819 	u8 vdev_id;
820 	__le16 peer_id;
821 	u8 addr[6];
822 	u8 rsvd0;
823 	u8 rsvd1;
824 } __packed;
825 
826 struct htt_rx_peer_unmap {
827 	u8 rsvd0;
828 	__le16 peer_id;
829 } __packed;
830 
831 enum htt_txrx_sec_cast_type {
832 	HTT_TXRX_SEC_MCAST = 0,
833 	HTT_TXRX_SEC_UCAST
834 };
835 
836 enum htt_rx_pn_check_type {
837 	HTT_RX_NON_PN_CHECK = 0,
838 	HTT_RX_PN_CHECK
839 };
840 
841 enum htt_rx_tkip_demic_type {
842 	HTT_RX_NON_TKIP_MIC = 0,
843 	HTT_RX_TKIP_MIC
844 };
845 
846 enum htt_security_types {
847 	HTT_SECURITY_NONE,
848 	HTT_SECURITY_WEP128,
849 	HTT_SECURITY_WEP104,
850 	HTT_SECURITY_WEP40,
851 	HTT_SECURITY_TKIP,
852 	HTT_SECURITY_TKIP_NOMIC,
853 	HTT_SECURITY_AES_CCMP,
854 	HTT_SECURITY_WAPI,
855 
856 	HTT_NUM_SECURITY_TYPES /* keep this last! */
857 };
858 
859 #define ATH10K_HTT_TXRX_PEER_SECURITY_MAX 2
860 #define ATH10K_TXRX_NUM_EXT_TIDS 19
861 #define ATH10K_TXRX_NON_QOS_TID 16
862 
863 enum htt_security_flags {
864 #define HTT_SECURITY_TYPE_MASK 0x7F
865 #define HTT_SECURITY_TYPE_LSB  0
866 	HTT_SECURITY_IS_UNICAST = 1 << 7
867 };
868 
869 struct htt_security_indication {
870 	union {
871 		/* dont use bitfields; undefined behaviour */
872 		u8 flags; /* %htt_security_flags */
873 		struct {
874 			u8 security_type:7, /* %htt_security_types */
875 			   is_unicast:1;
876 		} __packed;
877 	} __packed;
878 	__le16 peer_id;
879 	u8 michael_key[8];
880 	u8 wapi_rsc[16];
881 } __packed;
882 
883 #define HTT_RX_BA_INFO0_TID_MASK     0x000F
884 #define HTT_RX_BA_INFO0_TID_LSB      0
885 #define HTT_RX_BA_INFO0_PEER_ID_MASK 0xFFF0
886 #define HTT_RX_BA_INFO0_PEER_ID_LSB  4
887 
888 struct htt_rx_addba {
889 	u8 window_size;
890 	__le16 info0; /* %HTT_RX_BA_INFO0_ */
891 } __packed;
892 
893 struct htt_rx_delba {
894 	u8 rsvd0;
895 	__le16 info0; /* %HTT_RX_BA_INFO0_ */
896 } __packed;
897 
898 enum htt_data_tx_status {
899 	HTT_DATA_TX_STATUS_OK            = 0,
900 	HTT_DATA_TX_STATUS_DISCARD       = 1,
901 	HTT_DATA_TX_STATUS_NO_ACK        = 2,
902 	HTT_DATA_TX_STATUS_POSTPONE      = 3, /* HL only */
903 	HTT_DATA_TX_STATUS_DOWNLOAD_FAIL = 128
904 };
905 
906 enum htt_data_tx_flags {
907 #define HTT_DATA_TX_STATUS_MASK 0x07
908 #define HTT_DATA_TX_STATUS_LSB  0
909 #define HTT_DATA_TX_TID_MASK    0x78
910 #define HTT_DATA_TX_TID_LSB     3
911 	HTT_DATA_TX_TID_INVALID = 1 << 7
912 };
913 
914 #define HTT_TX_COMPL_INV_MSDU_ID 0xFFFF
915 
916 struct htt_append_retries {
917 	__le16 msdu_id;
918 	u8 tx_retries;
919 	u8 flag;
920 } __packed;
921 
922 struct htt_data_tx_completion_ext {
923 	struct htt_append_retries a_retries;
924 	__le32 t_stamp;
925 	__le16 msdus_rssi[];
926 } __packed;
927 
928 /**
929  * @brief target -> host TX completion indication message definition
930  *
931  * @details
932  * The following diagram shows the format of the TX completion indication sent
933  * from the target to the host
934  *
935  *          |31 28|27|26|25|24|23        16| 15 |14 11|10   8|7          0|
936  *          |-------------------------------------------------------------|
937  * header:  |rsvd |A2|TP|A1|A0|     num    | t_i| tid |status|  msg_type  |
938  *          |-------------------------------------------------------------|
939  * payload: |            MSDU1 ID          |         MSDU0 ID             |
940  *          |-------------------------------------------------------------|
941  *          :            MSDU3 ID          :         MSDU2 ID             :
942  *          |-------------------------------------------------------------|
943  *          |          struct htt_tx_compl_ind_append_retries             |
944  *          |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -|
945  *          |          struct htt_tx_compl_ind_append_tx_tstamp           |
946  *          |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -|
947  *          |           MSDU1 ACK RSSI     |        MSDU0 ACK RSSI        |
948  *          |-------------------------------------------------------------|
949  *          :           MSDU3 ACK RSSI     :        MSDU2 ACK RSSI        :
950  *          |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -|
951  *    -msg_type
952  *     Bits 7:0
953  *     Purpose: identifies this as HTT TX completion indication
954  *    -status
955  *     Bits 10:8
956  *     Purpose: the TX completion status of payload fragmentations descriptors
957  *     Value: could be HTT_TX_COMPL_IND_STAT_OK or HTT_TX_COMPL_IND_STAT_DISCARD
958  *    -tid
959  *     Bits 14:11
960  *     Purpose: the tid associated with those fragmentation descriptors. It is
961  *     valid or not, depending on the tid_invalid bit.
962  *     Value: 0 to 15
963  *    -tid_invalid
964  *     Bits 15:15
965  *     Purpose: this bit indicates whether the tid field is valid or not
966  *     Value: 0 indicates valid, 1 indicates invalid
967  *    -num
968  *     Bits 23:16
969  *     Purpose: the number of payload in this indication
970  *     Value: 1 to 255
971  *    -A0 = append
972  *     Bits 24:24
973  *     Purpose: append the struct htt_tx_compl_ind_append_retries which contains
974  *            the number of tx retries for one MSDU at the end of this message
975  *     Value: 0 indicates no appending, 1 indicates appending
976  *    -A1 = append1
977  *     Bits 25:25
978  *     Purpose: Append the struct htt_tx_compl_ind_append_tx_tstamp which
979  *            contains the timestamp info for each TX msdu id in payload.
980  *     Value: 0 indicates no appending, 1 indicates appending
981  *    -TP = MSDU tx power presence
982  *     Bits 26:26
983  *     Purpose: Indicate whether the TX_COMPL_IND includes a tx power report
984  *            for each MSDU referenced by the TX_COMPL_IND message.
985  *            The order of the per-MSDU tx power reports matches the order
986  *            of the MSDU IDs.
987  *     Value: 0 indicates not appending, 1 indicates appending
988  *    -A2 = append2
989  *     Bits 27:27
990  *     Purpose: Indicate whether data ACK RSSI is appended for each MSDU in
991  *            TX_COMP_IND message.  The order of the per-MSDU ACK RSSI report
992  *            matches the order of the MSDU IDs.
993  *            The ACK RSSI values are valid when status is COMPLETE_OK (and
994  *            this append2 bit is set).
995  *     Value: 0 indicates not appending, 1 indicates appending
996  */
997 
998 struct htt_data_tx_completion {
999 	union {
1000 		u8 flags;
1001 		struct {
1002 			u8 status:3,
1003 			   tid:4,
1004 			   tid_invalid:1;
1005 		} __packed;
1006 	} __packed;
1007 	u8 num_msdus;
1008 	u8 flags2; /* HTT_TX_CMPL_FLAG_DATA_RSSI */
1009 	__le16 msdus[]; /* variable length based on %num_msdus */
1010 } __packed;
1011 
1012 #define HTT_TX_PPDU_DUR_INFO0_PEER_ID_MASK	GENMASK(15, 0)
1013 #define HTT_TX_PPDU_DUR_INFO0_TID_MASK		GENMASK(20, 16)
1014 
1015 struct htt_data_tx_ppdu_dur {
1016 	__le32 info0; /* HTT_TX_PPDU_DUR_INFO0_ */
1017 	__le32 tx_duration; /* in usecs */
1018 } __packed;
1019 
1020 #define HTT_TX_COMPL_PPDU_DUR_INFO0_NUM_ENTRIES_MASK	GENMASK(7, 0)
1021 
1022 struct htt_data_tx_compl_ppdu_dur {
1023 	__le32 info0; /* HTT_TX_COMPL_PPDU_DUR_INFO0_ */
1024 	struct htt_data_tx_ppdu_dur ppdu_dur[];
1025 } __packed;
1026 
1027 struct htt_tx_compl_ind_base {
1028 	u32 hdr;
1029 	u16 payload[1/*or more*/];
1030 } __packed;
1031 
1032 struct htt_rc_tx_done_params {
1033 	u32 rate_code;
1034 	u32 rate_code_flags;
1035 	u32 flags;
1036 	u32 num_enqued; /* 1 for non-AMPDU */
1037 	u32 num_retries;
1038 	u32 num_failed; /* for AMPDU */
1039 	u32 ack_rssi;
1040 	u32 time_stamp;
1041 	u32 is_probe;
1042 };
1043 
1044 struct htt_rc_update {
1045 	u8 vdev_id;
1046 	__le16 peer_id;
1047 	u8 addr[6];
1048 	u8 num_elems;
1049 	u8 rsvd0;
1050 	struct htt_rc_tx_done_params params[]; /* variable length %num_elems */
1051 } __packed;
1052 
1053 /* see htt_rx_indication for similar fields and descriptions */
1054 struct htt_rx_fragment_indication {
1055 	union {
1056 		u8 info0; /* %HTT_RX_FRAG_IND_INFO0_ */
1057 		struct {
1058 			u8 ext_tid:5,
1059 			   flush_valid:1;
1060 		} __packed;
1061 	} __packed;
1062 	__le16 peer_id;
1063 	__le32 info1; /* %HTT_RX_FRAG_IND_INFO1_ */
1064 	__le16 fw_rx_desc_bytes;
1065 	__le16 rsvd0;
1066 
1067 	u8 fw_msdu_rx_desc[];
1068 } __packed;
1069 
1070 #define ATH10K_IEEE80211_EXTIV               BIT(5)
1071 #define ATH10K_IEEE80211_TKIP_MICLEN         8   /* trailing MIC */
1072 
1073 #define HTT_RX_FRAG_IND_INFO0_HEADER_LEN     16
1074 
1075 #define HTT_RX_FRAG_IND_INFO0_EXT_TID_MASK     0x1F
1076 #define HTT_RX_FRAG_IND_INFO0_EXT_TID_LSB      0
1077 #define HTT_RX_FRAG_IND_INFO0_FLUSH_VALID_MASK 0x20
1078 #define HTT_RX_FRAG_IND_INFO0_FLUSH_VALID_LSB  5
1079 
1080 #define HTT_RX_FRAG_IND_INFO1_FLUSH_SEQ_NUM_START_MASK 0x0000003F
1081 #define HTT_RX_FRAG_IND_INFO1_FLUSH_SEQ_NUM_START_LSB  0
1082 #define HTT_RX_FRAG_IND_INFO1_FLUSH_SEQ_NUM_END_MASK   0x00000FC0
1083 #define HTT_RX_FRAG_IND_INFO1_FLUSH_SEQ_NUM_END_LSB    6
1084 
1085 struct htt_rx_pn_ind {
1086 	__le16 peer_id;
1087 	u8 tid;
1088 	u8 seqno_start;
1089 	u8 seqno_end;
1090 	u8 pn_ie_count;
1091 	u8 reserved;
1092 	u8 pn_ies[];
1093 } __packed;
1094 
1095 struct htt_rx_offload_msdu {
1096 	__le16 msdu_len;
1097 	__le16 peer_id;
1098 	u8 vdev_id;
1099 	u8 tid;
1100 	u8 fw_desc;
1101 	u8 payload[];
1102 } __packed;
1103 
1104 struct htt_rx_offload_ind {
1105 	u8 reserved;
1106 	__le16 msdu_count;
1107 } __packed;
1108 
1109 struct htt_rx_in_ord_msdu_desc {
1110 	__le32 msdu_paddr;
1111 	__le16 msdu_len;
1112 	u8 fw_desc;
1113 	u8 reserved;
1114 } __packed;
1115 
1116 struct htt_rx_in_ord_msdu_desc_ext {
1117 	__le64 msdu_paddr;
1118 	__le16 msdu_len;
1119 	u8 fw_desc;
1120 	u8 reserved;
1121 } __packed;
1122 
1123 struct htt_rx_in_ord_ind {
1124 	u8 info;
1125 	__le16 peer_id;
1126 	u8 vdev_id;
1127 	u8 reserved;
1128 	__le16 msdu_count;
1129 	union {
1130 		struct htt_rx_in_ord_msdu_desc msdu_descs32[0];
1131 		struct htt_rx_in_ord_msdu_desc_ext msdu_descs64[0];
1132 	} __packed;
1133 } __packed;
1134 
1135 #define HTT_RX_IN_ORD_IND_INFO_TID_MASK		0x0000001f
1136 #define HTT_RX_IN_ORD_IND_INFO_TID_LSB		0
1137 #define HTT_RX_IN_ORD_IND_INFO_OFFLOAD_MASK	0x00000020
1138 #define HTT_RX_IN_ORD_IND_INFO_OFFLOAD_LSB	5
1139 #define HTT_RX_IN_ORD_IND_INFO_FRAG_MASK	0x00000040
1140 #define HTT_RX_IN_ORD_IND_INFO_FRAG_LSB		6
1141 
1142 /*
1143  * target -> host test message definition
1144  *
1145  * The following field definitions describe the format of the test
1146  * message sent from the target to the host.
1147  * The message consists of a 4-octet header, followed by a variable
1148  * number of 32-bit integer values, followed by a variable number
1149  * of 8-bit character values.
1150  *
1151  * |31                         16|15           8|7            0|
1152  * |-----------------------------------------------------------|
1153  * |          num chars          |   num ints   |   msg type   |
1154  * |-----------------------------------------------------------|
1155  * |                           int 0                           |
1156  * |-----------------------------------------------------------|
1157  * |                           int 1                           |
1158  * |-----------------------------------------------------------|
1159  * |                            ...                            |
1160  * |-----------------------------------------------------------|
1161  * |    char 3    |    char 2    |    char 1    |    char 0    |
1162  * |-----------------------------------------------------------|
1163  * |              |              |      ...     |    char 4    |
1164  * |-----------------------------------------------------------|
1165  *   - MSG_TYPE
1166  *     Bits 7:0
1167  *     Purpose: identifies this as a test message
1168  *     Value: HTT_MSG_TYPE_TEST
1169  *   - NUM_INTS
1170  *     Bits 15:8
1171  *     Purpose: indicate how many 32-bit integers follow the message header
1172  *   - NUM_CHARS
1173  *     Bits 31:16
1174  *     Purpose: indicate how many 8-bit characters follow the series of integers
1175  */
1176 struct htt_rx_test {
1177 	u8 num_ints;
1178 	__le16 num_chars;
1179 
1180 	/* payload consists of 2 lists:
1181 	 *  a) num_ints * sizeof(__le32)
1182 	 *  b) num_chars * sizeof(u8) aligned to 4bytes
1183 	 */
1184 	u8 payload[];
1185 } __packed;
1186 
1187 static inline __le32 *htt_rx_test_get_ints(struct htt_rx_test *rx_test)
1188 {
1189 	return (__le32 *)rx_test->payload;
1190 }
1191 
1192 static inline u8 *htt_rx_test_get_chars(struct htt_rx_test *rx_test)
1193 {
1194 	return rx_test->payload + (rx_test->num_ints * sizeof(__le32));
1195 }
1196 
1197 /*
1198  * target -> host packet log message
1199  *
1200  * The following field definitions describe the format of the packet log
1201  * message sent from the target to the host.
1202  * The message consists of a 4-octet header,followed by a variable number
1203  * of 32-bit character values.
1204  *
1205  * |31          24|23          16|15           8|7            0|
1206  * |-----------------------------------------------------------|
1207  * |              |              |              |   msg type   |
1208  * |-----------------------------------------------------------|
1209  * |                        payload                            |
1210  * |-----------------------------------------------------------|
1211  *   - MSG_TYPE
1212  *     Bits 7:0
1213  *     Purpose: identifies this as a test message
1214  *     Value: HTT_MSG_TYPE_PACKETLOG
1215  */
1216 struct htt_pktlog_msg {
1217 	u8 pad[3];
1218 	u8 payload[];
1219 } __packed;
1220 
1221 struct htt_dbg_stats_rx_reorder_stats {
1222 	/* Non QoS MPDUs received */
1223 	__le32 deliver_non_qos;
1224 
1225 	/* MPDUs received in-order */
1226 	__le32 deliver_in_order;
1227 
1228 	/* Flush due to reorder timer expired */
1229 	__le32 deliver_flush_timeout;
1230 
1231 	/* Flush due to move out of window */
1232 	__le32 deliver_flush_oow;
1233 
1234 	/* Flush due to DELBA */
1235 	__le32 deliver_flush_delba;
1236 
1237 	/* MPDUs dropped due to FCS error */
1238 	__le32 fcs_error;
1239 
1240 	/* MPDUs dropped due to monitor mode non-data packet */
1241 	__le32 mgmt_ctrl;
1242 
1243 	/* MPDUs dropped due to invalid peer */
1244 	__le32 invalid_peer;
1245 
1246 	/* MPDUs dropped due to duplication (non aggregation) */
1247 	__le32 dup_non_aggr;
1248 
1249 	/* MPDUs dropped due to processed before */
1250 	__le32 dup_past;
1251 
1252 	/* MPDUs dropped due to duplicate in reorder queue */
1253 	__le32 dup_in_reorder;
1254 
1255 	/* Reorder timeout happened */
1256 	__le32 reorder_timeout;
1257 
1258 	/* invalid bar ssn */
1259 	__le32 invalid_bar_ssn;
1260 
1261 	/* reorder reset due to bar ssn */
1262 	__le32 ssn_reset;
1263 };
1264 
1265 struct htt_dbg_stats_wal_tx_stats {
1266 	/* Num HTT cookies queued to dispatch list */
1267 	__le32 comp_queued;
1268 
1269 	/* Num HTT cookies dispatched */
1270 	__le32 comp_delivered;
1271 
1272 	/* Num MSDU queued to WAL */
1273 	__le32 msdu_enqued;
1274 
1275 	/* Num MPDU queue to WAL */
1276 	__le32 mpdu_enqued;
1277 
1278 	/* Num MSDUs dropped by WMM limit */
1279 	__le32 wmm_drop;
1280 
1281 	/* Num Local frames queued */
1282 	__le32 local_enqued;
1283 
1284 	/* Num Local frames done */
1285 	__le32 local_freed;
1286 
1287 	/* Num queued to HW */
1288 	__le32 hw_queued;
1289 
1290 	/* Num PPDU reaped from HW */
1291 	__le32 hw_reaped;
1292 
1293 	/* Num underruns */
1294 	__le32 underrun;
1295 
1296 	/* Num PPDUs cleaned up in TX abort */
1297 	__le32 tx_abort;
1298 
1299 	/* Num MPDUs requeued by SW */
1300 	__le32 mpdus_requeued;
1301 
1302 	/* excessive retries */
1303 	__le32 tx_ko;
1304 
1305 	/* data hw rate code */
1306 	__le32 data_rc;
1307 
1308 	/* Scheduler self triggers */
1309 	__le32 self_triggers;
1310 
1311 	/* frames dropped due to excessive sw retries */
1312 	__le32 sw_retry_failure;
1313 
1314 	/* illegal rate phy errors  */
1315 	__le32 illgl_rate_phy_err;
1316 
1317 	/* wal pdev continuous xretry */
1318 	__le32 pdev_cont_xretry;
1319 
1320 	/* wal pdev continuous xretry */
1321 	__le32 pdev_tx_timeout;
1322 
1323 	/* wal pdev resets  */
1324 	__le32 pdev_resets;
1325 
1326 	__le32 phy_underrun;
1327 
1328 	/* MPDU is more than txop limit */
1329 	__le32 txop_ovf;
1330 } __packed;
1331 
1332 struct htt_dbg_stats_wal_rx_stats {
1333 	/* Cnts any change in ring routing mid-ppdu */
1334 	__le32 mid_ppdu_route_change;
1335 
1336 	/* Total number of statuses processed */
1337 	__le32 status_rcvd;
1338 
1339 	/* Extra frags on rings 0-3 */
1340 	__le32 r0_frags;
1341 	__le32 r1_frags;
1342 	__le32 r2_frags;
1343 	__le32 r3_frags;
1344 
1345 	/* MSDUs / MPDUs delivered to HTT */
1346 	__le32 htt_msdus;
1347 	__le32 htt_mpdus;
1348 
1349 	/* MSDUs / MPDUs delivered to local stack */
1350 	__le32 loc_msdus;
1351 	__le32 loc_mpdus;
1352 
1353 	/* AMSDUs that have more MSDUs than the status ring size */
1354 	__le32 oversize_amsdu;
1355 
1356 	/* Number of PHY errors */
1357 	__le32 phy_errs;
1358 
1359 	/* Number of PHY errors drops */
1360 	__le32 phy_err_drop;
1361 
1362 	/* Number of mpdu errors - FCS, MIC, ENC etc. */
1363 	__le32 mpdu_errs;
1364 } __packed;
1365 
1366 struct htt_dbg_stats_wal_peer_stats {
1367 	__le32 dummy; /* REMOVE THIS ONCE REAL PEER STAT COUNTERS ARE ADDED */
1368 } __packed;
1369 
1370 struct htt_dbg_stats_wal_pdev_txrx {
1371 	struct htt_dbg_stats_wal_tx_stats tx_stats;
1372 	struct htt_dbg_stats_wal_rx_stats rx_stats;
1373 	struct htt_dbg_stats_wal_peer_stats peer_stats;
1374 } __packed;
1375 
1376 struct htt_dbg_stats_rx_rate_info {
1377 	__le32 mcs[10];
1378 	__le32 sgi[10];
1379 	__le32 nss[4];
1380 	__le32 stbc[10];
1381 	__le32 bw[3];
1382 	__le32 pream[6];
1383 	__le32 ldpc;
1384 	__le32 txbf;
1385 };
1386 
1387 /*
1388  * htt_dbg_stats_status -
1389  * present -     The requested stats have been delivered in full.
1390  *               This indicates that either the stats information was contained
1391  *               in its entirety within this message, or else this message
1392  *               completes the delivery of the requested stats info that was
1393  *               partially delivered through earlier STATS_CONF messages.
1394  * partial -     The requested stats have been delivered in part.
1395  *               One or more subsequent STATS_CONF messages with the same
1396  *               cookie value will be sent to deliver the remainder of the
1397  *               information.
1398  * error -       The requested stats could not be delivered, for example due
1399  *               to a shortage of memory to construct a message holding the
1400  *               requested stats.
1401  * invalid -     The requested stat type is either not recognized, or the
1402  *               target is configured to not gather the stats type in question.
1403  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1404  * series_done - This special value indicates that no further stats info
1405  *               elements are present within a series of stats info elems
1406  *               (within a stats upload confirmation message).
1407  */
1408 enum htt_dbg_stats_status {
1409 	HTT_DBG_STATS_STATUS_PRESENT     = 0,
1410 	HTT_DBG_STATS_STATUS_PARTIAL     = 1,
1411 	HTT_DBG_STATS_STATUS_ERROR       = 2,
1412 	HTT_DBG_STATS_STATUS_INVALID     = 3,
1413 	HTT_DBG_STATS_STATUS_SERIES_DONE = 7
1414 };
1415 
1416 /*
1417  * host -> target FRAG DESCRIPTOR/MSDU_EXT DESC bank
1418  *
1419  * The following field definitions describe the format of the HTT host
1420  * to target frag_desc/msdu_ext bank configuration message.
1421  * The message contains the based address and the min and max id of the
1422  * MSDU_EXT/FRAG_DESC that will be used by the HTT to map MSDU DESC and
1423  * MSDU_EXT/FRAG_DESC.
1424  * HTT will use id in HTT descriptor instead sending the frag_desc_ptr.
1425  * For QCA988X HW the firmware will use fragment_desc_ptr but in WIFI2.0
1426  * the hardware does the mapping/translation.
1427  *
1428  * Total banks that can be configured is configured to 16.
1429  *
1430  * This should be called before any TX has be initiated by the HTT
1431  *
1432  * |31                         16|15           8|7   5|4       0|
1433  * |------------------------------------------------------------|
1434  * | DESC_SIZE    |  NUM_BANKS   | RES |SWP|pdev|    msg type   |
1435  * |------------------------------------------------------------|
1436  * |                     BANK0_BASE_ADDRESS                     |
1437  * |------------------------------------------------------------|
1438  * |                            ...                             |
1439  * |------------------------------------------------------------|
1440  * |                    BANK15_BASE_ADDRESS                     |
1441  * |------------------------------------------------------------|
1442  * |       BANK0_MAX_ID          |       BANK0_MIN_ID           |
1443  * |------------------------------------------------------------|
1444  * |                            ...                             |
1445  * |------------------------------------------------------------|
1446  * |       BANK15_MAX_ID         |       BANK15_MIN_ID          |
1447  * |------------------------------------------------------------|
1448  * Header fields:
1449  *  - MSG_TYPE
1450  *    Bits 7:0
1451  *    Value: 0x6
1452  *  - BANKx_BASE_ADDRESS
1453  *    Bits 31:0
1454  *    Purpose: Provide a mechanism to specify the base address of the MSDU_EXT
1455  *         bank physical/bus address.
1456  *  - BANKx_MIN_ID
1457  *    Bits 15:0
1458  *    Purpose: Provide a mechanism to specify the min index that needs to
1459  *          mapped.
1460  *  - BANKx_MAX_ID
1461  *    Bits 31:16
1462  *    Purpose: Provide a mechanism to specify the max index that needs to
1463  *
1464  */
1465 struct htt_frag_desc_bank_id {
1466 	__le16 bank_min_id;
1467 	__le16 bank_max_id;
1468 } __packed;
1469 
1470 /* real is 16 but it wouldn't fit in the max htt message size
1471  * so we use a conservatively safe value for now
1472  */
1473 #define HTT_FRAG_DESC_BANK_MAX 4
1474 
1475 #define HTT_FRAG_DESC_BANK_CFG_INFO_PDEV_ID_MASK		0x03
1476 #define HTT_FRAG_DESC_BANK_CFG_INFO_PDEV_ID_LSB			0
1477 #define HTT_FRAG_DESC_BANK_CFG_INFO_SWAP			BIT(2)
1478 #define HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_VALID		BIT(3)
1479 #define HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_DEPTH_TYPE_MASK	BIT(4)
1480 #define HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_DEPTH_TYPE_LSB	4
1481 
1482 enum htt_q_depth_type {
1483 	HTT_Q_DEPTH_TYPE_BYTES = 0,
1484 	HTT_Q_DEPTH_TYPE_MSDUS = 1,
1485 };
1486 
1487 #define HTT_TX_Q_STATE_NUM_PEERS		(TARGET_10_4_NUM_QCACHE_PEERS_MAX + \
1488 						 TARGET_10_4_NUM_VDEVS)
1489 #define HTT_TX_Q_STATE_NUM_TIDS			8
1490 #define HTT_TX_Q_STATE_ENTRY_SIZE		1
1491 #define HTT_TX_Q_STATE_ENTRY_MULTIPLIER		0
1492 
1493 /**
1494  * htt_q_state_conf - part of htt_frag_desc_bank_cfg for host q state config
1495  *
1496  * Defines host q state format and behavior. See htt_q_state.
1497  *
1498  * @record_size: Defines the size of each host q entry in bytes. In practice
1499  *	however firmware (at least 10.4.3-00191) ignores this host
1500  *	configuration value and uses hardcoded value of 1.
1501  * @record_multiplier: This is valid only when q depth type is MSDUs. It
1502  *	defines the exponent for the power of 2 multiplication.
1503  */
1504 struct htt_q_state_conf {
1505 	__le32 paddr;
1506 	__le16 num_peers;
1507 	__le16 num_tids;
1508 	u8 record_size;
1509 	u8 record_multiplier;
1510 	u8 pad[2];
1511 } __packed;
1512 
1513 struct htt_frag_desc_bank_cfg32 {
1514 	u8 info; /* HTT_FRAG_DESC_BANK_CFG_INFO_ */
1515 	u8 num_banks;
1516 	u8 desc_size;
1517 	__le32 bank_base_addrs[HTT_FRAG_DESC_BANK_MAX];
1518 	struct htt_frag_desc_bank_id bank_id[HTT_FRAG_DESC_BANK_MAX];
1519 	struct htt_q_state_conf q_state;
1520 } __packed;
1521 
1522 struct htt_frag_desc_bank_cfg64 {
1523 	u8 info; /* HTT_FRAG_DESC_BANK_CFG_INFO_ */
1524 	u8 num_banks;
1525 	u8 desc_size;
1526 	__le64 bank_base_addrs[HTT_FRAG_DESC_BANK_MAX];
1527 	struct htt_frag_desc_bank_id bank_id[HTT_FRAG_DESC_BANK_MAX];
1528 	struct htt_q_state_conf q_state;
1529 } __packed;
1530 
1531 #define HTT_TX_Q_STATE_ENTRY_COEFFICIENT	128
1532 #define HTT_TX_Q_STATE_ENTRY_FACTOR_MASK	0x3f
1533 #define HTT_TX_Q_STATE_ENTRY_FACTOR_LSB		0
1534 #define HTT_TX_Q_STATE_ENTRY_EXP_MASK		0xc0
1535 #define HTT_TX_Q_STATE_ENTRY_EXP_LSB		6
1536 
1537 /**
1538  * htt_q_state - shared between host and firmware via DMA
1539  *
1540  * This structure is used for the host to expose it's software queue state to
1541  * firmware so that its rate control can schedule fetch requests for optimized
1542  * performance. This is most notably used for MU-MIMO aggregation when multiple
1543  * MU clients are connected.
1544  *
1545  * @count: Each element defines the host queue depth. When q depth type was
1546  *	configured as HTT_Q_DEPTH_TYPE_BYTES then each entry is defined as:
1547  *	FACTOR * 128 * 8^EXP (see HTT_TX_Q_STATE_ENTRY_FACTOR_MASK and
1548  *	HTT_TX_Q_STATE_ENTRY_EXP_MASK). When q depth type was configured as
1549  *	HTT_Q_DEPTH_TYPE_MSDUS the number of packets is scaled by 2 **
1550  *	record_multiplier (see htt_q_state_conf).
1551  * @map: Used by firmware to quickly check which host queues are not empty. It
1552  *	is a bitmap simply saying.
1553  * @seq: Used by firmware to quickly check if the host queues were updated
1554  *	since it last checked.
1555  *
1556  * FIXME: Is the q_state map[] size calculation really correct?
1557  */
1558 struct htt_q_state {
1559 	u8 count[HTT_TX_Q_STATE_NUM_TIDS][HTT_TX_Q_STATE_NUM_PEERS];
1560 	u32 map[HTT_TX_Q_STATE_NUM_TIDS][(HTT_TX_Q_STATE_NUM_PEERS + 31) / 32];
1561 	__le32 seq;
1562 } __packed;
1563 
1564 #define HTT_TX_FETCH_RECORD_INFO_PEER_ID_MASK	0x0fff
1565 #define HTT_TX_FETCH_RECORD_INFO_PEER_ID_LSB	0
1566 #define HTT_TX_FETCH_RECORD_INFO_TID_MASK	0xf000
1567 #define HTT_TX_FETCH_RECORD_INFO_TID_LSB	12
1568 
1569 struct htt_tx_fetch_record {
1570 	__le16 info; /* HTT_TX_FETCH_IND_RECORD_INFO_ */
1571 	__le16 num_msdus;
1572 	__le32 num_bytes;
1573 } __packed;
1574 
1575 struct htt_tx_fetch_ind {
1576 	u8 pad0;
1577 	__le16 fetch_seq_num;
1578 	__le32 token;
1579 	__le16 num_resp_ids;
1580 	__le16 num_records;
1581 	union {
1582 		/* ath10k_htt_get_tx_fetch_ind_resp_ids() */
1583 		DECLARE_FLEX_ARRAY(__le32, resp_ids);
1584 		DECLARE_FLEX_ARRAY(struct htt_tx_fetch_record, records);
1585 	};
1586 } __packed;
1587 
1588 static inline void *
1589 ath10k_htt_get_tx_fetch_ind_resp_ids(struct htt_tx_fetch_ind *ind)
1590 {
1591 	return (void *)&ind->records[le16_to_cpu(ind->num_records)];
1592 }
1593 
1594 struct htt_tx_fetch_resp {
1595 	u8 pad0;
1596 	__le16 resp_id;
1597 	__le16 fetch_seq_num;
1598 	__le16 num_records;
1599 	__le32 token;
1600 	struct htt_tx_fetch_record records[];
1601 } __packed;
1602 
1603 struct htt_tx_fetch_confirm {
1604 	u8 pad0;
1605 	__le16 num_resp_ids;
1606 	__le32 resp_ids[];
1607 } __packed;
1608 
1609 enum htt_tx_mode_switch_mode {
1610 	HTT_TX_MODE_SWITCH_PUSH = 0,
1611 	HTT_TX_MODE_SWITCH_PUSH_PULL = 1,
1612 };
1613 
1614 #define HTT_TX_MODE_SWITCH_IND_INFO0_ENABLE		BIT(0)
1615 #define HTT_TX_MODE_SWITCH_IND_INFO0_NUM_RECORDS_MASK	0xfffe
1616 #define HTT_TX_MODE_SWITCH_IND_INFO0_NUM_RECORDS_LSB	1
1617 
1618 #define HTT_TX_MODE_SWITCH_IND_INFO1_MODE_MASK		0x0003
1619 #define HTT_TX_MODE_SWITCH_IND_INFO1_MODE_LSB		0
1620 #define HTT_TX_MODE_SWITCH_IND_INFO1_THRESHOLD_MASK	0xfffc
1621 #define HTT_TX_MODE_SWITCH_IND_INFO1_THRESHOLD_LSB	2
1622 
1623 #define HTT_TX_MODE_SWITCH_RECORD_INFO0_PEER_ID_MASK	0x0fff
1624 #define HTT_TX_MODE_SWITCH_RECORD_INFO0_PEER_ID_LSB	0
1625 #define HTT_TX_MODE_SWITCH_RECORD_INFO0_TID_MASK	0xf000
1626 #define HTT_TX_MODE_SWITCH_RECORD_INFO0_TID_LSB		12
1627 
1628 struct htt_tx_mode_switch_record {
1629 	__le16 info0; /* HTT_TX_MODE_SWITCH_RECORD_INFO0_ */
1630 	__le16 num_max_msdus;
1631 } __packed;
1632 
1633 struct htt_tx_mode_switch_ind {
1634 	u8 pad0;
1635 	__le16 info0; /* HTT_TX_MODE_SWITCH_IND_INFO0_ */
1636 	__le16 info1; /* HTT_TX_MODE_SWITCH_IND_INFO1_ */
1637 	u8 pad1[2];
1638 	struct htt_tx_mode_switch_record records[];
1639 } __packed;
1640 
1641 struct htt_channel_change {
1642 	u8 pad[3];
1643 	__le32 freq;
1644 	__le32 center_freq1;
1645 	__le32 center_freq2;
1646 	__le32 phymode;
1647 } __packed;
1648 
1649 struct htt_per_peer_tx_stats_ind {
1650 	__le32	succ_bytes;
1651 	__le32  retry_bytes;
1652 	__le32  failed_bytes;
1653 	u8	ratecode;
1654 	u8	flags;
1655 	__le16	peer_id;
1656 	__le16  succ_pkts;
1657 	__le16	retry_pkts;
1658 	__le16	failed_pkts;
1659 	__le16	tx_duration;
1660 	__le32	reserved1;
1661 	__le32	reserved2;
1662 } __packed;
1663 
1664 struct htt_peer_tx_stats {
1665 	u8 num_ppdu;
1666 	u8 ppdu_len;
1667 	u8 version;
1668 	u8 payload[];
1669 } __packed;
1670 
1671 #define ATH10K_10_2_TX_STATS_OFFSET	136
1672 #define PEER_STATS_FOR_NO_OF_PPDUS	4
1673 
1674 struct ath10k_10_2_peer_tx_stats {
1675 	u8 ratecode[PEER_STATS_FOR_NO_OF_PPDUS];
1676 	u8 success_pkts[PEER_STATS_FOR_NO_OF_PPDUS];
1677 	__le16 success_bytes[PEER_STATS_FOR_NO_OF_PPDUS];
1678 	u8 retry_pkts[PEER_STATS_FOR_NO_OF_PPDUS];
1679 	__le16 retry_bytes[PEER_STATS_FOR_NO_OF_PPDUS];
1680 	u8 failed_pkts[PEER_STATS_FOR_NO_OF_PPDUS];
1681 	__le16 failed_bytes[PEER_STATS_FOR_NO_OF_PPDUS];
1682 	u8 flags[PEER_STATS_FOR_NO_OF_PPDUS];
1683 	__le32 tx_duration;
1684 	u8 tx_ppdu_cnt;
1685 	u8 peer_id;
1686 } __packed;
1687 
1688 union htt_rx_pn_t {
1689 	/* WEP: 24-bit PN */
1690 	u32 pn24;
1691 
1692 	/* TKIP or CCMP: 48-bit PN */
1693 	u64 pn48;
1694 
1695 	/* WAPI: 128-bit PN */
1696 	u64 pn128[2];
1697 };
1698 
1699 struct htt_cmd {
1700 	struct htt_cmd_hdr hdr;
1701 	union {
1702 		struct htt_ver_req ver_req;
1703 		struct htt_mgmt_tx_desc mgmt_tx;
1704 		struct htt_data_tx_desc data_tx;
1705 		struct htt_rx_ring_setup_32 rx_setup_32;
1706 		struct htt_rx_ring_setup_64 rx_setup_64;
1707 		struct htt_stats_req stats_req;
1708 		struct htt_oob_sync_req oob_sync_req;
1709 		struct htt_aggr_conf aggr_conf;
1710 		struct htt_aggr_conf_v2 aggr_conf_v2;
1711 		struct htt_frag_desc_bank_cfg32 frag_desc_bank_cfg32;
1712 		struct htt_frag_desc_bank_cfg64 frag_desc_bank_cfg64;
1713 		struct htt_tx_fetch_resp tx_fetch_resp;
1714 	};
1715 } __packed;
1716 
1717 struct htt_resp {
1718 	struct htt_resp_hdr hdr;
1719 	union {
1720 		struct htt_ver_resp ver_resp;
1721 		struct htt_mgmt_tx_completion mgmt_tx_completion;
1722 		struct htt_data_tx_completion data_tx_completion;
1723 		struct htt_rx_indication rx_ind;
1724 		struct htt_rx_indication_hl rx_ind_hl;
1725 		struct htt_rx_fragment_indication rx_frag_ind;
1726 		struct htt_rx_peer_map peer_map;
1727 		struct htt_rx_peer_unmap peer_unmap;
1728 		struct htt_rx_flush rx_flush;
1729 		struct htt_rx_addba rx_addba;
1730 		struct htt_rx_delba rx_delba;
1731 		struct htt_security_indication security_indication;
1732 		struct htt_rc_update rc_update;
1733 		struct htt_rx_test rx_test;
1734 		struct htt_pktlog_msg pktlog_msg;
1735 		struct htt_rx_pn_ind rx_pn_ind;
1736 		struct htt_rx_offload_ind rx_offload_ind;
1737 		struct htt_rx_in_ord_ind rx_in_ord_ind;
1738 		struct htt_tx_fetch_ind tx_fetch_ind;
1739 		struct htt_tx_fetch_confirm tx_fetch_confirm;
1740 		struct htt_tx_mode_switch_ind tx_mode_switch_ind;
1741 		struct htt_channel_change chan_change;
1742 		struct htt_peer_tx_stats peer_tx_stats;
1743 	};
1744 } __packed;
1745 
1746 /*** host side structures follow ***/
1747 
1748 struct htt_tx_done {
1749 	u16 msdu_id;
1750 	u16 status;
1751 	u8 ack_rssi;
1752 };
1753 
1754 enum htt_tx_compl_state {
1755 	HTT_TX_COMPL_STATE_NONE,
1756 	HTT_TX_COMPL_STATE_ACK,
1757 	HTT_TX_COMPL_STATE_NOACK,
1758 	HTT_TX_COMPL_STATE_DISCARD,
1759 };
1760 
1761 struct htt_peer_map_event {
1762 	u8 vdev_id;
1763 	u16 peer_id;
1764 	u8 addr[ETH_ALEN];
1765 };
1766 
1767 struct htt_peer_unmap_event {
1768 	u16 peer_id;
1769 };
1770 
1771 struct ath10k_htt_txbuf_32 {
1772 	struct htt_data_tx_desc_frag frags[2];
1773 	struct ath10k_htc_hdr htc_hdr;
1774 	struct htt_cmd_hdr cmd_hdr;
1775 	struct htt_data_tx_desc cmd_tx;
1776 } __packed __aligned(4);
1777 
1778 struct ath10k_htt_txbuf_64 {
1779 	struct htt_data_tx_desc_frag frags[2];
1780 	struct ath10k_htc_hdr htc_hdr;
1781 	struct htt_cmd_hdr cmd_hdr;
1782 	struct htt_data_tx_desc_64 cmd_tx;
1783 } __packed __aligned(4);
1784 
1785 struct ath10k_htt {
1786 	struct ath10k *ar;
1787 	enum ath10k_htc_ep_id eid;
1788 
1789 	struct sk_buff_head rx_indication_head;
1790 
1791 	u8 target_version_major;
1792 	u8 target_version_minor;
1793 	struct completion target_version_received;
1794 	u8 max_num_amsdu;
1795 	u8 max_num_ampdu;
1796 
1797 	const enum htt_t2h_msg_type *t2h_msg_types;
1798 	u32 t2h_msg_types_max;
1799 
1800 	struct {
1801 		/*
1802 		 * Ring of network buffer objects - This ring is
1803 		 * used exclusively by the host SW. This ring
1804 		 * mirrors the dev_addrs_ring that is shared
1805 		 * between the host SW and the MAC HW. The host SW
1806 		 * uses this netbufs ring to locate the network
1807 		 * buffer objects whose data buffers the HW has
1808 		 * filled.
1809 		 */
1810 		struct sk_buff **netbufs_ring;
1811 
1812 		/* This is used only with firmware supporting IN_ORD_IND.
1813 		 *
1814 		 * With Full Rx Reorder the HTT Rx Ring is more of a temporary
1815 		 * buffer ring from which buffer addresses are copied by the
1816 		 * firmware to MAC Rx ring. Firmware then delivers IN_ORD_IND
1817 		 * pointing to specific (re-ordered) buffers.
1818 		 *
1819 		 * FIXME: With kernel generic hashing functions there's a lot
1820 		 * of hash collisions for sk_buffs.
1821 		 */
1822 		bool in_ord_rx;
1823 		DECLARE_HASHTABLE(skb_table, 4);
1824 
1825 		/*
1826 		 * Ring of buffer addresses -
1827 		 * This ring holds the "physical" device address of the
1828 		 * rx buffers the host SW provides for the MAC HW to
1829 		 * fill.
1830 		 */
1831 		union {
1832 			__le64 *paddrs_ring_64;
1833 			__le32 *paddrs_ring_32;
1834 		};
1835 
1836 		/*
1837 		 * Base address of ring, as a "physical" device address
1838 		 * rather than a CPU address.
1839 		 */
1840 		dma_addr_t base_paddr;
1841 
1842 		/* how many elems in the ring (power of 2) */
1843 		int size;
1844 
1845 		/* size - 1 */
1846 		unsigned int size_mask;
1847 
1848 		/* how many rx buffers to keep in the ring */
1849 		int fill_level;
1850 
1851 		/* how many rx buffers (full+empty) are in the ring */
1852 		int fill_cnt;
1853 
1854 		/*
1855 		 * alloc_idx - where HTT SW has deposited empty buffers
1856 		 * This is allocated in consistent mem, so that the FW can
1857 		 * read this variable, and program the HW's FW_IDX reg with
1858 		 * the value of this shadow register.
1859 		 */
1860 		struct {
1861 			__le32 *vaddr;
1862 			dma_addr_t paddr;
1863 		} alloc_idx;
1864 
1865 		/* where HTT SW has processed bufs filled by rx MAC DMA */
1866 		struct {
1867 			unsigned int msdu_payld;
1868 		} sw_rd_idx;
1869 
1870 		/*
1871 		 * refill_retry_timer - timer triggered when the ring is
1872 		 * not refilled to the level expected
1873 		 */
1874 		struct timer_list refill_retry_timer;
1875 
1876 		/* Protects access to all rx ring buffer state variables */
1877 		spinlock_t lock;
1878 	} rx_ring;
1879 
1880 	unsigned int prefetch_len;
1881 
1882 	/* Protects access to pending_tx, num_pending_tx */
1883 	spinlock_t tx_lock;
1884 	int max_num_pending_tx;
1885 	int num_pending_tx;
1886 	int num_pending_mgmt_tx;
1887 	struct idr pending_tx;
1888 	wait_queue_head_t empty_tx_wq;
1889 
1890 	/* FIFO for storing tx done status {ack, no-ack, discard} and msdu id */
1891 	DECLARE_KFIFO_PTR(txdone_fifo, struct htt_tx_done);
1892 
1893 	/* set if host-fw communication goes haywire
1894 	 * used to avoid further failures
1895 	 */
1896 	bool rx_confused;
1897 	atomic_t num_mpdus_ready;
1898 
1899 	/* This is used to group tx/rx completions separately and process them
1900 	 * in batches to reduce cache stalls
1901 	 */
1902 	struct sk_buff_head rx_msdus_q;
1903 	struct sk_buff_head rx_in_ord_compl_q;
1904 	struct sk_buff_head tx_fetch_ind_q;
1905 
1906 	/* rx_status template */
1907 	struct ieee80211_rx_status rx_status;
1908 
1909 	struct {
1910 		dma_addr_t paddr;
1911 		union {
1912 			struct htt_msdu_ext_desc *vaddr_desc_32;
1913 			struct htt_msdu_ext_desc_64 *vaddr_desc_64;
1914 		};
1915 		size_t size;
1916 	} frag_desc;
1917 
1918 	struct {
1919 		dma_addr_t paddr;
1920 		union {
1921 			struct ath10k_htt_txbuf_32 *vaddr_txbuff_32;
1922 			struct ath10k_htt_txbuf_64 *vaddr_txbuff_64;
1923 		};
1924 		size_t size;
1925 	} txbuf;
1926 
1927 	struct {
1928 		bool enabled;
1929 		struct htt_q_state *vaddr;
1930 		dma_addr_t paddr;
1931 		u16 num_push_allowed;
1932 		u16 num_peers;
1933 		u16 num_tids;
1934 		enum htt_tx_mode_switch_mode mode;
1935 		enum htt_q_depth_type type;
1936 	} tx_q_state;
1937 
1938 	bool tx_mem_allocated;
1939 	const struct ath10k_htt_tx_ops *tx_ops;
1940 	const struct ath10k_htt_rx_ops *rx_ops;
1941 	bool disable_tx_comp;
1942 	bool bundle_tx;
1943 	struct sk_buff_head tx_req_head;
1944 	struct sk_buff_head tx_complete_head;
1945 };
1946 
1947 struct ath10k_htt_tx_ops {
1948 	int (*htt_send_rx_ring_cfg)(struct ath10k_htt *htt);
1949 	int (*htt_send_frag_desc_bank_cfg)(struct ath10k_htt *htt);
1950 	int (*htt_alloc_frag_desc)(struct ath10k_htt *htt);
1951 	void (*htt_free_frag_desc)(struct ath10k_htt *htt);
1952 	int (*htt_tx)(struct ath10k_htt *htt, enum ath10k_hw_txrx_mode txmode,
1953 		      struct sk_buff *msdu);
1954 	int (*htt_alloc_txbuff)(struct ath10k_htt *htt);
1955 	void (*htt_free_txbuff)(struct ath10k_htt *htt);
1956 	int (*htt_h2t_aggr_cfg_msg)(struct ath10k_htt *htt,
1957 				    u8 max_subfrms_ampdu,
1958 				    u8 max_subfrms_amsdu);
1959 	void (*htt_flush_tx)(struct ath10k_htt *htt);
1960 };
1961 
1962 static inline int ath10k_htt_send_rx_ring_cfg(struct ath10k_htt *htt)
1963 {
1964 	if (!htt->tx_ops->htt_send_rx_ring_cfg)
1965 		return -EOPNOTSUPP;
1966 
1967 	return htt->tx_ops->htt_send_rx_ring_cfg(htt);
1968 }
1969 
1970 static inline int ath10k_htt_send_frag_desc_bank_cfg(struct ath10k_htt *htt)
1971 {
1972 	if (!htt->tx_ops->htt_send_frag_desc_bank_cfg)
1973 		return -EOPNOTSUPP;
1974 
1975 	return htt->tx_ops->htt_send_frag_desc_bank_cfg(htt);
1976 }
1977 
1978 static inline int ath10k_htt_alloc_frag_desc(struct ath10k_htt *htt)
1979 {
1980 	if (!htt->tx_ops->htt_alloc_frag_desc)
1981 		return -EOPNOTSUPP;
1982 
1983 	return htt->tx_ops->htt_alloc_frag_desc(htt);
1984 }
1985 
1986 static inline void ath10k_htt_free_frag_desc(struct ath10k_htt *htt)
1987 {
1988 	if (htt->tx_ops->htt_free_frag_desc)
1989 		htt->tx_ops->htt_free_frag_desc(htt);
1990 }
1991 
1992 static inline int ath10k_htt_tx(struct ath10k_htt *htt,
1993 				enum ath10k_hw_txrx_mode txmode,
1994 				struct sk_buff *msdu)
1995 {
1996 	return htt->tx_ops->htt_tx(htt, txmode, msdu);
1997 }
1998 
1999 static inline void ath10k_htt_flush_tx(struct ath10k_htt *htt)
2000 {
2001 	if (htt->tx_ops->htt_flush_tx)
2002 		htt->tx_ops->htt_flush_tx(htt);
2003 }
2004 
2005 static inline int ath10k_htt_alloc_txbuff(struct ath10k_htt *htt)
2006 {
2007 	if (!htt->tx_ops->htt_alloc_txbuff)
2008 		return -EOPNOTSUPP;
2009 
2010 	return htt->tx_ops->htt_alloc_txbuff(htt);
2011 }
2012 
2013 static inline void ath10k_htt_free_txbuff(struct ath10k_htt *htt)
2014 {
2015 	if (htt->tx_ops->htt_free_txbuff)
2016 		htt->tx_ops->htt_free_txbuff(htt);
2017 }
2018 
2019 static inline int ath10k_htt_h2t_aggr_cfg_msg(struct ath10k_htt *htt,
2020 					      u8 max_subfrms_ampdu,
2021 					      u8 max_subfrms_amsdu)
2022 
2023 {
2024 	if (!htt->tx_ops->htt_h2t_aggr_cfg_msg)
2025 		return -EOPNOTSUPP;
2026 
2027 	return htt->tx_ops->htt_h2t_aggr_cfg_msg(htt,
2028 						 max_subfrms_ampdu,
2029 						 max_subfrms_amsdu);
2030 }
2031 
2032 struct ath10k_htt_rx_ops {
2033 	size_t (*htt_get_rx_ring_size)(struct ath10k_htt *htt);
2034 	void (*htt_config_paddrs_ring)(struct ath10k_htt *htt, void *vaddr);
2035 	void (*htt_set_paddrs_ring)(struct ath10k_htt *htt, dma_addr_t paddr,
2036 				    int idx);
2037 	void* (*htt_get_vaddr_ring)(struct ath10k_htt *htt);
2038 	void (*htt_reset_paddrs_ring)(struct ath10k_htt *htt, int idx);
2039 	bool (*htt_rx_proc_rx_frag_ind)(struct ath10k_htt *htt,
2040 					struct htt_rx_fragment_indication *rx,
2041 					struct sk_buff *skb);
2042 };
2043 
2044 static inline size_t ath10k_htt_get_rx_ring_size(struct ath10k_htt *htt)
2045 {
2046 	if (!htt->rx_ops->htt_get_rx_ring_size)
2047 		return 0;
2048 
2049 	return htt->rx_ops->htt_get_rx_ring_size(htt);
2050 }
2051 
2052 static inline void ath10k_htt_config_paddrs_ring(struct ath10k_htt *htt,
2053 						 void *vaddr)
2054 {
2055 	if (htt->rx_ops->htt_config_paddrs_ring)
2056 		htt->rx_ops->htt_config_paddrs_ring(htt, vaddr);
2057 }
2058 
2059 static inline void ath10k_htt_set_paddrs_ring(struct ath10k_htt *htt,
2060 					      dma_addr_t paddr,
2061 					      int idx)
2062 {
2063 	if (htt->rx_ops->htt_set_paddrs_ring)
2064 		htt->rx_ops->htt_set_paddrs_ring(htt, paddr, idx);
2065 }
2066 
2067 static inline void *ath10k_htt_get_vaddr_ring(struct ath10k_htt *htt)
2068 {
2069 	if (!htt->rx_ops->htt_get_vaddr_ring)
2070 		return NULL;
2071 
2072 	return htt->rx_ops->htt_get_vaddr_ring(htt);
2073 }
2074 
2075 static inline void ath10k_htt_reset_paddrs_ring(struct ath10k_htt *htt, int idx)
2076 {
2077 	if (htt->rx_ops->htt_reset_paddrs_ring)
2078 		htt->rx_ops->htt_reset_paddrs_ring(htt, idx);
2079 }
2080 
2081 static inline bool ath10k_htt_rx_proc_rx_frag_ind(struct ath10k_htt *htt,
2082 						  struct htt_rx_fragment_indication *rx,
2083 						  struct sk_buff *skb)
2084 {
2085 	if (!htt->rx_ops->htt_rx_proc_rx_frag_ind)
2086 		return true;
2087 
2088 	return htt->rx_ops->htt_rx_proc_rx_frag_ind(htt, rx, skb);
2089 }
2090 
2091 /* the driver strongly assumes that the rx header status be 64 bytes long,
2092  * so all possible rx_desc structures must respect this assumption.
2093  */
2094 #define RX_HTT_HDR_STATUS_LEN 64
2095 
2096 /* The rx descriptor structure layout is programmed via rx ring setup
2097  * so that FW knows how to transfer the rx descriptor to the host.
2098  * Unfortunately, though, QCA6174's firmware doesn't currently behave correctly
2099  * when modifying the structure layout of the rx descriptor beyond what it expects
2100  * (even if it correctly programmed during the rx ring setup).
2101  * Therefore we must keep two different memory layouts, abstract the rx descriptor
2102  * representation and use ath10k_rx_desc_ops
2103  * for correctly accessing rx descriptor data.
2104  */
2105 
2106 /* base struct used for abstracting the rx descritor representation */
2107 struct htt_rx_desc {
2108 	union {
2109 		/* This field is filled on the host using the msdu buffer
2110 		 * from htt_rx_indication
2111 		 */
2112 		struct fw_rx_desc_base fw_desc;
2113 		u32 pad;
2114 	} __packed;
2115 } __packed;
2116 
2117 /* rx descriptor for wcn3990 and possibly extensible for newer cards
2118  * Buffers like this are placed on the rx ring.
2119  */
2120 struct htt_rx_desc_v2 {
2121 	struct htt_rx_desc base;
2122 	struct {
2123 		struct rx_attention attention;
2124 		struct rx_frag_info frag_info;
2125 		struct rx_mpdu_start mpdu_start;
2126 		struct rx_msdu_start msdu_start;
2127 		struct rx_msdu_end msdu_end;
2128 		struct rx_mpdu_end mpdu_end;
2129 		struct rx_ppdu_start ppdu_start;
2130 		struct rx_ppdu_end ppdu_end;
2131 	} __packed;
2132 	u8 rx_hdr_status[RX_HTT_HDR_STATUS_LEN];
2133 	u8 msdu_payload[];
2134 };
2135 
2136 /* QCA6174, QCA988x, QCA99x0 dedicated rx descriptor to make sure their firmware
2137  * works correctly. We keep a single rx descriptor for all these three
2138  * families of cards because from tests it seems to be the most stable solution,
2139  * e.g. having a rx descriptor only for QCA6174 seldom caused firmware crashes
2140  * during some tests.
2141  * Buffers like this are placed on the rx ring.
2142  */
2143 struct htt_rx_desc_v1 {
2144 	struct htt_rx_desc base;
2145 	struct {
2146 		struct rx_attention attention;
2147 		struct rx_frag_info_v1 frag_info;
2148 		struct rx_mpdu_start mpdu_start;
2149 		struct rx_msdu_start_v1 msdu_start;
2150 		struct rx_msdu_end_v1 msdu_end;
2151 		struct rx_mpdu_end mpdu_end;
2152 		struct rx_ppdu_start ppdu_start;
2153 		struct rx_ppdu_end_v1 ppdu_end;
2154 	} __packed;
2155 	u8 rx_hdr_status[RX_HTT_HDR_STATUS_LEN];
2156 	u8 msdu_payload[];
2157 };
2158 
2159 /* rx_desc abstraction */
2160 struct ath10k_htt_rx_desc_ops {
2161 	/* These fields are mandatory, they must be specified in any instance */
2162 
2163 	/* sizeof() of the rx_desc structure used by this hw */
2164 	size_t rx_desc_size;
2165 
2166 	/* offset of msdu_payload inside the rx_desc structure used by this hw */
2167 	size_t rx_desc_msdu_payload_offset;
2168 
2169 	/* These fields are options.
2170 	 * When a field is not provided the default implementation gets used
2171 	 * (see the ath10k_rx_desc_* operations below for more info about the defaults)
2172 	 */
2173 	bool (*rx_desc_get_msdu_limit_error)(struct htt_rx_desc *rxd);
2174 	int (*rx_desc_get_l3_pad_bytes)(struct htt_rx_desc *rxd);
2175 
2176 	/* Safely cast from a void* buffer containing an rx descriptor
2177 	 * to the proper rx_desc structure
2178 	 */
2179 	struct htt_rx_desc *(*rx_desc_from_raw_buffer)(void *buff);
2180 
2181 	void (*rx_desc_get_offsets)(struct htt_rx_ring_rx_desc_offsets *offs);
2182 	struct rx_attention *(*rx_desc_get_attention)(struct htt_rx_desc *rxd);
2183 	struct rx_frag_info_common *(*rx_desc_get_frag_info)(struct htt_rx_desc *rxd);
2184 	struct rx_mpdu_start *(*rx_desc_get_mpdu_start)(struct htt_rx_desc *rxd);
2185 	struct rx_mpdu_end *(*rx_desc_get_mpdu_end)(struct htt_rx_desc *rxd);
2186 	struct rx_msdu_start_common *(*rx_desc_get_msdu_start)(struct htt_rx_desc *rxd);
2187 	struct rx_msdu_end_common *(*rx_desc_get_msdu_end)(struct htt_rx_desc *rxd);
2188 	struct rx_ppdu_start *(*rx_desc_get_ppdu_start)(struct htt_rx_desc *rxd);
2189 	struct rx_ppdu_end_common *(*rx_desc_get_ppdu_end)(struct htt_rx_desc *rxd);
2190 	u8 *(*rx_desc_get_rx_hdr_status)(struct htt_rx_desc *rxd);
2191 	u8 *(*rx_desc_get_msdu_payload)(struct htt_rx_desc *rxd);
2192 };
2193 
2194 extern const struct ath10k_htt_rx_desc_ops qca988x_rx_desc_ops;
2195 extern const struct ath10k_htt_rx_desc_ops qca99x0_rx_desc_ops;
2196 extern const struct ath10k_htt_rx_desc_ops wcn3990_rx_desc_ops;
2197 
2198 static inline int
2199 ath10k_htt_rx_desc_get_l3_pad_bytes(struct ath10k_hw_params *hw, struct htt_rx_desc *rxd)
2200 {
2201 	if (hw->rx_desc_ops->rx_desc_get_l3_pad_bytes)
2202 		return hw->rx_desc_ops->rx_desc_get_l3_pad_bytes(rxd);
2203 	return 0;
2204 }
2205 
2206 static inline bool
2207 ath10k_htt_rx_desc_msdu_limit_error(struct ath10k_hw_params *hw, struct htt_rx_desc *rxd)
2208 {
2209 	if (hw->rx_desc_ops->rx_desc_get_msdu_limit_error)
2210 		return hw->rx_desc_ops->rx_desc_get_msdu_limit_error(rxd);
2211 	return false;
2212 }
2213 
2214 /* The default implementation of all these getters is using the old rx_desc,
2215  * so that it is easier to define the ath10k_htt_rx_desc_ops instances.
2216  * But probably, if new wireless cards must be supported, it would be better
2217  * to switch the default implementation to the new rx_desc, since this would
2218  * make the extension easier .
2219  */
2220 static inline struct htt_rx_desc *
2221 ath10k_htt_rx_desc_from_raw_buffer(struct ath10k_hw_params *hw,	void *buff)
2222 {
2223 	if (hw->rx_desc_ops->rx_desc_from_raw_buffer)
2224 		return hw->rx_desc_ops->rx_desc_from_raw_buffer(buff);
2225 	return &((struct htt_rx_desc_v1 *)buff)->base;
2226 }
2227 
2228 static inline void
2229 ath10k_htt_rx_desc_get_offsets(struct ath10k_hw_params *hw,
2230 			       struct htt_rx_ring_rx_desc_offsets *off)
2231 {
2232 	if (hw->rx_desc_ops->rx_desc_get_offsets) {
2233 		hw->rx_desc_ops->rx_desc_get_offsets(off);
2234 	} else {
2235 #define	desc_offset(x) (offsetof(struct	htt_rx_desc_v1, x)	/ 4)
2236 		off->mac80211_hdr_offset = __cpu_to_le16(desc_offset(rx_hdr_status));
2237 		off->msdu_payload_offset = __cpu_to_le16(desc_offset(msdu_payload));
2238 		off->ppdu_start_offset = __cpu_to_le16(desc_offset(ppdu_start));
2239 		off->ppdu_end_offset = __cpu_to_le16(desc_offset(ppdu_end));
2240 		off->mpdu_start_offset = __cpu_to_le16(desc_offset(mpdu_start));
2241 		off->mpdu_end_offset = __cpu_to_le16(desc_offset(mpdu_end));
2242 		off->msdu_start_offset = __cpu_to_le16(desc_offset(msdu_start));
2243 		off->msdu_end_offset = __cpu_to_le16(desc_offset(msdu_end));
2244 		off->rx_attention_offset = __cpu_to_le16(desc_offset(attention));
2245 		off->frag_info_offset =	__cpu_to_le16(desc_offset(frag_info));
2246 #undef desc_offset
2247 	}
2248 }
2249 
2250 static inline struct rx_attention *
2251 ath10k_htt_rx_desc_get_attention(struct	ath10k_hw_params *hw, struct htt_rx_desc *rxd)
2252 {
2253 	struct htt_rx_desc_v1 *rx_desc;
2254 
2255 	if (hw->rx_desc_ops->rx_desc_get_attention)
2256 		return hw->rx_desc_ops->rx_desc_get_attention(rxd);
2257 
2258 	rx_desc = container_of(rxd, struct htt_rx_desc_v1, base);
2259 	return &rx_desc->attention;
2260 }
2261 
2262 static inline struct rx_frag_info_common *
2263 ath10k_htt_rx_desc_get_frag_info(struct	ath10k_hw_params *hw, struct htt_rx_desc *rxd)
2264 {
2265 	struct htt_rx_desc_v1 *rx_desc;
2266 
2267 	if (hw->rx_desc_ops->rx_desc_get_frag_info)
2268 		return hw->rx_desc_ops->rx_desc_get_frag_info(rxd);
2269 
2270 	rx_desc = container_of(rxd, struct htt_rx_desc_v1, base);
2271 	return &rx_desc->frag_info.common;
2272 }
2273 
2274 static inline struct rx_mpdu_start *
2275 ath10k_htt_rx_desc_get_mpdu_start(struct ath10k_hw_params *hw, struct htt_rx_desc *rxd)
2276 {
2277 	struct htt_rx_desc_v1 *rx_desc;
2278 
2279 	if (hw->rx_desc_ops->rx_desc_get_mpdu_start)
2280 		return hw->rx_desc_ops->rx_desc_get_mpdu_start(rxd);
2281 
2282 	rx_desc = container_of(rxd, struct htt_rx_desc_v1, base);
2283 	return &rx_desc->mpdu_start;
2284 }
2285 
2286 static inline struct rx_mpdu_end *
2287 ath10k_htt_rx_desc_get_mpdu_end(struct ath10k_hw_params	*hw, struct htt_rx_desc	*rxd)
2288 {
2289 	struct htt_rx_desc_v1 *rx_desc;
2290 
2291 	if (hw->rx_desc_ops->rx_desc_get_mpdu_end)
2292 		return hw->rx_desc_ops->rx_desc_get_mpdu_end(rxd);
2293 
2294 	rx_desc = container_of(rxd, struct htt_rx_desc_v1, base);
2295 	return &rx_desc->mpdu_end;
2296 }
2297 
2298 static inline struct rx_msdu_start_common *
2299 ath10k_htt_rx_desc_get_msdu_start(struct ath10k_hw_params *hw, struct htt_rx_desc *rxd)
2300 {
2301 	struct htt_rx_desc_v1 *rx_desc;
2302 
2303 	if (hw->rx_desc_ops->rx_desc_get_msdu_start)
2304 		return hw->rx_desc_ops->rx_desc_get_msdu_start(rxd);
2305 
2306 	rx_desc = container_of(rxd, struct htt_rx_desc_v1, base);
2307 	return &rx_desc->msdu_start.common;
2308 }
2309 
2310 static inline struct rx_msdu_end_common	*
2311 ath10k_htt_rx_desc_get_msdu_end(struct ath10k_hw_params	*hw, struct htt_rx_desc	*rxd)
2312 {
2313 	struct htt_rx_desc_v1 *rx_desc;
2314 
2315 	if (hw->rx_desc_ops->rx_desc_get_msdu_end)
2316 		return hw->rx_desc_ops->rx_desc_get_msdu_end(rxd);
2317 
2318 	rx_desc = container_of(rxd, struct htt_rx_desc_v1, base);
2319 	return &rx_desc->msdu_end.common;
2320 }
2321 
2322 static inline struct rx_ppdu_start *
2323 ath10k_htt_rx_desc_get_ppdu_start(struct ath10k_hw_params *hw, struct htt_rx_desc *rxd)
2324 {
2325 	struct htt_rx_desc_v1 *rx_desc;
2326 
2327 	if (hw->rx_desc_ops->rx_desc_get_ppdu_start)
2328 		return hw->rx_desc_ops->rx_desc_get_ppdu_start(rxd);
2329 
2330 	rx_desc = container_of(rxd, struct htt_rx_desc_v1, base);
2331 	return &rx_desc->ppdu_start;
2332 }
2333 
2334 static inline struct rx_ppdu_end_common	*
2335 ath10k_htt_rx_desc_get_ppdu_end(struct ath10k_hw_params	*hw, struct htt_rx_desc	*rxd)
2336 {
2337 	struct htt_rx_desc_v1 *rx_desc;
2338 
2339 	if (hw->rx_desc_ops->rx_desc_get_ppdu_end)
2340 		return hw->rx_desc_ops->rx_desc_get_ppdu_end(rxd);
2341 
2342 	rx_desc = container_of(rxd, struct htt_rx_desc_v1, base);
2343 	return &rx_desc->ppdu_end.common;
2344 }
2345 
2346 static inline u8 *
2347 ath10k_htt_rx_desc_get_rx_hdr_status(struct ath10k_hw_params *hw, struct htt_rx_desc *rxd)
2348 {
2349 	struct htt_rx_desc_v1 *rx_desc;
2350 
2351 	if (hw->rx_desc_ops->rx_desc_get_rx_hdr_status)
2352 		return hw->rx_desc_ops->rx_desc_get_rx_hdr_status(rxd);
2353 
2354 	rx_desc = container_of(rxd, struct htt_rx_desc_v1, base);
2355 	return rx_desc->rx_hdr_status;
2356 }
2357 
2358 static inline u8 *
2359 ath10k_htt_rx_desc_get_msdu_payload(struct ath10k_hw_params *hw, struct	htt_rx_desc *rxd)
2360 {
2361 	struct htt_rx_desc_v1 *rx_desc;
2362 
2363 	if (hw->rx_desc_ops->rx_desc_get_msdu_payload)
2364 		return hw->rx_desc_ops->rx_desc_get_msdu_payload(rxd);
2365 
2366 	rx_desc = container_of(rxd, struct htt_rx_desc_v1, base);
2367 	return rx_desc->msdu_payload;
2368 }
2369 
2370 #define HTT_RX_DESC_HL_INFO_SEQ_NUM_MASK           0x00000fff
2371 #define HTT_RX_DESC_HL_INFO_SEQ_NUM_LSB            0
2372 #define HTT_RX_DESC_HL_INFO_ENCRYPTED_MASK         0x00001000
2373 #define HTT_RX_DESC_HL_INFO_ENCRYPTED_LSB          12
2374 #define HTT_RX_DESC_HL_INFO_CHAN_INFO_PRESENT_MASK 0x00002000
2375 #define HTT_RX_DESC_HL_INFO_CHAN_INFO_PRESENT_LSB  13
2376 #define HTT_RX_DESC_HL_INFO_MCAST_BCAST_MASK       0x00010000
2377 #define HTT_RX_DESC_HL_INFO_MCAST_BCAST_LSB        16
2378 #define HTT_RX_DESC_HL_INFO_KEY_ID_OCT_MASK        0x01fe0000
2379 #define HTT_RX_DESC_HL_INFO_KEY_ID_OCT_LSB         17
2380 
2381 struct htt_rx_desc_base_hl {
2382 	__le32 info; /* HTT_RX_DESC_HL_INFO_ */
2383 };
2384 
2385 struct htt_rx_chan_info {
2386 	__le16 primary_chan_center_freq_mhz;
2387 	__le16 contig_chan1_center_freq_mhz;
2388 	__le16 contig_chan2_center_freq_mhz;
2389 	u8 phy_mode;
2390 	u8 reserved;
2391 } __packed;
2392 
2393 #define HTT_RX_DESC_ALIGN 8
2394 
2395 #define HTT_MAC_ADDR_LEN 6
2396 
2397 /*
2398  * FIX THIS
2399  * Should be: sizeof(struct htt_host_rx_desc) + max rx MSDU size,
2400  * rounded up to a cache line size.
2401  */
2402 #define HTT_RX_BUF_SIZE 2048
2403 
2404 /* The HTT_RX_MSDU_SIZE can't be statically computed anymore,
2405  * because it depends on the underlying device rx_desc representation
2406  */
2407 static inline int ath10k_htt_rx_msdu_size(struct ath10k_hw_params *hw)
2408 {
2409 	return HTT_RX_BUF_SIZE - (int)hw->rx_desc_ops->rx_desc_size;
2410 }
2411 
2412 /* Refill a bunch of RX buffers for each refill round so that FW/HW can handle
2413  * aggregated traffic more nicely.
2414  */
2415 #define ATH10K_HTT_MAX_NUM_REFILL 100
2416 
2417 /*
2418  * DMA_MAP expects the buffer to be an integral number of cache lines.
2419  * Rather than checking the actual cache line size, this code makes a
2420  * conservative estimate of what the cache line size could be.
2421  */
2422 #define HTT_LOG2_MAX_CACHE_LINE_SIZE 7	/* 2^7 = 128 */
2423 #define HTT_MAX_CACHE_LINE_SIZE_MASK ((1 << HTT_LOG2_MAX_CACHE_LINE_SIZE) - 1)
2424 
2425 /* These values are default in most firmware revisions and apparently are a
2426  * sweet spot performance wise.
2427  */
2428 #define ATH10K_HTT_MAX_NUM_AMSDU_DEFAULT 3
2429 #define ATH10K_HTT_MAX_NUM_AMPDU_DEFAULT 64
2430 
2431 int ath10k_htt_connect(struct ath10k_htt *htt);
2432 int ath10k_htt_init(struct ath10k *ar);
2433 int ath10k_htt_setup(struct ath10k_htt *htt);
2434 
2435 int ath10k_htt_tx_start(struct ath10k_htt *htt);
2436 void ath10k_htt_tx_stop(struct ath10k_htt *htt);
2437 void ath10k_htt_tx_destroy(struct ath10k_htt *htt);
2438 void ath10k_htt_tx_free(struct ath10k_htt *htt);
2439 
2440 int ath10k_htt_rx_alloc(struct ath10k_htt *htt);
2441 int ath10k_htt_rx_ring_refill(struct ath10k *ar);
2442 void ath10k_htt_rx_free(struct ath10k_htt *htt);
2443 
2444 void ath10k_htt_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb);
2445 void ath10k_htt_htc_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb);
2446 bool ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb);
2447 int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt *htt);
2448 int ath10k_htt_h2t_stats_req(struct ath10k_htt *htt, u32 mask, u32 reset_mask,
2449 			     u64 cookie);
2450 void ath10k_htt_hif_tx_complete(struct ath10k *ar, struct sk_buff *skb);
2451 int ath10k_htt_tx_fetch_resp(struct ath10k *ar,
2452 			     __le32 token,
2453 			     __le16 fetch_seq_num,
2454 			     struct htt_tx_fetch_record *records,
2455 			     size_t num_records);
2456 void ath10k_htt_op_ep_tx_credits(struct ath10k *ar);
2457 
2458 void ath10k_htt_tx_txq_update(struct ieee80211_hw *hw,
2459 			      struct ieee80211_txq *txq);
2460 void ath10k_htt_tx_txq_recalc(struct ieee80211_hw *hw,
2461 			      struct ieee80211_txq *txq);
2462 void ath10k_htt_tx_txq_sync(struct ath10k *ar);
2463 void ath10k_htt_tx_dec_pending(struct ath10k_htt *htt);
2464 int ath10k_htt_tx_inc_pending(struct ath10k_htt *htt);
2465 void ath10k_htt_tx_mgmt_dec_pending(struct ath10k_htt *htt);
2466 int ath10k_htt_tx_mgmt_inc_pending(struct ath10k_htt *htt, bool is_mgmt,
2467 				   bool is_presp);
2468 
2469 int ath10k_htt_tx_alloc_msdu_id(struct ath10k_htt *htt, struct sk_buff *skb);
2470 void ath10k_htt_tx_free_msdu_id(struct ath10k_htt *htt, u16 msdu_id);
2471 int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *msdu);
2472 void ath10k_htt_rx_pktlog_completion_handler(struct ath10k *ar,
2473 					     struct sk_buff *skb);
2474 int ath10k_htt_txrx_compl_task(struct ath10k *ar, int budget);
2475 int ath10k_htt_rx_hl_indication(struct ath10k *ar, int budget);
2476 void ath10k_htt_set_tx_ops(struct ath10k_htt *htt);
2477 void ath10k_htt_set_rx_ops(struct ath10k_htt *htt);
2478 #endif
2479