1/* $Id: old_checksum.c,v 1.1.1.1 2007-08-03 18:51:41 $ 2 * 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. 6 * 7 * IP/TCP/UDP checksumming routines 8 * 9 * Authors: Jorge Cwik, <jorge@laser.satlink.net> 10 * Arnt Gulbrandsen, <agulbra@nvg.unit.no> 11 * Tom May, <ftom@netcom.com> 12 * Lots of code moved from tcp.c and ip.c; see those files 13 * for more names. 14 * 15 * This program is free software; you can redistribute it and/or 16 * modify it under the terms of the GNU General Public License 17 * as published by the Free Software Foundation; either version 18 * 2 of the License, or (at your option) any later version. 19 */ 20 21#include <net/checksum.h> 22#include <net/module.h> 23 24#undef PROFILE_CHECKSUM 25 26#ifdef PROFILE_CHECKSUM 27/* these are just for profiling the checksum code with an oscillioscope.. uh */ 28#include <asm/io.h> 29#define CBITON LED_ACTIVE_SET(1) 30#define CBITOFF LED_ACTIVE_SET(0) 31#define BITOFF 32#define BITON 33#else 34#define BITOFF 35#define BITON 36#define CBITOFF 37#define CBITON 38#endif 39 40/* 41 * computes a partial checksum, e.g. for TCP/UDP fragments 42 */ 43 44#include <asm/delay.h> 45 46__wsum csum_partial(const void *p, int len, __wsum __sum) 47{ 48 u32 sum = (__force u32)__sum; 49 const u16 *buff = p; 50 /* 51 * Experiments with ethernet and slip connections show that buff 52 * is aligned on either a 2-byte or 4-byte boundary. 53 */ 54 const void *endMarker = p + len; 55 const void *marker = endMarker - (len % 16); 56 BITON; 57 while (buff < marker) { 58 sum += *buff++; 59 sum += *buff++; 60 sum += *buff++; 61 sum += *buff++; 62 sum += *buff++; 63 sum += *buff++; 64 sum += *buff++; 65 sum += *buff++; 66 } 67 marker = endMarker - (len % 2); 68 while (buff < marker) 69 sum += *buff++; 70 71 if (endMarker > buff) 72 sum += *(const u8 *)buff; /* add extra byte seperately */ 73 74 BITOFF; 75 return (__force __wsum)sum; 76} 77 78EXPORT_SYMBOL(csum_partial); 79