Commit | Line | Data |
---|---|---|
665af4fc BC |
1 | #include <net/mac80211.h> |
2 | #include <net/rtnetlink.h> | |
3 | ||
4 | #include "ieee80211_i.h" | |
5bb644a0 | 5 | #include "mesh.h" |
24487981 | 6 | #include "driver-ops.h" |
665af4fc BC |
7 | #include "led.h" |
8 | ||
eecc4800 | 9 | int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) |
665af4fc BC |
10 | { |
11 | struct ieee80211_local *local = hw_to_local(hw); | |
12 | struct ieee80211_sub_if_data *sdata; | |
665af4fc BC |
13 | struct sta_info *sta; |
14 | ||
94f9b97b JB |
15 | if (!local->open_count) |
16 | goto suspend; | |
17 | ||
4136c422 | 18 | ieee80211_scan_cancel(local); |
5bb644a0 | 19 | |
164eb02d SW |
20 | ieee80211_dfs_cac_cancel(local); |
21 | ||
ca45de77 JB |
22 | if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { |
23 | mutex_lock(&local->sta_mtx); | |
24 | list_for_each_entry(sta, &local->sta_list, list) { | |
c2c98fde | 25 | set_sta_flag(sta, WLAN_STA_BLOCK_BA); |
c82c4a80 JB |
26 | ieee80211_sta_tear_down_BA_sessions( |
27 | sta, AGG_STOP_LOCAL_REQUEST); | |
ca45de77 JB |
28 | } |
29 | mutex_unlock(&local->sta_mtx); | |
30 | } | |
31 | ||
25420604 | 32 | ieee80211_stop_queues_by_reason(hw, |
445ea4e8 JB |
33 | IEEE80211_MAX_QUEUE_MAP, |
34 | IEEE80211_QUEUE_STOP_REASON_SUSPEND); | |
25420604 | 35 | |
5bb644a0 JB |
36 | /* flush out all packets */ |
37 | synchronize_net(); | |
38 | ||
39ecc01d | 39 | ieee80211_flush_queues(local, NULL); |
ca45de77 | 40 | |
5bb644a0 JB |
41 | local->quiescing = true; |
42 | /* make quiescing visible to timers everywhere */ | |
43 | mb(); | |
44 | ||
42935eca | 45 | flush_workqueue(local->workqueue); |
665af4fc | 46 | |
5bb644a0 JB |
47 | /* Don't try to run timers while suspended. */ |
48 | del_timer_sync(&local->sta_cleanup); | |
49 | ||
50 | /* | |
51 | * Note that this particular timer doesn't need to be | |
52 | * restarted at resume. | |
53 | */ | |
54 | cancel_work_sync(&local->dynamic_ps_enable_work); | |
55 | del_timer_sync(&local->dynamic_ps_timer); | |
56 | ||
eecc4800 JB |
57 | local->wowlan = wowlan && local->open_count; |
58 | if (local->wowlan) { | |
59 | int err = drv_suspend(local, wowlan); | |
2b4562df | 60 | if (err < 0) { |
eecc4800 | 61 | local->quiescing = false; |
3b08cf6b | 62 | local->wowlan = false; |
9ea4fa15 ES |
63 | if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { |
64 | mutex_lock(&local->sta_mtx); | |
65 | list_for_each_entry(sta, | |
66 | &local->sta_list, list) { | |
67 | clear_sta_flag(sta, WLAN_STA_BLOCK_BA); | |
68 | } | |
69 | mutex_unlock(&local->sta_mtx); | |
70 | } | |
71 | ieee80211_wake_queues_by_reason(hw, | |
445ea4e8 | 72 | IEEE80211_MAX_QUEUE_MAP, |
9ea4fa15 | 73 | IEEE80211_QUEUE_STOP_REASON_SUSPEND); |
eecc4800 | 74 | return err; |
2b4562df JB |
75 | } else if (err > 0) { |
76 | WARN_ON(err != 1); | |
81256969 | 77 | return err; |
2b4562df | 78 | } else { |
2b4562df | 79 | goto suspend; |
eecc4800 | 80 | } |
eecc4800 JB |
81 | } |
82 | ||
2a419056 JB |
83 | /* tear down aggregation sessions and remove STAs */ |
84 | mutex_lock(&local->sta_mtx); | |
85 | list_for_each_entry(sta, &local->sta_list, list) { | |
f09603a2 JB |
86 | if (sta->uploaded) { |
87 | enum ieee80211_sta_state state; | |
88 | ||
f09603a2 JB |
89 | state = sta->sta_state; |
90 | for (; state > IEEE80211_STA_NOTEXIST; state--) | |
9d88c7f6 | 91 | WARN_ON(drv_sta_state(local, sta->sdata, sta, |
f09603a2 JB |
92 | state, state - 1)); |
93 | } | |
665af4fc | 94 | } |
34e89507 | 95 | mutex_unlock(&local->sta_mtx); |
665af4fc BC |
96 | |
97 | /* remove all interfaces */ | |
98 | list_for_each_entry(sdata, &local->interfaces, list) { | |
61e8a48c | 99 | if (!ieee80211_sdata_running(sdata)) |
5bb644a0 | 100 | continue; |
7b7eab6f | 101 | drv_remove_interface(local, sdata); |
665af4fc | 102 | } |
5bb644a0 | 103 | |
4b6f1dd6 | 104 | sdata = rtnl_dereference(local->monitor_sdata); |
12e7f517 | 105 | if (sdata) |
4b6f1dd6 | 106 | drv_remove_interface(local, sdata); |
fe5f2559 | 107 | |
12e7f517 SG |
108 | /* |
109 | * We disconnected on all interfaces before suspend, all channel | |
110 | * contexts should be released. | |
111 | */ | |
112 | WARN_ON(!list_empty(&local->chanctx_list)); | |
4b6f1dd6 | 113 | |
89c3a8ac | 114 | /* stop hardware - this must stop RX */ |
84f6a01c JB |
115 | if (local->open_count) |
116 | ieee80211_stop_device(local); | |
89c3a8ac | 117 | |
eecc4800 | 118 | suspend: |
5bb644a0 | 119 | local->suspended = true; |
89c3a8ac JB |
120 | /* need suspended to be visible before quiescing is false */ |
121 | barrier(); | |
5bb644a0 JB |
122 | local->quiescing = false; |
123 | ||
665af4fc BC |
124 | return 0; |
125 | } | |
126 | ||
f2753ddb JB |
127 | /* |
128 | * __ieee80211_resume() is a static inline which just calls | |
129 | * ieee80211_reconfig(), which is also needed for hardware | |
130 | * hang/firmware failure/etc. recovery. | |
131 | */ | |
cd8f7cb4 JB |
132 | |
133 | void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif, | |
134 | struct cfg80211_wowlan_wakeup *wakeup, | |
135 | gfp_t gfp) | |
136 | { | |
137 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
138 | ||
139 | cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp); | |
140 | } | |
141 | EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup); |