]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - drivers/net/wireless/rt2x00/rt2x00dev.c
rt2x00: Allow beacon update without scheduling a work
[linux-2.6.git] / drivers / net / wireless / rt2x00 / rt2x00dev.c
index 328ff8bc4c16b31e324df229d1464f96ba7d308a..e2557257565cdcf8f9d755556e7a5dde8a66ed45 100644 (file)
@@ -1,5 +1,5 @@
 /*
-       Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
+       Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
        <http://rt2x00.serialmonkey.com>
 
        This program is free software; you can redistribute it and/or modify
 
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/slab.h>
 
 #include "rt2x00.h"
 #include "rt2x00lib.h"
 
-/*
- * Link tuning handlers
- */
-void rt2x00lib_reset_link_tuner(struct rt2x00_dev *rt2x00dev)
-{
-       if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
-               return;
-
-       /*
-        * Reset link information.
-        * Both the currently active vgc level as well as
-        * the link tuner counter should be reset. Resetting
-        * the counter is important for devices where the
-        * device should only perform link tuning during the
-        * first minute after being enabled.
-        */
-       rt2x00dev->link.count = 0;
-       rt2x00dev->link.vgc_level = 0;
-
-       /*
-        * Reset the link tuner.
-        */
-       rt2x00dev->ops->lib->reset_tuner(rt2x00dev);
-}
-
-static void rt2x00lib_start_link_tuner(struct rt2x00_dev *rt2x00dev)
-{
-       /*
-        * Clear all (possibly) pre-existing quality statistics.
-        */
-       memset(&rt2x00dev->link.qual, 0, sizeof(rt2x00dev->link.qual));
-
-       /*
-        * The RX and TX percentage should start at 50%
-        * this will assure we will get at least get some
-        * decent value when the link tuner starts.
-        * The value will be dropped and overwritten with
-        * the correct (measured )value anyway during the
-        * first run of the link tuner.
-        */
-       rt2x00dev->link.qual.rx_percentage = 50;
-       rt2x00dev->link.qual.tx_percentage = 50;
-
-       rt2x00lib_reset_link_tuner(rt2x00dev);
-
-       queue_delayed_work(rt2x00dev->hw->workqueue,
-                          &rt2x00dev->link.work, LINK_TUNE_INTERVAL);
-}
-
-static void rt2x00lib_stop_link_tuner(struct rt2x00_dev *rt2x00dev)
-{
-       cancel_delayed_work_sync(&rt2x00dev->link.work);
-}
-
 /*
  * Radio control handlers.
  */
@@ -94,15 +41,13 @@ 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_ENABLED_RADIO, &rt2x00dev->flags) ||
-           test_bit(DEVICE_DISABLED_RADIO_HW, &rt2x00dev->flags))
+       if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
                return 0;
 
        /*
         * Initialize all data queues.
         */
-       rt2x00queue_init_rx(rt2x00dev);
-       rt2x00queue_init_tx(rt2x00dev);
+       rt2x00queue_init_queues(rt2x00dev);
 
        /*
         * Enable radio.
@@ -117,13 +62,18 @@ int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev)
        rt2x00leds_led_radio(rt2x00dev, true);
        rt2x00led_led_activity(rt2x00dev, true);
 
-       __set_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags);
+       set_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags);
 
        /*
         * Enable RX.
         */
        rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON);
 
+       /*
+        * Start watchdog monitoring.
+        */
+       rt2x00link_start_watchdog(rt2x00dev);
+
        /*
         * Start the TX queues.
         */
@@ -134,13 +84,19 @@ int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev)
 
 void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev)
 {
-       if (!__test_and_clear_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
+       if (!test_and_clear_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
                return;
 
        /*
-        * Stop the TX queues.
+        * Stop the TX queues in mac80211.
         */
        ieee80211_stop_queues(rt2x00dev->hw);
+       rt2x00queue_stop_queues(rt2x00dev);
+
+       /*
+        * Stop watchdog monitoring.
+        */
+       rt2x00link_stop_watchdog(rt2x00dev);
 
        /*
         * Disable RX.
@@ -162,246 +118,15 @@ void rt2x00lib_toggle_rx(struct rt2x00_dev *rt2x00dev, enum dev_state state)
         * When we are disabling the RX, we should also stop the link tuner.
         */
        if (state == STATE_RADIO_RX_OFF)
-               rt2x00lib_stop_link_tuner(rt2x00dev);
+               rt2x00link_stop_tuner(rt2x00dev);
 
        rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
 
        /*
         * When we are enabling the RX, we should also start the link tuner.
         */
-       if (state == STATE_RADIO_RX_ON &&
-           (rt2x00dev->intf_ap_count || rt2x00dev->intf_sta_count))
-               rt2x00lib_start_link_tuner(rt2x00dev);
-}
-
-static void rt2x00lib_evaluate_antenna_sample(struct rt2x00_dev *rt2x00dev)
-{
-       enum antenna rx = rt2x00dev->link.ant.active.rx;
-       enum antenna tx = rt2x00dev->link.ant.active.tx;
-       int sample_a =
-           rt2x00_get_link_ant_rssi_history(&rt2x00dev->link, ANTENNA_A);
-       int sample_b =
-           rt2x00_get_link_ant_rssi_history(&rt2x00dev->link, ANTENNA_B);
-
-       /*
-        * We are done sampling. Now we should evaluate the results.
-        */
-       rt2x00dev->link.ant.flags &= ~ANTENNA_MODE_SAMPLE;
-
-       /*
-        * During the last period we have sampled the RSSI
-        * from both antenna's. It now is time to determine
-        * which antenna demonstrated the best performance.
-        * When we are already on the antenna with the best
-        * performance, then there really is nothing for us
-        * left to do.
-        */
-       if (sample_a == sample_b)
-               return;
-
-       if (rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY)
-               rx = (sample_a > sample_b) ? ANTENNA_A : ANTENNA_B;
-
-       if (rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY)
-               tx = (sample_a > sample_b) ? ANTENNA_A : ANTENNA_B;
-
-       rt2x00lib_config_antenna(rt2x00dev, rx, tx);
-}
-
-static void rt2x00lib_evaluate_antenna_eval(struct rt2x00_dev *rt2x00dev)
-{
-       enum antenna rx = rt2x00dev->link.ant.active.rx;
-       enum antenna tx = rt2x00dev->link.ant.active.tx;
-       int rssi_curr = rt2x00_get_link_ant_rssi(&rt2x00dev->link);
-       int rssi_old = rt2x00_update_ant_rssi(&rt2x00dev->link, rssi_curr);
-
-       /*
-        * Legacy driver indicates that we should swap antenna's
-        * when the difference in RSSI is greater that 5. This
-        * also should be done when the RSSI was actually better
-        * then the previous sample.
-        * When the difference exceeds the threshold we should
-        * sample the rssi from the other antenna to make a valid
-        * comparison between the 2 antennas.
-        */
-       if (abs(rssi_curr - rssi_old) < 5)
-               return;
-
-       rt2x00dev->link.ant.flags |= ANTENNA_MODE_SAMPLE;
-
-       if (rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY)
-               rx = (rx == ANTENNA_A) ? ANTENNA_B : ANTENNA_A;
-
-       if (rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY)
-               tx = (tx == ANTENNA_A) ? ANTENNA_B : ANTENNA_A;
-
-       rt2x00lib_config_antenna(rt2x00dev, rx, tx);
-}
-
-static void rt2x00lib_evaluate_antenna(struct rt2x00_dev *rt2x00dev)
-{
-       /*
-        * Determine if software diversity is enabled for
-        * either the TX or RX antenna (or both).
-        * Always perform this check since within the link
-        * tuner interval the configuration might have changed.
-        */
-       rt2x00dev->link.ant.flags &= ~ANTENNA_RX_DIVERSITY;
-       rt2x00dev->link.ant.flags &= ~ANTENNA_TX_DIVERSITY;
-
-       if (rt2x00dev->hw->conf.antenna_sel_rx == 0 &&
-           rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY)
-               rt2x00dev->link.ant.flags |= ANTENNA_RX_DIVERSITY;
-       if (rt2x00dev->hw->conf.antenna_sel_tx == 0 &&
-           rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY)
-               rt2x00dev->link.ant.flags |= ANTENNA_TX_DIVERSITY;
-
-       if (!(rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY) &&
-           !(rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY)) {
-               rt2x00dev->link.ant.flags = 0;
-               return;
-       }
-
-       /*
-        * If we have only sampled the data over the last period
-        * we should now harvest the data. Otherwise just evaluate
-        * the data. The latter should only be performed once
-        * every 2 seconds.
-        */
-       if (rt2x00dev->link.ant.flags & ANTENNA_MODE_SAMPLE)
-               rt2x00lib_evaluate_antenna_sample(rt2x00dev);
-       else if (rt2x00dev->link.count & 1)
-               rt2x00lib_evaluate_antenna_eval(rt2x00dev);
-}
-
-static void rt2x00lib_update_link_stats(struct link *link, int rssi)
-{
-       int avg_rssi = rssi;
-
-       /*
-        * Update global RSSI
-        */
-       if (link->qual.avg_rssi)
-               avg_rssi = MOVING_AVERAGE(link->qual.avg_rssi, rssi, 8);
-       link->qual.avg_rssi = avg_rssi;
-
-       /*
-        * Update antenna RSSI
-        */
-       if (link->ant.rssi_ant)
-               rssi = MOVING_AVERAGE(link->ant.rssi_ant, rssi, 8);
-       link->ant.rssi_ant = rssi;
-}
-
-static void rt2x00lib_precalculate_link_signal(struct link_qual *qual)
-{
-       if (qual->rx_failed || qual->rx_success)
-               qual->rx_percentage =
-                   (qual->rx_success * 100) /
-                   (qual->rx_failed + qual->rx_success);
-       else
-               qual->rx_percentage = 50;
-
-       if (qual->tx_failed || qual->tx_success)
-               qual->tx_percentage =
-                   (qual->tx_success * 100) /
-                   (qual->tx_failed + qual->tx_success);
-       else
-               qual->tx_percentage = 50;
-
-       qual->rx_success = 0;
-       qual->rx_failed = 0;
-       qual->tx_success = 0;
-       qual->tx_failed = 0;
-}
-
-static int rt2x00lib_calculate_link_signal(struct rt2x00_dev *rt2x00dev,
-                                          int rssi)
-{
-       int rssi_percentage = 0;
-       int signal;
-
-       /*
-        * We need a positive value for the RSSI.
-        */
-       if (rssi < 0)
-               rssi += rt2x00dev->rssi_offset;
-
-       /*
-        * Calculate the different percentages,
-        * which will be used for the signal.
-        */
-       if (rt2x00dev->rssi_offset)
-               rssi_percentage = (rssi * 100) / rt2x00dev->rssi_offset;
-
-       /*
-        * Add the individual percentages and use the WEIGHT
-        * defines to calculate the current link signal.
-        */
-       signal = ((WEIGHT_RSSI * rssi_percentage) +
-                 (WEIGHT_TX * rt2x00dev->link.qual.tx_percentage) +
-                 (WEIGHT_RX * rt2x00dev->link.qual.rx_percentage)) / 100;
-
-       return (signal > 100) ? 100 : signal;
-}
-
-static void rt2x00lib_link_tuner(struct work_struct *work)
-{
-       struct rt2x00_dev *rt2x00dev =
-           container_of(work, struct rt2x00_dev, link.work.work);
-
-       /*
-        * When the radio is shutting down we should
-        * immediately cease all link tuning.
-        */
-       if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
-               return;
-
-       /*
-        * Update statistics.
-        */
-       rt2x00dev->ops->lib->link_stats(rt2x00dev, &rt2x00dev->link.qual);
-       rt2x00dev->low_level_stats.dot11FCSErrorCount +=
-           rt2x00dev->link.qual.rx_failed;
-
-       /*
-        * Only perform the link tuning when Link tuning
-        * has been enabled (This could have been disabled from the EEPROM).
-        */
-       if (!test_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags))
-               rt2x00dev->ops->lib->link_tuner(rt2x00dev);
-
-       /*
-        * Precalculate a portion of the link signal which is
-        * in based on the tx/rx success/failure counters.
-        */
-       rt2x00lib_precalculate_link_signal(&rt2x00dev->link.qual);
-
-       /*
-        * Send a signal to the led to update the led signal strength.
-        */
-       rt2x00leds_led_quality(rt2x00dev, rt2x00dev->link.qual.avg_rssi);
-
-       /*
-        * Evaluate antenna setup, make this the last step since this could
-        * possibly reset some statistics.
-        */
-       rt2x00lib_evaluate_antenna(rt2x00dev);
-
-       /*
-        * Increase tuner counter, and reschedule the next link tuner run.
-        */
-       rt2x00dev->link.count++;
-       queue_delayed_work(rt2x00dev->hw->workqueue,
-                          &rt2x00dev->link.work, LINK_TUNE_INTERVAL);
-}
-
-static void rt2x00lib_packetfilter_scheduled(struct work_struct *work)
-{
-       struct rt2x00_dev *rt2x00dev =
-           container_of(work, struct rt2x00_dev, filter_work);
-
-       rt2x00dev->ops->lib->config_filter(rt2x00dev, rt2x00dev->packet_filter);
+       if (state == STATE_RADIO_RX_ON)
+               rt2x00link_start_tuner(rt2x00dev);
 }
 
 static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac,
@@ -409,7 +134,6 @@ static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac,
 {
        struct rt2x00_dev *rt2x00dev = data;
        struct rt2x00_intf *intf = vif_to_intf(vif);
-       struct ieee80211_bss_conf conf;
        int delayed_flags;
 
        /*
@@ -419,7 +143,6 @@ static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac,
         */
        spin_lock(&intf->lock);
 
-       memcpy(&conf, &intf->conf, sizeof(conf));
        delayed_flags = intf->delayed_flags;
        intf->delayed_flags = 0;
 
@@ -431,17 +154,11 @@ static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac,
         * note that in the spinlock protected area above the delayed_flags
         * have been cleared correctly.
         */
-       if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
+       if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
                return;
 
        if (delayed_flags & DELAYED_UPDATE_BEACON)
-               rt2x00queue_update_beacon(rt2x00dev, vif);
-
-       if (delayed_flags & DELAYED_CONFIG_ERP)
-               rt2x00lib_config_erp(rt2x00dev, intf, &conf);
-
-       if (delayed_flags & DELAYED_LED_ASSOC)
-               rt2x00leds_led_assoc(rt2x00dev, !!rt2x00dev->intf_associated);
+               rt2x00queue_update_beacon(rt2x00dev, vif, true);
 }
 
 static void rt2x00lib_intf_scheduled(struct work_struct *work)
@@ -465,33 +182,25 @@ 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 != IEEE80211_IF_TYPE_AP &&
-           vif->type != IEEE80211_IF_TYPE_IBSS)
+       if (vif->type != NL80211_IFTYPE_AP &&
+           vif->type != NL80211_IFTYPE_ADHOC &&
+           vif->type != NL80211_IFTYPE_MESH_POINT &&
+           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);
+       rt2x00queue_update_beacon(rt2x00dev, vif, true);
 }
 
 void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev)
 {
-       if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
+       if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
                return;
 
-       ieee80211_iterate_active_interfaces_atomic(rt2x00dev->hw,
-                                                  rt2x00lib_beacondone_iter,
-                                                  rt2x00dev);
+       ieee80211_iterate_active_interfaces(rt2x00dev->hw,
+                                          rt2x00lib_beacondone_iter,
+                                          rt2x00dev);
 
-       schedule_work(&rt2x00dev->intf_work);
 }
 EXPORT_SYMBOL_GPL(rt2x00lib_beacondone);
 
@@ -500,21 +209,43 @@ void rt2x00lib_txdone(struct queue_entry *entry,
 {
        struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
        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);
+       unsigned int header_length = ieee80211_get_hdrlen_from_skb(entry->skb);
+       u8 rate_idx, rate_flags, retry_rates;
+       u8 skbdesc_flags = skbdesc->flags;
+       unsigned int i;
+       bool success;
 
        /*
         * Unmap the skb.
         */
        rt2x00queue_unmap_skb(rt2x00dev, entry->skb);
 
+       /*
+        * Remove the extra tx headroom from the skb.
+        */
+       skb_pull(entry->skb, rt2x00dev->ops->extra_tx_headroom);
+
+       /*
+        * Signal that the TX descriptor is no longer in the skb.
+        */
+       skbdesc->flags &= ~SKBDESC_DESC_IN_SKB;
+
+       /*
+        * Remove L2 padding which was added during
+        */
+       if (test_bit(DRIVER_REQUIRE_L2PAD, &rt2x00dev->flags))
+               rt2x00queue_remove_l2pad(entry->skb, 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
-        * mac80211 will expect the the same data to be present it the
+        * mac80211 will expect the same data to be present it the
         * 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
@@ -522,47 +253,101 @@ void rt2x00lib_txdone(struct queue_entry *entry,
         */
        rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TXDONE, entry->skb);
 
+       /*
+        * Determine if the frame has been successfully transmitted.
+        */
+       success =
+           test_bit(TXDONE_SUCCESS, &txdesc->flags) ||
+           test_bit(TXDONE_UNKNOWN, &txdesc->flags);
+
        /*
         * Update TX statistics.
         */
-       rt2x00dev->link.qual.tx_success +=
-           test_bit(TXDONE_SUCCESS, &txdesc->flags);
-       rt2x00dev->link.qual.tx_failed +=
-           test_bit(TXDONE_FAILURE, &txdesc->flags);
+       rt2x00dev->link.qual.tx_success += success;
+       rt2x00dev->link.qual.tx_failed += !success;
+
+       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.excessive_retries =
-           test_bit(TXDONE_EXCESSIVE_RETRY, &txdesc->flags);
-       tx_info->status.retry_count = txdesc->retry;
+
+       /*
+        * Frame was send with retries, hardware tried
+        * different rates to send out the frame, at each
+        * retry it lowered the rate 1 step except when the
+        * lowest rate was used.
+        */
+       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;
+
+               if (rate_idx - i == 0) {
+                       /*
+                        * The lowest rate (index 0) was used until the
+                        * number of max retries was reached.
+                        */
+                       tx_info->status.rates[i].count = retry_rates - i;
+                       i++;
+                       break;
+               }
+               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 (success)
                        tx_info->flags |= IEEE80211_TX_STAT_ACK;
-               else if (test_bit(TXDONE_FAILURE, &txdesc->flags))
+               else
                        rt2x00dev->low_level_stats.dot11ACKFailureCount++;
        }
 
-       if (tx_info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) {
-               if (test_bit(TXDONE_SUCCESS, &txdesc->flags))
+       /*
+        * Every single frame has it's own tx status, hence report
+        * every frame as ampdu of size 1.
+        *
+        * TODO: if we can find out how many frames were aggregated
+        * by the hw we could provide the real ampdu_len to mac80211
+        * which would allow the rc algorithm to better decide on
+        * which rates are suitable.
+        */
+       if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
+               tx_info->flags |= IEEE80211_TX_STAT_AMPDU;
+               tx_info->status.ampdu_len = 1;
+               tx_info->status.ampdu_ack_len = success ? 1 : 0;
+       }
+
+       if (rate_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
+               if (success)
                        rt2x00dev->low_level_stats.dot11RTSSuccessCount++;
-               else if (test_bit(TXDONE_FAILURE, &txdesc->flags))
+               else
                        rt2x00dev->low_level_stats.dot11RTSFailureCount++;
        }
 
        /*
-        * Only send the status report to mac80211 when TX status was
-        * requested by it. If this was a extra frame coming through
-        * a mac80211 library call (RTS/CTS) then we should not send the
-        * status report back.
-        */
-       if (tx_info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS)
-               ieee80211_tx_status_irqsafe(rt2x00dev->hw, entry->skb);
+        * Only send the status report to mac80211 when it's a frame
+        * that originated in mac80211. If this was a extra frame coming
+        * through a mac80211 library call (RTS/CTS) then we should not
+        * send the status report back.
+        */
+       if (!(skbdesc_flags & SKBDESC_NOT_MAC80211))
+               /*
+                * Only PCI and SOC devices process the tx status in process
+                * context. Hence use ieee80211_tx_status for PCI and SOC
+                * devices and stick to ieee80211_tx_status_irqsafe for USB.
+                */
+               if (rt2x00_is_usb(rt2x00dev))
+                       ieee80211_tx_status_irqsafe(rt2x00dev->hw, entry->skb);
+               else
+                       ieee80211_tx_status(rt2x00dev->hw, entry->skb);
        else
-               dev_kfree_skb_irq(entry->skb);
+               dev_kfree_skb_any(entry->skb);
 
        /*
         * Make this entry available for reuse.
@@ -570,9 +355,9 @@ void rt2x00lib_txdone(struct queue_entry *entry,
        entry->skb = NULL;
        entry->flags = 0;
 
-       rt2x00dev->ops->lib->init_txentry(rt2x00dev, entry);
+       rt2x00dev->ops->lib->clear_entry(entry);
 
-       __clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
+       clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
        rt2x00queue_index_inc(entry->queue, Q_INDEX_DONE);
 
        /*
@@ -585,20 +370,53 @@ 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;
-       struct ieee80211_hdr *hdr;
-       const struct rt2x00_rate *rate;
        unsigned int header_length;
-       unsigned int align;
-       unsigned int i;
-       int idx = -1;
-
+       int rate_idx;
        /*
         * Allocate a new sk_buffer. If no new buffer available, drop the
         * received frame and reuse the existing buffer.
@@ -623,68 +441,49 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
         * aligned on a 4 byte boundary.
         */
        header_length = ieee80211_get_hdrlen_from_skb(entry->skb);
-       align = ((unsigned long)(entry->skb->data + header_length)) & 3;
 
        /*
         * Hardware might have stripped the IV/EIV/ICV data,
         * in that case it is possible that the data was
-        * provided seperately (through hardware descriptor)
+        * provided separately (through hardware descriptor)
         * in which case we should reinsert the data into the frame.
         */
-       if ((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);
-       }
+       if ((rxdesc.dev_flags & RXDONE_CRYPTO_IV) &&
+           (rxdesc.flags & RX_FLAG_IV_STRIPPED))
+               rt2x00crypto_rx_insert_iv(entry->skb, header_length,
+                                         &rxdesc);
+       else if (header_length &&
+                (rxdesc.size > header_length) &&
+                (rxdesc.dev_flags & RXDONE_L2PAD))
+               rt2x00queue_remove_l2pad(entry->skb, header_length);
+       else
+               rt2x00queue_align_payload(entry->skb, header_length);
 
-       /* Update data pointers, trim buffer to correct size */
+       /* Trim buffer to correct size */
        skb_trim(entry->skb, rxdesc.size);
 
        /*
-        * 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_PLCP) &&
-                     (rate->bitrate == rxdesc.signal))) {
-                       idx = i;
-                       break;
-               }
-       }
-
-       if (idx < 0) {
-               WARNING(rt2x00dev, "Frame received with unrecognized signal,"
-                       "signal=0x%.2x, plcp=%d.\n", rxdesc.signal,
-                       !!(rxdesc.dev_flags & RXDONE_SIGNAL_PLCP));
-               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;
        }
 
        /*
-        * Only update link status if this is a beacon frame carrying our bssid.
+        * Update extra components
         */
-       hdr = (struct ieee80211_hdr *)entry->skb->data;
-       if (ieee80211_is_beacon(hdr->frame_control) &&
-           (rxdesc.dev_flags & RXDONE_MY_BSS))
-               rt2x00lib_update_link_stats(&rt2x00dev->link, rxdesc.rssi);
-
-       rt2x00debug_update_crypto(rt2x00dev,
-                                 rxdesc.cipher,
-                                 rxdesc.cipher_status);
-
-       rt2x00dev->link.qual.rx_success++;
+       rt2x00link_update_stats(rt2x00dev, entry->skb, &rxdesc);
+       rt2x00debug_update_crypto(rt2x00dev, &rxdesc);
 
        rx_status->mactime = rxdesc.timestamp;
-       rx_status->rate_idx = idx;
-       rx_status->qual =
-           rt2x00lib_calculate_link_signal(rt2x00dev, rxdesc.rssi);
+       rx_status->rate_idx = rate_idx;
        rx_status->signal = rxdesc.rssi;
        rx_status->flag = rxdesc.flags;
        rx_status->antenna = rt2x00dev->link.ant.active.rx;
@@ -694,7 +493,17 @@ 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));
+
+       /*
+        * Currently only PCI and SOC devices handle rx interrupts in process
+        * context. Hence, use ieee80211_rx_irqsafe for USB and ieee80211_rx_ni
+        * for PCI and SOC devices.
+        */
+       if (rt2x00_is_usb(rt2x00dev))
+               ieee80211_rx_irqsafe(rt2x00dev->hw, entry->skb);
+       else
+               ieee80211_rx_ni(rt2x00dev->hw, entry->skb);
 
        /*
         * Replace the skb with the freshly allocated one.
@@ -702,7 +511,7 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
        entry->skb = skb;
        entry->flags = 0;
 
-       rt2x00dev->ops->lib->init_rxentry(rt2x00dev, entry);
+       rt2x00dev->ops->lib->clear_entry(entry);
 
        rt2x00queue_index_inc(entry->queue, Q_INDEX);
 }
@@ -713,76 +522,88 @@ EXPORT_SYMBOL_GPL(rt2x00lib_rxdone);
  */
 const struct rt2x00_rate rt2x00_supported_rates[12] = {
        {
-               .flags = DEV_RATE_CCK | DEV_RATE_BASIC,
+               .flags = DEV_RATE_CCK,
                .bitrate = 10,
                .ratemask = BIT(0),
                .plcp = 0x00,
+               .mcs = RATE_MCS(RATE_MODE_CCK, 0),
        },
        {
-               .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE | DEV_RATE_BASIC,
+               .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 | DEV_RATE_BASIC,
+               .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 | DEV_RATE_BASIC,
+               .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 | DEV_RATE_BASIC,
+               .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 | DEV_RATE_BASIC,
+               .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 | DEV_RATE_BASIC,
+               .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),
        },
 };
 
@@ -801,13 +622,11 @@ static void rt2x00lib_rate(struct ieee80211_rate *entry,
 {
        entry->flags = 0;
        entry->bitrate = rate->bitrate;
-       entry->hw_value = rt2x00_create_rate_hw_value(index, 0);
-       entry->hw_value_short = entry->hw_value;
+       entry->hw_value =index;
+       entry->hw_value_short = index;
 
-       if (rate->flags & DEV_RATE_SHORT_PREAMBLE) {
+       if (rate->flags & DEV_RATE_SHORT_PREAMBLE)
                entry->flags |= IEEE80211_RATE_SHORT_PREAMBLE;
-               entry->hw_value_short |= rt2x00_create_rate_hw_value(index, 1);
-       }
 }
 
 static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
@@ -860,6 +679,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));
        }
 
        /*
@@ -876,6 +697,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;
@@ -888,7 +711,7 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
 
 static void rt2x00lib_remove_hw(struct rt2x00_dev *rt2x00dev)
 {
-       if (test_bit(DEVICE_REGISTERED_HW, &rt2x00dev->flags))
+       if (test_bit(DEVICE_STATE_REGISTERED_HW, &rt2x00dev->flags))
                ieee80211_unregister_hw(rt2x00dev->hw);
 
        if (likely(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ])) {
@@ -906,6 +729,9 @@ static int rt2x00lib_probe_hw(struct rt2x00_dev *rt2x00dev)
        struct hw_mode_spec *spec = &rt2x00dev->spec;
        int status;
 
+       if (test_bit(DEVICE_STATE_REGISTERED_HW, &rt2x00dev->flags))
+               return 0;
+
        /*
         * Initialize HW modes.
         */
@@ -918,16 +744,29 @@ static int rt2x00lib_probe_hw(struct rt2x00_dev *rt2x00dev)
         */
        rt2x00dev->hw->queues = rt2x00dev->ops->tx_queues;
 
+       /*
+        * Initialize extra TX headroom required.
+        */
+       rt2x00dev->hw->extra_tx_headroom =
+               max_t(unsigned int, IEEE80211_TX_STATUS_HEADROOM,
+                     rt2x00dev->ops->extra_tx_headroom);
+
+       /*
+        * Take TX headroom required for alignment into account.
+        */
+       if (test_bit(DRIVER_REQUIRE_L2PAD, &rt2x00dev->flags))
+               rt2x00dev->hw->extra_tx_headroom += RT2X00_L2PAD_SIZE;
+       else if (test_bit(DRIVER_REQUIRE_DMA, &rt2x00dev->flags))
+               rt2x00dev->hw->extra_tx_headroom += RT2X00_ALIGN_SIZE;
+
        /*
         * Register HW.
         */
        status = ieee80211_register_hw(rt2x00dev->hw);
-       if (status) {
-               rt2x00lib_remove_hw(rt2x00dev);
+       if (status)
                return status;
-       }
 
-       __set_bit(DEVICE_REGISTERED_HW, &rt2x00dev->flags);
+       set_bit(DEVICE_STATE_REGISTERED_HW, &rt2x00dev->flags);
 
        return 0;
 }
@@ -937,7 +776,7 @@ static int rt2x00lib_probe_hw(struct rt2x00_dev *rt2x00dev)
  */
 static void rt2x00lib_uninitialize(struct rt2x00_dev *rt2x00dev)
 {
-       if (!__test_and_clear_bit(DEVICE_INITIALIZED, &rt2x00dev->flags))
+       if (!test_and_clear_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags))
                return;
 
        /*
@@ -960,7 +799,7 @@ static int rt2x00lib_initialize(struct rt2x00_dev *rt2x00dev)
 {
        int status;
 
-       if (test_bit(DEVICE_INITIALIZED, &rt2x00dev->flags))
+       if (test_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags))
                return 0;
 
        /*
@@ -979,7 +818,7 @@ static int rt2x00lib_initialize(struct rt2x00_dev *rt2x00dev)
                return status;
        }
 
-       __set_bit(DEVICE_INITIALIZED, &rt2x00dev->flags);
+       set_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags);
 
        /*
         * Register the extra components.
@@ -993,7 +832,7 @@ int rt2x00lib_start(struct rt2x00_dev *rt2x00dev)
 {
        int retval;
 
-       if (test_bit(DEVICE_STARTED, &rt2x00dev->flags))
+       if (test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags))
                return 0;
 
        /*
@@ -1011,28 +850,25 @@ int rt2x00lib_start(struct rt2x00_dev *rt2x00dev)
        if (retval)
                return retval;
 
-       /*
-        * Enable radio.
-        */
+       rt2x00dev->intf_ap_count = 0;
+       rt2x00dev->intf_sta_count = 0;
+       rt2x00dev->intf_associated = 0;
+
+       /* Enable the radio */
        retval = rt2x00lib_enable_radio(rt2x00dev);
        if (retval) {
-               rt2x00lib_uninitialize(rt2x00dev);
+               rt2x00queue_uninitialize(rt2x00dev);
                return retval;
        }
 
-       rt2x00dev->intf_ap_count = 0;
-       rt2x00dev->intf_sta_count = 0;
-       rt2x00dev->intf_associated = 0;
-
-       __set_bit(DEVICE_STARTED, &rt2x00dev->flags);
-       __set_bit(DEVICE_DIRTY_CONFIG, &rt2x00dev->flags);
+       set_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags);
 
        return 0;
 }
 
 void rt2x00lib_stop(struct rt2x00_dev *rt2x00dev)
 {
-       if (!test_bit(DEVICE_STARTED, &rt2x00dev->flags))
+       if (!test_and_clear_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags))
                return;
 
        /*
@@ -1044,8 +880,6 @@ void rt2x00lib_stop(struct rt2x00_dev *rt2x00dev)
        rt2x00dev->intf_ap_count = 0;
        rt2x00dev->intf_sta_count = 0;
        rt2x00dev->intf_associated = 0;
-
-       __clear_bit(DEVICE_STARTED, &rt2x00dev->flags);
 }
 
 /*
@@ -1055,12 +889,29 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
 {
        int retval = -ENOMEM;
 
+       mutex_init(&rt2x00dev->csr_mutex);
+
+       set_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
+
        /*
         * Make room for rt2x00_intf inside the per-interface
         * structure ieee80211_vif.
         */
        rt2x00dev->hw->vif_data_size = sizeof(struct rt2x00_intf);
 
+       /*
+        * Determine which operating modes are supported, all modes
+        * which require beaconing, depend on the availability of
+        * beacon entries.
+        */
+       rt2x00dev->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
+       if (rt2x00dev->ops->bcn->entry_num > 0)
+               rt2x00dev->hw->wiphy->interface_modes |=
+                   BIT(NL80211_IFTYPE_ADHOC) |
+                   BIT(NL80211_IFTYPE_AP) |
+                   BIT(NL80211_IFTYPE_MESH_POINT) |
+                   BIT(NL80211_IFTYPE_WDS);
+
        /*
         * Let the driver probe the device to detect the capabilities.
         */
@@ -1074,8 +925,6 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
         * Initialize configuration work.
         */
        INIT_WORK(&rt2x00dev->intf_work, rt2x00lib_intf_scheduled);
-       INIT_WORK(&rt2x00dev->filter_work, rt2x00lib_packetfilter_scheduled);
-       INIT_DELAYED_WORK(&rt2x00dev->link.work, rt2x00lib_link_tuner);
 
        /*
         * Allocate queue array.
@@ -1096,12 +945,10 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
        /*
         * Register extra components.
         */
+       rt2x00link_register(rt2x00dev);
        rt2x00leds_register(rt2x00dev);
-       rt2x00rfkill_allocate(rt2x00dev);
        rt2x00debug_register(rt2x00dev);
 
-       __set_bit(DEVICE_PRESENT, &rt2x00dev->flags);
-
        return 0;
 
 exit:
@@ -1113,13 +960,18 @@ EXPORT_SYMBOL_GPL(rt2x00lib_probe_dev);
 
 void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
 {
-       __clear_bit(DEVICE_PRESENT, &rt2x00dev->flags);
+       clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
 
        /*
         * Disable radio.
         */
        rt2x00lib_disable_radio(rt2x00dev);
 
+       /*
+        * Stop all work.
+        */
+       cancel_work_sync(&rt2x00dev->intf_work);
+
        /*
         * Uninitialize device.
         */
@@ -1129,7 +981,6 @@ void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
         * Free extra components
         */
        rt2x00debug_deregister(rt2x00dev);
-       rt2x00rfkill_free(rt2x00dev);
        rt2x00leds_unregister(rt2x00dev);
 
        /*
@@ -1155,22 +1006,17 @@ EXPORT_SYMBOL_GPL(rt2x00lib_remove_dev);
 #ifdef CONFIG_PM
 int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state)
 {
-       int retval;
-
        NOTICE(rt2x00dev, "Going to sleep.\n");
-       __clear_bit(DEVICE_PRESENT, &rt2x00dev->flags);
 
        /*
-        * Only continue if mac80211 has open interfaces.
+        * Prevent mac80211 from accessing driver while suspended.
         */
-       if (!test_bit(DEVICE_STARTED, &rt2x00dev->flags))
-               goto exit;
-       __set_bit(DEVICE_STARTED_SUSPEND, &rt2x00dev->flags);
+       if (!test_and_clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
+               return 0;
 
        /*
-        * Disable radio.
+        * Cleanup as much as possible.
         */
-       rt2x00lib_stop(rt2x00dev);
        rt2x00lib_uninitialize(rt2x00dev);
 
        /*
@@ -1179,7 +1025,6 @@ int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state)
        rt2x00leds_suspend(rt2x00dev);
        rt2x00debug_deregister(rt2x00dev);
 
-exit:
        /*
         * Set device mode to sleep for power management,
         * on some hardware this call seems to consistently fail.
@@ -1191,8 +1036,7 @@ exit:
         * the radio and the other components already disabled the
         * device is as good as disabled.
         */
-       retval = rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_SLEEP);
-       if (retval)
+       if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_SLEEP))
                WARNING(rt2x00dev, "Device failed to enter sleep state, "
                        "continue suspending.\n");
 
@@ -1200,32 +1044,8 @@ exit:
 }
 EXPORT_SYMBOL_GPL(rt2x00lib_suspend);
 
-static void rt2x00lib_resume_intf(void *data, u8 *mac,
-                                 struct ieee80211_vif *vif)
-{
-       struct rt2x00_dev *rt2x00dev = data;
-       struct rt2x00_intf *intf = vif_to_intf(vif);
-
-       spin_lock(&intf->lock);
-
-       rt2x00lib_config_intf(rt2x00dev, intf,
-                             vif->type, intf->mac, intf->bssid);
-
-
-       /*
-        * Master or Ad-hoc mode require a new beacon update.
-        */
-       if (vif->type == IEEE80211_IF_TYPE_AP ||
-           vif->type == IEEE80211_IF_TYPE_IBSS)
-               intf->delayed_flags |= DELAYED_UPDATE_BEACON;
-
-       spin_unlock(&intf->lock);
-}
-
 int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
 {
-       int retval;
-
        NOTICE(rt2x00dev, "Waking up.\n");
 
        /*
@@ -1234,61 +1054,12 @@ int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
        rt2x00debug_register(rt2x00dev);
        rt2x00leds_resume(rt2x00dev);
 
-       /*
-        * Only continue if mac80211 had open interfaces.
-        */
-       if (!__test_and_clear_bit(DEVICE_STARTED_SUSPEND, &rt2x00dev->flags))
-               return 0;
-
-       /*
-        * Reinitialize device and all active interfaces.
-        */
-       retval = rt2x00lib_start(rt2x00dev);
-       if (retval)
-               goto exit;
-
-       /*
-        * Reconfigure device.
-        */
-       retval = rt2x00mac_config(rt2x00dev->hw, &rt2x00dev->hw->conf);
-       if (retval)
-               goto exit;
-
-       /*
-        * Iterator over each active interface to
-        * reconfigure the hardware.
-        */
-       ieee80211_iterate_active_interfaces(rt2x00dev->hw,
-                                           rt2x00lib_resume_intf, rt2x00dev);
-
        /*
         * We are ready again to receive requests from mac80211.
         */
-       __set_bit(DEVICE_PRESENT, &rt2x00dev->flags);
-
-       /*
-        * It is possible that during that mac80211 has attempted
-        * to send frames while we were suspending or resuming.
-        * In that case we have disabled the TX queue and should
-        * now enable it again
-        */
-       ieee80211_wake_queues(rt2x00dev->hw);
-
-       /*
-        * During interface iteration we might have changed the
-        * delayed_flags, time to handles the event by calling
-        * the work handler directly.
-        */
-       rt2x00lib_intf_scheduled(&rt2x00dev->intf_work);
+       set_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
 
        return 0;
-
-exit:
-       rt2x00lib_disable_radio(rt2x00dev);
-       rt2x00lib_uninitialize(rt2x00dev);
-       rt2x00debug_deregister(rt2x00dev);
-
-       return retval;
 }
 EXPORT_SYMBOL_GPL(rt2x00lib_resume);
 #endif /* CONFIG_PM */