aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/include/sysdep-i386/checksum.h
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/include/sysdep-i386/checksum.h')
-rw-r--r--arch/um/include/sysdep-i386/checksum.h74
1 files changed, 30 insertions, 44 deletions
diff --git a/arch/um/include/sysdep-i386/checksum.h b/arch/um/include/sysdep-i386/checksum.h
index 052bb061a978..0cb4645cbeb8 100644
--- a/arch/um/include/sysdep-i386/checksum.h
+++ b/arch/um/include/sysdep-i386/checksum.h
@@ -20,8 +20,7 @@
20 * 20 *
21 * it's best to have buff aligned on a 32-bit boundary 21 * it's best to have buff aligned on a 32-bit boundary
22 */ 22 */
23unsigned int csum_partial(const unsigned char * buff, int len, 23__wsum csum_partial(const void *buff, int len, __wsum sum);
24 unsigned int sum);
25 24
26/* 25/*
27 * Note: when you get a NULL pointer exception here this means someone 26 * Note: when you get a NULL pointer exception here this means someone
@@ -32,8 +31,8 @@ unsigned int csum_partial(const unsigned char * buff, int len,
32 */ 31 */
33 32
34static __inline__ 33static __inline__
35unsigned int csum_partial_copy_nocheck(const unsigned char *src, unsigned char *dst, 34__wsum csum_partial_copy_nocheck(const void *src, void *dst,
36 int len, int sum) 35 int len, __wsum sum)
37{ 36{
38 memcpy(dst, src, len); 37 memcpy(dst, src, len);
39 return csum_partial(dst, len, sum); 38 return csum_partial(dst, len, sum);
@@ -48,36 +47,25 @@ unsigned int csum_partial_copy_nocheck(const unsigned char *src, unsigned char *
48 */ 47 */
49 48
50static __inline__ 49static __inline__
51unsigned int csum_partial_copy_from_user(const unsigned char __user *src, 50__wsum csum_partial_copy_from_user(const void __user *src, void *dst,
52 unsigned char *dst, 51 int len, __wsum sum, int *err_ptr)
53 int len, int sum, int *err_ptr)
54{ 52{
55 if(copy_from_user(dst, src, len)){ 53 if (copy_from_user(dst, src, len)) {
56 *err_ptr = -EFAULT; 54 *err_ptr = -EFAULT;
57 return(-1); 55 return (__force __wsum)-1;
58 } 56 }
59 57
60 return csum_partial(dst, len, sum); 58 return csum_partial(dst, len, sum);
61} 59}
62 60
63/* 61/*
64 * These are the old (and unsafe) way of doing checksums, a warning message
65 * will be printed if they are used and an exception occurs.
66 *
67 * these functions should go away after some time.
68 */
69
70#define csum_partial_copy_fromuser csum_partial_copy_from_user
71
72/*
73 * This is a version of ip_compute_csum() optimized for IP headers, 62 * This is a version of ip_compute_csum() optimized for IP headers,
74 * which always checksum on 4 octet boundaries. 63 * which always checksum on 4 octet boundaries.
75 * 64 *
76 * By Jorge Cwik <jorge@laser.satlink.net>, adapted for linux by 65 * By Jorge Cwik <jorge@laser.satlink.net>, adapted for linux by
77 * Arnt Gulbrandsen. 66 * Arnt Gulbrandsen.
78 */ 67 */
79static inline unsigned short ip_fast_csum(unsigned char * iph, 68static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
80 unsigned int ihl)
81{ 69{
82 unsigned int sum; 70 unsigned int sum;
83 71
@@ -105,29 +93,29 @@ static inline unsigned short ip_fast_csum(unsigned char * iph,
105 : "=r" (sum), "=r" (iph), "=r" (ihl) 93 : "=r" (sum), "=r" (iph), "=r" (ihl)
106 : "1" (iph), "2" (ihl) 94 : "1" (iph), "2" (ihl)
107 : "memory"); 95 : "memory");
108 return sum; 96 return (__force __sum16)sum;
109} 97}
110 98
111/* 99/*
112 * Fold a partial checksum 100 * Fold a partial checksum
113 */ 101 */
114 102
115static inline unsigned int csum_fold(unsigned int sum) 103static inline __sum16 csum_fold(__wsum sum)
116{ 104{
117 __asm__( 105 __asm__(
118 "addl %1, %0 ;\n" 106 "addl %1, %0 ;\n"
119 "adcl $0xffff, %0 ;\n" 107 "adcl $0xffff, %0 ;\n"
120 : "=r" (sum) 108 : "=r" (sum)
121 : "r" (sum << 16), "0" (sum & 0xffff0000) 109 : "r" ((__force u32)sum << 16),
110 "0" ((__force u32)sum & 0xffff0000)
122 ); 111 );
123 return (~sum) >> 16; 112 return (__force __sum16)(~(__force u32)sum >> 16);
124} 113}
125 114
126static inline unsigned long csum_tcpudp_nofold(unsigned long saddr, 115static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
127 unsigned long daddr,
128 unsigned short len, 116 unsigned short len,
129 unsigned short proto, 117 unsigned short proto,
130 unsigned int sum) 118 __wsum sum)
131{ 119{
132 __asm__( 120 __asm__(
133 "addl %1, %0 ;\n" 121 "addl %1, %0 ;\n"
@@ -135,7 +123,7 @@ static inline unsigned long csum_tcpudp_nofold(unsigned long saddr,
135 "adcl %3, %0 ;\n" 123 "adcl %3, %0 ;\n"
136 "adcl $0, %0 ;\n" 124 "adcl $0, %0 ;\n"
137 : "=r" (sum) 125 : "=r" (sum)
138 : "g" (daddr), "g"(saddr), "g"((ntohs(len)<<16)+proto*256), "0"(sum)); 126 : "g" (daddr), "g"(saddr), "g"((len + proto) << 8), "0"(sum));
139 return sum; 127 return sum;
140} 128}
141 129
@@ -143,11 +131,10 @@ static inline unsigned long csum_tcpudp_nofold(unsigned long saddr,
143 * computes the checksum of the TCP/UDP pseudo-header 131 * computes the checksum of the TCP/UDP pseudo-header
144 * returns a 16-bit checksum, already complemented 132 * returns a 16-bit checksum, already complemented
145 */ 133 */
146static inline unsigned short int csum_tcpudp_magic(unsigned long saddr, 134static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
147 unsigned long daddr,
148 unsigned short len, 135 unsigned short len,
149 unsigned short proto, 136 unsigned short proto,
150 unsigned int sum) 137 __wsum sum)
151{ 138{
152 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); 139 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
153} 140}
@@ -157,17 +144,16 @@ static inline unsigned short int csum_tcpudp_magic(unsigned long saddr,
157 * in icmp.c 144 * in icmp.c
158 */ 145 */
159 146
160static inline unsigned short ip_compute_csum(unsigned char * buff, int len) 147static inline __sum16 ip_compute_csum(const void *buff, int len)
161{ 148{
162 return csum_fold (csum_partial(buff, len, 0)); 149 return csum_fold (csum_partial(buff, len, 0));
163} 150}
164 151
165#define _HAVE_ARCH_IPV6_CSUM 152#define _HAVE_ARCH_IPV6_CSUM
166static __inline__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr, 153static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
167 struct in6_addr *daddr, 154 const struct in6_addr *daddr,
168 __u32 len, 155 __u32 len, unsigned short proto,
169 unsigned short proto, 156 __wsum sum)
170 unsigned int sum)
171{ 157{
172 __asm__( 158 __asm__(
173 "addl 0(%1), %0 ;\n" 159 "addl 0(%1), %0 ;\n"
@@ -192,14 +178,14 @@ static __inline__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr,
192 * Copy and checksum to user 178 * Copy and checksum to user
193 */ 179 */
194#define HAVE_CSUM_COPY_USER 180#define HAVE_CSUM_COPY_USER
195static __inline__ unsigned int csum_and_copy_to_user(const unsigned char *src, 181static __inline__ __wsum csum_and_copy_to_user(const void *src,
196 unsigned char __user *dst, 182 void __user *dst,
197 int len, int sum, int *err_ptr) 183 int len, __wsum sum, int *err_ptr)
198{ 184{
199 if (access_ok(VERIFY_WRITE, dst, len)){ 185 if (access_ok(VERIFY_WRITE, dst, len)) {
200 if(copy_to_user(dst, src, len)){ 186 if (copy_to_user(dst, src, len)) {
201 *err_ptr = -EFAULT; 187 *err_ptr = -EFAULT;
202 return(-1); 188 return (__force __wsum)-1;
203 } 189 }
204 190
205 return csum_partial(src, len, sum); 191 return csum_partial(src, len, sum);
@@ -208,7 +194,7 @@ static __inline__ unsigned int csum_and_copy_to_user(const unsigned char *src,
208 if (len) 194 if (len)
209 *err_ptr = -EFAULT; 195 *err_ptr = -EFAULT;
210 196
211 return -1; /* invalid checksum */ 197 return (__force __wsum)-1; /* invalid checksum */
212} 198}
213 199
214#endif 200#endif