rt2x00: Add support for retry rates
[pandora-kernel.git] / drivers / net / wireless / rt2x00 / rt2x00dev.c
index 5752aaa..9ab70e4 100644 (file)
@@ -40,8 +40,7 @@ int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev)
         * Don't enable the radio twice.
         * And check if the hardware button has been disabled.
         */
-       if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags) ||
-           test_bit(DEVICE_STATE_DISABLED_RADIO_HW, &rt2x00dev->flags))
+       if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
                return 0;
 
        /*
@@ -187,7 +186,6 @@ static void rt2x00lib_intf_scheduled(struct work_struct *work)
 static void rt2x00lib_beacondone_iter(void *data, u8 *mac,
                                      struct ieee80211_vif *vif)
 {
-       struct rt2x00_dev *rt2x00dev = data;
        struct rt2x00_intf *intf = vif_to_intf(vif);
 
        if (vif->type != NL80211_IFTYPE_AP &&
@@ -196,12 +194,6 @@ static void rt2x00lib_beacondone_iter(void *data, u8 *mac,
            vif->type != NL80211_IFTYPE_WDS)
                return;
 
-       /*
-        * Clean up the beacon skb.
-        */
-       rt2x00queue_free_skb(rt2x00dev, intf->beacon->skb);
-       intf->beacon->skb = NULL;
-
        spin_lock(&intf->lock);
        intf->delayed_flags |= DELAYED_UPDATE_BEACON;
        spin_unlock(&intf->lock);
@@ -216,7 +208,7 @@ void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev)
                                                   rt2x00lib_beacondone_iter,
                                                   rt2x00dev);
 
-       queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->intf_work);
+       ieee80211_queue_work(rt2x00dev->hw, &rt2x00dev->intf_work);
 }
 EXPORT_SYMBOL_GPL(rt2x00lib_beacondone);
 
@@ -227,13 +219,21 @@ void rt2x00lib_txdone(struct queue_entry *entry,
        struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
        struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
        enum data_queue_qid qid = skb_get_queue_mapping(entry->skb);
-       u8 rate_idx, rate_flags;
+       unsigned int header_length = ieee80211_get_hdrlen_from_skb(entry->skb);
+       u8 rate_idx, rate_flags, retry_rates;
+       unsigned int i;
 
        /*
         * Unmap the skb.
         */
        rt2x00queue_unmap_skb(rt2x00dev, entry->skb);
 
+       /*
+        * Remove L2 padding which was added during
+        */
+       if (test_bit(DRIVER_REQUIRE_L2PAD, &rt2x00dev->flags))
+               rt2x00queue_payload_align(entry->skb, true, header_length);
+
        /*
         * If the IV/EIV data was stripped from the frame before it was
         * passed to the hardware, we should now reinsert it again because
@@ -241,7 +241,7 @@ void rt2x00lib_txdone(struct queue_entry *entry,
         * frame as it was passed to us.
         */
        if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags))
-               rt2x00crypto_tx_insert_iv(entry->skb);
+               rt2x00crypto_tx_insert_iv(entry->skb, header_length);
 
        /*
         * Send frame to debugfs immediately, after this call is completed
@@ -253,32 +253,46 @@ void rt2x00lib_txdone(struct queue_entry *entry,
         * Update TX statistics.
         */
        rt2x00dev->link.qual.tx_success +=
-           test_bit(TXDONE_SUCCESS, &txdesc->flags);
+           test_bit(TXDONE_SUCCESS, &txdesc->flags) ||
+           test_bit(TXDONE_UNKNOWN, &txdesc->flags);
        rt2x00dev->link.qual.tx_failed +=
            test_bit(TXDONE_FAILURE, &txdesc->flags);
 
        rate_idx = skbdesc->tx_rate_idx;
        rate_flags = skbdesc->tx_rate_flags;
+       retry_rates = test_bit(TXDONE_FALLBACK, &txdesc->flags) ?
+           (txdesc->retry + 1) : 1;
 
        /*
         * Initialize TX status
         */
        memset(&tx_info->status, 0, sizeof(tx_info->status));
        tx_info->status.ack_signal = 0;
-       tx_info->status.rates[0].idx = rate_idx;
-       tx_info->status.rates[0].flags = rate_flags;
-       tx_info->status.rates[0].count = txdesc->retry + 1;
-       tx_info->status.rates[1].idx = -1; /* terminate */
+
+       /*
+        * Frame was send with retries, hardware tried
+        * different rates to send out the frame, at each
+        * retry it lowered the rate 1 step.
+        */
+       for (i = 0; i < retry_rates && i < IEEE80211_TX_MAX_RATES; i++) {
+               tx_info->status.rates[i].idx = rate_idx - i;
+               tx_info->status.rates[i].flags = rate_flags;
+               tx_info->status.rates[i].count = 1;
+       }
+       if (i < (IEEE80211_TX_MAX_RATES -1))
+               tx_info->status.rates[i].idx = -1; /* terminate */
 
        if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK)) {
-               if (test_bit(TXDONE_SUCCESS, &txdesc->flags))
+               if (test_bit(TXDONE_SUCCESS, &txdesc->flags) ||
+                               test_bit(TXDONE_UNKNOWN, &txdesc->flags))
                        tx_info->flags |= IEEE80211_TX_STAT_ACK;
                else if (test_bit(TXDONE_FAILURE, &txdesc->flags))
                        rt2x00dev->low_level_stats.dot11ACKFailureCount++;
        }
 
        if (rate_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
-               if (test_bit(TXDONE_SUCCESS, &txdesc->flags))
+               if (test_bit(TXDONE_SUCCESS, &txdesc->flags) ||
+                               test_bit(TXDONE_UNKNOWN, &txdesc->flags))
                        rt2x00dev->low_level_stats.dot11RTSSuccessCount++;
                else if (test_bit(TXDONE_FAILURE, &txdesc->flags))
                        rt2x00dev->low_level_stats.dot11RTSFailureCount++;
@@ -316,19 +330,54 @@ void rt2x00lib_txdone(struct queue_entry *entry,
 }
 EXPORT_SYMBOL_GPL(rt2x00lib_txdone);
 
+static int rt2x00lib_rxdone_read_signal(struct rt2x00_dev *rt2x00dev,
+                                       struct rxdone_entry_desc *rxdesc)
+{
+       struct ieee80211_supported_band *sband;
+       const struct rt2x00_rate *rate;
+       unsigned int i;
+       int signal;
+       int type;
+
+       /*
+        * For non-HT rates the MCS value needs to contain the
+        * actually used rate modulation (CCK or OFDM).
+        */
+       if (rxdesc->dev_flags & RXDONE_SIGNAL_MCS)
+               signal = RATE_MCS(rxdesc->rate_mode, rxdesc->signal);
+       else
+               signal = rxdesc->signal;
+
+       type = (rxdesc->dev_flags & RXDONE_SIGNAL_MASK);
+
+       sband = &rt2x00dev->bands[rt2x00dev->curr_band];
+       for (i = 0; i < sband->n_bitrates; i++) {
+               rate = rt2x00_get_rate(sband->bitrates[i].hw_value);
+
+               if (((type == RXDONE_SIGNAL_PLCP) &&
+                    (rate->plcp == signal)) ||
+                   ((type == RXDONE_SIGNAL_BITRATE) &&
+                     (rate->bitrate == signal)) ||
+                   ((type == RXDONE_SIGNAL_MCS) &&
+                     (rate->mcs == signal))) {
+                       return i;
+               }
+       }
+
+       WARNING(rt2x00dev, "Frame received with unrecognized signal, "
+               "signal=0x%.4x, type=%d.\n", signal, type);
+       return 0;
+}
+
 void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
                      struct queue_entry *entry)
 {
        struct rxdone_entry_desc rxdesc;
        struct sk_buff *skb;
        struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status;
-       struct ieee80211_supported_band *sband;
-       const struct rt2x00_rate *rate;
        unsigned int header_length;
-       unsigned int align;
-       unsigned int i;
-       int idx = -1;
-
+       bool l2pad;
+       int rate_idx;
        /*
         * Allocate a new sk_buffer. If no new buffer available, drop the
         * received frame and reuse the existing buffer.
@@ -348,12 +397,15 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
        memset(&rxdesc, 0, sizeof(rxdesc));
        rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc);
 
+       /* Trim buffer to correct size */
+       skb_trim(entry->skb, rxdesc.size);
+
        /*
         * The data behind the ieee80211 header must be
         * aligned on a 4 byte boundary.
         */
        header_length = ieee80211_get_hdrlen_from_skb(entry->skb);
-       align = ((unsigned long)(entry->skb->data + header_length)) & 3;
+       l2pad = !!(rxdesc.dev_flags & RXDONE_L2PAD);
 
        /*
         * Hardware might have stripped the IV/EIV/ICV data,
@@ -362,40 +414,24 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
         * in which case we should reinsert the data into the frame.
         */
        if ((rxdesc.dev_flags & RXDONE_CRYPTO_IV) &&
-           (rxdesc.flags & RX_FLAG_IV_STRIPPED)) {
-               rt2x00crypto_rx_insert_iv(entry->skb, align,
-                                         header_length, &rxdesc);
-       } else if (align) {
-               skb_push(entry->skb, align);
-               /* Move entire frame in 1 command */
-               memmove(entry->skb->data, entry->skb->data + align,
-                       rxdesc.size);
-       }
-
-       /* Update data pointers, trim buffer to correct size */
-       skb_trim(entry->skb, rxdesc.size);
+           (rxdesc.flags & RX_FLAG_IV_STRIPPED))
+               rt2x00crypto_rx_insert_iv(entry->skb, l2pad, header_length,
+                                         &rxdesc);
+       else
+               rt2x00queue_payload_align(entry->skb, l2pad, header_length);
 
        /*
-        * Update RX statistics.
+        * Check if the frame was received using HT. In that case,
+        * the rate is the MCS index and should be passed to mac80211
+        * directly. Otherwise we need to translate the signal to
+        * the correct bitrate index.
         */
-       sband = &rt2x00dev->bands[rt2x00dev->curr_band];
-       for (i = 0; i < sband->n_bitrates; i++) {
-               rate = rt2x00_get_rate(sband->bitrates[i].hw_value);
-
-               if (((rxdesc.dev_flags & RXDONE_SIGNAL_PLCP) &&
-                    (rate->plcp == rxdesc.signal)) ||
-                   ((rxdesc.dev_flags & RXDONE_SIGNAL_BITRATE) &&
-                     (rate->bitrate == rxdesc.signal))) {
-                       idx = i;
-                       break;
-               }
-       }
-
-       if (idx < 0) {
-               WARNING(rt2x00dev, "Frame received with unrecognized signal,"
-                       "signal=0x%.2x, type=%d.\n", rxdesc.signal,
-                       (rxdesc.dev_flags & RXDONE_SIGNAL_MASK));
-               idx = 0;
+       if (rxdesc.rate_mode == RATE_MODE_CCK ||
+           rxdesc.rate_mode == RATE_MODE_OFDM) {
+               rate_idx = rt2x00lib_rxdone_read_signal(rt2x00dev, &rxdesc);
+       } else {
+               rxdesc.flags |= RX_FLAG_HT;
+               rate_idx = rxdesc.signal;
        }
 
        /*
@@ -405,7 +441,7 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
        rt2x00debug_update_crypto(rt2x00dev, &rxdesc);
 
        rx_status->mactime = rxdesc.timestamp;
-       rx_status->rate_idx = idx;
+       rx_status->rate_idx = rate_idx;
        rx_status->qual = rt2x00link_calculate_signal(rt2x00dev, rxdesc.rssi);
        rx_status->signal = rxdesc.rssi;
        rx_status->noise = rxdesc.noise;
@@ -417,7 +453,8 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
         * mac80211 will clean up the skb structure.
         */
        rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_RXDONE, entry->skb);
-       ieee80211_rx_irqsafe(rt2x00dev->hw, entry->skb, rx_status);
+       memcpy(IEEE80211_SKB_RXCB(entry->skb), rx_status, sizeof(*rx_status));
+       ieee80211_rx_irqsafe(rt2x00dev->hw, entry->skb);
 
        /*
         * Replace the skb with the freshly allocated one.
@@ -440,72 +477,84 @@ const struct rt2x00_rate rt2x00_supported_rates[12] = {
                .bitrate = 10,
                .ratemask = BIT(0),
                .plcp = 0x00,
+               .mcs = RATE_MCS(RATE_MODE_CCK, 0),
        },
        {
                .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
                .bitrate = 20,
                .ratemask = BIT(1),
                .plcp = 0x01,
+               .mcs = RATE_MCS(RATE_MODE_CCK, 1),
        },
        {
                .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
                .bitrate = 55,
                .ratemask = BIT(2),
                .plcp = 0x02,
+               .mcs = RATE_MCS(RATE_MODE_CCK, 2),
        },
        {
                .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
                .bitrate = 110,
                .ratemask = BIT(3),
                .plcp = 0x03,
+               .mcs = RATE_MCS(RATE_MODE_CCK, 3),
        },
        {
                .flags = DEV_RATE_OFDM,
                .bitrate = 60,
                .ratemask = BIT(4),
                .plcp = 0x0b,
+               .mcs = RATE_MCS(RATE_MODE_OFDM, 0),
        },
        {
                .flags = DEV_RATE_OFDM,
                .bitrate = 90,
                .ratemask = BIT(5),
                .plcp = 0x0f,
+               .mcs = RATE_MCS(RATE_MODE_OFDM, 1),
        },
        {
                .flags = DEV_RATE_OFDM,
                .bitrate = 120,
                .ratemask = BIT(6),
                .plcp = 0x0a,
+               .mcs = RATE_MCS(RATE_MODE_OFDM, 2),
        },
        {
                .flags = DEV_RATE_OFDM,
                .bitrate = 180,
                .ratemask = BIT(7),
                .plcp = 0x0e,
+               .mcs = RATE_MCS(RATE_MODE_OFDM, 3),
        },
        {
                .flags = DEV_RATE_OFDM,
                .bitrate = 240,
                .ratemask = BIT(8),
                .plcp = 0x09,
+               .mcs = RATE_MCS(RATE_MODE_OFDM, 4),
        },
        {
                .flags = DEV_RATE_OFDM,
                .bitrate = 360,
                .ratemask = BIT(9),
                .plcp = 0x0d,
+               .mcs = RATE_MCS(RATE_MODE_OFDM, 5),
        },
        {
                .flags = DEV_RATE_OFDM,
                .bitrate = 480,
                .ratemask = BIT(10),
                .plcp = 0x08,
+               .mcs = RATE_MCS(RATE_MODE_OFDM, 6),
        },
        {
                .flags = DEV_RATE_OFDM,
                .bitrate = 540,
                .ratemask = BIT(11),
                .plcp = 0x0c,
+               .mcs = RATE_MCS(RATE_MODE_OFDM, 7),
        },
 };
 
@@ -581,6 +630,8 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
                rt2x00dev->bands[IEEE80211_BAND_2GHZ].bitrates = rates;
                hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
                    &rt2x00dev->bands[IEEE80211_BAND_2GHZ];
+               memcpy(&rt2x00dev->bands[IEEE80211_BAND_2GHZ].ht_cap,
+                      &spec->ht, sizeof(spec->ht));
        }
 
        /*
@@ -597,6 +648,8 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
                rt2x00dev->bands[IEEE80211_BAND_5GHZ].bitrates = &rates[4];
                hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
                    &rt2x00dev->bands[IEEE80211_BAND_5GHZ];
+               memcpy(&rt2x00dev->bands[IEEE80211_BAND_5GHZ].ht_cap,
+                      &spec->ht, sizeof(spec->ht));
        }
 
        return 0;
@@ -737,6 +790,13 @@ int rt2x00lib_start(struct rt2x00_dev *rt2x00dev)
        rt2x00dev->intf_sta_count = 0;
        rt2x00dev->intf_associated = 0;
 
+       /* Enable the radio */
+       retval = rt2x00lib_enable_radio(rt2x00dev);
+       if (retval) {
+               rt2x00queue_uninitialize(rt2x00dev);
+               return retval;
+       }
+
        set_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags);
 
        return 0;
@@ -822,7 +882,6 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
         */
        rt2x00link_register(rt2x00dev);
        rt2x00leds_register(rt2x00dev);
-       rt2x00rfkill_allocate(rt2x00dev);
        rt2x00debug_register(rt2x00dev);
 
        set_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
@@ -845,6 +904,12 @@ void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
         */
        rt2x00lib_disable_radio(rt2x00dev);
 
+       /*
+        * Stop all work.
+        */
+       cancel_work_sync(&rt2x00dev->filter_work);
+       cancel_work_sync(&rt2x00dev->intf_work);
+
        /*
         * Uninitialize device.
         */
@@ -854,7 +919,6 @@ void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
         * Free extra components
         */
        rt2x00debug_deregister(rt2x00dev);
-       rt2x00rfkill_free(rt2x00dev);
        rt2x00leds_unregister(rt2x00dev);
 
        /*