patch-2.4.0-test11 linux/drivers/net/lance.c

Next file: linux/drivers/net/lne390.c
Previous file: linux/drivers/net/irda/w83977af_ir.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.0-test10/linux/drivers/net/lance.c linux/drivers/net/lance.c
@@ -224,7 +224,6 @@
 	int dma;
 	struct net_device_stats stats;
 	unsigned char chip_version;	/* See lance_chip_type. */
-	char tx_full;
 	spinlock_t devlock;
 };
 
@@ -268,8 +267,6 @@
 
 enum {OLD_LANCE = 0, PCNET_ISA=1, PCNET_ISAP=2, PCNET_PCI=3, PCNET_VLB=4, PCNET_PCI_II=5, LANCE_UNKNOWN=6};
 
-/* Non-zero only if the current card is a PCI with BIOS-set IRQ. */
-static unsigned int pci_irq_line = 0;
 
 /* Non-zero if lance_probe1() needs to allocate low-memory bounce buffers.
    Assume yes until we know the memory size. */
@@ -360,29 +357,6 @@
 	if (high_memory <= phys_to_virt(16*1024*1024))
 		lance_need_isa_bounce_buffers = 0;
 
-#if defined(CONFIG_PCI)
-	{
-		struct pci_dev *pdev = NULL;
-		if (lance_debug > 1)
-			printk("lance.c: PCI bios is present, checking for devices...\n");
-
-		while ((pdev = pci_find_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE, pdev))) {
-			unsigned int pci_ioaddr;
-
-			if (pci_enable_device(pdev))
-				continue;
-			pci_set_master(pdev);
-			pci_irq_line = pdev->irq;
-			pci_ioaddr = pci_resource_start (pdev, 0);
-			printk("Found PCnet/PCI at %#x, irq %d.\n",
-				   pci_ioaddr, pci_irq_line);
-			result = lance_probe1(dev, pci_ioaddr, pci_irq_line, 0);
-			pci_irq_line = 0;
-			if (!result) return 0;
-		}
-	}
-#endif  /* defined(CONFIG_PCI) */
-
 	for (port = lance_portlist; *port; port++) {
 		int ioaddr = *port;
 
@@ -671,7 +645,7 @@
 static int
 lance_open(struct net_device *dev)
 {
-	struct lance_private *lp = (struct lance_private *)dev->priv;
+	struct lance_private *lp = dev->priv;
 	int ioaddr = dev->base_addr;
 	int i;
 
@@ -761,7 +735,7 @@
 static void 
 lance_purge_ring(struct net_device *dev)
 {
-	struct lance_private *lp = (struct lance_private *)dev->priv;
+	struct lance_private *lp = dev->priv;
 	int i;
 
 	/* Free all the skbuffs in the Rx and Tx queues. */
@@ -770,11 +744,11 @@
 		lp->rx_skbuff[i] = 0;
 		lp->rx_ring[i].base = 0;		/* Not owned by LANCE chip. */
 		if (skb)
-			dev_kfree_skb(skb);
+			dev_kfree_skb_any(skb);
 	}
 	for (i = 0; i < TX_RING_SIZE; i++) {
 		if (lp->tx_skbuff[i]) {
-			dev_kfree_skb(lp->tx_skbuff[i]);
+			dev_kfree_skb_any(lp->tx_skbuff[i]);
 			lp->tx_skbuff[i] = NULL;
 		}
 	}
@@ -785,10 +759,9 @@
 static void
 lance_init_ring(struct net_device *dev, int gfp)
 {
-	struct lance_private *lp = (struct lance_private *)dev->priv;
+	struct lance_private *lp = dev->priv;
 	int i;
 
-	lp->tx_full = 0;
 	lp->cur_rx = lp->cur_tx = 0;
 	lp->dirty_rx = lp->dirty_tx = 0;
 
@@ -828,7 +801,7 @@
 static void
 lance_restart(struct net_device *dev, unsigned int csr0_bits, int must_reinit)
 {
-	struct lance_private *lp = (struct lance_private *)dev->priv;
+	struct lance_private *lp = dev->priv;
 
 	if (must_reinit ||
 		(chip_table[lp->chip_version].flags & LANCE_MUST_REINIT_RING)) {
@@ -854,7 +827,7 @@
 	if (lance_debug > 3) {
 		int i;
 		printk (" Ring data dump: dirty_tx %d cur_tx %d%s cur_rx %d.",
-		  lp->dirty_tx, lp->cur_tx, lp->tx_full ? " (full)" : "",
+		  lp->dirty_tx, lp->cur_tx, netif_queue_stopped(dev) ? " (full)" : "",
 			lp->cur_rx);
 		for (i = 0; i < RX_RING_SIZE; i++)
 			printk ("%s %08x %04x %04x", i & 0x3 ? "" : "\n ",
@@ -876,10 +849,13 @@
 
 static int lance_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
-	struct lance_private *lp = (struct lance_private *)dev->priv;
+	struct lance_private *lp = dev->priv;
 	int ioaddr = dev->base_addr;
 	int entry;
 	unsigned long flags;
+
+	spin_lock_irqsave(&lp->devlock, flags);
+
 	if (lance_debug > 3) {
 		outw(0x0000, ioaddr+LANCE_ADDR);
 		printk("%s: lance_start_xmit() called, csr0 %4.4x.\n", dev->name,
@@ -887,8 +863,6 @@
 		outw(0x0000, ioaddr+LANCE_DATA);
 	}
 
-	netif_stop_queue (dev);
-	
 	/* Fill in a Tx ring entry */
 
 	/* Mask to ring buffer boundary. */
@@ -929,13 +903,10 @@
 
 	dev->trans_start = jiffies;
 
-	spin_lock_irqsave (&lp->devlock, flags);
-	if (lp->tx_ring[(entry+1) & TX_RING_MOD_MASK].base == 0)
-		netif_start_queue (dev);
-	else
-		lp->tx_full = 1;
-	spin_unlock_irqrestore (&lp->devlock, flags);
+	if ((lp->cur_tx - lp->dirty_tx) >= TX_RING_SIZE)
+		netif_stop_queue(dev);
 
+	spin_unlock_irqrestore(&lp->devlock, flags);
 	return 0;
 }
 
@@ -954,7 +925,7 @@
 	}
 
 	ioaddr = dev->base_addr;
-	lp = (struct lance_private *)dev->priv;
+	lp = dev->priv;
 	
 	spin_lock (&lp->devlock);
 
@@ -1018,19 +989,17 @@
 
 #ifndef final_version
 			if (lp->cur_tx - dirty_tx >= TX_RING_SIZE) {
-				printk("out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
-					   dirty_tx, lp->cur_tx, lp->tx_full);
+				printk("out-of-sync dirty pointer, %d vs. %d, full=%s.\n",
+					   dirty_tx, lp->cur_tx,
+					   netif_queue_stopped(dev) ? "yes" : "no");
 				dirty_tx += TX_RING_SIZE;
 			}
 #endif
 
-			if (lp->tx_full &&
-			    (netif_queue_stopped(dev)) &&
-			    dirty_tx > lp->cur_tx - TX_RING_SIZE + 2) {
-				/* The ring is no longer full, clear tbusy. */
-				lp->tx_full = 0;
+			/* if the ring is no longer full, accept more packets */
+			if (netif_queue_stopped(dev) &&
+			    dirty_tx > lp->cur_tx - TX_RING_SIZE + 2)
 				netif_wake_queue (dev);
-			}
 
 			lp->dirty_tx = dirty_tx;
 		}
@@ -1068,7 +1037,7 @@
 static int
 lance_rx(struct net_device *dev)
 {
-	struct lance_private *lp = (struct lance_private *)dev->priv;
+	struct lance_private *lp = dev->priv;
 	int entry = lp->cur_rx & RX_RING_MOD_MASK;
 	int i;
 		
@@ -1147,7 +1116,7 @@
 lance_close(struct net_device *dev)
 {
 	int ioaddr = dev->base_addr;
-	struct lance_private *lp = (struct lance_private *)dev->priv;
+	struct lance_private *lp = dev->priv;
 
 	netif_stop_queue (dev);
 
@@ -1181,19 +1150,19 @@
 
 static struct net_device_stats *lance_get_stats(struct net_device *dev)
 {
-	struct lance_private *lp = (struct lance_private *)dev->priv;
-	short ioaddr = dev->base_addr;
-	short saved_addr;
-	unsigned long flags;
+	struct lance_private *lp = dev->priv;
 
 	if (chip_table[lp->chip_version].flags & LANCE_HAS_MISSED_FRAME) {
-		save_flags(flags);
-		cli();
+		short ioaddr = dev->base_addr;
+		short saved_addr;
+		unsigned long flags;
+
+		spin_lock_irqsave(&lp->devlock, flags);
 		saved_addr = inw(ioaddr+LANCE_ADDR);
 		outw(112, ioaddr+LANCE_ADDR);
 		lp->stats.rx_missed_errors = inw(ioaddr+LANCE_DATA);
 		outw(saved_addr, ioaddr+LANCE_ADDR);
-		restore_flags(flags);
+		spin_unlock_irqrestore(&lp->devlock, flags);
 	}
 
 	return &lp->stats;

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