162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* Copyright(c) 2009-2013 Realtek Corporation.*/ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci#ifndef __RTL92C__FW__H__ 562306a36Sopenharmony_ci#define __RTL92C__FW__H__ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#define FW_8192C_SIZE 0x8000 862306a36Sopenharmony_ci#define FW_8192C_START_ADDRESS 0x1000 962306a36Sopenharmony_ci#define FW_8192C_END_ADDRESS 0x5FFF 1062306a36Sopenharmony_ci#define FW_8192C_PAGE_SIZE 4096 1162306a36Sopenharmony_ci#define FW_8192C_POLLING_DELAY 5 1262306a36Sopenharmony_ci#define FW_8192C_POLLING_TIMEOUT_COUNT 3000 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#define IS_FW_HEADER_EXIST(_pfwhdr) \ 1562306a36Sopenharmony_ci ((le16_to_cpu(_pfwhdr->signature) & 0xFFFF) == 0x88E1) 1662306a36Sopenharmony_ci#define USE_OLD_WOWLAN_DEBUG_FW 0 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci#define H2C_88E_RSVDPAGE_LOC_LEN 5 1962306a36Sopenharmony_ci#define H2C_88E_PWEMODE_LENGTH 5 2062306a36Sopenharmony_ci#define H2C_88E_JOINBSSRPT_LENGTH 1 2162306a36Sopenharmony_ci#define H2C_88E_AP_OFFLOAD_LENGTH 3 2262306a36Sopenharmony_ci#define H2C_88E_WOWLAN_LENGTH 3 2362306a36Sopenharmony_ci#define H2C_88E_KEEP_ALIVE_CTRL_LENGTH 3 2462306a36Sopenharmony_ci#if (USE_OLD_WOWLAN_DEBUG_FW == 0) 2562306a36Sopenharmony_ci#define H2C_88E_REMOTE_WAKE_CTRL_LEN 1 2662306a36Sopenharmony_ci#else 2762306a36Sopenharmony_ci#define H2C_88E_REMOTE_WAKE_CTRL_LEN 3 2862306a36Sopenharmony_ci#endif 2962306a36Sopenharmony_ci#define H2C_88E_AOAC_GLOBAL_INFO_LEN 2 3062306a36Sopenharmony_ci#define H2C_88E_AOAC_RSVDPAGE_LOC_LEN 7 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci/* Fw PS state for RPWM. 3362306a36Sopenharmony_ci*BIT[2:0] = HW state 3462306a36Sopenharmony_ci*BIT[3] = Protocol PS state, 3562306a36Sopenharmony_ci*1: register active state , 0: register sleep state 3662306a36Sopenharmony_ci*BIT[4] = sub-state 3762306a36Sopenharmony_ci*/ 3862306a36Sopenharmony_ci#define FW_PS_GO_ON BIT(0) 3962306a36Sopenharmony_ci#define FW_PS_TX_NULL BIT(1) 4062306a36Sopenharmony_ci#define FW_PS_RF_ON BIT(2) 4162306a36Sopenharmony_ci#define FW_PS_REGISTER_ACTIVE BIT(3) 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#define FW_PS_DPS BIT(0) 4462306a36Sopenharmony_ci#define FW_PS_LCLK (FW_PS_DPS) 4562306a36Sopenharmony_ci#define FW_PS_RF_OFF BIT(1) 4662306a36Sopenharmony_ci#define FW_PS_ALL_ON BIT(2) 4762306a36Sopenharmony_ci#define FW_PS_ST_ACTIVE BIT(3) 4862306a36Sopenharmony_ci#define FW_PS_ISR_ENABLE BIT(4) 4962306a36Sopenharmony_ci#define FW_PS_IMR_ENABLE BIT(5) 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci#define FW_PS_ACK BIT(6) 5362306a36Sopenharmony_ci#define FW_PS_TOGGLE BIT(7) 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci /* 88E RPWM value*/ 5662306a36Sopenharmony_ci /* BIT[0] = 1: 32k, 0: 40M*/ 5762306a36Sopenharmony_ci#define FW_PS_CLOCK_OFF BIT(0) /* 32k*/ 5862306a36Sopenharmony_ci#define FW_PS_CLOCK_ON 0 /*40M*/ 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci#define FW_PS_STATE_MASK (0x0F) 6162306a36Sopenharmony_ci#define FW_PS_STATE_HW_MASK (0x07) 6262306a36Sopenharmony_ci/*ISR_ENABLE, IMR_ENABLE, and PS mode should be inherited.*/ 6362306a36Sopenharmony_ci#define FW_PS_STATE_INT_MASK (0x3F) 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci#define FW_PS_STATE(x) (FW_PS_STATE_MASK & (x)) 6662306a36Sopenharmony_ci#define FW_PS_STATE_HW(x) (FW_PS_STATE_HW_MASK & (x)) 6762306a36Sopenharmony_ci#define FW_PS_STATE_INT(x) (FW_PS_STATE_INT_MASK & (x)) 6862306a36Sopenharmony_ci#define FW_PS_ISR_VAL(x) ((x) & 0x70) 6962306a36Sopenharmony_ci#define FW_PS_IMR_MASK(x) ((x) & 0xDF) 7062306a36Sopenharmony_ci#define FW_PS_KEEP_IMR(x) ((x) & 0x20) 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci#define FW_PS_STATE_S0 (FW_PS_DPS) 7362306a36Sopenharmony_ci#define FW_PS_STATE_S1 (FW_PS_LCLK) 7462306a36Sopenharmony_ci#define FW_PS_STATE_S2 (FW_PS_RF_OFF) 7562306a36Sopenharmony_ci#define FW_PS_STATE_S3 (FW_PS_ALL_ON) 7662306a36Sopenharmony_ci#define FW_PS_STATE_S4 ((FW_PS_ST_ACTIVE) | (FW_PS_ALL_ON)) 7762306a36Sopenharmony_ci/* ((FW_PS_RF_ON) | (FW_PS_REGISTER_ACTIVE))*/ 7862306a36Sopenharmony_ci#define FW_PS_STATE_ALL_ON_88E (FW_PS_CLOCK_ON) 7962306a36Sopenharmony_ci/* (FW_PS_RF_ON)*/ 8062306a36Sopenharmony_ci#define FW_PS_STATE_RF_ON_88E (FW_PS_CLOCK_ON) 8162306a36Sopenharmony_ci/* 0x0*/ 8262306a36Sopenharmony_ci#define FW_PS_STATE_RF_OFF_88E (FW_PS_CLOCK_ON) 8362306a36Sopenharmony_ci/* (FW_PS_STATE_RF_OFF)*/ 8462306a36Sopenharmony_ci#define FW_PS_STATE_RF_OFF_LOW_PWR_88E (FW_PS_CLOCK_OFF) 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci#define FW_PS_STATE_ALL_ON_92C (FW_PS_STATE_S4) 8762306a36Sopenharmony_ci#define FW_PS_STATE_RF_ON_92C (FW_PS_STATE_S3) 8862306a36Sopenharmony_ci#define FW_PS_STATE_RF_OFF_92C (FW_PS_STATE_S2) 8962306a36Sopenharmony_ci#define FW_PS_STATE_RF_OFF_LOW_PWR_92C (FW_PS_STATE_S1) 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci/* For 88E H2C PwrMode Cmd ID 5.*/ 9262306a36Sopenharmony_ci#define FW_PWR_STATE_ACTIVE ((FW_PS_RF_ON) | (FW_PS_REGISTER_ACTIVE)) 9362306a36Sopenharmony_ci#define FW_PWR_STATE_RF_OFF 0 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci#define FW_PS_IS_ACK(x) ((x) & FW_PS_ACK) 9662306a36Sopenharmony_ci#define FW_PS_IS_CLK_ON(x) ((x) & (FW_PS_RF_OFF | FW_PS_ALL_ON)) 9762306a36Sopenharmony_ci#define FW_PS_IS_RF_ON(x) ((x) & (FW_PS_ALL_ON)) 9862306a36Sopenharmony_ci#define FW_PS_IS_ACTIVE(x) ((x) & (FW_PS_ST_ACTIVE)) 9962306a36Sopenharmony_ci#define FW_PS_IS_CPWM_INT(x) ((x) & 0x40) 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci#define FW_CLR_PS_STATE(x) ((x) = ((x) & (0xF0))) 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci#define IS_IN_LOW_POWER_STATE_88E(fwpsstate) \ 10462306a36Sopenharmony_ci (FW_PS_STATE(fwpsstate) == FW_PS_CLOCK_OFF) 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci#define FW_PWR_STATE_ACTIVE ((FW_PS_RF_ON) | (FW_PS_REGISTER_ACTIVE)) 10762306a36Sopenharmony_ci#define FW_PWR_STATE_RF_OFF 0 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_cienum rtl8188e_h2c_cmd { 11062306a36Sopenharmony_ci H2C_88E_RSVDPAGE = 0, 11162306a36Sopenharmony_ci H2C_88E_JOINBSSRPT = 1, 11262306a36Sopenharmony_ci H2C_88E_SCAN = 2, 11362306a36Sopenharmony_ci H2C_88E_KEEP_ALIVE_CTRL = 3, 11462306a36Sopenharmony_ci H2C_88E_DISCONNECT_DECISION = 4, 11562306a36Sopenharmony_ci#if (USE_OLD_WOWLAN_DEBUG_FW == 1) 11662306a36Sopenharmony_ci H2C_88E_WO_WLAN = 5, 11762306a36Sopenharmony_ci#endif 11862306a36Sopenharmony_ci H2C_88E_INIT_OFFLOAD = 6, 11962306a36Sopenharmony_ci#if (USE_OLD_WOWLAN_DEBUG_FW == 1) 12062306a36Sopenharmony_ci H2C_88E_REMOTE_WAKE_CTRL = 7, 12162306a36Sopenharmony_ci#endif 12262306a36Sopenharmony_ci H2C_88E_AP_OFFLOAD = 8, 12362306a36Sopenharmony_ci H2C_88E_BCN_RSVDPAGE = 9, 12462306a36Sopenharmony_ci H2C_88E_PROBERSP_RSVDPAGE = 10, 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci H2C_88E_SETPWRMODE = 0x20, 12762306a36Sopenharmony_ci H2C_88E_PS_TUNING_PARA = 0x21, 12862306a36Sopenharmony_ci H2C_88E_PS_TUNING_PARA2 = 0x22, 12962306a36Sopenharmony_ci H2C_88E_PS_LPS_PARA = 0x23, 13062306a36Sopenharmony_ci H2C_88E_P2P_PS_OFFLOAD = 024, 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci#if (USE_OLD_WOWLAN_DEBUG_FW == 0) 13362306a36Sopenharmony_ci H2C_88E_WO_WLAN = 0x80, 13462306a36Sopenharmony_ci H2C_88E_REMOTE_WAKE_CTRL = 0x81, 13562306a36Sopenharmony_ci H2C_88E_AOAC_GLOBAL_INFO = 0x82, 13662306a36Sopenharmony_ci H2C_88E_AOAC_RSVDPAGE = 0x83, 13762306a36Sopenharmony_ci#endif 13862306a36Sopenharmony_ci /*Not defined in new 88E H2C CMD Format*/ 13962306a36Sopenharmony_ci H2C_88E_RA_MASK, 14062306a36Sopenharmony_ci H2C_88E_SELECTIVE_SUSPEND_ROF_CMD, 14162306a36Sopenharmony_ci H2C_88E_P2P_PS_MODE, 14262306a36Sopenharmony_ci H2C_88E_PSD_RESULT, 14362306a36Sopenharmony_ci /*Not defined CTW CMD for P2P yet*/ 14462306a36Sopenharmony_ci H2C_88E_P2P_PS_CTW_CMD, 14562306a36Sopenharmony_ci MAX_88E_H2CCMD 14662306a36Sopenharmony_ci}; 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci#define pagenum_128(_len) (u32)(((_len)>>7) + ((_len)&0x7F ? 1 : 0)) 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ci#define SET_88E_H2CCMD_WOWLAN_FUNC_ENABLE(__cmd, __value) \ 15162306a36Sopenharmony_ci SET_BITS_TO_LE_1BYTE(__cmd, 0, 1, __value) 15262306a36Sopenharmony_ci#define SET_88E_H2CCMD_WOWLAN_PATTERN_MATCH_ENABLE(__cmd, __value) \ 15362306a36Sopenharmony_ci SET_BITS_TO_LE_1BYTE(__cmd, 1, 1, __value) 15462306a36Sopenharmony_ci#define SET_88E_H2CCMD_WOWLAN_MAGIC_PKT_ENABLE(__cmd, __value) \ 15562306a36Sopenharmony_ci SET_BITS_TO_LE_1BYTE(__cmd, 2, 1, __value) 15662306a36Sopenharmony_ci#define SET_88E_H2CCMD_WOWLAN_UNICAST_PKT_ENABLE(__cmd, __value) \ 15762306a36Sopenharmony_ci SET_BITS_TO_LE_1BYTE(__cmd, 3, 1, __value) 15862306a36Sopenharmony_ci#define SET_88E_H2CCMD_WOWLAN_ALL_PKT_DROP(__cmd, __value) \ 15962306a36Sopenharmony_ci SET_BITS_TO_LE_1BYTE(__cmd, 4, 1, __value) 16062306a36Sopenharmony_ci#define SET_88E_H2CCMD_WOWLAN_GPIO_ACTIVE(__cmd, __value) \ 16162306a36Sopenharmony_ci SET_BITS_TO_LE_1BYTE(__cmd, 5, 1, __value) 16262306a36Sopenharmony_ci#define SET_88E_H2CCMD_WOWLAN_REKEY_WAKE_UP(__cmd, __value) \ 16362306a36Sopenharmony_ci SET_BITS_TO_LE_1BYTE(__cmd, 6, 1, __value) 16462306a36Sopenharmony_ci#define SET_88E_H2CCMD_WOWLAN_DISCONNECT_WAKE_UP(__cmd, __value) \ 16562306a36Sopenharmony_ci SET_BITS_TO_LE_1BYTE(__cmd, 7, 1, __value) 16662306a36Sopenharmony_ci#define SET_88E_H2CCMD_WOWLAN_GPIONUM(__cmd, __value) \ 16762306a36Sopenharmony_ci SET_BITS_TO_LE_1BYTE((__cmd)+1, 0, 8, __value) 16862306a36Sopenharmony_ci#define SET_88E_H2CCMD_WOWLAN_GPIO_DURATION(__cmd, __value) \ 16962306a36Sopenharmony_ci SET_BITS_TO_LE_1BYTE((__cmd)+2, 0, 8, __value) 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_cistatic inline void set_h2ccmd_pwrmode_parm_mode(u8 *__ph2ccmd, u8 __val) 17362306a36Sopenharmony_ci{ 17462306a36Sopenharmony_ci *(u8 *)(__ph2ccmd) = __val; 17562306a36Sopenharmony_ci} 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_cistatic inline void set_h2ccmd_pwrmode_parm_rlbm(u8 *__cmd, u8 __value) 17862306a36Sopenharmony_ci{ 17962306a36Sopenharmony_ci u8p_replace_bits(__cmd + 1, __value, GENMASK(3, 0)); 18062306a36Sopenharmony_ci} 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_cistatic inline void set_h2ccmd_pwrmode_parm_smart_ps(u8 *__cmd, u8 __value) 18362306a36Sopenharmony_ci{ 18462306a36Sopenharmony_ci u8p_replace_bits(__cmd + 1, __value, GENMASK(7, 4)); 18562306a36Sopenharmony_ci} 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_cistatic inline void set_h2ccmd_pwrmode_parm_awake_interval(u8 *__cmd, u8 __value) 18862306a36Sopenharmony_ci{ 18962306a36Sopenharmony_ci *(u8 *)(__cmd + 2) = __value; 19062306a36Sopenharmony_ci} 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_cistatic inline void set_h2ccmd_pwrmode_parm_all_queue_uapsd(u8 *__cmd, 19362306a36Sopenharmony_ci u8 __value) 19462306a36Sopenharmony_ci{ 19562306a36Sopenharmony_ci *(u8 *)(__cmd + 3) = __value; 19662306a36Sopenharmony_ci} 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_cistatic inline void set_h2ccmd_pwrmode_parm_pwr_state(u8 *__cmd, u8 __value) 19962306a36Sopenharmony_ci{ 20062306a36Sopenharmony_ci *(u8 *)(__cmd + 4) = __value; 20162306a36Sopenharmony_ci} 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ci#define SET_H2CCMD_JOINBSSRPT_PARM_OPMODE(__ph2ccmd, __val) \ 20462306a36Sopenharmony_ci *(u8 *)(__ph2ccmd) = __val; 20562306a36Sopenharmony_ci#define SET_H2CCMD_RSVDPAGE_LOC_PROBE_RSP(__ph2ccmd, __val) \ 20662306a36Sopenharmony_ci *(u8 *)(__ph2ccmd) = __val; 20762306a36Sopenharmony_ci#define SET_H2CCMD_RSVDPAGE_LOC_PSPOLL(__ph2ccmd, __val) \ 20862306a36Sopenharmony_ci *(u8 *)(__ph2ccmd + 1) = __val; 20962306a36Sopenharmony_ci#define SET_H2CCMD_RSVDPAGE_LOC_NULL_DATA(__ph2ccmd, __val) \ 21062306a36Sopenharmony_ci *(u8 *)(__ph2ccmd + 2) = __val; 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_ci/* AP_OFFLOAD */ 21362306a36Sopenharmony_ci#define SET_H2CCMD_AP_OFFLOAD_ON(__cmd, __value) \ 21462306a36Sopenharmony_ci *(u8 *)__cmd = __value; 21562306a36Sopenharmony_ci#define SET_H2CCMD_AP_OFFLOAD_HIDDEN(__cmd, __value) \ 21662306a36Sopenharmony_ci *(u8 *)(__cmd + 1) = __value; 21762306a36Sopenharmony_ci#define SET_H2CCMD_AP_OFFLOAD_DENYANY(__cmd, __value) \ 21862306a36Sopenharmony_ci *(u8 *)(__cmd + 2) = __value; 21962306a36Sopenharmony_ci#define SET_H2CCMD_AP_OFFLOAD_WAKEUP_EVT_RPT(__cmd, __value) \ 22062306a36Sopenharmony_ci *(u8 *)(__cmd + 3) = __value; 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_ciint rtl88e_download_fw(struct ieee80211_hw *hw, 22362306a36Sopenharmony_ci bool buse_wake_on_wlan_fw); 22462306a36Sopenharmony_civoid rtl88e_fill_h2c_cmd(struct ieee80211_hw *hw, u8 element_id, 22562306a36Sopenharmony_ci u32 cmd_len, u8 *cmdbuffer); 22662306a36Sopenharmony_civoid rtl88e_firmware_selfreset(struct ieee80211_hw *hw); 22762306a36Sopenharmony_civoid rtl88e_set_fw_pwrmode_cmd(struct ieee80211_hw *hw, u8 mode); 22862306a36Sopenharmony_civoid rtl88e_set_fw_joinbss_report_cmd(struct ieee80211_hw *hw, u8 mstatus); 22962306a36Sopenharmony_civoid rtl88e_set_fw_ap_off_load_cmd(struct ieee80211_hw *hw, 23062306a36Sopenharmony_ci u8 ap_offload_enable); 23162306a36Sopenharmony_civoid rtl88e_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool b_dl_finished); 23262306a36Sopenharmony_civoid rtl88e_set_p2p_ps_offload_cmd(struct ieee80211_hw *hw, u8 p2p_ps_state); 23362306a36Sopenharmony_ci#endif 234