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

TOMOYO Linux Cross Reference
Linux/arch/sparc/include/asm/checksum_64.h

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef __SPARC64_CHECKSUM_H
  3 #define __SPARC64_CHECKSUM_H
  4 
  5 /*  checksum.h:  IP/UDP/TCP checksum routines on the V9.
  6  *
  7  *  Copyright(C) 1995 Linus Torvalds
  8  *  Copyright(C) 1995 Miguel de Icaza
  9  *  Copyright(C) 1996 David S. Miller
 10  *  Copyright(C) 1996 Eddie C. Dost
 11  *  Copyright(C) 1997 Jakub Jelinek
 12  *
 13  * derived from:
 14  *      Alpha checksum c-code
 15  *      ix86 inline assembly
 16  *      RFC1071 Computing the Internet Checksum
 17  */
 18 
 19 #include <linux/in6.h>
 20 #include <linux/uaccess.h>
 21 
 22 /* computes the checksum of a memory block at buff, length len,
 23  * and adds in "sum" (32-bit)
 24  *
 25  * returns a 32-bit number suitable for feeding into itself
 26  * or csum_tcpudp_magic
 27  *
 28  * this function must be called with even lengths, except
 29  * for the last fragment, which may be odd
 30  *
 31  * it's best to have buff aligned on a 32-bit boundary
 32  */
 33 __wsum csum_partial(const void * buff, int len, __wsum sum);
 34 
 35 /* the same as csum_partial, but copies from user space while it
 36  * checksums
 37  *
 38  * here even more important to align src and dst on a 32-bit (or even
 39  * better 64-bit) boundary
 40  */
 41 __wsum csum_partial_copy_nocheck(const void *src, void *dst, int len);
 42 __wsum csum_and_copy_from_user(const void __user *src, void *dst, int len);
 43 __wsum csum_and_copy_to_user(const void *src, void __user *dst, int len);
 44 
 45 /* ihl is always 5 or greater, almost always is 5, and iph is word aligned
 46  * the majority of the time.
 47  */
 48 __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
 49 
 50 /* Fold a partial checksum without adding pseudo headers. */
 51 static inline __sum16 csum_fold(__wsum sum)
 52 {
 53         unsigned int tmp;
 54 
 55         __asm__ __volatile__(
 56 "       addcc           %0, %1, %1\n"
 57 "       srl             %1, 16, %1\n"
 58 "       addc            %1, %%g0, %1\n"
 59 "       xnor            %%g0, %1, %0\n"
 60         : "=&r" (sum), "=r" (tmp)
 61         : "" (sum), "1" ((__force u32)sum<<16)
 62         : "cc");
 63         return (__force __sum16)sum;
 64 }
 65 
 66 static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
 67                                         __u32 len, __u8 proto,
 68                                         __wsum sum)
 69 {
 70         __asm__ __volatile__(
 71 "       addcc           %1, %0, %0\n"
 72 "       addccc          %2, %0, %0\n"
 73 "       addccc          %3, %0, %0\n"
 74 "       addc            %0, %%g0, %0\n"
 75         : "=r" (sum), "=r" (saddr)
 76         : "r" (daddr), "r" (proto + len), "" (sum), "1" (saddr)
 77         : "cc");
 78         return sum;
 79 }
 80 
 81 /*
 82  * computes the checksum of the TCP/UDP pseudo-header
 83  * returns a 16-bit checksum, already complemented
 84  */
 85 static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
 86                                         __u32 len, __u8 proto,
 87                                         __wsum sum)
 88 {
 89         return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
 90 }
 91 
 92 #define _HAVE_ARCH_IPV6_CSUM
 93 
 94 static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
 95                                       const struct in6_addr *daddr,
 96                                       __u32 len, __u8 proto, __wsum sum)
 97 {
 98         __asm__ __volatile__ (
 99 "       addcc           %3, %4, %%g7\n"
100 "       addccc          %5, %%g7, %%g7\n"
101 "       lduw            [%2 + 0x0c], %%g2\n"
102 "       lduw            [%2 + 0x08], %%g3\n"
103 "       addccc          %%g2, %%g7, %%g7\n"
104 "       lduw            [%2 + 0x04], %%g2\n"
105 "       addccc          %%g3, %%g7, %%g7\n"
106 "       lduw            [%2 + 0x00], %%g3\n"
107 "       addccc          %%g2, %%g7, %%g7\n"
108 "       lduw            [%1 + 0x0c], %%g2\n"
109 "       addccc          %%g3, %%g7, %%g7\n"
110 "       lduw            [%1 + 0x08], %%g3\n"
111 "       addccc          %%g2, %%g7, %%g7\n"
112 "       lduw            [%1 + 0x04], %%g2\n"
113 "       addccc          %%g3, %%g7, %%g7\n"
114 "       lduw            [%1 + 0x00], %%g3\n"
115 "       addccc          %%g2, %%g7, %%g7\n"
116 "       addccc          %%g3, %%g7, %0\n"
117 "       addc            0, %0, %0\n"
118         : "=&r" (sum)
119         : "r" (saddr), "r" (daddr), "r"(htonl(len)),
120           "r"(htonl(proto)), "r"(sum)
121         : "g2", "g3", "g7", "cc");
122 
123         return csum_fold(sum);
124 }
125 
126 /* this routine is used for miscellaneous IP-like checksums, mainly in icmp.c */
127 static inline __sum16 ip_compute_csum(const void *buff, int len)
128 {
129         return csum_fold(csum_partial(buff, len, 0));
130 }
131 
132 #define HAVE_ARCH_CSUM_ADD
133 static inline __wsum csum_add(__wsum csum, __wsum addend)
134 {
135         __asm__ __volatile__(
136                 "addcc   %0, %1, %0\n"
137                 "addx    %0, %%g0, %0"
138                 : "=r" (csum)
139                 : "r" (addend), "" (csum));
140 
141         return csum;
142 }
143 
144 #endif /* !(__SPARC64_CHECKSUM_H) */
145 

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php