• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 _RTL8188E_DM_C_
28 
29 #include <osdep_service.h>
30 #include <drv_types.h>
31 
32 #include <rtl8188e_hal.h>
33 
34 /*  Initialize GPIO setting registers */
dm_InitGPIOSetting(struct adapter * Adapter)35 static void dm_InitGPIOSetting(struct adapter *Adapter)
36 {
37 	u8	tmp1byte;
38 
39 	tmp1byte = usb_read8(Adapter, REG_GPIO_MUXCFG);
40 	tmp1byte &= (GPIOSEL_GPIO | ~GPIOSEL_ENBT);
41 
42 	usb_write8(Adapter, REG_GPIO_MUXCFG, tmp1byte);
43 }
44 
45 /*  */
46 /*  functions */
47 /*  */
Init_ODM_ComInfo_88E(struct adapter * Adapter)48 static void Init_ODM_ComInfo_88E(struct adapter *Adapter)
49 {
50 	struct hal_data_8188e *hal_data = GET_HAL_DATA(Adapter);
51 	struct dm_priv	*pdmpriv = &hal_data->dmpriv;
52 	struct odm_dm_struct *dm_odm = &(hal_data->odmpriv);
53 	u8 cut_ver, fab_ver;
54 
55 	/*  Init Value */
56 	memset(dm_odm, 0, sizeof(*dm_odm));
57 
58 	dm_odm->Adapter = Adapter;
59 
60 	ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_PLATFORM, ODM_CE);
61 
62 	ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_IC_TYPE, ODM_RTL8188E);
63 
64 	fab_ver = ODM_TSMC;
65 	cut_ver = ODM_CUT_A;
66 
67 	ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_FAB_VER, fab_ver);
68 	ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_CUT_VER, cut_ver);
69 
70 	ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_MP_TEST_CHIP, IS_NORMAL_CHIP(hal_data->VersionID));
71 
72 	ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_PATCH_ID, hal_data->CustomerID);
73 	ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_BWIFI_TEST, Adapter->registrypriv.wifi_spec);
74 
75 
76 	if (hal_data->rf_type == RF_1T1R)
77 		ODM_CmnInfoUpdate(dm_odm, ODM_CMNINFO_RF_TYPE, ODM_1T1R);
78 	else if (hal_data->rf_type == RF_2T2R)
79 		ODM_CmnInfoUpdate(dm_odm, ODM_CMNINFO_RF_TYPE, ODM_2T2R);
80 	else if (hal_data->rf_type == RF_1T2R)
81 		ODM_CmnInfoUpdate(dm_odm, ODM_CMNINFO_RF_TYPE, ODM_1T2R);
82 
83 	ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_RF_ANTENNA_TYPE, hal_data->TRxAntDivType);
84 
85 	pdmpriv->InitODMFlag =	ODM_RF_CALIBRATION |
86 				ODM_RF_TX_PWR_TRACK;
87 
88 	ODM_CmnInfoUpdate(dm_odm, ODM_CMNINFO_ABILITY, pdmpriv->InitODMFlag);
89 }
90 
Update_ODM_ComInfo_88E(struct adapter * Adapter)91 static void Update_ODM_ComInfo_88E(struct adapter *Adapter)
92 {
93 	struct mlme_ext_priv	*pmlmeext = &Adapter->mlmeextpriv;
94 	struct mlme_priv	*pmlmepriv = &Adapter->mlmepriv;
95 	struct pwrctrl_priv *pwrctrlpriv = &Adapter->pwrctrlpriv;
96 	struct hal_data_8188e *hal_data = GET_HAL_DATA(Adapter);
97 	struct odm_dm_struct *dm_odm = &(hal_data->odmpriv);
98 	struct dm_priv	*pdmpriv = &hal_data->dmpriv;
99 	int i;
100 
101 	pdmpriv->InitODMFlag =	ODM_BB_DIG |
102 				ODM_BB_RA_MASK |
103 				ODM_BB_DYNAMIC_TXPWR |
104 				ODM_BB_FA_CNT |
105 				ODM_BB_RSSI_MONITOR |
106 				ODM_BB_CCK_PD |
107 				ODM_BB_PWR_SAVE |
108 				ODM_MAC_EDCA_TURBO |
109 				ODM_RF_CALIBRATION |
110 				ODM_RF_TX_PWR_TRACK;
111 	if (hal_data->AntDivCfg)
112 		pdmpriv->InitODMFlag |= ODM_BB_ANT_DIV;
113 
114 	if (Adapter->registrypriv.mp_mode == 1) {
115 		pdmpriv->InitODMFlag =	ODM_RF_CALIBRATION |
116 					ODM_RF_TX_PWR_TRACK;
117 	}
118 
119 	ODM_CmnInfoUpdate(dm_odm, ODM_CMNINFO_ABILITY, pdmpriv->InitODMFlag);
120 
121 	ODM_CmnInfoHook(dm_odm, ODM_CMNINFO_TX_UNI, &(Adapter->xmitpriv.tx_bytes));
122 	ODM_CmnInfoHook(dm_odm, ODM_CMNINFO_RX_UNI, &(Adapter->recvpriv.rx_bytes));
123 	ODM_CmnInfoHook(dm_odm, ODM_CMNINFO_WM_MODE, &(pmlmeext->cur_wireless_mode));
124 	ODM_CmnInfoHook(dm_odm, ODM_CMNINFO_SEC_CHNL_OFFSET, &(hal_data->nCur40MhzPrimeSC));
125 	ODM_CmnInfoHook(dm_odm, ODM_CMNINFO_SEC_MODE, &(Adapter->securitypriv.dot11PrivacyAlgrthm));
126 	ODM_CmnInfoHook(dm_odm, ODM_CMNINFO_BW, &(hal_data->CurrentChannelBW));
127 	ODM_CmnInfoHook(dm_odm, ODM_CMNINFO_CHNL, &(hal_data->CurrentChannel));
128 	ODM_CmnInfoHook(dm_odm, ODM_CMNINFO_NET_CLOSED, &(Adapter->net_closed));
129 	ODM_CmnInfoHook(dm_odm, ODM_CMNINFO_MP_MODE, &(Adapter->registrypriv.mp_mode));
130 	ODM_CmnInfoHook(dm_odm, ODM_CMNINFO_SCAN, &(pmlmepriv->bScanInProcess));
131 	ODM_CmnInfoHook(dm_odm, ODM_CMNINFO_POWER_SAVING, &(pwrctrlpriv->bpower_saving));
132 	ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_RF_ANTENNA_TYPE, hal_data->TRxAntDivType);
133 
134 	for (i = 0; i < NUM_STA; i++)
135 		ODM_CmnInfoPtrArrayHook(dm_odm, ODM_CMNINFO_STA_STATUS, i, NULL);
136 }
137 
rtl8188e_InitHalDm(struct adapter * Adapter)138 void rtl8188e_InitHalDm(struct adapter *Adapter)
139 {
140 	struct hal_data_8188e *hal_data = GET_HAL_DATA(Adapter);
141 	struct dm_priv	*pdmpriv = &hal_data->dmpriv;
142 	struct odm_dm_struct *dm_odm = &(hal_data->odmpriv);
143 
144 	dm_InitGPIOSetting(Adapter);
145 	pdmpriv->DM_Type = DM_Type_ByDriver;
146 	pdmpriv->DMFlag = DYNAMIC_FUNC_DISABLE;
147 	Update_ODM_ComInfo_88E(Adapter);
148 	ODM_DMInit(dm_odm);
149 	Adapter->fix_rate = 0xFF;
150 }
151 
rtl8188e_HalDmWatchDog(struct adapter * Adapter)152 void rtl8188e_HalDmWatchDog(struct adapter *Adapter)
153 {
154 	bool fw_cur_in_ps = false;
155 	bool fw_ps_awake = true;
156 	u8 hw_init_completed = false;
157 	struct hal_data_8188e *hal_data = GET_HAL_DATA(Adapter);
158 
159 	hw_init_completed = Adapter->hw_init_completed;
160 
161 	if (!hw_init_completed)
162 		goto skip_dm;
163 
164 	fw_cur_in_ps = Adapter->pwrctrlpriv.bFwCurrentInPSMode;
165 	rtw_hal_get_hwreg(Adapter, HW_VAR_FWLPS_RF_ON, (u8 *)(&fw_ps_awake));
166 
167 	/*  Fw is under p2p powersaving mode, driver should stop dynamic mechanism. */
168 	/*  modifed by thomas. 2011.06.11. */
169 	if (Adapter->wdinfo.p2p_ps_mode)
170 		fw_ps_awake = false;
171 
172 	/* ODM */
173 	if (hw_init_completed) {
174 		struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
175 		u8 bLinked = false;
176 
177 		if ((check_fwstate(pmlmepriv, WIFI_AP_STATE)) ||
178 		    (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE))) {
179 			if (Adapter->stapriv.asoc_sta_count > 2)
180 				bLinked = true;
181 		} else {/* Station mode */
182 			if (check_fwstate(pmlmepriv, _FW_LINKED))
183 				bLinked = true;
184 		}
185 
186 		ODM_CmnInfoUpdate(&hal_data->odmpriv, ODM_CMNINFO_LINK, bLinked);
187 		ODM_DMWatchdog(&hal_data->odmpriv);
188 	}
189 skip_dm:
190 	/*  Check GPIO to determine current RF on/off and Pbc status. */
191 	/*  Check Hardware Radio ON/OFF or not */
192 	return;
193 }
194 
rtl8188e_init_dm_priv(struct adapter * Adapter)195 void rtl8188e_init_dm_priv(struct adapter *Adapter)
196 {
197 	struct hal_data_8188e *hal_data = GET_HAL_DATA(Adapter);
198 	struct dm_priv	*pdmpriv = &hal_data->dmpriv;
199 	struct odm_dm_struct *podmpriv = &hal_data->odmpriv;
200 
201 	memset(pdmpriv, 0, sizeof(struct dm_priv));
202 	Init_ODM_ComInfo_88E(Adapter);
203 	ODM_InitDebugSetting(podmpriv);
204 }
205 
206 /*  Add new function to reset the state of antenna diversity before link. */
207 /*  Compare RSSI for deciding antenna */
AntDivCompare8188E(struct adapter * Adapter,struct wlan_bssid_ex * dst,struct wlan_bssid_ex * src)208 void AntDivCompare8188E(struct adapter *Adapter, struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src)
209 {
210 	struct hal_data_8188e *hal_data = GET_HAL_DATA(Adapter);
211 
212 	if (0 != hal_data->AntDivCfg) {
213 		/* select optimum_antenna for before linked =>For antenna diversity */
214 		if (dst->Rssi >=  src->Rssi) {/* keep org parameter */
215 			src->Rssi = dst->Rssi;
216 			src->PhyInfo.Optimum_antenna = dst->PhyInfo.Optimum_antenna;
217 		}
218 	}
219 }
220 
221 /*  Add new function to reset the state of antenna diversity before link. */
AntDivBeforeLink8188E(struct adapter * Adapter)222 u8 AntDivBeforeLink8188E(struct adapter *Adapter)
223 {
224 	struct hal_data_8188e *hal_data = GET_HAL_DATA(Adapter);
225 	struct odm_dm_struct *dm_odm = &hal_data->odmpriv;
226 	struct sw_ant_switch *dm_swat_tbl = &dm_odm->DM_SWAT_Table;
227 	struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
228 
229 	/*  Condition that does not need to use antenna diversity. */
230 	if (hal_data->AntDivCfg == 0)
231 		return false;
232 
233 	if (check_fwstate(pmlmepriv, _FW_LINKED))
234 		return false;
235 
236 	if (dm_swat_tbl->SWAS_NoLink_State == 0) {
237 		/* switch channel */
238 		dm_swat_tbl->SWAS_NoLink_State = 1;
239 		dm_swat_tbl->CurAntenna = (dm_swat_tbl->CurAntenna == Antenna_A) ? Antenna_B : Antenna_A;
240 
241 		rtw_antenna_select_cmd(Adapter, dm_swat_tbl->CurAntenna, false);
242 		return true;
243 	} else {
244 		dm_swat_tbl->SWAS_NoLink_State = 0;
245 		return false;
246 	}
247 }
248