Whamcloud - gitweb
Revert "b=21951 2.6.32-fc13 patchless client support for HEAD"
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd_lib-linux.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #define DEBUG_PORTAL_ALLOC
38 #ifndef EXPORT_SYMTAB
39 # define EXPORT_SYMTAB
40 #endif
41
42 #ifndef __LINUX_SOCKNAL_LIB_H__
43 #define __LINUX_SOCKNAL_LIB_H__
44
45 #ifndef AUTOCONF_INCLUDED
46 #include <linux/config.h>
47 #endif
48 #include <linux/module.h>
49 #include <linux/kernel.h>
50 #include <linux/version.h>
51 #include <linux/mm.h>
52 #include <linux/string.h>
53 #include <linux/stat.h>
54 #include <linux/errno.h>
55 #include <linux/smp_lock.h>
56 #include <linux/unistd.h>
57 #include <net/sock.h>
58 #include <net/tcp.h>
59 #include <linux/uio.h>
60
61 #include <asm/system.h>
62 #include <asm/uaccess.h>
63 #include <asm/irq.h>
64
65 #include <linux/init.h>
66 #include <linux/fs.h>
67 #include <linux/file.h>
68 #include <linux/stat.h>
69 #include <linux/list.h>
70 #include <linux/kmod.h>
71 #include <linux/sysctl.h>
72 #include <asm/uaccess.h>
73 #include <asm/div64.h>
74
75 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
76 # include <linux/syscalls.h>
77 #endif
78
79 #include <libcfs/libcfs.h>
80 #include <libcfs/linux/portals_compat25.h>
81
82 #include <linux/crc32.h>
83 static inline __u32 ksocknal_csum(__u32 crc, unsigned char const *p, size_t len)
84 {
85 #if 1
86         return crc32_le(crc, p, len);
87 #else
88         while (len-- > 0)
89                 crc = ((crc + 0x100) & ~0xff) | ((crc + *p++) & 0xff) ;
90         return crc;
91 #endif
92 }
93
94 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,7))
95 # define SOCKNAL_WSPACE(sk)       sk_stream_wspace(sk)
96 # define SOCKNAL_MIN_WSPACE(sk)   sk_stream_min_wspace(sk)
97 #else
98 # define SOCKNAL_WSPACE(sk)     tcp_wspace(sk)
99 # define SOCKNAL_MIN_WSPACE(sk) (((sk)->sk_sndbuf*8)/10)
100 #endif
101
102 #ifndef CONFIG_SMP
103 static inline
104 int ksocknal_nsched(void)
105 {
106         return 1;
107 }
108 #else
109 #include <linux/lustre_version.h>
110 # 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))
111 static inline int
112 ksocknal_nsched(void)
113 {
114         return num_online_cpus();
115 }
116
117 static inline int
118 ksocknal_sched2cpu(int i)
119 {
120         return i;
121 }
122
123 static inline int
124 ksocknal_irqsched2cpu(int i)
125 {
126         return i;
127 }
128 # else
129 static inline int
130 ksocknal_nsched(void)
131 {
132         if (smp_num_siblings == 1)
133                 return (num_online_cpus());
134
135         /* We need to know if this assumption is crap */
136         LASSERT (smp_num_siblings == 2);
137         return (num_online_cpus()/2);
138 }
139
140 static inline int
141 ksocknal_sched2cpu(int i)
142 {
143         if (smp_num_siblings == 1)
144                 return i;
145
146         return (i * 2);
147 }
148
149 static inline int
150 ksocknal_irqsched2cpu(int i)
151 {
152         return (ksocknal_sched2cpu(i) + 1);
153 }
154 # endif
155 #endif
156
157 #endif