2 * linux/include/asm-arm/checksum.h
6 * Copyright (C) Original authors of ../asm-i386/checksum.h
7 * Copyright (C) 1996-1999 Russell King
9 #ifndef __ASM_ARM_CHECKSUM_H
10 #define __ASM_ARM_CHECKSUM_H
12 #include <linux/in6.h>
15 * computes the checksum of a memory block at buff, length len,
16 * and adds in "sum" (32-bit)
18 * returns a 32-bit number suitable for feeding into itself
19 * or csum_tcpudp_magic
21 * this function must be called with even lengths, except
22 * for the last fragment, which may be odd
24 * it's best to have buff aligned on a 32-bit boundary
26 __wsum csum_partial(const void *buff, int len, __wsum sum);
29 * the same as csum_partial, but copies from src while it
30 * checksums, and handles user-space pointer exceptions correctly, when needed.
32 * here even more important to align src and dst on a 32-bit (or even
33 * better 64-bit) boundary
37 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
40 csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
43 * This is a version of ip_compute_csum() optimized for IP headers,
44 * which always checksum on 4 octet boundaries.
47 ip_fast_csum(const void *iph, unsigned int ihl)
49 unsigned int sum, tmp1;
52 "ldr %0, [%1], #4 @ ip_fast_csum \n\
59 1: adcs %0, %0, %3 \n\
61 tst %2, #15 @ do this carefully \n\
62 subne %2, %2, #1 @ without destroying \n\
63 bne 1b @ the carry flag \n\
66 adds %0, %0, %0, lsl #16 \n\
67 addcs %0, %0, #0x10000 \n\
70 : "=r" (sum), "=r" (iph), "=r" (ihl), "=r" (tmp1)
71 : "1" (iph), "2" (ihl)
73 return (__force __sum16)sum;
77 * Fold a partial checksum without adding pseudo headers
79 static inline __sum16 csum_fold(__wsum sum)
82 "adds %0, %1, %1, lsl #16 @ csum_fold \n\
83 addcs %0, %0, #0x10000"
87 return (__force __sum16)(~(__force u32)sum >> 16);
91 csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,
92 unsigned short proto, __wsum sum)
95 "adds %0, %1, %2 @ csum_tcpudp_nofold \n\
101 : "r" (sum), "r" (daddr), "r" (saddr), "r" (htons(len)), "Ir" (htons(proto))
106 * computes the checksum of the TCP/UDP pseudo-header
107 * returns a 16-bit checksum, already complemented
109 static inline __sum16
110 csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len,
111 unsigned short proto, __wsum sum)
114 "adds %0, %1, %2 @ csum_tcpudp_magic \n\
119 adds %0, %0, %0, lsl #16 \n\
120 addcs %0, %0, #0x10000 \n\
123 : "r" (sum), "r" (daddr), "r" (saddr), "r" (htons(len)), "Ir" (htons(proto))
125 return (__force __sum16)((__force u32)sum >> 16);
130 * this routine is used for miscellaneous IP-like checksums, mainly
133 static inline __sum16
134 ip_compute_csum(const void *buff, int len)
136 return csum_fold(csum_partial(buff, len, 0));
139 #define _HAVE_ARCH_IPV6_CSUM
141 __csum_ipv6_magic(const struct in6_addr *saddr, const struct in6_addr *daddr, __be32 len,
142 __be32 proto, __wsum sum);
144 static inline __sum16
145 csum_ipv6_magic(const struct in6_addr *saddr, const struct in6_addr *daddr, __u32 len,
146 unsigned short proto, __wsum sum)
148 return csum_fold(__csum_ipv6_magic(saddr, daddr, htonl(len),