diff options
author | Paul Mundt <lethal@linux-sh.org> | 2009-06-14 11:00:42 -0400 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2009-06-14 11:00:42 -0400 |
commit | 3767f3f1ee11da55760616a2c68a09c02babdd9b (patch) | |
tree | 41f01349b06063bd9ba52c6bb852cb34797a9331 /arch/sh | |
parent | 2b74b85693c7c0772e8787883230cd15314555f8 (diff) |
sh: Convert sh64 to use the generic checksum code.
This plugs in GENERIC_CSUM support on sh64, and kills off all of the old
references.
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'arch/sh')
-rw-r--r-- | arch/sh/Kconfig | 4 | ||||
-rw-r--r-- | arch/sh/include/asm/checksum.h | 2 | ||||
-rw-r--r-- | arch/sh/include/asm/checksum_64.h | 78 | ||||
-rw-r--r-- | arch/sh/kernel/sh_ksyms_64.c | 7 | ||||
-rw-r--r-- | arch/sh/lib64/Makefile | 2 | ||||
-rw-r--r-- | arch/sh/lib64/c-checksum.c | 214 |
6 files changed, 6 insertions, 301 deletions
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index 586cd045e2db..739a12d2ffb9 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig | |||
@@ -50,6 +50,10 @@ config GENERIC_BUG | |||
50 | def_bool y | 50 | def_bool y |
51 | depends on BUG && SUPERH32 | 51 | depends on BUG && SUPERH32 |
52 | 52 | ||
53 | config GENERIC_CSUM | ||
54 | def_bool y | ||
55 | depends on SUPERH64 | ||
56 | |||
53 | config GENERIC_FIND_NEXT_BIT | 57 | config GENERIC_FIND_NEXT_BIT |
54 | def_bool y | 58 | def_bool y |
55 | 59 | ||
diff --git a/arch/sh/include/asm/checksum.h b/arch/sh/include/asm/checksum.h index 67496ab0ef04..fc26d1f4b590 100644 --- a/arch/sh/include/asm/checksum.h +++ b/arch/sh/include/asm/checksum.h | |||
@@ -1,5 +1,5 @@ | |||
1 | #ifdef CONFIG_SUPERH32 | 1 | #ifdef CONFIG_SUPERH32 |
2 | # include "checksum_32.h" | 2 | # include "checksum_32.h" |
3 | #else | 3 | #else |
4 | # include "checksum_64.h" | 4 | # include <asm-generic/checksum.h> |
5 | #endif | 5 | #endif |
diff --git a/arch/sh/include/asm/checksum_64.h b/arch/sh/include/asm/checksum_64.h deleted file mode 100644 index 9c62a031a8f5..000000000000 --- a/arch/sh/include/asm/checksum_64.h +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | #ifndef __ASM_SH_CHECKSUM_64_H | ||
2 | #define __ASM_SH_CHECKSUM_64_H | ||
3 | |||
4 | /* | ||
5 | * include/asm-sh/checksum_64.h | ||
6 | * | ||
7 | * Copyright (C) 2000, 2001 Paolo Alberelli | ||
8 | * | ||
9 | * This file is subject to the terms and conditions of the GNU General Public | ||
10 | * License. See the file "COPYING" in the main directory of this archive | ||
11 | * for more details. | ||
12 | */ | ||
13 | |||
14 | /* | ||
15 | * computes the checksum of a memory block at buff, length len, | ||
16 | * and adds in "sum" (32-bit) | ||
17 | * | ||
18 | * returns a 32-bit number suitable for feeding into itself | ||
19 | * or csum_tcpudp_magic | ||
20 | * | ||
21 | * this function must be called with even lengths, except | ||
22 | * for the last fragment, which may be odd | ||
23 | * | ||
24 | * it's best to have buff aligned on a 32-bit boundary | ||
25 | */ | ||
26 | asmlinkage __wsum csum_partial(const void *buff, int len, __wsum sum); | ||
27 | |||
28 | /* | ||
29 | * Note: when you get a NULL pointer exception here this means someone | ||
30 | * passed in an incorrect kernel address to one of these functions. | ||
31 | * | ||
32 | * If you use these functions directly please don't forget the | ||
33 | * access_ok(). | ||
34 | */ | ||
35 | |||
36 | |||
37 | __wsum csum_partial_copy_nocheck(const void *src, void *dst, int len, | ||
38 | __wsum sum); | ||
39 | |||
40 | __wsum csum_partial_copy_from_user(const void __user *src, void *dst, | ||
41 | int len, __wsum sum, int *err_ptr); | ||
42 | |||
43 | static inline __sum16 csum_fold(__wsum csum) | ||
44 | { | ||
45 | u32 sum = (__force u32)csum; | ||
46 | sum = (sum & 0xffff) + (sum >> 16); | ||
47 | sum = (sum & 0xffff) + (sum >> 16); | ||
48 | return (__force __sum16)~sum; | ||
49 | } | ||
50 | |||
51 | __sum16 ip_fast_csum(const void *iph, unsigned int ihl); | ||
52 | |||
53 | __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, | ||
54 | unsigned short len, unsigned short proto, | ||
55 | __wsum sum); | ||
56 | |||
57 | /* | ||
58 | * computes the checksum of the TCP/UDP pseudo-header | ||
59 | * returns a 16-bit checksum, already complemented | ||
60 | */ | ||
61 | static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, | ||
62 | unsigned short len, | ||
63 | unsigned short proto, | ||
64 | __wsum sum) | ||
65 | { | ||
66 | return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); | ||
67 | } | ||
68 | |||
69 | /* | ||
70 | * this routine is used for miscellaneous IP-like checksums, mainly | ||
71 | * in icmp.c | ||
72 | */ | ||
73 | static inline __sum16 ip_compute_csum(const void *buff, int len) | ||
74 | { | ||
75 | return csum_fold(csum_partial(buff, len, 0)); | ||
76 | } | ||
77 | |||
78 | #endif /* __ASM_SH_CHECKSUM_64_H */ | ||
diff --git a/arch/sh/kernel/sh_ksyms_64.c b/arch/sh/kernel/sh_ksyms_64.c index 8f54ef0cfbca..f5bd156ea504 100644 --- a/arch/sh/kernel/sh_ksyms_64.c +++ b/arch/sh/kernel/sh_ksyms_64.c | |||
@@ -38,13 +38,6 @@ EXPORT_SYMBOL(clear_user_page); | |||
38 | EXPORT_SYMBOL(flush_dcache_page); | 38 | EXPORT_SYMBOL(flush_dcache_page); |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | /* Networking helper routines. */ | ||
42 | EXPORT_SYMBOL(csum_partial); | ||
43 | EXPORT_SYMBOL(csum_partial_copy_nocheck); | ||
44 | #ifdef CONFIG_IPV6 | ||
45 | EXPORT_SYMBOL(csum_ipv6_magic); | ||
46 | #endif | ||
47 | |||
48 | #ifdef CONFIG_VT | 41 | #ifdef CONFIG_VT |
49 | EXPORT_SYMBOL(screen_info); | 42 | EXPORT_SYMBOL(screen_info); |
50 | #endif | 43 | #endif |
diff --git a/arch/sh/lib64/Makefile b/arch/sh/lib64/Makefile index 4bacb9e83478..334bb2da36ea 100644 --- a/arch/sh/lib64/Makefile +++ b/arch/sh/lib64/Makefile | |||
@@ -10,7 +10,7 @@ | |||
10 | # | 10 | # |
11 | 11 | ||
12 | # Panic should really be compiled as PIC | 12 | # Panic should really be compiled as PIC |
13 | lib-y := udelay.o c-checksum.o dbg.o panic.o memcpy.o memset.o \ | 13 | lib-y := udelay.o dbg.o panic.o memcpy.o memset.o \ |
14 | copy_user_memcpy.o copy_page.o clear_page.o strcpy.o strlen.o | 14 | copy_user_memcpy.o copy_page.o clear_page.o strcpy.o strlen.o |
15 | 15 | ||
16 | # Extracted from libgcc | 16 | # Extracted from libgcc |
diff --git a/arch/sh/lib64/c-checksum.c b/arch/sh/lib64/c-checksum.c deleted file mode 100644 index 73c0877e3a29..000000000000 --- a/arch/sh/lib64/c-checksum.c +++ /dev/null | |||
@@ -1,214 +0,0 @@ | |||
1 | /* | ||
2 | * arch/sh/lib64/c-checksum.c | ||
3 | * | ||
4 | * This file contains network checksum routines that are better done | ||
5 | * in an architecture-specific manner due to speed.. | ||
6 | */ | ||
7 | #include <linux/string.h> | ||
8 | #include <linux/errno.h> | ||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <asm/byteorder.h> | ||
12 | #include <asm/uaccess.h> | ||
13 | |||
14 | static inline unsigned short from64to16(unsigned long long x) | ||
15 | { | ||
16 | /* add up 32-bit words for 33 bits */ | ||
17 | x = (x & 0xffffffff) + (x >> 32); | ||
18 | /* add up 16-bit and 17-bit words for 17+c bits */ | ||
19 | x = (x & 0xffff) + (x >> 16); | ||
20 | /* add up 16-bit and 2-bit for 16+c bit */ | ||
21 | x = (x & 0xffff) + (x >> 16); | ||
22 | /* add up carry.. */ | ||
23 | x = (x & 0xffff) + (x >> 16); | ||
24 | return x; | ||
25 | } | ||
26 | |||
27 | static inline unsigned short foldto16(unsigned long x) | ||
28 | { | ||
29 | /* add up 16-bit for 17 bits */ | ||
30 | x = (x & 0xffff) + (x >> 16); | ||
31 | /* add up carry.. */ | ||
32 | x = (x & 0xffff) + (x >> 16); | ||
33 | return x; | ||
34 | } | ||
35 | |||
36 | static inline unsigned short myfoldto16(unsigned long long x) | ||
37 | { | ||
38 | /* Fold down to 32-bits so we don't lose in the typedef-less | ||
39 | network stack. */ | ||
40 | /* 64 to 33 */ | ||
41 | x = (x & 0xffffffff) + (x >> 32); | ||
42 | /* 33 to 32 */ | ||
43 | x = (x & 0xffffffff) + (x >> 32); | ||
44 | |||
45 | /* add up 16-bit for 17 bits */ | ||
46 | x = (x & 0xffff) + (x >> 16); | ||
47 | /* add up carry.. */ | ||
48 | x = (x & 0xffff) + (x >> 16); | ||
49 | return x; | ||
50 | } | ||
51 | |||
52 | #define odd(x) ((x)&1) | ||
53 | #define U16(x) ntohs(x) | ||
54 | |||
55 | static unsigned long do_csum(const unsigned char *buff, int len) | ||
56 | { | ||
57 | int odd, count; | ||
58 | unsigned long result = 0; | ||
59 | |||
60 | pr_debug("do_csum buff %p, len %d (0x%x)\n", buff, len, len); | ||
61 | #ifdef DEBUG | ||
62 | for (i = 0; i < len; i++) { | ||
63 | if ((i % 26) == 0) | ||
64 | printk("\n"); | ||
65 | printk("%02X ", buff[i]); | ||
66 | } | ||
67 | #endif | ||
68 | |||
69 | if (len <= 0) | ||
70 | goto out; | ||
71 | |||
72 | odd = 1 & (unsigned long) buff; | ||
73 | if (odd) { | ||
74 | result = *buff << 8; | ||
75 | len--; | ||
76 | buff++; | ||
77 | } | ||
78 | count = len >> 1; /* nr of 16-bit words.. */ | ||
79 | if (count) { | ||
80 | if (2 & (unsigned long) buff) { | ||
81 | result += *(unsigned short *) buff; | ||
82 | count--; | ||
83 | len -= 2; | ||
84 | buff += 2; | ||
85 | } | ||
86 | count >>= 1; /* nr of 32-bit words.. */ | ||
87 | if (count) { | ||
88 | unsigned long carry = 0; | ||
89 | do { | ||
90 | unsigned long w = *(unsigned long *) buff; | ||
91 | buff += 4; | ||
92 | count--; | ||
93 | result += carry; | ||
94 | result += w; | ||
95 | carry = (w > result); | ||
96 | } while (count); | ||
97 | result += carry; | ||
98 | result = (result & 0xffff) + (result >> 16); | ||
99 | } | ||
100 | if (len & 2) { | ||
101 | result += *(unsigned short *) buff; | ||
102 | buff += 2; | ||
103 | } | ||
104 | } | ||
105 | if (len & 1) | ||
106 | result += *buff; | ||
107 | result = foldto16(result); | ||
108 | if (odd) | ||
109 | result = ((result >> 8) & 0xff) | ((result & 0xff) << 8); | ||
110 | |||
111 | pr_debug("\nCHECKSUM is 0x%lx\n", result); | ||
112 | |||
113 | out: | ||
114 | return result; | ||
115 | } | ||
116 | |||
117 | /* computes the checksum of a memory block at buff, length len, | ||
118 | and adds in "sum" (32-bit) */ | ||
119 | __wsum csum_partial(const void *buff, int len, __wsum sum) | ||
120 | { | ||
121 | unsigned long long result = do_csum(buff, len); | ||
122 | |||
123 | /* add in old sum, and carry.. */ | ||
124 | result += (__force u32)sum; | ||
125 | /* 32+c bits -> 32 bits */ | ||
126 | result = (result & 0xffffffff) + (result >> 32); | ||
127 | |||
128 | pr_debug("csum_partial, buff %p len %d sum 0x%x result=0x%016Lx\n", | ||
129 | buff, len, sum, result); | ||
130 | |||
131 | return (__force __wsum)result; | ||
132 | } | ||
133 | |||
134 | /* Copy while checksumming, otherwise like csum_partial. */ | ||
135 | __wsum | ||
136 | csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum) | ||
137 | { | ||
138 | sum = csum_partial(src, len, sum); | ||
139 | memcpy(dst, src, len); | ||
140 | |||
141 | return sum; | ||
142 | } | ||
143 | |||
144 | /* Copy from userspace and compute checksum. If we catch an exception | ||
145 | then zero the rest of the buffer. */ | ||
146 | __wsum | ||
147 | csum_partial_copy_from_user(const void __user *src, void *dst, int len, | ||
148 | __wsum sum, int *err_ptr) | ||
149 | { | ||
150 | int missing; | ||
151 | |||
152 | pr_debug | ||
153 | ("csum_partial_copy_from_user src %p, dest %p, len %d, sum %08x, err_ptr %p\n", | ||
154 | src, dst, len, sum, err_ptr); | ||
155 | missing = copy_from_user(dst, src, len); | ||
156 | pr_debug(" access_ok %d\n", __access_ok((unsigned long) src, len)); | ||
157 | pr_debug(" missing %d\n", missing); | ||
158 | if (missing) { | ||
159 | memset(dst + len - missing, 0, missing); | ||
160 | *err_ptr = -EFAULT; | ||
161 | } | ||
162 | |||
163 | return csum_partial(dst, len, sum); | ||
164 | } | ||
165 | |||
166 | /* Copy to userspace and compute checksum. */ | ||
167 | __wsum | ||
168 | csum_partial_copy_to_user(const unsigned char *src, unsigned char *dst, int len, | ||
169 | __wsum sum, int *err_ptr) | ||
170 | { | ||
171 | sum = csum_partial(src, len, sum); | ||
172 | |||
173 | if (copy_to_user(dst, src, len)) | ||
174 | *err_ptr = -EFAULT; | ||
175 | |||
176 | return sum; | ||
177 | } | ||
178 | |||
179 | /* | ||
180 | * This is a version of ip_compute_csum() optimized for IP headers, | ||
181 | * which always checksum on 4 octet boundaries. | ||
182 | */ | ||
183 | __sum16 ip_fast_csum(const void *iph, unsigned int ihl) | ||
184 | { | ||
185 | pr_debug("ip_fast_csum %p,%d\n", iph, ihl); | ||
186 | |||
187 | return (__force __sum16)~do_csum(iph, ihl * 4); | ||
188 | } | ||
189 | |||
190 | __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, | ||
191 | unsigned short len, | ||
192 | unsigned short proto, __wsum sum) | ||
193 | { | ||
194 | unsigned long long result; | ||
195 | |||
196 | pr_debug("ntohs(0x%x)=0x%x\n", 0xdead, ntohs(0xdead)); | ||
197 | pr_debug("htons(0x%x)=0x%x\n", 0xdead, htons(0xdead)); | ||
198 | |||
199 | result = (__force u64) saddr + (__force u64) daddr + | ||
200 | (__force u64) sum + ((len + proto) << 8); | ||
201 | |||
202 | /* Fold down to 32-bits so we don't lose in the typedef-less | ||
203 | network stack. */ | ||
204 | /* 64 to 33 */ | ||
205 | result = (result & 0xffffffff) + (result >> 32); | ||
206 | /* 33 to 32 */ | ||
207 | result = (result & 0xffffffff) + (result >> 32); | ||
208 | |||
209 | pr_debug("%s saddr %x daddr %x len %x proto %x sum %x result %08Lx\n", | ||
210 | __func__, saddr, daddr, len, proto, sum, result); | ||
211 | |||
212 | return (__wsum)result; | ||
213 | } | ||
214 | EXPORT_SYMBOL(csum_tcpudp_nofold); | ||