Commit efa6a370 authored by Michael Buesch's avatar Michael Buesch Committed by John W. Linville

[PATCH] bcm43xx: opencoded locking

As many people don't seem to like the locking "obfuscation"
in the bcm43xx driver, this patch removes it.
Signed-off-by: default avatarMichael Buesch <mb@bu3sch.de>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent b312d799
...@@ -649,6 +649,19 @@ enum { ...@@ -649,6 +649,19 @@ enum {
#define bcm43xx_status(bcm) atomic_read(&(bcm)->init_status) #define bcm43xx_status(bcm) atomic_read(&(bcm)->init_status)
#define bcm43xx_set_status(bcm, stat) atomic_set(&(bcm)->init_status, (stat)) #define bcm43xx_set_status(bcm, stat) atomic_set(&(bcm)->init_status, (stat))
/* *** THEORY OF LOCKING ***
*
* We have two different locks in the bcm43xx driver.
* => bcm->mutex: General sleeping mutex. Protects struct bcm43xx_private
* and the device registers. This mutex does _not_ protect
* against concurrency from the IRQ handler.
* => bcm->irq_lock: IRQ spinlock. Protects against IRQ handler concurrency.
*
* Please note that, if you only take the irq_lock, you are not protected
* against concurrency from the periodic work handlers.
* Most times you want to take _both_ locks.
*/
struct bcm43xx_private { struct bcm43xx_private {
struct ieee80211_device *ieee; struct ieee80211_device *ieee;
struct ieee80211softmac_device *softmac; struct ieee80211softmac_device *softmac;
...@@ -659,7 +672,6 @@ struct bcm43xx_private { ...@@ -659,7 +672,6 @@ struct bcm43xx_private {
void __iomem *mmio_addr; void __iomem *mmio_addr;
/* Locking, see "theory of locking" text below. */
spinlock_t irq_lock; spinlock_t irq_lock;
struct mutex mutex; struct mutex mutex;
...@@ -691,6 +703,7 @@ struct bcm43xx_private { ...@@ -691,6 +703,7 @@ struct bcm43xx_private {
struct bcm43xx_sprominfo sprom; struct bcm43xx_sprominfo sprom;
#define BCM43xx_NR_LEDS 4 #define BCM43xx_NR_LEDS 4
struct bcm43xx_led leds[BCM43xx_NR_LEDS]; struct bcm43xx_led leds[BCM43xx_NR_LEDS];
spinlock_t leds_lock;
/* The currently active core. */ /* The currently active core. */
struct bcm43xx_coreinfo *current_core; struct bcm43xx_coreinfo *current_core;
...@@ -763,55 +776,6 @@ struct bcm43xx_private { ...@@ -763,55 +776,6 @@ struct bcm43xx_private {
}; };
/* *** THEORY OF LOCKING ***
*
* We have two different locks in the bcm43xx driver.
* => bcm->mutex: General sleeping mutex. Protects struct bcm43xx_private
* and the device registers.
* => bcm->irq_lock: IRQ spinlock. Protects against IRQ handler concurrency.
*
* We have three types of helper function pairs to utilize these locks.
* (Always use the helper functions.)
* 1) bcm43xx_{un}lock_noirq():
* Takes bcm->mutex. Does _not_ protect against IRQ concurrency,
* so it is almost always unsafe, if device IRQs are enabled.
* So only use this, if device IRQs are masked.
* Locking may sleep.
* You can sleep within the critical section.
* 2) bcm43xx_{un}lock_irqonly():
* Takes bcm->irq_lock. Does _not_ protect against
* bcm43xx_lock_noirq() critical sections.
* Does only protect against the IRQ handler path and other
* irqonly() critical sections.
* Locking does not sleep.
* You must not sleep within the critical section.
* 3) bcm43xx_{un}lock_irqsafe():
* This is the cummulative lock and takes both, mutex and irq_lock.
* Protects against noirq() and irqonly() critical sections (and
* the IRQ handler path).
* Locking may sleep.
* You must not sleep within the critical section.
*/
/* Lock type 1 */
#define bcm43xx_lock_noirq(bcm) mutex_lock(&(bcm)->mutex)
#define bcm43xx_unlock_noirq(bcm) mutex_unlock(&(bcm)->mutex)
/* Lock type 2 */
#define bcm43xx_lock_irqonly(bcm, flags) \
spin_lock_irqsave(&(bcm)->irq_lock, flags)
#define bcm43xx_unlock_irqonly(bcm, flags) \
spin_unlock_irqrestore(&(bcm)->irq_lock, flags)
/* Lock type 3 */
#define bcm43xx_lock_irqsafe(bcm, flags) do { \
bcm43xx_lock_noirq(bcm); \
bcm43xx_lock_irqonly(bcm, flags); \
} while (0)
#define bcm43xx_unlock_irqsafe(bcm, flags) do { \
bcm43xx_unlock_irqonly(bcm, flags); \
bcm43xx_unlock_noirq(bcm); \
} while (0)
static inline static inline
struct bcm43xx_private * bcm43xx_priv(struct net_device *dev) struct bcm43xx_private * bcm43xx_priv(struct net_device *dev)
{ {
......
...@@ -77,7 +77,8 @@ static ssize_t devinfo_read_file(struct file *file, char __user *userbuf, ...@@ -77,7 +77,8 @@ static ssize_t devinfo_read_file(struct file *file, char __user *userbuf,
down(&big_buffer_sem); down(&big_buffer_sem);
bcm43xx_lock_irqsafe(bcm, flags); mutex_lock(&bcm->mutex);
spin_lock_irqsave(&bcm->irq_lock, flags);
if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) { if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
fappend("Board not initialized.\n"); fappend("Board not initialized.\n");
goto out; goto out;
...@@ -121,7 +122,8 @@ static ssize_t devinfo_read_file(struct file *file, char __user *userbuf, ...@@ -121,7 +122,8 @@ static ssize_t devinfo_read_file(struct file *file, char __user *userbuf,
fappend("\n"); fappend("\n");
out: out:
bcm43xx_unlock_irqsafe(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
mutex_unlock(&bcm->mutex);
res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
up(&big_buffer_sem); up(&big_buffer_sem);
return res; return res;
...@@ -159,7 +161,8 @@ static ssize_t spromdump_read_file(struct file *file, char __user *userbuf, ...@@ -159,7 +161,8 @@ static ssize_t spromdump_read_file(struct file *file, char __user *userbuf,
unsigned long flags; unsigned long flags;
down(&big_buffer_sem); down(&big_buffer_sem);
bcm43xx_lock_irqsafe(bcm, flags); mutex_lock(&bcm->mutex);
spin_lock_irqsave(&bcm->irq_lock, flags);
if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) { if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
fappend("Board not initialized.\n"); fappend("Board not initialized.\n");
goto out; goto out;
...@@ -169,7 +172,8 @@ static ssize_t spromdump_read_file(struct file *file, char __user *userbuf, ...@@ -169,7 +172,8 @@ static ssize_t spromdump_read_file(struct file *file, char __user *userbuf,
fappend("boardflags: 0x%04x\n", bcm->sprom.boardflags); fappend("boardflags: 0x%04x\n", bcm->sprom.boardflags);
out: out:
bcm43xx_unlock_irqsafe(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
mutex_unlock(&bcm->mutex);
res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
up(&big_buffer_sem); up(&big_buffer_sem);
return res; return res;
...@@ -188,7 +192,8 @@ static ssize_t tsf_read_file(struct file *file, char __user *userbuf, ...@@ -188,7 +192,8 @@ static ssize_t tsf_read_file(struct file *file, char __user *userbuf,
u64 tsf; u64 tsf;
down(&big_buffer_sem); down(&big_buffer_sem);
bcm43xx_lock_irqsafe(bcm, flags); mutex_lock(&bcm->mutex);
spin_lock_irqsave(&bcm->irq_lock, flags);
if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) { if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
fappend("Board not initialized.\n"); fappend("Board not initialized.\n");
goto out; goto out;
...@@ -199,7 +204,8 @@ static ssize_t tsf_read_file(struct file *file, char __user *userbuf, ...@@ -199,7 +204,8 @@ static ssize_t tsf_read_file(struct file *file, char __user *userbuf,
(unsigned int)(tsf & 0xFFFFFFFFULL)); (unsigned int)(tsf & 0xFFFFFFFFULL));
out: out:
bcm43xx_unlock_irqsafe(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
mutex_unlock(&bcm->mutex);
res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
up(&big_buffer_sem); up(&big_buffer_sem);
return res; return res;
...@@ -221,7 +227,8 @@ static ssize_t tsf_write_file(struct file *file, const char __user *user_buf, ...@@ -221,7 +227,8 @@ static ssize_t tsf_write_file(struct file *file, const char __user *user_buf,
res = -EFAULT; res = -EFAULT;
goto out_up; goto out_up;
} }
bcm43xx_lock_irqsafe(bcm, flags); mutex_lock(&bcm->mutex);
spin_lock_irqsave(&bcm->irq_lock, flags);
if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) { if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
printk(KERN_INFO PFX "debugfs: Board not initialized.\n"); printk(KERN_INFO PFX "debugfs: Board not initialized.\n");
res = -EFAULT; res = -EFAULT;
...@@ -237,7 +244,8 @@ static ssize_t tsf_write_file(struct file *file, const char __user *user_buf, ...@@ -237,7 +244,8 @@ static ssize_t tsf_write_file(struct file *file, const char __user *user_buf,
res = buf_size; res = buf_size;
out_unlock: out_unlock:
bcm43xx_unlock_irqsafe(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
mutex_unlock(&bcm->mutex);
out_up: out_up:
up(&big_buffer_sem); up(&big_buffer_sem);
return res; return res;
...@@ -258,7 +266,8 @@ static ssize_t txstat_read_file(struct file *file, char __user *userbuf, ...@@ -258,7 +266,8 @@ static ssize_t txstat_read_file(struct file *file, char __user *userbuf,
int i, cnt, j = 0; int i, cnt, j = 0;
down(&big_buffer_sem); down(&big_buffer_sem);
bcm43xx_lock_irqsafe(bcm, flags); mutex_lock(&bcm->mutex);
spin_lock_irqsave(&bcm->irq_lock, flags);
fappend("Last %d logged xmitstatus blobs (Latest first):\n\n", fappend("Last %d logged xmitstatus blobs (Latest first):\n\n",
BCM43xx_NR_LOGGED_XMITSTATUS); BCM43xx_NR_LOGGED_XMITSTATUS);
...@@ -294,14 +303,15 @@ static ssize_t txstat_read_file(struct file *file, char __user *userbuf, ...@@ -294,14 +303,15 @@ static ssize_t txstat_read_file(struct file *file, char __user *userbuf,
i = BCM43xx_NR_LOGGED_XMITSTATUS - 1; i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
} }
bcm43xx_unlock_irqsafe(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
bcm43xx_lock_irqsafe(bcm, flags); spin_lock_irqsave(&bcm->irq_lock, flags);
if (*ppos == pos) { if (*ppos == pos) {
/* Done. Drop the copied data. */ /* Done. Drop the copied data. */
e->xmitstatus_printing = 0; e->xmitstatus_printing = 0;
} }
bcm43xx_unlock_irqsafe(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
mutex_unlock(&bcm->mutex);
up(&big_buffer_sem); up(&big_buffer_sem);
return res; return res;
} }
......
...@@ -51,12 +51,12 @@ static void bcm43xx_led_blink(unsigned long d) ...@@ -51,12 +51,12 @@ static void bcm43xx_led_blink(unsigned long d)
struct bcm43xx_private *bcm = led->bcm; struct bcm43xx_private *bcm = led->bcm;
unsigned long flags; unsigned long flags;
bcm43xx_lock_irqonly(bcm, flags); spin_lock_irqsave(&bcm->leds_lock, flags);
if (led->blink_interval) { if (led->blink_interval) {
bcm43xx_led_changestate(led); bcm43xx_led_changestate(led);
mod_timer(&led->blink_timer, jiffies + led->blink_interval); mod_timer(&led->blink_timer, jiffies + led->blink_interval);
} }
bcm43xx_unlock_irqonly(bcm, flags); spin_unlock_irqrestore(&bcm->leds_lock, flags);
} }
static void bcm43xx_led_blink_start(struct bcm43xx_led *led, static void bcm43xx_led_blink_start(struct bcm43xx_led *led,
...@@ -177,7 +177,9 @@ void bcm43xx_leds_update(struct bcm43xx_private *bcm, int activity) ...@@ -177,7 +177,9 @@ void bcm43xx_leds_update(struct bcm43xx_private *bcm, int activity)
int i, turn_on; int i, turn_on;
unsigned long interval = 0; unsigned long interval = 0;
u16 ledctl; u16 ledctl;
unsigned long flags;
spin_lock_irqsave(&bcm->leds_lock, flags);
ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL); ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
for (i = 0; i < BCM43xx_NR_LEDS; i++) { for (i = 0; i < BCM43xx_NR_LEDS; i++) {
led = &(bcm->leds[i]); led = &(bcm->leds[i]);
...@@ -266,6 +268,7 @@ void bcm43xx_leds_update(struct bcm43xx_private *bcm, int activity) ...@@ -266,6 +268,7 @@ void bcm43xx_leds_update(struct bcm43xx_private *bcm, int activity)
ledctl &= ~(1 << i); ledctl &= ~(1 << i);
} }
bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl); bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
spin_unlock_irqrestore(&bcm->leds_lock, flags);
} }
void bcm43xx_leds_switch_all(struct bcm43xx_private *bcm, int on) void bcm43xx_leds_switch_all(struct bcm43xx_private *bcm, int on)
...@@ -274,7 +277,9 @@ void bcm43xx_leds_switch_all(struct bcm43xx_private *bcm, int on) ...@@ -274,7 +277,9 @@ void bcm43xx_leds_switch_all(struct bcm43xx_private *bcm, int on)
u16 ledctl; u16 ledctl;
int i; int i;
int bit_on; int bit_on;
unsigned long flags;
spin_lock_irqsave(&bcm->leds_lock, flags);
ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL); ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
for (i = 0; i < BCM43xx_NR_LEDS; i++) { for (i = 0; i < BCM43xx_NR_LEDS; i++) {
led = &(bcm->leds[i]); led = &(bcm->leds[i]);
...@@ -290,4 +295,5 @@ void bcm43xx_leds_switch_all(struct bcm43xx_private *bcm, int on) ...@@ -290,4 +295,5 @@ void bcm43xx_leds_switch_all(struct bcm43xx_private *bcm, int on)
ledctl &= ~(1 << i); ledctl &= ~(1 << i);
} }
bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl); bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
spin_unlock_irqrestore(&bcm->leds_lock, flags);
} }
...@@ -514,13 +514,13 @@ static int bcm43xx_disable_interrupts_sync(struct bcm43xx_private *bcm, u32 *old ...@@ -514,13 +514,13 @@ static int bcm43xx_disable_interrupts_sync(struct bcm43xx_private *bcm, u32 *old
unsigned long flags; unsigned long flags;
u32 old; u32 old;
bcm43xx_lock_irqonly(bcm, flags); spin_lock_irqsave(&bcm->irq_lock, flags);
if (unlikely(bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED)) { if (unlikely(bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED)) {
bcm43xx_unlock_irqonly(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
return -EBUSY; return -EBUSY;
} }
old = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL); old = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
bcm43xx_unlock_irqonly(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
bcm43xx_synchronize_irq(bcm); bcm43xx_synchronize_irq(bcm);
if (oldstate) if (oldstate)
...@@ -1720,7 +1720,7 @@ static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm) ...@@ -1720,7 +1720,7 @@ static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm)
# define bcmirq_handled(irq) do { /* nothing */ } while (0) # define bcmirq_handled(irq) do { /* nothing */ } while (0)
#endif /* CONFIG_BCM43XX_DEBUG*/ #endif /* CONFIG_BCM43XX_DEBUG*/
bcm43xx_lock_irqonly(bcm, flags); spin_lock_irqsave(&bcm->irq_lock, flags);
reason = bcm->irq_reason; reason = bcm->irq_reason;
dma_reason[0] = bcm->dma_reason[0]; dma_reason[0] = bcm->dma_reason[0];
dma_reason[1] = bcm->dma_reason[1]; dma_reason[1] = bcm->dma_reason[1];
...@@ -1746,7 +1746,7 @@ static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm) ...@@ -1746,7 +1746,7 @@ static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm)
dma_reason[2], dma_reason[3]); dma_reason[2], dma_reason[3]);
bcm43xx_controller_restart(bcm, "DMA error"); bcm43xx_controller_restart(bcm, "DMA error");
mmiowb(); mmiowb();
bcm43xx_unlock_irqonly(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
return; return;
} }
if (unlikely((dma_reason[0] & BCM43xx_DMAIRQ_NONFATALMASK) | if (unlikely((dma_reason[0] & BCM43xx_DMAIRQ_NONFATALMASK) |
...@@ -1834,7 +1834,7 @@ static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm) ...@@ -1834,7 +1834,7 @@ static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm)
bcm43xx_leds_update(bcm, activity); bcm43xx_leds_update(bcm, activity);
bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate); bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
mmiowb(); mmiowb();
bcm43xx_unlock_irqonly(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
} }
static void pio_irq_workaround(struct bcm43xx_private *bcm, static void pio_irq_workaround(struct bcm43xx_private *bcm,
...@@ -3182,25 +3182,26 @@ static void bcm43xx_periodic_work_handler(void *d) ...@@ -3182,25 +3182,26 @@ static void bcm43xx_periodic_work_handler(void *d)
/* Periodic work will take a long time, so we want it to /* Periodic work will take a long time, so we want it to
* be preemtible. * be preemtible.
*/ */
bcm43xx_lock_irqonly(bcm, flags);
netif_stop_queue(bcm->net_dev); netif_stop_queue(bcm->net_dev);
spin_lock_irqsave(&bcm->irq_lock, flags);
if (bcm43xx_using_pio(bcm)) if (bcm43xx_using_pio(bcm))
bcm43xx_pio_freeze_txqueues(bcm); bcm43xx_pio_freeze_txqueues(bcm);
savedirqs = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL); savedirqs = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
bcm43xx_unlock_irqonly(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
bcm43xx_lock_noirq(bcm); mutex_lock(&bcm->mutex);
bcm43xx_synchronize_irq(bcm); bcm43xx_synchronize_irq(bcm);
} else { } else {
/* Periodic work should take short time, so we want low /* Periodic work should take short time, so we want low
* locking overhead. * locking overhead.
*/ */
bcm43xx_lock_irqsafe(bcm, flags); mutex_lock(&bcm->mutex);
spin_lock_irqsave(&bcm->irq_lock, flags);
} }
do_periodic_work(bcm); do_periodic_work(bcm);
if (badness > BADNESS_LIMIT) { if (badness > BADNESS_LIMIT) {
bcm43xx_lock_irqonly(bcm, flags); spin_lock_irqsave(&bcm->irq_lock, flags);
if (likely(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED)) { if (likely(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED)) {
tasklet_enable(&bcm->isr_tasklet); tasklet_enable(&bcm->isr_tasklet);
bcm43xx_interrupt_enable(bcm, savedirqs); bcm43xx_interrupt_enable(bcm, savedirqs);
...@@ -3208,13 +3209,10 @@ static void bcm43xx_periodic_work_handler(void *d) ...@@ -3208,13 +3209,10 @@ static void bcm43xx_periodic_work_handler(void *d)
bcm43xx_pio_thaw_txqueues(bcm); bcm43xx_pio_thaw_txqueues(bcm);
} }
netif_wake_queue(bcm->net_dev); netif_wake_queue(bcm->net_dev);
mmiowb();
bcm43xx_unlock_irqonly(bcm, flags);
bcm43xx_unlock_noirq(bcm);
} else {
mmiowb();
bcm43xx_unlock_irqsafe(bcm, flags);
} }
mmiowb();
spin_unlock_irqrestore(&bcm->irq_lock, flags);
mutex_unlock(&bcm->mutex);
} }
static void bcm43xx_periodic_tasks_delete(struct bcm43xx_private *bcm) static void bcm43xx_periodic_tasks_delete(struct bcm43xx_private *bcm)
...@@ -3276,7 +3274,7 @@ static void bcm43xx_free_board(struct bcm43xx_private *bcm) ...@@ -3276,7 +3274,7 @@ static void bcm43xx_free_board(struct bcm43xx_private *bcm)
{ {
int i, err; int i, err;
bcm43xx_lock_noirq(bcm); mutex_lock(&bcm->mutex);
bcm43xx_sysfs_unregister(bcm); bcm43xx_sysfs_unregister(bcm);
bcm43xx_periodic_tasks_delete(bcm); bcm43xx_periodic_tasks_delete(bcm);
...@@ -3297,7 +3295,7 @@ static void bcm43xx_free_board(struct bcm43xx_private *bcm) ...@@ -3297,7 +3295,7 @@ static void bcm43xx_free_board(struct bcm43xx_private *bcm)
bcm43xx_pctl_set_crystal(bcm, 0); bcm43xx_pctl_set_crystal(bcm, 0);
bcm43xx_set_status(bcm, BCM43xx_STAT_UNINIT); bcm43xx_set_status(bcm, BCM43xx_STAT_UNINIT);
bcm43xx_unlock_noirq(bcm); mutex_unlock(&bcm->mutex);
} }
static int bcm43xx_init_board(struct bcm43xx_private *bcm) static int bcm43xx_init_board(struct bcm43xx_private *bcm)
...@@ -3307,7 +3305,7 @@ static int bcm43xx_init_board(struct bcm43xx_private *bcm) ...@@ -3307,7 +3305,7 @@ static int bcm43xx_init_board(struct bcm43xx_private *bcm)
might_sleep(); might_sleep();
bcm43xx_lock_noirq(bcm); mutex_lock(&bcm->mutex);
bcm43xx_set_status(bcm, BCM43xx_STAT_INITIALIZING); bcm43xx_set_status(bcm, BCM43xx_STAT_INITIALIZING);
err = bcm43xx_pctl_set_crystal(bcm, 1); err = bcm43xx_pctl_set_crystal(bcm, 1);
...@@ -3389,7 +3387,7 @@ static int bcm43xx_init_board(struct bcm43xx_private *bcm) ...@@ -3389,7 +3387,7 @@ static int bcm43xx_init_board(struct bcm43xx_private *bcm)
assert(err == 0); assert(err == 0);
out: out:
bcm43xx_unlock_noirq(bcm); mutex_unlock(&bcm->mutex);
return err; return err;
...@@ -3647,7 +3645,8 @@ static void bcm43xx_ieee80211_set_chan(struct net_device *net_dev, ...@@ -3647,7 +3645,8 @@ static void bcm43xx_ieee80211_set_chan(struct net_device *net_dev,
struct bcm43xx_radioinfo *radio; struct bcm43xx_radioinfo *radio;
unsigned long flags; unsigned long flags;
bcm43xx_lock_irqsafe(bcm, flags); mutex_lock(&bcm->mutex);
spin_lock_irqsave(&bcm->irq_lock, flags);
if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) { if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) {
bcm43xx_mac_suspend(bcm); bcm43xx_mac_suspend(bcm);
bcm43xx_radio_selectchannel(bcm, channel, 0); bcm43xx_radio_selectchannel(bcm, channel, 0);
...@@ -3656,7 +3655,8 @@ static void bcm43xx_ieee80211_set_chan(struct net_device *net_dev, ...@@ -3656,7 +3655,8 @@ static void bcm43xx_ieee80211_set_chan(struct net_device *net_dev,
radio = bcm43xx_current_radio(bcm); radio = bcm43xx_current_radio(bcm);
radio->initial_channel = channel; radio->initial_channel = channel;
} }
bcm43xx_unlock_irqsafe(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
mutex_unlock(&bcm->mutex);
} }
/* set_security() callback in struct ieee80211_device */ /* set_security() callback in struct ieee80211_device */
...@@ -3670,7 +3670,8 @@ static void bcm43xx_ieee80211_set_security(struct net_device *net_dev, ...@@ -3670,7 +3670,8 @@ static void bcm43xx_ieee80211_set_security(struct net_device *net_dev,
dprintk(KERN_INFO PFX "set security called"); dprintk(KERN_INFO PFX "set security called");
bcm43xx_lock_irqsafe(bcm, flags); mutex_lock(&bcm->mutex);
spin_lock_irqsave(&bcm->irq_lock, flags);
for (keyidx = 0; keyidx<WEP_KEYS; keyidx++) for (keyidx = 0; keyidx<WEP_KEYS; keyidx++)
if (sec->flags & (1<<keyidx)) { if (sec->flags & (1<<keyidx)) {
...@@ -3739,7 +3740,8 @@ static void bcm43xx_ieee80211_set_security(struct net_device *net_dev, ...@@ -3739,7 +3740,8 @@ static void bcm43xx_ieee80211_set_security(struct net_device *net_dev,
} else } else
bcm43xx_clear_keys(bcm); bcm43xx_clear_keys(bcm);
} }
bcm43xx_unlock_irqsafe(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
mutex_unlock(&bcm->mutex);
} }
/* hard_start_xmit() callback in struct ieee80211_device */ /* hard_start_xmit() callback in struct ieee80211_device */
...@@ -3751,10 +3753,10 @@ static int bcm43xx_ieee80211_hard_start_xmit(struct ieee80211_txb *txb, ...@@ -3751,10 +3753,10 @@ static int bcm43xx_ieee80211_hard_start_xmit(struct ieee80211_txb *txb,
int err = -ENODEV; int err = -ENODEV;
unsigned long flags; unsigned long flags;
bcm43xx_lock_irqonly(bcm, flags); spin_lock_irqsave(&bcm->irq_lock, flags);
if (likely(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED)) if (likely(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED))
err = bcm43xx_tx(bcm, txb); err = bcm43xx_tx(bcm, txb);
bcm43xx_unlock_irqonly(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
return err; return err;
} }
...@@ -3769,9 +3771,9 @@ static void bcm43xx_net_tx_timeout(struct net_device *net_dev) ...@@ -3769,9 +3771,9 @@ static void bcm43xx_net_tx_timeout(struct net_device *net_dev)
struct bcm43xx_private *bcm = bcm43xx_priv(net_dev); struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
unsigned long flags; unsigned long flags;
bcm43xx_lock_irqonly(bcm, flags); spin_lock_irqsave(&bcm->irq_lock, flags);
bcm43xx_controller_restart(bcm, "TX timeout"); bcm43xx_controller_restart(bcm, "TX timeout");
bcm43xx_unlock_irqonly(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
} }
#ifdef CONFIG_NET_POLL_CONTROLLER #ifdef CONFIG_NET_POLL_CONTROLLER
...@@ -3822,6 +3824,7 @@ static int bcm43xx_init_private(struct bcm43xx_private *bcm, ...@@ -3822,6 +3824,7 @@ static int bcm43xx_init_private(struct bcm43xx_private *bcm,
bcm->net_dev = net_dev; bcm->net_dev = net_dev;
bcm->bad_frames_preempt = modparam_bad_frames_preempt; bcm->bad_frames_preempt = modparam_bad_frames_preempt;
spin_lock_init(&bcm->irq_lock); spin_lock_init(&bcm->irq_lock);
spin_lock_init(&bcm->leds_lock);
mutex_init(&bcm->mutex); mutex_init(&bcm->mutex);
tasklet_init(&bcm->isr_tasklet, tasklet_init(&bcm->isr_tasklet,
(void (*)(unsigned long))bcm43xx_interrupt_tasklet, (void (*)(unsigned long))bcm43xx_interrupt_tasklet,
...@@ -4002,16 +4005,13 @@ static int bcm43xx_suspend(struct pci_dev *pdev, pm_message_t state) ...@@ -4002,16 +4005,13 @@ static int bcm43xx_suspend(struct pci_dev *pdev, pm_message_t state)
{ {
struct net_device *net_dev = pci_get_drvdata(pdev); struct net_device *net_dev = pci_get_drvdata(pdev);
struct bcm43xx_private *bcm = bcm43xx_priv(net_dev); struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
unsigned long flags;
int try_to_shutdown = 0, err; int try_to_shutdown = 0, err;
dprintk(KERN_INFO PFX "Suspending...\n"); dprintk(KERN_INFO PFX "Suspending...\n");
bcm43xx_lock_irqsafe(bcm, flags);
bcm->was_initialized = (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED); bcm->was_initialized = (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED);
if (bcm->was_initialized) if (bcm->was_initialized)
try_to_shutdown = 1; try_to_shutdown = 1;
bcm43xx_unlock_irqsafe(bcm, flags);
netif_device_detach(net_dev); netif_device_detach(net_dev);
if (try_to_shutdown) { if (try_to_shutdown) {
......
...@@ -262,7 +262,7 @@ static void tx_tasklet(unsigned long d) ...@@ -262,7 +262,7 @@ static void tx_tasklet(unsigned long d)
int err; int err;
u16 txctl; u16 txctl;
bcm43xx_lock_irqonly(bcm, flags); spin_lock_irqsave(&bcm->irq_lock, flags);
if (queue->tx_frozen) if (queue->tx_frozen)
goto out_unlock; goto out_unlock;
...@@ -300,7 +300,7 @@ static void tx_tasklet(unsigned long d) ...@@ -300,7 +300,7 @@ static void tx_tasklet(unsigned long d)
continue; continue;
} }
out_unlock: out_unlock:
bcm43xx_unlock_irqonly(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
} }
static void setup_txqueues(struct bcm43xx_pioqueue *queue) static void setup_txqueues(struct bcm43xx_pioqueue *queue)
......
...@@ -120,12 +120,14 @@ static ssize_t bcm43xx_attr_sprom_show(struct device *dev, ...@@ -120,12 +120,14 @@ static ssize_t bcm43xx_attr_sprom_show(struct device *dev,
GFP_KERNEL); GFP_KERNEL);
if (!sprom) if (!sprom)
return -ENOMEM; return -ENOMEM;
bcm43xx_lock_irqsafe(bcm, flags); mutex_lock(&bcm->mutex);
spin_lock_irqsave(&bcm->irq_lock, flags);
err = bcm43xx_sprom_read(bcm, sprom); err = bcm43xx_sprom_read(bcm, sprom);
if (!err) if (!err)
err = sprom2hex(sprom, buf, PAGE_SIZE); err = sprom2hex(sprom, buf, PAGE_SIZE);
mmiowb(); mmiowb();
bcm43xx_unlock_irqsafe(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
mutex_unlock(&bcm->mutex);
kfree(sprom); kfree(sprom);
return err; return err;
...@@ -150,10 +152,14 @@ static ssize_t bcm43xx_attr_sprom_store(struct device *dev, ...@@ -150,10 +152,14 @@ static ssize_t bcm43xx_attr_sprom_store(struct device *dev,
err = hex2sprom(sprom, buf, count); err = hex2sprom(sprom, buf, count);
if (err) if (err)
goto out_kfree; goto out_kfree;
bcm43xx_lock_irqsafe(bcm, flags); mutex_lock(&bcm->mutex);
spin_lock_irqsave(&bcm->irq_lock, flags);
spin_lock(&bcm->leds_lock);
err = bcm43xx_sprom_write(bcm, sprom); err = bcm43xx_sprom_write(bcm, sprom);
mmiowb(); mmiowb();
bcm43xx_unlock_irqsafe(bcm, flags); spin_unlock(&bcm->leds_lock);
spin_unlock_irqrestore(&bcm->irq_lock, flags);
mutex_unlock(&bcm->mutex);
out_kfree: out_kfree:
kfree(sprom); kfree(sprom);
...@@ -176,7 +182,7 @@ static ssize_t bcm43xx_attr_interfmode_show(struct device *dev, ...@@ -176,7 +182,7 @@ static ssize_t bcm43xx_attr_interfmode_show(struct device *dev,
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
bcm43xx_lock_noirq(bcm); mutex_lock(&bcm->mutex);
switch (bcm43xx_current_radio(bcm)->interfmode) { switch (bcm43xx_current_radio(bcm)->interfmode) {
case BCM43xx_RADIO_INTERFMODE_NONE: case BCM43xx_RADIO_INTERFMODE_NONE:
...@@ -193,7 +199,7 @@ static ssize_t bcm43xx_attr_interfmode_show(struct device *dev, ...@@ -193,7 +199,7 @@ static ssize_t bcm43xx_attr_interfmode_show(struct device *dev,
} }
err = 0; err = 0;
bcm43xx_unlock_noirq(bcm); mutex_unlock(&bcm->mutex);
return err ? err : count; return err ? err : count;
...@@ -229,7 +235,8 @@ static ssize_t bcm43xx_attr_interfmode_store(struct device *dev, ...@@ -229,7 +235,8 @@ static ssize_t bcm43xx_attr_interfmode_store(struct device *dev,
return -EINVAL; return -EINVAL;
} }
bcm43xx_lock_irqsafe(bcm, flags); mutex_lock(&bcm->mutex);
spin_lock_irqsave(&bcm->irq_lock, flags);
err = bcm43xx_radio_set_interference_mitigation(bcm, mode); err = bcm43xx_radio_set_interference_mitigation(bcm, mode);
if (err) { if (err) {
...@@ -237,7 +244,8 @@ static ssize_t bcm43xx_attr_interfmode_store(struct device *dev, ...@@ -237,7 +244,8 @@ static ssize_t bcm43xx_attr_interfmode_store(struct device *dev,
"supported by device\n"); "supported by device\n");
} }
mmiowb(); mmiowb();
bcm43xx_unlock_irqsafe(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
mutex_unlock(&bcm->mutex);
return err ? err : count; return err ? err : count;
} }
...@@ -257,7 +265,7 @@ static ssize_t bcm43xx_attr_preamble_show(struct device *dev, ...@@ -257,7 +265,7 @@ static ssize_t bcm43xx_attr_preamble_show(struct device *dev,
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
bcm43xx_lock_noirq(bcm); mutex_lock(&bcm->mutex);
if (bcm->short_preamble) if (bcm->short_preamble)
count = snprintf(buf, PAGE_SIZE, "1 (Short Preamble enabled)\n"); count = snprintf(buf, PAGE_SIZE, "1 (Short Preamble enabled)\n");
...@@ -265,7 +273,7 @@ static ssize_t bcm43xx_attr_preamble_show(struct device *dev, ...@@ -265,7 +273,7 @@ static ssize_t bcm43xx_attr_preamble_show(struct device *dev,
count = snprintf(buf, PAGE_SIZE, "0 (Short Preamble disabled)\n"); count = snprintf(buf, PAGE_SIZE, "0 (Short Preamble disabled)\n");
err = 0; err = 0;
bcm43xx_unlock_noirq(bcm); mutex_unlock(&bcm->mutex);
return err ? err : count; return err ? err : count;
} }
...@@ -285,12 +293,14 @@ static ssize_t bcm43xx_attr_preamble_store(struct device *dev, ...@@ -285,12 +293,14 @@ static ssize_t bcm43xx_attr_preamble_store(struct device *dev,
value = get_boolean(buf, count); value = get_boolean(buf, count);
if (value < 0) if (value < 0)
return value; return value;
bcm43xx_lock_irqsafe(bcm, flags); mutex_lock(&bcm->mutex);
spin_lock_irqsave(&bcm->irq_lock, flags);
bcm->short_preamble = !!value; bcm->short_preamble = !!value;
err = 0; err = 0;
bcm43xx_unlock_irqsafe(bcm, flags); spin_unlock_irqrestore(&bcm->irq_lock, flags);
mutex_unlock(&bcm->mutex);
return err ? err : count; return err ? err : count;
} }
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment