2 * Copyright (C) 2004-2006 Atmel Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 #ifndef __ASM_AVR32_CHECKSUM_H
9 #define __ASM_AVR32_CHECKSUM_H
12 * computes the checksum of a memory block at buff, length len,
13 * and adds in "sum" (32-bit)
15 * returns a 32-bit number suitable for feeding into itself
16 * or csum_tcpudp_magic
18 * this function must be called with even lengths, except
19 * for the last fragment, which may be odd
21 * it's best to have buff aligned on a 32-bit boundary
23 __wsum
csum_partial(const void *buff
, int len
, __wsum sum
);
26 * the same as csum_partial, but copies from src while it
27 * checksums, and handles user-space pointer exceptions correctly, when needed.
29 * here even more important to align src and dst on a 32-bit (or even
30 * better 64-bit) boundary
32 __wsum
csum_partial_copy_generic(const void *src
, void *dst
, int len
,
33 __wsum sum
, int *src_err_ptr
,
37 * Note: when you get a NULL pointer exception here this means someone
38 * passed in an incorrect kernel address to one of these functions.
40 * If you use these functions directly please don't forget the
44 __wsum
csum_partial_copy_nocheck(const void *src
, void *dst
,
47 return csum_partial_copy_generic(src
, dst
, len
, sum
, NULL
, NULL
);
51 __wsum
csum_partial_copy_from_user(const void __user
*src
, void *dst
,
52 int len
, __wsum sum
, int *err_ptr
)
54 return csum_partial_copy_generic((const void __force
*)src
, dst
, len
,
59 * This is a version of ip_compute_csum() optimized for IP headers,
60 * which always checksum on 4 octet boundaries.
62 static inline __sum16
ip_fast_csum(const void *iph
, unsigned int ihl
)
64 unsigned int sum
, tmp
;
88 : "=r"(sum
), "=r"(iph
), "=r"(ihl
), "=r"(tmp
)
91 return (__force __sum16
)sum
;
95 * Fold a partial checksum
98 static inline __sum16
csum_fold(__wsum sum
)
102 asm(" bfextu %1, %0, 0, 16\n"
105 " bfextu %1, %0, 16, 16\n"
107 : "=&r"(sum
), "=&r"(tmp
)
110 return (__force __sum16
)~sum
;
113 static inline __wsum
csum_tcpudp_nofold(__be32 saddr
, __be32 daddr
,
115 unsigned short proto
,
123 : "r"(daddr
), "r"(saddr
), "r"(len
+ proto
),
131 * computes the checksum of the TCP/UDP pseudo-header
132 * returns a 16-bit checksum, already complemented
134 static inline __sum16
csum_tcpudp_magic(__be32 saddr
, __be32 daddr
,
136 unsigned short proto
,
139 return csum_fold(csum_tcpudp_nofold(saddr
,daddr
,len
,proto
,sum
));
143 * this routine is used for miscellaneous IP-like checksums, mainly
147 static inline __sum16
ip_compute_csum(const void *buff
, int len
)
149 return csum_fold(csum_partial(buff
, len
, 0));
152 #endif /* __ASM_AVR32_CHECKSUM_H */