1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2014 - 2017 Jes Sorensen <Jes.Sorensen@gmail.com>
5 * Register definitions taken from original Realtek rtl8723au driver
8 #include <asm/byteorder.h>
10 #define RTL8XXXU_DEBUG_REG_WRITE 0x01
11 #define RTL8XXXU_DEBUG_REG_READ 0x02
12 #define RTL8XXXU_DEBUG_RFREG_WRITE 0x04
13 #define RTL8XXXU_DEBUG_RFREG_READ 0x08
14 #define RTL8XXXU_DEBUG_CHANNEL 0x10
15 #define RTL8XXXU_DEBUG_TX 0x20
16 #define RTL8XXXU_DEBUG_TX_DUMP 0x40
17 #define RTL8XXXU_DEBUG_RX 0x80
18 #define RTL8XXXU_DEBUG_RX_DUMP 0x100
19 #define RTL8XXXU_DEBUG_USB 0x200
20 #define RTL8XXXU_DEBUG_KEY 0x400
21 #define RTL8XXXU_DEBUG_H2C 0x800
22 #define RTL8XXXU_DEBUG_ACTION 0x1000
23 #define RTL8XXXU_DEBUG_EFUSE 0x2000
24 #define RTL8XXXU_DEBUG_INTERRUPT 0x4000
26 #define RTW_USB_CONTROL_MSG_TIMEOUT 500
27 #define RTL8XXXU_MAX_REG_POLL 500
28 #define USB_INTR_CONTENT_LENGTH 56
30 #define RTL8XXXU_OUT_ENDPOINTS 4
32 #define REALTEK_USB_READ 0xc0
33 #define REALTEK_USB_WRITE 0x40
34 #define REALTEK_USB_CMD_REQ 0x05
35 #define REALTEK_USB_CMD_IDX 0x00
37 #define TX_TOTAL_PAGE_NUM 0xf8
38 #define TX_TOTAL_PAGE_NUM_8192E 0xf3
39 #define TX_TOTAL_PAGE_NUM_8723B 0xf7
40 /* (HPQ + LPQ + NPQ + PUBQ) = TX_TOTAL_PAGE_NUM */
41 #define TX_PAGE_NUM_PUBQ 0xe7
42 #define TX_PAGE_NUM_HI_PQ 0x0c
43 #define TX_PAGE_NUM_LO_PQ 0x02
44 #define TX_PAGE_NUM_NORM_PQ 0x02
46 #define TX_PAGE_NUM_PUBQ_8192E 0xe7
47 #define TX_PAGE_NUM_HI_PQ_8192E 0x08
48 #define TX_PAGE_NUM_LO_PQ_8192E 0x0c
49 #define TX_PAGE_NUM_NORM_PQ_8192E 0x00
51 #define TX_PAGE_NUM_PUBQ_8723B 0xe7
52 #define TX_PAGE_NUM_HI_PQ_8723B 0x0c
53 #define TX_PAGE_NUM_LO_PQ_8723B 0x02
54 #define TX_PAGE_NUM_NORM_PQ_8723B 0x02
56 #define RTL_FW_PAGE_SIZE 4096
57 #define RTL8XXXU_FIRMWARE_POLL_MAX 1000
59 #define RTL8723A_CHANNEL_GROUPS 3
60 #define RTL8723A_MAX_RF_PATHS 2
61 #define RTL8723B_CHANNEL_GROUPS 6
62 #define RTL8723B_TX_COUNT 4
63 #define RTL8723B_MAX_RF_PATHS 4
64 #define RTL8XXXU_MAX_CHANNEL_GROUPS 6
65 #define RF6052_MAX_TX_PWR 0x3f
67 #define EFUSE_MAP_LEN 512
68 #define EFUSE_MAX_SECTION_8723A 64
69 #define EFUSE_REAL_CONTENT_LEN_8723A 512
70 #define EFUSE_BT_MAP_LEN_8723A 1024
71 #define EFUSE_MAX_WORD_UNIT 4
73 enum rtl8xxxu_rtl_chip
{
97 enum rtl8xxxu_rx_type
{
103 struct rtl8xxxu_rxdesc16
{
104 #ifdef __LITTLE_ENDIAN
241 struct rtl8xxxu_rxdesc24
{
242 #ifdef __LITTLE_ENDIAN
264 u32 a1fit
:4; /* 16 */
279 u32 rx_is_qos
:1; /* 16 */
292 u32 usb_agg_pktnum
:8; /* 16 */
348 u32 usb_agg_pktnum
:8;
349 u32 dummy3_1
:2; /* 16 */
366 struct rtl8xxxu_txdesc32
{
380 struct rtl8xxxu_txdesc40
{
396 /* CCK Rates, TxHT = 0 */
397 #define DESC_RATE_1M 0x00
398 #define DESC_RATE_2M 0x01
399 #define DESC_RATE_5_5M 0x02
400 #define DESC_RATE_11M 0x03
402 /* OFDM Rates, TxHT = 0 */
403 #define DESC_RATE_6M 0x04
404 #define DESC_RATE_9M 0x05
405 #define DESC_RATE_12M 0x06
406 #define DESC_RATE_18M 0x07
407 #define DESC_RATE_24M 0x08
408 #define DESC_RATE_36M 0x09
409 #define DESC_RATE_48M 0x0a
410 #define DESC_RATE_54M 0x0b
412 /* MCS Rates, TxHT = 1 */
413 #define DESC_RATE_MCS0 0x0c
414 #define DESC_RATE_MCS1 0x0d
415 #define DESC_RATE_MCS2 0x0e
416 #define DESC_RATE_MCS3 0x0f
417 #define DESC_RATE_MCS4 0x10
418 #define DESC_RATE_MCS5 0x11
419 #define DESC_RATE_MCS6 0x12
420 #define DESC_RATE_MCS7 0x13
421 #define DESC_RATE_MCS8 0x14
422 #define DESC_RATE_MCS9 0x15
423 #define DESC_RATE_MCS10 0x16
424 #define DESC_RATE_MCS11 0x17
425 #define DESC_RATE_MCS12 0x18
426 #define DESC_RATE_MCS13 0x19
427 #define DESC_RATE_MCS14 0x1a
428 #define DESC_RATE_MCS15 0x1b
429 #define DESC_RATE_MCS15_SG 0x1c
430 #define DESC_RATE_MCS32 0x20
432 #define TXDESC_OFFSET_SZ 0
433 #define TXDESC_OFFSET_SHT 16
435 #define TXDESC_BMC BIT(24)
436 #define TXDESC_LSG BIT(26)
437 #define TXDESC_FSG BIT(27)
438 #define TXDESC_OWN BIT(31)
440 #define TXDESC_BROADMULTICAST BIT(0)
441 #define TXDESC_HTC BIT(1)
442 #define TXDESC_LAST_SEGMENT BIT(2)
443 #define TXDESC_FIRST_SEGMENT BIT(3)
444 #define TXDESC_LINIP BIT(4)
445 #define TXDESC_NO_ACM BIT(5)
446 #define TXDESC_GF BIT(6)
447 #define TXDESC_OWN BIT(7)
452 * Bits 0-7 differ dependent on chip generation. For 8723au bits 5/6 are
453 * aggregation enable and break respectively. For 8723bu, bits 0-7 are macid.
455 #define TXDESC_PKT_OFFSET_SZ 0
456 #define TXDESC32_AGG_ENABLE BIT(5)
457 #define TXDESC32_AGG_BREAK BIT(6)
458 #define TXDESC40_MACID_SHIFT 0
459 #define TXDESC40_MACID_MASK 0x00f0
460 #define TXDESC_QUEUE_SHIFT 8
461 #define TXDESC_QUEUE_MASK 0x1f00
462 #define TXDESC_QUEUE_BK 0x2
463 #define TXDESC_QUEUE_BE 0x0
464 #define TXDESC_QUEUE_VI 0x5
465 #define TXDESC_QUEUE_VO 0x7
466 #define TXDESC_QUEUE_BEACON 0x10
467 #define TXDESC_QUEUE_HIGH 0x11
468 #define TXDESC_QUEUE_MGNT 0x12
469 #define TXDESC_QUEUE_CMD 0x13
470 #define TXDESC_QUEUE_MAX (TXDESC_QUEUE_CMD + 1)
471 #define TXDESC40_RDG_NAV_EXT BIT(13)
472 #define TXDESC40_LSIG_TXOP_ENABLE BIT(14)
473 #define TXDESC40_PIFS BIT(15)
475 #define DESC_RATE_ID_SHIFT 16
476 #define DESC_RATE_ID_MASK 0xf
477 #define TXDESC_NAVUSEHDR BIT(20)
478 #define TXDESC_SEC_RC4 0x00400000
479 #define TXDESC_SEC_AES 0x00c00000
480 #define TXDESC_PKT_OFFSET_SHIFT 26
481 #define TXDESC_AGG_EN BIT(29)
482 #define TXDESC_HWPC BIT(31)
485 #define TXDESC40_PAID_SHIFT 0
486 #define TXDESC40_PAID_MASK 0x1ff
487 #define TXDESC40_CCA_RTS_SHIFT 10
488 #define TXDESC40_CCA_RTS_MASK 0xc00
489 #define TXDESC40_AGG_ENABLE BIT(12)
490 #define TXDESC40_RDG_ENABLE BIT(13)
491 #define TXDESC40_AGG_BREAK BIT(16)
492 #define TXDESC40_MORE_FRAG BIT(17)
493 #define TXDESC40_RAW BIT(18)
494 #define TXDESC32_ACK_REPORT BIT(19)
495 #define TXDESC40_SPE_RPT BIT(19)
496 #define TXDESC_AMPDU_DENSITY_SHIFT 20
497 #define TXDESC40_BT_INT BIT(23)
498 #define TXDESC40_GID_SHIFT 24
501 #define TXDESC40_USE_DRIVER_RATE BIT(8)
502 #define TXDESC40_CTS_SELF_ENABLE BIT(11)
503 #define TXDESC40_RTS_CTS_ENABLE BIT(12)
504 #define TXDESC40_HW_RTS_ENABLE BIT(13)
505 #define TXDESC32_SEQ_SHIFT 16
506 #define TXDESC32_SEQ_MASK 0x0fff0000
509 #define TXDESC32_RTS_RATE_SHIFT 0
510 #define TXDESC32_RTS_RATE_MASK 0x3f
511 #define TXDESC32_QOS BIT(6)
512 #define TXDESC32_HW_SEQ_ENABLE BIT(7)
513 #define TXDESC32_USE_DRIVER_RATE BIT(8)
514 #define TXDESC_DISABLE_DATA_FB BIT(10)
515 #define TXDESC32_CTS_SELF_ENABLE BIT(11)
516 #define TXDESC32_RTS_CTS_ENABLE BIT(12)
517 #define TXDESC32_HW_RTS_ENABLE BIT(13)
518 #define TXDESC_PRIME_CH_OFF_LOWER BIT(20)
519 #define TXDESC_PRIME_CH_OFF_UPPER BIT(21)
520 #define TXDESC32_SHORT_PREAMBLE BIT(24)
521 #define TXDESC_DATA_BW BIT(25)
522 #define TXDESC_RTS_DATA_BW BIT(27)
523 #define TXDESC_RTS_PRIME_CH_OFF_LOWER BIT(28)
524 #define TXDESC_RTS_PRIME_CH_OFF_UPPER BIT(29)
525 #define TXDESC40_DATA_RATE_FB_SHIFT 8
526 #define TXDESC40_DATA_RATE_FB_MASK 0x00001f00
527 #define TXDESC40_RETRY_LIMIT_ENABLE BIT(17)
528 #define TXDESC40_RETRY_LIMIT_SHIFT 18
529 #define TXDESC40_RETRY_LIMIT_MASK 0x00fc0000
530 #define TXDESC40_RTS_RATE_SHIFT 24
531 #define TXDESC40_RTS_RATE_MASK 0x3f000000
534 #define TXDESC40_SHORT_PREAMBLE BIT(4)
535 #define TXDESC32_SHORT_GI BIT(6)
536 #define TXDESC_CCX_TAG BIT(7)
537 #define TXDESC32_RETRY_LIMIT_ENABLE BIT(17)
538 #define TXDESC32_RETRY_LIMIT_SHIFT 18
539 #define TXDESC32_RETRY_LIMIT_MASK 0x00fc0000
542 #define TXDESC_MAX_AGG_SHIFT 11
545 #define TXDESC40_HW_SEQ_ENABLE BIT(15)
548 #define TXDESC40_SEQ_SHIFT 12
549 #define TXDESC40_SEQ_MASK 0x00fff000
551 struct phy_rx_agc_info
{
552 #ifdef __LITTLE_ENDIAN
559 struct rtl8723au_phy_stats
{
560 struct phy_rx_agc_info path_agc
[RTL8723A_MAX_RF_PATHS
];
561 u8 ch_corr
[RTL8723A_MAX_RF_PATHS
];
562 u8 cck_sig_qual_ofdm_pwdb_all
;
563 u8 cck_agc_rpt_ofdm_cfosho_a
;
564 u8 cck_rpt_b_ofdm_cfosho_b
;
566 u8 noise_power_db_msb
;
567 u8 path_cfotail
[RTL8723A_MAX_RF_PATHS
];
568 u8 pcts_mask
[RTL8723A_MAX_RF_PATHS
];
569 s8 stream_rxevm
[RTL8723A_MAX_RF_PATHS
];
570 u8 path_rxsnr
[RTL8723A_MAX_RF_PATHS
];
571 u8 noise_power_db_lsb
;
573 u8 stream_csi
[RTL8723A_MAX_RF_PATHS
];
574 u8 stream_target_csi
[RTL8723A_MAX_RF_PATHS
];
578 #ifdef __LITTLE_ENDIAN
579 u8 antsel_rx_keep_2
:1; /* ex_intf_flg:1; */
584 u8 antenna_select_b
:1;
586 #else /* _BIG_ENDIAN_ */
588 u8 antenna_select_b
:1;
593 u8 antsel_rx_keep_2
:1; /* ex_intf_flg:1; */
600 #define RTL8XXXU_ADDA_REGS 16
601 #define RTL8XXXU_MAC_REGS 4
602 #define RTL8XXXU_BB_REGS 9
604 struct rtl8xxxu_firmware_header
{
605 __le16 signature
; /* 92C0: test chip; 92C,
609 u8 category
; /* AP/NIC and USB/PCI */
612 __le16 major_version
; /* FW Version */
613 u8 minor_version
; /* FW Subversion, default 0x00 */
616 u8 month
; /* Release time Month field */
617 u8 date
; /* Release time Date field */
618 u8 hour
; /* Release time Hour field */
619 u8 minute
; /* Release time Minute field */
621 __le16 ramcodesize
; /* Size of RAM code */
624 __le32 svn_idx
; /* SVN entry index */
634 * 8723au/8192cu/8188ru required base power index offset tables.
636 struct rtl8xxxu_power_base
{
659 * The 8723au has 3 channel groups: 1-3, 4-9, and 10-14
661 struct rtl8723au_idx
{
662 #ifdef __LITTLE_ENDIAN
669 } __attribute__((packed
));
671 struct rtl8723au_efuse
{
674 u8 cck_tx_power_index_A
[3]; /* 0x10 */
675 u8 cck_tx_power_index_B
[3];
676 u8 ht40_1s_tx_power_index_A
[3]; /* 0x16 */
677 u8 ht40_1s_tx_power_index_B
[3];
679 * The following entries are half-bytes split as:
680 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
682 struct rtl8723au_idx ht20_tx_power_index_diff
[3];
683 struct rtl8723au_idx ofdm_tx_power_index_diff
[3];
684 struct rtl8723au_idx ht40_max_power_offset
[3];
685 struct rtl8723au_idx ht20_max_power_offset
[3];
686 u8 channel_plan
; /* 0x28 */
694 u8 version
/* 0x30 */;
695 u8 customer_id_major
;
696 u8 customer_id_minor
;
698 u8 chipset
; /* 0x34 */
704 u8 mac_addr
[ETH_ALEN
]; /* 0xc6 */
708 u8 device_name
[0x29]; /* 0xd7 */
711 struct rtl8192cu_efuse
{
720 __le16 smid
; /* 0x10 */
722 u8 mac_addr
[ETH_ALEN
]; /* 0x16 */
726 u8 device_name
[0x14]; /* 0x28 */
727 u8 res4
[0x1e]; /* 0x3c */
728 u8 cck_tx_power_index_A
[3]; /* 0x5a */
729 u8 cck_tx_power_index_B
[3];
730 u8 ht40_1s_tx_power_index_A
[3]; /* 0x60 */
731 u8 ht40_1s_tx_power_index_B
[3];
733 * The following entries are half-bytes split as:
734 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
736 struct rtl8723au_idx ht40_2s_tx_power_index_diff
[3];
737 struct rtl8723au_idx ht20_tx_power_index_diff
[3]; /* 0x69 */
738 struct rtl8723au_idx ofdm_tx_power_index_diff
[3];
739 struct rtl8723au_idx ht40_max_power_offset
[3]; /* 0x6f */
740 struct rtl8723au_idx ht20_max_power_offset
[3];
741 u8 channel_plan
; /* 0x75 */
744 u8 thermal_meter
; /* xtal_k */ /* 0x78 */
749 u8 res5
[1]; /* 0x7d */
754 struct rtl8723bu_pwr_idx
{
755 #ifdef __LITTLE_ENDIAN
766 } __attribute__((packed
));
768 struct rtl8723bu_efuse_tx_power
{
771 struct rtl8723au_idx ht20_ofdm_1s_diff
;
772 struct rtl8723bu_pwr_idx pwr_diff
[3];
773 u8 dummy5g
[24]; /* max channel group (14) + power diff offset (10) */
776 struct rtl8723bu_efuse
{
779 struct rtl8723bu_efuse_tx_power tx_power_index_A
; /* 0x10 */
780 struct rtl8723bu_efuse_tx_power tx_power_index_B
; /* 0x3a */
781 struct rtl8723bu_efuse_tx_power tx_power_index_C
; /* 0x64 */
782 struct rtl8723bu_efuse_tx_power tx_power_index_D
; /* 0x8e */
783 u8 channel_plan
; /* 0xb8 */
787 u8 pa_type
; /* 0xbc */
788 u8 lna_type_2g
; /* 0xbd */
791 u8 rf_feature_option
;
794 u8 eeprom_customer_id
;
796 u8 tx_pwr_calibrate_rate
;
797 u8 rf_antenna_option
; /* 0xc9 */
800 u8 usb_optional_function
;
803 u8 serial
[0x0b]; /* 0xf5 */
808 u8 mac_addr
[ETH_ALEN
]; /* 0x107 */
810 u8 vendor_name
[0x07];
812 u8 device_name
[0x14];
814 u8 package_type
; /* 0x1fb */
818 struct rtl8192eu_efuse_tx_power
{
821 struct rtl8723au_idx ht20_ofdm_1s_diff
;
822 struct rtl8723bu_pwr_idx pwr_diff
[3];
823 u8 dummy5g
[24]; /* max channel group (14) + power diff offset (10) */
826 struct rtl8192eu_efuse
{
829 struct rtl8192eu_efuse_tx_power tx_power_index_A
; /* 0x10 */
830 struct rtl8192eu_efuse_tx_power tx_power_index_B
; /* 0x3a */
832 u8 channel_plan
; /* 0xb8 */
836 u8 pa_type
; /* 0xbc */
837 u8 lna_type_2g
; /* 0xbd */
839 u8 lna_type_5g
; /* 0xbf */
842 u8 rf_feature_option
;
845 u8 eeprom_customer_id
;
847 u8 rf_antenna_option
; /* 0xc9 */
853 u8 usb_optional_function
;
855 u8 mac_addr
[ETH_ALEN
]; /* 0xd7 */
859 u8 device_name
[0x0b]; /* 0xe8 */
861 u8 serial
[0x0b]; /* 0xf5 */
863 u8 unknown
[0x0d]; /* 0x130 */
867 struct rtl8xxxu_reg8val
{
872 struct rtl8xxxu_reg32val
{
877 struct rtl8xxxu_rfregval
{
882 enum rtl8xxxu_rfpath
{
887 struct rtl8xxxu_rfregs
{
896 #define H2C_MAX_MBOX 4
897 #define H2C_EXT BIT(7)
898 #define H2C_JOIN_BSS_DISCONNECT 0
899 #define H2C_JOIN_BSS_CONNECT 1
902 * H2C (firmware) commands differ between the older generation chips
903 * 8188[cr]u, 819[12]cu, and 8723au, and the more recent chips 8723bu,
904 * 8192[de]u, 8192eu, and 8812.
907 H2C_SET_POWER_MODE
= 1,
908 H2C_JOIN_BSS_REPORT
= 2,
910 H2C_SET_RATE_MASK
= (6 | H2C_EXT
),
917 H2C_8723B_RSVD_PAGE
= 0x00,
918 H2C_8723B_MEDIA_STATUS_RPT
= 0x01,
919 H2C_8723B_SCAN_ENABLE
= 0x02,
920 H2C_8723B_KEEP_ALIVE
= 0x03,
921 H2C_8723B_DISCON_DECISION
= 0x04,
922 H2C_8723B_PSD_OFFLOAD
= 0x05,
923 H2C_8723B_AP_OFFLOAD
= 0x08,
924 H2C_8723B_BCN_RSVDPAGE
= 0x09,
925 H2C_8723B_PROBERSP_RSVDPAGE
= 0x0A,
926 H2C_8723B_FCS_RSVDPAGE
= 0x10,
927 H2C_8723B_FCS_INFO
= 0x11,
928 H2C_8723B_AP_WOW_GPIO_CTRL
= 0x13,
931 * PoweSave Class: 001
933 H2C_8723B_SET_PWR_MODE
= 0x20,
934 H2C_8723B_PS_TUNING_PARA
= 0x21,
935 H2C_8723B_PS_TUNING_PARA2
= 0x22,
936 H2C_8723B_P2P_LPS_PARAM
= 0x23,
937 H2C_8723B_P2P_PS_OFFLOAD
= 0x24,
938 H2C_8723B_PS_SCAN_ENABLE
= 0x25,
939 H2C_8723B_SAP_PS_
= 0x26,
940 H2C_8723B_INACTIVE_PS_
= 0x27,
941 H2C_8723B_FWLPS_IN_IPS_
= 0x28,
944 * Dynamic Mechanism Class: 010
946 H2C_8723B_MACID_CFG_RAID
= 0x40,
947 H2C_8723B_TXBF
= 0x41,
948 H2C_8723B_RSSI_SETTING
= 0x42,
949 H2C_8723B_AP_REQ_TXRPT
= 0x43,
950 H2C_8723B_INIT_RATE_COLLECT
= 0x44,
955 H2C_8723B_B_TYPE_TDMA
= 0x60,
956 H2C_8723B_BT_INFO
= 0x61,
957 H2C_8723B_FORCE_BT_TXPWR
= 0x62,
958 H2C_8723B_BT_IGNORE_WLANACT
= 0x63,
959 H2C_8723B_DAC_SWING_VALUE
= 0x64,
960 H2C_8723B_ANT_SEL_RSV
= 0x65,
961 H2C_8723B_WL_OPMODE
= 0x66,
962 H2C_8723B_BT_MP_OPER
= 0x67,
963 H2C_8723B_BT_CONTROL
= 0x68,
964 H2C_8723B_BT_WIFI_CTRL
= 0x69,
965 H2C_8723B_BT_FW_PATCH
= 0x6a,
966 H2C_8723B_BT_WLAN_CALIBRATION
= 0x6d,
967 H2C_8723B_BT_GRANT
= 0x6e,
972 H2C_8723B_WOWLAN
= 0x80,
973 H2C_8723B_REMOTE_WAKE_CTRL
= 0x81,
974 H2C_8723B_AOAC_GLOBAL_INFO
= 0x82,
975 H2C_8723B_AOAC_RSVD_PAGE
= 0x83,
976 H2C_8723B_AOAC_RSVD_PAGE2
= 0x84,
977 H2C_8723B_D0_SCAN_OFFLOAD_CTRL
= 0x85,
978 H2C_8723B_D0_SCAN_OFFLOAD_INFO
= 0x86,
979 H2C_8723B_CHNL_SWITCH_OFFLOAD
= 0x87,
981 H2C_8723B_RESET_TSF
= 0xC0,
1014 } __packed media_status_rpt
;
1026 * [4:5] - VHT enable
1035 } __packed b_macid_cfg
;
1043 } __packed b_type_dma
;
1054 } __packed bt_mp_oper
;
1058 } __packed bt_wlan_calibration
;
1062 } __packed ignore_wlan
;
1067 } __packed ant_sel_rsv
;
1071 } __packed bt_grant
;
1075 enum c2h_evt_8723b
{
1076 C2H_8723B_DEBUG
= 0,
1078 C2H_8723B_AP_RPT_RSP
= 2,
1079 C2H_8723B_CCX_TX_RPT
= 3,
1080 C2H_8723B_BT_RSSI
= 4,
1081 C2H_8723B_BT_OP_MODE
= 5,
1082 C2H_8723B_EXT_RA_RPT
= 6,
1083 C2H_8723B_BT_INFO
= 9,
1084 C2H_8723B_HW_INFO_EXCH
= 0x0a,
1085 C2H_8723B_BT_MP_INFO
= 0x0b,
1086 C2H_8723B_RA_REPORT
= 0x0c,
1087 C2H_8723B_FW_DEBUG
= 0xff,
1090 enum bt_info_src_8723b
{
1091 BT_INFO_SRC_8723B_WIFI_FW
= 0x0,
1092 BT_INFO_SRC_8723B_BT_RSP
= 0x1,
1093 BT_INFO_SRC_8723B_BT_ACTIVE_SEND
= 0x2,
1096 enum bt_mp_oper_opcode_8723b
{
1097 BT_MP_OP_GET_BT_VERSION
= 0x00,
1098 BT_MP_OP_RESET
= 0x01,
1099 BT_MP_OP_TEST_CTRL
= 0x02,
1100 BT_MP_OP_SET_BT_MODE
= 0x03,
1101 BT_MP_OP_SET_CHNL_TX_GAIN
= 0x04,
1102 BT_MP_OP_SET_PKT_TYPE_LEN
= 0x05,
1103 BT_MP_OP_SET_PKT_CNT_L_PL_TYPE
= 0x06,
1104 BT_MP_OP_SET_PKT_CNT_H_PKT_INTV
= 0x07,
1105 BT_MP_OP_SET_PKT_HEADER
= 0x08,
1106 BT_MP_OP_SET_WHITENCOEFF
= 0x09,
1107 BT_MP_OP_SET_BD_ADDR_L
= 0x0a,
1108 BT_MP_OP_SET_BD_ADDR_H
= 0x0b,
1109 BT_MP_OP_WRITE_REG_ADDR
= 0x0c,
1110 BT_MP_OP_WRITE_REG_VALUE
= 0x0d,
1111 BT_MP_OP_GET_BT_STATUS
= 0x0e,
1112 BT_MP_OP_GET_BD_ADDR_L
= 0x0f,
1113 BT_MP_OP_GET_BD_ADDR_H
= 0x10,
1114 BT_MP_OP_READ_REG
= 0x11,
1115 BT_MP_OP_SET_TARGET_BD_ADDR_L
= 0x12,
1116 BT_MP_OP_SET_TARGET_BD_ADDR_H
= 0x13,
1117 BT_MP_OP_SET_TX_POWER_CALIBRATION
= 0x14,
1118 BT_MP_OP_GET_RX_PKT_CNT_L
= 0x15,
1119 BT_MP_OP_GET_RX_PKT_CNT_H
= 0x16,
1120 BT_MP_OP_GET_RX_ERROR_BITS_L
= 0x17,
1121 BT_MP_OP_GET_RX_ERROR_BITS_H
= 0x18,
1122 BT_MP_OP_GET_RSSI
= 0x19,
1123 BT_MP_OP_GET_CFO_HDR_QUALITY_L
= 0x1a,
1124 BT_MP_OP_GET_CFO_HDR_QUALITY_H
= 0x1b,
1125 BT_MP_OP_GET_TARGET_BD_ADDR_L
= 0x1c,
1126 BT_MP_OP_GET_TARGET_BD_ADDR_H
= 0x1d,
1127 BT_MP_OP_GET_AFH_MAP_L
= 0x1e,
1128 BT_MP_OP_GET_AFH_MAP_M
= 0x1f,
1129 BT_MP_OP_GET_AFH_MAP_H
= 0x20,
1130 BT_MP_OP_GET_AFH_STATUS
= 0x21,
1131 BT_MP_OP_SET_TRACKING_INTERVAL
= 0x22,
1132 BT_MP_OP_SET_THERMAL_METER
= 0x23,
1133 BT_MP_OP_ENABLE_CFO_TRACKING
= 0x24,
1136 struct rtl8723bu_c2h
{
1150 } __packed bt_mp_info
;
1152 u8 response_source
:4;
1184 } __packed ra_report
;
1188 struct rtl8xxxu_fileops
;
1191 enum wireless_mode
{
1192 WIRELESS_MODE_UNKNOWN
= 0,
1194 WIRELESS_MODE_B
= BIT(0),
1195 WIRELESS_MODE_G
= BIT(1),
1196 WIRELESS_MODE_A
= BIT(2),
1197 WIRELESS_MODE_N_24G
= BIT(3),
1198 WIRELESS_MODE_N_5G
= BIT(4),
1199 WIRELESS_AUTO
= BIT(5),
1200 WIRELESS_MODE_AC
= BIT(6),
1201 WIRELESS_MODE_MAX
= 0x7F,
1204 /* from rtlwifi/wifi.h */
1205 enum ratr_table_mode_new
{
1206 RATEID_IDX_BGN_40M_2SS
= 0,
1207 RATEID_IDX_BGN_40M_1SS
= 1,
1208 RATEID_IDX_BGN_20M_2SS_BN
= 2,
1209 RATEID_IDX_BGN_20M_1SS_BN
= 3,
1210 RATEID_IDX_GN_N2SS
= 4,
1211 RATEID_IDX_GN_N1SS
= 5,
1215 RATEID_IDX_VHT_2SS
= 9,
1216 RATEID_IDX_VHT_1SS
= 10,
1217 RATEID_IDX_MIX1
= 11,
1218 RATEID_IDX_MIX2
= 12,
1219 RATEID_IDX_VHT_3SS
= 13,
1220 RATEID_IDX_BGN_3SS
= 14,
1223 #define BT_INFO_8723B_1ANT_B_FTP BIT(7)
1224 #define BT_INFO_8723B_1ANT_B_A2DP BIT(6)
1225 #define BT_INFO_8723B_1ANT_B_HID BIT(5)
1226 #define BT_INFO_8723B_1ANT_B_SCO_BUSY BIT(4)
1227 #define BT_INFO_8723B_1ANT_B_ACL_BUSY BIT(3)
1228 #define BT_INFO_8723B_1ANT_B_INQ_PAGE BIT(2)
1229 #define BT_INFO_8723B_1ANT_B_SCO_ESCO BIT(1)
1230 #define BT_INFO_8723B_1ANT_B_CONNECTION BIT(0)
1232 enum _BT_8723B_1ANT_STATUS
{
1233 BT_8723B_1ANT_STATUS_NON_CONNECTED_IDLE
= 0x0,
1234 BT_8723B_1ANT_STATUS_CONNECTED_IDLE
= 0x1,
1235 BT_8723B_1ANT_STATUS_INQ_PAGE
= 0x2,
1236 BT_8723B_1ANT_STATUS_ACL_BUSY
= 0x3,
1237 BT_8723B_1ANT_STATUS_SCO_BUSY
= 0x4,
1238 BT_8723B_1ANT_STATUS_ACL_SCO_BUSY
= 0x5,
1239 BT_8723B_1ANT_STATUS_MAX
1242 struct rtl8xxxu_btcoex
{
1251 bool c2h_bt_inquiry
;
1254 #define RTL8XXXU_RATR_STA_INIT 0
1255 #define RTL8XXXU_RATR_STA_HIGH 1
1256 #define RTL8XXXU_RATR_STA_MID 2
1257 #define RTL8XXXU_RATR_STA_LOW 3
1259 #define RTL8XXXU_NOISE_FLOOR_MIN -100
1260 #define RTL8XXXU_SNR_THRESH_HIGH 50
1261 #define RTL8XXXU_SNR_THRESH_LOW 20
1263 struct rtl8xxxu_priv
{
1264 struct ieee80211_hw
*hw
;
1265 struct usb_device
*udev
;
1266 struct rtl8xxxu_fileops
*fops
;
1268 spinlock_t tx_urb_lock
;
1269 struct list_head tx_urb_free_list
;
1270 int tx_urb_free_count
;
1273 spinlock_t rx_urb_lock
;
1274 struct list_head rx_urb_pending_list
;
1275 int rx_urb_pending_count
;
1277 struct work_struct rx_urb_wq
;
1279 u8 mac_addr
[ETH_ALEN
];
1281 char chip_vendor
[8];
1282 u8 cck_tx_power_index_A
[RTL8XXXU_MAX_CHANNEL_GROUPS
];
1283 u8 cck_tx_power_index_B
[RTL8XXXU_MAX_CHANNEL_GROUPS
];
1284 u8 ht40_1s_tx_power_index_A
[RTL8XXXU_MAX_CHANNEL_GROUPS
];
1285 u8 ht40_1s_tx_power_index_B
[RTL8XXXU_MAX_CHANNEL_GROUPS
];
1287 * The following entries are half-bytes split as:
1288 * bits 0-3: path A, bits 4-7: path B, all values 4 bits signed
1290 struct rtl8723au_idx ht40_2s_tx_power_index_diff
[
1291 RTL8723A_CHANNEL_GROUPS
];
1292 struct rtl8723au_idx ht20_tx_power_index_diff
[RTL8723A_CHANNEL_GROUPS
];
1293 struct rtl8723au_idx ofdm_tx_power_index_diff
[RTL8723A_CHANNEL_GROUPS
];
1294 struct rtl8723au_idx ht40_max_power_offset
[RTL8723A_CHANNEL_GROUPS
];
1295 struct rtl8723au_idx ht20_max_power_offset
[RTL8723A_CHANNEL_GROUPS
];
1297 * Newer generation chips only keep power diffs per TX count,
1298 * not per channel group.
1300 struct rtl8723au_idx ofdm_tx_power_diff
[RTL8723B_TX_COUNT
];
1301 struct rtl8723au_idx ht20_tx_power_diff
[RTL8723B_TX_COUNT
];
1302 struct rtl8723au_idx ht40_tx_power_diff
[RTL8723B_TX_COUNT
];
1303 struct rtl8xxxu_power_base
*power_base
;
1306 u32 is_multi_func
:1;
1308 u32 has_bluetooth
:1;
1309 u32 enable_bluetooth
:1;
1314 u32 has_polarity_ctrl
:1;
1317 u32 usb_interrupts
:1;
1318 u32 ep_tx_high_queue
:1;
1319 u32 ep_tx_normal_queue
:1;
1320 u32 ep_tx_low_queue
:1;
1322 u32 rx_buf_aggregation
:1;
1324 unsigned int pipe_interrupt
;
1325 unsigned int pipe_in
;
1326 unsigned int pipe_out
[TXDESC_QUEUE_MAX
];
1327 u8 out_ep
[RTL8XXXU_OUT_ENDPOINTS
];
1339 struct mutex h2c_mutex
;
1341 struct usb_anchor rx_anchor
;
1342 struct usb_anchor tx_anchor
;
1343 struct usb_anchor int_anchor
;
1344 struct rtl8xxxu_firmware_header
*fw_data
;
1346 struct mutex usb_buf_mutex
;
1353 u8 raw
[EFUSE_MAP_LEN
];
1354 struct rtl8723au_efuse efuse8723
;
1355 struct rtl8723bu_efuse efuse8723bu
;
1356 struct rtl8192cu_efuse efuse8192
;
1357 struct rtl8192eu_efuse efuse8192eu
;
1359 u32 adda_backup
[RTL8XXXU_ADDA_REGS
];
1360 u32 mac_backup
[RTL8XXXU_MAC_REGS
];
1361 u32 bb_backup
[RTL8XXXU_BB_REGS
];
1362 u32 bb_recovery_backup
[RTL8XXXU_BB_REGS
];
1363 enum rtl8xxxu_rtl_chip rtl_chip
;
1366 u8 int_buf
[USB_INTR_CONTENT_LENGTH
];
1369 * Only one virtual interface permitted because only STA mode
1370 * is supported and no iface_combinations are provided.
1372 struct ieee80211_vif
*vif
;
1373 struct delayed_work ra_watchdog
;
1374 struct work_struct c2hcmd_work
;
1375 struct sk_buff_head c2hcmd_queue
;
1376 spinlock_t c2hcmd_lock
;
1377 struct rtl8xxxu_btcoex bt_coex
;
1380 struct rtl8xxxu_rx_urb
{
1382 struct ieee80211_hw
*hw
;
1383 struct list_head list
;
1386 struct rtl8xxxu_tx_urb
{
1388 struct ieee80211_hw
*hw
;
1389 struct list_head list
;
1392 struct rtl8xxxu_fileops
{
1393 int (*parse_efuse
) (struct rtl8xxxu_priv
*priv
);
1394 int (*load_firmware
) (struct rtl8xxxu_priv
*priv
);
1395 int (*power_on
) (struct rtl8xxxu_priv
*priv
);
1396 void (*power_off
) (struct rtl8xxxu_priv
*priv
);
1397 void (*reset_8051
) (struct rtl8xxxu_priv
*priv
);
1398 int (*llt_init
) (struct rtl8xxxu_priv
*priv
);
1399 void (*init_phy_bb
) (struct rtl8xxxu_priv
*priv
);
1400 int (*init_phy_rf
) (struct rtl8xxxu_priv
*priv
);
1401 void (*phy_init_antenna_selection
) (struct rtl8xxxu_priv
*priv
);
1402 void (*phy_iq_calibrate
) (struct rtl8xxxu_priv
*priv
);
1403 void (*config_channel
) (struct ieee80211_hw
*hw
);
1404 int (*parse_rx_desc
) (struct rtl8xxxu_priv
*priv
, struct sk_buff
*skb
);
1405 void (*init_aggregation
) (struct rtl8xxxu_priv
*priv
);
1406 void (*init_statistics
) (struct rtl8xxxu_priv
*priv
);
1407 void (*enable_rf
) (struct rtl8xxxu_priv
*priv
);
1408 void (*disable_rf
) (struct rtl8xxxu_priv
*priv
);
1409 void (*usb_quirks
) (struct rtl8xxxu_priv
*priv
);
1410 void (*set_tx_power
) (struct rtl8xxxu_priv
*priv
, int channel
,
1412 void (*update_rate_mask
) (struct rtl8xxxu_priv
*priv
,
1413 u32 ramask
, u8 rateid
, int sgi
);
1414 void (*report_connect
) (struct rtl8xxxu_priv
*priv
,
1415 u8 macid
, bool connect
);
1416 void (*fill_txdesc
) (struct ieee80211_hw
*hw
, struct ieee80211_hdr
*hdr
,
1417 struct ieee80211_tx_info
*tx_info
,
1418 struct rtl8xxxu_txdesc32
*tx_desc
, bool sgi
,
1419 bool short_preamble
, bool ampdu_enable
,
1421 int writeN_block_size
;
1422 int rx_agg_buf_size
;
1427 u8 gen2_thermal_meter
:1;
1428 u8 needs_full_init
:1;
1430 u32 adda_1t_path_on
;
1431 u32 adda_2t_path_on_a
;
1432 u32 adda_2t_path_on_b
;
1436 struct rtl8xxxu_reg8val
*mactable
;
1443 extern int rtl8xxxu_debug
;
1445 extern struct rtl8xxxu_reg8val rtl8xxxu_gen1_mac_init_table
[];
1446 extern const u32 rtl8xxxu_iqk_phy_iq_bb_reg
[];
1447 u8
rtl8xxxu_read8(struct rtl8xxxu_priv
*priv
, u16 addr
);
1448 u16
rtl8xxxu_read16(struct rtl8xxxu_priv
*priv
, u16 addr
);
1449 u32
rtl8xxxu_read32(struct rtl8xxxu_priv
*priv
, u16 addr
);
1450 int rtl8xxxu_write8(struct rtl8xxxu_priv
*priv
, u16 addr
, u8 val
);
1451 int rtl8xxxu_write16(struct rtl8xxxu_priv
*priv
, u16 addr
, u16 val
);
1452 int rtl8xxxu_write32(struct rtl8xxxu_priv
*priv
, u16 addr
, u32 val
);
1453 u32
rtl8xxxu_read_rfreg(struct rtl8xxxu_priv
*priv
,
1454 enum rtl8xxxu_rfpath path
, u8 reg
);
1455 int rtl8xxxu_write_rfreg(struct rtl8xxxu_priv
*priv
,
1456 enum rtl8xxxu_rfpath path
, u8 reg
, u32 data
);
1457 void rtl8xxxu_save_regs(struct rtl8xxxu_priv
*priv
, const u32
*regs
,
1458 u32
*backup
, int count
);
1459 void rtl8xxxu_restore_regs(struct rtl8xxxu_priv
*priv
, const u32
*regs
,
1460 u32
*backup
, int count
);
1461 void rtl8xxxu_save_mac_regs(struct rtl8xxxu_priv
*priv
,
1462 const u32
*reg
, u32
*backup
);
1463 void rtl8xxxu_restore_mac_regs(struct rtl8xxxu_priv
*priv
,
1464 const u32
*reg
, u32
*backup
);
1465 void rtl8xxxu_path_adda_on(struct rtl8xxxu_priv
*priv
, const u32
*regs
,
1467 void rtl8xxxu_mac_calibration(struct rtl8xxxu_priv
*priv
,
1468 const u32
*regs
, u32
*backup
);
1469 void rtl8xxxu_fill_iqk_matrix_a(struct rtl8xxxu_priv
*priv
, bool iqk_ok
,
1470 int result
[][8], int candidate
, bool tx_only
);
1471 void rtl8xxxu_fill_iqk_matrix_b(struct rtl8xxxu_priv
*priv
, bool iqk_ok
,
1472 int result
[][8], int candidate
, bool tx_only
);
1473 int rtl8xxxu_init_phy_rf(struct rtl8xxxu_priv
*priv
,
1474 struct rtl8xxxu_rfregval
*table
,
1475 enum rtl8xxxu_rfpath path
);
1476 int rtl8xxxu_init_phy_regs(struct rtl8xxxu_priv
*priv
,
1477 struct rtl8xxxu_reg32val
*array
);
1478 int rtl8xxxu_load_firmware(struct rtl8xxxu_priv
*priv
, char *fw_name
);
1479 void rtl8xxxu_firmware_self_reset(struct rtl8xxxu_priv
*priv
);
1480 void rtl8xxxu_power_off(struct rtl8xxxu_priv
*priv
);
1481 void rtl8xxxu_reset_8051(struct rtl8xxxu_priv
*priv
);
1482 int rtl8xxxu_auto_llt_table(struct rtl8xxxu_priv
*priv
);
1483 void rtl8xxxu_gen2_prepare_calibrate(struct rtl8xxxu_priv
*priv
, u8 start
);
1484 int rtl8xxxu_flush_fifo(struct rtl8xxxu_priv
*priv
);
1485 int rtl8xxxu_gen2_h2c_cmd(struct rtl8xxxu_priv
*priv
,
1486 struct h2c_cmd
*h2c
, int len
);
1487 int rtl8xxxu_active_to_lps(struct rtl8xxxu_priv
*priv
);
1488 void rtl8xxxu_disabled_to_emu(struct rtl8xxxu_priv
*priv
);
1489 int rtl8xxxu_init_llt_table(struct rtl8xxxu_priv
*priv
);
1490 void rtl8xxxu_gen1_phy_iq_calibrate(struct rtl8xxxu_priv
*priv
);
1491 void rtl8xxxu_gen1_init_phy_bb(struct rtl8xxxu_priv
*priv
);
1492 void rtl8xxxu_gen1_set_tx_power(struct rtl8xxxu_priv
*priv
,
1493 int channel
, bool ht40
);
1494 void rtl8xxxu_gen1_config_channel(struct ieee80211_hw
*hw
);
1495 void rtl8xxxu_gen2_config_channel(struct ieee80211_hw
*hw
);
1496 void rtl8xxxu_gen1_usb_quirks(struct rtl8xxxu_priv
*priv
);
1497 void rtl8xxxu_gen2_usb_quirks(struct rtl8xxxu_priv
*priv
);
1498 void rtl8xxxu_update_rate_mask(struct rtl8xxxu_priv
*priv
,
1499 u32 ramask
, u8 rateid
, int sgi
);
1500 void rtl8xxxu_gen2_update_rate_mask(struct rtl8xxxu_priv
*priv
,
1501 u32 ramask
, u8 rateid
, int sgi
);
1502 void rtl8xxxu_gen1_report_connect(struct rtl8xxxu_priv
*priv
,
1503 u8 macid
, bool connect
);
1504 void rtl8xxxu_gen2_report_connect(struct rtl8xxxu_priv
*priv
,
1505 u8 macid
, bool connect
);
1506 void rtl8xxxu_gen1_init_aggregation(struct rtl8xxxu_priv
*priv
);
1507 void rtl8xxxu_gen1_enable_rf(struct rtl8xxxu_priv
*priv
);
1508 void rtl8xxxu_gen1_disable_rf(struct rtl8xxxu_priv
*priv
);
1509 void rtl8xxxu_gen2_disable_rf(struct rtl8xxxu_priv
*priv
);
1510 int rtl8xxxu_parse_rxdesc16(struct rtl8xxxu_priv
*priv
, struct sk_buff
*skb
);
1511 int rtl8xxxu_parse_rxdesc24(struct rtl8xxxu_priv
*priv
, struct sk_buff
*skb
);
1512 int rtl8xxxu_gen2_channel_to_group(int channel
);
1513 bool rtl8xxxu_gen2_simularity_compare(struct rtl8xxxu_priv
*priv
,
1514 int result
[][8], int c1
, int c2
);
1515 void rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw
*hw
, struct ieee80211_hdr
*hdr
,
1516 struct ieee80211_tx_info
*tx_info
,
1517 struct rtl8xxxu_txdesc32
*tx_desc
, bool sgi
,
1518 bool short_preamble
, bool ampdu_enable
,
1520 void rtl8xxxu_fill_txdesc_v2(struct ieee80211_hw
*hw
, struct ieee80211_hdr
*hdr
,
1521 struct ieee80211_tx_info
*tx_info
,
1522 struct rtl8xxxu_txdesc32
*tx_desc32
, bool sgi
,
1523 bool short_preamble
, bool ampdu_enable
,
1525 void rtl8723bu_set_ps_tdma(struct rtl8xxxu_priv
*priv
,
1526 u8 arg1
, u8 arg2
, u8 arg3
, u8 arg4
, u8 arg5
);
1528 extern struct rtl8xxxu_fileops rtl8192cu_fops
;
1529 extern struct rtl8xxxu_fileops rtl8192eu_fops
;
1530 extern struct rtl8xxxu_fileops rtl8723au_fops
;
1531 extern struct rtl8xxxu_fileops rtl8723bu_fops
;