~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/s390/include/asm/checksum.h

Version: ~ [ linux-5.4-rc3 ] ~ [ linux-5.3.6 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.79 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.149 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.196 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.196 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.75 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *    S390 fast network checksum routines
  3  *
  4  *  S390 version
  5  *    Copyright IBM Corp. 1999
  6  *    Author(s): Ulrich Hild        (first version)
  7  *               Martin Schwidefsky (heavily optimized CKSM version)
  8  *               D.J. Barrow        (third attempt) 
  9  */
 10 
 11 #ifndef _S390_CHECKSUM_H
 12 #define _S390_CHECKSUM_H
 13 
 14 #include <linux/uaccess.h>
 15 
 16 /*
 17  * computes the checksum of a memory block at buff, length len,
 18  * and adds in "sum" (32-bit)
 19  *
 20  * returns a 32-bit number suitable for feeding into itself
 21  * or csum_tcpudp_magic
 22  *
 23  * this function must be called with even lengths, except
 24  * for the last fragment, which may be odd
 25  *
 26  * it's best to have buff aligned on a 32-bit boundary
 27  */
 28 static inline __wsum
 29 csum_partial(const void *buff, int len, __wsum sum)
 30 {
 31         register unsigned long reg2 asm("2") = (unsigned long) buff;
 32         register unsigned long reg3 asm("3") = (unsigned long) len;
 33 
 34         asm volatile(
 35                 "0:     cksm    %0,%1\n"        /* do checksum on longs */
 36                 "       jo      0b\n"
 37                 : "+d" (sum), "+d" (reg2), "+d" (reg3) : : "cc", "memory");
 38         return sum;
 39 }
 40 
 41 /*
 42  * the same as csum_partial_copy, but copies from user space.
 43  *
 44  * here even more important to align src and dst on a 32-bit (or even
 45  * better 64-bit) boundary
 46  *
 47  * Copy from userspace and compute checksum.
 48  */
 49 static inline __wsum
 50 csum_partial_copy_from_user(const void __user *src, void *dst,
 51                                           int len, __wsum sum,
 52                                           int *err_ptr)
 53 {
 54         if (unlikely(copy_from_user(dst, src, len)))
 55                 *err_ptr = -EFAULT;
 56         return csum_partial(dst, len, sum);
 57 }
 58 
 59 
 60 static inline __wsum
 61 csum_partial_copy_nocheck (const void *src, void *dst, int len, __wsum sum)
 62 {
 63         memcpy(dst,src,len);
 64         return csum_partial(dst, len, sum);
 65 }
 66 
 67 /*
 68  *      Fold a partial checksum without adding pseudo headers
 69  */
 70 static inline __sum16 csum_fold(__wsum sum)
 71 {
 72         u32 csum = (__force u32) sum;
 73 
 74         csum += (csum >> 16) + (csum << 16);
 75         csum >>= 16;
 76         return (__force __sum16) ~csum;
 77 }
 78 
 79 /*
 80  *      This is a version of ip_compute_csum() optimized for IP headers,
 81  *      which always checksum on 4 octet boundaries.
 82  *
 83  */
 84 static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
 85 {
 86         return csum_fold(csum_partial(iph, ihl*4, 0));
 87 }
 88 
 89 /*
 90  * computes the checksum of the TCP/UDP pseudo-header
 91  * returns a 32-bit checksum
 92  */
 93 static inline __wsum
 94 csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len, __u8 proto,
 95                    __wsum sum)
 96 {
 97         __u32 csum = (__force __u32)sum;
 98 
 99         csum += (__force __u32)saddr;
100         if (csum < (__force __u32)saddr)
101                 csum++;
102 
103         csum += (__force __u32)daddr;
104         if (csum < (__force __u32)daddr)
105                 csum++;
106 
107         csum += len + proto;
108         if (csum < len + proto)
109                 csum++;
110 
111         return (__force __wsum)csum;
112 }
113 
114 /*
115  * computes the checksum of the TCP/UDP pseudo-header
116  * returns a 16-bit checksum, already complemented
117  */
118 
119 static inline __sum16
120 csum_tcpudp_magic(__be32 saddr, __be32 daddr, __u32 len, __u8 proto,
121                   __wsum sum)
122 {
123         return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
124 }
125 
126 /*
127  * this routine is used for miscellaneous IP-like checksums, mainly
128  * in icmp.c
129  */
130 
131 static inline __sum16 ip_compute_csum(const void *buff, int len)
132 {
133         return csum_fold(csum_partial(buff, len, 0));
134 }
135 
136 #endif /* _S390_CHECKSUM_H */
137 
138 
139 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp