1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright(c) 2009-2014  Realtek Corporation.*/
3 
4 #ifndef __RTL92E_TRX_H__
5 #define __RTL92E_TRX_H__
6 
7 #define TX_DESC_SIZE					64
8 
9 #define RX_DRV_INFO_SIZE_UNIT				8
10 
11 #define	TX_DESC_NEXT_DESC_OFFSET			40
12 #define USB_HWDESC_HEADER_LEN				40
13 
14 #define RX_DESC_SIZE					24
15 #define MAX_RECEIVE_BUFFER_SIZE				8192
16 
17 #define SET_TX_DESC_PKT_SIZE(__pdesc, __val)		\
18 	SET_BITS_TO_LE_4BYTE(__pdesc, 0, 16, __val)
19 #define SET_TX_DESC_OFFSET(__pdesc, __val)		\
20 	SET_BITS_TO_LE_4BYTE(__pdesc, 16, 8, __val)
21 #define SET_TX_DESC_BMC(__pdesc, __val)			\
22 	SET_BITS_TO_LE_4BYTE(__pdesc, 24, 1, __val)
23 #define SET_TX_DESC_HTC(__pdesc, __val)			\
24 	SET_BITS_TO_LE_4BYTE(__pdesc, 25, 1, __val)
25 #define SET_TX_DESC_LAST_SEG(__pdesc, __val)		\
26 	SET_BITS_TO_LE_4BYTE(__pdesc, 26, 1, __val)
27 #define SET_TX_DESC_FIRST_SEG(__pdesc, __val)		\
28 	SET_BITS_TO_LE_4BYTE(__pdesc, 27, 1, __val)
29 #define SET_TX_DESC_LINIP(__pdesc, __val)		\
30 	SET_BITS_TO_LE_4BYTE(__pdesc, 28, 1, __val)
31 #define SET_TX_DESC_NO_ACM(__pdesc, __val)		\
32 	SET_BITS_TO_LE_4BYTE(__pdesc, 29, 1, __val)
33 #define SET_TX_DESC_GF(__pdesc, __val)			\
34 	SET_BITS_TO_LE_4BYTE(__pdesc, 30, 1, __val)
35 #define SET_TX_DESC_OWN(__pdesc, __val)			\
36 	SET_BITS_TO_LE_4BYTE(__pdesc, 31, 1, __val)
37 
38 #define GET_TX_DESC_PKT_SIZE(__pdesc)			\
39 	LE_BITS_TO_4BYTE(__pdesc, 0, 16)
40 #define GET_TX_DESC_OFFSET(__pdesc)			\
41 	LE_BITS_TO_4BYTE(__pdesc, 16, 8)
42 #define GET_TX_DESC_BMC(__pdesc)			\
43 	LE_BITS_TO_4BYTE(__pdesc, 24, 1)
44 #define GET_TX_DESC_HTC(__pdesc)			\
45 	LE_BITS_TO_4BYTE(__pdesc, 25, 1)
46 #define GET_TX_DESC_LAST_SEG(__pdesc)			\
47 	LE_BITS_TO_4BYTE(__pdesc, 26, 1)
48 #define GET_TX_DESC_FIRST_SEG(__pdesc)			\
49 	LE_BITS_TO_4BYTE(__pdesc, 27, 1)
50 #define GET_TX_DESC_LINIP(__pdesc)			\
51 	LE_BITS_TO_4BYTE(__pdesc, 28, 1)
52 #define GET_TX_DESC_NO_ACM(__pdesc)			\
53 	LE_BITS_TO_4BYTE(__pdesc, 29, 1)
54 #define GET_TX_DESC_GF(__pdesc)				\
55 	LE_BITS_TO_4BYTE(__pdesc, 30, 1)
56 #define GET_TX_DESC_OWN(__pdesc)			\
57 	LE_BITS_TO_4BYTE(__pdesc, 31, 1)
58 
59 #define SET_TX_DESC_MACID(__pdesc, __val)		\
60 	SET_BITS_TO_LE_4BYTE(__pdesc+4, 0, 7, __val)
61 #define SET_TX_DESC_QUEUE_SEL(__pdesc, __val)		\
62 	SET_BITS_TO_LE_4BYTE(__pdesc+4, 8, 5, __val)
63 #define SET_TX_DESC_RDG_NAV_EXT(__pdesc, __val)		\
64 	SET_BITS_TO_LE_4BYTE(__pdesc+4, 13, 1, __val)
65 #define SET_TX_DESC_LSIG_TXOP_EN(__pdesc, __val)	\
66 	SET_BITS_TO_LE_4BYTE(__pdesc+4, 14, 1, __val)
67 #define SET_TX_DESC_PIFS(__pdesc, __val)		\
68 	SET_BITS_TO_LE_4BYTE(__pdesc+4, 15, 1, __val)
69 #define SET_TX_DESC_RATE_ID(__pdesc, __val)		\
70 	SET_BITS_TO_LE_4BYTE(__pdesc+4, 16, 5, __val)
71 #define SET_TX_DESC_EN_DESC_ID(__pdesc, __val)		\
72 	SET_BITS_TO_LE_4BYTE(__pdesc+4, 21, 1, __val)
73 #define SET_TX_DESC_SEC_TYPE(__pdesc, __val)		\
74 	SET_BITS_TO_LE_4BYTE(__pdesc+4, 22, 2, __val)
75 #define SET_TX_DESC_PKT_OFFSET(__pdesc, __val)		\
76 	SET_BITS_TO_LE_4BYTE(__pdesc+4, 24, 5, __val)
77 #define SET_TX_DESC_MORE_DATA(__pdesc, __val)		\
78 	SET_BITS_TO_LE_4BYTE(__pdesc+4, 29, 1, __val)
79 #define SET_TX_DESC_TXOP_PS_CAP(__pdesc, __val)		\
80 	SET_BITS_TO_LE_4BYTE(__pdesc+4, 30, 1, __val)
81 #define SET_TX_DESC_TXOP_PS_MODE(__pdesc, __val)	\
82 	SET_BITS_TO_LE_4BYTE(__pdesc+4, 31, 1, __val)
83 
84 #define GET_TX_DESC_MACID(__pdesc)			\
85 	LE_BITS_TO_4BYTE(__pdesc+4, 0, 5)
86 #define GET_TX_DESC_AGG_ENABLE(__pdesc)			\
87 	LE_BITS_TO_4BYTE(__pdesc+4, 5, 1)
88 #define GET_TX_DESC_AGG_BREAK(__pdesc)			\
89 	LE_BITS_TO_4BYTE(__pdesc+4, 6, 1)
90 #define GET_TX_DESC_RDG_ENABLE(__pdesc)			\
91 	LE_BITS_TO_4BYTE(__pdesc+4, 7, 1)
92 #define GET_TX_DESC_QUEUE_SEL(__pdesc)			\
93 	LE_BITS_TO_4BYTE(__pdesc+4, 8, 5)
94 #define GET_TX_DESC_RDG_NAV_EXT(__pdesc)		\
95 	LE_BITS_TO_4BYTE(__pdesc+4, 13, 1)
96 #define GET_TX_DESC_LSIG_TXOP_EN(__pdesc)		\
97 	LE_BITS_TO_4BYTE(__pdesc+4, 14, 1)
98 #define GET_TX_DESC_PIFS(__pdesc)			\
99 	LE_BITS_TO_4BYTE(__pdesc+4, 15, 1)
100 #define GET_TX_DESC_RATE_ID(__pdesc)			\
101 	LE_BITS_TO_4BYTE(__pdesc+4, 16, 4)
102 #define GET_TX_DESC_NAV_USE_HDR(__pdesc)		\
103 	LE_BITS_TO_4BYTE(__pdesc+4, 20, 1)
104 #define GET_TX_DESC_EN_DESC_ID(__pdesc)			\
105 	LE_BITS_TO_4BYTE(__pdesc+4, 21, 1)
106 #define GET_TX_DESC_SEC_TYPE(__pdesc)			\
107 	LE_BITS_TO_4BYTE(__pdesc+4, 22, 2)
108 #define GET_TX_DESC_PKT_OFFSET(__pdesc)			\
109 	LE_BITS_TO_4BYTE(__pdesc+4, 24, 5)
110 
111 #define SET_TX_DESC_PAID(__pdesc, __val)		\
112 	SET_BITS_TO_LE_4BYTE(__pdesc+8, 0, 9, __val)
113 #define SET_TX_DESC_CCA_RTS(__pdesc, __val)		\
114 	SET_BITS_TO_LE_4BYTE(__pdesc+8, 10, 2, __val)
115 #define SET_TX_DESC_AGG_ENABLE(__pdesc, __val)		\
116 	SET_BITS_TO_LE_4BYTE(__pdesc+8, 12, 1, __val)
117 #define SET_TX_DESC_RDG_ENABLE(__pdesc, __val)		\
118 	SET_BITS_TO_LE_4BYTE(__pdesc+8, 13, 1, __val)
119 #define SET_TX_DESC_NULL_0(__pdesc, __val)		\
120 	SET_BITS_TO_LE_4BYTE(__pdesc+8, 14, 1, __val)
121 #define SET_TX_DESC_NULL_1(__pdesc, __val)		\
122 	SET_BITS_TO_LE_4BYTE((__pdesc) + 8, 15, 1, __val)
123 #define SET_TX_DESC_BK(__pdesc, __val)			\
124 	SET_BITS_TO_LE_4BYTE(__pdesc+8, 16, 1, __val)
125 #define SET_TX_DESC_MORE_FRAG(__pdesc, __val)		\
126 	SET_BITS_TO_LE_4BYTE(__pdesc+8, 17, 1, __val)
127 #define SET_TX_DESC_RAW(__pdesc, __val)			\
128 	SET_BITS_TO_LE_4BYTE(__pdesc+8, 18, 1, __val)
129 #define SET_TX_DESC_SPE_RPT(__pdesc, __val)		\
130 	SET_BITS_TO_LE_4BYTE((__pdesc) + 8, 19, 1, __val)
131 #define SET_TX_DESC_AMPDU_DENSITY(__pdesc, __val)	\
132 	SET_BITS_TO_LE_4BYTE(__pdesc+8, 20, 3, __val)
133 #define SET_TX_DESC_BT_NULL(__pdesc, __val)		\
134 	SET_BITS_TO_LE_4BYTE(__pdesc+8, 23, 1, __val)
135 #define SET_TX_DESC_GID(__pdesc, __val)			\
136 	SET_BITS_TO_LE_4BYTE(__pdesc+8, 24, 6, __val)
137 
138 #define SET_TX_DESC_WHEADER_LEN(__pdesc, __val)		\
139 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 0, 4, __val)
140 #define SET_TX_DESC_CHK_EN(__pdesc, __val)		\
141 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 4, 1, __val)
142 #define SET_TX_DESC_EARLY_RATE(__pdesc, __val)		\
143 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 5, 1, __val)
144 #define SET_TX_DESC_HWSEQ_SEL(__pdesc, __val)		\
145 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 6, 2, __val)
146 #define SET_TX_DESC_USE_RATE(__pdesc, __val)		\
147 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 8, 1, __val)
148 #define SET_TX_DESC_DISABLE_RTS_FB(__pdesc, __val)	\
149 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 9, 1, __val)
150 #define SET_TX_DESC_DISABLE_FB(__pdesc, __val)		\
151 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 10, 1, __val)
152 #define SET_TX_DESC_CTS2SELF(__pdesc, __val)		\
153 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 11, 1, __val)
154 #define SET_TX_DESC_RTS_ENABLE(__pdesc, __val)		\
155 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 12, 1, __val)
156 #define SET_TX_DESC_HW_RTS_ENABLE(__pdesc, __val)	\
157 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 13, 1, __val)
158 #define SET_TX_DESC_HW_PORT_ID(__pdesc, __val)		\
159 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 14, 1, __val)
160 #define SET_TX_DESC_NAV_USE_HDR(__pdesc, __val)		\
161 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 15, 1, __val)
162 #define SET_TX_DESC_USE_MAX_LEN(__pdesc, __val)		\
163 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 16, 1, __val)
164 #define SET_TX_DESC_MAX_AGG_NUM(__pdesc, __val)		\
165 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 17, 5, __val)
166 #define SET_TX_DESC_NDPA(__pdesc, __val)		\
167 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 22, 2, __val)
168 #define SET_TX_DESC_AMPDU_MAX_TIME(__pdesc, __val)	\
169 	SET_BITS_TO_LE_4BYTE(__pdesc+12, 24, 8, __val)
170 
171 /* Dword 4 */
172 #define SET_TX_DESC_TX_RATE(__pdesc, __val)		\
173 	SET_BITS_TO_LE_4BYTE(__pdesc+16, 0, 7, __val)
174 #define SET_TX_DESC_TRY_RATE(__pdesc, __val)		\
175 	SET_BITS_TO_LE_4BYTE(__pdesc+16, 7, 1, __val)
176 #define SET_TX_DESC_DATA_RATE_FB_LIMIT(__pdesc, __val)	\
177 	SET_BITS_TO_LE_4BYTE(__pdesc+16, 8, 5, __val)
178 #define SET_TX_DESC_RTS_RATE_FB_LIMIT(__pdesc, __val)	\
179 	SET_BITS_TO_LE_4BYTE(__pdesc+16, 13, 4, __val)
180 #define SET_TX_DESC_RETRY_LIMIT_ENABLE(__pdesc, __val)	\
181 	SET_BITS_TO_LE_4BYTE(__pdesc+16, 17, 1, __val)
182 #define SET_TX_DESC_DATA_RETRY_LIMIT(__pdesc, __val)	\
183 	SET_BITS_TO_LE_4BYTE(__pdesc+16, 18, 6, __val)
184 #define SET_TX_DESC_RTS_RATE(__pdesc, __val)		\
185 	SET_BITS_TO_LE_4BYTE(__pdesc+16, 24, 5, __val)
186 #define SET_TX_DESC_PCTS_ENABLE(__pdesc, __val)		\
187 	SET_BITS_TO_LE_4BYTE(__pdesc+16, 29, 1, __val)
188 #define SET_TX_DESC_PCTS_MASK_IDX(__pdesc, __val)	\
189 	SET_BITS_TO_LE_4BYTE(__pdesc+16, 30, 2, __val)
190 
191 /* Dword 5 */
192 #define SET_TX_DESC_TX_SUB_CARRIER(__pdesc, __val)	\
193 	SET_BITS_TO_LE_4BYTE(__pdesc+20, 0, 4, __val)
194 #define SET_TX_DESC_DATA_SHORT(__pdesc, __val)		\
195 	SET_BITS_TO_LE_4BYTE(__pdesc+20, 4, 1, __val)
196 #define SET_TX_DESC_DATA_BW(__pdesc, __val)		\
197 	SET_BITS_TO_LE_4BYTE(__pdesc+20, 5, 2, __val)
198 #define SET_TX_DESC_DATA_LDPC(__pdesc, __val)		\
199 	SET_BITS_TO_LE_4BYTE(__pdesc+20, 7, 1, __val)
200 #define SET_TX_DESC_DATA_STBC(__pdesc, __val)		\
201 	SET_BITS_TO_LE_4BYTE(__pdesc+20, 8, 2, __val)
202 #define SET_TX_DESC_VCS_STBC(__pdesc, __val)		\
203 	SET_BITS_TO_LE_4BYTE(__pdesc+20, 10, 2, __val)
204 #define SET_TX_DESC_RTS_SHORT(__pdesc, __val)		\
205 	SET_BITS_TO_LE_4BYTE(__pdesc+20, 12, 1, __val)
206 #define SET_TX_DESC_RTS_SC(__pdesc, __val)		\
207 	SET_BITS_TO_LE_4BYTE(__pdesc+20, 13, 4, __val)
208 #define SET_TX_DESC_TX_ANT(__pdesc, __val)		\
209 	SET_BITS_TO_LE_4BYTE(__pdesc+20, 24, 4, __val)
210 #define SET_TX_DESC_TX_POWER_0_PSET(__pdesc, __val)	\
211 	SET_BITS_TO_LE_4BYTE(__pdesc+20, 28, 3, __val)
212 
213 /* Dword 6 */
214 #define SET_TX_DESC_SW_DEFINE(__pdesc, __val)		\
215 	SET_BITS_TO_LE_4BYTE((__pdesc) + 24, 0, 12, __val)
216 #define SET_TX_DESC_ANTSEL_A(__pdesc, __val)		\
217 	SET_BITS_TO_LE_4BYTE((__pdesc) + 24, 16, 3, __val)
218 #define SET_TX_DESC_ANTSEL_B(__pdesc, __val)		\
219 	SET_BITS_TO_LE_4BYTE((__pdesc) + 24, 19, 3, __val)
220 #define SET_TX_DESC_ANTSEL_C(__pdesc, __val)		\
221 	SET_BITS_TO_LE_4BYTE((__pdesc) + 24, 22, 3, __val)
222 #define SET_TX_DESC_ANTSEL_D(__pdesc, __val)		\
223 	SET_BITS_TO_LE_4BYTE((__pdesc) + 24, 25, 3, __val)
224 
225 /* Dword 7 */
226 #define SET_TX_DESC_TX_BUFFER_SIZE(__pdesc, __val)	\
227 	SET_BITS_TO_LE_4BYTE(__pdesc+28, 0, 16, __val)
228 #define SET_TX_DESC_USB_TXAGG_NUM(__pdesc, __val)	\
229 	SET_BITS_TO_LE_4BYTE(__pdesc+28, 24, 8, __val)
230 
231 /* Dword 8 */
232 #define SET_TX_DESC_RTS_RC(__pdesc, __val)		\
233 	SET_BITS_TO_LE_4BYTE(__pdesc+32, 0, 6, __val)
234 #define SET_TX_DESC_BAR_RTY_TH(__pdesc, __val)		\
235 	SET_BITS_TO_LE_4BYTE(__pdesc+32, 6, 2, __val)
236 #define SET_TX_DESC_DATA_RC(__pdesc, __val)		\
237 	SET_BITS_TO_LE_4BYTE(__pdesc+32, 8, 6, __val)
238 #define SET_TX_DESC_ENABLE_HW_SELECT(__pdesc, __val)	\
239 	SET_BITS_TO_LE_4BYTE(__pdesc+32, 15, 1, __val)
240 #define SET_TX_DESC_NEXT_HEAD_PAGE(__pdesc, __val)	\
241 	SET_BITS_TO_LE_4BYTE(__pdesc+32, 16, 8, __val)
242 #define SET_TX_DESC_TAIL_PAGE(__pdesc, __val)		\
243 	SET_BITS_TO_LE_4BYTE(__pdesc+32, 24, 8, __val)
244 
245 /* Dword 9 */
246 #define SET_TX_DESC_PADDING_LENGTH(__pdesc, __val)	\
247 	SET_BITS_TO_LE_4BYTE(__pdesc+36, 0, 11, __val)
248 #define SET_TX_DESC_TXBF_PATH(__pdesc, __val)		\
249 	SET_BITS_TO_LE_4BYTE(__pdesc+36, 11, 1, __val)
250 #define SET_TX_DESC_SEQ(__pdesc, __val)			\
251 	SET_BITS_TO_LE_4BYTE(__pdesc+36, 12, 12, __val)
252 #define SET_TX_DESC_FINAL_DATA_RATE(__pdesc, __val)	\
253 	SET_BITS_TO_LE_4BYTE(__pdesc+36, 24, 8, __val)
254 
255 /* Dword 10 */
256 #define SET_TX_DESC_TX_BUFFER_ADDRESS(__pdesc, __val)	\
257 	SET_BITS_TO_LE_4BYTE(__pdesc+40, 0, 32, __val)
258 
259 /* Dword 11*/
260 #define SET_TX_DESC_NEXT_DESC_ADDRESS(__pdesc, __val)	\
261 	SET_BITS_TO_LE_4BYTE(__pdesc+48, 0, 32, __val)
262 
263 #define SET_EARLYMODE_PKTNUM(__paddr, __val)		\
264 	SET_BITS_TO_LE_4BYTE(__paddr, 0, 4, __val)
265 #define SET_EARLYMODE_LEN0(__paddr, __val)		\
266 	SET_BITS_TO_LE_4BYTE(__paddr, 4, 15, __val)
267 #define SET_EARLYMODE_LEN1(__paddr, __val)		\
268 	SET_BITS_TO_LE_4BYTE(__paddr, 16, 2, __val)
269 #define SET_EARLYMODE_LEN1_1(__paddr, __val)		\
270 	SET_BITS_TO_LE_4BYTE(__paddr, 19, 13, __val)
271 #define SET_EARLYMODE_LEN1_2(__paddr, __val)		\
272 	SET_BITS_TO_LE_4BYTE(__paddr+4, 0, 2, __val)
273 #define SET_EARLYMODE_LEN2(__paddr, __val)		\
274 	SET_BITS_TO_LE_4BYTE(__paddr+4, 2, 15,  __val)
275 #define SET_EARLYMODE_LEN2_1(__paddr, __val)		\
276 	SET_BITS_TO_LE_4BYTE(__paddr, 2, 4,  __val)
277 #define SET_EARLYMODE_LEN2_2(__paddr, __val)		\
278 	SET_BITS_TO_LE_4BYTE(__paddr+4, 0, 8,  __val)
279 #define SET_EARLYMODE_LEN3(__paddr, __val)		\
280 	SET_BITS_TO_LE_4BYTE(__paddr+4, 17, 15, __val)
281 #define SET_EARLYMODE_LEN4(__paddr, __val)		\
282 	SET_BITS_TO_LE_4BYTE(__paddr+4, 20, 12, __val)
283 
284 /* TX/RX buffer descriptor */
285 
286 #define SET_TX_EXTBUFF_DESC_LEN(__pdesc, __val, __set)	\
287 	SET_BITS_TO_LE_4BYTE(__pdesc+(__set*16), 0, 16, __val)
288 #define SET_TX_EXTBUFF_DESC_ADDR_LOW(__pdesc, __val, __set)\
289 	SET_BITS_TO_LE_4BYTE(__pdesc+(__set*16)+4, 0, 32, __val)
290 #define SET_TX_EXTBUFF_DESC_ADDR_HIGH(__pdesc, __val, __set)\
291 	SET_BITS_TO_LE_4BYTE(__pdesc+(__set*16)+8, 0, 32, __val)
292 
293 /* for Txfilldescroptor92ee, fill the desc content. */
294 #define SET_TXBUFFER_DESC_LEN_WITH_OFFSET(__pdesc, __offset, __val)            \
295 	SET_BITS_TO_LE_4BYTE((__pdesc) + ((__offset) * 16), 0, 16, __val)
296 #define SET_TXBUFFER_DESC_AMSDU_WITH_OFFSET(__pdesc, __offset, __val)          \
297 	SET_BITS_TO_LE_4BYTE((__pdesc) + ((__offset) * 16), 31, 1, __val)
298 #define SET_TXBUFFER_DESC_ADD_LOW_WITH_OFFSET(__pdesc, __offset, __val)        \
299 	SET_BITS_TO_LE_4BYTE((__pdesc) + ((__offset) * 16) + 4, 0, 32, __val)
300 #define SET_TXBUFFER_DESC_ADD_HIGH_WITH_OFFSET(pbd, off, val, dma64)	       \
301 	(dma64 ? SET_BITS_TO_LE_4BYTE((pbd) + ((off) * 16) + 8, 0, 32, val) : 0)
302 #define GET_TXBUFFER_DESC_ADDR_LOW(__pdesc, __offset)                          \
303 	LE_BITS_TO_4BYTE((__pdesc) + ((__offset) * 16) + 4, 0, 32)
304 #define GET_TXBUFFER_DESC_ADDR_HIGH(pbd, off, dma64)			       \
305 	(dma64 ? LE_BITS_TO_4BYTE((pbd) + ((off) * 16) + 8, 0, 32) : 0)
306 
307 /* Dword 0 */
308 #define SET_TX_BUFF_DESC_LEN_0(__pdesc, __val)                                 \
309 	SET_BITS_TO_LE_4BYTE(__pdesc, 0, 14, __val)
310 #define SET_TX_BUFF_DESC_PSB(__pdesc, __val)                                   \
311 	SET_BITS_TO_LE_4BYTE(__pdesc, 16, 15, __val)
312 #define SET_TX_BUFF_DESC_OWN(__pdesc, __val)                                   \
313 	SET_BITS_TO_LE_4BYTE(__pdesc, 31, 1, __val)
314 
315 /* Dword 1 */
316 #define SET_TX_BUFF_DESC_ADDR_LOW_0(__pdesc, __val)                            \
317 	SET_BITS_TO_LE_4BYTE((__pdesc) + 4, 0, 32, __val)
318 /* Dword 2 */
319 #define SET_TX_BUFF_DESC_ADDR_HIGH_0(bdesc, val, dma64)			       \
320 	SET_TXBUFFER_DESC_ADD_HIGH_WITH_OFFSET(bdesc, 0, val, dma64)
321 /* Dword 3 / RESERVED 0 */
322 
323 /* RX buffer  */
324 
325 /* DWORD 0 */
326 #define SET_RX_BUFFER_DESC_DATA_LENGTH(__status, __val)	\
327 	SET_BITS_TO_LE_4BYTE(__status, 0, 14, __val)
328 #define SET_RX_BUFFER_DESC_LS(__status, __val)		\
329 	SET_BITS_TO_LE_4BYTE(__status, 15, 1, __val)
330 #define SET_RX_BUFFER_DESC_FS(__status, __val)		\
331 	SET_BITS_TO_LE_4BYTE(__status, 16, 1, __val)
332 #define SET_RX_BUFFER_DESC_TOTAL_LENGTH(__status, __val)	\
333 	SET_BITS_TO_LE_4BYTE(__status, 16, 15, __val)
334 
335 #define GET_RX_BUFFER_DESC_OWN(__status)			\
336 	LE_BITS_TO_4BYTE(__status, 31, 1)
337 #define GET_RX_BUFFER_DESC_LS(__status)			\
338 	LE_BITS_TO_4BYTE(__status, 15, 1)
339 #define GET_RX_BUFFER_DESC_FS(__status)			\
340 	LE_BITS_TO_4BYTE(__status, 16, 1)
341 #define GET_RX_BUFFER_DESC_TOTAL_LENGTH(__status)	\
342 	LE_BITS_TO_4BYTE(__status, 16, 15)
343 
344 /* DWORD 1 */
345 #define SET_RX_BUFFER_PHYSICAL_LOW(__status, __val)	\
346 	SET_BITS_TO_LE_4BYTE(__status+4, 0, 32, __val)
347 
348 /* DWORD 2 */
349 #define SET_RX_BUFFER_PHYSICAL_HIGH(__rx_status_desc, __val, dma64)            \
350 	(dma64 ? SET_BITS_TO_LE_4BYTE((__rx_status_desc) + 8, 0, 32, __val) : 0)
351 
352 #define GET_RX_DESC_PKT_LEN(__pdesc)			\
353 	LE_BITS_TO_4BYTE(__pdesc, 0, 14)
354 #define GET_RX_DESC_CRC32(__pdesc)			\
355 	LE_BITS_TO_4BYTE(__pdesc, 14, 1)
356 #define GET_RX_DESC_ICV(__pdesc)			\
357 	LE_BITS_TO_4BYTE(__pdesc, 15, 1)
358 #define GET_RX_DESC_DRV_INFO_SIZE(__pdesc)		\
359 	LE_BITS_TO_4BYTE(__pdesc, 16, 4)
360 #define GET_RX_DESC_SECURITY(__pdesc)			\
361 	LE_BITS_TO_4BYTE(__pdesc, 20, 3)
362 #define GET_RX_DESC_QOS(__pdesc)			\
363 	LE_BITS_TO_4BYTE(__pdesc, 23, 1)
364 #define GET_RX_DESC_SHIFT(__pdesc)			\
365 	LE_BITS_TO_4BYTE(__pdesc, 24, 2)
366 #define GET_RX_DESC_PHYST(__pdesc)			\
367 	LE_BITS_TO_4BYTE(__pdesc, 26, 1)
368 #define GET_RX_DESC_SWDEC(__pdesc)			\
369 	LE_BITS_TO_4BYTE(__pdesc, 27, 1)
370 #define GET_RX_DESC_LS(__pdesc)				\
371 	LE_BITS_TO_4BYTE(__pdesc, 28, 1)
372 #define GET_RX_DESC_FS(__pdesc)				\
373 	LE_BITS_TO_4BYTE(__pdesc, 29, 1)
374 #define GET_RX_DESC_EOR(__pdesc)			\
375 	LE_BITS_TO_4BYTE(__pdesc, 30, 1)
376 #define GET_RX_DESC_OWN(__pdesc)			\
377 	LE_BITS_TO_4BYTE(__pdesc, 31, 1)
378 
379 #define SET_RX_DESC_PKT_LEN(__pdesc, __val)		\
380 	SET_BITS_TO_LE_4BYTE(__pdesc, 0, 14, __val)
381 #define SET_RX_DESC_EOR(__pdesc, __val)			\
382 	SET_BITS_TO_LE_4BYTE(__pdesc, 30, 1, __val)
383 #define SET_RX_DESC_OWN(__pdesc, __val)			\
384 	SET_BITS_TO_LE_4BYTE(__pdesc, 31, 1, __val)
385 
386 #define GET_RX_DESC_MACID(__pdesc)			\
387 	LE_BITS_TO_4BYTE(__pdesc+4, 0, 7)
388 #define GET_RX_DESC_TID(__pdesc)			\
389 	LE_BITS_TO_4BYTE(__pdesc+4, 8, 4)
390 #define GET_RX_DESC_MACID_VLD(__pdesc)			\
391 	LE_BITS_TO_4BYTE(__pdesc+4, 12, 1)
392 #define GET_RX_DESC_AMSDU(__pdesc)			\
393 	LE_BITS_TO_4BYTE(__pdesc+4, 13, 1)
394 #define GET_RX_DESC_RXID_MATCH(__pdesc)			\
395 	LE_BITS_TO_4BYTE(__pdesc+4, 14, 1)
396 #define GET_RX_DESC_PAGGR(__pdesc)			\
397 	LE_BITS_TO_4BYTE(__pdesc+4, 15, 1)
398 #define GET_RX_DESC_A1_FIT(__pdesc)			\
399 	LE_BITS_TO_4BYTE(__pdesc+4, 16, 4)
400 #define GET_RX_DESC_TCPOFFLOAD_CHKERR(__pdesc)		\
401 	LE_BITS_TO_4BYTE(__pdesc+4, 20, 1)
402 #define GET_RX_DESC_TCPOFFLOAD_IPVER(__pdesc)		\
403 	LE_BITS_TO_4BYTE(__pdesc+4, 21, 1)
404 #define GET_RX_DESC_TCPOFFLOAD_IS_TCPUDP(__pdesc)	\
405 	LE_BITS_TO_4BYTE(__pdesc+4, 22, 1)
406 #define GET_RX_DESC_TCPOFFLOAD_CHK_VLD(__pdesc)		\
407 	LE_BITS_TO_4BYTE(__pdesc+4, 23, 1)
408 #define GET_RX_DESC_PAM(__pdesc)			\
409 	LE_BITS_TO_4BYTE(__pdesc+4, 24, 1)
410 #define GET_RX_DESC_PWR(__pdesc)			\
411 	LE_BITS_TO_4BYTE(__pdesc+4, 25, 1)
412 #define GET_RX_DESC_MD(__pdesc)				\
413 	LE_BITS_TO_4BYTE(__pdesc+4, 26, 1)
414 #define GET_RX_DESC_MF(__pdesc)				\
415 	LE_BITS_TO_4BYTE(__pdesc+4, 27, 1)
416 #define GET_RX_DESC_TYPE(__pdesc)			\
417 	LE_BITS_TO_4BYTE(__pdesc+4, 28, 2)
418 #define GET_RX_DESC_MC(__pdesc)				\
419 	LE_BITS_TO_4BYTE(__pdesc+4, 30, 1)
420 #define GET_RX_DESC_BC(__pdesc)				\
421 	LE_BITS_TO_4BYTE(__pdesc+4, 31, 1)
422 #define GET_RX_DESC_SEQ(__pdesc)			\
423 	LE_BITS_TO_4BYTE(__pdesc+8, 0, 12)
424 #define GET_RX_DESC_FRAG(__pdesc)			\
425 	LE_BITS_TO_4BYTE(__pdesc+8, 12, 4)
426 #define GET_RX_DESC_RX_IS_QOS(__pdesc)			\
427 	LE_BITS_TO_4BYTE(__pdesc+8, 16, 1)
428 #define GET_RX_STATUS_DESC_RPT_SEL(__pdesc)		\
429 	LE_BITS_TO_4BYTE(__pdesc+8, 28, 1)
430 
431 #define GET_RX_DESC_RXMCS(__pdesc)			\
432 	LE_BITS_TO_4BYTE(__pdesc+12, 0, 7)
433 #define GET_RX_DESC_HTC(__pdesc)			\
434 	LE_BITS_TO_4BYTE(__pdesc+12, 10, 1)
435 #define GET_RX_STATUS_DESC_EOSP(__pdesc)		\
436 	LE_BITS_TO_4BYTE(__pdesc+12, 11, 1)
437 #define GET_RX_STATUS_DESC_BSSID_FIT(__pdesc)		\
438 	LE_BITS_TO_4BYTE(__pdesc+12, 12, 2)
439 #define GET_RX_STATUS_DESC_DMA_AGG_NUM(__pdesc)		\
440 	LE_BITS_TO_4BYTE(__pdesc+12, 16, 8)
441 #define GET_RX_STATUS_DESC_PATTERN_MATCH(__pdesc)	\
442 	LE_BITS_TO_4BYTE(__pdesc+12, 29, 1)
443 #define GET_RX_STATUS_DESC_UNICAST_MATCH(__pdesc)	\
444 	LE_BITS_TO_4BYTE(__pdesc+12, 30, 1)
445 #define GET_RX_STATUS_DESC_MAGIC_MATCH(__pdesc)		\
446 	LE_BITS_TO_4BYTE(__pdesc+12, 31, 1)
447 
448 #define GET_RX_DESC_TSFL(__pdesc)			\
449 	LE_BITS_TO_4BYTE(__pdesc+20, 0, 32)
450 
451 #define GET_RX_DESC_BUFF_ADDR(__pdesc)			\
452 	LE_BITS_TO_4BYTE(__pdesc+24, 0, 32)
453 #define GET_RX_DESC_BUFF_ADDR64(__pdesc)		\
454 	LE_BITS_TO_4BYTE(__pdesc+28, 0, 32)
455 
456 #define SET_RX_DESC_BUFF_ADDR(__pdesc, __val)		\
457 	SET_BITS_TO_LE_4BYTE(__pdesc+24, 0, 32, __val)
458 #define SET_RX_DESC_BUFF_ADDR64(__pdesc, __val)		\
459 	SET_BITS_TO_LE_4BYTE(__pdesc+28, 0, 32, __val)
460 
461 /* TX report 2 format in Rx desc*/
462 
463 #define GET_RX_RPT2_DESC_PKT_LEN(__status)	\
464 	LE_BITS_TO_4BYTE(__status, 0, 9)
465 #define GET_RX_RPT2_DESC_MACID_VALID_1(__status)	\
466 	LE_BITS_TO_4BYTE(__status+16, 0, 32)
467 #define GET_RX_RPT2_DESC_MACID_VALID_2(__status)	\
468 	LE_BITS_TO_4BYTE(__status+20, 0, 32)
469 
470 #define CLEAR_PCI_TX_DESC_CONTENT(__pdesc, _size)		\
471 do {								\
472 	if (_size > TX_DESC_NEXT_DESC_OFFSET)			\
473 		memset(__pdesc, 0, TX_DESC_NEXT_DESC_OFFSET);	\
474 	else							\
475 		memset(__pdesc, 0, _size);			\
476 } while (0)
477 
478 #define RTL92EE_RX_HAL_IS_CCK_RATE(rxmcs)\
479 	(rxmcs == DESC_RATE1M ||\
480 	 rxmcs == DESC_RATE2M ||\
481 	 rxmcs == DESC_RATE5_5M ||\
482 	 rxmcs == DESC_RATE11M)
483 
484 #define IS_LITTLE_ENDIAN	1
485 
486 struct phy_rx_agc_info_t {
487 	#if IS_LITTLE_ENDIAN
488 		u8 gain:7, trsw:1;
489 	#else
490 		u8 trsw:1, gain:7;
491 	#endif
492 };
493 
494 struct phy_status_rpt {
495 	struct phy_rx_agc_info_t path_agc[2];
496 	u8 ch_corr[2];
497 	u8 cck_sig_qual_ofdm_pwdb_all;
498 	u8 cck_agc_rpt_ofdm_cfosho_a;
499 	u8 cck_rpt_b_ofdm_cfosho_b;
500 	u8 rsvd_1;
501 	u8 noise_power_db_msb;
502 	u8 path_cfotail[2];
503 	u8 pcts_mask[2];
504 	u8 stream_rxevm[2];
505 	u8 path_rxsnr[2];
506 	u8 noise_power_db_lsb;
507 	u8 rsvd_2[3];
508 	u8 stream_csi[2];
509 	u8 stream_target_csi[2];
510 	u8 sig_evm;
511 	u8 rsvd_3;
512 #if IS_LITTLE_ENDIAN
513 	u8 antsel_rx_keep_2:1;	/*ex_intf_flg:1;*/
514 	u8 sgi_en:1;
515 	u8 rxsc:2;
516 	u8 idle_long:1;
517 	u8 r_ant_train_en:1;
518 	u8 ant_sel_b:1;
519 	u8 ant_sel:1;
520 #else	/* _BIG_ENDIAN_	*/
521 	u8 ant_sel:1;
522 	u8 ant_sel_b:1;
523 	u8 r_ant_train_en:1;
524 	u8 idle_long:1;
525 	u8 rxsc:2;
526 	u8 sgi_en:1;
527 	u8 antsel_rx_keep_2:1;	/*ex_intf_flg:1;*/
528 #endif
529 } __packed;
530 
531 struct rx_fwinfo {
532 	u8 gain_trsw[4];
533 	u8 pwdb_all;
534 	u8 cfosho[4];
535 	u8 cfotail[4];
536 	s8 rxevm[2];
537 	s8 rxsnr[4];
538 	u8 pdsnr[2];
539 	u8 csi_current[2];
540 	u8 csi_target[2];
541 	u8 sigevm;
542 	u8 max_ex_pwr;
543 	u8 ex_intf_flag:1;
544 	u8 sgi_en:1;
545 	u8 rxsc:2;
546 	u8 reserve:4;
547 } __packed;
548 
549 struct tx_desc {
550 	u32 pktsize:16;
551 	u32 offset:8;
552 	u32 bmc:1;
553 	u32 htc:1;
554 	u32 lastseg:1;
555 	u32 firstseg:1;
556 	u32 linip:1;
557 	u32 noacm:1;
558 	u32 gf:1;
559 	u32 own:1;
560 
561 	u32 macid:6;
562 	u32 rsvd0:2;
563 	u32 queuesel:5;
564 	u32 rd_nav_ext:1;
565 	u32 lsig_txop_en:1;
566 	u32 pifs:1;
567 	u32 rateid:4;
568 	u32 nav_usehdr:1;
569 	u32 en_descid:1;
570 	u32 sectype:2;
571 	u32 pktoffset:8;
572 
573 	u32 rts_rc:6;
574 	u32 data_rc:6;
575 	u32 agg_en:1;
576 	u32 rdg_en:1;
577 	u32 bar_retryht:2;
578 	u32 agg_break:1;
579 	u32 morefrag:1;
580 	u32 raw:1;
581 	u32 ccx:1;
582 	u32 ampdudensity:3;
583 	u32 bt_int:1;
584 	u32 ant_sela:1;
585 	u32 ant_selb:1;
586 	u32 txant_cck:2;
587 	u32 txant_l:2;
588 	u32 txant_ht:2;
589 
590 	u32 nextheadpage:8;
591 	u32 tailpage:8;
592 	u32 seq:12;
593 	u32 cpu_handle:1;
594 	u32 tag1:1;
595 	u32 trigger_int:1;
596 	u32 hwseq_en:1;
597 
598 	u32 rtsrate:5;
599 	u32 apdcfe:1;
600 	u32 qos:1;
601 	u32 hwseq_ssn:1;
602 	u32 userrate:1;
603 	u32 dis_rtsfb:1;
604 	u32 dis_datafb:1;
605 	u32 cts2self:1;
606 	u32 rts_en:1;
607 	u32 hwrts_en:1;
608 	u32 portid:1;
609 	u32 pwr_status:3;
610 	u32 waitdcts:1;
611 	u32 cts2ap_en:1;
612 	u32 txsc:2;
613 	u32 stbc:2;
614 	u32 txshort:1;
615 	u32 txbw:1;
616 	u32 rtsshort:1;
617 	u32 rtsbw:1;
618 	u32 rtssc:2;
619 	u32 rtsstbc:2;
620 
621 	u32 txrate:6;
622 	u32 shortgi:1;
623 	u32 ccxt:1;
624 	u32 txrate_fb_lmt:5;
625 	u32 rtsrate_fb_lmt:4;
626 	u32 retrylmt_en:1;
627 	u32 txretrylmt:6;
628 	u32 usb_txaggnum:8;
629 
630 	u32 txagca:5;
631 	u32 txagcb:5;
632 	u32 usemaxlen:1;
633 	u32 maxaggnum:5;
634 	u32 mcsg1maxlen:4;
635 	u32 mcsg2maxlen:4;
636 	u32 mcsg3maxlen:4;
637 	u32 mcs7sgimaxlen:4;
638 
639 	u32 txbuffersize:16;
640 	u32 sw_offset30:8;
641 	u32 sw_offset31:4;
642 	u32 rsvd1:1;
643 	u32 antsel_c:1;
644 	u32 null_0:1;
645 	u32 null_1:1;
646 
647 	u32 txbuffaddr;
648 	u32 txbufferaddr64;
649 	u32 nextdescaddress;
650 	u32 nextdescaddress64;
651 
652 	u32 reserve_pass_pcie_mm_limit[4];
653 } __packed;
654 
655 struct rx_desc {
656 	u32 length:14;
657 	u32 crc32:1;
658 	u32 icverror:1;
659 	u32 drv_infosize:4;
660 	u32 security:3;
661 	u32 qos:1;
662 	u32 shift:2;
663 	u32 phystatus:1;
664 	u32 swdec:1;
665 	u32 lastseg:1;
666 	u32 firstseg:1;
667 	u32 eor:1;
668 	u32 own:1;
669 
670 	u32 macid:6;
671 	u32 tid:4;
672 	u32 hwrsvd:5;
673 	u32 paggr:1;
674 	u32 faggr:1;
675 	u32 a1_fit:4;
676 	u32 a2_fit:4;
677 	u32 pam:1;
678 	u32 pwr:1;
679 	u32 moredata:1;
680 	u32 morefrag:1;
681 	u32 type:2;
682 	u32 mc:1;
683 	u32 bc:1;
684 
685 	u32 seq:12;
686 	u32 frag:4;
687 	u32 nextpktlen:14;
688 	u32 nextind:1;
689 	u32 rsvd:1;
690 
691 	u32 rxmcs:6;
692 	u32 rxht:1;
693 	u32 amsdu:1;
694 	u32 splcp:1;
695 	u32 bandwidth:1;
696 	u32 htc:1;
697 	u32 tcpchk_rpt:1;
698 	u32 ipcchk_rpt:1;
699 	u32 tcpchk_valid:1;
700 	u32 hwpcerr:1;
701 	u32 hwpcind:1;
702 	u32 iv0:16;
703 
704 	u32 iv1;
705 
706 	u32 tsfl;
707 
708 	u32 bufferaddress;
709 	u32 bufferaddress64;
710 
711 } __packed;
712 
713 void rtl92ee_rx_check_dma_ok(struct ieee80211_hw *hw, u8 *header_desc,
714 			     u8 queue_index);
715 u16	rtl92ee_rx_desc_buff_remained_cnt(struct ieee80211_hw *hw,
716 					  u8 queue_index);
717 u16 rtl92ee_get_available_desc(struct ieee80211_hw *hw, u8 queue_index);
718 void rtl92ee_pre_fill_tx_bd_desc(struct ieee80211_hw *hw,
719 				 u8 *tx_bd_desc, u8 *desc, u8 queue_index,
720 				 struct sk_buff *skb, dma_addr_t addr);
721 
722 void rtl92ee_tx_fill_desc(struct ieee80211_hw *hw,
723 			  struct ieee80211_hdr *hdr, u8 *pdesc_tx,
724 			  u8 *pbd_desc_tx,
725 			  struct ieee80211_tx_info *info,
726 			  struct ieee80211_sta *sta,
727 			  struct sk_buff *skb,
728 			  u8 hw_queue, struct rtl_tcb_desc *ptcb_desc);
729 bool rtl92ee_rx_query_desc(struct ieee80211_hw *hw,
730 			   struct rtl_stats *status,
731 			   struct ieee80211_rx_status *rx_status,
732 			   u8 *pdesc, struct sk_buff *skb);
733 void rtl92ee_set_desc(struct ieee80211_hw *hw, u8 *pdesc, bool istx,
734 		      u8 desc_name, u8 *val);
735 
736 u64 rtl92ee_get_desc(struct ieee80211_hw *hw,
737 		     u8 *pdesc, bool istx, u8 desc_name);
738 bool rtl92ee_is_tx_desc_closed(struct ieee80211_hw *hw, u8 hw_queue, u16 index);
739 void rtl92ee_tx_polling(struct ieee80211_hw *hw, u8 hw_queue);
740 void rtl92ee_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 *pdesc,
741 			     bool firstseg, bool lastseg,
742 			     struct sk_buff *skb);
743 #endif
744