1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright(c) 2009-2012  Realtek Corporation.*/
3 
4 #ifndef __RTL92DE_TRX_H__
5 #define __RTL92DE_TRX_H__
6 
7 #define TX_DESC_SIZE				64
8 #define TX_DESC_AGGR_SUBFRAME_SIZE		32
9 
10 #define RX_DESC_SIZE				32
11 #define RX_DRV_INFO_SIZE_UNIT			8
12 
13 #define	TX_DESC_NEXT_DESC_OFFSET		40
14 #define USB_HWDESC_HEADER_LEN			32
15 #define CRCLENGTH				4
16 
17 /* Define a macro that takes a le32 word, converts it to host ordering,
18  * right shifts by a specified count, creates a mask of the specified
19  * bit count, and extracts that number of bits.
20  */
21 
22 #define SHIFT_AND_MASK_LE(__pdesc, __shift, __mask)		\
23 	((le32_to_cpu(*(((__le32 *)(__pdesc)))) >> (__shift)) &	\
24 	BIT_LEN_MASK_32(__mask))
25 
26 /* Define a macro that clears a bit field in an le32 word and
27  * sets the specified value into that bit field. The resulting
28  * value remains in le32 ordering; however, it is properly converted
29  * to host ordering for the clear and set operations before conversion
30  * back to le32.
31  */
32 
33 #define SET_BITS_OFFSET_LE(__pdesc, __shift, __len, __val)	\
34 	(*(__le32 *)(__pdesc) =					\
35 	(cpu_to_le32((le32_to_cpu(*((__le32 *)(__pdesc))) &	\
36 	(~(BIT_OFFSET_LEN_MASK_32((__shift), __len)))) |		\
37 	(((u32)(__val) & BIT_LEN_MASK_32(__len)) << (__shift)))));
38 
39 /* macros to read/write various fields in RX or TX descriptors */
40 
41 #define SET_TX_DESC_PKT_SIZE(__pdesc, __val)		\
42 	SET_BITS_OFFSET_LE(__pdesc, 0, 16, __val)
43 #define SET_TX_DESC_OFFSET(__pdesc, __val)		\
44 	SET_BITS_OFFSET_LE(__pdesc, 16, 8, __val)
45 #define SET_TX_DESC_BMC(__pdesc, __val)			\
46 	SET_BITS_OFFSET_LE(__pdesc, 24, 1, __val)
47 #define SET_TX_DESC_HTC(__pdesc, __val)			\
48 	SET_BITS_OFFSET_LE(__pdesc, 25, 1, __val)
49 #define SET_TX_DESC_LAST_SEG(__pdesc, __val)		\
50 	SET_BITS_OFFSET_LE(__pdesc, 26, 1, __val)
51 #define SET_TX_DESC_FIRST_SEG(__pdesc, __val)		\
52 	SET_BITS_OFFSET_LE(__pdesc, 27, 1, __val)
53 #define SET_TX_DESC_LINIP(__pdesc, __val)		\
54 	SET_BITS_OFFSET_LE(__pdesc, 28, 1, __val)
55 #define SET_TX_DESC_NO_ACM(__pdesc, __val)		\
56 	SET_BITS_OFFSET_LE(__pdesc, 29, 1, __val)
57 #define SET_TX_DESC_GF(__pdesc, __val)			\
58 	SET_BITS_OFFSET_LE(__pdesc, 30, 1, __val)
59 #define SET_TX_DESC_OWN(__pdesc, __val)			\
60 	SET_BITS_OFFSET_LE(__pdesc, 31, 1, __val)
61 
62 #define GET_TX_DESC_PKT_SIZE(__pdesc)			\
63 	SHIFT_AND_MASK_LE(__pdesc, 0, 16)
64 #define GET_TX_DESC_OFFSET(__pdesc)			\
65 	SHIFT_AND_MASK_LE(__pdesc, 16, 8)
66 #define GET_TX_DESC_BMC(__pdesc)			\
67 	SHIFT_AND_MASK_LE(__pdesc, 24, 1)
68 #define GET_TX_DESC_HTC(__pdesc)			\
69 	SHIFT_AND_MASK_LE(__pdesc, 25, 1)
70 #define GET_TX_DESC_LAST_SEG(__pdesc)			\
71 	SHIFT_AND_MASK_LE(__pdesc, 26, 1)
72 #define GET_TX_DESC_FIRST_SEG(__pdesc)			\
73 	SHIFT_AND_MASK_LE(__pdesc, 27, 1)
74 #define GET_TX_DESC_LINIP(__pdesc)			\
75 	SHIFT_AND_MASK_LE(__pdesc, 28, 1)
76 #define GET_TX_DESC_NO_ACM(__pdesc)			\
77 	SHIFT_AND_MASK_LE(__pdesc, 29, 1)
78 #define GET_TX_DESC_GF(__pdesc)				\
79 	SHIFT_AND_MASK_LE(__pdesc, 30, 1)
80 #define GET_TX_DESC_OWN(__pdesc)			\
81 	SHIFT_AND_MASK_LE(__pdesc, 31, 1)
82 
83 #define SET_TX_DESC_MACID(__pdesc, __val)		\
84 	SET_BITS_OFFSET_LE(__pdesc+4, 0, 5, __val)
85 #define SET_TX_DESC_AGG_ENABLE(__pdesc, __val)		\
86 	SET_BITS_OFFSET_LE(__pdesc+4, 5, 1, __val)
87 #define SET_TX_DESC_BK(__pdesc, __val)			\
88 	SET_BITS_OFFSET_LE(__pdesc+4, 6, 1, __val)
89 #define SET_TX_DESC_RDG_ENABLE(__pdesc, __val)		\
90 	SET_BITS_OFFSET_LE(__pdesc+4, 7, 1, __val)
91 #define SET_TX_DESC_QUEUE_SEL(__pdesc, __val)		\
92 	SET_BITS_OFFSET_LE(__pdesc+4, 8, 5, __val)
93 #define SET_TX_DESC_RDG_NAV_EXT(__pdesc, __val)		\
94 	SET_BITS_OFFSET_LE(__pdesc+4, 13, 1, __val)
95 #define SET_TX_DESC_LSIG_TXOP_EN(__pdesc, __val)	\
96 	SET_BITS_OFFSET_LE(__pdesc+4, 14, 1, __val)
97 #define SET_TX_DESC_PIFS(__pdesc, __val)		\
98 	SET_BITS_OFFSET_LE(__pdesc+4, 15, 1, __val)
99 #define SET_TX_DESC_RATE_ID(__pdesc, __val)		\
100 	SET_BITS_OFFSET_LE(__pdesc+4, 16, 4, __val)
101 #define SET_TX_DESC_NAV_USE_HDR(__pdesc, __val)		\
102 	SET_BITS_OFFSET_LE(__pdesc+4, 20, 1, __val)
103 #define SET_TX_DESC_EN_DESC_ID(__pdesc, __val)		\
104 	SET_BITS_OFFSET_LE(__pdesc+4, 21, 1, __val)
105 #define SET_TX_DESC_SEC_TYPE(__pdesc, __val)		\
106 	SET_BITS_OFFSET_LE(__pdesc+4, 22, 2, __val)
107 #define SET_TX_DESC_PKT_OFFSET(__pdesc, __val)		\
108 	SET_BITS_OFFSET_LE(__pdesc+4, 26, 8, __val)
109 
110 #define GET_TX_DESC_MACID(__pdesc)					\
111 	SHIFT_AND_MASK_LE(__pdesc+4, 0, 5)
112 #define GET_TX_DESC_AGG_ENABLE(__pdesc)			\
113 	SHIFT_AND_MASK_LE(__pdesc+4, 5, 1)
114 #define GET_TX_DESC_AGG_BREAK(__pdesc)			\
115 	SHIFT_AND_MASK_LE(__pdesc+4, 6, 1)
116 #define GET_TX_DESC_RDG_ENABLE(__pdesc)			\
117 	SHIFT_AND_MASK_LE(__pdesc+4, 7, 1)
118 #define GET_TX_DESC_QUEUE_SEL(__pdesc)			\
119 	SHIFT_AND_MASK_LE(__pdesc+4, 8, 5)
120 #define GET_TX_DESC_RDG_NAV_EXT(__pdesc)		\
121 	SHIFT_AND_MASK_LE(__pdesc+4, 13, 1)
122 #define GET_TX_DESC_LSIG_TXOP_EN(__pdesc)		\
123 	SHIFT_AND_MASK_LE(__pdesc+4, 14, 1)
124 #define GET_TX_DESC_PIFS(__pdesc)			\
125 	SHIFT_AND_MASK_LE(__pdesc+4, 15, 1)
126 #define GET_TX_DESC_RATE_ID(__pdesc)			\
127 	SHIFT_AND_MASK_LE(__pdesc+4, 16, 4)
128 #define GET_TX_DESC_NAV_USE_HDR(__pdesc)		\
129 	SHIFT_AND_MASK_LE(__pdesc+4, 20, 1)
130 #define GET_TX_DESC_EN_DESC_ID(__pdesc)			\
131 	SHIFT_AND_MASK_LE(__pdesc+4, 21, 1)
132 #define GET_TX_DESC_SEC_TYPE(__pdesc)			\
133 	SHIFT_AND_MASK_LE(__pdesc+4, 22, 2)
134 #define GET_TX_DESC_PKT_OFFSET(__pdesc)			\
135 	SHIFT_AND_MASK_LE(__pdesc+4, 24, 8)
136 
137 #define SET_TX_DESC_RTS_RC(__pdesc, __val)		\
138 	SET_BITS_OFFSET_LE(__pdesc+8, 0, 6, __val)
139 #define SET_TX_DESC_DATA_RC(__pdesc, __val)		\
140 	SET_BITS_OFFSET_LE(__pdesc+8, 6, 6, __val)
141 #define SET_TX_DESC_BAR_RTY_TH(__pdesc, __val)		\
142 	SET_BITS_OFFSET_LE(__pdesc+8, 14, 2, __val)
143 #define SET_TX_DESC_MORE_FRAG(__pdesc, __val)		\
144 	SET_BITS_OFFSET_LE(__pdesc+8, 17, 1, __val)
145 #define SET_TX_DESC_RAW(__pdesc, __val)			\
146 	SET_BITS_OFFSET_LE(__pdesc+8, 18, 1, __val)
147 #define SET_TX_DESC_CCX(__pdesc, __val)			\
148 	SET_BITS_OFFSET_LE(__pdesc+8, 19, 1, __val)
149 #define SET_TX_DESC_AMPDU_DENSITY(__pdesc, __val)	\
150 	SET_BITS_OFFSET_LE(__pdesc+8, 20, 3, __val)
151 #define SET_TX_DESC_ANTSEL_A(__pdesc, __val)		\
152 	SET_BITS_OFFSET_LE(__pdesc+8, 24, 1, __val)
153 #define SET_TX_DESC_ANTSEL_B(__pdesc, __val)		\
154 	SET_BITS_OFFSET_LE(__pdesc+8, 25, 1, __val)
155 #define SET_TX_DESC_TX_ANT_CCK(__pdesc, __val)		\
156 	SET_BITS_OFFSET_LE(__pdesc+8, 26, 2, __val)
157 #define SET_TX_DESC_TX_ANTL(__pdesc, __val)		\
158 	SET_BITS_OFFSET_LE(__pdesc+8, 28, 2, __val)
159 #define SET_TX_DESC_TX_ANT_HT(__pdesc, __val)		\
160 	SET_BITS_OFFSET_LE(__pdesc+8, 30, 2, __val)
161 
162 #define GET_TX_DESC_RTS_RC(__pdesc)			\
163 	SHIFT_AND_MASK_LE(__pdesc+8, 0, 6)
164 #define GET_TX_DESC_DATA_RC(__pdesc)			\
165 	SHIFT_AND_MASK_LE(__pdesc+8, 6, 6)
166 #define GET_TX_DESC_BAR_RTY_TH(__pdesc)			\
167 	SHIFT_AND_MASK_LE(__pdesc+8, 14, 2)
168 #define GET_TX_DESC_MORE_FRAG(__pdesc)			\
169 	SHIFT_AND_MASK_LE(__pdesc+8, 17, 1)
170 #define GET_TX_DESC_RAW(__pdesc)			\
171 	SHIFT_AND_MASK_LE(__pdesc+8, 18, 1)
172 #define GET_TX_DESC_CCX(__pdesc)			\
173 	SHIFT_AND_MASK_LE(__pdesc+8, 19, 1)
174 #define GET_TX_DESC_AMPDU_DENSITY(__pdesc)		\
175 	SHIFT_AND_MASK_LE(__pdesc+8, 20, 3)
176 #define GET_TX_DESC_ANTSEL_A(__pdesc)			\
177 	SHIFT_AND_MASK_LE(__pdesc+8, 24, 1)
178 #define GET_TX_DESC_ANTSEL_B(__pdesc)			\
179 	SHIFT_AND_MASK_LE(__pdesc+8, 25, 1)
180 #define GET_TX_DESC_TX_ANT_CCK(__pdesc)			\
181 	SHIFT_AND_MASK_LE(__pdesc+8, 26, 2)
182 #define GET_TX_DESC_TX_ANTL(__pdesc)			\
183 	SHIFT_AND_MASK_LE(__pdesc+8, 28, 2)
184 #define GET_TX_DESC_TX_ANT_HT(__pdesc)			\
185 	SHIFT_AND_MASK_LE(__pdesc+8, 30, 2)
186 
187 #define SET_TX_DESC_NEXT_HEAP_PAGE(__pdesc, __val)	\
188 	SET_BITS_OFFSET_LE(__pdesc+12, 0, 8, __val)
189 #define SET_TX_DESC_TAIL_PAGE(__pdesc, __val)		\
190 	SET_BITS_OFFSET_LE(__pdesc+12, 8, 8, __val)
191 #define SET_TX_DESC_SEQ(__pdesc, __val)			\
192 	SET_BITS_OFFSET_LE(__pdesc+12, 16, 12, __val)
193 #define SET_TX_DESC_PKT_ID(__pdesc, __val)		\
194 	SET_BITS_OFFSET_LE(__pdesc+12, 28, 4, __val)
195 
196 #define GET_TX_DESC_NEXT_HEAP_PAGE(__pdesc)		\
197 	SHIFT_AND_MASK_LE(__pdesc+12, 0, 8)
198 #define GET_TX_DESC_TAIL_PAGE(__pdesc)			\
199 	SHIFT_AND_MASK_LE(__pdesc+12, 8, 8)
200 #define GET_TX_DESC_SEQ(__pdesc)			\
201 	SHIFT_AND_MASK_LE(__pdesc+12, 16, 12)
202 #define GET_TX_DESC_PKT_ID(__pdesc)			\
203 	SHIFT_AND_MASK_LE(__pdesc+12, 28, 4)
204 
205 #define SET_TX_DESC_RTS_RATE(__pdesc, __val)		\
206 	SET_BITS_OFFSET_LE(__pdesc+16, 0, 5, __val)
207 #define SET_TX_DESC_AP_DCFE(__pdesc, __val)		\
208 	SET_BITS_OFFSET_LE(__pdesc+16, 5, 1, __val)
209 #define SET_TX_DESC_QOS(__pdesc, __val)			\
210 	SET_BITS_OFFSET_LE(__pdesc+16, 6, 1, __val)
211 #define SET_TX_DESC_HWSEQ_EN(__pdesc, __val)		\
212 	SET_BITS_OFFSET_LE(__pdesc+16, 7, 1, __val)
213 #define SET_TX_DESC_USE_RATE(__pdesc, __val)		\
214 	SET_BITS_OFFSET_LE(__pdesc+16, 8, 1, __val)
215 #define SET_TX_DESC_DISABLE_RTS_FB(__pdesc, __val)	\
216 	SET_BITS_OFFSET_LE(__pdesc+16, 9, 1, __val)
217 #define SET_TX_DESC_DISABLE_FB(__pdesc, __val)		\
218 	SET_BITS_OFFSET_LE(__pdesc+16, 10, 1, __val)
219 #define SET_TX_DESC_CTS2SELF(__pdesc, __val)		\
220 	SET_BITS_OFFSET_LE(__pdesc+16, 11, 1, __val)
221 #define SET_TX_DESC_RTS_ENABLE(__pdesc, __val)		\
222 	SET_BITS_OFFSET_LE(__pdesc+16, 12, 1, __val)
223 #define SET_TX_DESC_HW_RTS_ENABLE(__pdesc, __val)	\
224 	SET_BITS_OFFSET_LE(__pdesc+16, 13, 1, __val)
225 #define SET_TX_DESC_PORT_ID(__pdesc, __val)		\
226 	SET_BITS_OFFSET_LE(__pdesc+16, 14, 1, __val)
227 #define SET_TX_DESC_WAIT_DCTS(__pdesc, __val)		\
228 	SET_BITS_OFFSET_LE(__pdesc+16, 18, 1, __val)
229 #define SET_TX_DESC_CTS2AP_EN(__pdesc, __val)		\
230 	SET_BITS_OFFSET_LE(__pdesc+16, 19, 1, __val)
231 #define SET_TX_DESC_TX_SUB_CARRIER(__pdesc, __val)	\
232 	SET_BITS_OFFSET_LE(__pdesc+16, 20, 2, __val)
233 #define SET_TX_DESC_TX_STBC(__pdesc, __val)		\
234 	SET_BITS_OFFSET_LE(__pdesc+16, 22, 2, __val)
235 #define SET_TX_DESC_DATA_SHORT(__pdesc, __val)		\
236 	SET_BITS_OFFSET_LE(__pdesc+16, 24, 1, __val)
237 #define SET_TX_DESC_DATA_BW(__pdesc, __val)		\
238 	SET_BITS_OFFSET_LE(__pdesc+16, 25, 1, __val)
239 #define SET_TX_DESC_RTS_SHORT(__pdesc, __val)		\
240 	SET_BITS_OFFSET_LE(__pdesc+16, 26, 1, __val)
241 #define SET_TX_DESC_RTS_BW(__pdesc, __val)		\
242 	SET_BITS_OFFSET_LE(__pdesc+16, 27, 1, __val)
243 #define SET_TX_DESC_RTS_SC(__pdesc, __val)		\
244 	SET_BITS_OFFSET_LE(__pdesc+16, 28, 2, __val)
245 #define SET_TX_DESC_RTS_STBC(__pdesc, __val)		\
246 	SET_BITS_OFFSET_LE(__pdesc+16, 30, 2, __val)
247 
248 #define GET_TX_DESC_RTS_RATE(__pdesc)			\
249 	SHIFT_AND_MASK_LE(__pdesc+16, 0, 5)
250 #define GET_TX_DESC_AP_DCFE(__pdesc)			\
251 	SHIFT_AND_MASK_LE(__pdesc+16, 5, 1)
252 #define GET_TX_DESC_QOS(__pdesc)			\
253 	SHIFT_AND_MASK_LE(__pdesc+16, 6, 1)
254 #define GET_TX_DESC_HWSEQ_EN(__pdesc)			\
255 	SHIFT_AND_MASK_LE(__pdesc+16, 7, 1)
256 #define GET_TX_DESC_USE_RATE(__pdesc)			\
257 	SHIFT_AND_MASK_LE(__pdesc+16, 8, 1)
258 #define GET_TX_DESC_DISABLE_RTS_FB(__pdesc)		\
259 	SHIFT_AND_MASK_LE(__pdesc+16, 9, 1)
260 #define GET_TX_DESC_DISABLE_FB(__pdesc)			\
261 	SHIFT_AND_MASK_LE(__pdesc+16, 10, 1)
262 #define GET_TX_DESC_CTS2SELF(__pdesc)			\
263 	SHIFT_AND_MASK_LE(__pdesc+16, 11, 1)
264 #define GET_TX_DESC_RTS_ENABLE(__pdesc)			\
265 	SHIFT_AND_MASK_LE(__pdesc+16, 12, 1)
266 #define GET_TX_DESC_HW_RTS_ENABLE(__pdesc)		\
267 	SHIFT_AND_MASK_LE(__pdesc+16, 13, 1)
268 #define GET_TX_DESC_PORT_ID(__pdesc)			\
269 	SHIFT_AND_MASK_LE(__pdesc+16, 14, 1)
270 #define GET_TX_DESC_WAIT_DCTS(__pdesc)			\
271 	SHIFT_AND_MASK_LE(__pdesc+16, 18, 1)
272 #define GET_TX_DESC_CTS2AP_EN(__pdesc)			\
273 	SHIFT_AND_MASK_LE(__pdesc+16, 19, 1)
274 #define GET_TX_DESC_TX_SUB_CARRIER(__pdesc)		\
275 	SHIFT_AND_MASK_LE(__pdesc+16, 20, 2)
276 #define GET_TX_DESC_TX_STBC(__pdesc)			\
277 	SHIFT_AND_MASK_LE(__pdesc+16, 22, 2)
278 #define GET_TX_DESC_DATA_SHORT(__pdesc)			\
279 	SHIFT_AND_MASK_LE(__pdesc+16, 24, 1)
280 #define GET_TX_DESC_DATA_BW(__pdesc)			\
281 	SHIFT_AND_MASK_LE(__pdesc+16, 25, 1)
282 #define GET_TX_DESC_RTS_SHORT(__pdesc)			\
283 	SHIFT_AND_MASK_LE(__pdesc+16, 26, 1)
284 #define GET_TX_DESC_RTS_BW(__pdesc)			\
285 	SHIFT_AND_MASK_LE(__pdesc+16, 27, 1)
286 #define GET_TX_DESC_RTS_SC(__pdesc)			\
287 	SHIFT_AND_MASK_LE(__pdesc+16, 28, 2)
288 #define GET_TX_DESC_RTS_STBC(__pdesc)			\
289 	SHIFT_AND_MASK_LE(__pdesc+16, 30, 2)
290 
291 #define SET_TX_DESC_TX_RATE(__pdesc, __val)		\
292 	SET_BITS_OFFSET_LE(__pdesc+20, 0, 6, __val)
293 #define SET_TX_DESC_DATA_SHORTGI(__pdesc, __val)	\
294 	SET_BITS_OFFSET_LE(__pdesc+20, 6, 1, __val)
295 #define SET_TX_DESC_CCX_TAG(__pdesc, __val)		\
296 	SET_BITS_OFFSET_LE(__pdesc+20, 7, 1, __val)
297 #define SET_TX_DESC_DATA_RATE_FB_LIMIT(__pdesc, __val)	\
298 	SET_BITS_OFFSET_LE(__pdesc+20, 8, 5, __val)
299 #define SET_TX_DESC_RTS_RATE_FB_LIMIT(__pdesc, __val)	\
300 	SET_BITS_OFFSET_LE(__pdesc+20, 13, 4, __val)
301 #define SET_TX_DESC_RETRY_LIMIT_ENABLE(__pdesc, __val)	\
302 	SET_BITS_OFFSET_LE(__pdesc+20, 17, 1, __val)
303 #define SET_TX_DESC_DATA_RETRY_LIMIT(__pdesc, __val)	\
304 	SET_BITS_OFFSET_LE(__pdesc+20, 18, 6, __val)
305 #define SET_TX_DESC_USB_TXAGG_NUM(__pdesc, __val)	\
306 	SET_BITS_OFFSET_LE(__pdesc+20, 24, 8, __val)
307 
308 #define GET_TX_DESC_TX_RATE(__pdesc)			\
309 	SHIFT_AND_MASK_LE(__pdesc+20, 0, 6)
310 #define GET_TX_DESC_DATA_SHORTGI(__pdesc)		\
311 	SHIFT_AND_MASK_LE(__pdesc+20, 6, 1)
312 #define GET_TX_DESC_CCX_TAG(__pdesc)			\
313 	SHIFT_AND_MASK_LE(__pdesc+20, 7, 1)
314 #define GET_TX_DESC_DATA_RATE_FB_LIMIT(__pdesc)		\
315 	SHIFT_AND_MASK_LE(__pdesc+20, 8, 5)
316 #define GET_TX_DESC_RTS_RATE_FB_LIMIT(__pdesc)		\
317 	SHIFT_AND_MASK_LE(__pdesc+20, 13, 4)
318 #define GET_TX_DESC_RETRY_LIMIT_ENABLE(__pdesc)		\
319 	SHIFT_AND_MASK_LE(__pdesc+20, 17, 1)
320 #define GET_TX_DESC_DATA_RETRY_LIMIT(__pdesc)		\
321 	SHIFT_AND_MASK_LE(__pdesc+20, 18, 6)
322 #define GET_TX_DESC_USB_TXAGG_NUM(__pdesc)		\
323 	SHIFT_AND_MASK_LE(__pdesc+20, 24, 8)
324 
325 #define SET_TX_DESC_TXAGC_A(__pdesc, __val)		\
326 	SET_BITS_OFFSET_LE(__pdesc+24, 0, 5, __val)
327 #define SET_TX_DESC_TXAGC_B(__pdesc, __val)		\
328 	SET_BITS_OFFSET_LE(__pdesc+24, 5, 5, __val)
329 #define SET_TX_DESC_USE_MAX_LEN(__pdesc, __val)		\
330 	SET_BITS_OFFSET_LE(__pdesc+24, 10, 1, __val)
331 #define SET_TX_DESC_MAX_AGG_NUM(__pdesc, __val)		\
332 	SET_BITS_OFFSET_LE(__pdesc+24, 11, 5, __val)
333 #define SET_TX_DESC_MCSG1_MAX_LEN(__pdesc, __val)	\
334 	SET_BITS_OFFSET_LE(__pdesc+24, 16, 4, __val)
335 #define SET_TX_DESC_MCSG2_MAX_LEN(__pdesc, __val)	\
336 	SET_BITS_OFFSET_LE(__pdesc+24, 20, 4, __val)
337 #define SET_TX_DESC_MCSG3_MAX_LEN(__pdesc, __val)	\
338 	SET_BITS_OFFSET_LE(__pdesc+24, 24, 4, __val)
339 #define SET_TX_DESC_MCS7_SGI_MAX_LEN(__pdesc, __val)	\
340 	SET_BITS_OFFSET_LE(__pdesc+24, 28, 4, __val)
341 
342 #define GET_TX_DESC_TXAGC_A(__pdesc)			\
343 	SHIFT_AND_MASK_LE(__pdesc+24, 0, 5)
344 #define GET_TX_DESC_TXAGC_B(__pdesc)			\
345 	SHIFT_AND_MASK_LE(__pdesc+24, 5, 5)
346 #define GET_TX_DESC_USE_MAX_LEN(__pdesc)		\
347 	SHIFT_AND_MASK_LE(__pdesc+24, 10, 1)
348 #define GET_TX_DESC_MAX_AGG_NUM(__pdesc)		\
349 	SHIFT_AND_MASK_LE(__pdesc+24, 11, 5)
350 #define GET_TX_DESC_MCSG1_MAX_LEN(__pdesc)		\
351 	SHIFT_AND_MASK_LE(__pdesc+24, 16, 4)
352 #define GET_TX_DESC_MCSG2_MAX_LEN(__pdesc)		\
353 	SHIFT_AND_MASK_LE(__pdesc+24, 20, 4)
354 #define GET_TX_DESC_MCSG3_MAX_LEN(__pdesc)		\
355 	SHIFT_AND_MASK_LE(__pdesc+24, 24, 4)
356 #define GET_TX_DESC_MCS7_SGI_MAX_LEN(__pdesc)		\
357 	SHIFT_AND_MASK_LE(__pdesc+24, 28, 4)
358 
359 #define SET_TX_DESC_TX_BUFFER_SIZE(__pdesc, __val)	\
360 	SET_BITS_OFFSET_LE(__pdesc+28, 0, 16, __val)
361 #define SET_TX_DESC_MCSG4_MAX_LEN(__pdesc, __val)	\
362 	SET_BITS_OFFSET_LE(__pdesc+28, 16, 4, __val)
363 #define SET_TX_DESC_MCSG5_MAX_LEN(__pdesc, __val)	\
364 	SET_BITS_OFFSET_LE(__pdesc+28, 20, 4, __val)
365 #define SET_TX_DESC_MCSG6_MAX_LEN(__pdesc, __val)	\
366 	SET_BITS_OFFSET_LE(__pdesc+28, 24, 4, __val)
367 #define SET_TX_DESC_MCS15_SGI_MAX_LEN(__pdesc, __val)	\
368 	SET_BITS_OFFSET_LE(__pdesc+28, 28, 4, __val)
369 
370 #define GET_TX_DESC_TX_BUFFER_SIZE(__pdesc)		\
371 	SHIFT_AND_MASK_LE(__pdesc+28, 0, 16)
372 #define GET_TX_DESC_MCSG4_MAX_LEN(__pdesc)		\
373 	SHIFT_AND_MASK_LE(__pdesc+28, 16, 4)
374 #define GET_TX_DESC_MCSG5_MAX_LEN(__pdesc)		\
375 	SHIFT_AND_MASK_LE(__pdesc+28, 20, 4)
376 #define GET_TX_DESC_MCSG6_MAX_LEN(__pdesc)		\
377 	SHIFT_AND_MASK_LE(__pdesc+28, 24, 4)
378 #define GET_TX_DESC_MCS15_SGI_MAX_LEN(__pdesc)		\
379 	SHIFT_AND_MASK_LE(__pdesc+28, 28, 4)
380 
381 #define SET_TX_DESC_TX_BUFFER_ADDRESS(__pdesc, __val)	\
382 	SET_BITS_OFFSET_LE(__pdesc+32, 0, 32, __val)
383 #define SET_TX_DESC_TX_BUFFER_ADDRESS64(__pdesc, __val) \
384 	SET_BITS_OFFSET_LE(__pdesc+36, 0, 32, __val)
385 
386 #define GET_TX_DESC_TX_BUFFER_ADDRESS(__pdesc)		\
387 	SHIFT_AND_MASK_LE(__pdesc+32, 0, 32)
388 #define GET_TX_DESC_TX_BUFFER_ADDRESS64(__pdesc)	\
389 	SHIFT_AND_MASK_LE(__pdesc+36, 0, 32)
390 
391 #define SET_TX_DESC_NEXT_DESC_ADDRESS(__pdesc, __val)	\
392 	SET_BITS_OFFSET_LE(__pdesc+40, 0, 32, __val)
393 #define SET_TX_DESC_NEXT_DESC_ADDRESS64(__pdesc, __val) \
394 	SET_BITS_OFFSET_LE(__pdesc+44, 0, 32, __val)
395 
396 #define GET_TX_DESC_NEXT_DESC_ADDRESS(__pdesc)		\
397 	SHIFT_AND_MASK_LE(__pdesc+40, 0, 32)
398 #define GET_TX_DESC_NEXT_DESC_ADDRESS64(__pdesc)	\
399 	SHIFT_AND_MASK_LE(__pdesc+44, 0, 32)
400 
401 #define GET_RX_DESC_PKT_LEN(__pdesc)			\
402 	SHIFT_AND_MASK_LE(__pdesc, 0, 14)
403 #define GET_RX_DESC_CRC32(__pdesc)			\
404 	SHIFT_AND_MASK_LE(__pdesc, 14, 1)
405 #define GET_RX_DESC_ICV(__pdesc)			\
406 	SHIFT_AND_MASK_LE(__pdesc, 15, 1)
407 #define GET_RX_DESC_DRV_INFO_SIZE(__pdesc)		\
408 	SHIFT_AND_MASK_LE(__pdesc, 16, 4)
409 #define GET_RX_DESC_SECURITY(__pdesc)			\
410 	SHIFT_AND_MASK_LE(__pdesc, 20, 3)
411 #define GET_RX_DESC_QOS(__pdesc)			\
412 	SHIFT_AND_MASK_LE(__pdesc, 23, 1)
413 #define GET_RX_DESC_SHIFT(__pdesc)			\
414 	SHIFT_AND_MASK_LE(__pdesc, 24, 2)
415 #define GET_RX_DESC_PHYST(__pdesc)			\
416 	SHIFT_AND_MASK_LE(__pdesc, 26, 1)
417 #define GET_RX_DESC_SWDEC(__pdesc)			\
418 	SHIFT_AND_MASK_LE(__pdesc, 27, 1)
419 #define GET_RX_DESC_LS(__pdesc)				\
420 	SHIFT_AND_MASK_LE(__pdesc, 28, 1)
421 #define GET_RX_DESC_FS(__pdesc)				\
422 	SHIFT_AND_MASK_LE(__pdesc, 29, 1)
423 #define GET_RX_DESC_EOR(__pdesc)			\
424 	SHIFT_AND_MASK_LE(__pdesc, 30, 1)
425 #define GET_RX_DESC_OWN(__pdesc)			\
426 	SHIFT_AND_MASK_LE(__pdesc, 31, 1)
427 
428 #define SET_RX_DESC_PKT_LEN(__pdesc, __val)		\
429 	SET_BITS_OFFSET_LE(__pdesc, 0, 14, __val)
430 #define SET_RX_DESC_EOR(__pdesc, __val)			\
431 	SET_BITS_OFFSET_LE(__pdesc, 30, 1, __val)
432 #define SET_RX_DESC_OWN(__pdesc, __val)			\
433 	SET_BITS_OFFSET_LE(__pdesc, 31, 1, __val)
434 
435 #define GET_RX_DESC_MACID(__pdesc)			\
436 	SHIFT_AND_MASK_LE(__pdesc+4, 0, 5)
437 #define GET_RX_DESC_TID(__pdesc)			\
438 	SHIFT_AND_MASK_LE(__pdesc+4, 5, 4)
439 #define GET_RX_DESC_HWRSVD(__pdesc)			\
440 	SHIFT_AND_MASK_LE(__pdesc+4, 9, 5)
441 #define GET_RX_DESC_PAGGR(__pdesc)			\
442 	SHIFT_AND_MASK_LE(__pdesc+4, 14, 1)
443 #define GET_RX_DESC_FAGGR(__pdesc)			\
444 	SHIFT_AND_MASK_LE(__pdesc+4, 15, 1)
445 #define GET_RX_DESC_A1_FIT(__pdesc)			\
446 	SHIFT_AND_MASK_LE(__pdesc+4, 16, 4)
447 #define GET_RX_DESC_A2_FIT(__pdesc)			\
448 	SHIFT_AND_MASK_LE(__pdesc+4, 20, 4)
449 #define GET_RX_DESC_PAM(__pdesc)			\
450 	SHIFT_AND_MASK_LE(__pdesc+4, 24, 1)
451 #define GET_RX_DESC_PWR(__pdesc)			\
452 	SHIFT_AND_MASK_LE(__pdesc+4, 25, 1)
453 #define GET_RX_DESC_MD(__pdesc)				\
454 	SHIFT_AND_MASK_LE(__pdesc+4, 26, 1)
455 #define GET_RX_DESC_MF(__pdesc)				\
456 	SHIFT_AND_MASK_LE(__pdesc+4, 27, 1)
457 #define GET_RX_DESC_TYPE(__pdesc)			\
458 	SHIFT_AND_MASK_LE(__pdesc+4, 28, 2)
459 #define GET_RX_DESC_MC(__pdesc)				\
460 	SHIFT_AND_MASK_LE(__pdesc+4, 30, 1)
461 #define GET_RX_DESC_BC(__pdesc)				\
462 	SHIFT_AND_MASK_LE(__pdesc+4, 31, 1)
463 #define GET_RX_DESC_SEQ(__pdesc)			\
464 	SHIFT_AND_MASK_LE(__pdesc+8, 0, 12)
465 #define GET_RX_DESC_FRAG(__pdesc)			\
466 	SHIFT_AND_MASK_LE(__pdesc+8, 12, 4)
467 #define GET_RX_DESC_NEXT_PKT_LEN(__pdesc)		\
468 	SHIFT_AND_MASK_LE(__pdesc+8, 16, 14)
469 #define GET_RX_DESC_NEXT_IND(__pdesc)			\
470 	SHIFT_AND_MASK_LE(__pdesc+8, 30, 1)
471 #define GET_RX_DESC_RSVD(__pdesc)			\
472 	SHIFT_AND_MASK_LE(__pdesc+8, 31, 1)
473 
474 #define GET_RX_DESC_RXMCS(__pdesc)			\
475 	SHIFT_AND_MASK_LE(__pdesc+12, 0, 6)
476 #define GET_RX_DESC_RXHT(__pdesc)			\
477 	SHIFT_AND_MASK_LE(__pdesc+12, 6, 1)
478 #define GET_RX_DESC_SPLCP(__pdesc)			\
479 	SHIFT_AND_MASK_LE(__pdesc+12, 8, 1)
480 #define GET_RX_DESC_BW(__pdesc)				\
481 	SHIFT_AND_MASK_LE(__pdesc+12, 9, 1)
482 #define GET_RX_DESC_HTC(__pdesc)			\
483 	SHIFT_AND_MASK_LE(__pdesc+12, 10, 1)
484 #define GET_RX_DESC_HWPC_ERR(__pdesc)			\
485 	SHIFT_AND_MASK_LE(__pdesc+12, 14, 1)
486 #define GET_RX_DESC_HWPC_IND(__pdesc)			\
487 	SHIFT_AND_MASK_LE(__pdesc+12, 15, 1)
488 #define GET_RX_DESC_IV0(__pdesc)			\
489 	SHIFT_AND_MASK_LE(__pdesc+12, 16, 16)
490 
491 #define GET_RX_DESC_IV1(__pdesc)			\
492 	SHIFT_AND_MASK_LE(__pdesc+16, 0, 32)
493 #define GET_RX_DESC_TSFL(__pdesc)			\
494 	SHIFT_AND_MASK_LE(__pdesc+20, 0, 32)
495 
496 #define GET_RX_DESC_BUFF_ADDR(__pdesc)			\
497 	SHIFT_AND_MASK_LE(__pdesc+24, 0, 32)
498 #define GET_RX_DESC_BUFF_ADDR64(__pdesc)		\
499 	SHIFT_AND_MASK_LE(__pdesc+28, 0, 32)
500 
501 #define SET_RX_DESC_BUFF_ADDR(__pdesc, __val)		\
502 	SET_BITS_OFFSET_LE(__pdesc+24, 0, 32, __val)
503 #define SET_RX_DESC_BUFF_ADDR64(__pdesc, __val)		\
504 	SET_BITS_OFFSET_LE(__pdesc+28, 0, 32, __val)
505 
506 #define CLEAR_PCI_TX_DESC_CONTENT(__pdesc, _size)	\
507 	memset((void *)__pdesc, 0,			\
508 	       min_t(size_t, _size, TX_DESC_NEXT_DESC_OFFSET))
509 
510 /* For 92D early mode */
511 #define SET_EARLYMODE_PKTNUM(__paddr, __value)		\
512 	SET_BITS_OFFSET_LE(__paddr, 0, 3, __value)
513 #define SET_EARLYMODE_LEN0(__paddr, __value)		\
514 	SET_BITS_OFFSET_LE(__paddr, 4, 12, __value)
515 #define SET_EARLYMODE_LEN1(__paddr, __value)		\
516 	SET_BITS_OFFSET_LE(__paddr, 16, 12, __value)
517 #define SET_EARLYMODE_LEN2_1(__paddr, __value)		\
518 	SET_BITS_OFFSET_LE(__paddr, 28, 4, __value)
519 #define SET_EARLYMODE_LEN2_2(__paddr, __value)		\
520 	SET_BITS_OFFSET_LE(__paddr+4, 0, 8, __value)
521 #define SET_EARLYMODE_LEN3(__paddr, __value)		\
522 	SET_BITS_OFFSET_LE(__paddr+4, 8, 12, __value)
523 #define SET_EARLYMODE_LEN4(__paddr, __value)		\
524 	SET_BITS_OFFSET_LE(__paddr+4, 20, 12, __value)
525 
526 struct rx_fwinfo_92d {
527 	u8 gain_trsw[4];
528 	u8 pwdb_all;
529 	u8 cfosho[4];
530 	u8 cfotail[4];
531 	s8 rxevm[2];
532 	s8 rxsnr[4];
533 	u8 pdsnr[2];
534 	u8 csi_current[2];
535 	u8 csi_target[2];
536 	u8 sigevm;
537 	u8 max_ex_pwr;
538 	u8 ex_intf_flag:1;
539 	u8 sgi_en:1;
540 	u8 rxsc:2;
541 	u8 reserve:4;
542 } __packed;
543 
544 struct tx_desc_92d {
545 	u32 pktsize:16;
546 	u32 offset:8;
547 	u32 bmc:1;
548 	u32 htc:1;
549 	u32 lastseg:1;
550 	u32 firstseg:1;
551 	u32 linip:1;
552 	u32 noacm:1;
553 	u32 gf:1;
554 	u32 own:1;
555 
556 	u32 macid:5;
557 	u32 agg_en:1;
558 	u32 bk:1;
559 	u32 rdg_en:1;
560 	u32 queuesel:5;
561 	u32 rd_nav_ext:1;
562 	u32 lsig_txop_en:1;
563 	u32 pifs:1;
564 	u32 rateid:4;
565 	u32 nav_usehdr:1;
566 	u32 en_descid:1;
567 	u32 sectype:2;
568 	u32 pktoffset:8;
569 
570 	u32 rts_rc:6;
571 	u32 data_rc:6;
572 	u32 rsvd0:2;
573 	u32 bar_retryht:2;
574 	u32 rsvd1:1;
575 	u32 morefrag:1;
576 	u32 raw:1;
577 	u32 ccx:1;
578 	u32 ampdudensity:3;
579 	u32 rsvd2:1;
580 	u32 ant_sela:1;
581 	u32 ant_selb:1;
582 	u32 txant_cck:2;
583 	u32 txant_l:2;
584 	u32 txant_ht:2;
585 
586 	u32 nextheadpage:8;
587 	u32 tailpage:8;
588 	u32 seq:12;
589 	u32 pktid:4;
590 
591 	u32 rtsrate:5;
592 	u32 apdcfe:1;
593 	u32 qos:1;
594 	u32 hwseq_enable:1;
595 	u32 userrate:1;
596 	u32 dis_rtsfb:1;
597 	u32 dis_datafb:1;
598 	u32 cts2self:1;
599 	u32 rts_en:1;
600 	u32 hwrts_en:1;
601 	u32 portid:1;
602 	u32 rsvd3:3;
603 	u32 waitdcts:1;
604 	u32 cts2ap_en:1;
605 	u32 txsc:2;
606 	u32 stbc:2;
607 	u32 txshort:1;
608 	u32 txbw:1;
609 	u32 rtsshort:1;
610 	u32 rtsbw:1;
611 	u32 rtssc:2;
612 	u32 rtsstbc:2;
613 
614 	u32 txrate:6;
615 	u32 shortgi:1;
616 	u32 ccxt:1;
617 	u32 txrate_fb_lmt:5;
618 	u32 rtsrate_fb_lmt:4;
619 	u32 retrylmt_en:1;
620 	u32 txretrylmt:6;
621 	u32 usb_txaggnum:8;
622 
623 	u32 txagca:5;
624 	u32 txagcb:5;
625 	u32 usemaxlen:1;
626 	u32 maxaggnum:5;
627 	u32 mcsg1maxlen:4;
628 	u32 mcsg2maxlen:4;
629 	u32 mcsg3maxlen:4;
630 	u32 mcs7sgimaxlen:4;
631 
632 	u32 txbuffersize:16;
633 	u32 mcsg4maxlen:4;
634 	u32 mcsg5maxlen:4;
635 	u32 mcsg6maxlen:4;
636 	u32 mcsg15sgimaxlen:4;
637 
638 	u32 txbuffaddr;
639 	u32 txbufferaddr64;
640 	u32 nextdescaddress;
641 	u32 nextdescaddress64;
642 
643 	u32 reserve_pass_pcie_mm_limit[4];
644 } __packed;
645 
646 struct rx_desc_92d {
647 	u32 length:14;
648 	u32 crc32:1;
649 	u32 icverror:1;
650 	u32 drv_infosize:4;
651 	u32 security:3;
652 	u32 qos:1;
653 	u32 shift:2;
654 	u32 phystatus:1;
655 	u32 swdec:1;
656 	u32 lastseg:1;
657 	u32 firstseg:1;
658 	u32 eor:1;
659 	u32 own:1;
660 
661 	u32 macid:5;
662 	u32 tid:4;
663 	u32 hwrsvd:5;
664 	u32 paggr:1;
665 	u32 faggr:1;
666 	u32 a1_fit:4;
667 	u32 a2_fit:4;
668 	u32 pam:1;
669 	u32 pwr:1;
670 	u32 moredata:1;
671 	u32 morefrag:1;
672 	u32 type:2;
673 	u32 mc:1;
674 	u32 bc:1;
675 
676 	u32 seq:12;
677 	u32 frag:4;
678 	u32 nextpktlen:14;
679 	u32 nextind:1;
680 	u32 rsvd:1;
681 
682 	u32 rxmcs:6;
683 	u32 rxht:1;
684 	u32 amsdu:1;
685 	u32 splcp:1;
686 	u32 bandwidth:1;
687 	u32 htc:1;
688 	u32 tcpchk_rpt:1;
689 	u32 ipcchk_rpt:1;
690 	u32 tcpchk_valid:1;
691 	u32 hwpcerr:1;
692 	u32 hwpcind:1;
693 	u32 iv0:16;
694 
695 	u32 iv1;
696 
697 	u32 tsfl;
698 
699 	u32 bufferaddress;
700 	u32 bufferaddress64;
701 
702 } __packed;
703 
704 void rtl92de_tx_fill_desc(struct ieee80211_hw *hw,
705 			  struct ieee80211_hdr *hdr, u8 *pdesc,
706 			  u8 *pbd_desc_tx, struct ieee80211_tx_info *info,
707 			  struct ieee80211_sta *sta,
708 			  struct sk_buff *skb, u8 hw_queue,
709 			  struct rtl_tcb_desc *ptcb_desc);
710 bool rtl92de_rx_query_desc(struct ieee80211_hw *hw,
711 			   struct rtl_stats *stats,
712 			   struct ieee80211_rx_status *rx_status,
713 			   u8 *pdesc, struct sk_buff *skb);
714 void rtl92de_set_desc(struct ieee80211_hw *hw, u8 *pdesc, bool istx,
715 		      u8 desc_name, u8 *val);
716 u64 rtl92de_get_desc(struct ieee80211_hw *hw,
717 		     u8 *p_desc, bool istx, u8 desc_name);
718 void rtl92de_tx_polling(struct ieee80211_hw *hw, u8 hw_queue);
719 void rtl92de_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 *pdesc,
720 			     bool b_firstseg, bool b_lastseg,
721 			     struct sk_buff *skb);
722 
723 #endif
724