]> git.karo-electronics.de Git - karo-tx-linux.git/blob - net/mac80211/pm.c
Merge remote-tracking branch 'mfd/for-mfd-next'
[karo-tx-linux.git] / net / mac80211 / pm.c
1 #include <net/mac80211.h>
2 #include <net/rtnetlink.h>
3
4 #include "ieee80211_i.h"
5 #include "mesh.h"
6 #include "driver-ops.h"
7 #include "led.h"
8
9 int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
10 {
11         struct ieee80211_local *local = hw_to_local(hw);
12         struct ieee80211_sub_if_data *sdata;
13         struct sta_info *sta;
14
15         if (!local->open_count)
16                 goto suspend;
17
18         ieee80211_scan_cancel(local);
19
20         ieee80211_dfs_cac_cancel(local);
21
22         ieee80211_roc_purge(local, NULL);
23
24         ieee80211_del_virtual_monitor(local);
25
26         if (ieee80211_hw_check(hw, AMPDU_AGGREGATION) &&
27             !(wowlan && wowlan->any)) {
28                 mutex_lock(&local->sta_mtx);
29                 list_for_each_entry(sta, &local->sta_list, list) {
30                         set_sta_flag(sta, WLAN_STA_BLOCK_BA);
31                         ieee80211_sta_tear_down_BA_sessions(
32                                         sta, AGG_STOP_LOCAL_REQUEST);
33                 }
34                 mutex_unlock(&local->sta_mtx);
35         }
36
37         ieee80211_stop_queues_by_reason(hw,
38                                         IEEE80211_MAX_QUEUE_MAP,
39                                         IEEE80211_QUEUE_STOP_REASON_SUSPEND,
40                                         false);
41
42         /* flush out all packets */
43         synchronize_net();
44
45         ieee80211_flush_queues(local, NULL, true);
46
47         local->quiescing = true;
48         /* make quiescing visible to timers everywhere */
49         mb();
50
51         flush_workqueue(local->workqueue);
52
53         /* Don't try to run timers while suspended. */
54         del_timer_sync(&local->sta_cleanup);
55
56          /*
57          * Note that this particular timer doesn't need to be
58          * restarted at resume.
59          */
60         cancel_work_sync(&local->dynamic_ps_enable_work);
61         del_timer_sync(&local->dynamic_ps_timer);
62
63         local->wowlan = wowlan;
64         if (local->wowlan) {
65                 int err;
66
67                 /* Drivers don't expect to suspend while some operations like
68                  * authenticating or associating are in progress. It doesn't
69                  * make sense anyway to accept that, since the authentication
70                  * or association would never finish since the driver can't do
71                  * that on its own.
72                  * Thus, clean up in-progress auth/assoc first.
73                  */
74                 list_for_each_entry(sdata, &local->interfaces, list) {
75                         if (!ieee80211_sdata_running(sdata))
76                                 continue;
77                         if (sdata->vif.type != NL80211_IFTYPE_STATION)
78                                 continue;
79                         ieee80211_mgd_quiesce(sdata);
80                         /* If suspended during TX in progress, and wowlan
81                          * is enabled (connection will be active) there
82                          * can be a race where the driver is put out
83                          * of power-save due to TX and during suspend
84                          * dynamic_ps_timer is cancelled and TX packet
85                          * is flushed, leaving the driver in ACTIVE even
86                          * after resuming until dynamic_ps_timer puts
87                          * driver back in DOZE.
88                          */
89                         if (sdata->u.mgd.associated &&
90                             sdata->u.mgd.powersave &&
91                              !(local->hw.conf.flags & IEEE80211_CONF_PS)) {
92                                 local->hw.conf.flags |= IEEE80211_CONF_PS;
93                                 ieee80211_hw_config(local,
94                                                     IEEE80211_CONF_CHANGE_PS);
95                         }
96                 }
97
98                 err = drv_suspend(local, wowlan);
99                 if (err < 0) {
100                         local->quiescing = false;
101                         local->wowlan = false;
102                         if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) {
103                                 mutex_lock(&local->sta_mtx);
104                                 list_for_each_entry(sta,
105                                                     &local->sta_list, list) {
106                                         clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
107                                 }
108                                 mutex_unlock(&local->sta_mtx);
109                         }
110                         ieee80211_wake_queues_by_reason(hw,
111                                         IEEE80211_MAX_QUEUE_MAP,
112                                         IEEE80211_QUEUE_STOP_REASON_SUSPEND,
113                                         false);
114                         return err;
115                 } else if (err > 0) {
116                         WARN_ON(err != 1);
117                         /* cfg80211 will call back into mac80211 to disconnect
118                          * all interfaces, allow that to proceed properly
119                          */
120                         ieee80211_wake_queues_by_reason(hw,
121                                         IEEE80211_MAX_QUEUE_MAP,
122                                         IEEE80211_QUEUE_STOP_REASON_SUSPEND,
123                                         false);
124                         return err;
125                 } else {
126                         goto suspend;
127                 }
128         }
129
130         /* remove all interfaces that were created in the driver */
131         list_for_each_entry(sdata, &local->interfaces, list) {
132                 if (!ieee80211_sdata_running(sdata))
133                         continue;
134                 switch (sdata->vif.type) {
135                 case NL80211_IFTYPE_AP_VLAN:
136                 case NL80211_IFTYPE_MONITOR:
137                         continue;
138                 case NL80211_IFTYPE_STATION:
139                         ieee80211_mgd_quiesce(sdata);
140                         break;
141                 case NL80211_IFTYPE_WDS:
142                         /* tear down aggregation sessions and remove STAs */
143                         mutex_lock(&local->sta_mtx);
144                         sta = sdata->u.wds.sta;
145                         if (sta && sta->uploaded) {
146                                 enum ieee80211_sta_state state;
147
148                                 state = sta->sta_state;
149                                 for (; state > IEEE80211_STA_NOTEXIST; state--)
150                                         WARN_ON(drv_sta_state(local, sta->sdata,
151                                                               sta, state,
152                                                               state - 1));
153                         }
154                         mutex_unlock(&local->sta_mtx);
155                         break;
156                 default:
157                         break;
158                 }
159
160                 drv_remove_interface(local, sdata);
161         }
162
163         /*
164          * We disconnected on all interfaces before suspend, all channel
165          * contexts should be released.
166          */
167         WARN_ON(!list_empty(&local->chanctx_list));
168
169         /* stop hardware - this must stop RX */
170         if (local->open_count)
171                 ieee80211_stop_device(local);
172
173  suspend:
174         local->suspended = true;
175         /* need suspended to be visible before quiescing is false */
176         barrier();
177         local->quiescing = false;
178
179         return 0;
180 }
181
182 /*
183  * __ieee80211_resume() is a static inline which just calls
184  * ieee80211_reconfig(), which is also needed for hardware
185  * hang/firmware failure/etc. recovery.
186  */
187
188 void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
189                                     struct cfg80211_wowlan_wakeup *wakeup,
190                                     gfp_t gfp)
191 {
192         struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
193
194         cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
195 }
196 EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);