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

[NET]: V850 checksum annotations and cleanups.

* sanitize prototypes, annotate
* collapse csum_partial_copy
* usual ntohs->shift
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent abf419b8
......@@ -24,7 +24,7 @@ EXPORT_SYMBOL (kernel_thread);
EXPORT_SYMBOL (__bug);
/* Networking helper routines. */
EXPORT_SYMBOL (csum_partial_copy);
EXPORT_SYMBOL (csum_partial_copy_nocheck);
EXPORT_SYMBOL (csum_partial_copy_from_user);
EXPORT_SYMBOL (ip_compute_csum);
EXPORT_SYMBOL (ip_fast_csum);
......
......@@ -88,32 +88,32 @@ static inline unsigned int do_csum(const unsigned char * buff, int len)
* This is a version of ip_compute_csum() optimized for IP headers,
* 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);
}
/*
* this routine is used for miscellaneous IP-like checksums, mainly
* 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);
}
/*
* computes a partial checksum, e.g. for TCP/UDP fragments
*/
unsigned int csum_partial(const unsigned char *buff, int len, unsigned int sum)
__wsum csum_partial(const void *buff, int len, __wsum sum)
{
unsigned int result = do_csum(buff, len);
/* add in old sum, and carry.. */
result += sum;
if(sum > result)
result += (__force u32)sum;
if ((__force u32)sum > result)
result += 1;
return result;
return (__force __wsum)result;
}
EXPORT_SYMBOL(csum_partial);
......@@ -121,8 +121,8 @@ EXPORT_SYMBOL(csum_partial);
/*
* copy while checksumming, otherwise like csum_partial
*/
unsigned int csum_partial_copy(const unsigned char *src, unsigned char *dst,
int len, unsigned int sum)
__wsum csum_partial_copy_nocheck(const void *src, void *dst,
int len, __wsum sum)
{
/*
* It's 2:30 am and I don't feel like doing it real ...
......@@ -138,9 +138,9 @@ unsigned int csum_partial_copy(const unsigned char *src, unsigned char *dst,
* Copy from userspace and compute checksum. If we catch an exception
* then zero the rest of the buffer.
*/
unsigned int csum_partial_copy_from_user (const unsigned char *src,
unsigned char *dst,
int len, unsigned int sum,
__wsum csum_partial_copy_from_user (const void *src,
void *dst,
int len, __wsum sum,
int *err_ptr)
{
int missing;
......
......@@ -26,8 +26,7 @@
*
* it's best to have buff aligned on a 32-bit boundary
*/
extern unsigned int csum_partial (const unsigned char * buff, int len,
unsigned int sum);
extern __wsum csum_partial(const void *buff, int len, __wsum sum);
/*
* the same as csum_partial, but copies from src while it
......@@ -36,8 +35,8 @@ extern unsigned int csum_partial (const unsigned char * buff, int len,
* here even more important to align src and dst on a 32-bit (or even
* better 64-bit) boundary
*/
extern unsigned csum_partial_copy (const unsigned char *src,
unsigned char *dst, int len, unsigned sum);
extern __wsum csum_partial_copy_nocheck(const void *src,
void *dst, int len, __wsum sum);
/*
......@@ -46,20 +45,17 @@ extern unsigned csum_partial_copy (const unsigned char *src,
* here even more important to align src and dst on a 32-bit (or even
* better 64-bit) boundary
*/
extern unsigned csum_partial_copy_from_user (const unsigned char *src,
unsigned char *dst,
int len, unsigned sum,
extern __wsum csum_partial_copy_from_user (const void *src,
void *dst,
int len, __wsum sum,
int *csum_err);
#define csum_partial_copy_nocheck(src, dst, len, sum) \
csum_partial_copy ((src), (dst), (len), (sum))
unsigned short ip_fast_csum (unsigned char *iph, unsigned int ihl);
__sum16 ip_fast_csum(const void *iph, unsigned int ihl);
/*
* Fold a partial checksum
*/
static inline unsigned int csum_fold (unsigned long sum)
static inline __sum16 csum_fold (__wsum sum)
{
unsigned int result;
/*
......@@ -68,7 +64,7 @@ static inline unsigned int csum_fold (unsigned long sum)
add %1, %0 H L H+L+C H+L
*/
asm ("hsw %1, %0; add %1, %0" : "=&r" (result) : "r" (sum));
return (~result) >> 16;
return (__force __sum16)(~result >> 16);
}
......@@ -76,10 +72,10 @@ static inline unsigned int csum_fold (unsigned long sum)
* computes the checksum of the TCP/UDP pseudo-header
* returns a 16-bit checksum, already complemented
*/
static inline unsigned int
csum_tcpudp_nofold (unsigned long saddr, unsigned long daddr,
static inline __wsum
csum_tcpudp_nofold (__be32 saddr, __be32 daddr,
unsigned short len,
unsigned short proto, unsigned int sum)
unsigned short proto, __wsum sum)
{
int __carry;
__asm__ ("add %2, %0;"
......@@ -93,15 +89,15 @@ csum_tcpudp_nofold (unsigned long saddr, unsigned long daddr,
"add %1, %0"
: "=&r" (sum), "=&r" (__carry)
: "r" (daddr), "r" (saddr),
"r" (ntohs (len) + (proto << 8)),
"r" ((len + proto) << 8),
"0" (sum));
return sum;
}
static inline unsigned short int
csum_tcpudp_magic (unsigned long saddr, unsigned long daddr,
static inline __sum16
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));
}
......@@ -110,7 +106,7 @@ csum_tcpudp_magic (unsigned long saddr, unsigned long daddr,
* this routine is used for miscellaneous IP-like checksums, mainly
* 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 /* __V850_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