headers: remove sched.h from interrupt.h
[safe/jmp/linux-2.6] / drivers / net / wireless / iwlwifi / iwl-tx.c
index 51ddbab..fb9bcfa 100644 (file)
@@ -28,6 +28,7 @@
  *****************************************************************************/
 
 #include <linux/etherdevice.h>
+#include <linux/sched.h>
 #include <net/mac80211.h>
 #include "iwl-eeprom.h"
 #include "iwl-dev.h"
@@ -197,6 +198,12 @@ void iwl_cmd_queue_free(struct iwl_priv *priv)
                pci_free_consistent(dev, priv->hw_params.tfd_size *
                                    txq->q.n_bd, txq->tfds, txq->q.dma_addr);
 
+       /* deallocate arrays */
+       kfree(txq->cmd);
+       kfree(txq->meta);
+       txq->cmd = NULL;
+       txq->meta = NULL;
+
        /* 0-fill queue descriptor structure */
        memset(txq, 0, sizeof(*txq));
 }
@@ -566,62 +573,81 @@ static void iwl_tx_cmd_build_basic(struct iwl_priv *priv,
 static void iwl_tx_cmd_build_rate(struct iwl_priv *priv,
                              struct iwl_tx_cmd *tx_cmd,
                              struct ieee80211_tx_info *info,
-                             __le16 fc, int sta_id,
-                             int is_hcca)
+                             __le16 fc, int is_hcca)
 {
-       u32 rate_flags = 0;
+       u32 rate_flags;
        int rate_idx;
-       u8 rts_retry_limit = 0;
-       u8 data_retry_limit = 0;
+       u8 rts_retry_limit;
+       u8 data_retry_limit;
        u8 rate_plcp;
 
-       rate_idx = min(ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xffff,
-                       IWL_RATE_COUNT - 1);
-
-       rate_plcp = iwl_rates[rate_idx].plcp;
-
-       rts_retry_limit = (is_hcca) ?
-           RTS_HCCA_RETRY_LIMIT : RTS_DFAULT_RETRY_LIMIT;
-
-       if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
-               rate_flags |= RATE_MCS_CCK_MSK;
-
-
-       if (ieee80211_is_probe_resp(fc)) {
-               data_retry_limit = 3;
-               if (data_retry_limit < rts_retry_limit)
-                       rts_retry_limit = data_retry_limit;
-       } else
-               data_retry_limit = IWL_DEFAULT_TX_RETRY;
-
+       /* Set retry limit on DATA packets and Probe Responses*/
        if (priv->data_retry_limit != -1)
                data_retry_limit = priv->data_retry_limit;
+       else if (ieee80211_is_probe_resp(fc))
+               data_retry_limit = 3;
+       else
+               data_retry_limit = IWL_DEFAULT_TX_RETRY;
+       tx_cmd->data_retry_limit = data_retry_limit;
 
+       /* Set retry limit on RTS packets */
+       rts_retry_limit = (is_hcca) ?  RTS_HCCA_RETRY_LIMIT :
+               RTS_DFAULT_RETRY_LIMIT;
+       if (data_retry_limit < rts_retry_limit)
+               rts_retry_limit = data_retry_limit;
+       tx_cmd->rts_retry_limit = rts_retry_limit;
 
+       /* DATA packets will use the uCode station table for rate/antenna
+        * selection */
        if (ieee80211_is_data(fc)) {
                tx_cmd->initial_rate_index = 0;
                tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
-       } else {
-               switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
-               case cpu_to_le16(IEEE80211_STYPE_AUTH):
-               case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
-               case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
-               case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
-                       if (tx_cmd->tx_flags & TX_CMD_FLG_RTS_MSK) {
-                               tx_cmd->tx_flags &= ~TX_CMD_FLG_RTS_MSK;
-                               tx_cmd->tx_flags |= TX_CMD_FLG_CTS_MSK;
-                       }
-                       break;
-               default:
-                       break;
-               }
+               return;
+       }
+
+       /**
+        * If the current TX rate stored in mac80211 has the MCS bit set, it's
+        * not really a TX rate.  Thus, we use the lowest supported rate for
+        * this band.  Also use the lowest supported rate if the stored rate
+        * index is invalid.
+        */
+       rate_idx = info->control.rates[0].idx;
+       if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS ||
+                       (rate_idx < 0) || (rate_idx > IWL_RATE_COUNT_LEGACY))
+               rate_idx = rate_lowest_index(&priv->bands[info->band],
+                               info->control.sta);
+       /* For 5 GHZ band, remap mac80211 rate indices into driver indices */
+       if (info->band == IEEE80211_BAND_5GHZ)
+               rate_idx += IWL_FIRST_OFDM_RATE;
+       /* Get PLCP rate for tx_cmd->rate_n_flags */
+       rate_plcp = iwl_rates[rate_idx].plcp;
+       /* Zero out flags for this packet */
+       rate_flags = 0;
 
-               priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant);
-               rate_flags |= iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
+       /* Set CCK flag as needed */
+       if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
+               rate_flags |= RATE_MCS_CCK_MSK;
+
+       /* Set up RTS and CTS flags for certain packets */
+       switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
+       case cpu_to_le16(IEEE80211_STYPE_AUTH):
+       case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
+       case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
+       case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
+               if (tx_cmd->tx_flags & TX_CMD_FLG_RTS_MSK) {
+                       tx_cmd->tx_flags &= ~TX_CMD_FLG_RTS_MSK;
+                       tx_cmd->tx_flags |= TX_CMD_FLG_CTS_MSK;
+               }
+               break;
+       default:
+               break;
        }
 
-       tx_cmd->rts_retry_limit = rts_retry_limit;
-       tx_cmd->data_retry_limit = data_retry_limit;
+       /* Set up antennas */
+       priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant);
+       rate_flags |= iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
+
+       /* Set the rate in the TX cmd */
        tx_cmd->rate_n_flags = iwl_hw_set_rate_n_flags(rate_plcp, rate_flags);
 }
 
@@ -668,14 +694,6 @@ static void iwl_tx_cmd_build_hwcrypto(struct iwl_priv *priv,
        }
 }
 
-static void iwl_update_tx_stats(struct iwl_priv *priv, u16 fc, u16 len)
-{
-       /* 0 - mgmt, 1 - cnt, 2 - data */
-       int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
-       priv->tx_stats[idx].cnt++;
-       priv->tx_stats[idx].bytes += len;
-}
-
 /*
  * start REPLY_TX command process
  */
@@ -709,12 +727,6 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
                goto drop_unlock;
        }
 
-       if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) ==
-            IWL_INVALID_RATE) {
-               IWL_ERR(priv, "ERROR: No TX rate available.\n");
-               goto drop_unlock;
-       }
-
        fc = hdr->frame_control;
 
 #ifdef CONFIG_IWLWIFI_DEBUG
@@ -726,10 +738,9 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
                IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
 #endif
 
-       /* drop all data frame if we are not associated */
+       /* drop all non-injected data frame if we are not associated */
        if (ieee80211_is_data(fc) &&
-           (!iwl_is_monitor_mode(priv) ||
-           !(info->flags & IEEE80211_TX_CTL_INJECTED)) && /* packet injection */
+           !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
            (!iwl_is_associated(priv) ||
             ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id) ||
             !priv->assoc_station_added)) {
@@ -737,16 +748,17 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
                goto drop_unlock;
        }
 
-       spin_unlock_irqrestore(&priv->lock, flags);
-
        hdr_len = ieee80211_hdrlen(fc);
 
        /* Find (or create) index into station table for destination station */
-       sta_id = iwl_get_sta_id(priv, hdr);
+       if (info->flags & IEEE80211_TX_CTL_INJECTED)
+               sta_id = priv->hw_params.bcast_sta_id;
+       else
+               sta_id = iwl_get_sta_id(priv, hdr);
        if (sta_id == IWL_INVALID_STATION) {
                IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
                               hdr->addr1);
-               goto drop;
+               goto drop_unlock;
        }
 
        IWL_DEBUG_TX(priv, "station Id %d\n", sta_id);
@@ -755,6 +767,8 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
        if (ieee80211_is_data_qos(fc)) {
                qc = ieee80211_get_qos_ctl(hdr);
                tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
+               if (unlikely(tid >= MAX_TID_COUNT))
+                       goto drop_unlock;
                seq_number = priv->stations[sta_id].tid[tid].seq_number;
                seq_number &= IEEE80211_SCTL_SEQ;
                hdr->seq_ctrl = hdr->seq_ctrl &
@@ -764,14 +778,17 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
                /* aggregation is on for this <sta,tid> */
                if (info->flags & IEEE80211_TX_CTL_AMPDU)
                        txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
-               priv->stations[sta_id].tid[tid].tfds_in_queue++;
        }
 
        txq = &priv->txq[txq_id];
        swq_id = txq->swq_id;
        q = &txq->q;
 
-       spin_lock_irqsave(&priv->lock, flags);
+       if (unlikely(iwl_queue_space(q) < q->high_mark))
+               goto drop_unlock;
+
+       if (ieee80211_is_data_qos(fc))
+               priv->stations[sta_id].tid[tid].tfds_in_queue++;
 
        /* Set up driver data for this TFD */
        memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
@@ -807,12 +824,12 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
 
        /* TODO need this for burst mode later on */
        iwl_tx_cmd_build_basic(priv, tx_cmd, info, hdr, sta_id);
+       iwl_dbg_log_tx_data_frame(priv, len, hdr);
 
        /* set is_hcca to 0; it probably will never be implemented */
-       iwl_tx_cmd_build_rate(priv, tx_cmd, info, fc, sta_id, 0);
-
-       iwl_update_tx_stats(priv, le16_to_cpu(fc), len);
+       iwl_tx_cmd_build_rate(priv, tx_cmd, info, fc, 0);
 
+       iwl_update_stats(priv, true, fc, len);
        /*
         * Use the first empty entry in this queue's command buffer array
         * to contain the Tx command and MAC header concatenated together
@@ -883,8 +900,8 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
        IWL_DEBUG_TX(priv, "sequence nr = 0X%x \n",
                     le16_to_cpu(out_cmd->hdr.sequence));
        IWL_DEBUG_TX(priv, "tx_flags = 0X%x \n", le32_to_cpu(tx_cmd->tx_flags));
-       iwl_print_hex_dump(IWL_DL_TX, (u8 *)tx_cmd, sizeof(*tx_cmd));
-       iwl_print_hex_dump(IWL_DL_TX, (u8 *)tx_cmd->hdr, hdr_len);
+       iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd, sizeof(*tx_cmd));
+       iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd->hdr, hdr_len);
 
        /* Set up entry for this TFD in Tx byte-count array */
        if (info->flags & IEEE80211_TX_CTL_AMPDU)
@@ -917,7 +934,6 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
 
 drop_unlock:
        spin_unlock_irqrestore(&priv->lock, flags);
-drop:
        return -1;
 }
 EXPORT_SYMBOL(iwl_tx_skb);
@@ -970,6 +986,7 @@ int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
        out_cmd = txq->cmd[idx];
        out_meta = &txq->meta[idx];
 
+       memset(out_meta, 0, sizeof(*out_meta)); /* re-initialize to NULL */
        out_meta->flags = cmd->flags;
        if (cmd->flags & CMD_WANT_SKB)
                out_meta->source = cmd;
@@ -1132,7 +1149,7 @@ void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
                  txq_id, sequence,
                  priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
                  priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
-               iwl_print_hex_error(priv, rxb, 32);
+               iwl_print_hex_error(priv, pkt, 32);
                return;
        }
 
@@ -1144,8 +1161,8 @@ void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
        if (meta->flags & CMD_WANT_SKB) {
                meta->source->reply_skb = rxb->skb;
                rxb->skb = NULL;
-       } else if (meta->callback && !meta->callback(priv, cmd, rxb->skb))
-               rxb->skb = NULL;
+       } else if (meta->callback)
+               meta->callback(priv, cmd, rxb->skb);
 
        iwl_hcmd_queue_reclaim(priv, txq_id, index, cmd_index);
 
@@ -1194,6 +1211,8 @@ int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn)
                IWL_ERR(priv, "Start AGG on invalid station\n");
                return -ENXIO;
        }
+       if (unlikely(tid >= MAX_TID_COUNT))
+               return -EINVAL;
 
        if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) {
                IWL_ERR(priv, "Start AGG when state is not IWL_AGG_OFF !\n");
@@ -1243,6 +1262,9 @@ int iwl_tx_agg_stop(struct iwl_priv *priv , const u8 *ra, u16 tid)
                return -EINVAL;
        }
 
+       if (unlikely(tid >= MAX_TID_COUNT))
+               return -EINVAL;
+
        if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
                tx_fifo_id = default_tid_to_tx_fifo[tid];
        else