]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/net/wireless/rt2x00/rt2x00dev.c
rt2x00: Add dev_flags to rx descriptor
[mirror_ubuntu-bionic-kernel.git] / drivers / net / wireless / rt2x00 / rt2x00dev.c
index f0ba481c51e67917c06f6d65a67d39fe971ba062..4fd0c25aebf3b9f6147df3381ec2f05ce455a4ec 100644 (file)
@@ -378,6 +378,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.
@@ -442,9 +447,8 @@ static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac,
                }
        }
 
-       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);
 }
 
 static void rt2x00lib_intf_scheduled(struct work_struct *work)
@@ -495,6 +499,7 @@ 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);
@@ -515,7 +520,7 @@ void rt2x00lib_txdone(struct queue_entry *entry,
        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));
+       memcpy(&tx_status.control, txdesc->control, sizeof(*txdesc->control));
 
        if (!(tx_status.control.flags & IEEE80211_TXCTL_NO_ACK)) {
                if (success)
@@ -535,12 +540,23 @@ void rt2x00lib_txdone(struct queue_entry *entry,
        }
 
        /*
-        * 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;
+       skbdesc = get_skb_frame_desc(entry->skb);
+       skbdesc->frame_type = DUMP_FRAME_TXDONE;
+
        rt2x00debug_dump_frame(rt2x00dev, entry->skb);
-       ieee80211_tx_status_irqsafe(rt2x00dev->hw, entry->skb, &tx_status);
+
+       if (!(skbdesc->flags & FRAME_DESC_DRIVER_GENERATED))
+               ieee80211_tx_status_irqsafe(rt2x00dev->hw,
+                                           entry->skb, &tx_status);
+       else
+               dev_kfree_skb(entry->skb);
        entry->skb = NULL;
 }
 EXPORT_SYMBOL_GPL(rt2x00lib_txdone);
@@ -564,13 +580,10 @@ void rt2x00lib_rxdone(struct queue_entry *entry,
        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;
                }
@@ -581,7 +594,7 @@ void rt2x00lib_rxdone(struct queue_entry *entry,
         */
        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++;
@@ -613,7 +626,7 @@ 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 *hdr = (struct ieee80211_hdr *)skb->data;
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skbdesc->data;
        const struct rt2x00_rate *rate;
        int tx_rate;
        int length;
@@ -693,7 +706,7 @@ void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
        txdesc.signal = rate->plcp;
        txdesc.service = 0x04;
 
-       length = skb->len + FCS_LEN;
+       length = skbdesc->data_len + FCS_LEN;
        if (rate->flags & DEV_RATE_OFDM) {
                __set_bit(ENTRY_TXD_OFDM_RATE, &txdesc.flags);
 
@@ -750,75 +763,75 @@ EXPORT_SYMBOL_GPL(rt2x00lib_write_tx_desc);
  */
 const struct rt2x00_rate rt2x00_supported_rates[12] = {
        {
-               .flags = 0,
+               .flags = DEV_RATE_CCK | DEV_RATE_BASIC,
                .bitrate = 10,
-               .ratemask = DEV_RATEMASK_1MB,
+               .ratemask = BIT(0),
                .plcp = 0x00,
        },
        {
-               .flags = 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_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_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,
        },
 };
@@ -827,10 +840,7 @@ static void rt2x00lib_channel(struct ieee80211_channel *entry,
                              const int channel, const int tx_power,
                              const int value)
 {
-       if (channel <= 14)
-               entry->center_freq = 2407 + (5 * channel);
-       else
-               entry->center_freq = 5000 + (5 * channel);
+       entry->center_freq = ieee80211_channel_to_frequency(channel);
        entry->hw_value = value;
        entry->max_power = tx_power;
        entry->max_antenna_gain = 0xff;
@@ -854,67 +864,64 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
                                    struct hw_mode_spec *spec)
 {
        struct ieee80211_hw *hw = rt2x00dev->hw;
-       struct ieee80211_supported_band *sbands;
        struct ieee80211_channel *channels;
        struct ieee80211_rate *rates;
+       unsigned int num_rates;
        unsigned int i;
        unsigned char tx_power;
 
-       sbands = &rt2x00dev->bands[0];
+       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)
                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.
         */
-       for (i = 0; i < spec->num_rates; i++)
-               rt2x00lib_rate(&rates[0], i, rt2x00_get_rate(i));
+       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: 2.4 GHz
-        */
-       if (spec->num_modes > HWMODE_B) {
-               sbands[IEEE80211_BAND_2GHZ].n_channels = 14;
-               sbands[IEEE80211_BAND_2GHZ].n_bitrates = 4;
-               sbands[IEEE80211_BAND_2GHZ].channels = channels;
-               sbands[IEEE80211_BAND_2GHZ].bitrates = rates;
-               hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &rt2x00dev->bands[IEEE80211_BAND_2GHZ];
-       }
-
-       /*
-        * Intitialize 802.11g
+        * Intitialize 802.11b, 802.11g
         * Rates: CCK, OFDM.
         * Channels: 2.4 GHz
         */
-       if (spec->num_modes > HWMODE_G) {
-               sbands[IEEE80211_BAND_2GHZ].n_channels = 14;
-               sbands[IEEE80211_BAND_2GHZ].n_bitrates = spec->num_rates;
-               sbands[IEEE80211_BAND_2GHZ].channels = channels;
-               sbands[IEEE80211_BAND_2GHZ].bitrates = rates;
-               hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &rt2x00dev->bands[IEEE80211_BAND_2GHZ];
+       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];
        }
 
        /*
@@ -922,12 +929,15 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
         * Rates: OFDM.
         * Channels: OFDM, UNII, HiperLAN2.
         */
-       if (spec->num_modes > HWMODE_A) {
-               sbands[IEEE80211_BAND_5GHZ].n_channels = spec->num_channels - 14;
-               sbands[IEEE80211_BAND_5GHZ].n_bitrates = spec->num_rates - 4;
-               sbands[IEEE80211_BAND_5GHZ].channels = &channels[14];
-               sbands[IEEE80211_BAND_5GHZ].bitrates = &rates[4];
-               hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &rt2x00dev->bands[IEEE80211_BAND_5GHZ];
+       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];
        }
 
        return 0;
@@ -986,7 +996,7 @@ static void rt2x00lib_uninitialize(struct rt2x00_dev *rt2x00dev)
                return;
 
        /*
-        * Unregister rfkill.
+        * Unregister extra components.
         */
        rt2x00rfkill_unregister(rt2x00dev);
 
@@ -1025,11 +1035,9 @@ static int rt2x00lib_initialize(struct rt2x00_dev *rt2x00dev)
        __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;
 
@@ -1143,15 +1151,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);
@@ -1180,14 +1183,15 @@ void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
        rt2x00lib_uninitialize(rt2x00dev);
 
        /*
-        * Close debugfs entry.
+        * Free extra components
         */
        rt2x00debug_deregister(rt2x00dev);
+       rt2x00rfkill_free(rt2x00dev);
 
        /*
-        * Free rfkill
+        * Free LED.
         */
-       rt2x00rfkill_free(rt2x00dev);
+       rt2x00leds_unregister(rt2x00dev);
 
        /*
         * Free ieee80211_hw memory.
@@ -1225,11 +1229,16 @@ 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:
@@ -1273,9 +1282,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.