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			7
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 rtl8821a_h2c_cmd {
141 	H2C_8821AE_RSVDPAGE = 0,
142 	H2C_8821AE_MSRRPT = 1,
143 	H2C_8821AE_SCAN = 2,
144 	H2C_8821AE_KEEP_ALIVE_CTRL = 3,
145 	H2C_8821AE_DISCONNECT_DECISION = 4,
146 	H2C_8821AE_INIT_OFFLOAD = 6,
147 	H2C_8821AE_AP_OFFLOAD = 8,
148 	H2C_8821AE_BCN_RSVDPAGE = 9,
149 	H2C_8821AE_PROBERSP_RSVDPAGE = 10,
150 
151 	H2C_8821AE_SETPWRMODE = 0x20,
152 	H2C_8821AE_PS_TUNING_PARA = 0x21,
153 	H2C_8821AE_PS_TUNING_PARA2 = 0x22,
154 	H2C_8821AE_PS_LPS_PARA = 0x23,
155 	H2C_8821AE_P2P_PS_OFFLOAD = 024,
156 
157 	H2C_8821AE_WO_WLAN = 0x80,
158 	H2C_8821AE_REMOTE_WAKE_CTRL = 0x81,
159 	H2C_8821AE_AOAC_GLOBAL_INFO = 0x82,
160 	H2C_8821AE_AOAC_RSVDPAGE = 0x83,
161 
162 	H2C_RSSI_21AE_REPORT = 0x42,
163 	H2C_8821AE_RA_MASK = 0x40,
164 	H2C_8821AE_SELECTIVE_SUSPEND_ROF_CMD,
165 	H2C_8821AE_P2P_PS_MODE,
166 	H2C_8821AE_PSD_RESULT,
167 	/*Not defined CTW CMD for P2P yet*/
168 	H2C_8821AE_P2P_PS_CTW_CMD,
169 	MAX_8821AE_H2CCMD
170 };
171 
172 #define pagenum_128(_len)	(u32)(((_len)>>7) + ((_len)&0x7F ? 1 : 0))
173 
174 #define SET_8812_H2CCMD_WOWLAN_FUNC_ENABLE(__cmd, __value)		\
175 	SET_BITS_TO_LE_1BYTE(__cmd, 0, 1, __value)
176 #define SET_8812_H2CCMD_WOWLAN_PATTERN_MATCH_ENABLE(__cmd, __value)	\
177 	SET_BITS_TO_LE_1BYTE(__cmd, 1, 1, __value)
178 #define SET_8812_H2CCMD_WOWLAN_MAGIC_PKT_ENABLE(__cmd, __value)	\
179 	SET_BITS_TO_LE_1BYTE(__cmd, 2, 1, __value)
180 #define SET_8812_H2CCMD_WOWLAN_UNICAST_PKT_ENABLE(__cmd, __value)	\
181 	SET_BITS_TO_LE_1BYTE(__cmd, 3, 1, __value)
182 #define SET_8812_H2CCMD_WOWLAN_ALL_PKT_DROP(__cmd, __value)		\
183 	SET_BITS_TO_LE_1BYTE(__cmd, 4, 1, __value)
184 #define SET_8812_H2CCMD_WOWLAN_GPIO_ACTIVE(__cmd, __value)		\
185 	SET_BITS_TO_LE_1BYTE(__cmd, 5, 1, __value)
186 #define SET_8812_H2CCMD_WOWLAN_REKEY_WAKE_UP(__cmd, __value)	\
187 	SET_BITS_TO_LE_1BYTE(__cmd, 6, 1, __value)
188 #define SET_8812_H2CCMD_WOWLAN_DISCONNECT_WAKE_UP(__cmd, __value)	\
189 	SET_BITS_TO_LE_1BYTE(__cmd, 7, 1, __value)
190 #define SET_8812_H2CCMD_WOWLAN_GPIONUM(__cmd, __value)		\
191 	SET_BITS_TO_LE_1BYTE((__cmd) + 1, 0, 8, __value)
192 #define SET_8812_H2CCMD_WOWLAN_GPIO_DURATION(__cmd, __value)	\
193 	SET_BITS_TO_LE_1BYTE((__cmd) + 2, 0, 8, __value)
194 
195 #define SET_H2CCMD_PWRMODE_PARM_MODE(__ph2ccmd, __val)			\
196 	SET_BITS_TO_LE_1BYTE(__ph2ccmd, 0, 8, __val)
197 #define SET_H2CCMD_PWRMODE_PARM_RLBM(__cmd, __value)		\
198 	SET_BITS_TO_LE_1BYTE((__cmd)+1, 0, 4, __value)
199 #define SET_H2CCMD_PWRMODE_PARM_SMART_PS(__cmd, __value)	\
200 	SET_BITS_TO_LE_1BYTE((__cmd)+1, 4, 4, __value)
201 #define SET_H2CCMD_PWRMODE_PARM_AWAKE_INTERVAL(__cmd, __value)	\
202 	SET_BITS_TO_LE_1BYTE((__cmd)+2, 0, 8, __value)
203 #define SET_H2CCMD_PWRMODE_PARM_ALL_QUEUE_UAPSD(__cmd, __value)		\
204 	SET_BITS_TO_LE_1BYTE((__cmd)+3, 0, 8, __value)
205 #define SET_H2CCMD_PWRMODE_PARM_PWR_STATE(__cmd, __value)	\
206 	SET_BITS_TO_LE_1BYTE((__cmd)+4, 0, 8, __value)
207 #define SET_H2CCMD_PWRMODE_PARM_BYTE5(__cmd, __value)		\
208 	SET_BITS_TO_LE_1BYTE((__cmd) + 5, 0, 8, __value)
209 #define GET_8821AE_H2CCMD_PWRMODE_PARM_MODE(__cmd)		\
210 	LE_BITS_TO_1BYTE(__cmd, 0, 8)
211 
212 #define SET_H2CCMD_JOINBSSRPT_PARM_OPMODE(__ph2ccmd, __val)		\
213 	SET_BITS_TO_LE_1BYTE(__ph2ccmd, 0, 8, __val)
214 #define SET_H2CCMD_RSVDPAGE_LOC_PSPOLL(__ph2ccmd, __val)		\
215 	SET_BITS_TO_LE_1BYTE((__ph2ccmd)+1, 0, 8, __val)
216 #define SET_H2CCMD_RSVDPAGE_LOC_NULL_DATA(__ph2ccmd, __val)		\
217 	SET_BITS_TO_LE_1BYTE((__ph2ccmd)+2, 0, 8, __val)
218 #define SET_H2CCMD_RSVDPAGE_LOC_QOS_NULL_DATA(__ph2ccmd, __val)		\
219 	SET_BITS_TO_LE_1BYTE((__ph2ccmd)+3, 0, 8, __val)
220 #define SET_H2CCMD_RSVDPAGE_LOC_BT_QOS_NULL_DATA(__ph2ccmd, __val)	\
221 	SET_BITS_TO_LE_1BYTE((__ph2ccmd) + 4, 0, 8, __val)
222 
223 /* _MEDIA_STATUS_RPT_PARM_CMD1 */
224 #define SET_H2CCMD_MSRRPT_PARM_OPMODE(__cmd, __value)	\
225 	SET_BITS_TO_LE_1BYTE(__cmd, 0, 1, __value)
226 #define SET_H2CCMD_MSRRPT_PARM_MACID_IND(__cmd, __value)	\
227 	SET_BITS_TO_LE_1BYTE(__cmd, 1, 1, __value)
228 #define SET_H2CCMD_MSRRPT_PARM_MACID(__cmd, __value)	\
229 	SET_BITS_TO_LE_1BYTE(__cmd+1, 0, 8, __value)
230 #define SET_H2CCMD_MSRRPT_PARM_MACID_END(__cmd, __value)	\
231 	SET_BITS_TO_LE_1BYTE(__cmd+2, 0, 8, __value)
232 
233 /* AP_OFFLOAD */
234 #define SET_H2CCMD_AP_OFFLOAD_ON(__cmd, __value)	\
235 	SET_BITS_TO_LE_1BYTE(__cmd, 0, 8, __value)
236 #define SET_H2CCMD_AP_OFFLOAD_HIDDEN(__cmd, __value)	\
237 	SET_BITS_TO_LE_1BYTE((__cmd)+1, 0, 8, __value)
238 #define SET_H2CCMD_AP_OFFLOAD_DENYANY(__cmd, __value)	\
239 	SET_BITS_TO_LE_1BYTE((__cmd)+2, 0, 8, __value)
240 #define SET_H2CCMD_AP_OFFLOAD_WAKEUP_EVT_RPT(__cmd, __value) \
241 	SET_BITS_TO_LE_1BYTE((__cmd)+3, 0, 8, __value)
242 
243 /* Keep Alive Control*/
244 #define SET_8812_H2CCMD_KEEP_ALIVE_ENABLE(__cmd, __value)	\
245 	SET_BITS_TO_LE_1BYTE(__cmd, 0, 1, __value)
246 #define SET_8812_H2CCMD_KEEP_ALIVE_ACCPEPT_USER_DEFINED(__cmd, __value)	\
247 	SET_BITS_TO_LE_1BYTE(__cmd, 1, 1, __value)
248 #define SET_8812_H2CCMD_KEEP_ALIVE_PERIOD(__cmd, __value)	\
249 	SET_BITS_TO_LE_1BYTE((__cmd)+1, 0, 8, __value)
250 
251 /*REMOTE_WAKE_CTRL */
252 #define SET_8812_H2CCMD_REMOTE_WAKECTRL_ENABLE(__cmd, __value)	\
253 	SET_BITS_TO_LE_1BYTE(__cmd, 0, 1, __value)
254 #define SET_8812_H2CCMD_REMOTE_WAKE_CTRL_ARP_OFFLOAD_EN(__cmd, __value)\
255 	SET_BITS_TO_LE_1BYTE(__cmd, 1, 1, __value)
256 #define SET_8812_H2CCMD_REMOTE_WAKE_CTRL_NDP_OFFLOAD_EN(__cmd, __value)\
257 	SET_BITS_TO_LE_1BYTE(__cmd, 2, 1, __value)
258 #define SET_8812_H2CCMD_REMOTE_WAKE_CTRL_GTK_OFFLOAD_EN(__cmd, __value)\
259 	SET_BITS_TO_LE_1BYTE(__cmd, 3, 1, __value)
260 #define SET_8812_H2CCMD_REMOTE_WAKE_CTRL_REALWOWV2_EN(__cmd, __value)\
261 	SET_BITS_TO_LE_1BYTE(__cmd, 6, 1, __value)
262 
263 /* GTK_OFFLOAD */
264 #define SET_8812_H2CCMD_AOAC_GLOBAL_INFO_PAIRWISE_ENC_ALG(__cmd, __value)\
265 	SET_BITS_TO_LE_1BYTE(__cmd, 0, 8, __value)
266 #define SET_8812_H2CCMD_AOAC_GLOBAL_INFO_GROUP_ENC_ALG(__cmd, __value)	\
267 	SET_BITS_TO_LE_1BYTE((__cmd)+1, 0, 8, __value)
268 
269 /* AOAC_RSVDPAGE_LOC */
270 #define SET_8821AE_H2CCMD_AOAC_RSVDPAGE_LOC_REMOTE_WAKE_CTRL_INFO(__cmd, __value)	\
271 	SET_BITS_TO_LE_1BYTE((__cmd), 0, 8, __value)
272 #define SET_8821AE_H2CCMD_AOAC_RSVDPAGE_LOC_ARP_RSP(__cmd, __value)	\
273 	SET_BITS_TO_LE_1BYTE((__cmd)+1, 0, 8, __value)
274 #define SET_8821AE_H2CCMD_AOAC_RSVDPAGE_LOC_NEIGHBOR_ADV(__cmd, __value)\
275 	SET_BITS_TO_LE_1BYTE((__cmd)+2, 0, 8, __value)
276 #define SET_8821AE_H2CCMD_AOAC_RSVDPAGE_LOC_GTK_RSP(__cmd, __value)	\
277 	SET_BITS_TO_LE_1BYTE((__cmd)+3, 0, 8, __value)
278 #define SET_8821AE_H2CCMD_AOAC_RSVDPAGE_LOC_GTK_INFO(__cmd, __value)	\
279 	SET_BITS_TO_LE_1BYTE((__cmd)+4, 0, 8, __value)
280 #define SET_8821AE_H2CCMD_AOAC_RSVDPAGE_LOC_GTK_EXT_MEM(__cmd, __value)	\
281 	SET_BITS_TO_LE_1BYTE((__cmd)+5, 0, 8, __value)
282 
283 /* Disconnect_Decision_Control */
284 #define SET_8812_H2CCMD_DISCONNECT_DECISION_CTRL_ENABLE(__cmd, __value)	\
285 	SET_BITS_TO_LE_1BYTE(__cmd, 0, 1, __value)
286 #define SET_8812_H2CCMD_DISCONNECT_DECISION_CTRL_USER_SETTING(__cmd, __value)\
287 	SET_BITS_TO_LE_1BYTE(__cmd, 1, 1, __value)
288 #define SET_8812_H2CCMD_DISCONNECT_DECISION_CTRL_CHECK_PERIOD(__cmd, __value)\
289 	SET_BITS_TO_LE_1BYTE((__cmd)+1, 0, 8, __value) /* unit: beacon period */
290 #define SET_8812_H2CCMD_DISCONNECT_DECISION_CTRL_TRYPKT_NUM(__cmd, __value)\
291 	SET_BITS_TO_LE_1BYTE((__cmd)+2, 0, 8, __value)
292 
293 int rtl8821ae_download_fw(struct ieee80211_hw *hw, bool buse_wake_on_wlan_fw);
294 #if (USE_SPECIFIC_FW_TO_SUPPORT_WOWLAN == 1)
295 void rtl8821ae_set_fw_related_for_wowlan(struct ieee80211_hw *hw,
296 					 bool used_wowlan_fw);
297 
298 #endif
299 void rtl8821ae_fill_h2c_cmd(struct ieee80211_hw *hw, u8 element_id,
300 			    u32 cmd_len, u8 *cmdbuffer);
301 void rtl8821ae_firmware_selfreset(struct ieee80211_hw *hw);
302 void rtl8821ae_set_fw_pwrmode_cmd(struct ieee80211_hw *hw, u8 mode);
303 void rtl8821ae_set_fw_media_status_rpt_cmd(struct ieee80211_hw *hw,
304 					   u8 mstatus);
305 void rtl8821ae_set_fw_ap_off_load_cmd(struct ieee80211_hw *hw,
306 				      u8 ap_offload_enable);
307 void rtl8821ae_set_fw_rsvdpagepkt(struct ieee80211_hw *hw,
308 				  bool b_dl_finished, bool dl_whole_packet);
309 void rtl8812ae_set_fw_rsvdpagepkt(struct ieee80211_hw *hw,
310 				  bool b_dl_finished, bool dl_whole_packet);
311 void rtl8821ae_set_p2p_ps_offload_cmd(struct ieee80211_hw *hw,
312 				      u8 p2p_ps_state);
313 void rtl8821ae_set_fw_wowlan_mode(struct ieee80211_hw *hw, bool func_en);
314 void rtl8821ae_set_fw_remote_wake_ctrl_cmd(struct ieee80211_hw *hw,
315 					   u8 enable);
316 void rtl8821ae_set_fw_keep_alive_cmd(struct ieee80211_hw *hw, bool func_en);
317 void rtl8821ae_set_fw_disconnect_decision_ctrl_cmd(struct ieee80211_hw *hw,
318 						   bool enabled);
319 void rtl8821ae_set_fw_global_info_cmd(struct ieee80211_hw *hw);
320 void rtl8821ae_c2h_ra_report_handler(struct ieee80211_hw *hw,
321 				     u8 *cmd_buf, u8 cmd_len);
322 #endif
323