1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef	_MSGTRACE_H
18 #define	_MSGTRACE_H
19 
20 #define MSGTRACE_VERSION 1
21 
22 /* Message trace header */
23 typedef struct msgtrace_hdr {
24 	u8 version;
25 	u8 spare;
26 	u16 len;		/* Len of the trace */
27 	u32 seqnum;		/* Sequence number of message. Useful
28 				 * if the messsage has been lost
29 				 * because of DMA error or a bus reset
30 				 * (ex: SDIO Func2)
31 				 */
32 	u32 discarded_bytes;	/* Number of discarded bytes because of
33 				 trace overflow  */
34 	u32 discarded_printf;	/* Number of discarded printf
35 				 because of trace overflow */
36 } __attribute__((packed)) msgtrace_hdr_t;
37 
38 #define MSGTRACE_HDRLEN		sizeof(msgtrace_hdr_t)
39 
40 /* The hbus driver generates traces when sending a trace message.
41  * This causes endless traces.
42  * This flag must be set to true in any hbus traces.
43  * The flag is reset in the function msgtrace_put.
44  * This prevents endless traces but generates hasardous
45  * lost of traces only in bus device code.
46  * It is recommendat to set this flag in macro SD_TRACE
47  * but not in SD_ERROR for avoiding missing
48  * hbus error traces. hbus error trace should not generates endless traces.
49  */
50 extern bool msgtrace_hbus_trace;
51 
52 typedef void (*msgtrace_func_send_t) (void *hdl1, void *hdl2, u8 *hdr,
53 				      u16 hdrlen, u8 *buf,
54 				      u16 buflen);
55 
56 extern void msgtrace_sent(void);
57 extern void msgtrace_put(char *buf, int count);
58 extern void msgtrace_init(void *hdl1, void *hdl2,
59 			  msgtrace_func_send_t func_send);
60 
61 #endif				/* _MSGTRACE_H */
62