Whamcloud - gitweb
Branch b1_6
[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 #ifndef AUTOCONF_INCLUDED
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 #ifdef HAVE_SEGMENT_H
38 # include <asm/segment.h>
39 #endif
40 #include <asm/div64.h>
41
42 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
43 # include <linux/syscalls.h>
44 #endif
45
46 #include <libcfs/kp30.h>
47 #include <libcfs/linux/portals_compat25.h>
48
49 #include <linux/crc32.h>
50 static inline __u32 ksocknal_csum(__u32 crc, unsigned char const *p, size_t len)
51 {
52 #if 1
53         return crc32_le(crc, p, len);
54 #else
55         while (len-- > 0)
56                 crc = ((crc + 0x100) & ~0xff) | ((crc + *p++) & 0xff) ;
57         return crc;
58 #endif
59 }
60
61 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,7))
62 # define SOCKNAL_WSPACE(sk)       sk_stream_wspace(sk)
63 # define SOCKNAL_MIN_WSPACE(sk)   sk_stream_min_wspace(sk)
64 #else
65 # define SOCKNAL_WSPACE(sk)     tcp_wspace(sk)
66 # define SOCKNAL_MIN_WSPACE(sk) (((sk)->sk_sndbuf*8)/10)
67 #endif
68
69 #ifndef CONFIG_SMP
70 static inline
71 int ksocknal_nsched(void)
72 {
73         return 1;
74 }
75 #else
76 #include <linux/lustre_version.h>
77 # if !(defined(CONFIG_X86) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21))) || defined(CONFIG_X86_64) || ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) && !defined(CONFIG_X86_HT))
78 static inline int
79 ksocknal_nsched(void)
80 {
81         return num_online_cpus();
82 }
83
84 static inline int
85 ksocknal_sched2cpu(int i)
86 {
87         return i;
88 }
89
90 static inline int
91 ksocknal_irqsched2cpu(int i)
92 {
93         return i;
94 }
95 # else
96 static inline int
97 ksocknal_nsched(void)
98 {
99         if (smp_num_siblings == 1)
100                 return (num_online_cpus());
101
102         /* We need to know if this assumption is crap */
103         LASSERT (smp_num_siblings == 2);
104         return (num_online_cpus()/2);
105 }
106
107 static inline int
108 ksocknal_sched2cpu(int i)
109 {
110         if (smp_num_siblings == 1)
111                 return i;
112
113         return (i * 2);
114 }
115
116 static inline int
117 ksocknal_irqsched2cpu(int i)
118 {
119         return (ksocknal_sched2cpu(i) + 1);
120 }
121 # endif
122 #endif
123
124 #endif