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