Module Name:    src
Committed By:   phx
Date:           Sat Oct 27 21:13:03 UTC 2012

Modified Files:
        src/sys/arch/amiga/dev: if_ed_zbus.c

Log Message:
Fixed receiving of odd-length packets. Driver works now perfectly.
Thanks to Harald Meinzer for providing me with a Hydra for a few days.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/amiga/dev/if_ed_zbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amiga/dev/if_ed_zbus.c
diff -u src/sys/arch/amiga/dev/if_ed_zbus.c:1.1 src/sys/arch/amiga/dev/if_ed_zbus.c:1.2
--- src/sys/arch/amiga/dev/if_ed_zbus.c:1.1	Sun Oct 14 13:36:07 2012
+++ src/sys/arch/amiga/dev/if_ed_zbus.c	Sat Oct 27 21:13:03 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ed_zbus.c,v 1.1 2012/10/14 13:36:07 phx Exp $ */
+/*	$NetBSD: if_ed_zbus.c,v 1.2 2012/10/27 21:13:03 phx Exp $ */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ed_zbus.c,v 1.1 2012/10/14 13:36:07 phx Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ed_zbus.c,v 1.2 2012/10/27 21:13:03 phx Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -208,9 +208,10 @@ ed_zbus_test_mem(struct dp8390_softc *sc
 	bus_space_handle_t bufh = sc->sc_bufh;
 	int i;
 
-	bus_space_set_region_2(buft, bufh, sc->mem_start, 0, sc->mem_size >> 1);
+	bus_space_set_region_2(buft, bufh, sc->mem_start, 0,
+	    sc->mem_size >> 1);
 
-	for (i = 0; i < sc->mem_size >> 1; i += 2) {
+	for (i = 0; i < sc->mem_size; i += 2) {
 		if (bus_space_read_2(sc->sc_buft, sc->sc_bufh, i)) {
 			printf(": failed to clear NIC buffer at offset %x - "
 			    "check configuration\n", (sc->mem_start + i));
@@ -225,16 +226,16 @@ ed_zbus_read_hdr(struct dp8390_softc *sc
 {
 	bus_space_tag_t buft = sc->sc_buft;
 	bus_space_handle_t bufh = sc->sc_bufh;
-	uint16_t wrd;
+	uint16_t wrd[2];
 
 	/*
 	 * Read the 4-byte header as two 16-bit words in little-endian
 	 * format. Convert into big-endian and put them into hdrp.
 	 */
-	wrd = bus_space_read_2(buft, bufh, src);
-	hdrp->rsr = wrd & 0xff;
-	hdrp->next_packet = wrd >> 8;
-	hdrp->count = bswap16(bus_space_read_2(buft, bufh, src + 2));
+	bus_space_read_region_stream_2(buft, bufh, src, wrd, 2);
+	hdrp->rsr = wrd[0] & 0xff;
+	hdrp->next_packet = wrd[0] >> 8;
+	hdrp->count = bswap16(wrd[1]);
 }
 
 /*
@@ -248,19 +249,30 @@ ed_zbus_ring_copy(struct dp8390_softc *s
 	bus_space_tag_t buft = sc->sc_buft;
 	bus_space_handle_t bufh = sc->sc_bufh;
 	u_short tmp_amount;
+	u_char readbyte[2];
 
 	/* Does copy wrap to lower addr in ring buffer? */
 	if (src + amount > sc->mem_end) {
 		tmp_amount = sc->mem_end - src;
 
-		/* Copy amount up to end of NIC memory. */
-		bus_space_read_region_2(buft, bufh, src, dst, tmp_amount >> 1);
+		/* copy amount up to end of NIC memory */
+		bus_space_read_region_stream_2(buft, bufh, src, dst,
+		    tmp_amount >> 1);
 
 		amount -= tmp_amount;
 		src = sc->mem_ring;
-		dst = (char *)dst + tmp_amount;
+		dst = (u_char *)dst + tmp_amount;
+	}
+
+	bus_space_read_region_stream_2(buft, bufh, src, dst, amount >> 1);
+
+	/* handle odd length packet */
+	if (amount & 1) {
+		bus_space_read_region_stream_2(buft, bufh, src + amount - 1,
+		    (u_int16_t *)readbyte, 1);
+		*((u_char *)dst + amount - 1) = readbyte[0];
+		amount++;
 	}
-	bus_space_read_region_2(buft, bufh, src, dst, amount >> 1);
 
 	return src + amount;
 }
@@ -287,8 +299,9 @@ ed_zbus_write_mbuf(struct dp8390_softc *
 			/* Finish the last word. */
 			if (wantbyte) {
 				savebyte[1] = *data;
-				bus_space_write_region_2(sc->sc_buft,
-				    sc->sc_bufh, buf, (u_int16_t *)savebyte, 1);
+				bus_space_write_region_stream_2(sc->sc_buft,
+				    sc->sc_bufh, buf,
+				    (u_int16_t *)savebyte, 1);
 				buf += 2;
 				data++;
 				len--;
@@ -296,9 +309,9 @@ ed_zbus_write_mbuf(struct dp8390_softc *
 			}
 			/* Output contiguous words. */
 			if (len > 1) {
-				bus_space_write_region_2(
-				    sc->sc_buft, sc->sc_bufh,
-				    buf, (u_int16_t *)data, len >> 1);
+				bus_space_write_region_stream_2(sc->sc_buft,
+				    sc->sc_bufh, buf,
+				    (u_int16_t *)data, len >> 1);
 				buf += len & ~1;
 				data += len & ~1;
 				len &= 1;
@@ -314,7 +327,7 @@ ed_zbus_write_mbuf(struct dp8390_softc *
 	len = ETHER_PAD_LEN - totlen;
 	if (wantbyte) {
 		savebyte[1] = 0;
-		bus_space_write_region_2(sc->sc_buft, sc->sc_bufh,
+		bus_space_write_region_stream_2(sc->sc_buft, sc->sc_bufh,
 		    buf, (u_int16_t *)savebyte, 1);
 		buf += 2;
 		totlen++;

Reply via email to