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 * These are the old (and unsafe) way of doing checksums, a warning message will be
42 * printed if they are used and an exception occurs.
44 * these 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
72 adds %0, %0, %0, lsl #16
73 addcs %0, %0, #0x10000
77 : "=r" (sum
), "=r" (iph
), "=r" (ihl
), "=r" (tmp1
)
78 : "1" (iph
), "2" (ihl
)
84 * Fold a partial checksum without adding pseudo headers
86 static inline unsigned int
87 csum_fold(unsigned int sum
)
90 "adds %0, %1, %1, lsl #16 @ csum_fold
91 addcs %0, %0, #0x10000"
98 static inline unsigned int
99 csum_tcpudp_nofold(unsigned long saddr
, unsigned long daddr
, unsigned short len
,
100 unsigned int proto
, unsigned int sum
)
103 "adds %0, %1, %2 @ csum_tcpudp_nofold
109 : "r" (sum
), "r" (daddr
), "r" (saddr
), "r" (ntohs(len
) << 16), "Ir" (proto
<< 8)
114 * computes the checksum of the TCP/UDP pseudo-header
115 * returns a 16-bit checksum, already complemented
117 static inline unsigned short int
118 csum_tcpudp_magic(unsigned long saddr
, unsigned long daddr
, unsigned short len
,
119 unsigned int proto
, unsigned int sum
)
122 "adds %0, %1, %2 @ csum_tcpudp_magic
127 adds %0, %0, %0, lsl #16
128 addcs %0, %0, #0x10000
131 : "r" (sum
), "r" (daddr
), "r" (saddr
), "r" (ntohs(len
)), "Ir" (proto
<< 8)
138 * this routine is used for miscellaneous IP-like checksums, mainly
141 static inline unsigned short
142 ip_compute_csum(unsigned char * buff
, int len
)
144 return csum_fold(csum_partial(buff
, len
, 0));
147 #define _HAVE_ARCH_IPV6_CSUM
149 __csum_ipv6_magic(struct in6_addr
*saddr
, struct in6_addr
*daddr
, __u32 len
,
150 __u32 proto
, unsigned int sum
);
152 extern __inline__
unsigned short int
153 csum_ipv6_magic(struct in6_addr
*saddr
, struct in6_addr
*daddr
, __u32 len
,
154 unsigned short proto
, unsigned int sum
)
156 return csum_fold(__csum_ipv6_magic(saddr
, daddr
, htonl(len
),