patch-2.4.20 linux-2.4.20/drivers/net/natsemi.c

Next file: linux-2.4.20/drivers/net/ni65.c
Previous file: linux-2.4.20/drivers/net/mii.c
Back to the patch index
Back to the overall index

diff -urN linux-2.4.19/drivers/net/natsemi.c linux-2.4.20/drivers/net/natsemi.c
@@ -1,7 +1,8 @@
 /* natsemi.c: A Linux PCI Ethernet driver for the NatSemi DP8381x series. */
 /*
 	Written/copyright 1999-2001 by Donald Becker.
-	Portions copyright (c) 2001 Sun Microsystems (thockin@sun.com)
+	Portions copyright (c) 2001,2002 Sun Microsystems (thockin@sun.com)
+	Portions copyright 2001,2002 Manfred Spraul (manfred@colorfullife.com)
 
 	This software may be used and distributed according to the terms of
 	the GNU General Public License (GPL), incorporated herein by reference.
@@ -86,7 +87,7 @@
 		* use long for ee_addr (various)
 		* print pointers properly (DaveM)
 		* include asm/irq.h (?)
-	
+
 	version 1.0.11:
 		* check and reset if PHY errors appear (Adrian Sun)
 		* WoL cleanup (Tim Hockin)
@@ -100,18 +101,42 @@
 		* ETHTOOL_* further support (Tim Hockin)
 
 	version 1.0.13:
-		* ETHTOOL_GEEPROM support (Tim Hockin)
+		* ETHTOOL_[G]EEPROM support (Tim Hockin)
+
+	version 1.0.13:
+		* crc cleanup (Matt Domsch <Matt_Domsch@dell.com>)
 
 	version 1.0.14:
 		* Cleanup some messages and autoneg in ethtool (Tim Hockin)
 
-	version 1.0.13:
-		* crc cleanup (Matt Domsch <Matt_Domsch@dell.com>)
+	version 1.0.15:
+		* Get rid of cable_magic flag
+		* use new (National provided) solution for cable magic issue
+
+	version 1.0.16:
+		* call netdev_rx() for RxErrors (Manfred Spraul)
+		* formatting and cleanups
+		* change options and full_duplex arrays to be zero
+		  initialized
+		* enable only the WoL and PHY interrupts in wol mode
+
+	version 1.0.17:
+		* only do cable_magic on 83815 and early 83816 (Tim Hockin)
+		* create a function for rx refill (Manfred Spraul)
+		* combine drain_ring and init_ring (Manfred Spraul)
+		* oom handling (Manfred Spraul)
+		* hands_off instead of playing with netif_device_{de,a}ttach
+		  (Manfred Spraul)
+		* be sure to write the MAC back to the chip (Manfred Spraul)
+		* lengthen EEPROM timeout, and always warn about timeouts
+		  (Manfred Spraul)
+		* comments update (Manfred)
+		* do the right thing on a phy-reset (Manfred and Tim)
 
 	TODO:
 	* big endian support with CFG:BEM instead of cpu_to_le32
 	* support for an external PHY
-	* flow control
+	* NAPI
 */
 
 #if !defined(__OPTIMIZE__)
@@ -146,23 +171,11 @@
 #include <asm/uaccess.h>
 
 #define DRV_NAME	"natsemi"
-#define DRV_VERSION	"1.07+LK1.0.14"
-#define DRV_RELDATE	"Nov 27, 2001"
+#define DRV_VERSION	"1.07+LK1.0.17"
+#define DRV_RELDATE	"Sep 27, 2002"
 
 /* Updated to recommendations in pci-skeleton v2.03. */
 
-/* Automatically extracted configuration info:
-probe-func: natsemi_probe
-config-in: tristate 'National Semiconductor DP8381x series PCI Ethernet support' CONFIG_NATSEMI
-
-c-help-name: National Semiconductor DP8381x series PCI Ethernet support
-c-help-symbol: CONFIG_NATSEMI
-c-help: This driver is for the National Semiconductor DP8381x series,
-c-help: including the 8381[56] chips.
-c-help: More specific information and updates are available from 
-c-help: http://www.scyld.com/network/natsemi.html
-*/
-
 /* The user-configurable values.
    These may be modified when a driver module is loaded.*/
 
@@ -171,7 +184,7 @@
 				 NETIF_MSG_WOL		| \
 				 NETIF_MSG_RX_ERR	| \
 				 NETIF_MSG_TX_ERR)
-static int debug = NATSEMI_DEF_MSG;
+static int debug = -1;
 
 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
 static int max_interrupt_work = 20;
@@ -191,8 +204,8 @@
    The media type is usually passed in 'options[]'.
 */
 #define MAX_UNITS 8		/* More are supported, limit only on options */
-static int options[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
-static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
+static int options[MAX_UNITS];
+static int full_duplex[MAX_UNITS];
 
 /* Operational parameters that are set at compile time. */
 
@@ -203,7 +216,7 @@
    There are no ill effects from too-large receive rings. */
 #define TX_RING_SIZE	16
 #define TX_QUEUE_LEN	10 /* Limit ring entries actually used, min 4. */
-#define RX_RING_SIZE	64
+#define RX_RING_SIZE	32
 
 /* Operational parameters that usually are not changed. */
 /* Time in jiffies before concluding the transmitter is hung. */
@@ -224,9 +237,11 @@
 
 /* These identify the driver base version and may not be removed. */
 static char version[] __devinitdata =
-KERN_INFO DRV_NAME ".c:v1.07 1/9/2001  Written by Donald Becker <becker@scyld.com>\n"
-KERN_INFO "  http://www.scyld.com/network/natsemi.html\n"
-KERN_INFO "  (unofficial 2.4.x kernel port, version " DRV_VERSION ", " DRV_RELDATE "  Jeff Garzik, Tjeerd Mulder)\n";
+  KERN_INFO DRV_NAME " dp8381x driver, version "
+      DRV_VERSION ", " DRV_RELDATE "\n"
+  KERN_INFO "  originally by Donald Becker <becker@scyld.com>\n"
+  KERN_INFO "  http://www.scyld.com/network/natsemi.html\n"
+  KERN_INFO "  2.4.x kernel port by Jeff Garzik, Tjeerd Mulder\n";
 
 MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
 MODULE_DESCRIPTION("National Semiconductor DP8381x series PCI Ethernet driver");
@@ -238,11 +253,14 @@
 MODULE_PARM(rx_copybreak, "i");
 MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
 MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
-MODULE_PARM_DESC(max_interrupt_work, "DP8381x maximum events handled per interrupt");
+MODULE_PARM_DESC(max_interrupt_work, 
+	"DP8381x maximum events handled per interrupt");
 MODULE_PARM_DESC(mtu, "DP8381x MTU (all boards)");
-MODULE_PARM_DESC(debug, "DP8381x debug bitmask");
-MODULE_PARM_DESC(rx_copybreak, "DP8381x copy breakpoint for copy-only-tiny-frames");
-MODULE_PARM_DESC(options, "DP8381x: Bits 0-3: media type, bit 17: full duplex");
+MODULE_PARM_DESC(debug, "DP8381x default debug level");
+MODULE_PARM_DESC(rx_copybreak, 
+	"DP8381x copy breakpoint for copy-only-tiny-frames");
+MODULE_PARM_DESC(options, 
+	"DP8381x: Bits 0-3: media type, bit 17: full duplex");
 MODULE_PARM_DESC(full_duplex, "DP8381x full duplex setting(s) (1)");
 
 /*
@@ -256,7 +274,7 @@
 II. Board-specific settings
 
 This driver requires the PCI interrupt line to be valid.
-It honors the EEPROM-set values. 
+It honors the EEPROM-set values.
 
 III. Driver operation
 
@@ -266,7 +284,7 @@
 formed into rings by a branch from the final descriptor to the beginning of
 the list.  The ring sizes are set at compile time by RX/TX_RING_SIZE.
 The NatSemi design uses a 'next descriptor' pointer that the driver forms
-into a list. 
+into a list.
 
 IIIb/c. Transmit/Receive Structure
 
@@ -295,20 +313,19 @@
 
 IIId. Synchronization
 
-The driver runs as two independent, single-threaded flows of control.  One
-is the send-packet routine, which enforces single-threaded use by the
-dev->tbusy flag.  The other thread is the interrupt handler, which is single
-threaded by the hardware and interrupt handling software.
-
-The send packet thread has partial control over the Tx ring and 'dev->tbusy'
-flag.  It sets the tbusy flag whenever it's queuing a Tx packet. If the next
-queue slot is empty, it clears the tbusy flag when finished otherwise it sets
-the 'lp->tx_full' flag.
-
-The interrupt handler has exclusive control over the Rx ring and records stats
-from the Tx ring.  After reaping the stats, it marks the Tx queue entry as
-empty by incrementing the dirty_tx mark. Iff the 'lp->tx_full' flag is set, it
-clears both the tx_full and tbusy flags.
+Most operations are synchronized on the np->lock irq spinlock, except the
+performance critical codepaths:
+
+The rx process only runs in the interrupt handler. Access from outside
+the interrupt handler is only permitted after disable_irq().
+
+The rx process usually runs under the dev->xmit_lock. If np->intr_tx_reap
+is set, then access is permitted under spin_lock_irq(&np->lock).
+
+Thus configuration functions that want to access everything must call
+	disable_irq(dev->irq);
+	spin_lock_bh(dev->xmit_lock);
+	spin_lock_irq(&np->lock);
 
 IV. Notes
 
@@ -326,7 +343,7 @@
 None characterised.
 */
 
-
+
 
 enum pcistuff {
 	PCI_USES_IO = 0x01,
@@ -367,6 +384,7 @@
 	IntrStatus		= 0x10,
 	IntrMask		= 0x14,
 	IntrEnable		= 0x18,
+	IntrHoldoff		= 0x16, /* DP83816 only */
 	TxRingPtr		= 0x20,
 	TxConfig		= 0x24,
 	RxRingPtr		= 0x30,
@@ -402,14 +420,12 @@
 	SDCFG			= 0xF8
 };
 /* the values for the 'magic' registers above (PGSEL=1) */
-#ifdef CONFIG_NATSEMI_CABLE_MAGIC
-#define PMDCSR_VAL	0x1898
-#else
-#define PMDCSR_VAL	0x189C
-#endif
+#define PMDCSR_VAL	0x189c	/* enable preferred adaptation circuitry */
 #define TSTDAT_VAL	0x0
 #define DSPCFG_VAL	0x5040
-#define SDCFG_VAL	0x008c
+#define SDCFG_VAL	0x008c	/* set voltage thresholds for Signal Detect */
+#define DSPCFG_LOCK	0x20	/* coefficient lock bit in DSPCFG */
+#define TSTDAT_FIXED	0xe8	/* magic number for bad coefficients */
 
 /* misc PCI space registers */
 enum pci_register_offsets {
@@ -477,11 +493,11 @@
 
 /*
  * Default Interrupts:
- * Rx OK, Rx Packet Error, Rx Overrun, 
- * Tx OK, Tx Packet Error, Tx Underrun, 
+ * Rx OK, Rx Packet Error, Rx Overrun,
+ * Tx OK, Tx Packet Error, Tx Underrun,
  * MIB Service, Phy Interrupt, High Bits,
  * Rx Status FIFO overrun,
- * Received Target Abort, Received Master Abort, 
+ * Received Target Abort, Received Master Abort,
  * Signalled System Error, Received Parity Error
  */
 #define DEFAULT_INTR 0x00f1cd65
@@ -578,8 +594,11 @@
 	PhyAddrMask		= 0xf,
 };
 
-#define SRR_REV_C	0x0302
-#define SRR_REV_D	0x0403
+/* values we might find in the silicon revision register */
+#define SRR_DP83815_C	0x0302
+#define SRR_DP83815_D	0x0403
+#define SRR_DP83816_A4	0x0504
+#define SRR_DP83816_A5	0x0505
 
 /* The Rx and Tx buffer descriptors. */
 /* Note that using only 32 bit fields simplifies conversion to big-endian
@@ -594,14 +613,14 @@
 /* Bits in network_desc.status */
 enum desc_status_bits {
 	DescOwn=0x80000000, DescMore=0x40000000, DescIntr=0x20000000,
-	DescNoCRC=0x10000000, DescPktOK=0x08000000, 
+	DescNoCRC=0x10000000, DescPktOK=0x08000000,
 	DescSizeMask=0xfff,
 
-	DescTxAbort=0x04000000, DescTxFIFO=0x02000000, 
+	DescTxAbort=0x04000000, DescTxFIFO=0x02000000,
 	DescTxCarrier=0x01000000, DescTxDefer=0x00800000,
 	DescTxExcDefer=0x00400000, DescTxOOWCol=0x00200000,
 	DescTxExcColl=0x00100000, DescTxCollCount=0x000f0000,
-	
+
 	DescRxAbort=0x04000000, DescRxOver=0x02000000,
 	DescRxDest=0x01800000, DescRxLong=0x00400000,
 	DescRxRunt=0x00200000, DescRxInvalid=0x00100000,
@@ -610,37 +629,45 @@
 };
 
 struct netdev_private {
-	/* Descriptor rings first for alignment. */
+	/* Descriptor rings first for alignment */
 	dma_addr_t ring_dma;
-	struct netdev_desc* rx_ring;
-	struct netdev_desc* tx_ring;
-	/* The addresses of receive-in-place skbuffs. */
-	struct sk_buff* rx_skbuff[RX_RING_SIZE];
+	struct netdev_desc *rx_ring;
+	struct netdev_desc *tx_ring;
+	/* The addresses of receive-in-place skbuffs */
+	struct sk_buff *rx_skbuff[RX_RING_SIZE];
 	dma_addr_t rx_dma[RX_RING_SIZE];
-	/* The saved address of a sent-in-place packet/buffer, for later free(). */
-	struct sk_buff* tx_skbuff[TX_RING_SIZE];
+	/* address of a sent-in-place packet/buffer, for later free() */
+	struct sk_buff *tx_skbuff[TX_RING_SIZE];
 	dma_addr_t tx_dma[TX_RING_SIZE];
 	struct net_device_stats stats;
-	struct timer_list timer;	/* Media monitoring timer. */
-	/* Frequently used values: keep some adjacent for cache effect. */
+	/* Media monitoring timer */
+	struct timer_list timer;
+	/* Frequently used values: keep some adjacent for cache effect */
 	struct pci_dev *pci_dev;
 	struct netdev_desc *rx_head_desc;
-	unsigned int cur_rx, dirty_rx;		/* Producer/consumer ring indices */
+	/* Producer/consumer ring indices */
+	unsigned int cur_rx, dirty_rx;
 	unsigned int cur_tx, dirty_tx;
-	unsigned int rx_buf_sz;				/* Based on MTU+slack. */
-	/* These values are keep track of the transceiver/media in use. */
+	/* Based on MTU+slack. */
+	unsigned int rx_buf_sz;
+	int oom;
+	/* Do not touch the nic registers */
+	int hands_off;
+	/* These values are keep track of the transceiver/media in use */
 	unsigned int full_duplex;
-	/* Rx filter. */
+	/* Rx filter */
 	u32 cur_rx_mode;
 	u32 rx_filter[16];
-	/* FIFO and PCI burst thresholds. */
+	/* FIFO and PCI burst thresholds */
 	u32 tx_config, rx_config;
 	/* original contents of ClkRun register */
 	u32 SavedClkRun;
 	/* silicon revision */
 	u32 srr;
-	/* MII transceiver section. */
-	u16 advertising; /* NWay media advertisement */
+	/* expected DSPCFG value */
+	u16 dspcfg;
+	/* MII transceiver section */
+	u16 advertising;
 	unsigned int iosize;
 	spinlock_t lock;
 	u32 msg_enable;
@@ -653,13 +680,19 @@
 static void natsemi_reload_eeprom(struct net_device *dev);
 static void natsemi_stop_rxtx(struct net_device *dev);
 static int netdev_open(struct net_device *dev);
+static void do_cable_magic(struct net_device *dev);
+static void undo_cable_magic(struct net_device *dev);
 static void check_link(struct net_device *dev);
 static void netdev_timer(unsigned long data);
+static void dump_ring(struct net_device *dev);
 static void tx_timeout(struct net_device *dev);
 static int alloc_ring(struct net_device *dev);
+static void refill_rx(struct net_device *dev);
 static void init_ring(struct net_device *dev);
+static void drain_tx(struct net_device *dev);
 static void drain_ring(struct net_device *dev);
 static void free_ring(struct net_device *dev);
+static void reinit_ring(struct net_device *dev);
 static void init_registers(struct net_device *dev);
 static int start_tx(struct sk_buff *skb, struct net_device *dev);
 static void intr_handler(int irq, void *dev_instance, struct pt_regs *regs);
@@ -682,9 +715,9 @@
 static int netdev_get_regs(struct net_device *dev, u8 *buf);
 static int netdev_get_eeprom(struct net_device *dev, u8 *buf);
 
-
+
 static int __devinit natsemi_probe1 (struct pci_dev *pdev,
-				     const struct pci_device_id *ent)
+	const struct pci_device_id *ent)
 {
 	struct net_device *dev;
 	struct netdev_private *np;
@@ -763,7 +796,8 @@
 	pci_set_drvdata(pdev, dev);
 	np->iosize = iosize;
 	spin_lock_init(&np->lock);
-	np->msg_enable = debug;
+	np->msg_enable = (debug >= 0) ? (1<<debug)-1 : NATSEMI_DEF_MSG;
+	np->hands_off = 0;
 
 	/* Reset the chip to erase previous misconfiguration. */
 	natsemi_reload_eeprom(dev);
@@ -774,15 +808,15 @@
 		option = dev->mem_start;
 
 	/* The lower four bits are the media type. */
-	if (option > 0) {
+	if (option) {
 		if (option & 0x200)
 			np->full_duplex = 1;
 		if (option & 15)
-			printk(KERN_INFO 
+			printk(KERN_INFO
 				"%s: ignoring user supplied media type %d",
 				dev->name, option & 15);
 	}
-	if (find_cnt < MAX_UNITS  &&  full_duplex[find_cnt] > 0)
+	if (find_cnt < MAX_UNITS  &&  full_duplex[find_cnt])
 		np->full_duplex = 1;
 
 	/* The chip-specific entries in the device structure. */
@@ -810,27 +844,28 @@
 
 	if (netif_msg_drv(np)) {
 		printk(KERN_INFO "%s: %s at %#08lx, ",
-			   dev->name, natsemi_pci_info[chip_idx].name, ioaddr);
+			dev->name, natsemi_pci_info[chip_idx].name, ioaddr);
 		for (i = 0; i < ETH_ALEN-1; i++)
 				printk("%02x:", dev->dev_addr[i]);
 		printk("%02x, IRQ %d.\n", dev->dev_addr[i], irq);
 	}
 
 	np->advertising = mdio_read(dev, 1, MII_ADVERTISE);
-	if ((readl(ioaddr + ChipConfig) & 0xe000) != 0xe000 
+	if ((readl(ioaddr + ChipConfig) & 0xe000) != 0xe000
 	 && netif_msg_probe(np)) {
 		u32 chip_config = readl(ioaddr + ChipConfig);
 		printk(KERN_INFO "%s: Transceiver default autonegotiation %s "
-			   "10%s %s duplex.\n",
-			   dev->name,
-			   chip_config & CfgAnegEnable ? "enabled, advertise" : "disabled, force",
-			   chip_config & CfgAneg100 ? "0" : "",
-			   chip_config & CfgAnegFull ? "full" : "half");
+			"10%s %s duplex.\n",
+			dev->name,
+			chip_config & CfgAnegEnable ?
+			  "enabled, advertise" : "disabled, force",
+			chip_config & CfgAneg100 ? "0" : "",
+			chip_config & CfgAnegFull ? "full" : "half");
 	}
 	if (netif_msg_probe(np))
-		printk(KERN_INFO 
+		printk(KERN_INFO
 			"%s: Transceiver status %#04x advertising %#04x.\n",
-			dev->name, mdio_read(dev, 1, MII_BMSR), 
+			dev->name, mdio_read(dev, 1, MII_BMSR),
 			np->advertising);
 
 	/* save the silicon revision for later querying */
@@ -843,7 +878,7 @@
 	return 0;
 }
 
-
+
 /* Read the EEPROM and MII Management Data I/O (MDIO) interfaces.
    The EEPROM code is for the common 93c06/46 EEPROMs with 6 bit addresses. */
 
@@ -897,9 +932,9 @@
 	return retval;
 }
 
-/*  MII transceiver control section.
-	The 83815 series has an internal transceiver, and we present the
-	management registers as if they were MII connected. */
+/* MII transceiver control section.
+ * The 83815 series has an internal transceiver, and we present the
+ * management registers as if they were MII connected. */
 
 static int mdio_read(struct net_device *dev, int phy_id, int reg)
 {
@@ -937,11 +972,11 @@
 	u16 sopass[3];
 	struct netdev_private *np = dev->priv;
 
-	/* 
+	/*
 	 * Resetting the chip causes some registers to be lost.
 	 * Natsemi suggests NOT reloading the EEPROM while live, so instead
 	 * we save the state that would have been loaded from EEPROM
-	 * on a normal power-up (see the spec EEPROM map).  This assumes 
+	 * on a normal power-up (see the spec EEPROM map).  This assumes
 	 * whoever calls this will follow up with init_registers() eventually.
 	 */
 
@@ -969,12 +1004,12 @@
 			break;
 		udelay(5);
 	}
-	if (i==NATSEMI_HW_TIMEOUT && netif_msg_hw(np)) {
-		printk(KERN_INFO "%s: reset did not complete in %d usec.\n",
-		   dev->name, i*5);
+	if (i==NATSEMI_HW_TIMEOUT) {
+		printk(KERN_WARNING "%s: reset did not complete in %d usec.\n",
+			dev->name, i*5);
 	} else if (netif_msg_hw(np)) {
 		printk(KERN_DEBUG "%s: reset completed in %d usec.\n",
-		   dev->name, i*5);
+			dev->name, i*5);
 	}
 
 	/* restore CFG */
@@ -985,7 +1020,7 @@
 	writel(wcsr, dev->base_addr + WOLCmd);
 	/* read RFCR */
 	rfcr |= readl(dev->base_addr + RxFilterAddr) & ~RFCR_RESET_SAVE;
-	/* restore PMATCH */ 
+	/* restore PMATCH */
 	for (i = 0; i < 3; i++) {
 		writel(i*2, dev->base_addr + RxFilterAddr);
 		writew(pmatch[i], dev->base_addr + RxFilterData);
@@ -996,7 +1031,6 @@
 	}
 	/* restore RFCR */
 	writel(rfcr, dev->base_addr + RxFilterAddr);
-	
 }
 
 static void natsemi_reload_eeprom(struct net_device *dev)
@@ -1006,16 +1040,16 @@
 
 	writel(EepromReload, dev->base_addr + PCIBusCfg);
 	for (i=0;i<NATSEMI_HW_TIMEOUT;i++) {
+		udelay(50);
 		if (!(readl(dev->base_addr + PCIBusCfg) & EepromReload))
 			break;
-		udelay(5);
 	}
-	if (i==NATSEMI_HW_TIMEOUT && netif_msg_hw(np)) {
-		printk(KERN_INFO "%s: EEPROM did not reload in %d usec.\n",
-		   dev->name, i*5);
+	if (i==NATSEMI_HW_TIMEOUT) {
+		printk(KERN_WARNING "%s: EEPROM did not reload in %d usec.\n",
+			dev->name, i*50);
 	} else if (netif_msg_hw(np)) {
 		printk(KERN_DEBUG "%s: EEPROM reloaded in %d usec.\n",
-		   dev->name, i*5);
+			dev->name, i*50);
 	}
 }
 
@@ -1031,12 +1065,12 @@
 			break;
 		udelay(5);
 	}
-	if (i==NATSEMI_HW_TIMEOUT && netif_msg_hw(np)) {
-		printk(KERN_INFO "%s: Tx/Rx process did not stop in %d usec.\n",
-				dev->name, i*5);
+	if (i==NATSEMI_HW_TIMEOUT) {
+		printk(KERN_WARNING "%s: Tx/Rx process did not stop in %d usec.\n",
+			dev->name, i*5);
 	} else if (netif_msg_hw(np)) {
 		printk(KERN_DEBUG "%s: Tx/Rx process stopped in %d usec.\n",
-				dev->name, i*5);
+			dev->name, i*5);
 	}
 }
 
@@ -1054,7 +1088,7 @@
 
 	if (netif_msg_ifup(np))
 		printk(KERN_DEBUG "%s: netdev_open() irq %d.\n",
-			   dev->name, dev->irq);
+			dev->name, dev->irq);
 	i = alloc_ring(dev);
 	if (i < 0) {
 		free_irq(dev->irq, dev);
@@ -1063,13 +1097,21 @@
 	init_ring(dev);
 	spin_lock_irq(&np->lock);
 	init_registers(dev);
+	/* now set the MAC address according to dev->dev_addr */
+	for (i = 0; i < 3; i++) {
+		u16 mac = (dev->dev_addr[2*i+1]<<8) + dev->dev_addr[2*i];
+
+		writel(i*2, ioaddr + RxFilterAddr);
+		writew(mac, ioaddr + RxFilterData);
+	}
+	writel(np->cur_rx_mode, ioaddr + RxFilterAddr);
 	spin_unlock_irq(&np->lock);
 
 	netif_start_queue(dev);
 
 	if (netif_msg_ifup(np))
 		printk(KERN_DEBUG "%s: Done netdev_open(), status: %#08x.\n",
-			   dev->name, (int)readl(ioaddr + ChipCmd));
+			dev->name, (int)readl(ioaddr + ChipCmd));
 
 	/* Set the timer to check for link beat. */
 	init_timer(&np->timer);
@@ -1081,6 +1123,62 @@
 	return 0;
 }
 
+static void do_cable_magic(struct net_device *dev)
+{
+	struct netdev_private *np = dev->priv;
+
+	if (np->srr >= SRR_DP83816_A5)
+		return;
+
+	/*
+	 * 100 MBit links with short cables can trip an issue with the chip.
+	 * The problem manifests as lots of CRC errors and/or flickering
+	 * activity LED while idle.  This process is based on instructions
+	 * from engineers at National.
+	 */
+	if (readl(dev->base_addr + ChipConfig) & CfgSpeed100) {
+		u16 data;
+
+		writew(1, dev->base_addr + PGSEL);
+		/*
+		 * coefficient visibility should already be enabled via
+		 * DSPCFG | 0x1000
+		 */
+		data = readw(dev->base_addr + TSTDAT) & 0xff;
+		/*
+		 * the value must be negative, and within certain values
+		 * (these values all come from National)
+		 */
+		if (!(data & 0x80) || ((data >= 0xd8) && (data <= 0xff))) {
+			struct netdev_private *np = dev->priv;
+
+			/* the bug has been triggered - fix the coefficient */
+			writew(TSTDAT_FIXED, dev->base_addr + TSTDAT);
+			/* lock the value */
+			data = readw(dev->base_addr + DSPCFG);
+			np->dspcfg = data | DSPCFG_LOCK;
+			writew(np->dspcfg, dev->base_addr + DSPCFG);
+		}
+		writew(0, dev->base_addr + PGSEL);
+	}
+}
+
+static void undo_cable_magic(struct net_device *dev)
+{
+	u16 data;
+	struct netdev_private *np = dev->priv;
+
+	if (np->srr >= SRR_DP83816_A5)
+		return;
+
+	writew(1, dev->base_addr + PGSEL);
+	/* make sure the lock bit is clear */
+	data = readw(dev->base_addr + DSPCFG);
+	np->dspcfg = data & ~DSPCFG_LOCK;
+	writew(np->dspcfg, dev->base_addr + DSPCFG);
+	writew(0, dev->base_addr + PGSEL);
+}
+
 static void check_link(struct net_device *dev)
 {
 	struct netdev_private *np = dev->priv;
@@ -1091,9 +1189,10 @@
 	if (!(chipcfg & CfgLink)) {
 		if (netif_carrier_ok(dev)) {
 			if (netif_msg_link(np))
-				printk(KERN_NOTICE "%s: link down.\n", 
+				printk(KERN_NOTICE "%s: link down.\n",
 					dev->name);
 			netif_carrier_off(dev);
+			undo_cable_magic(dev);
 		}
 		return;
 	}
@@ -1101,6 +1200,7 @@
 		if (netif_msg_link(np))
 			printk(KERN_NOTICE "%s: link up.\n", dev->name);
 		netif_carrier_on(dev);
+		do_cable_magic(dev);
 	}
 
 	duplex = np->full_duplex || (chipcfg & CfgFullDuplex ? 1 : 0);
@@ -1108,7 +1208,7 @@
 	/* if duplex is set then bit 28 must be set, too */
 	if (duplex ^ !!(np->rx_config & RxAcceptTx)) {
 		if (netif_msg_link(np))
-			printk(KERN_INFO 
+			printk(KERN_INFO
 				"%s: Setting %s-duplex based on negotiated "
 				"link capability.\n", dev->name,
 				duplex ? "full" : "half");
@@ -1136,16 +1236,16 @@
 		udelay(10);
 	}
 	if (i==NATSEMI_HW_TIMEOUT && netif_msg_link(np)) {
-		printk(KERN_INFO 
+		printk(KERN_INFO
 			"%s: autonegotiation did not complete in %d usec.\n",
 			dev->name, i*10);
 	}
 
 	/* On page 78 of the spec, they recommend some settings for "optimum
 	   performance" to be done in sequence.  These settings optimize some
-	   of the 100Mbit autodetection circuitry.  They say we only want to 
-	   do this for rev C of the chip, but engineers at NSC (Bradley 
-	   Kennedy) recommends always setting them.  If you don't, you get 
+	   of the 100Mbit autodetection circuitry.  They say we only want to
+	   do this for rev C of the chip, but engineers at NSC (Bradley
+	   Kennedy) recommends always setting them.  If you don't, you get
 	   errors on some autonegotiations that make the device unusable.
 	*/
 	writew(1, ioaddr + PGSEL);
@@ -1154,6 +1254,7 @@
 	writew(DSPCFG_VAL, ioaddr + DSPCFG);
 	writew(SDCFG_VAL, ioaddr + SDCFG);
 	writew(0, ioaddr + PGSEL);
+	np->dspcfg = DSPCFG_VAL;
 
 	/* Enable PHY Specific event based interrupts.  Link state change
 	   and Auto-Negotiation Completion are among the affected.
@@ -1166,14 +1267,14 @@
 	readl(ioaddr + IntrStatus);
 
 	writel(np->ring_dma, ioaddr + RxRingPtr);
-	writel(np->ring_dma + RX_RING_SIZE * sizeof(struct netdev_desc), 
+	writel(np->ring_dma + RX_RING_SIZE * sizeof(struct netdev_desc),
 		ioaddr + TxRingPtr);
 
 	/* Initialize other registers.
 	 * Configure the PCI bus bursts and FIFO thresholds.
 	 * Configure for standard, in-spec Ethernet.
 	 * Start with half-duplex. check_link will update
-	 * to the correct settings. 
+	 * to the correct settings.
 	 */
 
 	/* DRTH: 2: start tx if 64 bytes are in the fifo
@@ -1195,13 +1296,13 @@
 	/* Disable PME:
 	 * The PME bit is initialized from the EEPROM contents.
 	 * PCI cards probably have PME disabled, but motherboard
-	 * implementations may have PME set to enable WakeOnLan. 
+	 * implementations may have PME set to enable WakeOnLan.
 	 * With PME set the chip will scan incoming packets but
 	 * nothing will be written to memory. */
 	np->SavedClkRun = readl(ioaddr + ClkRun);
 	writel(np->SavedClkRun & ~PMEEnable, ioaddr + ClkRun);
 	if (np->SavedClkRun & PMEStatus && netif_msg_wol(np)) {
-		printk(KERN_NOTICE "%s: Wake-up event %#08x\n", 
+		printk(KERN_NOTICE "%s: Wake-up event %#08x\n",
 			dev->name, readl(ioaddr + WOLCmd));
 	}
 
@@ -1216,12 +1317,17 @@
 	writel(StatsClear, ioaddr + StatsCtrl); /* Clear Stats */
 }
 
-/* 
- * The frequency on this has been increased because of a nasty little problem.
- * It seems that a reference set for this chip went out with incorrect info,
- * and there exist boards that aren't quite right.  An unexpected voltage drop
- * can cause the PHY to get itself in a weird state (basically reset..).
- * NOTE: this only seems to affect revC chips.
+/*
+ * netdev_timer:
+ * Purpose:
+ * 1) check for link changes. Usually they are handled by the MII interrupt
+ *    but it doesn't hurt to check twice.
+ * 2) check for sudden death of the NIC:
+ *    It seems that a reference set for this chip went out with incorrect info,
+ *    and there exist boards that aren't quite right.  An unexpected voltage
+ *    drop can cause the PHY to get itself in a weird state (basically reset).
+ *    NOTE: this only seems to affect revC chips.
+ * 3) check of death of the RX path due to OOM
  */
 static void netdev_timer(unsigned long data)
 {
@@ -1232,37 +1338,54 @@
 	u16 dspcfg;
 
 	if (netif_msg_timer(np)) {
-		/* DO NOT read the IntrStatus register, 
+		/* DO NOT read the IntrStatus register,
 		 * a read clears any pending interrupts.
 		 */
 		printk(KERN_DEBUG "%s: Media selection timer tick.\n",
-			   dev->name);
+			dev->name);
 	}
 
+	spin_lock_irq(&np->lock);
+
 	/* check for a nasty random phy-reset - use dspcfg as a flag */
 	writew(1, ioaddr+PGSEL);
 	dspcfg = readw(ioaddr+DSPCFG);
 	writew(0, ioaddr+PGSEL);
-	if (dspcfg != DSPCFG_VAL) {
+	if (dspcfg != np->dspcfg) {
 		if (!netif_queue_stopped(dev)) {
+			spin_unlock_irq(&np->lock);
 			if (netif_msg_hw(np))
 				printk(KERN_NOTICE "%s: possible phy reset: "
 					"re-initializing\n", dev->name);
 			disable_irq(dev->irq);
 			spin_lock_irq(&np->lock);
+			natsemi_stop_rxtx(dev);
+			dump_ring(dev);
+			reinit_ring(dev);
 			init_registers(dev);
 			spin_unlock_irq(&np->lock);
 			enable_irq(dev->irq);
 		} else {
 			/* hurry back */
 			next_tick = HZ;
+			spin_unlock_irq(&np->lock);
 		}
 	} else {
 		/* init_registers() calls check_link() for the above case */
-		spin_lock_irq(&np->lock);
 		check_link(dev);
 		spin_unlock_irq(&np->lock);
 	}
+	if (np->oom) {
+		disable_irq(dev->irq);
+		np->oom = 0;
+		refill_rx(dev);
+		enable_irq(dev->irq);
+		if (!np->oom) {
+			writel(RxOn, dev->base_addr + ChipCmd);
+		} else {
+			next_tick = 1;
+		}
+	}
 	mod_timer(&np->timer, jiffies + next_tick);
 }
 
@@ -1275,16 +1398,16 @@
 		printk(KERN_DEBUG "  Tx ring at %p:\n", np->tx_ring);
 		for (i = 0; i < TX_RING_SIZE; i++) {
 			printk(KERN_DEBUG " #%d desc. %#08x %#08x %#08x.\n",
-				   i, np->tx_ring[i].next_desc,
-				   np->tx_ring[i].cmd_status, 
-				   np->tx_ring[i].addr);
+				i, np->tx_ring[i].next_desc,
+				np->tx_ring[i].cmd_status,
+				np->tx_ring[i].addr);
 		}
 		printk(KERN_DEBUG "  Rx ring %p:\n", np->rx_ring);
 		for (i = 0; i < RX_RING_SIZE; i++) {
 			printk(KERN_DEBUG " #%d desc. %#08x %#08x %#08x.\n",
-				   i, np->rx_ring[i].next_desc,
-				   np->rx_ring[i].cmd_status, 
-				   np->rx_ring[i].addr);
+				i, np->rx_ring[i].next_desc,
+				np->rx_ring[i].cmd_status,
+				np->rx_ring[i].addr);
 		}
 	}
 }
@@ -1296,22 +1419,21 @@
 
 	disable_irq(dev->irq);
 	spin_lock_irq(&np->lock);
-	if (netif_device_present(dev)) {
+	if (!np->hands_off) {
 		if (netif_msg_tx_err(np))
-			printk(KERN_WARNING 
+			printk(KERN_WARNING
 				"%s: Transmit timed out, status %#08x,"
-				" resetting...\n", 
+				" resetting...\n",
 				dev->name, readl(ioaddr + IntrStatus));
 		dump_ring(dev);
 
 		natsemi_reset(dev);
-		drain_ring(dev);
-		init_ring(dev);
+		reinit_ring(dev);
 		init_registers(dev);
 	} else {
-		printk(KERN_WARNING 
-			"%s: tx_timeout while in suspended state?\n",
-		   	dev->name);
+		printk(KERN_WARNING
+			"%s: tx_timeout while in hands_off state?\n",
+			dev->name);
 	}
 	spin_unlock_irq(&np->lock);
 	enable_irq(dev->irq);
@@ -1325,24 +1447,62 @@
 {
 	struct netdev_private *np = dev->priv;
 	np->rx_ring = pci_alloc_consistent(np->pci_dev,
-				sizeof(struct netdev_desc) * (RX_RING_SIZE+TX_RING_SIZE),
-				&np->ring_dma);
+		sizeof(struct netdev_desc) * (RX_RING_SIZE+TX_RING_SIZE),
+		&np->ring_dma);
 	if (!np->rx_ring)
 		return -ENOMEM;
 	np->tx_ring = &np->rx_ring[RX_RING_SIZE];
 	return 0;
 }
 
+static void refill_rx(struct net_device *dev)
+{
+	struct netdev_private *np = dev->priv;
+
+	/* Refill the Rx ring buffers. */
+	for (; np->cur_rx - np->dirty_rx > 0; np->dirty_rx++) {
+		struct sk_buff *skb;
+		int entry = np->dirty_rx % RX_RING_SIZE;
+		if (np->rx_skbuff[entry] == NULL) {
+			skb = dev_alloc_skb(np->rx_buf_sz);
+			np->rx_skbuff[entry] = skb;
+			if (skb == NULL)
+				break; /* Better luck next round. */
+			skb->dev = dev; /* Mark as being used by this device. */
+			np->rx_dma[entry] = pci_map_single(np->pci_dev,
+				skb->data, skb->len, PCI_DMA_FROMDEVICE);
+			np->rx_ring[entry].addr = cpu_to_le32(np->rx_dma[entry]);
+		}
+		np->rx_ring[entry].cmd_status = cpu_to_le32(np->rx_buf_sz);
+	}
+	if (np->cur_rx - np->dirty_rx == RX_RING_SIZE) {
+		if (netif_msg_rx_err(np))
+			printk(KERN_WARNING "%s: going OOM.\n", dev->name);
+		np->oom = 1;
+	}
+}
+
 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
 static void init_ring(struct net_device *dev)
 {
 	struct netdev_private *np = dev->priv;
 	int i;
 
-	np->cur_rx = np->cur_tx = 0;
-	np->dirty_rx = np->dirty_tx = 0;
+	/* 1) TX ring */
+	np->dirty_tx = np->cur_tx = 0;
+	for (i = 0; i < TX_RING_SIZE; i++) {
+		np->tx_skbuff[i] = NULL;
+		np->tx_ring[i].next_desc = cpu_to_le32(np->ring_dma
+			+sizeof(struct netdev_desc)
+			*((i+1)%TX_RING_SIZE+RX_RING_SIZE));
+		np->tx_ring[i].cmd_status = 0;
+	}
 
+	/* 2) RX ring */
+	np->dirty_rx = 0;
+	np->cur_rx = RX_RING_SIZE;
 	np->rx_buf_sz = (dev->mtu <= 1500 ? PKT_BUF_SZ : dev->mtu + 32);
+	np->oom = 0;
 	np->rx_head_desc = &np->rx_ring[0];
 
 	/* Please be carefull before changing this loop - at least gcc-2.95.1
@@ -1356,29 +1516,25 @@
 		np->rx_ring[i].cmd_status = cpu_to_le32(DescOwn);
 		np->rx_skbuff[i] = NULL;
 	}
+	refill_rx(dev);
+	dump_ring(dev);
+}
 
-	/* Fill in the Rx buffers.  Handle allocation failure gracefully. */
-	for (i = 0; i < RX_RING_SIZE; i++) {
-		struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz);
-		np->rx_skbuff[i] = skb;
-		if (skb == NULL)
-			break;
-		skb->dev = dev;			/* Mark as being used by this device. */
-		np->rx_dma[i] = pci_map_single(np->pci_dev,
-						skb->data, skb->len, PCI_DMA_FROMDEVICE);
-		np->rx_ring[i].addr = cpu_to_le32(np->rx_dma[i]);
-		np->rx_ring[i].cmd_status = cpu_to_le32(np->rx_buf_sz);
-	}
-	np->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
+static void drain_tx(struct net_device *dev)
+{
+	struct netdev_private *np = dev->priv;
+	int i;
 
 	for (i = 0; i < TX_RING_SIZE; i++) {
+		if (np->tx_skbuff[i]) {
+			pci_unmap_single(np->pci_dev,
+				np->rx_dma[i], np->rx_skbuff[i]->len,
+				PCI_DMA_TODEVICE);
+			dev_kfree_skb(np->tx_skbuff[i]);
+			np->stats.tx_dropped++;
+		}
 		np->tx_skbuff[i] = NULL;
-		np->tx_ring[i].next_desc = cpu_to_le32(np->ring_dma
-					+sizeof(struct netdev_desc)
-					 *((i+1)%TX_RING_SIZE+RX_RING_SIZE));
-		np->tx_ring[i].cmd_status = 0;
 	}
-	dump_ring(dev);
 }
 
 static void drain_ring(struct net_device *dev)
@@ -1392,31 +1548,43 @@
 		np->rx_ring[i].addr = 0xBADF00D0; /* An invalid address. */
 		if (np->rx_skbuff[i]) {
 			pci_unmap_single(np->pci_dev,
-						np->rx_dma[i],
-						np->rx_skbuff[i]->len,
-						PCI_DMA_FROMDEVICE);
+				np->rx_dma[i], np->rx_skbuff[i]->len,
+				PCI_DMA_FROMDEVICE);
 			dev_kfree_skb(np->rx_skbuff[i]);
 		}
 		np->rx_skbuff[i] = NULL;
 	}
-	for (i = 0; i < TX_RING_SIZE; i++) {
-		if (np->tx_skbuff[i]) {
-			pci_unmap_single(np->pci_dev,
-						np->rx_dma[i],
-						np->rx_skbuff[i]->len,
-						PCI_DMA_TODEVICE);
-			dev_kfree_skb(np->tx_skbuff[i]);
-		}
-		np->tx_skbuff[i] = NULL;
-	}
+	drain_tx(dev);
 }
 
 static void free_ring(struct net_device *dev)
 {
 	struct netdev_private *np = dev->priv;
 	pci_free_consistent(np->pci_dev,
-				sizeof(struct netdev_desc) * (RX_RING_SIZE+TX_RING_SIZE),
-				np->rx_ring, np->ring_dma);
+		sizeof(struct netdev_desc) * (RX_RING_SIZE+TX_RING_SIZE),
+		np->rx_ring, np->ring_dma);
+}
+
+static void reinit_ring(struct net_device *dev)
+{
+	struct netdev_private *np = dev->priv;
+	int i;
+
+	/* drain TX ring */
+	drain_tx(dev);
+	np->dirty_tx = np->cur_tx = 0;
+	for (i=0;i<TX_RING_SIZE;i++)
+		np->tx_ring[i].cmd_status = 0;
+
+	/* RX Ring */
+	np->dirty_rx = 0;
+	np->cur_rx = RX_RING_SIZE;
+	np->rx_head_desc = &np->rx_ring[0];
+	/* Initialize all Rx descriptors. */
+	for (i = 0; i < RX_RING_SIZE; i++)
+		np->rx_ring[i].cmd_status = cpu_to_le32(DescOwn);
+
+	refill_rx(dev);
 }
 
 static int start_tx(struct sk_buff *skb, struct net_device *dev)
@@ -1437,10 +1605,10 @@
 	np->tx_ring[entry].addr = cpu_to_le32(np->tx_dma[entry]);
 
 	spin_lock_irq(&np->lock);
-	
-	if (netif_device_present(dev)) {
+
+	if (!np->hands_off) {
 		np->tx_ring[entry].cmd_status = cpu_to_le32(DescOwn | skb->len);
-		/* StrongARM: Explicitly cache flush np->tx_ring and 
+		/* StrongARM: Explicitly cache flush np->tx_ring and
 		 * skb->data,skb->len. */
 		wmb();
 		np->cur_tx++;
@@ -1461,7 +1629,7 @@
 
 	if (netif_msg_tx_queued(np)) {
 		printk(KERN_DEBUG "%s: Transmit frame #%d queued in slot %d.\n",
-			   dev->name, np->cur_tx, entry);
+			dev->name, np->cur_tx, entry);
 	}
 	return 0;
 }
@@ -1475,7 +1643,7 @@
 		if (np->tx_ring[entry].cmd_status & cpu_to_le32(DescOwn))
 			break;
 		if (netif_msg_tx_done(np))
-			printk(KERN_DEBUG 
+			printk(KERN_DEBUG
 				"%s: tx frame #%d finished, status %#08x.\n",
 					dev->name, np->dirty_tx,
 					le32_to_cpu(np->tx_ring[entry].cmd_status));
@@ -1483,14 +1651,15 @@
 			np->stats.tx_packets++;
 			np->stats.tx_bytes += np->tx_skbuff[entry]->len;
 		} else { /* Various Tx errors */
-			int tx_status = le32_to_cpu(np->tx_ring[entry].cmd_status);
-			if (tx_status & (DescTxAbort|DescTxExcColl)) 
+			int tx_status =
+				le32_to_cpu(np->tx_ring[entry].cmd_status);
+			if (tx_status & (DescTxAbort|DescTxExcColl))
 				np->stats.tx_aborted_errors++;
-			if (tx_status & DescTxFIFO) 
+			if (tx_status & DescTxFIFO)
 				np->stats.tx_fifo_errors++;
-			if (tx_status & DescTxCarrier) 
+			if (tx_status & DescTxCarrier)
 				np->stats.tx_carrier_errors++;
-			if (tx_status & DescTxOOWCol) 
+			if (tx_status & DescTxOOWCol)
 				np->stats.tx_window_errors++;
 			np->stats.tx_errors++;
 		}
@@ -1517,23 +1686,29 @@
 	long ioaddr = dev->base_addr;
 	int boguscnt = max_interrupt_work;
 
-	if (!netif_device_present(dev))
+	if (np->hands_off)
 		return;
 	do {
 		/* Reading automatically acknowledges all int sources. */
 		u32 intr_status = readl(ioaddr + IntrStatus);
 
 		if (netif_msg_intr(np))
-			printk(KERN_DEBUG "%s: Interrupt, status %#08x.\n",
-				   dev->name, intr_status);
+			printk(KERN_DEBUG
+				"%s: Interrupt, status %#08x, mask %#08x.\n",
+				dev->name, intr_status,
+				readl(ioaddr + IntrMask));
 
 		if (intr_status == 0)
 			break;
 
-		if (intr_status & (IntrRxDone | IntrRxIntr))
+		if (intr_status &
+		   (IntrRxDone | IntrRxIntr | RxStatusFIFOOver |
+		    IntrRxErr | IntrRxOverrun)) {
 			netdev_rx(dev);
+		}
 
-		if (intr_status & (IntrTxDone | IntrTxIntr | IntrTxIdle | IntrTxErr) ) {
+		if (intr_status &
+		   (IntrTxDone | IntrTxIntr | IntrTxIdle | IntrTxErr)) {
 			spin_lock(&np->lock);
 			netdev_tx_done(dev);
 			spin_unlock(&np->lock);
@@ -1544,16 +1719,17 @@
 			netdev_error(dev, intr_status);
 
 		if (--boguscnt < 0) {
-			printk(KERN_WARNING "%s: Too much work at interrupt, "
-				   "status=%#08x.\n",
-				   dev->name, intr_status);
+			if (netif_msg_intr(np))
+				printk(KERN_WARNING
+					"%s: Too much work at interrupt, "
+					"status=%#08x.\n",
+					dev->name, intr_status);
 			break;
 		}
 	} while (1);
 
 	if (netif_msg_intr(np))
-		printk(KERN_DEBUG "%s: exiting interrupt.\n",
-			   dev->name);
+		printk(KERN_DEBUG "%s: exiting interrupt.\n", dev->name);
 }
 
 /* This routine is logically part of the interrupt handler, but separated
@@ -1566,9 +1742,9 @@
 	s32 desc_status = le32_to_cpu(np->rx_head_desc->cmd_status);
 
 	/* If the driver owns the next entry it's a new packet. Send it up. */
-	while (desc_status < 0) {        /* e.g. & DescOwn */
+	while (desc_status < 0) { /* e.g. & DescOwn */
 		if (netif_msg_rx_status(np))
-			printk(KERN_DEBUG 
+			printk(KERN_DEBUG
 				"  netdev_rx() entry %d status was %#08x.\n",
 				entry, desc_status);
 		if (--boguscnt < 0)
@@ -1576,54 +1752,56 @@
 		if ((desc_status&(DescMore|DescPktOK|DescRxLong)) != DescPktOK){
 			if (desc_status & DescMore) {
 				if (netif_msg_rx_err(np))
-					printk(KERN_WARNING 
+					printk(KERN_WARNING
 						"%s: Oversized(?) Ethernet "
 						"frame spanned multiple "
 						"buffers, entry %#08x "
-						"status %#08x.\n", dev->name, 
+						"status %#08x.\n", dev->name,
 						np->cur_rx, desc_status);
 				np->stats.rx_length_errors++;
 			} else {
 				/* There was an error. */
 				np->stats.rx_errors++;
-				if (desc_status & (DescRxAbort|DescRxOver)) 
+				if (desc_status & (DescRxAbort|DescRxOver))
 					np->stats.rx_over_errors++;
-				if (desc_status & (DescRxLong|DescRxRunt)) 
+				if (desc_status & (DescRxLong|DescRxRunt))
 					np->stats.rx_length_errors++;
-				if (desc_status & (DescRxInvalid|DescRxAlign)) 
+				if (desc_status & (DescRxInvalid|DescRxAlign))
 					np->stats.rx_frame_errors++;
-				if (desc_status & DescRxCRC) 
+				if (desc_status & DescRxCRC)
 					np->stats.rx_crc_errors++;
 			}
 		} else {
 			struct sk_buff *skb;
 			/* Omit CRC size. */
 			int pkt_len = (desc_status & DescSizeMask) - 4;
-			/* Check if the packet is long enough to accept 
+			/* Check if the packet is long enough to accept
 			 * without copying to a minimally-sized skbuff. */
 			if (pkt_len < rx_copybreak
-				&& (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
+			    && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
 				skb->dev = dev;
-				skb_reserve(skb, 2);	/* 16 byte align the IP header */
-				pci_dma_sync_single(np->pci_dev, np->rx_dma[entry],
-							np->rx_skbuff[entry]->len,
-							PCI_DMA_FROMDEVICE);
+				/* 16 byte align the IP header */
+				skb_reserve(skb, 2);
+				pci_dma_sync_single(np->pci_dev,
+					np->rx_dma[entry],
+					np->rx_skbuff[entry]->len,
+					PCI_DMA_FROMDEVICE);
 #if HAS_IP_COPYSUM
-				eth_copy_and_sum(skb, np->rx_skbuff[entry]->tail, pkt_len, 0);
+				eth_copy_and_sum(skb,
+					np->rx_skbuff[entry]->tail, pkt_len, 0);
 				skb_put(skb, pkt_len);
 #else
-				memcpy(skb_put(skb, pkt_len), np->rx_skbuff[entry]->tail,
-					   pkt_len);
+				memcpy(skb_put(skb, pkt_len),
+					np->rx_skbuff[entry]->tail, pkt_len);
 #endif
 			} else {
 				pci_unmap_single(np->pci_dev, np->rx_dma[entry],
-							np->rx_skbuff[entry]->len,
-							PCI_DMA_FROMDEVICE);
+					np->rx_skbuff[entry]->len,
+					PCI_DMA_FROMDEVICE);
 				skb_put(skb = np->rx_skbuff[entry], pkt_len);
 				np->rx_skbuff[entry] = NULL;
 			}
 			skb->protocol = eth_type_trans(skb, dev);
-			/* W/ hardware checksum: skb->ip_summed = CHECKSUM_UNNECESSARY; */
 			netif_rx(skb);
 			dev->last_rx = jiffies;
 			np->stats.rx_packets++;
@@ -1633,27 +1811,13 @@
 		np->rx_head_desc = &np->rx_ring[entry];
 		desc_status = le32_to_cpu(np->rx_head_desc->cmd_status);
 	}
-
-	/* Refill the Rx ring buffers. */
-	for (; np->cur_rx - np->dirty_rx > 0; np->dirty_rx++) {
-		struct sk_buff *skb;
-		entry = np->dirty_rx % RX_RING_SIZE;
-		if (np->rx_skbuff[entry] == NULL) {
-			skb = dev_alloc_skb(np->rx_buf_sz);
-			np->rx_skbuff[entry] = skb;
-			if (skb == NULL)
-				break;				/* Better luck next round. */
-			skb->dev = dev;			/* Mark as being used by this device. */
-			np->rx_dma[entry] = pci_map_single(np->pci_dev,
-							skb->data, skb->len, PCI_DMA_FROMDEVICE);
-			np->rx_ring[entry].addr = cpu_to_le32(np->rx_dma[entry]);
-		}
-		np->rx_ring[entry].cmd_status =
-			cpu_to_le32(np->rx_buf_sz);
-	}
+	refill_rx(dev);
 
 	/* Restart Rx engine if stopped. */
-	writel(RxOn, dev->base_addr + ChipCmd);
+	if (np->oom)
+		mod_timer(&np->timer, jiffies + 1);
+	else
+		writel(RxOn, dev->base_addr + ChipCmd);
 }
 
 static void netdev_error(struct net_device *dev, int intr_status)
@@ -1665,9 +1829,9 @@
 	if (intr_status & LinkChange) {
 		u16 adv = mdio_read(dev, 1, MII_ADVERTISE);
 		u16 lpa = mdio_read(dev, 1, MII_LPA);
-		if (mdio_read(dev, 1, MII_BMCR) & BMCR_ANENABLE 
+		if (mdio_read(dev, 1, MII_BMCR) & BMCR_ANENABLE
 		 && netif_msg_link(np)) {
-			printk(KERN_INFO 
+			printk(KERN_INFO
 				"%s: Autonegotiation advertising"
 				" %#04x  partner %#04x.\n", dev->name,
 				adv, lpa);
@@ -1684,19 +1848,19 @@
 		if ((np->tx_config & TxDrthMask) < 62)
 			np->tx_config += 2;
 		if (netif_msg_tx_err(np))
-			printk(KERN_NOTICE 
-				"%s: increased Tx theshold, txcfg %#08x.\n",
+			printk(KERN_NOTICE
+				"%s: increased Tx threshold, txcfg %#08x.\n",
 				dev->name, np->tx_config);
 		writel(np->tx_config, ioaddr + TxConfig);
 	}
 	if (intr_status & WOLPkt && netif_msg_wol(np)) {
 		int wol_status = readl(ioaddr + WOLCmd);
 		printk(KERN_NOTICE "%s: Link wake-up event %#08x\n",
-			   dev->name, wol_status);
+			dev->name, wol_status);
 	}
 	if (intr_status & RxStatusFIFOOver) {
 		if (netif_msg_rx_err(np) && netif_msg_intr(np)) {
-			printk(KERN_NOTICE "%s: Rx status FIFO overrun\n", 
+			printk(KERN_NOTICE "%s: Rx status FIFO overrun\n",
 				dev->name);
 		}
 		np->stats.rx_fifo_errors++;
@@ -1727,8 +1891,8 @@
 
 	/* The chip only need report frame silently dropped. */
 	spin_lock_irq(&np->lock);
- 	if (netif_running(dev) && netif_device_present(dev))
- 		__get_stats(dev);
+	if (netif_running(dev) && !np->hands_off)
+		__get_stats(dev);
 	spin_unlock_irq(&np->lock);
 
 	return &np->stats;
@@ -1744,27 +1908,27 @@
 #define DP_POLYNOMIAL			0x04C11DB7
 static unsigned dp83815_crc(int length, unsigned char *data)
 {
-    u32 crc;
-    u8 cur_byte;
-    u8 msb;
-    u8 byte, bit;
-
-    crc = ~0;
-    for (byte=0; byte<length; byte++) {
-        cur_byte = *data++;
-        for (bit=0; bit<8; bit++) {
-            msb = crc >> 31;
-            crc <<= 1;
-            if (msb ^ (cur_byte & 1)) {
-                crc ^= DP_POLYNOMIAL;
-                crc |= 1;
-            }
-            cur_byte >>= 1;
-        }
-    }
-    crc >>= 23;
+	u32 crc;
+	u8 cur_byte;
+	u8 msb;
+	u8 byte, bit;
+
+	crc = ~0;
+	for (byte=0; byte<length; byte++) {
+		cur_byte = *data++;
+		for (bit=0; bit<8; bit++) {
+			msb = crc >> 31;
+			crc <<= 1;
+			if (msb ^ (cur_byte & 1)) {
+				crc ^= DP_POLYNOMIAL;
+				crc |= 1;
+			}
+			cur_byte >>= 1;
+		}
+	}
+	crc >>= 23;
 
-    return (crc);
+	return (crc);
 }
 
 
@@ -1777,18 +1941,18 @@
 {
 	long ioaddr = dev->base_addr;
 	struct netdev_private *np = dev->priv;
-	u8 mc_filter[64];			/* Multicast hash filter */
+	u8 mc_filter[64]; /* Multicast hash filter */
 	u32 rx_mode;
 
-	if (dev->flags & IFF_PROMISC) {			/* Set promiscuous. */
+	if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
 		/* Unconditionally log net taps. */
-		printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n", 
+		printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n",
 			dev->name);
-		rx_mode = RxFilterEnable | AcceptBroadcast 
+		rx_mode = RxFilterEnable | AcceptBroadcast
 			| AcceptAllMulticast | AcceptAllPhys | AcceptMyPhys;
 	} else if ((dev->mc_count > multicast_filter_limit)
-			   ||  (dev->flags & IFF_ALLMULTI)) {
-		rx_mode = RxFilterEnable | AcceptBroadcast 
+	  || (dev->flags & IFF_ALLMULTI)) {
+		rx_mode = RxFilterEnable | AcceptBroadcast
 			| AcceptAllMulticast | AcceptMyPhys;
 	} else {
 		struct dev_mc_list *mclist;
@@ -1796,14 +1960,15 @@
 		memset(mc_filter, 0, sizeof(mc_filter));
 		for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
 			 i++, mclist = mclist->next) {
-			set_bit_le(dp83815_crc(ETH_ALEN, mclist->dmi_addr) & 0x1ff,
-					mc_filter);
+			set_bit_le(
+				dp83815_crc(ETH_ALEN, mclist->dmi_addr) & 0x1ff,
+				mc_filter);
 		}
-		rx_mode = RxFilterEnable | AcceptBroadcast 
+		rx_mode = RxFilterEnable | AcceptBroadcast
 			| AcceptMulticast | AcceptMyPhys;
 		for (i = 0; i < 64; i += 2) {
 			writew(HASH_TABLE + i, ioaddr + RxFilterAddr);
-			writew((mc_filter[i+1]<<8) + mc_filter[i], 
+			writew((mc_filter[i+1]<<8) + mc_filter[i],
 				ioaddr + RxFilterData);
 		}
 	}
@@ -1815,7 +1980,7 @@
 {
 	struct netdev_private *np = dev->priv;
 	spin_lock_irq(&np->lock);
-	if (netif_device_present(dev))
+	if (!np->hands_off)
 		__set_rx_mode(dev);
 	spin_unlock_irq(&np->lock);
 }
@@ -1824,18 +1989,18 @@
 {
 	struct netdev_private *np = dev->priv;
 	u32 cmd;
-	
+
 	if (get_user(cmd, (u32 *)useraddr))
 		return -EFAULT;
 
-        switch (cmd) {
+	switch (cmd) {
 	/* get driver info */
-        case ETHTOOL_GDRVINFO: {
+	case ETHTOOL_GDRVINFO: {
 		struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
 		strncpy(info.driver, DRV_NAME, ETHTOOL_BUSINFO_LEN);
 		strncpy(info.version, DRV_VERSION, ETHTOOL_BUSINFO_LEN);
 		info.fw_version[0] = '\0';
-		strncpy(info.bus_info, np->pci_dev->slot_name, 
+		strncpy(info.bus_info, np->pci_dev->slot_name,
 			ETHTOOL_BUSINFO_LEN);
 		info.eedump_len = NATSEMI_EEPROM_SIZE;
 		info.regdump_len = NATSEMI_REGS_SIZE;
@@ -1895,7 +2060,7 @@
 
 		if (copy_from_user(&regs, useraddr, sizeof(regs)))
 			return -EFAULT;
-		
+
 		if (regs.len > NATSEMI_REGS_SIZE) {
 			regs.len = NATSEMI_REGS_SIZE;
 		}
@@ -1962,10 +2127,10 @@
 
 		if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
 			return -EFAULT;
-		
+
 		if (eeprom.offset > eeprom.offset+eeprom.len)
 			return -EINVAL;
-			
+
 		if ((eeprom.offset+eeprom.len) > NATSEMI_EEPROM_SIZE) {
 			eeprom.len = NATSEMI_EEPROM_SIZE-eeprom.offset;
 		}
@@ -1986,8 +2151,8 @@
 		return 0;
 	}
 
-        }
-	
+	}
+
 	return -EOPNOTSUPP;
 }
 
@@ -2009,7 +2174,7 @@
 		data |= WakeArp;
 	if (newval & WAKE_MAGIC)
 		data |= WakeMagic;
-	if (np->srr >= SRR_REV_D) {
+	if (np->srr >= SRR_DP83815_D) {
 		if (newval & WAKE_MAGICSECURE) {
 			data |= WakeMagicSecure;
 		}
@@ -2025,10 +2190,10 @@
 	struct netdev_private *np = dev->priv;
 	u32 regval = readl(dev->base_addr + WOLCmd);
 
-	*supported = (WAKE_PHY | WAKE_UCAST | WAKE_MCAST | WAKE_BCAST 
+	*supported = (WAKE_PHY | WAKE_UCAST | WAKE_MCAST | WAKE_BCAST
 			| WAKE_ARP | WAKE_MAGIC);
-	
-	if (np->srr >= SRR_REV_D) {
+
+	if (np->srr >= SRR_DP83815_D) {
 		/* SOPASS works on revD and higher */
 		*supported |= WAKE_MAGICSECURE;
 	}
@@ -2060,8 +2225,8 @@
 	struct netdev_private *np = dev->priv;
 	u16 *sval = (u16 *)newval;
 	u32 addr;
-	
-	if (np->srr < SRR_REV_D) {
+
+	if (np->srr < SRR_DP83815_D) {
 		return 0;
 	}
 
@@ -2076,10 +2241,10 @@
 
 	writel(addr | 0xc, dev->base_addr + RxFilterAddr);
 	writew(sval[1], dev->base_addr + RxFilterData);
-	
+
 	writel(addr | 0xe, dev->base_addr + RxFilterAddr);
 	writew(sval[2], dev->base_addr + RxFilterData);
-	
+
 	/* re-enable the RX filter */
 	writel(addr | RxFilterEnable, dev->base_addr + RxFilterAddr);
 
@@ -2092,7 +2257,7 @@
 	u16 *sval = (u16 *)data;
 	u32 addr;
 
-	if (np->srr < SRR_REV_D) {
+	if (np->srr < SRR_DP83815_D) {
 		sval[0] = sval[1] = sval[2] = 0;
 		return 0;
 	}
@@ -2105,10 +2270,10 @@
 
 	writel(addr | 0xc, dev->base_addr + RxFilterAddr);
 	sval[1] = readw(dev->base_addr + RxFilterData);
-	
+
 	writel(addr | 0xe, dev->base_addr + RxFilterAddr);
 	sval[2] = readw(dev->base_addr + RxFilterData);
-	
+
 	writel(addr, dev->base_addr + RxFilterAddr);
 
 	return 0;
@@ -2118,11 +2283,11 @@
 {
 	u32 tmp;
 
-	ecmd->supported = 
+	ecmd->supported =
 		(SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
 		SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
 		SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII);
-	
+
 	/* only supports twisted-pair or MII */
 	tmp = readl(dev->base_addr + ChipConfig);
 	if (tmp & CfgExtPhy)
@@ -2161,7 +2326,7 @@
 	} else {
 		ecmd->speed = SPEED_10;
 	}
-		
+
 	if (tmp & CfgFullDuplex) {
 		ecmd->duplex = DUPLEX_FULL;
 	} else {
@@ -2189,9 +2354,9 @@
 	if (ecmd->autoneg != AUTONEG_DISABLE && ecmd->autoneg != AUTONEG_ENABLE)
 		return -EINVAL;
 	/* ignore phy_address, maxtxpkt, maxrxpkt for now */
-	
+
 	/* WHEW! now lets bang some bits */
-	
+
 	tmp = mdio_read(dev, 1, MII_BMCR);
 	if (ecmd->autoneg == AUTONEG_ENABLE) {
 		/* turn on autonegotiation */
@@ -2217,7 +2382,7 @@
 	int j;
 	u32 rfcr;
 	u32 *rbuf = (u32 *)buf;
-	
+
 	/* read all of page 0 of registers */
 	for (i = 0; i < NATSEMI_PG0_NREGS; i++) {
 		rbuf[i] = readl(dev->base_addr + i*4);
@@ -2241,8 +2406,8 @@
 
 	/* the interrupt status is clear-on-read - see if we missed any */
 	if (rbuf[4] & rbuf[5]) {
-		printk(KERN_WARNING 
-			"%s: shoot, we dropped an interrupt (%#08x)\n", 
+		printk(KERN_WARNING
+			"%s: shoot, we dropped an interrupt (%#08x)\n",
 			dev->name, rbuf[4] & rbuf[5]);
 	}
 
@@ -2266,7 +2431,7 @@
 	/* eeprom_read reads 16 bits, and indexes by 16 bits */
 	for (i = 0; i < NATSEMI_EEPROM_SIZE/2; i++) {
 		ebuf[i] = eeprom_read(dev->base_addr, i);
-		/* The EEPROM itself stores data bit-swapped, but eeprom_read 
+		/* The EEPROM itself stores data bit-swapped, but eeprom_read
 		 * reads it back "sanely". So we swap it back here in order to
 		 * present it to userland as it is stored. */
 		ebuf[i] = SWAP_BITS(ebuf[i]);
@@ -2288,7 +2453,7 @@
 
 	case SIOCGMIIREG:		/* Read MII PHY register. */
 	case SIOCDEVPRIVATE+1:		/* for binary compat, remove in 2.5 */
-		data->val_out = mdio_read(dev, data->phy_id & 0x1f, 
+		data->val_out = mdio_read(dev, data->phy_id & 0x1f,
 			data->reg_num & 0x1f);
 		return 0;
 
@@ -2296,7 +2461,7 @@
 	case SIOCDEVPRIVATE+2:		/* for binary compat, remove in 2.5 */
 		if (!capable(CAP_NET_ADMIN))
 			return -EPERM;
-		mdio_write(dev, data->phy_id & 0x1f, data->reg_num & 0x1f, 
+		mdio_write(dev, data->phy_id & 0x1f, data->reg_num & 0x1f,
 			data->val_in);
 		return 0;
 	default:
@@ -2310,7 +2475,7 @@
 	struct netdev_private *np = dev->priv;
 
 	if (netif_msg_wol(np))
-		printk(KERN_INFO "%s: remaining active for wake-on-lan\n", 
+		printk(KERN_INFO "%s: remaining active for wake-on-lan\n",
 			dev->name);
 
 	/* For WOL we must restart the rx process in silent mode.
@@ -2332,7 +2497,8 @@
 		/* enable the WOL interrupt.
 		 * Could be used to send a netlink message.
 		 */
-		writel(readl(ioaddr + IntrMask) | WOLPkt, ioaddr + IntrMask);
+		writel(WOLPkt | LinkChange, ioaddr + IntrMask);
+		writel(1, ioaddr + IntrEnable);
 	}
 }
 
@@ -2341,57 +2507,62 @@
 	long ioaddr = dev->base_addr;
 	struct netdev_private *np = dev->priv;
 
-	netif_stop_queue(dev);
-	netif_carrier_off(dev);
-
 	if (netif_msg_ifdown(np))
-		printk(KERN_DEBUG 
+		printk(KERN_DEBUG
 			"%s: Shutting down ethercard, status was %#04x.\n",
 			dev->name, (int)readl(ioaddr + ChipCmd));
 	if (netif_msg_pktdata(np))
-		printk(KERN_DEBUG 
+		printk(KERN_DEBUG
 			"%s: Queue pointers were Tx %d / %d,  Rx %d / %d.\n",
-			dev->name, np->cur_tx, np->dirty_tx, 
+			dev->name, np->cur_tx, np->dirty_tx,
 			np->cur_rx, np->dirty_rx);
 
-	del_timer_sync(&np->timer);
+	/*
+	 * FIXME: what if someone tries to close a device
+	 * that is suspended?
+	 * Should we reenable the nic to switch to
+	 * the final WOL settings?
+	 */
 
+	del_timer_sync(&np->timer);
 	disable_irq(dev->irq);
 	spin_lock_irq(&np->lock);
-
-	/* Disable and clear interrupts */
+	/* Disable interrupts, and flush posted writes */
 	writel(0, ioaddr + IntrEnable);
+	readl(ioaddr + IntrEnable);
+	np->hands_off = 1;
+	spin_unlock_irq(&np->lock);
+	enable_irq(dev->irq);
+
+	free_irq(dev->irq, dev);
+
+	/* Interrupt disabled, interrupt handler released,
+	 * queue stopped, timer deleted, rtnl_lock held
+	 * All async codepaths that access the driver are disabled.
+	 */
+	spin_lock_irq(&np->lock);
+	np->hands_off = 0;
 	readl(ioaddr + IntrMask);
 	readw(ioaddr + MIntrStatus);
 
- 	/* Freeze Stats */
+	/* Freeze Stats */
 	writel(StatsFreeze, ioaddr + StatsCtrl);
-	    
+
 	/* Stop the chip's Tx and Rx processes. */
 	natsemi_stop_rxtx(dev);
 
 	__get_stats(dev);
 	spin_unlock_irq(&np->lock);
 
-	/* race: shared irq and as most nics the DP83815
-	 * reports _all_ interrupt conditions in IntrStatus, even
-	 * disabled ones.
-	 * packet received after disable_irq, but before stop_rxtx
-	 * --> race. intr_handler would restart the rx process.
-	 * netif_device_{de,a}tach around {enable,free}_irq.
-	 */
-	netif_device_detach(dev);
-	enable_irq(dev->irq);
-	free_irq(dev->irq, dev);
-	netif_device_attach(dev);
 	/* clear the carrier last - an interrupt could reenable it otherwise */
 	netif_carrier_off(dev);
+	netif_stop_queue(dev);
 
 	dump_ring(dev);
 	drain_ring(dev);
 	free_ring(dev);
 
-	 {
+	{
 		u32 wol = readl(ioaddr + WOLCmd) & WakeOptsSummary;
 		if (wol) {
 			/* restart the NIC in WOL mode.
@@ -2406,7 +2577,7 @@
 	return 0;
 }
 
-
+
 static void __devexit natsemi_remove1 (struct pci_dev *pdev)
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
@@ -2421,23 +2592,26 @@
 #ifdef CONFIG_PM
 
 /*
+ * The ns83815 chip doesn't have explicit RxStop bits.
+ * Kicking the Rx or Tx process for a new packet reenables the Rx process
+ * of the nic, thus this function must be very careful:
+ *
  * suspend/resume synchronization:
  * entry points:
  *   netdev_open, netdev_close, netdev_ioctl, set_rx_mode, intr_handler,
  *   start_tx, tx_timeout
- * Reading from some registers can restart the nic!
- * No function accesses the hardware without checking netif_device_present().
- * 	the check occurs under spin_lock_irq(&np->lock);
+ *
+ * No function accesses the hardware without checking np->hands_off.
+ *	the check occurs under spin_lock_irq(&np->lock);
  * exceptions:
- * 	* netdev_ioctl, netdev_open.
- * 		net/core checks netif_device_present() before calling them.
- * 	* netdev_close: doesn't hurt.
+ *	* netdev_ioctl: noncritical access.
+ *	* netdev_open: cannot happen due to the device_detach
+ *	* netdev_close: doesn't hurt.
  *	* netdev_timer: timer stopped by natsemi_suspend.
  *	* intr_handler: doesn't acquire the spinlock. suspend calls
  *		disable_irq() to enforce synchronization.
  *
- * netif_device_detach must occur under spin_unlock_irq(), interrupts from a
- * detached device would cause an irq storm.
+ * Interrupts must be disabled, otherwise hands_off can cause irq storms.
  */
 
 static int natsemi_suspend (struct pci_dev *pdev, u32 state)
@@ -2454,13 +2628,13 @@
 		spin_lock_irq(&np->lock);
 
 		writel(0, ioaddr + IntrEnable);
+		np->hands_off = 1;
 		natsemi_stop_rxtx(dev);
 		netif_stop_queue(dev);
-		netif_device_detach(dev);
 
 		spin_unlock_irq(&np->lock);
 		enable_irq(dev->irq);
-		
+
 		/* Update the error counts. */
 		__get_stats(dev);
 
@@ -2472,7 +2646,7 @@
 			if (wol) {
 				/* restart the NIC in WOL mode.
 				 * The nic must be stopped for this.
-				 * FIXME: use the WOL interupt 
+				 * FIXME: use the WOL interupt
 				 */
 				enable_wol_mode(dev, 0);
 			} else {
@@ -2480,9 +2654,8 @@
 				writel(np->SavedClkRun, ioaddr + ClkRun);
 			}
 		}
-	} else {
-		netif_device_detach(dev);
 	}
+	netif_device_detach(dev);
 	rtnl_unlock();
 	return 0;
 }
@@ -2497,20 +2670,23 @@
 	if (netif_device_present(dev))
 		goto out;
 	if (netif_running(dev)) {
+		BUG_ON(!np->hands_off);
 		pci_enable_device(pdev);
 	/*	pci_power_on(pdev); */
-		
+
 		natsemi_reset(dev);
 		init_ring(dev);
+		disable_irq(dev->irq);
 		spin_lock_irq(&np->lock);
+		np->hands_off = 0;
 		init_registers(dev);
 		netif_device_attach(dev);
 		spin_unlock_irq(&np->lock);
+		enable_irq(dev->irq);
 
 		mod_timer(&np->timer, jiffies + 1*HZ);
-	} else {
-		netif_device_attach(dev);
 	}
+	netif_device_attach(dev);
 out:
 	rtnl_unlock();
 	return 0;
@@ -2519,13 +2695,13 @@
 #endif /* CONFIG_PM */
 
 static struct pci_driver natsemi_driver = {
-	name:		DRV_NAME,
-	id_table:	natsemi_pci_tbl,
-	probe:		natsemi_probe1,
-	remove:		__devexit_p(natsemi_remove1),
+	.name		= DRV_NAME,
+	.id_table	= natsemi_pci_tbl,
+	.probe		= natsemi_probe1,
+	.remove		= __devexit_p(natsemi_remove1),
 #ifdef CONFIG_PM
-	suspend:	natsemi_suspend,
-	resume:		natsemi_resume,
+	.suspend	= natsemi_suspend,
+	.resume		= natsemi_resume,
 #endif
 };
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)