Path: blob/master/arch/cris/arch-v10/lib/old_checksum.c
15126 views
/*1* INET An implementation of the TCP/IP protocol suite for the LINUX2* operating system. INET is implemented using the BSD Socket3* interface as the means of communication with the user level.4*5* IP/TCP/UDP checksumming routines6*7* Authors: Jorge Cwik, <[email protected]>8* Arnt Gulbrandsen, <[email protected]>9* Tom May, <[email protected]>10* Lots of code moved from tcp.c and ip.c; see those files11* for more names.12*13* This program is free software; you can redistribute it and/or14* modify it under the terms of the GNU General Public License15* as published by the Free Software Foundation; either version16* 2 of the License, or (at your option) any later version.17*/1819#include <net/checksum.h>20#include <net/module.h>2122#undef PROFILE_CHECKSUM2324#ifdef PROFILE_CHECKSUM25/* these are just for profiling the checksum code with an oscillioscope.. uh */26#if 027#define BITOFF *((unsigned char *)0xb0000030) = 0xff28#define BITON *((unsigned char *)0xb0000030) = 0x029#endif30#include <asm/io.h>31#define CBITON LED_ACTIVE_SET(1)32#define CBITOFF LED_ACTIVE_SET(0)33#define BITOFF34#define BITON35#else36#define BITOFF37#define BITON38#define CBITOFF39#define CBITON40#endif4142/*43* computes a partial checksum, e.g. for TCP/UDP fragments44*/4546#include <asm/delay.h>4748__wsum csum_partial(const void *p, int len, __wsum __sum)49{50u32 sum = (__force u32)__sum;51const u16 *buff = p;52/*53* Experiments with ethernet and slip connections show that buff54* is aligned on either a 2-byte or 4-byte boundary.55*/56const void *endMarker = p + len;57const void *marker = endMarker - (len % 16);58#if 059if((int)buff & 0x3)60printk("unaligned buff %p\n", buff);61__delay(900); /* extra delay of 90 us to test performance hit */62#endif63BITON;64while (buff < marker) {65sum += *buff++;66sum += *buff++;67sum += *buff++;68sum += *buff++;69sum += *buff++;70sum += *buff++;71sum += *buff++;72sum += *buff++;73}74marker = endMarker - (len % 2);75while (buff < marker)76sum += *buff++;7778if (endMarker > buff)79sum += *(const u8 *)buff; /* add extra byte separately */8081BITOFF;82return (__force __wsum)sum;83}8485EXPORT_SYMBOL(csum_partial);868788