hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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
335
336
337
338
339
340
341
342
343
344
/******************************************************************************
 *
 * 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.
 *
 *****************************************************************************/
#define _HAL_DBCC_C_
#include "hal_headers.h"
 
#ifdef CONFIG_DBCC_SUPPORT
enum phl_phy_idx
hal_dbcc_cck_phyidx_decision(struct hal_info_t *hal_info,
                        struct rtw_phl_com_t *phl_com,
                        bool dbcc_en)
{
   enum phl_phy_idx phy_idx = HW_PHY_0;
   struct mr_ctl_t *mr_ctl = &phl_com->mr_ctrl;
   struct hw_band_ctl_t *band0_ctrl = &(mr_ctl->band_ctrl[HW_BAND_0]);
   /*struct hw_band_ctl_t *band1_ctrl = &(mr_ctl->band_ctrl[HW_BAND_1]);*/
 
   if (dbcc_en == false)
       goto _exit;
 
   #ifdef CONFIG_DBCC_FORCE
   if (is_frc_dbcc_mode(phl_com))
       phy_idx = phl_com->dev_cap.dbcc_force_cck_phyidx;
   else
   #endif
   if (phl_is_mp_mode(phl_com)) {
            phy_idx = (hal_info->hal_com->band[HW_BAND_0].cur_chandef.band ==
                  BAND_ON_24G)
                 ? HW_PHY_0 : HW_PHY_1;
   } else {
       phy_idx = (band0_ctrl->chctx_band_map & BIT(CC_BAND_24G)) ? HW_PHY_0 : HW_PHY_1;
   }
 
_exit:
   mr_ctl->cck_phyidx = phy_idx;
   PHL_INFO("%s => mr_ctl->cck_phyidx:%d\n", __func__, mr_ctl->cck_phyidx);
   return phy_idx;
}
 
enum rtw_hal_status
rtw_hal_dbcc_trx_ctrl(void *hal, struct rtw_phl_com_t *phl_com,
               enum phl_band_idx band_idx, bool pause)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   enum rtw_hal_status hsts = RTW_HAL_STATUS_FAILURE;
#ifdef DBG_DBCC_MONITOR_TIME
   u32 start_t = 0;
 
   phl_fun_monitor_start(&start_t, true, __FUNCTION__);
#endif /* DBG_DBCC_MONITOR_TIME */
   hsts = rtw_hal_mac_dbcc_trx_ctrl(hal_info, band_idx, pause);
   if (hsts != RTW_HAL_STATUS_SUCCESS)
       PHL_ERR("%s band_%d , pause:%d failed\n", __func__, band_idx, pause);
#ifdef DBG_DBCC_MONITOR_TIME
   phl_fun_monitor_end(&start_t, __FUNCTION__);
#endif /* DBG_DBCC_MONITOR_TIME */
   return hsts;
}
 
enum rtw_hal_status
rtw_hal_dbcc_pre_cfg(void *hal, struct rtw_phl_com_t *phl_com, bool dbcc_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 hsts = RTW_HAL_STATUS_FAILURE;
   struct hal_ppdu_sts_cfg psts_cfg = {0};
#ifdef DBG_DBCC_MONITOR_TIME
   u32 start_t = 0;
 
   phl_fun_monitor_start(&start_t, true, __FUNCTION__);
#endif /* DBG_DBCC_MONITOR_TIME */
   if (!phl_com->dev_cap.dbcc_sup)
       goto exit_func;
 
   hal_com->dbcc_en = (dbcc_en) ? true : false;
   if (dbcc_en) { /*dbcc enable*/
       rtw_hal_init_hw_band_info(hal, HW_BAND_1);
       hsts = rtw_hal_reset(hal_com, HW_PHY_0, HW_BAND_0, true);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("%s - EN hal reset - HW_PHY_0, HW_BAND_0 failed\n", __func__);
           goto exit_func;
       }
 
       hsts = rtw_hal_mac_dbcc_pre_cfg(phl_com, hal_info, dbcc_en);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("%s - EN mac_dbcc_pre_cfg failed\n", __func__);
           hal_com->dbcc_en = false;
           goto exit_func;
       }
 
       psts_cfg.band_idx = HW_BAND_1;
       psts_cfg.ppdu_stat_en = true;
       psts_cfg.filter = HAL_PPDU_HAS_CRC_OK | HAL_PPDU_HAS_DMA_OK;
       psts_cfg.appen_info = HAL_PPDU_MAC_INFO | HAL_PPDU_PLCP | HAL_PPDU_RX_CNT;
 
       hsts = rtw_hal_ppdu_sts_init(hal, &psts_cfg);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           hal_com->dbcc_en = false;
           PHL_ERR("%s - EN HW_BAND_1 ppdu_sts_init failed\n", __func__);
           goto exit_func;
       }
       phl_com->ppdu_sts_info.en_ppdu_sts[HW_BAND_1] = true;
 
       /* Enable DrvInfo for per pkt rssi */
       if (RTW_DEV_CAP_ENABLE == phl_com->dev_cap.drv_info_sup) {
           hsts = rtw_hal_mac_drvinfo_cfg(hal, true, HW_BAND_1);
           if (hsts != RTW_HAL_STATUS_SUCCESS) {
               hal_com->dbcc_en = false;
               PHL_ERR("%s - EN HW_BAND_1 drvinfo failed\n", __func__);
               goto exit_func;
           }
       }
 
       rtw_hal_mac_dbcc_trx_ctrl(hal_info, HW_BAND_1, true);
 
       hsts = rtw_hal_reset(hal_com, HW_PHY_1, HW_BAND_1, true);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("%s - EN hal reset - HW_PHY_1, HW_BAND_1 failed\n", __func__);
           goto exit_func;
       }
 
       /*phy_dbcc_pre_cfg*/
       hsts = rtw_hal_phy_dbcc_pre_cfg(hal_info, phl_com, dbcc_en);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("%s - EN phy_dbcc_pre_cfg failed\n", __func__);
           hal_com->dbcc_en = false;
           goto exit_func;
       }
   }
   else { /*dbcc disable*/
       hsts = rtw_hal_reset(hal_com, HW_PHY_0, HW_BAND_0, true);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("%s - DIS hal reset - HW_PHY_0, HW_BAND_0 failed\n", __func__);
           goto exit_func;
       }
 
       hsts = rtw_hal_reset(hal_com, HW_PHY_1, HW_BAND_1, true);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("%s - DIS hal reset - HW_PHY_1, HW_BAND_1 failed\n", __func__);
           goto exit_func;
       }
 
       hsts = rtw_hal_mac_dbcc_pre_cfg(phl_com, hal_info, dbcc_en);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("%s - DIS mac_dbcc_pre_cfg failed\n", __func__);
           hal_com->dbcc_en = true;
           goto exit_func;
       }
       /*phy_dbcc_pre_cfg*/
       hsts = rtw_hal_phy_dbcc_pre_cfg(hal_info, phl_com, dbcc_en);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("%s - DIS phy_dbcc_pre_cfg failed\n", __func__);
           hal_com->dbcc_en = true;
           goto exit_func;
       }
   }
 
   PHL_INFO("%s-%s done and success\n", __func__, (dbcc_en) ? "EN" : "DIS");
 
exit_func:
#ifdef DBG_DBCC_MONITOR_TIME
   phl_fun_monitor_end(&start_t, __FUNCTION__);
#endif /* DBG_DBCC_MONITOR_TIME */
   return hsts;
}
 
enum rtw_hal_status
rtw_hal_dbcc_cfg(void *hal, struct rtw_phl_com_t *phl_com, bool dbcc_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 hsts = RTW_HAL_STATUS_FAILURE;
   struct hal_ppdu_sts_cfg psts_cfg = {0};
#ifdef DBG_DBCC_MONITOR_TIME
   u32 start_t = 0;
 
   phl_fun_monitor_start(&start_t, true, __FUNCTION__);
#endif /* DBG_DBCC_MONITOR_TIME */
   if (!phl_com->dev_cap.dbcc_sup)
       goto exit_func;
 
   if (dbcc_en) { /*dbcc enable*/
       /*mac_dbcc_cfg*/
       hsts = rtw_hal_mac_dbcc_cfg(phl_com, hal_info, dbcc_en);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("%s - EN mac_dbcc_cfg failed\n", __func__);
           hal_com->dbcc_en = false;
           goto exit_func;
       }
 
       /*bb,rf_dbcc_cfg*/
       hsts = rtw_hal_phy_dbcc_cfg(hal_info, phl_com, dbcc_en);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("%s - EN phy_dbcc_cfg failed\n", __func__);
           hal_com->dbcc_en = false;
           goto exit_func;
       }
 
       /*init rx filter opt,type, max MPDU size, RTS threshold*/
       hsts = rtw_hal_hw_param_init(hal_info, phl_com, HW_BAND_1);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("%s - EN rx param init failed\n", __func__);
           hal_com->dbcc_en = false;
           goto exit_func;
       }
   }
   else { /*dbcc disable*/
       psts_cfg.band_idx = HW_BAND_1;
       psts_cfg.ppdu_stat_en = false;
 
       hsts = rtw_hal_ppdu_sts_init(hal, &psts_cfg);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           hal_com->dbcc_en = true;
           PHL_ERR("%s - DIS HW_BAND_1 ppdu_sts_deinit failed\n", __func__);
           goto exit_func;
       }
       phl_com->ppdu_sts_info.en_ppdu_sts[HW_BAND_1] = false;
 
       /* Disable DrvInfo for per pkt rssi */
       if (RTW_DEV_CAP_ENABLE == phl_com->dev_cap.drv_info_sup) {
           hsts = rtw_hal_mac_drvinfo_cfg(hal, false, HW_BAND_1);
           if (hsts != RTW_HAL_STATUS_SUCCESS) {
               PHL_ERR("%s - DIS HW_BAND_1 drvinfo failed\n", __func__);
               hal_com->dbcc_en = true;
               goto exit_func;
           }
       }
 
       /*mac_dbcc_cfg*/
       hsts = rtw_hal_mac_dbcc_cfg(phl_com, hal_info, dbcc_en);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("%s - DIS HW_BAND_1 mac_dbcc_cfg failed\n", __func__);
           hal_com->dbcc_en = true;
           goto exit_func;
       }
 
       /*bb,rf_dbcc_cfg*/
       hsts = rtw_hal_phy_dbcc_cfg(hal_info, phl_com, dbcc_en);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("%s - DIS HW_BAND_1 phy_dbcc_cfg failed\n", __func__);
           hal_com->dbcc_en = true;
           goto exit_func;
       }
       hsts = rtw_hal_reset(hal_com, HW_PHY_0, HW_BAND_0, false);
       if (hsts != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("%s - DIS hal reset - HW_PHY_0, HW_BAND_0 failed\n", __func__);
           goto exit_func;
       }
   }
 
   PHL_INFO("%s-%s done and success\n", __func__, (dbcc_en) ? "EN" : "DIS");
 
exit_func:
#ifdef DBG_DBCC_MONITOR_TIME
   phl_fun_monitor_end(&start_t, __FUNCTION__);
#endif /* DBG_DBCC_MONITOR_TIME */
   return hsts;
}
 
enum rtw_hal_status
rtw_hal_dbcc_reset_hal(void *hal)
{
   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 hsts = RTW_HAL_STATUS_FAILURE;
 
   hsts = rtw_hal_reset(hal_com, HW_PHY_0, HW_BAND_0, false);
   if (hsts != RTW_HAL_STATUS_SUCCESS) {
       PHL_ERR("%s - hal reset - HW_PHY_0, HW_BAND_0 failed\n", __func__);
       _os_warn_on(1);
       goto exit_func;
   }
   hsts = rtw_hal_reset(hal_com, HW_PHY_1, HW_BAND_1, false);
   if (hsts != RTW_HAL_STATUS_SUCCESS) {
       PHL_ERR("%s - hal reset - HW_PHY_1, HW_BAND_1 failed\n", __func__);
       _os_warn_on(1);
       goto exit_func;
   }
 
   hsts = RTW_HAL_STATUS_SUCCESS;
 
exit_func:
   return hsts;
}
 
enum rtw_hal_status
rtw_hal_dbcc_band_switch_hdl(void *hal, enum phl_band_idx band_idx)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct rtw_hal_com_t *hal_com = hal_info->hal_com;
 
   PHL_INFO("[assoc_sta_cnt] all:%d, B0:%d, B1:%d\n",
           hal_com->assoc_sta_cnt,
           hal_com->band[HW_BAND_0].assoc_sta_cnt,
           hal_com->band[HW_BAND_1].assoc_sta_cnt);
 
   hal_com->band[HW_BAND_0].assoc_sta_cnt =
       hal_com->band[HW_BAND_1].assoc_sta_cnt;
   hal_com->band[HW_BAND_1].assoc_sta_cnt = 0;
 
   PHL_INFO("[assoc_sta_cnt] all:%d, B0:%d, B1:%d\n",
           hal_com->assoc_sta_cnt,
           hal_com->band[HW_BAND_0].assoc_sta_cnt,
           hal_com->band[HW_BAND_1].assoc_sta_cnt);
   return RTW_HAL_STATUS_SUCCESS;
}
 
void rtw_hal_dbcc_hci_ctrl(void *hal, enum phl_band_idx band_idx, u8 pause)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
 
   /* Stop DMA + Disable all of txch dma (Reset B1 TXBD idx to 0) */
   if (RTW_HAL_STATUS_SUCCESS != rtw_hal_mac_dbcc_hci_ctrl(hal_info, band_idx, pause))
       PHL_ERR("%s failure \n", __func__);
}
 
 
void
hal_dbcc_cfg_phy_map(struct hal_info_t *hal, enum phl_band_idx band_idx)
{
   enum phl_phy_idx phy_idx = rtw_hal_hw_band_to_phy_idx(band_idx);
   enum phl_phy_idx cck_phy_idx = HW_PHY_MAX;
 
   rtw_hal_reset(hal->hal_com, phy_idx, band_idx, true);
 
   cck_phy_idx = hal_dbcc_cck_phyidx_decision(hal, hal->phl_com,
                                              hal->hal_com->dbcc_en);
   PHL_INFO("%s: cck_phy_idx(%d)\n", __func__, cck_phy_idx);
   rtw_hal_bb_cfg_dbcc_phy_map(hal, cck_phy_idx);
 
   rtw_hal_reset(hal->hal_com, phy_idx, band_idx, false);
}
#endif /*CONFIG_DBCC_SUPPORT*/