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