iwlwifi: serialize station management actions
[pandora-kernel.git] / drivers / net / wireless / iwlwifi / iwl-sta.c
index 8fec026..c27c13f 100644 (file)
 #include "iwl-core.h"
 #include "iwl-sta.h"
 
-u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr)
-{
-       int i;
-       int start = 0;
-       int ret = IWL_INVALID_STATION;
-       unsigned long flags;
-
-       if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) ||
-           (priv->iw_mode == NL80211_IFTYPE_AP))
-               start = IWL_STA_ID;
-
-       if (is_broadcast_ether_addr(addr))
-               return priv->hw_params.bcast_sta_id;
-
-       spin_lock_irqsave(&priv->sta_lock, flags);
-       for (i = start; i < priv->hw_params.max_stations; i++)
-               if (priv->stations[i].used &&
-                   (!compare_ether_addr(priv->stations[i].sta.sta.addr,
-                                        addr))) {
-                       ret = i;
-                       goto out;
-               }
-
-       IWL_DEBUG_ASSOC_LIMIT(priv, "can not find STA %pM total %d\n",
-                             addr, priv->num_stations);
-
- out:
-       /*
-        * It may be possible that more commands interacting with stations
-        * arrive before we completed processing the adding of
-        * station
-        */
-       if (ret != IWL_INVALID_STATION &&
-           (!(priv->stations[ret].used & IWL_STA_UCODE_ACTIVE) ||
-            ((priv->stations[ret].used & IWL_STA_UCODE_ACTIVE) &&
-             (priv->stations[ret].used & IWL_STA_UCODE_INPROGRESS)))) {
-               IWL_ERR(priv, "Requested station info for sta %d before ready.\n",
-                       ret);
-               ret = IWL_INVALID_STATION;
-       }
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
-       return ret;
-}
-EXPORT_SYMBOL(iwl_find_station);
-
 /* priv->sta_lock must be held */
 static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id)
 {
@@ -329,10 +284,12 @@ static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr,
        station->sta.sta.sta_id = sta_id;
        station->sta.station_flags = 0;
 
-       /* BCAST station and IBSS stations do not work in HT mode */
-       if (sta_id != priv->hw_params.bcast_sta_id &&
-           priv->iw_mode != NL80211_IFTYPE_ADHOC)
-               iwl_set_ht_add_station(priv, sta_id, ht_info);
+       /*
+        * OK to call unconditionally, since local stations (IBSS BSSID
+        * STA and broadcast STA) pass in a NULL ht_info, and mac80211
+        * doesn't allow HT IBSS.
+        */
+       iwl_set_ht_add_station(priv, sta_id, ht_info);
 
        /* 3945 only */
        rate = (priv->band == IEEE80211_BAND_5GHZ) ?
@@ -462,14 +419,11 @@ static struct iwl_link_quality_cmd *iwl_sta_alloc_lq(struct iwl_priv *priv,
 }
 
 /*
- * iwl_add_local_station - Add stations not requested by mac80211
- *
- * This will be either the broadcast station or the bssid station needed by
- * ad-hoc.
+ * iwl_add_bssid_station - Add the special IBSS BSSID station
  *
  * Function sleeps.
  */
-int iwl_add_local_station(struct iwl_priv *priv, const u8 *addr, bool init_rs,
+int iwl_add_bssid_station(struct iwl_priv *priv, const u8 *addr, bool init_rs,
                          u8 *sta_id_r)
 {
        int ret;
@@ -477,7 +431,7 @@ int iwl_add_local_station(struct iwl_priv *priv, const u8 *addr, bool init_rs,
        struct iwl_link_quality_cmd *link_cmd;
        unsigned long flags;
 
-       if (*sta_id_r)
+       if (sta_id_r)
                *sta_id_r = IWL_INVALID_STATION;
 
        ret = iwl_add_station_common(priv, addr, 0, NULL, &sta_id);
@@ -513,7 +467,7 @@ int iwl_add_local_station(struct iwl_priv *priv, const u8 *addr, bool init_rs,
 
        return 0;
 }
-EXPORT_SYMBOL(iwl_add_local_station);
+EXPORT_SYMBOL(iwl_add_bssid_station);
 
 /**
  * iwl_sta_ucode_deactivate - deactivate ucode status for a station
@@ -1012,18 +966,23 @@ static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
 
 void iwl_update_tkip_key(struct iwl_priv *priv,
                        struct ieee80211_key_conf *keyconf,
-                       const u8 *addr, u32 iv32, u16 *phase1key)
+                       struct ieee80211_sta *sta, u32 iv32, u16 *phase1key)
 {
-       u8 sta_id = IWL_INVALID_STATION;
+       u8 sta_id;
        unsigned long flags;
        int i;
 
-       sta_id = iwl_find_station(priv, addr);
-       if (sta_id == IWL_INVALID_STATION) {
-               IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
-                                  addr);
-               return;
-       }
+       if (sta) {
+               sta_id = iwl_sta_id(sta);
+
+               if (sta_id == IWL_INVALID_STATION) {
+                       IWL_DEBUG_MAC80211(priv, "leave - %pM not initialised.\n",
+                                          sta->addr);
+                       return;
+               }
+       } else
+               sta_id = priv->hw_params.bcast_sta_id;
+
 
        if (iwl_scan_cancel(priv)) {
                /* cancel scan failed, just live w/ bad key and rely
@@ -1414,10 +1373,14 @@ int iwl_mac_sta_remove(struct ieee80211_hw *hw,
 
        IWL_DEBUG_INFO(priv, "received request to remove station %pM\n",
                        sta->addr);
+       mutex_lock(&priv->mutex);
+       IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n",
+                       sta->addr);
        ret = iwl_remove_station(priv, sta_common->sta_id, sta->addr);
        if (ret)
                IWL_ERR(priv, "Error removing station %pM\n",
                        sta->addr);
+       mutex_unlock(&priv->mutex);
        return ret;
 }
 EXPORT_SYMBOL(iwl_mac_sta_remove);