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 ******************************************************************************/
15 /* */
16 /* Description: */
17 /* */
18 /* This file is for 92CE/92CU dynamic mechanism only */
19 /* */
20 /* */
21 /* */
22 #define _RTL8188E_DM_C_
23
24 #include <osdep_service.h>
25 #include <drv_types.h>
26
27 #include <rtl8188e_hal.h>
28
29 /* Initialize GPIO setting registers */
dm_InitGPIOSetting(struct adapter * Adapter)30 static void dm_InitGPIOSetting(struct adapter *Adapter)
31 {
32 u8 tmp1byte;
33
34 tmp1byte = usb_read8(Adapter, REG_GPIO_MUXCFG);
35 tmp1byte &= (GPIOSEL_GPIO | ~GPIOSEL_ENBT);
36
37 usb_write8(Adapter, REG_GPIO_MUXCFG, tmp1byte);
38 }
39
40 /* */
41 /* functions */
42 /* */
Init_ODM_ComInfo_88E(struct adapter * Adapter)43 static void Init_ODM_ComInfo_88E(struct adapter *Adapter)
44 {
45 struct hal_data_8188e *hal_data = Adapter->HalData;
46 struct dm_priv *pdmpriv = &hal_data->dmpriv;
47 struct odm_dm_struct *dm_odm = &(hal_data->odmpriv);
48
49 /* Init Value */
50 memset(dm_odm, 0, sizeof(*dm_odm));
51
52 dm_odm->Adapter = Adapter;
53 dm_odm->SupportPlatform = ODM_CE;
54 dm_odm->SupportICType = ODM_RTL8188E;
55 dm_odm->CutVersion = ODM_CUT_A;
56 dm_odm->bIsMPChip = hal_data->VersionID.ChipType == NORMAL_CHIP;
57 dm_odm->PatchID = hal_data->CustomerID;
58 dm_odm->bWIFITest = Adapter->registrypriv.wifi_spec;
59
60 dm_odm->AntDivType = hal_data->TRxAntDivType;
61
62 /* Tx power tracking BB swing table. */
63 /* The base index = 12. +((12-n)/2)dB 13~?? = decrease tx pwr by -((n-12)/2)dB */
64 dm_odm->BbSwingIdxOfdm = 12; /* Set defalut value as index 12. */
65 dm_odm->BbSwingIdxOfdmCurrent = 12;
66 dm_odm->BbSwingFlagOfdm = false;
67
68 pdmpriv->InitODMFlag = ODM_RF_CALIBRATION |
69 ODM_RF_TX_PWR_TRACK;
70
71 dm_odm->SupportAbility = pdmpriv->InitODMFlag;
72 }
73
Update_ODM_ComInfo_88E(struct adapter * Adapter)74 static void Update_ODM_ComInfo_88E(struct adapter *Adapter)
75 {
76 struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
77 struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
78 struct pwrctrl_priv *pwrctrlpriv = &Adapter->pwrctrlpriv;
79 struct hal_data_8188e *hal_data = Adapter->HalData;
80 struct odm_dm_struct *dm_odm = &(hal_data->odmpriv);
81 struct dm_priv *pdmpriv = &hal_data->dmpriv;
82 int i;
83
84 pdmpriv->InitODMFlag = ODM_BB_DIG |
85 ODM_BB_RA_MASK |
86 ODM_BB_DYNAMIC_TXPWR |
87 ODM_BB_FA_CNT |
88 ODM_BB_RSSI_MONITOR |
89 ODM_BB_CCK_PD |
90 ODM_BB_PWR_SAVE |
91 ODM_MAC_EDCA_TURBO |
92 ODM_RF_CALIBRATION |
93 ODM_RF_TX_PWR_TRACK;
94 if (hal_data->AntDivCfg)
95 pdmpriv->InitODMFlag |= ODM_BB_ANT_DIV;
96
97 if (Adapter->registrypriv.mp_mode == 1) {
98 pdmpriv->InitODMFlag = ODM_RF_CALIBRATION |
99 ODM_RF_TX_PWR_TRACK;
100 }
101
102 dm_odm->SupportAbility = pdmpriv->InitODMFlag;
103
104 dm_odm->pNumTxBytesUnicast = &Adapter->xmitpriv.tx_bytes;
105 dm_odm->pNumRxBytesUnicast = &Adapter->recvpriv.rx_bytes;
106 dm_odm->pWirelessMode = &pmlmeext->cur_wireless_mode;
107 dm_odm->pSecChOffset = &hal_data->nCur40MhzPrimeSC;
108 dm_odm->pSecurity = (u8 *)&Adapter->securitypriv.dot11PrivacyAlgrthm;
109 dm_odm->pBandWidth = (u8 *)&hal_data->CurrentChannelBW;
110 dm_odm->pChannel = &hal_data->CurrentChannel;
111 dm_odm->pbNet_closed = (bool *)&Adapter->net_closed;
112 dm_odm->mp_mode = &Adapter->registrypriv.mp_mode;
113 dm_odm->pbScanInProcess = (bool *)&pmlmepriv->bScanInProcess;
114 dm_odm->pbPowerSaving = (bool *)&pwrctrlpriv->bpower_saving;
115 dm_odm->AntDivType = hal_data->TRxAntDivType;
116
117 /* Tx power tracking BB swing table. */
118 /* The base index = 12. +((12-n)/2)dB 13~?? = decrease tx pwr by -((n-12)/2)dB */
119 dm_odm->BbSwingIdxOfdm = 12; /* Set defalut value as index 12. */
120 dm_odm->BbSwingIdxOfdmCurrent = 12;
121 dm_odm->BbSwingFlagOfdm = false;
122
123 for (i = 0; i < NUM_STA; i++)
124 ODM_CmnInfoPtrArrayHook(dm_odm, ODM_CMNINFO_STA_STATUS, i, NULL);
125 }
126
rtl8188e_InitHalDm(struct adapter * Adapter)127 void rtl8188e_InitHalDm(struct adapter *Adapter)
128 {
129 struct dm_priv *pdmpriv = &Adapter->HalData->dmpriv;
130 struct odm_dm_struct *dm_odm = &(Adapter->HalData->odmpriv);
131
132 dm_InitGPIOSetting(Adapter);
133 pdmpriv->DM_Type = DM_Type_ByDriver;
134 pdmpriv->DMFlag = DYNAMIC_FUNC_DISABLE;
135 Update_ODM_ComInfo_88E(Adapter);
136 ODM_DMInit(dm_odm);
137 }
138
rtw_hal_dm_watchdog(struct adapter * Adapter)139 void rtw_hal_dm_watchdog(struct adapter *Adapter)
140 {
141 u8 hw_init_completed = false;
142 struct mlme_priv *pmlmepriv = NULL;
143 u8 bLinked = false;
144
145 hw_init_completed = Adapter->hw_init_completed;
146
147 if (!hw_init_completed)
148 goto skip_dm;
149
150 /* ODM */
151 pmlmepriv = &Adapter->mlmepriv;
152
153 if ((check_fwstate(pmlmepriv, WIFI_AP_STATE)) ||
154 (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE |
155 WIFI_ADHOC_MASTER_STATE))) {
156 if (Adapter->stapriv.asoc_sta_count > 2)
157 bLinked = true;
158 } else {/* Station mode */
159 if (check_fwstate(pmlmepriv, _FW_LINKED))
160 bLinked = true;
161 }
162
163 Adapter->HalData->odmpriv.bLinked = bLinked;
164 ODM_DMWatchdog(&Adapter->HalData->odmpriv);
165 skip_dm:
166 /* Check GPIO to determine current RF on/off and Pbc status. */
167 /* Check Hardware Radio ON/OFF or not */
168 return;
169 }
170
rtw_hal_dm_init(struct adapter * Adapter)171 void rtw_hal_dm_init(struct adapter *Adapter)
172 {
173 struct dm_priv *pdmpriv = &Adapter->HalData->dmpriv;
174 struct odm_dm_struct *podmpriv = &Adapter->HalData->odmpriv;
175
176 memset(pdmpriv, 0, sizeof(struct dm_priv));
177 Init_ODM_ComInfo_88E(Adapter);
178 ODM_InitDebugSetting(podmpriv);
179 }
180
181 /* Add new function to reset the state of antenna diversity before link. */
182 /* Compare RSSI for deciding antenna */
rtw_hal_antdiv_rssi_compared(struct adapter * Adapter,struct wlan_bssid_ex * dst,struct wlan_bssid_ex * src)183 void rtw_hal_antdiv_rssi_compared(struct adapter *Adapter, struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src)
184 {
185 if (0 != Adapter->HalData->AntDivCfg) {
186 /* select optimum_antenna for before linked =>For antenna diversity */
187 if (dst->Rssi >= src->Rssi) {/* keep org parameter */
188 src->Rssi = dst->Rssi;
189 src->PhyInfo.Optimum_antenna = dst->PhyInfo.Optimum_antenna;
190 }
191 }
192 }
193
194 /* Add new function to reset the state of antenna diversity before link. */
rtw_hal_antdiv_before_linked(struct adapter * Adapter)195 u8 rtw_hal_antdiv_before_linked(struct adapter *Adapter)
196 {
197 struct odm_dm_struct *dm_odm = &Adapter->HalData->odmpriv;
198 struct sw_ant_switch *dm_swat_tbl = &dm_odm->DM_SWAT_Table;
199 struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
200
201 /* Condition that does not need to use antenna diversity. */
202 if (Adapter->HalData->AntDivCfg == 0)
203 return false;
204
205 if (check_fwstate(pmlmepriv, _FW_LINKED))
206 return false;
207
208 if (dm_swat_tbl->SWAS_NoLink_State == 0) {
209 /* switch channel */
210 dm_swat_tbl->SWAS_NoLink_State = 1;
211 dm_swat_tbl->CurAntenna = (dm_swat_tbl->CurAntenna == Antenna_A) ? Antenna_B : Antenna_A;
212
213 rtw_antenna_select_cmd(Adapter, dm_swat_tbl->CurAntenna, false);
214 return true;
215 } else {
216 dm_swat_tbl->SWAS_NoLink_State = 0;
217 return false;
218 }
219 }
220