Commit db521083 authored by Al Viro's avatar Al Viro Committed by David S. Miller

[NET]: H8300 checksum annotations and cleanups.

* sanitize prototypes and annotate
* collapse csum_partial_copy

NB: csum_partial() is almost certainly still buggy.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8042c44b
...@@ -39,7 +39,7 @@ EXPORT_SYMBOL(enable_irq); ...@@ -39,7 +39,7 @@ EXPORT_SYMBOL(enable_irq);
EXPORT_SYMBOL(disable_irq); EXPORT_SYMBOL(disable_irq);
/* Networking helper routines. */ /* Networking helper routines. */
EXPORT_SYMBOL(csum_partial_copy); EXPORT_SYMBOL(csum_partial_copy_nocheck);
/* The following are special because they're not called /* The following are special because they're not called
explicitly (the C compiler generates them). Fortunately, explicitly (the C compiler generates them). Fortunately,
......
...@@ -96,9 +96,9 @@ out: ...@@ -96,9 +96,9 @@ out:
* 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.
*/ */
unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl) __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
{ {
return ~do_csum(iph,ihl*4); return (__force __sum16)~do_csum(iph,ihl*4);
} }
/* /*
...@@ -113,15 +113,19 @@ unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl) ...@@ -113,15 +113,19 @@ unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl)
* *
* it's best to have buff aligned on a 32-bit boundary * it's best to have buff aligned on a 32-bit boundary
*/ */
unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum) /*
* Egads... That thing apparently assumes that *all* checksums it ever sees will
* be folded. Very likely a bug.
*/
__wsum csum_partial(const void *buff, int len, __wsum sum)
{ {
unsigned int result = do_csum(buff, len); unsigned int result = do_csum(buff, len);
/* add in old sum, and carry.. */ /* add in old sum, and carry.. */
result += sum; result += (__force u32)sum;
/* 16+c bits -> 16 bits */ /* 16+c bits -> 16 bits */
result = (result & 0xffff) + (result >> 16); result = (result & 0xffff) + (result >> 16);
return result; return (__force __wsum)result;
} }
EXPORT_SYMBOL(csum_partial); EXPORT_SYMBOL(csum_partial);
...@@ -130,20 +134,21 @@ EXPORT_SYMBOL(csum_partial); ...@@ -130,20 +134,21 @@ EXPORT_SYMBOL(csum_partial);
* this routine is used for miscellaneous IP-like checksums, mainly * this routine is used for miscellaneous IP-like checksums, mainly
* in icmp.c * in icmp.c
*/ */
unsigned short ip_compute_csum(const unsigned char * buff, int len) __sum16 ip_compute_csum(const void *buff, int len)
{ {
return ~do_csum(buff,len); return (__force __sum16)~do_csum(buff,len);
} }
/* /*
* copy from fs while checksumming, otherwise like csum_partial * copy from fs while checksumming, otherwise like csum_partial
*/ */
unsigned int __wsum
csum_partial_copy_from_user(const char *src, char *dst, int len, int sum, int *csum_err) csum_partial_copy_from_user(const void __user *src, void *dst, int len,
__wsum sum, int *csum_err)
{ {
if (csum_err) *csum_err = 0; if (csum_err) *csum_err = 0;
memcpy(dst, src, len); memcpy(dst, (__force const void *)src, len);
return csum_partial(dst, len, sum); return csum_partial(dst, len, sum);
} }
...@@ -151,8 +156,8 @@ csum_partial_copy_from_user(const char *src, char *dst, int len, int sum, int *c ...@@ -151,8 +156,8 @@ csum_partial_copy_from_user(const char *src, char *dst, int len, int sum, int *c
* copy from ds while checksumming, otherwise like csum_partial * copy from ds while checksumming, otherwise like csum_partial
*/ */
unsigned int __wsum
csum_partial_copy(const char *src, char *dst, int len, int sum) csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum)
{ {
memcpy(dst, src, len); memcpy(dst, src, len);
return csum_partial(dst, len, sum); return csum_partial(dst, len, sum);
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,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
*/ */
unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum); __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
...@@ -23,7 +23,7 @@ unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum) ...@@ -23,7 +23,7 @@ unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum)
* better 64-bit) boundary * better 64-bit) boundary
*/ */
unsigned int csum_partial_copy(const char *src, char *dst, int len, int sum); __wsum csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
/* /*
...@@ -33,20 +33,17 @@ unsigned int csum_partial_copy(const char *src, char *dst, int len, int sum); ...@@ -33,20 +33,17 @@ unsigned int csum_partial_copy(const char *src, char *dst, int len, int sum);
* better 64-bit) boundary * better 64-bit) boundary
*/ */
extern unsigned int csum_partial_copy_from_user(const char *src, char *dst, extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
int len, int sum, int *csum_err); int len, __wsum sum, int *csum_err);
#define csum_partial_copy_nocheck(src, dst, len, sum) \ __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
csum_partial_copy((src), (dst), (len), (sum))
unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl);
/* /*
* Fold a partial checksum * Fold a partial checksum
*/ */
static inline unsigned int csum_fold(unsigned int sum) static inline __sum16 csum_fold(__wsum sum)
{ {
__asm__("mov.l %0,er0\n\t" __asm__("mov.l %0,er0\n\t"
"add.w e0,r0\n\t" "add.w e0,r0\n\t"
...@@ -58,7 +55,7 @@ static inline unsigned int csum_fold(unsigned int sum) ...@@ -58,7 +55,7 @@ static inline unsigned int csum_fold(unsigned int sum)
: "=r"(sum) : "=r"(sum)
: "0"(sum) : "0"(sum)
: "er0"); : "er0");
return ~sum; return (__force __sum16)~sum;
} }
...@@ -67,9 +64,9 @@ static inline unsigned int csum_fold(unsigned int sum) ...@@ -67,9 +64,9 @@ static inline unsigned int csum_fold(unsigned int sum)
* returns a 16-bit checksum, already complemented * returns a 16-bit checksum, already complemented
*/ */
static inline unsigned int static inline __wsum
csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr, unsigned short len, csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,
unsigned short proto, unsigned int sum) unsigned short proto, __wsum sum)
{ {
__asm__ ("sub.l er0,er0\n\t" __asm__ ("sub.l er0,er0\n\t"
"add.l %2,%0\n\t" "add.l %2,%0\n\t"
...@@ -88,9 +85,9 @@ csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr, unsigned short len, ...@@ -88,9 +85,9 @@ csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr, unsigned short len,
return sum; return sum;
} }
static inline unsigned short int static inline __sum16
csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len, csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len,
unsigned short proto, unsigned int sum) unsigned short proto, __wsum sum)
{ {
return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
} }
...@@ -100,6 +97,6 @@ csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len, ...@@ -100,6 +97,6 @@ csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len,
* in icmp.c * in icmp.c
*/ */
extern unsigned short ip_compute_csum(const unsigned char * buff, int len); extern __sum16 ip_compute_csum(const void *buff, int len);
#endif /* _H8300_CHECKSUM_H */ #endif /* _H8300_CHECKSUM_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment