Skip to content

Commit

Permalink
mac80211: handle failed restart/resume better
Browse files Browse the repository at this point in the history
When the driver fails during HW restart or resume, the whole
stack goes into a very confused state with interfaces being
up while the hardware is down etc.

Address this by shutting down everything; we'll run into a
lot of warnings in the process but that's better than having
the whole stack get messed up.

Reviewed-by: Arik Nemtsov <arik@wizery.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  • Loading branch information
Johannes Berg committed May 9, 2014
1 parent f29f58a commit f6837ba
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 51 deletions.
14 changes: 14 additions & 0 deletions include/net/cfg80211.h
Original file line number Diff line number Diff line change
Expand Up @@ -4771,6 +4771,20 @@ int cfg80211_iter_combinations(struct wiphy *wiphy,
void cfg80211_stop_iface(struct wiphy *wiphy, struct wireless_dev *wdev,
gfp_t gfp);

/**
* cfg80211_shutdown_all_interfaces - shut down all interfaces for a wiphy
* @wiphy: the wiphy to shut down
*
* This function shuts down all interfaces belonging to this wiphy by
* calling dev_close() (and treating non-netdev interfaces as needed).
* It shouldn't really be used unless there are some fatal device errors
* that really can't be recovered in any other way.
*
* Callers must hold the RTNL and be able to deal with callbacks into
* the driver while the function is running.
*/
void cfg80211_shutdown_all_interfaces(struct wiphy *wiphy);

/* Logging, debugging and troubleshooting/diagnostic helpers. */

/* wiphy_printk helpers, similar to dev_printk */
Expand Down
108 changes: 71 additions & 37 deletions net/mac80211/driver-ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#include "ieee80211_i.h"
#include "trace.h"

static inline void check_sdata_in_driver(struct ieee80211_sub_if_data *sdata)
static inline bool check_sdata_in_driver(struct ieee80211_sub_if_data *sdata)
{
WARN(!(sdata->flags & IEEE80211_SDATA_IN_DRIVER),
"%s: Failed check-sdata-in-driver check, flags: 0x%x\n",
sdata->dev ? sdata->dev->name : sdata->name, sdata->flags);
return !WARN(!(sdata->flags & IEEE80211_SDATA_IN_DRIVER),
"%s: Failed check-sdata-in-driver check, flags: 0x%x\n",
sdata->dev ? sdata->dev->name : sdata->name, sdata->flags);
}

static inline struct ieee80211_sub_if_data *
Expand Down Expand Up @@ -168,7 +168,8 @@ static inline int drv_change_interface(struct ieee80211_local *local,

might_sleep();

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return -EIO;

trace_drv_change_interface(local, sdata, type, p2p);
ret = local->ops->change_interface(&local->hw, &sdata->vif, type, p2p);
Expand All @@ -181,7 +182,8 @@ static inline void drv_remove_interface(struct ieee80211_local *local,
{
might_sleep();

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

trace_drv_remove_interface(local, sdata);
local->ops->remove_interface(&local->hw, &sdata->vif);
Expand Down Expand Up @@ -219,7 +221,8 @@ static inline void drv_bss_info_changed(struct ieee80211_local *local,
sdata->vif.type == NL80211_IFTYPE_MONITOR))
return;

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

trace_drv_bss_info_changed(local, sdata, info, changed);
if (local->ops->bss_info_changed)
Expand Down Expand Up @@ -278,7 +281,8 @@ static inline int drv_set_key(struct ieee80211_local *local,
might_sleep();

sdata = get_bss_sdata(sdata);
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return -EIO;

trace_drv_set_key(local, cmd, sdata, sta, key);
ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
Expand All @@ -298,7 +302,8 @@ static inline void drv_update_tkip_key(struct ieee80211_local *local,
ista = &sta->sta;

sdata = get_bss_sdata(sdata);
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

trace_drv_update_tkip_key(local, sdata, conf, ista, iv32);
if (local->ops->update_tkip_key)
Expand All @@ -315,7 +320,8 @@ static inline int drv_hw_scan(struct ieee80211_local *local,

might_sleep();

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return -EIO;

trace_drv_hw_scan(local, sdata);
ret = local->ops->hw_scan(&local->hw, &sdata->vif, req);
Expand All @@ -328,7 +334,8 @@ static inline void drv_cancel_hw_scan(struct ieee80211_local *local,
{
might_sleep();

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

trace_drv_cancel_hw_scan(local, sdata);
local->ops->cancel_hw_scan(&local->hw, &sdata->vif);
Expand All @@ -345,7 +352,8 @@ drv_sched_scan_start(struct ieee80211_local *local,

might_sleep();

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return -EIO;

trace_drv_sched_scan_start(local, sdata);
ret = local->ops->sched_scan_start(&local->hw, &sdata->vif,
Expand All @@ -361,7 +369,8 @@ static inline int drv_sched_scan_stop(struct ieee80211_local *local,

might_sleep();

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return -EIO;

trace_drv_sched_scan_stop(local, sdata);
ret = local->ops->sched_scan_stop(&local->hw, &sdata->vif);
Expand Down Expand Up @@ -462,7 +471,8 @@ static inline void drv_sta_notify(struct ieee80211_local *local,
struct ieee80211_sta *sta)
{
sdata = get_bss_sdata(sdata);
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

trace_drv_sta_notify(local, sdata, cmd, sta);
if (local->ops->sta_notify)
Expand All @@ -479,7 +489,8 @@ static inline int drv_sta_add(struct ieee80211_local *local,
might_sleep();

sdata = get_bss_sdata(sdata);
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return -EIO;

trace_drv_sta_add(local, sdata, sta);
if (local->ops->sta_add)
Expand All @@ -497,7 +508,8 @@ static inline void drv_sta_remove(struct ieee80211_local *local,
might_sleep();

sdata = get_bss_sdata(sdata);
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

trace_drv_sta_remove(local, sdata, sta);
if (local->ops->sta_remove)
Expand All @@ -515,7 +527,8 @@ static inline void drv_sta_add_debugfs(struct ieee80211_local *local,
might_sleep();

sdata = get_bss_sdata(sdata);
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

if (local->ops->sta_add_debugfs)
local->ops->sta_add_debugfs(&local->hw, &sdata->vif,
Expand Down Expand Up @@ -545,7 +558,8 @@ static inline void drv_sta_pre_rcu_remove(struct ieee80211_local *local,
might_sleep();

sdata = get_bss_sdata(sdata);
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

trace_drv_sta_pre_rcu_remove(local, sdata, &sta->sta);
if (local->ops->sta_pre_rcu_remove)
Expand All @@ -566,7 +580,8 @@ int drv_sta_state(struct ieee80211_local *local,
might_sleep();

sdata = get_bss_sdata(sdata);
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return -EIO;

trace_drv_sta_state(local, sdata, &sta->sta, old_state, new_state);
if (local->ops->sta_state) {
Expand All @@ -590,7 +605,8 @@ static inline void drv_sta_rc_update(struct ieee80211_local *local,
struct ieee80211_sta *sta, u32 changed)
{
sdata = get_bss_sdata(sdata);
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

WARN_ON(changed & IEEE80211_RC_SUPP_RATES_CHANGED &&
(sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Expand All @@ -612,7 +628,8 @@ static inline int drv_conf_tx(struct ieee80211_local *local,

might_sleep();

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return -EIO;

trace_drv_conf_tx(local, sdata, ac, params);
if (local->ops->conf_tx)
Expand All @@ -629,7 +646,8 @@ static inline u64 drv_get_tsf(struct ieee80211_local *local,

might_sleep();

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return ret;

trace_drv_get_tsf(local, sdata);
if (local->ops->get_tsf)
Expand All @@ -644,7 +662,8 @@ static inline void drv_set_tsf(struct ieee80211_local *local,
{
might_sleep();

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

trace_drv_set_tsf(local, sdata, tsf);
if (local->ops->set_tsf)
Expand All @@ -657,7 +676,8 @@ static inline void drv_reset_tsf(struct ieee80211_local *local,
{
might_sleep();

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

trace_drv_reset_tsf(local, sdata);
if (local->ops->reset_tsf)
Expand Down Expand Up @@ -689,7 +709,8 @@ static inline int drv_ampdu_action(struct ieee80211_local *local,
might_sleep();

sdata = get_bss_sdata(sdata);
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return -EIO;

trace_drv_ampdu_action(local, sdata, action, sta, tid, ssn, buf_size);

Expand Down Expand Up @@ -733,8 +754,8 @@ static inline void drv_flush(struct ieee80211_local *local,

might_sleep();

if (sdata)
check_sdata_in_driver(sdata);
if (sdata && !check_sdata_in_driver(sdata))
return;

trace_drv_flush(local, queues, drop);
if (local->ops->flush)
Expand Down Expand Up @@ -854,7 +875,8 @@ static inline int drv_set_bitrate_mask(struct ieee80211_local *local,

might_sleep();

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return -EIO;

trace_drv_set_bitrate_mask(local, sdata, mask);
if (local->ops->set_bitrate_mask)
Expand All @@ -869,7 +891,8 @@ static inline void drv_set_rekey_data(struct ieee80211_local *local,
struct ieee80211_sub_if_data *sdata,
struct cfg80211_gtk_rekey_data *data)
{
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

trace_drv_set_rekey_data(local, sdata, data);
if (local->ops->set_rekey_data)
Expand Down Expand Up @@ -937,7 +960,8 @@ static inline void drv_mgd_prepare_tx(struct ieee80211_local *local,
{
might_sleep();

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;
WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION);

trace_drv_mgd_prepare_tx(local, sdata);
Expand All @@ -964,6 +988,9 @@ static inline int drv_add_chanctx(struct ieee80211_local *local,
static inline void drv_remove_chanctx(struct ieee80211_local *local,
struct ieee80211_chanctx *ctx)
{
if (WARN_ON(!ctx->driver_present))
return;

trace_drv_remove_chanctx(local, ctx);
if (local->ops->remove_chanctx)
local->ops->remove_chanctx(&local->hw, &ctx->conf);
Expand All @@ -989,7 +1016,8 @@ static inline int drv_assign_vif_chanctx(struct ieee80211_local *local,
{
int ret = 0;

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return -EIO;

trace_drv_assign_vif_chanctx(local, sdata, ctx);
if (local->ops->assign_vif_chanctx) {
Expand All @@ -1007,7 +1035,8 @@ static inline void drv_unassign_vif_chanctx(struct ieee80211_local *local,
struct ieee80211_sub_if_data *sdata,
struct ieee80211_chanctx *ctx)
{
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

trace_drv_unassign_vif_chanctx(local, sdata, ctx);
if (local->ops->unassign_vif_chanctx) {
Expand All @@ -1024,7 +1053,8 @@ static inline int drv_start_ap(struct ieee80211_local *local,
{
int ret = 0;

check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return -EIO;

trace_drv_start_ap(local, sdata, &sdata->vif.bss_conf);
if (local->ops->start_ap)
Expand All @@ -1036,7 +1066,8 @@ static inline int drv_start_ap(struct ieee80211_local *local,
static inline void drv_stop_ap(struct ieee80211_local *local,
struct ieee80211_sub_if_data *sdata)
{
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

trace_drv_stop_ap(local, sdata);
if (local->ops->stop_ap)
Expand All @@ -1059,7 +1090,8 @@ drv_set_default_unicast_key(struct ieee80211_local *local,
struct ieee80211_sub_if_data *sdata,
int key_idx)
{
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

WARN_ON_ONCE(key_idx < -1 || key_idx > 3);

Expand Down Expand Up @@ -1101,7 +1133,8 @@ static inline int drv_join_ibss(struct ieee80211_local *local,
int ret = 0;

might_sleep();
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return -EIO;

trace_drv_join_ibss(local, sdata, &sdata->vif.bss_conf);
if (local->ops->join_ibss)
Expand All @@ -1114,7 +1147,8 @@ static inline void drv_leave_ibss(struct ieee80211_local *local,
struct ieee80211_sub_if_data *sdata)
{
might_sleep();
check_sdata_in_driver(sdata);
if (!check_sdata_in_driver(sdata))
return;

trace_drv_leave_ibss(local, sdata);
if (local->ops->leave_ibss)
Expand Down
1 change: 1 addition & 0 deletions net/mac80211/ieee80211_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,7 @@ __ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
int ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
struct cfg80211_sched_scan_request *req);
int ieee80211_request_sched_scan_stop(struct ieee80211_sub_if_data *sdata);
void ieee80211_sched_scan_end(struct ieee80211_local *local);
void ieee80211_sched_scan_stopped_work(struct work_struct *work);

/* off-channel helpers */
Expand Down
Loading

0 comments on commit f6837ba

Please sign in to comment.