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

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

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

Diff markup

Differences between /arch/alpha/lib/checksum.c (Architecture mips) and /arch/alpha/lib/checksum.c (Architecture alpha)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 /*                                                  2 /*
  3  * arch/alpha/lib/checksum.c                        3  * arch/alpha/lib/checksum.c
  4  *                                                  4  *
  5  * This file contains network checksum routine      5  * This file contains network checksum routines that are better done
  6  * in an architecture-specific manner due to s      6  * in an architecture-specific manner due to speed..
  7  * Comments in other versions indicate that th      7  * Comments in other versions indicate that the algorithms are from RFC1071
  8  *                                                  8  *
  9  * accelerated versions (and 21264 assembly ve      9  * accelerated versions (and 21264 assembly versions ) contributed by
 10  *      Rick Gorton     <rick.gorton@alpha-pro     10  *      Rick Gorton     <rick.gorton@alpha-processor.com>
 11  */                                                11  */
 12                                                    12  
 13 #include <linux/module.h>                          13 #include <linux/module.h>
 14 #include <linux/string.h>                          14 #include <linux/string.h>
 15 #include <net/checksum.h>                          15 #include <net/checksum.h>
 16                                                    16 
 17 #include <asm/byteorder.h>                         17 #include <asm/byteorder.h>
 18 #include <asm/checksum.h>                          18 #include <asm/checksum.h>
 19                                                    19 
 20 static inline unsigned short from64to16(unsign     20 static inline unsigned short from64to16(unsigned long x)
 21 {                                                  21 {
 22         /* Using extract instructions is a bit     22         /* Using extract instructions is a bit more efficient
 23            than the original shift/bitmask ver     23            than the original shift/bitmask version.  */
 24                                                    24 
 25         union {                                    25         union {
 26                 unsigned long   ul;                26                 unsigned long   ul;
 27                 unsigned int    ui[2];             27                 unsigned int    ui[2];
 28                 unsigned short  us[4];             28                 unsigned short  us[4];
 29         } in_v, tmp_v, out_v;                      29         } in_v, tmp_v, out_v;
 30                                                    30 
 31         in_v.ul = x;                               31         in_v.ul = x;
 32         tmp_v.ul = (unsigned long) in_v.ui[0]      32         tmp_v.ul = (unsigned long) in_v.ui[0] + (unsigned long) in_v.ui[1];
 33                                                    33 
 34         /* Since the bits of tmp_v.sh[3] are g     34         /* Since the bits of tmp_v.sh[3] are going to always be zero,
 35            we don't have to bother to add that     35            we don't have to bother to add that in.  */
 36         out_v.ul = (unsigned long) tmp_v.us[0]     36         out_v.ul = (unsigned long) tmp_v.us[0] + (unsigned long) tmp_v.us[1]
 37                         + (unsigned long) tmp_     37                         + (unsigned long) tmp_v.us[2];
 38                                                    38 
 39         /* Similarly, out_v.us[2] is always ze     39         /* Similarly, out_v.us[2] is always zero for the final add.  */
 40         return out_v.us[0] + out_v.us[1];          40         return out_v.us[0] + out_v.us[1];
 41 }                                                  41 }
 42                                                    42 
 43 /*                                                 43 /*
 44  * computes the checksum of the TCP/UDP pseudo     44  * computes the checksum of the TCP/UDP pseudo-header
 45  * returns a 16-bit checksum, already compleme     45  * returns a 16-bit checksum, already complemented.
 46  */                                                46  */
 47 __sum16 csum_tcpudp_magic(__be32 saddr, __be32     47 __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
 48                           __u32 len, __u8 prot     48                           __u32 len, __u8 proto, __wsum sum)
 49 {                                                  49 {
 50         return (__force __sum16)~from64to16(       50         return (__force __sum16)~from64to16(
 51                 (__force u64)saddr + (__force      51                 (__force u64)saddr + (__force u64)daddr +
 52                 (__force u64)sum + ((len + pro     52                 (__force u64)sum + ((len + proto) << 8));
 53 }                                                  53 }
 54 EXPORT_SYMBOL(csum_tcpudp_magic);                  54 EXPORT_SYMBOL(csum_tcpudp_magic);
 55                                                    55 
 56 __wsum csum_tcpudp_nofold(__be32 saddr, __be32     56 __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
 57                           __u32 len, __u8 prot     57                           __u32 len, __u8 proto, __wsum sum)
 58 {                                                  58 {
 59         unsigned long result;                      59         unsigned long result;
 60                                                    60 
 61         result = (__force u64)saddr + (__force     61         result = (__force u64)saddr + (__force u64)daddr +
 62                  (__force u64)sum + ((len + pr     62                  (__force u64)sum + ((len + proto) << 8);
 63                                                    63 
 64         /* Fold down to 32-bits so we don't lo     64         /* Fold down to 32-bits so we don't lose in the typedef-less 
 65            network stack.  */                      65            network stack.  */
 66         /* 64 to 33 */                             66         /* 64 to 33 */
 67         result = (result & 0xffffffff) + (resu     67         result = (result & 0xffffffff) + (result >> 32);
 68         /* 33 to 32 */                             68         /* 33 to 32 */
 69         result = (result & 0xffffffff) + (resu     69         result = (result & 0xffffffff) + (result >> 32);
 70         return (__force __wsum)result;             70         return (__force __wsum)result;
 71 }                                                  71 }
 72 EXPORT_SYMBOL(csum_tcpudp_nofold);                 72 EXPORT_SYMBOL(csum_tcpudp_nofold);
 73                                                    73 
 74 /*                                                 74 /*
 75  * Do a 64-bit checksum on an arbitrary memory     75  * Do a 64-bit checksum on an arbitrary memory area..
 76  *                                                 76  *
 77  * This isn't a great routine, but it's not _h     77  * This isn't a great routine, but it's not _horrible_ either. The
 78  * inner loop could be unrolled a bit further,     78  * inner loop could be unrolled a bit further, and there are better
 79  * ways to do the carry, but this is reasonabl     79  * ways to do the carry, but this is reasonable.
 80  */                                                80  */
 81 static inline unsigned long do_csum(const unsi     81 static inline unsigned long do_csum(const unsigned char * buff, int len)
 82 {                                                  82 {
 83         int odd, count;                            83         int odd, count;
 84         unsigned long result = 0;                  84         unsigned long result = 0;
 85                                                    85 
 86         if (len <= 0)                              86         if (len <= 0)
 87                 goto out;                          87                 goto out;
 88         odd = 1 & (unsigned long) buff;            88         odd = 1 & (unsigned long) buff;
 89         if (odd) {                                 89         if (odd) {
 90                 result = *buff << 8;               90                 result = *buff << 8;
 91                 len--;                             91                 len--;
 92                 buff++;                            92                 buff++;
 93         }                                          93         }
 94         count = len >> 1;               /* nr      94         count = len >> 1;               /* nr of 16-bit words.. */
 95         if (count) {                               95         if (count) {
 96                 if (2 & (unsigned long) buff)      96                 if (2 & (unsigned long) buff) {
 97                         result += *(unsigned s     97                         result += *(unsigned short *) buff;
 98                         count--;                   98                         count--;
 99                         len -= 2;                  99                         len -= 2;
100                         buff += 2;                100                         buff += 2;
101                 }                                 101                 }
102                 count >>= 1;            /* nr     102                 count >>= 1;            /* nr of 32-bit words.. */
103                 if (count) {                      103                 if (count) {
104                         if (4 & (unsigned long    104                         if (4 & (unsigned long) buff) {
105                                 result += *(un    105                                 result += *(unsigned int *) buff;
106                                 count--;          106                                 count--;
107                                 len -= 4;         107                                 len -= 4;
108                                 buff += 4;        108                                 buff += 4;
109                         }                         109                         }
110                         count >>= 1;    /* nr     110                         count >>= 1;    /* nr of 64-bit words.. */
111                         if (count) {              111                         if (count) {
112                                 unsigned long     112                                 unsigned long carry = 0;
113                                 do {              113                                 do {
114                                         unsign    114                                         unsigned long w = *(unsigned long *) buff;
115                                         count-    115                                         count--;
116                                         buff +    116                                         buff += 8;
117                                         result    117                                         result += carry;
118                                         result    118                                         result += w;
119                                         carry     119                                         carry = (w > result);
120                                 } while (count    120                                 } while (count);
121                                 result += carr    121                                 result += carry;
122                                 result = (resu    122                                 result = (result & 0xffffffff) + (result >> 32);
123                         }                         123                         }
124                         if (len & 4) {            124                         if (len & 4) {
125                                 result += *(un    125                                 result += *(unsigned int *) buff;
126                                 buff += 4;        126                                 buff += 4;
127                         }                         127                         }
128                 }                                 128                 }
129                 if (len & 2) {                    129                 if (len & 2) {
130                         result += *(unsigned s    130                         result += *(unsigned short *) buff;
131                         buff += 2;                131                         buff += 2;
132                 }                                 132                 }
133         }                                         133         }
134         if (len & 1)                              134         if (len & 1)
135                 result += *buff;                  135                 result += *buff;
136         result = from64to16(result);              136         result = from64to16(result);
137         if (odd)                                  137         if (odd)
138                 result = ((result >> 8) & 0xff    138                 result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
139 out:                                              139 out:
140         return result;                            140         return result;
141 }                                                 141 }
142                                                   142 
143 /*                                                143 /*
144  *      This is a version of ip_compute_csum()    144  *      This is a version of ip_compute_csum() optimized for IP headers,
145  *      which always checksum on 4 octet bound    145  *      which always checksum on 4 octet boundaries.
146  */                                               146  */
147 __sum16 ip_fast_csum(const void *iph, unsigned    147 __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
148 {                                                 148 {
149         return (__force __sum16)~do_csum(iph,i    149         return (__force __sum16)~do_csum(iph,ihl*4);
150 }                                                 150 }
151 EXPORT_SYMBOL(ip_fast_csum);                      151 EXPORT_SYMBOL(ip_fast_csum);
152                                                   152 
153 /*                                                153 /*
154  * computes the checksum of a memory block at     154  * computes the checksum of a memory block at buff, length len,
155  * and adds in "sum" (32-bit)                     155  * and adds in "sum" (32-bit)
156  *                                                156  *
157  * returns a 32-bit number suitable for feedin    157  * returns a 32-bit number suitable for feeding into itself
158  * or csum_tcpudp_magic                           158  * or csum_tcpudp_magic
159  *                                                159  *
160  * this function must be called with even leng    160  * this function must be called with even lengths, except
161  * for the last fragment, which may be odd        161  * for the last fragment, which may be odd
162  *                                                162  *
163  * it's best to have buff aligned on a 32-bit     163  * it's best to have buff aligned on a 32-bit boundary
164  */                                               164  */
165 __wsum csum_partial(const void *buff, int len,    165 __wsum csum_partial(const void *buff, int len, __wsum sum)
166 {                                                 166 {
167         unsigned long result = do_csum(buff, l    167         unsigned long result = do_csum(buff, len);
168                                                   168 
169         /* add in old sum, and carry.. */         169         /* add in old sum, and carry.. */
170         result += (__force u32)sum;               170         result += (__force u32)sum;
171         /* 32+c bits -> 32 bits */                171         /* 32+c bits -> 32 bits */
172         result = (result & 0xffffffff) + (resu    172         result = (result & 0xffffffff) + (result >> 32);
173         return (__force __wsum)result;            173         return (__force __wsum)result;
174 }                                                 174 }
175                                                   175 
176 EXPORT_SYMBOL(csum_partial);                      176 EXPORT_SYMBOL(csum_partial);
177                                                   177 
178 /*                                                178 /*
179  * this routine is used for miscellaneous IP-l    179  * this routine is used for miscellaneous IP-like checksums, mainly
180  * in icmp.c                                      180  * in icmp.c
181  */                                               181  */
182 __sum16 ip_compute_csum(const void *buff, int     182 __sum16 ip_compute_csum(const void *buff, int len)
183 {                                                 183 {
184         return (__force __sum16)~from64to16(do    184         return (__force __sum16)~from64to16(do_csum(buff,len));
185 }                                                 185 }
186 EXPORT_SYMBOL(ip_compute_csum);                   186 EXPORT_SYMBOL(ip_compute_csum);
187                                                   187 

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