blob: 1e6152ac6778d7c900cd2600225774bba9b63a2c [file] [log] [blame]
Bob Copeland665af4f2009-01-19 11:20:53 -05001#include <net/mac80211.h>
2#include <net/rtnetlink.h>
3
4#include "ieee80211_i.h"
5#include "led.h"
6
7int __ieee80211_suspend(struct ieee80211_hw *hw)
8{
9 struct ieee80211_local *local = hw_to_local(hw);
10 struct ieee80211_sub_if_data *sdata;
11 struct ieee80211_if_init_conf conf;
12 struct sta_info *sta;
Johannes Berg7f0216a2009-03-14 09:42:49 +010013 unsigned long flags;
Bob Copeland665af4f2009-01-19 11:20:53 -050014
Johannes Berg25420602009-03-13 11:43:36 +010015 ieee80211_stop_queues_by_reason(hw,
16 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
17
Bob Copeland665af4f2009-01-19 11:20:53 -050018 flush_workqueue(local->hw.workqueue);
19
20 /* disable keys */
21 list_for_each_entry(sdata, &local->interfaces, list)
22 ieee80211_disable_keys(sdata);
23
Sujith722f0692009-03-17 08:50:06 +053024 /* Tear down aggregation sessions */
25
26 rcu_read_lock();
27
28 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
29 list_for_each_entry_rcu(sta, &local->sta_list, list) {
30 set_sta_flags(sta, WLAN_STA_SUSPEND);
31 ieee80211_sta_tear_down_BA_sessions(sta);
32 }
33 }
34
35 rcu_read_unlock();
36
Bob Copeland665af4f2009-01-19 11:20:53 -050037 /* remove STAs */
Johannes Berg7f0216a2009-03-14 09:42:49 +010038 if (local->ops->sta_notify) {
39 spin_lock_irqsave(&local->sta_lock, flags);
40 list_for_each_entry(sta, &local->sta_list, list) {
Bob Copeland665af4f2009-01-19 11:20:53 -050041 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
42 sdata = container_of(sdata->bss,
43 struct ieee80211_sub_if_data,
44 u.ap);
45
46 local->ops->sta_notify(hw, &sdata->vif,
47 STA_NOTIFY_REMOVE, &sta->sta);
48 }
Johannes Berg7f0216a2009-03-14 09:42:49 +010049 spin_unlock_irqrestore(&local->sta_lock, flags);
Bob Copeland665af4f2009-01-19 11:20:53 -050050 }
51
52 /* remove all interfaces */
53 list_for_each_entry(sdata, &local->interfaces, list) {
Bob Copeland665af4f2009-01-19 11:20:53 -050054 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
55 sdata->vif.type != NL80211_IFTYPE_MONITOR &&
56 netif_running(sdata->dev)) {
57 conf.vif = &sdata->vif;
58 conf.type = sdata->vif.type;
59 conf.mac_addr = sdata->dev->dev_addr;
60 local->ops->remove_interface(hw, &conf);
61 }
62 }
63
Bob Copelande874e652009-01-24 13:21:14 -050064 /* flush again, in case driver queued work */
65 flush_workqueue(local->hw.workqueue);
66
Bob Copeland665af4f2009-01-19 11:20:53 -050067 /* stop hardware */
68 if (local->open_count) {
69 ieee80211_led_radio(local, false);
70 local->ops->stop(hw);
71 }
72 return 0;
73}
74
75int __ieee80211_resume(struct ieee80211_hw *hw)
76{
77 struct ieee80211_local *local = hw_to_local(hw);
78 struct ieee80211_sub_if_data *sdata;
79 struct ieee80211_if_init_conf conf;
80 struct sta_info *sta;
Johannes Berg7f0216a2009-03-14 09:42:49 +010081 unsigned long flags;
Bob Copeland665af4f2009-01-19 11:20:53 -050082 int res;
83
84 /* restart hardware */
85 if (local->open_count) {
86 res = local->ops->start(hw);
87
88 ieee80211_led_radio(local, hw->conf.radio_enabled);
89 }
90
91 /* add interfaces */
92 list_for_each_entry(sdata, &local->interfaces, list) {
Bob Copeland665af4f2009-01-19 11:20:53 -050093 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
94 sdata->vif.type != NL80211_IFTYPE_MONITOR &&
95 netif_running(sdata->dev)) {
96 conf.vif = &sdata->vif;
97 conf.type = sdata->vif.type;
98 conf.mac_addr = sdata->dev->dev_addr;
99 res = local->ops->add_interface(hw, &conf);
100 }
101 }
102
103 /* add STAs back */
Johannes Berg7f0216a2009-03-14 09:42:49 +0100104 if (local->ops->sta_notify) {
105 spin_lock_irqsave(&local->sta_lock, flags);
106 list_for_each_entry(sta, &local->sta_list, list) {
Bob Copeland665af4f2009-01-19 11:20:53 -0500107 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
108 sdata = container_of(sdata->bss,
109 struct ieee80211_sub_if_data,
110 u.ap);
111
112 local->ops->sta_notify(hw, &sdata->vif,
113 STA_NOTIFY_ADD, &sta->sta);
114 }
Johannes Berg7f0216a2009-03-14 09:42:49 +0100115 spin_unlock_irqrestore(&local->sta_lock, flags);
Bob Copeland665af4f2009-01-19 11:20:53 -0500116 }
117
Sujith722f0692009-03-17 08:50:06 +0530118 /* Clear Suspend state so that ADDBA requests can be processed */
119
120 rcu_read_lock();
121
122 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
123 list_for_each_entry_rcu(sta, &local->sta_list, list) {
124 clear_sta_flags(sta, WLAN_STA_SUSPEND);
125 }
126 }
127
128 rcu_read_unlock();
129
Bob Copeland665af4f2009-01-19 11:20:53 -0500130 /* add back keys */
131 list_for_each_entry(sdata, &local->interfaces, list)
132 if (netif_running(sdata->dev))
133 ieee80211_enable_keys(sdata);
134
135 /* setup RTS threshold */
136 if (local->ops->set_rts_threshold)
137 local->ops->set_rts_threshold(hw, local->rts_threshold);
138
139 /* reconfigure hardware */
140 ieee80211_hw_config(local, ~0);
141
142 netif_addr_lock_bh(local->mdev);
143 ieee80211_configure_filter(local);
144 netif_addr_unlock_bh(local->mdev);
145
Johannes Berg25420602009-03-13 11:43:36 +0100146 ieee80211_wake_queues_by_reason(hw,
147 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
148
Bob Copeland665af4f2009-01-19 11:20:53 -0500149 return 0;
150}