mac80211: acquire sta_lock for station suspend/resume
[linux-2.6.git] / net / mac80211 / pm.c
index 6d17ed7..ef7be1c 100644 (file)
@@ -10,6 +10,10 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
        struct ieee80211_sub_if_data *sdata;
        struct ieee80211_if_init_conf conf;
        struct sta_info *sta;
+       unsigned long flags;
+
+       ieee80211_stop_queues_by_reason(hw,
+                       IEEE80211_QUEUE_STOP_REASON_SUSPEND);
 
        flush_workqueue(local->hw.workqueue);
 
@@ -18,9 +22,9 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
                ieee80211_disable_keys(sdata);
 
        /* remove STAs */
-       list_for_each_entry(sta, &local->sta_list, list) {
-
-               if (local->ops->sta_notify) {
+       if (local->ops->sta_notify) {
+               spin_lock_irqsave(&local->sta_lock, flags);
+               list_for_each_entry(sta, &local->sta_list, list) {
                        if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
                                sdata = container_of(sdata->bss,
                                             struct ieee80211_sub_if_data,
@@ -29,11 +33,11 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
                        local->ops->sta_notify(hw, &sdata->vif,
                                STA_NOTIFY_REMOVE, &sta->sta);
                }
+               spin_unlock_irqrestore(&local->sta_lock, flags);
        }
 
        /* remove all interfaces */
        list_for_each_entry(sdata, &local->interfaces, list) {
-
                if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
                    sdata->vif.type != NL80211_IFTYPE_MONITOR &&
                    netif_running(sdata->dev)) {
@@ -44,6 +48,9 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
                }
        }
 
+       /* flush again, in case driver queued work */
+       flush_workqueue(local->hw.workqueue);
+
        /* stop hardware */
        if (local->open_count) {
                ieee80211_led_radio(local, false);
@@ -58,6 +65,7 @@ int __ieee80211_resume(struct ieee80211_hw *hw)
        struct ieee80211_sub_if_data *sdata;
        struct ieee80211_if_init_conf conf;
        struct sta_info *sta;
+       unsigned long flags;
        int res;
 
        /* restart hardware */
@@ -69,7 +77,6 @@ int __ieee80211_resume(struct ieee80211_hw *hw)
 
        /* add interfaces */
        list_for_each_entry(sdata, &local->interfaces, list) {
-
                if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
                    sdata->vif.type != NL80211_IFTYPE_MONITOR &&
                    netif_running(sdata->dev)) {
@@ -81,9 +88,9 @@ int __ieee80211_resume(struct ieee80211_hw *hw)
        }
 
        /* add STAs back */
-       list_for_each_entry(sta, &local->sta_list, list) {
-
-               if (local->ops->sta_notify) {
+       if (local->ops->sta_notify) {
+               spin_lock_irqsave(&local->sta_lock, flags);
+               list_for_each_entry(sta, &local->sta_list, list) {
                        if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
                                sdata = container_of(sdata->bss,
                                             struct ieee80211_sub_if_data,
@@ -92,6 +99,7 @@ int __ieee80211_resume(struct ieee80211_hw *hw)
                        local->ops->sta_notify(hw, &sdata->vif,
                                STA_NOTIFY_ADD, &sta->sta);
                }
+               spin_unlock_irqrestore(&local->sta_lock, flags);
        }
 
        /* add back keys */
@@ -110,5 +118,8 @@ int __ieee80211_resume(struct ieee80211_hw *hw)
        ieee80211_configure_filter(local);
        netif_addr_unlock_bh(local->mdev);
 
+       ieee80211_wake_queues_by_reason(hw,
+                       IEEE80211_QUEUE_STOP_REASON_SUSPEND);
+
        return 0;
 }