NetBSD Problem Report #8001

Received: (qmail 23080 invoked from network); 15 Jul 1999 05:14:03 -0000
Message-Id: <199907150513.AAA09710@marvin.ece.utexas.edu>
Date: Thu, 15 Jul 1999 00:13:56 -0500 (CDT)
From: bgrayson@ece.utexas.edu
Reply-To: bgrayson@ece.utexas.edu
To: gnats-bugs@gnats.netbsd.org
Subject: ix* w/ 16KB unhappy
X-Send-Pr-Version: 3.95

>Number:         8001
>Category:       kern
>Synopsis:       ix* w/ 16KB unhappy
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bjh21
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 14 22:20:01 +0000 1999
>Closed-Date:    Thu Mar 22 23:11:53 +0000 2001
>Last-Modified:  Thu Mar 22 23:11:53 +0000 2001
>Originator:     Brian Grayson
>Release:        Jul 13, 1999
>Organization:
	Parallel and Distributed Systems
	Electrical and Computer Engineering
	The University of Texas at Austin
>Environment:
	NetBSD k9.ece.utexas.edu 1.4F NetBSD 1.4F (K93) #16: Wed Jul 14 20:53:52 CDT 1999 bgrayson@marvin:/usr/src/sys/arch/i386/compile/K93 i386


>Description:
	If an ix* card (EtherExpress 16) is configured for 16KB
	of buffer, the kernel prints out zillions of spurious
	interrupt messages.

	Here's the relevant lines from my config, followed by my
	dmesg from after I set the card to 32KB:
ix0     at isa? port 0x300 irq 10               # EtherExpress/16
ix1     at isa? port 0x310 irq 11               # EtherExpress/16

Jul 14 22:10:41 k9 /netbsd: NetBSD 1.4F (K93) #16: Wed Jul 14 20:53:52 CDT 1999
Jul 14 22:10:41 k9 /netbsd:     bgrayson@marvin:/usr/src/sys/arch/i386/compile/K93
Jul 14 22:10:41 k9 /netbsd: cpu0: family 5 model 2 step 2
Jul 14 22:10:41 k9 /netbsd: cpu0: Intel Pentium (P54C) (586-class)
Jul 14 22:10:41 k9 /netbsd: total memory = 32384 KB
Jul 14 22:10:41 k9 /netbsd: avail memory = 27712 KB
Jul 14 22:10:41 k9 /netbsd: using 430 buffers containing 1720 KB of memory
Jul 14 22:10:41 k9 /netbsd: mainbus0 (root)
Jul 14 22:10:41 k9 /netbsd: pci0 at mainbus0 bus 0: configuration mode 1
Jul 14 22:10:41 k9 /netbsd: pci0: i/o enabled, memory enabled
Jul 14 22:10:41 k9 /netbsd: pchb0 at pci0 dev 0 function 0
Jul 14 22:10:41 k9 /netbsd: pchb0: Acer Labs M1531 Host-PCI Bridge (rev. 0xb2)
Jul 14 22:10:41 k9 /netbsd: pcib0 at pci0 dev 2 function 0
Jul 14 22:10:41 k9 /netbsd: pcib0: Acer Labs M1543 PCI-ISA Bridge (rev. 0xb4)
Jul 14 22:10:41 k9 /netbsd: S3 Trio64V2/DX (VGA display, revision 0x14) at pci0 dev 5 function 0 not configured
Jul 14 22:10:41 k9 /netbsd: pciide0 at pci0 dev 11 function 0: Acer Labs M5229 UDMA IDE Controller
Jul 14 22:10:42 k9 /netbsd: pciide0: bus-master DMA support present
Jul 14 22:10:42 k9 /netbsd: pciide0: primary channel configured to compatibility mode
Jul 14 22:10:42 k9 /netbsd: wd0 at pciide0 channel 0 drive 0: <QUANTUM BIGFOOT_CY4320A>
Jul 14 22:10:42 k9 /netbsd: wd0: drive supports 32-sector pio transfers, lba addressing
Jul 14 22:10:42 k9 /netbsd: wd0: 4134MB, 8960 cyl, 15 head, 63 sec, 512 bytes/sect x 8467200 sectors
Jul 14 22:10:42 k9 /netbsd: wd0: 32-bits data port
Jul 14 22:10:42 k9 /netbsd: wd0: drive supports PIO mode 4, DMA mode 2
Jul 14 22:10:42 k9 /netbsd: pciide0: primary channel interrupting at irq 14
Jul 14 22:10:42 k9 /netbsd: pciide0: secondary channel configured to compatibility mode
Jul 14 22:10:42 k9 /netbsd: pciide0: disabling secondary channel (no drives)
Jul 14 22:10:42 k9 /netbsd: wd0(pciide0:0:0): using PIO mode 4, DMA mode 2 (using DMA data transfers)
Jul 14 22:10:42 k9 /netbsd: isa0 at pcib0
Jul 14 22:10:42 k9 /netbsd: com0 at isa0 port 0x3f8-0x3ff irq 4: ns8250 or ns16450, no fifo
Jul 14 22:10:42 k9 /netbsd: com1 at isa0 port 0x2f8-0x2ff irq 3: ns16550a, working fifo
Jul 14 22:10:42 k9 /netbsd: lpt0 at isa0 port 0x378-0x37b irq 7
Jul 14 22:10:42 k9 /netbsd: ix0 at isa0 port 0x300-0x30f iomem 0xd8000-0xdffff irq 10 address 00:aa:00:64:47:c6, type EtherExpress/16
Jul 14 22:10:42 k9 /netbsd: ix1 at isa0 port 0x310-0x31f iomem 0xd0000-0xd7fff irq 11 address 00:aa:00:57:c7:c0, type EtherExpress/16
Jul 14 22:10:42 k9 /netbsd: pcppi0 at isa0 port 0x61
Jul 14 22:10:42 k9 /netbsd: sysbeep0 at pcppi0
Jul 14 22:10:42 k9 /netbsd: isapnp0 at isa0 port 0x279: ISA Plug 'n Play device support
Jul 14 22:10:42 k9 /netbsd: npx0 at isa0 port 0xf0-0xff: using exception 16
Jul 14 22:10:42 k9 /netbsd: WARNING: Pentium FDIV bug detected!
Jul 14 22:10:42 k9 /netbsd: vt0 at isa0 port 0x60-0x6f irq 1
Jul 14 22:10:42 k9 /netbsd: vt0: unknown s3, 80 col, color, 8 scr, mf2-kbd, [R3.32]
Jul 14 22:10:42 k9 /netbsd: vt0: console
Jul 14 22:10:42 k9 /netbsd: fdc0 at isa0 port 0x3f0-0x3f7 irq 6 drq 2
Jul 14 22:10:42 k9 /netbsd: fd0 at fdc0 drive 0: 1.44MB, 80 cyl, 2 head, 18 sec
Jul 14 22:10:42 k9 /netbsd: isapnp0: no ISA Plug 'n Play devices found
Jul 14 22:10:42 k9 /netbsd: biomask 4040 netmask 4c40 ttymask 4cc2
Jul 14 22:10:43 k9 /netbsd: boot device: wd0
Jul 14 22:10:43 k9 /netbsd: root on wd0a dumps on wd0b
Jul 14 22:10:43 k9 /netbsd: root file system type: ffs
Jul 14 22:10:43 k9 /netbsd: IP Filter: initialized.  Default = pass all, Logging = disabled

>How-To-Repeat:
	Accidentally forget to set the card to 32KB, and boot
	using a modern kernel.  Watch the screen scroll by with
	somewhere around 10,000 spurious interrupts per second,
	and the machine be completely unresponsive.

	Besides fixing the cause for spurious interrupts,
	would this be a good job for exponentially-backed-off
	warnings?  A la:
ix0: i82586_intr: 1 spurious interrupts
ix0: i82586_intr: 2 spurious interrupts
ix0: i82586_intr: 4 spurious interrupts
ix0: i82586_intr: 8 spurious interrupts
ix0: i82586_intr: 16 spurious interrupts
ix0: i82586_intr: 32 spurious interrupts
ix0: i82586_intr: 64 spurious interrupts
ix0: i82586_intr: 128 spurious interrupts
...

>Fix:
	???  Jason?  :)
>Release-Note:
>Audit-Trail:

From: Rafal Boni <rafal@mediaone.net>
To: bgrayson@ece.utexas.edu
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/8001: ix* w/ 16KB unhappy 
Date: Wed, 11 Aug 1999 23:41:17 -0400

 -> 	If an ix* card (EtherExpress 16) is configured for 16KB
 -> 	of buffer, the kernel prints out zillions of spurious
 -> 	interrupt messages.

 I've seen this happen on my EE/16, but haven't had the time to sit
 down and fix it.  There seems to be a problem with the way the EE/16
 maps in memory if you set it to 16K, but I haven't dug further.

 As I have no docs for the cards other than the Linux driver and/or
 the packet drivers, it looks like for 16K mappings the driver will
 need to use PIO to talk to the card.

 [..Can we make the spurious interrupt messages back off...]
 -> ix0: i82586_intr: 1 spurious interrupts
 -> ix0: i82586_intr: 2 spurious interrupts
 [...]

 If I recall correctly, eariler versions of the 82586 driver did something 
 like this.  Now, it just logs once every 25 or so spurious interrupts on 
 the theory that if you're getting more than that in rapid succession, 
 something is *really* wrong with the card.

 If I get some time (and after I finish the fdisk hacks I promised Perry
 I'd have done before I left on vacation in mid-July), I'll try and have
 a whack at this.

 --rafal

 ----
 Rafal Boni                                                  rafal@mediaone.net

From: Rafal Boni <rafal@mediaone.net>
To: gnats-bugs@gnats.netbsd.org
Cc:  Subject: Re: kern/8001: ix* w/ 16KB unhappy 
Date: Sun, 19 Sep 1999 20:44:37 -0400

 Patches that work around the problem follow.  The MI 82586 driver and all
 front ends that use it have been slightly tweaked, as the MI driver to front-
 end interface has changed as a result of this fix.

 This has been tested on the x86 on an ix card with 16K and 32K of memory as
 well as on a 3Com 3C507 (if_ef, which also uses the MI 82586 driver core).

 --rafal

 Index: arch/mvme68k/dev/if_ie.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/arch/mvme68k/dev/if_ie.c,v
 retrieving revision 1.3
 diff -b -u -r1.3 if_ie.c
 --- if_ie.c	1999/07/08 18:08:55	1.3
 +++ if_ie.c	1999/09/19 04:17:48
 @@ -245,6 +245,9 @@
  	sc->intrhook = ie_intrhook;
  	sc->memcopyin = ie_copyin;
  	sc->memcopyout = ie_copyout;
 +	sc->ie_bus_read8 = NULL;
 +	sc->ie_bus_write8 = NULL;
 +	sc->ie_bus_barrier = NULL;
  	sc->ie_bus_read16 = ie_read_16;
  	sc->ie_bus_write16 = ie_write_16;
  	sc->ie_bus_write24 = ie_write_24;
 Index: arch/sparc/dev/if_ie_obio.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/arch/sparc/dev/if_ie_obio.c,v
 retrieving revision 1.11
 diff -b -u -r1.11 if_ie_obio.c
 --- if_ie_obio.c	1999/07/08 18:08:58	1.11
 +++ if_ie_obio.c	1999/09/19 04:17:48
 @@ -296,6 +296,11 @@
  	sc->hwinit = ie_obrun;
  	sc->memcopyout = ie_obio_memcopyout;
  	sc->memcopyin = ie_obio_memcopyin;
 +
 +	sc->ie_bus_read8 = NULL;
 +	sc->ie_bus_write8 = NULL;
 +	sc->ie_bus_barrier = NULL;
 +
  	sc->ie_bus_read16 = ie_obio_read16;
  	sc->ie_bus_write16 = ie_obio_write16;
  	sc->ie_bus_write24 = ie_obio_write24;
 Index: dev/isa/if_ai.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/isa/if_ai.c,v
 retrieving revision 1.7
 diff -b -u -r1.7 if_ai.c
 --- if_ai.c	1999/01/08 19:22:35	1.7
 +++ if_ai.c	1999/09/19 04:17:53
 @@ -350,6 +350,10 @@
  	sc->hwreset = ai_reset;
  	sc->chan_attn = ai_atten;

 +	sc->ie_bus_read8 = NULL;
 +	sc->ie_bus_write8 = NULL;
 +	sc->ie_bus_barrier = NULL;
 +
  	sc->memcopyin = ai_copyin;
  	sc->memcopyout = ai_copyout;
  	sc->ie_bus_read16 = ai_read_16;
 Index: dev/isa/if_ef.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/isa/if_ef.c,v
 retrieving revision 1.6
 diff -b -u -r1.6 if_ef.c
 --- if_ef.c	1999/01/08 19:22:36	1.6
 +++ if_ef.c	1999/09/19 04:20:18
 @@ -505,6 +505,10 @@
  	sc->chan_attn = ef_atten;
  	sc->intrhook = ef_intrhook;

 +	sc->ie_bus_read8 = NULL;
 +	sc->ie_bus_write8 = NULL;
 +	sc->ie_bus_barrier = NULL;
 +
  	sc->memcopyin = ef_copyin;
  	sc->memcopyout = ef_copyout;
  	sc->ie_bus_read16 = ef_read_16;
 Index: dev/isa/if_ix.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/isa/if_ix.c,v
 retrieving revision 1.6
 diff -b -u -r1.6 if_ix.c
 --- if_ix.c	1999/01/08 19:22:36	1.6
 +++ if_ix.c	1999/09/19 04:22:26
 @@ -36,6 +36,8 @@
   * POSSIBILITY OF SUCH DAMAGE.
   */

 +#include "opt_ddb.h"
 +
  #include <sys/param.h>
  #include <sys/systm.h>
  #include <sys/mbuf.h>
 @@ -69,6 +71,10 @@
  #define DPRINTF(x)
  #endif

 +#ifndef	DDB
 +#define Debugger() panic("should call debugger here (if_ix.c)")
 +#endif /* ! DDB */
 +
  int ix_media[] = {
  	IFM_ETHER | IFM_10_5,
  	IFM_ETHER | IFM_10_2,
 @@ -82,6 +88,7 @@
  	bus_space_tag_t sc_regt;	/* space tag for registers */
  	bus_space_handle_t sc_regh;	/* space handle for registers */

 +	u_int8_t	use_pio;	/* use PIO rather than shared mem */
  	u_int16_t	irq_encoded;	/* encoded IRQ */
  	void		*sc_ih;		/* interrupt handle */
  };
 @@ -93,9 +100,14 @@
  static void     ix_copyin __P((struct ie_softc *, void *, int, size_t));
  static void     ix_copyout __P((struct ie_softc *, const void *, int, size_t));

 +static void	ix_bus_barrier __P((struct ie_softc *, int, int, int));
 +
 +static u_int8_t ix_read_8 __P((struct ie_softc *, int));
 +static void	ix_write_8 __P((struct ie_softc *, int, u_int8_t));
  static u_int16_t ix_read_16 __P((struct ie_softc *, int));
  static void	ix_write_16 __P((struct ie_softc *, int, u_int16_t));
  static void	ix_write_24 __P((struct ie_softc *, int, int));
 +static void	ix_zeromem  __P((struct ie_softc *, int, int));

  static void	ix_mediastatus __P((struct ie_softc *, struct ifmediareq *));

 @@ -258,24 +270,51 @@
          int offset;
          size_t size;
  {
 -	int dribble;
 +	int i, dribble;
  	u_int8_t* bptr = dst;
 +	u_int16_t* wptr = dst;
 +	struct ix_softc* isc = (struct ix_softc *) sc;

 +	if (isc->use_pio) {
 +		/* Reset read pointer to the specified offset */
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2,
 +						  BUS_SPACE_BARRIER_READ);
 +		bus_space_write_2(sc->bt, sc->bh, IX_READPTR, offset);
 +		bus_space_barrier(sc->bt, sc->bh, IX_READPTR, 2,
 +						  BUS_SPACE_BARRIER_WRITE);
 +	} else {
  	bus_space_barrier(sc->bt, sc->bh, offset, size,
  			  BUS_SPACE_BARRIER_READ);
 +	}

  	if (offset % 2) {
 +		if (isc->use_pio)
 +			*bptr = bus_space_read_1(sc->bt, sc->bh, IX_DATAPORT);
 +		else
  		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
  		offset++; bptr++; size--;
  	}

  	dribble = size % 2;
 -	bus_space_read_region_2(sc->bt, sc->bh, offset, (u_int16_t *) bptr,
 -				size >> 1);
 +	wptr = (u_int16_t*) bptr;
 +
 +	if (isc->use_pio) {
 +		for(i = 0; i <  size / 2; i++) {
 +			*wptr = bus_space_read_2(sc->bt, sc->bh, IX_DATAPORT);
 +			wptr++;
 +		}
 +	} else {
 +		bus_space_read_region_2(sc->bt, sc->bh, offset, 
 +					(u_int16_t *) bptr, size / 2);
 +	}

  	if (dribble) {
  		bptr += size - 1;
  		offset += size - 1;
 +
 +		if (isc->use_pio)
 +			*bptr = bus_space_read_1(sc->bt, sc->bh, IX_DATAPORT);
 +		else
  		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
  	}
  }
 @@ -287,36 +326,142 @@
          int offset;
          size_t size;
  {
 -	int dribble;
 +	int i, dribble;
  	int osize = size;
  	int ooffset = offset;
  	const u_int8_t* bptr = src;
 +	const u_int16_t* wptr = src;
 +	struct ix_softc* isc = (struct ix_softc *) sc;
 +
 +	if (isc->use_pio) {
 +		/* Reset write pointer to the specified offset */
 +		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, offset);
 +		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	}

  	if (offset % 2) {
 +		if (isc->use_pio)
 +			bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, *bptr);
 +		else
  		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
  		offset++; bptr++; size--;
  	}

  	dribble = size % 2;
 -	bus_space_write_region_2(sc->bt, sc->bh, offset, (u_int16_t *)bptr,
 -				 size >> 1);
 +	wptr = (u_int16_t*) bptr;
 +
 +	if (isc->use_pio) {
 +		for(i = 0; i < size / 2; i++) {
 +			bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT, *wptr);
 +			wptr++;
 +		}
 +	} else {
 +		bus_space_write_region_2(sc->bt, sc->bh, offset, 
 +					 (u_int16_t *)bptr, size / 2);
 +	}
 +
  	if (dribble) {
  		bptr += size - 1;
  		offset += size - 1;
 +
 +		if (isc->use_pio)
 +			bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, *bptr);
 +		else
  		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
  	}

 +	if (isc->use_pio)
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	else
  	bus_space_barrier(sc->bt, sc->bh, ooffset, osize,
  			  BUS_SPACE_BARRIER_WRITE);
  }

 +static void
 +ix_bus_barrier(sc, offset, length, flags)
 +        struct ie_softc *sc;
 +        int offset, length, flags;
 +{
 +	struct ix_softc* isc = (struct ix_softc *) sc;
 +
 +	if (isc->use_pio)
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2, flags);
 +	else
 +		bus_space_barrier(sc->bt, sc->bh, offset, length, flags);
 +}
 +
 +static u_int8_t
 +ix_read_8 (sc, offset)
 +        struct ie_softc *sc;
 +        int offset;
 +{
 +	struct ix_softc* isc = (struct ix_softc *) sc;
 +
 +	if (isc->use_pio) {
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 1,
 +						  BUS_SPACE_BARRIER_READ);
 +
 +		/* Reset read pointer to the specified offset */
 +		bus_space_write_2(sc->bt, sc->bh, IX_READPTR, offset);
 +		bus_space_barrier(sc->bt, sc->bh, IX_READPTR, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +
 +		return bus_space_read_1(sc->bt, sc->bh, IX_DATAPORT);
 +	} else {
 +		bus_space_barrier(sc->bt, sc->bh, offset, 1, 
 +						  BUS_SPACE_BARRIER_READ);
 +        	return bus_space_read_1(sc->bt, sc->bh, offset);
 +	}
 +}
 +
 +static void
 +ix_write_8 (sc, offset, value)
 +        struct ie_softc *sc;
 +        int offset;
 +        u_int8_t value;
 +{
 +	struct ix_softc* isc = (struct ix_softc *) sc;
 +
 +	if (isc->use_pio) {
 +		/* Reset write pointer to the specified offset */
 +		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, offset);
 +		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +
 +		bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, value);
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 1, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	} else {
 +        	bus_space_write_1(sc->bt, sc->bh, offset, value);
 +		bus_space_barrier(sc->bt, sc->bh, offset, 1, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	}
 +}
 +
  static u_int16_t
  ix_read_16 (sc, offset)
          struct ie_softc *sc;
          int offset;
  {
 -	bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_READ);
 +	struct ix_softc* isc = (struct ix_softc *) sc;
 +
 +	if (isc->use_pio) {
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2,
 +						  BUS_SPACE_BARRIER_READ);
 +
 +		/* Reset read pointer to the specified offset */
 +		bus_space_write_2(sc->bt, sc->bh, IX_READPTR, offset);
 +		bus_space_barrier(sc->bt, sc->bh, IX_READPTR, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +
 +		return bus_space_read_2(sc->bt, sc->bh, IX_DATAPORT);
 +	} else {
 +		bus_space_barrier(sc->bt, sc->bh, offset, 2, 
 +						  BUS_SPACE_BARRIER_READ);
          return bus_space_read_2(sc->bt, sc->bh, offset);
 +	}
  }

  static void
 @@ -325,8 +470,22 @@
          int offset;
          u_int16_t value;
  {
 +	struct ix_softc* isc = (struct ix_softc *) sc;
 +
 +	if (isc->use_pio) {
 +		/* Reset write pointer to the specified offset */
 +		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, offset);
 +		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +
 +		bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT, value);
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	} else {
          bus_space_write_2(sc->bt, sc->bh, offset, value);
 -	bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_WRITE);
 +		bus_space_barrier(sc->bt, sc->bh, offset, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	}
  }

  static void
 @@ -334,12 +493,67 @@
          struct ie_softc *sc;
          int offset, addr;
  {
 -        bus_space_write_4(sc->bt, sc->bh, offset, addr +
 -			  (u_long) sc->sc_maddr - (u_long) sc->sc_iobase);
 -	bus_space_barrier(sc->bt, sc->bh, offset, 4, BUS_SPACE_BARRIER_WRITE);
 +	char* ptr;
 +	struct ix_softc* isc = (struct ix_softc *) sc;
 +	int val = addr + (u_long) sc->sc_maddr - (u_long) sc->sc_iobase;
 +
 +	if (isc->use_pio) {
 +		/* Reset write pointer to the specified offset */
 +		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, offset);
 +		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +
 +		ptr = (char*) &val;
 +		bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT, 
 +						  *((u_int16_t *)ptr));
 +		bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT, 
 +						  *((u_int16_t *)(ptr + 2)));
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	} else {
 +        	bus_space_write_4(sc->bt, sc->bh, offset, val);
 +		bus_space_barrier(sc->bt, sc->bh, offset, 4, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	}
  }

  static void
 +ix_zeromem(sc, offset, count)
 +        struct ie_softc *sc;
 +        int offset, count;
 +{
 +	int i;
 +	int dribble;
 +	struct ix_softc* isc = (struct ix_softc *) sc;
 +
 +	if (isc->use_pio) {
 +		/* Reset write pointer to the specified offset */
 +		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, offset);
 +		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +
 +		if (offset % 2) {
 +			bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, 0);
 +			count--;
 +		}
 +
 +	        dribble = count % 2;
 +		for(i = 0; i < count / 2; i++)
 +			bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT, 0);
 +
 +		if (dribble)
 +			bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, 0);
 +
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	} else {
 +		bus_space_set_region_1(sc->bt, sc->bh, offset, 0, count);
 +		bus_space_barrier(sc->bt, sc->bh, offset, count, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	}
 +}
 +
 +static void
  ix_mediastatus(sc, ifmr)
          struct ie_softc *sc;
          struct ifmediareq *ifmr;
 @@ -416,22 +630,24 @@
  	 */

  	val = ix_read_eeprom(iot, ioh, 6) & 0xff;
 -	DPRINTF(("memory config: 0x%02x\n", val));
 -
 -	for(i = 0; i < 8; i++) {
 +	for(pg = 0; pg < 8; pg++) {
  		if (val & 1)
  			break;
  		val = val >> 1;
  	}

 -	if (i == 8) {
 +	if (pg == 8) {
  		DPRINTF(("Invalid or unsupported memory config\n"));
  		goto out;
  	}

 -	maddr = 0xc0000 + (i * 0x4000);
 +	maddr = 0xc0000 + (pg * 0x4000);

  	switch (val) {
 +	case 0x00:
 +		msize = 0;
 +		break;
 +
  	case 0x01:
  		msize = 16 * 1024;
  		break;
 @@ -471,9 +687,6 @@
  		goto out;
  	}

 -	DPRINTF(("found %d byte memory region at %x\n",
 -		ia->ia_msize, ia->ia_maddr));
 -
  	/* need to put the 586 in RESET, and leave it */
  	bus_space_write_1(iot, ioh, IX_ECTRL, IX_RESET_586);

 @@ -488,26 +701,24 @@
  	}

  	/*
 -	 * Size and test the memory on the board.  The size of the memory
 -	 * can be one of 16k, 32k, 48k or 64k.  It can be located in the
 -	 * address range 0xC0000 to 0xEFFFF on 16k boundaries.
 +	 * Only do the following bit if using memory-mapped access.  For 
 +	 * boards with no mapped memory, we use PIO.  We also use PIO for
 +	 * boards with 16K of mapped memory, as those setups don't seem
 +	 * to work otherwise.
  	 */
 -	pg = (ia->ia_maddr & 0x3C000) >> 14;
 +	if (msize != 0 && msize != 16384) {
 +		/* Set board up with memory-mapping info */
  	adjust = IX_MCTRL_FMCS16 | (pg & 0x3) << 2;
  	decode = ((1 << (ia->ia_msize / 16384)) - 1) << pg;
  	edecode = ((~decode >> 4) & 0xF0) | (decode >> 8);

 -	/* ZZZ This should be checked against eeprom location 6, low byte */
  	bus_space_write_1(iot, ioh, IX_MEMDEC, decode & 0xFF);
 -
 -	/* ZZZ This should be checked against eeprom location 1, low byte */
  	bus_space_write_1(iot, ioh, IX_MCTRL, adjust);
 -
 -	/* ZZZ Now if I could find this one I would have it made */
  	bus_space_write_1(iot, ioh, IX_MPCTRL, (~decode & 0xFF));

 -	/* ZZZ I think this is location 6, high byte */
 -	bus_space_write_1(iot, ioh, IX_MECTRL, edecode); /*XXX disable Exxx */
 +		/* XXX disable Exxx */
 +		bus_space_write_1(iot, ioh, IX_MECTRL, edecode); 
 +	}

  	/*
  	 * Get the encoded interrupt number from the EEPROM, check it
 @@ -557,15 +768,24 @@
  	struct isa_attach_args *ia = aux;

  	int media;
 -	u_short eaddrtemp;
 +	int i, memsize;
  	u_int8_t bart_config;
  	bus_space_tag_t iot;
 +	u_int8_t bpat, bval;
 +	u_int16_t wpat, wval;
  	bus_space_handle_t ioh, memh;
  	u_short irq_encoded;
  	u_int8_t ethaddr[ETHER_ADDR_LEN];

  	iot = ia->ia_iot;

 +	/* 
 +	 * Shared memory access seems to fail on 16K mapped boards, so
 +	 * disable shared memory access if the board is in 16K mode.  If 
 +	 * no memory is mapped, we have no choice but to use PIO
 +	 */
 +	isc->use_pio = (ia->ia_msize <= (16 * 1024));
 +
  	if (bus_space_map(iot, ia->ia_iobase,
  			  ia->ia_iosize, 0, &ioh) != 0) {

 @@ -575,15 +795,17 @@
  		return;
  	}

 +	/* We map memory even if using PIO so something else doesn't grab it */
 +	if (ia->ia_msize) {
  	if (bus_space_map(ia->ia_memt, ia->ia_maddr,
  			  ia->ia_msize, 0, &memh) != 0) {
 -
  		DPRINTF(("\n%s: can't map iomem space 0x%x-0x%x\n",
  			sc->sc_dev.dv_xname, ia->ia_maddr,
  			ia->ia_maddr + ia->ia_msize - 1));
  		bus_space_unmap(iot, ioh, ia->ia_iosize);
  		return;
  	}
 +	}

  	isc->sc_regt = iot;
  	isc->sc_regh = ioh;
 @@ -592,15 +814,15 @@
  	 * Get the hardware ethernet address from the EEPROM and
  	 * save it in the softc for use by the 586 setup code.
  	 */
 -	eaddrtemp = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_HIGH);
 -	ethaddr[1] = eaddrtemp & 0xFF;
 -	ethaddr[0] = eaddrtemp >> 8;
 -	eaddrtemp = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_MID);
 -	ethaddr[3] = eaddrtemp & 0xFF;
 -	ethaddr[2] = eaddrtemp >> 8;
 -	eaddrtemp = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_LOW);
 -	ethaddr[5] = eaddrtemp & 0xFF;
 -	ethaddr[4] = eaddrtemp >> 8;
 +	wval = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_HIGH);
 +	ethaddr[1] = wval & 0xFF;
 +	ethaddr[0] = wval >> 8;
 +	wval = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_MID);
 +	ethaddr[3] = wval & 0xFF;
 +	ethaddr[2] = wval >> 8;
 +	wval = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_LOW);
 +	ethaddr[5] = wval & 0xFF;
 +	ethaddr[4] = wval >> 8;

  	sc->hwinit = NULL;
  	sc->hwreset = ix_reset;
 @@ -609,6 +831,18 @@

  	sc->memcopyin = ix_copyin;
  	sc->memcopyout = ix_copyout;
 +
 +	/* If using PIO, make sure to setup single-byte read/write functions */
 +	if (isc->use_pio) {
 +		sc->ie_bus_read8 = ix_read_8;
 +		sc->ie_bus_write8 = ix_write_8;
 +		sc->ie_bus_barrier = ix_bus_barrier;
 +	} else {
 +		sc->ie_bus_read8 = NULL;
 +		sc->ie_bus_write8 = NULL;
 +		sc->ie_bus_barrier = NULL;
 +	}
 +
  	sc->ie_bus_read16 = ix_read_16;
  	sc->ie_bus_write16 = ix_write_16;
  	sc->ie_bus_write24 = ix_write_24;
 @@ -618,12 +852,115 @@
  	sc->sc_mediachange = NULL;
  	sc->sc_mediastatus = ix_mediastatus;

 +	if (isc->use_pio) {
 +		sc->bt = iot;
 +		sc->bh = ioh;
 +
 +		/* 
 +		 * If using PIO, the memory size is bounded by on-card memory, 
 +		 * not by how much is mapped into the memory-mapped region, so 
 +		 * determine how much total memory we have to play with here.  
 +		 */
 +		for(memsize = 64 * 1024; memsize; memsize -= 16 * 1024) {
 +			/* warm up shared memory, the zero it all out */
 +			ix_zeromem(sc, 0, 32);
 +			ix_zeromem(sc, 0, memsize);
 +
 +			/* Reset write pointer to the start of RAM */
 +			bus_space_write_2(iot, ioh, IX_WRITEPTR, 0);
 +			bus_space_barrier(iot, ioh, IX_WRITEPTR, 2, 
 +						    BUS_SPACE_BARRIER_WRITE);
 +
 +			/* write test pattern */
 +			for(i = 0; i < memsize; i += 2) {
 +				bus_space_write_2(iot, ioh, IX_DATAPORT, wpat);
 +				wpat += 3;
 +			}
 +
 +			/* Flush all reads & writes to data port */
 +			bus_space_barrier(iot, ioh, IX_DATAPORT, 2, 
 +						    BUS_SPACE_BARRIER_READ |
 +						    BUS_SPACE_BARRIER_WRITE);
 +
 +			/* Reset read pointer to beginning of card RAM */
 +			bus_space_write_2(iot, ioh, IX_READPTR, 0);
 +			bus_space_barrier(iot, ioh, IX_READPTR, 2, 
 +						    BUS_SPACE_BARRIER_WRITE);
 +
 +			/* read and verify test pattern */
 +			for(i = 0, wpat = 1; i < memsize; i += 2) {
 +				wval = bus_space_read_2(iot, ioh, IX_DATAPORT);
 +
 +				if (wval != wpat)
 +					break;
 +
 +				wpat += 3;
 +			}
 +
 +			/* If we failed, try next size down */
 +			if (i != memsize)
 +				continue;
 +
 +			/* Now try it all with byte reads/writes */
 +			ix_zeromem(sc, 0, 32);
 +			ix_zeromem(sc, 0, memsize);
 +
 +			/* Reset write pointer to start of card RAM */
 +			bus_space_write_2(iot, ioh, IX_WRITEPTR, 0);
 +			bus_space_barrier(iot, ioh, IX_WRITEPTR, 2, 
 +						    BUS_SPACE_BARRIER_WRITE);
 +
 +			/* write out test pattern */
 +			for(i = 0, bpat = 1; i < memsize; i++) {
 +				bus_space_write_1(iot, ioh, IX_DATAPORT, bpat);
 +				bpat += 3;
 +			}
 +
 +			/* Flush all reads & writes to data port */
 +			bus_space_barrier(iot, ioh, IX_DATAPORT, 2, 
 +						    BUS_SPACE_BARRIER_READ |
 +						    BUS_SPACE_BARRIER_WRITE);
 +
 +			/* Reset read pointer to beginning of card RAM */
 +			bus_space_write_2(iot, ioh, IX_READPTR, 0);
 +			bus_space_barrier(iot, ioh, IX_READPTR, 2, 
 +						    BUS_SPACE_BARRIER_WRITE);
 +
 +			/* read and verify test pattern */
 +			for(i = 0, bpat = 1; i < memsize; i++) {
 +				bval = bus_space_read_1(iot, ioh, IX_DATAPORT);
 +
 +				if (bval != bpat)
 +				bpat += 3;
 +			}
 +
 +			/* If we got through all of memory, we're done! */ 
 +			if (i == memsize)
 +				break;
 +		}
 +
 +		/* Memory tests failed, punt... */
 +		if (memsize == 0)  {
 +			DPRINTF(("\n%s: can't determine size of on-card RAM\n",
 +				sc->sc_dev.dv_xname));
 +			bus_space_unmap(iot, ioh, ia->ia_iosize);
 +			return;
 +		}
 +
 +		sc->bt = iot;
 +		sc->bh = ioh;
 +
 +		sc->sc_msize = memsize;
 +		sc->sc_maddr = (void*) 0;
 +	} else {
  	sc->bt = ia->ia_memt;
  	sc->bh = memh;

 -	/* Map i/o space. */
  	sc->sc_msize = ia->ia_msize;
  	sc->sc_maddr = (void *)memh;
 +	}
 +
 +	/* Map i/o space. */
  	sc->sc_iobase = (char *)sc->sc_maddr + sc->sc_msize - (1 << 24);

  	/* set up pointers to important on-card control structures */
 @@ -635,24 +972,42 @@
  	sc->buf_area_sz = sc->sc_msize - IE_ISCP_SZ - IE_SCB_SZ - IE_SCP_SZ;

  	/* zero card memory */
 -	bus_space_set_region_1(sc->bt, sc->bh, 0, 0, 32);
 -	bus_space_set_region_1(sc->bt, sc->bh, 0, 0, sc->sc_msize);
 +	ix_zeromem(sc, 0, 32);
 +	ix_zeromem(sc, 0, sc->sc_msize);

  	/* set card to 16-bit bus mode */
 -	bus_space_write_1(sc->bt, sc->bh, IE_SCP_BUS_USE((u_long)sc->scp), 0);
 +	if (isc->use_pio) {
 +		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, 
 +				  	    IE_SCP_BUS_USE((u_long)sc->scp));
 +		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2,
 +					          BUS_SPACE_BARRIER_WRITE);

 +		bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, 0);
 +	} else {
 +		bus_space_write_1(sc->bt, sc->bh, 
 +				  IE_SCP_BUS_USE((u_long)sc->scp), 0);
 +	}
 +
  	/* set up pointers to key structures */
  	ix_write_24(sc, IE_SCP_ISCP((u_long)sc->scp), (u_long) sc->iscp);
  	ix_write_16(sc, IE_ISCP_SCB((u_long)sc->iscp), (u_long) sc->scb);
  	ix_write_24(sc, IE_ISCP_BASE((u_long)sc->iscp), (u_long) sc->iscp);

  	/* flush setup of pointers, check if chip answers */
 +	if (isc->use_pio) {
 +		bus_space_barrier(sc->bt, sc->bh, 0, IX_IOSIZE,
 +				  BUS_SPACE_BARRIER_WRITE);
 +	} else {
  	bus_space_barrier(sc->bt, sc->bh, 0, sc->sc_msize,
  			  BUS_SPACE_BARRIER_WRITE);
 +	}
 +
  	if (!i82586_proberam(sc)) {
  		DPRINTF(("\n%s: Can't talk to i82586!\n",
  			sc->sc_dev.dv_xname));
  		bus_space_unmap(iot, ioh, ia->ia_iosize);
 +
 +		if (ia->ia_msize)
  		bus_space_unmap(ia->ia_memt, memh, ia->ia_msize);
  		return;
  	}
 @@ -683,10 +1038,16 @@
  	bus_space_write_1(iot, ioh, IX_IRQ,
  			  irq_encoded | IX_IRQ_ENABLE);

 +	/* Flush all writes to registers */
 +	bus_space_barrier(iot, ioh, 0, ia->ia_iosize, BUS_SPACE_BARRIER_WRITE);
 +
  	isc->irq_encoded = irq_encoded;

  	i82586_attach(sc, "EtherExpress/16", ethaddr,
  		      ix_media, NIX_MEDIA, media);
 +
 +	if (isc->use_pio)
 +		printf("%s: unsupported memory config, using PIO to access %d bytes of memory\n", sc->sc_dev.dv_xname, sc->sc_msize);

  	isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
  					IPL_NET, i82586_intr, sc);
 Index: dev/isa/if_ixreg.h
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/isa/if_ixreg.h,v
 retrieving revision 1.2
 diff -b -u -r1.2 if_ixreg.h
 --- if_ixreg.h	1998/02/28 20:43:28	1.2
 +++ if_ixreg.h	1999/09/19 04:22:26
 @@ -38,9 +38,15 @@

  #define IX_IOSIZE	16	/* card has 16 registers in IO space */

 +#define IX_DATAPORT  		0x00	/* shared memory data port */
 +#define IX_WRITEPTR  		0x02	/* shared memory write pointer */
 +#define IX_READPTR  		0x04	/* shared memory read pointer */
 +
  #define IX_ATTN			0x06	/* channel attention control */
  #define IX_IRQ			0x07	/* IRQ configuration */
  #define IX_IRQ_ENABLE		0x08	/* enable board interrupts */
 +
 +#define IX_SHADOWPTR  		0x08	/* shadow memory pointer */

  #define IX_MEMDEC		0x0a	/* memory decode */
  #define IX_MCTRL		0x0b	/* memory control */
 Index: dev/ic/i82586.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/ic/i82586.c,v
 retrieving revision 1.25
 diff -b -u -r1.25 i82586.c
 --- i82586.c	1999/08/23 12:12:42	1.25
 +++ i82586.c	1999/09/19 04:22:28
 @@ -155,6 +155,7 @@
  #include <sys/socket.h>
  #include <sys/ioctl.h>
  #include <sys/errno.h>
 +#include <sys/systm.h>
  #include <sys/syslog.h>
  #include <sys/device.h>

 @@ -461,19 +462,23 @@
  {
  	/* spin on i82586 command acknowledge; wait at most 0.9 (!) seconds */
  	int i, off;
 +	u_int16_t cmd;

  	for (i = 0; i < 900000; i++) {
  		/* Read the command word */
  		off = IE_SCB_CMD(sc->scb);
 -		bus_space_barrier(sc->bt, sc->bh, off, 2,
 -				  BUS_SPACE_BARRIER_READ);
 -		if ((sc->ie_bus_read16)(sc, off) == 0)
 +
 +		IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
 +		if ((cmd = (sc->ie_bus_read16)(sc, off)) == 0)
  			return (0);
  		delay(1);
  	}
 +
 +	off = IE_SCB_STATUS(sc->scb);
 +	printf("i82586_cmd_wait: timo(%ssync): scb status: 0x%x, cmd: 0x%x\n",
 +		sc->async_cmd_inprogress?"a":"", 
 +		sc->ie_bus_read16(sc, off), cmd);

 -	printf("i82586_cmd_wait: timo(%ssync): scb status: 0x%x\n",
 -		sc->async_cmd_inprogress?"a":"", sc->ie_bus_read16(sc, off));
  	return (1);	/* Timeout */
  }

 @@ -510,7 +515,7 @@

  	off = IE_SCB_CMD(sc->scb);
  	(sc->ie_bus_write16)(sc, off, cmd);
 -	bus_space_barrier(sc->bt, sc->bh, off, 2, BUS_SPACE_BARRIER_WRITE);
 +	IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_WRITE);
  	(sc->chan_attn)(sc);

  	if (async != 0) {
 @@ -529,8 +534,7 @@
  		for (i = 0; i < 369000; i++) {
  			/* Read the command status */
  			off = IE_CMD_COMMON_STATUS(iecmdbuf);
 -			bus_space_barrier(sc->bt, sc->bh, off, 2,
 -					  BUS_SPACE_BARRIER_READ);
 +			IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
  			status = (sc->ie_bus_read16)(sc, off);
  			if (status & mask)
  				return (0);
 @@ -558,7 +562,7 @@
  {
  	u_int status;

 -	bus_space_barrier(sc->bt, sc->bh, 0, 0, BUS_SPACE_BARRIER_READ);
 +	IE_BUS_BARRIER(sc, 0, 0, BUS_SPACE_BARRIER_READ);
  	status = (sc->ie_bus_read16)(sc, IE_SCB_STATUS(sc->scb));
  	i82586_start_cmd(sc, status & mask, 0, 0, 0);
  }
 @@ -573,16 +577,16 @@
  	int scb = sc->scb;

  	sc->sc_ethercom.ec_if.if_ierrors +=
 -	    sc->ie_bus_read16(sc, IE_SCB_ERRCRC(scb)) +
 -	    sc->ie_bus_read16(sc, IE_SCB_ERRALN(scb)) +
 -	    sc->ie_bus_read16(sc, IE_SCB_ERRRES(scb)) +
 -	    sc->ie_bus_read16(sc, IE_SCB_ERROVR(scb));
 +	    (sc->ie_bus_read16)(sc, IE_SCB_ERRCRC(scb)) +
 +	    (sc->ie_bus_read16)(sc, IE_SCB_ERRALN(scb)) +
 +	    (sc->ie_bus_read16)(sc, IE_SCB_ERRRES(scb)) +
 +	    (sc->ie_bus_read16)(sc, IE_SCB_ERROVR(scb));

  	/* Clear error counters */
 -	sc->ie_bus_write16(sc, IE_SCB_ERRCRC(scb), 0);
 -	sc->ie_bus_write16(sc, IE_SCB_ERRALN(scb), 0);
 -	sc->ie_bus_write16(sc, IE_SCB_ERRRES(scb), 0);
 -	sc->ie_bus_write16(sc, IE_SCB_ERROVR(scb), 0);
 +	(sc->ie_bus_write16)(sc, IE_SCB_ERRCRC(scb), 0);
 +	(sc->ie_bus_write16)(sc, IE_SCB_ERRALN(scb), 0);
 +	(sc->ie_bus_write16)(sc, IE_SCB_ERRRES(scb), 0);
 +	(sc->ie_bus_write16)(sc, IE_SCB_ERROVR(scb), 0);
  }

  static void
 @@ -615,8 +619,8 @@
  		(sc->intrhook)(sc, INTR_ENTER);

  	off = IE_SCB_STATUS(sc->scb);
 -	bus_space_barrier(sc->bt, sc->bh, off, 2, BUS_SPACE_BARRIER_READ);
 -	status = sc->ie_bus_read16(sc, off) & IE_ST_WHENCE;
 +	IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
 +	status = (sc->ie_bus_read16)(sc, off) & IE_ST_WHENCE;

  	if ((status & IE_ST_WHENCE) == 0) {
  		if (sc->intrhook)
 @@ -650,11 +654,15 @@
  	/*
  	 * Interrupt ACK was posted asynchronously; wait for
  	 * completion here before reading SCB status again.
 +	 * 
 +	 * If ACK fails, try to reset the chip, in hopes that
 +	 * it helps.
  	 */
 -	i82586_cmd_wait(sc);
 +	if (i82586_cmd_wait(sc) != 0)
 +		goto reset;

 -	bus_space_barrier(sc->bt, sc->bh, off, 2, BUS_SPACE_BARRIER_READ);
 -	status = sc->ie_bus_read16(sc, off);
 +	IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
 +	status = (sc->ie_bus_read16)(sc, off);
  	if ((status & IE_ST_WHENCE) != 0)
  		goto loop;

 @@ -692,9 +700,8 @@

  		i = sc->rfhead;
  		off = IE_RFRAME_STATUS(sc->rframes, i);
 -		bus_space_barrier(sc->bt, sc->bh, off, 2,
 -				  BUS_SPACE_BARRIER_READ);
 -		status = sc->ie_bus_read16(sc, off);
 +		IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
 +		status = (sc->ie_bus_read16)(sc, off);

  #if I82586_DEBUG
  		if (sc->sc_debug & IED_RINT)
 @@ -737,19 +744,19 @@
  		 */

  		/* Clear frame status */
 -		sc->ie_bus_write16(sc, off, 0);
 +		(sc->ie_bus_write16)(sc, off, 0);

  		/* Put fence at this frame (the head) */
  		off = IE_RFRAME_LAST(sc->rframes, i);
 -		sc->ie_bus_write16(sc, off, IE_FD_EOL|IE_FD_SUSP);
 +		(sc->ie_bus_write16)(sc, off, IE_FD_EOL|IE_FD_SUSP);

  		/* and clear RBD field */
  		off = IE_RFRAME_BUFDESC(sc->rframes, i);
 -		sc->ie_bus_write16(sc, off, 0xffff);
 +		(sc->ie_bus_write16)(sc, off, 0xffff);

  		/* Remove fence from current tail */
  		off = IE_RFRAME_LAST(sc->rframes, sc->rftail);
 -		sc->ie_bus_write16(sc, off, 0);
 +		(sc->ie_bus_write16)(sc, off, 0);

  		if (++sc->rftail == sc->nframes)
  			sc->rftail = 0;
 @@ -848,7 +855,7 @@
  	}
  #endif

 -	status = sc->ie_bus_read16(sc, IE_CMD_XMIT_STATUS(sc->xmit_cmds,
 +	status = (sc->ie_bus_read16)(sc, IE_CMD_XMIT_STATUS(sc->xmit_cmds,
  							  sc->xctail));

  #if I82586_DEBUG
 @@ -928,9 +935,8 @@

  	do {
  		off = IE_RBD_STATUS(rbbase, rbindex);
 -		bus_space_barrier(sc->bt, sc->bh, off, 2,
 -				  BUS_SPACE_BARRIER_READ);
 -		rbdstatus = sc->ie_bus_read16(sc, off);
 +		IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
 +		rbdstatus = (sc->ie_bus_read16)(sc, off);
  		if ((rbdstatus & IE_RBD_USED) == 0) {
  			/*
  			 * This means we are somehow out of sync.  So, we
 @@ -972,7 +978,7 @@
  	do {
  		/* Clear buffer status */
  		off = IE_RBD_STATUS(rbbase, rbindex);
 -		sc->ie_bus_write16(sc, off, 0);
 +		(sc->ie_bus_write16)(sc, off, 0);
  		if (++rbindex == sc->nrxbuf)
  			rbindex = 0;
  	} while (rbindex != end);
 @@ -980,11 +986,11 @@
  	/* Mark EOL at new tail */
  	rbindex = ((rbindex == 0) ? sc->nrxbuf : rbindex) - 1;
  	off = IE_RBD_BUFLEN(rbbase, rbindex);
 -	sc->ie_bus_write16(sc, off, IE_RBUF_SIZE|IE_RBD_EOL);
 +	(sc->ie_bus_write16)(sc, off, IE_RBUF_SIZE|IE_RBD_EOL);

  	/* Remove EOL from current tail */
  	off = IE_RBD_BUFLEN(rbbase, sc->rbtail);
 -	sc->ie_bus_write16(sc, off, IE_RBUF_SIZE);
 +	(sc->ie_bus_write16)(sc, off, IE_RBUF_SIZE);

  	/* New head & tail pointer */
  /* hmm, why have both? head is always (tail + 1) % NRXBUF */
 @@ -1028,7 +1034,7 @@

  	for (n = 0; n < sc->nrxbuf; n++) {
  		off = IE_RBD_BUFLEN(sc->rbds, n);
 -		val = sc->ie_bus_read16(sc, off);
 +		val = (sc->ie_bus_read16)(sc, off);
  		if ((n == sc->rbtail) ^ ((val & IE_RBD_EOL) != 0)) {
  			/* `rbtail' and EOL flag out of sync */
  			log(LOG_ERR,
 @@ -1042,7 +1048,7 @@

  	for (n = 0; n < sc->nframes; n++) {
  		off = IE_RFRAME_LAST(sc->rframes, n);
 -		val = sc->ie_bus_read16(sc, off);
 +		val = (sc->ie_bus_read16)(sc, off);
  		if ((n == sc->rftail) ^ ((val & (IE_FD_EOL|IE_FD_SUSP)) != 0)) {
  			/* `rftail' and EOL flag out of sync */
  			log(LOG_ERR,
 @@ -1296,39 +1302,38 @@
  	/*
  	 * Setup the transmit command.
  	 */
 -	sc->ie_bus_write16(sc, IE_CMD_XMIT_DESC(sc->xmit_cmds, cur),
 +	(sc->ie_bus_write16)(sc, IE_CMD_XMIT_DESC(sc->xmit_cmds, cur),
  			       IE_XBD_ADDR(sc->xbds, cur));

 -	sc->ie_bus_write16(sc, IE_CMD_XMIT_STATUS(sc->xmit_cmds, cur), 0);
 +	(sc->ie_bus_write16)(sc, IE_CMD_XMIT_STATUS(sc->xmit_cmds, cur), 0);

  	if (sc->do_xmitnopchain) {
  		/*
  		 * Gate this XMIT command to the following NOP
  		 */
 -		sc->ie_bus_write16(sc, IE_CMD_XMIT_LINK(sc->xmit_cmds, cur),
 +		(sc->ie_bus_write16)(sc, IE_CMD_XMIT_LINK(sc->xmit_cmds, cur),
  				       IE_CMD_NOP_ADDR(sc->nop_cmds, cur));
 -		sc->ie_bus_write16(sc, IE_CMD_XMIT_CMD(sc->xmit_cmds, cur),
 +		(sc->ie_bus_write16)(sc, IE_CMD_XMIT_CMD(sc->xmit_cmds, cur),
  				       IE_CMD_XMIT | IE_CMD_INTR);

  		/*
  		 * Loopback at following NOP
  		 */
 -		sc->ie_bus_write16(sc, IE_CMD_NOP_STATUS(sc->nop_cmds, cur), 0);
 -		sc->ie_bus_write16(sc, IE_CMD_NOP_LINK(sc->nop_cmds, cur),
 +		(sc->ie_bus_write16)(sc, IE_CMD_NOP_STATUS(sc->nop_cmds, cur), 0);
 +		(sc->ie_bus_write16)(sc, IE_CMD_NOP_LINK(sc->nop_cmds, cur),
  				       IE_CMD_NOP_ADDR(sc->nop_cmds, cur));

  		/*
  		 * Gate preceding NOP to this XMIT command
  		 */
  		prev = (cur + NTXBUF - 1) % NTXBUF;
 -		sc->ie_bus_write16(sc, IE_CMD_NOP_STATUS(sc->nop_cmds, prev), 0);
 -		sc->ie_bus_write16(sc, IE_CMD_NOP_LINK(sc->nop_cmds, prev),
 +		(sc->ie_bus_write16)(sc, IE_CMD_NOP_STATUS(sc->nop_cmds, prev), 0);
 +		(sc->ie_bus_write16)(sc, IE_CMD_NOP_LINK(sc->nop_cmds, prev),
  				       IE_CMD_XMIT_ADDR(sc->xmit_cmds, cur));

  		off = IE_SCB_STATUS(sc->scb);
 -		bus_space_barrier(sc->bt, sc->bh, off, 2,
 -				  BUS_SPACE_BARRIER_READ);
 -		if ((sc->ie_bus_read16(sc, off) & IE_CUS_ACTIVE) == 0) {
 +		IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
 +		if (((sc->ie_bus_read16)(sc, off) & IE_CUS_ACTIVE) == 0) {
  			printf("iexmit: CU not active\n");
  			i82586_start_transceiver(sc);
  		}
 @@ -1341,8 +1346,7 @@

  		off = IE_SCB_CMDLST(sc->scb);
  		sc->ie_bus_write16(sc, off, IE_CMD_XMIT_ADDR(sc->xmit_cmds, cur));
 -		bus_space_barrier(sc->bt, sc->bh, off, 2,
 -				  BUS_SPACE_BARRIER_WRITE);
 +		IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);

  		if (i82586_start_cmd(sc, IE_CUC_START, 0, 0, 1))
  			printf("%s: iexmit: start xmit command timed out\n",
 @@ -1446,13 +1450,15 @@

  	/* Put in 16-bit mode */
  	off = IE_SCP_BUS_USE(sc->scp);
 -	bus_space_write_1(sc->bt, sc->bh, off, 0);
 -	bus_space_barrier(sc->bt, sc->bh, off, 1, BUS_SPACE_BARRIER_WRITE);

 +	IE_BUS_WRITE8(sc, off, 0);
 +	IE_BUS_BARRIER(sc, off, 1, BUS_SPACE_BARRIER_WRITE);
 +
  	/* Set the ISCP `busy' bit */
  	off = IE_ISCP_BUSY(sc->iscp);
 -	bus_space_write_1(sc->bt, sc->bh, off, 1);
 -	bus_space_barrier(sc->bt, sc->bh, off, 1, BUS_SPACE_BARRIER_WRITE);
 +
 +	IE_BUS_WRITE8(sc, off, 1);
 +	IE_BUS_BARRIER(sc, off, 1, BUS_SPACE_BARRIER_WRITE);

  	if (sc->hwreset)
  		(sc->hwreset)(sc, CHIP_PROBE);
 @@ -1463,9 +1469,10 @@

  	/* Read back the ISCP `busy' bit; it should be clear by now */
  	off = IE_ISCP_BUSY(sc->iscp);
 -	bus_space_barrier(sc->bt, sc->bh, off, 1, BUS_SPACE_BARRIER_READ);
 -	result = bus_space_read_1(sc->bt, sc->bh, off) == 0;

 +	IE_BUS_BARRIER(sc, off, 1, BUS_SPACE_BARRIER_READ);
 +	result = IE_BUS_READ8(sc, off) == 0;
 +
  	/* Acknowledge any interrupts we may have caused. */
  	ie_ack(sc, IE_ST_WHENCE);

 @@ -1543,10 +1550,10 @@
  	(sc->ie_bus_write16)(sc, IE_CMD_TDR_TIME(cmd), 0);

  	if (i82586_start_cmd(sc, IE_CUC_START, cmd, IE_STAT_COMPL, 0) ||
 -	    (sc->ie_bus_read16(sc, IE_CMD_COMMON_STATUS(cmd)) & IE_STAT_OK) == 0)
 +	    ((sc->ie_bus_read16)(sc, IE_CMD_COMMON_STATUS(cmd)) & IE_STAT_OK) == 0)
  		result = 0x10000; /* XXX */
  	else
 -		result = sc->ie_bus_read16(sc, IE_CMD_TDR_TIME(cmd));
 +		result = (sc->ie_bus_read16)(sc, IE_CMD_TDR_TIME(cmd));

  	/* Squash any pending interrupts */
  	ie_ack(sc, IE_ST_WHENCE);
 @@ -1744,24 +1751,25 @@
  	int cmdresult, status;

  	setup_simple_command(sc, IE_CMD_CONFIG, cmd);
 -	bus_space_write_1(sc->bt, sc->bh, IE_CMD_CFG_CNT(cmd), 0x0c);
 -	bus_space_write_1(sc->bt, sc->bh, IE_CMD_CFG_FIFO(cmd), 8);
 -	bus_space_write_1(sc->bt, sc->bh, IE_CMD_CFG_SAVEBAD(cmd), 0x40);
 -	bus_space_write_1(sc->bt, sc->bh, IE_CMD_CFG_ADDRLEN(cmd), 0x2e);
 -	bus_space_write_1(sc->bt, sc->bh, IE_CMD_CFG_PRIORITY(cmd), 0);
 -	bus_space_write_1(sc->bt, sc->bh, IE_CMD_CFG_IFS(cmd), 0x60);
 -	bus_space_write_1(sc->bt, sc->bh, IE_CMD_CFG_SLOT_LOW(cmd), 0);
 -	bus_space_write_1(sc->bt, sc->bh, IE_CMD_CFG_SLOT_HIGH(cmd), 0xf2);
 -	bus_space_write_1(sc->bt, sc->bh, IE_CMD_CFG_PROMISC(cmd),
 +
 +	IE_BUS_WRITE8(sc, IE_CMD_CFG_CNT(cmd), 0x0c);
 +	IE_BUS_WRITE8(sc, IE_CMD_CFG_FIFO(cmd), 8);
 +	IE_BUS_WRITE8(sc, IE_CMD_CFG_SAVEBAD(cmd), 0x40);
 +	IE_BUS_WRITE8(sc, IE_CMD_CFG_ADDRLEN(cmd), 0x2e);
 +	IE_BUS_WRITE8(sc, IE_CMD_CFG_PRIORITY(cmd), 0);
 +	IE_BUS_WRITE8(sc, IE_CMD_CFG_IFS(cmd), 0x60);
 +	IE_BUS_WRITE8(sc, IE_CMD_CFG_SLOT_LOW(cmd), 0);
 +	IE_BUS_WRITE8(sc, IE_CMD_CFG_SLOT_HIGH(cmd), 0xf2);
 +	IE_BUS_WRITE8(sc, IE_CMD_CFG_PROMISC(cmd), 
  					  !!promiscuous | manchester << 2);
 -	bus_space_write_1(sc->bt, sc->bh, IE_CMD_CFG_CRSCDT(cmd), 0);
 -	bus_space_write_1(sc->bt, sc->bh, IE_CMD_CFG_MINLEN(cmd), 64);
 -	bus_space_write_1(sc->bt, sc->bh, IE_CMD_CFG_JUNK(cmd), 0xff);
 -	bus_space_barrier(sc->bt, sc->bh, cmd, IE_CMD_CFG_SZ,
 -			  BUS_SPACE_BARRIER_WRITE);
 +	IE_BUS_WRITE8(sc, IE_CMD_CFG_CRSCDT(cmd), 0);
 +	IE_BUS_WRITE8(sc, IE_CMD_CFG_MINLEN(cmd), 64);
 +	IE_BUS_WRITE8(sc, IE_CMD_CFG_JUNK(cmd), 0xff);
 +
 +	IE_BUS_BARRIER(sc, cmd, IE_CMD_CFG_SZ, BUS_SPACE_BARRIER_WRITE);

  	cmdresult = i82586_start_cmd(sc, IE_CUC_START, cmd, IE_STAT_COMPL, 0);
 -	status = sc->ie_bus_read16(sc, IE_CMD_COMMON_STATUS(cmd));
 +	status = (sc->ie_bus_read16)(sc, IE_CMD_COMMON_STATUS(cmd));
  	if (cmdresult != 0) {
  		printf("%s: configure command timed out; status %x\n",
  			sc->sc_dev.dv_xname, status);
 @@ -1792,7 +1800,7 @@
  			 IE_CMD_IAS_EADDR(cmdbuf), ETHER_ADDR_LEN);

  	cmdresult = i82586_start_cmd(sc, IE_CUC_START, cmdbuf, IE_STAT_COMPL, 0);
 -	status = sc->ie_bus_read16(sc, IE_CMD_COMMON_STATUS(cmdbuf));
 +	status = (sc->ie_bus_read16)(sc, IE_CMD_COMMON_STATUS(cmdbuf));
  	if (cmdresult != 0) {
  		printf("%s: individual address command timed out; status %x\n",
  			sc->sc_dev.dv_xname, status);
 @@ -1834,7 +1842,7 @@

  	/* Start the command */
  	cmdresult = i82586_start_cmd(sc, IE_CUC_START, cmdbuf, IE_STAT_COMPL, 0);
 -	status = sc->ie_bus_read16(sc, IE_CMD_COMMON_STATUS(cmdbuf));
 +	status = (sc->ie_bus_read16)(sc, IE_CMD_COMMON_STATUS(cmdbuf));
  	if (cmdresult != 0) {
  		printf("%s: multicast setup command timed out; status %x\n",
  			sc->sc_dev.dv_xname, status);
 @@ -2164,9 +2172,9 @@

  	printf("RBD at %08x:\n  status %04x, next %04x, buffer %lx\n"
  		"length/EOL %04x\n", IE_RBD_ADDR(sc->rbds,n),
 -		sc->ie_bus_read16(sc, IE_RBD_STATUS(sc->rbds,n)),
 -		sc->ie_bus_read16(sc, IE_RBD_NEXT(sc->rbds,n)),
 +		(sc->ie_bus_read16)(sc, IE_RBD_STATUS(sc->rbds,n)),
 +		(sc->ie_bus_read16)(sc, IE_RBD_NEXT(sc->rbds,n)),
  		(u_long)0,/*bus_space_read_4(sc->bt, sc->bh, IE_RBD_BUFADDR(sc->rbds,n)),-* XXX */
 -		sc->ie_bus_read16(sc, IE_RBD_BUFLEN(sc->rbds,n)));
 +		(sc->ie_bus_read16)(sc, IE_RBD_BUFLEN(sc->rbds,n)));
  }
  #endif
 Index: dev/ic/i82586var.h
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/ic/i82586var.h,v
 retrieving revision 1.12
 diff -b -u -r1.12 i82586var.h
 --- i82586var.h	1999/08/23 12:12:43	1.12
 +++ i82586var.h	1999/09/19 04:22:28
 @@ -158,12 +158,16 @@
   *
   *	memcopyin	- copy device memory: board to KVA
   *	memcopyout	- copy device memory: KVA to board
 + *	bus_read8	- read a byte from i82586 RAM
 + *	bus_write8	- write a byte to i82586 RAM
   *	bus_read16	- read a 16-bit i82586 pointer
  			  `offset' argument will be 16-bit aligned
   *	bus_write16	- write a 16-bit i82586 pointer
  			  `offset' argument will be 16-bit aligned
   *	bus_write24	- write a 24-bit i82586 pointer
  			  `offset' argument will be 32-bit aligned
 + *	bus_barrier	- perform a bus barrier operation, forcing
 +			  all outstanding reads/writes to complete
   *
   */

 @@ -191,11 +195,16 @@
  	void	(*memcopyin) __P((struct ie_softc *, void *, int, size_t));
  	void	(*memcopyout) __P((struct ie_softc *, const void *,
  				   int, size_t));
 +	u_int8_t (*ie_bus_read8) __P((struct ie_softc *, int offset));
 +	void	(*ie_bus_write8) __P((struct ie_softc *, int offset,
 +					u_int8_t value));
  	u_int16_t (*ie_bus_read16) __P((struct ie_softc *, int offset));
  	void	(*ie_bus_write16) __P((struct ie_softc *, int offset,
  					u_int16_t value));
  	void	(*ie_bus_write24) __P((struct ie_softc *, int offset,
  					int addr));
 +	void	(*ie_bus_barrier) __P((struct ie_softc *, int offset, 
 +					int length, int flags));

  	/* Media management */
          int  (*sc_mediachange) __P((struct ie_softc *));
 @@ -261,3 +270,26 @@
  int 	i82586_proberam __P((struct ie_softc *));
  void 	i82586_attach 	__P((struct ie_softc *, char *, u_int8_t *, 
  			     int*, int, int));
 +
 +/* Shortcut macros to optional (driver uses default if unspecified) callbacks */
 +#define IE_BUS_BARRIER(sc, offset, length, flags)			  \
 +do { 	    								  \
 +	if ((sc)->ie_bus_barrier) 					  \
 +		((sc)->ie_bus_barrier)((sc), (offset), (length), (flags));\
 +	else 								  \
 +		bus_space_barrier((sc)->bt, (sc)->bh, (offset), (length), \
 +							        (flags)); \
 +} while (0)
 +
 +#define IE_BUS_READ8(sc, offset)					  \
 +		((sc)->ie_bus_read8 ?					  \
 +			((sc)->ie_bus_read8)(sc, offset) :		  \
 +			bus_space_read_1((sc)->bt, (sc)->bh, offset))
 +
 +#define IE_BUS_WRITE8(sc, offset, value)				 \
 +do  {									 \
 +	if ((sc)->ie_bus_write8)					 \
 +		((sc)->ie_bus_write8)(sc, offset, value);		 \
 +	else								 \
 +		bus_space_write_1((sc)->bt, (sc)->bh, (offset),	(value));\
 +} while (0)


From: Rafal Boni <rafal@mediaone.net>
To: gnats-bugs@netbsd.org
Cc: bjh21@netbsd.org
Subject: Re: kern/8001
Date: Sun, 14 Jan 2001 13:32:46 -0500

 Attached are patches to fix PR/8001 after Ben's tweaks and other recent
 work to the 82586 driver.  This has been tested on the i386 port with 
 the 'ix' driver in both 16KB (which was the source of the problem) and
 32KB modes, as well as with the 'ef' driver.  I don't have any non-i386
 machines with 82586-based NIC's but don't expect these changes to break
 anything else. (caveat emptor!)

 Since Ben was grossed out by my over-parenthesizing all callbacks through
 the softc functions as '(sc->ie_bus_read16)(args)', I've gone the other 
 way and converted all the callbacks to read 'sc->ie_bus_read16 (args)'
 instead (and I finally figured out why I picked the first style in the 
 first place -- the driver did both and I just picked the paren-paranoid 
 one 8-)

 I've also attempted to fix up all front ends based on the 82586 MI
 core to incorporate the new 'ie_bus_barrier' callback (which is only
 used on the 'ix' driver and is NULL on the rest, thus falling back 
 to standard bus_space_barrier() calls).

 Please let me know if there's anything else I can do to help get this
 finally in the tree.

 Thanks!
 --rafal

 Index: arch/arm26/podulebus/if_ei.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/arch/arm26/podulebus/if_ei.c,v
 retrieving revision 1.4
 diff -b -u -r1.4 if_ei.c
 --- if_ei.c	2001/01/07 15:56:02	1.4
 +++ if_ei.c	2001/01/14 17:44:27
 @@ -136,6 +136,8 @@

  	sc->sc_ie.memcopyin = ei_copyin;
  	sc->sc_ie.memcopyout = ei_copyout;
 +
 +	sc->sc_ie.ie_bus_barrier = NULL;
  	sc->sc_ie.ie_bus_read16 = ei_read16;
  	sc->sc_ie.ie_bus_write16 = ei_write16;
  	sc->sc_ie.ie_bus_write24 = ei_write24;
 Index: arch/mvme68k/dev/if_ie.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/arch/mvme68k/dev/if_ie.c,v
 retrieving revision 1.8
 diff -b -u -r1.8 if_ie.c
 --- if_ie.c	2000/09/15 08:50:24	1.8
 +++ if_ie.c	2001/01/14 17:44:38
 @@ -306,6 +306,7 @@
  	sc->intrhook = ie_intrhook;
  	sc->memcopyin = ie_copyin;
  	sc->memcopyout = ie_copyout;
 +	sc->ie_bus_barrier = NULL;
  	sc->ie_bus_read16 = ie_read_16;
  	sc->ie_bus_write16 = ie_write_16;
  	sc->ie_bus_write24 = ie_write_24;
 Index: arch/sparc/dev/if_ie_obio.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/arch/sparc/dev/if_ie_obio.c,v
 retrieving revision 1.17
 diff -b -u -r1.17 if_ie_obio.c
 --- if_ie_obio.c	2000/07/09 20:57:47	1.17
 +++ if_ie_obio.c	2001/01/14 17:44:43
 @@ -297,6 +297,8 @@
  	sc->hwinit = ie_obrun;
  	sc->memcopyout = ie_obio_memcopyout;
  	sc->memcopyin = ie_obio_memcopyin;
 +
 +	sc->ie_bus_barrier = NULL;
  	sc->ie_bus_read16 = ie_obio_read16;
  	sc->ie_bus_write16 = ie_obio_write16;
  	sc->ie_bus_write24 = ie_obio_write24;
 Index: dev/ic/i82586.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/ic/i82586.c,v
 retrieving revision 1.33
 diff -b -u -r1.33 i82586.c
 --- i82586.c	2000/12/14 06:27:25	1.33
 +++ i82586.c	2001/01/14 17:44:51
 @@ -305,19 +305,23 @@
  {
  	/* spin on i82586 command acknowledge; wait at most 0.9 (!) seconds */
  	int i, off;
 +	u_int16_t cmd;

  	for (i = 0; i < 900000; i++) {
  		/* Read the command word */
  		off = IE_SCB_CMD(sc->scb);
 -		bus_space_barrier(sc->bt, sc->bh, off, 2,
 -				  BUS_SPACE_BARRIER_READ);
 -		if ((sc->ie_bus_read16)(sc, off) == 0)
 +
 +		IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
 +		if ((cmd = sc->ie_bus_read16(sc, off)) == 0)
  			return (0);
  		delay(1);
  	}
 +
 +	off = IE_SCB_STATUS(sc->scb);
 +	printf("i82586_cmd_wait: timo(%ssync): scb status: 0x%x, cmd: 0x%x\n",
 +		sc->async_cmd_inprogress?"a":"", 
 +		sc->ie_bus_read16(sc, off), cmd);

 -	printf("i82586_cmd_wait: timo(%ssync): scb status: 0x%x\n",
 -		sc->async_cmd_inprogress?"a":"", sc->ie_bus_read16(sc, off));
  	return (1);	/* Timeout */
  }

 @@ -353,8 +357,8 @@
  	}

  	off = IE_SCB_CMD(sc->scb);
 -	(sc->ie_bus_write16)(sc, off, cmd);
 -	bus_space_barrier(sc->bt, sc->bh, off, 2, BUS_SPACE_BARRIER_WRITE);
 +	sc->ie_bus_write16(sc, off, cmd);
 +	IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_WRITE);
  	(sc->chan_attn)(sc);

  	if (async != 0) {
 @@ -373,9 +377,8 @@
  		for (i = 0; i < 369000; i++) {
  			/* Read the command status */
  			off = IE_CMD_COMMON_STATUS(iecmdbuf);
 -			bus_space_barrier(sc->bt, sc->bh, off, 2,
 -					  BUS_SPACE_BARRIER_READ);
 -			status = (sc->ie_bus_read16)(sc, off);
 +			IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
 +			status = sc->ie_bus_read16(sc, off);
  			if (status & mask)
  				return (0);
  			delay(1);
 @@ -402,8 +405,8 @@
  {
  	u_int status;

 -	bus_space_barrier(sc->bt, sc->bh, 0, 0, BUS_SPACE_BARRIER_READ);
 -	status = (sc->ie_bus_read16)(sc, IE_SCB_STATUS(sc->scb));
 +	IE_BUS_BARRIER(sc, 0, 0, BUS_SPACE_BARRIER_READ);
 +	status = sc->ie_bus_read16(sc, IE_SCB_STATUS(sc->scb));
  	i82586_start_cmd(sc, status & mask, 0, 0, 0);
  	if (sc->intrhook)
  		sc->intrhook(sc, INTR_ACK);
 @@ -461,7 +464,7 @@
  		(sc->intrhook)(sc, INTR_ENTER);

  	off = IE_SCB_STATUS(sc->scb);
 -	bus_space_barrier(sc->bt, sc->bh, off, 2, BUS_SPACE_BARRIER_READ);
 +	IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
  	status = sc->ie_bus_read16(sc, off) & IE_ST_WHENCE;

  	if ((status & IE_ST_WHENCE) == 0) {
 @@ -496,10 +499,14 @@
  	/*
  	 * Interrupt ACK was posted asynchronously; wait for
  	 * completion here before reading SCB status again.
 +	 * 
 +	 * If ACK fails, try to reset the chip, in hopes that
 +	 * it helps.
  	 */
 -	i82586_cmd_wait(sc);
 +	if (i82586_cmd_wait(sc) != 0)
 +		goto reset;

 -	bus_space_barrier(sc->bt, sc->bh, off, 2, BUS_SPACE_BARRIER_READ);
 +	IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
  	status = sc->ie_bus_read16(sc, off);
  	if ((status & IE_ST_WHENCE) != 0)
  		goto loop;
 @@ -538,8 +545,7 @@

  		i = sc->rfhead;
  		off = IE_RFRAME_STATUS(sc->rframes, i);
 -		bus_space_barrier(sc->bt, sc->bh, off, 2,
 -				  BUS_SPACE_BARRIER_READ);
 +		IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
  		status = sc->ie_bus_read16(sc, off);

  #if I82586_DEBUG
 @@ -774,8 +780,7 @@

  	do {
  		off = IE_RBD_STATUS(rbbase, rbindex);
 -		bus_space_barrier(sc->bt, sc->bh, off, 2,
 -				  BUS_SPACE_BARRIER_READ);
 +		IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
  		rbdstatus = sc->ie_bus_read16(sc, off);
  		if ((rbdstatus & IE_RBD_USED) == 0) {
  			/*
 @@ -1132,8 +1137,7 @@
  				       IE_CMD_XMIT_ADDR(sc->xmit_cmds, cur));

  		off = IE_SCB_STATUS(sc->scb);
 -		bus_space_barrier(sc->bt, sc->bh, off, 2,
 -				  BUS_SPACE_BARRIER_READ);
 +		IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
  		if ((sc->ie_bus_read16(sc, off) & IE_CUS_ACTIVE) == 0) {
  			printf("iexmit: CU not active\n");
  			i82586_start_transceiver(sc);
 @@ -1147,8 +1151,7 @@

  		off = IE_SCB_CMDLST(sc->scb);
  		sc->ie_bus_write16(sc, off, IE_CMD_XMIT_ADDR(sc->xmit_cmds, cur));
 -		bus_space_barrier(sc->bt, sc->bh, off, 2,
 -				  BUS_SPACE_BARRIER_WRITE);
 +		IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);

  		if (i82586_start_cmd(sc, IE_CUC_START, 0, 0, 1))
  			printf("%s: iexmit: start xmit command timed out\n",
 @@ -1252,13 +1255,13 @@

  	/* Put in 16-bit mode */
  	off = IE_SCP_BUS_USE(sc->scp);
 -	(sc->ie_bus_write16)(sc, off, 0);
 -	bus_space_barrier(sc->bt, sc->bh, off, 1, BUS_SPACE_BARRIER_WRITE);
 +	sc->ie_bus_write16(sc, off, 0);
 +	IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_WRITE);

  	/* Set the ISCP `busy' bit */
  	off = IE_ISCP_BUSY(sc->iscp);
 -	(sc->ie_bus_write16)(sc, off, 1);
 -	bus_space_barrier(sc->bt, sc->bh, off, 1, BUS_SPACE_BARRIER_WRITE);
 +	sc->ie_bus_write16(sc, off, 1);
 +	IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_WRITE);

  	if (sc->hwreset)
  		(sc->hwreset)(sc, CHIP_PROBE);
 @@ -1269,8 +1272,8 @@

  	/* Read back the ISCP `busy' bit; it should be clear by now */
  	off = IE_ISCP_BUSY(sc->iscp);
 -	bus_space_barrier(sc->bt, sc->bh, off, 1, BUS_SPACE_BARRIER_READ);
 -	result = (sc->ie_bus_read16)(sc, off) == 0;
 +	IE_BUS_BARRIER(sc, off, 2, BUS_SPACE_BARRIER_READ);
 +	result = sc->ie_bus_read16(sc, off) == 0;

  	/* Acknowledge any interrupts we may have caused. */
  	ie_ack(sc, IE_ST_WHENCE);
 @@ -1346,7 +1349,7 @@
  	int result;

  	setup_simple_command(sc, IE_CMD_TDR, cmd);
 -	(sc->ie_bus_write16)(sc, IE_CMD_TDR_TIME(cmd), 0);
 +	sc->ie_bus_write16(sc, IE_CMD_TDR_TIME(cmd), 0);

  	if (i82586_start_cmd(sc, IE_CUC_START, cmd, IE_STAT_COMPL, 0) ||
  	    (sc->ie_bus_read16(sc, IE_CMD_COMMON_STATUS(cmd)) & IE_STAT_OK) == 0)
 @@ -1499,12 +1502,12 @@
  	 * step 4: all xmit no-op commands loopback onto themselves
  	 */
  	for (n = 0; n < NTXBUF; n++) {
 -		(sc->ie_bus_write16)(sc, IE_CMD_NOP_STATUS(sc->nop_cmds, n), 0);
 +		sc->ie_bus_write16(sc, IE_CMD_NOP_STATUS(sc->nop_cmds, n), 0);

 -		(sc->ie_bus_write16)(sc, IE_CMD_NOP_CMD(sc->nop_cmds, n),
 +		sc->ie_bus_write16(sc, IE_CMD_NOP_CMD(sc->nop_cmds, n),
  					 IE_CMD_NOP);

 -		(sc->ie_bus_write16)(sc, IE_CMD_NOP_LINK(sc->nop_cmds, n),
 +		sc->ie_bus_write16(sc, IE_CMD_NOP_LINK(sc->nop_cmds, n),
  					 IE_CMD_NOP_ADDR(sc->nop_cmds, n));
  	}

 @@ -1564,8 +1567,7 @@
  	*IE_CMD_CFG_JUNK(buf)      = 0xff;
  	sc->memcopyout(sc, buf, cmd, IE_CMD_CFG_SZ);
  	setup_simple_command(sc, IE_CMD_CONFIG, cmd);
 -	bus_space_barrier(sc->bt, sc->bh, cmd, IE_CMD_CFG_SZ,
 -			  BUS_SPACE_BARRIER_WRITE);
 +	IE_BUS_BARRIER(sc, cmd, IE_CMD_CFG_SZ, BUS_SPACE_BARRIER_WRITE);

  	cmdresult = i82586_start_cmd(sc, IE_CUC_START, cmd, IE_STAT_COMPL, 0);
  	status = sc->ie_bus_read16(sc, IE_CMD_COMMON_STATUS(cmd));
 Index: dev/ic/i82586var.h
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/ic/i82586var.h,v
 retrieving revision 1.14
 diff -b -u -r1.14 i82586var.h
 --- i82586var.h	2000/05/11 20:55:04	1.14
 +++ i82586var.h	2001/01/14 17:44:52
 @@ -167,6 +167,8 @@
  			  `offset' argument will be 16-bit aligned
   *	bus_write24	- write a 24-bit i82586 pointer
  			  `offset' argument will be 32-bit aligned
 + *	bus_barrier	- perform a bus barrier operation, forcing
 +			  all outstanding reads/writes to complete
   *
   */

 @@ -201,6 +203,8 @@
  					u_int16_t value));
  	void	(*ie_bus_write24) __P((struct ie_softc *, int offset,
  					int addr));
 +	void	(*ie_bus_barrier) __P((struct ie_softc *, int offset, 
 +					int length, int flags));

  	/* Media management */
          int  (*sc_mediachange) __P((struct ie_softc *));
 @@ -266,3 +270,14 @@
  int 	i82586_proberam __P((struct ie_softc *));
  void 	i82586_attach 	__P((struct ie_softc *, char *, u_int8_t *, 
  			     int*, int, int));
 +
 +/* Shortcut macros to optional (driver uses default if unspecified) callbacks */
 +#define IE_BUS_BARRIER(sc, offset, length, flags)			  \
 +do { 	    								  \
 +	if ((sc)->ie_bus_barrier) 					  \
 +		((sc)->ie_bus_barrier)((sc), (offset), (length), (flags));\
 +	else 								  \
 +		bus_space_barrier((sc)->bt, (sc)->bh, (offset), (length), \
 +							        (flags)); \
 +} while (0)
 +
 Index: dev/isa/if_ai.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/isa/if_ai.c,v
 retrieving revision 1.8
 diff -b -u -r1.8 if_ai.c
 --- if_ai.c	2000/06/28 16:27:53	1.8
 +++ if_ai.c	2001/01/14 17:44:53
 @@ -348,6 +348,8 @@
  	sc->hwreset = ai_reset;
  	sc->chan_attn = ai_atten;

 +	sc->ie_bus_barrier = NULL;
 +
  	sc->memcopyin = ai_copyin;
  	sc->memcopyout = ai_copyout;
  	sc->ie_bus_read16 = ai_read_16;
 Index: dev/isa/if_ef.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/isa/if_ef.c,v
 retrieving revision 1.7
 diff -b -u -r1.7 if_ef.c
 --- if_ef.c	2000/06/28 16:27:54	1.7
 +++ if_ef.c	2001/01/14 17:44:53
 @@ -503,6 +503,8 @@
  	sc->chan_attn = ef_atten;
  	sc->intrhook = ef_intrhook;

 +	sc->ie_bus_barrier = NULL;
 +
  	sc->memcopyin = ef_copyin;
  	sc->memcopyout = ef_copyout;
  	sc->ie_bus_read16 = ef_read_16;
 Index: if_ix.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/isa/if_ix.c,v
 retrieving revision 1.7
 diff -b -u -b -u -r1.7 if_ix.c
 --- if_ix.c	2000/06/28 16:27:54	1.7
 +++ if_ix.c	2001/01/14 17:53:10
 @@ -80,6 +80,7 @@
  	bus_space_tag_t sc_regt;	/* space tag for registers */
  	bus_space_handle_t sc_regh;	/* space handle for registers */

 +	u_int8_t	use_pio;	/* use PIO rather than shared mem */
  	u_int16_t	irq_encoded;	/* encoded IRQ */
  	void		*sc_ih;		/* interrupt handle */
  };
 @@ -91,9 +92,12 @@
  static void     ix_copyin __P((struct ie_softc *, void *, int, size_t));
  static void     ix_copyout __P((struct ie_softc *, const void *, int, size_t));

 +static void	ix_bus_barrier __P((struct ie_softc *, int, int, int));
 +
  static u_int16_t ix_read_16 __P((struct ie_softc *, int));
  static void	ix_write_16 __P((struct ie_softc *, int, u_int16_t));
  static void	ix_write_24 __P((struct ie_softc *, int, int));
 +static void	ix_zeromem  __P((struct ie_softc *, int, int));

  static void	ix_mediastatus __P((struct ie_softc *, struct ifmediareq *));

 @@ -256,24 +260,51 @@
          int offset;
          size_t size;
  {
 -	int dribble;
 +	int i, dribble;
  	u_int8_t* bptr = dst;
 +	u_int16_t* wptr = dst;
 +	struct ix_softc* isc = (struct ix_softc *) sc;

 +	if (isc->use_pio) {
 +		/* Reset read pointer to the specified offset */
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2,
 +						  BUS_SPACE_BARRIER_READ);
 +		bus_space_write_2(sc->bt, sc->bh, IX_READPTR, offset);
 +		bus_space_barrier(sc->bt, sc->bh, IX_READPTR, 2,
 +						  BUS_SPACE_BARRIER_WRITE);
 +	} else {
  	bus_space_barrier(sc->bt, sc->bh, offset, size,
  			  BUS_SPACE_BARRIER_READ);
 +	}

  	if (offset % 2) {
 +		if (isc->use_pio)
 +			*bptr = bus_space_read_1(sc->bt, sc->bh, IX_DATAPORT);
 +		else
  		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
  		offset++; bptr++; size--;
  	}

  	dribble = size % 2;
 -	bus_space_read_region_2(sc->bt, sc->bh, offset, (u_int16_t *) bptr,
 -				size >> 1);
 +	wptr = (u_int16_t*) bptr;
 +
 +	if (isc->use_pio) {
 +		for(i = 0; i <  size / 2; i++) {
 +			*wptr = bus_space_read_2(sc->bt, sc->bh, IX_DATAPORT);
 +			wptr++;
 +		}
 +	} else {
 +		bus_space_read_region_2(sc->bt, sc->bh, offset, 
 +					(u_int16_t *) bptr, size / 2);
 +	}

  	if (dribble) {
  		bptr += size - 1;
  		offset += size - 1;
 +
 +		if (isc->use_pio)
 +			*bptr = bus_space_read_1(sc->bt, sc->bh, IX_DATAPORT);
 +		else
  		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
  	}
  }
 @@ -285,36 +316,94 @@
          int offset;
          size_t size;
  {
 -	int dribble;
 +	int i, dribble;
  	int osize = size;
  	int ooffset = offset;
  	const u_int8_t* bptr = src;
 +	const u_int16_t* wptr = src;
 +	struct ix_softc* isc = (struct ix_softc *) sc;

 +	if (isc->use_pio) {
 +		/* Reset write pointer to the specified offset */
 +		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, offset);
 +		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	}
 +
  	if (offset % 2) {
 +		if (isc->use_pio)
 +			bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, *bptr);
 +		else
  		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
  		offset++; bptr++; size--;
  	}

  	dribble = size % 2;
 -	bus_space_write_region_2(sc->bt, sc->bh, offset, (u_int16_t *)bptr,
 -				 size >> 1);
 +	wptr = (u_int16_t*) bptr;
 +
 +	if (isc->use_pio) {
 +		for(i = 0; i < size / 2; i++) {
 +			bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT, *wptr);
 +			wptr++;
 +		}
 +	} else {
 +		bus_space_write_region_2(sc->bt, sc->bh, offset, 
 +					 (u_int16_t *)bptr, size / 2);
 +	}
 +
  	if (dribble) {
  		bptr += size - 1;
  		offset += size - 1;
 +
 +		if (isc->use_pio)
 +			bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, *bptr);
 +		else
  		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
  	}

 +	if (isc->use_pio)
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	else
  	bus_space_barrier(sc->bt, sc->bh, ooffset, osize,
  			  BUS_SPACE_BARRIER_WRITE);
  }

 +static void
 +ix_bus_barrier(sc, offset, length, flags)
 +        struct ie_softc *sc;
 +        int offset, length, flags;
 +{
 +	struct ix_softc* isc = (struct ix_softc *) sc;
 +
 +	if (isc->use_pio)
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2, flags);
 +	else
 +		bus_space_barrier(sc->bt, sc->bh, offset, length, flags);
 +}
 +
  static u_int16_t
  ix_read_16 (sc, offset)
          struct ie_softc *sc;
          int offset;
  {
 -	bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_READ);
 +	struct ix_softc* isc = (struct ix_softc *) sc;
 +
 +	if (isc->use_pio) {
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2,
 +						  BUS_SPACE_BARRIER_READ);
 +
 +		/* Reset read pointer to the specified offset */
 +		bus_space_write_2(sc->bt, sc->bh, IX_READPTR, offset);
 +		bus_space_barrier(sc->bt, sc->bh, IX_READPTR, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +
 +		return bus_space_read_2(sc->bt, sc->bh, IX_DATAPORT);
 +	} else {
 +		bus_space_barrier(sc->bt, sc->bh, offset, 2, 
 +						  BUS_SPACE_BARRIER_READ);
          return bus_space_read_2(sc->bt, sc->bh, offset);
 +	}
  }

  static void
 @@ -323,8 +412,22 @@
          int offset;
          u_int16_t value;
  {
 +	struct ix_softc* isc = (struct ix_softc *) sc;
 +
 +	if (isc->use_pio) {
 +		/* Reset write pointer to the specified offset */
 +		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, offset);
 +		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +
 +		bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT, value);
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	} else {
          bus_space_write_2(sc->bt, sc->bh, offset, value);
 -	bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_WRITE);
 +		bus_space_barrier(sc->bt, sc->bh, offset, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	}
  }

  static void
 @@ -332,12 +435,67 @@
          struct ie_softc *sc;
          int offset, addr;
  {
 -        bus_space_write_4(sc->bt, sc->bh, offset, addr +
 -			  (u_long) sc->sc_maddr - (u_long) sc->sc_iobase);
 -	bus_space_barrier(sc->bt, sc->bh, offset, 4, BUS_SPACE_BARRIER_WRITE);
 +	char* ptr;
 +	struct ix_softc* isc = (struct ix_softc *) sc;
 +	int val = addr + (u_long) sc->sc_maddr - (u_long) sc->sc_iobase;
 +
 +	if (isc->use_pio) {
 +		/* Reset write pointer to the specified offset */
 +		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, offset);
 +		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +
 +		ptr = (char*) &val;
 +		bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT, 
 +						  *((u_int16_t *)ptr));
 +		bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT, 
 +						  *((u_int16_t *)(ptr + 2)));
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	} else {
 +        	bus_space_write_4(sc->bt, sc->bh, offset, val);
 +		bus_space_barrier(sc->bt, sc->bh, offset, 4, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	}
  }

  static void
 +ix_zeromem(sc, offset, count)
 +        struct ie_softc *sc;
 +        int offset, count;
 +{
 +	int i;
 +	int dribble;
 +	struct ix_softc* isc = (struct ix_softc *) sc;
 +
 +	if (isc->use_pio) {
 +		/* Reset write pointer to the specified offset */
 +		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, offset);
 +		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +
 +		if (offset % 2) {
 +			bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, 0);
 +			count--;
 +		}
 +
 +	        dribble = count % 2;
 +		for(i = 0; i < count / 2; i++)
 +			bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT, 0);
 +
 +		if (dribble)
 +			bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, 0);
 +
 +		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	} else {
 +		bus_space_set_region_1(sc->bt, sc->bh, offset, 0, count);
 +		bus_space_barrier(sc->bt, sc->bh, offset, count, 
 +						  BUS_SPACE_BARRIER_WRITE);
 +	}
 +}
 +
 +static void
  ix_mediastatus(sc, ifmr)
          struct ie_softc *sc;
          struct ifmediareq *ifmr;
 @@ -414,22 +572,24 @@
  	 */

  	val = ix_read_eeprom(iot, ioh, 6) & 0xff;
 -	DPRINTF(("memory config: 0x%02x\n", val));
 -
 -	for(i = 0; i < 8; i++) {
 +	for(pg = 0; pg < 8; pg++) {
  		if (val & 1)
  			break;
  		val = val >> 1;
  	}

 -	if (i == 8) {
 +	if (pg == 8) {
  		DPRINTF(("Invalid or unsupported memory config\n"));
  		goto out;
  	}

 -	maddr = 0xc0000 + (i * 0x4000);
 +	maddr = 0xc0000 + (pg * 0x4000);

  	switch (val) {
 +	case 0x00:
 +		msize = 0;
 +		break;
 +
  	case 0x01:
  		msize = 16 * 1024;
  		break;
 @@ -469,9 +629,6 @@
  		goto out;
  	}

 -	DPRINTF(("found %d byte memory region at %x\n",
 -		ia->ia_msize, ia->ia_maddr));
 -
  	/* need to put the 586 in RESET, and leave it */
  	bus_space_write_1(iot, ioh, IX_ECTRL, IX_RESET_586);

 @@ -486,26 +643,24 @@
  	}

  	/*
 -	 * Size and test the memory on the board.  The size of the memory
 -	 * can be one of 16k, 32k, 48k or 64k.  It can be located in the
 -	 * address range 0xC0000 to 0xEFFFF on 16k boundaries.
 +	 * Only do the following bit if using memory-mapped access.  For 
 +	 * boards with no mapped memory, we use PIO.  We also use PIO for
 +	 * boards with 16K of mapped memory, as those setups don't seem
 +	 * to work otherwise.
  	 */
 -	pg = (ia->ia_maddr & 0x3C000) >> 14;
 +	if (msize != 0 && msize != 16384) {
 +		/* Set board up with memory-mapping info */
  	adjust = IX_MCTRL_FMCS16 | (pg & 0x3) << 2;
  	decode = ((1 << (ia->ia_msize / 16384)) - 1) << pg;
  	edecode = ((~decode >> 4) & 0xF0) | (decode >> 8);

 -	/* ZZZ This should be checked against eeprom location 6, low byte */
  	bus_space_write_1(iot, ioh, IX_MEMDEC, decode & 0xFF);
 -
 -	/* ZZZ This should be checked against eeprom location 1, low byte */
  	bus_space_write_1(iot, ioh, IX_MCTRL, adjust);
 -
 -	/* ZZZ Now if I could find this one I would have it made */
  	bus_space_write_1(iot, ioh, IX_MPCTRL, (~decode & 0xFF));

 -	/* ZZZ I think this is location 6, high byte */
 -	bus_space_write_1(iot, ioh, IX_MECTRL, edecode); /*XXX disable Exxx */
 +		/* XXX disable Exxx */
 +		bus_space_write_1(iot, ioh, IX_MECTRL, edecode); 
 +	}

  	/*
  	 * Get the encoded interrupt number from the EEPROM, check it
 @@ -555,15 +710,24 @@
  	struct isa_attach_args *ia = aux;

  	int media;
 -	u_short eaddrtemp;
 +	int i, memsize;
  	u_int8_t bart_config;
  	bus_space_tag_t iot;
 +	u_int8_t bpat, bval;
 +	u_int16_t wpat, wval;
  	bus_space_handle_t ioh, memh;
  	u_short irq_encoded;
  	u_int8_t ethaddr[ETHER_ADDR_LEN];

  	iot = ia->ia_iot;

 +	/* 
 +	 * Shared memory access seems to fail on 16K mapped boards, so
 +	 * disable shared memory access if the board is in 16K mode.  If 
 +	 * no memory is mapped, we have no choice but to use PIO
 +	 */
 +	isc->use_pio = (ia->ia_msize <= (16 * 1024));
 +
  	if (bus_space_map(iot, ia->ia_iobase,
  			  ia->ia_iosize, 0, &ioh) != 0) {

 @@ -573,15 +737,17 @@
  		return;
  	}

 +	/* We map memory even if using PIO so something else doesn't grab it */
 +	if (ia->ia_msize) {
  	if (bus_space_map(ia->ia_memt, ia->ia_maddr,
  			  ia->ia_msize, 0, &memh) != 0) {
 -
  		DPRINTF(("\n%s: can't map iomem space 0x%x-0x%x\n",
  			sc->sc_dev.dv_xname, ia->ia_maddr,
  			ia->ia_maddr + ia->ia_msize - 1));
  		bus_space_unmap(iot, ioh, ia->ia_iosize);
  		return;
  	}
 +	}

  	isc->sc_regt = iot;
  	isc->sc_regh = ioh;
 @@ -590,15 +756,15 @@
  	 * Get the hardware ethernet address from the EEPROM and
  	 * save it in the softc for use by the 586 setup code.
  	 */
 -	eaddrtemp = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_HIGH);
 -	ethaddr[1] = eaddrtemp & 0xFF;
 -	ethaddr[0] = eaddrtemp >> 8;
 -	eaddrtemp = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_MID);
 -	ethaddr[3] = eaddrtemp & 0xFF;
 -	ethaddr[2] = eaddrtemp >> 8;
 -	eaddrtemp = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_LOW);
 -	ethaddr[5] = eaddrtemp & 0xFF;
 -	ethaddr[4] = eaddrtemp >> 8;
 +	wval = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_HIGH);
 +	ethaddr[1] = wval & 0xFF;
 +	ethaddr[0] = wval >> 8;
 +	wval = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_MID);
 +	ethaddr[3] = wval & 0xFF;
 +	ethaddr[2] = wval >> 8;
 +	wval = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_LOW);
 +	ethaddr[5] = wval & 0xFF;
 +	ethaddr[4] = wval >> 8;

  	sc->hwinit = NULL;
  	sc->hwreset = ix_reset;
 @@ -607,6 +773,14 @@

  	sc->memcopyin = ix_copyin;
  	sc->memcopyout = ix_copyout;
 +
 +	/* If using PIO, make sure to setup single-byte read/write functions */
 +	if (isc->use_pio) {
 +		sc->ie_bus_barrier = ix_bus_barrier;
 +	} else {
 +		sc->ie_bus_barrier = NULL;
 +	}
 +
  	sc->ie_bus_read16 = ix_read_16;
  	sc->ie_bus_write16 = ix_write_16;
  	sc->ie_bus_write24 = ix_write_24;
 @@ -616,12 +790,115 @@
  	sc->sc_mediachange = NULL;
  	sc->sc_mediastatus = ix_mediastatus;

 +	if (isc->use_pio) {
 +		sc->bt = iot;
 +		sc->bh = ioh;
 +
 +		/* 
 +		 * If using PIO, the memory size is bounded by on-card memory, 
 +		 * not by how much is mapped into the memory-mapped region, so 
 +		 * determine how much total memory we have to play with here.  
 +		 */
 +		for(memsize = 64 * 1024; memsize; memsize -= 16 * 1024) {
 +			/* warm up shared memory, the zero it all out */
 +			ix_zeromem(sc, 0, 32);
 +			ix_zeromem(sc, 0, memsize);
 +
 +			/* Reset write pointer to the start of RAM */
 +			bus_space_write_2(iot, ioh, IX_WRITEPTR, 0);
 +			bus_space_barrier(iot, ioh, IX_WRITEPTR, 2, 
 +						    BUS_SPACE_BARRIER_WRITE);
 +
 +			/* write test pattern */
 +			for(i = 0; i < memsize; i += 2) {
 +				bus_space_write_2(iot, ioh, IX_DATAPORT, wpat);
 +				wpat += 3;
 +			}
 +
 +			/* Flush all reads & writes to data port */
 +			bus_space_barrier(iot, ioh, IX_DATAPORT, 2, 
 +						    BUS_SPACE_BARRIER_READ |
 +						    BUS_SPACE_BARRIER_WRITE);
 +
 +			/* Reset read pointer to beginning of card RAM */
 +			bus_space_write_2(iot, ioh, IX_READPTR, 0);
 +			bus_space_barrier(iot, ioh, IX_READPTR, 2, 
 +						    BUS_SPACE_BARRIER_WRITE);
 +
 +			/* read and verify test pattern */
 +			for(i = 0, wpat = 1; i < memsize; i += 2) {
 +				wval = bus_space_read_2(iot, ioh, IX_DATAPORT);
 +
 +				if (wval != wpat)
 +					break;
 +
 +				wpat += 3;
 +			}
 +
 +			/* If we failed, try next size down */
 +			if (i != memsize)
 +				continue;
 +
 +			/* Now try it all with byte reads/writes */
 +			ix_zeromem(sc, 0, 32);
 +			ix_zeromem(sc, 0, memsize);
 +
 +			/* Reset write pointer to start of card RAM */
 +			bus_space_write_2(iot, ioh, IX_WRITEPTR, 0);
 +			bus_space_barrier(iot, ioh, IX_WRITEPTR, 2, 
 +						    BUS_SPACE_BARRIER_WRITE);
 +
 +			/* write out test pattern */
 +			for(i = 0, bpat = 1; i < memsize; i++) {
 +				bus_space_write_1(iot, ioh, IX_DATAPORT, bpat);
 +				bpat += 3;
 +			}
 +
 +			/* Flush all reads & writes to data port */
 +			bus_space_barrier(iot, ioh, IX_DATAPORT, 2, 
 +						    BUS_SPACE_BARRIER_READ |
 +						    BUS_SPACE_BARRIER_WRITE);
 +
 +			/* Reset read pointer to beginning of card RAM */
 +			bus_space_write_2(iot, ioh, IX_READPTR, 0);
 +			bus_space_barrier(iot, ioh, IX_READPTR, 2, 
 +						    BUS_SPACE_BARRIER_WRITE);
 +
 +			/* read and verify test pattern */
 +			for(i = 0, bpat = 1; i < memsize; i++) {
 +				bval = bus_space_read_1(iot, ioh, IX_DATAPORT);
 +
 +				if (bval != bpat)
 +				bpat += 3;
 +			}
 +
 +			/* If we got through all of memory, we're done! */ 
 +			if (i == memsize)
 +				break;
 +		}
 +
 +		/* Memory tests failed, punt... */
 +		if (memsize == 0)  {
 +			DPRINTF(("\n%s: can't determine size of on-card RAM\n",
 +				sc->sc_dev.dv_xname));
 +			bus_space_unmap(iot, ioh, ia->ia_iosize);
 +			return;
 +		}
 +
 +		sc->bt = iot;
 +		sc->bh = ioh;
 +
 +		sc->sc_msize = memsize;
 +		sc->sc_maddr = (void*) 0;
 +	} else {
  	sc->bt = ia->ia_memt;
  	sc->bh = memh;

 -	/* Map i/o space. */
  	sc->sc_msize = ia->ia_msize;
  	sc->sc_maddr = (void *)memh;
 +	}
 +
 +	/* Map i/o space. */
  	sc->sc_iobase = (char *)sc->sc_maddr + sc->sc_msize - (1 << 24);

  	/* set up pointers to important on-card control structures */
 @@ -633,24 +910,42 @@
  	sc->buf_area_sz = sc->sc_msize - IE_ISCP_SZ - IE_SCB_SZ - IE_SCP_SZ;

  	/* zero card memory */
 -	bus_space_set_region_1(sc->bt, sc->bh, 0, 0, 32);
 -	bus_space_set_region_1(sc->bt, sc->bh, 0, 0, sc->sc_msize);
 +	ix_zeromem(sc, 0, 32);
 +	ix_zeromem(sc, 0, sc->sc_msize);

  	/* set card to 16-bit bus mode */
 -	bus_space_write_1(sc->bt, sc->bh, IE_SCP_BUS_USE((u_long)sc->scp), 0);
 +	if (isc->use_pio) {
 +		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, 
 +				  	    IE_SCP_BUS_USE((u_long)sc->scp));
 +		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2,
 +					          BUS_SPACE_BARRIER_WRITE);

 +		bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, 0);
 +	} else {
 +		bus_space_write_1(sc->bt, sc->bh, 
 +				  IE_SCP_BUS_USE((u_long)sc->scp), 0);
 +	}
 +
  	/* set up pointers to key structures */
  	ix_write_24(sc, IE_SCP_ISCP((u_long)sc->scp), (u_long) sc->iscp);
  	ix_write_16(sc, IE_ISCP_SCB((u_long)sc->iscp), (u_long) sc->scb);
  	ix_write_24(sc, IE_ISCP_BASE((u_long)sc->iscp), (u_long) sc->iscp);

  	/* flush setup of pointers, check if chip answers */
 +	if (isc->use_pio) {
 +		bus_space_barrier(sc->bt, sc->bh, 0, IX_IOSIZE,
 +				  BUS_SPACE_BARRIER_WRITE);
 +	} else {
  	bus_space_barrier(sc->bt, sc->bh, 0, sc->sc_msize,
  			  BUS_SPACE_BARRIER_WRITE);
 +	}
 +
  	if (!i82586_proberam(sc)) {
  		DPRINTF(("\n%s: Can't talk to i82586!\n",
  			sc->sc_dev.dv_xname));
  		bus_space_unmap(iot, ioh, ia->ia_iosize);
 +
 +		if (ia->ia_msize)
  		bus_space_unmap(ia->ia_memt, memh, ia->ia_msize);
  		return;
  	}
 @@ -681,10 +976,16 @@
  	bus_space_write_1(iot, ioh, IX_IRQ,
  			  irq_encoded | IX_IRQ_ENABLE);

 +	/* Flush all writes to registers */
 +	bus_space_barrier(iot, ioh, 0, ia->ia_iosize, BUS_SPACE_BARRIER_WRITE);
 +
  	isc->irq_encoded = irq_encoded;

  	i82586_attach(sc, "EtherExpress/16", ethaddr,
  		      ix_media, NIX_MEDIA, media);
 +
 +	if (isc->use_pio)
 +		printf("%s: unsupported memory config, using PIO to access %d bytes of memory\n", sc->sc_dev.dv_xname, sc->sc_msize);

  	isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
  					IPL_NET, i82586_intr, sc);
 cvs server: I know nothing about if_ix.c.orig
 Index: if_ixreg.h
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/isa/if_ixreg.h,v
 retrieving revision 1.2
 diff -b -u -b -u -r1.2 if_ixreg.h
 --- if_ixreg.h	1998/02/28 20:43:28	1.2
 +++ if_ixreg.h	2001/01/14 17:53:11
 @@ -38,9 +38,15 @@

  #define IX_IOSIZE	16	/* card has 16 registers in IO space */

 +#define IX_DATAPORT  		0x00	/* shared memory data port */
 +#define IX_WRITEPTR  		0x02	/* shared memory write pointer */
 +#define IX_READPTR  		0x04	/* shared memory read pointer */
 +
  #define IX_ATTN			0x06	/* channel attention control */
  #define IX_IRQ			0x07	/* IRQ configuration */
  #define IX_IRQ_ENABLE		0x08	/* enable board interrupts */
 +
 +#define IX_SHADOWPTR  		0x08	/* shadow memory pointer */

  #define IX_MEMDEC		0x0a	/* memory decode */
  #define IX_MCTRL		0x0b	/* memory control */
 Index: dev/vme/if_ie_vme.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/vme/if_ie_vme.c,v
 retrieving revision 1.11
 diff -b -u -r1.11 if_ie_vme.c
 --- if_ie_vme.c	2000/07/10 13:54:54	1.11
 +++ if_ie_vme.c	2001/01/14 17:45:00
 @@ -525,6 +525,8 @@
  	sc->intrhook = ie_vmeintr;
  	sc->memcopyout = ie_memcopyout;
  	sc->memcopyin = ie_memcopyin;
 +
 +	sc->ie_bus_barrier = NULL;
  	sc->ie_bus_read16 = ie_vme_read16;
  	sc->ie_bus_write16 = ie_vme_write16;
  	sc->ie_bus_write24 = ie_vme_write24;
 ----
 Rafal Boni                                                   rafal@mediaone.net

From: Ben Harris <bjh21@netbsd.org>
To: Rafal Boni <rafal@mediaone.net>
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/8001
Date: Mon, 15 Jan 2001 11:27:47 +0000 (GMT)

 On Sun, 14 Jan 2001, Rafal Boni wrote:

 > Since Ben was grossed out by my over-parenthesizing all callbacks through
 > the softc functions as '(sc->ie_bus_read16)(args)', I've gone the other 
 > way and converted all the callbacks to read 'sc->ie_bus_read16 (args)'
 > instead

 It wasn't the parentheses I cared about, it was gratuitously including
 those changes in the same patch as your functionality changes, so I had to
 wade through several paren-fixes for every substantive change.  Luckily,
 this way round, the number of paren changes is small enough not to matter.

 > I've also attempted to fix up all front ends based on the 82586 MI
 > core to incorporate the new 'ie_bus_barrier' callback (which is only
 > used on the 'ix' driver and is NULL on the rest, thus falling back 
 > to standard bus_space_barrier() calls).

 FWIW, device softc structures are zeroed when they're allocated anyway, so
 it's not strictly necessary to zero new members yourself.

 > Please let me know if there's anything else I can do to help get this
 > finally in the tree.

 Glancing through it, it looks like the changes to the MI i82586 driver are
 minimal.  Since you're the nearest thing we've got to a maintainer for the
 "ix" driver, I doubt there'll be any problems with merging this, but it'll
 have to wait till I get home so I can check the "ei" driver still works.

 Thanks for your work on this driver.

 -- 
 Ben Harris                                                   <bjh21@netbsd.org>
 Portmaster, NetBSD/arm26               <URL:http://www.netbsd.org/Ports/arm26/>


From: Rafal Boni <rafal@mediaone.net>
To: Ben Harris <bjh21@netbsd.org>
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/8001 
Date: Mon, 15 Jan 2001 08:28:54 -0500

 In message <Pine.SOL.4.21.0101151121250.25557-100000@draco.cus.cam.ac.uk>, you 
 write: 

 -> It wasn't the parentheses I cared about, it was gratuitously including
 -> those changes in the same patch as your functionality changes, so I had to
 -> wade through several paren-fixes for every substantive change.  Luckily,
 -> this way round, the number of paren changes is small enough not to matter.

 Makes sense... Though the changes were pretty mechanical, I can understand
 why wading through four pages of mechanical, stylistic diffs for a few lines
 of functional diffs would suck 8-)

 [...]
 -> FWIW, device softc structures are zeroed when they're allocated anyway, so
 -> it's not strictly necessary to zero new members yourself.

 I was aware of that, but figured since it's a one-time initialization cost it
 was easier to explicitly set the bus_barrier callback to NULL more as a form
 of documentation than anything else.

 -> Glancing through it, it looks like the changes to the MI i82586 driver are
 -> minimal.  Since you're the nearest thing we've got to a maintainer for the
 -> "ix" driver, I doubt there'll be any problems with merging this, but it'll
 -> have to wait till I get home so I can check the "ei" driver still works.

 No problem.  I appreciate your looking at this so quickly (and the long mail
 exchange earlier that got me to get off my duff and update this for the new
 state of the world).

 -> Thanks for your work on this driver.

 Thanks for looking at the PR!
 --rafal

 ----
 Rafal Boni                                                  rafal@mediaone.net
State-Changed-From-To: open->feedback 
State-Changed-By: bjh21 
State-Changed-When: Mon Jan 22 14:29:08 PST 2001 
State-Changed-Why:  
I've applied the final patch.  Could the submitter please confirm whether the 
problem is now fixed?  (this needs if_ix.c rev 1.7 or later) 
Responsible-Changed-From-To: kern-bug-people->bjh21 
Responsible-Changed-By: bjh21 
Responsible-Changed-When: Mon Jan 22 14:32:14 PST 2001 
Responsible-Changed-Why:  
I was reckless enough as to apply the patch. 
State-Changed-From-To: feedback->closed 
State-Changed-By: fair 
State-Changed-When: Thu Mar 22 15:10:33 PST 2001 
State-Changed-Why:  
submitter has vanished - E-mail bounces. Since patch has been applied, 
I deem this PR resolved. 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.