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_NOTIFY_C_
16 #include "phl_headers.h"
17
18 #ifdef CONFIG_CMD_DISP
19 struct cmd_notify_param {
20 u8 hw_idx;
21 void *hal_cmd;
22 enum phl_msg_evt_id event;
23 };
24
_phl_notify_done(void * drv_priv,u8 * cmd,u32 cmd_len,enum rtw_phl_status status)25 static void _phl_notify_done(void *drv_priv, u8 *cmd, u32 cmd_len, enum rtw_phl_status status)
26 {
27 if (cmd) {
28 _os_kmem_free(drv_priv, cmd, cmd_len);
29 cmd = NULL;
30 PHL_INFO("%s.....\n", __func__);
31 }
32 }
33
34 enum rtw_phl_status
phl_notify_cmd_hdl(struct phl_info_t * phl_info,u8 * param)35 phl_notify_cmd_hdl(struct phl_info_t *phl_info, u8 *param)
36 {
37 struct cmd_notify_param *cmd_notify = (struct cmd_notify_param *)param;
38
39 if (cmd_notify->event == MSG_EVT_NOTIFY_BB ||
40 cmd_notify->event == MSG_EVT_NOTIFY_RF ||
41 cmd_notify->event == MSG_EVT_NOTIFY_MAC)
42 rtw_hal_cmd_notification(phl_info->hal,
43 cmd_notify->event,
44 cmd_notify->hal_cmd,
45 cmd_notify->hw_idx);
46 else
47 rtw_hal_notification(phl_info->hal, cmd_notify->event, cmd_notify->hw_idx);
48
49 return RTW_PHL_STATUS_SUCCESS;
50 }
51
52 enum rtw_phl_status
rtw_phl_cmd_notify(struct rtw_phl_com_t * phl_com,enum phl_msg_evt_id event,void * hal_cmd,u8 hw_idx)53 rtw_phl_cmd_notify(struct rtw_phl_com_t *phl_com,
54 enum phl_msg_evt_id event,
55 void *hal_cmd,
56 u8 hw_idx)
57 {
58 void *drv = phlcom_to_drvpriv(phl_com);
59 enum rtw_phl_status psts = RTW_PHL_STATUS_FAILURE;
60
61 struct cmd_notify_param *param = NULL;
62 u32 param_len = 0;
63
64 param_len = sizeof(struct cmd_notify_param);
65 param = _os_kmem_alloc(drv, param_len);
66 if (param == NULL) {
67 PHL_ERR("%s: alloc param failed!\n", __func__);
68 psts = RTW_PHL_STATUS_RESOURCE;
69 goto error_param;
70 }
71 _os_mem_set(drv, param, 0, param_len);
72
73 param->event = event;
74 param->hw_idx = hw_idx;
75 param->hal_cmd = hal_cmd;
76 psts = phl_cmd_enqueue(phl_com->phl_priv,
77 hw_idx,
78 MSG_EVT_NOTIFY_HAL,
79 (u8 *)param,
80 param_len,
81 _phl_notify_done,
82 PHL_CMD_NO_WAIT,
83 0);
84
85 if (is_cmd_failure(psts)) {
86 /* Send cmd success, but wait cmd fail*/
87 psts = RTW_PHL_STATUS_FAILURE;
88 } else if (psts != RTW_PHL_STATUS_SUCCESS) {
89 /* Send cmd fail */
90 _os_kmem_free(drv, param, param_len);
91 psts = RTW_PHL_STATUS_FAILURE;
92 }
93
94 error_param:
95 return psts;
96 }
97 #endif /* CONFIG_CMD_DISP */
98
rtw_phl_notification(void * phl,enum phl_msg_evt_id event,struct rtw_wifi_role_t * wrole,bool direct)99 void rtw_phl_notification(void *phl,
100 enum phl_msg_evt_id event,
101 struct rtw_wifi_role_t *wrole,
102 bool direct)
103 {
104 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
105
106 #ifdef CONFIG_CMD_DISP
107 /**
108 * caller must make sure the current power state is I/O allowable or the
109 * notification have nothing to do with I/O when "direct" is set to true.
110 */
111 if (direct)
112 rtw_hal_notification(phl_info->hal, event, wrole->hw_band);
113 else
114 rtw_phl_cmd_notify(phl_info->phl_com, event, NULL, wrole->hw_band);
115 #else
116 PHL_TRACE(COMP_PHL_DBG, _PHL_INFO_, "%s: not support cmd notify\n",
117 __func__);
118
119 rtw_hal_notification(phl_info->hal, event, wrole->hw_band);
120 #endif /* CONFIG_CMD_DISP */
121 }
122
rtw_phl_dev_terminate_ntf(void * phl)123 void rtw_phl_dev_terminate_ntf(void *phl)
124 {
125 struct phl_info_t *phl_info = (struct phl_info_t *)phl;
126
127 SET_STATUS_FLAG(phl_info->phl_com->dev_state, RTW_DEV_SURPRISE_REMOVAL);
128 phl_disp_eng_notify_shall_stop(phl_info);
129 rtw_hal_notification(phl_info->hal, MSG_EVT_SURPRISE_REMOVE, HW_BAND_MAX);
130 }