Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[safe/jmp/linux-2.6] / drivers / net / wireless / ath5k / base.c
index d6599d2..bd2c580 100644 (file)
  *
  */
 
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/delay.h>
+#include <linux/hardirq.h>
 #include <linux/if.h>
+#include <linux/io.h>
 #include <linux/netdevice.h>
 #include <linux/cache.h>
 #include <linux/pci.h>
 #include "reg.h"
 #include "debug.h"
 
-/* unaligned little endian access */
-#define LE_READ_2(_p) (le16_to_cpu(get_unaligned((__le16 *)(_p))))
-#define LE_READ_4(_p) (le32_to_cpu(get_unaligned((__le32 *)(_p))))
-
-enum {
-       ATH_LED_TX,
-       ATH_LED_RX,
-};
-
 static int ath5k_calinterval = 10; /* Calibrate PHY every 10 secs (TODO: Fixme) */
+static int modparam_nohwcrypt;
+module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444);
+MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
 
 
 /******************\
@@ -80,7 +75,7 @@ MODULE_AUTHOR("Nick Kossifidis");
 MODULE_DESCRIPTION("Support for 5xxx series of Atheros 802.11 wireless LAN cards.");
 MODULE_SUPPORTED_DEVICE("Atheros 5xxx WLAN cards");
 MODULE_LICENSE("Dual BSD/GPL");
-MODULE_VERSION("0.1.1 (EXPERIMENTAL)");
+MODULE_VERSION("0.6.0 (EXPERIMENTAL)");
 
 
 /* Known PCI ids */
@@ -101,43 +96,94 @@ static struct pci_device_id ath5k_pci_id_table[] __devinitdata = {
        { PCI_VDEVICE(ATHEROS, 0x0019), .driver_data = AR5K_AR5212 }, /* 5212 combatible */
        { PCI_VDEVICE(ATHEROS, 0x001a), .driver_data = AR5K_AR5212 }, /* 2413 Griffin-lite */
        { PCI_VDEVICE(ATHEROS, 0x001b), .driver_data = AR5K_AR5212 }, /* 5413 Eagle */
-       { PCI_VDEVICE(ATHEROS, 0x001c), .driver_data = AR5K_AR5212 }, /* 5424 Condor (PCI-E)*/
-       { PCI_VDEVICE(ATHEROS, 0x0023), .driver_data = AR5K_AR5212 }, /* 5416 */
-       { PCI_VDEVICE(ATHEROS, 0x0024), .driver_data = AR5K_AR5212 }, /* 5418 */
+       { PCI_VDEVICE(ATHEROS, 0x001c), .driver_data = AR5K_AR5212 }, /* PCI-E cards */
+       { PCI_VDEVICE(ATHEROS, 0x001d), .driver_data = AR5K_AR5212 }, /* 2417 Nala */
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, ath5k_pci_id_table);
 
 /* Known SREVs */
 static struct ath5k_srev_name srev_names[] = {
-       { "5210",       AR5K_VERSION_VER,       AR5K_SREV_VER_AR5210 },
-       { "5311",       AR5K_VERSION_VER,       AR5K_SREV_VER_AR5311 },
-       { "5311A",      AR5K_VERSION_VER,       AR5K_SREV_VER_AR5311A },
-       { "5311B",      AR5K_VERSION_VER,       AR5K_SREV_VER_AR5311B },
-       { "5211",       AR5K_VERSION_VER,       AR5K_SREV_VER_AR5211 },
-       { "5212",       AR5K_VERSION_VER,       AR5K_SREV_VER_AR5212 },
-       { "5213",       AR5K_VERSION_VER,       AR5K_SREV_VER_AR5213 },
-       { "5213A",      AR5K_VERSION_VER,       AR5K_SREV_VER_AR5213A },
-       { "2424",       AR5K_VERSION_VER,       AR5K_SREV_VER_AR2424 },
-       { "5424",       AR5K_VERSION_VER,       AR5K_SREV_VER_AR5424 },
-       { "5413",       AR5K_VERSION_VER,       AR5K_SREV_VER_AR5413 },
-       { "5414",       AR5K_VERSION_VER,       AR5K_SREV_VER_AR5414 },
-       { "5416",       AR5K_VERSION_VER,       AR5K_SREV_VER_AR5416 },
-       { "5418",       AR5K_VERSION_VER,       AR5K_SREV_VER_AR5418 },
-       { "xxxxx",      AR5K_VERSION_VER,       AR5K_SREV_UNKNOWN },
+       { "5210",       AR5K_VERSION_MAC,       AR5K_SREV_AR5210 },
+       { "5311",       AR5K_VERSION_MAC,       AR5K_SREV_AR5311 },
+       { "5311A",      AR5K_VERSION_MAC,       AR5K_SREV_AR5311A },
+       { "5311B",      AR5K_VERSION_MAC,       AR5K_SREV_AR5311B },
+       { "5211",       AR5K_VERSION_MAC,       AR5K_SREV_AR5211 },
+       { "5212",       AR5K_VERSION_MAC,       AR5K_SREV_AR5212 },
+       { "5213",       AR5K_VERSION_MAC,       AR5K_SREV_AR5213 },
+       { "5213A",      AR5K_VERSION_MAC,       AR5K_SREV_AR5213A },
+       { "2413",       AR5K_VERSION_MAC,       AR5K_SREV_AR2413 },
+       { "2414",       AR5K_VERSION_MAC,       AR5K_SREV_AR2414 },
+       { "5424",       AR5K_VERSION_MAC,       AR5K_SREV_AR5424 },
+       { "5413",       AR5K_VERSION_MAC,       AR5K_SREV_AR5413 },
+       { "5414",       AR5K_VERSION_MAC,       AR5K_SREV_AR5414 },
+       { "2415",       AR5K_VERSION_MAC,       AR5K_SREV_AR2415 },
+       { "5416",       AR5K_VERSION_MAC,       AR5K_SREV_AR5416 },
+       { "5418",       AR5K_VERSION_MAC,       AR5K_SREV_AR5418 },
+       { "2425",       AR5K_VERSION_MAC,       AR5K_SREV_AR2425 },
+       { "2417",       AR5K_VERSION_MAC,       AR5K_SREV_AR2417 },
+       { "xxxxx",      AR5K_VERSION_MAC,       AR5K_SREV_UNKNOWN },
        { "5110",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5110 },
        { "5111",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5111 },
+       { "5111A",      AR5K_VERSION_RAD,       AR5K_SREV_RAD_5111A },
        { "2111",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_2111 },
        { "5112",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5112 },
        { "5112A",      AR5K_VERSION_RAD,       AR5K_SREV_RAD_5112A },
+       { "5112B",      AR5K_VERSION_RAD,       AR5K_SREV_RAD_5112B },
        { "2112",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_2112 },
        { "2112A",      AR5K_VERSION_RAD,       AR5K_SREV_RAD_2112A },
-       { "SChip",      AR5K_VERSION_RAD,       AR5K_SREV_RAD_SC1 },
-       { "SChip",      AR5K_VERSION_RAD,       AR5K_SREV_RAD_SC2 },
+       { "2112B",      AR5K_VERSION_RAD,       AR5K_SREV_RAD_2112B },
+       { "2413",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_2413 },
+       { "5413",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5413 },
+       { "2316",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_2316 },
+       { "2317",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_2317 },
+       { "5424",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5424 },
        { "5133",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5133 },
        { "xxxxx",      AR5K_VERSION_RAD,       AR5K_SREV_UNKNOWN },
 };
 
+static struct ieee80211_rate ath5k_rates[] = {
+       { .bitrate = 10,
+         .hw_value = ATH5K_RATE_CODE_1M, },
+       { .bitrate = 20,
+         .hw_value = ATH5K_RATE_CODE_2M,
+         .hw_value_short = ATH5K_RATE_CODE_2M | AR5K_SET_SHORT_PREAMBLE,
+         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+       { .bitrate = 55,
+         .hw_value = ATH5K_RATE_CODE_5_5M,
+         .hw_value_short = ATH5K_RATE_CODE_5_5M | AR5K_SET_SHORT_PREAMBLE,
+         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+       { .bitrate = 110,
+         .hw_value = ATH5K_RATE_CODE_11M,
+         .hw_value_short = ATH5K_RATE_CODE_11M | AR5K_SET_SHORT_PREAMBLE,
+         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+       { .bitrate = 60,
+         .hw_value = ATH5K_RATE_CODE_6M,
+         .flags = 0 },
+       { .bitrate = 90,
+         .hw_value = ATH5K_RATE_CODE_9M,
+         .flags = 0 },
+       { .bitrate = 120,
+         .hw_value = ATH5K_RATE_CODE_12M,
+         .flags = 0 },
+       { .bitrate = 180,
+         .hw_value = ATH5K_RATE_CODE_18M,
+         .flags = 0 },
+       { .bitrate = 240,
+         .hw_value = ATH5K_RATE_CODE_24M,
+         .flags = 0 },
+       { .bitrate = 360,
+         .hw_value = ATH5K_RATE_CODE_36M,
+         .flags = 0 },
+       { .bitrate = 480,
+         .hw_value = ATH5K_RATE_CODE_48M,
+         .flags = 0 },
+       { .bitrate = 540,
+         .hw_value = ATH5K_RATE_CODE_54M,
+         .flags = 0 },
+       /* XR missing */
+};
+
 /*
  * Prototypes - PCI stack related functions
  */
@@ -153,8 +199,8 @@ static int          ath5k_pci_resume(struct pci_dev *pdev);
 #define ath5k_pci_resume NULL
 #endif /* CONFIG_PM */
 
-static struct pci_driver ath5k_pci_drv_id = {
-       .name           = "ath5k_pci",
+static struct pci_driver ath5k_pci_driver = {
+       .name           = KBUILD_MODNAME,
        .id_table       = ath5k_pci_id_table,
        .probe          = ath5k_pci_probe,
        .remove         = __devexit_p(ath5k_pci_remove),
@@ -167,17 +213,16 @@ static struct pci_driver ath5k_pci_drv_id = {
 /*
  * Prototypes - MAC 802.11 stack related functions
  */
-static int ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
-               struct ieee80211_tx_control *ctl);
-static int ath5k_reset(struct ieee80211_hw *hw);
+static int ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
+static int ath5k_reset(struct ath5k_softc *sc, bool stop, bool change_channel);
+static int ath5k_reset_wake(struct ath5k_softc *sc);
 static int ath5k_start(struct ieee80211_hw *hw);
 static void ath5k_stop(struct ieee80211_hw *hw);
 static int ath5k_add_interface(struct ieee80211_hw *hw,
                struct ieee80211_if_init_conf *conf);
 static void ath5k_remove_interface(struct ieee80211_hw *hw,
                struct ieee80211_if_init_conf *conf);
-static int ath5k_config(struct ieee80211_hw *hw,
-               struct ieee80211_conf *conf);
+static int ath5k_config(struct ieee80211_hw *hw, u32 changed);
 static int ath5k_config_interface(struct ieee80211_hw *hw,
                struct ieee80211_vif *vif,
                struct ieee80211_if_conf *conf);
@@ -187,17 +232,21 @@ static void ath5k_configure_filter(struct ieee80211_hw *hw,
                int mc_count, struct dev_mc_list *mclist);
 static int ath5k_set_key(struct ieee80211_hw *hw,
                enum set_key_cmd cmd,
-               const u8 *local_addr, const u8 *addr,
+               struct ieee80211_vif *vif, struct ieee80211_sta *sta,
                struct ieee80211_key_conf *key);
 static int ath5k_get_stats(struct ieee80211_hw *hw,
                struct ieee80211_low_level_stats *stats);
 static int ath5k_get_tx_stats(struct ieee80211_hw *hw,
                struct ieee80211_tx_queue_stats *stats);
 static u64 ath5k_get_tsf(struct ieee80211_hw *hw);
+static void ath5k_set_tsf(struct ieee80211_hw *hw, u64 tsf);
 static void ath5k_reset_tsf(struct ieee80211_hw *hw);
-static int ath5k_beacon_update(struct ieee80211_hw *hw,
-               struct sk_buff *skb,
-               struct ieee80211_tx_control *ctl);
+static int ath5k_beacon_update(struct ath5k_softc *sc,
+               struct sk_buff *skb);
+static void ath5k_bss_info_changed(struct ieee80211_hw *hw,
+               struct ieee80211_vif *vif,
+               struct ieee80211_bss_conf *bss_conf,
+               u32 changes);
 
 static struct ieee80211_ops ath5k_hw_ops = {
        .tx             = ath5k_tx,
@@ -213,8 +262,9 @@ static struct ieee80211_ops ath5k_hw_ops = {
        .conf_tx        = NULL,
        .get_tx_stats   = ath5k_get_tx_stats,
        .get_tsf        = ath5k_get_tsf,
+       .set_tsf        = ath5k_set_tsf,
        .reset_tsf      = ath5k_reset_tsf,
-       .beacon_update  = ath5k_beacon_update,
+       .bss_info_changed = ath5k_bss_info_changed,
 };
 
 /*
@@ -227,19 +277,17 @@ static void       ath5k_detach(struct pci_dev *pdev,
                        struct ieee80211_hw *hw);
 /* Channel/mode setup */
 static inline short ath5k_ieee2mhz(short chan);
-static unsigned int ath5k_copy_rates(struct ieee80211_rate *rates,
-                               const struct ath5k_rate_table *rt,
-                               unsigned int max);
 static unsigned int ath5k_copy_channels(struct ath5k_hw *ah,
                                struct ieee80211_channel *channels,
                                unsigned int mode,
                                unsigned int max);
-static int     ath5k_getchannels(struct ieee80211_hw *hw);
+static int     ath5k_setup_bands(struct ieee80211_hw *hw);
 static int     ath5k_chan_set(struct ath5k_softc *sc,
                                struct ieee80211_channel *chan);
 static void    ath5k_setcurmode(struct ath5k_softc *sc,
                                unsigned int mode);
 static void    ath5k_mode_setup(struct ath5k_softc *sc);
+
 /* Descriptor setup */
 static int     ath5k_desc_alloc(struct ath5k_softc *sc,
                                struct pci_dev *pdev);
@@ -249,9 +297,7 @@ static void ath5k_desc_free(struct ath5k_softc *sc,
 static int     ath5k_rxbuf_setup(struct ath5k_softc *sc,
                                struct ath5k_buf *bf);
 static int     ath5k_txbuf_setup(struct ath5k_softc *sc,
-                               struct ath5k_buf *bf,
-                               struct ieee80211_tx_control *ctl);
-
+                               struct ath5k_buf *bf);
 static inline void ath5k_txbuf_free(struct ath5k_softc *sc,
                                struct ath5k_buf *bf)
 {
@@ -260,7 +306,7 @@ static inline void ath5k_txbuf_free(struct ath5k_softc *sc,
                return;
        pci_unmap_single(sc->pdev, bf->skbaddr, bf->skb->len,
                        PCI_DMA_TODEVICE);
-       dev_kfree_skb(bf->skb);
+       dev_kfree_skb_any(bf->skb);
        bf->skb = NULL;
 }
 
@@ -278,7 +324,8 @@ static int  ath5k_rx_start(struct ath5k_softc *sc);
 static void    ath5k_rx_stop(struct ath5k_softc *sc);
 static unsigned int ath5k_rx_decrypted(struct ath5k_softc *sc,
                                        struct ath5k_desc *ds,
-                                       struct sk_buff *skb);
+                                       struct sk_buff *skb,
+                                       struct ath5k_rx_status *rs);
 static void    ath5k_tasklet_rx(unsigned long data);
 /* Tx handling */
 static void    ath5k_tx_processq(struct ath5k_softc *sc,
@@ -286,8 +333,7 @@ static void         ath5k_tx_processq(struct ath5k_softc *sc,
 static void    ath5k_tasklet_tx(unsigned long data);
 /* Beacon handling */
 static int     ath5k_beacon_setup(struct ath5k_softc *sc,
-                               struct ath5k_buf *bf,
-                               struct ieee80211_tx_control *ctl);
+                                       struct ath5k_buf *bf);
 static void    ath5k_beacon_send(struct ath5k_softc *sc);
 static void    ath5k_beacon_config(struct ath5k_softc *sc);
 static void    ath5k_beacon_update_timers(struct ath5k_softc *sc, u64 bc_tsf);
@@ -311,13 +357,10 @@ static void       ath5k_tasklet_reset(unsigned long data);
 
 static void    ath5k_calibrate(unsigned long data);
 /* LED functions */
-static void    ath5k_led_off(unsigned long data);
-static void    ath5k_led_blink(struct ath5k_softc *sc,
-                               unsigned int on,
-                               unsigned int off);
-static void    ath5k_led_event(struct ath5k_softc *sc,
-                               int event);
-
+static int     ath5k_init_leds(struct ath5k_softc *sc);
+static void    ath5k_led_enable(struct ath5k_softc *sc);
+static void    ath5k_led_off(struct ath5k_softc *sc);
+static void    ath5k_unregister_leds(struct ath5k_softc *sc);
 
 /*
  * Module init/exit functions
@@ -329,7 +372,7 @@ init_ath5k_pci(void)
 
        ath5k_debug_init();
 
-       ret = pci_register_driver(&ath5k_pci_drv_id);
+       ret = pci_register_driver(&ath5k_pci_driver);
        if (ret) {
                printk(KERN_ERR "ath5k_pci: can't register pci driver\n");
                return ret;
@@ -341,7 +384,7 @@ init_ath5k_pci(void)
 static void __exit
 exit_ath5k_pci(void)
 {
-       pci_unregister_driver(&ath5k_pci_drv_id);
+       pci_unregister_driver(&ath5k_pci_driver);
 
        ath5k_debug_finish();
 }
@@ -363,7 +406,11 @@ ath5k_chip_name(enum ath5k_srev_type type, u_int16_t val)
        for (i = 0; i < ARRAY_SIZE(srev_names); i++) {
                if (srev_names[i].sr_type != type)
                        continue;
-               if ((val & 0xff) < srev_names[i + 1].sr_val) {
+
+               if ((val & 0xf0) == srev_names[i].sr_val)
+                       name = srev_names[i].sr_name;
+
+               if ((val & 0xff) == srev_names[i].sr_val) {
                        name = srev_names[i].sr_name;
                        break;
                }
@@ -455,13 +502,17 @@ ath5k_pci_probe(struct pci_dev *pdev,
 
        /* Initialize driver private data */
        SET_IEEE80211_DEV(hw, &pdev->dev);
-       hw->flags = IEEE80211_HW_RX_INCLUDES_FCS;
+       hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
+                   IEEE80211_HW_SIGNAL_DBM |
+                   IEEE80211_HW_NOISE_DBM;
+
+       hw->wiphy->interface_modes =
+               BIT(NL80211_IFTYPE_STATION) |
+               BIT(NL80211_IFTYPE_ADHOC) |
+               BIT(NL80211_IFTYPE_MESH_POINT);
+
        hw->extra_tx_headroom = 2;
        hw->channel_change_time = 5000;
-       /* these names are misleading */
-       hw->max_rssi = -110; /* signal in dBm */
-       hw->max_noise = -110; /* noise in dBm */
-       hw->max_signal = 100; /* we will provide a percentage based on rssi */
        sc = hw->priv;
        sc->hw = hw;
        sc->pdev = pdev;
@@ -476,17 +527,15 @@ ath5k_pci_probe(struct pci_dev *pdev,
 
        sc->iobase = mem; /* So we can unmap it on detach */
        sc->cachelsz = csz * sizeof(u32); /* convert to bytes */
-       sc->opmode = IEEE80211_IF_TYPE_STA;
+       sc->opmode = NL80211_IFTYPE_STATION;
        mutex_init(&sc->lock);
        spin_lock_init(&sc->rxbuflock);
        spin_lock_init(&sc->txbuflock);
+       spin_lock_init(&sc->block);
 
        /* Set private data */
        pci_set_drvdata(pdev, hw);
 
-       /* Enable msi for devices that support it */
-       pci_enable_msi(pdev);
-
        /* Setup interrupt handler */
        ret = request_irq(pdev->irq, ath5k_intr, IRQF_SHARED, "ath", sc);
        if (ret) {
@@ -501,45 +550,62 @@ ath5k_pci_probe(struct pci_dev *pdev,
                goto err_irq;
        }
 
+       /* set up multi-rate retry capabilities */
+       if (sc->ah->ah_version == AR5K_AR5212) {
+               hw->max_rates = 4;
+               hw->max_rate_tries = 11;
+       }
+
        /* Finish private driver data initialization */
        ret = ath5k_attach(pdev, hw);
        if (ret)
                goto err_ah;
 
        ATH5K_INFO(sc, "Atheros AR%s chip found (MAC: 0x%x, PHY: 0x%x)\n",
-                       ath5k_chip_name(AR5K_VERSION_VER,sc->ah->ah_mac_srev),
+                       ath5k_chip_name(AR5K_VERSION_MAC, sc->ah->ah_mac_srev),
                                        sc->ah->ah_mac_srev,
                                        sc->ah->ah_phy_revision);
 
-       if(!sc->ah->ah_single_chip){
+       if (!sc->ah->ah_single_chip) {
                /* Single chip radio (!RF5111) */
-               if(sc->ah->ah_radio_5ghz_revision && !sc->ah->ah_radio_2ghz_revision) {
+               if (sc->ah->ah_radio_5ghz_revision &&
+                       !sc->ah->ah_radio_2ghz_revision) {
                        /* No 5GHz support -> report 2GHz radio */
-                       if(!test_bit(MODE_IEEE80211A, sc->ah->ah_capabilities.cap_mode)){
+                       if (!test_bit(AR5K_MODE_11A,
+                               sc->ah->ah_capabilities.cap_mode)) {
                                ATH5K_INFO(sc, "RF%s 2GHz radio found (0x%x)\n",
-                                       ath5k_chip_name(AR5K_VERSION_RAD,sc->ah->ah_radio_5ghz_revision),
-                                                       sc->ah->ah_radio_5ghz_revision);
-                       /* No 2GHz support (5110 and some 5Ghz only cards) -> report 5Ghz radio */
-                       } else if(!test_bit(MODE_IEEE80211B, sc->ah->ah_capabilities.cap_mode)){
+                                       ath5k_chip_name(AR5K_VERSION_RAD,
+                                               sc->ah->ah_radio_5ghz_revision),
+                                               sc->ah->ah_radio_5ghz_revision);
+                       /* No 2GHz support (5110 and some
+                        * 5Ghz only cards) -> report 5Ghz radio */
+                       } else if (!test_bit(AR5K_MODE_11B,
+                               sc->ah->ah_capabilities.cap_mode)) {
                                ATH5K_INFO(sc, "RF%s 5GHz radio found (0x%x)\n",
-                                       ath5k_chip_name(AR5K_VERSION_RAD,sc->ah->ah_radio_5ghz_revision),
-                                                       sc->ah->ah_radio_5ghz_revision);
+                                       ath5k_chip_name(AR5K_VERSION_RAD,
+                                               sc->ah->ah_radio_5ghz_revision),
+                                               sc->ah->ah_radio_5ghz_revision);
                        /* Multiband radio */
                        } else {
                                ATH5K_INFO(sc, "RF%s multiband radio found"
                                        " (0x%x)\n",
-                                       ath5k_chip_name(AR5K_VERSION_RAD,sc->ah->ah_radio_5ghz_revision),
-                                                       sc->ah->ah_radio_5ghz_revision);
+                                       ath5k_chip_name(AR5K_VERSION_RAD,
+                                               sc->ah->ah_radio_5ghz_revision),
+                                               sc->ah->ah_radio_5ghz_revision);
                        }
                }
-               /* Multi chip radio (RF5111 - RF2111) -> report both 2GHz/5GHz radios */
-               else if(sc->ah->ah_radio_5ghz_revision && sc->ah->ah_radio_2ghz_revision){
+               /* Multi chip radio (RF5111 - RF2111) ->
+                * report both 2GHz/5GHz radios */
+               else if (sc->ah->ah_radio_5ghz_revision &&
+                               sc->ah->ah_radio_2ghz_revision){
                        ATH5K_INFO(sc, "RF%s 5GHz radio found (0x%x)\n",
-                               ath5k_chip_name(AR5K_VERSION_RAD,sc->ah->ah_radio_5ghz_revision),
-                                               sc->ah->ah_radio_5ghz_revision);
+                               ath5k_chip_name(AR5K_VERSION_RAD,
+                                       sc->ah->ah_radio_5ghz_revision),
+                                       sc->ah->ah_radio_5ghz_revision);
                        ATH5K_INFO(sc, "RF%s 2GHz radio found (0x%x)\n",
-                               ath5k_chip_name(AR5K_VERSION_RAD,sc->ah->ah_radio_2ghz_revision),
-                                               sc->ah->ah_radio_2ghz_revision);
+                               ath5k_chip_name(AR5K_VERSION_RAD,
+                                       sc->ah->ah_radio_2ghz_revision),
+                                       sc->ah->ah_radio_2ghz_revision);
                }
        }
 
@@ -553,7 +619,6 @@ err_ah:
 err_irq:
        free_irq(pdev->irq, sc);
 err_free:
-       pci_disable_msi(pdev);
        ieee80211_free_hw(hw);
 err_map:
        pci_iounmap(pdev, mem);
@@ -575,7 +640,6 @@ ath5k_pci_remove(struct pci_dev *pdev)
        ath5k_detach(pdev, hw);
        ath5k_hw_detach(sc->ah);
        free_irq(pdev->irq, sc);
-       pci_disable_msi(pdev);
        pci_iounmap(pdev, sc->iobase);
        pci_release_region(pdev, 0);
        pci_disable_device(pdev);
@@ -589,10 +653,9 @@ ath5k_pci_suspend(struct pci_dev *pdev, pm_message_t state)
        struct ieee80211_hw *hw = pci_get_drvdata(pdev);
        struct ath5k_softc *sc = hw->priv;
 
-       if (test_bit(ATH_STAT_LEDSOFT, sc->status))
-               ath5k_hw_set_gpio(sc->ah, sc->led_pin, 1);
+       ath5k_led_off(sc);
 
-       ath5k_stop_hw(sc);
+       free_irq(pdev->irq, sc);
        pci_save_state(pdev);
        pci_disable_device(pdev);
        pci_set_power_state(pdev, PCI_D3hot);
@@ -605,18 +668,14 @@ ath5k_pci_resume(struct pci_dev *pdev)
 {
        struct ieee80211_hw *hw = pci_get_drvdata(pdev);
        struct ath5k_softc *sc = hw->priv;
-       struct ath5k_hw *ah = sc->ah;
-       int i, err;
+       int err;
 
-       err = pci_set_power_state(pdev, PCI_D0);
-       if (err)
-               return err;
+       pci_restore_state(pdev);
 
        err = pci_enable_device(pdev);
        if (err)
                return err;
 
-       pci_restore_state(pdev);
        /*
         * Suspend/Resume resets the PCI configuration space, so we have to
         * re-disable the RETRY_TIMEOUT register (0x41) to keep
@@ -624,28 +683,22 @@ ath5k_pci_resume(struct pci_dev *pdev)
         */
        pci_write_config_byte(pdev, 0x41, 0);
 
-       ath5k_init(sc);
-       if (test_bit(ATH_STAT_LEDSOFT, sc->status)) {
-               ath5k_hw_set_gpio_output(ah, sc->led_pin);
-               ath5k_hw_set_gpio(ah, sc->led_pin, 0);
+       err = request_irq(pdev->irq, ath5k_intr, IRQF_SHARED, "ath", sc);
+       if (err) {
+               ATH5K_ERR(sc, "request_irq failed\n");
+               goto err_no_irq;
        }
 
-       /*
-        * Reset the key cache since some parts do not
-        * reset the contents on initial power up or resume.
-        *
-        * FIXME: This may need to be revisited when mac80211 becomes
-        *        aware of suspend/resume.
-        */
-       for (i = 0; i < AR5K_KEYTABLE_SIZE; i++)
-               ath5k_hw_reset_key(ah, i);
-
+       ath5k_led_enable(sc);
        return 0;
+
+err_no_irq:
+       pci_disable_device(pdev);
+       return err;
 }
 #endif /* CONFIG_PM */
 
 
-
 /***********************\
 * Driver Initialization *
 \***********************/
@@ -655,8 +708,7 @@ ath5k_attach(struct pci_dev *pdev, struct ieee80211_hw *hw)
 {
        struct ath5k_softc *sc = hw->priv;
        struct ath5k_hw *ah = sc->ah;
-       u8 mac[ETH_ALEN];
-       unsigned int i;
+       u8 mac[ETH_ALEN] = {};
        int ret;
 
        ATH5K_DBG(sc, ATH5K_DEBUG_ANY, "devid 0x%x\n", pdev->device);
@@ -668,33 +720,29 @@ ath5k_attach(struct pci_dev *pdev, struct ieee80211_hw *hw)
         * return false w/o doing anything.  MAC's that do
         * support it will return true w/o doing anything.
         */
-       if (ah->ah_setup_xtx_desc(ah, NULL, 0, 0, 0, 0, 0, 0))
+       ret = ah->ah_setup_mrr_tx_desc(ah, NULL, 0, 0, 0, 0, 0, 0);
+       if (ret < 0)
+               goto err;
+       if (ret > 0)
                __set_bit(ATH_STAT_MRRETRY, sc->status);
 
        /*
-        * Reset the key cache since some parts do not
-        * reset the contents on initial power up.
-        */
-       for (i = 0; i < AR5K_KEYTABLE_SIZE; i++)
-               ath5k_hw_reset_key(ah, i);
-
-       /*
         * Collect the channel list.  The 802.11 layer
         * is resposible for filtering this list based
         * on settings like the phy mode and regulatory
         * domain restrictions.
         */
-       ret = ath5k_getchannels(hw);
+       ret = ath5k_setup_bands(hw);
        if (ret) {
                ATH5K_ERR(sc, "can't get channels\n");
                goto err;
        }
 
        /* NB: setup here so ath5k_rate_update is happy */
-       if (test_bit(MODE_IEEE80211A, ah->ah_modes))
-               ath5k_setcurmode(sc, MODE_IEEE80211A);
+       if (test_bit(AR5K_MODE_11A, ah->ah_modes))
+               ath5k_setcurmode(sc, AR5K_MODE_11A);
        else
-               ath5k_setcurmode(sc, MODE_IEEE80211B);
+               ath5k_setcurmode(sc, AR5K_MODE_11B);
 
        /*
         * Allocate tx+rx descriptors and populate the lists.
@@ -729,29 +777,14 @@ ath5k_attach(struct pci_dev *pdev, struct ieee80211_hw *hw)
        tasklet_init(&sc->txtq, ath5k_tasklet_tx, (unsigned long)sc);
        tasklet_init(&sc->restq, ath5k_tasklet_reset, (unsigned long)sc);
        setup_timer(&sc->calib_tim, ath5k_calibrate, (unsigned long)sc);
-       setup_timer(&sc->led_tim, ath5k_led_off, (unsigned long)sc);
 
-       sc->led_on = 0; /* low true */
-       /*
-        * Auto-enable soft led processing for IBM cards and for
-        * 5211 minipci cards.
-        */
-       if (pdev->device == PCI_DEVICE_ID_ATHEROS_AR5212_IBM ||
-                       pdev->device == PCI_DEVICE_ID_ATHEROS_AR5211) {
-               __set_bit(ATH_STAT_LEDSOFT, sc->status);
-               sc->led_pin = 0;
-       }
-       /* Enable softled on PIN1 on HP Compaq nc6xx, nc4000 & nx5000 laptops */
-       if (pdev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ) {
-               __set_bit(ATH_STAT_LEDSOFT, sc->status);
-               sc->led_pin = 0;
-       }
-       if (test_bit(ATH_STAT_LEDSOFT, sc->status)) {
-               ath5k_hw_set_gpio_output(ah, sc->led_pin);
-               ath5k_hw_set_gpio(ah, sc->led_pin, !sc->led_on);
+       ret = ath5k_eeprom_read_mac(ah, mac);
+       if (ret) {
+               ATH5K_ERR(sc, "unable to read address from EEPROM: 0x%04x\n",
+                       sc->pdev->device);
+               goto err_queues;
        }
 
-       ath5k_hw_get_lladdr(ah, mac);
        SET_IEEE80211_PERM_ADDR(hw, mac);
        /* All MAC address bits matter for ACKs */
        memset(sc->bssidmask, 0xff, ETH_ALEN);
@@ -763,6 +796,8 @@ ath5k_attach(struct pci_dev *pdev, struct ieee80211_hw *hw)
                goto err_queues;
        }
 
+       ath5k_init_leds(sc);
+
        return 0;
 err_queues:
        ath5k_txq_release(sc);
@@ -796,6 +831,7 @@ ath5k_detach(struct pci_dev *pdev, struct ieee80211_hw *hw)
        ath5k_desc_free(sc, pdev);
        ath5k_txq_release(sc);
        ath5k_hw_release_tx_queue(sc->ah, sc->bhalq);
+       ath5k_unregister_leds(sc);
 
        /*
         * NB: can't reclaim these until after ieee80211_ifdetach
@@ -824,72 +860,27 @@ ath5k_ieee2mhz(short chan)
 }
 
 static unsigned int
-ath5k_copy_rates(struct ieee80211_rate *rates,
-               const struct ath5k_rate_table *rt,
-               unsigned int max)
-{
-       unsigned int i, count;
-
-       if (rt == NULL)
-               return 0;
-
-       for (i = 0, count = 0; i < rt->rate_count && max > 0; i++) {
-               if (!rt->rates[i].valid)
-                       continue;
-               rates->rate = rt->rates[i].rate_kbps / 100;
-               rates->val = rt->rates[i].rate_code;
-               rates->flags = rt->rates[i].modulation;
-               rates++;
-               count++;
-               max--;
-       }
-
-       return count;
-}
-
-static unsigned int
 ath5k_copy_channels(struct ath5k_hw *ah,
                struct ieee80211_channel *channels,
                unsigned int mode,
                unsigned int max)
 {
-       static const struct { unsigned int mode, mask, chan; } map[] = {
-               [MODE_IEEE80211A] = { CHANNEL_OFDM, CHANNEL_OFDM | CHANNEL_TURBO, CHANNEL_A },
-               [MODE_ATHEROS_TURBO] = { CHANNEL_OFDM|CHANNEL_TURBO, CHANNEL_OFDM | CHANNEL_TURBO, CHANNEL_T },
-               [MODE_IEEE80211B] = { CHANNEL_CCK, CHANNEL_CCK, CHANNEL_B },
-               [MODE_IEEE80211G] = { CHANNEL_OFDM, CHANNEL_OFDM, CHANNEL_G },
-               [MODE_ATHEROS_TURBOG] = { CHANNEL_OFDM | CHANNEL_TURBO, CHANNEL_OFDM | CHANNEL_TURBO, CHANNEL_TG },
-       };
-       static const struct ath5k_regchannel chans_2ghz[] =
-               IEEE80211_CHANNELS_2GHZ;
-       static const struct ath5k_regchannel chans_5ghz[] =
-               IEEE80211_CHANNELS_5GHZ;
-       const struct ath5k_regchannel *chans;
-       enum ath5k_regdom dmn;
-       unsigned int i, count, size, chfreq, all, f, ch;
+       unsigned int i, count, size, chfreq, freq, ch;
 
        if (!test_bit(mode, ah->ah_modes))
                return 0;
 
-       all = ah->ah_regdomain == DMN_DEFAULT || CHAN_DEBUG == 1;
-
        switch (mode) {
-       case MODE_IEEE80211A:
-       case MODE_ATHEROS_TURBO:
+       case AR5K_MODE_11A:
+       case AR5K_MODE_11A_TURBO:
                /* 1..220, but 2GHz frequencies are filtered by check_channel */
-               size = all ? 220 : ARRAY_SIZE(chans_5ghz);
-               chans = chans_5ghz;
-               dmn = ath5k_regdom2flag(ah->ah_regdomain,
-                               IEEE80211_CHANNELS_5GHZ_MIN);
+               size = 220 ;
                chfreq = CHANNEL_5GHZ;
                break;
-       case MODE_IEEE80211B:
-       case MODE_IEEE80211G:
-       case MODE_ATHEROS_TURBOG:
-               size = all ? 26 : ARRAY_SIZE(chans_2ghz);
-               chans = chans_2ghz;
-               dmn = ath5k_regdom2flag(ah->ah_regdomain,
-                               IEEE80211_CHANNELS_2GHZ_MIN);
+       case AR5K_MODE_11B:
+       case AR5K_MODE_11G:
+       case AR5K_MODE_11G_TURBO:
+               size = 26;
                chfreq = CHANNEL_2GHZ;
                break;
        default:
@@ -898,25 +889,31 @@ ath5k_copy_channels(struct ath5k_hw *ah,
        }
 
        for (i = 0, count = 0; i < size && max > 0; i++) {
-               ch = all ? i + 1 : chans[i].chan;
-               f = ath5k_ieee2mhz(ch);
-               /* Check if channel is supported by the chipset */
-               if (!ath5k_channel_ok(ah, f, chfreq))
-                       continue;
+               ch = i + 1 ;
+               freq = ath5k_ieee2mhz(ch);
 
-               /* Match regulation domain */
-               if (!all && !(IEEE80211_DMN(chans[i].domain) &
-                                                       IEEE80211_DMN(dmn)))
+               /* Check if channel is supported by the chipset */
+               if (!ath5k_channel_ok(ah, freq, chfreq))
                        continue;
 
-               if (!all && (chans[i].mode & map[mode].mask) != map[mode].mode)
-                       continue;
+               /* Write channel info and increment counter */
+               channels[count].center_freq = freq;
+               channels[count].band = (chfreq == CHANNEL_2GHZ) ?
+                       IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
+               switch (mode) {
+               case AR5K_MODE_11A:
+               case AR5K_MODE_11G:
+                       channels[count].hw_value = chfreq | CHANNEL_OFDM;
+                       break;
+               case AR5K_MODE_11A_TURBO:
+               case AR5K_MODE_11G_TURBO:
+                       channels[count].hw_value = chfreq |
+                               CHANNEL_OFDM | CHANNEL_TURBO;
+                       break;
+               case AR5K_MODE_11B:
+                       channels[count].hw_value = CHANNEL_B;
+               }
 
-               /* Write channel and increment counter */
-               channels->chan = ch;
-               channels->freq = f;
-               channels->val = map[mode].chan;
-               channels++;
                count++;
                max--;
        }
@@ -924,95 +921,101 @@ ath5k_copy_channels(struct ath5k_hw *ah,
        return count;
 }
 
-/* Only tries to register modes our EEPROM says it can support */
-#define REGISTER_MODE(m) do { \
-       ret = ath5k_register_mode(hw, m); \
-       if (ret) \
-               return ret; \
-} while (0) \
-
-static inline int
-ath5k_register_mode(struct ieee80211_hw *hw, u8 m)
+static void
+ath5k_setup_rate_idx(struct ath5k_softc *sc, struct ieee80211_supported_band *b)
 {
-       struct ath5k_softc *sc = hw->priv;
-       struct ieee80211_hw_mode *modes = sc->modes;
-       unsigned int i;
-       int ret;
+       u8 i;
 
-       if (!test_bit(m, sc->ah->ah_capabilities.cap_mode))
-               return 0;
+       for (i = 0; i < AR5K_MAX_RATES; i++)
+               sc->rate_idx[b->band][i] = -1;
 
-       for (i = 0; i < NUM_DRIVER_MODES; i++) {
-               if (modes[i].mode != m || !modes[i].num_channels)
-                       continue;
-               ret = ieee80211_register_hwmode(hw, &modes[i]);
-               if (ret) {
-                       ATH5K_ERR(sc, "can't register hwmode %u\n", m);
-                       return ret;
-               }
-               return 0;
+       for (i = 0; i < b->n_bitrates; i++) {
+               sc->rate_idx[b->band][b->bitrates[i].hw_value] = i;
+               if (b->bitrates[i].hw_value_short)
+                       sc->rate_idx[b->band][b->bitrates[i].hw_value_short] = i;
        }
-       BUG();
 }
 
 static int
-ath5k_getchannels(struct ieee80211_hw *hw)
+ath5k_setup_bands(struct ieee80211_hw *hw)
 {
        struct ath5k_softc *sc = hw->priv;
        struct ath5k_hw *ah = sc->ah;
-       struct ieee80211_hw_mode *modes = sc->modes;
-       unsigned int i, max_r, max_c;
-       int ret;
-
-       BUILD_BUG_ON(ARRAY_SIZE(sc->modes) < 3);
-
-       /* The order here does not matter */
-       modes[0].mode = MODE_IEEE80211G;
-       modes[1].mode = MODE_IEEE80211B;
-       modes[2].mode = MODE_IEEE80211A;
+       struct ieee80211_supported_band *sband;
+       int max_c, count_c = 0;
+       int i;
 
-       max_r = ARRAY_SIZE(sc->rates);
+       BUILD_BUG_ON(ARRAY_SIZE(sc->sbands) < IEEE80211_NUM_BANDS);
        max_c = ARRAY_SIZE(sc->channels);
 
-       for (i = 0; i < NUM_DRIVER_MODES; i++) {
-               struct ieee80211_hw_mode *mode = &modes[i];
-               const struct ath5k_rate_table *hw_rates;
-
-               if (i == 0) {
-                       modes[0].rates  = sc->rates;
-                       modes->channels = sc->channels;
-               } else {
-                       struct ieee80211_hw_mode *prev_mode = &modes[i-1];
-                       int prev_num_r  = prev_mode->num_rates;
-                       int prev_num_c  = prev_mode->num_channels;
-                       mode->rates     = &prev_mode->rates[prev_num_r];
-                       mode->channels  = &prev_mode->channels[prev_num_c];
+       /* 2GHz band */
+       sband = &sc->sbands[IEEE80211_BAND_2GHZ];
+       sband->band = IEEE80211_BAND_2GHZ;
+       sband->bitrates = &sc->rates[IEEE80211_BAND_2GHZ][0];
+
+       if (test_bit(AR5K_MODE_11G, sc->ah->ah_capabilities.cap_mode)) {
+               /* G mode */
+               memcpy(sband->bitrates, &ath5k_rates[0],
+                      sizeof(struct ieee80211_rate) * 12);
+               sband->n_bitrates = 12;
+
+               sband->channels = sc->channels;
+               sband->n_channels = ath5k_copy_channels(ah, sband->channels,
+                                       AR5K_MODE_11G, max_c);
+
+               hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
+               count_c = sband->n_channels;
+               max_c -= count_c;
+       } else if (test_bit(AR5K_MODE_11B, sc->ah->ah_capabilities.cap_mode)) {
+               /* B mode */
+               memcpy(sband->bitrates, &ath5k_rates[0],
+                      sizeof(struct ieee80211_rate) * 4);
+               sband->n_bitrates = 4;
+
+               /* 5211 only supports B rates and uses 4bit rate codes
+                * (e.g normally we have 0x1B for 1M, but on 5211 we have 0x0B)
+                * fix them up here:
+                */
+               if (ah->ah_version == AR5K_AR5211) {
+                       for (i = 0; i < 4; i++) {
+                               sband->bitrates[i].hw_value =
+                                       sband->bitrates[i].hw_value & 0xF;
+                               sband->bitrates[i].hw_value_short =
+                                       sband->bitrates[i].hw_value_short & 0xF;
+                       }
                }
 
-               hw_rates = ath5k_hw_get_rate_table(ah, mode->mode);
-               mode->num_rates    = ath5k_copy_rates(mode->rates, hw_rates,
-                       max_r);
-               mode->num_channels = ath5k_copy_channels(ah, mode->channels,
-                       mode->mode, max_c);
-               max_r -= mode->num_rates;
-               max_c -= mode->num_channels;
+               sband->channels = sc->channels;
+               sband->n_channels = ath5k_copy_channels(ah, sband->channels,
+                                       AR5K_MODE_11B, max_c);
+
+               hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
+               count_c = sband->n_channels;
+               max_c -= count_c;
        }
+       ath5k_setup_rate_idx(sc, sband);
 
-       /* We try to register all modes this driver supports. We don't bother
-        * with MODE_IEEE80211B for AR5212 as MODE_IEEE80211G already accounts
-        * for that as per mac80211. Then, REGISTER_MODE() will will actually
-        * check the eeprom reading for more reliable capability information.
-        * Order matters here as per mac80211's latest preference. This will
-        * all hopefullly soon go away. */
+       /* 5GHz band, A mode */
+       if (test_bit(AR5K_MODE_11A, sc->ah->ah_capabilities.cap_mode)) {
+               sband = &sc->sbands[IEEE80211_BAND_5GHZ];
+               sband->band = IEEE80211_BAND_5GHZ;
+               sband->bitrates = &sc->rates[IEEE80211_BAND_5GHZ][0];
 
-       REGISTER_MODE(MODE_IEEE80211G);
-       if (ah->ah_version != AR5K_AR5212)
-               REGISTER_MODE(MODE_IEEE80211B);
-       REGISTER_MODE(MODE_IEEE80211A);
+               memcpy(sband->bitrates, &ath5k_rates[4],
+                      sizeof(struct ieee80211_rate) * 8);
+               sband->n_bitrates = 8;
 
-       ath5k_debug_dump_modes(sc, modes);
+               sband->channels = &sc->channels[count_c];
+               sband->n_channels = ath5k_copy_channels(ah, sband->channels,
+                                       AR5K_MODE_11A, max_c);
 
-       return ret;
+               hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
+       }
+       ath5k_setup_rate_idx(sc, sband);
+
+       ath5k_debug_dump_bands(sc);
+
+       return 0;
 }
 
 /*
@@ -1020,59 +1023,28 @@ ath5k_getchannels(struct ieee80211_hw *hw)
  * it's done by reseting the chip.  To accomplish this we must
  * first cleanup any pending DMA, then restart stuff after a la
  * ath5k_init.
+ *
+ * Called with sc->lock.
  */
 static int
 ath5k_chan_set(struct ath5k_softc *sc, struct ieee80211_channel *chan)
 {
-       struct ath5k_hw *ah = sc->ah;
-       int ret;
+       ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "(%u MHz) -> (%u MHz)\n",
+               sc->curchan->center_freq, chan->center_freq);
 
-       ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "%u (%u MHz) -> %u (%u MHz)\n",
-               sc->curchan->chan, sc->curchan->freq,
-               chan->chan, chan->freq);
+       if (chan->center_freq != sc->curchan->center_freq ||
+               chan->hw_value != sc->curchan->hw_value) {
+
+               sc->curchan = chan;
+               sc->curband = &sc->sbands[chan->band];
 
-       if (chan->freq != sc->curchan->freq || chan->val != sc->curchan->val) {
                /*
                 * To switch channels clear any pending DMA operations;
                 * wait long enough for the RX fifo to drain, reset the
                 * hardware at the new frequency, and then re-enable
                 * the relevant bits of the h/w.
                 */
-               ath5k_hw_set_intr(ah, 0);       /* disable interrupts */
-               ath5k_txq_cleanup(sc);          /* clear pending tx frames */
-               ath5k_rx_stop(sc);              /* turn off frame recv */
-               ret = ath5k_hw_reset(ah, sc->opmode, chan, true);
-               if (ret) {
-                       ATH5K_ERR(sc, "%s: unable to reset channel %u "
-                               "(%u Mhz)\n", __func__, chan->chan, chan->freq);
-                       return ret;
-               }
-               sc->curchan = chan;
-               ath5k_hw_set_txpower_limit(sc->ah, 0);
-
-               /*
-                * Re-enable rx framework.
-                */
-               ret = ath5k_rx_start(sc);
-               if (ret) {
-                       ATH5K_ERR(sc, "%s: unable to restart recv logic\n",
-                                       __func__);
-                       return ret;
-               }
-
-               /*
-                * Change channels and update the h/w rate map
-                * if we're switching; e.g. 11a to 11b/g.
-                *
-                * XXX needed?
-                */
-/*             ath5k_chan_change(sc, chan); */
-
-               ath5k_beacon_config(sc);
-               /*
-                * Re-enable interrupts.
-                */
-               ath5k_hw_set_intr(ah, sc->imask);
+               return ath5k_reset(sc, true, true);
        }
 
        return 0;
@@ -1081,64 +1053,13 @@ ath5k_chan_set(struct ath5k_softc *sc, struct ieee80211_channel *chan)
 static void
 ath5k_setcurmode(struct ath5k_softc *sc, unsigned int mode)
 {
-       if (unlikely(test_bit(ATH_STAT_LEDSOFT, sc->status))) {
-               /* from Atheros NDIS driver, w/ permission */
-               static const struct {
-                       u16 rate;       /* tx/rx 802.11 rate */
-                       u16 timeOn;     /* LED on time (ms) */
-                       u16 timeOff;    /* LED off time (ms) */
-               } blinkrates[] = {
-                       { 108,  40,  10 },
-                       {  96,  44,  11 },
-                       {  72,  50,  13 },
-                       {  48,  57,  14 },
-                       {  36,  67,  16 },
-                       {  24,  80,  20 },
-                       {  22, 100,  25 },
-                       {  18, 133,  34 },
-                       {  12, 160,  40 },
-                       {  10, 200,  50 },
-                       {   6, 240,  58 },
-                       {   4, 267,  66 },
-                       {   2, 400, 100 },
-                       {   0, 500, 130 }
-               };
-               const struct ath5k_rate_table *rt =
-                               ath5k_hw_get_rate_table(sc->ah, mode);
-               unsigned int i, j;
-
-               BUG_ON(rt == NULL);
-
-               memset(sc->hwmap, 0, sizeof(sc->hwmap));
-               for (i = 0; i < 32; i++) {
-                       u8 ix = rt->rate_code_to_index[i];
-                       if (ix == 0xff) {
-                               sc->hwmap[i].ledon = msecs_to_jiffies(500);
-                               sc->hwmap[i].ledoff = msecs_to_jiffies(130);
-                               continue;
-                       }
-                       sc->hwmap[i].txflags = IEEE80211_RADIOTAP_F_DATAPAD;
-                       if (SHPREAMBLE_FLAG(ix) || rt->rates[ix].modulation ==
-                                       IEEE80211_RATE_OFDM)
-                               sc->hwmap[i].txflags |=
-                                               IEEE80211_RADIOTAP_F_SHORTPRE;
-                       /* receive frames include FCS */
-                       sc->hwmap[i].rxflags = sc->hwmap[i].txflags |
-                                       IEEE80211_RADIOTAP_F_FCS;
-                       /* setup blink rate table to avoid per-packet lookup */
-                       for (j = 0; j < ARRAY_SIZE(blinkrates) - 1; j++)
-                               if (blinkrates[j].rate == /* XXX why 7f? */
-                                               (rt->rates[ix].dot11_rate&0x7f))
-                                       break;
-
-                       sc->hwmap[i].ledon = msecs_to_jiffies(blinkrates[j].
-                                       timeOn);
-                       sc->hwmap[i].ledoff = msecs_to_jiffies(blinkrates[j].
-                                       timeOff);
-               }
-       }
-
        sc->curmode = mode;
+
+       if (mode == AR5K_MODE_11A) {
+               sc->curband = &sc->sbands[IEEE80211_BAND_5GHZ];
+       } else {
+               sc->curband = &sc->sbands[IEEE80211_BAND_2GHZ];
+       }
 }
 
 static void
@@ -1161,13 +1082,53 @@ ath5k_mode_setup(struct ath5k_softc *sc)
        ATH5K_DBG(sc, ATH5K_DEBUG_MODE, "RX filter 0x%x\n", rfilt);
 }
 
-
-
+static inline int
+ath5k_hw_to_driver_rix(struct ath5k_softc *sc, int hw_rix)
+{
+       WARN_ON(hw_rix < 0 || hw_rix > AR5K_MAX_RATES);
+       return sc->rate_idx[sc->curband->band][hw_rix];
+}
 
 /***************\
 * Buffers setup *
 \***************/
 
+static
+struct sk_buff *ath5k_rx_skb_alloc(struct ath5k_softc *sc, dma_addr_t *skb_addr)
+{
+       struct sk_buff *skb;
+       unsigned int off;
+
+       /*
+        * Allocate buffer with headroom_needed space for the
+        * fake physical layer header at the start.
+        */
+       skb = dev_alloc_skb(sc->rxbufsize + sc->cachelsz - 1);
+
+       if (!skb) {
+               ATH5K_ERR(sc, "can't alloc skbuff of size %u\n",
+                               sc->rxbufsize + sc->cachelsz - 1);
+               return NULL;
+       }
+       /*
+        * Cache-line-align.  This is important (for the
+        * 5210 at least) as not doing so causes bogus data
+        * in rx'd frames.
+        */
+       off = ((unsigned long)skb->data) % sc->cachelsz;
+       if (off != 0)
+               skb_reserve(skb, sc->cachelsz - off);
+
+       *skb_addr = pci_map_single(sc->pdev,
+               skb->data, sc->rxbufsize, PCI_DMA_FROMDEVICE);
+       if (unlikely(pci_dma_mapping_error(sc->pdev, *skb_addr))) {
+               ATH5K_ERR(sc, "%s: DMA mapping failed\n", __func__);
+               dev_kfree_skb(skb);
+               return NULL;
+       }
+       return skb;
+}
+
 static int
 ath5k_rxbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
 {
@@ -1175,37 +1136,11 @@ ath5k_rxbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
        struct sk_buff *skb = bf->skb;
        struct ath5k_desc *ds;
 
-       if (likely(skb == NULL)) {
-               unsigned int off;
-
-               /*
-                * Allocate buffer with headroom_needed space for the
-                * fake physical layer header at the start.
-                */
-               skb = dev_alloc_skb(sc->rxbufsize + sc->cachelsz - 1);
-               if (unlikely(skb == NULL)) {
-                       ATH5K_ERR(sc, "can't alloc skbuff of size %u\n",
-                                       sc->rxbufsize + sc->cachelsz - 1);
+       if (!skb) {
+               skb = ath5k_rx_skb_alloc(sc, &bf->skbaddr);
+               if (!skb)
                        return -ENOMEM;
-               }
-               /*
-                * Cache-line-align.  This is important (for the
-                * 5210 at least) as not doing so causes bogus data
-                * in rx'd frames.
-                */
-               off = ((unsigned long)skb->data) % sc->cachelsz;
-               if (off != 0)
-                       skb_reserve(skb, sc->cachelsz - off);
-
                bf->skb = skb;
-               bf->skbaddr = pci_map_single(sc->pdev,
-                       skb->data, sc->rxbufsize, PCI_DMA_FROMDEVICE);
-               if (unlikely(pci_dma_mapping_error(bf->skbaddr))) {
-                       ATH5K_ERR(sc, "%s: DMA mapping failed\n", __func__);
-                       dev_kfree_skb(skb);
-                       bf->skb = NULL;
-                       return -ENOMEM;
-               }
        }
 
        /*
@@ -1226,7 +1161,7 @@ ath5k_rxbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
        ds = bf->desc;
        ds->ds_link = bf->daddr;        /* link to self */
        ds->ds_data = bf->skbaddr;
-       ath5k_hw_setup_rx_desc(ah, ds,
+       ah->ah_setup_rx_desc(ah, ds,
                skb_tailroom(skb),      /* buffer size */
                0);
 
@@ -1237,51 +1172,95 @@ ath5k_rxbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
 }
 
 static int
-ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf,
-               struct ieee80211_tx_control *ctl)
+ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
 {
        struct ath5k_hw *ah = sc->ah;
        struct ath5k_txq *txq = sc->txq;
        struct ath5k_desc *ds = bf->desc;
        struct sk_buff *skb = bf->skb;
+       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
        unsigned int pktlen, flags, keyidx = AR5K_TXKEYIX_INVALID;
-       int ret;
+       struct ieee80211_rate *rate;
+       unsigned int mrr_rate[3], mrr_tries[3];
+       int i, ret;
+       u16 hw_rate;
+       u16 cts_rate = 0;
+       u16 duration = 0;
+       u8 rc_flags;
 
        flags = AR5K_TXDESC_INTREQ | AR5K_TXDESC_CLRDMASK;
-       bf->ctl = *ctl;
+
        /* XXX endianness */
        bf->skbaddr = pci_map_single(sc->pdev, skb->data, skb->len,
                        PCI_DMA_TODEVICE);
 
-       if (ctl->flags & IEEE80211_TXCTL_NO_ACK)
+       rate = ieee80211_get_tx_rate(sc->hw, info);
+
+       if (info->flags & IEEE80211_TX_CTL_NO_ACK)
                flags |= AR5K_TXDESC_NOACK;
 
-       pktlen = skb->len + FCS_LEN;
+       rc_flags = info->control.rates[0].flags;
+       hw_rate = (rc_flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) ?
+               rate->hw_value_short : rate->hw_value;
+
+       pktlen = skb->len;
 
-       if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) {
-               keyidx = ctl->key_idx;
-               pktlen += ctl->icv_len;
+       if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
+               flags |= AR5K_TXDESC_RTSENA;
+               cts_rate = ieee80211_get_rts_cts_rate(sc->hw, info)->hw_value;
+               duration = le16_to_cpu(ieee80211_rts_duration(sc->hw,
+                       sc->vif, pktlen, info));
+       }
+       if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
+               flags |= AR5K_TXDESC_CTSENA;
+               cts_rate = ieee80211_get_rts_cts_rate(sc->hw, info)->hw_value;
+               duration = le16_to_cpu(ieee80211_ctstoself_duration(sc->hw,
+                       sc->vif, pktlen, info));
        }
 
+       if (info->control.hw_key) {
+               keyidx = info->control.hw_key->hw_key_idx;
+               pktlen += info->control.hw_key->icv_len;
+       }
        ret = ah->ah_setup_tx_desc(ah, ds, pktlen,
                ieee80211_get_hdrlen_from_skb(skb), AR5K_PKT_TYPE_NORMAL,
-               (ctl->power_level * 2), ctl->tx_rate, ctl->retry_limit, keyidx, 0, flags, 0, 0);
+               (sc->power_level * 2),
+               hw_rate,
+               info->control.rates[0].count, keyidx, 0, flags,
+               cts_rate, duration);
        if (ret)
                goto err_unmap;
 
+       memset(mrr_rate, 0, sizeof(mrr_rate));
+       memset(mrr_tries, 0, sizeof(mrr_tries));
+       for (i = 0; i < 3; i++) {
+               rate = ieee80211_get_alt_retry_rate(sc->hw, info, i);
+               if (!rate)
+                       break;
+
+               mrr_rate[i] = rate->hw_value;
+               mrr_tries[i] = info->control.rates[i + 1].count;
+       }
+
+       ah->ah_setup_mrr_tx_desc(ah, ds,
+               mrr_rate[0], mrr_tries[0],
+               mrr_rate[1], mrr_tries[1],
+               mrr_rate[2], mrr_tries[2]);
+
        ds->ds_link = 0;
        ds->ds_data = bf->skbaddr;
 
        spin_lock_bh(&txq->lock);
        list_add_tail(&bf->list, &txq->q);
-       sc->tx_stats.data[txq->qnum].len++;
+       sc->tx_stats[txq->qnum].len++;
        if (txq->link == NULL) /* is this first packet? */
-               ath5k_hw_put_tx_buf(ah, txq->qnum, bf->daddr);
+               ath5k_hw_set_txdp(ah, txq->qnum, bf->daddr);
        else /* no, so only link it */
                *txq->link = bf->daddr;
 
        txq->link = &ds->ds_link;
-       ath5k_hw_tx_start(ah, txq->qnum);
+       ath5k_hw_start_tx_dma(ah, txq->qnum);
+       mmiowb();
        spin_unlock_bh(&txq->lock);
 
        return 0;
@@ -1458,7 +1437,8 @@ ath5k_beaconq_config(struct ath5k_softc *sc)
        ret = ath5k_hw_get_tx_queueprops(ah, sc->bhalq, &qi);
        if (ret)
                return ret;
-       if (sc->opmode == IEEE80211_IF_TYPE_AP) {
+       if (sc->opmode == NL80211_IFTYPE_AP ||
+               sc->opmode == NL80211_IFTYPE_MESH_POINT) {
                /*
                 * Always burst out beacon and CAB traffic
                 * (aifs = cwmin = cwmax = 0)
@@ -1466,7 +1446,7 @@ ath5k_beaconq_config(struct ath5k_softc *sc)
                qi.tqi_aifs = 0;
                qi.tqi_cw_min = 0;
                qi.tqi_cw_max = 0;
-       } else if (sc->opmode == IEEE80211_IF_TYPE_IBSS) {
+       } else if (sc->opmode == NL80211_IFTYPE_ADHOC) {
                /*
                 * Adhoc mode; backoff between 0 and (2 * cw_min).
                 */
@@ -1479,7 +1459,7 @@ ath5k_beaconq_config(struct ath5k_softc *sc)
                "beacon queueprops tqi_aifs:%d tqi_cw_min:%d tqi_cw_max:%d\n",
                qi.tqi_aifs, qi.tqi_cw_min, qi.tqi_cw_max);
 
-       ret = ath5k_hw_setup_tx_queueprops(ah, sc->bhalq, &qi);
+       ret = ath5k_hw_set_tx_queueprops(ah, sc->bhalq, &qi);
        if (ret) {
                ATH5K_ERR(sc, "%s: unable to update parameters for beacon "
                        "hardware queue!\n", __func__);
@@ -1500,13 +1480,12 @@ ath5k_txq_drainq(struct ath5k_softc *sc, struct ath5k_txq *txq)
         */
        spin_lock_bh(&txq->lock);
        list_for_each_entry_safe(bf, bf0, &txq->q, list) {
-               ath5k_debug_printtxbuf(sc, bf, !sc->ah->ah_proc_tx_desc(sc->ah,
-                                       bf->desc));
+               ath5k_debug_printtxbuf(sc, bf);
 
                ath5k_txbuf_free(sc, bf);
 
                spin_lock_bh(&sc->txbuflock);
-               sc->tx_stats.data[txq->qnum].len--;
+               sc->tx_stats[txq->qnum].len--;
                list_move_tail(&bf->list, &sc->txbuf);
                sc->txbuf_len++;
                spin_unlock_bh(&sc->txbuflock);
@@ -1529,19 +1508,19 @@ ath5k_txq_cleanup(struct ath5k_softc *sc)
                /* don't touch the hardware if marked invalid */
                ath5k_hw_stop_tx_dma(ah, sc->bhalq);
                ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "beacon queue %x\n",
-                       ath5k_hw_get_tx_buf(ah, sc->bhalq));
+                       ath5k_hw_get_txdp(ah, sc->bhalq));
                for (i = 0; i < ARRAY_SIZE(sc->txqs); i++)
                        if (sc->txqs[i].setup) {
                                ath5k_hw_stop_tx_dma(ah, sc->txqs[i].qnum);
                                ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "txq [%u] %x, "
                                        "link %p\n",
                                        sc->txqs[i].qnum,
-                                       ath5k_hw_get_tx_buf(ah,
+                                       ath5k_hw_get_txdp(ah,
                                                        sc->txqs[i].qnum),
                                        sc->txqs[i].link);
                        }
        }
-       ieee80211_start_queues(sc->hw); /* XXX move to callers */
+       ieee80211_wake_queues(sc->hw); /* XXX move to callers */
 
        for (i = 0; i < ARRAY_SIZE(sc->txqs); i++)
                if (sc->txqs[i].setup)
@@ -1596,8 +1575,8 @@ ath5k_rx_start(struct ath5k_softc *sc)
        bf = list_first_entry(&sc->rxbuf, struct ath5k_buf, list);
        spin_unlock_bh(&sc->rxbuflock);
 
-       ath5k_hw_put_rx_buf(ah, bf->daddr);
-       ath5k_hw_start_rx(ah);          /* enable recv descriptors */
+       ath5k_hw_set_rxdp(ah, bf->daddr);
+       ath5k_hw_start_rx_dma(ah);      /* enable recv descriptors */
        ath5k_mode_setup(sc);           /* set filters, etc. */
        ath5k_hw_start_rx_pcu(ah);      /* re-enable PCU/DMA engine */
 
@@ -1614,10 +1593,9 @@ ath5k_rx_stop(struct ath5k_softc *sc)
 {
        struct ath5k_hw *ah = sc->ah;
 
-       ath5k_hw_stop_pcu_recv(ah);     /* disable PCU */
+       ath5k_hw_stop_rx_pcu(ah);       /* disable PCU */
        ath5k_hw_set_rx_filter(ah, 0);  /* clear recv filter */
        ath5k_hw_stop_rx_dma(ah);       /* disable DMA engine */
-       mdelay(3);                      /* 3ms is long enough for 1 frame */
 
        ath5k_debug_printrxbuffs(sc, ah);
 
@@ -1626,21 +1604,22 @@ ath5k_rx_stop(struct ath5k_softc *sc)
 
 static unsigned int
 ath5k_rx_decrypted(struct ath5k_softc *sc, struct ath5k_desc *ds,
-               struct sk_buff *skb)
+               struct sk_buff *skb, struct ath5k_rx_status *rs)
 {
        struct ieee80211_hdr *hdr = (void *)skb->data;
-       unsigned int keyix, hlen = ieee80211_get_hdrlen_from_skb(skb);
+       unsigned int keyix, hlen;
 
-       if (!(ds->ds_rxstat.rs_status & AR5K_RXERR_DECRYPT) &&
-                       ds->ds_rxstat.rs_keyix != AR5K_RXKEYIX_INVALID)
+       if (!(rs->rs_status & AR5K_RXERR_DECRYPT) &&
+                       rs->rs_keyix != AR5K_RXKEYIX_INVALID)
                return RX_FLAG_DECRYPTED;
 
        /* Apparently when a default key is used to decrypt the packet
           the hw does not set the index used to decrypt.  In such cases
           get the index from the packet. */
-       if ((le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_PROTECTED) &&
-                       !(ds->ds_rxstat.rs_status & AR5K_RXERR_DECRYPT) &&
-                       skb->len >= hlen + 4) {
+       hlen = ieee80211_hdrlen(hdr->frame_control);
+       if (ieee80211_has_protected(hdr->frame_control) &&
+           !(rs->rs_status & AR5K_RXERR_DECRYPT) &&
+           skb->len >= hlen + 4) {
                keyix = skb->data[hlen + 3] >> 6;
 
                if (test_bit(keyix, sc->keymap))
@@ -1652,28 +1631,59 @@ ath5k_rx_decrypted(struct ath5k_softc *sc, struct ath5k_desc *ds,
 
 
 static void
-ath5k_check_ibss_hw_merge(struct ath5k_softc *sc, struct sk_buff *skb)
+ath5k_check_ibss_tsf(struct ath5k_softc *sc, struct sk_buff *skb,
+                    struct ieee80211_rx_status *rxs)
 {
+       u64 tsf, bc_tstamp;
        u32 hw_tu;
        struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
 
-       if ((mgmt->frame_control & IEEE80211_FCTL_FTYPE) ==
-               IEEE80211_FTYPE_MGMT &&
-           (mgmt->frame_control & IEEE80211_FCTL_STYPE) ==
-               IEEE80211_STYPE_BEACON &&
-           mgmt->u.beacon.capab_info & WLAN_CAPABILITY_IBSS &&
+       if (ieee80211_is_beacon(mgmt->frame_control) &&
+           le16_to_cpu(mgmt->u.beacon.capab_info) & WLAN_CAPABILITY_IBSS &&
            memcmp(mgmt->bssid, sc->ah->ah_bssid, ETH_ALEN) == 0) {
                /*
-                * Received an IBSS beacon with the same BSSID. Hardware might
-                * have updated the TSF, check if we need to update timers.
+                * Received an IBSS beacon with the same BSSID. Hardware *must*
+                * have updated the local TSF. We have to work around various
+                * hardware bugs, though...
                 */
-               hw_tu = TSF_TO_TU(ath5k_hw_get_tsf64(sc->ah));
-               if (hw_tu >= sc->nexttbtt) {
-                       ath5k_beacon_update_timers(sc,
-                               mgmt->u.beacon.timestamp);
+               tsf = ath5k_hw_get_tsf64(sc->ah);
+               bc_tstamp = le64_to_cpu(mgmt->u.beacon.timestamp);
+               hw_tu = TSF_TO_TU(tsf);
+
+               ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON,
+                       "beacon %llx mactime %llx (diff %lld) tsf now %llx\n",
+                       (unsigned long long)bc_tstamp,
+                       (unsigned long long)rxs->mactime,
+                       (unsigned long long)(rxs->mactime - bc_tstamp),
+                       (unsigned long long)tsf);
+
+               /*
+                * Sometimes the HW will give us a wrong tstamp in the rx
+                * status, causing the timestamp extension to go wrong.
+                * (This seems to happen especially with beacon frames bigger
+                * than 78 byte (incl. FCS))
+                * But we know that the receive timestamp must be later than the
+                * timestamp of the beacon since HW must have synced to that.
+                *
+                * NOTE: here we assume mactime to be after the frame was
+                * received, not like mac80211 which defines it at the start.
+                */
+               if (bc_tstamp > rxs->mactime) {
                        ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON,
-                               "detected HW merge from received beacon\n");
+                               "fixing mactime from %llx to %llx\n",
+                               (unsigned long long)rxs->mactime,
+                               (unsigned long long)tsf);
+                       rxs->mactime = tsf;
                }
+
+               /*
+                * Local TSF might have moved higher than our beacon timers,
+                * in that case we have to update them to continue sending
+                * beacons. This also takes care of synchronizing beacon sending
+                * times with other stations.
+                */
+               if (hw_tu >= sc->nexttbtt)
+                       ath5k_beacon_update_timers(sc, bc_tstamp);
        }
 }
 
@@ -1682,52 +1692,67 @@ static void
 ath5k_tasklet_rx(unsigned long data)
 {
        struct ieee80211_rx_status rxs = {};
-       struct sk_buff *skb;
+       struct ath5k_rx_status rs = {};
+       struct sk_buff *skb, *next_skb;
+       dma_addr_t next_skb_addr;
        struct ath5k_softc *sc = (void *)data;
-       struct ath5k_buf *bf;
+       struct ath5k_buf *bf, *bf_last;
        struct ath5k_desc *ds;
-       u16 len;
-       u8 stat;
        int ret;
        int hdrlen;
-       int pad;
+       int padsize;
 
        spin_lock(&sc->rxbuflock);
+       if (list_empty(&sc->rxbuf)) {
+               ATH5K_WARN(sc, "empty rx buf pool\n");
+               goto unlock;
+       }
+       bf_last = list_entry(sc->rxbuf.prev, struct ath5k_buf, list);
        do {
-               if (unlikely(list_empty(&sc->rxbuf))) {
-                       ATH5K_WARN(sc, "empty rx buf pool\n");
-                       break;
-               }
+               rxs.flag = 0;
+
                bf = list_first_entry(&sc->rxbuf, struct ath5k_buf, list);
                BUG_ON(bf->skb == NULL);
                skb = bf->skb;
                ds = bf->desc;
 
-               /* TODO only one segment */
-               pci_dma_sync_single_for_cpu(sc->pdev, sc->desc_daddr,
-                               sc->desc_len, PCI_DMA_FROMDEVICE);
-
-               if (unlikely(ds->ds_link == bf->daddr)) /* this is the end */
-                       break;
+               /*
+                * last buffer must not be freed to ensure proper hardware
+                * function. When the hardware finishes also a packet next to
+                * it, we are sure, it doesn't use it anymore and we can go on.
+                */
+               if (bf_last == bf)
+                       bf->flags |= 1;
+               if (bf->flags) {
+                       struct ath5k_buf *bf_next = list_entry(bf->list.next,
+                                       struct ath5k_buf, list);
+                       ret = sc->ah->ah_proc_rx_desc(sc->ah, bf_next->desc,
+                                       &rs);
+                       if (ret)
+                               break;
+                       bf->flags &= ~1;
+                       /* skip the overwritten one (even status is martian) */
+                       goto next;
+               }
 
-               ret = sc->ah->ah_proc_rx_desc(sc->ah, ds);
+               ret = sc->ah->ah_proc_rx_desc(sc->ah, ds, &rs);
                if (unlikely(ret == -EINPROGRESS))
                        break;
                else if (unlikely(ret)) {
                        ATH5K_ERR(sc, "error in processing rx descriptor\n");
+                       spin_unlock(&sc->rxbuflock);
                        return;
                }
 
-               if (unlikely(ds->ds_rxstat.rs_more)) {
+               if (unlikely(rs.rs_more)) {
                        ATH5K_WARN(sc, "unsupported jumbo\n");
                        goto next;
                }
 
-               stat = ds->ds_rxstat.rs_status;
-               if (unlikely(stat)) {
-                       if (stat & AR5K_RXERR_PHY)
+               if (unlikely(rs.rs_status)) {
+                       if (rs.rs_status & AR5K_RXERR_PHY)
                                goto next;
-                       if (stat & AR5K_RXERR_DECRYPT) {
+                       if (rs.rs_status & AR5K_RXERR_DECRYPT) {
                                /*
                                 * Decrypt error.  If the error occurred
                                 * because there was no hardware key, then
@@ -1738,41 +1763,48 @@ ath5k_tasklet_rx(unsigned long data)
                                 *
                                 * XXX do key cache faulting
                                 */
-                               if (ds->ds_rxstat.rs_keyix ==
-                                               AR5K_RXKEYIX_INVALID &&
-                                               !(stat & AR5K_RXERR_CRC))
+                               if (rs.rs_keyix == AR5K_RXKEYIX_INVALID &&
+                                   !(rs.rs_status & AR5K_RXERR_CRC))
                                        goto accept;
                        }
-                       if (stat & AR5K_RXERR_MIC) {
+                       if (rs.rs_status & AR5K_RXERR_MIC) {
                                rxs.flag |= RX_FLAG_MMIC_ERROR;
                                goto accept;
                        }
 
                        /* let crypto-error packets fall through in MNTR */
-                       if ((stat & ~(AR5K_RXERR_DECRYPT|AR5K_RXERR_MIC)) ||
-                                       sc->opmode != IEEE80211_IF_TYPE_MNTR)
+                       if ((rs.rs_status &
+                               ~(AR5K_RXERR_DECRYPT|AR5K_RXERR_MIC)) ||
+                                       sc->opmode != NL80211_IFTYPE_MONITOR)
                                goto next;
                }
 accept:
-               len = ds->ds_rxstat.rs_datalen;
-               pci_dma_sync_single_for_cpu(sc->pdev, bf->skbaddr, len,
-                               PCI_DMA_FROMDEVICE);
-               pci_unmap_single(sc->pdev, bf->skbaddr, sc->rxbufsize,
-                               PCI_DMA_FROMDEVICE);
-               bf->skb = NULL;
-
-               skb_put(skb, len);
+               next_skb = ath5k_rx_skb_alloc(sc, &next_skb_addr);
 
                /*
-                * the hardware adds a padding to 4 byte boundaries between
-                * the header and the payload data if the header length is
-                * not multiples of 4 - remove it
+                * If we can't replace bf->skb with a new skb under memory
+                * pressure, just skip this packet
                 */
+               if (!next_skb)
+                       goto next;
+
+               pci_unmap_single(sc->pdev, bf->skbaddr, sc->rxbufsize,
+                               PCI_DMA_FROMDEVICE);
+               skb_put(skb, rs.rs_datalen);
+
+               /* The MAC header is padded to have 32-bit boundary if the
+                * packet payload is non-zero. The general calculation for
+                * padsize would take into account odd header lengths:
+                * padsize = (4 - hdrlen % 4) % 4; However, since only
+                * even-length headers are used, padding can only be 0 or 2
+                * bytes and we can optimize this a bit. In addition, we must
+                * not try to remove padding from short control frames that do
+                * not have payload. */
                hdrlen = ieee80211_get_hdrlen_from_skb(skb);
-               if (hdrlen & 3) {
-                       pad = hdrlen % 4;
-                       memmove(skb->data + pad, skb->data, hdrlen);
-                       skb_pull(skb, pad);
+               padsize = ath5k_pad_size(hdrlen);
+               if (padsize) {
+                       memmove(skb->data + padsize, skb->data, hdrlen);
+                       skb_pull(skb, padsize);
                }
 
                /*
@@ -1783,45 +1815,60 @@ accept:
                 * 15bit only. that means TSF extension has to be done within
                 * 32768usec (about 32ms). it might be necessary to move this to
                 * the interrupt handler, like it is done in madwifi.
+                *
+                * Unfortunately we don't know when the hardware takes the rx
+                * timestamp (beginning of phy frame, data frame, end of rx?).
+                * The only thing we know is that it is hardware specific...
+                * On AR5213 it seems the rx timestamp is at the end of the
+                * frame, but i'm not sure.
+                *
+                * NOTE: mac80211 defines mactime at the beginning of the first
+                * data symbol. Since we don't have any time references it's
+                * impossible to comply to that. This affects IBSS merge only
+                * right now, so it's not too bad...
                 */
-               rxs.mactime = ath5k_extend_tsf(sc->ah, ds->ds_rxstat.rs_tstamp);
+               rxs.mactime = ath5k_extend_tsf(sc->ah, rs.rs_tstamp);
                rxs.flag |= RX_FLAG_TSFT;
 
-               rxs.freq = sc->curchan->freq;
-               rxs.channel = sc->curchan->chan;
-               rxs.phymode = sc->curmode;
+               rxs.freq = sc->curchan->center_freq;
+               rxs.band = sc->curband->band;
 
-               /*
-                * signal quality:
-                * the names here are misleading and the usage of these
-                * values by iwconfig makes it even worse
-                */
-               /* noise floor in dBm, from the last noise calibration */
                rxs.noise = sc->ah->ah_noise_floor;
-               /* signal level in dBm */
-               rxs.ssi = rxs.noise + ds->ds_rxstat.rs_rssi;
-               /*
-                * "signal" is actually displayed as Link Quality by iwconfig
-                * we provide a percentage based on rssi (assuming max rssi 64)
-                */
-               rxs.signal = ds->ds_rxstat.rs_rssi * 100 / 64;
+               rxs.signal = rxs.noise + rs.rs_rssi;
 
-               rxs.antenna = ds->ds_rxstat.rs_antenna;
-               rxs.rate = ds->ds_rxstat.rs_rate;
-               rxs.flag |= ath5k_rx_decrypted(sc, ds, skb);
+               /* An rssi of 35 indicates you should be able use
+                * 54 Mbps reliably. A more elaborate scheme can be used
+                * here but it requires a map of SNR/throughput for each
+                * possible mode used */
+               rxs.qual = rs.rs_rssi * 100 / 35;
+
+               /* rssi can be more than 35 though, anything above that
+                * should be considered at 100% */
+               if (rxs.qual > 100)
+                       rxs.qual = 100;
+
+               rxs.antenna = rs.rs_antenna;
+               rxs.rate_idx = ath5k_hw_to_driver_rix(sc, rs.rs_rate);
+               rxs.flag |= ath5k_rx_decrypted(sc, ds, skb, &rs);
+
+               if (rxs.rate_idx >= 0 && rs.rs_rate ==
+                   sc->curband->bitrates[rxs.rate_idx].hw_value_short)
+                       rxs.flag |= RX_FLAG_SHORTPRE;
 
                ath5k_debug_dump_skb(sc, skb, "RX  ", 0);
 
                /* check beacons in IBSS mode */
-               if (sc->opmode == IEEE80211_IF_TYPE_IBSS)
-                       ath5k_check_ibss_hw_merge(sc, skb);
+               if (sc->opmode == NL80211_IFTYPE_ADHOC)
+                       ath5k_check_ibss_tsf(sc, skb, &rxs);
 
                __ieee80211_rx(sc->hw, skb, &rxs);
-               sc->led_rxrate = ds->ds_rxstat.rs_rate;
-               ath5k_led_event(sc, ATH_LED_RX);
+
+               bf->skb = next_skb;
+               bf->skbaddr = next_skb_addr;
 next:
                list_move_tail(&bf->list, &sc->rxbuf);
        } while (ath5k_rxbuf_setup(sc, bf) == 0);
+unlock:
        spin_unlock(&sc->rxbuflock);
 }
 
@@ -1835,20 +1882,18 @@ next:
 static void
 ath5k_tx_processq(struct ath5k_softc *sc, struct ath5k_txq *txq)
 {
-       struct ieee80211_tx_status txs = {};
+       struct ath5k_tx_status ts = {};
        struct ath5k_buf *bf, *bf0;
        struct ath5k_desc *ds;
        struct sk_buff *skb;
-       int ret;
+       struct ieee80211_tx_info *info;
+       int i, ret;
 
        spin_lock(&txq->lock);
        list_for_each_entry_safe(bf, bf0, &txq->q, list) {
                ds = bf->desc;
 
-               /* TODO only one segment */
-               pci_dma_sync_single_for_cpu(sc->pdev, sc->desc_daddr,
-                               sc->desc_len, PCI_DMA_FROMDEVICE);
-               ret = sc->ah->ah_proc_tx_desc(sc->ah, ds);
+               ret = sc->ah->ah_proc_tx_desc(sc->ah, ds, &ts);
                if (unlikely(ret == -EINPROGRESS))
                        break;
                else if (unlikely(ret)) {
@@ -1858,29 +1903,43 @@ ath5k_tx_processq(struct ath5k_softc *sc, struct ath5k_txq *txq)
                }
 
                skb = bf->skb;
+               info = IEEE80211_SKB_CB(skb);
                bf->skb = NULL;
+
                pci_unmap_single(sc->pdev, bf->skbaddr, skb->len,
                                PCI_DMA_TODEVICE);
 
-               txs.control = bf->ctl;
-               txs.retry_count = ds->ds_txstat.ts_shortretry +
-                       ds->ds_txstat.ts_longretry / 6;
-               if (unlikely(ds->ds_txstat.ts_status)) {
+               ieee80211_tx_info_clear_status(info);
+               for (i = 0; i < 4; i++) {
+                       struct ieee80211_tx_rate *r =
+                               &info->status.rates[i];
+
+                       if (ts.ts_rate[i]) {
+                               r->idx = ath5k_hw_to_driver_rix(sc, ts.ts_rate[i]);
+                               r->count = ts.ts_retry[i];
+                       } else {
+                               r->idx = -1;
+                               r->count = 0;
+                       }
+               }
+
+               /* count the successful attempt as well */
+               info->status.rates[ts.ts_final_idx].count++;
+
+               if (unlikely(ts.ts_status)) {
                        sc->ll_stats.dot11ACKFailureCount++;
-                       if (ds->ds_txstat.ts_status & AR5K_TXERR_XRETRY)
-                               txs.excessive_retries = 1;
-                       else if (ds->ds_txstat.ts_status & AR5K_TXERR_FILT)
-                               txs.flags |= IEEE80211_TX_STATUS_TX_FILTERED;
+                       if (ts.ts_status & AR5K_TXERR_FILT)
+                               info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
                } else {
-                       txs.flags |= IEEE80211_TX_STATUS_ACK;
-                       txs.ack_signal = ds->ds_txstat.ts_rssi;
+                       info->flags |= IEEE80211_TX_STAT_ACK;
+                       info->status.ack_signal = ts.ts_rssi;
                }
 
-               ieee80211_tx_status(sc->hw, skb, &txs);
-               sc->tx_stats.data[txq->qnum].count++;
+               ieee80211_tx_status(sc->hw, skb);
+               sc->tx_stats[txq->qnum].count++;
 
                spin_lock(&sc->txbuflock);
-               sc->tx_stats.data[txq->qnum].len--;
+               sc->tx_stats[txq->qnum].len--;
                list_move_tail(&bf->list, &sc->txbuf);
                sc->txbuf_len++;
                spin_unlock(&sc->txbuflock);
@@ -1898,13 +1957,9 @@ ath5k_tasklet_tx(unsigned long data)
        struct ath5k_softc *sc = (void *)data;
 
        ath5k_tx_processq(sc, sc->txq);
-
-       ath5k_led_event(sc, ATH_LED_TX);
 }
 
 
-
-
 /*****************\
 * Beacon handling *
 \*****************/
@@ -1913,10 +1968,10 @@ ath5k_tasklet_tx(unsigned long data)
  * Setup the beacon frame for transmit.
  */
 static int
-ath5k_beacon_setup(struct ath5k_softc *sc, struct ath5k_buf *bf,
-               struct ieee80211_tx_control *ctl)
+ath5k_beacon_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
 {
        struct sk_buff *skb = bf->skb;
+       struct  ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
        struct ath5k_hw *ah = sc->ah;
        struct ath5k_desc *ds;
        int ret, antenna = 0;
@@ -1927,7 +1982,7 @@ ath5k_beacon_setup(struct ath5k_softc *sc, struct ath5k_buf *bf,
        ATH5K_DBG(sc, ATH5K_DEBUG_BEACON, "skb %p [data %p len %u] "
                        "skbaddr %llx\n", skb, skb->data, skb->len,
                        (unsigned long long)bf->skbaddr);
-       if (pci_dma_mapping_error(bf->skbaddr)) {
+       if (pci_dma_mapping_error(sc->pdev, bf->skbaddr)) {
                ATH5K_ERR(sc, "beacon DMA mapping failed\n");
                return -EIO;
        }
@@ -1935,7 +1990,7 @@ ath5k_beacon_setup(struct ath5k_softc *sc, struct ath5k_buf *bf,
        ds = bf->desc;
 
        flags = AR5K_TXDESC_NOACK;
-       if (sc->opmode == IEEE80211_IF_TYPE_IBSS && ath5k_hw_hasveol(ah)) {
+       if (sc->opmode == NL80211_IFTYPE_ADHOC && ath5k_hw_hasveol(ah)) {
                ds->ds_link = bf->daddr;        /* self-linked */
                flags |= AR5K_TXDESC_VEOL;
                /*
@@ -1952,10 +2007,12 @@ ath5k_beacon_setup(struct ath5k_softc *sc, struct ath5k_buf *bf,
        }
 
        ds->ds_data = bf->skbaddr;
-       ret = ah->ah_setup_tx_desc(ah, ds, skb->len + FCS_LEN,
+       ret = ah->ah_setup_tx_desc(ah, ds, skb->len,
                        ieee80211_get_hdrlen_from_skb(skb),
-                       AR5K_PKT_TYPE_BEACON, (ctl->power_level * 2), ctl->tx_rate, 1,
-                       AR5K_TXKEYIX_INVALID, antenna, flags, 0, 0);
+                       AR5K_PKT_TYPE_BEACON, (sc->power_level * 2),
+                       ieee80211_get_tx_rate(sc->hw, info)->hw_value,
+                       1, AR5K_TXKEYIX_INVALID,
+                       antenna, flags, 0, 0);
        if (ret)
                goto err_unmap;
 
@@ -1982,8 +2039,8 @@ ath5k_beacon_send(struct ath5k_softc *sc)
 
        ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON, "in beacon_send\n");
 
-       if (unlikely(bf->skb == NULL || sc->opmode == IEEE80211_IF_TYPE_STA ||
-                       sc->opmode == IEEE80211_IF_TYPE_MNTR)) {
+       if (unlikely(bf->skb == NULL || sc->opmode == NL80211_IFTYPE_STATION ||
+                       sc->opmode == NL80211_IFTYPE_MONITOR)) {
                ATH5K_WARN(sc, "bf=%p bf_skb=%p\n", bf, bf ? bf->skb : NULL);
                return;
        }
@@ -2022,11 +2079,9 @@ ath5k_beacon_send(struct ath5k_softc *sc)
                ATH5K_WARN(sc, "beacon queue %u didn't stop?\n", sc->bhalq);
                /* NB: hw still stops DMA, so proceed */
        }
-       pci_dma_sync_single_for_cpu(sc->pdev, bf->skbaddr, bf->skb->len,
-                       PCI_DMA_TODEVICE);
 
-       ath5k_hw_put_tx_buf(ah, sc->bhalq, bf->daddr);
-       ath5k_hw_tx_start(ah, sc->bhalq);
+       ath5k_hw_set_txdp(ah, sc->bhalq, bf->daddr);
+       ath5k_hw_start_tx_dma(ah, sc->bhalq);
        ATH5K_DBG(sc, ATH5K_DEBUG_BEACON, "TXDP[%u] = %llx (%p)\n",
                sc->bhalq, (unsigned long long)bf->daddr, bf->desc);
 
@@ -2046,7 +2101,7 @@ ath5k_beacon_send(struct ath5k_softc *sc)
  * beacon timer registers.
  *
  * This is called in a variety of situations, e.g. when a beacon is received,
- * when a HW merge has been detected, but also when an new IBSS is created or
+ * when a TSF update has been detected, but also when an new IBSS is created or
  * when we otherwise know we have to update the timers, but we keep it in this
  * function to have it all together in one place.
  */
@@ -2126,8 +2181,9 @@ ath5k_beacon_update_timers(struct ath5k_softc *sc, u64 bc_tsf)
                        "updated timers based on beacon TSF\n");
 
        ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON,
-               "bc_tsf %llx hw_tsf %llx bc_tu %u hw_tu %u nexttbtt %u\n",
-               bc_tsf, hw_tsf, bc_tu, hw_tu, nexttbtt);
+                         "bc_tsf %llx hw_tsf %llx bc_tu %u hw_tu %u nexttbtt %u\n",
+                         (unsigned long long) bc_tsf,
+                         (unsigned long long) hw_tsf, bc_tu, hw_tu, nexttbtt);
        ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON, "intval %u %s %s\n",
                intval & AR5K_BEACON_PERIOD,
                intval & AR5K_BEACON_ENA ? "AR5K_BEACON_ENA" : "",
@@ -2145,38 +2201,44 @@ ath5k_beacon_update_timers(struct ath5k_softc *sc, u64 bc_tsf)
  * another AP to associate with.
  *
  * In IBSS mode we use a self-linked tx descriptor if possible. We enable SWBA
- * interrupts to detect HW merges only.
- *
- * AP mode is missing.
+ * interrupts to detect TSF updates only.
  */
 static void
 ath5k_beacon_config(struct ath5k_softc *sc)
 {
        struct ath5k_hw *ah = sc->ah;
 
-       ath5k_hw_set_intr(ah, 0);
+       ath5k_hw_set_imr(ah, 0);
        sc->bmisscount = 0;
+       sc->imask &= ~(AR5K_INT_BMISS | AR5K_INT_SWBA);
 
-       if (sc->opmode == IEEE80211_IF_TYPE_STA) {
+       if (sc->opmode == NL80211_IFTYPE_STATION) {
                sc->imask |= AR5K_INT_BMISS;
-       } else if (sc->opmode == IEEE80211_IF_TYPE_IBSS) {
+       } else if (sc->opmode == NL80211_IFTYPE_ADHOC ||
+                       sc->opmode == NL80211_IFTYPE_MESH_POINT ||
+                       sc->opmode == NL80211_IFTYPE_AP) {
                /*
                 * In IBSS mode we use a self-linked tx descriptor and let the
                 * hardware send the beacons automatically. We have to load it
                 * only once here.
                 * We use the SWBA interrupt only to keep track of the beacon
-                * timers in order to detect HW merges (automatic TSF updates).
+                * timers in order to detect automatic TSF updates.
                 */
                ath5k_beaconq_config(sc);
 
                sc->imask |= AR5K_INT_SWBA;
 
-               if (ath5k_hw_hasveol(ah))
-                       ath5k_beacon_send(sc);
+               if (sc->opmode == NL80211_IFTYPE_ADHOC) {
+                       if (ath5k_hw_hasveol(ah)) {
+                               spin_lock(&sc->block);
+                               ath5k_beacon_send(sc);
+                               spin_unlock(&sc->block);
+                       }
+               } else
+                       ath5k_beacon_update_timers(sc, -1);
        }
-       /* TODO else AP */
 
-       ath5k_hw_set_intr(ah, sc->imask);
+       ath5k_hw_set_imr(ah, sc->imask);
 }
 
 
@@ -2187,7 +2249,8 @@ ath5k_beacon_config(struct ath5k_softc *sc)
 static int
 ath5k_init(struct ath5k_softc *sc)
 {
-       int ret;
+       struct ath5k_hw *ah = sc->ah;
+       int ret, i;
 
        mutex_lock(&sc->lock);
 
@@ -2206,44 +2269,31 @@ ath5k_init(struct ath5k_softc *sc)
         * be followed by initialization of the appropriate bits
         * and then setup of the interrupt mask.
         */
-       sc->curchan = sc->hw->conf.chan;
-       ret = ath5k_hw_reset(sc->ah, sc->opmode, sc->curchan, false);
-       if (ret) {
-               ATH5K_ERR(sc, "unable to reset hardware: %d\n", ret);
-               goto done;
-       }
-       /*
-        * This is needed only to setup initial state
-        * but it's best done after a reset.
-        */
-       ath5k_hw_set_txpower_limit(sc->ah, 0);
-
-       /*
-        * Setup the hardware after reset: the key cache
-        * is filled as needed and the receive engine is
-        * set going.  Frame transmit is handled entirely
-        * in the frame output path; there's nothing to do
-        * here except setup the interrupt mask.
-        */
-       ret = ath5k_rx_start(sc);
+       sc->curchan = sc->hw->conf.channel;
+       sc->curband = &sc->sbands[sc->curchan->band];
+       sc->imask = AR5K_INT_RXOK | AR5K_INT_RXERR | AR5K_INT_RXEOL |
+               AR5K_INT_RXORN | AR5K_INT_TXDESC | AR5K_INT_TXEOL |
+               AR5K_INT_FATAL | AR5K_INT_GLOBAL | AR5K_INT_MIB;
+       ret = ath5k_reset(sc, false, false);
        if (ret)
                goto done;
 
        /*
-        * Enable interrupts.
+        * Reset the key cache since some parts do not reset the
+        * contents on initial power up or resume from suspend.
         */
-       sc->imask = AR5K_INT_RX | AR5K_INT_TX | AR5K_INT_RXEOL |
-               AR5K_INT_RXORN | AR5K_INT_FATAL | AR5K_INT_GLOBAL;
+       for (i = 0; i < AR5K_KEYTABLE_SIZE; i++)
+               ath5k_hw_reset_key(ah, i);
 
-       ath5k_hw_set_intr(sc->ah, sc->imask);
        /* Set ack to be sent at low bit-rates */
-       ath5k_hw_set_ack_bitrate_high(sc->ah, false);
+       ath5k_hw_set_ack_bitrate_high(ah, false);
 
        mod_timer(&sc->calib_tim, round_jiffies(jiffies +
                        msecs_to_jiffies(ath5k_calinterval * 1000)));
 
        ret = 0;
 done:
+       mmiowb();
        mutex_unlock(&sc->lock);
        return ret;
 }
@@ -2274,12 +2324,9 @@ ath5k_stop_locked(struct ath5k_softc *sc)
        ieee80211_stop_queues(sc->hw);
 
        if (!test_bit(ATH_STAT_INVALID, sc->status)) {
-               if (test_bit(ATH_STAT_LEDSOFT, sc->status)) {
-                       del_timer_sync(&sc->led_tim);
-                       ath5k_hw_set_gpio(ah, sc->led_pin, !sc->led_on);
-                       __clear_bit(ATH_STAT_LEDBLINKING, sc->status);
-               }
-               ath5k_hw_set_intr(ah, 0);
+               ath5k_led_off(sc);
+               ath5k_hw_set_imr(ah, 0);
+               synchronize_irq(sc->pdev->irq);
        }
        ath5k_txq_cleanup(sc);
        if (!test_bit(ATH_STAT_INVALID, sc->status)) {
@@ -2329,9 +2376,14 @@ ath5k_stop_hw(struct ath5k_softc *sc)
                }
        }
        ath5k_txbuf_free(sc, sc->bbuf);
+
+       mmiowb();
        mutex_unlock(&sc->lock);
 
        del_timer_sync(&sc->calib_tim);
+       tasklet_kill(&sc->rxtq);
+       tasklet_kill(&sc->txtq);
+       tasklet_kill(&sc->restq);
 
        return ret;
 }
@@ -2377,20 +2429,23 @@ ath5k_intr(int irq, void *dev_id)
                                *
                                * In IBSS mode we use this interrupt just to
                                * keep track of the next TBTT (target beacon
-                               * transmission time) in order to detect hardware
-                               * merges (TSF updates).
+                               * transmission time) in order to detect wether
+                               * automatic TSF updates happened.
                                */
-                               if (sc->opmode == IEEE80211_IF_TYPE_IBSS) {
+                               if (sc->opmode == NL80211_IFTYPE_ADHOC) {
                                         /* XXX: only if VEOL suppported */
                                        u64 tsf = ath5k_hw_get_tsf64(ah);
                                        sc->nexttbtt += sc->bintval;
                                        ATH5K_DBG(sc, ATH5K_DEBUG_BEACON,
-                                               "SWBA nexttbtt: %x hw_tu: %x "
-                                               "TSF: %llx\n",
-                                               sc->nexttbtt,
-                                               TSF_TO_TU(tsf), tsf);
+                                                 "SWBA nexttbtt: %x hw_tu: %x "
+                                                 "TSF: %llx\n",
+                                                 sc->nexttbtt,
+                                                 TSF_TO_TU(tsf),
+                                                 (unsigned long long) tsf);
                                } else {
+                                       spin_lock(&sc->block);
                                        ath5k_beacon_send(sc);
+                                       spin_unlock(&sc->block);
                                }
                        }
                        if (status & AR5K_INT_RXEOL) {
@@ -2405,14 +2460,19 @@ ath5k_intr(int irq, void *dev_id)
                                /* bump tx trigger level */
                                ath5k_hw_update_tx_triglevel(ah, true);
                        }
-                       if (status & AR5K_INT_RX)
+                       if (status & (AR5K_INT_RXOK | AR5K_INT_RXERR))
                                tasklet_schedule(&sc->rxtq);
-                       if (status & AR5K_INT_TX)
+                       if (status & (AR5K_INT_TXOK | AR5K_INT_TXDESC
+                                       | AR5K_INT_TXERR | AR5K_INT_TXEOL))
                                tasklet_schedule(&sc->txtq);
                        if (status & AR5K_INT_BMISS) {
                        }
                        if (status & AR5K_INT_MIB) {
-                               /* TODO */
+                               /*
+                                * These stats are also used for ANI i think
+                                * so how about updating them more often ?
+                                */
+                               ath5k_hw_update_mib_counters(ah, &sc->ll_stats);
                        }
                }
        } while (ath5k_hw_is_intr_pending(ah) && counter-- > 0);
@@ -2428,7 +2488,7 @@ ath5k_tasklet_reset(unsigned long data)
 {
        struct ath5k_softc *sc = (void *)data;
 
-       ath5k_reset(sc->hw);
+       ath5k_reset_wake(sc);
 }
 
 /*
@@ -2442,7 +2502,8 @@ ath5k_calibrate(unsigned long data)
        struct ath5k_hw *ah = sc->ah;
 
        ATH5K_DBG(sc, ATH5K_DEBUG_CALIBRATE, "channel %u/%x\n",
-               sc->curchan->chan, sc->curchan->val);
+               ieee80211_frequency_to_channel(sc->curchan->center_freq),
+               sc->curchan->hw_value);
 
        if (ath5k_hw_get_rf_gain(ah) == AR5K_RFGAIN_NEED_CHANGE) {
                /*
@@ -2450,11 +2511,12 @@ ath5k_calibrate(unsigned long data)
                 * to load new gain values.
                 */
                ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "calibration, resetting\n");
-               ath5k_reset(sc->hw);
+               ath5k_reset_wake(sc);
        }
        if (ath5k_hw_phy_calibrate(ah, sc->curchan))
                ATH5K_ERR(sc, "calibration of channel %u failed\n",
-                               sc->curchan->chan);
+                       ieee80211_frequency_to_channel(
+                               sc->curchan->center_freq));
 
        mod_timer(&sc->calib_tim, round_jiffies(jiffies +
                        msecs_to_jiffies(ath5k_calinterval * 1000)));
@@ -2467,54 +2529,133 @@ ath5k_calibrate(unsigned long data)
 \***************/
 
 static void
-ath5k_led_off(unsigned long data)
+ath5k_led_enable(struct ath5k_softc *sc)
 {
-       struct ath5k_softc *sc = (void *)data;
-
-       if (test_bit(ATH_STAT_LEDENDBLINK, sc->status))
-               __clear_bit(ATH_STAT_LEDBLINKING, sc->status);
-       else {
-               __set_bit(ATH_STAT_LEDENDBLINK, sc->status);
-               ath5k_hw_set_gpio(sc->ah, sc->led_pin, !sc->led_on);
-               mod_timer(&sc->led_tim, jiffies + sc->led_off);
+       if (test_bit(ATH_STAT_LEDSOFT, sc->status)) {
+               ath5k_hw_set_gpio_output(sc->ah, sc->led_pin);
+               ath5k_led_off(sc);
        }
 }
 
-/*
- * Blink the LED according to the specified on/off times.
- */
 static void
-ath5k_led_blink(struct ath5k_softc *sc, unsigned int on,
-               unsigned int off)
+ath5k_led_on(struct ath5k_softc *sc)
 {
-       ATH5K_DBG(sc, ATH5K_DEBUG_LED, "on %u off %u\n", on, off);
+       if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
+               return;
        ath5k_hw_set_gpio(sc->ah, sc->led_pin, sc->led_on);
-       __set_bit(ATH_STAT_LEDBLINKING, sc->status);
-       __clear_bit(ATH_STAT_LEDENDBLINK, sc->status);
-       sc->led_off = off;
-       mod_timer(&sc->led_tim, jiffies + on);
 }
 
 static void
-ath5k_led_event(struct ath5k_softc *sc, int event)
+ath5k_led_off(struct ath5k_softc *sc)
 {
-       if (likely(!test_bit(ATH_STAT_LEDSOFT, sc->status)))
+       if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
                return;
-       if (unlikely(test_bit(ATH_STAT_LEDBLINKING, sc->status)))
-               return; /* don't interrupt active blink */
-       switch (event) {
-       case ATH_LED_TX:
-               ath5k_led_blink(sc, sc->hwmap[sc->led_txrate].ledon,
-                       sc->hwmap[sc->led_txrate].ledoff);
-               break;
-       case ATH_LED_RX:
-               ath5k_led_blink(sc, sc->hwmap[sc->led_rxrate].ledon,
-                       sc->hwmap[sc->led_rxrate].ledoff);
-               break;
+       ath5k_hw_set_gpio(sc->ah, sc->led_pin, !sc->led_on);
+}
+
+static void
+ath5k_led_brightness_set(struct led_classdev *led_dev,
+       enum led_brightness brightness)
+{
+       struct ath5k_led *led = container_of(led_dev, struct ath5k_led,
+               led_dev);
+
+       if (brightness == LED_OFF)
+               ath5k_led_off(led->sc);
+       else
+               ath5k_led_on(led->sc);
+}
+
+static int
+ath5k_register_led(struct ath5k_softc *sc, struct ath5k_led *led,
+                  const char *name, char *trigger)
+{
+       int err;
+
+       led->sc = sc;
+       strncpy(led->name, name, sizeof(led->name));
+       led->led_dev.name = led->name;
+       led->led_dev.default_trigger = trigger;
+       led->led_dev.brightness_set = ath5k_led_brightness_set;
+
+       err = led_classdev_register(&sc->pdev->dev, &led->led_dev);
+       if (err) {
+               ATH5K_WARN(sc, "could not register LED %s\n", name);
+               led->sc = NULL;
        }
+       return err;
+}
+
+static void
+ath5k_unregister_led(struct ath5k_led *led)
+{
+       if (!led->sc)
+               return;
+       led_classdev_unregister(&led->led_dev);
+       ath5k_led_off(led->sc);
+       led->sc = NULL;
 }
 
+static void
+ath5k_unregister_leds(struct ath5k_softc *sc)
+{
+       ath5k_unregister_led(&sc->rx_led);
+       ath5k_unregister_led(&sc->tx_led);
+}
+
+
+static int
+ath5k_init_leds(struct ath5k_softc *sc)
+{
+       int ret = 0;
+       struct ieee80211_hw *hw = sc->hw;
+       struct pci_dev *pdev = sc->pdev;
+       char name[ATH5K_LED_MAX_NAME_LEN + 1];
+
+       /*
+        * Auto-enable soft led processing for IBM cards and for
+        * 5211 minipci cards.
+        */
+       if (pdev->device == PCI_DEVICE_ID_ATHEROS_AR5212_IBM ||
+           pdev->device == PCI_DEVICE_ID_ATHEROS_AR5211) {
+               __set_bit(ATH_STAT_LEDSOFT, sc->status);
+               sc->led_pin = 0;
+               sc->led_on = 0;  /* active low */
+       }
+       /* Enable softled on PIN1 on HP Compaq nc6xx, nc4000 & nx5000 laptops */
+       if (pdev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ) {
+               __set_bit(ATH_STAT_LEDSOFT, sc->status);
+               sc->led_pin = 1;
+               sc->led_on = 1;  /* active high */
+       }
+       /*
+        * Pin 3 on Foxconn chips used in Acer Aspire One (0x105b:e008) and
+        * in emachines notebooks with AMBIT subsystem.
+        */
+       if (pdev->subsystem_vendor == PCI_VENDOR_ID_FOXCONN ||
+           pdev->subsystem_vendor == PCI_VENDOR_ID_AMBIT) {
+               __set_bit(ATH_STAT_LEDSOFT, sc->status);
+               sc->led_pin = 3;
+               sc->led_on = 0;  /* active low */
+       }
+
+       if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
+               goto out;
 
+       ath5k_led_enable(sc);
+
+       snprintf(name, sizeof(name), "ath5k-%s::rx", wiphy_name(hw->wiphy));
+       ret = ath5k_register_led(sc, &sc->rx_led, name,
+               ieee80211_get_rx_led_name(hw));
+       if (ret)
+               goto out;
+
+       snprintf(name, sizeof(name), "ath5k-%s::tx", wiphy_name(hw->wiphy));
+       ret = ath5k_register_led(sc, &sc->tx_led, name,
+               ieee80211_get_tx_led_name(hw));
+out:
+       return ret;
+}
 
 
 /********************\
@@ -2522,18 +2663,17 @@ ath5k_led_event(struct ath5k_softc *sc, int event)
 \********************/
 
 static int
-ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
-                       struct ieee80211_tx_control *ctl)
+ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
 {
        struct ath5k_softc *sc = hw->priv;
        struct ath5k_buf *bf;
        unsigned long flags;
        int hdrlen;
-       int pad;
+       int padsize;
 
        ath5k_debug_dump_skb(sc, skb, "TX  ", 1);
 
-       if (sc->opmode == IEEE80211_IF_TYPE_MNTR)
+       if (sc->opmode == NL80211_IFTYPE_MONITOR)
                ATH5K_DBG(sc, ATH5K_DEBUG_XMIT, "tx in monitor (scan?)\n");
 
        /*
@@ -2541,25 +2681,24 @@ ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
         * if this is not the case we add the padding after the header
         */
        hdrlen = ieee80211_get_hdrlen_from_skb(skb);
-       if (hdrlen & 3) {
-               pad = hdrlen % 4;
-               if (skb_headroom(skb) < pad) {
+       padsize = ath5k_pad_size(hdrlen);
+       if (padsize) {
+
+               if (skb_headroom(skb) < padsize) {
                        ATH5K_ERR(sc, "tx hdrlen not %%4: %d not enough"
-                               " headroom to pad %d\n", hdrlen, pad);
-                       return -1;
+                                 " headroom to pad %d\n", hdrlen, padsize);
+                       return NETDEV_TX_BUSY;
                }
-               skb_push(skb, pad);
-               memmove(skb->data, skb->data+pad, hdrlen);
+               skb_push(skb, padsize);
+               memmove(skb->data, skb->data+padsize, hdrlen);
        }
 
-       sc->led_txrate = ctl->tx_rate;
-
        spin_lock_irqsave(&sc->txbuflock, flags);
        if (list_empty(&sc->txbuf)) {
                ATH5K_ERR(sc, "no further txbuf available, dropping packet\n");
                spin_unlock_irqrestore(&sc->txbuflock, flags);
-               ieee80211_stop_queue(hw, ctl->queue);
-               return -1;
+               ieee80211_stop_queue(hw, skb_get_queue_mapping(skb));
+               return NETDEV_TX_BUSY;
        }
        bf = list_first_entry(&sc->txbuf, struct ath5k_buf, list);
        list_del(&bf->list);
@@ -2570,67 +2709,81 @@ ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
 
        bf->skb = skb;
 
-       if (ath5k_txbuf_setup(sc, bf, ctl)) {
+       if (ath5k_txbuf_setup(sc, bf)) {
                bf->skb = NULL;
                spin_lock_irqsave(&sc->txbuflock, flags);
                list_add_tail(&bf->list, &sc->txbuf);
                sc->txbuf_len++;
                spin_unlock_irqrestore(&sc->txbuflock, flags);
                dev_kfree_skb_any(skb);
-               return 0;
+               return NETDEV_TX_OK;
        }
 
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 static int
-ath5k_reset(struct ieee80211_hw *hw)
+ath5k_reset(struct ath5k_softc *sc, bool stop, bool change_channel)
 {
-       struct ath5k_softc *sc = hw->priv;
        struct ath5k_hw *ah = sc->ah;
        int ret;
 
        ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "resetting\n");
-       /*
-        * Convert to a hw channel description with the flags
-        * constrained to reflect the current operating mode.
-        */
-       sc->curchan = hw->conf.chan;
-
-       ath5k_hw_set_intr(ah, 0);
-       ath5k_txq_cleanup(sc);
-       ath5k_rx_stop(sc);
 
+       if (stop) {
+               ath5k_hw_set_imr(ah, 0);
+               ath5k_txq_cleanup(sc);
+               ath5k_rx_stop(sc);
+       }
        ret = ath5k_hw_reset(ah, sc->opmode, sc->curchan, true);
-       if (unlikely(ret)) {
+       if (ret) {
                ATH5K_ERR(sc, "can't reset hardware (%d)\n", ret);
                goto err;
        }
+
+       /*
+        * This is needed only to setup initial state
+        * but it's best done after a reset.
+        */
        ath5k_hw_set_txpower_limit(sc->ah, 0);
 
        ret = ath5k_rx_start(sc);
-       if (unlikely(ret)) {
+       if (ret) {
                ATH5K_ERR(sc, "can't start recv logic\n");
                goto err;
        }
+
        /*
-        * We may be doing a reset in response to an ioctl
-        * that changes the channel so update any state that
-        * might change as a result.
+        * Change channels and update the h/w rate map if we're switching;
+        * e.g. 11a to 11b/g.
+        *
+        * We may be doing a reset in response to an ioctl that changes the
+        * channel so update any state that might change as a result.
         *
         * XXX needed?
         */
 /*     ath5k_chan_change(sc, c); */
-       ath5k_beacon_config(sc);
-       /* intrs are started by ath5k_beacon_config */
 
-       ieee80211_wake_queues(hw);
+       ath5k_beacon_config(sc);
+       /* intrs are enabled by ath5k_beacon_config */
 
        return 0;
 err:
        return ret;
 }
 
+static int
+ath5k_reset_wake(struct ath5k_softc *sc)
+{
+       int ret;
+
+       ret = ath5k_reset(sc, true, true);
+       if (!ret)
+               ieee80211_wake_queues(sc->hw);
+
+       return ret;
+}
+
 static int ath5k_start(struct ieee80211_hw *hw)
 {
        return ath5k_init(hw->priv);
@@ -2656,15 +2809,23 @@ static int ath5k_add_interface(struct ieee80211_hw *hw,
        sc->vif = conf->vif;
 
        switch (conf->type) {
-       case IEEE80211_IF_TYPE_STA:
-       case IEEE80211_IF_TYPE_IBSS:
-       case IEEE80211_IF_TYPE_MNTR:
+       case NL80211_IFTYPE_AP:
+       case NL80211_IFTYPE_STATION:
+       case NL80211_IFTYPE_ADHOC:
+       case NL80211_IFTYPE_MESH_POINT:
+       case NL80211_IFTYPE_MONITOR:
                sc->opmode = conf->type;
                break;
        default:
                ret = -EOPNOTSUPP;
                goto end;
        }
+
+       /* Set to a reasonable value. Note that this will
+        * be set to mac80211's value at ath5k_config(). */
+       sc->bintval = 1000;
+       ath5k_hw_set_lladdr(sc->ah, conf->mac_addr);
+
        ret = 0;
 end:
        mutex_unlock(&sc->lock);
@@ -2676,26 +2837,37 @@ ath5k_remove_interface(struct ieee80211_hw *hw,
                        struct ieee80211_if_init_conf *conf)
 {
        struct ath5k_softc *sc = hw->priv;
+       u8 mac[ETH_ALEN] = {};
 
        mutex_lock(&sc->lock);
        if (sc->vif != conf->vif)
                goto end;
 
+       ath5k_hw_set_lladdr(sc->ah, mac);
        sc->vif = NULL;
 end:
        mutex_unlock(&sc->lock);
 }
 
+/*
+ * TODO: Phy disable/diversity etc
+ */
 static int
-ath5k_config(struct ieee80211_hw *hw,
-                       struct ieee80211_conf *conf)
+ath5k_config(struct ieee80211_hw *hw, u32 changed)
 {
        struct ath5k_softc *sc = hw->priv;
+       struct ieee80211_conf *conf = &hw->conf;
+       int ret;
+
+       mutex_lock(&sc->lock);
 
        sc->bintval = conf->beacon_int;
-       ath5k_setcurmode(sc, conf->phymode);
+       sc->power_level = conf->power_level;
 
-       return ath5k_chan_set(sc, conf->chan);
+       ret = ath5k_chan_set(sc, conf->channel);
+
+       mutex_unlock(&sc->lock);
+       return ret;
 }
 
 static int
@@ -2706,24 +2878,33 @@ ath5k_config_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
        struct ath5k_hw *ah = sc->ah;
        int ret;
 
-       /* Set to a reasonable value. Note that this will
-        * be set to mac80211's value at ath5k_config(). */
-       sc->bintval = 1000;
        mutex_lock(&sc->lock);
        if (sc->vif != vif) {
                ret = -EIO;
                goto unlock;
        }
-       if (conf->bssid) {
+       if (conf->changed & IEEE80211_IFCC_BSSID && conf->bssid) {
                /* Cache for later use during resets */
                memcpy(ah->ah_bssid, conf->bssid, ETH_ALEN);
                /* XXX: assoc id is set to 0 for now, mac80211 doesn't have
                 * a clean way of letting us retrieve this yet. */
                ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
+               mmiowb();
+       }
+       if (conf->changed & IEEE80211_IFCC_BEACON &&
+                       (vif->type == NL80211_IFTYPE_ADHOC ||
+                        vif->type == NL80211_IFTYPE_MESH_POINT ||
+                        vif->type == NL80211_IFTYPE_AP)) {
+               struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
+               if (!beacon) {
+                       ret = -ENOMEM;
+                       goto unlock;
+               }
+               ath5k_beacon_update(sc, beacon);
        }
        mutex_unlock(&sc->lock);
 
-       return ath5k_reset(hw);
+       return ath5k_reset_wake(sc);
 unlock:
        mutex_unlock(&sc->lock);
        return ret;
@@ -2780,9 +2961,9 @@ static void ath5k_configure_filter(struct ieee80211_hw *hw,
                if (*new_flags & FIF_PROMISC_IN_BSS) {
                        rfilt |= AR5K_RX_FILTER_PROM;
                        __set_bit(ATH_STAT_PROMISC, sc->status);
-               }
-               else
+               } else {
                        __clear_bit(ATH_STAT_PROMISC, sc->status);
+               }
        }
 
        /* Note, AR5K_RX_FILTER_MCAST is already enabled */
@@ -2794,9 +2975,9 @@ static void ath5k_configure_filter(struct ieee80211_hw *hw,
                        if (!mclist)
                                break;
                        /* calculate XOR of eight 6-bit values */
-                       val = LE_READ_4(mclist->dmi_addr + 0);
+                       val = get_unaligned_le32(mclist->dmi_addr + 0);
                        pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
-                       val = LE_READ_4(mclist->dmi_addr + 3);
+                       val = get_unaligned_le32(mclist->dmi_addr + 3);
                        pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
                        pos &= 0x3f;
                        mfilt[pos / 32] |= (1 << (pos % 32));
@@ -2830,21 +3011,25 @@ static void ath5k_configure_filter(struct ieee80211_hw *hw,
 
        /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
 
-       if (sc->opmode == IEEE80211_IF_TYPE_MNTR)
+       if (sc->opmode == NL80211_IFTYPE_MONITOR)
                rfilt |= AR5K_RX_FILTER_CONTROL | AR5K_RX_FILTER_BEACON |
                        AR5K_RX_FILTER_PROBEREQ | AR5K_RX_FILTER_PROM;
-       if (sc->opmode != IEEE80211_IF_TYPE_STA)
+       if (sc->opmode != NL80211_IFTYPE_STATION)
                rfilt |= AR5K_RX_FILTER_PROBEREQ;
-       if (sc->opmode != IEEE80211_IF_TYPE_AP &&
+       if (sc->opmode != NL80211_IFTYPE_AP &&
+               sc->opmode != NL80211_IFTYPE_MESH_POINT &&
                test_bit(ATH_STAT_PROMISC, sc->status))
                rfilt |= AR5K_RX_FILTER_PROM;
-       if (sc->opmode == IEEE80211_IF_TYPE_STA ||
-               sc->opmode == IEEE80211_IF_TYPE_IBSS) {
+       if ((sc->opmode == NL80211_IFTYPE_STATION && sc->assoc) ||
+               sc->opmode == NL80211_IFTYPE_ADHOC ||
+               sc->opmode == NL80211_IFTYPE_AP)
                rfilt |= AR5K_RX_FILTER_BEACON;
-       }
+       if (sc->opmode == NL80211_IFTYPE_MESH_POINT)
+               rfilt |= AR5K_RX_FILTER_CONTROL | AR5K_RX_FILTER_BEACON |
+                       AR5K_RX_FILTER_PROBEREQ | AR5K_RX_FILTER_PROM;
 
        /* Set filters */
-       ath5k_hw_set_rx_filter(ah,rfilt);
+       ath5k_hw_set_rx_filter(ah, rfilt);
 
        /* Set multicast bits */
        ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
@@ -2855,16 +3040,19 @@ static void ath5k_configure_filter(struct ieee80211_hw *hw,
 
 static int
 ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
-               const u8 *local_addr, const u8 *addr,
-               struct ieee80211_key_conf *key)
+             struct ieee80211_vif *vif, struct ieee80211_sta *sta,
+             struct ieee80211_key_conf *key)
 {
        struct ath5k_softc *sc = hw->priv;
        int ret = 0;
 
-       switch(key->alg) {
+       if (modparam_nohwcrypt)
+               return -EOPNOTSUPP;
+
+       switch (key->alg) {
        case ALG_WEP:
-               break;
        case ALG_TKIP:
+               break;
        case ALG_CCMP:
                return -EOPNOTSUPP;
        default:
@@ -2876,13 +3064,16 @@ ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 
        switch (cmd) {
        case SET_KEY:
-               ret = ath5k_hw_set_key(sc->ah, key->keyidx, key, addr);
+               ret = ath5k_hw_set_key(sc->ah, key->keyidx, key,
+                                      sta ? sta->addr : NULL);
                if (ret) {
                        ATH5K_ERR(sc, "can't set the key\n");
                        goto unlock;
                }
                __set_bit(key->keyidx, sc->keymap);
                key->hw_key_idx = key->keyidx;
+               key->flags |= (IEEE80211_KEY_FLAG_GENERATE_IV |
+                              IEEE80211_KEY_FLAG_GENERATE_MMIC);
                break;
        case DISABLE_KEY:
                ath5k_hw_reset_key(sc->ah, key->keyidx);
@@ -2894,6 +3085,7 @@ ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
        }
 
 unlock:
+       mmiowb();
        mutex_unlock(&sc->lock);
        return ret;
 }
@@ -2903,6 +3095,10 @@ ath5k_get_stats(struct ieee80211_hw *hw,
                struct ieee80211_low_level_stats *stats)
 {
        struct ath5k_softc *sc = hw->priv;
+       struct ath5k_hw *ah = sc->ah;
+
+       /* Force update */
+       ath5k_hw_update_mib_counters(ah, &sc->ll_stats);
 
        memcpy(stats, &sc->ll_stats, sizeof(sc->ll_stats));
 
@@ -2929,6 +3125,14 @@ ath5k_get_tsf(struct ieee80211_hw *hw)
 }
 
 static void
+ath5k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
+{
+       struct ath5k_softc *sc = hw->priv;
+
+       ath5k_hw_set_tsf64(sc->ah, tsf);
+}
+
+static void
 ath5k_reset_tsf(struct ieee80211_hw *hw)
 {
        struct ath5k_softc *sc = hw->priv;
@@ -2937,38 +3141,60 @@ ath5k_reset_tsf(struct ieee80211_hw *hw)
         * in IBSS mode we need to update the beacon timers too.
         * this will also reset the TSF if we call it with 0
         */
-       if (sc->opmode == IEEE80211_IF_TYPE_IBSS)
+       if (sc->opmode == NL80211_IFTYPE_ADHOC)
                ath5k_beacon_update_timers(sc, 0);
        else
                ath5k_hw_reset_tsf(sc->ah);
 }
 
 static int
-ath5k_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
-                       struct ieee80211_tx_control *ctl)
+ath5k_beacon_update(struct ath5k_softc *sc, struct sk_buff *skb)
 {
-       struct ath5k_softc *sc = hw->priv;
+       unsigned long flags;
        int ret;
 
        ath5k_debug_dump_skb(sc, skb, "BC  ", 1);
 
-       mutex_lock(&sc->lock);
-
-       if (sc->opmode != IEEE80211_IF_TYPE_IBSS) {
-               ret = -EIO;
-               goto end;
-       }
-
+       spin_lock_irqsave(&sc->block, flags);
        ath5k_txbuf_free(sc, sc->bbuf);
        sc->bbuf->skb = skb;
-       ret = ath5k_beacon_setup(sc, sc->bbuf, ctl);
+       ret = ath5k_beacon_setup(sc, sc->bbuf);
        if (ret)
                sc->bbuf->skb = NULL;
-       else
+       spin_unlock_irqrestore(&sc->block, flags);
+       if (!ret) {
                ath5k_beacon_config(sc);
+               mmiowb();
+       }
 
-end:
-       mutex_unlock(&sc->lock);
        return ret;
 }
+static void
+set_beacon_filter(struct ieee80211_hw *hw, bool enable)
+{
+       struct ath5k_softc *sc = hw->priv;
+       struct ath5k_hw *ah = sc->ah;
+       u32 rfilt;
+       rfilt = ath5k_hw_get_rx_filter(ah);
+       if (enable)
+               rfilt |= AR5K_RX_FILTER_BEACON;
+       else
+               rfilt &= ~AR5K_RX_FILTER_BEACON;
+       ath5k_hw_set_rx_filter(ah, rfilt);
+       sc->filter_flags = rfilt;
+}
 
+static void ath5k_bss_info_changed(struct ieee80211_hw *hw,
+                                   struct ieee80211_vif *vif,
+                                   struct ieee80211_bss_conf *bss_conf,
+                                   u32 changes)
+{
+       struct ath5k_softc *sc = hw->priv;
+       if (changes & BSS_CHANGED_ASSOC) {
+               mutex_lock(&sc->lock);
+               sc->assoc = bss_conf->assoc;
+               if (sc->opmode == NL80211_IFTYPE_STATION)
+                       set_beacon_filter(hw, sc->assoc);
+               mutex_unlock(&sc->lock);
+       }
+}