1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
7 #ifdef HAVE_ASM_TYPES_H
14 # include <linux/time.h>
15 # include <asm/timex.h>
17 # include <sys/time.h>
18 # define do_gettimeofday(tv) gettimeofday(tv, NULL);
19 typedef unsigned long long cycles_t;
25 # define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
28 #define LOWEST_BIT_SET(x) ((x) & ~((x) - 1))
31 /* Userpace byte flipping */
33 # include <byteswap.h>
34 # define __swab16(x) bswap_16(x)
35 # define __swab32(x) bswap_32(x)
36 # define __swab64(x) bswap_64(x)
37 # define __swab16s(x) do {*(x) = bswap_16(*(x));} while (0)
38 # define __swab32s(x) do {*(x) = bswap_32(*(x));} while (0)
39 # define __swab64s(x) do {*(x) = bswap_64(*(x));} while (0)
40 # if __BYTE_ORDER == __LITTLE_ENDIAN
41 # define le16_to_cpu(x) (x)
42 # define cpu_to_le16(x) (x)
43 # define le32_to_cpu(x) (x)
44 # define cpu_to_le32(x) (x)
45 # define le64_to_cpu(x) (x)
46 # define cpu_to_le64(x) (x)
48 # if __BYTE_ORDER == __BIG_ENDIAN
49 # define le16_to_cpu(x) bswap_16(x)
50 # define cpu_to_le16(x) bswap_16(x)
51 # define le32_to_cpu(x) bswap_32(x)
52 # define cpu_to_le32(x) bswap_32(x)
53 # define le64_to_cpu(x) bswap_64(x)
54 # define cpu_to_le64(x) bswap_64(x)
56 # error "Unknown byte order"
57 # endif /* __BIG_ENDIAN */
58 # endif /* __LITTLE_ENDIAN */
59 #endif /* ! __KERNEL__ */
64 extern unsigned int portal_subsystem_debug;
65 extern unsigned int portal_stack;
66 extern unsigned int portal_debug;
67 extern unsigned int portal_printk;
69 struct ptldebug_header {
81 } __attribute__((packed));
83 #define PH_FLAG_FIRST_RECORD 1
85 /* Debugging subsystems (32 bits, non-overlapping) */
86 #define S_UNDEFINED 0x00000001
87 #define S_MDC 0x00000002
88 #define S_MDS 0x00000004
89 #define S_OSC 0x00000008
90 #define S_OST 0x00000010
91 #define S_CLASS 0x00000020
92 #define S_LOG 0x00000040
93 #define S_LLITE 0x00000080
94 #define S_RPC 0x00000100
95 #define S_MGMT 0x00000200
96 #define S_PORTALS 0x00000400
97 #define S_SOCKNAL 0x00000800
98 #define S_QSWNAL 0x00001000
99 #define S_PINGER 0x00002000
100 #define S_FILTER 0x00004000
101 #define S_PTLBD 0x00008000
102 #define S_ECHO 0x00010000
103 #define S_LDLM 0x00020000
104 #define S_LOV 0x00040000
105 #define S_GMNAL 0x00080000
106 #define S_PTLROUTER 0x00100000
107 #define S_COBD 0x00200000
108 #define S_IBNAL 0x00400000 /* All IB NALs */
109 #define S_SM 0x00800000
110 #define S_ASOBD 0x01000000
111 #define S_LMV 0x02000000
112 #define S_CMOBD 0x04000000
113 #define S_LONAL 0x08000000
115 /* If you change these values, please keep portals/utils/debug.c
118 /* Debugging masks (32 bits, non-overlapping) */
119 #define D_TRACE 0x00000001 /* ENTRY/EXIT markers */
120 #define D_INODE 0x00000002
121 #define D_SUPER 0x00000004
122 #define D_EXT2 0x00000008 /* anything from ext2_debug */
123 #define D_MALLOC 0x00000010 /* print malloc, free information */
124 #define D_CACHE 0x00000020 /* cache-related items */
125 #define D_INFO 0x00000040 /* general information */
126 #define D_IOCTL 0x00000080 /* ioctl related information */
127 #define D_BLOCKS 0x00000100 /* ext2 block allocation */
128 #define D_NET 0x00000200 /* network communications */
129 #define D_WARNING 0x00000400 /* CWARN(...) == CDEBUG (D_WARNING, ...) */
130 #define D_BUFFS 0x00000800
131 #define D_OTHER 0x00001000
132 #define D_DENTRY 0x00002000
133 #define D_PORTALS 0x00004000 /* ENTRY/EXIT markers */
134 #define D_PAGE 0x00008000 /* bulk page handling */
135 #define D_DLMTRACE 0x00010000
136 #define D_ERROR 0x00020000 /* CERROR(...) == CDEBUG (D_ERROR, ...) */
137 #define D_EMERG 0x00040000 /* CEMERG(...) == CDEBUG (D_EMERG, ...) */
138 #define D_HA 0x00080000 /* recovery and failover */
139 #define D_RPCTRACE 0x00100000 /* for distributed debugging */
140 #define D_VFSTRACE 0x00200000
141 #define D_READA 0x00400000 /* read-ahead */
142 #define D_MMAP 0x00800000
143 #define D_CONFIG 0x01000000
145 # include <linux/sched.h> /* THREAD_SIZE */
147 # ifndef THREAD_SIZE /* x86_64 has THREAD_SIZE in userspace */
148 # define THREAD_SIZE 8192
152 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
156 # define CDEBUG_STACK (THREAD_SIZE - \
157 ((unsigned long)__builtin_dwarf_cfa() & \
160 # define CDEBUG_STACK (THREAD_SIZE - \
161 ((unsigned long)__builtin_frame_address(0) & \
163 # endif /* __ia64__ */
165 #define CHECK_STACK(stack) \
167 if ((stack) > 3*THREAD_SIZE/4 && (stack) > portal_stack) { \
168 portals_debug_msg(DEBUG_SUBSYSTEM, D_WARNING, \
169 __FILE__, __FUNCTION__, __LINE__, \
170 (stack),"maximum lustre stack %u\n",\
171 portal_stack = (stack)); \
175 #else /* !__KERNEL__ */
176 #define CHECK_STACK(stack) do { } while(0)
177 #define CDEBUG_STACK (0L)
178 #endif /* __KERNEL__ */
181 #define CDEBUG(mask, format, a...) \
183 CHECK_STACK(CDEBUG_STACK); \
184 if (((mask) & (D_ERROR | D_EMERG | D_WARNING)) || \
185 (portal_debug & (mask) && \
186 portal_subsystem_debug & DEBUG_SUBSYSTEM)) \
187 portals_debug_msg(DEBUG_SUBSYSTEM, mask, \
188 __FILE__, __FUNCTION__, __LINE__, \
189 CDEBUG_STACK, format, ## a); \
192 #define CDEBUG_MAX_LIMIT 600
193 #define CDEBUG_LIMIT(cdebug_mask, cdebug_format, a...) \
195 static unsigned long cdebug_next; \
196 static int cdebug_count, cdebug_delay = 1; \
198 CHECK_STACK(CDEBUG_STACK); \
199 if (time_after(jiffies, cdebug_next)) { \
200 portals_debug_msg(DEBUG_SUBSYSTEM, cdebug_mask, __FILE__, \
201 __FUNCTION__, __LINE__, CDEBUG_STACK, \
202 cdebug_format, ## a); \
203 if (cdebug_count) { \
204 portals_debug_msg(DEBUG_SUBSYSTEM, cdebug_mask, \
205 __FILE__, __FUNCTION__, __LINE__, \
206 CDEBUG_STACK, cdebug_format, ## a); \
209 if (time_after(jiffies, cdebug_next+(CDEBUG_MAX_LIMIT+10)*HZ))\
210 cdebug_delay = cdebug_delay > 8 ? cdebug_delay/8 : 1; \
212 cdebug_delay = cdebug_delay*2 >= CDEBUG_MAX_LIMIT*HZ ?\
213 CDEBUG_MAX_LIMIT*HZ : cdebug_delay*2; \
214 cdebug_next = jiffies + cdebug_delay; \
216 portals_debug_msg(DEBUG_SUBSYSTEM, \
217 portal_debug & ~(D_EMERG|D_ERROR|D_WARNING),\
218 __FILE__, __FUNCTION__, __LINE__, \
219 CDEBUG_STACK, cdebug_format, ## a); \
224 #define CWARN(format, a...) CDEBUG_LIMIT(D_WARNING, format, ## a)
225 #define CERROR(format, a...) CDEBUG_LIMIT(D_ERROR, format, ## a)
226 #define CEMERG(format, a...) CDEBUG(D_EMERG, format, ## a)
228 #define GOTO(label, rc) \
230 long GOTO__ret = (long)(rc); \
231 CDEBUG(D_TRACE,"Process leaving via %s (rc=%lu : %ld : %lx)\n", \
232 #label, (unsigned long)GOTO__ret, (signed long)GOTO__ret,\
233 (signed long)GOTO__ret); \
239 typeof(rc) RETURN__ret = (rc); \
240 CDEBUG(D_TRACE, "Process leaving (rc=%lu : %ld : %lx)\n", \
241 (long)RETURN__ret, (long)RETURN__ret, (long)RETURN__ret);\
242 return RETURN__ret; \
247 CDEBUG(D_TRACE, "Process entered\n"); \
252 CDEBUG(D_TRACE, "Process leaving\n"); \
255 #define CDEBUG(mask, format, a...) do { } while (0)
256 #define CWARN(format, a...) printk(KERN_WARNING format, ## a)
257 #define CERROR(format, a...) printk(KERN_ERR format, ## a)
258 #define CEMERG(format, a...) printk(KERN_EMERG format, ## a)
259 #define GOTO(label, rc) do { (void)(rc); goto label; } while (0)
260 #define RETURN(rc) return (rc)
261 #define ENTRY do { } while (0)
262 #define EXIT do { } while (0)
268 * 1) ptl_pid_t in cray portals is only 16 bits, not 32 bits, therefore this
271 * 2) the implementation of ernal in cray portals further restricts the pid
272 * space that may be used to 0 <= pid <= 255 (an 8 bit value). Returns
273 * an error at nal init time for any pid outside this range. Other nals
274 * in cray portals don't have this restriction.
276 #define LUSTRE_PTL_PID 9
278 #define LUSTRE_PTL_PID 12345
281 #define LUSTRE_SRV_PTL_PID LUSTRE_PTL_PID
283 #define PORTALS_CFG_VERSION 0x00010001;
303 __u32 pcfg_plen1; /* buffers in userspace */
305 __u32 pcfg_plen2; /* buffers in userspace */
309 #define PCFG_INIT(pcfg, cmd) \
311 memset(&pcfg, 0, sizeof(pcfg)); \
312 pcfg.pcfg_version = PORTALS_CFG_VERSION; \
313 pcfg.pcfg_command = (cmd); \
317 typedef int (nal_cmd_handler_fn)(struct portals_cfg *, void *);
318 int libcfs_nal_cmd_register(int nal, nal_cmd_handler_fn *handler, void *arg);
319 int libcfs_nal_cmd(struct portals_cfg *pcfg);
320 void libcfs_nal_cmd_unregister(int nal);
322 struct portal_ioctl_data {
346 __u32 ioc_plen1; /* buffers in userspace */
348 __u32 ioc_plen2; /* buffers in userspace */
357 #include <linux/list.h>
359 struct libcfs_ioctl_handler {
360 struct list_head item;
361 int (*handle_ioctl)(struct portal_ioctl_data *data,
362 unsigned int cmd, unsigned long args);
365 #define DECLARE_IOCTL_HANDLER(ident, func) \
366 struct libcfs_ioctl_handler ident = { \
367 .item = LIST_HEAD_INIT(ident.item), \
368 .handle_ioctl = func \
371 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
372 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
378 #endif /* _LIBCFS_H */