diff options
| author | Kumar Gala <galak@freescale.com> | 2005-10-20 12:44:46 -0400 |
|---|---|---|
| committer | Paul Mackerras <paulus@samba.org> | 2005-10-26 01:54:31 -0400 |
| commit | d95bbcb3a344b3eb84b45d162c0a20348f0af37f (patch) | |
| tree | 036e03b868b09e3b064489ff7d8f2ccca26a9dda /include | |
| parent | 60dda2565bbf31bbe662fd143a41c861b7a190cf (diff) | |
[PATCH] powerpc: merge include/asm-ppc*/checksum.h into include/asm-powerpc/checksum.h
Signed-off-by: Kumar Gala <kumar.gala@freescale.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/asm-powerpc/checksum.h (renamed from include/asm-ppc64/checksum.h) | 47 | ||||
| -rw-r--r-- | include/asm-ppc/checksum.h | 107 |
2 files changed, 36 insertions, 118 deletions
diff --git a/include/asm-ppc64/checksum.h b/include/asm-powerpc/checksum.h index d22d4469de43..d8354d8a49ce 100644 --- a/include/asm-ppc64/checksum.h +++ b/include/asm-powerpc/checksum.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | #ifndef _PPC64_CHECKSUM_H | 1 | #ifndef _ASM_POWERPC_CHECKSUM_H |
| 2 | #define _PPC64_CHECKSUM_H | 2 | #define _ASM_POWERPC_CHECKSUM_H |
| 3 | 3 | ||
| 4 | /* | 4 | /* |
| 5 | * This program is free software; you can redistribute it and/or | 5 | * This program is free software; you can redistribute it and/or |
| @@ -41,8 +41,14 @@ extern unsigned int csum_partial(const unsigned char * buff, int len, | |||
| 41 | unsigned int sum); | 41 | unsigned int sum); |
| 42 | 42 | ||
| 43 | /* | 43 | /* |
| 44 | * the same as csum_partial, but copies from src to dst while it | 44 | * Computes the checksum of a memory block at src, length len, |
| 45 | * checksums | 45 | * and adds in "sum" (32-bit), while copying the block to dst. |
| 46 | * If an access exception occurs on src or dst, it stores -EFAULT | ||
| 47 | * to *src_err or *dst_err respectively (if that pointer is not | ||
| 48 | * NULL), and, for an error on src, zeroes the rest of dst. | ||
| 49 | * | ||
| 50 | * Like csum_partial, this must be called with even lengths, | ||
| 51 | * except for the last fragment. | ||
| 46 | */ | 52 | */ |
| 47 | extern unsigned int csum_partial_copy_generic(const char *src, char *dst, | 53 | extern unsigned int csum_partial_copy_generic(const char *src, char *dst, |
| 48 | int len, unsigned int sum, | 54 | int len, unsigned int sum, |
| @@ -51,12 +57,18 @@ extern unsigned int csum_partial_copy_generic(const char *src, char *dst, | |||
| 51 | * the same as csum_partial, but copies from src to dst while it | 57 | * the same as csum_partial, but copies from src to dst while it |
| 52 | * checksums. | 58 | * checksums. |
| 53 | */ | 59 | */ |
| 54 | |||
| 55 | unsigned int csum_partial_copy_nocheck(const char *src, | 60 | unsigned int csum_partial_copy_nocheck(const char *src, |
| 56 | char *dst, | 61 | char *dst, |
| 57 | int len, | 62 | int len, |
| 58 | unsigned int sum); | 63 | unsigned int sum); |
| 59 | 64 | ||
| 65 | #define csum_partial_copy_from_user(src, dst, len, sum, errp) \ | ||
| 66 | csum_partial_copy_generic((src), (dst), (len), (sum), (errp), NULL) | ||
| 67 | |||
| 68 | #define csum_partial_copy_nocheck(src, dst, len, sum) \ | ||
| 69 | csum_partial_copy_generic((src), (dst), (len), (sum), NULL, NULL) | ||
| 70 | |||
| 71 | |||
| 60 | /* | 72 | /* |
| 61 | * turns a 32-bit partial checksum (e.g. from csum_partial) into a | 73 | * turns a 32-bit partial checksum (e.g. from csum_partial) into a |
| 62 | * 1's complement 16-bit checksum. | 74 | * 1's complement 16-bit checksum. |
| @@ -83,12 +95,7 @@ static inline unsigned short ip_compute_csum(unsigned char * buff, int len) | |||
| 83 | return csum_fold(csum_partial(buff, len, 0)); | 95 | return csum_fold(csum_partial(buff, len, 0)); |
| 84 | } | 96 | } |
| 85 | 97 | ||
| 86 | #define csum_partial_copy_from_user(src, dst, len, sum, errp) \ | 98 | #ifdef __powerpc64__ |
| 87 | csum_partial_copy_generic((src), (dst), (len), (sum), (errp), NULL) | ||
| 88 | |||
| 89 | #define csum_partial_copy_nocheck(src, dst, len, sum) \ | ||
| 90 | csum_partial_copy_generic((src), (dst), (len), (sum), NULL, NULL) | ||
| 91 | |||
| 92 | static inline u32 csum_tcpudp_nofold(u32 saddr, | 99 | static inline u32 csum_tcpudp_nofold(u32 saddr, |
| 93 | u32 daddr, | 100 | u32 daddr, |
| 94 | unsigned short len, | 101 | unsigned short len, |
| @@ -103,5 +110,23 @@ static inline u32 csum_tcpudp_nofold(u32 saddr, | |||
| 103 | s += (s >> 32); | 110 | s += (s >> 32); |
| 104 | return (u32) s; | 111 | return (u32) s; |
| 105 | } | 112 | } |
| 113 | #else | ||
| 114 | static inline unsigned long csum_tcpudp_nofold(unsigned long saddr, | ||
| 115 | unsigned long daddr, | ||
| 116 | unsigned short len, | ||
| 117 | unsigned short proto, | ||
| 118 | unsigned int sum) | ||
| 119 | { | ||
| 120 | __asm__("\n\ | ||
| 121 | addc %0,%0,%1 \n\ | ||
| 122 | adde %0,%0,%2 \n\ | ||
| 123 | adde %0,%0,%3 \n\ | ||
| 124 | addze %0,%0 \n\ | ||
| 125 | " | ||
| 126 | : "=r" (sum) | ||
| 127 | : "r" (daddr), "r"(saddr), "r"((proto<<16)+len), "0"(sum)); | ||
| 128 | return sum; | ||
| 129 | } | ||
| 106 | 130 | ||
| 107 | #endif | 131 | #endif |
| 132 | #endif | ||
diff --git a/include/asm-ppc/checksum.h b/include/asm-ppc/checksum.h deleted file mode 100644 index cf953a92c7ab..000000000000 --- a/include/asm-ppc/checksum.h +++ /dev/null | |||
| @@ -1,107 +0,0 @@ | |||
| 1 | #ifdef __KERNEL__ | ||
| 2 | #ifndef _PPC_CHECKSUM_H | ||
| 3 | #define _PPC_CHECKSUM_H | ||
| 4 | |||
| 5 | |||
| 6 | /* | ||
| 7 | * computes the checksum of a memory block at buff, length len, | ||
| 8 | * and adds in "sum" (32-bit) | ||
| 9 | * | ||
| 10 | * returns a 32-bit number suitable for feeding into itself | ||
| 11 | * or csum_tcpudp_magic | ||
| 12 | * | ||
| 13 | * this function must be called with even lengths, except | ||
| 14 | * for the last fragment, which may be odd | ||
| 15 | * | ||
| 16 | * it's best to have buff aligned on a 32-bit boundary | ||
| 17 | */ | ||
| 18 | extern unsigned int csum_partial(const unsigned char * buff, int len, | ||
| 19 | unsigned int sum); | ||
| 20 | |||
| 21 | /* | ||
| 22 | * Computes the checksum of a memory block at src, length len, | ||
| 23 | * and adds in "sum" (32-bit), while copying the block to dst. | ||
| 24 | * If an access exception occurs on src or dst, it stores -EFAULT | ||
| 25 | * to *src_err or *dst_err respectively (if that pointer is not | ||
| 26 | * NULL), and, for an error on src, zeroes the rest of dst. | ||
| 27 | * | ||
| 28 | * Like csum_partial, this must be called with even lengths, | ||
| 29 | * except for the last fragment. | ||
| 30 | */ | ||
| 31 | extern unsigned int csum_partial_copy_generic(const char *src, char *dst, | ||
| 32 | int len, unsigned int sum, | ||
| 33 | int *src_err, int *dst_err); | ||
| 34 | |||
| 35 | #define csum_partial_copy_from_user(src, dst, len, sum, errp) \ | ||
| 36 | csum_partial_copy_generic((__force void *)(src), (dst), (len), (sum), (errp), NULL) | ||
| 37 | |||
| 38 | /* FIXME: this needs to be written to really do no check -- Cort */ | ||
| 39 | #define csum_partial_copy_nocheck(src, dst, len, sum) \ | ||
| 40 | csum_partial_copy_generic((src), (dst), (len), (sum), NULL, NULL) | ||
| 41 | |||
| 42 | /* | ||
| 43 | * turns a 32-bit partial checksum (e.g. from csum_partial) into a | ||
| 44 | * 1's complement 16-bit checksum. | ||
| 45 | */ | ||
| 46 | static inline unsigned int csum_fold(unsigned int sum) | ||
| 47 | { | ||
| 48 | unsigned int tmp; | ||
| 49 | |||
| 50 | /* swap the two 16-bit halves of sum */ | ||
| 51 | __asm__("rlwinm %0,%1,16,0,31" : "=r" (tmp) : "r" (sum)); | ||
| 52 | /* if there is a carry from adding the two 16-bit halves, | ||
| 53 | it will carry from the lower half into the upper half, | ||
| 54 | giving us the correct sum in the upper half. */ | ||
| 55 | sum = ~(sum + tmp) >> 16; | ||
| 56 | return sum; | ||
| 57 | } | ||
| 58 | |||
| 59 | /* | ||
| 60 | * this routine is used for miscellaneous IP-like checksums, mainly | ||
| 61 | * in icmp.c | ||
| 62 | */ | ||
| 63 | static inline unsigned short ip_compute_csum(unsigned char * buff, int len) | ||
| 64 | { | ||
| 65 | return csum_fold(csum_partial(buff, len, 0)); | ||
| 66 | } | ||
| 67 | |||
| 68 | /* | ||
| 69 | * FIXME: I swiped this one from the sparc and made minor modifications. | ||
| 70 | * It may not be correct. -- Cort | ||
| 71 | */ | ||
| 72 | static inline unsigned long csum_tcpudp_nofold(unsigned long saddr, | ||
| 73 | unsigned long daddr, | ||
| 74 | unsigned short len, | ||
| 75 | unsigned short proto, | ||
| 76 | unsigned int sum) | ||
| 77 | { | ||
| 78 | __asm__("\n\ | ||
| 79 | addc %0,%0,%1 \n\ | ||
| 80 | adde %0,%0,%2 \n\ | ||
| 81 | adde %0,%0,%3 \n\ | ||
| 82 | addze %0,%0 \n\ | ||
| 83 | " | ||
| 84 | : "=r" (sum) | ||
| 85 | : "r" (daddr), "r"(saddr), "r"((proto<<16)+len), "0"(sum)); | ||
| 86 | return sum; | ||
| 87 | } | ||
| 88 | |||
| 89 | /* | ||
| 90 | * This is a version of ip_compute_csum() optimized for IP headers, | ||
| 91 | * which always checksum on 4 octet boundaries. ihl is the number | ||
| 92 | * of 32-bit words and is always >= 5. | ||
| 93 | */ | ||
| 94 | extern unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl); | ||
| 95 | |||
