pm.c 5.9 KB
Newer Older
1 2 3 4
#include <net/mac80211.h>
#include <net/rtnetlink.h>

#include "ieee80211_i.h"
5
#include "mesh.h"
6
#include "driver-ops.h"
7 8
#include "led.h"

9
/* return value indicates whether the driver should be further notified */
10
static void ieee80211_quiesce(struct ieee80211_sub_if_data *sdata)
11 12 13 14
{
	switch (sdata->vif.type) {
	case NL80211_IFTYPE_STATION:
		ieee80211_sta_quiesce(sdata);
15
		break;
16 17
	case NL80211_IFTYPE_ADHOC:
		ieee80211_ibss_quiesce(sdata);
18
		break;
19 20
	case NL80211_IFTYPE_MESH_POINT:
		ieee80211_mesh_quiesce(sdata);
21
		break;
22
	default:
23
		break;
24
	}
25 26

	cancel_work_sync(&sdata->work);
27 28
}

29
int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
30 31 32 33
{
	struct ieee80211_local *local = hw_to_local(hw);
	struct ieee80211_sub_if_data *sdata;
	struct sta_info *sta;
34
	struct ieee80211_chanctx *ctx;
35

36 37 38
	if (!local->open_count)
		goto suspend;

39
	ieee80211_scan_cancel(local);
40

41 42
	ieee80211_dfs_cac_cancel(local);

43 44 45
	if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
		mutex_lock(&local->sta_mtx);
		list_for_each_entry(sta, &local->sta_list, list) {
J
Johannes Berg 已提交
46
			set_sta_flag(sta, WLAN_STA_BLOCK_BA);
47 48
			ieee80211_sta_tear_down_BA_sessions(
					sta, AGG_STOP_LOCAL_REQUEST);
49 50 51 52
		}
		mutex_unlock(&local->sta_mtx);
	}

53 54 55
	ieee80211_stop_queues_by_reason(hw,
			IEEE80211_QUEUE_STOP_REASON_SUSPEND);

56 57 58
	/* flush out all packets */
	synchronize_net();

59 60
	drv_flush(local, false);

61 62 63 64
	local->quiescing = true;
	/* make quiescing visible to timers everywhere */
	mb();

65
	flush_workqueue(local->workqueue);
66

67 68 69 70 71 72 73 74 75 76
	/* Don't try to run timers while suspended. */
	del_timer_sync(&local->sta_cleanup);

	 /*
	 * Note that this particular timer doesn't need to be
	 * restarted at resume.
	 */
	cancel_work_sync(&local->dynamic_ps_enable_work);
	del_timer_sync(&local->dynamic_ps_timer);

77 78 79
	local->wowlan = wowlan && local->open_count;
	if (local->wowlan) {
		int err = drv_suspend(local, wowlan);
80
		if (err < 0) {
81
			local->quiescing = false;
82
			local->wowlan = false;
83 84 85 86 87 88 89 90 91 92
			if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
				mutex_lock(&local->sta_mtx);
				list_for_each_entry(sta,
						    &local->sta_list, list) {
					clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
				}
				mutex_unlock(&local->sta_mtx);
			}
			ieee80211_wake_queues_by_reason(hw,
					IEEE80211_QUEUE_STOP_REASON_SUSPEND);
93
			return err;
94 95 96 97
		} else if (err > 0) {
			WARN_ON(err != 1);
			local->wowlan = false;
		} else {
98 99 100
			list_for_each_entry(sdata, &local->interfaces, list)
				if (ieee80211_sdata_running(sdata))
					ieee80211_quiesce(sdata);
101
			goto suspend;
102 103 104
		}
	}

105 106 107 108
	/* disable keys */
	list_for_each_entry(sdata, &local->interfaces, list)
		ieee80211_disable_keys(sdata);

109 110 111
	/* tear down aggregation sessions and remove STAs */
	mutex_lock(&local->sta_mtx);
	list_for_each_entry(sta, &local->sta_list, list) {
J
Johannes Berg 已提交
112 113 114 115 116
		if (sta->uploaded) {
			enum ieee80211_sta_state state;

			state = sta->sta_state;
			for (; state > IEEE80211_STA_NOTEXIST; state--)
117
				WARN_ON(drv_sta_state(local, sta->sdata, sta,
J
Johannes Berg 已提交
118 119 120
						      state, state - 1));
		}

121
		mesh_plink_quiesce(sta);
122
	}
123
	mutex_unlock(&local->sta_mtx);
124 125 126

	/* remove all interfaces */
	list_for_each_entry(sdata, &local->interfaces, list) {
127
		static u8 zero_addr[ETH_ALEN] = {};
128
		u32 changed = 0;
129

130
		if (!ieee80211_sdata_running(sdata))
131
			continue;
132

133 134 135 136
		switch (sdata->vif.type) {
		case NL80211_IFTYPE_AP_VLAN:
		case NL80211_IFTYPE_MONITOR:
			/* skip these */
137
			continue;
138 139 140 141 142
		case NL80211_IFTYPE_STATION:
			if (sdata->vif.bss_conf.assoc)
				changed = BSS_CHANGED_ASSOC |
					  BSS_CHANGED_BSSID |
					  BSS_CHANGED_IDLE;
143 144 145 146 147 148 149
			break;
		case NL80211_IFTYPE_AP:
		case NL80211_IFTYPE_ADHOC:
		case NL80211_IFTYPE_MESH_POINT:
			if (sdata->vif.bss_conf.enable_beacon)
				changed = BSS_CHANGED_BEACON_ENABLED;
			break;
150 151 152
		default:
			break;
		}
153

154 155
		ieee80211_quiesce(sdata);

156 157 158
		sdata->suspend_bss_conf = sdata->vif.bss_conf;
		memset(&sdata->vif.bss_conf, 0, sizeof(sdata->vif.bss_conf));
		sdata->vif.bss_conf.idle = true;
159 160
		if (sdata->suspend_bss_conf.bssid)
			sdata->vif.bss_conf.bssid = zero_addr;
161 162 163

		/* disable beaconing or remove association */
		ieee80211_bss_info_change_notify(sdata, changed);
164

165 166 167 168
		if (sdata->vif.type == NL80211_IFTYPE_AP &&
		    rcu_access_pointer(sdata->u.ap.beacon))
			drv_stop_ap(local, sdata);

169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
		if (local->use_chanctx) {
			struct ieee80211_chanctx_conf *conf;

			mutex_lock(&local->chanctx_mtx);
			conf = rcu_dereference_protected(
					sdata->vif.chanctx_conf,
					lockdep_is_held(&local->chanctx_mtx));
			if (conf) {
				ctx = container_of(conf,
						   struct ieee80211_chanctx,
						   conf);
				drv_unassign_vif_chanctx(local, sdata, ctx);
			}

			mutex_unlock(&local->chanctx_mtx);
		}
185
		drv_remove_interface(local, sdata);
186
	}
187

188
	sdata = rtnl_dereference(local->monitor_sdata);
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
	if (sdata) {
		if (local->use_chanctx) {
			struct ieee80211_chanctx_conf *conf;

			mutex_lock(&local->chanctx_mtx);
			conf = rcu_dereference_protected(
					sdata->vif.chanctx_conf,
					lockdep_is_held(&local->chanctx_mtx));
			if (conf) {
				ctx = container_of(conf,
						   struct ieee80211_chanctx,
						   conf);
				drv_unassign_vif_chanctx(local, sdata, ctx);
			}

			mutex_unlock(&local->chanctx_mtx);
		}

207
		drv_remove_interface(local, sdata);
208 209 210 211 212 213
	}

	mutex_lock(&local->chanctx_mtx);
	list_for_each_entry(ctx, &local->chanctx_list, list)
		drv_remove_chanctx(local, ctx);
	mutex_unlock(&local->chanctx_mtx);
214

J
Johannes Berg 已提交
215
	/* stop hardware - this must stop RX */
216 217
	if (local->open_count)
		ieee80211_stop_device(local);
J
Johannes Berg 已提交
218

219
 suspend:
220
	local->suspended = true;
J
Johannes Berg 已提交
221 222
	/* need suspended to be visible before quiescing is false */
	barrier();
223 224
	local->quiescing = false;

225 226 227
	return 0;
}

228 229 230 231 232
/*
 * __ieee80211_resume() is a static inline which just calls
 * ieee80211_reconfig(), which is also needed for hardware
 * hang/firmware failure/etc. recovery.
 */
233 234 235 236 237 238 239 240 241 242

void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
				    struct cfg80211_wowlan_wakeup *wakeup,
				    gfp_t gfp)
{
	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);

	cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
}
EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);