Linux 3.12.28
[linux/fpc-iii.git] / arch / cris / arch-v10 / lib / old_checksum.c
blob8f79163f139415773acb3ee4f65bb00ed64ea940
1 /*
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
12 * for more names.
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 */
27 #if 0
28 #define BITOFF *((unsigned char *)0xb0000030) = 0xff
29 #define BITON *((unsigned char *)0xb0000030) = 0x0
30 #endif
31 #include <asm/io.h>
32 #define CBITON LED_ACTIVE_SET(1)
33 #define CBITOFF LED_ACTIVE_SET(0)
34 #define BITOFF
35 #define BITON
36 #else
37 #define BITOFF
38 #define BITON
39 #define CBITOFF
40 #define CBITON
41 #endif
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;
52 const u16 *buff = p;
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);
59 #if 0
60 if((int)buff & 0x3)
61 printk("unaligned buff %p\n", buff);
62 __delay(900); /* extra delay of 90 us to test performance hit */
63 #endif
64 BITON;
65 while (buff < marker) {
66 sum += *buff++;
67 sum += *buff++;
68 sum += *buff++;
69 sum += *buff++;
70 sum += *buff++;
71 sum += *buff++;
72 sum += *buff++;
73 sum += *buff++;
75 marker = endMarker - (len % 2);
76 while (buff < marker)
77 sum += *buff++;
79 if (endMarker > buff)
80 sum += *(const u8 *)buff; /* add extra byte separately */
82 BITOFF;
83 return (__force __wsum)sum;
86 EXPORT_SYMBOL(csum_partial);