1 /**************************************************************************
3 * Copyright © 2000-2008 Alacritech, Inc. All rights reserved.
5 * $Id: sxgdbg.h,v 1.1 2008/06/27 12:49:28 mook Exp $
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY ALACRITECH, INC. ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ALACRITECH, INC. OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * The views and conclusions contained in the software and documentation
32 * are those of the authors and should not be interpreted as representing
33 * official policies, either expressed or implied, of Alacritech, Inc.
35 **************************************************************************/
40 * All debug and assertion-based definitions and macros are included
41 * in this file for the SXGOSS driver.
47 #define ATK_TRACE_ENABLED 1
49 #define DBG_ERROR(n, args...) printk(KERN_EMERG n, ##args)
55 #ifdef SXG_ASSERT_ENABLED
60 DBG_ERROR("ASSERT() Failure: file %s, function %s line %d\n",\
61 __FILE__, __func__, __LINE__); \
69 #endif /* SXG_ASSERT_ENABLED */
74 * Global for timer granularity; every driver must have an instance
75 * of this initialized to 0
78 extern ulong ATKTimerDiv;
83 * This structure defines an entry in the trace buffer. The
84 * first few fields mean the same from entry to entry, while
85 * the meaning of last several fields change to suit the
86 * needs of the trace entry. Typically they are function call
89 typedef struct _trace_entry_s {
90 char name[8]; /* 8 character name - like 's'i'm'b'a'r'c'v' */
91 u32 time; /* Current clock tic */
92 unsigned char cpu; /* Current CPU */
93 unsigned char irql; /* Current IRQL */
94 unsigned char driver; /* The driver which added the trace call */
95 unsigned char pad2; /* pad to 4 byte boundary - will probably get used */
96 u32 arg1; /* Caller arg1 */
97 u32 arg2; /* Caller arg2 */
98 u32 arg3; /* Caller arg3 */
99 u32 arg4; /* Caller arg4 */
100 } trace_entry_t, *ptrace_entry_t;
103 * Driver types for driver field in trace_entry_t
109 #define TRACE_ENTRIES 1024
111 typedef struct _sxg_trace_buffer_t
113 unsigned int size; /* aid for windbg extension */
114 unsigned int in; /* Where to add */
115 unsigned int level; /* Current Trace level */
116 spinlock_t lock; /* For MP tracing */
117 trace_entry_t entries[TRACE_ENTRIES];/* The circular buffer */
118 } sxg_trace_buffer_t;
123 * XXX At the moment I am only defining critical, important, and noisy.
124 * I am leaving room for more if anyone wants them.
126 #define TRACE_NONE 0 /* For trace level - if no tracing wanted */
127 #define TRACE_CRITICAL 1 /* minimal tracing - only critical stuff */
128 #define TRACE_IMPORTANT 5 /* more tracing - anything important */
129 #define TRACE_NOISY 10 /* Everything in the world */
132 /**********************************************************************
134 * The macros themselves -
136 *********************************************************************/
137 #if ATK_TRACE_ENABLED
138 #define SXG_TRACE_INIT(buffer, tlevel) \
140 memset((buffer), 0, sizeof(sxg_trace_buffer_t)); \
141 (buffer)->level = (tlevel); \
142 (buffer)->size = TRACE_ENTRIES; \
143 spin_lock_init(&(buffer)->lock); \
146 #define SXG_TRACE_INIT(buffer, tlevel)
150 * The trace macro. This is active only if ATK_TRACE_ENABLED is set.
152 #if ATK_TRACE_ENABLED
153 #define SXG_TRACE(tdriver, buffer, tlevel, tname, a1, a2, a3, a4) { \
154 if ((buffer) && ((buffer)->level >= (tlevel))) { \
155 unsigned int trace_irql = 0; /* ?????? FIX THIS */ \
156 unsigned int trace_len; \
157 ptrace_entry_t trace_entry; \
158 struct timeval timev; \
160 spin_lock(&(buffer)->lock); \
161 trace_entry = &(buffer)->entries[(buffer)->in]; \
162 do_gettimeofday(&timev); \
164 memset(trace_entry->name, 0, 8); \
165 trace_len = strlen(tname); \
166 trace_len = trace_len > 8 ? 8 : trace_len; \
167 memcpy(trace_entry->name, (tname), trace_len); \
168 trace_entry->time = timev.tv_usec; \
169 trace_entry->cpu = (unsigned char)(smp_processor_id() & 0xFF); \
170 trace_entry->driver = (tdriver); \
171 trace_entry->irql = trace_irql; \
172 trace_entry->arg1 = (ulong)(a1); \
173 trace_entry->arg2 = (ulong)(a2); \
174 trace_entry->arg3 = (ulong)(a3); \
175 trace_entry->arg4 = (ulong)(a4); \
178 if ((buffer)->in == TRACE_ENTRIES) \
181 spin_unlock(&(buffer)->lock); \
185 #define SXG_TRACE(tdriver, buffer, tlevel, tname, a1, a2, a3, a4)
190 #endif /* _SXG_DEBUG_H_ */