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
rtw_hal_read_bbreg(struct adapter * padapter,u32 RegAddr,u32 BitMask)221 u32 rtw_hal_read_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask)
222 {
223 return PHY_QueryBBReg_8723B(padapter, RegAddr, BitMask);
224 }
rtw_hal_write_bbreg(struct adapter * padapter,u32 RegAddr,u32 BitMask,u32 Data)225 void rtw_hal_write_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask, u32 Data)
226 {
227 PHY_SetBBReg_8723B(padapter, RegAddr, BitMask, Data);
228 }
229
rtw_hal_read_rfreg(struct adapter * padapter,u32 eRFPath,u32 RegAddr,u32 BitMask)230 u32 rtw_hal_read_rfreg(struct adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask)
231 {
232 return PHY_QueryRFReg_8723B(padapter, eRFPath, RegAddr, BitMask);
233 }
rtw_hal_write_rfreg(struct adapter * padapter,u32 eRFPath,u32 RegAddr,u32 BitMask,u32 Data)234 void rtw_hal_write_rfreg(struct adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
235 {
236 PHY_SetRFReg_8723B(padapter, eRFPath, RegAddr, BitMask, Data);
237 }
238
rtw_hal_set_chan(struct adapter * padapter,u8 channel)239 void rtw_hal_set_chan(struct adapter *padapter, u8 channel)
240 {
241 PHY_SwChnl8723B(padapter, channel);
242 }
243
rtw_hal_set_chnl_bw(struct adapter * padapter,u8 channel,enum channel_width Bandwidth,u8 Offset40,u8 Offset80)244 void rtw_hal_set_chnl_bw(struct adapter *padapter, u8 channel,
245 enum channel_width Bandwidth, u8 Offset40, u8 Offset80)
246 {
247 PHY_SetSwChnlBWMode8723B(padapter, channel, Bandwidth, Offset40, Offset80);
248 }
249
rtw_hal_dm_watchdog(struct adapter * padapter)250 void rtw_hal_dm_watchdog(struct adapter *padapter)
251 {
252 rtl8723b_HalDmWatchDog(padapter);
253 }
254
rtw_hal_dm_watchdog_in_lps(struct adapter * padapter)255 void rtw_hal_dm_watchdog_in_lps(struct adapter *padapter)
256 {
257 if (adapter_to_pwrctl(padapter)->fw_current_in_ps_mode) {
258 rtl8723b_HalDmWatchDog_in_LPS(padapter); /* this function caller is in interrupt context */
259 }
260 }
261
beacon_timing_control(struct adapter * padapter)262 void beacon_timing_control(struct adapter *padapter)
263 {
264 rtl8723b_SetBeaconRelatedRegisters(padapter);
265 }
266
267
rtw_hal_xmit_thread_handler(struct adapter * padapter)268 s32 rtw_hal_xmit_thread_handler(struct adapter *padapter)
269 {
270 return rtl8723bs_xmit_buf_handler(padapter);
271 }
272
rtw_hal_notch_filter(struct adapter * adapter,bool enable)273 void rtw_hal_notch_filter(struct adapter *adapter, bool enable)
274 {
275 hal_notch_filter_8723b(adapter, enable);
276 }
277
rtw_hal_c2h_valid(struct adapter * adapter,u8 * buf)278 bool rtw_hal_c2h_valid(struct adapter *adapter, u8 *buf)
279 {
280 return c2h_evt_valid((struct c2h_evt_hdr_88xx *)buf);
281 }
282
rtw_hal_c2h_handler(struct adapter * adapter,u8 * c2h_evt)283 s32 rtw_hal_c2h_handler(struct adapter *adapter, u8 *c2h_evt)
284 {
285 return c2h_handler_8723b(adapter, c2h_evt);
286 }
287
rtw_hal_c2h_id_filter_ccx(struct adapter * adapter)288 c2h_id_filter rtw_hal_c2h_id_filter_ccx(struct adapter *adapter)
289 {
290 return c2h_id_filter_ccx_8723b;
291 }
292
rtw_hal_macid_sleep(struct adapter * padapter,u32 macid)293 s32 rtw_hal_macid_sleep(struct adapter *padapter, u32 macid)
294 {
295 u8 support;
296
297 support = false;
298 rtw_hal_get_def_var(padapter, HAL_DEF_MACID_SLEEP, &support);
299 if (false == support)
300 return _FAIL;
301
302 rtw_hal_set_hwreg(padapter, HW_VAR_MACID_SLEEP, (u8 *)&macid);
303
304 return _SUCCESS;
305 }
306
rtw_hal_macid_wakeup(struct adapter * padapter,u32 macid)307 s32 rtw_hal_macid_wakeup(struct adapter *padapter, u32 macid)
308 {
309 u8 support;
310
311 support = false;
312 rtw_hal_get_def_var(padapter, HAL_DEF_MACID_SLEEP, &support);
313 if (false == support)
314 return _FAIL;
315
316 rtw_hal_set_hwreg(padapter, HW_VAR_MACID_WAKEUP, (u8 *)&macid);
317
318 return _SUCCESS;
319 }
320
rtw_hal_fill_h2c_cmd(struct adapter * padapter,u8 ElementID,u32 CmdLen,u8 * pCmdBuffer)321 s32 rtw_hal_fill_h2c_cmd(struct adapter *padapter, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer)
322 {
323 return FillH2CCmd8723B(padapter, ElementID, CmdLen, pCmdBuffer);
324 }
325