1 /* 2 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch> 3 * Copyright (C) 2004 Microtronix Datacom Ltd. 4 * 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 7 * for more details. 8 */ 9 10 #ifndef _ASM_NIOS_CHECKSUM_H 11 #define _ASM_NIOS_CHECKSUM_H 12 13 /* Take these from lib/checksum.c */ 14 extern __wsum csum_partial(const void *buff, int len, __wsum sum); 15 __wsum csum_partial_copy_nocheck(const void *src, void *dst, int len, 16 __wsum sum); 17 #define csum_partial_copy_nocheck csum_partial_copy_nocheck 18 19 extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl); 20 extern __sum16 ip_compute_csum(const void *buff, int len); 21 22 /* 23 * Fold a partial checksum 24 */ 25 static inline __sum16 csum_fold(__wsum sum) 26 { 27 __asm__ __volatile__( 28 "add %0, %1, %0\n" 29 "cmpltu r8, %0, %1\n" 30 "srli %0, %0, 16\n" 31 "add %0, %0, r8\n" 32 "nor %0, %0, %0\n" 33 : "=r" (sum) 34 : "r" (sum << 16), "0" (sum) 35 : "r8"); 36 return (__force __sum16) sum; 37 } 38 39 /* 40 * computes the checksum of the TCP/UDP pseudo-header 41 * returns a 16-bit checksum, already complemented 42 */ 43 #define csum_tcpudp_nofold csum_tcpudp_nofold 44 static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, 45 __u32 len, __u8 proto, 46 __wsum sum) 47 { 48 __asm__ __volatile__( 49 "add %0, %1, %0\n" 50 "cmpltu r8, %0, %1\n" 51 "add %0, %0, r8\n" /* add carry */ 52 "add %0, %2, %0\n" 53 "cmpltu r8, %0, %2\n" 54 "add %0, %0, r8\n" /* add carry */ 55 "add %0, %3, %0\n" 56 "cmpltu r8, %0, %3\n" 57 "add %0, %0, r8\n" /* add carry */ 58 : "=r" (sum), "=r" (saddr) 59 : "r" (daddr), "r" ((len + proto) << 8), 60 "0" (sum), 61 "1" (saddr) 62 : "r8"); 63 64 return sum; 65 } 66 67 static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, 68 __u32 len, __u8 proto, 69 __wsum sum) 70 { 71 return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum)); 72 } 73 74 #endif /* _ASM_NIOS_CHECKSUM_H */ 75