Path: blob/master/arch/m68k/include/asm/checksum.h
10820 views
#ifndef _M68K_CHECKSUM_H1#define _M68K_CHECKSUM_H23#include <linux/in6.h>45/*6* computes the checksum of a memory block at buff, length len,7* and adds in "sum" (32-bit)8*9* returns a 32-bit number suitable for feeding into itself10* or csum_tcpudp_magic11*12* this function must be called with even lengths, except13* for the last fragment, which may be odd14*15* it's best to have buff aligned on a 32-bit boundary16*/17__wsum csum_partial(const void *buff, int len, __wsum sum);1819/*20* the same as csum_partial, but copies from src while it21* checksums22*23* here even more important to align src and dst on a 32-bit (or even24* better 64-bit) boundary25*/2627extern __wsum csum_partial_copy_from_user(const void __user *src,28void *dst,29int len, __wsum sum,30int *csum_err);3132extern __wsum csum_partial_copy_nocheck(const void *src,33void *dst, int len,34__wsum sum);353637#ifdef CONFIG_COLDFIRE3839/*40* The ColdFire cores don't support all the 68k instructions used41* in the optimized checksum code below. So it reverts back to using42* more standard C coded checksums. The fast checksum code is43* significantly larger than the optimized version, so it is not44* inlined here.45*/46__sum16 ip_fast_csum(const void *iph, unsigned int ihl);4748static inline __sum16 csum_fold(__wsum sum)49{50unsigned int tmp = (__force u32)sum;5152tmp = (tmp & 0xffff) + (tmp >> 16);53tmp = (tmp & 0xffff) + (tmp >> 16);5455return (__force __sum16)~tmp;56}5758#else5960/*61* This is a version of ip_fast_csum() optimized for IP headers,62* which always checksum on 4 octet boundaries.63*/64static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)65{66unsigned int sum = 0;67unsigned long tmp;6869__asm__ ("subqw #1,%2\n"70"1:\t"71"movel %1@+,%3\n\t"72"addxl %3,%0\n\t"73"dbra %2,1b\n\t"74"movel %0,%3\n\t"75"swap %3\n\t"76"addxw %3,%0\n\t"77"clrw %3\n\t"78"addxw %3,%0\n\t"79: "=d" (sum), "=&a" (iph), "=&d" (ihl), "=&d" (tmp)80: "0" (sum), "1" (iph), "2" (ihl)81: "memory");82return (__force __sum16)~sum;83}8485static inline __sum16 csum_fold(__wsum sum)86{87unsigned int tmp = (__force u32)sum;8889__asm__("swap %1\n\t"90"addw %1, %0\n\t"91"clrw %1\n\t"92"addxw %1, %0"93: "=&d" (sum), "=&d" (tmp)94: "0" (sum), "1" (tmp));9596return (__force __sum16)~sum;97}9899#endif /* CONFIG_COLDFIRE */100101static inline __wsum102csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,103unsigned short proto, __wsum sum)104{105__asm__ ("addl %2,%0\n\t"106"addxl %3,%0\n\t"107"addxl %4,%0\n\t"108"clrl %1\n\t"109"addxl %1,%0"110: "=&d" (sum), "=d" (saddr)111: "g" (daddr), "1" (saddr), "d" (len + proto),112"0" (sum));113return sum;114}115116117/*118* computes the checksum of the TCP/UDP pseudo-header119* returns a 16-bit checksum, already complemented120*/121static inline __sum16122csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len,123unsigned short proto, __wsum sum)124{125return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));126}127128/*129* this routine is used for miscellaneous IP-like checksums, mainly130* in icmp.c131*/132133static inline __sum16 ip_compute_csum(const void *buff, int len)134{135return csum_fold (csum_partial(buff, len, 0));136}137138#define _HAVE_ARCH_IPV6_CSUM139static __inline__ __sum16140csum_ipv6_magic(const struct in6_addr *saddr, const struct in6_addr *daddr,141__u32 len, unsigned short proto, __wsum sum)142{143register unsigned long tmp;144__asm__("addl %2@,%0\n\t"145"movel %2@(4),%1\n\t"146"addxl %1,%0\n\t"147"movel %2@(8),%1\n\t"148"addxl %1,%0\n\t"149"movel %2@(12),%1\n\t"150"addxl %1,%0\n\t"151"movel %3@,%1\n\t"152"addxl %1,%0\n\t"153"movel %3@(4),%1\n\t"154"addxl %1,%0\n\t"155"movel %3@(8),%1\n\t"156"addxl %1,%0\n\t"157"movel %3@(12),%1\n\t"158"addxl %1,%0\n\t"159"addxl %4,%0\n\t"160"clrl %1\n\t"161"addxl %1,%0"162: "=&d" (sum), "=&d" (tmp)163: "a" (saddr), "a" (daddr), "d" (len + proto),164"0" (sum));165166return csum_fold(sum);167}168169#endif /* _M68K_CHECKSUM_H */170171172