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 #include <osdep_service.h>
21 #include <drv_types.h>
22
23 #include <hal_intf.h>
24 #include <hal_com.h>
25 #include <rtl8188e_hal.h>
26
27 #define _HAL_INIT_C_
28
dump_chip_info(struct HAL_VERSION chip_vers)29 void dump_chip_info(struct HAL_VERSION chip_vers)
30 {
31 uint cnt = 0;
32 char buf[128];
33
34 if (IS_81XXC(chip_vers)) {
35 cnt += sprintf((buf+cnt), "Chip Version Info: %s_",
36 IS_92C_SERIAL(chip_vers) ?
37 "CHIP_8192C" : "CHIP_8188C");
38 } else if (IS_92D(chip_vers)) {
39 cnt += sprintf((buf+cnt), "Chip Version Info: CHIP_8192D_");
40 } else if (IS_8723_SERIES(chip_vers)) {
41 cnt += sprintf((buf+cnt), "Chip Version Info: CHIP_8723A_");
42 } else if (IS_8188E(chip_vers)) {
43 cnt += sprintf((buf+cnt), "Chip Version Info: CHIP_8188E_");
44 }
45
46 cnt += sprintf((buf+cnt), "%s_", IS_NORMAL_CHIP(chip_vers) ?
47 "Normal_Chip" : "Test_Chip");
48 cnt += sprintf((buf+cnt), "%s_", IS_CHIP_VENDOR_TSMC(chip_vers) ?
49 "TSMC" : "UMC");
50 if (IS_A_CUT(chip_vers))
51 cnt += sprintf((buf+cnt), "A_CUT_");
52 else if (IS_B_CUT(chip_vers))
53 cnt += sprintf((buf+cnt), "B_CUT_");
54 else if (IS_C_CUT(chip_vers))
55 cnt += sprintf((buf+cnt), "C_CUT_");
56 else if (IS_D_CUT(chip_vers))
57 cnt += sprintf((buf+cnt), "D_CUT_");
58 else if (IS_E_CUT(chip_vers))
59 cnt += sprintf((buf+cnt), "E_CUT_");
60 else
61 cnt += sprintf((buf+cnt), "UNKNOWN_CUT(%d)_",
62 chip_vers.CUTVersion);
63
64 if (IS_1T1R(chip_vers))
65 cnt += sprintf((buf+cnt), "1T1R_");
66 else if (IS_1T2R(chip_vers))
67 cnt += sprintf((buf+cnt), "1T2R_");
68 else if (IS_2T2R(chip_vers))
69 cnt += sprintf((buf+cnt), "2T2R_");
70 else
71 cnt += sprintf((buf+cnt), "UNKNOWN_RFTYPE(%d)_",
72 chip_vers.RFType);
73
74 cnt += sprintf((buf+cnt), "RomVer(%d)\n", chip_vers.ROMVer);
75
76 pr_info("%s", buf);
77 }
78
79 #define CHAN_PLAN_HW 0x80
80
81 u8 /* return the final channel plan decision */
hal_com_get_channel_plan(struct adapter * padapter,u8 hw_channel_plan,u8 sw_channel_plan,u8 def_channel_plan,bool load_fail)82 hal_com_get_channel_plan(struct adapter *padapter, u8 hw_channel_plan,
83 u8 sw_channel_plan, u8 def_channel_plan,
84 bool load_fail)
85 {
86 u8 sw_cfg;
87 u8 chnlplan;
88
89 sw_cfg = true;
90 if (!load_fail) {
91 if (!rtw_is_channel_plan_valid(sw_channel_plan))
92 sw_cfg = false;
93 if (hw_channel_plan & CHAN_PLAN_HW)
94 sw_cfg = false;
95 }
96
97 if (sw_cfg)
98 chnlplan = sw_channel_plan;
99 else
100 chnlplan = hw_channel_plan & (~CHAN_PLAN_HW);
101
102 if (!rtw_is_channel_plan_valid(chnlplan))
103 chnlplan = def_channel_plan;
104
105 return chnlplan;
106 }
107
MRateToHwRate(u8 rate)108 u8 MRateToHwRate(u8 rate)
109 {
110 u8 ret = DESC_RATE1M;
111
112 switch (rate) {
113 /* CCK and OFDM non-HT rates */
114 case IEEE80211_CCK_RATE_1MB:
115 ret = DESC_RATE1M;
116 break;
117 case IEEE80211_CCK_RATE_2MB:
118 ret = DESC_RATE2M;
119 break;
120 case IEEE80211_CCK_RATE_5MB:
121 ret = DESC_RATE5_5M;
122 break;
123 case IEEE80211_CCK_RATE_11MB:
124 ret = DESC_RATE11M;
125 break;
126 case IEEE80211_OFDM_RATE_6MB:
127 ret = DESC_RATE6M;
128 break;
129 case IEEE80211_OFDM_RATE_9MB:
130 ret = DESC_RATE9M;
131 break;
132 case IEEE80211_OFDM_RATE_12MB:
133 ret = DESC_RATE12M;
134 break;
135 case IEEE80211_OFDM_RATE_18MB:
136 ret = DESC_RATE18M;
137 break;
138 case IEEE80211_OFDM_RATE_24MB:
139 ret = DESC_RATE24M;
140 break;
141 case IEEE80211_OFDM_RATE_36MB:
142 ret = DESC_RATE36M;
143 break;
144 case IEEE80211_OFDM_RATE_48MB:
145 ret = DESC_RATE48M;
146 break;
147 case IEEE80211_OFDM_RATE_54MB:
148 ret = DESC_RATE54M;
149 break;
150 default:
151 break;
152 }
153 return ret;
154 }
155
HalSetBrateCfg(struct adapter * adapt,u8 * brates,u16 * rate_cfg)156 void HalSetBrateCfg(struct adapter *adapt, u8 *brates, u16 *rate_cfg)
157 {
158 u8 i, is_brate, brate;
159
160 for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
161 is_brate = brates[i] & IEEE80211_BASIC_RATE_MASK;
162 brate = brates[i] & 0x7f;
163
164 if (is_brate) {
165 switch (brate) {
166 case IEEE80211_CCK_RATE_1MB:
167 *rate_cfg |= RATE_1M;
168 break;
169 case IEEE80211_CCK_RATE_2MB:
170 *rate_cfg |= RATE_2M;
171 break;
172 case IEEE80211_CCK_RATE_5MB:
173 *rate_cfg |= RATE_5_5M;
174 break;
175 case IEEE80211_CCK_RATE_11MB:
176 *rate_cfg |= RATE_11M;
177 break;
178 case IEEE80211_OFDM_RATE_6MB:
179 *rate_cfg |= RATE_6M;
180 break;
181 case IEEE80211_OFDM_RATE_9MB:
182 *rate_cfg |= RATE_9M;
183 break;
184 case IEEE80211_OFDM_RATE_12MB:
185 *rate_cfg |= RATE_12M;
186 break;
187 case IEEE80211_OFDM_RATE_18MB:
188 *rate_cfg |= RATE_18M;
189 break;
190 case IEEE80211_OFDM_RATE_24MB:
191 *rate_cfg |= RATE_24M;
192 break;
193 case IEEE80211_OFDM_RATE_36MB:
194 *rate_cfg |= RATE_36M;
195 break;
196 case IEEE80211_OFDM_RATE_48MB:
197 *rate_cfg |= RATE_48M;
198 break;
199 case IEEE80211_OFDM_RATE_54MB:
200 *rate_cfg |= RATE_54M;
201 break;
202 }
203 }
204 }
205 }
206
one_out_pipe(struct adapter * adapter)207 static void one_out_pipe(struct adapter *adapter)
208 {
209 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(adapter);
210
211 pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[0];/* VO */
212 pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[0];/* VI */
213 pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[0];/* BE */
214 pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[0];/* BK */
215
216 pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */
217 pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */
218 pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */
219 pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */
220 }
221
two_out_pipe(struct adapter * adapter,bool wifi_cfg)222 static void two_out_pipe(struct adapter *adapter, bool wifi_cfg)
223 {
224 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(adapter);
225
226 if (wifi_cfg) { /* WMM */
227 /* BK, BE, VI, VO, BCN, CMD, MGT, HIGH, HCCA */
228 /* 0, 1, 0, 1, 0, 0, 0, 0, 0}; */
229 /* 0:H, 1:L */
230
231 pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[1];/* VO */
232 pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[0];/* VI */
233 pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[1];/* BE */
234 pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[0];/* BK */
235
236 pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */
237 pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */
238 pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */
239 pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */
240
241 } else {/* typical setting */
242 /* BK, BE, VI, VO, BCN, CMD, MGT, HIGH, HCCA */
243 /* 1, 1, 0, 0, 0, 0, 0, 0, 0}; */
244 /* 0:H, 1:L */
245
246 pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[0];/* VO */
247 pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[0];/* VI */
248 pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[1];/* BE */
249 pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[1];/* BK */
250
251 pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */
252 pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */
253 pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */
254 pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */
255 }
256 }
257
three_out_pipe(struct adapter * adapter,bool wifi_cfg)258 static void three_out_pipe(struct adapter *adapter, bool wifi_cfg)
259 {
260 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(adapter);
261
262 if (wifi_cfg) {/* for WMM */
263 /* BK, BE, VI, VO, BCN, CMD, MGT, HIGH, HCCA */
264 /* 1, 2, 1, 0, 0, 0, 0, 0, 0}; */
265 /* 0:H, 1:N, 2:L */
266
267 pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[0];/* VO */
268 pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[1];/* VI */
269 pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[2];/* BE */
270 pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[1];/* BK */
271
272 pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */
273 pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */
274 pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */
275 pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */
276
277 } else {/* typical setting */
278 /* BK, BE, VI, VO, BCN, CMD, MGT, HIGH, HCCA */
279 /* 2, 2, 1, 0, 0, 0, 0, 0, 0}; */
280 /* 0:H, 1:N, 2:L */
281
282 pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[0];/* VO */
283 pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[1];/* VI */
284 pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[2];/* BE */
285 pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[2];/* BK */
286
287 pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */
288 pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */
289 pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */
290 pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */
291 }
292 }
293
Hal_MappingOutPipe(struct adapter * adapter,u8 numoutpipe)294 bool Hal_MappingOutPipe(struct adapter *adapter, u8 numoutpipe)
295 {
296 struct registry_priv *pregistrypriv = &adapter->registrypriv;
297 bool wifi_cfg = (pregistrypriv->wifi_spec) ? true : false;
298 bool result = true;
299
300 switch (numoutpipe) {
301 case 2:
302 two_out_pipe(adapter, wifi_cfg);
303 break;
304 case 3:
305 three_out_pipe(adapter, wifi_cfg);
306 break;
307 case 1:
308 one_out_pipe(adapter);
309 break;
310 default:
311 result = false;
312 break;
313 }
314 return result;
315 }
316
hal_init_macaddr(struct adapter * adapter)317 void hal_init_macaddr(struct adapter *adapter)
318 {
319 rtw_hal_set_hwreg(adapter, HW_VAR_MAC_ADDR,
320 adapter->eeprompriv.mac_addr);
321 }
322