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

[PATCH] bcm43xx: redesign locking

Redesign the bcm43xx locking.
This is pre-work to get a preemptible periodic work handler.
Signed-off-by: default avatarMichael Buesch <mb@bu3sch.de>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 74f49033
...@@ -636,6 +636,17 @@ struct bcm43xx_key { ...@@ -636,6 +636,17 @@ struct bcm43xx_key {
u8 algorithm; u8 algorithm;
}; };
/* Driver initialization status. */
enum {
BCM43xx_STAT_UNINIT, /* Uninitialized. */
BCM43xx_STAT_INITIALIZING, /* init_board() in progress. */
BCM43xx_STAT_INITIALIZED, /* Fully operational. */
BCM43xx_STAT_SHUTTINGDOWN, /* free_board() in progress. */
BCM43xx_STAT_RESTARTING, /* controller_restart() called. */
};
#define bcm43xx_status(bcm) atomic_read(&(bcm)->init_status)
#define bcm43xx_set_status(bcm, stat) atomic_set(&(bcm)->init_status, (stat))
struct bcm43xx_private { struct bcm43xx_private {
struct ieee80211_device *ieee; struct ieee80211_device *ieee;
struct ieee80211softmac_device *softmac; struct ieee80211softmac_device *softmac;
...@@ -646,18 +657,17 @@ struct bcm43xx_private { ...@@ -646,18 +657,17 @@ struct bcm43xx_private {
void __iomem *mmio_addr; void __iomem *mmio_addr;
/* Do not use the lock directly. Use the bcm43xx_lock* helper /* Locking, see "theory of locking" text below. */
* functions, to be MMIO-safe. */ spinlock_t irq_lock;
spinlock_t _lock; struct mutex mutex;
/* Driver status flags. */ /* Driver initialization status BCM43xx_STAT_*** */
u32 initialized:1, /* init_board() succeed */ atomic_t init_status;
was_initialized:1, /* for PCI suspend/resume. */
shutting_down:1, /* free_board() in progress */ u16 was_initialized:1, /* for PCI suspend/resume. */
__using_pio:1, /* Internal, use bcm43xx_using_pio(). */ __using_pio:1, /* Internal, use bcm43xx_using_pio(). */
bad_frames_preempt:1, /* Use "Bad Frames Preemption" (default off) */ bad_frames_preempt:1, /* Use "Bad Frames Preemption" (default off) */
reg124_set_0x4:1, /* Some variable to keep track of IRQ stuff. */ reg124_set_0x4:1, /* Some variable to keep track of IRQ stuff. */
powersaving:1, /* TRUE if we are in PowerSaving mode. FALSE otherwise. */
short_preamble:1, /* TRUE, if short preamble is enabled. */ short_preamble:1, /* TRUE, if short preamble is enabled. */
firmware_norelease:1; /* Do not release the firmware. Used on suspend. */ firmware_norelease:1; /* Do not release the firmware. Used on suspend. */
...@@ -721,7 +731,7 @@ struct bcm43xx_private { ...@@ -721,7 +731,7 @@ struct bcm43xx_private {
struct tasklet_struct isr_tasklet; struct tasklet_struct isr_tasklet;
/* Periodic tasks */ /* Periodic tasks */
struct timer_list periodic_tasks; struct work_struct periodic_work;
unsigned int periodic_state; unsigned int periodic_state;
struct work_struct restart_work; struct work_struct restart_work;
...@@ -746,21 +756,55 @@ struct bcm43xx_private { ...@@ -746,21 +756,55 @@ struct bcm43xx_private {
#endif #endif
}; };
/* bcm43xx_(un)lock() protect struct bcm43xx_private.
* Note that _NO_ MMIO writes are allowed. If you want to /* *** THEORY OF LOCKING ***
* write to the device through MMIO in the critical section, use *
* the *_mmio lock functions. * We have two different locks in the bcm43xx driver.
* MMIO read-access is allowed, though. * => bcm->mutex: General sleeping mutex. Protects struct bcm43xx_private
*/ * and the device registers.
#define bcm43xx_lock(bcm, flags) spin_lock_irqsave(&(bcm)->_lock, flags) * => bcm->irq_lock: IRQ spinlock. Protects against IRQ handler concurrency.
#define bcm43xx_unlock(bcm, flags) spin_unlock_irqrestore(&(bcm)->_lock, flags) *
/* bcm43xx_(un)lock_mmio() protect struct bcm43xx_private and MMIO. * We have three types of helper function pairs to utilize these locks.
* MMIO write-access to the device is allowed. * (Always use the helper functions.)
* All MMIO writes are flushed on unlock, so it is guaranteed to not * 1) bcm43xx_{un}lock_noirq():
* interfere with other threads writing MMIO registers. * 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.
*/ */
#define bcm43xx_lock_mmio(bcm, flags) bcm43xx_lock(bcm, flags)
#define bcm43xx_unlock_mmio(bcm, flags) do { mmiowb(); bcm43xx_unlock(bcm, flags); } while (0) /* 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)
...@@ -843,16 +887,6 @@ struct bcm43xx_radioinfo * bcm43xx_current_radio(struct bcm43xx_private *bcm) ...@@ -843,16 +887,6 @@ struct bcm43xx_radioinfo * bcm43xx_current_radio(struct bcm43xx_private *bcm)
return &(bcm->core_80211_ext[bcm->current_80211_core_idx].radio); return &(bcm->core_80211_ext[bcm->current_80211_core_idx].radio);
} }
/* Are we running in init_board() context? */
static inline
int bcm43xx_is_initializing(struct bcm43xx_private *bcm)
{
if (bcm->initialized)
return 0;
if (bcm->shutting_down)
return 0;
return 1;
}
static inline static inline
struct bcm43xx_lopair * bcm43xx_get_lopair(struct bcm43xx_phyinfo *phy, struct bcm43xx_lopair * bcm43xx_get_lopair(struct bcm43xx_phyinfo *phy,
......
...@@ -77,8 +77,8 @@ static ssize_t devinfo_read_file(struct file *file, char __user *userbuf, ...@@ -77,8 +77,8 @@ static ssize_t devinfo_read_file(struct file *file, char __user *userbuf,
down(&big_buffer_sem); down(&big_buffer_sem);
bcm43xx_lock_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
if (!bcm->initialized) { if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
fappend("Board not initialized.\n"); fappend("Board not initialized.\n");
goto out; goto out;
} }
...@@ -121,7 +121,7 @@ static ssize_t devinfo_read_file(struct file *file, char __user *userbuf, ...@@ -121,7 +121,7 @@ static ssize_t devinfo_read_file(struct file *file, char __user *userbuf,
fappend("\n"); fappend("\n");
out: out:
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
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,8 +159,8 @@ static ssize_t spromdump_read_file(struct file *file, char __user *userbuf, ...@@ -159,8 +159,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_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
if (!bcm->initialized) { if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
fappend("Board not initialized.\n"); fappend("Board not initialized.\n");
goto out; goto out;
} }
...@@ -169,7 +169,7 @@ static ssize_t spromdump_read_file(struct file *file, char __user *userbuf, ...@@ -169,7 +169,7 @@ 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_mmio(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
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,8 +188,8 @@ static ssize_t tsf_read_file(struct file *file, char __user *userbuf, ...@@ -188,8 +188,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_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
if (!bcm->initialized) { if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
fappend("Board not initialized.\n"); fappend("Board not initialized.\n");
goto out; goto out;
} }
...@@ -199,7 +199,7 @@ static ssize_t tsf_read_file(struct file *file, char __user *userbuf, ...@@ -199,7 +199,7 @@ static ssize_t tsf_read_file(struct file *file, char __user *userbuf,
(unsigned int)(tsf & 0xFFFFFFFFULL)); (unsigned int)(tsf & 0xFFFFFFFFULL));
out: out:
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
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,8 +221,8 @@ static ssize_t tsf_write_file(struct file *file, const char __user *user_buf, ...@@ -221,8 +221,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_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
if (!bcm->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;
goto out_unlock; goto out_unlock;
...@@ -233,10 +233,11 @@ static ssize_t tsf_write_file(struct file *file, const char __user *user_buf, ...@@ -233,10 +233,11 @@ static ssize_t tsf_write_file(struct file *file, const char __user *user_buf,
goto out_unlock; goto out_unlock;
} }
bcm43xx_tsf_write(bcm, tsf); bcm43xx_tsf_write(bcm, tsf);
mmiowb();
res = buf_size; res = buf_size;
out_unlock: out_unlock:
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
out_up: out_up:
up(&big_buffer_sem); up(&big_buffer_sem);
return res; return res;
...@@ -257,7 +258,7 @@ static ssize_t txstat_read_file(struct file *file, char __user *userbuf, ...@@ -257,7 +258,7 @@ 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(bcm, flags); bcm43xx_lock_irqsafe(bcm, 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);
...@@ -293,14 +294,14 @@ static ssize_t txstat_read_file(struct file *file, char __user *userbuf, ...@@ -293,14 +294,14 @@ 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(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
bcm43xx_lock(bcm, flags); bcm43xx_lock_irqsafe(bcm, 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(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
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_mmio(bcm, flags); bcm43xx_lock_irqonly(bcm, 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_mmio(bcm, flags); bcm43xx_unlock_irqonly(bcm, flags);
} }
static void bcm43xx_led_blink_start(struct bcm43xx_led *led, static void bcm43xx_led_blink_start(struct bcm43xx_led *led,
......
...@@ -504,14 +504,14 @@ static int bcm43xx_disable_interrupts_sync(struct bcm43xx_private *bcm, u32 *old ...@@ -504,14 +504,14 @@ static int bcm43xx_disable_interrupts_sync(struct bcm43xx_private *bcm, u32 *old
u32 old; u32 old;
unsigned long flags; unsigned long flags;
bcm43xx_lock_mmio(bcm, flags); bcm43xx_lock_irqonly(bcm, flags);
if (bcm43xx_is_initializing(bcm) || bcm->shutting_down) { if (unlikely(bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED)) {
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqonly(bcm, flags);
return -EBUSY; return -EBUSY;
} }
old = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL); old = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
tasklet_disable(&bcm->isr_tasklet); tasklet_disable(&bcm->isr_tasklet);
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqonly(bcm, flags);
if (oldstate) if (oldstate)
*oldstate = old; *oldstate = old;
...@@ -1389,7 +1389,7 @@ void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy) ...@@ -1389,7 +1389,7 @@ void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy)
bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA4_BASE); bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
#endif #endif
} }
if (bcm->shutting_down) { if (bcm43xx_status(bcm) == BCM43xx_STAT_SHUTTINGDOWN) {
bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD) bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
& ~(BCM43xx_SBF_MAC_ENABLED | 0x00000002)); & ~(BCM43xx_SBF_MAC_ENABLED | 0x00000002));
...@@ -1709,7 +1709,7 @@ static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm) ...@@ -1709,7 +1709,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_mmio(bcm, flags); bcm43xx_lock_irqonly(bcm, 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];
...@@ -1734,7 +1734,8 @@ static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm) ...@@ -1734,7 +1734,8 @@ static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm)
dma_reason[0], dma_reason[1], dma_reason[0], dma_reason[1],
dma_reason[2], dma_reason[3]); dma_reason[2], dma_reason[3]);
bcm43xx_controller_restart(bcm, "DMA error"); bcm43xx_controller_restart(bcm, "DMA error");
bcm43xx_unlock_mmio(bcm, flags); mmiowb();
bcm43xx_unlock_irqonly(bcm, flags);
return; return;
} }
if (unlikely((dma_reason[0] & BCM43xx_DMAIRQ_NONFATALMASK) | if (unlikely((dma_reason[0] & BCM43xx_DMAIRQ_NONFATALMASK) |
...@@ -1821,7 +1822,8 @@ static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm) ...@@ -1821,7 +1822,8 @@ static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm)
if (!modparam_noleds) if (!modparam_noleds)
bcm43xx_leds_update(bcm, activity); bcm43xx_leds_update(bcm, activity);
bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate); bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
bcm43xx_unlock_mmio(bcm, flags); mmiowb();
bcm43xx_unlock_irqonly(bcm, flags);
} }
static void pio_irq_workaround(struct bcm43xx_private *bcm, static void pio_irq_workaround(struct bcm43xx_private *bcm,
...@@ -1870,7 +1872,7 @@ static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_re ...@@ -1870,7 +1872,7 @@ static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_re
if (!bcm) if (!bcm)
return IRQ_NONE; return IRQ_NONE;
spin_lock(&bcm->_lock); spin_lock(&bcm->irq_lock);
reason = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); reason = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
if (reason == 0xffffffff) { if (reason == 0xffffffff) {
...@@ -1899,7 +1901,7 @@ static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_re ...@@ -1899,7 +1901,7 @@ static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_re
* completely, but some careful work is needed to fix this. I think it * completely, but some careful work is needed to fix this. I think it
* is best to stay with this cheap workaround for now... . * is best to stay with this cheap workaround for now... .
*/ */
if (likely(bcm->initialized)) { if (likely(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED)) {
/* disable all IRQs. They are enabled again in the bottom half. */ /* disable all IRQs. They are enabled again in the bottom half. */
bcm->irq_savedstate = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL); bcm->irq_savedstate = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
/* save the reason code and call our bottom half. */ /* save the reason code and call our bottom half. */
...@@ -1909,7 +1911,7 @@ static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_re ...@@ -1909,7 +1911,7 @@ static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_re
out: out:
mmiowb(); mmiowb();
spin_unlock(&bcm->_lock); spin_unlock(&bcm->irq_lock);
return ret; return ret;
} }
...@@ -3106,15 +3108,14 @@ static void bcm43xx_periodic_every15sec(struct bcm43xx_private *bcm) ...@@ -3106,15 +3108,14 @@ static void bcm43xx_periodic_every15sec(struct bcm43xx_private *bcm)
//TODO for APHY (temperature?) //TODO for APHY (temperature?)
} }
static void bcm43xx_periodic_task_handler(unsigned long d) static void bcm43xx_periodic_work_handler(void *d)
{ {
struct bcm43xx_private *bcm = (struct bcm43xx_private *)d; struct bcm43xx_private *bcm = d;
unsigned long flags; unsigned long flags;
unsigned int state; unsigned int state;
bcm43xx_lock_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
assert(bcm->initialized);
state = bcm->periodic_state; state = bcm->periodic_state;
if (state % 8 == 0) if (state % 8 == 0)
bcm43xx_periodic_every120sec(bcm); bcm43xx_periodic_every120sec(bcm);
...@@ -3125,26 +3126,24 @@ static void bcm43xx_periodic_task_handler(unsigned long d) ...@@ -3125,26 +3126,24 @@ static void bcm43xx_periodic_task_handler(unsigned long d)
bcm43xx_periodic_every15sec(bcm); bcm43xx_periodic_every15sec(bcm);
bcm->periodic_state = state + 1; bcm->periodic_state = state + 1;
mod_timer(&bcm->periodic_tasks, jiffies + (HZ * 15)); schedule_delayed_work(&bcm->periodic_work, HZ * 15);
bcm43xx_unlock_mmio(bcm, flags); mmiowb();
bcm43xx_unlock_irqsafe(bcm, flags);
} }
static void bcm43xx_periodic_tasks_delete(struct bcm43xx_private *bcm) static void bcm43xx_periodic_tasks_delete(struct bcm43xx_private *bcm)
{ {
del_timer_sync(&bcm->periodic_tasks); cancel_rearming_delayed_work(&bcm->periodic_work);
} }
static void bcm43xx_periodic_tasks_setup(struct bcm43xx_private *bcm) static void bcm43xx_periodic_tasks_setup(struct bcm43xx_private *bcm)
{ {
struct timer_list *timer = &(bcm->periodic_tasks); struct work_struct *work = &(bcm->periodic_work);
assert(bcm->initialized); assert(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED);
setup_timer(timer, INIT_WORK(work, bcm43xx_periodic_work_handler, bcm);
bcm43xx_periodic_task_handler, schedule_work(work);
(unsigned long)bcm);
timer->expires = jiffies;
add_timer(timer);
} }
static void bcm43xx_security_init(struct bcm43xx_private *bcm) static void bcm43xx_security_init(struct bcm43xx_private *bcm)
...@@ -3158,16 +3157,12 @@ static void bcm43xx_security_init(struct bcm43xx_private *bcm) ...@@ -3158,16 +3157,12 @@ static void bcm43xx_security_init(struct bcm43xx_private *bcm)
static void bcm43xx_free_board(struct bcm43xx_private *bcm) static void bcm43xx_free_board(struct bcm43xx_private *bcm)
{ {
int i, err; int i, err;
unsigned long flags;
bcm43xx_lock_noirq(bcm);
bcm43xx_sysfs_unregister(bcm); bcm43xx_sysfs_unregister(bcm);
bcm43xx_periodic_tasks_delete(bcm); bcm43xx_periodic_tasks_delete(bcm);
bcm43xx_lock(bcm, flags); bcm43xx_set_status(bcm, BCM43xx_STAT_SHUTTINGDOWN);
bcm->initialized = 0;
bcm->shutting_down = 1;
bcm43xx_unlock(bcm, flags);
for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) { for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
if (!bcm->core_80211[i].available) if (!bcm->core_80211[i].available)
...@@ -3182,23 +3177,19 @@ static void bcm43xx_free_board(struct bcm43xx_private *bcm) ...@@ -3182,23 +3177,19 @@ static void bcm43xx_free_board(struct bcm43xx_private *bcm)
bcm43xx_pctl_set_crystal(bcm, 0); bcm43xx_pctl_set_crystal(bcm, 0);
bcm43xx_lock(bcm, flags); bcm43xx_set_status(bcm, BCM43xx_STAT_UNINIT);
bcm->shutting_down = 0; bcm43xx_unlock_noirq(bcm);
bcm43xx_unlock(bcm, flags);
} }
static int bcm43xx_init_board(struct bcm43xx_private *bcm) static int bcm43xx_init_board(struct bcm43xx_private *bcm)
{ {
int i, err; int i, err;
int connect_phy; int connect_phy;
unsigned long flags;
might_sleep(); might_sleep();
bcm43xx_lock(bcm, flags); bcm43xx_lock_noirq(bcm);
bcm->initialized = 0; bcm43xx_set_status(bcm, BCM43xx_STAT_INITIALIZING);
bcm->shutting_down = 0;
bcm43xx_unlock(bcm, flags);
err = bcm43xx_pctl_set_crystal(bcm, 1); err = bcm43xx_pctl_set_crystal(bcm, 1);
if (err) if (err)
...@@ -3265,9 +3256,7 @@ static int bcm43xx_init_board(struct bcm43xx_private *bcm) ...@@ -3265,9 +3256,7 @@ static int bcm43xx_init_board(struct bcm43xx_private *bcm)
} }
/* Initialization of the board is done. Flag it as such. */ /* Initialization of the board is done. Flag it as such. */
bcm43xx_lock(bcm, flags); bcm43xx_set_status(bcm, BCM43xx_STAT_INITIALIZED);
bcm->initialized = 1;
bcm43xx_unlock(bcm, flags);
bcm43xx_periodic_tasks_setup(bcm); bcm43xx_periodic_tasks_setup(bcm);
bcm43xx_sysfs_register(bcm); bcm43xx_sysfs_register(bcm);
...@@ -3278,6 +3267,8 @@ static int bcm43xx_init_board(struct bcm43xx_private *bcm) ...@@ -3278,6 +3267,8 @@ static int bcm43xx_init_board(struct bcm43xx_private *bcm)
assert(err == 0); assert(err == 0);
out: out:
bcm43xx_unlock_noirq(bcm);
return err; return err;
err_80211_unwind: err_80211_unwind:
...@@ -3534,8 +3525,8 @@ static void bcm43xx_ieee80211_set_chan(struct net_device *net_dev, ...@@ -3534,8 +3525,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_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
if (bcm->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);
bcm43xx_mac_enable(bcm); bcm43xx_mac_enable(bcm);
...@@ -3543,7 +3534,7 @@ static void bcm43xx_ieee80211_set_chan(struct net_device *net_dev, ...@@ -3543,7 +3534,7 @@ 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_mmio(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
} }
/* set_security() callback in struct ieee80211_device */ /* set_security() callback in struct ieee80211_device */
...@@ -3557,7 +3548,7 @@ static void bcm43xx_ieee80211_set_security(struct net_device *net_dev, ...@@ -3557,7 +3548,7 @@ 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_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, 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)) {
...@@ -3587,7 +3578,8 @@ static void bcm43xx_ieee80211_set_security(struct net_device *net_dev, ...@@ -3587,7 +3578,8 @@ static void bcm43xx_ieee80211_set_security(struct net_device *net_dev,
dprintk(", .encrypt = %d", sec->encrypt); dprintk(", .encrypt = %d", sec->encrypt);
} }
dprintk("\n"); dprintk("\n");
if (bcm->initialized && !bcm->ieee->host_encrypt) { if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED &&
!bcm->ieee->host_encrypt) {
if (secinfo->enabled) { if (secinfo->enabled) {
/* upload WEP keys to hardware */ /* upload WEP keys to hardware */
char null_address[6] = { 0 }; char null_address[6] = { 0 };
...@@ -3621,7 +3613,7 @@ static void bcm43xx_ieee80211_set_security(struct net_device *net_dev, ...@@ -3621,7 +3613,7 @@ static void bcm43xx_ieee80211_set_security(struct net_device *net_dev,
} else } else
bcm43xx_clear_keys(bcm); bcm43xx_clear_keys(bcm);
} }
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
} }
/* hard_start_xmit() callback in struct ieee80211_device */ /* hard_start_xmit() callback in struct ieee80211_device */
...@@ -3633,10 +3625,10 @@ static int bcm43xx_ieee80211_hard_start_xmit(struct ieee80211_txb *txb, ...@@ -3633,10 +3625,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_mmio(bcm, flags); bcm43xx_lock_irqonly(bcm, flags);
if (likely(bcm->initialized)) if (likely(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED))
err = bcm43xx_tx(bcm, txb); err = bcm43xx_tx(bcm, txb);
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqonly(bcm, flags);
return err; return err;
} }
...@@ -3651,9 +3643,9 @@ static void bcm43xx_net_tx_timeout(struct net_device *net_dev) ...@@ -3651,9 +3643,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_mmio(bcm, flags); bcm43xx_lock_irqonly(bcm, flags);
bcm43xx_controller_restart(bcm, "TX timeout"); bcm43xx_controller_restart(bcm, "TX timeout");
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqonly(bcm, flags);
} }
#ifdef CONFIG_NET_POLL_CONTROLLER #ifdef CONFIG_NET_POLL_CONTROLLER
...@@ -3692,6 +3684,7 @@ static int bcm43xx_init_private(struct bcm43xx_private *bcm, ...@@ -3692,6 +3684,7 @@ static int bcm43xx_init_private(struct bcm43xx_private *bcm,
{ {
int err; int err;
bcm43xx_set_status(bcm, BCM43xx_STAT_UNINIT);
bcm->ieee = netdev_priv(net_dev); bcm->ieee = netdev_priv(net_dev);
bcm->softmac = ieee80211_priv(net_dev); bcm->softmac = ieee80211_priv(net_dev);
bcm->softmac->set_channel = bcm43xx_ieee80211_set_chan; bcm->softmac->set_channel = bcm43xx_ieee80211_set_chan;
...@@ -3700,7 +3693,8 @@ static int bcm43xx_init_private(struct bcm43xx_private *bcm, ...@@ -3700,7 +3693,8 @@ static int bcm43xx_init_private(struct bcm43xx_private *bcm,
bcm->pci_dev = pci_dev; bcm->pci_dev = pci_dev;
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->_lock); spin_lock_init(&bcm->irq_lock);
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,
(unsigned long)bcm); (unsigned long)bcm);
...@@ -3831,7 +3825,7 @@ static void bcm43xx_chip_reset(void *_bcm) ...@@ -3831,7 +3825,7 @@ static void bcm43xx_chip_reset(void *_bcm)
struct net_device *net_dev = bcm->net_dev; struct net_device *net_dev = bcm->net_dev;
struct pci_dev *pci_dev = bcm->pci_dev; struct pci_dev *pci_dev = bcm->pci_dev;
int err; int err;
int was_initialized = bcm->initialized; int was_initialized = (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED);
netif_stop_queue(bcm->net_dev); netif_stop_queue(bcm->net_dev);
tasklet_disable(&bcm->isr_tasklet); tasklet_disable(&bcm->isr_tasklet);
...@@ -3866,6 +3860,7 @@ static void bcm43xx_chip_reset(void *_bcm) ...@@ -3866,6 +3860,7 @@ static void bcm43xx_chip_reset(void *_bcm)
*/ */
void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason) void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason)
{ {
bcm43xx_set_status(bcm, BCM43xx_STAT_RESTARTING);
bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL); bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */ bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
printk(KERN_ERR PFX "Controller RESET (%s) ...\n", reason); printk(KERN_ERR PFX "Controller RESET (%s) ...\n", reason);
...@@ -3884,11 +3879,11 @@ static int bcm43xx_suspend(struct pci_dev *pdev, pm_message_t state) ...@@ -3884,11 +3879,11 @@ static int bcm43xx_suspend(struct pci_dev *pdev, pm_message_t state)
dprintk(KERN_INFO PFX "Suspending...\n"); dprintk(KERN_INFO PFX "Suspending...\n");
bcm43xx_lock(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
bcm->was_initialized = bcm->initialized; bcm->was_initialized = (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED);
if (bcm->initialized) if (bcm->was_initialized)
try_to_shutdown = 1; try_to_shutdown = 1;
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
netif_device_detach(net_dev); netif_device_detach(net_dev);
if (try_to_shutdown) { if (try_to_shutdown) {
......
...@@ -1648,7 +1648,7 @@ void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm, ...@@ -1648,7 +1648,7 @@ void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
void bcm43xx_phy_lo_g_measure(struct bcm43xx_private *bcm) void bcm43xx_phy_lo_g_measure(struct bcm43xx_private *bcm)
{ {
static const u8 pairorder[10] = { 3, 1, 5, 7, 9, 2, 0, 4, 6, 8 }; static const u8 pairorder[10] = { 3, 1, 5, 7, 9, 2, 0, 4, 6, 8 };
const int is_initializing = bcm43xx_is_initializing(bcm); const int is_initializing = (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZING);
struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm); struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm); struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
u16 h, i, oldi = 0, j; u16 h, i, oldi = 0, j;
......
...@@ -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_mmio(bcm, flags); bcm43xx_lock_irqonly(bcm, flags);
txctl = bcm43xx_pio_read(queue, BCM43xx_PIO_TXCTL); txctl = bcm43xx_pio_read(queue, BCM43xx_PIO_TXCTL);
if (txctl & BCM43xx_PIO_TXCTL_SUSPEND) if (txctl & BCM43xx_PIO_TXCTL_SUSPEND)
...@@ -298,7 +298,7 @@ static void tx_tasklet(unsigned long d) ...@@ -298,7 +298,7 @@ static void tx_tasklet(unsigned long d)
continue; continue;
} }
out_unlock: out_unlock:
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqonly(bcm, flags);
} }
static void setup_txqueues(struct bcm43xx_pioqueue *queue) static void setup_txqueues(struct bcm43xx_pioqueue *queue)
...@@ -374,7 +374,6 @@ static void cancel_transfers(struct bcm43xx_pioqueue *queue) ...@@ -374,7 +374,6 @@ static void cancel_transfers(struct bcm43xx_pioqueue *queue)
struct bcm43xx_pio_txpacket *packet, *tmp_packet; struct bcm43xx_pio_txpacket *packet, *tmp_packet;
netif_tx_disable(queue->bcm->net_dev); netif_tx_disable(queue->bcm->net_dev);
assert(queue->bcm->shutting_down);
tasklet_disable(&queue->txtask); tasklet_disable(&queue->txtask);
list_for_each_entry_safe(packet, tmp_packet, &queue->txrunning, list) list_for_each_entry_safe(packet, tmp_packet, &queue->txrunning, list)
......
...@@ -120,12 +120,12 @@ static ssize_t bcm43xx_attr_sprom_show(struct device *dev, ...@@ -120,12 +120,12 @@ static ssize_t bcm43xx_attr_sprom_show(struct device *dev,
GFP_KERNEL); GFP_KERNEL);
if (!sprom) if (!sprom)
return -ENOMEM; return -ENOMEM;
bcm43xx_lock_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
assert(bcm->initialized);
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);
bcm43xx_unlock_mmio(bcm, flags); mmiowb();
bcm43xx_unlock_irqsafe(bcm, flags);
kfree(sprom); kfree(sprom);
return err; return err;
...@@ -150,10 +150,10 @@ static ssize_t bcm43xx_attr_sprom_store(struct device *dev, ...@@ -150,10 +150,10 @@ 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_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
assert(bcm->initialized);
err = bcm43xx_sprom_write(bcm, sprom); err = bcm43xx_sprom_write(bcm, sprom);
bcm43xx_unlock_mmio(bcm, flags); mmiowb();
bcm43xx_unlock_irqsafe(bcm, flags);
out_kfree: out_kfree:
kfree(sprom); kfree(sprom);
...@@ -170,15 +170,13 @@ static ssize_t bcm43xx_attr_interfmode_show(struct device *dev, ...@@ -170,15 +170,13 @@ static ssize_t bcm43xx_attr_interfmode_show(struct device *dev,
char *buf) char *buf)
{ {
struct bcm43xx_private *bcm = dev_to_bcm(dev); struct bcm43xx_private *bcm = dev_to_bcm(dev);
unsigned long flags;
int err; int err;
ssize_t count = 0; ssize_t count = 0;
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
bcm43xx_lock(bcm, flags); bcm43xx_lock_noirq(bcm);
assert(bcm->initialized);
switch (bcm43xx_current_radio(bcm)->interfmode) { switch (bcm43xx_current_radio(bcm)->interfmode) {
case BCM43xx_RADIO_INTERFMODE_NONE: case BCM43xx_RADIO_INTERFMODE_NONE:
...@@ -195,7 +193,7 @@ static ssize_t bcm43xx_attr_interfmode_show(struct device *dev, ...@@ -195,7 +193,7 @@ static ssize_t bcm43xx_attr_interfmode_show(struct device *dev,
} }
err = 0; err = 0;
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_noirq(bcm);
return err ? err : count; return err ? err : count;
...@@ -231,16 +229,15 @@ static ssize_t bcm43xx_attr_interfmode_store(struct device *dev, ...@@ -231,16 +229,15 @@ static ssize_t bcm43xx_attr_interfmode_store(struct device *dev,
return -EINVAL; return -EINVAL;
} }
bcm43xx_lock_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
assert(bcm->initialized);
err = bcm43xx_radio_set_interference_mitigation(bcm, mode); err = bcm43xx_radio_set_interference_mitigation(bcm, mode);
if (err) { if (err) {
printk(KERN_ERR PFX "Interference Mitigation not " printk(KERN_ERR PFX "Interference Mitigation not "
"supported by device\n"); "supported by device\n");
} }
mmiowb();
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return err ? err : count; return err ? err : count;
} }
...@@ -254,15 +251,13 @@ static ssize_t bcm43xx_attr_preamble_show(struct device *dev, ...@@ -254,15 +251,13 @@ static ssize_t bcm43xx_attr_preamble_show(struct device *dev,
char *buf) char *buf)
{ {
struct bcm43xx_private *bcm = dev_to_bcm(dev); struct bcm43xx_private *bcm = dev_to_bcm(dev);
unsigned long flags;
int err; int err;
ssize_t count; ssize_t count;
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
bcm43xx_lock(bcm, flags); bcm43xx_lock_noirq(bcm);
assert(bcm->initialized);
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");
...@@ -270,7 +265,7 @@ static ssize_t bcm43xx_attr_preamble_show(struct device *dev, ...@@ -270,7 +265,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(bcm, flags); bcm43xx_unlock_noirq(bcm);
return err ? err : count; return err ? err : count;
} }
...@@ -290,13 +285,12 @@ static ssize_t bcm43xx_attr_preamble_store(struct device *dev, ...@@ -290,13 +285,12 @@ 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(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
assert(bcm->initialized);
bcm->short_preamble = !!value; bcm->short_preamble = !!value;
err = 0; err = 0;
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return err ? err : count; return err ? err : count;
} }
...@@ -310,7 +304,7 @@ int bcm43xx_sysfs_register(struct bcm43xx_private *bcm) ...@@ -310,7 +304,7 @@ int bcm43xx_sysfs_register(struct bcm43xx_private *bcm)
struct device *dev = &bcm->pci_dev->dev; struct device *dev = &bcm->pci_dev->dev;
int err; int err;
assert(bcm->initialized); assert(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED);
err = device_create_file(dev, &dev_attr_sprom); err = device_create_file(dev, &dev_attr_sprom);
if (err) if (err)
......
...@@ -55,13 +55,13 @@ static int bcm43xx_wx_get_name(struct net_device *net_dev, ...@@ -55,13 +55,13 @@ static int bcm43xx_wx_get_name(struct net_device *net_dev,
char *extra) char *extra)
{ {
struct bcm43xx_private *bcm = bcm43xx_priv(net_dev); struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
unsigned long flags;
int i; int i;
unsigned long flags;
struct bcm43xx_phyinfo *phy; struct bcm43xx_phyinfo *phy;
char suffix[7] = { 0 }; char suffix[7] = { 0 };
int have_a = 0, have_b = 0, have_g = 0; int have_a = 0, have_b = 0, have_g = 0;
bcm43xx_lock(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
for (i = 0; i < bcm->nr_80211_available; i++) { for (i = 0; i < bcm->nr_80211_available; i++) {
phy = &(bcm->core_80211_ext[i].phy); phy = &(bcm->core_80211_ext[i].phy);
switch (phy->type) { switch (phy->type) {
...@@ -77,7 +77,7 @@ static int bcm43xx_wx_get_name(struct net_device *net_dev, ...@@ -77,7 +77,7 @@ static int bcm43xx_wx_get_name(struct net_device *net_dev,
assert(0); assert(0);
} }
} }
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
i = 0; i = 0;
if (have_a) { if (have_a) {
...@@ -111,7 +111,7 @@ static int bcm43xx_wx_set_channelfreq(struct net_device *net_dev, ...@@ -111,7 +111,7 @@ static int bcm43xx_wx_set_channelfreq(struct net_device *net_dev,
int freq; int freq;
int err = -EINVAL; int err = -EINVAL;
bcm43xx_lock_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
if ((data->freq.m >= 0) && (data->freq.m <= 1000)) { if ((data->freq.m >= 0) && (data->freq.m <= 1000)) {
channel = data->freq.m; channel = data->freq.m;
freq = bcm43xx_channel_to_freq(bcm, channel); freq = bcm43xx_channel_to_freq(bcm, channel);
...@@ -121,7 +121,7 @@ static int bcm43xx_wx_set_channelfreq(struct net_device *net_dev, ...@@ -121,7 +121,7 @@ static int bcm43xx_wx_set_channelfreq(struct net_device *net_dev,
} }
if (!bcm43xx_is_valid_channel(bcm, channel)) if (!bcm43xx_is_valid_channel(bcm, channel))
goto out_unlock; goto out_unlock;
if (bcm->initialized) { if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) {
//ieee80211softmac_disassoc(softmac, $REASON); //ieee80211softmac_disassoc(softmac, $REASON);
bcm43xx_mac_suspend(bcm); bcm43xx_mac_suspend(bcm);
err = bcm43xx_radio_selectchannel(bcm, channel, 0); err = bcm43xx_radio_selectchannel(bcm, channel, 0);
...@@ -131,7 +131,7 @@ static int bcm43xx_wx_set_channelfreq(struct net_device *net_dev, ...@@ -131,7 +131,7 @@ static int bcm43xx_wx_set_channelfreq(struct net_device *net_dev,
err = 0; err = 0;
} }
out_unlock: out_unlock:
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return err; return err;
} }
...@@ -147,11 +147,10 @@ static int bcm43xx_wx_get_channelfreq(struct net_device *net_dev, ...@@ -147,11 +147,10 @@ static int bcm43xx_wx_get_channelfreq(struct net_device *net_dev,
int err = -ENODEV; int err = -ENODEV;
u16 channel; u16 channel;
bcm43xx_lock(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
radio = bcm43xx_current_radio(bcm); radio = bcm43xx_current_radio(bcm);
channel = radio->channel; channel = radio->channel;
if (channel == 0xFF) { if (channel == 0xFF) {
assert(!bcm->initialized);
channel = radio->initial_channel; channel = radio->initial_channel;
if (channel == 0xFF) if (channel == 0xFF)
goto out_unlock; goto out_unlock;
...@@ -163,7 +162,7 @@ static int bcm43xx_wx_get_channelfreq(struct net_device *net_dev, ...@@ -163,7 +162,7 @@ static int bcm43xx_wx_get_channelfreq(struct net_device *net_dev,
err = 0; err = 0;
out_unlock: out_unlock:
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return err; return err;
} }
...@@ -181,13 +180,13 @@ static int bcm43xx_wx_set_mode(struct net_device *net_dev, ...@@ -181,13 +180,13 @@ static int bcm43xx_wx_set_mode(struct net_device *net_dev,
if (mode == IW_MODE_AUTO) if (mode == IW_MODE_AUTO)
mode = BCM43xx_INITIAL_IWMODE; mode = BCM43xx_INITIAL_IWMODE;
bcm43xx_lock_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
if (bcm->initialized) { if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) {
if (bcm->ieee->iw_mode != mode) if (bcm->ieee->iw_mode != mode)
bcm43xx_set_iwmode(bcm, mode); bcm43xx_set_iwmode(bcm, mode);
} else } else
bcm->ieee->iw_mode = mode; bcm->ieee->iw_mode = mode;
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return 0; return 0;
} }
...@@ -200,9 +199,9 @@ static int bcm43xx_wx_get_mode(struct net_device *net_dev, ...@@ -200,9 +199,9 @@ static int bcm43xx_wx_get_mode(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(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
data->mode = bcm->ieee->iw_mode; data->mode = bcm->ieee->iw_mode;
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return 0; return 0;
} }
...@@ -255,7 +254,7 @@ static int bcm43xx_wx_get_rangeparams(struct net_device *net_dev, ...@@ -255,7 +254,7 @@ static int bcm43xx_wx_get_rangeparams(struct net_device *net_dev,
IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_TKIP |
IW_ENC_CAPA_CIPHER_CCMP; IW_ENC_CAPA_CIPHER_CCMP;
bcm43xx_lock(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
phy = bcm43xx_current_phy(bcm); phy = bcm43xx_current_phy(bcm);
range->num_bitrates = 0; range->num_bitrates = 0;
...@@ -302,7 +301,7 @@ static int bcm43xx_wx_get_rangeparams(struct net_device *net_dev, ...@@ -302,7 +301,7 @@ static int bcm43xx_wx_get_rangeparams(struct net_device *net_dev,
} }
range->num_frequency = j; range->num_frequency = j;
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return 0; return 0;
} }
...@@ -313,14 +312,13 @@ static int bcm43xx_wx_set_nick(struct net_device *net_dev, ...@@ -313,14 +312,13 @@ static int bcm43xx_wx_set_nick(struct net_device *net_dev,
char *extra) char *extra)
{ {
struct bcm43xx_private *bcm = bcm43xx_priv(net_dev); struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
unsigned long flags;
size_t len; size_t len;
bcm43xx_lock(bcm, flags); bcm43xx_lock_noirq(bcm);
len = min((size_t)data->data.length, (size_t)IW_ESSID_MAX_SIZE); len = min((size_t)data->data.length, (size_t)IW_ESSID_MAX_SIZE);
memcpy(bcm->nick, extra, len); memcpy(bcm->nick, extra, len);
bcm->nick[len] = '\0'; bcm->nick[len] = '\0';
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_noirq(bcm);
return 0; return 0;
} }
...@@ -331,15 +329,14 @@ static int bcm43xx_wx_get_nick(struct net_device *net_dev, ...@@ -331,15 +329,14 @@ static int bcm43xx_wx_get_nick(struct net_device *net_dev,
char *extra) char *extra)
{ {
struct bcm43xx_private *bcm = bcm43xx_priv(net_dev); struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
unsigned long flags;
size_t len; size_t len;
bcm43xx_lock(bcm, flags); bcm43xx_lock_noirq(bcm);
len = strlen(bcm->nick) + 1; len = strlen(bcm->nick) + 1;
memcpy(extra, bcm->nick, len); memcpy(extra, bcm->nick, len);
data->data.length = (__u16)len; data->data.length = (__u16)len;
data->data.flags = 1; data->data.flags = 1;
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_noirq(bcm);
return 0; return 0;
} }
...@@ -353,7 +350,7 @@ static int bcm43xx_wx_set_rts(struct net_device *net_dev, ...@@ -353,7 +350,7 @@ static int bcm43xx_wx_set_rts(struct net_device *net_dev,
unsigned long flags; unsigned long flags;
int err = -EINVAL; int err = -EINVAL;
bcm43xx_lock(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
if (data->rts.disabled) { if (data->rts.disabled) {
bcm->rts_threshold = BCM43xx_MAX_RTS_THRESHOLD; bcm->rts_threshold = BCM43xx_MAX_RTS_THRESHOLD;
err = 0; err = 0;
...@@ -364,7 +361,7 @@ static int bcm43xx_wx_set_rts(struct net_device *net_dev, ...@@ -364,7 +361,7 @@ static int bcm43xx_wx_set_rts(struct net_device *net_dev,
err = 0; err = 0;
} }
} }
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return err; return err;
} }
...@@ -377,11 +374,11 @@ static int bcm43xx_wx_get_rts(struct net_device *net_dev, ...@@ -377,11 +374,11 @@ static int bcm43xx_wx_get_rts(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(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
data->rts.value = bcm->rts_threshold; data->rts.value = bcm->rts_threshold;
data->rts.fixed = 0; data->rts.fixed = 0;
data->rts.disabled = (bcm->rts_threshold == BCM43xx_MAX_RTS_THRESHOLD); data->rts.disabled = (bcm->rts_threshold == BCM43xx_MAX_RTS_THRESHOLD);
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return 0; return 0;
} }
...@@ -395,7 +392,7 @@ static int bcm43xx_wx_set_frag(struct net_device *net_dev, ...@@ -395,7 +392,7 @@ static int bcm43xx_wx_set_frag(struct net_device *net_dev,
unsigned long flags; unsigned long flags;
int err = -EINVAL; int err = -EINVAL;
bcm43xx_lock(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
if (data->frag.disabled) { if (data->frag.disabled) {
bcm->ieee->fts = MAX_FRAG_THRESHOLD; bcm->ieee->fts = MAX_FRAG_THRESHOLD;
err = 0; err = 0;
...@@ -406,7 +403,7 @@ static int bcm43xx_wx_set_frag(struct net_device *net_dev, ...@@ -406,7 +403,7 @@ static int bcm43xx_wx_set_frag(struct net_device *net_dev,
err = 0; err = 0;
} }
} }
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return err; return err;
} }
...@@ -419,11 +416,11 @@ static int bcm43xx_wx_get_frag(struct net_device *net_dev, ...@@ -419,11 +416,11 @@ static int bcm43xx_wx_get_frag(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(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
data->frag.value = bcm->ieee->fts; data->frag.value = bcm->ieee->fts;
data->frag.fixed = 0; data->frag.fixed = 0;
data->frag.disabled = (bcm->ieee->fts == MAX_FRAG_THRESHOLD); data->frag.disabled = (bcm->ieee->fts == MAX_FRAG_THRESHOLD);
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return 0; return 0;
} }
...@@ -445,8 +442,8 @@ static int bcm43xx_wx_set_xmitpower(struct net_device *net_dev, ...@@ -445,8 +442,8 @@ static int bcm43xx_wx_set_xmitpower(struct net_device *net_dev,
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
bcm43xx_lock_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
if (!bcm->initialized) if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED)
goto out_unlock; goto out_unlock;
radio = bcm43xx_current_radio(bcm); radio = bcm43xx_current_radio(bcm);
phy = bcm43xx_current_phy(bcm); phy = bcm43xx_current_phy(bcm);
...@@ -469,7 +466,7 @@ static int bcm43xx_wx_set_xmitpower(struct net_device *net_dev, ...@@ -469,7 +466,7 @@ static int bcm43xx_wx_set_xmitpower(struct net_device *net_dev,
err = 0; err = 0;
out_unlock: out_unlock:
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return err; return err;
} }
...@@ -484,8 +481,8 @@ static int bcm43xx_wx_get_xmitpower(struct net_device *net_dev, ...@@ -484,8 +481,8 @@ static int bcm43xx_wx_get_xmitpower(struct net_device *net_dev,
unsigned long flags; unsigned long flags;
int err = -ENODEV; int err = -ENODEV;
bcm43xx_lock(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
if (!bcm->initialized) if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED)
goto out_unlock; goto out_unlock;
radio = bcm43xx_current_radio(bcm); radio = bcm43xx_current_radio(bcm);
/* desired dBm value is in Q5.2 */ /* desired dBm value is in Q5.2 */
...@@ -496,7 +493,7 @@ static int bcm43xx_wx_get_xmitpower(struct net_device *net_dev, ...@@ -496,7 +493,7 @@ static int bcm43xx_wx_get_xmitpower(struct net_device *net_dev,
err = 0; err = 0;
out_unlock: out_unlock:
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return err; return err;
} }
...@@ -583,8 +580,8 @@ static int bcm43xx_wx_set_interfmode(struct net_device *net_dev, ...@@ -583,8 +580,8 @@ static int bcm43xx_wx_set_interfmode(struct net_device *net_dev,
return -EINVAL; return -EINVAL;
} }
bcm43xx_lock_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
if (bcm->initialized) { if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) {
err = bcm43xx_radio_set_interference_mitigation(bcm, mode); err = bcm43xx_radio_set_interference_mitigation(bcm, mode);
if (err) { if (err) {
printk(KERN_ERR PFX "Interference Mitigation not " printk(KERN_ERR PFX "Interference Mitigation not "
...@@ -598,7 +595,7 @@ static int bcm43xx_wx_set_interfmode(struct net_device *net_dev, ...@@ -598,7 +595,7 @@ static int bcm43xx_wx_set_interfmode(struct net_device *net_dev,
} else } else
bcm43xx_current_radio(bcm)->interfmode = mode; bcm43xx_current_radio(bcm)->interfmode = mode;
} }
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return err; return err;
} }
...@@ -612,9 +609,9 @@ static int bcm43xx_wx_get_interfmode(struct net_device *net_dev, ...@@ -612,9 +609,9 @@ static int bcm43xx_wx_get_interfmode(struct net_device *net_dev,
unsigned long flags; unsigned long flags;
int mode; int mode;
bcm43xx_lock(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
mode = bcm43xx_current_radio(bcm)->interfmode; mode = bcm43xx_current_radio(bcm)->interfmode;
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
switch (mode) { switch (mode) {
case BCM43xx_RADIO_INTERFMODE_NONE: case BCM43xx_RADIO_INTERFMODE_NONE:
...@@ -644,9 +641,9 @@ static int bcm43xx_wx_set_shortpreamble(struct net_device *net_dev, ...@@ -644,9 +641,9 @@ static int bcm43xx_wx_set_shortpreamble(struct net_device *net_dev,
int on; int on;
on = *((int *)extra); on = *((int *)extra);
bcm43xx_lock(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
bcm->short_preamble = !!on; bcm->short_preamble = !!on;
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return 0; return 0;
} }
...@@ -660,9 +657,9 @@ static int bcm43xx_wx_get_shortpreamble(struct net_device *net_dev, ...@@ -660,9 +657,9 @@ static int bcm43xx_wx_get_shortpreamble(struct net_device *net_dev,
unsigned long flags; unsigned long flags;
int on; int on;
bcm43xx_lock(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
on = bcm->short_preamble; on = bcm->short_preamble;
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
if (on) if (on)
strncpy(extra, "1 (Short Preamble enabled)", MAX_WX_STRING); strncpy(extra, "1 (Short Preamble enabled)", MAX_WX_STRING);
...@@ -684,11 +681,11 @@ static int bcm43xx_wx_set_swencryption(struct net_device *net_dev, ...@@ -684,11 +681,11 @@ static int bcm43xx_wx_set_swencryption(struct net_device *net_dev,
on = *((int *)extra); on = *((int *)extra);
bcm43xx_lock(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
bcm->ieee->host_encrypt = !!on; bcm->ieee->host_encrypt = !!on;
bcm->ieee->host_decrypt = !!on; bcm->ieee->host_decrypt = !!on;
bcm->ieee->host_build_iv = !on; bcm->ieee->host_build_iv = !on;
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
return 0; return 0;
} }
...@@ -702,9 +699,9 @@ static int bcm43xx_wx_get_swencryption(struct net_device *net_dev, ...@@ -702,9 +699,9 @@ static int bcm43xx_wx_get_swencryption(struct net_device *net_dev,
unsigned long flags; unsigned long flags;
int on; int on;
bcm43xx_lock(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
on = bcm->ieee->host_encrypt; on = bcm->ieee->host_encrypt;
bcm43xx_unlock(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
if (on) if (on)
strncpy(extra, "1 (SW encryption enabled) ", MAX_WX_STRING); strncpy(extra, "1 (SW encryption enabled) ", MAX_WX_STRING);
...@@ -767,11 +764,11 @@ static int bcm43xx_wx_sprom_read(struct net_device *net_dev, ...@@ -767,11 +764,11 @@ static int bcm43xx_wx_sprom_read(struct net_device *net_dev,
if (!sprom) if (!sprom)
goto out; goto out;
bcm43xx_lock_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
err = -ENODEV; err = -ENODEV;
if (bcm->initialized) if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED)
err = bcm43xx_sprom_read(bcm, sprom); err = bcm43xx_sprom_read(bcm, sprom);
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
if (!err) if (!err)
data->data.length = sprom2hex(sprom, extra); data->data.length = sprom2hex(sprom, extra);
kfree(sprom); kfree(sprom);
...@@ -812,11 +809,11 @@ static int bcm43xx_wx_sprom_write(struct net_device *net_dev, ...@@ -812,11 +809,11 @@ static int bcm43xx_wx_sprom_write(struct net_device *net_dev,
if (err) if (err)
goto out_kfree; goto out_kfree;
bcm43xx_lock_mmio(bcm, flags); bcm43xx_lock_irqsafe(bcm, flags);
err = -ENODEV; err = -ENODEV;
if (bcm->initialized) if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED)
err = bcm43xx_sprom_write(bcm, sprom); err = bcm43xx_sprom_write(bcm, sprom);
bcm43xx_unlock_mmio(bcm, flags); bcm43xx_unlock_irqsafe(bcm, flags);
out_kfree: out_kfree:
kfree(sprom); kfree(sprom);
out: out:
......
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