1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2018-2019 Realtek Corporation
8 #include <net/mac80211.h>
9 #include <linux/vmalloc.h>
10 #include <linux/firmware.h>
11 #include <linux/average.h>
12 #include <linux/bitops.h>
13 #include <linux/bitfield.h>
14 #include <linux/interrupt.h>
18 #define RTW_MAX_MAC_ID_NUM 32
19 #define RTW_MAX_SEC_CAM_NUM 32
20 #define MAX_PG_CAM_BACKUP_NUM 8
22 #define RTW_MAX_PATTERN_NUM 12
23 #define RTW_MAX_PATTERN_MASK_SIZE 16
24 #define RTW_MAX_PATTERN_SIZE 128
26 #define RTW_WATCH_DOG_DELAY_TIME round_jiffies_relative(HZ * 2)
28 #define RFREG_MASK 0xfffff
29 #define INV_RF_DATA 0xffffffff
30 #define TX_PAGE_SIZE_SHIFT 7
32 #define RTW_CHANNEL_WIDTH_MAX 3
33 #define RTW_RF_PATH_MAX 4
34 #define HW_FEATURE_LEN 13
36 #define RTW_TP_SHIFT 18 /* bytes/2s --> Mbps */
38 extern bool rtw_bf_support
;
39 extern unsigned int rtw_fw_lps_deep_mode
;
40 extern unsigned int rtw_debug_mask
;
41 extern const struct ieee80211_ops rtw_ops
;
42 extern struct rtw_chip_info rtw8822b_hw_spec
;
43 extern struct rtw_chip_info rtw8822c_hw_spec
;
45 #define RTW_MAX_CHANNEL_NUM_2G 14
46 #define RTW_MAX_CHANNEL_NUM_5G 49
55 RTW_HCI_TYPE_UNDEFINE
,
59 struct rtw_hci_ops
*ops
;
60 enum rtw_hci_type type
;
68 #define IS_CH_5G_BAND_1(channel) ((channel) >= 36 && (channel <= 48))
69 #define IS_CH_5G_BAND_2(channel) ((channel) >= 52 && (channel <= 64))
70 #define IS_CH_5G_BAND_3(channel) ((channel) >= 100 && (channel <= 144))
71 #define IS_CH_5G_BAND_4(channel) ((channel) >= 149 && (channel <= 177))
73 #define IS_CH_5G_BAND_MID(channel) \
74 (IS_CH_5G_BAND_2(channel) || IS_CH_5G_BAND_3(channel))
76 #define IS_CH_2G_BAND(channel) ((channel) <= 14)
77 #define IS_CH_5G_BAND(channel) \
78 (IS_CH_5G_BAND_1(channel) || IS_CH_5G_BAND_2(channel) || \
79 IS_CH_5G_BAND_3(channel) || IS_CH_5G_BAND_4(channel))
81 enum rtw_supported_band
{
84 RTW_BAND_60G
= 1 << 2,
89 /* now, support upto 80M bw */
90 #define RTW_MAX_CHANNEL_WIDTH RTW_CHANNEL_WIDTH_80
93 RTW_CHANNEL_WIDTH_20
= 0,
94 RTW_CHANNEL_WIDTH_40
= 1,
95 RTW_CHANNEL_WIDTH_80
= 2,
96 RTW_CHANNEL_WIDTH_160
= 3,
97 RTW_CHANNEL_WIDTH_80_80
= 4,
98 RTW_CHANNEL_WIDTH_5
= 5,
99 RTW_CHANNEL_WIDTH_10
= 6,
103 RTW_SC_DONT_CARE
= 0,
106 RTW_SC_20_UPMOST
= 3,
107 RTW_SC_20_LOWEST
= 4,
109 RTW_SC_40_LOWER
= 10,
115 RTW_NET_MGD_LINKED
= 2,
144 BB_PATH_AB
= (BB_PATH_A
| BB_PATH_B
),
145 BB_PATH_AC
= (BB_PATH_A
| BB_PATH_C
),
146 BB_PATH_AD
= (BB_PATH_A
| BB_PATH_D
),
147 BB_PATH_BC
= (BB_PATH_B
| BB_PATH_C
),
148 BB_PATH_BD
= (BB_PATH_B
| BB_PATH_D
),
149 BB_PATH_CD
= (BB_PATH_C
| BB_PATH_D
),
151 BB_PATH_ABC
= (BB_PATH_A
| BB_PATH_B
| BB_PATH_C
),
152 BB_PATH_ABD
= (BB_PATH_A
| BB_PATH_B
| BB_PATH_D
),
153 BB_PATH_ACD
= (BB_PATH_A
| BB_PATH_C
| BB_PATH_D
),
154 BB_PATH_BCD
= (BB_PATH_B
| BB_PATH_C
| BB_PATH_D
),
156 BB_PATH_ABCD
= (BB_PATH_A
| BB_PATH_B
| BB_PATH_C
| BB_PATH_D
),
159 enum rtw_rate_section
{
160 RTW_RATE_SECTION_CCK
= 0,
161 RTW_RATE_SECTION_OFDM
,
162 RTW_RATE_SECTION_HT_1S
,
163 RTW_RATE_SECTION_HT_2S
,
164 RTW_RATE_SECTION_VHT_1S
,
165 RTW_RATE_SECTION_VHT_2S
,
168 RTW_RATE_SECTION_MAX
,
171 enum rtw_wireless_set
{
172 WIRELESS_CCK
= 0x00000001,
173 WIRELESS_OFDM
= 0x00000002,
174 WIRELESS_HT
= 0x00000004,
175 WIRELESS_VHT
= 0x00000008,
178 #define HT_STBC_EN BIT(0)
179 #define VHT_STBC_EN BIT(1)
180 #define HT_LDPC_EN BIT(0)
181 #define VHT_LDPC_EN BIT(1)
188 enum rtw_tx_queue_type
{
189 /* the order of AC queues matters */
190 RTW_TX_QUEUE_BK
= 0x0,
191 RTW_TX_QUEUE_BE
= 0x1,
192 RTW_TX_QUEUE_VI
= 0x2,
193 RTW_TX_QUEUE_VO
= 0x3,
195 RTW_TX_QUEUE_BCN
= 0x4,
196 RTW_TX_QUEUE_MGMT
= 0x5,
197 RTW_TX_QUEUE_HI0
= 0x6,
198 RTW_TX_QUEUE_H2C
= 0x7,
203 enum rtw_rx_queue_type
{
204 RTW_RX_QUEUE_MPDU
= 0x0,
205 RTW_RX_QUEUE_C2H
= 0x1,
215 enum rtw_rate_index
{
216 RTW_RATEID_BGN_40M_2SS
= 0,
217 RTW_RATEID_BGN_40M_1SS
= 1,
218 RTW_RATEID_BGN_20M_2SS
= 2,
219 RTW_RATEID_BGN_20M_1SS
= 3,
220 RTW_RATEID_GN_N2SS
= 4,
221 RTW_RATEID_GN_N1SS
= 5,
224 RTW_RATEID_B_20M
= 8,
225 RTW_RATEID_ARFR0_AC_2SS
= 9,
226 RTW_RATEID_ARFR1_AC_1SS
= 10,
227 RTW_RATEID_ARFR2_AC_2G_1SS
= 11,
228 RTW_RATEID_ARFR3_AC_2G_2SS
= 12,
229 RTW_RATEID_ARFR4_AC_3SS
= 13,
230 RTW_RATEID_ARFR5_N_3SS
= 14,
231 RTW_RATEID_ARFR7_N_4SS
= 15,
232 RTW_RATEID_ARFR6_AC_4SS
= 16
235 enum rtw_trx_desc_rate
{
238 DESC_RATE5_5M
= 0x02,
250 DESC_RATEMCS0
= 0x0c,
251 DESC_RATEMCS1
= 0x0d,
252 DESC_RATEMCS2
= 0x0e,
253 DESC_RATEMCS3
= 0x0f,
254 DESC_RATEMCS4
= 0x10,
255 DESC_RATEMCS5
= 0x11,
256 DESC_RATEMCS6
= 0x12,
257 DESC_RATEMCS7
= 0x13,
258 DESC_RATEMCS8
= 0x14,
259 DESC_RATEMCS9
= 0x15,
260 DESC_RATEMCS10
= 0x16,
261 DESC_RATEMCS11
= 0x17,
262 DESC_RATEMCS12
= 0x18,
263 DESC_RATEMCS13
= 0x19,
264 DESC_RATEMCS14
= 0x1a,
265 DESC_RATEMCS15
= 0x1b,
266 DESC_RATEMCS16
= 0x1c,
267 DESC_RATEMCS17
= 0x1d,
268 DESC_RATEMCS18
= 0x1e,
269 DESC_RATEMCS19
= 0x1f,
270 DESC_RATEMCS20
= 0x20,
271 DESC_RATEMCS21
= 0x21,
272 DESC_RATEMCS22
= 0x22,
273 DESC_RATEMCS23
= 0x23,
274 DESC_RATEMCS24
= 0x24,
275 DESC_RATEMCS25
= 0x25,
276 DESC_RATEMCS26
= 0x26,
277 DESC_RATEMCS27
= 0x27,
278 DESC_RATEMCS28
= 0x28,
279 DESC_RATEMCS29
= 0x29,
280 DESC_RATEMCS30
= 0x2a,
281 DESC_RATEMCS31
= 0x2b,
283 DESC_RATEVHT1SS_MCS0
= 0x2c,
284 DESC_RATEVHT1SS_MCS1
= 0x2d,
285 DESC_RATEVHT1SS_MCS2
= 0x2e,
286 DESC_RATEVHT1SS_MCS3
= 0x2f,
287 DESC_RATEVHT1SS_MCS4
= 0x30,
288 DESC_RATEVHT1SS_MCS5
= 0x31,
289 DESC_RATEVHT1SS_MCS6
= 0x32,
290 DESC_RATEVHT1SS_MCS7
= 0x33,
291 DESC_RATEVHT1SS_MCS8
= 0x34,
292 DESC_RATEVHT1SS_MCS9
= 0x35,
294 DESC_RATEVHT2SS_MCS0
= 0x36,
295 DESC_RATEVHT2SS_MCS1
= 0x37,
296 DESC_RATEVHT2SS_MCS2
= 0x38,
297 DESC_RATEVHT2SS_MCS3
= 0x39,
298 DESC_RATEVHT2SS_MCS4
= 0x3a,
299 DESC_RATEVHT2SS_MCS5
= 0x3b,
300 DESC_RATEVHT2SS_MCS6
= 0x3c,
301 DESC_RATEVHT2SS_MCS7
= 0x3d,
302 DESC_RATEVHT2SS_MCS8
= 0x3e,
303 DESC_RATEVHT2SS_MCS9
= 0x3f,
305 DESC_RATEVHT3SS_MCS0
= 0x40,
306 DESC_RATEVHT3SS_MCS1
= 0x41,
307 DESC_RATEVHT3SS_MCS2
= 0x42,
308 DESC_RATEVHT3SS_MCS3
= 0x43,
309 DESC_RATEVHT3SS_MCS4
= 0x44,
310 DESC_RATEVHT3SS_MCS5
= 0x45,
311 DESC_RATEVHT3SS_MCS6
= 0x46,
312 DESC_RATEVHT3SS_MCS7
= 0x47,
313 DESC_RATEVHT3SS_MCS8
= 0x48,
314 DESC_RATEVHT3SS_MCS9
= 0x49,
316 DESC_RATEVHT4SS_MCS0
= 0x4a,
317 DESC_RATEVHT4SS_MCS1
= 0x4b,
318 DESC_RATEVHT4SS_MCS2
= 0x4c,
319 DESC_RATEVHT4SS_MCS3
= 0x4d,
320 DESC_RATEVHT4SS_MCS4
= 0x4e,
321 DESC_RATEVHT4SS_MCS5
= 0x4f,
322 DESC_RATEVHT4SS_MCS6
= 0x50,
323 DESC_RATEVHT4SS_MCS7
= 0x51,
324 DESC_RATEVHT4SS_MCS8
= 0x52,
325 DESC_RATEVHT4SS_MCS9
= 0x53,
330 enum rtw_regulatory_domains
{
338 RTW_REGD_UKRAINE
= 7,
354 RTW_FLAG_INACTIVE_PS
,
356 RTW_FLAG_LEISURE_PS_DEEP
,
357 RTW_FLAG_DIG_DISABLE
,
358 RTW_FLAG_BUSY_TRAFFIC
,
391 RTW_WOW_FLAG_EN_MAGIC_PKT
,
392 RTW_WOW_FLAG_EN_REKEY_PKT
,
393 RTW_WOW_FLAG_EN_DISCONNECT
,
399 /* the power index is represented by differences, which cck-1s & ht40-1s are
400 * the base values, so for 1s's differences, there are only ht20 & ofdm
402 struct rtw_2g_1s_pwr_idx_diff
{
403 #ifdef __LITTLE_ENDIAN
412 struct rtw_2g_ns_pwr_idx_diff
{
413 #ifdef __LITTLE_ENDIAN
426 struct rtw_2g_txpwr_idx
{
429 struct rtw_2g_1s_pwr_idx_diff ht_1s_diff
;
430 struct rtw_2g_ns_pwr_idx_diff ht_2s_diff
;
431 struct rtw_2g_ns_pwr_idx_diff ht_3s_diff
;
432 struct rtw_2g_ns_pwr_idx_diff ht_4s_diff
;
435 struct rtw_5g_ht_1s_pwr_idx_diff
{
436 #ifdef __LITTLE_ENDIAN
445 struct rtw_5g_ht_ns_pwr_idx_diff
{
446 #ifdef __LITTLE_ENDIAN
455 struct rtw_5g_ofdm_ns_pwr_idx_diff
{
456 #ifdef __LITTLE_ENDIAN
469 struct rtw_5g_vht_ns_pwr_idx_diff
{
470 #ifdef __LITTLE_ENDIAN
479 struct rtw_5g_txpwr_idx
{
481 struct rtw_5g_ht_1s_pwr_idx_diff ht_1s_diff
;
482 struct rtw_5g_ht_ns_pwr_idx_diff ht_2s_diff
;
483 struct rtw_5g_ht_ns_pwr_idx_diff ht_3s_diff
;
484 struct rtw_5g_ht_ns_pwr_idx_diff ht_4s_diff
;
485 struct rtw_5g_ofdm_ns_pwr_idx_diff ofdm_diff
;
486 struct rtw_5g_vht_ns_pwr_idx_diff vht_1s_diff
;
487 struct rtw_5g_vht_ns_pwr_idx_diff vht_2s_diff
;
488 struct rtw_5g_vht_ns_pwr_idx_diff vht_3s_diff
;
489 struct rtw_5g_vht_ns_pwr_idx_diff vht_4s_diff
;
492 struct rtw_txpwr_idx
{
493 struct rtw_2g_txpwr_idx pwr_idx_2g
;
494 struct rtw_5g_txpwr_idx pwr_idx_5g
;
497 struct rtw_timer_list
{
498 struct timer_list timer
;
499 void (*function
)(void *data
);
503 struct rtw_channel_params
{
507 /* center channel by different available bandwidth,
508 * val of (bw > current bandwidth) is invalid
510 u8 cch_by_bw
[RTW_MAX_CHANNEL_WIDTH
+ 1];
518 struct rtw_reg_domain
{
521 #define RTW_REG_DOMAIN_MAC32 0
522 #define RTW_REG_DOMAIN_MAC16 1
523 #define RTW_REG_DOMAIN_MAC8 2
524 #define RTW_REG_DOMAIN_RF_A 3
525 #define RTW_REG_DOMAIN_RF_B 4
526 #define RTW_REG_DOMAIN_NL 0xFF
530 struct rtw_backup_info
{
536 enum rtw_vif_port_set
{
537 PORT_SET_MAC_ADDR
= BIT(0),
538 PORT_SET_BSSID
= BIT(1),
539 PORT_SET_NET_TYPE
= BIT(2),
540 PORT_SET_AID
= BIT(3),
541 PORT_SET_BCN_CTRL
= BIT(4),
544 struct rtw_vif_port
{
545 struct rtw_hw_reg mac_addr
;
546 struct rtw_hw_reg bssid
;
547 struct rtw_hw_reg net_type
;
548 struct rtw_hw_reg aid
;
549 struct rtw_hw_reg bcn_ctrl
;
552 struct rtw_tx_pkt_info
{
569 bool dis_rate_fallback
;
582 struct rtw_rx_pkt_stat
{
599 s8 rx_power
[RTW_RF_PATH_MAX
];
602 s8 rx_snr
[RTW_RF_PATH_MAX
];
603 u8 rx_evm
[RTW_RF_PATH_MAX
];
604 s8 cfo_tail
[RTW_RF_PATH_MAX
];
606 struct rtw_sta_info
*si
;
607 struct ieee80211_vif
*vif
;
610 DECLARE_EWMA(tp
, 10, 2);
612 struct rtw_traffic_stats
{
617 /* count for packets */
624 struct ewma_tp tx_ewma_tp
;
625 struct ewma_tp rx_ewma_tp
;
634 enum rtw_lps_deep_mode
{
635 LPS_DEEP_MODE_NONE
= 0,
636 LPS_DEEP_MODE_LCLK
= 1,
637 LPS_DEEP_MODE_PG
= 2,
646 struct rtw_lps_conf
{
647 enum rtw_lps_mode mode
;
648 enum rtw_lps_deep_mode deep_mode
;
649 enum rtw_pwr_state state
;
655 bool pattern_cam_backup
;
658 enum rtw_hw_key_type
{
666 struct rtw_cam_entry
{
671 struct ieee80211_key_conf
*key
;
674 struct rtw_sec_desc
{
675 /* search strategy */
676 bool default_key_search
;
679 struct rtw_cam_entry cam_table
[RTW_MAX_SEC_CAM_NUM
];
680 DECLARE_BITMAP(cam_map
, RTW_MAX_SEC_CAM_NUM
);
683 struct rtw_tx_report
{
684 /* protect the tx report queue */
686 struct sk_buff_head queue
;
688 struct timer_list purge_timer
;
691 struct rtw_ra_report
{
692 struct rate_info txrate
;
698 struct list_head list
;
701 unsigned long last_push
;
704 #define RTW_BC_MC_MACID 1
705 DECLARE_EWMA(rssi
, 10, 16);
707 struct rtw_sta_info
{
708 struct ieee80211_sta
*sta
;
709 struct ieee80211_vif
*vif
;
711 struct ewma_rssi avg_rssi
;
716 enum rtw_bandwidth bw_mode
;
717 enum rtw_rf_type rf_type
;
718 enum rtw_wireless_set wireless_set
;
727 DECLARE_BITMAP(tid_ba
, IEEE80211_NUM_TIDS
);
729 struct rtw_ra_report ra_report
;
732 struct cfg80211_bitrate_mask
*mask
;
742 enum rtw_bfee_role role
;
746 u8 mac_addr
[ETH_ALEN
];
759 DECLARE_BITMAP(bfer_su_reg_maping
, 2);
764 enum rtw_net_type net_type
;
766 u8 mac_addr
[ETH_ALEN
];
770 struct list_head rsvd_page_list
;
771 struct ieee80211_tx_queue_params tx_params
[IEEE80211_NUM_ACS
];
772 const struct rtw_vif_port
*conf
;
774 struct rtw_traffic_stats stats
;
776 struct rtw_bfee bfee
;
779 struct rtw_regulatory
{
785 struct rtw_chip_ops
{
786 int (*mac_init
)(struct rtw_dev
*rtwdev
);
787 int (*read_efuse
)(struct rtw_dev
*rtwdev
, u8
*map
);
788 void (*phy_set_param
)(struct rtw_dev
*rtwdev
);
789 void (*set_channel
)(struct rtw_dev
*rtwdev
, u8 channel
,
790 u8 bandwidth
, u8 primary_chan_idx
);
791 void (*query_rx_desc
)(struct rtw_dev
*rtwdev
, u8
*rx_desc
,
792 struct rtw_rx_pkt_stat
*pkt_stat
,
793 struct ieee80211_rx_status
*rx_status
);
794 u32 (*read_rf
)(struct rtw_dev
*rtwdev
, enum rtw_rf_path rf_path
,
796 bool (*write_rf
)(struct rtw_dev
*rtwdev
, enum rtw_rf_path rf_path
,
797 u32 addr
, u32 mask
, u32 data
);
798 void (*set_tx_power_index
)(struct rtw_dev
*rtwdev
);
799 int (*rsvd_page_dump
)(struct rtw_dev
*rtwdev
, u8
*buf
, u32 offset
,
801 void (*set_antenna
)(struct rtw_dev
*rtwdev
, u8 antenna_tx
,
803 void (*cfg_ldo25
)(struct rtw_dev
*rtwdev
, bool enable
);
804 void (*false_alarm_statistics
)(struct rtw_dev
*rtwdev
);
805 void (*phy_calibration
)(struct rtw_dev
*rtwdev
);
806 void (*dpk_track
)(struct rtw_dev
*rtwdev
);
807 void (*cck_pd_set
)(struct rtw_dev
*rtwdev
, u8 level
);
808 void (*pwr_track
)(struct rtw_dev
*rtwdev
);
809 void (*config_bfee
)(struct rtw_dev
*rtwdev
, struct rtw_vif
*vif
,
810 struct rtw_bfee
*bfee
, bool enable
);
811 void (*set_gid_table
)(struct rtw_dev
*rtwdev
,
812 struct ieee80211_vif
*vif
,
813 struct ieee80211_bss_conf
*conf
);
814 void (*cfg_csi_rate
)(struct rtw_dev
*rtwdev
, u8 rssi
, u8 cur_rate
,
815 u8 fixrate_en
, u8
*new_rate
);
818 void (*coex_set_init
)(struct rtw_dev
*rtwdev
);
819 void (*coex_set_ant_switch
)(struct rtw_dev
*rtwdev
,
820 u8 ctrl_type
, u8 pos_type
);
821 void (*coex_set_gnt_fix
)(struct rtw_dev
*rtwdev
);
822 void (*coex_set_gnt_debug
)(struct rtw_dev
*rtwdev
);
823 void (*coex_set_rfe_type
)(struct rtw_dev
*rtwdev
);
824 void (*coex_set_wl_tx_power
)(struct rtw_dev
*rtwdev
, u8 wl_pwr
);
825 void (*coex_set_wl_rx_gain
)(struct rtw_dev
*rtwdev
, bool low_gain
);
828 #define RTW_PWR_POLLING_CNT 20000
830 #define RTW_PWR_CMD_READ 0x00
831 #define RTW_PWR_CMD_WRITE 0x01
832 #define RTW_PWR_CMD_POLLING 0x02
833 #define RTW_PWR_CMD_DELAY 0x03
834 #define RTW_PWR_CMD_END 0x04
836 /* define the base address of each block */
837 #define RTW_PWR_ADDR_MAC 0x00
838 #define RTW_PWR_ADDR_USB 0x01
839 #define RTW_PWR_ADDR_PCIE 0x02
840 #define RTW_PWR_ADDR_SDIO 0x03
842 #define RTW_PWR_INTF_SDIO_MSK BIT(0)
843 #define RTW_PWR_INTF_USB_MSK BIT(1)
844 #define RTW_PWR_INTF_PCI_MSK BIT(2)
845 #define RTW_PWR_INTF_ALL_MSK (BIT(0) | BIT(1) | BIT(2) | BIT(3))
847 #define RTW_PWR_CUT_A_MSK BIT(1)
848 #define RTW_PWR_CUT_B_MSK BIT(2)
849 #define RTW_PWR_CUT_C_MSK BIT(3)
850 #define RTW_PWR_CUT_D_MSK BIT(4)
851 #define RTW_PWR_CUT_E_MSK BIT(5)
852 #define RTW_PWR_CUT_F_MSK BIT(6)
853 #define RTW_PWR_CUT_G_MSK BIT(7)
854 #define RTW_PWR_CUT_ALL_MSK 0xFF
856 enum rtw_pwr_seq_cmd_delay_unit
{
861 struct rtw_pwr_seq_cmd
{
872 RTW_CHIP_VER_CUT_A
= 0x00,
873 RTW_CHIP_VER_CUT_B
= 0x01,
874 RTW_CHIP_VER_CUT_C
= 0x02,
875 RTW_CHIP_VER_CUT_D
= 0x03,
876 RTW_CHIP_VER_CUT_E
= 0x04,
877 RTW_CHIP_VER_CUT_F
= 0x05,
878 RTW_CHIP_VER_CUT_G
= 0x06,
881 #define RTW_INTF_PHY_PLATFORM_ALL 0
883 enum rtw_intf_phy_cut
{
884 RTW_INTF_PHY_CUT_A
= BIT(0),
885 RTW_INTF_PHY_CUT_B
= BIT(1),
886 RTW_INTF_PHY_CUT_C
= BIT(2),
887 RTW_INTF_PHY_CUT_D
= BIT(3),
888 RTW_INTF_PHY_CUT_E
= BIT(4),
889 RTW_INTF_PHY_CUT_F
= BIT(5),
890 RTW_INTF_PHY_CUT_G
= BIT(6),
891 RTW_INTF_PHY_CUT_ALL
= 0xFFFF,
899 RTW_IP_SEL_UNDEF
= 0xFFFF
909 RTW_PQ_MAP_NUM
= 0x6,
914 enum rtw_dma_mapping
{
915 RTW_DMA_MAPPING_EXTRA
= 0,
916 RTW_DMA_MAPPING_LOW
= 1,
917 RTW_DMA_MAPPING_NORMAL
= 2,
918 RTW_DMA_MAPPING_HIGH
= 3,
921 RTW_DMA_MAPPING_UNDEF
,
925 enum rtw_dma_mapping dma_map_vo
;
926 enum rtw_dma_mapping dma_map_vi
;
927 enum rtw_dma_mapping dma_map_be
;
928 enum rtw_dma_mapping dma_map_bk
;
929 enum rtw_dma_mapping dma_map_mg
;
930 enum rtw_dma_mapping dma_map_hi
;
933 struct rtw_page_table
{
941 struct rtw_intf_phy_para
{
949 struct rtw_wow_pattern
{
953 u8 mask
[RTW_MAX_PATTERN_MASK_SIZE
];
956 struct rtw_pno_request
{
959 struct cfg80211_match_set
*match_sets
;
961 struct ieee80211_channel
*channels
;
962 struct cfg80211_sched_scan_plan scan_plan
;
965 struct rtw_wow_param
{
966 struct ieee80211_vif
*wow_vif
;
967 DECLARE_BITMAP(flags
, RTW_WOW_FLAG_MAX
);
970 struct rtw_wow_pattern patterns
[RTW_MAX_PATTERN_NUM
];
973 struct rtw_pno_request pno_req
;
976 struct rtw_intf_phy_para_table
{
977 const struct rtw_intf_phy_para
*usb2_para
;
978 const struct rtw_intf_phy_para
*usb3_para
;
979 const struct rtw_intf_phy_para
*gen1_para
;
980 const struct rtw_intf_phy_para
*gen2_para
;
990 void (*parse
)(struct rtw_dev
*rtwdev
, const struct rtw_table
*tbl
);
991 void (*do_cfg
)(struct rtw_dev
*rtwdev
, const struct rtw_table
*tbl
,
993 enum rtw_rf_path rf_path
;
996 static inline void rtw_load_table(struct rtw_dev
*rtwdev
,
997 const struct rtw_table
*tbl
)
999 (*tbl
->parse
)(rtwdev
, tbl
);
1005 RTW_RFE_IFEM2G_EFEM5G
,
1009 struct rtw_rfe_def
{
1010 const struct rtw_table
*phy_pg_tbl
;
1011 const struct rtw_table
*txpwr_lmt_tbl
;
1014 #define RTW_DEF_RFE(chip, bb_pg, pwrlmt) { \
1015 .phy_pg_tbl = &rtw ## chip ## _bb_pg_type ## bb_pg ## _tbl, \
1016 .txpwr_lmt_tbl = &rtw ## chip ## _txpwr_lmt_type ## pwrlmt ## _tbl, \
1019 #define RTW_PWR_TRK_5G_1 0
1020 #define RTW_PWR_TRK_5G_2 1
1021 #define RTW_PWR_TRK_5G_3 2
1022 #define RTW_PWR_TRK_5G_NUM 3
1024 #define RTW_PWR_TRK_TBL_SZ 30
1026 /* This table stores the values of TX power that will be adjusted by power
1029 * For 5G bands, there are 3 different settings.
1030 * For 2G there are cck rate and ofdm rate with different settings.
1032 struct rtw_pwr_track_tbl
{
1033 const u8
*pwrtrk_5gb_n
[RTW_PWR_TRK_5G_NUM
];
1034 const u8
*pwrtrk_5gb_p
[RTW_PWR_TRK_5G_NUM
];
1035 const u8
*pwrtrk_5ga_n
[RTW_PWR_TRK_5G_NUM
];
1036 const u8
*pwrtrk_5ga_p
[RTW_PWR_TRK_5G_NUM
];
1037 const u8
*pwrtrk_2gb_n
;
1038 const u8
*pwrtrk_2gb_p
;
1039 const u8
*pwrtrk_2ga_n
;
1040 const u8
*pwrtrk_2ga_p
;
1041 const u8
*pwrtrk_2g_cckb_n
;
1042 const u8
*pwrtrk_2g_cckb_p
;
1043 const u8
*pwrtrk_2g_ccka_n
;
1044 const u8
*pwrtrk_2g_ccka_p
;
1047 /* hardware configuration for each IC */
1048 struct rtw_chip_info
{
1049 struct rtw_chip_ops
*ops
;
1052 const char *fw_name
;
1059 u32 ptct_efuse_size
;
1068 bool is_pwr_by_rate_dec
;
1073 u8 lps_deep_mode_supported
;
1077 const struct rtw_pwr_seq_cmd
**pwr_on_seq
;
1078 const struct rtw_pwr_seq_cmd
**pwr_off_seq
;
1079 const struct rtw_rqpn
*rqpn_table
;
1080 const struct rtw_page_table
*page_table
;
1081 const struct rtw_intf_phy_para_table
*intf_table
;
1083 const struct rtw_hw_reg
*dig
;
1084 u32 rf_base_addr
[2];
1085 u32 rf_sipi_addr
[2];
1087 const struct rtw_table
*mac_tbl
;
1088 const struct rtw_table
*agc_tbl
;
1089 const struct rtw_table
*bb_tbl
;
1090 const struct rtw_table
*rf_tbl
[RTW_RF_PATH_MAX
];
1091 const struct rtw_table
*rfk_init_tbl
;
1093 const struct rtw_rfe_def
*rfe_defs
;
1099 const struct rtw_pwr_track_tbl
*pwr_track_tbl
;
1104 const char *wow_fw_name
;
1105 const struct wiphy_wowlan_support
*wowlan_stub
;
1106 const u8 max_sched_scan_ssids
;
1112 bool new_scbd10_def
; /* true: fix 2M(8822c) */
1113 u8 pstdma_type
; /* 0: LPSoff, 1:LPSon */
1121 u8 bt_afh_span_bw20
;
1122 u8 bt_afh_span_bw40
;
1125 u8 coex_info_hw_regs_num
;
1126 const u8
*bt_rssi_step
;
1127 const u8
*wl_rssi_step
;
1128 const struct coex_table_para
*table_nsant
;
1129 const struct coex_table_para
*table_sant
;
1130 const struct coex_tdma_para
*tdma_sant
;
1131 const struct coex_tdma_para
*tdma_nsant
;
1132 const struct coex_rf_para
*wl_rf_para_tx
;
1133 const struct coex_rf_para
*wl_rf_para_rx
;
1134 const struct coex_5g_afh_map
*afh_5g
;
1135 const struct rtw_reg_domain
*coex_info_hw_regs
;
1138 enum rtw_coex_bt_state_cnt
{
1141 COEX_CNT_BT_REENABLE
,
1142 COEX_CNT_BT_POPEVENT
,
1143 COEX_CNT_BT_SETUPLINK
,
1144 COEX_CNT_BT_IGNWLANACT
,
1147 COEX_CNT_BT_ROLESWITCH
,
1148 COEX_CNT_BT_AFHUPDATE
,
1149 COEX_CNT_BT_INFOUPDATE
,
1151 COEX_CNT_BT_IQKFAIL
,
1156 enum rtw_coex_wl_state_cnt
{
1157 COEX_CNT_WL_CONNPKT
,
1158 COEX_CNT_WL_COEXRUN
,
1162 COEX_CNT_WL_5MS_NOEXTEND
,
1163 COEX_CNT_WL_FW_NOTIFY
,
1168 struct rtw_coex_rfe
{
1169 bool ant_switch_exist
;
1170 bool ant_switch_diversity
;
1171 bool ant_switch_with_bt
;
1173 u8 ant_switch_polarity
;
1175 /* true if WLG at BTG, else at WLAG */
1179 struct rtw_coex_dm
{
1180 bool cur_ps_tdma_on
;
1181 bool cur_wl_rx_low_gain_en
;
1185 u8 bt_rssi_state
[4];
1186 u8 wl_rssi_state
[4];
1195 u32 cur_ant_pos_type
;
1196 u32 cur_switch_status
;
1200 #define COEX_BTINFO_SRC_WL_FW 0x0
1201 #define COEX_BTINFO_SRC_BT_RSP 0x1
1202 #define COEX_BTINFO_SRC_BT_ACT 0x2
1203 #define COEX_BTINFO_SRC_BT_IQK 0x3
1204 #define COEX_BTINFO_SRC_BT_SCBD 0x4
1205 #define COEX_BTINFO_SRC_MAX 0x5
1207 #define COEX_INFO_FTP BIT(7)
1208 #define COEX_INFO_A2DP BIT(6)
1209 #define COEX_INFO_HID BIT(5)
1210 #define COEX_INFO_SCO_BUSY BIT(4)
1211 #define COEX_INFO_ACL_BUSY BIT(3)
1212 #define COEX_INFO_INQ_PAGE BIT(2)
1213 #define COEX_INFO_SCO_ESCO BIT(1)
1214 #define COEX_INFO_CONNECTION BIT(0)
1215 #define COEX_BTINFO_LENGTH_MAX 10
1217 struct rtw_coex_stat
{
1219 bool bt_disabled_pre
;
1230 bool bt_pan_exist
; /* PAN or OPP */
1231 bool bt_opp_exist
; /* OPP only */
1237 bool bt_a2dp_active
;
1239 bool bt_ble_scan_en
;
1242 bool bt_418_hid_exist
;
1243 bool bt_mailbox_reply
;
1247 bool wl_hi_pri_task1
;
1248 bool wl_hi_pri_task2
;
1249 bool wl_force_lps_ctrl
;
1251 bool wl_linkscan_proc
;
1252 bool wl_ps_state_fail
;
1253 bool wl_tx_limit_en
;
1254 bool wl_ampdu_limit_en
;
1256 bool wl_slot_extend
;
1258 bool wl_cck_lock_pre
;
1259 bool wl_cck_lock_ever
;
1261 u32 bt_supported_version
;
1262 u32 bt_supported_feature
;
1264 u16 bt_reg_vendor_ae
;
1265 u16 bt_reg_vendor_ac
;
1268 u8 gnt_workaround_state
;
1271 u8 bt_info_c2h
[COEX_BTINFO_SRC_MAX
][COEX_BTINFO_LENGTH_MAX
];
1278 u8 bt_ble_scan_type
;
1285 u8 wl_fw_dbg_info
[10];
1286 u8 wl_fw_dbg_info_pre
[10];
1294 /* counters to record bt states */
1295 u32 cnt_bt
[COEX_CNT_BT_MAX
];
1297 /* counters to record wifi states */
1298 u32 cnt_wl
[COEX_CNT_WL_MAX
];
1305 /* protects coex info request section */
1307 struct sk_buff_head queue
;
1308 wait_queue_head_t wait
;
1316 struct rtw_coex_stat stat
;
1317 struct rtw_coex_dm dm
;
1318 struct rtw_coex_rfe rfe
;
1320 struct delayed_work bt_relink_work
;
1321 struct delayed_work bt_reenable_work
;
1322 struct delayed_work defreeze_work
;
1325 #define DPK_RF_REG_NUM 7
1326 #define DPK_RF_PATH_NUM 2
1327 #define DPK_BB_REG_NUM 18
1328 #define DPK_CHANNEL_WIDTH_80 1
1330 DECLARE_EWMA(thermal
, 10, 4);
1332 struct rtw_dpk_info
{
1336 DECLARE_BITMAP(dpk_path_ok
, DPK_RF_PATH_NUM
);
1338 u8 thermal_dpk
[DPK_RF_PATH_NUM
];
1339 struct ewma_thermal avg_thermal
[DPK_RF_PATH_NUM
];
1344 u8 result
[RTW_RF_PATH_MAX
];
1345 u8 dpk_txagc
[RTW_RF_PATH_MAX
];
1346 u32 coef
[RTW_RF_PATH_MAX
][20];
1347 u16 dpk_gs
[RTW_RF_PATH_MAX
];
1348 u8 thermal_dpk_delta
[RTW_RF_PATH_MAX
];
1349 u8 pre_pwsf
[RTW_RF_PATH_MAX
];
1356 struct rtw_phy_cck_pd_reg
{
1363 #define DACK_MSBK_BACKUP_NUM 0xf
1364 #define DACK_DCK_BACKUP_NUM 0x2
1366 struct rtw_swing_table
{
1367 const u8
*p
[RTW_RF_PATH_MAX
];
1368 const u8
*n
[RTW_RF_PATH_MAX
];
1371 struct rtw_pkt_count
{
1373 u16 num_qry_pkt
[DESC_RATE_MAX
];
1376 DECLARE_EWMA(evm
, 10, 4);
1377 DECLARE_EWMA(snr
, 10, 4);
1379 struct rtw_dm_info
{
1409 u8 thermal_avg
[RTW_RF_PATH_MAX
];
1411 s8 delta_power_index
[RTW_RF_PATH_MAX
];
1412 u8 default_ofdm_index
;
1413 bool pwr_trk_triggered
;
1414 bool pwr_trk_init_trigger
;
1415 struct ewma_thermal avg_thermal
[RTW_RF_PATH_MAX
];
1417 /* backup dack results for each path and I/Q */
1418 u32 dack_adck
[RTW_RF_PATH_MAX
];
1419 u16 dack_msbk
[RTW_RF_PATH_MAX
][2][DACK_MSBK_BACKUP_NUM
];
1420 u8 dack_dck
[RTW_RF_PATH_MAX
][2][DACK_DCK_BACKUP_NUM
];
1422 struct rtw_dpk_info dpk_info
;
1424 /* [bandwidth 0:20M/1:40M][number of path] */
1425 u8 cck_pd_lv
[2][RTW_RF_PATH_MAX
];
1428 /* save the last rx phy status for debug */
1429 s8 rx_snr
[RTW_RF_PATH_MAX
];
1430 u8 rx_evm_dbm
[RTW_RF_PATH_MAX
];
1431 s16 cfo_tail
[RTW_RF_PATH_MAX
];
1432 u8 rssi
[RTW_RF_PATH_MAX
];
1434 struct rtw_pkt_count cur_pkt_count
;
1435 struct rtw_pkt_count last_pkt_count
;
1436 struct ewma_evm ewma_evm
[RTW_EVM_NUM
];
1437 struct ewma_snr ewma_snr
[RTW_SNR_NUM
];
1451 u8 power_track_type
;
1452 u8 thermal_meter
[RTW_RF_PATH_MAX
];
1473 /* bt share antenna with wifi */
1485 struct rtw_txpwr_idx txpwr_idx_table
[4];
1488 struct rtw_phy_cond
{
1489 #ifdef __LITTLE_ENDIAN
1511 #define INTF_PCIE BIT(0)
1512 #define INTF_USB BIT(1)
1513 #define INTF_SDIO BIT(2)
1516 #define BRANCH_ELIF 1
1517 #define BRANCH_ELSE 2
1518 #define BRANCH_ENDIF 3
1521 struct rtw_fifo_conf
{
1522 /* tx fifo information */
1525 u16 rsvd_drv_pg_num
;
1529 u16 rsvd_h2c_info_addr
;
1530 u16 rsvd_h2c_sta_info_addr
;
1532 u16 rsvd_cpu_instr_addr
;
1533 u16 rsvd_fw_txbuf_addr
;
1534 u16 rsvd_csibuf_addr
;
1535 const struct rtw_rqpn
*rqpn
;
1538 struct rtw_fw_state
{
1539 const struct firmware
*firmware
;
1540 struct rtw_dev
*rtwdev
;
1541 struct completion completion
;
1555 struct rtw_phy_cond phy_cond
;
1559 u8 current_band_width
;
1560 u8 current_band_type
;
1562 /* center channel for different available bandwidth,
1563 * val of (bw > current_band_width) is invalid
1565 u8 cch_by_bw
[RTW_MAX_CHANNEL_WIDTH
+ 1];
1574 /* protect tx power section */
1575 struct mutex tx_power_mutex
;
1576 s8 tx_pwr_by_rate_offset_2g
[RTW_RF_PATH_MAX
]
1578 s8 tx_pwr_by_rate_offset_5g
[RTW_RF_PATH_MAX
]
1580 s8 tx_pwr_by_rate_base_2g
[RTW_RF_PATH_MAX
]
1581 [RTW_RATE_SECTION_MAX
];
1582 s8 tx_pwr_by_rate_base_5g
[RTW_RF_PATH_MAX
]
1583 [RTW_RATE_SECTION_MAX
];
1584 s8 tx_pwr_limit_2g
[RTW_REGD_MAX
]
1585 [RTW_CHANNEL_WIDTH_MAX
]
1586 [RTW_RATE_SECTION_MAX
]
1587 [RTW_MAX_CHANNEL_NUM_2G
];
1588 s8 tx_pwr_limit_5g
[RTW_REGD_MAX
]
1589 [RTW_CHANNEL_WIDTH_MAX
]
1590 [RTW_RATE_SECTION_MAX
]
1591 [RTW_MAX_CHANNEL_NUM_5G
];
1592 s8 tx_pwr_tbl
[RTW_RF_PATH_MAX
]
1597 struct ieee80211_hw
*hw
;
1602 struct rtw_chip_info
*chip
;
1604 struct rtw_fifo_conf fifo
;
1605 struct rtw_fw_state fw
;
1606 struct rtw_efuse efuse
;
1607 struct rtw_sec_desc sec
;
1608 struct rtw_traffic_stats stats
;
1609 struct rtw_regulatory regd
;
1610 struct rtw_bf_info bf_info
;
1612 struct rtw_dm_info dm_info
;
1613 struct rtw_coex coex
;
1615 /* ensures exclusive access from mac80211 callbacks */
1618 /* read/write rf register */
1621 /* watch dog every 2 sec */
1622 struct delayed_work watch_dog_work
;
1625 struct list_head rsvd_page_list
;
1627 /* c2h cmd queue & handler work */
1628 struct sk_buff_head c2h_queue
;
1629 struct work_struct c2h_work
;
1631 /* used to protect txqs list */
1632 spinlock_t txq_lock
;
1633 struct list_head txqs
;
1634 struct tasklet_struct tx_tasklet
;
1635 struct work_struct ba_work
;
1637 struct rtw_tx_report tx_report
;
1640 /* incicate the mail box to use with fw */
1642 /* protect to send h2c to fw */
1647 /* lps power state & handler work */
1648 struct rtw_lps_conf lps_conf
;
1651 struct dentry
*debugfs
;
1656 DECLARE_BITMAP(mac_id_map
, RTW_MAX_MAC_ID_NUM
);
1657 DECLARE_BITMAP(flags
, NUM_OF_RTW_FLAGS
);
1661 struct rtw_fw_state wow_fw
;
1662 struct rtw_wow_param wow
;
1664 /* hci related data, must be last */
1665 u8 priv
[] __aligned(sizeof(void *));
1670 static inline bool rtw_is_assoc(struct rtw_dev
*rtwdev
)
1672 return !!rtwdev
->sta_cnt
;
1675 static inline struct ieee80211_txq
*rtwtxq_to_txq(struct rtw_txq
*rtwtxq
)
1679 return container_of(p
, struct ieee80211_txq
, drv_priv
);
1682 static inline struct ieee80211_vif
*rtwvif_to_vif(struct rtw_vif
*rtwvif
)
1686 return container_of(p
, struct ieee80211_vif
, drv_priv
);
1689 static inline bool rtw_ssid_equal(struct cfg80211_ssid
*a
,
1690 struct cfg80211_ssid
*b
)
1692 if (!a
|| !b
|| a
->ssid_len
!= b
->ssid_len
)
1695 if (memcmp(a
->ssid
, b
->ssid
, a
->ssid_len
))
1701 void rtw_get_channel_params(struct cfg80211_chan_def
*chandef
,
1702 struct rtw_channel_params
*ch_param
);
1703 bool check_hw_ready(struct rtw_dev
*rtwdev
, u32 addr
, u32 mask
, u32 target
);
1704 bool ltecoex_read_reg(struct rtw_dev
*rtwdev
, u16 offset
, u32
*val
);
1705 bool ltecoex_reg_write(struct rtw_dev
*rtwdev
, u16 offset
, u32 value
);
1706 void rtw_restore_reg(struct rtw_dev
*rtwdev
,
1707 struct rtw_backup_info
*bckp
, u32 num
);
1708 void rtw_desc_to_mcsrate(u16 rate
, u8
*mcs
, u8
*nss
);
1709 void rtw_set_channel(struct rtw_dev
*rtwdev
);
1710 void rtw_vif_port_config(struct rtw_dev
*rtwdev
, struct rtw_vif
*rtwvif
,
1712 void rtw_tx_report_purge_timer(struct timer_list
*t
);
1713 void rtw_update_sta_info(struct rtw_dev
*rtwdev
, struct rtw_sta_info
*si
);
1714 int rtw_core_start(struct rtw_dev
*rtwdev
);
1715 void rtw_core_stop(struct rtw_dev
*rtwdev
);
1716 int rtw_chip_info_setup(struct rtw_dev
*rtwdev
);
1717 int rtw_core_init(struct rtw_dev
*rtwdev
);
1718 void rtw_core_deinit(struct rtw_dev
*rtwdev
);
1719 int rtw_register_hw(struct rtw_dev
*rtwdev
, struct ieee80211_hw
*hw
);
1720 void rtw_unregister_hw(struct rtw_dev
*rtwdev
, struct ieee80211_hw
*hw
);
1721 u16
rtw_desc_to_bitrate(u8 desc_rate
);