1 /* SPDX-License-Identifier: GPL-2.0 */ 1 2 #ifndef _PARISC_CHECKSUM_H 3 #define _PARISC_CHECKSUM_H 4 5 #include <linux/in6.h> 6 7 /* 8 * computes the checksum of a memory block at 9 * and adds in "sum" (32-bit) 10 * 11 * returns a 32-bit number suitable for feedin 12 * or csum_tcpudp_magic 13 * 14 * this function must be called with even leng 15 * for the last fragment, which may be odd 16 * 17 * it's best to have buff aligned on a 32-bit 18 */ 19 extern __wsum csum_partial(const void *, int, 20 21 /* 22 * Optimized for IP headers, which always 23 * 24 * Written by Randolph Chung <tausq@debia 25 * LaMont Jones <lamont@debian.org> 26 */ 27 static inline __sum16 ip_fast_csum(const void 28 { 29 unsigned int sum; 30 unsigned long t0, t1, t2; 31 32 __asm__ __volatile__ ( 33 " ldws,ma 4(%1), %0\n" 34 " addib,<= -4, %2, 2f\n" 35 "\n" 36 " ldws 4(%1), %4\n" 37 " ldws 8(%1), %5\n" 38 " add %0, %4, %0\n" 39 " ldws,ma 12(%1), %3\n" 40 " addc %0, %5, %0\n" 41 " addc %0, %3, %0\n" 42 "1: ldws,ma 4(%1), %3\n" 43 " addib,> -1, %2, 1b\n" 44 " addc %0, %3, %0\n" 45 "\n" 46 " extru %0, 31, 16, %4\n" 47 " extru %0, 15, 16, %5\n" 48 " addc %4, %5, %0\n" 49 " extru %0, 15, 16, %5\n" 50 " add %0, %5, %0\n" 51 " subi -1, %0, %0\n" 52 "2:\n" 53 : "=r" (sum), "=r" (iph), "=r" (ihl), 54 : "1" (iph), "2" (ihl) 55 : "memory"); 56 57 return (__force __sum16)sum; 58 } 59 60 /* 61 * Fold a partial checksum 62 */ 63 static inline __sum16 csum_fold(__wsum csum) 64 { 65 u32 sum = (__force u32)csum; 66 /* add the swapped two 16-bit halves o 67 a possible carry from adding the tw 68 will carry from the lower half into 69 giving us the correct sum in the up 70 sum += (sum << 16) + (sum >> 16); 71 return (__force __sum16)(~sum >> 16); 72 } 73 74 static inline __wsum csum_tcpudp_nofold(__be32 75 __u32 76 __wsum 77 { 78 __asm__( 79 " add %1, %0, %0\n" 80 " addc %2, %0, %0\n" 81 " addc %3, %0, %0\n" 82 " addc %%r0, %0, %0\n" 83 : "=r" (sum) 84 : "r" (daddr), "r"(saddr), "r" 85 return sum; 86 } 87 88 /* 89 * computes the checksum of the TCP/UDP pseudo 90 * returns a 16-bit checksum, already compleme 91 */ 92 static inline __sum16 csum_tcpudp_magic(__be32 93 __u32 94 __wsum 95 { 96 return csum_fold(csum_tcpudp_nofold(sa 97 } 98 99 /* 100 * this routine is used for miscellaneous IP-l 101 * in icmp.c 102 */ 103 static inline __sum16 ip_compute_csum(const vo 104 { 105 return csum_fold (csum_partial(buf, l 106 } 107 108 109 #define _HAVE_ARCH_IPV6_CSUM 110 static __inline__ __sum16 csum_ipv6_magic(cons 111 cons 112 __u3 113 __ws 114 { 115 unsigned long t0, t1, t2, t3; 116 117 len += proto; /* add 16-bit proto + 118 119 __asm__ __volatile__ ( 120 121 #if BITS_PER_LONG > 32 122 123 /* 124 ** We can execute two loads and two ad 125 ** But add insn's get serialized waiti 126 ** Try to keep 4 registers with "live" 127 */ 128 129 " depdi 0, 31, 32, %0\n"/* cle 130 " ldd,ma 8(%1), %4\n" /* get 131 " ldd,ma 8(%2), %5\n" /* get 132 " add %4, %0, %0\n" 133 " ldd,ma 8(%1), %6\n" /* 2nd 134 " ldd,ma 8(%2), %7\n" /* 2nd 135 " add,dc %5, %0, %0\n" 136 " add,dc %6, %0, %0\n" 137 " add,dc %7, %0, %0\n" 138 " add,dc %3, %0, %0\n" /* fold 139 " extrd,u %0, 31, 32, %4\n"/* co 140 " depdi 0, 31, 32, %0\n"/* cle 141 " add,dc %4, %0, %0\n" /* fol 142 " addc 0, %0, %0\n" /* add 143 144 #else 145 146 /* 147 ** For PA 1.x, the insn order doesn't 148 ** Insn stream is serialized on the ca 149 ** result from the previous operation 150 */ 151 " ldw,ma 4(%1), %4\n" /* get 152 " ldw,ma 4(%2), %5\n" /* get 153 " add %4, %0, %0\n" 154 " ldw,ma 4(%1), %6\n" /* 2nd 155 " addc %5, %0, %0\n" 156 " ldw,ma 4(%2), %7\n" /* 2nd 157 " addc %6, %0, %0\n" 158 " ldw,ma 4(%1), %4\n" /* 3rd 159 " addc %7, %0, %0\n" 160 " ldw,ma 4(%2), %5\n" /* 3rd 161 " addc %4, %0, %0\n" 162 " ldw,ma 4(%1), %6\n" /* 4th 163 " addc %5, %0, %0\n" 164 " ldw,ma 4(%2), %7\n" /* 4th 165 " addc %6, %0, %0\n" 166 " addc %7, %0, %0\n" 167 " addc %3, %0, %0\n" /* fol 168 " addc 0, %0, %0\n" /* add 169 170 #endif 171 : "=r" (sum), "=r" (saddr), "=r" (dadd 172 "=r" (t0), "=r" (t1), "=r" (t2), "=r 173 : "" (sum), "1" (saddr), "2" (daddr), 174 : "memory"); 175 return csum_fold(sum); 176 } 177 178 #endif 179 180
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.