]> Pileus Git - ~andy/linux/blob - arch/microblaze/include/asm/checksum.h
Merge branch 'x86-fpu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[~andy/linux] / arch / microblaze / include / asm / checksum.h
1 /*
2  * Copyright (C) 2008 Michal Simek <monstr@monstr.eu>
3  * Copyright (C) 2006 Atmark Techno, Inc.
4  *
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
7  * for more details.
8  */
9
10 #ifndef _ASM_MICROBLAZE_CHECKSUM_H
11 #define _ASM_MICROBLAZE_CHECKSUM_H
12
13 #include <linux/in6.h>
14
15 /*
16  * computes the checksum of the TCP/UDP pseudo-header
17  * returns a 16-bit checksum, already complemented
18  */
19 static inline __wsum
20 csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,
21                    unsigned short proto, __wsum sum)
22 {
23         __asm__("add %0, %0, %1\n\t"
24                 "addc %0, %0, %2\n\t"
25                 "addc %0, %0, %3\n\t"
26                 "addc %0, %0, r0\n\t"
27                 : "+&d" (sum)
28                 : "d" (saddr), "d" (daddr), "d" (len + proto));
29
30         return sum;
31 }
32
33 /*
34  * computes the checksum of a memory block at buff, length len,
35  * and adds in "sum" (32-bit)
36  *
37  * returns a 32-bit number suitable for feeding into itself
38  * or csum_tcpudp_magic
39  *
40  * this function must be called with even lengths, except
41  * for the last fragment, which may be odd
42  *
43  * it's best to have buff aligned on a 32-bit boundary
44  */
45 extern __wsum csum_partial(const void *buff, int len, __wsum sum);
46
47 /*
48  * the same as csum_partial, but copies from src while it
49  * checksums
50  *
51  * here even more important to align src and dst on a 32-bit (or even
52  * better 64-bit) boundary
53  */
54 extern __wsum csum_partial_copy(const char *src, char *dst, int len, int sum);
55
56 /*
57  * the same as csum_partial_copy, but copies from user space.
58  *
59  * here even more important to align src and dst on a 32-bit (or even
60  * better 64-bit) boundary
61  */
62 extern __wsum csum_partial_copy_from_user(const char *src, char *dst,
63                                         int len, int sum, int *csum_err);
64
65 #define csum_partial_copy_nocheck(src, dst, len, sum)   \
66         csum_partial_copy((src), (dst), (len), (sum))
67
68 /*
69  *      This is a version of ip_compute_csum() optimized for IP headers,
70  *      which always checksum on 4 octet boundaries.
71  *
72  */
73 extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
74
75 /*
76  *      Fold a partial checksum
77  */
78 static inline __sum16 csum_fold(unsigned int sum)
79 {
80         sum = (sum & 0xffff) + (sum >> 16);
81         sum = (sum & 0xffff) + (sum >> 16);
82         return ~sum;
83 }
84
85 static inline __sum16
86 csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len,
87                   unsigned short proto, __wsum sum)
88 {
89         return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
90 }
91
92 /*
93  * this routine is used for miscellaneous IP-like checksums, mainly
94  * in icmp.c
95  */
96 extern __sum16 ip_compute_csum(const unsigned char *buff, int len);
97
98 #endif /* _ASM_MICROBLAZE_CHECKSUM_H */