mac80211: use chanctx reservation for AP CSA

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

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

Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Michal Kazior 2014-06-25 12:35:08 +02:00 committed by Johannes Berg
parent 71e6195ed2
commit 03078de4f9
2 changed files with 96 additions and 37 deletions

View File

@ -2792,17 +2792,35 @@ static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
sdata_assert_lock(sdata); sdata_assert_lock(sdata);
lockdep_assert_held(&local->mtx); lockdep_assert_held(&local->mtx);
lockdep_assert_held(&local->chanctx_mtx);
sdata->radar_required = sdata->csa_radar_required; /*
err = ieee80211_vif_change_channel(sdata, &changed); * using reservation isn't immediate as it may be deferred until later
if (err < 0) * with multi-vif. once reservation is complete it will re-schedule the
return err; * work with no reserved_chanctx so verify chandef to check if it
* completed successfully
*/
if (!local->use_chanctx) { if (sdata->reserved_chanctx) {
local->_oper_chandef = sdata->csa_chandef; /*
ieee80211_hw_config(local, 0); * 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)
return 0;
err = ieee80211_vif_use_reserved_context(sdata);
if (err)
return err;
return 0;
} }
if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
&sdata->csa_chandef))
return -EINVAL;
sdata->vif.csa_active = false; sdata->vif.csa_active = false;
err = ieee80211_set_after_csa_beacon(sdata, &changed); err = ieee80211_set_after_csa_beacon(sdata, &changed);
@ -2839,6 +2857,7 @@ void ieee80211_csa_finalize_work(struct work_struct *work)
sdata_lock(sdata); sdata_lock(sdata);
mutex_lock(&local->mtx); mutex_lock(&local->mtx);
mutex_lock(&local->chanctx_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)
@ -2850,6 +2869,7 @@ void ieee80211_csa_finalize_work(struct work_struct *work)
ieee80211_csa_finalize(sdata); ieee80211_csa_finalize(sdata);
unlock: unlock:
mutex_unlock(&local->chanctx_mtx);
mutex_unlock(&local->mtx); mutex_unlock(&local->mtx);
sdata_unlock(sdata); sdata_unlock(sdata);
} }
@ -2995,7 +3015,7 @@ __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
struct ieee80211_local *local = sdata->local; struct ieee80211_local *local = sdata->local;
struct ieee80211_chanctx_conf *conf; struct ieee80211_chanctx_conf *conf;
struct ieee80211_chanctx *chanctx; struct ieee80211_chanctx *chanctx;
int err, num_chanctx, changed = 0; int err, changed = 0;
sdata_assert_lock(sdata); sdata_assert_lock(sdata);
lockdep_assert_held(&local->mtx); lockdep_assert_held(&local->mtx);
@ -3010,37 +3030,43 @@ __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
&sdata->vif.bss_conf.chandef)) &sdata->vif.bss_conf.chandef))
return -EINVAL; return -EINVAL;
mutex_lock(&local->chanctx_mtx);
conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
lockdep_is_held(&local->chanctx_mtx));
if (!conf) {
mutex_unlock(&local->chanctx_mtx);
return -EBUSY;
}
/* don't handle for multi-VIF cases */
chanctx = container_of(conf, struct ieee80211_chanctx, conf);
if (ieee80211_chanctx_refcount(local, chanctx) > 1) {
mutex_unlock(&local->chanctx_mtx);
return -EBUSY;
}
num_chanctx = 0;
list_for_each_entry_rcu(chanctx, &local->chanctx_list, list)
num_chanctx++;
mutex_unlock(&local->chanctx_mtx);
if (num_chanctx > 1)
return -EBUSY;
/* don't allow another channel switch if one is already active. */ /* don't allow another channel switch if one is already active. */
if (sdata->vif.csa_active) if (sdata->vif.csa_active)
return -EBUSY; return -EBUSY;
err = ieee80211_set_csa_beacon(sdata, params, &changed); mutex_lock(&local->chanctx_mtx);
if (err) conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
return err; lockdep_is_held(&local->chanctx_mtx));
if (!conf) {
err = -EBUSY;
goto out;
}
chanctx = container_of(conf, struct ieee80211_chanctx, conf);
if (!chanctx) {
err = -EBUSY;
goto out;
}
err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
chanctx->mode,
params->radar_required);
if (err)
goto out;
/* if reservation is invalid then this will fail */
err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
if (err) {
ieee80211_vif_unreserve_chanctx(sdata);
goto out;
}
err = ieee80211_set_csa_beacon(sdata, params, &changed);
if (err) {
ieee80211_vif_unreserve_chanctx(sdata);
goto out;
}
sdata->csa_radar_required = params->radar_required;
sdata->csa_chandef = params->chandef; sdata->csa_chandef = params->chandef;
sdata->csa_block_tx = params->block_tx; sdata->csa_block_tx = params->block_tx;
sdata->vif.csa_active = true; sdata->vif.csa_active = true;
@ -3057,7 +3083,9 @@ __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
ieee80211_csa_finalize(sdata); ieee80211_csa_finalize(sdata);
} }
return 0; out:
mutex_unlock(&local->chanctx_mtx);
return err;
} }
int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,

View File

@ -1056,6 +1056,30 @@ int ieee80211_vif_reserve_chanctx(struct ieee80211_sub_if_data *sdata,
return 0; return 0;
} }
static void
ieee80211_vif_chanctx_reservation_complete(struct ieee80211_sub_if_data *sdata)
{
switch (sdata->vif.type) {
case NL80211_IFTYPE_ADHOC:
case NL80211_IFTYPE_AP:
case NL80211_IFTYPE_MESH_POINT:
ieee80211_queue_work(&sdata->local->hw,
&sdata->csa_finalize_work);
break;
case NL80211_IFTYPE_UNSPECIFIED:
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_AP_VLAN:
case NL80211_IFTYPE_WDS:
case NL80211_IFTYPE_MONITOR:
case NL80211_IFTYPE_P2P_CLIENT:
case NL80211_IFTYPE_P2P_GO:
case NL80211_IFTYPE_P2P_DEVICE:
case NUM_NL80211_IFTYPES:
WARN_ON(1);
break;
}
}
static int static int
ieee80211_vif_use_reserved_reassign(struct ieee80211_sub_if_data *sdata) ieee80211_vif_use_reserved_reassign(struct ieee80211_sub_if_data *sdata)
{ {
@ -1103,7 +1127,7 @@ ieee80211_vif_use_reserved_reassign(struct ieee80211_sub_if_data *sdata)
if (ieee80211_chanctx_refcount(local, new_ctx) == 0) if (ieee80211_chanctx_refcount(local, new_ctx) == 0)
ieee80211_free_chanctx(local, new_ctx); ieee80211_free_chanctx(local, new_ctx);
return err; goto out;
} }
list_move(&sdata->assigned_chanctx_list, &new_ctx->assigned_vifs); list_move(&sdata->assigned_chanctx_list, &new_ctx->assigned_vifs);
@ -1123,6 +1147,8 @@ ieee80211_vif_use_reserved_reassign(struct ieee80211_sub_if_data *sdata)
if (changed) if (changed)
ieee80211_bss_info_change_notify(sdata, changed); ieee80211_bss_info_change_notify(sdata, changed);
out:
ieee80211_vif_chanctx_reservation_complete(sdata);
return err; return err;
} }
@ -1167,6 +1193,7 @@ ieee80211_vif_use_reserved_assign(struct ieee80211_sub_if_data *sdata)
} }
out: out:
ieee80211_vif_chanctx_reservation_complete(sdata);
return err; return err;
} }
@ -1480,6 +1507,8 @@ ieee80211_vif_use_reserved_switch(struct ieee80211_local *local)
list_move(&sdata->assigned_chanctx_list, list_move(&sdata->assigned_chanctx_list,
&new_ctx->assigned_vifs); &new_ctx->assigned_vifs);
sdata->reserved_chanctx = NULL; sdata->reserved_chanctx = NULL;
ieee80211_vif_chanctx_reservation_complete(sdata);
} }
/* /*
@ -1543,8 +1572,10 @@ err:
continue; continue;
list_for_each_entry_safe(sdata, sdata_tmp, &ctx->reserved_vifs, list_for_each_entry_safe(sdata, sdata_tmp, &ctx->reserved_vifs,
reserved_chanctx_list) reserved_chanctx_list) {
ieee80211_vif_unreserve_chanctx(sdata); ieee80211_vif_unreserve_chanctx(sdata);
ieee80211_vif_chanctx_reservation_complete(sdata);
}
} }
return err; return err;