• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2012 Realtek Corporation. */
3 
4 #define _HAL_INTF_C_
5 #include "../include/osdep_service.h"
6 #include "../include/drv_types.h"
7 #include "../include/hal_intf.h"
8 
rtw_hal_chip_configure(struct adapter * adapt)9 void rtw_hal_chip_configure(struct adapter *adapt)
10 {
11 	if (adapt->HalFunc.intf_chip_configure)
12 		adapt->HalFunc.intf_chip_configure(adapt);
13 }
14 
rtw_hal_read_chip_info(struct adapter * adapt)15 void rtw_hal_read_chip_info(struct adapter *adapt)
16 {
17 	if (adapt->HalFunc.read_adapter_info)
18 		adapt->HalFunc.read_adapter_info(adapt);
19 }
20 
rtw_hal_read_chip_version(struct adapter * adapt)21 void rtw_hal_read_chip_version(struct adapter *adapt)
22 {
23 	if (adapt->HalFunc.read_chip_version)
24 		adapt->HalFunc.read_chip_version(adapt);
25 }
26 
rtw_hal_def_value_init(struct adapter * adapt)27 void rtw_hal_def_value_init(struct adapter *adapt)
28 {
29 	if (adapt->HalFunc.init_default_value)
30 		adapt->HalFunc.init_default_value(adapt);
31 }
32 
rtw_hal_free_data(struct adapter * adapt)33 void rtw_hal_free_data(struct adapter *adapt)
34 {
35 	if (adapt->HalFunc.free_hal_data)
36 		adapt->HalFunc.free_hal_data(adapt);
37 }
38 
rtw_hal_dm_init(struct adapter * adapt)39 void rtw_hal_dm_init(struct adapter *adapt)
40 {
41 	if (adapt->HalFunc.dm_init)
42 		adapt->HalFunc.dm_init(adapt);
43 }
44 
rtw_hal_dm_deinit(struct adapter * adapt)45 void rtw_hal_dm_deinit(struct adapter *adapt)
46 {
47 	/*  cancel dm  timer */
48 	if (adapt->HalFunc.dm_deinit)
49 		adapt->HalFunc.dm_deinit(adapt);
50 }
51 
rtw_hal_sw_led_init(struct adapter * adapt)52 void rtw_hal_sw_led_init(struct adapter *adapt)
53 {
54 	if (adapt->HalFunc.InitSwLeds)
55 		adapt->HalFunc.InitSwLeds(adapt);
56 }
57 
rtw_hal_sw_led_deinit(struct adapter * adapt)58 void rtw_hal_sw_led_deinit(struct adapter *adapt)
59 {
60 	if (adapt->HalFunc.DeInitSwLeds)
61 		adapt->HalFunc.DeInitSwLeds(adapt);
62 }
63 
rtw_hal_power_on(struct adapter * adapt)64 u32 rtw_hal_power_on(struct adapter *adapt)
65 {
66 	if (adapt->HalFunc.hal_power_on)
67 		return adapt->HalFunc.hal_power_on(adapt);
68 	return _FAIL;
69 }
70 
rtw_hal_init(struct adapter * adapt)71 uint	 rtw_hal_init(struct adapter *adapt)
72 {
73 	uint	status = _SUCCESS;
74 
75 	adapt->hw_init_completed = false;
76 
77 	status = adapt->HalFunc.hal_init(adapt);
78 
79 	if (status == _SUCCESS) {
80 		adapt->hw_init_completed = true;
81 
82 		if (adapt->registrypriv.notch_filter == 1)
83 			rtw_hal_notch_filter(adapt, 1);
84 
85 		rtw_hal_reset_security_engine(adapt);
86 	} else {
87 		adapt->hw_init_completed = false;
88 		DBG_88E("rtw_hal_init: hal__init fail\n");
89 	}
90 
91 	return status;
92 }
93 
rtw_hal_deinit(struct adapter * adapt)94 uint rtw_hal_deinit(struct adapter *adapt)
95 {
96 	uint	status = _SUCCESS;
97 
98 	status = adapt->HalFunc.hal_deinit(adapt);
99 
100 	if (status == _SUCCESS)
101 		adapt->hw_init_completed = false;
102 	else
103 		DBG_88E("\n rtw_hal_deinit: hal_init fail\n");
104 
105 	return status;
106 }
107 
rtw_hal_set_hwreg(struct adapter * adapt,u8 variable,u8 * val)108 void rtw_hal_set_hwreg(struct adapter *adapt, u8 variable, u8 *val)
109 {
110 	if (adapt->HalFunc.SetHwRegHandler)
111 		adapt->HalFunc.SetHwRegHandler(adapt, variable, val);
112 }
113 
rtw_hal_get_hwreg(struct adapter * adapt,u8 variable,u8 * val)114 void rtw_hal_get_hwreg(struct adapter *adapt, u8 variable, u8 *val)
115 {
116 	if (adapt->HalFunc.GetHwRegHandler)
117 		adapt->HalFunc.GetHwRegHandler(adapt, variable, val);
118 }
119 
rtw_hal_set_def_var(struct adapter * adapt,enum hal_def_variable var,void * val)120 u8 rtw_hal_set_def_var(struct adapter *adapt, enum hal_def_variable var,
121 		      void *val)
122 {
123 	if (adapt->HalFunc.SetHalDefVarHandler)
124 		return adapt->HalFunc.SetHalDefVarHandler(adapt, var, val);
125 	return _FAIL;
126 }
127 
rtw_hal_get_def_var(struct adapter * adapt,enum hal_def_variable var,void * val)128 u8 rtw_hal_get_def_var(struct adapter *adapt,
129 		       enum hal_def_variable var, void *val)
130 {
131 	if (adapt->HalFunc.GetHalDefVarHandler)
132 		return adapt->HalFunc.GetHalDefVarHandler(adapt, var, val);
133 	return _FAIL;
134 }
135 
rtw_hal_set_odm_var(struct adapter * adapt,enum hal_odm_variable var,void * val1,bool set)136 void rtw_hal_set_odm_var(struct adapter *adapt,
137 			 enum hal_odm_variable var, void *val1,
138 			 bool set)
139 {
140 	if (adapt->HalFunc.SetHalODMVarHandler)
141 		adapt->HalFunc.SetHalODMVarHandler(adapt, var,
142 						      val1, set);
143 }
144 
rtw_hal_get_odm_var(struct adapter * adapt,enum hal_odm_variable var,void * val1,bool set)145 void rtw_hal_get_odm_var(struct adapter *adapt,
146 			 enum hal_odm_variable var, void *val1,
147 			 bool set)
148 {
149 	if (adapt->HalFunc.GetHalODMVarHandler)
150 		adapt->HalFunc.GetHalODMVarHandler(adapt, var,
151 						      val1, set);
152 }
153 
rtw_hal_enable_interrupt(struct adapter * adapt)154 void rtw_hal_enable_interrupt(struct adapter *adapt)
155 {
156 	if (adapt->HalFunc.enable_interrupt)
157 		adapt->HalFunc.enable_interrupt(adapt);
158 	else
159 		DBG_88E("%s: HalFunc.enable_interrupt is NULL!\n", __func__);
160 }
161 
rtw_hal_disable_interrupt(struct adapter * adapt)162 void rtw_hal_disable_interrupt(struct adapter *adapt)
163 {
164 	if (adapt->HalFunc.disable_interrupt)
165 		adapt->HalFunc.disable_interrupt(adapt);
166 	else
167 		DBG_88E("%s: HalFunc.disable_interrupt is NULL!\n", __func__);
168 }
169 
rtw_hal_inirp_init(struct adapter * adapt)170 u32 rtw_hal_inirp_init(struct adapter *adapt)
171 {
172 	u32 rst = _FAIL;
173 
174 	if (adapt->HalFunc.inirp_init)
175 		rst = adapt->HalFunc.inirp_init(adapt);
176 	else
177 		DBG_88E(" %s HalFunc.inirp_init is NULL!!!\n", __func__);
178 	return rst;
179 }
180 
rtw_hal_inirp_deinit(struct adapter * adapt)181 u32 rtw_hal_inirp_deinit(struct adapter *adapt)
182 {
183 	if (adapt->HalFunc.inirp_deinit)
184 		return adapt->HalFunc.inirp_deinit(adapt);
185 
186 	return _FAIL;
187 }
188 
rtw_hal_intf_ps_func(struct adapter * adapt,enum hal_intf_ps_func efunc_id,u8 * val)189 u8 rtw_hal_intf_ps_func(struct adapter *adapt,
190 			enum hal_intf_ps_func efunc_id, u8 *val)
191 {
192 	if (adapt->HalFunc.interface_ps_func)
193 		return adapt->HalFunc.interface_ps_func(adapt, efunc_id,
194 							   val);
195 	return _FAIL;
196 }
197 
rtw_hal_xmitframe_enqueue(struct adapter * padapter,struct xmit_frame * pxmitframe)198 s32 rtw_hal_xmitframe_enqueue(struct adapter *padapter,
199 			      struct xmit_frame *pxmitframe)
200 {
201 	if (padapter->HalFunc.hal_xmitframe_enqueue)
202 		return padapter->HalFunc.hal_xmitframe_enqueue(padapter, pxmitframe);
203 	return false;
204 }
205 
rtw_hal_xmit(struct adapter * adapt,struct xmit_frame * pxmitframe)206 s32 rtw_hal_xmit(struct adapter *adapt, struct xmit_frame *pxmitframe)
207 {
208 	if (adapt->HalFunc.hal_xmit)
209 		return adapt->HalFunc.hal_xmit(adapt, pxmitframe);
210 
211 	return false;
212 }
213 
rtw_hal_mgnt_xmit(struct adapter * adapt,struct xmit_frame * pmgntframe)214 s32 rtw_hal_mgnt_xmit(struct adapter *adapt, struct xmit_frame *pmgntframe)
215 {
216 	s32 ret = _FAIL;
217 	if (adapt->HalFunc.mgnt_xmit)
218 		ret = adapt->HalFunc.mgnt_xmit(adapt, pmgntframe);
219 	return ret;
220 }
221 
rtw_hal_init_xmit_priv(struct adapter * adapt)222 s32 rtw_hal_init_xmit_priv(struct adapter *adapt)
223 {
224 	if (adapt->HalFunc.init_xmit_priv)
225 		return adapt->HalFunc.init_xmit_priv(adapt);
226 	return _FAIL;
227 }
228 
rtw_hal_init_recv_priv(struct adapter * adapt)229 s32 rtw_hal_init_recv_priv(struct adapter *adapt)
230 {
231 	if (adapt->HalFunc.init_recv_priv)
232 		return adapt->HalFunc.init_recv_priv(adapt);
233 
234 	return _FAIL;
235 }
236 
rtw_hal_free_recv_priv(struct adapter * adapt)237 void rtw_hal_free_recv_priv(struct adapter *adapt)
238 {
239 	if (adapt->HalFunc.free_recv_priv)
240 		adapt->HalFunc.free_recv_priv(adapt);
241 }
242 
rtw_hal_update_ra_mask(struct adapter * adapt,u32 mac_id,u8 rssi_level)243 void rtw_hal_update_ra_mask(struct adapter *adapt, u32 mac_id, u8 rssi_level)
244 {
245 	struct mlme_priv *pmlmepriv = &adapt->mlmepriv;
246 
247 	if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
248 #ifdef CONFIG_88EU_AP_MODE
249 		struct sta_info *psta = NULL;
250 		struct sta_priv *pstapriv = &adapt->stapriv;
251 		if (mac_id >= 2)
252 			psta = pstapriv->sta_aid[(mac_id - 1) - 1];
253 		if (psta)
254 			add_RATid(adapt, psta, 0);/* todo: based on rssi_level*/
255 #endif
256 	} else {
257 		if (adapt->HalFunc.UpdateRAMaskHandler)
258 			adapt->HalFunc.UpdateRAMaskHandler(adapt, mac_id,
259 							      rssi_level);
260 	}
261 }
262 
rtw_hal_add_ra_tid(struct adapter * adapt,u32 bitmap,u8 arg,u8 rssi_level)263 void rtw_hal_add_ra_tid(struct adapter *adapt, u32 bitmap, u8 arg,
264 			u8 rssi_level)
265 {
266 	if (adapt->HalFunc.Add_RateATid)
267 		adapt->HalFunc.Add_RateATid(adapt, bitmap, arg,
268 					       rssi_level);
269 }
270 
271 /*	Start specifical interface thread		*/
rtw_hal_start_thread(struct adapter * adapt)272 void rtw_hal_start_thread(struct adapter *adapt)
273 {
274 	if (adapt->HalFunc.run_thread)
275 		adapt->HalFunc.run_thread(adapt);
276 }
277 
278 /*	Start specifical interface thread		*/
rtw_hal_stop_thread(struct adapter * adapt)279 void rtw_hal_stop_thread(struct adapter *adapt)
280 {
281 	if (adapt->HalFunc.cancel_thread)
282 		adapt->HalFunc.cancel_thread(adapt);
283 }
284 
rtw_hal_read_bbreg(struct adapter * adapt,u32 regaddr,u32 bitmask)285 u32 rtw_hal_read_bbreg(struct adapter *adapt, u32 regaddr, u32 bitmask)
286 {
287 	u32 data = 0;
288 
289 	if (adapt->HalFunc.read_bbreg)
290 		data = adapt->HalFunc.read_bbreg(adapt, regaddr, bitmask);
291 	return data;
292 }
293 
rtw_hal_write_bbreg(struct adapter * adapt,u32 regaddr,u32 bitmask,u32 data)294 void rtw_hal_write_bbreg(struct adapter *adapt, u32 regaddr, u32 bitmask,
295 			 u32 data)
296 {
297 	if (adapt->HalFunc.write_bbreg)
298 		adapt->HalFunc.write_bbreg(adapt, regaddr, bitmask, data);
299 }
300 
rtw_hal_read_rfreg(struct adapter * adapt,enum rf_radio_path rfpath,u32 regaddr,u32 bitmask)301 u32 rtw_hal_read_rfreg(struct adapter *adapt, enum rf_radio_path rfpath,
302 		       u32 regaddr, u32 bitmask)
303 {
304 	u32 data = 0;
305 
306 	if (adapt->HalFunc.read_rfreg)
307 		data = adapt->HalFunc.read_rfreg(adapt, rfpath, regaddr,
308 						    bitmask);
309 	return data;
310 }
311 
rtw_hal_write_rfreg(struct adapter * adapt,enum rf_radio_path rfpath,u32 regaddr,u32 bitmask,u32 data)312 void rtw_hal_write_rfreg(struct adapter *adapt, enum rf_radio_path rfpath,
313 			 u32 regaddr, u32 bitmask, u32 data)
314 {
315 	if (adapt->HalFunc.write_rfreg)
316 		adapt->HalFunc.write_rfreg(adapt, rfpath, regaddr,
317 					      bitmask, data);
318 }
319 
rtw_hal_interrupt_handler(struct adapter * adapt)320 s32 rtw_hal_interrupt_handler(struct adapter *adapt)
321 {
322 	if (adapt->HalFunc.interrupt_handler)
323 		return adapt->HalFunc.interrupt_handler(adapt);
324 	return _FAIL;
325 }
326 
rtw_hal_set_bwmode(struct adapter * adapt,enum ht_channel_width bandwidth,u8 offset)327 void rtw_hal_set_bwmode(struct adapter *adapt,
328 			enum ht_channel_width bandwidth, u8 offset)
329 {
330 	if (adapt->HalFunc.set_bwmode_handler)
331 		adapt->HalFunc.set_bwmode_handler(adapt, bandwidth,
332 						     offset);
333 }
334 
rtw_hal_set_chan(struct adapter * adapt,u8 channel)335 void rtw_hal_set_chan(struct adapter *adapt, u8 channel)
336 {
337 	if (adapt->HalFunc.set_channel_handler)
338 		adapt->HalFunc.set_channel_handler(adapt, channel);
339 }
340 
rtw_hal_dm_watchdog(struct adapter * adapt)341 void rtw_hal_dm_watchdog(struct adapter *adapt)
342 {
343 	if (adapt->HalFunc.hal_dm_watchdog)
344 		adapt->HalFunc.hal_dm_watchdog(adapt);
345 }
346 
rtw_hal_bcn_related_reg_setting(struct adapter * adapt)347 void rtw_hal_bcn_related_reg_setting(struct adapter *adapt)
348 {
349 	if (adapt->HalFunc.SetBeaconRelatedRegistersHandler)
350 		adapt->HalFunc.SetBeaconRelatedRegistersHandler(adapt);
351 }
352 
rtw_hal_antdiv_before_linked(struct adapter * adapt)353 u8 rtw_hal_antdiv_before_linked(struct adapter *adapt)
354 {
355 	if (adapt->HalFunc.AntDivBeforeLinkHandler)
356 		return adapt->HalFunc.AntDivBeforeLinkHandler(adapt);
357 	return false;
358 }
359 
rtw_hal_antdiv_rssi_compared(struct adapter * adapt,struct wlan_bssid_ex * dst,struct wlan_bssid_ex * src)360 void rtw_hal_antdiv_rssi_compared(struct adapter *adapt,
361 				  struct wlan_bssid_ex *dst,
362 				  struct wlan_bssid_ex *src)
363 {
364 	if (adapt->HalFunc.AntDivCompareHandler)
365 		adapt->HalFunc.AntDivCompareHandler(adapt, dst, src);
366 }
367 
rtw_hal_sreset_init(struct adapter * adapt)368 void rtw_hal_sreset_init(struct adapter *adapt)
369 {
370 	if (adapt->HalFunc.sreset_init_value)
371 		adapt->HalFunc.sreset_init_value(adapt);
372 }
373 
rtw_hal_sreset_reset(struct adapter * adapt)374 void rtw_hal_sreset_reset(struct adapter *adapt)
375 {
376 	if (adapt->HalFunc.silentreset)
377 		adapt->HalFunc.silentreset(adapt);
378 }
379 
rtw_hal_sreset_reset_value(struct adapter * adapt)380 void rtw_hal_sreset_reset_value(struct adapter *adapt)
381 {
382 	if (adapt->HalFunc.sreset_reset_value)
383 		adapt->HalFunc.sreset_reset_value(adapt);
384 }
385 
rtw_hal_sreset_xmit_status_check(struct adapter * adapt)386 void rtw_hal_sreset_xmit_status_check(struct adapter *adapt)
387 {
388 	if (adapt->HalFunc.sreset_xmit_status_check)
389 		adapt->HalFunc.sreset_xmit_status_check(adapt);
390 }
391 
rtw_hal_sreset_linked_status_check(struct adapter * adapt)392 void rtw_hal_sreset_linked_status_check(struct adapter *adapt)
393 {
394 	if (adapt->HalFunc.sreset_linked_status_check)
395 		adapt->HalFunc.sreset_linked_status_check(adapt);
396 }
397 
rtw_hal_sreset_get_wifi_status(struct adapter * adapt)398 u8   rtw_hal_sreset_get_wifi_status(struct adapter *adapt)
399 {
400 	u8 status = 0;
401 
402 	if (adapt->HalFunc.sreset_get_wifi_status)
403 		status = adapt->HalFunc.sreset_get_wifi_status(adapt);
404 	return status;
405 }
406 
rtw_hal_iol_cmd(struct adapter * adapter,struct xmit_frame * xmit_frame,u32 max_wating_ms,u32 bndy_cnt)407 int rtw_hal_iol_cmd(struct adapter  *adapter, struct xmit_frame *xmit_frame,
408 		    u32 max_wating_ms, u32 bndy_cnt)
409 {
410 	if (adapter->HalFunc.IOL_exec_cmds_sync)
411 		return adapter->HalFunc.IOL_exec_cmds_sync(adapter, xmit_frame,
412 							   max_wating_ms,
413 							   bndy_cnt);
414 	return _FAIL;
415 }
416 
rtw_hal_notch_filter(struct adapter * adapter,bool enable)417 void rtw_hal_notch_filter(struct adapter *adapter, bool enable)
418 {
419 	if (adapter->HalFunc.hal_notch_filter)
420 		adapter->HalFunc.hal_notch_filter(adapter, enable);
421 }
422 
rtw_hal_reset_security_engine(struct adapter * adapter)423 void rtw_hal_reset_security_engine(struct adapter *adapter)
424 {
425 	if (adapter->HalFunc.hal_reset_security_engine)
426 		adapter->HalFunc.hal_reset_security_engine(adapter);
427 }
428 
rtw_hal_c2h_handler(struct adapter * adapter,struct c2h_evt_hdr * c2h_evt)429 s32 rtw_hal_c2h_handler(struct adapter *adapter, struct c2h_evt_hdr *c2h_evt)
430 {
431 	s32 ret = _FAIL;
432 
433 	if (adapter->HalFunc.c2h_handler)
434 		ret = adapter->HalFunc.c2h_handler(adapter, c2h_evt);
435 	return ret;
436 }
437 
rtw_hal_c2h_id_filter_ccx(struct adapter * adapter)438 c2h_id_filter rtw_hal_c2h_id_filter_ccx(struct adapter *adapter)
439 {
440 	return adapter->HalFunc.c2h_id_filter_ccx;
441 }
442