1 /* 2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 */ 18 19 #ifndef __PLAT_PM_WLAN_H__ 20 #define __PLAT_PM_WLAN_H__ 21 22 /* **************************************************************************** 23 1 Include other Head file 24 **************************************************************************** */ 25 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) || (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) 26 #ifndef HAVE_PCLINT_CHECK 27 #include <linux/kernel.h> 28 #endif 29 #endif 30 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) 31 #include <linux/mmc/host.h> 32 #include <linux/mmc/sdio_func.h> 33 #include <linux/mmc/sdio.h> 34 #include <linux/fb.h> 35 #include <linux/mutex.h> 36 #endif 37 #include "oal_ext_if.h" 38 #include "oal_channel_host_if.h" 39 40 /* cmw need to be confirmed */ 41 #define HOST_WAIT_BOTTOM_INIT_TIMEOUT 5000 42 #define HOST_WAIT_READY_INTERVAL 10 43 #define WLAN_WAKUP_MSG_WAIT_TIMEOUT 500 44 #define WLAN_SLEEP_MSG_WAIT_TIMEOUT 50 45 #define WLAN_FORSLP_MSG_WAIT_TIMEOUT 100 /* suspend wait forceslp work */ 46 #define WLAN_SLP_MSG_WAIT_TIMEOUT 500 /* wdgtimeout wait slp work */ 47 #define WLAN_RESUME_WAIT_TIMEOUT 3000 48 #define WLAN_POWEROFF_ACK_WAIT_TIMEOUT 1000 49 #define WLAN_OPEN_BCPU_WAIT_TIMEOUT 1000 50 #define WLAN_HALT_BCPU_TIMEOUT 1000 51 #define HOST_WAIT_FOR_DEV_DETACH 0xffffff 52 53 #define WLAN_SLEEP_TIMER_PERIOD 80 /* 睡眠定时器80ms定时 */ 54 #define WLAN_SLEEP_DEFAULT_CHECK_CNT 5 /* 默认检查5次,即400ms */ 55 #define WLAN_SLEEP_LONG_CHECK_CNT 10 /* 入网阶段,延长至400ms */ 56 #define WLAN_SDIO_MSG_RETRY_NUM 3 57 #define WLAN_WAKEUP_FAIL_MAX_TIMES 1 /* 连续多少次wakeup失败,可进入DFR流程 */ 58 #define WLAN_TRY_WAKEUP_FAIL_TIMES 3 59 #define WLAN_PM_MODULE "[wlan]" 60 61 #define WLAN_PM_SLPREQ_LEVEL 0 62 #define WLAN_PM_WKUPDEV_LEVEL 1 63 #define INVALID_IRQ (-1) 64 #define WK_FAIL_SIG 44 65 #define TIMEOUT_MUTIPLE_6 6 66 67 enum WLAN_PM_CPU_FREQ_ENUM { 68 WLCPU_40MHZ = 1, 69 WLCPU_80MHZ = 2, 70 WLCPU_160MHZ = 3, 71 WLCPU_240MHZ = 4, 72 WLCPU_320MHZ = 5, 73 WLCPU_480MHZ = 6, 74 }; 75 76 enum WLAN_PM_SLEEP_STAGE { 77 SLEEP_STAGE_INIT = 0, /* 初始 */ 78 SLEEP_REQ_SND = 1, /* leep request发送完成 */ 79 SLEEP_ALLOW_RCV = 2, /* 收到allow sleep response */ 80 SLEEP_DISALLOW_RCV = 3, /* 收到allow sleep response */ 81 SLEEP_CMD_SND = 4, /* 允许睡眠reg设置完成 */ 82 }; 83 84 enum WLAN_PM_SLP_REQ { 85 NO_SLPREQ_STATUS = 0, 86 FORCE_SLP_STATUS = 1, 87 REQ_SLP_STATUS = 2, 88 }; 89 90 enum WLAN_PM_SLPREQ_ACK { 91 SLPACK_DEV_ALLOW = 0, 92 SLPACK_DEV_DISALLOW = 1, 93 }; 94 95 enum WLAN_PM_REUSME_WIFI_MODE { 96 REUSME_WIFI_NO = 0, 97 REUSME_WIFI_AP = 1, 98 REUSME_WIFI_STA = 2, 99 }; 100 101 /* 睡眠模块ID 枚举,每个id占用1个bit,继续扩展时要注意最大为(1 << 31)。 */ 102 typedef enum { 103 HI_PM_ID_AP = 0, /* AP 模块 Id */ 104 HI_PM_ID_STA = 1, /* STA 模块 Id */ 105 HI_PM_ID_RSV = 5, /* 内部预留 Id 5 */ 106 HI_PM_ID_MAX = 31, /* ID不可大于 31 */ 107 } wlan_pm_vote_id; 108 109 /* **************************************************************************** 110 3 STRUCT DEFINE 111 **************************************************************************** */ 112 typedef hi_u32 (*wifi_srv_get_pm_pause_func)(hi_void); 113 typedef void (*hi_wifi_wkup_fail_cb)(void); 114 115 struct wifi_srv_callback_handler { 116 wifi_srv_get_pm_pause_func p_wifi_srv_get_pm_pause_func; 117 }; 118 119 struct wlan_pm_info { 120 struct BusDev *bus; 121 unsigned long wlan_pm_enable; /* pm使能开关 */ 122 unsigned long wlan_power_state; /* wlan power on state */ 123 unsigned long apmode_allow_pm_flag; /* ap模式下,是否允许下电操作,1:允许,0:不允许 */ 124 125 volatile unsigned long wlan_dev_state; /* wlan sleep state */ 126 volatile unsigned long wlan_host_state; /* wlan host sleep state */ 127 volatile hi_u32 vote_status; /* 0:sleep 1: work,每一bit代表一个投票 */ 128 129 oal_workqueue_stru *pm_wq; /* pm work quque */ 130 oal_work_stru wakeup_work; /* 唤醒work */ 131 oal_work_stru sleep_work; /* sleep work */ 132 133 oal_timer_list_stru watchdog_timer; /* sleep watch dog */ 134 hi_u32 packet_cnt; /* 睡眠周期内统计的packet个数 */ 135 hi_u32 wdg_timeout_cnt; /* timeout check cnt */ 136 hi_u32 wdg_timeout_curr_cnt; /* timeout check current cnt */ 137 hi_u32 slpreq_flag; 138 hi_u32 slpack; 139 140 oal_completion close_done; 141 oal_completion device_ready; 142 oal_completion wakeup_done; 143 oal_completion sleep_request_ack; 144 oal_completion host_sleep_request_ack; 145 146 struct wifi_srv_callback_handler st_wifi_srv_handler; 147 148 /* 维测统计 */ 149 hi_u32 open_cnt; 150 hi_u32 close_cnt; 151 hi_u32 close_done_callback; 152 hi_u32 wakeup_succ; 153 hi_u32 wakeup_succ_work_submit; 154 hi_u32 wakeup_dev_ack; 155 hi_u32 wakeup_done_callback; 156 hi_u32 wakeup_fail_wait_sdio; 157 hi_u32 wakeup_fail_timeout; 158 hi_u32 wakeup_fail_set_reg; 159 hi_u32 wakeup_fail_submit_work; 160 hi_u32 wakeup_gpio_up_cnt; 161 162 hi_u32 sleep_succ; 163 hi_u32 sleep_feed_wdg_cnt; 164 hi_u32 sleep_start_wdg_timer_cnt; 165 hi_u32 sleep_fail_request; 166 hi_u32 sleep_fail_wait_timeout; 167 hi_u32 sleep_fail_set_reg; 168 hi_u32 sleep_fail_forbid; 169 hi_u32 sleep_work_submit; 170 hi_u32 sleep_msg_send_cnt; 171 hi_u32 sleep_dev_ack_cnt; 172 hi_u32 sleep_gpio_low_cnt; 173 }; 174 175 typedef struct { 176 hi_u32 wakeup_times; /**< wakeup times.CNcomment:唤醒次数统计 CNend */ 177 hi_u32 sleep_threshold_refuse_times; /**< sleep threshold refuse times.CNcomment: 178 可睡时间小于设定门限次数统计 CNend */ 179 hi_u32 sleep_check_refuse_times; /**< sleep check refuse times.CNcomment: 180 入睡投票睡眠失败次数统计 CNend */ 181 hi_u32 sleep_times; /**< sleep times.CNcomment:入睡次数统计 CNend */ 182 hi_u32 sleep_threshold; /**< sleep threshold, unit is ms, only when 183 the system' Remaining idle time is bigger than the threshold, 184 system can enter deep sleep state.CNcomment:深睡眠门限,单位 185 为ms,当系统剩余空闲时间大于该门限时,方可进入深睡 CNend */ 186 hi_u32 dsleep_fail_times; /**< the times of power off fail during deepsleep.CNcomment:深睡下电失败次数统计 CNend */ 187 hi_u8 type; /**< hi_lpc_type type, enable low power management. 188 CNcomment:hi_lp_type类型,低功耗类型 CNend */ 189 hi_u8 evt_sts; /**< sleep event state.CNcomment:唤醒事件状态 CNend */ 190 hi_u8 int_sts; /**< sleep interrupt state.CNcomment:唤醒中断状态 CNend */ 191 hi_u8 last_time_vote_state; /**< last time vote state, 0:no sleep, 1: light sleep, 2: deep sleep. 192 CNcomment:最近一次睡眠状态,0:没有入睡,1:浅睡,2:深睡。 CNend */ 193 hi_u32 timer_ticks; /**< the time ticks is about to expire, unit is 10 ms, if the value is 0xffffffff, there is 194 no timer that is about to expire. 195 CNcomment:定时器即将到期的时间,单位为10ms;如果是0xffffffff,表示没有即将到期的 196 定时器 CNend */ 197 hi_u32 timer_handle; /**< the callback function address of the timer that is about to expire. if the value is 198 0xffffffff, it means that there is no timer that is about to expire. 199 CNcomment:即将到期定时器回调函数的地址,如果是0xffffffff,表示没有即将到期的定时器 CNend */ 200 hi_u32 timer_handle_arg; /**< the parameter of the timer callback function, if the value is 0xffffffff, it means 201 there is no timer to expire.CNcomment:定时器回调函数的参数,如果是0xffffffff, 202 表示没有即将到期的定时器 CNend */ 203 hi_u32 task_ticks; /**< the task ticks is about to expire, unit is 10 ms.CNcomment:任务即将到期的时间, 204 单位为10ms。CNend */ 205 hi_u32 task_id; /**< the task id that is about to expire.CNcomment:即将到期任务的ID。CNend */ 206 hi_u32 sleep_ticks; /**< last sleep time ticks, unit is 10 ms.CNcomment:最近一次睡眠的tick时间, 207 单位为10ms。CNend */ 208 hi_u32 veto_info; /**< veto_info.CNcomment:投票否决睡眠信息,详见hi_lpc_id。CNend */ 209 hi_u16 dsleep_wk_gpio; /**< wakeup gpio for deep sleep.CNcomment:唤醒的GPIO,该值(1<<x)为1表示GPIOx使能。CNend */ 210 hi_u16 sdio_busy : 1; 211 hi_u16 host_sleeped : 1; 212 hi_u16 host_allow_dev_sleep : 1; 213 hi_u16 sdio_allow_sleep : 1; 214 hi_u16 reserve : 12; /* reserve 12 bits */ 215 hi_u32 refuse_vote_handle; /**< Address of voting funcfion refusing to vote for sleep.CNcomment: 216 拒绝投睡眠票的投票函数地址。CNend */ 217 hi_u32 host_allow_device_slp_times; 218 hi_u32 sdio_wkup_int_times; 219 hi_u32 device_sdio_wkup_ack_times; 220 hi_u32 sdio_busy_times; 221 hi_u32 host_vote_work_times; 222 hi_u32 sdio_vote_work_times; 223 } hi_device_lpc_info; 224 225 /* **************************************************************************** 226 5 EXTERN FUNCTION 227 **************************************************************************** */ 228 struct wlan_pm_info *wlan_pm_get_drv(hi_void); 229 void wlan_pm_dump_host_info(void); 230 void wlan_pm_dump_device_info(void); 231 unsigned long wlan_pm_exit(hi_void); 232 hi_s32 wlan_pm_is_poweron(hi_void); 233 hi_s32 wlan_pm_is_shutdown(hi_void); 234 hi_u32 wlan_pm_open(hi_void); 235 hi_u32 wlan_pm_close(hi_void); 236 unsigned long wlan_pm_wakeup_dev(hi_void); 237 unsigned long wlan_pm_wakeup_host(void); 238 unsigned long wlan_pm_state_get(void); 239 hi_u32 hi_wifi_plat_pm_enable(hi_void); 240 hi_u32 hi_wifi_plat_pm_disable(hi_void); 241 hi_s32 wlan_pm_disable_check_wakeup(hi_s32 flag); 242 hi_u32 wlan_pm_set_pm_sts_exception(hi_void); 243 struct wifi_srv_callback_handler *wlan_pm_get_wifi_srv_handler(hi_void); 244 hi_void wlan_pm_wakeup_dev_ack(hi_void); 245 hi_void wlan_pm_set_timeout(hi_u32 timeout); 246 hi_void wlan_pm_feed_wdg(hi_void); 247 hi_s32 wlan_pm_stop_wdg(hi_void); 248 void wlan_pm_wdg_timeout(struct wlan_pm_info *wlan_pm); 249 hi_void wlan_pm_state_set(struct wlan_pm_info *wlan_pm, unsigned long state); 250 251 void wlan_pm_info_clean(void); 252 hi_s32 wlan_device_mem_check(void); 253 hi_s32 wlan_device_mem_check_result(unsigned long long *time); 254 255 unsigned long wlan_pm_dev_sleep_request(void); 256 unsigned int hi_wifi_host_request_sleep(bool slp); 257 struct wlan_pm_info *wlan_pm_init(void); 258 259 /* 统计hcc中的数据包 */ 260 hi_void wlan_pm_set_packet_cnt(hi_u32 delt); 261 262 hi_void wlan_pm_set_wkfail_pid(int pid); 263 hi_s32 hi_wifi_register_wkup_fail_process_handle(hi_wifi_wkup_fail_cb cb); 264 hi_u8 wlan_pm_is_disabling(void); 265 void wlan_pm_dump_device_pm_info(char *buf, int length); 266 hi_void hi_wlan_dump_pm_info(hi_u8 is_host); 267 /* 投票禁止睡眠 */ 268 hi_void wlan_pm_add_vote(wlan_pm_vote_id id); 269 /* 解除对应id的禁止进入睡眠模式状态 */ 270 hi_void wlan_pm_remove_vote(wlan_pm_vote_id id); 271 272 void set_device_is_ready(hi_u8 is_ready); 273 274 #ifdef _PRE_WLAN_PM_FEATURE_FORCESLP_RESUME 275 hi_void wlan_resume_state_set(hi_u32 ul_state); 276 hi_u32 wlan_resume_state_get(hi_void); 277 #endif 278 279 #endif 280