Path: blob/master/arch/sparc/include/asm/checksum_32.h
17537 views
#ifndef __SPARC_CHECKSUM_H1#define __SPARC_CHECKSUM_H23/* checksum.h: IP/UDP/TCP checksum routines on the Sparc.4*5* Copyright(C) 1995 Linus Torvalds6* Copyright(C) 1995 Miguel de Icaza7* Copyright(C) 1996 David S. Miller8* Copyright(C) 1996 Eddie C. Dost9* Copyright(C) 1997 Jakub Jelinek10*11* derived from:12* Alpha checksum c-code13* ix86 inline assembly14* RFC1071 Computing the Internet Checksum15*/1617#include <linux/in6.h>18#include <asm/uaccess.h>1920/* computes the checksum of a memory block at buff, length len,21* and adds in "sum" (32-bit)22*23* returns a 32-bit number suitable for feeding into itself24* or csum_tcpudp_magic25*26* this function must be called with even lengths, except27* for the last fragment, which may be odd28*29* it's best to have buff aligned on a 32-bit boundary30*/31extern __wsum csum_partial(const void *buff, int len, __wsum sum);3233/* the same as csum_partial, but copies from fs:src while it34* checksums35*36* here even more important to align src and dst on a 32-bit (or even37* better 64-bit) boundary38*/3940extern unsigned int __csum_partial_copy_sparc_generic (const unsigned char *, unsigned char *);4142static inline __wsum43csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum)44{45register unsigned int ret asm("o0") = (unsigned int)src;46register char *d asm("o1") = dst;47register int l asm("g1") = len;4849__asm__ __volatile__ (50"call __csum_partial_copy_sparc_generic\n\t"51" mov %6, %%g7\n"52: "=&r" (ret), "=&r" (d), "=&r" (l)53: "0" (ret), "1" (d), "2" (l), "r" (sum)54: "o2", "o3", "o4", "o5", "o7",55"g2", "g3", "g4", "g5", "g7",56"memory", "cc");57return (__force __wsum)ret;58}5960static inline __wsum61csum_partial_copy_from_user(const void __user *src, void *dst, int len,62__wsum sum, int *err)63{64register unsigned long ret asm("o0") = (unsigned long)src;65register char *d asm("o1") = dst;66register int l asm("g1") = len;67register __wsum s asm("g7") = sum;6869__asm__ __volatile__ (70".section __ex_table,#alloc\n\t"71".align 4\n\t"72".word 1f,2\n\t"73".previous\n"74"1:\n\t"75"call __csum_partial_copy_sparc_generic\n\t"76" st %8, [%%sp + 64]\n"77: "=&r" (ret), "=&r" (d), "=&r" (l), "=&r" (s)78: "0" (ret), "1" (d), "2" (l), "3" (s), "r" (err)79: "o2", "o3", "o4", "o5", "o7", "g2", "g3", "g4", "g5",80"cc", "memory");81return (__force __wsum)ret;82}8384static inline __wsum85csum_partial_copy_to_user(const void *src, void __user *dst, int len,86__wsum sum, int *err)87{88if (!access_ok (VERIFY_WRITE, dst, len)) {89*err = -EFAULT;90return sum;91} else {92register unsigned long ret asm("o0") = (unsigned long)src;93register char __user *d asm("o1") = dst;94register int l asm("g1") = len;95register __wsum s asm("g7") = sum;9697__asm__ __volatile__ (98".section __ex_table,#alloc\n\t"99".align 4\n\t"100".word 1f,1\n\t"101".previous\n"102"1:\n\t"103"call __csum_partial_copy_sparc_generic\n\t"104" st %8, [%%sp + 64]\n"105: "=&r" (ret), "=&r" (d), "=&r" (l), "=&r" (s)106: "0" (ret), "1" (d), "2" (l), "3" (s), "r" (err)107: "o2", "o3", "o4", "o5", "o7",108"g2", "g3", "g4", "g5",109"cc", "memory");110return (__force __wsum)ret;111}112}113114#define HAVE_CSUM_COPY_USER115#define csum_and_copy_to_user csum_partial_copy_to_user116117/* ihl is always 5 or greater, almost always is 5, and iph is word aligned118* the majority of the time.119*/120static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)121{122__sum16 sum;123124/* Note: We must read %2 before we touch %0 for the first time,125* because GCC can legitimately use the same register for126* both operands.127*/128__asm__ __volatile__("sub\t%2, 4, %%g4\n\t"129"ld\t[%1 + 0x00], %0\n\t"130"ld\t[%1 + 0x04], %%g2\n\t"131"ld\t[%1 + 0x08], %%g3\n\t"132"addcc\t%%g2, %0, %0\n\t"133"addxcc\t%%g3, %0, %0\n\t"134"ld\t[%1 + 0x0c], %%g2\n\t"135"ld\t[%1 + 0x10], %%g3\n\t"136"addxcc\t%%g2, %0, %0\n\t"137"addx\t%0, %%g0, %0\n"138"1:\taddcc\t%%g3, %0, %0\n\t"139"add\t%1, 4, %1\n\t"140"addxcc\t%0, %%g0, %0\n\t"141"subcc\t%%g4, 1, %%g4\n\t"142"be,a\t2f\n\t"143"sll\t%0, 16, %%g2\n\t"144"b\t1b\n\t"145"ld\t[%1 + 0x10], %%g3\n"146"2:\taddcc\t%0, %%g2, %%g2\n\t"147"srl\t%%g2, 16, %0\n\t"148"addx\t%0, %%g0, %0\n\t"149"xnor\t%%g0, %0, %0"150: "=r" (sum), "=&r" (iph)151: "r" (ihl), "1" (iph)152: "g2", "g3", "g4", "cc", "memory");153return sum;154}155156/* Fold a partial checksum without adding pseudo headers. */157static inline __sum16 csum_fold(__wsum sum)158{159unsigned int tmp;160161__asm__ __volatile__("addcc\t%0, %1, %1\n\t"162"srl\t%1, 16, %1\n\t"163"addx\t%1, %%g0, %1\n\t"164"xnor\t%%g0, %1, %0"165: "=&r" (sum), "=r" (tmp)166: "0" (sum), "1" ((__force u32)sum<<16)167: "cc");168return (__force __sum16)sum;169}170171static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,172unsigned short len,173unsigned short proto,174__wsum sum)175{176__asm__ __volatile__("addcc\t%1, %0, %0\n\t"177"addxcc\t%2, %0, %0\n\t"178"addxcc\t%3, %0, %0\n\t"179"addx\t%0, %%g0, %0\n\t"180: "=r" (sum), "=r" (saddr)181: "r" (daddr), "r" (proto + len), "0" (sum),182"1" (saddr)183: "cc");184return sum;185}186187/*188* computes the checksum of the TCP/UDP pseudo-header189* returns a 16-bit checksum, already complemented190*/191static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,192unsigned short len,193unsigned short proto,194__wsum sum)195{196return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));197}198199#define _HAVE_ARCH_IPV6_CSUM200201static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr,202const struct in6_addr *daddr,203__u32 len, unsigned short proto,204__wsum sum)205{206__asm__ __volatile__ (207"addcc %3, %4, %%g4\n\t"208"addxcc %5, %%g4, %%g4\n\t"209"ld [%2 + 0x0c], %%g2\n\t"210"ld [%2 + 0x08], %%g3\n\t"211"addxcc %%g2, %%g4, %%g4\n\t"212"ld [%2 + 0x04], %%g2\n\t"213"addxcc %%g3, %%g4, %%g4\n\t"214"ld [%2 + 0x00], %%g3\n\t"215"addxcc %%g2, %%g4, %%g4\n\t"216"ld [%1 + 0x0c], %%g2\n\t"217"addxcc %%g3, %%g4, %%g4\n\t"218"ld [%1 + 0x08], %%g3\n\t"219"addxcc %%g2, %%g4, %%g4\n\t"220"ld [%1 + 0x04], %%g2\n\t"221"addxcc %%g3, %%g4, %%g4\n\t"222"ld [%1 + 0x00], %%g3\n\t"223"addxcc %%g2, %%g4, %%g4\n\t"224"addxcc %%g3, %%g4, %0\n\t"225"addx 0, %0, %0\n"226: "=&r" (sum)227: "r" (saddr), "r" (daddr),228"r"(htonl(len)), "r"(htonl(proto)), "r"(sum)229: "g2", "g3", "g4", "cc");230231return csum_fold(sum);232}233234/* this routine is used for miscellaneous IP-like checksums, mainly in icmp.c */235static inline __sum16 ip_compute_csum(const void *buff, int len)236{237return csum_fold(csum_partial(buff, len, 0));238}239240#endif /* !(__SPARC_CHECKSUM_H) */241242243