xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/phl/hal_g6/hal_com_i.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2019 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 #ifndef _HAL_COM_I_C_
16 #define _HAL_COM_I_C_
17 #include "hal_headers.h"
18 
19 void
rtw_hal_com_scan_set_tx_lifetime(void * hal,u8 band)20 rtw_hal_com_scan_set_tx_lifetime(void *hal, u8 band)
21 {
22 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
23 
24 	/* set mgnt queue pkt lifetime */
25 #define HAL_COM_MGQ_TX_LIFETIME_MS 19
26 	rtw_hal_mac_set_tx_lifetime(hal_info, band, false, true, 0,
27 				    (HAL_COM_MGQ_TX_LIFETIME_MS * 1000));
28 }
29 
rtw_hal_com_scan_restore_tx_lifetime(void * hal,u8 band)30 void rtw_hal_com_scan_restore_tx_lifetime(void *hal, u8 band)
31 {
32 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
33 
34 	/* reset data/mgnt queue pkt lifetime to 0 */
35 	rtw_hal_mac_set_tx_lifetime(hal_info, band, false, false, 0, 0);
36 
37 }
38 
rtw_hal_scan_pause_tx_fifo(void * hinfo,u8 band_idx,bool off_ch)39 enum rtw_hal_status rtw_hal_scan_pause_tx_fifo(void *hinfo,
40 	u8 band_idx, bool off_ch)
41 {
42 	enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
43 	struct hal_info_t *hal_info = (struct hal_info_t *)hinfo;
44 
45 
46 	hal_status = rtw_hal_tx_pause(hal_info->hal_com, band_idx,
47 		off_ch, PAUSE_RSON_NOR_SCAN);
48 
49 	return hal_status;
50 }
51 
rtw_hal_dfs_pause_tx(void * hinfo,u8 band_idx,bool off_ch)52 enum rtw_hal_status rtw_hal_dfs_pause_tx(void *hinfo,
53 					 u8 band_idx, bool off_ch)
54 {
55 	enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
56 	struct hal_info_t *hal_info = (struct hal_info_t *)hinfo;
57 
58 	hal_status = rtw_hal_tx_pause(hal_info->hal_com, band_idx,
59 				      off_ch, PAUSE_RSON_DFS);
60 
61 	return hal_status;
62 }
63 
64 #ifdef CONFIG_FSM
rtw_hal_scan_flush_queue(void * hinfo,struct rtw_wifi_role_t * wrole)65 enum rtw_hal_status rtw_hal_scan_flush_queue(void *hinfo,
66 	struct rtw_wifi_role_t *wrole)
67 {
68 	struct hal_info_t *hal_info = (struct hal_info_t *)hinfo;
69 	int wait = 5/* 10ms */, hal_status;
70 	u8 val8;
71 #if 0
72 	struct phl_queue *sta_queue;
73 	struct rtw_phl_stainfo_t *sta;
74 	void *drv = hal_to_drvpriv(hal_info);
75 	_os_list *sta_list;
76 	u8 rts_txcnt_lmt_sel = 1;
77 	u8 rts_txcnt_lmt = 1;
78 	u8 data_txcnt_lmt_sel = 1;
79 	u8 data_tx_cnt_lmt = 1;
80 #endif
81 	hal_status = rtw_hal_mac_is_tx_mgnt_empty(hal_info, wrole->hw_band, &val8);
82 
83 	if (val8)
84 		return RTW_HAL_STATUS_SUCCESS;
85 
86 #if 0
87 	sta_queue = &wrole->assoc_sta_queue;
88 	sta_list = &sta_queue->queue;
89 
90 	/* TODO wait halmac api */
91 	/* shorten retry limit */
92 	_os_spinlock(drv, &sta_queue->lock, _bh, NULL);
93 	phl_list_for_loop(sta, struct rtw_phl_stainfo_t, sta_list, list) {
94 		rtw_hal_mac_set_rty_lmt(hal_info->hal_com, sta->macid,
95 			rts_txcnt_lmt_sel, rts_txcnt_lmt,
96 			data_txcnt_lmt_sel, data_tx_cnt_lmt);
97 	}
98 	_os_spinunlock(drv, &sta_queue->lock, _bh, NULL);
99 #endif
100 	while (wait-- && (!val8)) {
101 		_os_delay_ms(hal_info->hal_com->drv_priv, 2);
102 		rtw_hal_mac_is_tx_mgnt_empty(hal_info, wrole->hw_band, &val8);
103 	}
104 #if 0
105 	/* restore retry limit */
106 	if (wrole->cap.rty_lmt_rts == 0xFF)
107 		rts_txcnt_lmt_sel = 0;
108 	else
109 		rts_txcnt_lmt = wrole->cap.rty_lmt_rts & 0xF;
110 
111 	if (wrole->cap.rty_lmt == 0xFF)
112 		data_txcnt_lmt_sel = 0;
113 	else
114 		data_tx_cnt_lmt = wrole->cap.rty_lmt & 0x3F;
115 
116 	rtw_hal_mac_set_rty_lmt(hal_info->hal_com, sta->macid,
117 		rts_txcnt_lmt_sel, rts_txcnt_lmt,
118 		data_txcnt_lmt_sel, data_tx_cnt_lmt);
119 #endif
120 	if (val8 == DLE_QUEUE_EMPTY)
121 		return RTW_HAL_STATUS_SUCCESS;
122 
123 	return RTW_HAL_STATUS_FAILURE;
124 }
125 #endif
126 
rtw_hal_notify_switch_band(void * hinfo,enum band_type band,enum phl_phy_idx phy_idx)127 enum rtw_hal_status rtw_hal_notify_switch_band(void *hinfo,
128 			enum band_type band, enum phl_phy_idx phy_idx)
129 {
130 	enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
131 	struct hal_info_t *hal_info = (struct hal_info_t *)hinfo;
132 
133 #ifdef CONFIG_BTCOEX
134 	rtw_hal_btc_switch_band_ntfy(hal_info, phy_idx, band);
135 #endif
136 
137 	rtw_hal_bb_fw_edcca(hal_info);
138 
139 	rtw_hal_rf_set_power(hal_info, phy_idx, PWR_BY_RATE);
140 
141 	rtw_hal_rf_do_tssi_scan(hal_info, phy_idx);
142 
143 	return hal_status;
144 }
145 
146 enum rtw_hal_status
rtw_hal_proc_cmd(void * hal,char proc_cmd,struct rtw_proc_cmd * incmd,char * output,u32 out_len)147 rtw_hal_proc_cmd(void *hal, char proc_cmd, struct rtw_proc_cmd *incmd,
148 							char *output, u32 out_len)
149 {
150 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
151 	enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
152 
153 	if(proc_cmd == RTW_PROC_CMD_BB){
154 		if(rtw_hal_bb_proc_cmd(hal_info, incmd, output, out_len))
155 			hal_status = RTW_HAL_STATUS_SUCCESS;
156 	}
157 	if(proc_cmd == RTW_PROC_CMD_RF){
158 		if(rtw_hal_rf_proc_cmd(hal_info, incmd, output, out_len))
159 			hal_status = RTW_HAL_STATUS_SUCCESS;
160 	}
161 	if(proc_cmd == RTW_PROC_CMD_MAC){
162 		if(rtw_hal_mac_proc_cmd(hal_info, incmd, output, out_len))
163 			hal_status = RTW_HAL_STATUS_SUCCESS;
164 	}
165 #ifdef CONFIG_BTCOEX
166 	if(proc_cmd == RTW_PROC_CMD_BTC){
167 		if(rtw_hal_btc_proc_cmd(hal_info, incmd, output, out_len))
168 			hal_status = RTW_HAL_STATUS_SUCCESS;
169 	}
170 #endif
171 	if(proc_cmd == RTW_PROC_CMD_EFUSE){
172 		if(rtw_hal_efuse_proc_cmd(hal_info, incmd, output, out_len))
173 			hal_status = RTW_HAL_STATUS_SUCCESS;
174 	}
175 	return hal_status;
176 }
177 
rtw_hal_get_fw_ver(void * hal,char * ver_str,u16 len)178 void rtw_hal_get_fw_ver(void *hal, char *ver_str, u16 len)
179 {
180 	rtw_hal_mac_get_fw_ver((struct hal_info_t *)hal, ver_str, len);
181 }
182 
183 enum rtw_hal_status
rtw_hal_set_mu_edca(void * hal,u8 band,u8 ac,u16 timer,u8 cw_min,u8 cw_max,u8 aifsn)184 rtw_hal_set_mu_edca(void *hal, u8 band, u8 ac,
185 	u16 timer, u8 cw_min, u8 cw_max, u8 aifsn)
186 {
187 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
188 	enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
189 	u16 timer_32us;
190 	u8 aifs_us;
191 	u8 slot_time, sifs;
192 
193 	/* TODO: Get aSlotTime and aSIFS according to current PHY */
194 	slot_time = 9;
195 	sifs = 16;
196 	timer_32us = (timer<<8);
197 	aifs_us = (aifsn == 0)?0:(aifsn*slot_time + sifs);
198 	hal_status = rtw_hal_mac_set_mu_edca(hal_info->hal_com,
199 					band, ac, timer_32us, cw_min, cw_max, aifs_us);
200 	return hal_status;
201 }
202 
203 enum rtw_hal_status
rtw_hal_set_mu_edca_ctrl(void * hal,u8 band,u8 wmm,u8 set)204 rtw_hal_set_mu_edca_ctrl(void *hal, u8 band, u8 wmm, u8 set)
205 {
206 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
207 	enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
208 
209 	hal_status = rtw_hal_mac_set_mu_edca_ctrl(hal_info->hal_com,
210 					band, wmm, set);
211 	return hal_status;
212 }
213 enum rtw_hal_status
rtw_hal_reset(struct rtw_hal_com_t * hal_com,enum phl_phy_idx phy_idx,u8 band_idx,bool reset)214 rtw_hal_reset(struct rtw_hal_com_t *hal_com, enum phl_phy_idx phy_idx, u8 band_idx, bool reset)
215 {
216     struct hal_info_t *hal_info = hal_com->hal_priv;
217     enum rtw_hal_status status = RTW_HAL_STATUS_SUCCESS;
218 
219 	if (reset){
220 		/* disable contention */
221 		status = rtw_hal_tx_pause(hal_com, band_idx, true, PAUSE_RSON_RESET);
222 		if(status != RTW_HAL_STATUS_SUCCESS){
223 			PHL_ERR("%s rtw_hal_tx_pause - failed\n", __func__);
224 			return status;
225 		}
226 
227 		/* disable ppdu_sts */
228 		status = rtw_hal_mac_ppdu_stat_cfg(hal_info, band_idx, false, 0, 0);
229 		if(status != RTW_HAL_STATUS_SUCCESS){
230 			PHL_ERR("%s rtw_hal_mac_ppdu_stat_cfg - failed\n", __func__);
231 			return status;
232 		}
233 
234 		/*disable DFS/TSSI*/
235 		rtw_hal_bb_dfs_en(hal_info, false);
236 		if (!hal_com->dbcc_en) {
237 			rtw_hal_bb_tssi_cont_en(hal_info, false, RF_PATH_A);
238 			rtw_hal_bb_tssi_cont_en(hal_info, false, RF_PATH_B);
239 		}else{
240 			if(phy_idx == HW_PHY_0)
241 				rtw_hal_bb_tssi_cont_en(hal_info, false, RF_PATH_A);
242 			else
243 				rtw_hal_bb_tssi_cont_en(hal_info, false, RF_PATH_B);
244 		}
245 		/*disable ADC*/
246 		rtw_hal_bb_adc_en(hal_info, false);
247 		/* wait 40us*/
248 		_os_delay_us(hal_com->drv_priv, 40);
249 		/* reset BB*/
250 		rtw_hal_bb_reset_en(hal_info, false, phy_idx);
251 	}else{
252 		/*enable ppdu_sts*/
253 		status = rtw_hal_mac_ppdu_stat_cfg(
254 			hal_info, band_idx, true,
255 			hal_com->band[band_idx].ppdu_sts_appen_info,
256 			hal_com->band[band_idx].ppdu_sts_filter);
257 
258 		if(status != RTW_HAL_STATUS_SUCCESS){
259 			PHL_ERR("%s rtw_hal_mac_ppdu_stat_cfg - failed\n", __func__);
260 			return status;
261 		}
262 		/*enable ADC*/
263 		rtw_hal_bb_adc_en(hal_info, true);
264 		/*enable DFS/TSSI*/
265 		rtw_hal_bb_dfs_en(hal_info, true);
266 		if (!hal_com->dbcc_en) {
267 			rtw_hal_bb_tssi_cont_en(hal_info, true, RF_PATH_A);
268 			rtw_hal_bb_tssi_cont_en(hal_info, true, RF_PATH_B);
269 		}else{
270 			if(phy_idx == HW_PHY_0)
271 				rtw_hal_bb_tssi_cont_en(hal_info, true, RF_PATH_A);
272 			else
273 				rtw_hal_bb_tssi_cont_en(hal_info, true, RF_PATH_B);
274 		}
275 		/*BB reset set to 1*/
276 		rtw_hal_bb_reset_en(hal_info, true, phy_idx);
277 
278 		status = rtw_hal_tx_pause(hal_com, band_idx, false, PAUSE_RSON_RESET);
279 		if(status != RTW_HAL_STATUS_SUCCESS){
280 			PHL_ERR("%s rtw_hal_tx_pause - failed\n", __func__);
281 			return status;
282 		}
283 	}
284 	return status;
285 }
286 
rtw_hal_ppdu_sts_cfg(void * hal,u8 band_idx,bool en)287 enum rtw_hal_status rtw_hal_ppdu_sts_cfg(void *hal, u8 band_idx, bool en)
288 {
289 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
290 	struct rtw_hal_com_t *hal_com = hal_info->hal_com;
291 	enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
292 
293 	if (en) {
294 		hal_status = rtw_hal_mac_ppdu_stat_cfg(
295 			hal_info, band_idx, true,
296 			hal_com->band[band_idx].ppdu_sts_appen_info,
297 			hal_com->band[band_idx].ppdu_sts_filter);
298 	} else {
299 		hal_status = rtw_hal_mac_ppdu_stat_cfg(hal_info, band_idx, false, 0, 0);
300 	}
301 
302 	if (hal_status != RTW_HAL_STATUS_SUCCESS)
303 		PHL_ERR("%s (en %d) - failed\n", __func__, en);
304 
305 	return hal_status;
306 }
307 
308 void
rtw_hal_disconnect_notify(void * hal,struct rtw_chan_def * chandef)309 rtw_hal_disconnect_notify(void *hal, struct rtw_chan_def *chandef)
310 {
311 	rtw_hal_rf_disconnect_notify(hal, chandef);
312 	PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_disconnect_notify(): chandef band(%d), chan(%d), bw(%d), offset(%d)\n",
313 		chandef->band, chandef->chan, chandef->bw, chandef->offset);
314 }
315 
rtw_hal_check_ch_rfk(void * hal,struct rtw_chan_def * chandef)316 bool rtw_hal_check_ch_rfk(void *hal, struct rtw_chan_def *chandef)
317 {
318 	bool check = false;
319 	check = rtw_hal_rf_check_mcc_ch(hal, chandef);
320 	PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_check_ch_rfk(): check ok(%d), band(%d), chan(%d), bw(%d), offset(%d)\n",
321 		check, chandef->band, chandef->chan, chandef->bw, chandef->offset);
322 	return check;
323 }
324 
rtw_hal_env_rpt(struct rtw_hal_com_t * hal_com,struct rtw_env_report * env_rpt,struct rtw_wifi_role_t * wrole)325 void rtw_hal_env_rpt(struct rtw_hal_com_t *hal_com, struct rtw_env_report *env_rpt,
326 	struct rtw_wifi_role_t *wrole)
327 {
328 	enum phl_phy_idx p_idx = HW_PHY_0;
329 
330 	p_idx = rtw_hal_bb_band_to_phy_idx(hal_com, wrole->hw_band);
331 	rtw_hal_bb_env_rpt(hal_com, env_rpt, p_idx);
332 }
333 
334 #endif /* _HAL_COM_I_C_ */
335