1*4882a593Smuzhiyun /******************************************************************************
2*4882a593Smuzhiyun *
3*4882a593Smuzhiyun * Copyright(c) 2019 Realtek Corporation.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify it
6*4882a593Smuzhiyun * under the terms of version 2 of the GNU General Public License as
7*4882a593Smuzhiyun * published by the Free Software Foundation.
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, but WITHOUT
10*4882a593Smuzhiyun * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12*4882a593Smuzhiyun * more details.
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun *****************************************************************************/
15*4882a593Smuzhiyun #define _PHL_NOTIFY_C_
16*4882a593Smuzhiyun #include "phl_headers.h"
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #ifdef CONFIG_CMD_DISP
19*4882a593Smuzhiyun struct cmd_notify_param {
20*4882a593Smuzhiyun u8 hw_idx;
21*4882a593Smuzhiyun void *hal_cmd;
22*4882a593Smuzhiyun enum phl_msg_evt_id event;
23*4882a593Smuzhiyun };
24*4882a593Smuzhiyun
_phl_notify_done(void * drv_priv,u8 * cmd,u32 cmd_len,enum rtw_phl_status status)25*4882a593Smuzhiyun static void _phl_notify_done(void *drv_priv, u8 *cmd, u32 cmd_len, enum rtw_phl_status status)
26*4882a593Smuzhiyun {
27*4882a593Smuzhiyun if (cmd) {
28*4882a593Smuzhiyun _os_kmem_free(drv_priv, cmd, cmd_len);
29*4882a593Smuzhiyun cmd = NULL;
30*4882a593Smuzhiyun PHL_INFO("%s.....\n", __func__);
31*4882a593Smuzhiyun }
32*4882a593Smuzhiyun }
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun enum rtw_phl_status
phl_notify_cmd_hdl(struct phl_info_t * phl_info,u8 * param)35*4882a593Smuzhiyun phl_notify_cmd_hdl(struct phl_info_t *phl_info, u8 *param)
36*4882a593Smuzhiyun {
37*4882a593Smuzhiyun struct cmd_notify_param *cmd_notify = (struct cmd_notify_param *)param;
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun if (cmd_notify->event == MSG_EVT_NOTIFY_BB ||
40*4882a593Smuzhiyun cmd_notify->event == MSG_EVT_NOTIFY_RF ||
41*4882a593Smuzhiyun cmd_notify->event == MSG_EVT_NOTIFY_MAC)
42*4882a593Smuzhiyun rtw_hal_cmd_notification(phl_info->hal,
43*4882a593Smuzhiyun cmd_notify->event,
44*4882a593Smuzhiyun cmd_notify->hal_cmd,
45*4882a593Smuzhiyun cmd_notify->hw_idx);
46*4882a593Smuzhiyun else
47*4882a593Smuzhiyun rtw_hal_notification(phl_info->hal, cmd_notify->event, cmd_notify->hw_idx);
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun return RTW_PHL_STATUS_SUCCESS;
50*4882a593Smuzhiyun }
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun 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*4882a593Smuzhiyun rtw_phl_cmd_notify(struct rtw_phl_com_t *phl_com,
54*4882a593Smuzhiyun enum phl_msg_evt_id event,
55*4882a593Smuzhiyun void *hal_cmd,
56*4882a593Smuzhiyun u8 hw_idx)
57*4882a593Smuzhiyun {
58*4882a593Smuzhiyun void *drv = phlcom_to_drvpriv(phl_com);
59*4882a593Smuzhiyun enum rtw_phl_status psts = RTW_PHL_STATUS_FAILURE;
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun struct cmd_notify_param *param = NULL;
62*4882a593Smuzhiyun u32 param_len = 0;
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun param_len = sizeof(struct cmd_notify_param);
65*4882a593Smuzhiyun param = _os_kmem_alloc(drv, param_len);
66*4882a593Smuzhiyun if (param == NULL) {
67*4882a593Smuzhiyun PHL_ERR("%s: alloc param failed!\n", __func__);
68*4882a593Smuzhiyun psts = RTW_PHL_STATUS_RESOURCE;
69*4882a593Smuzhiyun goto error_param;
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun _os_mem_set(drv, param, 0, param_len);
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun param->event = event;
74*4882a593Smuzhiyun param->hw_idx = hw_idx;
75*4882a593Smuzhiyun param->hal_cmd = hal_cmd;
76*4882a593Smuzhiyun psts = phl_cmd_enqueue(phl_com->phl_priv,
77*4882a593Smuzhiyun hw_idx,
78*4882a593Smuzhiyun MSG_EVT_NOTIFY_HAL,
79*4882a593Smuzhiyun (u8 *)param,
80*4882a593Smuzhiyun param_len,
81*4882a593Smuzhiyun _phl_notify_done,
82*4882a593Smuzhiyun PHL_CMD_NO_WAIT,
83*4882a593Smuzhiyun 0);
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun if (is_cmd_failure(psts)) {
86*4882a593Smuzhiyun /* Send cmd success, but wait cmd fail*/
87*4882a593Smuzhiyun psts = RTW_PHL_STATUS_FAILURE;
88*4882a593Smuzhiyun } else if (psts != RTW_PHL_STATUS_SUCCESS) {
89*4882a593Smuzhiyun /* Send cmd fail */
90*4882a593Smuzhiyun _os_kmem_free(drv, param, param_len);
91*4882a593Smuzhiyun psts = RTW_PHL_STATUS_FAILURE;
92*4882a593Smuzhiyun }
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun error_param:
95*4882a593Smuzhiyun return psts;
96*4882a593Smuzhiyun }
97*4882a593Smuzhiyun #endif /* CONFIG_CMD_DISP */
98*4882a593Smuzhiyun
rtw_phl_notification(void * phl,enum phl_msg_evt_id event,struct rtw_wifi_role_t * wrole,bool direct)99*4882a593Smuzhiyun void rtw_phl_notification(void *phl,
100*4882a593Smuzhiyun enum phl_msg_evt_id event,
101*4882a593Smuzhiyun struct rtw_wifi_role_t *wrole,
102*4882a593Smuzhiyun bool direct)
103*4882a593Smuzhiyun {
104*4882a593Smuzhiyun struct phl_info_t *phl_info = (struct phl_info_t *)phl;
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun #ifdef CONFIG_CMD_DISP
107*4882a593Smuzhiyun /**
108*4882a593Smuzhiyun * caller must make sure the current power state is I/O allowable or the
109*4882a593Smuzhiyun * notification have nothing to do with I/O when "direct" is set to true.
110*4882a593Smuzhiyun */
111*4882a593Smuzhiyun if (direct)
112*4882a593Smuzhiyun rtw_hal_notification(phl_info->hal, event, wrole->hw_band);
113*4882a593Smuzhiyun else
114*4882a593Smuzhiyun rtw_phl_cmd_notify(phl_info->phl_com, event, NULL, wrole->hw_band);
115*4882a593Smuzhiyun #else
116*4882a593Smuzhiyun PHL_TRACE(COMP_PHL_DBG, _PHL_INFO_, "%s: not support cmd notify\n",
117*4882a593Smuzhiyun __func__);
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun rtw_hal_notification(phl_info->hal, event, wrole->hw_band);
120*4882a593Smuzhiyun #endif /* CONFIG_CMD_DISP */
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun
rtw_phl_dev_terminate_ntf(void * phl)123*4882a593Smuzhiyun void rtw_phl_dev_terminate_ntf(void *phl)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun struct phl_info_t *phl_info = (struct phl_info_t *)phl;
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun SET_STATUS_FLAG(phl_info->phl_com->dev_state, RTW_DEV_SURPRISE_REMOVAL);
128*4882a593Smuzhiyun phl_disp_eng_notify_shall_stop(phl_info);
129*4882a593Smuzhiyun rtw_hal_notification(phl_info->hal, MSG_EVT_SURPRISE_REMOVE, HW_BAND_MAX);
130*4882a593Smuzhiyun }