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