xref: /OK3568_Linux_fs/external/rkwifibt/drivers/infineon/dhd_debug.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * DHD debugability header file
3  *
4  * <<Broadcom-WL-IPTag/Open:>>
5  *
6  * Portions of this code are copyright (c) 2021 Cypress Semiconductor Corporation
7  *
8  * Copyright (C) 1999-2017, Broadcom Corporation
9  *
10  *      Unless you and Broadcom execute a separate written software license
11  * agreement governing use of this software, this software is licensed to you
12  * under the terms of the GNU General Public License version 2 (the "GPL"),
13  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
14  * following added to such license:
15  *
16  *      As a special exception, the copyright holders of this software give you
17  * permission to link this software with independent modules, and to copy and
18  * distribute the resulting executable under terms of your choice, provided that
19  * you also meet, for each linked independent module, the terms and conditions of
20  * the license of that module.  An independent module is a module which is not
21  * derived from this software.  The special exception does not apply to any
22  * modifications of the software.
23  *
24  *      Notwithstanding the above, under no circumstances may you combine this
25  * software in any way with any other Broadcom software provided under a license
26  * other than the GPL, without Broadcom's express prior written consent.
27  *
28  * $Id: dhd_debug.h 701031 2017-05-23 11:19:09Z $
29  */
30 
31 #ifndef _dhd_debug_h_
32 #define _dhd_debug_h_
33 #include <event_log.h>
34 #include <bcmutils.h>
35 #include <dhd_dbg_ring.h>
36 
37 enum {
38 	DEBUG_RING_ID_INVALID	= 0,
39 	FW_VERBOSE_RING_ID,
40 	DHD_EVENT_RING_ID,
41 	/* add new id here */
42 	DEBUG_RING_ID_MAX
43 };
44 
45 enum {
46 	/* Feature set */
47 	DBG_MEMORY_DUMP_SUPPORTED = (1 << (0)), /* Memory dump of FW */
48 	DBG_PER_PACKET_TX_RX_STATUS_SUPPORTED = (1 << (1)), /* PKT Status */
49 	DBG_CONNECT_EVENT_SUPPORTED = (1 << (2)), /* Connectivity Event */
50 	DBG_POWER_EVENT_SUPOORTED = (1 << (3)), /* POWER of Driver */
51 	DBG_WAKE_LOCK_SUPPORTED = (1 << (4)), /* WAKE LOCK of Driver */
52 	DBG_VERBOSE_LOG_SUPPORTED = (1 << (5)), /* verbose log of FW */
53 	DBG_HEALTH_CHECK_SUPPORTED = (1 << (6)), /* monitor the health of FW */
54 	DBG_DRIVER_DUMP_SUPPORTED = (1 << (7)), /* dumps driver state */
55 	DBG_PACKET_FATE_SUPPORTED = (1 << (8)), /* tracks connection packets' fate */
56 	DBG_NAN_EVENT_SUPPORTED = (1 << (9)), /* NAN Events */
57 };
58 
59 enum {
60 	/* set for binary entries */
61 	DBG_RING_ENTRY_FLAGS_HAS_BINARY = (1 << (0)),
62 	/* set if 64 bits timestamp is present */
63 	DBG_RING_ENTRY_FLAGS_HAS_TIMESTAMP = (1 << (1))
64 };
65 
66 /* firmware verbose ring, ring id 1 */
67 #define FW_VERBOSE_RING_NAME		"fw_verbose"
68 #define FW_VERBOSE_RING_SIZE		(256 * 1024)
69 /* firmware event ring, ring id 2 */
70 #define FW_EVENT_RING_NAME		"fw_event"
71 #define FW_EVENT_RING_SIZE		(64 * 1024)
72 /* DHD connection event ring, ring id 3 */
73 #define DHD_EVENT_RING_NAME		"dhd_event"
74 #define DHD_EVENT_RING_SIZE		(64 * 1024)
75 /* NAN event ring, ring id 4 */
76 #define NAN_EVENT_RING_NAME		"nan_event"
77 #define NAN_EVENT_RING_SIZE		(64 * 1024)
78 
79 #define TLV_LOG_SIZE(tlv) ((tlv) ? (sizeof(tlv_log) + (tlv)->len) : 0)
80 
81 #define TLV_LOG_NEXT(tlv) \
82 	((tlv) ? ((tlv_log *)((uint8 *)tlv + TLV_LOG_SIZE(tlv))) : 0)
83 
84 #define VALID_RING(id)	\
85 	((id > DEBUG_RING_ID_INVALID) && (id < DEBUG_RING_ID_MAX))
86 
87 #ifdef DEBUGABILITY
88 #define DBG_RING_ACTIVE(dhdp, ring_id) \
89 	((dhdp)->dbg->dbg_rings[(ring_id)].state == RING_ACTIVE)
90 #else
91 #define DBG_RING_ACTIVE(dhdp, ring_id) 0
92 #endif /* DEBUGABILITY */
93 
94 enum {
95 	/* driver receive association command from kernel */
96 	WIFI_EVENT_ASSOCIATION_REQUESTED	= 0,
97 	WIFI_EVENT_AUTH_COMPLETE,
98 	WIFI_EVENT_ASSOC_COMPLETE,
99 	/* received firmware event indicating auth frames are sent */
100 	WIFI_EVENT_FW_AUTH_STARTED,
101 	/* received firmware event indicating assoc frames are sent */
102 	WIFI_EVENT_FW_ASSOC_STARTED,
103 	/* received firmware event indicating reassoc frames are sent */
104 	WIFI_EVENT_FW_RE_ASSOC_STARTED,
105 	WIFI_EVENT_DRIVER_SCAN_REQUESTED,
106 	WIFI_EVENT_DRIVER_SCAN_RESULT_FOUND,
107 	WIFI_EVENT_DRIVER_SCAN_COMPLETE,
108 	WIFI_EVENT_G_SCAN_STARTED,
109 	WIFI_EVENT_G_SCAN_COMPLETE,
110 	WIFI_EVENT_DISASSOCIATION_REQUESTED,
111 	WIFI_EVENT_RE_ASSOCIATION_REQUESTED,
112 	WIFI_EVENT_ROAM_REQUESTED,
113 	/* received beacon from AP (event enabled only in verbose mode) */
114 	WIFI_EVENT_BEACON_RECEIVED,
115 	/* firmware has triggered a roam scan (not g-scan) */
116 	WIFI_EVENT_ROAM_SCAN_STARTED,
117 	/* firmware has completed a roam scan (not g-scan) */
118 	WIFI_EVENT_ROAM_SCAN_COMPLETE,
119 	/* firmware has started searching for roam candidates (with reason =xx) */
120 	WIFI_EVENT_ROAM_SEARCH_STARTED,
121 	/* firmware has stopped searching for roam candidates (with reason =xx) */
122 	WIFI_EVENT_ROAM_SEARCH_STOPPED,
123 	WIFI_EVENT_UNUSED_0,
124 	/* received channel switch anouncement from AP */
125 	WIFI_EVENT_CHANNEL_SWITCH_ANOUNCEMENT,
126 	/* fw start transmit eapol frame, with EAPOL index 1-4 */
127 	WIFI_EVENT_FW_EAPOL_FRAME_TRANSMIT_START,
128 	/* fw gives up eapol frame, with rate, success/failure and number retries */
129 	WIFI_EVENT_FW_EAPOL_FRAME_TRANSMIT_STOP,
130 	/* kernel queue EAPOL for transmission in driver with EAPOL index 1-4 */
131 	WIFI_EVENT_DRIVER_EAPOL_FRAME_TRANSMIT_REQUESTED,
132 	/* with rate, regardless of the fact that EAPOL frame is accepted or
133 	 * rejected by firmware
134 	 */
135 	WIFI_EVENT_FW_EAPOL_FRAME_RECEIVED,
136 	WIFI_EVENT_UNUSED_1,
137 	/* with rate, and eapol index, driver has received */
138 	/* EAPOL frame and will queue it up to wpa_supplicant */
139 	WIFI_EVENT_DRIVER_EAPOL_FRAME_RECEIVED,
140 	/* with success/failure, parameters */
141 	WIFI_EVENT_BLOCK_ACK_NEGOTIATION_COMPLETE,
142 	WIFI_EVENT_BT_COEX_BT_SCO_START,
143 	WIFI_EVENT_BT_COEX_BT_SCO_STOP,
144 	/* for paging/scan etc..., when BT starts transmiting twice per BT slot */
145 	WIFI_EVENT_BT_COEX_BT_SCAN_START,
146 	WIFI_EVENT_BT_COEX_BT_SCAN_STOP,
147 	WIFI_EVENT_BT_COEX_BT_HID_START,
148 	WIFI_EVENT_BT_COEX_BT_HID_STOP,
149 	/* firmware sends auth frame in roaming to next candidate */
150 	WIFI_EVENT_ROAM_AUTH_STARTED,
151 	/* firmware receive auth confirm from ap */
152 	WIFI_EVENT_ROAM_AUTH_COMPLETE,
153 	/* firmware sends assoc/reassoc frame in */
154 	WIFI_EVENT_ROAM_ASSOC_STARTED,
155 	/* firmware receive assoc/reassoc confirm from ap */
156 	WIFI_EVENT_ROAM_ASSOC_COMPLETE,
157 	/* firmware sends stop G_SCAN */
158 	WIFI_EVENT_G_SCAN_STOP,
159 	/* firmware indicates G_SCAN scan cycle started */
160 	WIFI_EVENT_G_SCAN_CYCLE_STARTED,
161 	/* firmware indicates G_SCAN scan cycle completed */
162 	WIFI_EVENT_G_SCAN_CYCLE_COMPLETED,
163 	/* firmware indicates G_SCAN scan start for a particular bucket */
164 	WIFI_EVENT_G_SCAN_BUCKET_STARTED,
165 	/* firmware indicates G_SCAN scan completed for particular bucket */
166 	WIFI_EVENT_G_SCAN_BUCKET_COMPLETED,
167 	/* Event received from firmware about G_SCAN scan results being available */
168 	WIFI_EVENT_G_SCAN_RESULTS_AVAILABLE,
169 	/* Event received from firmware with G_SCAN capabilities */
170 	WIFI_EVENT_G_SCAN_CAPABILITIES,
171 	/* Event received from firmware when eligible candidate is found */
172 	WIFI_EVENT_ROAM_CANDIDATE_FOUND,
173 	/* Event received from firmware when roam scan configuration gets enabled or disabled */
174 	WIFI_EVENT_ROAM_SCAN_CONFIG,
175 	/* firmware/driver timed out authentication */
176 	WIFI_EVENT_AUTH_TIMEOUT,
177 	/* firmware/driver timed out association */
178 	WIFI_EVENT_ASSOC_TIMEOUT,
179 	/* firmware/driver encountered allocation failure */
180 	WIFI_EVENT_MEM_ALLOC_FAILURE,
181 	/* driver added a PNO network in firmware */
182 	WIFI_EVENT_DRIVER_PNO_ADD,
183 	/* driver removed a PNO network in firmware */
184 	WIFI_EVENT_DRIVER_PNO_REMOVE,
185 	/* driver received PNO networks found indication from firmware */
186 	WIFI_EVENT_DRIVER_PNO_NETWORK_FOUND,
187 	/* driver triggered a scan for PNO networks */
188 	WIFI_EVENT_DRIVER_PNO_SCAN_REQUESTED,
189 	/* driver received scan results of PNO networks */
190 	WIFI_EVENT_DRIVER_PNO_SCAN_RESULT_FOUND,
191 	/* driver updated scan results from PNO candidates to cfg */
192 	WIFI_EVENT_DRIVER_PNO_SCAN_COMPLETE
193 };
194 
195 enum {
196 	WIFI_TAG_VENDOR_SPECIFIC = 0, /* take a byte stream as parameter */
197 	WIFI_TAG_BSSID, /* takes a 6 bytes MAC address as parameter */
198 	WIFI_TAG_ADDR, /* takes a 6 bytes MAC address as parameter */
199 	WIFI_TAG_SSID, /* takes a 32 bytes SSID address as parameter */
200 	WIFI_TAG_STATUS, /* takes an integer as parameter */
201 	WIFI_TAG_CHANNEL_SPEC, /* takes one or more wifi_channel_spec as parameter */
202 	WIFI_TAG_WAKE_LOCK_EVENT, /* takes a wake_lock_event struct as parameter */
203 	WIFI_TAG_ADDR1, /* takes a 6 bytes MAC address as parameter */
204 	WIFI_TAG_ADDR2, /* takes a 6 bytes MAC address as parameter */
205 	WIFI_TAG_ADDR3, /* takes a 6 bytes MAC address as parameter */
206 	WIFI_TAG_ADDR4, /* takes a 6 bytes MAC address as parameter */
207 	WIFI_TAG_TSF, /* take a 64 bits TSF value as parameter */
208 	WIFI_TAG_IE,
209 	/* take one or more specific 802.11 IEs parameter, IEs are in turn
210 	 * indicated in TLV format as per 802.11 spec
211 	 */
212 	WIFI_TAG_INTERFACE,	/* take interface name as parameter */
213 	WIFI_TAG_REASON_CODE,	/* take a reason code as per 802.11 as parameter */
214 	WIFI_TAG_RATE_MBPS,	/* take a wifi rate in 0.5 mbps */
215 	WIFI_TAG_REQUEST_ID,	/* take an integer as parameter */
216 	WIFI_TAG_BUCKET_ID,	/* take an integer as parameter */
217 	WIFI_TAG_GSCAN_PARAMS,	/* takes a wifi_scan_cmd_params struct as parameter */
218 	WIFI_TAG_GSCAN_CAPABILITIES, /* takes a wifi_gscan_capabilities struct as parameter */
219 	WIFI_TAG_SCAN_ID,	/* take an integer as parameter */
220 	WIFI_TAG_RSSI,		/* takes s16 as parameter */
221 	WIFI_TAG_CHANNEL,	/* takes u16 as parameter */
222 	WIFI_TAG_LINK_ID,	/* take an integer as parameter */
223 	WIFI_TAG_LINK_ROLE,	/* take an integer as parameter */
224 	WIFI_TAG_LINK_STATE,	/* take an integer as parameter */
225 	WIFI_TAG_LINK_TYPE,	/* take an integer as parameter */
226 	WIFI_TAG_TSCO,		/* take an integer as parameter */
227 	WIFI_TAG_RSCO,		/* take an integer as parameter */
228 	WIFI_TAG_EAPOL_MESSAGE_TYPE /* take an integer as parameter */
229 };
230 
231 /* NAN  events */
232 typedef enum {
233 	NAN_EVENT_INVALID = 0,
234 	NAN_EVENT_CLUSTER_STARTED = 1,
235 	NAN_EVENT_CLUSTER_JOINED = 2,
236 	NAN_EVENT_CLUSTER_MERGED = 3,
237 	NAN_EVENT_ROLE_CHANGED = 4,
238 	NAN_EVENT_SCAN_COMPLETE = 5,
239 	NAN_EVENT_STATUS_CHNG  = 6,
240 	/* ADD new events before this line */
241 	NAN_EVENT_MAX
242 } nan_event_id_t;
243 
244 typedef struct {
245     uint16 tag;
246     uint16 len; /* length of value */
247     uint8 value[0];
248 } tlv_log;
249 
250 typedef struct per_packet_status_entry {
251     uint8 flags;
252     uint8 tid; /* transmit or received tid */
253     uint16 MCS; /* modulation and bandwidth */
254 	/*
255 	* TX: RSSI of ACK for that packet
256 	* RX: RSSI of packet
257 	*/
258     uint8 rssi;
259     uint8 num_retries; /* number of attempted retries */
260     uint16 last_transmit_rate; /* last transmit rate in .5 mbps */
261 	 /* transmit/reeive sequence for that MPDU packet */
262     uint16 link_layer_transmit_sequence;
263 	/*
264 	* TX: firmware timestamp (us) when packet is queued within firmware buffer
265 	* for SDIO/HSIC or into PCIe buffer
266 	* RX : firmware receive timestamp
267 	*/
268     uint64 firmware_entry_timestamp;
269 	/*
270 	* firmware timestamp (us) when packet start contending for the
271 	* medium for the first time, at head of its AC queue,
272 	* or as part of an MPDU or A-MPDU. This timestamp is not updated
273 	* for each retry, only the first transmit attempt.
274 	*/
275     uint64 start_contention_timestamp;
276 	/*
277 	* fimrware timestamp (us) when packet is successfully transmitted
278 	* or aborted because it has exhausted its maximum number of retries
279 	*/
280 	uint64 transmit_success_timestamp;
281 	/*
282 	* packet data. The length of packet data is determined by the entry_size field of
283 	* the wifi_ring_buffer_entry structure. It is expected that first bytes of the
284 	* packet, or packet headers only (up to TCP or RTP/UDP headers) will be copied into the ring
285 	*/
286     uint8 *data;
287 } per_packet_status_entry_t;
288 
289 #define PACKED_STRUCT __attribute__ ((packed))
290 
291 typedef struct log_conn_event {
292     uint16 event;
293     tlv_log *tlvs;
294 	/*
295 	* separate parameter structure per event to be provided and optional data
296 	* the event_data is expected to include an official android part, with some
297 	* parameter as transmit rate, num retries, num scan result found etc...
298 	* as well, event_data can include a vendor proprietary part which is
299 	* understood by the developer only.
300 	*/
301 } PACKED_STRUCT log_conn_event_t;
302 
303 /*
304  * Ring buffer name for power events ring. note that power event are extremely frequents
305  * and thus should be stored in their own ring/file so as not to clobber connectivity events
306  */
307 
308 typedef struct wake_lock_event {
309     uint32 status; /* 0 taken, 1 released */
310     uint32 reason; /* reason why this wake lock is taken */
311     char *name; /* null terminated */
312 } wake_lock_event_t;
313 
314 typedef struct wifi_power_event {
315     uint16 event;
316     tlv_log *tlvs;
317 } wifi_power_event_t;
318 
319 #define NAN_EVENT_VERSION 1
320 typedef struct log_nan_event {
321     uint8 version;
322     uint8 pad;
323     uint16 event;
324     tlv_log *tlvs;
325 } log_nan_event_t;
326 
327 /* entry type */
328 enum {
329 	DBG_RING_ENTRY_EVENT_TYPE = 1,
330 	DBG_RING_ENTRY_PKT_TYPE,
331 	DBG_RING_ENTRY_WAKE_LOCK_EVENT_TYPE,
332 	DBG_RING_ENTRY_POWER_EVENT_TYPE,
333 	DBG_RING_ENTRY_DATA_TYPE,
334 	DBG_RING_ENTRY_NAN_EVENT_TYPE
335 };
336 
337 struct log_level_table {
338 	int log_level;
339 	uint16 tag;
340 	char *desc;
341 };
342 
343 #ifdef OEM_ANDROID
344 /*
345  * Assuming that the Ring lock is mutex, bailing out if the
346  * callers are from atomic context. On a long term, one has to
347  * schedule a job to execute in sleepable context so that
348  * contents are pushed to the ring.
349  */
350 #define DBG_EVENT_LOG(dhdp, connect_state)					\
351 {										\
352 	do {									\
353 		uint16 state = connect_state;					\
354 		if (CAN_SLEEP() && DBG_RING_ACTIVE(dhdp, DHD_EVENT_RING_ID))			\
355 			dhd_os_push_push_ring_data(dhdp, DHD_EVENT_RING_ID,	\
356 				&state, sizeof(state));				\
357 	} while (0);								\
358 }
359 #else
360 #define DBG_EVENT_LOG(dhd, connect_state)
361 #endif /* !OEM_ANDROID */
362 
363 #define MD5_PREFIX_LEN				4
364 #define MAX_FATE_LOG_LEN			32
365 #define MAX_FRAME_LEN_ETHERNET		1518
366 #define MAX_FRAME_LEN_80211_MGMT	2352 /* 802.11-2012 Fig. 8-34 */
367 
368 typedef enum {
369 	/* Sent over air and ACKed. */
370 	TX_PKT_FATE_ACKED,
371 
372 	/* Sent over air but not ACKed. (Normal for broadcast/multicast.) */
373 	TX_PKT_FATE_SENT,
374 
375 	/* Queued within firmware, but not yet sent over air. */
376 	TX_PKT_FATE_FW_QUEUED,
377 
378 	/*
379 	 * Dropped by firmware as invalid. E.g. bad source address,
380 	 * bad checksum, or invalid for current state.
381 	 */
382 	TX_PKT_FATE_FW_DROP_INVALID,
383 
384 	/* Dropped by firmware due to lifetime expiration. */
385 	TX_PKT_FATE_FW_DROP_EXPTIME,
386 
387 	/*
388 	 * Dropped by firmware for any other reason. Includes
389 	 * frames that were sent by driver to firmware, but
390 	 * unaccounted for by firmware.
391 	 */
392 	TX_PKT_FATE_FW_DROP_OTHER,
393 
394 	/* Queued within driver, not yet sent to firmware. */
395 	TX_PKT_FATE_DRV_QUEUED,
396 
397 	/*
398 	 * Dropped by driver as invalid. E.g. bad source address,
399 	 * or invalid for current state.
400 	 */
401 	TX_PKT_FATE_DRV_DROP_INVALID,
402 
403 	/* Dropped by driver due to lack of buffer space. */
404 	TX_PKT_FATE_DRV_DROP_NOBUFS,
405 
406 	/*  Dropped by driver for any other reason. */
407 	TX_PKT_FATE_DRV_DROP_OTHER,
408 
409 	/* Packet free by firmware. */
410 	TX_PKT_FATE_FW_PKT_FREE,
411 
412 	} wifi_tx_packet_fate;
413 
414 typedef enum {
415 	/* Valid and delivered to network stack (e.g., netif_rx()). */
416 	RX_PKT_FATE_SUCCESS,
417 
418 	/* Queued within firmware, but not yet sent to driver. */
419 	RX_PKT_FATE_FW_QUEUED,
420 
421 	/* Dropped by firmware due to host-programmable filters. */
422 	RX_PKT_FATE_FW_DROP_FILTER,
423 
424 	/*
425 	 * Dropped by firmware as invalid. E.g. bad checksum,
426 	 * decrypt failed, or invalid for current state.
427 	 */
428 	RX_PKT_FATE_FW_DROP_INVALID,
429 
430 	/* Dropped by firmware due to lack of buffer space. */
431 	RX_PKT_FATE_FW_DROP_NOBUFS,
432 
433 	/* Dropped by firmware for any other reason. */
434 	RX_PKT_FATE_FW_DROP_OTHER,
435 
436 	/* Queued within driver, not yet delivered to network stack. */
437 	RX_PKT_FATE_DRV_QUEUED,
438 
439 	/* Dropped by driver due to filter rules. */
440 	RX_PKT_FATE_DRV_DROP_FILTER,
441 
442 	/* Dropped by driver as invalid. E.g. not permitted in current state. */
443 	RX_PKT_FATE_DRV_DROP_INVALID,
444 
445 	/* Dropped by driver due to lack of buffer space. */
446 	RX_PKT_FATE_DRV_DROP_NOBUFS,
447 
448 	/* Dropped by driver for any other reason. */
449 	RX_PKT_FATE_DRV_DROP_OTHER,
450 
451 	} wifi_rx_packet_fate;
452 
453 typedef enum {
454 	FRAME_TYPE_UNKNOWN,
455 	FRAME_TYPE_ETHERNET_II,
456 	FRAME_TYPE_80211_MGMT,
457 	} frame_type;
458 
459 typedef struct wifi_frame_info {
460 	/*
461 	 * The type of MAC-layer frame that this frame_info holds.
462 	 * - For data frames, use FRAME_TYPE_ETHERNET_II.
463 	 * - For management frames, use FRAME_TYPE_80211_MGMT.
464 	 * - If the type of the frame is unknown, use FRAME_TYPE_UNKNOWN.
465 	 */
466 	frame_type payload_type;
467 
468 	/*
469 	 * The number of bytes included in |frame_content|. If the frame
470 	 * contents are missing (e.g. RX frame dropped in firmware),
471 	 * |frame_len| should be set to 0.
472 	 */
473 	size_t frame_len;
474 
475 	/*
476 	 * Host clock when this frame was received by the driver (either
477 	 *	outbound from the host network stack, or inbound from the
478 	 *	firmware).
479 	 *	- The timestamp should be taken from a clock which includes time
480 	 *	  the host spent suspended (e.g. ktime_get_boottime()).
481 	 *	- If no host timestamp is available (e.g. RX frame was dropped in
482 	 *	  firmware), this field should be set to 0.
483 	 */
484 	uint32 driver_timestamp_usec;
485 
486 	/*
487 	 * Firmware clock when this frame was received by the firmware
488 	 *	(either outbound from the host, or inbound from a remote
489 	 *	station).
490 	 *	- The timestamp should be taken from a clock which includes time
491 	 *	  firmware spent suspended (if applicable).
492 	 *	- If no firmware timestamp is available (e.g. TX frame was
493 	 *	  dropped by driver), this field should be set to 0.
494 	 *	- Consumers of |frame_info| should _not_ assume any
495 	 *	  synchronization between driver and firmware clocks.
496 	 */
497 	uint32 firmware_timestamp_usec;
498 
499 	/*
500 	 * Actual frame content.
501 	 * - Should be provided for TX frames originated by the host.
502 	 * - Should be provided for RX frames received by the driver.
503 	 * - Optionally provided for TX frames originated by firmware. (At
504 	 *   discretion of HAL implementation.)
505 	 * - Optionally provided for RX frames dropped in firmware. (At
506 	 *   discretion of HAL implementation.)
507 	 * - If frame content is not provided, |frame_len| should be set
508 	 *   to 0.
509 	 */
510 	union {
511 		char ethernet_ii[MAX_FRAME_LEN_ETHERNET];
512 		char ieee_80211_mgmt[MAX_FRAME_LEN_80211_MGMT];
513 	} frame_content;
514 } wifi_frame_info_t;
515 
516 typedef struct wifi_tx_report {
517 	/*
518 	 * Prefix of MD5 hash of |frame_inf.frame_content|. If frame
519 	 * content is not provided, prefix of MD5 hash over the same data
520 	 * that would be in frame_content, if frame content were provided.
521 	 */
522 	char md5_prefix[MD5_PREFIX_LEN];
523 	wifi_tx_packet_fate fate;
524 	wifi_frame_info_t frame_inf;
525 } wifi_tx_report_t;
526 
527 typedef struct wifi_rx_report {
528 	/*
529 	 * Prefix of MD5 hash of |frame_inf.frame_content|. If frame
530 	 * content is not provided, prefix of MD5 hash over the same data
531 	 * that would be in frame_content, if frame content were provided.
532 	 */
533 	char md5_prefix[MD5_PREFIX_LEN];
534 	wifi_rx_packet_fate fate;
535 	wifi_frame_info_t frame_inf;
536 } wifi_rx_report_t;
537 
538 typedef struct compat_wifi_frame_info {
539 	frame_type payload_type;
540 
541 	uint32 frame_len;
542 
543 	uint32 driver_timestamp_usec;
544 
545 	uint32 firmware_timestamp_usec;
546 
547 	union {
548 		char ethernet_ii[MAX_FRAME_LEN_ETHERNET];
549 		char ieee_80211_mgmt[MAX_FRAME_LEN_80211_MGMT];
550 	} frame_content;
551 } compat_wifi_frame_info_t;
552 
553 typedef struct compat_wifi_tx_report {
554 	char md5_prefix[MD5_PREFIX_LEN];
555 	wifi_tx_packet_fate fate;
556 	compat_wifi_frame_info_t frame_inf;
557 } compat_wifi_tx_report_t;
558 
559 typedef struct compat_wifi_rx_report {
560 	char md5_prefix[MD5_PREFIX_LEN];
561 	wifi_rx_packet_fate fate;
562 	compat_wifi_frame_info_t frame_inf;
563 } compat_wifi_rx_report_t;
564 
565 /*
566  * Packet logging - internal data
567  */
568 
569 typedef enum dhd_dbg_pkt_mon_state {
570 	PKT_MON_INVALID = 0,
571 	PKT_MON_ATTACHED,
572 	PKT_MON_STARTING,
573 	PKT_MON_STARTED,
574 	PKT_MON_STOPPING,
575 	PKT_MON_STOPPED,
576 	PKT_MON_DETACHED,
577 	} dhd_dbg_pkt_mon_state_t;
578 
579 typedef struct dhd_dbg_pkt_info {
580 	frame_type payload_type;
581 	size_t pkt_len;
582 	uint32 driver_ts;
583 	uint32 firmware_ts;
584 	uint32 pkt_hash;
585 	void *pkt;
586 } dhd_dbg_pkt_info_t;
587 
588 typedef struct compat_dhd_dbg_pkt_info {
589 	frame_type payload_type;
590 	uint32 pkt_len;
591 	uint32 driver_ts;
592 	uint32 firmware_ts;
593 	uint32 pkt_hash;
594 	void *pkt;
595 } compat_dhd_dbg_pkt_info_t;
596 
597 typedef struct dhd_dbg_tx_info
598 {
599 	wifi_tx_packet_fate fate;
600 	dhd_dbg_pkt_info_t info;
601 } dhd_dbg_tx_info_t;
602 
603 typedef struct dhd_dbg_rx_info
604 {
605 	wifi_rx_packet_fate fate;
606 	dhd_dbg_pkt_info_t info;
607 } dhd_dbg_rx_info_t;
608 
609 typedef struct dhd_dbg_tx_report
610 {
611 	dhd_dbg_tx_info_t *tx_pkts;
612 	uint16 pkt_pos;
613 	uint16 status_pos;
614 } dhd_dbg_tx_report_t;
615 
616 typedef struct dhd_dbg_rx_report
617 {
618 	dhd_dbg_rx_info_t *rx_pkts;
619 	uint16 pkt_pos;
620 } dhd_dbg_rx_report_t;
621 
622 typedef void (*dbg_pullreq_t)(void *os_priv, const int ring_id);
623 typedef void (*dbg_urgent_noti_t) (dhd_pub_t *dhdp, const void *data, const uint32 len);
624 typedef int (*dbg_mon_tx_pkts_t) (dhd_pub_t *dhdp, void *pkt, uint32 pktid);
625 typedef int (*dbg_mon_tx_status_t) (dhd_pub_t *dhdp, void *pkt,
626 	uint32 pktid, uint16 status);
627 typedef int (*dbg_mon_rx_pkts_t) (dhd_pub_t *dhdp, void *pkt);
628 
629 typedef struct dhd_dbg_pkt_mon
630 {
631 	dhd_dbg_tx_report_t *tx_report;
632 	dhd_dbg_rx_report_t *rx_report;
633 	dhd_dbg_pkt_mon_state_t tx_pkt_state;
634 	dhd_dbg_pkt_mon_state_t tx_status_state;
635 	dhd_dbg_pkt_mon_state_t rx_pkt_state;
636 
637 	/* call backs */
638 	dbg_mon_tx_pkts_t tx_pkt_mon;
639 	dbg_mon_tx_status_t tx_status_mon;
640 	dbg_mon_rx_pkts_t rx_pkt_mon;
641 } dhd_dbg_pkt_mon_t;
642 
643 typedef struct dhd_dbg {
644 	dhd_dbg_ring_t dbg_rings[DEBUG_RING_ID_MAX];
645 	void *private;          /* os private_data */
646 	dhd_dbg_pkt_mon_t pkt_mon;
647 	void *pkt_mon_lock; /* spin lock for packet monitoring */
648 	dbg_pullreq_t pullreq;
649 	dbg_urgent_noti_t urgent_notifier;
650 } dhd_dbg_t;
651 
652 #define PKT_MON_ATTACHED(state) \
653 		(((state) > PKT_MON_INVALID) && ((state) < PKT_MON_DETACHED))
654 #define PKT_MON_DETACHED(state) \
655 		(((state) == PKT_MON_INVALID) || ((state) == PKT_MON_DETACHED))
656 #define PKT_MON_STARTED(state) ((state) == PKT_MON_STARTED)
657 #define PKT_MON_STOPPED(state) ((state) == PKT_MON_STOPPED)
658 #define PKT_MON_NOT_OPERATIONAL(state) \
659 	(((state) != PKT_MON_STARTED) && ((state) != PKT_MON_STOPPED))
660 #define PKT_MON_SAFE_TO_FREE(state) \
661 	(((state) == PKT_MON_STARTING) || ((state) == PKT_MON_STOPPED))
662 #define PKT_MON_PKT_FULL(pkt_count) ((pkt_count) >= MAX_FATE_LOG_LEN)
663 #define PKT_MON_STATUS_FULL(pkt_count, status_count) \
664 		(((status_count) >= (pkt_count)) || ((status_count) >= MAX_FATE_LOG_LEN))
665 
666 #ifdef DBG_PKT_MON
667 #define DHD_DBG_PKT_MON_TX(dhdp, pkt, pktid) \
668 	do { \
669 		if ((dhdp) && (dhdp)->dbg && (dhdp)->dbg->pkt_mon.tx_pkt_mon && (pkt)) { \
670 			(dhdp)->dbg->pkt_mon.tx_pkt_mon((dhdp), (pkt), (pktid)); \
671 		} \
672 	} while (0);
673 #define DHD_DBG_PKT_MON_TX_STATUS(dhdp, pkt, pktid, status) \
674 	do { \
675 		if ((dhdp) && (dhdp)->dbg && (dhdp)->dbg->pkt_mon.tx_status_mon && (pkt)) { \
676 			(dhdp)->dbg->pkt_mon.tx_status_mon((dhdp), (pkt), (pktid), (status)); \
677 		} \
678 	} while (0);
679 #define DHD_DBG_PKT_MON_RX(dhdp, pkt) \
680 	do { \
681 		if ((dhdp) && (dhdp)->dbg && (dhdp)->dbg->pkt_mon.rx_pkt_mon && (pkt)) { \
682 			if (ntoh16((pkt)->protocol) != ETHER_TYPE_BRCM) { \
683 				(dhdp)->dbg->pkt_mon.rx_pkt_mon((dhdp), (pkt)); \
684 			} \
685 		} \
686 	} while (0);
687 
688 #define DHD_DBG_PKT_MON_START(dhdp) \
689 		dhd_os_dbg_start_pkt_monitor((dhdp));
690 #define DHD_DBG_PKT_MON_STOP(dhdp) \
691 		dhd_os_dbg_stop_pkt_monitor((dhdp));
692 #else
693 #define DHD_DBG_PKT_MON_TX(dhdp, pkt, pktid)
694 #define DHD_DBG_PKT_MON_TX_STATUS(dhdp, pkt, pktid, status)
695 #define DHD_DBG_PKT_MON_RX(dhdp, pkt)
696 #define DHD_DBG_PKT_MON_START(dhdp)
697 #define DHD_DBG_PKT_MON_STOP(dhdp)
698 #endif /* DBG_PKT_MON */
699 
700 #ifdef DUMP_IOCTL_IOV_LIST
701 typedef struct dhd_iov_li {
702 	dll_t list;
703 	uint32 cmd; /* command number */
704 	char buff[100]; /* command name */
705 } dhd_iov_li_t;
706 #endif /* DUMP_IOCTL_IOV_LIST */
707 
708 #define IOV_LIST_MAX_LEN 5
709 
710 #ifdef DHD_DEBUG
711 typedef struct {
712 	dll_t list;
713 	uint32 id; /* wasted chunk id */
714 	uint32 handle; /* wasted chunk handle */
715 	uint32 size; /* wasted chunk size */
716 } dhd_dbg_mwli_t;
717 #endif /* DHD_DEBUG */
718 
719 #define DHD_OW_BI_RAW_EVENT_LOG_FMT 0xFFFF
720 
721 /* LSB 2 bits of format number to identify the type of event log */
722 #define DHD_EVENT_LOG_HDR_MASK 0x3
723 
724 #define DHD_EVENT_LOG_FMT_NUM_OFFSET 2
725 #define DHD_EVENT_LOG_FMT_NUM_MASK 0x3FFF
726 /**
727  * OW:- one word
728  * TW:- two word
729  * NB:- non binary
730  * BI:- binary
731  */
732 #define	DHD_OW_NB_EVENT_LOG_HDR 0
733 #define DHD_TW_NB_EVENT_LOG_HDR 1
734 #define DHD_BI_EVENT_LOG_HDR 3
735 #define DHD_INVALID_EVENT_LOG_HDR 2
736 
737 #define DHD_TW_VALID_TAG_BITS_MASK 0xF
738 #define DHD_OW_BI_EVENT_FMT_NUM 0x3FFF
739 #define DHD_TW_BI_EVENT_FMT_NUM 0x3FFE
740 
741 #define DHD_TW_EVENT_LOG_TAG_OFFSET 8
742 
743 #define EVENT_TAG_TIMESTAMP_OFFSET 1
744 #define EVENT_TAG_TIMESTAMP_EXT_OFFSET 2
745 
746 typedef struct prcd_event_log_hdr {
747 	uint32 tag;		/* Event_log entry tag */
748 	uint32 count;		/* Count of 4-byte entries */
749 	uint32 fmt_num_raw;	/* Format number */
750 	uint32 fmt_num;		/* Format number >> 2 */
751 	uint32 armcycle;	/* global ARM CYCLE for TAG */
752 	uint32 *log_ptr;	/* start of payload */
753 	uint32	payload_len;
754 	/* Extended event log header info
755 	 * 0 - legacy, 1 - extended event log header present
756 	 */
757 	bool ext_event_log_hdr;
758 	bool binary_payload;	/* 0 - non binary payload, 1 - binary payload */
759 } prcd_event_log_hdr_t;		/* Processed event log header */
760 
761 /* dhd_dbg functions */
762 extern void dhd_dbg_trace_evnt_handler(dhd_pub_t *dhdp, void *event_data,
763 		void *raw_event_ptr, uint datalen);
764 void dhd_dbg_msgtrace_log_parser(dhd_pub_t *dhdp, void *event_data,
765 	void *raw_event_ptr, uint datalen, bool msgtrace_hdr_present,
766 	uint32 msgtrace_seqnum);
767 
768 extern int dhd_dbg_attach(dhd_pub_t *dhdp, dbg_pullreq_t os_pullreq,
769 	dbg_urgent_noti_t os_urgent_notifier, void *os_priv);
770 extern void dhd_dbg_detach(dhd_pub_t *dhdp);
771 extern int dhd_dbg_start(dhd_pub_t *dhdp, bool start);
772 extern int dhd_dbg_set_configuration(dhd_pub_t *dhdp, int ring_id,
773 		int log_level, int flags, uint32 threshold);
774 extern int dhd_dbg_find_ring_id(dhd_pub_t *dhdp, char *ring_name);
775 extern dhd_dbg_ring_t *dhd_dbg_get_ring_from_ring_id(dhd_pub_t *dhdp, int ring_id);
776 extern void *dhd_dbg_get_priv(dhd_pub_t *dhdp);
777 extern int dhd_dbg_send_urgent_evt(dhd_pub_t *dhdp, const void *data, const uint32 len);
778 extern void dhd_dbg_verboselog_printf(dhd_pub_t *dhdp, prcd_event_log_hdr_t *plog_hdr,
779 	void *raw_event_ptr, uint32 *log_ptr, uint32 logset, uint16 block);
780 int dhd_dbg_pull_from_ring(dhd_pub_t *dhdp, int ring_id, void *data, uint32 buf_len);
781 int dhd_dbg_pull_single_from_ring(dhd_pub_t *dhdp, int ring_id, void *data, uint32 buf_len,
782 	bool strip_header);
783 int dhd_dbg_push_to_ring(dhd_pub_t *dhdp, int ring_id, dhd_dbg_ring_entry_t *hdr,
784 		void *data);
785 int __dhd_dbg_get_ring_status(dhd_dbg_ring_t *ring, dhd_dbg_ring_status_t *ring_status);
786 int dhd_dbg_get_ring_status(dhd_pub_t *dhdp, int ring_id,
787 		dhd_dbg_ring_status_t *dbg_ring_status);
788 #ifdef SHOW_LOGTRACE
789 void dhd_dbg_read_ring_into_trace_buf(dhd_dbg_ring_t *ring, trace_buf_info_t *trace_buf_info);
790 #endif /* SHOW_LOGTRACE */
791 
792 #ifdef DBG_PKT_MON
793 extern int dhd_dbg_attach_pkt_monitor(dhd_pub_t *dhdp,
794 		dbg_mon_tx_pkts_t tx_pkt_mon,
795 		dbg_mon_tx_status_t tx_status_mon,
796 		dbg_mon_rx_pkts_t rx_pkt_mon);
797 extern int dhd_dbg_start_pkt_monitor(dhd_pub_t *dhdp);
798 extern int dhd_dbg_monitor_tx_pkts(dhd_pub_t *dhdp, void *pkt, uint32 pktid);
799 extern int dhd_dbg_monitor_tx_status(dhd_pub_t *dhdp, void *pkt,
800 		uint32 pktid, uint16 status);
801 extern int dhd_dbg_monitor_rx_pkts(dhd_pub_t *dhdp, void *pkt);
802 extern int dhd_dbg_stop_pkt_monitor(dhd_pub_t *dhdp);
803 extern int dhd_dbg_monitor_get_tx_pkts(dhd_pub_t *dhdp, void __user *user_buf,
804 		uint16 req_count, uint16 *resp_count);
805 extern int dhd_dbg_monitor_get_rx_pkts(dhd_pub_t *dhdp, void __user *user_buf,
806 		uint16 req_count, uint16 *resp_count);
807 extern int dhd_dbg_detach_pkt_monitor(dhd_pub_t *dhdp);
808 #endif /* DBG_PKT_MON */
809 
810 extern bool dhd_dbg_process_tx_status(dhd_pub_t *dhdp, void *pkt,
811 		uint32 pktid, uint16 status);
812 
813 /* os wrapper function */
814 extern int dhd_os_dbg_attach(dhd_pub_t *dhdp);
815 extern void dhd_os_dbg_detach(dhd_pub_t *dhdp);
816 extern int dhd_os_dbg_register_callback(int ring_id,
817 	void (*dbg_ring_sub_cb)(void *ctx, const int ring_id, const void *data,
818 		const uint32 len, const dhd_dbg_ring_status_t dbg_ring_status));
819 extern int dhd_os_dbg_register_urgent_notifier(dhd_pub_t *dhdp,
820 	void (*urgent_noti)(void *ctx, const void *data, const uint32 len, const uint32 fw_len));
821 
822 extern int dhd_os_start_logging(dhd_pub_t *dhdp, char *ring_name, int log_level,
823 		int flags, int time_intval, int threshold);
824 extern int dhd_os_reset_logging(dhd_pub_t *dhdp);
825 extern int dhd_os_suppress_logging(dhd_pub_t *dhdp, bool suppress);
826 
827 extern int dhd_os_get_ring_status(dhd_pub_t *dhdp, int ring_id,
828 		dhd_dbg_ring_status_t *dbg_ring_status);
829 extern int dhd_os_trigger_get_ring_data(dhd_pub_t *dhdp, char *ring_name);
830 extern int dhd_os_push_push_ring_data(dhd_pub_t *dhdp, int ring_id, void *data, int32 data_len);
831 extern int dhd_os_dbg_get_feature(dhd_pub_t *dhdp, int32 *features);
832 
833 #ifdef DBG_PKT_MON
834 extern int dhd_os_dbg_attach_pkt_monitor(dhd_pub_t *dhdp);
835 extern int dhd_os_dbg_start_pkt_monitor(dhd_pub_t *dhdp);
836 extern int dhd_os_dbg_monitor_tx_pkts(dhd_pub_t *dhdp, void *pkt,
837 	uint32 pktid);
838 extern int dhd_os_dbg_monitor_tx_status(dhd_pub_t *dhdp, void *pkt,
839 	uint32 pktid, uint16 status);
840 extern int dhd_os_dbg_monitor_rx_pkts(dhd_pub_t *dhdp, void *pkt);
841 extern int dhd_os_dbg_stop_pkt_monitor(dhd_pub_t *dhdp);
842 extern int dhd_os_dbg_monitor_get_tx_pkts(dhd_pub_t *dhdp,
843 	void __user *user_buf, uint16 req_count, uint16 *resp_count);
844 extern int dhd_os_dbg_monitor_get_rx_pkts(dhd_pub_t *dhdp,
845 	void __user *user_buf, uint16 req_count, uint16 *resp_count);
846 extern int dhd_os_dbg_detach_pkt_monitor(dhd_pub_t *dhdp);
847 #endif /* DBG_PKT_MON */
848 
849 #ifdef DUMP_IOCTL_IOV_LIST
850 extern void dhd_iov_li_append(dhd_pub_t *dhd, dll_t *list_head, dll_t *node);
851 extern void dhd_iov_li_print(dll_t *list_head);
852 extern void dhd_iov_li_delete(dhd_pub_t *dhd, dll_t *list_head);
853 #endif /* DUMP_IOCTL_IOV_LIST */
854 
855 #ifdef DHD_DEBUG
856 extern void dhd_mw_list_delete(dhd_pub_t *dhd, dll_t *list_head);
857 #endif /* DHD_DEBUG */
858 #endif /* _dhd_debug_h_ */
859