MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / arch / nios2nommu / lib / checksum.c
blob475f1a31a9db66e9a1c94c27388a699591b4c263
1 /*--------------------------------------------------------------------
3 * Derived from various works, Alpha, ix86, M68K, Sparc, ...et al
5 * Copyright (C) 2004 Microtronix Datacom Ltd
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 * Jan/20/2004 dgt NiosII
20 ---------------------------------------------------------------------*/
22 #include <net/checksum.h>
23 #include <asm/checksum.h>
25 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
28 * computes the checksum of a memory block at buff, length len,
29 * and adds in "sum" (32-bit)
31 * returns a 32-bit number suitable for feeding into itself
32 * or csum_tcpudp_magic
34 * this function must be called with even lengths, except
35 * for the last fragment, which may be odd
37 * it's best to have buff aligned on a 32-bit boundary
40 unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum)
42 #if 0
43 __asm__ __volatile__ ...//;dgt2;tmp;not (yet) available...
44 ...//;dgt2;tmp;NiosI didn't offer either...
45 #else
46 unsigned int result = do_csum(buff, len);
48 /* add in old sum, and carry.. */
49 result += sum;
50 if (sum > result)
51 result += 1;
52 return result;
53 #endif
57 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
61 * the same as csum_partial, but copies from fs:src while it
62 * checksums
64 * here even more important to align src and dst on a 32-bit (or even
65 * better 64-bit) boundary
68 unsigned int csum_partial_copy(const char *src, char *dst, int len, int sum)
70 memcpy(dst, src, len);
71 return csum_partial(dst, len, sum);