Commit 4c3ebc56 authored by Michal Kazior's avatar Michal Kazior Committed by Johannes Berg

mac80211: use chanctx reservation for STA CSA

Channel switch finalization is now 2-step. First
step is when driver calls chswitch_done(), the
other is when reservation is actually finalized
(which be defered for in-place reservation).

It is now safe to call ieee80211_chswitch_done()
more than once.

Also remove the ieee80211_vif_change_channel()
because it is no longer used.
Signed-off-by: default avatarMichal Kazior <michal.kazior@tieto.com>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 03078de4
...@@ -819,70 +819,6 @@ int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata, ...@@ -819,70 +819,6 @@ int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata,
return ret; return ret;
} }
static int __ieee80211_vif_change_channel(struct ieee80211_sub_if_data *sdata,
struct ieee80211_chanctx *ctx,
u32 *changed)
{
struct ieee80211_local *local = sdata->local;
const struct cfg80211_chan_def *chandef = &sdata->csa_chandef;
u32 chanctx_changed = 0;
if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
IEEE80211_CHAN_DISABLED))
return -EINVAL;
if (ieee80211_chanctx_refcount(local, ctx) != 1)
return -EINVAL;
if (sdata->vif.bss_conf.chandef.width != chandef->width) {
chanctx_changed = IEEE80211_CHANCTX_CHANGE_WIDTH;
*changed |= BSS_CHANGED_BANDWIDTH;
}
sdata->vif.bss_conf.chandef = *chandef;
ctx->conf.def = *chandef;
chanctx_changed |= IEEE80211_CHANCTX_CHANGE_CHANNEL;
drv_change_chanctx(local, ctx, chanctx_changed);
ieee80211_recalc_chanctx_chantype(local, ctx);
ieee80211_recalc_smps_chanctx(local, ctx);
ieee80211_recalc_radar_chanctx(local, ctx);
ieee80211_recalc_chanctx_min_def(local, ctx);
return 0;
}
int ieee80211_vif_change_channel(struct ieee80211_sub_if_data *sdata,
u32 *changed)
{
struct ieee80211_local *local = sdata->local;
struct ieee80211_chanctx_conf *conf;
struct ieee80211_chanctx *ctx;
int ret;
lockdep_assert_held(&local->mtx);
/* should never be called if not performing a channel switch. */
if (WARN_ON(!sdata->vif.csa_active))
return -EINVAL;
mutex_lock(&local->chanctx_mtx);
conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
lockdep_is_held(&local->chanctx_mtx));
if (!conf) {
ret = -EINVAL;
goto out;
}
ctx = container_of(conf, struct ieee80211_chanctx, conf);
ret = __ieee80211_vif_change_channel(sdata, ctx, changed);
out:
mutex_unlock(&local->chanctx_mtx);
return ret;
}
static void static void
__ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata, __ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata,
bool clear) bool clear)
...@@ -1066,8 +1002,11 @@ ieee80211_vif_chanctx_reservation_complete(struct ieee80211_sub_if_data *sdata) ...@@ -1066,8 +1002,11 @@ ieee80211_vif_chanctx_reservation_complete(struct ieee80211_sub_if_data *sdata)
ieee80211_queue_work(&sdata->local->hw, ieee80211_queue_work(&sdata->local->hw,
&sdata->csa_finalize_work); &sdata->csa_finalize_work);
break; break;
case NL80211_IFTYPE_UNSPECIFIED:
case NL80211_IFTYPE_STATION: case NL80211_IFTYPE_STATION:
ieee80211_queue_work(&sdata->local->hw,
&sdata->u.mgd.chswitch_work);
break;
case NL80211_IFTYPE_UNSPECIFIED:
case NL80211_IFTYPE_AP_VLAN: case NL80211_IFTYPE_AP_VLAN:
case NL80211_IFTYPE_WDS: case NL80211_IFTYPE_WDS:
case NL80211_IFTYPE_MONITOR: case NL80211_IFTYPE_MONITOR:
......
...@@ -788,7 +788,6 @@ struct ieee80211_sub_if_data { ...@@ -788,7 +788,6 @@ struct ieee80211_sub_if_data {
struct mac80211_qos_map __rcu *qos_map; struct mac80211_qos_map __rcu *qos_map;
struct work_struct csa_finalize_work; struct work_struct csa_finalize_work;
bool csa_radar_required;
bool csa_block_tx; /* write-protected by sdata_lock and local->mtx */ bool csa_block_tx; /* write-protected by sdata_lock and local->mtx */
struct cfg80211_chan_def csa_chandef; struct cfg80211_chan_def csa_chandef;
...@@ -1850,10 +1849,6 @@ int __must_check ...@@ -1850,10 +1849,6 @@ int __must_check
ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata, ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata,
const struct cfg80211_chan_def *chandef, const struct cfg80211_chan_def *chandef,
u32 *changed); u32 *changed);
/* NOTE: only use ieee80211_vif_change_channel() for channel switch */
int __must_check
ieee80211_vif_change_channel(struct ieee80211_sub_if_data *sdata,
u32 *changed);
void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata); void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata);
void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data *sdata); void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data *sdata);
void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata, void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata,
......
...@@ -940,52 +940,70 @@ static void ieee80211_chswitch_work(struct work_struct *work) ...@@ -940,52 +940,70 @@ static void ieee80211_chswitch_work(struct work_struct *work)
container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
struct ieee80211_local *local = sdata->local; struct ieee80211_local *local = sdata->local;
struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
u32 changed = 0;
int ret; int ret;
if (!ieee80211_sdata_running(sdata)) if (!ieee80211_sdata_running(sdata))
return; return;
sdata_lock(sdata); sdata_lock(sdata);
mutex_lock(&local->mtx);
mutex_lock(&local->chanctx_mtx);
if (!ifmgd->associated) if (!ifmgd->associated)
goto out; goto out;
mutex_lock(&local->mtx); if (!sdata->vif.csa_active)
ret = ieee80211_vif_change_channel(sdata, &changed); goto out;
mutex_unlock(&local->mtx);
if (ret) { /*
* using reservation isn't immediate as it may be deferred until later
* with multi-vif. once reservation is complete it will re-schedule the
* work with no reserved_chanctx so verify chandef to check if it
* completed successfully
*/
if (sdata->reserved_chanctx) {
/*
* with multi-vif csa driver may call ieee80211_csa_finish()
* many times while waiting for other interfaces to use their
* reservations
*/
if (sdata->reserved_ready)
goto out;
ret = ieee80211_vif_use_reserved_context(sdata);
if (ret) {
sdata_info(sdata,
"failed to use reserved channel context, disconnecting (err=%d)\n",
ret);
ieee80211_queue_work(&sdata->local->hw,
&ifmgd->csa_connection_drop_work);
goto out;
}
goto out;
}
if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
&sdata->csa_chandef)) {
sdata_info(sdata, sdata_info(sdata,
"vif channel switch failed, disconnecting\n"); "failed to finalize channel switch, disconnecting\n");
ieee80211_queue_work(&sdata->local->hw, ieee80211_queue_work(&sdata->local->hw,
&ifmgd->csa_connection_drop_work); &ifmgd->csa_connection_drop_work);
goto out; goto out;
} }
if (!local->use_chanctx) {
local->_oper_chandef = sdata->csa_chandef;
/* Call "hw_config" only if doing sw channel switch.
* Otherwise update the channel directly
*/
if (!local->ops->channel_switch)
ieee80211_hw_config(local, 0);
else
local->hw.conf.chandef = local->_oper_chandef;
}
/* 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; sdata->vif.csa_active = false;
/* XXX: wait for a beacon first? */ /* XXX: wait for a beacon first? */
if (sdata->csa_block_tx) { if (sdata->csa_block_tx) {
ieee80211_wake_vif_queues(local, sdata, ieee80211_wake_vif_queues(local, sdata,
IEEE80211_QUEUE_STOP_REASON_CSA); IEEE80211_QUEUE_STOP_REASON_CSA);
sdata->csa_block_tx = false; sdata->csa_block_tx = false;
} }
mutex_unlock(&local->mtx);
ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
...@@ -993,6 +1011,8 @@ static void ieee80211_chswitch_work(struct work_struct *work) ...@@ -993,6 +1011,8 @@ static void ieee80211_chswitch_work(struct work_struct *work)
ieee80211_sta_reset_conn_monitor(sdata); ieee80211_sta_reset_conn_monitor(sdata);
out: out:
mutex_unlock(&local->chanctx_mtx);
mutex_unlock(&local->mtx);
sdata_unlock(sdata); sdata_unlock(sdata);
} }
...@@ -1029,6 +1049,7 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, ...@@ -1029,6 +1049,7 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
struct ieee80211_local *local = sdata->local; struct ieee80211_local *local = sdata->local;
struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
struct cfg80211_bss *cbss = ifmgd->associated; struct cfg80211_bss *cbss = ifmgd->associated;
struct ieee80211_chanctx_conf *conf;
struct ieee80211_chanctx *chanctx; struct ieee80211_chanctx *chanctx;
enum ieee80211_band current_band; enum ieee80211_band current_band;
struct ieee80211_csa_ie csa_ie; struct ieee80211_csa_ie csa_ie;
...@@ -1072,7 +1093,22 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, ...@@ -1072,7 +1093,22 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED; ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
mutex_lock(&local->mtx);
mutex_lock(&local->chanctx_mtx); mutex_lock(&local->chanctx_mtx);
conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
lockdep_is_held(&local->chanctx_mtx));
if (!conf) {
sdata_info(sdata,
"no channel context assigned to vif?, disconnecting\n");
ieee80211_queue_work(&local->hw,
&ifmgd->csa_connection_drop_work);
mutex_unlock(&local->chanctx_mtx);
mutex_unlock(&local->mtx);
return;
}
chanctx = container_of(conf, struct ieee80211_chanctx, conf);
if (local->use_chanctx) { if (local->use_chanctx) {
u32 num_chanctx = 0; u32 num_chanctx = 0;
list_for_each_entry(chanctx, &local->chanctx_list, list) list_for_each_entry(chanctx, &local->chanctx_list, list)
...@@ -1085,32 +1121,27 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, ...@@ -1085,32 +1121,27 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
ieee80211_queue_work(&local->hw, ieee80211_queue_work(&local->hw,
&ifmgd->csa_connection_drop_work); &ifmgd->csa_connection_drop_work);
mutex_unlock(&local->chanctx_mtx); mutex_unlock(&local->chanctx_mtx);
mutex_unlock(&local->mtx);
return; return;
} }
} }
if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) { res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
ieee80211_queue_work(&local->hw, chanctx->mode, false);
&ifmgd->csa_connection_drop_work); if (res) {
mutex_unlock(&local->chanctx_mtx);
return;
}
chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
struct ieee80211_chanctx, conf);
if (ieee80211_chanctx_refcount(local, chanctx) > 1) {
sdata_info(sdata, sdata_info(sdata,
"channel switch with multiple interfaces on the same channel, disconnecting\n"); "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
res);
ieee80211_queue_work(&local->hw, ieee80211_queue_work(&local->hw,
&ifmgd->csa_connection_drop_work); &ifmgd->csa_connection_drop_work);
mutex_unlock(&local->chanctx_mtx); mutex_unlock(&local->chanctx_mtx);
mutex_unlock(&local->mtx);
return; return;
} }
mutex_unlock(&local->chanctx_mtx); mutex_unlock(&local->chanctx_mtx);
sdata->csa_chandef = csa_ie.chandef;
mutex_lock(&local->mtx);
sdata->vif.csa_active = true; sdata->vif.csa_active = true;
sdata->csa_chandef = csa_ie.chandef;
sdata->csa_block_tx = csa_ie.mode; sdata->csa_block_tx = csa_ie.mode;
if (sdata->csa_block_tx) if (sdata->csa_block_tx)
......
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