blob: 48a80fa9eac23ac8d66b8ee355109f7d7f48c3c1 [file] [log] [blame]
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001/*
2 * Copyright (c) 2014 - 2015 Jes Sorensen <Jes.Sorensen@redhat.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * Register definitions taken from original Realtek rtl8723au driver
14 */
15
16#include <asm/byteorder.h>
17
18#define RTL8XXXU_DEBUG_REG_WRITE 0x01
19#define RTL8XXXU_DEBUG_REG_READ 0x02
20#define RTL8XXXU_DEBUG_RFREG_WRITE 0x04
21#define RTL8XXXU_DEBUG_RFREG_READ 0x08
22#define RTL8XXXU_DEBUG_CHANNEL 0x10
23#define RTL8XXXU_DEBUG_TX 0x20
24#define RTL8XXXU_DEBUG_TX_DUMP 0x40
25#define RTL8XXXU_DEBUG_RX 0x80
26#define RTL8XXXU_DEBUG_RX_DUMP 0x100
27#define RTL8XXXU_DEBUG_USB 0x200
28#define RTL8XXXU_DEBUG_KEY 0x400
29#define RTL8XXXU_DEBUG_H2C 0x800
30#define RTL8XXXU_DEBUG_ACTION 0x1000
31#define RTL8XXXU_DEBUG_EFUSE 0x2000
32
33#define RTW_USB_CONTROL_MSG_TIMEOUT 500
34#define RTL8XXXU_MAX_REG_POLL 500
35#define USB_INTR_CONTENT_LENGTH 56
36
Jes Sorensen35a741f2016-02-29 17:04:10 -050037#define RTL8XXXU_OUT_ENDPOINTS 4
Jes Sorensen26f1fad2015-10-14 20:44:51 -040038
39#define REALTEK_USB_READ 0xc0
40#define REALTEK_USB_WRITE 0x40
41#define REALTEK_USB_CMD_REQ 0x05
42#define REALTEK_USB_CMD_IDX 0x00
43
44#define TX_TOTAL_PAGE_NUM 0xf8
Jes Sorensen80805aa2016-04-07 14:19:18 -040045#define TX_TOTAL_PAGE_NUM_8192E 0xf3
Jes Sorensen26f1fad2015-10-14 20:44:51 -040046/* (HPQ + LPQ + NPQ + PUBQ) = TX_TOTAL_PAGE_NUM */
47#define TX_PAGE_NUM_PUBQ 0xe7
48#define TX_PAGE_NUM_HI_PQ 0x0c
49#define TX_PAGE_NUM_LO_PQ 0x02
50#define TX_PAGE_NUM_NORM_PQ 0x02
51
52#define RTL_FW_PAGE_SIZE 4096
53#define RTL8XXXU_FIRMWARE_POLL_MAX 1000
54
55#define RTL8723A_CHANNEL_GROUPS 3
56#define RTL8723A_MAX_RF_PATHS 2
Jes Sorensen21db9972016-02-29 17:05:21 -050057#define RTL8723B_CHANNEL_GROUPS 6
Jes Sorensen3be26992016-02-29 17:05:22 -050058#define RTL8723B_TX_COUNT 4
Jes Sorensen4a0d7db2016-02-29 17:05:18 -050059#define RTL8723B_MAX_RF_PATHS 4
Jes Sorensen21db9972016-02-29 17:05:21 -050060#define RTL8XXXU_MAX_CHANNEL_GROUPS 6
Jes Sorensen26f1fad2015-10-14 20:44:51 -040061#define RF6052_MAX_TX_PWR 0x3f
62
Jes Sorensen3307d842016-02-29 17:03:59 -050063#define EFUSE_MAP_LEN 512
64#define EFUSE_MAX_SECTION_8723A 64
Jes Sorensen26f1fad2015-10-14 20:44:51 -040065#define EFUSE_REAL_CONTENT_LEN_8723A 512
66#define EFUSE_BT_MAP_LEN_8723A 1024
67#define EFUSE_MAX_WORD_UNIT 4
68
Jes Sorensenba17d822016-03-31 17:08:39 -040069enum rtl8xxxu_rtl_chip {
70 RTL8192S = 0x81920,
71 RTL8191S = 0x81910,
72 RTL8192C = 0x8192c,
73 RTL8191C = 0x8191c,
74 RTL8188C = 0x8188c,
75 RTL8188R = 0x81889,
76 RTL8192D = 0x8192d,
77 RTL8723A = 0x8723a,
78 RTL8188E = 0x8188e,
79 RTL8812 = 0x88120,
80 RTL8821 = 0x88210,
81 RTL8192E = 0x8192e,
82 RTL8191E = 0x8191e,
83 RTL8723B = 0x8723b,
84 RTL8814A = 0x8814a,
85 RTL8881A = 0x8881a,
86 RTL8821B = 0x8821b,
87 RTL8822B = 0x8822b,
88 RTL8703B = 0x8703b,
89 RTL8195A = 0x8195a,
90 RTL8188F = 0x8188f
91};
92
Jes Sorensenb18cdfd2016-02-29 17:04:47 -050093enum rtl8xxxu_rx_type {
94 RX_TYPE_DATA_PKT = 0,
95 RX_TYPE_C2H = 1,
96 RX_TYPE_ERROR = -1
97};
98
Jes Sorensen26f1fad2015-10-14 20:44:51 -040099struct rtl8xxxu_rx_desc {
100#ifdef __LITTLE_ENDIAN
101 u32 pktlen:14;
102 u32 crc32:1;
103 u32 icverr:1;
104 u32 drvinfo_sz:4;
105 u32 security:3;
106 u32 qos:1;
107 u32 shift:2;
108 u32 phy_stats:1;
109 u32 swdec:1;
110 u32 ls:1;
111 u32 fs:1;
112 u32 eor:1;
113 u32 own:1;
114
115 u32 macid:5;
116 u32 tid:4;
117 u32 hwrsvd:4;
118 u32 amsdu:1;
119 u32 paggr:1;
120 u32 faggr:1;
121 u32 a1fit:4;
122 u32 a2fit:4;
123 u32 pam:1;
124 u32 pwr:1;
125 u32 md:1;
126 u32 mf:1;
127 u32 type:2;
128 u32 mc:1;
129 u32 bc:1;
130
131 u32 seq:12;
132 u32 frag:4;
133 u32 nextpktlen:14;
134 u32 nextind:1;
135 u32 reserved0:1;
136
137 u32 rxmcs:6;
138 u32 rxht:1;
139 u32 gf:1;
140 u32 splcp:1;
141 u32 bw:1;
142 u32 htc:1;
143 u32 eosp:1;
144 u32 bssidfit:2;
145 u32 reserved1:16;
146 u32 unicastwake:1;
147 u32 magicwake:1;
148
149 u32 pattern0match:1;
150 u32 pattern1match:1;
151 u32 pattern2match:1;
152 u32 pattern3match:1;
153 u32 pattern4match:1;
154 u32 pattern5match:1;
155 u32 pattern6match:1;
156 u32 pattern7match:1;
157 u32 pattern8match:1;
158 u32 pattern9match:1;
159 u32 patternamatch:1;
160 u32 patternbmatch:1;
161 u32 patterncmatch:1;
162 u32 reserved2:19;
163#else
164 u32 own:1;
165 u32 eor:1;
166 u32 fs:1;
167 u32 ls:1;
168 u32 swdec:1;
169 u32 phy_stats:1;
170 u32 shift:2;
171 u32 qos:1;
172 u32 security:3;
173 u32 drvinfo_sz:4;
174 u32 icverr:1;
175 u32 crc32:1;
176 u32 pktlen:14;
177
178 u32 bc:1;
179 u32 mc:1;
180 u32 type:2;
181 u32 mf:1;
182 u32 md:1;
183 u32 pwr:1;
184 u32 pam:1;
185 u32 a2fit:4;
186 u32 a1fit:4;
187 u32 faggr:1;
188 u32 paggr:1;
189 u32 amsdu:1;
190 u32 hwrsvd:4;
191 u32 tid:4;
192 u32 macid:5;
193
194 u32 reserved0:1;
195 u32 nextind:1;
196 u32 nextpktlen:14;
197 u32 frag:4;
198 u32 seq:12;
199
200 u32 magicwake:1;
201 u32 unicastwake:1;
202 u32 reserved1:16;
203 u32 bssidfit:2;
204 u32 eosp:1;
205 u32 htc:1;
206 u32 bw:1;
207 u32 splcp:1;
208 u32 gf:1;
209 u32 rxht:1;
210 u32 rxmcs:6;
211
212 u32 reserved2:19;
213 u32 patterncmatch:1;
214 u32 patternbmatch:1;
215 u32 patternamatch:1;
216 u32 pattern9match:1;
217 u32 pattern8match:1;
218 u32 pattern7match:1;
219 u32 pattern6match:1;
220 u32 pattern5match:1;
221 u32 pattern4match:1;
222 u32 pattern3match:1;
223 u32 pattern2match:1;
224 u32 pattern1match:1;
225 u32 pattern0match:1;
226#endif
227 __le32 tsfl;
228#if 0
229 u32 bassn:12;
230 u32 bavld:1;
231 u32 reserved3:19;
232#endif
233};
234
Jes Sorensena6c80d22016-02-29 17:04:46 -0500235struct rtl8723bu_rx_desc {
236#ifdef __LITTLE_ENDIAN
237 u32 pktlen:14;
238 u32 crc32:1;
239 u32 icverr:1;
240 u32 drvinfo_sz:4;
241 u32 security:3;
242 u32 qos:1;
243 u32 shift:2;
244 u32 phy_stats:1;
245 u32 swdec:1;
246 u32 ls:1;
247 u32 fs:1;
248 u32 eor:1;
249 u32 own:1;
250
251 u32 macid:7;
252 u32 dummy1_0:1;
253 u32 tid:4;
254 u32 dummy1_1:1;
255 u32 amsdu:1;
256 u32 rxid_match:1;
257 u32 paggr:1;
258 u32 a1fit:4; /* 16 */
259 u32 chkerr:1;
260 u32 ipver:1;
261 u32 tcpudp:1;
262 u32 chkvld:1;
263 u32 pam:1;
264 u32 pwr:1;
265 u32 more_data:1;
266 u32 more_frag:1;
267 u32 type:2;
268 u32 mc:1;
269 u32 bc:1;
270
271 u32 seq:12;
272 u32 frag:4;
273 u32 rx_is_qos:1; /* 16 */
274 u32 dummy2_0:1;
275 u32 wlanhd_iv_len:6;
276 u32 dummy2_1:4;
277 u32 rpt_sel:1;
278 u32 dummy2_2:3;
279
280 u32 rxmcs:7;
281 u32 dummy3_0:3;
282 u32 htc:1;
283 u32 eosp:1;
284 u32 bssidfit:2;
285 u32 dummy3_1:2;
286 u32 usb_agg_pktnum:8; /* 16 */
287 u32 dummy3_2:5;
288 u32 pattern_match:1;
289 u32 unicast_match:1;
290 u32 magic_match:1;
291
292 u32 splcp:1;
293 u32 ldcp:1;
294 u32 stbc:1;
295 u32 dummy4_0:1;
296 u32 bw:2;
297 u32 dummy4_1:26;
298#else
299 u32 own:1;
300 u32 eor:1;
301 u32 fs:1;
302 u32 ls:1;
303 u32 swdec:1;
304 u32 phy_stats:1;
305 u32 shift:2;
306 u32 qos:1;
307 u32 security:3;
308 u32 drvinfo_sz:4;
309 u32 icverr:1;
310 u32 crc32:1;
311 u32 pktlen:14;
312
313 u32 bc:1;
314 u32 mc:1;
315 u32 type:2;
316 u32 mf:1;
317 u32 md:1;
318 u32 pwr:1;
319 u32 pam:1;
320 u32 a2fit:4;
321 u32 a1fit:4;
322 u32 faggr:1;
323 u32 paggr:1;
324 u32 amsdu:1;
325 u32 hwrsvd:4;
326 u32 tid:4;
327 u32 macid:5;
328
329 u32 dummy2_2:3;
330 u32 rpt_sel:1;
331 u32 dummy2_1:4;
332 u32 wlanhd_iv_len:6;
333 u32 dummy2_0:1;
334 u32 rx_is_qos:1;
335 u32 frag:4; /* 16 */
336 u32 seq:12;
337
338 u32 magic_match:1;
339 u32 unicast_match:1;
340 u32 pattern_match:1;
341 u32 dummy3_2:5;
342 u32 usb_agg_pktnum:8;
343 u32 dummy3_1:2; /* 16 */
344 u32 bssidfit:2;
345 u32 eosp:1;
346 u32 htc:1;
347 u32 dummy3_0:3;
348 u32 rxmcs:7;
349
350 u32 dumm4_1:26;
351 u32 bw:2;
352 u32 dummy4_0:1;
353 u32 stbc:1;
354 u32 ldcp:1;
355 u32 splcp:1;
356#endif
357 __le32 tsfl;
358};
359
Jes Sorensendbb28962016-03-31 17:08:33 -0400360struct rtl8xxxu_txdesc32 {
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400361 __le16 pkt_size;
362 u8 pkt_offset;
363 u8 txdw0;
364 __le32 txdw1;
365 __le32 txdw2;
366 __le32 txdw3;
367 __le32 txdw4;
368 __le32 txdw5;
369 __le32 txdw6;
370 __le16 csum;
371 __le16 txdw7;
372};
373
Jes Sorensendbb28962016-03-31 17:08:33 -0400374struct rtl8xxxu_txdesc40 {
Jes Sorensen80491a12016-02-29 17:05:26 -0500375 __le16 pkt_size;
376 u8 pkt_offset;
377 u8 txdw0;
378 __le32 txdw1;
379 __le32 txdw2;
380 __le32 txdw3;
381 __le32 txdw4;
382 __le32 txdw5;
383 __le32 txdw6;
384 __le16 csum;
385 __le16 txdw7;
386 __le32 txdw8;
387 __le32 txdw9;
388};
389
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400390/* CCK Rates, TxHT = 0 */
391#define DESC_RATE_1M 0x00
392#define DESC_RATE_2M 0x01
393#define DESC_RATE_5_5M 0x02
394#define DESC_RATE_11M 0x03
395
396/* OFDM Rates, TxHT = 0 */
397#define DESC_RATE_6M 0x04
398#define DESC_RATE_9M 0x05
399#define DESC_RATE_12M 0x06
400#define DESC_RATE_18M 0x07
401#define DESC_RATE_24M 0x08
402#define DESC_RATE_36M 0x09
403#define DESC_RATE_48M 0x0a
404#define DESC_RATE_54M 0x0b
405
406/* MCS Rates, TxHT = 1 */
407#define DESC_RATE_MCS0 0x0c
408#define DESC_RATE_MCS1 0x0d
409#define DESC_RATE_MCS2 0x0e
410#define DESC_RATE_MCS3 0x0f
411#define DESC_RATE_MCS4 0x10
412#define DESC_RATE_MCS5 0x11
413#define DESC_RATE_MCS6 0x12
414#define DESC_RATE_MCS7 0x13
415#define DESC_RATE_MCS8 0x14
416#define DESC_RATE_MCS9 0x15
417#define DESC_RATE_MCS10 0x16
418#define DESC_RATE_MCS11 0x17
419#define DESC_RATE_MCS12 0x18
420#define DESC_RATE_MCS13 0x19
421#define DESC_RATE_MCS14 0x1a
422#define DESC_RATE_MCS15 0x1b
423#define DESC_RATE_MCS15_SG 0x1c
424#define DESC_RATE_MCS32 0x20
425
426#define TXDESC_OFFSET_SZ 0
427#define TXDESC_OFFSET_SHT 16
428#if 0
429#define TXDESC_BMC BIT(24)
430#define TXDESC_LSG BIT(26)
431#define TXDESC_FSG BIT(27)
432#define TXDESC_OWN BIT(31)
433#else
434#define TXDESC_BROADMULTICAST BIT(0)
Jes Sorensen02492582016-02-29 17:05:29 -0500435#define TXDESC_HTC BIT(1)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400436#define TXDESC_LAST_SEGMENT BIT(2)
437#define TXDESC_FIRST_SEGMENT BIT(3)
Jes Sorensen02492582016-02-29 17:05:29 -0500438#define TXDESC_LINIP BIT(4)
439#define TXDESC_NO_ACM BIT(5)
440#define TXDESC_GF BIT(6)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400441#define TXDESC_OWN BIT(7)
442#endif
443
444/* Word 1 */
Jes Sorensence2d1db2016-02-29 17:05:30 -0500445/*
446 * Bits 0-7 differ dependent on chip generation. For 8723au bits 5/6 are
447 * aggregation enable and break respectively. For 8723bu, bits 0-7 are macid.
448 */
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400449#define TXDESC_PKT_OFFSET_SZ 0
Jes Sorensen33f37242016-03-31 17:08:34 -0400450#define TXDESC32_AGG_ENABLE BIT(5)
451#define TXDESC32_AGG_BREAK BIT(6)
452#define TXDESC40_MACID_SHIFT 0
453#define TXDESC40_MACID_MASK 0x00f0
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400454#define TXDESC_QUEUE_SHIFT 8
455#define TXDESC_QUEUE_MASK 0x1f00
456#define TXDESC_QUEUE_BK 0x2
457#define TXDESC_QUEUE_BE 0x0
458#define TXDESC_QUEUE_VI 0x5
459#define TXDESC_QUEUE_VO 0x7
460#define TXDESC_QUEUE_BEACON 0x10
461#define TXDESC_QUEUE_HIGH 0x11
462#define TXDESC_QUEUE_MGNT 0x12
463#define TXDESC_QUEUE_CMD 0x13
464#define TXDESC_QUEUE_MAX (TXDESC_QUEUE_CMD + 1)
Jes Sorensen33f37242016-03-31 17:08:34 -0400465#define TXDESC40_RDG_NAV_EXT BIT(13)
466#define TXDESC40_LSIG_TXOP_ENABLE BIT(14)
467#define TXDESC40_PIFS BIT(15)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400468
469#define DESC_RATE_ID_SHIFT 16
470#define DESC_RATE_ID_MASK 0xf
471#define TXDESC_NAVUSEHDR BIT(20)
472#define TXDESC_SEC_RC4 0x00400000
473#define TXDESC_SEC_AES 0x00c00000
474#define TXDESC_PKT_OFFSET_SHIFT 26
475#define TXDESC_AGG_EN BIT(29)
476#define TXDESC_HWPC BIT(31)
477
478/* Word 2 */
Jes Sorensen33f37242016-03-31 17:08:34 -0400479#define TXDESC40_PAID_SHIFT 0
480#define TXDESC40_PAID_MASK 0x1ff
481#define TXDESC40_CCA_RTS_SHIFT 10
482#define TXDESC40_CCA_RTS_MASK 0xc00
483#define TXDESC40_AGG_ENABLE BIT(12)
484#define TXDESC40_RDG_ENABLE BIT(13)
485#define TXDESC40_AGG_BREAK BIT(16)
486#define TXDESC40_MORE_FRAG BIT(17)
487#define TXDESC40_RAW BIT(18)
488#define TXDESC32_ACK_REPORT BIT(19)
489#define TXDESC40_SPE_RPT BIT(19)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400490#define TXDESC_AMPDU_DENSITY_SHIFT 20
Jes Sorensen33f37242016-03-31 17:08:34 -0400491#define TXDESC40_BT_INT BIT(23)
Jes Sorensen169bc5c2016-03-31 17:08:35 -0400492#define TXDESC40_GID_SHIFT 24
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400493
494/* Word 3 */
Jes Sorensen33f37242016-03-31 17:08:34 -0400495#define TXDESC40_USE_DRIVER_RATE BIT(8)
496#define TXDESC40_CTS_SELF_ENABLE BIT(11)
497#define TXDESC40_RTS_CTS_ENABLE BIT(12)
498#define TXDESC40_HW_RTS_ENABLE BIT(13)
499#define TXDESC32_SEQ_SHIFT 16
500#define TXDESC32_SEQ_MASK 0x0fff0000
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400501
502/* Word 4 */
Jes Sorensen33f37242016-03-31 17:08:34 -0400503#define TXDESC32_RTS_RATE_SHIFT 0
504#define TXDESC32_RTS_RATE_MASK 0x3f
505#define TXDESC32_QOS BIT(6)
506#define TXDESC32_HW_SEQ_ENABLE BIT(7)
507#define TXDESC32_USE_DRIVER_RATE BIT(8)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400508#define TXDESC_DISABLE_DATA_FB BIT(10)
Jes Sorensen33f37242016-03-31 17:08:34 -0400509#define TXDESC32_CTS_SELF_ENABLE BIT(11)
510#define TXDESC32_RTS_CTS_ENABLE BIT(12)
511#define TXDESC32_HW_RTS_ENABLE BIT(13)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400512#define TXDESC_PRIME_CH_OFF_LOWER BIT(20)
513#define TXDESC_PRIME_CH_OFF_UPPER BIT(21)
Jes Sorensen33f37242016-03-31 17:08:34 -0400514#define TXDESC32_SHORT_PREAMBLE BIT(24)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400515#define TXDESC_DATA_BW BIT(25)
516#define TXDESC_RTS_DATA_BW BIT(27)
517#define TXDESC_RTS_PRIME_CH_OFF_LOWER BIT(28)
518#define TXDESC_RTS_PRIME_CH_OFF_UPPER BIT(29)
Jes Sorensen33f37242016-03-31 17:08:34 -0400519#define TXDESC40_DATA_RATE_FB_SHIFT 8
520#define TXDESC40_DATA_RATE_FB_MASK 0x00001f00
521#define TXDESC40_RETRY_LIMIT_ENABLE BIT(17)
522#define TXDESC40_RETRY_LIMIT_SHIFT 18
523#define TXDESC40_RETRY_LIMIT_MASK 0x00fc0000
524#define TXDESC40_RTS_RATE_SHIFT 24
525#define TXDESC40_RTS_RATE_MASK 0x3f000000
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400526
527/* Word 5 */
Jes Sorensen33f37242016-03-31 17:08:34 -0400528#define TXDESC40_SHORT_PREAMBLE BIT(4)
Jes Sorensen1df1de32016-03-31 17:08:36 -0400529#define TXDESC32_SHORT_GI BIT(6)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400530#define TXDESC_CCX_TAG BIT(7)
Jes Sorensen33f37242016-03-31 17:08:34 -0400531#define TXDESC32_RETRY_LIMIT_ENABLE BIT(17)
532#define TXDESC32_RETRY_LIMIT_SHIFT 18
533#define TXDESC32_RETRY_LIMIT_MASK 0x00fc0000
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400534
535/* Word 6 */
536#define TXDESC_MAX_AGG_SHIFT 11
537
Jes Sorensen2098bfb2016-02-29 17:05:33 -0500538/* Word 8 */
Jes Sorensen33f37242016-03-31 17:08:34 -0400539#define TXDESC40_HW_SEQ_ENABLE BIT(15)
Jes Sorensen2098bfb2016-02-29 17:05:33 -0500540
Jes Sorensencc2646d2016-02-29 17:05:32 -0500541/* Word 9 */
Jes Sorensen33f37242016-03-31 17:08:34 -0400542#define TXDESC40_SEQ_SHIFT 12
543#define TXDESC40_SEQ_MASK 0x00fff000
Jes Sorensencc2646d2016-02-29 17:05:32 -0500544
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400545struct phy_rx_agc_info {
546#ifdef __LITTLE_ENDIAN
547 u8 gain:7, trsw:1;
548#else
549 u8 trsw:1, gain:7;
550#endif
551};
552
553struct rtl8723au_phy_stats {
554 struct phy_rx_agc_info path_agc[RTL8723A_MAX_RF_PATHS];
555 u8 ch_corr[RTL8723A_MAX_RF_PATHS];
556 u8 cck_sig_qual_ofdm_pwdb_all;
557 u8 cck_agc_rpt_ofdm_cfosho_a;
558 u8 cck_rpt_b_ofdm_cfosho_b;
559 u8 reserved_1;
560 u8 noise_power_db_msb;
561 u8 path_cfotail[RTL8723A_MAX_RF_PATHS];
562 u8 pcts_mask[RTL8723A_MAX_RF_PATHS];
563 s8 stream_rxevm[RTL8723A_MAX_RF_PATHS];
564 u8 path_rxsnr[RTL8723A_MAX_RF_PATHS];
565 u8 noise_power_db_lsb;
566 u8 reserved_2[3];
567 u8 stream_csi[RTL8723A_MAX_RF_PATHS];
568 u8 stream_target_csi[RTL8723A_MAX_RF_PATHS];
569 s8 sig_evm;
570 u8 reserved_3;
571
572#ifdef __LITTLE_ENDIAN
573 u8 antsel_rx_keep_2:1; /* ex_intf_flg:1; */
574 u8 sgi_en:1;
575 u8 rxsc:2;
576 u8 idle_long:1;
577 u8 r_ant_train_en:1;
578 u8 antenna_select_b:1;
579 u8 antenna_select:1;
580#else /* _BIG_ENDIAN_ */
581 u8 antenna_select:1;
582 u8 antenna_select_b:1;
583 u8 r_ant_train_en:1;
584 u8 idle_long:1;
585 u8 rxsc:2;
586 u8 sgi_en:1;
587 u8 antsel_rx_keep_2:1; /* ex_intf_flg:1; */
588#endif
589};
590
591/*
592 * Regs to backup
593 */
594#define RTL8XXXU_ADDA_REGS 16
595#define RTL8XXXU_MAC_REGS 4
596#define RTL8XXXU_BB_REGS 9
597
598struct rtl8xxxu_firmware_header {
599 __le16 signature; /* 92C0: test chip; 92C,
600 88C0: test chip;
601 88C1: MP A-cut;
602 92C1: MP A-cut */
603 u8 category; /* AP/NIC and USB/PCI */
604 u8 function;
605
606 __le16 major_version; /* FW Version */
607 u8 minor_version; /* FW Subversion, default 0x00 */
608 u8 reserved1;
609
610 u8 month; /* Release time Month field */
611 u8 date; /* Release time Date field */
612 u8 hour; /* Release time Hour field */
613 u8 minute; /* Release time Minute field */
614
615 __le16 ramcodesize; /* Size of RAM code */
616 u16 reserved2;
617
618 __le32 svn_idx; /* SVN entry index */
619 u32 reserved3;
620
621 u32 reserved4;
622 u32 reserved5;
623
624 u8 data[0];
625};
626
627/*
628 * The 8723au has 3 channel groups: 1-3, 4-9, and 10-14
629 */
630struct rtl8723au_idx {
631#ifdef __LITTLE_ENDIAN
632 int a:4;
633 int b:4;
634#else
635 int b:4;
636 int a:4;
637#endif
638} __attribute__((packed));
639
640struct rtl8723au_efuse {
641 __le16 rtl_id;
642 u8 res0[0xe];
643 u8 cck_tx_power_index_A[3]; /* 0x10 */
644 u8 cck_tx_power_index_B[3];
645 u8 ht40_1s_tx_power_index_A[3]; /* 0x16 */
646 u8 ht40_1s_tx_power_index_B[3];
647 /*
648 * The following entries are half-bytes split as:
649 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
650 */
651 struct rtl8723au_idx ht20_tx_power_index_diff[3];
652 struct rtl8723au_idx ofdm_tx_power_index_diff[3];
653 struct rtl8723au_idx ht40_max_power_offset[3];
654 struct rtl8723au_idx ht20_max_power_offset[3];
655 u8 channel_plan; /* 0x28 */
656 u8 tssi_a;
657 u8 thermal_meter;
658 u8 rf_regulatory;
659 u8 rf_option_2;
660 u8 rf_option_3;
661 u8 rf_option_4;
662 u8 res7;
663 u8 version /* 0x30 */;
664 u8 customer_id_major;
665 u8 customer_id_minor;
666 u8 xtal_k;
667 u8 chipset; /* 0x34 */
668 u8 res8[0x82];
669 u8 vid; /* 0xb7 */
670 u8 res9;
671 u8 pid; /* 0xb9 */
672 u8 res10[0x0c];
673 u8 mac_addr[ETH_ALEN]; /* 0xc6 */
674 u8 res11[2];
675 u8 vendor_name[7];
676 u8 res12[2];
677 u8 device_name[0x29]; /* 0xd7 */
678};
679
680struct rtl8192cu_efuse {
681 __le16 rtl_id;
682 __le16 hpon;
683 u8 res0[2];
684 __le16 clk;
685 __le16 testr;
686 __le16 vid;
687 __le16 did;
688 __le16 svid;
689 __le16 smid; /* 0x10 */
690 u8 res1[4];
691 u8 mac_addr[ETH_ALEN]; /* 0x16 */
692 u8 res2[2];
693 u8 vendor_name[7];
694 u8 res3[3];
695 u8 device_name[0x14]; /* 0x28 */
696 u8 res4[0x1e]; /* 0x3c */
697 u8 cck_tx_power_index_A[3]; /* 0x5a */
698 u8 cck_tx_power_index_B[3];
699 u8 ht40_1s_tx_power_index_A[3]; /* 0x60 */
700 u8 ht40_1s_tx_power_index_B[3];
701 /*
702 * The following entries are half-bytes split as:
703 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
704 */
705 struct rtl8723au_idx ht40_2s_tx_power_index_diff[3];
706 struct rtl8723au_idx ht20_tx_power_index_diff[3]; /* 0x69 */
707 struct rtl8723au_idx ofdm_tx_power_index_diff[3];
708 struct rtl8723au_idx ht40_max_power_offset[3]; /* 0x6f */
709 struct rtl8723au_idx ht20_max_power_offset[3];
710 u8 channel_plan; /* 0x75 */
711 u8 tssi_a;
712 u8 tssi_b;
713 u8 thermal_meter; /* xtal_k */ /* 0x78 */
714 u8 rf_regulatory;
715 u8 rf_option_2;
716 u8 rf_option_3;
717 u8 rf_option_4;
718 u8 res5[1]; /* 0x7d */
719 u8 version;
720 u8 customer_id;
721};
722
Jes Sorensen3be26992016-02-29 17:05:22 -0500723struct rtl8723bu_pwr_idx {
724#ifdef __LITTLE_ENDIAN
725 int ht20:4;
726 int ht40:4;
727 int ofdm:4;
728 int cck:4;
729#else
730 int cck:4;
731 int ofdm:4;
732 int ht40:4;
733 int ht20:4;
734#endif
735} __attribute__((packed));
736
Jes Sorensen4a0d7db2016-02-29 17:05:18 -0500737struct rtl8723bu_efuse_tx_power {
738 u8 cck_base[6];
739 u8 ht40_base[5];
740 struct rtl8723au_idx ht20_ofdm_1s_diff;
Jes Sorensen3be26992016-02-29 17:05:22 -0500741 struct rtl8723bu_pwr_idx pwr_diff[3];
Jes Sorensen4a0d7db2016-02-29 17:05:18 -0500742 u8 dummy5g[24]; /* max channel group (14) + power diff offset (10) */
743};
744
Jes Sorensen3c836d62016-02-29 17:04:11 -0500745struct rtl8723bu_efuse {
746 __le16 rtl_id;
747 u8 res0[0x0e];
Jes Sorensen4a0d7db2016-02-29 17:05:18 -0500748 struct rtl8723bu_efuse_tx_power tx_power_index_A; /* 0x10 */
749 struct rtl8723bu_efuse_tx_power tx_power_index_B; /* 0x3a */
750 struct rtl8723bu_efuse_tx_power tx_power_index_C; /* 0x64 */
751 struct rtl8723bu_efuse_tx_power tx_power_index_D; /* 0x8e */
Jes Sorensen3c836d62016-02-29 17:04:11 -0500752 u8 channel_plan; /* 0xb8 */
753 u8 xtal_k;
754 u8 thermal_meter;
755 u8 iqk_lck;
756 u8 pa_type; /* 0xbc */
757 u8 lna_type_2g; /* 0xbd */
758 u8 res2[3];
759 u8 rf_board_option;
760 u8 rf_feature_option;
761 u8 rf_bt_setting;
762 u8 eeprom_version;
763 u8 eeprom_customer_id;
764 u8 res3[2];
765 u8 tx_pwr_calibrate_rate;
766 u8 rf_antenna_option; /* 0xc9 */
767 u8 rfe_option;
768 u8 res4[9];
769 u8 usb_optional_function;
770 u8 res5[0x1e];
771 u8 res6[2];
772 u8 serial[0x0b]; /* 0xf5 */
773 u8 vid; /* 0x100 */
774 u8 res7;
775 u8 pid;
776 u8 res8[4];
777 u8 mac_addr[ETH_ALEN]; /* 0x107 */
778 u8 res9[2];
779 u8 vendor_name[0x07];
780 u8 res10[2];
Jes Sorensen22a31d42016-02-29 17:04:15 -0500781 u8 device_name[0x14];
782 u8 res11[0xcf];
783 u8 package_type; /* 0x1fb */
784 u8 res12[0x4];
Jes Sorensen3c836d62016-02-29 17:04:11 -0500785};
786
Jakub Sitnickie6f9a9c2016-02-29 17:04:39 -0500787struct rtl8192eu_efuse_tx_power {
788 u8 cck_base[6];
789 u8 ht40_base[5];
790 struct rtl8723au_idx ht20_ofdm_1s_diff;
Jes Sorensen9e247722016-04-07 14:19:23 -0400791 struct rtl8723bu_pwr_idx pwr_diff[3];
792 u8 dummy5g[24]; /* max channel group (14) + power diff offset (10) */
Jakub Sitnickie6f9a9c2016-02-29 17:04:39 -0500793};
794
Jes Sorensen3307d842016-02-29 17:03:59 -0500795struct rtl8192eu_efuse {
796 __le16 rtl_id;
797 u8 res0[0x0e];
Jakub Sitnickie6f9a9c2016-02-29 17:04:39 -0500798 struct rtl8192eu_efuse_tx_power tx_power_index_A; /* 0x10 */
Jes Sorensen9e247722016-04-07 14:19:23 -0400799 struct rtl8192eu_efuse_tx_power tx_power_index_B; /* 0x3a */
800 u8 res2[0x54];
Jes Sorensen3307d842016-02-29 17:03:59 -0500801 u8 channel_plan; /* 0xb8 */
802 u8 xtal_k;
803 u8 thermal_meter;
804 u8 iqk_lck;
805 u8 pa_type; /* 0xbc */
806 u8 lna_type_2g; /* 0xbd */
Jes Sorensen9e247722016-04-07 14:19:23 -0400807 u8 res3[1];
Jes Sorensen3307d842016-02-29 17:03:59 -0500808 u8 lna_type_5g; /* 0xbf */
Jes Sorensen9e247722016-04-07 14:19:23 -0400809 u8 res4[1];
Jes Sorensen3307d842016-02-29 17:03:59 -0500810 u8 rf_board_option;
811 u8 rf_feature_option;
812 u8 rf_bt_setting;
813 u8 eeprom_version;
814 u8 eeprom_customer_id;
Jes Sorensen9e247722016-04-07 14:19:23 -0400815 u8 res5[3];
Jes Sorensen3307d842016-02-29 17:03:59 -0500816 u8 rf_antenna_option; /* 0xc9 */
Jes Sorensen9e247722016-04-07 14:19:23 -0400817 u8 res6[6];
Jes Sorensen3307d842016-02-29 17:03:59 -0500818 u8 vid; /* 0xd0 */
Jes Sorensen9e247722016-04-07 14:19:23 -0400819 u8 res7[1];
Jes Sorensen3307d842016-02-29 17:03:59 -0500820 u8 pid; /* 0xd2 */
Jes Sorensen9e247722016-04-07 14:19:23 -0400821 u8 res8[1];
Jes Sorensen3307d842016-02-29 17:03:59 -0500822 u8 usb_optional_function;
Jes Sorensen3307d842016-02-29 17:03:59 -0500823 u8 res9[2];
Jes Sorensen9e247722016-04-07 14:19:23 -0400824 u8 mac_addr[ETH_ALEN]; /* 0xd7 */
Jes Sorensen3307d842016-02-29 17:03:59 -0500825 u8 res10[2];
Jes Sorensen9e247722016-04-07 14:19:23 -0400826 u8 vendor_name[7];
827 u8 res11[2];
828 u8 device_name[0x0b]; /* 0xe8 */
829 u8 res12[2];
Jes Sorensen3307d842016-02-29 17:03:59 -0500830 u8 serial[0x0b]; /* 0xf5 */
Jes Sorensen9e247722016-04-07 14:19:23 -0400831 u8 res13[0x30];
Jes Sorensen3307d842016-02-29 17:03:59 -0500832 u8 unknown[0x0d]; /* 0x130 */
Jes Sorensen9e247722016-04-07 14:19:23 -0400833 u8 res14[0xc3];
Jes Sorensen3307d842016-02-29 17:03:59 -0500834};
835
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400836struct rtl8xxxu_reg8val {
837 u16 reg;
838 u8 val;
839};
840
841struct rtl8xxxu_reg32val {
842 u16 reg;
843 u32 val;
844};
845
846struct rtl8xxxu_rfregval {
847 u8 reg;
848 u32 val;
849};
850
851enum rtl8xxxu_rfpath {
852 RF_A = 0,
853 RF_B = 1,
854};
855
856struct rtl8xxxu_rfregs {
857 u16 hssiparm1;
858 u16 hssiparm2;
859 u16 lssiparm;
860 u16 hspiread;
861 u16 lssiread;
862 u16 rf_sw_ctrl;
863};
864
865#define H2C_MAX_MBOX 4
866#define H2C_EXT BIT(7)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400867#define H2C_JOIN_BSS_DISCONNECT 0
868#define H2C_JOIN_BSS_CONNECT 1
Jes Sorensend940c242016-02-29 17:04:22 -0500869
870/*
871 * H2C (firmware) commands differ between the older generation chips
872 * 8188[cr]u, 819[12]cu, and 8723au, and the more recent chips 8723bu,
873 * 8192[de]u, 8192eu, and 8812.
874 */
875enum h2c_cmd_8723a {
876 H2C_SET_POWER_MODE = 1,
877 H2C_JOIN_BSS_REPORT = 2,
878 H2C_SET_RSSI = 5,
879 H2C_SET_RATE_MASK = (6 | H2C_EXT),
880};
881
882enum h2c_cmd_8723b {
883 /*
884 * Common Class: 000
885 */
886 H2C_8723B_RSVD_PAGE = 0x00,
887 H2C_8723B_MEDIA_STATUS_RPT = 0x01,
888 H2C_8723B_SCAN_ENABLE = 0x02,
889 H2C_8723B_KEEP_ALIVE = 0x03,
890 H2C_8723B_DISCON_DECISION = 0x04,
891 H2C_8723B_PSD_OFFLOAD = 0x05,
892 H2C_8723B_AP_OFFLOAD = 0x08,
893 H2C_8723B_BCN_RSVDPAGE = 0x09,
894 H2C_8723B_PROBERSP_RSVDPAGE = 0x0A,
895 H2C_8723B_FCS_RSVDPAGE = 0x10,
896 H2C_8723B_FCS_INFO = 0x11,
897 H2C_8723B_AP_WOW_GPIO_CTRL = 0x13,
898
899 /*
900 * PoweSave Class: 001
901 */
902 H2C_8723B_SET_PWR_MODE = 0x20,
903 H2C_8723B_PS_TUNING_PARA = 0x21,
904 H2C_8723B_PS_TUNING_PARA2 = 0x22,
905 H2C_8723B_P2P_LPS_PARAM = 0x23,
906 H2C_8723B_P2P_PS_OFFLOAD = 0x24,
907 H2C_8723B_PS_SCAN_ENABLE = 0x25,
908 H2C_8723B_SAP_PS_ = 0x26,
909 H2C_8723B_INACTIVE_PS_ = 0x27,
910 H2C_8723B_FWLPS_IN_IPS_ = 0x28,
911
912 /*
913 * Dynamic Mechanism Class: 010
914 */
Jes Sorensen80b30b22016-02-29 17:05:37 -0500915 H2C_8723B_MACID_CFG_RAID = 0x40,
Jes Sorensend940c242016-02-29 17:04:22 -0500916 H2C_8723B_TXBF = 0x41,
917 H2C_8723B_RSSI_SETTING = 0x42,
918 H2C_8723B_AP_REQ_TXRPT = 0x43,
919 H2C_8723B_INIT_RATE_COLLECT = 0x44,
920
921 /*
922 * BT Class: 011
923 */
924 H2C_8723B_B_TYPE_TDMA = 0x60,
925 H2C_8723B_BT_INFO = 0x61,
926 H2C_8723B_FORCE_BT_TXPWR = 0x62,
927 H2C_8723B_BT_IGNORE_WLANACT = 0x63,
928 H2C_8723B_DAC_SWING_VALUE = 0x64,
929 H2C_8723B_ANT_SEL_RSV = 0x65,
930 H2C_8723B_WL_OPMODE = 0x66,
931 H2C_8723B_BT_MP_OPER = 0x67,
932 H2C_8723B_BT_CONTROL = 0x68,
933 H2C_8723B_BT_WIFI_CTRL = 0x69,
Jes Sorensenf37e9222016-02-29 17:04:41 -0500934 H2C_8723B_BT_FW_PATCH = 0x6a,
935 H2C_8723B_BT_WLAN_CALIBRATION = 0x6d,
936 H2C_8723B_BT_GRANT = 0x6e,
Jes Sorensend940c242016-02-29 17:04:22 -0500937
938 /*
939 * WOWLAN Class: 100
940 */
941 H2C_8723B_WOWLAN = 0x80,
942 H2C_8723B_REMOTE_WAKE_CTRL = 0x81,
943 H2C_8723B_AOAC_GLOBAL_INFO = 0x82,
944 H2C_8723B_AOAC_RSVD_PAGE = 0x83,
945 H2C_8723B_AOAC_RSVD_PAGE2 = 0x84,
946 H2C_8723B_D0_SCAN_OFFLOAD_CTRL = 0x85,
947 H2C_8723B_D0_SCAN_OFFLOAD_INFO = 0x86,
948 H2C_8723B_CHNL_SWITCH_OFFLOAD = 0x87,
949
950 H2C_8723B_RESET_TSF = 0xC0,
951};
952
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400953
954struct h2c_cmd {
955 union {
956 struct {
957 u8 cmd;
Jes Sorensened35d092016-02-29 17:04:19 -0500958 u8 data[7];
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400959 } __packed cmd;
960 struct {
961 __le32 data;
962 __le16 ext;
963 } __packed raw;
964 struct {
Jes Sorensened35d092016-02-29 17:04:19 -0500965 __le32 data;
966 __le32 ext;
967 } __packed raw_wide;
968 struct {
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400969 u8 cmd;
970 u8 data;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400971 } __packed joinbss;
972 struct {
973 u8 cmd;
974 __le16 mask_hi;
975 u8 arg;
976 __le16 mask_lo;
977 } __packed ramask;
Jes Sorensenc7a5a192016-02-29 17:04:30 -0500978 struct {
979 u8 cmd;
Jes Sorensen7d794ea2016-02-29 17:05:39 -0500980 u8 parm;
981 u8 macid;
982 u8 macid_end;
983 } __packed media_status_rpt;
984 struct {
985 u8 cmd;
Jes Sorensenf653e692016-02-29 17:05:38 -0500986 u8 macid;
987 /*
988 * [0:4] - RAID
989 * [7] - SGI
990 */
Jes Sorensen3ca7b322016-02-29 17:04:43 -0500991 u8 data1;
Jes Sorensenf653e692016-02-29 17:05:38 -0500992 /*
993 * [0:1] - Bandwidth
994 * [3] - No Update
995 * [4:5] - VHT enable
996 * [6] - DISPT
997 * [7] - DISRA
998 */
Jes Sorensen3ca7b322016-02-29 17:04:43 -0500999 u8 data2;
Jes Sorensenf653e692016-02-29 17:05:38 -05001000 u8 ramask0;
Jes Sorensen80b30b22016-02-29 17:05:37 -05001001 u8 ramask1;
1002 u8 ramask2;
1003 u8 ramask3;
Jes Sorensen80b30b22016-02-29 17:05:37 -05001004 } __packed b_macid_cfg;
1005 struct {
1006 u8 cmd;
1007 u8 data1;
1008 u8 data2;
Jes Sorensen3ca7b322016-02-29 17:04:43 -05001009 u8 data3;
1010 u8 data4;
1011 u8 data5;
1012 } __packed b_type_dma;
1013 struct {
1014 u8 cmd;
Jes Sorensen6b9eae02016-02-29 17:04:50 -05001015 u8 data;
1016 } __packed bt_info;
1017 struct {
1018 u8 cmd;
Jes Sorensen394f1bd2016-02-29 17:04:49 -05001019 u8 operreq;
1020 u8 opcode;
1021 u8 data;
1022 u8 addr;
1023 } __packed bt_mp_oper;
1024 struct {
1025 u8 cmd;
Jes Sorensenc7a5a192016-02-29 17:04:30 -05001026 u8 data;
1027 } __packed bt_wlan_calibration;
Jes Sorensenf37e9222016-02-29 17:04:41 -05001028 struct {
1029 u8 cmd;
Jes Sorensen7297f492016-02-29 17:04:44 -05001030 u8 data;
1031 } __packed ignore_wlan;
1032 struct {
1033 u8 cmd;
Jes Sorensenf37e9222016-02-29 17:04:41 -05001034 u8 ant_inverse;
1035 u8 int_switch_type;
1036 } __packed ant_sel_rsv;
1037 struct {
1038 u8 cmd;
1039 u8 data;
1040 } __packed bt_grant;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001041 };
1042};
1043
Jes Sorensenb2b43b72016-02-29 17:04:48 -05001044enum c2h_evt_8723b {
1045 C2H_8723B_DEBUG = 0,
1046 C2H_8723B_TSF = 1,
1047 C2H_8723B_AP_RPT_RSP = 2,
1048 C2H_8723B_CCX_TX_RPT = 3,
1049 C2H_8723B_BT_RSSI = 4,
1050 C2H_8723B_BT_OP_MODE = 5,
1051 C2H_8723B_EXT_RA_RPT = 6,
1052 C2H_8723B_BT_INFO = 9,
Jes Sorensen394f1bd2016-02-29 17:04:49 -05001053 C2H_8723B_HW_INFO_EXCH = 0x0a,
1054 C2H_8723B_BT_MP_INFO = 0x0b,
Jes Sorensen55a18dd2016-02-29 17:05:41 -05001055 C2H_8723B_RA_REPORT = 0x0c,
Jes Sorensenb2b43b72016-02-29 17:04:48 -05001056 C2H_8723B_FW_DEBUG = 0xff,
1057};
1058
1059enum bt_info_src_8723b {
1060 BT_INFO_SRC_8723B_WIFI_FW = 0x0,
1061 BT_INFO_SRC_8723B_BT_RSP = 0x1,
1062 BT_INFO_SRC_8723B_BT_ACTIVE_SEND = 0x2,
1063};
1064
Jes Sorensen394f1bd2016-02-29 17:04:49 -05001065enum bt_mp_oper_opcode_8723b {
1066 BT_MP_OP_GET_BT_VERSION = 0x00,
1067 BT_MP_OP_RESET = 0x01,
1068 BT_MP_OP_TEST_CTRL = 0x02,
1069 BT_MP_OP_SET_BT_MODE = 0x03,
1070 BT_MP_OP_SET_CHNL_TX_GAIN = 0x04,
1071 BT_MP_OP_SET_PKT_TYPE_LEN = 0x05,
1072 BT_MP_OP_SET_PKT_CNT_L_PL_TYPE = 0x06,
1073 BT_MP_OP_SET_PKT_CNT_H_PKT_INTV = 0x07,
1074 BT_MP_OP_SET_PKT_HEADER = 0x08,
1075 BT_MP_OP_SET_WHITENCOEFF = 0x09,
1076 BT_MP_OP_SET_BD_ADDR_L = 0x0a,
1077 BT_MP_OP_SET_BD_ADDR_H = 0x0b,
1078 BT_MP_OP_WRITE_REG_ADDR = 0x0c,
1079 BT_MP_OP_WRITE_REG_VALUE = 0x0d,
1080 BT_MP_OP_GET_BT_STATUS = 0x0e,
1081 BT_MP_OP_GET_BD_ADDR_L = 0x0f,
1082 BT_MP_OP_GET_BD_ADDR_H = 0x10,
1083 BT_MP_OP_READ_REG = 0x11,
1084 BT_MP_OP_SET_TARGET_BD_ADDR_L = 0x12,
1085 BT_MP_OP_SET_TARGET_BD_ADDR_H = 0x13,
1086 BT_MP_OP_SET_TX_POWER_CALIBRATION = 0x14,
1087 BT_MP_OP_GET_RX_PKT_CNT_L = 0x15,
1088 BT_MP_OP_GET_RX_PKT_CNT_H = 0x16,
1089 BT_MP_OP_GET_RX_ERROR_BITS_L = 0x17,
1090 BT_MP_OP_GET_RX_ERROR_BITS_H = 0x18,
1091 BT_MP_OP_GET_RSSI = 0x19,
1092 BT_MP_OP_GET_CFO_HDR_QUALITY_L = 0x1a,
1093 BT_MP_OP_GET_CFO_HDR_QUALITY_H = 0x1b,
1094 BT_MP_OP_GET_TARGET_BD_ADDR_L = 0x1c,
1095 BT_MP_OP_GET_TARGET_BD_ADDR_H = 0x1d,
1096 BT_MP_OP_GET_AFH_MAP_L = 0x1e,
1097 BT_MP_OP_GET_AFH_MAP_M = 0x1f,
1098 BT_MP_OP_GET_AFH_MAP_H = 0x20,
1099 BT_MP_OP_GET_AFH_STATUS = 0x21,
1100 BT_MP_OP_SET_TRACKING_INTERVAL = 0x22,
1101 BT_MP_OP_SET_THERMAL_METER = 0x23,
1102 BT_MP_OP_ENABLE_CFO_TRACKING = 0x24,
1103};
1104
Jes Sorensenb2b43b72016-02-29 17:04:48 -05001105struct rtl8723bu_c2h {
1106 u8 id;
1107 u8 seq;
1108 union {
1109 struct {
1110 u8 payload[0];
1111 } __packed raw;
1112 struct {
Jes Sorensen394f1bd2016-02-29 17:04:49 -05001113 u8 ext_id;
1114 u8 status:4;
1115 u8 retlen:4;
1116 u8 opcode_ver:4;
1117 u8 req_num:4;
1118 u8 payload[2];
1119 } __packed bt_mp_info;
1120 struct {
Jes Sorensenb2b43b72016-02-29 17:04:48 -05001121 u8 response_source:4;
1122 u8 dummy0_0:4;
1123
1124 u8 bt_info;
1125
1126 u8 retry_count:4;
1127 u8 dummy2_0:1;
1128 u8 bt_page:1;
1129 u8 tx_rx_mask:1;
1130 u8 dummy2_2:1;
1131
1132 u8 rssi;
1133
1134 u8 basic_rate:1;
1135 u8 bt_has_reset:1;
1136 u8 dummy4_1:1;;
1137 u8 ignore_wlan:1;
1138 u8 auto_report:1;
1139 u8 dummy4_2:3;
1140
1141 u8 a4;
1142 u8 a5;
1143 } __packed bt_info;
Jes Sorensen55a18dd2016-02-29 17:05:41 -05001144 struct {
1145 u8 rate:7;
1146 u8 dummy0_0:1;
1147 u8 macid;
1148 u8 ldpc:1;
1149 u8 txbf:1;
1150 u8 noisy_state:1;
1151 u8 dummy2_0:5;
1152 u8 dummy3_0;
1153 } __packed ra_report;
Jes Sorensenb2b43b72016-02-29 17:04:48 -05001154 };
1155};
1156
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001157struct rtl8xxxu_fileops;
1158
1159struct rtl8xxxu_priv {
1160 struct ieee80211_hw *hw;
1161 struct usb_device *udev;
1162 struct rtl8xxxu_fileops *fops;
1163
1164 spinlock_t tx_urb_lock;
1165 struct list_head tx_urb_free_list;
1166 int tx_urb_free_count;
1167 bool tx_stopped;
1168
1169 spinlock_t rx_urb_lock;
1170 struct list_head rx_urb_pending_list;
1171 int rx_urb_pending_count;
1172 bool shutdown;
1173 struct work_struct rx_urb_wq;
1174
1175 u8 mac_addr[ETH_ALEN];
1176 char chip_name[8];
Jes Sorensen0e5d4352016-02-29 17:04:00 -05001177 char chip_vendor[8];
Jes Sorensen21db9972016-02-29 17:05:21 -05001178 u8 cck_tx_power_index_A[RTL8XXXU_MAX_CHANNEL_GROUPS];
1179 u8 cck_tx_power_index_B[RTL8XXXU_MAX_CHANNEL_GROUPS];
1180 u8 ht40_1s_tx_power_index_A[RTL8XXXU_MAX_CHANNEL_GROUPS];
1181 u8 ht40_1s_tx_power_index_B[RTL8XXXU_MAX_CHANNEL_GROUPS];
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001182 /*
1183 * The following entries are half-bytes split as:
1184 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
1185 */
Jes Sorensen21db9972016-02-29 17:05:21 -05001186 struct rtl8723au_idx ht40_2s_tx_power_index_diff[
Jes Sorensen3be26992016-02-29 17:05:22 -05001187 RTL8723A_CHANNEL_GROUPS];
1188 struct rtl8723au_idx ht20_tx_power_index_diff[RTL8723A_CHANNEL_GROUPS];
1189 struct rtl8723au_idx ofdm_tx_power_index_diff[RTL8723A_CHANNEL_GROUPS];
1190 struct rtl8723au_idx ht40_max_power_offset[RTL8723A_CHANNEL_GROUPS];
1191 struct rtl8723au_idx ht20_max_power_offset[RTL8723A_CHANNEL_GROUPS];
1192 /*
1193 * Newer generation chips only keep power diffs per TX count,
1194 * not per channel group.
1195 */
1196 struct rtl8723au_idx ofdm_tx_power_diff[RTL8723B_TX_COUNT];
1197 struct rtl8723au_idx ht20_tx_power_diff[RTL8723B_TX_COUNT];
1198 struct rtl8723au_idx ht40_tx_power_diff[RTL8723B_TX_COUNT];
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001199 u32 chip_cut:4;
1200 u32 rom_rev:4;
Jakub Sitnicki38451992016-02-03 13:39:49 -05001201 u32 is_multi_func:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001202 u32 has_wifi:1;
1203 u32 has_bluetooth:1;
1204 u32 enable_bluetooth:1;
1205 u32 has_gps:1;
1206 u32 hi_pa:1;
1207 u32 vendor_umc:1;
Jes Sorensen0e5d4352016-02-29 17:04:00 -05001208 u32 vendor_smic:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001209 u32 has_polarity_ctrl:1;
1210 u32 has_eeprom:1;
1211 u32 boot_eeprom:1;
Jes Sorensen0e28b972016-02-29 17:04:13 -05001212 u32 usb_interrupts:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001213 u32 ep_tx_high_queue:1;
1214 u32 ep_tx_normal_queue:1;
1215 u32 ep_tx_low_queue:1;
Jes Sorensen4ef22eb2016-02-29 17:04:55 -05001216 u32 has_xtalk:1;
1217 u8 xtalk;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001218 unsigned int pipe_interrupt;
1219 unsigned int pipe_in;
1220 unsigned int pipe_out[TXDESC_QUEUE_MAX];
1221 u8 out_ep[RTL8XXXU_OUT_ENDPOINTS];
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001222 u8 ep_tx_count;
1223 u8 rf_paths;
1224 u8 rx_paths;
1225 u8 tx_paths;
1226 u32 rf_mode_ag[2];
1227 u32 rege94;
1228 u32 rege9c;
1229 u32 regeb4;
1230 u32 regebc;
1231 int next_mbox;
1232 int nr_out_eps;
1233
1234 struct mutex h2c_mutex;
1235
1236 struct usb_anchor rx_anchor;
1237 struct usb_anchor tx_anchor;
1238 struct usb_anchor int_anchor;
1239 struct rtl8xxxu_firmware_header *fw_data;
1240 size_t fw_size;
1241 struct mutex usb_buf_mutex;
1242 union {
1243 __le32 val32;
1244 __le16 val16;
1245 u8 val8;
1246 } usb_buf;
1247 union {
Jes Sorensen3307d842016-02-29 17:03:59 -05001248 u8 raw[EFUSE_MAP_LEN];
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001249 struct rtl8723au_efuse efuse8723;
Jes Sorensen3c836d62016-02-29 17:04:11 -05001250 struct rtl8723bu_efuse efuse8723bu;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001251 struct rtl8192cu_efuse efuse8192;
Jes Sorensen3307d842016-02-29 17:03:59 -05001252 struct rtl8192eu_efuse efuse8192eu;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001253 } efuse_wifi;
1254 u32 adda_backup[RTL8XXXU_ADDA_REGS];
1255 u32 mac_backup[RTL8XXXU_MAC_REGS];
1256 u32 bb_backup[RTL8XXXU_BB_REGS];
1257 u32 bb_recovery_backup[RTL8XXXU_BB_REGS];
Jes Sorensenba17d822016-03-31 17:08:39 -04001258 enum rtl8xxxu_rtl_chip rtl_chip;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001259 u8 pi_enabled:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001260 u8 int_buf[USB_INTR_CONTENT_LENGTH];
1261};
1262
1263struct rtl8xxxu_rx_urb {
1264 struct urb urb;
1265 struct ieee80211_hw *hw;
1266 struct list_head list;
1267};
1268
1269struct rtl8xxxu_tx_urb {
1270 struct urb urb;
1271 struct ieee80211_hw *hw;
1272 struct list_head list;
1273};
1274
1275struct rtl8xxxu_fileops {
1276 int (*parse_efuse) (struct rtl8xxxu_priv *priv);
1277 int (*load_firmware) (struct rtl8xxxu_priv *priv);
1278 int (*power_on) (struct rtl8xxxu_priv *priv);
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05001279 void (*power_off) (struct rtl8xxxu_priv *priv);
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05001280 void (*reset_8051) (struct rtl8xxxu_priv *priv);
Jes Sorensen74b99be2016-02-29 17:04:04 -05001281 int (*llt_init) (struct rtl8xxxu_priv *priv, u8 last_tx_page);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05001282 void (*phy_init_antenna_selection) (struct rtl8xxxu_priv *priv);
Jes Sorensene1547c52016-02-29 17:04:35 -05001283 void (*phy_iq_calibrate) (struct rtl8xxxu_priv *priv);
Jes Sorensenc3f95062016-02-29 17:04:40 -05001284 void (*config_channel) (struct ieee80211_hw *hw);
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05001285 int (*parse_rx_desc) (struct rtl8xxxu_priv *priv, struct sk_buff *skb,
1286 struct ieee80211_rx_status *rx_status);
Jes Sorensen3e88ca42016-02-29 17:05:08 -05001287 void (*init_aggregation) (struct rtl8xxxu_priv *priv);
Jes Sorensen9c79bf92016-02-29 17:05:10 -05001288 void (*init_statistics) (struct rtl8xxxu_priv *priv);
Jes Sorensendb08de92016-02-29 17:05:17 -05001289 void (*enable_rf) (struct rtl8xxxu_priv *priv);
Jes Sorensenfc89a412016-02-29 17:05:46 -05001290 void (*disable_rf) (struct rtl8xxxu_priv *priv);
Jes Sorensene796dab2016-02-29 17:05:19 -05001291 void (*set_tx_power) (struct rtl8xxxu_priv *priv, int channel,
1292 bool ht40);
Jes Sorensenf653e692016-02-29 17:05:38 -05001293 void (*update_rate_mask) (struct rtl8xxxu_priv *priv,
1294 u32 ramask, int sgi);
Jes Sorensen7d794ea2016-02-29 17:05:39 -05001295 void (*report_connect) (struct rtl8xxxu_priv *priv,
1296 u8 macid, bool connect);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001297 int writeN_block_size;
Jes Sorensened35d092016-02-29 17:04:19 -05001298 u16 mbox_ext_reg;
1299 char mbox_ext_width;
Jes Sorensen179e1742016-02-29 17:05:27 -05001300 char tx_desc_size;
Jes Sorensen0d698de2016-02-29 17:04:36 -05001301 char has_s0s1;
Jes Sorensen8634af52016-02-29 17:04:33 -05001302 u32 adda_1t_init;
1303 u32 adda_1t_path_on;
1304 u32 adda_2t_path_on_a;
1305 u32 adda_2t_path_on_b;
Jes Sorensenc606e662016-04-07 14:19:16 -04001306 struct rtl8xxxu_reg8val *mactable;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001307};