blob: c4c0b287127bf205a8db51e95507b5463a6083a5 [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
200struct rtl8xxxu_tx_desc {
201 __le16 pkt_size;
202 u8 pkt_offset;
203 u8 txdw0;
204 __le32 txdw1;
205 __le32 txdw2;
206 __le32 txdw3;
207 __le32 txdw4;
208 __le32 txdw5;
209 __le32 txdw6;
210 __le16 csum;
211 __le16 txdw7;
212};
213
214/* CCK Rates, TxHT = 0 */
215#define DESC_RATE_1M 0x00
216#define DESC_RATE_2M 0x01
217#define DESC_RATE_5_5M 0x02
218#define DESC_RATE_11M 0x03
219
220/* OFDM Rates, TxHT = 0 */
221#define DESC_RATE_6M 0x04
222#define DESC_RATE_9M 0x05
223#define DESC_RATE_12M 0x06
224#define DESC_RATE_18M 0x07
225#define DESC_RATE_24M 0x08
226#define DESC_RATE_36M 0x09
227#define DESC_RATE_48M 0x0a
228#define DESC_RATE_54M 0x0b
229
230/* MCS Rates, TxHT = 1 */
231#define DESC_RATE_MCS0 0x0c
232#define DESC_RATE_MCS1 0x0d
233#define DESC_RATE_MCS2 0x0e
234#define DESC_RATE_MCS3 0x0f
235#define DESC_RATE_MCS4 0x10
236#define DESC_RATE_MCS5 0x11
237#define DESC_RATE_MCS6 0x12
238#define DESC_RATE_MCS7 0x13
239#define DESC_RATE_MCS8 0x14
240#define DESC_RATE_MCS9 0x15
241#define DESC_RATE_MCS10 0x16
242#define DESC_RATE_MCS11 0x17
243#define DESC_RATE_MCS12 0x18
244#define DESC_RATE_MCS13 0x19
245#define DESC_RATE_MCS14 0x1a
246#define DESC_RATE_MCS15 0x1b
247#define DESC_RATE_MCS15_SG 0x1c
248#define DESC_RATE_MCS32 0x20
249
250#define TXDESC_OFFSET_SZ 0
251#define TXDESC_OFFSET_SHT 16
252#if 0
253#define TXDESC_BMC BIT(24)
254#define TXDESC_LSG BIT(26)
255#define TXDESC_FSG BIT(27)
256#define TXDESC_OWN BIT(31)
257#else
258#define TXDESC_BROADMULTICAST BIT(0)
259#define TXDESC_LAST_SEGMENT BIT(2)
260#define TXDESC_FIRST_SEGMENT BIT(3)
261#define TXDESC_OWN BIT(7)
262#endif
263
264/* Word 1 */
265#define TXDESC_PKT_OFFSET_SZ 0
266#define TXDESC_AGG_ENABLE BIT(5)
267#define TXDESC_BK BIT(6)
268#define TXDESC_QUEUE_SHIFT 8
269#define TXDESC_QUEUE_MASK 0x1f00
270#define TXDESC_QUEUE_BK 0x2
271#define TXDESC_QUEUE_BE 0x0
272#define TXDESC_QUEUE_VI 0x5
273#define TXDESC_QUEUE_VO 0x7
274#define TXDESC_QUEUE_BEACON 0x10
275#define TXDESC_QUEUE_HIGH 0x11
276#define TXDESC_QUEUE_MGNT 0x12
277#define TXDESC_QUEUE_CMD 0x13
278#define TXDESC_QUEUE_MAX (TXDESC_QUEUE_CMD + 1)
279
280#define DESC_RATE_ID_SHIFT 16
281#define DESC_RATE_ID_MASK 0xf
282#define TXDESC_NAVUSEHDR BIT(20)
283#define TXDESC_SEC_RC4 0x00400000
284#define TXDESC_SEC_AES 0x00c00000
285#define TXDESC_PKT_OFFSET_SHIFT 26
286#define TXDESC_AGG_EN BIT(29)
287#define TXDESC_HWPC BIT(31)
288
289/* Word 2 */
290#define TXDESC_ACK_REPORT BIT(19)
291#define TXDESC_AMPDU_DENSITY_SHIFT 20
292
293/* Word 3 */
294#define TXDESC_SEQ_SHIFT 16
295#define TXDESC_SEQ_MASK 0x0fff0000
296
297/* Word 4 */
298#define TXDESC_QOS BIT(6)
299#define TXDESC_HW_SEQ_ENABLE BIT(7)
300#define TXDESC_USE_DRIVER_RATE BIT(8)
301#define TXDESC_DISABLE_DATA_FB BIT(10)
302#define TXDESC_CTS_SELF_ENABLE BIT(11)
303#define TXDESC_RTS_CTS_ENABLE BIT(12)
304#define TXDESC_HW_RTS_ENABLE BIT(13)
305#define TXDESC_PRIME_CH_OFF_LOWER BIT(20)
306#define TXDESC_PRIME_CH_OFF_UPPER BIT(21)
307#define TXDESC_SHORT_PREAMBLE BIT(24)
308#define TXDESC_DATA_BW BIT(25)
309#define TXDESC_RTS_DATA_BW BIT(27)
310#define TXDESC_RTS_PRIME_CH_OFF_LOWER BIT(28)
311#define TXDESC_RTS_PRIME_CH_OFF_UPPER BIT(29)
312
313/* Word 5 */
314#define TXDESC_RTS_RATE_SHIFT 0
315#define TXDESC_RTS_RATE_MASK 0x3f
316#define TXDESC_SHORT_GI BIT(6)
317#define TXDESC_CCX_TAG BIT(7)
318#define TXDESC_RETRY_LIMIT_ENABLE BIT(17)
319#define TXDESC_RETRY_LIMIT_SHIFT 18
320#define TXDESC_RETRY_LIMIT_MASK 0x00fc0000
321
322/* Word 6 */
323#define TXDESC_MAX_AGG_SHIFT 11
324
325struct phy_rx_agc_info {
326#ifdef __LITTLE_ENDIAN
327 u8 gain:7, trsw:1;
328#else
329 u8 trsw:1, gain:7;
330#endif
331};
332
333struct rtl8723au_phy_stats {
334 struct phy_rx_agc_info path_agc[RTL8723A_MAX_RF_PATHS];
335 u8 ch_corr[RTL8723A_MAX_RF_PATHS];
336 u8 cck_sig_qual_ofdm_pwdb_all;
337 u8 cck_agc_rpt_ofdm_cfosho_a;
338 u8 cck_rpt_b_ofdm_cfosho_b;
339 u8 reserved_1;
340 u8 noise_power_db_msb;
341 u8 path_cfotail[RTL8723A_MAX_RF_PATHS];
342 u8 pcts_mask[RTL8723A_MAX_RF_PATHS];
343 s8 stream_rxevm[RTL8723A_MAX_RF_PATHS];
344 u8 path_rxsnr[RTL8723A_MAX_RF_PATHS];
345 u8 noise_power_db_lsb;
346 u8 reserved_2[3];
347 u8 stream_csi[RTL8723A_MAX_RF_PATHS];
348 u8 stream_target_csi[RTL8723A_MAX_RF_PATHS];
349 s8 sig_evm;
350 u8 reserved_3;
351
352#ifdef __LITTLE_ENDIAN
353 u8 antsel_rx_keep_2:1; /* ex_intf_flg:1; */
354 u8 sgi_en:1;
355 u8 rxsc:2;
356 u8 idle_long:1;
357 u8 r_ant_train_en:1;
358 u8 antenna_select_b:1;
359 u8 antenna_select:1;
360#else /* _BIG_ENDIAN_ */
361 u8 antenna_select:1;
362 u8 antenna_select_b:1;
363 u8 r_ant_train_en:1;
364 u8 idle_long:1;
365 u8 rxsc:2;
366 u8 sgi_en:1;
367 u8 antsel_rx_keep_2:1; /* ex_intf_flg:1; */
368#endif
369};
370
371/*
372 * Regs to backup
373 */
374#define RTL8XXXU_ADDA_REGS 16
375#define RTL8XXXU_MAC_REGS 4
376#define RTL8XXXU_BB_REGS 9
377
378struct rtl8xxxu_firmware_header {
379 __le16 signature; /* 92C0: test chip; 92C,
380 88C0: test chip;
381 88C1: MP A-cut;
382 92C1: MP A-cut */
383 u8 category; /* AP/NIC and USB/PCI */
384 u8 function;
385
386 __le16 major_version; /* FW Version */
387 u8 minor_version; /* FW Subversion, default 0x00 */
388 u8 reserved1;
389
390 u8 month; /* Release time Month field */
391 u8 date; /* Release time Date field */
392 u8 hour; /* Release time Hour field */
393 u8 minute; /* Release time Minute field */
394
395 __le16 ramcodesize; /* Size of RAM code */
396 u16 reserved2;
397
398 __le32 svn_idx; /* SVN entry index */
399 u32 reserved3;
400
401 u32 reserved4;
402 u32 reserved5;
403
404 u8 data[0];
405};
406
407/*
408 * The 8723au has 3 channel groups: 1-3, 4-9, and 10-14
409 */
410struct rtl8723au_idx {
411#ifdef __LITTLE_ENDIAN
412 int a:4;
413 int b:4;
414#else
415 int b:4;
416 int a:4;
417#endif
418} __attribute__((packed));
419
420struct rtl8723au_efuse {
421 __le16 rtl_id;
422 u8 res0[0xe];
423 u8 cck_tx_power_index_A[3]; /* 0x10 */
424 u8 cck_tx_power_index_B[3];
425 u8 ht40_1s_tx_power_index_A[3]; /* 0x16 */
426 u8 ht40_1s_tx_power_index_B[3];
427 /*
428 * The following entries are half-bytes split as:
429 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
430 */
431 struct rtl8723au_idx ht20_tx_power_index_diff[3];
432 struct rtl8723au_idx ofdm_tx_power_index_diff[3];
433 struct rtl8723au_idx ht40_max_power_offset[3];
434 struct rtl8723au_idx ht20_max_power_offset[3];
435 u8 channel_plan; /* 0x28 */
436 u8 tssi_a;
437 u8 thermal_meter;
438 u8 rf_regulatory;
439 u8 rf_option_2;
440 u8 rf_option_3;
441 u8 rf_option_4;
442 u8 res7;
443 u8 version /* 0x30 */;
444 u8 customer_id_major;
445 u8 customer_id_minor;
446 u8 xtal_k;
447 u8 chipset; /* 0x34 */
448 u8 res8[0x82];
449 u8 vid; /* 0xb7 */
450 u8 res9;
451 u8 pid; /* 0xb9 */
452 u8 res10[0x0c];
453 u8 mac_addr[ETH_ALEN]; /* 0xc6 */
454 u8 res11[2];
455 u8 vendor_name[7];
456 u8 res12[2];
457 u8 device_name[0x29]; /* 0xd7 */
458};
459
460struct rtl8192cu_efuse {
461 __le16 rtl_id;
462 __le16 hpon;
463 u8 res0[2];
464 __le16 clk;
465 __le16 testr;
466 __le16 vid;
467 __le16 did;
468 __le16 svid;
469 __le16 smid; /* 0x10 */
470 u8 res1[4];
471 u8 mac_addr[ETH_ALEN]; /* 0x16 */
472 u8 res2[2];
473 u8 vendor_name[7];
474 u8 res3[3];
475 u8 device_name[0x14]; /* 0x28 */
476 u8 res4[0x1e]; /* 0x3c */
477 u8 cck_tx_power_index_A[3]; /* 0x5a */
478 u8 cck_tx_power_index_B[3];
479 u8 ht40_1s_tx_power_index_A[3]; /* 0x60 */
480 u8 ht40_1s_tx_power_index_B[3];
481 /*
482 * The following entries are half-bytes split as:
483 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
484 */
485 struct rtl8723au_idx ht40_2s_tx_power_index_diff[3];
486 struct rtl8723au_idx ht20_tx_power_index_diff[3]; /* 0x69 */
487 struct rtl8723au_idx ofdm_tx_power_index_diff[3];
488 struct rtl8723au_idx ht40_max_power_offset[3]; /* 0x6f */
489 struct rtl8723au_idx ht20_max_power_offset[3];
490 u8 channel_plan; /* 0x75 */
491 u8 tssi_a;
492 u8 tssi_b;
493 u8 thermal_meter; /* xtal_k */ /* 0x78 */
494 u8 rf_regulatory;
495 u8 rf_option_2;
496 u8 rf_option_3;
497 u8 rf_option_4;
498 u8 res5[1]; /* 0x7d */
499 u8 version;
500 u8 customer_id;
501};
502
Jes Sorensen3c836d62016-02-29 17:04:11 -0500503struct rtl8723bu_efuse {
504 __le16 rtl_id;
505 u8 res0[0x0e];
506 u8 cck_tx_power_index_A[3]; /* 0x10 */
507 u8 cck_tx_power_index_B[3];
508 u8 ht40_1s_tx_power_index_A[3]; /* 0x16 */
509 u8 ht40_1s_tx_power_index_B[3];
510 u8 res1[0x9c];
511 u8 channel_plan; /* 0xb8 */
512 u8 xtal_k;
513 u8 thermal_meter;
514 u8 iqk_lck;
515 u8 pa_type; /* 0xbc */
516 u8 lna_type_2g; /* 0xbd */
517 u8 res2[3];
518 u8 rf_board_option;
519 u8 rf_feature_option;
520 u8 rf_bt_setting;
521 u8 eeprom_version;
522 u8 eeprom_customer_id;
523 u8 res3[2];
524 u8 tx_pwr_calibrate_rate;
525 u8 rf_antenna_option; /* 0xc9 */
526 u8 rfe_option;
527 u8 res4[9];
528 u8 usb_optional_function;
529 u8 res5[0x1e];
530 u8 res6[2];
531 u8 serial[0x0b]; /* 0xf5 */
532 u8 vid; /* 0x100 */
533 u8 res7;
534 u8 pid;
535 u8 res8[4];
536 u8 mac_addr[ETH_ALEN]; /* 0x107 */
537 u8 res9[2];
538 u8 vendor_name[0x07];
539 u8 res10[2];
Jes Sorensen22a31d42016-02-29 17:04:15 -0500540 u8 device_name[0x14];
541 u8 res11[0xcf];
542 u8 package_type; /* 0x1fb */
543 u8 res12[0x4];
Jes Sorensen3c836d62016-02-29 17:04:11 -0500544};
545
Jakub Sitnickie6f9a9c2016-02-29 17:04:39 -0500546struct rtl8192eu_efuse_tx_power {
547 u8 cck_base[6];
548 u8 ht40_base[5];
549 struct rtl8723au_idx ht20_ofdm_1s_diff;
550 struct rtl8723au_idx ht40_ht20_2s_diff;
551 struct rtl8723au_idx ofdm_cck_2s_diff; /* not used */
552 struct rtl8723au_idx ht40_ht20_3s_diff;
553 struct rtl8723au_idx ofdm_cck_3s_diff; /* not used */
554 struct rtl8723au_idx ht40_ht20_4s_diff;
555 struct rtl8723au_idx ofdm_cck_4s_diff; /* not used */
556};
557
Jes Sorensen3307d842016-02-29 17:03:59 -0500558struct rtl8192eu_efuse {
559 __le16 rtl_id;
560 u8 res0[0x0e];
Jakub Sitnickie6f9a9c2016-02-29 17:04:39 -0500561 struct rtl8192eu_efuse_tx_power tx_power_index_A; /* 0x10 */
562 struct rtl8192eu_efuse_tx_power tx_power_index_B; /* 0x22 */
563 struct rtl8192eu_efuse_tx_power tx_power_index_C; /* 0x34 */
564 struct rtl8192eu_efuse_tx_power tx_power_index_D; /* 0x46 */
565 u8 res1[0x60];
Jes Sorensen3307d842016-02-29 17:03:59 -0500566 u8 channel_plan; /* 0xb8 */
567 u8 xtal_k;
568 u8 thermal_meter;
569 u8 iqk_lck;
570 u8 pa_type; /* 0xbc */
571 u8 lna_type_2g; /* 0xbd */
572 u8 res2[1];
573 u8 lna_type_5g; /* 0xbf */
574 u8 res13[1];
575 u8 rf_board_option;
576 u8 rf_feature_option;
577 u8 rf_bt_setting;
578 u8 eeprom_version;
579 u8 eeprom_customer_id;
580 u8 res3[3];
581 u8 rf_antenna_option; /* 0xc9 */
582 u8 res4[6];
583 u8 vid; /* 0xd0 */
584 u8 res5[1];
585 u8 pid; /* 0xd2 */
586 u8 res6[1];
587 u8 usb_optional_function;
588 u8 res7[2];
589 u8 mac_addr[ETH_ALEN]; /* 0xd7 */
590 u8 res8[2];
591 u8 vendor_name[7];
592 u8 res9[2];
593 u8 device_name[0x0b]; /* 0xe8 */
594 u8 res10[2];
595 u8 serial[0x0b]; /* 0xf5 */
596 u8 res11[0x30];
597 u8 unknown[0x0d]; /* 0x130 */
598 u8 res12[0xc3];
599};
600
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400601struct rtl8xxxu_reg8val {
602 u16 reg;
603 u8 val;
604};
605
606struct rtl8xxxu_reg32val {
607 u16 reg;
608 u32 val;
609};
610
611struct rtl8xxxu_rfregval {
612 u8 reg;
613 u32 val;
614};
615
616enum rtl8xxxu_rfpath {
617 RF_A = 0,
618 RF_B = 1,
619};
620
621struct rtl8xxxu_rfregs {
622 u16 hssiparm1;
623 u16 hssiparm2;
624 u16 lssiparm;
625 u16 hspiread;
626 u16 lssiread;
627 u16 rf_sw_ctrl;
628};
629
630#define H2C_MAX_MBOX 4
631#define H2C_EXT BIT(7)
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400632#define H2C_JOIN_BSS_DISCONNECT 0
633#define H2C_JOIN_BSS_CONNECT 1
Jes Sorensend940c242016-02-29 17:04:22 -0500634
635/*
636 * H2C (firmware) commands differ between the older generation chips
637 * 8188[cr]u, 819[12]cu, and 8723au, and the more recent chips 8723bu,
638 * 8192[de]u, 8192eu, and 8812.
639 */
640enum h2c_cmd_8723a {
641 H2C_SET_POWER_MODE = 1,
642 H2C_JOIN_BSS_REPORT = 2,
643 H2C_SET_RSSI = 5,
644 H2C_SET_RATE_MASK = (6 | H2C_EXT),
645};
646
647enum h2c_cmd_8723b {
648 /*
649 * Common Class: 000
650 */
651 H2C_8723B_RSVD_PAGE = 0x00,
652 H2C_8723B_MEDIA_STATUS_RPT = 0x01,
653 H2C_8723B_SCAN_ENABLE = 0x02,
654 H2C_8723B_KEEP_ALIVE = 0x03,
655 H2C_8723B_DISCON_DECISION = 0x04,
656 H2C_8723B_PSD_OFFLOAD = 0x05,
657 H2C_8723B_AP_OFFLOAD = 0x08,
658 H2C_8723B_BCN_RSVDPAGE = 0x09,
659 H2C_8723B_PROBERSP_RSVDPAGE = 0x0A,
660 H2C_8723B_FCS_RSVDPAGE = 0x10,
661 H2C_8723B_FCS_INFO = 0x11,
662 H2C_8723B_AP_WOW_GPIO_CTRL = 0x13,
663
664 /*
665 * PoweSave Class: 001
666 */
667 H2C_8723B_SET_PWR_MODE = 0x20,
668 H2C_8723B_PS_TUNING_PARA = 0x21,
669 H2C_8723B_PS_TUNING_PARA2 = 0x22,
670 H2C_8723B_P2P_LPS_PARAM = 0x23,
671 H2C_8723B_P2P_PS_OFFLOAD = 0x24,
672 H2C_8723B_PS_SCAN_ENABLE = 0x25,
673 H2C_8723B_SAP_PS_ = 0x26,
674 H2C_8723B_INACTIVE_PS_ = 0x27,
675 H2C_8723B_FWLPS_IN_IPS_ = 0x28,
676
677 /*
678 * Dynamic Mechanism Class: 010
679 */
680 H2C_8723B_MACID_CFG = 0x40,
681 H2C_8723B_TXBF = 0x41,
682 H2C_8723B_RSSI_SETTING = 0x42,
683 H2C_8723B_AP_REQ_TXRPT = 0x43,
684 H2C_8723B_INIT_RATE_COLLECT = 0x44,
685
686 /*
687 * BT Class: 011
688 */
689 H2C_8723B_B_TYPE_TDMA = 0x60,
690 H2C_8723B_BT_INFO = 0x61,
691 H2C_8723B_FORCE_BT_TXPWR = 0x62,
692 H2C_8723B_BT_IGNORE_WLANACT = 0x63,
693 H2C_8723B_DAC_SWING_VALUE = 0x64,
694 H2C_8723B_ANT_SEL_RSV = 0x65,
695 H2C_8723B_WL_OPMODE = 0x66,
696 H2C_8723B_BT_MP_OPER = 0x67,
697 H2C_8723B_BT_CONTROL = 0x68,
698 H2C_8723B_BT_WIFI_CTRL = 0x69,
Jes Sorensenf37e9222016-02-29 17:04:41 -0500699 H2C_8723B_BT_FW_PATCH = 0x6a,
700 H2C_8723B_BT_WLAN_CALIBRATION = 0x6d,
701 H2C_8723B_BT_GRANT = 0x6e,
Jes Sorensend940c242016-02-29 17:04:22 -0500702
703 /*
704 * WOWLAN Class: 100
705 */
706 H2C_8723B_WOWLAN = 0x80,
707 H2C_8723B_REMOTE_WAKE_CTRL = 0x81,
708 H2C_8723B_AOAC_GLOBAL_INFO = 0x82,
709 H2C_8723B_AOAC_RSVD_PAGE = 0x83,
710 H2C_8723B_AOAC_RSVD_PAGE2 = 0x84,
711 H2C_8723B_D0_SCAN_OFFLOAD_CTRL = 0x85,
712 H2C_8723B_D0_SCAN_OFFLOAD_INFO = 0x86,
713 H2C_8723B_CHNL_SWITCH_OFFLOAD = 0x87,
714
715 H2C_8723B_RESET_TSF = 0xC0,
716};
717
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400718
719struct h2c_cmd {
720 union {
721 struct {
722 u8 cmd;
Jes Sorensened35d092016-02-29 17:04:19 -0500723 u8 data[7];
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400724 } __packed cmd;
725 struct {
726 __le32 data;
727 __le16 ext;
728 } __packed raw;
729 struct {
Jes Sorensened35d092016-02-29 17:04:19 -0500730 __le32 data;
731 __le32 ext;
732 } __packed raw_wide;
733 struct {
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400734 u8 cmd;
735 u8 data;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400736 } __packed joinbss;
737 struct {
738 u8 cmd;
739 __le16 mask_hi;
740 u8 arg;
741 __le16 mask_lo;
742 } __packed ramask;
Jes Sorensenc7a5a192016-02-29 17:04:30 -0500743 struct {
744 u8 cmd;
Jes Sorensen3ca7b322016-02-29 17:04:43 -0500745 u8 data1;
746 u8 data2;
747 u8 data3;
748 u8 data4;
749 u8 data5;
750 } __packed b_type_dma;
751 struct {
752 u8 cmd;
Jes Sorensenc7a5a192016-02-29 17:04:30 -0500753 u8 data;
754 } __packed bt_wlan_calibration;
Jes Sorensenf37e9222016-02-29 17:04:41 -0500755 struct {
756 u8 cmd;
757 u8 ant_inverse;
758 u8 int_switch_type;
759 } __packed ant_sel_rsv;
760 struct {
761 u8 cmd;
762 u8 data;
763 } __packed bt_grant;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400764 };
765};
766
767struct rtl8xxxu_fileops;
768
769struct rtl8xxxu_priv {
770 struct ieee80211_hw *hw;
771 struct usb_device *udev;
772 struct rtl8xxxu_fileops *fops;
773
774 spinlock_t tx_urb_lock;
775 struct list_head tx_urb_free_list;
776 int tx_urb_free_count;
777 bool tx_stopped;
778
779 spinlock_t rx_urb_lock;
780 struct list_head rx_urb_pending_list;
781 int rx_urb_pending_count;
782 bool shutdown;
783 struct work_struct rx_urb_wq;
784
785 u8 mac_addr[ETH_ALEN];
786 char chip_name[8];
Jes Sorensen0e5d4352016-02-29 17:04:00 -0500787 char chip_vendor[8];
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400788 u8 cck_tx_power_index_A[3]; /* 0x10 */
789 u8 cck_tx_power_index_B[3];
790 u8 ht40_1s_tx_power_index_A[3]; /* 0x16 */
791 u8 ht40_1s_tx_power_index_B[3];
792 /*
793 * The following entries are half-bytes split as:
794 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
795 */
796 struct rtl8723au_idx ht40_2s_tx_power_index_diff[3];
797 struct rtl8723au_idx ht20_tx_power_index_diff[3];
798 struct rtl8723au_idx ofdm_tx_power_index_diff[3];
799 struct rtl8723au_idx ht40_max_power_offset[3];
800 struct rtl8723au_idx ht20_max_power_offset[3];
801 u32 chip_cut:4;
802 u32 rom_rev:4;
Jakub Sitnicki38451992016-02-03 13:39:49 -0500803 u32 is_multi_func:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400804 u32 has_wifi:1;
805 u32 has_bluetooth:1;
806 u32 enable_bluetooth:1;
807 u32 has_gps:1;
808 u32 hi_pa:1;
809 u32 vendor_umc:1;
Jes Sorensen0e5d4352016-02-29 17:04:00 -0500810 u32 vendor_smic:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400811 u32 has_polarity_ctrl:1;
812 u32 has_eeprom:1;
813 u32 boot_eeprom:1;
Jes Sorensen0e28b972016-02-29 17:04:13 -0500814 u32 usb_interrupts:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400815 u32 ep_tx_high_queue:1;
816 u32 ep_tx_normal_queue:1;
817 u32 ep_tx_low_queue:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400818 unsigned int pipe_interrupt;
819 unsigned int pipe_in;
820 unsigned int pipe_out[TXDESC_QUEUE_MAX];
821 u8 out_ep[RTL8XXXU_OUT_ENDPOINTS];
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400822 u8 ep_tx_count;
823 u8 rf_paths;
824 u8 rx_paths;
825 u8 tx_paths;
826 u32 rf_mode_ag[2];
827 u32 rege94;
828 u32 rege9c;
829 u32 regeb4;
830 u32 regebc;
831 int next_mbox;
832 int nr_out_eps;
833
834 struct mutex h2c_mutex;
835
836 struct usb_anchor rx_anchor;
837 struct usb_anchor tx_anchor;
838 struct usb_anchor int_anchor;
839 struct rtl8xxxu_firmware_header *fw_data;
840 size_t fw_size;
841 struct mutex usb_buf_mutex;
842 union {
843 __le32 val32;
844 __le16 val16;
845 u8 val8;
846 } usb_buf;
847 union {
Jes Sorensen3307d842016-02-29 17:03:59 -0500848 u8 raw[EFUSE_MAP_LEN];
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400849 struct rtl8723au_efuse efuse8723;
Jes Sorensen3c836d62016-02-29 17:04:11 -0500850 struct rtl8723bu_efuse efuse8723bu;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400851 struct rtl8192cu_efuse efuse8192;
Jes Sorensen3307d842016-02-29 17:03:59 -0500852 struct rtl8192eu_efuse efuse8192eu;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400853 } efuse_wifi;
854 u32 adda_backup[RTL8XXXU_ADDA_REGS];
855 u32 mac_backup[RTL8XXXU_MAC_REGS];
856 u32 bb_backup[RTL8XXXU_BB_REGS];
857 u32 bb_recovery_backup[RTL8XXXU_BB_REGS];
858 u32 rtlchip;
859 u8 pi_enabled:1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400860 u8 int_buf[USB_INTR_CONTENT_LENGTH];
861};
862
863struct rtl8xxxu_rx_urb {
864 struct urb urb;
865 struct ieee80211_hw *hw;
866 struct list_head list;
867};
868
869struct rtl8xxxu_tx_urb {
870 struct urb urb;
871 struct ieee80211_hw *hw;
872 struct list_head list;
873};
874
875struct rtl8xxxu_fileops {
876 int (*parse_efuse) (struct rtl8xxxu_priv *priv);
877 int (*load_firmware) (struct rtl8xxxu_priv *priv);
878 int (*power_on) (struct rtl8xxxu_priv *priv);
Jes Sorensen74b99be2016-02-29 17:04:04 -0500879 int (*llt_init) (struct rtl8xxxu_priv *priv, u8 last_tx_page);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -0500880 void (*phy_init_antenna_selection) (struct rtl8xxxu_priv *priv);
Jes Sorensene1547c52016-02-29 17:04:35 -0500881 void (*phy_iq_calibrate) (struct rtl8xxxu_priv *priv);
Jes Sorensenc3f95062016-02-29 17:04:40 -0500882 void (*config_channel) (struct ieee80211_hw *hw);
Jes Sorensenf37e9222016-02-29 17:04:41 -0500883 void (*init_bt) (struct rtl8xxxu_priv *priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400884 int writeN_block_size;
Jes Sorensened35d092016-02-29 17:04:19 -0500885 u16 mbox_ext_reg;
886 char mbox_ext_width;
Jes Sorensen0d698de2016-02-29 17:04:36 -0500887 char has_s0s1;
Jes Sorensen8634af52016-02-29 17:04:33 -0500888 u32 adda_1t_init;
889 u32 adda_1t_path_on;
890 u32 adda_2t_path_on_a;
891 u32 adda_2t_path_on_b;
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400892};