mac80211: acquire sta_lock for station suspend/resume
[linux-2.6.git] / net / mac80211 / pm.c
1 #include <net/mac80211.h>
2 #include <net/rtnetlink.h>
3
4 #include "ieee80211_i.h"
5 #include "led.h"
6
7 int __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;
13         unsigned long flags;
14
15         ieee80211_stop_queues_by_reason(hw,
16                         IEEE80211_QUEUE_STOP_REASON_SUSPEND);
17
18         flush_workqueue(local->hw.workqueue);
19
20         /* disable keys */
21         list_for_each_entry(sdata, &local->interfaces, list)
22                 ieee80211_disable_keys(sdata);
23
24         /* remove STAs */
25         if (local->ops->sta_notify) {
26                 spin_lock_irqsave(&local->sta_lock, flags);
27                 list_for_each_entry(sta, &local->sta_list, list) {
28                         if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
29                                 sdata = container_of(sdata->bss,
30                                              struct ieee80211_sub_if_data,
31                                              u.ap);
32
33                         local->ops->sta_notify(hw, &sdata->vif,
34                                 STA_NOTIFY_REMOVE, &sta->sta);
35                 }
36                 spin_unlock_irqrestore(&local->sta_lock, flags);
37         }
38
39         /* remove all interfaces */
40         list_for_each_entry(sdata, &local->interfaces, list) {
41                 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
42                     sdata->vif.type != NL80211_IFTYPE_MONITOR &&
43                     netif_running(sdata->dev)) {
44                         conf.vif = &sdata->vif;
45                         conf.type = sdata->vif.type;
46                         conf.mac_addr = sdata->dev->dev_addr;
47                         local->ops->remove_interface(hw, &conf);
48                 }
49         }
50
51         /* flush again, in case driver queued work */
52         flush_workqueue(local->hw.workqueue);
53
54         /* stop hardware */
55         if (local->open_count) {
56                 ieee80211_led_radio(local, false);
57                 local->ops->stop(hw);
58         }
59         return 0;
60 }
61
62 int __ieee80211_resume(struct ieee80211_hw *hw)
63 {
64         struct ieee80211_local *local = hw_to_local(hw);
65         struct ieee80211_sub_if_data *sdata;
66         struct ieee80211_if_init_conf conf;
67         struct sta_info *sta;
68         unsigned long flags;
69         int res;
70
71         /* restart hardware */
72         if (local->open_count) {
73                 res = local->ops->start(hw);
74
75                 ieee80211_led_radio(local, hw->conf.radio_enabled);
76         }
77
78         /* add interfaces */
79         list_for_each_entry(sdata, &local->interfaces, list) {
80                 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
81                     sdata->vif.type != NL80211_IFTYPE_MONITOR &&
82                     netif_running(sdata->dev)) {
83                         conf.vif = &sdata->vif;
84                         conf.type = sdata->vif.type;
85                         conf.mac_addr = sdata->dev->dev_addr;
86                         res = local->ops->add_interface(hw, &conf);
87                 }
88         }
89
90         /* add STAs back */
91         if (local->ops->sta_notify) {
92                 spin_lock_irqsave(&local->sta_lock, flags);
93                 list_for_each_entry(sta, &local->sta_list, list) {
94                         if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
95                                 sdata = container_of(sdata->bss,
96                                              struct ieee80211_sub_if_data,
97                                              u.ap);
98
99                         local->ops->sta_notify(hw, &sdata->vif,
100                                 STA_NOTIFY_ADD, &sta->sta);
101                 }
102                 spin_unlock_irqrestore(&local->sta_lock, flags);
103         }
104
105         /* add back keys */
106         list_for_each_entry(sdata, &local->interfaces, list)
107                 if (netif_running(sdata->dev))
108                         ieee80211_enable_keys(sdata);
109
110         /* setup RTS threshold */
111         if (local->ops->set_rts_threshold)
112                 local->ops->set_rts_threshold(hw, local->rts_threshold);
113
114         /* reconfigure hardware */
115         ieee80211_hw_config(local, ~0);
116
117         netif_addr_lock_bh(local->mdev);
118         ieee80211_configure_filter(local);
119         netif_addr_unlock_bh(local->mdev);
120
121         ieee80211_wake_queues_by_reason(hw,
122                         IEEE80211_QUEUE_STOP_REASON_SUSPEND);
123
124         return 0;
125 }