Commit 59af6928 authored by Michal Kazior's avatar Michal Kazior Committed by Johannes Berg

mac80211: fix CSA tx queue stopping

It was possible for tx queues to be stuck stopped
if AP CSA finalization failed. In that case
neither stop_ap nor do_stop woke the queues up.
This means it was impossible to perform tx at all
until driver was reloaded or a successful CSA was
performed later.

It was possible to solve this in a simpler manner
however this is more robust and future proof
(having multi-vif CSA in mind).

New sdata->csa_block_tx is introduced to keep
track of which interfaces requested tx to be
blocked for CSA. This is required because mac80211
stops all tx queues for that purpose. This means
queues must be awoken only when last tx-blocking
CSA interface is finished.

It is still possible to have tx queues stopped
after CSA failure but as soon as offending
interfaces are stopped from userspace (stop_ap or
ifdown) tx queues are woken up properly.
Signed-off-by: default avatarMichal Kazior <michal.kazior@tieto.com>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 33926eb7
...@@ -1113,7 +1113,9 @@ enum ieee80211_vif_flags { ...@@ -1113,7 +1113,9 @@ enum ieee80211_vif_flags {
* @addr: address of this interface * @addr: address of this interface
* @p2p: indicates whether this AP or STA interface is a p2p * @p2p: indicates whether this AP or STA interface is a p2p
* interface, i.e. a GO or p2p-sta respectively * interface, i.e. a GO or p2p-sta respectively
* @csa_active: marks whether a channel switch is going on * @csa_active: marks whether a channel switch is going on. Internally it is
* write-protected by sdata_lock and local->mtx so holding either is fine
* for read access.
* @driver_flags: flags/capabilities the driver has for this interface, * @driver_flags: flags/capabilities the driver has for this interface,
* these need to be set (or cleared) when the interface is added * these need to be set (or cleared) when the interface is added
* or, if supported by the driver, the interface type is changed * or, if supported by the driver, the interface type is changed
......
...@@ -1084,6 +1084,31 @@ static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev, ...@@ -1084,6 +1084,31 @@ static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
return 0; return 0;
} }
bool ieee80211_csa_needs_block_tx(struct ieee80211_local *local)
{
struct ieee80211_sub_if_data *sdata;
lockdep_assert_held(&local->mtx);
rcu_read_lock();
list_for_each_entry_rcu(sdata, &local->interfaces, list) {
if (!ieee80211_sdata_running(sdata))
continue;
if (!sdata->vif.csa_active)
continue;
if (!sdata->csa_block_tx)
continue;
rcu_read_unlock();
return true;
}
rcu_read_unlock();
return false;
}
static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev) static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
{ {
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
...@@ -1101,7 +1126,14 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev) ...@@ -1101,7 +1126,14 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata); old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
/* abort any running channel switch */ /* abort any running channel switch */
mutex_lock(&local->mtx);
sdata->vif.csa_active = false; sdata->vif.csa_active = false;
if (!ieee80211_csa_needs_block_tx(local))
ieee80211_wake_queues_by_reason(&local->hw,
IEEE80211_MAX_QUEUE_MAP,
IEEE80211_QUEUE_STOP_REASON_CSA);
mutex_unlock(&local->mtx);
kfree(sdata->u.ap.next_beacon); kfree(sdata->u.ap.next_beacon);
sdata->u.ap.next_beacon = NULL; sdata->u.ap.next_beacon = NULL;
...@@ -3027,11 +3059,10 @@ static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata) ...@@ -3027,11 +3059,10 @@ static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
int err, changed = 0; int err, changed = 0;
sdata_assert_lock(sdata); sdata_assert_lock(sdata);
lockdep_assert_held(&local->mtx);
mutex_lock(&local->mtx);
sdata->radar_required = sdata->csa_radar_required; sdata->radar_required = sdata->csa_radar_required;
err = ieee80211_vif_change_channel(sdata, &changed); err = ieee80211_vif_change_channel(sdata, &changed);
mutex_unlock(&local->mtx);
if (WARN_ON(err < 0)) if (WARN_ON(err < 0))
return; return;
...@@ -3072,11 +3103,12 @@ static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata) ...@@ -3072,11 +3103,12 @@ static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
ieee80211_bss_info_change_notify(sdata, changed); ieee80211_bss_info_change_notify(sdata, changed);
ieee80211_wake_queues_by_reason(&sdata->local->hw, cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
if (!ieee80211_csa_needs_block_tx(local))
ieee80211_wake_queues_by_reason(&local->hw,
IEEE80211_MAX_QUEUE_MAP, IEEE80211_MAX_QUEUE_MAP,
IEEE80211_QUEUE_STOP_REASON_CSA); IEEE80211_QUEUE_STOP_REASON_CSA);
cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
} }
void ieee80211_csa_finalize_work(struct work_struct *work) void ieee80211_csa_finalize_work(struct work_struct *work)
...@@ -3084,8 +3116,11 @@ void ieee80211_csa_finalize_work(struct work_struct *work) ...@@ -3084,8 +3116,11 @@ void ieee80211_csa_finalize_work(struct work_struct *work)
struct ieee80211_sub_if_data *sdata = struct ieee80211_sub_if_data *sdata =
container_of(work, struct ieee80211_sub_if_data, container_of(work, struct ieee80211_sub_if_data,
csa_finalize_work); csa_finalize_work);
struct ieee80211_local *local = sdata->local;
sdata_lock(sdata); sdata_lock(sdata);
mutex_lock(&local->mtx);
/* AP might have been stopped while waiting for the lock. */ /* AP might have been stopped while waiting for the lock. */
if (!sdata->vif.csa_active) if (!sdata->vif.csa_active)
goto unlock; goto unlock;
...@@ -3096,6 +3131,7 @@ void ieee80211_csa_finalize_work(struct work_struct *work) ...@@ -3096,6 +3131,7 @@ void ieee80211_csa_finalize_work(struct work_struct *work)
ieee80211_csa_finalize(sdata); ieee80211_csa_finalize(sdata);
unlock: unlock:
mutex_unlock(&local->mtx);
sdata_unlock(sdata); sdata_unlock(sdata);
} }
...@@ -3222,7 +3258,7 @@ static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata, ...@@ -3222,7 +3258,7 @@ static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
return 0; return 0;
} }
int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, int __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
struct cfg80211_csa_settings *params) struct cfg80211_csa_settings *params)
{ {
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
...@@ -3232,6 +3268,7 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, ...@@ -3232,6 +3268,7 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
int err, num_chanctx, changed = 0; int err, num_chanctx, changed = 0;
sdata_assert_lock(sdata); sdata_assert_lock(sdata);
lockdep_assert_held(&local->mtx);
if (!list_empty(&local->roc_list) || local->scanning) if (!list_empty(&local->roc_list) || local->scanning)
return -EBUSY; return -EBUSY;
...@@ -3274,15 +3311,15 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, ...@@ -3274,15 +3311,15 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
return err; return err;
sdata->csa_radar_required = params->radar_required; sdata->csa_radar_required = params->radar_required;
sdata->csa_chandef = params->chandef;
sdata->csa_block_tx = params->block_tx;
sdata->vif.csa_active = true;
if (params->block_tx) if (sdata->csa_block_tx)
ieee80211_stop_queues_by_reason(&local->hw, ieee80211_stop_queues_by_reason(&local->hw,
IEEE80211_MAX_QUEUE_MAP, IEEE80211_MAX_QUEUE_MAP,
IEEE80211_QUEUE_STOP_REASON_CSA); IEEE80211_QUEUE_STOP_REASON_CSA);
sdata->csa_chandef = params->chandef;
sdata->vif.csa_active = true;
if (changed) { if (changed) {
ieee80211_bss_info_change_notify(sdata, changed); ieee80211_bss_info_change_notify(sdata, changed);
drv_channel_switch_beacon(sdata, &params->chandef); drv_channel_switch_beacon(sdata, &params->chandef);
...@@ -3294,6 +3331,20 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, ...@@ -3294,6 +3331,20 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
return 0; return 0;
} }
int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
struct cfg80211_csa_settings *params)
{
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
struct ieee80211_local *local = sdata->local;
int err;
mutex_lock(&local->mtx);
err = __ieee80211_channel_switch(wiphy, dev, params);
mutex_unlock(&local->mtx);
return err;
}
static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
struct cfg80211_mgmt_tx_params *params, struct cfg80211_mgmt_tx_params *params,
u64 *cookie) u64 *cookie)
......
...@@ -756,6 +756,7 @@ struct ieee80211_sub_if_data { ...@@ -756,6 +756,7 @@ struct ieee80211_sub_if_data {
int csa_counter_offset_beacon; int csa_counter_offset_beacon;
int csa_counter_offset_presp; int csa_counter_offset_presp;
bool csa_radar_required; bool csa_radar_required;
bool csa_block_tx; /* write-protected by sdata_lock and local->mtx */
struct cfg80211_chan_def csa_chandef; struct cfg80211_chan_def csa_chandef;
struct list_head assigned_chanctx_list; /* protected by chanctx_mtx */ struct list_head assigned_chanctx_list; /* protected by chanctx_mtx */
...@@ -1472,6 +1473,7 @@ void ieee80211_sw_roc_work(struct work_struct *work); ...@@ -1472,6 +1473,7 @@ void ieee80211_sw_roc_work(struct work_struct *work);
void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc); void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc);
/* channel switch handling */ /* channel switch handling */
bool ieee80211_csa_needs_block_tx(struct ieee80211_local *local);
void ieee80211_csa_finalize_work(struct work_struct *work); void ieee80211_csa_finalize_work(struct work_struct *work);
int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
struct cfg80211_csa_settings *params); struct cfg80211_csa_settings *params);
......
...@@ -838,8 +838,15 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata, ...@@ -838,8 +838,15 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
cancel_work_sync(&sdata->recalc_smps); cancel_work_sync(&sdata->recalc_smps);
sdata_lock(sdata); sdata_lock(sdata);
mutex_lock(&local->mtx);
sdata->vif.csa_active = false; sdata->vif.csa_active = false;
if (!ieee80211_csa_needs_block_tx(local))
ieee80211_wake_queues_by_reason(&local->hw,
IEEE80211_MAX_QUEUE_MAP,
IEEE80211_QUEUE_STOP_REASON_CSA);
mutex_unlock(&local->mtx);
sdata_unlock(sdata); sdata_unlock(sdata);
cancel_work_sync(&sdata->csa_finalize_work); cancel_work_sync(&sdata->csa_finalize_work);
cancel_delayed_work_sync(&sdata->dfs_cac_timer_work); cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
......
...@@ -975,16 +975,20 @@ static void ieee80211_chswitch_work(struct work_struct *work) ...@@ -975,16 +975,20 @@ static void ieee80211_chswitch_work(struct work_struct *work)
/* XXX: shouldn't really modify cfg80211-owned data! */ /* XXX: shouldn't really modify cfg80211-owned data! */
ifmgd->associated->channel = sdata->csa_chandef.chan; ifmgd->associated->channel = sdata->csa_chandef.chan;
ieee80211_bss_info_change_notify(sdata, changed);
mutex_lock(&local->mtx);
sdata->vif.csa_active = false;
/* XXX: wait for a beacon first? */ /* XXX: wait for a beacon first? */
if (!ieee80211_csa_needs_block_tx(local))
ieee80211_wake_queues_by_reason(&local->hw, ieee80211_wake_queues_by_reason(&local->hw,
IEEE80211_MAX_QUEUE_MAP, IEEE80211_MAX_QUEUE_MAP,
IEEE80211_QUEUE_STOP_REASON_CSA); IEEE80211_QUEUE_STOP_REASON_CSA);
mutex_unlock(&local->mtx);
ieee80211_bss_info_change_notify(sdata, changed);
out:
sdata->vif.csa_active = false;
ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
out:
sdata_unlock(sdata); sdata_unlock(sdata);
} }
...@@ -1100,12 +1104,16 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, ...@@ -1100,12 +1104,16 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
mutex_unlock(&local->chanctx_mtx); mutex_unlock(&local->chanctx_mtx);
sdata->csa_chandef = csa_ie.chandef; sdata->csa_chandef = csa_ie.chandef;
mutex_lock(&local->mtx);
sdata->vif.csa_active = true; sdata->vif.csa_active = true;
sdata->csa_block_tx = csa_ie.mode;
if (csa_ie.mode) if (sdata->csa_block_tx)
ieee80211_stop_queues_by_reason(&local->hw, ieee80211_stop_queues_by_reason(&local->hw,
IEEE80211_MAX_QUEUE_MAP, IEEE80211_MAX_QUEUE_MAP,
IEEE80211_QUEUE_STOP_REASON_CSA); IEEE80211_QUEUE_STOP_REASON_CSA);
mutex_unlock(&local->mtx);
if (local->ops->channel_switch) { if (local->ops->channel_switch) {
/* use driver's channel switch callback */ /* use driver's channel switch callback */
...@@ -1817,6 +1825,12 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, ...@@ -1817,6 +1825,12 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
ifmgd->flags = 0; ifmgd->flags = 0;
mutex_lock(&local->mtx); mutex_lock(&local->mtx);
ieee80211_vif_release_channel(sdata); ieee80211_vif_release_channel(sdata);
sdata->vif.csa_active = false;
if (!ieee80211_csa_needs_block_tx(local))
ieee80211_wake_queues_by_reason(&local->hw,
IEEE80211_MAX_QUEUE_MAP,
IEEE80211_QUEUE_STOP_REASON_CSA);
mutex_unlock(&local->mtx); mutex_unlock(&local->mtx);
sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM; sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
...@@ -2045,6 +2059,7 @@ EXPORT_SYMBOL(ieee80211_ap_probereq_get); ...@@ -2045,6 +2059,7 @@ EXPORT_SYMBOL(ieee80211_ap_probereq_get);
static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata) static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
{ {
struct ieee80211_local *local = sdata->local;
struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
...@@ -2058,10 +2073,14 @@ static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata) ...@@ -2058,10 +2073,14 @@ static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
true, frame_buf); true, frame_buf);
ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
mutex_lock(&local->mtx);
sdata->vif.csa_active = false; sdata->vif.csa_active = false;
ieee80211_wake_queues_by_reason(&sdata->local->hw, if (!ieee80211_csa_needs_block_tx(local))
ieee80211_wake_queues_by_reason(&local->hw,
IEEE80211_MAX_QUEUE_MAP, IEEE80211_MAX_QUEUE_MAP,
IEEE80211_QUEUE_STOP_REASON_CSA); IEEE80211_QUEUE_STOP_REASON_CSA);
mutex_unlock(&local->mtx);
cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf, cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
IEEE80211_DEAUTH_FRAME_LEN); IEEE80211_DEAUTH_FRAME_LEN);
......
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