xref: /wlan-driver/qca-wifi-host-cmn/wmi/src/wmi_hang_event.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
3*5113495bSYour Name  *
4*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for any
5*5113495bSYour Name  * purpose with or without fee is hereby granted, provided that the above
6*5113495bSYour Name  * copyright notice and this permission notice appear in all copies.
7*5113495bSYour Name  *
8*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*5113495bSYour Name  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*5113495bSYour Name  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11*5113495bSYour Name  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*5113495bSYour Name  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13*5113495bSYour Name  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14*5113495bSYour Name  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*5113495bSYour Name  */
16*5113495bSYour Name #include <qdf_hang_event_notifier.h>
17*5113495bSYour Name #include <qdf_notifier.h>
18*5113495bSYour Name #include <wmi_hang_event.h>
19*5113495bSYour Name #include <wmi_unified_priv.h>
20*5113495bSYour Name #include <qdf_trace.h>
21*5113495bSYour Name 
22*5113495bSYour Name struct wmi_hang_data_fixed_param {
23*5113495bSYour Name 	uint16_t tlv_header; /* tlv tag and length */
24*5113495bSYour Name 	uint32_t event;
25*5113495bSYour Name 	uint32_t data;
26*5113495bSYour Name 	uint64_t time;
27*5113495bSYour Name } qdf_packed;
28*5113495bSYour Name 
29*5113495bSYour Name #define WMI_EVT_HIST 0
30*5113495bSYour Name #define WMI_CMD_HIST 1
31*5113495bSYour Name #define NUM_HANG_WMI_HISTORY 1
32*5113495bSYour Name 
wmi_log_history(struct notifier_block * block,void * data,uint8_t wmi_history)33*5113495bSYour Name static void wmi_log_history(struct notifier_block *block, void *data,
34*5113495bSYour Name 			    uint8_t wmi_history)
35*5113495bSYour Name {
36*5113495bSYour Name 	qdf_notif_block *notif_block = qdf_container_of(block, qdf_notif_block,
37*5113495bSYour Name 							notif_block);
38*5113495bSYour Name 	struct qdf_notifer_data *wmi_hang_data = data;
39*5113495bSYour Name 	int nread, pos, total_len;
40*5113495bSYour Name 	unsigned int wmi_ring_size = NUM_HANG_WMI_HISTORY;
41*5113495bSYour Name 	uint64_t secs, usecs;
42*5113495bSYour Name 	struct wmi_event_debug *wmi_evt;
43*5113495bSYour Name 	struct wmi_unified *wmi_handle;
44*5113495bSYour Name 	struct wmi_log_buf_t *wmi_log;
45*5113495bSYour Name 	struct wmi_hang_data_fixed_param *cmd;
46*5113495bSYour Name 	struct wmi_command_debug *wmi_cmd;
47*5113495bSYour Name 	uint8_t *wmi_buf_ptr;
48*5113495bSYour Name 
49*5113495bSYour Name 	if (!wmi_hang_data)
50*5113495bSYour Name 		return;
51*5113495bSYour Name 
52*5113495bSYour Name 	wmi_handle = notif_block->priv_data;
53*5113495bSYour Name 	if (!wmi_handle)
54*5113495bSYour Name 		return;
55*5113495bSYour Name 
56*5113495bSYour Name 	if (wmi_history == WMI_EVT_HIST)
57*5113495bSYour Name 		wmi_log = &wmi_handle->log_info.wmi_event_log_buf_info;
58*5113495bSYour Name 	else
59*5113495bSYour Name 		wmi_log = &wmi_handle->log_info.wmi_command_log_buf_info;
60*5113495bSYour Name 
61*5113495bSYour Name 	total_len = sizeof(struct wmi_hang_data_fixed_param);
62*5113495bSYour Name 
63*5113495bSYour Name 	if (wmi_log->length <= wmi_ring_size)
64*5113495bSYour Name 		nread = wmi_log->length;
65*5113495bSYour Name 	else
66*5113495bSYour Name 		nread = wmi_ring_size;
67*5113495bSYour Name 
68*5113495bSYour Name 	if (*wmi_log->p_buf_tail_idx == 0)
69*5113495bSYour Name 		/* tail can be 0 after wrap-around */
70*5113495bSYour Name 		pos = wmi_ring_size - 1;
71*5113495bSYour Name 	else
72*5113495bSYour Name 		pos = *wmi_log->p_buf_tail_idx - 1;
73*5113495bSYour Name 
74*5113495bSYour Name 	while (nread--) {
75*5113495bSYour Name 		if (wmi_hang_data->offset + total_len > QDF_WLAN_HANG_FW_OFFSET)
76*5113495bSYour Name 			return;
77*5113495bSYour Name 
78*5113495bSYour Name 		switch (wmi_history) {
79*5113495bSYour Name 		case WMI_EVT_HIST:
80*5113495bSYour Name 			wmi_buf_ptr = (wmi_hang_data->hang_data +
81*5113495bSYour Name 				       wmi_hang_data->offset);
82*5113495bSYour Name 			cmd = ((struct wmi_hang_data_fixed_param *)wmi_buf_ptr);
83*5113495bSYour Name 			QDF_HANG_EVT_SET_HDR(&cmd->tlv_header,
84*5113495bSYour Name 					     HANG_EVT_TAG_WMI_EVT_HIST,
85*5113495bSYour Name 		  QDF_HANG_GET_STRUCT_TLVLEN(struct wmi_hang_data_fixed_param));
86*5113495bSYour Name 		     wmi_evt = &(((struct wmi_event_debug *)wmi_log->buf)[pos]);
87*5113495bSYour Name 			cmd->event = wmi_evt->event;
88*5113495bSYour Name 			qdf_log_timestamp_to_secs(wmi_evt->time, &secs, &usecs);
89*5113495bSYour Name 			cmd->time = secs;
90*5113495bSYour Name 			cmd->data = wmi_evt->data[0];
91*5113495bSYour Name 			break;
92*5113495bSYour Name 		case WMI_CMD_HIST:
93*5113495bSYour Name 			wmi_buf_ptr = (wmi_hang_data->hang_data +
94*5113495bSYour Name 				       wmi_hang_data->offset);
95*5113495bSYour Name 			cmd = ((struct wmi_hang_data_fixed_param *)wmi_buf_ptr);
96*5113495bSYour Name 			QDF_HANG_EVT_SET_HDR(&cmd->tlv_header,
97*5113495bSYour Name 					     HANG_EVT_TAG_WMI_CMD_HIST,
98*5113495bSYour Name 		 QDF_HANG_GET_STRUCT_TLVLEN(struct wmi_hang_data_fixed_param));
99*5113495bSYour Name 		   wmi_cmd = &(((struct wmi_command_debug *)wmi_log->buf)[pos]);
100*5113495bSYour Name 			cmd->event = wmi_cmd->command;
101*5113495bSYour Name 			qdf_log_timestamp_to_secs(wmi_cmd->time, &secs, &usecs);
102*5113495bSYour Name 			cmd->time = secs;
103*5113495bSYour Name 			cmd->data = wmi_cmd->data[0];
104*5113495bSYour Name 			break;
105*5113495bSYour Name 		}
106*5113495bSYour Name 		if (pos == 0)
107*5113495bSYour Name 			pos = wmi_ring_size - 1;
108*5113495bSYour Name 		else
109*5113495bSYour Name 			pos--;
110*5113495bSYour Name 		wmi_hang_data->offset += total_len;
111*5113495bSYour Name 	}
112*5113495bSYour Name }
113*5113495bSYour Name 
wmi_recovery_notifier_call(struct notifier_block * block,unsigned long state,void * data)114*5113495bSYour Name static int wmi_recovery_notifier_call(struct notifier_block *block,
115*5113495bSYour Name 				      unsigned long state,
116*5113495bSYour Name 				      void *data)
117*5113495bSYour Name {
118*5113495bSYour Name 	wmi_log_history(block, data, WMI_EVT_HIST);
119*5113495bSYour Name 	wmi_log_history(block, data, WMI_CMD_HIST);
120*5113495bSYour Name 
121*5113495bSYour Name 	return NOTIFY_OK;
122*5113495bSYour Name }
123*5113495bSYour Name 
124*5113495bSYour Name static qdf_notif_block wmi_recovery_notifier = {
125*5113495bSYour Name 	.notif_block.notifier_call = wmi_recovery_notifier_call,
126*5113495bSYour Name };
127*5113495bSYour Name 
wmi_hang_event_notifier_register(struct wmi_unified * wmi_hdl)128*5113495bSYour Name QDF_STATUS wmi_hang_event_notifier_register(struct wmi_unified *wmi_hdl)
129*5113495bSYour Name {
130*5113495bSYour Name 	wmi_recovery_notifier.priv_data = wmi_hdl;
131*5113495bSYour Name 	return qdf_hang_event_register_notifier(&wmi_recovery_notifier);
132*5113495bSYour Name }
133*5113495bSYour Name 
wmi_hang_event_notifier_unregister(void)134*5113495bSYour Name QDF_STATUS wmi_hang_event_notifier_unregister(void)
135*5113495bSYour Name {
136*5113495bSYour Name 	return qdf_hang_event_unregister_notifier(&wmi_recovery_notifier);
137*5113495bSYour Name }
138