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