xref: /wlan-dirver/qca-wifi-host-cmn/utils/logging/src/wlan_roam_debug.c (revision a175314c51a4ce5cec2835cc8a8c7dc0c1810915)
1 /*
2  * Copyright (c) 2013-2018 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /*
20  * DOC: Roaming debug log operations routines and global data
21  */
22 
23 #include <qdf_types.h>
24 #include <qdf_atomic.h>
25 #include <qdf_mem.h>
26 #include <qdf_time.h>
27 #include <qdf_trace.h>
28 #include <qdf_module.h>
29 #include <wlan_cmn.h>
30 #include "wlan_roam_debug.h"
31 
32 #ifdef FEATURE_ROAM_DEBUG
33 #ifdef WLAN_LOGGING_BUFFERS_DYNAMICALLY
34 static struct wlan_roam_debug_info *global_wlan_roam_debug_table;
35 
36 /**
37  * wlan_roam_debug_init() - Allocate log buffer dynamically
38  *
39  * Return: none
40  */
41 void wlan_roam_debug_init(void)
42 {
43 	global_wlan_roam_debug_table = vzalloc(
44 				sizeof(*global_wlan_roam_debug_table));
45 
46 	QDF_BUG(global_wlan_roam_debug_table);
47 
48 	if (global_wlan_roam_debug_table) {
49 		qdf_atomic_init(&global_wlan_roam_debug_table->index);
50 		global_wlan_roam_debug_table->num_max_rec =
51 						WLAN_ROAM_DEBUG_MAX_REC;
52 	}
53 }
54 
55 qdf_export_symbol(wlan_roam_debug_init);
56 
57 static inline struct wlan_roam_debug_info *wlan_roam_debug_get_table(void)
58 {
59 	return global_wlan_roam_debug_table;
60 }
61 
62 /**
63  * wlan_roam_debug_deinit() - Free log buffer allocated dynamically
64  *
65  * Return: none
66  */
67 void wlan_roam_debug_deinit(void)
68 {
69 	vfree(global_wlan_roam_debug_table);
70 	global_wlan_roam_debug_table = NULL;
71 }
72 
73 qdf_export_symbol(wlan_roam_debug_deinit);
74 #else /* WLAN_LOGGING_BUFFERS_DYNAMICALLY */
75 /*
76  * wlan roam debug log is stored in this global structure. It can be accessed
77  * without requiring any psoc or vdev context. It will be accessible in
78  * the crash dump without having to dereference complex stack traces.
79  */
80 static struct wlan_roam_debug_info global_wlan_roam_debug_table = {
81 				{ 0 },
82 				WLAN_ROAM_DEBUG_MAX_REC,
83 };
84 
85 static inline struct wlan_roam_debug_info *wlan_roam_debug_get_table(void)
86 {
87 	return &global_wlan_roam_debug_table;
88 }
89 #endif /* WLAN_LOGGING_BUFFERS_DYNAMICALLY */
90 
91 /**
92  * wlan_roam_next_debug_log_index() - atomically increment and wrap around index
93  * @index: address of index to increment
94  * @size: wrap around this value
95  *
96  * Return: new value of index
97  */
98 static int wlan_roam_next_debug_log_index(qdf_atomic_t *index, int size)
99 {
100 	int i = qdf_atomic_inc_return(index);
101 
102 	if (i == WLAN_ROAM_DEBUG_MAX_REC)
103 		qdf_atomic_sub(WLAN_ROAM_DEBUG_MAX_REC, index);
104 	while (i >= size)
105 		i -= WLAN_ROAM_DEBUG_MAX_REC;
106 
107 	return i;
108 }
109 
110 /**
111  * wlan_roam_debug_log() - Add a debug log entry to wlan roam debug records
112  * @vdev_id: vdev identifier
113  * @op: operation identifier
114  * @peer_id: peer id
115  * @mac_addr: mac address of peer, can be NULL
116  * @peer_obj: peer object address, can be NULL
117  * @arg1: extra argument #1
118  * @arg2: extra argument #2
119  *
120  * Return: none
121  */
122 void wlan_roam_debug_log(uint8_t vdev_id, uint8_t op,
123 			uint16_t peer_id, void *mac_addr,
124 			void *peer_obj, uint32_t arg1, uint32_t arg2)
125 {
126 	uint32_t i;
127 	struct wlan_roam_debug_info *dbg_tbl;
128 	struct wlan_roam_debug_rec *rec;
129 
130 	dbg_tbl = wlan_roam_debug_get_table();
131 	if (!dbg_tbl)
132 		return;
133 
134 	i = wlan_roam_next_debug_log_index(
135 				    &dbg_tbl->index,
136 				    WLAN_ROAM_DEBUG_MAX_REC);
137 	rec = &dbg_tbl->rec[i];
138 	rec->time = qdf_get_log_timestamp();
139 	rec->operation = op;
140 	rec->vdev_id = vdev_id;
141 	rec->peer_id = peer_id;
142 	if (mac_addr)
143 		qdf_mem_copy(rec->mac_addr.bytes, mac_addr,
144 			     QDF_MAC_ADDR_SIZE);
145 	else
146 		qdf_mem_zero(rec->mac_addr.bytes,
147 			     QDF_MAC_ADDR_SIZE);
148 	rec->peer_obj = peer_obj;
149 	rec->arg1 = arg1;
150 	rec->arg2 = arg2;
151 }
152 qdf_export_symbol(wlan_roam_debug_log);
153 
154 /**
155  * wlan_roam_debug_string() - convert operation value to printable string
156  * @op: operation identifier
157  *
158  * Return: printable string for the operation
159  */
160 static char *wlan_roam_debug_string(uint32_t op)
161 {
162 	switch (op) {
163 	case DEBUG_PEER_CREATE_SEND:
164 		return "peer create send";
165 	case DEBUG_PEER_CREATE_RESP:
166 		return "peer create resp_event";
167 	case DEBUG_PEER_DELETE_SEND:
168 		return "peer delete send";
169 	case DEBUG_PEER_DELETE_RESP:
170 		return "peer delete resp_event";
171 	case DEBUG_PEER_MAP_EVENT:
172 		return "peer map event";
173 	case DEBUG_PEER_UNMAP_EVENT:
174 		return "peer unmap event";
175 	case DEBUG_PEER_UNREF_DELETE:
176 		return "peer unref delete";
177 	case DEBUG_DELETING_PEER_OBJ:
178 		return "peer obj deleted";
179 	case DEBUG_ROAM_SYNCH_IND:
180 		return "roam synch ind event";
181 	case DEBUG_ROAM_SYNCH_CNF:
182 		return "roam sync conf sent";
183 	case DEBUG_ROAM_SYNCH_FAIL:
184 		return "roam sync fail event";
185 	case DEBUG_ROAM_EVENT:
186 		return "roam event";
187 	case DEBUG_WOW_ROAM_EVENT:
188 		return "wow wakeup roam event";
189 	case DEBUG_BUS_SUSPEND:
190 		return "host suspend";
191 	case DEBUG_BUS_RESUME:
192 		return "host wakeup";
193 	case DEBUG_WOW_REASON:
194 		return "wow wakeup reason";
195 	default:
196 		return "unknown";
197 	}
198 }
199 
200 /**
201  * wlan_roam_debug_dump_table() - Print the wlan roam debug log records
202  * print all the valid debug records in the order of timestamp
203  *
204  * Return: none
205  */
206 void wlan_roam_debug_dump_table(void)
207 {
208 	uint32_t i;
209 	int32_t current_index;
210 	struct wlan_roam_debug_info *dbg_tbl;
211 	struct wlan_roam_debug_rec *dbg_rec;
212 	uint64_t startt = 0;
213 	uint32_t delta;
214 
215 #define DEBUG_CLOCK_TICKS_PER_MSEC 19200
216 
217 	dbg_tbl = wlan_roam_debug_get_table();
218 	if (!dbg_tbl)
219 		return;
220 
221 	current_index = qdf_atomic_read(&dbg_tbl->index);
222 	if (current_index < 0) {
223 		QDF_TRACE(QDF_MODULE_ID_ROAM_DEBUG, QDF_TRACE_LEVEL_ERROR,
224 			  "%s: No records to dump", __func__);
225 		return;
226 	}
227 	QDF_TRACE(QDF_MODULE_ID_ROAM_DEBUG, QDF_TRACE_LEVEL_ERROR,
228 		  "%s: Dumping all records. current index %d",
229 		  __func__, current_index);
230 
231 	i = current_index;
232 	do {
233 		/* wrap around */
234 		i = (i + 1) % WLAN_ROAM_DEBUG_MAX_REC;
235 		dbg_rec = &dbg_tbl->rec[i];
236 		/* skip unused entry */
237 		if (dbg_rec->time == 0)
238 			continue;
239 		if (startt == 0)
240 			startt = dbg_rec->time;
241 
242 		/*
243 		 * Divide by 19200 == right shift 8 bits, then divide by 75
244 		 * 32 bit computation keeps both 32 and 64 bit compilers happy.
245 		 * The value will roll over after approx. 33554 seconds.
246 		 */
247 		delta = (uint32_t) (((dbg_rec->time - startt) >> 8) &
248 				    0xffffffff);
249 		delta = delta / (DEBUG_CLOCK_TICKS_PER_MSEC >> 8);
250 
251 		QDF_TRACE(QDF_MODULE_ID_ROAM_DEBUG, QDF_TRACE_LEVEL_ERROR,
252 			  "index = %5d timestamp = 0x%016llx delta ms = %-12u",
253 			  i, dbg_rec->time, delta);
254 		QDF_TRACE(QDF_MODULE_ID_ROAM_DEBUG, QDF_TRACE_LEVEL_ERROR,
255 			  "info = %-24s vdev_id = %-3d mac addr = %pM",
256 			  wlan_roam_debug_string(dbg_rec->operation),
257 			  (int8_t) dbg_rec->vdev_id, dbg_rec->mac_addr.bytes);
258 		QDF_TRACE(QDF_MODULE_ID_ROAM_DEBUG, QDF_TRACE_LEVEL_ERROR,
259 			  "peer obj = 0x%pK peer_id = %-4d",
260 			  dbg_rec->peer_obj, (int8_t) dbg_rec->peer_id);
261 		QDF_TRACE(QDF_MODULE_ID_ROAM_DEBUG, QDF_TRACE_LEVEL_ERROR,
262 			  "arg1 = 0x%-8x arg2 = 0x%-8x",
263 			  dbg_rec->arg1, dbg_rec->arg2);
264 	} while (i != current_index);
265 }
266 
267 qdf_export_symbol(wlan_roam_debug_dump_table);
268 
269 #endif /* FEATURE_ROAM_DEBUG */
270 
271