Skip to content

Commit

Permalink
Merge branch 'upstream' of git://git.kernel.org/pub/scm/linux/kernel/…
Browse files Browse the repository at this point in the history
…git/linville/wireless-2.6 into upstream
  • Loading branch information
Jeff Garzik committed Jun 20, 2006
2 parents 4c1234f + 89c318e commit 4b2d9cf
Show file tree
Hide file tree
Showing 13 changed files with 402 additions and 216 deletions.
100 changes: 67 additions & 33 deletions drivers/net/wireless/bcm43xx/bcm43xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,17 @@ struct bcm43xx_key {
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 ieee80211_device *ieee;
struct ieee80211softmac_device *softmac;
Expand All @@ -646,18 +657,17 @@ struct bcm43xx_private {

void __iomem *mmio_addr;

/* Do not use the lock directly. Use the bcm43xx_lock* helper
* functions, to be MMIO-safe. */
spinlock_t _lock;
/* Locking, see "theory of locking" text below. */
spinlock_t irq_lock;
struct mutex mutex;

/* Driver status flags. */
u32 initialized:1, /* init_board() succeed */
was_initialized:1, /* for PCI suspend/resume. */
shutting_down:1, /* free_board() in progress */
/* Driver initialization status BCM43xx_STAT_*** */
atomic_t init_status;

u16 was_initialized:1, /* for PCI suspend/resume. */
__using_pio:1, /* Internal, use bcm43xx_using_pio(). */
bad_frames_preempt:1, /* Use "Bad Frames Preemption" (default off) */
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. */
firmware_norelease:1; /* Do not release the firmware. Used on suspend. */

Expand Down Expand Up @@ -721,7 +731,7 @@ struct bcm43xx_private {
struct tasklet_struct isr_tasklet;

/* Periodic tasks */
struct timer_list periodic_tasks;
struct work_struct periodic_work;
unsigned int periodic_state;

struct work_struct restart_work;
Expand All @@ -746,21 +756,55 @@ struct bcm43xx_private {
#endif
};

/* bcm43xx_(un)lock() protect struct bcm43xx_private.
* Note that _NO_ MMIO writes are allowed. If you want to
* write to the device through MMIO in the critical section, use
* the *_mmio lock functions.
* MMIO read-access is allowed, though.
*/
#define bcm43xx_lock(bcm, flags) spin_lock_irqsave(&(bcm)->_lock, flags)
#define bcm43xx_unlock(bcm, flags) spin_unlock_irqrestore(&(bcm)->_lock, flags)
/* bcm43xx_(un)lock_mmio() protect struct bcm43xx_private and MMIO.
* MMIO write-access to the device is allowed.
* All MMIO writes are flushed on unlock, so it is guaranteed to not
* interfere with other threads writing MMIO registers.

/* *** 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.
*/
#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
struct bcm43xx_private * bcm43xx_priv(struct net_device *dev)
Expand Down Expand Up @@ -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);
}

/* 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
struct bcm43xx_lopair * bcm43xx_get_lopair(struct bcm43xx_phyinfo *phy,
Expand Down
33 changes: 17 additions & 16 deletions drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ static ssize_t devinfo_read_file(struct file *file, char __user *userbuf,

down(&big_buffer_sem);

bcm43xx_lock_mmio(bcm, flags);
if (!bcm->initialized) {
bcm43xx_lock_irqsafe(bcm, flags);
if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
fappend("Board not initialized.\n");
goto out;
}
Expand Down Expand Up @@ -121,7 +121,7 @@ static ssize_t devinfo_read_file(struct file *file, char __user *userbuf,
fappend("\n");

out:
bcm43xx_unlock_mmio(bcm, flags);
bcm43xx_unlock_irqsafe(bcm, flags);
res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
up(&big_buffer_sem);
return res;
Expand Down Expand Up @@ -159,8 +159,8 @@ static ssize_t spromdump_read_file(struct file *file, char __user *userbuf,
unsigned long flags;

down(&big_buffer_sem);
bcm43xx_lock_mmio(bcm, flags);
if (!bcm->initialized) {
bcm43xx_lock_irqsafe(bcm, flags);
if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
fappend("Board not initialized.\n");
goto out;
}
Expand All @@ -169,7 +169,7 @@ static ssize_t spromdump_read_file(struct file *file, char __user *userbuf,
fappend("boardflags: 0x%04x\n", bcm->sprom.boardflags);

out:
bcm43xx_unlock_mmio(bcm, flags);
bcm43xx_unlock_irqsafe(bcm, flags);
res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
up(&big_buffer_sem);
return res;
Expand All @@ -188,8 +188,8 @@ static ssize_t tsf_read_file(struct file *file, char __user *userbuf,
u64 tsf;

down(&big_buffer_sem);
bcm43xx_lock_mmio(bcm, flags);
if (!bcm->initialized) {
bcm43xx_lock_irqsafe(bcm, flags);
if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
fappend("Board not initialized.\n");
goto out;
}
Expand All @@ -199,7 +199,7 @@ static ssize_t tsf_read_file(struct file *file, char __user *userbuf,
(unsigned int)(tsf & 0xFFFFFFFFULL));

out:
bcm43xx_unlock_mmio(bcm, flags);
bcm43xx_unlock_irqsafe(bcm, flags);
res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
up(&big_buffer_sem);
return res;
Expand All @@ -221,8 +221,8 @@ static ssize_t tsf_write_file(struct file *file, const char __user *user_buf,
res = -EFAULT;
goto out_up;
}
bcm43xx_lock_mmio(bcm, flags);
if (!bcm->initialized) {
bcm43xx_lock_irqsafe(bcm, flags);
if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
printk(KERN_INFO PFX "debugfs: Board not initialized.\n");
res = -EFAULT;
goto out_unlock;
Expand All @@ -233,10 +233,11 @@ static ssize_t tsf_write_file(struct file *file, const char __user *user_buf,
goto out_unlock;
}
bcm43xx_tsf_write(bcm, tsf);
mmiowb();
res = buf_size;

out_unlock:
bcm43xx_unlock_mmio(bcm, flags);
bcm43xx_unlock_irqsafe(bcm, flags);
out_up:
up(&big_buffer_sem);
return res;
Expand All @@ -257,7 +258,7 @@ static ssize_t txstat_read_file(struct file *file, char __user *userbuf,
int i, cnt, j = 0;

down(&big_buffer_sem);
bcm43xx_lock(bcm, flags);
bcm43xx_lock_irqsafe(bcm, flags);

fappend("Last %d logged xmitstatus blobs (Latest first):\n\n",
BCM43xx_NR_LOGGED_XMITSTATUS);
Expand Down Expand Up @@ -293,14 +294,14 @@ static ssize_t txstat_read_file(struct file *file, char __user *userbuf,
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);
bcm43xx_lock(bcm, flags);
bcm43xx_lock_irqsafe(bcm, flags);
if (*ppos == pos) {
/* Done. Drop the copied data. */
e->xmitstatus_printing = 0;
}
bcm43xx_unlock(bcm, flags);
bcm43xx_unlock_irqsafe(bcm, flags);
up(&big_buffer_sem);
return res;
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/wireless/bcm43xx/bcm43xx_leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ static void bcm43xx_led_blink(unsigned long d)
struct bcm43xx_private *bcm = led->bcm;
unsigned long flags;

bcm43xx_lock_mmio(bcm, flags);
bcm43xx_lock_irqonly(bcm, flags);
if (led->blink_interval) {
bcm43xx_led_changestate(led);
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,
Expand Down
Loading

0 comments on commit 4b2d9cf

Please sign in to comment.