Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 1 | #include <net/mac80211.h> |
| 2 | #include <net/rtnetlink.h> |
| 3 | |
| 4 | #include "ieee80211_i.h" |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 5 | #include "mesh.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 6 | #include "driver-ops.h" |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 7 | #include "led.h" |
| 8 | |
Eliad Peller | 77572fd | 2011-06-16 11:49:33 +0300 | [diff] [blame] | 9 | /* return value indicates whether the driver should be further notified */ |
Johannes Berg | 61e8a48 | 2012-12-13 16:47:42 +0100 | [diff] [blame^] | 10 | static void ieee80211_quiesce(struct ieee80211_sub_if_data *sdata) |
Eliad Peller | 77572fd | 2011-06-16 11:49:33 +0300 | [diff] [blame] | 11 | { |
| 12 | switch (sdata->vif.type) { |
| 13 | case NL80211_IFTYPE_STATION: |
| 14 | ieee80211_sta_quiesce(sdata); |
Johannes Berg | 61e8a48 | 2012-12-13 16:47:42 +0100 | [diff] [blame^] | 15 | break; |
Eliad Peller | 77572fd | 2011-06-16 11:49:33 +0300 | [diff] [blame] | 16 | case NL80211_IFTYPE_ADHOC: |
| 17 | ieee80211_ibss_quiesce(sdata); |
Johannes Berg | 61e8a48 | 2012-12-13 16:47:42 +0100 | [diff] [blame^] | 18 | break; |
Eliad Peller | 77572fd | 2011-06-16 11:49:33 +0300 | [diff] [blame] | 19 | case NL80211_IFTYPE_MESH_POINT: |
| 20 | ieee80211_mesh_quiesce(sdata); |
Johannes Berg | 61e8a48 | 2012-12-13 16:47:42 +0100 | [diff] [blame^] | 21 | break; |
Eliad Peller | 77572fd | 2011-06-16 11:49:33 +0300 | [diff] [blame] | 22 | default: |
Johannes Berg | 61e8a48 | 2012-12-13 16:47:42 +0100 | [diff] [blame^] | 23 | break; |
Eliad Peller | 77572fd | 2011-06-16 11:49:33 +0300 | [diff] [blame] | 24 | } |
Johannes Berg | 61e8a48 | 2012-12-13 16:47:42 +0100 | [diff] [blame^] | 25 | |
| 26 | cancel_work_sync(&sdata->work); |
Eliad Peller | 77572fd | 2011-06-16 11:49:33 +0300 | [diff] [blame] | 27 | } |
| 28 | |
Johannes Berg | eecc480 | 2011-05-04 15:37:29 +0200 | [diff] [blame] | 29 | int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 30 | { |
| 31 | struct ieee80211_local *local = hw_to_local(hw); |
| 32 | struct ieee80211_sub_if_data *sdata; |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 33 | struct sta_info *sta; |
Johannes Berg | fe5f255 | 2012-11-19 22:19:08 +0100 | [diff] [blame] | 34 | struct ieee80211_chanctx *ctx; |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 35 | |
Johannes Berg | 94f9b97 | 2011-07-14 16:48:54 +0200 | [diff] [blame] | 36 | if (!local->open_count) |
| 37 | goto suspend; |
| 38 | |
Stanislaw Gruszka | 4136c42 | 2010-10-06 11:22:10 +0200 | [diff] [blame] | 39 | ieee80211_scan_cancel(local); |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 40 | |
Johannes Berg | ca45de7 | 2011-04-21 13:38:00 +0200 | [diff] [blame] | 41 | if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { |
| 42 | mutex_lock(&local->sta_mtx); |
| 43 | list_for_each_entry(sta, &local->sta_list, list) { |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 44 | set_sta_flag(sta, WLAN_STA_BLOCK_BA); |
Johannes Berg | ca45de7 | 2011-04-21 13:38:00 +0200 | [diff] [blame] | 45 | ieee80211_sta_tear_down_BA_sessions(sta, true); |
| 46 | } |
| 47 | mutex_unlock(&local->sta_mtx); |
| 48 | } |
| 49 | |
Johannes Berg | 2542060 | 2009-03-13 11:43:36 +0100 | [diff] [blame] | 50 | ieee80211_stop_queues_by_reason(hw, |
| 51 | IEEE80211_QUEUE_STOP_REASON_SUSPEND); |
| 52 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 53 | /* flush out all packets */ |
| 54 | synchronize_net(); |
| 55 | |
Johannes Berg | ca45de7 | 2011-04-21 13:38:00 +0200 | [diff] [blame] | 56 | drv_flush(local, false); |
| 57 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 58 | local->quiescing = true; |
| 59 | /* make quiescing visible to timers everywhere */ |
| 60 | mb(); |
| 61 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 62 | flush_workqueue(local->workqueue); |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 63 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 64 | /* Don't try to run timers while suspended. */ |
| 65 | del_timer_sync(&local->sta_cleanup); |
| 66 | |
| 67 | /* |
| 68 | * Note that this particular timer doesn't need to be |
| 69 | * restarted at resume. |
| 70 | */ |
| 71 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 72 | del_timer_sync(&local->dynamic_ps_timer); |
| 73 | |
Johannes Berg | eecc480 | 2011-05-04 15:37:29 +0200 | [diff] [blame] | 74 | local->wowlan = wowlan && local->open_count; |
| 75 | if (local->wowlan) { |
| 76 | int err = drv_suspend(local, wowlan); |
Johannes Berg | 2b4562d | 2011-07-02 00:02:01 +0200 | [diff] [blame] | 77 | if (err < 0) { |
Johannes Berg | eecc480 | 2011-05-04 15:37:29 +0200 | [diff] [blame] | 78 | local->quiescing = false; |
Pontus Fuchs | 3b08cf6 | 2012-05-31 12:34:47 +0200 | [diff] [blame] | 79 | local->wowlan = false; |
Eyal Shapira | 9ea4fa1 | 2012-06-20 13:10:14 +0300 | [diff] [blame] | 80 | if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { |
| 81 | mutex_lock(&local->sta_mtx); |
| 82 | list_for_each_entry(sta, |
| 83 | &local->sta_list, list) { |
| 84 | clear_sta_flag(sta, WLAN_STA_BLOCK_BA); |
| 85 | } |
| 86 | mutex_unlock(&local->sta_mtx); |
| 87 | } |
| 88 | ieee80211_wake_queues_by_reason(hw, |
| 89 | IEEE80211_QUEUE_STOP_REASON_SUSPEND); |
Johannes Berg | eecc480 | 2011-05-04 15:37:29 +0200 | [diff] [blame] | 90 | return err; |
Johannes Berg | 2b4562d | 2011-07-02 00:02:01 +0200 | [diff] [blame] | 91 | } else if (err > 0) { |
| 92 | WARN_ON(err != 1); |
| 93 | local->wowlan = false; |
| 94 | } else { |
Johannes Berg | 61e8a48 | 2012-12-13 16:47:42 +0100 | [diff] [blame^] | 95 | list_for_each_entry(sdata, &local->interfaces, list) |
| 96 | if (ieee80211_sdata_running(sdata)) |
| 97 | ieee80211_quiesce(sdata); |
Johannes Berg | 2b4562d | 2011-07-02 00:02:01 +0200 | [diff] [blame] | 98 | goto suspend; |
Johannes Berg | eecc480 | 2011-05-04 15:37:29 +0200 | [diff] [blame] | 99 | } |
Johannes Berg | eecc480 | 2011-05-04 15:37:29 +0200 | [diff] [blame] | 100 | } |
| 101 | |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 102 | /* disable keys */ |
| 103 | list_for_each_entry(sdata, &local->interfaces, list) |
| 104 | ieee80211_disable_keys(sdata); |
| 105 | |
Johannes Berg | 2a41905 | 2010-06-10 10:21:29 +0200 | [diff] [blame] | 106 | /* tear down aggregation sessions and remove STAs */ |
| 107 | mutex_lock(&local->sta_mtx); |
| 108 | list_for_each_entry(sta, &local->sta_list, list) { |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 109 | if (sta->uploaded) { |
| 110 | enum ieee80211_sta_state state; |
| 111 | |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 112 | state = sta->sta_state; |
| 113 | for (; state > IEEE80211_STA_NOTEXIST; state--) |
Jakub Kicinski | 9d88c7f | 2012-02-23 02:17:48 +0100 | [diff] [blame] | 114 | WARN_ON(drv_sta_state(local, sta->sdata, sta, |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 115 | state, state - 1)); |
| 116 | } |
| 117 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 118 | mesh_plink_quiesce(sta); |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 119 | } |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 120 | mutex_unlock(&local->sta_mtx); |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 121 | |
| 122 | /* remove all interfaces */ |
| 123 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 124 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 125 | continue; |
| 126 | |
Johannes Berg | 61e8a48 | 2012-12-13 16:47:42 +0100 | [diff] [blame^] | 127 | switch (sdata->vif.type) { |
| 128 | case NL80211_IFTYPE_AP_VLAN: |
| 129 | case NL80211_IFTYPE_MONITOR: |
| 130 | /* skip these */ |
| 131 | continue; |
| 132 | default: |
| 133 | ieee80211_quiesce(sdata); |
| 134 | break; |
| 135 | } |
| 136 | |
Bob Copeland | 97af743 | 2009-07-29 10:13:03 +0200 | [diff] [blame] | 137 | /* disable beaconing */ |
| 138 | ieee80211_bss_info_change_notify(sdata, |
| 139 | BSS_CHANGED_BEACON_ENABLED); |
| 140 | |
Johannes Berg | 1041638 | 2012-10-19 15:44:42 +0200 | [diff] [blame] | 141 | if (sdata->vif.type == NL80211_IFTYPE_AP && |
| 142 | rcu_access_pointer(sdata->u.ap.beacon)) |
| 143 | drv_stop_ap(local, sdata); |
| 144 | |
Johannes Berg | fe5f255 | 2012-11-19 22:19:08 +0100 | [diff] [blame] | 145 | if (local->use_chanctx) { |
| 146 | struct ieee80211_chanctx_conf *conf; |
| 147 | |
| 148 | mutex_lock(&local->chanctx_mtx); |
| 149 | conf = rcu_dereference_protected( |
| 150 | sdata->vif.chanctx_conf, |
| 151 | lockdep_is_held(&local->chanctx_mtx)); |
| 152 | if (conf) { |
| 153 | ctx = container_of(conf, |
| 154 | struct ieee80211_chanctx, |
| 155 | conf); |
| 156 | drv_unassign_vif_chanctx(local, sdata, ctx); |
| 157 | } |
| 158 | |
| 159 | mutex_unlock(&local->chanctx_mtx); |
| 160 | } |
Johannes Berg | 7b7eab6 | 2011-11-03 14:41:13 +0100 | [diff] [blame] | 161 | drv_remove_interface(local, sdata); |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Johannes Berg | 4b6f1dd | 2012-04-03 14:35:57 +0200 | [diff] [blame] | 164 | sdata = rtnl_dereference(local->monitor_sdata); |
Johannes Berg | fe5f255 | 2012-11-19 22:19:08 +0100 | [diff] [blame] | 165 | if (sdata) { |
| 166 | if (local->use_chanctx) { |
| 167 | struct ieee80211_chanctx_conf *conf; |
| 168 | |
| 169 | mutex_lock(&local->chanctx_mtx); |
| 170 | conf = rcu_dereference_protected( |
| 171 | sdata->vif.chanctx_conf, |
| 172 | lockdep_is_held(&local->chanctx_mtx)); |
| 173 | if (conf) { |
| 174 | ctx = container_of(conf, |
| 175 | struct ieee80211_chanctx, |
| 176 | conf); |
| 177 | drv_unassign_vif_chanctx(local, sdata, ctx); |
| 178 | } |
| 179 | |
| 180 | mutex_unlock(&local->chanctx_mtx); |
| 181 | } |
| 182 | |
Johannes Berg | 4b6f1dd | 2012-04-03 14:35:57 +0200 | [diff] [blame] | 183 | drv_remove_interface(local, sdata); |
Johannes Berg | fe5f255 | 2012-11-19 22:19:08 +0100 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | mutex_lock(&local->chanctx_mtx); |
| 187 | list_for_each_entry(ctx, &local->chanctx_list, list) |
| 188 | drv_remove_chanctx(local, ctx); |
| 189 | mutex_unlock(&local->chanctx_mtx); |
Johannes Berg | 4b6f1dd | 2012-04-03 14:35:57 +0200 | [diff] [blame] | 190 | |
Johannes Berg | 89c3a8a | 2009-07-28 18:10:17 +0200 | [diff] [blame] | 191 | /* stop hardware - this must stop RX */ |
Johannes Berg | 84f6a01 | 2009-08-20 20:02:20 +0200 | [diff] [blame] | 192 | if (local->open_count) |
| 193 | ieee80211_stop_device(local); |
Johannes Berg | 89c3a8a | 2009-07-28 18:10:17 +0200 | [diff] [blame] | 194 | |
Johannes Berg | eecc480 | 2011-05-04 15:37:29 +0200 | [diff] [blame] | 195 | suspend: |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 196 | local->suspended = true; |
Johannes Berg | 89c3a8a | 2009-07-28 18:10:17 +0200 | [diff] [blame] | 197 | /* need suspended to be visible before quiescing is false */ |
| 198 | barrier(); |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 199 | local->quiescing = false; |
Bob Copeland | e874e65 | 2009-01-24 13:21:14 -0500 | [diff] [blame] | 200 | |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 201 | return 0; |
| 202 | } |
| 203 | |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 204 | /* |
| 205 | * __ieee80211_resume() is a static inline which just calls |
| 206 | * ieee80211_reconfig(), which is also needed for hardware |
| 207 | * hang/firmware failure/etc. recovery. |
| 208 | */ |