2 * Copyright (C) 2008 Michal Simek <monstr@monstr.eu>
3 * Copyright (C) 2006 Atmark Techno, Inc.
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
10 #ifndef _ASM_MICROBLAZE_CHECKSUM_H
11 #define _ASM_MICROBLAZE_CHECKSUM_H
13 #include <linux/in6.h>
16 * computes the checksum of the TCP/UDP pseudo-header
17 * returns a 16-bit checksum, already complemented
20 csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,
21 unsigned short proto, __wsum sum)
23 __asm__("add %0, %0, %1\n\t"
28 : "d" (saddr), "d" (daddr), "d" (len + proto));
34 * computes the checksum of a memory block at buff, length len,
35 * and adds in "sum" (32-bit)
37 * returns a 32-bit number suitable for feeding into itself
38 * or csum_tcpudp_magic
40 * this function must be called with even lengths, except
41 * for the last fragment, which may be odd
43 * it's best to have buff aligned on a 32-bit boundary
45 extern __wsum csum_partial(const void *buff, int len, __wsum sum);
48 * the same as csum_partial, but copies from src while it
51 * here even more important to align src and dst on a 32-bit (or even
52 * better 64-bit) boundary
54 extern __wsum csum_partial_copy(const void *src, void *dst, int len,
58 * the same as csum_partial_copy, but copies from user space.
60 * here even more important to align src and dst on a 32-bit (or even
61 * better 64-bit) boundary
63 extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
64 int len, __wsum sum, int *csum_err);
66 #define csum_partial_copy_nocheck(src, dst, len, sum) \
67 csum_partial_copy((src), (dst), (len), (sum))
70 * This is a version of ip_compute_csum() optimized for IP headers,
71 * which always checksum on 4 octet boundaries.
74 extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
77 * Fold a partial checksum
79 static inline __sum16 csum_fold(__wsum csum)
81 u32 sum = (__force u32)csum;
82 sum = (sum & 0xffff) + (sum >> 16);
83 sum = (sum & 0xffff) + (sum >> 16);
84 return (__force __sum16)~sum;
88 csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len,
89 unsigned short proto, __wsum sum)
91 return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
95 * this routine is used for miscellaneous IP-like checksums, mainly
98 extern __sum16 ip_compute_csum(const void *buff, int len);
100 #endif /* _ASM_MICROBLAZE_CHECKSUM_H */