rtw_pwrctrl.c 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _RTW_PWRCTRL_C_
  21. #include <drv_types.h>
  22. #include <hal_data.h>
  23. #include <hal_com_h2c.h>
  24. int rtw_fw_ps_state(PADAPTER padapter)
  25. {
  26. struct dvobj_priv *psdpriv = padapter->dvobj;
  27. struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
  28. int ret=_FAIL, dont_care=0;
  29. u16 fw_ps_state=0;
  30. u32 start_time;
  31. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  32. struct registry_priv *registry_par = &padapter->registrypriv;
  33. if(registry_par->check_fw_ps != 1)
  34. return _SUCCESS;
  35. _enter_pwrlock(&pwrpriv->check_32k_lock);
  36. if (RTW_CANNOT_RUN(padapter)) {
  37. DBG_871X("%s: bSurpriseRemoved=%s , hw_init_completed=%d, bDriverStopped=%s\n", __func__
  38. , rtw_is_surprise_removed(padapter)?"True":"False"
  39. , rtw_get_hw_init_completed(padapter)
  40. , rtw_is_drv_stopped(padapter)?"True":"False");
  41. goto exit_fw_ps_state;
  42. }
  43. rtw_hal_set_hwreg(padapter, HW_VAR_SET_REQ_FW_PS, (u8 *)&dont_care);
  44. {
  45. //4. if 0x88[7]=1, driver set cmd to leave LPS/IPS.
  46. //Else, hw will keep in active mode.
  47. //debug info:
  48. //0x88[7] = 32kpermission,
  49. //0x88[6:0] = current_ps_state
  50. //0x89[7:0] = last_rpwm
  51. rtw_hal_get_hwreg(padapter, HW_VAR_FW_PS_STATE, (u8 *)&fw_ps_state);
  52. if((fw_ps_state & 0x80) == 0)
  53. ret=_SUCCESS;
  54. else
  55. {
  56. pdbgpriv->dbg_poll_fail_cnt++;
  57. DBG_871X("%s: fw_ps_state=%04x \n", __FUNCTION__, fw_ps_state);
  58. }
  59. }
  60. exit_fw_ps_state:
  61. _exit_pwrlock(&pwrpriv->check_32k_lock);
  62. return ret;
  63. }
  64. #ifdef CONFIG_IPS
  65. void _ips_enter(_adapter * padapter)
  66. {
  67. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  68. pwrpriv->bips_processing = _TRUE;
  69. // syn ips_mode with request
  70. pwrpriv->ips_mode = pwrpriv->ips_mode_req;
  71. pwrpriv->ips_enter_cnts++;
  72. DBG_871X("==>ips_enter cnts:%d\n",pwrpriv->ips_enter_cnts);
  73. if(rf_off == pwrpriv->change_rfpwrstate )
  74. {
  75. pwrpriv->bpower_saving = _TRUE;
  76. DBG_871X("nolinked power save enter\n");
  77. if(pwrpriv->ips_mode == IPS_LEVEL_2)
  78. pwrpriv->bkeepfwalive = _TRUE;
  79. rtw_ips_pwr_down(padapter);
  80. pwrpriv->rf_pwrstate = rf_off;
  81. }
  82. pwrpriv->bips_processing = _FALSE;
  83. }
  84. void ips_enter(_adapter * padapter)
  85. {
  86. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  87. #ifdef CONFIG_BT_COEXIST
  88. rtw_btcoex_IpsNotify(padapter, pwrpriv->ips_mode_req);
  89. #endif // CONFIG_BT_COEXIST
  90. _enter_pwrlock(&pwrpriv->lock);
  91. _ips_enter(padapter);
  92. _exit_pwrlock(&pwrpriv->lock);
  93. }
  94. int _ips_leave(_adapter * padapter)
  95. {
  96. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  97. int result = _SUCCESS;
  98. if((pwrpriv->rf_pwrstate == rf_off) &&(!pwrpriv->bips_processing))
  99. {
  100. pwrpriv->bips_processing = _TRUE;
  101. pwrpriv->change_rfpwrstate = rf_on;
  102. pwrpriv->ips_leave_cnts++;
  103. DBG_871X("==>ips_leave cnts:%d\n",pwrpriv->ips_leave_cnts);
  104. if ((result = rtw_ips_pwr_up(padapter)) == _SUCCESS) {
  105. pwrpriv->rf_pwrstate = rf_on;
  106. }
  107. DBG_871X("nolinked power save leave\n");
  108. DBG_871X("==> ips_leave.....LED(0x%08x)...\n",rtw_read32(padapter,0x4c));
  109. pwrpriv->bips_processing = _FALSE;
  110. pwrpriv->bkeepfwalive = _FALSE;
  111. pwrpriv->bpower_saving = _FALSE;
  112. }
  113. return result;
  114. }
  115. int ips_leave(_adapter * padapter)
  116. {
  117. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  118. struct dvobj_priv *psdpriv = padapter->dvobj;
  119. struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
  120. int ret;
  121. if(!is_primary_adapter(padapter))
  122. return _SUCCESS;
  123. _enter_pwrlock(&pwrpriv->lock);
  124. ret = _ips_leave(padapter);
  125. #ifdef DBG_CHECK_FW_PS_STATE
  126. if(rtw_fw_ps_state(padapter) == _FAIL)
  127. {
  128. DBG_871X("ips leave doesn't leave 32k\n");
  129. pdbgpriv->dbg_leave_ips_fail_cnt++;
  130. }
  131. #endif //DBG_CHECK_FW_PS_STATE
  132. _exit_pwrlock(&pwrpriv->lock);
  133. if (_SUCCESS == ret)
  134. ODM_DMReset(&GET_HAL_DATA(padapter)->odmpriv);
  135. #ifdef CONFIG_BT_COEXIST
  136. if (_SUCCESS == ret)
  137. rtw_btcoex_IpsNotify(padapter, IPS_NONE);
  138. #endif // CONFIG_BT_COEXIST
  139. return ret;
  140. }
  141. #endif /* CONFIG_IPS */
  142. #ifdef CONFIG_AUTOSUSPEND
  143. extern void autosuspend_enter(_adapter* padapter);
  144. extern int autoresume_enter(_adapter* padapter);
  145. #endif
  146. #ifdef SUPPORT_HW_RFOFF_DETECTED
  147. int rtw_hw_suspend(_adapter *padapter );
  148. int rtw_hw_resume(_adapter *padapter);
  149. #endif
  150. bool rtw_pwr_unassociated_idle(_adapter *adapter)
  151. {
  152. _adapter *buddy = adapter->pbuddy_adapter;
  153. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  154. struct xmit_priv *pxmit_priv = &adapter->xmitpriv;
  155. #ifdef CONFIG_P2P
  156. struct wifidirect_info *pwdinfo = &(adapter->wdinfo);
  157. #ifdef CONFIG_IOCTL_CFG80211
  158. struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &adapter->cfg80211_wdinfo;
  159. #endif
  160. #endif
  161. bool ret = _FALSE;
  162. if (adapter_to_pwrctl(adapter)->bpower_saving ==_TRUE ) {
  163. //DBG_871X("%s: already in LPS or IPS mode\n", __func__);
  164. goto exit;
  165. }
  166. if (adapter_to_pwrctl(adapter)->ips_deny_time >= rtw_get_current_time()) {
  167. //DBG_871X("%s ips_deny_time\n", __func__);
  168. goto exit;
  169. }
  170. if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE|WIFI_SITE_MONITOR)
  171. || check_fwstate(pmlmepriv, WIFI_UNDER_LINKING|WIFI_UNDER_WPS)
  172. || check_fwstate(pmlmepriv, WIFI_AP_STATE)
  173. || check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE|WIFI_ADHOC_STATE)
  174. #if defined(CONFIG_P2P) && defined(CONFIG_IOCTL_CFG80211) && defined(CONFIG_P2P_IPS)
  175. || pcfg80211_wdinfo->is_ro_ch
  176. #elif defined(CONFIG_P2P)
  177. || !rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)
  178. #endif
  179. #if defined(CONFIG_P2P) && defined(CONFIG_IOCTL_CFG80211)
  180. || rtw_get_passing_time_ms(pcfg80211_wdinfo->last_ro_ch_time) < 3000
  181. #endif
  182. ) {
  183. goto exit;
  184. }
  185. /* consider buddy, if exist */
  186. if (buddy) {
  187. struct mlme_priv *b_pmlmepriv = &(buddy->mlmepriv);
  188. #ifdef CONFIG_P2P
  189. struct wifidirect_info *b_pwdinfo = &(buddy->wdinfo);
  190. #ifdef CONFIG_IOCTL_CFG80211
  191. struct cfg80211_wifidirect_info *b_pcfg80211_wdinfo = &buddy->cfg80211_wdinfo;
  192. #endif
  193. #endif
  194. if (check_fwstate(b_pmlmepriv, WIFI_ASOC_STATE|WIFI_SITE_MONITOR)
  195. || check_fwstate(b_pmlmepriv, WIFI_UNDER_LINKING|WIFI_UNDER_WPS)
  196. || check_fwstate(b_pmlmepriv, WIFI_AP_STATE)
  197. || check_fwstate(b_pmlmepriv, WIFI_ADHOC_MASTER_STATE|WIFI_ADHOC_STATE)
  198. #if defined(CONFIG_P2P) && defined(CONFIG_IOCTL_CFG80211) && defined(CONFIG_P2P_IPS)
  199. || b_pcfg80211_wdinfo->is_ro_ch
  200. #elif defined(CONFIG_P2P)
  201. || !rtw_p2p_chk_state(b_pwdinfo, P2P_STATE_NONE)
  202. #endif
  203. #if defined(CONFIG_P2P) && defined(CONFIG_IOCTL_CFG80211)
  204. || rtw_get_passing_time_ms(b_pcfg80211_wdinfo->last_ro_ch_time) < 3000
  205. #endif
  206. ) {
  207. goto exit;
  208. }
  209. }
  210. #if (MP_DRIVER == 1)
  211. if (adapter->registrypriv.mp_mode == 1)
  212. goto exit;
  213. #endif
  214. #ifdef CONFIG_INTEL_PROXIM
  215. if(adapter->proximity.proxim_on==_TRUE){
  216. return;
  217. }
  218. #endif
  219. if (pxmit_priv->free_xmitbuf_cnt != NR_XMITBUFF ||
  220. pxmit_priv->free_xmit_extbuf_cnt != NR_XMIT_EXTBUFF) {
  221. DBG_871X_LEVEL(_drv_always_, "There are some pkts to transmit\n");
  222. DBG_871X_LEVEL(_drv_always_, "free_xmitbuf_cnt: %d, free_xmit_extbuf_cnt: %d\n",
  223. pxmit_priv->free_xmitbuf_cnt, pxmit_priv->free_xmit_extbuf_cnt);
  224. goto exit;
  225. }
  226. ret = _TRUE;
  227. exit:
  228. return ret;
  229. }
  230. /*
  231. * ATTENTION:
  232. * rtw_ps_processor() doesn't handle LPS.
  233. */
  234. void rtw_ps_processor(_adapter*padapter)
  235. {
  236. #ifdef CONFIG_P2P
  237. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  238. #endif //CONFIG_P2P
  239. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  240. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  241. struct dvobj_priv *psdpriv = padapter->dvobj;
  242. struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
  243. #ifdef SUPPORT_HW_RFOFF_DETECTED
  244. rt_rf_power_state rfpwrstate;
  245. #endif //SUPPORT_HW_RFOFF_DETECTED
  246. u32 ps_deny = 0;
  247. _enter_pwrlock(&adapter_to_pwrctl(padapter)->lock);
  248. ps_deny = rtw_ps_deny_get(padapter);
  249. _exit_pwrlock(&adapter_to_pwrctl(padapter)->lock);
  250. if (ps_deny != 0)
  251. {
  252. DBG_871X(FUNC_ADPT_FMT ": ps_deny=0x%08X, skip power save!\n",
  253. FUNC_ADPT_ARG(padapter), ps_deny);
  254. goto exit;
  255. }
  256. if(pwrpriv->bInSuspend == _TRUE){//system suspend or autosuspend
  257. pdbgpriv->dbg_ps_insuspend_cnt++;
  258. DBG_871X("%s, pwrpriv->bInSuspend == _TRUE ignore this process\n",__FUNCTION__);
  259. return;
  260. }
  261. pwrpriv->ps_processing = _TRUE;
  262. #ifdef SUPPORT_HW_RFOFF_DETECTED
  263. if(pwrpriv->bips_processing == _TRUE)
  264. goto exit;
  265. //DBG_871X("==> fw report state(0x%x)\n",rtw_read8(padapter,0x1ca));
  266. if(pwrpriv->bHWPwrPindetect)
  267. {
  268. #ifdef CONFIG_AUTOSUSPEND
  269. if(padapter->registrypriv.usbss_enable)
  270. {
  271. if(pwrpriv->rf_pwrstate == rf_on)
  272. {
  273. if(padapter->net_closed == _TRUE)
  274. pwrpriv->ps_flag = _TRUE;
  275. rfpwrstate = RfOnOffDetect(padapter);
  276. DBG_871X("@@@@- #1 %s==> rfstate:%s \n",__FUNCTION__,(rfpwrstate==rf_on)?"rf_on":"rf_off");
  277. if(rfpwrstate!= pwrpriv->rf_pwrstate)
  278. {
  279. if(rfpwrstate == rf_off)
  280. {
  281. pwrpriv->change_rfpwrstate = rf_off;
  282. pwrpriv->bkeepfwalive = _TRUE;
  283. pwrpriv->brfoffbyhw = _TRUE;
  284. autosuspend_enter(padapter);
  285. }
  286. }
  287. }
  288. }
  289. else
  290. #endif //CONFIG_AUTOSUSPEND
  291. {
  292. rfpwrstate = RfOnOffDetect(padapter);
  293. DBG_871X("@@@@- #2 %s==> rfstate:%s \n",__FUNCTION__,(rfpwrstate==rf_on)?"rf_on":"rf_off");
  294. if(rfpwrstate!= pwrpriv->rf_pwrstate)
  295. {
  296. if(rfpwrstate == rf_off)
  297. {
  298. pwrpriv->change_rfpwrstate = rf_off;
  299. pwrpriv->brfoffbyhw = _TRUE;
  300. rtw_hw_suspend(padapter );
  301. }
  302. else
  303. {
  304. pwrpriv->change_rfpwrstate = rf_on;
  305. rtw_hw_resume(padapter );
  306. }
  307. DBG_871X("current rf_pwrstate(%s)\n",(pwrpriv->rf_pwrstate == rf_off)?"rf_off":"rf_on");
  308. }
  309. }
  310. pwrpriv->pwr_state_check_cnts ++;
  311. }
  312. #endif //SUPPORT_HW_RFOFF_DETECTED
  313. if (pwrpriv->ips_mode_req == IPS_NONE)
  314. goto exit;
  315. if (rtw_pwr_unassociated_idle(padapter) == _FALSE)
  316. goto exit;
  317. if((pwrpriv->rf_pwrstate == rf_on) && ((pwrpriv->pwr_state_check_cnts%4)==0))
  318. {
  319. DBG_871X("==>%s .fw_state(%x)\n",__FUNCTION__,get_fwstate(pmlmepriv));
  320. #if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND)
  321. #else
  322. pwrpriv->change_rfpwrstate = rf_off;
  323. #endif
  324. #ifdef CONFIG_AUTOSUSPEND
  325. if(padapter->registrypriv.usbss_enable)
  326. {
  327. if(pwrpriv->bHWPwrPindetect)
  328. pwrpriv->bkeepfwalive = _TRUE;
  329. if(padapter->net_closed == _TRUE)
  330. pwrpriv->ps_flag = _TRUE;
  331. #if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND)
  332. if (_TRUE==pwrpriv->bInternalAutoSuspend) {
  333. DBG_871X("<==%s .pwrpriv->bInternalAutoSuspend)(%x)\n",__FUNCTION__,pwrpriv->bInternalAutoSuspend);
  334. } else {
  335. pwrpriv->change_rfpwrstate = rf_off;
  336. DBG_871X("<==%s .pwrpriv->bInternalAutoSuspend)(%x) call autosuspend_enter\n",__FUNCTION__,pwrpriv->bInternalAutoSuspend);
  337. autosuspend_enter(padapter);
  338. }
  339. #else
  340. autosuspend_enter(padapter);
  341. #endif //if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND)
  342. }
  343. else if(pwrpriv->bHWPwrPindetect)
  344. {
  345. }
  346. else
  347. #endif //CONFIG_AUTOSUSPEND
  348. {
  349. #if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND)
  350. pwrpriv->change_rfpwrstate = rf_off;
  351. #endif //defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND)
  352. #ifdef CONFIG_IPS
  353. ips_enter(padapter);
  354. #endif
  355. }
  356. }
  357. exit:
  358. #ifndef CONFIG_IPS_CHECK_IN_WD
  359. rtw_set_pwr_state_check_timer(pwrpriv);
  360. #endif
  361. pwrpriv->ps_processing = _FALSE;
  362. return;
  363. }
  364. void pwr_state_check_handler(RTW_TIMER_HDL_ARGS);
  365. void pwr_state_check_handler(RTW_TIMER_HDL_ARGS)
  366. {
  367. _adapter *padapter = (_adapter *)FunctionContext;
  368. rtw_ps_cmd(padapter);
  369. }
  370. #ifdef CONFIG_LPS
  371. void traffic_check_for_leave_lps(PADAPTER padapter, u8 tx, u32 tx_packets)
  372. {
  373. #ifdef CONFIG_CHECK_LEAVE_LPS
  374. static u32 start_time = 0;
  375. static u32 xmit_cnt = 0;
  376. u8 bLeaveLPS = _FALSE;
  377. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  378. if(tx) //from tx
  379. {
  380. xmit_cnt += tx_packets;
  381. if (start_time== 0)
  382. start_time= rtw_get_current_time();
  383. if (rtw_get_passing_time_ms(start_time) > 2000) // 2 sec == watch dog timer
  384. {
  385. if(xmit_cnt > 8)
  386. {
  387. if ((adapter_to_pwrctl(padapter)->bLeisurePs)
  388. && (adapter_to_pwrctl(padapter)->pwr_mode != PS_MODE_ACTIVE)
  389. #ifdef CONFIG_BT_COEXIST
  390. && (rtw_btcoex_IsBtControlLps(padapter) == _FALSE)
  391. #endif
  392. )
  393. {
  394. //DBG_871X("leave lps via Tx = %d\n", xmit_cnt);
  395. bLeaveLPS = _TRUE;
  396. }
  397. }
  398. start_time= rtw_get_current_time();
  399. xmit_cnt = 0;
  400. }
  401. }
  402. else // from rx path
  403. {
  404. if(pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod > 4/*2*/)
  405. {
  406. if ((adapter_to_pwrctl(padapter)->bLeisurePs)
  407. && (adapter_to_pwrctl(padapter)->pwr_mode != PS_MODE_ACTIVE)
  408. #ifdef CONFIG_BT_COEXIST
  409. && (rtw_btcoex_IsBtControlLps(padapter) == _FALSE)
  410. #endif
  411. )
  412. {
  413. //DBG_871X("leave lps via Rx = %d\n", pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod);
  414. bLeaveLPS = _TRUE;
  415. }
  416. }
  417. }
  418. if(bLeaveLPS)
  419. {
  420. //DBG_871X("leave lps via %s, Tx = %d, Rx = %d \n", tx?"Tx":"Rx", pmlmepriv->LinkDetectInfo.NumTxOkInPeriod,pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod);
  421. //rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_LEAVE, 1);
  422. rtw_lps_ctrl_wk_cmd(padapter, tx?LPS_CTRL_TX_TRAFFIC_LEAVE:LPS_CTRL_RX_TRAFFIC_LEAVE, tx?0:1);
  423. }
  424. #endif //CONFIG_CHECK_LEAVE_LPS
  425. }
  426. /*
  427. * Description:
  428. * This function MUST be called under power lock protect
  429. *
  430. * Parameters
  431. * padapter
  432. * pslv power state level, only could be PS_STATE_S0 ~ PS_STATE_S4
  433. *
  434. */
  435. void rtw_set_rpwm(PADAPTER padapter, u8 pslv)
  436. {
  437. u8 rpwm;
  438. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  439. #ifdef CONFIG_DETECT_CPWM_BY_POLLING
  440. u8 cpwm_orig;
  441. #endif // CONFIG_DETECT_CPWM_BY_POLLING
  442. struct dvobj_priv *psdpriv = padapter->dvobj;
  443. struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
  444. _func_enter_;
  445. pslv = PS_STATE(pslv);
  446. #ifdef CONFIG_LPS_RPWM_TIMER
  447. if (pwrpriv->brpwmtimeout == _TRUE)
  448. {
  449. DBG_871X("%s: RPWM timeout, force to set RPWM(0x%02X) again!\n", __FUNCTION__, pslv);
  450. }
  451. else
  452. #endif // CONFIG_LPS_RPWM_TIMER
  453. {
  454. if ( (pwrpriv->rpwm == pslv)
  455. #ifdef CONFIG_LPS_LCLK
  456. || ((pwrpriv->rpwm >= PS_STATE_S2)&&(pslv >= PS_STATE_S2))
  457. #endif
  458. )
  459. {
  460. RT_TRACE(_module_rtl871x_pwrctrl_c_,_drv_err_,
  461. ("%s: Already set rpwm[0x%02X], new=0x%02X!\n", __FUNCTION__, pwrpriv->rpwm, pslv));
  462. return;
  463. }
  464. }
  465. if (rtw_is_surprise_removed(padapter) ||
  466. (!rtw_is_hw_init_completed(padapter)))
  467. {
  468. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
  469. ("%s: SurpriseRemoved(%s) hw_init_completed(%s)\n"
  470. , __func__
  471. , rtw_is_surprise_removed(padapter)?"True":"False"
  472. , rtw_is_hw_init_completed(padapter)?"True":"False"));
  473. pwrpriv->cpwm = PS_STATE_S4;
  474. return;
  475. }
  476. if (rtw_is_drv_stopped(padapter)) {
  477. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
  478. ("%s: change power state(0x%02X) when DriverStopped\n", __FUNCTION__, pslv));
  479. if (pslv < PS_STATE_S2) {
  480. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
  481. ("%s: Reject to enter PS_STATE(0x%02X) lower than S2 when DriverStopped!!\n", __FUNCTION__, pslv));
  482. return;
  483. }
  484. }
  485. rpwm = pslv | pwrpriv->tog;
  486. #ifdef CONFIG_LPS_LCLK
  487. // only when from PS_STATE S0/S1 to S2 and higher needs ACK
  488. if ((pwrpriv->cpwm < PS_STATE_S2) && (pslv >= PS_STATE_S2))
  489. rpwm |= PS_ACK;
  490. #endif
  491. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
  492. ("rtw_set_rpwm: rpwm=0x%02x cpwm=0x%02x\n", rpwm, pwrpriv->cpwm));
  493. pwrpriv->rpwm = pslv;
  494. #ifdef CONFIG_DETECT_CPWM_BY_POLLING
  495. cpwm_orig = 0;
  496. if (rpwm & PS_ACK)
  497. {
  498. rtw_hal_get_hwreg(padapter, HW_VAR_CPWM, &cpwm_orig);
  499. }
  500. #endif
  501. #if defined(CONFIG_LPS_RPWM_TIMER) && !defined(CONFIG_DETECT_CPWM_BY_POLLING)
  502. if (rpwm & PS_ACK)
  503. _set_timer(&pwrpriv->pwr_rpwm_timer, LPS_RPWM_WAIT_MS);
  504. #endif // CONFIG_LPS_RPWM_TIMER & !CONFIG_DETECT_CPWM_BY_POLLING
  505. rtw_hal_set_hwreg(padapter, HW_VAR_SET_RPWM, (u8 *)(&rpwm));
  506. pwrpriv->tog += 0x80;
  507. #ifdef CONFIG_LPS_LCLK
  508. // No LPS 32K, No Ack
  509. if (rpwm & PS_ACK)
  510. {
  511. #ifdef CONFIG_DETECT_CPWM_BY_POLLING
  512. u32 start_time;
  513. u8 cpwm_now;
  514. u8 poll_cnt=0;
  515. start_time = rtw_get_current_time();
  516. // polling cpwm
  517. do {
  518. rtw_msleep_os(1);
  519. poll_cnt++;
  520. cpwm_now = 0;
  521. rtw_hal_get_hwreg(padapter, HW_VAR_CPWM, &cpwm_now);
  522. if ((cpwm_orig ^ cpwm_now) & 0x80)
  523. {
  524. pwrpriv->cpwm = PS_STATE_S4;
  525. pwrpriv->cpwm_tog = cpwm_now & PS_TOGGLE;
  526. #ifdef DBG_CHECK_FW_PS_STATE
  527. DBG_871X("%s: polling cpwm OK! poll_cnt=%d, cpwm_orig=%02x, cpwm_now=%02x , 0x100=0x%x\n"
  528. , __FUNCTION__,poll_cnt, cpwm_orig, cpwm_now, rtw_read8(padapter, REG_CR));
  529. if(rtw_fw_ps_state(padapter) == _FAIL)
  530. {
  531. DBG_871X("leave 32k but fw state in 32k\n");
  532. pdbgpriv->dbg_rpwm_toogle_cnt++;
  533. }
  534. #endif //DBG_CHECK_FW_PS_STATE
  535. break;
  536. }
  537. if (rtw_get_passing_time_ms(start_time) > LPS_RPWM_WAIT_MS)
  538. {
  539. DBG_871X("%s: polling cpwm timeout! poll_cnt=%d, cpwm_orig=%02x, cpwm_now=%02x \n", __FUNCTION__,poll_cnt, cpwm_orig, cpwm_now);
  540. #ifdef DBG_CHECK_FW_PS_STATE
  541. if(rtw_fw_ps_state(padapter) == _FAIL)
  542. {
  543. DBG_871X("rpwm timeout and fw ps state in 32k\n");
  544. pdbgpriv->dbg_rpwm_timeout_fail_cnt++;
  545. }
  546. #endif //DBG_CHECK_FW_PS_STATE
  547. #ifdef CONFIG_LPS_RPWM_TIMER
  548. _set_timer(&pwrpriv->pwr_rpwm_timer, 1);
  549. #endif // CONFIG_LPS_RPWM_TIMER
  550. break;
  551. }
  552. } while (1);
  553. #endif // CONFIG_DETECT_CPWM_BY_POLLING
  554. }
  555. else
  556. #endif // CONFIG_LPS_LCLK
  557. {
  558. pwrpriv->cpwm = pslv;
  559. }
  560. _func_exit_;
  561. }
  562. u8 PS_RDY_CHECK(_adapter * padapter)
  563. {
  564. u32 curr_time, delta_time;
  565. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  566. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  567. #ifdef CONFIG_P2P
  568. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  569. #ifdef CONFIG_IOCTL_CFG80211
  570. struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
  571. #endif /* CONFIG_IOCTL_CFG80211 */
  572. #endif /* CONFIG_P2P */
  573. #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
  574. if(_TRUE == pwrpriv->bInSuspend && pwrpriv->wowlan_mode)
  575. return _TRUE;
  576. else if(_TRUE == pwrpriv->bInSuspend && pwrpriv->wowlan_ap_mode)
  577. return _TRUE;
  578. else if (_TRUE == pwrpriv->bInSuspend)
  579. return _FALSE;
  580. #else
  581. if(_TRUE == pwrpriv->bInSuspend )
  582. return _FALSE;
  583. #endif
  584. curr_time = rtw_get_current_time();
  585. delta_time = curr_time -pwrpriv->DelayLPSLastTimeStamp;
  586. if(delta_time < LPS_DELAY_TIME)
  587. {
  588. return _FALSE;
  589. }
  590. if (check_fwstate(pmlmepriv, WIFI_SITE_MONITOR)
  591. || check_fwstate(pmlmepriv, WIFI_UNDER_LINKING|WIFI_UNDER_WPS)
  592. || check_fwstate(pmlmepriv, WIFI_AP_STATE)
  593. || check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE|WIFI_ADHOC_STATE)
  594. #if defined(CONFIG_P2P) && defined(CONFIG_IOCTL_CFG80211) && defined(CONFIG_P2P_IPS)
  595. || pcfg80211_wdinfo->is_ro_ch
  596. #elif defined(CONFIG_P2P)
  597. || !rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)
  598. #endif
  599. || rtw_is_scan_deny(padapter)
  600. #ifdef CONFIG_TDLS
  601. // TDLS link is established.
  602. || ( padapter->tdlsinfo.link_established == _TRUE )
  603. #endif // CONFIG_TDLS
  604. )
  605. return _FALSE;
  606. if( (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) && (padapter->securitypriv.binstallGrpkey == _FALSE) )
  607. {
  608. DBG_871X("Group handshake still in progress !!!\n");
  609. return _FALSE;
  610. }
  611. #ifdef CONFIG_IOCTL_CFG80211
  612. if (!rtw_cfg80211_pwr_mgmt(padapter))
  613. return _FALSE;
  614. #endif
  615. return _TRUE;
  616. }
  617. #if defined(CONFIG_FWLPS_IN_IPS)
  618. void rtw_set_fw_in_ips_mode(PADAPTER padapter, u8 enable)
  619. {
  620. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  621. int cnt=0;
  622. u32 start_time;
  623. u8 val8 = 0;
  624. u8 cpwm_orig = 0, cpwm_now = 0;
  625. u8 parm[H2C_INACTIVE_PS_LEN]={0};
  626. if (padapter->netif_up == _FALSE) {
  627. DBG_871X("%s: ERROR, netif is down\n", __func__);
  628. return;
  629. }
  630. //u8 cmd_param; //BIT0:enable, BIT1:NoConnect32k
  631. if (enable) {
  632. #ifdef CONFIG_BT_COEXIST
  633. rtw_btcoex_IpsNotify(padapter, pwrpriv->ips_mode_req);
  634. #endif
  635. //Enter IPS
  636. DBG_871X("%s: issue H2C to FW when entering IPS\n", __func__);
  637. #ifdef CONFIG_PNO_SUPPORT
  638. parm[0] = 0x03;
  639. parm[1] = pwrpriv->pnlo_info->fast_scan_iterations;
  640. parm[2] = pwrpriv->pnlo_info->slow_scan_period;
  641. #else
  642. parm[0] = 0x03;
  643. parm[1] = 0x0;
  644. parm[2] = 0x0;
  645. #endif//CONFIG_PNO_SUPPORT
  646. rtw_hal_fill_h2c_cmd(padapter, //H2C_FWLPS_IN_IPS_,
  647. H2C_INACTIVE_PS_,
  648. H2C_INACTIVE_PS_LEN, parm);
  649. //poll 0x1cc to make sure H2C command already finished by FW; MAC_0x1cc=0 means H2C done by FW.
  650. do{
  651. val8 = rtw_read8(padapter, REG_HMETFR);
  652. cnt++;
  653. DBG_871X("%s polling REG_HMETFR=0x%x, cnt=%d \n",
  654. __func__, val8, cnt);
  655. rtw_mdelay_os(10);
  656. }while(cnt<100 && (val8!=0));
  657. //H2C done, enter 32k
  658. if (val8 == 0) {
  659. //ser rpwm to enter 32k
  660. val8 = rtw_read8(padapter, SDIO_LOCAL_BASE|SDIO_REG_HRPWM1);
  661. DBG_871X("%s: read rpwm=%02x\n", __FUNCTION__, val8);
  662. val8 += 0x80;
  663. val8 |= BIT(0);
  664. rtw_write8(padapter, SDIO_LOCAL_BASE|SDIO_REG_HRPWM1, val8);
  665. DBG_871X("%s: write rpwm=%02x\n", __FUNCTION__, val8);
  666. adapter_to_pwrctl(padapter)->tog = (val8 + 0x80) & 0x80;
  667. cnt = val8 = 0;
  668. if (parm[1] == 0 || parm[2] == 0) {
  669. do {
  670. val8 = rtw_read8(padapter, REG_CR);
  671. cnt++;
  672. DBG_871X("%s polling 0x100=0x%x, cnt=%d \n",
  673. __func__, val8, cnt);
  674. DBG_871X("%s 0x08:%02x, 0x03:%02x\n",
  675. __func__,
  676. rtw_read8(padapter, 0x08),
  677. rtw_read8(padapter, 0x03));
  678. rtw_mdelay_os(10);
  679. } while(cnt<20 && (val8!=0xEA));
  680. }
  681. }
  682. } else {
  683. //Leave IPS
  684. DBG_871X("%s: Leaving IPS in FWLPS state\n", __func__);
  685. //for polling cpwm
  686. cpwm_orig = 0;
  687. rtw_hal_get_hwreg(padapter, HW_VAR_CPWM, &cpwm_orig);
  688. //ser rpwm
  689. val8 = rtw_read8(padapter, SDIO_LOCAL_BASE|SDIO_REG_HRPWM1);
  690. val8 &= 0x80;
  691. val8 += 0x80;
  692. val8 |= BIT(6);
  693. rtw_write8(padapter, SDIO_LOCAL_BASE|SDIO_REG_HRPWM1, val8);
  694. DBG_871X("%s: write rpwm=%02x\n", __FUNCTION__, val8);
  695. adapter_to_pwrctl(padapter)->tog = (val8 + 0x80) & 0x80;
  696. //do polling cpwm
  697. start_time = rtw_get_current_time();
  698. do {
  699. rtw_mdelay_os(1);
  700. rtw_hal_get_hwreg(padapter, HW_VAR_CPWM, &cpwm_now);
  701. if ((cpwm_orig ^ cpwm_now) & 0x80) {
  702. break;
  703. }
  704. if (rtw_get_passing_time_ms(start_time) > 100)
  705. {
  706. DBG_871X("%s: polling cpwm timeout when leaving IPS in FWLPS state\n", __FUNCTION__);
  707. break;
  708. }
  709. } while (1);
  710. parm[0] = 0x0;
  711. parm[1] = 0x0;
  712. parm[2] = 0x0;
  713. rtw_hal_fill_h2c_cmd(padapter, H2C_INACTIVE_PS_,
  714. H2C_INACTIVE_PS_LEN, parm);
  715. #ifdef CONFIG_BT_COEXIST
  716. rtw_btcoex_IpsNotify(padapter, IPS_NONE);
  717. #endif
  718. }
  719. }
  720. #endif //CONFIG_PNO_SUPPORT
  721. void rtw_set_ps_mode(PADAPTER padapter, u8 ps_mode, u8 smart_ps, u8 bcn_ant_mode, const char *msg)
  722. {
  723. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  724. struct dvobj_priv *psdpriv = padapter->dvobj;
  725. struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
  726. #ifdef CONFIG_P2P
  727. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  728. #endif //CONFIG_P2P
  729. #ifdef CONFIG_TDLS
  730. struct sta_priv *pstapriv = &padapter->stapriv;
  731. _irqL irqL;
  732. int i, j;
  733. _list *plist, *phead;
  734. struct sta_info *ptdls_sta;
  735. #endif //CONFIG_TDLS
  736. _func_enter_;
  737. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
  738. ("%s: PowerMode=%d Smart_PS=%d\n",
  739. __FUNCTION__, ps_mode, smart_ps));
  740. if(ps_mode > PM_Card_Disable) {
  741. RT_TRACE(_module_rtl871x_pwrctrl_c_,_drv_err_,("ps_mode:%d error\n", ps_mode));
  742. return;
  743. }
  744. if (pwrpriv->pwr_mode == ps_mode)
  745. {
  746. if (PS_MODE_ACTIVE == ps_mode) return;
  747. #ifndef CONFIG_BT_COEXIST
  748. if ((pwrpriv->smart_ps == smart_ps) &&
  749. (pwrpriv->bcn_ant_mode == bcn_ant_mode))
  750. {
  751. return;
  752. }
  753. #endif // !CONFIG_BT_COEXIST
  754. }
  755. #ifdef CONFIG_LPS_LCLK
  756. _enter_pwrlock(&pwrpriv->lock);
  757. #endif
  758. //if(pwrpriv->pwr_mode == PS_MODE_ACTIVE)
  759. if(ps_mode == PS_MODE_ACTIVE)
  760. {
  761. if (1
  762. #ifdef CONFIG_BT_COEXIST
  763. && (((rtw_btcoex_IsBtControlLps(padapter) == _FALSE)
  764. #ifdef CONFIG_P2P_PS
  765. && (pwdinfo->opp_ps == 0)
  766. #endif // CONFIG_P2P_PS
  767. )
  768. || ((rtw_btcoex_IsBtControlLps(padapter) == _TRUE)
  769. && (rtw_btcoex_IsLpsOn(padapter) == _FALSE))
  770. )
  771. #else // !CONFIG_BT_COEXIST
  772. #ifdef CONFIG_P2P_PS
  773. && (pwdinfo->opp_ps == 0)
  774. #endif // CONFIG_P2P_PS
  775. #endif // !CONFIG_BT_COEXIST
  776. )
  777. {
  778. DBG_871X(FUNC_ADPT_FMT" Leave 802.11 power save - %s\n",
  779. FUNC_ADPT_ARG(padapter), msg);
  780. if (pwrpriv->lps_leave_cnts < UINT_MAX)
  781. pwrpriv->lps_leave_cnts++;
  782. else
  783. pwrpriv->lps_leave_cnts = 0;
  784. #ifdef CONFIG_TDLS
  785. for(i=0; i< NUM_STA; i++)
  786. {
  787. phead = &(pstapriv->sta_hash[i]);
  788. plist = get_next(phead);
  789. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
  790. {
  791. ptdls_sta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
  792. if( ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE )
  793. issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta->hwaddr, 0, 0, 0);
  794. plist = get_next(plist);
  795. }
  796. }
  797. #endif //CONFIG_TDLS
  798. pwrpriv->pwr_mode = ps_mode;
  799. rtw_set_rpwm(padapter, PS_STATE_S4);
  800. #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN) || defined(CONFIG_P2P_WOWLAN)
  801. if (pwrpriv->wowlan_mode == _TRUE ||
  802. pwrpriv->wowlan_ap_mode == _TRUE ||
  803. pwrpriv->wowlan_p2p_mode == _TRUE)
  804. {
  805. u32 start_time, delay_ms;
  806. u8 val8;
  807. delay_ms = 20;
  808. start_time = rtw_get_current_time();
  809. do {
  810. rtw_hal_get_hwreg(padapter, HW_VAR_SYS_CLKR, &val8);
  811. if (!(val8 & BIT(4))){ //0x08 bit4 =1 --> in 32k, bit4 = 0 --> leave 32k
  812. pwrpriv->cpwm = PS_STATE_S4;
  813. break;
  814. }
  815. if (rtw_get_passing_time_ms(start_time) > delay_ms)
  816. {
  817. DBG_871X("%s: Wait for FW 32K leave more than %u ms!!!\n",
  818. __FUNCTION__, delay_ms);
  819. pdbgpriv->dbg_wow_leave_ps_fail_cnt++;
  820. break;
  821. }
  822. rtw_usleep_os(100);
  823. } while (1);
  824. }
  825. #endif
  826. rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode));
  827. pwrpriv->bFwCurrentInPSMode = _FALSE;
  828. #ifdef CONFIG_BT_COEXIST
  829. rtw_btcoex_LpsNotify(padapter, ps_mode);
  830. #endif // CONFIG_BT_COEXIST
  831. }
  832. }
  833. else
  834. {
  835. if ((PS_RDY_CHECK(padapter) && check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE))
  836. #ifdef CONFIG_BT_COEXIST
  837. || ((rtw_btcoex_IsBtControlLps(padapter) == _TRUE)
  838. && (rtw_btcoex_IsLpsOn(padapter) == _TRUE))
  839. #endif
  840. #ifdef CONFIG_P2P_WOWLAN
  841. ||( _TRUE == pwrpriv->wowlan_p2p_mode)
  842. #endif //CONFIG_P2P_WOWLAN
  843. )
  844. {
  845. u8 pslv;
  846. DBG_871X(FUNC_ADPT_FMT" Enter 802.11 power save - %s\n",
  847. FUNC_ADPT_ARG(padapter), msg);
  848. if (pwrpriv->lps_enter_cnts < UINT_MAX)
  849. pwrpriv->lps_enter_cnts++;
  850. else
  851. pwrpriv->lps_enter_cnts = 0;
  852. #ifdef CONFIG_TDLS
  853. for(i=0; i< NUM_STA; i++)
  854. {
  855. phead = &(pstapriv->sta_hash[i]);
  856. plist = get_next(phead);
  857. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
  858. {
  859. ptdls_sta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
  860. if( ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE )
  861. issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta->hwaddr, 1, 0, 0);
  862. plist = get_next(plist);
  863. }
  864. }
  865. #endif //CONFIG_TDLS
  866. #ifdef CONFIG_BT_COEXIST
  867. rtw_btcoex_LpsNotify(padapter, ps_mode);
  868. #endif // CONFIG_BT_COEXIST
  869. pwrpriv->bFwCurrentInPSMode = _TRUE;
  870. pwrpriv->pwr_mode = ps_mode;
  871. pwrpriv->smart_ps = smart_ps;
  872. pwrpriv->bcn_ant_mode = bcn_ant_mode;
  873. rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode));
  874. #ifdef CONFIG_P2P_PS
  875. // Set CTWindow after LPS
  876. if(pwdinfo->opp_ps == 1)
  877. p2p_ps_wk_cmd(padapter, P2P_PS_ENABLE, 0);
  878. #endif //CONFIG_P2P_PS
  879. pslv = PS_STATE_S2;
  880. #ifdef CONFIG_LPS_LCLK
  881. if (pwrpriv->alives == 0)
  882. pslv = PS_STATE_S0;
  883. #endif // CONFIG_LPS_LCLK
  884. #ifdef CONFIG_BT_COEXIST
  885. if ((rtw_btcoex_IsBtDisabled(padapter) == _FALSE)
  886. && (rtw_btcoex_IsBtControlLps(padapter) == _TRUE))
  887. {
  888. u8 val8;
  889. val8 = rtw_btcoex_LpsVal(padapter);
  890. if (val8 & BIT(4))
  891. pslv = PS_STATE_S2;
  892. }
  893. #endif // CONFIG_BT_COEXIST
  894. rtw_set_rpwm(padapter, pslv);
  895. }
  896. }
  897. #ifdef CONFIG_LPS_LCLK
  898. _exit_pwrlock(&pwrpriv->lock);
  899. #endif
  900. _func_exit_;
  901. }
  902. /*
  903. * Return:
  904. * 0: Leave OK
  905. * -1: Timeout
  906. * -2: Other error
  907. */
  908. s32 LPS_RF_ON_check(PADAPTER padapter, u32 delay_ms)
  909. {
  910. u32 start_time;
  911. u8 bAwake = _FALSE;
  912. s32 err = 0;
  913. start_time = rtw_get_current_time();
  914. while (1)
  915. {
  916. rtw_hal_get_hwreg(padapter, HW_VAR_FWLPS_RF_ON, &bAwake);
  917. if (_TRUE == bAwake)
  918. break;
  919. if (rtw_is_surprise_removed(padapter)) {
  920. err = -2;
  921. DBG_871X("%s: device surprise removed!!\n", __FUNCTION__);
  922. break;
  923. }
  924. if (rtw_get_passing_time_ms(start_time) > delay_ms)
  925. {
  926. err = -1;
  927. DBG_871X("%s: Wait for FW LPS leave more than %u ms!!!\n", __FUNCTION__, delay_ms);
  928. break;
  929. }
  930. rtw_usleep_os(100);
  931. }
  932. return err;
  933. }
  934. //
  935. // Description:
  936. // Enter the leisure power save mode.
  937. //
  938. void LPS_Enter(PADAPTER padapter, const char *msg)
  939. {
  940. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  941. struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
  942. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  943. _adapter *buddy = padapter->pbuddy_adapter;
  944. int n_assoc_iface = 0;
  945. int i;
  946. char buf[32] = {0};
  947. _func_enter_;
  948. // DBG_871X("+LeisurePSEnter\n");
  949. #ifdef CONFIG_BT_COEXIST
  950. if (rtw_btcoex_IsBtControlLps(padapter) == _TRUE)
  951. return;
  952. #endif
  953. /* Skip lps enter request if number of assocated adapters is not 1 */
  954. for (i = 0; i < dvobj->iface_nums; i++) {
  955. if (check_fwstate(&(dvobj->padapters[i]->mlmepriv), WIFI_ASOC_STATE))
  956. n_assoc_iface++;
  957. }
  958. if (n_assoc_iface != 1)
  959. return;
  960. /* Skip lps enter request for adapter not port0 */
  961. if (get_iface_type(padapter) != IFACE_PORT0)
  962. return;
  963. for (i = 0; i < dvobj->iface_nums; i++) {
  964. if (PS_RDY_CHECK(dvobj->padapters[i]) == _FALSE)
  965. return;
  966. }
  967. #ifdef CONFIG_P2P_PS
  968. if(padapter->wdinfo.p2p_ps_mode == P2P_PS_NOA)
  969. {
  970. return;//supporting p2p client ps NOA via H2C_8723B_P2P_PS_OFFLOAD
  971. }
  972. #endif //CONFIG_P2P_PS
  973. if (pwrpriv->bLeisurePs)
  974. {
  975. // Idle for a while if we connect to AP a while ago.
  976. if (pwrpriv->LpsIdleCount >= 2) // 4 Sec
  977. {
  978. if(pwrpriv->pwr_mode == PS_MODE_ACTIVE)
  979. {
  980. sprintf(buf, "WIFI-%s", msg);
  981. pwrpriv->bpower_saving = _TRUE;
  982. rtw_set_ps_mode(padapter, pwrpriv->power_mgnt, padapter->registrypriv.smart_ps, 0, buf);
  983. }
  984. }
  985. else
  986. pwrpriv->LpsIdleCount++;
  987. }
  988. // DBG_871X("-LeisurePSEnter\n");
  989. _func_exit_;
  990. }
  991. //
  992. // Description:
  993. // Leave the leisure power save mode.
  994. //
  995. void LPS_Leave(PADAPTER padapter, const char *msg)
  996. {
  997. #define LPS_LEAVE_TIMEOUT_MS 100
  998. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  999. struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
  1000. u32 start_time;
  1001. u8 bAwake = _FALSE;
  1002. char buf[32] = {0};
  1003. struct debug_priv *pdbgpriv = &dvobj->drv_dbg;
  1004. _func_enter_;
  1005. // DBG_871X("+LeisurePSLeave\n");
  1006. #ifdef CONFIG_BT_COEXIST
  1007. if (rtw_btcoex_IsBtControlLps(padapter) == _TRUE)
  1008. return;
  1009. #endif
  1010. if (pwrpriv->bLeisurePs)
  1011. {
  1012. if(pwrpriv->pwr_mode != PS_MODE_ACTIVE)
  1013. {
  1014. sprintf(buf, "WIFI-%s", msg);
  1015. rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0, buf);
  1016. if(pwrpriv->pwr_mode == PS_MODE_ACTIVE)
  1017. LPS_RF_ON_check(padapter, LPS_LEAVE_TIMEOUT_MS);
  1018. }
  1019. }
  1020. pwrpriv->bpower_saving = _FALSE;
  1021. #ifdef DBG_CHECK_FW_PS_STATE
  1022. if(rtw_fw_ps_state(padapter) == _FAIL)
  1023. {
  1024. DBG_871X("leave lps, fw in 32k\n");
  1025. pdbgpriv->dbg_leave_lps_fail_cnt++;
  1026. }
  1027. #endif //DBG_CHECK_FW_PS_STATE
  1028. // DBG_871X("-LeisurePSLeave\n");
  1029. _func_exit_;
  1030. }
  1031. #endif
  1032. void LeaveAllPowerSaveModeDirect(PADAPTER Adapter)
  1033. {
  1034. PADAPTER pri_padapter = GET_PRIMARY_ADAPTER(Adapter);
  1035. struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
  1036. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(Adapter);
  1037. struct dvobj_priv *psdpriv = Adapter->dvobj;
  1038. struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
  1039. #ifndef CONFIG_DETECT_CPWM_BY_POLLING
  1040. u8 cpwm_orig, cpwm_now;
  1041. u32 start_time;
  1042. #endif // CONFIG_DETECT_CPWM_BY_POLLING
  1043. _func_enter_;
  1044. DBG_871X("%s.....\n",__FUNCTION__);
  1045. if (rtw_is_surprise_removed(Adapter)) {
  1046. DBG_871X(FUNC_ADPT_FMT ": bSurpriseRemoved=_TRUE Skip!\n", FUNC_ADPT_ARG(Adapter));
  1047. return;
  1048. }
  1049. if ((check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  1050. #ifdef CONFIG_CONCURRENT_MODE
  1051. || (check_buddy_fwstate(Adapter,_FW_LINKED) == _TRUE)
  1052. #endif
  1053. )
  1054. { //connect
  1055. if(pwrpriv->pwr_mode == PS_MODE_ACTIVE) {
  1056. DBG_871X("%s: Driver Already Leave LPS\n",__FUNCTION__);
  1057. return;
  1058. }
  1059. #ifdef CONFIG_LPS_LCLK
  1060. _enter_pwrlock(&pwrpriv->lock);
  1061. #ifndef CONFIG_DETECT_CPWM_BY_POLLING
  1062. cpwm_orig = 0;
  1063. rtw_hal_get_hwreg(Adapter, HW_VAR_CPWM, &cpwm_orig);
  1064. #endif //CONFIG_DETECT_CPWM_BY_POLLING
  1065. rtw_set_rpwm(Adapter, PS_STATE_S4);
  1066. #ifndef CONFIG_DETECT_CPWM_BY_POLLING
  1067. start_time = rtw_get_current_time();
  1068. // polling cpwm
  1069. do {
  1070. rtw_mdelay_os(1);
  1071. rtw_hal_get_hwreg(Adapter, HW_VAR_CPWM, &cpwm_now);
  1072. if ((cpwm_orig ^ cpwm_now) & 0x80)
  1073. {
  1074. pwrpriv->cpwm = PS_STATE_S4;
  1075. pwrpriv->cpwm_tog = cpwm_now & PS_TOGGLE;
  1076. #ifdef DBG_CHECK_FW_PS_STATE
  1077. DBG_871X("%s: polling cpwm OK! cpwm_orig=%02x, cpwm_now=%02x, 0x100=0x%x \n"
  1078. , __FUNCTION__, cpwm_orig, cpwm_now, rtw_read8(Adapter, REG_CR));
  1079. if(rtw_fw_ps_state(Adapter) == _FAIL)
  1080. {
  1081. DBG_871X("%s: leave 32k but fw state in 32k\n", __FUNCTION__);
  1082. pdbgpriv->dbg_rpwm_toogle_cnt++;
  1083. }
  1084. #endif //DBG_CHECK_FW_PS_STATE
  1085. break;
  1086. }
  1087. if (rtw_get_passing_time_ms(start_time) > LPS_RPWM_WAIT_MS)
  1088. {
  1089. DBG_871X("%s: polling cpwm timeout! cpwm_orig=%02x, cpwm_now=%02x \n", __FUNCTION__, cpwm_orig, cpwm_now);
  1090. #ifdef DBG_CHECK_FW_PS_STATE
  1091. if(rtw_fw_ps_state(Adapter) == _FAIL)
  1092. {
  1093. DBG_871X("rpwm timeout and fw ps state in 32k\n");
  1094. pdbgpriv->dbg_rpwm_timeout_fail_cnt++;
  1095. }
  1096. #endif //DBG_CHECK_FW_PS_STATE
  1097. break;
  1098. }
  1099. } while (1);
  1100. #endif // CONFIG_DETECT_CPWM_BY_POLLING
  1101. _exit_pwrlock(&pwrpriv->lock);
  1102. #endif
  1103. #ifdef CONFIG_P2P_PS
  1104. p2p_ps_wk_cmd(pri_padapter, P2P_PS_DISABLE, 0);
  1105. #endif //CONFIG_P2P_PS
  1106. #ifdef CONFIG_LPS
  1107. rtw_lps_ctrl_wk_cmd(pri_padapter, LPS_CTRL_LEAVE, 0);
  1108. #endif
  1109. }
  1110. else
  1111. {
  1112. if(pwrpriv->rf_pwrstate== rf_off)
  1113. {
  1114. #ifdef CONFIG_AUTOSUSPEND
  1115. if(Adapter->registrypriv.usbss_enable)
  1116. {
  1117. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
  1118. usb_disable_autosuspend(adapter_to_dvobj(Adapter)->pusbdev);
  1119. #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22) && LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,34))
  1120. adapter_to_dvobj(Adapter)->pusbdev->autosuspend_disabled = Adapter->bDisableAutosuspend;//autosuspend disabled by the user
  1121. #endif
  1122. }
  1123. else
  1124. #endif
  1125. {
  1126. #if defined(CONFIG_FWLPS_IN_IPS) || defined(CONFIG_SWLPS_IN_IPS) || defined(CONFIG_RTL8188E)
  1127. #ifdef CONFIG_IPS
  1128. if(_FALSE == ips_leave(pri_padapter))
  1129. {
  1130. DBG_871X("======> ips_leave fail.............\n");
  1131. }
  1132. #endif
  1133. #endif //CONFIG_SWLPS_IN_IPS || (CONFIG_PLATFORM_SPRD && CONFIG_RTL8188E)
  1134. }
  1135. }
  1136. }
  1137. _func_exit_;
  1138. }
  1139. //
  1140. // Description: Leave all power save mode: LPS, FwLPS, IPS if needed.
  1141. // Move code to function by tynli. 2010.03.26.
  1142. //
  1143. void LeaveAllPowerSaveMode(IN PADAPTER Adapter)
  1144. {
  1145. struct dvobj_priv *dvobj = adapter_to_dvobj(Adapter);
  1146. struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
  1147. u8 enqueue = 0;
  1148. int n_assoc_iface = 0;
  1149. int i;
  1150. _func_enter_;
  1151. //DBG_871X("%s.....\n",__FUNCTION__);
  1152. if (_FALSE == Adapter->bup)
  1153. {
  1154. DBG_871X(FUNC_ADPT_FMT ": bup=%d Skip!\n",
  1155. FUNC_ADPT_ARG(Adapter), Adapter->bup);
  1156. return;
  1157. }
  1158. if (rtw_is_surprise_removed(Adapter)) {
  1159. DBG_871X(FUNC_ADPT_FMT ": bSurpriseRemoved=_TRUE Skip!\n", FUNC_ADPT_ARG(Adapter));
  1160. return;
  1161. }
  1162. for (i = 0; i < dvobj->iface_nums; i++) {
  1163. if (check_fwstate(&(dvobj->padapters[i]->mlmepriv), WIFI_ASOC_STATE))
  1164. n_assoc_iface++;
  1165. }
  1166. if (n_assoc_iface)
  1167. { //connect
  1168. #ifdef CONFIG_LPS_LCLK
  1169. enqueue = 1;
  1170. #endif
  1171. #ifdef CONFIG_P2P_PS
  1172. p2p_ps_wk_cmd(Adapter, P2P_PS_DISABLE, enqueue);
  1173. #endif //CONFIG_P2P_PS
  1174. #ifdef CONFIG_LPS
  1175. rtw_lps_ctrl_wk_cmd(Adapter, LPS_CTRL_LEAVE, enqueue);
  1176. #endif
  1177. #ifdef CONFIG_LPS_LCLK
  1178. LPS_Leave_check(Adapter);
  1179. #endif
  1180. }
  1181. else
  1182. {
  1183. if(adapter_to_pwrctl(Adapter)->rf_pwrstate== rf_off)
  1184. {
  1185. #ifdef CONFIG_AUTOSUSPEND
  1186. if(Adapter->registrypriv.usbss_enable)
  1187. {
  1188. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
  1189. usb_disable_autosuspend(adapter_to_dvobj(Adapter)->pusbdev);
  1190. #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22) && LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,34))
  1191. adapter_to_dvobj(Adapter)->pusbdev->autosuspend_disabled = Adapter->bDisableAutosuspend;//autosuspend disabled by the user
  1192. #endif
  1193. }
  1194. else
  1195. #endif
  1196. {
  1197. #if defined(CONFIG_FWLPS_IN_IPS) || defined(CONFIG_SWLPS_IN_IPS) || (defined(CONFIG_PLATFORM_SPRD) && defined(CONFIG_RTL8188E))
  1198. #ifdef CONFIG_IPS
  1199. if(_FALSE == ips_leave(Adapter))
  1200. {
  1201. DBG_871X("======> ips_leave fail.............\n");
  1202. }
  1203. #endif
  1204. #endif //CONFIG_SWLPS_IN_IPS || (CONFIG_PLATFORM_SPRD && CONFIG_RTL8188E)
  1205. }
  1206. }
  1207. }
  1208. _func_exit_;
  1209. }
  1210. #ifdef CONFIG_LPS_LCLK
  1211. void LPS_Leave_check(
  1212. PADAPTER padapter)
  1213. {
  1214. struct pwrctrl_priv *pwrpriv;
  1215. u32 start_time;
  1216. u8 bReady;
  1217. _func_enter_;
  1218. pwrpriv = adapter_to_pwrctl(padapter);
  1219. bReady = _FALSE;
  1220. start_time = rtw_get_current_time();
  1221. rtw_yield_os();
  1222. while(1)
  1223. {
  1224. _enter_pwrlock(&pwrpriv->lock);
  1225. if (rtw_is_surprise_removed(padapter)
  1226. || (!rtw_is_hw_init_completed(padapter))
  1227. #ifdef CONFIG_USB_HCI
  1228. || rtw_is_drv_stopped(padapter)
  1229. #endif
  1230. || (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
  1231. )
  1232. {
  1233. bReady = _TRUE;
  1234. }
  1235. _exit_pwrlock(&pwrpriv->lock);
  1236. if(_TRUE == bReady)
  1237. break;
  1238. if(rtw_get_passing_time_ms(start_time)>100)
  1239. {
  1240. DBG_871X("Wait for cpwm event than 100 ms!!!\n");
  1241. break;
  1242. }
  1243. rtw_msleep_os(1);
  1244. }
  1245. _func_exit_;
  1246. }
  1247. /*
  1248. * Caller:ISR handler...
  1249. *
  1250. * This will be called when CPWM interrupt is up.
  1251. *
  1252. * using to update cpwn of drv; and drv willl make a decision to up or down pwr level
  1253. */
  1254. void cpwm_int_hdl(
  1255. PADAPTER padapter,
  1256. struct reportpwrstate_parm *preportpwrstate)
  1257. {
  1258. struct pwrctrl_priv *pwrpriv;
  1259. _func_enter_;
  1260. pwrpriv = adapter_to_pwrctl(padapter);
  1261. #if 0
  1262. if (pwrpriv->cpwm_tog == (preportpwrstate->state & PS_TOGGLE)) {
  1263. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
  1264. ("cpwm_int_hdl: tog(old)=0x%02x cpwm(new)=0x%02x toggle bit didn't change!?\n",
  1265. pwrpriv->cpwm_tog, preportpwrstate->state));
  1266. goto exit;
  1267. }
  1268. #endif
  1269. _enter_pwrlock(&pwrpriv->lock);
  1270. #ifdef CONFIG_LPS_RPWM_TIMER
  1271. if (pwrpriv->rpwm < PS_STATE_S2)
  1272. {
  1273. DBG_871X("%s: Redundant CPWM Int. RPWM=0x%02X CPWM=0x%02x\n", __func__, pwrpriv->rpwm, pwrpriv->cpwm);
  1274. _exit_pwrlock(&pwrpriv->lock);
  1275. goto exit;
  1276. }
  1277. #endif // CONFIG_LPS_RPWM_TIMER
  1278. pwrpriv->cpwm = PS_STATE(preportpwrstate->state);
  1279. pwrpriv->cpwm_tog = preportpwrstate->state & PS_TOGGLE;
  1280. if (pwrpriv->cpwm >= PS_STATE_S2)
  1281. {
  1282. if (pwrpriv->alives & CMD_ALIVE)
  1283. _rtw_up_sema(&padapter->cmdpriv.cmd_queue_sema);
  1284. if (pwrpriv->alives & XMIT_ALIVE)
  1285. _rtw_up_sema(&padapter->xmitpriv.xmit_sema);
  1286. }
  1287. _exit_pwrlock(&pwrpriv->lock);
  1288. exit:
  1289. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
  1290. ("cpwm_int_hdl: cpwm=0x%02x\n", pwrpriv->cpwm));
  1291. _func_exit_;
  1292. }
  1293. static void cpwm_event_callback(struct work_struct *work)
  1294. {
  1295. struct pwrctrl_priv *pwrpriv = container_of(work, struct pwrctrl_priv, cpwm_event);
  1296. struct dvobj_priv *dvobj = pwrctl_to_dvobj(pwrpriv);
  1297. _adapter *adapter = dvobj->padapters[IFACE_ID0];
  1298. struct reportpwrstate_parm report;
  1299. //DBG_871X("%s\n",__FUNCTION__);
  1300. report.state = PS_STATE_S2;
  1301. cpwm_int_hdl(adapter, &report);
  1302. }
  1303. #ifdef CONFIG_LPS_RPWM_TIMER
  1304. static void rpwmtimeout_workitem_callback(struct work_struct *work)
  1305. {
  1306. PADAPTER padapter;
  1307. struct dvobj_priv *dvobj;
  1308. struct pwrctrl_priv *pwrpriv;
  1309. pwrpriv = container_of(work, struct pwrctrl_priv, rpwmtimeoutwi);
  1310. dvobj = pwrctl_to_dvobj(pwrpriv);
  1311. padapter = dvobj->padapters[IFACE_ID0];
  1312. // DBG_871X("+%s: rpwm=0x%02X cpwm=0x%02X\n", __func__, pwrpriv->rpwm, pwrpriv->cpwm);
  1313. _enter_pwrlock(&pwrpriv->lock);
  1314. if ((pwrpriv->rpwm == pwrpriv->cpwm) || (pwrpriv->cpwm >= PS_STATE_S2))
  1315. {
  1316. DBG_871X("%s: rpwm=0x%02X cpwm=0x%02X CPWM done!\n", __func__, pwrpriv->rpwm, pwrpriv->cpwm);
  1317. goto exit;
  1318. }
  1319. _exit_pwrlock(&pwrpriv->lock);
  1320. if (rtw_read8(padapter, 0x100) != 0xEA)
  1321. {
  1322. #if 1
  1323. struct reportpwrstate_parm report;
  1324. report.state = PS_STATE_S2;
  1325. DBG_871X("\n%s: FW already leave 32K!\n\n", __func__);
  1326. cpwm_int_hdl(padapter, &report);
  1327. #else
  1328. DBG_871X("\n%s: FW already leave 32K!\n\n", __func__);
  1329. cpwm_event_callback(&pwrpriv->cpwm_event);
  1330. #endif
  1331. return;
  1332. }
  1333. _enter_pwrlock(&pwrpriv->lock);
  1334. if ((pwrpriv->rpwm == pwrpriv->cpwm) || (pwrpriv->cpwm >= PS_STATE_S2))
  1335. {
  1336. DBG_871X("%s: cpwm=%d, nothing to do!\n", __func__, pwrpriv->cpwm);
  1337. goto exit;
  1338. }
  1339. pwrpriv->brpwmtimeout = _TRUE;
  1340. rtw_set_rpwm(padapter, pwrpriv->rpwm);
  1341. pwrpriv->brpwmtimeout = _FALSE;
  1342. exit:
  1343. _exit_pwrlock(&pwrpriv->lock);
  1344. }
  1345. /*
  1346. * This function is a timer handler, can't do any IO in it.
  1347. */
  1348. static void pwr_rpwm_timeout_handler(void *FunctionContext)
  1349. {
  1350. PADAPTER padapter;
  1351. struct pwrctrl_priv *pwrpriv;
  1352. padapter = (PADAPTER)FunctionContext;
  1353. pwrpriv = adapter_to_pwrctl(padapter);
  1354. DBG_871X("+%s: rpwm=0x%02X cpwm=0x%02X\n", __func__, pwrpriv->rpwm, pwrpriv->cpwm);
  1355. if ((pwrpriv->rpwm == pwrpriv->cpwm) || (pwrpriv->cpwm >= PS_STATE_S2))
  1356. {
  1357. DBG_871X("+%s: cpwm=%d, nothing to do!\n", __func__, pwrpriv->cpwm);
  1358. return;
  1359. }
  1360. _set_workitem(&pwrpriv->rpwmtimeoutwi);
  1361. }
  1362. #endif // CONFIG_LPS_RPWM_TIMER
  1363. __inline static void register_task_alive(struct pwrctrl_priv *pwrctrl, u32 tag)
  1364. {
  1365. pwrctrl->alives |= tag;
  1366. }
  1367. __inline static void unregister_task_alive(struct pwrctrl_priv *pwrctrl, u32 tag)
  1368. {
  1369. pwrctrl->alives &= ~tag;
  1370. }
  1371. /*
  1372. * Description:
  1373. * Check if the fw_pwrstate is okay for I/O.
  1374. * If not (cpwm is less than S2), then the sub-routine
  1375. * will raise the cpwm to be greater than or equal to S2.
  1376. *
  1377. * Calling Context: Passive
  1378. *
  1379. * Constraint:
  1380. * 1. this function will request pwrctrl->lock
  1381. *
  1382. * Return Value:
  1383. * _SUCCESS hardware is ready for I/O
  1384. * _FAIL can't I/O right now
  1385. */
  1386. s32 rtw_register_task_alive(PADAPTER padapter, u32 task)
  1387. {
  1388. s32 res;
  1389. struct pwrctrl_priv *pwrctrl;
  1390. u8 pslv;
  1391. _func_enter_;
  1392. res = _SUCCESS;
  1393. pwrctrl = adapter_to_pwrctl(padapter);
  1394. pslv = PS_STATE_S2;
  1395. _enter_pwrlock(&pwrctrl->lock);
  1396. register_task_alive(pwrctrl, task);
  1397. if (pwrctrl->bFwCurrentInPSMode == _TRUE)
  1398. {
  1399. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
  1400. ("%s: task=0x%x cpwm=0x%02x alives=0x%08x\n",
  1401. __FUNCTION__, task, pwrctrl->cpwm, pwrctrl->alives));
  1402. if (pwrctrl->cpwm < pslv)
  1403. {
  1404. if (pwrctrl->cpwm < PS_STATE_S2)
  1405. res = _FAIL;
  1406. if (pwrctrl->rpwm < pslv)
  1407. rtw_set_rpwm(padapter, pslv);
  1408. }
  1409. }
  1410. _exit_pwrlock(&pwrctrl->lock);
  1411. #ifdef CONFIG_DETECT_CPWM_BY_POLLING
  1412. if (_FAIL == res)
  1413. {
  1414. if (pwrctrl->cpwm >= PS_STATE_S2)
  1415. res = _SUCCESS;
  1416. }
  1417. #endif // CONFIG_DETECT_CPWM_BY_POLLING
  1418. _func_exit_;
  1419. return res;
  1420. }
  1421. /*
  1422. * Description:
  1423. * If task is done, call this func. to power down firmware again.
  1424. *
  1425. * Constraint:
  1426. * 1. this function will request pwrctrl->lock
  1427. *
  1428. * Return Value:
  1429. * none
  1430. */
  1431. void rtw_unregister_task_alive(PADAPTER padapter, u32 task)
  1432. {
  1433. struct pwrctrl_priv *pwrctrl;
  1434. u8 pslv;
  1435. _func_enter_;
  1436. pwrctrl = adapter_to_pwrctl(padapter);
  1437. pslv = PS_STATE_S0;
  1438. #ifdef CONFIG_BT_COEXIST
  1439. if ((rtw_btcoex_IsBtDisabled(padapter) == _FALSE)
  1440. && (rtw_btcoex_IsBtControlLps(padapter) == _TRUE))
  1441. {
  1442. u8 val8;
  1443. val8 = rtw_btcoex_LpsVal(padapter);
  1444. if (val8 & BIT(4))
  1445. pslv = PS_STATE_S2;
  1446. }
  1447. #endif // CONFIG_BT_COEXIST
  1448. _enter_pwrlock(&pwrctrl->lock);
  1449. unregister_task_alive(pwrctrl, task);
  1450. if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE)
  1451. && (pwrctrl->bFwCurrentInPSMode == _TRUE))
  1452. {
  1453. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
  1454. ("%s: cpwm=0x%02x alives=0x%08x\n",
  1455. __FUNCTION__, pwrctrl->cpwm, pwrctrl->alives));
  1456. if (pwrctrl->cpwm > pslv)
  1457. {
  1458. if ((pslv >= PS_STATE_S2) || (pwrctrl->alives == 0))
  1459. rtw_set_rpwm(padapter, pslv);
  1460. }
  1461. }
  1462. _exit_pwrlock(&pwrctrl->lock);
  1463. _func_exit_;
  1464. }
  1465. /*
  1466. * Caller: rtw_xmit_thread
  1467. *
  1468. * Check if the fw_pwrstate is okay for xmit.
  1469. * If not (cpwm is less than S3), then the sub-routine
  1470. * will raise the cpwm to be greater than or equal to S3.
  1471. *
  1472. * Calling Context: Passive
  1473. *
  1474. * Return Value:
  1475. * _SUCCESS rtw_xmit_thread can write fifo/txcmd afterwards.
  1476. * _FAIL rtw_xmit_thread can not do anything.
  1477. */
  1478. s32 rtw_register_tx_alive(PADAPTER padapter)
  1479. {
  1480. s32 res;
  1481. struct pwrctrl_priv *pwrctrl;
  1482. u8 pslv;
  1483. _func_enter_;
  1484. res = _SUCCESS;
  1485. pwrctrl = adapter_to_pwrctl(padapter);
  1486. pslv = PS_STATE_S2;
  1487. _enter_pwrlock(&pwrctrl->lock);
  1488. register_task_alive(pwrctrl, XMIT_ALIVE);
  1489. if (pwrctrl->bFwCurrentInPSMode == _TRUE)
  1490. {
  1491. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
  1492. ("rtw_register_tx_alive: cpwm=0x%02x alives=0x%08x\n",
  1493. pwrctrl->cpwm, pwrctrl->alives));
  1494. if (pwrctrl->cpwm < pslv)
  1495. {
  1496. if (pwrctrl->cpwm < PS_STATE_S2)
  1497. res = _FAIL;
  1498. if (pwrctrl->rpwm < pslv)
  1499. rtw_set_rpwm(padapter, pslv);
  1500. }
  1501. }
  1502. _exit_pwrlock(&pwrctrl->lock);
  1503. #ifdef CONFIG_DETECT_CPWM_BY_POLLING
  1504. if (_FAIL == res)
  1505. {
  1506. if (pwrctrl->cpwm >= PS_STATE_S2)
  1507. res = _SUCCESS;
  1508. }
  1509. #endif // CONFIG_DETECT_CPWM_BY_POLLING
  1510. _func_exit_;
  1511. return res;
  1512. }
  1513. /*
  1514. * Caller: rtw_cmd_thread
  1515. *
  1516. * Check if the fw_pwrstate is okay for issuing cmd.
  1517. * If not (cpwm should be is less than S2), then the sub-routine
  1518. * will raise the cpwm to be greater than or equal to S2.
  1519. *
  1520. * Calling Context: Passive
  1521. *
  1522. * Return Value:
  1523. * _SUCCESS rtw_cmd_thread can issue cmds to firmware afterwards.
  1524. * _FAIL rtw_cmd_thread can not do anything.
  1525. */
  1526. s32 rtw_register_cmd_alive(PADAPTER padapter)
  1527. {
  1528. s32 res;
  1529. struct pwrctrl_priv *pwrctrl;
  1530. u8 pslv;
  1531. _func_enter_;
  1532. res = _SUCCESS;
  1533. pwrctrl = adapter_to_pwrctl(padapter);
  1534. pslv = PS_STATE_S2;
  1535. _enter_pwrlock(&pwrctrl->lock);
  1536. register_task_alive(pwrctrl, CMD_ALIVE);
  1537. if (pwrctrl->bFwCurrentInPSMode == _TRUE)
  1538. {
  1539. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_info_,
  1540. ("rtw_register_cmd_alive: cpwm=0x%02x alives=0x%08x\n",
  1541. pwrctrl->cpwm, pwrctrl->alives));
  1542. if (pwrctrl->cpwm < pslv)
  1543. {
  1544. if (pwrctrl->cpwm < PS_STATE_S2)
  1545. res = _FAIL;
  1546. if (pwrctrl->rpwm < pslv)
  1547. rtw_set_rpwm(padapter, pslv);
  1548. }
  1549. }
  1550. _exit_pwrlock(&pwrctrl->lock);
  1551. #ifdef CONFIG_DETECT_CPWM_BY_POLLING
  1552. if (_FAIL == res)
  1553. {
  1554. if (pwrctrl->cpwm >= PS_STATE_S2)
  1555. res = _SUCCESS;
  1556. }
  1557. #endif // CONFIG_DETECT_CPWM_BY_POLLING
  1558. _func_exit_;
  1559. return res;
  1560. }
  1561. /*
  1562. * Caller: rx_isr
  1563. *
  1564. * Calling Context: Dispatch/ISR
  1565. *
  1566. * Return Value:
  1567. * _SUCCESS
  1568. * _FAIL
  1569. */
  1570. s32 rtw_register_rx_alive(PADAPTER padapter)
  1571. {
  1572. struct pwrctrl_priv *pwrctrl;
  1573. _func_enter_;
  1574. pwrctrl = adapter_to_pwrctl(padapter);
  1575. _enter_pwrlock(&pwrctrl->lock);
  1576. register_task_alive(pwrctrl, RECV_ALIVE);
  1577. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
  1578. ("rtw_register_rx_alive: cpwm=0x%02x alives=0x%08x\n",
  1579. pwrctrl->cpwm, pwrctrl->alives));
  1580. _exit_pwrlock(&pwrctrl->lock);
  1581. _func_exit_;
  1582. return _SUCCESS;
  1583. }
  1584. /*
  1585. * Caller: evt_isr or evt_thread
  1586. *
  1587. * Calling Context: Dispatch/ISR or Passive
  1588. *
  1589. * Return Value:
  1590. * _SUCCESS
  1591. * _FAIL
  1592. */
  1593. s32 rtw_register_evt_alive(PADAPTER padapter)
  1594. {
  1595. struct pwrctrl_priv *pwrctrl;
  1596. _func_enter_;
  1597. pwrctrl = adapter_to_pwrctl(padapter);
  1598. _enter_pwrlock(&pwrctrl->lock);
  1599. register_task_alive(pwrctrl, EVT_ALIVE);
  1600. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
  1601. ("rtw_register_evt_alive: cpwm=0x%02x alives=0x%08x\n",
  1602. pwrctrl->cpwm, pwrctrl->alives));
  1603. _exit_pwrlock(&pwrctrl->lock);
  1604. _func_exit_;
  1605. return _SUCCESS;
  1606. }
  1607. /*
  1608. * Caller: ISR
  1609. *
  1610. * If ISR's txdone,
  1611. * No more pkts for TX,
  1612. * Then driver shall call this fun. to power down firmware again.
  1613. */
  1614. void rtw_unregister_tx_alive(PADAPTER padapter)
  1615. {
  1616. struct pwrctrl_priv *pwrctrl;
  1617. u8 pslv;
  1618. _func_enter_;
  1619. pwrctrl = adapter_to_pwrctl(padapter);
  1620. pslv = PS_STATE_S0;
  1621. #ifdef CONFIG_BT_COEXIST
  1622. if ((rtw_btcoex_IsBtDisabled(padapter) == _FALSE)
  1623. && (rtw_btcoex_IsBtControlLps(padapter) == _TRUE))
  1624. {
  1625. u8 val8;
  1626. val8 = rtw_btcoex_LpsVal(padapter);
  1627. if (val8 & BIT(4))
  1628. pslv = PS_STATE_S2;
  1629. }
  1630. #endif // CONFIG_BT_COEXIST
  1631. #ifdef CONFIG_P2P_PS
  1632. if(padapter->wdinfo.p2p_ps_mode > P2P_PS_NONE)
  1633. {
  1634. pslv = PS_STATE_S2;
  1635. }
  1636. #ifdef CONFIG_CONCURRENT_MODE
  1637. else if(rtw_buddy_adapter_up(padapter))
  1638. {
  1639. if(padapter->pbuddy_adapter->wdinfo.p2p_ps_mode > P2P_PS_NONE)
  1640. pslv = PS_STATE_S2;
  1641. }
  1642. #endif
  1643. #endif
  1644. _enter_pwrlock(&pwrctrl->lock);
  1645. unregister_task_alive(pwrctrl, XMIT_ALIVE);
  1646. if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE)
  1647. && (pwrctrl->bFwCurrentInPSMode == _TRUE))
  1648. {
  1649. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
  1650. ("%s: cpwm=0x%02x alives=0x%08x\n",
  1651. __FUNCTION__, pwrctrl->cpwm, pwrctrl->alives));
  1652. if (pwrctrl->cpwm > pslv)
  1653. {
  1654. if ((pslv >= PS_STATE_S2) || (pwrctrl->alives == 0))
  1655. rtw_set_rpwm(padapter, pslv);
  1656. }
  1657. }
  1658. _exit_pwrlock(&pwrctrl->lock);
  1659. _func_exit_;
  1660. }
  1661. /*
  1662. * Caller: ISR
  1663. *
  1664. * If all commands have been done,
  1665. * and no more command to do,
  1666. * then driver shall call this fun. to power down firmware again.
  1667. */
  1668. void rtw_unregister_cmd_alive(PADAPTER padapter)
  1669. {
  1670. struct pwrctrl_priv *pwrctrl;
  1671. u8 pslv;
  1672. _func_enter_;
  1673. pwrctrl = adapter_to_pwrctl(padapter);
  1674. pslv = PS_STATE_S0;
  1675. #ifdef CONFIG_BT_COEXIST
  1676. if ((rtw_btcoex_IsBtDisabled(padapter) == _FALSE)
  1677. && (rtw_btcoex_IsBtControlLps(padapter) == _TRUE))
  1678. {
  1679. u8 val8;
  1680. val8 = rtw_btcoex_LpsVal(padapter);
  1681. if (val8 & BIT(4))
  1682. pslv = PS_STATE_S2;
  1683. }
  1684. #endif // CONFIG_BT_COEXIST
  1685. #ifdef CONFIG_P2P_PS
  1686. if(padapter->wdinfo.p2p_ps_mode > P2P_PS_NONE)
  1687. {
  1688. pslv = PS_STATE_S2;
  1689. }
  1690. #ifdef CONFIG_CONCURRENT_MODE
  1691. else if(rtw_buddy_adapter_up(padapter))
  1692. {
  1693. if(padapter->pbuddy_adapter->wdinfo.p2p_ps_mode > P2P_PS_NONE)
  1694. pslv = PS_STATE_S2;
  1695. }
  1696. #endif
  1697. #endif
  1698. _enter_pwrlock(&pwrctrl->lock);
  1699. unregister_task_alive(pwrctrl, CMD_ALIVE);
  1700. if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE)
  1701. && (pwrctrl->bFwCurrentInPSMode == _TRUE))
  1702. {
  1703. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_info_,
  1704. ("%s: cpwm=0x%02x alives=0x%08x\n",
  1705. __FUNCTION__, pwrctrl->cpwm, pwrctrl->alives));
  1706. if (pwrctrl->cpwm > pslv)
  1707. {
  1708. if ((pslv >= PS_STATE_S2) || (pwrctrl->alives == 0))
  1709. rtw_set_rpwm(padapter, pslv);
  1710. }
  1711. }
  1712. _exit_pwrlock(&pwrctrl->lock);
  1713. _func_exit_;
  1714. }
  1715. /*
  1716. * Caller: ISR
  1717. */
  1718. void rtw_unregister_rx_alive(PADAPTER padapter)
  1719. {
  1720. struct pwrctrl_priv *pwrctrl;
  1721. _func_enter_;
  1722. pwrctrl = adapter_to_pwrctl(padapter);
  1723. _enter_pwrlock(&pwrctrl->lock);
  1724. unregister_task_alive(pwrctrl, RECV_ALIVE);
  1725. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
  1726. ("rtw_unregister_rx_alive: cpwm=0x%02x alives=0x%08x\n",
  1727. pwrctrl->cpwm, pwrctrl->alives));
  1728. _exit_pwrlock(&pwrctrl->lock);
  1729. _func_exit_;
  1730. }
  1731. void rtw_unregister_evt_alive(PADAPTER padapter)
  1732. {
  1733. struct pwrctrl_priv *pwrctrl;
  1734. _func_enter_;
  1735. pwrctrl = adapter_to_pwrctl(padapter);
  1736. unregister_task_alive(pwrctrl, EVT_ALIVE);
  1737. RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
  1738. ("rtw_unregister_evt_alive: cpwm=0x%02x alives=0x%08x\n",
  1739. pwrctrl->cpwm, pwrctrl->alives));
  1740. _exit_pwrlock(&pwrctrl->lock);
  1741. _func_exit_;
  1742. }
  1743. #endif /* CONFIG_LPS_LCLK */
  1744. #ifdef CONFIG_RESUME_IN_WORKQUEUE
  1745. static void resume_workitem_callback(struct work_struct *work);
  1746. #endif //CONFIG_RESUME_IN_WORKQUEUE
  1747. void rtw_init_pwrctrl_priv(PADAPTER padapter)
  1748. {
  1749. struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
  1750. int i = 0;
  1751. u8 val8 = 0;
  1752. #if defined(CONFIG_CONCURRENT_MODE)
  1753. if (padapter->adapter_type != PRIMARY_ADAPTER)
  1754. return;
  1755. #endif
  1756. _func_enter_;
  1757. #ifdef PLATFORM_WINDOWS
  1758. pwrctrlpriv->pnp_current_pwr_state=NdisDeviceStateD0;
  1759. #endif
  1760. _init_pwrlock(&pwrctrlpriv->lock);
  1761. _init_pwrlock(&pwrctrlpriv->check_32k_lock);
  1762. pwrctrlpriv->rf_pwrstate = rf_on;
  1763. pwrctrlpriv->ips_enter_cnts=0;
  1764. pwrctrlpriv->ips_leave_cnts=0;
  1765. pwrctrlpriv->lps_enter_cnts=0;
  1766. pwrctrlpriv->lps_leave_cnts=0;
  1767. pwrctrlpriv->bips_processing = _FALSE;
  1768. pwrctrlpriv->ips_mode = padapter->registrypriv.ips_mode;
  1769. pwrctrlpriv->ips_mode_req = padapter->registrypriv.ips_mode;
  1770. pwrctrlpriv->pwr_state_check_interval = RTW_PWR_STATE_CHK_INTERVAL;
  1771. pwrctrlpriv->pwr_state_check_cnts = 0;
  1772. pwrctrlpriv->bInternalAutoSuspend = _FALSE;
  1773. pwrctrlpriv->bInSuspend = _FALSE;
  1774. pwrctrlpriv->bkeepfwalive = _FALSE;
  1775. #ifdef CONFIG_AUTOSUSPEND
  1776. #ifdef SUPPORT_HW_RFOFF_DETECTED
  1777. pwrctrlpriv->pwr_state_check_interval = (pwrctrlpriv->bHWPwrPindetect) ?1000:2000;
  1778. #endif
  1779. #endif
  1780. pwrctrlpriv->LpsIdleCount = 0;
  1781. //pwrctrlpriv->FWCtrlPSMode =padapter->registrypriv.power_mgnt;// PS_MODE_MIN;
  1782. if (padapter->registrypriv.mp_mode == 1)
  1783. pwrctrlpriv->power_mgnt =PS_MODE_ACTIVE ;
  1784. else
  1785. pwrctrlpriv->power_mgnt =padapter->registrypriv.power_mgnt;// PS_MODE_MIN;
  1786. pwrctrlpriv->bLeisurePs = (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt)?_TRUE:_FALSE;
  1787. pwrctrlpriv->bFwCurrentInPSMode = _FALSE;
  1788. pwrctrlpriv->rpwm = 0;
  1789. pwrctrlpriv->cpwm = PS_STATE_S4;
  1790. pwrctrlpriv->pwr_mode = PS_MODE_ACTIVE;
  1791. pwrctrlpriv->smart_ps = padapter->registrypriv.smart_ps;
  1792. pwrctrlpriv->bcn_ant_mode = 0;
  1793. pwrctrlpriv->dtim = 0;
  1794. pwrctrlpriv->tog = 0x80;
  1795. #ifdef CONFIG_LPS_LCLK
  1796. rtw_hal_set_hwreg(padapter, HW_VAR_SET_RPWM, (u8 *)(&pwrctrlpriv->rpwm));
  1797. _init_workitem(&pwrctrlpriv->cpwm_event, cpwm_event_callback, NULL);
  1798. #ifdef CONFIG_LPS_RPWM_TIMER
  1799. pwrctrlpriv->brpwmtimeout = _FALSE;
  1800. _init_workitem(&pwrctrlpriv->rpwmtimeoutwi, rpwmtimeout_workitem_callback, NULL);
  1801. _init_timer(&pwrctrlpriv->pwr_rpwm_timer, padapter->pnetdev, pwr_rpwm_timeout_handler, padapter);
  1802. #endif // CONFIG_LPS_RPWM_TIMER
  1803. #endif // CONFIG_LPS_LCLK
  1804. rtw_init_timer(&pwrctrlpriv->pwr_state_check_timer, padapter, pwr_state_check_handler);
  1805. pwrctrlpriv->wowlan_mode = _FALSE;
  1806. pwrctrlpriv->wowlan_ap_mode = _FALSE;
  1807. pwrctrlpriv->wowlan_p2p_mode = _FALSE;
  1808. #ifdef CONFIG_RESUME_IN_WORKQUEUE
  1809. _init_workitem(&pwrctrlpriv->resume_work, resume_workitem_callback, NULL);
  1810. pwrctrlpriv->rtw_workqueue = create_singlethread_workqueue("rtw_workqueue");
  1811. #endif //CONFIG_RESUME_IN_WORKQUEUE
  1812. #if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
  1813. pwrctrlpriv->early_suspend.suspend = NULL;
  1814. rtw_register_early_suspend(pwrctrlpriv);
  1815. #endif //CONFIG_HAS_EARLYSUSPEND || CONFIG_ANDROID_POWER
  1816. #ifdef CONFIG_GPIO_WAKEUP
  1817. /*default low active*/
  1818. pwrctrlpriv->is_high_active = HIGH_ACTIVE;
  1819. val8 = (pwrctrlpriv->is_high_active == 0) ? 1 : 0;
  1820. rtw_hal_set_output_gpio(padapter, WAKEUP_GPIO_IDX, val8);
  1821. DBG_871X("%s: set GPIO_%d %d as default.\n",
  1822. __func__, WAKEUP_GPIO_IDX, val8);
  1823. #endif /* CONFIG_GPIO_WAKEUP */
  1824. #ifdef CONFIG_WOWLAN
  1825. pwrctrlpriv->wowlan_pattern_idx = 0;
  1826. for (i = 0 ; i < MAX_WKFM_NUM; i++) {
  1827. _rtw_memset(pwrctrlpriv->patterns[i].content, '\0',
  1828. sizeof(pwrctrlpriv->patterns[i].content));
  1829. _rtw_memset(pwrctrlpriv->patterns[i].mask, '\0',
  1830. sizeof(pwrctrlpriv->patterns[i].mask));
  1831. pwrctrlpriv->patterns[i].len = 0;
  1832. }
  1833. #ifdef CONFIG_PNO_SUPPORT
  1834. pwrctrlpriv->pno_inited = _FALSE;
  1835. pwrctrlpriv->pnlo_info = NULL;
  1836. pwrctrlpriv->pscan_info = NULL;
  1837. pwrctrlpriv->pno_ssid_list = NULL;
  1838. pwrctrlpriv->pno_in_resume = _TRUE;
  1839. #endif /* CONFIG_PNO_SUPPORT */
  1840. #endif /* CONFIG_WOWLAN */
  1841. _func_exit_;
  1842. }
  1843. void rtw_free_pwrctrl_priv(PADAPTER adapter)
  1844. {
  1845. struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(adapter);
  1846. #if defined(CONFIG_CONCURRENT_MODE)
  1847. if (adapter->adapter_type != PRIMARY_ADAPTER)
  1848. return;
  1849. #endif
  1850. _func_enter_;
  1851. //_rtw_memset((unsigned char *)pwrctrlpriv, 0, sizeof(struct pwrctrl_priv));
  1852. #ifdef CONFIG_RESUME_IN_WORKQUEUE
  1853. if (pwrctrlpriv->rtw_workqueue) {
  1854. flush_workqueue(pwrctrlpriv->rtw_workqueue);
  1855. destroy_workqueue(pwrctrlpriv->rtw_workqueue);
  1856. }
  1857. #endif
  1858. #ifdef CONFIG_WOWLAN
  1859. #ifdef CONFIG_PNO_SUPPORT
  1860. if (pwrctrlpriv->pnlo_info != NULL)
  1861. printk("****** pnlo_info memory leak********\n");
  1862. if (pwrctrlpriv->pscan_info != NULL)
  1863. printk("****** pscan_info memory leak********\n");
  1864. if (pwrctrlpriv->pno_ssid_list != NULL)
  1865. printk("****** pno_ssid_list memory leak********\n");
  1866. #endif
  1867. #endif /* CONFIG_WOWLAN */
  1868. #if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
  1869. rtw_unregister_early_suspend(pwrctrlpriv);
  1870. #endif //CONFIG_HAS_EARLYSUSPEND || CONFIG_ANDROID_POWER
  1871. _free_pwrlock(&pwrctrlpriv->lock);
  1872. _free_pwrlock(&pwrctrlpriv->check_32k_lock);
  1873. _func_exit_;
  1874. }
  1875. #ifdef CONFIG_RESUME_IN_WORKQUEUE
  1876. extern int rtw_resume_process(_adapter *padapter);
  1877. static void resume_workitem_callback(struct work_struct *work)
  1878. {
  1879. struct pwrctrl_priv *pwrpriv = container_of(work, struct pwrctrl_priv, resume_work);
  1880. struct dvobj_priv *dvobj = pwrctl_to_dvobj(pwrpriv);
  1881. _adapter *adapter = dvobj->padapters[IFACE_ID0];
  1882. DBG_871X("%s\n",__FUNCTION__);
  1883. rtw_resume_process(adapter);
  1884. rtw_resume_unlock_suspend();
  1885. }
  1886. void rtw_resume_in_workqueue(struct pwrctrl_priv *pwrpriv)
  1887. {
  1888. // accquire system's suspend lock preventing from falliing asleep while resume in workqueue
  1889. //rtw_lock_suspend();
  1890. rtw_resume_lock_suspend();
  1891. #if 1
  1892. queue_work(pwrpriv->rtw_workqueue, &pwrpriv->resume_work);
  1893. #else
  1894. _set_workitem(&pwrpriv->resume_work);
  1895. #endif
  1896. }
  1897. #endif //CONFIG_RESUME_IN_WORKQUEUE
  1898. #if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
  1899. inline bool rtw_is_earlysuspend_registered(struct pwrctrl_priv *pwrpriv)
  1900. {
  1901. return (pwrpriv->early_suspend.suspend) ? _TRUE : _FALSE;
  1902. }
  1903. inline bool rtw_is_do_late_resume(struct pwrctrl_priv *pwrpriv)
  1904. {
  1905. return (pwrpriv->do_late_resume) ? _TRUE : _FALSE;
  1906. }
  1907. inline void rtw_set_do_late_resume(struct pwrctrl_priv *pwrpriv, bool enable)
  1908. {
  1909. pwrpriv->do_late_resume = enable;
  1910. }
  1911. #endif
  1912. #ifdef CONFIG_HAS_EARLYSUSPEND
  1913. extern int rtw_resume_process(_adapter *padapter);
  1914. static void rtw_early_suspend(struct early_suspend *h)
  1915. {
  1916. struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
  1917. DBG_871X("%s\n",__FUNCTION__);
  1918. rtw_set_do_late_resume(pwrpriv, _FALSE);
  1919. }
  1920. static void rtw_late_resume(struct early_suspend *h)
  1921. {
  1922. struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
  1923. struct dvobj_priv *dvobj = pwrctl_to_dvobj(pwrpriv);
  1924. _adapter *adapter = dvobj->padapters[IFACE_ID0];
  1925. DBG_871X("%s\n",__FUNCTION__);
  1926. if(pwrpriv->do_late_resume) {
  1927. rtw_set_do_late_resume(pwrpriv, _FALSE);
  1928. rtw_resume_process(adapter);
  1929. }
  1930. }
  1931. void rtw_register_early_suspend(struct pwrctrl_priv *pwrpriv)
  1932. {
  1933. DBG_871X("%s\n", __FUNCTION__);
  1934. //jeff: set the early suspend level before blank screen, so we wll do late resume after scree is lit
  1935. pwrpriv->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
  1936. pwrpriv->early_suspend.suspend = rtw_early_suspend;
  1937. pwrpriv->early_suspend.resume = rtw_late_resume;
  1938. register_early_suspend(&pwrpriv->early_suspend);
  1939. }
  1940. void rtw_unregister_early_suspend(struct pwrctrl_priv *pwrpriv)
  1941. {
  1942. DBG_871X("%s\n", __FUNCTION__);
  1943. rtw_set_do_late_resume(pwrpriv, _FALSE);
  1944. if (pwrpriv->early_suspend.suspend)
  1945. unregister_early_suspend(&pwrpriv->early_suspend);
  1946. pwrpriv->early_suspend.suspend = NULL;
  1947. pwrpriv->early_suspend.resume = NULL;
  1948. }
  1949. #endif //CONFIG_HAS_EARLYSUSPEND
  1950. #ifdef CONFIG_ANDROID_POWER
  1951. #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1952. extern int rtw_resume_process(PADAPTER padapter);
  1953. #endif
  1954. static void rtw_early_suspend(android_early_suspend_t *h)
  1955. {
  1956. struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
  1957. DBG_871X("%s\n",__FUNCTION__);
  1958. rtw_set_do_late_resume(pwrpriv, _FALSE);
  1959. }
  1960. static void rtw_late_resume(android_early_suspend_t *h)
  1961. {
  1962. struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
  1963. struct dvobj_priv *dvobj = pwrctl_to_dvobj(pwrpriv);
  1964. _adapter *adapter = dvobj->padapters[IFACE_ID0];
  1965. DBG_871X("%s\n",__FUNCTION__);
  1966. if(pwrpriv->do_late_resume) {
  1967. #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1968. rtw_set_do_late_resume(pwrpriv, _FALSE);
  1969. rtw_resume_process(adapter);
  1970. #endif
  1971. }
  1972. }
  1973. void rtw_register_early_suspend(struct pwrctrl_priv *pwrpriv)
  1974. {
  1975. DBG_871X("%s\n", __FUNCTION__);
  1976. //jeff: set the early suspend level before blank screen, so we wll do late resume after scree is lit
  1977. pwrpriv->early_suspend.level = ANDROID_EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
  1978. pwrpriv->early_suspend.suspend = rtw_early_suspend;
  1979. pwrpriv->early_suspend.resume = rtw_late_resume;
  1980. android_register_early_suspend(&pwrpriv->early_suspend);
  1981. }
  1982. void rtw_unregister_early_suspend(struct pwrctrl_priv *pwrpriv)
  1983. {
  1984. DBG_871X("%s\n", __FUNCTION__);
  1985. rtw_set_do_late_resume(pwrpriv, _FALSE);
  1986. if (pwrpriv->early_suspend.suspend)
  1987. android_unregister_early_suspend(&pwrpriv->early_suspend);
  1988. pwrpriv->early_suspend.suspend = NULL;
  1989. pwrpriv->early_suspend.resume = NULL;
  1990. }
  1991. #endif //CONFIG_ANDROID_POWER
  1992. u8 rtw_interface_ps_func(_adapter *padapter,HAL_INTF_PS_FUNC efunc_id,u8* val)
  1993. {
  1994. u8 bResult = _TRUE;
  1995. rtw_hal_intf_ps_func(padapter,efunc_id,val);
  1996. return bResult;
  1997. }
  1998. inline void rtw_set_ips_deny(_adapter *padapter, u32 ms)
  1999. {
  2000. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  2001. pwrpriv->ips_deny_time = rtw_get_current_time() + rtw_ms_to_systime(ms);
  2002. }
  2003. /*
  2004. * rtw_pwr_wakeup - Wake the NIC up from: 1)IPS. 2)USB autosuspend
  2005. * @adapter: pointer to _adapter structure
  2006. * @ips_deffer_ms: the ms wiil prevent from falling into IPS after wakeup
  2007. * Return _SUCCESS or _FAIL
  2008. */
  2009. int _rtw_pwr_wakeup(_adapter *padapter, u32 ips_deffer_ms, const char *caller)
  2010. {
  2011. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  2012. struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
  2013. struct mlme_priv *pmlmepriv;
  2014. int ret = _SUCCESS;
  2015. int i;
  2016. u32 start = rtw_get_current_time();
  2017. /* for LPS */
  2018. LeaveAllPowerSaveMode(padapter);
  2019. /* IPS still bound with primary adapter */
  2020. padapter = GET_PRIMARY_ADAPTER(padapter);
  2021. pmlmepriv = &padapter->mlmepriv;
  2022. if (pwrpriv->ips_deny_time < rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms))
  2023. pwrpriv->ips_deny_time = rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms);
  2024. if (pwrpriv->ps_processing) {
  2025. DBG_871X("%s wait ps_processing...\n", __func__);
  2026. while (pwrpriv->ps_processing && rtw_get_passing_time_ms(start) <= 3000)
  2027. rtw_msleep_os(10);
  2028. if (pwrpriv->ps_processing)
  2029. DBG_871X("%s wait ps_processing timeout\n", __func__);
  2030. else
  2031. DBG_871X("%s wait ps_processing done\n", __func__);
  2032. }
  2033. #ifdef DBG_CONFIG_ERROR_DETECT
  2034. if (rtw_hal_sreset_inprogress(padapter)) {
  2035. DBG_871X("%s wait sreset_inprogress...\n", __func__);
  2036. while (rtw_hal_sreset_inprogress(padapter) && rtw_get_passing_time_ms(start) <= 4000)
  2037. rtw_msleep_os(10);
  2038. if (rtw_hal_sreset_inprogress(padapter))
  2039. DBG_871X("%s wait sreset_inprogress timeout\n", __func__);
  2040. else
  2041. DBG_871X("%s wait sreset_inprogress done\n", __func__);
  2042. }
  2043. #endif
  2044. if (pwrpriv->bInternalAutoSuspend == _FALSE && pwrpriv->bInSuspend) {
  2045. DBG_871X("%s wait bInSuspend...\n", __func__);
  2046. while (pwrpriv->bInSuspend
  2047. && ((rtw_get_passing_time_ms(start) <= 3000 && !rtw_is_do_late_resume(pwrpriv))
  2048. || (rtw_get_passing_time_ms(start) <= 500 && rtw_is_do_late_resume(pwrpriv)))
  2049. ) {
  2050. rtw_msleep_os(10);
  2051. }
  2052. if (pwrpriv->bInSuspend)
  2053. DBG_871X("%s wait bInSuspend timeout\n", __func__);
  2054. else
  2055. DBG_871X("%s wait bInSuspend done\n", __func__);
  2056. }
  2057. //System suspend is not allowed to wakeup
  2058. if((pwrpriv->bInternalAutoSuspend == _FALSE) && (_TRUE == pwrpriv->bInSuspend )){
  2059. ret = _FAIL;
  2060. goto exit;
  2061. }
  2062. //block???
  2063. if((pwrpriv->bInternalAutoSuspend == _TRUE) && (padapter->net_closed == _TRUE)) {
  2064. ret = _FAIL;
  2065. goto exit;
  2066. }
  2067. //I think this should be check in IPS, LPS, autosuspend functions...
  2068. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  2069. {
  2070. #if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND)
  2071. if(_TRUE==pwrpriv->bInternalAutoSuspend){
  2072. if(0==pwrpriv->autopm_cnt){
  2073. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
  2074. if (usb_autopm_get_interface(adapter_to_dvobj(padapter)->pusbintf) < 0)
  2075. {
  2076. DBG_871X( "can't get autopm: \n");
  2077. }
  2078. #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
  2079. usb_autopm_disable(adapter_to_dvobj(padapter)->pusbintf);
  2080. #else
  2081. usb_autoresume_device(adapter_to_dvobj(padapter)->pusbdev, 1);
  2082. #endif
  2083. pwrpriv->autopm_cnt++;
  2084. }
  2085. #endif //#if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND)
  2086. ret = _SUCCESS;
  2087. goto exit;
  2088. #if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND)
  2089. }
  2090. #endif //#if defined (CONFIG_BT_COEXIST)&& defined (CONFIG_AUTOSUSPEND)
  2091. }
  2092. if(rf_off == pwrpriv->rf_pwrstate )
  2093. {
  2094. #ifdef CONFIG_USB_HCI
  2095. #ifdef CONFIG_AUTOSUSPEND
  2096. if(pwrpriv->brfoffbyhw==_TRUE)
  2097. {
  2098. DBG_8192C("hw still in rf_off state ...........\n");
  2099. ret = _FAIL;
  2100. goto exit;
  2101. }
  2102. else if(padapter->registrypriv.usbss_enable)
  2103. {
  2104. DBG_8192C("%s call autoresume_enter....\n",__FUNCTION__);
  2105. if(_FAIL == autoresume_enter(padapter))
  2106. {
  2107. DBG_8192C("======> autoresume fail.............\n");
  2108. ret = _FAIL;
  2109. goto exit;
  2110. }
  2111. }
  2112. else
  2113. #endif
  2114. #endif
  2115. {
  2116. #ifdef CONFIG_IPS
  2117. DBG_8192C("%s call ips_leave....\n",__FUNCTION__);
  2118. if(_FAIL == ips_leave(padapter))
  2119. {
  2120. DBG_8192C("======> ips_leave fail.............\n");
  2121. ret = _FAIL;
  2122. goto exit;
  2123. }
  2124. #endif
  2125. }
  2126. }
  2127. //TODO: the following checking need to be merged...
  2128. if (rtw_is_drv_stopped(padapter)
  2129. || !padapter->bup
  2130. || !rtw_is_hw_init_completed(padapter)
  2131. ) {
  2132. DBG_8192C("%s: bDriverStopped=%s, bup=%d, hw_init_completed=%u\n"
  2133. , caller
  2134. , rtw_is_drv_stopped(padapter)?"True":"False"
  2135. , padapter->bup
  2136. , rtw_get_hw_init_completed(padapter));
  2137. ret= _FALSE;
  2138. goto exit;
  2139. }
  2140. exit:
  2141. if (pwrpriv->ips_deny_time < rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms))
  2142. pwrpriv->ips_deny_time = rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms);
  2143. return ret;
  2144. }
  2145. int rtw_pm_set_lps(_adapter *padapter, u8 mode)
  2146. {
  2147. int ret = 0;
  2148. struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
  2149. if ( mode < PS_MODE_NUM )
  2150. {
  2151. if(pwrctrlpriv->power_mgnt !=mode)
  2152. {
  2153. if(PS_MODE_ACTIVE == mode)
  2154. {
  2155. LeaveAllPowerSaveMode(padapter);
  2156. }
  2157. else
  2158. {
  2159. pwrctrlpriv->LpsIdleCount = 2;
  2160. }
  2161. pwrctrlpriv->power_mgnt = mode;
  2162. pwrctrlpriv->bLeisurePs = (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt)?_TRUE:_FALSE;
  2163. }
  2164. }
  2165. else
  2166. {
  2167. ret = -EINVAL;
  2168. }
  2169. return ret;
  2170. }
  2171. int rtw_pm_set_ips(_adapter *padapter, u8 mode)
  2172. {
  2173. struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
  2174. if( mode == IPS_NORMAL || mode == IPS_LEVEL_2 ) {
  2175. rtw_ips_mode_req(pwrctrlpriv, mode);
  2176. DBG_871X("%s %s\n", __FUNCTION__, mode == IPS_NORMAL?"IPS_NORMAL":"IPS_LEVEL_2");
  2177. return 0;
  2178. }
  2179. else if(mode ==IPS_NONE){
  2180. rtw_ips_mode_req(pwrctrlpriv, mode);
  2181. DBG_871X("%s %s\n", __FUNCTION__, "IPS_NONE");
  2182. if (!rtw_is_surprise_removed(padapter) && (_FAIL == rtw_pwr_wakeup(padapter)))
  2183. return -EFAULT;
  2184. }
  2185. else {
  2186. return -EINVAL;
  2187. }
  2188. return 0;
  2189. }
  2190. /*
  2191. * ATTENTION:
  2192. * This function will request pwrctrl LOCK!
  2193. */
  2194. void rtw_ps_deny(PADAPTER padapter, PS_DENY_REASON reason)
  2195. {
  2196. struct pwrctrl_priv *pwrpriv;
  2197. s32 ret;
  2198. // DBG_871X("+" FUNC_ADPT_FMT ": Request PS deny for %d (0x%08X)\n",
  2199. // FUNC_ADPT_ARG(padapter), reason, BIT(reason));
  2200. pwrpriv = adapter_to_pwrctl(padapter);
  2201. _enter_pwrlock(&pwrpriv->lock);
  2202. if (pwrpriv->ps_deny & BIT(reason))
  2203. {
  2204. DBG_871X(FUNC_ADPT_FMT ": [WARNING] Reason %d had been set before!!\n",
  2205. FUNC_ADPT_ARG(padapter), reason);
  2206. }
  2207. pwrpriv->ps_deny |= BIT(reason);
  2208. _exit_pwrlock(&pwrpriv->lock);
  2209. // DBG_871X("-" FUNC_ADPT_FMT ": Now PS deny for 0x%08X\n",
  2210. // FUNC_ADPT_ARG(padapter), pwrpriv->ps_deny);
  2211. }
  2212. /*
  2213. * ATTENTION:
  2214. * This function will request pwrctrl LOCK!
  2215. */
  2216. void rtw_ps_deny_cancel(PADAPTER padapter, PS_DENY_REASON reason)
  2217. {
  2218. struct pwrctrl_priv *pwrpriv;
  2219. // DBG_871X("+" FUNC_ADPT_FMT ": Cancel PS deny for %d(0x%08X)\n",
  2220. // FUNC_ADPT_ARG(padapter), reason, BIT(reason));
  2221. pwrpriv = adapter_to_pwrctl(padapter);
  2222. _enter_pwrlock(&pwrpriv->lock);
  2223. if ((pwrpriv->ps_deny & BIT(reason)) == 0)
  2224. {
  2225. DBG_871X(FUNC_ADPT_FMT ": [ERROR] Reason %d had been canceled before!!\n",
  2226. FUNC_ADPT_ARG(padapter), reason);
  2227. }
  2228. pwrpriv->ps_deny &= ~BIT(reason);
  2229. _exit_pwrlock(&pwrpriv->lock);
  2230. // DBG_871X("-" FUNC_ADPT_FMT ": Now PS deny for 0x%08X\n",
  2231. // FUNC_ADPT_ARG(padapter), pwrpriv->ps_deny);
  2232. }
  2233. /*
  2234. * ATTENTION:
  2235. * Before calling this function pwrctrl lock should be occupied already,
  2236. * otherwise it may return incorrect value.
  2237. */
  2238. u32 rtw_ps_deny_get(PADAPTER padapter)
  2239. {
  2240. u32 deny;
  2241. deny = adapter_to_pwrctl(padapter)->ps_deny;
  2242. return deny;
  2243. }