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 __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
16 extern __sum16 ip_compute_csum(const void *buff, int len);
19 * Fold a partial checksum
21 static inline __sum16 csum_fold(__wsum sum)
30 : "r" (sum << 16), "0" (sum)
32 return (__force __sum16) sum;
36 * computes the checksum of the TCP/UDP pseudo-header
37 * returns a 16-bit checksum, already complemented
39 #define csum_tcpudp_nofold csum_tcpudp_nofold
40 static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
41 __u32 len, __u8 proto,
47 "add %0, %0, r8\n" /* add carry */
50 "add %0, %0, r8\n" /* add carry */
53 "add %0, %0, r8\n" /* add carry */
54 : "=r" (sum), "=r" (saddr)
55 : "r" (daddr), "r" ((len + proto) << 8),
63 static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
64 __u32 len, __u8 proto,
67 return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
70 #endif /* _ASM_NIOS_CHECKSUM_H */