2013-05-08 21:45:39 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
|
2013-05-19 04:28:07 +00:00
|
|
|
*
|
2013-05-08 21:45:39 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of version 2 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
#define _RTW_PWRCTRL_C_
|
|
|
|
|
|
|
|
#include <drv_conf.h>
|
|
|
|
#include <osdep_service.h>
|
|
|
|
#include <drv_types.h>
|
|
|
|
#include <osdep_intf.h>
|
2013-05-25 20:45:50 +00:00
|
|
|
#include <linux/usb.h>
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_BT_COEXIST
|
|
|
|
#include <rtl8723a_hal.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_IPS
|
|
|
|
void ips_enter(_adapter * padapter)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
|
|
|
|
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
|
|
|
struct xmit_priv *pxmit_priv = &padapter->xmitpriv;
|
|
|
|
|
|
|
|
#if (MP_DRIVER == 1)
|
|
|
|
if (padapter->registrypriv.mp_mode == 1)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (pxmit_priv->free_xmitbuf_cnt != NR_XMITBUFF ||
|
|
|
|
pxmit_priv->free_xmit_extbuf_cnt != NR_XMIT_EXTBUFF) {
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E_LEVEL(_drv_info_, "There are some pkts to transmit\n");
|
|
|
|
DBG_88E_LEVEL(_drv_info_, "free_xmitbuf_cnt: %d, free_xmit_extbuf_cnt: %d\n",
|
2013-05-19 04:28:07 +00:00
|
|
|
pxmit_priv->free_xmitbuf_cnt, pxmit_priv->free_xmit_extbuf_cnt);
|
2013-05-08 21:45:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_enter_pwrlock(&pwrpriv->lock);
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->bips_processing = true;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* syn ips_mode with request */
|
2013-05-08 21:45:39 +00:00
|
|
|
pwrpriv->ips_mode = pwrpriv->ips_mode_req;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
|
|
|
pwrpriv->ips_enter_cnts++;
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("==>ips_enter cnts:%d\n",pwrpriv->ips_enter_cnts);
|
2013-05-08 21:45:39 +00:00
|
|
|
#ifdef CONFIG_BT_COEXIST
|
|
|
|
BTDM_TurnOffBtCoexistBeforeEnterIPS(padapter);
|
|
|
|
#endif
|
2013-05-09 04:04:25 +00:00
|
|
|
if (rf_off == pwrpriv->change_rfpwrstate )
|
2013-05-19 04:28:07 +00:00
|
|
|
{
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->bpower_saving = true;
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E_LEVEL(_drv_info_, "nolinked power save enter\n");
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if (pwrpriv->ips_mode == IPS_LEVEL_2)
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->bkeepfwalive = true;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
rtw_ips_pwr_down(padapter);
|
|
|
|
pwrpriv->rf_pwrstate = rf_off;
|
2013-05-19 04:28:07 +00:00
|
|
|
}
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->bips_processing = false;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
_exit_pwrlock(&pwrpriv->lock);
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ips_leave(_adapter * padapter)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
|
|
|
|
struct security_priv* psecuritypriv=&(padapter->securitypriv);
|
|
|
|
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
|
|
|
int result = _SUCCESS;
|
|
|
|
sint keyid;
|
|
|
|
|
|
|
|
|
|
|
|
_enter_pwrlock(&pwrpriv->lock);
|
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if ((pwrpriv->rf_pwrstate == rf_off) &&(!pwrpriv->bips_processing))
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->bips_processing = true;
|
2013-05-08 21:45:39 +00:00
|
|
|
pwrpriv->change_rfpwrstate = rf_on;
|
|
|
|
pwrpriv->ips_leave_cnts++;
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("==>ips_leave cnts:%d\n",pwrpriv->ips_leave_cnts);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
if ((result = rtw_ips_pwr_up(padapter)) == _SUCCESS) {
|
|
|
|
pwrpriv->rf_pwrstate = rf_on;
|
|
|
|
}
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E_LEVEL(_drv_info_, "nolinked power save leave\n");
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if ((_WEP40_ == psecuritypriv->dot11PrivacyAlgrthm) ||(_WEP104_ == psecuritypriv->dot11PrivacyAlgrthm))
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("==>%s,channel(%d),processing(%x)\n",__func__,padapter->mlmeextpriv.cur_channel,pwrpriv->bips_processing);
|
2013-05-19 04:28:07 +00:00
|
|
|
set_channel_bwmode(padapter, padapter->mlmeextpriv.cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
|
2013-05-09 04:04:25 +00:00
|
|
|
for (keyid=0;keyid<4;keyid++){
|
|
|
|
if (pmlmepriv->key_mask & BIT(keyid)){
|
|
|
|
if (keyid == psecuritypriv->dot11PrivacyKeyIndex)
|
2013-05-08 21:45:39 +00:00
|
|
|
result=rtw_set_key(padapter,psecuritypriv, keyid, 1);
|
|
|
|
else
|
|
|
|
result=rtw_set_key(padapter,psecuritypriv, keyid, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("==> ips_leave.....LED(0x%08x)...\n",rtw_read32(padapter,0x4c));
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->bips_processing = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->bkeepfwalive = false;
|
|
|
|
pwrpriv->bpower_saving = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_exit_pwrlock(&pwrpriv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUTOSUSPEND
|
2013-05-19 04:28:07 +00:00
|
|
|
extern void autosuspend_enter(_adapter* padapter);
|
2013-05-08 21:45:39 +00:00
|
|
|
extern int autoresume_enter(_adapter* padapter);
|
|
|
|
#endif
|
|
|
|
|
2013-06-03 19:52:18 +00:00
|
|
|
static bool rtw_pwr_unassociated_idle(_adapter *adapter)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
_adapter *buddy = adapter->pbuddy_adapter;
|
|
|
|
struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
|
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
struct wifidirect_info *pwdinfo = &(adapter->wdinfo);
|
|
|
|
#ifdef CONFIG_IOCTL_CFG80211
|
|
|
|
struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &adapter->cfg80211_wdinfo;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
bool ret = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
if (adapter->pwrctrlpriv.ips_deny_time >= rtw_get_current_time()) {
|
2013-07-09 22:38:46 +00:00
|
|
|
/* DBG_88E("%s ips_deny_time\n", __func__); */
|
2013-05-08 21:45:39 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE|WIFI_SITE_MONITOR)
|
|
|
|
|| check_fwstate(pmlmepriv, WIFI_UNDER_LINKING|WIFI_UNDER_WPS)
|
|
|
|
|| check_fwstate(pmlmepriv, WIFI_AP_STATE)
|
|
|
|
|| check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE|WIFI_ADHOC_STATE)
|
|
|
|
#if defined(CONFIG_P2P) && defined(CONFIG_IOCTL_CFG80211) && defined(CONFIG_P2P_IPS)
|
|
|
|
|| pcfg80211_wdinfo->is_ro_ch
|
|
|
|
#elif defined(CONFIG_P2P)
|
|
|
|
|| !rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* consider buddy, if exist */
|
|
|
|
if (buddy) {
|
|
|
|
struct mlme_priv *b_pmlmepriv = &(buddy->mlmepriv);
|
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
struct wifidirect_info *b_pwdinfo = &(buddy->wdinfo);
|
|
|
|
#ifdef CONFIG_IOCTL_CFG80211
|
|
|
|
struct cfg80211_wifidirect_info *b_pcfg80211_wdinfo = &buddy->cfg80211_wdinfo;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (check_fwstate(b_pmlmepriv, WIFI_ASOC_STATE|WIFI_SITE_MONITOR)
|
|
|
|
|| check_fwstate(b_pmlmepriv, WIFI_UNDER_LINKING|WIFI_UNDER_WPS)
|
|
|
|
|| check_fwstate(b_pmlmepriv, WIFI_AP_STATE)
|
|
|
|
|| check_fwstate(b_pmlmepriv, WIFI_ADHOC_MASTER_STATE|WIFI_ADHOC_STATE)
|
|
|
|
#if defined(CONFIG_P2P) && defined(CONFIG_IOCTL_CFG80211) && defined(CONFIG_P2P_IPS)
|
|
|
|
|| b_pcfg80211_wdinfo->is_ro_ch
|
|
|
|
#elif defined(CONFIG_P2P)
|
|
|
|
|| !rtw_p2p_chk_state(b_pwdinfo, P2P_STATE_NONE)
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
2013-05-26 03:02:10 +00:00
|
|
|
ret = true;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
exit:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined (PLATFORM_LINUX)||defined (PLATFORM_FREEBSD)
|
|
|
|
void rtw_ps_processor(_adapter*padapter)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_P2P */
|
2013-05-08 21:45:39 +00:00
|
|
|
struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
|
|
|
|
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
|
|
|
#ifdef SUPPORT_HW_RFOFF_DETECTED
|
|
|
|
rt_rf_power_state rfpwrstate;
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* SUPPORT_HW_RFOFF_DETECTED */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->ps_processing = true;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#ifdef SUPPORT_HW_RFOFF_DETECTED
|
2013-05-26 03:02:10 +00:00
|
|
|
if (pwrpriv->bips_processing == true)
|
2013-05-08 21:45:39 +00:00
|
|
|
goto exit;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* DBG_88E("==> fw report state(0x%x)\n",rtw_read8(padapter,0x1ca)); */
|
2013-05-19 04:28:07 +00:00
|
|
|
if (padapter->pwrctrlpriv.bHWPwrPindetect)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_AUTOSUSPEND
|
2013-05-09 04:04:25 +00:00
|
|
|
if (padapter->registrypriv.usbss_enable)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-09 04:04:25 +00:00
|
|
|
if (pwrpriv->rf_pwrstate == rf_on)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-26 03:02:10 +00:00
|
|
|
if (padapter->net_closed == true)
|
|
|
|
pwrpriv->ps_flag = true;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
rfpwrstate = RfOnOffDetect(padapter);
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("@@@@- #1 %s==> rfstate:%s\n",__func__,(rfpwrstate==rf_on)?"rf_on":"rf_off");
|
2013-05-09 04:04:25 +00:00
|
|
|
if (rfpwrstate!= pwrpriv->rf_pwrstate)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-09 04:04:25 +00:00
|
|
|
if (rfpwrstate == rf_off)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
pwrpriv->change_rfpwrstate = rf_off;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->bkeepfwalive = true;
|
|
|
|
pwrpriv->brfoffbyhw = true;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
|
|
|
autosuspend_enter(padapter);
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-19 04:28:07 +00:00
|
|
|
}
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
else
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_AUTOSUSPEND */
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
rfpwrstate = RfOnOffDetect(padapter);
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("@@@@- #2 %s==> rfstate:%s\n",__func__,(rfpwrstate==rf_on)?"rf_on":"rf_off");
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if (rfpwrstate!= pwrpriv->rf_pwrstate)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-09 04:04:25 +00:00
|
|
|
if (rfpwrstate == rf_off)
|
2013-05-19 04:28:07 +00:00
|
|
|
{
|
|
|
|
pwrpriv->change_rfpwrstate = rf_off;
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->brfoffbyhw = true;
|
|
|
|
padapter->bCardDisableWOHSM = true;
|
2013-05-19 04:28:07 +00:00
|
|
|
rtw_hw_suspend(padapter );
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pwrpriv->change_rfpwrstate = rf_on;
|
2013-05-19 04:28:07 +00:00
|
|
|
rtw_hw_resume(padapter );
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("current rf_pwrstate(%s)\n",(pwrpriv->rf_pwrstate == rf_off)?"rf_off":"rf_on");
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-19 04:28:07 +00:00
|
|
|
pwrpriv->pwr_state_check_cnts ++;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* SUPPORT_HW_RFOFF_DETECTED */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
if (pwrpriv->ips_mode_req == IPS_NONE
|
|
|
|
#ifdef CONFIG_CONCURRENT_MODE
|
|
|
|
|| padapter->pbuddy_adapter->pwrctrlpriv.ips_mode_req == IPS_NONE
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
goto exit;
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if (rtw_pwr_unassociated_idle(padapter) == false)
|
2013-05-08 21:45:39 +00:00
|
|
|
goto exit;
|
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if ((pwrpriv->rf_pwrstate == rf_on) && ((pwrpriv->pwr_state_check_cnts%4)==0))
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("==>%s .fw_state(%x)\n",__func__,get_fwstate(pmlmepriv));
|
2013-05-08 21:45:39 +00:00
|
|
|
#if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND)
|
|
|
|
#else
|
|
|
|
pwrpriv->change_rfpwrstate = rf_off;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_AUTOSUSPEND
|
2013-05-09 04:04:25 +00:00
|
|
|
if (padapter->registrypriv.usbss_enable)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-19 04:28:07 +00:00
|
|
|
if (pwrpriv->bHWPwrPindetect)
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->bkeepfwalive = true;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if (padapter->net_closed == true)
|
|
|
|
pwrpriv->ps_flag = true;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND)
|
2013-05-26 03:02:10 +00:00
|
|
|
if (true==pwrpriv->bInternalAutoSuspend) {
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("<==%s .pwrpriv->bInternalAutoSuspend)(%x)\n",__func__,pwrpriv->bInternalAutoSuspend);
|
2013-05-08 21:45:39 +00:00
|
|
|
} else {
|
|
|
|
pwrpriv->change_rfpwrstate = rf_off;
|
2013-05-26 03:02:10 +00:00
|
|
|
padapter->bCardDisableWOHSM = true;
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("<==%s .pwrpriv->bInternalAutoSuspend)(%x) call autosuspend_enter\n",__func__,pwrpriv->bInternalAutoSuspend);
|
2013-05-08 21:45:39 +00:00
|
|
|
autosuspend_enter(padapter);
|
2013-05-19 04:28:07 +00:00
|
|
|
}
|
2013-05-08 21:45:39 +00:00
|
|
|
#else
|
2013-05-26 03:02:10 +00:00
|
|
|
padapter->bCardDisableWOHSM = true;
|
2013-05-08 21:45:39 +00:00
|
|
|
autosuspend_enter(padapter);
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND) */
|
2013-05-19 04:28:07 +00:00
|
|
|
}
|
2013-05-09 04:04:25 +00:00
|
|
|
else if (pwrpriv->bHWPwrPindetect)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_AUTOSUSPEND */
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
#if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND)
|
|
|
|
pwrpriv->change_rfpwrstate = rf_off;
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND) */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_IPS
|
2013-05-19 04:28:07 +00:00
|
|
|
ips_enter(padapter);
|
2013-05-08 21:45:39 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit:
|
|
|
|
rtw_set_pwr_state_check_timer(&padapter->pwrctrlpriv);
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->ps_processing = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pwr_state_check_handler(void *FunctionContext);
|
|
|
|
void pwr_state_check_handler(void *FunctionContext)
|
|
|
|
{
|
|
|
|
_adapter *padapter = (_adapter *)FunctionContext;
|
|
|
|
rtw_ps_cmd(padapter);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_LPS
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Parameters
|
|
|
|
* padapter
|
|
|
|
* pslv power state level, only could be PS_STATE_S0 ~ PS_STATE_S4
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void rtw_set_rpwm(PADAPTER padapter, u8 pslv)
|
|
|
|
{
|
|
|
|
u8 rpwm;
|
|
|
|
struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
|
|
|
pslv = PS_STATE(pslv);
|
|
|
|
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if (true == pwrpriv->btcoex_rfon)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
if (pslv < PS_STATE_S4)
|
|
|
|
pslv = PS_STATE_S3;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_LPS_RPWM_TIMER
|
2013-05-26 03:02:10 +00:00
|
|
|
if (pwrpriv->brpwmtimeout == true)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s: RPWM timeout, force to set RPWM(0x%02X) again!\n", __func__, pslv);
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
else
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_LPS_RPWM_TIMER */
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
if ( (pwrpriv->rpwm == pslv)
|
|
|
|
#ifdef CONFIG_LPS_LCLK
|
|
|
|
|| ((pwrpriv->rpwm >= PS_STATE_S2)&&(pslv >= PS_STATE_S2))
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_,_drv_err_,
|
2013-05-09 16:23:32 +00:00
|
|
|
("%s: Already set rpwm[0x%02X], new=0x%02X!\n", __func__, pwrpriv->rpwm, pslv));
|
2013-05-08 21:45:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if ((padapter->bSurpriseRemoved == true) ||
|
|
|
|
(padapter->hw_init_completed == false))
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
|
|
|
|
("%s: SurpriseRemoved(%d) hw_init_completed(%d)\n",
|
2013-05-09 16:23:32 +00:00
|
|
|
__func__, padapter->bSurpriseRemoved, padapter->hw_init_completed));
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
pwrpriv->cpwm = PS_STATE_S4;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if (padapter->bDriverStopped == true)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
|
2013-05-09 16:23:32 +00:00
|
|
|
("%s: change power state(0x%02X) when DriverStopped\n", __func__, pslv));
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
if (pslv < PS_STATE_S2) {
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
|
2013-05-09 16:23:32 +00:00
|
|
|
("%s: Reject to enter PS_STATE(0x%02X) lower than S2 when DriverStopped!!\n", __func__, pslv));
|
2013-05-08 21:45:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpwm = pslv | pwrpriv->tog;
|
|
|
|
#ifdef CONFIG_LPS_LCLK
|
2013-07-09 22:38:46 +00:00
|
|
|
/* only when from PS_STATE S0/S1 to S2 and higher needs ACK */
|
2013-05-08 21:45:39 +00:00
|
|
|
if ((pwrpriv->cpwm < PS_STATE_S2) && (pslv >= PS_STATE_S2))
|
|
|
|
rpwm |= PS_ACK;
|
|
|
|
#endif
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
|
|
|
|
("rtw_set_rpwm: rpwm=0x%02x cpwm=0x%02x\n", rpwm, pwrpriv->cpwm));
|
|
|
|
|
|
|
|
pwrpriv->rpwm = pslv;
|
|
|
|
|
|
|
|
#ifdef CONFIG_LPS_RPWM_TIMER
|
|
|
|
if (rpwm & PS_ACK)
|
|
|
|
_set_timer(&pwrpriv->pwr_rpwm_timer, LPS_RPWM_WAIT_MS);
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_LPS_RPWM_TIMER */
|
2013-05-08 21:45:39 +00:00
|
|
|
rtw_hal_set_hwreg(padapter, HW_VAR_SET_RPWM, (u8 *)(&rpwm));
|
|
|
|
|
|
|
|
pwrpriv->tog += 0x80;
|
|
|
|
|
|
|
|
#ifdef CONFIG_LPS_LCLK
|
2013-07-09 22:38:46 +00:00
|
|
|
/* No LPS 32K, No Ack */
|
2013-05-08 21:45:39 +00:00
|
|
|
if (!(rpwm & PS_ACK))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
pwrpriv->cpwm = pslv;
|
|
|
|
}
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 PS_RDY_CHECK(_adapter * padapter);
|
|
|
|
u8 PS_RDY_CHECK(_adapter * padapter)
|
|
|
|
{
|
|
|
|
u32 curr_time, delta_time;
|
|
|
|
struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
|
|
|
|
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
|
|
|
|
|
|
|
|
2013-05-19 04:28:07 +00:00
|
|
|
curr_time = rtw_get_current_time();
|
2013-05-08 21:45:39 +00:00
|
|
|
delta_time = curr_time -pwrpriv->DelayLPSLastTimeStamp;
|
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if (delta_time < LPS_DELAY_TIME)
|
2013-05-19 04:28:07 +00:00
|
|
|
{
|
2013-05-26 03:02:10 +00:00
|
|
|
return false;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if ((check_fwstate(pmlmepriv, _FW_LINKED) == false) ||
|
|
|
|
(check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true) ||
|
|
|
|
(check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) ||
|
|
|
|
(check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) ||
|
|
|
|
(check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) )
|
|
|
|
return false;
|
2013-05-08 21:45:39 +00:00
|
|
|
#ifdef CONFIG_WOWLAN
|
2013-05-26 03:02:10 +00:00
|
|
|
if (true == pwrpriv->bInSuspend && pwrpriv->wowlan_mode)
|
|
|
|
return true;
|
2013-05-08 21:45:39 +00:00
|
|
|
else
|
2013-05-26 03:02:10 +00:00
|
|
|
return false;
|
2013-05-08 21:45:39 +00:00
|
|
|
#else
|
2013-05-26 03:02:10 +00:00
|
|
|
if (true == pwrpriv->bInSuspend )
|
|
|
|
return false;
|
2013-05-08 21:45:39 +00:00
|
|
|
#endif
|
2013-05-26 03:02:10 +00:00
|
|
|
if ( (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) && (padapter->securitypriv.binstallGrpkey == false) )
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("Group handshake still in progress !!!\n");
|
2013-05-26 03:02:10 +00:00
|
|
|
return false;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
#ifdef CONFIG_IOCTL_CFG80211
|
|
|
|
if (!rtw_cfg80211_pwr_mgmt(padapter))
|
2013-05-26 03:02:10 +00:00
|
|
|
return false;
|
2013-05-19 04:28:07 +00:00
|
|
|
#endif
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
return true;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void rtw_set_ps_mode(PADAPTER padapter, u8 ps_mode, u8 smart_ps, u8 bcn_ant_mode)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
|
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_P2P */
|
2013-05-08 21:45:39 +00:00
|
|
|
#ifdef CONFIG_TDLS
|
|
|
|
struct sta_priv *pstapriv = &padapter->stapriv;
|
|
|
|
_irqL irqL;
|
|
|
|
int i, j;
|
|
|
|
_list *plist, *phead;
|
|
|
|
struct sta_info *ptdls_sta;
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_TDLS */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
|
|
|
|
("%s: PowerMode=%d Smart_PS=%d\n",
|
2013-05-09 16:23:32 +00:00
|
|
|
__func__, ps_mode, smart_ps));
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if (ps_mode > PM_Card_Disable) {
|
2013-05-08 21:45:39 +00:00
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_,_drv_err_,("ps_mode:%d error\n", ps_mode));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pwrpriv->pwr_mode == ps_mode)
|
|
|
|
{
|
|
|
|
if (PS_MODE_ACTIVE == ps_mode) return;
|
|
|
|
|
|
|
|
if ((pwrpriv->smart_ps == smart_ps) &&
|
|
|
|
(pwrpriv->bcn_ant_mode == bcn_ant_mode))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_LPS_LCLK
|
|
|
|
_enter_pwrlock(&pwrpriv->lock);
|
|
|
|
#endif
|
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) */
|
2013-05-09 04:04:25 +00:00
|
|
|
if (ps_mode == PS_MODE_ACTIVE)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_P2P_PS
|
2013-05-09 04:04:25 +00:00
|
|
|
if (pwdinfo->opp_ps == 0)
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_P2P_PS */
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("rtw_set_ps_mode: Leave 802.11 power save\n");
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_TDLS
|
|
|
|
_enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
|
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
for (i=0; i< NUM_STA; i++)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
phead = &(pstapriv->sta_hash[i]);
|
|
|
|
plist = get_next(phead);
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
while ((rtw_end_of_queue_search(phead, plist)) == false)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
ptdls_sta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
|
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if ( ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE )
|
2013-05-08 21:45:39 +00:00
|
|
|
issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta, 0);
|
|
|
|
plist = get_next(plist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_TDLS */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
pwrpriv->pwr_mode = ps_mode;
|
|
|
|
rtw_set_rpwm(padapter, PS_STATE_S4);
|
|
|
|
rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode));
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->bFwCurrentInPSMode = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (PS_RDY_CHECK(padapter)
|
|
|
|
#ifdef CONFIG_BT_COEXIST
|
2013-05-26 03:02:10 +00:00
|
|
|
|| (BT_1Ant(padapter) == true)
|
2013-05-08 21:45:39 +00:00
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s: Enter 802.11 power save\n", __func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_TDLS
|
|
|
|
_enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
|
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
for (i=0; i< NUM_STA; i++)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
phead = &(pstapriv->sta_hash[i]);
|
|
|
|
plist = get_next(phead);
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
while ((rtw_end_of_queue_search(phead, plist)) == false)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
ptdls_sta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
|
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if ( ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE )
|
2013-05-08 21:45:39 +00:00
|
|
|
issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta, 1);
|
|
|
|
plist = get_next(plist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_TDLS */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->bFwCurrentInPSMode = true;
|
2013-05-08 21:45:39 +00:00
|
|
|
pwrpriv->pwr_mode = ps_mode;
|
|
|
|
pwrpriv->smart_ps = smart_ps;
|
|
|
|
pwrpriv->bcn_ant_mode = bcn_ant_mode;
|
|
|
|
rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode));
|
|
|
|
|
|
|
|
#ifdef CONFIG_P2P_PS
|
2013-07-09 22:38:46 +00:00
|
|
|
/* Set CTWindow after LPS */
|
2013-05-09 04:04:25 +00:00
|
|
|
if (pwdinfo->opp_ps == 1)
|
2013-05-08 21:45:39 +00:00
|
|
|
p2p_ps_wk_cmd(padapter, P2P_PS_ENABLE, 0);
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_P2P_PS */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_LPS_LCLK
|
|
|
|
if (pwrpriv->alives == 0)
|
|
|
|
rtw_set_rpwm(padapter, PS_STATE_S0);
|
|
|
|
#else
|
|
|
|
rtw_set_rpwm(padapter, PS_STATE_S2);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_LPS_LCLK
|
|
|
|
_exit_pwrlock(&pwrpriv->lock);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return:
|
|
|
|
* 0: Leave OK
|
|
|
|
* -1: Timeout
|
|
|
|
* -2: Other error
|
|
|
|
*/
|
|
|
|
s32 LPS_RF_ON_check(PADAPTER padapter, u32 delay_ms)
|
|
|
|
{
|
|
|
|
u32 start_time;
|
2013-05-26 03:02:10 +00:00
|
|
|
u8 bAwake = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
s32 err = 0;
|
|
|
|
|
|
|
|
|
|
|
|
start_time = rtw_get_current_time();
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
rtw_hal_get_hwreg(padapter, HW_VAR_FWLPS_RF_ON, &bAwake);
|
2013-05-26 03:02:10 +00:00
|
|
|
if (true == bAwake)
|
2013-05-08 21:45:39 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if (true == padapter->bSurpriseRemoved)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
err = -2;
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s: device surprise removed!!\n", __func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rtw_get_passing_time_ms(start_time) > delay_ms)
|
|
|
|
{
|
|
|
|
err = -1;
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s: Wait for FW LPS leave more than %u ms!!!\n", __func__, delay_ms);
|
2013-05-08 21:45:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
rtw_usleep_os(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* */
|
|
|
|
/* Description: */
|
|
|
|
/* Enter the leisure power save mode. */
|
|
|
|
/* */
|
2013-05-08 21:45:39 +00:00
|
|
|
void LPS_Enter(PADAPTER padapter)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
|
|
|
|
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
|
|
|
_adapter *buddy = padapter->pbuddy_adapter;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* DBG_88E("+LeisurePSEnter\n"); */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_CONCURRENT_MODE
|
|
|
|
if (padapter->iface_type != IFACE_PORT0)
|
|
|
|
return; /* Skip power saving for concurrent mode port 1*/
|
|
|
|
|
|
|
|
/* consider buddy, if exist */
|
|
|
|
if (buddy) {
|
|
|
|
struct mlme_priv *b_pmlmepriv = &(buddy->mlmepriv);
|
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
struct wifidirect_info *b_pwdinfo = &(buddy->wdinfo);
|
2013-05-19 04:28:07 +00:00
|
|
|
#ifdef CONFIG_IOCTL_CFG80211
|
2013-05-08 21:45:39 +00:00
|
|
|
struct cfg80211_wifidirect_info *b_pcfg80211_wdinfo = &buddy->cfg80211_wdinfo;
|
|
|
|
#endif
|
|
|
|
#endif
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
if (check_fwstate(b_pmlmepriv, WIFI_ASOC_STATE|WIFI_SITE_MONITOR)
|
|
|
|
|| check_fwstate(b_pmlmepriv, WIFI_UNDER_LINKING|WIFI_UNDER_WPS)
|
|
|
|
|| check_fwstate(b_pmlmepriv, WIFI_AP_STATE)
|
|
|
|
|| check_fwstate(b_pmlmepriv, WIFI_ADHOC_MASTER_STATE|WIFI_ADHOC_STATE)
|
|
|
|
#if defined(CONFIG_P2P) && defined(CONFIG_IOCTL_CFG80211) && defined(CONFIG_P2P_IPS)
|
|
|
|
|| b_pcfg80211_wdinfo->is_ro_ch
|
|
|
|
#elif defined(CONFIG_P2P)
|
|
|
|
|| !rtw_p2p_chk_state(b_pwdinfo, P2P_STATE_NONE)
|
|
|
|
#endif
|
|
|
|
|| rtw_is_scan_deny(buddy)
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if (PS_RDY_CHECK(padapter) == false)
|
2013-05-08 21:45:39 +00:00
|
|
|
return;
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if (true == pwrpriv->bLeisurePs)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-07-09 22:38:46 +00:00
|
|
|
/* Idle for a while if we connect to AP a while ago. */
|
|
|
|
if (pwrpriv->LpsIdleCount >= 2) /* 4 Sec */
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-09 04:04:25 +00:00
|
|
|
if (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->bpower_saving = true;
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s smart_ps:%d\n", __func__, pwrpriv->smart_ps);
|
2013-07-09 22:38:46 +00:00
|
|
|
/* For Tenda W311R IOT issue */
|
2013-05-08 21:45:39 +00:00
|
|
|
rtw_set_ps_mode(padapter, pwrpriv->power_mgnt, pwrpriv->smart_ps, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pwrpriv->LpsIdleCount++;
|
|
|
|
}
|
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* DBG_88E("-LeisurePSEnter\n"); */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
}
|
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* */
|
|
|
|
/* Description: */
|
|
|
|
/* Leave the leisure power save mode. */
|
|
|
|
/* */
|
2013-05-08 21:45:39 +00:00
|
|
|
void LPS_Leave(PADAPTER padapter)
|
|
|
|
{
|
|
|
|
#define LPS_LEAVE_TIMEOUT_MS 100
|
|
|
|
|
|
|
|
struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
|
|
|
|
u32 start_time;
|
2013-05-26 03:02:10 +00:00
|
|
|
u8 bAwake = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
|
|
|
#ifdef CONFIG_CONCURRENT_MODE
|
|
|
|
if (padapter->iface_type != IFACE_PORT0)
|
|
|
|
return; /* Skip power saving for concurrent mode port 1*/
|
|
|
|
#endif
|
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* DBG_88E("+LeisurePSLeave\n"); */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
if (pwrpriv->bLeisurePs)
|
|
|
|
{
|
2013-05-09 04:04:25 +00:00
|
|
|
if (pwrpriv->pwr_mode != PS_MODE_ACTIVE)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0);
|
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
|
2013-05-08 21:45:39 +00:00
|
|
|
LPS_RF_ON_check(padapter, LPS_LEAVE_TIMEOUT_MS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->bpower_saving = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* DBG_88E("-LeisurePSLeave\n"); */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* */
|
|
|
|
/* Description: Leave all power save mode: LPS, FwLPS, IPS if needed. */
|
|
|
|
/* Move code to function by tynli. 2010.03.26. */
|
|
|
|
/* */
|
2013-05-27 03:51:56 +00:00
|
|
|
void LeaveAllPowerSaveMode(PADAPTER Adapter)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
|
|
|
|
u8 enqueue = 0;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
|
2013-07-09 22:38:46 +00:00
|
|
|
{ /* connect */
|
2013-05-08 21:45:39 +00:00
|
|
|
#ifdef CONFIG_LPS_LCLK
|
|
|
|
enqueue = 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_P2P_PS
|
|
|
|
p2p_ps_wk_cmd(Adapter, P2P_PS_DISABLE, enqueue);
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_P2P_PS */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_LPS
|
|
|
|
rtw_lps_ctrl_wk_cmd(Adapter, LPS_CTRL_LEAVE, enqueue);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_LPS_LCLK
|
|
|
|
LPS_Leave_check(Adapter);
|
2013-05-19 04:28:07 +00:00
|
|
|
#endif
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-09 04:04:25 +00:00
|
|
|
if (Adapter->pwrctrlpriv.rf_pwrstate== rf_off)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_AUTOSUSPEND
|
2013-05-09 04:04:25 +00:00
|
|
|
if (Adapter->registrypriv.usbss_enable)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
#if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
|
|
|
|
usb_disable_autosuspend(adapter_to_dvobj(Adapter)->pusbdev);
|
|
|
|
#elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22) && LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,34))
|
2013-07-09 22:38:46 +00:00
|
|
|
adapter_to_dvobj(Adapter)->pusbdev->autosuspend_disabled = Adapter->bDisableAutosuspend;/* autosuspend disabled by the user */
|
2013-05-08 21:45:39 +00:00
|
|
|
#endif
|
|
|
|
}
|
2013-05-26 17:17:22 +00:00
|
|
|
else
|
2013-05-08 21:45:39 +00:00
|
|
|
#endif
|
2013-05-26 17:17:22 +00:00
|
|
|
{
|
|
|
|
#if defined(CONFIG_PLATFORM_SPRD) && defined(CONFIG_RTL8188E)
|
|
|
|
#ifdef CONFIG_IPS
|
|
|
|
if (false == ips_leave(Adapter))
|
|
|
|
{
|
|
|
|
DBG_88E("======> ips_leave fail.............\n");
|
|
|
|
}
|
|
|
|
#endif
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_PLATFORM_SPRD && CONFIG_RTL8188E */
|
2013-05-26 17:17:22 +00:00
|
|
|
}
|
2013-05-19 04:28:07 +00:00
|
|
|
}
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_LPS_LCLK
|
|
|
|
void LPS_Leave_check(
|
|
|
|
PADAPTER padapter)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrpriv;
|
|
|
|
u32 start_time;
|
|
|
|
u8 bReady;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
|
|
|
pwrpriv = &padapter->pwrctrlpriv;
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
bReady = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
start_time = rtw_get_current_time();
|
|
|
|
|
|
|
|
rtw_yield_os();
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
while (1)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
_enter_pwrlock(&pwrpriv->lock);
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if ((padapter->bSurpriseRemoved == true)
|
|
|
|
|| (padapter->hw_init_completed == false)
|
2013-05-08 21:45:39 +00:00
|
|
|
#ifdef CONFIG_USB_HCI
|
2013-05-26 03:02:10 +00:00
|
|
|
|| (padapter->bDriverStopped== true)
|
2013-05-08 21:45:39 +00:00
|
|
|
#endif
|
|
|
|
|| (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
|
|
|
|
)
|
|
|
|
{
|
2013-05-26 03:02:10 +00:00
|
|
|
bReady = true;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_exit_pwrlock(&pwrpriv->lock);
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if (true == bReady)
|
2013-05-08 21:45:39 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if (rtw_get_passing_time_ms(start_time)>100)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("Wait for cpwm event than 100 ms!!!\n");
|
2013-05-08 21:45:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
rtw_msleep_os(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Caller:ISR handler...
|
|
|
|
*
|
|
|
|
* This will be called when CPWM interrupt is up.
|
|
|
|
*
|
|
|
|
* using to update cpwn of drv; and drv willl make a decision to up or down pwr level
|
|
|
|
*/
|
|
|
|
void cpwm_int_hdl(
|
|
|
|
PADAPTER padapter,
|
|
|
|
struct reportpwrstate_parm *preportpwrstate)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrpriv;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
|
|
|
pwrpriv = &padapter->pwrctrlpriv;
|
|
|
|
_enter_pwrlock(&pwrpriv->lock);
|
|
|
|
|
|
|
|
#ifdef CONFIG_LPS_RPWM_TIMER
|
|
|
|
if (pwrpriv->rpwm < PS_STATE_S2)
|
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s: Redundant CPWM Int. RPWM=0x%02X CPWM=0x%02x\n", __func__, pwrpriv->rpwm, pwrpriv->cpwm);
|
2013-05-08 21:45:39 +00:00
|
|
|
_exit_pwrlock(&pwrpriv->lock);
|
|
|
|
goto exit;
|
|
|
|
}
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_LPS_RPWM_TIMER */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
pwrpriv->cpwm = PS_STATE(preportpwrstate->state);
|
|
|
|
pwrpriv->cpwm_tog = preportpwrstate->state & PS_TOGGLE;
|
|
|
|
|
|
|
|
if (pwrpriv->cpwm >= PS_STATE_S2)
|
|
|
|
{
|
|
|
|
if (pwrpriv->alives & CMD_ALIVE)
|
|
|
|
_rtw_up_sema(&padapter->cmdpriv.cmd_queue_sema);
|
|
|
|
|
|
|
|
if (pwrpriv->alives & XMIT_ALIVE)
|
|
|
|
_rtw_up_sema(&padapter->xmitpriv.xmit_sema);
|
|
|
|
}
|
|
|
|
|
|
|
|
_exit_pwrlock(&pwrpriv->lock);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
|
|
|
|
("cpwm_int_hdl: cpwm=0x%02x\n", pwrpriv->cpwm));
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cpwm_event_callback(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrpriv = container_of(work, struct pwrctrl_priv, cpwm_event);
|
|
|
|
_adapter *adapter = container_of(pwrpriv, _adapter, pwrctrlpriv);
|
|
|
|
struct reportpwrstate_parm report;
|
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* DBG_88E("%s\n",__func__); */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
report.state = PS_STATE_S2;
|
|
|
|
cpwm_int_hdl(adapter, &report);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_LPS_RPWM_TIMER
|
|
|
|
static void rpwmtimeout_workitem_callback(struct work_struct *work)
|
|
|
|
{
|
|
|
|
PADAPTER padapter;
|
|
|
|
struct pwrctrl_priv *pwrpriv;
|
|
|
|
|
|
|
|
|
|
|
|
pwrpriv = container_of(work, struct pwrctrl_priv, rpwmtimeoutwi);
|
|
|
|
padapter = container_of(pwrpriv, _adapter, pwrctrlpriv);
|
2013-07-09 22:38:46 +00:00
|
|
|
/* DBG_88E("+%s: rpwm=0x%02X cpwm=0x%02X\n", __func__, pwrpriv->rpwm, pwrpriv->cpwm); */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
_enter_pwrlock(&pwrpriv->lock);
|
|
|
|
if ((pwrpriv->rpwm == pwrpriv->cpwm) || (pwrpriv->cpwm >= PS_STATE_S2))
|
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s: rpwm=0x%02X cpwm=0x%02X CPWM done!\n", __func__, pwrpriv->rpwm, pwrpriv->cpwm);
|
2013-05-08 21:45:39 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
_exit_pwrlock(&pwrpriv->lock);
|
|
|
|
|
|
|
|
if (rtw_read8(padapter, 0x100) != 0xEA)
|
|
|
|
{
|
|
|
|
#if 1
|
|
|
|
struct reportpwrstate_parm report;
|
|
|
|
|
|
|
|
report.state = PS_STATE_S2;
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("\n%s: FW already leave 32K!\n\n", __func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
cpwm_int_hdl(padapter, &report);
|
|
|
|
#else
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("\n%s: FW already leave 32K!\n\n", __func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
cpwm_event_callback(&pwrpriv->cpwm_event);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_enter_pwrlock(&pwrpriv->lock);
|
|
|
|
|
|
|
|
if ((pwrpriv->rpwm == pwrpriv->cpwm) || (pwrpriv->cpwm >= PS_STATE_S2))
|
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s: cpwm=%d, nothing to do!\n", __func__, pwrpriv->cpwm);
|
2013-05-08 21:45:39 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->brpwmtimeout = true;
|
2013-05-08 21:45:39 +00:00
|
|
|
rtw_set_rpwm(padapter, pwrpriv->rpwm);
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->brpwmtimeout = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
exit:
|
|
|
|
_exit_pwrlock(&pwrpriv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is a timer handler, can't do any IO in it.
|
|
|
|
*/
|
|
|
|
static void pwr_rpwm_timeout_handler(void *FunctionContext)
|
|
|
|
{
|
|
|
|
PADAPTER padapter;
|
|
|
|
struct pwrctrl_priv *pwrpriv;
|
|
|
|
|
|
|
|
|
|
|
|
padapter = (PADAPTER)FunctionContext;
|
|
|
|
pwrpriv = &padapter->pwrctrlpriv;
|
2013-07-09 22:38:46 +00:00
|
|
|
/* DBG_88E("+%s: rpwm=0x%02X cpwm=0x%02X\n", __func__, pwrpriv->rpwm, pwrpriv->cpwm); */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
if ((pwrpriv->rpwm == pwrpriv->cpwm) || (pwrpriv->cpwm >= PS_STATE_S2))
|
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("+%s: cpwm=%d, nothing to do!\n", __func__, pwrpriv->cpwm);
|
2013-05-08 21:45:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_set_workitem(&pwrpriv->rpwmtimeoutwi);
|
|
|
|
}
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_LPS_RPWM_TIMER */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
__inline static void register_task_alive(struct pwrctrl_priv *pwrctrl, u32 tag)
|
|
|
|
{
|
|
|
|
pwrctrl->alives |= tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
__inline static void unregister_task_alive(struct pwrctrl_priv *pwrctrl, u32 tag)
|
|
|
|
{
|
|
|
|
pwrctrl->alives &= ~tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Caller: rtw_xmit_thread
|
2013-05-19 04:28:07 +00:00
|
|
|
*
|
2013-05-08 21:45:39 +00:00
|
|
|
* Check if the fw_pwrstate is okay for xmit.
|
|
|
|
* If not (cpwm is less than S3), then the sub-routine
|
2013-05-19 04:28:07 +00:00
|
|
|
* will raise the cpwm to be greater than or equal to S3.
|
2013-05-08 21:45:39 +00:00
|
|
|
*
|
|
|
|
* Calling Context: Passive
|
2013-05-19 04:28:07 +00:00
|
|
|
*
|
2013-05-08 21:45:39 +00:00
|
|
|
* Return Value:
|
|
|
|
* _SUCCESS rtw_xmit_thread can write fifo/txcmd afterwards.
|
|
|
|
* _FAIL rtw_xmit_thread can not do anything.
|
|
|
|
*/
|
|
|
|
s32 rtw_register_tx_alive(PADAPTER padapter)
|
|
|
|
{
|
|
|
|
s32 res;
|
|
|
|
struct pwrctrl_priv *pwrctrl;
|
|
|
|
u8 pslv;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
|
|
|
res = _SUCCESS;
|
|
|
|
pwrctrl = &padapter->pwrctrlpriv;
|
|
|
|
#ifdef CONFIG_BT_COEXIST
|
2013-05-26 03:02:10 +00:00
|
|
|
if (true == padapter->pwrctrlpriv.btcoex_rfon)
|
2013-05-08 21:45:39 +00:00
|
|
|
pslv = PS_STATE_S3;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
pslv = PS_STATE_S2;
|
|
|
|
}
|
|
|
|
|
|
|
|
_enter_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
register_task_alive(pwrctrl, XMIT_ALIVE);
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if (pwrctrl->bFwCurrentInPSMode == true)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
|
|
|
|
("rtw_register_tx_alive: cpwm=0x%02x alives=0x%08x\n",
|
|
|
|
pwrctrl->cpwm, pwrctrl->alives));
|
|
|
|
|
|
|
|
if (pwrctrl->cpwm < pslv)
|
|
|
|
{
|
|
|
|
if (pwrctrl->cpwm < PS_STATE_S2)
|
|
|
|
res = _FAIL;
|
|
|
|
if (pwrctrl->rpwm < pslv)
|
|
|
|
rtw_set_rpwm(padapter, pslv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_exit_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
|
2013-05-19 04:28:07 +00:00
|
|
|
return res;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Caller: rtw_cmd_thread
|
|
|
|
*
|
|
|
|
* Check if the fw_pwrstate is okay for issuing cmd.
|
|
|
|
* If not (cpwm should be is less than S2), then the sub-routine
|
|
|
|
* will raise the cpwm to be greater than or equal to S2.
|
|
|
|
*
|
|
|
|
* Calling Context: Passive
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* _SUCCESS rtw_cmd_thread can issue cmds to firmware afterwards.
|
|
|
|
* _FAIL rtw_cmd_thread can not do anything.
|
|
|
|
*/
|
|
|
|
s32 rtw_register_cmd_alive(PADAPTER padapter)
|
|
|
|
{
|
|
|
|
s32 res;
|
|
|
|
struct pwrctrl_priv *pwrctrl;
|
|
|
|
u8 pslv;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
|
|
|
res = _SUCCESS;
|
|
|
|
pwrctrl = &padapter->pwrctrlpriv;
|
|
|
|
#ifdef CONFIG_BT_COEXIST
|
2013-05-26 03:02:10 +00:00
|
|
|
if (true == padapter->pwrctrlpriv.btcoex_rfon)
|
2013-05-08 21:45:39 +00:00
|
|
|
pslv = PS_STATE_S3;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
pslv = PS_STATE_S2;
|
|
|
|
}
|
|
|
|
|
|
|
|
_enter_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
register_task_alive(pwrctrl, CMD_ALIVE);
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if (pwrctrl->bFwCurrentInPSMode == true)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_info_,
|
|
|
|
("rtw_register_cmd_alive: cpwm=0x%02x alives=0x%08x\n",
|
|
|
|
pwrctrl->cpwm, pwrctrl->alives));
|
|
|
|
|
|
|
|
if (pwrctrl->cpwm < pslv)
|
|
|
|
{
|
|
|
|
if (pwrctrl->cpwm < PS_STATE_S2)
|
|
|
|
res = _FAIL;
|
|
|
|
if (pwrctrl->rpwm < pslv)
|
|
|
|
rtw_set_rpwm(padapter, pslv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_exit_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Caller: rx_isr
|
|
|
|
*
|
|
|
|
* Calling Context: Dispatch/ISR
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* _SUCCESS
|
|
|
|
* _FAIL
|
|
|
|
*/
|
|
|
|
s32 rtw_register_rx_alive(PADAPTER padapter)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrctrl;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
|
|
|
pwrctrl = &padapter->pwrctrlpriv;
|
|
|
|
|
|
|
|
_enter_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
register_task_alive(pwrctrl, RECV_ALIVE);
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
|
|
|
|
("rtw_register_rx_alive: cpwm=0x%02x alives=0x%08x\n",
|
|
|
|
pwrctrl->cpwm, pwrctrl->alives));
|
|
|
|
|
|
|
|
_exit_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
|
|
|
|
return _SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Caller: evt_isr or evt_thread
|
|
|
|
*
|
|
|
|
* Calling Context: Dispatch/ISR or Passive
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* _SUCCESS
|
|
|
|
* _FAIL
|
|
|
|
*/
|
|
|
|
s32 rtw_register_evt_alive(PADAPTER padapter)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrctrl;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
|
|
|
pwrctrl = &padapter->pwrctrlpriv;
|
|
|
|
|
|
|
|
_enter_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
register_task_alive(pwrctrl, EVT_ALIVE);
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
|
|
|
|
("rtw_register_evt_alive: cpwm=0x%02x alives=0x%08x\n",
|
|
|
|
pwrctrl->cpwm, pwrctrl->alives));
|
|
|
|
|
|
|
|
_exit_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
|
|
|
|
return _SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Caller: ISR
|
|
|
|
*
|
|
|
|
* If ISR's txdone,
|
|
|
|
* No more pkts for TX,
|
|
|
|
* Then driver shall call this fun. to power down firmware again.
|
|
|
|
*/
|
|
|
|
void rtw_unregister_tx_alive(PADAPTER padapter)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrctrl;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
|
|
|
pwrctrl = &padapter->pwrctrlpriv;
|
|
|
|
|
|
|
|
_enter_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
unregister_task_alive(pwrctrl, XMIT_ALIVE);
|
|
|
|
|
|
|
|
if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE) &&
|
2013-05-26 03:02:10 +00:00
|
|
|
(pwrctrl->bFwCurrentInPSMode == true))
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
|
|
|
|
("%s: cpwm=0x%02x alives=0x%08x\n",
|
2013-05-09 16:23:32 +00:00
|
|
|
__func__, pwrctrl->cpwm, pwrctrl->alives));
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
if ((pwrctrl->alives == 0) &&
|
|
|
|
(pwrctrl->cpwm > PS_STATE_S0))
|
|
|
|
{
|
|
|
|
rtw_set_rpwm(padapter, PS_STATE_S0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_exit_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Caller: ISR
|
|
|
|
*
|
|
|
|
* If all commands have been done,
|
|
|
|
* and no more command to do,
|
|
|
|
* then driver shall call this fun. to power down firmware again.
|
|
|
|
*/
|
|
|
|
void rtw_unregister_cmd_alive(PADAPTER padapter)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrctrl;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
|
|
|
pwrctrl = &padapter->pwrctrlpriv;
|
|
|
|
|
|
|
|
_enter_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
unregister_task_alive(pwrctrl, CMD_ALIVE);
|
|
|
|
|
|
|
|
if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE) &&
|
2013-05-26 03:02:10 +00:00
|
|
|
(pwrctrl->bFwCurrentInPSMode == true))
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_info_,
|
|
|
|
("%s: cpwm=0x%02x alives=0x%08x\n",
|
2013-05-09 16:23:32 +00:00
|
|
|
__func__, pwrctrl->cpwm, pwrctrl->alives));
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
if ((pwrctrl->alives == 0) &&
|
|
|
|
(pwrctrl->cpwm > PS_STATE_S0))
|
|
|
|
{
|
|
|
|
rtw_set_rpwm(padapter, PS_STATE_S0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_exit_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Caller: ISR
|
|
|
|
*/
|
|
|
|
void rtw_unregister_rx_alive(PADAPTER padapter)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrctrl;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
|
|
|
pwrctrl = &padapter->pwrctrlpriv;
|
|
|
|
|
|
|
|
_enter_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
unregister_task_alive(pwrctrl, RECV_ALIVE);
|
|
|
|
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
|
|
|
|
("rtw_unregister_rx_alive: cpwm=0x%02x alives=0x%08x\n",
|
|
|
|
pwrctrl->cpwm, pwrctrl->alives));
|
|
|
|
|
|
|
|
_exit_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtw_unregister_evt_alive(PADAPTER padapter)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrctrl;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
|
|
|
pwrctrl = &padapter->pwrctrlpriv;
|
|
|
|
|
|
|
|
unregister_task_alive(pwrctrl, EVT_ALIVE);
|
|
|
|
|
|
|
|
RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
|
|
|
|
("rtw_unregister_evt_alive: cpwm=0x%02x alives=0x%08x\n",
|
|
|
|
pwrctrl->cpwm, pwrctrl->alives));
|
|
|
|
|
|
|
|
_exit_pwrlock(&pwrctrl->lock);
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_LPS_LCLK */
|
|
|
|
|
|
|
|
#ifdef CONFIG_RESUME_IN_WORKQUEUE
|
|
|
|
static void resume_workitem_callback(struct work_struct *work);
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_RESUME_IN_WORKQUEUE */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
void rtw_init_pwrctrl_priv(PADAPTER padapter)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
pwrctrlpriv->pnp_current_pwr_state=NdisDeviceStateD0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_init_pwrlock(&pwrctrlpriv->lock);
|
|
|
|
pwrctrlpriv->rf_pwrstate = rf_on;
|
|
|
|
pwrctrlpriv->ips_enter_cnts=0;
|
|
|
|
pwrctrlpriv->ips_leave_cnts=0;
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrctrlpriv->bips_processing = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
pwrctrlpriv->ips_mode = padapter->registrypriv.ips_mode;
|
|
|
|
pwrctrlpriv->ips_mode_req = padapter->registrypriv.ips_mode;
|
|
|
|
|
|
|
|
pwrctrlpriv->pwr_state_check_interval = RTW_PWR_STATE_CHK_INTERVAL;
|
|
|
|
pwrctrlpriv->pwr_state_check_cnts = 0;
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrctrlpriv->bInternalAutoSuspend = false;
|
|
|
|
pwrctrlpriv->bInSuspend = false;
|
|
|
|
pwrctrlpriv->bkeepfwalive = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_AUTOSUSPEND
|
|
|
|
#ifdef SUPPORT_HW_RFOFF_DETECTED
|
2013-05-19 04:28:07 +00:00
|
|
|
pwrctrlpriv->pwr_state_check_interval = (pwrctrlpriv->bHWPwrPindetect) ?1000:2000;
|
2013-05-08 21:45:39 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pwrctrlpriv->LpsIdleCount = 0;
|
|
|
|
if (padapter->registrypriv.mp_mode == 1)
|
|
|
|
pwrctrlpriv->power_mgnt =PS_MODE_ACTIVE ;
|
2013-05-19 04:28:07 +00:00
|
|
|
else
|
2013-07-09 22:38:46 +00:00
|
|
|
pwrctrlpriv->power_mgnt =padapter->registrypriv.power_mgnt;/* PS_MODE_MIN; */
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrctrlpriv->bLeisurePs = (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt)?true:false;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrctrlpriv->bFwCurrentInPSMode = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
pwrctrlpriv->rpwm = 0;
|
|
|
|
pwrctrlpriv->cpwm = PS_STATE_S4;
|
|
|
|
|
|
|
|
pwrctrlpriv->pwr_mode = PS_MODE_ACTIVE;
|
|
|
|
pwrctrlpriv->smart_ps = padapter->registrypriv.smart_ps;
|
|
|
|
pwrctrlpriv->bcn_ant_mode = 0;
|
|
|
|
|
|
|
|
pwrctrlpriv->tog = 0x80;
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrctrlpriv->btcoex_rfon = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_LPS_LCLK
|
|
|
|
rtw_hal_set_hwreg(padapter, HW_VAR_SET_RPWM, (u8 *)(&pwrctrlpriv->rpwm));
|
|
|
|
|
|
|
|
_init_workitem(&pwrctrlpriv->cpwm_event, cpwm_event_callback, NULL);
|
|
|
|
|
|
|
|
#ifdef CONFIG_LPS_RPWM_TIMER
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrctrlpriv->brpwmtimeout = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
_init_workitem(&pwrctrlpriv->rpwmtimeoutwi, rpwmtimeout_workitem_callback, NULL);
|
|
|
|
_init_timer(&pwrctrlpriv->pwr_rpwm_timer, padapter->pnetdev, pwr_rpwm_timeout_handler, padapter);
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_LPS_RPWM_TIMER */
|
|
|
|
#endif /* CONFIG_LPS_LCLK */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#ifdef PLATFORM_LINUX
|
|
|
|
_init_timer(&(pwrctrlpriv->pwr_state_check_timer), padapter->pnetdev, pwr_state_check_handler, (u8 *)padapter);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_RESUME_IN_WORKQUEUE
|
|
|
|
_init_workitem(&pwrctrlpriv->resume_work, resume_workitem_callback, NULL);
|
|
|
|
pwrctrlpriv->rtw_workqueue = create_singlethread_workqueue("rtw_workqueue");
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_RESUME_IN_WORKQUEUE */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
|
|
|
|
pwrctrlpriv->early_suspend.suspend = NULL;
|
|
|
|
rtw_register_early_suspend(pwrctrlpriv);
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_HAS_EARLYSUSPEND || CONFIG_ANDROID_POWER */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void rtw_free_pwrctrl_priv(PADAPTER adapter)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrctrlpriv = &adapter->pwrctrlpriv;
|
|
|
|
|
|
|
|
_func_enter_;
|
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* _rtw_memset((unsigned char *)pwrctrlpriv, 0, sizeof(struct pwrctrl_priv)); */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_RESUME_IN_WORKQUEUE
|
2013-05-19 04:28:07 +00:00
|
|
|
if (pwrctrlpriv->rtw_workqueue) {
|
2013-05-08 21:45:39 +00:00
|
|
|
flush_workqueue(pwrctrlpriv->rtw_workqueue);
|
|
|
|
destroy_workqueue(pwrctrlpriv->rtw_workqueue);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
|
|
|
|
rtw_unregister_early_suspend(pwrctrlpriv);
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_HAS_EARLYSUSPEND || CONFIG_ANDROID_POWER */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
_free_pwrlock(&pwrctrlpriv->lock);
|
|
|
|
|
|
|
|
_func_exit_;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_RESUME_IN_WORKQUEUE
|
|
|
|
#if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
|
|
|
|
extern int rtw_resume_process(_adapter *padapter);
|
|
|
|
#endif
|
|
|
|
static void resume_workitem_callback(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrpriv = container_of(work, struct pwrctrl_priv, resume_work);
|
|
|
|
_adapter *adapter = container_of(pwrpriv, _adapter, pwrctrlpriv);
|
|
|
|
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s\n",__func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
|
|
|
|
rtw_resume_process(adapter);
|
|
|
|
#endif
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void rtw_resume_in_workqueue(struct pwrctrl_priv *pwrpriv)
|
|
|
|
{
|
2013-07-09 22:38:46 +00:00
|
|
|
/* accquire system's suspend lock preventing from falliing asleep while resume in workqueue */
|
2013-05-08 21:45:39 +00:00
|
|
|
rtw_lock_suspend();
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
#if 1
|
2013-05-19 04:28:07 +00:00
|
|
|
queue_work(pwrpriv->rtw_workqueue, &pwrpriv->resume_work);
|
2013-05-08 21:45:39 +00:00
|
|
|
#else
|
|
|
|
_set_workitem(&pwrpriv->resume_work);
|
|
|
|
#endif
|
|
|
|
}
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_RESUME_IN_WORKQUEUE */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_HAS_EARLYSUSPEND
|
|
|
|
#if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
|
|
|
|
extern int rtw_resume_process(_adapter *padapter);
|
|
|
|
#endif
|
|
|
|
static void rtw_early_suspend(struct early_suspend *h)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s\n",__func__);
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* jeff: do nothing but set do_late_resume to false */
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->do_late_resume = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rtw_late_resume(struct early_suspend *h)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
|
|
|
|
_adapter *adapter = container_of(pwrpriv, _adapter, pwrctrlpriv);
|
|
|
|
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s\n",__func__);
|
2013-05-09 04:04:25 +00:00
|
|
|
if (pwrpriv->do_late_resume) {
|
2013-05-08 21:45:39 +00:00
|
|
|
#if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
|
|
|
|
rtw_resume_process(adapter);
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->do_late_resume = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtw_register_early_suspend(struct pwrctrl_priv *pwrpriv)
|
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s\n", __func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* jeff: set the early suspend level before blank screen, so we wll do late resume after scree is lit */
|
2013-05-08 21:45:39 +00:00
|
|
|
pwrpriv->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
|
|
|
|
pwrpriv->early_suspend.suspend = rtw_early_suspend;
|
|
|
|
pwrpriv->early_suspend.resume = rtw_late_resume;
|
2013-05-19 04:28:07 +00:00
|
|
|
register_early_suspend(&pwrpriv->early_suspend);
|
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtw_unregister_early_suspend(struct pwrctrl_priv *pwrpriv)
|
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s\n", __func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->do_late_resume = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-19 04:28:07 +00:00
|
|
|
if (pwrpriv->early_suspend.suspend)
|
2013-05-08 21:45:39 +00:00
|
|
|
unregister_early_suspend(&pwrpriv->early_suspend);
|
|
|
|
|
|
|
|
pwrpriv->early_suspend.suspend = NULL;
|
|
|
|
pwrpriv->early_suspend.resume = NULL;
|
|
|
|
}
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_HAS_EARLYSUSPEND */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_ANDROID_POWER
|
|
|
|
#if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
|
|
|
|
extern int rtw_resume_process(PADAPTER padapter);
|
|
|
|
#endif
|
|
|
|
static void rtw_early_suspend(android_early_suspend_t *h)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s\n",__func__);
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* jeff: do nothing but set do_late_resume to false */
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->do_late_resume = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rtw_late_resume(android_early_suspend_t *h)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
|
|
|
|
_adapter *adapter = container_of(pwrpriv, _adapter, pwrctrlpriv);
|
|
|
|
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s\n",__func__);
|
2013-05-09 04:04:25 +00:00
|
|
|
if (pwrpriv->do_late_resume) {
|
2013-05-08 21:45:39 +00:00
|
|
|
#if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
|
|
|
|
rtw_resume_process(adapter);
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->do_late_resume = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtw_register_early_suspend(struct pwrctrl_priv *pwrpriv)
|
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s\n", __func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* jeff: set the early suspend level before blank screen, so we wll do late resume after scree is lit */
|
2013-05-08 21:45:39 +00:00
|
|
|
pwrpriv->early_suspend.level = ANDROID_EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
|
|
|
|
pwrpriv->early_suspend.suspend = rtw_early_suspend;
|
|
|
|
pwrpriv->early_suspend.resume = rtw_late_resume;
|
2013-05-19 04:28:07 +00:00
|
|
|
android_register_early_suspend(&pwrpriv->early_suspend);
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void rtw_unregister_early_suspend(struct pwrctrl_priv *pwrpriv)
|
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s\n", __func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrpriv->do_late_resume = false;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-19 04:28:07 +00:00
|
|
|
if (pwrpriv->early_suspend.suspend)
|
2013-05-08 21:45:39 +00:00
|
|
|
android_unregister_early_suspend(&pwrpriv->early_suspend);
|
|
|
|
|
|
|
|
pwrpriv->early_suspend.suspend = NULL;
|
|
|
|
pwrpriv->early_suspend.resume = NULL;
|
|
|
|
}
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* CONFIG_ANDROID_POWER */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
u8 rtw_interface_ps_func(_adapter *padapter,HAL_INTF_PS_FUNC efunc_id,u8* val)
|
|
|
|
{
|
2013-05-26 03:02:10 +00:00
|
|
|
u8 bResult = true;
|
2013-05-08 21:45:39 +00:00
|
|
|
rtw_hal_intf_ps_func(padapter,efunc_id,val);
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void rtw_set_ips_deny(_adapter *padapter, u32 ms)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
|
|
|
|
pwrpriv->ips_deny_time = rtw_get_current_time() + rtw_ms_to_systime(ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rtw_pwr_wakeup - Wake the NIC up from: 1)IPS. 2)USB autosuspend
|
|
|
|
* @adapter: pointer to _adapter structure
|
|
|
|
* @ips_deffer_ms: the ms wiil prevent from falling into IPS after wakeup
|
|
|
|
* Return _SUCCESS or _FAIL
|
|
|
|
*/
|
|
|
|
|
|
|
|
int _rtw_pwr_wakeup(_adapter *padapter, u32 ips_deffer_ms, const char *caller)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
|
2013-05-19 04:28:07 +00:00
|
|
|
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
|
2013-05-08 21:45:39 +00:00
|
|
|
int ret = _SUCCESS;
|
|
|
|
|
|
|
|
#ifdef CONFIG_CONCURRENT_MODE
|
|
|
|
if (padapter->pbuddy_adapter)
|
|
|
|
LeaveAllPowerSaveMode(padapter->pbuddy_adapter);
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
if ((padapter->isprimary == false) && padapter->pbuddy_adapter){
|
2013-05-08 21:45:39 +00:00
|
|
|
padapter = padapter->pbuddy_adapter;
|
|
|
|
pwrpriv = &padapter->pwrctrlpriv;
|
|
|
|
pmlmepriv = &padapter->mlmepriv;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (pwrpriv->ips_deny_time < rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms))
|
|
|
|
pwrpriv->ips_deny_time = rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms);
|
|
|
|
|
|
|
|
{
|
|
|
|
u32 start = rtw_get_current_time();
|
|
|
|
if (pwrpriv->ps_processing) {
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s wait ps_processing...\n", __func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
while (pwrpriv->ps_processing && rtw_get_passing_time_ms(start) <= 3000)
|
|
|
|
rtw_msleep_os(10);
|
|
|
|
if (pwrpriv->ps_processing)
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s wait ps_processing timeout\n", __func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
else
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s wait ps_processing done\n", __func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* System suspend is not allowed to wakeup */
|
2013-05-26 03:02:10 +00:00
|
|
|
if ((pwrpriv->bInternalAutoSuspend == false) && (true == pwrpriv->bInSuspend )){
|
2013-05-08 21:45:39 +00:00
|
|
|
ret = _FAIL;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* block??? */
|
2013-05-26 03:02:10 +00:00
|
|
|
if ((pwrpriv->bInternalAutoSuspend == true) && (padapter->net_closed == true)) {
|
2013-05-08 21:45:39 +00:00
|
|
|
ret = _FAIL;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* I think this should be check in IPS, LPS, autosuspend functions... */
|
2013-05-26 03:02:10 +00:00
|
|
|
if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
#if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND)
|
2013-05-26 03:02:10 +00:00
|
|
|
if (true==pwrpriv->bInternalAutoSuspend){
|
2013-05-09 04:04:25 +00:00
|
|
|
if (0==pwrpriv->autopm_cnt){
|
2013-05-19 04:28:07 +00:00
|
|
|
#if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
|
|
|
|
if (usb_autopm_get_interface(adapter_to_dvobj(padapter)->pusbintf) < 0)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E( "can't get autopm:\n");
|
2013-05-19 04:28:07 +00:00
|
|
|
}
|
|
|
|
#elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
|
2013-05-08 21:45:39 +00:00
|
|
|
usb_autopm_disable(adapter_to_dvobj(padapter)->pusbintf);
|
|
|
|
#else
|
|
|
|
usb_autoresume_device(adapter_to_dvobj(padapter)->pusbdev, 1);
|
|
|
|
#endif
|
|
|
|
pwrpriv->autopm_cnt++;
|
|
|
|
}
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND) */
|
2013-05-08 21:45:39 +00:00
|
|
|
ret = _SUCCESS;
|
|
|
|
goto exit;
|
|
|
|
#if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND)
|
|
|
|
}
|
2013-07-09 22:38:46 +00:00
|
|
|
#endif /* if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND) */
|
2013-05-19 04:28:07 +00:00
|
|
|
}
|
2013-05-09 04:04:25 +00:00
|
|
|
if (rf_off == pwrpriv->rf_pwrstate )
|
2013-05-19 04:28:07 +00:00
|
|
|
{
|
2013-05-08 21:45:39 +00:00
|
|
|
#ifdef CONFIG_USB_HCI
|
|
|
|
#ifdef CONFIG_AUTOSUSPEND
|
2013-05-26 03:02:10 +00:00
|
|
|
if (pwrpriv->brfoffbyhw==true)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("hw still in rf_off state ...........\n");
|
2013-05-08 21:45:39 +00:00
|
|
|
ret = _FAIL;
|
|
|
|
goto exit;
|
|
|
|
}
|
2013-05-09 04:04:25 +00:00
|
|
|
else if (padapter->registrypriv.usbss_enable)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s call autoresume_enter....\n",__func__);
|
2013-05-09 04:04:25 +00:00
|
|
|
if (_FAIL == autoresume_enter(padapter))
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("======> autoresume fail.............\n");
|
2013-05-08 21:45:39 +00:00
|
|
|
ret = _FAIL;
|
|
|
|
goto exit;
|
2013-05-19 04:28:07 +00:00
|
|
|
}
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_IPS
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s call ips_leave....\n",__func__);
|
2013-05-09 04:04:25 +00:00
|
|
|
if (_FAIL == ips_leave(padapter))
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("======> ips_leave fail.............\n");
|
2013-05-08 21:45:39 +00:00
|
|
|
ret = _FAIL;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 22:38:46 +00:00
|
|
|
/* TODO: the following checking need to be merged... */
|
2013-05-09 04:04:25 +00:00
|
|
|
if (padapter->bDriverStopped
|
2013-05-08 21:45:39 +00:00
|
|
|
|| !padapter->bup
|
|
|
|
|| !padapter->hw_init_completed
|
|
|
|
){
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s: bDriverStopped=%d, bup=%d, hw_init_completed=%u\n"
|
2013-05-08 21:45:39 +00:00
|
|
|
, caller
|
2013-05-19 04:28:07 +00:00
|
|
|
, padapter->bDriverStopped
|
|
|
|
, padapter->bup
|
|
|
|
, padapter->hw_init_completed);
|
2013-05-26 03:02:10 +00:00
|
|
|
ret= false;
|
2013-05-08 21:45:39 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
if (pwrpriv->ips_deny_time < rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms))
|
|
|
|
pwrpriv->ips_deny_time = rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int rtw_pm_set_lps(_adapter *padapter, u8 mode)
|
|
|
|
{
|
2013-05-19 04:28:07 +00:00
|
|
|
int ret = 0;
|
2013-05-08 21:45:39 +00:00
|
|
|
struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
if ( mode < PS_MODE_NUM )
|
|
|
|
{
|
2013-05-09 04:04:25 +00:00
|
|
|
if (pwrctrlpriv->power_mgnt !=mode)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-09 04:04:25 +00:00
|
|
|
if (PS_MODE_ACTIVE == mode)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
LeaveAllPowerSaveMode(padapter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pwrctrlpriv->LpsIdleCount = 2;
|
|
|
|
}
|
|
|
|
pwrctrlpriv->power_mgnt = mode;
|
2013-05-26 03:02:10 +00:00
|
|
|
pwrctrlpriv->bLeisurePs = (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt)?true:false;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rtw_pm_set_ips(_adapter *padapter, u8 mode)
|
|
|
|
{
|
|
|
|
struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
|
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if ( mode == IPS_NORMAL || mode == IPS_LEVEL_2 ) {
|
2013-05-08 21:45:39 +00:00
|
|
|
rtw_ips_mode_req(pwrctrlpriv, mode);
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s %s\n", __func__, mode == IPS_NORMAL?"IPS_NORMAL":"IPS_LEVEL_2");
|
2013-05-08 21:45:39 +00:00
|
|
|
return 0;
|
2013-05-19 04:28:07 +00:00
|
|
|
}
|
2013-05-09 04:04:25 +00:00
|
|
|
else if (mode ==IPS_NONE){
|
2013-05-08 21:45:39 +00:00
|
|
|
rtw_ips_mode_req(pwrctrlpriv, mode);
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s %s\n", __func__, "IPS_NONE");
|
2013-05-09 04:04:25 +00:00
|
|
|
if ((padapter->bSurpriseRemoved ==0)&&(_FAIL == rtw_pwr_wakeup(padapter)) )
|
2013-05-08 21:45:39 +00:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|