Path: blob/master/arch/sparc/include/asm/checksum_64.h
17537 views
#ifndef __SPARC64_CHECKSUM_H1#define __SPARC64_CHECKSUM_H23/* checksum.h: IP/UDP/TCP checksum routines on the V9.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 user space while it34* checksums35*36* here even more important to align src and dst on a 32-bit (or even37* better 64-bit) boundary38*/39extern __wsum csum_partial_copy_nocheck(const void *src, void *dst,40int len, __wsum sum);4142extern long __csum_partial_copy_from_user(const void __user *src,43void *dst, int len,44__wsum sum);4546static inline __wsum47csum_partial_copy_from_user(const void __user *src,48void *dst, int len,49__wsum sum, int *err)50{51long ret = __csum_partial_copy_from_user(src, dst, len, sum);52if (ret < 0)53*err = -EFAULT;54return (__force __wsum) ret;55}5657/*58* Copy and checksum to user59*/60#define HAVE_CSUM_COPY_USER61extern long __csum_partial_copy_to_user(const void *src,62void __user *dst, int len,63__wsum sum);6465static inline __wsum66csum_and_copy_to_user(const void *src,67void __user *dst, int len,68__wsum sum, int *err)69{70long ret = __csum_partial_copy_to_user(src, dst, len, sum);71if (ret < 0)72*err = -EFAULT;73return (__force __wsum) ret;74}7576/* ihl is always 5 or greater, almost always is 5, and iph is word aligned77* the majority of the time.78*/79extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);8081/* Fold a partial checksum without adding pseudo headers. */82static inline __sum16 csum_fold(__wsum sum)83{84unsigned int tmp;8586__asm__ __volatile__(87" addcc %0, %1, %1\n"88" srl %1, 16, %1\n"89" addc %1, %%g0, %1\n"90" xnor %%g0, %1, %0\n"91: "=&r" (sum), "=r" (tmp)92: "0" (sum), "1" ((__force u32)sum<<16)93: "cc");94return (__force __sum16)sum;95}9697static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,98unsigned int len,99unsigned short proto,100__wsum sum)101{102__asm__ __volatile__(103" addcc %1, %0, %0\n"104" addccc %2, %0, %0\n"105" addccc %3, %0, %0\n"106" addc %0, %%g0, %0\n"107: "=r" (sum), "=r" (saddr)108: "r" (daddr), "r" (proto + len), "0" (sum), "1" (saddr)109: "cc");110return sum;111}112113/*114* computes the checksum of the TCP/UDP pseudo-header115* returns a 16-bit checksum, already complemented116*/117static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,118unsigned short len,119unsigned short proto,120__wsum sum)121{122return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));123}124125#define _HAVE_ARCH_IPV6_CSUM126127static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr,128const struct in6_addr *daddr,129__u32 len, unsigned short proto,130__wsum sum)131{132__asm__ __volatile__ (133" addcc %3, %4, %%g7\n"134" addccc %5, %%g7, %%g7\n"135" lduw [%2 + 0x0c], %%g2\n"136" lduw [%2 + 0x08], %%g3\n"137" addccc %%g2, %%g7, %%g7\n"138" lduw [%2 + 0x04], %%g2\n"139" addccc %%g3, %%g7, %%g7\n"140" lduw [%2 + 0x00], %%g3\n"141" addccc %%g2, %%g7, %%g7\n"142" lduw [%1 + 0x0c], %%g2\n"143" addccc %%g3, %%g7, %%g7\n"144" lduw [%1 + 0x08], %%g3\n"145" addccc %%g2, %%g7, %%g7\n"146" lduw [%1 + 0x04], %%g2\n"147" addccc %%g3, %%g7, %%g7\n"148" lduw [%1 + 0x00], %%g3\n"149" addccc %%g2, %%g7, %%g7\n"150" addccc %%g3, %%g7, %0\n"151" addc 0, %0, %0\n"152: "=&r" (sum)153: "r" (saddr), "r" (daddr), "r"(htonl(len)),154"r"(htonl(proto)), "r"(sum)155: "g2", "g3", "g7", "cc");156157return csum_fold(sum);158}159160/* this routine is used for miscellaneous IP-like checksums, mainly in icmp.c */161static inline __sum16 ip_compute_csum(const void *buff, int len)162{163return csum_fold(csum_partial(buff, len, 0));164}165166#endif /* !(__SPARC64_CHECKSUM_H) */167168169