blob: 3efbb6042ca2cd590fa660a104c7d2a6117ad251 [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
Jes Sorensen89c2a092016-04-14 14:58:44 -040052#define TX_PAGE_NUM_PUBQ_8192E 0xe7
53#define TX_PAGE_NUM_HI_PQ_8192E 0x08
54#define TX_PAGE_NUM_LO_PQ_8192E 0x0c
55#define TX_PAGE_NUM_NORM_PQ_8192E 0x00
56
Jes Sorensen26f1fad2015-10-14 20:44:51 -040057#define RTL_FW_PAGE_SIZE 4096
58#define RTL8XXXU_FIRMWARE_POLL_MAX 1000
59
60#define RTL8723A_CHANNEL_GROUPS 3
61#define RTL8723A_MAX_RF_PATHS 2
Jes Sorensen21db9972016-02-29 17:05:21 -050062#define RTL8723B_CHANNEL_GROUPS 6
Jes Sorensen3be26992016-02-29 17:05:22 -050063#define RTL8723B_TX_COUNT 4
Jes Sorensen4a0d7db2016-02-29 17:05:18 -050064#define RTL8723B_MAX_RF_PATHS 4
Jes Sorensen21db9972016-02-29 17:05:21 -050065#define RTL8XXXU_MAX_CHANNEL_GROUPS 6
Jes Sorensen26f1fad2015-10-14 20:44:51 -040066#define RF6052_MAX_TX_PWR 0x3f
67
Jes Sorensen3307d842016-02-29 17:03:59 -050068#define EFUSE_MAP_LEN 512
69#define EFUSE_MAX_SECTION_8723A 64
Jes Sorensen26f1fad2015-10-14 20:44:51 -040070#define EFUSE_REAL_CONTENT_LEN_8723A 512
71#define EFUSE_BT_MAP_LEN_8723A 1024
72#define EFUSE_MAX_WORD_UNIT 4
73
Jes Sorensenba17d822016-03-31 17:08:39 -040074enum rtl8xxxu_rtl_chip {
75 RTL8192S = 0x81920,
76 RTL8191S = 0x81910,
77 RTL8192C = 0x8192c,
78 RTL8191C = 0x8191c,
79 RTL8188C = 0x8188c,
80 RTL8188R = 0x81889,
81 RTL8192D = 0x8192d,
82 RTL8723A = 0x8723a,
83 RTL8188E = 0x8188e,
84 RTL8812 = 0x88120,
85 RTL8821 = 0x88210,
86 RTL8192E = 0x8192e,
87 RTL8191E = 0x8191e,
88 RTL8723B = 0x8723b,
89 RTL8814A = 0x8814a,
90 RTL8881A = 0x8881a,
91 RTL8821B = 0x8821b,
92 RTL8822B = 0x8822b,
93 RTL8703B = 0x8703b,
94 RTL8195A = 0x8195a,
95 RTL8188F = 0x8188f
96};
97
Jes Sorensenb18cdfd2016-02-29 17:04:47 -050098enum rtl8xxxu_rx_type {
99 RX_TYPE_DATA_PKT = 0,
100 RX_TYPE_C2H = 1,
101 RX_TYPE_ERROR = -1
102};
103
Jes Sorensena49c7ce2016-04-14 14:58:52 -0400104struct rtl8xxxu_rxdesc16 {
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400105#ifdef __LITTLE_ENDIAN
106 u32 pktlen:14;
107 u32 crc32:1;
108 u32 icverr:1;
109 u32 drvinfo_sz:4;
110 u32 security:3;
111 u32 qos:1;
112 u32 shift:2;
113 u32 phy_stats:1;
114 u32 swdec:1;
115 u32 ls:1;
116 u32 fs:1;
117 u32 eor:1;
118 u32 own:1;
119
120 u32 macid:5;
121 u32 tid:4;
122 u32 hwrsvd:4;
123 u32 amsdu:1;
124 u32 paggr:1;
125 u32 faggr:1;
126 u32 a1fit:4;
127 u32 a2fit:4;
128 u32 pam:1;
129 u32 pwr:1;
130 u32 md:1;
131 u32 mf:1;
132 u32 type:2;
133 u32 mc:1;
134 u32 bc:1;
135
136 u32 seq:12;
137 u32 frag:4;
138 u32 nextpktlen:14;
139 u32 nextind:1;
140 u32 reserved0:1;
141
142 u32 rxmcs:6;
143 u32 rxht:1;
144 u32 gf:1;
145 u32 splcp:1;
146 u32 bw:1;
147 u32 htc:1;
148 u32 eosp:1;
149 u32 bssidfit:2;
150 u32 reserved1:16;
151 u32 unicastwake:1;
152 u32 magicwake:1;
153
154 u32 pattern0match:1;
155 u32 pattern1match:1;
156 u32 pattern2match:1;
157 u32 pattern3match:1;
158 u32 pattern4match:1;
159 u32 pattern5match:1;
160 u32 pattern6match:1;
161 u32 pattern7match:1;
162 u32 pattern8match:1;
163 u32 pattern9match:1;
164 u32 patternamatch:1;
165 u32 patternbmatch:1;
166 u32 patterncmatch:1;
167 u32 reserved2:19;
168#else
169 u32 own:1;
170 u32 eor:1;
171 u32 fs:1;
172 u32 ls:1;
173 u32 swdec:1;
174 u32 phy_stats:1;
175 u32 shift:2;
176 u32 qos:1;
177 u32 security:3;
178 u32 drvinfo_sz:4;
179 u32 icverr:1;
180 u32 crc32:1;
181 u32 pktlen:14;
182
183 u32 bc:1;
184 u32 mc:1;
185 u32 type:2;
186 u32 mf:1;
187 u32 md:1;
188 u32 pwr:1;
189 u32 pam:1;
190 u32 a2fit:4;
191 u32 a1fit:4;
192 u32 faggr:1;
193 u32 paggr:1;
194 u32 amsdu:1;
195 u32 hwrsvd:4;
196 u32 tid:4;
197 u32 macid:5;
198
199 u32 reserved0:1;
200 u32 nextind:1;
201 u32 nextpktlen:14;
202 u32 frag:4;
203 u32 seq:12;
204
205 u32 magicwake:1;
206 u32 unicastwake:1;
207 u32 reserved1:16;
208 u32 bssidfit:2;
209 u32 eosp:1;
210 u32 htc:1;
211 u32 bw:1;
212 u32 splcp:1;
213 u32 gf:1;
214 u32 rxht:1;
215 u32 rxmcs:6;
216
217 u32 reserved2:19;
218 u32 patterncmatch:1;
219 u32 patternbmatch:1;
220 u32 patternamatch:1;
221 u32 pattern9match:1;
222 u32 pattern8match:1;
223 u32 pattern7match:1;
224 u32 pattern6match:1;
225 u32 pattern5match:1;
226 u32 pattern4match:1;
227 u32 pattern3match:1;
228 u32 pattern2match:1;
229 u32 pattern1match:1;
230 u32 pattern0match:1;
231#endif
232 __le32 tsfl;
233#if 0
234 u32 bassn:12;
235 u32 bavld:1;
236 u32 reserved3:19;
237#endif
238};
239
Jes Sorensena49c7ce2016-04-14 14:58:52 -0400240struct rtl8xxxu_rxdesc24 {
Jes Sorensena6c80d22016-02-29 17:04:46 -0500241#ifdef __LITTLE_ENDIAN
242 u32 pktlen:14;
243 u32 crc32:1;
244 u32 icverr:1;
245 u32 drvinfo_sz:4;
246 u32 security:3;
247 u32 qos:1;
248 u32 shift:2;
249 u32 phy_stats:1;
250 u32 swdec:1;
251 u32 ls:1;
252 u32 fs:1;
253 u32 eor:1;
254 u32 own:1;
255
256 u32 macid:7;
257 u32 dummy1_0:1;
258 u32 tid:4;
259 u32 dummy1_1:1;
260 u32 amsdu:1;
261 u32 rxid_match:1;
262 u32 paggr:1;
263 u32 a1fit:4; /* 16 */
264 u32 chkerr:1;
265 u32 ipver:1;
266 u32 tcpudp:1;
267 u32 chkvld:1;
268 u32 pam:1;
269 u32 pwr:1;
270 u32 more_data:1;
271 u32 more_frag:1;
272 u32 type:2;
273 u32 mc:1;
274 u32 bc:1;
275
276 u32 seq:12;
277 u32 frag:4;
278 u32 rx_is_qos:1; /* 16 */
279 u32 dummy2_0:1;
280 u32 wlanhd_iv_len:6;
281 u32 dummy2_1:4;
282 u32 rpt_sel:1;
283 u32 dummy2_2:3;
284
285 u32 rxmcs:7;
286 u32 dummy3_0:3;
287 u32 htc:1;
288 u32 eosp:1;
289 u32 bssidfit:2;
290 u32 dummy3_1:2;
291 u32 usb_agg_pktnum:8; /* 16 */
292 u32 dummy3_2:5;
293 u32 pattern_match:1;
294 u32 unicast_match:1;
295 u32 magic_match:1;
296
297 u32 splcp:1;
298 u32 ldcp:1;
299 u32 stbc:1;
300 u32 dummy4_0:1;
301 u32 bw:2;
302 u32 dummy4_1:26;
303#else
304 u32 own:1;
305 u32 eor:1;
306 u32 fs:1;
307 u32 ls:1;
308 u32 swdec:1;
309 u32 phy_stats:1;
310 u32 shift:2;
311 u32 qos:1;
312 u32 security:3;
313 u32 drvinfo_sz:4;
314 u32 icverr:1;
315 u32 crc32:1;
316 u32 pktlen:14;
317
318 u32 bc:1;
319 u32 mc:1;
320 u32 type:2;
321 u32 mf:1;
322 u32 md:1;
323 u32 pwr:1;
324 u32 pam:1;
325 u32 a2fit:4;
326 u32 a1fit:4;
327 u32 faggr:1;
328 u32 paggr:1;
329 u32 amsdu:1;
330 u32 hwrsvd:4;
331 u32 tid:4;
332 u32 macid:5;
333
334 u32 dummy2_2:3;
335 u32 rpt_sel:1;
336 u32 dummy2_1:4;
337 u32 wlanhd_iv_len:6;
338 u32 dummy2_0:1;
339 u32 rx_is_qos:1;
340 u32 frag:4; /* 16 */
341 u32 seq:12;
342
343 u32 magic_match:1;
344 u32 unicast_match:1;
345 u32 pattern_match:1;
346 u32 dummy3_2:5;
347 u32 usb_agg_pktnum:8;
348 u32 dummy3_1:2; /* 16 */
349 u32 bssidfit:2;
350 u32 eosp:1;
351 u32 htc:1;
352 u32 dummy3_0:3;
353 u32 rxmcs:7;
354
355 u32 dumm4_1:26;
356 u32 bw:2;
357 u32 dummy4_0:1;
358 u32 stbc:1;
359 u32 ldcp:1;
360 u32 splcp:1;
361#endif
362 __le32 tsfl;
363};
364
Jes Sorensendbb28962016-03-31 17:08:33 -0400365struct rtl8xxxu_txdesc32 {
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400366 __le16 pkt_size;
367 u8 pkt_offset;
368 u8 txdw0;
369 __le32 txdw1;
370 __le32 txdw2;
371 __le32 txdw3;
372 __le32 txdw4;
373 __le32 txdw5;
374 __le32 txdw6;
375 __le16 csum;
376 __le16 txdw7;
377};
378
Jes Sorensendbb28962016-03-31 17:08:33 -0400379struct rtl8xxxu_txdesc40 {
Jes Sorensen80491a12016-02-29 17:05:26 -0500380 __le16 pkt_size;
381 u8 pkt_offset;
382 u8 txdw0;
383 __le32 txdw1;
384 __le32 txdw2;
385 __le32 txdw3;
386 __le32 txdw4;
387 __le32 txdw5;
388 __le32 txdw6;
389 __le16 csum;
390 __le16 txdw7;
391 __le32 txdw8;
392 __le32 txdw9;
393};
394
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400395/* CCK Rates, TxHT = 0 */
396#define DESC_RATE_1M 0x00
397#define DESC_RATE_2M 0x01
398#define DESC_RATE_5_5M 0x02
399#define DESC_RATE_11M 0x03
400
401/* OFDM Rates, TxHT = 0 */
402#define DESC_RATE_6M 0x04
403#define DESC_RATE_9M 0x05
404#define DESC_RATE_12M 0x06
405#define DESC_RATE_18M 0x07
406#define DESC_RATE_24M 0x08
407#define DESC_RATE_36M 0x09
408#define DESC_RATE_48M 0x0a
409#define DESC_RATE_54M 0x0b
410
411/* MCS Rates, TxHT = 1 */
412#define DESC_RATE_MCS0 0x0c
413#define DESC_RATE_MCS1 0x0d
414#define DESC_RATE_MCS2 0x0e
415#define DESC_RATE_MCS3 0x0f
416#define DESC_RATE_MCS4 0x10
417#define DESC_RATE_MCS5 0x11
418#define DESC_RATE_MCS6 0x12
419#define DESC_RATE_MCS7 0x13
420#define DESC_RATE_MCS8 0x14
421#define DESC_RATE_MCS9 0x15
422#define DESC_RATE_MCS10 0x16
423#define DESC_RATE_MCS11 0x17
424#define DESC_RATE_MCS12 0x18
425#define DESC_RATE_MCS13 0x19
426#define DESC_RATE_MCS14 0x1a
427#define DESC_RATE_MCS15 0x1b
428#define DESC_RATE_MCS15_SG 0x1c
429#define DESC_RATE_MCS32 0x20
430
431#define TXDESC_OFFSET_SZ 0
432#define TXDESC_OFFSET_SHT 16
433#if 0
434#define TXDESC_BMC BIT(24)
435#define TXDESC_LSG BIT(26)
436#define TXDESC_FSG BIT(27)
437#define TXDESC_OWN BIT(31)
438#else
439#define TXDESC_BROADMULTICAST BIT(0)
Jes Sorensen02492582016-02-29 17:05:29 -0500440#define TXDESC_HTC BIT(1)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400441#define TXDESC_LAST_SEGMENT BIT(2)
442#define TXDESC_FIRST_SEGMENT BIT(3)
Jes Sorensen02492582016-02-29 17:05:29 -0500443#define TXDESC_LINIP BIT(4)
444#define TXDESC_NO_ACM BIT(5)
445#define TXDESC_GF BIT(6)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400446#define TXDESC_OWN BIT(7)
447#endif
448
449/* Word 1 */
Jes Sorensence2d1db2016-02-29 17:05:30 -0500450/*
451 * Bits 0-7 differ dependent on chip generation. For 8723au bits 5/6 are
452 * aggregation enable and break respectively. For 8723bu, bits 0-7 are macid.
453 */
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400454#define TXDESC_PKT_OFFSET_SZ 0
Jes Sorensen33f37242016-03-31 17:08:34 -0400455#define TXDESC32_AGG_ENABLE BIT(5)
456#define TXDESC32_AGG_BREAK BIT(6)
457#define TXDESC40_MACID_SHIFT 0
458#define TXDESC40_MACID_MASK 0x00f0
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400459#define TXDESC_QUEUE_SHIFT 8
460#define TXDESC_QUEUE_MASK 0x1f00
461#define TXDESC_QUEUE_BK 0x2
462#define TXDESC_QUEUE_BE 0x0
463#define TXDESC_QUEUE_VI 0x5
464#define TXDESC_QUEUE_VO 0x7
465#define TXDESC_QUEUE_BEACON 0x10
466#define TXDESC_QUEUE_HIGH 0x11
467#define TXDESC_QUEUE_MGNT 0x12
468#define TXDESC_QUEUE_CMD 0x13
469#define TXDESC_QUEUE_MAX (TXDESC_QUEUE_CMD + 1)
Jes Sorensen33f37242016-03-31 17:08:34 -0400470#define TXDESC40_RDG_NAV_EXT BIT(13)
471#define TXDESC40_LSIG_TXOP_ENABLE BIT(14)
472#define TXDESC40_PIFS BIT(15)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400473
474#define DESC_RATE_ID_SHIFT 16
475#define DESC_RATE_ID_MASK 0xf
476#define TXDESC_NAVUSEHDR BIT(20)
477#define TXDESC_SEC_RC4 0x00400000
478#define TXDESC_SEC_AES 0x00c00000
479#define TXDESC_PKT_OFFSET_SHIFT 26
480#define TXDESC_AGG_EN BIT(29)
481#define TXDESC_HWPC BIT(31)
482
483/* Word 2 */
Jes Sorensen33f37242016-03-31 17:08:34 -0400484#define TXDESC40_PAID_SHIFT 0
485#define TXDESC40_PAID_MASK 0x1ff
486#define TXDESC40_CCA_RTS_SHIFT 10
487#define TXDESC40_CCA_RTS_MASK 0xc00
488#define TXDESC40_AGG_ENABLE BIT(12)
489#define TXDESC40_RDG_ENABLE BIT(13)
490#define TXDESC40_AGG_BREAK BIT(16)
491#define TXDESC40_MORE_FRAG BIT(17)
492#define TXDESC40_RAW BIT(18)
493#define TXDESC32_ACK_REPORT BIT(19)
494#define TXDESC40_SPE_RPT BIT(19)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400495#define TXDESC_AMPDU_DENSITY_SHIFT 20
Jes Sorensen33f37242016-03-31 17:08:34 -0400496#define TXDESC40_BT_INT BIT(23)
Jes Sorensen169bc5c2016-03-31 17:08:35 -0400497#define TXDESC40_GID_SHIFT 24
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400498
499/* Word 3 */
Jes Sorensen33f37242016-03-31 17:08:34 -0400500#define TXDESC40_USE_DRIVER_RATE BIT(8)
501#define TXDESC40_CTS_SELF_ENABLE BIT(11)
502#define TXDESC40_RTS_CTS_ENABLE BIT(12)
503#define TXDESC40_HW_RTS_ENABLE BIT(13)
504#define TXDESC32_SEQ_SHIFT 16
505#define TXDESC32_SEQ_MASK 0x0fff0000
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400506
507/* Word 4 */
Jes Sorensen33f37242016-03-31 17:08:34 -0400508#define TXDESC32_RTS_RATE_SHIFT 0
509#define TXDESC32_RTS_RATE_MASK 0x3f
510#define TXDESC32_QOS BIT(6)
511#define TXDESC32_HW_SEQ_ENABLE BIT(7)
512#define TXDESC32_USE_DRIVER_RATE BIT(8)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400513#define TXDESC_DISABLE_DATA_FB BIT(10)
Jes Sorensen33f37242016-03-31 17:08:34 -0400514#define TXDESC32_CTS_SELF_ENABLE BIT(11)
515#define TXDESC32_RTS_CTS_ENABLE BIT(12)
516#define TXDESC32_HW_RTS_ENABLE BIT(13)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400517#define TXDESC_PRIME_CH_OFF_LOWER BIT(20)
518#define TXDESC_PRIME_CH_OFF_UPPER BIT(21)
Jes Sorensen33f37242016-03-31 17:08:34 -0400519#define TXDESC32_SHORT_PREAMBLE BIT(24)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400520#define TXDESC_DATA_BW BIT(25)
521#define TXDESC_RTS_DATA_BW BIT(27)
522#define TXDESC_RTS_PRIME_CH_OFF_LOWER BIT(28)
523#define TXDESC_RTS_PRIME_CH_OFF_UPPER BIT(29)
Jes Sorensen33f37242016-03-31 17:08:34 -0400524#define TXDESC40_DATA_RATE_FB_SHIFT 8
525#define TXDESC40_DATA_RATE_FB_MASK 0x00001f00
526#define TXDESC40_RETRY_LIMIT_ENABLE BIT(17)
527#define TXDESC40_RETRY_LIMIT_SHIFT 18
528#define TXDESC40_RETRY_LIMIT_MASK 0x00fc0000
529#define TXDESC40_RTS_RATE_SHIFT 24
530#define TXDESC40_RTS_RATE_MASK 0x3f000000
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400531
532/* Word 5 */
Jes Sorensen33f37242016-03-31 17:08:34 -0400533#define TXDESC40_SHORT_PREAMBLE BIT(4)
Jes Sorensen1df1de32016-03-31 17:08:36 -0400534#define TXDESC32_SHORT_GI BIT(6)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400535#define TXDESC_CCX_TAG BIT(7)
Jes Sorensen33f37242016-03-31 17:08:34 -0400536#define TXDESC32_RETRY_LIMIT_ENABLE BIT(17)
537#define TXDESC32_RETRY_LIMIT_SHIFT 18
538#define TXDESC32_RETRY_LIMIT_MASK 0x00fc0000
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400539
540/* Word 6 */
541#define TXDESC_MAX_AGG_SHIFT 11
542
Jes Sorensen2098bfb2016-02-29 17:05:33 -0500543/* Word 8 */
Jes Sorensen33f37242016-03-31 17:08:34 -0400544#define TXDESC40_HW_SEQ_ENABLE BIT(15)
Jes Sorensen2098bfb2016-02-29 17:05:33 -0500545
Jes Sorensencc2646d2016-02-29 17:05:32 -0500546/* Word 9 */
Jes Sorensen33f37242016-03-31 17:08:34 -0400547#define TXDESC40_SEQ_SHIFT 12
548#define TXDESC40_SEQ_MASK 0x00fff000
Jes Sorensencc2646d2016-02-29 17:05:32 -0500549
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400550struct phy_rx_agc_info {
551#ifdef __LITTLE_ENDIAN
552 u8 gain:7, trsw:1;
553#else
554 u8 trsw:1, gain:7;
555#endif
556};
557
558struct rtl8723au_phy_stats {
559 struct phy_rx_agc_info path_agc[RTL8723A_MAX_RF_PATHS];
560 u8 ch_corr[RTL8723A_MAX_RF_PATHS];
561 u8 cck_sig_qual_ofdm_pwdb_all;
562 u8 cck_agc_rpt_ofdm_cfosho_a;
563 u8 cck_rpt_b_ofdm_cfosho_b;
564 u8 reserved_1;
565 u8 noise_power_db_msb;
566 u8 path_cfotail[RTL8723A_MAX_RF_PATHS];
567 u8 pcts_mask[RTL8723A_MAX_RF_PATHS];
568 s8 stream_rxevm[RTL8723A_MAX_RF_PATHS];
569 u8 path_rxsnr[RTL8723A_MAX_RF_PATHS];
570 u8 noise_power_db_lsb;
571 u8 reserved_2[3];
572 u8 stream_csi[RTL8723A_MAX_RF_PATHS];
573 u8 stream_target_csi[RTL8723A_MAX_RF_PATHS];
574 s8 sig_evm;
575 u8 reserved_3;
576
577#ifdef __LITTLE_ENDIAN
578 u8 antsel_rx_keep_2:1; /* ex_intf_flg:1; */
579 u8 sgi_en:1;
580 u8 rxsc:2;
581 u8 idle_long:1;
582 u8 r_ant_train_en:1;
583 u8 antenna_select_b:1;
584 u8 antenna_select:1;
585#else /* _BIG_ENDIAN_ */
586 u8 antenna_select:1;
587 u8 antenna_select_b:1;
588 u8 r_ant_train_en:1;
589 u8 idle_long:1;
590 u8 rxsc:2;
591 u8 sgi_en:1;
592 u8 antsel_rx_keep_2:1; /* ex_intf_flg:1; */
593#endif
594};
595
596/*
597 * Regs to backup
598 */
599#define RTL8XXXU_ADDA_REGS 16
600#define RTL8XXXU_MAC_REGS 4
601#define RTL8XXXU_BB_REGS 9
602
603struct rtl8xxxu_firmware_header {
604 __le16 signature; /* 92C0: test chip; 92C,
605 88C0: test chip;
606 88C1: MP A-cut;
607 92C1: MP A-cut */
608 u8 category; /* AP/NIC and USB/PCI */
609 u8 function;
610
611 __le16 major_version; /* FW Version */
612 u8 minor_version; /* FW Subversion, default 0x00 */
613 u8 reserved1;
614
615 u8 month; /* Release time Month field */
616 u8 date; /* Release time Date field */
617 u8 hour; /* Release time Hour field */
618 u8 minute; /* Release time Minute field */
619
620 __le16 ramcodesize; /* Size of RAM code */
621 u16 reserved2;
622
623 __le32 svn_idx; /* SVN entry index */
624 u32 reserved3;
625
626 u32 reserved4;
627 u32 reserved5;
628
629 u8 data[0];
630};
631
632/*
633 * The 8723au has 3 channel groups: 1-3, 4-9, and 10-14
634 */
635struct rtl8723au_idx {
636#ifdef __LITTLE_ENDIAN
637 int a:4;
638 int b:4;
639#else
640 int b:4;
641 int a:4;
642#endif
643} __attribute__((packed));
644
645struct rtl8723au_efuse {
646 __le16 rtl_id;
647 u8 res0[0xe];
648 u8 cck_tx_power_index_A[3]; /* 0x10 */
649 u8 cck_tx_power_index_B[3];
650 u8 ht40_1s_tx_power_index_A[3]; /* 0x16 */
651 u8 ht40_1s_tx_power_index_B[3];
652 /*
653 * The following entries are half-bytes split as:
654 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
655 */
656 struct rtl8723au_idx ht20_tx_power_index_diff[3];
657 struct rtl8723au_idx ofdm_tx_power_index_diff[3];
658 struct rtl8723au_idx ht40_max_power_offset[3];
659 struct rtl8723au_idx ht20_max_power_offset[3];
660 u8 channel_plan; /* 0x28 */
661 u8 tssi_a;
662 u8 thermal_meter;
663 u8 rf_regulatory;
664 u8 rf_option_2;
665 u8 rf_option_3;
666 u8 rf_option_4;
667 u8 res7;
668 u8 version /* 0x30 */;
669 u8 customer_id_major;
670 u8 customer_id_minor;
671 u8 xtal_k;
672 u8 chipset; /* 0x34 */
673 u8 res8[0x82];
674 u8 vid; /* 0xb7 */
675 u8 res9;
676 u8 pid; /* 0xb9 */
677 u8 res10[0x0c];
678 u8 mac_addr[ETH_ALEN]; /* 0xc6 */
679 u8 res11[2];
680 u8 vendor_name[7];
681 u8 res12[2];
682 u8 device_name[0x29]; /* 0xd7 */
683};
684
685struct rtl8192cu_efuse {
686 __le16 rtl_id;
687 __le16 hpon;
688 u8 res0[2];
689 __le16 clk;
690 __le16 testr;
691 __le16 vid;
692 __le16 did;
693 __le16 svid;
694 __le16 smid; /* 0x10 */
695 u8 res1[4];
696 u8 mac_addr[ETH_ALEN]; /* 0x16 */
697 u8 res2[2];
698 u8 vendor_name[7];
699 u8 res3[3];
700 u8 device_name[0x14]; /* 0x28 */
701 u8 res4[0x1e]; /* 0x3c */
702 u8 cck_tx_power_index_A[3]; /* 0x5a */
703 u8 cck_tx_power_index_B[3];
704 u8 ht40_1s_tx_power_index_A[3]; /* 0x60 */
705 u8 ht40_1s_tx_power_index_B[3];
706 /*
707 * The following entries are half-bytes split as:
708 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
709 */
710 struct rtl8723au_idx ht40_2s_tx_power_index_diff[3];
711 struct rtl8723au_idx ht20_tx_power_index_diff[3]; /* 0x69 */
712 struct rtl8723au_idx ofdm_tx_power_index_diff[3];
713 struct rtl8723au_idx ht40_max_power_offset[3]; /* 0x6f */
714 struct rtl8723au_idx ht20_max_power_offset[3];
715 u8 channel_plan; /* 0x75 */
716 u8 tssi_a;
717 u8 tssi_b;
718 u8 thermal_meter; /* xtal_k */ /* 0x78 */
719 u8 rf_regulatory;
720 u8 rf_option_2;
721 u8 rf_option_3;
722 u8 rf_option_4;
723 u8 res5[1]; /* 0x7d */
724 u8 version;
725 u8 customer_id;
726};
727
Jes Sorensen3be26992016-02-29 17:05:22 -0500728struct rtl8723bu_pwr_idx {
729#ifdef __LITTLE_ENDIAN
730 int ht20:4;
731 int ht40:4;
732 int ofdm:4;
733 int cck:4;
734#else
735 int cck:4;
736 int ofdm:4;
737 int ht40:4;
738 int ht20:4;
739#endif
740} __attribute__((packed));
741
Jes Sorensen4a0d7db2016-02-29 17:05:18 -0500742struct rtl8723bu_efuse_tx_power {
743 u8 cck_base[6];
744 u8 ht40_base[5];
745 struct rtl8723au_idx ht20_ofdm_1s_diff;
Jes Sorensen3be26992016-02-29 17:05:22 -0500746 struct rtl8723bu_pwr_idx pwr_diff[3];
Jes Sorensen4a0d7db2016-02-29 17:05:18 -0500747 u8 dummy5g[24]; /* max channel group (14) + power diff offset (10) */
748};
749
Jes Sorensen3c836d62016-02-29 17:04:11 -0500750struct rtl8723bu_efuse {
751 __le16 rtl_id;
752 u8 res0[0x0e];
Jes Sorensen4a0d7db2016-02-29 17:05:18 -0500753 struct rtl8723bu_efuse_tx_power tx_power_index_A; /* 0x10 */
754 struct rtl8723bu_efuse_tx_power tx_power_index_B; /* 0x3a */
755 struct rtl8723bu_efuse_tx_power tx_power_index_C; /* 0x64 */
756 struct rtl8723bu_efuse_tx_power tx_power_index_D; /* 0x8e */
Jes Sorensen3c836d62016-02-29 17:04:11 -0500757 u8 channel_plan; /* 0xb8 */
758 u8 xtal_k;
759 u8 thermal_meter;
760 u8 iqk_lck;
761 u8 pa_type; /* 0xbc */
762 u8 lna_type_2g; /* 0xbd */
763 u8 res2[3];
764 u8 rf_board_option;
765 u8 rf_feature_option;
766 u8 rf_bt_setting;
767 u8 eeprom_version;
768 u8 eeprom_customer_id;
769 u8 res3[2];
770 u8 tx_pwr_calibrate_rate;
771 u8 rf_antenna_option; /* 0xc9 */
772 u8 rfe_option;
773 u8 res4[9];
774 u8 usb_optional_function;
775 u8 res5[0x1e];
776 u8 res6[2];
777 u8 serial[0x0b]; /* 0xf5 */
778 u8 vid; /* 0x100 */
779 u8 res7;
780 u8 pid;
781 u8 res8[4];
782 u8 mac_addr[ETH_ALEN]; /* 0x107 */
783 u8 res9[2];
784 u8 vendor_name[0x07];
785 u8 res10[2];
Jes Sorensen22a31d42016-02-29 17:04:15 -0500786 u8 device_name[0x14];
787 u8 res11[0xcf];
788 u8 package_type; /* 0x1fb */
789 u8 res12[0x4];
Jes Sorensen3c836d62016-02-29 17:04:11 -0500790};
791
Jakub Sitnickie6f9a9c2016-02-29 17:04:39 -0500792struct rtl8192eu_efuse_tx_power {
793 u8 cck_base[6];
794 u8 ht40_base[5];
795 struct rtl8723au_idx ht20_ofdm_1s_diff;
Jes Sorensen9e247722016-04-07 14:19:23 -0400796 struct rtl8723bu_pwr_idx pwr_diff[3];
797 u8 dummy5g[24]; /* max channel group (14) + power diff offset (10) */
Jakub Sitnickie6f9a9c2016-02-29 17:04:39 -0500798};
799
Jes Sorensen3307d842016-02-29 17:03:59 -0500800struct rtl8192eu_efuse {
801 __le16 rtl_id;
802 u8 res0[0x0e];
Jakub Sitnickie6f9a9c2016-02-29 17:04:39 -0500803 struct rtl8192eu_efuse_tx_power tx_power_index_A; /* 0x10 */
Jes Sorensen9e247722016-04-07 14:19:23 -0400804 struct rtl8192eu_efuse_tx_power tx_power_index_B; /* 0x3a */
805 u8 res2[0x54];
Jes Sorensen3307d842016-02-29 17:03:59 -0500806 u8 channel_plan; /* 0xb8 */
807 u8 xtal_k;
808 u8 thermal_meter;
809 u8 iqk_lck;
810 u8 pa_type; /* 0xbc */
811 u8 lna_type_2g; /* 0xbd */
Jes Sorensen9e247722016-04-07 14:19:23 -0400812 u8 res3[1];
Jes Sorensen3307d842016-02-29 17:03:59 -0500813 u8 lna_type_5g; /* 0xbf */
Jes Sorensen9e247722016-04-07 14:19:23 -0400814 u8 res4[1];
Jes Sorensen3307d842016-02-29 17:03:59 -0500815 u8 rf_board_option;
816 u8 rf_feature_option;
817 u8 rf_bt_setting;
818 u8 eeprom_version;
819 u8 eeprom_customer_id;
Jes Sorensen9e247722016-04-07 14:19:23 -0400820 u8 res5[3];
Jes Sorensen3307d842016-02-29 17:03:59 -0500821 u8 rf_antenna_option; /* 0xc9 */
Jes Sorensen9e247722016-04-07 14:19:23 -0400822 u8 res6[6];
Jes Sorensen3307d842016-02-29 17:03:59 -0500823 u8 vid; /* 0xd0 */
Jes Sorensen9e247722016-04-07 14:19:23 -0400824 u8 res7[1];
Jes Sorensen3307d842016-02-29 17:03:59 -0500825 u8 pid; /* 0xd2 */
Jes Sorensen9e247722016-04-07 14:19:23 -0400826 u8 res8[1];
Jes Sorensen3307d842016-02-29 17:03:59 -0500827 u8 usb_optional_function;
Jes Sorensen3307d842016-02-29 17:03:59 -0500828 u8 res9[2];
Jes Sorensen9e247722016-04-07 14:19:23 -0400829 u8 mac_addr[ETH_ALEN]; /* 0xd7 */
Jes Sorensen3307d842016-02-29 17:03:59 -0500830 u8 res10[2];
Jes Sorensen9e247722016-04-07 14:19:23 -0400831 u8 vendor_name[7];
832 u8 res11[2];
833 u8 device_name[0x0b]; /* 0xe8 */
834 u8 res12[2];
Jes Sorensen3307d842016-02-29 17:03:59 -0500835 u8 serial[0x0b]; /* 0xf5 */
Jes Sorensen9e247722016-04-07 14:19:23 -0400836 u8 res13[0x30];
Jes Sorensen3307d842016-02-29 17:03:59 -0500837 u8 unknown[0x0d]; /* 0x130 */
Jes Sorensen9e247722016-04-07 14:19:23 -0400838 u8 res14[0xc3];
Jes Sorensen3307d842016-02-29 17:03:59 -0500839};
840
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400841struct rtl8xxxu_reg8val {
842 u16 reg;
843 u8 val;
844};
845
846struct rtl8xxxu_reg32val {
847 u16 reg;
848 u32 val;
849};
850
851struct rtl8xxxu_rfregval {
852 u8 reg;
853 u32 val;
854};
855
856enum rtl8xxxu_rfpath {
857 RF_A = 0,
858 RF_B = 1,
859};
860
861struct rtl8xxxu_rfregs {
862 u16 hssiparm1;
863 u16 hssiparm2;
864 u16 lssiparm;
865 u16 hspiread;
866 u16 lssiread;
867 u16 rf_sw_ctrl;
868};
869
870#define H2C_MAX_MBOX 4
871#define H2C_EXT BIT(7)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400872#define H2C_JOIN_BSS_DISCONNECT 0
873#define H2C_JOIN_BSS_CONNECT 1
Jes Sorensend940c242016-02-29 17:04:22 -0500874
875/*
876 * H2C (firmware) commands differ between the older generation chips
877 * 8188[cr]u, 819[12]cu, and 8723au, and the more recent chips 8723bu,
878 * 8192[de]u, 8192eu, and 8812.
879 */
880enum h2c_cmd_8723a {
881 H2C_SET_POWER_MODE = 1,
882 H2C_JOIN_BSS_REPORT = 2,
883 H2C_SET_RSSI = 5,
884 H2C_SET_RATE_MASK = (6 | H2C_EXT),
885};
886
887enum h2c_cmd_8723b {
888 /*
889 * Common Class: 000
890 */
891 H2C_8723B_RSVD_PAGE = 0x00,
892 H2C_8723B_MEDIA_STATUS_RPT = 0x01,
893 H2C_8723B_SCAN_ENABLE = 0x02,
894 H2C_8723B_KEEP_ALIVE = 0x03,
895 H2C_8723B_DISCON_DECISION = 0x04,
896 H2C_8723B_PSD_OFFLOAD = 0x05,
897 H2C_8723B_AP_OFFLOAD = 0x08,
898 H2C_8723B_BCN_RSVDPAGE = 0x09,
899 H2C_8723B_PROBERSP_RSVDPAGE = 0x0A,
900 H2C_8723B_FCS_RSVDPAGE = 0x10,
901 H2C_8723B_FCS_INFO = 0x11,
902 H2C_8723B_AP_WOW_GPIO_CTRL = 0x13,
903
904 /*
905 * PoweSave Class: 001
906 */
907 H2C_8723B_SET_PWR_MODE = 0x20,
908 H2C_8723B_PS_TUNING_PARA = 0x21,
909 H2C_8723B_PS_TUNING_PARA2 = 0x22,
910 H2C_8723B_P2P_LPS_PARAM = 0x23,
911 H2C_8723B_P2P_PS_OFFLOAD = 0x24,
912 H2C_8723B_PS_SCAN_ENABLE = 0x25,
913 H2C_8723B_SAP_PS_ = 0x26,
914 H2C_8723B_INACTIVE_PS_ = 0x27,
915 H2C_8723B_FWLPS_IN_IPS_ = 0x28,
916
917 /*
918 * Dynamic Mechanism Class: 010
919 */
Jes Sorensen80b30b22016-02-29 17:05:37 -0500920 H2C_8723B_MACID_CFG_RAID = 0x40,
Jes Sorensend940c242016-02-29 17:04:22 -0500921 H2C_8723B_TXBF = 0x41,
922 H2C_8723B_RSSI_SETTING = 0x42,
923 H2C_8723B_AP_REQ_TXRPT = 0x43,
924 H2C_8723B_INIT_RATE_COLLECT = 0x44,
925
926 /*
927 * BT Class: 011
928 */
929 H2C_8723B_B_TYPE_TDMA = 0x60,
930 H2C_8723B_BT_INFO = 0x61,
931 H2C_8723B_FORCE_BT_TXPWR = 0x62,
932 H2C_8723B_BT_IGNORE_WLANACT = 0x63,
933 H2C_8723B_DAC_SWING_VALUE = 0x64,
934 H2C_8723B_ANT_SEL_RSV = 0x65,
935 H2C_8723B_WL_OPMODE = 0x66,
936 H2C_8723B_BT_MP_OPER = 0x67,
937 H2C_8723B_BT_CONTROL = 0x68,
938 H2C_8723B_BT_WIFI_CTRL = 0x69,
Jes Sorensenf37e9222016-02-29 17:04:41 -0500939 H2C_8723B_BT_FW_PATCH = 0x6a,
940 H2C_8723B_BT_WLAN_CALIBRATION = 0x6d,
941 H2C_8723B_BT_GRANT = 0x6e,
Jes Sorensend940c242016-02-29 17:04:22 -0500942
943 /*
944 * WOWLAN Class: 100
945 */
946 H2C_8723B_WOWLAN = 0x80,
947 H2C_8723B_REMOTE_WAKE_CTRL = 0x81,
948 H2C_8723B_AOAC_GLOBAL_INFO = 0x82,
949 H2C_8723B_AOAC_RSVD_PAGE = 0x83,
950 H2C_8723B_AOAC_RSVD_PAGE2 = 0x84,
951 H2C_8723B_D0_SCAN_OFFLOAD_CTRL = 0x85,
952 H2C_8723B_D0_SCAN_OFFLOAD_INFO = 0x86,
953 H2C_8723B_CHNL_SWITCH_OFFLOAD = 0x87,
954
955 H2C_8723B_RESET_TSF = 0xC0,
956};
957
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400958
959struct h2c_cmd {
960 union {
961 struct {
962 u8 cmd;
Jes Sorensened35d092016-02-29 17:04:19 -0500963 u8 data[7];
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400964 } __packed cmd;
965 struct {
966 __le32 data;
967 __le16 ext;
968 } __packed raw;
969 struct {
Jes Sorensened35d092016-02-29 17:04:19 -0500970 __le32 data;
971 __le32 ext;
972 } __packed raw_wide;
973 struct {
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400974 u8 cmd;
975 u8 data;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400976 } __packed joinbss;
977 struct {
978 u8 cmd;
979 __le16 mask_hi;
980 u8 arg;
981 __le16 mask_lo;
982 } __packed ramask;
Jes Sorensenc7a5a192016-02-29 17:04:30 -0500983 struct {
984 u8 cmd;
Jes Sorensen7d794ea2016-02-29 17:05:39 -0500985 u8 parm;
986 u8 macid;
987 u8 macid_end;
988 } __packed media_status_rpt;
989 struct {
990 u8 cmd;
Jes Sorensenf653e692016-02-29 17:05:38 -0500991 u8 macid;
992 /*
993 * [0:4] - RAID
994 * [7] - SGI
995 */
Jes Sorensen3ca7b322016-02-29 17:04:43 -0500996 u8 data1;
Jes Sorensenf653e692016-02-29 17:05:38 -0500997 /*
998 * [0:1] - Bandwidth
999 * [3] - No Update
1000 * [4:5] - VHT enable
1001 * [6] - DISPT
1002 * [7] - DISRA
1003 */
Jes Sorensen3ca7b322016-02-29 17:04:43 -05001004 u8 data2;
Jes Sorensenf653e692016-02-29 17:05:38 -05001005 u8 ramask0;
Jes Sorensen80b30b22016-02-29 17:05:37 -05001006 u8 ramask1;
1007 u8 ramask2;
1008 u8 ramask3;
Jes Sorensen80b30b22016-02-29 17:05:37 -05001009 } __packed b_macid_cfg;
1010 struct {
1011 u8 cmd;
1012 u8 data1;
1013 u8 data2;
Jes Sorensen3ca7b322016-02-29 17:04:43 -05001014 u8 data3;
1015 u8 data4;
1016 u8 data5;
1017 } __packed b_type_dma;
1018 struct {
1019 u8 cmd;
Jes Sorensen6b9eae02016-02-29 17:04:50 -05001020 u8 data;
1021 } __packed bt_info;
1022 struct {
1023 u8 cmd;
Jes Sorensen394f1bd2016-02-29 17:04:49 -05001024 u8 operreq;
1025 u8 opcode;
1026 u8 data;
1027 u8 addr;
1028 } __packed bt_mp_oper;
1029 struct {
1030 u8 cmd;
Jes Sorensenc7a5a192016-02-29 17:04:30 -05001031 u8 data;
1032 } __packed bt_wlan_calibration;
Jes Sorensenf37e9222016-02-29 17:04:41 -05001033 struct {
1034 u8 cmd;
Jes Sorensen7297f492016-02-29 17:04:44 -05001035 u8 data;
1036 } __packed ignore_wlan;
1037 struct {
1038 u8 cmd;
Jes Sorensenf37e9222016-02-29 17:04:41 -05001039 u8 ant_inverse;
1040 u8 int_switch_type;
1041 } __packed ant_sel_rsv;
1042 struct {
1043 u8 cmd;
1044 u8 data;
1045 } __packed bt_grant;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001046 };
1047};
1048
Jes Sorensenb2b43b72016-02-29 17:04:48 -05001049enum c2h_evt_8723b {
1050 C2H_8723B_DEBUG = 0,
1051 C2H_8723B_TSF = 1,
1052 C2H_8723B_AP_RPT_RSP = 2,
1053 C2H_8723B_CCX_TX_RPT = 3,
1054 C2H_8723B_BT_RSSI = 4,
1055 C2H_8723B_BT_OP_MODE = 5,
1056 C2H_8723B_EXT_RA_RPT = 6,
1057 C2H_8723B_BT_INFO = 9,
Jes Sorensen394f1bd2016-02-29 17:04:49 -05001058 C2H_8723B_HW_INFO_EXCH = 0x0a,
1059 C2H_8723B_BT_MP_INFO = 0x0b,
Jes Sorensen55a18dd2016-02-29 17:05:41 -05001060 C2H_8723B_RA_REPORT = 0x0c,
Jes Sorensenb2b43b72016-02-29 17:04:48 -05001061 C2H_8723B_FW_DEBUG = 0xff,
1062};
1063
1064enum bt_info_src_8723b {
1065 BT_INFO_SRC_8723B_WIFI_FW = 0x0,
1066 BT_INFO_SRC_8723B_BT_RSP = 0x1,
1067 BT_INFO_SRC_8723B_BT_ACTIVE_SEND = 0x2,
1068};
1069
Jes Sorensen394f1bd2016-02-29 17:04:49 -05001070enum bt_mp_oper_opcode_8723b {
1071 BT_MP_OP_GET_BT_VERSION = 0x00,
1072 BT_MP_OP_RESET = 0x01,
1073 BT_MP_OP_TEST_CTRL = 0x02,
1074 BT_MP_OP_SET_BT_MODE = 0x03,
1075 BT_MP_OP_SET_CHNL_TX_GAIN = 0x04,
1076 BT_MP_OP_SET_PKT_TYPE_LEN = 0x05,
1077 BT_MP_OP_SET_PKT_CNT_L_PL_TYPE = 0x06,
1078 BT_MP_OP_SET_PKT_CNT_H_PKT_INTV = 0x07,
1079 BT_MP_OP_SET_PKT_HEADER = 0x08,
1080 BT_MP_OP_SET_WHITENCOEFF = 0x09,
1081 BT_MP_OP_SET_BD_ADDR_L = 0x0a,
1082 BT_MP_OP_SET_BD_ADDR_H = 0x0b,
1083 BT_MP_OP_WRITE_REG_ADDR = 0x0c,
1084 BT_MP_OP_WRITE_REG_VALUE = 0x0d,
1085 BT_MP_OP_GET_BT_STATUS = 0x0e,
1086 BT_MP_OP_GET_BD_ADDR_L = 0x0f,
1087 BT_MP_OP_GET_BD_ADDR_H = 0x10,
1088 BT_MP_OP_READ_REG = 0x11,
1089 BT_MP_OP_SET_TARGET_BD_ADDR_L = 0x12,
1090 BT_MP_OP_SET_TARGET_BD_ADDR_H = 0x13,
1091 BT_MP_OP_SET_TX_POWER_CALIBRATION = 0x14,
1092 BT_MP_OP_GET_RX_PKT_CNT_L = 0x15,
1093 BT_MP_OP_GET_RX_PKT_CNT_H = 0x16,
1094 BT_MP_OP_GET_RX_ERROR_BITS_L = 0x17,
1095 BT_MP_OP_GET_RX_ERROR_BITS_H = 0x18,
1096 BT_MP_OP_GET_RSSI = 0x19,
1097 BT_MP_OP_GET_CFO_HDR_QUALITY_L = 0x1a,
1098 BT_MP_OP_GET_CFO_HDR_QUALITY_H = 0x1b,
1099 BT_MP_OP_GET_TARGET_BD_ADDR_L = 0x1c,
1100 BT_MP_OP_GET_TARGET_BD_ADDR_H = 0x1d,
1101 BT_MP_OP_GET_AFH_MAP_L = 0x1e,
1102 BT_MP_OP_GET_AFH_MAP_M = 0x1f,
1103 BT_MP_OP_GET_AFH_MAP_H = 0x20,
1104 BT_MP_OP_GET_AFH_STATUS = 0x21,
1105 BT_MP_OP_SET_TRACKING_INTERVAL = 0x22,
1106 BT_MP_OP_SET_THERMAL_METER = 0x23,
1107 BT_MP_OP_ENABLE_CFO_TRACKING = 0x24,
1108};
1109
Jes Sorensenb2b43b72016-02-29 17:04:48 -05001110struct rtl8723bu_c2h {
1111 u8 id;
1112 u8 seq;
1113 union {
1114 struct {
1115 u8 payload[0];
1116 } __packed raw;
1117 struct {
Jes Sorensen394f1bd2016-02-29 17:04:49 -05001118 u8 ext_id;
1119 u8 status:4;
1120 u8 retlen:4;
1121 u8 opcode_ver:4;
1122 u8 req_num:4;
1123 u8 payload[2];
1124 } __packed bt_mp_info;
1125 struct {
Jes Sorensenb2b43b72016-02-29 17:04:48 -05001126 u8 response_source:4;
1127 u8 dummy0_0:4;
1128
1129 u8 bt_info;
1130
1131 u8 retry_count:4;
1132 u8 dummy2_0:1;
1133 u8 bt_page:1;
1134 u8 tx_rx_mask:1;
1135 u8 dummy2_2:1;
1136
1137 u8 rssi;
1138
1139 u8 basic_rate:1;
1140 u8 bt_has_reset:1;
1141 u8 dummy4_1:1;;
1142 u8 ignore_wlan:1;
1143 u8 auto_report:1;
1144 u8 dummy4_2:3;
1145
1146 u8 a4;
1147 u8 a5;
1148 } __packed bt_info;
Jes Sorensen55a18dd2016-02-29 17:05:41 -05001149 struct {
1150 u8 rate:7;
1151 u8 dummy0_0:1;
1152 u8 macid;
1153 u8 ldpc:1;
1154 u8 txbf:1;
1155 u8 noisy_state:1;
1156 u8 dummy2_0:5;
1157 u8 dummy3_0;
1158 } __packed ra_report;
Jes Sorensenb2b43b72016-02-29 17:04:48 -05001159 };
1160};
1161
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001162struct rtl8xxxu_fileops;
1163
1164struct rtl8xxxu_priv {
1165 struct ieee80211_hw *hw;
1166 struct usb_device *udev;
1167 struct rtl8xxxu_fileops *fops;
1168
1169 spinlock_t tx_urb_lock;
1170 struct list_head tx_urb_free_list;
1171 int tx_urb_free_count;
1172 bool tx_stopped;
1173
1174 spinlock_t rx_urb_lock;
1175 struct list_head rx_urb_pending_list;
1176 int rx_urb_pending_count;
1177 bool shutdown;
1178 struct work_struct rx_urb_wq;
1179
1180 u8 mac_addr[ETH_ALEN];
1181 char chip_name[8];
Jes Sorensen0e5d4352016-02-29 17:04:00 -05001182 char chip_vendor[8];
Jes Sorensen21db9972016-02-29 17:05:21 -05001183 u8 cck_tx_power_index_A[RTL8XXXU_MAX_CHANNEL_GROUPS];
1184 u8 cck_tx_power_index_B[RTL8XXXU_MAX_CHANNEL_GROUPS];
1185 u8 ht40_1s_tx_power_index_A[RTL8XXXU_MAX_CHANNEL_GROUPS];
1186 u8 ht40_1s_tx_power_index_B[RTL8XXXU_MAX_CHANNEL_GROUPS];
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001187 /*
1188 * The following entries are half-bytes split as:
1189 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
1190 */
Jes Sorensen21db9972016-02-29 17:05:21 -05001191 struct rtl8723au_idx ht40_2s_tx_power_index_diff[
Jes Sorensen3be26992016-02-29 17:05:22 -05001192 RTL8723A_CHANNEL_GROUPS];
1193 struct rtl8723au_idx ht20_tx_power_index_diff[RTL8723A_CHANNEL_GROUPS];
1194 struct rtl8723au_idx ofdm_tx_power_index_diff[RTL8723A_CHANNEL_GROUPS];
1195 struct rtl8723au_idx ht40_max_power_offset[RTL8723A_CHANNEL_GROUPS];
1196 struct rtl8723au_idx ht20_max_power_offset[RTL8723A_CHANNEL_GROUPS];
1197 /*
1198 * Newer generation chips only keep power diffs per TX count,
1199 * not per channel group.
1200 */
1201 struct rtl8723au_idx ofdm_tx_power_diff[RTL8723B_TX_COUNT];
1202 struct rtl8723au_idx ht20_tx_power_diff[RTL8723B_TX_COUNT];
1203 struct rtl8723au_idx ht40_tx_power_diff[RTL8723B_TX_COUNT];
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001204 u32 chip_cut:4;
1205 u32 rom_rev:4;
Jakub Sitnicki38451992016-02-03 13:39:49 -05001206 u32 is_multi_func:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001207 u32 has_wifi:1;
1208 u32 has_bluetooth:1;
1209 u32 enable_bluetooth:1;
1210 u32 has_gps:1;
1211 u32 hi_pa:1;
1212 u32 vendor_umc:1;
Jes Sorensen0e5d4352016-02-29 17:04:00 -05001213 u32 vendor_smic:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001214 u32 has_polarity_ctrl:1;
1215 u32 has_eeprom:1;
1216 u32 boot_eeprom:1;
Jes Sorensen0e28b972016-02-29 17:04:13 -05001217 u32 usb_interrupts:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001218 u32 ep_tx_high_queue:1;
1219 u32 ep_tx_normal_queue:1;
1220 u32 ep_tx_low_queue:1;
Jes Sorensen4ef22eb2016-02-29 17:04:55 -05001221 u32 has_xtalk:1;
1222 u8 xtalk;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001223 unsigned int pipe_interrupt;
1224 unsigned int pipe_in;
1225 unsigned int pipe_out[TXDESC_QUEUE_MAX];
1226 u8 out_ep[RTL8XXXU_OUT_ENDPOINTS];
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001227 u8 ep_tx_count;
1228 u8 rf_paths;
1229 u8 rx_paths;
1230 u8 tx_paths;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001231 u32 rege94;
1232 u32 rege9c;
1233 u32 regeb4;
1234 u32 regebc;
1235 int next_mbox;
1236 int nr_out_eps;
1237
1238 struct mutex h2c_mutex;
1239
1240 struct usb_anchor rx_anchor;
1241 struct usb_anchor tx_anchor;
1242 struct usb_anchor int_anchor;
1243 struct rtl8xxxu_firmware_header *fw_data;
1244 size_t fw_size;
1245 struct mutex usb_buf_mutex;
1246 union {
1247 __le32 val32;
1248 __le16 val16;
1249 u8 val8;
1250 } usb_buf;
1251 union {
Jes Sorensen3307d842016-02-29 17:03:59 -05001252 u8 raw[EFUSE_MAP_LEN];
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001253 struct rtl8723au_efuse efuse8723;
Jes Sorensen3c836d62016-02-29 17:04:11 -05001254 struct rtl8723bu_efuse efuse8723bu;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001255 struct rtl8192cu_efuse efuse8192;
Jes Sorensen3307d842016-02-29 17:03:59 -05001256 struct rtl8192eu_efuse efuse8192eu;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001257 } efuse_wifi;
1258 u32 adda_backup[RTL8XXXU_ADDA_REGS];
1259 u32 mac_backup[RTL8XXXU_MAC_REGS];
1260 u32 bb_backup[RTL8XXXU_BB_REGS];
1261 u32 bb_recovery_backup[RTL8XXXU_BB_REGS];
Jes Sorensenba17d822016-03-31 17:08:39 -04001262 enum rtl8xxxu_rtl_chip rtl_chip;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001263 u8 pi_enabled:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001264 u8 int_buf[USB_INTR_CONTENT_LENGTH];
1265};
1266
1267struct rtl8xxxu_rx_urb {
1268 struct urb urb;
1269 struct ieee80211_hw *hw;
1270 struct list_head list;
1271};
1272
1273struct rtl8xxxu_tx_urb {
1274 struct urb urb;
1275 struct ieee80211_hw *hw;
1276 struct list_head list;
1277};
1278
1279struct rtl8xxxu_fileops {
1280 int (*parse_efuse) (struct rtl8xxxu_priv *priv);
1281 int (*load_firmware) (struct rtl8xxxu_priv *priv);
1282 int (*power_on) (struct rtl8xxxu_priv *priv);
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05001283 void (*power_off) (struct rtl8xxxu_priv *priv);
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05001284 void (*reset_8051) (struct rtl8xxxu_priv *priv);
Jes Sorensen74b99be2016-02-29 17:04:04 -05001285 int (*llt_init) (struct rtl8xxxu_priv *priv, u8 last_tx_page);
Jes Sorensencb877252016-04-14 14:58:57 -04001286 void (*init_phy_bb) (struct rtl8xxxu_priv *priv);
Jes Sorensen4062b8f2016-04-14 16:37:08 -04001287 int (*init_phy_rf) (struct rtl8xxxu_priv *priv);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05001288 void (*phy_init_antenna_selection) (struct rtl8xxxu_priv *priv);
Jes Sorensene1547c52016-02-29 17:04:35 -05001289 void (*phy_iq_calibrate) (struct rtl8xxxu_priv *priv);
Jes Sorensenc3f95062016-02-29 17:04:40 -05001290 void (*config_channel) (struct ieee80211_hw *hw);
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05001291 int (*parse_rx_desc) (struct rtl8xxxu_priv *priv, struct sk_buff *skb,
1292 struct ieee80211_rx_status *rx_status);
Jes Sorensen3e88ca42016-02-29 17:05:08 -05001293 void (*init_aggregation) (struct rtl8xxxu_priv *priv);
Jes Sorensen9c79bf92016-02-29 17:05:10 -05001294 void (*init_statistics) (struct rtl8xxxu_priv *priv);
Jes Sorensendb08de92016-02-29 17:05:17 -05001295 void (*enable_rf) (struct rtl8xxxu_priv *priv);
Jes Sorensenfc89a412016-02-29 17:05:46 -05001296 void (*disable_rf) (struct rtl8xxxu_priv *priv);
Jes Sorensen747bf232016-04-14 14:59:04 -04001297 void (*usb_quirks) (struct rtl8xxxu_priv *priv);
Jes Sorensene796dab2016-02-29 17:05:19 -05001298 void (*set_tx_power) (struct rtl8xxxu_priv *priv, int channel,
1299 bool ht40);
Jes Sorensenf653e692016-02-29 17:05:38 -05001300 void (*update_rate_mask) (struct rtl8xxxu_priv *priv,
1301 u32 ramask, int sgi);
Jes Sorensen7d794ea2016-02-29 17:05:39 -05001302 void (*report_connect) (struct rtl8xxxu_priv *priv,
1303 u8 macid, bool connect);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001304 int writeN_block_size;
Jes Sorensened35d092016-02-29 17:04:19 -05001305 u16 mbox_ext_reg;
1306 char mbox_ext_width;
Jes Sorensen179e1742016-02-29 17:05:27 -05001307 char tx_desc_size;
Jes Sorensena49c7ce2016-04-14 14:58:52 -04001308 char rx_desc_size;
Jes Sorensen0d698de2016-02-29 17:04:36 -05001309 char has_s0s1;
Jes Sorensen8634af52016-02-29 17:04:33 -05001310 u32 adda_1t_init;
1311 u32 adda_1t_path_on;
1312 u32 adda_2t_path_on_a;
1313 u32 adda_2t_path_on_b;
Jes Sorensen24e8e7e2016-04-14 14:59:01 -04001314 u16 trxff_boundary;
Jes Sorensen9b323ee2016-04-14 14:59:03 -04001315 u8 pbp_rx;
1316 u8 pbp_tx;
Jes Sorensenc606e662016-04-07 14:19:16 -04001317 struct rtl8xxxu_reg8val *mactable;
Jes Sorensen89c2a092016-04-14 14:58:44 -04001318 u8 total_page_num;
1319 u8 page_num_hi;
1320 u8 page_num_lo;
1321 u8 page_num_norm;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001322};