2 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2004 Microtronix Datacom Ltd.
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
10 #ifndef _ASM_NIOS_CHECKSUM_H
11 #define _ASM_NIOS_CHECKSUM_H
13 /* Take these from lib/checksum.c */
14 extern __wsum
csum_partial(const void *buff
, int len
, __wsum sum
);
15 extern __wsum
csum_partial_copy(const void *src
, void *dst
, int len
,
17 extern __wsum
csum_partial_copy_from_user(const void __user
*src
, void *dst
,
18 int len
, __wsum sum
, int *csum_err
);
19 #define csum_partial_copy_nocheck(src, dst, len, sum) \
20 csum_partial_copy((src), (dst), (len), (sum))
22 extern __sum16
ip_fast_csum(const void *iph
, unsigned int ihl
);
23 extern __sum16
ip_compute_csum(const void *buff
, int len
);
26 * Fold a partial checksum
28 static inline __sum16
csum_fold(__wsum sum
)
37 : "r" (sum
<< 16), "0" (sum
)
39 return (__force __sum16
) sum
;
43 * computes the checksum of the TCP/UDP pseudo-header
44 * returns a 16-bit checksum, already complemented
46 #define csum_tcpudp_nofold csum_tcpudp_nofold
47 static inline __wsum
csum_tcpudp_nofold(__be32 saddr
, __be32 daddr
,
55 "add %0, %0, r8\n" /* add carry */
58 "add %0, %0, r8\n" /* add carry */
61 "add %0, %0, r8\n" /* add carry */
62 : "=r" (sum
), "=r" (saddr
)
63 : "r" (daddr
), "r" ((ntohs(len
) << 16) + (proto
* 256)),
71 static inline __sum16
csum_tcpudp_magic(__be32 saddr
, __be32 daddr
,
73 unsigned short proto
, __wsum sum
)
75 return csum_fold(csum_tcpudp_nofold(saddr
, daddr
, len
, proto
, sum
));
78 #endif /* _ASM_NIOS_CHECKSUM_H */