1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright(c) 2009-2010  Realtek Corporation.*/
3 
4 #ifndef __RTL8821AE__FW__H__
5 #define __RTL8821AE__FW__H__
6 #include "def.h"
7 
8 #define FW_8821AE_SIZE					0x8000
9 #define FW_8821AE_START_ADDRESS			0x1000
10 #define FW_8821AE_END_ADDRESS			0x5FFF
11 #define FW_8821AE_PAGE_SIZE				4096
12 #define FW_8821AE_POLLING_DELAY			5
13 #define FW_8821AE_POLLING_TIMEOUT_COUNT	6000
14 
15 #define IS_FW_HEADER_EXIST_8812(_pfwhdr)	\
16 	((le16_to_cpu(_pfwhdr->signature) & 0xFFF0) == 0x9500)
17 
18 #define IS_FW_HEADER_EXIST_8821(_pfwhdr)	\
19 	((le16_to_cpu(_pfwhdr->signature) & 0xFFF0) == 0x2100)
20 
21 #define USE_OLD_WOWLAN_DEBUG_FW 0
22 
23 #define H2C_8821AE_RSVDPAGE_LOC_LEN		5
24 #define H2C_8821AE_PWEMODE_LENGTH			7
25 #define H2C_8821AE_JOINBSSRPT_LENGTH		1
26 #define H2C_8821AE_AP_OFFLOAD_LENGTH		3
27 #define H2C_8821AE_WOWLAN_LENGTH			3
28 #define H2C_8821AE_KEEP_ALIVE_CTRL_LENGTH	3
29 #if (USE_OLD_WOWLAN_DEBUG_FW == 0)
30 #define H2C_8821AE_REMOTE_WAKE_CTRL_LEN	1
31 #else
32 #define H2C_8821AE_REMOTE_WAKE_CTRL_LEN	3
33 #endif
34 #define H2C_8821AE_AOAC_GLOBAL_INFO_LEN	2
35 #define H2C_8821AE_AOAC_RSVDPAGE_LOC_LEN	7
36 #define H2C_8821AE_DISCONNECT_DECISION_CTRL_LEN	3
37 
38 /* Fw PS state for RPWM.
39 *BIT[2:0] = HW state
40 
41 *BIT[3] = Protocol PS state,
42 1: register active state ,
43 0: register sleep state
44 
45 *BIT[4] = sub-state
46 */
47 #define	FW_PS_GO_ON			BIT(0)
48 #define	FW_PS_TX_NULL			BIT(1)
49 #define	FW_PS_RF_ON			BIT(2)
50 #define	FW_PS_REGISTER_ACTIVE	BIT(3)
51 
52 #define	FW_PS_DPS		BIT(0)
53 #define	FW_PS_LCLK		(FW_PS_DPS)
54 #define	FW_PS_RF_OFF		BIT(1)
55 #define	FW_PS_ALL_ON		BIT(2)
56 #define	FW_PS_ST_ACTIVE		BIT(3)
57 #define	FW_PS_ISR_ENABLE	BIT(4)
58 #define	FW_PS_IMR_ENABLE	BIT(5)
59 
60 #define	FW_PS_ACK		BIT(6)
61 #define	FW_PS_TOGGLE		BIT(7)
62 
63  /* 8821AE RPWM value*/
64  /* BIT[0] = 1: 32k, 0: 40M*/
65  /* 32k*/
66 #define	FW_PS_CLOCK_OFF		BIT(0)
67 /*40M*/
68 #define	FW_PS_CLOCK_ON		0
69 
70 #define	FW_PS_STATE_MASK		(0x0F)
71 #define	FW_PS_STATE_HW_MASK	(0x07)
72 /*ISR_ENABLE, IMR_ENABLE, and PS mode should be inherited.*/
73 #define	FW_PS_STATE_INT_MASK	(0x3F)
74 
75 #define	FW_PS_STATE(x)			(FW_PS_STATE_MASK & (x))
76 #define	FW_PS_STATE_HW(x)		(FW_PS_STATE_HW_MASK & (x))
77 #define	FW_PS_STATE_INT(x)	(FW_PS_STATE_INT_MASK & (x))
78 #define	FW_PS_ISR_VAL(x)		((x) & 0x70)
79 #define	FW_PS_IMR_MASK(x)	((x) & 0xDF)
80 #define	FW_PS_KEEP_IMR(x)		((x) & 0x20)
81 
82 #define	FW_PS_STATE_S0		(FW_PS_DPS)
83 #define	FW_PS_STATE_S1		(FW_PS_LCLK)
84 #define	FW_PS_STATE_S2		(FW_PS_RF_OFF)
85 #define	FW_PS_STATE_S3		(FW_PS_ALL_ON)
86 #define	FW_PS_STATE_S4		((FW_PS_ST_ACTIVE) | (FW_PS_ALL_ON))
87  /* ((FW_PS_RF_ON) | (FW_PS_REGISTER_ACTIVE))*/
88 #define	FW_PS_STATE_ALL_ON_8821AE	(FW_PS_CLOCK_ON)
89  /* (FW_PS_RF_ON)*/
90 #define	FW_PS_STATE_RF_ON_8821AE	(FW_PS_CLOCK_ON)
91  /* 0x0*/
92 #define	FW_PS_STATE_RF_OFF_8821AE	(FW_PS_CLOCK_ON)
93  /* (FW_PS_STATE_RF_OFF)*/
94 #define	FW_PS_STATE_RF_OFF_LOW_PWR_8821AE	(FW_PS_CLOCK_OFF)
95 
96 #define	FW_PS_STATE_ALL_ON_92C	(FW_PS_STATE_S4)
97 #define	FW_PS_STATE_RF_ON_92C		(FW_PS_STATE_S3)
98 #define	FW_PS_STATE_RF_OFF_92C	(FW_PS_STATE_S2)
99 #define	FW_PS_STATE_RF_OFF_LOW_PWR_92C	(FW_PS_STATE_S1)
100 
101 /* For 8821AE H2C PwrMode Cmd ID 5.*/
102 #define	FW_PWR_STATE_ACTIVE	((FW_PS_RF_ON) | (FW_PS_REGISTER_ACTIVE))
103 #define	FW_PWR_STATE_RF_OFF	0
104 
105 #define	FW_PS_IS_ACK(x)		((x) & FW_PS_ACK)
106 #define	FW_PS_IS_CLK_ON(x)	((x) & (FW_PS_RF_OFF | FW_PS_ALL_ON))
107 #define	FW_PS_IS_RF_ON(x)	((x) & (FW_PS_ALL_ON))
108 #define	FW_PS_IS_ACTIVE(x)	((x) & (FW_PS_ST_ACTIVE))
109 #define	FW_PS_IS_CPWM_INT(x)	((x) & 0x40)
110 
111 #define	FW_CLR_PS_STATE(x)	((x) = ((x) & (0xF0)))
112 
113 #define	IS_IN_LOW_POWER_STATE_8821AE(__state)		\
114 			(FW_PS_STATE(__state) == FW_PS_CLOCK_OFF)
115 
116 #define	FW_PWR_STATE_ACTIVE	((FW_PS_RF_ON) | (FW_PS_REGISTER_ACTIVE))
117 #define	FW_PWR_STATE_RF_OFF	0
118 
119 enum rtl8821a_h2c_cmd {
120 	H2C_8821AE_RSVDPAGE = 0,
121 	H2C_8821AE_MSRRPT = 1,
122 	H2C_8821AE_SCAN = 2,
123 	H2C_8821AE_KEEP_ALIVE_CTRL = 3,
124 	H2C_8821AE_DISCONNECT_DECISION = 4,
125 	H2C_8821AE_INIT_OFFLOAD = 6,
126 	H2C_8821AE_AP_OFFLOAD = 8,
127 	H2C_8821AE_BCN_RSVDPAGE = 9,
128 	H2C_8821AE_PROBERSP_RSVDPAGE = 10,
129 
130 	H2C_8821AE_SETPWRMODE = 0x20,
131 	H2C_8821AE_PS_TUNING_PARA = 0x21,
132 	H2C_8821AE_PS_TUNING_PARA2 = 0x22,
133 	H2C_8821AE_PS_LPS_PARA = 0x23,
134 	H2C_8821AE_P2P_PS_OFFLOAD = 024,
135 
136 	H2C_8821AE_WO_WLAN = 0x80,
137 	H2C_8821AE_REMOTE_WAKE_CTRL = 0x81,
138 	H2C_8821AE_AOAC_GLOBAL_INFO = 0x82,
139 	H2C_8821AE_AOAC_RSVDPAGE = 0x83,
140 
141 	H2C_RSSI_21AE_REPORT = 0x42,
142 	H2C_8821AE_RA_MASK = 0x40,
143 	H2C_8821AE_SELECTIVE_SUSPEND_ROF_CMD,
144 	H2C_8821AE_P2P_PS_MODE,
145 	H2C_8821AE_PSD_RESULT,
146 	/*Not defined CTW CMD for P2P yet*/
147 	H2C_8821AE_P2P_PS_CTW_CMD,
148 	MAX_8821AE_H2CCMD
149 };
150 
151 #define pagenum_128(_len)	(u32)(((_len)>>7) + ((_len)&0x7F ? 1 : 0))
152 
153 #define SET_8812_H2CCMD_WOWLAN_FUNC_ENABLE(__cmd, __value)		\
154 	SET_BITS_TO_LE_1BYTE(__cmd, 0, 1, __value)
155 #define SET_8812_H2CCMD_WOWLAN_PATTERN_MATCH_ENABLE(__cmd, __value)	\
156 	SET_BITS_TO_LE_1BYTE(__cmd, 1, 1, __value)
157 #define SET_8812_H2CCMD_WOWLAN_MAGIC_PKT_ENABLE(__cmd, __value)	\
158 	SET_BITS_TO_LE_1BYTE(__cmd, 2, 1, __value)
159 #define SET_8812_H2CCMD_WOWLAN_UNICAST_PKT_ENABLE(__cmd, __value)	\
160 	SET_BITS_TO_LE_1BYTE(__cmd, 3, 1, __value)
161 #define SET_8812_H2CCMD_WOWLAN_ALL_PKT_DROP(__cmd, __value)		\
162 	SET_BITS_TO_LE_1BYTE(__cmd, 4, 1, __value)
163 #define SET_8812_H2CCMD_WOWLAN_GPIO_ACTIVE(__cmd, __value)		\
164 	SET_BITS_TO_LE_1BYTE(__cmd, 5, 1, __value)
165 #define SET_8812_H2CCMD_WOWLAN_REKEY_WAKE_UP(__cmd, __value)	\
166 	SET_BITS_TO_LE_1BYTE(__cmd, 6, 1, __value)
167 #define SET_8812_H2CCMD_WOWLAN_DISCONNECT_WAKE_UP(__cmd, __value)	\
168 	SET_BITS_TO_LE_1BYTE(__cmd, 7, 1, __value)
169 #define SET_8812_H2CCMD_WOWLAN_GPIONUM(__cmd, __value)		\
170 	SET_BITS_TO_LE_1BYTE((__cmd) + 1, 0, 8, __value)
171 #define SET_8812_H2CCMD_WOWLAN_GPIO_DURATION(__cmd, __value)	\
172 	SET_BITS_TO_LE_1BYTE((__cmd) + 2, 0, 8, __value)
173 
174 #define SET_H2CCMD_PWRMODE_PARM_MODE(__ph2ccmd, __val)			\
175 	SET_BITS_TO_LE_1BYTE(__ph2ccmd, 0, 8, __val)
176 #define SET_H2CCMD_PWRMODE_PARM_RLBM(__cmd, __value)		\
177 	SET_BITS_TO_LE_1BYTE((__cmd)+1, 0, 4, __value)
178 #define SET_H2CCMD_PWRMODE_PARM_SMART_PS(__cmd, __value)	\
179 	SET_BITS_TO_LE_1BYTE((__cmd)+1, 4, 4, __value)
180 #define SET_H2CCMD_PWRMODE_PARM_AWAKE_INTERVAL(__cmd, __value)	\
181 	SET_BITS_TO_LE_1BYTE((__cmd)+2, 0, 8, __value)
182 #define SET_H2CCMD_PWRMODE_PARM_ALL_QUEUE_UAPSD(__cmd, __value)		\
183 	SET_BITS_TO_LE_1BYTE((__cmd)+3, 0, 8, __value)
184 #define SET_H2CCMD_PWRMODE_PARM_PWR_STATE(__cmd, __value)	\
185 	SET_BITS_TO_LE_1BYTE((__cmd)+4, 0, 8, __value)
186 #define SET_H2CCMD_PWRMODE_PARM_BYTE5(__cmd, __value)		\
187 	SET_BITS_TO_LE_1BYTE((__cmd) + 5, 0, 8, __value)
188 #define GET_8821AE_H2CCMD_PWRMODE_PARM_MODE(__cmd)		\
189 	LE_BITS_TO_1BYTE(__cmd, 0, 8)
190 
191 #define SET_H2CCMD_JOINBSSRPT_PARM_OPMODE(__ph2ccmd, __val)		\
192 	SET_BITS_TO_LE_1BYTE(__ph2ccmd, 0, 8, __val)
193 #define SET_H2CCMD_RSVDPAGE_LOC_PSPOLL(__ph2ccmd, __val)		\
194 	SET_BITS_TO_LE_1BYTE((__ph2ccmd)+1, 0, 8, __val)
195 #define SET_H2CCMD_RSVDPAGE_LOC_NULL_DATA(__ph2ccmd, __val)		\
196 	SET_BITS_TO_LE_1BYTE((__ph2ccmd)+2, 0, 8, __val)
197 #define SET_H2CCMD_RSVDPAGE_LOC_QOS_NULL_DATA(__ph2ccmd, __val)		\
198 	SET_BITS_TO_LE_1BYTE((__ph2ccmd)+3, 0, 8, __val)
199 #define SET_H2CCMD_RSVDPAGE_LOC_BT_QOS_NULL_DATA(__ph2ccmd, __val)	\
200 	SET_BITS_TO_LE_1BYTE((__ph2ccmd) + 4, 0, 8, __val)
201 
202 /* _MEDIA_STATUS_RPT_PARM_CMD1 */
203 #define SET_H2CCMD_MSRRPT_PARM_OPMODE(__cmd, __value)	\
204 	SET_BITS_TO_LE_1BYTE(__cmd, 0, 1, __value)
205 #define SET_H2CCMD_MSRRPT_PARM_MACID_IND(__cmd, __value)	\
206 	SET_BITS_TO_LE_1BYTE(__cmd, 1, 1, __value)
207 #define SET_H2CCMD_MSRRPT_PARM_MACID(__cmd, __value)	\
208 	SET_BITS_TO_LE_1BYTE(__cmd+1, 0, 8, __value)
209 #define SET_H2CCMD_MSRRPT_PARM_MACID_END(__cmd, __value)	\
210 	SET_BITS_TO_LE_1BYTE(__cmd+2, 0, 8, __value)
211 
212 /* AP_OFFLOAD */
213 #define SET_H2CCMD_AP_OFFLOAD_ON(__cmd, __value)	\
214 	SET_BITS_TO_LE_1BYTE(__cmd, 0, 8, __value)
215 #define SET_H2CCMD_AP_OFFLOAD_HIDDEN(__cmd, __value)	\
216 	SET_BITS_TO_LE_1BYTE((__cmd)+1, 0, 8, __value)
217 #define SET_H2CCMD_AP_OFFLOAD_DENYANY(__cmd, __value)	\
218 	SET_BITS_TO_LE_1BYTE((__cmd)+2, 0, 8, __value)
219 #define SET_H2CCMD_AP_OFFLOAD_WAKEUP_EVT_RPT(__cmd, __value) \
220 	SET_BITS_TO_LE_1BYTE((__cmd)+3, 0, 8, __value)
221 
222 /* Keep Alive Control*/
223 #define SET_8812_H2CCMD_KEEP_ALIVE_ENABLE(__cmd, __value)	\
224 	SET_BITS_TO_LE_1BYTE(__cmd, 0, 1, __value)
225 #define SET_8812_H2CCMD_KEEP_ALIVE_ACCPEPT_USER_DEFINED(__cmd, __value)	\
226 	SET_BITS_TO_LE_1BYTE(__cmd, 1, 1, __value)
227 #define SET_8812_H2CCMD_KEEP_ALIVE_PERIOD(__cmd, __value)	\
228 	SET_BITS_TO_LE_1BYTE((__cmd)+1, 0, 8, __value)
229 
230 /*REMOTE_WAKE_CTRL */
231 #define SET_8812_H2CCMD_REMOTE_WAKECTRL_ENABLE(__cmd, __value)	\
232 	SET_BITS_TO_LE_1BYTE(__cmd, 0, 1, __value)
233 #define SET_8812_H2CCMD_REMOTE_WAKE_CTRL_ARP_OFFLOAD_EN(__cmd, __value)\
234 	SET_BITS_TO_LE_1BYTE(__cmd, 1, 1, __value)
235 #define SET_8812_H2CCMD_REMOTE_WAKE_CTRL_NDP_OFFLOAD_EN(__cmd, __value)\
236 	SET_BITS_TO_LE_1BYTE(__cmd, 2, 1, __value)
237 #define SET_8812_H2CCMD_REMOTE_WAKE_CTRL_GTK_OFFLOAD_EN(__cmd, __value)\
238 	SET_BITS_TO_LE_1BYTE(__cmd, 3, 1, __value)
239 #define SET_8812_H2CCMD_REMOTE_WAKE_CTRL_REALWOWV2_EN(__cmd, __value)\
240 	SET_BITS_TO_LE_1BYTE(__cmd, 6, 1, __value)
241 
242 /* GTK_OFFLOAD */
243 #define SET_8812_H2CCMD_AOAC_GLOBAL_INFO_PAIRWISE_ENC_ALG(__cmd, __value)\
244 	SET_BITS_TO_LE_1BYTE(__cmd, 0, 8, __value)
245 #define SET_8812_H2CCMD_AOAC_GLOBAL_INFO_GROUP_ENC_ALG(__cmd, __value)	\
246 	SET_BITS_TO_LE_1BYTE((__cmd)+1, 0, 8, __value)
247 
248 /* AOAC_RSVDPAGE_LOC */
249 #define SET_8821AE_H2CCMD_AOAC_RSVDPAGE_LOC_REMOTE_WAKE_CTRL_INFO(__cmd, __value)	\
250 	SET_BITS_TO_LE_1BYTE((__cmd), 0, 8, __value)
251 #define SET_8821AE_H2CCMD_AOAC_RSVDPAGE_LOC_ARP_RSP(__cmd, __value)	\
252 	SET_BITS_TO_LE_1BYTE((__cmd)+1, 0, 8, __value)
253 #define SET_8821AE_H2CCMD_AOAC_RSVDPAGE_LOC_NEIGHBOR_ADV(__cmd, __value)\
254 	SET_BITS_TO_LE_1BYTE((__cmd)+2, 0, 8, __value)
255 #define SET_8821AE_H2CCMD_AOAC_RSVDPAGE_LOC_GTK_RSP(__cmd, __value)	\
256 	SET_BITS_TO_LE_1BYTE((__cmd)+3, 0, 8, __value)
257 #define SET_8821AE_H2CCMD_AOAC_RSVDPAGE_LOC_GTK_INFO(__cmd, __value)	\
258 	SET_BITS_TO_LE_1BYTE((__cmd)+4, 0, 8, __value)
259 #define SET_8821AE_H2CCMD_AOAC_RSVDPAGE_LOC_GTK_EXT_MEM(__cmd, __value)	\
260 	SET_BITS_TO_LE_1BYTE((__cmd)+5, 0, 8, __value)
261 
262 /* Disconnect_Decision_Control */
263 #define SET_8812_H2CCMD_DISCONNECT_DECISION_CTRL_ENABLE(__cmd, __value)	\
264 	SET_BITS_TO_LE_1BYTE(__cmd, 0, 1, __value)
265 #define SET_8812_H2CCMD_DISCONNECT_DECISION_CTRL_USER_SETTING(__cmd, __value)\
266 	SET_BITS_TO_LE_1BYTE(__cmd, 1, 1, __value)
267 #define SET_8812_H2CCMD_DISCONNECT_DECISION_CTRL_CHECK_PERIOD(__cmd, __value)\
268 	SET_BITS_TO_LE_1BYTE((__cmd)+1, 0, 8, __value) /* unit: beacon period */
269 #define SET_8812_H2CCMD_DISCONNECT_DECISION_CTRL_TRYPKT_NUM(__cmd, __value)\
270 	SET_BITS_TO_LE_1BYTE((__cmd)+2, 0, 8, __value)
271 
272 int rtl8821ae_download_fw(struct ieee80211_hw *hw, bool buse_wake_on_wlan_fw);
273 #if (USE_SPECIFIC_FW_TO_SUPPORT_WOWLAN == 1)
274 void rtl8821ae_set_fw_related_for_wowlan(struct ieee80211_hw *hw,
275 					 bool used_wowlan_fw);
276 
277 #endif
278 void rtl8821ae_fill_h2c_cmd(struct ieee80211_hw *hw, u8 element_id,
279 			    u32 cmd_len, u8 *cmdbuffer);
280 void rtl8821ae_firmware_selfreset(struct ieee80211_hw *hw);
281 void rtl8821ae_set_fw_pwrmode_cmd(struct ieee80211_hw *hw, u8 mode);
282 void rtl8821ae_set_fw_media_status_rpt_cmd(struct ieee80211_hw *hw,
283 					   u8 mstatus);
284 void rtl8821ae_set_fw_ap_off_load_cmd(struct ieee80211_hw *hw,
285 				      u8 ap_offload_enable);
286 void rtl8821ae_set_fw_rsvdpagepkt(struct ieee80211_hw *hw,
287 				  bool b_dl_finished, bool dl_whole_packet);
288 void rtl8812ae_set_fw_rsvdpagepkt(struct ieee80211_hw *hw,
289 				  bool b_dl_finished, bool dl_whole_packet);
290 void rtl8821ae_set_p2p_ps_offload_cmd(struct ieee80211_hw *hw,
291 				      u8 p2p_ps_state);
292 void rtl8821ae_set_fw_wowlan_mode(struct ieee80211_hw *hw, bool func_en);
293 void rtl8821ae_set_fw_remote_wake_ctrl_cmd(struct ieee80211_hw *hw,
294 					   u8 enable);
295 void rtl8821ae_set_fw_keep_alive_cmd(struct ieee80211_hw *hw, bool func_en);
296 void rtl8821ae_set_fw_disconnect_decision_ctrl_cmd(struct ieee80211_hw *hw,
297 						   bool enabled);
298 void rtl8821ae_set_fw_global_info_cmd(struct ieee80211_hw *hw);
299 void rtl8821ae_c2h_ra_report_handler(struct ieee80211_hw *hw,
300 				     u8 *cmd_buf, u8 cmd_len);
301 #endif
302