b43legacy: use frame control helpers
[safe/jmp/linux-2.6] / drivers / net / wireless / rt2x00 / rt2x00dev.c
index d6b1278..9ea6773 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "rt2x00.h"
 #include "rt2x00lib.h"
-#include "rt2x00dump.h"
 
 /*
  * Link tuning handlers
@@ -108,11 +107,16 @@ int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev)
        /*
         * Enable radio.
         */
-       status = rt2x00dev->ops->lib->set_device_state(rt2x00dev,
-                                                      STATE_RADIO_ON);
+       status =
+           rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_ON);
        if (status)
                return status;
 
+       rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_ON);
+
+       rt2x00leds_led_radio(rt2x00dev, true);
+       rt2x00led_led_activity(rt2x00dev, true);
+
        __set_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags);
 
        /*
@@ -123,7 +127,7 @@ int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev)
        /*
         * Start the TX queues.
         */
-       ieee80211_start_queues(rt2x00dev->hw);
+       ieee80211_wake_queues(rt2x00dev->hw);
 
        return 0;
 }
@@ -155,6 +159,9 @@ void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev)
         * Disable radio.
         */
        rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_OFF);
+       rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_OFF);
+       rt2x00led_led_activity(rt2x00dev, false);
+       rt2x00leds_led_radio(rt2x00dev, false);
 }
 
 void rt2x00lib_toggle_rx(struct rt2x00_dev *rt2x00dev, enum dev_state state)
@@ -401,18 +408,8 @@ static void rt2x00lib_packetfilter_scheduled(struct work_struct *work)
 {
        struct rt2x00_dev *rt2x00dev =
            container_of(work, struct rt2x00_dev, filter_work);
-       unsigned int filter = rt2x00dev->packet_filter;
 
-       /*
-        * Since we had stored the filter inside rt2x00dev->packet_filter,
-        * we should now clear that field. Otherwise the driver will
-        * assume nothing has changed (*total_flags will be compared
-        * to rt2x00dev->packet_filter to determine if any action is required).
-        */
-       rt2x00dev->packet_filter = 0;
-
-       rt2x00dev->ops->hw->configure_filter(rt2x00dev->hw,
-                                            filter, &filter, 0, NULL);
+       rt2x00dev->ops->lib->config_filter(rt2x00dev, rt2x00dev->packet_filter);
 }
 
 static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac,
@@ -421,7 +418,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 sk_buff *skb;
-       struct ieee80211_tx_control control;
        struct ieee80211_bss_conf conf;
        int delayed_flags;
 
@@ -439,16 +435,17 @@ static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac,
        spin_unlock(&intf->lock);
 
        if (delayed_flags & DELAYED_UPDATE_BEACON) {
-               skb = ieee80211_beacon_get(rt2x00dev->hw, vif, &control);
-               if (skb) {
-                       rt2x00dev->ops->hw->beacon_update(rt2x00dev->hw, skb,
-                                                         &control);
+               skb = ieee80211_beacon_get(rt2x00dev->hw, vif);
+               if (skb &&
+                   rt2x00dev->ops->hw->beacon_update(rt2x00dev->hw, skb))
                        dev_kfree_skb(skb);
-               }
        }
 
        if (delayed_flags & DELAYED_CONFIG_ERP)
                rt2x00lib_config_erp(rt2x00dev, intf, &intf->conf);
+
+       if (delayed_flags & DELAYED_LED_ASSOC)
+               rt2x00leds_led_assoc(rt2x00dev, !!rt2x00dev->intf_associated);
 }
 
 static void rt2x00lib_intf_scheduled(struct work_struct *work)
@@ -487,9 +484,9 @@ void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev)
        if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
                return;
 
-       ieee80211_iterate_active_interfaces(rt2x00dev->hw,
-                                           rt2x00lib_beacondone_iter,
-                                           rt2x00dev);
+       ieee80211_iterate_active_interfaces_atomic(rt2x00dev->hw,
+                                                  rt2x00lib_beacondone_iter,
+                                                  rt2x00dev);
 
        queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->intf_work);
 }
@@ -499,64 +496,55 @@ void rt2x00lib_txdone(struct queue_entry *entry,
                      struct txdone_entry_desc *txdesc)
 {
        struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
-       struct skb_frame_desc *skbdesc;
-       struct ieee80211_tx_status tx_status;
-       int success = !!(txdesc->status == TX_SUCCESS ||
-                        txdesc->status == TX_SUCCESS_RETRY);
-       int fail = !!(txdesc->status == TX_FAIL_RETRY ||
-                     txdesc->status == TX_FAIL_INVALID ||
-                     txdesc->status == TX_FAIL_OTHER);
+       struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
+
+       /*
+        * Send frame to debugfs immediately, after this call is completed
+        * we are going to overwrite the skb->cb array.
+        */
+       rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TXDONE, entry->skb);
 
        /*
         * Update TX statistics.
         */
-       rt2x00dev->link.qual.tx_success += success;
-       rt2x00dev->link.qual.tx_failed += txdesc->retry + fail;
+       rt2x00dev->link.qual.tx_success +=
+           test_bit(TXDONE_SUCCESS, &txdesc->flags);
+       rt2x00dev->link.qual.tx_failed +=
+           test_bit(TXDONE_FAILURE, &txdesc->flags);
 
        /*
         * Initialize TX status
         */
-       tx_status.flags = 0;
-       tx_status.ack_signal = 0;
-       tx_status.excessive_retries = (txdesc->status == TX_FAIL_RETRY);
-       tx_status.retry_count = txdesc->retry;
-       memcpy(&tx_status.control, txdesc->control, sizeof(*txdesc->control));
+       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;
 
-       if (!(tx_status.control.flags & IEEE80211_TXCTL_NO_ACK)) {
-               if (success)
-                       tx_status.flags |= IEEE80211_TX_STATUS_ACK;
-               else
+       if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK)) {
+               if (test_bit(TXDONE_SUCCESS, &txdesc->flags))
+                       tx_info->flags |= IEEE80211_TX_STAT_ACK;
+               else if (test_bit(TXDONE_FAILURE, &txdesc->flags))
                        rt2x00dev->low_level_stats.dot11ACKFailureCount++;
        }
 
-       tx_status.queue_length = entry->queue->limit;
-       tx_status.queue_number = tx_status.control.queue;
-
-       if (tx_status.control.flags & IEEE80211_TXCTL_USE_RTS_CTS) {
-               if (success)
+       if (tx_info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) {
+               if (test_bit(TXDONE_SUCCESS, &txdesc->flags))
                        rt2x00dev->low_level_stats.dot11RTSSuccessCount++;
-               else
+               else if (test_bit(TXDONE_FAILURE, &txdesc->flags))
                        rt2x00dev->low_level_stats.dot11RTSFailureCount++;
        }
 
        /*
-        * Send the tx_status to debugfs. Only send the status report
-        * to mac80211 when the frame originated from there. If this was
-        * a extra frame coming through a mac80211 library call (RTS/CTS)
-        * then we should not send the status report back.
-        * If send to mac80211, mac80211 will clean up the skb structure,
-        * otherwise we have to do it ourself.
+        * 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.
         */
-       skbdesc = get_skb_frame_desc(entry->skb);
-       skbdesc->frame_type = DUMP_FRAME_TXDONE;
-
-       rt2x00debug_dump_frame(rt2x00dev, entry->skb);
-
-       if (!(skbdesc->flags & FRAME_DESC_DRIVER_GENERATED))
-               ieee80211_tx_status_irqsafe(rt2x00dev->hw,
-                                           entry->skb, &tx_status);
+       if (tx_info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS)
+               ieee80211_tx_status_irqsafe(rt2x00dev->hw, entry->skb);
        else
-               dev_kfree_skb(entry->skb);
+               dev_kfree_skb_irq(entry->skb);
        entry->skb = NULL;
 }
 EXPORT_SYMBOL_GPL(rt2x00lib_txdone);
@@ -566,46 +554,68 @@ void rt2x00lib_rxdone(struct queue_entry *entry,
 {
        struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
        struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status;
+       unsigned int header_size = ieee80211_get_hdrlen_from_skb(entry->skb);
        struct ieee80211_supported_band *sband;
        struct ieee80211_hdr *hdr;
        const struct rt2x00_rate *rate;
+       unsigned int align;
        unsigned int i;
        int idx = -1;
        u16 fc;
 
        /*
+        * The data behind the ieee80211 header must be
+        * aligned on a 4 byte boundary.
+        */
+       align = ((unsigned long)(entry->skb->data + header_size)) & 3;
+
+       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);
+
+       /*
         * Update RX statistics.
         */
        sband = &rt2x00dev->bands[rt2x00dev->curr_band];
        for (i = 0; i < sband->n_bitrates; i++) {
                rate = rt2x00_get_rate(sband->bitrates[i].hw_value);
 
-               /*
-                * When frame was received with an OFDM bitrate,
-                * the signal is the PLCP value. If it was received with
-                * a CCK bitrate the signal is the rate in 100kbit/s.
-                */
-               if ((rxdesc->ofdm && rate->plcp == rxdesc->signal) ||
-                   (!rxdesc->ofdm && rate->bitrate == rxdesc->signal)) {
+               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;
+       }
+
        /*
         * Only update link status if this is a beacon frame carrying our bssid.
         */
        hdr = (struct ieee80211_hdr *)entry->skb->data;
        fc = le16_to_cpu(hdr->frame_control);
-       if (is_beacon(fc) && rxdesc->my_bss)
+       if (is_beacon(fc) && (rxdesc->dev_flags & RXDONE_MY_BSS))
                rt2x00lib_update_link_stats(&rt2x00dev->link, rxdesc->rssi);
 
        rt2x00dev->link.qual.rx_success++;
 
        rx_status->rate_idx = idx;
-       rx_status->signal =
+       rx_status->qual =
            rt2x00lib_calculate_link_signal(rt2x00dev, rxdesc->rssi);
-       rx_status->ssi = rxdesc->rssi;
+       rx_status->signal = rxdesc->rssi;
        rx_status->flag = rxdesc->flags;
        rx_status->antenna = rt2x00dev->link.ant.active.rx;
 
@@ -613,228 +623,86 @@ void rt2x00lib_rxdone(struct queue_entry *entry,
         * Send frame to mac80211 & debugfs.
         * mac80211 will clean up the skb structure.
         */
-       get_skb_frame_desc(entry->skb)->frame_type = DUMP_FRAME_RXDONE;
-       rt2x00debug_dump_frame(rt2x00dev, entry->skb);
+       rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_RXDONE, entry->skb);
        ieee80211_rx_irqsafe(rt2x00dev->hw, entry->skb, rx_status);
        entry->skb = NULL;
 }
 EXPORT_SYMBOL_GPL(rt2x00lib_rxdone);
 
 /*
- * TX descriptor initializer
- */
-void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
-                            struct sk_buff *skb,
-                            struct ieee80211_tx_control *control)
-{
-       struct txentry_desc txdesc;
-       struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
-       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skbdesc->data;
-       const struct rt2x00_rate *rate;
-       int tx_rate;
-       int length;
-       int duration;
-       int residual;
-       u16 frame_control;
-       u16 seq_ctrl;
-
-       memset(&txdesc, 0, sizeof(txdesc));
-
-       txdesc.queue = skbdesc->entry->queue->qid;
-       txdesc.cw_min = skbdesc->entry->queue->cw_min;
-       txdesc.cw_max = skbdesc->entry->queue->cw_max;
-       txdesc.aifs = skbdesc->entry->queue->aifs;
-
-       /*
-        * Read required fields from ieee80211 header.
-        */
-       frame_control = le16_to_cpu(hdr->frame_control);
-       seq_ctrl = le16_to_cpu(hdr->seq_ctrl);
-
-       tx_rate = control->tx_rate->hw_value;
-
-       /*
-        * Check whether this frame is to be acked
-        */
-       if (!(control->flags & IEEE80211_TXCTL_NO_ACK))
-               __set_bit(ENTRY_TXD_ACK, &txdesc.flags);
-
-       /*
-        * Check if this is a RTS/CTS frame
-        */
-       if (is_rts_frame(frame_control) || is_cts_frame(frame_control)) {
-               __set_bit(ENTRY_TXD_BURST, &txdesc.flags);
-               if (is_rts_frame(frame_control)) {
-                       __set_bit(ENTRY_TXD_RTS_FRAME, &txdesc.flags);
-                       __set_bit(ENTRY_TXD_ACK, &txdesc.flags);
-               } else
-                       __clear_bit(ENTRY_TXD_ACK, &txdesc.flags);
-               if (control->rts_cts_rate)
-                       tx_rate = control->rts_cts_rate->hw_value;
-       }
-
-       rate = rt2x00_get_rate(tx_rate);
-
-       /*
-        * Check if more fragments are pending
-        */
-       if (ieee80211_get_morefrag(hdr)) {
-               __set_bit(ENTRY_TXD_BURST, &txdesc.flags);
-               __set_bit(ENTRY_TXD_MORE_FRAG, &txdesc.flags);
-       }
-
-       /*
-        * Beacons and probe responses require the tsf timestamp
-        * to be inserted into the frame.
-        */
-       if (control->queue == RT2X00_BCN_QUEUE_BEACON ||
-           is_probe_resp(frame_control))
-               __set_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc.flags);
-
-       /*
-        * Determine with what IFS priority this frame should be send.
-        * Set ifs to IFS_SIFS when the this is not the first fragment,
-        * or this fragment came after RTS/CTS.
-        */
-       if ((seq_ctrl & IEEE80211_SCTL_FRAG) > 0 ||
-           test_bit(ENTRY_TXD_RTS_FRAME, &txdesc.flags))
-               txdesc.ifs = IFS_SIFS;
-       else
-               txdesc.ifs = IFS_BACKOFF;
-
-       /*
-        * PLCP setup
-        * Length calculation depends on OFDM/CCK rate.
-        */
-       txdesc.signal = rate->plcp;
-       txdesc.service = 0x04;
-
-       length = skbdesc->data_len + FCS_LEN;
-       if (rate->flags & DEV_RATE_OFDM) {
-               __set_bit(ENTRY_TXD_OFDM_RATE, &txdesc.flags);
-
-               txdesc.length_high = (length >> 6) & 0x3f;
-               txdesc.length_low = length & 0x3f;
-       } else {
-               /*
-                * Convert length to microseconds.
-                */
-               residual = get_duration_res(length, rate->bitrate);
-               duration = get_duration(length, rate->bitrate);
-
-               if (residual != 0) {
-                       duration++;
-
-                       /*
-                        * Check if we need to set the Length Extension
-                        */
-                       if (rate->bitrate == 110 && residual <= 30)
-                               txdesc.service |= 0x80;
-               }
-
-               txdesc.length_high = (duration >> 8) & 0xff;
-               txdesc.length_low = duration & 0xff;
-
-               /*
-                * When preamble is enabled we should set the
-                * preamble bit for the signal.
-                */
-               if (rt2x00_get_rate_preamble(tx_rate))
-                       txdesc.signal |= 0x08;
-       }
-
-       rt2x00dev->ops->lib->write_tx_desc(rt2x00dev, skb, &txdesc, control);
-
-       /*
-        * Update queue entry.
-        */
-       skbdesc->entry->skb = skb;
-
-       /*
-        * The frame has been completely initialized and ready
-        * for sending to the device. The caller will push the
-        * frame to the device, but we are going to push the
-        * frame to debugfs here.
-        */
-       skbdesc->frame_type = DUMP_FRAME_TX;
-       rt2x00debug_dump_frame(rt2x00dev, skb);
-}
-EXPORT_SYMBOL_GPL(rt2x00lib_write_tx_desc);
-
-/*
  * Driver initialization handlers.
  */
 const struct rt2x00_rate rt2x00_supported_rates[12] = {
        {
-               .flags = DEV_RATE_CCK,
+               .flags = DEV_RATE_CCK | DEV_RATE_BASIC,
                .bitrate = 10,
-               .ratemask = DEV_RATEMASK_1MB,
+               .ratemask = BIT(0),
                .plcp = 0x00,
        },
        {
-               .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
+               .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE | DEV_RATE_BASIC,
                .bitrate = 20,
-               .ratemask = DEV_RATEMASK_2MB,
+               .ratemask = BIT(1),
                .plcp = 0x01,
        },
        {
-               .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
+               .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE | DEV_RATE_BASIC,
                .bitrate = 55,
-               .ratemask = DEV_RATEMASK_5_5MB,
+               .ratemask = BIT(2),
                .plcp = 0x02,
        },
        {
-               .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
+               .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE | DEV_RATE_BASIC,
                .bitrate = 110,
-               .ratemask = DEV_RATEMASK_11MB,
+               .ratemask = BIT(3),
                .plcp = 0x03,
        },
        {
-               .flags = DEV_RATE_OFDM,
+               .flags = DEV_RATE_OFDM | DEV_RATE_BASIC,
                .bitrate = 60,
-               .ratemask = DEV_RATEMASK_6MB,
+               .ratemask = BIT(4),
                .plcp = 0x0b,
        },
        {
                .flags = DEV_RATE_OFDM,
                .bitrate = 90,
-               .ratemask = DEV_RATEMASK_9MB,
+               .ratemask = BIT(5),
                .plcp = 0x0f,
        },
        {
-               .flags = DEV_RATE_OFDM,
+               .flags = DEV_RATE_OFDM | DEV_RATE_BASIC,
                .bitrate = 120,
-               .ratemask = DEV_RATEMASK_12MB,
+               .ratemask = BIT(6),
                .plcp = 0x0a,
        },
        {
                .flags = DEV_RATE_OFDM,
                .bitrate = 180,
-               .ratemask = DEV_RATEMASK_18MB,
+               .ratemask = BIT(7),
                .plcp = 0x0e,
        },
        {
-               .flags = DEV_RATE_OFDM,
+               .flags = DEV_RATE_OFDM | DEV_RATE_BASIC,
                .bitrate = 240,
-               .ratemask = DEV_RATEMASK_24MB,
+               .ratemask = BIT(8),
                .plcp = 0x09,
        },
        {
                .flags = DEV_RATE_OFDM,
                .bitrate = 360,
-               .ratemask = DEV_RATEMASK_36MB,
+               .ratemask = BIT(9),
                .plcp = 0x0d,
        },
        {
                .flags = DEV_RATE_OFDM,
                .bitrate = 480,
-               .ratemask = DEV_RATEMASK_48MB,
+               .ratemask = BIT(10),
                .plcp = 0x08,
        },
        {
                .flags = DEV_RATE_OFDM,
                .bitrate = 540,
-               .ratemask = DEV_RATEMASK_54MB,
+               .ratemask = BIT(11),
                .plcp = 0x0c,
        },
 };
@@ -977,6 +845,11 @@ static int rt2x00lib_probe_hw(struct rt2x00_dev *rt2x00dev)
                return status;
 
        /*
+        * Initialize HW fields.
+        */
+       rt2x00dev->hw->queues = rt2x00dev->ops->tx_queues;
+
+       /*
         * Register HW.
         */
        status = ieee80211_register_hw(rt2x00dev->hw);
@@ -999,7 +872,7 @@ static void rt2x00lib_uninitialize(struct rt2x00_dev *rt2x00dev)
                return;
 
        /*
-        * Unregister rfkill.
+        * Unregister extra components.
         */
        rt2x00rfkill_unregister(rt2x00dev);
 
@@ -1032,24 +905,19 @@ static int rt2x00lib_initialize(struct rt2x00_dev *rt2x00dev)
         * Initialize the device.
         */
        status = rt2x00dev->ops->lib->initialize(rt2x00dev);
-       if (status)
-               goto exit;
+       if (status) {
+               rt2x00queue_uninitialize(rt2x00dev);
+               return status;
+       }
 
        __set_bit(DEVICE_INITIALIZED, &rt2x00dev->flags);
 
        /*
-        * Register the rfkill handler.
+        * Register the extra components.
         */
-       status = rt2x00rfkill_register(rt2x00dev);
-       if (status)
-               goto exit;
+       rt2x00rfkill_register(rt2x00dev);
 
        return 0;
-
-exit:
-       rt2x00lib_uninitialize(rt2x00dev);
-
-       return status;
 }
 
 int rt2x00lib_start(struct rt2x00_dev *rt2x00dev)
@@ -1156,20 +1024,10 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
        }
 
        /*
-        * Register LED.
+        * Register extra components.
         */
        rt2x00leds_register(rt2x00dev);
-
-       /*
-        * Allocatie rfkill.
-        */
-       retval = rt2x00rfkill_allocate(rt2x00dev);
-       if (retval)
-               goto exit;
-
-       /*
-        * Open the debugfs entry.
-        */
+       rt2x00rfkill_allocate(rt2x00dev);
        rt2x00debug_register(rt2x00dev);
 
        __set_bit(DEVICE_PRESENT, &rt2x00dev->flags);
@@ -1198,18 +1056,10 @@ void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
        rt2x00lib_uninitialize(rt2x00dev);
 
        /*
-        * Close debugfs entry.
+        * Free extra components
         */
        rt2x00debug_deregister(rt2x00dev);
-
-       /*
-        * Free rfkill
-        */
        rt2x00rfkill_free(rt2x00dev);
-
-       /*
-        * Free LED.
-        */
        rt2x00leds_unregister(rt2x00dev);
 
        /*
@@ -1248,21 +1098,34 @@ int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state)
        __set_bit(DEVICE_STARTED_SUSPEND, &rt2x00dev->flags);
 
        /*
-        * Disable radio and unitialize all items
-        * that must be recreated on resume.
+        * Disable radio.
         */
        rt2x00lib_stop(rt2x00dev);
        rt2x00lib_uninitialize(rt2x00dev);
+
+       /*
+        * Suspend/disable extra components.
+        */
        rt2x00leds_suspend(rt2x00dev);
+       rt2x00rfkill_suspend(rt2x00dev);
        rt2x00debug_deregister(rt2x00dev);
 
 exit:
        /*
-        * Set device mode to sleep for power management.
+        * Set device mode to sleep for power management,
+        * on some hardware this call seems to consistently fail.
+        * From the specifications it is hard to tell why it fails,
+        * and if this is a "bad thing".
+        * Overall it is safe to just ignore the failure and
+        * continue suspending. The only downside is that the
+        * device will not be in optimal power save mode, but with
+        * 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)
-               return retval;
+               WARNING(rt2x00dev, "Device failed to enter sleep state, "
+                       "continue suspending.\n");
 
        return 0;
 }
@@ -1297,9 +1160,10 @@ int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
        NOTICE(rt2x00dev, "Waking up.\n");
 
        /*
-        * Open the debugfs entry and restore led handling.
+        * Restore/enable extra components.
         */
        rt2x00debug_register(rt2x00dev);
+       rt2x00rfkill_resume(rt2x00dev);
        rt2x00leds_resume(rt2x00dev);
 
        /*
@@ -1340,7 +1204,7 @@ int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
         * In that case we have disabled the TX queue and should
         * now enable it again
         */
-       ieee80211_start_queues(rt2x00dev->hw);
+       ieee80211_wake_queues(rt2x00dev->hw);
 
        /*
         * During interface iteration we might have changed the