blob: a8a4f2b451d1c84de0dadf1db087407e3452ecd4 [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
45/* (HPQ + LPQ + NPQ + PUBQ) = TX_TOTAL_PAGE_NUM */
46#define TX_PAGE_NUM_PUBQ 0xe7
47#define TX_PAGE_NUM_HI_PQ 0x0c
48#define TX_PAGE_NUM_LO_PQ 0x02
49#define TX_PAGE_NUM_NORM_PQ 0x02
50
51#define RTL_FW_PAGE_SIZE 4096
52#define RTL8XXXU_FIRMWARE_POLL_MAX 1000
53
54#define RTL8723A_CHANNEL_GROUPS 3
55#define RTL8723A_MAX_RF_PATHS 2
56#define RF6052_MAX_TX_PWR 0x3f
57
Jes Sorensen3307d842016-02-29 17:03:59 -050058#define EFUSE_MAP_LEN 512
59#define EFUSE_MAX_SECTION_8723A 64
Jes Sorensen26f1fad2015-10-14 20:44:51 -040060#define EFUSE_REAL_CONTENT_LEN_8723A 512
61#define EFUSE_BT_MAP_LEN_8723A 1024
62#define EFUSE_MAX_WORD_UNIT 4
63
64struct rtl8xxxu_rx_desc {
65#ifdef __LITTLE_ENDIAN
66 u32 pktlen:14;
67 u32 crc32:1;
68 u32 icverr:1;
69 u32 drvinfo_sz:4;
70 u32 security:3;
71 u32 qos:1;
72 u32 shift:2;
73 u32 phy_stats:1;
74 u32 swdec:1;
75 u32 ls:1;
76 u32 fs:1;
77 u32 eor:1;
78 u32 own:1;
79
80 u32 macid:5;
81 u32 tid:4;
82 u32 hwrsvd:4;
83 u32 amsdu:1;
84 u32 paggr:1;
85 u32 faggr:1;
86 u32 a1fit:4;
87 u32 a2fit:4;
88 u32 pam:1;
89 u32 pwr:1;
90 u32 md:1;
91 u32 mf:1;
92 u32 type:2;
93 u32 mc:1;
94 u32 bc:1;
95
96 u32 seq:12;
97 u32 frag:4;
98 u32 nextpktlen:14;
99 u32 nextind:1;
100 u32 reserved0:1;
101
102 u32 rxmcs:6;
103 u32 rxht:1;
104 u32 gf:1;
105 u32 splcp:1;
106 u32 bw:1;
107 u32 htc:1;
108 u32 eosp:1;
109 u32 bssidfit:2;
110 u32 reserved1:16;
111 u32 unicastwake:1;
112 u32 magicwake:1;
113
114 u32 pattern0match:1;
115 u32 pattern1match:1;
116 u32 pattern2match:1;
117 u32 pattern3match:1;
118 u32 pattern4match:1;
119 u32 pattern5match:1;
120 u32 pattern6match:1;
121 u32 pattern7match:1;
122 u32 pattern8match:1;
123 u32 pattern9match:1;
124 u32 patternamatch:1;
125 u32 patternbmatch:1;
126 u32 patterncmatch:1;
127 u32 reserved2:19;
128#else
129 u32 own:1;
130 u32 eor:1;
131 u32 fs:1;
132 u32 ls:1;
133 u32 swdec:1;
134 u32 phy_stats:1;
135 u32 shift:2;
136 u32 qos:1;
137 u32 security:3;
138 u32 drvinfo_sz:4;
139 u32 icverr:1;
140 u32 crc32:1;
141 u32 pktlen:14;
142
143 u32 bc:1;
144 u32 mc:1;
145 u32 type:2;
146 u32 mf:1;
147 u32 md:1;
148 u32 pwr:1;
149 u32 pam:1;
150 u32 a2fit:4;
151 u32 a1fit:4;
152 u32 faggr:1;
153 u32 paggr:1;
154 u32 amsdu:1;
155 u32 hwrsvd:4;
156 u32 tid:4;
157 u32 macid:5;
158
159 u32 reserved0:1;
160 u32 nextind:1;
161 u32 nextpktlen:14;
162 u32 frag:4;
163 u32 seq:12;
164
165 u32 magicwake:1;
166 u32 unicastwake:1;
167 u32 reserved1:16;
168 u32 bssidfit:2;
169 u32 eosp:1;
170 u32 htc:1;
171 u32 bw:1;
172 u32 splcp:1;
173 u32 gf:1;
174 u32 rxht:1;
175 u32 rxmcs:6;
176
177 u32 reserved2:19;
178 u32 patterncmatch:1;
179 u32 patternbmatch:1;
180 u32 patternamatch:1;
181 u32 pattern9match:1;
182 u32 pattern8match:1;
183 u32 pattern7match:1;
184 u32 pattern6match:1;
185 u32 pattern5match:1;
186 u32 pattern4match:1;
187 u32 pattern3match:1;
188 u32 pattern2match:1;
189 u32 pattern1match:1;
190 u32 pattern0match:1;
191#endif
192 __le32 tsfl;
193#if 0
194 u32 bassn:12;
195 u32 bavld:1;
196 u32 reserved3:19;
197#endif
198};
199
Jes Sorensena6c80d22016-02-29 17:04:46 -0500200struct rtl8723bu_rx_desc {
201#ifdef __LITTLE_ENDIAN
202 u32 pktlen:14;
203 u32 crc32:1;
204 u32 icverr:1;
205 u32 drvinfo_sz:4;
206 u32 security:3;
207 u32 qos:1;
208 u32 shift:2;
209 u32 phy_stats:1;
210 u32 swdec:1;
211 u32 ls:1;
212 u32 fs:1;
213 u32 eor:1;
214 u32 own:1;
215
216 u32 macid:7;
217 u32 dummy1_0:1;
218 u32 tid:4;
219 u32 dummy1_1:1;
220 u32 amsdu:1;
221 u32 rxid_match:1;
222 u32 paggr:1;
223 u32 a1fit:4; /* 16 */
224 u32 chkerr:1;
225 u32 ipver:1;
226 u32 tcpudp:1;
227 u32 chkvld:1;
228 u32 pam:1;
229 u32 pwr:1;
230 u32 more_data:1;
231 u32 more_frag:1;
232 u32 type:2;
233 u32 mc:1;
234 u32 bc:1;
235
236 u32 seq:12;
237 u32 frag:4;
238 u32 rx_is_qos:1; /* 16 */
239 u32 dummy2_0:1;
240 u32 wlanhd_iv_len:6;
241 u32 dummy2_1:4;
242 u32 rpt_sel:1;
243 u32 dummy2_2:3;
244
245 u32 rxmcs:7;
246 u32 dummy3_0:3;
247 u32 htc:1;
248 u32 eosp:1;
249 u32 bssidfit:2;
250 u32 dummy3_1:2;
251 u32 usb_agg_pktnum:8; /* 16 */
252 u32 dummy3_2:5;
253 u32 pattern_match:1;
254 u32 unicast_match:1;
255 u32 magic_match:1;
256
257 u32 splcp:1;
258 u32 ldcp:1;
259 u32 stbc:1;
260 u32 dummy4_0:1;
261 u32 bw:2;
262 u32 dummy4_1:26;
263#else
264 u32 own:1;
265 u32 eor:1;
266 u32 fs:1;
267 u32 ls:1;
268 u32 swdec:1;
269 u32 phy_stats:1;
270 u32 shift:2;
271 u32 qos:1;
272 u32 security:3;
273 u32 drvinfo_sz:4;
274 u32 icverr:1;
275 u32 crc32:1;
276 u32 pktlen:14;
277
278 u32 bc:1;
279 u32 mc:1;
280 u32 type:2;
281 u32 mf:1;
282 u32 md:1;
283 u32 pwr:1;
284 u32 pam:1;
285 u32 a2fit:4;
286 u32 a1fit:4;
287 u32 faggr:1;
288 u32 paggr:1;
289 u32 amsdu:1;
290 u32 hwrsvd:4;
291 u32 tid:4;
292 u32 macid:5;
293
294 u32 dummy2_2:3;
295 u32 rpt_sel:1;
296 u32 dummy2_1:4;
297 u32 wlanhd_iv_len:6;
298 u32 dummy2_0:1;
299 u32 rx_is_qos:1;
300 u32 frag:4; /* 16 */
301 u32 seq:12;
302
303 u32 magic_match:1;
304 u32 unicast_match:1;
305 u32 pattern_match:1;
306 u32 dummy3_2:5;
307 u32 usb_agg_pktnum:8;
308 u32 dummy3_1:2; /* 16 */
309 u32 bssidfit:2;
310 u32 eosp:1;
311 u32 htc:1;
312 u32 dummy3_0:3;
313 u32 rxmcs:7;
314
315 u32 dumm4_1:26;
316 u32 bw:2;
317 u32 dummy4_0:1;
318 u32 stbc:1;
319 u32 ldcp:1;
320 u32 splcp:1;
321#endif
322 __le32 tsfl;
323};
324
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400325struct rtl8xxxu_tx_desc {
326 __le16 pkt_size;
327 u8 pkt_offset;
328 u8 txdw0;
329 __le32 txdw1;
330 __le32 txdw2;
331 __le32 txdw3;
332 __le32 txdw4;
333 __le32 txdw5;
334 __le32 txdw6;
335 __le16 csum;
336 __le16 txdw7;
337};
338
339/* CCK Rates, TxHT = 0 */
340#define DESC_RATE_1M 0x00
341#define DESC_RATE_2M 0x01
342#define DESC_RATE_5_5M 0x02
343#define DESC_RATE_11M 0x03
344
345/* OFDM Rates, TxHT = 0 */
346#define DESC_RATE_6M 0x04
347#define DESC_RATE_9M 0x05
348#define DESC_RATE_12M 0x06
349#define DESC_RATE_18M 0x07
350#define DESC_RATE_24M 0x08
351#define DESC_RATE_36M 0x09
352#define DESC_RATE_48M 0x0a
353#define DESC_RATE_54M 0x0b
354
355/* MCS Rates, TxHT = 1 */
356#define DESC_RATE_MCS0 0x0c
357#define DESC_RATE_MCS1 0x0d
358#define DESC_RATE_MCS2 0x0e
359#define DESC_RATE_MCS3 0x0f
360#define DESC_RATE_MCS4 0x10
361#define DESC_RATE_MCS5 0x11
362#define DESC_RATE_MCS6 0x12
363#define DESC_RATE_MCS7 0x13
364#define DESC_RATE_MCS8 0x14
365#define DESC_RATE_MCS9 0x15
366#define DESC_RATE_MCS10 0x16
367#define DESC_RATE_MCS11 0x17
368#define DESC_RATE_MCS12 0x18
369#define DESC_RATE_MCS13 0x19
370#define DESC_RATE_MCS14 0x1a
371#define DESC_RATE_MCS15 0x1b
372#define DESC_RATE_MCS15_SG 0x1c
373#define DESC_RATE_MCS32 0x20
374
375#define TXDESC_OFFSET_SZ 0
376#define TXDESC_OFFSET_SHT 16
377#if 0
378#define TXDESC_BMC BIT(24)
379#define TXDESC_LSG BIT(26)
380#define TXDESC_FSG BIT(27)
381#define TXDESC_OWN BIT(31)
382#else
383#define TXDESC_BROADMULTICAST BIT(0)
384#define TXDESC_LAST_SEGMENT BIT(2)
385#define TXDESC_FIRST_SEGMENT BIT(3)
386#define TXDESC_OWN BIT(7)
387#endif
388
389/* Word 1 */
390#define TXDESC_PKT_OFFSET_SZ 0
391#define TXDESC_AGG_ENABLE BIT(5)
392#define TXDESC_BK BIT(6)
393#define TXDESC_QUEUE_SHIFT 8
394#define TXDESC_QUEUE_MASK 0x1f00
395#define TXDESC_QUEUE_BK 0x2
396#define TXDESC_QUEUE_BE 0x0
397#define TXDESC_QUEUE_VI 0x5
398#define TXDESC_QUEUE_VO 0x7
399#define TXDESC_QUEUE_BEACON 0x10
400#define TXDESC_QUEUE_HIGH 0x11
401#define TXDESC_QUEUE_MGNT 0x12
402#define TXDESC_QUEUE_CMD 0x13
403#define TXDESC_QUEUE_MAX (TXDESC_QUEUE_CMD + 1)
404
405#define DESC_RATE_ID_SHIFT 16
406#define DESC_RATE_ID_MASK 0xf
407#define TXDESC_NAVUSEHDR BIT(20)
408#define TXDESC_SEC_RC4 0x00400000
409#define TXDESC_SEC_AES 0x00c00000
410#define TXDESC_PKT_OFFSET_SHIFT 26
411#define TXDESC_AGG_EN BIT(29)
412#define TXDESC_HWPC BIT(31)
413
414/* Word 2 */
415#define TXDESC_ACK_REPORT BIT(19)
416#define TXDESC_AMPDU_DENSITY_SHIFT 20
417
418/* Word 3 */
419#define TXDESC_SEQ_SHIFT 16
420#define TXDESC_SEQ_MASK 0x0fff0000
421
422/* Word 4 */
423#define TXDESC_QOS BIT(6)
424#define TXDESC_HW_SEQ_ENABLE BIT(7)
425#define TXDESC_USE_DRIVER_RATE BIT(8)
426#define TXDESC_DISABLE_DATA_FB BIT(10)
427#define TXDESC_CTS_SELF_ENABLE BIT(11)
428#define TXDESC_RTS_CTS_ENABLE BIT(12)
429#define TXDESC_HW_RTS_ENABLE BIT(13)
430#define TXDESC_PRIME_CH_OFF_LOWER BIT(20)
431#define TXDESC_PRIME_CH_OFF_UPPER BIT(21)
432#define TXDESC_SHORT_PREAMBLE BIT(24)
433#define TXDESC_DATA_BW BIT(25)
434#define TXDESC_RTS_DATA_BW BIT(27)
435#define TXDESC_RTS_PRIME_CH_OFF_LOWER BIT(28)
436#define TXDESC_RTS_PRIME_CH_OFF_UPPER BIT(29)
437
438/* Word 5 */
439#define TXDESC_RTS_RATE_SHIFT 0
440#define TXDESC_RTS_RATE_MASK 0x3f
441#define TXDESC_SHORT_GI BIT(6)
442#define TXDESC_CCX_TAG BIT(7)
443#define TXDESC_RETRY_LIMIT_ENABLE BIT(17)
444#define TXDESC_RETRY_LIMIT_SHIFT 18
445#define TXDESC_RETRY_LIMIT_MASK 0x00fc0000
446
447/* Word 6 */
448#define TXDESC_MAX_AGG_SHIFT 11
449
450struct phy_rx_agc_info {
451#ifdef __LITTLE_ENDIAN
452 u8 gain:7, trsw:1;
453#else
454 u8 trsw:1, gain:7;
455#endif
456};
457
458struct rtl8723au_phy_stats {
459 struct phy_rx_agc_info path_agc[RTL8723A_MAX_RF_PATHS];
460 u8 ch_corr[RTL8723A_MAX_RF_PATHS];
461 u8 cck_sig_qual_ofdm_pwdb_all;
462 u8 cck_agc_rpt_ofdm_cfosho_a;
463 u8 cck_rpt_b_ofdm_cfosho_b;
464 u8 reserved_1;
465 u8 noise_power_db_msb;
466 u8 path_cfotail[RTL8723A_MAX_RF_PATHS];
467 u8 pcts_mask[RTL8723A_MAX_RF_PATHS];
468 s8 stream_rxevm[RTL8723A_MAX_RF_PATHS];
469 u8 path_rxsnr[RTL8723A_MAX_RF_PATHS];
470 u8 noise_power_db_lsb;
471 u8 reserved_2[3];
472 u8 stream_csi[RTL8723A_MAX_RF_PATHS];
473 u8 stream_target_csi[RTL8723A_MAX_RF_PATHS];
474 s8 sig_evm;
475 u8 reserved_3;
476
477#ifdef __LITTLE_ENDIAN
478 u8 antsel_rx_keep_2:1; /* ex_intf_flg:1; */
479 u8 sgi_en:1;
480 u8 rxsc:2;
481 u8 idle_long:1;
482 u8 r_ant_train_en:1;
483 u8 antenna_select_b:1;
484 u8 antenna_select:1;
485#else /* _BIG_ENDIAN_ */
486 u8 antenna_select:1;
487 u8 antenna_select_b:1;
488 u8 r_ant_train_en:1;
489 u8 idle_long:1;
490 u8 rxsc:2;
491 u8 sgi_en:1;
492 u8 antsel_rx_keep_2:1; /* ex_intf_flg:1; */
493#endif
494};
495
496/*
497 * Regs to backup
498 */
499#define RTL8XXXU_ADDA_REGS 16
500#define RTL8XXXU_MAC_REGS 4
501#define RTL8XXXU_BB_REGS 9
502
503struct rtl8xxxu_firmware_header {
504 __le16 signature; /* 92C0: test chip; 92C,
505 88C0: test chip;
506 88C1: MP A-cut;
507 92C1: MP A-cut */
508 u8 category; /* AP/NIC and USB/PCI */
509 u8 function;
510
511 __le16 major_version; /* FW Version */
512 u8 minor_version; /* FW Subversion, default 0x00 */
513 u8 reserved1;
514
515 u8 month; /* Release time Month field */
516 u8 date; /* Release time Date field */
517 u8 hour; /* Release time Hour field */
518 u8 minute; /* Release time Minute field */
519
520 __le16 ramcodesize; /* Size of RAM code */
521 u16 reserved2;
522
523 __le32 svn_idx; /* SVN entry index */
524 u32 reserved3;
525
526 u32 reserved4;
527 u32 reserved5;
528
529 u8 data[0];
530};
531
532/*
533 * The 8723au has 3 channel groups: 1-3, 4-9, and 10-14
534 */
535struct rtl8723au_idx {
536#ifdef __LITTLE_ENDIAN
537 int a:4;
538 int b:4;
539#else
540 int b:4;
541 int a:4;
542#endif
543} __attribute__((packed));
544
545struct rtl8723au_efuse {
546 __le16 rtl_id;
547 u8 res0[0xe];
548 u8 cck_tx_power_index_A[3]; /* 0x10 */
549 u8 cck_tx_power_index_B[3];
550 u8 ht40_1s_tx_power_index_A[3]; /* 0x16 */
551 u8 ht40_1s_tx_power_index_B[3];
552 /*
553 * The following entries are half-bytes split as:
554 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
555 */
556 struct rtl8723au_idx ht20_tx_power_index_diff[3];
557 struct rtl8723au_idx ofdm_tx_power_index_diff[3];
558 struct rtl8723au_idx ht40_max_power_offset[3];
559 struct rtl8723au_idx ht20_max_power_offset[3];
560 u8 channel_plan; /* 0x28 */
561 u8 tssi_a;
562 u8 thermal_meter;
563 u8 rf_regulatory;
564 u8 rf_option_2;
565 u8 rf_option_3;
566 u8 rf_option_4;
567 u8 res7;
568 u8 version /* 0x30 */;
569 u8 customer_id_major;
570 u8 customer_id_minor;
571 u8 xtal_k;
572 u8 chipset; /* 0x34 */
573 u8 res8[0x82];
574 u8 vid; /* 0xb7 */
575 u8 res9;
576 u8 pid; /* 0xb9 */
577 u8 res10[0x0c];
578 u8 mac_addr[ETH_ALEN]; /* 0xc6 */
579 u8 res11[2];
580 u8 vendor_name[7];
581 u8 res12[2];
582 u8 device_name[0x29]; /* 0xd7 */
583};
584
585struct rtl8192cu_efuse {
586 __le16 rtl_id;
587 __le16 hpon;
588 u8 res0[2];
589 __le16 clk;
590 __le16 testr;
591 __le16 vid;
592 __le16 did;
593 __le16 svid;
594 __le16 smid; /* 0x10 */
595 u8 res1[4];
596 u8 mac_addr[ETH_ALEN]; /* 0x16 */
597 u8 res2[2];
598 u8 vendor_name[7];
599 u8 res3[3];
600 u8 device_name[0x14]; /* 0x28 */
601 u8 res4[0x1e]; /* 0x3c */
602 u8 cck_tx_power_index_A[3]; /* 0x5a */
603 u8 cck_tx_power_index_B[3];
604 u8 ht40_1s_tx_power_index_A[3]; /* 0x60 */
605 u8 ht40_1s_tx_power_index_B[3];
606 /*
607 * The following entries are half-bytes split as:
608 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
609 */
610 struct rtl8723au_idx ht40_2s_tx_power_index_diff[3];
611 struct rtl8723au_idx ht20_tx_power_index_diff[3]; /* 0x69 */
612 struct rtl8723au_idx ofdm_tx_power_index_diff[3];
613 struct rtl8723au_idx ht40_max_power_offset[3]; /* 0x6f */
614 struct rtl8723au_idx ht20_max_power_offset[3];
615 u8 channel_plan; /* 0x75 */
616 u8 tssi_a;
617 u8 tssi_b;
618 u8 thermal_meter; /* xtal_k */ /* 0x78 */
619 u8 rf_regulatory;
620 u8 rf_option_2;
621 u8 rf_option_3;
622 u8 rf_option_4;
623 u8 res5[1]; /* 0x7d */
624 u8 version;
625 u8 customer_id;
626};
627
Jes Sorensen3c836d62016-02-29 17:04:11 -0500628struct rtl8723bu_efuse {
629 __le16 rtl_id;
630 u8 res0[0x0e];
631 u8 cck_tx_power_index_A[3]; /* 0x10 */
632 u8 cck_tx_power_index_B[3];
633 u8 ht40_1s_tx_power_index_A[3]; /* 0x16 */
634 u8 ht40_1s_tx_power_index_B[3];
635 u8 res1[0x9c];
636 u8 channel_plan; /* 0xb8 */
637 u8 xtal_k;
638 u8 thermal_meter;
639 u8 iqk_lck;
640 u8 pa_type; /* 0xbc */
641 u8 lna_type_2g; /* 0xbd */
642 u8 res2[3];
643 u8 rf_board_option;
644 u8 rf_feature_option;
645 u8 rf_bt_setting;
646 u8 eeprom_version;
647 u8 eeprom_customer_id;
648 u8 res3[2];
649 u8 tx_pwr_calibrate_rate;
650 u8 rf_antenna_option; /* 0xc9 */
651 u8 rfe_option;
652 u8 res4[9];
653 u8 usb_optional_function;
654 u8 res5[0x1e];
655 u8 res6[2];
656 u8 serial[0x0b]; /* 0xf5 */
657 u8 vid; /* 0x100 */
658 u8 res7;
659 u8 pid;
660 u8 res8[4];
661 u8 mac_addr[ETH_ALEN]; /* 0x107 */
662 u8 res9[2];
663 u8 vendor_name[0x07];
664 u8 res10[2];
Jes Sorensen22a31d42016-02-29 17:04:15 -0500665 u8 device_name[0x14];
666 u8 res11[0xcf];
667 u8 package_type; /* 0x1fb */
668 u8 res12[0x4];
Jes Sorensen3c836d62016-02-29 17:04:11 -0500669};
670
Jakub Sitnickie6f9a9c2016-02-29 17:04:39 -0500671struct rtl8192eu_efuse_tx_power {
672 u8 cck_base[6];
673 u8 ht40_base[5];
674 struct rtl8723au_idx ht20_ofdm_1s_diff;
675 struct rtl8723au_idx ht40_ht20_2s_diff;
676 struct rtl8723au_idx ofdm_cck_2s_diff; /* not used */
677 struct rtl8723au_idx ht40_ht20_3s_diff;
678 struct rtl8723au_idx ofdm_cck_3s_diff; /* not used */
679 struct rtl8723au_idx ht40_ht20_4s_diff;
680 struct rtl8723au_idx ofdm_cck_4s_diff; /* not used */
681};
682
Jes Sorensen3307d842016-02-29 17:03:59 -0500683struct rtl8192eu_efuse {
684 __le16 rtl_id;
685 u8 res0[0x0e];
Jakub Sitnickie6f9a9c2016-02-29 17:04:39 -0500686 struct rtl8192eu_efuse_tx_power tx_power_index_A; /* 0x10 */
687 struct rtl8192eu_efuse_tx_power tx_power_index_B; /* 0x22 */
688 struct rtl8192eu_efuse_tx_power tx_power_index_C; /* 0x34 */
689 struct rtl8192eu_efuse_tx_power tx_power_index_D; /* 0x46 */
690 u8 res1[0x60];
Jes Sorensen3307d842016-02-29 17:03:59 -0500691 u8 channel_plan; /* 0xb8 */
692 u8 xtal_k;
693 u8 thermal_meter;
694 u8 iqk_lck;
695 u8 pa_type; /* 0xbc */
696 u8 lna_type_2g; /* 0xbd */
697 u8 res2[1];
698 u8 lna_type_5g; /* 0xbf */
699 u8 res13[1];
700 u8 rf_board_option;
701 u8 rf_feature_option;
702 u8 rf_bt_setting;
703 u8 eeprom_version;
704 u8 eeprom_customer_id;
705 u8 res3[3];
706 u8 rf_antenna_option; /* 0xc9 */
707 u8 res4[6];
708 u8 vid; /* 0xd0 */
709 u8 res5[1];
710 u8 pid; /* 0xd2 */
711 u8 res6[1];
712 u8 usb_optional_function;
713 u8 res7[2];
714 u8 mac_addr[ETH_ALEN]; /* 0xd7 */
715 u8 res8[2];
716 u8 vendor_name[7];
717 u8 res9[2];
718 u8 device_name[0x0b]; /* 0xe8 */
719 u8 res10[2];
720 u8 serial[0x0b]; /* 0xf5 */
721 u8 res11[0x30];
722 u8 unknown[0x0d]; /* 0x130 */
723 u8 res12[0xc3];
724};
725
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400726struct rtl8xxxu_reg8val {
727 u16 reg;
728 u8 val;
729};
730
731struct rtl8xxxu_reg32val {
732 u16 reg;
733 u32 val;
734};
735
736struct rtl8xxxu_rfregval {
737 u8 reg;
738 u32 val;
739};
740
741enum rtl8xxxu_rfpath {
742 RF_A = 0,
743 RF_B = 1,
744};
745
746struct rtl8xxxu_rfregs {
747 u16 hssiparm1;
748 u16 hssiparm2;
749 u16 lssiparm;
750 u16 hspiread;
751 u16 lssiread;
752 u16 rf_sw_ctrl;
753};
754
755#define H2C_MAX_MBOX 4
756#define H2C_EXT BIT(7)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400757#define H2C_JOIN_BSS_DISCONNECT 0
758#define H2C_JOIN_BSS_CONNECT 1
Jes Sorensend940c242016-02-29 17:04:22 -0500759
760/*
761 * H2C (firmware) commands differ between the older generation chips
762 * 8188[cr]u, 819[12]cu, and 8723au, and the more recent chips 8723bu,
763 * 8192[de]u, 8192eu, and 8812.
764 */
765enum h2c_cmd_8723a {
766 H2C_SET_POWER_MODE = 1,
767 H2C_JOIN_BSS_REPORT = 2,
768 H2C_SET_RSSI = 5,
769 H2C_SET_RATE_MASK = (6 | H2C_EXT),
770};
771
772enum h2c_cmd_8723b {
773 /*
774 * Common Class: 000
775 */
776 H2C_8723B_RSVD_PAGE = 0x00,
777 H2C_8723B_MEDIA_STATUS_RPT = 0x01,
778 H2C_8723B_SCAN_ENABLE = 0x02,
779 H2C_8723B_KEEP_ALIVE = 0x03,
780 H2C_8723B_DISCON_DECISION = 0x04,
781 H2C_8723B_PSD_OFFLOAD = 0x05,
782 H2C_8723B_AP_OFFLOAD = 0x08,
783 H2C_8723B_BCN_RSVDPAGE = 0x09,
784 H2C_8723B_PROBERSP_RSVDPAGE = 0x0A,
785 H2C_8723B_FCS_RSVDPAGE = 0x10,
786 H2C_8723B_FCS_INFO = 0x11,
787 H2C_8723B_AP_WOW_GPIO_CTRL = 0x13,
788
789 /*
790 * PoweSave Class: 001
791 */
792 H2C_8723B_SET_PWR_MODE = 0x20,
793 H2C_8723B_PS_TUNING_PARA = 0x21,
794 H2C_8723B_PS_TUNING_PARA2 = 0x22,
795 H2C_8723B_P2P_LPS_PARAM = 0x23,
796 H2C_8723B_P2P_PS_OFFLOAD = 0x24,
797 H2C_8723B_PS_SCAN_ENABLE = 0x25,
798 H2C_8723B_SAP_PS_ = 0x26,
799 H2C_8723B_INACTIVE_PS_ = 0x27,
800 H2C_8723B_FWLPS_IN_IPS_ = 0x28,
801
802 /*
803 * Dynamic Mechanism Class: 010
804 */
805 H2C_8723B_MACID_CFG = 0x40,
806 H2C_8723B_TXBF = 0x41,
807 H2C_8723B_RSSI_SETTING = 0x42,
808 H2C_8723B_AP_REQ_TXRPT = 0x43,
809 H2C_8723B_INIT_RATE_COLLECT = 0x44,
810
811 /*
812 * BT Class: 011
813 */
814 H2C_8723B_B_TYPE_TDMA = 0x60,
815 H2C_8723B_BT_INFO = 0x61,
816 H2C_8723B_FORCE_BT_TXPWR = 0x62,
817 H2C_8723B_BT_IGNORE_WLANACT = 0x63,
818 H2C_8723B_DAC_SWING_VALUE = 0x64,
819 H2C_8723B_ANT_SEL_RSV = 0x65,
820 H2C_8723B_WL_OPMODE = 0x66,
821 H2C_8723B_BT_MP_OPER = 0x67,
822 H2C_8723B_BT_CONTROL = 0x68,
823 H2C_8723B_BT_WIFI_CTRL = 0x69,
Jes Sorensenf37e9222016-02-29 17:04:41 -0500824 H2C_8723B_BT_FW_PATCH = 0x6a,
825 H2C_8723B_BT_WLAN_CALIBRATION = 0x6d,
826 H2C_8723B_BT_GRANT = 0x6e,
Jes Sorensend940c242016-02-29 17:04:22 -0500827
828 /*
829 * WOWLAN Class: 100
830 */
831 H2C_8723B_WOWLAN = 0x80,
832 H2C_8723B_REMOTE_WAKE_CTRL = 0x81,
833 H2C_8723B_AOAC_GLOBAL_INFO = 0x82,
834 H2C_8723B_AOAC_RSVD_PAGE = 0x83,
835 H2C_8723B_AOAC_RSVD_PAGE2 = 0x84,
836 H2C_8723B_D0_SCAN_OFFLOAD_CTRL = 0x85,
837 H2C_8723B_D0_SCAN_OFFLOAD_INFO = 0x86,
838 H2C_8723B_CHNL_SWITCH_OFFLOAD = 0x87,
839
840 H2C_8723B_RESET_TSF = 0xC0,
841};
842
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400843
844struct h2c_cmd {
845 union {
846 struct {
847 u8 cmd;
Jes Sorensened35d092016-02-29 17:04:19 -0500848 u8 data[7];
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400849 } __packed cmd;
850 struct {
851 __le32 data;
852 __le16 ext;
853 } __packed raw;
854 struct {
Jes Sorensened35d092016-02-29 17:04:19 -0500855 __le32 data;
856 __le32 ext;
857 } __packed raw_wide;
858 struct {
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400859 u8 cmd;
860 u8 data;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400861 } __packed joinbss;
862 struct {
863 u8 cmd;
864 __le16 mask_hi;
865 u8 arg;
866 __le16 mask_lo;
867 } __packed ramask;
Jes Sorensenc7a5a192016-02-29 17:04:30 -0500868 struct {
869 u8 cmd;
Jes Sorensen3ca7b322016-02-29 17:04:43 -0500870 u8 data1;
871 u8 data2;
872 u8 data3;
873 u8 data4;
874 u8 data5;
875 } __packed b_type_dma;
876 struct {
877 u8 cmd;
Jes Sorensenc7a5a192016-02-29 17:04:30 -0500878 u8 data;
879 } __packed bt_wlan_calibration;
Jes Sorensenf37e9222016-02-29 17:04:41 -0500880 struct {
881 u8 cmd;
Jes Sorensen7297f492016-02-29 17:04:44 -0500882 u8 data;
883 } __packed ignore_wlan;
884 struct {
885 u8 cmd;
Jes Sorensenf37e9222016-02-29 17:04:41 -0500886 u8 ant_inverse;
887 u8 int_switch_type;
888 } __packed ant_sel_rsv;
889 struct {
890 u8 cmd;
891 u8 data;
892 } __packed bt_grant;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400893 };
894};
895
896struct rtl8xxxu_fileops;
897
898struct rtl8xxxu_priv {
899 struct ieee80211_hw *hw;
900 struct usb_device *udev;
901 struct rtl8xxxu_fileops *fops;
902
903 spinlock_t tx_urb_lock;
904 struct list_head tx_urb_free_list;
905 int tx_urb_free_count;
906 bool tx_stopped;
907
908 spinlock_t rx_urb_lock;
909 struct list_head rx_urb_pending_list;
910 int rx_urb_pending_count;
911 bool shutdown;
912 struct work_struct rx_urb_wq;
913
914 u8 mac_addr[ETH_ALEN];
915 char chip_name[8];
Jes Sorensen0e5d4352016-02-29 17:04:00 -0500916 char chip_vendor[8];
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400917 u8 cck_tx_power_index_A[3]; /* 0x10 */
918 u8 cck_tx_power_index_B[3];
919 u8 ht40_1s_tx_power_index_A[3]; /* 0x16 */
920 u8 ht40_1s_tx_power_index_B[3];
921 /*
922 * The following entries are half-bytes split as:
923 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
924 */
925 struct rtl8723au_idx ht40_2s_tx_power_index_diff[3];
926 struct rtl8723au_idx ht20_tx_power_index_diff[3];
927 struct rtl8723au_idx ofdm_tx_power_index_diff[3];
928 struct rtl8723au_idx ht40_max_power_offset[3];
929 struct rtl8723au_idx ht20_max_power_offset[3];
930 u32 chip_cut:4;
931 u32 rom_rev:4;
Jakub Sitnicki38451992016-02-03 13:39:49 -0500932 u32 is_multi_func:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400933 u32 has_wifi:1;
934 u32 has_bluetooth:1;
935 u32 enable_bluetooth:1;
936 u32 has_gps:1;
937 u32 hi_pa:1;
938 u32 vendor_umc:1;
Jes Sorensen0e5d4352016-02-29 17:04:00 -0500939 u32 vendor_smic:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400940 u32 has_polarity_ctrl:1;
941 u32 has_eeprom:1;
942 u32 boot_eeprom:1;
Jes Sorensen0e28b972016-02-29 17:04:13 -0500943 u32 usb_interrupts:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400944 u32 ep_tx_high_queue:1;
945 u32 ep_tx_normal_queue:1;
946 u32 ep_tx_low_queue:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400947 unsigned int pipe_interrupt;
948 unsigned int pipe_in;
949 unsigned int pipe_out[TXDESC_QUEUE_MAX];
950 u8 out_ep[RTL8XXXU_OUT_ENDPOINTS];
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400951 u8 ep_tx_count;
952 u8 rf_paths;
953 u8 rx_paths;
954 u8 tx_paths;
955 u32 rf_mode_ag[2];
956 u32 rege94;
957 u32 rege9c;
958 u32 regeb4;
959 u32 regebc;
960 int next_mbox;
961 int nr_out_eps;
962
963 struct mutex h2c_mutex;
964
965 struct usb_anchor rx_anchor;
966 struct usb_anchor tx_anchor;
967 struct usb_anchor int_anchor;
968 struct rtl8xxxu_firmware_header *fw_data;
969 size_t fw_size;
970 struct mutex usb_buf_mutex;
971 union {
972 __le32 val32;
973 __le16 val16;
974 u8 val8;
975 } usb_buf;
976 union {
Jes Sorensen3307d842016-02-29 17:03:59 -0500977 u8 raw[EFUSE_MAP_LEN];
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400978 struct rtl8723au_efuse efuse8723;
Jes Sorensen3c836d62016-02-29 17:04:11 -0500979 struct rtl8723bu_efuse efuse8723bu;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400980 struct rtl8192cu_efuse efuse8192;
Jes Sorensen3307d842016-02-29 17:03:59 -0500981 struct rtl8192eu_efuse efuse8192eu;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400982 } efuse_wifi;
983 u32 adda_backup[RTL8XXXU_ADDA_REGS];
984 u32 mac_backup[RTL8XXXU_MAC_REGS];
985 u32 bb_backup[RTL8XXXU_BB_REGS];
986 u32 bb_recovery_backup[RTL8XXXU_BB_REGS];
987 u32 rtlchip;
988 u8 pi_enabled:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400989 u8 int_buf[USB_INTR_CONTENT_LENGTH];
990};
991
992struct rtl8xxxu_rx_urb {
993 struct urb urb;
994 struct ieee80211_hw *hw;
995 struct list_head list;
996};
997
998struct rtl8xxxu_tx_urb {
999 struct urb urb;
1000 struct ieee80211_hw *hw;
1001 struct list_head list;
1002};
1003
1004struct rtl8xxxu_fileops {
1005 int (*parse_efuse) (struct rtl8xxxu_priv *priv);
1006 int (*load_firmware) (struct rtl8xxxu_priv *priv);
1007 int (*power_on) (struct rtl8xxxu_priv *priv);
Jes Sorensen74b99be2016-02-29 17:04:04 -05001008 int (*llt_init) (struct rtl8xxxu_priv *priv, u8 last_tx_page);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05001009 void (*phy_init_antenna_selection) (struct rtl8xxxu_priv *priv);
Jes Sorensene1547c52016-02-29 17:04:35 -05001010 void (*phy_iq_calibrate) (struct rtl8xxxu_priv *priv);
Jes Sorensenc3f95062016-02-29 17:04:40 -05001011 void (*config_channel) (struct ieee80211_hw *hw);
Jes Sorensenf37e9222016-02-29 17:04:41 -05001012 void (*init_bt) (struct rtl8xxxu_priv *priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001013 int writeN_block_size;
Jes Sorensened35d092016-02-29 17:04:19 -05001014 u16 mbox_ext_reg;
1015 char mbox_ext_width;
Jes Sorensen0d698de2016-02-29 17:04:36 -05001016 char has_s0s1;
Jes Sorensen8634af52016-02-29 17:04:33 -05001017 u32 adda_1t_init;
1018 u32 adda_1t_path_on;
1019 u32 adda_2t_path_on_a;
1020 u32 adda_2t_path_on_b;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001021};