Skip to content

Commit

Permalink
mac80211: redefine usage of the mac80211 workqueue
Browse files Browse the repository at this point in the history
The mac80211 workqueue exists to enable mac80211 and drivers
to queue their own work on a single threaded workqueue. mac80211
takes care to flush the workqueue during suspend but we never
really had requirements on drivers for how they should use
the workqueue in consideration for suspend.

We extend mac80211 to document how the mac80211 workqueue should
be used, how it should not be used and finally move raw access to
the workqueue to mac80211 only. Drivers and mac80211 use helpers
to queue work onto the mac80211 workqueue:

  * ieee80211_queue_work()
  * ieee80211_queue_delayed_work()

These helpers will now warn if mac80211 already completed its
suspend cycle and someone is trying to queue work. mac80211
flushes the mac80211 workqueue prior to suspend a few times,
but we haven't taken the care to ensure drivers won't add more
work after suspend. To help with this we add a warning when
someone tries to add work and mac80211 already completed the
suspend cycle.

Drivers should ensure they cancel any work or delayed work
in the mac80211 stop() callback.

Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Luis R. Rodriguez authored and John W. Linville committed Aug 4, 2009
1 parent 64344d7 commit 42935ec
Show file tree
Hide file tree
Showing 32 changed files with 208 additions and 123 deletions.
10 changes: 5 additions & 5 deletions drivers/net/wireless/at76c50x-usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1875,8 +1875,8 @@ static void at76_dwork_hw_scan(struct work_struct *work)
/* FIXME: add maximum time for scan to complete */

if (ret != CMD_STATUS_COMPLETE) {
queue_delayed_work(priv->hw->workqueue, &priv->dwork_hw_scan,
SCAN_POLL_INTERVAL);
ieee80211_queue_delayed_work(priv->hw, &priv->dwork_hw_scan,
SCAN_POLL_INTERVAL);
mutex_unlock(&priv->mtx);
return;
}
Expand Down Expand Up @@ -1937,8 +1937,8 @@ static int at76_hw_scan(struct ieee80211_hw *hw,
goto exit;
}

queue_delayed_work(priv->hw->workqueue, &priv->dwork_hw_scan,
SCAN_POLL_INTERVAL);
ieee80211_queue_delayed_work(priv->hw, &priv->dwork_hw_scan,
SCAN_POLL_INTERVAL);

exit:
mutex_unlock(&priv->mtx);
Expand Down Expand Up @@ -2027,7 +2027,7 @@ static void at76_configure_filter(struct ieee80211_hw *hw,
} else
return;

queue_work(hw->workqueue, &priv->work_set_promisc);
ieee80211_queue_work(hw, &priv->work_set_promisc);
}

static int at76_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Expand Down
11 changes: 7 additions & 4 deletions drivers/net/wireless/ath/ar9170/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ static void ar9170_update_leds(struct work_struct *work)
ar9170_set_leds_state(ar, led_val);
mutex_unlock(&ar->mutex);

if (rerun)
queue_delayed_work(ar->hw->workqueue, &ar->led_work,
msecs_to_jiffies(blink_delay));
if (!rerun)
return;

ieee80211_queue_delayed_work(ar->hw,
&ar->led_work,
msecs_to_jiffies(blink_delay));
}

static void ar9170_led_brightness_set(struct led_classdev *led,
Expand All @@ -110,7 +113,7 @@ static void ar9170_led_brightness_set(struct led_classdev *led,
}

if (likely(IS_ACCEPTING_CMD(ar) && arl->toggled))
queue_delayed_work(ar->hw->workqueue, &ar->led_work, HZ/10);
ieee80211_queue_delayed_work(ar->hw, &ar->led_work, HZ/10);
}

static int ar9170_register_led(struct ar9170 *ar, int i, char *name,
Expand Down
26 changes: 15 additions & 11 deletions drivers/net/wireless/ath/ar9170/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,12 @@ static void ar9170_tx_janitor(struct work_struct *work)

ar9170_tx_fake_ampdu_status(ar);

if (resched)
queue_delayed_work(ar->hw->workqueue,
&ar->tx_janitor,
msecs_to_jiffies(AR9170_JANITOR_DELAY));
if (!resched)
return;

ieee80211_queue_delayed_work(ar->hw,
&ar->tx_janitor,
msecs_to_jiffies(AR9170_JANITOR_DELAY));
}

void ar9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len)
Expand Down Expand Up @@ -648,7 +650,7 @@ void ar9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len)
* pre-TBTT event
*/
if (ar->vif && ar->vif->type == NL80211_IFTYPE_AP)
queue_work(ar->hw->workqueue, &ar->beacon_work);
ieee80211_queue_work(ar->hw, &ar->beacon_work);
break;

case 0xc2:
Expand Down Expand Up @@ -1825,10 +1827,12 @@ static void ar9170_tx(struct ar9170 *ar)
}
}

if (schedule_garbagecollector)
queue_delayed_work(ar->hw->workqueue,
&ar->tx_janitor,
msecs_to_jiffies(AR9170_JANITOR_DELAY));
if (!schedule_garbagecollector)
return;

ieee80211_queue_delayed_work(ar->hw,
&ar->tx_janitor,
msecs_to_jiffies(AR9170_JANITOR_DELAY));
}

static bool ar9170_tx_ampdu_queue(struct ar9170 *ar, struct sk_buff *skb)
Expand Down Expand Up @@ -2157,7 +2161,7 @@ static void ar9170_op_configure_filter(struct ieee80211_hw *hw,
}

if (likely(IS_STARTED(ar)))
queue_work(ar->hw->workqueue, &ar->filter_config_work);
ieee80211_queue_work(ar->hw, &ar->filter_config_work);
}

static void ar9170_op_bss_info_changed(struct ieee80211_hw *hw,
Expand Down Expand Up @@ -2415,7 +2419,7 @@ static void ar9170_sta_notify(struct ieee80211_hw *hw,
}

if (IS_STARTED(ar) && ar->filter_changed)
queue_work(ar->hw->workqueue, &ar->filter_config_work);
ieee80211_queue_work(ar->hw, &ar->filter_config_work);
}

static int ar9170_get_stats(struct ieee80211_hw *hw,
Expand Down
15 changes: 8 additions & 7 deletions drivers/net/wireless/ath/ath9k/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,10 +973,11 @@ static void ath_led_blink_work(struct work_struct *work)
ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN,
(sc->sc_flags & SC_OP_LED_ON) ? 1 : 0);

queue_delayed_work(sc->hw->workqueue, &sc->ath_led_blink_work,
(sc->sc_flags & SC_OP_LED_ON) ?
msecs_to_jiffies(sc->led_off_duration) :
msecs_to_jiffies(sc->led_on_duration));
ieee80211_queue_delayed_work(sc->hw,
&sc->ath_led_blink_work,
(sc->sc_flags & SC_OP_LED_ON) ?
msecs_to_jiffies(sc->led_off_duration) :
msecs_to_jiffies(sc->led_on_duration));

sc->led_on_duration = sc->led_on_cnt ?
max((ATH_LED_ON_DURATION_IDLE - sc->led_on_cnt), 25) :
Expand Down Expand Up @@ -1013,8 +1014,8 @@ static void ath_led_brightness(struct led_classdev *led_cdev,
case LED_FULL:
if (led->led_type == ATH_LED_ASSOC) {
sc->sc_flags |= SC_OP_LED_ASSOCIATED;
queue_delayed_work(sc->hw->workqueue,
&sc->ath_led_blink_work, 0);
ieee80211_queue_delayed_work(sc->hw,
&sc->ath_led_blink_work, 0);
} else if (led->led_type == ATH_LED_RADIO) {
ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 0);
sc->sc_flags |= SC_OP_LED_ON;
Expand Down Expand Up @@ -1972,7 +1973,7 @@ static int ath9k_start(struct ieee80211_hw *hw)

ieee80211_wake_queues(hw);

queue_delayed_work(sc->hw->workqueue, &sc->tx_complete_work, 0);
ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);

mutex_unlock:
mutex_unlock(&sc->mutex);
Expand Down
17 changes: 9 additions & 8 deletions drivers/net/wireless/ath/ath9k/virtual.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ void ath9k_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
* Drop from tasklet to work to allow mutex for channel
* change.
*/
queue_work(aphy->sc->hw->workqueue,
ieee80211_queue_work(aphy->sc->hw,
&aphy->sc->chan_work);
}
}
Expand All @@ -367,7 +367,7 @@ static void ath9k_mark_paused(struct ath_wiphy *aphy)
struct ath_softc *sc = aphy->sc;
aphy->state = ATH_WIPHY_PAUSED;
if (!__ath9k_wiphy_pausing(sc))
queue_work(sc->hw->workqueue, &sc->chan_work);
ieee80211_queue_work(sc->hw, &sc->chan_work);
}

static void ath9k_pause_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
Expand Down Expand Up @@ -521,7 +521,7 @@ int ath9k_wiphy_select(struct ath_wiphy *aphy)
spin_unlock_bh(&sc->wiphy_lock);
ath_radio_disable(sc);
ath_radio_enable(sc);
queue_work(aphy->sc->hw->workqueue,
ieee80211_queue_work(aphy->sc->hw,
&aphy->sc->chan_work);
return -EBUSY; /* previous select still in progress */
}
Expand All @@ -541,7 +541,7 @@ int ath9k_wiphy_select(struct ath_wiphy *aphy)

if (now) {
/* Ready to request channel change immediately */
queue_work(aphy->sc->hw->workqueue, &aphy->sc->chan_work);
ieee80211_queue_work(aphy->sc->hw, &aphy->sc->chan_work);
}

/*
Expand Down Expand Up @@ -648,17 +648,18 @@ void ath9k_wiphy_work(struct work_struct *work)
"change\n");
}

queue_delayed_work(sc->hw->workqueue, &sc->wiphy_work,
sc->wiphy_scheduler_int);
ieee80211_queue_delayed_work(sc->hw,
&sc->wiphy_work,
sc->wiphy_scheduler_int);
}

void ath9k_wiphy_set_scheduler(struct ath_softc *sc, unsigned int msec_int)
{
cancel_delayed_work_sync(&sc->wiphy_work);
sc->wiphy_scheduler_int = msecs_to_jiffies(msec_int);
if (sc->wiphy_scheduler_int)
queue_delayed_work(sc->hw->workqueue, &sc->wiphy_work,
sc->wiphy_scheduler_int);
ieee80211_queue_delayed_work(sc->hw, &sc->wiphy_work,
sc->wiphy_scheduler_int);
}

/* caller must hold wiphy_lock */
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/ath/ath9k/xmit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2063,7 +2063,7 @@ static void ath_tx_complete_poll_work(struct work_struct *work)
ath_reset(sc, false);
}

queue_delayed_work(sc->hw->workqueue, &sc->tx_complete_work,
ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work,
msecs_to_jiffies(ATH_TX_COMPLETE_POLL_INT));
}

Expand Down
8 changes: 4 additions & 4 deletions drivers/net/wireless/b43/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,7 @@ static void b43_update_templates(struct b43_wl *wl)
wl->current_beacon = beacon;
wl->beacon0_uploaded = 0;
wl->beacon1_uploaded = 0;
queue_work(wl->hw->workqueue, &wl->beacon_update_trigger);
ieee80211_queue_work(wl->hw, &wl->beacon_update_trigger);
}

static void b43_set_beacon_int(struct b43_wldev *dev, u16 beacon_int)
Expand Down Expand Up @@ -2914,7 +2914,7 @@ static void b43_periodic_work_handler(struct work_struct *work)
delay = msecs_to_jiffies(50);
else
delay = round_jiffies_relative(HZ * 15);
queue_delayed_work(wl->hw->workqueue, &dev->periodic_work, delay);
ieee80211_queue_delayed_work(wl->hw, &dev->periodic_work, delay);
out:
mutex_unlock(&wl->mutex);
}
Expand All @@ -2925,7 +2925,7 @@ static void b43_periodic_tasks_setup(struct b43_wldev *dev)

dev->periodic_state = 0;
INIT_DELAYED_WORK(work, b43_periodic_work_handler);
queue_delayed_work(dev->wl->hw->workqueue, work, 0);
ieee80211_queue_delayed_work(dev->wl->hw, work, 0);
}

/* Check if communication with the device works correctly. */
Expand Down Expand Up @@ -4871,7 +4871,7 @@ void b43_controller_restart(struct b43_wldev *dev, const char *reason)
if (b43_status(dev) < B43_STAT_INITIALIZED)
return;
b43info(dev->wl, "Controller RESET (%s) ...\n", reason);
queue_work(dev->wl->hw->workqueue, &dev->restart_work);
ieee80211_queue_work(dev->wl->hw, &dev->restart_work);
}

#ifdef CONFIG_PM
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/b43/phy_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void b43_phy_txpower_check(struct b43_wldev *dev, unsigned int flags)

/* We must adjust the transmission power in hardware.
* Schedule b43_phy_txpower_adjust_work(). */
queue_work(dev->wl->hw->workqueue, &dev->wl->txpower_adjust_work);
ieee80211_queue_work(dev->wl->hw, &dev->wl->txpower_adjust_work);
}

int b43_phy_shm_tssi_read(struct b43_wldev *dev, u16 shm_offset)
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/b43/pio.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ void b43_pio_rx(struct b43_pio_rxqueue *q)
{
/* Due to latency issues we must run the RX path in
* a workqueue to be able to schedule between packets. */
queue_work(q->dev->wl->hw->workqueue, &q->rx_work);
ieee80211_queue_work(q->dev->wl->hw, &q->rx_work);
}

static void b43_pio_tx_suspend_queue(struct b43_pio_txqueue *q)
Expand Down
8 changes: 4 additions & 4 deletions drivers/net/wireless/b43legacy/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ static void b43legacy_update_templates(struct b43legacy_wl *wl)
wl->current_beacon = beacon;
wl->beacon0_uploaded = 0;
wl->beacon1_uploaded = 0;
queue_work(wl->hw->workqueue, &wl->beacon_update_trigger);
ieee80211_queue_work(wl->hw, &wl->beacon_update_trigger);
}

static void b43legacy_set_beacon_int(struct b43legacy_wldev *dev,
Expand Down Expand Up @@ -2300,7 +2300,7 @@ static void b43legacy_periodic_work_handler(struct work_struct *work)
delay = msecs_to_jiffies(50);
else
delay = round_jiffies_relative(HZ * 15);
queue_delayed_work(wl->hw->workqueue, &dev->periodic_work, delay);
ieee80211_queue_delayed_work(wl->hw, &dev->periodic_work, delay);
out:
mutex_unlock(&wl->mutex);
}
Expand All @@ -2311,7 +2311,7 @@ static void b43legacy_periodic_tasks_setup(struct b43legacy_wldev *dev)

dev->periodic_state = 0;
INIT_DELAYED_WORK(work, b43legacy_periodic_work_handler);
queue_delayed_work(dev->wl->hw->workqueue, work, 0);
ieee80211_queue_delayed_work(dev->wl->hw, work, 0);
}

/* Validate access to the chip (SHM) */
Expand Down Expand Up @@ -3885,7 +3885,7 @@ void b43legacy_controller_restart(struct b43legacy_wldev *dev,
if (b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)
return;
b43legacyinfo(dev->wl, "Controller RESET (%s) ...\n", reason);
queue_work(dev->wl->hw->workqueue, &dev->restart_work);
ieee80211_queue_work(dev->wl->hw, &dev->restart_work);
}

#ifdef CONFIG_PM
Expand Down
5 changes: 2 additions & 3 deletions drivers/net/wireless/p54/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void p54_update_leds(struct work_struct *work)
wiphy_name(priv->hw->wiphy), err);

if (rerun)
queue_delayed_work(priv->hw->workqueue, &priv->led_work,
ieee80211_queue_delayed_work(priv->hw, &priv->led_work,
msecs_to_jiffies(blink_delay));
}

Expand All @@ -78,8 +78,7 @@ static void p54_led_brightness_set(struct led_classdev *led_dev,

if ((brightness) && (led->registered)) {
led->toggled++;
queue_delayed_work(priv->hw->workqueue, &priv->led_work,
HZ/10);
ieee80211_queue_delayed_work(priv->hw, &priv->led_work, HZ/10);
}
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/p54/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static int p54_start(struct ieee80211_hw *dev)
goto out;
}

queue_delayed_work(dev->workqueue, &priv->work, 0);
ieee80211_queue_delayed_work(dev, &priv->work, 0);

priv->softled_state = 0;
err = p54_set_leds(priv);
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/wireless/p54/p54spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ static irqreturn_t p54spi_interrupt(int irq, void *config)
struct spi_device *spi = config;
struct p54s_priv *priv = dev_get_drvdata(&spi->dev);

queue_work(priv->hw->workqueue, &priv->work);
ieee80211_queue_work(priv->hw, &priv->work);

return IRQ_HANDLED;
}
Expand Down Expand Up @@ -479,7 +479,7 @@ static void p54spi_op_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
list_add_tail(&di->tx_list, &priv->tx_pending);
spin_unlock_irqrestore(&priv->tx_lock, flags);

queue_work(priv->hw->workqueue, &priv->work);
ieee80211_queue_work(priv->hw, &priv->work);
}

static void p54spi_work(struct work_struct *work)
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/p54/txrx.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ static int p54_rx_data(struct p54_common *priv, struct sk_buff *skb)

ieee80211_rx_irqsafe(priv->hw, skb);

queue_delayed_work(priv->hw->workqueue, &priv->work,
ieee80211_queue_delayed_work(priv->hw, &priv->work,
msecs_to_jiffies(P54_STATISTICS_UPDATE));

return -1;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/rt2x00/rt2x00dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev)
rt2x00lib_beacondone_iter,
rt2x00dev);

queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->intf_work);
ieee80211_queue_work(rt2x00dev->hw, &rt2x00dev->intf_work);
}
EXPORT_SYMBOL_GPL(rt2x00lib_beacondone);

Expand Down
8 changes: 4 additions & 4 deletions drivers/net/wireless/rt2x00/rt2x00link.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ void rt2x00link_start_tuner(struct rt2x00_dev *rt2x00dev)

rt2x00link_reset_tuner(rt2x00dev, false);

queue_delayed_work(rt2x00dev->hw->workqueue,
&link->work, LINK_TUNE_INTERVAL);
ieee80211_queue_delayed_work(rt2x00dev->hw,
&link->work, LINK_TUNE_INTERVAL);
}

void rt2x00link_stop_tuner(struct rt2x00_dev *rt2x00dev)
Expand Down Expand Up @@ -461,8 +461,8 @@ static void rt2x00link_tuner(struct work_struct *work)
* Increase tuner counter, and reschedule the next link tuner run.
*/
link->count++;
queue_delayed_work(rt2x00dev->hw->workqueue,
&link->work, LINK_TUNE_INTERVAL);
ieee80211_queue_delayed_work(rt2x00dev->hw,
&link->work, LINK_TUNE_INTERVAL);
}

void rt2x00link_register(struct rt2x00_dev *rt2x00dev)
Expand Down
Loading

0 comments on commit 42935ec

Please sign in to comment.