1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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.
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
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
19 ******************************************************************************/
20 #include <osdep_service.h>
21 #include <drv_types.h>
25 #include <rtl8188e_hal.h>
29 void dump_chip_info(struct HAL_VERSION chip_vers)
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_");
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) ?
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_");
61 cnt += sprintf((buf+cnt), "UNKNOWN_CUT(%d)_",
62 chip_vers.CUTVersion);
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_");
71 cnt += sprintf((buf+cnt), "UNKNOWN_RFTYPE(%d)_",
74 cnt += sprintf((buf+cnt), "RomVer(%d)\n", chip_vers.ROMVer);
79 #define CHAN_PLAN_HW 0x80
81 u8 /* return the final channel plan decision */
82 hal_com_get_channel_plan(struct adapter *padapter, u8 hw_channel_plan,
83 u8 sw_channel_plan, u8 def_channel_plan,
91 if (!rtw_is_channel_plan_valid(sw_channel_plan))
93 if (hw_channel_plan & CHAN_PLAN_HW)
98 chnlplan = sw_channel_plan;
100 chnlplan = hw_channel_plan & (~CHAN_PLAN_HW);
102 if (!rtw_is_channel_plan_valid(chnlplan))
103 chnlplan = def_channel_plan;
108 u8 MRateToHwRate(u8 rate)
110 u8 ret = DESC_RATE1M;
113 /* CCK and OFDM non-HT rates */
114 case IEEE80211_CCK_RATE_1MB:
117 case IEEE80211_CCK_RATE_2MB:
120 case IEEE80211_CCK_RATE_5MB:
123 case IEEE80211_CCK_RATE_11MB:
126 case IEEE80211_OFDM_RATE_6MB:
129 case IEEE80211_OFDM_RATE_9MB:
132 case IEEE80211_OFDM_RATE_12MB:
135 case IEEE80211_OFDM_RATE_18MB:
138 case IEEE80211_OFDM_RATE_24MB:
141 case IEEE80211_OFDM_RATE_36MB:
144 case IEEE80211_OFDM_RATE_48MB:
147 case IEEE80211_OFDM_RATE_54MB:
156 void HalSetBrateCfg(struct adapter *adapt, u8 *brates, u16 *rate_cfg)
158 u8 i, is_brate, brate;
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;
166 case IEEE80211_CCK_RATE_1MB:
167 *rate_cfg |= RATE_1M;
169 case IEEE80211_CCK_RATE_2MB:
170 *rate_cfg |= RATE_2M;
172 case IEEE80211_CCK_RATE_5MB:
173 *rate_cfg |= RATE_5_5M;
175 case IEEE80211_CCK_RATE_11MB:
176 *rate_cfg |= RATE_11M;
178 case IEEE80211_OFDM_RATE_6MB:
179 *rate_cfg |= RATE_6M;
181 case IEEE80211_OFDM_RATE_9MB:
182 *rate_cfg |= RATE_9M;
184 case IEEE80211_OFDM_RATE_12MB:
185 *rate_cfg |= RATE_12M;
187 case IEEE80211_OFDM_RATE_18MB:
188 *rate_cfg |= RATE_18M;
190 case IEEE80211_OFDM_RATE_24MB:
191 *rate_cfg |= RATE_24M;
193 case IEEE80211_OFDM_RATE_36MB:
194 *rate_cfg |= RATE_36M;
196 case IEEE80211_OFDM_RATE_48MB:
197 *rate_cfg |= RATE_48M;
199 case IEEE80211_OFDM_RATE_54MB:
200 *rate_cfg |= RATE_54M;
207 static void one_out_pipe(struct adapter *adapter)
209 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(adapter);
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 */
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 */
222 static void two_out_pipe(struct adapter *adapter, bool wifi_cfg)
224 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(adapter);
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}; */
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 */
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 */
241 } else {/* typical setting */
242 /* BK, BE, VI, VO, BCN, CMD, MGT, HIGH, HCCA */
243 /* 1, 1, 0, 0, 0, 0, 0, 0, 0}; */
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 */
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 */
258 static void three_out_pipe(struct adapter *adapter, bool wifi_cfg)
260 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(adapter);
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}; */
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 */
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 */
277 } else {/* typical setting */
278 /* BK, BE, VI, VO, BCN, CMD, MGT, HIGH, HCCA */
279 /* 2, 2, 1, 0, 0, 0, 0, 0, 0}; */
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 */
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 */
294 bool Hal_MappingOutPipe(struct adapter *adapter, u8 numoutpipe)
296 struct registry_priv *pregistrypriv = &adapter->registrypriv;
297 bool wifi_cfg = (pregistrypriv->wifi_spec) ? true : false;
300 switch (numoutpipe) {
302 two_out_pipe(adapter, wifi_cfg);
305 three_out_pipe(adapter, wifi_cfg);
308 one_out_pipe(adapter);
317 void hal_init_macaddr(struct adapter *adapter)
319 rtw_hal_set_hwreg(adapter, HW_VAR_MAC_ADDR,
320 adapter->eeprompriv.mac_addr);
325 * Field TRIGGER CONTENT CMD_SEQ CMD_LEN CMD_ID
326 * BITS [127:120] [119:16] [15:8] [7:4] [3:0]
329 void c2h_evt_clear(struct adapter *adapter)
331 rtw_write8(adapter, REG_C2HEVT_CLEAR, C2H_EVT_HOST_CLOSE);
334 s32 c2h_evt_read(struct adapter *adapter, u8 *buf)
337 struct c2h_evt_hdr *c2h_evt;
344 trigger = rtw_read8(adapter, REG_C2HEVT_CLEAR);
346 if (trigger == C2H_EVT_HOST_CLOSE)
347 goto exit; /* Not ready */
348 else if (trigger != C2H_EVT_FW_CLOSE)
349 goto clear_evt; /* Not a valid value */
351 c2h_evt = (struct c2h_evt_hdr *)buf;
353 _rtw_memset(c2h_evt, 0, 16);
355 *buf = rtw_read8(adapter, REG_C2HEVT_MSG_NORMAL);
356 *(buf+1) = rtw_read8(adapter, REG_C2HEVT_MSG_NORMAL + 1);
358 RT_PRINT_DATA(_module_hal_init_c_, _drv_info_, "c2h_evt_read(): ",
359 &c2h_evt , sizeof(c2h_evt));
361 /* Read the content */
362 for (i = 0; i < c2h_evt->plen; i++)
363 c2h_evt->payload[i] = rtw_read8(adapter, REG_C2HEVT_MSG_NORMAL +
364 sizeof(*c2h_evt) + i);
366 RT_PRINT_DATA(_module_hal_init_c_, _drv_info_,
367 "c2h_evt_read(): Command Content:\n",
368 c2h_evt->payload, c2h_evt->plen);
374 * Clear event to notify FW we have read the command.
375 * If this field isn't clear, the FW won't update the next
378 c2h_evt_clear(adapter);