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

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

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ 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-only */
  2 /*
  3  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  4  *
  5  * Joern Rennecke  <joern.rennecke@embecosm.com>: Jan 2012
  6  *  -Insn Scheduling improvements to csum core routines.
  7  *      = csum_fold( ) largely derived from ARM version.
  8  *      = ip_fast_cum( ) to have module scheduling
  9  *  -gcc 4.4.x broke networking. Alias analysis needed to be primed.
 10  *   worked around by adding memory clobber to ip_fast_csum( )
 11  *
 12  * vineetg: May 2010
 13  *  -Rewrote ip_fast_cscum( ) and csum_fold( ) with fast inline asm
 14  */
 15 
 16 #ifndef _ASM_ARC_CHECKSUM_H
 17 #define _ASM_ARC_CHECKSUM_H
 18 
 19 /*
 20  *      Fold a partial checksum
 21  *
 22  *  The 2 swords comprising the 32bit sum are added, any carry to 16th bit
 23  *  added back and final sword result inverted.
 24  */
 25 static inline __sum16 csum_fold(__wsum s)
 26 {
 27         unsigned int r = s << 16 | s >> 16;     /* ror */
 28         s = ~s;
 29         s -= r;
 30         return s >> 16;
 31 }
 32 
 33 /*
 34  *      This is a version of ip_compute_csum() optimized for IP headers,
 35  *      which always checksum on 4 octet boundaries.
 36  */
 37 static inline __sum16
 38 ip_fast_csum(const void *iph, unsigned int ihl)
 39 {
 40         const void *ptr = iph;
 41         unsigned int tmp, tmp2, sum;
 42 
 43         __asm__(
 44         "       ld.ab  %0, [%3, 4]              \n"
 45         "       ld.ab  %2, [%3, 4]              \n"
 46         "       sub    %1, %4, 2                \n"
 47         "       lsr.f  lp_count, %1, 1          \n"
 48         "       bcc    0f                       \n"
 49         "       add.f  %0, %0, %2               \n"
 50         "       ld.ab  %2, [%3, 4]              \n"
 51         "0:     lp     1f                       \n"
 52         "       ld.ab  %1, [%3, 4]              \n"
 53         "       adc.f  %0, %0, %2               \n"
 54         "       ld.ab  %2, [%3, 4]              \n"
 55         "       adc.f  %0, %0, %1               \n"
 56         "1:     adc.f  %0, %0, %2               \n"
 57         "       add.cs %0,%0,1                  \n"
 58         : "=&r"(sum), "=r"(tmp), "=&r"(tmp2), "+&r" (ptr)
 59         : "r"(ihl)
 60         : "cc", "lp_count", "memory");
 61 
 62         return csum_fold(sum);
 63 }
 64 
 65 /*
 66  * TCP pseudo Header is 12 bytes:
 67  * SA [4], DA [4], zeroes [1], Proto[1], TCP Seg(hdr+data) Len [2]
 68  */
 69 static inline __wsum
 70 csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len,
 71                    __u8 proto, __wsum sum)
 72 {
 73         __asm__ __volatile__(
 74         "       add.f %0, %0, %1        \n"
 75         "       adc.f %0, %0, %2        \n"
 76         "       adc.f %0, %0, %3        \n"
 77         "       adc.f %0, %0, %4        \n"
 78         "       adc   %0, %0, 0         \n"
 79         : "+&r"(sum)
 80         : "r"(saddr), "r"(daddr),
 81 #ifdef CONFIG_CPU_BIG_ENDIAN
 82           "r"(len),
 83 #else
 84           "r"(len << 8),
 85 #endif
 86           "r"(htons(proto))
 87         : "cc");
 88 
 89         return sum;
 90 }
 91 
 92 #define csum_fold csum_fold
 93 #define ip_fast_csum ip_fast_csum
 94 #define csum_tcpudp_nofold csum_tcpudp_nofold
 95 
 96 #include <asm-generic/checksum.h>
 97 
 98 #endif /* _ASM_ARC_CHECKSUM_H */
 99 

~ [ 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