]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/net/wireless/wl12xx/main.c
Merge tag 'v2.6.38' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[mv-sheeva.git] / drivers / net / wireless / wl12xx / main.c
similarity index 87%
rename from drivers/net/wireless/wl12xx/wl1271_main.c
rename to drivers/net/wireless/wl12xx/main.c
index 48a4b9961ae6e1bea44a4985bca56e46bdf1ee32..062247ef3ad2742378c7993649eef5780842c665 100644 (file)
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 
-#include "wl1271.h"
+#include "wl12xx.h"
 #include "wl12xx_80211.h"
-#include "wl1271_reg.h"
-#include "wl1271_io.h"
-#include "wl1271_event.h"
-#include "wl1271_tx.h"
-#include "wl1271_rx.h"
-#include "wl1271_ps.h"
-#include "wl1271_init.h"
-#include "wl1271_debugfs.h"
-#include "wl1271_cmd.h"
-#include "wl1271_boot.h"
-#include "wl1271_testmode.h"
-#include "wl1271_scan.h"
+#include "reg.h"
+#include "io.h"
+#include "event.h"
+#include "tx.h"
+#include "rx.h"
+#include "ps.h"
+#include "init.h"
+#include "debugfs.h"
+#include "cmd.h"
+#include "boot.h"
+#include "testmode.h"
+#include "scan.h"
 
 #define WL1271_BOOT_RETRIES 3
 
@@ -335,6 +335,28 @@ out:
        return NOTIFY_OK;
 }
 
+static int wl1271_reg_notify(struct wiphy *wiphy,
+                            struct regulatory_request *request)
+{
+       struct ieee80211_supported_band *band;
+       struct ieee80211_channel *ch;
+       int i;
+
+       band = wiphy->bands[IEEE80211_BAND_5GHZ];
+       for (i = 0; i < band->n_channels; i++) {
+               ch = &band->channels[i];
+               if (ch->flags & IEEE80211_CHAN_DISABLED)
+                       continue;
+
+               if (ch->flags & IEEE80211_CHAN_RADAR)
+                       ch->flags |= IEEE80211_CHAN_NO_IBSS |
+                                    IEEE80211_CHAN_PASSIVE_SCAN;
+
+       }
+
+       return 0;
+}
+
 static void wl1271_conf_init(struct wl1271 *wl)
 {
 
@@ -404,7 +426,7 @@ static int wl1271_plt_init(struct wl1271 *wl)
                goto out_free_memmap;
 
        /* Default fragmentation threshold */
-       ret = wl1271_acx_frag_threshold(wl);
+       ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold);
        if (ret < 0)
                goto out_free_memmap;
 
@@ -481,9 +503,9 @@ static void wl1271_fw_status(struct wl1271 *wl,
                total += cnt;
        }
 
-       /* if more blocks are available now, schedule some tx work */
-       if (total && !skb_queue_empty(&wl->tx_queue))
-               ieee80211_queue_work(wl->hw, &wl->tx_work);
+       /* if more blocks are available now, tx work can be scheduled */
+       if (total)
+               clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
 
        /* update the host-chipset time offset */
        getnstimeofday(&ts);
@@ -529,6 +551,15 @@ static void wl1271_irq_work(struct work_struct *work)
 
                intr &= WL1271_INTR_MASK;
 
+               if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
+                       wl1271_error("watchdog interrupt received! "
+                                    "starting recovery.");
+                       ieee80211_queue_work(wl->hw, &wl->recovery_work);
+
+                       /* restarting the chip. ignore any other interrupt. */
+                       goto out;
+               }
+
                if (intr & WL1271_ACX_INTR_DATA) {
                        wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
 
@@ -537,6 +568,16 @@ static void wl1271_irq_work(struct work_struct *work)
                            (wl->tx_results_count & 0xff))
                                wl1271_tx_complete(wl);
 
+                       /* Check if any tx blocks were freed */
+                       if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
+                           wl->tx_queue_count) {
+                               /*
+                                * In order to avoid starvation of the TX path,
+                                * call the work function directly.
+                                */
+                               wl1271_tx_work_locked(wl);
+                       }
+
                        wl1271_rx(wl, wl->fw_status);
                }
 
@@ -850,30 +891,54 @@ static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
        struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb);
        struct ieee80211_sta *sta = txinfo->control.sta;
        unsigned long flags;
+       int q;
 
-       /* peek into the rates configured in the STA entry */
+       /*
+        * peek into the rates configured in the STA entry.
+        * The rates set after connection stage, The first block only BG sets:
+        * the compare is for bit 0-16 of sta_rate_set. The second block add
+        * HT rates in case of HT supported.
+        */
        spin_lock_irqsave(&wl->wl_lock, flags);
-       if (sta && sta->supp_rates[conf->channel->band] != wl->sta_rate_set) {
+       if (sta &&
+           (sta->supp_rates[conf->channel->band] !=
+           (wl->sta_rate_set & HW_BG_RATES_MASK))) {
                wl->sta_rate_set = sta->supp_rates[conf->channel->band];
                set_bit(WL1271_FLAG_STA_RATES_CHANGED, &wl->flags);
        }
+
+#ifdef CONFIG_WL12XX_HT
+       if (sta &&
+           sta->ht_cap.ht_supported &&
+           ((wl->sta_rate_set >> HW_HT_RATES_OFFSET) !=
+             sta->ht_cap.mcs.rx_mask[0])) {
+               /* Clean MCS bits before setting them */
+               wl->sta_rate_set &= HW_BG_RATES_MASK;
+               wl->sta_rate_set |=
+                       (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
+               set_bit(WL1271_FLAG_STA_RATES_CHANGED, &wl->flags);
+       }
+#endif
+       wl->tx_queue_count++;
        spin_unlock_irqrestore(&wl->wl_lock, flags);
 
        /* queue the packet */
-       skb_queue_tail(&wl->tx_queue, skb);
+       q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
+       skb_queue_tail(&wl->tx_queue[q], skb);
 
        /*
         * The chip specific setup must run before the first TX packet -
         * before that, the tx_work will not be initialized!
         */
 
-       ieee80211_queue_work(wl->hw, &wl->tx_work);
+       if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
+               ieee80211_queue_work(wl->hw, &wl->tx_work);
 
        /*
         * The workqueue is slow to process the tx_queue and we need stop
         * the queue here, otherwise the queue will get too long.
         */
-       if (skb_queue_len(&wl->tx_queue) >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
+       if (wl->tx_queue_count >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
                wl1271_debug(DEBUG_TX, "op_tx: stopping queues");
 
                spin_lock_irqsave(&wl->wl_lock, flags);
@@ -919,18 +984,19 @@ static int wl1271_op_add_interface(struct ieee80211_hw *hw,
        struct wiphy *wiphy = hw->wiphy;
        int retries = WL1271_BOOT_RETRIES;
        int ret = 0;
+       bool booted = false;
 
        wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
                     vif->type, vif->addr);
 
        mutex_lock(&wl->mutex);
        if (wl->vif) {
+               wl1271_debug(DEBUG_MAC80211,
+                            "multiple vifs are not supported yet");
                ret = -EBUSY;
                goto out;
        }
 
-       wl->vif = vif;
-
        switch (vif->type) {
        case NL80211_IFTYPE_STATION:
                wl->bss_type = BSS_TYPE_STA_BSS;
@@ -968,15 +1034,8 @@ static int wl1271_op_add_interface(struct ieee80211_hw *hw,
                if (ret < 0)
                        goto irq_disable;
 
-               wl->state = WL1271_STATE_ON;
-               wl1271_info("firmware booted (%s)", wl->chip.fw_ver);
-
-               /* update hw/fw version info in wiphy struct */
-               wiphy->hw_version = wl->chip.id;
-               strncpy(wiphy->fw_version, wl->chip.fw_ver,
-                       sizeof(wiphy->fw_version));
-
-               goto out;
+               booted = true;
+               break;
 
 irq_disable:
                wl1271_disable_interrupts(wl);
@@ -994,8 +1053,31 @@ power_off:
                wl1271_power_off(wl);
        }
 
-       wl1271_error("firmware boot failed despite %d retries",
-                    WL1271_BOOT_RETRIES);
+       if (!booted) {
+               wl1271_error("firmware boot failed despite %d retries",
+                            WL1271_BOOT_RETRIES);
+               goto out;
+       }
+
+       wl->vif = vif;
+       wl->state = WL1271_STATE_ON;
+       wl1271_info("firmware booted (%s)", wl->chip.fw_ver);
+
+       /* update hw/fw version info in wiphy struct */
+       wiphy->hw_version = wl->chip.id;
+       strncpy(wiphy->fw_version, wl->chip.fw_ver,
+               sizeof(wiphy->fw_version));
+
+       /*
+        * Now we know if 11a is supported (info from the NVS), so disable
+        * 11a channels if not supported
+        */
+       if (!wl->enable_11a)
+               wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0;
+
+       wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
+                    wl->enable_11a ? "" : "not ");
+
 out:
        mutex_unlock(&wl->mutex);
 
@@ -1025,6 +1107,7 @@ static void __wl1271_op_remove_interface(struct wl1271 *wl)
                wl->scan.state = WL1271_SCAN_STATE_IDLE;
                kfree(wl->scan.scanned_ch);
                wl->scan.scanned_ch = NULL;
+               wl->scan.req = NULL;
                ieee80211_scan_completed(wl->hw, true);
        }
 
@@ -1088,10 +1171,16 @@ static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
        struct wl1271 *wl = hw->priv;
 
        mutex_lock(&wl->mutex);
-       WARN_ON(wl->vif != vif);
-       __wl1271_op_remove_interface(wl);
-       mutex_unlock(&wl->mutex);
+       /*
+        * wl->vif can be null here if someone shuts down the interface
+        * just when hardware recovery has been started.
+        */
+       if (wl->vif) {
+               WARN_ON(wl->vif != vif);
+               __wl1271_op_remove_interface(wl);
+       }
 
+       mutex_unlock(&wl->mutex);
        cancel_work_sync(&wl->recovery_work);
 }
 
@@ -1312,8 +1401,10 @@ static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
 
        mutex_lock(&wl->mutex);
 
-       if (unlikely(wl->state == WL1271_STATE_OFF))
+       if (unlikely(wl->state == WL1271_STATE_OFF)) {
+               ret = -EAGAIN;
                goto out;
+       }
 
        ret = wl1271_ps_elp_wakeup(wl, false);
        if (ret < 0)
@@ -1536,6 +1627,11 @@ static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 
        mutex_lock(&wl->mutex);
 
+       if (unlikely(wl->state == WL1271_STATE_OFF)) {
+               ret = -EAGAIN;
+               goto out_unlock;
+       }
+
        ret = wl1271_ps_elp_wakeup(wl, false);
        if (ret < 0)
                goto out_unlock;
@@ -1645,6 +1741,16 @@ static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
 
        mutex_lock(&wl->mutex);
 
+       if (wl->state == WL1271_STATE_OFF) {
+               /*
+                * We cannot return -EBUSY here because cfg80211 will expect
+                * a call to ieee80211_scan_completed if we do - in this case
+                * there won't be any call.
+                */
+               ret = -EAGAIN;
+               goto out;
+       }
+
        ret = wl1271_ps_elp_wakeup(wl, false);
        if (ret < 0)
                goto out;
@@ -1659,6 +1765,34 @@ out:
        return ret;
 }
 
+static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
+{
+       struct wl1271 *wl = hw->priv;
+       int ret = 0;
+
+       mutex_lock(&wl->mutex);
+
+       if (unlikely(wl->state == WL1271_STATE_OFF)) {
+               ret = -EAGAIN;
+               goto out;
+       }
+
+       ret = wl1271_ps_elp_wakeup(wl, false);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_acx_frag_threshold(wl, (u16)value);
+       if (ret < 0)
+               wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret);
+
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
 static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
 {
        struct wl1271 *wl = hw->priv;
@@ -1666,8 +1800,10 @@ static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
 
        mutex_lock(&wl->mutex);
 
-       if (unlikely(wl->state == WL1271_STATE_OFF))
+       if (unlikely(wl->state == WL1271_STATE_OFF)) {
+               ret = -EAGAIN;
                goto out;
+       }
 
        ret = wl1271_ps_elp_wakeup(wl, false);
        if (ret < 0)
@@ -1685,21 +1821,21 @@ out:
        return ret;
 }
 
-static void wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *beacon)
+static void wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *skb,
+                           int offset)
 {
-       u8 *ptr = beacon->data +
-               offsetof(struct ieee80211_mgmt, u.beacon.variable);
+       u8 *ptr = skb->data + offset;
 
        /* find the location of the ssid in the beacon */
-       while (ptr < beacon->data + beacon->len) {
+       while (ptr < skb->data + skb->len) {
                if (ptr[0] == WLAN_EID_SSID) {
                        wl->ssid_len = ptr[1];
                        memcpy(wl->ssid, ptr+2, wl->ssid_len);
                        return;
                }
-               ptr += ptr[1];
+               ptr += (ptr[1] + 2);
        }
-       wl1271_error("ad-hoc beacon template has no SSID!\n");
+       wl1271_error("No SSID in IEs!\n");
 }
 
 static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
@@ -1709,6 +1845,7 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
 {
        enum wl1271_cmd_ps_mode mode;
        struct wl1271 *wl = hw->priv;
+       struct ieee80211_sta *sta = ieee80211_find_sta(vif, bss_conf->bssid);
        bool do_join = false;
        bool set_assoc = false;
        int ret;
@@ -1717,6 +1854,9 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
 
        mutex_lock(&wl->mutex);
 
+       if (unlikely(wl->state == WL1271_STATE_OFF))
+               goto out;
+
        ret = wl1271_ps_elp_wakeup(wl, false);
        if (ret < 0)
                goto out;
@@ -1738,8 +1878,11 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
 
                if (beacon) {
                        struct ieee80211_hdr *hdr;
+                       int ieoffset = offsetof(struct ieee80211_mgmt,
+                                               u.beacon.variable);
+
+                       wl1271_ssid_set(wl, beacon, ieoffset);
 
-                       wl1271_ssid_set(wl, beacon);
                        ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON,
                                                      beacon->data,
                                                      beacon->len, 0,
@@ -1819,6 +1962,7 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
        if (changed & BSS_CHANGED_ASSOC) {
                if (bss_conf->assoc) {
                        u32 rates;
+                       int ieoffset;
                        wl->aid = bss_conf->aid;
                        set_assoc = true;
 
@@ -1847,13 +1991,13 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
                                goto out_sleep;
 
                        /*
-                        * The SSID is intentionally set to NULL here - the
-                        * firmware will set the probe request with a
-                        * broadcast SSID regardless of what we set in the
-                        * template.
+                        * Get a template for hardware connection maintenance
                         */
-                       ret = wl1271_cmd_build_probe_req(wl, NULL, 0,
-                                                        NULL, 0, wl->band);
+                       dev_kfree_skb(wl->probereq);
+                       wl->probereq = wl1271_cmd_build_ap_probe_req(wl, NULL);
+                       ieoffset = offsetof(struct ieee80211_mgmt,
+                                           u.probe_req.variable);
+                       wl1271_ssid_set(wl, wl->probereq, ieoffset);
 
                        /* enable the connection monitoring feature */
                        ret = wl1271_acx_conn_monit_params(wl, true);
@@ -1876,6 +2020,10 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
                        clear_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags);
                        wl->aid = 0;
 
+                       /* free probe-request template */
+                       dev_kfree_skb(wl->probereq);
+                       wl->probereq = NULL;
+
                        /* re-enable dynamic ps - just in case */
                        ieee80211_enable_dyn_ps(wl->vif);
 
@@ -1891,9 +2039,12 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
 
                        /* Disable the keep-alive feature */
                        ret = wl1271_acx_keep_alive_mode(wl, false);
-
                        if (ret < 0)
                                goto out_sleep;
+
+                       /* restore the bssid filter and go to dummy bssid */
+                       wl1271_unjoin(wl);
+                       wl1271_dummy_join(wl);
                }
 
        }
@@ -1927,14 +2078,61 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
                }
        }
 
+       /*
+        * Takes care of: New association with HT enable,
+        *                HT information change in beacon.
+        */
+       if (sta &&
+           (changed & BSS_CHANGED_HT) &&
+           (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
+               ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true);
+               if (ret < 0) {
+                       wl1271_warning("Set ht cap true failed %d", ret);
+                       goto out_sleep;
+               }
+                       ret = wl1271_acx_set_ht_information(wl,
+                               bss_conf->ht_operation_mode);
+               if (ret < 0) {
+                       wl1271_warning("Set ht information failed %d", ret);
+                       goto out_sleep;
+               }
+       }
+       /*
+        * Takes care of: New association without HT,
+        *                Disassociation.
+        */
+       else if (sta && (changed & BSS_CHANGED_ASSOC)) {
+               ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, false);
+               if (ret < 0) {
+                       wl1271_warning("Set ht cap false failed %d", ret);
+                       goto out_sleep;
+               }
+       }
+
        if (changed & BSS_CHANGED_ARP_FILTER) {
                __be32 addr = bss_conf->arp_addr_list[0];
                WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS);
 
-               if (bss_conf->arp_addr_cnt == 1 && bss_conf->arp_filter_enabled)
-                       ret = wl1271_acx_arp_ip_filter(wl, true, addr);
-               else
-                       ret = wl1271_acx_arp_ip_filter(wl, false, addr);
+               if (bss_conf->arp_addr_cnt == 1 &&
+                   bss_conf->arp_filter_enabled) {
+                       /*
+                        * The template should have been configured only upon
+                        * association. however, it seems that the correct ip
+                        * isn't being set (when sending), so we have to
+                        * reconfigure the template upon every ip change.
+                        */
+                       ret = wl1271_cmd_build_arp_rsp(wl, addr);
+                       if (ret < 0) {
+                               wl1271_warning("build arp rsp failed: %d", ret);
+                               goto out_sleep;
+                       }
+
+                       ret = wl1271_acx_arp_ip_filter(wl,
+                               (ACX_ARP_FILTER_ARP_FILTERING |
+                                ACX_ARP_FILTER_AUTO_ARP),
+                               addr);
+               } else
+                       ret = wl1271_acx_arp_ip_filter(wl, 0, addr);
 
                if (ret < 0)
                        goto out_sleep;
@@ -1966,6 +2164,11 @@ static int wl1271_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
 
        wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
 
+       if (unlikely(wl->state == WL1271_STATE_OFF)) {
+               ret = -EAGAIN;
+               goto out;
+       }
+
        ret = wl1271_ps_elp_wakeup(wl, false);
        if (ret < 0)
                goto out;
@@ -2009,6 +2212,9 @@ static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw)
 
        mutex_lock(&wl->mutex);
 
+       if (unlikely(wl->state == WL1271_STATE_OFF))
+               goto out;
+
        ret = wl1271_ps_elp_wakeup(wl, false);
        if (ret < 0)
                goto out;
@@ -2030,14 +2236,14 @@ static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
 {
        struct wl1271 *wl = hw->priv;
        struct ieee80211_conf *conf = &hw->conf;
+
        if (idx != 0)
                return -ENOENT;
+
        survey->channel = conf->channel;
        survey->filled = SURVEY_INFO_NOISE_DBM;
        survey->noise = wl->noise;
+
        return 0;
 }
 
@@ -2084,37 +2290,34 @@ static struct ieee80211_rate wl1271_rates[] = {
          .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
 };
 
-/*
- * Can't be const, mac80211 writes to this. The order of the channels here
- * is designed to improve scanning.
- */
+/* can't be const, mac80211 writes to this */
 static struct ieee80211_channel wl1271_channels[] = {
        { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
-       { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
-       { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
-       { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
-       { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
-       { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
-       { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
-       { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
-       { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
-       { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
        { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
+       { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
+       { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
+       { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
        { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
+       { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
+       { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
+       { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
        { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
+       { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
+       { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
+       { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
 };
 
 /* mapping to indexes for wl1271_rates */
 static const u8 wl1271_rate_to_idx_2ghz[] = {
        /* MCS rates are used only with 11n */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS7 */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS6 */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS5 */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS4 */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS3 */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS2 */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS1 */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS0 */
+       7,                            /* CONF_HW_RXTX_RATE_MCS7 */
+       6,                            /* CONF_HW_RXTX_RATE_MCS6 */
+       5,                            /* CONF_HW_RXTX_RATE_MCS5 */
+       4,                            /* CONF_HW_RXTX_RATE_MCS4 */
+       3,                            /* CONF_HW_RXTX_RATE_MCS3 */
+       2,                            /* CONF_HW_RXTX_RATE_MCS2 */
+       1,                            /* CONF_HW_RXTX_RATE_MCS1 */
+       0,                            /* CONF_HW_RXTX_RATE_MCS0 */
 
        11,                            /* CONF_HW_RXTX_RATE_54   */
        10,                            /* CONF_HW_RXTX_RATE_48   */
@@ -2134,12 +2337,34 @@ static const u8 wl1271_rate_to_idx_2ghz[] = {
        0                              /* CONF_HW_RXTX_RATE_1    */
 };
 
+/* 11n STA capabilities */
+#define HW_RX_HIGHEST_RATE     72
+
+#ifdef CONFIG_WL12XX_HT
+#define WL12XX_HT_CAP { \
+       .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20, \
+       .ht_supported = true, \
+       .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
+       .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
+       .mcs = { \
+               .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
+               .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \
+               .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
+               }, \
+}
+#else
+#define WL12XX_HT_CAP { \
+       .ht_supported = false, \
+}
+#endif
+
 /* can't be const, mac80211 writes to this */
 static struct ieee80211_supported_band wl1271_band_2ghz = {
        .channels = wl1271_channels,
        .n_channels = ARRAY_SIZE(wl1271_channels),
        .bitrates = wl1271_rates,
        .n_bitrates = ARRAY_SIZE(wl1271_rates),
+       .ht_cap = WL12XX_HT_CAP,
 };
 
 /* 5 GHz data rates for WL1273 */
@@ -2170,66 +2395,55 @@ static struct ieee80211_rate wl1271_rates_5ghz[] = {
          .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
 };
 
-/*
- * 5 GHz band channels for WL1273 - can't be const, mac80211 writes to this.
- * The order of the channels here is designed to improve scanning.
- */
+/* 5 GHz band channels for WL1273 */
 static struct ieee80211_channel wl1271_channels_5ghz[] = {
-       { .hw_value = 183, .center_freq = 4915},
-       { .hw_value = 188, .center_freq = 4940},
+       { .hw_value = 7, .center_freq = 5035},
        { .hw_value = 8, .center_freq = 5040},
-       { .hw_value = 34, .center_freq = 5170},
-       { .hw_value = 44, .center_freq = 5220},
-       { .hw_value = 60, .center_freq = 5300},
-       { .hw_value = 112, .center_freq = 5560},
-       { .hw_value = 132, .center_freq = 5660},
-       { .hw_value = 157, .center_freq = 5785},
-       { .hw_value = 184, .center_freq = 4920},
-       { .hw_value = 189, .center_freq = 4945},
        { .hw_value = 9, .center_freq = 5045},
-       { .hw_value = 36, .center_freq = 5180},
-       { .hw_value = 46, .center_freq = 5230},
-       { .hw_value = 64, .center_freq = 5320},
-       { .hw_value = 116, .center_freq = 5580},
-       { .hw_value = 136, .center_freq = 5680},
-       { .hw_value = 192, .center_freq = 4960},
        { .hw_value = 11, .center_freq = 5055},
-       { .hw_value = 38, .center_freq = 5190},
-       { .hw_value = 48, .center_freq = 5240},
-       { .hw_value = 100, .center_freq = 5500},
-       { .hw_value = 120, .center_freq = 5600},
-       { .hw_value = 140, .center_freq = 5700},
-       { .hw_value = 185, .center_freq = 4925},
-       { .hw_value = 196, .center_freq = 4980},
        { .hw_value = 12, .center_freq = 5060},
-       { .hw_value = 40, .center_freq = 5200},
-       { .hw_value = 52, .center_freq = 5260},
-       { .hw_value = 104, .center_freq = 5520},
-       { .hw_value = 124, .center_freq = 5620},
-       { .hw_value = 149, .center_freq = 5745},
-       { .hw_value = 161, .center_freq = 5805},
-       { .hw_value = 187, .center_freq = 4935},
-       { .hw_value = 7, .center_freq = 5035},
        { .hw_value = 16, .center_freq = 5080},
+       { .hw_value = 34, .center_freq = 5170},
+       { .hw_value = 36, .center_freq = 5180},
+       { .hw_value = 38, .center_freq = 5190},
+       { .hw_value = 40, .center_freq = 5200},
        { .hw_value = 42, .center_freq = 5210},
+       { .hw_value = 44, .center_freq = 5220},
+       { .hw_value = 46, .center_freq = 5230},
+       { .hw_value = 48, .center_freq = 5240},
+       { .hw_value = 52, .center_freq = 5260},
        { .hw_value = 56, .center_freq = 5280},
+       { .hw_value = 60, .center_freq = 5300},
+       { .hw_value = 64, .center_freq = 5320},
+       { .hw_value = 100, .center_freq = 5500},
+       { .hw_value = 104, .center_freq = 5520},
        { .hw_value = 108, .center_freq = 5540},
+       { .hw_value = 112, .center_freq = 5560},
+       { .hw_value = 116, .center_freq = 5580},
+       { .hw_value = 120, .center_freq = 5600},
+       { .hw_value = 124, .center_freq = 5620},
        { .hw_value = 128, .center_freq = 5640},
+       { .hw_value = 132, .center_freq = 5660},
+       { .hw_value = 136, .center_freq = 5680},
+       { .hw_value = 140, .center_freq = 5700},
+       { .hw_value = 149, .center_freq = 5745},
        { .hw_value = 153, .center_freq = 5765},
+       { .hw_value = 157, .center_freq = 5785},
+       { .hw_value = 161, .center_freq = 5805},
        { .hw_value = 165, .center_freq = 5825},
 };
 
 /* mapping to indexes for wl1271_rates_5ghz */
 static const u8 wl1271_rate_to_idx_5ghz[] = {
        /* MCS rates are used only with 11n */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS7 */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS6 */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS5 */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS4 */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS3 */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS2 */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS1 */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS0 */
+       7,                            /* CONF_HW_RXTX_RATE_MCS7 */
+       6,                            /* CONF_HW_RXTX_RATE_MCS6 */
+       5,                            /* CONF_HW_RXTX_RATE_MCS5 */
+       4,                            /* CONF_HW_RXTX_RATE_MCS4 */
+       3,                            /* CONF_HW_RXTX_RATE_MCS3 */
+       2,                            /* CONF_HW_RXTX_RATE_MCS2 */
+       1,                            /* CONF_HW_RXTX_RATE_MCS1 */
+       0,                            /* CONF_HW_RXTX_RATE_MCS0 */
 
        7,                             /* CONF_HW_RXTX_RATE_54   */
        6,                             /* CONF_HW_RXTX_RATE_48   */
@@ -2254,6 +2468,7 @@ static struct ieee80211_supported_band wl1271_band_5ghz = {
        .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
        .bitrates = wl1271_rates_5ghz,
        .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
+       .ht_cap = WL12XX_HT_CAP,
 };
 
 static const u8 *wl1271_band_rate_to_idx[] = {
@@ -2273,6 +2488,7 @@ static const struct ieee80211_ops wl1271_ops = {
        .set_key = wl1271_op_set_key,
        .hw_scan = wl1271_op_hw_scan,
        .bss_info_changed = wl1271_op_bss_info_changed,
+       .set_frag_threshold = wl1271_op_set_frag_threshold,
        .set_rts_threshold = wl1271_op_set_rts_threshold,
        .conf_tx = wl1271_op_conf_tx,
        .get_tsf = wl1271_op_get_tsf,
@@ -2281,18 +2497,18 @@ static const struct ieee80211_ops wl1271_ops = {
 };
 
 
-u8 wl1271_rate_to_idx(struct wl1271 *wl, int rate)
+u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band)
 {
        u8 idx;
 
-       BUG_ON(wl->band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *));
+       BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *));
 
        if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) {
                wl1271_error("Illegal RX rate from HW: %d", rate);
                return 0;
        }
 
-       idx = wl1271_band_rate_to_idx[wl->band][rate];
+       idx = wl1271_band_rate_to_idx[band][rate];
        if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) {
                wl1271_error("Unsupported RX rate from HW: %d", rate);
                return 0;
@@ -2401,6 +2617,8 @@ int wl1271_register_hw(struct wl1271 *wl)
 
        wl->mac80211_registered = true;
 
+       wl1271_debugfs_init(wl);
+
        register_netdevice_notifier(&wl1271_dev_notifier);
 
        wl1271_notice("loaded");
@@ -2451,12 +2669,21 @@ int wl1271_init_ieee80211(struct wl1271 *wl)
        wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
                BIT(NL80211_IFTYPE_ADHOC);
        wl->hw->wiphy->max_scan_ssids = 1;
+       /*
+        * Maximum length of elements in scanning probe request templates
+        * should be the maximum length possible for a template, without
+        * the IEEE80211 header of the template
+        */
+       wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
+                       sizeof(struct ieee80211_header);
        wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1271_band_2ghz;
        wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wl1271_band_5ghz;
 
        wl->hw->queues = 4;
        wl->hw->max_rates = 1;
 
+       wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
+
        SET_IEEE80211_DEV(wl->hw, wl1271_wl_to_dev(wl));
 
        return 0;
@@ -2495,7 +2722,8 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
        wl->hw = hw;
        wl->plat_dev = plat_dev;
 
-       skb_queue_head_init(&wl->tx_queue);
+       for (i = 0; i < NUM_TX_QUEUES; i++)
+               skb_queue_head_init(&wl->tx_queue[i]);
 
        INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
        INIT_DELAYED_WORK(&wl->pspoll_work, wl1271_pspoll_work);
@@ -2521,6 +2749,7 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
        wl->sg_enabled = true;
        wl->hw_pg_ver = -1;
 
+       memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
        for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
                wl->tx_frames[i] = NULL;
 
@@ -2532,8 +2761,6 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
        /* Apply default driver configuration. */
        wl1271_conf_init(wl);
 
-       wl1271_debugfs_init(wl);
-
        order = get_order(WL1271_AGGR_BUFFER_SIZE);
        wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
        if (!wl->aggr_buf) {
@@ -2610,6 +2837,11 @@ int wl1271_free_hw(struct wl1271 *wl)
 }
 EXPORT_SYMBOL_GPL(wl1271_free_hw);
 
+u32 wl12xx_debug_level;
+EXPORT_SYMBOL_GPL(wl12xx_debug_level);
+module_param_named(debug_level, wl12xx_debug_level, uint, DEBUG_NONE);
+MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
+
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
 MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");