Whamcloud - gitweb
- merge 2 weeks of b1_4 fixes onto HEAD
[fs/lustre-release.git] / lnet / include / linux / kp30.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4 #ifndef _KP30_INCLUDED
5 #define _KP30_INCLUDED
6
7 #include <linux/libcfs.h>
8 #define PORTAL_DEBUG
9
10 #ifdef __KERNEL__
11 # include <linux/vmalloc.h>
12 # include <linux/time.h>
13 # include <linux/slab.h>
14 # include <linux/interrupt.h>
15 # include <linux/highmem.h>
16 # include <linux/module.h>
17 # include <linux/version.h>
18 # include <portals/p30.h>
19 # include <linux/smp_lock.h>
20 # include <asm/atomic.h>
21
22 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
23 #define schedule_work schedule_task
24 #define prepare_work(wq,cb,cbdata)                                            \
25 do {                                                                          \
26         INIT_TQUEUE((wq), 0, 0);                                              \
27         PREPARE_TQUEUE((wq), (cb), (cbdata));                                 \
28 } while (0)
29
30 #define PageUptodate Page_Uptodate
31 #define our_recalc_sigpending(current) recalc_sigpending(current)
32 #define num_online_cpus() smp_num_cpus
33 static inline void our_cond_resched(void)
34 {
35         if (current->need_resched)
36                schedule ();
37 }
38 #define work_struct_t       struct tq_struct
39
40 #else
41
42 #define prepare_work(wq,cb,cbdata)                                            \
43 do {                                                                          \
44         INIT_WORK((wq), (void *)(cb), (void *)(cbdata));                      \
45 } while (0)
46 #define wait_on_page wait_on_page_locked
47 #define our_recalc_sigpending(current) recalc_sigpending()
48 #define strtok(a,b) strpbrk(a, b)
49 static inline void our_cond_resched(void)
50 {
51         cond_resched();
52 }
53 #define work_struct_t      struct work_struct
54
55 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */
56
57 #ifdef PORTAL_DEBUG
58 extern void kportal_assertion_failed(char *expr, char *file, const char *func,
59                                      const int line);
60 #define LASSERT(e) ((e) ? 0 : kportal_assertion_failed( #e , __FILE__,  \
61                                                         __FUNCTION__, __LINE__))
62 /* it would be great to dump_stack() here, but some kernels
63  * export it as show_stack() and I can't be bothered to
64  * proprely engage in that dance right now */
65 #define LASSERTF(cond, fmt...)                                                \
66         do {                                                                  \
67                 if (unlikely(!(cond))) {                                      \
68                         portals_debug_msg(0, D_EMERG,  __FILE__, __FUNCTION__,\
69                                           __LINE__,  CDEBUG_STACK,            \
70                                           "ASSERTION(" #cond ") failed:" fmt);\
71                         LBUG();                                               \
72                 }                                                             \
73         } while (0)
74
75 #else
76 #define LASSERT(e)
77 #define LASSERTF(cond, fmt...) do { } while (0)
78 #endif
79
80 #ifdef CONFIG_SMP
81 #define LASSERT_SPIN_LOCKED(lock) LASSERT(spin_is_locked(lock))
82 #else
83 #define LASSERT_SPIN_LOCKED(lock) do {} while(0)
84 #endif
85
86 #ifdef __arch_um__
87 #define LBUG_WITH_LOC(file, func, line)                                 \
88 do {                                                                    \
89         CEMERG("LBUG - trying to dump log to /tmp/lustre-log\n");       \
90         portals_debug_dumplog();                                        \
91         portals_run_lbug_upcall(file, func, line);                      \
92         panic("LBUG");                                                  \
93 } while (0)
94 #else
95 #define LBUG_WITH_LOC(file, func, line)                                 \
96 do {                                                                    \
97         CEMERG("LBUG\n");                                               \
98         portals_debug_dumplog();                                        \
99         portals_run_lbug_upcall(file, func, line);                      \
100         set_task_state(current, TASK_UNINTERRUPTIBLE);                  \
101         schedule();                                                     \
102 } while (0)
103 #endif /* __arch_um__ */
104
105 #define LBUG() LBUG_WITH_LOC(__FILE__, __FUNCTION__, __LINE__)
106
107 /*
108  * Memory
109  */
110 #ifdef PORTAL_DEBUG
111 extern atomic_t portal_kmemory;
112
113 # define portal_kmem_inc(ptr, size)                                           \
114 do {                                                                          \
115         atomic_add(size, &portal_kmemory);                                    \
116 } while (0)
117
118 # define portal_kmem_dec(ptr, size) do {                                      \
119         atomic_sub(size, &portal_kmemory);                                    \
120 } while (0)
121
122 #else
123 # define portal_kmem_inc(ptr, size) do {} while (0)
124 # define portal_kmem_dec(ptr, size) do {} while (0)
125 #endif /* PORTAL_DEBUG */
126
127 #define PORTAL_VMALLOC_SIZE        16384
128
129 #define PORTAL_ALLOC_GFP(ptr, size, mask)                                 \
130 do {                                                                      \
131         LASSERT(!in_interrupt() ||                                        \
132                (size <= PORTAL_VMALLOC_SIZE && mask == GFP_ATOMIC));      \
133         if ((size) > PORTAL_VMALLOC_SIZE)                                 \
134                 (ptr) = vmalloc(size);                                    \
135         else                                                              \
136                 (ptr) = kmalloc((size), (mask));                          \
137         if ((ptr) == NULL) {                                              \
138                 CERROR("PORTALS: out of memory at %s:%d (tried to alloc '"\
139                        #ptr "' = %d)\n", __FILE__, __LINE__, (int)(size));\
140                 CERROR("PORTALS: %d total bytes allocated by portals\n",  \
141                        atomic_read(&portal_kmemory));                     \
142         } else {                                                          \
143                 portal_kmem_inc((ptr), (size));                           \
144                 memset((ptr), 0, (size));                                 \
145         }                                                                 \
146         CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %d at %p (tot %d).\n",    \
147                (int)(size), (ptr), atomic_read (&portal_kmemory));        \
148 } while (0)
149
150 #define PORTAL_ALLOC(ptr, size) \
151         PORTAL_ALLOC_GFP(ptr, size, GFP_NOFS)
152
153 #define PORTAL_ALLOC_ATOMIC(ptr, size) \
154         PORTAL_ALLOC_GFP(ptr, size, GFP_ATOMIC)
155
156 #define PORTAL_FREE(ptr, size)                                          \
157 do {                                                                    \
158         int s = (size);                                                 \
159         if ((ptr) == NULL) {                                            \
160                 CERROR("PORTALS: free NULL '" #ptr "' (%d bytes) at "   \
161                        "%s:%d\n", s, __FILE__, __LINE__);               \
162                 break;                                                  \
163         }                                                               \
164         if (s > PORTAL_VMALLOC_SIZE)                                    \
165                 vfree(ptr);                                             \
166         else                                                            \
167                 kfree(ptr);                                             \
168         portal_kmem_dec((ptr), s);                                      \
169         CDEBUG(D_MALLOC, "kfreed '" #ptr "': %d at %p (tot %d).\n",     \
170                s, (ptr), atomic_read(&portal_kmemory));                 \
171 } while (0)
172
173 /* ------------------------------------------------------------------- */
174
175 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
176
177 #define PORTAL_SYMBOL_REGISTER(x) inter_module_register(#x, THIS_MODULE, &x)
178 #define PORTAL_SYMBOL_UNREGISTER(x) inter_module_unregister(#x)
179
180 #define PORTAL_SYMBOL_GET(x) ((typeof(&x))inter_module_get(#x))
181 #define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
182
183 #define PORTAL_MODULE_USE       MOD_INC_USE_COUNT
184 #define PORTAL_MODULE_UNUSE     MOD_DEC_USE_COUNT
185 #else
186
187 #define PORTAL_SYMBOL_REGISTER(x)
188 #define PORTAL_SYMBOL_UNREGISTER(x)
189
190 #define PORTAL_SYMBOL_GET(x) symbol_get(x)
191 #define PORTAL_SYMBOL_PUT(x) symbol_put(x)
192
193 #define PORTAL_MODULE_USE       try_module_get(THIS_MODULE)
194 #define PORTAL_MODULE_UNUSE     module_put(THIS_MODULE)
195
196 #endif
197
198 /******************************************************************************/
199
200 #ifdef PORTALS_PROFILING
201 #define prof_enum(FOO) PROF__##FOO
202 enum {
203         prof_enum(our_recvmsg),
204         prof_enum(our_sendmsg),
205         prof_enum(socknal_recv),
206         prof_enum(lib_parse),
207         prof_enum(conn_list_walk),
208         prof_enum(memcpy),
209         prof_enum(lib_finalize),
210         prof_enum(pingcli_time),
211         prof_enum(gmnal_send),
212         prof_enum(gmnal_recv),
213         MAX_PROFS
214 };
215
216 struct prof_ent {
217         char *str;
218         /* hrmph.  wrap-tastic. */
219         u32       starts;
220         u32       finishes;
221         cycles_t  total_cycles;
222         cycles_t  start;
223         cycles_t  end;
224 };
225
226 extern struct prof_ent prof_ents[MAX_PROFS];
227
228 #define PROF_START(FOO)                                         \
229         do {                                                    \
230                 struct prof_ent *pe = &prof_ents[PROF__##FOO];  \
231                 pe->starts++;                                   \
232                 pe->start = get_cycles();                       \
233         } while (0)
234
235 #define PROF_FINISH(FOO)                                        \
236         do {                                                    \
237                 struct prof_ent *pe = &prof_ents[PROF__##FOO];  \
238                 pe->finishes++;                                 \
239                 pe->end = get_cycles();                         \
240                 pe->total_cycles += (pe->end - pe->start);      \
241         } while (0)
242 #else /* !PORTALS_PROFILING */
243 #define PROF_START(FOO) do {} while(0)
244 #define PROF_FINISH(FOO) do {} while(0)
245 #endif /* PORTALS_PROFILING */
246
247 /* debug.c */
248 extern spinlock_t stack_backtrace_lock;
249
250 char *portals_debug_dumpstack(void);
251 void portals_run_upcall(char **argv);
252 void portals_run_lbug_upcall(char * file, const char *fn, const int line);
253 void portals_debug_dumplog(void);
254 int portals_debug_init(unsigned long bufsize);
255 int portals_debug_cleanup(void);
256 int portals_debug_clear_buffer(void);
257 int portals_debug_mark_buffer(char *text);
258 int portals_debug_set_daemon(unsigned int cmd, unsigned int length,
259                              char *file, unsigned int size);
260 __s32 portals_debug_copy_to_user(char *buf, unsigned long len);
261 #if (__GNUC__)
262 /* Use the special GNU C __attribute__ hack to have the compiler check the
263  * printf style argument string against the actual argument count and
264  * types.
265  */
266 #ifdef printf
267 # warning printf has been defined as a macro...
268 # undef printf
269 #endif
270 void portals_debug_msg(int subsys, int mask, char *file, const char *fn,
271                        const int line, unsigned long stack,
272                        char *format, ...)
273         __attribute__ ((format (printf, 7, 8)));
274 #else
275 void portals_debug_msg(int subsys, int mask, char *file, const char *fn,
276                        const int line, unsigned long stack,
277                        const char *format, ...);
278 #endif /* __GNUC__ */
279 void portals_debug_set_level(unsigned int debug_level);
280
281 # define fprintf(a, format, b...) CDEBUG(D_OTHER, format , ## b)
282 # define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
283 # define time(a) CURRENT_TIME
284
285 extern void kportal_daemonize (char *name);
286 extern void kportal_blockallsigs (void);
287
288 #else  /* !__KERNEL__ */
289 # include <stdio.h>
290 # include <stdlib.h>
291 #ifndef __CYGWIN__
292 # include <stdint.h>
293 #else
294 # include <cygwin-ioctl.h>
295 #endif
296 # include <unistd.h>
297 # include <time.h>
298 # include <limits.h>
299 # include <asm/types.h>
300 # ifndef DEBUG_SUBSYSTEM
301 #  define DEBUG_SUBSYSTEM S_UNDEFINED
302 # endif
303 # ifdef PORTAL_DEBUG
304 #  undef NDEBUG
305 #  include <assert.h>
306 #  define LASSERT(e)     assert(e)
307 #  define LASSERTF(cond, args...)                                              \
308 do {                                                                           \
309           if (!(cond))                                                         \
310                 CERROR(args);                                                  \
311           assert(cond);                                                        \
312 } while (0)
313 # else
314 #  define LASSERT(e)
315 #  define LASSERTF(cond, args...) do { } while (0)
316 # endif
317 # define printk(format, args...) printf (format, ## args)
318 # define PORTAL_ALLOC(ptr, size) do { (ptr) = malloc(size); } while (0);
319 # define PORTAL_FREE(a, b) do { free(a); } while (0);
320 void portals_debug_dumplog(void);
321 # define portals_debug_msg(subsys, mask, file, fn, line, stack, format, a...) \
322     printf("%02x:%06x (@%lu %s:%s,l. %d %d %lu): " format,                    \
323            (subsys), (mask), (long)time(0), file, fn, line,                   \
324            getpid() , stack, ## a);
325 #endif
326
327 /* support decl needed both by kernel and liblustre */
328 char *portals_nid2str(int nal, ptl_nid_t nid, char *str);
329
330 #ifndef CURRENT_TIME
331 # define CURRENT_TIME time(0)
332 #endif
333
334 /******************************************************************************/
335 /* Light-weight trace
336  * Support for temporary event tracing with minimal Heisenberg effect. */
337 #define LWT_SUPPORT  0
338
339 #define LWT_MEMORY   (64<<20)
340 #define LWT_MAX_CPUS 4
341
342 typedef struct {
343         cycles_t    lwte_when;
344         char       *lwte_where;
345         void       *lwte_task;
346         long        lwte_p1;
347         long        lwte_p2;
348         long        lwte_p3;
349         long        lwte_p4;
350 #if BITS_PER_LONG > 32
351         long        lwte_pad;
352 #endif
353 } lwt_event_t;
354
355 #if LWT_SUPPORT
356 #ifdef __KERNEL__
357 #define LWT_EVENTS_PER_PAGE (PAGE_SIZE / sizeof (lwt_event_t))
358
359 typedef struct _lwt_page {
360         struct list_head     lwtp_list;
361         struct page         *lwtp_page;
362         lwt_event_t         *lwtp_events;
363 } lwt_page_t;
364
365 typedef struct {
366         int                lwtc_current_index;
367         lwt_page_t        *lwtc_current_page;
368 } lwt_cpu_t;
369
370 extern int       lwt_enabled;
371 extern lwt_cpu_t lwt_cpus[];
372
373 extern int  lwt_init (void);
374 extern void lwt_fini (void);
375 extern int  lwt_lookup_string (int *size, char *knlptr,
376                                char *usrptr, int usrsize);
377 extern int  lwt_control (int enable, int clear);
378 extern int  lwt_snapshot (cycles_t *now, int *ncpu, int *total_size,
379                           void *user_ptr, int user_size);
380
381 /* Note that we _don't_ define LWT_EVENT at all if LWT_SUPPORT isn't set.
382  * This stuff is meant for finding specific problems; it never stays in
383  * production code... */
384
385 #define LWTSTR(n)       #n
386 #define LWTWHERE(f,l)   f ":" LWTSTR(l)
387
388 #define LWT_EVENT(p1, p2, p3, p4)                                       \
389 do {                                                                    \
390         unsigned long    flags;                                         \
391         lwt_cpu_t       *cpu;                                           \
392         lwt_page_t      *p;                                             \
393         lwt_event_t     *e;                                             \
394                                                                         \
395         local_irq_save (flags);                                         \
396                                                                         \
397         if (lwt_enabled) {                                              \
398                 cpu = &lwt_cpus[smp_processor_id()];                    \
399                 p = cpu->lwtc_current_page;                             \
400                 e = &p->lwtp_events[cpu->lwtc_current_index++];         \
401                                                                         \
402                 if (cpu->lwtc_current_index >= LWT_EVENTS_PER_PAGE) {   \
403                         cpu->lwtc_current_page =                        \
404                                 list_entry (p->lwtp_list.next,          \
405                                             lwt_page_t, lwtp_list);     \
406                         cpu->lwtc_current_index = 0;                    \
407                 }                                                       \
408                                                                         \
409                 e->lwte_when  = get_cycles();                           \
410                 e->lwte_where = LWTWHERE(__FILE__,__LINE__);            \
411                 e->lwte_task  = current;                                \
412                 e->lwte_p1    = (long)(p1);                             \
413                 e->lwte_p2    = (long)(p2);                             \
414                 e->lwte_p3    = (long)(p3);                             \
415                 e->lwte_p4    = (long)(p4);                             \
416         }                                                               \
417                                                                         \
418         local_irq_restore (flags);                                      \
419 } while (0)
420 #else  /* __KERNEL__ */
421 #define LWT_EVENT(p1,p2,p3,p4)     /* no userland implementation yet */
422 #endif /* __KERNEL__ */
423 #endif /* LWT_SUPPORT */
424
425 struct portals_device_userstate
426 {
427         int          pdu_memhog_pages;
428         struct page *pdu_memhog_root_page;
429 };
430
431 #include <linux/portals_lib.h>
432
433 /*
434  * USER LEVEL STUFF BELOW
435  */
436
437 #define PORTAL_IOCTL_VERSION 0x00010007
438 #define PING_SYNC       0
439 #define PING_ASYNC      1
440
441 struct portal_ioctl_hdr {
442         __u32 ioc_len;
443         __u32 ioc_version;
444 };
445
446 struct portals_debug_ioctl_data
447 {
448         struct portal_ioctl_hdr hdr;
449         unsigned int subs;
450         unsigned int debug;
451 };
452
453 #define PORTAL_IOC_INIT(data)                           \
454 do {                                                    \
455         memset(&data, 0, sizeof(data));                 \
456         data.ioc_version = PORTAL_IOCTL_VERSION;        \
457         data.ioc_len = sizeof(data);                    \
458 } while (0)
459
460 /* FIXME check conflict with lustre_lib.h */
461 #define PTL_IOC_DEBUG_MASK             _IOWR('f', 250, long)
462
463 static inline int portal_ioctl_packlen(struct portal_ioctl_data *data)
464 {
465         int len = sizeof(*data);
466         len += size_round(data->ioc_inllen1);
467         len += size_round(data->ioc_inllen2);
468         return len;
469 }
470
471 static inline int portal_ioctl_is_invalid(struct portal_ioctl_data *data)
472 {
473         if (data->ioc_len > (1<<30)) {
474                 CERROR ("PORTALS ioctl: ioc_len larger than 1<<30\n");
475                 return 1;
476         }
477         if (data->ioc_inllen1 > (1<<30)) {
478                 CERROR ("PORTALS ioctl: ioc_inllen1 larger than 1<<30\n");
479                 return 1;
480         }
481         if (data->ioc_inllen2 > (1<<30)) {
482                 CERROR ("PORTALS ioctl: ioc_inllen2 larger than 1<<30\n");
483                 return 1;
484         }
485         if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
486                 CERROR ("PORTALS ioctl: inlbuf1 pointer but 0 length\n");
487                 return 1;
488         }
489         if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
490                 CERROR ("PORTALS ioctl: inlbuf2 pointer but 0 length\n");
491                 return 1;
492         }
493         if (data->ioc_pbuf1 && !data->ioc_plen1) {
494                 CERROR ("PORTALS ioctl: pbuf1 pointer but 0 length\n");
495                 return 1;
496         }
497         if (data->ioc_pbuf2 && !data->ioc_plen2) {
498                 CERROR ("PORTALS ioctl: pbuf2 pointer but 0 length\n");
499                 return 1;
500         }
501         if (data->ioc_plen1 && !data->ioc_pbuf1) {
502                 CERROR ("PORTALS ioctl: plen1 nonzero but no pbuf1 pointer\n");
503                 return 1;
504         }
505         if (data->ioc_plen2 && !data->ioc_pbuf2) {
506                 CERROR ("PORTALS ioctl: plen2 nonzero but no pbuf2 pointer\n");
507                 return 1;
508         }
509         if (portal_ioctl_packlen(data) != data->ioc_len ) {
510                 CERROR ("PORTALS ioctl: packlen != ioc_len\n");
511                 return 1;
512         }
513         if (data->ioc_inllen1 &&
514             data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
515                 CERROR ("PORTALS ioctl: inlbuf1 not 0 terminated\n");
516                 return 1;
517         }
518         if (data->ioc_inllen2 &&
519             data->ioc_bulk[size_round(data->ioc_inllen1) +
520                            data->ioc_inllen2 - 1] != '\0') {
521                 CERROR ("PORTALS ioctl: inlbuf2 not 0 terminated\n");
522                 return 1;
523         }
524         return 0;
525 }
526
527 #ifndef __KERNEL__
528 static inline int portal_ioctl_pack(struct portal_ioctl_data *data, char **pbuf,
529                                     int max)
530 {
531         char *ptr;
532         struct portal_ioctl_data *overlay;
533         data->ioc_len = portal_ioctl_packlen(data);
534         data->ioc_version = PORTAL_IOCTL_VERSION;
535
536         if (*pbuf && portal_ioctl_packlen(data) > max)
537                 return 1;
538         if (*pbuf == NULL) {
539                 *pbuf = malloc(data->ioc_len);
540         }
541         if (!*pbuf)
542                 return 1;
543         overlay = (struct portal_ioctl_data *)*pbuf;
544         memcpy(*pbuf, data, sizeof(*data));
545
546         ptr = overlay->ioc_bulk;
547         if (data->ioc_inlbuf1)
548                 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
549         if (data->ioc_inlbuf2)
550                 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
551         if (portal_ioctl_is_invalid(overlay))
552                 return 1;
553
554         return 0;
555 }
556 #else
557 #include <asm/uaccess.h>
558
559 /* buffer MUST be at least the size of portal_ioctl_hdr */
560 static inline int portal_ioctl_getdata(char *buf, char *end, void *arg)
561 {
562         struct portal_ioctl_hdr *hdr;
563         struct portal_ioctl_data *data;
564         int err;
565         ENTRY;
566
567         hdr = (struct portal_ioctl_hdr *)buf;
568         data = (struct portal_ioctl_data *)buf;
569
570         err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
571         if ( err ) {
572                 EXIT;
573                 return err;
574         }
575
576         if (hdr->ioc_version != PORTAL_IOCTL_VERSION) {
577                 CERROR ("PORTALS: version mismatch kernel vs application\n");
578                 return -EINVAL;
579         }
580
581         if (hdr->ioc_len + buf >= end) {
582                 CERROR ("PORTALS: user buffer exceeds kernel buffer\n");
583                 return -EINVAL;
584         }
585
586
587         if (hdr->ioc_len < sizeof(struct portal_ioctl_data)) {
588                 CERROR ("PORTALS: user buffer too small for ioctl\n");
589                 return -EINVAL;
590         }
591
592         err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
593         if ( err ) {
594                 EXIT;
595                 return err;
596         }
597
598         if (portal_ioctl_is_invalid(data)) {
599                 CERROR ("PORTALS: ioctl not correctly formatted\n");
600                 return -EINVAL;
601         }
602
603         if (data->ioc_inllen1) {
604                 data->ioc_inlbuf1 = &data->ioc_bulk[0];
605         }
606
607         if (data->ioc_inllen2) {
608                 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
609                         size_round(data->ioc_inllen1);
610         }
611
612         EXIT;
613         return 0;
614 }
615 #endif
616
617 /* ioctls for manipulating snapshots 30- */
618 #define IOC_PORTAL_TYPE                   'e'
619 #define IOC_PORTAL_MIN_NR                 30
620
621 #define IOC_PORTAL_PING                    _IOWR('e', 30, long)
622 #define IOC_PORTAL_GET_DEBUG               _IOWR('e', 31, long)
623 #define IOC_PORTAL_CLEAR_DEBUG             _IOWR('e', 32, long)
624 #define IOC_PORTAL_MARK_DEBUG              _IOWR('e', 33, long)
625 #define IOC_PORTAL_PANIC                   _IOWR('e', 34, long)
626 #define IOC_PORTAL_NAL_CMD                 _IOWR('e', 35, long)
627 #define IOC_PORTAL_GET_NID                 _IOWR('e', 36, long)
628 #define IOC_PORTAL_FAIL_NID                _IOWR('e', 37, long)
629 #define IOC_PORTAL_SET_DAEMON              _IOWR('e', 38, long)
630 #define IOC_PORTAL_LWT_CONTROL             _IOWR('e', 39, long)
631 #define IOC_PORTAL_LWT_SNAPSHOT            _IOWR('e', 40, long)
632 #define IOC_PORTAL_LWT_LOOKUP_STRING       _IOWR('e', 41, long)
633 #define IOC_PORTAL_MEMHOG                  _IOWR('e', 42, long)
634 #define IOC_PORTAL_MAX_NR                             42
635
636 enum {
637         QSWNAL    = 1,
638         SOCKNAL   = 2,
639         GMNAL     = 3,
640         /*          4 unused */
641         TCPNAL    = 5,
642         ROUTER    = 6,
643         IBNAL     = 7,
644         NAL_ENUM_END_MARKER
645 };
646
647 #define PTL_NALFMT_SIZE               26 /* %u:%u.%u.%u.%u (10+4+4+4+3+1) */
648
649 #define NAL_MAX_NR (NAL_ENUM_END_MARKER - 1)
650
651 #define NAL_CMD_REGISTER_PEER_FD     100
652 #define NAL_CMD_CLOSE_CONNECTION     101
653 #define NAL_CMD_REGISTER_MYNID       102
654 #define NAL_CMD_PUSH_CONNECTION      103
655 #define NAL_CMD_GET_CONN             104
656 #define NAL_CMD_DEL_AUTOCONN         105
657 #define NAL_CMD_ADD_AUTOCONN         106
658 #define NAL_CMD_GET_AUTOCONN         107
659 #define NAL_CMD_GET_TXDESC           108
660 #define NAL_CMD_ADD_ROUTE            109
661 #define NAL_CMD_DEL_ROUTE            110
662 #define NAL_CMD_GET_ROUTE            111
663 #define NAL_CMD_NOTIFY_ROUTER        112
664
665 enum {
666         DEBUG_DAEMON_START       =  1,
667         DEBUG_DAEMON_STOP        =  2,
668         DEBUG_DAEMON_PAUSE       =  3,
669         DEBUG_DAEMON_CONTINUE    =  4,
670 };
671
672
673 enum cfg_record_type {
674         PORTALS_CFG_TYPE = 1,
675         LUSTRE_CFG_TYPE = 123,
676 };
677
678 typedef int (*cfg_record_cb_t)(enum cfg_record_type, int len, void *data);
679
680 #ifdef __CYGWIN__
681 # ifndef BITS_PER_LONG
682 #  if (~0UL) == 0xffffffffUL
683 #   define BITS_PER_LONG 32
684 #  else
685 #   define BITS_PER_LONG 64
686 #  endif
687 # endif
688 #endif
689
690 #if BITS_PER_LONG > 32
691 # define LI_POISON ((int)0x5a5a5a5a5a5a5a5a)
692 # define LL_POISON ((long)0x5a5a5a5a5a5a5a5a)
693 # define LP_POISON ((void *)(long)0x5a5a5a5a5a5a5a5a)
694 #else
695 # define LI_POISON ((int)0x5a5a5a5a)
696 # define LL_POISON ((long)0x5a5a5a5a)
697 # define LP_POISON ((void *)(long)0x5a5a5a5a)
698 #endif
699
700 #if defined(__x86_64__)
701 # define LPU64 "%Lu"
702 # define LPD64 "%Ld"
703 # define LPX64 "%#Lx"
704 # define LPSZ  "%lu"
705 # define LPSSZ "%ld"
706 #elif (BITS_PER_LONG == 32 || __WORDSIZE == 32)
707 # define LPU64 "%Lu"
708 # define LPD64 "%Ld"
709 # define LPX64 "%#Lx"
710 # define LPSZ  "%u"
711 # define LPSSZ "%d"
712 #elif (BITS_PER_LONG == 64 || __WORDSIZE == 64)
713 # define LPU64 "%lu"
714 # define LPD64 "%ld"
715 # define LPX64 "%#lx"
716 # define LPSZ  "%lu"
717 # define LPSSZ "%ld"
718 #endif
719 #ifndef LPU64
720 # error "No word size defined"
721 #endif
722
723 #endif