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
/******************************************************************************
 *
 * 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_FW_C_
#include "hal_headers.h"
 
static void _hal_send_fwdl_hub_msg(struct rtw_phl_com_t *phl_com, u8 dl_ok)
{
   struct phl_msg msg = {0};
   u16 evt_id = (dl_ok) ? MSG_EVT_FWDL_OK : MSG_EVT_FWDL_FAIL;
 
   msg.inbuf = NULL;
   msg.inlen = 0;
   SET_MSG_MDL_ID_FIELD(msg.msg_id, PHL_MDL_PHY_MGNT);
   SET_MSG_EVT_ID_FIELD(msg.msg_id, evt_id);
   msg.band_idx = HW_BAND_0;
   rtw_phl_msg_hub_hal_send(phl_com, NULL, &msg);
}
 
static void _hal_fw_log_set(struct rtw_hal_fw_log_cfg *fl_cfg, u8 type, u32 value)
{
   switch(type) {
   case FL_CFG_TYPE_LEVEL:
       fl_cfg->level = value;
       break;
 
   case FL_CFG_TYPE_OUTPUT:
       fl_cfg->output |= value;
       break;
 
   case FL_CFG_TYPE_COMP:
       fl_cfg->comp |= value;
       break;
 
   case FL_CFG_TYPE_COMP_EXT:
       fl_cfg->comp_ext |= value;
       break;
 
   default:
       break;
   }
}
 
static void _hal_fw_log_clr(struct rtw_hal_fw_log_cfg *fl_cfg, u8 type, u32 value)
{
   switch(type) {
   case FL_CFG_TYPE_LEVEL:
       break;
 
   case FL_CFG_TYPE_OUTPUT:
       fl_cfg->output &= (~value);
       break;
 
   case FL_CFG_TYPE_COMP:
       fl_cfg->comp &= (~value);
       break;
 
   case FL_CFG_TYPE_COMP_EXT:
       fl_cfg->comp_ext &= (~value);
       break;
 
   default:
       break;
   }
}
 
static void _hal_fw_log_info(struct rtw_hal_fw_log_cfg *fl_cfg)
{
   PHL_PRINT("%s: level %d, output 0x%08x, comp 0x%08x, comp ext 0x%08x.\n",
           __func__,
           fl_cfg->level,
           fl_cfg->output,
           fl_cfg->comp,
           fl_cfg->comp_ext);
}
 
/*
 * Only export for hal_submodule
*/
enum rtw_hal_status rtw_hal_fw_log_cfg(void *halcom, u8 op, u8 type, u32 value)
{
   struct rtw_hal_com_t *hal_com = (struct rtw_hal_com_t *)halcom;
   static struct rtw_hal_fw_log_cfg fl_cfg = {0};
 
   switch(op) {
   case FL_CFG_OP_SET:
       _hal_fw_log_set(&fl_cfg, type, value);
       break;
   case FL_CFG_OP_CLR:
       _hal_fw_log_clr(&fl_cfg, type, value);
       break;
   case FL_CFG_OP_INFO:
       _hal_fw_log_info(&fl_cfg);
       break;
   default:
       break;
   }
 
   return rtw_hal_mac_fw_log_cfg(hal_com, &fl_cfg);
}
 
void hal_fw_en_basic_log(struct rtw_hal_com_t *hal_com,
                         struct mac_ax_fw_log* fw_log_info)
{
   rtw_hal_fw_log_cfg(hal_com, FL_CFG_OP_SET, FL_CFG_TYPE_LEVEL,
               fw_log_info->level);
   rtw_hal_fw_log_cfg(hal_com, FL_CFG_OP_SET, FL_CFG_TYPE_OUTPUT,
               fw_log_info->output);
   rtw_hal_fw_log_cfg(hal_com, FL_CFG_OP_SET, FL_CFG_TYPE_COMP,
               fw_log_info->comp);
   rtw_hal_fw_log_cfg(hal_com, FL_CFG_OP_SET, FL_CFG_TYPE_COMP_EXT,
               fw_log_info->comp_ext);
}
 
enum rtw_hal_status rtw_hal_en_fw_log(void *hal, u32 comp, bool en)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   enum rtw_hal_status status = RTW_HAL_STATUS_FAILURE;
 
   if (en)
       status = rtw_hal_fw_log_cfg(hal_info->hal_com, FL_CFG_OP_SET,
                       FL_CFG_TYPE_COMP, comp);
   else
       status = rtw_hal_fw_log_cfg(hal_info->hal_com, FL_CFG_OP_CLR,
                       FL_CFG_TYPE_COMP, comp);
   PHL_INFO("rtw_hal_en_fw_log(): status(%d), en(%d)\n", status, en);
   return status;
}
 
enum rtw_hal_status
rtw_hal_download_fw(struct rtw_phl_com_t *phl_com, void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
   struct rtw_fw_info_t *fw_info = &phl_com->fw_info;
 
   FUNCIN_WSTS(hal_status);
 
   if (!fw_info->fw_en)
       return hal_status;
 
   if (fw_info->dlrom_en) {
       hal_status = rtw_hal_mac_romdl(hal_info, fw_info->rom_buff,
                                      fw_info->rom_size);
 
       if (hal_status != RTW_HAL_STATUS_SUCCESS)
           return hal_status;
   }
 
   hal_status = rtw_hal_mac_disable_cpu(hal_info);
   if (hal_status != RTW_HAL_STATUS_SUCCESS) {
       PHL_ERR("disable cpu fail!\n");
       return hal_status;
   }
 
   hal_status = rtw_hal_mac_enable_cpu(hal_info, 0, true);
   if (hal_status != RTW_HAL_STATUS_SUCCESS) {
       PHL_ERR("enable cpu fail!\n");
       return hal_status;
   }
 
   if (fw_info->dlram_en) {
       hal_status = rtw_hal_mac_fwdl(hal_info, fw_info->ram_buff,
                                     fw_info->ram_size);
   }
 
   _hal_send_fwdl_hub_msg(phl_com, (!hal_status) ? true : false);
 
   FUNCOUT_WSTS(hal_status);
 
   return hal_status;
}
 
enum rtw_hal_status
rtw_hal_redownload_fw(struct rtw_phl_com_t *phl_com, void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
   struct rtw_fw_info_t *fw_info = &phl_com->fw_info;
   u32 start_t = 0;
 
   FUNCIN_WSTS(hal_status);
 
   /* Disable/Enable CPU is necessary first when FWDL from files */
   if(fw_info->dlram_en && fw_info->fw_src == RTW_FW_SRC_EXTNAL) {
 
       hal_status = rtw_hal_mac_disable_cpu(hal_info);
       if (hal_status != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("disable cpu fail!\n");
           return hal_status;
       }
 
       hal_status = rtw_hal_mac_enable_cpu(hal_info, 0, true);
       if (hal_status != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("enable cpu fail!\n");
           return hal_status;
       }
 
       hal_status = rtw_hal_mac_fwdl(hal_info, fw_info->ram_buff,
                         fw_info->ram_size);
       if (hal_status != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("rtw_hal_mac_fwdl fail!\n");
           return hal_status;
       }
   }
 
   if (fw_info->dlram_en && fw_info->fw_src != RTW_FW_SRC_EXTNAL) {
       start_t = _os_get_cur_time_us();
       hal_status = rtw_hal_mac_enable_fw(hal_info, fw_info->fw_type);
       PHL_INFO("%s : fw_type: %d, FWDL Total Cost Time: %u us\n",
            __func__, fw_info->fw_type,
            phl_get_passing_time_us(start_t));
       if (hal_status != RTW_HAL_STATUS_SUCCESS) {
           PHL_ERR("rtw_hal_mac_enable_fw fail!\n");
           return hal_status;
       }
   }
 
   if (rtw_hal_mac_get_wcpu_cap(phl_com, hal_info) != RTW_HAL_STATUS_SUCCESS) {
       PHL_ERR("%s : can't get fw capability.\n", __func__);
       return RTW_HAL_STATUS_FAILURE;
   }
 
#ifdef CONFIG_POWER_SAVE
   if (fw_info->fw_type == RTW_FW_WOWLAN)
       rtw_hal_ps_fw_cap_decision(phl_com, true);
   else
       rtw_hal_ps_fw_cap_decision(phl_com, false);
#endif /* CONFIG_POWER_SAVE */
 
   rtw_hal_rf_config_radio_to_fw(hal_info);
 
   /**
    * Should reset packet offload related information
    * 1. phl packet offload module
    * 2. halmac packet offload module
    */
   rtw_phl_pkt_ofld_del_all_entry_req(phl_com);
   if (RTW_HAL_STATUS_SUCCESS != rtw_hal_mac_reset_pkt_ofld_state(hal_info))
       PHL_ERR("%s: reset pkt ofld state fail!\n", __func__);
 
   _hal_send_fwdl_hub_msg(phl_com, (!hal_status) ? true : false);
   #ifdef CONFIG_BTCOEX
   rtw_hal_btc_redownload_fw_ntfy(hal_info);
   #endif /* CONFIG_BTCOEX */
   FUNCOUT_WSTS(hal_status);
 
   return hal_status;
}
 
enum rtw_hal_status
rtw_hal_pg_redownload_fw(struct rtw_phl_com_t *phl_com, void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
   struct rtw_fw_info_t *fw_info = &phl_com->fw_info;
   u8 *fw_buff = NULL;
   u32 fw_size = 0;
 
   FUNCIN_WSTS(hal_status);
 
   if (fw_info->fw_src == RTW_FW_SRC_EXTNAL) {
       fw_buff = fw_info->ram_buff;
       fw_size = fw_info->ram_size;
   } else {
       hal_status = rtw_hal_mac_query_fw_buff(hal_info,
                       fw_info->fw_type,
                       &fw_buff, &fw_size);
       if (hal_status != RTW_HAL_STATUS_SUCCESS)
           return RTW_HAL_STATUS_FAILURE;
   }
 
   hal_status = rtw_hal_mac_fwredl(hal_info, fw_buff, fw_size);
 
   FUNCOUT_WSTS(hal_status);
 
   return hal_status;
}
 
void rtw_hal_fw_dbg_dump(void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
 
   rtw_hal_mac_fw_dbg_dump(hal_info);
}
 
enum rtw_fw_status rtw_hal_get_fw_status(void *h)
{
   struct hal_info_t *hal = (struct hal_info_t *)h;
 
   return rtw_hal_mac_get_fw_status(hal);
}