hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/******************************************************************************
 *
 * Copyright(c) 2019 Realtek Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 *****************************************************************************/
#define _PHL_WATCHDOG_C_
#include "phl_headers.h"
 
#ifdef CONFIG_FSM
static void _phl_datapath_watchdog(struct phl_info_t *phl_info)
{
   phl_tx_watchdog(phl_info);
   phl_rx_watchdog(phl_info);
   phl_sta_trx_tfc_upd(phl_info);
}
 
void rtw_phl_watchdog_callback(void *phl)
{
   struct phl_info_t *phl_info = (struct phl_info_t *)phl;
   do {
       _phl_datapath_watchdog(phl_info);
       #ifdef CONFIG_PCI_HCI
       #ifdef RTW_WKARD_DYNAMIC_LTR
       phl_ltr_ctrl_watchdog(phl_info);
       #endif
       #ifdef PCIE_TRX_MIT_EN
       phl_pcie_trx_mit_watchdog(phl_info);
       #endif
       #endif
       phl_mr_watchdog(phl_info);
       rtw_hal_watchdog(phl_info->hal);
   } while (false);
}
#endif
 
static void _phl_watchdog_sw(struct phl_info_t *phl)
{
   /* Only sw statistics or sw behavior or trigger FG cmd */
   phl_tx_watchdog(phl);
   phl_rx_watchdog(phl);
   phl_sta_trx_tfc_upd(phl);
}
 
static void _phl_watchdog_hw(struct phl_info_t *phl)
{
   #ifdef CONFIG_PHL_THERMAL_PROTECT
   phl_thermal_protect_watchdog(phl);
   #endif
 
   /* I/O, tx behavior, request power, ... */
   #ifdef CONFIG_PCI_HCI
   #ifdef RTW_WKARD_DYNAMIC_LTR
   phl_ltr_ctrl_watchdog(phl);
   #endif
   #ifdef PCIE_TRX_MIT_EN
   phl_pcie_trx_mit_watchdog(phl);
   #endif
   #endif
 
   phl_mr_watchdog(phl);
   rtw_hal_watchdog(phl->hal);
   phl_bcn_watchdog(phl);
}
 
#ifdef CONFIG_CMD_DISP
static void _phl_watchdog_post_action(struct phl_info_t *phl_info)
{
#ifdef CONFIG_POWER_SAVE
   rtw_hal_ps_chk_hw_rf_state(phl_info->phl_com, phl_info->hal);
#endif /* CONFIG_POWER_SAVE */
}
 
static void _phl_trigger_next_watchdog(struct phl_info_t *phl_info)
{
   struct phl_watchdog *wdog = &(phl_info->wdog);
 
   if (wdog->state == WD_STATE_STARTED)
       _os_set_timer(phl_to_drvpriv(phl_info), &wdog->wdog_timer, wdog->period);
}
 
static void _phl_watchdog_hw_done(void *drv_priv, u8 *cmd, u32 cmd_len, enum rtw_phl_status status)
{
   struct phl_info_t *phl_info = (struct phl_info_t *)cmd;
 
   _phl_watchdog_post_action(phl_info);
   _phl_trigger_next_watchdog(phl_info);
}
 
static enum rtw_phl_status
_phl_watchdog_hw_cmd(struct phl_info_t *phl_info,
                  enum phl_cmd_type cmd_type,
                  u32 cmd_timeout)
{
   enum rtw_phl_status phl_status = RTW_PHL_STATUS_FAILURE;
 
   if (cmd_type == PHL_CMD_DIRECTLY) {
       phl_status = phl_watchdog_hw_cmd_hdl(phl_info, RTW_PHL_STATUS_SUCCESS);
       goto _exit;
   }
 
   /* watchdog dont care hw_band */
   phl_status = phl_cmd_enqueue(phl_info,
                                HW_BAND_0,
                                MSG_EVT_HW_WATCHDOG,
                                (u8 *)phl_info,
                                0,
                                _phl_watchdog_hw_done,
                                cmd_type,
                                cmd_timeout);
 
   if (is_cmd_failure(phl_status)) {
       /* Send cmd success, but wait cmd fail*/
   } else if (phl_status != RTW_PHL_STATUS_SUCCESS) {
       /* Send cmd fail */
       phl_status = RTW_PHL_STATUS_FAILURE;
   }
 
 
_exit:
   return phl_status;
}
 
static void _phl_watchdog_sw_done(void *drv_priv, u8 *cmd, u32 cmd_len, enum rtw_phl_status status)
{
   struct phl_info_t *phl_info = (struct phl_info_t *)cmd;
   enum rtw_phl_status psts = RTW_PHL_STATUS_FAILURE;
   bool set_timer = true;
 
   if (true == phl_disp_eng_is_fg_empty(phl_info, HW_BAND_MAX)) {
 
       /* send watchdog cmd to request privilege of I/O */
       psts = _phl_watchdog_hw_cmd(phl_info, PHL_CMD_NO_WAIT, 0);
       if (psts != RTW_PHL_STATUS_FAILURE)
           set_timer = false;
   } else {
       PHL_TRACE(COMP_PHL_DBG, _PHL_DEBUG_, "%s: skip watchdog\n",
                 __FUNCTION__);
   }
 
   if (set_timer)
       _phl_trigger_next_watchdog(phl_info);
}
 
static enum rtw_phl_status
_phl_watchdog_sw_cmd(struct phl_info_t *phl_info,
                  enum phl_cmd_type cmd_type,
                  u32 cmd_timeout)
{
   enum rtw_phl_status phl_status = RTW_PHL_STATUS_FAILURE;
 
   if (cmd_type == PHL_CMD_DIRECTLY) {
       phl_status = phl_watchdog_sw_cmd_hdl(phl_info, RTW_PHL_STATUS_SUCCESS);
       goto _exit;
   }
 
   /* watchdog dont care hw_band */
   phl_status = phl_cmd_enqueue(phl_info,
                                HW_BAND_0,
                                MSG_EVT_SW_WATCHDOG,
                                (u8 *)phl_info,
                                0,
                                _phl_watchdog_sw_done,
                                cmd_type,
                                cmd_timeout);
 
   if (is_cmd_failure(phl_status)) {
       /* Send cmd success, but wait cmd fail*/
   } else if (phl_status != RTW_PHL_STATUS_SUCCESS) {
       /* Send cmd fail */
       phl_status = RTW_PHL_STATUS_FAILURE;
   }
 
 
_exit:
   return phl_status;
}
#endif
 
static void _phl_watchdog_timer_expired(void *context)
{
#ifdef CONFIG_CMD_DISP
   struct phl_info_t *phl_info = (struct phl_info_t *)context;
   enum rtw_phl_status psts = RTW_PHL_STATUS_FAILURE;
   bool set_timer = true;
 
   /* phl sw watchdog */
   _phl_watchdog_sw(phl_info);
   psts = _phl_watchdog_sw_cmd(phl_info, PHL_CMD_NO_WAIT, 0);
   if (psts != RTW_PHL_STATUS_FAILURE)
       set_timer = false;
 
   if (set_timer)
       _phl_trigger_next_watchdog(phl_info);
#else
   PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "%s: Not support watchdog\n", __FUNCTION__);
#endif
}
 
enum rtw_phl_status
phl_watchdog_hw_cmd_hdl(struct phl_info_t *phl_info, enum rtw_phl_status psts)
{
   struct phl_watchdog *wdog = &(phl_info->wdog);
 
   if (false == is_cmd_failure(psts)) {
       _phl_watchdog_hw(phl_info);
 
       if (NULL != wdog->core_hw_wdog)
           wdog->core_hw_wdog(phl_to_drvpriv(phl_info));
   }
 
   return RTW_PHL_STATUS_SUCCESS;
}
 
enum rtw_phl_status
phl_watchdog_sw_cmd_hdl(struct phl_info_t *phl_info, enum rtw_phl_status psts)
{
   struct phl_watchdog *wdog = &(phl_info->wdog);
 
   if (false == is_cmd_failure(psts)) {
       if (NULL != wdog->core_sw_wdog)
           wdog->core_sw_wdog(phl_to_drvpriv(phl_info));
   }
 
   return RTW_PHL_STATUS_SUCCESS;
}
 
void rtw_phl_watchdog_init(void *phl,
                           u16 period,
                           void (*core_sw_wdog)(void *drv_priv),
                           void (*core_hw_wdog)(void *drv_priv))
{
   struct phl_info_t *phl_info = (struct phl_info_t *)phl;
   struct phl_watchdog *wdog = &(phl_info->wdog);
 
   wdog->state = WD_STATE_INIT;
   wdog->core_sw_wdog = core_sw_wdog;
   wdog->core_hw_wdog = core_hw_wdog;
 
   if (period > 0)
       wdog->period = period;
   else
       wdog->period = WDOG_PERIOD;
 
   _os_init_timer(phl_to_drvpriv(phl_info),
                  &wdog->wdog_timer,
                  _phl_watchdog_timer_expired,
                  phl,
                  "phl_watchdog_timer");
}
 
void rtw_phl_watchdog_deinit(void *phl)
{
   struct phl_info_t *phl_info = (struct phl_info_t *)phl;
   struct phl_watchdog *wdog = &(phl_info->wdog);
 
   _os_release_timer(phl_to_drvpriv(phl_info), &wdog->wdog_timer);
}
 
void rtw_phl_watchdog_start(void *phl)
{
   struct phl_info_t *phl_info = (struct phl_info_t *)phl;
   struct phl_watchdog *wdog = &(phl_info->wdog);
 
   wdog->state = WD_STATE_STARTED;
   _phl_trigger_next_watchdog(phl_info);
}
 
void rtw_phl_watchdog_stop(void *phl)
{
   struct phl_info_t *phl_info = (struct phl_info_t *)phl;
   struct phl_watchdog *wdog = &(phl_info->wdog);
 
   PHL_INFO("%s\n", __func__);
 
   wdog->state = WD_STATE_STOP;
 
   _os_cancel_timer(phl_to_drvpriv(phl_info), &wdog->wdog_timer);
}