Messages in this thread Patch in this message | | | Date | Sat, 3 Jul 1999 13:16:58 -0300 (EST) | From | Augusto Cesar Radtke <> | Subject | [PATCH]: better usage of spinlocks in networking drivers |
| |
The patch above it's to implement a better usage of spinlocks in misc networking drivers, as Linus says in Documentation/spinlocks.txt you must use the irq version of spinlocks in interrupt handlers. The patch try to do this in some 3com cards and in Donald's skeleton.c (for future hackers reference), but there many others drivers that I need to look in next weeks.
-- Augusto Cesar Radtke Sekure SDI http://www.sekure.org
--- 3c501.c.orig Sat Jul 3 12:49:08 1999 +++ 3c501.c Sat Jul 3 12:51:10 1999 @@ -484,6 +484,7 @@ struct net_local *lp; int ioaddr; int axsr; /* Aux. status reg. */ + unsigned long flags; if (dev == NULL || dev->irq != irq) { @@ -494,7 +495,7 @@ ioaddr = dev->base_addr; lp = (struct net_local *)dev->priv; - spin_lock(&lp->lock); + spin_lock_irqsave(&lp->lock, flags); /* * What happened ? @@ -534,7 +535,7 @@ } lp->loading=2; /* Force a reload */ dev->interrupt = 0; - spin_unlock(&lp->lock); + spin_unlock_irqrestore(&lp->lock, flags); return; } @@ -581,7 +582,7 @@ outb(AX_XMIT, AX_CMD); lp->stats.collisions++; dev->interrupt = 0; - spin_unlock(&lp->lock); + spin_unlock_irqrestore(&lp->lock, flags); return; } else @@ -651,7 +652,7 @@ inb(RX_STATUS); /* Be certain that interrupts are cleared. */ inb(TX_STATUS); dev->interrupt = 0; - spin_unlock(&lp->lock); + spin_unlock_irqrestore(&lp->lock, flags); return; } --- 3c507.c.orig Sat Jul 3 12:46:13 1999 +++ 3c507.c Sat Jul 3 13:09:09 1999 @@ -451,7 +451,9 @@ struct net_local *lp = (struct net_local *)dev->priv; int ioaddr = dev->base_addr; unsigned long shmem = dev->mem_start; +#ifdef CONFIG_SMP unsigned long flags; +#endif if (dev->tbusy) { @@ -518,7 +520,7 @@ struct net_local *lp; int ioaddr, status, boguscount = 0; ushort ack_cmd = 0; - unsigned long shmem; + unsigned long shmem, flags; if (dev == NULL) { printk ("net_interrupt(): irq %d for unknown device.\n", irq); @@ -531,7 +533,7 @@ lp = (struct net_local *)dev->priv; shmem = dev->mem_start; - spin_lock(&lp->lock); + spin_lock_irqsave(&lp->lock, flags); status = readw(shmem+iSCB_STATUS); @@ -611,7 +613,7 @@ /* Enable the 82586's interrupt input. */ outb(0x84, ioaddr + MISC_CTRL); - spin_unlock(&lp->lock); + spin_unlock_irqrestore(&lp->lock, flags); return; } --- 3c509.c.orig Sat Jul 3 12:41:04 1999 +++ 3c509.c Sat Jul 3 12:44:44 1999 @@ -619,6 +619,7 @@ struct el3_private *lp; int ioaddr, status; int i = max_interrupt_work; + unsigned long flags; if (dev == NULL) { printk ("el3_interrupt(): irq %d for unknown device.\n", irq); @@ -626,7 +627,7 @@ } lp = (struct el3_private *)dev->priv; - spin_lock(&lp->lock); + spin_lock_irqsave(&lp->lock, flags); if (dev->interrupt) printk("%s: Re-entering the interrupt handler.\n", dev->name); @@ -701,7 +702,7 @@ printk("%s: exiting interrupt, status %4.4x.\n", dev->name, inw(ioaddr + EL3_STATUS)); } - spin_unlock(&lp->lock); + spin_unlock_irqrestore(&lp->lock, flags); dev->interrupt = 0; return; } --- skeleton.c.orig Sat Jul 3 12:53:11 1999 +++ skeleton.c Sat Jul 3 12:58:46 1999 @@ -55,6 +55,7 @@ #include <asm/bitops.h> #include <asm/io.h> #include <asm/dma.h> +#include <asm/spinlock.h> #include <linux/errno.h> #include <linux/init.h> @@ -87,6 +88,7 @@ struct net_local { struct net_device_stats stats; long open_time; /* Useless example local info. */ + spinlock_t lock; }; /* The station (ethernet) address prefix, used for IDing the board. */ @@ -310,6 +312,10 @@ { struct net_local *lp = (struct net_local *)dev->priv; int ioaddr = dev->base_addr; + + /* setting the spinlock */ + lp->lock = (spinlock_t) SPIN_LOCK_UNLOCKED; + /* * This is used if the interrupt line can turned off (shared). * See 3c503.c for an example of selecting the IRQ at config-time. @@ -392,6 +398,7 @@ struct device *dev = dev_id; struct net_local *lp; int ioaddr, status, boguscount = 0; + unsigned long flags; if (dev == NULL) { printk(KERN_WARNING "%s: irq %d for unknown device.\n", cardname, irq); @@ -401,6 +408,7 @@ ioaddr = dev->base_addr; lp = (struct net_local *)dev->priv; + spin_lock_irqsave(&lp->lock, flags); status = inw(ioaddr + 0); do { @@ -419,6 +427,7 @@ } } while (++boguscount < 20) ; + spin_unlock_irqrestore(&lp->lock, flags); dev->interrupt = 0; return; } --- CREDITS.orig Sat Jul 3 13:00:57 1999 +++ CREDITS Sat Jul 3 13:04:58 1999 @@ -1661,6 +1661,15 @@ S: San Jose, California 95129 S: USA +N: Augusto Cesar Radtke +E: bishop@sekure.org +W: http://bishop.sekure.org +D: Better usage of spinlocks in networking drivers +D: Miscellaneous hacks +S: R. Otto Marquardt, 226 - Garcia +S: 89020-350 Blumenau - Santa Catarina +S: Brazil + N: Eric S. Raymond E: esr@thyrsus.com W: http://www.tuxedo.org/~esr/
| |