1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3 *
4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7 #include <drv_types.h>
8 #include <hal_data.h>
9
rtw_hal_chip_configure(struct adapter * padapter)10 void rtw_hal_chip_configure(struct adapter *padapter)
11 {
12 rtl8723bs_interface_configure(padapter);
13 }
14
rtw_hal_read_chip_info(struct adapter * padapter)15 void rtw_hal_read_chip_info(struct adapter *padapter)
16 {
17 ReadAdapterInfo8723BS(padapter);
18 }
19
rtw_hal_read_chip_version(struct adapter * padapter)20 void rtw_hal_read_chip_version(struct adapter *padapter)
21 {
22 rtl8723b_read_chip_version(padapter);
23 }
24
rtw_hal_def_value_init(struct adapter * padapter)25 void rtw_hal_def_value_init(struct adapter *padapter)
26 {
27 rtl8723bs_init_default_value(padapter);
28 }
29
rtw_hal_free_data(struct adapter * padapter)30 void rtw_hal_free_data(struct adapter *padapter)
31 {
32 /* free HAL Data */
33 rtw_hal_data_deinit(padapter);
34 }
35
rtw_hal_dm_init(struct adapter * padapter)36 void rtw_hal_dm_init(struct adapter *padapter)
37 {
38 rtl8723b_init_dm_priv(padapter);
39 }
40
rtw_hal_init_opmode(struct adapter * padapter)41 static void rtw_hal_init_opmode(struct adapter *padapter)
42 {
43 enum ndis_802_11_network_infrastructure networkType = Ndis802_11InfrastructureMax;
44 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
45 signed int fw_state;
46
47 fw_state = get_fwstate(pmlmepriv);
48
49 if (fw_state & WIFI_ADHOC_STATE)
50 networkType = Ndis802_11IBSS;
51 else if (fw_state & WIFI_STATION_STATE)
52 networkType = Ndis802_11Infrastructure;
53 else if (fw_state & WIFI_AP_STATE)
54 networkType = Ndis802_11APMode;
55 else
56 return;
57
58 rtw_setopmode_cmd(padapter, networkType, false);
59 }
60
rtw_hal_init(struct adapter * padapter)61 uint rtw_hal_init(struct adapter *padapter)
62 {
63 uint status;
64 struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
65
66 status = rtl8723bs_hal_init(padapter);
67
68 if (status == _SUCCESS) {
69 rtw_hal_init_opmode(padapter);
70
71 dvobj->padapters->hw_init_completed = true;
72
73 if (padapter->registrypriv.notch_filter == 1)
74 rtw_hal_notch_filter(padapter, 1);
75
76 rtw_sec_restore_wep_key(dvobj->padapters);
77
78 init_hw_mlme_ext(padapter);
79
80 rtw_bb_rf_gain_offset(padapter);
81 } else {
82 dvobj->padapters->hw_init_completed = false;
83 }
84
85 return status;
86 }
87
rtw_hal_deinit(struct adapter * padapter)88 uint rtw_hal_deinit(struct adapter *padapter)
89 {
90 uint status = _SUCCESS;
91 struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
92
93 status = rtl8723bs_hal_deinit(padapter);
94
95 if (status == _SUCCESS) {
96 padapter = dvobj->padapters;
97 padapter->hw_init_completed = false;
98 }
99
100 return status;
101 }
102
rtw_hal_set_hwreg(struct adapter * padapter,u8 variable,u8 * val)103 void rtw_hal_set_hwreg(struct adapter *padapter, u8 variable, u8 *val)
104 {
105 SetHwReg8723BS(padapter, variable, val);
106 }
107
rtw_hal_get_hwreg(struct adapter * padapter,u8 variable,u8 * val)108 void rtw_hal_get_hwreg(struct adapter *padapter, u8 variable, u8 *val)
109 {
110 GetHwReg8723BS(padapter, variable, val);
111 }
112
rtw_hal_set_hwreg_with_buf(struct adapter * padapter,u8 variable,u8 * pbuf,int len)113 void rtw_hal_set_hwreg_with_buf(struct adapter *padapter, u8 variable, u8 *pbuf, int len)
114 {
115 SetHwRegWithBuf8723B(padapter, variable, pbuf, len);
116 }
117
rtw_hal_get_def_var(struct adapter * padapter,enum hal_def_variable eVariable,void * pValue)118 u8 rtw_hal_get_def_var(struct adapter *padapter, enum hal_def_variable eVariable, void *pValue)
119 {
120 return GetHalDefVar8723BSDIO(padapter, eVariable, pValue);
121 }
122
rtw_hal_set_odm_var(struct adapter * padapter,enum hal_odm_variable eVariable,void * pValue1,bool bSet)123 void rtw_hal_set_odm_var(struct adapter *padapter, enum hal_odm_variable eVariable, void *pValue1, bool bSet)
124 {
125 SetHalODMVar(padapter, eVariable, pValue1, bSet);
126 }
127
rtw_hal_enable_interrupt(struct adapter * padapter)128 void rtw_hal_enable_interrupt(struct adapter *padapter)
129 {
130 EnableInterrupt8723BSdio(padapter);
131 }
132
rtw_hal_disable_interrupt(struct adapter * padapter)133 void rtw_hal_disable_interrupt(struct adapter *padapter)
134 {
135 DisableInterrupt8723BSdio(padapter);
136 }
137
rtw_hal_check_ips_status(struct adapter * padapter)138 u8 rtw_hal_check_ips_status(struct adapter *padapter)
139 {
140 return CheckIPSStatus(padapter);
141 }
142
rtw_hal_xmitframe_enqueue(struct adapter * padapter,struct xmit_frame * pxmitframe)143 s32 rtw_hal_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe)
144 {
145 return rtl8723bs_hal_xmitframe_enqueue(padapter, pxmitframe);
146 }
147
rtw_hal_xmit(struct adapter * padapter,struct xmit_frame * pxmitframe)148 s32 rtw_hal_xmit(struct adapter *padapter, struct xmit_frame *pxmitframe)
149 {
150 return rtl8723bs_hal_xmit(padapter, pxmitframe);
151 }
152
153 /*
154 * [IMPORTANT] This function would be run in interrupt context.
155 */
rtw_hal_mgnt_xmit(struct adapter * padapter,struct xmit_frame * pmgntframe)156 s32 rtw_hal_mgnt_xmit(struct adapter *padapter, struct xmit_frame *pmgntframe)
157 {
158 update_mgntframe_attrib_addr(padapter, pmgntframe);
159 /* pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; */
160 /* pwlanhdr = (struct rtw_ieee80211_hdr *)pframe; */
161 /* memcpy(pmgntframe->attrib.ra, pwlanhdr->addr1, ETH_ALEN); */
162
163 if (padapter->securitypriv.binstallBIPkey == true) {
164 if (is_multicast_ether_addr(pmgntframe->attrib.ra)) {
165 pmgntframe->attrib.encrypt = _BIP_;
166 /* pmgntframe->attrib.bswenc = true; */
167 } else {
168 pmgntframe->attrib.encrypt = _AES_;
169 pmgntframe->attrib.bswenc = true;
170 }
171 rtw_mgmt_xmitframe_coalesce(padapter, pmgntframe->pkt, pmgntframe);
172 }
173
174 return rtl8723bs_mgnt_xmit(padapter, pmgntframe);
175 }
176
rtw_hal_init_xmit_priv(struct adapter * padapter)177 s32 rtw_hal_init_xmit_priv(struct adapter *padapter)
178 {
179 return rtl8723bs_init_xmit_priv(padapter);
180 }
181
rtw_hal_free_xmit_priv(struct adapter * padapter)182 void rtw_hal_free_xmit_priv(struct adapter *padapter)
183 {
184 rtl8723bs_free_xmit_priv(padapter);
185 }
186
rtw_hal_init_recv_priv(struct adapter * padapter)187 s32 rtw_hal_init_recv_priv(struct adapter *padapter)
188 {
189 return rtl8723bs_init_recv_priv(padapter);
190 }
191
rtw_hal_free_recv_priv(struct adapter * padapter)192 void rtw_hal_free_recv_priv(struct adapter *padapter)
193 {
194 rtl8723bs_free_recv_priv(padapter);
195 }
196
rtw_hal_update_ra_mask(struct sta_info * psta,u8 rssi_level)197 void rtw_hal_update_ra_mask(struct sta_info *psta, u8 rssi_level)
198 {
199 struct adapter *padapter;
200 struct mlme_priv *pmlmepriv;
201
202 if (!psta)
203 return;
204
205 padapter = psta->padapter;
206
207 pmlmepriv = &(padapter->mlmepriv);
208
209 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
210 add_RATid(padapter, psta, rssi_level);
211 else {
212 UpdateHalRAMask8723B(padapter, psta->mac_id, rssi_level);
213 }
214 }
215
rtw_hal_add_ra_tid(struct adapter * padapter,u32 bitmap,u8 * arg,u8 rssi_level)216 void rtw_hal_add_ra_tid(struct adapter *padapter, u32 bitmap, u8 *arg, u8 rssi_level)
217 {
218 rtl8723b_Add_RateATid(padapter, bitmap, arg, rssi_level);
219 }
220
221 /*Start specifical interface thread */
rtw_hal_start_thread(struct adapter * padapter)222 void rtw_hal_start_thread(struct adapter *padapter)
223 {
224 rtl8723b_start_thread(padapter);
225 }
226 /*Start specifical interface thread */
rtw_hal_stop_thread(struct adapter * padapter)227 void rtw_hal_stop_thread(struct adapter *padapter)
228 {
229 rtl8723b_stop_thread(padapter);
230 }
231
rtw_hal_read_bbreg(struct adapter * padapter,u32 RegAddr,u32 BitMask)232 u32 rtw_hal_read_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask)
233 {
234 return PHY_QueryBBReg_8723B(padapter, RegAddr, BitMask);
235 }
rtw_hal_write_bbreg(struct adapter * padapter,u32 RegAddr,u32 BitMask,u32 Data)236 void rtw_hal_write_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask, u32 Data)
237 {
238 PHY_SetBBReg_8723B(padapter, RegAddr, BitMask, Data);
239 }
240
rtw_hal_read_rfreg(struct adapter * padapter,u32 eRFPath,u32 RegAddr,u32 BitMask)241 u32 rtw_hal_read_rfreg(struct adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask)
242 {
243 return PHY_QueryRFReg_8723B(padapter, eRFPath, RegAddr, BitMask);
244 }
rtw_hal_write_rfreg(struct adapter * padapter,u32 eRFPath,u32 RegAddr,u32 BitMask,u32 Data)245 void rtw_hal_write_rfreg(struct adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
246 {
247 PHY_SetRFReg_8723B(padapter, eRFPath, RegAddr, BitMask, Data);
248 }
249
rtw_hal_set_chan(struct adapter * padapter,u8 channel)250 void rtw_hal_set_chan(struct adapter *padapter, u8 channel)
251 {
252 PHY_SwChnl8723B(padapter, channel);
253 }
254
rtw_hal_set_chnl_bw(struct adapter * padapter,u8 channel,enum channel_width Bandwidth,u8 Offset40,u8 Offset80)255 void rtw_hal_set_chnl_bw(struct adapter *padapter, u8 channel,
256 enum channel_width Bandwidth, u8 Offset40, u8 Offset80)
257 {
258 PHY_SetSwChnlBWMode8723B(padapter, channel, Bandwidth, Offset40, Offset80);
259 }
260
rtw_hal_dm_watchdog(struct adapter * padapter)261 void rtw_hal_dm_watchdog(struct adapter *padapter)
262 {
263 rtl8723b_HalDmWatchDog(padapter);
264 }
265
rtw_hal_dm_watchdog_in_lps(struct adapter * padapter)266 void rtw_hal_dm_watchdog_in_lps(struct adapter *padapter)
267 {
268 if (adapter_to_pwrctl(padapter)->fw_current_in_ps_mode) {
269 rtl8723b_HalDmWatchDog_in_LPS(padapter); /* this function caller is in interrupt context */
270 }
271 }
272
beacon_timing_control(struct adapter * padapter)273 void beacon_timing_control(struct adapter *padapter)
274 {
275 rtl8723b_SetBeaconRelatedRegisters(padapter);
276 }
277
278
rtw_hal_xmit_thread_handler(struct adapter * padapter)279 s32 rtw_hal_xmit_thread_handler(struct adapter *padapter)
280 {
281 return rtl8723bs_xmit_buf_handler(padapter);
282 }
283
rtw_hal_notch_filter(struct adapter * adapter,bool enable)284 void rtw_hal_notch_filter(struct adapter *adapter, bool enable)
285 {
286 hal_notch_filter_8723b(adapter, enable);
287 }
288
rtw_hal_c2h_valid(struct adapter * adapter,u8 * buf)289 bool rtw_hal_c2h_valid(struct adapter *adapter, u8 *buf)
290 {
291 return c2h_evt_valid((struct c2h_evt_hdr_88xx *)buf);
292 }
293
rtw_hal_c2h_handler(struct adapter * adapter,u8 * c2h_evt)294 s32 rtw_hal_c2h_handler(struct adapter *adapter, u8 *c2h_evt)
295 {
296 return c2h_handler_8723b(adapter, c2h_evt);
297 }
298
rtw_hal_c2h_id_filter_ccx(struct adapter * adapter)299 c2h_id_filter rtw_hal_c2h_id_filter_ccx(struct adapter *adapter)
300 {
301 return c2h_id_filter_ccx_8723b;
302 }
303
rtw_hal_macid_sleep(struct adapter * padapter,u32 macid)304 s32 rtw_hal_macid_sleep(struct adapter *padapter, u32 macid)
305 {
306 u8 support;
307
308 support = false;
309 rtw_hal_get_def_var(padapter, HAL_DEF_MACID_SLEEP, &support);
310 if (false == support)
311 return _FAIL;
312
313 rtw_hal_set_hwreg(padapter, HW_VAR_MACID_SLEEP, (u8 *)&macid);
314
315 return _SUCCESS;
316 }
317
rtw_hal_macid_wakeup(struct adapter * padapter,u32 macid)318 s32 rtw_hal_macid_wakeup(struct adapter *padapter, u32 macid)
319 {
320 u8 support;
321
322 support = false;
323 rtw_hal_get_def_var(padapter, HAL_DEF_MACID_SLEEP, &support);
324 if (false == support)
325 return _FAIL;
326
327 rtw_hal_set_hwreg(padapter, HW_VAR_MACID_WAKEUP, (u8 *)&macid);
328
329 return _SUCCESS;
330 }
331
rtw_hal_fill_h2c_cmd(struct adapter * padapter,u8 ElementID,u32 CmdLen,u8 * pCmdBuffer)332 s32 rtw_hal_fill_h2c_cmd(struct adapter *padapter, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer)
333 {
334 return FillH2CCmd8723B(padapter, ElementID, CmdLen, pCmdBuffer);
335 }
336