]> err.no Git - linux-2.6/blobdiff - drivers/net/wireless/rt2x00/rt2x00dev.c
rt2x00: Fix TX status reporting
[linux-2.6] / drivers / net / wireless / rt2x00 / rt2x00dev.c
index 1bc8c14e6aec9efd17045333806baf0b64460991..69da22cf085c12bc3fb3b41d349f04b8bbb4186a 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "rt2x00.h"
 #include "rt2x00lib.h"
-#include "rt2x00dump.h"
 
 /*
  * Link tuning handlers
@@ -108,11 +107,14 @@ 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;
 
+       rt2x00leds_led_radio(rt2x00dev, true);
+       rt2x00led_led_activity(rt2x00dev, true);
+
        __set_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags);
 
        /*
@@ -155,6 +157,8 @@ void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev)
         * Disable radio.
         */
        rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_OFF);
+       rt2x00led_led_activity(rt2x00dev, false);
+       rt2x00leds_led_radio(rt2x00dev, false);
 }
 
 void rt2x00lib_toggle_rx(struct rt2x00_dev *rt2x00dev, enum dev_state state)
@@ -378,6 +382,11 @@ static void rt2x00lib_link_tuner(struct work_struct *work)
         */
        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.
@@ -396,18 +405,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,
@@ -435,16 +434,16 @@ static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac,
 
        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);
+               if (skb && rt2x00dev->ops->hw->beacon_update(rt2x00dev->hw,
+                                                            skb, &control))
                        dev_kfree_skb(skb);
-               }
        }
 
-       if (delayed_flags & DELAYED_CONFIG_PREAMBLE)
-               rt2x00lib_config_preamble(rt2x00dev, intf,
-                                         intf->conf.use_short_preamble);
+       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)
@@ -495,52 +494,57 @@ 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);
 
        /*
         * 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 +=
+           txdesc->retry + !!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.excessive_retries =
+           test_bit(TXDONE_EXCESSIVE_RETRY, &txdesc->flags);
        tx_status.retry_count = txdesc->retry;
-       memcpy(&tx_status.control, txdesc->control, sizeof(txdesc->control));
+       memcpy(&tx_status.control, txdesc->control, sizeof(*txdesc->control));
 
        if (!(tx_status.control.flags & IEEE80211_TXCTL_NO_ACK)) {
-               if (success)
+               if (test_bit(TXDONE_SUCCESS, &txdesc->flags))
                        tx_status.flags |= IEEE80211_TX_STATUS_ACK;
-               else
+               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 (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 mac80211 & debugfs.
-        * mac80211 will clean up the skb structure.
+        * 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.
         */
-       get_skb_frame_desc(entry->skb)->frame_type = DUMP_FRAME_TXDONE;
-       rt2x00debug_dump_frame(rt2x00dev, entry->skb);
-       ieee80211_tx_status_irqsafe(rt2x00dev->hw, entry->skb, &tx_status);
+       rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TXDONE, entry->skb);
+
+       skbdesc = get_skb_frame_desc(entry->skb);
+       if (!(skbdesc->flags & FRAME_DESC_DRIVER_GENERATED))
+               ieee80211_tx_status_irqsafe(rt2x00dev->hw,
+                                           entry->skb, &tx_status);
+       else
+               dev_kfree_skb_irq(entry->skb);
        entry->skb = NULL;
 }
 EXPORT_SYMBOL_GPL(rt2x00lib_txdone);
@@ -550,50 +554,50 @@ void rt2x00lib_rxdone(struct queue_entry *entry,
 {
        struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
        struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status;
-       struct ieee80211_hw_mode *mode;
-       struct ieee80211_rate *rate;
+       struct ieee80211_supported_band *sband;
        struct ieee80211_hdr *hdr;
+       const struct rt2x00_rate *rate;
        unsigned int i;
-       int val = 0;
+       int idx = -1;
        u16 fc;
 
        /*
         * Update RX statistics.
         */
-       mode = &rt2x00dev->hwmodes[rt2x00dev->curr_hwmode];
-       for (i = 0; i < mode->num_rates; i++) {
-               rate = &mode->rates[i];
+       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 0.5kbit/s.
-                */
-               if (!rxdesc->ofdm)
-                       val = DEVICE_GET_RATE_FIELD(rate->val, RATE);
-               else
-                       val = DEVICE_GET_RATE_FIELD(rate->val, PLCP);
-
-               if (val == rxdesc->signal) {
-                       val = rate->val;
+               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;
+       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 = val;
-       rx_status->signal =
+       rx_status->rate_idx = idx;
+       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;
 
@@ -601,8 +605,7 @@ 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;
 }
@@ -617,9 +620,9 @@ void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
 {
        struct txentry_desc txdesc;
        struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
-       struct ieee80211_hdr *ieee80211hdr = (struct ieee80211_hdr *)skb->data;
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skbdesc->data;
+       const struct rt2x00_rate *rate;
        int tx_rate;
-       int bitrate;
        int length;
        int duration;
        int residual;
@@ -636,10 +639,10 @@ void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
        /*
         * Read required fields from ieee80211 header.
         */
-       frame_control = le16_to_cpu(ieee80211hdr->frame_control);
-       seq_ctrl = le16_to_cpu(ieee80211hdr->seq_ctrl);
+       frame_control = le16_to_cpu(hdr->frame_control);
+       seq_ctrl = le16_to_cpu(hdr->seq_ctrl);
 
-       tx_rate = control->tx_rate;
+       tx_rate = control->tx_rate->hw_value;
 
        /*
         * Check whether this frame is to be acked
@@ -658,19 +661,15 @@ void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
                } else
                        __clear_bit(ENTRY_TXD_ACK, &txdesc.flags);
                if (control->rts_cts_rate)
-                       tx_rate = control->rts_cts_rate;
+                       tx_rate = control->rts_cts_rate->hw_value;
        }
 
-       /*
-        * Check for OFDM
-        */
-       if (DEVICE_GET_RATE_FIELD(tx_rate, RATEMASK) & DEV_OFDM_RATEMASK)
-               __set_bit(ENTRY_TXD_OFDM_RATE, &txdesc.flags);
+       rate = rt2x00_get_rate(tx_rate);
 
        /*
         * Check if more fragments are pending
         */
-       if (ieee80211_get_morefrag(ieee80211hdr)) {
+       if (ieee80211_get_morefrag(hdr)) {
                __set_bit(ENTRY_TXD_BURST, &txdesc.flags);
                __set_bit(ENTRY_TXD_MORE_FRAG, &txdesc.flags);
        }
@@ -679,8 +678,7 @@ void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
         * Beacons and probe responses require the tsf timestamp
         * to be inserted into the frame.
         */
-       if (control->queue == IEEE80211_TX_QUEUE_BEACON ||
-           is_probe_resp(frame_control))
+       if (txdesc.queue == QID_BEACON || is_probe_resp(frame_control))
                __set_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc.flags);
 
        /*
@@ -698,21 +696,21 @@ void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
         * PLCP setup
         * Length calculation depends on OFDM/CCK rate.
         */
-       txdesc.signal = DEVICE_GET_RATE_FIELD(tx_rate, PLCP);
+       txdesc.signal = rate->plcp;
        txdesc.service = 0x04;
 
-       length = skb->len + FCS_LEN;
-       if (test_bit(ENTRY_TXD_OFDM_RATE, &txdesc.flags)) {
+       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 {
-               bitrate = DEVICE_GET_RATE_FIELD(tx_rate, RATE);
-
                /*
                 * Convert length to microseconds.
                 */
-               residual = get_duration_res(length, bitrate);
-               duration = get_duration(length, bitrate);
+               residual = get_duration_res(length, rate->bitrate);
+               duration = get_duration(length, rate->bitrate);
 
                if (residual != 0) {
                        duration++;
@@ -720,7 +718,7 @@ void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
                        /*
                         * Check if we need to set the Length Extension
                         */
-                       if (bitrate == 110 && residual <= 30)
+                       if (rate->bitrate == 110 && residual <= 30)
                                txdesc.service |= 0x80;
                }
 
@@ -731,7 +729,7 @@ void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
                 * When preamble is enabled we should set the
                 * preamble bit for the signal.
                 */
-               if (DEVICE_GET_RATE_FIELD(tx_rate, PREAMBLE))
+               if (rt2x00_get_rate_preamble(tx_rate))
                        txdesc.signal |= 0x08;
        }
 
@@ -748,141 +746,174 @@ void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
         * 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);
+       rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TX, skb);
 }
 EXPORT_SYMBOL_GPL(rt2x00lib_write_tx_desc);
 
 /*
  * Driver initialization handlers.
  */
+const struct rt2x00_rate rt2x00_supported_rates[12] = {
+       {
+               .flags = DEV_RATE_CCK | DEV_RATE_BASIC,
+               .bitrate = 10,
+               .ratemask = BIT(0),
+               .plcp = 0x00,
+       },
+       {
+               .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE | DEV_RATE_BASIC,
+               .bitrate = 20,
+               .ratemask = BIT(1),
+               .plcp = 0x01,
+       },
+       {
+               .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE | DEV_RATE_BASIC,
+               .bitrate = 55,
+               .ratemask = BIT(2),
+               .plcp = 0x02,
+       },
+       {
+               .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE | DEV_RATE_BASIC,
+               .bitrate = 110,
+               .ratemask = BIT(3),
+               .plcp = 0x03,
+       },
+       {
+               .flags = DEV_RATE_OFDM | DEV_RATE_BASIC,
+               .bitrate = 60,
+               .ratemask = BIT(4),
+               .plcp = 0x0b,
+       },
+       {
+               .flags = DEV_RATE_OFDM,
+               .bitrate = 90,
+               .ratemask = BIT(5),
+               .plcp = 0x0f,
+       },
+       {
+               .flags = DEV_RATE_OFDM | DEV_RATE_BASIC,
+               .bitrate = 120,
+               .ratemask = BIT(6),
+               .plcp = 0x0a,
+       },
+       {
+               .flags = DEV_RATE_OFDM,
+               .bitrate = 180,
+               .ratemask = BIT(7),
+               .plcp = 0x0e,
+       },
+       {
+               .flags = DEV_RATE_OFDM | DEV_RATE_BASIC,
+               .bitrate = 240,
+               .ratemask = BIT(8),
+               .plcp = 0x09,
+       },
+       {
+               .flags = DEV_RATE_OFDM,
+               .bitrate = 360,
+               .ratemask = BIT(9),
+               .plcp = 0x0d,
+       },
+       {
+               .flags = DEV_RATE_OFDM,
+               .bitrate = 480,
+               .ratemask = BIT(10),
+               .plcp = 0x08,
+       },
+       {
+               .flags = DEV_RATE_OFDM,
+               .bitrate = 540,
+               .ratemask = BIT(11),
+               .plcp = 0x0c,
+       },
+};
+
 static void rt2x00lib_channel(struct ieee80211_channel *entry,
                              const int channel, const int tx_power,
                              const int value)
 {
-       entry->chan = channel;
-       if (channel <= 14)
-               entry->freq = 2407 + (5 * channel);
-       else
-               entry->freq = 5000 + (5 * channel);
-       entry->val = value;
-       entry->flag =
-           IEEE80211_CHAN_W_IBSS |
-           IEEE80211_CHAN_W_ACTIVE_SCAN |
-           IEEE80211_CHAN_W_SCAN;
-       entry->power_level = tx_power;
-       entry->antenna_max = 0xff;
+       entry->center_freq = ieee80211_channel_to_frequency(channel);
+       entry->hw_value = value;
+       entry->max_power = tx_power;
+       entry->max_antenna_gain = 0xff;
 }
 
 static void rt2x00lib_rate(struct ieee80211_rate *entry,
-                          const int rate, const int mask,
-                          const int plcp, const int flags)
+                          const u16 index, const struct rt2x00_rate *rate)
 {
-       entry->rate = rate;
-       entry->val =
-           DEVICE_SET_RATE_FIELD(rate, RATE) |
-           DEVICE_SET_RATE_FIELD(mask, RATEMASK) |
-           DEVICE_SET_RATE_FIELD(plcp, PLCP);
-       entry->flags = flags;
-       entry->val2 = entry->val;
-       if (entry->flags & IEEE80211_RATE_PREAMBLE2)
-               entry->val2 |= DEVICE_SET_RATE_FIELD(1, PREAMBLE);
-       entry->min_rssi_ack = 0;
-       entry->min_rssi_ack_delta = 0;
+       entry->flags = 0;
+       entry->bitrate = rate->bitrate;
+       entry->hw_value = rt2x00_create_rate_hw_value(index, 0);
+       entry->hw_value_short = entry->hw_value;
+
+       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,
                                    struct hw_mode_spec *spec)
 {
        struct ieee80211_hw *hw = rt2x00dev->hw;
-       struct ieee80211_hw_mode *hwmodes;
        struct ieee80211_channel *channels;
        struct ieee80211_rate *rates;
+       unsigned int num_rates;
        unsigned int i;
        unsigned char tx_power;
 
-       hwmodes = kzalloc(sizeof(*hwmodes) * spec->num_modes, GFP_KERNEL);
-       if (!hwmodes)
-               goto exit;
+       num_rates = 0;
+       if (spec->supported_rates & SUPPORT_RATE_CCK)
+               num_rates += 4;
+       if (spec->supported_rates & SUPPORT_RATE_OFDM)
+               num_rates += 8;
 
        channels = kzalloc(sizeof(*channels) * spec->num_channels, GFP_KERNEL);
        if (!channels)
-               goto exit_free_modes;
+               return -ENOMEM;
 
-       rates = kzalloc(sizeof(*rates) * spec->num_rates, GFP_KERNEL);
+       rates = kzalloc(sizeof(*rates) * num_rates, GFP_KERNEL);
        if (!rates)
                goto exit_free_channels;
 
        /*
         * Initialize Rate list.
         */
-       rt2x00lib_rate(&rates[0], 10, DEV_RATEMASK_1MB,
-                      0x00, IEEE80211_RATE_CCK);
-       rt2x00lib_rate(&rates[1], 20, DEV_RATEMASK_2MB,
-                      0x01, IEEE80211_RATE_CCK_2);
-       rt2x00lib_rate(&rates[2], 55, DEV_RATEMASK_5_5MB,
-                      0x02, IEEE80211_RATE_CCK_2);
-       rt2x00lib_rate(&rates[3], 110, DEV_RATEMASK_11MB,
-                      0x03, IEEE80211_RATE_CCK_2);
-
-       if (spec->num_rates > 4) {
-               rt2x00lib_rate(&rates[4], 60, DEV_RATEMASK_6MB,
-                              0x0b, IEEE80211_RATE_OFDM);
-               rt2x00lib_rate(&rates[5], 90, DEV_RATEMASK_9MB,
-                              0x0f, IEEE80211_RATE_OFDM);
-               rt2x00lib_rate(&rates[6], 120, DEV_RATEMASK_12MB,
-                              0x0a, IEEE80211_RATE_OFDM);
-               rt2x00lib_rate(&rates[7], 180, DEV_RATEMASK_18MB,
-                              0x0e, IEEE80211_RATE_OFDM);
-               rt2x00lib_rate(&rates[8], 240, DEV_RATEMASK_24MB,
-                              0x09, IEEE80211_RATE_OFDM);
-               rt2x00lib_rate(&rates[9], 360, DEV_RATEMASK_36MB,
-                              0x0d, IEEE80211_RATE_OFDM);
-               rt2x00lib_rate(&rates[10], 480, DEV_RATEMASK_48MB,
-                              0x08, IEEE80211_RATE_OFDM);
-               rt2x00lib_rate(&rates[11], 540, DEV_RATEMASK_54MB,
-                              0x0c, IEEE80211_RATE_OFDM);
-       }
+       for (i = 0; i < num_rates; i++)
+               rt2x00lib_rate(&rates[i], i, rt2x00_get_rate(i));
 
        /*
         * Initialize Channel list.
         */
        for (i = 0; i < spec->num_channels; i++) {
-               if (spec->channels[i].channel <= 14)
-                       tx_power = spec->tx_power_bg[i];
-               else if (spec->tx_power_a)
-                       tx_power = spec->tx_power_a[i];
-               else
-                       tx_power = spec->tx_power_default;
+               if (spec->channels[i].channel <= 14) {
+                       if (spec->tx_power_bg)
+                               tx_power = spec->tx_power_bg[i];
+                       else
+                               tx_power = spec->tx_power_default;
+               } else {
+                       if (spec->tx_power_a)
+                               tx_power = spec->tx_power_a[i];
+                       else
+                               tx_power = spec->tx_power_default;
+               }
 
                rt2x00lib_channel(&channels[i],
                                  spec->channels[i].channel, tx_power, i);
        }
 
        /*
-        * Intitialize 802.11b
-        * Rates: CCK.
-        * Channels: OFDM.
-        */
-       if (spec->num_modes > HWMODE_B) {
-               hwmodes[HWMODE_B].mode = MODE_IEEE80211B;
-               hwmodes[HWMODE_B].num_channels = 14;
-               hwmodes[HWMODE_B].num_rates = 4;
-               hwmodes[HWMODE_B].channels = channels;
-               hwmodes[HWMODE_B].rates = rates;
-       }
-
-       /*
-        * Intitialize 802.11g
+        * Intitialize 802.11b, 802.11g
         * Rates: CCK, OFDM.
-        * Channels: OFDM.
-        */
-       if (spec->num_modes > HWMODE_G) {
-               hwmodes[HWMODE_G].mode = MODE_IEEE80211G;
-               hwmodes[HWMODE_G].num_channels = 14;
-               hwmodes[HWMODE_G].num_rates = spec->num_rates;
-               hwmodes[HWMODE_G].channels = channels;
-               hwmodes[HWMODE_G].rates = rates;
+        * Channels: 2.4 GHz
+        */
+       if (spec->supported_bands & SUPPORT_BAND_2GHZ) {
+               rt2x00dev->bands[IEEE80211_BAND_2GHZ].n_channels = 14;
+               rt2x00dev->bands[IEEE80211_BAND_2GHZ].n_bitrates = num_rates;
+               rt2x00dev->bands[IEEE80211_BAND_2GHZ].channels = channels;
+               rt2x00dev->bands[IEEE80211_BAND_2GHZ].bitrates = rates;
+               hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
+                   &rt2x00dev->bands[IEEE80211_BAND_2GHZ];
        }
 
        /*
@@ -890,40 +921,21 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
         * Rates: OFDM.
         * Channels: OFDM, UNII, HiperLAN2.
         */
-       if (spec->num_modes > HWMODE_A) {
-               hwmodes[HWMODE_A].mode = MODE_IEEE80211A;
-               hwmodes[HWMODE_A].num_channels = spec->num_channels - 14;
-               hwmodes[HWMODE_A].num_rates = spec->num_rates - 4;
-               hwmodes[HWMODE_A].channels = &channels[14];
-               hwmodes[HWMODE_A].rates = &rates[4];
+       if (spec->supported_bands & SUPPORT_BAND_5GHZ) {
+               rt2x00dev->bands[IEEE80211_BAND_5GHZ].n_channels =
+                   spec->num_channels - 14;
+               rt2x00dev->bands[IEEE80211_BAND_5GHZ].n_bitrates =
+                   num_rates - 4;
+               rt2x00dev->bands[IEEE80211_BAND_5GHZ].channels = &channels[14];
+               rt2x00dev->bands[IEEE80211_BAND_5GHZ].bitrates = &rates[4];
+               hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
+                   &rt2x00dev->bands[IEEE80211_BAND_5GHZ];
        }
 
-       if (spec->num_modes > HWMODE_G &&
-           ieee80211_register_hwmode(hw, &hwmodes[HWMODE_G]))
-               goto exit_free_rates;
-
-       if (spec->num_modes > HWMODE_B &&
-           ieee80211_register_hwmode(hw, &hwmodes[HWMODE_B]))
-               goto exit_free_rates;
-
-       if (spec->num_modes > HWMODE_A &&
-           ieee80211_register_hwmode(hw, &hwmodes[HWMODE_A]))
-               goto exit_free_rates;
-
-       rt2x00dev->hwmodes = hwmodes;
-
        return 0;
 
-exit_free_rates:
-       kfree(rates);
-
-exit_free_channels:
+ exit_free_channels:
        kfree(channels);
-
-exit_free_modes:
-       kfree(hwmodes);
-
-exit:
        ERROR(rt2x00dev, "Allocation ieee80211 modes failed.\n");
        return -ENOMEM;
 }
@@ -933,11 +945,11 @@ static void rt2x00lib_remove_hw(struct rt2x00_dev *rt2x00dev)
        if (test_bit(DEVICE_REGISTERED_HW, &rt2x00dev->flags))
                ieee80211_unregister_hw(rt2x00dev->hw);
 
-       if (likely(rt2x00dev->hwmodes)) {
-               kfree(rt2x00dev->hwmodes->channels);
-               kfree(rt2x00dev->hwmodes->rates);
-               kfree(rt2x00dev->hwmodes);
-               rt2x00dev->hwmodes = NULL;
+       if (likely(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ])) {
+               kfree(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
+               kfree(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->bitrates);
+               rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
+               rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
        }
 }
 
@@ -976,7 +988,7 @@ static void rt2x00lib_uninitialize(struct rt2x00_dev *rt2x00dev)
                return;
 
        /*
-        * Unregister rfkill.
+        * Unregister extra components.
         */
        rt2x00rfkill_unregister(rt2x00dev);
 
@@ -1009,24 +1021,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)
@@ -1133,15 +1140,10 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
        }
 
        /*
-        * Allocatie rfkill.
-        */
-       retval = rt2x00rfkill_allocate(rt2x00dev);
-       if (retval)
-               goto exit;
-
-       /*
-        * Open the debugfs entry.
+        * Register extra components.
         */
+       rt2x00leds_register(rt2x00dev);
+       rt2x00rfkill_allocate(rt2x00dev);
        rt2x00debug_register(rt2x00dev);
 
        __set_bit(DEVICE_PRESENT, &rt2x00dev->flags);
@@ -1170,14 +1172,11 @@ 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);
+       rt2x00leds_unregister(rt2x00dev);
 
        /*
         * Free ieee80211_hw memory.
@@ -1215,20 +1214,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;
 }
@@ -1263,9 +1276,11 @@ int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
        NOTICE(rt2x00dev, "Waking up.\n");
 
        /*
-        * Open the debugfs entry.
+        * Restore/enable extra components.
         */
        rt2x00debug_register(rt2x00dev);
+       rt2x00rfkill_resume(rt2x00dev);
+       rt2x00leds_resume(rt2x00dev);
 
        /*
         * Only continue if mac80211 had open interfaces.