Whamcloud - gitweb
Landing b_hd_newconfig on HEAD
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd_lib-linux.h
1 #define DEBUG_PORTAL_ALLOC
2 #ifndef EXPORT_SYMTAB
3 # define EXPORT_SYMTAB
4 #endif
5
6 #ifndef __LINUX_SOCKNAL_LIB_H__
7 #define __LINUX_SOCKNAL_LIB_H__
8
9 #ifdef HAVE_KERNEL_CONFIG_H
10 #include <linux/config.h>
11 #endif
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/version.h>
15 #include <linux/mm.h>
16 #include <linux/string.h>
17 #include <linux/stat.h>
18 #include <linux/errno.h>
19 #include <linux/smp_lock.h>
20 #include <linux/unistd.h>
21 #include <net/sock.h>
22 #include <net/tcp.h>
23 #include <linux/uio.h>
24
25 #include <asm/system.h>
26 #include <asm/uaccess.h>
27 #include <asm/irq.h>
28
29 #include <linux/init.h>
30 #include <linux/fs.h>
31 #include <linux/file.h>
32 #include <linux/stat.h>
33 #include <linux/list.h>
34 #include <linux/kmod.h>
35 #include <linux/sysctl.h>
36 #include <asm/uaccess.h>
37 #include <asm/segment.h>
38 #include <asm/div64.h>
39
40 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
41 # include <linux/syscalls.h>
42 #endif
43
44 #include <libcfs/kp30.h>
45 #include <libcfs/linux/portals_compat25.h>
46
47 #include <linux/crc32.h>
48 static inline __u32 ksocknal_csum(__u32 crc, unsigned char const *p, size_t len)
49 {
50 #if 1
51         return crc32_le(crc, p, len);
52 #else
53         while (len-- > 0)
54                 crc = ((crc + 0x100) & ~0xff) | ((crc + *p++) & 0xff) ;
55         return crc;
56 #endif
57 }
58
59 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,7))
60 # define SOCKNAL_WSPACE(sk)       sk_stream_wspace(sk)
61 # define SOCKNAL_MIN_WSPACE(sk)   sk_stream_min_wspace(sk)
62 #else
63 # define SOCKNAL_WSPACE(sk)     tcp_wspace(sk)
64 # define SOCKNAL_MIN_WSPACE(sk) (((sk)->sk_sndbuf*8)/10)
65 #endif
66
67 #ifndef CONFIG_SMP
68 static inline
69 int ksocknal_nsched(void)
70 {
71         return 1;
72 }
73 #else
74 #include <linux/lustre_version.h>
75 # if !(defined(CONFIG_X86) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21))) || defined(CONFIG_X86_64) || (LUSTRE_KERNEL_VERSION < 39) || ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) && !defined(CONFIG_X86_HT))
76 static inline int
77 ksocknal_nsched(void)
78 {
79         return num_online_cpus();
80 }
81
82 static inline int
83 ksocknal_sched2cpu(int i)
84 {
85         return i;
86 }
87
88 static inline int
89 ksocknal_irqsched2cpu(int i)
90 {
91         return i;
92 }
93 # else
94 static inline int
95 ksocknal_nsched(void)
96 {
97         if (smp_num_siblings == 1)
98                 return (num_online_cpus());
99
100         /* We need to know if this assumption is crap */
101         LASSERT (smp_num_siblings == 2);
102         return (num_online_cpus()/2);
103 }
104
105 static inline int
106 ksocknal_sched2cpu(int i)
107 {
108         if (smp_num_siblings == 1)
109                 return i;
110
111         return (i * 2);
112 }
113
114 static inline int
115 ksocknal_irqsched2cpu(int i)
116 {
117         return (ksocknal_sched2cpu(i) + 1);
118 }
119 # endif
120 #endif
121
122 #endif