2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
6 * IP/TCP/UDP checksumming routines
8 * Authors: Jorge Cwik, <jorge@laser.satlink.net>
9 * Arnt Gulbrandsen, <agulbra@nvg.unit.no>
10 * Tom May, <ftom@netcom.com>
11 * Lots of code moved from tcp.c and ip.c; see those files
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version
17 * 2 of the License, or (at your option) any later version.
20 #include <net/checksum.h>
21 #include <net/module.h>
23 #undef PROFILE_CHECKSUM
25 #ifdef PROFILE_CHECKSUM
26 /* these are just for profiling the checksum code with an oscillioscope.. uh */
28 #define BITOFF *((unsigned char *)0xb0000030) = 0xff
29 #define BITON *((unsigned char *)0xb0000030) = 0x0
32 #define CBITON LED_ACTIVE_SET(1)
33 #define CBITOFF LED_ACTIVE_SET(0)
44 * computes a partial checksum, e.g. for TCP/UDP fragments
47 #include <asm/delay.h>
49 __wsum
csum_partial(const void *p
, int len
, __wsum __sum
)
51 u32 sum
= (__force u32
)__sum
;
54 * Experiments with ethernet and slip connections show that buff
55 * is aligned on either a 2-byte or 4-byte boundary.
57 const void *endMarker
= p
+ len
;
58 const void *marker
= endMarker
- (len
% 16);
61 printk("unaligned buff %p\n", buff
);
62 __delay(900); /* extra delay of 90 us to test performance hit */
65 while (buff
< marker
) {
75 marker
= endMarker
- (len
% 2);
80 sum
+= *(const u8
*)buff
; /* add extra byte separately */
83 return (__force __wsum
)sum
;
86 EXPORT_SYMBOL(csum_partial
);