Whamcloud - gitweb
* Landed portals:b_port_step as follows...
[fs/lustre-release.git] / lnet / include / libcfs / linux / libcfs.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4 #ifndef __LIBCFS_LINUX_LIBCFS_H__
5 #define __LIBCFS_LINUX_LIBCFS_H__
6
7 #ifndef __LIBCFS_LIBCFS_H__
8 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
9 #endif
10
11 #include <libcfs/linux/linux-mem.h>
12 #include <libcfs/linux/linux-time.h>
13 #include <libcfs/linux/linux-prim.h>
14 #include <libcfs/linux/linux-lock.h>
15 #include <libcfs/linux/linux-fs.h>
16
17 #ifdef HAVE_ASM_TYPES_H
18 #include <asm/types.h>
19 #else
20 #include "types.h"
21 #endif
22
23
24 #ifdef __KERNEL__
25 # include <linux/types.h>
26 # include <linux/time.h>
27 # include <asm/timex.h>
28 #else
29 # include <sys/types.h>
30 # include <sys/time.h>
31 # define do_gettimeofday(tv) gettimeofday(tv, NULL);
32 typedef unsigned long long cycles_t;
33 #endif
34
35 #ifndef __KERNEL__
36 /* Userpace byte flipping */
37 # include <endian.h>
38 # include <byteswap.h>
39 # define __swab16(x) bswap_16(x)
40 # define __swab32(x) bswap_32(x)
41 # define __swab64(x) bswap_64(x)
42 # define __swab16s(x) do {*(x) = bswap_16(*(x));} while (0)
43 # define __swab32s(x) do {*(x) = bswap_32(*(x));} while (0)
44 # define __swab64s(x) do {*(x) = bswap_64(*(x));} while (0)
45 # if __BYTE_ORDER == __LITTLE_ENDIAN
46 #  define le16_to_cpu(x) (x)
47 #  define cpu_to_le16(x) (x)
48 #  define le32_to_cpu(x) (x)
49 #  define cpu_to_le32(x) (x)
50 #  define le64_to_cpu(x) (x)
51 #  define cpu_to_le64(x) (x)
52 # else
53 #  if __BYTE_ORDER == __BIG_ENDIAN
54 #   define le16_to_cpu(x) bswap_16(x)
55 #   define cpu_to_le16(x) bswap_16(x)
56 #   define le32_to_cpu(x) bswap_32(x)
57 #   define cpu_to_le32(x) bswap_32(x)
58 #   define le64_to_cpu(x) bswap_64(x)
59 #   define cpu_to_le64(x) bswap_64(x)
60 #  else
61 #   error "Unknown byte order"
62 #  endif /* __BIG_ENDIAN */
63 # endif /* __LITTLE_ENDIAN */
64 #endif /* ! __KERNEL__ */
65
66 struct ptldebug_header {
67         __u32 ph_len;
68         __u32 ph_flags;
69         __u32 ph_subsys;
70         __u32 ph_mask;
71         __u32 ph_cpu_id;
72         __u32 ph_sec;
73         __u64 ph_usec;
74         __u32 ph_stack;
75         __u32 ph_pid;
76         __u32 ph_extern_pid;
77         __u32 ph_line_num;
78 } __attribute__((packed));
79
80 #ifdef __KERNEL__
81 # include <linux/sched.h> /* THREAD_SIZE */
82 #else
83 # ifndef THREAD_SIZE /* x86_64 has THREAD_SIZE in userspace */
84 #  define THREAD_SIZE 8192
85 # endif
86 #endif
87
88 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
89
90 #ifdef __KERNEL__
91 # ifdef  __ia64__
92 #  define CDEBUG_STACK (THREAD_SIZE -                                      \
93                         ((unsigned long)__builtin_dwarf_cfa() &            \
94                          (THREAD_SIZE - 1)))
95 # else
96 #  define CDEBUG_STACK (THREAD_SIZE -                                      \
97                         ((unsigned long)__builtin_frame_address(0) &       \
98                          (THREAD_SIZE - 1)))
99 # endif /* __ia64__ */
100
101 #define CHECK_STACK(stack)                                                    \
102         do {                                                                  \
103                 if ((stack) > 3*THREAD_SIZE/4 && (stack) > portal_stack) {    \
104                         portals_debug_msg(DEBUG_SUBSYSTEM, D_WARNING,         \
105                                           __FILE__, __FUNCTION__, __LINE__,   \
106                                           (stack),"maximum lustre stack %u\n",\
107                                           portal_stack = (stack));            \
108                       /*panic("LBUG");*/                                      \
109                 }                                                             \
110         } while (0)
111 #else /* !__KERNEL__ */
112 #define CHECK_STACK(stack) do { } while(0)
113 #define CDEBUG_STACK (0L)
114 #endif /* __KERNEL__ */
115
116 /* initial pid  */
117 # if CRAY_PORTALS
118 /*
119  * 1) ptl_pid_t in cray portals is only 16 bits, not 32 bits, therefore this
120  *    is too big.
121  *
122  * 2) the implementation of ernal in cray portals further restricts the pid
123  *    space that may be used to 0 <= pid <= 255 (an 8 bit value).  Returns
124  *    an error at nal init time for any pid outside this range.  Other nals
125  *    in cray portals don't have this restriction.
126  * */
127 #define LUSTRE_PTL_PID          9
128 # else
129 #define LUSTRE_PTL_PID          12345
130 # endif
131
132 #define ENTRY_NESTING_SUPPORT (0)
133 #define ENTRY_NESTING   do {;} while (0)
134 #define EXIT_NESTING   do {;} while (0)
135 #define __current_nesting_level() (0)
136
137 /*
138  * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
139  *
140  * Implementation is in linux-curproc.c
141  */
142 #define CFS_CURPROC_COMM_MAX (sizeof ((struct task_struct *)0)->comm)
143
144 #if defined(__KERNEL__)
145 #include <linux/capability.h>
146 typedef kernel_cap_t cfs_kernel_cap_t;
147 #else
148 typedef __u32 cfs_kernel_cap_t;
149 #endif
150
151 #endif /* _LINUX_LIBCFS_H */