1
2
3
4
5
6#include <net/mac80211.h>
7#include <net/rtnetlink.h>
8
9#include "ieee80211_i.h"
10#include "mesh.h"
11#include "driver-ops.h"
12#include "led.h"
13
14static void ieee80211_sched_scan_cancel(struct ieee80211_local *local)
15{
16 if (ieee80211_request_sched_scan_stop(local))
17 return;
18 cfg80211_sched_scan_stopped_locked(local->hw.wiphy, 0);
19}
20
21int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
22{
23 struct ieee80211_local *local = hw_to_local(hw);
24 struct ieee80211_sub_if_data *sdata;
25 struct sta_info *sta;
26
27 if (!local->open_count)
28 goto suspend;
29
30 local->suspending = true;
31 mb();
32
33 ieee80211_scan_cancel(local);
34
35 ieee80211_dfs_cac_cancel(local);
36
37 ieee80211_roc_purge(local, NULL);
38
39 ieee80211_del_virtual_monitor(local);
40
41 if (ieee80211_hw_check(hw, AMPDU_AGGREGATION) &&
42 !(wowlan && wowlan->any)) {
43 mutex_lock(&local->sta_mtx);
44 list_for_each_entry(sta, &local->sta_list, list) {
45 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
46 ieee80211_sta_tear_down_BA_sessions(
47 sta, AGG_STOP_LOCAL_REQUEST);
48 }
49 mutex_unlock(&local->sta_mtx);
50 }
51
52
53 if (!(wowlan && wowlan->any))
54 ieee80211_sched_scan_cancel(local);
55
56 ieee80211_stop_queues_by_reason(hw,
57 IEEE80211_MAX_QUEUE_MAP,
58 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
59 false);
60
61
62 synchronize_net();
63
64 ieee80211_flush_queues(local, NULL, true);
65
66 local->quiescing = true;
67
68 mb();
69
70 flush_workqueue(local->workqueue);
71
72
73 del_timer_sync(&local->sta_cleanup);
74
75
76
77
78
79 cancel_work_sync(&local->dynamic_ps_enable_work);
80 del_timer_sync(&local->dynamic_ps_timer);
81
82 local->wowlan = wowlan;
83 if (local->wowlan) {
84 int err;
85
86
87
88
89
90
91
92
93 list_for_each_entry(sdata, &local->interfaces, list) {
94 if (!ieee80211_sdata_running(sdata))
95 continue;
96 if (sdata->vif.type != NL80211_IFTYPE_STATION)
97 continue;
98 ieee80211_mgd_quiesce(sdata);
99
100
101
102
103
104
105
106
107
108 if (sdata->u.mgd.associated &&
109 sdata->u.mgd.powersave &&
110 !(local->hw.conf.flags & IEEE80211_CONF_PS)) {
111 local->hw.conf.flags |= IEEE80211_CONF_PS;
112 ieee80211_hw_config(local,
113 IEEE80211_CONF_CHANGE_PS);
114 }
115 }
116
117 err = drv_suspend(local, wowlan);
118 if (err < 0) {
119 local->quiescing = false;
120 local->wowlan = false;
121 if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) {
122 mutex_lock(&local->sta_mtx);
123 list_for_each_entry(sta,
124 &local->sta_list, list) {
125 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
126 }
127 mutex_unlock(&local->sta_mtx);
128 }
129 ieee80211_wake_queues_by_reason(hw,
130 IEEE80211_MAX_QUEUE_MAP,
131 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
132 false);
133 return err;
134 } else if (err > 0) {
135 WARN_ON(err != 1);
136
137
138
139 ieee80211_wake_queues_by_reason(hw,
140 IEEE80211_MAX_QUEUE_MAP,
141 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
142 false);
143 return err;
144 } else {
145 goto suspend;
146 }
147 }
148
149
150 list_for_each_entry(sdata, &local->interfaces, list) {
151 if (!ieee80211_sdata_running(sdata))
152 continue;
153 switch (sdata->vif.type) {
154 case NL80211_IFTYPE_AP_VLAN:
155 case NL80211_IFTYPE_MONITOR:
156 continue;
157 case NL80211_IFTYPE_STATION:
158 ieee80211_mgd_quiesce(sdata);
159 break;
160 default:
161 break;
162 }
163
164 flush_delayed_work(&sdata->dec_tailroom_needed_wk);
165 drv_remove_interface(local, sdata);
166 }
167
168
169
170
171
172 WARN_ON(!list_empty(&local->chanctx_list));
173
174
175 ieee80211_stop_device(local);
176
177 suspend:
178 local->suspended = true;
179
180 barrier();
181 local->quiescing = false;
182 local->suspending = false;
183
184 return 0;
185}
186
187
188
189
190
191
192
193void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
194 struct cfg80211_wowlan_wakeup *wakeup,
195 gfp_t gfp)
196{
197 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
198
199 cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
200}
201EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);
202