rtl8812a_dm.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 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. //============================================================
  21. // Description:
  22. //
  23. // This file is for 92CE/92CU dynamic mechanism only
  24. //
  25. //
  26. //============================================================
  27. #define _RTL8812A_DM_C_
  28. //============================================================
  29. // include files
  30. //============================================================
  31. //#include <drv_types.h>
  32. #include <rtl8812a_hal.h>
  33. //============================================================
  34. // Global var
  35. //============================================================
  36. static VOID
  37. dm_CheckProtection(
  38. IN PADAPTER Adapter
  39. )
  40. {
  41. #if 0
  42. PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  43. u1Byte CurRate, RateThreshold;
  44. if(pMgntInfo->pHTInfo->bCurBW40MHz)
  45. RateThreshold = MGN_MCS1;
  46. else
  47. RateThreshold = MGN_MCS3;
  48. if(Adapter->TxStats.CurrentInitTxRate <= RateThreshold)
  49. {
  50. pMgntInfo->bDmDisableProtect = TRUE;
  51. DbgPrint("Forced disable protect: %x\n", Adapter->TxStats.CurrentInitTxRate);
  52. }
  53. else
  54. {
  55. pMgntInfo->bDmDisableProtect = FALSE;
  56. DbgPrint("Enable protect: %x\n", Adapter->TxStats.CurrentInitTxRate);
  57. }
  58. #endif
  59. }
  60. static VOID
  61. dm_CheckStatistics(
  62. IN PADAPTER Adapter
  63. )
  64. {
  65. #if 0
  66. if(!Adapter->MgntInfo.bMediaConnect)
  67. return;
  68. //2008.12.10 tynli Add for getting Current_Tx_Rate_Reg flexibly.
  69. rtw_hal_get_hwreg( Adapter, HW_VAR_INIT_TX_RATE, (pu1Byte)(&Adapter->TxStats.CurrentInitTxRate) );
  70. // Calculate current Tx Rate(Successful transmited!!)
  71. // Calculate current Rx Rate(Successful received!!)
  72. //for tx tx retry count
  73. rtw_hal_get_hwreg( Adapter, HW_VAR_RETRY_COUNT, (pu1Byte)(&Adapter->TxStats.NumTxRetryCount) );
  74. #endif
  75. }
  76. static void dm_CheckPbcGPIO(_adapter *padapter)
  77. {
  78. u8 tmp1byte;
  79. u8 bPbcPressed = _FALSE;
  80. if(!padapter->registrypriv.hw_wps_pbc)
  81. return;
  82. #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI)
  83. if (IS_HARDWARE_TYPE_8812(padapter))
  84. {
  85. tmp1byte = rtw_read8(padapter, GPIO_IO_SEL);
  86. tmp1byte |= (HAL_8192C_HW_GPIO_WPS_BIT);
  87. rtw_write8(padapter, GPIO_IO_SEL, tmp1byte); //enable GPIO[2] as output mode
  88. tmp1byte &= ~(HAL_8192C_HW_GPIO_WPS_BIT);
  89. rtw_write8(padapter, GPIO_IN, tmp1byte); //reset the floating voltage level
  90. tmp1byte = rtw_read8(padapter, GPIO_IO_SEL);
  91. tmp1byte &= ~(HAL_8192C_HW_GPIO_WPS_BIT);
  92. rtw_write8(padapter, GPIO_IO_SEL, tmp1byte); //enable GPIO[2] as input mode
  93. tmp1byte =rtw_read8(padapter, GPIO_IN);
  94. if (tmp1byte == 0xff)
  95. return ;
  96. if (tmp1byte&HAL_8192C_HW_GPIO_WPS_BIT)
  97. {
  98. bPbcPressed = _TRUE;
  99. }
  100. }
  101. else if (IS_HARDWARE_TYPE_8821(padapter))
  102. {
  103. tmp1byte = rtw_read8(padapter, GPIO_IO_SEL_8811A);
  104. tmp1byte |= (BIT4);
  105. rtw_write8(padapter, GPIO_IO_SEL_8811A, tmp1byte); //enable GPIO[2] as output mode
  106. tmp1byte &= ~(BIT4);
  107. rtw_write8(padapter, GPIO_IN_8811A, tmp1byte); //reset the floating voltage level
  108. tmp1byte = rtw_read8(padapter, GPIO_IO_SEL_8811A);
  109. tmp1byte &= ~(BIT4);
  110. rtw_write8(padapter, GPIO_IO_SEL_8811A, tmp1byte); //enable GPIO[2] as input mode
  111. tmp1byte =rtw_read8(padapter, GPIO_IN_8811A);
  112. if (tmp1byte == 0xff)
  113. return ;
  114. if (tmp1byte&BIT4)
  115. {
  116. bPbcPressed = _TRUE;
  117. }
  118. }
  119. #else
  120. #endif
  121. if( _TRUE == bPbcPressed)
  122. {
  123. // Here we only set bPbcPressed to true
  124. // After trigger PBC, the variable will be set to false
  125. DBG_8192C("CheckPbcGPIO - PBC is pressed\n");
  126. rtw_request_wps_pbc_event(padapter);
  127. }
  128. }
  129. #ifdef CONFIG_PCI_HCI
  130. //
  131. // Description:
  132. // Perform interrupt migration dynamically to reduce CPU utilization.
  133. //
  134. // Assumption:
  135. // 1. Do not enable migration under WIFI test.
  136. //
  137. // Created by Roger, 2010.03.05.
  138. //
  139. VOID
  140. dm_InterruptMigration(
  141. IN PADAPTER Adapter
  142. )
  143. {
  144. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  145. struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
  146. BOOLEAN bCurrentIntMt, bCurrentACIntDisable;
  147. BOOLEAN IntMtToSet = _FALSE;
  148. BOOLEAN ACIntToSet = _FALSE;
  149. // Retrieve current interrupt migration and Tx four ACs IMR settings first.
  150. bCurrentIntMt = pHalData->bInterruptMigration;
  151. bCurrentACIntDisable = pHalData->bDisableTxInt;
  152. //
  153. // <Roger_Notes> Currently we use busy traffic for reference instead of RxIntOK counts to prevent non-linear Rx statistics
  154. // when interrupt migration is set before. 2010.03.05.
  155. //
  156. if(!Adapter->registrypriv.wifi_spec &&
  157. (check_fwstate(pmlmepriv, _FW_LINKED)== _TRUE) &&
  158. pmlmepriv->LinkDetectInfo.bHigherBusyTraffic)
  159. {
  160. IntMtToSet = _TRUE;
  161. // To check whether we should disable Tx interrupt or not.
  162. if(pmlmepriv->LinkDetectInfo.bHigherBusyRxTraffic )
  163. ACIntToSet = _TRUE;
  164. }
  165. //Update current settings.
  166. if( bCurrentIntMt != IntMtToSet ){
  167. DBG_8192C("%s(): Update interrrupt migration(%d)\n",__FUNCTION__,IntMtToSet);
  168. if(IntMtToSet)
  169. {
  170. //
  171. // <Roger_Notes> Set interrrupt migration timer and corresponging Tx/Rx counter.
  172. // timer 25ns*0xfa0=100us for 0xf packets.
  173. // 2010.03.05.
  174. //
  175. rtw_write32(Adapter, REG_INT_MIG, 0xff000fa0);// 0x306:Rx, 0x307:Tx
  176. pHalData->bInterruptMigration = IntMtToSet;
  177. }
  178. else
  179. {
  180. // Reset all interrupt migration settings.
  181. rtw_write32(Adapter, REG_INT_MIG, 0);
  182. pHalData->bInterruptMigration = IntMtToSet;
  183. }
  184. }
  185. /*if( bCurrentACIntDisable != ACIntToSet ){
  186. DBG_8192C("%s(): Update AC interrrupt(%d)\n",__FUNCTION__,ACIntToSet);
  187. if(ACIntToSet) // Disable four ACs interrupts.
  188. {
  189. //
  190. // <Roger_Notes> Disable VO, VI, BE and BK four AC interrupts to gain more efficient CPU utilization.
  191. // When extremely highly Rx OK occurs, we will disable Tx interrupts.
  192. // 2010.03.05.
  193. //
  194. UpdateInterruptMask8192CE( Adapter, 0, RT_AC_INT_MASKS );
  195. pHalData->bDisableTxInt = ACIntToSet;
  196. }
  197. else// Enable four ACs interrupts.
  198. {
  199. UpdateInterruptMask8192CE( Adapter, RT_AC_INT_MASKS, 0 );
  200. pHalData->bDisableTxInt = ACIntToSet;
  201. }
  202. }*/
  203. }
  204. #endif
  205. //
  206. // Initialize GPIO setting registers
  207. //
  208. static void
  209. dm_InitGPIOSetting(
  210. IN PADAPTER Adapter
  211. )
  212. {
  213. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  214. u8 tmp1byte;
  215. tmp1byte = rtw_read8(Adapter, REG_GPIO_MUXCFG);
  216. tmp1byte &= (GPIOSEL_GPIO | ~GPIOSEL_ENBT);
  217. #ifdef CONFIG_BT_COEXIST
  218. // UMB-B cut bug. We need to support the modification.
  219. if (IS_81xxC_VENDOR_UMC_B_CUT(pHalData->VersionID) &&
  220. pHalData->bt_coexist.BT_Coexist)
  221. {
  222. tmp1byte |= (BIT5);
  223. }
  224. #endif
  225. rtw_write8(Adapter, REG_GPIO_MUXCFG, tmp1byte);
  226. }
  227. // A mapping from HalData to ODM.
  228. ODM_BOARD_TYPE_E boardType(u8 InterfaceSel)
  229. {
  230. ODM_BOARD_TYPE_E board = ODM_BOARD_DEFAULT;
  231. #ifdef CONFIG_PCI_HCI
  232. INTERFACE_SELECT_PCIE pcie = (INTERFACE_SELECT_PCIE)InterfaceSel;
  233. switch (pcie)
  234. {
  235. case INTF_SEL0_SOLO_MINICARD:
  236. board |= ODM_BOARD_MINICARD;
  237. break;
  238. case INTF_SEL1_BT_COMBO_MINICARD:
  239. board |= ODM_BOARD_BT;
  240. board |= ODM_BOARD_MINICARD;
  241. break;
  242. default:
  243. board = ODM_BOARD_DEFAULT;
  244. break;
  245. }
  246. #elif defined(CONFIG_USB_HCI)
  247. INTERFACE_SELECT_USB usb = (INTERFACE_SELECT_USB)InterfaceSel;
  248. switch (usb)
  249. {
  250. case INTF_SEL1_USB_High_Power:
  251. board |= ODM_BOARD_EXT_LNA;
  252. board |= ODM_BOARD_EXT_PA;
  253. break;
  254. case INTF_SEL2_MINICARD:
  255. board |= ODM_BOARD_MINICARD;
  256. break;
  257. case INTF_SEL4_USB_Combo:
  258. board |= ODM_BOARD_BT;
  259. break;
  260. case INTF_SEL5_USB_Combo_MF:
  261. board |= ODM_BOARD_BT;
  262. break;
  263. case INTF_SEL0_USB:
  264. case INTF_SEL3_USB_Solo:
  265. default:
  266. board = ODM_BOARD_DEFAULT;
  267. break;
  268. }
  269. #endif
  270. //DBG_871X("===> boardType(): (pHalData->InterfaceSel, pDM_Odm->BoardType) = (%d, %d)\n", InterfaceSel, board);
  271. return board;
  272. }
  273. //============================================================
  274. // functions
  275. //============================================================
  276. static void Init_ODM_ComInfo_8812(PADAPTER Adapter)
  277. {
  278. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  279. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(Adapter);
  280. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  281. PDM_ODM_T pDM_Odm = &(pHalData->odmpriv);
  282. u8 cut_ver,fab_ver;
  283. u8 BoardType = ODM_BOARD_DEFAULT;
  284. //
  285. // Init Value
  286. //
  287. _rtw_memset(pDM_Odm,0,sizeof(pDM_Odm));
  288. pDM_Odm->Adapter = Adapter;
  289. ODM_CmnInfoInit(pDM_Odm,ODM_CMNINFO_PLATFORM,ODM_CE);
  290. if (Adapter->interface_type == RTW_GSPI)
  291. ODM_CmnInfoInit(pDM_Odm,ODM_CMNINFO_INTERFACE,ODM_ITRF_SDIO);
  292. else
  293. ODM_CmnInfoInit(pDM_Odm,ODM_CMNINFO_INTERFACE,Adapter->interface_type);
  294. if (IS_HARDWARE_TYPE_8812(Adapter))
  295. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_IC_TYPE, ODM_RTL8812);
  296. else if (IS_HARDWARE_TYPE_8821(Adapter))
  297. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_IC_TYPE, ODM_RTL8821);
  298. fab_ver = ODM_TSMC;
  299. if (IS_VENDOR_8812A_C_CUT(Adapter))
  300. cut_ver = ODM_CUT_C;
  301. else
  302. cut_ver = ODM_CUT_A;
  303. ODM_CmnInfoInit(pDM_Odm,ODM_CMNINFO_FAB_VER,fab_ver);
  304. ODM_CmnInfoInit(pDM_Odm,ODM_CMNINFO_CUT_VER,cut_ver);
  305. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_MP_TEST_CHIP,IS_NORMAL_CHIP(pHalData->VersionID));
  306. //1 ======= BoardType: ODM_CMNINFO_BOARD_TYPE =======
  307. #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI)
  308. if(pHalData->InterfaceSel == INTF_SEL1_USB_High_Power)
  309. {
  310. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_EXT_PA, 1);
  311. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_EXT_LNA, 1);
  312. }
  313. else
  314. {
  315. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_EXT_PA, pHalData->ExternalPA_2G);
  316. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_EXT_LNA, 0);
  317. }
  318. #else
  319. // PCIE no external PA now???
  320. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_EXT_PA, 0);
  321. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_EXT_LNA, 0);
  322. #endif
  323. if (pHalData->ExternalLNA_2G != 0) {
  324. BoardType |= ODM_BOARD_EXT_LNA;
  325. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_EXT_LNA, 1);
  326. }
  327. if (pHalData->ExternalLNA_5G != 0) {
  328. BoardType |= ODM_BOARD_EXT_LNA_5G;
  329. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_5G_EXT_LNA, 1);
  330. }
  331. if (pHalData->ExternalPA_2G != 0) {
  332. BoardType |= ODM_BOARD_EXT_PA;
  333. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_EXT_PA, 1);
  334. }
  335. if (pHalData->ExternalPA_5G != 0) {
  336. BoardType |= ODM_BOARD_EXT_PA_5G;
  337. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_5G_EXT_PA, 1);
  338. }
  339. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_BOARD_TYPE, BoardType);
  340. //1 ============== End of BoardType ==============
  341. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_RFE_TYPE, pHalData->RFEType);
  342. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_EXT_TRSW, 0);
  343. ODM_CmnInfoInit(pDM_Odm,ODM_CMNINFO_PATCH_ID,pEEPROM->CustomerID);
  344. // ODM_CMNINFO_BINHCT_TEST only for MP Team
  345. ODM_CmnInfoInit(pDM_Odm,ODM_CMNINFO_BWIFI_TEST,Adapter->registrypriv.wifi_spec);
  346. if(pHalData->rf_type == RF_1T1R){
  347. ODM_CmnInfoUpdate(pDM_Odm,ODM_CMNINFO_RF_TYPE,ODM_1T1R);
  348. }
  349. else if(pHalData->rf_type == RF_2T2R){
  350. ODM_CmnInfoUpdate(pDM_Odm,ODM_CMNINFO_RF_TYPE,ODM_2T2R);
  351. }
  352. else if(pHalData->rf_type == RF_1T2R){
  353. ODM_CmnInfoUpdate(pDM_Odm,ODM_CMNINFO_RF_TYPE,ODM_1T2R);
  354. }
  355. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_RFE_TYPE, pHalData->RFEType);
  356. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_RF_ANTENNA_TYPE, pHalData->TRxAntDivType);
  357. #ifdef CONFIG_DISABLE_ODM
  358. pdmpriv->InitODMFlag = 0;
  359. #else
  360. pdmpriv->InitODMFlag = ODM_RF_CALIBRATION |
  361. ODM_RF_TX_PWR_TRACK //|
  362. ;
  363. //if(pHalData->AntDivCfg)
  364. // pdmpriv->InitODMFlag |= ODM_BB_ANT_DIV;
  365. #endif
  366. ODM_CmnInfoUpdate(pDM_Odm,ODM_CMNINFO_ABILITY,pdmpriv->InitODMFlag);
  367. }
  368. static void Update_ODM_ComInfo_8812(PADAPTER Adapter)
  369. {
  370. struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
  371. struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
  372. struct pwrctrl_priv *pwrctrlpriv = &Adapter->pwrctrlpriv;
  373. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  374. PDM_ODM_T pDM_Odm = &(pHalData->odmpriv);
  375. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  376. int i;
  377. #ifdef CONFIG_DISABLE_ODM
  378. pdmpriv->InitODMFlag = 0;
  379. #else //CONFIG_DISABLE_ODM
  380. pdmpriv->InitODMFlag = ODM_BB_DIG |
  381. #ifdef CONFIG_ODM_REFRESH_RAMASK
  382. ODM_BB_RA_MASK |
  383. #endif
  384. ODM_BB_FA_CNT |
  385. ODM_BB_RSSI_MONITOR |
  386. ODM_RF_TX_PWR_TRACK | // For RF
  387. ODM_MAC_EDCA_TURBO
  388. ;
  389. if(pHalData->AntDivCfg)
  390. pdmpriv->InitODMFlag |= ODM_BB_ANT_DIV;
  391. #if (MP_DRIVER==1)
  392. if (Adapter->registrypriv.mp_mode == 1)
  393. {
  394. pdmpriv->InitODMFlag = ODM_RF_CALIBRATION |
  395. ODM_RF_TX_PWR_TRACK;
  396. }
  397. #endif//(MP_DRIVER==1)
  398. #endif//CONFIG_DISABLE_ODM
  399. ODM_CmnInfoUpdate(pDM_Odm,ODM_CMNINFO_ABILITY,pdmpriv->InitODMFlag);
  400. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_TX_UNI,&(Adapter->xmitpriv.tx_bytes));
  401. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_RX_UNI,&(Adapter->recvpriv.rx_bytes));
  402. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_WM_MODE,&(pmlmeext->cur_wireless_mode));
  403. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_BAND,&(pHalData->CurrentBandType));
  404. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_FORCED_RATE,&(pHalData->ForcedDataRate));
  405. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_SEC_CHNL_OFFSET,&(pHalData->nCur40MhzPrimeSC));
  406. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_SEC_MODE,&(Adapter->securitypriv.dot11PrivacyAlgrthm));
  407. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_BW,&(pHalData->CurrentChannelBW ));
  408. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_CHNL,&( pHalData->CurrentChannel));
  409. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_NET_CLOSED,&( Adapter->net_closed));
  410. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_MP_MODE,&(Adapter->registrypriv.mp_mode));
  411. //================= only for 8192D =================
  412. /*
  413. //pHalData->CurrentBandType92D
  414. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_DMSP_GET_VALUE,&(pDM_Odm->u1Byte_temp));
  415. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_BUDDY_ADAPTOR,&(pDM_Odm->PADAPTER_temp));
  416. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_DMSP_IS_MASTER,&(pDM_Odm->u1Byte_temp));
  417. //================= only for 8192D =================
  418. // driver havn't those variable now
  419. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_BT_OPERATION,&(pDM_Odm->u1Byte_temp));
  420. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_BT_DISABLE_EDCA,&(pDM_Odm->u1Byte_temp));
  421. */
  422. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_SCAN,&(pmlmepriv->bScanInProcess));
  423. ODM_CmnInfoHook(pDM_Odm,ODM_CMNINFO_POWER_SAVING,&(pwrctrlpriv->bpower_saving));
  424. ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_RF_ANTENNA_TYPE, pHalData->TRxAntDivType);
  425. for(i=0; i< NUM_STA; i++)
  426. {
  427. //pDM_Odm->pODM_StaInfo[i] = NULL;
  428. ODM_CmnInfoPtrArrayHook(pDM_Odm, ODM_CMNINFO_STA_STATUS,i,NULL);
  429. }
  430. }
  431. void
  432. rtl8812_InitHalDm(
  433. IN PADAPTER Adapter
  434. )
  435. {
  436. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  437. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  438. PDM_ODM_T pDM_Odm = &(pHalData->odmpriv);
  439. u8 i;
  440. #ifdef CONFIG_USB_HCI
  441. dm_InitGPIOSetting(Adapter);
  442. #endif
  443. pdmpriv->DM_Type = DM_Type_ByDriver;
  444. pdmpriv->DMFlag = DYNAMIC_FUNC_DISABLE;
  445. Update_ODM_ComInfo_8812(Adapter);
  446. ODM_DMInit(pDM_Odm);
  447. Adapter->fix_rate = 0xFF;
  448. }
  449. VOID
  450. rtl8812_HalDmWatchDog(
  451. IN PADAPTER Adapter
  452. )
  453. {
  454. BOOLEAN bFwCurrentInPSMode = _FALSE;
  455. BOOLEAN bFwPSAwake = _TRUE;
  456. u8 hw_init_completed = _FALSE;
  457. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  458. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  459. PDM_ODM_T pDM_Odm = &(pHalData->odmpriv);
  460. #ifdef CONFIG_CONCURRENT_MODE
  461. PADAPTER pbuddy_adapter = Adapter->pbuddy_adapter;
  462. #endif //CONFIG_CONCURRENT_MODE
  463. _func_enter_;
  464. hw_init_completed = Adapter->hw_init_completed;
  465. if (hw_init_completed == _FALSE)
  466. goto skip_dm;
  467. #ifdef CONFIG_LPS
  468. #ifdef CONFIG_CONCURRENT_MODE
  469. if (Adapter->iface_type != IFACE_PORT0 && pbuddy_adapter) {
  470. bFwCurrentInPSMode = pbuddy_adapter->pwrctrlpriv.bFwCurrentInPSMode;
  471. rtw_hal_get_hwreg(pbuddy_adapter, HW_VAR_FWLPS_RF_ON, (u8 *)(&bFwPSAwake));
  472. } else
  473. #endif //CONFIG_CONCURRENT_MODE
  474. {
  475. bFwCurrentInPSMode = Adapter->pwrctrlpriv.bFwCurrentInPSMode;
  476. rtw_hal_get_hwreg(Adapter, HW_VAR_FWLPS_RF_ON, (u8 *)(&bFwPSAwake));
  477. }
  478. #endif
  479. #ifdef CONFIG_P2P_PS
  480. // Fw is under p2p powersaving mode, driver should stop dynamic mechanism.
  481. // modifed by thomas. 2011.06.11.
  482. if(Adapter->wdinfo.p2p_ps_mode)
  483. bFwPSAwake = _FALSE;
  484. #endif //CONFIG_P2P_PS
  485. if( (hw_init_completed == _TRUE)
  486. && ((!bFwCurrentInPSMode) && bFwPSAwake))
  487. {
  488. //
  489. // Calculate Tx/Rx statistics.
  490. //
  491. dm_CheckStatistics(Adapter);
  492. //
  493. // Dynamically switch RTS/CTS protection.
  494. //
  495. //dm_CheckProtection(Adapter);
  496. #ifdef CONFIG_PCI_HCI
  497. // 20100630 Joseph: Disable Interrupt Migration mechanism temporarily because it degrades Rx throughput.
  498. // Tx Migration settings.
  499. //dm_InterruptMigration(Adapter);
  500. //if(Adapter->HalFunc.TxCheckStuckHandler(Adapter))
  501. // PlatformScheduleWorkItem(&(GET_HAL_DATA(Adapter)->HalResetWorkItem));
  502. #endif
  503. }
  504. //ODM
  505. if (hw_init_completed == _TRUE)
  506. {
  507. u8 bLinked=_FALSE;
  508. #ifdef CONFIG_DISABLE_ODM
  509. pHalData->odmpriv.SupportAbility = 0;
  510. #endif
  511. if(rtw_linked_check(Adapter))
  512. bLinked = _TRUE;
  513. #ifdef CONFIG_CONCURRENT_MODE
  514. if(pbuddy_adapter && rtw_linked_check(pbuddy_adapter))
  515. bLinked = _TRUE;
  516. #endif //CONFIG_CONCURRENT_MODE
  517. ODM_CmnInfoUpdate(&pHalData->odmpriv ,ODM_CMNINFO_LINK, bLinked);
  518. ODM_DMWatchdog(&pHalData->odmpriv);
  519. }
  520. skip_dm:
  521. // Check GPIO to determine current RF on/off and Pbc status.
  522. // Check Hardware Radio ON/OFF or not
  523. #ifdef CONFIG_PCI_HCI
  524. if(pHalData->bGpioHwWpsPbc)
  525. #endif
  526. {
  527. //temp removed
  528. dm_CheckPbcGPIO(Adapter);
  529. }
  530. return;
  531. }
  532. void rtl8812_init_dm_priv(IN PADAPTER Adapter)
  533. {
  534. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  535. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  536. PDM_ODM_T podmpriv = &pHalData->odmpriv;
  537. _rtw_memset(pdmpriv, 0, sizeof(struct dm_priv));
  538. //_rtw_spinlock_init(&(pHalData->odm_stainfo_lock));
  539. Init_ODM_ComInfo_8812(Adapter);
  540. #ifdef CONFIG_SW_ANTENNA_DIVERSITY
  541. //_init_timer(&(pdmpriv->SwAntennaSwitchTimer), Adapter->pnetdev , odm_SW_AntennaSwitchCallback, Adapter);
  542. ODM_InitAllTimers(podmpriv );
  543. #endif
  544. ODM_InitDebugSetting(podmpriv);
  545. Adapter->registrypriv.RegEnableTxPowerLimit = 0;
  546. Adapter->registrypriv.RegPowerBase = 14;
  547. Adapter->registrypriv.RegTxPwrLimit = 0xFFFFFFFF;
  548. Adapter->registrypriv.TxBBSwing_2G = 0xFF;
  549. Adapter->registrypriv.TxBBSwing_5G = 0xFF;
  550. Adapter->registrypriv.bEn_RFE = 0;
  551. Adapter->registrypriv.RFE_Type = 64;
  552. pHalData->RegRFPathS1 = 0;
  553. pHalData->TxPwrInPercentage = TX_PWR_PERCENTAGE_3;
  554. }
  555. void rtl8812_deinit_dm_priv(IN PADAPTER Adapter)
  556. {
  557. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  558. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  559. PDM_ODM_T podmpriv = &pHalData->odmpriv;
  560. //_rtw_spinlock_free(&pHalData->odm_stainfo_lock);
  561. #ifdef CONFIG_SW_ANTENNA_DIVERSITY
  562. //_cancel_timer_ex(&pdmpriv->SwAntennaSwitchTimer);
  563. ODM_CancelAllTimers(podmpriv);
  564. #endif
  565. }
  566. #ifdef CONFIG_ANTENNA_DIVERSITY
  567. // Add new function to reset the state of antenna diversity before link.
  568. //
  569. // Compare RSSI for deciding antenna
  570. void AntDivCompare8812(PADAPTER Adapter, WLAN_BSSID_EX *dst, WLAN_BSSID_EX *src)
  571. {
  572. //PADAPTER Adapter = pDM_Odm->Adapter ;
  573. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  574. if(0 != pHalData->AntDivCfg )
  575. {
  576. //DBG_8192C("update_network=> orgRSSI(%d)(%d),newRSSI(%d)(%d)\n",dst->Rssi,query_rx_pwr_percentage(dst->Rssi),
  577. // src->Rssi,query_rx_pwr_percentage(src->Rssi));
  578. //select optimum_antenna for before linked =>For antenna diversity
  579. if(dst->Rssi >= src->Rssi )//keep org parameter
  580. {
  581. src->Rssi = dst->Rssi;
  582. src->PhyInfo.Optimum_antenna = dst->PhyInfo.Optimum_antenna;
  583. }
  584. }
  585. }
  586. // Add new function to reset the state of antenna diversity before link.
  587. u8 AntDivBeforeLink8812(PADAPTER Adapter )
  588. {
  589. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  590. PDM_ODM_T pDM_Odm =&pHalData->odmpriv;
  591. SWAT_T *pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
  592. struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
  593. // Condition that does not need to use antenna diversity.
  594. if(pHalData->AntDivCfg==0)
  595. {
  596. //DBG_8192C("odm_AntDivBeforeLink8192C(): No AntDiv Mechanism.\n");
  597. return _FALSE;
  598. }
  599. if(check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  600. {
  601. return _FALSE;
  602. }
  603. if(pDM_SWAT_Table->SWAS_NoLink_State == 0){
  604. //switch channel
  605. pDM_SWAT_Table->SWAS_NoLink_State = 1;
  606. pDM_SWAT_Table->CurAntenna = (pDM_SWAT_Table->CurAntenna==MAIN_ANT)?AUX_ANT:MAIN_ANT;
  607. //PHY_SetBBReg(Adapter, rFPGA0_XA_RFInterfaceOE, 0x300, pDM_SWAT_Table->CurAntenna);
  608. rtw_antenna_select_cmd(Adapter, pDM_SWAT_Table->CurAntenna, _FALSE);
  609. //DBG_8192C("%s change antenna to ANT_( %s ).....\n",__FUNCTION__, (pDM_SWAT_Table->CurAntenna==MAIN_ANT)?"MAIN":"AUX");
  610. return _TRUE;
  611. }
  612. else
  613. {
  614. pDM_SWAT_Table->SWAS_NoLink_State = 0;
  615. return _FALSE;
  616. }
  617. }
  618. #endif