Skip to content

Commit

Permalink
b43legacy: Remove the PHY spinlock
Browse files Browse the repository at this point in the history
This fixes a sparse warning about weird locking.
The spinlock is not needed, so simply remove it.
This also adds some sanity checks to the PHY and radio locking
to protect against recursive locking.

Signed-off-by: Michael Buesch <mb@bu3sch.de>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Michael Buesch authored and David S. Miller committed Jan 28, 2008
1 parent a8bdf29 commit bfe6a50
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 48 deletions.
16 changes: 7 additions & 9 deletions drivers/net/wireless/b43legacy/b43legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ struct b43legacy_phy {
u8 calibrated:1;
u8 radio_rev; /* Radio revision */

bool locked; /* Only used in b43legacy_phy_{un}lock() */
bool dyn_tssi_tbl; /* tssi2dbm is kmalloc()ed. */

/* ACI (adjacent channel interference) flags. */
Expand Down Expand Up @@ -458,11 +457,6 @@ struct b43legacy_phy {
s16 lna_gain; /* LNA */
s16 pga_gain; /* PGA */

/* PHY lock for core.rev < 3
* This lock is only used by b43legacy_phy_{un}lock()
*/
spinlock_t lock;

/* Desired TX power level (in dBm). This is set by the user and
* adjusted in b43legacy_phy_xmitpower(). */
u8 power_level;
Expand All @@ -486,9 +480,6 @@ struct b43legacy_phy {
u16 txpwr_offset;
};

#ifdef CONFIG_B43LEGACY_DEBUG
bool manual_txpower_control; /* Manual TX-power control enabled? */
#endif
/* Current Interference Mitigation mode */
int interfmode;
/* Stack of saved values from the Interference Mitigation code.
Expand Down Expand Up @@ -516,6 +507,13 @@ struct b43legacy_phy {

/* PHY TX errors counter. */
atomic_t txerr_cnt;

#if B43legacy_DEBUG
/* Manual TX-power control enabled? */
bool manual_txpower_control;
/* PHY registers locked by b43legacy_phy_lock()? */
bool phy_locked;
#endif /* B43legacy_DEBUG */
};

/* Data structures for DMA transmission, per 80211 core. */
Expand Down
4 changes: 0 additions & 4 deletions drivers/net/wireless/b43legacy/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2847,8 +2847,6 @@ static void setup_struct_phy_for_init(struct b43legacy_wldev *dev,
memset(phy->minlowsig, 0xFF, sizeof(phy->minlowsig));
memset(phy->minlowsigpos, 0, sizeof(phy->minlowsigpos));

/* Flags */
phy->locked = 0;
/* Assume the radio is enabled. If it's not enabled, the state will
* immediately get fixed on the first periodic work run. */
dev->radio_hw_enable = 1;
Expand Down Expand Up @@ -2881,7 +2879,6 @@ static void setup_struct_phy_for_init(struct b43legacy_wldev *dev,
phy->lofcal = 0xFFFF;
phy->initval = 0xFFFF;

spin_lock_init(&phy->lock);
phy->interfmode = B43legacy_INTERFMODE_NONE;
phy->channel = 0xFF;
}
Expand Down Expand Up @@ -3013,7 +3010,6 @@ static void prepare_phy_data_for_init(struct b43legacy_wldev *dev)

/* Flags */
phy->calibrated = 0;
phy->locked = 0;

if (phy->_lo_pairs)
memset(phy->_lo_pairs, 0,
Expand Down
35 changes: 15 additions & 20 deletions drivers/net/wireless/b43legacy/phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,40 +91,36 @@ void b43legacy_voluntary_preempt(void)
#endif /* CONFIG_PREEMPT */
}

void b43legacy_raw_phy_lock(struct b43legacy_wldev *dev)
/* Lock the PHY registers against concurrent access from the microcode.
* This lock is nonrecursive. */
void b43legacy_phy_lock(struct b43legacy_wldev *dev)
{
struct b43legacy_phy *phy = &dev->phy;
#if B43legacy_DEBUG
B43legacy_WARN_ON(dev->phy.phy_locked);
dev->phy.phy_locked = 1;
#endif

B43legacy_WARN_ON(!irqs_disabled());
if (b43legacy_read32(dev, B43legacy_MMIO_STATUS_BITFIELD) == 0) {
phy->locked = 0;
return;
}
if (dev->dev->id.revision < 3) {
b43legacy_mac_suspend(dev);
spin_lock(&phy->lock);
} else {
if (!b43legacy_is_mode(dev->wl, IEEE80211_IF_TYPE_AP))
b43legacy_power_saving_ctl_bits(dev, -1, 1);
}
phy->locked = 1;
}

void b43legacy_raw_phy_unlock(struct b43legacy_wldev *dev)
void b43legacy_phy_unlock(struct b43legacy_wldev *dev)
{
struct b43legacy_phy *phy = &dev->phy;
#if B43legacy_DEBUG
B43legacy_WARN_ON(!dev->phy.phy_locked);
dev->phy.phy_locked = 0;
#endif

B43legacy_WARN_ON(!irqs_disabled());
if (dev->dev->id.revision < 3) {
if (phy->locked) {
spin_unlock(&phy->lock);
b43legacy_mac_enable(dev);
}
b43legacy_mac_enable(dev);
} else {
if (!b43legacy_is_mode(dev->wl, IEEE80211_IF_TYPE_AP))
b43legacy_power_saving_ctl_bits(dev, -1, -1);
}
phy->locked = 0;
}

u16 b43legacy_phy_read(struct b43legacy_wldev *dev, u16 offset)
Expand Down Expand Up @@ -1789,7 +1785,6 @@ void b43legacy_phy_xmitpower(struct b43legacy_wldev *dev)
s16 baseband_att_delta;
s16 radio_attenuation;
s16 baseband_attenuation;
unsigned long phylock_flags;

if (phy->savedpctlreg == 0xFFFF)
return;
Expand Down Expand Up @@ -1944,13 +1939,13 @@ void b43legacy_phy_xmitpower(struct b43legacy_wldev *dev)
phy->bbatt = baseband_attenuation;

/* Adjust the hardware */
b43legacy_phy_lock(dev, phylock_flags);
b43legacy_phy_lock(dev);
b43legacy_radio_lock(dev);
b43legacy_radio_set_txpower_bg(dev, baseband_attenuation,
radio_attenuation, txpower);
b43legacy_phy_lo_mark_current_used(dev);
b43legacy_radio_unlock(dev);
b43legacy_phy_unlock(dev, phylock_flags);
b43legacy_phy_unlock(dev);
}

static inline
Expand Down
14 changes: 2 additions & 12 deletions drivers/net/wireless/b43legacy/phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,8 @@ void b43legacy_put_attenuation_into_ranges(int *_bbatt, int *_rfatt);

struct b43legacy_wldev;

void b43legacy_raw_phy_lock(struct b43legacy_wldev *dev);
#define b43legacy_phy_lock(bcm, flags) \
do { \
local_irq_save(flags); \
b43legacy_raw_phy_lock(bcm); \
} while (0)
void b43legacy_raw_phy_unlock(struct b43legacy_wldev *dev);
#define b43legacy_phy_unlock(bcm, flags) \
do { \
b43legacy_raw_phy_unlock(bcm); \
local_irq_restore(flags); \
} while (0)
void b43legacy_phy_lock(struct b43legacy_wldev *dev);
void b43legacy_phy_unlock(struct b43legacy_wldev *dev);

/* Card uses the loopback gain stuff */
#define has_loopback_gain(phy) \
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/wireless/b43legacy/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void b43legacy_radio_lock(struct b43legacy_wldev *dev)
u32 status;

status = b43legacy_read32(dev, B43legacy_MMIO_STATUS_BITFIELD);
B43legacy_WARN_ON(status & B43legacy_SBF_RADIOREG_LOCK);
status |= B43legacy_SBF_RADIOREG_LOCK;
b43legacy_write32(dev, B43legacy_MMIO_STATUS_BITFIELD, status);
mmiowb();
Expand All @@ -104,6 +105,7 @@ void b43legacy_radio_unlock(struct b43legacy_wldev *dev)

b43legacy_read16(dev, B43legacy_MMIO_PHY_VER); /* dummy read */
status = b43legacy_read32(dev, B43legacy_MMIO_STATUS_BITFIELD);
B43legacy_WARN_ON(!(status & B43legacy_SBF_RADIOREG_LOCK));
status &= ~B43legacy_SBF_RADIOREG_LOCK;
b43legacy_write32(dev, B43legacy_MMIO_STATUS_BITFIELD, status);
mmiowb();
Expand Down Expand Up @@ -284,12 +286,11 @@ u8 b43legacy_radio_aci_scan(struct b43legacy_wldev *dev)
unsigned int j;
unsigned int start;
unsigned int end;
unsigned long phylock_flags;

if (!((phy->type == B43legacy_PHYTYPE_G) && (phy->rev > 0)))
return 0;

b43legacy_phy_lock(dev, phylock_flags);
b43legacy_phy_lock(dev);
b43legacy_radio_lock(dev);
b43legacy_phy_write(dev, 0x0802,
b43legacy_phy_read(dev, 0x0802) & 0xFFFC);
Expand Down Expand Up @@ -323,7 +324,7 @@ u8 b43legacy_radio_aci_scan(struct b43legacy_wldev *dev)
ret[j] = 1;
}
b43legacy_radio_unlock(dev);
b43legacy_phy_unlock(dev, phylock_flags);
b43legacy_phy_unlock(dev);

return ret[channel - 1];
}
Expand Down

0 comments on commit bfe6a50

Please sign in to comment.