[NET]: XTENSA checksum annotations and cleanups.

* sanitize prototypes, annotate
* kill csum_partial_copy_fromuser
* kill csum_partial_copy
* kill useless shifts
* usual ntohs->shift

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Al Viro 2006-11-14 21:23:40 -08:00 committed by David S. Miller
parent d5c6393641
commit b8e4e01dd5

View file

@ -26,7 +26,7 @@
* *
* it's best to have buff aligned on a 32-bit boundary * it's best to have buff aligned on a 32-bit boundary
*/ */
asmlinkage unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum); asmlinkage __wsum csum_partial(const void *buff, int len, __wsum sum);
/* /*
* the same as csum_partial, but copies from src while it * the same as csum_partial, but copies from src while it
@ -36,7 +36,7 @@ asmlinkage unsigned int csum_partial(const unsigned char * buff, int len, unsign
* better 64-bit) boundary * better 64-bit) boundary
*/ */
asmlinkage unsigned int csum_partial_copy_generic( const char *src, char *dst, int len, int sum, asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst, int len, __wsum sum,
int *src_err_ptr, int *dst_err_ptr); int *src_err_ptr, int *dst_err_ptr);
/* /*
@ -46,34 +46,25 @@ asmlinkage unsigned int csum_partial_copy_generic( const char *src, char *dst, i
* If you use these functions directly please don't forget the access_ok(). * If you use these functions directly please don't forget the access_ok().
*/ */
static inline static inline
unsigned int csum_partial_copy_nocheck ( const char *src, char *dst, __wsum csum_partial_copy_nocheck(const void *src, void *dst,
int len, int sum) int len, __wsum sum)
{ {
return csum_partial_copy_generic ( src, dst, len, sum, NULL, NULL); return csum_partial_copy_generic(src, dst, len, sum, NULL, NULL);
} }
static inline static inline
unsigned int csum_partial_copy_from_user ( const char *src, char *dst, __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
int len, int sum, int *err_ptr) int len, __wsum sum, int *err_ptr)
{ {
return csum_partial_copy_generic ( src, dst, len, sum, err_ptr, NULL); return csum_partial_copy_generic((__force const void *)src, dst,
len, sum, err_ptr, NULL);
} }
/*
* These are the old (and unsafe) way of doing checksums, a warning message will be
* printed if they are used and an exeption occurs.
*
* these functions should go away after some time.
*/
#define csum_partial_copy_fromuser csum_partial_copy
unsigned int csum_partial_copy( const char *src, char *dst, int len, int sum);
/* /*
* Fold a partial checksum * Fold a partial checksum
*/ */
static __inline__ unsigned int csum_fold(unsigned int sum) static __inline__ __sum16 csum_fold(__wsum sum)
{ {
unsigned int __dummy; unsigned int __dummy;
__asm__("extui %1, %0, 16, 16\n\t" __asm__("extui %1, %0, 16, 16\n\t"
@ -87,14 +78,14 @@ static __inline__ unsigned int csum_fold(unsigned int sum)
"extui %0, %0, 0, 16\n\t" "extui %0, %0, 0, 16\n\t"
: "=r" (sum), "=&r" (__dummy) : "=r" (sum), "=&r" (__dummy)
: "0" (sum)); : "0" (sum));
return sum; return (__force __sum16)sum;
} }
/* /*
* This is a version of ip_compute_csum() optimized for IP headers, * This is a version of ip_compute_csum() optimized for IP headers,
* which always checksum on 4 octet boundaries. * which always checksum on 4 octet boundaries.
*/ */
static __inline__ unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl) static __inline__ __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
{ {
unsigned int sum, tmp, endaddr; unsigned int sum, tmp, endaddr;
@ -127,17 +118,16 @@ static __inline__ unsigned short ip_fast_csum(unsigned char * iph, unsigned int
return csum_fold(sum); return csum_fold(sum);
} }
static __inline__ unsigned long csum_tcpudp_nofold(unsigned long saddr, static __inline__ __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
unsigned long daddr,
unsigned short len, unsigned short len,
unsigned short proto, unsigned short proto,
unsigned int sum) __wsum sum)
{ {
#ifdef __XTENSA_EL__ #ifdef __XTENSA_EL__
unsigned long len_proto = (ntohs(len)<<16)+proto*256; unsigned long len_proto = (len + proto) << 8;
#elif defined(__XTENSA_EB__) #elif defined(__XTENSA_EB__)
unsigned long len_proto = (proto<<16)+len; unsigned long len_proto = len + proto;
#else #else
# error processor byte order undefined! # error processor byte order undefined!
#endif #endif
@ -162,11 +152,10 @@ static __inline__ unsigned long csum_tcpudp_nofold(unsigned long saddr,
* computes the checksum of the TCP/UDP pseudo-header * computes the checksum of the TCP/UDP pseudo-header
* returns a 16-bit checksum, already complemented * returns a 16-bit checksum, already complemented
*/ */
static __inline__ unsigned short int csum_tcpudp_magic(unsigned long saddr, static __inline__ __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
unsigned long daddr,
unsigned short len, unsigned short len,
unsigned short proto, unsigned short proto,
unsigned int sum) __wsum sum)
{ {
return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
} }
@ -176,17 +165,16 @@ static __inline__ unsigned short int csum_tcpudp_magic(unsigned long saddr,
* in icmp.c * in icmp.c
*/ */
static __inline__ unsigned short ip_compute_csum(unsigned char * buff, int len) static __inline__ __sum16 ip_compute_csum(const void *buff, int len)
{ {
return csum_fold (csum_partial(buff, len, 0)); return csum_fold (csum_partial(buff, len, 0));
} }
#define _HAVE_ARCH_IPV6_CSUM #define _HAVE_ARCH_IPV6_CSUM
static __inline__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr, static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
struct in6_addr *daddr, const struct in6_addr *daddr,
__u32 len, __u32 len, unsigned short proto,
unsigned short proto, __wsum sum)
unsigned int sum)
{ {
unsigned int __dummy; unsigned int __dummy;
__asm__("l32i %1, %2, 0\n\t" __asm__("l32i %1, %2, 0\n\t"
@ -248,8 +236,8 @@ static __inline__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr,
* Copy and checksum to user * Copy and checksum to user
*/ */
#define HAVE_CSUM_COPY_USER #define HAVE_CSUM_COPY_USER
static __inline__ unsigned int csum_and_copy_to_user (const char *src, char *dst, static __inline__ __wsum csum_and_copy_to_user(const void *src, void __user *dst,
int len, int sum, int *err_ptr) int len, __wsum sum, int *err_ptr)
{ {
if (access_ok(VERIFY_WRITE, dst, len)) if (access_ok(VERIFY_WRITE, dst, len))
return csum_partial_copy_generic(src, dst, len, sum, NULL, err_ptr); return csum_partial_copy_generic(src, dst, len, sum, NULL, err_ptr);
@ -257,6 +245,6 @@ static __inline__ unsigned int csum_and_copy_to_user (const char *src, char *dst
if (len) if (len)
*err_ptr = -EFAULT; *err_ptr = -EFAULT;
return -1; /* invalid checksum */ return (__force __wsum)-1; /* invalid checksum */
} }
#endif #endif