2 * Copyright (C) 2004-2006 Atmel Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 #ifndef __ASM_AVR32_CHECKSUM_H
9 #define __ASM_AVR32_CHECKSUM_H
12 * computes the checksum of a memory block at buff, length len,
13 * and adds in "sum" (32-bit)
15 * returns a 32-bit number suitable for feeding into itself
16 * or csum_tcpudp_magic
18 * this function must be called with even lengths, except
19 * for the last fragment, which may be odd
21 * it's best to have buff aligned on a 32-bit boundary
23 unsigned int csum_partial(const unsigned char * buff
, int len
,
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
33 unsigned int csum_partial_copy_generic(const char *src
, char *dst
, int len
,
34 int sum
, int *src_err_ptr
,
38 * Note: when you get a NULL pointer exception here this means someone
39 * passed in an incorrect kernel address to one of these functions.
41 * If you use these functions directly please don't forget the
45 unsigned int csum_partial_copy_nocheck(const char *src
, char *dst
,
48 return csum_partial_copy_generic(src
, dst
, len
, sum
, NULL
, NULL
);
52 unsigned int csum_partial_copy_from_user (const char __user
*src
, char *dst
,
53 int len
, int sum
, int *err_ptr
)
55 return csum_partial_copy_generic((const char __force
*)src
, dst
, len
,
60 * This is a version of ip_compute_csum() optimized for IP headers,
61 * which always checksum on 4 octet boundaries.
63 static inline unsigned short ip_fast_csum(unsigned char *iph
,
66 unsigned int sum
, tmp
;
90 : "=r"(sum
), "=r"(iph
), "=r"(ihl
), "=r"(tmp
)
97 * Fold a partial checksum
100 static inline unsigned int csum_fold(unsigned int sum
)
104 asm(" bfextu %1, %0, 0, 16\n"
107 " bfextu %1, %0, 16, 16\n"
109 : "=&r"(sum
), "=&r"(tmp
)
115 static inline unsigned long csum_tcpudp_nofold(unsigned long saddr
,
118 unsigned short proto
,
126 : "r"(daddr
), "r"(saddr
), "r"(ntohs(len
) | (proto
<< 16)),
134 * computes the checksum of the TCP/UDP pseudo-header
135 * returns a 16-bit checksum, already complemented
137 static inline unsigned short int csum_tcpudp_magic(unsigned long saddr
,
140 unsigned short proto
,
143 return csum_fold(csum_tcpudp_nofold(saddr
,daddr
,len
,proto
,sum
));
147 * this routine is used for miscellaneous IP-like checksums, mainly
151 static inline unsigned short ip_compute_csum(unsigned char * buff
, int len
)
153 return csum_fold(csum_partial(buff
, len
, 0));
156 #endif /* __ASM_AVR32_CHECKSUM_H */