diff options
Diffstat (limited to 'include/asm-sh/checksum.h')
-rw-r--r-- | include/asm-sh/checksum.h | 94 |
1 files changed, 46 insertions, 48 deletions
diff --git a/include/asm-sh/checksum.h b/include/asm-sh/checksum.h index 08168afe6746..4bc8357e8892 100644 --- a/include/asm-sh/checksum.h +++ b/include/asm-sh/checksum.h | |||
@@ -23,7 +23,7 @@ | |||
23 | * | 23 | * |
24 | * it's best to have buff aligned on a 32-bit boundary | 24 | * it's best to have buff aligned on a 32-bit boundary |
25 | */ | 25 | */ |
26 | asmlinkage unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum); | 26 | asmlinkage __wsum csum_partial(const void *buff, int len, __wsum sum); |
27 | 27 | ||
28 | /* | 28 | /* |
29 | * the same as csum_partial, but copies from src while it | 29 | * the same as csum_partial, but copies from src while it |
@@ -33,35 +33,37 @@ asmlinkage unsigned int csum_partial(const unsigned char * buff, int len, unsign | |||
33 | * better 64-bit) boundary | 33 | * better 64-bit) boundary |
34 | */ | 34 | */ |
35 | 35 | ||
36 | asmlinkage unsigned int csum_partial_copy_generic(const unsigned char *src, unsigned char *dst, | 36 | asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst, |
37 | int len, int sum, int *src_err_ptr, int *dst_err_ptr); | 37 | int len, __wsum sum, |
38 | int *src_err_ptr, int *dst_err_ptr); | ||
38 | 39 | ||
39 | /* | 40 | /* |
40 | * Note: when you get a NULL pointer exception here this means someone | 41 | * Note: when you get a NULL pointer exception here this means someone |
41 | * passed in an incorrect kernel address to one of these functions. | 42 | * passed in an incorrect kernel address to one of these functions. |
42 | * | 43 | * |
43 | * If you use these functions directly please don't forget the | 44 | * If you use these functions directly please don't forget the |
44 | * access_ok(). | 45 | * access_ok(). |
45 | */ | 46 | */ |
46 | static __inline__ | 47 | static inline |
47 | unsigned int csum_partial_copy_nocheck (const unsigned char *src, unsigned char *dst, | 48 | __wsum csum_partial_copy_nocheck(const void *src, void *dst, |
48 | int len, int sum) | 49 | int len, __wsum sum) |
49 | { | 50 | { |
50 | return csum_partial_copy_generic ( src, dst, len, sum, NULL, NULL); | 51 | return csum_partial_copy_generic(src, dst, len, sum, NULL, NULL); |
51 | } | 52 | } |
52 | 53 | ||
53 | static __inline__ | 54 | static inline |
54 | unsigned int csum_partial_copy_from_user (const unsigned char *src, unsigned char *dst, | 55 | __wsum csum_partial_copy_from_user(const void __user *src, void *dst, |
55 | int len, int sum, int *err_ptr) | 56 | int len, __wsum sum, int *err_ptr) |
56 | { | 57 | { |
57 | return csum_partial_copy_generic ( src, dst, len, sum, err_ptr, NULL); | 58 | return csum_partial_copy_generic((__force const void *)src, dst, |
59 | len, sum, err_ptr, NULL); | ||
58 | } | 60 | } |
59 | 61 | ||
60 | /* | 62 | /* |
61 | * Fold a partial checksum | 63 | * Fold a partial checksum |
62 | */ | 64 | */ |
63 | 65 | ||
64 | static __inline__ unsigned int csum_fold(unsigned int sum) | 66 | static inline __sum16 csum_fold(__wsum sum) |
65 | { | 67 | { |
66 | unsigned int __dummy; | 68 | unsigned int __dummy; |
67 | __asm__("swap.w %0, %1\n\t" | 69 | __asm__("swap.w %0, %1\n\t" |
@@ -74,7 +76,7 @@ static __inline__ unsigned int csum_fold(unsigned int sum) | |||
74 | : "=r" (sum), "=&r" (__dummy) | 76 | : "=r" (sum), "=&r" (__dummy) |
75 | : "0" (sum) | 77 | : "0" (sum) |
76 | : "t"); | 78 | : "t"); |
77 | return sum; | 79 | return (__force __sum16)sum; |
78 | } | 80 | } |
79 | 81 | ||
80 | /* | 82 | /* |
@@ -84,7 +86,7 @@ static __inline__ unsigned int csum_fold(unsigned int sum) | |||
84 | * i386 version by Jorge Cwik <jorge@laser.satlink.net>, adapted | 86 | * i386 version by Jorge Cwik <jorge@laser.satlink.net>, adapted |
85 | * for linux by * Arnt Gulbrandsen. | 87 | * for linux by * Arnt Gulbrandsen. |
86 | */ | 88 | */ |
87 | static __inline__ unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl) | 89 | static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) |
88 | { | 90 | { |
89 | unsigned int sum, __dummy0, __dummy1; | 91 | unsigned int sum, __dummy0, __dummy1; |
90 | 92 | ||
@@ -112,16 +114,15 @@ static __inline__ unsigned short ip_fast_csum(unsigned char * iph, unsigned int | |||
112 | return csum_fold(sum); | 114 | return csum_fold(sum); |
113 | } | 115 | } |
114 | 116 | ||
115 | static __inline__ unsigned long csum_tcpudp_nofold(unsigned long saddr, | 117 | static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, |
116 | unsigned long daddr, | 118 | unsigned short len, |
117 | unsigned short len, | 119 | unsigned short proto, |
118 | unsigned short proto, | 120 | __wsum sum) |
119 | unsigned int sum) | ||
120 | { | 121 | { |
121 | #ifdef __LITTLE_ENDIAN__ | 122 | #ifdef __LITTLE_ENDIAN__ |
122 | unsigned long len_proto = (ntohs(len)<<16)+proto*256; | 123 | unsigned long len_proto = (proto + len) << 8; |
123 | #else | 124 | #else |
124 | unsigned long len_proto = (proto<<16)+len; | 125 | unsigned long len_proto = proto + len; |
125 | #endif | 126 | #endif |
126 | __asm__("clrt\n\t" | 127 | __asm__("clrt\n\t" |
127 | "addc %0, %1\n\t" | 128 | "addc %0, %1\n\t" |
@@ -132,6 +133,7 @@ static __inline__ unsigned long csum_tcpudp_nofold(unsigned long saddr, | |||
132 | : "=r" (sum), "=r" (len_proto) | 133 | : "=r" (sum), "=r" (len_proto) |
133 | : "r" (daddr), "r" (saddr), "1" (len_proto), "0" (sum) | 134 | : "r" (daddr), "r" (saddr), "1" (len_proto), "0" (sum) |
134 | : "t"); | 135 | : "t"); |
136 | |||
135 | return sum; | 137 | return sum; |
136 | } | 138 | } |
137 | 139 | ||
@@ -139,32 +141,28 @@ static __inline__ unsigned long csum_tcpudp_nofold(unsigned long saddr, | |||
139 | * computes the checksum of the TCP/UDP pseudo-header | 141 | * computes the checksum of the TCP/UDP pseudo-header |
140 | * returns a 16-bit checksum, already complemented | 142 | * returns a 16-bit checksum, already complemented |
141 | */ | 143 | */ |
142 | static __inline__ unsigned short int csum_tcpudp_magic(unsigned long saddr, | 144 | static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, |
143 | unsigned long daddr, | 145 | unsigned short len, |
144 | unsigned short len, | 146 | unsigned short proto, |
145 | unsigned short proto, | 147 | __wsum sum) |
146 | unsigned int sum) | ||
147 | { | 148 | { |
148 | return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); | 149 | return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum)); |
149 | } | 150 | } |
150 | 151 | ||
151 | /* | 152 | /* |
152 | * this routine is used for miscellaneous IP-like checksums, mainly | 153 | * this routine is used for miscellaneous IP-like checksums, mainly |
153 | * in icmp.c | 154 | * in icmp.c |
154 | */ | 155 | */ |
155 | 156 | static inline __sum16 ip_compute_csum(const void *buff, int len) | |
156 | static __inline__ unsigned short ip_compute_csum(unsigned char * buff, int len) | ||
157 | { | 157 | { |
158 | return csum_fold (csum_partial(buff, len, 0)); | 158 | return csum_fold(csum_partial(buff, len, 0)); |
159 | } | 159 | } |
160 | 160 | ||
161 | #define _HAVE_ARCH_IPV6_CSUM | 161 | #define _HAVE_ARCH_IPV6_CSUM |
162 | #ifdef CONFIG_IPV6 | 162 | static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr, |
163 | static __inline__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr, | 163 | const struct in6_addr *daddr, |
164 | struct in6_addr *daddr, | 164 | __u32 len, unsigned short proto, |
165 | __u32 len, | 165 | __wsum sum) |
166 | unsigned short proto, | ||
167 | unsigned int sum) | ||
168 | { | 166 | { |
169 | unsigned int __dummy; | 167 | unsigned int __dummy; |
170 | __asm__("clrt\n\t" | 168 | __asm__("clrt\n\t" |
@@ -189,29 +187,29 @@ static __inline__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr, | |||
189 | "movt %1\n\t" | 187 | "movt %1\n\t" |
190 | "add %1, %0\n" | 188 | "add %1, %0\n" |
191 | : "=r" (sum), "=&r" (__dummy) | 189 | : "=r" (sum), "=&r" (__dummy) |
192 | : "r" (saddr), "r" (daddr), | 190 | : "r" (saddr), "r" (daddr), |
193 | "r" (htonl(len)), "r" (htonl(proto)), "0" (sum) | 191 | "r" (htonl(len)), "r" (htonl(proto)), "0" (sum) |
194 | : "t"); | 192 | : "t"); |
195 | 193 | ||
196 | return csum_fold(sum); | 194 | return csum_fold(sum); |
197 | } | 195 | } |
198 | #endif | ||
199 | 196 | ||
200 | /* | 197 | /* |
201 | * Copy and checksum to user | 198 | * Copy and checksum to user |
202 | */ | 199 | */ |
203 | #define HAVE_CSUM_COPY_USER | 200 | #define HAVE_CSUM_COPY_USER |
204 | static __inline__ unsigned int csum_and_copy_to_user (const unsigned char *src, | 201 | static inline __wsum csum_and_copy_to_user(const void *src, |
205 | unsigned char __user *dst, | 202 | void __user *dst, |
206 | int len, int sum, | 203 | int len, __wsum sum, |
207 | int *err_ptr) | 204 | int *err_ptr) |
208 | { | 205 | { |
209 | if (access_ok(VERIFY_WRITE, dst, len)) | 206 | if (access_ok(VERIFY_WRITE, dst, len)) |
210 | return csum_partial_copy_generic(src, dst, len, sum, NULL, err_ptr); | 207 | return csum_partial_copy_generic((__force const void *)src, |
208 | dst, len, sum, NULL, err_ptr); | ||
211 | 209 | ||
212 | if (len) | 210 | if (len) |
213 | *err_ptr = -EFAULT; | 211 | *err_ptr = -EFAULT; |
214 | 212 | ||
215 | return -1; /* invalid checksum */ | 213 | return (__force __wsum)-1; /* invalid checksum */ |
216 | } | 214 | } |
217 | #endif /* __ASM_SH_CHECKSUM_H */ | 215 | #endif /* __ASM_SH_CHECKSUM_H */ |