iwlagn: rename all the mac80211 callback functions
[cascardo/linux.git] / drivers / net / wireless / iwlwifi / iwl-sta.c
index 65386e5..586007e 100644 (file)
@@ -38,7 +38,7 @@
 #include "iwl-trans.h"
 #include "iwl-agn.h"
 
-/* priv->sta_lock must be held */
+/* priv->shrd->sta_lock must be held */
 static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id)
 {
 
@@ -59,8 +59,7 @@ static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id)
 
 static int iwl_process_add_sta_resp(struct iwl_priv *priv,
                                    struct iwl_addsta_cmd *addsta,
-                                   struct iwl_rx_packet *pkt,
-                                   bool sync)
+                                   struct iwl_rx_packet *pkt)
 {
        u8 sta_id = addsta->sta.sta_id;
        unsigned long flags;
@@ -75,7 +74,7 @@ static int iwl_process_add_sta_resp(struct iwl_priv *priv,
        IWL_DEBUG_INFO(priv, "Processing response for adding station %u\n",
                       sta_id);
 
-       spin_lock_irqsave(&priv->sta_lock, flags);
+       spin_lock_irqsave(&priv->shrd->sta_lock, flags);
 
        switch (pkt->u.add_sta.status) {
        case ADD_STA_SUCCESS_MSK:
@@ -118,20 +117,19 @@ static int iwl_process_add_sta_resp(struct iwl_priv *priv,
                       priv->stations[sta_id].sta.mode ==
                       STA_CONTROL_MODIFY_MSK ? "Modified" : "Added",
                       addsta->sta.addr);
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
+       spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
 
        return ret;
 }
 
-static void iwl_add_sta_callback(struct iwl_priv *priv,
-                                struct iwl_device_cmd *cmd,
-                                struct iwl_rx_packet *pkt)
+int iwl_add_sta_callback(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb,
+                              struct iwl_device_cmd *cmd)
 {
+       struct iwl_rx_packet *pkt = rxb_addr(rxb);
        struct iwl_addsta_cmd *addsta =
-               (struct iwl_addsta_cmd *)cmd->cmd.payload;
-
-       iwl_process_add_sta_resp(priv, addsta, pkt, false);
+               (struct iwl_addsta_cmd *) cmd->payload;
 
+       return iwl_process_add_sta_resp(priv, addsta, pkt);
 }
 
 static u16 iwlagn_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
@@ -147,7 +145,6 @@ static u16 iwlagn_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
 int iwl_send_add_sta(struct iwl_priv *priv,
                     struct iwl_addsta_cmd *sta, u8 flags)
 {
-       struct iwl_rx_packet *pkt = NULL;
        int ret = 0;
        u8 data[sizeof(*sta)];
        struct iwl_host_cmd cmd = {
@@ -160,26 +157,26 @@ int iwl_send_add_sta(struct iwl_priv *priv,
        IWL_DEBUG_INFO(priv, "Adding sta %u (%pM) %ssynchronously\n",
                       sta_id, sta->sta.addr, flags & CMD_ASYNC ?  "a" : "");
 
-       if (flags & CMD_ASYNC)
-               cmd.callback = iwl_add_sta_callback;
-       else {
+       if (!(flags & CMD_ASYNC)) {
                cmd.flags |= CMD_WANT_SKB;
                might_sleep();
        }
 
        cmd.len[0] = iwlagn_build_addsta_hcmd(sta, data);
-       ret = trans_send_cmd(priv, &cmd);
+       ret = iwl_trans_send_cmd(trans(priv), &cmd);
 
        if (ret || (flags & CMD_ASYNC))
                return ret;
+       /*else the command was successfully sent in SYNC mode, need to free
+        * the reply page */
 
-       if (ret == 0) {
-               pkt = (struct iwl_rx_packet *)cmd.reply_page;
-               ret = iwl_process_add_sta_resp(priv, sta, pkt, true);
-       }
-       iwl_free_pages(priv, cmd.reply_page);
+       iwl_free_pages(priv->shrd, cmd.reply_page);
 
-       return ret;
+       if (cmd.handler_status)
+               IWL_ERR(priv, "%s - error in the CMD response %d", __func__,
+                       cmd.handler_status);
+
+       return cmd.handler_status;
 }
 
 static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
@@ -251,7 +248,7 @@ u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
        else if (is_broadcast_ether_addr(addr))
                sta_id = ctx->bcast_sta_id;
        else
-               for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
+               for (i = IWL_STA_ID; i < IWLAGN_STATION_COUNT; i++) {
                        if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
                                                addr)) {
                                sta_id = i;
@@ -304,7 +301,7 @@ u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
        station->ctxid = ctx->ctxid;
 
        if (sta) {
-               struct iwl_station_priv_common *sta_priv;
+               struct iwl_station_priv *sta_priv;
 
                sta_priv = (void *)sta->drv_priv;
                sta_priv->ctx = ctx;
@@ -336,12 +333,12 @@ int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
        struct iwl_addsta_cmd sta_cmd;
 
        *sta_id_r = 0;
-       spin_lock_irqsave(&priv->sta_lock, flags_spin);
+       spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin);
        sta_id = iwl_prep_station(priv, ctx, addr, is_ap, sta);
        if (sta_id == IWL_INVALID_STATION) {
                IWL_ERR(priv, "Unable to prepare station %pM for addition\n",
                        addr);
-               spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
+               spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin);
                return -EINVAL;
        }
 
@@ -353,7 +350,7 @@ int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
        if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) {
                IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n",
                               sta_id);
-               spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
+               spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin);
                return -EEXIST;
        }
 
@@ -361,23 +358,23 @@ int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
            (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
                IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n",
                                sta_id, addr);
-               spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
+               spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin);
                return -EEXIST;
        }
 
        priv->stations[sta_id].used |= IWL_STA_UCODE_INPROGRESS;
        memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
-       spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
+       spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin);
 
        /* Add station to device's station table */
        ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
        if (ret) {
-               spin_lock_irqsave(&priv->sta_lock, flags_spin);
+               spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin);
                IWL_ERR(priv, "Adding station %pM failed.\n",
                        priv->stations[sta_id].sta.sta.addr);
                priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
                priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
-               spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
+               spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin);
        }
        *sta_id_r = sta_id;
        return ret;
@@ -386,7 +383,7 @@ int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
 /**
  * iwl_sta_ucode_deactivate - deactivate ucode status for a station
  *
- * priv->sta_lock must be held
+ * priv->shrd->sta_lock must be held
  */
 static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id)
 {
@@ -424,7 +421,7 @@ static int iwl_send_remove_station(struct iwl_priv *priv,
 
        cmd.flags |= CMD_WANT_SKB;
 
-       ret = trans_send_cmd(priv, &cmd);
+       ret = iwl_trans_send_cmd(trans(priv), &cmd);
 
        if (ret)
                return ret;
@@ -440,9 +437,11 @@ static int iwl_send_remove_station(struct iwl_priv *priv,
                switch (pkt->u.rem_sta.status) {
                case REM_STA_SUCCESS_MSK:
                        if (!temporary) {
-                               spin_lock_irqsave(&priv->sta_lock, flags_spin);
+                               spin_lock_irqsave(&priv->shrd->sta_lock,
+                                       flags_spin);
                                iwl_sta_ucode_deactivate(priv, sta_id);
-                               spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
+                               spin_unlock_irqrestore(&priv->shrd->sta_lock,
+                                       flags_spin);
                        }
                        IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n");
                        break;
@@ -452,7 +451,7 @@ static int iwl_send_remove_station(struct iwl_priv *priv,
                        break;
                }
        }
-       iwl_free_pages(priv, cmd.reply_page);
+       iwl_free_pages(priv->shrd, cmd.reply_page);
 
        return ret;
 }
@@ -465,7 +464,7 @@ int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id,
 {
        unsigned long flags;
 
-       if (!iwl_is_ready(priv)) {
+       if (!iwl_is_ready(priv->shrd)) {
                IWL_DEBUG_INFO(priv,
                        "Unable to remove station %pM, device not ready.\n",
                        addr);
@@ -483,7 +482,7 @@ int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id,
        if (WARN_ON(sta_id == IWL_INVALID_STATION))
                return -EINVAL;
 
-       spin_lock_irqsave(&priv->sta_lock, flags);
+       spin_lock_irqsave(&priv->shrd->sta_lock, flags);
 
        if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) {
                IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n",
@@ -509,11 +508,11 @@ int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id,
        if (WARN_ON(priv->num_stations < 0))
                priv->num_stations = 0;
 
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
+       spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
 
        return iwl_send_remove_station(priv, addr, sta_id, false);
 out_err:
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
+       spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
        return -EINVAL;
 }
 
@@ -534,8 +533,8 @@ void iwl_clear_ucode_stations(struct iwl_priv *priv,
 
        IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver\n");
 
-       spin_lock_irqsave(&priv->sta_lock, flags_spin);
-       for (i = 0; i < priv->hw_params.max_stations; i++) {
+       spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin);
+       for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
                if (ctx && ctx->ctxid != priv->stations[i].ctxid)
                        continue;
 
@@ -545,7 +544,7 @@ void iwl_clear_ucode_stations(struct iwl_priv *priv,
                        cleared = true;
                }
        }
-       spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
+       spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin);
 
        if (!cleared)
                IWL_DEBUG_INFO(priv, "No active stations found to be cleared\n");
@@ -569,14 +568,14 @@ void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
        int ret;
        bool send_lq;
 
-       if (!iwl_is_ready(priv)) {
+       if (!iwl_is_ready(priv->shrd)) {
                IWL_DEBUG_INFO(priv, "Not ready yet, not restoring any stations.\n");
                return;
        }
 
        IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n");
-       spin_lock_irqsave(&priv->sta_lock, flags_spin);
-       for (i = 0; i < priv->hw_params.max_stations; i++) {
+       spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin);
+       for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
                if (ctx->ctxid != priv->stations[i].ctxid)
                        continue;
                if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) &&
@@ -589,25 +588,31 @@ void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
                }
        }
 
-       for (i = 0; i < priv->hw_params.max_stations; i++) {
+       for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
                if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) {
                        memcpy(&sta_cmd, &priv->stations[i].sta,
                               sizeof(struct iwl_addsta_cmd));
                        send_lq = false;
                        if (priv->stations[i].lq) {
-                               memcpy(&lq, priv->stations[i].lq,
-                                      sizeof(struct iwl_link_quality_cmd));
+                               if (priv->shrd->wowlan)
+                                       iwl_sta_fill_lq(priv, ctx, i, &lq);
+                               else
+                                       memcpy(&lq, priv->stations[i].lq,
+                                              sizeof(struct iwl_link_quality_cmd));
                                send_lq = true;
                        }
-                       spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
+                       spin_unlock_irqrestore(&priv->shrd->sta_lock,
+                                              flags_spin);
                        ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
                        if (ret) {
-                               spin_lock_irqsave(&priv->sta_lock, flags_spin);
+                               spin_lock_irqsave(&priv->shrd->sta_lock,
+                                                 flags_spin);
                                IWL_ERR(priv, "Adding station %pM failed.\n",
                                        priv->stations[i].sta.sta.addr);
                                priv->stations[i].used &= ~IWL_STA_DRIVER_ACTIVE;
                                priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
-                               spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
+                               spin_unlock_irqrestore(&priv->shrd->sta_lock,
+                                                      flags_spin);
                        }
                        /*
                         * Rate scaling has already been initialized, send
@@ -615,12 +620,12 @@ void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
                         */
                        if (send_lq)
                                iwl_send_lq_cmd(priv, ctx, &lq, CMD_SYNC, true);
-                       spin_lock_irqsave(&priv->sta_lock, flags_spin);
+                       spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin);
                        priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
                }
        }
 
-       spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
+       spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin);
        if (!found)
                IWL_DEBUG_INFO(priv, "Restoring all known stations .... no stations to be restored.\n");
        else
@@ -636,9 +641,9 @@ void iwl_reprogram_ap_sta(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
        struct iwl_link_quality_cmd lq;
        bool active;
 
-       spin_lock_irqsave(&priv->sta_lock, flags);
+       spin_lock_irqsave(&priv->shrd->sta_lock, flags);
        if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) {
-               spin_unlock_irqrestore(&priv->sta_lock, flags);
+               spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
                return;
        }
 
@@ -648,7 +653,7 @@ void iwl_reprogram_ap_sta(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
 
        active = priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE;
        priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
+       spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
 
        if (active) {
                ret = iwl_send_remove_station(
@@ -658,9 +663,9 @@ void iwl_reprogram_ap_sta(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
                        IWL_ERR(priv, "failed to remove STA %pM (%d)\n",
                                priv->stations[sta_id].sta.sta.addr, ret);
        }
-       spin_lock_irqsave(&priv->sta_lock, flags);
+       spin_lock_irqsave(&priv->shrd->sta_lock, flags);
        priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE;
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
+       spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
 
        ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
        if (ret)
@@ -669,7 +674,7 @@ void iwl_reprogram_ap_sta(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
        iwl_send_lq_cmd(priv, ctx, &lq, CMD_SYNC, true);
 }
 
-int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
+int iwl_get_free_ucode_key_offset(struct iwl_priv *priv)
 {
        int i;
 
@@ -685,8 +690,8 @@ void iwl_dealloc_bcast_stations(struct iwl_priv *priv)
        unsigned long flags;
        int i;
 
-       spin_lock_irqsave(&priv->sta_lock, flags);
-       for (i = 0; i < priv->hw_params.max_stations; i++) {
+       spin_lock_irqsave(&priv->shrd->sta_lock, flags);
+       for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
                if (!(priv->stations[i].used & IWL_STA_BCAST))
                        continue;
 
@@ -697,7 +702,7 @@ void iwl_dealloc_bcast_stations(struct iwl_priv *priv)
                kfree(priv->stations[i].lq);
                priv->stations[i].lq = NULL;
        }
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
+       spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
 }
 
 #ifdef CONFIG_IWLWIFI_DEBUG
@@ -781,19 +786,19 @@ int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
                return -EINVAL;
 
 
-       spin_lock_irqsave(&priv->sta_lock, flags_spin);
+       spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin);
        if (!(priv->stations[lq->sta_id].used & IWL_STA_DRIVER_ACTIVE)) {
-               spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
+               spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin);
                return -EINVAL;
        }
-       spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
+       spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin);
 
        iwl_dump_lq_cmd(priv, lq);
        if (WARN_ON(init && (cmd.flags & CMD_ASYNC)))
                return -EINVAL;
 
        if (is_lq_table_valid(priv, ctx, lq))
-               ret = trans_send_cmd(priv, &cmd);
+               ret = iwl_trans_send_cmd(trans(priv), &cmd);
        else
                ret = -EINVAL;
 
@@ -803,30 +808,32 @@ int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
        if (init) {
                IWL_DEBUG_INFO(priv, "init LQ command complete, clearing sta addition status for sta %d\n",
                               lq->sta_id);
-               spin_lock_irqsave(&priv->sta_lock, flags_spin);
+               spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin);
                priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
-               spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
+               spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin);
        }
        return ret;
 }
 
-int iwl_mac_sta_remove(struct ieee80211_hw *hw,
+int iwlagn_mac_sta_remove(struct ieee80211_hw *hw,
                       struct ieee80211_vif *vif,
                       struct ieee80211_sta *sta)
 {
        struct iwl_priv *priv = hw->priv;
-       struct iwl_station_priv_common *sta_common = (void *)sta->drv_priv;
+       struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
        int ret;
 
-       IWL_DEBUG_INFO(priv, "received request to remove station %pM\n",
-                       sta->addr);
-       mutex_lock(&priv->mutex);
+       IWL_DEBUG_MAC80211(priv, "enter: received request to remove "
+                          "station %pM\n", sta->addr);
+       mutex_lock(&priv->shrd->mutex);
        IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n",
                        sta->addr);
-       ret = iwl_remove_station(priv, sta_common->sta_id, sta->addr);
+       ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr);
        if (ret)
                IWL_ERR(priv, "Error removing station %pM\n",
                        sta->addr);
-       mutex_unlock(&priv->mutex);
+       mutex_unlock(&priv->shrd->mutex);
+       IWL_DEBUG_MAC80211(priv, "leave\n");
+
        return ret;
 }