summaryrefslogtreecommitdiffstats
path: root/arch/ppc/lib
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>1997-01-07 02:33:00 +0000
committer <ralf@linux-mips.org>1997-01-07 02:33:00 +0000
commitbeb116954b9b7f3bb56412b2494b562f02b864b1 (patch)
tree120e997879884e1b9d93b265221b939d2ef1ade1 /arch/ppc/lib
parent908d4681a1dc3792ecafbe64265783a86c4cccb6 (diff)
Import of Linux/MIPS 2.1.14
Diffstat (limited to 'arch/ppc/lib')
-rw-r--r--arch/ppc/lib/Makefile11
-rw-r--r--arch/ppc/lib/checksum.c136
-rw-r--r--arch/ppc/lib/cksum_support.S125
3 files changed, 272 insertions, 0 deletions
diff --git a/arch/ppc/lib/Makefile b/arch/ppc/lib/Makefile
new file mode 100644
index 000000000..d94420c4a
--- /dev/null
+++ b/arch/ppc/lib/Makefile
@@ -0,0 +1,11 @@
+#
+# Makefile for i386-specific library files..
+#
+
+L_TARGET = lib.o
+L_OBJS = checksum.o cksum_support.o
+
+${L_TARGET}: $(L_OBJS)
+ $(LD) -r -o ${L_TARGET} $(L_OBJS)
+
+fastdep:
diff --git a/arch/ppc/lib/checksum.c b/arch/ppc/lib/checksum.c
new file mode 100644
index 000000000..0e0a37ea0
--- /dev/null
+++ b/arch/ppc/lib/checksum.c
@@ -0,0 +1,136 @@
+/*
+ * 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>
+ * Lots of code moved from tcp.c and ip.c; see those files
+ * for more names.
+ *
+ * Adapted for PowerPC by Gary Thomas <gdt@mc.com>
+ *
+ * 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.
+ */
+
+#include <net/checksum.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)
+{
+ unsigned long result = ~_csum_partial(buff, len, sum);
+#if 0
+printk("Csum partial(%x, %d, %x) = %x\n", buff, len, sum, result);
+dump_buf(buff, len);
+#endif
+ return result;
+}
+
+/*
+ * 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 boundary
+ */
+
+unsigned int csum_partial_copy(const char *src, char *dst, int len, int sum)
+{
+ /*
+ * The whole idea is to do the copy and the checksum at
+ * the same time, but we do it the easy way now.
+ *
+ * At least csum on the source, not destination, for cache
+ * reasons..
+ */
+ sum = csum_partial(src, len, sum);
+ memcpy(dst, src, len);
+ return sum;
+}
+
+extern unsigned short _ip_fast_csum(unsigned char *buf);
+
+unsigned short
+ip_fast_csum(unsigned char *buf, unsigned int len)
+{
+ unsigned short _val;
+ _val = _ip_fast_csum(buf);
+#if 0
+ printk("IP CKSUM(%x, %d) = %x\n", buf, len, _val);
+ dump_buf(buf, len*4);
+#endif
+ return (_val);
+}
+
+extern unsigned short _ip_compute_csum(unsigned char *buf, int len);
+
+unsigned short
+ip_compute_csum(unsigned char *buf, int len)
+{
+ unsigned short _val;
+ _val = _ip_compute_csum(buf, len);
+#if 0
+ printk("Compute IP CKSUM(%x, %d) = %x\n", buf, len, _val);
+ dump_buf(buf, len);
+#endif
+ return (_val);
+}
+
+unsigned short
+_udp_check(unsigned char *buf, int len, int saddr, int daddr, int hdr);
+
+unsigned short
+udp_check(unsigned char *buf, int len, int saddr, int daddr)
+{
+ unsigned short _val;
+ int hdr;
+ hdr = (len << 16) + IPPROTO_UDP;
+ _val = _udp_check(buf, len, saddr, daddr, hdr);
+#if 0
+ printk("UDP CSUM(%x,%d,%x,%x) = %x\n", buf, len, saddr, daddr, _val);
+ dump_buf(buf, len);
+#endif
+ return (_val);
+}
+
+unsigned short
+_tcp_check(unsigned char *buf, int len, int saddr, int daddr, int hdr);
+
+unsigned short
+csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len, unsigned short proto, unsigned int sum)
+{
+ unsigned short _val;
+ _val = _csum_tcpudp_magic(saddr, daddr, sum, (len<<16)+proto);
+#if 0
+ printk("TCP Magic(%x, %x, %x, %x) = %x\n", saddr, daddr, (len<<16)+proto, sum, _val);
+#endif
+ return (_val);
+}
+
+/*
+ * Fold a partial checksum without adding pseudo headers
+ */
+
+unsigned short csum_fold(unsigned int sum)
+{
+ sum = (sum & 0xffff) + (sum >> 16);
+ sum = (sum & 0xffff) + (sum >> 16);
+ return ~sum;
+}
+
diff --git a/arch/ppc/lib/cksum_support.S b/arch/ppc/lib/cksum_support.S
new file mode 100644
index 000000000..264d5a6fb
--- /dev/null
+++ b/arch/ppc/lib/cksum_support.S
@@ -0,0 +1,125 @@
+/*
+ * This module contains the PowerPC interrupt fielders
+ * set of code at specific locations, based on function
+ */
+
+#include <linux/sys.h>
+#include "../kernel/ppc_asm.tmpl"
+
+_TEXT()
+
+/*
+ * Compute IP checksums
+ * _ip_fast_csum(buf, len) -- Optimized for IP header
+ * _ip_compute_csum(buf, len)
+ */
+
+_GLOBAL(_ip_fast_csum)
+ li r0,0
+ addic r0,r0,0 /* Clear initial carry */
+ lwz r4,0(r3)
+ lwz r5,4(r3)
+ adde r0,r0,r4
+ lwz r4,8(r3)
+ adde r0,r0,r5
+ lwz r5,12(r3)
+ adde r0,r0,r4
+ lwz r4,16(r3)
+ adde r0,r0,r5
+ adde r0,r0,r4
+ mr r3,r0
+ andi. r3,r3,0xFFFF
+ srwi r0,r0,16
+ adde r3,r3,r0
+ andis. r0,r3,1
+ beq 10f
+ addi r3,r3,1
+10: not r3,r3
+ andi. r3,r3,0xFFFF
+ blr
+
+_GLOBAL(_ip_compute_csum)
+ li r0,0
+ addic r0,r0,0
+finish_ip_csum:
+ subi r3,r3,4
+ andi. r5,r3,2 /* Align buffer to longword boundary */
+ beq 10f
+ lhz r5,4(r3)
+ adde r0,r0,r5
+ addi r3,r3,2
+ subi r4,r4,2
+10: cmpi 0,r4,16 /* unrolled loop - 16 bytes at a time */
+ blt 20f
+ lwz r5,4(r3)
+ lwz r6,8(r3)
+ adde r0,r0,r5
+ lwz r5,12(r3)
+ adde r0,r0,r6
+ lwzu r6,16(r3)
+ adde r0,r0,r5
+ adde r0,r0,r6
+ subi r4,r4,16
+ b 10b
+20: cmpi 0,r4,4
+ blt 30f
+ lwzu r5,4(r3)
+ adde r0,r0,r5
+ subi r4,r4,4
+ b 20b
+30: cmpi 0,r4,2
+ blt 40f
+ lhz r5,4(r3)
+ addi r3,r3,2
+ adde r0,r0,r5
+ subi r4,r4,2
+40: cmpi 0,r4,1
+ bne 50f
+ lbz r5,4(r3)
+ slwi r5,r5,8 /* Upper byte of word */
+ adde r0,r0,r5
+50: mr r3,r0
+ andi. r3,r3,0xFFFF
+ srwi r0,r0,16
+ adde r3,r3,r0
+ andis. r0,r3,1
+ beq 60f
+ addi r3,r3,1
+60: not r3,r3
+ andi. r3,r3,0xFFFF
+ blr
+
+_GLOBAL(_udp_check)
+ addc r0,r5,r6 /* Add in header fields */
+ adde r0,r0,r7
+ b finish_ip_csum
+
+_GLOBAL(_tcp_check)
+ addc r0,r5,r6 /* Add in header fields */
+ adde r0,r0,r7
+ b finish_ip_csum
+
+_GLOBAL(_csum_partial)
+ li r0,0
+ addc r0,r5,r0
+ b finish_ip_csum
+
+/*
+ * Compute 16 bit sum:
+ * _csum_tcpudp_magic(int saddr, int daddr, int sum, int proto)
+ */
+_GLOBAL(_csum_tcpudp_magic)
+ addc r0,r3,r4
+ adde r0,r0,r5
+ adde r0,r0,r6
+ mr r3,r0
+ andi. r3,r3,0xFFFF
+ srwi r0,r0,16
+ adde r3,r3,r0
+ andis. r0,r3,1 /* Carry out of 16 bits? */
+ beq 10f
+ addi r3,r3,1
+10: not r3,r3
+ andi. r3,r3,0xFFFF
+ blr
+