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