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