Blame view

net/mac80211/pm.c 5.48 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  // SPDX-License-Identifier: GPL-2.0
665af4fc8   Bob Copeland   mac80211: add sus...
2
3
4
5
  #include <net/mac80211.h>
  #include <net/rtnetlink.h>
  
  #include "ieee80211_i.h"
5bb644a0f   Johannes Berg   mac80211: cancel/...
6
  #include "mesh.h"
244879813   Johannes Berg   mac80211: add dri...
7
  #include "driver-ops.h"
665af4fc8   Bob Copeland   mac80211: add sus...
8
  #include "led.h"
0d440ea29   Eliad Peller   mac80211: don't r...
9
10
11
12
  static void ieee80211_sched_scan_cancel(struct ieee80211_local *local)
  {
  	if (ieee80211_request_sched_scan_stop(local))
  		return;
b34939b98   Arend Van Spriel   cfg80211: add req...
13
  	cfg80211_sched_scan_stopped_rtnl(local->hw.wiphy, 0);
0d440ea29   Eliad Peller   mac80211: don't r...
14
  }
eecc48000   Johannes Berg   mac80211: add bas...
15
  int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
665af4fc8   Bob Copeland   mac80211: add sus...
16
17
18
  {
  	struct ieee80211_local *local = hw_to_local(hw);
  	struct ieee80211_sub_if_data *sdata;
665af4fc8   Bob Copeland   mac80211: add sus...
19
  	struct sta_info *sta;
94f9b97be   Johannes Berg   mac80211: be more...
20
21
  	if (!local->open_count)
  		goto suspend;
4136c4224   Stanislaw Gruszka   mac80211: assure ...
22
  	ieee80211_scan_cancel(local);
5bb644a0f   Johannes Berg   mac80211: cancel/...
23

164eb02d0   Simon Wunderlich   mac80211: add rad...
24
  	ieee80211_dfs_cac_cancel(local);
c8f994eec   Johannes Berg   mac80211: purge r...
25
  	ieee80211_roc_purge(local, NULL);
3c3e21e74   Johannes Berg   mac80211: destroy...
26
  	ieee80211_del_virtual_monitor(local);
273927195   Eliad Peller   mac80211: don't t...
27
28
  	if (ieee80211_hw_check(hw, AMPDU_AGGREGATION) &&
  	    !(wowlan && wowlan->any)) {
ca45de77a   Johannes Berg   mac80211: tear do...
29
30
  		mutex_lock(&local->sta_mtx);
  		list_for_each_entry(sta, &local->sta_list, list) {
c2c98fdeb   Johannes Berg   mac80211: optimis...
31
  			set_sta_flag(sta, WLAN_STA_BLOCK_BA);
c82c4a80b   Johannes Berg   mac80211: split a...
32
33
  			ieee80211_sta_tear_down_BA_sessions(
  					sta, AGG_STOP_LOCAL_REQUEST);
ca45de77a   Johannes Berg   mac80211: tear do...
34
35
36
  		}
  		mutex_unlock(&local->sta_mtx);
  	}
0d440ea29   Eliad Peller   mac80211: don't r...
37
38
39
  	/* keep sched_scan only in case of 'any' trigger */
  	if (!(wowlan && wowlan->any))
  		ieee80211_sched_scan_cancel(local);
25420604c   Johannes Berg   mac80211: stop qu...
40
  	ieee80211_stop_queues_by_reason(hw,
445ea4e83   Johannes Berg   mac80211: stop qu...
41
  					IEEE80211_MAX_QUEUE_MAP,
cca07b00a   Luciano Coelho   mac80211: introdu...
42
43
  					IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  					false);
25420604c   Johannes Berg   mac80211: stop qu...
44

d34ba2168   Johannes Berg   mac80211: don't d...
45
  	/* flush out all packets */
8ceb59557   Bob Copeland   mac80211: use syn...
46
  	synchronize_net();
5bb644a0f   Johannes Berg   mac80211: cancel/...
47

3b24f4c65   Emmanuel Grumbach   mac80211: let flu...
48
  	ieee80211_flush_queues(local, NULL, true);
ca45de77a   Johannes Berg   mac80211: tear do...
49

5bb644a0f   Johannes Berg   mac80211: cancel/...
50
51
52
  	local->quiescing = true;
  	/* make quiescing visible to timers everywhere */
  	mb();
42935ecaf   Luis R. Rodriguez   mac80211: redefin...
53
  	flush_workqueue(local->workqueue);
665af4fc8   Bob Copeland   mac80211: add sus...
54

5bb644a0f   Johannes Berg   mac80211: cancel/...
55
56
57
58
59
60
61
62
63
  	/* 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);
8bb6f4b9c   Luciano Coelho   mac80211: remove ...
64
  	local->wowlan = wowlan;
eecc48000   Johannes Berg   mac80211: add bas...
65
  	if (local->wowlan) {
ef7c67257   Johannes Berg   mac80211: don't d...
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  		int err;
  
  		/* Drivers don't expect to suspend while some operations like
  		 * authenticating or associating are in progress. It doesn't
  		 * make sense anyway to accept that, since the authentication
  		 * or association would never finish since the driver can't do
  		 * that on its own.
  		 * Thus, clean up in-progress auth/assoc first.
  		 */
  		list_for_each_entry(sdata, &local->interfaces, list) {
  			if (!ieee80211_sdata_running(sdata))
  				continue;
  			if (sdata->vif.type != NL80211_IFTYPE_STATION)
  				continue;
  			ieee80211_mgd_quiesce(sdata);
541b6ed7c   Chaitanya T K   mac80211: wowlan:...
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  			/* If suspended during TX in progress, and wowlan
  			 * is enabled (connection will be active) there
  			 * can be a race where the driver is put out
  			 * of power-save due to TX and during suspend
  			 * dynamic_ps_timer is cancelled and TX packet
  			 * is flushed, leaving the driver in ACTIVE even
  			 * after resuming until dynamic_ps_timer puts
  			 * driver back in DOZE.
  			 */
  			if (sdata->u.mgd.associated &&
  			    sdata->u.mgd.powersave &&
  			     !(local->hw.conf.flags & IEEE80211_CONF_PS)) {
  				local->hw.conf.flags |= IEEE80211_CONF_PS;
  				ieee80211_hw_config(local,
  						    IEEE80211_CONF_CHANGE_PS);
  			}
ef7c67257   Johannes Berg   mac80211: don't d...
97
98
99
  		}
  
  		err = drv_suspend(local, wowlan);
2b4562dfd   Johannes Berg   mac80211: allow d...
100
  		if (err < 0) {
eecc48000   Johannes Berg   mac80211: add bas...
101
  			local->quiescing = false;
3b08cf6bd   Pontus Fuchs   mac80211: Clear w...
102
  			local->wowlan = false;
30686bf7f   Johannes Berg   mac80211: convert...
103
  			if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) {
9ea4fa158   Eyal Shapira   mac80211: fix cle...
104
105
106
107
108
109
110
111
  				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,
445ea4e83   Johannes Berg   mac80211: stop qu...
112
  					IEEE80211_MAX_QUEUE_MAP,
cca07b00a   Luciano Coelho   mac80211: introdu...
113
114
  					IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  					false);
eecc48000   Johannes Berg   mac80211: add bas...
115
  			return err;
2b4562dfd   Johannes Berg   mac80211: allow d...
116
117
  		} else if (err > 0) {
  			WARN_ON(err != 1);
23e370989   Johannes Berg   mac80211: start q...
118
119
120
121
122
123
124
  			/* cfg80211 will call back into mac80211 to disconnect
  			 * all interfaces, allow that to proceed properly
  			 */
  			ieee80211_wake_queues_by_reason(hw,
  					IEEE80211_MAX_QUEUE_MAP,
  					IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  					false);
812569699   Stanislaw Gruszka   cfg80211/mac80211...
125
  			return err;
2b4562dfd   Johannes Berg   mac80211: allow d...
126
  		} else {
2b4562dfd   Johannes Berg   mac80211: allow d...
127
  			goto suspend;
eecc48000   Johannes Berg   mac80211: add bas...
128
  		}
eecc48000   Johannes Berg   mac80211: add bas...
129
  	}
cd34f647a   Stanislaw Gruszka   mac80211: fix mon...
130
  	/* remove all interfaces that were created in the driver */
665af4fc8   Bob Copeland   mac80211: add sus...
131
  	list_for_each_entry(sdata, &local->interfaces, list) {
1a1cb744d   Johannes Berg   mac80211: fix sus...
132
  		if (!ieee80211_sdata_running(sdata))
5bb644a0f   Johannes Berg   mac80211: cancel/...
133
  			continue;
1a1cb744d   Johannes Berg   mac80211: fix sus...
134
135
136
137
138
139
140
  		switch (sdata->vif.type) {
  		case NL80211_IFTYPE_AP_VLAN:
  		case NL80211_IFTYPE_MONITOR:
  			continue;
  		case NL80211_IFTYPE_STATION:
  			ieee80211_mgd_quiesce(sdata);
  			break;
2af81d671   Luciano Coelho   mac80211: only ro...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
  		case NL80211_IFTYPE_WDS:
  			/* tear down aggregation sessions and remove STAs */
  			mutex_lock(&local->sta_mtx);
  			sta = sdata->u.wds.sta;
  			if (sta && sta->uploaded) {
  				enum ieee80211_sta_state state;
  
  				state = sta->sta_state;
  				for (; state > IEEE80211_STA_NOTEXIST; state--)
  					WARN_ON(drv_sta_state(local, sta->sdata,
  							      sta, state,
  							      state - 1));
  			}
  			mutex_unlock(&local->sta_mtx);
  			break;
1a1cb744d   Johannes Berg   mac80211: fix sus...
156
157
158
  		default:
  			break;
  		}
cd34f647a   Stanislaw Gruszka   mac80211: fix mon...
159

a9e9200d8   Matt Chen   mac80211: flush d...
160
  		flush_delayed_work(&sdata->dec_tailroom_needed_wk);
7b7eab6fc   Johannes Berg   mac80211: verify ...
161
  		drv_remove_interface(local, sdata);
665af4fc8   Bob Copeland   mac80211: add sus...
162
  	}
5bb644a0f   Johannes Berg   mac80211: cancel/...
163

12e7f5170   Stanislaw Gruszka   mac80211: cleanup...
164
165
166
167
168
  	/*
  	 * We disconnected on all interfaces before suspend, all channel
  	 * contexts should be released.
  	 */
  	WARN_ON(!list_empty(&local->chanctx_list));
4b6f1dd6a   Johannes Berg   mac80211: add exp...
169

89c3a8aca   Johannes Berg   mac80211: fix sus...
170
  	/* stop hardware - this must stop RX */
4854f175c   Johannes Berg   mac80211: remove ...
171
  	ieee80211_stop_device(local);
89c3a8aca   Johannes Berg   mac80211: fix sus...
172

eecc48000   Johannes Berg   mac80211: add bas...
173
   suspend:
5bb644a0f   Johannes Berg   mac80211: cancel/...
174
  	local->suspended = true;
89c3a8aca   Johannes Berg   mac80211: fix sus...
175
176
  	/* need suspended to be visible before quiescing is false */
  	barrier();
5bb644a0f   Johannes Berg   mac80211: cancel/...
177
  	local->quiescing = false;
665af4fc8   Bob Copeland   mac80211: add sus...
178
179
  	return 0;
  }
f2753ddba   Johannes Berg   mac80211: add har...
180
181
182
183
184
  /*
   * __ieee80211_resume() is a static inline which just calls
   * ieee80211_reconfig(), which is also needed for hardware
   * hang/firmware failure/etc. recovery.
   */
cd8f7cb4e   Johannes Berg   cfg80211/mac80211...
185
186
187
188
189
190
191
192
193
194
  
  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);