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

TOMOYO Linux Cross Reference
Linux/arch/parisc/lib/checksum.c

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-or-later
  2 /*
  3  * INET         An implementation of the TCP/IP protocol suite for the LINUX
  4  *              operating system.  INET is implemented using the  BSD Socket
  5  *              interface as the means of communication with the user level.
  6  *
  7  *              MIPS specific IP/TCP/UDP checksumming routines
  8  *
  9  * Authors:     Ralf Baechle, <ralf@waldorf-gmbh.de>
 10  *              Lots of code moved from tcp.c and ip.c; see those files
 11  *              for more names.
 12  */
 13 #include <linux/module.h>
 14 #include <linux/types.h>
 15 
 16 #include <net/checksum.h>
 17 #include <asm/byteorder.h>
 18 #include <asm/string.h>
 19 #include <linux/uaccess.h>
 20 
 21 #define addc(_t,_r)                     \
 22         __asm__ __volatile__ (          \
 23 "       add             %0, %1, %0\n"   \
 24 "       addc            %0, %%r0, %0\n" \
 25         : "=r"(_t)                      \
 26         : "r"(_r), ""(_t));
 27 
 28 static inline unsigned short from32to16(unsigned int x)
 29 {
 30         /* 32 bits --> 16 bits + carry */
 31         x = (x & 0xffff) + (x >> 16);
 32         /* 16 bits + carry --> 16 bits including carry */
 33         x = (x & 0xffff) + (x >> 16);
 34         return (unsigned short)x;
 35 }
 36 
 37 static inline unsigned int do_csum(const unsigned char * buff, int len)
 38 {
 39         int odd, count;
 40         unsigned int result = 0;
 41 
 42         if (len <= 0)
 43                 goto out;
 44         odd = 1 & (unsigned long) buff;
 45         if (odd) {
 46                 result = be16_to_cpu(*buff);
 47                 len--;
 48                 buff++;
 49         }
 50         count = len >> 1;               /* nr of 16-bit words.. */
 51         if (count) {
 52                 if (2 & (unsigned long) buff) {
 53                         result += *(unsigned short *) buff;
 54                         count--;
 55                         len -= 2;
 56                         buff += 2;
 57                 }
 58                 count >>= 1;            /* nr of 32-bit words.. */
 59                 if (count) {
 60                         while (count >= 4) {
 61                                 unsigned int r1, r2, r3, r4;
 62                                 r1 = *(unsigned int *)(buff + 0);
 63                                 r2 = *(unsigned int *)(buff + 4);
 64                                 r3 = *(unsigned int *)(buff + 8);
 65                                 r4 = *(unsigned int *)(buff + 12);
 66                                 addc(result, r1);
 67                                 addc(result, r2);
 68                                 addc(result, r3);
 69                                 addc(result, r4);
 70                                 count -= 4;
 71                                 buff += 16;
 72                         }
 73                         while (count) {
 74                                 unsigned int w = *(unsigned int *) buff;
 75                                 count--;
 76                                 buff += 4;
 77                                 addc(result, w);
 78                         }
 79                         result = (result & 0xffff) + (result >> 16);
 80                 }
 81                 if (len & 2) {
 82                         result += *(unsigned short *) buff;
 83                         buff += 2;
 84                 }
 85         }
 86         if (len & 1)
 87                 result += le16_to_cpu(*buff);
 88         result = from32to16(result);
 89         if (odd)
 90                 result = swab16(result);
 91 out:
 92         return result;
 93 }
 94 
 95 /*
 96  * computes a partial checksum, e.g. for TCP/UDP fragments
 97  */
 98 /*
 99  * why bother folding?
100  */
101 __wsum csum_partial(const void *buff, int len, __wsum sum)
102 {
103         unsigned int result = do_csum(buff, len);
104         addc(result, sum);
105         return (__force __wsum)from32to16(result);
106 }
107 
108 EXPORT_SYMBOL(csum_partial);
109 

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