diff options
author | Roland McGrath <roland@gnu.org> | 2002-05-29 08:34:41 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 2002-05-29 08:34:41 +0000 |
commit | 2a348a0bd593ff396a0aa5f0fc0ec3a80a2cc1c9 (patch) | |
tree | 090dc48cd0b53f58ac20d7ca6a7d4cd96e226e07 | |
parent | 6f0783f05f1ec037bea1619306aff367b7f50d47 (diff) |
2002-05-29 Roland McGrath <roland@frob.com>
* linux-src/arch/alpha/lib/csum_partial_copy.c: New file,
taken verbatim from Linux 2.2.14.
* Makefile (arch-lib-srcs): Add csum_partial_copy.c.
(LINUXSRCS): Match $(arch-lib-srcs) subset in arch/$(asm_syntax)/lib.
(OBJS): Use delayed evaluation.
* glue-include/asm/uaccess.h (__get_user): New macro.
(__m): New macro.
-rw-r--r-- | pfinet/Makefile | 9 | ||||
-rw-r--r-- | pfinet/glue-include/asm/uaccess.h | 6 | ||||
-rw-r--r-- | pfinet/linux-src/arch/alpha/lib/csum_partial_copy.c | 384 |
3 files changed, 396 insertions, 3 deletions
diff --git a/pfinet/Makefile b/pfinet/Makefile index 35e30baa..959af6b3 100644 --- a/pfinet/Makefile +++ b/pfinet/Makefile @@ -29,7 +29,7 @@ core-srcs := datagram.c \ skbuff.c \ sock.c \ utils.c -arch-lib-srcs := checksum.c old-checksum.c +arch-lib-srcs := checksum.c old-checksum.c csum_partial_copy.c ethernet-srcs := eth.c ipv4-srcs := af_inet.c \ arp.c \ @@ -58,14 +58,17 @@ ipv4-srcs := af_inet.c \ timer.c \ udp.c \ utils.c -LINUXSRCS = $(core-srcs) $(ethernet-srcs) $(ipv4-srcs) $(arch-lib-srcs) +LINUXSRCS = $(core-srcs) $(ethernet-srcs) $(ipv4-srcs) \ + $(notdir $(wildcard $(addprefix \ + $(srcdir)/linux-src/arch/$(asm_syntax)/lib/,\ + $(arch-lib-srcs)))) SRCS = sched.c timer-emul.c socket.c main.c ethernet.c \ io-ops.c socket-ops.c misc.c time.c options.c loopback.c \ kmem_cache.c stubs.c dummy.c tunnel.c pfinet-ops.c \ iioctl-ops.c MIGSRCS = ioServer.c socketServer.c startup_notifyServer.c \ pfinetServer.c iioctlServer.c -OBJS := $(patsubst %.c,%.o,$(LINUXSRCS) $(SRCS) $(MIGSRCS)) +OBJS = $(patsubst %.c,%.o,$(LINUXSRCS) $(SRCS) $(MIGSRCS)) LCLHDRS = config.h mapped-time.h mutations.h pfinet.h LINUXHDRS = arp.h datalink.h eth.h icmp.h ip.h ipx.h ipxcall.h p8022.h \ p8022call.h protocol.h psnap.h psnapcall.h \ diff --git a/pfinet/glue-include/asm/uaccess.h b/pfinet/glue-include/asm/uaccess.h index d8373797..6f6dc413 100644 --- a/pfinet/glue-include/asm/uaccess.h +++ b/pfinet/glue-include/asm/uaccess.h @@ -23,6 +23,12 @@ extern int __verify_write(const void *, unsigned long); #define put_user(x,ptr) (*(ptr) = (x), 0) #define get_user(x,ptr) ((x) = *(ptr), 0) +#define __get_user(x,ptr) get_user((x), (ptr)) + +/* This is used to constitute an arbitrarily-sized memory clobber in an asm. */ +struct __large_struct { unsigned long buf[100]; }; +#define __m(x) (*(struct __large_struct *)(x)) + /* * The "xxx_ret" versions return constant specified in third argument, if diff --git a/pfinet/linux-src/arch/alpha/lib/csum_partial_copy.c b/pfinet/linux-src/arch/alpha/lib/csum_partial_copy.c new file mode 100644 index 00000000..71308133 --- /dev/null +++ b/pfinet/linux-src/arch/alpha/lib/csum_partial_copy.c @@ -0,0 +1,384 @@ +/* + * csum_partial_copy - do IP checksumming and copy + * + * (C) Copyright 1996 Linus Torvalds + * + * Don't look at this too closely - you'll go mad. The things + * we do for performance.. + */ + +#include <linux/types.h> +#include <linux/string.h> +#include <asm/uaccess.h> + + +#define ldq_u(x,y) \ +__asm__ __volatile__("ldq_u %0,%1":"=r" (x):"m" (*(const unsigned long *)(y))) + +#define stq_u(x,y) \ +__asm__ __volatile__("stq_u %1,%0":"=m" (*(unsigned long *)(y)):"r" (x)) + +#define extql(x,y,z) \ +__asm__ __volatile__("extql %1,%2,%0":"=r" (z):"r" (x),"r" (y)) + +#define extqh(x,y,z) \ +__asm__ __volatile__("extqh %1,%2,%0":"=r" (z):"r" (x),"r" (y)) + +#define mskql(x,y,z) \ +__asm__ __volatile__("mskql %1,%2,%0":"=r" (z):"r" (x),"r" (y)) + +#define mskqh(x,y,z) \ +__asm__ __volatile__("mskqh %1,%2,%0":"=r" (z):"r" (x),"r" (y)) + +#define insql(x,y,z) \ +__asm__ __volatile__("insql %1,%2,%0":"=r" (z):"r" (x),"r" (y)) + +#define insqh(x,y,z) \ +__asm__ __volatile__("insqh %1,%2,%0":"=r" (z):"r" (x),"r" (y)) + + +#define __get_user_u(x,ptr) \ +({ \ + long __guu_err; \ + __asm__ __volatile__( \ + "1: ldq_u %0,%2\n" \ + "2:\n" \ + ".section __ex_table,\"a\"\n" \ + " .gprel32 1b\n" \ + " lda %0,2b-1b(%1)\n" \ + ".previous" \ + : "=r"(x), "=r"(__guu_err) \ + : "m"(__m(ptr)), "1"(0)); \ + __guu_err; \ +}) + +#define __put_user_u(x,ptr) \ +({ \ + long __puu_err; \ + __asm__ __volatile__( \ + "1: stq_u %2,%1\n" \ + "2:\n" \ + ".section __ex_table,\"a\"\n" \ + " .gprel32 1b" \ + " lda $31,2b-1b(%0)\n" \ + ".previous" \ + : "=r"(__puu_err) \ + : "m"(__m(addr)), "rJ"(x), "0"(0)); \ + __puu_err; \ +}) + + +/* + * Ok. This isn't fun, but this is the EASY case. + */ +static inline unsigned long +csum_partial_cfu_aligned(const unsigned long *src, unsigned long *dst, + long len, unsigned long checksum, + int *errp) +{ + unsigned long carry = 0; + int err = 0; + + while (len >= 0) { + unsigned long word; + err |= __get_user(word, src); + checksum += carry; + src++; + checksum += word; + len -= 8; + carry = checksum < word; + *dst = word; + dst++; + } + len += 8; + checksum += carry; + if (len) { + unsigned long word, tmp; + err |= __get_user(word, src); + tmp = *dst; + mskql(word, len, word); + checksum += word; + mskqh(tmp, len, tmp); + carry = checksum < word; + *dst = word | tmp; + checksum += carry; + } + if (err) *errp = err; + return checksum; +} + +/* + * This is even less fun, but this is still reasonably + * easy. + */ +static inline unsigned long +csum_partial_cfu_dest_aligned(const unsigned long *src, unsigned long *dst, + unsigned long soff, + long len, unsigned long checksum, + int *errp) +{ + unsigned long first; + unsigned long word, carry; + unsigned long lastsrc = 7+len+(unsigned long)src; + int err = 0; + + err |= __get_user_u(first,src); + carry = 0; + while (len >= 0) { + unsigned long second; + + err |= __get_user_u(second, src+1); + extql(first, soff, word); + len -= 8; + src++; + extqh(second, soff, first); + checksum += carry; + word |= first; + first = second; + checksum += word; + *dst = word; + dst++; + carry = checksum < word; + } + len += 8; + checksum += carry; + if (len) { + unsigned long tmp; + unsigned long second; + err |= __get_user_u(second, lastsrc); + tmp = *dst; + extql(first, soff, word); + extqh(second, soff, first); + word |= first; + mskql(word, len, word); + checksum += word; + mskqh(tmp, len, tmp); + carry = checksum < word; + *dst = word | tmp; + checksum += carry; + } + if (err) *errp = err; + return checksum; +} + +/* + * This is slightly less fun than the above.. + */ +static inline unsigned long +csum_partial_cfu_src_aligned(const unsigned long *src, unsigned long *dst, + unsigned long doff, + long len, unsigned long checksum, + unsigned long partial_dest, + int *errp) +{ + unsigned long carry = 0; + unsigned long word; + int err = 0; + + mskql(partial_dest, doff, partial_dest); + while (len >= 0) { + unsigned long second_dest; + err |= __get_user(word, src); + len -= 8; + insql(word, doff, second_dest); + checksum += carry; + stq_u(partial_dest | second_dest, dst); + src++; + checksum += word; + insqh(word, doff, partial_dest); + carry = checksum < word; + dst++; + } + len += doff; + checksum += carry; + if (len >= 0) { + unsigned long second_dest; + err |= __get_user(word, src); + mskql(word, len-doff, word); + checksum += word; + insql(word, doff, second_dest); + stq_u(partial_dest | second_dest, dst); + carry = checksum < word; + if (len) { + ldq_u(second_dest, dst+1); + insqh(word, doff, partial_dest); + mskqh(second_dest, len, second_dest); + stq_u(partial_dest | second_dest, dst+1); + } + checksum += carry; + } else if (len & 7) { + unsigned long second_dest; + err |= __get_user(word, src); + ldq_u(second_dest, dst); + mskql(word, len-doff, word); + checksum += word; + mskqh(second_dest, len, second_dest); + carry = checksum < word; + insql(word, doff, word); + stq_u(partial_dest | word | second_dest, dst); + checksum += carry; + } + if (err) *errp = err; + return checksum; +} + +/* + * This is so totally un-fun that it's frightening. Don't + * look at this too closely, you'll go blind. + */ +static inline unsigned long +csum_partial_cfu_unaligned(const unsigned long * src, unsigned long * dst, + unsigned long soff, unsigned long doff, + long len, unsigned long checksum, + unsigned long partial_dest, + int *errp) +{ + unsigned long carry = 0; + unsigned long first; + unsigned long lastsrc; + int err = 0; + + err |= __get_user_u(first, src); + lastsrc = 7+len+(unsigned long)src; + mskql(partial_dest, doff, partial_dest); + while (len >= 0) { + unsigned long second, word; + unsigned long second_dest; + + err |= __get_user_u(second, src+1); + extql(first, soff, word); + checksum += carry; + len -= 8; + extqh(second, soff, first); + src++; + word |= first; + first = second; + insql(word, doff, second_dest); + checksum += word; + stq_u(partial_dest | second_dest, dst); + carry = checksum < word; + insqh(word, doff, partial_dest); + dst++; + } + len += doff; + checksum += carry; + if (len >= 0) { + unsigned long second, word; + unsigned long second_dest; + + err |= __get_user_u(second, lastsrc); + extql(first, soff, word); + extqh(second, soff, first); + word |= first; + first = second; + mskql(word, len-doff, word); + checksum += word; + insql(word, doff, second_dest); + carry = checksum < word; + stq_u(partial_dest | second_dest, dst); + if (len) { + ldq_u(second_dest, dst+1); + insqh(word, doff, partial_dest); + mskqh(second_dest, len, second_dest); + stq_u(partial_dest | second_dest, dst+1); + } + checksum += carry; + } else if (len & 7) { + unsigned long second, word; + unsigned long second_dest; + + err |= __get_user_u(second, lastsrc); + extql(first, soff, word); + extqh(second, soff, first); + word |= first; + ldq_u(second_dest, dst); + mskql(word, len-doff, word); + checksum += word; + mskqh(second_dest, len, second_dest); + carry = checksum < word; + insql(word, doff, word); + stq_u(partial_dest | word | second_dest, dst); + checksum += carry; + } + if (err) *errp = err; + return checksum; +} + +static unsigned int +do_csum_partial_copy_from_user(const char *src, char *dst, int len, + unsigned int sum, int *errp) +{ + unsigned long checksum = (unsigned) sum; + unsigned long soff = 7 & (unsigned long) src; + unsigned long doff = 7 & (unsigned long) dst; + + if (len) { + if (!doff) { + if (!soff) + checksum = csum_partial_cfu_aligned( + (const unsigned long *) src, + (unsigned long *) dst, + len-8, checksum, errp); + else + checksum = csum_partial_cfu_dest_aligned( + (const unsigned long *) src, + (unsigned long *) dst, + soff, len-8, checksum, errp); + } else { + unsigned long partial_dest; + ldq_u(partial_dest, dst); + if (!soff) + checksum = csum_partial_cfu_src_aligned( + (const unsigned long *) src, + (unsigned long *) dst, + doff, len-8, checksum, + partial_dest, errp); + else + checksum = csum_partial_cfu_unaligned( + (const unsigned long *) src, + (unsigned long *) dst, + soff, doff, len-8, checksum, + partial_dest, errp); + } + /* 64 -> 33 bits */ + checksum = (checksum & 0xffffffff) + (checksum >> 32); + /* 33 -> < 32 bits */ + checksum = (checksum & 0xffff) + (checksum >> 16); + /* 32 -> 16 bits */ + checksum = (checksum & 0xffff) + (checksum >> 16); + checksum = (checksum & 0xffff) + (checksum >> 16); + } + return checksum; +} + +unsigned int +csum_partial_copy_from_user(const char *src, char *dst, int len, + unsigned int sum, int *errp) +{ + if (!access_ok(src, len, VERIFY_READ)) { + *errp = -EFAULT; + memset(dst, 0, len); + return sum; + } + + return do_csum_partial_copy_from_user(src, dst, len, sum, errp); +} + +unsigned int +csum_partial_copy_nocheck(const char *src, char *dst, int len, unsigned int sum) +{ + return do_csum_partial_copy_from_user(src, dst, len, sum, NULL); +} + +unsigned int +csum_partial_copy (const char *src, char *dst, int len, unsigned int sum) +{ + unsigned int ret; + int error = 0; + + ret = do_csum_partial_copy_from_user(src, dst, len, sum, &error); + if (error) + printk("csum_partial_copy_old(): tell mingo to convert me!\n"); + + return ret; +} |