1 // SPDX-License-Identifier: GPL-2.0-or-later
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.
7 * MIPS specific IP/TCP/UDP checksumming routines
9 * Authors: Ralf Baechle, <ralf@waldorf-gmbh.de>
10 * Lots of code moved from tcp.c and ip.c; see those files
13 #include <linux/module.h>
14 #include <linux/types.h>
16 #include <net/checksum.h>
17 #include <asm/byteorder.h>
18 #include <asm/string.h>
19 #include <linux/uaccess.h>
22 __asm__ __volatile__ ( \
24 " addc %0, %%r0, %0\n" \
28 static inline unsigned int do_csum(const unsigned char * buff
, int len
)
31 unsigned int result
= 0;
35 odd
= 1 & (unsigned long) buff
;
37 result
= be16_to_cpu(*buff
);
41 count
= len
>> 1; /* nr of 16-bit words.. */
43 if (2 & (unsigned long) buff
) {
44 result
+= *(unsigned short *) buff
;
49 count
>>= 1; /* nr of 32-bit words.. */
52 unsigned int r1
, r2
, r3
, r4
;
53 r1
= *(unsigned int *)(buff
+ 0);
54 r2
= *(unsigned int *)(buff
+ 4);
55 r3
= *(unsigned int *)(buff
+ 8);
56 r4
= *(unsigned int *)(buff
+ 12);
65 unsigned int w
= *(unsigned int *) buff
;
70 result
= (result
& 0xffff) + (result
>> 16);
73 result
+= *(unsigned short *) buff
;
78 result
+= le16_to_cpu(*buff
);
79 result
= csum_from32to16(result
);
81 result
= swab16(result
);
87 * computes a partial checksum, e.g. for TCP/UDP fragments
92 __wsum
csum_partial(const void *buff
, int len
, __wsum sum
)
94 unsigned int result
= do_csum(buff
, len
);
96 return (__force __wsum
)csum_from32to16(result
);
99 EXPORT_SYMBOL(csum_partial
);