ia64/linux-2.6.18-xen.hg

annotate arch/m68knommu/lib/checksum.c @ 854:950b9eb27661

usbback: fix urb interval value for interrupt urbs.

Signed-off-by: Noboru Iwamatsu <n_iwamatsu@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Apr 06 13:51:20 2009 +0100 (2009-04-06)
parents 831230e53067
children
rev   line source
ian@0 1 /*
ian@0 2 * INET An implementation of the TCP/IP protocol suite for the LINUX
ian@0 3 * operating system. INET is implemented using the BSD Socket
ian@0 4 * interface as the means of communication with the user level.
ian@0 5 *
ian@0 6 * IP/TCP/UDP checksumming routines
ian@0 7 *
ian@0 8 * Authors: Jorge Cwik, <jorge@laser.satlink.net>
ian@0 9 * Arnt Gulbrandsen, <agulbra@nvg.unit.no>
ian@0 10 * Tom May, <ftom@netcom.com>
ian@0 11 * Andreas Schwab, <schwab@issan.informatik.uni-dortmund.de>
ian@0 12 * Lots of code moved from tcp.c and ip.c; see those files
ian@0 13 * for more names.
ian@0 14 *
ian@0 15 * 03/02/96 Jes Sorensen, Andreas Schwab, Roman Hodek:
ian@0 16 * Fixed some nasty bugs, causing some horrible crashes.
ian@0 17 * A: At some points, the sum (%0) was used as
ian@0 18 * length-counter instead of the length counter
ian@0 19 * (%1). Thanks to Roman Hodek for pointing this out.
ian@0 20 * B: GCC seems to mess up if one uses too many
ian@0 21 * data-registers to hold input values and one tries to
ian@0 22 * specify d0 and d1 as scratch registers. Letting gcc choose these
ian@0 23 * registers itself solves the problem.
ian@0 24 *
ian@0 25 * This program is free software; you can redistribute it and/or
ian@0 26 * modify it under the terms of the GNU General Public License
ian@0 27 * as published by the Free Software Foundation; either version
ian@0 28 * 2 of the License, or (at your option) any later version.
ian@0 29 */
ian@0 30
ian@0 31 /* Revised by Kenneth Albanowski for m68knommu. Basic problem: unaligned access kills, so most
ian@0 32 of the assembly has to go. */
ian@0 33
ian@0 34 #include <linux/module.h>
ian@0 35 #include <net/checksum.h>
ian@0 36
ian@0 37 static inline unsigned short from32to16(unsigned long x)
ian@0 38 {
ian@0 39 /* add up 16-bit and 16-bit for 16+c bit */
ian@0 40 x = (x & 0xffff) + (x >> 16);
ian@0 41 /* add up carry.. */
ian@0 42 x = (x & 0xffff) + (x >> 16);
ian@0 43 return x;
ian@0 44 }
ian@0 45
ian@0 46 static unsigned long do_csum(const unsigned char * buff, int len)
ian@0 47 {
ian@0 48 int odd, count;
ian@0 49 unsigned long result = 0;
ian@0 50
ian@0 51 if (len <= 0)
ian@0 52 goto out;
ian@0 53 odd = 1 & (unsigned long) buff;
ian@0 54 if (odd) {
ian@0 55 result = *buff;
ian@0 56 len--;
ian@0 57 buff++;
ian@0 58 }
ian@0 59 count = len >> 1; /* nr of 16-bit words.. */
ian@0 60 if (count) {
ian@0 61 if (2 & (unsigned long) buff) {
ian@0 62 result += *(unsigned short *) buff;
ian@0 63 count--;
ian@0 64 len -= 2;
ian@0 65 buff += 2;
ian@0 66 }
ian@0 67 count >>= 1; /* nr of 32-bit words.. */
ian@0 68 if (count) {
ian@0 69 unsigned long carry = 0;
ian@0 70 do {
ian@0 71 unsigned long w = *(unsigned long *) buff;
ian@0 72 count--;
ian@0 73 buff += 4;
ian@0 74 result += carry;
ian@0 75 result += w;
ian@0 76 carry = (w > result);
ian@0 77 } while (count);
ian@0 78 result += carry;
ian@0 79 result = (result & 0xffff) + (result >> 16);
ian@0 80 }
ian@0 81 if (len & 2) {
ian@0 82 result += *(unsigned short *) buff;
ian@0 83 buff += 2;
ian@0 84 }
ian@0 85 }
ian@0 86 if (len & 1)
ian@0 87 result += (*buff << 8);
ian@0 88 result = from32to16(result);
ian@0 89 if (odd)
ian@0 90 result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
ian@0 91 out:
ian@0 92 return result;
ian@0 93 }
ian@0 94
ian@0 95 /*
ian@0 96 * This is a version of ip_compute_csum() optimized for IP headers,
ian@0 97 * which always checksum on 4 octet boundaries.
ian@0 98 */
ian@0 99 unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl)
ian@0 100 {
ian@0 101 return ~do_csum(iph,ihl*4);
ian@0 102 }
ian@0 103
ian@0 104 /*
ian@0 105 * computes the checksum of a memory block at buff, length len,
ian@0 106 * and adds in "sum" (32-bit)
ian@0 107 *
ian@0 108 * returns a 32-bit number suitable for feeding into itself
ian@0 109 * or csum_tcpudp_magic
ian@0 110 *
ian@0 111 * this function must be called with even lengths, except
ian@0 112 * for the last fragment, which may be odd
ian@0 113 *
ian@0 114 * it's best to have buff aligned on a 32-bit boundary
ian@0 115 */
ian@0 116 unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum)
ian@0 117 {
ian@0 118 unsigned int result = do_csum(buff, len);
ian@0 119
ian@0 120 /* add in old sum, and carry.. */
ian@0 121 result += sum;
ian@0 122 if (sum > result)
ian@0 123 result += 1;
ian@0 124 return result;
ian@0 125 }
ian@0 126
ian@0 127 EXPORT_SYMBOL(csum_partial);
ian@0 128
ian@0 129 /*
ian@0 130 * this routine is used for miscellaneous IP-like checksums, mainly
ian@0 131 * in icmp.c
ian@0 132 */
ian@0 133 unsigned short ip_compute_csum(const unsigned char * buff, int len)
ian@0 134 {
ian@0 135 return ~do_csum(buff,len);
ian@0 136 }
ian@0 137
ian@0 138 /*
ian@0 139 * copy from fs while checksumming, otherwise like csum_partial
ian@0 140 */
ian@0 141
ian@0 142 unsigned int
ian@0 143 csum_partial_copy_from_user(const unsigned char *src, unsigned char *dst,
ian@0 144 int len, int sum, int *csum_err)
ian@0 145 {
ian@0 146 if (csum_err) *csum_err = 0;
ian@0 147 memcpy(dst, src, len);
ian@0 148 return csum_partial(dst, len, sum);
ian@0 149 }
ian@0 150
ian@0 151 /*
ian@0 152 * copy from ds while checksumming, otherwise like csum_partial
ian@0 153 */
ian@0 154
ian@0 155 unsigned int
ian@0 156 csum_partial_copy(const unsigned char *src, unsigned char *dst, int len, int sum)
ian@0 157 {
ian@0 158 memcpy(dst, src, len);
ian@0 159 return csum_partial(dst, len, sum);
ian@0 160 }