30 #ifndef __RTL_WIFI_H__
31 #define __RTL_WIFI_H__
33 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
35 #include <linux/sched.h>
44 #define RF_CHANGE_BY_INIT 0
45 #define RF_CHANGE_BY_IPS BIT(28)
46 #define RF_CHANGE_BY_PS BIT(29)
47 #define RF_CHANGE_BY_HW BIT(30)
48 #define RF_CHANGE_BY_SW BIT(31)
50 #define IQK_ADDA_REG_NUM 16
51 #define IQK_MAC_REG_NUM 4
53 #define MAX_KEY_LEN 61
54 #define KEY_BUF_SIZE 5
67 #define QOS_QUEUE_NUM 4
68 #define RTL_MAC80211_NUM_QUEUE 5
69 #define REALTEK_USB_VENQT_MAX_BUF_SIZE 254
70 #define RTL_USB_MAX_RX_COUNT 100
71 #define QBSS_LOAD_SIZE 5
72 #define MAX_WMMELE_LENGTH 64
74 #define TOTAL_CAM_ENTRY 32
77 #define RTL_SLOT_TIME_9 9
78 #define RTL_SLOT_TIME_20 20
82 #define ETH_P_PAE 0x888E
83 #define ETH_P_IP 0x0800
84 #define ETH_P_ARP 0x0806
86 #define PROTOC_TYPE_SIZE 2
89 #define MAC80211_3ADDR_LEN 24
90 #define MAC80211_4ADDR_LEN 30
92 #define CHANNEL_MAX_NUMBER (14 + 24 + 21)
93 #define CHANNEL_GROUP_MAX (3 + 9)
94 #define MAX_PG_GROUP 13
95 #define CHANNEL_GROUP_MAX_2G 3
96 #define CHANNEL_GROUP_IDX_5GL 3
97 #define CHANNEL_GROUP_IDX_5GM 6
98 #define CHANNEL_GROUP_IDX_5GH 9
99 #define CHANNEL_GROUP_MAX_5G 9
100 #define CHANNEL_MAX_NUMBER_2G 14
101 #define AVG_THERMAL_NUM 8
102 #define MAX_TID_COUNT 9
145 #define IS_HARDWARE_TYPE_8192SU(rtlhal) \
146 (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SU)
147 #define IS_HARDWARE_TYPE_8192SE(rtlhal) \
148 (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE)
149 #define IS_HARDWARE_TYPE_8192CE(rtlhal) \
150 (rtlhal->hw_type == HARDWARE_TYPE_RTL8192CE)
151 #define IS_HARDWARE_TYPE_8192CU(rtlhal) \
152 (rtlhal->hw_type == HARDWARE_TYPE_RTL8192CU)
153 #define IS_HARDWARE_TYPE_8192DE(rtlhal) \
154 (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DE)
155 #define IS_HARDWARE_TYPE_8192DU(rtlhal) \
156 (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DU)
157 #define IS_HARDWARE_TYPE_8723E(rtlhal) \
158 (rtlhal->hw_type == HARDWARE_TYPE_RTL8723E)
159 #define IS_HARDWARE_TYPE_8723U(rtlhal) \
160 (rtlhal->hw_type == HARDWARE_TYPE_RTL8723U)
161 #define IS_HARDWARE_TYPE_8192S(rtlhal) \
162 (IS_HARDWARE_TYPE_8192SE(rtlhal) || IS_HARDWARE_TYPE_8192SU(rtlhal))
163 #define IS_HARDWARE_TYPE_8192C(rtlhal) \
164 (IS_HARDWARE_TYPE_8192CE(rtlhal) || IS_HARDWARE_TYPE_8192CU(rtlhal))
165 #define IS_HARDWARE_TYPE_8192D(rtlhal) \
166 (IS_HARDWARE_TYPE_8192DE(rtlhal) || IS_HARDWARE_TYPE_8192DU(rtlhal))
167 #define IS_HARDWARE_TYPE_8723(rtlhal) \
168 (IS_HARDWARE_TYPE_8723E(rtlhal) || IS_HARDWARE_TYPE_8723U(rtlhal))
169 #define IS_HARDWARE_TYPE_8723U(rtlhal) \
170 (rtlhal->hw_type == HARDWARE_TYPE_RTL8723U)
172 #define RX_HAL_IS_CCK_RATE(_pdesc)\
173 (_pdesc->rxmcs == DESC92_RATE1M || \
174 _pdesc->rxmcs == DESC92_RATE2M || \
175 _pdesc->rxmcs == DESC92_RATE5_5M || \
176 _pdesc->rxmcs == DESC92_RATE11M)
620 #define IS_WIRELESS_MODE_A(wirelessmode) \
621 (wirelessmode == WIRELESS_MODE_A)
622 #define IS_WIRELESS_MODE_B(wirelessmode) \
623 (wirelessmode == WIRELESS_MODE_B)
624 #define IS_WIRELESS_MODE_G(wirelessmode) \
625 (wirelessmode == WIRELESS_MODE_G)
626 #define IS_WIRELESS_MODE_N_24G(wirelessmode) \
627 (wirelessmode == WIRELESS_MODE_N_24G)
628 #define IS_WIRELESS_MODE_N_5G(wirelessmode) \
629 (wirelessmode == WIRELESS_MODE_N_5G)
818 #define IQK_MATRIX_REG_NUM 8
819 #define IQK_MATRIX_SETTINGS_NUM (1 + 24 + 21)
908 #define MAX_TID_COUNT 9
909 #define RTL_AGG_STOP 0
910 #define RTL_AGG_PROGRESS 1
911 #define RTL_AGG_START 2
912 #define RTL_AGG_OPERATIONAL 3
913 #define RTL_AGG_OFF 0
915 #define RTL_RX_AGG_START 1
916 #define RTL_RX_AGG_STOP 0
917 #define RTL_AGG_EMPTYING_HW_QUEUE_ADDBA 2
918 #define RTL_AGG_EMPTYING_HW_QUEUE_DELBA 3
1173 #define EFUSE_MAX_LOGICAL_SIZE 256
1183 #ifdef EFUSE_REPG_WORKAROUND
1184 bool efuse_re_pg_sec1flag;
1185 u8 efuse_re_pg_data[8];
1424 u32 *p_inta,
u32 *p_intb);
1442 u32 add_msr,
u32 rm_msr);
1455 u32 buffer_len,
bool bIsPsPoll);
1457 bool firstseg,
bool lastseg,
1478 bool is_wepkey,
bool clear_all);
1489 bool allow_all_da,
bool write_into_reg);
1644 #define MIMO_PS_STATIC 0
1645 #define MIMO_PS_DYNAMIC 1
1646 #define MIMO_PS_NOLIMIT 3
1795 #define rtl_priv(hw) (((struct rtl_priv *)(hw)->priv))
1796 #define rtl_mac(rtlpriv) (&((rtlpriv)->mac80211))
1797 #define rtl_hal(rtlpriv) (&((rtlpriv)->rtlhal))
1798 #define rtl_efuse(rtlpriv) (&((rtlpriv)->efuse))
1799 #define rtl_psc(rtlpriv) (&((rtlpriv)->psc))
1894 #define EF1BYTE(_val) \
1896 #define EF2BYTE(_val) \
1898 #define EF4BYTE(_val) \
1902 #define READEF1BYTE(_ptr) \
1903 EF1BYTE(*((u8 *)(_ptr)))
1905 #define READEF2BYTE(_ptr) \
1907 #define READEF4BYTE(_ptr) \
1911 #define WRITEEF1BYTE(_ptr, _val) \
1912 (*((u8 *)(_ptr))) = EF1BYTE(_val)
1914 #define WRITEEF2BYTE(_ptr, _val) \
1915 (*((u16 *)(_ptr))) = EF2BYTE(_val)
1916 #define WRITEEF4BYTE(_ptr, _val) \
1917 (*((u32 *)(_ptr))) = EF2BYTE(_val)
1926 #define BIT_LEN_MASK_32(__bitlen) \
1927 (0xFFFFFFFF >> (32 - (__bitlen)))
1928 #define BIT_LEN_MASK_16(__bitlen) \
1929 (0xFFFF >> (16 - (__bitlen)))
1930 #define BIT_LEN_MASK_8(__bitlen) \
1931 (0xFF >> (8 - (__bitlen)))
1938 #define BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen) \
1939 (BIT_LEN_MASK_32(__bitlen) << (__bitoffset))
1940 #define BIT_OFFSET_LEN_MASK_16(__bitoffset, __bitlen) \
1941 (BIT_LEN_MASK_16(__bitlen) << (__bitoffset))
1942 #define BIT_OFFSET_LEN_MASK_8(__bitoffset, __bitlen) \
1943 (BIT_LEN_MASK_8(__bitlen) << (__bitoffset))
1949 #define LE_P4BYTE_TO_HOST_4BYTE(__pstart) \
1950 (EF4BYTE(*((__le32 *)(__pstart))))
1951 #define LE_P2BYTE_TO_HOST_2BYTE(__pstart) \
1952 (EF2BYTE(*((__le16 *)(__pstart))))
1953 #define LE_P1BYTE_TO_HOST_1BYTE(__pstart) \
1954 (EF1BYTE(*((u8 *)(__pstart))))
1959 #define LE_BITS_TO_4BYTE(__pstart, __bitoffset, __bitlen) \
1961 (LE_P4BYTE_TO_HOST_4BYTE(__pstart) >> (__bitoffset)) & \
1962 BIT_LEN_MASK_32(__bitlen) \
1964 #define LE_BITS_TO_2BYTE(__pstart, __bitoffset, __bitlen) \
1966 (LE_P2BYTE_TO_HOST_2BYTE(__pstart) >> (__bitoffset)) & \
1967 BIT_LEN_MASK_16(__bitlen) \
1969 #define LE_BITS_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
1971 (LE_P1BYTE_TO_HOST_1BYTE(__pstart) >> (__bitoffset)) & \
1972 BIT_LEN_MASK_8(__bitlen) \
1979 #define LE_BITS_CLEARED_TO_4BYTE(__pstart, __bitoffset, __bitlen) \
1981 LE_P4BYTE_TO_HOST_4BYTE(__pstart) & \
1982 (~BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen)) \
1984 #define LE_BITS_CLEARED_TO_2BYTE(__pstart, __bitoffset, __bitlen) \
1986 LE_P2BYTE_TO_HOST_2BYTE(__pstart) & \
1987 (~BIT_OFFSET_LEN_MASK_16(__bitoffset, __bitlen)) \
1989 #define LE_BITS_CLEARED_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
1991 LE_P1BYTE_TO_HOST_1BYTE(__pstart) & \
1992 (~BIT_OFFSET_LEN_MASK_8(__bitoffset, __bitlen)) \
1998 #define SET_BITS_TO_LE_4BYTE(__pstart, __bitoffset, __bitlen, __val) \
1999 *((u32 *)(__pstart)) = \
2001 LE_BITS_CLEARED_TO_4BYTE(__pstart, __bitoffset, __bitlen) | \
2002 ((((u32)__val) & BIT_LEN_MASK_32(__bitlen)) << (__bitoffset)) \
2004 #define SET_BITS_TO_LE_2BYTE(__pstart, __bitoffset, __bitlen, __val) \
2005 *((u16 *)(__pstart)) = \
2007 LE_BITS_CLEARED_TO_2BYTE(__pstart, __bitoffset, __bitlen) | \
2008 ((((u16)__val) & BIT_LEN_MASK_16(__bitlen)) << (__bitoffset)) \
2010 #define SET_BITS_TO_LE_1BYTE(__pstart, __bitoffset, __bitlen, __val) \
2011 *((u8 *)(__pstart)) = EF1BYTE \
2013 LE_BITS_CLEARED_TO_1BYTE(__pstart, __bitoffset, __bitlen) | \
2014 ((((u8)__val) & BIT_LEN_MASK_8(__bitlen)) << (__bitoffset)) \
2017 #define N_BYTE_ALIGMENT(__value, __aligment) ((__aligment == 1) ? \
2018 (__value) : (((__value + __aligment - 1) / __aligment) * __aligment))
2024 #define byte(x, n) ((x >> (8 * n)) & 0xff)
2026 #define packet_get_type(_packet) (EF1BYTE((_packet).octet[0]) & 0xFC)
2027 #define RTL_WATCH_DOG_TIME 2000
2028 #define MSECS(t) msecs_to_jiffies(t)
2029 #define WLAN_FC_GET_VERS(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_VERS)
2030 #define WLAN_FC_GET_TYPE(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_FTYPE)
2031 #define WLAN_FC_GET_STYPE(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_STYPE)
2032 #define WLAN_FC_MORE_DATA(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_MOREDATA)
2033 #define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
2034 #define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
2035 #define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
2037 #define RT_RF_OFF_LEVL_ASPM BIT(0)
2038 #define RT_RF_OFF_LEVL_CLK_REQ BIT(1)
2039 #define RT_RF_OFF_LEVL_PCI_D3 BIT(2)
2041 #define RT_RF_OFF_LEVL_HALT_NIC BIT(3)
2042 #define RT_RF_OFF_LEVL_FREE_FW BIT(4)
2043 #define RT_RF_OFF_LEVL_FW_32K BIT(5)
2045 #define RT_RF_PS_LEVEL_ALWAYS_ASPM BIT(6)
2047 #define RT_PS_LEVEL_ASPM BIT(7)
2049 #define RT_RF_LPS_DISALBE_2R BIT(30)
2050 #define RT_RF_LPS_LEVEL_ASPM BIT(31)
2051 #define RT_IN_PS_LEVEL(ppsc, _ps_flg) \
2052 ((ppsc->cur_ps_level & _ps_flg) ? true : false)
2053 #define RT_CLEAR_PS_LEVEL(ppsc, _ps_flg) \
2054 (ppsc->cur_ps_level &= (~(_ps_flg)))
2055 #define RT_SET_PS_LEVEL(ppsc, _ps_flg) \
2056 (ppsc->cur_ps_level |= _ps_flg)
2058 #define container_of_dwork_rtl(x, y, z) \
2059 container_of(container_of(x, struct delayed_work, work), y, z)
2061 #define FILL_OCTET_STRING(_os, _octet, _len) \
2062 (_os).octet = (u8 *)(_octet); \
2063 (_os).length = (_len);
2065 #define CP_MACADDR(des, src) \
2066 ((des)[0] = (src)[0], (des)[1] = (src)[1],\
2067 (des)[2] = (src)[2], (des)[3] = (src)[3],\
2068 (des)[4] = (src)[4], (des)[5] = (src)[5])
2072 return rtlpriv->
io.read8_sync(rtlpriv, addr);
2077 return rtlpriv->
io.read16_sync(rtlpriv, addr);
2080 static inline u32 rtl_read_dword(
struct rtl_priv *rtlpriv,
u32 addr)
2082 return rtlpriv->
io.read32_sync(rtlpriv, addr);
2085 static inline void rtl_write_byte(
struct rtl_priv *rtlpriv,
u32 addr,
u8 val8)
2087 rtlpriv->
io.write8_async(rtlpriv, addr, val8);
2089 if (rtlpriv->
cfg->write_readback)
2090 rtlpriv->
io.read8_sync(rtlpriv, addr);
2093 static inline void rtl_write_word(
struct rtl_priv *rtlpriv,
u32 addr,
u16 val16)
2095 rtlpriv->
io.write16_async(rtlpriv, addr, val16);
2097 if (rtlpriv->
cfg->write_readback)
2098 rtlpriv->
io.read16_sync(rtlpriv, addr);
2101 static inline void rtl_write_dword(
struct rtl_priv *rtlpriv,
2104 rtlpriv->
io.write32_async(rtlpriv, addr, val32);
2106 if (rtlpriv->
cfg->write_readback)
2107 rtlpriv->
io.read32_sync(rtlpriv, addr);
2115 return rtlpriv->
cfg->ops->get_bbreg(hw, regaddr, bitmask);
2118 static inline void rtl_set_bbreg(
struct ieee80211_hw *hw,
u32 regaddr,
2123 rtlpriv->
cfg->ops->set_bbreg(hw, regaddr, bitmask, data);
2132 return rtlpriv->
cfg->ops->get_rfreg(hw, rfpath, regaddr, bitmask);
2135 static inline void rtl_set_rfreg(
struct ieee80211_hw *hw,
2141 rtlpriv->
cfg->ops->set_rfreg(hw, rfpath, regaddr, bitmask, data);
2149 static inline void set_hal_start(
struct rtl_hal *rtlhal)
2154 static inline void set_hal_stop(
struct rtl_hal *rtlhal)
2159 static inline u8 get_rf_type(
struct rtl_phy *rtlphy)
2171 return rtl_get_hdr(skb)->frame_control;
2179 static inline u16 rtl_get_tid(
struct sk_buff *skb)
2181 return rtl_get_tid_h(rtl_get_hdr(skb));