1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 #ifndef __LIBCFS_LINUX_KP30_H__
5 #define __LIBCFS_LINUX_KP30_H__
7 #ifndef __LIBCFS_KP30_H__
8 #error Do not #include this file directly. #include <libcfs/kp30.h> instead
12 # include <linux/config.h>
13 # include <linux/kernel.h>
14 # include <linux/mm.h>
15 # include <linux/string.h>
16 # include <linux/stat.h>
17 # include <linux/init.h>
18 # include <linux/errno.h>
19 # include <linux/unistd.h>
20 # include <asm/system.h>
21 # include <linux/kmod.h>
22 # include <linux/notifier.h>
23 # include <linux/fs.h>
24 # include <asm/segment.h>
25 # include <linux/miscdevice.h>
26 # include <linux/vmalloc.h>
27 # include <linux/time.h>
28 # include <linux/slab.h>
29 # include <linux/interrupt.h>
30 # include <linux/highmem.h>
31 # include <linux/module.h>
32 # include <linux/version.h>
33 # include <portals/p30.h>
34 # include <linux/smp_lock.h>
35 # include <asm/atomic.h>
36 # include <asm/uaccess.h>
37 # include <linux/rwsem.h>
38 # include <linux/proc_fs.h>
39 # include <linux/file.h>
40 # include <linux/smp.h>
41 # include <linux/ctype.h>
42 # ifdef HAVE_MM_INLINE
43 # include <linux/mm_inline.h>
45 # if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
46 # include <linux/kallsyms.h>
49 #include <libcfs/linux/portals_compat25.h>
51 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
52 #define schedule_work schedule_task
53 #define prepare_work(wq,cb,cbdata) \
55 INIT_TQUEUE((wq), 0, 0); \
56 PREPARE_TQUEUE((wq), (cb), (cbdata)); \
59 #define PageUptodate Page_Uptodate
60 #define our_recalc_sigpending(current) recalc_sigpending(current)
61 #define num_online_cpus() smp_num_cpus
62 static inline void our_cond_resched(void)
64 if (current->need_resched)
67 #define work_struct_t struct tq_struct
71 #define prepare_work(wq,cb,cbdata) \
73 INIT_WORK((wq), (void *)(cb), (void *)(cbdata)); \
75 #define wait_on_page wait_on_page_locked
76 #define our_recalc_sigpending(current) recalc_sigpending()
77 #define strtok(a,b) strpbrk(a, b)
78 static inline void our_cond_resched(void)
82 #define work_struct_t struct work_struct
84 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */
87 #define LASSERT_SPIN_LOCKED(lock) LASSERT(spin_is_locked(lock))
89 #define LASSERT_SPIN_LOCKED(lock) do {} while(0)
93 #define LBUG_WITH_LOC(file, func, line) \
95 CEMERG("LBUG - trying to dump log to /tmp/lustre-log\n"); \
96 portals_catastrophe = 1; \
97 portals_debug_dumplog(); \
98 portals_run_lbug_upcall(file, func, line); \
102 #define LBUG_WITH_LOC(file, func, line) \
105 portals_catastrophe = 1; \
106 portals_debug_dumpstack(NULL); \
107 portals_debug_dumplog(); \
108 portals_run_lbug_upcall(file, func, line); \
109 set_task_state(current, TASK_UNINTERRUPTIBLE); \
112 #endif /* __arch_um__ */
114 /* ------------------------------------------------------------------- */
116 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
118 #define PORTAL_SYMBOL_REGISTER(x) inter_module_register(#x, THIS_MODULE, &x)
119 #define PORTAL_SYMBOL_UNREGISTER(x) inter_module_unregister(#x)
121 #define PORTAL_SYMBOL_GET(x) ((typeof(&x))inter_module_get(#x))
122 #define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
124 #define PORTAL_MODULE_USE MOD_INC_USE_COUNT
125 #define PORTAL_MODULE_UNUSE MOD_DEC_USE_COUNT
128 #define PORTAL_SYMBOL_REGISTER(x)
129 #define PORTAL_SYMBOL_UNREGISTER(x)
131 #define PORTAL_SYMBOL_GET(x) symbol_get(x)
132 #define PORTAL_SYMBOL_PUT(x) symbol_put(x)
134 #define PORTAL_MODULE_USE try_module_get(THIS_MODULE)
135 #define PORTAL_MODULE_UNUSE module_put(THIS_MODULE)
139 /******************************************************************************/
142 /* Use the special GNU C __attribute__ hack to have the compiler check the
143 * printf style argument string against the actual argument count and
147 # warning printf has been defined as a macro...
151 #endif /* __GNUC__ */
153 # define fprintf(a, format, b...) CDEBUG(D_OTHER, format , ## b)
154 # define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
155 # define time(a) CURRENT_TIME
157 #else /* !__KERNEL__ */
163 # include <cygwin-ioctl.h>
169 #endif /* End of !__KERNEL__ */
171 /******************************************************************************/
172 /* Light-weight trace
173 * Support for temporary event tracing with minimal Heisenberg effect. */
174 #define LWT_SUPPORT 0
176 #define LWT_MEMORY (16<<20)
179 # if defined(__KERNEL__)
180 # if !defined(BITS_PER_LONG)
181 # error "BITS_PER_LONG not defined"
183 # elif !defined(__WORDSIZE)
184 # error "__WORDSIZE not defined"
186 # define BITS_PER_LONG __WORDSIZE
189 /* kernel hasn't defined this? */
198 # if BITS_PER_LONG > 32
202 #endif /* !KLWT_SUPPORT */
208 typedef struct _lwt_page {
209 struct list_head lwtp_list;
210 struct page *lwtp_page;
211 lwt_event_t *lwtp_events;
215 int lwtc_current_index;
216 lwt_page_t *lwtc_current_page;
219 extern int lwt_enabled;
220 extern lwt_cpu_t lwt_cpus[];
222 /* Note that we _don't_ define LWT_EVENT at all if LWT_SUPPORT isn't set.
223 * This stuff is meant for finding specific problems; it never stays in
224 * production code... */
227 #define LWTWHERE(f,l) f ":" LWTSTR(l)
228 #define LWT_EVENTS_PER_PAGE (PAGE_SIZE / sizeof (lwt_event_t))
230 #define LWT_EVENT(p1, p2, p3, p4) \
232 unsigned long flags; \
238 local_irq_save (flags); \
240 cpu = &lwt_cpus[smp_processor_id()]; \
241 p = cpu->lwtc_current_page; \
242 e = &p->lwtp_events[cpu->lwtc_current_index++]; \
244 if (cpu->lwtc_current_index >= LWT_EVENTS_PER_PAGE) { \
245 cpu->lwtc_current_page = \
246 list_entry (p->lwtp_list.next, \
247 lwt_page_t, lwtp_list); \
248 cpu->lwtc_current_index = 0; \
251 e->lwte_when = get_cycles(); \
252 e->lwte_where = LWTWHERE(__FILE__,__LINE__); \
253 e->lwte_task = current; \
254 e->lwte_p1 = (long)(p1); \
255 e->lwte_p2 = (long)(p2); \
256 e->lwte_p3 = (long)(p3); \
257 e->lwte_p4 = (long)(p4); \
259 local_irq_restore (flags); \
263 #endif /* !KLWT_SUPPORT */
265 extern int lwt_init (void);
266 extern void lwt_fini (void);
267 extern int lwt_lookup_string (int *size, char *knlptr,
268 char *usrptr, int usrsize);
269 extern int lwt_control (int enable, int clear);
270 extern int lwt_snapshot (cycles_t *now, int *ncpu, int *total_size,
271 void *user_ptr, int user_size);
272 # else /* __KERNEL__ */
273 # define LWT_EVENT(p1,p2,p3,p4) /* no userland implementation yet */
274 # endif /* __KERNEL__ */
275 #endif /* LWT_SUPPORT */
277 /* ------------------------------------------------------------------ */
279 #define IOCTL_PORTAL_TYPE long
282 # ifndef BITS_PER_LONG
283 # if (~0UL) == 0xffffffffUL
284 # define BITS_PER_LONG 32
286 # define BITS_PER_LONG 64
291 #if BITS_PER_LONG > 32
292 # define LI_POISON ((int)0x5a5a5a5a5a5a5a5a)
293 # define LL_POISON ((long)0x5a5a5a5a5a5a5a5a)
294 # define LP_POISON ((void *)(long)0x5a5a5a5a5a5a5a5a)
296 # define LI_POISON ((int)0x5a5a5a5a)
297 # define LL_POISON ((long)0x5a5a5a5a)
298 # define LP_POISON ((void *)(long)0x5a5a5a5a)
301 #if defined(__x86_64__) && defined(__KERNEL__)
302 /* x86_64 defines __u64 as "long" in userspace, but "long long" in the kernel */
305 # define LPX64 "%#Lx"
308 #elif (BITS_PER_LONG == 32 || __WORDSIZE == 32)
311 # define LPX64 "%#Lx"
314 #elif (BITS_PER_LONG == 64 || __WORDSIZE == 64)
317 # define LPX64 "%#lx"
322 # error "No word size defined"