Path: blob/master/arch/mn10300/include/asm/checksum.h
15126 views
/* MN10300 Optimised checksumming code1*2* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.3* Written by David Howells ([email protected])4*5* This program is free software; you can redistribute it and/or6* modify it under the terms of the GNU General Public Licence7* as published by the Free Software Foundation; either version8* 2 of the Licence, or (at your option) any later version.9*/10#ifndef _ASM_CHECKSUM_H11#define _ASM_CHECKSUM_H1213extern __wsum csum_partial(const void *buff, int len, __wsum sum);14extern __wsum csum_partial_copy_nocheck(const void *src, void *dst,15int len, __wsum sum);16extern __wsum csum_partial_copy_from_user(const void *src, void *dst,17int len, __wsum sum,18int *err_ptr);19extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);20extern __wsum csum_partial(const void *buff, int len, __wsum sum);21extern __sum16 ip_compute_csum(const void *buff, int len);2223#define csum_partial_copy_fromuser csum_partial_copy24extern __wsum csum_partial_copy(const void *src, void *dst, int len,25__wsum sum);2627static inline __sum16 csum_fold(__wsum sum)28{29asm(30" add %1,%0 \n"31" addc 0xffff,%0 \n"32: "=r" (sum)33: "r" (sum << 16), "0" (sum & 0xffff0000)34: "cc"35);36return (~sum) >> 16;37}3839static inline __wsum csum_tcpudp_nofold(unsigned long saddr,40unsigned long daddr,41unsigned short len,42unsigned short proto,43__wsum sum)44{45__wsum tmp;4647tmp = (__wsum) ntohs(len) << 16;48tmp += (__wsum) proto << 8;4950asm(51" add %1,%0 \n"52" addc %2,%0 \n"53" addc %3,%0 \n"54" addc 0,%0 \n"55: "=r" (sum)56: "r" (daddr), "r"(saddr), "r"(tmp), "0"(sum)57: "cc"58);59return sum;60}6162/*63* computes the checksum of the TCP/UDP pseudo-header64* returns a 16-bit checksum, already complemented65*/66static inline __sum16 csum_tcpudp_magic(unsigned long saddr,67unsigned long daddr,68unsigned short len,69unsigned short proto,70__wsum sum)71{72return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));73}7475#undef _HAVE_ARCH_IPV6_CSUM7677/*78* Copy and checksum to user79*/80#define HAVE_CSUM_COPY_USER81extern __wsum csum_and_copy_to_user(const void *src, void *dst, int len,82__wsum sum, int *err_ptr);838485#endif /* _ASM_CHECKSUM_H */868788