2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
13 * Support code for the main lib/checksum.c.
16 #include <net/checksum.h>
17 #include <linux/module.h>
19 __wsum
do_csum(const unsigned char *buff
, int len
)
22 unsigned long result
= 0;
26 odd
= 1 & (unsigned long) buff
;
28 result
= (*buff
<< 8);
32 count
= len
>> 1; /* nr of 16-bit words.. */
34 if (2 & (unsigned long) buff
) {
35 result
+= *(const unsigned short *)buff
;
40 count
>>= 1; /* nr of 32-bit words.. */
43 if (4 & (unsigned long) buff
) {
44 unsigned int w
= *(const unsigned int *)buff
;
45 result
= __insn_v2sadau(result
, w
, 0);
50 count
>>= 1; /* nr of 64-bit words.. */
54 * This algorithm could wrap around for very
55 * large buffers, but those should be impossible.
57 BUG_ON(count
>= 65530);
60 unsigned long w
= *(const unsigned long *)buff
;
64 result
= __insn_v2sadau(result
, w
, 0);
66 result
= __insn_sadah_u(result
, w
, 0);
71 unsigned int w
= *(const unsigned int *)buff
;
72 result
= __insn_v2sadau(result
, w
, 0);
78 result
+= *(const unsigned short *) buff
;
84 result
= csum_long(result
);
86 result
= swab16(result
);