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_set_def_var(struct adapter * padapter,enum hal_def_variable eVariable,void * pValue)118 u8 rtw_hal_set_def_var(struct adapter *padapter, enum hal_def_variable eVariable, void *pValue)
119 {
120 return SetHalDefVar8723BSDIO(padapter, eVariable, pValue);
121 }
122
rtw_hal_get_def_var(struct adapter * padapter,enum hal_def_variable eVariable,void * pValue)123 u8 rtw_hal_get_def_var(struct adapter *padapter, enum hal_def_variable eVariable, void *pValue)
124 {
125 return GetHalDefVar8723BSDIO(padapter, eVariable, pValue);
126 }
127
rtw_hal_set_odm_var(struct adapter * padapter,enum hal_odm_variable eVariable,void * pValue1,bool bSet)128 void rtw_hal_set_odm_var(struct adapter *padapter, enum hal_odm_variable eVariable, void *pValue1, bool bSet)
129 {
130 SetHalODMVar(padapter, eVariable, pValue1, bSet);
131 }
132
rtw_hal_enable_interrupt(struct adapter * padapter)133 void rtw_hal_enable_interrupt(struct adapter *padapter)
134 {
135 EnableInterrupt8723BSdio(padapter);
136 }
137
rtw_hal_disable_interrupt(struct adapter * padapter)138 void rtw_hal_disable_interrupt(struct adapter *padapter)
139 {
140 DisableInterrupt8723BSdio(padapter);
141 }
142
rtw_hal_check_ips_status(struct adapter * padapter)143 u8 rtw_hal_check_ips_status(struct adapter *padapter)
144 {
145 return CheckIPSStatus(padapter);
146 }
147
rtw_hal_xmitframe_enqueue(struct adapter * padapter,struct xmit_frame * pxmitframe)148 s32 rtw_hal_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe)
149 {
150 return rtl8723bs_hal_xmitframe_enqueue(padapter, pxmitframe);
151 }
152
rtw_hal_xmit(struct adapter * padapter,struct xmit_frame * pxmitframe)153 s32 rtw_hal_xmit(struct adapter *padapter, struct xmit_frame *pxmitframe)
154 {
155 return rtl8723bs_hal_xmit(padapter, pxmitframe);
156 }
157
158 /*
159 * [IMPORTANT] This function would be run in interrupt context.
160 */
rtw_hal_mgnt_xmit(struct adapter * padapter,struct xmit_frame * pmgntframe)161 s32 rtw_hal_mgnt_xmit(struct adapter *padapter, struct xmit_frame *pmgntframe)
162 {
163 update_mgntframe_attrib_addr(padapter, pmgntframe);
164 /* pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; */
165 /* pwlanhdr = (struct rtw_ieee80211_hdr *)pframe; */
166 /* memcpy(pmgntframe->attrib.ra, pwlanhdr->addr1, ETH_ALEN); */
167
168 if (padapter->securitypriv.binstallBIPkey == true) {
169 if (is_multicast_ether_addr(pmgntframe->attrib.ra)) {
170 pmgntframe->attrib.encrypt = _BIP_;
171 /* pmgntframe->attrib.bswenc = true; */
172 } else {
173 pmgntframe->attrib.encrypt = _AES_;
174 pmgntframe->attrib.bswenc = true;
175 }
176 rtw_mgmt_xmitframe_coalesce(padapter, pmgntframe->pkt, pmgntframe);
177 }
178
179 return rtl8723bs_mgnt_xmit(padapter, pmgntframe);
180 }
181
rtw_hal_init_xmit_priv(struct adapter * padapter)182 s32 rtw_hal_init_xmit_priv(struct adapter *padapter)
183 {
184 return rtl8723bs_init_xmit_priv(padapter);
185 }
186
rtw_hal_free_xmit_priv(struct adapter * padapter)187 void rtw_hal_free_xmit_priv(struct adapter *padapter)
188 {
189 rtl8723bs_free_xmit_priv(padapter);
190 }
191
rtw_hal_init_recv_priv(struct adapter * padapter)192 s32 rtw_hal_init_recv_priv(struct adapter *padapter)
193 {
194 return rtl8723bs_init_recv_priv(padapter);
195 }
196
rtw_hal_free_recv_priv(struct adapter * padapter)197 void rtw_hal_free_recv_priv(struct adapter *padapter)
198 {
199 rtl8723bs_free_recv_priv(padapter);
200 }
201
rtw_hal_update_ra_mask(struct sta_info * psta,u8 rssi_level)202 void rtw_hal_update_ra_mask(struct sta_info *psta, u8 rssi_level)
203 {
204 struct adapter *padapter;
205 struct mlme_priv *pmlmepriv;
206
207 if (!psta)
208 return;
209
210 padapter = psta->padapter;
211
212 pmlmepriv = &(padapter->mlmepriv);
213
214 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
215 add_RATid(padapter, psta, rssi_level);
216 else {
217 UpdateHalRAMask8723B(padapter, psta->mac_id, rssi_level);
218 }
219 }
220
rtw_hal_add_ra_tid(struct adapter * padapter,u32 bitmap,u8 * arg,u8 rssi_level)221 void rtw_hal_add_ra_tid(struct adapter *padapter, u32 bitmap, u8 *arg, u8 rssi_level)
222 {
223 rtl8723b_Add_RateATid(padapter, bitmap, arg, rssi_level);
224 }
225
226 /*Start specifical interface thread */
rtw_hal_start_thread(struct adapter * padapter)227 void rtw_hal_start_thread(struct adapter *padapter)
228 {
229 rtl8723b_start_thread(padapter);
230 }
231 /*Start specifical interface thread */
rtw_hal_stop_thread(struct adapter * padapter)232 void rtw_hal_stop_thread(struct adapter *padapter)
233 {
234 rtl8723b_stop_thread(padapter);
235 }
236
rtw_hal_read_bbreg(struct adapter * padapter,u32 RegAddr,u32 BitMask)237 u32 rtw_hal_read_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask)
238 {
239 return PHY_QueryBBReg_8723B(padapter, RegAddr, BitMask);
240 }
rtw_hal_write_bbreg(struct adapter * padapter,u32 RegAddr,u32 BitMask,u32 Data)241 void rtw_hal_write_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask, u32 Data)
242 {
243 PHY_SetBBReg_8723B(padapter, RegAddr, BitMask, Data);
244 }
245
rtw_hal_read_rfreg(struct adapter * padapter,u32 eRFPath,u32 RegAddr,u32 BitMask)246 u32 rtw_hal_read_rfreg(struct adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask)
247 {
248 return PHY_QueryRFReg_8723B(padapter, eRFPath, RegAddr, BitMask);
249 }
rtw_hal_write_rfreg(struct adapter * padapter,u32 eRFPath,u32 RegAddr,u32 BitMask,u32 Data)250 void rtw_hal_write_rfreg(struct adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
251 {
252 PHY_SetRFReg_8723B(padapter, eRFPath, RegAddr, BitMask, Data);
253 }
254
rtw_hal_set_chan(struct adapter * padapter,u8 channel)255 void rtw_hal_set_chan(struct adapter *padapter, u8 channel)
256 {
257 PHY_SwChnl8723B(padapter, channel);
258 }
259
rtw_hal_set_chnl_bw(struct adapter * padapter,u8 channel,enum channel_width Bandwidth,u8 Offset40,u8 Offset80)260 void rtw_hal_set_chnl_bw(struct adapter *padapter, u8 channel,
261 enum channel_width Bandwidth, u8 Offset40, u8 Offset80)
262 {
263 PHY_SetSwChnlBWMode8723B(padapter, channel, Bandwidth, Offset40, Offset80);
264 }
265
rtw_hal_dm_watchdog(struct adapter * padapter)266 void rtw_hal_dm_watchdog(struct adapter *padapter)
267 {
268 rtl8723b_HalDmWatchDog(padapter);
269 }
270
rtw_hal_dm_watchdog_in_lps(struct adapter * padapter)271 void rtw_hal_dm_watchdog_in_lps(struct adapter *padapter)
272 {
273 if (adapter_to_pwrctl(padapter)->fw_current_in_ps_mode) {
274 rtl8723b_HalDmWatchDog_in_LPS(padapter); /* this function caller is in interrupt context */
275 }
276 }
277
beacon_timing_control(struct adapter * padapter)278 void beacon_timing_control(struct adapter *padapter)
279 {
280 rtl8723b_SetBeaconRelatedRegisters(padapter);
281 }
282
283
rtw_hal_xmit_thread_handler(struct adapter * padapter)284 s32 rtw_hal_xmit_thread_handler(struct adapter *padapter)
285 {
286 return rtl8723bs_xmit_buf_handler(padapter);
287 }
288
rtw_hal_notch_filter(struct adapter * adapter,bool enable)289 void rtw_hal_notch_filter(struct adapter *adapter, bool enable)
290 {
291 hal_notch_filter_8723b(adapter, enable);
292 }
293
rtw_hal_c2h_valid(struct adapter * adapter,u8 * buf)294 bool rtw_hal_c2h_valid(struct adapter *adapter, u8 *buf)
295 {
296 return c2h_evt_valid((struct c2h_evt_hdr_88xx *)buf);
297 }
298
rtw_hal_c2h_handler(struct adapter * adapter,u8 * c2h_evt)299 s32 rtw_hal_c2h_handler(struct adapter *adapter, u8 *c2h_evt)
300 {
301 return c2h_handler_8723b(adapter, c2h_evt);
302 }
303
rtw_hal_c2h_id_filter_ccx(struct adapter * adapter)304 c2h_id_filter rtw_hal_c2h_id_filter_ccx(struct adapter *adapter)
305 {
306 return c2h_id_filter_ccx_8723b;
307 }
308
rtw_hal_macid_sleep(struct adapter * padapter,u32 macid)309 s32 rtw_hal_macid_sleep(struct adapter *padapter, u32 macid)
310 {
311 u8 support;
312
313 support = false;
314 rtw_hal_get_def_var(padapter, HAL_DEF_MACID_SLEEP, &support);
315 if (false == support)
316 return _FAIL;
317
318 rtw_hal_set_hwreg(padapter, HW_VAR_MACID_SLEEP, (u8 *)&macid);
319
320 return _SUCCESS;
321 }
322
rtw_hal_macid_wakeup(struct adapter * padapter,u32 macid)323 s32 rtw_hal_macid_wakeup(struct adapter *padapter, u32 macid)
324 {
325 u8 support;
326
327 support = false;
328 rtw_hal_get_def_var(padapter, HAL_DEF_MACID_SLEEP, &support);
329 if (false == support)
330 return _FAIL;
331
332 rtw_hal_set_hwreg(padapter, HW_VAR_MACID_WAKEUP, (u8 *)&macid);
333
334 return _SUCCESS;
335 }
336
rtw_hal_fill_h2c_cmd(struct adapter * padapter,u8 ElementID,u32 CmdLen,u8 * pCmdBuffer)337 s32 rtw_hal_fill_h2c_cmd(struct adapter *padapter, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer)
338 {
339 return FillH2CCmd8723B(padapter, ElementID, CmdLen, pCmdBuffer);
340 }
341