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/iopoll.h>
15 #include <linux/interrupt.h>
16 #include <linux/workqueue.h>
20 #define RTW_MAX_MAC_ID_NUM 32
21 #define RTW_MAX_SEC_CAM_NUM 32
22 #define MAX_PG_CAM_BACKUP_NUM 8
24 #define RTW_SCAN_MAX_SSIDS 4
26 #define RTW_MAX_PATTERN_NUM 12
27 #define RTW_MAX_PATTERN_MASK_SIZE 16
28 #define RTW_MAX_PATTERN_SIZE 128
30 #define RTW_WATCH_DOG_DELAY_TIME round_jiffies_relative(HZ * 2)
32 #define RFREG_MASK 0xfffff
33 #define INV_RF_DATA 0xffffffff
34 #define TX_PAGE_SIZE_SHIFT 7
35 #define TX_PAGE_SIZE (1 << TX_PAGE_SIZE_SHIFT)
37 #define RTW_CHANNEL_WIDTH_MAX 3
38 #define RTW_RF_PATH_MAX 4
39 #define HW_FEATURE_LEN 13
41 #define RTW_TP_SHIFT 18 /* bytes/2s --> Mbps */
43 extern bool rtw_bf_support;
44 extern bool rtw_disable_lps_deep_mode;
45 extern unsigned int rtw_debug_mask;
46 extern bool rtw_edcca_enabled;
47 extern const struct ieee80211_ops rtw_ops;
49 #define RTW_MAX_CHANNEL_NUM_2G 14
50 #define RTW_MAX_CHANNEL_NUM_5G 49
59 RTW_HCI_TYPE_UNDEFINE,
63 struct rtw_hci_ops *ops;
64 enum rtw_hci_type type;
72 #define IS_CH_5G_BAND_1(channel) ((channel) >= 36 && (channel <= 48))
73 #define IS_CH_5G_BAND_2(channel) ((channel) >= 52 && (channel <= 64))
74 #define IS_CH_5G_BAND_3(channel) ((channel) >= 100 && (channel <= 144))
75 #define IS_CH_5G_BAND_4(channel) ((channel) >= 149 && (channel <= 177))
77 #define IS_CH_5G_BAND_MID(channel) \
78 (IS_CH_5G_BAND_2(channel) || IS_CH_5G_BAND_3(channel))
80 #define IS_CH_2G_BAND(channel) ((channel) <= 14)
81 #define IS_CH_5G_BAND(channel) \
82 (IS_CH_5G_BAND_1(channel) || IS_CH_5G_BAND_2(channel) || \
83 IS_CH_5G_BAND_3(channel) || IS_CH_5G_BAND_4(channel))
85 enum rtw_supported_band {
86 RTW_BAND_2G = BIT(NL80211_BAND_2GHZ),
87 RTW_BAND_5G = BIT(NL80211_BAND_5GHZ),
88 RTW_BAND_60G = BIT(NL80211_BAND_60GHZ),
91 /* now, support upto 80M bw */
92 #define RTW_MAX_CHANNEL_WIDTH RTW_CHANNEL_WIDTH_80
95 RTW_CHANNEL_WIDTH_20 = 0,
96 RTW_CHANNEL_WIDTH_40 = 1,
97 RTW_CHANNEL_WIDTH_80 = 2,
98 RTW_CHANNEL_WIDTH_160 = 3,
99 RTW_CHANNEL_WIDTH_80_80 = 4,
100 RTW_CHANNEL_WIDTH_5 = 5,
101 RTW_CHANNEL_WIDTH_10 = 6,
105 RTW_SC_DONT_CARE = 0,
108 RTW_SC_20_UPMOST = 3,
109 RTW_SC_20_LOWEST = 4,
111 RTW_SC_40_LOWER = 10,
117 RTW_NET_MGD_LINKED = 2,
146 BB_PATH_AB = (BB_PATH_A | BB_PATH_B),
147 BB_PATH_AC = (BB_PATH_A | BB_PATH_C),
148 BB_PATH_AD = (BB_PATH_A | BB_PATH_D),
149 BB_PATH_BC = (BB_PATH_B | BB_PATH_C),
150 BB_PATH_BD = (BB_PATH_B | BB_PATH_D),
151 BB_PATH_CD = (BB_PATH_C | BB_PATH_D),
153 BB_PATH_ABC = (BB_PATH_A | BB_PATH_B | BB_PATH_C),
154 BB_PATH_ABD = (BB_PATH_A | BB_PATH_B | BB_PATH_D),
155 BB_PATH_ACD = (BB_PATH_A | BB_PATH_C | BB_PATH_D),
156 BB_PATH_BCD = (BB_PATH_B | BB_PATH_C | BB_PATH_D),
158 BB_PATH_ABCD = (BB_PATH_A | BB_PATH_B | BB_PATH_C | BB_PATH_D),
161 enum rtw_rate_section {
162 RTW_RATE_SECTION_CCK = 0,
163 RTW_RATE_SECTION_OFDM,
164 RTW_RATE_SECTION_HT_1S,
165 RTW_RATE_SECTION_HT_2S,
166 RTW_RATE_SECTION_VHT_1S,
167 RTW_RATE_SECTION_VHT_2S,
170 RTW_RATE_SECTION_MAX,
173 enum rtw_wireless_set {
174 WIRELESS_CCK = 0x00000001,
175 WIRELESS_OFDM = 0x00000002,
176 WIRELESS_HT = 0x00000004,
177 WIRELESS_VHT = 0x00000008,
180 #define HT_STBC_EN BIT(0)
181 #define VHT_STBC_EN BIT(1)
182 #define HT_LDPC_EN BIT(0)
183 #define VHT_LDPC_EN BIT(1)
192 enum rtw_tx_queue_type {
193 /* the order of AC queues matters */
194 RTW_TX_QUEUE_BK = 0x0,
195 RTW_TX_QUEUE_BE = 0x1,
196 RTW_TX_QUEUE_VI = 0x2,
197 RTW_TX_QUEUE_VO = 0x3,
199 RTW_TX_QUEUE_BCN = 0x4,
200 RTW_TX_QUEUE_MGMT = 0x5,
201 RTW_TX_QUEUE_HI0 = 0x6,
202 RTW_TX_QUEUE_H2C = 0x7,
207 enum rtw_rx_queue_type {
208 RTW_RX_QUEUE_MPDU = 0x0,
209 RTW_RX_QUEUE_C2H = 0x1,
219 enum rtw_rate_index {
220 RTW_RATEID_BGN_40M_2SS = 0,
221 RTW_RATEID_BGN_40M_1SS = 1,
222 RTW_RATEID_BGN_20M_2SS = 2,
223 RTW_RATEID_BGN_20M_1SS = 3,
224 RTW_RATEID_GN_N2SS = 4,
225 RTW_RATEID_GN_N1SS = 5,
228 RTW_RATEID_B_20M = 8,
229 RTW_RATEID_ARFR0_AC_2SS = 9,
230 RTW_RATEID_ARFR1_AC_1SS = 10,
231 RTW_RATEID_ARFR2_AC_2G_1SS = 11,
232 RTW_RATEID_ARFR3_AC_2G_2SS = 12,
233 RTW_RATEID_ARFR4_AC_3SS = 13,
234 RTW_RATEID_ARFR5_N_3SS = 14,
235 RTW_RATEID_ARFR7_N_4SS = 15,
236 RTW_RATEID_ARFR6_AC_4SS = 16
239 enum rtw_trx_desc_rate {
242 DESC_RATE5_5M = 0x02,
254 DESC_RATEMCS0 = 0x0c,
255 DESC_RATEMCS1 = 0x0d,
256 DESC_RATEMCS2 = 0x0e,
257 DESC_RATEMCS3 = 0x0f,
258 DESC_RATEMCS4 = 0x10,
259 DESC_RATEMCS5 = 0x11,
260 DESC_RATEMCS6 = 0x12,
261 DESC_RATEMCS7 = 0x13,
262 DESC_RATEMCS8 = 0x14,
263 DESC_RATEMCS9 = 0x15,
264 DESC_RATEMCS10 = 0x16,
265 DESC_RATEMCS11 = 0x17,
266 DESC_RATEMCS12 = 0x18,
267 DESC_RATEMCS13 = 0x19,
268 DESC_RATEMCS14 = 0x1a,
269 DESC_RATEMCS15 = 0x1b,
270 DESC_RATEMCS16 = 0x1c,
271 DESC_RATEMCS17 = 0x1d,
272 DESC_RATEMCS18 = 0x1e,
273 DESC_RATEMCS19 = 0x1f,
274 DESC_RATEMCS20 = 0x20,
275 DESC_RATEMCS21 = 0x21,
276 DESC_RATEMCS22 = 0x22,
277 DESC_RATEMCS23 = 0x23,
278 DESC_RATEMCS24 = 0x24,
279 DESC_RATEMCS25 = 0x25,
280 DESC_RATEMCS26 = 0x26,
281 DESC_RATEMCS27 = 0x27,
282 DESC_RATEMCS28 = 0x28,
283 DESC_RATEMCS29 = 0x29,
284 DESC_RATEMCS30 = 0x2a,
285 DESC_RATEMCS31 = 0x2b,
287 DESC_RATEVHT1SS_MCS0 = 0x2c,
288 DESC_RATEVHT1SS_MCS1 = 0x2d,
289 DESC_RATEVHT1SS_MCS2 = 0x2e,
290 DESC_RATEVHT1SS_MCS3 = 0x2f,
291 DESC_RATEVHT1SS_MCS4 = 0x30,
292 DESC_RATEVHT1SS_MCS5 = 0x31,
293 DESC_RATEVHT1SS_MCS6 = 0x32,
294 DESC_RATEVHT1SS_MCS7 = 0x33,
295 DESC_RATEVHT1SS_MCS8 = 0x34,
296 DESC_RATEVHT1SS_MCS9 = 0x35,
298 DESC_RATEVHT2SS_MCS0 = 0x36,
299 DESC_RATEVHT2SS_MCS1 = 0x37,
300 DESC_RATEVHT2SS_MCS2 = 0x38,
301 DESC_RATEVHT2SS_MCS3 = 0x39,
302 DESC_RATEVHT2SS_MCS4 = 0x3a,
303 DESC_RATEVHT2SS_MCS5 = 0x3b,
304 DESC_RATEVHT2SS_MCS6 = 0x3c,
305 DESC_RATEVHT2SS_MCS7 = 0x3d,
306 DESC_RATEVHT2SS_MCS8 = 0x3e,
307 DESC_RATEVHT2SS_MCS9 = 0x3f,
309 DESC_RATEVHT3SS_MCS0 = 0x40,
310 DESC_RATEVHT3SS_MCS1 = 0x41,
311 DESC_RATEVHT3SS_MCS2 = 0x42,
312 DESC_RATEVHT3SS_MCS3 = 0x43,
313 DESC_RATEVHT3SS_MCS4 = 0x44,
314 DESC_RATEVHT3SS_MCS5 = 0x45,
315 DESC_RATEVHT3SS_MCS6 = 0x46,
316 DESC_RATEVHT3SS_MCS7 = 0x47,
317 DESC_RATEVHT3SS_MCS8 = 0x48,
318 DESC_RATEVHT3SS_MCS9 = 0x49,
320 DESC_RATEVHT4SS_MCS0 = 0x4a,
321 DESC_RATEVHT4SS_MCS1 = 0x4b,
322 DESC_RATEVHT4SS_MCS2 = 0x4c,
323 DESC_RATEVHT4SS_MCS3 = 0x4d,
324 DESC_RATEVHT4SS_MCS4 = 0x4e,
325 DESC_RATEVHT4SS_MCS5 = 0x4f,
326 DESC_RATEVHT4SS_MCS6 = 0x50,
327 DESC_RATEVHT4SS_MCS7 = 0x51,
328 DESC_RATEVHT4SS_MCS8 = 0x52,
329 DESC_RATEVHT4SS_MCS9 = 0x53,
334 enum rtw_regulatory_domains {
342 RTW_REGD_UKRAINE = 7,
361 RTW_FLAG_LEISURE_PS_DEEP,
362 RTW_FLAG_DIG_DISABLE,
363 RTW_FLAG_BUSY_TRAFFIC,
366 RTW_FLAG_RESTART_TRIGGERING,
367 RTW_FLAG_FORCE_LOWEST_RATE,
408 RTW_WOW_FLAG_EN_MAGIC_PKT,
409 RTW_WOW_FLAG_EN_REKEY_PKT,
410 RTW_WOW_FLAG_EN_DISCONNECT,
416 /* the power index is represented by differences, which cck-1s & ht40-1s are
417 * the base values, so for 1s's differences, there are only ht20 & ofdm
419 struct rtw_2g_1s_pwr_idx_diff {
420 #ifdef __LITTLE_ENDIAN
429 struct rtw_2g_ns_pwr_idx_diff {
430 #ifdef __LITTLE_ENDIAN
443 struct rtw_2g_txpwr_idx {
446 struct rtw_2g_1s_pwr_idx_diff ht_1s_diff;
447 struct rtw_2g_ns_pwr_idx_diff ht_2s_diff;
448 struct rtw_2g_ns_pwr_idx_diff ht_3s_diff;
449 struct rtw_2g_ns_pwr_idx_diff ht_4s_diff;
452 struct rtw_5g_ht_1s_pwr_idx_diff {
453 #ifdef __LITTLE_ENDIAN
462 struct rtw_5g_ht_ns_pwr_idx_diff {
463 #ifdef __LITTLE_ENDIAN
472 struct rtw_5g_ofdm_ns_pwr_idx_diff {
473 #ifdef __LITTLE_ENDIAN
486 struct rtw_5g_vht_ns_pwr_idx_diff {
487 #ifdef __LITTLE_ENDIAN
496 struct rtw_5g_txpwr_idx {
498 struct rtw_5g_ht_1s_pwr_idx_diff ht_1s_diff;
499 struct rtw_5g_ht_ns_pwr_idx_diff ht_2s_diff;
500 struct rtw_5g_ht_ns_pwr_idx_diff ht_3s_diff;
501 struct rtw_5g_ht_ns_pwr_idx_diff ht_4s_diff;
502 struct rtw_5g_ofdm_ns_pwr_idx_diff ofdm_diff;
503 struct rtw_5g_vht_ns_pwr_idx_diff vht_1s_diff;
504 struct rtw_5g_vht_ns_pwr_idx_diff vht_2s_diff;
505 struct rtw_5g_vht_ns_pwr_idx_diff vht_3s_diff;
506 struct rtw_5g_vht_ns_pwr_idx_diff vht_4s_diff;
509 struct rtw_txpwr_idx {
510 struct rtw_2g_txpwr_idx pwr_idx_2g;
511 struct rtw_5g_txpwr_idx pwr_idx_5g;
514 struct rtw_timer_list {
515 struct timer_list timer;
516 void (*function)(void *data);
520 struct rtw_channel_params {
531 struct rtw_ltecoex_addr {
537 struct rtw_reg_domain {
540 #define RTW_REG_DOMAIN_MAC32 0
541 #define RTW_REG_DOMAIN_MAC16 1
542 #define RTW_REG_DOMAIN_MAC8 2
543 #define RTW_REG_DOMAIN_RF_A 3
544 #define RTW_REG_DOMAIN_RF_B 4
545 #define RTW_REG_DOMAIN_NL 0xFF
549 struct rtw_rf_sipi_addr {
556 struct rtw_hw_reg_offset {
557 struct rtw_hw_reg hw_reg;
561 struct rtw_backup_info {
567 enum rtw_vif_port_set {
568 PORT_SET_MAC_ADDR = BIT(0),
569 PORT_SET_BSSID = BIT(1),
570 PORT_SET_NET_TYPE = BIT(2),
571 PORT_SET_AID = BIT(3),
572 PORT_SET_BCN_CTRL = BIT(4),
575 struct rtw_vif_port {
576 struct rtw_hw_reg mac_addr;
577 struct rtw_hw_reg bssid;
578 struct rtw_hw_reg net_type;
579 struct rtw_hw_reg aid;
580 struct rtw_hw_reg bcn_ctrl;
583 struct rtw_tx_pkt_info {
601 bool dis_rate_fallback;
616 struct rtw_rx_pkt_stat {
633 s8 rx_power[RTW_RF_PATH_MAX];
636 s8 rx_snr[RTW_RF_PATH_MAX];
637 u8 rx_evm[RTW_RF_PATH_MAX];
638 s8 cfo_tail[RTW_RF_PATH_MAX];
642 struct rtw_sta_info *si;
643 struct ieee80211_vif *vif;
644 struct ieee80211_hdr *hdr;
647 DECLARE_EWMA(tp, 10, 2);
649 struct rtw_traffic_stats {
654 /* count for packets */
661 struct ewma_tp tx_ewma_tp;
662 struct ewma_tp rx_ewma_tp;
671 enum rtw_lps_deep_mode {
672 LPS_DEEP_MODE_NONE = 0,
673 LPS_DEEP_MODE_LCLK = 1,
674 LPS_DEEP_MODE_PG = 2,
683 struct rtw_lps_conf {
684 enum rtw_lps_mode mode;
685 enum rtw_lps_deep_mode deep_mode;
686 enum rtw_lps_deep_mode wow_deep_mode;
687 enum rtw_pwr_state state;
693 bool pattern_cam_backup;
696 enum rtw_hw_key_type {
704 struct rtw_cam_entry {
709 struct ieee80211_key_conf *key;
712 struct rtw_sec_desc {
713 /* search strategy */
714 bool default_key_search;
717 struct rtw_cam_entry cam_table[RTW_MAX_SEC_CAM_NUM];
718 DECLARE_BITMAP(cam_map, RTW_MAX_SEC_CAM_NUM);
721 struct rtw_tx_report {
722 /* protect the tx report queue */
724 struct sk_buff_head queue;
726 struct timer_list purge_timer;
729 struct rtw_ra_report {
730 struct rate_info txrate;
736 struct list_head list;
739 unsigned long last_push;
742 #define RTW_BC_MC_MACID 1
743 DECLARE_EWMA(rssi, 10, 16);
745 struct rtw_sta_info {
746 struct ieee80211_sta *sta;
747 struct ieee80211_vif *vif;
749 struct ewma_rssi avg_rssi;
754 enum rtw_bandwidth bw_mode;
755 enum rtw_rf_type rf_type;
756 enum rtw_wireless_set wireless_set;
764 DECLARE_BITMAP(tid_ba, IEEE80211_NUM_TIDS);
766 struct rtw_ra_report ra_report;
769 struct cfg80211_bitrate_mask *mask;
779 enum rtw_bfee_role role;
783 u8 mac_addr[ETH_ALEN];
796 DECLARE_BITMAP(bfer_su_reg_maping, 2);
801 enum rtw_net_type net_type;
803 u8 mac_addr[ETH_ALEN];
807 struct list_head rsvd_page_list;
808 struct ieee80211_tx_queue_params tx_params[IEEE80211_NUM_ACS];
809 const struct rtw_vif_port *conf;
810 struct cfg80211_scan_request *scan_req;
811 struct ieee80211_scan_ies *scan_ies;
813 struct rtw_traffic_stats stats;
815 struct rtw_bfee bfee;
818 struct rtw_regulatory {
824 enum rtw_regd_state {
825 RTW_REGD_STATE_WORLDWIDE,
826 RTW_REGD_STATE_PROGRAMMED,
827 RTW_REGD_STATE_SETTING,
833 enum rtw_regd_state state;
834 const struct rtw_regulatory *regulatory;
835 enum nl80211_dfs_regions dfs_region;
838 struct rtw_chip_ops {
839 int (*mac_init)(struct rtw_dev *rtwdev);
840 int (*dump_fw_crash)(struct rtw_dev *rtwdev);
841 void (*shutdown)(struct rtw_dev *rtwdev);
842 int (*read_efuse)(struct rtw_dev *rtwdev, u8 *map);
843 void (*phy_set_param)(struct rtw_dev *rtwdev);
844 void (*set_channel)(struct rtw_dev *rtwdev, u8 channel,
845 u8 bandwidth, u8 primary_chan_idx);
846 void (*query_rx_desc)(struct rtw_dev *rtwdev, u8 *rx_desc,
847 struct rtw_rx_pkt_stat *pkt_stat,
848 struct ieee80211_rx_status *rx_status);
849 u32 (*read_rf)(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
851 bool (*write_rf)(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
852 u32 addr, u32 mask, u32 data);
853 void (*set_tx_power_index)(struct rtw_dev *rtwdev);
854 int (*rsvd_page_dump)(struct rtw_dev *rtwdev, u8 *buf, u32 offset,
856 int (*set_antenna)(struct rtw_dev *rtwdev,
859 void (*cfg_ldo25)(struct rtw_dev *rtwdev, bool enable);
860 void (*efuse_grant)(struct rtw_dev *rtwdev, bool enable);
861 void (*false_alarm_statistics)(struct rtw_dev *rtwdev);
862 void (*phy_calibration)(struct rtw_dev *rtwdev);
863 void (*dpk_track)(struct rtw_dev *rtwdev);
864 void (*cck_pd_set)(struct rtw_dev *rtwdev, u8 level);
865 void (*pwr_track)(struct rtw_dev *rtwdev);
866 void (*config_bfee)(struct rtw_dev *rtwdev, struct rtw_vif *vif,
867 struct rtw_bfee *bfee, bool enable);
868 void (*set_gid_table)(struct rtw_dev *rtwdev,
869 struct ieee80211_vif *vif,
870 struct ieee80211_bss_conf *conf);
871 void (*cfg_csi_rate)(struct rtw_dev *rtwdev, u8 rssi, u8 cur_rate,
872 u8 fixrate_en, u8 *new_rate);
873 void (*adaptivity_init)(struct rtw_dev *rtwdev);
874 void (*adaptivity)(struct rtw_dev *rtwdev);
875 void (*cfo_init)(struct rtw_dev *rtwdev);
876 void (*cfo_track)(struct rtw_dev *rtwdev);
877 void (*config_tx_path)(struct rtw_dev *rtwdev, u8 tx_path,
878 enum rtw_bb_path tx_path_1ss,
879 enum rtw_bb_path tx_path_cck,
881 void (*config_txrx_mode)(struct rtw_dev *rtwdev, u8 tx_path,
882 u8 rx_path, bool is_tx2_path);
883 /* for USB/SDIO only */
884 void (*fill_txdesc_checksum)(struct rtw_dev *rtwdev,
885 struct rtw_tx_pkt_info *pkt_info,
889 void (*coex_set_init)(struct rtw_dev *rtwdev);
890 void (*coex_set_ant_switch)(struct rtw_dev *rtwdev,
891 u8 ctrl_type, u8 pos_type);
892 void (*coex_set_gnt_fix)(struct rtw_dev *rtwdev);
893 void (*coex_set_gnt_debug)(struct rtw_dev *rtwdev);
894 void (*coex_set_rfe_type)(struct rtw_dev *rtwdev);
895 void (*coex_set_wl_tx_power)(struct rtw_dev *rtwdev, u8 wl_pwr);
896 void (*coex_set_wl_rx_gain)(struct rtw_dev *rtwdev, bool low_gain);
899 #define RTW_PWR_POLLING_CNT 20000
901 #define RTW_PWR_CMD_READ 0x00
902 #define RTW_PWR_CMD_WRITE 0x01
903 #define RTW_PWR_CMD_POLLING 0x02
904 #define RTW_PWR_CMD_DELAY 0x03
905 #define RTW_PWR_CMD_END 0x04
907 /* define the base address of each block */
908 #define RTW_PWR_ADDR_MAC 0x00
909 #define RTW_PWR_ADDR_USB 0x01
910 #define RTW_PWR_ADDR_PCIE 0x02
911 #define RTW_PWR_ADDR_SDIO 0x03
913 #define RTW_PWR_INTF_SDIO_MSK BIT(0)
914 #define RTW_PWR_INTF_USB_MSK BIT(1)
915 #define RTW_PWR_INTF_PCI_MSK BIT(2)
916 #define RTW_PWR_INTF_ALL_MSK (BIT(0) | BIT(1) | BIT(2) | BIT(3))
918 #define RTW_PWR_CUT_TEST_MSK BIT(0)
919 #define RTW_PWR_CUT_A_MSK BIT(1)
920 #define RTW_PWR_CUT_B_MSK BIT(2)
921 #define RTW_PWR_CUT_C_MSK BIT(3)
922 #define RTW_PWR_CUT_D_MSK BIT(4)
923 #define RTW_PWR_CUT_E_MSK BIT(5)
924 #define RTW_PWR_CUT_F_MSK BIT(6)
925 #define RTW_PWR_CUT_G_MSK BIT(7)
926 #define RTW_PWR_CUT_ALL_MSK 0xFF
928 enum rtw_pwr_seq_cmd_delay_unit {
933 struct rtw_pwr_seq_cmd {
944 RTW_CHIP_VER_CUT_A = 0x00,
945 RTW_CHIP_VER_CUT_B = 0x01,
946 RTW_CHIP_VER_CUT_C = 0x02,
947 RTW_CHIP_VER_CUT_D = 0x03,
948 RTW_CHIP_VER_CUT_E = 0x04,
949 RTW_CHIP_VER_CUT_F = 0x05,
950 RTW_CHIP_VER_CUT_G = 0x06,
953 #define RTW_INTF_PHY_PLATFORM_ALL 0
955 enum rtw_intf_phy_cut {
956 RTW_INTF_PHY_CUT_A = BIT(0),
957 RTW_INTF_PHY_CUT_B = BIT(1),
958 RTW_INTF_PHY_CUT_C = BIT(2),
959 RTW_INTF_PHY_CUT_D = BIT(3),
960 RTW_INTF_PHY_CUT_E = BIT(4),
961 RTW_INTF_PHY_CUT_F = BIT(5),
962 RTW_INTF_PHY_CUT_G = BIT(6),
963 RTW_INTF_PHY_CUT_ALL = 0xFFFF,
971 RTW_IP_SEL_UNDEF = 0xFFFF
981 RTW_PQ_MAP_NUM = 0x6,
986 enum rtw_dma_mapping {
987 RTW_DMA_MAPPING_EXTRA = 0,
988 RTW_DMA_MAPPING_LOW = 1,
989 RTW_DMA_MAPPING_NORMAL = 2,
990 RTW_DMA_MAPPING_HIGH = 3,
993 RTW_DMA_MAPPING_UNDEF,
997 enum rtw_dma_mapping dma_map_vo;
998 enum rtw_dma_mapping dma_map_vi;
999 enum rtw_dma_mapping dma_map_be;
1000 enum rtw_dma_mapping dma_map_bk;
1001 enum rtw_dma_mapping dma_map_mg;
1002 enum rtw_dma_mapping dma_map_hi;
1005 struct rtw_prioq_addr {
1010 struct rtw_prioq_addrs {
1011 struct rtw_prioq_addr prio[RTW_DMA_MAPPING_MAX];
1015 struct rtw_page_table {
1023 struct rtw_intf_phy_para {
1031 struct rtw_wow_pattern {
1035 u8 mask[RTW_MAX_PATTERN_MASK_SIZE];
1038 struct rtw_pno_request {
1041 struct cfg80211_match_set *match_sets;
1043 struct ieee80211_channel *channels;
1044 struct cfg80211_sched_scan_plan scan_plan;
1047 struct rtw_wow_param {
1048 struct ieee80211_vif *wow_vif;
1049 DECLARE_BITMAP(flags, RTW_WOW_FLAG_MAX);
1052 struct rtw_wow_pattern patterns[RTW_MAX_PATTERN_NUM];
1055 struct rtw_pno_request pno_req;
1058 struct rtw_intf_phy_para_table {
1059 const struct rtw_intf_phy_para *usb2_para;
1060 const struct rtw_intf_phy_para *usb3_para;
1061 const struct rtw_intf_phy_para *gen1_para;
1062 const struct rtw_intf_phy_para *gen2_para;
1072 void (*parse)(struct rtw_dev *rtwdev, const struct rtw_table *tbl);
1073 void (*do_cfg)(struct rtw_dev *rtwdev, const struct rtw_table *tbl,
1074 u32 addr, u32 data);
1075 enum rtw_rf_path rf_path;
1078 static inline void rtw_load_table(struct rtw_dev *rtwdev,
1079 const struct rtw_table *tbl)
1081 (*tbl->parse)(rtwdev, tbl);
1087 RTW_RFE_IFEM2G_EFEM5G,
1091 struct rtw_rfe_def {
1092 const struct rtw_table *phy_pg_tbl;
1093 const struct rtw_table *txpwr_lmt_tbl;
1094 const struct rtw_table *agc_btg_tbl;
1097 #define RTW_DEF_RFE(chip, bb_pg, pwrlmt) { \
1098 .phy_pg_tbl = &rtw ## chip ## _bb_pg_type ## bb_pg ## _tbl, \
1099 .txpwr_lmt_tbl = &rtw ## chip ## _txpwr_lmt_type ## pwrlmt ## _tbl, \
1102 #define RTW_DEF_RFE_EXT(chip, bb_pg, pwrlmt, btg) { \
1103 .phy_pg_tbl = &rtw ## chip ## _bb_pg_type ## bb_pg ## _tbl, \
1104 .txpwr_lmt_tbl = &rtw ## chip ## _txpwr_lmt_type ## pwrlmt ## _tbl, \
1105 .agc_btg_tbl = &rtw ## chip ## _agc_btg_type ## btg ## _tbl, \
1108 #define RTW_PWR_TRK_5G_1 0
1109 #define RTW_PWR_TRK_5G_2 1
1110 #define RTW_PWR_TRK_5G_3 2
1111 #define RTW_PWR_TRK_5G_NUM 3
1113 #define RTW_PWR_TRK_TBL_SZ 30
1115 /* This table stores the values of TX power that will be adjusted by power
1118 * For 5G bands, there are 3 different settings.
1119 * For 2G there are cck rate and ofdm rate with different settings.
1121 struct rtw_pwr_track_tbl {
1122 const u8 *pwrtrk_5gb_n[RTW_PWR_TRK_5G_NUM];
1123 const u8 *pwrtrk_5gb_p[RTW_PWR_TRK_5G_NUM];
1124 const u8 *pwrtrk_5ga_n[RTW_PWR_TRK_5G_NUM];
1125 const u8 *pwrtrk_5ga_p[RTW_PWR_TRK_5G_NUM];
1126 const u8 *pwrtrk_2gb_n;
1127 const u8 *pwrtrk_2gb_p;
1128 const u8 *pwrtrk_2ga_n;
1129 const u8 *pwrtrk_2ga_p;
1130 const u8 *pwrtrk_2g_cckb_n;
1131 const u8 *pwrtrk_2g_cckb_p;
1132 const u8 *pwrtrk_2g_ccka_n;
1133 const u8 *pwrtrk_2g_ccka_p;
1134 const s8 *pwrtrk_xtal_n;
1135 const s8 *pwrtrk_xtal_p;
1143 enum rtw_fw_fifo_sel {
1146 RTW_FW_FIFO_SEL_RSVD_PAGE,
1147 RTW_FW_FIFO_SEL_REPORT,
1148 RTW_FW_FIFO_SEL_LLT,
1149 RTW_FW_FIFO_SEL_RXBUF_FW,
1154 enum rtw_fwcd_item {
1163 /* hardware configuration for each IC */
1164 struct rtw_chip_info {
1165 struct rtw_chip_ops *ops;
1168 const char *fw_name;
1169 enum rtw_wlan_cpu wlan_cpu;
1176 u32 ptct_efuse_size;
1180 u16 rsvd_drv_pg_num;
1187 bool is_pwr_by_rate_dec;
1193 u16 fw_fifo_addr[RTW_FW_FIFO_MAX];
1194 const struct rtw_fwcd_segs *fwcd_segs;
1196 u8 default_1ss_tx_path;
1198 bool path_div_supported;
1201 u8 lps_deep_mode_supported;
1205 const struct rtw_pwr_seq_cmd **pwr_on_seq;
1206 const struct rtw_pwr_seq_cmd **pwr_off_seq;
1207 const struct rtw_rqpn *rqpn_table;
1208 const struct rtw_prioq_addrs *prioq_addrs;
1209 const struct rtw_page_table *page_table;
1210 const struct rtw_intf_phy_para_table *intf_table;
1212 const struct rtw_hw_reg *dig;
1213 const struct rtw_hw_reg *dig_cck;
1214 u32 rf_base_addr[2];
1215 u32 rf_sipi_addr[2];
1216 const struct rtw_rf_sipi_addr *rf_sipi_read_addr;
1218 const struct rtw_ltecoex_addr *ltecoex_addr;
1220 const struct rtw_table *mac_tbl;
1221 const struct rtw_table *agc_tbl;
1222 const struct rtw_table *bb_tbl;
1223 const struct rtw_table *rf_tbl[RTW_RF_PATH_MAX];
1224 const struct rtw_table *rfk_init_tbl;
1226 const struct rtw_rfe_def *rfe_defs;
1233 const struct rtw_pwr_track_tbl *pwr_track_tbl;
1238 struct rtw_hw_reg_offset *edcca_th;
1242 const char *wow_fw_name;
1243 const struct wiphy_wowlan_support *wowlan_stub;
1244 const u8 max_sched_scan_ssids;
1245 const u16 max_scan_ie_len;
1251 bool new_scbd10_def; /* true: fix 2M(8822c) */
1252 bool ble_hid_profile_support;
1253 bool wl_mimo_ps_support;
1254 u8 pstdma_type; /* 0: LPSoff, 1:LPSon */
1262 u8 bt_afh_span_bw20;
1263 u8 bt_afh_span_bw40;
1266 u8 coex_info_hw_regs_num;
1267 const u8 *bt_rssi_step;
1268 const u8 *wl_rssi_step;
1269 const struct coex_table_para *table_nsant;
1270 const struct coex_table_para *table_sant;
1271 const struct coex_tdma_para *tdma_sant;
1272 const struct coex_tdma_para *tdma_nsant;
1273 const struct coex_rf_para *wl_rf_para_tx;
1274 const struct coex_rf_para *wl_rf_para_rx;
1275 const struct coex_5g_afh_map *afh_5g;
1276 const struct rtw_hw_reg *btg_reg;
1277 const struct rtw_reg_domain *coex_info_hw_regs;
1278 u32 wl_fw_desired_ver;
1281 enum rtw_coex_bt_state_cnt {
1284 COEX_CNT_BT_REENABLE,
1285 COEX_CNT_BT_POPEVENT,
1286 COEX_CNT_BT_SETUPLINK,
1287 COEX_CNT_BT_IGNWLANACT,
1290 COEX_CNT_BT_ROLESWITCH,
1291 COEX_CNT_BT_AFHUPDATE,
1292 COEX_CNT_BT_INFOUPDATE,
1294 COEX_CNT_BT_IQKFAIL,
1299 enum rtw_coex_wl_state_cnt {
1301 COEX_CNT_WL_CONNPKT,
1302 COEX_CNT_WL_COEXRUN,
1306 COEX_CNT_WL_5MS_NOEXTEND,
1307 COEX_CNT_WL_FW_NOTIFY,
1312 struct rtw_coex_rfe {
1313 bool ant_switch_exist;
1314 bool ant_switch_diversity;
1315 bool ant_switch_with_bt;
1317 u8 ant_switch_polarity;
1319 /* true if WLG at BTG, else at WLAG */
1323 #define COEX_WL_TDMA_PARA_LENGTH 5
1325 struct rtw_coex_dm {
1326 bool cur_ps_tdma_on;
1327 bool cur_wl_rx_low_gain_en;
1331 u8 bt_rssi_state[4];
1332 u8 wl_rssi_state[4];
1341 u32 cur_ant_pos_type;
1342 u32 cur_switch_status;
1344 u8 fw_tdma_para[COEX_WL_TDMA_PARA_LENGTH];
1347 #define COEX_BTINFO_SRC_WL_FW 0x0
1348 #define COEX_BTINFO_SRC_BT_RSP 0x1
1349 #define COEX_BTINFO_SRC_BT_ACT 0x2
1350 #define COEX_BTINFO_SRC_BT_IQK 0x3
1351 #define COEX_BTINFO_SRC_BT_SCBD 0x4
1352 #define COEX_BTINFO_SRC_H2C60 0x5
1353 #define COEX_BTINFO_SRC_MAX 0x6
1355 #define COEX_INFO_FTP BIT(7)
1356 #define COEX_INFO_A2DP BIT(6)
1357 #define COEX_INFO_HID BIT(5)
1358 #define COEX_INFO_SCO_BUSY BIT(4)
1359 #define COEX_INFO_ACL_BUSY BIT(3)
1360 #define COEX_INFO_INQ_PAGE BIT(2)
1361 #define COEX_INFO_SCO_ESCO BIT(1)
1362 #define COEX_INFO_CONNECTION BIT(0)
1363 #define COEX_BTINFO_LENGTH_MAX 10
1364 #define COEX_BTINFO_LENGTH 7
1366 #define COEX_BT_HIDINFO_LIST 0x0
1367 #define COEX_BT_HIDINFO_A 0x1
1368 #define COEX_BT_HIDINFO_NAME 3
1370 #define COEX_BT_HIDINFO_LENGTH 6
1371 #define COEX_BT_HIDINFO_HANDLE_NUM 4
1372 #define COEX_BT_HIDINFO_C2H_HANDLE 0
1373 #define COEX_BT_HIDINFO_C2H_VENDOR 1
1374 #define COEX_BT_BLE_HANDLE_THRS 0x10
1375 #define COEX_BT_HIDINFO_NOTCON 0xff
1377 struct rtw_coex_hid {
1380 u8 hid_name[COEX_BT_HIDINFO_NAME];
1381 bool hid_info_completed;
1385 struct rtw_coex_hid_handle_list {
1390 u8 handle[COEX_BT_HIDINFO_HANDLE_NUM];
1393 struct rtw_coex_hid_info_a {
1399 u8 name[COEX_BT_HIDINFO_NAME];
1402 struct rtw_coex_stat {
1404 bool bt_disabled_pre;
1416 bool bt_pan_exist; /* PAN or OPP */
1417 bool bt_opp_exist; /* OPP only */
1422 bool bt_multi_link_pre;
1423 bool bt_multi_link_remain;
1425 bool bt_a2dp_active;
1427 bool bt_ble_scan_en;
1430 bool bt_418_hid_exist;
1431 bool bt_ble_hid_exist;
1432 bool bt_game_hid_exist;
1433 bool bt_hid_handle_cnt;
1434 bool bt_mailbox_reply;
1438 bool wl_hi_pri_task1;
1439 bool wl_hi_pri_task2;
1440 bool wl_force_lps_ctrl;
1442 bool wl_linkscan_proc;
1443 bool wl_ps_state_fail;
1444 bool wl_tx_limit_en;
1445 bool wl_ampdu_limit_en;
1447 bool wl_slot_extend;
1449 bool wl_cck_lock_pre;
1450 bool wl_cck_lock_ever;
1452 bool wl_slot_toggle;
1453 bool wl_slot_toggle_change; /* if toggle to no-toggle */
1456 u32 bt_supported_version;
1457 u32 bt_supported_feature;
1463 u16 bt_reg_vendor_ae;
1464 u16 bt_reg_vendor_ac;
1467 u8 gnt_workaround_state;
1470 u8 bt_info_c2h[COEX_BTINFO_SRC_MAX][COEX_BTINFO_LENGTH_MAX];
1477 u8 bt_ble_scan_type;
1483 u16 wl_beacon_interval;
1485 u8 wl_fw_dbg_info[10];
1486 u8 wl_fw_dbg_info_pre[10];
1495 u8 wl_toggle_para[6];
1496 u8 wl_toggle_interval;
1501 /* counters to record bt states */
1502 u32 cnt_bt[COEX_CNT_BT_MAX];
1504 /* counters to record wifi states */
1505 u32 cnt_wl[COEX_CNT_WL_MAX];
1507 /* counters to record bt c2h data */
1508 u32 cnt_bt_info_c2h[COEX_BTINFO_SRC_MAX];
1513 struct rtw_coex_hid hid_info[COEX_BT_HIDINFO_HANDLE_NUM];
1514 struct rtw_coex_hid_handle_list hid_handle_list;
1518 struct sk_buff_head queue;
1519 wait_queue_head_t wait;
1526 bool manual_control;
1528 struct rtw_coex_stat stat;
1529 struct rtw_coex_dm dm;
1530 struct rtw_coex_rfe rfe;
1532 struct delayed_work bt_relink_work;
1533 struct delayed_work bt_reenable_work;
1534 struct delayed_work defreeze_work;
1535 struct delayed_work wl_remain_work;
1536 struct delayed_work bt_remain_work;
1537 struct delayed_work wl_connecting_work;
1538 struct delayed_work bt_multi_link_remain_work;
1539 struct delayed_work wl_ccklock_work;
1543 #define DPK_RF_REG_NUM 7
1544 #define DPK_RF_PATH_NUM 2
1545 #define DPK_BB_REG_NUM 18
1546 #define DPK_CHANNEL_WIDTH_80 1
1548 DECLARE_EWMA(thermal, 10, 4);
1550 struct rtw_dpk_info {
1554 DECLARE_BITMAP(dpk_path_ok, DPK_RF_PATH_NUM);
1556 u8 thermal_dpk[DPK_RF_PATH_NUM];
1557 struct ewma_thermal avg_thermal[DPK_RF_PATH_NUM];
1562 u8 result[RTW_RF_PATH_MAX];
1563 u8 dpk_txagc[RTW_RF_PATH_MAX];
1564 u32 coef[RTW_RF_PATH_MAX][20];
1565 u16 dpk_gs[RTW_RF_PATH_MAX];
1566 u8 thermal_dpk_delta[RTW_RF_PATH_MAX];
1567 u8 pre_pwsf[RTW_RF_PATH_MAX];
1574 struct rtw_phy_cck_pd_reg {
1581 #define DACK_MSBK_BACKUP_NUM 0xf
1582 #define DACK_DCK_BACKUP_NUM 0x2
1584 struct rtw_swing_table {
1585 const u8 *p[RTW_RF_PATH_MAX];
1586 const u8 *n[RTW_RF_PATH_MAX];
1589 struct rtw_pkt_count {
1591 u16 num_qry_pkt[DESC_RATE_MAX];
1594 DECLARE_EWMA(evm, 10, 4);
1595 DECLARE_EWMA(snr, 10, 4);
1597 struct rtw_iqk_info {
1616 #define RF_GAIN_NUM 11
1617 #define RF_HW_OFFSET_NUM 10
1619 struct rtw_gapk_info {
1620 u32 rf3f_bp[RF_BAND_MAX][RF_GAIN_NUM][RTW_RF_PATH_MAX];
1621 u32 rf3f_fs[RTW_RF_PATH_MAX][RF_GAIN_NUM];
1622 bool txgapk_bp_done;
1623 s8 offset[RF_GAIN_NUM][RTW_RF_PATH_MAX];
1624 s8 fianl_offset[RF_GAIN_NUM][RTW_RF_PATH_MAX];
1629 #define EDCCA_TH_L2H_IDX 0
1630 #define EDCCA_TH_H2L_IDX 1
1631 #define EDCCA_TH_L2H_LB 48
1632 #define EDCCA_ADC_BACKOFF 12
1633 #define EDCCA_IGI_BASE 50
1634 #define EDCCA_IGI_L2H_DIFF 8
1635 #define EDCCA_L2H_H2L_DIFF 7
1636 #define EDCCA_L2H_H2L_DIFF_NORMAL 8
1638 enum rtw_edcca_mode {
1639 RTW_EDCCA_NORMAL = 0,
1640 RTW_EDCCA_ADAPTIVITY = 1,
1643 struct rtw_cfo_track {
1646 s32 cfo_tail[RTW_RF_PATH_MAX];
1647 s32 cfo_cnt[RTW_RF_PATH_MAX];
1649 u32 packet_count_pre;
1652 #define RRSR_INIT_2G 0x15f
1653 #define RRSR_INIT_5G 0x150
1661 struct rtw_dm_info {
1694 u8 thermal_avg[RTW_RF_PATH_MAX];
1696 u8 thermal_meter_lck;
1697 s8 delta_power_index[RTW_RF_PATH_MAX];
1698 s8 delta_power_index_last[RTW_RF_PATH_MAX];
1699 u8 default_ofdm_index;
1700 bool pwr_trk_triggered;
1701 bool pwr_trk_init_trigger;
1702 struct ewma_thermal avg_thermal[RTW_RF_PATH_MAX];
1703 s8 txagc_remnant_cck;
1704 s8 txagc_remnant_ofdm;
1706 /* backup dack results for each path and I/Q */
1707 u32 dack_adck[RTW_RF_PATH_MAX];
1708 u16 dack_msbk[RTW_RF_PATH_MAX][2][DACK_MSBK_BACKUP_NUM];
1709 u8 dack_dck[RTW_RF_PATH_MAX][2][DACK_DCK_BACKUP_NUM];
1711 struct rtw_dpk_info dpk_info;
1712 struct rtw_cfo_track cfo_track;
1714 /* [bandwidth 0:20M/1:40M][number of path] */
1715 u8 cck_pd_lv[2][RTW_RF_PATH_MAX];
1719 /* save the last rx phy status for debug */
1720 s8 rx_snr[RTW_RF_PATH_MAX];
1721 u8 rx_evm_dbm[RTW_RF_PATH_MAX];
1722 s16 cfo_tail[RTW_RF_PATH_MAX];
1723 u8 rssi[RTW_RF_PATH_MAX];
1725 struct rtw_pkt_count cur_pkt_count;
1726 struct rtw_pkt_count last_pkt_count;
1727 struct ewma_evm ewma_evm[RTW_EVM_NUM];
1728 struct ewma_snr ewma_snr[RTW_SNR_NUM];
1730 u32 dm_flags; /* enum rtw_dm_cap */
1731 struct rtw_iqk_info iqk;
1732 struct rtw_gapk_info gapk;
1733 bool is_bt_iqk_timeout;
1736 enum rtw_edcca_mode edcca_mode;
1751 u8 power_track_type;
1752 u8 thermal_meter[RTW_RF_PATH_MAX];
1772 u8 tx_bb_swing_setting_2g;
1773 u8 tx_bb_swing_setting_5g;
1776 /* bt share antenna with wifi */
1788 struct rtw_txpwr_idx txpwr_idx_table[4];
1791 struct rtw_phy_cond {
1792 #ifdef __LITTLE_ENDIAN
1814 #define INTF_PCIE BIT(0)
1815 #define INTF_USB BIT(1)
1816 #define INTF_SDIO BIT(2)
1819 #define BRANCH_ELIF 1
1820 #define BRANCH_ELSE 2
1821 #define BRANCH_ENDIF 3
1824 struct rtw_fifo_conf {
1825 /* tx fifo information */
1828 u16 rsvd_drv_pg_num;
1832 u16 rsvd_h2c_info_addr;
1833 u16 rsvd_h2c_sta_info_addr;
1835 u16 rsvd_cpu_instr_addr;
1836 u16 rsvd_fw_txbuf_addr;
1837 u16 rsvd_csibuf_addr;
1838 const struct rtw_rqpn *rqpn;
1841 struct rtw_fwcd_desc {
1847 struct rtw_fwcd_segs {
1852 #define FW_CD_TYPE 0xffff
1854 #define FW_CD_VAL 0xaabbccdd
1855 struct rtw_fw_state {
1856 const struct firmware *firmware;
1857 struct rtw_dev *rtwdev;
1858 struct completion completion;
1859 struct rtw_fwcd_desc fwcd_desc;
1866 enum rtw_fw_type type;
1869 enum rtw_sar_sources {
1870 RTW_SAR_SOURCE_NONE,
1871 RTW_SAR_SOURCE_COMMON,
1874 enum rtw_sar_bands {
1877 /* RTW_SAR_BAND_2, not used now */
1884 /* the union is reserved for other knids of SAR sources
1885 * which might not re-use same format with array common.
1888 s8 common[RTW_SAR_BAND_NR];
1892 enum rtw_sar_sources src;
1893 union rtw_sar_cfg cfg[RTW_RF_PATH_MAX][RTW_RATE_SECTION_MAX];
1903 struct rtw_phy_cond phy_cond;
1907 u8 current_primary_channel_index;
1908 u8 current_band_width;
1909 u8 current_band_type;
1912 /* center channel for different available bandwidth,
1913 * val of (bw > current_band_width) is invalid
1915 u8 cch_by_bw[RTW_MAX_CHANNEL_WIDTH + 1];
1926 /* protect tx power section */
1927 struct mutex tx_power_mutex;
1928 s8 tx_pwr_by_rate_offset_2g[RTW_RF_PATH_MAX]
1930 s8 tx_pwr_by_rate_offset_5g[RTW_RF_PATH_MAX]
1932 s8 tx_pwr_by_rate_base_2g[RTW_RF_PATH_MAX]
1933 [RTW_RATE_SECTION_MAX];
1934 s8 tx_pwr_by_rate_base_5g[RTW_RF_PATH_MAX]
1935 [RTW_RATE_SECTION_MAX];
1936 s8 tx_pwr_limit_2g[RTW_REGD_MAX]
1937 [RTW_CHANNEL_WIDTH_MAX]
1938 [RTW_RATE_SECTION_MAX]
1939 [RTW_MAX_CHANNEL_NUM_2G];
1940 s8 tx_pwr_limit_5g[RTW_REGD_MAX]
1941 [RTW_CHANNEL_WIDTH_MAX]
1942 [RTW_RATE_SECTION_MAX]
1943 [RTW_MAX_CHANNEL_NUM_5G];
1944 s8 tx_pwr_tbl[RTW_RF_PATH_MAX]
1947 enum rtw_sar_bands sar_band;
1950 /* for 8821c set channel */
1954 struct rtw_path_div {
1955 enum rtw_bb_path current_tx_path;
1962 struct rtw_chan_info {
1971 struct rtw_chan_list {
1978 struct rtw_hw_scan_info {
1979 struct ieee80211_vif *scanning_vif;
1988 struct ieee80211_hw *hw;
1993 struct rtw_hw_scan_info scan_info;
1994 const struct rtw_chip_info *chip;
1996 struct rtw_fifo_conf fifo;
1997 struct rtw_fw_state fw;
1998 struct rtw_efuse efuse;
1999 struct rtw_sec_desc sec;
2000 struct rtw_traffic_stats stats;
2001 struct rtw_regd regd;
2002 struct rtw_bf_info bf_info;
2004 struct rtw_dm_info dm_info;
2005 struct rtw_coex coex;
2007 /* ensures exclusive access from mac80211 callbacks */
2010 /* watch dog every 2 sec */
2011 struct delayed_work watch_dog_work;
2014 struct list_head rsvd_page_list;
2016 /* c2h cmd queue & handler work */
2017 struct sk_buff_head c2h_queue;
2018 struct work_struct c2h_work;
2019 struct work_struct ips_work;
2020 struct work_struct fw_recovery_work;
2021 struct work_struct update_beacon_work;
2023 /* used to protect txqs list */
2024 spinlock_t txq_lock;
2025 struct list_head txqs;
2026 struct workqueue_struct *tx_wq;
2027 struct work_struct tx_work;
2028 struct work_struct ba_work;
2030 struct rtw_tx_report tx_report;
2033 /* incicate the mail box to use with fw */
2038 /* lps power state & handler work */
2039 struct rtw_lps_conf lps_conf;
2042 struct completion lps_leave_check;
2044 struct dentry *debugfs;
2049 DECLARE_BITMAP(hw_port, RTW_PORT_NUM);
2050 DECLARE_BITMAP(mac_id_map, RTW_MAX_MAC_ID_NUM);
2051 DECLARE_BITMAP(flags, NUM_OF_RTW_FLAGS);
2054 struct rtw_path_div dm_path_div;
2056 struct rtw_fw_state wow_fw;
2057 struct rtw_wow_param wow;
2060 struct completion fw_scan_density;
2063 /* hci related data, must be last */
2064 u8 priv[] __aligned(sizeof(void *));
2069 static inline bool rtw_is_assoc(struct rtw_dev *rtwdev)
2071 return !!rtwdev->sta_cnt;
2074 static inline struct ieee80211_txq *rtwtxq_to_txq(struct rtw_txq *rtwtxq)
2078 return container_of(p, struct ieee80211_txq, drv_priv);
2081 static inline struct ieee80211_vif *rtwvif_to_vif(struct rtw_vif *rtwvif)
2085 return container_of(p, struct ieee80211_vif, drv_priv);
2088 static inline bool rtw_ssid_equal(struct cfg80211_ssid *a,
2089 struct cfg80211_ssid *b)
2091 if (!a || !b || a->ssid_len != b->ssid_len)
2094 if (memcmp(a->ssid, b->ssid, a->ssid_len))
2100 static inline void rtw_chip_efuse_grant_on(struct rtw_dev *rtwdev)
2102 if (rtwdev->chip->ops->efuse_grant)
2103 rtwdev->chip->ops->efuse_grant(rtwdev, true);
2106 static inline void rtw_chip_efuse_grant_off(struct rtw_dev *rtwdev)
2108 if (rtwdev->chip->ops->efuse_grant)
2109 rtwdev->chip->ops->efuse_grant(rtwdev, false);
2112 static inline bool rtw_chip_wcpu_11n(struct rtw_dev *rtwdev)
2114 return rtwdev->chip->wlan_cpu == RTW_WCPU_11N;
2117 static inline bool rtw_chip_wcpu_11ac(struct rtw_dev *rtwdev)
2119 return rtwdev->chip->wlan_cpu == RTW_WCPU_11AC;
2122 static inline bool rtw_chip_has_rx_ldpc(struct rtw_dev *rtwdev)
2124 return rtwdev->chip->rx_ldpc;
2127 static inline bool rtw_chip_has_tx_stbc(struct rtw_dev *rtwdev)
2129 return rtwdev->chip->tx_stbc;
2132 static inline void rtw_release_macid(struct rtw_dev *rtwdev, u8 mac_id)
2134 clear_bit(mac_id, rtwdev->mac_id_map);
2137 static inline int rtw_chip_dump_fw_crash(struct rtw_dev *rtwdev)
2139 if (rtwdev->chip->ops->dump_fw_crash)
2140 return rtwdev->chip->ops->dump_fw_crash(rtwdev);
2146 enum nl80211_band rtw_hw_to_nl80211_band(enum rtw_supported_band hw_band)
2151 return NL80211_BAND_2GHZ;
2153 return NL80211_BAND_5GHZ;
2155 return NL80211_BAND_60GHZ;
2159 void rtw_set_rx_freq_band(struct rtw_rx_pkt_stat *pkt_stat, u8 channel);
2160 void rtw_set_dtim_period(struct rtw_dev *rtwdev, int dtim_period);
2161 void rtw_get_channel_params(struct cfg80211_chan_def *chandef,
2162 struct rtw_channel_params *ch_param);
2163 bool check_hw_ready(struct rtw_dev *rtwdev, u32 addr, u32 mask, u32 target);
2164 bool ltecoex_read_reg(struct rtw_dev *rtwdev, u16 offset, u32 *val);
2165 bool ltecoex_reg_write(struct rtw_dev *rtwdev, u16 offset, u32 value);
2166 void rtw_restore_reg(struct rtw_dev *rtwdev,
2167 struct rtw_backup_info *bckp, u32 num);
2168 void rtw_desc_to_mcsrate(u16 rate, u8 *mcs, u8 *nss);
2169 void rtw_set_channel(struct rtw_dev *rtwdev);
2170 void rtw_chip_prepare_tx(struct rtw_dev *rtwdev);
2171 void rtw_vif_port_config(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif,
2173 void rtw_tx_report_purge_timer(struct timer_list *t);
2174 void rtw_update_sta_info(struct rtw_dev *rtwdev, struct rtw_sta_info *si,
2175 bool reset_ra_mask);
2176 void rtw_core_scan_start(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif,
2177 const u8 *mac_addr, bool hw_scan);
2178 void rtw_core_scan_complete(struct rtw_dev *rtwdev, struct ieee80211_vif *vif,
2180 int rtw_core_start(struct rtw_dev *rtwdev);
2181 void rtw_core_stop(struct rtw_dev *rtwdev);
2182 int rtw_chip_info_setup(struct rtw_dev *rtwdev);
2183 int rtw_core_init(struct rtw_dev *rtwdev);
2184 void rtw_core_deinit(struct rtw_dev *rtwdev);
2185 int rtw_register_hw(struct rtw_dev *rtwdev, struct ieee80211_hw *hw);
2186 void rtw_unregister_hw(struct rtw_dev *rtwdev, struct ieee80211_hw *hw);
2187 u16 rtw_desc_to_bitrate(u8 desc_rate);
2188 void rtw_vif_assoc_changed(struct rtw_vif *rtwvif,
2189 struct ieee80211_bss_conf *conf);
2190 int rtw_sta_add(struct rtw_dev *rtwdev, struct ieee80211_sta *sta,
2191 struct ieee80211_vif *vif);
2192 void rtw_sta_remove(struct rtw_dev *rtwdev, struct ieee80211_sta *sta,
2194 void rtw_fw_recovery(struct rtw_dev *rtwdev);
2195 void rtw_core_fw_scan_notify(struct rtw_dev *rtwdev, bool start);
2196 int rtw_dump_fw(struct rtw_dev *rtwdev, const u32 ocp_src, u32 size,
2198 int rtw_dump_reg(struct rtw_dev *rtwdev, const u32 addr, const u32 size);
2199 void rtw_set_txrx_1ss(struct rtw_dev *rtwdev, bool config_1ss);
2200 void rtw_update_channel(struct rtw_dev *rtwdev, u8 center_channel,
2201 u8 primary_channel, enum rtw_supported_band band,
2202 enum rtw_bandwidth bandwidth);
2203 void rtw_core_port_switch(struct rtw_dev *rtwdev, struct ieee80211_vif *vif);
2204 bool rtw_core_check_sta_active(struct rtw_dev *rtwdev);
2205 void rtw_core_enable_beacon(struct rtw_dev *rtwdev, bool enable);