staging: lirc: remove sa1100 support
[linux-2.6/btrfs-unstable.git] / net / mac80211 / pm.c
blobd478b880a0afd676dae699d5b5541c150a7e819f
1 #include <net/mac80211.h>
2 #include <net/rtnetlink.h>
4 #include "ieee80211_i.h"
5 #include "mesh.h"
6 #include "driver-ops.h"
7 #include "led.h"
9 int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
11 struct ieee80211_local *local = hw_to_local(hw);
12 struct ieee80211_sub_if_data *sdata;
13 struct sta_info *sta;
15 if (!local->open_count)
16 goto suspend;
18 ieee80211_scan_cancel(local);
20 ieee80211_dfs_cac_cancel(local);
22 ieee80211_roc_purge(local, NULL);
24 ieee80211_del_virtual_monitor(local);
26 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
27 mutex_lock(&local->sta_mtx);
28 list_for_each_entry(sta, &local->sta_list, list) {
29 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
30 ieee80211_sta_tear_down_BA_sessions(
31 sta, AGG_STOP_LOCAL_REQUEST);
33 mutex_unlock(&local->sta_mtx);
36 ieee80211_stop_queues_by_reason(hw,
37 IEEE80211_MAX_QUEUE_MAP,
38 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
40 /* flush out all packets */
41 synchronize_net();
43 ieee80211_flush_queues(local, NULL);
45 local->quiescing = true;
46 /* make quiescing visible to timers everywhere */
47 mb();
49 flush_workqueue(local->workqueue);
51 /* Don't try to run timers while suspended. */
52 del_timer_sync(&local->sta_cleanup);
55 * Note that this particular timer doesn't need to be
56 * restarted at resume.
58 cancel_work_sync(&local->dynamic_ps_enable_work);
59 del_timer_sync(&local->dynamic_ps_timer);
61 local->wowlan = wowlan && local->open_count;
62 if (local->wowlan) {
63 int err = drv_suspend(local, wowlan);
64 if (err < 0) {
65 local->quiescing = false;
66 local->wowlan = false;
67 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
68 mutex_lock(&local->sta_mtx);
69 list_for_each_entry(sta,
70 &local->sta_list, list) {
71 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
73 mutex_unlock(&local->sta_mtx);
75 ieee80211_wake_queues_by_reason(hw,
76 IEEE80211_MAX_QUEUE_MAP,
77 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
78 return err;
79 } else if (err > 0) {
80 WARN_ON(err != 1);
81 return err;
82 } else {
83 goto suspend;
87 /* tear down aggregation sessions and remove STAs */
88 mutex_lock(&local->sta_mtx);
89 list_for_each_entry(sta, &local->sta_list, list) {
90 if (sta->uploaded) {
91 enum ieee80211_sta_state state;
93 state = sta->sta_state;
94 for (; state > IEEE80211_STA_NOTEXIST; state--)
95 WARN_ON(drv_sta_state(local, sta->sdata, sta,
96 state, state - 1));
99 mutex_unlock(&local->sta_mtx);
101 /* remove all interfaces that were created in the driver */
102 list_for_each_entry(sdata, &local->interfaces, list) {
103 if (!ieee80211_sdata_running(sdata))
104 continue;
105 switch (sdata->vif.type) {
106 case NL80211_IFTYPE_AP_VLAN:
107 case NL80211_IFTYPE_MONITOR:
108 continue;
109 case NL80211_IFTYPE_STATION:
110 ieee80211_mgd_quiesce(sdata);
111 break;
112 default:
113 break;
116 drv_remove_interface(local, sdata);
120 * We disconnected on all interfaces before suspend, all channel
121 * contexts should be released.
123 WARN_ON(!list_empty(&local->chanctx_list));
125 /* stop hardware - this must stop RX */
126 if (local->open_count)
127 ieee80211_stop_device(local);
129 suspend:
130 local->suspended = true;
131 /* need suspended to be visible before quiescing is false */
132 barrier();
133 local->quiescing = false;
135 return 0;
139 * __ieee80211_resume() is a static inline which just calls
140 * ieee80211_reconfig(), which is also needed for hardware
141 * hang/firmware failure/etc. recovery.
144 void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
145 struct cfg80211_wowlan_wakeup *wakeup,
146 gfp_t gfp)
148 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
150 cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
152 EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);