From: monstr@monstr.eu
To: linux-kernel@vger.kernel.org
Cc: monstr@seznam.cz, arnd@arndb.de, linux-arch@vger.kernel.org,
stephen.neuendorffer@xilinx.com, John.Linn@xilinx.com,
john.williams@petalogix.com, matthew@wil.cx,
will.newton@gmail.com, drepper@redhat.com,
microblaze-uclinux@itee.uq.edu.au, grant.likely@secretlab.ca,
vapier.adi@gmail.com, alan@lxorguk.ukuu.org.uk, hpa@zytor.com,
lethal@linux-sh.org, florian@openwrt.org,
Michal Simek <monstr@monstr.eu>
Subject: [PATCH 18/58] microblaze_v5: checksum support
Date: Tue, 8 Jul 2008 13:59:18 +0200 [thread overview]
Message-ID: <c5f0730287365c845746467a9917dbc07d2fca3c.1215517976.git.monstr@monstr.eu> (raw)
In-Reply-To: <a967ee4e5a60b410e2810ce0475e8fd04f99e3ae.1215517976.git.monstr@monstr.eu>
In-Reply-To: <80a2e46f2fb93812ab12bf79c703e8e2d6b0faa0.1215517976.git.monstr@monstr.eu>
From: Michal Simek <monstr@monstr.eu>
Acked-by: Stephen Neuendorffer <stephen.neuendorffer@xilinx.com>
Signed-off-by: Michal Simek <monstr@monstr.eu>
---
include/asm-generic/checksum.h | 80 ++++++++++++++++++
include/asm-microblaze/checksum.h | 34 ++++++++
lib/Makefile | 2 +
lib/checksum.c | 166 +++++++++++++++++++++++++++++++++++++
4 files changed, 282 insertions(+), 0 deletions(-)
create mode 100644 include/asm-generic/checksum.h
create mode 100644 include/asm-microblaze/checksum.h
create mode 100644 lib/checksum.c
diff --git a/include/asm-generic/checksum.h b/include/asm-generic/checksum.h
new file mode 100644
index 0000000..7dfb920
--- /dev/null
+++ b/include/asm-generic/checksum.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2006 Atmark Techno, Inc.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_GENERIC_CHECKSUM_H
+#define _ASM_GENERIC_CHECKSUM_H
+
+#include <linux/in6.h>
+
+/*
+ * computes the checksum of a memory block at buff, length len,
+ * and adds in "sum" (32-bit)
+ *
+ * returns a 32-bit number suitable for feeding into itself
+ * or csum_tcpudp_magic
+ *
+ * this function must be called with even lengths, except
+ * for the last fragment, which may be odd
+ *
+ * it's best to have buff aligned on a 32-bit boundary
+ */
+unsigned int csum_partial(const unsigned char *buff, int len,
+ unsigned int sum);
+
+/*
+ * the same as csum_partial, but copies from src while it
+ * checksums
+ *
+ * here even more important to align src and dst on a 32-bit (or even
+ * better 64-bit) boundary
+ */
+unsigned int csum_partial_copy(const char *src, char *dst, int len, int sum);
+
+/*
+ * the same as csum_partial_copy, but copies from user space.
+ *
+ * here even more important to align src and dst on a 32-bit (or even
+ * better 64-bit) boundary
+ */
+extern unsigned int csum_partial_copy_from_user(const char *src, char *dst,
+ int len, int sum, int *csum_err);
+
+#define csum_partial_copy_nocheck(src, dst, len, sum) \
+ csum_partial_copy((src), (dst), (len), (sum))
+
+/*
+ * This is a version of ip_compute_csum() optimized for IP headers,
+ * which always checksum on 4 octet boundaries.
+ *
+ */
+extern unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl);
+
+/*
+ * Fold a partial checksum
+ */
+static inline unsigned int csum_fold(unsigned int sum)
+{
+ sum = (sum & 0xffff) + (sum >> 16);
+ sum = (sum & 0xffff) + (sum >> 16);
+ return ~sum;
+}
+
+static inline unsigned short int
+csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len,
+ unsigned short proto, unsigned int sum)
+{
+ return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
+}
+
+/*
+ * this routine is used for miscellaneous IP-like checksums, mainly
+ * in icmp.c
+ */
+extern unsigned short ip_compute_csum(const unsigned char *buff, int len);
+
+#endif /* _ASM_GENERIC_CHECKSUM_H */
diff --git a/include/asm-microblaze/checksum.h b/include/asm-microblaze/checksum.h
new file mode 100644
index 0000000..2da3744
--- /dev/null
+++ b/include/asm-microblaze/checksum.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2006 Atmark Techno, Inc.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_MICROBLAZE_CHECKSUM_H
+#define _ASM_MICROBLAZE_CHECKSUM_H
+
+/*
+ * computes the checksum of the TCP/UDP pseudo-header
+ * returns a 16-bit checksum, already complemented
+ */
+static inline unsigned int
+csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr, unsigned short len,
+ unsigned short proto, unsigned int sum)
+{
+ __asm__("add %0, %4, %1\n\t"
+ "addc %0, %4, %2\n\t"
+ "addc %0, %4, %3\n\t"
+ "addc %0, %4, r0\n\t"
+ : "=d" (sum)
+ : "d" (saddr), "d" (daddr), "d" (len + proto),
+ "0"(sum));
+
+ return sum;
+}
+
+
+#include <asm-generic/checksum.h>
+
+#endif /* _ASM_MICROBLAZE_CHECKSUM_H */
diff --git a/lib/Makefile b/lib/Makefile
index 74b0cfb..6f48c04 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -72,6 +72,8 @@ lib-$(CONFIG_GENERIC_BUG) += bug.o
obj-$(CONFIG_HAVE_LMB) += lmb.o
+obj-$(CONFIG_GENERIC_CSUM) += checksum.o
+
hostprogs-y := gen_crc32table
clean-files := crc32table.h
diff --git a/lib/checksum.c b/lib/checksum.c
new file mode 100644
index 0000000..0060873
--- /dev/null
+++ b/lib/checksum.c
@@ -0,0 +1,166 @@
+/*
+ * arch/microblaze/lib/checksum.c
+ *
+ * Copyright (C) 2008 Michal Simek <monstr@monstr.eu>
+ *
+ * INET An implementation of the TCP/IP protocol suite for the LINUX
+ * operating system. INET is implemented using the BSD Socket
+ * interface as the means of communication with the user level.
+ *
+ * IP/TCP/UDP checksumming routines
+ *
+ * Authors: Jorge Cwik, <jorge@laser.satlink.net>
+ * Arnt Gulbrandsen, <agulbra@nvg.unit.no>
+ * Tom May, <ftom@netcom.com>
+ * Andreas Schwab, <schwab@issan.informatik.uni-dortmund.de>
+ * Lots of code moved from tcp.c and ip.c; see those files
+ * for more names.
+ *
+ * 03/02/96 Jes Sorensen, Andreas Schwab, Roman Hodek:
+ * Fixed some nasty bugs, causing some horrible crashes.
+ * A: At some points, the sum (%0) was used as
+ * length-counter instead of the length counter
+ * (%1). Thanks to Roman Hodek for pointing this out.
+ * B: GCC seems to mess up if one uses too many
+ * data-registers to hold input values and one tries to
+ * specify d0 and d1 as scratch registers. Letting gcc choose these
+ * registers itself solves the problem.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+/* Revised by Kenneth Albanowski for m68knommu. Basic problem: unaligned access
+ kills, so most of the assembly has to go. */
+
+#include <net/checksum.h>
+#include <asm-generic/checksum.h>
+#include <linux/module.h>
+
+static inline unsigned short from32to16(unsigned long x)
+{
+ /* add up 16-bit and 16-bit for 16+c bit */
+ x = (x & 0xffff) + (x >> 16);
+ /* add up carry.. */
+ x = (x & 0xffff) + (x >> 16);
+ return x;
+}
+
+static unsigned long do_csum(const unsigned char *buff, int len)
+{
+ int odd, count;
+ unsigned long result = 0;
+
+ if (len <= 0)
+ goto out;
+ odd = 1 & (unsigned long) buff;
+ if (odd) {
+ result = *buff;
+ len--;
+ buff++;
+ }
+ count = len >> 1; /* nr of 16-bit words.. */
+ if (count) {
+ if (2 & (unsigned long) buff) {
+ result += *(unsigned short *) buff;
+ count--;
+ len -= 2;
+ buff += 2;
+ }
+ count >>= 1; /* nr of 32-bit words.. */
+ if (count) {
+ unsigned long carry = 0;
+ do {
+ unsigned long w = *(unsigned long *) buff;
+ count--;
+ buff += 4;
+ result += carry;
+ result += w;
+ carry = (w > result);
+ } while (count);
+ result += carry;
+ result = (result & 0xffff) + (result >> 16);
+ }
+ if (len & 2) {
+ result += *(unsigned short *) buff;
+ buff += 2;
+ }
+ }
+ if (len & 1)
+ result += (*buff << 8);
+ result = from32to16(result);
+ if (odd)
+ result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
+out:
+ return result;
+}
+
+/*
+ * This is a version of ip_compute_csum() optimized for IP headers,
+ * which always checksum on 4 octet boundaries.
+ */
+unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl)
+{
+ return ~do_csum(iph, ihl*4);
+}
+
+/*
+ * computes the checksum of a memory block at buff, length len,
+ * and adds in "sum" (32-bit)
+ *
+ * returns a 32-bit number suitable for feeding into itself
+ * or csum_tcpudp_magic
+ *
+ * this function must be called with even lengths, except
+ * for the last fragment, which may be odd
+ *
+ * it's best to have buff aligned on a 32-bit boundary
+ */
+unsigned int csum_partial(const unsigned char *buff, int len, unsigned int sum)
+{
+ unsigned int result = do_csum(buff, len);
+
+ /* add in old sum, and carry.. */
+ result += sum;
+ if (sum > result)
+ result += 1;
+ return result;
+}
+EXPORT_SYMBOL(csum_partial);
+
+/*
+ * this routine is used for miscellaneous IP-like checksums, mainly
+ * in icmp.c
+ */
+unsigned short ip_compute_csum(const unsigned char *buff, int len)
+{
+ return ~do_csum(buff, len);
+}
+EXPORT_SYMBOL(ip_compute_csum);
+
+/*
+ * copy from fs while checksumming, otherwise like csum_partial
+ */
+unsigned int
+csum_partial_copy_from_user(const char __user *src, char *dst, int len,
+ int sum, int *csum_err)
+{
+ if (csum_err)
+ *csum_err = 0;
+ memcpy(dst, src, len);
+ return csum_partial(dst, len, sum);
+}
+EXPORT_SYMBOL(csum_partial_copy_from_user);
+
+/*
+ * copy from ds while checksumming, otherwise like csum_partial
+ */
+unsigned int
+csum_partial_copy(const char *src, char *dst, int len, int sum)
+{
+ memcpy(dst, src, len);
+ return csum_partial(dst, len, sum);
+}
+EXPORT_SYMBOL(csum_partial_copy);
--
1.5.4.GIT
next prev parent reply other threads:[~2008-07-08 12:45 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-08 11:59 microblaze_v5: Status message monstr
2008-07-08 11:59 ` [PATCH 01/58] microblaze_v5: Kconfig patches monstr
2008-07-08 11:59 ` [PATCH 02/58] microblaze_v5: Makefiles for Microblaze cpu monstr
2008-07-08 11:59 ` [PATCH 03/58] microblaze_v5: Cpuinfo handling monstr
2008-07-08 11:59 ` [PATCH 04/58] microblaze_v5: Open firmware files1 monstr
2008-07-08 11:59 ` [PATCH 05/58] microblaze_v5: Open firmware files2 monstr
2008-07-08 11:59 ` [PATCH 06/58] microblaze_v5: Open firmware common files monstr
2008-07-08 11:59 ` [PATCH 07/58] microblaze_v5: exception handling monstr
2008-07-08 11:59 ` [PATCH 08/58] microblaze_v5: Signal support monstr
2008-07-08 11:59 ` [PATCH 09/58] microblaze_v5: Interrupt handling, timer support, supported function monstr
2008-07-08 11:59 ` [PATCH 10/58] microblaze_v5: cache support monstr
2008-07-08 11:59 ` monstr
2008-07-08 11:59 ` [PATCH 11/58] microblaze_v5: Generic dts file for platforms monstr
2008-07-08 11:59 ` [PATCH 12/58] microblaze_v5: kernel modules support monstr
2008-07-08 11:59 ` [PATCH 13/58] microblaze_v5: lmb support monstr
2008-07-08 11:59 ` [PATCH 14/58] microblaze_v5: PVR support, cpuinfo support monstr
2008-07-08 11:59 ` [PATCH 15/58] microblaze_v5: defconfig file monstr
2008-07-08 11:59 ` [PATCH 16/58] microblaze_v5: head.S + linker script monstr
2008-07-08 11:59 ` [PATCH 17/58] microblaze_v5: supported function for memory - kernel/lib monstr
2008-07-08 11:59 ` monstr [this message]
2008-07-08 11:59 ` [PATCH 19/58] microblaze_v5: early_printk support monstr
2008-07-08 11:59 ` [PATCH 20/58] microblaze_v5: uaccess files monstr
2008-07-08 11:59 ` [PATCH 21/58] microblaze_v5: heartbeat file monstr
2008-07-08 11:59 ` [PATCH 22/58] microblaze_v5: setup.c - system setting monstr
2008-07-08 11:59 ` [PATCH 23/58] microblaze_v5: asm-offsets monstr
2008-07-08 11:59 ` [PATCH 24/58] microblaze_v5: process and init task function monstr
2008-07-08 11:59 ` [PATCH 25/58] microblaze_v5: time support monstr
2008-07-08 11:59 ` [PATCH 26/58] microblaze_v5: virtualization monstr
2008-07-08 11:59 ` [PATCH 27/58] microblaze_v5: ptrace support monstr
2008-07-08 11:59 ` [PATCH 28/58] microblaze_v5: traps support monstr
2008-07-08 11:59 ` [PATCH 29/58] microblaze_v5: memory inicialization, MMU, TLB monstr
2008-07-08 11:59 ` [PATCH 30/58] microblaze_v5: page.h, segment.h, unaligned.h monstr
2008-07-08 11:59 ` [PATCH 31/58] microblaze_v5: includes SHM*, msgbuf monstr
2008-07-08 11:59 ` [PATCH 32/58] microblaze_v5: bug headers files monstr
2008-07-08 11:59 ` [PATCH 33/58] microblaze_v5: definitions of types monstr
2008-07-08 11:59 ` [PATCH 34/58] microblaze_v5: ioctl support monstr
2008-07-08 11:59 ` [PATCH 35/58] microblaze_v5: io.h IO operations monstr
2008-07-08 11:59 ` [PATCH 36/58] microblaze_v5: headers for executables format FLAT, ELF monstr
2008-07-08 11:59 ` [PATCH 37/58] microblaze_v5: dma support monstr
2008-07-08 11:59 ` [PATCH 38/58] microblaze_v5: headers for irq monstr
2008-07-08 11:59 ` [PATCH 39/58] microblaze_v5: atomic.h bitops.h byteorder.h monstr
2008-07-08 11:59 ` [PATCH 40/58] microblaze_v5: headers pgalloc.h pgtable.h monstr
2008-07-08 11:59 ` [PATCH 41/58] microblaze_v5: system.h pvr.h processor.h monstr
2008-07-08 11:59 ` [PATCH 42/58] microblaze_v5: clinkage.h linkage.h sections.h kmap_types.h monstr
2008-07-08 11:59 ` [PATCH 43/58] microblaze_v5: stats headers monstr
2008-07-08 11:59 ` [PATCH 44/58] microblaze_v5: termbits.h termios.h monstr
2008-07-08 11:59 ` [PATCH 45/58] microblaze_v5: sigcontext.h siginfo.h monstr
2008-07-08 11:59 ` [PATCH 46/58] microblaze_v5: headers simple files - empty or redirect to asm-generic monstr
2008-07-08 11:59 ` [PATCH 47/58] microblaze_v5: headers files entry.h current.h mman.h registers.h sembuf.h monstr
2008-07-08 11:59 ` [PATCH 48/58] microblaze_v5: device.h param.h topology.h monstr
2008-07-08 11:59 ` [PATCH 49/58] microblaze_v5: pool.h socket.h monstr
2008-07-08 11:59 ` [PATCH 50/58] microblaze_v5: generic files sockios.h ucontext.h monstr
2008-07-08 11:59 ` [PATCH 51/58] microblaze_v5: setup.h string.h thread_info.h monstr
2008-07-08 11:59 ` [PATCH 52/58] microblaze_v5: Kbuild file monstr
2008-07-08 11:59 ` [PATCH 53/58] microblaze_v5: pci headers monstr
2008-07-08 11:59 ` [PATCH 54/58] microblaze_v5: IPC headers monstr
2008-07-08 11:59 ` [PATCH 55/58] microblaze_v5: entry.S monstr
2008-07-08 11:59 ` [PATCH 56/58] microblaze_v5: sys_microblaze.c monstr
2008-07-08 11:59 ` [PATCH 57/58] microblaze_v5: syscall_table.S and unistd.h monstr
2008-07-08 11:59 ` [PATCH 58/58] microblaze_v5: Enable drivers for Microblaze monstr
2008-07-08 23:47 ` [PATCH 19/58] microblaze_v5: early_printk support John Williams
2008-07-08 19:43 ` microblaze_v5: Status message Michal Simek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c5f0730287365c845746467a9917dbc07d2fca3c.1215517976.git.monstr@monstr.eu \
--to=monstr@monstr.eu \
--cc=John.Linn@xilinx.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arnd@arndb.de \
--cc=drepper@redhat.com \
--cc=florian@openwrt.org \
--cc=grant.likely@secretlab.ca \
--cc=hpa@zytor.com \
--cc=john.williams@petalogix.com \
--cc=lethal@linux-sh.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew@wil.cx \
--cc=microblaze-uclinux@itee.uq.edu.au \
--cc=monstr@seznam.cz \
--cc=stephen.neuendorffer@xilinx.com \
--cc=vapier.adi@gmail.com \
--cc=will.newton@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).