rtl8821c_dm.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2016 - 2017 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. *****************************************************************************/
  15. /* ************************************************************
  16. * Description:
  17. *
  18. * This file is for 8821C dynamic mechanism
  19. *
  20. *
  21. * ************************************************************ */
  22. #define _RTL8812C_DM_C_
  23. /* ************************************************************
  24. * include files
  25. * ************************************************************
  26. */
  27. #include <drv_types.h>
  28. #include <rtl8821c_hal.h>
  29. /* ************************************************************
  30. * Global var
  31. * ************************************************************ */
  32. static void dm_CheckProtection(PADAPTER adapter)
  33. {
  34. }
  35. #ifdef CONFIG_SUPPORT_HW_WPS_PBC
  36. static void dm_CheckPbcGPIO(PADAPTER adapter)
  37. {
  38. u8 tmp1byte;
  39. u8 bPbcPressed = _FALSE;
  40. if (!adapter->registrypriv.hw_wps_pbc)
  41. return;
  42. #ifdef CONFIG_USB_HCI
  43. tmp1byte = rtw_read8(adapter, GPIO_IO_SEL);
  44. tmp1byte |= (HAL_8192C_HW_GPIO_WPS_BIT);
  45. rtw_write8(adapter, GPIO_IO_SEL, tmp1byte); /* enable GPIO[2] as output mode */
  46. tmp1byte &= ~(HAL_8192C_HW_GPIO_WPS_BIT);
  47. rtw_write8(adapter, GPIO_IN, tmp1byte); /* reset the floating voltage level */
  48. tmp1byte = rtw_read8(adapter, GPIO_IO_SEL);
  49. tmp1byte &= ~(HAL_8192C_HW_GPIO_WPS_BIT);
  50. rtw_write8(adapter, GPIO_IO_SEL, tmp1byte); /* enable GPIO[2] as input mode */
  51. tmp1byte = rtw_read8(adapter, GPIO_IN);
  52. if (tmp1byte == 0xff)
  53. return;
  54. if (tmp1byte & HAL_8192C_HW_GPIO_WPS_BIT)
  55. bPbcPressed = _TRUE;
  56. #else
  57. tmp1byte = rtw_read8(adapter, GPIO_IN);
  58. if ((tmp1byte == 0xff) || adapter->init_adpt_in_progress)
  59. return;
  60. if ((tmp1byte & HAL_8192C_HW_GPIO_WPS_BIT) == 0)
  61. bPbcPressed = _TRUE;
  62. #endif
  63. if (_TRUE == bPbcPressed) {
  64. /*
  65. * Here we only set bPbcPressed to true
  66. * After trigger PBC, the variable will be set to false
  67. */
  68. RTW_INFO("CheckPbcGPIO - PBC is pressed\n");
  69. rtw_request_wps_pbc_event(adapter);
  70. }
  71. }
  72. #endif /* CONFIG_SUPPORT_HW_WPS_PBC */
  73. #ifdef CONFIG_PCI_HCI
  74. /*
  75. * Description:
  76. * Perform interrupt migration dynamically to reduce CPU utilization.
  77. *
  78. * Assumption:
  79. * 1. Do not enable migration under WIFI test.
  80. */
  81. void dm_InterruptMigration(PADAPTER adapter)
  82. {
  83. PHAL_DATA_TYPE hal = GET_HAL_DATA(adapter);
  84. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  85. BOOLEAN bCurrentIntMt, bCurrentACIntDisable;
  86. BOOLEAN IntMtToSet = _FALSE;
  87. BOOLEAN ACIntToSet = _FALSE;
  88. /* Retrieve current interrupt migration and Tx four ACs IMR settings first. */
  89. bCurrentIntMt = hal->bInterruptMigration;
  90. bCurrentACIntDisable = hal->bDisableTxInt;
  91. /*
  92. * <Roger_Notes> Currently we use busy traffic for reference instead of RxIntOK counts to prevent non-linear Rx statistics
  93. * when interrupt migration is set before. 2010.03.05.
  94. */
  95. if (!adapter->registrypriv.wifi_spec
  96. && (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  97. && pmlmepriv->LinkDetectInfo.bHigherBusyTraffic) {
  98. IntMtToSet = _TRUE;
  99. /* To check whether we should disable Tx interrupt or not. */
  100. if (pmlmepriv->LinkDetectInfo.bHigherBusyRxTraffic)
  101. ACIntToSet = _TRUE;
  102. }
  103. /* Update current settings. */
  104. if (bCurrentIntMt != IntMtToSet) {
  105. RTW_INFO("%s: Update interrrupt migration(%d)\n", __FUNCTION__, IntMtToSet);
  106. if (IntMtToSet) {
  107. /*
  108. * <Roger_Notes> Set interrrupt migration timer and corresponging Tx/Rx counter.
  109. * timer 25ns*0xfa0=100us for 0xf packets.
  110. * 2010.03.05.
  111. */
  112. rtw_write32(adapter, REG_INT_MIG, 0xff000fa0); /* 0x306:Rx, 0x307:Tx */
  113. hal->bInterruptMigration = IntMtToSet;
  114. } else {
  115. /* Reset all interrupt migration settings. */
  116. rtw_write32(adapter, REG_INT_MIG, 0);
  117. hal->bInterruptMigration = IntMtToSet;
  118. }
  119. }
  120. }
  121. #endif /* CONFIG_PCI_HCI */
  122. /*
  123. * ============================================================
  124. * functions
  125. * ============================================================
  126. */
  127. static void init_phydm_cominfo(PADAPTER adapter)
  128. {
  129. PHAL_DATA_TYPE hal = GET_HAL_DATA(adapter);
  130. struct dm_struct *pDM_Odm = &hal->odmpriv;
  131. u8 cut_ver = ODM_CUT_A, fab_ver = ODM_TSMC;
  132. Init_ODM_ComInfo(adapter);
  133. odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_PACKAGE_TYPE, hal->PackageType);
  134. if (IS_CHIP_VENDOR_TSMC(hal->version_id))
  135. fab_ver = ODM_TSMC;
  136. else if (IS_CHIP_VENDOR_UMC(hal->version_id))
  137. fab_ver = ODM_UMC;
  138. else if (IS_CHIP_VENDOR_SMIC(hal->version_id))
  139. fab_ver = ODM_UMC + 1;
  140. else
  141. RTW_INFO("%s: unknown fab_ver=%d !!\n",
  142. __FUNCTION__, GET_CVID_MANUFACTUER(hal->version_id));
  143. if (IS_A_CUT(hal->version_id))
  144. cut_ver = ODM_CUT_A;
  145. else if (IS_B_CUT(hal->version_id))
  146. cut_ver = ODM_CUT_B;
  147. else if (IS_C_CUT(hal->version_id))
  148. cut_ver = ODM_CUT_C;
  149. else if (IS_D_CUT(hal->version_id))
  150. cut_ver = ODM_CUT_D;
  151. else if (IS_E_CUT(hal->version_id))
  152. cut_ver = ODM_CUT_E;
  153. else if (IS_F_CUT(hal->version_id))
  154. cut_ver = ODM_CUT_F;
  155. else if (IS_I_CUT(hal->version_id))
  156. cut_ver = ODM_CUT_I;
  157. else if (IS_J_CUT(hal->version_id))
  158. cut_ver = ODM_CUT_J;
  159. else if (IS_K_CUT(hal->version_id))
  160. cut_ver = ODM_CUT_K;
  161. else
  162. RTW_INFO("%s: unknown cut_ver=%d !!\n",
  163. __FUNCTION__, GET_CVID_CUT_VERSION(hal->version_id));
  164. RTW_INFO("%s: fab_ver=%d cut_ver=%d\n", __FUNCTION__, fab_ver, cut_ver);
  165. odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_FAB_VER, fab_ver);
  166. odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_CUT_VER, cut_ver);
  167. }
  168. void rtl8821c_phy_init_dm_priv(PADAPTER adapter)
  169. {
  170. struct dm_struct *phydm = adapter_to_phydm(adapter);
  171. init_phydm_cominfo(adapter);
  172. odm_init_all_timers(phydm);
  173. }
  174. void rtl8821c_phy_deinit_dm_priv(PADAPTER adapter)
  175. {
  176. struct dm_struct *phydm = adapter_to_phydm(adapter);
  177. odm_cancel_all_timers(phydm);
  178. }
  179. void rtl8821c_phy_init_haldm(PADAPTER adapter)
  180. {
  181. rtw_phydm_init(adapter);
  182. }
  183. void rtl8821c_phy_haldm_watchdog(PADAPTER Adapter)
  184. {
  185. BOOLEAN bFwCurrentInPSMode = _FALSE;
  186. u8 bFwPSAwake = _TRUE;
  187. if (!rtw_is_hw_init_completed(Adapter))
  188. goto skip_dm;
  189. #ifdef CONFIG_LPS
  190. bFwCurrentInPSMode = adapter_to_pwrctl(Adapter)->bFwCurrentInPSMode;
  191. rtw_hal_get_hwreg(Adapter, HW_VAR_FWLPS_RF_ON, &bFwPSAwake);
  192. #endif
  193. #ifdef CONFIG_P2P_PS
  194. /* Fw is under p2p powersaving mode, driver should stop dynamic mechanism.
  195. modifed by thomas. 2011.06.11.*/
  196. if (Adapter->wdinfo.p2p_ps_mode)
  197. bFwPSAwake = _FALSE;
  198. #endif /*CONFIG_P2P_PS*/
  199. if ((rtw_is_hw_init_completed(Adapter))
  200. && ((!bFwCurrentInPSMode) && bFwPSAwake)) {
  201. /* Dynamically switch RTS/CTS protection.*/
  202. /*dm_CheckProtection(Adapter);*/
  203. }
  204. #ifdef CONFIG_DISABLE_ODM
  205. goto skip_dm;
  206. #endif
  207. rtw_phydm_watchdog(Adapter);
  208. skip_dm:
  209. #ifdef CONFIG_BEAMFORMING
  210. #ifdef RTW_BEAMFORMING_VERSION_2
  211. if (check_fwstate(&Adapter->mlmepriv, WIFI_STATION_STATE) &&
  212. check_fwstate(&Adapter->mlmepriv, _FW_LINKED))
  213. rtw_hal_beamforming_config_csirate(Adapter);
  214. #endif
  215. #endif
  216. #ifdef CONFIG_SUPPORT_HW_WPS_PBC
  217. /* Check GPIO to determine current Pbc status.*/
  218. dm_CheckPbcGPIO(Adapter);
  219. #endif
  220. return;
  221. }