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>
17 #define RTW_MAX_MAC_ID_NUM 32
18 #define RTW_MAX_SEC_CAM_NUM 32
20 #define RTW_WATCH_DOG_DELAY_TIME round_jiffies_relative(HZ * 2)
22 #define RFREG_MASK 0xfffff
23 #define INV_RF_DATA 0xffffffff
24 #define TX_PAGE_SIZE_SHIFT 7
26 #define RTW_CHANNEL_WIDTH_MAX 3
27 #define RTW_RF_PATH_MAX 4
28 #define HW_FEATURE_LEN 13
30 extern unsigned int rtw_debug_mask;
31 extern const struct ieee80211_ops rtw_ops;
32 extern struct rtw_chip_info rtw8822b_hw_spec;
33 extern struct rtw_chip_info rtw8822c_hw_spec;
35 #define RTW_MAX_CHANNEL_NUM_2G 14
36 #define RTW_MAX_CHANNEL_NUM_5G 49
45 RTW_HCI_TYPE_UNDEFINE,
49 struct rtw_hci_ops *ops;
50 enum rtw_hci_type type;
57 enum rtw_supported_band {
60 RTW_BAND_60G = 1 << 2,
65 /* now, support upto 80M bw */
66 #define RTW_MAX_CHANNEL_WIDTH RTW_CHANNEL_WIDTH_80
69 RTW_CHANNEL_WIDTH_20 = 0,
70 RTW_CHANNEL_WIDTH_40 = 1,
71 RTW_CHANNEL_WIDTH_80 = 2,
72 RTW_CHANNEL_WIDTH_160 = 3,
73 RTW_CHANNEL_WIDTH_80_80 = 4,
74 RTW_CHANNEL_WIDTH_5 = 5,
75 RTW_CHANNEL_WIDTH_10 = 6,
81 RTW_NET_MGD_LINKED = 2,
110 BB_PATH_AB = (BB_PATH_A | BB_PATH_B),
111 BB_PATH_AC = (BB_PATH_A | BB_PATH_C),
112 BB_PATH_AD = (BB_PATH_A | BB_PATH_D),
113 BB_PATH_BC = (BB_PATH_B | BB_PATH_C),
114 BB_PATH_BD = (BB_PATH_B | BB_PATH_D),
115 BB_PATH_CD = (BB_PATH_C | BB_PATH_D),
117 BB_PATH_ABC = (BB_PATH_A | BB_PATH_B | BB_PATH_C),
118 BB_PATH_ABD = (BB_PATH_A | BB_PATH_B | BB_PATH_D),
119 BB_PATH_ACD = (BB_PATH_A | BB_PATH_C | BB_PATH_D),
120 BB_PATH_BCD = (BB_PATH_B | BB_PATH_C | BB_PATH_D),
122 BB_PATH_ABCD = (BB_PATH_A | BB_PATH_B | BB_PATH_C | BB_PATH_D),
125 enum rtw_rate_section {
126 RTW_RATE_SECTION_CCK = 0,
127 RTW_RATE_SECTION_OFDM,
128 RTW_RATE_SECTION_HT_1S,
129 RTW_RATE_SECTION_HT_2S,
130 RTW_RATE_SECTION_VHT_1S,
131 RTW_RATE_SECTION_VHT_2S,
134 RTW_RATE_SECTION_MAX,
137 enum rtw_wireless_set {
138 WIRELESS_CCK = 0x00000001,
139 WIRELESS_OFDM = 0x00000002,
140 WIRELESS_HT = 0x00000004,
141 WIRELESS_VHT = 0x00000008,
144 #define HT_STBC_EN BIT(0)
145 #define VHT_STBC_EN BIT(1)
146 #define HT_LDPC_EN BIT(0)
147 #define VHT_LDPC_EN BIT(1)
154 enum rtw_tx_queue_type {
155 /* the order of AC queues matters */
156 RTW_TX_QUEUE_BK = 0x0,
157 RTW_TX_QUEUE_BE = 0x1,
158 RTW_TX_QUEUE_VI = 0x2,
159 RTW_TX_QUEUE_VO = 0x3,
161 RTW_TX_QUEUE_BCN = 0x4,
162 RTW_TX_QUEUE_MGMT = 0x5,
163 RTW_TX_QUEUE_HI0 = 0x6,
164 RTW_TX_QUEUE_H2C = 0x7,
169 enum rtw_rx_queue_type {
170 RTW_RX_QUEUE_MPDU = 0x0,
171 RTW_RX_QUEUE_C2H = 0x1,
176 enum rtw_rate_index {
177 RTW_RATEID_BGN_40M_2SS = 0,
178 RTW_RATEID_BGN_40M_1SS = 1,
179 RTW_RATEID_BGN_20M_2SS = 2,
180 RTW_RATEID_BGN_20M_1SS = 3,
181 RTW_RATEID_GN_N2SS = 4,
182 RTW_RATEID_GN_N1SS = 5,
185 RTW_RATEID_B_20M = 8,
186 RTW_RATEID_ARFR0_AC_2SS = 9,
187 RTW_RATEID_ARFR1_AC_1SS = 10,
188 RTW_RATEID_ARFR2_AC_2G_1SS = 11,
189 RTW_RATEID_ARFR3_AC_2G_2SS = 12,
190 RTW_RATEID_ARFR4_AC_3SS = 13,
191 RTW_RATEID_ARFR5_N_3SS = 14,
192 RTW_RATEID_ARFR7_N_4SS = 15,
193 RTW_RATEID_ARFR6_AC_4SS = 16
196 enum rtw_trx_desc_rate {
199 DESC_RATE5_5M = 0x02,
211 DESC_RATEMCS0 = 0x0c,
212 DESC_RATEMCS1 = 0x0d,
213 DESC_RATEMCS2 = 0x0e,
214 DESC_RATEMCS3 = 0x0f,
215 DESC_RATEMCS4 = 0x10,
216 DESC_RATEMCS5 = 0x11,
217 DESC_RATEMCS6 = 0x12,
218 DESC_RATEMCS7 = 0x13,
219 DESC_RATEMCS8 = 0x14,
220 DESC_RATEMCS9 = 0x15,
221 DESC_RATEMCS10 = 0x16,
222 DESC_RATEMCS11 = 0x17,
223 DESC_RATEMCS12 = 0x18,
224 DESC_RATEMCS13 = 0x19,
225 DESC_RATEMCS14 = 0x1a,
226 DESC_RATEMCS15 = 0x1b,
227 DESC_RATEMCS16 = 0x1c,
228 DESC_RATEMCS17 = 0x1d,
229 DESC_RATEMCS18 = 0x1e,
230 DESC_RATEMCS19 = 0x1f,
231 DESC_RATEMCS20 = 0x20,
232 DESC_RATEMCS21 = 0x21,
233 DESC_RATEMCS22 = 0x22,
234 DESC_RATEMCS23 = 0x23,
235 DESC_RATEMCS24 = 0x24,
236 DESC_RATEMCS25 = 0x25,
237 DESC_RATEMCS26 = 0x26,
238 DESC_RATEMCS27 = 0x27,
239 DESC_RATEMCS28 = 0x28,
240 DESC_RATEMCS29 = 0x29,
241 DESC_RATEMCS30 = 0x2a,
242 DESC_RATEMCS31 = 0x2b,
244 DESC_RATEVHT1SS_MCS0 = 0x2c,
245 DESC_RATEVHT1SS_MCS1 = 0x2d,
246 DESC_RATEVHT1SS_MCS2 = 0x2e,
247 DESC_RATEVHT1SS_MCS3 = 0x2f,
248 DESC_RATEVHT1SS_MCS4 = 0x30,
249 DESC_RATEVHT1SS_MCS5 = 0x31,
250 DESC_RATEVHT1SS_MCS6 = 0x32,
251 DESC_RATEVHT1SS_MCS7 = 0x33,
252 DESC_RATEVHT1SS_MCS8 = 0x34,
253 DESC_RATEVHT1SS_MCS9 = 0x35,
255 DESC_RATEVHT2SS_MCS0 = 0x36,
256 DESC_RATEVHT2SS_MCS1 = 0x37,
257 DESC_RATEVHT2SS_MCS2 = 0x38,
258 DESC_RATEVHT2SS_MCS3 = 0x39,
259 DESC_RATEVHT2SS_MCS4 = 0x3a,
260 DESC_RATEVHT2SS_MCS5 = 0x3b,
261 DESC_RATEVHT2SS_MCS6 = 0x3c,
262 DESC_RATEVHT2SS_MCS7 = 0x3d,
263 DESC_RATEVHT2SS_MCS8 = 0x3e,
264 DESC_RATEVHT2SS_MCS9 = 0x3f,
266 DESC_RATEVHT3SS_MCS0 = 0x40,
267 DESC_RATEVHT3SS_MCS1 = 0x41,
268 DESC_RATEVHT3SS_MCS2 = 0x42,
269 DESC_RATEVHT3SS_MCS3 = 0x43,
270 DESC_RATEVHT3SS_MCS4 = 0x44,
271 DESC_RATEVHT3SS_MCS5 = 0x45,
272 DESC_RATEVHT3SS_MCS6 = 0x46,
273 DESC_RATEVHT3SS_MCS7 = 0x47,
274 DESC_RATEVHT3SS_MCS8 = 0x48,
275 DESC_RATEVHT3SS_MCS9 = 0x49,
277 DESC_RATEVHT4SS_MCS0 = 0x4a,
278 DESC_RATEVHT4SS_MCS1 = 0x4b,
279 DESC_RATEVHT4SS_MCS2 = 0x4c,
280 DESC_RATEVHT4SS_MCS3 = 0x4d,
281 DESC_RATEVHT4SS_MCS4 = 0x4e,
282 DESC_RATEVHT4SS_MCS5 = 0x4f,
283 DESC_RATEVHT4SS_MCS6 = 0x50,
284 DESC_RATEVHT4SS_MCS7 = 0x51,
285 DESC_RATEVHT4SS_MCS8 = 0x52,
286 DESC_RATEVHT4SS_MCS9 = 0x53,
291 enum rtw_regulatory_domains {
299 RTW_REGD_UKRAINE = 7,
310 RTW_FLAG_INACTIVE_PS,
312 RTW_FLAG_DIG_DISABLE,
313 RTW_FLAG_BUSY_TRAFFIC,
318 /* the power index is represented by differences, which cck-1s & ht40-1s are
319 * the base values, so for 1s's differences, there are only ht20 & ofdm
321 struct rtw_2g_1s_pwr_idx_diff {
322 #ifdef __LITTLE_ENDIAN
331 struct rtw_2g_ns_pwr_idx_diff {
332 #ifdef __LITTLE_ENDIAN
345 struct rtw_2g_txpwr_idx {
348 struct rtw_2g_1s_pwr_idx_diff ht_1s_diff;
349 struct rtw_2g_ns_pwr_idx_diff ht_2s_diff;
350 struct rtw_2g_ns_pwr_idx_diff ht_3s_diff;
351 struct rtw_2g_ns_pwr_idx_diff ht_4s_diff;
354 struct rtw_5g_ht_1s_pwr_idx_diff {
355 #ifdef __LITTLE_ENDIAN
364 struct rtw_5g_ht_ns_pwr_idx_diff {
365 #ifdef __LITTLE_ENDIAN
374 struct rtw_5g_ofdm_ns_pwr_idx_diff {
375 #ifdef __LITTLE_ENDIAN
388 struct rtw_5g_vht_ns_pwr_idx_diff {
389 #ifdef __LITTLE_ENDIAN
398 struct rtw_5g_txpwr_idx {
400 struct rtw_5g_ht_1s_pwr_idx_diff ht_1s_diff;
401 struct rtw_5g_ht_ns_pwr_idx_diff ht_2s_diff;
402 struct rtw_5g_ht_ns_pwr_idx_diff ht_3s_diff;
403 struct rtw_5g_ht_ns_pwr_idx_diff ht_4s_diff;
404 struct rtw_5g_ofdm_ns_pwr_idx_diff ofdm_diff;
405 struct rtw_5g_vht_ns_pwr_idx_diff vht_1s_diff;
406 struct rtw_5g_vht_ns_pwr_idx_diff vht_2s_diff;
407 struct rtw_5g_vht_ns_pwr_idx_diff vht_3s_diff;
408 struct rtw_5g_vht_ns_pwr_idx_diff vht_4s_diff;
411 struct rtw_txpwr_idx {
412 struct rtw_2g_txpwr_idx pwr_idx_2g;
413 struct rtw_5g_txpwr_idx pwr_idx_5g;
416 struct rtw_timer_list {
417 struct timer_list timer;
418 void (*function)(void *data);
422 struct rtw_channel_params {
426 /* center channel by different available bandwidth,
427 * val of (bw > current bandwidth) is invalid
429 u8 cch_by_bw[RTW_MAX_CHANNEL_WIDTH + 1];
437 struct rtw_backup_info {
443 enum rtw_vif_port_set {
444 PORT_SET_MAC_ADDR = BIT(0),
445 PORT_SET_BSSID = BIT(1),
446 PORT_SET_NET_TYPE = BIT(2),
447 PORT_SET_AID = BIT(3),
448 PORT_SET_BCN_CTRL = BIT(4),
451 struct rtw_vif_port {
452 struct rtw_hw_reg mac_addr;
453 struct rtw_hw_reg bssid;
454 struct rtw_hw_reg net_type;
455 struct rtw_hw_reg aid;
456 struct rtw_hw_reg bcn_ctrl;
459 struct rtw_tx_pkt_info {
476 bool dis_rate_fallback;
485 struct rtw_rx_pkt_stat {
502 s8 rx_power[RTW_RF_PATH_MAX];
505 struct rtw_sta_info *si;
506 struct ieee80211_vif *vif;
509 struct rtw_traffic_stats {
514 /* count for packets */
535 struct rtw_lps_conf {
536 /* the interface to enter lps */
537 struct rtw_vif *rtwvif;
538 enum rtw_lps_mode mode;
539 enum rtw_pwr_state state;
546 enum rtw_hw_key_type {
554 struct rtw_cam_entry {
559 struct ieee80211_key_conf *key;
562 struct rtw_sec_desc {
563 /* search strategy */
564 bool default_key_search;
567 struct rtw_cam_entry cam_table[RTW_MAX_SEC_CAM_NUM];
568 DECLARE_BITMAP(cam_map, RTW_MAX_SEC_CAM_NUM);
571 struct rtw_tx_report {
572 /* protect the tx report queue */
574 struct sk_buff_head queue;
576 struct timer_list purge_timer;
579 #define RTW_BC_MC_MACID 1
580 DECLARE_EWMA(rssi, 10, 16);
582 struct rtw_sta_info {
583 struct ieee80211_sta *sta;
584 struct ieee80211_vif *vif;
586 struct ewma_rssi avg_rssi;
591 enum rtw_bandwidth bw_mode;
592 enum rtw_rf_type rf_type;
593 enum rtw_wireless_set wireless_set;
604 struct ieee80211_vif *vif;
605 enum rtw_net_type net_type;
607 u8 mac_addr[ETH_ALEN];
611 const struct rtw_vif_port *conf;
613 struct rtw_traffic_stats stats;
617 struct rtw_regulatory {
623 struct rtw_chip_ops {
624 int (*mac_init)(struct rtw_dev *rtwdev);
625 int (*read_efuse)(struct rtw_dev *rtwdev, u8 *map);
626 void (*phy_set_param)(struct rtw_dev *rtwdev);
627 void (*set_channel)(struct rtw_dev *rtwdev, u8 channel,
628 u8 bandwidth, u8 primary_chan_idx);
629 void (*query_rx_desc)(struct rtw_dev *rtwdev, u8 *rx_desc,
630 struct rtw_rx_pkt_stat *pkt_stat,
631 struct ieee80211_rx_status *rx_status);
632 u32 (*read_rf)(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
634 bool (*write_rf)(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
635 u32 addr, u32 mask, u32 data);
636 void (*set_tx_power_index)(struct rtw_dev *rtwdev);
637 int (*rsvd_page_dump)(struct rtw_dev *rtwdev, u8 *buf, u32 offset,
639 void (*set_antenna)(struct rtw_dev *rtwdev, u8 antenna_tx,
641 void (*cfg_ldo25)(struct rtw_dev *rtwdev, bool enable);
642 void (*false_alarm_statistics)(struct rtw_dev *rtwdev);
643 void (*phy_calibration)(struct rtw_dev *rtwdev);
644 void (*dpk_track)(struct rtw_dev *rtwdev);
645 void (*cck_pd_set)(struct rtw_dev *rtwdev, u8 level);
648 void (*coex_set_init)(struct rtw_dev *rtwdev);
649 void (*coex_set_ant_switch)(struct rtw_dev *rtwdev,
650 u8 ctrl_type, u8 pos_type);
651 void (*coex_set_gnt_fix)(struct rtw_dev *rtwdev);
652 void (*coex_set_gnt_debug)(struct rtw_dev *rtwdev);
653 void (*coex_set_rfe_type)(struct rtw_dev *rtwdev);
654 void (*coex_set_wl_tx_power)(struct rtw_dev *rtwdev, u8 wl_pwr);
655 void (*coex_set_wl_rx_gain)(struct rtw_dev *rtwdev, bool low_gain);
658 #define RTW_PWR_POLLING_CNT 20000
660 #define RTW_PWR_CMD_READ 0x00
661 #define RTW_PWR_CMD_WRITE 0x01
662 #define RTW_PWR_CMD_POLLING 0x02
663 #define RTW_PWR_CMD_DELAY 0x03
664 #define RTW_PWR_CMD_END 0x04
666 /* define the base address of each block */
667 #define RTW_PWR_ADDR_MAC 0x00
668 #define RTW_PWR_ADDR_USB 0x01
669 #define RTW_PWR_ADDR_PCIE 0x02
670 #define RTW_PWR_ADDR_SDIO 0x03
672 #define RTW_PWR_INTF_SDIO_MSK BIT(0)
673 #define RTW_PWR_INTF_USB_MSK BIT(1)
674 #define RTW_PWR_INTF_PCI_MSK BIT(2)
675 #define RTW_PWR_INTF_ALL_MSK (BIT(0) | BIT(1) | BIT(2) | BIT(3))
677 #define RTW_PWR_CUT_A_MSK BIT(1)
678 #define RTW_PWR_CUT_B_MSK BIT(2)
679 #define RTW_PWR_CUT_C_MSK BIT(3)
680 #define RTW_PWR_CUT_D_MSK BIT(4)
681 #define RTW_PWR_CUT_E_MSK BIT(5)
682 #define RTW_PWR_CUT_F_MSK BIT(6)
683 #define RTW_PWR_CUT_G_MSK BIT(7)
684 #define RTW_PWR_CUT_ALL_MSK 0xFF
686 enum rtw_pwr_seq_cmd_delay_unit {
691 struct rtw_pwr_seq_cmd {
702 RTW_CHIP_VER_CUT_A = 0x00,
703 RTW_CHIP_VER_CUT_B = 0x01,
704 RTW_CHIP_VER_CUT_C = 0x02,
705 RTW_CHIP_VER_CUT_D = 0x03,
706 RTW_CHIP_VER_CUT_E = 0x04,
707 RTW_CHIP_VER_CUT_F = 0x05,
708 RTW_CHIP_VER_CUT_G = 0x06,
711 #define RTW_INTF_PHY_PLATFORM_ALL 0
713 enum rtw_intf_phy_cut {
714 RTW_INTF_PHY_CUT_A = BIT(0),
715 RTW_INTF_PHY_CUT_B = BIT(1),
716 RTW_INTF_PHY_CUT_C = BIT(2),
717 RTW_INTF_PHY_CUT_D = BIT(3),
718 RTW_INTF_PHY_CUT_E = BIT(4),
719 RTW_INTF_PHY_CUT_F = BIT(5),
720 RTW_INTF_PHY_CUT_G = BIT(6),
721 RTW_INTF_PHY_CUT_ALL = 0xFFFF,
729 RTW_IP_SEL_UNDEF = 0xFFFF
739 RTW_PQ_MAP_NUM = 0x6,
744 enum rtw_dma_mapping {
745 RTW_DMA_MAPPING_EXTRA = 0,
746 RTW_DMA_MAPPING_LOW = 1,
747 RTW_DMA_MAPPING_NORMAL = 2,
748 RTW_DMA_MAPPING_HIGH = 3,
750 RTW_DMA_MAPPING_UNDEF,
754 enum rtw_dma_mapping dma_map_vo;
755 enum rtw_dma_mapping dma_map_vi;
756 enum rtw_dma_mapping dma_map_be;
757 enum rtw_dma_mapping dma_map_bk;
758 enum rtw_dma_mapping dma_map_mg;
759 enum rtw_dma_mapping dma_map_hi;
762 struct rtw_page_table {
770 struct rtw_intf_phy_para {
778 struct rtw_intf_phy_para_table {
779 struct rtw_intf_phy_para *usb2_para;
780 struct rtw_intf_phy_para *usb3_para;
781 struct rtw_intf_phy_para *gen1_para;
782 struct rtw_intf_phy_para *gen2_para;
792 void (*parse)(struct rtw_dev *rtwdev, const struct rtw_table *tbl);
793 void (*do_cfg)(struct rtw_dev *rtwdev, const struct rtw_table *tbl,
795 enum rtw_rf_path rf_path;
798 static inline void rtw_load_table(struct rtw_dev *rtwdev,
799 const struct rtw_table *tbl)
801 (*tbl->parse)(rtwdev, tbl);
807 RTW_RFE_IFEM2G_EFEM5G,
812 const struct rtw_table *phy_pg_tbl;
813 const struct rtw_table *txpwr_lmt_tbl;
816 #define RTW_DEF_RFE(chip, bb_pg, pwrlmt) { \
817 .phy_pg_tbl = &rtw ## chip ## _bb_pg_type ## bb_pg ## _tbl, \
818 .txpwr_lmt_tbl = &rtw ## chip ## _txpwr_lmt_type ## pwrlmt ## _tbl, \
821 /* hardware configuration for each IC */
822 struct rtw_chip_info {
823 struct rtw_chip_ops *ops;
842 bool is_pwr_by_rate_dec;
850 struct rtw_pwr_seq_cmd **pwr_on_seq;
851 struct rtw_pwr_seq_cmd **pwr_off_seq;
852 struct rtw_rqpn *rqpn_table;
853 struct rtw_page_table *page_table;
854 struct rtw_intf_phy_para_table *intf_table;
856 struct rtw_hw_reg *dig;
860 const struct rtw_table *mac_tbl;
861 const struct rtw_table *agc_tbl;
862 const struct rtw_table *bb_tbl;
863 const struct rtw_table *rf_tbl[RTW_RF_PATH_MAX];
864 const struct rtw_table *rfk_init_tbl;
866 const struct rtw_rfe_def *rfe_defs;
876 bool new_scbd10_def; /* true: fix 2M(8822c) */
877 u8 pstdma_type; /* 0: LPSoff, 1:LPSon */
889 const u8 *bt_rssi_step;
890 const u8 *wl_rssi_step;
891 const struct coex_table_para *table_nsant;
892 const struct coex_table_para *table_sant;
893 const struct coex_tdma_para *tdma_sant;
894 const struct coex_tdma_para *tdma_nsant;
895 const struct coex_rf_para *wl_rf_para_tx;
896 const struct coex_rf_para *wl_rf_para_rx;
897 const struct coex_5g_afh_map *afh_5g;
900 enum rtw_coex_bt_state_cnt {
903 COEX_CNT_BT_REENABLE,
904 COEX_CNT_BT_POPEVENT,
905 COEX_CNT_BT_SETUPLINK,
906 COEX_CNT_BT_IGNWLANACT,
909 COEX_CNT_BT_ROLESWITCH,
910 COEX_CNT_BT_AFHUPDATE,
911 COEX_CNT_BT_INFOUPDATE,
918 enum rtw_coex_wl_state_cnt {
924 COEX_CNT_WL_5MS_NOEXTEND,
925 COEX_CNT_WL_FW_NOTIFY,
930 struct rtw_coex_rfe {
931 bool ant_switch_exist;
932 bool ant_switch_diversity;
933 bool ant_switch_with_bt;
935 u8 ant_switch_polarity;
937 /* true if WLG at BTG, else at WLAG */
943 bool cur_wl_rx_low_gain_en;
956 u32 cur_ant_pos_type;
957 u32 cur_switch_status;
961 #define COEX_BTINFO_SRC_WL_FW 0x0
962 #define COEX_BTINFO_SRC_BT_RSP 0x1
963 #define COEX_BTINFO_SRC_BT_ACT 0x2
964 #define COEX_BTINFO_SRC_BT_IQK 0x3
965 #define COEX_BTINFO_SRC_BT_SCBD 0x4
966 #define COEX_BTINFO_SRC_MAX 0x5
968 #define COEX_INFO_FTP BIT(7)
969 #define COEX_INFO_A2DP BIT(6)
970 #define COEX_INFO_HID BIT(5)
971 #define COEX_INFO_SCO_BUSY BIT(4)
972 #define COEX_INFO_ACL_BUSY BIT(3)
973 #define COEX_INFO_INQ_PAGE BIT(2)
974 #define COEX_INFO_SCO_ESCO BIT(1)
975 #define COEX_INFO_CONNECTION BIT(0)
976 #define COEX_BTINFO_LENGTH_MAX 10
978 struct rtw_coex_stat {
980 bool bt_disabled_pre;
991 bool bt_pan_exist; /* PAN or OPP */
992 bool bt_opp_exist; /* OPP only */
1000 bool bt_ble_scan_en;
1003 bool bt_418_hid_exist;
1004 bool bt_mailbox_reply;
1008 bool wl_hi_pri_task1;
1009 bool wl_hi_pri_task2;
1010 bool wl_force_lps_ctrl;
1012 bool wl_linkscan_proc;
1013 bool wl_ps_state_fail;
1014 bool wl_tx_limit_en;
1015 bool wl_ampdu_limit_en;
1017 bool wl_slot_extend;
1019 bool wl_cck_lock_pre;
1020 bool wl_cck_lock_ever;
1022 u32 bt_supported_version;
1023 u32 bt_supported_feature;
1026 u8 gnt_workaround_state;
1029 u8 bt_info_c2h[COEX_BTINFO_SRC_MAX][COEX_BTINFO_LENGTH_MAX];
1036 u8 bt_ble_scan_type;
1043 u8 wl_fw_dbg_info[10];
1044 u8 wl_fw_dbg_info_pre[10];
1052 /* counters to record bt states */
1053 u32 cnt_bt[COEX_CNT_BT_MAX];
1055 /* counters to record wifi states */
1056 u32 cnt_wl[COEX_CNT_WL_MAX];
1063 /* protects coex info request section */
1065 struct sk_buff_head queue;
1066 wait_queue_head_t wait;
1074 struct rtw_coex_stat stat;
1075 struct rtw_coex_dm dm;
1076 struct rtw_coex_rfe rfe;
1078 struct delayed_work bt_relink_work;
1079 struct delayed_work bt_reenable_work;
1080 struct delayed_work defreeze_work;
1083 #define DPK_RF_REG_NUM 7
1084 #define DPK_RF_PATH_NUM 2
1085 #define DPK_BB_REG_NUM 18
1086 #define DPK_CHANNEL_WIDTH_80 1
1088 DECLARE_EWMA(thermal, 10, 4);
1090 struct rtw_dpk_info {
1094 DECLARE_BITMAP(dpk_path_ok, DPK_RF_PATH_NUM);
1096 u8 thermal_dpk[DPK_RF_PATH_NUM];
1097 struct ewma_thermal avg_thermal[DPK_RF_PATH_NUM];
1102 u8 result[RTW_RF_PATH_MAX];
1103 u8 dpk_txagc[RTW_RF_PATH_MAX];
1104 u32 coef[RTW_RF_PATH_MAX][20];
1105 u16 dpk_gs[RTW_RF_PATH_MAX];
1106 u8 thermal_dpk_delta[RTW_RF_PATH_MAX];
1107 u8 pre_pwsf[RTW_RF_PATH_MAX];
1114 struct rtw_phy_cck_pd_reg {
1121 #define DACK_MSBK_BACKUP_NUM 0xf
1122 #define DACK_DCK_BACKUP_NUM 0x2
1124 struct rtw_dm_info {
1150 /* backup dack results for each path and I/Q */
1151 u32 dack_adck[RTW_RF_PATH_MAX];
1152 u16 dack_msbk[RTW_RF_PATH_MAX][2][DACK_MSBK_BACKUP_NUM];
1153 u8 dack_dck[RTW_RF_PATH_MAX][2][DACK_DCK_BACKUP_NUM];
1155 struct rtw_dpk_info dpk_info;
1157 /* [bandwidth 0:20M/1:40M][number of path] */
1158 u8 cck_pd_lv[2][RTW_RF_PATH_MAX];
1193 /* bt share antenna with wifi */
1205 struct rtw_txpwr_idx txpwr_idx_table[4];
1208 struct rtw_phy_cond {
1209 #ifdef __LITTLE_ENDIAN
1231 #define INTF_PCIE BIT(0)
1232 #define INTF_USB BIT(1)
1233 #define INTF_SDIO BIT(2)
1236 #define BRANCH_ELIF 1
1237 #define BRANCH_ELSE 2
1238 #define BRANCH_ENDIF 3
1241 struct rtw_fifo_conf {
1242 /* tx fifo information */
1245 u16 rsvd_drv_pg_num;
1249 u16 rsvd_h2c_info_addr;
1250 u16 rsvd_h2c_sta_info_addr;
1252 u16 rsvd_cpu_instr_addr;
1253 u16 rsvd_fw_txbuf_addr;
1254 u16 rsvd_csibuf_addr;
1255 enum rtw_dma_mapping pq_map[RTW_PQ_MAP_NUM];
1258 struct rtw_fw_state {
1259 const struct firmware *firmware;
1260 struct completion completion;
1275 struct rtw_phy_cond phy_cond;
1279 u8 current_band_width;
1280 u8 current_band_type;
1282 /* center channel for different available bandwidth,
1283 * val of (bw > current_band_width) is invalid
1285 u8 cch_by_bw[RTW_MAX_CHANNEL_WIDTH + 1];
1293 /* protect tx power section */
1294 struct mutex tx_power_mutex;
1295 s8 tx_pwr_by_rate_offset_2g[RTW_RF_PATH_MAX]
1297 s8 tx_pwr_by_rate_offset_5g[RTW_RF_PATH_MAX]
1299 s8 tx_pwr_by_rate_base_2g[RTW_RF_PATH_MAX]
1300 [RTW_RATE_SECTION_MAX];
1301 s8 tx_pwr_by_rate_base_5g[RTW_RF_PATH_MAX]
1302 [RTW_RATE_SECTION_MAX];
1303 s8 tx_pwr_limit_2g[RTW_REGD_MAX]
1304 [RTW_CHANNEL_WIDTH_MAX]
1305 [RTW_RATE_SECTION_MAX]
1306 [RTW_MAX_CHANNEL_NUM_2G];
1307 s8 tx_pwr_limit_5g[RTW_REGD_MAX]
1308 [RTW_CHANNEL_WIDTH_MAX]
1309 [RTW_RATE_SECTION_MAX]
1310 [RTW_MAX_CHANNEL_NUM_5G];
1311 s8 tx_pwr_tbl[RTW_RF_PATH_MAX]
1316 struct ieee80211_hw *hw;
1321 struct rtw_chip_info *chip;
1323 struct rtw_fifo_conf fifo;
1324 struct rtw_fw_state fw;
1325 struct rtw_efuse efuse;
1326 struct rtw_sec_desc sec;
1327 struct rtw_traffic_stats stats;
1328 struct rtw_regulatory regd;
1330 struct rtw_dm_info dm_info;
1331 struct rtw_coex coex;
1333 /* ensures exclusive access from mac80211 callbacks */
1336 /* lock for dm to use */
1339 /* read/write rf register */
1342 /* watch dog every 2 sec */
1343 struct delayed_work watch_dog_work;
1346 struct list_head rsvd_page_list;
1348 /* c2h cmd queue & handler work */
1349 struct sk_buff_head c2h_queue;
1350 struct work_struct c2h_work;
1352 struct rtw_tx_report tx_report;
1355 /* incicate the mail box to use with fw */
1357 /* protect to send h2c to fw */
1362 /* lps power state & handler work */
1363 struct rtw_lps_conf lps_conf;
1364 struct delayed_work lps_work;
1366 struct dentry *debugfs;
1370 DECLARE_BITMAP(mac_id_map, RTW_MAX_MAC_ID_NUM);
1371 DECLARE_BITMAP(flags, NUM_OF_RTW_FLAGS);
1375 /* hci related data, must be last */
1376 u8 priv[0] __aligned(sizeof(void *));
1381 static inline bool rtw_flag_check(struct rtw_dev *rtwdev, enum rtw_flags flag)
1383 return test_bit(flag, rtwdev->flags);
1386 static inline void rtw_flag_clear(struct rtw_dev *rtwdev, enum rtw_flags flag)
1388 clear_bit(flag, rtwdev->flags);
1391 static inline void rtw_flag_set(struct rtw_dev *rtwdev, enum rtw_flags flag)
1393 set_bit(flag, rtwdev->flags);
1396 static inline bool rtw_is_assoc(struct rtw_dev *rtwdev)
1398 return !!rtwdev->sta_cnt;
1401 void rtw_get_channel_params(struct cfg80211_chan_def *chandef,
1402 struct rtw_channel_params *ch_param);
1403 bool check_hw_ready(struct rtw_dev *rtwdev, u32 addr, u32 mask, u32 target);
1404 bool ltecoex_read_reg(struct rtw_dev *rtwdev, u16 offset, u32 *val);
1405 bool ltecoex_reg_write(struct rtw_dev *rtwdev, u16 offset, u32 value);
1406 void rtw_restore_reg(struct rtw_dev *rtwdev,
1407 struct rtw_backup_info *bckp, u32 num);
1408 void rtw_set_channel(struct rtw_dev *rtwdev);
1409 void rtw_vif_port_config(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif,
1411 void rtw_tx_report_purge_timer(struct timer_list *t);
1412 void rtw_update_sta_info(struct rtw_dev *rtwdev, struct rtw_sta_info *si);
1413 int rtw_core_start(struct rtw_dev *rtwdev);
1414 void rtw_core_stop(struct rtw_dev *rtwdev);
1415 int rtw_chip_info_setup(struct rtw_dev *rtwdev);
1416 int rtw_core_init(struct rtw_dev *rtwdev);
1417 void rtw_core_deinit(struct rtw_dev *rtwdev);
1418 int rtw_register_hw(struct rtw_dev *rtwdev, struct ieee80211_hw *hw);
1419 void rtw_unregister_hw(struct rtw_dev *rtwdev, struct ieee80211_hw *hw);