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
13 * computes the checksum of a memory block at buff, length len,
14 * and adds in "sum" (32-bit)
16 * returns a 32-bit number suitable for feeding into itself
17 * or csum_tcpudp_magic
19 * this function must be called with even lengths, except
20 * for the last fragment, which may be odd
22 * it's best to have buff aligned on a 32-bit boundary
24 unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum);
27 * the same as csum_partial, but copies from src while it
28 * checksums, and handles user-space pointer exceptions correctly, when needed.
30 * here even more important to align src and dst on a 32-bit (or even
31 * better 64-bit) boundary
35 csum_partial_copy_nocheck(const char *src, char *dst, int len, int sum);
38 csum_partial_copy_from_user(const char *src, char *dst, int len, int sum, int *err_ptr);
41 * This is the old (and unsafe) way of doing checksums, a warning message will
42 * be printed if it is used and an exception occurs.
44 * this functions should go away after some time.
46 #define csum_partial_copy(src,dst,len,sum) csum_partial_copy_nocheck(src,dst,len,sum)
49 * This is a version of ip_compute_csum() optimized for IP headers,
50 * which always checksum on 4 octet boundaries.
52 static inline unsigned short
53 ip_fast_csum(unsigned char * iph, unsigned int ihl)
55 unsigned int sum, tmp1;
58 "ldr %0, [%1], #4 @ ip_fast_csum \n\
65 1: adcs %0, %0, %3 \n\
67 tst %2, #15 @ do this carefully \n\
68 subne %2, %2, #1 @ without destroying \n\
69 bne 1b @ the carry flag \n\
72 adds %0, %0, %0, lsl #16 \n\
73 addcs %0, %0, #0x10000 \n\
76 : "=r" (sum), "=r" (iph), "=r" (ihl), "=r" (tmp1)
77 : "1" (iph), "2" (ihl)
83 * Fold a partial checksum without adding pseudo headers
85 static inline unsigned int
86 csum_fold(unsigned int sum)
89 "adds %0, %1, %1, lsl #16 @ csum_fold \n\
90 addcs %0, %0, #0x10000"
97 static inline unsigned int
98 csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr, unsigned short len,
99 unsigned int proto, unsigned int sum)
102 "adds %0, %1, %2 @ csum_tcpudp_nofold \n\
108 : "r" (sum), "r" (daddr), "r" (saddr), "r" (ntohs(len)), "Ir" (ntohs(proto))
113 * computes the checksum of the TCP/UDP pseudo-header
114 * returns a 16-bit checksum, already complemented
116 static inline unsigned short int
117 csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len,
118 unsigned int proto, unsigned int sum)
121 "adds %0, %1, %2 @ csum_tcpudp_magic \n\
126 adds %0, %0, %0, lsl #16 \n\
127 addcs %0, %0, #0x10000 \n\
130 : "r" (sum), "r" (daddr), "r" (saddr), "r" (ntohs(len)), "Ir" (ntohs(proto))
137 * this routine is used for miscellaneous IP-like checksums, mainly
140 static inline unsigned short
141 ip_compute_csum(unsigned char * buff, int len)
143 return csum_fold(csum_partial(buff, len, 0));
146 #define _HAVE_ARCH_IPV6_CSUM
148 __csum_ipv6_magic(struct in6_addr *saddr, struct in6_addr *daddr, __u32 len,
149 __u32 proto, unsigned int sum);
151 static inline unsigned short int
152 csum_ipv6_magic(struct in6_addr *saddr, struct in6_addr *daddr, __u32 len,
153 unsigned short proto, unsigned int sum)
155 return csum_fold(__csum_ipv6_magic(saddr, daddr, htonl(len),