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 #define _PHL_INIT_C_
16 #include "phl_headers.h"
17
_phl_com_init_rssi_stat(struct rtw_phl_com_t * phl_com)18 void _phl_com_init_rssi_stat(struct rtw_phl_com_t *phl_com)
19 {
20 u8 i = 0, j = 0;
21 for (i = 0; i < RTW_RSSI_TYPE_MAX; i++) {
22 phl_com->rssi_stat.ma_rssi_ele_idx[i] = 0;
23 phl_com->rssi_stat.ma_rssi_ele_cnt[i] = 0;
24 phl_com->rssi_stat.ma_rssi_ele_sum[i] = 0;
25 phl_com->rssi_stat.ma_rssi[i] = 0;
26 for (j = 0; j < PHL_RSSI_MAVG_NUM; j++)
27 phl_com->rssi_stat.ma_rssi_ele[i][j] = 0;
28 }
29 _os_spinlock_init(phl_com->drv_priv, &(phl_com->rssi_stat.lock));
30 }
31
_phl_com_deinit_rssi_stat(struct rtw_phl_com_t * phl_com)32 void _phl_com_deinit_rssi_stat(struct rtw_phl_com_t *phl_com)
33 {
34 _os_spinlock_free(phl_com->drv_priv, &(phl_com->rssi_stat.lock));
35 }
36
37 /**
38 * rtw_phl_init_ppdu_sts_para(...)
39 * Description:
40 * 1. Do not call this api after rx started.
41 * 2. PPDU Status per PKT settings
42 **/
rtw_phl_init_ppdu_sts_para(struct rtw_phl_com_t * phl_com,bool en_psts_per_pkt,bool psts_ampdu,u8 rx_fltr)43 void rtw_phl_init_ppdu_sts_para(struct rtw_phl_com_t *phl_com,
44 bool en_psts_per_pkt, bool psts_ampdu,
45 u8 rx_fltr)
46 {
47 #ifdef CONFIG_PHL_RX_PSTS_PER_PKT
48 phl_com->ppdu_sts_info.en_psts_per_pkt = en_psts_per_pkt;
49 phl_com->ppdu_sts_info.psts_ampdu = psts_ampdu;
50 #ifdef RTW_WKARD_DISABLE_PSTS_PER_PKT_DATA
51 /* Forced disable PSTS for DATA frame, to avoid unknown performance issue */
52 rx_fltr &= (~RTW_PHL_PSTS_FLTR_DATA);
53 #endif
54 phl_com->ppdu_sts_info.ppdu_sts_filter = rx_fltr;
55 #else
56 return;
57 #endif
58 }
59
_phl_com_deinit_ppdu_sts(struct rtw_phl_com_t * phl_com)60 void _phl_com_deinit_ppdu_sts(struct rtw_phl_com_t *phl_com)
61 {
62 #ifdef CONFIG_PHL_RX_PSTS_PER_PKT
63 u8 i = 0;
64 u8 j = 0;
65 for (j = 0; j < HW_BAND_MAX; j++) {
66 for (i = 0; i < PHL_MAX_PPDU_CNT; i++) {
67 if (phl_com->ppdu_sts_info.sts_ent[j][i].frames.cnt != 0) {
68 PHL_INFO("[Error] deinit_ppdu_sts : frame queue is not empty\n");
69 }
70 pq_deinit(phl_com->drv_priv,
71 &(phl_com->ppdu_sts_info.sts_ent[j][i].frames));
72 }
73 }
74 #else
75 return;
76 #endif
77 }
78
_phl_com_init_ppdu_sts(struct rtw_phl_com_t * phl_com)79 void _phl_com_init_ppdu_sts(struct rtw_phl_com_t *phl_com)
80 {
81 #ifdef CONFIG_PHL_RX_PSTS_PER_PKT
82 u8 i = 0;
83 #endif
84 u8 j = 0;
85 for (j = 0; j < HW_BAND_MAX; j++) {
86 phl_com->ppdu_sts_info.cur_rx_ppdu_cnt[j] = 0xFF;
87 }
88 #ifdef CONFIG_PHL_RX_PSTS_PER_PKT
89 /* Default enable when compile flag is set. */
90 phl_com->ppdu_sts_info.en_psts_per_pkt = true;
91 /**
92 * Filter of buffer pkt for phy status:
93 * if the correspond bit is set to 1,
94 * the pkt will be buffer till ppdu sts or next ppdu is processed.
95 **/
96 phl_com->ppdu_sts_info.ppdu_sts_filter =
97 RTW_PHL_PSTS_FLTR_MGNT | RTW_PHL_PSTS_FLTR_CTRL |
98 RTW_PHL_PSTS_FLTR_EXT_RSVD;
99
100 /* if set to false, only the first mpdu in ppdu has phy status */
101 phl_com->ppdu_sts_info.psts_ampdu = false;
102
103 phl_com->ppdu_sts_info.en_fake_psts = false;
104
105 for (j = 0; j < HW_BAND_MAX; j++) {
106 for (i = 0; i < PHL_MAX_PPDU_CNT; i++) {
107 pq_init(phl_com->drv_priv,
108 &(phl_com->ppdu_sts_info.sts_ent[j][i].frames));
109 }
110 }
111 #endif
112 #ifdef CONFIG_PHY_INFO_NTFY
113 phl_com->ppdu_sts_info.msg_aggr_cnt = 0;
114 #endif
115 }
116
phl_msg_entry(void * priv,struct phl_msg * msg)117 static void phl_msg_entry(void* priv, struct phl_msg *msg)
118 {
119 struct phl_info_t *phl_info = (struct phl_info_t *)priv;
120 u8 mdl_id = MSG_MDL_ID_FIELD(msg->msg_id);
121 u16 evt_id = MSG_EVT_ID_FIELD(msg->msg_id);
122
123 PHL_DBG("[PHL]%s, mdl_id(%d)\n", __FUNCTION__, mdl_id);
124
125 /* dispatch received PHY msg here */
126 switch(mdl_id) {
127 case PHL_MDL_PHY_MGNT:
128 phl_msg_hub_phy_mgnt_evt_hdlr(phl_info, evt_id);
129 break;
130 case PHL_MDL_RX:
131 phl_msg_hub_rx_evt_hdlr(phl_info, evt_id, msg->inbuf, msg->inlen);
132 break;
133 case PHL_MDL_BTC:
134 rtw_phl_btc_hub_msg_hdl(phl_info, msg);
135 break;
136 default:
137 break;
138 }
139 }
140
phl_register_msg_entry(struct phl_info_t * phl_info)141 static enum rtw_phl_status phl_register_msg_entry(struct phl_info_t *phl_info)
142 {
143 struct phl_msg_receiver ctx;
144 void *d = phl_to_drvpriv(phl_info);
145 u8 imr[] = {PHL_MDL_PHY_MGNT, PHL_MDL_RX, PHL_MDL_MRC, PHL_MDL_POWER_MGNT
146 , PHL_MDL_BTC};
147 _os_mem_set(d, &ctx, 0, sizeof(struct phl_msg_receiver));
148 ctx.incoming_evt_notify = phl_msg_entry;
149 ctx.priv = (void*)phl_info;
150 if( phl_msg_hub_register_recver((void*)phl_info,
151 &ctx, MSG_RECV_PHL) == RTW_PHL_STATUS_SUCCESS) {
152 /* PHL layer module should set IMR for receiving
153 desired PHY msg and handle it in phl_phy_evt_entry*/
154 phl_msg_hub_update_recver_mask((void*)phl_info, MSG_RECV_PHL,
155 imr, sizeof(imr), false);
156 return RTW_PHL_STATUS_SUCCESS;
157 }
158 else
159 return RTW_PHL_STATUS_FAILURE;
160
161 }
162
phl_deregister_msg_entry(struct phl_info_t * phl_info)163 static enum rtw_phl_status phl_deregister_msg_entry(
164 struct phl_info_t *phl_info)
165 {
166 return phl_msg_hub_deregister_recver((void*)phl_info, MSG_RECV_PHL);
167 }
168
phl_fw_init(struct phl_info_t * phl_info)169 static enum rtw_phl_status phl_fw_init(struct phl_info_t *phl_info)
170 {
171 enum rtw_phl_status phl_status = RTW_PHL_STATUS_RESOURCE;
172 struct rtw_phl_com_t *phl_com = phl_info->phl_com;
173 struct rtw_fw_info_t *fw_info = &phl_com->fw_info;
174
175 FUNCIN_WSTS(phl_status);
176
177 fw_info->rom_buff = _os_mem_alloc(phl_to_drvpriv(phl_info), RTW_MAX_FW_SIZE);
178
179 if (!fw_info->rom_buff) {
180 PHL_ERR("%s : rom buff allocate fail!!\n", __func__);
181 goto mem_alloc_fail;
182 }
183
184 fw_info->ram_buff = _os_mem_alloc(phl_to_drvpriv(phl_info), RTW_MAX_FW_SIZE);
185
186 if (!fw_info->ram_buff) {
187 PHL_ERR("%s : ram buff allocate fail!!\n", __func__);
188 goto mem_alloc_fail;
189 }
190
191 #ifdef CONFIG_PHL_REUSED_FWDL_BUF
192 fw_info->buf = _os_mem_alloc(phl_to_drvpriv(phl_info), RTW_MAX_FW_SIZE);
193
194 /* if allocating failed, fw bin files will be reading every time */
195 if (!fw_info->buf)
196 PHL_WARN("%s : buf for fw storage allocate fail!!\n", __func__);
197
198 fw_info->wow_buf = _os_mem_alloc(phl_to_drvpriv(phl_info), RTW_MAX_FW_SIZE);
199
200 /* if allocating failed, fw bin files will be reading every time */
201 if (!fw_info->wow_buf)
202 PHL_WARN("%s : wow buf for wowlan fw storage allocate fail!!\n", __func__);
203 #endif
204
205 phl_status = RTW_PHL_STATUS_SUCCESS;
206
207 FUNCOUT_WSTS(phl_status);
208
209 mem_alloc_fail:
210 return phl_status;
211 }
212
phl_fw_deinit(struct phl_info_t * phl_info)213 static void phl_fw_deinit(struct phl_info_t *phl_info)
214 {
215 struct rtw_fw_info_t *fw_info = &phl_info->phl_com->fw_info;
216
217 if (fw_info->rom_buff)
218 _os_mem_free(phl_to_drvpriv(phl_info), fw_info->rom_buff,
219 RTW_MAX_FW_SIZE);
220 if (fw_info->ram_buff)
221 _os_mem_free(phl_to_drvpriv(phl_info), fw_info->ram_buff,
222 RTW_MAX_FW_SIZE);
223
224 #ifdef CONFIG_REUSED_FWDL_BUF
225 if (fw_info->buf)
226 _os_mem_free(phl_to_drvpriv(phl_info), fw_info->buf,
227 RTW_MAX_FW_SIZE);
228 if (fw_info->wow_buf)
229 _os_mem_free(phl_to_drvpriv(phl_info), fw_info->wow_buf,
230 RTW_MAX_FW_SIZE);
231 #endif
232
233 /* allocate in rtw_hal_ld_fw_symbol */
234 if (fw_info->sym_buf)
235 _os_mem_free(phl_to_drvpriv(phl_info), fw_info->sym_buf,
236 RTW_MAX_FW_SIZE);
237 }
238 static enum rtw_phl_status
phl_register_background_module_entry(struct phl_info_t * phl_info)239 phl_register_background_module_entry(struct phl_info_t *phl_info)
240 {
241 enum rtw_phl_status phl_status = RTW_PHL_STATUS_FAILURE;
242 #ifdef CONFIG_CMD_DISP
243 /*
244 * setup struct phl_module_ops & call dispr_register_module
245 * to register background module instance.
246 * call dispr_deregister_module if you need to dynamically
247 * deregister the instance of background module.
248 */
249
250 /* 1,2,3 cmd controller section */
251
252
253 /* 41 ~ 70 mandatory background module section*/
254 #ifdef CONFIG_PHL_CMD_SER
255 phl_status = phl_register_ser_module(phl_info);
256 if (phl_status != RTW_PHL_STATUS_SUCCESS)
257 return phl_status;
258 #endif
259 #ifdef CONFIG_POWER_SAVE
260 phl_status = phl_register_ps_module(phl_info);
261 if (phl_status != RTW_PHL_STATUS_SUCCESS)
262 return phl_status;
263 #endif
264 /* 70 ~ 127 optional background module section*/
265 #ifdef CONFIG_PHL_CMD_BTC
266 phl_status = phl_register_btc_module(phl_info);
267 if (phl_status != RTW_PHL_STATUS_SUCCESS)
268 return phl_status;
269 #endif
270 phl_status = phl_register_custom_module(phl_info, HW_BAND_0);
271 if (phl_status != RTW_PHL_STATUS_SUCCESS)
272 return phl_status;
273
274 phl_status = phl_register_led_module(phl_info);
275 if (phl_status != RTW_PHL_STATUS_SUCCESS)
276 return phl_status;
277
278 phl_status = phl_register_cmd_general(phl_info);
279 if (phl_status != RTW_PHL_STATUS_SUCCESS)
280 return phl_status;
281
282 /* 10 ~ 40 protocol, wifi role section*/
283 phl_status = phl_register_mrc_module(phl_info);
284 if (phl_status != RTW_PHL_STATUS_SUCCESS)
285 return phl_status;
286
287 phl_status = phl_snd_cmd_register_module(phl_info);
288 if (phl_status != RTW_PHL_STATUS_SUCCESS)
289 return phl_status;
290 #else
291 phl_status = RTW_PHL_STATUS_SUCCESS;
292 #endif
293 return phl_status;
294 }
295
phl_com_init(void * drv_priv,struct phl_info_t * phl_info,struct rtw_ic_info * ic_info)296 static enum rtw_phl_status phl_com_init(void *drv_priv,
297 struct phl_info_t *phl_info,
298 struct rtw_ic_info *ic_info)
299 {
300 enum rtw_phl_status phl_status = RTW_PHL_STATUS_FAILURE;
301
302 phl_info->phl_com = _os_mem_alloc(drv_priv,
303 sizeof(struct rtw_phl_com_t));
304 if (phl_info->phl_com == NULL) {
305 phl_status = RTW_PHL_STATUS_RESOURCE;
306 PHL_ERR("alloc phl_com failed\n");
307 goto error_phl_com_mem;
308 }
309
310 phl_info->phl_com->phl_priv = phl_info;
311 phl_info->phl_com->drv_priv = drv_priv;
312 phl_info->phl_com->hci_type = ic_info->hci_type;
313 phl_info->phl_com->edcca_mode = RTW_EDCCA_NORMAL;
314
315 phl_sw_cap_init(phl_info->phl_com);
316
317 _os_spinlock_init(drv_priv, &phl_info->phl_com->evt_info.evt_lock);
318
319 phl_fw_init(phl_info);
320 #ifdef CONFIG_PHL_CHANNEL_INFO
321 phl_status = phl_chaninfo_init(phl_info);
322 if (phl_status)
323 goto error_phl_com_mem;
324 #endif /* CONFIG_PHL_CHANNEL_INFO */
325
326 _phl_com_init_rssi_stat(phl_info->phl_com);
327 _phl_com_init_ppdu_sts(phl_info->phl_com);
328
329 phl_status = RTW_PHL_STATUS_SUCCESS;
330 return phl_status;
331
332 error_phl_com_mem:
333 return phl_status;
334 }
335
phl_hci_init(struct phl_info_t * phl_info,struct rtw_ic_info * ic_info)336 static enum rtw_phl_status phl_hci_init(struct phl_info_t *phl_info,
337 struct rtw_ic_info *ic_info)
338 {
339 enum rtw_phl_status phl_status = RTW_PHL_STATUS_FAILURE;
340
341 phl_info->hci = _os_mem_alloc(phl_to_drvpriv(phl_info),
342 sizeof(struct hci_info_t));
343 if (phl_info->hci == NULL) {
344 phl_status = RTW_PHL_STATUS_RESOURCE;
345 goto error_hci_mem;
346 }
347 #ifdef CONFIG_USB_HCI
348 phl_info->hci->usb_bulkout_size = ic_info->usb_info.usb_bulkout_size;
349 #endif
350
351 /* init variable of hci_info_t struct */
352
353 phl_status = RTW_PHL_STATUS_SUCCESS;
354
355 error_hci_mem:
356 return phl_status;
357 }
358
phl_com_deinit(struct phl_info_t * phl_info,struct rtw_phl_com_t * phl_com)359 static void phl_com_deinit(struct phl_info_t *phl_info,
360 struct rtw_phl_com_t *phl_com)
361 {
362 void *drv_priv = phl_to_drvpriv(phl_info);
363
364 /* deinit variable or stop mechanism. */
365 if (phl_com) {
366 phl_sw_cap_deinit(phl_info->phl_com);
367 _os_spinlock_free(drv_priv, &phl_com->evt_info.evt_lock);
368 _phl_com_deinit_rssi_stat(phl_info->phl_com);
369 _phl_com_deinit_ppdu_sts(phl_info->phl_com);
370 phl_fw_deinit(phl_info);
371 #ifdef CONFIG_PHL_CHANNEL_INFO
372 phl_chaninfo_deinit(phl_info);
373 #endif /* CONFIG_PHL_CHANNEL_INFO */
374 _os_mem_free(drv_priv, phl_com, sizeof(struct rtw_phl_com_t));
375 }
376 }
377
phl_hci_deinit(struct phl_info_t * phl_info,struct hci_info_t * hci)378 static void phl_hci_deinit(struct phl_info_t *phl_info, struct hci_info_t *hci)
379 {
380
381 /* deinit variable or stop mechanism. */
382 if (hci)
383 _os_mem_free(phl_to_drvpriv(phl_info), hci,
384 sizeof(struct hci_info_t));
385 }
386
_phl_hci_ops_check(struct phl_info_t * phl_info)387 static enum rtw_phl_status _phl_hci_ops_check(struct phl_info_t *phl_info)
388 {
389 enum rtw_phl_status status = RTW_PHL_STATUS_SUCCESS;
390 struct phl_hci_trx_ops *trx_ops = phl_info->hci_trx_ops;
391
392 if (!trx_ops->hci_trx_init) {
393 phl_ops_error_msg("hci_trx_init");
394 status = RTW_PHL_STATUS_FAILURE;
395 }
396 if (!trx_ops->hci_trx_deinit) {
397 phl_ops_error_msg("hci_trx_deinit");
398 status = RTW_PHL_STATUS_FAILURE;
399 }
400 if (!trx_ops->prepare_tx) {
401 phl_ops_error_msg("prepare_tx");
402 status = RTW_PHL_STATUS_FAILURE;
403 }
404 if (!trx_ops->recycle_rx_buf) {
405 phl_ops_error_msg("recycle_rx_buf");
406 status = RTW_PHL_STATUS_FAILURE;
407 }
408 if (!trx_ops->tx) {
409 phl_ops_error_msg("tx");
410 status = RTW_PHL_STATUS_FAILURE;
411 }
412 if (!trx_ops->rx) {
413 phl_ops_error_msg("rx");
414 status = RTW_PHL_STATUS_FAILURE;
415 }
416 if (!trx_ops->trx_cfg) {
417 phl_ops_error_msg("trx_cfg");
418 status = RTW_PHL_STATUS_FAILURE;
419 }
420 if (!trx_ops->pltfm_tx) {
421 phl_ops_error_msg("pltfm_tx");
422 status = RTW_PHL_STATUS_FAILURE;
423 }
424 if (!trx_ops->alloc_h2c_pkt_buf) {
425 phl_ops_error_msg("alloc_h2c_pkt_buf");
426 status = RTW_PHL_STATUS_FAILURE;
427 }
428 if (!trx_ops->free_h2c_pkt_buf) {
429 phl_ops_error_msg("free_h2c_pkt_buf");
430 status = RTW_PHL_STATUS_FAILURE;
431 }
432 if (!trx_ops->trx_reset) {
433 phl_ops_error_msg("trx_reset");
434 status = RTW_PHL_STATUS_FAILURE;
435 }
436 if (!trx_ops->trx_resume) {
437 phl_ops_error_msg("trx_resume");
438 status = RTW_PHL_STATUS_FAILURE;
439 }
440 if (!trx_ops->req_tx_stop) {
441 phl_ops_error_msg("req_tx_stop");
442 status = RTW_PHL_STATUS_FAILURE;
443 }
444 if (!trx_ops->req_rx_stop) {
445 phl_ops_error_msg("req_rx_stop");
446 status = RTW_PHL_STATUS_FAILURE;
447 }
448 if (!trx_ops->is_tx_pause) {
449 phl_ops_error_msg("is_tx_pause");
450 status = RTW_PHL_STATUS_FAILURE;
451 }
452 if (!trx_ops->is_rx_pause) {
453 phl_ops_error_msg("is_rx_pause");
454 status = RTW_PHL_STATUS_FAILURE;
455 }
456 if (!trx_ops->get_txbd_buf) {
457 phl_ops_error_msg("get_txbd_buf");
458 status = RTW_PHL_STATUS_FAILURE;
459 }
460 if (!trx_ops->get_rxbd_buf) {
461 phl_ops_error_msg("get_rxbd_buf");
462 status = RTW_PHL_STATUS_FAILURE;
463 }
464 if (!trx_ops->recycle_rx_pkt) {
465 phl_ops_error_msg("recycle_rx_pkt");
466 status = RTW_PHL_STATUS_FAILURE;
467 }
468 if (!trx_ops->register_trx_hdlr) {
469 phl_ops_error_msg("register_trx_hdlr");
470 status = RTW_PHL_STATUS_FAILURE;
471 }
472 if (!trx_ops->rx_handle_normal) {
473 phl_ops_error_msg("rx_handle_normal");
474 status = RTW_PHL_STATUS_FAILURE;
475 }
476 if (!trx_ops->tx_watchdog) {
477 phl_ops_error_msg("tx_watchdog");
478 status = RTW_PHL_STATUS_FAILURE;
479 }
480
481 #ifdef CONFIG_PCI_HCI
482 if (!trx_ops->recycle_busy_wd) {
483 phl_ops_error_msg("recycle_busy_wd");
484 status = RTW_PHL_STATUS_FAILURE;
485 }
486 if (!trx_ops->recycle_busy_h2c) {
487 phl_ops_error_msg("recycle_busy_h2c");
488 status = RTW_PHL_STATUS_FAILURE;
489 }
490 #endif
491
492 #ifdef CONFIG_USB_HCI
493 if (!trx_ops->pend_rxbuf) {
494 phl_ops_error_msg("pend_rxbuf");
495 status = RTW_PHL_STATUS_FAILURE;
496 }
497 if (!trx_ops->recycle_tx_buf) {
498 phl_ops_error_msg("recycle_tx_buf");
499 status = RTW_PHL_STATUS_FAILURE;
500 }
501 #endif
502
503 return status;
504 }
505
phl_set_hci_ops(struct phl_info_t * phl_info)506 static enum rtw_phl_status phl_set_hci_ops(struct phl_info_t *phl_info)
507 {
508 #ifdef CONFIG_PCI_HCI
509 if (phl_get_hci_type(phl_info->phl_com) == RTW_HCI_PCIE)
510 phl_hook_trx_ops_pci(phl_info);
511 #endif
512
513 #ifdef CONFIG_USB_HCI
514 if (phl_get_hci_type(phl_info->phl_com) == RTW_HCI_USB)
515 phl_hook_trx_ops_usb(phl_info);
516 #endif
517
518 #ifdef CONFIG_SDIO_HCI
519 if (phl_get_hci_type(phl_info->phl_com) == RTW_HCI_SDIO)
520 phl_hook_trx_ops_sdio(phl_info);
521 #endif
522
523 return _phl_hci_ops_check(phl_info);
524 }
525
526 #ifdef CONFIG_FSM
phl_cmd_init(struct phl_info_t * phl_info)527 static enum rtw_phl_status phl_cmd_init(struct phl_info_t *phl_info)
528 {
529 if (phl_info->cmd_fsm != NULL)
530 return RTW_PHL_STATUS_FAILURE;
531
532 phl_info->cmd_fsm = phl_cmd_new_fsm(phl_info->fsm_root, phl_info);
533 if (phl_info->cmd_fsm == NULL)
534 return RTW_PHL_STATUS_FAILURE;
535
536 if (phl_info->cmd_obj != NULL)
537 goto obj_fail;
538
539 phl_info->cmd_obj = phl_cmd_new_obj(phl_info->cmd_fsm, phl_info);
540 if (phl_info->cmd_obj == NULL)
541 goto obj_fail;
542
543 return RTW_PHL_STATUS_SUCCESS;
544
545 obj_fail:
546 phl_fsm_deinit_fsm(phl_info->cmd_fsm);
547 phl_info->cmd_fsm = NULL;
548 return RTW_PHL_STATUS_FAILURE;
549 }
550
phl_cmd_deinit(struct phl_info_t * phl_info)551 static void phl_cmd_deinit(struct phl_info_t *phl_info)
552 {
553 phl_cmd_destory_obj(phl_info->cmd_obj);
554 phl_info->cmd_obj = NULL;
555 phl_cmd_destory_fsm(phl_info->cmd_fsm);
556 phl_info->cmd_fsm = NULL;
557 }
558
phl_ser_init(struct phl_info_t * phl_info)559 static enum rtw_phl_status phl_ser_init(struct phl_info_t *phl_info)
560 {
561 if (phl_info->ser_fsm != NULL)
562 return RTW_PHL_STATUS_FAILURE;
563
564 phl_info->ser_fsm = phl_ser_new_fsm(phl_info->fsm_root, phl_info);
565 if (phl_info->ser_fsm == NULL)
566 return RTW_PHL_STATUS_FAILURE;
567
568 if (phl_info->ser_obj != NULL)
569 goto obj_fail;
570
571 phl_info->ser_obj = phl_ser_new_obj(phl_info->ser_fsm, phl_info);
572 if (phl_info->ser_obj == NULL)
573 goto obj_fail;
574
575 return RTW_PHL_STATUS_SUCCESS;
576
577 obj_fail:
578 phl_ser_destory_fsm(phl_info->ser_fsm);
579 phl_info->ser_fsm = NULL;
580 return RTW_PHL_STATUS_FAILURE;
581 }
582
phl_ser_deinit(struct phl_info_t * phl_info)583 static void phl_ser_deinit(struct phl_info_t *phl_info)
584 {
585 phl_ser_destory_obj(phl_info->ser_obj);
586 phl_info->ser_obj = NULL;
587
588 phl_ser_destory_fsm(phl_info->ser_fsm);
589 phl_info->ser_fsm = NULL;
590 }
591
phl_btc_init(struct phl_info_t * phl_info)592 static enum rtw_phl_status phl_btc_init(struct phl_info_t *phl_info)
593 {
594 if (phl_info->btc_fsm != NULL)
595 return RTW_PHL_STATUS_FAILURE;
596
597 phl_info->btc_fsm = phl_btc_new_fsm(phl_info->fsm_root, phl_info);
598 if (phl_info->btc_fsm == NULL)
599 return RTW_PHL_STATUS_FAILURE;
600
601 phl_info->btc_obj = phl_btc_new_obj(phl_info->btc_fsm, phl_info);
602 if (phl_info->btc_obj == NULL)
603 goto obj_fail;
604
605 return RTW_PHL_STATUS_SUCCESS;
606
607 obj_fail:
608 phl_fsm_deinit_fsm(phl_info->btc_fsm);
609 phl_info->btc_fsm = NULL;
610 return RTW_PHL_STATUS_FAILURE;
611
612 }
613
phl_btc_deinit(struct phl_info_t * phl_info)614 static void phl_btc_deinit(struct phl_info_t *phl_info)
615 {
616 phl_btc_destory_obj(phl_info->btc_obj);
617 phl_info->btc_obj = NULL;
618
619 phl_btc_destory_fsm(phl_info->btc_fsm);
620 phl_info->btc_fsm = NULL;
621 }
622
phl_scan_init(struct phl_info_t * phl_info)623 static enum rtw_phl_status phl_scan_init(struct phl_info_t *phl_info)
624 {
625 if (phl_info->scan_fsm != NULL)
626 return RTW_PHL_STATUS_FAILURE;
627
628 phl_info->scan_fsm = phl_scan_new_fsm(phl_info->fsm_root, phl_info);
629 if (phl_info->scan_fsm == NULL)
630 return RTW_PHL_STATUS_FAILURE;
631
632 if (phl_info->scan_obj != NULL)
633 goto obj_fail;
634
635 phl_info->scan_obj = phl_scan_new_obj(phl_info->scan_fsm, phl_info);
636 if (phl_info->scan_obj == NULL)
637 goto obj_fail;
638
639 return RTW_PHL_STATUS_SUCCESS;
640
641 obj_fail:
642 phl_fsm_deinit_fsm(phl_info->scan_fsm);
643 phl_info->scan_fsm = NULL;
644 return RTW_PHL_STATUS_FAILURE;
645 }
646
phl_scan_deinit(struct phl_info_t * phl_info)647 static void phl_scan_deinit(struct phl_info_t *phl_info)
648 {
649 phl_scan_destory_obj(phl_info->scan_obj);
650 phl_info->scan_obj = NULL;
651 phl_scan_destory_fsm(phl_info->scan_fsm);
652 phl_info->scan_fsm = NULL;
653 }
654
phl_sound_init(struct phl_info_t * phl_info)655 static enum rtw_phl_status phl_sound_init(struct phl_info_t *phl_info)
656 {
657 enum rtw_phl_status pstatus = RTW_PHL_STATUS_SUCCESS;
658
659 if (phl_info->snd_fsm!= NULL)
660 return RTW_PHL_STATUS_FAILURE;
661
662 phl_info->snd_fsm = phl_sound_new_fsm(phl_info->fsm_root, phl_info);
663 if (phl_info->snd_fsm == NULL)
664 return RTW_PHL_STATUS_FAILURE;
665
666 pstatus = phl_snd_new_obj(phl_info->snd_fsm, phl_info);
667 if (pstatus != RTW_PHL_STATUS_SUCCESS)
668 goto obj_fail;
669
670 return pstatus;
671
672 obj_fail:
673 phl_fsm_deinit_fsm(phl_info->snd_fsm);
674 phl_info->snd_fsm = NULL;
675 return RTW_PHL_STATUS_FAILURE;
676 }
677
phl_sound_deinit(struct phl_info_t * phl_info)678 static void phl_sound_deinit(struct phl_info_t *phl_info)
679 {
680 phl_snd_destory_obj(phl_info->snd_obj);
681 phl_info->snd_obj = NULL;
682 phl_snd_destory_fsm(phl_info->snd_fsm);
683 phl_info->snd_fsm = NULL;
684 }
685
phl_fsm_init(struct phl_info_t * phl_info)686 static enum rtw_phl_status phl_fsm_init(struct phl_info_t *phl_info)
687 {
688 if (phl_info->fsm_root != NULL)
689 return RTW_PHL_STATUS_FAILURE;
690
691 /* allocate memory for fsm to do version control */
692 phl_info->fsm_root = phl_fsm_init_root(phl_info);
693 if (phl_info->fsm_root == NULL)
694 return RTW_PHL_STATUS_FAILURE;
695
696 return RTW_PHL_STATUS_SUCCESS;
697 }
698
phl_fsm_deinit(struct phl_info_t * phl_info)699 static void phl_fsm_deinit(struct phl_info_t *phl_info)
700 {
701 /* free memory for fsm */
702 phl_fsm_deinit_root(phl_info->fsm_root);
703 phl_info->fsm_root = NULL;
704 }
705
phl_fsm_module_init(struct phl_info_t * phl_info)706 static enum rtw_phl_status phl_fsm_module_init(struct phl_info_t *phl_info)
707 {
708 enum rtw_phl_status phl_status = RTW_PHL_STATUS_SUCCESS;
709
710 phl_status = phl_cmd_init(phl_info);
711 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
712 PHL_ERR("phl_cmd_init failed\n");
713 goto cmd_fail;
714 }
715
716 phl_status = phl_ser_init(phl_info);
717 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
718 PHL_ERR("phl_ser_init failed\n");
719 goto ser_fail;
720 }
721
722 phl_status = phl_btc_init(phl_info);
723 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
724 PHL_ERR("phl_btc_init failed\n");
725 goto btc_fail;
726 }
727
728 phl_status = phl_scan_init(phl_info);
729 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
730 PHL_ERR("phl_scan_init failed\n");
731 goto scan_fail;
732 }
733
734 phl_status = phl_sound_init(phl_info);
735 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
736 PHL_ERR("phl_sound_init failed\n");
737 goto sound_fail;
738 }
739
740 return phl_status;
741
742 sound_fail:
743 phl_scan_deinit(phl_info);
744 scan_fail:
745 phl_btc_deinit(phl_info);
746 btc_fail:
747 phl_ser_deinit(phl_info);
748 ser_fail:
749 phl_cmd_deinit(phl_info);
750 cmd_fail:
751 return phl_status;
752 }
753
phl_fsm_module_deinit(struct phl_info_t * phl_info)754 static void phl_fsm_module_deinit(struct phl_info_t *phl_info)
755 {
756 phl_sound_deinit(phl_info);
757 phl_scan_deinit(phl_info);
758 phl_btc_deinit(phl_info);
759 phl_ser_deinit(phl_info);
760 phl_cmd_deinit(phl_info);
761 }
762
phl_fsm_start(struct phl_info_t * phl_info)763 static enum rtw_phl_status phl_fsm_start(struct phl_info_t *phl_info)
764 {
765 return phl_fsm_start_root(phl_info->fsm_root);
766 }
767
phl_fsm_stop(struct phl_info_t * phl_info)768 static enum rtw_phl_status phl_fsm_stop(struct phl_info_t *phl_info)
769 {
770 return phl_fsm_stop_root(phl_info->fsm_root);
771 }
772
phl_fsm_module_start(struct phl_info_t * phl_info)773 static enum rtw_phl_status phl_fsm_module_start(struct phl_info_t *phl_info)
774 {
775 enum rtw_phl_status phl_status = RTW_PHL_STATUS_SUCCESS;
776
777 phl_status = phl_fsm_start_fsm(phl_info->ser_fsm);
778 if (phl_status != RTW_PHL_STATUS_SUCCESS)
779 goto ser_fail;
780
781 phl_status = phl_btc_start(phl_info->btc_obj);
782 if (phl_status != RTW_PHL_STATUS_SUCCESS)
783 goto btc_fail;
784
785 phl_status = phl_fsm_start_fsm(phl_info->scan_fsm);
786 if (phl_status != RTW_PHL_STATUS_SUCCESS)
787 goto scan_fail;
788
789 phl_status = phl_cmd_start(phl_info->cmd_obj);
790 if (phl_status != RTW_PHL_STATUS_SUCCESS)
791 goto cmd_fail;
792
793 phl_status = phl_fsm_start_fsm(phl_info->snd_fsm);
794 if (phl_status != RTW_PHL_STATUS_SUCCESS)
795 goto snd_fail;
796
797 return phl_status;
798
799 snd_fail:
800 phl_fsm_stop_fsm(phl_info->cmd_fsm);
801 phl_fsm_stop_fsm(phl_info->scan_fsm);
802 scan_fail:
803 phl_fsm_stop_fsm(phl_info->btc_fsm);
804 btc_fail:
805 phl_fsm_stop_fsm(phl_info->ser_fsm);
806 ser_fail:
807 phl_fsm_cmd_stop(phl_info);
808 cmd_fail:
809 return phl_status;
810 }
811
phl_fsm_module_stop(struct phl_info_t * phl_info)812 static enum rtw_phl_status phl_fsm_module_stop(struct phl_info_t *phl_info)
813 {
814 enum rtw_phl_status phl_status = RTW_PHL_STATUS_SUCCESS;
815
816 phl_fsm_stop_fsm(phl_info->snd_fsm);
817 phl_fsm_stop_fsm(phl_info->scan_fsm);
818 phl_fsm_stop_fsm(phl_info->btc_fsm);
819 phl_fsm_stop_fsm(phl_info->ser_fsm);
820 phl_fsm_cmd_stop(phl_info);
821
822 return phl_status;
823 }
824
825 #endif /*CONFIG_FSM*/
phl_module_init(struct phl_info_t * phl_info)826 static enum rtw_phl_status phl_module_init(struct phl_info_t *phl_info)
827 {
828 enum rtw_phl_status phl_status = RTW_PHL_STATUS_SUCCESS;
829
830 phl_status = phl_msg_hub_init(phl_info);
831 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
832 PHL_ERR("phl_msg_hub_init failed\n");
833 goto msg_hub_fail;
834 }
835
836 phl_status = phl_wow_mdl_init(phl_info);
837 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
838 PHL_ERR("phl_wow_mdl_init failed\n");
839 goto wow_init_fail;
840 }
841
842 phl_status = phl_pkt_ofld_init(phl_info);
843 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
844 PHL_ERR("phl_pkt_ofld_init failed\n");
845 goto pkt_ofld_init_fail;
846 }
847
848 if (!phl_test_module_init(phl_info)) {
849 PHL_ERR("phl_test_module_init failed\n");
850 phl_status = RTW_PHL_STATUS_FAILURE;
851 goto error_test_module_init;
852 }
853
854 phl_status = phl_p2pps_init(phl_info);
855 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
856 PHL_ERR("phl_p2pps_init failed\n");
857 goto error_p2pps_init;
858 }
859
860 phl_status = phl_disp_eng_init(phl_info, HW_BAND_MAX);
861 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
862 PHL_ERR("phl_disp_eng_init failed\n");
863 goto error_disp_eng_init;
864 }
865
866 phl_status = phl_register_background_module_entry(phl_info);
867 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
868 PHL_ERR("phl_register_disp_eng_module_entry failed\n");
869 goto error_disp_eng_reg_init;
870 }
871
872 phl_status = phl_ecsa_ctrl_init(phl_info);
873 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
874 PHL_ERR("phl_ecsa_ctrl_init failed\n");
875 goto error_ecsa_ctrl_init;
876 }
877 return phl_status;
878
879 error_ecsa_ctrl_init:
880 error_disp_eng_reg_init:
881 phl_disp_eng_deinit(phl_info);
882 error_disp_eng_init:
883 phl_p2pps_deinit(phl_info);
884 error_p2pps_init:
885 phl_test_module_deinit(phl_info->phl_com);
886 error_test_module_init:
887 phl_pkt_ofld_deinit(phl_info);
888 pkt_ofld_init_fail:
889 phl_wow_mdl_deinit(phl_info);
890 wow_init_fail:
891 phl_msg_hub_deinit(phl_info);
892 msg_hub_fail:
893 return phl_status;
894 }
895
phl_module_deinit(struct phl_info_t * phl_info)896 static void phl_module_deinit(struct phl_info_t *phl_info)
897 {
898 phl_ecsa_ctrl_deinit(phl_info);
899 phl_disp_eng_deinit(phl_info);
900 phl_test_module_deinit(phl_info->phl_com);
901 phl_pkt_ofld_deinit(phl_info);
902 phl_wow_mdl_deinit(phl_info);
903 phl_msg_hub_deinit(phl_info);
904 phl_p2pps_deinit(phl_info);
905 }
906
phl_module_start(struct phl_info_t * phl_info)907 static enum rtw_phl_status phl_module_start(struct phl_info_t *phl_info)
908 {
909 enum rtw_phl_status phl_status = RTW_PHL_STATUS_SUCCESS;
910
911 if (!phl_test_module_start(phl_info->phl_com)) {
912 PHL_ERR("phl_test_module_start failed\n");
913 phl_status = RTW_PHL_STATUS_FAILURE;
914 goto error_test_mdl_start;
915 }
916
917 phl_status = phl_disp_eng_start(phl_info);
918 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
919 PHL_ERR("phl_disp_eng_start failed\n");
920 goto error_disp_eng_start;
921 }
922
923 if(phl_info->msg_hub) {
924 phl_msg_hub_start(phl_info);
925 phl_register_msg_entry(phl_info);
926 }
927
928 return phl_status;
929
930 error_disp_eng_start:
931 phl_test_module_stop(phl_info->phl_com);
932 error_test_mdl_start:
933 return phl_status;
934 }
935
phl_module_stop(struct phl_info_t * phl_info)936 static enum rtw_phl_status phl_module_stop(struct phl_info_t *phl_info)
937 {
938 enum rtw_phl_status phl_status = RTW_PHL_STATUS_SUCCESS;
939
940 phl_status = phl_cmd_enqueue(phl_info, HW_BAND_0, MSG_EVT_MDL_CHECK_STOP,
941 NULL, 0, NULL, PHL_CMD_WAIT, 500);
942
943 phl_disp_eng_stop(phl_info);
944 phl_test_module_stop(phl_info->phl_com);
945
946 if(phl_info->msg_hub) {
947 phl_deregister_msg_entry(phl_info);
948 phl_msg_hub_stop(phl_info);
949 }
950
951 return phl_status;
952 }
953
phl_var_init(struct phl_info_t * phl_info)954 static enum rtw_phl_status phl_var_init(struct phl_info_t *phl_info)
955 {
956 return RTW_PHL_STATUS_SUCCESS;
957 }
958
phl_var_deinit(struct phl_info_t * phl_info)959 static void phl_var_deinit(struct phl_info_t *phl_info)
960 {
961
962 }
963
rtw_phl_get_com(void * phl)964 struct rtw_phl_com_t *rtw_phl_get_com(void *phl)
965 {
966 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
967
968 return phl_info->phl_com;
969 }
970
phl_regulation_init(void * drv_priv,void * phl)971 static void phl_regulation_init(void *drv_priv, void *phl)
972 {
973 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
974 struct rtw_regulation *rg = NULL;
975
976 if (!drv_priv || !phl)
977 return;
978
979 rg = &phl_info->regulation;
980
981 _os_spinlock_init(drv_priv, &rg->lock);
982 rg->init = 1;
983 rg->domain.code = INVALID_DOMAIN_CODE;
984 rg->domain_6g.code = INVALID_DOMAIN_CODE;
985 rg->tpo = TPO_NA;
986 }
987
phl_regulation_deinit(void * drv_priv,void * phl)988 static void phl_regulation_deinit(void *drv_priv, void *phl)
989 {
990 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
991 struct rtw_regulation *rg = NULL;
992
993 if (!drv_priv || !phl)
994 return;
995
996 rg = &phl_info->regulation;
997
998 _os_spinlock_free(drv_priv, &rg->lock);
999 }
1000
rtw_phl_init(void * drv_priv,void ** phl,struct rtw_ic_info * ic_info)1001 enum rtw_phl_status rtw_phl_init(void *drv_priv, void **phl,
1002 struct rtw_ic_info *ic_info)
1003 {
1004 struct phl_info_t *phl_info = NULL;
1005 enum rtw_phl_status phl_status = RTW_PHL_STATUS_FAILURE;
1006 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
1007
1008 FUNCIN();
1009 phl_info = _os_mem_alloc(drv_priv, sizeof(struct phl_info_t));
1010 if (phl_info == NULL) {
1011 phl_status = RTW_PHL_STATUS_RESOURCE;
1012 PHL_ERR("alloc phl_info failed\n");
1013 goto error_phl_mem;
1014 }
1015 _os_mem_set(drv_priv, phl_info, 0, sizeof(struct phl_info_t));
1016 *phl = phl_info;
1017
1018 phl_regulation_init(drv_priv, phl_info);
1019
1020 phl_status = phl_com_init(drv_priv, phl_info, ic_info);
1021 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
1022 phl_status = RTW_PHL_STATUS_RESOURCE;
1023 PHL_ERR("alloc phl_com failed\n");
1024 goto error_phl_com_mem;
1025 }
1026
1027 phl_status = phl_hci_init(phl_info, ic_info);
1028 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
1029 PHL_ERR("phl_hci_init failed\n");
1030 goto error_hci_init;
1031 }
1032
1033 phl_status = phl_set_hci_ops(phl_info);
1034 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
1035 PHL_ERR("phl_set_hci_ops failed\n");
1036 goto error_set_hci_ops;
1037 }
1038 #ifdef CONFIG_FSM
1039 phl_status = phl_fsm_init(phl_info);
1040 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
1041 PHL_ERR("phl_fsm_init failed\n");
1042 goto error_fsm_init;
1043 }
1044
1045 /* init FSM modules */
1046 phl_status = phl_fsm_module_init(phl_info);
1047 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
1048 PHL_ERR("phl_fsm_module_init failed\n");
1049 goto error_fsm_module_init;
1050 }
1051 #endif
1052 phl_status = phl_twt_init(*phl);
1053 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
1054 PHL_ERR("phl_twt_init failed\n");
1055 goto error_phl_twt_init;
1056 }
1057 hal_status = rtw_hal_init(drv_priv, phl_info->phl_com,
1058 &(phl_info->hal), ic_info->ic_id);
1059 if ((hal_status != RTW_HAL_STATUS_SUCCESS) || (phl_info->hal == NULL)) {
1060 phl_status = RTW_PHL_STATUS_HAL_INIT_FAILURE;
1061 PHL_ERR("rtw_hal_init failed status(%d),phl_info->hal(%p)\n",
1062 hal_status, phl_info->hal);
1063 goto error_hal_init;
1064 }
1065
1066 /*send bus info to hal*/
1067 rtw_hal_hci_cfg(phl_info->phl_com, phl_info->hal, ic_info);
1068
1069 /*get hw capability from mac/bb/rf/btc/efuse/fw-defeature-rpt*/
1070 hal_status = rtw_hal_read_chip_info(phl_info->phl_com, phl_info->hal);
1071 if (hal_status != RTW_HAL_STATUS_SUCCESS) {
1072 phl_status = RTW_PHL_STATUS_HAL_INIT_FAILURE;
1073 PHL_ERR("rtw_hal_read_chip_info failed\n");
1074 goto error_hal_read_chip_info;
1075 }
1076
1077 hal_status = rtw_hal_var_init(phl_info->phl_com, phl_info->hal);
1078 if (hal_status != RTW_HAL_STATUS_SUCCESS) {
1079 phl_status = RTW_PHL_STATUS_HAL_INIT_FAILURE;
1080 PHL_ERR("rtw_hal_var_init failed\n");
1081 goto error_hal_var_init;
1082 }
1083
1084 phl_status = phl_var_init(phl_info);
1085 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
1086 PHL_ERR("phl_var_init failed\n");
1087 goto error_phl_var_init;
1088 }
1089
1090 /* init mr_ctrl, wifi_role[] */
1091 phl_status = phl_mr_ctrl_init(phl_info);
1092 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
1093 PHL_ERR("phl_mr_ctrl_init failed\n");
1094 goto error_wifi_role_ctrl_init;
1095 }
1096
1097 /* init modules */
1098 phl_status = phl_module_init(phl_info);
1099 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
1100 PHL_ERR("phl_module_init failed\n");
1101 goto error_module_init;
1102 }
1103
1104 /* init macid_ctrl , stainfo_ctrl*/
1105 /* init after get hw cap - macid number*/
1106 phl_status = phl_macid_ctrl_init(phl_info);
1107 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
1108 PHL_ERR("phl_macid_ctrl_init failed\n");
1109 goto error_macid_ctrl_init;
1110 }
1111
1112 /*init after hal_init - hal_sta_info*/
1113 phl_status = phl_stainfo_ctrl_init(phl_info);
1114 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
1115 PHL_ERR("phl_stainfo_ctrl_init failed\n");
1116 goto error_stainfo_ctrl_init;
1117 }
1118 FUNCOUT();
1119
1120 return phl_status;
1121
1122 error_stainfo_ctrl_init:
1123 phl_macid_ctrl_deinit(phl_info);
1124 error_macid_ctrl_init:
1125 phl_module_deinit(phl_info);
1126 error_module_init:
1127 phl_mr_ctrl_deinit(phl_info);
1128 error_wifi_role_ctrl_init:
1129 phl_var_deinit(phl_info);
1130 error_phl_var_init:
1131 error_hal_var_init:
1132 error_hal_read_chip_info:
1133 rtw_hal_deinit(phl_info->phl_com, phl_info->hal);
1134 error_hal_init:
1135 error_phl_twt_init:
1136 phl_twt_deinit(phl);
1137 #ifdef CONFIG_FSM
1138 phl_fsm_module_deinit(phl_info);
1139 error_fsm_module_init:
1140 phl_fsm_deinit(phl_info);
1141 error_fsm_init:
1142 /* Do nothing */
1143 #endif
1144 error_set_hci_ops:
1145 phl_hci_deinit(phl_info, phl_info->hci);
1146 error_hci_init:
1147 phl_com_deinit(phl_info, phl_info->phl_com);
1148 error_phl_com_mem:
1149 if (phl_info) {
1150 phl_regulation_deinit(drv_priv, phl_info);
1151 _os_mem_free(drv_priv, phl_info, sizeof(struct phl_info_t));
1152 *phl = phl_info = NULL;
1153 }
1154 error_phl_mem:
1155 return phl_status;
1156 }
1157
rtw_phl_deinit(void * phl)1158 void rtw_phl_deinit(void *phl)
1159 {
1160 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1161 void *drv_priv = phl_to_drvpriv(phl_info);
1162
1163 if (phl_info) {
1164 phl_twt_deinit(phl);
1165 phl_stainfo_ctrl_deinie(phl_info);
1166 phl_macid_ctrl_deinit(phl_info);
1167 /*deinit mr_ctrl, wifi_role[]*/
1168 phl_module_deinit(phl_info);
1169 phl_mr_ctrl_deinit(phl_info);
1170 rtw_hal_deinit(phl_info->phl_com, phl_info->hal);
1171 phl_var_deinit(phl_info);
1172 #ifdef CONFIG_FSM
1173 phl_fsm_module_deinit(phl_info);
1174 phl_fsm_deinit(phl_info);
1175 #endif
1176 phl_hci_deinit(phl_info, phl_info->hci);
1177 phl_com_deinit(phl_info, phl_info->phl_com);
1178 phl_regulation_deinit(drv_priv, phl_info);
1179 _os_mem_free(drv_priv, phl_info,
1180 sizeof(struct phl_info_t));
1181 }
1182 }
1183
1184 enum rtw_phl_status
rtw_phl_trx_alloc(void * phl)1185 rtw_phl_trx_alloc(void *phl)
1186 {
1187 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1188 enum rtw_phl_status phl_status = RTW_PHL_STATUS_FAILURE;
1189
1190 phl_status = phl_datapath_init(phl_info);
1191 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
1192 PHL_ERR("phl_datapath_init failed\n");
1193 goto error_datapath;
1194 }
1195
1196 phl_status = phl_trx_test_init(phl);
1197 if (phl_status != RTW_PHL_STATUS_SUCCESS) {
1198 PHL_ERR("phl_trx_test_init failed\n");
1199 goto error_trx_test;
1200 }
1201
1202 return phl_status;
1203
1204 error_trx_test:
1205 phl_datapath_deinit(phl_info);
1206 error_datapath:
1207 return phl_status;
1208 }
1209
1210 void
rtw_phl_trx_free_handler(void * phl)1211 rtw_phl_trx_free_handler(void *phl)
1212 {
1213 phl_trx_free_handler(phl);
1214 }
1215
1216 void
rtw_phl_trx_free_sw_rsc(void * phl)1217 rtw_phl_trx_free_sw_rsc(void *phl)
1218 {
1219 phl_trx_free_sw_rsc(phl);
1220 phl_trx_test_deinit(phl);
1221 }
1222
1223 void
rtw_phl_trx_free(void * phl)1224 rtw_phl_trx_free(void *phl)
1225 {
1226 rtw_phl_trx_free_handler(phl);
1227 rtw_phl_trx_free_sw_rsc(phl);
1228 }
1229
1230
rtw_phl_is_init_completed(void * phl)1231 bool rtw_phl_is_init_completed(void *phl)
1232 {
1233 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1234
1235 return rtw_hal_is_inited(phl_info->phl_com, phl_info->hal);
1236 }
1237
1238 #ifdef RTW_PHL_BCN
1239
1240 enum rtw_phl_status
phl_add_beacon(struct phl_info_t * phl_info,struct rtw_bcn_info_cmn * bcn_cmn)1241 phl_add_beacon(struct phl_info_t *phl_info, struct rtw_bcn_info_cmn *bcn_cmn)
1242 {
1243 struct rtw_phl_com_t *phl_com = phl_info->phl_com;
1244 void *hal = phl_info->hal;
1245
1246 if(rtw_hal_add_beacon(phl_com, hal, bcn_cmn) == RTW_HAL_STATUS_SUCCESS)
1247 return RTW_PHL_STATUS_SUCCESS;
1248 else
1249 return RTW_PHL_STATUS_FAILURE;
1250 }
1251
phl_update_beacon(struct phl_info_t * phl_info,u8 bcn_id)1252 enum rtw_phl_status phl_update_beacon(struct phl_info_t *phl_info, u8 bcn_id)
1253 {
1254 struct rtw_phl_com_t *phl_com = phl_info->phl_com;
1255 void *hal = phl_info->hal;
1256
1257 if(rtw_hal_update_beacon(phl_com, hal, bcn_id) == RTW_HAL_STATUS_SUCCESS)
1258 return RTW_PHL_STATUS_SUCCESS;
1259 else
1260 return RTW_PHL_STATUS_FAILURE;
1261 }
1262
rtw_phl_free_bcn_entry(void * phl,struct rtw_wifi_role_t * wrole)1263 enum rtw_phl_status rtw_phl_free_bcn_entry(void *phl, struct rtw_wifi_role_t *wrole)
1264 {
1265 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1266 struct rtw_phl_com_t *phl_com = phl_info->phl_com;
1267 struct rtw_bcn_info_cmn *bcn_cmn = &wrole->bcn_cmn;
1268 void *hal = phl_info->hal;
1269 enum rtw_phl_status phl_status = RTW_PHL_STATUS_SUCCESS;
1270
1271 if (bcn_cmn->bcn_added == 1) {
1272 if (rtw_hal_free_beacon(phl_com, hal, bcn_cmn->bcn_id) == RTW_HAL_STATUS_SUCCESS) {
1273 bcn_cmn->bcn_added = 0;
1274 phl_status = RTW_PHL_STATUS_SUCCESS;
1275 } else {
1276 phl_status = RTW_PHL_STATUS_FAILURE;
1277 }
1278 }
1279
1280 return phl_status;
1281 }
1282
1283 enum rtw_phl_status
phl_beacon_stop(struct phl_info_t * phl_info,struct rtw_wifi_role_t * wrole,u8 stop)1284 phl_beacon_stop(struct phl_info_t *phl_info, struct rtw_wifi_role_t *wrole, u8 stop)
1285 {
1286 enum rtw_phl_status pstatus = RTW_PHL_STATUS_SUCCESS;
1287 enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
1288
1289 hstatus = rtw_hal_beacon_stop(phl_info->hal, wrole, stop);
1290 if (hstatus != RTW_HAL_STATUS_SUCCESS)
1291 pstatus = RTW_PHL_STATUS_FAILURE;
1292
1293 return pstatus;
1294 }
1295
1296 enum rtw_phl_status
phl_issue_beacon(struct phl_info_t * phl_info,struct rtw_bcn_info_cmn * bcn_cmn)1297 phl_issue_beacon(struct phl_info_t *phl_info, struct rtw_bcn_info_cmn *bcn_cmn)
1298 {
1299 struct rtw_phl_com_t *phl_com = phl_info->phl_com;
1300 struct rtw_bcn_info_cmn *wrole_bcn_cmn;
1301 struct rtw_wifi_role_t *wifi_role;
1302 void *drv = phl_com->drv_priv;
1303 u8 bcn_id, role_idx, bcn_added;
1304
1305 role_idx = bcn_cmn->role_idx;
1306 if (role_idx > MAX_WIFI_ROLE_NUMBER) {
1307 PHL_ERR("%s: role idx err(%d)\n", __func__, role_idx);
1308 return RTW_PHL_STATUS_FAILURE;
1309 }
1310
1311 wifi_role = &phl_com->wifi_roles[role_idx];
1312 wrole_bcn_cmn = &wifi_role->bcn_cmn;
1313 bcn_added = wrole_bcn_cmn->bcn_added;
1314 _os_mem_cpy(drv, wrole_bcn_cmn, bcn_cmn, sizeof(struct rtw_bcn_info_cmn));
1315
1316 /* BCN add */
1317 if (!bcn_added) {
1318 if(phl_add_beacon(phl_info, wrole_bcn_cmn) == RTW_PHL_STATUS_SUCCESS) {
1319 wrole_bcn_cmn->bcn_added = true;
1320 return RTW_PHL_STATUS_SUCCESS;
1321 } else {
1322 return RTW_PHL_STATUS_FAILURE;
1323 }
1324 } else {
1325 /* BCN update */
1326 bcn_id = wrole_bcn_cmn->bcn_id;
1327 if(phl_update_beacon(phl_info, bcn_id) == RTW_PHL_STATUS_SUCCESS)
1328 return RTW_PHL_STATUS_SUCCESS;
1329 else
1330 return RTW_PHL_STATUS_FAILURE;
1331 }
1332 }
1333 #ifdef CONFIG_CMD_DISP
1334 enum rtw_phl_status
phl_cmd_issue_bcn_hdl(struct phl_info_t * phl_info,u8 * param)1335 phl_cmd_issue_bcn_hdl(struct phl_info_t *phl_info, u8 *param)
1336 {
1337 struct rtw_bcn_info_cmn *bcn_cmn = (struct rtw_bcn_info_cmn *)param;
1338
1339 return phl_issue_beacon(phl_info, bcn_cmn);
1340 }
1341
_phl_issue_bcn_done(void * drv_priv,u8 * buf,u32 buf_len,enum rtw_phl_status status)1342 static void _phl_issue_bcn_done(void *drv_priv, u8 *buf, u32 buf_len,
1343 enum rtw_phl_status status)
1344 {
1345 if (buf) {
1346 _os_kmem_free(drv_priv, buf, buf_len);
1347 buf = NULL;
1348 PHL_INFO("%s.....\n", __func__);
1349 }
1350 }
1351
1352 enum rtw_phl_status
rtw_phl_cmd_issue_beacon(void * phl,struct rtw_wifi_role_t * wifi_role,struct rtw_bcn_info_cmn * bcn_cmn,enum phl_cmd_type cmd_type,u32 cmd_timeout)1353 rtw_phl_cmd_issue_beacon(void *phl,
1354 struct rtw_wifi_role_t *wifi_role,
1355 struct rtw_bcn_info_cmn *bcn_cmn,
1356 enum phl_cmd_type cmd_type,
1357 u32 cmd_timeout)
1358 {
1359 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1360 void *drv = wifi_role->phl_com->drv_priv;
1361 enum rtw_phl_status psts = RTW_PHL_STATUS_FAILURE;
1362 struct rtw_bcn_info_cmn *param = NULL;
1363 u32 param_len;
1364
1365 if (cmd_type == PHL_CMD_DIRECTLY) {
1366 psts = phl_issue_beacon(phl_info, bcn_cmn);
1367 goto _exit;
1368 }
1369
1370 param_len = sizeof(struct rtw_bcn_info_cmn);
1371 param = _os_kmem_alloc(drv, param_len);
1372 if (param == NULL) {
1373 PHL_ERR("%s: alloc param failed!\n", __func__);
1374 goto _exit;
1375 }
1376
1377 _os_mem_cpy(drv, param, bcn_cmn, param_len);
1378
1379 psts = phl_cmd_enqueue(phl_info,
1380 wifi_role->hw_band,
1381 MSG_EVT_ISSUE_BCN,
1382 (u8 *)param, param_len,
1383 _phl_issue_bcn_done,
1384 cmd_type, cmd_timeout);
1385
1386 if (is_cmd_failure(psts)) {
1387 /* Send cmd success, but wait cmd fail*/
1388 psts = RTW_PHL_STATUS_FAILURE;
1389 } else if (psts != RTW_PHL_STATUS_SUCCESS) {
1390 /* Send cmd fail */
1391 _os_kmem_free(phl_to_drvpriv(phl_info), param, param_len);
1392 psts = RTW_PHL_STATUS_FAILURE;
1393 }
1394
1395 _exit:
1396 return psts;
1397 }
1398
1399 struct stop_bcn_param {
1400 struct rtw_wifi_role_t *wrole;
1401 u8 stop;
1402 };
1403
1404 enum rtw_phl_status
phl_cmd_stop_bcn_hdl(struct phl_info_t * phl_info,u8 * param)1405 phl_cmd_stop_bcn_hdl(struct phl_info_t *phl_info, u8 *param)
1406 {
1407 struct stop_bcn_param *bcn_param = (struct stop_bcn_param *)param;
1408
1409 return phl_beacon_stop(phl_info, bcn_param->wrole, bcn_param->stop);
1410 }
1411
1412
_phl_stop_bcn_done(void * drv_priv,u8 * buf,u32 buf_len,enum rtw_phl_status status)1413 static void _phl_stop_bcn_done(void *drv_priv, u8 *buf, u32 buf_len,
1414 enum rtw_phl_status status)
1415 {
1416 if (buf) {
1417 _os_kmem_free(drv_priv, buf, buf_len);
1418 buf = NULL;
1419 PHL_INFO("%s.....\n", __func__);
1420 }
1421 }
1422
1423
1424 enum rtw_phl_status
rtw_phl_cmd_stop_beacon(void * phl,struct rtw_wifi_role_t * wifi_role,u8 stop,enum phl_cmd_type cmd_type,u32 cmd_timeout)1425 rtw_phl_cmd_stop_beacon(void *phl,
1426 struct rtw_wifi_role_t *wifi_role,
1427 u8 stop,
1428 enum phl_cmd_type cmd_type,
1429 u32 cmd_timeout)
1430 {
1431 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1432 void *drv = wifi_role->phl_com->drv_priv;
1433 enum rtw_phl_status psts = RTW_PHL_STATUS_FAILURE;
1434 struct stop_bcn_param *param = NULL;
1435 u32 param_len;
1436
1437 if (cmd_type == PHL_CMD_DIRECTLY) {
1438 psts = phl_beacon_stop(phl_info, wifi_role, stop);
1439 goto _exit;
1440 }
1441
1442 param_len = sizeof(struct stop_bcn_param);
1443 param = _os_kmem_alloc(drv, param_len);
1444 if (param == NULL) {
1445 PHL_ERR("%s: alloc param failed!\n", __func__);
1446 goto _exit;
1447 }
1448
1449 param->wrole = wifi_role;
1450 param->stop = stop;
1451
1452 psts = phl_cmd_enqueue(phl_info,
1453 wifi_role->hw_band,
1454 MSG_EVT_STOP_BCN,
1455 (u8 *)param, param_len,
1456 _phl_stop_bcn_done,
1457 cmd_type, cmd_timeout);
1458
1459 if (is_cmd_failure(psts)) {
1460 /* Send cmd success, but wait cmd fail*/
1461 psts = RTW_PHL_STATUS_FAILURE;
1462 } else if (psts != RTW_PHL_STATUS_SUCCESS) {
1463 /* Send cmd fail */
1464 _os_kmem_free(phl_to_drvpriv(phl_info), param, param_len);
1465 psts = RTW_PHL_STATUS_FAILURE;
1466 }
1467 _exit:
1468 return psts;
1469 }
1470 #else /*for FSM*/
1471 enum rtw_phl_status
rtw_phl_cmd_stop_beacon(void * phl,struct rtw_wifi_role_t * wifi_role,u8 stop,enum phl_cmd_type cmd_type,u32 cmd_timeout)1472 rtw_phl_cmd_stop_beacon(void *phl,
1473 struct rtw_wifi_role_t *wifi_role,
1474 u8 stop,
1475 enum phl_cmd_type cmd_type,
1476 u32 cmd_timeout)
1477 {
1478 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1479
1480 return phl_beacon_stop(phl_info, wifi_role, stop);
1481 }
1482
1483 enum rtw_phl_status
rtw_phl_cmd_issue_beacon(void * phl,struct rtw_wifi_role_t * wifi_role,struct rtw_bcn_info_cmn * bcn_cmn,enum phl_cmd_type cmd_type,u32 cmd_timeout)1484 rtw_phl_cmd_issue_beacon(void *phl,
1485 struct rtw_wifi_role_t *wifi_role,
1486 struct rtw_bcn_info_cmn *bcn_cmn,
1487 enum phl_cmd_type cmd_type,
1488 u32 cmd_timeout)
1489 {
1490 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1491
1492 return phl_issue_beacon(phl_info, bcn_cmn);
1493 }
1494 #endif /*CONFIG_CMD_DISP*/
1495 #endif /*RTW_PHL_BCN*/
1496
rtw_phl_cap_pre_config(void * phl)1497 void rtw_phl_cap_pre_config(void *phl)
1498 {
1499 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1500 /* FW Pre-config */
1501 rtw_hal_fw_cap_pre_config(phl_info->phl_com,phl_info->hal);
1502 /* Bus Pre-config */
1503 rtw_hal_bus_cap_pre_config(phl_info->phl_com,phl_info->hal);
1504 }
1505
rtw_phl_preload(void * phl)1506 enum rtw_phl_status rtw_phl_preload(void *phl)
1507 {
1508 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1509 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
1510
1511 #ifdef RTW_WKARD_PRELOAD_TRX_RESET
1512 struct phl_hci_trx_ops *ops = phl_info->hci_trx_ops;
1513 #endif
1514 FUNCIN();
1515
1516 hal_status = rtw_hal_preload(phl_info->phl_com, phl_info->hal);
1517
1518 #ifdef RTW_WKARD_PRELOAD_TRX_RESET
1519 ops->trx_reset(phl_info, PHL_CTRL_TX|PHL_CTRL_RX);
1520 #endif
1521 if (hal_status != RTW_HAL_STATUS_SUCCESS)
1522 return RTW_PHL_STATUS_FAILURE;
1523
1524 return RTW_PHL_STATUS_SUCCESS;
1525 }
1526
rtw_phl_start(void * phl)1527 enum rtw_phl_status rtw_phl_start(void *phl)
1528 {
1529 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1530 enum rtw_phl_status phl_status = RTW_PHL_STATUS_FAILURE;
1531 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
1532 #ifdef CONFIG_SYNC_INTERRUPT
1533 struct rtw_phl_evt_ops *evt_ops = &phl_info->phl_com->evt_ops;
1534 #endif /* CONFIG_SYNC_INTERRUPT */
1535
1536 hal_status = rtw_hal_start(phl_info->phl_com, phl_info->hal);
1537 if (hal_status == RTW_HAL_STATUS_MAC_INIT_FAILURE) {
1538 phl_status = RTW_PHL_STATUS_HAL_INIT_FAILURE;
1539 goto error_hal_start;
1540 } else if (hal_status == RTW_HAL_STATUS_BB_INIT_FAILURE) {
1541 phl_status = RTW_PHL_STATUS_HAL_INIT_FAILURE;
1542 goto error_hal_start;
1543 } else if (hal_status == RTW_HAL_STATUS_RF_INIT_FAILURE) {
1544 phl_status = RTW_PHL_STATUS_HAL_INIT_FAILURE;
1545 goto error_hal_start;
1546 } else if (hal_status == RTW_HAL_STATUS_BTC_INIT_FAILURE) {
1547 phl_status = RTW_PHL_STATUS_HAL_INIT_FAILURE;
1548 goto error_hal_start;
1549 } else if (hal_status != RTW_HAL_STATUS_SUCCESS) {
1550 phl_status = RTW_PHL_STATUS_HAL_INIT_FAILURE;
1551 goto error_hal_start;
1552 }
1553
1554 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
1555 /* if no need keep para buf, phl_com->dev_sw_cap->keep_para_info = false*/
1556 rtw_phl_init_free_para_buf(phl_info->phl_com);
1557 #endif
1558
1559 #ifdef CONFIG_FSM
1560 /* start FSM framework */
1561 phl_status = phl_fsm_start(phl_info);
1562 if (phl_status != RTW_PHL_STATUS_SUCCESS)
1563 goto error_phl_fsm_start;
1564
1565 /* start FSM modules */
1566 phl_status = phl_fsm_module_start(phl_info);
1567 if (phl_status != RTW_PHL_STATUS_SUCCESS)
1568 goto error_phl_fsm_module_start;
1569 #endif
1570 /* start modules */
1571 phl_status = phl_module_start(phl_info);
1572 if (phl_status != RTW_PHL_STATUS_SUCCESS)
1573 goto error_phl_module_start;
1574
1575 phl_status = phl_datapath_start(phl_info);
1576 if (phl_status != RTW_PHL_STATUS_SUCCESS)
1577 goto error_phl_datapath_start;
1578
1579 #ifdef CONFIG_SYNC_INTERRUPT
1580 evt_ops->set_interrupt_caps(phl_to_drvpriv(phl_info), true);
1581 #else
1582 rtw_hal_enable_interrupt(phl_info->phl_com, phl_info->hal);
1583 #endif /* CONFIG_SYNC_INTERRUPT */
1584
1585 phl_info->phl_com->dev_state = RTW_DEV_WORKING;
1586 phl_status = RTW_PHL_STATUS_SUCCESS;
1587
1588 return phl_status;
1589
1590 error_phl_datapath_start:
1591 phl_module_stop(phl_info);
1592 error_phl_module_start:
1593 #ifdef CONFIG_FSM
1594 phl_fsm_module_stop(phl_info);
1595 error_phl_fsm_module_start:
1596 phl_fsm_stop(phl_info);
1597 error_phl_fsm_start:
1598 #endif
1599 rtw_hal_stop(phl_info->phl_com, phl_info->hal);
1600 error_hal_start:
1601 return phl_status;
1602 }
1603
_phl_interrupt_stop(struct phl_info_t * phl_info)1604 static void _phl_interrupt_stop(struct phl_info_t *phl_info)
1605 {
1606 #ifdef CONFIG_SYNC_INTERRUPT
1607 struct rtw_phl_evt_ops *evt_ops = &phl_info->phl_com->evt_ops;
1608
1609 do {
1610 if (false == TEST_STATUS_FLAG(phl_info->phl_com->dev_state,
1611 RTW_DEV_SURPRISE_REMOVAL))
1612 evt_ops->set_interrupt_caps(phl_to_drvpriv(phl_info), false);
1613 } while (false);
1614 #else
1615 do {
1616 if (false == TEST_STATUS_FLAG(phl_info->phl_com->dev_state,
1617 RTW_DEV_SURPRISE_REMOVAL))
1618 rtw_hal_disable_interrupt(phl_info->phl_com, phl_info->hal);
1619 } while (false);
1620 #endif /* CONFIG_SYNC_INTERRUPT */
1621 }
1622
_phl_cmd_send_msg_phy_on(struct phl_info_t * phl_info)1623 static enum rtw_phl_status _phl_cmd_send_msg_phy_on(struct phl_info_t *phl_info)
1624 {
1625 enum rtw_phl_status sts = RTW_PHL_STATUS_FAILURE;
1626 #ifdef DBG_PHY_ON_TIME
1627 u32 phyon_start = 0, phyon_t = 0;
1628 #endif /* DBG_PHY_ON_TIME */
1629
1630 #ifdef DBG_PHY_ON_TIME
1631 phyon_start = _os_get_cur_time_ms();
1632 #endif /* DBG_PHY_ON_TIME */
1633
1634 sts = phl_cmd_enqueue(phl_info, HW_BAND_0, MSG_EVT_PHY_ON, NULL, 0, NULL,
1635 PHL_CMD_WAIT, 3000);
1636
1637 #ifdef DBG_PHY_ON_TIME
1638 phyon_t = phl_get_passing_time_ms(phyon_start);
1639 if (phyon_t > 1000) {
1640 PHL_TRACE(COMP_PHL_DBG, _PHL_WARNING_, "%s : phy on takes %u (ms).\n"
1641 , __func__, phyon_t);
1642 }
1643 #endif /* DBG_PHY_ON_TIME */
1644
1645 if (is_cmd_failure(sts)) {
1646 /* send cmd success, but wait cmd fail */
1647 sts = RTW_PHL_STATUS_FAILURE;
1648 } else if (sts != RTW_PHL_STATUS_SUCCESS) {
1649 /* send cmd fail */
1650 sts = RTW_PHL_STATUS_FAILURE;
1651 }
1652 return sts;
1653 }
1654
rtw_phl_stop(void * phl)1655 void rtw_phl_stop(void *phl)
1656 {
1657 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1658
1659 _phl_cmd_send_msg_phy_on(phl_info);
1660
1661 _phl_interrupt_stop(phl_info);
1662 phl_module_stop(phl_info);
1663
1664 #ifdef DBG_PHL_MR
1665 phl_mr_info_dbg(phl_info);
1666 #endif
1667
1668 #ifdef CONFIG_FSM
1669 phl_fsm_module_stop(phl_info);
1670 phl_fsm_stop(phl_info);
1671 #endif
1672
1673 rtw_hal_stop(phl_info->phl_com, phl_info->hal);
1674 phl_datapath_stop(phl_info);
1675
1676 phl_info->phl_com->dev_state = 0;
1677 }
1678
phl_wow_start(struct phl_info_t * phl_info,struct rtw_phl_stainfo_t * sta)1679 enum rtw_phl_status phl_wow_start(struct phl_info_t *phl_info, struct rtw_phl_stainfo_t *sta)
1680 {
1681 #ifdef CONFIG_WOWLAN
1682 enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1683 enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
1684 struct phl_wow_info *wow_info = phl_to_wow_info(phl_info);
1685
1686 #ifdef CONFIG_SYNC_INTERRUPT
1687 struct rtw_phl_evt_ops *evt_ops = &phl_info->phl_com->evt_ops;
1688 #endif /* CONFIG_SYNC_INTERRUPT */
1689
1690 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "[wow] %s enter with sta state(%d)\n.", __func__, sta->wrole->mstate);
1691
1692 phl_wow_decide_op_mode(wow_info, sta);
1693
1694 if (wow_info->op_mode == RTW_WOW_OP_PWR_DOWN) {
1695 phl_cmd_role_suspend(phl_info);
1696 rtw_phl_stop(phl_info);
1697 /* since control path stopped after rtw_phl_stop,
1698 below action don't have to migrate to general module */
1699 hstatus = rtw_hal_set_wowlan(phl_info->phl_com, phl_info->hal, true);
1700 if (RTW_HAL_STATUS_SUCCESS != hstatus)
1701 PHL_WARN("[wow] rtw_hal_set_wowlan failed, status(%u)\n", hstatus);
1702 pstatus = RTW_PHL_STATUS_SUCCESS;
1703 } else {
1704 /* stop all active features */
1705 #ifdef CONFIG_WOW_WITH_SER
1706 rtw_hal_ser_ctrl(phl_info->hal, false);
1707 #endif
1708
1709 pstatus = phl_module_stop(phl_info);
1710 if (RTW_PHL_STATUS_SUCCESS != pstatus) {
1711 PHL_ERR("[wow] phl_module_stop failed.\n");
1712 goto end;
1713 }
1714 /* since control path stopped after phl_module_stop,
1715 below action don't have to migrate to general module */
1716 #ifdef CONFIG_FSM
1717 pstatus = phl_fsm_module_stop(phl_info);
1718 if (RTW_PHL_STATUS_SUCCESS != pstatus) {
1719 PHL_ERR("[wow] phl_fsm_module_stop failed.\n");
1720 goto end;
1721 }
1722
1723 pstatus = phl_fsm_stop(phl_info);
1724 if (RTW_PHL_STATUS_SUCCESS != pstatus) {
1725 PHL_ERR("[wow] phl_fsm_stop failed.\n");
1726 goto end;
1727 }
1728 #endif
1729 hstatus = rtw_hal_set_wowlan(phl_info->phl_com, phl_info->hal, true);
1730 if (RTW_HAL_STATUS_SUCCESS != hstatus)
1731 PHL_WARN("[wow] rtw_hal_set_wowlan failed, status(%u)\n", hstatus);
1732 pstatus = phl_wow_init_precfg(wow_info);
1733 if (RTW_PHL_STATUS_SUCCESS != pstatus) {
1734 PHL_ERR("[wow] phl_wow_init_precfg failed.\n");
1735 goto end;
1736 }
1737
1738 hstatus = rtw_hal_wow_init(phl_info->phl_com, phl_info->hal, sta);
1739 if (RTW_HAL_STATUS_SUCCESS != hstatus) {
1740 pstatus = RTW_PHL_STATUS_FAILURE;
1741 goto end;
1742 }
1743
1744 pstatus = phl_wow_func_en(wow_info);
1745 if (RTW_PHL_STATUS_SUCCESS != pstatus)
1746 goto end;
1747 #ifdef CONFIG_POWER_SAVE
1748 /* power saving */
1749 phl_wow_ps_proto_cfg(wow_info, true);
1750
1751 phl_wow_ps_pwr_ntfy(wow_info, true);
1752 #endif
1753 pstatus = phl_wow_init_postcfg(wow_info);
1754 if (RTW_PHL_STATUS_SUCCESS != pstatus) {
1755 PHL_ERR("[wow] phl_wow_init_postcfg failed.\n");
1756 goto end;
1757 }
1758 #ifdef CONFIG_WOW_WITH_SER
1759 rtw_hal_ser_ctrl(phl_info->hal, true);
1760 #endif
1761 #ifdef CONFIG_POWER_SAVE
1762 /* power saving */
1763 phl_wow_ps_pwr_cfg(wow_info, true);
1764 #endif
1765 pstatus = RTW_PHL_STATUS_SUCCESS;
1766 }
1767
1768 end:
1769 if (RTW_PHL_STATUS_SUCCESS != pstatus) {
1770 #ifdef CONFIG_SYNC_INTERRUPT
1771 evt_ops->set_interrupt_caps(phl_to_drvpriv(phl_info), false);
1772 #else
1773 rtw_hal_disable_interrupt(phl_info->phl_com, phl_info->hal);
1774 #endif /* CONFIG_SYNC_INTERRUPT */
1775 rtw_hal_stop(phl_info->phl_com, phl_info->hal);
1776 phl_datapath_stop(phl_info);
1777 wow_info->op_mode = RTW_WOW_OP_PWR_DOWN;
1778 PHL_ERR("[wow] %s fail, set op_mode %d!\n", __func__, wow_info->op_mode);
1779 } else {
1780 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_,
1781 "[wow] %s success, with func_en %d, op_mode %d.\n",
1782 __func__, wow_info->func_en, wow_info->op_mode);
1783 }
1784
1785 return pstatus;
1786 #else
1787 return RTW_PHL_STATUS_SUCCESS;
1788 #endif /* CONFIG_WOWLAN */
1789 }
1790
_wow_stop_reinit(struct phl_info_t * phl_info)1791 static void _wow_stop_reinit(struct phl_info_t *phl_info)
1792 {
1793 enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1794
1795 PHL_WARN("%s : reset hw!\n", __func__);
1796 rtw_hal_hal_deinit(phl_info->phl_com, phl_info->hal);
1797 phl_datapath_stop(phl_info);
1798 pstatus = rtw_phl_start(phl_info);
1799 if (pstatus)
1800 PHL_ERR("%s : rtw_phl_start fail!\n", __func__);
1801 phl_cmd_role_recover(phl_info);
1802
1803 }
1804
phl_wow_stop(struct phl_info_t * phl_info,struct rtw_phl_stainfo_t * sta,u8 * hw_reinit)1805 void phl_wow_stop(struct phl_info_t *phl_info, struct rtw_phl_stainfo_t *sta, u8 *hw_reinit)
1806 {
1807 #ifdef CONFIG_WOWLAN
1808 enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1809 enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
1810 struct phl_wow_info *wow_info = phl_to_wow_info(phl_info);
1811 u8 reset = 0;
1812
1813 if (rtw_hal_get_pwr_state(phl_info->hal, &wow_info->mac_pwr)
1814 != RTW_HAL_STATUS_SUCCESS)
1815 return;
1816
1817 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "%s enter with mac power %d\n.",
1818 __func__, wow_info->mac_pwr);
1819
1820 if (wow_info->mac_pwr != RTW_MAC_PWR_OFF) {
1821 #ifdef CONFIG_WOW_WITH_SER
1822 rtw_hal_ser_ctrl(phl_info->hal, false);
1823 #endif
1824 #ifdef CONFIG_POWER_SAVE
1825 /* leave clock/power gating */
1826 pstatus = phl_wow_ps_pwr_cfg(wow_info, false);
1827 if (RTW_PHL_STATUS_SUCCESS != pstatus) {
1828 PHL_ERR("[wow] HW leave power saving failed.\n");
1829 _wow_stop_reinit(phl_info);
1830 *hw_reinit = true;
1831 return;
1832 }
1833 #endif
1834 }
1835
1836 hstatus = rtw_hal_set_wowlan(phl_info->phl_com, phl_info->hal, false);
1837 if (RTW_HAL_STATUS_SUCCESS != hstatus) {
1838 PHL_WARN("[wow] rtw_hal_set_wowlan failed, status(%u)\n", hstatus);
1839 }
1840
1841 if (wow_info->mac_pwr == RTW_MAC_PWR_OFF) {
1842 if (wow_info->op_mode == RTW_WOW_OP_PWR_DOWN) {
1843 pstatus = rtw_phl_start(phl_info);
1844 phl_role_recover(phl_info);
1845 *hw_reinit = true;
1846 } else {
1847 PHL_WARN("[wow] enter suspend with wow enabled but mac is power down\n");
1848 _wow_stop_reinit(phl_info);
1849 *hw_reinit = true;
1850 }
1851 } else if (wow_info->mac_pwr == RTW_MAC_PWR_ON ||
1852 wow_info->mac_pwr == RTW_MAC_PWR_LPS) {
1853
1854 phl_wow_handle_wake_rsn(wow_info, &reset);
1855 if (reset) {
1856 _wow_stop_reinit(phl_info);
1857 *hw_reinit = true;
1858 return;
1859 }
1860
1861 phl_wow_deinit_precfg(wow_info);
1862
1863 rtw_hal_fw_dbg_dump(phl_info->hal);
1864 #ifdef CONFIG_POWER_SAVE
1865 phl_wow_ps_pwr_ntfy(wow_info, false);
1866 /* leave power saving */
1867 phl_wow_ps_proto_cfg(wow_info, false);
1868 #endif
1869 phl_wow_func_dis(wow_info);
1870
1871 hstatus = rtw_hal_wow_deinit(phl_info->phl_com, phl_info->hal, sta);
1872 if (hstatus)
1873 PHL_ERR("%s : rtw_hal_wow_deinit failed.\n", __func__);
1874
1875 phl_module_start(phl_info);
1876 #ifdef CONFIG_FSM
1877 phl_fsm_start(phl_info);
1878 phl_fsm_module_start(phl_info);
1879 #endif
1880 phl_wow_deinit_postcfg(wow_info);
1881 #ifdef CONFIG_WOW_WITH_SER
1882 rtw_hal_ser_ctrl(phl_info->hal, true);
1883 #endif
1884 *hw_reinit = false;
1885 } else {
1886 PHL_ERR("%s : unexpected mac pwr state %d.\n", __func__, wow_info->mac_pwr);
1887 }
1888
1889 #endif /* CONFIG_WOWLAN */
1890 }
1891
rtw_phl_rf_on(void * phl)1892 enum rtw_phl_status rtw_phl_rf_on(void *phl)
1893 {
1894 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1895 enum rtw_phl_status phl_status = RTW_PHL_STATUS_FAILURE;
1896 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
1897 #ifdef CONFIG_SYNC_INTERRUPT
1898 struct rtw_phl_evt_ops *evt_ops = &phl_info->phl_com->evt_ops;
1899 #endif /* CONFIG_SYNC_INTERRUPT */
1900 struct phl_data_ctl_t ctl = {0};
1901
1902 hal_status = rtw_hal_start(phl_info->phl_com, phl_info->hal);
1903 if (hal_status == RTW_HAL_STATUS_MAC_INIT_FAILURE) {
1904 phl_status = RTW_PHL_STATUS_HAL_INIT_FAILURE;
1905 goto error_hal_start;
1906 } else if (hal_status == RTW_HAL_STATUS_BB_INIT_FAILURE) {
1907 phl_status = RTW_PHL_STATUS_HAL_INIT_FAILURE;
1908 goto error_hal_start;
1909 } else if (hal_status == RTW_HAL_STATUS_RF_INIT_FAILURE) {
1910 phl_status = RTW_PHL_STATUS_HAL_INIT_FAILURE;
1911 goto error_hal_start;
1912 } else if (hal_status == RTW_HAL_STATUS_BTC_INIT_FAILURE) {
1913 phl_status = RTW_PHL_STATUS_HAL_INIT_FAILURE;
1914 goto error_hal_start;
1915 }
1916
1917 phl_role_recover(phl_info);
1918 #ifdef CONFIG_SYNC_INTERRUPT
1919 evt_ops->set_interrupt_caps(phl_to_drvpriv(phl_info), true);
1920 #else
1921 rtw_hal_enable_interrupt(phl_info->phl_com, phl_info->hal);
1922 #endif /* CONFIG_SYNC_INTERRUPT */
1923
1924 ctl.id = PHL_MDL_POWER_MGNT;
1925 ctl.cmd = PHL_DATA_CTL_SW_TX_RESUME;
1926 if (phl_data_ctrler(phl_info, &ctl, NULL) != RTW_PHL_STATUS_SUCCESS)
1927 PHL_WARN("%s: tx resume fail!\n", __func__);
1928 ctl.cmd = PHL_DATA_CTL_SW_RX_RESUME;
1929 if (phl_data_ctrler(phl_info, &ctl, NULL) != RTW_PHL_STATUS_SUCCESS)
1930 PHL_WARN("%s: rx resume fail!\n", __func__);
1931
1932 return RTW_PHL_STATUS_SUCCESS;
1933 error_hal_start:
1934 PHL_ERR("error_hal_start\n");
1935 return phl_status;
1936 }
1937
1938 #define MAX_RF_OFF_STOP_TRX_TIME 100 /* ms */
rtw_phl_rf_off(void * phl)1939 enum rtw_phl_status rtw_phl_rf_off(void *phl)
1940 {
1941 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1942 #ifdef CONFIG_SYNC_INTERRUPT
1943 struct rtw_phl_evt_ops *evt_ops = &phl_info->phl_com->evt_ops;
1944 #endif /* CONFIG_SYNC_INTERRUPT */
1945 struct phl_data_ctl_t ctl = {0};
1946
1947 #ifdef CONFIG_SYNC_INTERRUPT
1948 evt_ops->set_interrupt_caps(phl_to_drvpriv(phl_info), false);
1949 #else
1950 rtw_hal_disable_interrupt(phl_info->phl_com, phl_info->hal);
1951 #endif /* CONFIG_SYNC_INTERRUPT */
1952
1953 ctl.id = PHL_MDL_POWER_MGNT;
1954 ctl.cmd = PHL_DATA_CTL_SW_TX_PAUSE;
1955 if (phl_data_ctrler(phl_info, &ctl, NULL) != RTW_PHL_STATUS_SUCCESS)
1956 PHL_WARN("%s: tx pause fail!\n", __func__);
1957 ctl.cmd = PHL_DATA_CTL_SW_RX_PAUSE;
1958 if (phl_data_ctrler(phl_info, &ctl, NULL) != RTW_PHL_STATUS_SUCCESS)
1959 PHL_WARN("%s: rx pause fail!\n", __func__);
1960
1961 phl_role_suspend(phl_info);
1962 rtw_hal_stop(phl_info->phl_com, phl_info->hal);
1963
1964 ctl.cmd = PHL_DATA_CTL_SW_TX_RESET;
1965 if (phl_data_ctrler(phl_info, &ctl, NULL) != RTW_PHL_STATUS_SUCCESS)
1966 PHL_WARN("%s: tx reset fail!\n", __func__);
1967 ctl.cmd = PHL_DATA_CTL_SW_RX_RESET;
1968 if (phl_data_ctrler(phl_info, &ctl, NULL) != RTW_PHL_STATUS_SUCCESS)
1969 PHL_WARN("%s: rx reset fail!\n", __func__);
1970
1971 return RTW_PHL_STATUS_SUCCESS;
1972 }
1973
rtw_phl_suspend(void * phl,struct rtw_phl_stainfo_t * sta,u8 wow_en)1974 enum rtw_phl_status rtw_phl_suspend(void *phl, struct rtw_phl_stainfo_t *sta, u8 wow_en)
1975 {
1976 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1977 enum rtw_phl_status pstatus = RTW_PHL_STATUS_SUCCESS;
1978
1979 PHL_INFO("%s enter with wow_en(%d)\n.", __func__, wow_en);
1980 #ifdef CONFIG_WOWLAN
1981 pstatus = _phl_cmd_send_msg_phy_on(phl_info);
1982 if (RTW_PHL_STATUS_SUCCESS != pstatus) {
1983 PHL_ERR("[wow] _phl_cmd_send_msg_phy_on fail!\n");
1984 wow_en = false;
1985 }
1986
1987 if (wow_en) {
1988 pstatus = phl_wow_start(phl_info, sta);
1989 } else {
1990 phl_cmd_role_suspend(phl_info);
1991 rtw_phl_stop(phl);
1992 }
1993 #else
1994 PHL_INFO("%s enter with wow_en(%d)\n.", __func__, wow_en);
1995
1996 phl_cmd_role_suspend(phl_info);
1997 rtw_phl_stop(phl);
1998 #endif
1999
2000 FUNCOUT_WSTS(pstatus);
2001
2002 return pstatus;
2003 }
2004
rtw_phl_resume(void * phl,struct rtw_phl_stainfo_t * sta,u8 * hw_reinit)2005 enum rtw_phl_status rtw_phl_resume(void *phl, struct rtw_phl_stainfo_t *sta, u8 *hw_reinit)
2006 {
2007 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2008 enum rtw_phl_status pstatus = RTW_PHL_STATUS_SUCCESS;
2009 #ifdef CONFIG_WOWLAN
2010 struct phl_wow_info *wow_info = phl_to_wow_info(phl_info);
2011 #endif
2012
2013 /**
2014 * Since some platforms require performance when device resuming, we need
2015 * to finish "rtw_phl_resume" as fast as possible. In this situation, we
2016 * prevent ps module entering any power saving mechanisms and try to do I/O
2017 * operations directly without issue commands to cmd dispatcher. Therefore,
2018 * ps module will not enter power saving if device state "RTW_DEV_RESUMING"
2019 * is set. If device state "RTW_DEV_RESUMING" is set, operations of I/O
2020 * should check whether the current power state can perform I/O or not and
2021 * perform I/O directly without issuing commands to cmd dispatcher if device
2022 * power state is I/O allowable. This kind of flow is only suitable for
2023 * "rtw_phl_resume" because core layer will not perform any other tasks when
2024 * calling rtw_phl_resume which is relatively simple enough.
2025 */
2026 PHL_INFO("%s enter...\n.", __func__);
2027 SET_STATUS_FLAG(phl_info->phl_com->dev_state, RTW_DEV_RESUMING);
2028
2029 #ifdef CONFIG_WOWLAN
2030 if (wow_info->op_mode != RTW_WOW_OP_NONE) {
2031 phl_wow_stop(phl_info, sta, hw_reinit);
2032 } else {
2033 pstatus = rtw_phl_start(phl);
2034 #ifdef CONFIG_POWER_SAVE
2035 if (phl_ps_get_cur_pwr_lvl(phl_info) == PS_PWR_LVL_PWRON)
2036 #endif
2037 phl_role_recover(phl_info);
2038 *hw_reinit = true;
2039 }
2040 #if defined(RTW_WKARD_WOW_L2_PWR) && defined(CONFIG_PCI_HCI)
2041 rtw_hal_set_l2_leave(phl_info->hal);
2042 #endif
2043 phl_record_wow_stat(wow_info);
2044 phl_reset_wow_info(wow_info);
2045 #else
2046 pstatus = rtw_phl_start(phl);
2047 #ifdef CONFIG_POWER_SAVE
2048 if (phl_ps_get_cur_pwr_lvl(phl_info) == PS_PWR_LVL_PWRON)
2049 #endif
2050 phl_role_recover(phl_info);
2051 *hw_reinit = true;
2052 #endif
2053
2054 CLEAR_STATUS_FLAG(phl_info->phl_com->dev_state, RTW_DEV_RESUMING);
2055
2056 PHL_INFO("%s exit with hw_reinit %d.\n.", __func__, *hw_reinit);
2057
2058 return pstatus;
2059 }
2060
rtw_phl_reset(void * phl)2061 enum rtw_phl_status rtw_phl_reset(void *phl)
2062 {
2063 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2064 struct phl_hci_trx_ops *ops = phl_info->hci_trx_ops;
2065 enum rtw_phl_status phl_status = RTW_PHL_STATUS_FAILURE;
2066
2067 if(rtw_phl_is_init_completed(phl_info))
2068 phl_status = RTW_PHL_STATUS_SUCCESS;
2069
2070 rtw_hal_stop(phl_info->phl_com, phl_info->hal);
2071
2072 ops->trx_reset(phl_info, PHL_CTRL_TX|PHL_CTRL_RX);
2073 ops->trx_resume(phl_info, PHL_CTRL_TX|PHL_CTRL_RX);
2074
2075 rtw_hal_start(phl_info->phl_com, phl_info->hal);
2076 /* Leave power save */
2077 /* scan abort */
2078 /* STA disconnect/stop AP/Stop p2p function */
2079
2080 return phl_status;
2081 }
2082
rtw_phl_restart(void * phl)2083 enum rtw_phl_status rtw_phl_restart(void *phl)
2084 {
2085 enum rtw_phl_status phl_status = RTW_PHL_STATUS_FAILURE;
2086
2087 phl_status = RTW_PHL_STATUS_SUCCESS;
2088
2089 return phl_status;
2090 }
2091
2092
2093 /******************* IO APIs *******************/
rtw_phl_read8(void * phl,u32 addr)2094 u8 rtw_phl_read8(void *phl, u32 addr)
2095 {
2096 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2097
2098 return rtw_hal_read8(phl_info->hal, addr);
2099 }
rtw_phl_read16(void * phl,u32 addr)2100 u16 rtw_phl_read16(void *phl, u32 addr)
2101 {
2102 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2103
2104 return rtw_hal_read16(phl_info->hal, addr);
2105 }
rtw_phl_read32(void * phl,u32 addr)2106 u32 rtw_phl_read32(void *phl, u32 addr)
2107 {
2108 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2109
2110 return rtw_hal_read32(phl_info->hal, addr);
2111 }
rtw_phl_write8(void * phl,u32 addr,u8 val)2112 void rtw_phl_write8(void *phl, u32 addr, u8 val)
2113 {
2114 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2115
2116 rtw_hal_write8(phl_info->hal, addr, val);
2117 }
rtw_phl_write16(void * phl,u32 addr,u16 val)2118 void rtw_phl_write16(void *phl, u32 addr, u16 val)
2119 {
2120 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2121
2122 rtw_hal_write16(phl_info->hal, addr, val);
2123 }
rtw_phl_write32(void * phl,u32 addr,u32 val)2124 void rtw_phl_write32(void *phl, u32 addr, u32 val)
2125 {
2126 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2127
2128 rtw_hal_write32(phl_info->hal, addr, val);
2129 }
rtw_phl_read_macreg(void * phl,u32 offset,u32 bit_mask)2130 u32 rtw_phl_read_macreg(void *phl, u32 offset, u32 bit_mask)
2131 {
2132 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2133
2134 return rtw_hal_read_macreg(phl_info->hal, offset, bit_mask);
2135 }
rtw_phl_write_macreg(void * phl,u32 offset,u32 bit_mask,u32 data)2136 void rtw_phl_write_macreg(void *phl,
2137 u32 offset, u32 bit_mask, u32 data)
2138 {
2139 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2140
2141 rtw_hal_write_macreg(phl_info->hal, offset, bit_mask, data);
2142
2143 }
rtw_phl_read_bbreg(void * phl,u32 offset,u32 bit_mask)2144 u32 rtw_phl_read_bbreg(void *phl, u32 offset, u32 bit_mask)
2145 {
2146 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2147
2148 return rtw_hal_read_bbreg(phl_info->hal, offset, bit_mask);
2149 }
rtw_phl_write_bbreg(void * phl,u32 offset,u32 bit_mask,u32 data)2150 void rtw_phl_write_bbreg(void *phl,
2151 u32 offset, u32 bit_mask, u32 data)
2152 {
2153 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2154
2155 rtw_hal_write_bbreg(phl_info->hal, offset, bit_mask, data);
2156
2157 }
rtw_phl_read_rfreg(void * phl,enum rf_path path,u32 offset,u32 bit_mask)2158 u32 rtw_phl_read_rfreg(void *phl,
2159 enum rf_path path, u32 offset, u32 bit_mask)
2160 {
2161 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2162
2163 return rtw_hal_read_rfreg(phl_info->hal, path, offset, bit_mask);
2164 }
rtw_phl_write_rfreg(void * phl,enum rf_path path,u32 offset,u32 bit_mask,u32 data)2165 void rtw_phl_write_rfreg(void *phl,
2166 enum rf_path path, u32 offset, u32 bit_mask, u32 data)
2167 {
2168 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2169
2170 rtw_hal_write_rfreg(phl_info->hal, path, offset, bit_mask, data);
2171
2172 }
2173
rtw_phl_restore_interrupt(void * phl)2174 void rtw_phl_restore_interrupt(void *phl)
2175 {
2176 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2177 rtw_hal_restore_interrupt(phl_info->phl_com, phl_info->hal);
2178 }
2179
rtw_phl_interrupt_handler(void * phl)2180 enum rtw_phl_status rtw_phl_interrupt_handler(void *phl)
2181 {
2182 enum rtw_phl_status phl_status = RTW_PHL_STATUS_SUCCESS;
2183 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2184 u32 int_hdler_msk = 0x0;
2185 #ifdef CONFIG_SYNC_INTERRUPT
2186 struct rtw_phl_evt_ops *ops = &phl_info->phl_com->evt_ops;
2187 #endif /* CONFIG_SYNC_INTERRUPT */
2188 int_hdler_msk = rtw_hal_interrupt_handler(phl_info->hal);
2189
2190 if (!int_hdler_msk) {
2191 PHL_WARN("%s : 0x%x\n", __func__, int_hdler_msk);
2192 phl_status = RTW_PHL_STATUS_FAILURE;
2193 goto end;
2194 }
2195
2196 PHL_DBG("%s : 0x%x\n", __func__, int_hdler_msk);
2197 /* beacon interrupt */
2198 if (int_hdler_msk & BIT0)
2199 ;/* todo */
2200
2201 /* rx interrupt */
2202 if (int_hdler_msk & BIT1) {
2203 #if defined(CONFIG_SDIO_HCI) && defined(CONFIG_PHL_SDIO_READ_RXFF_IN_INT)
2204 phl_info->hci_trx_ops->recv_rxfifo(phl);
2205 #else
2206 phl_status = rtw_phl_start_rx_process(phl);
2207 #endif
2208
2209 #if defined(CONFIG_PCI_HCI) && !defined(CONFIG_DYNAMIC_RX_BUF)
2210 /* phl_status = hci_trx_ops->recycle_busy_wd(phl); */
2211 #endif
2212 }
2213
2214 /* tx interrupt */
2215 if (int_hdler_msk & BIT2)
2216 ;
2217
2218 /* cmd interrupt */
2219 if (int_hdler_msk & BIT3)
2220 ;/* todo */
2221
2222 /* halt c2h interrupt */
2223 if (int_hdler_msk & BIT4)
2224 phl_status = phl_ser_send_msg(phl, RTW_PHL_SER_EVENT_CHK);
2225
2226 /* halt c2h interrupt */
2227 if (int_hdler_msk & BIT5)
2228 phl_status = phl_fw_watchdog_timeout_notify(phl);
2229
2230 /* halt c2h interrupt - send msg to SER FSM to check ser event */
2231 if (int_hdler_msk & BIT6)
2232 phl_status = phl_ser_send_msg(phl, RTW_PHL_SER_EVENT_CHK);
2233
2234 if (phl_status != RTW_PHL_STATUS_SUCCESS)
2235 PHL_INFO("rtw_phl_interrupt_handler fail !!\n");
2236
2237 /* schedule tx process */
2238 phl_status = phl_schedule_handler(phl_info->phl_com, &phl_info->phl_tx_handler);
2239 end:
2240
2241 #ifdef CONFIG_SYNC_INTERRUPT
2242 ops->interrupt_restore(phl_to_drvpriv(phl_info), false);
2243 #endif
2244 return phl_status;
2245 }
2246
rtw_phl_enable_interrupt(void * phl)2247 void rtw_phl_enable_interrupt(void *phl)
2248 {
2249 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2250 rtw_hal_enable_interrupt(phl_info->phl_com, phl_info->hal);
2251 }
2252
rtw_phl_disable_interrupt(void * phl)2253 void rtw_phl_disable_interrupt(void *phl)
2254 {
2255 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2256 rtw_hal_disable_interrupt(phl_info->phl_com, phl_info->hal);
2257 }
2258
rtw_phl_recognize_interrupt(void * phl)2259 bool rtw_phl_recognize_interrupt(void *phl)
2260 {
2261 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2262
2263 return rtw_hal_recognize_interrupt(phl_info->hal);
2264 }
2265
rtw_phl_clear_interrupt(void * phl)2266 void rtw_phl_clear_interrupt(void *phl)
2267 {
2268 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2269
2270 rtw_hal_clear_interrupt(phl_info->hal);
2271 }
2272
rtw_phl_msg_hub_register_recver(void * phl,struct phl_msg_receiver * ctx,enum phl_msg_recver_layer layer)2273 enum rtw_phl_status rtw_phl_msg_hub_register_recver(void* phl,
2274 struct phl_msg_receiver* ctx, enum phl_msg_recver_layer layer)
2275 {
2276 return phl_msg_hub_register_recver(phl, ctx, layer);
2277 }
rtw_phl_msg_hub_update_recver_mask(void * phl,enum phl_msg_recver_layer layer,u8 * mdl_id,u32 len,u8 clr)2278 enum rtw_phl_status rtw_phl_msg_hub_update_recver_mask(void* phl,
2279 enum phl_msg_recver_layer layer, u8* mdl_id, u32 len, u8 clr)
2280 {
2281 return phl_msg_hub_update_recver_mask(phl, layer, mdl_id, len, clr);
2282 }
rtw_phl_msg_hub_deregister_recver(void * phl,enum phl_msg_recver_layer layer)2283 enum rtw_phl_status rtw_phl_msg_hub_deregister_recver(void* phl,
2284 enum phl_msg_recver_layer layer)
2285 {
2286 return phl_msg_hub_deregister_recver(phl, layer);
2287 }
rtw_phl_msg_hub_send(void * phl,struct phl_msg_attribute * attr,struct phl_msg * msg)2288 enum rtw_phl_status rtw_phl_msg_hub_send(void* phl,
2289 struct phl_msg_attribute* attr, struct phl_msg* msg)
2290 {
2291 return phl_msg_hub_send((struct phl_info_t*)phl, attr, msg);
2292 }
2293 #ifdef PHL_PLATFORM_LINUX
rtw_phl_mac_reg_dump(void * sel,void * phl)2294 void rtw_phl_mac_reg_dump(void *sel, void *phl)
2295 {
2296 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2297
2298 rtw_hal_mac_reg_dump(sel, phl_info->hal);
2299 }
2300
rtw_phl_bb_reg_dump(void * sel,void * phl)2301 void rtw_phl_bb_reg_dump(void *sel, void *phl)
2302 {
2303 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2304
2305 rtw_hal_bb_reg_dump(sel, phl_info->hal);
2306 }
2307
rtw_phl_bb_reg_dump_ex(void * sel,void * phl)2308 void rtw_phl_bb_reg_dump_ex(void *sel, void *phl)
2309 {
2310 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2311
2312 rtw_hal_bb_reg_dump_ex(sel, phl_info->hal);
2313 }
2314
rtw_phl_rf_reg_dump(void * sel,void * phl)2315 void rtw_phl_rf_reg_dump(void *sel, void *phl)
2316 {
2317 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2318
2319 rtw_hal_rf_reg_dump(sel, phl_info->hal);
2320 }
2321 #endif
2322
2323 /**
2324 * rtw_phl_get_sec_cam() - get the security cam raw data from HW
2325 * @phl: struct phl_info_t *
2326 * @num: How many cam you wnat to dump from the first one.
2327 * @buf: ptr to buffer which store the content from HW.
2328 * If buf is NULL, use console as debug path.
2329 * @size Size of allocated memroy for @buf.
2330 * The size should be @num * size of security cam offset(0x20).
2331 *
2332 * Return true when function successfully works, otherwise, return fail.
2333 */
rtw_phl_get_sec_cam(void * phl,u16 num,u8 * buf,u16 size)2334 bool rtw_phl_get_sec_cam(void *phl, u16 num, u8 *buf, u16 size)
2335 {
2336 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2337 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
2338
2339 ret = rtw_hal_get_sec_cam(phl_info->hal, num, buf, size);
2340 if (ret != RTW_HAL_STATUS_SUCCESS)
2341 return false;
2342
2343 return true;
2344 }
2345
2346 /**
2347 * rtw_phl_get_addr_cam() - get the address cam raw data from HW
2348 * @phl: struct phl_info_t *
2349 * @num: How many cam you wnat to dump from the first one.
2350 * @buf: ptr to buffer which store the content from HW.
2351 * If buf is NULL, use console as debug path.
2352 * @size Size of allocated memroy for @buf.
2353 * The size should be @num * size of Addr cam offset(0x40).
2354 *
2355 * Return true when function successfully works, otherwise, return fail.
2356 */
rtw_phl_get_addr_cam(void * phl,u16 num,u8 * buf,u16 size)2357 bool rtw_phl_get_addr_cam(void *phl, u16 num, u8 *buf, u16 size)
2358 {
2359 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2360 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
2361
2362 ret = rtw_hal_get_addr_cam(phl_info->hal, num, buf, size);
2363 if (ret != RTW_HAL_STATUS_SUCCESS)
2364 return false;
2365
2366 return true;
2367 }
2368
rtw_phl_mac_dbg_status_dump(void * phl,u32 * val,u8 * en)2369 void rtw_phl_mac_dbg_status_dump(void *phl, u32 *val, u8 *en)
2370 {
2371 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2372 struct hal_mac_dbg_dump_cfg cfg = {0};
2373
2374 cfg.ss_dbg_0 = val[0];
2375 cfg.ss_dbg_1 = val[1];
2376
2377 cfg.ss_dbg = (*en & BIT0);
2378 cfg.dle_dbg = (*en & BIT1) >> 1;
2379 cfg.dmac_dbg = (*en & BIT2) >> 2;
2380 cfg.cmac_dbg = (*en & BIT3) >> 3;
2381 cfg.mac_dbg_port = (*en & BIT4) >> 4;
2382 cfg.plersvd_dbg = (*en & BIT5) >> 5;
2383 cfg.tx_flow_dbg = (*en & BIT6) >> 6;
2384
2385 rtw_hal_dbg_status_dump(phl_info->hal, &cfg);
2386 }
2387
rtw_phl_get_mac_addr_efuse(void * phl,u8 * addr)2388 enum rtw_phl_status rtw_phl_get_mac_addr_efuse(void* phl, u8 *addr)
2389 {
2390 enum rtw_phl_status pstatus = RTW_PHL_STATUS_SUCCESS;
2391 enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
2392 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2393 void *d = phl_to_drvpriv(phl_info);
2394 u8 addr_efuse[MAC_ADDRESS_LENGTH] = {0};
2395
2396 hstatus = rtw_hal_get_efuse_info(phl_info->hal,
2397 EFUSE_INFO_MAC_ADDR,
2398 (void *)addr_efuse,
2399 MAC_ADDRESS_LENGTH);
2400 if (is_broadcast_mac_addr(addr_efuse)) {
2401 PHL_INFO("[WARNING] MAC Address from EFUSE is FF:FF:FF:FF:FF:FF\n");
2402 hstatus = RTW_HAL_STATUS_FAILURE;
2403 }
2404 if (RTW_HAL_STATUS_SUCCESS != hstatus) {
2405 pstatus = RTW_PHL_STATUS_FAILURE;
2406 } else {
2407 _os_mem_cpy(d, addr, addr_efuse, MAC_ADDRESS_LENGTH);
2408 PHL_INFO("%s : 0x%2x - 0x%2x - 0x%2x - 0x%2x - 0x%2x - 0x%2x\n",
2409 __func__, addr[0], addr[1], addr[2],
2410 addr[3], addr[4], addr[5]);
2411
2412 }
2413 return pstatus;
2414 }
2415
2416 enum rtw_phl_status
rtw_phl_cfg_trx_path(void * phl,enum rf_path tx,u8 tx_nss,enum rf_path rx,u8 rx_nss)2417 rtw_phl_cfg_trx_path(void* phl, enum rf_path tx, u8 tx_nss,
2418 enum rf_path rx, u8 rx_nss)
2419 {
2420 enum rtw_phl_status pstatus = RTW_PHL_STATUS_SUCCESS;
2421 enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
2422 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2423
2424 hstatus = rtw_hal_cfg_trx_path(phl_info->hal, tx, tx_nss, rx, rx_nss);
2425
2426 if (RTW_HAL_STATUS_SUCCESS != hstatus)
2427 pstatus = RTW_PHL_STATUS_FAILURE;
2428
2429 return pstatus;
2430 }
2431
2432
rtw_phl_reset_stat_ma_rssi(struct rtw_phl_com_t * phl_com)2433 void rtw_phl_reset_stat_ma_rssi(struct rtw_phl_com_t *phl_com)
2434 {
2435 u8 i = 0, j = 0;
2436 PHL_INFO("--> %s\n", __func__);
2437 do{
2438 if (NULL == phl_com)
2439 break;
2440
2441 _os_spinlock(phl_com->drv_priv,
2442 &(phl_com->rssi_stat.lock), _bh, NULL);
2443 for (i = 0; i < RTW_RSSI_TYPE_MAX; i++) {
2444 phl_com->rssi_stat.ma_rssi_ele_idx[i] = 0;
2445 phl_com->rssi_stat.ma_rssi_ele_cnt[i] = 0;
2446 phl_com->rssi_stat.ma_rssi_ele_sum[i] = 0;
2447 phl_com->rssi_stat.ma_rssi[i] = 0;
2448 for (j = 0; j < PHL_RSSI_MAVG_NUM; j++)
2449 phl_com->rssi_stat.ma_rssi_ele[i][j] = 0;
2450 }
2451 _os_spinunlock(phl_com->drv_priv,
2452 &(phl_com->rssi_stat.lock), _bh, NULL);
2453 } while (0);
2454
2455 PHL_INFO("<-- %s\n", __func__);
2456 }
2457
2458 u8
rtw_phl_get_ma_rssi(struct rtw_phl_com_t * phl_com,enum rtw_rssi_type rssi_type)2459 rtw_phl_get_ma_rssi(struct rtw_phl_com_t *phl_com,
2460 enum rtw_rssi_type rssi_type)
2461 {
2462
2463 u8 ret = 0;
2464 if (NULL == phl_com)
2465 return ret;
2466
2467 _os_spinlock(phl_com->drv_priv,
2468 &(phl_com->rssi_stat.lock), _bh, NULL);
2469 ret = phl_com->rssi_stat.ma_rssi[rssi_type];
2470 _os_spinunlock(phl_com->drv_priv,
2471 &(phl_com->rssi_stat.lock), _bh, NULL);
2472
2473 return ret;
2474 }
2475
2476 #ifdef RTW_WKARD_DYNAMIC_BFEE_CAP
2477 enum rtw_phl_status
rtw_phl_bfee_ctrl(void * phl,struct rtw_wifi_role_t * wrole,bool ctrl)2478 rtw_phl_bfee_ctrl(void *phl, struct rtw_wifi_role_t *wrole, bool ctrl)
2479 {
2480 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2481 enum rtw_phl_status pstatus = RTW_PHL_STATUS_SUCCESS;
2482 if (RTW_HAL_STATUS_SUCCESS !=
2483 rtw_hal_bf_bfee_ctrl(phl_info->hal, wrole->hw_band, ctrl)) {
2484 pstatus = RTW_PHL_STATUS_FAILURE;
2485 }
2486 return pstatus;
2487 }
2488 #endif
2489
2490 u8
rtw_phl_get_sta_mgnt_rssi(struct rtw_phl_stainfo_t * psta)2491 rtw_phl_get_sta_mgnt_rssi(struct rtw_phl_stainfo_t *psta)
2492 {
2493 u8 ret = PHL_MAX_RSSI;
2494
2495 if (psta != NULL) {
2496 ret = psta->hal_sta->rssi_stat.ma_rssi_mgnt;
2497 }
2498
2499 return ret;
2500 }
2501