• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2012 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 #define _HAL_INTF_C_
17 
18 #include <drv_types.h>
19 #include <rtw_debug.h>
20 #include <hal_data.h>
21 
rtw_hal_chip_configure(struct adapter * padapter)22 void rtw_hal_chip_configure(struct adapter *padapter)
23 {
24 	if (padapter->HalFunc.intf_chip_configure)
25 		padapter->HalFunc.intf_chip_configure(padapter);
26 }
27 
rtw_hal_read_chip_info(struct adapter * padapter)28 void rtw_hal_read_chip_info(struct adapter *padapter)
29 {
30 	if (padapter->HalFunc.read_adapter_info)
31 		padapter->HalFunc.read_adapter_info(padapter);
32 }
33 
rtw_hal_read_chip_version(struct adapter * padapter)34 void rtw_hal_read_chip_version(struct adapter *padapter)
35 {
36 	if (padapter->HalFunc.read_chip_version)
37 		padapter->HalFunc.read_chip_version(padapter);
38 }
39 
rtw_hal_def_value_init(struct adapter * padapter)40 void rtw_hal_def_value_init(struct adapter *padapter)
41 {
42 	if (is_primary_adapter(padapter))
43 		if (padapter->HalFunc.init_default_value)
44 			padapter->HalFunc.init_default_value(padapter);
45 }
46 
rtw_hal_free_data(struct adapter * padapter)47 void rtw_hal_free_data(struct adapter *padapter)
48 {
49 	/* free HAL Data */
50 	rtw_hal_data_deinit(padapter);
51 
52 	if (is_primary_adapter(padapter))
53 		if (padapter->HalFunc.free_hal_data)
54 			padapter->HalFunc.free_hal_data(padapter);
55 }
56 
rtw_hal_dm_init(struct adapter * padapter)57 void rtw_hal_dm_init(struct adapter *padapter)
58 {
59 	if (is_primary_adapter(padapter))
60 		if (padapter->HalFunc.dm_init)
61 			padapter->HalFunc.dm_init(padapter);
62 }
63 
rtw_hal_dm_deinit(struct adapter * padapter)64 void rtw_hal_dm_deinit(struct adapter *padapter)
65 {
66 	/*  cancel dm  timer */
67 	if (is_primary_adapter(padapter))
68 		if (padapter->HalFunc.dm_deinit)
69 			padapter->HalFunc.dm_deinit(padapter);
70 }
71 
rtw_hal_init_opmode(struct adapter * padapter)72 static void rtw_hal_init_opmode(struct adapter *padapter)
73 {
74 	enum NDIS_802_11_NETWORK_INFRASTRUCTURE networkType = Ndis802_11InfrastructureMax;
75 	struct  mlme_priv *pmlmepriv = &(padapter->mlmepriv);
76 	sint fw_state;
77 
78 	fw_state = get_fwstate(pmlmepriv);
79 
80 	if (fw_state & WIFI_ADHOC_STATE)
81 		networkType = Ndis802_11IBSS;
82 	else if (fw_state & WIFI_STATION_STATE)
83 		networkType = Ndis802_11Infrastructure;
84 	else if (fw_state & WIFI_AP_STATE)
85 		networkType = Ndis802_11APMode;
86 	else
87 		return;
88 
89 	rtw_setopmode_cmd(padapter, networkType, false);
90 }
91 
rtw_hal_init(struct adapter * padapter)92 uint rtw_hal_init(struct adapter *padapter)
93 {
94 	uint status;
95 	struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
96 
97 	status = padapter->HalFunc.hal_init(padapter);
98 
99 	if (status == _SUCCESS) {
100 		rtw_hal_init_opmode(padapter);
101 
102 		dvobj->padapters->hw_init_completed = true;
103 
104 		if (padapter->registrypriv.notch_filter == 1)
105 			rtw_hal_notch_filter(padapter, 1);
106 
107 		rtw_hal_reset_security_engine(padapter);
108 
109 		rtw_sec_restore_wep_key(dvobj->padapters);
110 
111 		init_hw_mlme_ext(padapter);
112 
113 		rtw_bb_rf_gain_offset(padapter);
114 	} else {
115 		dvobj->padapters->hw_init_completed = false;
116 		DBG_871X("rtw_hal_init: hal__init fail\n");
117 	}
118 
119 	RT_TRACE(_module_hal_init_c_, _drv_err_, ("-rtl871x_hal_init:status = 0x%x\n", status));
120 
121 	return status;
122 
123 }
124 
rtw_hal_deinit(struct adapter * padapter)125 uint rtw_hal_deinit(struct adapter *padapter)
126 {
127 	uint	status = _SUCCESS;
128 	struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
129 
130 	status = padapter->HalFunc.hal_deinit(padapter);
131 
132 	if (status == _SUCCESS) {
133 		padapter = dvobj->padapters;
134 		padapter->hw_init_completed = false;
135 	} else {
136 		DBG_871X("\n rtw_hal_deinit: hal_init fail\n");
137 	}
138 	return status;
139 }
140 
rtw_hal_set_hwreg(struct adapter * padapter,u8 variable,u8 * val)141 void rtw_hal_set_hwreg(struct adapter *padapter, u8 variable, u8 *val)
142 {
143 	if (padapter->HalFunc.SetHwRegHandler)
144 		padapter->HalFunc.SetHwRegHandler(padapter, variable, val);
145 }
146 
rtw_hal_get_hwreg(struct adapter * padapter,u8 variable,u8 * val)147 void rtw_hal_get_hwreg(struct adapter *padapter, u8 variable, u8 *val)
148 {
149 	if (padapter->HalFunc.GetHwRegHandler)
150 		padapter->HalFunc.GetHwRegHandler(padapter, variable, val);
151 }
152 
rtw_hal_set_hwreg_with_buf(struct adapter * padapter,u8 variable,u8 * pbuf,int len)153 void rtw_hal_set_hwreg_with_buf(struct adapter *padapter, u8 variable, u8 *pbuf, int len)
154 {
155 	if (padapter->HalFunc.SetHwRegHandlerWithBuf)
156 		padapter->HalFunc.SetHwRegHandlerWithBuf(padapter, variable, pbuf, len);
157 }
158 
rtw_hal_set_def_var(struct adapter * padapter,enum HAL_DEF_VARIABLE eVariable,void * pValue)159 u8 rtw_hal_set_def_var(struct adapter *padapter, enum HAL_DEF_VARIABLE eVariable, void *pValue)
160 {
161 	if (padapter->HalFunc.SetHalDefVarHandler)
162 		return padapter->HalFunc.SetHalDefVarHandler(padapter, eVariable, pValue);
163 	return _FAIL;
164 }
165 
rtw_hal_get_def_var(struct adapter * padapter,enum HAL_DEF_VARIABLE eVariable,void * pValue)166 u8 rtw_hal_get_def_var(struct adapter *padapter, enum HAL_DEF_VARIABLE eVariable, void *pValue)
167 {
168 	if (padapter->HalFunc.GetHalDefVarHandler)
169 		return padapter->HalFunc.GetHalDefVarHandler(padapter, eVariable, pValue);
170 	return _FAIL;
171 }
172 
rtw_hal_set_odm_var(struct adapter * padapter,enum HAL_ODM_VARIABLE eVariable,void * pValue1,bool bSet)173 void rtw_hal_set_odm_var(struct adapter *padapter, enum HAL_ODM_VARIABLE eVariable, void *pValue1, bool bSet)
174 {
175 	if (padapter->HalFunc.SetHalODMVarHandler)
176 		padapter->HalFunc.SetHalODMVarHandler(padapter, eVariable, pValue1, bSet);
177 }
178 
rtw_hal_get_odm_var(struct adapter * padapter,enum HAL_ODM_VARIABLE eVariable,void * pValue1,void * pValue2)179 void rtw_hal_get_odm_var(struct adapter *padapter, enum HAL_ODM_VARIABLE eVariable, void *pValue1, void *pValue2)
180 {
181 	if (padapter->HalFunc.GetHalODMVarHandler)
182 		padapter->HalFunc.GetHalODMVarHandler(padapter, eVariable, pValue1, pValue2);
183 }
184 
rtw_hal_enable_interrupt(struct adapter * padapter)185 void rtw_hal_enable_interrupt(struct adapter *padapter)
186 {
187 	if (padapter->HalFunc.enable_interrupt)
188 		padapter->HalFunc.enable_interrupt(padapter);
189 	else
190 		DBG_871X("%s: HalFunc.enable_interrupt is NULL!\n", __func__);
191 
192 }
193 
rtw_hal_disable_interrupt(struct adapter * padapter)194 void rtw_hal_disable_interrupt(struct adapter *padapter)
195 {
196 	if (padapter->HalFunc.disable_interrupt)
197 		padapter->HalFunc.disable_interrupt(padapter);
198 	else
199 		DBG_871X("%s: HalFunc.disable_interrupt is NULL!\n", __func__);
200 
201 }
202 
rtw_hal_check_ips_status(struct adapter * padapter)203 u8 rtw_hal_check_ips_status(struct adapter *padapter)
204 {
205 	u8 val = false;
206 	if (padapter->HalFunc.check_ips_status)
207 		val = padapter->HalFunc.check_ips_status(padapter);
208 	else
209 		DBG_871X("%s: HalFunc.check_ips_status is NULL!\n", __func__);
210 
211 	return val;
212 }
213 
rtw_hal_xmitframe_enqueue(struct adapter * padapter,struct xmit_frame * pxmitframe)214 s32	rtw_hal_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe)
215 {
216 	if (padapter->HalFunc.hal_xmitframe_enqueue)
217 		return padapter->HalFunc.hal_xmitframe_enqueue(padapter, pxmitframe);
218 
219 	return false;
220 }
221 
rtw_hal_xmit(struct adapter * padapter,struct xmit_frame * pxmitframe)222 s32	rtw_hal_xmit(struct adapter *padapter, struct xmit_frame *pxmitframe)
223 {
224 	if (padapter->HalFunc.hal_xmit)
225 		return padapter->HalFunc.hal_xmit(padapter, pxmitframe);
226 
227 	return false;
228 }
229 
230 /*
231  * [IMPORTANT] This function would be run in interrupt context.
232  */
rtw_hal_mgnt_xmit(struct adapter * padapter,struct xmit_frame * pmgntframe)233 s32	rtw_hal_mgnt_xmit(struct adapter *padapter, struct xmit_frame *pmgntframe)
234 {
235 	s32 ret = _FAIL;
236 	update_mgntframe_attrib_addr(padapter, pmgntframe);
237 	/* pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; */
238 	/* pwlanhdr = (struct rtw_ieee80211_hdr *)pframe; */
239 	/* memcpy(pmgntframe->attrib.ra, pwlanhdr->addr1, ETH_ALEN); */
240 
241 	if (padapter->securitypriv.binstallBIPkey == true) {
242 		if (IS_MCAST(pmgntframe->attrib.ra)) {
243 			pmgntframe->attrib.encrypt = _BIP_;
244 			/* pmgntframe->attrib.bswenc = true; */
245 		} else {
246 			pmgntframe->attrib.encrypt = _AES_;
247 			pmgntframe->attrib.bswenc = true;
248 		}
249 		rtw_mgmt_xmitframe_coalesce(padapter, pmgntframe->pkt, pmgntframe);
250 	}
251 
252 	if (padapter->HalFunc.mgnt_xmit)
253 		ret = padapter->HalFunc.mgnt_xmit(padapter, pmgntframe);
254 	return ret;
255 }
256 
rtw_hal_init_xmit_priv(struct adapter * padapter)257 s32	rtw_hal_init_xmit_priv(struct adapter *padapter)
258 {
259 	if (padapter->HalFunc.init_xmit_priv != NULL)
260 		return padapter->HalFunc.init_xmit_priv(padapter);
261 	return _FAIL;
262 }
263 
rtw_hal_free_xmit_priv(struct adapter * padapter)264 void rtw_hal_free_xmit_priv(struct adapter *padapter)
265 {
266 	if (padapter->HalFunc.free_xmit_priv != NULL)
267 		padapter->HalFunc.free_xmit_priv(padapter);
268 }
269 
rtw_hal_init_recv_priv(struct adapter * padapter)270 s32	rtw_hal_init_recv_priv(struct adapter *padapter)
271 {
272 	if (padapter->HalFunc.init_recv_priv)
273 		return padapter->HalFunc.init_recv_priv(padapter);
274 
275 	return _FAIL;
276 }
277 
rtw_hal_free_recv_priv(struct adapter * padapter)278 void rtw_hal_free_recv_priv(struct adapter *padapter)
279 {
280 
281 	if (padapter->HalFunc.free_recv_priv)
282 		padapter->HalFunc.free_recv_priv(padapter);
283 }
284 
rtw_hal_update_ra_mask(struct sta_info * psta,u8 rssi_level)285 void rtw_hal_update_ra_mask(struct sta_info *psta, u8 rssi_level)
286 {
287 	struct adapter *padapter;
288 	struct mlme_priv *pmlmepriv;
289 
290 	if (!psta)
291 		return;
292 
293 	padapter = psta->padapter;
294 
295 	pmlmepriv = &(padapter->mlmepriv);
296 
297 	if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
298 		add_RATid(padapter, psta, rssi_level);
299 	else {
300 		if (padapter->HalFunc.UpdateRAMaskHandler)
301 			padapter->HalFunc.UpdateRAMaskHandler(padapter, psta->mac_id, rssi_level);
302 	}
303 }
304 
rtw_hal_add_ra_tid(struct adapter * padapter,u32 bitmap,u8 * arg,u8 rssi_level)305 void rtw_hal_add_ra_tid(struct adapter *padapter, u32 bitmap, u8 *arg, u8 rssi_level)
306 {
307 	if (padapter->HalFunc.Add_RateATid)
308 		padapter->HalFunc.Add_RateATid(padapter, bitmap, arg, rssi_level);
309 }
310 
311 /*Start specifical interface thread		*/
rtw_hal_start_thread(struct adapter * padapter)312 void rtw_hal_start_thread(struct adapter *padapter)
313 {
314 	if (padapter->HalFunc.run_thread)
315 		padapter->HalFunc.run_thread(padapter);
316 }
317 /*Start specifical interface thread		*/
rtw_hal_stop_thread(struct adapter * padapter)318 void rtw_hal_stop_thread(struct adapter *padapter)
319 {
320 	if (padapter->HalFunc.cancel_thread)
321 		padapter->HalFunc.cancel_thread(padapter);
322 }
323 
rtw_hal_read_bbreg(struct adapter * padapter,u32 RegAddr,u32 BitMask)324 u32 rtw_hal_read_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask)
325 {
326 	u32 data = 0;
327 	if (padapter->HalFunc.read_bbreg)
328 		 data = padapter->HalFunc.read_bbreg(padapter, RegAddr, BitMask);
329 	return data;
330 }
rtw_hal_write_bbreg(struct adapter * padapter,u32 RegAddr,u32 BitMask,u32 Data)331 void rtw_hal_write_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask, u32 Data)
332 {
333 	if (padapter->HalFunc.write_bbreg)
334 		padapter->HalFunc.write_bbreg(padapter, RegAddr, BitMask, Data);
335 }
336 
rtw_hal_read_rfreg(struct adapter * padapter,u32 eRFPath,u32 RegAddr,u32 BitMask)337 u32 rtw_hal_read_rfreg(struct adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask)
338 {
339 	u32 data = 0;
340 	if (padapter->HalFunc.read_rfreg)
341 		data = padapter->HalFunc.read_rfreg(padapter, eRFPath, RegAddr, BitMask);
342 	return data;
343 }
rtw_hal_write_rfreg(struct adapter * padapter,u32 eRFPath,u32 RegAddr,u32 BitMask,u32 Data)344 void rtw_hal_write_rfreg(struct adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
345 {
346 	if (padapter->HalFunc.write_rfreg)
347 		padapter->HalFunc.write_rfreg(padapter, eRFPath, RegAddr, BitMask, Data);
348 }
349 
rtw_hal_set_chan(struct adapter * padapter,u8 channel)350 void rtw_hal_set_chan(struct adapter *padapter, u8 channel)
351 {
352 	if (padapter->HalFunc.set_channel_handler)
353 		padapter->HalFunc.set_channel_handler(padapter, channel);
354 }
355 
rtw_hal_set_chnl_bw(struct adapter * padapter,u8 channel,enum CHANNEL_WIDTH Bandwidth,u8 Offset40,u8 Offset80)356 void rtw_hal_set_chnl_bw(struct adapter *padapter, u8 channel,
357 			 enum CHANNEL_WIDTH Bandwidth, u8 Offset40, u8 Offset80)
358 {
359 	if (padapter->HalFunc.set_chnl_bw_handler)
360 		padapter->HalFunc.set_chnl_bw_handler(padapter, channel,
361 						      Bandwidth, Offset40,
362 						      Offset80);
363 }
364 
rtw_hal_dm_watchdog(struct adapter * padapter)365 void rtw_hal_dm_watchdog(struct adapter *padapter)
366 {
367 	if (padapter->HalFunc.hal_dm_watchdog)
368 		padapter->HalFunc.hal_dm_watchdog(padapter);
369 
370 }
371 
rtw_hal_dm_watchdog_in_lps(struct adapter * padapter)372 void rtw_hal_dm_watchdog_in_lps(struct adapter *padapter)
373 {
374 	if (adapter_to_pwrctl(padapter)->bFwCurrentInPSMode == true) {
375 		if (padapter->HalFunc.hal_dm_watchdog_in_lps)
376 			padapter->HalFunc.hal_dm_watchdog_in_lps(padapter); /* this fuction caller is in interrupt context */
377 	}
378 }
379 
rtw_hal_bcn_related_reg_setting(struct adapter * padapter)380 void rtw_hal_bcn_related_reg_setting(struct adapter *padapter)
381 {
382 	if (padapter->HalFunc.SetBeaconRelatedRegistersHandler)
383 		padapter->HalFunc.SetBeaconRelatedRegistersHandler(padapter);
384 }
385 
386 
rtw_hal_xmit_thread_handler(struct adapter * padapter)387 s32 rtw_hal_xmit_thread_handler(struct adapter *padapter)
388 {
389 	if (padapter->HalFunc.xmit_thread_handler)
390 		return padapter->HalFunc.xmit_thread_handler(padapter);
391 	return _FAIL;
392 }
393 
rtw_hal_notch_filter(struct adapter * adapter,bool enable)394 void rtw_hal_notch_filter(struct adapter *adapter, bool enable)
395 {
396 	if (adapter->HalFunc.hal_notch_filter)
397 		adapter->HalFunc.hal_notch_filter(adapter, enable);
398 }
399 
rtw_hal_reset_security_engine(struct adapter * adapter)400 void rtw_hal_reset_security_engine(struct adapter *adapter)
401 {
402 	if (adapter->HalFunc.hal_reset_security_engine)
403 		adapter->HalFunc.hal_reset_security_engine(adapter);
404 }
405 
rtw_hal_c2h_valid(struct adapter * adapter,u8 * buf)406 bool rtw_hal_c2h_valid(struct adapter *adapter, u8 *buf)
407 {
408 	return c2h_evt_valid((struct c2h_evt_hdr_88xx *)buf);
409 }
410 
rtw_hal_c2h_evt_read(struct adapter * adapter,u8 * buf)411 s32 rtw_hal_c2h_evt_read(struct adapter *adapter, u8 *buf)
412 {
413 	return c2h_evt_read_88xx(adapter, buf);
414 }
415 
rtw_hal_c2h_handler(struct adapter * adapter,u8 * c2h_evt)416 s32 rtw_hal_c2h_handler(struct adapter *adapter, u8 *c2h_evt)
417 {
418 	s32 ret = _FAIL;
419 	if (adapter->HalFunc.c2h_handler)
420 		ret = adapter->HalFunc.c2h_handler(adapter, c2h_evt);
421 	return ret;
422 }
423 
rtw_hal_c2h_id_filter_ccx(struct adapter * adapter)424 c2h_id_filter rtw_hal_c2h_id_filter_ccx(struct adapter *adapter)
425 {
426 	return adapter->HalFunc.c2h_id_filter_ccx;
427 }
428 
rtw_hal_is_disable_sw_channel_plan(struct adapter * padapter)429 s32 rtw_hal_is_disable_sw_channel_plan(struct adapter *padapter)
430 {
431 	return GET_HAL_DATA(padapter)->bDisableSWChannelPlan;
432 }
433 
rtw_hal_macid_sleep(struct adapter * padapter,u32 macid)434 s32 rtw_hal_macid_sleep(struct adapter *padapter, u32 macid)
435 {
436 	u8 support;
437 
438 
439 	support = false;
440 	rtw_hal_get_def_var(padapter, HAL_DEF_MACID_SLEEP, &support);
441 	if (false == support)
442 		return _FAIL;
443 
444 	rtw_hal_set_hwreg(padapter, HW_VAR_MACID_SLEEP, (u8 *)&macid);
445 
446 	return _SUCCESS;
447 }
448 
rtw_hal_macid_wakeup(struct adapter * padapter,u32 macid)449 s32 rtw_hal_macid_wakeup(struct adapter *padapter, u32 macid)
450 {
451 	u8 support;
452 
453 
454 	support = false;
455 	rtw_hal_get_def_var(padapter, HAL_DEF_MACID_SLEEP, &support);
456 	if (false == support)
457 		return _FAIL;
458 
459 	rtw_hal_set_hwreg(padapter, HW_VAR_MACID_WAKEUP, (u8 *)&macid);
460 
461 	return _SUCCESS;
462 }
463 
rtw_hal_fill_h2c_cmd(struct adapter * padapter,u8 ElementID,u32 CmdLen,u8 * pCmdBuffer)464 s32 rtw_hal_fill_h2c_cmd(struct adapter *padapter, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer)
465 {
466 	s32 ret = _FAIL;
467 
468 	if (padapter->HalFunc.fill_h2c_cmd)
469 		ret = padapter->HalFunc.fill_h2c_cmd(padapter, ElementID, CmdLen, pCmdBuffer);
470 	else
471 		DBG_871X("%s:  func[fill_h2c_cmd] not defined!\n", __func__);
472 
473 	return ret;
474 }
475