]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[ath5k] Add support for non-802.11n Atheros wireless NICs
authorJoshua Oreman <oremanj@rwcr.net>
Fri, 7 Aug 2009 09:25:35 +0000 (02:25 -0700)
committerMichael Brown <mcb30@etherboot.org>
Sat, 8 Aug 2009 23:16:13 +0000 (00:16 +0100)
Signed-off-by: Michael Brown <mcb30@etherboot.org>
21 files changed:
src/Makefile
src/drivers/net/ath5k/ath5k.c [new file with mode: 0644]
src/drivers/net/ath5k/ath5k.h [new file with mode: 0644]
src/drivers/net/ath5k/ath5k_attach.c [new file with mode: 0644]
src/drivers/net/ath5k/ath5k_caps.c [new file with mode: 0644]
src/drivers/net/ath5k/ath5k_desc.c [new file with mode: 0644]
src/drivers/net/ath5k/ath5k_dma.c [new file with mode: 0644]
src/drivers/net/ath5k/ath5k_eeprom.c [new file with mode: 0644]
src/drivers/net/ath5k/ath5k_gpio.c [new file with mode: 0644]
src/drivers/net/ath5k/ath5k_initvals.c [new file with mode: 0644]
src/drivers/net/ath5k/ath5k_pcu.c [new file with mode: 0644]
src/drivers/net/ath5k/ath5k_phy.c [new file with mode: 0644]
src/drivers/net/ath5k/ath5k_qcu.c [new file with mode: 0644]
src/drivers/net/ath5k/ath5k_reset.c [new file with mode: 0644]
src/drivers/net/ath5k/base.h [new file with mode: 0644]
src/drivers/net/ath5k/desc.h [new file with mode: 0644]
src/drivers/net/ath5k/eeprom.h [new file with mode: 0644]
src/drivers/net/ath5k/reg.h [new file with mode: 0644]
src/drivers/net/ath5k/rfbuffer.h [new file with mode: 0644]
src/drivers/net/ath5k/rfgain.h [new file with mode: 0644]
src/include/gpxe/errfile.h

index b246faae9c7ed471f405cbf6337108429a763fe8..0dbe8d3d1e71cd08f9239ced9b1e73c79a35c074 100644 (file)
@@ -62,6 +62,7 @@ SRCDIRS               += drivers/net
 SRCDIRS                += drivers/net/e1000
 SRCDIRS                += drivers/net/phantom
 SRCDIRS                += drivers/net/rtl818x
+SRCDIRS                += drivers/net/ath5k
 SRCDIRS                += drivers/block
 SRCDIRS                += drivers/nvs
 SRCDIRS                += drivers/bitbash
diff --git a/src/drivers/net/ath5k/ath5k.c b/src/drivers/net/ath5k/ath5k.c
new file mode 100644 (file)
index 0000000..5101a54
--- /dev/null
@@ -0,0 +1,1694 @@
+/*
+ * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
+ * Copyright (c) 2004-2005 Atheros Communications, Inc.
+ * Copyright (c) 2006 Devicescape Software, Inc.
+ * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
+ * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
+ *
+ * Modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>
+ * Original from Linux kernel 2.6.30.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
+ *    redistribution must be conditioned upon including a substantially
+ *    similar Disclaimer requirement for further binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+FILE_LICENCE ( BSD3 );
+
+#include <stdlib.h>
+#include <gpxe/malloc.h>
+#include <gpxe/timer.h>
+#include <gpxe/netdevice.h>
+#include <gpxe/pci.h>
+#include <gpxe/pci_io.h>
+
+#include "base.h"
+#include "reg.h"
+
+#define ATH5K_CALIB_INTERVAL   10 /* Calibrate PHY every 10 seconds */
+#define ATH5K_RETRIES          4  /* Number of times to retry packet sends */
+#define ATH5K_DESC_ALIGN       16 /* Alignment for TX/RX descriptors */
+
+/******************\
+* Internal defines *
+\******************/
+
+/* Known PCI ids */
+static struct pci_device_id ath5k_nics[] = {
+       PCI_ROM(0x168c, 0x0207, "ath5210e", "Atheros 5210 early", AR5K_AR5210),
+       PCI_ROM(0x168c, 0x0007, "ath5210", "Atheros 5210", AR5K_AR5210),
+       PCI_ROM(0x168c, 0x0011, "ath5311", "Atheros 5311 (AHB)", AR5K_AR5211),
+       PCI_ROM(0x168c, 0x0012, "ath5211", "Atheros 5211", AR5K_AR5211),
+       PCI_ROM(0x168c, 0x0013, "ath5212", "Atheros 5212", AR5K_AR5212),
+       PCI_ROM(0xa727, 0x0013, "ath5212c","3com Ath 5212", AR5K_AR5212),
+       PCI_ROM(0x10b7, 0x0013, "rdag675", "3com 3CRDAG675", AR5K_AR5212),
+       PCI_ROM(0x168c, 0x1014, "ath5212m", "Ath 5212 miniPCI", AR5K_AR5212),
+       PCI_ROM(0x168c, 0x0014, "ath5212x14", "Atheros 5212 x14", AR5K_AR5212),
+       PCI_ROM(0x168c, 0x0015, "ath5212x15", "Atheros 5212 x15", AR5K_AR5212),
+       PCI_ROM(0x168c, 0x0016, "ath5212x16", "Atheros 5212 x16", AR5K_AR5212),
+       PCI_ROM(0x168c, 0x0017, "ath5212x17", "Atheros 5212 x17", AR5K_AR5212),
+       PCI_ROM(0x168c, 0x0018, "ath5212x18", "Atheros 5212 x18", AR5K_AR5212),
+       PCI_ROM(0x168c, 0x0019, "ath5212x19", "Atheros 5212 x19", AR5K_AR5212),
+       PCI_ROM(0x168c, 0x001a, "ath2413", "Atheros 2413 Griffin", AR5K_AR5212),
+       PCI_ROM(0x168c, 0x001b, "ath5413", "Atheros 5413 Eagle", AR5K_AR5212),
+       PCI_ROM(0x168c, 0x001c, "ath5212e", "Atheros 5212 PCI-E", AR5K_AR5212),
+       PCI_ROM(0x168c, 0x001d, "ath2417", "Atheros 2417 Nala", AR5K_AR5212),
+};
+
+/* Known SREVs */
+static const struct ath5k_srev_name srev_names[] = {
+       { "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 },
+       { "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 },
+};
+
+#define ATH5K_SPMBL_NO   1
+#define ATH5K_SPMBL_YES  2
+#define ATH5K_SPMBL_BOTH 3
+
+static const struct {
+       u16 bitrate;
+       u8 short_pmbl;
+       u8 hw_code;
+} ath5k_rates[] = {
+       { 10, ATH5K_SPMBL_BOTH, ATH5K_RATE_CODE_1M },
+       { 20, ATH5K_SPMBL_NO, ATH5K_RATE_CODE_2M },
+       { 55, ATH5K_SPMBL_NO, ATH5K_RATE_CODE_5_5M },
+       { 110, ATH5K_SPMBL_NO, ATH5K_RATE_CODE_11M },
+       { 60, ATH5K_SPMBL_BOTH, ATH5K_RATE_CODE_6M },
+       { 90, ATH5K_SPMBL_BOTH, ATH5K_RATE_CODE_9M },
+       { 120, ATH5K_SPMBL_BOTH, ATH5K_RATE_CODE_12M },
+       { 180, ATH5K_SPMBL_BOTH, ATH5K_RATE_CODE_18M },
+       { 240, ATH5K_SPMBL_BOTH, ATH5K_RATE_CODE_24M },
+       { 360, ATH5K_SPMBL_BOTH, ATH5K_RATE_CODE_36M },
+       { 480, ATH5K_SPMBL_BOTH, ATH5K_RATE_CODE_48M },
+       { 540, ATH5K_SPMBL_BOTH, ATH5K_RATE_CODE_54M },
+       { 20, ATH5K_SPMBL_YES, ATH5K_RATE_CODE_2M | AR5K_SET_SHORT_PREAMBLE },
+       { 55, ATH5K_SPMBL_YES, ATH5K_RATE_CODE_5_5M | AR5K_SET_SHORT_PREAMBLE },
+       { 110, ATH5K_SPMBL_YES, ATH5K_RATE_CODE_11M | AR5K_SET_SHORT_PREAMBLE },
+       { 0, 0, 0 },
+};
+
+#define ATH5K_NR_RATES 15
+
+/*
+ * Prototypes - PCI stack related functions
+ */
+static int             ath5k_probe(struct pci_device *pdev,
+                                   const struct pci_device_id *id);
+static void            ath5k_remove(struct pci_device *pdev);
+
+struct pci_driver ath5k_pci_driver __pci_driver = {
+       .ids            = ath5k_nics,
+       .id_count       = sizeof(ath5k_nics) / sizeof(ath5k_nics[0]),
+       .probe          = ath5k_probe,
+       .remove         = ath5k_remove,
+};
+
+
+
+/*
+ * Prototypes - MAC 802.11 stack related functions
+ */
+static int ath5k_tx(struct net80211_device *dev, struct io_buffer *skb);
+static int ath5k_reset(struct ath5k_softc *sc, struct net80211_channel *chan);
+static int ath5k_reset_wake(struct ath5k_softc *sc);
+static int ath5k_start(struct net80211_device *dev);
+static void ath5k_stop(struct net80211_device *dev);
+static int ath5k_config(struct net80211_device *dev, int changed);
+static void ath5k_poll(struct net80211_device *dev);
+static void ath5k_irq(struct net80211_device *dev, int enable);
+
+static struct net80211_device_operations ath5k_ops = {
+       .open           = ath5k_start,
+       .close          = ath5k_stop,
+       .transmit       = ath5k_tx,
+       .poll           = ath5k_poll,
+       .irq            = ath5k_irq,
+       .config         = ath5k_config,
+};
+
+/*
+ * Prototypes - Internal functions
+ */
+/* Attach detach */
+static int     ath5k_attach(struct net80211_device *dev);
+static void    ath5k_detach(struct net80211_device *dev);
+/* Channel/mode setup */
+static unsigned int ath5k_copy_channels(struct ath5k_hw *ah,
+                               struct net80211_channel *channels,
+                               unsigned int mode,
+                               unsigned int max);
+static int     ath5k_setup_bands(struct net80211_device *dev);
+static int     ath5k_chan_set(struct ath5k_softc *sc,
+                               struct net80211_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);
+static void    ath5k_desc_free(struct ath5k_softc *sc);
+/* Buffers setup */
+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);
+
+static inline void ath5k_txbuf_free(struct ath5k_softc *sc,
+                                   struct ath5k_buf *bf)
+{
+       if (!bf->iob)
+               return;
+
+       net80211_tx_complete(sc->dev, bf->iob, 0, ECANCELED);
+       bf->iob = NULL;
+}
+
+static inline void ath5k_rxbuf_free(struct ath5k_softc *sc __unused,
+                                   struct ath5k_buf *bf)
+{
+       free_iob(bf->iob);
+       bf->iob = NULL;
+}
+
+/* Queues setup */
+static int     ath5k_txq_setup(struct ath5k_softc *sc,
+                                          int qtype, int subtype);
+static void    ath5k_txq_drainq(struct ath5k_softc *sc,
+                                struct ath5k_txq *txq);
+static void    ath5k_txq_cleanup(struct ath5k_softc *sc);
+static void    ath5k_txq_release(struct ath5k_softc *sc);
+/* Rx handling */
+static int     ath5k_rx_start(struct ath5k_softc *sc);
+static void    ath5k_rx_stop(struct ath5k_softc *sc);
+/* Tx handling */
+static void    ath5k_tx_processq(struct ath5k_softc *sc,
+                                 struct ath5k_txq *txq);
+
+/* Interrupt handling */
+static int     ath5k_init(struct ath5k_softc *sc);
+static int     ath5k_stop_hw(struct ath5k_softc *sc);
+
+static void    ath5k_calibrate(struct ath5k_softc *sc);
+
+/* Filter */
+static void    ath5k_configure_filter(struct ath5k_softc *sc);
+
+/********************\
+* PCI Initialization *
+\********************/
+
+#if DBGLVL_MAX
+static const char *
+ath5k_chip_name(enum ath5k_srev_type type, u16 val)
+{
+       const char *name = "xxxxx";
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(srev_names); i++) {
+               if (srev_names[i].sr_type != type)
+                       continue;
+
+               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;
+               }
+       }
+
+       return name;
+}
+#endif
+
+static int ath5k_probe(struct pci_device *pdev,
+                      const struct pci_device_id *id)
+{
+       void *mem;
+       struct ath5k_softc *sc;
+       struct net80211_device *dev;
+       int ret;
+       u8 csz;
+
+       adjust_pci_device(pdev);
+
+       /*
+        * Cache line size is used to size and align various
+        * structures used to communicate with the hardware.
+        */
+       pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
+       if (csz == 0) {
+               /*
+                * We must have this setup properly for rx buffer
+                * DMA to work so force a reasonable value here if it
+                * comes up zero.
+                */
+               pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 16);
+       }
+       /*
+        * The default setting of latency timer yields poor results,
+        * set it to the value used by other systems.  It may be worth
+        * tweaking this setting more.
+        */
+       pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
+
+       /*
+        * Disable the RETRY_TIMEOUT register (0x41) to keep
+        * PCI Tx retries from interfering with C3 CPU state.
+        */
+       pci_write_config_byte(pdev, 0x41, 0);
+
+       mem = ioremap(pdev->membase, 0x10000);
+       if (!mem) {
+               DBG("ath5k: cannot remap PCI memory region\n");
+               ret = -EIO;
+               goto err;
+       }
+
+       /*
+        * Allocate dev (net80211 main struct)
+        * and dev->priv (driver private data)
+        */
+       dev = net80211_alloc(sizeof(*sc));
+       if (!dev) {
+               DBG("ath5k: cannot allocate 802.11 device\n");
+               ret = -ENOMEM;
+               goto err_map;
+       }
+
+       /* Initialize driver private data */
+       sc = dev->priv;
+       sc->dev = dev;
+       sc->pdev = pdev;
+
+       sc->hwinfo = zalloc(sizeof(*sc->hwinfo));
+       if (!sc->hwinfo) {
+               DBG("ath5k: cannot allocate 802.11 hardware info structure\n");
+               ret = -ENOMEM;
+               goto err_free;
+       }
+
+       sc->hwinfo->flags = NET80211_HW_RX_HAS_FCS;
+       sc->hwinfo->signal_type = NET80211_SIGNAL_DB;
+       sc->hwinfo->signal_max = 40; /* 35dB should give perfect 54Mbps */
+       sc->hwinfo->channel_change_time = 5000;
+
+       /* Avoid working with the device until setup is complete */
+       sc->status |= ATH_STAT_INVALID;
+
+       sc->iobase = mem;
+       sc->cachelsz = csz * 4; /* convert to bytes */
+
+       DBG("ath5k: register base at %p (%08lx)\n", sc->iobase, pdev->membase);
+       DBG("ath5k: cache line size %d\n", sc->cachelsz);
+
+       /* Set private data */
+       pci_set_drvdata(pdev, dev);
+       dev->netdev->dev = (struct device *)pdev;
+
+       /* Initialize device */
+       ret = ath5k_hw_attach(sc, id->driver_data, &sc->ah);
+       if (ret)
+               goto err_free_hwinfo;
+
+       /* Finish private driver data initialization */
+       ret = ath5k_attach(dev);
+       if (ret)
+               goto err_ah;
+
+#if DBGLVL_MAX
+       DBG("Atheros AR%s chip found (MAC: 0x%x, PHY: 0x%x)\n",
+           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) {
+               /* Single chip radio (!RF5111) */
+               if (sc->ah->ah_radio_5ghz_revision &&
+                   !sc->ah->ah_radio_2ghz_revision) {
+                       /* No 5GHz support -> report 2GHz radio */
+                       if (!(sc->ah->ah_capabilities.cap_mode & AR5K_MODE_BIT_11A)) {
+                               DBG("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 (!(sc->ah->ah_capabilities.cap_mode & AR5K_MODE_BIT_11B)) {
+                               DBG("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);
+                       /* Multiband radio */
+                       } else {
+                               DBG("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);
+                       }
+               }
+               /* Multi chip radio (RF5111 - RF2111) ->
+                * report both 2GHz/5GHz radios */
+               else if (sc->ah->ah_radio_5ghz_revision &&
+                        sc->ah->ah_radio_2ghz_revision) {
+                       DBG("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);
+                       DBG("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);
+               }
+       }
+#endif
+
+       /* Ready to go */
+       sc->status &= ~ATH_STAT_INVALID;
+
+       return 0;
+err_ah:
+       ath5k_hw_detach(sc->ah);
+err_free_hwinfo:
+       free(sc->hwinfo);
+err_free:
+       net80211_free(dev);
+err_map:
+       iounmap(mem);
+err:
+       return ret;
+}
+
+static void ath5k_remove(struct pci_device *pdev)
+{
+       struct net80211_device *dev = pci_get_drvdata(pdev);
+       struct ath5k_softc *sc = dev->priv;
+
+       ath5k_detach(dev);
+       ath5k_hw_detach(sc->ah);
+       iounmap(sc->iobase);
+       free(sc->hwinfo);
+       net80211_free(dev);
+}
+
+
+/***********************\
+* Driver Initialization *
+\***********************/
+
+static int
+ath5k_attach(struct net80211_device *dev)
+{
+       struct ath5k_softc *sc = dev->priv;
+       struct ath5k_hw *ah = sc->ah;
+       int ret;
+
+       /*
+        * 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_setup_bands(dev);
+       if (ret) {
+               DBG("ath5k: can't get channels\n");
+               goto err;
+       }
+
+       /* NB: setup here so ath5k_rate_update is happy */
+       if (ah->ah_modes & AR5K_MODE_BIT_11A)
+               ath5k_setcurmode(sc, AR5K_MODE_11A);
+       else
+               ath5k_setcurmode(sc, AR5K_MODE_11B);
+
+       /*
+        * Allocate tx+rx descriptors and populate the lists.
+        */
+       ret = ath5k_desc_alloc(sc);
+       if (ret) {
+               DBG("ath5k: can't allocate descriptors\n");
+               goto err;
+       }
+
+       /*
+        * Allocate hardware transmit queues. Note that hw functions
+        * handle reseting these queues at the needed time.
+        */
+       ret = ath5k_txq_setup(sc, AR5K_TX_QUEUE_DATA, AR5K_WME_AC_BE);
+       if (ret) {
+               DBG("ath5k: can't setup xmit queue\n");
+               goto err_desc;
+       }
+
+       sc->last_calib_ticks = currticks();
+
+       ret = ath5k_eeprom_read_mac(ah, sc->hwinfo->hwaddr);
+       if (ret) {
+               DBG("ath5k: unable to read address from EEPROM: 0x%04x\n",
+                   sc->pdev->device);
+               goto err_queues;
+       }
+
+       memset(sc->bssidmask, 0xff, ETH_ALEN);
+       ath5k_hw_set_bssid_mask(sc->ah, sc->bssidmask);
+
+       ret = net80211_register(sc->dev, &ath5k_ops, sc->hwinfo);
+       if (ret) {
+               DBG("ath5k: can't register ieee80211 hw\n");
+               goto err_queues;
+       }
+
+       return 0;
+err_queues:
+       ath5k_txq_release(sc);
+err_desc:
+       ath5k_desc_free(sc);
+err:
+       return ret;
+}
+
+static void
+ath5k_detach(struct net80211_device *dev)
+{
+       struct ath5k_softc *sc = dev->priv;
+
+       net80211_unregister(dev);
+       ath5k_desc_free(sc);
+       ath5k_txq_release(sc);
+}
+
+
+
+
+/********************\
+* Channel/mode setup *
+\********************/
+
+/*
+ * Convert IEEE channel number to MHz frequency.
+ */
+static inline short
+ath5k_ieee2mhz(short chan)
+{
+       if (chan < 14)
+               return 2407 + 5 * chan;
+       if (chan == 14)
+               return 2484;
+       if (chan < 27)
+               return 2212 + 20 * chan;
+       return 5000 + 5 * chan;
+}
+
+static unsigned int
+ath5k_copy_channels(struct ath5k_hw *ah,
+                   struct net80211_channel *channels,
+                   unsigned int mode, unsigned int max)
+{
+       unsigned int i, count, size, chfreq, freq, ch;
+
+       if (!(ah->ah_modes & (1 << mode)))
+               return 0;
+
+       switch (mode) {
+       case AR5K_MODE_11A:
+       case AR5K_MODE_11A_TURBO:
+               /* 1..220, but 2GHz frequencies are filtered by check_channel */
+               size = 220;
+               chfreq = CHANNEL_5GHZ;
+               break;
+       case AR5K_MODE_11B:
+       case AR5K_MODE_11G:
+       case AR5K_MODE_11G_TURBO:
+               size = 26;
+               chfreq = CHANNEL_2GHZ;
+               break;
+       default:
+               return 0;
+       }
+
+       for (i = 0, count = 0; i < size && max > 0; i++) {
+               ch = i + 1 ;
+               freq = ath5k_ieee2mhz(ch);
+
+               /* Check if channel is supported by the chipset */
+               if (!ath5k_channel_ok(ah, freq, chfreq))
+                       continue;
+
+               /* Write channel info and increment counter */
+               channels[count].center_freq = freq;
+               channels[count].maxpower = 0; /* use regulatory */
+               channels[count].band = (chfreq == CHANNEL_2GHZ) ?
+                       NET80211_BAND_2GHZ : NET80211_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;
+               }
+
+               count++;
+               max--;
+       }
+
+       return count;
+}
+
+static int
+ath5k_setup_bands(struct net80211_device *dev)
+{
+       struct ath5k_softc *sc = dev->priv;
+       struct ath5k_hw *ah = sc->ah;
+       int max_c, count_c = 0;
+       int i;
+       int band;
+
+       max_c = sizeof(sc->hwinfo->channels) / sizeof(sc->hwinfo->channels[0]);
+
+       /* 2GHz band */
+       if (sc->ah->ah_capabilities.cap_mode & AR5K_MODE_BIT_11G) {
+               /* G mode */
+               band = NET80211_BAND_2GHZ;
+               sc->hwinfo->bands = NET80211_BAND_BIT_2GHZ;
+               sc->hwinfo->modes = (NET80211_MODE_G | NET80211_MODE_B);
+
+               for (i = 0; i < 12; i++)
+                       sc->hwinfo->rates[band][i] = ath5k_rates[i].bitrate;
+               sc->hwinfo->nr_rates[band] = 12;
+
+               sc->hwinfo->nr_channels =
+                       ath5k_copy_channels(ah, sc->hwinfo->channels,
+                                           AR5K_MODE_11G, max_c);
+               count_c = sc->hwinfo->nr_channels;
+               max_c -= count_c;
+       } else if (sc->ah->ah_capabilities.cap_mode & AR5K_MODE_BIT_11B) {
+               /* B mode */
+               band = NET80211_BAND_2GHZ;
+               sc->hwinfo->bands = NET80211_BAND_BIT_2GHZ;
+               sc->hwinfo->modes = NET80211_MODE_B;
+
+               for (i = 0; i < 4; i++)
+                       sc->hwinfo->rates[band][i] = ath5k_rates[i].bitrate;
+               sc->hwinfo->nr_rates[band] = 4;
+
+               sc->hwinfo->nr_channels =
+                       ath5k_copy_channels(ah, sc->hwinfo->channels,
+                                           AR5K_MODE_11B, max_c);
+               count_c = sc->hwinfo->nr_channels;
+               max_c -= count_c;
+       }
+
+       /* 5GHz band, A mode */
+       if (sc->ah->ah_capabilities.cap_mode & AR5K_MODE_BIT_11A) {
+               band = NET80211_BAND_5GHZ;
+               sc->hwinfo->bands |= NET80211_BAND_BIT_5GHZ;
+               sc->hwinfo->modes |= NET80211_MODE_A;
+
+               for (i = 0; i < 8; i++)
+                       sc->hwinfo->rates[band][i] = ath5k_rates[i+4].bitrate;
+               sc->hwinfo->nr_rates[band] = 8;
+
+               sc->hwinfo->nr_channels =
+                       ath5k_copy_channels(ah, sc->hwinfo->channels,
+                                           AR5K_MODE_11B, max_c);
+               count_c = sc->hwinfo->nr_channels;
+               max_c -= count_c;
+       }
+
+       return 0;
+}
+
+/*
+ * Set/change channels.  If the channel is really being changed,
+ * 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.
+ */
+static int
+ath5k_chan_set(struct ath5k_softc *sc, struct net80211_channel *chan)
+{
+       if (chan->center_freq != sc->curchan->center_freq ||
+           chan->hw_value != sc->curchan->hw_value) {
+               /*
+                * 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.
+                */
+               DBG2("ath5k: resetting for channel change (%d -> %d MHz)\n",
+                    sc->curchan->center_freq, chan->center_freq);
+               return ath5k_reset(sc, chan);
+       }
+
+       return 0;
+}
+
+static void
+ath5k_setcurmode(struct ath5k_softc *sc, unsigned int mode)
+{
+       sc->curmode = mode;
+
+       if (mode == AR5K_MODE_11A) {
+               sc->curband = NET80211_BAND_5GHZ;
+       } else {
+               sc->curband = NET80211_BAND_2GHZ;
+       }
+}
+
+static void
+ath5k_mode_setup(struct ath5k_softc *sc)
+{
+       struct ath5k_hw *ah = sc->ah;
+       u32 rfilt;
+
+       /* configure rx filter */
+       rfilt = sc->filter_flags;
+       ath5k_hw_set_rx_filter(ah, rfilt);
+
+       if (ath5k_hw_hasbssidmask(ah))
+               ath5k_hw_set_bssid_mask(ah, sc->bssidmask);
+
+       /* configure operational mode */
+       ath5k_hw_set_opmode(ah);
+
+       ath5k_hw_set_mcast_filter(ah, 0, 0);
+}
+
+static inline int
+ath5k_hw_rix_to_bitrate(int hw_rix)
+{
+       int i;
+
+       for (i = 0; i < ATH5K_NR_RATES; i++) {
+               if (ath5k_rates[i].hw_code == hw_rix)
+                       return ath5k_rates[i].bitrate;
+       }
+
+       DBG("ath5k: invalid rix %02x\n", hw_rix);
+       return 10;              /* use lowest rate */
+}
+
+int ath5k_bitrate_to_hw_rix(int bitrate)
+{
+       int i;
+
+       for (i = 0; i < ATH5K_NR_RATES; i++) {
+               if (ath5k_rates[i].bitrate == bitrate)
+                       return ath5k_rates[i].hw_code;
+       }
+
+       DBG("ath5k: invalid bitrate %d\n", bitrate);
+       return ATH5K_RATE_CODE_1M; /* use lowest rate */
+}
+
+/***************\
+* Buffers setup *
+\***************/
+
+static struct io_buffer *
+ath5k_rx_iob_alloc(struct ath5k_softc *sc, u32 *iob_addr)
+{
+       struct io_buffer *iob;
+       unsigned int off;
+
+       /*
+        * Allocate buffer with headroom_needed space for the
+        * fake physical layer header at the start.
+        */
+       iob = alloc_iob(sc->rxbufsize + sc->cachelsz - 1);
+
+       if (!iob) {
+               DBG("ath5k: can't alloc iobuf of size %d\n",
+                   sc->rxbufsize + sc->cachelsz - 1);
+               return NULL;
+       }
+
+       *iob_addr = virt_to_bus(iob->data);
+
+       /*
+        * Cache-line-align.  This is important (for the
+        * 5210 at least) as not doing so causes bogus data
+        * in rx'd frames.
+        */
+       off = *iob_addr % sc->cachelsz;
+       if (off != 0) {
+               iob_reserve(iob, sc->cachelsz - off);
+               *iob_addr += sc->cachelsz - off;
+       }
+
+       return iob;
+}
+
+static int
+ath5k_rxbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
+{
+       struct ath5k_hw *ah = sc->ah;
+       struct io_buffer *iob = bf->iob;
+       struct ath5k_desc *ds;
+
+       if (!iob) {
+               iob = ath5k_rx_iob_alloc(sc, &bf->iobaddr);
+               if (!iob)
+                       return -ENOMEM;
+               bf->iob = iob;
+       }
+
+       /*
+        * Setup descriptors.  For receive we always terminate
+        * the descriptor list with a self-linked entry so we'll
+        * not get overrun under high load (as can happen with a
+        * 5212 when ANI processing enables PHY error frames).
+        *
+        * To insure the last descriptor is self-linked we create
+        * each descriptor as self-linked and add it to the end.  As
+        * each additional descriptor is added the previous self-linked
+        * entry is ``fixed'' naturally.  This should be safe even
+        * if DMA is happening.  When processing RX interrupts we
+        * never remove/process the last, self-linked, entry on the
+        * descriptor list.  This insures the hardware always has
+        * someplace to write a new frame.
+        */
+       ds = bf->desc;
+       ds->ds_link = bf->daddr;        /* link to self */
+       ds->ds_data = bf->iobaddr;
+       if (ah->ah_setup_rx_desc(ah, ds,
+                                iob_tailroom(iob),     /* buffer size */
+                                0) != 0) {
+               DBG("ath5k: error setting up RX descriptor for %d bytes\n", iob_tailroom(iob));
+               return -EINVAL;
+       }
+
+       if (sc->rxlink != NULL)
+               *sc->rxlink = bf->daddr;
+       sc->rxlink = &ds->ds_link;
+       return 0;
+}
+
+static int
+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 io_buffer *iob = bf->iob;
+       unsigned int pktlen, flags;
+       int ret;
+       u16 duration = 0;
+       u16 cts_rate = 0;
+
+       flags = AR5K_TXDESC_INTREQ | AR5K_TXDESC_CLRDMASK;
+       bf->iobaddr = virt_to_bus(iob->data);
+       pktlen = iob_len(iob);
+
+       /* FIXME: If we are in g mode and rate is a CCK rate
+        * subtract ah->ah_txpower.txp_cck_ofdm_pwr_delta
+        * from tx power (value is in dB units already) */
+       if (sc->dev->phy_flags & NET80211_PHY_USE_PROTECTION) {
+               struct net80211_device *dev = sc->dev;
+
+               flags |= AR5K_TXDESC_CTSENA;
+               cts_rate = sc->hw_rtscts_rate;
+               duration = net80211_cts_duration(dev, pktlen);
+       }
+       ret = ah->ah_setup_tx_desc(ah, ds, pktlen,
+                                  IEEE80211_TYP_FRAME_HEADER_LEN,
+                                  AR5K_PKT_TYPE_NORMAL, sc->power_level * 2,
+                                  sc->hw_rate, ATH5K_RETRIES,
+                                  AR5K_TXKEYIX_INVALID, 0, flags,
+                                  cts_rate, duration);
+       if (ret)
+               return ret;
+
+       ds->ds_link = 0;
+       ds->ds_data = bf->iobaddr;
+
+       list_add_tail(&bf->list, &txq->q);
+       if (txq->link == NULL) /* is this first packet? */
+               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_start_tx_dma(ah, txq->qnum);
+       mb();
+
+       return 0;
+}
+
+/*******************\
+* Descriptors setup *
+\*******************/
+
+static int
+ath5k_desc_alloc(struct ath5k_softc *sc)
+{
+       struct ath5k_desc *ds;
+       struct ath5k_buf *bf;
+       u32 da;
+       unsigned int i;
+       int ret;
+
+       /* allocate descriptors */
+       sc->desc_len = sizeof(struct ath5k_desc) * (ATH_TXBUF + ATH_RXBUF + 1);
+       sc->desc = malloc_dma(sc->desc_len, ATH5K_DESC_ALIGN);
+       if (sc->desc == NULL) {
+               DBG("ath5k: can't allocate descriptors\n");
+               ret = -ENOMEM;
+               goto err;
+       }
+       memset(sc->desc, 0, sc->desc_len);
+       sc->desc_daddr = virt_to_bus(sc->desc);
+
+       ds = sc->desc;
+       da = sc->desc_daddr;
+
+       bf = calloc(ATH_TXBUF + ATH_RXBUF + 1, sizeof(struct ath5k_buf));
+       if (bf == NULL) {
+               DBG("ath5k: can't allocate buffer pointers\n");
+               ret = -ENOMEM;
+               goto err_free;
+       }
+       sc->bufptr = bf;
+
+       INIT_LIST_HEAD(&sc->rxbuf);
+       for (i = 0; i < ATH_RXBUF; i++, bf++, ds++, da += sizeof(*ds)) {
+               bf->desc = ds;
+               bf->daddr = da;
+               list_add_tail(&bf->list, &sc->rxbuf);
+       }
+
+       INIT_LIST_HEAD(&sc->txbuf);
+       sc->txbuf_len = ATH_TXBUF;
+       for (i = 0; i < ATH_TXBUF; i++, bf++, ds++, da += sizeof(*ds)) {
+               bf->desc = ds;
+               bf->daddr = da;
+               list_add_tail(&bf->list, &sc->txbuf);
+       }
+
+       return 0;
+
+err_free:
+       free_dma(sc->desc, sc->desc_len);
+err:
+       sc->desc = NULL;
+       return ret;
+}
+
+static void
+ath5k_desc_free(struct ath5k_softc *sc)
+{
+       struct ath5k_buf *bf;
+
+       list_for_each_entry(bf, &sc->txbuf, list)
+               ath5k_txbuf_free(sc, bf);
+       list_for_each_entry(bf, &sc->rxbuf, list)
+               ath5k_rxbuf_free(sc, bf);
+
+       /* Free memory associated with all descriptors */
+       free_dma(sc->desc, sc->desc_len);
+
+       free(sc->bufptr);
+       sc->bufptr = NULL;
+}
+
+
+
+
+
+/**************\
+* Queues setup *
+\**************/
+
+static int
+ath5k_txq_setup(struct ath5k_softc *sc, int qtype, int subtype)
+{
+       struct ath5k_hw *ah = sc->ah;
+       struct ath5k_txq *txq;
+       struct ath5k_txq_info qi = {
+               .tqi_subtype = subtype,
+               .tqi_aifs = AR5K_TXQ_USEDEFAULT,
+               .tqi_cw_min = AR5K_TXQ_USEDEFAULT,
+               .tqi_cw_max = AR5K_TXQ_USEDEFAULT
+       };
+       int qnum;
+
+       /*
+        * Enable interrupts only for EOL and DESC conditions.
+        * We mark tx descriptors to receive a DESC interrupt
+        * when a tx queue gets deep; otherwise waiting for the
+        * EOL to reap descriptors.  Note that this is done to
+        * reduce interrupt load and this only defers reaping
+        * descriptors, never transmitting frames.  Aside from
+        * reducing interrupts this also permits more concurrency.
+        * The only potential downside is if the tx queue backs
+        * up in which case the top half of the kernel may backup
+        * due to a lack of tx descriptors.
+        */
+       qi.tqi_flags = AR5K_TXQ_FLAG_TXEOLINT_ENABLE |
+                               AR5K_TXQ_FLAG_TXDESCINT_ENABLE;
+       qnum = ath5k_hw_setup_tx_queue(ah, qtype, &qi);
+       if (qnum < 0) {
+               DBG("ath5k: can't set up a TX queue\n");
+               return -EIO;
+       }
+
+       txq = &sc->txq;
+       if (!txq->setup) {
+               txq->qnum = qnum;
+               txq->link = NULL;
+               INIT_LIST_HEAD(&txq->q);
+               txq->setup = 1;
+       }
+       return 0;
+}
+
+static void
+ath5k_txq_drainq(struct ath5k_softc *sc, struct ath5k_txq *txq)
+{
+       struct ath5k_buf *bf, *bf0;
+
+       list_for_each_entry_safe(bf, bf0, &txq->q, list) {
+               ath5k_txbuf_free(sc, bf);
+
+               list_del(&bf->list);
+               list_add_tail(&bf->list, &sc->txbuf);
+               sc->txbuf_len++;
+       }
+       txq->link = NULL;
+}
+
+/*
+ * Drain the transmit queues and reclaim resources.
+ */
+static void
+ath5k_txq_cleanup(struct ath5k_softc *sc)
+{
+       struct ath5k_hw *ah = sc->ah;
+
+       if (!(sc->status & ATH_STAT_INVALID)) {
+               /* don't touch the hardware if marked invalid */
+               if (sc->txq.setup) {
+                       ath5k_hw_stop_tx_dma(ah, sc->txq.qnum);
+                       DBG("ath5k: txq [%d] %x, link %p\n",
+                           sc->txq.qnum,
+                           ath5k_hw_get_txdp(ah, sc->txq.qnum),
+                           sc->txq.link);
+               }
+       }
+
+       if (sc->txq.setup)
+               ath5k_txq_drainq(sc, &sc->txq);
+}
+
+static void
+ath5k_txq_release(struct ath5k_softc *sc)
+{
+       if (sc->txq.setup) {
+               ath5k_hw_release_tx_queue(sc->ah);
+               sc->txq.setup = 0;
+       }
+}
+
+
+
+
+/*************\
+* RX Handling *
+\*************/
+
+/*
+ * Enable the receive h/w following a reset.
+ */
+static int
+ath5k_rx_start(struct ath5k_softc *sc)
+{
+       struct ath5k_hw *ah = sc->ah;
+       struct ath5k_buf *bf;
+       int ret;
+
+       sc->rxbufsize = IEEE80211_MAX_LEN;
+       if (sc->rxbufsize % sc->cachelsz != 0)
+               sc->rxbufsize += sc->cachelsz - (sc->rxbufsize % sc->cachelsz);
+
+       sc->rxlink = NULL;
+
+       list_for_each_entry(bf, &sc->rxbuf, list) {
+               ret = ath5k_rxbuf_setup(sc, bf);
+               if (ret != 0)
+                       return ret;
+       }
+
+       bf = list_entry(sc->rxbuf.next, struct ath5k_buf, list);
+
+       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 */
+
+       return 0;
+}
+
+/*
+ * Disable the receive h/w in preparation for a reset.
+ */
+static void
+ath5k_rx_stop(struct ath5k_softc *sc)
+{
+       struct ath5k_hw *ah = sc->ah;
+
+       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 */
+
+       sc->rxlink = NULL;              /* just in case */
+}
+
+static void
+ath5k_handle_rx(struct ath5k_softc *sc)
+{
+       struct ath5k_rx_status rs;
+       struct io_buffer *iob, *next_iob;
+       u32 next_iob_addr;
+       struct ath5k_buf *bf, *bf_last;
+       struct ath5k_desc *ds;
+       int ret;
+
+       memset(&rs, 0, sizeof(rs));
+
+       if (list_empty(&sc->rxbuf)) {
+               DBG("ath5k: empty rx buf pool\n");
+               return;
+       }
+
+       bf_last = list_entry(sc->rxbuf.prev, struct ath5k_buf, list);
+
+       do {
+               bf = list_entry(sc->rxbuf.next, struct ath5k_buf, list);
+               assert(bf->iob != NULL);
+               iob = bf->iob;
+               ds = bf->desc;
+
+               /*
+                * 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, &rs);
+               if (ret) {
+                       if (ret != -EINPROGRESS) {
+                               DBG("ath5k: error in processing rx desc: %s\n",
+                                   strerror(ret));
+                               net80211_rx_err(sc->dev, NULL, -ret);
+                       } else {
+                               /* normal return, reached end of
+                                  available descriptors */
+                       }
+                       return;
+               }
+
+               if (rs.rs_more) {
+                       DBG("ath5k: unsupported fragmented rx\n");
+                       goto next;
+               }
+
+               if (rs.rs_status) {
+                       if (rs.rs_status & AR5K_RXERR_PHY) {
+                               DBG("ath5k: rx PHY error\n");
+                               goto next;
+                       }
+                       if (rs.rs_status & AR5K_RXERR_CRC) {
+                               net80211_rx_err(sc->dev, NULL, EIO);
+                               goto next;
+                       }
+                       if (rs.rs_status & AR5K_RXERR_DECRYPT) {
+                               /*
+                                * Decrypt error.  If the error occurred
+                                * because there was no hardware key, then
+                                * let the frame through so the upper layers
+                                * can process it.  This is necessary for 5210
+                                * parts which have no way to setup a ``clear''
+                                * key cache entry.
+                                *
+                                * XXX do key cache faulting
+                                */
+                               if (rs.rs_keyix == AR5K_RXKEYIX_INVALID &&
+                                   !(rs.rs_status & AR5K_RXERR_CRC))
+                                       goto accept;
+                       }
+
+                       /* any other error, unhandled */
+                       DBG("ath5k: packet rx status %x\n", rs.rs_status);
+                       goto next;
+               }
+accept:
+               next_iob = ath5k_rx_iob_alloc(sc, &next_iob_addr);
+
+               /*
+                * If we can't replace bf->iob with a new iob under memory
+                * pressure, just skip this packet
+                */
+               if (!next_iob) {
+                       DBG("ath5k: dropping packet under memory pressure\n");
+                       goto next;
+               }
+
+               iob_put(iob, rs.rs_datalen);
+
+               /* The MAC header is padded to have 32-bit boundary if the
+                * packet payload is non-zero. However, gPXE only
+                * supports standard 802.11 packets with 24-byte
+                * header, so no padding correction should be needed.
+                */
+
+               DBG2("ath5k: rx %d bytes, signal %d\n", rs.rs_datalen,
+                    rs.rs_rssi);
+
+               net80211_rx(sc->dev, iob, rs.rs_rssi,
+                           ath5k_hw_rix_to_bitrate(rs.rs_rate));
+
+               bf->iob = next_iob;
+               bf->iobaddr = next_iob_addr;
+next:
+               list_del(&bf->list);
+               list_add_tail(&bf->list, &sc->rxbuf);
+       } while (ath5k_rxbuf_setup(sc, bf) == 0);
+}
+
+
+
+
+/*************\
+* TX Handling *
+\*************/
+
+static void
+ath5k_tx_processq(struct ath5k_softc *sc, struct ath5k_txq *txq)
+{
+       struct ath5k_tx_status ts;
+       struct ath5k_buf *bf, *bf0;
+       struct ath5k_desc *ds;
+       struct io_buffer *iob;
+       int ret;
+
+       memset(&ts, 0, sizeof(ts));
+
+       list_for_each_entry_safe(bf, bf0, &txq->q, list) {
+               ds = bf->desc;
+
+               ret = sc->ah->ah_proc_tx_desc(sc->ah, ds, &ts);
+               if (ret) {
+                       if (ret != -EINPROGRESS) {
+                               DBG("ath5k: error in processing tx desc: %s\n",
+                                   strerror(ret));
+                       } else {
+                               /* normal return, reached end of tx completions */
+                       }
+                       break;
+               }
+
+               iob = bf->iob;
+               bf->iob = NULL;
+
+               DBG2("ath5k: tx %d bytes complete, %d retries\n",
+                    iob_len(iob), ts.ts_retry[0]);
+
+               net80211_tx_complete(sc->dev, iob, ts.ts_retry[0],
+                                    ts.ts_status ? EIO : 0);
+
+               list_del(&bf->list);
+               list_add_tail(&bf->list, &sc->txbuf);
+               sc->txbuf_len++;
+       }
+
+       if (list_empty(&txq->q))
+               txq->link = NULL;
+}
+
+static void
+ath5k_handle_tx(struct ath5k_softc *sc)
+{
+       ath5k_tx_processq(sc, &sc->txq);
+}
+
+
+/********************\
+* Interrupt handling *
+\********************/
+
+static void
+ath5k_irq(struct net80211_device *dev, int enable)
+{
+       struct ath5k_softc *sc = dev->priv;
+       struct ath5k_hw *ah = sc->ah;
+
+       sc->irq_ena = enable;
+       ah->ah_ier = enable ? AR5K_IER_ENABLE : AR5K_IER_DISABLE;
+
+       ath5k_hw_reg_write(ah, ah->ah_ier, AR5K_IER);
+       ath5k_hw_set_imr(ah, sc->imask);
+}
+
+static int
+ath5k_init(struct ath5k_softc *sc)
+{
+       struct ath5k_hw *ah = sc->ah;
+       int ret, i;
+
+       /*
+        * Stop anything previously setup.  This is safe
+        * no matter this is the first time through or not.
+        */
+       ath5k_stop_hw(sc);
+
+       /*
+        * The basic interface to setting the hardware in a good
+        * state is ``reset''.  On return the hardware is known to
+        * be powered up and with interrupts disabled.  This must
+        * be followed by initialization of the appropriate bits
+        * and then setup of the interrupt mask.
+        */
+       sc->curchan = sc->dev->channels + sc->dev->channel;
+       sc->curband = 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;
+       ret = ath5k_reset(sc, NULL);
+       if (ret)
+               goto done;
+
+       /*
+        * Reset the key cache since some parts do not reset the
+        * contents on initial power up or resume from suspend.
+        */
+       for (i = 0; i < AR5K_KEYTABLE_SIZE; i++)
+               ath5k_hw_reset_key(ah, i);
+
+       /* Set ack to be sent at low bit-rates */
+       ath5k_hw_set_ack_bitrate_high(ah, 0);
+
+       ret = 0;
+done:
+       mb();
+       return ret;
+}
+
+static int
+ath5k_stop_hw(struct ath5k_softc *sc)
+{
+       struct ath5k_hw *ah = sc->ah;
+
+       /*
+        * Shutdown the hardware and driver:
+        *    stop output from above
+        *    disable interrupts
+        *    turn off timers
+        *    turn off the radio
+        *    clear transmit machinery
+        *    clear receive machinery
+        *    drain and release tx queues
+        *    reclaim beacon resources
+        *    power down hardware
+        *
+        * Note that some of this work is not possible if the
+        * hardware is gone (invalid).
+        */
+
+       if (!(sc->status & ATH_STAT_INVALID)) {
+               ath5k_hw_set_imr(ah, 0);
+       }
+       ath5k_txq_cleanup(sc);
+       if (!(sc->status & ATH_STAT_INVALID)) {
+               ath5k_rx_stop(sc);
+               ath5k_hw_phy_disable(ah);
+       } else
+               sc->rxlink = NULL;
+
+       return 0;
+}
+
+static void
+ath5k_poll(struct net80211_device *dev)
+{
+       struct ath5k_softc *sc = dev->priv;
+       struct ath5k_hw *ah = sc->ah;
+       enum ath5k_int status;
+       unsigned int counter = 1000;
+
+       if (currticks() - sc->last_calib_ticks >
+           ATH5K_CALIB_INTERVAL * ticks_per_sec()) {
+               ath5k_calibrate(sc);
+               sc->last_calib_ticks = currticks();
+       }
+
+       if ((sc->status & ATH_STAT_INVALID) ||
+           (sc->irq_ena && !ath5k_hw_is_intr_pending(ah)))
+               return;
+
+       do {
+               ath5k_hw_get_isr(ah, &status);          /* NB: clears IRQ too */
+               DBGP("ath5k: status %#x/%#x\n", status, sc->imask);
+               if (status & AR5K_INT_FATAL) {
+                       /*
+                        * Fatal errors are unrecoverable.
+                        * Typically these are caused by DMA errors.
+                        */
+                       DBG("ath5k: fatal error, resetting\n");
+                       ath5k_reset_wake(sc);
+               } else if (status & AR5K_INT_RXORN) {
+                       DBG("ath5k: rx overrun, resetting\n");
+                       ath5k_reset_wake(sc);
+               } else {
+                       if (status & AR5K_INT_RXEOL) {
+                               /*
+                                * NB: the hardware should re-read the link when
+                                *     RXE bit is written, but it doesn't work at
+                                *     least on older hardware revs.
+                                */
+                               DBG("ath5k: rx EOL\n");
+                               sc->rxlink = NULL;
+                       }
+                       if (status & AR5K_INT_TXURN) {
+                               /* bump tx trigger level */
+                               DBG("ath5k: tx underrun\n");
+                               ath5k_hw_update_tx_triglevel(ah, 1);
+                       }
+                       if (status & (AR5K_INT_RXOK | AR5K_INT_RXERR))
+                               ath5k_handle_rx(sc);
+                       if (status & (AR5K_INT_TXOK | AR5K_INT_TXDESC
+                                     | AR5K_INT_TXERR | AR5K_INT_TXEOL))
+                               ath5k_handle_tx(sc);
+               }
+       } while (ath5k_hw_is_intr_pending(ah) && counter-- > 0);
+
+       if (!counter)
+               DBG("ath5k: too many interrupts, giving up for now\n");
+}
+
+/*
+ * Periodically recalibrate the PHY to account
+ * for temperature/environment changes.
+ */
+static void
+ath5k_calibrate(struct ath5k_softc *sc)
+{
+       struct ath5k_hw *ah = sc->ah;
+
+       if (ath5k_hw_gainf_calibrate(ah) == AR5K_RFGAIN_NEED_CHANGE) {
+               /*
+                * Rfgain is out of bounds, reset the chip
+                * to load new gain values.
+                */
+               DBG("ath5k: resetting for calibration\n");
+               ath5k_reset_wake(sc);
+       }
+       if (ath5k_hw_phy_calibrate(ah, sc->curchan))
+               DBG("ath5k: calibration of channel %d failed\n",
+                   sc->curchan->channel_nr);
+}
+
+
+/********************\
+* Net80211 functions *
+\********************/
+
+static int
+ath5k_tx(struct net80211_device *dev, struct io_buffer *iob)
+{
+       struct ath5k_softc *sc = dev->priv;
+       struct ath5k_buf *bf;
+       int rc;
+
+       /*
+        * The hardware expects the header padded to 4 byte boundaries.
+        * gPXE only ever sends 24-byte headers, so no action necessary.
+        */
+
+       if (list_empty(&sc->txbuf)) {
+               DBG("ath5k: dropping packet because no tx bufs available\n");
+               return -ENOBUFS;
+       }
+
+       bf = list_entry(sc->txbuf.next, struct ath5k_buf, list);
+       list_del(&bf->list);
+       sc->txbuf_len--;
+
+       bf->iob = iob;
+
+       if ((rc = ath5k_txbuf_setup(sc, bf)) != 0) {
+               bf->iob = NULL;
+               list_add_tail(&bf->list, &sc->txbuf);
+               sc->txbuf_len++;
+               return rc;
+       }
+       return 0;
+}
+
+/*
+ * Reset the hardware.  If chan is not NULL, then also pause rx/tx
+ * and change to the given channel.
+ */
+static int
+ath5k_reset(struct ath5k_softc *sc, struct net80211_channel *chan)
+{
+       struct ath5k_hw *ah = sc->ah;
+       int ret;
+
+       if (chan) {
+               ath5k_hw_set_imr(ah, 0);
+               ath5k_txq_cleanup(sc);
+               ath5k_rx_stop(sc);
+
+               sc->curchan = chan;
+               sc->curband = chan->band;
+       }
+
+       ret = ath5k_hw_reset(ah, sc->curchan, 1);
+       if (ret) {
+               DBG("ath5k: can't reset hardware: %s\n", strerror(ret));
+               return ret;
+       }
+
+       ret = ath5k_rx_start(sc);
+       if (ret) {
+               DBG("ath5k: can't start rx logic: %s\n", strerror(ret));
+               return ret;
+       }
+
+       /*
+        * 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); */
+
+       /* Reenable interrupts if necessary */
+       ath5k_irq(sc->dev, sc->irq_ena);
+
+       return 0;
+}
+
+static int ath5k_reset_wake(struct ath5k_softc *sc)
+{
+       return ath5k_reset(sc, sc->curchan);
+}
+
+static int ath5k_start(struct net80211_device *dev)
+{
+       struct ath5k_softc *sc = dev->priv;
+       int ret;
+
+       if ((ret = ath5k_init(sc)) != 0)
+               return ret;
+
+       sc->assoc = 0;
+       ath5k_configure_filter(sc);
+       ath5k_hw_set_lladdr(sc->ah, dev->netdev->ll_addr);
+
+       return 0;
+}
+
+static void ath5k_stop(struct net80211_device *dev)
+{
+       struct ath5k_softc *sc = dev->priv;
+       u8 mac[ETH_ALEN] = {};
+
+       ath5k_hw_set_lladdr(sc->ah, mac);
+
+       ath5k_stop_hw(sc);
+}
+
+static int
+ath5k_config(struct net80211_device *dev, int changed)
+{
+       struct ath5k_softc *sc = dev->priv;
+       struct ath5k_hw *ah = sc->ah;
+       struct net80211_channel *chan = &dev->channels[dev->channel];
+       int ret;
+
+       if (changed & NET80211_CFG_CHANNEL) {
+               sc->power_level = chan->maxpower;
+               if ((ret = ath5k_chan_set(sc, chan)) != 0)
+                       return ret;
+       }
+
+       if ((changed & NET80211_CFG_RATE) ||
+           (changed & NET80211_CFG_PHY_PARAMS)) {
+               int spmbl = ATH5K_SPMBL_NO;
+               u16 rate = dev->rates[dev->rate];
+               u16 slowrate = dev->rates[dev->rtscts_rate];
+               int i;
+
+               if (dev->phy_flags & NET80211_PHY_USE_SHORT_PREAMBLE)
+                       spmbl = ATH5K_SPMBL_YES;
+
+               for (i = 0; i < ATH5K_NR_RATES; i++) {
+                       if (ath5k_rates[i].bitrate == rate &&
+                           (ath5k_rates[i].short_pmbl & spmbl))
+                               sc->hw_rate = ath5k_rates[i].hw_code;
+
+                       if (ath5k_rates[i].bitrate == slowrate &&
+                           (ath5k_rates[i].short_pmbl & spmbl))
+                               sc->hw_rtscts_rate = ath5k_rates[i].hw_code;
+               }
+       }
+
+       if (changed & NET80211_CFG_ASSOC) {
+               sc->assoc = !!(dev->state & NET80211_ASSOCIATED);
+               if (sc->assoc) {
+                       memcpy(ah->ah_bssid, dev->bssid, ETH_ALEN);
+               } else {
+                       memset(ah->ah_bssid, 0xff, ETH_ALEN);
+               }
+               ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
+       }
+
+       return 0;
+}
+
+/*
+ * o always accept unicast, broadcast, and multicast traffic
+ * o multicast traffic for all BSSIDs will be enabled if mac80211
+ *   says it should be
+ * o maintain current state of phy ofdm or phy cck error reception.
+ *   If the hardware detects any of these type of errors then
+ *   ath5k_hw_get_rx_filter() will pass to us the respective
+ *   hardware filters to be able to receive these type of frames.
+ * o probe request frames are accepted only when operating in
+ *   hostap, adhoc, or monitor modes
+ * o enable promiscuous mode according to the interface state
+ * o accept beacons:
+ *   - when operating in adhoc mode so the 802.11 layer creates
+ *     node table entries for peers,
+ *   - when operating in station mode for collecting rssi data when
+ *     the station is otherwise quiet, or
+ *   - when scanning
+ */
+static void ath5k_configure_filter(struct ath5k_softc *sc)
+{
+       struct ath5k_hw *ah = sc->ah;
+       u32 mfilt[2], rfilt;
+
+       /* Enable all multicast */
+       mfilt[0] = ~0;
+       mfilt[1] = ~0;
+
+       /* Enable data frames and beacons */
+       rfilt = (AR5K_RX_FILTER_UCAST | AR5K_RX_FILTER_BCAST |
+                AR5K_RX_FILTER_MCAST | AR5K_RX_FILTER_BEACON);
+
+       /* Set filters */
+       ath5k_hw_set_rx_filter(ah, rfilt);
+
+       /* Set multicast bits */
+       ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
+
+       /* Set the cached hw filter flags, this will alter actually
+        * be set in HW */
+       sc->filter_flags = rfilt;
+}
diff --git a/src/drivers/net/ath5k/ath5k.h b/src/drivers/net/ath5k/ath5k.h
new file mode 100644 (file)
index 0000000..c79fbec
--- /dev/null
@@ -0,0 +1,1275 @@
+/*
+ * Copyright (c) 2004-2007 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2007 Nick Kossifidis <mickflemm@gmail.com>
+ *
+ * Modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>
+ * Original from Linux kernel 2.6.30.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _ATH5K_H
+#define _ATH5K_H
+
+FILE_LICENCE ( MIT );
+
+#include <stddef.h>
+#include <byteswap.h>
+#include <gpxe/io.h>
+#include <gpxe/netdevice.h>
+#include <gpxe/net80211.h>
+#include <errno.h>
+
+/* Keep all ath5k files under one errfile ID */
+#undef ERRFILE
+#define ERRFILE ERRFILE_ath5k
+
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
+
+/* RX/TX descriptor hw structs */
+#include "desc.h"
+
+/* EEPROM structs/offsets */
+#include "eeprom.h"
+
+/* PCI IDs */
+#define PCI_DEVICE_ID_ATHEROS_AR5210           0x0007 /* AR5210 */
+#define PCI_DEVICE_ID_ATHEROS_AR5311           0x0011 /* AR5311 */
+#define PCI_DEVICE_ID_ATHEROS_AR5211           0x0012 /* AR5211 */
+#define PCI_DEVICE_ID_ATHEROS_AR5212           0x0013 /* AR5212 */
+#define PCI_DEVICE_ID_3COM_3CRDAG675           0x0013 /* 3CRDAG675 (Atheros AR5212) */
+#define PCI_DEVICE_ID_3COM_2_3CRPAG175                 0x0013 /* 3CRPAG175 (Atheros AR5212) */
+#define PCI_DEVICE_ID_ATHEROS_AR5210_AP        0x0207 /* AR5210 (Early) */
+#define PCI_DEVICE_ID_ATHEROS_AR5212_IBM       0x1014 /* AR5212 (IBM MiniPCI) */
+#define PCI_DEVICE_ID_ATHEROS_AR5210_DEFAULT   0x1107 /* AR5210 (no eeprom) */
+#define PCI_DEVICE_ID_ATHEROS_AR5212_DEFAULT   0x1113 /* AR5212 (no eeprom) */
+#define PCI_DEVICE_ID_ATHEROS_AR5211_DEFAULT   0x1112 /* AR5211 (no eeprom) */
+#define PCI_DEVICE_ID_ATHEROS_AR5212_FPGA      0xf013 /* AR5212 (emulation board) */
+#define PCI_DEVICE_ID_ATHEROS_AR5211_LEGACY    0xff12 /* AR5211 (emulation board) */
+#define PCI_DEVICE_ID_ATHEROS_AR5211_FPGA11B   0xf11b /* AR5211 (emulation board) */
+#define PCI_DEVICE_ID_ATHEROS_AR5312_REV2      0x0052 /* AR5312 WMAC (AP31) */
+#define PCI_DEVICE_ID_ATHEROS_AR5312_REV7      0x0057 /* AR5312 WMAC (AP30-040) */
+#define PCI_DEVICE_ID_ATHEROS_AR5312_REV8      0x0058 /* AR5312 WMAC (AP43-030) */
+#define PCI_DEVICE_ID_ATHEROS_AR5212_0014      0x0014 /* AR5212 compatible */
+#define PCI_DEVICE_ID_ATHEROS_AR5212_0015      0x0015 /* AR5212 compatible */
+#define PCI_DEVICE_ID_ATHEROS_AR5212_0016      0x0016 /* AR5212 compatible */
+#define PCI_DEVICE_ID_ATHEROS_AR5212_0017      0x0017 /* AR5212 compatible */
+#define PCI_DEVICE_ID_ATHEROS_AR5212_0018      0x0018 /* AR5212 compatible */
+#define PCI_DEVICE_ID_ATHEROS_AR5212_0019      0x0019 /* AR5212 compatible */
+#define PCI_DEVICE_ID_ATHEROS_AR2413           0x001a /* AR2413 (Griffin-lite) */
+#define PCI_DEVICE_ID_ATHEROS_AR5413           0x001b /* AR5413 (Eagle) */
+#define PCI_DEVICE_ID_ATHEROS_AR5424           0x001c /* AR5424 (Condor PCI-E) */
+#define PCI_DEVICE_ID_ATHEROS_AR5416           0x0023 /* AR5416 */
+#define PCI_DEVICE_ID_ATHEROS_AR5418           0x0024 /* AR5418 */
+
+/****************************\
+  GENERIC DRIVER DEFINITIONS
+\****************************/
+
+/*
+ * AR5K REGISTER ACCESS
+ */
+
+/* Some macros to read/write fields */
+
+/* First shift, then mask */
+#define AR5K_REG_SM(_val, _flags)                                      \
+       (((_val) << _flags##_S) & (_flags))
+
+/* First mask, then shift */
+#define AR5K_REG_MS(_val, _flags)                                      \
+       (((_val) & (_flags)) >> _flags##_S)
+
+/* Some registers can hold multiple values of interest. For this
+ * reason when we want to write to these registers we must first
+ * retrieve the values which we do not want to clear (lets call this
+ * old_data) and then set the register with this and our new_value:
+ * ( old_data | new_value) */
+#define AR5K_REG_WRITE_BITS(ah, _reg, _flags, _val)                    \
+       ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, _reg) & ~(_flags)) | \
+           (((_val) << _flags##_S) & (_flags)), _reg)
+
+#define AR5K_REG_MASKED_BITS(ah, _reg, _flags, _mask)                  \
+       ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, _reg) &           \
+                       (_mask)) | (_flags), _reg)
+
+#define AR5K_REG_ENABLE_BITS(ah, _reg, _flags)                         \
+       ath5k_hw_reg_write(ah, ath5k_hw_reg_read(ah, _reg) | (_flags), _reg)
+
+#define AR5K_REG_DISABLE_BITS(ah, _reg, _flags)                        \
+       ath5k_hw_reg_write(ah, ath5k_hw_reg_read(ah, _reg) & ~(_flags), _reg)
+
+/* Access to PHY registers */
+#define AR5K_PHY_READ(ah, _reg)                                        \
+       ath5k_hw_reg_read(ah, (ah)->ah_phy + ((_reg) << 2))
+
+#define AR5K_PHY_WRITE(ah, _reg, _val)                                 \
+       ath5k_hw_reg_write(ah, _val, (ah)->ah_phy + ((_reg) << 2))
+
+/* Access QCU registers per queue */
+#define AR5K_REG_READ_Q(ah, _reg, _queue)                              \
+       (ath5k_hw_reg_read(ah, _reg) & (1 << _queue))                   \
+
+#define AR5K_REG_WRITE_Q(ah, _reg, _queue)                             \
+       ath5k_hw_reg_write(ah, (1 << _queue), _reg)
+
+#define AR5K_Q_ENABLE_BITS(_reg, _queue) do {                          \
+       _reg |= 1 << _queue;                                            \
+} while (0)
+
+#define AR5K_Q_DISABLE_BITS(_reg, _queue) do {                         \
+       _reg &= ~(1 << _queue);                                         \
+} while (0)
+
+/* Used while writing initvals */
+#define AR5K_REG_WAIT(_i) do {                                         \
+       if (_i % 64)                                                    \
+               udelay(1);                                              \
+} while (0)
+
+/* Register dumps are done per operation mode */
+#define AR5K_INI_RFGAIN_5GHZ           0
+#define AR5K_INI_RFGAIN_2GHZ           1
+
+/* TODO: Clean this up */
+#define AR5K_INI_VAL_11A               0
+#define AR5K_INI_VAL_11A_TURBO         1
+#define AR5K_INI_VAL_11B               2
+#define AR5K_INI_VAL_11G               3
+#define AR5K_INI_VAL_11G_TURBO         4
+#define AR5K_INI_VAL_XR                        0
+#define AR5K_INI_VAL_MAX               5
+
+/* Used for BSSID etc manipulation */
+#define AR5K_LOW_ID(_a)(                               \
+(_a)[0] | (_a)[1] << 8 | (_a)[2] << 16 | (_a)[3] << 24 \
+)
+
+#define AR5K_HIGH_ID(_a)       ((_a)[4] | (_a)[5] << 8)
+
+#define IEEE80211_MAX_LEN      2352
+
+/*
+ * Some tuneable values (these should be changeable by the user)
+ */
+#define AR5K_TUNE_DMA_BEACON_RESP              2
+#define AR5K_TUNE_SW_BEACON_RESP               10
+#define AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF      0
+#define AR5K_TUNE_RADAR_ALERT                  0
+#define AR5K_TUNE_MIN_TX_FIFO_THRES            1
+#define AR5K_TUNE_MAX_TX_FIFO_THRES            ((IEEE80211_MAX_LEN / 64) + 1)
+#define AR5K_TUNE_REGISTER_TIMEOUT             20000
+/* Register for RSSI threshold has a mask of 0xff, so 255 seems to
+ * be the max value. */
+#define AR5K_TUNE_RSSI_THRES                   129
+/* This must be set when setting the RSSI threshold otherwise it can
+ * prevent a reset. If AR5K_RSSI_THR is read after writing to it
+ * the BMISS_THRES will be seen as 0, seems harware doesn't keep
+ * track of it. Max value depends on harware. For AR5210 this is just 7.
+ * For AR5211+ this seems to be up to 255. */
+#define AR5K_TUNE_BMISS_THRES                  7
+#define AR5K_TUNE_REGISTER_DWELL_TIME          20000
+#define AR5K_TUNE_BEACON_INTERVAL              100
+#define AR5K_TUNE_AIFS                         2
+#define AR5K_TUNE_AIFS_11B                     2
+#define AR5K_TUNE_AIFS_XR                      0
+#define AR5K_TUNE_CWMIN                                15
+#define AR5K_TUNE_CWMIN_11B                    31
+#define AR5K_TUNE_CWMIN_XR                     3
+#define AR5K_TUNE_CWMAX                                1023
+#define AR5K_TUNE_CWMAX_11B                    1023
+#define AR5K_TUNE_CWMAX_XR                     7
+#define AR5K_TUNE_NOISE_FLOOR                  -72
+#define AR5K_TUNE_MAX_TXPOWER                  63
+#define AR5K_TUNE_DEFAULT_TXPOWER              25
+#define AR5K_TUNE_TPC_TXPOWER                  0
+#define AR5K_TUNE_ANT_DIVERSITY                        1
+#define AR5K_TUNE_HWTXTRIES                    4
+
+#define AR5K_INIT_CARR_SENSE_EN                        1
+
+/*Swap RX/TX Descriptor for big endian archs*/
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define AR5K_INIT_CFG  (               \
+       AR5K_CFG_SWTD | AR5K_CFG_SWRD   \
+)
+#else
+#define AR5K_INIT_CFG  0x00000000
+#endif
+
+/* Initial values */
+#define        AR5K_INIT_CYCRSSI_THR1                  2
+#define AR5K_INIT_TX_LATENCY                   502
+#define AR5K_INIT_USEC                         39
+#define AR5K_INIT_USEC_TURBO                   79
+#define AR5K_INIT_USEC_32                      31
+#define AR5K_INIT_SLOT_TIME                    396
+#define AR5K_INIT_SLOT_TIME_TURBO              480
+#define AR5K_INIT_ACK_CTS_TIMEOUT              1024
+#define AR5K_INIT_ACK_CTS_TIMEOUT_TURBO                0x08000800
+#define AR5K_INIT_PROG_IFS                     920
+#define AR5K_INIT_PROG_IFS_TURBO               960
+#define AR5K_INIT_EIFS                         3440
+#define AR5K_INIT_EIFS_TURBO                   6880
+#define AR5K_INIT_SIFS                         560
+#define AR5K_INIT_SIFS_TURBO                   480
+#define AR5K_INIT_SH_RETRY                     10
+#define AR5K_INIT_LG_RETRY                     AR5K_INIT_SH_RETRY
+#define AR5K_INIT_SSH_RETRY                    32
+#define AR5K_INIT_SLG_RETRY                    AR5K_INIT_SSH_RETRY
+#define AR5K_INIT_TX_RETRY                     10
+
+#define AR5K_INIT_TRANSMIT_LATENCY             (                       \
+       (AR5K_INIT_TX_LATENCY << 14) | (AR5K_INIT_USEC_32 << 7) |       \
+       (AR5K_INIT_USEC)                                                \
+)
+#define AR5K_INIT_TRANSMIT_LATENCY_TURBO       (                       \
+       (AR5K_INIT_TX_LATENCY << 14) | (AR5K_INIT_USEC_32 << 7) |       \
+       (AR5K_INIT_USEC_TURBO)                                          \
+)
+#define AR5K_INIT_PROTO_TIME_CNTRL             (                       \
+       (AR5K_INIT_CARR_SENSE_EN << 26) | (AR5K_INIT_EIFS << 12) |      \
+       (AR5K_INIT_PROG_IFS)                                            \
+)
+#define AR5K_INIT_PROTO_TIME_CNTRL_TURBO       (                       \
+       (AR5K_INIT_CARR_SENSE_EN << 26) | (AR5K_INIT_EIFS_TURBO << 12) | \
+       (AR5K_INIT_PROG_IFS_TURBO)                                      \
+)
+
+/* token to use for aifs, cwmin, cwmax in MadWiFi */
+#define        AR5K_TXQ_USEDEFAULT     ((u32) -1)
+
+/* GENERIC CHIPSET DEFINITIONS */
+
+/* MAC Chips */
+enum ath5k_version {
+       AR5K_AR5210     = 0,
+       AR5K_AR5211     = 1,
+       AR5K_AR5212     = 2,
+};
+
+/* PHY Chips */
+enum ath5k_radio {
+       AR5K_RF5110     = 0,
+       AR5K_RF5111     = 1,
+       AR5K_RF5112     = 2,
+       AR5K_RF2413     = 3,
+       AR5K_RF5413     = 4,
+       AR5K_RF2316     = 5,
+       AR5K_RF2317     = 6,
+       AR5K_RF2425     = 7,
+};
+
+/*
+ * Common silicon revision/version values
+ */
+
+enum ath5k_srev_type {
+       AR5K_VERSION_MAC,
+       AR5K_VERSION_RAD,
+};
+
+struct ath5k_srev_name {
+       const char              *sr_name;
+       enum ath5k_srev_type    sr_type;
+       unsigned                sr_val;
+};
+
+#define AR5K_SREV_UNKNOWN      0xffff
+
+#define AR5K_SREV_AR5210       0x00 /* Crete */
+#define AR5K_SREV_AR5311       0x10 /* Maui 1 */
+#define AR5K_SREV_AR5311A      0x20 /* Maui 2 */
+#define AR5K_SREV_AR5311B      0x30 /* Spirit */
+#define AR5K_SREV_AR5211       0x40 /* Oahu */
+#define AR5K_SREV_AR5212       0x50 /* Venice */
+#define AR5K_SREV_AR5213       0x55 /* ??? */
+#define AR5K_SREV_AR5213A      0x59 /* Hainan */
+#define AR5K_SREV_AR2413       0x78 /* Griffin lite */
+#define AR5K_SREV_AR2414       0x70 /* Griffin */
+#define AR5K_SREV_AR5424       0x90 /* Condor */
+#define AR5K_SREV_AR5413       0xa4 /* Eagle lite */
+#define AR5K_SREV_AR5414       0xa0 /* Eagle */
+#define AR5K_SREV_AR2415       0xb0 /* Talon */
+#define AR5K_SREV_AR5416       0xc0 /* PCI-E */
+#define AR5K_SREV_AR5418       0xca /* PCI-E */
+#define AR5K_SREV_AR2425       0xe0 /* Swan */
+#define AR5K_SREV_AR2417       0xf0 /* Nala */
+
+#define AR5K_SREV_RAD_5110     0x00
+#define AR5K_SREV_RAD_5111     0x10
+#define AR5K_SREV_RAD_5111A    0x15
+#define AR5K_SREV_RAD_2111     0x20
+#define AR5K_SREV_RAD_5112     0x30
+#define AR5K_SREV_RAD_5112A    0x35
+#define        AR5K_SREV_RAD_5112B     0x36
+#define AR5K_SREV_RAD_2112     0x40
+#define AR5K_SREV_RAD_2112A    0x45
+#define        AR5K_SREV_RAD_2112B     0x46
+#define AR5K_SREV_RAD_2413     0x50
+#define AR5K_SREV_RAD_5413     0x60
+#define AR5K_SREV_RAD_2316     0x70 /* Cobra SoC */
+#define AR5K_SREV_RAD_2317     0x80
+#define AR5K_SREV_RAD_5424     0xa0 /* Mostly same as 5413 */
+#define AR5K_SREV_RAD_2425     0xa2
+#define AR5K_SREV_RAD_5133     0xc0
+
+#define AR5K_SREV_PHY_5211     0x30
+#define AR5K_SREV_PHY_5212     0x41
+#define        AR5K_SREV_PHY_5212A     0x42
+#define AR5K_SREV_PHY_5212B    0x43
+#define AR5K_SREV_PHY_2413     0x45
+#define AR5K_SREV_PHY_5413     0x61
+#define AR5K_SREV_PHY_2425     0x70
+
+/*
+ * Some of this information is based on Documentation from:
+ *
+ * http://madwifi.org/wiki/ChipsetFeatures/SuperAG
+ *
+ * Modulation for Atheros' eXtended Range - range enhancing extension that is
+ * supposed to double the distance an Atheros client device can keep a
+ * connection with an Atheros access point. This is achieved by increasing
+ * the receiver sensitivity up to, -105dBm, which is about 20dB above what
+ * the 802.11 specifications demand. In addition, new (proprietary) data rates
+ * are introduced: 3, 2, 1, 0.5 and 0.25 MBit/s.
+ *
+ * Please note that can you either use XR or TURBO but you cannot use both,
+ * they are exclusive.
+ *
+ */
+#define MODULATION_XR          0x00000200
+
+/*
+ * Modulation for Atheros' Turbo G and Turbo A, its supposed to provide a
+ * throughput transmission speed up to 40Mbit/s-60Mbit/s at a 108Mbit/s
+ * signaling rate achieved through the bonding of two 54Mbit/s 802.11g
+ * channels. To use this feature your Access Point must also suport it.
+ * There is also a distinction between "static" and "dynamic" turbo modes:
+ *
+ * - Static: is the dumb version: devices set to this mode stick to it until
+ *     the mode is turned off.
+ * - Dynamic: is the intelligent version, the network decides itself if it
+ *     is ok to use turbo. As soon as traffic is detected on adjacent channels
+ *     (which would get used in turbo mode), or when a non-turbo station joins
+ *     the network, turbo mode won't be used until the situation changes again.
+ *     Dynamic mode is achieved by Atheros' Adaptive Radio (AR) feature which
+ *     monitors the used radio band in order to decide whether turbo mode may
+ *     be used or not.
+ *
+ * This article claims Super G sticks to bonding of channels 5 and 6 for
+ * USA:
+ *
+ * http://www.pcworld.com/article/id,113428-page,1/article.html
+ *
+ * The channel bonding seems to be driver specific though. In addition to
+ * deciding what channels will be used, these "Turbo" modes are accomplished
+ * by also enabling the following features:
+ *
+ * - Bursting: allows multiple frames to be sent at once, rather than pausing
+ *     after each frame. Bursting is a standards-compliant feature that can be
+ *     used with any Access Point.
+ * - Fast frames: increases the amount of information that can be sent per
+ *     frame, also resulting in a reduction of transmission overhead. It is a
+ *     proprietary feature that needs to be supported by the Access Point.
+ * - Compression: data frames are compressed in real time using a Lempel Ziv
+ *     algorithm. This is done transparently. Once this feature is enabled,
+ *     compression and decompression takes place inside the chipset, without
+ *     putting additional load on the host CPU.
+ *
+ */
+#define MODULATION_TURBO       0x00000080
+
+enum ath5k_driver_mode {
+       AR5K_MODE_11A           = 0,
+       AR5K_MODE_11A_TURBO     = 1,
+       AR5K_MODE_11B           = 2,
+       AR5K_MODE_11G           = 3,
+       AR5K_MODE_11G_TURBO     = 4,
+       AR5K_MODE_XR            = 5,
+};
+
+enum {
+       AR5K_MODE_BIT_11A       = (1 << AR5K_MODE_11A),
+       AR5K_MODE_BIT_11A_TURBO = (1 << AR5K_MODE_11A_TURBO),
+       AR5K_MODE_BIT_11B       = (1 << AR5K_MODE_11B),
+       AR5K_MODE_BIT_11G       = (1 << AR5K_MODE_11G),
+       AR5K_MODE_BIT_11G_TURBO = (1 << AR5K_MODE_11G_TURBO),
+       AR5K_MODE_BIT_XR        = (1 << AR5K_MODE_XR),
+};
+
+/****************\
+  TX DEFINITIONS
+\****************/
+
+/*
+ * TX Status descriptor
+ */
+struct ath5k_tx_status {
+       u16     ts_seqnum;
+       u16     ts_tstamp;
+       u8      ts_status;
+       u8      ts_rate[4];
+       u8      ts_retry[4];
+       u8      ts_final_idx;
+       s8      ts_rssi;
+       u8      ts_shortretry;
+       u8      ts_longretry;
+       u8      ts_virtcol;
+       u8      ts_antenna;
+} __attribute__ ((packed));
+
+#define AR5K_TXSTAT_ALTRATE    0x80
+#define AR5K_TXERR_XRETRY      0x01
+#define AR5K_TXERR_FILT                0x02
+#define AR5K_TXERR_FIFO                0x04
+
+/**
+ * enum ath5k_tx_queue - Queue types used to classify tx queues.
+ * @AR5K_TX_QUEUE_INACTIVE: q is unused -- see ath5k_hw_release_tx_queue
+ * @AR5K_TX_QUEUE_DATA: A normal data queue
+ * @AR5K_TX_QUEUE_XR_DATA: An XR-data queue
+ * @AR5K_TX_QUEUE_BEACON: The beacon queue
+ * @AR5K_TX_QUEUE_CAB: The after-beacon queue
+ * @AR5K_TX_QUEUE_UAPSD: Unscheduled Automatic Power Save Delivery queue
+ */
+enum ath5k_tx_queue {
+       AR5K_TX_QUEUE_INACTIVE = 0,
+       AR5K_TX_QUEUE_DATA,
+       AR5K_TX_QUEUE_XR_DATA,
+       AR5K_TX_QUEUE_BEACON,
+       AR5K_TX_QUEUE_CAB,
+       AR5K_TX_QUEUE_UAPSD,
+};
+
+/*
+ * Queue syb-types to classify normal data queues.
+ * These are the 4 Access Categories as defined in
+ * WME spec. 0 is the lowest priority and 4 is the
+ * highest. Normal data that hasn't been classified
+ * goes to the Best Effort AC.
+ */
+enum ath5k_tx_queue_subtype {
+       AR5K_WME_AC_BK = 0,     /*Background traffic*/
+       AR5K_WME_AC_BE,         /*Best-effort (normal) traffic)*/
+       AR5K_WME_AC_VI,         /*Video traffic*/
+       AR5K_WME_AC_VO,         /*Voice traffic*/
+};
+
+/*
+ * Queue ID numbers as returned by the hw functions, each number
+ * represents a hw queue. If hw does not support hw queues
+ * (eg 5210) all data goes in one queue. These match
+ * d80211 definitions (net80211/MadWiFi don't use them).
+ */
+enum ath5k_tx_queue_id {
+       AR5K_TX_QUEUE_ID_NOQCU_DATA     = 0,
+       AR5K_TX_QUEUE_ID_NOQCU_BEACON   = 1,
+       AR5K_TX_QUEUE_ID_DATA_MIN       = 0, /*IEEE80211_TX_QUEUE_DATA0*/
+       AR5K_TX_QUEUE_ID_DATA_MAX       = 4, /*IEEE80211_TX_QUEUE_DATA4*/
+       AR5K_TX_QUEUE_ID_DATA_SVP       = 5, /*IEEE80211_TX_QUEUE_SVP - Spectralink Voice Protocol*/
+       AR5K_TX_QUEUE_ID_CAB            = 6, /*IEEE80211_TX_QUEUE_AFTER_BEACON*/
+       AR5K_TX_QUEUE_ID_BEACON         = 7, /*IEEE80211_TX_QUEUE_BEACON*/
+       AR5K_TX_QUEUE_ID_UAPSD          = 8,
+       AR5K_TX_QUEUE_ID_XR_DATA        = 9,
+};
+
+/*
+ * Flags to set hw queue's parameters...
+ */
+#define AR5K_TXQ_FLAG_TXOKINT_ENABLE           0x0001  /* Enable TXOK interrupt */
+#define AR5K_TXQ_FLAG_TXERRINT_ENABLE          0x0002  /* Enable TXERR interrupt */
+#define AR5K_TXQ_FLAG_TXEOLINT_ENABLE          0x0004  /* Enable TXEOL interrupt -not used- */
+#define AR5K_TXQ_FLAG_TXDESCINT_ENABLE         0x0008  /* Enable TXDESC interrupt -not used- */
+#define AR5K_TXQ_FLAG_TXURNINT_ENABLE          0x0010  /* Enable TXURN interrupt */
+#define AR5K_TXQ_FLAG_CBRORNINT_ENABLE         0x0020  /* Enable CBRORN interrupt */
+#define AR5K_TXQ_FLAG_CBRURNINT_ENABLE         0x0040  /* Enable CBRURN interrupt */
+#define AR5K_TXQ_FLAG_QTRIGINT_ENABLE          0x0080  /* Enable QTRIG interrupt */
+#define AR5K_TXQ_FLAG_TXNOFRMINT_ENABLE                0x0100  /* Enable TXNOFRM interrupt */
+#define AR5K_TXQ_FLAG_BACKOFF_DISABLE          0x0200  /* Disable random post-backoff */
+#define AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE        0x0300  /* Enable ready time expiry policy (?)*/
+#define AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE        0x0800  /* Enable backoff while bursting */
+#define AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS                0x1000  /* Disable backoff while bursting */
+#define AR5K_TXQ_FLAG_COMPRESSION_ENABLE       0x2000  /* Enable hw compression -not implemented-*/
+
+/*
+ * A struct to hold tx queue's parameters
+ */
+struct ath5k_txq_info {
+       enum ath5k_tx_queue tqi_type;
+       enum ath5k_tx_queue_subtype tqi_subtype;
+       u16     tqi_flags;      /* Tx queue flags (see above) */
+       u32     tqi_aifs;       /* Arbitrated Interframe Space */
+       s32     tqi_cw_min;     /* Minimum Contention Window */
+       s32     tqi_cw_max;     /* Maximum Contention Window */
+       u32     tqi_cbr_period; /* Constant bit rate period */
+       u32     tqi_cbr_overflow_limit;
+       u32     tqi_burst_time;
+       u32     tqi_ready_time; /* Not used */
+};
+
+/*
+ * Transmit packet types.
+ * used on tx control descriptor
+ * TODO: Use them inside base.c corectly
+ */
+enum ath5k_pkt_type {
+       AR5K_PKT_TYPE_NORMAL            = 0,
+       AR5K_PKT_TYPE_ATIM              = 1,
+       AR5K_PKT_TYPE_PSPOLL            = 2,
+       AR5K_PKT_TYPE_BEACON            = 3,
+       AR5K_PKT_TYPE_PROBE_RESP        = 4,
+       AR5K_PKT_TYPE_PIFS              = 5,
+};
+
+/*
+ * TX power and TPC settings
+ */
+#define AR5K_TXPOWER_OFDM(_r, _v)      (                       \
+       ((0 & 1) << ((_v) + 6)) |                               \
+       (((ah->ah_txpower.txp_rates_power_table[(_r)]) & 0x3f) << (_v)) \
+)
+
+#define AR5K_TXPOWER_CCK(_r, _v)       (                       \
+       (ah->ah_txpower.txp_rates_power_table[(_r)] & 0x3f) << (_v)     \
+)
+
+/*
+ * DMA size definitions (2^n+2)
+ */
+enum ath5k_dmasize {
+       AR5K_DMASIZE_4B = 0,
+       AR5K_DMASIZE_8B,
+       AR5K_DMASIZE_16B,
+       AR5K_DMASIZE_32B,
+       AR5K_DMASIZE_64B,
+       AR5K_DMASIZE_128B,
+       AR5K_DMASIZE_256B,
+       AR5K_DMASIZE_512B
+};
+
+
+/****************\
+  RX DEFINITIONS
+\****************/
+
+/*
+ * RX Status descriptor
+ */
+struct ath5k_rx_status {
+       u16     rs_datalen;
+       u16     rs_tstamp;
+       u8      rs_status;
+       u8      rs_phyerr;
+       s8      rs_rssi;
+       u8      rs_keyix;
+       u8      rs_rate;
+       u8      rs_antenna;
+       u8      rs_more;
+};
+
+#define AR5K_RXERR_CRC         0x01
+#define AR5K_RXERR_PHY         0x02
+#define AR5K_RXERR_FIFO                0x04
+#define AR5K_RXERR_DECRYPT     0x08
+#define AR5K_RXERR_MIC         0x10
+#define AR5K_RXKEYIX_INVALID   ((u8) - 1)
+#define AR5K_TXKEYIX_INVALID   ((u32) - 1)
+
+
+/*
+ * TSF to TU conversion:
+ *
+ * TSF is a 64bit value in usec (microseconds).
+ * TU is a 32bit value and defined by IEEE802.11 (page 6) as "A measurement of
+ * time equal to 1024 usec", so it's roughly milliseconds (usec / 1024).
+ */
+#define TSF_TO_TU(_tsf) (u32)((_tsf) >> 10)
+
+
+/*******************************\
+  GAIN OPTIMIZATION DEFINITIONS
+\*******************************/
+
+enum ath5k_rfgain {
+       AR5K_RFGAIN_INACTIVE = 0,
+       AR5K_RFGAIN_ACTIVE,
+       AR5K_RFGAIN_READ_REQUESTED,
+       AR5K_RFGAIN_NEED_CHANGE,
+};
+
+struct ath5k_gain {
+       u8                      g_step_idx;
+       u8                      g_current;
+       u8                      g_target;
+       u8                      g_low;
+       u8                      g_high;
+       u8                      g_f_corr;
+       u8                      g_state;
+};
+
+/********************\
+  COMMON DEFINITIONS
+\********************/
+
+#define AR5K_SLOT_TIME_9       396
+#define AR5K_SLOT_TIME_20      880
+#define AR5K_SLOT_TIME_MAX     0xffff
+
+/* channel_flags */
+#define        CHANNEL_CW_INT  0x0008  /* Contention Window interference detected */
+#define        CHANNEL_TURBO   0x0010  /* Turbo Channel */
+#define        CHANNEL_CCK     0x0020  /* CCK channel */
+#define        CHANNEL_OFDM    0x0040  /* OFDM channel */
+#define        CHANNEL_2GHZ    0x0080  /* 2GHz channel. */
+#define        CHANNEL_5GHZ    0x0100  /* 5GHz channel */
+#define        CHANNEL_PASSIVE 0x0200  /* Only passive scan allowed */
+#define        CHANNEL_DYN     0x0400  /* Dynamic CCK-OFDM channel (for g operation) */
+#define        CHANNEL_XR      0x0800  /* XR channel */
+
+#define        CHANNEL_A       (CHANNEL_5GHZ|CHANNEL_OFDM)
+#define        CHANNEL_B       (CHANNEL_2GHZ|CHANNEL_CCK)
+#define        CHANNEL_G       (CHANNEL_2GHZ|CHANNEL_OFDM)
+#define        CHANNEL_T       (CHANNEL_5GHZ|CHANNEL_OFDM|CHANNEL_TURBO)
+#define        CHANNEL_TG      (CHANNEL_2GHZ|CHANNEL_OFDM|CHANNEL_TURBO)
+#define        CHANNEL_108A    CHANNEL_T
+#define        CHANNEL_108G    CHANNEL_TG
+#define        CHANNEL_X       (CHANNEL_5GHZ|CHANNEL_OFDM|CHANNEL_XR)
+
+#define        CHANNEL_ALL     (CHANNEL_OFDM|CHANNEL_CCK|CHANNEL_2GHZ|CHANNEL_5GHZ| \
+               CHANNEL_TURBO)
+
+#define        CHANNEL_ALL_NOTURBO     (CHANNEL_ALL & ~CHANNEL_TURBO)
+#define CHANNEL_MODES          CHANNEL_ALL
+
+/*
+ * Used internaly for reset_tx_queue).
+ * Also see struct struct net80211_channel.
+ */
+#define IS_CHAN_XR(_c) ((_c->hw_value & CHANNEL_XR) != 0)
+#define IS_CHAN_B(_c)  ((_c->hw_value & CHANNEL_B) != 0)
+
+/*
+ * The following structure is used to map 2GHz channels to
+ * 5GHz Atheros channels.
+ * TODO: Clean up
+ */
+struct ath5k_athchan_2ghz {
+       u32     a2_flags;
+       u16     a2_athchan;
+};
+
+
+/******************\
+  RATE DEFINITIONS
+\******************/
+
+/**
+ * Seems the ar5xxx harware supports up to 32 rates, indexed by 1-32.
+ *
+ * The rate code is used to get the RX rate or set the TX rate on the
+ * hardware descriptors. It is also used for internal modulation control
+ * and settings.
+ *
+ * This is the hardware rate map we are aware of:
+ *
+ * rate_code   0x01    0x02    0x03    0x04    0x05    0x06    0x07    0x08
+ * rate_kbps   3000    1000    ?       ?       ?       2000    500     48000
+ *
+ * rate_code   0x09    0x0A    0x0B    0x0C    0x0D    0x0E    0x0F    0x10
+ * rate_kbps   24000   12000   6000    54000   36000   18000   9000    ?
+ *
+ * rate_code   17      18      19      20      21      22      23      24
+ * rate_kbps   ?       ?       ?       ?       ?       ?       ?       11000
+ *
+ * rate_code   25      26      27      28      29      30      31      32
+ * rate_kbps   5500    2000    1000    11000S  5500S   2000S   ?       ?
+ *
+ * "S" indicates CCK rates with short preamble.
+ *
+ * AR5211 has different rate codes for CCK (802.11B) rates. It only uses the
+ * lowest 4 bits, so they are the same as below with a 0xF mask.
+ * (0xB, 0xA, 0x9 and 0x8 for 1M, 2M, 5.5M and 11M).
+ * We handle this in ath5k_setup_bands().
+ */
+#define AR5K_MAX_RATES 32
+
+/* B */
+#define ATH5K_RATE_CODE_1M     0x1B
+#define ATH5K_RATE_CODE_2M     0x1A
+#define ATH5K_RATE_CODE_5_5M   0x19
+#define ATH5K_RATE_CODE_11M    0x18
+/* A and G */
+#define ATH5K_RATE_CODE_6M     0x0B
+#define ATH5K_RATE_CODE_9M     0x0F
+#define ATH5K_RATE_CODE_12M    0x0A
+#define ATH5K_RATE_CODE_18M    0x0E
+#define ATH5K_RATE_CODE_24M    0x09
+#define ATH5K_RATE_CODE_36M    0x0D
+#define ATH5K_RATE_CODE_48M    0x08
+#define ATH5K_RATE_CODE_54M    0x0C
+/* XR */
+#define ATH5K_RATE_CODE_XR_500K        0x07
+#define ATH5K_RATE_CODE_XR_1M  0x02
+#define ATH5K_RATE_CODE_XR_2M  0x06
+#define ATH5K_RATE_CODE_XR_3M  0x01
+
+/* adding this flag to rate_code enables short preamble */
+#define AR5K_SET_SHORT_PREAMBLE 0x04
+
+/*
+ * Crypto definitions
+ */
+
+#define AR5K_KEYCACHE_SIZE     8
+
+/***********************\
+ HW RELATED DEFINITIONS
+\***********************/
+
+/*
+ * Misc definitions
+ */
+#define        AR5K_RSSI_EP_MULTIPLIER (1<<7)
+
+#define AR5K_ASSERT_ENTRY(_e, _s) do {         \
+       if (_e >= _s)                           \
+               return 0;                       \
+} while (0)
+
+/*
+ * Hardware interrupt abstraction
+ */
+
+/**
+ * enum ath5k_int - Hardware interrupt masks helpers
+ *
+ * @AR5K_INT_RX: mask to identify received frame interrupts, of type
+ *     AR5K_ISR_RXOK or AR5K_ISR_RXERR
+ * @AR5K_INT_RXDESC: Request RX descriptor/Read RX descriptor (?)
+ * @AR5K_INT_RXNOFRM: No frame received (?)
+ * @AR5K_INT_RXEOL: received End Of List for VEOL (Virtual End Of List). The
+ *     Queue Control Unit (QCU) signals an EOL interrupt only if a descriptor's
+ *     LinkPtr is NULL. For more details, refer to:
+ *     http://www.freepatentsonline.com/20030225739.html
+ * @AR5K_INT_RXORN: Indicates we got RX overrun (eg. no more descriptors).
+ *     Note that Rx overrun is not always fatal, on some chips we can continue
+ *     operation without reseting the card, that's why int_fatal is not
+ *     common for all chips.
+ * @AR5K_INT_TX: mask to identify received frame interrupts, of type
+ *     AR5K_ISR_TXOK or AR5K_ISR_TXERR
+ * @AR5K_INT_TXDESC: Request TX descriptor/Read TX status descriptor (?)
+ * @AR5K_INT_TXURN: received when we should increase the TX trigger threshold
+ *     We currently do increments on interrupt by
+ *     (AR5K_TUNE_MAX_TX_FIFO_THRES - current_trigger_level) / 2
+ * @AR5K_INT_MIB: Indicates the Management Information Base counters should be
+ *     checked. We should do this with ath5k_hw_update_mib_counters() but
+ *     it seems we should also then do some noise immunity work.
+ * @AR5K_INT_RXPHY: RX PHY Error
+ * @AR5K_INT_RXKCM: RX Key cache miss
+ * @AR5K_INT_SWBA: SoftWare Beacon Alert - indicates its time to send a
+ *     beacon that must be handled in software. The alternative is if you
+ *     have VEOL support, in that case you let the hardware deal with things.
+ * @AR5K_INT_BMISS: If in STA mode this indicates we have stopped seeing
+ *     beacons from the AP have associated with, we should probably try to
+ *     reassociate. When in IBSS mode this might mean we have not received
+ *     any beacons from any local stations. Note that every station in an
+ *     IBSS schedules to send beacons at the Target Beacon Transmission Time
+ *     (TBTT) with a random backoff.
+ * @AR5K_INT_BNR: Beacon Not Ready interrupt - ??
+ * @AR5K_INT_GPIO: GPIO interrupt is used for RF Kill, disabled for now
+ *     until properly handled
+ * @AR5K_INT_FATAL: Fatal errors were encountered, typically caused by DMA
+ *     errors. These types of errors we can enable seem to be of type
+ *     AR5K_SIMR2_MCABT, AR5K_SIMR2_SSERR and AR5K_SIMR2_DPERR.
+ * @AR5K_INT_GLOBAL: Used to clear and set the IER
+ * @AR5K_INT_NOCARD: signals the card has been removed
+ * @AR5K_INT_COMMON: common interrupts shared amogst MACs with the same
+ *     bit value
+ *
+ * These are mapped to take advantage of some common bits
+ * between the MACs, to be able to set intr properties
+ * easier. Some of them are not used yet inside hw.c. Most map
+ * to the respective hw interrupt value as they are common amogst different
+ * MACs.
+ */
+enum ath5k_int {
+       AR5K_INT_RXOK   = 0x00000001,
+       AR5K_INT_RXDESC = 0x00000002,
+       AR5K_INT_RXERR  = 0x00000004,
+       AR5K_INT_RXNOFRM = 0x00000008,
+       AR5K_INT_RXEOL  = 0x00000010,
+       AR5K_INT_RXORN  = 0x00000020,
+       AR5K_INT_TXOK   = 0x00000040,
+       AR5K_INT_TXDESC = 0x00000080,
+       AR5K_INT_TXERR  = 0x00000100,
+       AR5K_INT_TXNOFRM = 0x00000200,
+       AR5K_INT_TXEOL  = 0x00000400,
+       AR5K_INT_TXURN  = 0x00000800,
+       AR5K_INT_MIB    = 0x00001000,
+       AR5K_INT_SWI    = 0x00002000,
+       AR5K_INT_RXPHY  = 0x00004000,
+       AR5K_INT_RXKCM  = 0x00008000,
+       AR5K_INT_SWBA   = 0x00010000,
+       AR5K_INT_BRSSI  = 0x00020000,
+       AR5K_INT_BMISS  = 0x00040000,
+       AR5K_INT_FATAL  = 0x00080000, /* Non common */
+       AR5K_INT_BNR    = 0x00100000, /* Non common */
+       AR5K_INT_TIM    = 0x00200000, /* Non common */
+       AR5K_INT_DTIM   = 0x00400000, /* Non common */
+       AR5K_INT_DTIM_SYNC =    0x00800000, /* Non common */
+       AR5K_INT_GPIO   =       0x01000000,
+       AR5K_INT_BCN_TIMEOUT =  0x02000000, /* Non common */
+       AR5K_INT_CAB_TIMEOUT =  0x04000000, /* Non common */
+       AR5K_INT_RX_DOPPLER =   0x08000000, /* Non common */
+       AR5K_INT_QCBRORN =      0x10000000, /* Non common */
+       AR5K_INT_QCBRURN =      0x20000000, /* Non common */
+       AR5K_INT_QTRIG  =       0x40000000, /* Non common */
+       AR5K_INT_GLOBAL =       0x80000000,
+
+       AR5K_INT_COMMON  = AR5K_INT_RXOK
+               | AR5K_INT_RXDESC
+               | AR5K_INT_RXERR
+               | AR5K_INT_RXNOFRM
+               | AR5K_INT_RXEOL
+               | AR5K_INT_RXORN
+               | AR5K_INT_TXOK
+               | AR5K_INT_TXDESC
+               | AR5K_INT_TXERR
+               | AR5K_INT_TXNOFRM
+               | AR5K_INT_TXEOL
+               | AR5K_INT_TXURN
+               | AR5K_INT_MIB
+               | AR5K_INT_SWI
+               | AR5K_INT_RXPHY
+               | AR5K_INT_RXKCM
+               | AR5K_INT_SWBA
+               | AR5K_INT_BRSSI
+               | AR5K_INT_BMISS
+               | AR5K_INT_GPIO
+               | AR5K_INT_GLOBAL,
+
+       AR5K_INT_NOCARD = 0xffffffff
+};
+
+/*
+ * Power management
+ */
+enum ath5k_power_mode {
+       AR5K_PM_UNDEFINED = 0,
+       AR5K_PM_AUTO,
+       AR5K_PM_AWAKE,
+       AR5K_PM_FULL_SLEEP,
+       AR5K_PM_NETWORK_SLEEP,
+};
+
+/* GPIO-controlled software LED */
+#define AR5K_SOFTLED_PIN       0
+#define AR5K_SOFTLED_ON                0
+#define AR5K_SOFTLED_OFF       1
+
+/*
+ * Chipset capabilities -see ath5k_hw_get_capability-
+ * get_capability function is not yet fully implemented
+ * in ath5k so most of these don't work yet...
+ * TODO: Implement these & merge with _TUNE_ stuff above
+ */
+enum ath5k_capability_type {
+       AR5K_CAP_REG_DMN                = 0,    /* Used to get current reg. domain id */
+       AR5K_CAP_TKIP_MIC               = 2,    /* Can handle TKIP MIC in hardware */
+       AR5K_CAP_TKIP_SPLIT             = 3,    /* TKIP uses split keys */
+       AR5K_CAP_PHYCOUNTERS            = 4,    /* PHY error counters */
+       AR5K_CAP_DIVERSITY              = 5,    /* Supports fast diversity */
+       AR5K_CAP_NUM_TXQUEUES           = 6,    /* Used to get max number of hw txqueues */
+       AR5K_CAP_VEOL                   = 7,    /* Supports virtual EOL */
+       AR5K_CAP_COMPRESSION            = 8,    /* Supports compression */
+       AR5K_CAP_BURST                  = 9,    /* Supports packet bursting */
+       AR5K_CAP_FASTFRAME              = 10,   /* Supports fast frames */
+       AR5K_CAP_TXPOW                  = 11,   /* Used to get global tx power limit */
+       AR5K_CAP_TPC                    = 12,   /* Can do per-packet tx power control (needed for 802.11a) */
+       AR5K_CAP_BSSIDMASK              = 13,   /* Supports bssid mask */
+       AR5K_CAP_MCAST_KEYSRCH          = 14,   /* Supports multicast key search */
+       AR5K_CAP_TSF_ADJUST             = 15,   /* Supports beacon tsf adjust */
+       AR5K_CAP_XR                     = 16,   /* Supports XR mode */
+       AR5K_CAP_WME_TKIPMIC            = 17,   /* Supports TKIP MIC when using WMM */
+       AR5K_CAP_CHAN_HALFRATE          = 18,   /* Supports half rate channels */
+       AR5K_CAP_CHAN_QUARTERRATE       = 19,   /* Supports quarter rate channels */
+       AR5K_CAP_RFSILENT               = 20,   /* Supports RFsilent */
+};
+
+
+/* XXX: we *may* move cap_range stuff to struct wiphy */
+struct ath5k_capabilities {
+       /*
+        * Supported PHY modes
+        * (ie. CHANNEL_A, CHANNEL_B, ...)
+        */
+       u16 cap_mode;
+
+       /*
+        * Frequency range (without regulation restrictions)
+        */
+       struct {
+               u16     range_2ghz_min;
+               u16     range_2ghz_max;
+               u16     range_5ghz_min;
+               u16     range_5ghz_max;
+       } cap_range;
+
+       /*
+        * Values stored in the EEPROM (some of them...)
+        */
+       struct ath5k_eeprom_info        cap_eeprom;
+
+       /*
+        * Queue information
+        */
+       struct {
+               u8      q_tx_num;
+       } cap_queues;
+};
+
+
+/***************************************\
+  HARDWARE ABSTRACTION LAYER STRUCTURE
+\***************************************/
+
+/*
+ * Misc defines
+ */
+
+#define AR5K_MAX_GPIO          10
+#define AR5K_MAX_RF_BANKS      8
+
+/* TODO: Clean up and merge with ath5k_softc */
+struct ath5k_hw {
+       struct ath5k_softc      *ah_sc;
+       void                    *ah_iobase;
+
+       enum ath5k_int          ah_imr;
+       int                     ah_ier;
+
+       struct net80211_channel *ah_current_channel;
+       int                     ah_turbo;
+       int                     ah_calibration;
+       int                     ah_running;
+       int                     ah_single_chip;
+       int                     ah_combined_mic;
+
+       u32                     ah_mac_srev;
+       u16                     ah_mac_version;
+       u16                     ah_mac_revision;
+       u16                     ah_phy_revision;
+       u16                     ah_radio_5ghz_revision;
+       u16                     ah_radio_2ghz_revision;
+
+       enum ath5k_version      ah_version;
+       enum ath5k_radio        ah_radio;
+       u32                     ah_phy;
+
+       int                     ah_5ghz;
+       int                     ah_2ghz;
+
+#define ah_regdomain           ah_capabilities.cap_regdomain.reg_current
+#define ah_regdomain_hw                ah_capabilities.cap_regdomain.reg_hw
+#define ah_modes               ah_capabilities.cap_mode
+#define ah_ee_version          ah_capabilities.cap_eeprom.ee_version
+
+       u32                     ah_atim_window;
+       u32                     ah_aifs;
+       u32                     ah_cw_min;
+       u32                     ah_cw_max;
+       int                     ah_software_retry;
+       u32                     ah_limit_tx_retries;
+
+       u32                     ah_antenna[AR5K_EEPROM_N_MODES][AR5K_ANT_MAX];
+       int                     ah_ant_diversity;
+
+       u8                      ah_sta_id[ETH_ALEN];
+
+       /* Current BSSID we are trying to assoc to / create.
+        * This is passed by mac80211 on config_interface() and cached here for
+        * use in resets */
+       u8                      ah_bssid[ETH_ALEN];
+       u8                      ah_bssid_mask[ETH_ALEN];
+
+       u32                     ah_gpio[AR5K_MAX_GPIO];
+       int                     ah_gpio_npins;
+
+       struct ath5k_capabilities ah_capabilities;
+
+       struct ath5k_txq_info   ah_txq;
+       u32                     ah_txq_status;
+       u32                     ah_txq_imr_txok;
+       u32                     ah_txq_imr_txerr;
+       u32                     ah_txq_imr_txurn;
+       u32                     ah_txq_imr_txdesc;
+       u32                     ah_txq_imr_txeol;
+       u32                     ah_txq_imr_cbrorn;
+       u32                     ah_txq_imr_cbrurn;
+       u32                     ah_txq_imr_qtrig;
+       u32                     ah_txq_imr_nofrm;
+       u32                     ah_txq_isr;
+       u32                     *ah_rf_banks;
+       size_t                  ah_rf_banks_size;
+       size_t                  ah_rf_regs_count;
+       struct ath5k_gain       ah_gain;
+       u8                      ah_offset[AR5K_MAX_RF_BANKS];
+
+
+       struct {
+               /* Temporary tables used for interpolation */
+               u8              tmpL[AR5K_EEPROM_N_PD_GAINS]
+                                       [AR5K_EEPROM_POWER_TABLE_SIZE];
+               u8              tmpR[AR5K_EEPROM_N_PD_GAINS]
+                                       [AR5K_EEPROM_POWER_TABLE_SIZE];
+               u8              txp_pd_table[AR5K_EEPROM_POWER_TABLE_SIZE * 2];
+               u16             txp_rates_power_table[AR5K_MAX_RATES];
+               u8              txp_min_idx;
+               int             txp_tpc;
+               /* Values in 0.25dB units */
+               s16             txp_min_pwr;
+               s16             txp_max_pwr;
+               s16             txp_offset;
+               s16             txp_ofdm;
+               /* Values in dB units */
+               s16             txp_cck_ofdm_pwr_delta;
+               s16             txp_cck_ofdm_gainf_delta;
+       } ah_txpower;
+
+       /* noise floor from last periodic calibration */
+       s32                     ah_noise_floor;
+
+       /*
+        * Function pointers
+        */
+       int (*ah_setup_rx_desc)(struct ath5k_hw *ah, struct ath5k_desc *desc,
+                               u32 size, unsigned int flags);
+       int (*ah_setup_tx_desc)(struct ath5k_hw *, struct ath5k_desc *,
+               unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
+               unsigned int, unsigned int, unsigned int, unsigned int,
+               unsigned int, unsigned int, unsigned int);
+       int (*ah_proc_tx_desc)(struct ath5k_hw *, struct ath5k_desc *,
+               struct ath5k_tx_status *);
+       int (*ah_proc_rx_desc)(struct ath5k_hw *, struct ath5k_desc *,
+               struct ath5k_rx_status *);
+};
+
+/*
+ * Prototypes
+ */
+
+extern int ath5k_bitrate_to_hw_rix(int bitrate);
+
+/* Attach/Detach Functions */
+extern int ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version, struct ath5k_hw **ah);
+extern void ath5k_hw_detach(struct ath5k_hw *ah);
+
+/* LED functions */
+extern int ath5k_init_leds(struct ath5k_softc *sc);
+extern void ath5k_led_enable(struct ath5k_softc *sc);
+extern void ath5k_led_off(struct ath5k_softc *sc);
+extern void ath5k_unregister_leds(struct ath5k_softc *sc);
+
+/* Reset Functions */
+extern int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, int initial);
+extern int ath5k_hw_reset(struct ath5k_hw *ah, struct net80211_channel *channel, int change_channel);
+/* Power management functions */
+extern int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode, int set_chip, u16 sleep_duration);
+
+/* DMA Related Functions */
+extern void ath5k_hw_start_rx_dma(struct ath5k_hw *ah);
+extern int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah);
+extern u32 ath5k_hw_get_rxdp(struct ath5k_hw *ah);
+extern void ath5k_hw_set_rxdp(struct ath5k_hw *ah, u32 phys_addr);
+extern int ath5k_hw_start_tx_dma(struct ath5k_hw *ah, unsigned int queue);
+extern int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue);
+extern u32 ath5k_hw_get_txdp(struct ath5k_hw *ah, unsigned int queue);
+extern int ath5k_hw_set_txdp(struct ath5k_hw *ah, unsigned int queue,
+                               u32 phys_addr);
+extern int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, int increase);
+/* Interrupt handling */
+extern int ath5k_hw_is_intr_pending(struct ath5k_hw *ah);
+extern int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask);
+extern enum ath5k_int ath5k_hw_set_imr(struct ath5k_hw *ah, enum ath5k_int new_mask);
+
+/* EEPROM access functions */
+extern int ath5k_eeprom_init(struct ath5k_hw *ah);
+extern void ath5k_eeprom_detach(struct ath5k_hw *ah);
+extern int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac);
+extern int ath5k_eeprom_is_hb63(struct ath5k_hw *ah);
+
+/* Protocol Control Unit Functions */
+extern int ath5k_hw_set_opmode(struct ath5k_hw *ah);
+/* BSSID Functions */
+extern void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac);
+extern int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac);
+extern void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id);
+extern int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask);
+/* Receive start/stop functions */
+extern void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah);
+extern void ath5k_hw_stop_rx_pcu(struct ath5k_hw *ah);
+/* RX Filter functions */
+extern void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1);
+extern u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah);
+extern void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter);
+/* ACK bit rate */
+void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, int high);
+/* ACK/CTS Timeouts */
+extern int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout);
+extern unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah);
+extern int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout);
+extern unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah);
+/* Key table (WEP) functions */
+extern int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry);
+
+/* Queue Control Unit, DFS Control Unit Functions */
+extern int ath5k_hw_set_tx_queueprops(struct ath5k_hw *ah, const struct ath5k_txq_info *queue_info);
+extern int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah,
+                               enum ath5k_tx_queue queue_type,
+                               struct ath5k_txq_info *queue_info);
+extern u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah);
+extern void ath5k_hw_release_tx_queue(struct ath5k_hw *ah);
+extern int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah);
+extern int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time);
+
+/* Hardware Descriptor Functions */
+extern int ath5k_hw_init_desc_functions(struct ath5k_hw *ah);
+
+/* GPIO Functions */
+extern int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio);
+extern int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio);
+extern u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio);
+extern int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val);
+extern void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio, u32 interrupt_level);
+
+/* Misc functions */
+int ath5k_hw_set_capabilities(struct ath5k_hw *ah);
+extern int ath5k_hw_get_capability(struct ath5k_hw *ah, enum ath5k_capability_type cap_type, u32 capability, u32 *result);
+extern int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid, u16 assoc_id);
+extern int ath5k_hw_disable_pspoll(struct ath5k_hw *ah);
+
+/* Initial register settings functions */
+extern int ath5k_hw_write_initvals(struct ath5k_hw *ah, u8 mode, int change_channel);
+
+/* Initialize RF */
+extern int ath5k_hw_rfregs_init(struct ath5k_hw *ah,
+                               struct net80211_channel *channel,
+                               unsigned int mode);
+extern int ath5k_hw_rfgain_init(struct ath5k_hw *ah, unsigned int freq);
+extern enum ath5k_rfgain ath5k_hw_gainf_calibrate(struct ath5k_hw *ah);
+extern int ath5k_hw_rfgain_opt_init(struct ath5k_hw *ah);
+/* PHY/RF channel functions */
+extern int ath5k_channel_ok(struct ath5k_hw *ah, u16 freq, unsigned int flags);
+extern int ath5k_hw_channel(struct ath5k_hw *ah, struct net80211_channel *channel);
+/* PHY calibration */
+extern int ath5k_hw_phy_calibrate(struct ath5k_hw *ah, struct net80211_channel *channel);
+extern int ath5k_hw_noise_floor_calibration(struct ath5k_hw *ah, short freq);
+/* Misc PHY functions */
+extern u16 ath5k_hw_radio_revision(struct ath5k_hw *ah, unsigned int chan);
+extern void ath5k_hw_set_def_antenna(struct ath5k_hw *ah, unsigned int ant);
+extern unsigned int ath5k_hw_get_def_antenna(struct ath5k_hw *ah);
+extern int ath5k_hw_phy_disable(struct ath5k_hw *ah);
+/* TX power setup */
+extern int ath5k_hw_txpower(struct ath5k_hw *ah, struct net80211_channel *channel, u8 ee_mode, u8 txpower);
+extern int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 ee_mode, u8 txpower);
+
+/*
+ * Functions used internaly
+ */
+
+/*
+ * Translate usec to hw clock units
+ * TODO: Half/quarter rate
+ */
+static inline unsigned int ath5k_hw_htoclock(unsigned int usec, int turbo)
+{
+       return turbo ? (usec * 80) : (usec * 40);
+}
+
+/*
+ * Translate hw clock units to usec
+ * TODO: Half/quarter rate
+ */
+static inline unsigned int ath5k_hw_clocktoh(unsigned int clock, int turbo)
+{
+       return turbo ? (clock / 80) : (clock / 40);
+}
+
+/*
+ * Read from a register
+ */
+static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
+{
+       return readl(ah->ah_iobase + reg);
+}
+
+/*
+ * Write to a register
+ */
+static inline void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
+{
+       writel(val, ah->ah_iobase + reg);
+}
+
+#if defined(_ATH5K_RESET) || defined(_ATH5K_PHY)
+/*
+ * Check if a register write has been completed
+ */
+static int ath5k_hw_register_timeout(struct ath5k_hw *ah, u32 reg, u32 flag,
+               u32 val, int is_set)
+{
+       int i;
+       u32 data;
+
+       for (i = AR5K_TUNE_REGISTER_TIMEOUT; i > 0; i--) {
+               data = ath5k_hw_reg_read(ah, reg);
+               if (is_set && (data & flag))
+                       break;
+               else if ((data & flag) == val)
+                       break;
+               udelay(15);
+       }
+
+       return (i <= 0) ? -EAGAIN : 0;
+}
+
+/*
+ * Convert channel frequency to channel number
+ */
+static inline int ath5k_freq_to_channel(int freq)
+{
+       if (freq == 2484)
+               return 14;
+
+       if (freq < 2484)
+               return (freq - 2407) / 5;
+
+       return freq/5 - 1000;
+}
+
+#endif
+
+static inline u32 ath5k_hw_bitswap(u32 val, unsigned int bits)
+{
+       u32 retval = 0, bit, i;
+
+       for (i = 0; i < bits; i++) {
+               bit = (val >> i) & 1;
+               retval = (retval << 1) | bit;
+       }
+
+       return retval;
+}
+
+#endif
diff --git a/src/drivers/net/ath5k/ath5k_attach.c b/src/drivers/net/ath5k/ath5k_attach.c
new file mode 100644 (file)
index 0000000..36dc243
--- /dev/null
@@ -0,0 +1,340 @@
+/*
+ * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
+ *
+ * Modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>
+ * Original from Linux kernel 2.6.30.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+FILE_LICENCE ( MIT );
+
+/*************************************\
+* Attach/Detach Functions and helpers *
+\*************************************/
+
+#include <gpxe/pci.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "ath5k.h"
+#include "reg.h"
+#include "base.h"
+
+/**
+ * ath5k_hw_post - Power On Self Test helper function
+ *
+ * @ah: The &struct ath5k_hw
+ */
+static int ath5k_hw_post(struct ath5k_hw *ah)
+{
+
+       static const u32 static_pattern[4] = {
+               0x55555555,     0xaaaaaaaa,
+               0x66666666,     0x99999999
+       };
+       static const u16 regs[2] = { AR5K_STA_ID0, AR5K_PHY(8) };
+       int i, c;
+       u16 cur_reg;
+       u32 var_pattern;
+       u32 init_val;
+       u32 cur_val;
+
+       for (c = 0; c < 2; c++) {
+
+               cur_reg = regs[c];
+
+               /* Save previous value */
+               init_val = ath5k_hw_reg_read(ah, cur_reg);
+
+               for (i = 0; i < 256; i++) {
+                       var_pattern = i << 16 | i;
+                       ath5k_hw_reg_write(ah, var_pattern, cur_reg);
+                       cur_val = ath5k_hw_reg_read(ah, cur_reg);
+
+                       if (cur_val != var_pattern) {
+                               DBG("ath5k: POST failed!\n");
+                               return -EAGAIN;
+                       }
+
+                       /* Found on ndiswrapper dumps */
+                       var_pattern = 0x0039080f;
+                       ath5k_hw_reg_write(ah, var_pattern, cur_reg);
+               }
+
+               for (i = 0; i < 4; i++) {
+                       var_pattern = static_pattern[i];
+                       ath5k_hw_reg_write(ah, var_pattern, cur_reg);
+                       cur_val = ath5k_hw_reg_read(ah, cur_reg);
+
+                       if (cur_val != var_pattern) {
+                               DBG("ath5k: POST failed!\n");
+                               return -EAGAIN;
+                       }
+
+                       /* Found on ndiswrapper dumps */
+                       var_pattern = 0x003b080f;
+                       ath5k_hw_reg_write(ah, var_pattern, cur_reg);
+               }
+
+               /* Restore previous value */
+               ath5k_hw_reg_write(ah, init_val, cur_reg);
+
+       }
+
+       return 0;
+
+}
+
+/**
+ * ath5k_hw_attach - Check if hw is supported and init the needed structs
+ *
+ * @sc: The &struct ath5k_softc we got from the driver's attach function
+ * @mac_version: The mac version id (check out ath5k.h) based on pci id
+ * @hw: Returned newly allocated hardware structure, on success
+ *
+ * Check if the device is supported, perform a POST and initialize the needed
+ * structs. Returns -ENOMEM if we don't have memory for the needed structs,
+ * -ENODEV if the device is not supported or prints an error msg if something
+ * else went wrong.
+ */
+int ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version,
+                   struct ath5k_hw **hw)
+{
+       struct ath5k_hw *ah;
+       struct pci_device *pdev = sc->pdev;
+       int ret;
+       u32 srev;
+
+       ah = zalloc(sizeof(struct ath5k_hw));
+       if (ah == NULL) {
+               ret = -ENOMEM;
+               DBG("ath5k: out of memory\n");
+               goto err;
+       }
+
+       ah->ah_sc = sc;
+       ah->ah_iobase = sc->iobase;
+
+       /*
+        * HW information
+        */
+       ah->ah_turbo = 0;
+       ah->ah_txpower.txp_tpc = 0;
+       ah->ah_imr = 0;
+       ah->ah_atim_window = 0;
+       ah->ah_aifs = AR5K_TUNE_AIFS;
+       ah->ah_cw_min = AR5K_TUNE_CWMIN;
+       ah->ah_limit_tx_retries = AR5K_INIT_TX_RETRY;
+       ah->ah_software_retry = 0;
+       ah->ah_ant_diversity = AR5K_TUNE_ANT_DIVERSITY;
+
+       /*
+        * Set the mac version based on the pci id
+        */
+       ah->ah_version = mac_version;
+
+       /*Fill the ath5k_hw struct with the needed functions*/
+       ret = ath5k_hw_init_desc_functions(ah);
+       if (ret)
+               goto err_free;
+
+       /* Bring device out of sleep and reset it's units */
+       ret = ath5k_hw_nic_wakeup(ah, CHANNEL_B, 1);
+       if (ret)
+               goto err_free;
+
+       /* Get MAC, PHY and RADIO revisions */
+       srev = ath5k_hw_reg_read(ah, AR5K_SREV);
+       ah->ah_mac_srev = srev;
+       ah->ah_mac_version = AR5K_REG_MS(srev, AR5K_SREV_VER);
+       ah->ah_mac_revision = AR5K_REG_MS(srev, AR5K_SREV_REV);
+       ah->ah_phy_revision = ath5k_hw_reg_read(ah, AR5K_PHY_CHIP_ID);
+       ah->ah_radio_5ghz_revision = ath5k_hw_radio_revision(ah, CHANNEL_5GHZ);
+       ah->ah_phy = AR5K_PHY(0);
+
+       /* Try to identify radio chip based on it's srev */
+       switch (ah->ah_radio_5ghz_revision & 0xf0) {
+       case AR5K_SREV_RAD_5111:
+               ah->ah_radio = AR5K_RF5111;
+               ah->ah_single_chip = 0;
+               ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
+                                                       CHANNEL_2GHZ);
+               break;
+       case AR5K_SREV_RAD_5112:
+       case AR5K_SREV_RAD_2112:
+               ah->ah_radio = AR5K_RF5112;
+               ah->ah_single_chip = 0;
+               ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
+                                                       CHANNEL_2GHZ);
+               break;
+       case AR5K_SREV_RAD_2413:
+               ah->ah_radio = AR5K_RF2413;
+               ah->ah_single_chip = 1;
+               break;
+       case AR5K_SREV_RAD_5413:
+               ah->ah_radio = AR5K_RF5413;
+               ah->ah_single_chip = 1;
+               break;
+       case AR5K_SREV_RAD_2316:
+               ah->ah_radio = AR5K_RF2316;
+               ah->ah_single_chip = 1;
+               break;
+       case AR5K_SREV_RAD_2317:
+               ah->ah_radio = AR5K_RF2317;
+               ah->ah_single_chip = 1;
+               break;
+       case AR5K_SREV_RAD_5424:
+               if (ah->ah_mac_version == AR5K_SREV_AR2425 ||
+                   ah->ah_mac_version == AR5K_SREV_AR2417) {
+                       ah->ah_radio = AR5K_RF2425;
+               } else {
+                       ah->ah_radio = AR5K_RF5413;
+               }
+               ah->ah_single_chip = 1;
+               break;
+       default:
+               /* Identify radio based on mac/phy srev */
+               if (ah->ah_version == AR5K_AR5210) {
+                       ah->ah_radio = AR5K_RF5110;
+                       ah->ah_single_chip = 0;
+               } else if (ah->ah_version == AR5K_AR5211) {
+                       ah->ah_radio = AR5K_RF5111;
+                       ah->ah_single_chip = 0;
+                       ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
+                                                               CHANNEL_2GHZ);
+               } else if (ah->ah_mac_version == (AR5K_SREV_AR2425 >> 4) ||
+                          ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4) ||
+                          ah->ah_phy_revision == AR5K_SREV_PHY_2425) {
+                       ah->ah_radio = AR5K_RF2425;
+                       ah->ah_single_chip = 1;
+                       ah->ah_radio_5ghz_revision = AR5K_SREV_RAD_2425;
+               } else if (srev == AR5K_SREV_AR5213A &&
+                          ah->ah_phy_revision == AR5K_SREV_PHY_5212B) {
+                       ah->ah_radio = AR5K_RF5112;
+                       ah->ah_single_chip = 0;
+                       ah->ah_radio_5ghz_revision = AR5K_SREV_RAD_5112B;
+               } else if (ah->ah_mac_version == (AR5K_SREV_AR2415 >> 4)) {
+                       ah->ah_radio = AR5K_RF2316;
+                       ah->ah_single_chip = 1;
+                       ah->ah_radio_5ghz_revision = AR5K_SREV_RAD_2316;
+               } else if (ah->ah_mac_version == (AR5K_SREV_AR5414 >> 4) ||
+                          ah->ah_phy_revision == AR5K_SREV_PHY_5413) {
+                       ah->ah_radio = AR5K_RF5413;
+                       ah->ah_single_chip = 1;
+                       ah->ah_radio_5ghz_revision = AR5K_SREV_RAD_5413;
+               } else if (ah->ah_mac_version == (AR5K_SREV_AR2414 >> 4) ||
+                          ah->ah_phy_revision == AR5K_SREV_PHY_2413) {
+                       ah->ah_radio = AR5K_RF2413;
+                       ah->ah_single_chip = 1;
+                       ah->ah_radio_5ghz_revision = AR5K_SREV_RAD_2413;
+               } else {
+                       DBG("ath5k: Couldn't identify radio revision.\n");
+                       ret = -ENOTSUP;
+                       goto err_free;
+               }
+       }
+
+       /* Return on unsuported chips (unsupported eeprom etc) */
+       if ((srev >= AR5K_SREV_AR5416) &&
+           (srev < AR5K_SREV_AR2425)) {
+               DBG("ath5k: Device not yet supported.\n");
+               ret = -ENOTSUP;
+               goto err_free;
+       }
+
+       /*
+        * Write PCI-E power save settings
+        */
+       if ((ah->ah_version == AR5K_AR5212) &&
+           pci_find_capability(pdev, PCI_CAP_ID_EXP)) {
+               ath5k_hw_reg_write(ah, 0x9248fc00, AR5K_PCIE_SERDES);
+               ath5k_hw_reg_write(ah, 0x24924924, AR5K_PCIE_SERDES);
+               /* Shut off RX when elecidle is asserted */
+               ath5k_hw_reg_write(ah, 0x28000039, AR5K_PCIE_SERDES);
+               ath5k_hw_reg_write(ah, 0x53160824, AR5K_PCIE_SERDES);
+               /* TODO: EEPROM work */
+               ath5k_hw_reg_write(ah, 0xe5980579, AR5K_PCIE_SERDES);
+               /* Shut off PLL and CLKREQ active in L1 */
+               ath5k_hw_reg_write(ah, 0x001defff, AR5K_PCIE_SERDES);
+               /* Preserce other settings */
+               ath5k_hw_reg_write(ah, 0x1aaabe40, AR5K_PCIE_SERDES);
+               ath5k_hw_reg_write(ah, 0xbe105554, AR5K_PCIE_SERDES);
+               ath5k_hw_reg_write(ah, 0x000e3007, AR5K_PCIE_SERDES);
+               /* Reset SERDES to load new settings */
+               ath5k_hw_reg_write(ah, 0x00000000, AR5K_PCIE_SERDES_RESET);
+               mdelay(1);
+       }
+
+       /*
+        * POST
+        */
+       ret = ath5k_hw_post(ah);
+       if (ret)
+               goto err_free;
+
+       /* Enable pci core retry fix on Hainan (5213A) and later chips */
+       if (srev >= AR5K_SREV_AR5213A)
+               ath5k_hw_reg_write(ah, AR5K_PCICFG_RETRY_FIX, AR5K_PCICFG);
+
+       /*
+        * Get card capabilities, calibration values etc
+        * TODO: EEPROM work
+        */
+       ret = ath5k_eeprom_init(ah);
+       if (ret) {
+               DBG("ath5k: unable to init EEPROM\n");
+               goto err_free;
+       }
+
+       /* Get misc capabilities */
+       ret = ath5k_hw_set_capabilities(ah);
+       if (ret) {
+               DBG("ath5k: unable to get device capabilities: 0x%04x\n",
+                   sc->pdev->device);
+               goto err_free;
+       }
+
+       if (srev >= AR5K_SREV_AR2414) {
+               ah->ah_combined_mic = 1;
+               AR5K_REG_ENABLE_BITS(ah, AR5K_MISC_MODE,
+                                    AR5K_MISC_MODE_COMBINED_MIC);
+       }
+
+       /* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */
+       memset(ah->ah_bssid, 0xff, ETH_ALEN);
+       ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
+       ath5k_hw_set_opmode(ah);
+
+       ath5k_hw_rfgain_opt_init(ah);
+
+       *hw = ah;
+       return 0;
+err_free:
+       free(ah);
+err:
+       return ret;
+}
+
+/**
+ * ath5k_hw_detach - Free the ath5k_hw struct
+ *
+ * @ah: The &struct ath5k_hw
+ */
+void ath5k_hw_detach(struct ath5k_hw *ah)
+{
+       free(ah->ah_rf_banks);
+       ath5k_eeprom_detach(ah);
+       free(ah);
+}
diff --git a/src/drivers/net/ath5k/ath5k_caps.c b/src/drivers/net/ath5k/ath5k_caps.c
new file mode 100644 (file)
index 0000000..1d60d74
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
+ * Copyright (c) 2007-2008 Jiri Slaby <jirislaby@gmail.com>
+ *
+ * Lightly modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+FILE_LICENCE ( MIT );
+
+/**************\
+* Capabilities *
+\**************/
+
+#include "ath5k.h"
+#include "reg.h"
+#include "base.h"
+
+/*
+ * Fill the capabilities struct
+ * TODO: Merge this with EEPROM code when we are done with it
+ */
+int ath5k_hw_set_capabilities(struct ath5k_hw *ah)
+{
+       u16 ee_header;
+
+       /* Capabilities stored in the EEPROM */
+       ee_header = ah->ah_capabilities.cap_eeprom.ee_header;
+
+       if (ah->ah_version == AR5K_AR5210) {
+               /*
+                * Set radio capabilities
+                * (The AR5110 only supports the middle 5GHz band)
+                */
+               ah->ah_capabilities.cap_range.range_5ghz_min = 5120;
+               ah->ah_capabilities.cap_range.range_5ghz_max = 5430;
+               ah->ah_capabilities.cap_range.range_2ghz_min = 0;
+               ah->ah_capabilities.cap_range.range_2ghz_max = 0;
+
+               /* Set supported modes */
+               ah->ah_capabilities.cap_mode |= AR5K_MODE_BIT_11A;
+               ah->ah_capabilities.cap_mode |= AR5K_MODE_BIT_11A_TURBO;
+       } else {
+               /*
+                * XXX The tranceiver supports frequencies from 4920 to 6100GHz
+                * XXX and from 2312 to 2732GHz. There are problems with the
+                * XXX current ieee80211 implementation because the IEEE
+                * XXX channel mapping does not support negative channel
+                * XXX numbers (2312MHz is channel -19). Of course, this
+                * XXX doesn't matter because these channels are out of range
+                * XXX but some regulation domains like MKK (Japan) will
+                * XXX support frequencies somewhere around 4.8GHz.
+                */
+
+               /*
+                * Set radio capabilities
+                */
+
+               if (AR5K_EEPROM_HDR_11A(ee_header)) {
+                       /* 4920 */
+                       ah->ah_capabilities.cap_range.range_5ghz_min = 5005;
+                       ah->ah_capabilities.cap_range.range_5ghz_max = 6100;
+
+                       /* Set supported modes */
+                       ah->ah_capabilities.cap_mode |= AR5K_MODE_BIT_11A;
+                       ah->ah_capabilities.cap_mode |= AR5K_MODE_BIT_11A_TURBO;
+                       if (ah->ah_version == AR5K_AR5212)
+                               ah->ah_capabilities.cap_mode |=
+                                       AR5K_MODE_BIT_11G_TURBO;
+               }
+
+               /* Enable  802.11b if a 2GHz capable radio (2111/5112) is
+                * connected */
+               if (AR5K_EEPROM_HDR_11B(ee_header) ||
+                   (AR5K_EEPROM_HDR_11G(ee_header) &&
+                    ah->ah_version != AR5K_AR5211)) {
+                       /* 2312 */
+                       ah->ah_capabilities.cap_range.range_2ghz_min = 2412;
+                       ah->ah_capabilities.cap_range.range_2ghz_max = 2732;
+
+                       if (AR5K_EEPROM_HDR_11B(ee_header))
+                               ah->ah_capabilities.cap_mode |=
+                                       AR5K_MODE_BIT_11B;
+
+                       if (AR5K_EEPROM_HDR_11G(ee_header) &&
+                           ah->ah_version != AR5K_AR5211)
+                               ah->ah_capabilities.cap_mode |=
+                                       AR5K_MODE_BIT_11G;
+               }
+       }
+
+       /* GPIO */
+       ah->ah_gpio_npins = AR5K_NUM_GPIO;
+
+       /* Set number of supported TX queues */
+       ah->ah_capabilities.cap_queues.q_tx_num = 1;
+
+       return 0;
+}
+
+/* Main function used by the driver part to check caps */
+int ath5k_hw_get_capability(struct ath5k_hw *ah,
+               enum ath5k_capability_type cap_type,
+               u32 capability __unused, u32 *result)
+{
+       switch (cap_type) {
+       case AR5K_CAP_NUM_TXQUEUES:
+               if (result) {
+                       *result = 1;
+                       goto yes;
+               }
+       case AR5K_CAP_VEOL:
+               goto yes;
+       case AR5K_CAP_COMPRESSION:
+               if (ah->ah_version == AR5K_AR5212)
+                       goto yes;
+               else
+                       goto no;
+       case AR5K_CAP_BURST:
+               goto yes;
+       case AR5K_CAP_TPC:
+               goto yes;
+       case AR5K_CAP_BSSIDMASK:
+               if (ah->ah_version == AR5K_AR5212)
+                       goto yes;
+               else
+                       goto no;
+       case AR5K_CAP_XR:
+               if (ah->ah_version == AR5K_AR5212)
+                       goto yes;
+               else
+                       goto no;
+       default:
+               goto no;
+       }
+
+no:
+       return -EINVAL;
+yes:
+       return 0;
+}
diff --git a/src/drivers/net/ath5k/ath5k_desc.c b/src/drivers/net/ath5k/ath5k_desc.c
new file mode 100644 (file)
index 0000000..c839ec5
--- /dev/null
@@ -0,0 +1,554 @@
+/*
+ * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
+ * Copyright (c) 2007-2008 Pavel Roskin <proski@gnu.org>
+ *
+ * Lightly modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+FILE_LICENCE ( MIT );
+
+/******************************\
+ Hardware Descriptor Functions
+\******************************/
+
+#include "ath5k.h"
+#include "reg.h"
+#include "base.h"
+
+/*
+ * TX Descriptors
+ */
+
+#define FCS_LEN        4
+
+/*
+ * Initialize the 2-word tx control descriptor on 5210/5211
+ */
+static int
+ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
+       unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
+       unsigned int tx_power __unused, unsigned int tx_rate0, unsigned int tx_tries0,
+       unsigned int key_index __unused, unsigned int antenna_mode, unsigned int flags,
+       unsigned int rtscts_rate __unused, unsigned int rtscts_duration)
+{
+       u32 frame_type;
+       struct ath5k_hw_2w_tx_ctl *tx_ctl;
+       unsigned int frame_len;
+
+       tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
+
+       /*
+        * Validate input
+        * - Zero retries don't make sense.
+        * - A zero rate will put the HW into a mode where it continously sends
+        *   noise on the channel, so it is important to avoid this.
+        */
+       if (tx_tries0 == 0) {
+               DBG("ath5k: zero retries\n");
+               return -EINVAL;
+       }
+       if (tx_rate0 == 0) {
+               DBG("ath5k: zero rate\n");
+               return -EINVAL;
+       }
+
+       /* Clear descriptor */
+       memset(&desc->ud.ds_tx5210, 0, sizeof(struct ath5k_hw_5210_tx_desc));
+
+       /* Setup control descriptor */
+
+       /* Verify and set frame length */
+
+       frame_len = pkt_len + FCS_LEN;
+
+       if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
+               return -EINVAL;
+
+       tx_ctl->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
+
+       /* Verify and set buffer length */
+
+       if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
+               return -EINVAL;
+
+       tx_ctl->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
+
+       /*
+        * Verify and set header length
+        * XXX: I only found that on 5210 code, does it work on 5211 ?
+        */
+       if (ah->ah_version == AR5K_AR5210) {
+               if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN)
+                       return -EINVAL;
+               tx_ctl->tx_control_0 |=
+                       AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
+       }
+
+       /*Diferences between 5210-5211*/
+       if (ah->ah_version == AR5K_AR5210) {
+               switch (type) {
+               case AR5K_PKT_TYPE_BEACON:
+               case AR5K_PKT_TYPE_PROBE_RESP:
+                       frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
+               case AR5K_PKT_TYPE_PIFS:
+                       frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
+               default:
+                       frame_type = type /*<< 2 ?*/;
+               }
+
+               tx_ctl->tx_control_0 |=
+               AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE) |
+               AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
+
+       } else {
+               tx_ctl->tx_control_0 |=
+                       AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
+                       AR5K_REG_SM(antenna_mode,
+                               AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
+               tx_ctl->tx_control_1 |=
+                       AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE);
+       }
+#define _TX_FLAGS(_c, _flag)                                   \
+       if (flags & AR5K_TXDESC_##_flag) {                      \
+               tx_ctl->tx_control_##_c |=                      \
+                       AR5K_2W_TX_DESC_CTL##_c##_##_flag;      \
+       }
+
+       _TX_FLAGS(0, CLRDMASK);
+       _TX_FLAGS(0, VEOL);
+       _TX_FLAGS(0, INTREQ);
+       _TX_FLAGS(0, RTSENA);
+       _TX_FLAGS(1, NOACK);
+
+#undef _TX_FLAGS
+
+       /*
+        * RTS/CTS Duration [5210 ?]
+        */
+       if ((ah->ah_version == AR5K_AR5210) &&
+                       (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
+               tx_ctl->tx_control_1 |= rtscts_duration &
+                               AR5K_2W_TX_DESC_CTL1_RTS_DURATION;
+
+       return 0;
+}
+
+/*
+ * Initialize the 4-word tx control descriptor on 5212
+ */
+static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
+       struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len __unused,
+       enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
+       unsigned int tx_tries0, unsigned int key_index __unused,
+       unsigned int antenna_mode, unsigned int flags,
+       unsigned int rtscts_rate,
+       unsigned int rtscts_duration)
+{
+       struct ath5k_hw_4w_tx_ctl *tx_ctl;
+       unsigned int frame_len;
+
+       tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
+
+       /*
+        * Validate input
+        * - Zero retries don't make sense.
+        * - A zero rate will put the HW into a mode where it continously sends
+        *   noise on the channel, so it is important to avoid this.
+        */
+       if (tx_tries0 == 0) {
+               DBG("ath5k: zero retries\n");
+               return -EINVAL;
+       }
+       if (tx_rate0 == 0) {
+               DBG("ath5k: zero rate\n");
+               return -EINVAL;
+       }
+
+       tx_power += ah->ah_txpower.txp_offset;
+       if (tx_power > AR5K_TUNE_MAX_TXPOWER)
+               tx_power = AR5K_TUNE_MAX_TXPOWER;
+
+       /* Clear descriptor */
+       memset(&desc->ud.ds_tx5212, 0, sizeof(struct ath5k_hw_5212_tx_desc));
+
+       /* Setup control descriptor */
+
+       /* Verify and set frame length */
+
+       frame_len = pkt_len + FCS_LEN;
+
+       if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
+               return -EINVAL;
+
+       tx_ctl->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
+
+       /* Verify and set buffer length */
+
+       if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
+               return -EINVAL;
+
+       tx_ctl->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
+
+       tx_ctl->tx_control_0 |=
+               AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
+               AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
+       tx_ctl->tx_control_1 |= AR5K_REG_SM(type,
+                                       AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
+       tx_ctl->tx_control_2 = AR5K_REG_SM(tx_tries0 + AR5K_TUNE_HWTXTRIES,
+                                       AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
+       tx_ctl->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
+
+#define _TX_FLAGS(_c, _flag)                                   \
+       if (flags & AR5K_TXDESC_##_flag) {                      \
+               tx_ctl->tx_control_##_c |=                      \
+                       AR5K_4W_TX_DESC_CTL##_c##_##_flag;      \
+       }
+
+       _TX_FLAGS(0, CLRDMASK);
+       _TX_FLAGS(0, VEOL);
+       _TX_FLAGS(0, INTREQ);
+       _TX_FLAGS(0, RTSENA);
+       _TX_FLAGS(0, CTSENA);
+       _TX_FLAGS(1, NOACK);
+
+#undef _TX_FLAGS
+
+       /*
+        * RTS/CTS
+        */
+       if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
+               if ((flags & AR5K_TXDESC_RTSENA) &&
+                               (flags & AR5K_TXDESC_CTSENA))
+                       return -EINVAL;
+               tx_ctl->tx_control_2 |= rtscts_duration &
+                               AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
+               tx_ctl->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
+                               AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
+       }
+
+       return 0;
+}
+
+/*
+ * Proccess the tx status descriptor on 5210/5211
+ */
+static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah __unused,
+               struct ath5k_desc *desc, struct ath5k_tx_status *ts)
+{
+       struct ath5k_hw_2w_tx_ctl *tx_ctl;
+       struct ath5k_hw_tx_status *tx_status;
+
+       tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
+       tx_status = &desc->ud.ds_tx5210.tx_stat;
+
+       /* No frame has been send or error */
+       if ((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0)
+               return -EINPROGRESS;
+
+       /*
+        * Get descriptor status
+        */
+       ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
+               AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
+       ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
+               AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
+       ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
+               AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
+       /*TODO: ts->ts_virtcol + test*/
+       ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
+               AR5K_DESC_TX_STATUS1_SEQ_NUM);
+       ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
+               AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
+       ts->ts_antenna = 1;
+       ts->ts_status = 0;
+       ts->ts_rate[0] = AR5K_REG_MS(tx_ctl->tx_control_0,
+               AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
+       ts->ts_retry[0] = ts->ts_longretry;
+       ts->ts_final_idx = 0;
+
+       if (!(tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK)) {
+               if (tx_status->tx_status_0 &
+                               AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
+                       ts->ts_status |= AR5K_TXERR_XRETRY;
+
+               if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
+                       ts->ts_status |= AR5K_TXERR_FIFO;
+
+               if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
+                       ts->ts_status |= AR5K_TXERR_FILT;
+       }
+
+       return 0;
+}
+
+/*
+ * Proccess a tx status descriptor on 5212
+ */
+static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah __unused,
+               struct ath5k_desc *desc, struct ath5k_tx_status *ts)
+{
+       struct ath5k_hw_4w_tx_ctl *tx_ctl;
+       struct ath5k_hw_tx_status *tx_status;
+
+       tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
+       tx_status = &desc->ud.ds_tx5212.tx_stat;
+
+       /* No frame has been send or error */
+       if (!(tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE))
+               return -EINPROGRESS;
+
+       /*
+        * Get descriptor status
+        */
+       ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
+               AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
+       ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
+               AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
+       ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
+               AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
+       ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
+               AR5K_DESC_TX_STATUS1_SEQ_NUM);
+       ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
+               AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
+       ts->ts_antenna = (tx_status->tx_status_1 &
+               AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
+       ts->ts_status = 0;
+
+       ts->ts_final_idx = AR5K_REG_MS(tx_status->tx_status_1,
+                       AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX);
+
+       ts->ts_retry[0] = ts->ts_longretry;
+       ts->ts_rate[0] = tx_ctl->tx_control_3 &
+               AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
+
+       /* TX error */
+       if (!(tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK)) {
+               if (tx_status->tx_status_0 &
+                               AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
+                       ts->ts_status |= AR5K_TXERR_XRETRY;
+
+               if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
+                       ts->ts_status |= AR5K_TXERR_FIFO;
+
+               if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
+                       ts->ts_status |= AR5K_TXERR_FILT;
+       }
+
+       return 0;
+}
+
+/*
+ * RX Descriptors
+ */
+
+/*
+ * Initialize an rx control descriptor
+ */
+static int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah __unused,
+                                 struct ath5k_desc *desc,
+                                 u32 size, unsigned int flags)
+{
+       struct ath5k_hw_rx_ctl *rx_ctl;
+
+       rx_ctl = &desc->ud.ds_rx.rx_ctl;
+
+       /*
+        * Clear the descriptor
+        * If we don't clean the status descriptor,
+        * while scanning we get too many results,
+        * most of them virtual, after some secs
+        * of scanning system hangs. M.F.
+       */
+       memset(&desc->ud.ds_rx, 0, sizeof(struct ath5k_hw_all_rx_desc));
+
+       /* Setup descriptor */
+       rx_ctl->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
+       if (rx_ctl->rx_control_1 != size)
+               return -EINVAL;
+
+       if (flags & AR5K_RXDESC_INTREQ)
+               rx_ctl->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
+
+       if (desc->ds_link < ah->ah_sc->desc_daddr ||
+           desc->ds_link + sizeof(struct ath5k_desc) > ah->ah_sc->desc_daddr + ah->ah_sc->desc_len ||
+           size != 2400 ||
+           *(void **)bus_to_virt(desc->ds_data + 2408) != bus_to_virt(desc->ds_data)) {
+               DBG("ath5k! set rx desc %p for %d bytes at %p (%08x) link to %p (%08x)\n",
+                   desc, size, bus_to_virt(desc->ds_data), desc->ds_data,
+                   bus_to_virt(desc->ds_link), desc->ds_link);
+               asm("cli;hlt");
+       }
+
+       return 0;
+}
+
+/*
+ * Proccess the rx status descriptor on 5210/5211
+ */
+static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *ah __unused,
+               struct ath5k_desc *desc, struct ath5k_rx_status *rs)
+{
+       struct ath5k_hw_rx_status *rx_status;
+
+       rx_status = &desc->ud.ds_rx.u.rx_stat;
+
+       /* No frame received / not ready */
+       if (!(rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_DONE))
+               return -EINPROGRESS;
+
+       /*
+        * Frame receive status
+        */
+       rs->rs_datalen = rx_status->rx_status_0 &
+               AR5K_5210_RX_DESC_STATUS0_DATA_LEN;
+       rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
+               AR5K_5210_RX_DESC_STATUS0_RECEIVE_SIGNAL);
+       rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
+               AR5K_5210_RX_DESC_STATUS0_RECEIVE_RATE);
+       rs->rs_antenna = AR5K_REG_MS(rx_status->rx_status_0,
+               AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANTENNA);
+       rs->rs_more = !!(rx_status->rx_status_0 &
+               AR5K_5210_RX_DESC_STATUS0_MORE);
+       /* TODO: this timestamp is 13 bit, later on we assume 15 bit */
+       rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
+               AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
+       rs->rs_status = 0;
+       rs->rs_phyerr = 0;
+       rs->rs_keyix = AR5K_RXKEYIX_INVALID;
+
+       /*
+        * Receive/descriptor errors
+        */
+       if (!(rx_status->rx_status_1 &
+             AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK)) {
+               if (rx_status->rx_status_1 &
+                               AR5K_5210_RX_DESC_STATUS1_CRC_ERROR)
+                       rs->rs_status |= AR5K_RXERR_CRC;
+
+               if (rx_status->rx_status_1 &
+                               AR5K_5210_RX_DESC_STATUS1_FIFO_OVERRUN)
+                       rs->rs_status |= AR5K_RXERR_FIFO;
+
+               if (rx_status->rx_status_1 &
+                               AR5K_5210_RX_DESC_STATUS1_PHY_ERROR) {
+                       rs->rs_status |= AR5K_RXERR_PHY;
+                       rs->rs_phyerr |= AR5K_REG_MS(rx_status->rx_status_1,
+                               AR5K_5210_RX_DESC_STATUS1_PHY_ERROR);
+               }
+
+               if (rx_status->rx_status_1 &
+                               AR5K_5210_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
+                       rs->rs_status |= AR5K_RXERR_DECRYPT;
+       }
+
+       return 0;
+}
+
+/*
+ * Proccess the rx status descriptor on 5212
+ */
+static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *ah __unused,
+               struct ath5k_desc *desc, struct ath5k_rx_status *rs)
+{
+       struct ath5k_hw_rx_status *rx_status;
+       struct ath5k_hw_rx_error *rx_err;
+
+       rx_status = &desc->ud.ds_rx.u.rx_stat;
+
+       /* Overlay on error */
+       rx_err = &desc->ud.ds_rx.u.rx_err;
+
+       /* No frame received / not ready */
+       if (!(rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_DONE))
+               return -EINPROGRESS;
+
+       /*
+        * Frame receive status
+        */
+       rs->rs_datalen = rx_status->rx_status_0 &
+               AR5K_5212_RX_DESC_STATUS0_DATA_LEN;
+       rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
+               AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL);
+       rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
+               AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE);
+       rs->rs_antenna = AR5K_REG_MS(rx_status->rx_status_0,
+               AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA);
+       rs->rs_more = !!(rx_status->rx_status_0 &
+               AR5K_5212_RX_DESC_STATUS0_MORE);
+       rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
+               AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
+       rs->rs_status = 0;
+       rs->rs_phyerr = 0;
+       rs->rs_keyix = AR5K_RXKEYIX_INVALID;
+
+       /*
+        * Receive/descriptor errors
+        */
+       if (!(rx_status->rx_status_1 &
+             AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK)) {
+               if (rx_status->rx_status_1 &
+                               AR5K_5212_RX_DESC_STATUS1_CRC_ERROR)
+                       rs->rs_status |= AR5K_RXERR_CRC;
+
+               if (rx_status->rx_status_1 &
+                               AR5K_5212_RX_DESC_STATUS1_PHY_ERROR) {
+                       rs->rs_status |= AR5K_RXERR_PHY;
+                       rs->rs_phyerr |= AR5K_REG_MS(rx_err->rx_error_1,
+                                          AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
+               }
+
+               if (rx_status->rx_status_1 &
+                               AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
+                       rs->rs_status |= AR5K_RXERR_DECRYPT;
+
+               if (rx_status->rx_status_1 &
+                               AR5K_5212_RX_DESC_STATUS1_MIC_ERROR)
+                       rs->rs_status |= AR5K_RXERR_MIC;
+       }
+
+       return 0;
+}
+
+/*
+ * Init function pointers inside ath5k_hw struct
+ */
+int ath5k_hw_init_desc_functions(struct ath5k_hw *ah)
+{
+
+       if (ah->ah_version != AR5K_AR5210 &&
+           ah->ah_version != AR5K_AR5211 &&
+           ah->ah_version != AR5K_AR5212)
+               return -ENOTSUP;
+
+       if (ah->ah_version == AR5K_AR5212) {
+               ah->ah_setup_rx_desc = ath5k_hw_setup_rx_desc;
+               ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
+               ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
+       } else {
+               ah->ah_setup_rx_desc = ath5k_hw_setup_rx_desc;
+               ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
+               ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
+       }
+
+       if (ah->ah_version == AR5K_AR5212)
+               ah->ah_proc_rx_desc = ath5k_hw_proc_5212_rx_status;
+       else if (ah->ah_version <= AR5K_AR5211)
+               ah->ah_proc_rx_desc = ath5k_hw_proc_5210_rx_status;
+
+       return 0;
+}
+
diff --git a/src/drivers/net/ath5k/ath5k_dma.c b/src/drivers/net/ath5k/ath5k_dma.c
new file mode 100644 (file)
index 0000000..23c4cf9
--- /dev/null
@@ -0,0 +1,631 @@
+/*
+ * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
+ *
+ * Lightly modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+FILE_LICENCE ( MIT );
+
+/*************************************\
+* DMA and interrupt masking functions *
+\*************************************/
+
+/*
+ * dma.c - DMA and interrupt masking functions
+ *
+ * Here we setup descriptor pointers (rxdp/txdp) start/stop dma engine and
+ * handle queue setup for 5210 chipset (rest are handled on qcu.c).
+ * Also we setup interrupt mask register (IMR) and read the various iterrupt
+ * status registers (ISR).
+ *
+ * TODO: Handle SISR on 5211+ and introduce a function to return the queue
+ * number that resulted the interrupt.
+ */
+
+#include <unistd.h>
+
+#include "ath5k.h"
+#include "reg.h"
+#include "base.h"
+
+/*********\
+* Receive *
+\*********/
+
+/**
+ * ath5k_hw_start_rx_dma - Start DMA receive
+ *
+ * @ah:        The &struct ath5k_hw
+ */
+void ath5k_hw_start_rx_dma(struct ath5k_hw *ah)
+{
+       ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
+       ath5k_hw_reg_read(ah, AR5K_CR);
+}
+
+/**
+ * ath5k_hw_stop_rx_dma - Stop DMA receive
+ *
+ * @ah:        The &struct ath5k_hw
+ */
+int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
+{
+       unsigned int i;
+
+       ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
+
+       /*
+        * It may take some time to disable the DMA receive unit
+        */
+       for (i = 1000; i > 0 &&
+                       (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
+                       i--)
+               udelay(10);
+
+       return i ? 0 : -EBUSY;
+}
+
+/**
+ * ath5k_hw_get_rxdp - Get RX Descriptor's address
+ *
+ * @ah: The &struct ath5k_hw
+ *
+ * XXX: Is RXDP read and clear ?
+ */
+u32 ath5k_hw_get_rxdp(struct ath5k_hw *ah)
+{
+       return ath5k_hw_reg_read(ah, AR5K_RXDP);
+}
+
+/**
+ * ath5k_hw_set_rxdp - Set RX Descriptor's address
+ *
+ * @ah: The &struct ath5k_hw
+ * @phys_addr: RX descriptor address
+ *
+ * XXX: Should we check if rx is enabled before setting rxdp ?
+ */
+void ath5k_hw_set_rxdp(struct ath5k_hw *ah, u32 phys_addr)
+{
+       ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP);
+}
+
+
+/**********\
+* Transmit *
+\**********/
+
+/**
+ * ath5k_hw_start_tx_dma - Start DMA transmit for a specific queue
+ *
+ * @ah: The &struct ath5k_hw
+ * @queue: The hw queue number
+ *
+ * Start DMA transmit for a specific queue and since 5210 doesn't have
+ * QCU/DCU, set up queue parameters for 5210 here based on queue type (one
+ * queue for normal data and one queue for beacons). For queue setup
+ * on newer chips check out qcu.c. Returns -EINVAL if queue number is out
+ * of range or if queue is already disabled.
+ *
+ * NOTE: Must be called after setting up tx control descriptor for that
+ * queue (see below).
+ */
+int ath5k_hw_start_tx_dma(struct ath5k_hw *ah, unsigned int queue)
+{
+       u32 tx_queue;
+
+       /* Return if queue is declared inactive */
+       if (ah->ah_txq.tqi_type == AR5K_TX_QUEUE_INACTIVE)
+               return -EIO;
+
+       if (ah->ah_version == AR5K_AR5210) {
+               tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
+
+               /* Assume always a data queue */
+               tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
+
+               /* Start queue */
+               ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
+               ath5k_hw_reg_read(ah, AR5K_CR);
+       } else {
+               /* Return if queue is disabled */
+               if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
+                       return -EIO;
+
+               /* Start queue */
+               AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
+       }
+
+       return 0;
+}
+
+/**
+ * ath5k_hw_stop_tx_dma - Stop DMA transmit on a specific queue
+ *
+ * @ah: The &struct ath5k_hw
+ * @queue: The hw queue number
+ *
+ * Stop DMA transmit on a specific hw queue and drain queue so we don't
+ * have any pending frames. Returns -EBUSY if we still have pending frames,
+ * -EINVAL if queue number is out of range.
+ *
+ */
+int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
+{
+       unsigned int i = 40;
+       u32 tx_queue, pending;
+
+       /* Return if queue is declared inactive */
+       if (ah->ah_txq.tqi_type == AR5K_TX_QUEUE_INACTIVE)
+               return -EIO;
+
+       if (ah->ah_version == AR5K_AR5210) {
+               tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
+
+               /* Assume a data queue */
+               tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
+
+               /* Stop queue */
+               ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
+               ath5k_hw_reg_read(ah, AR5K_CR);
+       } else {
+               /*
+                * Schedule TX disable and wait until queue is empty
+                */
+               AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
+
+               /*Check for pending frames*/
+               do {
+                       pending = ath5k_hw_reg_read(ah,
+                               AR5K_QUEUE_STATUS(queue)) &
+                               AR5K_QCU_STS_FRMPENDCNT;
+                       udelay(100);
+               } while (--i && pending);
+
+               /* For 2413+ order PCU to drop packets using
+                * QUIET mechanism */
+               if (ah->ah_mac_version >= (AR5K_SREV_AR2414 >> 4) && pending) {
+                       /* Set periodicity and duration */
+                       ath5k_hw_reg_write(ah,
+                               AR5K_REG_SM(100, AR5K_QUIET_CTL2_QT_PER)|
+                               AR5K_REG_SM(10, AR5K_QUIET_CTL2_QT_DUR),
+                               AR5K_QUIET_CTL2);
+
+                       /* Enable quiet period for current TSF */
+                       ath5k_hw_reg_write(ah,
+                               AR5K_QUIET_CTL1_QT_EN |
+                               AR5K_REG_SM(ath5k_hw_reg_read(ah,
+                                               AR5K_TSF_L32_5211) >> 10,
+                                               AR5K_QUIET_CTL1_NEXT_QT_TSF),
+                               AR5K_QUIET_CTL1);
+
+                       /* Force channel idle high */
+                       AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW_5211,
+                                       AR5K_DIAG_SW_CHANEL_IDLE_HIGH);
+
+                       /* Wait a while and disable mechanism */
+                       udelay(200);
+                       AR5K_REG_DISABLE_BITS(ah, AR5K_QUIET_CTL1,
+                                               AR5K_QUIET_CTL1_QT_EN);
+
+                       /* Re-check for pending frames */
+                       i = 40;
+                       do {
+                               pending = ath5k_hw_reg_read(ah,
+                                       AR5K_QUEUE_STATUS(queue)) &
+                                       AR5K_QCU_STS_FRMPENDCNT;
+                               udelay(100);
+                       } while (--i && pending);
+
+                       AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW_5211,
+                                       AR5K_DIAG_SW_CHANEL_IDLE_HIGH);
+               }
+
+               /* Clear register */
+               ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
+               if (pending)
+                       return -EBUSY;
+       }
+
+       /* TODO: Check for success on 5210 else return error */
+       return 0;
+}
+
+/**
+ * ath5k_hw_get_txdp - Get TX Descriptor's address for a specific queue
+ *
+ * @ah: The &struct ath5k_hw
+ * @queue: The hw queue number
+ *
+ * Get TX descriptor's address for a specific queue. For 5210 we ignore
+ * the queue number and use tx queue type since we only have 2 queues.
+ * We use TXDP0 for normal data queue and TXDP1 for beacon queue.
+ * For newer chips with QCU/DCU we just read the corresponding TXDP register.
+ *
+ * XXX: Is TXDP read and clear ?
+ */
+u32 ath5k_hw_get_txdp(struct ath5k_hw *ah, unsigned int queue)
+{
+       u16 tx_reg;
+
+       /*
+        * Get the transmit queue descriptor pointer from the selected queue
+        */
+       /*5210 doesn't have QCU*/
+       if (ah->ah_version == AR5K_AR5210) {
+               /* Assume a data queue */
+               tx_reg = AR5K_NOQCU_TXDP0;
+       } else {
+               tx_reg = AR5K_QUEUE_TXDP(queue);
+       }
+
+       return ath5k_hw_reg_read(ah, tx_reg);
+}
+
+/**
+ * ath5k_hw_set_txdp - Set TX Descriptor's address for a specific queue
+ *
+ * @ah: The &struct ath5k_hw
+ * @queue: The hw queue number
+ *
+ * Set TX descriptor's address for a specific queue. For 5210 we ignore
+ * the queue number and we use tx queue type since we only have 2 queues
+ * so as above we use TXDP0 for normal data queue and TXDP1 for beacon queue.
+ * For newer chips with QCU/DCU we just set the corresponding TXDP register.
+ * Returns -EINVAL if queue type is invalid for 5210 and -EIO if queue is still
+ * active.
+ */
+int ath5k_hw_set_txdp(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
+{
+       u16 tx_reg;
+
+       /*
+        * Set the transmit queue descriptor pointer register by type
+        * on 5210
+        */
+       if (ah->ah_version == AR5K_AR5210) {
+               /* Assume a data queue */
+               tx_reg = AR5K_NOQCU_TXDP0;
+       } else {
+               /*
+                * Set the transmit queue descriptor pointer for
+                * the selected queue on QCU for 5211+
+                * (this won't work if the queue is still active)
+                */
+               if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
+                       return -EIO;
+
+               tx_reg = AR5K_QUEUE_TXDP(queue);
+       }
+
+       /* Set descriptor pointer */
+       ath5k_hw_reg_write(ah, phys_addr, tx_reg);
+
+       return 0;
+}
+
+/**
+ * ath5k_hw_update_tx_triglevel - Update tx trigger level
+ *
+ * @ah: The &struct ath5k_hw
+ * @increase: Flag to force increase of trigger level
+ *
+ * This function increases/decreases the tx trigger level for the tx fifo
+ * buffer (aka FIFO threshold) that is used to indicate when PCU flushes
+ * the buffer and transmits it's data. Lowering this results sending small
+ * frames more quickly but can lead to tx underruns, raising it a lot can
+ * result other problems (i think bmiss is related). Right now we start with
+ * the lowest possible (64Bytes) and if we get tx underrun we increase it using
+ * the increase flag. Returns -EIO if we have have reached maximum/minimum.
+ *
+ * XXX: Link this with tx DMA size ?
+ * XXX: Use it to save interrupts ?
+ * TODO: Needs testing, i think it's related to bmiss...
+ */
+int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, int increase)
+{
+       u32 trigger_level, imr;
+       int ret = -EIO;
+
+       /*
+        * Disable interrupts by setting the mask
+        */
+       imr = ath5k_hw_set_imr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
+
+       trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
+                       AR5K_TXCFG_TXFULL);
+
+       if (!increase) {
+               if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
+                       goto done;
+       } else
+               trigger_level +=
+                       ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
+
+       /*
+        * Update trigger level on success
+        */
+       if (ah->ah_version == AR5K_AR5210)
+               ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
+       else
+               AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
+                               AR5K_TXCFG_TXFULL, trigger_level);
+
+       ret = 0;
+
+done:
+       /*
+        * Restore interrupt mask
+        */
+       ath5k_hw_set_imr(ah, imr);
+
+       return ret;
+}
+
+/*******************\
+* Interrupt masking *
+\*******************/
+
+/**
+ * ath5k_hw_is_intr_pending - Check if we have pending interrupts
+ *
+ * @ah: The &struct ath5k_hw
+ *
+ * Check if we have pending interrupts to process. Returns 1 if we
+ * have pending interrupts and 0 if we haven't.
+ */
+int ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
+{
+       return ath5k_hw_reg_read(ah, AR5K_INTPEND) == 1 ? 1 : 0;
+}
+
+/**
+ * ath5k_hw_get_isr - Get interrupt status
+ *
+ * @ah: The @struct ath5k_hw
+ * @interrupt_mask: Driver's interrupt mask used to filter out
+ * interrupts in sw.
+ *
+ * This function is used inside our interrupt handler to determine the reason
+ * for the interrupt by reading Primary Interrupt Status Register. Returns an
+ * abstract interrupt status mask which is mostly ISR with some uncommon bits
+ * being mapped on some standard non hw-specific positions
+ * (check out &ath5k_int).
+ *
+ * NOTE: We use read-and-clear register, so after this function is called ISR
+ * is zeroed.
+ */
+int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
+{
+       u32 data;
+
+       /*
+        * Read interrupt status from the Interrupt Status register
+        * on 5210
+        */
+       if (ah->ah_version == AR5K_AR5210) {
+               data = ath5k_hw_reg_read(ah, AR5K_ISR);
+               if (data == AR5K_INT_NOCARD) {
+                       *interrupt_mask = data;
+                       return -ENODEV;
+               }
+       } else {
+               /*
+                * Read interrupt status from Interrupt
+                * Status Register shadow copy (Read And Clear)
+                *
+                * Note: PISR/SISR Not available on 5210
+                */
+               data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
+               if (data == AR5K_INT_NOCARD) {
+                       *interrupt_mask = data;
+                       return -ENODEV;
+               }
+       }
+
+       /*
+        * Get abstract interrupt mask (driver-compatible)
+        */
+       *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
+
+       if (ah->ah_version != AR5K_AR5210) {
+               u32 sisr2 = ath5k_hw_reg_read(ah, AR5K_RAC_SISR2);
+
+               /*HIU = Host Interface Unit (PCI etc)*/
+               if (data & (AR5K_ISR_HIUERR))
+                       *interrupt_mask |= AR5K_INT_FATAL;
+
+               /*Beacon Not Ready*/
+               if (data & (AR5K_ISR_BNR))
+                       *interrupt_mask |= AR5K_INT_BNR;
+
+               if (sisr2 & (AR5K_SISR2_SSERR | AR5K_SISR2_DPERR |
+                            AR5K_SISR2_MCABT))
+                       *interrupt_mask |= AR5K_INT_FATAL;
+
+               if (data & AR5K_ISR_TIM)
+                       *interrupt_mask |= AR5K_INT_TIM;
+
+               if (data & AR5K_ISR_BCNMISC) {
+                       if (sisr2 & AR5K_SISR2_TIM)
+                               *interrupt_mask |= AR5K_INT_TIM;
+                       if (sisr2 & AR5K_SISR2_DTIM)
+                               *interrupt_mask |= AR5K_INT_DTIM;
+                       if (sisr2 & AR5K_SISR2_DTIM_SYNC)
+                               *interrupt_mask |= AR5K_INT_DTIM_SYNC;
+                       if (sisr2 & AR5K_SISR2_BCN_TIMEOUT)
+                               *interrupt_mask |= AR5K_INT_BCN_TIMEOUT;
+                       if (sisr2 & AR5K_SISR2_CAB_TIMEOUT)
+                               *interrupt_mask |= AR5K_INT_CAB_TIMEOUT;
+               }
+
+               if (data & AR5K_ISR_RXDOPPLER)
+                       *interrupt_mask |= AR5K_INT_RX_DOPPLER;
+               if (data & AR5K_ISR_QCBRORN) {
+                       *interrupt_mask |= AR5K_INT_QCBRORN;
+                       ah->ah_txq_isr |= AR5K_REG_MS(
+                                       ath5k_hw_reg_read(ah, AR5K_RAC_SISR3),
+                                       AR5K_SISR3_QCBRORN);
+               }
+               if (data & AR5K_ISR_QCBRURN) {
+                       *interrupt_mask |= AR5K_INT_QCBRURN;
+                       ah->ah_txq_isr |= AR5K_REG_MS(
+                                       ath5k_hw_reg_read(ah, AR5K_RAC_SISR3),
+                                       AR5K_SISR3_QCBRURN);
+               }
+               if (data & AR5K_ISR_QTRIG) {
+                       *interrupt_mask |= AR5K_INT_QTRIG;
+                       ah->ah_txq_isr |= AR5K_REG_MS(
+                                       ath5k_hw_reg_read(ah, AR5K_RAC_SISR4),
+                                       AR5K_SISR4_QTRIG);
+               }
+
+               if (data & AR5K_ISR_TXOK)
+                       ah->ah_txq_isr |= AR5K_REG_MS(
+                                       ath5k_hw_reg_read(ah, AR5K_RAC_SISR0),
+                                       AR5K_SISR0_QCU_TXOK);
+
+               if (data & AR5K_ISR_TXDESC)
+                       ah->ah_txq_isr |= AR5K_REG_MS(
+                                       ath5k_hw_reg_read(ah, AR5K_RAC_SISR0),
+                                       AR5K_SISR0_QCU_TXDESC);
+
+               if (data & AR5K_ISR_TXERR)
+                       ah->ah_txq_isr |= AR5K_REG_MS(
+                                       ath5k_hw_reg_read(ah, AR5K_RAC_SISR1),
+                                       AR5K_SISR1_QCU_TXERR);
+
+               if (data & AR5K_ISR_TXEOL)
+                       ah->ah_txq_isr |= AR5K_REG_MS(
+                                       ath5k_hw_reg_read(ah, AR5K_RAC_SISR1),
+                                       AR5K_SISR1_QCU_TXEOL);
+
+               if (data & AR5K_ISR_TXURN)
+                       ah->ah_txq_isr |= AR5K_REG_MS(
+                                       ath5k_hw_reg_read(ah, AR5K_RAC_SISR2),
+                                       AR5K_SISR2_QCU_TXURN);
+       } else {
+               if (data & (AR5K_ISR_SSERR | AR5K_ISR_MCABT |
+                           AR5K_ISR_HIUERR | AR5K_ISR_DPERR))
+                       *interrupt_mask |= AR5K_INT_FATAL;
+
+               /*
+                * XXX: BMISS interrupts may occur after association.
+                * I found this on 5210 code but it needs testing. If this is
+                * true we should disable them before assoc and re-enable them
+                * after a successful assoc + some jiffies.
+                       interrupt_mask &= ~AR5K_INT_BMISS;
+                */
+       }
+
+       return 0;
+}
+
+/**
+ * ath5k_hw_set_imr - Set interrupt mask
+ *
+ * @ah: The &struct ath5k_hw
+ * @new_mask: The new interrupt mask to be set
+ *
+ * Set the interrupt mask in hw to save interrupts. We do that by mapping
+ * ath5k_int bits to hw-specific bits to remove abstraction and writing
+ * Interrupt Mask Register.
+ */
+enum ath5k_int ath5k_hw_set_imr(struct ath5k_hw *ah, enum ath5k_int new_mask)
+{
+       enum ath5k_int old_mask, int_mask;
+
+       old_mask = ah->ah_imr;
+
+       /*
+        * Disable card interrupts to prevent any race conditions
+        * (they will be re-enabled afterwards if AR5K_INT GLOBAL
+        * is set again on the new mask).
+        */
+       if (old_mask & AR5K_INT_GLOBAL) {
+               ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
+               ath5k_hw_reg_read(ah, AR5K_IER);
+       }
+
+       /*
+        * Add additional, chipset-dependent interrupt mask flags
+        * and write them to the IMR (interrupt mask register).
+        */
+       int_mask = new_mask & AR5K_INT_COMMON;
+
+       if (ah->ah_version != AR5K_AR5210) {
+               /* Preserve per queue TXURN interrupt mask */
+               u32 simr2 = ath5k_hw_reg_read(ah, AR5K_SIMR2)
+                               & AR5K_SIMR2_QCU_TXURN;
+
+               if (new_mask & AR5K_INT_FATAL) {
+                       int_mask |= AR5K_IMR_HIUERR;
+                       simr2 |= (AR5K_SIMR2_MCABT | AR5K_SIMR2_SSERR
+                               | AR5K_SIMR2_DPERR);
+               }
+
+               /*Beacon Not Ready*/
+               if (new_mask & AR5K_INT_BNR)
+                       int_mask |= AR5K_INT_BNR;
+
+               if (new_mask & AR5K_INT_TIM)
+                       int_mask |= AR5K_IMR_TIM;
+
+               if (new_mask & AR5K_INT_TIM)
+                       simr2 |= AR5K_SISR2_TIM;
+               if (new_mask & AR5K_INT_DTIM)
+                       simr2 |= AR5K_SISR2_DTIM;
+               if (new_mask & AR5K_INT_DTIM_SYNC)
+                       simr2 |= AR5K_SISR2_DTIM_SYNC;
+               if (new_mask & AR5K_INT_BCN_TIMEOUT)
+                       simr2 |= AR5K_SISR2_BCN_TIMEOUT;
+               if (new_mask & AR5K_INT_CAB_TIMEOUT)
+                       simr2 |= AR5K_SISR2_CAB_TIMEOUT;
+
+               if (new_mask & AR5K_INT_RX_DOPPLER)
+                       int_mask |= AR5K_IMR_RXDOPPLER;
+
+               /* Note: Per queue interrupt masks
+                * are set via reset_tx_queue (qcu.c) */
+               ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
+               ath5k_hw_reg_write(ah, simr2, AR5K_SIMR2);
+
+       } else {
+               if (new_mask & AR5K_INT_FATAL)
+                       int_mask |= (AR5K_IMR_SSERR | AR5K_IMR_MCABT
+                               | AR5K_IMR_HIUERR | AR5K_IMR_DPERR);
+
+               ath5k_hw_reg_write(ah, int_mask, AR5K_IMR);
+       }
+
+       /* If RXNOFRM interrupt is masked disable it
+        * by setting AR5K_RXNOFRM to zero */
+       if (!(new_mask & AR5K_INT_RXNOFRM))
+               ath5k_hw_reg_write(ah, 0, AR5K_RXNOFRM);
+
+       /* Store new interrupt mask */
+       ah->ah_imr = new_mask;
+
+       /* ..re-enable interrupts if AR5K_INT_GLOBAL is set */
+       if (new_mask & AR5K_INT_GLOBAL) {
+               ath5k_hw_reg_write(ah, ah->ah_ier, AR5K_IER);
+               ath5k_hw_reg_read(ah, AR5K_IER);
+       }
+
+       return old_mask;
+}
+
diff --git a/src/drivers/net/ath5k/ath5k_eeprom.c b/src/drivers/net/ath5k/ath5k_eeprom.c
new file mode 100644 (file)
index 0000000..592714d
--- /dev/null
@@ -0,0 +1,1749 @@
+/*
+ * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2009 Nick Kossifidis <mickflemm@gmail.com>
+ * Copyright (c) 2008-2009 Felix Fietkau <nbd@openwrt.org>
+ *
+ * Lightly modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+FILE_LICENCE ( MIT );
+
+/*************************************\
+* EEPROM access functions and helpers *
+\*************************************/
+
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "ath5k.h"
+#include "reg.h"
+#include "base.h"
+
+/*
+ * Read from eeprom
+ */
+static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data)
+{
+       u32 status, timeout;
+
+       /*
+        * Initialize EEPROM access
+        */
+       if (ah->ah_version == AR5K_AR5210) {
+               AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
+               (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
+       } else {
+               ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
+               AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
+                               AR5K_EEPROM_CMD_READ);
+       }
+
+       for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
+               status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
+               if (status & AR5K_EEPROM_STAT_RDDONE) {
+                       if (status & AR5K_EEPROM_STAT_RDERR)
+                               return -EIO;
+                       *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
+                                       0xffff);
+                       return 0;
+               }
+               udelay(15);
+       }
+
+       return -ETIMEDOUT;
+}
+
+/*
+ * Translate binary channel representation in EEPROM to frequency
+ */
+static u16 ath5k_eeprom_bin2freq(struct ath5k_eeprom_info *ee, u16 bin,
+                                 unsigned int mode)
+{
+       u16 val;
+
+       if (bin == AR5K_EEPROM_CHANNEL_DIS)
+               return bin;
+
+       if (mode == AR5K_EEPROM_MODE_11A) {
+               if (ee->ee_version > AR5K_EEPROM_VERSION_3_2)
+                       val = (5 * bin) + 4800;
+               else
+                       val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
+                               (bin * 10) + 5100;
+       } else {
+               if (ee->ee_version > AR5K_EEPROM_VERSION_3_2)
+                       val = bin + 2300;
+               else
+                       val = bin + 2400;
+       }
+
+       return val;
+}
+
+/*
+ * Initialize eeprom & capabilities structs
+ */
+static int
+ath5k_eeprom_init_header(struct ath5k_hw *ah)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       int ret;
+       u16 val;
+
+       /*
+        * Read values from EEPROM and store them in the capability structure
+        */
+       AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
+       AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
+       AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
+       AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
+       AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
+
+       /* Return if we have an old EEPROM */
+       if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
+               return 0;
+
+       AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
+           ee_ant_gain);
+
+       if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
+               AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
+               AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
+
+               /* XXX: Don't know which versions include these two */
+               AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC2, ee_misc2);
+
+               if (ee->ee_version >= AR5K_EEPROM_VERSION_4_3)
+                       AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC3, ee_misc3);
+
+               if (ee->ee_version >= AR5K_EEPROM_VERSION_5_0) {
+                       AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC4, ee_misc4);
+                       AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC5, ee_misc5);
+                       AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC6, ee_misc6);
+               }
+       }
+
+       if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
+               AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
+               ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
+               ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
+
+               AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
+               ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
+               ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
+       }
+
+       return 0;
+}
+
+
+/*
+ * Read antenna infos from eeprom
+ */
+static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
+               unsigned int mode)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       u32 o = *offset;
+       u16 val;
+       int ret, i = 0;
+
+       AR5K_EEPROM_READ(o++, val);
+       ee->ee_switch_settling[mode]    = (val >> 8) & 0x7f;
+       ee->ee_atn_tx_rx[mode]          = (val >> 2) & 0x3f;
+       ee->ee_ant_control[mode][i]     = (val << 4) & 0x3f;
+
+       AR5K_EEPROM_READ(o++, val);
+       ee->ee_ant_control[mode][i++]   |= (val >> 12) & 0xf;
+       ee->ee_ant_control[mode][i++]   = (val >> 6) & 0x3f;
+       ee->ee_ant_control[mode][i++]   = val & 0x3f;
+
+       AR5K_EEPROM_READ(o++, val);
+       ee->ee_ant_control[mode][i++]   = (val >> 10) & 0x3f;
+       ee->ee_ant_control[mode][i++]   = (val >> 4) & 0x3f;
+       ee->ee_ant_control[mode][i]     = (val << 2) & 0x3f;
+
+       AR5K_EEPROM_READ(o++, val);
+       ee->ee_ant_control[mode][i++]   |= (val >> 14) & 0x3;
+       ee->ee_ant_control[mode][i++]   = (val >> 8) & 0x3f;
+       ee->ee_ant_control[mode][i++]   = (val >> 2) & 0x3f;
+       ee->ee_ant_control[mode][i]     = (val << 4) & 0x3f;
+
+       AR5K_EEPROM_READ(o++, val);
+       ee->ee_ant_control[mode][i++]   |= (val >> 12) & 0xf;
+       ee->ee_ant_control[mode][i++]   = (val >> 6) & 0x3f;
+       ee->ee_ant_control[mode][i++]   = val & 0x3f;
+
+       /* Get antenna modes */
+       ah->ah_antenna[mode][0] =
+           (ee->ee_ant_control[mode][0] << 4);
+       ah->ah_antenna[mode][AR5K_ANT_FIXED_A] =
+            ee->ee_ant_control[mode][1]        |
+           (ee->ee_ant_control[mode][2] << 6)  |
+           (ee->ee_ant_control[mode][3] << 12) |
+           (ee->ee_ant_control[mode][4] << 18) |
+           (ee->ee_ant_control[mode][5] << 24);
+       ah->ah_antenna[mode][AR5K_ANT_FIXED_B] =
+            ee->ee_ant_control[mode][6]        |
+           (ee->ee_ant_control[mode][7] << 6)  |
+           (ee->ee_ant_control[mode][8] << 12) |
+           (ee->ee_ant_control[mode][9] << 18) |
+           (ee->ee_ant_control[mode][10] << 24);
+
+       /* return new offset */
+       *offset = o;
+
+       return 0;
+}
+
+/*
+ * Read supported modes and some mode-specific calibration data
+ * from eeprom
+ */
+static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
+               unsigned int mode)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       u32 o = *offset;
+       u16 val;
+       int ret;
+
+       ee->ee_n_piers[mode] = 0;
+       AR5K_EEPROM_READ(o++, val);
+       ee->ee_adc_desired_size[mode]   = (s8)((val >> 8) & 0xff);
+       switch(mode) {
+       case AR5K_EEPROM_MODE_11A:
+               ee->ee_ob[mode][3]      = (val >> 5) & 0x7;
+               ee->ee_db[mode][3]      = (val >> 2) & 0x7;
+               ee->ee_ob[mode][2]      = (val << 1) & 0x7;
+
+               AR5K_EEPROM_READ(o++, val);
+               ee->ee_ob[mode][2]      |= (val >> 15) & 0x1;
+               ee->ee_db[mode][2]      = (val >> 12) & 0x7;
+               ee->ee_ob[mode][1]      = (val >> 9) & 0x7;
+               ee->ee_db[mode][1]      = (val >> 6) & 0x7;
+               ee->ee_ob[mode][0]      = (val >> 3) & 0x7;
+               ee->ee_db[mode][0]      = val & 0x7;
+               break;
+       case AR5K_EEPROM_MODE_11G:
+       case AR5K_EEPROM_MODE_11B:
+               ee->ee_ob[mode][1]      = (val >> 4) & 0x7;
+               ee->ee_db[mode][1]      = val & 0x7;
+               break;
+       }
+
+       AR5K_EEPROM_READ(o++, val);
+       ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
+       ee->ee_thr_62[mode]             = val & 0xff;
+
+       if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
+               ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
+
+       AR5K_EEPROM_READ(o++, val);
+       ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
+       ee->ee_tx_frm2xpa_enable[mode]  = val & 0xff;
+
+       AR5K_EEPROM_READ(o++, val);
+       ee->ee_pga_desired_size[mode]   = (val >> 8) & 0xff;
+
+       if ((val & 0xff) & 0x80)
+               ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
+       else
+               ee->ee_noise_floor_thr[mode] = val & 0xff;
+
+       if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
+               ee->ee_noise_floor_thr[mode] =
+                   mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
+
+       AR5K_EEPROM_READ(o++, val);
+       ee->ee_xlna_gain[mode]          = (val >> 5) & 0xff;
+       ee->ee_x_gain[mode]             = (val >> 1) & 0xf;
+       ee->ee_xpd[mode]                = val & 0x1;
+
+       if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
+               ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
+
+       if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
+               AR5K_EEPROM_READ(o++, val);
+               ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
+
+               if (mode == AR5K_EEPROM_MODE_11A)
+                       ee->ee_xr_power[mode] = val & 0x3f;
+               else {
+                       ee->ee_ob[mode][0] = val & 0x7;
+                       ee->ee_db[mode][0] = (val >> 3) & 0x7;
+               }
+       }
+
+       if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
+               ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
+               ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
+       } else {
+               ee->ee_i_gain[mode] = (val >> 13) & 0x7;
+
+               AR5K_EEPROM_READ(o++, val);
+               ee->ee_i_gain[mode] |= (val << 3) & 0x38;
+
+               if (mode == AR5K_EEPROM_MODE_11G) {
+                       ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
+                       if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6)
+                               ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
+               }
+       }
+
+       if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
+                       mode == AR5K_EEPROM_MODE_11A) {
+               ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
+               ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
+       }
+
+       if (ah->ah_ee_version < AR5K_EEPROM_VERSION_4_0)
+               goto done;
+
+       /* Note: >= v5 have bg freq piers on another location
+        * so these freq piers are ignored for >= v5 (should be 0xff
+        * anyway) */
+       switch(mode) {
+       case AR5K_EEPROM_MODE_11A:
+               if (ah->ah_ee_version < AR5K_EEPROM_VERSION_4_1)
+                       break;
+
+               AR5K_EEPROM_READ(o++, val);
+               ee->ee_margin_tx_rx[mode] = val & 0x3f;
+               break;
+       case AR5K_EEPROM_MODE_11B:
+               AR5K_EEPROM_READ(o++, val);
+
+               ee->ee_pwr_cal_b[0].freq =
+                       ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
+               if (ee->ee_pwr_cal_b[0].freq != AR5K_EEPROM_CHANNEL_DIS)
+                       ee->ee_n_piers[mode]++;
+
+               ee->ee_pwr_cal_b[1].freq =
+                       ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode);
+               if (ee->ee_pwr_cal_b[1].freq != AR5K_EEPROM_CHANNEL_DIS)
+                       ee->ee_n_piers[mode]++;
+
+               AR5K_EEPROM_READ(o++, val);
+               ee->ee_pwr_cal_b[2].freq =
+                       ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
+               if (ee->ee_pwr_cal_b[2].freq != AR5K_EEPROM_CHANNEL_DIS)
+                       ee->ee_n_piers[mode]++;
+
+               if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
+                       ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
+               break;
+       case AR5K_EEPROM_MODE_11G:
+               AR5K_EEPROM_READ(o++, val);
+
+               ee->ee_pwr_cal_g[0].freq =
+                       ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
+               if (ee->ee_pwr_cal_g[0].freq != AR5K_EEPROM_CHANNEL_DIS)
+                       ee->ee_n_piers[mode]++;
+
+               ee->ee_pwr_cal_g[1].freq =
+                       ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode);
+               if (ee->ee_pwr_cal_g[1].freq != AR5K_EEPROM_CHANNEL_DIS)
+                       ee->ee_n_piers[mode]++;
+
+               AR5K_EEPROM_READ(o++, val);
+               ee->ee_turbo_max_power[mode] = val & 0x7f;
+               ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
+
+               AR5K_EEPROM_READ(o++, val);
+               ee->ee_pwr_cal_g[2].freq =
+                       ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
+               if (ee->ee_pwr_cal_g[2].freq != AR5K_EEPROM_CHANNEL_DIS)
+                       ee->ee_n_piers[mode]++;
+
+               if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
+                       ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
+
+               AR5K_EEPROM_READ(o++, val);
+               ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
+               ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
+
+               if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
+                       AR5K_EEPROM_READ(o++, val);
+                       ee->ee_cck_ofdm_gain_delta = val & 0xff;
+               }
+               break;
+       }
+
+done:
+       /* return new offset */
+       *offset = o;
+
+       return 0;
+}
+
+/*
+ * Read turbo mode information on newer EEPROM versions
+ */
+static int
+ath5k_eeprom_read_turbo_modes(struct ath5k_hw *ah,
+                             u32 *offset, unsigned int mode)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       u32 o = *offset;
+       u16 val;
+       int ret;
+
+       if (ee->ee_version < AR5K_EEPROM_VERSION_5_0)
+               return 0;
+
+       switch (mode){
+       case AR5K_EEPROM_MODE_11A:
+               ee->ee_switch_settling_turbo[mode] = (val >> 6) & 0x7f;
+
+               ee->ee_atn_tx_rx_turbo[mode] = (val >> 13) & 0x7;
+               AR5K_EEPROM_READ(o++, val);
+               ee->ee_atn_tx_rx_turbo[mode] |= (val & 0x7) << 3;
+               ee->ee_margin_tx_rx_turbo[mode] = (val >> 3) & 0x3f;
+
+               ee->ee_adc_desired_size_turbo[mode] = (val >> 9) & 0x7f;
+               AR5K_EEPROM_READ(o++, val);
+               ee->ee_adc_desired_size_turbo[mode] |= (val & 0x1) << 7;
+               ee->ee_pga_desired_size_turbo[mode] = (val >> 1) & 0xff;
+
+               if (AR5K_EEPROM_EEMAP(ee->ee_misc0) >=2)
+                       ee->ee_pd_gain_overlap = (val >> 9) & 0xf;
+               break;
+       case AR5K_EEPROM_MODE_11G:
+               ee->ee_switch_settling_turbo[mode] = (val >> 8) & 0x7f;
+
+               ee->ee_atn_tx_rx_turbo[mode] = (val >> 15) & 0x7;
+               AR5K_EEPROM_READ(o++, val);
+               ee->ee_atn_tx_rx_turbo[mode] |= (val & 0x1f) << 1;
+               ee->ee_margin_tx_rx_turbo[mode] = (val >> 5) & 0x3f;
+
+               ee->ee_adc_desired_size_turbo[mode] = (val >> 11) & 0x7f;
+               AR5K_EEPROM_READ(o++, val);
+               ee->ee_adc_desired_size_turbo[mode] |= (val & 0x7) << 5;
+               ee->ee_pga_desired_size_turbo[mode] = (val >> 3) & 0xff;
+               break;
+       }
+
+       /* return new offset */
+       *offset = o;
+
+       return 0;
+}
+
+/* Read mode-specific data (except power calibration data) */
+static int
+ath5k_eeprom_init_modes(struct ath5k_hw *ah)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       u32 mode_offset[3];
+       unsigned int mode;
+       u32 offset;
+       int ret;
+
+       /*
+        * Get values for all modes
+        */
+       mode_offset[AR5K_EEPROM_MODE_11A] = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
+       mode_offset[AR5K_EEPROM_MODE_11B] = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
+       mode_offset[AR5K_EEPROM_MODE_11G] = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
+
+       ee->ee_turbo_max_power[AR5K_EEPROM_MODE_11A] =
+               AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
+
+       for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; mode++) {
+               offset = mode_offset[mode];
+
+               ret = ath5k_eeprom_read_ants(ah, &offset, mode);
+               if (ret)
+                       return ret;
+
+               ret = ath5k_eeprom_read_modes(ah, &offset, mode);
+               if (ret)
+                       return ret;
+
+               ret = ath5k_eeprom_read_turbo_modes(ah, &offset, mode);
+               if (ret)
+                       return ret;
+       }
+
+       /* override for older eeprom versions for better performance */
+       if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2) {
+               ee->ee_thr_62[AR5K_EEPROM_MODE_11A] = 15;
+               ee->ee_thr_62[AR5K_EEPROM_MODE_11B] = 28;
+               ee->ee_thr_62[AR5K_EEPROM_MODE_11G] = 28;
+       }
+
+       return 0;
+}
+
+/* Read the frequency piers for each mode (mostly used on newer eeproms with 0xff
+ * frequency mask) */
+static inline int
+ath5k_eeprom_read_freq_list(struct ath5k_hw *ah, int *offset, int max,
+                       struct ath5k_chan_pcal_info *pc, unsigned int mode)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       int o = *offset;
+       int i = 0;
+       u8 freq1, freq2;
+       int ret;
+       u16 val;
+
+       ee->ee_n_piers[mode] = 0;
+       while(i < max) {
+               AR5K_EEPROM_READ(o++, val);
+
+               freq1 = val & 0xff;
+               if (!freq1)
+                       break;
+
+               pc[i++].freq = ath5k_eeprom_bin2freq(ee,
+                               freq1, mode);
+               ee->ee_n_piers[mode]++;
+
+               freq2 = (val >> 8) & 0xff;
+               if (!freq2)
+                       break;
+
+               pc[i++].freq = ath5k_eeprom_bin2freq(ee,
+                               freq2, mode);
+               ee->ee_n_piers[mode]++;
+       }
+
+       /* return new offset */
+       *offset = o;
+
+       return 0;
+}
+
+/* Read frequency piers for 802.11a */
+static int
+ath5k_eeprom_init_11a_pcal_freq(struct ath5k_hw *ah, int offset)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       struct ath5k_chan_pcal_info *pcal = ee->ee_pwr_cal_a;
+       int i, ret;
+       u16 val;
+       u8 mask;
+
+       if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3) {
+               ath5k_eeprom_read_freq_list(ah, &offset,
+                       AR5K_EEPROM_N_5GHZ_CHAN, pcal,
+                       AR5K_EEPROM_MODE_11A);
+       } else {
+               mask = AR5K_EEPROM_FREQ_M(ah->ah_ee_version);
+
+               AR5K_EEPROM_READ(offset++, val);
+               pcal[0].freq  = (val >> 9) & mask;
+               pcal[1].freq  = (val >> 2) & mask;
+               pcal[2].freq  = (val << 5) & mask;
+
+               AR5K_EEPROM_READ(offset++, val);
+               pcal[2].freq |= (val >> 11) & 0x1f;
+               pcal[3].freq  = (val >> 4) & mask;
+               pcal[4].freq  = (val << 3) & mask;
+
+               AR5K_EEPROM_READ(offset++, val);
+               pcal[4].freq |= (val >> 13) & 0x7;
+               pcal[5].freq  = (val >> 6) & mask;
+               pcal[6].freq  = (val << 1) & mask;
+
+               AR5K_EEPROM_READ(offset++, val);
+               pcal[6].freq |= (val >> 15) & 0x1;
+               pcal[7].freq  = (val >> 8) & mask;
+               pcal[8].freq  = (val >> 1) & mask;
+               pcal[9].freq  = (val << 6) & mask;
+
+               AR5K_EEPROM_READ(offset++, val);
+               pcal[9].freq |= (val >> 10) & 0x3f;
+
+               /* Fixed number of piers */
+               ee->ee_n_piers[AR5K_EEPROM_MODE_11A] = 10;
+
+               for (i = 0; i < AR5K_EEPROM_N_5GHZ_CHAN; i++) {
+                       pcal[i].freq = ath5k_eeprom_bin2freq(ee,
+                               pcal[i].freq, AR5K_EEPROM_MODE_11A);
+               }
+       }
+
+       return 0;
+}
+
+/* Read frequency piers for 802.11bg on eeprom versions >= 5 and eemap >= 2 */
+static inline int
+ath5k_eeprom_init_11bg_2413(struct ath5k_hw *ah, unsigned int mode, int offset)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       struct ath5k_chan_pcal_info *pcal;
+
+       switch(mode) {
+       case AR5K_EEPROM_MODE_11B:
+               pcal = ee->ee_pwr_cal_b;
+               break;
+       case AR5K_EEPROM_MODE_11G:
+               pcal = ee->ee_pwr_cal_g;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       ath5k_eeprom_read_freq_list(ah, &offset,
+               AR5K_EEPROM_N_2GHZ_CHAN_2413, pcal,
+               mode);
+
+       return 0;
+}
+
+/*
+ * Read power calibration for RF5111 chips
+ *
+ * For RF5111 we have an XPD -eXternal Power Detector- curve
+ * for each calibrated channel. Each curve has 0,5dB Power steps
+ * on x axis and PCDAC steps (offsets) on y axis and looks like an
+ * exponential function. To recreate the curve we read 11 points
+ * here and interpolate later.
+ */
+
+/* Used to match PCDAC steps with power values on RF5111 chips
+ * (eeprom versions < 4). For RF5111 we have 11 pre-defined PCDAC
+ * steps that match with the power values we read from eeprom. On
+ * older eeprom versions (< 3.2) these steps are equaly spaced at
+ * 10% of the pcdac curve -until the curve reaches it's maximum-
+ * (11 steps from 0 to 100%) but on newer eeprom versions (>= 3.2)
+ * these 11 steps are spaced in a different way. This function returns
+ * the pcdac steps based on eeprom version and curve min/max so that we
+ * can have pcdac/pwr points.
+ */
+static inline void
+ath5k_get_pcdac_intercepts(struct ath5k_hw *ah, u8 min, u8 max, u8 *vp)
+{
+       static const u16 intercepts3[] =
+               { 0, 5, 10, 20, 30, 50, 70, 85, 90, 95, 100 };
+       static const u16 intercepts3_2[] =
+               { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
+       const u16 *ip;
+       unsigned i;
+
+       if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_2)
+               ip = intercepts3_2;
+       else
+               ip = intercepts3;
+
+       for (i = 0; i < ARRAY_SIZE(intercepts3); i++)
+               vp[i] = (ip[i] * max + (100 - ip[i]) * min) / 100;
+}
+
+/* Convert RF5111 specific data to generic raw data
+ * used by interpolation code */
+static int
+ath5k_eeprom_convert_pcal_info_5111(struct ath5k_hw *ah, int mode,
+                               struct ath5k_chan_pcal_info *chinfo)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       struct ath5k_chan_pcal_info_rf5111 *pcinfo;
+       struct ath5k_pdgain_info *pd;
+       u8 pier, point, idx;
+       u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
+
+       /* Fill raw data for each calibration pier */
+       for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
+
+               pcinfo = &chinfo[pier].rf5111_info;
+
+               /* Allocate pd_curves for this cal pier */
+               chinfo[pier].pd_curves =
+                       calloc(AR5K_EEPROM_N_PD_CURVES,
+                              sizeof(struct ath5k_pdgain_info));
+
+               if (!chinfo[pier].pd_curves)
+                       return -ENOMEM;
+
+               /* Only one curve for RF5111
+                * find out which one and place
+                * in in pd_curves.
+                * Note: ee_x_gain is reversed here */
+               for (idx = 0; idx < AR5K_EEPROM_N_PD_CURVES; idx++) {
+
+                       if (!((ee->ee_x_gain[mode] >> idx) & 0x1)) {
+                               pdgain_idx[0] = idx;
+                               break;
+                       }
+               }
+
+               ee->ee_pd_gains[mode] = 1;
+
+               pd = &chinfo[pier].pd_curves[idx];
+
+               pd->pd_points = AR5K_EEPROM_N_PWR_POINTS_5111;
+
+               /* Allocate pd points for this curve */
+               pd->pd_step = calloc(AR5K_EEPROM_N_PWR_POINTS_5111, sizeof(u8));
+               if (!pd->pd_step)
+                       return -ENOMEM;
+
+               pd->pd_pwr = calloc(AR5K_EEPROM_N_PWR_POINTS_5111, sizeof(s16));
+               if (!pd->pd_pwr)
+                       return -ENOMEM;
+
+               /* Fill raw dataset
+                * (convert power to 0.25dB units
+                * for RF5112 combatibility) */
+               for (point = 0; point < pd->pd_points; point++) {
+
+                       /* Absolute values */
+                       pd->pd_pwr[point] = 2 * pcinfo->pwr[point];
+
+                       /* Already sorted */
+                       pd->pd_step[point] = pcinfo->pcdac[point];
+               }
+
+               /* Set min/max pwr */
+               chinfo[pier].min_pwr = pd->pd_pwr[0];
+               chinfo[pier].max_pwr = pd->pd_pwr[10];
+
+       }
+
+       return 0;
+}
+
+/* Parse EEPROM data */
+static int
+ath5k_eeprom_read_pcal_info_5111(struct ath5k_hw *ah, int mode)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       struct ath5k_chan_pcal_info *pcal;
+       int offset, ret;
+       int i;
+       u16 val;
+
+       offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
+       switch(mode) {
+       case AR5K_EEPROM_MODE_11A:
+               if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
+                       return 0;
+
+               ret = ath5k_eeprom_init_11a_pcal_freq(ah,
+                       offset + AR5K_EEPROM_GROUP1_OFFSET);
+               if (ret < 0)
+                       return ret;
+
+               offset += AR5K_EEPROM_GROUP2_OFFSET;
+               pcal = ee->ee_pwr_cal_a;
+               break;
+       case AR5K_EEPROM_MODE_11B:
+               if (!AR5K_EEPROM_HDR_11B(ee->ee_header) &&
+                   !AR5K_EEPROM_HDR_11G(ee->ee_header))
+                       return 0;
+
+               pcal = ee->ee_pwr_cal_b;
+               offset += AR5K_EEPROM_GROUP3_OFFSET;
+
+               /* fixed piers */
+               pcal[0].freq = 2412;
+               pcal[1].freq = 2447;
+               pcal[2].freq = 2484;
+               ee->ee_n_piers[mode] = 3;
+               break;
+       case AR5K_EEPROM_MODE_11G:
+               if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
+                       return 0;
+
+               pcal = ee->ee_pwr_cal_g;
+               offset += AR5K_EEPROM_GROUP4_OFFSET;
+
+               /* fixed piers */
+               pcal[0].freq = 2312;
+               pcal[1].freq = 2412;
+               pcal[2].freq = 2484;
+               ee->ee_n_piers[mode] = 3;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       for (i = 0; i < ee->ee_n_piers[mode]; i++) {
+               struct ath5k_chan_pcal_info_rf5111 *cdata =
+                       &pcal[i].rf5111_info;
+
+               AR5K_EEPROM_READ(offset++, val);
+               cdata->pcdac_max = ((val >> 10) & AR5K_EEPROM_PCDAC_M);
+               cdata->pcdac_min = ((val >> 4) & AR5K_EEPROM_PCDAC_M);
+               cdata->pwr[0] = ((val << 2) & AR5K_EEPROM_POWER_M);
+
+               AR5K_EEPROM_READ(offset++, val);
+               cdata->pwr[0] |= ((val >> 14) & 0x3);
+               cdata->pwr[1] = ((val >> 8) & AR5K_EEPROM_POWER_M);
+               cdata->pwr[2] = ((val >> 2) & AR5K_EEPROM_POWER_M);
+               cdata->pwr[3] = ((val << 4) & AR5K_EEPROM_POWER_M);
+
+               AR5K_EEPROM_READ(offset++, val);
+               cdata->pwr[3] |= ((val >> 12) & 0xf);
+               cdata->pwr[4] = ((val >> 6) & AR5K_EEPROM_POWER_M);
+               cdata->pwr[5] = (val  & AR5K_EEPROM_POWER_M);
+
+               AR5K_EEPROM_READ(offset++, val);
+               cdata->pwr[6] = ((val >> 10) & AR5K_EEPROM_POWER_M);
+               cdata->pwr[7] = ((val >> 4) & AR5K_EEPROM_POWER_M);
+               cdata->pwr[8] = ((val << 2) & AR5K_EEPROM_POWER_M);
+
+               AR5K_EEPROM_READ(offset++, val);
+               cdata->pwr[8] |= ((val >> 14) & 0x3);
+               cdata->pwr[9] = ((val >> 8) & AR5K_EEPROM_POWER_M);
+               cdata->pwr[10] = ((val >> 2) & AR5K_EEPROM_POWER_M);
+
+               ath5k_get_pcdac_intercepts(ah, cdata->pcdac_min,
+                       cdata->pcdac_max, cdata->pcdac);
+       }
+
+       return ath5k_eeprom_convert_pcal_info_5111(ah, mode, pcal);
+}
+
+
+/*
+ * Read power calibration for RF5112 chips
+ *
+ * For RF5112 we have 4 XPD -eXternal Power Detector- curves
+ * for each calibrated channel on 0, -6, -12 and -18dbm but we only
+ * use the higher (3) and the lower (0) curves. Each curve has 0.5dB
+ * power steps on x axis and PCDAC steps on y axis and looks like a
+ * linear function. To recreate the curve and pass the power values
+ * on hw, we read 4 points for xpd 0 (lower gain -> max power)
+ * and 3 points for xpd 3 (higher gain -> lower power) here and
+ * interpolate later.
+ *
+ * Note: Many vendors just use xpd 0 so xpd 3 is zeroed.
+ */
+
+/* Convert RF5112 specific data to generic raw data
+ * used by interpolation code */
+static int
+ath5k_eeprom_convert_pcal_info_5112(struct ath5k_hw *ah, int mode,
+                               struct ath5k_chan_pcal_info *chinfo)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       struct ath5k_chan_pcal_info_rf5112 *pcinfo;
+       u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
+       unsigned int pier, pdg, point;
+
+       /* Fill raw data for each calibration pier */
+       for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
+
+               pcinfo = &chinfo[pier].rf5112_info;
+
+               /* Allocate pd_curves for this cal pier */
+               chinfo[pier].pd_curves =
+                               calloc(AR5K_EEPROM_N_PD_CURVES,
+                                      sizeof(struct ath5k_pdgain_info));
+
+               if (!chinfo[pier].pd_curves)
+                       return -ENOMEM;
+
+               /* Fill pd_curves */
+               for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
+
+                       u8 idx = pdgain_idx[pdg];
+                       struct ath5k_pdgain_info *pd =
+                                       &chinfo[pier].pd_curves[idx];
+
+                       /* Lowest gain curve (max power) */
+                       if (pdg == 0) {
+                               /* One more point for better accuracy */
+                               pd->pd_points = AR5K_EEPROM_N_XPD0_POINTS;
+
+                               /* Allocate pd points for this curve */
+                               pd->pd_step = calloc(pd->pd_points, sizeof(u8));
+
+                               if (!pd->pd_step)
+                                       return -ENOMEM;
+
+                               pd->pd_pwr = calloc(pd->pd_points, sizeof(s16));
+
+                               if (!pd->pd_pwr)
+                                       return -ENOMEM;
+
+
+                               /* Fill raw dataset
+                                * (all power levels are in 0.25dB units) */
+                               pd->pd_step[0] = pcinfo->pcdac_x0[0];
+                               pd->pd_pwr[0] = pcinfo->pwr_x0[0];
+
+                               for (point = 1; point < pd->pd_points;
+                               point++) {
+                                       /* Absolute values */
+                                       pd->pd_pwr[point] =
+                                               pcinfo->pwr_x0[point];
+
+                                       /* Deltas */
+                                       pd->pd_step[point] =
+                                               pd->pd_step[point - 1] +
+                                               pcinfo->pcdac_x0[point];
+                               }
+
+                               /* Set min power for this frequency */
+                               chinfo[pier].min_pwr = pd->pd_pwr[0];
+
+                       /* Highest gain curve (min power) */
+                       } else if (pdg == 1) {
+
+                               pd->pd_points = AR5K_EEPROM_N_XPD3_POINTS;
+
+                               /* Allocate pd points for this curve */
+                               pd->pd_step = calloc(pd->pd_points, sizeof(u8));
+
+                               if (!pd->pd_step)
+                                       return -ENOMEM;
+
+                               pd->pd_pwr = calloc(pd->pd_points, sizeof(s16));
+
+                               if (!pd->pd_pwr)
+                                       return -ENOMEM;
+
+                               /* Fill raw dataset
+                                * (all power levels are in 0.25dB units) */
+                               for (point = 0; point < pd->pd_points;
+                               point++) {
+                                       /* Absolute values */
+                                       pd->pd_pwr[point] =
+                                               pcinfo->pwr_x3[point];
+
+                                       /* Fixed points */
+                                       pd->pd_step[point] =
+                                               pcinfo->pcdac_x3[point];
+                               }
+
+                               /* Since we have a higher gain curve
+                                * override min power */
+                               chinfo[pier].min_pwr = pd->pd_pwr[0];
+                       }
+               }
+       }
+
+       return 0;
+}
+
+/* Parse EEPROM data */
+static int
+ath5k_eeprom_read_pcal_info_5112(struct ath5k_hw *ah, int mode)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       struct ath5k_chan_pcal_info_rf5112 *chan_pcal_info;
+       struct ath5k_chan_pcal_info *gen_chan_info;
+       u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
+       u32 offset;
+       u8 i, c;
+       u16 val;
+       int ret;
+       u8 pd_gains = 0;
+
+       /* Count how many curves we have and
+        * identify them (which one of the 4
+        * available curves we have on each count).
+        * Curves are stored from lower (x0) to
+        * higher (x3) gain */
+       for (i = 0; i < AR5K_EEPROM_N_PD_CURVES; i++) {
+               /* ee_x_gain[mode] is x gain mask */
+               if ((ee->ee_x_gain[mode] >> i) & 0x1)
+                       pdgain_idx[pd_gains++] = i;
+       }
+       ee->ee_pd_gains[mode] = pd_gains;
+
+       if (pd_gains == 0 || pd_gains > 2)
+               return -EINVAL;
+
+       switch (mode) {
+       case AR5K_EEPROM_MODE_11A:
+               /*
+                * Read 5GHz EEPROM channels
+                */
+               offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
+               ath5k_eeprom_init_11a_pcal_freq(ah, offset);
+
+               offset += AR5K_EEPROM_GROUP2_OFFSET;
+               gen_chan_info = ee->ee_pwr_cal_a;
+               break;
+       case AR5K_EEPROM_MODE_11B:
+               offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
+               if (AR5K_EEPROM_HDR_11A(ee->ee_header))
+                       offset += AR5K_EEPROM_GROUP3_OFFSET;
+
+               /* NB: frequency piers parsed during mode init */
+               gen_chan_info = ee->ee_pwr_cal_b;
+               break;
+       case AR5K_EEPROM_MODE_11G:
+               offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
+               if (AR5K_EEPROM_HDR_11A(ee->ee_header))
+                       offset += AR5K_EEPROM_GROUP4_OFFSET;
+               else if (AR5K_EEPROM_HDR_11B(ee->ee_header))
+                       offset += AR5K_EEPROM_GROUP2_OFFSET;
+
+               /* NB: frequency piers parsed during mode init */
+               gen_chan_info = ee->ee_pwr_cal_g;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       for (i = 0; i < ee->ee_n_piers[mode]; i++) {
+               chan_pcal_info = &gen_chan_info[i].rf5112_info;
+
+               /* Power values in quarter dB
+                * for the lower xpd gain curve
+                * (0 dBm -> higher output power) */
+               for (c = 0; c < AR5K_EEPROM_N_XPD0_POINTS; c++) {
+                       AR5K_EEPROM_READ(offset++, val);
+                       chan_pcal_info->pwr_x0[c] = (s8) (val & 0xff);
+                       chan_pcal_info->pwr_x0[++c] = (s8) ((val >> 8) & 0xff);
+               }
+
+               /* PCDAC steps
+                * corresponding to the above power
+                * measurements */
+               AR5K_EEPROM_READ(offset++, val);
+               chan_pcal_info->pcdac_x0[1] = (val & 0x1f);
+               chan_pcal_info->pcdac_x0[2] = ((val >> 5) & 0x1f);
+               chan_pcal_info->pcdac_x0[3] = ((val >> 10) & 0x1f);
+
+               /* Power values in quarter dB
+                * for the higher xpd gain curve
+                * (18 dBm -> lower output power) */
+               AR5K_EEPROM_READ(offset++, val);
+               chan_pcal_info->pwr_x3[0] = (s8) (val & 0xff);
+               chan_pcal_info->pwr_x3[1] = (s8) ((val >> 8) & 0xff);
+
+               AR5K_EEPROM_READ(offset++, val);
+               chan_pcal_info->pwr_x3[2] = (val & 0xff);
+
+               /* PCDAC steps
+                * corresponding to the above power
+                * measurements (fixed) */
+               chan_pcal_info->pcdac_x3[0] = 20;
+               chan_pcal_info->pcdac_x3[1] = 35;
+               chan_pcal_info->pcdac_x3[2] = 63;
+
+               if (ee->ee_version >= AR5K_EEPROM_VERSION_4_3) {
+                       chan_pcal_info->pcdac_x0[0] = ((val >> 8) & 0x3f);
+
+                       /* Last xpd0 power level is also channel maximum */
+                       gen_chan_info[i].max_pwr = chan_pcal_info->pwr_x0[3];
+               } else {
+                       chan_pcal_info->pcdac_x0[0] = 1;
+                       gen_chan_info[i].max_pwr = (s8) ((val >> 8) & 0xff);
+               }
+
+       }
+
+       return ath5k_eeprom_convert_pcal_info_5112(ah, mode, gen_chan_info);
+}
+
+
+/*
+ * Read power calibration for RF2413 chips
+ *
+ * For RF2413 we have a Power to PDDAC table (Power Detector)
+ * instead of a PCDAC and 4 pd gain curves for each calibrated channel.
+ * Each curve has power on x axis in 0.5 db steps and PDDADC steps on y
+ * axis and looks like an exponential function like the RF5111 curve.
+ *
+ * To recreate the curves we read here the points and interpolate
+ * later. Note that in most cases only 2 (higher and lower) curves are
+ * used (like RF5112) but vendors have the oportunity to include all
+ * 4 curves on eeprom. The final curve (higher power) has an extra
+ * point for better accuracy like RF5112.
+ */
+
+/* For RF2413 power calibration data doesn't start on a fixed location and
+ * if a mode is not supported, it's section is missing -not zeroed-.
+ * So we need to calculate the starting offset for each section by using
+ * these two functions */
+
+/* Return the size of each section based on the mode and the number of pd
+ * gains available (maximum 4). */
+static inline unsigned int
+ath5k_pdgains_size_2413(struct ath5k_eeprom_info *ee, unsigned int mode)
+{
+       static const unsigned int pdgains_size[] = { 4, 6, 9, 12 };
+       unsigned int sz;
+
+       sz = pdgains_size[ee->ee_pd_gains[mode] - 1];
+       sz *= ee->ee_n_piers[mode];
+
+       return sz;
+}
+
+/* Return the starting offset for a section based on the modes supported
+ * and each section's size. */
+static unsigned int
+ath5k_cal_data_offset_2413(struct ath5k_eeprom_info *ee, int mode)
+{
+       u32 offset = AR5K_EEPROM_CAL_DATA_START(ee->ee_misc4);
+
+       switch(mode) {
+       case AR5K_EEPROM_MODE_11G:
+               if (AR5K_EEPROM_HDR_11B(ee->ee_header))
+                       offset += ath5k_pdgains_size_2413(ee,
+                                       AR5K_EEPROM_MODE_11B) +
+                                       AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
+               /* fall through */
+       case AR5K_EEPROM_MODE_11B:
+               if (AR5K_EEPROM_HDR_11A(ee->ee_header))
+                       offset += ath5k_pdgains_size_2413(ee,
+                                       AR5K_EEPROM_MODE_11A) +
+                                       AR5K_EEPROM_N_5GHZ_CHAN / 2;
+               /* fall through */
+       case AR5K_EEPROM_MODE_11A:
+               break;
+       default:
+               break;
+       }
+
+       return offset;
+}
+
+/* Convert RF2413 specific data to generic raw data
+ * used by interpolation code */
+static int
+ath5k_eeprom_convert_pcal_info_2413(struct ath5k_hw *ah, int mode,
+                               struct ath5k_chan_pcal_info *chinfo)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       struct ath5k_chan_pcal_info_rf2413 *pcinfo;
+       u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
+       unsigned int pier, point;
+       int pdg;
+
+       /* Fill raw data for each calibration pier */
+       for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
+
+               pcinfo = &chinfo[pier].rf2413_info;
+
+               /* Allocate pd_curves for this cal pier */
+               chinfo[pier].pd_curves =
+                               calloc(AR5K_EEPROM_N_PD_CURVES,
+                                      sizeof(struct ath5k_pdgain_info));
+
+               if (!chinfo[pier].pd_curves)
+                       return -ENOMEM;
+
+               /* Fill pd_curves */
+               for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
+
+                       u8 idx = pdgain_idx[pdg];
+                       struct ath5k_pdgain_info *pd =
+                                       &chinfo[pier].pd_curves[idx];
+
+                       /* One more point for the highest power
+                        * curve (lowest gain) */
+                       if (pdg == ee->ee_pd_gains[mode] - 1)
+                               pd->pd_points = AR5K_EEPROM_N_PD_POINTS;
+                       else
+                               pd->pd_points = AR5K_EEPROM_N_PD_POINTS - 1;
+
+                       /* Allocate pd points for this curve */
+                       pd->pd_step = calloc(pd->pd_points, sizeof(u8));
+
+                       if (!pd->pd_step)
+                               return -ENOMEM;
+
+                       pd->pd_pwr = calloc(pd->pd_points, sizeof(s16));
+
+                       if (!pd->pd_pwr)
+                               return -ENOMEM;
+
+                       /* Fill raw dataset
+                        * convert all pwr levels to
+                        * quarter dB for RF5112 combatibility */
+                       pd->pd_step[0] = pcinfo->pddac_i[pdg];
+                       pd->pd_pwr[0] = 4 * pcinfo->pwr_i[pdg];
+
+                       for (point = 1; point < pd->pd_points; point++) {
+
+                               pd->pd_pwr[point] = pd->pd_pwr[point - 1] +
+                                       2 * pcinfo->pwr[pdg][point - 1];
+
+                               pd->pd_step[point] = pd->pd_step[point - 1] +
+                                               pcinfo->pddac[pdg][point - 1];
+
+                       }
+
+                       /* Highest gain curve -> min power */
+                       if (pdg == 0)
+                               chinfo[pier].min_pwr = pd->pd_pwr[0];
+
+                       /* Lowest gain curve -> max power */
+                       if (pdg == ee->ee_pd_gains[mode] - 1)
+                               chinfo[pier].max_pwr =
+                                       pd->pd_pwr[pd->pd_points - 1];
+               }
+       }
+
+       return 0;
+}
+
+/* Parse EEPROM data */
+static int
+ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw *ah, int mode)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       struct ath5k_chan_pcal_info_rf2413 *pcinfo;
+       struct ath5k_chan_pcal_info *chinfo;
+       u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
+       u32 offset;
+       int idx, i, ret;
+       u16 val;
+       u8 pd_gains = 0;
+
+       /* Count how many curves we have and
+        * identify them (which one of the 4
+        * available curves we have on each count).
+        * Curves are stored from higher to
+        * lower gain so we go backwards */
+       for (idx = AR5K_EEPROM_N_PD_CURVES - 1; idx >= 0; idx--) {
+               /* ee_x_gain[mode] is x gain mask */
+               if ((ee->ee_x_gain[mode] >> idx) & 0x1)
+                       pdgain_idx[pd_gains++] = idx;
+
+       }
+       ee->ee_pd_gains[mode] = pd_gains;
+
+       if (pd_gains == 0)
+               return -EINVAL;
+
+       offset = ath5k_cal_data_offset_2413(ee, mode);
+       switch (mode) {
+       case AR5K_EEPROM_MODE_11A:
+               if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
+                       return 0;
+
+               ath5k_eeprom_init_11a_pcal_freq(ah, offset);
+               offset += AR5K_EEPROM_N_5GHZ_CHAN / 2;
+               chinfo = ee->ee_pwr_cal_a;
+               break;
+       case AR5K_EEPROM_MODE_11B:
+               if (!AR5K_EEPROM_HDR_11B(ee->ee_header))
+                       return 0;
+
+               ath5k_eeprom_init_11bg_2413(ah, mode, offset);
+               offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
+               chinfo = ee->ee_pwr_cal_b;
+               break;
+       case AR5K_EEPROM_MODE_11G:
+               if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
+                       return 0;
+
+               ath5k_eeprom_init_11bg_2413(ah, mode, offset);
+               offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
+               chinfo = ee->ee_pwr_cal_g;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       for (i = 0; i < ee->ee_n_piers[mode]; i++) {
+               pcinfo = &chinfo[i].rf2413_info;
+
+               /*
+                * Read pwr_i, pddac_i and the first
+                * 2 pd points (pwr, pddac)
+                */
+               AR5K_EEPROM_READ(offset++, val);
+               pcinfo->pwr_i[0] = val & 0x1f;
+               pcinfo->pddac_i[0] = (val >> 5) & 0x7f;
+               pcinfo->pwr[0][0] = (val >> 12) & 0xf;
+
+               AR5K_EEPROM_READ(offset++, val);
+               pcinfo->pddac[0][0] = val & 0x3f;
+               pcinfo->pwr[0][1] = (val >> 6) & 0xf;
+               pcinfo->pddac[0][1] = (val >> 10) & 0x3f;
+
+               AR5K_EEPROM_READ(offset++, val);
+               pcinfo->pwr[0][2] = val & 0xf;
+               pcinfo->pddac[0][2] = (val >> 4) & 0x3f;
+
+               pcinfo->pwr[0][3] = 0;
+               pcinfo->pddac[0][3] = 0;
+
+               if (pd_gains > 1) {
+                       /*
+                        * Pd gain 0 is not the last pd gain
+                        * so it only has 2 pd points.
+                        * Continue wih pd gain 1.
+                        */
+                       pcinfo->pwr_i[1] = (val >> 10) & 0x1f;
+
+                       pcinfo->pddac_i[1] = (val >> 15) & 0x1;
+                       AR5K_EEPROM_READ(offset++, val);
+                       pcinfo->pddac_i[1] |= (val & 0x3F) << 1;
+
+                       pcinfo->pwr[1][0] = (val >> 6) & 0xf;
+                       pcinfo->pddac[1][0] = (val >> 10) & 0x3f;
+
+                       AR5K_EEPROM_READ(offset++, val);
+                       pcinfo->pwr[1][1] = val & 0xf;
+                       pcinfo->pddac[1][1] = (val >> 4) & 0x3f;
+                       pcinfo->pwr[1][2] = (val >> 10) & 0xf;
+
+                       pcinfo->pddac[1][2] = (val >> 14) & 0x3;
+                       AR5K_EEPROM_READ(offset++, val);
+                       pcinfo->pddac[1][2] |= (val & 0xF) << 2;
+
+                       pcinfo->pwr[1][3] = 0;
+                       pcinfo->pddac[1][3] = 0;
+               } else if (pd_gains == 1) {
+                       /*
+                        * Pd gain 0 is the last one so
+                        * read the extra point.
+                        */
+                       pcinfo->pwr[0][3] = (val >> 10) & 0xf;
+
+                       pcinfo->pddac[0][3] = (val >> 14) & 0x3;
+                       AR5K_EEPROM_READ(offset++, val);
+                       pcinfo->pddac[0][3] |= (val & 0xF) << 2;
+               }
+
+               /*
+                * Proceed with the other pd_gains
+                * as above.
+                */
+               if (pd_gains > 2) {
+                       pcinfo->pwr_i[2] = (val >> 4) & 0x1f;
+                       pcinfo->pddac_i[2] = (val >> 9) & 0x7f;
+
+                       AR5K_EEPROM_READ(offset++, val);
+                       pcinfo->pwr[2][0] = (val >> 0) & 0xf;
+                       pcinfo->pddac[2][0] = (val >> 4) & 0x3f;
+                       pcinfo->pwr[2][1] = (val >> 10) & 0xf;
+
+                       pcinfo->pddac[2][1] = (val >> 14) & 0x3;
+                       AR5K_EEPROM_READ(offset++, val);
+                       pcinfo->pddac[2][1] |= (val & 0xF) << 2;
+
+                       pcinfo->pwr[2][2] = (val >> 4) & 0xf;
+                       pcinfo->pddac[2][2] = (val >> 8) & 0x3f;
+
+                       pcinfo->pwr[2][3] = 0;
+                       pcinfo->pddac[2][3] = 0;
+               } else if (pd_gains == 2) {
+                       pcinfo->pwr[1][3] = (val >> 4) & 0xf;
+                       pcinfo->pddac[1][3] = (val >> 8) & 0x3f;
+               }
+
+               if (pd_gains > 3) {
+                       pcinfo->pwr_i[3] = (val >> 14) & 0x3;
+                       AR5K_EEPROM_READ(offset++, val);
+                       pcinfo->pwr_i[3] |= ((val >> 0) & 0x7) << 2;
+
+                       pcinfo->pddac_i[3] = (val >> 3) & 0x7f;
+                       pcinfo->pwr[3][0] = (val >> 10) & 0xf;
+                       pcinfo->pddac[3][0] = (val >> 14) & 0x3;
+
+                       AR5K_EEPROM_READ(offset++, val);
+                       pcinfo->pddac[3][0] |= (val & 0xF) << 2;
+                       pcinfo->pwr[3][1] = (val >> 4) & 0xf;
+                       pcinfo->pddac[3][1] = (val >> 8) & 0x3f;
+
+                       pcinfo->pwr[3][2] = (val >> 14) & 0x3;
+                       AR5K_EEPROM_READ(offset++, val);
+                       pcinfo->pwr[3][2] |= ((val >> 0) & 0x3) << 2;
+
+                       pcinfo->pddac[3][2] = (val >> 2) & 0x3f;
+                       pcinfo->pwr[3][3] = (val >> 8) & 0xf;
+
+                       pcinfo->pddac[3][3] = (val >> 12) & 0xF;
+                       AR5K_EEPROM_READ(offset++, val);
+                       pcinfo->pddac[3][3] |= ((val >> 0) & 0x3) << 4;
+               } else if (pd_gains == 3) {
+                       pcinfo->pwr[2][3] = (val >> 14) & 0x3;
+                       AR5K_EEPROM_READ(offset++, val);
+                       pcinfo->pwr[2][3] |= ((val >> 0) & 0x3) << 2;
+
+                       pcinfo->pddac[2][3] = (val >> 2) & 0x3f;
+               }
+       }
+
+       return ath5k_eeprom_convert_pcal_info_2413(ah, mode, chinfo);
+}
+
+
+/*
+ * Read per rate target power (this is the maximum tx power
+ * supported by the card). This info is used when setting
+ * tx power, no matter the channel.
+ *
+ * This also works for v5 EEPROMs.
+ */
+static int
+ath5k_eeprom_read_target_rate_pwr_info(struct ath5k_hw *ah, unsigned int mode)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       struct ath5k_rate_pcal_info *rate_pcal_info;
+       u8 *rate_target_pwr_num;
+       u32 offset;
+       u16 val;
+       int ret, i;
+
+       offset = AR5K_EEPROM_TARGET_PWRSTART(ee->ee_misc1);
+       rate_target_pwr_num = &ee->ee_rate_target_pwr_num[mode];
+       switch (mode) {
+       case AR5K_EEPROM_MODE_11A:
+               offset += AR5K_EEPROM_TARGET_PWR_OFF_11A(ee->ee_version);
+               rate_pcal_info = ee->ee_rate_tpwr_a;
+               ee->ee_rate_target_pwr_num[mode] = AR5K_EEPROM_N_5GHZ_CHAN;
+               break;
+       case AR5K_EEPROM_MODE_11B:
+               offset += AR5K_EEPROM_TARGET_PWR_OFF_11B(ee->ee_version);
+               rate_pcal_info = ee->ee_rate_tpwr_b;
+               ee->ee_rate_target_pwr_num[mode] = 2; /* 3rd is g mode's 1st */
+               break;
+       case AR5K_EEPROM_MODE_11G:
+               offset += AR5K_EEPROM_TARGET_PWR_OFF_11G(ee->ee_version);
+               rate_pcal_info = ee->ee_rate_tpwr_g;
+               ee->ee_rate_target_pwr_num[mode] = AR5K_EEPROM_N_2GHZ_CHAN;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* Different freq mask for older eeproms (<= v3.2) */
+       if (ee->ee_version <= AR5K_EEPROM_VERSION_3_2) {
+               for (i = 0; i < (*rate_target_pwr_num); i++) {
+                       AR5K_EEPROM_READ(offset++, val);
+                       rate_pcal_info[i].freq =
+                           ath5k_eeprom_bin2freq(ee, (val >> 9) & 0x7f, mode);
+
+                       rate_pcal_info[i].target_power_6to24 = ((val >> 3) & 0x3f);
+                       rate_pcal_info[i].target_power_36 = (val << 3) & 0x3f;
+
+                       AR5K_EEPROM_READ(offset++, val);
+
+                       if (rate_pcal_info[i].freq == AR5K_EEPROM_CHANNEL_DIS ||
+                           val == 0) {
+                               (*rate_target_pwr_num) = i;
+                               break;
+                       }
+
+                       rate_pcal_info[i].target_power_36 |= ((val >> 13) & 0x7);
+                       rate_pcal_info[i].target_power_48 = ((val >> 7) & 0x3f);
+                       rate_pcal_info[i].target_power_54 = ((val >> 1) & 0x3f);
+               }
+       } else {
+               for (i = 0; i < (*rate_target_pwr_num); i++) {
+                       AR5K_EEPROM_READ(offset++, val);
+                       rate_pcal_info[i].freq =
+                           ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode);
+
+                       rate_pcal_info[i].target_power_6to24 = ((val >> 2) & 0x3f);
+                       rate_pcal_info[i].target_power_36 = (val << 4) & 0x3f;
+
+                       AR5K_EEPROM_READ(offset++, val);
+
+                       if (rate_pcal_info[i].freq == AR5K_EEPROM_CHANNEL_DIS ||
+                           val == 0) {
+                               (*rate_target_pwr_num) = i;
+                               break;
+                       }
+
+                       rate_pcal_info[i].target_power_36 |= (val >> 12) & 0xf;
+                       rate_pcal_info[i].target_power_48 = ((val >> 6) & 0x3f);
+                       rate_pcal_info[i].target_power_54 = (val & 0x3f);
+               }
+       }
+
+       return 0;
+}
+
+/*
+ * Read per channel calibration info from EEPROM
+ *
+ * This info is used to calibrate the baseband power table. Imagine
+ * that for each channel there is a power curve that's hw specific
+ * (depends on amplifier etc) and we try to "correct" this curve using
+ * offests we pass on to phy chip (baseband -> before amplifier) so that
+ * it can use accurate power values when setting tx power (takes amplifier's
+ * performance on each channel into account).
+ *
+ * EEPROM provides us with the offsets for some pre-calibrated channels
+ * and we have to interpolate to create the full table for these channels and
+ * also the table for any channel.
+ */
+static int
+ath5k_eeprom_read_pcal_info(struct ath5k_hw *ah)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       int (*read_pcal)(struct ath5k_hw *hw, int mode);
+       int mode;
+       int err;
+
+       if ((ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) &&
+                       (AR5K_EEPROM_EEMAP(ee->ee_misc0) == 1))
+               read_pcal = ath5k_eeprom_read_pcal_info_5112;
+       else if ((ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_0) &&
+                       (AR5K_EEPROM_EEMAP(ee->ee_misc0) == 2))
+               read_pcal = ath5k_eeprom_read_pcal_info_2413;
+       else
+               read_pcal = ath5k_eeprom_read_pcal_info_5111;
+
+
+       for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G;
+       mode++) {
+               err = read_pcal(ah, mode);
+               if (err)
+                       return err;
+
+               err = ath5k_eeprom_read_target_rate_pwr_info(ah, mode);
+               if (err < 0)
+                       return err;
+       }
+
+       return 0;
+}
+
+static int
+ath5k_eeprom_free_pcal_info(struct ath5k_hw *ah, int mode)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       struct ath5k_chan_pcal_info *chinfo;
+       u8 pier, pdg;
+
+       switch (mode) {
+       case AR5K_EEPROM_MODE_11A:
+               if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
+                       return 0;
+               chinfo = ee->ee_pwr_cal_a;
+               break;
+       case AR5K_EEPROM_MODE_11B:
+               if (!AR5K_EEPROM_HDR_11B(ee->ee_header))
+                       return 0;
+               chinfo = ee->ee_pwr_cal_b;
+               break;
+       case AR5K_EEPROM_MODE_11G:
+               if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
+                       return 0;
+               chinfo = ee->ee_pwr_cal_g;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
+               if (!chinfo[pier].pd_curves)
+                       continue;
+
+               for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
+                       struct ath5k_pdgain_info *pd =
+                                       &chinfo[pier].pd_curves[pdg];
+
+                       if (pd != NULL) {
+                               free(pd->pd_step);
+                               free(pd->pd_pwr);
+                       }
+               }
+
+               free(chinfo[pier].pd_curves);
+       }
+
+       return 0;
+}
+
+void
+ath5k_eeprom_detach(struct ath5k_hw *ah)
+{
+       u8 mode;
+
+       for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; mode++)
+               ath5k_eeprom_free_pcal_info(ah, mode);
+}
+
+/* Read conformance test limits used for regulatory control */
+static int
+ath5k_eeprom_read_ctl_info(struct ath5k_hw *ah)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       struct ath5k_edge_power *rep;
+       unsigned int fmask, pmask;
+       unsigned int ctl_mode;
+       int ret, i, j;
+       u32 offset;
+       u16 val;
+
+       pmask = AR5K_EEPROM_POWER_M;
+       fmask = AR5K_EEPROM_FREQ_M(ee->ee_version);
+       offset = AR5K_EEPROM_CTL(ee->ee_version);
+       ee->ee_ctls = AR5K_EEPROM_N_CTLS(ee->ee_version);
+       for (i = 0; i < ee->ee_ctls; i += 2) {
+               AR5K_EEPROM_READ(offset++, val);
+               ee->ee_ctl[i] = (val >> 8) & 0xff;
+               ee->ee_ctl[i + 1] = val & 0xff;
+       }
+
+       offset = AR5K_EEPROM_GROUP8_OFFSET;
+       if (ee->ee_version >= AR5K_EEPROM_VERSION_4_0)
+               offset += AR5K_EEPROM_TARGET_PWRSTART(ee->ee_misc1) -
+                       AR5K_EEPROM_GROUP5_OFFSET;
+       else
+               offset += AR5K_EEPROM_GROUPS_START(ee->ee_version);
+
+       rep = ee->ee_ctl_pwr;
+       for(i = 0; i < ee->ee_ctls; i++) {
+               switch(ee->ee_ctl[i] & AR5K_CTL_MODE_M) {
+               case AR5K_CTL_11A:
+               case AR5K_CTL_TURBO:
+                       ctl_mode = AR5K_EEPROM_MODE_11A;
+                       break;
+               default:
+                       ctl_mode = AR5K_EEPROM_MODE_11G;
+                       break;
+               }
+               if (ee->ee_ctl[i] == 0) {
+                       if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3)
+                               offset += 8;
+                       else
+                               offset += 7;
+                       rep += AR5K_EEPROM_N_EDGES;
+                       continue;
+               }
+               if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3) {
+                       for (j = 0; j < AR5K_EEPROM_N_EDGES; j += 2) {
+                               AR5K_EEPROM_READ(offset++, val);
+                               rep[j].freq = (val >> 8) & fmask;
+                               rep[j + 1].freq = val & fmask;
+                       }
+                       for (j = 0; j < AR5K_EEPROM_N_EDGES; j += 2) {
+                               AR5K_EEPROM_READ(offset++, val);
+                               rep[j].edge = (val >> 8) & pmask;
+                               rep[j].flag = (val >> 14) & 1;
+                               rep[j + 1].edge = val & pmask;
+                               rep[j + 1].flag = (val >> 6) & 1;
+                       }
+               } else {
+                       AR5K_EEPROM_READ(offset++, val);
+                       rep[0].freq = (val >> 9) & fmask;
+                       rep[1].freq = (val >> 2) & fmask;
+                       rep[2].freq = (val << 5) & fmask;
+
+                       AR5K_EEPROM_READ(offset++, val);
+                       rep[2].freq |= (val >> 11) & 0x1f;
+                       rep[3].freq = (val >> 4) & fmask;
+                       rep[4].freq = (val << 3) & fmask;
+
+                       AR5K_EEPROM_READ(offset++, val);
+                       rep[4].freq |= (val >> 13) & 0x7;
+                       rep[5].freq = (val >> 6) & fmask;
+                       rep[6].freq = (val << 1) & fmask;
+
+                       AR5K_EEPROM_READ(offset++, val);
+                       rep[6].freq |= (val >> 15) & 0x1;
+                       rep[7].freq = (val >> 8) & fmask;
+
+                       rep[0].edge = (val >> 2) & pmask;
+                       rep[1].edge = (val << 4) & pmask;
+
+                       AR5K_EEPROM_READ(offset++, val);
+                       rep[1].edge |= (val >> 12) & 0xf;
+                       rep[2].edge = (val >> 6) & pmask;
+                       rep[3].edge = val & pmask;
+
+                       AR5K_EEPROM_READ(offset++, val);
+                       rep[4].edge = (val >> 10) & pmask;
+                       rep[5].edge = (val >> 4) & pmask;
+                       rep[6].edge = (val << 2) & pmask;
+
+                       AR5K_EEPROM_READ(offset++, val);
+                       rep[6].edge |= (val >> 14) & 0x3;
+                       rep[7].edge = (val >> 8) & pmask;
+               }
+               for (j = 0; j < AR5K_EEPROM_N_EDGES; j++) {
+                       rep[j].freq = ath5k_eeprom_bin2freq(ee,
+                               rep[j].freq, ctl_mode);
+               }
+               rep += AR5K_EEPROM_N_EDGES;
+       }
+
+       return 0;
+}
+
+
+/*
+ * Initialize eeprom power tables
+ */
+int
+ath5k_eeprom_init(struct ath5k_hw *ah)
+{
+       int err;
+
+       err = ath5k_eeprom_init_header(ah);
+       if (err < 0)
+               return err;
+
+       err = ath5k_eeprom_init_modes(ah);
+       if (err < 0)
+               return err;
+
+       err = ath5k_eeprom_read_pcal_info(ah);
+       if (err < 0)
+               return err;
+
+       err = ath5k_eeprom_read_ctl_info(ah);
+       if (err < 0)
+               return err;
+
+       return 0;
+}
+
+/*
+ * Read the MAC address from eeprom
+ */
+int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
+{
+       u8 mac_d[ETH_ALEN] = {};
+       u32 total, offset;
+       u16 data;
+       int octet, ret;
+
+       ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
+       if (ret)
+               return ret;
+
+       for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
+               ret = ath5k_hw_eeprom_read(ah, offset, &data);
+               if (ret)
+                       return ret;
+
+               total += data;
+               mac_d[octet + 1] = data & 0xff;
+               mac_d[octet] = data >> 8;
+               octet += 2;
+       }
+
+       if (!total || total == 3 * 0xffff)
+               return -EINVAL;
+
+       memcpy(mac, mac_d, ETH_ALEN);
+
+       return 0;
+}
+
+int ath5k_eeprom_is_hb63(struct ath5k_hw *ah)
+{
+       u16 data;
+
+       ath5k_hw_eeprom_read(ah, AR5K_EEPROM_IS_HB63, &data);
+
+       if ((ah->ah_mac_version == (AR5K_SREV_AR2425 >> 4)) && data)
+               return 1;
+       else
+               return 0;
+}
+
diff --git a/src/drivers/net/ath5k/ath5k_gpio.c b/src/drivers/net/ath5k/ath5k_gpio.c
new file mode 100644 (file)
index 0000000..0e8a3e6
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
+ *
+ * Lightly modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+FILE_LICENCE ( MIT );
+
+/****************\
+  GPIO Functions
+\****************/
+
+#include "ath5k.h"
+#include "reg.h"
+#include "base.h"
+
+/*
+ * Set GPIO inputs
+ */
+int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
+{
+       if (gpio >= AR5K_NUM_GPIO)
+               return -EINVAL;
+
+       ath5k_hw_reg_write(ah,
+               (ath5k_hw_reg_read(ah, AR5K_GPIOCR) & ~AR5K_GPIOCR_OUT(gpio))
+               | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
+
+       return 0;
+}
+
+/*
+ * Set GPIO outputs
+ */
+int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
+{
+       if (gpio >= AR5K_NUM_GPIO)
+               return -EINVAL;
+
+       ath5k_hw_reg_write(ah,
+               (ath5k_hw_reg_read(ah, AR5K_GPIOCR) & ~AR5K_GPIOCR_OUT(gpio))
+               | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
+
+       return 0;
+}
+
+/*
+ * Get GPIO state
+ */
+u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
+{
+       if (gpio >= AR5K_NUM_GPIO)
+               return 0xffffffff;
+
+       /* GPIO input magic */
+       return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
+               0x1;
+}
+
+/*
+ * Set GPIO state
+ */
+int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
+{
+       u32 data;
+
+       if (gpio >= AR5K_NUM_GPIO)
+               return -EINVAL;
+
+       /* GPIO output magic */
+       data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
+
+       data &= ~(1 << gpio);
+       data |= (val & 1) << gpio;
+
+       ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
+
+       return 0;
+}
+
+/*
+ * Initialize the GPIO interrupt (RFKill switch)
+ */
+void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
+               u32 interrupt_level)
+{
+       u32 data;
+
+       if (gpio >= AR5K_NUM_GPIO)
+               return;
+
+       /*
+        * Set the GPIO interrupt
+        */
+       data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
+               ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
+               AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
+               (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
+
+       ath5k_hw_reg_write(ah, interrupt_level ? data :
+               (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
+
+       ah->ah_imr |= AR5K_IMR_GPIO;
+
+       /* Enable GPIO interrupts */
+       AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
+}
+
diff --git a/src/drivers/net/ath5k/ath5k_initvals.c b/src/drivers/net/ath5k/ath5k_initvals.c
new file mode 100644 (file)
index 0000000..5911be8
--- /dev/null
@@ -0,0 +1,1560 @@
+/*
+ * Initial register settings functions
+ *
+ * Copyright (c) 2004-2007 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2009 Nick Kossifidis <mickflemm@gmail.com>
+ * Copyright (c) 2007-2008 Jiri Slaby <jirislaby@gmail.com>
+ *
+ * Lightly modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+FILE_LICENCE ( MIT );
+
+#include <unistd.h>
+
+#include "ath5k.h"
+#include "reg.h"
+#include "base.h"
+
+/*
+ * Mode-independent initial register writes
+ */
+
+struct ath5k_ini {
+       u16     ini_register;
+       u32     ini_value;
+
+       enum {
+               AR5K_INI_WRITE = 0,     /* Default */
+               AR5K_INI_READ = 1,      /* Cleared on read */
+       } ini_mode;
+};
+
+/*
+ * Mode specific initial register values
+ */
+
+struct ath5k_ini_mode {
+       u16     mode_register;
+       u32     mode_value[5];
+};
+
+/* Initial register settings for AR5210 */
+static const struct ath5k_ini ar5210_ini[] = {
+       /* PCU and MAC registers */
+       { AR5K_NOQCU_TXDP0,     0, AR5K_INI_WRITE },
+       { AR5K_NOQCU_TXDP1,     0, AR5K_INI_WRITE },
+       { AR5K_RXDP,            0, AR5K_INI_WRITE },
+       { AR5K_CR,              0, AR5K_INI_WRITE },
+       { AR5K_ISR,             0, AR5K_INI_READ },
+       { AR5K_IMR,             0, AR5K_INI_WRITE },
+       { AR5K_IER,             AR5K_IER_DISABLE, AR5K_INI_WRITE },
+       { AR5K_BSR,             0, AR5K_INI_READ },
+       { AR5K_TXCFG,           AR5K_DMASIZE_128B, AR5K_INI_WRITE },
+       { AR5K_RXCFG,           AR5K_DMASIZE_128B, AR5K_INI_WRITE },
+       { AR5K_CFG,             AR5K_INIT_CFG, AR5K_INI_WRITE },
+       { AR5K_TOPS,            8, AR5K_INI_WRITE },
+       { AR5K_RXNOFRM,         8, AR5K_INI_WRITE },
+       { AR5K_RPGTO,           0, AR5K_INI_WRITE },
+       { AR5K_TXNOFRM,         0, AR5K_INI_WRITE },
+       { AR5K_SFR,             0, AR5K_INI_WRITE },
+       { AR5K_MIBC,            0, AR5K_INI_WRITE },
+       { AR5K_MISC,            0, AR5K_INI_WRITE },
+       { AR5K_RX_FILTER_5210,  0, AR5K_INI_WRITE },
+       { AR5K_MCAST_FILTER0_5210, 0, AR5K_INI_WRITE },
+       { AR5K_MCAST_FILTER1_5210, 0, AR5K_INI_WRITE },
+       { AR5K_TX_MASK0,        0, AR5K_INI_WRITE },
+       { AR5K_TX_MASK1,        0, AR5K_INI_WRITE },
+       { AR5K_CLR_TMASK,       0, AR5K_INI_WRITE },
+       { AR5K_TRIG_LVL,        AR5K_TUNE_MIN_TX_FIFO_THRES, AR5K_INI_WRITE },
+       { AR5K_DIAG_SW_5210,    0, AR5K_INI_WRITE },
+       { AR5K_RSSI_THR,        AR5K_TUNE_RSSI_THRES, AR5K_INI_WRITE },
+       { AR5K_TSF_L32_5210,    0, AR5K_INI_WRITE },
+       { AR5K_TIMER0_5210,     0, AR5K_INI_WRITE },
+       { AR5K_TIMER1_5210,     0xffffffff, AR5K_INI_WRITE },
+       { AR5K_TIMER2_5210,     0xffffffff, AR5K_INI_WRITE },
+       { AR5K_TIMER3_5210,     1, AR5K_INI_WRITE },
+       { AR5K_CFP_DUR_5210,    0, AR5K_INI_WRITE },
+       { AR5K_CFP_PERIOD_5210, 0, AR5K_INI_WRITE },
+       /* PHY registers */
+       { AR5K_PHY(0),  0x00000047, AR5K_INI_WRITE },
+       { AR5K_PHY_AGC, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(3),  0x09848ea6, AR5K_INI_WRITE },
+       { AR5K_PHY(4),  0x3d32e000, AR5K_INI_WRITE },
+       { AR5K_PHY(5),  0x0000076b, AR5K_INI_WRITE },
+       { AR5K_PHY_ACT, AR5K_PHY_ACT_DISABLE, AR5K_INI_WRITE },
+       { AR5K_PHY(8),  0x02020200, AR5K_INI_WRITE },
+       { AR5K_PHY(9),  0x00000e0e, AR5K_INI_WRITE },
+       { AR5K_PHY(10), 0x0a020201, AR5K_INI_WRITE },
+       { AR5K_PHY(11), 0x00036ffc, AR5K_INI_WRITE },
+       { AR5K_PHY(12), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(13), 0x00000e0e, AR5K_INI_WRITE },
+       { AR5K_PHY(14), 0x00000007, AR5K_INI_WRITE },
+       { AR5K_PHY(15), 0x00020100, AR5K_INI_WRITE },
+       { AR5K_PHY(16), 0x89630000, AR5K_INI_WRITE },
+       { AR5K_PHY(17), 0x1372169c, AR5K_INI_WRITE },
+       { AR5K_PHY(18), 0x0018b633, AR5K_INI_WRITE },
+       { AR5K_PHY(19), 0x1284613c, AR5K_INI_WRITE },
+       { AR5K_PHY(20), 0x0de8b8e0, AR5K_INI_WRITE },
+       { AR5K_PHY(21), 0x00074859, AR5K_INI_WRITE },
+       { AR5K_PHY(22), 0x7e80beba, AR5K_INI_WRITE },
+       { AR5K_PHY(23), 0x313a665e, AR5K_INI_WRITE },
+       { AR5K_PHY_AGCCTL, 0x00001d08, AR5K_INI_WRITE },
+       { AR5K_PHY(25), 0x0001ce00, AR5K_INI_WRITE },
+       { AR5K_PHY(26), 0x409a4190, AR5K_INI_WRITE },
+       { AR5K_PHY(28), 0x0000000f, AR5K_INI_WRITE },
+       { AR5K_PHY(29), 0x00000080, AR5K_INI_WRITE },
+       { AR5K_PHY(30), 0x00000004, AR5K_INI_WRITE },
+       { AR5K_PHY(31), 0x00000018, AR5K_INI_WRITE },   /* 0x987c */
+       { AR5K_PHY(64), 0x00000000, AR5K_INI_WRITE },   /* 0x9900 */
+       { AR5K_PHY(65), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(66), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(67), 0x00800000, AR5K_INI_WRITE },
+       { AR5K_PHY(68), 0x00000003, AR5K_INI_WRITE },
+       /* BB gain table (64bytes) */
+       { AR5K_BB_GAIN(0), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(1), 0x00000020, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(2), 0x00000010, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(3), 0x00000030, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(4), 0x00000008, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(5), 0x00000028, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(6), 0x00000028, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(7), 0x00000004, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(8), 0x00000024, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(9), 0x00000014, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(10), 0x00000034, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(11), 0x0000000c, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(12), 0x0000002c, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(13), 0x00000002, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(14), 0x00000022, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(15), 0x00000012, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(16), 0x00000032, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(17), 0x0000000a, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(18), 0x0000002a, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(19), 0x00000001, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(20), 0x00000021, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(21), 0x00000011, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(22), 0x00000031, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(23), 0x00000009, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(24), 0x00000029, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(25), 0x00000005, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(26), 0x00000025, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(27), 0x00000015, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(28), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(29), 0x0000000d, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(30), 0x0000002d, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(31), 0x00000003, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(32), 0x00000023, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(33), 0x00000013, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(34), 0x00000033, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(35), 0x0000000b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(36), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(37), 0x00000007, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(38), 0x00000027, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(39), 0x00000017, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(40), 0x00000037, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(41), 0x0000000f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(42), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(43), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(44), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(45), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(46), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(47), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(48), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(49), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(50), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(51), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(52), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(53), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(54), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(55), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(56), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(57), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(58), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(59), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(60), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(61), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(62), 0x0000002f, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(63), 0x0000002f, AR5K_INI_WRITE },
+       /* 5110 RF gain table (64btes) */
+       { AR5K_RF_GAIN(0), 0x0000001d, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(1), 0x0000005d, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(2), 0x0000009d, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(3), 0x000000dd, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(4), 0x0000011d, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(5), 0x00000021, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(6), 0x00000061, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(7), 0x000000a1, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(8), 0x000000e1, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(9), 0x00000031, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(10), 0x00000071, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(11), 0x000000b1, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(12), 0x0000001c, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(13), 0x0000005c, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(14), 0x00000029, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(15), 0x00000069, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(16), 0x000000a9, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(17), 0x00000020, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(18), 0x00000019, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(19), 0x00000059, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(20), 0x00000099, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(21), 0x00000030, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(22), 0x00000005, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(23), 0x00000025, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(24), 0x00000065, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(25), 0x000000a5, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(26), 0x00000028, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(27), 0x00000068, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(28), 0x0000001f, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(29), 0x0000001e, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(30), 0x00000018, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(31), 0x00000058, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(32), 0x00000098, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(33), 0x00000003, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(34), 0x00000004, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(35), 0x00000044, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(36), 0x00000084, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(37), 0x00000013, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(38), 0x00000012, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(39), 0x00000052, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(40), 0x00000092, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(41), 0x000000d2, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(42), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(43), 0x0000002a, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(44), 0x0000006a, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(45), 0x000000aa, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(46), 0x0000001b, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(47), 0x0000001a, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(48), 0x0000005a, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(49), 0x0000009a, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(50), 0x000000da, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(51), 0x00000006, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(52), 0x00000006, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(53), 0x00000006, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(54), 0x00000006, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(55), 0x00000006, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(56), 0x00000006, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(57), 0x00000006, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(58), 0x00000006, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(59), 0x00000006, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(60), 0x00000006, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(61), 0x00000006, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(62), 0x00000006, AR5K_INI_WRITE },
+       { AR5K_RF_GAIN(63), 0x00000006, AR5K_INI_WRITE },
+       /* PHY activation */
+       { AR5K_PHY(53), 0x00000020, AR5K_INI_WRITE },
+       { AR5K_PHY(51), 0x00000004, AR5K_INI_WRITE },
+       { AR5K_PHY(50), 0x00060106, AR5K_INI_WRITE },
+       { AR5K_PHY(39), 0x0000006d, AR5K_INI_WRITE },
+       { AR5K_PHY(48), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(52), 0x00000014, AR5K_INI_WRITE },
+       { AR5K_PHY_ACT, AR5K_PHY_ACT_ENABLE, AR5K_INI_WRITE },
+};
+
+/* Initial register settings for AR5211 */
+static const struct ath5k_ini ar5211_ini[] = {
+       { AR5K_RXDP,            0x00000000, AR5K_INI_WRITE },
+       { AR5K_RTSD0,           0x84849c9c, AR5K_INI_WRITE },
+       { AR5K_RTSD1,           0x7c7c7c7c, AR5K_INI_WRITE },
+       { AR5K_RXCFG,           0x00000005, AR5K_INI_WRITE },
+       { AR5K_MIBC,            0x00000000, AR5K_INI_WRITE },
+       { AR5K_TOPS,            0x00000008, AR5K_INI_WRITE },
+       { AR5K_RXNOFRM,         0x00000008, AR5K_INI_WRITE },
+       { AR5K_TXNOFRM,         0x00000010, AR5K_INI_WRITE },
+       { AR5K_RPGTO,           0x00000000, AR5K_INI_WRITE },
+       { AR5K_RFCNT,           0x0000001f, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(0),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(1),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(2),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(3),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(4),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(5),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(6),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(7),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(8),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(9),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_FP,          0x00000000, AR5K_INI_WRITE },
+       { AR5K_STA_ID1,         0x00000000, AR5K_INI_WRITE },
+       { AR5K_BSS_ID0,         0x00000000, AR5K_INI_WRITE },
+       { AR5K_BSS_ID1,         0x00000000, AR5K_INI_WRITE },
+       { AR5K_RSSI_THR,        0x00000000, AR5K_INI_WRITE },
+       { AR5K_CFP_PERIOD_5211, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_TIMER0_5211,     0x00000030, AR5K_INI_WRITE },
+       { AR5K_TIMER1_5211,     0x0007ffff, AR5K_INI_WRITE },
+       { AR5K_TIMER2_5211,     0x01ffffff, AR5K_INI_WRITE },
+       { AR5K_TIMER3_5211,     0x00000031, AR5K_INI_WRITE },
+       { AR5K_CFP_DUR_5211,    0x00000000, AR5K_INI_WRITE },
+       { AR5K_RX_FILTER_5211,  0x00000000, AR5K_INI_WRITE },
+       { AR5K_MCAST_FILTER0_5211, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_MCAST_FILTER1_5211, 0x00000002, AR5K_INI_WRITE },
+       { AR5K_DIAG_SW_5211,    0x00000000, AR5K_INI_WRITE },
+       { AR5K_ADDAC_TEST,      0x00000000, AR5K_INI_WRITE },
+       { AR5K_DEFAULT_ANTENNA, 0x00000000, AR5K_INI_WRITE },
+       /* PHY registers */
+       { AR5K_PHY_AGC, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(3),  0x2d849093, AR5K_INI_WRITE },
+       { AR5K_PHY(4),  0x7d32e000, AR5K_INI_WRITE },
+       { AR5K_PHY(5),  0x00000f6b, AR5K_INI_WRITE },
+       { AR5K_PHY_ACT, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(11), 0x00026ffe, AR5K_INI_WRITE },
+       { AR5K_PHY(12), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(15), 0x00020100, AR5K_INI_WRITE },
+       { AR5K_PHY(16), 0x206a017a, AR5K_INI_WRITE },
+       { AR5K_PHY(19), 0x1284613c, AR5K_INI_WRITE },
+       { AR5K_PHY(21), 0x00000859, AR5K_INI_WRITE },
+       { AR5K_PHY(26), 0x409a4190, AR5K_INI_WRITE },   /* 0x9868 */
+       { AR5K_PHY(27), 0x050cb081, AR5K_INI_WRITE },
+       { AR5K_PHY(28), 0x0000000f, AR5K_INI_WRITE },
+       { AR5K_PHY(29), 0x00000080, AR5K_INI_WRITE },
+       { AR5K_PHY(30), 0x0000000c, AR5K_INI_WRITE },
+       { AR5K_PHY(64), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(65), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(66), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(67), 0x00800000, AR5K_INI_WRITE },
+       { AR5K_PHY(68), 0x00000001, AR5K_INI_WRITE },
+       { AR5K_PHY(71), 0x0000092a, AR5K_INI_WRITE },
+       { AR5K_PHY_IQ,  0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(73), 0x00058a05, AR5K_INI_WRITE },
+       { AR5K_PHY(74), 0x00000001, AR5K_INI_WRITE },
+       { AR5K_PHY(75), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_PAPD_PROBE, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(77), 0x00000000, AR5K_INI_WRITE },   /* 0x9934 */
+       { AR5K_PHY(78), 0x00000000, AR5K_INI_WRITE },   /* 0x9938 */
+       { AR5K_PHY(79), 0x0000003f, AR5K_INI_WRITE },   /* 0x993c */
+       { AR5K_PHY(80), 0x00000004, AR5K_INI_WRITE },
+       { AR5K_PHY(82), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(83), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(84), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_RADAR, 0x5d50f14c, AR5K_INI_WRITE },
+       { AR5K_PHY(86), 0x00000018, AR5K_INI_WRITE },
+       { AR5K_PHY(87), 0x004b6a8e, AR5K_INI_WRITE },
+       /* Initial Power table (32bytes)
+        * common on all cards/modes.
+        * Note: Table is rewritten during
+        * txpower setup later using calibration
+        * data etc. so next write is non-common */
+       { AR5K_PHY_PCDAC_TXPOWER(1), 0x06ff05ff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(2), 0x07ff07ff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(3), 0x08ff08ff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(4), 0x09ff09ff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(5), 0x0aff0aff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(6), 0x0bff0bff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(7), 0x0cff0cff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(8), 0x0dff0dff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(9), 0x0fff0eff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(10), 0x12ff12ff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(11), 0x14ff13ff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(12), 0x16ff15ff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(13), 0x19ff17ff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(14), 0x1bff1aff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(15), 0x1eff1dff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(16), 0x23ff20ff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(17), 0x27ff25ff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(18), 0x2cff29ff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(19), 0x31ff2fff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(20), 0x37ff34ff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(21), 0x3aff3aff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(22), 0x3aff3aff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(23), 0x3aff3aff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(24), 0x3aff3aff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(25), 0x3aff3aff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(26), 0x3aff3aff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(27), 0x3aff3aff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(28), 0x3aff3aff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(29), 0x3aff3aff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(30), 0x3aff3aff, AR5K_INI_WRITE },
+       { AR5K_PHY_PCDAC_TXPOWER(31), 0x3aff3aff, AR5K_INI_WRITE },
+       { AR5K_PHY_CCKTXCTL, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(642), 0x503e4646, AR5K_INI_WRITE },
+       { AR5K_PHY_GAIN_2GHZ, 0x6480416c, AR5K_INI_WRITE },
+       { AR5K_PHY(644), 0x0199a003, AR5K_INI_WRITE },
+       { AR5K_PHY(645), 0x044cd610, AR5K_INI_WRITE },
+       { AR5K_PHY(646), 0x13800040, AR5K_INI_WRITE },
+       { AR5K_PHY(647), 0x1be00060, AR5K_INI_WRITE },
+       { AR5K_PHY(648), 0x0c53800a, AR5K_INI_WRITE },
+       { AR5K_PHY(649), 0x0014df3b, AR5K_INI_WRITE },
+       { AR5K_PHY(650), 0x000001b5, AR5K_INI_WRITE },
+       { AR5K_PHY(651), 0x00000020, AR5K_INI_WRITE },
+};
+
+/* Initial mode-specific settings for AR5211
+ * 5211 supports OFDM-only g (draft g) but we
+ * need to test it !
+ */
+static const struct ath5k_ini_mode ar5211_ini_mode[] = {
+       { AR5K_TXCFG,
+       /*        a         aTurbo        b       g (OFDM)    */
+          { 0x00000015, 0x00000015, 0x0000001d, 0x00000015 } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(0),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(1),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(2),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(3),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(4),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(5),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(6),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(7),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(8),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(9),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f } },
+       { AR5K_DCU_GBL_IFS_SLOT,
+          { 0x00000168, 0x000001e0, 0x000001b8, 0x00000168 } },
+       { AR5K_DCU_GBL_IFS_SIFS,
+          { 0x00000230, 0x000001e0, 0x000000b0, 0x00000230 } },
+       { AR5K_DCU_GBL_IFS_EIFS,
+          { 0x00000d98, 0x00001180, 0x00001f48, 0x00000d98 } },
+       { AR5K_DCU_GBL_IFS_MISC,
+          { 0x0000a0e0, 0x00014068, 0x00005880, 0x0000a0e0 } },
+       { AR5K_TIME_OUT,
+          { 0x04000400, 0x08000800, 0x20003000, 0x04000400 } },
+       { AR5K_USEC_5211,
+          { 0x0e8d8fa7, 0x0e8d8fcf, 0x01608f95, 0x0e8d8fa7 } },
+       { AR5K_PHY_TURBO,
+          { 0x00000000, 0x00000003, 0x00000000, 0x00000000 } },
+       { AR5K_PHY(8),
+          { 0x02020200, 0x02020200, 0x02010200, 0x02020200 } },
+       { AR5K_PHY(9),
+          { 0x00000e0e, 0x00000e0e, 0x00000707, 0x00000e0e } },
+       { AR5K_PHY(10),
+          { 0x0a020001, 0x0a020001, 0x05010000, 0x0a020001 } },
+       { AR5K_PHY(13),
+          { 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e } },
+       { AR5K_PHY(14),
+          { 0x00000007, 0x00000007, 0x0000000b, 0x0000000b } },
+       { AR5K_PHY(17),
+          { 0x1372169c, 0x137216a5, 0x137216a8, 0x1372169c } },
+       { AR5K_PHY(18),
+          { 0x0018ba67, 0x0018ba67, 0x0018ba69, 0x0018ba69 } },
+       { AR5K_PHY(20),
+          { 0x0c28b4e0, 0x0c28b4e0, 0x0c28b4e0, 0x0c28b4e0 } },
+       { AR5K_PHY_SIG,
+          { 0x7e800d2e, 0x7e800d2e, 0x7ec00d2e, 0x7e800d2e } },
+       { AR5K_PHY_AGCCOARSE,
+          { 0x31375d5e, 0x31375d5e, 0x313a5d5e, 0x31375d5e } },
+       { AR5K_PHY_AGCCTL,
+          { 0x0000bd10, 0x0000bd10, 0x0000bd38, 0x0000bd10 } },
+       { AR5K_PHY_NF,
+          { 0x0001ce00, 0x0001ce00, 0x0001ce00, 0x0001ce00 } },
+       { AR5K_PHY_RX_DELAY,
+          { 0x00002710, 0x00002710, 0x0000157c, 0x00002710 } },
+       { AR5K_PHY(70),
+          { 0x00000190, 0x00000190, 0x00000084, 0x00000190 } },
+       { AR5K_PHY_FRAME_CTL_5211,
+          { 0x6fe01020, 0x6fe01020, 0x6fe00920, 0x6fe01020 } },
+       { AR5K_PHY_PCDAC_TXPOWER_BASE,
+          { 0x05ff14ff, 0x05ff14ff, 0x05ff14ff, 0x05ff19ff } },
+       { AR5K_RF_BUFFER_CONTROL_4,
+          { 0x00000010, 0x00000014, 0x00000010, 0x00000010 } },
+};
+
+/* Initial register settings for AR5212 */
+static const struct ath5k_ini ar5212_ini_common_start[] = {
+       { AR5K_RXDP,            0x00000000, AR5K_INI_WRITE },
+       { AR5K_RXCFG,           0x00000005, AR5K_INI_WRITE },
+       { AR5K_MIBC,            0x00000000, AR5K_INI_WRITE },
+       { AR5K_TOPS,            0x00000008, AR5K_INI_WRITE },
+       { AR5K_RXNOFRM,         0x00000008, AR5K_INI_WRITE },
+       { AR5K_TXNOFRM,         0x00000010, AR5K_INI_WRITE },
+       { AR5K_RPGTO,           0x00000000, AR5K_INI_WRITE },
+       { AR5K_RFCNT,           0x0000001f, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(0),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(1),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(2),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(3),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(4),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(5),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(6),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(7),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(8),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUEUE_TXDP(9),   0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_FP,          0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TXP,         0x00000000, AR5K_INI_WRITE },
+       /* Tx filter table 0 (32 entries) */
+       { AR5K_DCU_TX_FILTER_0(0),  0x00000000, AR5K_INI_WRITE }, /* DCU 0 */
+       { AR5K_DCU_TX_FILTER_0(1),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(2),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(3),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(4),  0x00000000, AR5K_INI_WRITE }, /* DCU 1 */
+       { AR5K_DCU_TX_FILTER_0(5),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(6),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(7),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(8),  0x00000000, AR5K_INI_WRITE }, /* DCU 2 */
+       { AR5K_DCU_TX_FILTER_0(9),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(10), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(11), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(12), 0x00000000, AR5K_INI_WRITE }, /* DCU 3 */
+       { AR5K_DCU_TX_FILTER_0(13), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(14), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(15), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(16), 0x00000000, AR5K_INI_WRITE }, /* DCU 4 */
+       { AR5K_DCU_TX_FILTER_0(17), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(18), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(19), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(20), 0x00000000, AR5K_INI_WRITE }, /* DCU 5 */
+       { AR5K_DCU_TX_FILTER_0(21), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(22), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(23), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(24), 0x00000000, AR5K_INI_WRITE }, /* DCU 6 */
+       { AR5K_DCU_TX_FILTER_0(25), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(26), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(27), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(28), 0x00000000, AR5K_INI_WRITE }, /* DCU 7 */
+       { AR5K_DCU_TX_FILTER_0(29), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(30), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_0(31), 0x00000000, AR5K_INI_WRITE },
+       /* Tx filter table 1 (16 entries) */
+       { AR5K_DCU_TX_FILTER_1(0),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(1),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(2),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(3),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(4),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(5),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(6),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(7),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(8),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(9),  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(10), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(11), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(12), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(13), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(14), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_1(15), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_CLR, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_SET, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_CLR, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_DCU_TX_FILTER_SET, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_STA_ID1,         0x00000000, AR5K_INI_WRITE },
+       { AR5K_BSS_ID0,         0x00000000, AR5K_INI_WRITE },
+       { AR5K_BSS_ID1,         0x00000000, AR5K_INI_WRITE },
+       { AR5K_BEACON_5211,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_CFP_PERIOD_5211, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_TIMER0_5211,     0x00000030, AR5K_INI_WRITE },
+       { AR5K_TIMER1_5211,     0x0007ffff, AR5K_INI_WRITE },
+       { AR5K_TIMER2_5211,     0x01ffffff, AR5K_INI_WRITE },
+       { AR5K_TIMER3_5211,     0x00000031, AR5K_INI_WRITE },
+       { AR5K_CFP_DUR_5211,    0x00000000, AR5K_INI_WRITE },
+       { AR5K_RX_FILTER_5211,  0x00000000, AR5K_INI_WRITE },
+       { AR5K_DIAG_SW_5211,    0x00000000, AR5K_INI_WRITE },
+       { AR5K_ADDAC_TEST,      0x00000000, AR5K_INI_WRITE },
+       { AR5K_DEFAULT_ANTENNA, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_FRAME_CTL_QOSM,  0x000fc78f, AR5K_INI_WRITE },
+       { AR5K_XRMODE,          0x2a82301a, AR5K_INI_WRITE },
+       { AR5K_XRDELAY,         0x05dc01e0, AR5K_INI_WRITE },
+       { AR5K_XRTIMEOUT,       0x1f402710, AR5K_INI_WRITE },
+       { AR5K_XRCHIRP,         0x01f40000, AR5K_INI_WRITE },
+       { AR5K_XRSTOMP,         0x00001e1c, AR5K_INI_WRITE },
+       { AR5K_SLEEP0,          0x0002aaaa, AR5K_INI_WRITE },
+       { AR5K_SLEEP1,          0x02005555, AR5K_INI_WRITE },
+       { AR5K_SLEEP2,          0x00000000, AR5K_INI_WRITE },
+       { AR5K_BSS_IDM0,        0xffffffff, AR5K_INI_WRITE },
+       { AR5K_BSS_IDM1,        0x0000ffff, AR5K_INI_WRITE },
+       { AR5K_TXPC,            0x00000000, AR5K_INI_WRITE },
+       { AR5K_PROFCNT_TX,      0x00000000, AR5K_INI_WRITE },
+       { AR5K_PROFCNT_RX,      0x00000000, AR5K_INI_WRITE },
+       { AR5K_PROFCNT_RXCLR,   0x00000000, AR5K_INI_WRITE },
+       { AR5K_PROFCNT_CYCLE,   0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUIET_CTL1,      0x00000088, AR5K_INI_WRITE },
+       /* Initial rate duration table (32 entries )*/
+       { AR5K_RATE_DUR(0),     0x00000000, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(1),     0x0000008c, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(2),     0x000000e4, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(3),     0x000002d5, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(4),     0x00000000, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(5),     0x00000000, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(6),     0x000000a0, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(7),     0x000001c9, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(8),     0x0000002c, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(9),     0x0000002c, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(10),    0x00000030, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(11),    0x0000003c, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(12),    0x0000002c, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(13),    0x0000002c, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(14),    0x00000030, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(15),    0x0000003c, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(16),    0x00000000, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(17),    0x00000000, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(18),    0x00000000, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(19),    0x00000000, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(20),    0x00000000, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(21),    0x00000000, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(22),    0x00000000, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(23),    0x00000000, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(24),    0x000000d5, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(25),    0x000000df, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(26),    0x00000102, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(27),    0x0000013a, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(28),    0x00000075, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(29),    0x0000007f, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(30),    0x000000a2, AR5K_INI_WRITE },
+       { AR5K_RATE_DUR(31),    0x00000000, AR5K_INI_WRITE },
+       { AR5K_QUIET_CTL2,      0x00010002, AR5K_INI_WRITE },
+       { AR5K_TSF_PARM,        0x00000001, AR5K_INI_WRITE },
+       { AR5K_QOS_NOACK,       0x000000c0, AR5K_INI_WRITE },
+       { AR5K_PHY_ERR_FIL,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_XRLAT_TX,        0x00000168, AR5K_INI_WRITE },
+       { AR5K_ACKSIFS,         0x00000000, AR5K_INI_WRITE },
+       /* Rate -> db table
+        * notice ...03<-02<-01<-00 ! */
+       { AR5K_RATE2DB(0),      0x03020100, AR5K_INI_WRITE },
+       { AR5K_RATE2DB(1),      0x07060504, AR5K_INI_WRITE },
+       { AR5K_RATE2DB(2),      0x0b0a0908, AR5K_INI_WRITE },
+       { AR5K_RATE2DB(3),      0x0f0e0d0c, AR5K_INI_WRITE },
+       { AR5K_RATE2DB(4),      0x13121110, AR5K_INI_WRITE },
+       { AR5K_RATE2DB(5),      0x17161514, AR5K_INI_WRITE },
+       { AR5K_RATE2DB(6),      0x1b1a1918, AR5K_INI_WRITE },
+       { AR5K_RATE2DB(7),      0x1f1e1d1c, AR5K_INI_WRITE },
+       /* Db -> Rate table */
+       { AR5K_DB2RATE(0),      0x03020100, AR5K_INI_WRITE },
+       { AR5K_DB2RATE(1),      0x07060504, AR5K_INI_WRITE },
+       { AR5K_DB2RATE(2),      0x0b0a0908, AR5K_INI_WRITE },
+       { AR5K_DB2RATE(3),      0x0f0e0d0c, AR5K_INI_WRITE },
+       { AR5K_DB2RATE(4),      0x13121110, AR5K_INI_WRITE },
+       { AR5K_DB2RATE(5),      0x17161514, AR5K_INI_WRITE },
+       { AR5K_DB2RATE(6),      0x1b1a1918, AR5K_INI_WRITE },
+       { AR5K_DB2RATE(7),      0x1f1e1d1c, AR5K_INI_WRITE },
+       /* PHY registers (Common settings
+        * for all chips/modes) */
+       { AR5K_PHY(3),          0xad848e19, AR5K_INI_WRITE },
+       { AR5K_PHY(4),          0x7d28e000, AR5K_INI_WRITE },
+       { AR5K_PHY_TIMING_3,    0x9c0a9f6b, AR5K_INI_WRITE },
+       { AR5K_PHY_ACT,         0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY(16),         0x206a017a, AR5K_INI_WRITE },
+       { AR5K_PHY(21),         0x00000859, AR5K_INI_WRITE },
+       { AR5K_PHY_BIN_MASK_1,  0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_BIN_MASK_2,  0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_BIN_MASK_3,  0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_BIN_MASK_CTL, 0x00800000, AR5K_INI_WRITE },
+       { AR5K_PHY_ANT_CTL,     0x00000001, AR5K_INI_WRITE },
+       /*{ AR5K_PHY(71), 0x0000092a, AR5K_INI_WRITE },*/ /* Old value */
+       { AR5K_PHY_MAX_RX_LEN,  0x00000c80, AR5K_INI_WRITE },
+       { AR5K_PHY_IQ,          0x05100000, AR5K_INI_WRITE },
+       { AR5K_PHY_WARM_RESET,  0x00000001, AR5K_INI_WRITE },
+       { AR5K_PHY_CTL,         0x00000004, AR5K_INI_WRITE },
+       { AR5K_PHY_TXPOWER_RATE1, 0x1e1f2022, AR5K_INI_WRITE },
+       { AR5K_PHY_TXPOWER_RATE2, 0x0a0b0c0d, AR5K_INI_WRITE },
+       { AR5K_PHY_TXPOWER_RATE_MAX, 0x0000003f, AR5K_INI_WRITE },
+       { AR5K_PHY(82),         0x9280b212, AR5K_INI_WRITE },
+       { AR5K_PHY_RADAR,       0x5d50e188, AR5K_INI_WRITE },
+       /*{ AR5K_PHY(86), 0x000000ff, AR5K_INI_WRITE },*/
+       { AR5K_PHY(87),         0x004b6a8e, AR5K_INI_WRITE },
+       { AR5K_PHY_NFTHRES,     0x000003ce, AR5K_INI_WRITE },
+       { AR5K_PHY_RESTART,     0x192fb515, AR5K_INI_WRITE },
+       { AR5K_PHY(94),         0x00000001, AR5K_INI_WRITE },
+       { AR5K_PHY_RFBUS_REQ,   0x00000000, AR5K_INI_WRITE },
+       /*{ AR5K_PHY(644), 0x0080a333, AR5K_INI_WRITE },*/ /* Old value */
+       /*{ AR5K_PHY(645), 0x00206c10, AR5K_INI_WRITE },*/ /* Old value */
+       { AR5K_PHY(644),        0x00806333, AR5K_INI_WRITE },
+       { AR5K_PHY(645),        0x00106c10, AR5K_INI_WRITE },
+       { AR5K_PHY(646),        0x009c4060, AR5K_INI_WRITE },
+       /* { AR5K_PHY(647), 0x1483800a, AR5K_INI_WRITE }, */
+       /* { AR5K_PHY(648), 0x01831061, AR5K_INI_WRITE }, */ /* Old value */
+       { AR5K_PHY(648),        0x018830c6, AR5K_INI_WRITE },
+       { AR5K_PHY(649),        0x00000400, AR5K_INI_WRITE },
+       /*{ AR5K_PHY(650), 0x000001b5, AR5K_INI_WRITE },*/
+       { AR5K_PHY(651),        0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_TXPOWER_RATE3, 0x20202020, AR5K_INI_WRITE },
+       { AR5K_PHY_TXPOWER_RATE2, 0x20202020, AR5K_INI_WRITE },
+       /*{ AR5K_PHY(655), 0x13c889af, AR5K_INI_WRITE },*/
+       { AR5K_PHY(656),        0x38490a20, AR5K_INI_WRITE },
+       { AR5K_PHY(657),        0x00007bb6, AR5K_INI_WRITE },
+       { AR5K_PHY(658),        0x0fff3ffc, AR5K_INI_WRITE },
+};
+
+/* Initial mode-specific settings for AR5212 (Written before ar5212_ini) */
+static const struct ath5k_ini_mode ar5212_ini_mode_start[] = {
+       { AR5K_QUEUE_DFS_LOCAL_IFS(0),
+       /*      a/XR       aTurbo         b        g (DYN)     gTurbo     */
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(1),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(2),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(3),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(4),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(5),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(6),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(7),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(8),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f, 0x002ffc0f } },
+       { AR5K_QUEUE_DFS_LOCAL_IFS(9),
+          { 0x002ffc0f, 0x002ffc0f, 0x002ffc1f, 0x002ffc0f, 0x002ffc0f } },
+       { AR5K_DCU_GBL_IFS_SIFS,
+          { 0x00000230, 0x000001e0, 0x000000b0, 0x00000160, 0x000001e0 } },
+       { AR5K_DCU_GBL_IFS_SLOT,
+          { 0x00000168, 0x000001e0, 0x000001b8, 0x0000018c, 0x000001e0 } },
+       { AR5K_DCU_GBL_IFS_EIFS,
+          { 0x00000e60, 0x00001180, 0x00001f1c, 0x00003e38, 0x00001180 } },
+       { AR5K_DCU_GBL_IFS_MISC,
+          { 0x0000a0e0, 0x00014068, 0x00005880, 0x0000b0e0, 0x00014068 } },
+       { AR5K_TIME_OUT,
+          { 0x03e803e8, 0x06e006e0, 0x04200420, 0x08400840, 0x06e006e0 } },
+       { AR5K_PHY_TURBO,
+          { 0x00000000, 0x00000003, 0x00000000, 0x00000000, 0x00000003 } },
+       { AR5K_PHY(8),
+          { 0x02020200, 0x02020200, 0x02010200, 0x02020200, 0x02020200 } },
+       { AR5K_PHY_RF_CTL2,
+          { 0x00000e0e, 0x00000e0e, 0x00000707, 0x00000e0e, 0x00000e0e } },
+       { AR5K_PHY_SETTLING,
+          { 0x1372161c, 0x13721c25, 0x13721722, 0x137216a2, 0x13721c25 } },
+       { AR5K_PHY_AGCCTL,
+          { 0x00009d10, 0x00009d10, 0x00009d18, 0x00009d18, 0x00009d18 } },
+       { AR5K_PHY_NF,
+          { 0x0001ce00, 0x0001ce00, 0x0001ce00, 0x0001ce00, 0x0001ce00 } },
+       { AR5K_PHY_WEAK_OFDM_HIGH_THR,
+          { 0x409a4190, 0x409a4190, 0x409a4190, 0x409a4190, 0x409a4190 } },
+       { AR5K_PHY(70),
+          { 0x000001b8, 0x000001b8, 0x00000084, 0x00000108, 0x000001b8 } },
+       { AR5K_PHY_OFDM_SELFCORR,
+          { 0x10058a05, 0x10058a05, 0x10058a05, 0x10058a05, 0x10058a05 } },
+       { 0xa230,
+          { 0x00000000, 0x00000000, 0x00000000, 0x00000108, 0x00000000 } },
+};
+
+/* Initial mode-specific settings for AR5212 + RF5111 (Written after ar5212_ini) */
+static const struct ath5k_ini_mode rf5111_ini_mode_end[] = {
+       { AR5K_TXCFG,
+       /*      a/XR       aTurbo         b        g (DYN)     gTurbo     */
+          { 0x00008015, 0x00008015, 0x00008015, 0x00008015, 0x00008015 } },
+       { AR5K_USEC_5211,
+          { 0x128d8fa7, 0x09880fcf, 0x04e00f95, 0x12e00fab, 0x09880fcf } },
+       { AR5K_PHY_RF_CTL3,
+          { 0x0a020001, 0x0a020001, 0x05010100, 0x0a020001, 0x0a020001 } },
+       { AR5K_PHY_RF_CTL4,
+          { 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e } },
+       { AR5K_PHY_PA_CTL,
+          { 0x00000007, 0x00000007, 0x0000000b, 0x0000000b, 0x0000000b } },
+       { AR5K_PHY_GAIN,
+          { 0x0018da5a, 0x0018da5a, 0x0018ca69, 0x0018ca69, 0x0018ca69 } },
+       { AR5K_PHY_DESIRED_SIZE,
+          { 0x0de8b4e0, 0x0de8b4e0, 0x0de8b4e0, 0x0de8b4e0, 0x0de8b4e0 } },
+       { AR5K_PHY_SIG,
+          { 0x7e800d2e, 0x7e800d2e, 0x7ee84d2e, 0x7ee84d2e, 0x7e800d2e } },
+       { AR5K_PHY_AGCCOARSE,
+          { 0x3137665e, 0x3137665e, 0x3137665e, 0x3137665e, 0x3137615e } },
+       { AR5K_PHY_WEAK_OFDM_LOW_THR,
+          { 0x050cb081, 0x050cb081, 0x050cb081, 0x050cb080, 0x050cb080 } },
+       { AR5K_PHY_RX_DELAY,
+          { 0x00002710, 0x00002710, 0x0000157c, 0x00002af8, 0x00002710 } },
+       { AR5K_PHY_FRAME_CTL_5211,
+          { 0xf7b81020, 0xf7b81020, 0xf7b80d20, 0xf7b81020, 0xf7b81020 } },
+       { AR5K_PHY_GAIN_2GHZ,
+          { 0x642c416a, 0x642c416a, 0x6440416a, 0x6440416a, 0x6440416a } },
+       { AR5K_PHY_CCK_RX_CTL_4,
+          { 0x1883800a, 0x1883800a, 0x1873800a, 0x1883800a, 0x1883800a } },
+};
+
+static const struct ath5k_ini rf5111_ini_common_end[] = {
+       { AR5K_DCU_FP,          0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_AGC,         0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_ADC_CTL,     0x00022ffe, AR5K_INI_WRITE },
+       { 0x983c,               0x00020100, AR5K_INI_WRITE },
+       { AR5K_PHY_GAIN_OFFSET, 0x1284613c, AR5K_INI_WRITE },
+       { AR5K_PHY_PAPD_PROBE,  0x00004883, AR5K_INI_WRITE },
+       { 0x9940,               0x00000004, AR5K_INI_WRITE },
+       { 0x9958,               0x000000ff, AR5K_INI_WRITE },
+       { 0x9974,               0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_SPENDING,    0x00000018, AR5K_INI_WRITE },
+       { AR5K_PHY_CCKTXCTL,    0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_CCK_CROSSCORR, 0xd03e6788, AR5K_INI_WRITE },
+       { AR5K_PHY_DAG_CCK_CTL, 0x000001b5, AR5K_INI_WRITE },
+       { 0xa23c,               0x13c889af, AR5K_INI_WRITE },
+};
+
+/* Initial mode-specific settings for AR5212 + RF5112 (Written after ar5212_ini) */
+static const struct ath5k_ini_mode rf5112_ini_mode_end[] = {
+       { AR5K_TXCFG,
+       /*      a/XR       aTurbo         b        g (DYN)     gTurbo     */
+          { 0x00008015, 0x00008015, 0x00008015, 0x00008015, 0x00008015 } },
+       { AR5K_USEC_5211,
+          { 0x128d93a7, 0x098813cf, 0x04e01395, 0x12e013ab, 0x098813cf } },
+       { AR5K_PHY_RF_CTL3,
+          { 0x0a020001, 0x0a020001, 0x05020100, 0x0a020001, 0x0a020001 } },
+       { AR5K_PHY_RF_CTL4,
+          { 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e } },
+       { AR5K_PHY_PA_CTL,
+          { 0x00000007, 0x00000007, 0x0000000b, 0x0000000b, 0x0000000b } },
+       { AR5K_PHY_GAIN,
+          { 0x0018da6d, 0x0018da6d, 0x0018ca75, 0x0018ca75, 0x0018ca75 } },
+       { AR5K_PHY_DESIRED_SIZE,
+          { 0x0de8b4e0, 0x0de8b4e0, 0x0de8b4e0, 0x0de8b4e0, 0x0de8b4e0 } },
+       { AR5K_PHY_SIG,
+          { 0x7e800d2e, 0x7e800d2e, 0x7ee80d2e, 0x7ee80d2e, 0x7ee80d2e } },
+       { AR5K_PHY_AGCCOARSE,
+          { 0x3137665e, 0x3137665e, 0x3137665e, 0x3137665e, 0x3137665e } },
+       { AR5K_PHY_WEAK_OFDM_LOW_THR,
+          { 0x050cb081, 0x050cb081, 0x050cb081, 0x050cb081, 0x050cb081 } },
+       { AR5K_PHY_RX_DELAY,
+          { 0x000007d0, 0x000007d0, 0x0000044c, 0x00000898, 0x000007d0 } },
+       { AR5K_PHY_FRAME_CTL_5211,
+          { 0xf7b81020, 0xf7b81020, 0xf7b80d10, 0xf7b81010, 0xf7b81010 } },
+       { AR5K_PHY_CCKTXCTL,
+          { 0x00000000, 0x00000000, 0x00000008, 0x00000008, 0x00000008 } },
+       { AR5K_PHY_CCK_CROSSCORR,
+          { 0xd6be6788, 0xd6be6788, 0xd03e6788, 0xd03e6788, 0xd03e6788 } },
+       { AR5K_PHY_GAIN_2GHZ,
+          { 0x642c0140, 0x642c0140, 0x6442c160, 0x6442c160, 0x6442c160 } },
+       { AR5K_PHY_CCK_RX_CTL_4,
+          { 0x1883800a, 0x1883800a, 0x1873800a, 0x1883800a, 0x1883800a } },
+};
+
+static const struct ath5k_ini rf5112_ini_common_end[] = {
+       { AR5K_DCU_FP,          0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_AGC,         0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_ADC_CTL,     0x00022ffe, AR5K_INI_WRITE },
+       { 0x983c,               0x00020100, AR5K_INI_WRITE },
+       { AR5K_PHY_GAIN_OFFSET, 0x1284613c, AR5K_INI_WRITE },
+       { AR5K_PHY_PAPD_PROBE,  0x00004882, AR5K_INI_WRITE },
+       { 0x9940,               0x00000004, AR5K_INI_WRITE },
+       { 0x9958,               0x000000ff, AR5K_INI_WRITE },
+       { 0x9974,               0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_DAG_CCK_CTL, 0x000001b5, AR5K_INI_WRITE },
+       { 0xa23c,               0x13c889af, AR5K_INI_WRITE },
+};
+
+/* Initial mode-specific settings for RF5413/5414 (Written after ar5212_ini) */
+static const struct ath5k_ini_mode rf5413_ini_mode_end[] = {
+       { AR5K_TXCFG,
+       /*      a/XR       aTurbo         b        g (DYN)     gTurbo     */
+          { 0x00000015, 0x00000015, 0x00000015, 0x00000015, 0x00000015 } },
+       { AR5K_USEC_5211,
+          { 0x128d93a7, 0x098813cf, 0x04e01395, 0x12e013ab, 0x098813cf } },
+       { AR5K_PHY_RF_CTL3,
+          { 0x0a020001, 0x0a020001, 0x05020100, 0x0a020001, 0x0a020001 } },
+       { AR5K_PHY_RF_CTL4,
+          { 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e } },
+       { AR5K_PHY_PA_CTL,
+          { 0x00000007, 0x00000007, 0x0000000b, 0x0000000b, 0x0000000b } },
+       { AR5K_PHY_GAIN,
+          { 0x0018fa61, 0x0018fa61, 0x001a1a63, 0x001a1a63, 0x001a1a63 } },
+       { AR5K_PHY_DESIRED_SIZE,
+          { 0x0c98b4e0, 0x0c98b4e0, 0x0c98b0da, 0x0c98b0da, 0x0c98b0da } },
+       { AR5K_PHY_SIG,
+          { 0x7ec80d2e, 0x7ec80d2e, 0x7ec80d2e, 0x7ec80d2e, 0x7ec80d2e } },
+       { AR5K_PHY_AGCCOARSE,
+          { 0x3139605e, 0x3139605e, 0x3139605e, 0x3139605e, 0x3139605e } },
+       { AR5K_PHY_WEAK_OFDM_LOW_THR,
+          { 0x050cb081, 0x050cb081, 0x050cb081, 0x050cb081, 0x050cb081 } },
+       { AR5K_PHY_RX_DELAY,
+          { 0x000007d0, 0x000007d0, 0x0000044c, 0x00000898, 0x000007d0 } },
+       { AR5K_PHY_FRAME_CTL_5211,
+          { 0xf7b81000, 0xf7b81000, 0xf7b80d00, 0xf7b81000, 0xf7b81000 } },
+       { AR5K_PHY_CCKTXCTL,
+          { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { AR5K_PHY_CCK_CROSSCORR,
+          { 0xd6be6788, 0xd6be6788, 0xd03e6788, 0xd03e6788, 0xd03e6788 } },
+       { AR5K_PHY_GAIN_2GHZ,
+          { 0x002ec1e0, 0x002ec1e0, 0x002ac120, 0x002ac120, 0x002ac120 } },
+       { AR5K_PHY_CCK_RX_CTL_4,
+          { 0x1883800a, 0x1883800a, 0x1863800a, 0x1883800a, 0x1883800a } },
+       { 0xa300,
+          { 0x18010000, 0x18010000, 0x18010000, 0x18010000, 0x18010000 } },
+       { 0xa304,
+          { 0x30032602, 0x30032602, 0x30032602, 0x30032602, 0x30032602 } },
+       { 0xa308,
+          { 0x48073e06, 0x48073e06, 0x48073e06, 0x48073e06, 0x48073e06 } },
+       { 0xa30c,
+          { 0x560b4c0a, 0x560b4c0a, 0x560b4c0a, 0x560b4c0a, 0x560b4c0a } },
+       { 0xa310,
+          { 0x641a600f, 0x641a600f, 0x641a600f, 0x641a600f, 0x641a600f } },
+       { 0xa314,
+          { 0x784f6e1b, 0x784f6e1b, 0x784f6e1b, 0x784f6e1b, 0x784f6e1b } },
+       { 0xa318,
+          { 0x868f7c5a, 0x868f7c5a, 0x868f7c5a, 0x868f7c5a, 0x868f7c5a } },
+       { 0xa31c,
+          { 0x90cf865b, 0x90cf865b, 0x8ecf865b, 0x8ecf865b, 0x8ecf865b } },
+       { 0xa320,
+          { 0x9d4f970f, 0x9d4f970f, 0x9b4f970f, 0x9b4f970f, 0x9b4f970f } },
+       { 0xa324,
+          { 0xa7cfa38f, 0xa7cfa38f, 0xa3cf9f8f, 0xa3cf9f8f, 0xa3cf9f8f } },
+       { 0xa328,
+          { 0xb55faf1f, 0xb55faf1f, 0xb35faf1f, 0xb35faf1f, 0xb35faf1f } },
+       { 0xa32c,
+          { 0xbddfb99f, 0xbddfb99f, 0xbbdfb99f, 0xbbdfb99f, 0xbbdfb99f } },
+       { 0xa330,
+          { 0xcb7fc53f, 0xcb7fc53f, 0xcb7fc73f, 0xcb7fc73f, 0xcb7fc73f } },
+       { 0xa334,
+          { 0xd5ffd1bf, 0xd5ffd1bf, 0xd3ffd1bf, 0xd3ffd1bf, 0xd3ffd1bf } },
+};
+
+static const struct ath5k_ini rf5413_ini_common_end[] = {
+       { AR5K_DCU_FP,          0x000003e0, AR5K_INI_WRITE },
+       { AR5K_5414_CBCFG,      0x00000010, AR5K_INI_WRITE },
+       { AR5K_SEQ_MASK,        0x0000000f, AR5K_INI_WRITE },
+       { 0x809c,               0x00000000, AR5K_INI_WRITE },
+       { 0x80a0,               0x00000000, AR5K_INI_WRITE },
+       { AR5K_MIC_QOS_CTL,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_MIC_QOS_SEL,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_MISC_MODE,       0x00000000, AR5K_INI_WRITE },
+       { AR5K_OFDM_FIL_CNT,    0x00000000, AR5K_INI_WRITE },
+       { AR5K_CCK_FIL_CNT,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHYERR_CNT1,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHYERR_CNT1_MASK, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHYERR_CNT2,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHYERR_CNT2_MASK, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_TSF_THRES,       0x00000000, AR5K_INI_WRITE },
+       { 0x8140,               0x800003f9, AR5K_INI_WRITE },
+       { 0x8144,               0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_AGC,         0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_ADC_CTL,     0x0000a000, AR5K_INI_WRITE },
+       { 0x983c,               0x00200400, AR5K_INI_WRITE },
+       { AR5K_PHY_GAIN_OFFSET, 0x1284233c, AR5K_INI_WRITE },
+       { AR5K_PHY_SCR,         0x0000001f, AR5K_INI_WRITE },
+       { AR5K_PHY_SLMT,        0x00000080, AR5K_INI_WRITE },
+       { AR5K_PHY_SCAL,        0x0000000e, AR5K_INI_WRITE },
+       { 0x9958,               0x00081fff, AR5K_INI_WRITE },
+       { AR5K_PHY_TIMING_7,    0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_TIMING_8,    0x02800000, AR5K_INI_WRITE },
+       { AR5K_PHY_TIMING_11,   0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_HEAVY_CLIP_ENABLE, 0x00000000, AR5K_INI_WRITE },
+       { 0x99e4,               0xaaaaaaaa, AR5K_INI_WRITE },
+       { 0x99e8,               0x3c466478, AR5K_INI_WRITE },
+       { 0x99ec,               0x000000aa, AR5K_INI_WRITE },
+       { AR5K_PHY_SCLOCK,      0x0000000c, AR5K_INI_WRITE },
+       { AR5K_PHY_SDELAY,      0x000000ff, AR5K_INI_WRITE },
+       { AR5K_PHY_SPENDING,    0x00000014, AR5K_INI_WRITE },
+       { AR5K_PHY_DAG_CCK_CTL, 0x000009b5, AR5K_INI_WRITE },
+       { 0xa23c,               0x93c889af, AR5K_INI_WRITE },
+       { AR5K_PHY_FAST_ADC,    0x00000001, AR5K_INI_WRITE },
+       { 0xa250,               0x0000a000, AR5K_INI_WRITE },
+       { AR5K_PHY_BLUETOOTH,   0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_TPC_RG1,     0x0cc75380, AR5K_INI_WRITE },
+       { 0xa25c,               0x0f0f0f01, AR5K_INI_WRITE },
+       { 0xa260,               0x5f690f01, AR5K_INI_WRITE },
+       { 0xa264,               0x00418a11, AR5K_INI_WRITE },
+       { 0xa268,               0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_TPC_RG5,     0x0c30c16a, AR5K_INI_WRITE },
+       { 0xa270, 0x00820820, AR5K_INI_WRITE },
+       { 0xa274, 0x081b7caa, AR5K_INI_WRITE },
+       { 0xa278, 0x1ce739ce, AR5K_INI_WRITE },
+       { 0xa27c, 0x051701ce, AR5K_INI_WRITE },
+       { 0xa338, 0x00000000, AR5K_INI_WRITE },
+       { 0xa33c, 0x00000000, AR5K_INI_WRITE },
+       { 0xa340, 0x00000000, AR5K_INI_WRITE },
+       { 0xa344, 0x00000000, AR5K_INI_WRITE },
+       { 0xa348, 0x3fffffff, AR5K_INI_WRITE },
+       { 0xa34c, 0x3fffffff, AR5K_INI_WRITE },
+       { 0xa350, 0x3fffffff, AR5K_INI_WRITE },
+       { 0xa354, 0x0003ffff, AR5K_INI_WRITE },
+       { 0xa358, 0x79a8aa1f, AR5K_INI_WRITE },
+       { 0xa35c, 0x066c420f, AR5K_INI_WRITE },
+       { 0xa360, 0x0f282207, AR5K_INI_WRITE },
+       { 0xa364, 0x17601685, AR5K_INI_WRITE },
+       { 0xa368, 0x1f801104, AR5K_INI_WRITE },
+       { 0xa36c, 0x37a00c03, AR5K_INI_WRITE },
+       { 0xa370, 0x3fc40883, AR5K_INI_WRITE },
+       { 0xa374, 0x57c00803, AR5K_INI_WRITE },
+       { 0xa378, 0x5fd80682, AR5K_INI_WRITE },
+       { 0xa37c, 0x7fe00482, AR5K_INI_WRITE },
+       { 0xa380, 0x7f3c7bba, AR5K_INI_WRITE },
+       { 0xa384, 0xf3307ff0, AR5K_INI_WRITE },
+};
+
+/* Initial mode-specific settings for RF2413/2414 (Written after ar5212_ini) */
+/* XXX: a mode ? */
+static const struct ath5k_ini_mode rf2413_ini_mode_end[] = {
+       { AR5K_TXCFG,
+       /*      a/XR       aTurbo         b        g (DYN)     gTurbo     */
+          { 0x00000015, 0x00000015, 0x00000015, 0x00000015, 0x00000015 } },
+       { AR5K_USEC_5211,
+          { 0x128d93a7, 0x098813cf, 0x04e01395, 0x12e013ab, 0x098813cf } },
+       { AR5K_PHY_RF_CTL3,
+          { 0x0a020001, 0x0a020001, 0x05020000, 0x0a020001, 0x0a020001 } },
+       { AR5K_PHY_RF_CTL4,
+          { 0x00000e00, 0x00000e00, 0x00000e00, 0x00000e00, 0x00000e00 } },
+       { AR5K_PHY_PA_CTL,
+          { 0x00000002, 0x00000002, 0x0000000a, 0x0000000a, 0x0000000a } },
+       { AR5K_PHY_GAIN,
+          { 0x0018da6d, 0x0018da6d, 0x001a6a64, 0x001a6a64, 0x001a6a64 } },
+       { AR5K_PHY_DESIRED_SIZE,
+          { 0x0de8b4e0, 0x0de8b4e0, 0x0de8b0da, 0x0c98b0da, 0x0de8b0da } },
+       { AR5K_PHY_SIG,
+          { 0x7e800d2e, 0x7e800d2e, 0x7ee80d2e, 0x7ec80d2e, 0x7e800d2e } },
+       { AR5K_PHY_AGCCOARSE,
+          { 0x3137665e, 0x3137665e, 0x3137665e, 0x3139605e, 0x3137665e } },
+       { AR5K_PHY_WEAK_OFDM_LOW_THR,
+          { 0x050cb081, 0x050cb081, 0x050cb081, 0x050cb081, 0x050cb081 } },
+       { AR5K_PHY_RX_DELAY,
+          { 0x000007d0, 0x000007d0, 0x0000044c, 0x00000898, 0x000007d0 } },
+       { AR5K_PHY_FRAME_CTL_5211,
+          { 0xf7b81000, 0xf7b81000, 0xf7b80d00, 0xf7b81000, 0xf7b81000 } },
+       { AR5K_PHY_CCKTXCTL,
+          { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { AR5K_PHY_CCK_CROSSCORR,
+          { 0xd6be6788, 0xd6be6788, 0xd03e6788, 0xd03e6788, 0xd03e6788 } },
+       { AR5K_PHY_GAIN_2GHZ,
+          { 0x002c0140, 0x002c0140, 0x0042c140, 0x0042c140, 0x0042c140 } },
+       { AR5K_PHY_CCK_RX_CTL_4,
+          { 0x1883800a, 0x1883800a, 0x1863800a, 0x1883800a, 0x1883800a } },
+};
+
+static const struct ath5k_ini rf2413_ini_common_end[] = {
+       { AR5K_DCU_FP,          0x000003e0, AR5K_INI_WRITE },
+       { AR5K_SEQ_MASK,        0x0000000f, AR5K_INI_WRITE },
+       { AR5K_MIC_QOS_CTL,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_MIC_QOS_SEL,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_MISC_MODE,       0x00000000, AR5K_INI_WRITE },
+       { AR5K_OFDM_FIL_CNT,    0x00000000, AR5K_INI_WRITE },
+       { AR5K_CCK_FIL_CNT,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHYERR_CNT1,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHYERR_CNT1_MASK, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHYERR_CNT2,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHYERR_CNT2_MASK, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_TSF_THRES,       0x00000000, AR5K_INI_WRITE },
+       { 0x8140,               0x800000a8, AR5K_INI_WRITE },
+       { 0x8144,               0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_AGC,         0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_ADC_CTL,     0x0000a000, AR5K_INI_WRITE },
+       { 0x983c,               0x00200400, AR5K_INI_WRITE },
+       { AR5K_PHY_GAIN_OFFSET, 0x1284233c, AR5K_INI_WRITE },
+       { AR5K_PHY_SCR,         0x0000001f, AR5K_INI_WRITE },
+       { AR5K_PHY_SLMT,        0x00000080, AR5K_INI_WRITE },
+       { AR5K_PHY_SCAL,        0x0000000e, AR5K_INI_WRITE },
+       { 0x9958,               0x000000ff, AR5K_INI_WRITE },
+       { AR5K_PHY_TIMING_7,    0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_TIMING_8,    0x02800000, AR5K_INI_WRITE },
+       { AR5K_PHY_TIMING_11,   0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_HEAVY_CLIP_ENABLE, 0x00000000, AR5K_INI_WRITE },
+       { 0x99e4,               0xaaaaaaaa, AR5K_INI_WRITE },
+       { 0x99e8,               0x3c466478, AR5K_INI_WRITE },
+       { 0x99ec,               0x000000aa, AR5K_INI_WRITE },
+       { AR5K_PHY_SCLOCK,      0x0000000c, AR5K_INI_WRITE },
+       { AR5K_PHY_SDELAY,      0x000000ff, AR5K_INI_WRITE },
+       { AR5K_PHY_SPENDING,    0x00000014, AR5K_INI_WRITE },
+       { AR5K_PHY_DAG_CCK_CTL, 0x000009b5, AR5K_INI_WRITE },
+       { 0xa23c,               0x93c889af, AR5K_INI_WRITE },
+       { AR5K_PHY_FAST_ADC,    0x00000001, AR5K_INI_WRITE },
+       { 0xa250,               0x0000a000, AR5K_INI_WRITE },
+       { AR5K_PHY_BLUETOOTH,   0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_TPC_RG1,     0x0cc75380, AR5K_INI_WRITE },
+       { 0xa25c,               0x0f0f0f01, AR5K_INI_WRITE },
+       { 0xa260,               0x5f690f01, AR5K_INI_WRITE },
+       { 0xa264,               0x00418a11, AR5K_INI_WRITE },
+       { 0xa268,               0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_TPC_RG5,     0x0c30c16a, AR5K_INI_WRITE },
+       { 0xa270, 0x00820820, AR5K_INI_WRITE },
+       { 0xa274, 0x001b7caa, AR5K_INI_WRITE },
+       { 0xa278, 0x1ce739ce, AR5K_INI_WRITE },
+       { 0xa27c, 0x051701ce, AR5K_INI_WRITE },
+       { 0xa300, 0x18010000, AR5K_INI_WRITE },
+       { 0xa304, 0x30032602, AR5K_INI_WRITE },
+       { 0xa308, 0x48073e06, AR5K_INI_WRITE },
+       { 0xa30c, 0x560b4c0a, AR5K_INI_WRITE },
+       { 0xa310, 0x641a600f, AR5K_INI_WRITE },
+       { 0xa314, 0x784f6e1b, AR5K_INI_WRITE },
+       { 0xa318, 0x868f7c5a, AR5K_INI_WRITE },
+       { 0xa31c, 0x8ecf865b, AR5K_INI_WRITE },
+       { 0xa320, 0x9d4f970f, AR5K_INI_WRITE },
+       { 0xa324, 0xa5cfa18f, AR5K_INI_WRITE },
+       { 0xa328, 0xb55faf1f, AR5K_INI_WRITE },
+       { 0xa32c, 0xbddfb99f, AR5K_INI_WRITE },
+       { 0xa330, 0xcd7fc73f, AR5K_INI_WRITE },
+       { 0xa334, 0xd5ffd1bf, AR5K_INI_WRITE },
+       { 0xa338, 0x00000000, AR5K_INI_WRITE },
+       { 0xa33c, 0x00000000, AR5K_INI_WRITE },
+       { 0xa340, 0x00000000, AR5K_INI_WRITE },
+       { 0xa344, 0x00000000, AR5K_INI_WRITE },
+       { 0xa348, 0x3fffffff, AR5K_INI_WRITE },
+       { 0xa34c, 0x3fffffff, AR5K_INI_WRITE },
+       { 0xa350, 0x3fffffff, AR5K_INI_WRITE },
+       { 0xa354, 0x0003ffff, AR5K_INI_WRITE },
+       { 0xa358, 0x79a8aa1f, AR5K_INI_WRITE },
+       { 0xa35c, 0x066c420f, AR5K_INI_WRITE },
+       { 0xa360, 0x0f282207, AR5K_INI_WRITE },
+       { 0xa364, 0x17601685, AR5K_INI_WRITE },
+       { 0xa368, 0x1f801104, AR5K_INI_WRITE },
+       { 0xa36c, 0x37a00c03, AR5K_INI_WRITE },
+       { 0xa370, 0x3fc40883, AR5K_INI_WRITE },
+       { 0xa374, 0x57c00803, AR5K_INI_WRITE },
+       { 0xa378, 0x5fd80682, AR5K_INI_WRITE },
+       { 0xa37c, 0x7fe00482, AR5K_INI_WRITE },
+       { 0xa380, 0x7f3c7bba, AR5K_INI_WRITE },
+       { 0xa384, 0xf3307ff0, AR5K_INI_WRITE },
+};
+
+/* Initial mode-specific settings for RF2425 (Written after ar5212_ini) */
+/* XXX: a mode ? */
+static const struct ath5k_ini_mode rf2425_ini_mode_end[] = {
+       { AR5K_TXCFG,
+       /*      a/XR       aTurbo         b        g (DYN)     gTurbo     */
+          { 0x00000015, 0x00000015, 0x00000015, 0x00000015, 0x00000015 } },
+       { AR5K_USEC_5211,
+          { 0x128d93a7, 0x098813cf, 0x04e01395, 0x12e013ab, 0x098813cf } },
+       { AR5K_PHY_TURBO,
+          { 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000001 } },
+       { AR5K_PHY_RF_CTL3,
+          { 0x0a020001, 0x0a020001, 0x05020100, 0x0a020001, 0x0a020001 } },
+       { AR5K_PHY_RF_CTL4,
+          { 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e } },
+       { AR5K_PHY_PA_CTL,
+          { 0x00000003, 0x00000003, 0x0000000b, 0x0000000b, 0x0000000b } },
+       { AR5K_PHY_SETTLING,
+          { 0x1372161c, 0x13721c25, 0x13721722, 0x13721422, 0x13721c25 } },
+       { AR5K_PHY_GAIN,
+          { 0x0018fa61, 0x0018fa61, 0x00199a65, 0x00199a65, 0x00199a65 } },
+       { AR5K_PHY_DESIRED_SIZE,
+          { 0x0c98b4e0, 0x0c98b4e0, 0x0c98b0da, 0x0c98b0da, 0x0c98b0da } },
+       { AR5K_PHY_SIG,
+          { 0x7ec80d2e, 0x7ec80d2e, 0x7ec80d2e, 0x7ec80d2e, 0x7ec80d2e } },
+       { AR5K_PHY_AGCCOARSE,
+          { 0x3139605e, 0x3139605e, 0x3139605e, 0x3139605e, 0x3139605e } },
+       { AR5K_PHY_WEAK_OFDM_LOW_THR,
+          { 0x050cb081, 0x050cb081, 0x050cb081, 0x050cb081, 0x050cb081 } },
+       { AR5K_PHY_RX_DELAY,
+          { 0x000007d0, 0x000007d0, 0x0000044c, 0x00000898, 0x000007d0 } },
+       { AR5K_PHY_FRAME_CTL_5211,
+          { 0xf7b81000, 0xf7b81000, 0xf7b80d00, 0xf7b81000, 0xf7b81000 } },
+       { AR5K_PHY_CCKTXCTL,
+          { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { AR5K_PHY_CCK_CROSSCORR,
+          { 0xd6be6788, 0xd6be6788, 0xd03e6788, 0xd03e6788, 0xd03e6788 } },
+       { AR5K_PHY_GAIN_2GHZ,
+          { 0x00000140, 0x00000140, 0x0052c140, 0x0052c140, 0x0052c140 } },
+       { AR5K_PHY_CCK_RX_CTL_4,
+          { 0x1883800a, 0x1883800a, 0x1863800a, 0x1883800a, 0x1883800a } },
+       { 0xa324,
+          { 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf } },
+       { 0xa328,
+          { 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf } },
+       { 0xa32c,
+          { 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf } },
+       { 0xa330,
+          { 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf } },
+       { 0xa334,
+          { 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf, 0xa7cfa7cf } },
+};
+
+static const struct ath5k_ini rf2425_ini_common_end[] = {
+       { AR5K_DCU_FP,          0x000003e0, AR5K_INI_WRITE },
+       { AR5K_SEQ_MASK,        0x0000000f, AR5K_INI_WRITE },
+       { 0x809c,               0x00000000, AR5K_INI_WRITE },
+       { 0x80a0,               0x00000000, AR5K_INI_WRITE },
+       { AR5K_MIC_QOS_CTL,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_MIC_QOS_SEL,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_MISC_MODE,       0x00000000, AR5K_INI_WRITE },
+       { AR5K_OFDM_FIL_CNT,    0x00000000, AR5K_INI_WRITE },
+       { AR5K_CCK_FIL_CNT,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHYERR_CNT1,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHYERR_CNT1_MASK, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHYERR_CNT2,     0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHYERR_CNT2_MASK, 0x00000000, AR5K_INI_WRITE },
+       { AR5K_TSF_THRES,       0x00000000, AR5K_INI_WRITE },
+       { 0x8140,               0x800003f9, AR5K_INI_WRITE },
+       { 0x8144,               0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_AGC,         0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_ADC_CTL,     0x0000a000, AR5K_INI_WRITE },
+       { 0x983c,               0x00200400, AR5K_INI_WRITE },
+       { AR5K_PHY_GAIN_OFFSET, 0x1284233c, AR5K_INI_WRITE },
+       { AR5K_PHY_SCR,         0x0000001f, AR5K_INI_WRITE },
+       { AR5K_PHY_SLMT,        0x00000080, AR5K_INI_WRITE },
+       { AR5K_PHY_SCAL,        0x0000000e, AR5K_INI_WRITE },
+       { 0x9958,               0x00081fff, AR5K_INI_WRITE },
+       { AR5K_PHY_TIMING_7,    0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_TIMING_8,    0x02800000, AR5K_INI_WRITE },
+       { AR5K_PHY_TIMING_11,   0x00000000, AR5K_INI_WRITE },
+       { 0x99dc,               0xfebadbe8, AR5K_INI_WRITE },
+       { AR5K_PHY_HEAVY_CLIP_ENABLE, 0x00000000, AR5K_INI_WRITE },
+       { 0x99e4,               0xaaaaaaaa, AR5K_INI_WRITE },
+       { 0x99e8,               0x3c466478, AR5K_INI_WRITE },
+       { 0x99ec,               0x000000aa, AR5K_INI_WRITE },
+       { AR5K_PHY_SCLOCK,      0x0000000c, AR5K_INI_WRITE },
+       { AR5K_PHY_SDELAY,      0x000000ff, AR5K_INI_WRITE },
+       { AR5K_PHY_SPENDING,    0x00000014, AR5K_INI_WRITE },
+       { AR5K_PHY_DAG_CCK_CTL, 0x000009b5, AR5K_INI_WRITE },
+       { AR5K_PHY_TXPOWER_RATE3, 0x20202020, AR5K_INI_WRITE },
+       { AR5K_PHY_TXPOWER_RATE4, 0x20202020, AR5K_INI_WRITE },
+       { 0xa23c,               0x93c889af, AR5K_INI_WRITE },
+       { AR5K_PHY_FAST_ADC,    0x00000001, AR5K_INI_WRITE },
+       { 0xa250,               0x0000a000, AR5K_INI_WRITE },
+       { AR5K_PHY_BLUETOOTH,   0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_TPC_RG1,     0x0cc75380, AR5K_INI_WRITE },
+       { 0xa25c,               0x0f0f0f01, AR5K_INI_WRITE },
+       { 0xa260,               0x5f690f01, AR5K_INI_WRITE },
+       { 0xa264,               0x00418a11, AR5K_INI_WRITE },
+       { 0xa268,               0x00000000, AR5K_INI_WRITE },
+       { AR5K_PHY_TPC_RG5,     0x0c30c166, AR5K_INI_WRITE },
+       { 0xa270, 0x00820820, AR5K_INI_WRITE },
+       { 0xa274, 0x081a3caa, AR5K_INI_WRITE },
+       { 0xa278, 0x1ce739ce, AR5K_INI_WRITE },
+       { 0xa27c, 0x051701ce, AR5K_INI_WRITE },
+       { 0xa300, 0x16010000, AR5K_INI_WRITE },
+       { 0xa304, 0x2c032402, AR5K_INI_WRITE },
+       { 0xa308, 0x48433e42, AR5K_INI_WRITE },
+       { 0xa30c, 0x5a0f500b, AR5K_INI_WRITE },
+       { 0xa310, 0x6c4b624a, AR5K_INI_WRITE },
+       { 0xa314, 0x7e8b748a, AR5K_INI_WRITE },
+       { 0xa318, 0x96cf8ccb, AR5K_INI_WRITE },
+       { 0xa31c, 0xa34f9d0f, AR5K_INI_WRITE },
+       { 0xa320, 0xa7cfa58f, AR5K_INI_WRITE },
+       { 0xa348, 0x3fffffff, AR5K_INI_WRITE },
+       { 0xa34c, 0x3fffffff, AR5K_INI_WRITE },
+       { 0xa350, 0x3fffffff, AR5K_INI_WRITE },
+       { 0xa354, 0x0003ffff, AR5K_INI_WRITE },
+       { 0xa358, 0x79a8aa1f, AR5K_INI_WRITE },
+       { 0xa35c, 0x066c420f, AR5K_INI_WRITE },
+       { 0xa360, 0x0f282207, AR5K_INI_WRITE },
+       { 0xa364, 0x17601685, AR5K_INI_WRITE },
+       { 0xa368, 0x1f801104, AR5K_INI_WRITE },
+       { 0xa36c, 0x37a00c03, AR5K_INI_WRITE },
+       { 0xa370, 0x3fc40883, AR5K_INI_WRITE },
+       { 0xa374, 0x57c00803, AR5K_INI_WRITE },
+       { 0xa378, 0x5fd80682, AR5K_INI_WRITE },
+       { 0xa37c, 0x7fe00482, AR5K_INI_WRITE },
+       { 0xa380, 0x7f3c7bba, AR5K_INI_WRITE },
+       { 0xa384, 0xf3307ff0, AR5K_INI_WRITE },
+};
+
+/*
+ * Initial BaseBand Gain settings for RF5111/5112 (AR5210 comes with
+ * RF5110 only so initial BB Gain settings are included in AR5K_AR5210_INI)
+ */
+
+/* RF5111 Initial BaseBand Gain settings */
+static const struct ath5k_ini rf5111_ini_bbgain[] = {
+       { AR5K_BB_GAIN(0), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(1), 0x00000020, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(2), 0x00000010, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(3), 0x00000030, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(4), 0x00000008, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(5), 0x00000028, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(6), 0x00000004, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(7), 0x00000024, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(8), 0x00000014, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(9), 0x00000034, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(10), 0x0000000c, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(11), 0x0000002c, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(12), 0x00000002, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(13), 0x00000022, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(14), 0x00000012, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(15), 0x00000032, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(16), 0x0000000a, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(17), 0x0000002a, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(18), 0x00000006, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(19), 0x00000026, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(20), 0x00000016, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(21), 0x00000036, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(22), 0x0000000e, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(23), 0x0000002e, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(24), 0x00000001, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(25), 0x00000021, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(26), 0x00000011, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(27), 0x00000031, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(28), 0x00000009, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(29), 0x00000029, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(30), 0x00000005, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(31), 0x00000025, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(32), 0x00000015, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(33), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(34), 0x0000000d, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(35), 0x0000002d, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(36), 0x00000003, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(37), 0x00000023, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(38), 0x00000013, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(39), 0x00000033, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(40), 0x0000000b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(41), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(42), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(43), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(44), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(45), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(46), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(47), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(48), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(49), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(50), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(51), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(52), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(53), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(54), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(55), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(56), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(57), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(58), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(59), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(60), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(61), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(62), 0x00000002, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(63), 0x00000016, AR5K_INI_WRITE },
+};
+
+/* RF5112 Initial BaseBand Gain settings (Same for RF5413/5414+) */
+static const struct ath5k_ini rf5112_ini_bbgain[] = {
+       { AR5K_BB_GAIN(0), 0x00000000, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(1), 0x00000001, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(2), 0x00000002, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(3), 0x00000003, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(4), 0x00000004, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(5), 0x00000005, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(6), 0x00000008, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(7), 0x00000009, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(8), 0x0000000a, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(9), 0x0000000b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(10), 0x0000000c, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(11), 0x0000000d, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(12), 0x00000010, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(13), 0x00000011, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(14), 0x00000012, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(15), 0x00000013, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(16), 0x00000014, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(17), 0x00000015, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(18), 0x00000018, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(19), 0x00000019, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(20), 0x0000001a, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(21), 0x0000001b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(22), 0x0000001c, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(23), 0x0000001d, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(24), 0x00000020, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(25), 0x00000021, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(26), 0x00000022, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(27), 0x00000023, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(28), 0x00000024, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(29), 0x00000025, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(30), 0x00000028, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(31), 0x00000029, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(32), 0x0000002a, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(33), 0x0000002b, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(34), 0x0000002c, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(35), 0x0000002d, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(36), 0x00000030, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(37), 0x00000031, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(38), 0x00000032, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(39), 0x00000033, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(40), 0x00000034, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(41), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(42), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(43), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(44), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(45), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(46), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(47), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(48), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(49), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(50), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(51), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(52), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(53), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(54), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(55), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(56), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(57), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(58), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(59), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(60), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(61), 0x00000035, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(62), 0x00000010, AR5K_INI_WRITE },
+       { AR5K_BB_GAIN(63), 0x0000001a, AR5K_INI_WRITE },
+};
+
+
+/*
+ * Write initial register dump
+ */
+static void ath5k_hw_ini_registers(struct ath5k_hw *ah, unsigned int size,
+               const struct ath5k_ini *ini_regs, int change_channel)
+{
+       unsigned int i;
+
+       /* Write initial registers */
+       for (i = 0; i < size; i++) {
+               /* On channel change there is
+                * no need to mess with PCU */
+               if (change_channel &&
+                               ini_regs[i].ini_register >= AR5K_PCU_MIN &&
+                               ini_regs[i].ini_register <= AR5K_PCU_MAX)
+                       continue;
+
+               switch (ini_regs[i].ini_mode) {
+               case AR5K_INI_READ:
+                       /* Cleared on read */
+                       ath5k_hw_reg_read(ah, ini_regs[i].ini_register);
+                       break;
+               case AR5K_INI_WRITE:
+               default:
+                       AR5K_REG_WAIT(i);
+                       ath5k_hw_reg_write(ah, ini_regs[i].ini_value,
+                                       ini_regs[i].ini_register);
+               }
+       }
+}
+
+static void ath5k_hw_ini_mode_registers(struct ath5k_hw *ah,
+               unsigned int size, const struct ath5k_ini_mode *ini_mode,
+               u8 mode)
+{
+       unsigned int i;
+
+       for (i = 0; i < size; i++) {
+               AR5K_REG_WAIT(i);
+               ath5k_hw_reg_write(ah, ini_mode[i].mode_value[mode],
+                       (u32)ini_mode[i].mode_register);
+       }
+}
+
+int ath5k_hw_write_initvals(struct ath5k_hw *ah, u8 mode, int change_channel)
+{
+       /*
+        * Write initial register settings
+        */
+
+       /* For AR5212 and combatible */
+       if (ah->ah_version == AR5K_AR5212) {
+
+               /* First set of mode-specific settings */
+               ath5k_hw_ini_mode_registers(ah,
+                       ARRAY_SIZE(ar5212_ini_mode_start),
+                       ar5212_ini_mode_start, mode);
+
+               /*
+                * Write initial settings common for all modes
+                */
+               ath5k_hw_ini_registers(ah, ARRAY_SIZE(ar5212_ini_common_start),
+                               ar5212_ini_common_start, change_channel);
+
+               /* Second set of mode-specific settings */
+               switch (ah->ah_radio) {
+               case AR5K_RF5111:
+
+                       ath5k_hw_ini_mode_registers(ah,
+                                       ARRAY_SIZE(rf5111_ini_mode_end),
+                                       rf5111_ini_mode_end, mode);
+
+                       ath5k_hw_ini_registers(ah,
+                                       ARRAY_SIZE(rf5111_ini_common_end),
+                                       rf5111_ini_common_end, change_channel);
+
+                       /* Baseband gain table */
+                       ath5k_hw_ini_registers(ah,
+                                       ARRAY_SIZE(rf5111_ini_bbgain),
+                                       rf5111_ini_bbgain, change_channel);
+
+                       break;
+               case AR5K_RF5112:
+
+                       ath5k_hw_ini_mode_registers(ah,
+                                       ARRAY_SIZE(rf5112_ini_mode_end),
+                                       rf5112_ini_mode_end, mode);
+
+                       ath5k_hw_ini_registers(ah,
+                                       ARRAY_SIZE(rf5112_ini_common_end),
+                                       rf5112_ini_common_end, change_channel);
+
+                       ath5k_hw_ini_registers(ah,
+                                       ARRAY_SIZE(rf5112_ini_bbgain),
+                                       rf5112_ini_bbgain, change_channel);
+
+                       break;
+               case AR5K_RF5413:
+
+                       ath5k_hw_ini_mode_registers(ah,
+                                       ARRAY_SIZE(rf5413_ini_mode_end),
+                                       rf5413_ini_mode_end, mode);
+
+                       ath5k_hw_ini_registers(ah,
+                                       ARRAY_SIZE(rf5413_ini_common_end),
+                                       rf5413_ini_common_end, change_channel);
+
+                       ath5k_hw_ini_registers(ah,
+                                       ARRAY_SIZE(rf5112_ini_bbgain),
+                                       rf5112_ini_bbgain, change_channel);
+
+                       break;
+               case AR5K_RF2316:
+               case AR5K_RF2413:
+
+                       ath5k_hw_ini_mode_registers(ah,
+                                       ARRAY_SIZE(rf2413_ini_mode_end),
+                                       rf2413_ini_mode_end, mode);
+
+                       ath5k_hw_ini_registers(ah,
+                                       ARRAY_SIZE(rf2413_ini_common_end),
+                                       rf2413_ini_common_end, change_channel);
+
+                       /* Override settings from rf2413_ini_common_end */
+                       if (ah->ah_radio == AR5K_RF2316) {
+                               ath5k_hw_reg_write(ah, 0x00004000,
+                                                       AR5K_PHY_AGC);
+                               ath5k_hw_reg_write(ah, 0x081b7caa,
+                                                       0xa274);
+                       }
+
+                       ath5k_hw_ini_registers(ah,
+                                       ARRAY_SIZE(rf5112_ini_bbgain),
+                                       rf5112_ini_bbgain, change_channel);
+                       break;
+               case AR5K_RF2317:
+               case AR5K_RF2425:
+
+                       ath5k_hw_ini_mode_registers(ah,
+                                       ARRAY_SIZE(rf2425_ini_mode_end),
+                                       rf2425_ini_mode_end, mode);
+
+                       ath5k_hw_ini_registers(ah,
+                                       ARRAY_SIZE(rf2425_ini_common_end),
+                                       rf2425_ini_common_end, change_channel);
+
+                       ath5k_hw_ini_registers(ah,
+                                       ARRAY_SIZE(rf5112_ini_bbgain),
+                                       rf5112_ini_bbgain, change_channel);
+                       break;
+               default:
+                       return -EINVAL;
+
+               }
+
+       /* For AR5211 */
+       } else if (ah->ah_version == AR5K_AR5211) {
+
+               /* AR5K_MODE_11B */
+               if (mode > 2) {
+                       DBG("ath5k: unsupported channel mode %d\n", mode);
+                       return -EINVAL;
+               }
+
+               /* Mode-specific settings */
+               ath5k_hw_ini_mode_registers(ah, ARRAY_SIZE(ar5211_ini_mode),
+                               ar5211_ini_mode, mode);
+
+               /*
+                * Write initial settings common for all modes
+                */
+               ath5k_hw_ini_registers(ah, ARRAY_SIZE(ar5211_ini),
+                               ar5211_ini, change_channel);
+
+               /* AR5211 only comes with 5111 */
+
+               /* Baseband gain table */
+               ath5k_hw_ini_registers(ah, ARRAY_SIZE(rf5111_ini_bbgain),
+                               rf5111_ini_bbgain, change_channel);
+       /* For AR5210 (for mode settings check out ath5k_hw_reset_tx_queue) */
+       } else if (ah->ah_version == AR5K_AR5210) {
+               ath5k_hw_ini_registers(ah, ARRAY_SIZE(ar5210_ini),
+                               ar5210_ini, change_channel);
+       }
+
+       return 0;
+}
diff --git a/src/drivers/net/ath5k/ath5k_pcu.c b/src/drivers/net/ath5k/ath5k_pcu.c
new file mode 100644 (file)
index 0000000..1e90a94
--- /dev/null
@@ -0,0 +1,534 @@
+/*
+ * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
+ * Copyright (c) 2007-2008 Matthew W. S. Bell  <mentor@madwifi.org>
+ * Copyright (c) 2007-2008 Luis Rodriguez <mcgrof@winlab.rutgers.edu>
+ * Copyright (c) 2007-2008 Pavel Roskin <proski@gnu.org>
+ * Copyright (c) 2007-2008 Jiri Slaby <jirislaby@gmail.com>
+ *
+ * Lightly modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+FILE_LICENCE ( MIT );
+
+/*********************************\
+* Protocol Control Unit Functions *
+\*********************************/
+
+#include "ath5k.h"
+#include "reg.h"
+#include "base.h"
+
+/*******************\
+* Generic functions *
+\*******************/
+
+/**
+ * ath5k_hw_set_opmode - Set PCU operating mode
+ *
+ * @ah: The &struct ath5k_hw
+ *
+ * Initialize PCU for the various operating modes (AP/STA etc)
+ *
+ * For gPXE we always assume STA mode.
+ */
+int ath5k_hw_set_opmode(struct ath5k_hw *ah)
+{
+       u32 pcu_reg, beacon_reg, low_id, high_id;
+
+
+       /* Preserve rest settings */
+       pcu_reg = ath5k_hw_reg_read(ah, AR5K_STA_ID1) & 0xffff0000;
+       pcu_reg &= ~(AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_AP
+                       | AR5K_STA_ID1_KEYSRCH_MODE
+                       | (ah->ah_version == AR5K_AR5210 ?
+                       (AR5K_STA_ID1_PWR_SV | AR5K_STA_ID1_NO_PSPOLL) : 0));
+
+       beacon_reg = 0;
+
+       pcu_reg |= AR5K_STA_ID1_KEYSRCH_MODE
+               | (ah->ah_version == AR5K_AR5210 ?
+                  AR5K_STA_ID1_PWR_SV : 0);
+
+       /*
+        * Set PCU registers
+        */
+       low_id = AR5K_LOW_ID(ah->ah_sta_id);
+       high_id = AR5K_HIGH_ID(ah->ah_sta_id);
+       ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
+       ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
+
+       /*
+        * Set Beacon Control Register on 5210
+        */
+       if (ah->ah_version == AR5K_AR5210)
+               ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
+
+       return 0;
+}
+
+/**
+ * ath5k_hw_set_ack_bitrate - set bitrate for ACKs
+ *
+ * @ah: The &struct ath5k_hw
+ * @high: Flag to determine if we want to use high transmition rate
+ * for ACKs or not
+ *
+ * If high flag is set, we tell hw to use a set of control rates based on
+ * the current transmition rate (check out control_rates array inside reset.c).
+ * If not hw just uses the lowest rate available for the current modulation
+ * scheme being used (1Mbit for CCK and 6Mbits for OFDM).
+ */
+void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, int high)
+{
+       if (ah->ah_version != AR5K_AR5212)
+               return;
+       else {
+               u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
+               if (high)
+                       AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
+               else
+                       AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
+       }
+}
+
+
+/******************\
+* ACK/CTS Timeouts *
+\******************/
+
+/**
+ * ath5k_hw_het_ack_timeout - Get ACK timeout from PCU in usec
+ *
+ * @ah: The &struct ath5k_hw
+ */
+unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
+{
+       return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
+                       AR5K_TIME_OUT), AR5K_TIME_OUT_ACK), ah->ah_turbo);
+}
+
+/**
+ * ath5k_hw_set_ack_timeout - Set ACK timeout on PCU
+ *
+ * @ah: The &struct ath5k_hw
+ * @timeout: Timeout in usec
+ */
+int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
+{
+       if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK),
+                       ah->ah_turbo) <= timeout)
+               return -EINVAL;
+
+       AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
+               ath5k_hw_htoclock(timeout, ah->ah_turbo));
+
+       return 0;
+}
+
+/**
+ * ath5k_hw_get_cts_timeout - Get CTS timeout from PCU in usec
+ *
+ * @ah: The &struct ath5k_hw
+ */
+unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
+{
+       return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
+                       AR5K_TIME_OUT), AR5K_TIME_OUT_CTS), ah->ah_turbo);
+}
+
+/**
+ * ath5k_hw_set_cts_timeout - Set CTS timeout on PCU
+ *
+ * @ah: The &struct ath5k_hw
+ * @timeout: Timeout in usec
+ */
+int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
+{
+       if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS),
+                       ah->ah_turbo) <= timeout)
+               return -EINVAL;
+
+       AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
+                       ath5k_hw_htoclock(timeout, ah->ah_turbo));
+
+       return 0;
+}
+
+
+/****************\
+* BSSID handling *
+\****************/
+
+/**
+ * ath5k_hw_get_lladdr - Get station id
+ *
+ * @ah: The &struct ath5k_hw
+ * @mac: The card's mac address
+ *
+ * Initialize ah->ah_sta_id using the mac address provided
+ * (just a memcpy).
+ *
+ * TODO: Remove it once we merge ath5k_softc and ath5k_hw
+ */
+void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
+{
+       memcpy(mac, ah->ah_sta_id, ETH_ALEN);
+}
+
+/**
+ * ath5k_hw_set_lladdr - Set station id
+ *
+ * @ah: The &struct ath5k_hw
+ * @mac: The card's mac address
+ *
+ * Set station id on hw using the provided mac address
+ */
+int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
+{
+       u32 low_id, high_id;
+       u32 pcu_reg;
+
+       /* Set new station ID */
+       memcpy(ah->ah_sta_id, mac, ETH_ALEN);
+
+       pcu_reg = ath5k_hw_reg_read(ah, AR5K_STA_ID1) & 0xffff0000;
+
+       low_id = AR5K_LOW_ID(mac);
+       high_id = AR5K_HIGH_ID(mac);
+
+       ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
+       ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
+
+       return 0;
+}
+
+/**
+ * ath5k_hw_set_associd - Set BSSID for association
+ *
+ * @ah: The &struct ath5k_hw
+ * @bssid: BSSID
+ * @assoc_id: Assoc id
+ *
+ * Sets the BSSID which trigers the "SME Join" operation
+ */
+void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
+{
+       u32 low_id, high_id;
+
+       /*
+        * Set simple BSSID mask on 5212
+        */
+       if (ah->ah_version == AR5K_AR5212) {
+               ath5k_hw_reg_write(ah, AR5K_LOW_ID(ah->ah_bssid_mask),
+                                                       AR5K_BSS_IDM0);
+               ath5k_hw_reg_write(ah, AR5K_HIGH_ID(ah->ah_bssid_mask),
+                                                       AR5K_BSS_IDM1);
+       }
+
+       /*
+        * Set BSSID which triggers the "SME Join" operation
+        */
+       low_id = AR5K_LOW_ID(bssid);
+       high_id = AR5K_HIGH_ID(bssid);
+       ath5k_hw_reg_write(ah, low_id, AR5K_BSS_ID0);
+       ath5k_hw_reg_write(ah, high_id | ((assoc_id & 0x3fff) <<
+                               AR5K_BSS_ID1_AID_S), AR5K_BSS_ID1);
+}
+
+/**
+ * ath5k_hw_set_bssid_mask - filter out bssids we listen
+ *
+ * @ah: the &struct ath5k_hw
+ * @mask: the bssid_mask, a u8 array of size ETH_ALEN
+ *
+ * BSSID masking is a method used by AR5212 and newer hardware to inform PCU
+ * which bits of the interface's MAC address should be looked at when trying
+ * to decide which packets to ACK. In station mode and AP mode with a single
+ * BSS every bit matters since we lock to only one BSS. In AP mode with
+ * multiple BSSes (virtual interfaces) not every bit matters because hw must
+ * accept frames for all BSSes and so we tweak some bits of our mac address
+ * in order to have multiple BSSes.
+ *
+ * NOTE: This is a simple filter and does *not* filter out all
+ * relevant frames. Some frames that are not for us might get ACKed from us
+ * by PCU because they just match the mask.
+ *
+ * When handling multiple BSSes you can get the BSSID mask by computing the
+ * set of  ~ ( MAC XOR BSSID ) for all bssids we handle.
+ *
+ * When you do this you are essentially computing the common bits of all your
+ * BSSes. Later it is assumed the harware will "and" (&) the BSSID mask with
+ * the MAC address to obtain the relevant bits and compare the result with
+ * (frame's BSSID & mask) to see if they match.
+ */
+/*
+ * Simple example: on your card you have have two BSSes you have created with
+ * BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address.
+ * There is another BSSID-03 but you are not part of it. For simplicity's sake,
+ * assuming only 4 bits for a mac address and for BSSIDs you can then have:
+ *
+ *                  \
+ * MAC:                0001 |
+ * BSSID-01:   0100 | --> Belongs to us
+ * BSSID-02:   1001 |
+ *                  /
+ * -------------------
+ * BSSID-03:   0110  | --> External
+ * -------------------
+ *
+ * Our bssid_mask would then be:
+ *
+ *             On loop iteration for BSSID-01:
+ *             ~(0001 ^ 0100)  -> ~(0101)
+ *                             ->   1010
+ *             bssid_mask      =    1010
+ *
+ *             On loop iteration for BSSID-02:
+ *             bssid_mask &= ~(0001   ^   1001)
+ *             bssid_mask =   (1010)  & ~(0001 ^ 1001)
+ *             bssid_mask =   (1010)  & ~(1001)
+ *             bssid_mask =   (1010)  &  (0110)
+ *             bssid_mask =   0010
+ *
+ * A bssid_mask of 0010 means "only pay attention to the second least
+ * significant bit". This is because its the only bit common
+ * amongst the MAC and all BSSIDs we support. To findout what the real
+ * common bit is we can simply "&" the bssid_mask now with any BSSID we have
+ * or our MAC address (we assume the hardware uses the MAC address).
+ *
+ * Now, suppose there's an incoming frame for BSSID-03:
+ *
+ * IFRAME-01:  0110
+ *
+ * An easy eye-inspeciton of this already should tell you that this frame
+ * will not pass our check. This is beacuse the bssid_mask tells the
+ * hardware to only look at the second least significant bit and the
+ * common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB
+ * as 1, which does not match 0.
+ *
+ * So with IFRAME-01 we *assume* the hardware will do:
+ *
+ *     allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
+ *  --> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0;
+ *  --> allow = (0010) == 0000 ? 1 : 0;
+ *  --> allow = 0
+ *
+ *  Lets now test a frame that should work:
+ *
+ * IFRAME-02:  0001 (we should allow)
+ *
+ *     allow = (0001 & 1010) == 1010
+ *
+ *     allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
+ *  --> allow = (0001 & 0010) ==  (0010 & 0001) ? 1 :0;
+ *  --> allow = (0010) == (0010)
+ *  --> allow = 1
+ *
+ * Other examples:
+ *
+ * IFRAME-03:  0100 --> allowed
+ * IFRAME-04:  1001 --> allowed
+ * IFRAME-05:  1101 --> allowed but its not for us!!!
+ *
+ */
+int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
+{
+       u32 low_id, high_id;
+
+       /* Cache bssid mask so that we can restore it
+        * on reset */
+       memcpy(ah->ah_bssid_mask, mask, ETH_ALEN);
+       if (ah->ah_version == AR5K_AR5212) {
+               low_id = AR5K_LOW_ID(mask);
+               high_id = AR5K_HIGH_ID(mask);
+
+               ath5k_hw_reg_write(ah, low_id, AR5K_BSS_IDM0);
+               ath5k_hw_reg_write(ah, high_id, AR5K_BSS_IDM1);
+
+               return 0;
+       }
+
+       return -EIO;
+}
+
+
+/************\
+* RX Control *
+\************/
+
+/**
+ * ath5k_hw_start_rx_pcu - Start RX engine
+ *
+ * @ah: The &struct ath5k_hw
+ *
+ * Starts RX engine on PCU so that hw can process RXed frames
+ * (ACK etc).
+ *
+ * NOTE: RX DMA should be already enabled using ath5k_hw_start_rx_dma
+ * TODO: Init ANI here
+ */
+void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
+{
+       AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
+}
+
+/**
+ * at5k_hw_stop_rx_pcu - Stop RX engine
+ *
+ * @ah: The &struct ath5k_hw
+ *
+ * Stops RX engine on PCU
+ *
+ * TODO: Detach ANI here
+ */
+void ath5k_hw_stop_rx_pcu(struct ath5k_hw *ah)
+{
+       AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
+}
+
+/*
+ * Set multicast filter
+ */
+void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
+{
+       /* Set the multicat filter */
+       ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
+       ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
+}
+
+/**
+ * ath5k_hw_get_rx_filter - Get current rx filter
+ *
+ * @ah: The &struct ath5k_hw
+ *
+ * Returns the RX filter by reading rx filter and
+ * phy error filter registers. RX filter is used
+ * to set the allowed frame types that PCU will accept
+ * and pass to the driver. For a list of frame types
+ * check out reg.h.
+ */
+u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
+{
+       u32 data, filter = 0;
+
+       filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
+
+       /*Radar detection for 5212*/
+       if (ah->ah_version == AR5K_AR5212) {
+               data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
+
+               if (data & AR5K_PHY_ERR_FIL_RADAR)
+                       filter |= AR5K_RX_FILTER_RADARERR;
+               if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
+                       filter |= AR5K_RX_FILTER_PHYERR;
+       }
+
+       return filter;
+}
+
+/**
+ * ath5k_hw_set_rx_filter - Set rx filter
+ *
+ * @ah: The &struct ath5k_hw
+ * @filter: RX filter mask (see reg.h)
+ *
+ * Sets RX filter register and also handles PHY error filter
+ * register on 5212 and newer chips so that we have proper PHY
+ * error reporting.
+ */
+void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
+{
+       u32 data = 0;
+
+       /* Set PHY error filter register on 5212*/
+       if (ah->ah_version == AR5K_AR5212) {
+               if (filter & AR5K_RX_FILTER_RADARERR)
+                       data |= AR5K_PHY_ERR_FIL_RADAR;
+               if (filter & AR5K_RX_FILTER_PHYERR)
+                       data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
+       }
+
+       /*
+        * The AR5210 uses promiscous mode to detect radar activity
+        */
+       if (ah->ah_version == AR5K_AR5210 &&
+                       (filter & AR5K_RX_FILTER_RADARERR)) {
+               filter &= ~AR5K_RX_FILTER_RADARERR;
+               filter |= AR5K_RX_FILTER_PROM;
+       }
+
+       /*Zero length DMA (phy error reporting) */
+       if (data)
+               AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
+       else
+               AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
+
+       /*Write RX Filter register*/
+       ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
+
+       /*Write PHY error filter register on 5212*/
+       if (ah->ah_version == AR5K_AR5212)
+               ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
+
+}
+
+/*********************\
+* Key table functions *
+\*********************/
+
+/*
+ * Reset a key entry on the table
+ */
+int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
+{
+       unsigned int i, type;
+       u16 micentry = entry + AR5K_KEYTABLE_MIC_OFFSET;
+
+       type = ath5k_hw_reg_read(ah, AR5K_KEYTABLE_TYPE(entry));
+
+       for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
+               ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
+
+       /* Reset associated MIC entry if TKIP
+        * is enabled located at offset (entry + 64) */
+       if (type == AR5K_KEYTABLE_TYPE_TKIP) {
+               for (i = 0; i < AR5K_KEYCACHE_SIZE / 2 ; i++)
+                       ath5k_hw_reg_write(ah, 0,
+                               AR5K_KEYTABLE_OFF(micentry, i));
+       }
+
+       /*
+        * Set NULL encryption on AR5212+
+        *
+        * Note: AR5K_KEYTABLE_TYPE -> AR5K_KEYTABLE_OFF(entry, 5)
+        *       AR5K_KEYTABLE_TYPE_NULL -> 0x00000007
+        *
+        * Note2: Windows driver (ndiswrapper) sets this to
+        *        0x00000714 instead of 0x00000007
+        */
+       if (ah->ah_version > AR5K_AR5211) {
+               ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
+                               AR5K_KEYTABLE_TYPE(entry));
+
+               if (type == AR5K_KEYTABLE_TYPE_TKIP) {
+                       ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
+                               AR5K_KEYTABLE_TYPE(micentry));
+               }
+       }
+
+       return 0;
+}
diff --git a/src/drivers/net/ath5k/ath5k_phy.c b/src/drivers/net/ath5k/ath5k_phy.c
new file mode 100644 (file)
index 0000000..8856fa3
--- /dev/null
@@ -0,0 +1,2586 @@
+/*
+ * PHY functions
+ *
+ * Copyright (c) 2004-2007 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2009 Nick Kossifidis <mickflemm@gmail.com>
+ * Copyright (c) 2007-2008 Jiri Slaby <jirislaby@gmail.com>
+ * Copyright (c) 2008-2009 Felix Fietkau <nbd@openwrt.org>
+ *
+ * Lightly modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+FILE_LICENCE ( MIT );
+
+#define _ATH5K_PHY
+
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "ath5k.h"
+#include "reg.h"
+#include "base.h"
+#include "rfbuffer.h"
+#include "rfgain.h"
+
+static inline int min(int x, int y)
+{
+       return (x < y) ? x : y;
+}
+
+static inline int max(int x, int y)
+{
+       return (x > y) ? x : y;
+}
+
+/*
+ * Used to modify RF Banks before writing them to AR5K_RF_BUFFER
+ */
+static unsigned int ath5k_hw_rfb_op(struct ath5k_hw *ah,
+                                       const struct ath5k_rf_reg *rf_regs,
+                                       u32 val, u8 reg_id, int set)
+{
+       const struct ath5k_rf_reg *rfreg = NULL;
+       u8 offset, bank, num_bits, col, position;
+       u16 entry;
+       u32 mask, data, last_bit, bits_shifted, first_bit;
+       u32 *rfb;
+       s32 bits_left;
+       unsigned i;
+
+       data = 0;
+       rfb = ah->ah_rf_banks;
+
+       for (i = 0; i < ah->ah_rf_regs_count; i++) {
+               if (rf_regs[i].index == reg_id) {
+                       rfreg = &rf_regs[i];
+                       break;
+               }
+       }
+
+       if (rfb == NULL || rfreg == NULL) {
+               DBG("ath5k: RF register not found!\n");
+               /* should not happen */
+               return 0;
+       }
+
+       bank = rfreg->bank;
+       num_bits = rfreg->field.len;
+       first_bit = rfreg->field.pos;
+       col = rfreg->field.col;
+
+       /* first_bit is an offset from bank's
+        * start. Since we have all banks on
+        * the same array, we use this offset
+        * to mark each bank's start */
+       offset = ah->ah_offset[bank];
+
+       /* Boundary check */
+       if (!(col <= 3 && num_bits <= 32 && first_bit + num_bits <= 319)) {
+               DBG("ath5k: RF invalid values at offset %d\n", offset);
+               return 0;
+       }
+
+       entry = ((first_bit - 1) / 8) + offset;
+       position = (first_bit - 1) % 8;
+
+       if (set)
+               data = ath5k_hw_bitswap(val, num_bits);
+
+       for (bits_shifted = 0, bits_left = num_bits; bits_left > 0;
+       position = 0, entry++) {
+
+               last_bit = (position + bits_left > 8) ? 8 :
+                                       position + bits_left;
+
+               mask = (((1 << last_bit) - 1) ^ ((1 << position) - 1)) <<
+                                                               (col * 8);
+
+               if (set) {
+                       rfb[entry] &= ~mask;
+                       rfb[entry] |= ((data << position) << (col * 8)) & mask;
+                       data >>= (8 - position);
+               } else {
+                       data |= (((rfb[entry] & mask) >> (col * 8)) >> position)
+                               << bits_shifted;
+                       bits_shifted += last_bit - position;
+               }
+
+               bits_left -= 8 - position;
+       }
+
+       data = set ? 1 : ath5k_hw_bitswap(data, num_bits);
+
+       return data;
+}
+
+/**********************\
+* RF Gain optimization *
+\**********************/
+
+/*
+ * This code is used to optimize rf gain on different environments
+ * (temprature mostly) based on feedback from a power detector.
+ *
+ * It's only used on RF5111 and RF5112, later RF chips seem to have
+ * auto adjustment on hw -notice they have a much smaller BANK 7 and
+ * no gain optimization ladder-.
+ *
+ * For more infos check out this patent doc
+ * http://www.freepatentsonline.com/7400691.html
+ *
+ * This paper describes power drops as seen on the receiver due to
+ * probe packets
+ * http://www.cnri.dit.ie/publications/ICT08%20-%20Practical%20Issues
+ * %20of%20Power%20Control.pdf
+ *
+ * And this is the MadWiFi bug entry related to the above
+ * http://madwifi-project.org/ticket/1659
+ * with various measurements and diagrams
+ *
+ * TODO: Deal with power drops due to probes by setting an apropriate
+ * tx power on the probe packets ! Make this part of the calibration process.
+ */
+
+/* Initialize ah_gain durring attach */
+int ath5k_hw_rfgain_opt_init(struct ath5k_hw *ah)
+{
+       /* Initialize the gain optimization values */
+       switch (ah->ah_radio) {
+       case AR5K_RF5111:
+               ah->ah_gain.g_step_idx = rfgain_opt_5111.go_default;
+               ah->ah_gain.g_low = 20;
+               ah->ah_gain.g_high = 35;
+               ah->ah_gain.g_state = AR5K_RFGAIN_ACTIVE;
+               break;
+       case AR5K_RF5112:
+               ah->ah_gain.g_step_idx = rfgain_opt_5112.go_default;
+               ah->ah_gain.g_low = 20;
+               ah->ah_gain.g_high = 85;
+               ah->ah_gain.g_state = AR5K_RFGAIN_ACTIVE;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+/* Schedule a gain probe check on the next transmited packet.
+ * That means our next packet is going to be sent with lower
+ * tx power and a Peak to Average Power Detector (PAPD) will try
+ * to measure the gain.
+ *
+ * TODO: Use propper tx power setting for the probe packet so
+ * that we don't observe a serious power drop on the receiver
+ *
+ * XXX:  How about forcing a tx packet (bypassing PCU arbitrator etc)
+ * just after we enable the probe so that we don't mess with
+ * standard traffic ? Maybe it's time to use sw interrupts and
+ * a probe tasklet !!!
+ */
+static void ath5k_hw_request_rfgain_probe(struct ath5k_hw *ah)
+{
+
+       /* Skip if gain calibration is inactive or
+        * we already handle a probe request */
+       if (ah->ah_gain.g_state != AR5K_RFGAIN_ACTIVE)
+               return;
+
+       /* Send the packet with 2dB below max power as
+        * patent doc suggest */
+       ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txpower.txp_max_pwr - 4,
+                       AR5K_PHY_PAPD_PROBE_TXPOWER) |
+                       AR5K_PHY_PAPD_PROBE_TX_NEXT, AR5K_PHY_PAPD_PROBE);
+
+       ah->ah_gain.g_state = AR5K_RFGAIN_READ_REQUESTED;
+
+}
+
+/* Calculate gain_F measurement correction
+ * based on the current step for RF5112 rev. 2 */
+static u32 ath5k_hw_rf_gainf_corr(struct ath5k_hw *ah)
+{
+       u32 mix, step;
+       u32 *rf;
+       const struct ath5k_gain_opt *go;
+       const struct ath5k_gain_opt_step *g_step;
+       const struct ath5k_rf_reg *rf_regs;
+
+       /* Only RF5112 Rev. 2 supports it */
+       if ((ah->ah_radio != AR5K_RF5112) ||
+       (ah->ah_radio_5ghz_revision <= AR5K_SREV_RAD_5112A))
+               return 0;
+
+       go = &rfgain_opt_5112;
+       rf_regs = rf_regs_5112a;
+       ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_5112a);
+
+       g_step = &go->go_step[ah->ah_gain.g_step_idx];
+
+       if (ah->ah_rf_banks == NULL)
+               return 0;
+
+       rf = ah->ah_rf_banks;
+       ah->ah_gain.g_f_corr = 0;
+
+       /* No VGA (Variable Gain Amplifier) override, skip */
+       if (ath5k_hw_rfb_op(ah, rf_regs, 0, AR5K_RF_MIXVGA_OVR, 0) != 1)
+               return 0;
+
+       /* Mix gain stepping */
+       step = ath5k_hw_rfb_op(ah, rf_regs, 0, AR5K_RF_MIXGAIN_STEP, 0);
+
+       /* Mix gain override */
+       mix = g_step->gos_param[0];
+
+       switch (mix) {
+       case 3:
+               ah->ah_gain.g_f_corr = step * 2;
+               break;
+       case 2:
+               ah->ah_gain.g_f_corr = (step - 5) * 2;
+               break;
+       case 1:
+               ah->ah_gain.g_f_corr = step;
+               break;
+       default:
+               ah->ah_gain.g_f_corr = 0;
+               break;
+       }
+
+       return ah->ah_gain.g_f_corr;
+}
+
+/* Check if current gain_F measurement is in the range of our
+ * power detector windows. If we get a measurement outside range
+ * we know it's not accurate (detectors can't measure anything outside
+ * their detection window) so we must ignore it */
+static int ath5k_hw_rf_check_gainf_readback(struct ath5k_hw *ah)
+{
+       const struct ath5k_rf_reg *rf_regs;
+       u32 step, mix_ovr, level[4];
+       u32 *rf;
+
+       if (ah->ah_rf_banks == NULL)
+               return 0;
+
+       rf = ah->ah_rf_banks;
+
+       if (ah->ah_radio == AR5K_RF5111) {
+
+               rf_regs = rf_regs_5111;
+               ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_5111);
+
+               step = ath5k_hw_rfb_op(ah, rf_regs, 0, AR5K_RF_RFGAIN_STEP,
+                       0);
+
+               level[0] = 0;
+               level[1] = (step == 63) ? 50 : step + 4;
+               level[2] = (step != 63) ? 64 : level[0];
+               level[3] = level[2] + 50 ;
+
+               ah->ah_gain.g_high = level[3] -
+                       (step == 63 ? AR5K_GAIN_DYN_ADJUST_HI_MARGIN : -5);
+               ah->ah_gain.g_low = level[0] +
+                       (step == 63 ? AR5K_GAIN_DYN_ADJUST_LO_MARGIN : 0);
+       } else {
+
+               rf_regs = rf_regs_5112;
+               ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_5112);
+
+               mix_ovr = ath5k_hw_rfb_op(ah, rf_regs, 0, AR5K_RF_MIXVGA_OVR,
+                       0);
+
+               level[0] = level[2] = 0;
+
+               if (mix_ovr == 1) {
+                       level[1] = level[3] = 83;
+               } else {
+                       level[1] = level[3] = 107;
+                       ah->ah_gain.g_high = 55;
+               }
+       }
+
+       return (ah->ah_gain.g_current >= level[0] &&
+                       ah->ah_gain.g_current <= level[1]) ||
+               (ah->ah_gain.g_current >= level[2] &&
+                       ah->ah_gain.g_current <= level[3]);
+}
+
+/* Perform gain_F adjustment by choosing the right set
+ * of parameters from rf gain optimization ladder */
+static s8 ath5k_hw_rf_gainf_adjust(struct ath5k_hw *ah)
+{
+       const struct ath5k_gain_opt *go;
+       const struct ath5k_gain_opt_step *g_step;
+       int ret = 0;
+
+       switch (ah->ah_radio) {
+       case AR5K_RF5111:
+               go = &rfgain_opt_5111;
+               break;
+       case AR5K_RF5112:
+               go = &rfgain_opt_5112;
+               break;
+       default:
+               return 0;
+       }
+
+       g_step = &go->go_step[ah->ah_gain.g_step_idx];
+
+       if (ah->ah_gain.g_current >= ah->ah_gain.g_high) {
+
+               /* Reached maximum */
+               if (ah->ah_gain.g_step_idx == 0)
+                       return -1;
+
+               for (ah->ah_gain.g_target = ah->ah_gain.g_current;
+                               ah->ah_gain.g_target >=  ah->ah_gain.g_high &&
+                               ah->ah_gain.g_step_idx > 0;
+                               g_step = &go->go_step[ah->ah_gain.g_step_idx])
+                       ah->ah_gain.g_target -= 2 *
+                           (go->go_step[--(ah->ah_gain.g_step_idx)].gos_gain -
+                           g_step->gos_gain);
+
+               ret = 1;
+               goto done;
+       }
+
+       if (ah->ah_gain.g_current <= ah->ah_gain.g_low) {
+
+               /* Reached minimum */
+               if (ah->ah_gain.g_step_idx == (go->go_steps_count - 1))
+                       return -2;
+
+               for (ah->ah_gain.g_target = ah->ah_gain.g_current;
+                               ah->ah_gain.g_target <= ah->ah_gain.g_low &&
+                               ah->ah_gain.g_step_idx < go->go_steps_count-1;
+                               g_step = &go->go_step[ah->ah_gain.g_step_idx])
+                       ah->ah_gain.g_target -= 2 *
+                           (go->go_step[++ah->ah_gain.g_step_idx].gos_gain -
+                           g_step->gos_gain);
+
+               ret = 2;
+               goto done;
+       }
+
+done:
+       DBG2("ath5k RF adjust: ret %d, gain step %d, current gain %d, "
+            "target gain %d\n", ret, ah->ah_gain.g_step_idx,
+            ah->ah_gain.g_current, ah->ah_gain.g_target);
+
+       return ret;
+}
+
+/* Main callback for thermal rf gain calibration engine
+ * Check for a new gain reading and schedule an adjustment
+ * if needed.
+ *
+ * TODO: Use sw interrupt to schedule reset if gain_F needs
+ * adjustment */
+enum ath5k_rfgain ath5k_hw_gainf_calibrate(struct ath5k_hw *ah)
+{
+       u32 data, type;
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+
+       if (ah->ah_rf_banks == NULL ||
+       ah->ah_gain.g_state == AR5K_RFGAIN_INACTIVE)
+               return AR5K_RFGAIN_INACTIVE;
+
+       /* No check requested, either engine is inactive
+        * or an adjustment is already requested */
+       if (ah->ah_gain.g_state != AR5K_RFGAIN_READ_REQUESTED)
+               goto done;
+
+       /* Read the PAPD (Peak to Average Power Detector)
+        * register */
+       data = ath5k_hw_reg_read(ah, AR5K_PHY_PAPD_PROBE);
+
+       /* No probe is scheduled, read gain_F measurement */
+       if (!(data & AR5K_PHY_PAPD_PROBE_TX_NEXT)) {
+               ah->ah_gain.g_current = data >> AR5K_PHY_PAPD_PROBE_GAINF_S;
+               type = AR5K_REG_MS(data, AR5K_PHY_PAPD_PROBE_TYPE);
+
+               /* If tx packet is CCK correct the gain_F measurement
+                * by cck ofdm gain delta */
+               if (type == AR5K_PHY_PAPD_PROBE_TYPE_CCK) {
+                       if (ah->ah_radio_5ghz_revision >= AR5K_SREV_RAD_5112A)
+                               ah->ah_gain.g_current +=
+                                       ee->ee_cck_ofdm_gain_delta;
+                       else
+                               ah->ah_gain.g_current +=
+                                       AR5K_GAIN_CCK_PROBE_CORR;
+               }
+
+               /* Further correct gain_F measurement for
+                * RF5112A radios */
+               if (ah->ah_radio_5ghz_revision >= AR5K_SREV_RAD_5112A) {
+                       ath5k_hw_rf_gainf_corr(ah);
+                       ah->ah_gain.g_current =
+                               ah->ah_gain.g_current >= ah->ah_gain.g_f_corr ?
+                               (ah->ah_gain.g_current-ah->ah_gain.g_f_corr) :
+                               0;
+               }
+
+               /* Check if measurement is ok and if we need
+                * to adjust gain, schedule a gain adjustment,
+                * else switch back to the acive state */
+               if (ath5k_hw_rf_check_gainf_readback(ah) &&
+               AR5K_GAIN_CHECK_ADJUST(&ah->ah_gain) &&
+               ath5k_hw_rf_gainf_adjust(ah)) {
+                       ah->ah_gain.g_state = AR5K_RFGAIN_NEED_CHANGE;
+               } else {
+                       ah->ah_gain.g_state = AR5K_RFGAIN_ACTIVE;
+               }
+       }
+
+done:
+       return ah->ah_gain.g_state;
+}
+
+/* Write initial rf gain table to set the RF sensitivity
+ * this one works on all RF chips and has nothing to do
+ * with gain_F calibration */
+int ath5k_hw_rfgain_init(struct ath5k_hw *ah, unsigned int freq)
+{
+       const struct ath5k_ini_rfgain *ath5k_rfg;
+       unsigned int i, size;
+
+       switch (ah->ah_radio) {
+       case AR5K_RF5111:
+               ath5k_rfg = rfgain_5111;
+               size = ARRAY_SIZE(rfgain_5111);
+               break;
+       case AR5K_RF5112:
+               ath5k_rfg = rfgain_5112;
+               size = ARRAY_SIZE(rfgain_5112);
+               break;
+       case AR5K_RF2413:
+               ath5k_rfg = rfgain_2413;
+               size = ARRAY_SIZE(rfgain_2413);
+               break;
+       case AR5K_RF2316:
+               ath5k_rfg = rfgain_2316;
+               size = ARRAY_SIZE(rfgain_2316);
+               break;
+       case AR5K_RF5413:
+               ath5k_rfg = rfgain_5413;
+               size = ARRAY_SIZE(rfgain_5413);
+               break;
+       case AR5K_RF2317:
+       case AR5K_RF2425:
+               ath5k_rfg = rfgain_2425;
+               size = ARRAY_SIZE(rfgain_2425);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       switch (freq) {
+       case AR5K_INI_RFGAIN_2GHZ:
+       case AR5K_INI_RFGAIN_5GHZ:
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       for (i = 0; i < size; i++) {
+               AR5K_REG_WAIT(i);
+               ath5k_hw_reg_write(ah, ath5k_rfg[i].rfg_value[freq],
+                       (u32)ath5k_rfg[i].rfg_register);
+       }
+
+       return 0;
+}
+
+
+
+/********************\
+* RF Registers setup *
+\********************/
+
+
+/*
+ * Setup RF registers by writing rf buffer on hw
+ */
+int ath5k_hw_rfregs_init(struct ath5k_hw *ah, struct net80211_channel *channel,
+               unsigned int mode)
+{
+       const struct ath5k_rf_reg *rf_regs;
+       const struct ath5k_ini_rfbuffer *ini_rfb;
+       const struct ath5k_gain_opt *go = NULL;
+       const struct ath5k_gain_opt_step *g_step;
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       u8 ee_mode = 0;
+       u32 *rfb;
+       int obdb = -1, bank = -1;
+       unsigned i;
+
+       switch (ah->ah_radio) {
+       case AR5K_RF5111:
+               rf_regs = rf_regs_5111;
+               ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_5111);
+               ini_rfb = rfb_5111;
+               ah->ah_rf_banks_size = ARRAY_SIZE(rfb_5111);
+               go = &rfgain_opt_5111;
+               break;
+       case AR5K_RF5112:
+               if (ah->ah_radio_5ghz_revision >= AR5K_SREV_RAD_5112A) {
+                       rf_regs = rf_regs_5112a;
+                       ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_5112a);
+                       ini_rfb = rfb_5112a;
+                       ah->ah_rf_banks_size = ARRAY_SIZE(rfb_5112a);
+               } else {
+                       rf_regs = rf_regs_5112;
+                       ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_5112);
+                       ini_rfb = rfb_5112;
+                       ah->ah_rf_banks_size = ARRAY_SIZE(rfb_5112);
+               }
+               go = &rfgain_opt_5112;
+               break;
+       case AR5K_RF2413:
+               rf_regs = rf_regs_2413;
+               ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_2413);
+               ini_rfb = rfb_2413;
+               ah->ah_rf_banks_size = ARRAY_SIZE(rfb_2413);
+               break;
+       case AR5K_RF2316:
+               rf_regs = rf_regs_2316;
+               ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_2316);
+               ini_rfb = rfb_2316;
+               ah->ah_rf_banks_size = ARRAY_SIZE(rfb_2316);
+               break;
+       case AR5K_RF5413:
+               rf_regs = rf_regs_5413;
+               ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_5413);
+               ini_rfb = rfb_5413;
+               ah->ah_rf_banks_size = ARRAY_SIZE(rfb_5413);
+               break;
+       case AR5K_RF2317:
+               rf_regs = rf_regs_2425;
+               ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_2425);
+               ini_rfb = rfb_2317;
+               ah->ah_rf_banks_size = ARRAY_SIZE(rfb_2317);
+               break;
+       case AR5K_RF2425:
+               rf_regs = rf_regs_2425;
+               ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_2425);
+               if (ah->ah_mac_srev < AR5K_SREV_AR2417) {
+                       ini_rfb = rfb_2425;
+                       ah->ah_rf_banks_size = ARRAY_SIZE(rfb_2425);
+               } else {
+                       ini_rfb = rfb_2417;
+                       ah->ah_rf_banks_size = ARRAY_SIZE(rfb_2417);
+               }
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* If it's the first time we set rf buffer, allocate
+        * ah->ah_rf_banks based on ah->ah_rf_banks_size
+        * we set above */
+       if (ah->ah_rf_banks == NULL) {
+               ah->ah_rf_banks = malloc(sizeof(u32) * ah->ah_rf_banks_size);
+               if (ah->ah_rf_banks == NULL) {
+                       return -ENOMEM;
+               }
+       }
+
+       /* Copy values to modify them */
+       rfb = ah->ah_rf_banks;
+
+       for (i = 0; i < ah->ah_rf_banks_size; i++) {
+               if (ini_rfb[i].rfb_bank >= AR5K_MAX_RF_BANKS) {
+                       DBG("ath5k: invalid RF register bank\n");
+                       return -EINVAL;
+               }
+
+               /* Bank changed, write down the offset */
+               if (bank != ini_rfb[i].rfb_bank) {
+                       bank = ini_rfb[i].rfb_bank;
+                       ah->ah_offset[bank] = i;
+               }
+
+               rfb[i] = ini_rfb[i].rfb_mode_data[mode];
+       }
+
+       /* Set Output and Driver bias current (OB/DB) */
+       if (channel->hw_value & CHANNEL_2GHZ) {
+
+               if (channel->hw_value & CHANNEL_CCK)
+                       ee_mode = AR5K_EEPROM_MODE_11B;
+               else
+                       ee_mode = AR5K_EEPROM_MODE_11G;
+
+               /* For RF511X/RF211X combination we
+                * use b_OB and b_DB parameters stored
+                * in eeprom on ee->ee_ob[ee_mode][0]
+                *
+                * For all other chips we use OB/DB for 2Ghz
+                * stored in the b/g modal section just like
+                * 802.11a on ee->ee_ob[ee_mode][1] */
+               if ((ah->ah_radio == AR5K_RF5111) ||
+               (ah->ah_radio == AR5K_RF5112))
+                       obdb = 0;
+               else
+                       obdb = 1;
+
+               ath5k_hw_rfb_op(ah, rf_regs, ee->ee_ob[ee_mode][obdb],
+                                               AR5K_RF_OB_2GHZ, 1);
+
+               ath5k_hw_rfb_op(ah, rf_regs, ee->ee_db[ee_mode][obdb],
+                                               AR5K_RF_DB_2GHZ, 1);
+
+       /* RF5111 always needs OB/DB for 5GHz, even if we use 2GHz */
+       } else if ((channel->hw_value & CHANNEL_5GHZ) ||
+                       (ah->ah_radio == AR5K_RF5111)) {
+
+               /* For 11a, Turbo and XR we need to choose
+                * OB/DB based on frequency range */
+               ee_mode = AR5K_EEPROM_MODE_11A;
+               obdb =   channel->center_freq >= 5725 ? 3 :
+                       (channel->center_freq >= 5500 ? 2 :
+                       (channel->center_freq >= 5260 ? 1 :
+                        (channel->center_freq > 4000 ? 0 : -1)));
+
+               if (obdb < 0)
+                       return -EINVAL;
+
+               ath5k_hw_rfb_op(ah, rf_regs, ee->ee_ob[ee_mode][obdb],
+                                               AR5K_RF_OB_5GHZ, 1);
+
+               ath5k_hw_rfb_op(ah, rf_regs, ee->ee_db[ee_mode][obdb],
+                                               AR5K_RF_DB_5GHZ, 1);
+       }
+
+       g_step = &go->go_step[ah->ah_gain.g_step_idx];
+
+       /* Bank Modifications (chip-specific) */
+       if (ah->ah_radio == AR5K_RF5111) {
+
+               /* Set gain_F settings according to current step */
+               if (channel->hw_value & CHANNEL_OFDM) {
+
+                       AR5K_REG_WRITE_BITS(ah, AR5K_PHY_FRAME_CTL,
+                                       AR5K_PHY_FRAME_CTL_TX_CLIP,
+                                       g_step->gos_param[0]);
+
+                       ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[1],
+                                                       AR5K_RF_PWD_90, 1);
+
+                       ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[2],
+                                                       AR5K_RF_PWD_84, 1);
+
+                       ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[3],
+                                               AR5K_RF_RFGAIN_SEL, 1);
+
+                       /* We programmed gain_F parameters, switch back
+                        * to active state */
+                       ah->ah_gain.g_state = AR5K_RFGAIN_ACTIVE;
+
+               }
+
+               /* Bank 6/7 setup */
+
+               ath5k_hw_rfb_op(ah, rf_regs, !ee->ee_xpd[ee_mode],
+                                               AR5K_RF_PWD_XPD, 1);
+
+               ath5k_hw_rfb_op(ah, rf_regs, ee->ee_x_gain[ee_mode],
+                                               AR5K_RF_XPD_GAIN, 1);
+
+               ath5k_hw_rfb_op(ah, rf_regs, ee->ee_i_gain[ee_mode],
+                                               AR5K_RF_GAIN_I, 1);
+
+               ath5k_hw_rfb_op(ah, rf_regs, ee->ee_xpd[ee_mode],
+                                               AR5K_RF_PLO_SEL, 1);
+
+               /* TODO: Half/quarter channel support */
+       }
+
+       if (ah->ah_radio == AR5K_RF5112) {
+
+               /* Set gain_F settings according to current step */
+               if (channel->hw_value & CHANNEL_OFDM) {
+
+                       ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[0],
+                                               AR5K_RF_MIXGAIN_OVR, 1);
+
+                       ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[1],
+                                               AR5K_RF_PWD_138, 1);
+
+                       ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[2],
+                                               AR5K_RF_PWD_137, 1);
+
+                       ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[3],
+                                               AR5K_RF_PWD_136, 1);
+
+                       ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[4],
+                                               AR5K_RF_PWD_132, 1);
+
+                       ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[5],
+                                               AR5K_RF_PWD_131, 1);
+
+                       ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[6],
+                                               AR5K_RF_PWD_130, 1);
+
+                       /* We programmed gain_F parameters, switch back
+                        * to active state */
+                       ah->ah_gain.g_state = AR5K_RFGAIN_ACTIVE;
+               }
+
+               /* Bank 6/7 setup */
+
+               ath5k_hw_rfb_op(ah, rf_regs, ee->ee_xpd[ee_mode],
+                                               AR5K_RF_XPD_SEL, 1);
+
+               if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112A) {
+                       /* Rev. 1 supports only one xpd */
+                       ath5k_hw_rfb_op(ah, rf_regs,
+                                               ee->ee_x_gain[ee_mode],
+                                               AR5K_RF_XPD_GAIN, 1);
+
+               } else {
+                       /* TODO: Set high and low gain bits */
+                       ath5k_hw_rfb_op(ah, rf_regs,
+                                               ee->ee_x_gain[ee_mode],
+                                               AR5K_RF_PD_GAIN_LO, 1);
+                       ath5k_hw_rfb_op(ah, rf_regs,
+                                               ee->ee_x_gain[ee_mode],
+                                               AR5K_RF_PD_GAIN_HI, 1);
+
+                       /* Lower synth voltage on Rev 2 */
+                       ath5k_hw_rfb_op(ah, rf_regs, 2,
+                                       AR5K_RF_HIGH_VC_CP, 1);
+
+                       ath5k_hw_rfb_op(ah, rf_regs, 2,
+                                       AR5K_RF_MID_VC_CP, 1);
+
+                       ath5k_hw_rfb_op(ah, rf_regs, 2,
+                                       AR5K_RF_LOW_VC_CP, 1);
+
+                       ath5k_hw_rfb_op(ah, rf_regs, 2,
+                                       AR5K_RF_PUSH_UP, 1);
+
+                       /* Decrease power consumption on 5213+ BaseBand */
+                       if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
+                               ath5k_hw_rfb_op(ah, rf_regs, 1,
+                                               AR5K_RF_PAD2GND, 1);
+
+                               ath5k_hw_rfb_op(ah, rf_regs, 1,
+                                               AR5K_RF_XB2_LVL, 1);
+
+                               ath5k_hw_rfb_op(ah, rf_regs, 1,
+                                               AR5K_RF_XB5_LVL, 1);
+
+                               ath5k_hw_rfb_op(ah, rf_regs, 1,
+                                               AR5K_RF_PWD_167, 1);
+
+                               ath5k_hw_rfb_op(ah, rf_regs, 1,
+                                               AR5K_RF_PWD_166, 1);
+                       }
+               }
+
+               ath5k_hw_rfb_op(ah, rf_regs, ee->ee_i_gain[ee_mode],
+                                               AR5K_RF_GAIN_I, 1);
+
+               /* TODO: Half/quarter channel support */
+
+       }
+
+       if (ah->ah_radio == AR5K_RF5413 &&
+       channel->hw_value & CHANNEL_2GHZ) {
+
+               ath5k_hw_rfb_op(ah, rf_regs, 1, AR5K_RF_DERBY_CHAN_SEL_MODE,
+                                                                       1);
+
+               /* Set optimum value for early revisions (on pci-e chips) */
+               if (ah->ah_mac_srev >= AR5K_SREV_AR5424 &&
+               ah->ah_mac_srev < AR5K_SREV_AR5413)
+                       ath5k_hw_rfb_op(ah, rf_regs, ath5k_hw_bitswap(6, 3),
+                                               AR5K_RF_PWD_ICLOBUF_2G, 1);
+
+       }
+
+       /* Write RF banks on hw */
+       for (i = 0; i < ah->ah_rf_banks_size; i++) {
+               AR5K_REG_WAIT(i);
+               ath5k_hw_reg_write(ah, rfb[i], ini_rfb[i].rfb_ctrl_register);
+       }
+
+       return 0;
+}
+
+
+/**************************\
+  PHY/RF channel functions
+\**************************/
+
+/*
+ * Check if a channel is supported
+ */
+int ath5k_channel_ok(struct ath5k_hw *ah, u16 freq, unsigned int flags)
+{
+       /* Check if the channel is in our supported range */
+       if (flags & CHANNEL_2GHZ) {
+               if ((freq >= ah->ah_capabilities.cap_range.range_2ghz_min) &&
+                   (freq <= ah->ah_capabilities.cap_range.range_2ghz_max))
+                       return 1;
+       } else if (flags & CHANNEL_5GHZ)
+               if ((freq >= ah->ah_capabilities.cap_range.range_5ghz_min) &&
+                   (freq <= ah->ah_capabilities.cap_range.range_5ghz_max))
+                       return 1;
+
+       return 0;
+}
+
+/*
+ * Convertion needed for RF5110
+ */
+static u32 ath5k_hw_rf5110_chan2athchan(struct net80211_channel *channel)
+{
+       u32 athchan;
+
+       /*
+        * Convert IEEE channel/MHz to an internal channel value used
+        * by the AR5210 chipset. This has not been verified with
+        * newer chipsets like the AR5212A who have a completely
+        * different RF/PHY part.
+        */
+       athchan = (ath5k_hw_bitswap((ath5k_freq_to_channel(channel->center_freq)
+                                    - 24) / 2, 5) << 1)
+               | (1 << 6) | 0x1;
+       return athchan;
+}
+
+/*
+ * Set channel on RF5110
+ */
+static int ath5k_hw_rf5110_channel(struct ath5k_hw *ah,
+               struct net80211_channel *channel)
+{
+       u32 data;
+
+       /*
+        * Set the channel and wait
+        */
+       data = ath5k_hw_rf5110_chan2athchan(channel);
+       ath5k_hw_reg_write(ah, data, AR5K_RF_BUFFER);
+       ath5k_hw_reg_write(ah, 0, AR5K_RF_BUFFER_CONTROL_0);
+       mdelay(1);
+
+       return 0;
+}
+
+/*
+ * Convertion needed for 5111
+ */
+static int ath5k_hw_rf5111_chan2athchan(unsigned int ieee,
+               struct ath5k_athchan_2ghz *athchan)
+{
+       int channel;
+
+       /* Cast this value to catch negative channel numbers (>= -19) */
+       channel = (int)ieee;
+
+       /*
+        * Map 2GHz IEEE channel to 5GHz Atheros channel
+        */
+       if (channel <= 13) {
+               athchan->a2_athchan = 115 + channel;
+               athchan->a2_flags = 0x46;
+       } else if (channel == 14) {
+               athchan->a2_athchan = 124;
+               athchan->a2_flags = 0x44;
+       } else if (channel >= 15 && channel <= 26) {
+               athchan->a2_athchan = ((channel - 14) * 4) + 132;
+               athchan->a2_flags = 0x46;
+       } else
+               return -EINVAL;
+
+       return 0;
+}
+
+/*
+ * Set channel on 5111
+ */
+static int ath5k_hw_rf5111_channel(struct ath5k_hw *ah,
+               struct net80211_channel *channel)
+{
+       struct ath5k_athchan_2ghz ath5k_channel_2ghz;
+       unsigned int ath5k_channel = ath5k_freq_to_channel(channel->center_freq);
+       u32 data0, data1, clock;
+       int ret;
+
+       /*
+        * Set the channel on the RF5111 radio
+        */
+       data0 = data1 = 0;
+
+       if (channel->hw_value & CHANNEL_2GHZ) {
+               /* Map 2GHz channel to 5GHz Atheros channel ID */
+               ret = ath5k_hw_rf5111_chan2athchan(ath5k_channel,
+                                                  &ath5k_channel_2ghz);
+               if (ret)
+                       return ret;
+
+               ath5k_channel = ath5k_channel_2ghz.a2_athchan;
+               data0 = ((ath5k_hw_bitswap(ath5k_channel_2ghz.a2_flags, 8) & 0xff)
+                   << 5) | (1 << 4);
+       }
+
+       if (ath5k_channel < 145 || !(ath5k_channel & 1)) {
+               clock = 1;
+               data1 = ((ath5k_hw_bitswap(ath5k_channel - 24, 8) & 0xff) << 2) |
+                       (clock << 1) | (1 << 10) | 1;
+       } else {
+               clock = 0;
+               data1 = ((ath5k_hw_bitswap((ath5k_channel - 24) / 2, 8) & 0xff)
+                       << 2) | (clock << 1) | (1 << 10) | 1;
+       }
+
+       ath5k_hw_reg_write(ah, (data1 & 0xff) | ((data0 & 0xff) << 8),
+                       AR5K_RF_BUFFER);
+       ath5k_hw_reg_write(ah, ((data1 >> 8) & 0xff) | (data0 & 0xff00),
+                       AR5K_RF_BUFFER_CONTROL_3);
+
+       return 0;
+}
+
+/*
+ * Set channel on 5112 and newer
+ */
+static int ath5k_hw_rf5112_channel(struct ath5k_hw *ah,
+               struct net80211_channel *channel)
+{
+       u32 data, data0, data1, data2;
+       u16 c;
+
+       data = data0 = data1 = data2 = 0;
+       c = channel->center_freq;
+
+       if (c < 4800) {
+               if (!((c - 2224) % 5)) {
+                       data0 = ((2 * (c - 704)) - 3040) / 10;
+                       data1 = 1;
+               } else if (!((c - 2192) % 5)) {
+                       data0 = ((2 * (c - 672)) - 3040) / 10;
+                       data1 = 0;
+               } else
+                       return -EINVAL;
+
+               data0 = ath5k_hw_bitswap((data0 << 2) & 0xff, 8);
+       } else if ((c - (c % 5)) != 2 || c > 5435) {
+               if (!(c % 20) && c >= 5120) {
+                       data0 = ath5k_hw_bitswap(((c - 4800) / 20 << 2), 8);
+                       data2 = ath5k_hw_bitswap(3, 2);
+               } else if (!(c % 10)) {
+                       data0 = ath5k_hw_bitswap(((c - 4800) / 10 << 1), 8);
+                       data2 = ath5k_hw_bitswap(2, 2);
+               } else if (!(c % 5)) {
+                       data0 = ath5k_hw_bitswap((c - 4800) / 5, 8);
+                       data2 = ath5k_hw_bitswap(1, 2);
+               } else
+                       return -EINVAL;
+       } else {
+               data0 = ath5k_hw_bitswap((10 * (c - 2) - 4800) / 25 + 1, 8);
+               data2 = ath5k_hw_bitswap(0, 2);
+       }
+
+       data = (data0 << 4) | (data1 << 1) | (data2 << 2) | 0x1001;
+
+       ath5k_hw_reg_write(ah, data & 0xff, AR5K_RF_BUFFER);
+       ath5k_hw_reg_write(ah, (data >> 8) & 0x7f, AR5K_RF_BUFFER_CONTROL_5);
+
+       return 0;
+}
+
+/*
+ * Set the channel on the RF2425
+ */
+static int ath5k_hw_rf2425_channel(struct ath5k_hw *ah,
+               struct net80211_channel *channel)
+{
+       u32 data, data0, data2;
+       u16 c;
+
+       data = data0 = data2 = 0;
+       c = channel->center_freq;
+
+       if (c < 4800) {
+               data0 = ath5k_hw_bitswap((c - 2272), 8);
+               data2 = 0;
+       /* ? 5GHz ? */
+       } else if ((c - (c % 5)) != 2 || c > 5435) {
+               if (!(c % 20) && c < 5120)
+                       data0 = ath5k_hw_bitswap(((c - 4800) / 20 << 2), 8);
+               else if (!(c % 10))
+                       data0 = ath5k_hw_bitswap(((c - 4800) / 10 << 1), 8);
+               else if (!(c % 5))
+                       data0 = ath5k_hw_bitswap((c - 4800) / 5, 8);
+               else
+                       return -EINVAL;
+               data2 = ath5k_hw_bitswap(1, 2);
+       } else {
+               data0 = ath5k_hw_bitswap((10 * (c - 2) - 4800) / 25 + 1, 8);
+               data2 = ath5k_hw_bitswap(0, 2);
+       }
+
+       data = (data0 << 4) | data2 << 2 | 0x1001;
+
+       ath5k_hw_reg_write(ah, data & 0xff, AR5K_RF_BUFFER);
+       ath5k_hw_reg_write(ah, (data >> 8) & 0x7f, AR5K_RF_BUFFER_CONTROL_5);
+
+       return 0;
+}
+
+/*
+ * Set a channel on the radio chip
+ */
+int ath5k_hw_channel(struct ath5k_hw *ah, struct net80211_channel *channel)
+{
+       int ret;
+       /*
+        * Check bounds supported by the PHY (we don't care about regultory
+        * restrictions at this point). Note: hw_value already has the band
+        * (CHANNEL_2GHZ, or CHANNEL_5GHZ) so we inform ath5k_channel_ok()
+        * of the band by that */
+       if (!ath5k_channel_ok(ah, channel->center_freq, channel->hw_value)) {
+               DBG("ath5k: channel frequency (%d MHz) out of supported "
+                   "range\n", channel->center_freq);
+               return -EINVAL;
+       }
+
+       /*
+        * Set the channel and wait
+        */
+       switch (ah->ah_radio) {
+       case AR5K_RF5110:
+               ret = ath5k_hw_rf5110_channel(ah, channel);
+               break;
+       case AR5K_RF5111:
+               ret = ath5k_hw_rf5111_channel(ah, channel);
+               break;
+       case AR5K_RF2425:
+               ret = ath5k_hw_rf2425_channel(ah, channel);
+               break;
+       default:
+               ret = ath5k_hw_rf5112_channel(ah, channel);
+               break;
+       }
+
+       if (ret) {
+               DBG("ath5k: setting channel failed: %s\n", strerror(ret));
+               return ret;
+       }
+
+       /* Set JAPAN setting for channel 14 */
+       if (channel->center_freq == 2484) {
+               AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_CCKTXCTL,
+                               AR5K_PHY_CCKTXCTL_JAPAN);
+       } else {
+               AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_CCKTXCTL,
+                               AR5K_PHY_CCKTXCTL_WORLD);
+       }
+
+       ah->ah_current_channel = channel;
+       ah->ah_turbo = (channel->hw_value == CHANNEL_T ? 1 : 0);
+
+       return 0;
+}
+
+/*****************\
+  PHY calibration
+\*****************/
+
+/**
+ * ath5k_hw_noise_floor_calibration - perform PHY noise floor calibration
+ *
+ * @ah: struct ath5k_hw pointer we are operating on
+ * @freq: the channel frequency, just used for error logging
+ *
+ * This function performs a noise floor calibration of the PHY and waits for
+ * it to complete. Then the noise floor value is compared to some maximum
+ * noise floor we consider valid.
+ *
+ * Note that this is different from what the madwifi HAL does: it reads the
+ * noise floor and afterwards initiates the calibration. Since the noise floor
+ * calibration can take some time to finish, depending on the current channel
+ * use, that avoids the occasional timeout warnings we are seeing now.
+ *
+ * See the following link for an Atheros patent on noise floor calibration:
+ * http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&Sect2=HITOFF&d=PALL \
+ * &p=1&u=%2Fnetahtml%2FPTO%2Fsrchnum.htm&r=1&f=G&l=50&s1=7245893.PN.&OS=PN/7
+ *
+ * XXX: Since during noise floor calibration antennas are detached according to
+ * the patent, we should stop tx queues here.
+ */
+int
+ath5k_hw_noise_floor_calibration(struct ath5k_hw *ah, short freq)
+{
+       int ret;
+       unsigned int i;
+       s32 noise_floor;
+
+       /*
+        * Enable noise floor calibration
+        */
+       AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
+                               AR5K_PHY_AGCCTL_NF);
+
+       ret = ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
+                       AR5K_PHY_AGCCTL_NF, 0, 0);
+
+       if (ret) {
+               DBG("ath5k: noise floor calibration timeout (%d MHz)\n", freq);
+               return -EAGAIN;
+       }
+
+       /* Wait until the noise floor is calibrated and read the value */
+       for (i = 20; i > 0; i--) {
+               mdelay(1);
+               noise_floor = ath5k_hw_reg_read(ah, AR5K_PHY_NF);
+               noise_floor = AR5K_PHY_NF_RVAL(noise_floor);
+               if (noise_floor & AR5K_PHY_NF_ACTIVE) {
+                       noise_floor = AR5K_PHY_NF_AVAL(noise_floor);
+
+                       if (noise_floor <= AR5K_TUNE_NOISE_FLOOR)
+                               break;
+               }
+       }
+
+       DBG2("ath5k: noise floor %d\n", noise_floor);
+
+       if (noise_floor > AR5K_TUNE_NOISE_FLOOR) {
+               DBG("ath5k: noise floor calibration failed (%d MHz)\n", freq);
+               return -EAGAIN;
+       }
+
+       ah->ah_noise_floor = noise_floor;
+
+       return 0;
+}
+
+/*
+ * Perform a PHY calibration on RF5110
+ * -Fix BPSK/QAM Constellation (I/Q correction)
+ * -Calculate Noise Floor
+ */
+static int ath5k_hw_rf5110_calibrate(struct ath5k_hw *ah,
+               struct net80211_channel *channel)
+{
+       u32 phy_sig, phy_agc, phy_sat, beacon;
+       int ret;
+
+       /*
+        * Disable beacons and RX/TX queues, wait
+        */
+       AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW_5210,
+               AR5K_DIAG_SW_DIS_TX | AR5K_DIAG_SW_DIS_RX_5210);
+       beacon = ath5k_hw_reg_read(ah, AR5K_BEACON_5210);
+       ath5k_hw_reg_write(ah, beacon & ~AR5K_BEACON_ENABLE, AR5K_BEACON_5210);
+
+       mdelay(2);
+
+       /*
+        * Set the channel (with AGC turned off)
+        */
+       AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGC, AR5K_PHY_AGC_DISABLE);
+       udelay(10);
+       ret = ath5k_hw_channel(ah, channel);
+
+       /*
+        * Activate PHY and wait
+        */
+       ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
+       mdelay(1);
+
+       AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_AGC, AR5K_PHY_AGC_DISABLE);
+
+       if (ret)
+               return ret;
+
+       /*
+        * Calibrate the radio chip
+        */
+
+       /* Remember normal state */
+       phy_sig = ath5k_hw_reg_read(ah, AR5K_PHY_SIG);
+       phy_agc = ath5k_hw_reg_read(ah, AR5K_PHY_AGCCOARSE);
+       phy_sat = ath5k_hw_reg_read(ah, AR5K_PHY_ADCSAT);
+
+       /* Update radio registers */
+       ath5k_hw_reg_write(ah, (phy_sig & ~(AR5K_PHY_SIG_FIRPWR)) |
+               AR5K_REG_SM(-1, AR5K_PHY_SIG_FIRPWR), AR5K_PHY_SIG);
+
+       ath5k_hw_reg_write(ah, (phy_agc & ~(AR5K_PHY_AGCCOARSE_HI |
+                       AR5K_PHY_AGCCOARSE_LO)) |
+               AR5K_REG_SM(-1, AR5K_PHY_AGCCOARSE_HI) |
+               AR5K_REG_SM(-127, AR5K_PHY_AGCCOARSE_LO), AR5K_PHY_AGCCOARSE);
+
+       ath5k_hw_reg_write(ah, (phy_sat & ~(AR5K_PHY_ADCSAT_ICNT |
+                       AR5K_PHY_ADCSAT_THR)) |
+               AR5K_REG_SM(2, AR5K_PHY_ADCSAT_ICNT) |
+               AR5K_REG_SM(12, AR5K_PHY_ADCSAT_THR), AR5K_PHY_ADCSAT);
+
+       udelay(20);
+
+       AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGC, AR5K_PHY_AGC_DISABLE);
+       udelay(10);
+       ath5k_hw_reg_write(ah, AR5K_PHY_RFSTG_DISABLE, AR5K_PHY_RFSTG);
+       AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_AGC, AR5K_PHY_AGC_DISABLE);
+
+       mdelay(1);
+
+       /*
+        * Enable calibration and wait until completion
+        */
+       AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL, AR5K_PHY_AGCCTL_CAL);
+
+       ret = ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
+                       AR5K_PHY_AGCCTL_CAL, 0, 0);
+
+       /* Reset to normal state */
+       ath5k_hw_reg_write(ah, phy_sig, AR5K_PHY_SIG);
+       ath5k_hw_reg_write(ah, phy_agc, AR5K_PHY_AGCCOARSE);
+       ath5k_hw_reg_write(ah, phy_sat, AR5K_PHY_ADCSAT);
+
+       if (ret) {
+               DBG("ath5k: calibration timeout (%d MHz)\n",
+                   channel->center_freq);
+               return ret;
+       }
+
+       ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
+
+       /*
+        * Re-enable RX/TX and beacons
+        */
+       AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW_5210,
+               AR5K_DIAG_SW_DIS_TX | AR5K_DIAG_SW_DIS_RX_5210);
+       ath5k_hw_reg_write(ah, beacon, AR5K_BEACON_5210);
+
+       return 0;
+}
+
+/*
+ * Perform a PHY calibration on RF5111/5112 and newer chips
+ */
+static int ath5k_hw_rf511x_calibrate(struct ath5k_hw *ah,
+               struct net80211_channel *channel)
+{
+       u32 i_pwr, q_pwr;
+       s32 iq_corr, i_coff, i_coffd, q_coff, q_coffd;
+       int i;
+
+       if (!ah->ah_calibration ||
+               ath5k_hw_reg_read(ah, AR5K_PHY_IQ) & AR5K_PHY_IQ_RUN)
+               goto done;
+
+       /* Calibration has finished, get the results and re-run */
+       for (i = 0; i <= 10; i++) {
+               iq_corr = ath5k_hw_reg_read(ah, AR5K_PHY_IQRES_CAL_CORR);
+               i_pwr = ath5k_hw_reg_read(ah, AR5K_PHY_IQRES_CAL_PWR_I);
+               q_pwr = ath5k_hw_reg_read(ah, AR5K_PHY_IQRES_CAL_PWR_Q);
+       }
+
+       i_coffd = ((i_pwr >> 1) + (q_pwr >> 1)) >> 7;
+       q_coffd = q_pwr >> 7;
+
+       /* No correction */
+       if (i_coffd == 0 || q_coffd == 0)
+               goto done;
+
+       i_coff = ((-iq_corr) / i_coffd) & 0x3f;
+
+       /* Boundary check */
+       if (i_coff > 31)
+               i_coff = 31;
+       if (i_coff < -32)
+               i_coff = -32;
+
+       q_coff = (((s32)i_pwr / q_coffd) - 128) & 0x1f;
+
+       /* Boundary check */
+       if (q_coff > 15)
+               q_coff = 15;
+       if (q_coff < -16)
+               q_coff = -16;
+
+       /* Commit new I/Q value */
+       AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ, AR5K_PHY_IQ_CORR_ENABLE |
+               ((u32)q_coff) | ((u32)i_coff << AR5K_PHY_IQ_CORR_Q_I_COFF_S));
+
+       /* Re-enable calibration -if we don't we'll commit
+        * the same values again and again */
+       AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
+                       AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
+       AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ, AR5K_PHY_IQ_RUN);
+
+done:
+
+       /* TODO: Separate noise floor calibration from I/Q calibration
+        * since noise floor calibration interrupts rx path while I/Q
+        * calibration doesn't. We don't need to run noise floor calibration
+        * as often as I/Q calibration.*/
+       ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
+
+       /* Initiate a gain_F calibration */
+       ath5k_hw_request_rfgain_probe(ah);
+
+       return 0;
+}
+
+/*
+ * Perform a PHY calibration
+ */
+int ath5k_hw_phy_calibrate(struct ath5k_hw *ah,
+               struct net80211_channel *channel)
+{
+       int ret;
+
+       if (ah->ah_radio == AR5K_RF5110)
+               ret = ath5k_hw_rf5110_calibrate(ah, channel);
+       else
+               ret = ath5k_hw_rf511x_calibrate(ah, channel);
+
+       return ret;
+}
+
+int ath5k_hw_phy_disable(struct ath5k_hw *ah)
+{
+       ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
+
+       return 0;
+}
+
+/********************\
+  Misc PHY functions
+\********************/
+
+/*
+ * Get the PHY Chip revision
+ */
+u16 ath5k_hw_radio_revision(struct ath5k_hw *ah, unsigned int chan)
+{
+       unsigned int i;
+       u32 srev;
+       u16 ret;
+
+       /*
+        * Set the radio chip access register
+        */
+       switch (chan) {
+       case CHANNEL_2GHZ:
+               ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_2GHZ, AR5K_PHY(0));
+               break;
+       case CHANNEL_5GHZ:
+               ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
+               break;
+       default:
+               return 0;
+       }
+
+       mdelay(2);
+
+       /* ...wait until PHY is ready and read the selected radio revision */
+       ath5k_hw_reg_write(ah, 0x00001c16, AR5K_PHY(0x34));
+
+       for (i = 0; i < 8; i++)
+               ath5k_hw_reg_write(ah, 0x00010000, AR5K_PHY(0x20));
+
+       if (ah->ah_version == AR5K_AR5210) {
+               srev = ath5k_hw_reg_read(ah, AR5K_PHY(256) >> 28) & 0xf;
+               ret = (u16)ath5k_hw_bitswap(srev, 4) + 1;
+       } else {
+               srev = (ath5k_hw_reg_read(ah, AR5K_PHY(0x100)) >> 24) & 0xff;
+               ret = (u16)ath5k_hw_bitswap(((srev & 0xf0) >> 4) |
+                               ((srev & 0x0f) << 4), 8);
+       }
+
+       /* Reset to the 5GHz mode */
+       ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
+
+       return ret;
+}
+
+void /*TODO:Boundary check*/
+ath5k_hw_set_def_antenna(struct ath5k_hw *ah, unsigned int ant)
+{
+       if (ah->ah_version != AR5K_AR5210)
+               ath5k_hw_reg_write(ah, ant, AR5K_DEFAULT_ANTENNA);
+}
+
+unsigned int ath5k_hw_get_def_antenna(struct ath5k_hw *ah)
+{
+       if (ah->ah_version != AR5K_AR5210)
+               return ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
+
+       return 0; /*XXX: What do we return for 5210 ?*/
+}
+
+
+/****************\
+* TX power setup *
+\****************/
+
+/*
+ * Helper functions
+ */
+
+/*
+ * Do linear interpolation between two given (x, y) points
+ */
+static s16
+ath5k_get_interpolated_value(s16 target, s16 x_left, s16 x_right,
+                                       s16 y_left, s16 y_right)
+{
+       s16 ratio, result;
+
+       /* Avoid divide by zero and skip interpolation
+        * if we have the same point */
+       if ((x_left == x_right) || (y_left == y_right))
+               return y_left;
+
+       /*
+        * Since we use ints and not fps, we need to scale up in
+        * order to get a sane ratio value (or else we 'll eg. get
+        * always 1 instead of 1.25, 1.75 etc). We scale up by 100
+        * to have some accuracy both for 0.5 and 0.25 steps.
+        */
+       ratio = ((100 * y_right - 100 * y_left)/(x_right - x_left));
+
+       /* Now scale down to be in range */
+       result = y_left + (ratio * (target - x_left) / 100);
+
+       return result;
+}
+
+/*
+ * Find vertical boundary (min pwr) for the linear PCDAC curve.
+ *
+ * Since we have the top of the curve and we draw the line below
+ * until we reach 1 (1 pcdac step) we need to know which point
+ * (x value) that is so that we don't go below y axis and have negative
+ * pcdac values when creating the curve, or fill the table with zeroes.
+ */
+static s16
+ath5k_get_linear_pcdac_min(const u8 *stepL, const u8 *stepR,
+                               const s16 *pwrL, const s16 *pwrR)
+{
+       s8 tmp;
+       s16 min_pwrL, min_pwrR;
+       s16 pwr_i;
+
+       if (pwrL[0] == pwrL[1])
+               min_pwrL = pwrL[0];
+       else {
+               pwr_i = pwrL[0];
+               do {
+                       pwr_i--;
+                       tmp = (s8) ath5k_get_interpolated_value(pwr_i,
+                                                       pwrL[0], pwrL[1],
+                                                       stepL[0], stepL[1]);
+               } while (tmp > 1);
+
+               min_pwrL = pwr_i;
+       }
+
+       if (pwrR[0] == pwrR[1])
+               min_pwrR = pwrR[0];
+       else {
+               pwr_i = pwrR[0];
+               do {
+                       pwr_i--;
+                       tmp = (s8) ath5k_get_interpolated_value(pwr_i,
+                                                       pwrR[0], pwrR[1],
+                                                       stepR[0], stepR[1]);
+               } while (tmp > 1);
+
+               min_pwrR = pwr_i;
+       }
+
+       /* Keep the right boundary so that it works for both curves */
+       return max(min_pwrL, min_pwrR);
+}
+
+/*
+ * Interpolate (pwr,vpd) points to create a Power to PDADC or a
+ * Power to PCDAC curve.
+ *
+ * Each curve has power on x axis (in 0.5dB units) and PCDAC/PDADC
+ * steps (offsets) on y axis. Power can go up to 31.5dB and max
+ * PCDAC/PDADC step for each curve is 64 but we can write more than
+ * one curves on hw so we can go up to 128 (which is the max step we
+ * can write on the final table).
+ *
+ * We write y values (PCDAC/PDADC steps) on hw.
+ */
+static void
+ath5k_create_power_curve(s16 pmin, s16 pmax,
+                       const s16 *pwr, const u8 *vpd,
+                       u8 num_points,
+                       u8 *vpd_table, u8 type)
+{
+       u8 idx[2] = { 0, 1 };
+       s16 pwr_i = 2*pmin;
+       int i;
+
+       if (num_points < 2)
+               return;
+
+       /* We want the whole line, so adjust boundaries
+        * to cover the entire power range. Note that
+        * power values are already 0.25dB so no need
+        * to multiply pwr_i by 2 */
+       if (type == AR5K_PWRTABLE_LINEAR_PCDAC) {
+               pwr_i = pmin;
+               pmin = 0;
+               pmax = 63;
+       }
+
+       /* Find surrounding turning points (TPs)
+        * and interpolate between them */
+       for (i = 0; (i <= (u16) (pmax - pmin)) &&
+       (i < AR5K_EEPROM_POWER_TABLE_SIZE); i++) {
+
+               /* We passed the right TP, move to the next set of TPs
+                * if we pass the last TP, extrapolate above using the last
+                * two TPs for ratio */
+               if ((pwr_i > pwr[idx[1]]) && (idx[1] < num_points - 1)) {
+                       idx[0]++;
+                       idx[1]++;
+               }
+
+               vpd_table[i] = (u8) ath5k_get_interpolated_value(pwr_i,
+                                               pwr[idx[0]], pwr[idx[1]],
+                                               vpd[idx[0]], vpd[idx[1]]);
+
+               /* Increase by 0.5dB
+                * (0.25 dB units) */
+               pwr_i += 2;
+       }
+}
+
+/*
+ * Get the surrounding per-channel power calibration piers
+ * for a given frequency so that we can interpolate between
+ * them and come up with an apropriate dataset for our current
+ * channel.
+ */
+static void
+ath5k_get_chan_pcal_surrounding_piers(struct ath5k_hw *ah,
+                       struct net80211_channel *channel,
+                       struct ath5k_chan_pcal_info **pcinfo_l,
+                       struct ath5k_chan_pcal_info **pcinfo_r)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       struct ath5k_chan_pcal_info *pcinfo;
+       u8 idx_l, idx_r;
+       u8 mode, max, i;
+       u32 target = channel->center_freq;
+
+       idx_l = 0;
+       idx_r = 0;
+
+       if (!(channel->hw_value & CHANNEL_OFDM)) {
+               pcinfo = ee->ee_pwr_cal_b;
+               mode = AR5K_EEPROM_MODE_11B;
+       } else if (channel->hw_value & CHANNEL_2GHZ) {
+               pcinfo = ee->ee_pwr_cal_g;
+               mode = AR5K_EEPROM_MODE_11G;
+       } else {
+               pcinfo = ee->ee_pwr_cal_a;
+               mode = AR5K_EEPROM_MODE_11A;
+       }
+       max = ee->ee_n_piers[mode] - 1;
+
+       /* Frequency is below our calibrated
+        * range. Use the lowest power curve
+        * we have */
+       if (target < pcinfo[0].freq) {
+               idx_l = idx_r = 0;
+               goto done;
+       }
+
+       /* Frequency is above our calibrated
+        * range. Use the highest power curve
+        * we have */
+       if (target > pcinfo[max].freq) {
+               idx_l = idx_r = max;
+               goto done;
+       }
+
+       /* Frequency is inside our calibrated
+        * channel range. Pick the surrounding
+        * calibration piers so that we can
+        * interpolate */
+       for (i = 0; i <= max; i++) {
+
+               /* Frequency matches one of our calibration
+                * piers, no need to interpolate, just use
+                * that calibration pier */
+               if (pcinfo[i].freq == target) {
+                       idx_l = idx_r = i;
+                       goto done;
+               }
+
+               /* We found a calibration pier that's above
+                * frequency, use this pier and the previous
+                * one to interpolate */
+               if (target < pcinfo[i].freq) {
+                       idx_r = i;
+                       idx_l = idx_r - 1;
+                       goto done;
+               }
+       }
+
+done:
+       *pcinfo_l = &pcinfo[idx_l];
+       *pcinfo_r = &pcinfo[idx_r];
+
+       return;
+}
+
+/*
+ * Get the surrounding per-rate power calibration data
+ * for a given frequency and interpolate between power
+ * values to set max target power supported by hw for
+ * each rate.
+ */
+static void
+ath5k_get_rate_pcal_data(struct ath5k_hw *ah,
+                       struct net80211_channel *channel,
+                       struct ath5k_rate_pcal_info *rates)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       struct ath5k_rate_pcal_info *rpinfo;
+       u8 idx_l, idx_r;
+       u8 mode, max, i;
+       u32 target = channel->center_freq;
+
+       idx_l = 0;
+       idx_r = 0;
+
+       if (!(channel->hw_value & CHANNEL_OFDM)) {
+               rpinfo = ee->ee_rate_tpwr_b;
+               mode = AR5K_EEPROM_MODE_11B;
+       } else if (channel->hw_value & CHANNEL_2GHZ) {
+               rpinfo = ee->ee_rate_tpwr_g;
+               mode = AR5K_EEPROM_MODE_11G;
+       } else {
+               rpinfo = ee->ee_rate_tpwr_a;
+               mode = AR5K_EEPROM_MODE_11A;
+       }
+       max = ee->ee_rate_target_pwr_num[mode] - 1;
+
+       /* Get the surrounding calibration
+        * piers - same as above */
+       if (target < rpinfo[0].freq) {
+               idx_l = idx_r = 0;
+               goto done;
+       }
+
+       if (target > rpinfo[max].freq) {
+               idx_l = idx_r = max;
+               goto done;
+       }
+
+       for (i = 0; i <= max; i++) {
+
+               if (rpinfo[i].freq == target) {
+                       idx_l = idx_r = i;
+                       goto done;
+               }
+
+               if (target < rpinfo[i].freq) {
+                       idx_r = i;
+                       idx_l = idx_r - 1;
+                       goto done;
+               }
+       }
+
+done:
+       /* Now interpolate power value, based on the frequency */
+       rates->freq = target;
+
+       rates->target_power_6to24 =
+               ath5k_get_interpolated_value(target, rpinfo[idx_l].freq,
+                                       rpinfo[idx_r].freq,
+                                       rpinfo[idx_l].target_power_6to24,
+                                       rpinfo[idx_r].target_power_6to24);
+
+       rates->target_power_36 =
+               ath5k_get_interpolated_value(target, rpinfo[idx_l].freq,
+                                       rpinfo[idx_r].freq,
+                                       rpinfo[idx_l].target_power_36,
+                                       rpinfo[idx_r].target_power_36);
+
+       rates->target_power_48 =
+               ath5k_get_interpolated_value(target, rpinfo[idx_l].freq,
+                                       rpinfo[idx_r].freq,
+                                       rpinfo[idx_l].target_power_48,
+                                       rpinfo[idx_r].target_power_48);
+
+       rates->target_power_54 =
+               ath5k_get_interpolated_value(target, rpinfo[idx_l].freq,
+                                       rpinfo[idx_r].freq,
+                                       rpinfo[idx_l].target_power_54,
+                                       rpinfo[idx_r].target_power_54);
+}
+
+/*
+ * Get the max edge power for this channel if
+ * we have such data from EEPROM's Conformance Test
+ * Limits (CTL), and limit max power if needed.
+ *
+ * FIXME: Only works for world regulatory domains
+ */
+static void
+ath5k_get_max_ctl_power(struct ath5k_hw *ah,
+                       struct net80211_channel *channel)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       struct ath5k_edge_power *rep = ee->ee_ctl_pwr;
+       u8 *ctl_val = ee->ee_ctl;
+       s16 max_chan_pwr = ah->ah_txpower.txp_max_pwr / 4;
+       s16 edge_pwr = 0;
+       u8 rep_idx;
+       u8 i, ctl_mode;
+       u8 ctl_idx = 0xFF;
+       u32 target = channel->center_freq;
+
+       /* Find out a CTL for our mode that's not mapped
+        * on a specific reg domain.
+        *
+        * TODO: Map our current reg domain to one of the 3 available
+        * reg domain ids so that we can support more CTLs. */
+       switch (channel->hw_value & CHANNEL_MODES) {
+       case CHANNEL_A:
+               ctl_mode = AR5K_CTL_11A | AR5K_CTL_NO_REGDOMAIN;
+               break;
+       case CHANNEL_G:
+               ctl_mode = AR5K_CTL_11G | AR5K_CTL_NO_REGDOMAIN;
+               break;
+       case CHANNEL_B:
+               ctl_mode = AR5K_CTL_11B | AR5K_CTL_NO_REGDOMAIN;
+               break;
+       case CHANNEL_T:
+               ctl_mode = AR5K_CTL_TURBO | AR5K_CTL_NO_REGDOMAIN;
+               break;
+       case CHANNEL_TG:
+               ctl_mode = AR5K_CTL_TURBOG | AR5K_CTL_NO_REGDOMAIN;
+               break;
+       case CHANNEL_XR:
+               /* Fall through */
+       default:
+               return;
+       }
+
+       for (i = 0; i < ee->ee_ctls; i++) {
+               if (ctl_val[i] == ctl_mode) {
+                       ctl_idx = i;
+                       break;
+               }
+       }
+
+       /* If we have a CTL dataset available grab it and find the
+        * edge power for our frequency */
+       if (ctl_idx == 0xFF)
+               return;
+
+       /* Edge powers are sorted by frequency from lower
+        * to higher. Each CTL corresponds to 8 edge power
+        * measurements. */
+       rep_idx = ctl_idx * AR5K_EEPROM_N_EDGES;
+
+       /* Don't do boundaries check because we
+        * might have more that one bands defined
+        * for this mode */
+
+       /* Get the edge power that's closer to our
+        * frequency */
+       for (i = 0; i < AR5K_EEPROM_N_EDGES; i++) {
+               rep_idx += i;
+               if (target <= rep[rep_idx].freq)
+                       edge_pwr = (s16) rep[rep_idx].edge;
+       }
+
+       if (edge_pwr) {
+               ah->ah_txpower.txp_max_pwr = 4*min(edge_pwr, max_chan_pwr);
+       }
+}
+
+
+/*
+ * Power to PCDAC table functions
+ */
+
+/*
+ * Fill Power to PCDAC table on RF5111
+ *
+ * No further processing is needed for RF5111, the only thing we have to
+ * do is fill the values below and above calibration range since eeprom data
+ * may not cover the entire PCDAC table.
+ */
+static void
+ath5k_fill_pwr_to_pcdac_table(struct ath5k_hw *ah, s16* table_min,
+                                                       s16 *table_max)
+{
+       u8      *pcdac_out = ah->ah_txpower.txp_pd_table;
+       u8      *pcdac_tmp = ah->ah_txpower.tmpL[0];
+       u8      pcdac_0, pcdac_n, pcdac_i, pwr_idx, i;
+       s16     min_pwr, max_pwr;
+
+       /* Get table boundaries */
+       min_pwr = table_min[0];
+       pcdac_0 = pcdac_tmp[0];
+
+       max_pwr = table_max[0];
+       pcdac_n = pcdac_tmp[table_max[0] - table_min[0]];
+
+       /* Extrapolate below minimum using pcdac_0 */
+       pcdac_i = 0;
+       for (i = 0; i < min_pwr; i++)
+               pcdac_out[pcdac_i++] = pcdac_0;
+
+       /* Copy values from pcdac_tmp */
+       pwr_idx = min_pwr;
+       for (i = 0 ; pwr_idx <= max_pwr &&
+       pcdac_i < AR5K_EEPROM_POWER_TABLE_SIZE; i++) {
+               pcdac_out[pcdac_i++] = pcdac_tmp[i];
+               pwr_idx++;
+       }
+
+       /* Extrapolate above maximum */
+       while (pcdac_i < AR5K_EEPROM_POWER_TABLE_SIZE)
+               pcdac_out[pcdac_i++] = pcdac_n;
+
+}
+
+/*
+ * Combine available XPD Curves and fill Linear Power to PCDAC table
+ * on RF5112
+ *
+ * RFX112 can have up to 2 curves (one for low txpower range and one for
+ * higher txpower range). We need to put them both on pcdac_out and place
+ * them in the correct location. In case we only have one curve available
+ * just fit it on pcdac_out (it's supposed to cover the entire range of
+ * available pwr levels since it's always the higher power curve). Extrapolate
+ * below and above final table if needed.
+ */
+static void
+ath5k_combine_linear_pcdac_curves(struct ath5k_hw *ah, s16* table_min,
+                                               s16 *table_max, u8 pdcurves)
+{
+       u8      *pcdac_out = ah->ah_txpower.txp_pd_table;
+       u8      *pcdac_low_pwr;
+       u8      *pcdac_high_pwr;
+       u8      *pcdac_tmp;
+       u8      pwr;
+       s16     max_pwr_idx;
+       s16     min_pwr_idx;
+       s16     mid_pwr_idx = 0;
+       /* Edge flag turs on the 7nth bit on the PCDAC
+        * to delcare the higher power curve (force values
+        * to be greater than 64). If we only have one curve
+        * we don't need to set this, if we have 2 curves and
+        * fill the table backwards this can also be used to
+        * switch from higher power curve to lower power curve */
+       u8      edge_flag;
+       int     i;
+
+       /* When we have only one curve available
+        * that's the higher power curve. If we have
+        * two curves the first is the high power curve
+        * and the next is the low power curve. */
+       if (pdcurves > 1) {
+               pcdac_low_pwr = ah->ah_txpower.tmpL[1];
+               pcdac_high_pwr = ah->ah_txpower.tmpL[0];
+               mid_pwr_idx = table_max[1] - table_min[1] - 1;
+               max_pwr_idx = (table_max[0] - table_min[0]) / 2;
+
+               /* If table size goes beyond 31.5dB, keep the
+                * upper 31.5dB range when setting tx power.
+                * Note: 126 = 31.5 dB in quarter dB steps */
+               if (table_max[0] - table_min[1] > 126)
+                       min_pwr_idx = table_max[0] - 126;
+               else
+                       min_pwr_idx = table_min[1];
+
+               /* Since we fill table backwards
+                * start from high power curve */
+               pcdac_tmp = pcdac_high_pwr;
+
+               edge_flag = 0x40;
+       } else {
+               pcdac_low_pwr = ah->ah_txpower.tmpL[1]; /* Zeroed */
+               pcdac_high_pwr = ah->ah_txpower.tmpL[0];
+               min_pwr_idx = table_min[0];
+               max_pwr_idx = (table_max[0] - table_min[0]) / 2;
+               pcdac_tmp = pcdac_high_pwr;
+               edge_flag = 0;
+       }
+
+       /* This is used when setting tx power*/
+       ah->ah_txpower.txp_min_idx = min_pwr_idx/2;
+
+       /* Fill Power to PCDAC table backwards */
+       pwr = max_pwr_idx;
+       for (i = 63; i >= 0; i--) {
+               /* Entering lower power range, reset
+                * edge flag and set pcdac_tmp to lower
+                * power curve.*/
+               if (edge_flag == 0x40 &&
+               (2*pwr <= (table_max[1] - table_min[0]) || pwr == 0)) {
+                       edge_flag = 0x00;
+                       pcdac_tmp = pcdac_low_pwr;
+                       pwr = mid_pwr_idx/2;
+               }
+
+               /* Don't go below 1, extrapolate below if we have
+                * already swithced to the lower power curve -or
+                * we only have one curve and edge_flag is zero
+                * anyway */
+               if (pcdac_tmp[pwr] < 1 && (edge_flag == 0x00)) {
+                       while (i >= 0) {
+                               pcdac_out[i] = pcdac_out[i + 1];
+                               i--;
+                       }
+                       break;
+               }
+
+               pcdac_out[i] = pcdac_tmp[pwr] | edge_flag;
+
+               /* Extrapolate above if pcdac is greater than
+                * 126 -this can happen because we OR pcdac_out
+                * value with edge_flag on high power curve */
+               if (pcdac_out[i] > 126)
+                       pcdac_out[i] = 126;
+
+               /* Decrease by a 0.5dB step */
+               pwr--;
+       }
+}
+
+/* Write PCDAC values on hw */
+static void
+ath5k_setup_pcdac_table(struct ath5k_hw *ah)
+{
+       u8      *pcdac_out = ah->ah_txpower.txp_pd_table;
+       int     i;
+
+       /*
+        * Write TX power values
+        */
+       for (i = 0; i < (AR5K_EEPROM_POWER_TABLE_SIZE / 2); i++) {
+               ath5k_hw_reg_write(ah,
+                       (((pcdac_out[2*i + 0] << 8 | 0xff) & 0xffff) << 0) |
+                       (((pcdac_out[2*i + 1] << 8 | 0xff) & 0xffff) << 16),
+                       AR5K_PHY_PCDAC_TXPOWER(i));
+       }
+}
+
+
+/*
+ * Power to PDADC table functions
+ */
+
+/*
+ * Set the gain boundaries and create final Power to PDADC table
+ *
+ * We can have up to 4 pd curves, we need to do a simmilar process
+ * as we do for RF5112. This time we don't have an edge_flag but we
+ * set the gain boundaries on a separate register.
+ */
+static void
+ath5k_combine_pwr_to_pdadc_curves(struct ath5k_hw *ah,
+                       s16 *pwr_min, s16 *pwr_max, u8 pdcurves)
+{
+       u8 gain_boundaries[AR5K_EEPROM_N_PD_GAINS];
+       u8 *pdadc_out = ah->ah_txpower.txp_pd_table;
+       u8 *pdadc_tmp;
+       s16 pdadc_0;
+       u8 pdadc_i, pdadc_n, pwr_step, pdg, max_idx, table_size;
+       u8 pd_gain_overlap;
+
+       /* Note: Register value is initialized on initvals
+        * there is no feedback from hw.
+        * XXX: What about pd_gain_overlap from EEPROM ? */
+       pd_gain_overlap = (u8) ath5k_hw_reg_read(ah, AR5K_PHY_TPC_RG5) &
+               AR5K_PHY_TPC_RG5_PD_GAIN_OVERLAP;
+
+       /* Create final PDADC table */
+       for (pdg = 0, pdadc_i = 0; pdg < pdcurves; pdg++) {
+               pdadc_tmp = ah->ah_txpower.tmpL[pdg];
+
+               if (pdg == pdcurves - 1)
+                       /* 2 dB boundary stretch for last
+                        * (higher power) curve */
+                       gain_boundaries[pdg] = pwr_max[pdg] + 4;
+               else
+                       /* Set gain boundary in the middle
+                        * between this curve and the next one */
+                       gain_boundaries[pdg] =
+                               (pwr_max[pdg] + pwr_min[pdg + 1]) / 2;
+
+               /* Sanity check in case our 2 db stretch got out of
+                * range. */
+               if (gain_boundaries[pdg] > AR5K_TUNE_MAX_TXPOWER)
+                       gain_boundaries[pdg] = AR5K_TUNE_MAX_TXPOWER;
+
+               /* For the first curve (lower power)
+                * start from 0 dB */
+               if (pdg == 0)
+                       pdadc_0 = 0;
+               else
+                       /* For the other curves use the gain overlap */
+                       pdadc_0 = (gain_boundaries[pdg - 1] - pwr_min[pdg]) -
+                                                       pd_gain_overlap;
+
+               /* Force each power step to be at least 0.5 dB */
+               if ((pdadc_tmp[1] - pdadc_tmp[0]) > 1)
+                       pwr_step = pdadc_tmp[1] - pdadc_tmp[0];
+               else
+                       pwr_step = 1;
+
+               /* If pdadc_0 is negative, we need to extrapolate
+                * below this pdgain by a number of pwr_steps */
+               while ((pdadc_0 < 0) && (pdadc_i < 128)) {
+                       s16 tmp = pdadc_tmp[0] + pdadc_0 * pwr_step;
+                       pdadc_out[pdadc_i++] = (tmp < 0) ? 0 : (u8) tmp;
+                       pdadc_0++;
+               }
+
+               /* Set last pwr level, using gain boundaries */
+               pdadc_n = gain_boundaries[pdg] + pd_gain_overlap - pwr_min[pdg];
+               /* Limit it to be inside pwr range */
+               table_size = pwr_max[pdg] - pwr_min[pdg];
+               max_idx = (pdadc_n < table_size) ? pdadc_n : table_size;
+
+               /* Fill pdadc_out table */
+               while (pdadc_0 < max_idx)
+                       pdadc_out[pdadc_i++] = pdadc_tmp[pdadc_0++];
+
+               /* Need to extrapolate above this pdgain? */
+               if (pdadc_n <= max_idx)
+                       continue;
+
+               /* Force each power step to be at least 0.5 dB */
+               if ((pdadc_tmp[table_size - 1] - pdadc_tmp[table_size - 2]) > 1)
+                       pwr_step = pdadc_tmp[table_size - 1] -
+                                               pdadc_tmp[table_size - 2];
+               else
+                       pwr_step = 1;
+
+               /* Extrapolate above */
+               while ((pdadc_0 < (s16) pdadc_n) &&
+               (pdadc_i < AR5K_EEPROM_POWER_TABLE_SIZE * 2)) {
+                       s16 tmp = pdadc_tmp[table_size - 1] +
+                                       (pdadc_0 - max_idx) * pwr_step;
+                       pdadc_out[pdadc_i++] = (tmp > 127) ? 127 : (u8) tmp;
+                       pdadc_0++;
+               }
+       }
+
+       while (pdg < AR5K_EEPROM_N_PD_GAINS) {
+               gain_boundaries[pdg] = gain_boundaries[pdg - 1];
+               pdg++;
+       }
+
+       while (pdadc_i < AR5K_EEPROM_POWER_TABLE_SIZE * 2) {
+               pdadc_out[pdadc_i] = pdadc_out[pdadc_i - 1];
+               pdadc_i++;
+       }
+
+       /* Set gain boundaries */
+       ath5k_hw_reg_write(ah,
+               AR5K_REG_SM(pd_gain_overlap,
+                       AR5K_PHY_TPC_RG5_PD_GAIN_OVERLAP) |
+               AR5K_REG_SM(gain_boundaries[0],
+                       AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_1) |
+               AR5K_REG_SM(gain_boundaries[1],
+                       AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_2) |
+               AR5K_REG_SM(gain_boundaries[2],
+                       AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_3) |
+               AR5K_REG_SM(gain_boundaries[3],
+                       AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_4),
+               AR5K_PHY_TPC_RG5);
+
+       /* Used for setting rate power table */
+       ah->ah_txpower.txp_min_idx = pwr_min[0];
+
+}
+
+/* Write PDADC values on hw */
+static void
+ath5k_setup_pwr_to_pdadc_table(struct ath5k_hw *ah,
+                       u8 pdcurves, u8 *pdg_to_idx)
+{
+       u8 *pdadc_out = ah->ah_txpower.txp_pd_table;
+       u32 reg;
+       u8 i;
+
+       /* Select the right pdgain curves */
+
+       /* Clear current settings */
+       reg = ath5k_hw_reg_read(ah, AR5K_PHY_TPC_RG1);
+       reg &= ~(AR5K_PHY_TPC_RG1_PDGAIN_1 |
+               AR5K_PHY_TPC_RG1_PDGAIN_2 |
+               AR5K_PHY_TPC_RG1_PDGAIN_3 |
+               AR5K_PHY_TPC_RG1_NUM_PD_GAIN);
+
+       /*
+        * Use pd_gains curve from eeprom
+        *
+        * This overrides the default setting from initvals
+        * in case some vendors (e.g. Zcomax) don't use the default
+        * curves. If we don't honor their settings we 'll get a
+        * 5dB (1 * gain overlap ?) drop.
+        */
+       reg |= AR5K_REG_SM(pdcurves, AR5K_PHY_TPC_RG1_NUM_PD_GAIN);
+
+       switch (pdcurves) {
+       case 3:
+               reg |= AR5K_REG_SM(pdg_to_idx[2], AR5K_PHY_TPC_RG1_PDGAIN_3);
+               /* Fall through */
+       case 2:
+               reg |= AR5K_REG_SM(pdg_to_idx[1], AR5K_PHY_TPC_RG1_PDGAIN_2);
+               /* Fall through */
+       case 1:
+               reg |= AR5K_REG_SM(pdg_to_idx[0], AR5K_PHY_TPC_RG1_PDGAIN_1);
+               break;
+       }
+       ath5k_hw_reg_write(ah, reg, AR5K_PHY_TPC_RG1);
+
+       /*
+        * Write TX power values
+        */
+       for (i = 0; i < (AR5K_EEPROM_POWER_TABLE_SIZE / 2); i++) {
+               ath5k_hw_reg_write(ah,
+                       ((pdadc_out[4*i + 0] & 0xff) << 0) |
+                       ((pdadc_out[4*i + 1] & 0xff) << 8) |
+                       ((pdadc_out[4*i + 2] & 0xff) << 16) |
+                       ((pdadc_out[4*i + 3] & 0xff) << 24),
+                       AR5K_PHY_PDADC_TXPOWER(i));
+       }
+}
+
+
+/*
+ * Common code for PCDAC/PDADC tables
+ */
+
+/*
+ * This is the main function that uses all of the above
+ * to set PCDAC/PDADC table on hw for the current channel.
+ * This table is used for tx power calibration on the basband,
+ * without it we get weird tx power levels and in some cases
+ * distorted spectral mask
+ */
+static int
+ath5k_setup_channel_powertable(struct ath5k_hw *ah,
+                       struct net80211_channel *channel,
+                       u8 ee_mode, u8 type)
+{
+       struct ath5k_pdgain_info *pdg_L, *pdg_R;
+       struct ath5k_chan_pcal_info *pcinfo_L;
+       struct ath5k_chan_pcal_info *pcinfo_R;
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       u8 *pdg_curve_to_idx = ee->ee_pdc_to_idx[ee_mode];
+       s16 table_min[AR5K_EEPROM_N_PD_GAINS];
+       s16 table_max[AR5K_EEPROM_N_PD_GAINS];
+       u8 *tmpL;
+       u8 *tmpR;
+       u32 target = channel->center_freq;
+       int pdg, i;
+
+       /* Get surounding freq piers for this channel */
+       ath5k_get_chan_pcal_surrounding_piers(ah, channel,
+                                               &pcinfo_L,
+                                               &pcinfo_R);
+
+       /* Loop over pd gain curves on
+        * surounding freq piers by index */
+       for (pdg = 0; pdg < ee->ee_pd_gains[ee_mode]; pdg++) {
+
+               /* Fill curves in reverse order
+                * from lower power (max gain)
+                * to higher power. Use curve -> idx
+                * backmaping we did on eeprom init */
+               u8 idx = pdg_curve_to_idx[pdg];
+
+               /* Grab the needed curves by index */
+               pdg_L = &pcinfo_L->pd_curves[idx];
+               pdg_R = &pcinfo_R->pd_curves[idx];
+
+               /* Initialize the temp tables */
+               tmpL = ah->ah_txpower.tmpL[pdg];
+               tmpR = ah->ah_txpower.tmpR[pdg];
+
+               /* Set curve's x boundaries and create
+                * curves so that they cover the same
+                * range (if we don't do that one table
+                * will have values on some range and the
+                * other one won't have any so interpolation
+                * will fail) */
+               table_min[pdg] = min(pdg_L->pd_pwr[0],
+                                       pdg_R->pd_pwr[0]) / 2;
+
+               table_max[pdg] = max(pdg_L->pd_pwr[pdg_L->pd_points - 1],
+                               pdg_R->pd_pwr[pdg_R->pd_points - 1]) / 2;
+
+               /* Now create the curves on surrounding channels
+                * and interpolate if needed to get the final
+                * curve for this gain on this channel */
+               switch (type) {
+               case AR5K_PWRTABLE_LINEAR_PCDAC:
+                       /* Override min/max so that we don't loose
+                        * accuracy (don't divide by 2) */
+                       table_min[pdg] = min(pdg_L->pd_pwr[0],
+                                               pdg_R->pd_pwr[0]);
+
+                       table_max[pdg] =
+                               max(pdg_L->pd_pwr[pdg_L->pd_points - 1],
+                                       pdg_R->pd_pwr[pdg_R->pd_points - 1]);
+
+                       /* Override minimum so that we don't get
+                        * out of bounds while extrapolating
+                        * below. Don't do this when we have 2
+                        * curves and we are on the high power curve
+                        * because table_min is ok in this case */
+                       if (!(ee->ee_pd_gains[ee_mode] > 1 && pdg == 0)) {
+
+                               table_min[pdg] =
+                                       ath5k_get_linear_pcdac_min(pdg_L->pd_step,
+                                                               pdg_R->pd_step,
+                                                               pdg_L->pd_pwr,
+                                                               pdg_R->pd_pwr);
+
+                               /* Don't go too low because we will
+                                * miss the upper part of the curve.
+                                * Note: 126 = 31.5dB (max power supported)
+                                * in 0.25dB units */
+                               if (table_max[pdg] - table_min[pdg] > 126)
+                                       table_min[pdg] = table_max[pdg] - 126;
+                       }
+
+                       /* Fall through */
+               case AR5K_PWRTABLE_PWR_TO_PCDAC:
+               case AR5K_PWRTABLE_PWR_TO_PDADC:
+
+                       ath5k_create_power_curve(table_min[pdg],
+                                               table_max[pdg],
+                                               pdg_L->pd_pwr,
+                                               pdg_L->pd_step,
+                                               pdg_L->pd_points, tmpL, type);
+
+                       /* We are in a calibration
+                        * pier, no need to interpolate
+                        * between freq piers */
+                       if (pcinfo_L == pcinfo_R)
+                               continue;
+
+                       ath5k_create_power_curve(table_min[pdg],
+                                               table_max[pdg],
+                                               pdg_R->pd_pwr,
+                                               pdg_R->pd_step,
+                                               pdg_R->pd_points, tmpR, type);
+                       break;
+               default:
+                       return -EINVAL;
+               }
+
+               /* Interpolate between curves
+                * of surounding freq piers to
+                * get the final curve for this
+                * pd gain. Re-use tmpL for interpolation
+                * output */
+               for (i = 0; (i < (u16) (table_max[pdg] - table_min[pdg])) &&
+               (i < AR5K_EEPROM_POWER_TABLE_SIZE); i++) {
+                       tmpL[i] = (u8) ath5k_get_interpolated_value(target,
+                                                       (s16) pcinfo_L->freq,
+                                                       (s16) pcinfo_R->freq,
+                                                       (s16) tmpL[i],
+                                                       (s16) tmpR[i]);
+               }
+       }
+
+       /* Now we have a set of curves for this
+        * channel on tmpL (x range is table_max - table_min
+        * and y values are tmpL[pdg][]) sorted in the same
+        * order as EEPROM (because we've used the backmaping).
+        * So for RF5112 it's from higher power to lower power
+        * and for RF2413 it's from lower power to higher power.
+        * For RF5111 we only have one curve. */
+
+       /* Fill min and max power levels for this
+        * channel by interpolating the values on
+        * surounding channels to complete the dataset */
+       ah->ah_txpower.txp_min_pwr = ath5k_get_interpolated_value(target,
+                                       (s16) pcinfo_L->freq,
+                                       (s16) pcinfo_R->freq,
+                                       pcinfo_L->min_pwr, pcinfo_R->min_pwr);
+
+       ah->ah_txpower.txp_max_pwr = ath5k_get_interpolated_value(target,
+                                       (s16) pcinfo_L->freq,
+                                       (s16) pcinfo_R->freq,
+                                       pcinfo_L->max_pwr, pcinfo_R->max_pwr);
+
+       /* We are ready to go, fill PCDAC/PDADC
+        * table and write settings on hardware */
+       switch (type) {
+       case AR5K_PWRTABLE_LINEAR_PCDAC:
+               /* For RF5112 we can have one or two curves
+                * and each curve covers a certain power lvl
+                * range so we need to do some more processing */
+               ath5k_combine_linear_pcdac_curves(ah, table_min, table_max,
+                                               ee->ee_pd_gains[ee_mode]);
+
+               /* Set txp.offset so that we can
+                * match max power value with max
+                * table index */
+               ah->ah_txpower.txp_offset = 64 - (table_max[0] / 2);
+
+               /* Write settings on hw */
+               ath5k_setup_pcdac_table(ah);
+               break;
+       case AR5K_PWRTABLE_PWR_TO_PCDAC:
+               /* We are done for RF5111 since it has only
+                * one curve, just fit the curve on the table */
+               ath5k_fill_pwr_to_pcdac_table(ah, table_min, table_max);
+
+               /* No rate powertable adjustment for RF5111 */
+               ah->ah_txpower.txp_min_idx = 0;
+               ah->ah_txpower.txp_offset = 0;
+
+               /* Write settings on hw */
+               ath5k_setup_pcdac_table(ah);
+               break;
+       case AR5K_PWRTABLE_PWR_TO_PDADC:
+               /* Set PDADC boundaries and fill
+                * final PDADC table */
+               ath5k_combine_pwr_to_pdadc_curves(ah, table_min, table_max,
+                                               ee->ee_pd_gains[ee_mode]);
+
+               /* Write settings on hw */
+               ath5k_setup_pwr_to_pdadc_table(ah, pdg, pdg_curve_to_idx);
+
+               /* Set txp.offset, note that table_min
+                * can be negative */
+               ah->ah_txpower.txp_offset = table_min[0];
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+
+/*
+ * Per-rate tx power setting
+ *
+ * This is the code that sets the desired tx power (below
+ * maximum) on hw for each rate (we also have TPC that sets
+ * power per packet). We do that by providing an index on the
+ * PCDAC/PDADC table we set up.
+ */
+
+/*
+ * Set rate power table
+ *
+ * For now we only limit txpower based on maximum tx power
+ * supported by hw (what's inside rate_info). We need to limit
+ * this even more, based on regulatory domain etc.
+ *
+ * Rate power table contains indices to PCDAC/PDADC table (0.5dB steps)
+ * and is indexed as follows:
+ * rates[0] - rates[7] -> OFDM rates
+ * rates[8] - rates[14] -> CCK rates
+ * rates[15] -> XR rates (they all have the same power)
+ */
+static void
+ath5k_setup_rate_powertable(struct ath5k_hw *ah, u16 max_pwr,
+                       struct ath5k_rate_pcal_info *rate_info,
+                       u8 ee_mode)
+{
+       unsigned int i;
+       u16 *rates;
+
+       /* max_pwr is power level we got from driver/user in 0.5dB
+        * units, switch to 0.25dB units so we can compare */
+       max_pwr *= 2;
+       max_pwr = min(max_pwr, (u16) ah->ah_txpower.txp_max_pwr) / 2;
+
+       /* apply rate limits */
+       rates = ah->ah_txpower.txp_rates_power_table;
+
+       /* OFDM rates 6 to 24Mb/s */
+       for (i = 0; i < 5; i++)
+               rates[i] = min(max_pwr, rate_info->target_power_6to24);
+
+       /* Rest OFDM rates */
+       rates[5] = min(rates[0], rate_info->target_power_36);
+       rates[6] = min(rates[0], rate_info->target_power_48);
+       rates[7] = min(rates[0], rate_info->target_power_54);
+
+       /* CCK rates */
+       /* 1L */
+       rates[8] = min(rates[0], rate_info->target_power_6to24);
+       /* 2L */
+       rates[9] = min(rates[0], rate_info->target_power_36);
+       /* 2S */
+       rates[10] = min(rates[0], rate_info->target_power_36);
+       /* 5L */
+       rates[11] = min(rates[0], rate_info->target_power_48);
+       /* 5S */
+       rates[12] = min(rates[0], rate_info->target_power_48);
+       /* 11L */
+       rates[13] = min(rates[0], rate_info->target_power_54);
+       /* 11S */
+       rates[14] = min(rates[0], rate_info->target_power_54);
+
+       /* XR rates */
+       rates[15] = min(rates[0], rate_info->target_power_6to24);
+
+       /* CCK rates have different peak to average ratio
+        * so we have to tweak their power so that gainf
+        * correction works ok. For this we use OFDM to
+        * CCK delta from eeprom */
+       if ((ee_mode == AR5K_EEPROM_MODE_11G) &&
+       (ah->ah_phy_revision < AR5K_SREV_PHY_5212A))
+               for (i = 8; i <= 15; i++)
+                       rates[i] -= ah->ah_txpower.txp_cck_ofdm_gainf_delta;
+
+       ah->ah_txpower.txp_min_pwr = rates[7];
+       ah->ah_txpower.txp_max_pwr = rates[0];
+       ah->ah_txpower.txp_ofdm = rates[7];
+}
+
+
+/*
+ * Set transmition power
+ */
+int
+ath5k_hw_txpower(struct ath5k_hw *ah, struct net80211_channel *channel,
+               u8 ee_mode, u8 txpower)
+{
+       struct ath5k_rate_pcal_info rate_info;
+       u8 type;
+       int ret;
+
+       if (txpower > AR5K_TUNE_MAX_TXPOWER) {
+               DBG("ath5k: invalid tx power %d\n", txpower);
+               return -EINVAL;
+       }
+       if (txpower == 0)
+               txpower = AR5K_TUNE_DEFAULT_TXPOWER;
+
+       /* Reset TX power values */
+       memset(&ah->ah_txpower, 0, sizeof(ah->ah_txpower));
+       ah->ah_txpower.txp_tpc = AR5K_TUNE_TPC_TXPOWER;
+       ah->ah_txpower.txp_min_pwr = 0;
+       ah->ah_txpower.txp_max_pwr = AR5K_TUNE_MAX_TXPOWER;
+
+       /* Initialize TX power table */
+       switch (ah->ah_radio) {
+       case AR5K_RF5111:
+               type = AR5K_PWRTABLE_PWR_TO_PCDAC;
+               break;
+       case AR5K_RF5112:
+               type = AR5K_PWRTABLE_LINEAR_PCDAC;
+               break;
+       case AR5K_RF2413:
+       case AR5K_RF5413:
+       case AR5K_RF2316:
+       case AR5K_RF2317:
+       case AR5K_RF2425:
+               type = AR5K_PWRTABLE_PWR_TO_PDADC;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* FIXME: Only on channel/mode change */
+       ret = ath5k_setup_channel_powertable(ah, channel, ee_mode, type);
+       if (ret)
+               return ret;
+
+       /* Limit max power if we have a CTL available */
+       ath5k_get_max_ctl_power(ah, channel);
+
+       /* FIXME: Tx power limit for this regdomain
+        * XXX: Mac80211/CRDA will do that anyway ? */
+
+       /* FIXME: Antenna reduction stuff */
+
+       /* FIXME: Limit power on turbo modes */
+
+       /* FIXME: TPC scale reduction */
+
+       /* Get surounding channels for per-rate power table
+        * calibration */
+       ath5k_get_rate_pcal_data(ah, channel, &rate_info);
+
+       /* Setup rate power table */
+       ath5k_setup_rate_powertable(ah, txpower, &rate_info, ee_mode);
+
+       /* Write rate power table on hw */
+       ath5k_hw_reg_write(ah, AR5K_TXPOWER_OFDM(3, 24) |
+               AR5K_TXPOWER_OFDM(2, 16) | AR5K_TXPOWER_OFDM(1, 8) |
+               AR5K_TXPOWER_OFDM(0, 0), AR5K_PHY_TXPOWER_RATE1);
+
+       ath5k_hw_reg_write(ah, AR5K_TXPOWER_OFDM(7, 24) |
+               AR5K_TXPOWER_OFDM(6, 16) | AR5K_TXPOWER_OFDM(5, 8) |
+               AR5K_TXPOWER_OFDM(4, 0), AR5K_PHY_TXPOWER_RATE2);
+
+       ath5k_hw_reg_write(ah, AR5K_TXPOWER_CCK(10, 24) |
+               AR5K_TXPOWER_CCK(9, 16) | AR5K_TXPOWER_CCK(15, 8) |
+               AR5K_TXPOWER_CCK(8, 0), AR5K_PHY_TXPOWER_RATE3);
+
+       ath5k_hw_reg_write(ah, AR5K_TXPOWER_CCK(14, 24) |
+               AR5K_TXPOWER_CCK(13, 16) | AR5K_TXPOWER_CCK(12, 8) |
+               AR5K_TXPOWER_CCK(11, 0), AR5K_PHY_TXPOWER_RATE4);
+
+       /* FIXME: TPC support */
+       if (ah->ah_txpower.txp_tpc) {
+               ath5k_hw_reg_write(ah, AR5K_PHY_TXPOWER_RATE_MAX_TPC_ENABLE |
+                       AR5K_TUNE_MAX_TXPOWER, AR5K_PHY_TXPOWER_RATE_MAX);
+
+               ath5k_hw_reg_write(ah,
+                       AR5K_REG_MS(AR5K_TUNE_MAX_TXPOWER, AR5K_TPC_ACK) |
+                       AR5K_REG_MS(AR5K_TUNE_MAX_TXPOWER, AR5K_TPC_CTS) |
+                       AR5K_REG_MS(AR5K_TUNE_MAX_TXPOWER, AR5K_TPC_CHIRP),
+                       AR5K_TPC);
+       } else {
+               ath5k_hw_reg_write(ah, AR5K_PHY_TXPOWER_RATE_MAX |
+                       AR5K_TUNE_MAX_TXPOWER, AR5K_PHY_TXPOWER_RATE_MAX);
+       }
+
+       return 0;
+}
+
+int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 mode, u8 txpower)
+{
+       struct net80211_channel *channel = ah->ah_current_channel;
+
+       DBG2("ath5k: changing txpower to %d\n", txpower);
+
+       return ath5k_hw_txpower(ah, channel, mode, txpower);
+}
+
+#undef _ATH5K_PHY
diff --git a/src/drivers/net/ath5k/ath5k_qcu.c b/src/drivers/net/ath5k/ath5k_qcu.c
new file mode 100644 (file)
index 0000000..a674b85
--- /dev/null
@@ -0,0 +1,394 @@
+/*
+ * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
+ *
+ * Lightly modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+FILE_LICENCE ( MIT );
+
+/********************************************\
+Queue Control Unit, DFS Control Unit Functions
+\********************************************/
+
+#include "ath5k.h"
+#include "reg.h"
+#include "base.h"
+
+/*
+ * Set properties for a transmit queue
+ */
+int ath5k_hw_set_tx_queueprops(struct ath5k_hw *ah,
+                               const struct ath5k_txq_info *queue_info)
+{
+       if (ah->ah_txq.tqi_type == AR5K_TX_QUEUE_INACTIVE)
+               return -EIO;
+
+       memcpy(&ah->ah_txq, queue_info, sizeof(struct ath5k_txq_info));
+
+       /*XXX: Is this supported on 5210 ?*/
+       if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
+                       ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
+                       (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
+                       queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
+               ah->ah_txq.tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
+
+       return 0;
+}
+
+/*
+ * Initialize a transmit queue
+ */
+int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
+               struct ath5k_txq_info *queue_info)
+{
+       unsigned int queue;
+       int ret;
+
+       /* We only use one queue */
+       queue = 0;
+
+       /*
+        * Setup internal queue structure
+        */
+       memset(&ah->ah_txq, 0, sizeof(struct ath5k_txq_info));
+       ah->ah_txq.tqi_type = queue_type;
+
+       if (queue_info != NULL) {
+               queue_info->tqi_type = queue_type;
+               ret = ath5k_hw_set_tx_queueprops(ah, queue_info);
+               if (ret)
+                       return ret;
+       }
+
+       /*
+        * We use ah_txq_status to hold a temp value for
+        * the Secondary interrupt mask registers on 5211+
+        * check out ath5k_hw_reset_tx_queue
+        */
+       AR5K_Q_ENABLE_BITS(ah->ah_txq_status, 0);
+
+       return 0;
+}
+
+/*
+ * Set a transmit queue inactive
+ */
+void ath5k_hw_release_tx_queue(struct ath5k_hw *ah)
+{
+       /* This queue will be skipped in further operations */
+       ah->ah_txq.tqi_type = AR5K_TX_QUEUE_INACTIVE;
+       /*For SIMR setup*/
+       AR5K_Q_DISABLE_BITS(ah->ah_txq_status, 0);
+}
+
+/*
+ * Set DFS properties for a transmit queue on DCU
+ */
+int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah)
+{
+       u32 cw_min, cw_max, retry_lg, retry_sh;
+       struct ath5k_txq_info *tq = &ah->ah_txq;
+       const int queue = 0;
+
+       tq = &ah->ah_txq;
+
+       if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
+               return 0;
+
+       if (ah->ah_version == AR5K_AR5210) {
+               /* Only handle data queues, others will be ignored */
+               if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
+                       return 0;
+
+               /* Set Slot time */
+               ath5k_hw_reg_write(ah, ah->ah_turbo ?
+                       AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
+                       AR5K_SLOT_TIME);
+               /* Set ACK_CTS timeout */
+               ath5k_hw_reg_write(ah, ah->ah_turbo ?
+                       AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
+                       AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
+               /* Set Transmit Latency */
+               ath5k_hw_reg_write(ah, ah->ah_turbo ?
+                       AR5K_INIT_TRANSMIT_LATENCY_TURBO :
+                       AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
+
+               /* Set IFS0 */
+               if (ah->ah_turbo) {
+                        ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
+                               (ah->ah_aifs + tq->tqi_aifs) *
+                               AR5K_INIT_SLOT_TIME_TURBO) <<
+                               AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
+                               AR5K_IFS0);
+               } else {
+                       ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
+                               (ah->ah_aifs + tq->tqi_aifs) *
+                               AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
+                               AR5K_INIT_SIFS, AR5K_IFS0);
+               }
+
+               /* Set IFS1 */
+               ath5k_hw_reg_write(ah, ah->ah_turbo ?
+                       AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
+                       AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
+               /* Set AR5K_PHY_SETTLING */
+               ath5k_hw_reg_write(ah, ah->ah_turbo ?
+                       (ath5k_hw_reg_read(ah, AR5K_PHY_SETTLING) & ~0x7F)
+                       | 0x38 :
+                       (ath5k_hw_reg_read(ah, AR5K_PHY_SETTLING) & ~0x7F)
+                       | 0x1C,
+                       AR5K_PHY_SETTLING);
+               /* Set Frame Control Register */
+               ath5k_hw_reg_write(ah, ah->ah_turbo ?
+                       (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
+                       AR5K_PHY_TURBO_SHORT | 0x2020) :
+                       (AR5K_PHY_FRAME_CTL_INI | 0x1020),
+                       AR5K_PHY_FRAME_CTL_5210);
+       }
+
+       /*
+        * Calculate cwmin/max by channel mode
+        */
+       cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
+       cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
+       ah->ah_aifs = AR5K_TUNE_AIFS;
+       /*XR is only supported on 5212*/
+       if (IS_CHAN_XR(ah->ah_current_channel) &&
+                       ah->ah_version == AR5K_AR5212) {
+               cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
+               cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
+               ah->ah_aifs = AR5K_TUNE_AIFS_XR;
+       /*B mode is not supported on 5210*/
+       } else if (IS_CHAN_B(ah->ah_current_channel) &&
+                       ah->ah_version != AR5K_AR5210) {
+               cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
+               cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
+               ah->ah_aifs = AR5K_TUNE_AIFS_11B;
+       }
+
+       cw_min = 1;
+       while (cw_min < ah->ah_cw_min)
+               cw_min = (cw_min << 1) | 1;
+
+       cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
+               ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
+       cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
+               ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
+
+       /*
+        * Calculate and set retry limits
+        */
+       if (ah->ah_software_retry) {
+               /* XXX Need to test this */
+               retry_lg = ah->ah_limit_tx_retries;
+               retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
+                       AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
+       } else {
+               retry_lg = AR5K_INIT_LG_RETRY;
+               retry_sh = AR5K_INIT_SH_RETRY;
+       }
+
+       /*No QCU/DCU [5210]*/
+       if (ah->ah_version == AR5K_AR5210) {
+               ath5k_hw_reg_write(ah,
+                       (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
+                       | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
+                               AR5K_NODCU_RETRY_LMT_SLG_RETRY)
+                       | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
+                               AR5K_NODCU_RETRY_LMT_SSH_RETRY)
+                       | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
+                       | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
+                       AR5K_NODCU_RETRY_LMT);
+       } else {
+               /*QCU/DCU [5211+]*/
+               ath5k_hw_reg_write(ah,
+                       AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
+                               AR5K_DCU_RETRY_LMT_SLG_RETRY) |
+                       AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
+                               AR5K_DCU_RETRY_LMT_SSH_RETRY) |
+                       AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
+                       AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
+                       AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
+
+       /*===Rest is also for QCU/DCU only [5211+]===*/
+
+               /*
+                * Set initial content window (cw_min/cw_max)
+                * and arbitrated interframe space (aifs)...
+                */
+               ath5k_hw_reg_write(ah,
+                       AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
+                       AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
+                       AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
+                               AR5K_DCU_LCL_IFS_AIFS),
+                       AR5K_QUEUE_DFS_LOCAL_IFS(queue));
+
+               /*
+                * Set misc registers
+                */
+               /* Enable DCU early termination for this queue */
+               AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
+                                       AR5K_QCU_MISC_DCU_EARLY);
+
+               /* Enable DCU to wait for next fragment from QCU */
+               AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
+                                       AR5K_DCU_MISC_FRAG_WAIT);
+
+               /* On Maui and Spirit use the global seqnum on DCU */
+               if (ah->ah_mac_version < AR5K_SREV_AR5211)
+                       AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
+                                               AR5K_DCU_MISC_SEQNUM_CTL);
+
+               if (tq->tqi_cbr_period) {
+                       ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
+                               AR5K_QCU_CBRCFG_INTVAL) |
+                               AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
+                               AR5K_QCU_CBRCFG_ORN_THRES),
+                               AR5K_QUEUE_CBRCFG(queue));
+                       AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
+                               AR5K_QCU_MISC_FRSHED_CBR);
+                       if (tq->tqi_cbr_overflow_limit)
+                               AR5K_REG_ENABLE_BITS(ah,
+                                       AR5K_QUEUE_MISC(queue),
+                                       AR5K_QCU_MISC_CBR_THRES_ENABLE);
+               }
+
+               if (tq->tqi_ready_time &&
+               (tq->tqi_type != AR5K_TX_QUEUE_ID_CAB))
+                       ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
+                               AR5K_QCU_RDYTIMECFG_INTVAL) |
+                               AR5K_QCU_RDYTIMECFG_ENABLE,
+                               AR5K_QUEUE_RDYTIMECFG(queue));
+
+               if (tq->tqi_burst_time) {
+                       ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
+                               AR5K_DCU_CHAN_TIME_DUR) |
+                               AR5K_DCU_CHAN_TIME_ENABLE,
+                               AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
+
+                       if (tq->tqi_flags
+                       & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
+                               AR5K_REG_ENABLE_BITS(ah,
+                                       AR5K_QUEUE_MISC(queue),
+                                       AR5K_QCU_MISC_RDY_VEOL_POLICY);
+               }
+
+               if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
+                       ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
+                               AR5K_QUEUE_DFS_MISC(queue));
+
+               if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
+                       ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
+                               AR5K_QUEUE_DFS_MISC(queue));
+
+               /* TODO: Handle frame compression */
+
+               /*
+                * Enable interrupts for this tx queue
+                * in the secondary interrupt mask registers
+                */
+               if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
+                       AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
+
+               if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
+                       AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
+
+               if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
+                       AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
+
+               if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
+                       AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
+
+               if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
+                       AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
+
+               if (tq->tqi_flags & AR5K_TXQ_FLAG_CBRORNINT_ENABLE)
+                       AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_cbrorn, queue);
+
+               if (tq->tqi_flags & AR5K_TXQ_FLAG_CBRURNINT_ENABLE)
+                       AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_cbrurn, queue);
+
+               if (tq->tqi_flags & AR5K_TXQ_FLAG_QTRIGINT_ENABLE)
+                       AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_qtrig, queue);
+
+               if (tq->tqi_flags & AR5K_TXQ_FLAG_TXNOFRMINT_ENABLE)
+                       AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_nofrm, queue);
+
+               /* Update secondary interrupt mask registers */
+
+               /* Filter out inactive queues */
+               ah->ah_txq_imr_txok &= ah->ah_txq_status;
+               ah->ah_txq_imr_txerr &= ah->ah_txq_status;
+               ah->ah_txq_imr_txurn &= ah->ah_txq_status;
+               ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
+               ah->ah_txq_imr_txeol &= ah->ah_txq_status;
+               ah->ah_txq_imr_cbrorn &= ah->ah_txq_status;
+               ah->ah_txq_imr_cbrurn &= ah->ah_txq_status;
+               ah->ah_txq_imr_qtrig &= ah->ah_txq_status;
+               ah->ah_txq_imr_nofrm &= ah->ah_txq_status;
+
+               ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
+                       AR5K_SIMR0_QCU_TXOK) |
+                       AR5K_REG_SM(ah->ah_txq_imr_txdesc,
+                       AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
+               ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
+                       AR5K_SIMR1_QCU_TXERR) |
+                       AR5K_REG_SM(ah->ah_txq_imr_txeol,
+                       AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
+               /* Update simr2 but don't overwrite rest simr2 settings */
+               AR5K_REG_DISABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_QCU_TXURN);
+               AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2,
+                       AR5K_REG_SM(ah->ah_txq_imr_txurn,
+                       AR5K_SIMR2_QCU_TXURN));
+               ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_cbrorn,
+                       AR5K_SIMR3_QCBRORN) |
+                       AR5K_REG_SM(ah->ah_txq_imr_cbrurn,
+                       AR5K_SIMR3_QCBRURN), AR5K_SIMR3);
+               ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_qtrig,
+                       AR5K_SIMR4_QTRIG), AR5K_SIMR4);
+               /* Set TXNOFRM_QCU for the queues with TXNOFRM enabled */
+               ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_nofrm,
+                       AR5K_TXNOFRM_QCU), AR5K_TXNOFRM);
+               /* No queue has TXNOFRM enabled, disable the interrupt
+                * by setting AR5K_TXNOFRM to zero */
+               if (ah->ah_txq_imr_nofrm == 0)
+                       ath5k_hw_reg_write(ah, 0, AR5K_TXNOFRM);
+
+               /* Set QCU mask for this DCU to save power */
+               AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(queue), queue);
+       }
+
+       return 0;
+}
+
+/*
+ * Set slot time on DCU
+ */
+int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
+{
+       if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
+               return -EINVAL;
+
+       if (ah->ah_version == AR5K_AR5210)
+               ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
+                               ah->ah_turbo), AR5K_SLOT_TIME);
+       else
+               ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
+
+       return 0;
+}
+
diff --git a/src/drivers/net/ath5k/ath5k_reset.c b/src/drivers/net/ath5k/ath5k_reset.c
new file mode 100644 (file)
index 0000000..dc80093
--- /dev/null
@@ -0,0 +1,1176 @@
+/*
+ * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
+ * Copyright (c) 2007-2008 Luis Rodriguez <mcgrof@winlab.rutgers.edu>
+ * Copyright (c) 2007-2008 Pavel Roskin <proski@gnu.org>
+ * Copyright (c) 2007-2008 Jiri Slaby <jirislaby@gmail.com>
+ *
+ * Lightly modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+FILE_LICENCE ( MIT );
+
+#define _ATH5K_RESET
+
+/*****************************\
+  Reset functions and helpers
+\*****************************/
+
+#include <gpxe/pci.h>          /* To determine if a card is pci-e */
+#include <unistd.h>
+
+#include "ath5k.h"
+#include "reg.h"
+#include "base.h"
+
+/* Find last set bit; fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32 */
+static int fls(int x)
+{
+        int r = 32;
+
+        if (!x)
+                return 0;
+        if (!(x & 0xffff0000u)) {
+                x <<= 16;
+                r -= 16;
+        }
+        if (!(x & 0xff000000u)) {
+                x <<= 8;
+                r -= 8;
+        }
+        if (!(x & 0xf0000000u)) {
+                x <<= 4;
+                r -= 4;
+        }
+        if (!(x & 0xc0000000u)) {
+                x <<= 2;
+                r -= 2;
+        }
+        if (!(x & 0x80000000u)) {
+                x <<= 1;
+                r -= 1;
+        }
+        return r;
+}
+
+
+/**
+ * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
+ *
+ * @ah: the &struct ath5k_hw
+ * @channel: the currently set channel upon reset
+ *
+ * Write the delta slope coefficient (used on pilot tracking ?) for OFDM
+ * operation on the AR5212 upon reset. This is a helper for ath5k_hw_reset().
+ *
+ * Since delta slope is floating point we split it on its exponent and
+ * mantissa and provide these values on hw.
+ *
+ * For more infos i think this patent is related
+ * http://www.freepatentsonline.com/7184495.html
+ */
+static int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
+       struct net80211_channel *channel)
+{
+       /* Get exponent and mantissa and set it */
+       u32 coef_scaled, coef_exp, coef_man,
+               ds_coef_exp, ds_coef_man, clock;
+
+       if (!(ah->ah_version == AR5K_AR5212) ||
+           !(channel->hw_value & CHANNEL_OFDM)) {
+               DBG("ath5k: attempt to set OFDM timings on non-OFDM channel\n");
+               return -EFAULT;
+       }
+
+       /* Get coefficient
+        * ALGO: coef = (5 * clock * carrier_freq) / 2)
+        * we scale coef by shifting clock value by 24 for
+        * better precision since we use integers */
+       /* TODO: Half/quarter rate */
+       clock =  ath5k_hw_htoclock(1, channel->hw_value & CHANNEL_TURBO);
+
+       coef_scaled = ((5 * (clock << 24)) / 2) / channel->center_freq;
+
+       /* Get exponent
+        * ALGO: coef_exp = 14 - highest set bit position */
+       coef_exp = fls(coef_scaled) - 1;
+
+       /* Doesn't make sense if it's zero*/
+       if (!coef_scaled || !coef_exp)
+               return -EINVAL;
+
+       /* Note: we've shifted coef_scaled by 24 */
+       coef_exp = 14 - (coef_exp - 24);
+
+
+       /* Get mantissa (significant digits)
+        * ALGO: coef_mant = floor(coef_scaled* 2^coef_exp+0.5) */
+       coef_man = coef_scaled +
+               (1 << (24 - coef_exp - 1));
+
+       /* Calculate delta slope coefficient exponent
+        * and mantissa (remove scaling) and set them on hw */
+       ds_coef_man = coef_man >> (24 - coef_exp);
+       ds_coef_exp = coef_exp - 16;
+
+       AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
+               AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
+       AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
+               AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
+
+       return 0;
+}
+
+
+/*
+ * index into rates for control rates, we can set it up like this because
+ * this is only used for AR5212 and we know it supports G mode
+ */
+static const unsigned int control_rates[] =
+       { 0, 1, 1, 1, 4, 4, 6, 6, 8, 8, 8, 8 };
+
+/**
+ * ath5k_hw_write_rate_duration - fill rate code to duration table
+ *
+ * @ah: the &struct ath5k_hw
+ * @mode: one of enum ath5k_driver_mode
+ *
+ * Write the rate code to duration table upon hw reset. This is a helper for
+ * ath5k_hw_reset(). It seems all this is doing is setting an ACK timeout on
+ * the hardware, based on current mode, for each rate. The rates which are
+ * capable of short preamble (802.11b rates 2Mbps, 5.5Mbps, and 11Mbps) have
+ * different rate code so we write their value twice (one for long preample
+ * and one for short).
+ *
+ * Note: Band doesn't matter here, if we set the values for OFDM it works
+ * on both a and g modes. So all we have to do is set values for all g rates
+ * that include all OFDM and CCK rates. If we operate in turbo or xr/half/
+ * quarter rate mode, we need to use another set of bitrates (that's why we
+ * need the mode parameter) but we don't handle these proprietary modes yet.
+ */
+static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
+       unsigned int mode __unused)
+{
+       struct ath5k_softc *sc = ah->ah_sc;
+       u16 rate;
+       int i;
+
+       /* Write rate duration table */
+       for (i = 0; i < sc->hwinfo->nr_rates[NET80211_BAND_2GHZ]; i++) {
+               u32 reg;
+               u16 tx_time;
+
+               rate = sc->hwinfo->rates[NET80211_BAND_2GHZ][i];
+
+               /* Set ACK timeout */
+               reg = AR5K_RATE_DUR(ath5k_bitrate_to_hw_rix(rate));
+
+               /* An ACK frame consists of 10 bytes. If you add the FCS,
+                * it's 14 bytes. Note we use the control rate and not the
+                * actual rate for this rate. See mac80211 tx.c
+                * ieee80211_duration() for a brief description of
+                * what rate we should choose to TX ACKs. */
+               tx_time = net80211_duration(sc->dev, 14, rate);
+
+               ath5k_hw_reg_write(ah, tx_time, reg);
+
+               if (rate != 20 && rate != 55 && rate != 110)
+                       continue;
+
+               /*
+                * We're not distinguishing short preamble here,
+                * This is true, all we'll get is a longer value here
+                * which is not necessarilly bad.
+                */
+               ath5k_hw_reg_write(ah, tx_time,
+                       reg + (AR5K_SET_SHORT_PREAMBLE << 2));
+       }
+}
+
+/*
+ * Reset chipset
+ */
+static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
+{
+       int ret;
+       u32 mask = val ? val : ~0U;
+
+       /* Read-and-clear RX Descriptor Pointer*/
+       ath5k_hw_reg_read(ah, AR5K_RXDP);
+
+       /*
+        * Reset the device and wait until success
+        */
+       ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
+
+       /* Wait at least 128 PCI clocks */
+       udelay(15);
+
+       if (ah->ah_version == AR5K_AR5210) {
+               val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_DMA
+                       | AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_PHY;
+               mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_DMA
+                       | AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_PHY;
+       } else {
+               val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
+               mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
+       }
+
+       ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, 0);
+
+       /*
+        * Reset configuration register (for hw byte-swap). Note that this
+        * is only set for big endian. We do the necessary magic in
+        * AR5K_INIT_CFG.
+        */
+       if ((val & AR5K_RESET_CTL_PCU) == 0)
+               ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
+
+       return ret;
+}
+
+/*
+ * Sleep control
+ */
+int ath5k_hw_wake(struct ath5k_hw *ah)
+{
+       unsigned int i;
+       u32 staid, data;
+
+       staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
+       staid &= ~AR5K_STA_ID1_PWR_SV;
+
+       /* Preserve sleep duration */
+       data = ath5k_hw_reg_read(ah, AR5K_SLEEP_CTL);
+       if (data & 0xffc00000)
+               data = 0;
+       else
+               data = data & 0xfffcffff;
+
+       ath5k_hw_reg_write(ah, data, AR5K_SLEEP_CTL);
+       udelay(15);
+
+       for (i = 50; i > 0; i--) {
+               /* Check if the chip did wake up */
+               if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
+                    AR5K_PCICFG_SPWR_DN) == 0)
+                       break;
+
+               /* Wait a bit and retry */
+               udelay(200);
+               ath5k_hw_reg_write(ah, data, AR5K_SLEEP_CTL);
+       }
+
+       /* Fail if the chip didn't wake up */
+       if (i <= 0)
+               return -EIO;
+
+       ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
+
+       return 0;
+}
+
+/*
+ * Bring up MAC + PHY Chips and program PLL
+ * TODO: Half/Quarter rate support
+ */
+int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, int initial __unused)
+{
+       struct pci_device *pdev = ah->ah_sc->pdev;
+       u32 turbo, mode, clock, bus_flags;
+       int ret;
+
+       turbo = 0;
+       mode = 0;
+       clock = 0;
+
+       /* Wakeup the device */
+       ret = ath5k_hw_wake(ah);
+       if (ret) {
+               DBG("ath5k: failed to wake up the MAC chip\n");
+               return ret;
+       }
+
+       if (ah->ah_version != AR5K_AR5210) {
+               /*
+                * Get channel mode flags
+                */
+
+               if (ah->ah_radio >= AR5K_RF5112) {
+                       mode = AR5K_PHY_MODE_RAD_RF5112;
+                       clock = AR5K_PHY_PLL_RF5112;
+               } else {
+                       mode = AR5K_PHY_MODE_RAD_RF5111;        /*Zero*/
+                       clock = AR5K_PHY_PLL_RF5111;            /*Zero*/
+               }
+
+               if (flags & CHANNEL_2GHZ) {
+                       mode |= AR5K_PHY_MODE_FREQ_2GHZ;
+                       clock |= AR5K_PHY_PLL_44MHZ;
+
+                       if (flags & CHANNEL_CCK) {
+                               mode |= AR5K_PHY_MODE_MOD_CCK;
+                       } else if (flags & CHANNEL_OFDM) {
+                               /* XXX Dynamic OFDM/CCK is not supported by the
+                                * AR5211 so we set MOD_OFDM for plain g (no
+                                * CCK headers) operation. We need to test
+                                * this, 5211 might support ofdm-only g after
+                                * all, there are also initial register values
+                                * in the code for g mode (see initvals.c). */
+                               if (ah->ah_version == AR5K_AR5211)
+                                       mode |= AR5K_PHY_MODE_MOD_OFDM;
+                               else
+                                       mode |= AR5K_PHY_MODE_MOD_DYN;
+                       } else {
+                               DBG("ath5k: invalid radio modulation mode\n");
+                               return -EINVAL;
+                       }
+               } else if (flags & CHANNEL_5GHZ) {
+                       mode |= AR5K_PHY_MODE_FREQ_5GHZ;
+
+                       if (ah->ah_radio == AR5K_RF5413)
+                               clock = AR5K_PHY_PLL_40MHZ_5413;
+                       else
+                               clock |= AR5K_PHY_PLL_40MHZ;
+
+                       if (flags & CHANNEL_OFDM)
+                               mode |= AR5K_PHY_MODE_MOD_OFDM;
+                       else {
+                               DBG("ath5k: invalid radio modulation mode\n");
+                               return -EINVAL;
+                       }
+               } else {
+                       DBG("ath5k: invalid radio frequency mode\n");
+                       return -EINVAL;
+               }
+
+               if (flags & CHANNEL_TURBO)
+                       turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
+       } else { /* Reset the device */
+
+               /* ...enable Atheros turbo mode if requested */
+               if (flags & CHANNEL_TURBO)
+                       ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
+                                       AR5K_PHY_TURBO);
+       }
+
+       /* reseting PCI on PCI-E cards results card to hang
+        * and always return 0xffff... so we ingore that flag
+        * for PCI-E cards */
+       if (pci_find_capability(pdev, PCI_CAP_ID_EXP))
+               bus_flags = 0;
+       else
+               bus_flags = AR5K_RESET_CTL_PCI;
+
+       /* Reset chipset */
+       if (ah->ah_version == AR5K_AR5210) {
+               ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
+                       AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_DMA |
+                       AR5K_RESET_CTL_PHY | AR5K_RESET_CTL_PCI);
+               mdelay(2);
+       } else {
+               ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
+                       AR5K_RESET_CTL_BASEBAND | bus_flags);
+       }
+       if (ret) {
+               DBG("ath5k: failed to reset the MAC chip\n");
+               return -EIO;
+       }
+
+       /* ...wakeup again!*/
+       ret = ath5k_hw_wake(ah);
+       if (ret) {
+               DBG("ath5k: failed to resume the MAC chip\n");
+               return ret;
+       }
+
+       /* ...final warm reset */
+       if (ath5k_hw_nic_reset(ah, 0)) {
+               DBG("ath5k: failed to warm reset the MAC chip\n");
+               return -EIO;
+       }
+
+       if (ah->ah_version != AR5K_AR5210) {
+
+               /* ...update PLL if needed */
+               if (ath5k_hw_reg_read(ah, AR5K_PHY_PLL) != clock) {
+                       ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
+                       udelay(300);
+               }
+
+               /* ...set the PHY operating mode */
+               ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
+               ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
+       }
+
+       return 0;
+}
+
+static int ath5k_hw_chan_has_spur_noise(struct ath5k_hw *ah,
+                               struct net80211_channel *channel)
+{
+       u8 refclk_freq;
+
+       if ((ah->ah_radio == AR5K_RF5112) ||
+       (ah->ah_radio == AR5K_RF5413) ||
+       (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)))
+               refclk_freq = 40;
+       else
+               refclk_freq = 32;
+
+       if ((channel->center_freq % refclk_freq != 0) &&
+       ((channel->center_freq % refclk_freq < 10) ||
+       (channel->center_freq % refclk_freq > 22)))
+               return 1;
+       else
+               return 0;
+}
+
+/* TODO: Half/Quarter rate */
+static void ath5k_hw_tweak_initval_settings(struct ath5k_hw *ah,
+                               struct net80211_channel *channel)
+{
+       if (ah->ah_version == AR5K_AR5212 &&
+           ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
+
+               /* Setup ADC control */
+               ath5k_hw_reg_write(ah,
+                               (AR5K_REG_SM(2,
+                               AR5K_PHY_ADC_CTL_INBUFGAIN_OFF) |
+                               AR5K_REG_SM(2,
+                               AR5K_PHY_ADC_CTL_INBUFGAIN_ON) |
+                               AR5K_PHY_ADC_CTL_PWD_DAC_OFF |
+                               AR5K_PHY_ADC_CTL_PWD_ADC_OFF),
+                               AR5K_PHY_ADC_CTL);
+
+
+
+               /* Disable barker RSSI threshold */
+               AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_DAG_CCK_CTL,
+                               AR5K_PHY_DAG_CCK_CTL_EN_RSSI_THR);
+
+               AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DAG_CCK_CTL,
+                       AR5K_PHY_DAG_CCK_CTL_RSSI_THR, 2);
+
+               /* Set the mute mask */
+               ath5k_hw_reg_write(ah, 0x0000000f, AR5K_SEQ_MASK);
+       }
+
+       /* Clear PHY_BLUETOOTH to allow RX_CLEAR line debug */
+       if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212B)
+               ath5k_hw_reg_write(ah, 0, AR5K_PHY_BLUETOOTH);
+
+       /* Enable DCU double buffering */
+       if (ah->ah_phy_revision > AR5K_SREV_PHY_5212B)
+               AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
+                               AR5K_TXCFG_DCU_DBL_BUF_DIS);
+
+       /* Set DAC/ADC delays */
+       if (ah->ah_version == AR5K_AR5212) {
+               u32 scal;
+               if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))
+                       scal = AR5K_PHY_SCAL_32MHZ_2417;
+               else if (ath5k_eeprom_is_hb63(ah))
+                       scal = AR5K_PHY_SCAL_32MHZ_HB63;
+               else
+                       scal = AR5K_PHY_SCAL_32MHZ;
+               ath5k_hw_reg_write(ah, scal, AR5K_PHY_SCAL);
+       }
+
+       /* Set fast ADC */
+       if ((ah->ah_radio == AR5K_RF5413) ||
+       (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))) {
+               u32 fast_adc = 1;
+
+               if (channel->center_freq == 2462 ||
+               channel->center_freq == 2467)
+                       fast_adc = 0;
+
+               /* Only update if needed */
+               if (ath5k_hw_reg_read(ah, AR5K_PHY_FAST_ADC) != fast_adc)
+                               ath5k_hw_reg_write(ah, fast_adc,
+                                               AR5K_PHY_FAST_ADC);
+       }
+
+       /* Fix for first revision of the RF5112 RF chipset */
+       if (ah->ah_radio == AR5K_RF5112 &&
+                       ah->ah_radio_5ghz_revision <
+                       AR5K_SREV_RAD_5112A) {
+               u32 data;
+               ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
+                               AR5K_PHY_CCKTXCTL);
+               if (channel->hw_value & CHANNEL_5GHZ)
+                       data = 0xffb81020;
+               else
+                       data = 0xffb80d20;
+               ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
+       }
+
+       if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
+               u32 usec_reg;
+               /* 5311 has different tx/rx latency masks
+                * from 5211, since we deal 5311 the same
+                * as 5211 when setting initvals, shift
+                * values here to their proper locations */
+               usec_reg = ath5k_hw_reg_read(ah, AR5K_USEC_5211);
+               ath5k_hw_reg_write(ah, usec_reg & (AR5K_USEC_1 |
+                               AR5K_USEC_32 |
+                               AR5K_USEC_TX_LATENCY_5211 |
+                               AR5K_REG_SM(29,
+                               AR5K_USEC_RX_LATENCY_5210)),
+                               AR5K_USEC_5211);
+               /* Clear QCU/DCU clock gating register */
+               ath5k_hw_reg_write(ah, 0, AR5K_QCUDCU_CLKGT);
+               /* Set DAC/ADC delays */
+               ath5k_hw_reg_write(ah, 0x08, AR5K_PHY_SCAL);
+               /* Enable PCU FIFO corruption ECO */
+               AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW_5211,
+                                       AR5K_DIAG_SW_ECO_ENABLE);
+       }
+}
+
+static void ath5k_hw_commit_eeprom_settings(struct ath5k_hw *ah,
+               struct net80211_channel *channel, u8 *ant, u8 ee_mode)
+{
+       struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
+       s16 cck_ofdm_pwr_delta;
+
+       /* Adjust power delta for channel 14 */
+       if (channel->center_freq == 2484)
+               cck_ofdm_pwr_delta =
+                       ((ee->ee_cck_ofdm_power_delta -
+                       ee->ee_scaled_cck_delta) * 2) / 10;
+       else
+               cck_ofdm_pwr_delta =
+                       (ee->ee_cck_ofdm_power_delta * 2) / 10;
+
+       /* Set CCK to OFDM power delta on tx power
+        * adjustment register */
+       if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
+               if (channel->hw_value == CHANNEL_G)
+                       ath5k_hw_reg_write(ah,
+                       AR5K_REG_SM((ee->ee_cck_ofdm_gain_delta * -1),
+                               AR5K_PHY_TX_PWR_ADJ_CCK_GAIN_DELTA) |
+                       AR5K_REG_SM((cck_ofdm_pwr_delta * -1),
+                               AR5K_PHY_TX_PWR_ADJ_CCK_PCDAC_INDEX),
+                               AR5K_PHY_TX_PWR_ADJ);
+               else
+                       ath5k_hw_reg_write(ah, 0, AR5K_PHY_TX_PWR_ADJ);
+       } else {
+               /* For older revs we scale power on sw during tx power
+                * setup */
+               ah->ah_txpower.txp_cck_ofdm_pwr_delta = cck_ofdm_pwr_delta;
+               ah->ah_txpower.txp_cck_ofdm_gainf_delta =
+                                               ee->ee_cck_ofdm_gain_delta;
+       }
+
+       /* Set antenna idle switch table */
+       AR5K_REG_WRITE_BITS(ah, AR5K_PHY_ANT_CTL,
+                       AR5K_PHY_ANT_CTL_SWTABLE_IDLE,
+                       (ah->ah_antenna[ee_mode][0] |
+                       AR5K_PHY_ANT_CTL_TXRX_EN));
+
+       /* Set antenna switch table */
+       ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[0]],
+               AR5K_PHY_ANT_SWITCH_TABLE_0);
+       ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[1]],
+               AR5K_PHY_ANT_SWITCH_TABLE_1);
+
+       /* Noise floor threshold */
+       ath5k_hw_reg_write(ah,
+               AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
+               AR5K_PHY_NFTHRES);
+
+       if ((channel->hw_value & CHANNEL_TURBO) &&
+       (ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_0)) {
+               /* Switch settling time (Turbo) */
+               AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
+                               AR5K_PHY_SETTLING_SWITCH,
+                               ee->ee_switch_settling_turbo[ee_mode]);
+
+               /* Tx/Rx attenuation (Turbo) */
+               AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN,
+                               AR5K_PHY_GAIN_TXRX_ATTEN,
+                               ee->ee_atn_tx_rx_turbo[ee_mode]);
+
+               /* ADC/PGA desired size (Turbo) */
+               AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
+                               AR5K_PHY_DESIRED_SIZE_ADC,
+                               ee->ee_adc_desired_size_turbo[ee_mode]);
+
+               AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
+                               AR5K_PHY_DESIRED_SIZE_PGA,
+                               ee->ee_pga_desired_size_turbo[ee_mode]);
+
+               /* Tx/Rx margin (Turbo) */
+               AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
+                               AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
+                               ee->ee_margin_tx_rx_turbo[ee_mode]);
+
+       } else {
+               /* Switch settling time */
+               AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
+                               AR5K_PHY_SETTLING_SWITCH,
+                               ee->ee_switch_settling[ee_mode]);
+
+               /* Tx/Rx attenuation */
+               AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN,
+                               AR5K_PHY_GAIN_TXRX_ATTEN,
+                               ee->ee_atn_tx_rx[ee_mode]);
+
+               /* ADC/PGA desired size */
+               AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
+                               AR5K_PHY_DESIRED_SIZE_ADC,
+                               ee->ee_adc_desired_size[ee_mode]);
+
+               AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
+                               AR5K_PHY_DESIRED_SIZE_PGA,
+                               ee->ee_pga_desired_size[ee_mode]);
+
+               /* Tx/Rx margin */
+               if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
+                       AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
+                               AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
+                               ee->ee_margin_tx_rx[ee_mode]);
+       }
+
+       /* XPA delays */
+       ath5k_hw_reg_write(ah,
+               (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
+               (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
+               (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
+               (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY_RF_CTL4);
+
+       /* XLNA delay */
+       AR5K_REG_WRITE_BITS(ah, AR5K_PHY_RF_CTL3,
+                       AR5K_PHY_RF_CTL3_TXE2XLNA_ON,
+                       ee->ee_tx_end2xlna_enable[ee_mode]);
+
+       /* Thresh64 (ANI) */
+       AR5K_REG_WRITE_BITS(ah, AR5K_PHY_NF,
+                       AR5K_PHY_NF_THRESH62,
+                       ee->ee_thr_62[ee_mode]);
+
+
+       /* False detect backoff for channels
+        * that have spur noise. Write the new
+        * cyclic power RSSI threshold. */
+       if (ath5k_hw_chan_has_spur_noise(ah, channel))
+               AR5K_REG_WRITE_BITS(ah, AR5K_PHY_OFDM_SELFCORR,
+                               AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1,
+                               AR5K_INIT_CYCRSSI_THR1 +
+                               ee->ee_false_detect[ee_mode]);
+       else
+               AR5K_REG_WRITE_BITS(ah, AR5K_PHY_OFDM_SELFCORR,
+                               AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1,
+                               AR5K_INIT_CYCRSSI_THR1);
+
+       /* I/Q correction
+        * TODO: Per channel i/q infos ? */
+       AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
+               AR5K_PHY_IQ_CORR_ENABLE |
+               (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
+               ee->ee_q_cal[ee_mode]);
+
+       /* Heavy clipping -disable for now */
+       if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_1)
+               ath5k_hw_reg_write(ah, 0, AR5K_PHY_HEAVY_CLIP_ENABLE);
+
+       return;
+}
+
+/*
+ * Main reset function
+ */
+int ath5k_hw_reset(struct ath5k_hw *ah,
+       struct net80211_channel *channel, int change_channel)
+{
+       u32 s_seq[10], s_ant, s_led[3], staid1_flags, tsf_up, tsf_lo;
+       u32 phy_tst1;
+       u8 mode, freq, ee_mode, ant[2];
+       int i, ret;
+
+       s_ant = 0;
+       ee_mode = 0;
+       staid1_flags = 0;
+       tsf_up = 0;
+       tsf_lo = 0;
+       freq = 0;
+       mode = 0;
+
+       /*
+        * Save some registers before a reset
+        */
+       /*DCU/Antenna selection not available on 5210*/
+       if (ah->ah_version != AR5K_AR5210) {
+
+               switch (channel->hw_value & CHANNEL_MODES) {
+               case CHANNEL_A:
+                       mode = AR5K_MODE_11A;
+                       freq = AR5K_INI_RFGAIN_5GHZ;
+                       ee_mode = AR5K_EEPROM_MODE_11A;
+                       break;
+               case CHANNEL_G:
+                       mode = AR5K_MODE_11G;
+                       freq = AR5K_INI_RFGAIN_2GHZ;
+                       ee_mode = AR5K_EEPROM_MODE_11G;
+                       break;
+               case CHANNEL_B:
+                       mode = AR5K_MODE_11B;
+                       freq = AR5K_INI_RFGAIN_2GHZ;
+                       ee_mode = AR5K_EEPROM_MODE_11B;
+                       break;
+               case CHANNEL_T:
+                       mode = AR5K_MODE_11A_TURBO;
+                       freq = AR5K_INI_RFGAIN_5GHZ;
+                       ee_mode = AR5K_EEPROM_MODE_11A;
+                       break;
+               case CHANNEL_TG:
+                       if (ah->ah_version == AR5K_AR5211) {
+                               DBG("ath5k: TurboG not available on 5211\n");
+                               return -EINVAL;
+                       }
+                       mode = AR5K_MODE_11G_TURBO;
+                       freq = AR5K_INI_RFGAIN_2GHZ;
+                       ee_mode = AR5K_EEPROM_MODE_11G;
+                       break;
+               case CHANNEL_XR:
+                       if (ah->ah_version == AR5K_AR5211) {
+                               DBG("ath5k: XR mode not available on 5211\n");
+                               return -EINVAL;
+                       }
+                       mode = AR5K_MODE_XR;
+                       freq = AR5K_INI_RFGAIN_5GHZ;
+                       ee_mode = AR5K_EEPROM_MODE_11A;
+                       break;
+               default:
+                       DBG("ath5k: invalid channel (%d MHz)\n",
+                           channel->center_freq);
+                       return -EINVAL;
+               }
+
+               if (change_channel) {
+                       /*
+                        * Save frame sequence count
+                        * For revs. after Oahu, only save
+                        * seq num for DCU 0 (Global seq num)
+                        */
+                       if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
+
+                               for (i = 0; i < 10; i++)
+                                       s_seq[i] = ath5k_hw_reg_read(ah,
+                                               AR5K_QUEUE_DCU_SEQNUM(i));
+
+                       } else {
+                               s_seq[0] = ath5k_hw_reg_read(ah,
+                                               AR5K_QUEUE_DCU_SEQNUM(0));
+                       }
+               }
+
+               /* Save default antenna */
+               s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
+
+               if (ah->ah_version == AR5K_AR5212) {
+                       /* Since we are going to write rf buffer
+                        * check if we have any pending gain_F
+                        * optimization settings */
+                       if (change_channel && ah->ah_rf_banks != NULL)
+                               ath5k_hw_gainf_calibrate(ah);
+               }
+       }
+
+       /*GPIOs*/
+       s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) &
+                                       AR5K_PCICFG_LEDSTATE;
+       s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
+       s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
+
+       /* AR5K_STA_ID1 flags, only preserve antenna
+        * settings and ack/cts rate mode */
+       staid1_flags = ath5k_hw_reg_read(ah, AR5K_STA_ID1) &
+                       (AR5K_STA_ID1_DEFAULT_ANTENNA |
+                       AR5K_STA_ID1_DESC_ANTENNA |
+                       AR5K_STA_ID1_RTS_DEF_ANTENNA |
+                       AR5K_STA_ID1_ACKCTS_6MB |
+                       AR5K_STA_ID1_BASE_RATE_11B |
+                       AR5K_STA_ID1_SELFGEN_DEF_ANT);
+
+       /* Wakeup the device */
+       ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, 0);
+       if (ret)
+               return ret;
+
+       /* PHY access enable */
+       if (ah->ah_mac_srev >= AR5K_SREV_AR5211)
+               ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
+       else
+               ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ | 0x40,
+                                                       AR5K_PHY(0));
+
+       /* Write initial settings */
+       ret = ath5k_hw_write_initvals(ah, mode, change_channel);
+       if (ret)
+               return ret;
+
+       /*
+        * 5211/5212 Specific
+        */
+       if (ah->ah_version != AR5K_AR5210) {
+
+               /*
+                * Write initial RF gain settings
+                * This should work for both 5111/5112
+                */
+               ret = ath5k_hw_rfgain_init(ah, freq);
+               if (ret)
+                       return ret;
+
+               mdelay(1);
+
+               /*
+                * Tweak initval settings for revised
+                * chipsets and add some more config
+                * bits
+                */
+               ath5k_hw_tweak_initval_settings(ah, channel);
+
+               /*
+                * Set TX power (FIXME)
+                */
+               ret = ath5k_hw_txpower(ah, channel, ee_mode,
+                                       AR5K_TUNE_DEFAULT_TXPOWER);
+               if (ret)
+                       return ret;
+
+               /* Write rate duration table only on AR5212 */
+               if (ah->ah_version == AR5K_AR5212)
+                       ath5k_hw_write_rate_duration(ah, mode);
+
+               /*
+                * Write RF buffer
+                */
+               ret = ath5k_hw_rfregs_init(ah, channel, mode);
+               if (ret)
+                       return ret;
+
+
+               /* Write OFDM timings on 5212*/
+               if (ah->ah_version == AR5K_AR5212 &&
+                       channel->hw_value & CHANNEL_OFDM) {
+                       ret = ath5k_hw_write_ofdm_timings(ah, channel);
+                       if (ret)
+                               return ret;
+               }
+
+               /*Enable/disable 802.11b mode on 5111
+               (enable 2111 frequency converter + CCK)*/
+               if (ah->ah_radio == AR5K_RF5111) {
+                       if (mode == AR5K_MODE_11B)
+                               AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
+                                   AR5K_TXCFG_B_MODE);
+                       else
+                               AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
+                                   AR5K_TXCFG_B_MODE);
+               }
+
+               /*
+                * In case a fixed antenna was set as default
+                * write the same settings on both AR5K_PHY_ANT_SWITCH_TABLE
+                * registers.
+                */
+               if (s_ant != 0) {
+                       if (s_ant == AR5K_ANT_FIXED_A) /* 1 - Main */
+                               ant[0] = ant[1] = AR5K_ANT_FIXED_A;
+                       else    /* 2 - Aux */
+                               ant[0] = ant[1] = AR5K_ANT_FIXED_B;
+               } else {
+                       ant[0] = AR5K_ANT_FIXED_A;
+                       ant[1] = AR5K_ANT_FIXED_B;
+               }
+
+               /* Commit values from EEPROM */
+               ath5k_hw_commit_eeprom_settings(ah, channel, ant, ee_mode);
+
+       } else {
+               /*
+                * For 5210 we do all initialization using
+                * initvals, so we don't have to modify
+                * any settings (5210 also only supports
+                * a/aturbo modes)
+                */
+               mdelay(1);
+               /* Disable phy and wait */
+               ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
+               mdelay(1);
+       }
+
+       /*
+        * Restore saved values
+        */
+
+       /*DCU/Antenna selection not available on 5210*/
+       if (ah->ah_version != AR5K_AR5210) {
+
+               if (change_channel) {
+                       if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
+                               for (i = 0; i < 10; i++)
+                                       ath5k_hw_reg_write(ah, s_seq[i],
+                                               AR5K_QUEUE_DCU_SEQNUM(i));
+                       } else {
+                               ath5k_hw_reg_write(ah, s_seq[0],
+                                       AR5K_QUEUE_DCU_SEQNUM(0));
+                       }
+               }
+
+               ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
+       }
+
+       /* Ledstate */
+       AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
+
+       /* Gpio settings */
+       ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
+       ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
+
+       /* Restore sta_id flags and preserve our mac address*/
+       ath5k_hw_reg_write(ah, AR5K_LOW_ID(ah->ah_sta_id),
+                                               AR5K_STA_ID0);
+       ath5k_hw_reg_write(ah, staid1_flags | AR5K_HIGH_ID(ah->ah_sta_id),
+                                               AR5K_STA_ID1);
+
+
+       /*
+        * Configure PCU
+        */
+
+       /* Restore bssid and bssid mask */
+       /* XXX: add ah->aid once mac80211 gives this to us */
+       ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
+
+       /* Set PCU config */
+       ath5k_hw_set_opmode(ah);
+
+       /* Clear any pending interrupts
+        * PISR/SISR Not available on 5210 */
+       if (ah->ah_version != AR5K_AR5210)
+               ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
+
+       /* Set RSSI/BRSSI thresholds
+        *
+        * Note: If we decide to set this value
+        * dynamicaly, have in mind that when AR5K_RSSI_THR
+        * register is read it might return 0x40 if we haven't
+        * wrote anything to it plus BMISS RSSI threshold is zeroed.
+        * So doing a save/restore procedure here isn't the right
+        * choice. Instead store it on ath5k_hw */
+       ath5k_hw_reg_write(ah, (AR5K_TUNE_RSSI_THRES |
+                               AR5K_TUNE_BMISS_THRES <<
+                               AR5K_RSSI_THR_BMISS_S),
+                               AR5K_RSSI_THR);
+
+       /* MIC QoS support */
+       if (ah->ah_mac_srev >= AR5K_SREV_AR2413) {
+               ath5k_hw_reg_write(ah, 0x000100aa, AR5K_MIC_QOS_CTL);
+               ath5k_hw_reg_write(ah, 0x00003210, AR5K_MIC_QOS_SEL);
+       }
+
+       /* QoS NOACK Policy */
+       if (ah->ah_version == AR5K_AR5212) {
+               ath5k_hw_reg_write(ah,
+                       AR5K_REG_SM(2, AR5K_QOS_NOACK_2BIT_VALUES) |
+                       AR5K_REG_SM(5, AR5K_QOS_NOACK_BIT_OFFSET)  |
+                       AR5K_REG_SM(0, AR5K_QOS_NOACK_BYTE_OFFSET),
+                       AR5K_QOS_NOACK);
+       }
+
+
+       /*
+        * Configure PHY
+        */
+
+       /* Set channel on PHY */
+       ret = ath5k_hw_channel(ah, channel);
+       if (ret)
+               return ret;
+
+       /*
+        * Enable the PHY and wait until completion
+        * This includes BaseBand and Synthesizer
+        * activation.
+        */
+       ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
+
+       /*
+        * On 5211+ read activation -> rx delay
+        * and use it.
+        *
+        * TODO: Half/quarter rate support
+        */
+       if (ah->ah_version != AR5K_AR5210) {
+               u32 delay;
+               delay = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
+                       AR5K_PHY_RX_DELAY_M;
+               delay = (channel->hw_value & CHANNEL_CCK) ?
+                       ((delay << 2) / 22) : (delay / 10);
+
+               udelay(100 + (2 * delay));
+       } else {
+               mdelay(1);
+       }
+
+       /*
+        * Perform ADC test to see if baseband is ready
+        * Set tx hold and check adc test register
+        */
+       phy_tst1 = ath5k_hw_reg_read(ah, AR5K_PHY_TST1);
+       ath5k_hw_reg_write(ah, AR5K_PHY_TST1_TXHOLD, AR5K_PHY_TST1);
+       for (i = 0; i <= 20; i++) {
+               if (!(ath5k_hw_reg_read(ah, AR5K_PHY_ADC_TEST) & 0x10))
+                       break;
+               udelay(200);
+       }
+       ath5k_hw_reg_write(ah, phy_tst1, AR5K_PHY_TST1);
+
+       /*
+        * Start automatic gain control calibration
+        *
+        * During AGC calibration RX path is re-routed to
+        * a power detector so we don't receive anything.
+        *
+        * This method is used to calibrate some static offsets
+        * used together with on-the fly I/Q calibration (the
+        * one performed via ath5k_hw_phy_calibrate), that doesn't
+        * interrupt rx path.
+        *
+        * While rx path is re-routed to the power detector we also
+        * start a noise floor calibration, to measure the
+        * card's noise floor (the noise we measure when we are not
+        * transmiting or receiving anything).
+        *
+        * If we are in a noisy environment AGC calibration may time
+        * out and/or noise floor calibration might timeout.
+        */
+       AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
+                               AR5K_PHY_AGCCTL_CAL);
+
+       /* At the same time start I/Q calibration for QAM constellation
+        * -no need for CCK- */
+       ah->ah_calibration = 0;
+       if (!(mode == AR5K_MODE_11B)) {
+               ah->ah_calibration = 1;
+               AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
+                               AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
+               AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
+                               AR5K_PHY_IQ_RUN);
+       }
+
+       /* Wait for gain calibration to finish (we check for I/Q calibration
+        * during ath5k_phy_calibrate) */
+       if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
+                       AR5K_PHY_AGCCTL_CAL, 0, 0)) {
+               DBG("ath5k: gain calibration timeout (%d MHz)\n",
+                   channel->center_freq);
+       }
+
+       /*
+        * If we run NF calibration before AGC, it always times out.
+        * Binary HAL starts NF and AGC calibration at the same time
+        * and only waits for AGC to finish. Also if AGC or NF cal.
+        * times out, reset doesn't fail on binary HAL. I believe
+        * that's wrong because since rx path is routed to a detector,
+        * if cal. doesn't finish we won't have RX. Sam's HAL for AR5210/5211
+        * enables noise floor calibration after offset calibration and if noise
+        * floor calibration fails, reset fails. I believe that's
+        * a better approach, we just need to find a polling interval
+        * that suits best, even if reset continues we need to make
+        * sure that rx path is ready.
+        */
+       ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
+
+
+       /*
+        * Configure QCUs/DCUs
+        */
+
+       /* TODO: HW Compression support for data queues */
+       /* TODO: Burst prefetch for data queues */
+
+       /*
+        * Reset queues and start beacon timers at the end of the reset routine
+        * This also sets QCU mask on each DCU for 1:1 qcu to dcu mapping
+        * Note: If we want we can assign multiple qcus on one dcu.
+        */
+       ret = ath5k_hw_reset_tx_queue(ah);
+       if (ret) {
+               DBG("ath5k: failed to reset TX queue\n");
+               return ret;
+       }
+
+       /*
+        * Configure DMA/Interrupts
+        */
+
+       /*
+        * Set Rx/Tx DMA Configuration
+        *
+        * Set standard DMA size (128). Note that
+        * a DMA size of 512 causes rx overruns and tx errors
+        * on pci-e cards (tested on 5424 but since rx overruns
+        * also occur on 5416/5418 with madwifi we set 128
+        * for all PCI-E cards to be safe).
+        *
+        * XXX: need to check 5210 for this
+        * TODO: Check out tx triger level, it's always 64 on dumps but I
+        * guess we can tweak it and see how it goes ;-)
+        */
+       if (ah->ah_version != AR5K_AR5210) {
+               AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
+                       AR5K_TXCFG_SDMAMR, AR5K_DMASIZE_128B);
+               AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
+                       AR5K_RXCFG_SDMAMW, AR5K_DMASIZE_128B);
+       }
+
+       /* Pre-enable interrupts on 5211/5212*/
+       if (ah->ah_version != AR5K_AR5210)
+               ath5k_hw_set_imr(ah, ah->ah_imr);
+
+       /*
+        * Setup RFKill interrupt if rfkill flag is set on eeprom.
+        * TODO: Use gpio pin and polarity infos from eeprom
+        * TODO: Handle this in ath5k_intr because it'll result
+        *       a nasty interrupt storm.
+        */
+#if 0
+       if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
+               ath5k_hw_set_gpio_input(ah, 0);
+               ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
+               if (ah->ah_gpio[0] == 0)
+                       ath5k_hw_set_gpio_intr(ah, 0, 1);
+               else
+                       ath5k_hw_set_gpio_intr(ah, 0, 0);
+       }
+#endif
+
+       /*
+        * Disable beacons and reset the register
+        */
+       AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
+                       AR5K_BEACON_RESET_TSF);
+
+       return 0;
+}
+
+#undef _ATH5K_RESET
diff --git a/src/drivers/net/ath5k/base.h b/src/drivers/net/ath5k/base.h
new file mode 100644 (file)
index 0000000..45dad07
--- /dev/null
@@ -0,0 +1,140 @@
+/*-
+ * Copyright (c) 2002-2007 Sam Leffler, Errno Consulting
+ * All rights reserved.
+ *
+ * Modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>
+ * Original from Linux kernel 2.6.30.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
+ *    redistribution must be conditioned upon including a substantially
+ *    similar Disclaimer requirement for further binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+/*
+ * Defintions for the Atheros Wireless LAN controller driver.
+ */
+#ifndef _DEV_ATH_ATHVAR_H
+#define _DEV_ATH_ATHVAR_H
+
+FILE_LICENCE ( BSD3 );
+
+#include "ath5k.h"
+#include <gpxe/iobuf.h>
+
+#define        ATH_RXBUF       16              /* number of RX buffers */
+#define        ATH_TXBUF       16              /* number of TX buffers */
+
+struct ath5k_buf {
+       struct list_head        list;
+       unsigned int            flags;  /* rx descriptor flags */
+       struct ath5k_desc       *desc;  /* virtual addr of desc */
+       u32                     daddr;  /* physical addr of desc */
+       struct io_buffer        *iob;   /* I/O buffer for buf */
+       u32                     iobaddr;/* physical addr of iob data */
+};
+
+/*
+ * Data transmit queue state.  One of these exists for each
+ * hardware transmit queue.  Packets sent to us from above
+ * are assigned to queues based on their priority.  Not all
+ * devices support a complete set of hardware transmit queues.
+ * For those devices the array sc_ac2q will map multiple
+ * priorities to fewer hardware queues (typically all to one
+ * hardware queue).
+ */
+struct ath5k_txq {
+       unsigned int            qnum;   /* hardware q number */
+       u32                     *link;  /* link ptr in last TX desc */
+       struct list_head        q;      /* transmit queue */
+       int                     setup;
+};
+
+#if CHAN_DEBUG
+#define ATH_CHAN_MAX   (26+26+26+200+200)
+#else
+#define ATH_CHAN_MAX   (14+14+14+252+20)
+#endif
+
+/* Software Carrier, keeps track of the driver state
+ * associated with an instance of a device */
+struct ath5k_softc {
+       struct pci_device       *pdev;          /* for dma mapping */
+       void                    *iobase;        /* address of the device */
+       struct net80211_device  *dev;           /* IEEE 802.11 common */
+       struct ath5k_hw         *ah;            /* Atheros HW */
+       struct net80211_hw_info *hwinfo;
+       int                     curband;
+       int                     irq_ena;        /* interrupts enabled */
+
+       struct ath5k_buf        *bufptr;        /* allocated buffer ptr */
+       struct ath5k_desc       *desc;          /* TX/RX descriptors */
+       u32                     desc_daddr;     /* DMA (physical) address */
+       size_t                  desc_len;       /* size of TX/RX descriptors */
+       u16                     cachelsz;       /* cache line size */
+
+       int                     status;
+#define ATH_STAT_INVALID       0x01            /* disable hardware accesses */
+#define ATH_STAT_MRRETRY       0x02            /* multi-rate retry support */
+#define ATH_STAT_PROMISC       0x04
+#define ATH_STAT_LEDSOFT       0x08            /* enable LED gpio status */
+#define ATH_STAT_STARTED       0x10            /* opened & irqs enabled */
+
+       unsigned int            filter_flags;   /* HW flags, AR5K_RX_FILTER_* */
+       unsigned int            curmode;        /* current phy mode */
+       struct net80211_channel *curchan;       /* current h/w channel */
+
+       enum ath5k_int          imask;          /* interrupt mask copy */
+
+       u8                      bssidmask[ETH_ALEN];
+
+       unsigned int            rxbufsize;      /* rx size based on mtu */
+       struct list_head        rxbuf;          /* receive buffer */
+       u32                     *rxlink;        /* link ptr in last RX desc */
+
+       struct list_head        txbuf;          /* transmit buffer */
+       unsigned int            txbuf_len;      /* buf count in txbuf list */
+       struct ath5k_txq        txq;            /* tx queue */
+
+       int                     last_calib_ticks;
+
+       int                     power_level;    /* Requested tx power in dbm */
+       int                     assoc;          /* assocate state */
+
+       int                     hw_rate;        /* Hardware tx rate code */
+       int                     hw_rtscts_rate; /* Hardware rts/cts rate code */
+};
+
+#define ath5k_hw_hasbssidmask(_ah) \
+       (ath5k_hw_get_capability(_ah, AR5K_CAP_BSSIDMASK, 0, NULL) == 0)
+#define ath5k_hw_hasveol(_ah) \
+       (ath5k_hw_get_capability(_ah, AR5K_CAP_VEOL, 0, NULL) == 0)
+
+#endif
diff --git a/src/drivers/net/ath5k/desc.h b/src/drivers/net/ath5k/desc.h
new file mode 100644 (file)
index 0000000..6e11b0d
--- /dev/null
@@ -0,0 +1,332 @@
+/*
+ * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/*
+ * Internal RX/TX descriptor structures
+ * (rX: reserved fields possibily used by future versions of the ar5k chipset)
+ */
+
+/*
+ * common hardware RX control descriptor
+ */
+struct ath5k_hw_rx_ctl {
+       u32     rx_control_0; /* RX control word 0 */
+       u32     rx_control_1; /* RX control word 1 */
+} __attribute__ ((packed));
+
+/* RX control word 0 field/sflags */
+#define AR5K_DESC_RX_CTL0                      0x00000000
+
+/* RX control word 1 fields/flags */
+#define AR5K_DESC_RX_CTL1_BUF_LEN              0x00000fff
+#define AR5K_DESC_RX_CTL1_INTREQ               0x00002000
+
+/*
+ * common hardware RX status descriptor
+ * 5210/11 and 5212 differ only in the flags defined below
+ */
+struct ath5k_hw_rx_status {
+       u32     rx_status_0; /* RX status word 0 */
+       u32     rx_status_1; /* RX status word 1 */
+} __attribute__ ((packed));
+
+/* 5210/5211 */
+/* RX status word 0 fields/flags */
+#define AR5K_5210_RX_DESC_STATUS0_DATA_LEN             0x00000fff
+#define AR5K_5210_RX_DESC_STATUS0_MORE                 0x00001000
+#define AR5K_5210_RX_DESC_STATUS0_RECEIVE_RATE         0x00078000
+#define AR5K_5210_RX_DESC_STATUS0_RECEIVE_RATE_S       15
+#define AR5K_5210_RX_DESC_STATUS0_RECEIVE_SIGNAL       0x07f80000
+#define AR5K_5210_RX_DESC_STATUS0_RECEIVE_SIGNAL_S     19
+#define AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANTENNA      0x38000000
+#define AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANTENNA_S    27
+
+/* RX status word 1 fields/flags */
+#define AR5K_5210_RX_DESC_STATUS1_DONE                 0x00000001
+#define AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK     0x00000002
+#define AR5K_5210_RX_DESC_STATUS1_CRC_ERROR            0x00000004
+#define AR5K_5210_RX_DESC_STATUS1_FIFO_OVERRUN         0x00000008
+#define AR5K_5210_RX_DESC_STATUS1_DECRYPT_CRC_ERROR    0x00000010
+#define AR5K_5210_RX_DESC_STATUS1_PHY_ERROR            0x000000e0
+#define AR5K_5210_RX_DESC_STATUS1_PHY_ERROR_S          5
+#define AR5K_5210_RX_DESC_STATUS1_KEY_INDEX_VALID      0x00000100
+#define AR5K_5210_RX_DESC_STATUS1_KEY_INDEX            0x00007e00
+#define AR5K_5210_RX_DESC_STATUS1_KEY_INDEX_S          9
+#define AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP    0x0fff8000
+#define AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP_S  15
+#define AR5K_5210_RX_DESC_STATUS1_KEY_CACHE_MISS       0x10000000
+
+/* 5212 */
+/* RX status word 0 fields/flags */
+#define AR5K_5212_RX_DESC_STATUS0_DATA_LEN             0x00000fff
+#define AR5K_5212_RX_DESC_STATUS0_MORE                 0x00001000
+#define AR5K_5212_RX_DESC_STATUS0_DECOMP_CRC_ERROR     0x00002000
+#define AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE         0x000f8000
+#define AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE_S       15
+#define AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL       0x0ff00000
+#define AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL_S     20
+#define AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA      0xf0000000
+#define AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA_S    28
+
+/* RX status word 1 fields/flags */
+#define AR5K_5212_RX_DESC_STATUS1_DONE                 0x00000001
+#define AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK     0x00000002
+#define AR5K_5212_RX_DESC_STATUS1_CRC_ERROR            0x00000004
+#define AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR    0x00000008
+#define AR5K_5212_RX_DESC_STATUS1_PHY_ERROR            0x00000010
+#define AR5K_5212_RX_DESC_STATUS1_MIC_ERROR            0x00000020
+#define AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_VALID      0x00000100
+#define AR5K_5212_RX_DESC_STATUS1_KEY_INDEX            0x0000fe00
+#define AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_S          9
+#define AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP    0x7fff0000
+#define AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP_S  16
+#define AR5K_5212_RX_DESC_STATUS1_KEY_CACHE_MISS       0x80000000
+
+/*
+ * common hardware RX error descriptor
+ */
+struct ath5k_hw_rx_error {
+       u32     rx_error_0; /* RX status word 0 */
+       u32     rx_error_1; /* RX status word 1 */
+} __attribute__ ((packed));
+
+/* RX error word 0 fields/flags */
+#define AR5K_RX_DESC_ERROR0                    0x00000000
+
+/* RX error word 1 fields/flags */
+#define AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE     0x0000ff00
+#define AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE_S   8
+
+/* PHY Error codes */
+#define AR5K_DESC_RX_PHY_ERROR_NONE            0x00
+#define AR5K_DESC_RX_PHY_ERROR_TIMING          0x20
+#define AR5K_DESC_RX_PHY_ERROR_PARITY          0x40
+#define AR5K_DESC_RX_PHY_ERROR_RATE            0x60
+#define AR5K_DESC_RX_PHY_ERROR_LENGTH          0x80
+#define AR5K_DESC_RX_PHY_ERROR_64QAM           0xa0
+#define AR5K_DESC_RX_PHY_ERROR_SERVICE         0xc0
+#define AR5K_DESC_RX_PHY_ERROR_TRANSMITOVR     0xe0
+
+/*
+ * 5210/5211 hardware 2-word TX control descriptor
+ */
+struct ath5k_hw_2w_tx_ctl {
+       u32     tx_control_0; /* TX control word 0 */
+       u32     tx_control_1; /* TX control word 1 */
+} __attribute__ ((packed));
+
+/* TX control word 0 fields/flags */
+#define AR5K_2W_TX_DESC_CTL0_FRAME_LEN         0x00000fff
+#define AR5K_2W_TX_DESC_CTL0_HEADER_LEN                0x0003f000 /*[5210 ?]*/
+#define AR5K_2W_TX_DESC_CTL0_HEADER_LEN_S      12
+#define AR5K_2W_TX_DESC_CTL0_XMIT_RATE         0x003c0000
+#define AR5K_2W_TX_DESC_CTL0_XMIT_RATE_S       18
+#define AR5K_2W_TX_DESC_CTL0_RTSENA            0x00400000
+#define AR5K_2W_TX_DESC_CTL0_CLRDMASK          0x01000000
+#define AR5K_2W_TX_DESC_CTL0_LONG_PACKET       0x00800000 /*[5210]*/
+#define AR5K_2W_TX_DESC_CTL0_VEOL              0x00800000 /*[5211]*/
+#define AR5K_2W_TX_DESC_CTL0_FRAME_TYPE                0x1c000000 /*[5210]*/
+#define AR5K_2W_TX_DESC_CTL0_FRAME_TYPE_S      26
+#define AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT_5210        0x02000000
+#define AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT_5211        0x1e000000
+
+#define AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT                     \
+               (ah->ah_version == AR5K_AR5210 ?                \
+               AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT_5210 :       \
+               AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT_5211)
+
+#define AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT_S   25
+#define AR5K_2W_TX_DESC_CTL0_INTREQ            0x20000000
+#define AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID 0x40000000
+
+/* TX control word 1 fields/flags */
+#define AR5K_2W_TX_DESC_CTL1_BUF_LEN           0x00000fff
+#define AR5K_2W_TX_DESC_CTL1_MORE              0x00001000
+#define AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX_5210    0x0007e000
+#define AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX_5211    0x000fe000
+
+#define AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX                         \
+                       (ah->ah_version == AR5K_AR5210 ?                \
+                       AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX_5210 :   \
+                       AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX_5211)
+
+#define AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX_S       13
+#define AR5K_2W_TX_DESC_CTL1_FRAME_TYPE                0x00700000 /*[5211]*/
+#define AR5K_2W_TX_DESC_CTL1_FRAME_TYPE_S      20
+#define AR5K_2W_TX_DESC_CTL1_NOACK             0x00800000 /*[5211]*/
+#define AR5K_2W_TX_DESC_CTL1_RTS_DURATION      0xfff80000 /*[5210 ?]*/
+
+/* Frame types */
+#define AR5K_AR5210_TX_DESC_FRAME_TYPE_NORMAL   0x00
+#define AR5K_AR5210_TX_DESC_FRAME_TYPE_ATIM     0x04
+#define AR5K_AR5210_TX_DESC_FRAME_TYPE_PSPOLL   0x08
+#define AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY 0x0c
+#define AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS     0x10
+
+/*
+ * 5212 hardware 4-word TX control descriptor
+ */
+struct ath5k_hw_4w_tx_ctl {
+       u32     tx_control_0; /* TX control word 0 */
+
+#define AR5K_4W_TX_DESC_CTL0_FRAME_LEN         0x00000fff
+#define AR5K_4W_TX_DESC_CTL0_XMIT_POWER                0x003f0000
+#define AR5K_4W_TX_DESC_CTL0_XMIT_POWER_S      16
+#define AR5K_4W_TX_DESC_CTL0_RTSENA            0x00400000
+#define AR5K_4W_TX_DESC_CTL0_VEOL              0x00800000
+#define AR5K_4W_TX_DESC_CTL0_CLRDMASK          0x01000000
+#define AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT     0x1e000000
+#define AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT_S   25
+#define AR5K_4W_TX_DESC_CTL0_INTREQ            0x20000000
+#define AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID 0x40000000
+#define AR5K_4W_TX_DESC_CTL0_CTSENA            0x80000000
+
+       u32     tx_control_1; /* TX control word 1 */
+
+#define AR5K_4W_TX_DESC_CTL1_BUF_LEN           0x00000fff
+#define AR5K_4W_TX_DESC_CTL1_MORE              0x00001000
+#define AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX 0x000fe000
+#define AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX_S       13
+#define AR5K_4W_TX_DESC_CTL1_FRAME_TYPE                0x00f00000
+#define AR5K_4W_TX_DESC_CTL1_FRAME_TYPE_S      20
+#define AR5K_4W_TX_DESC_CTL1_NOACK             0x01000000
+#define AR5K_4W_TX_DESC_CTL1_COMP_PROC         0x06000000
+#define AR5K_4W_TX_DESC_CTL1_COMP_PROC_S       25
+#define AR5K_4W_TX_DESC_CTL1_COMP_IV_LEN       0x18000000
+#define AR5K_4W_TX_DESC_CTL1_COMP_IV_LEN_S     27
+#define AR5K_4W_TX_DESC_CTL1_COMP_ICV_LEN      0x60000000
+#define AR5K_4W_TX_DESC_CTL1_COMP_ICV_LEN_S    29
+
+       u32     tx_control_2; /* TX control word 2 */
+
+#define AR5K_4W_TX_DESC_CTL2_RTS_DURATION              0x00007fff
+#define AR5K_4W_TX_DESC_CTL2_DURATION_UPDATE_ENABLE    0x00008000
+#define AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0               0x000f0000
+#define AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0_S             16
+#define AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1               0x00f00000
+#define AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1_S             20
+#define AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2               0x0f000000
+#define AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2_S             24
+#define AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3               0xf0000000
+#define AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3_S             28
+
+       u32     tx_control_3; /* TX control word 3 */
+
+#define AR5K_4W_TX_DESC_CTL3_XMIT_RATE0                0x0000001f
+#define AR5K_4W_TX_DESC_CTL3_XMIT_RATE1                0x000003e0
+#define AR5K_4W_TX_DESC_CTL3_XMIT_RATE1_S      5
+#define AR5K_4W_TX_DESC_CTL3_XMIT_RATE2                0x00007c00
+#define AR5K_4W_TX_DESC_CTL3_XMIT_RATE2_S      10
+#define AR5K_4W_TX_DESC_CTL3_XMIT_RATE3                0x000f8000
+#define AR5K_4W_TX_DESC_CTL3_XMIT_RATE3_S      15
+#define AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE      0x01f00000
+#define AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE_S    20
+} __attribute__ ((packed));
+
+/*
+ * Common TX status descriptor
+ */
+struct ath5k_hw_tx_status {
+       u32     tx_status_0; /* TX status word 0 */
+       u32     tx_status_1; /* TX status word 1 */
+} __attribute__ ((packed));
+
+/* TX status word 0 fields/flags */
+#define AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK     0x00000001
+#define AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES 0x00000002
+#define AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN     0x00000004
+#define AR5K_DESC_TX_STATUS0_FILTERED          0x00000008
+/*???
+#define AR5K_DESC_TX_STATUS0_RTS_FAIL_COUNT    0x000000f0
+#define AR5K_DESC_TX_STATUS0_RTS_FAIL_COUNT_S  4
+*/
+#define AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT 0x000000f0
+#define AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT_S       4
+/*???
+#define AR5K_DESC_TX_STATUS0_DATA_FAIL_COUNT   0x00000f00
+#define AR5K_DESC_TX_STATUS0_DATA_FAIL_COUNT_S 8
+*/
+#define AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT  0x00000f00
+#define AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT_S        8
+#define AR5K_DESC_TX_STATUS0_VIRT_COLL_COUNT   0x0000f000
+#define AR5K_DESC_TX_STATUS0_VIRT_COLL_COUNT_S 12
+#define AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP    0xffff0000
+#define AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP_S  16
+
+/* TX status word 1 fields/flags */
+#define AR5K_DESC_TX_STATUS1_DONE              0x00000001
+#define AR5K_DESC_TX_STATUS1_SEQ_NUM           0x00001ffe
+#define AR5K_DESC_TX_STATUS1_SEQ_NUM_S         1
+#define AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH  0x001fe000
+#define AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH_S        13
+#define AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX    0x00600000
+#define AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX_S  21
+#define AR5K_DESC_TX_STATUS1_COMP_SUCCESS      0x00800000
+#define AR5K_DESC_TX_STATUS1_XMIT_ANTENNA      0x01000000
+
+/*
+ * 5210/5211 hardware TX descriptor
+ */
+struct ath5k_hw_5210_tx_desc {
+       struct ath5k_hw_2w_tx_ctl       tx_ctl;
+       struct ath5k_hw_tx_status       tx_stat;
+} __attribute__ ((packed));
+
+/*
+ * 5212 hardware TX descriptor
+ */
+struct ath5k_hw_5212_tx_desc {
+       struct ath5k_hw_4w_tx_ctl       tx_ctl;
+       struct ath5k_hw_tx_status       tx_stat;
+} __attribute__ ((packed));
+
+/*
+ * common hardware RX descriptor
+ */
+struct ath5k_hw_all_rx_desc {
+       struct ath5k_hw_rx_ctl                  rx_ctl;
+       union {
+               struct ath5k_hw_rx_status       rx_stat;
+               struct ath5k_hw_rx_error        rx_err;
+       } u;
+} __attribute__ ((packed));
+
+/*
+ * Atheros hardware descriptor
+ * This is read and written to by the hardware
+ */
+struct ath5k_desc {
+       u32     ds_link;        /* physical address of the next descriptor */
+       u32     ds_data;        /* physical address of data buffer (skb) */
+
+       union {
+               struct ath5k_hw_5210_tx_desc    ds_tx5210;
+               struct ath5k_hw_5212_tx_desc    ds_tx5212;
+               struct ath5k_hw_all_rx_desc     ds_rx;
+       } ud;
+} __attribute__ ((packed));
+
+#define AR5K_RXDESC_INTREQ     0x0020
+
+#define AR5K_TXDESC_CLRDMASK   0x0001
+#define AR5K_TXDESC_NOACK      0x0002  /*[5211+]*/
+#define AR5K_TXDESC_RTSENA     0x0004
+#define AR5K_TXDESC_CTSENA     0x0008
+#define AR5K_TXDESC_INTREQ     0x0010
+#define AR5K_TXDESC_VEOL       0x0020  /*[5211+]*/
+
diff --git a/src/drivers/net/ath5k/eeprom.h b/src/drivers/net/ath5k/eeprom.h
new file mode 100644 (file)
index 0000000..4d6250a
--- /dev/null
@@ -0,0 +1,441 @@
+/*
+ * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/*
+ * Common ar5xxx EEPROM data offsets (set these on AR5K_EEPROM_BASE)
+ */
+#define AR5K_EEPROM_MAGIC              0x003d  /* EEPROM Magic number */
+#define AR5K_EEPROM_MAGIC_VALUE                0x5aa5  /* Default - found on EEPROM */
+#define AR5K_EEPROM_MAGIC_5212         0x0000145c /* 5212 */
+#define AR5K_EEPROM_MAGIC_5211         0x0000145b /* 5211 */
+#define AR5K_EEPROM_MAGIC_5210         0x0000145a /* 5210 */
+
+#define        AR5K_EEPROM_IS_HB63             0x000b  /* Talon detect */
+#define AR5K_EEPROM_REG_DOMAIN         0x00bf  /* EEPROM regdom */
+#define AR5K_EEPROM_CHECKSUM           0x00c0  /* EEPROM checksum */
+#define AR5K_EEPROM_INFO_BASE          0x00c0  /* EEPROM header */
+#define AR5K_EEPROM_INFO_MAX           (0x400 - AR5K_EEPROM_INFO_BASE)
+#define AR5K_EEPROM_INFO_CKSUM         0xffff
+#define AR5K_EEPROM_INFO(_n)           (AR5K_EEPROM_INFO_BASE + (_n))
+
+#define AR5K_EEPROM_VERSION            AR5K_EEPROM_INFO(1)     /* EEPROM Version */
+#define AR5K_EEPROM_VERSION_3_0                0x3000  /* No idea what's going on before this version */
+#define AR5K_EEPROM_VERSION_3_1                0x3001  /* ob/db values for 2Ghz (ar5211_rfregs) */
+#define AR5K_EEPROM_VERSION_3_2                0x3002  /* different frequency representation (eeprom_bin2freq) */
+#define AR5K_EEPROM_VERSION_3_3                0x3003  /* offsets changed, has 32 CTLs (see below) and ee_false_detect (eeprom_read_modes) */
+#define AR5K_EEPROM_VERSION_3_4                0x3004  /* has ee_i_gain, ee_cck_ofdm_power_delta (eeprom_read_modes) */
+#define AR5K_EEPROM_VERSION_4_0                0x4000  /* has ee_misc, ee_cal_pier, ee_turbo_max_power and ee_xr_power (eeprom_init) */
+#define AR5K_EEPROM_VERSION_4_1                0x4001  /* has ee_margin_tx_rx (eeprom_init) */
+#define AR5K_EEPROM_VERSION_4_2                0x4002  /* has ee_cck_ofdm_gain_delta (eeprom_init) */
+#define AR5K_EEPROM_VERSION_4_3                0x4003  /* power calibration changes */
+#define AR5K_EEPROM_VERSION_4_4                0x4004
+#define AR5K_EEPROM_VERSION_4_5                0x4005
+#define AR5K_EEPROM_VERSION_4_6                0x4006  /* has ee_scaled_cck_delta */
+#define AR5K_EEPROM_VERSION_4_7                0x3007  /* 4007 ? */
+#define AR5K_EEPROM_VERSION_4_9                0x4009  /* EAR futureproofing */
+#define AR5K_EEPROM_VERSION_5_0                0x5000  /* Has 2413 PDADC calibration etc */
+#define AR5K_EEPROM_VERSION_5_1                0x5001  /* Has capability values */
+#define AR5K_EEPROM_VERSION_5_3                0x5003  /* Has spur mitigation tables */
+
+#define AR5K_EEPROM_MODE_11A           0
+#define AR5K_EEPROM_MODE_11B           1
+#define AR5K_EEPROM_MODE_11G           2
+
+#define AR5K_EEPROM_HDR                        AR5K_EEPROM_INFO(2)     /* Header that contains the device caps */
+#define AR5K_EEPROM_HDR_11A(_v)                (((_v) >> AR5K_EEPROM_MODE_11A) & 0x1)
+#define AR5K_EEPROM_HDR_11B(_v)                (((_v) >> AR5K_EEPROM_MODE_11B) & 0x1)
+#define AR5K_EEPROM_HDR_11G(_v)                (((_v) >> AR5K_EEPROM_MODE_11G) & 0x1)
+#define AR5K_EEPROM_HDR_T_2GHZ_DIS(_v) (((_v) >> 3) & 0x1)     /* Disable turbo for 2Ghz (?) */
+#define AR5K_EEPROM_HDR_T_5GHZ_DBM(_v) (((_v) >> 4) & 0x7f)    /* Max turbo power for a/XR mode (eeprom_init) */
+#define AR5K_EEPROM_HDR_DEVICE(_v)     (((_v) >> 11) & 0x7)
+#define AR5K_EEPROM_HDR_RFKILL(_v)     (((_v) >> 14) & 0x1)    /* Device has RFKill support */
+#define AR5K_EEPROM_HDR_T_5GHZ_DIS(_v) (((_v) >> 15) & 0x1)    /* Disable turbo for 5Ghz */
+
+#define AR5K_EEPROM_RFKILL_GPIO_SEL    0x0000001c
+#define AR5K_EEPROM_RFKILL_GPIO_SEL_S  2
+#define AR5K_EEPROM_RFKILL_POLARITY    0x00000002
+#define AR5K_EEPROM_RFKILL_POLARITY_S  1
+
+/* Newer EEPROMs are using a different offset */
+#define AR5K_EEPROM_OFF(_v, _v3_0, _v3_3) \
+       (((_v) >= AR5K_EEPROM_VERSION_3_3) ? _v3_3 : _v3_0)
+
+#define AR5K_EEPROM_ANT_GAIN(_v)       AR5K_EEPROM_OFF(_v, 0x00c4, 0x00c3)
+#define AR5K_EEPROM_ANT_GAIN_5GHZ(_v)  ((s8)(((_v) >> 8) & 0xff))
+#define AR5K_EEPROM_ANT_GAIN_2GHZ(_v)  ((s8)((_v) & 0xff))
+
+/* Misc values available since EEPROM 4.0 */
+#define AR5K_EEPROM_MISC0              AR5K_EEPROM_INFO(4)
+#define AR5K_EEPROM_EARSTART(_v)       ((_v) & 0xfff)
+#define AR5K_EEPROM_HDR_XR2_DIS(_v)    (((_v) >> 12) & 0x1)
+#define AR5K_EEPROM_HDR_XR5_DIS(_v)    (((_v) >> 13) & 0x1)
+#define AR5K_EEPROM_EEMAP(_v)          (((_v) >> 14) & 0x3)
+
+#define AR5K_EEPROM_MISC1                      AR5K_EEPROM_INFO(5)
+#define AR5K_EEPROM_TARGET_PWRSTART(_v)                ((_v) & 0xfff)
+#define AR5K_EEPROM_HAS32KHZCRYSTAL(_v)                (((_v) >> 14) & 0x1)
+#define AR5K_EEPROM_HAS32KHZCRYSTAL_OLD(_v)    (((_v) >> 15) & 0x1)
+
+#define AR5K_EEPROM_MISC2                      AR5K_EEPROM_INFO(6)
+#define AR5K_EEPROM_EEP_FILE_VERSION(_v)       (((_v) >> 8) & 0xff)
+#define AR5K_EEPROM_EAR_FILE_VERSION(_v)       ((_v) & 0xff)
+
+#define AR5K_EEPROM_MISC3              AR5K_EEPROM_INFO(7)
+#define AR5K_EEPROM_ART_BUILD_NUM(_v)  (((_v) >> 10) & 0x3f)
+#define AR5K_EEPROM_EAR_FILE_ID(_v)    ((_v) & 0xff)
+
+#define AR5K_EEPROM_MISC4              AR5K_EEPROM_INFO(8)
+#define AR5K_EEPROM_CAL_DATA_START(_v) (((_v) >> 4) & 0xfff)
+#define AR5K_EEPROM_MASK_R0(_v)                (((_v) >> 2) & 0x3)
+#define AR5K_EEPROM_MASK_R1(_v)                ((_v) & 0x3)
+
+#define AR5K_EEPROM_MISC5              AR5K_EEPROM_INFO(9)
+#define AR5K_EEPROM_COMP_DIS(_v)       ((_v) & 0x1)
+#define AR5K_EEPROM_AES_DIS(_v)                (((_v) >> 1) & 0x1)
+#define AR5K_EEPROM_FF_DIS(_v)         (((_v) >> 2) & 0x1)
+#define AR5K_EEPROM_BURST_DIS(_v)      (((_v) >> 3) & 0x1)
+#define AR5K_EEPROM_MAX_QCU(_v)                (((_v) >> 4) & 0xf)
+#define AR5K_EEPROM_HEAVY_CLIP_EN(_v)  (((_v) >> 8) & 0x1)
+#define AR5K_EEPROM_KEY_CACHE_SIZE(_v) (((_v) >> 12) & 0xf)
+
+#define AR5K_EEPROM_MISC6              AR5K_EEPROM_INFO(10)
+#define AR5K_EEPROM_TX_CHAIN_DIS       ((_v) & 0x8)
+#define AR5K_EEPROM_RX_CHAIN_DIS       (((_v) >> 3) & 0x8)
+#define AR5K_EEPROM_FCC_MID_EN         (((_v) >> 6) & 0x1)
+#define AR5K_EEPROM_JAP_U1EVEN_EN      (((_v) >> 7) & 0x1)
+#define AR5K_EEPROM_JAP_U2_EN          (((_v) >> 8) & 0x1)
+#define AR5K_EEPROM_JAP_U1ODD_EN       (((_v) >> 9) & 0x1)
+#define AR5K_EEPROM_JAP_11A_NEW_EN     (((_v) >> 10) & 0x1)
+
+/* calibration settings */
+#define AR5K_EEPROM_MODES_11A(_v)      AR5K_EEPROM_OFF(_v, 0x00c5, 0x00d4)
+#define AR5K_EEPROM_MODES_11B(_v)      AR5K_EEPROM_OFF(_v, 0x00d0, 0x00f2)
+#define AR5K_EEPROM_MODES_11G(_v)      AR5K_EEPROM_OFF(_v, 0x00da, 0x010d)
+#define AR5K_EEPROM_CTL(_v)            AR5K_EEPROM_OFF(_v, 0x00e4, 0x0128)     /* Conformance test limits */
+#define AR5K_EEPROM_GROUPS_START(_v)   AR5K_EEPROM_OFF(_v, 0x0100, 0x0150)     /* Start of Groups */
+#define AR5K_EEPROM_GROUP1_OFFSET      0x0
+#define AR5K_EEPROM_GROUP2_OFFSET      0x5
+#define AR5K_EEPROM_GROUP3_OFFSET      0x37
+#define AR5K_EEPROM_GROUP4_OFFSET      0x46
+#define AR5K_EEPROM_GROUP5_OFFSET      0x55
+#define AR5K_EEPROM_GROUP6_OFFSET      0x65
+#define AR5K_EEPROM_GROUP7_OFFSET      0x69
+#define AR5K_EEPROM_GROUP8_OFFSET      0x6f
+
+#define AR5K_EEPROM_TARGET_PWR_OFF_11A(_v)     AR5K_EEPROM_OFF(_v, AR5K_EEPROM_GROUPS_START(_v) + \
+                                                               AR5K_EEPROM_GROUP5_OFFSET, 0x0000)
+#define AR5K_EEPROM_TARGET_PWR_OFF_11B(_v)     AR5K_EEPROM_OFF(_v, AR5K_EEPROM_GROUPS_START(_v) + \
+                                                               AR5K_EEPROM_GROUP6_OFFSET, 0x0010)
+#define AR5K_EEPROM_TARGET_PWR_OFF_11G(_v)     AR5K_EEPROM_OFF(_v, AR5K_EEPROM_GROUPS_START(_v) + \
+                                                               AR5K_EEPROM_GROUP7_OFFSET, 0x0014)
+
+/* [3.1 - 3.3] */
+#define AR5K_EEPROM_OBDB0_2GHZ         0x00ec
+#define AR5K_EEPROM_OBDB1_2GHZ         0x00ed
+
+#define AR5K_EEPROM_PROTECT            0x003f  /* EEPROM protect status */
+#define AR5K_EEPROM_PROTECT_RD_0_31    0x0001  /* Read protection bit for offsets 0x0 - 0x1f */
+#define AR5K_EEPROM_PROTECT_WR_0_31    0x0002  /* Write protection bit for offsets 0x0 - 0x1f */
+#define AR5K_EEPROM_PROTECT_RD_32_63   0x0004  /* 0x20 - 0x3f */
+#define AR5K_EEPROM_PROTECT_WR_32_63   0x0008
+#define AR5K_EEPROM_PROTECT_RD_64_127  0x0010  /* 0x40 - 0x7f */
+#define AR5K_EEPROM_PROTECT_WR_64_127  0x0020
+#define AR5K_EEPROM_PROTECT_RD_128_191 0x0040  /* 0x80 - 0xbf (regdom) */
+#define AR5K_EEPROM_PROTECT_WR_128_191 0x0080
+#define AR5K_EEPROM_PROTECT_RD_192_207 0x0100  /* 0xc0 - 0xcf */
+#define AR5K_EEPROM_PROTECT_WR_192_207 0x0200
+#define AR5K_EEPROM_PROTECT_RD_208_223 0x0400  /* 0xd0 - 0xdf */
+#define AR5K_EEPROM_PROTECT_WR_208_223 0x0800
+#define AR5K_EEPROM_PROTECT_RD_224_239 0x1000  /* 0xe0 - 0xef */
+#define AR5K_EEPROM_PROTECT_WR_224_239 0x2000
+#define AR5K_EEPROM_PROTECT_RD_240_255 0x4000  /* 0xf0 - 0xff */
+#define AR5K_EEPROM_PROTECT_WR_240_255 0x8000
+
+/* Some EEPROM defines */
+#define AR5K_EEPROM_EEP_SCALE          100
+#define AR5K_EEPROM_EEP_DELTA          10
+#define AR5K_EEPROM_N_MODES            3
+#define AR5K_EEPROM_N_5GHZ_CHAN                10
+#define AR5K_EEPROM_N_2GHZ_CHAN                3
+#define AR5K_EEPROM_N_2GHZ_CHAN_2413   4
+#define        AR5K_EEPROM_N_2GHZ_CHAN_MAX     4
+#define AR5K_EEPROM_MAX_CHAN           10
+#define AR5K_EEPROM_N_PWR_POINTS_5111  11
+#define AR5K_EEPROM_N_PCDAC            11
+#define AR5K_EEPROM_N_PHASE_CAL                5
+#define AR5K_EEPROM_N_TEST_FREQ                8
+#define AR5K_EEPROM_N_EDGES            8
+#define AR5K_EEPROM_N_INTERCEPTS       11
+#define AR5K_EEPROM_FREQ_M(_v)         AR5K_EEPROM_OFF(_v, 0x7f, 0xff)
+#define AR5K_EEPROM_PCDAC_M            0x3f
+#define AR5K_EEPROM_PCDAC_START                1
+#define AR5K_EEPROM_PCDAC_STOP         63
+#define AR5K_EEPROM_PCDAC_STEP         1
+#define AR5K_EEPROM_NON_EDGE_M         0x40
+#define AR5K_EEPROM_CHANNEL_POWER      8
+#define AR5K_EEPROM_N_OBDB             4
+#define AR5K_EEPROM_OBDB_DIS           0xffff
+#define AR5K_EEPROM_CHANNEL_DIS                0xff
+#define AR5K_EEPROM_SCALE_OC_DELTA(_x) (((_x) * 2) / 10)
+#define AR5K_EEPROM_N_CTLS(_v)         AR5K_EEPROM_OFF(_v, 16, 32)
+#define AR5K_EEPROM_MAX_CTLS           32
+#define AR5K_EEPROM_N_PD_CURVES                4
+#define AR5K_EEPROM_N_XPD0_POINTS      4
+#define AR5K_EEPROM_N_XPD3_POINTS      3
+#define AR5K_EEPROM_N_PD_GAINS         4
+#define AR5K_EEPROM_N_PD_POINTS                5
+#define AR5K_EEPROM_N_INTERCEPT_10_2GHZ        35
+#define AR5K_EEPROM_N_INTERCEPT_10_5GHZ        55
+#define AR5K_EEPROM_POWER_M            0x3f
+#define AR5K_EEPROM_POWER_MIN          0
+#define AR5K_EEPROM_POWER_MAX          3150
+#define AR5K_EEPROM_POWER_STEP         50
+#define AR5K_EEPROM_POWER_TABLE_SIZE   64
+#define AR5K_EEPROM_N_POWER_LOC_11B    4
+#define AR5K_EEPROM_N_POWER_LOC_11G    6
+#define AR5K_EEPROM_I_GAIN             10
+#define AR5K_EEPROM_CCK_OFDM_DELTA     15
+#define AR5K_EEPROM_N_IQ_CAL           2
+
+#define AR5K_EEPROM_READ(_o, _v) do {                  \
+       ret = ath5k_hw_eeprom_read(ah, (_o), &(_v));    \
+       if (ret)                                        \
+               return ret;                             \
+} while (0)
+
+#define AR5K_EEPROM_READ_HDR(_o, _v)                                   \
+       AR5K_EEPROM_READ(_o, ah->ah_capabilities.cap_eeprom._v);        \
+
+enum ath5k_ant_setting {
+       AR5K_ANT_VARIABLE       = 0,    /* variable by programming */
+       AR5K_ANT_FIXED_A        = 1,    /* fixed to 11a frequencies */
+       AR5K_ANT_FIXED_B        = 2,    /* fixed to 11b frequencies */
+       AR5K_ANT_MAX            = 3,
+};
+
+enum ath5k_ctl_mode {
+       AR5K_CTL_11A = 0,
+       AR5K_CTL_11B = 1,
+       AR5K_CTL_11G = 2,
+       AR5K_CTL_TURBO = 3,
+       AR5K_CTL_TURBOG = 4,
+       AR5K_CTL_2GHT20 = 5,
+       AR5K_CTL_5GHT20 = 6,
+       AR5K_CTL_2GHT40 = 7,
+       AR5K_CTL_5GHT40 = 8,
+       AR5K_CTL_MODE_M = 15,
+};
+
+/* Default CTL ids for the 3 main reg domains.
+ * Atheros only uses these by default but vendors
+ * can have up to 32 different CTLs for different
+ * scenarios. Note that theese values are ORed with
+ * the mode id (above) so we can have up to 24 CTL
+ * datasets out of these 3 main regdomains. That leaves
+ * 8 ids that can be used by vendors and since 0x20 is
+ * missing from HAL sources i guess this is the set of
+ * custom CTLs vendors can use. */
+#define        AR5K_CTL_FCC    0x10
+#define        AR5K_CTL_CUSTOM 0x20
+#define        AR5K_CTL_ETSI   0x30
+#define        AR5K_CTL_MKK    0x40
+
+/* Indicates a CTL with only mode set and
+ * no reg domain mapping, such CTLs are used
+ * for world roaming domains or simply when
+ * a reg domain is not set */
+#define        AR5K_CTL_NO_REGDOMAIN   0xf0
+
+/* Indicates an empty (invalid) CTL */
+#define AR5K_CTL_NO_CTL                0xff
+
+/* Per channel calibration data, used for power table setup */
+struct ath5k_chan_pcal_info_rf5111 {
+       /* Power levels in half dbm units
+        * for one power curve. */
+       u8 pwr[AR5K_EEPROM_N_PWR_POINTS_5111];
+       /* PCDAC table steps
+        * for the above values */
+       u8 pcdac[AR5K_EEPROM_N_PWR_POINTS_5111];
+       /* Starting PCDAC step */
+       u8 pcdac_min;
+       /* Final PCDAC step */
+       u8 pcdac_max;
+};
+
+struct ath5k_chan_pcal_info_rf5112 {
+       /* Power levels in quarter dBm units
+        * for lower (0) and higher (3)
+        * level curves in 0.25dB units */
+       s8 pwr_x0[AR5K_EEPROM_N_XPD0_POINTS];
+       s8 pwr_x3[AR5K_EEPROM_N_XPD3_POINTS];
+       /* PCDAC table steps
+        * for the above values */
+       u8 pcdac_x0[AR5K_EEPROM_N_XPD0_POINTS];
+       u8 pcdac_x3[AR5K_EEPROM_N_XPD3_POINTS];
+};
+
+struct ath5k_chan_pcal_info_rf2413 {
+       /* Starting pwr/pddac values */
+       s8 pwr_i[AR5K_EEPROM_N_PD_GAINS];
+       u8 pddac_i[AR5K_EEPROM_N_PD_GAINS];
+       /* (pwr,pddac) points
+        * power levels in 0.5dB units */
+       s8 pwr[AR5K_EEPROM_N_PD_GAINS]
+               [AR5K_EEPROM_N_PD_POINTS];
+       u8 pddac[AR5K_EEPROM_N_PD_GAINS]
+               [AR5K_EEPROM_N_PD_POINTS];
+};
+
+enum ath5k_powertable_type {
+       AR5K_PWRTABLE_PWR_TO_PCDAC = 0,
+       AR5K_PWRTABLE_LINEAR_PCDAC = 1,
+       AR5K_PWRTABLE_PWR_TO_PDADC = 2,
+};
+
+struct ath5k_pdgain_info {
+       u8 pd_points;
+       u8 *pd_step;
+       /* Power values are in
+        * 0.25dB units */
+       s16 *pd_pwr;
+};
+
+struct ath5k_chan_pcal_info {
+       /* Frequency */
+       u16     freq;
+       /* Tx power boundaries */
+       s16     max_pwr;
+       s16     min_pwr;
+       union {
+               struct ath5k_chan_pcal_info_rf5111 rf5111_info;
+               struct ath5k_chan_pcal_info_rf5112 rf5112_info;
+               struct ath5k_chan_pcal_info_rf2413 rf2413_info;
+       };
+       /* Raw values used by phy code
+        * Curves are stored in order from lower
+        * gain to higher gain (max txpower -> min txpower) */
+       struct ath5k_pdgain_info *pd_curves;
+};
+
+/* Per rate calibration data for each mode,
+ * used for rate power table setup.
+ * Note: Values in 0.5dB units */
+struct ath5k_rate_pcal_info {
+       u16     freq; /* Frequency */
+       /* Power level for 6-24Mbit/s rates or
+        * 1Mb rate */
+       u16     target_power_6to24;
+       /* Power level for 36Mbit rate or
+        * 2Mb rate */
+       u16     target_power_36;
+       /* Power level for 48Mbit rate or
+        * 5.5Mbit rate */
+       u16     target_power_48;
+       /* Power level for 54Mbit rate or
+        * 11Mbit rate */
+       u16     target_power_54;
+};
+
+/* Power edges for conformance test limits */
+struct ath5k_edge_power {
+       u16 freq;
+       u16 edge; /* in half dBm */
+       int flag;
+};
+
+/* EEPROM calibration data */
+struct ath5k_eeprom_info {
+
+       /* Header information */
+       u16     ee_magic;
+       u16     ee_protect;
+       u16     ee_regdomain;
+       u16     ee_version;
+       u16     ee_header;
+       u16     ee_ant_gain;
+       u16     ee_misc0;
+       u16     ee_misc1;
+       u16     ee_misc2;
+       u16     ee_misc3;
+       u16     ee_misc4;
+       u16     ee_misc5;
+       u16     ee_misc6;
+       u16     ee_cck_ofdm_gain_delta;
+       u16     ee_cck_ofdm_power_delta;
+       u16     ee_scaled_cck_delta;
+
+       /* RF Calibration settings (reset, rfregs) */
+       u16     ee_i_cal[AR5K_EEPROM_N_MODES];
+       u16     ee_q_cal[AR5K_EEPROM_N_MODES];
+       u16     ee_fixed_bias[AR5K_EEPROM_N_MODES];
+       u16     ee_turbo_max_power[AR5K_EEPROM_N_MODES];
+       u16     ee_xr_power[AR5K_EEPROM_N_MODES];
+       u16     ee_switch_settling[AR5K_EEPROM_N_MODES];
+       u16     ee_atn_tx_rx[AR5K_EEPROM_N_MODES];
+       u16     ee_ant_control[AR5K_EEPROM_N_MODES][AR5K_EEPROM_N_PCDAC];
+       u16     ee_ob[AR5K_EEPROM_N_MODES][AR5K_EEPROM_N_OBDB];
+       u16     ee_db[AR5K_EEPROM_N_MODES][AR5K_EEPROM_N_OBDB];
+       u16     ee_tx_end2xlna_enable[AR5K_EEPROM_N_MODES];
+       u16     ee_tx_end2xpa_disable[AR5K_EEPROM_N_MODES];
+       u16     ee_tx_frm2xpa_enable[AR5K_EEPROM_N_MODES];
+       u16     ee_thr_62[AR5K_EEPROM_N_MODES];
+       u16     ee_xlna_gain[AR5K_EEPROM_N_MODES];
+       u16     ee_xpd[AR5K_EEPROM_N_MODES];
+       u16     ee_x_gain[AR5K_EEPROM_N_MODES];
+       u16     ee_i_gain[AR5K_EEPROM_N_MODES];
+       u16     ee_margin_tx_rx[AR5K_EEPROM_N_MODES];
+       u16     ee_switch_settling_turbo[AR5K_EEPROM_N_MODES];
+       u16     ee_margin_tx_rx_turbo[AR5K_EEPROM_N_MODES];
+       u16     ee_atn_tx_rx_turbo[AR5K_EEPROM_N_MODES];
+
+       /* Power calibration data */
+       u16     ee_false_detect[AR5K_EEPROM_N_MODES];
+
+       /* Number of pd gain curves per mode */
+       u8      ee_pd_gains[AR5K_EEPROM_N_MODES];
+       /* Back mapping pdcurve number -> pdcurve index in pd->pd_curves */
+       u8      ee_pdc_to_idx[AR5K_EEPROM_N_MODES][AR5K_EEPROM_N_PD_GAINS];
+
+       u8      ee_n_piers[AR5K_EEPROM_N_MODES];
+       struct ath5k_chan_pcal_info     ee_pwr_cal_a[AR5K_EEPROM_N_5GHZ_CHAN];
+       struct ath5k_chan_pcal_info     ee_pwr_cal_b[AR5K_EEPROM_N_2GHZ_CHAN_MAX];
+       struct ath5k_chan_pcal_info     ee_pwr_cal_g[AR5K_EEPROM_N_2GHZ_CHAN_MAX];
+
+       /* Per rate target power levels */
+       u8      ee_rate_target_pwr_num[AR5K_EEPROM_N_MODES];
+       struct ath5k_rate_pcal_info     ee_rate_tpwr_a[AR5K_EEPROM_N_5GHZ_CHAN];
+       struct ath5k_rate_pcal_info     ee_rate_tpwr_b[AR5K_EEPROM_N_2GHZ_CHAN_MAX];
+       struct ath5k_rate_pcal_info     ee_rate_tpwr_g[AR5K_EEPROM_N_2GHZ_CHAN_MAX];
+
+       /* Conformance test limits (Unused) */
+       u8      ee_ctls;
+       u8      ee_ctl[AR5K_EEPROM_MAX_CTLS];
+       struct ath5k_edge_power ee_ctl_pwr[AR5K_EEPROM_N_EDGES * AR5K_EEPROM_MAX_CTLS];
+
+       /* Noise Floor Calibration settings */
+       s16     ee_noise_floor_thr[AR5K_EEPROM_N_MODES];
+       s8      ee_adc_desired_size[AR5K_EEPROM_N_MODES];
+       s8      ee_pga_desired_size[AR5K_EEPROM_N_MODES];
+       s8      ee_adc_desired_size_turbo[AR5K_EEPROM_N_MODES];
+       s8      ee_pga_desired_size_turbo[AR5K_EEPROM_N_MODES];
+       s8      ee_pd_gain_overlap;
+
+       u32     ee_antenna[AR5K_EEPROM_N_MODES][AR5K_ANT_MAX];
+};
+
diff --git a/src/drivers/net/ath5k/reg.h b/src/drivers/net/ath5k/reg.h
new file mode 100644 (file)
index 0000000..7070d15
--- /dev/null
@@ -0,0 +1,2589 @@
+/*
+ * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
+ * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2007-2008 Michael Taylor <mike.taylor@apprion.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/*
+ * Register values for Atheros 5210/5211/5212 cards from OpenBSD's ar5k
+ * maintained by Reyk Floeter
+ *
+ * I tried to document those registers by looking at ar5k code, some
+ * 802.11 (802.11e mostly) papers and by reading various public available
+ * Atheros presentations and papers like these:
+ *
+ * 5210 - http://nova.stanford.edu/~bbaas/ps/isscc2002_slides.pdf
+ *        http://www.it.iitb.ac.in/~janak/wifire/01222734.pdf
+ *
+ * 5211 - http://www.hotchips.org/archives/hc14/3_Tue/16_mcfarland.pdf
+ *
+ * This file also contains register values found on a memory dump of
+ * Atheros's ART program (Atheros Radio Test), on ath9k, on legacy-hal
+ * released by Atheros and on various debug messages found on the net.
+ */
+
+
+
+/*====MAC DMA REGISTERS====*/
+
+/*
+ * AR5210-Specific TXDP registers
+ * 5210 has only 2 transmit queues so no DCU/QCU, just
+ * 2 transmit descriptor pointers...
+ */
+#define AR5K_NOQCU_TXDP0       0x0000          /* Queue 0 - data */
+#define AR5K_NOQCU_TXDP1       0x0004          /* Queue 1 - beacons */
+
+/*
+ * Mac Control Register
+ */
+#define        AR5K_CR         0x0008                  /* Register Address */
+#define AR5K_CR_TXE0   0x00000001      /* TX Enable for queue 0 on 5210 */
+#define AR5K_CR_TXE1   0x00000002      /* TX Enable for queue 1 on 5210 */
+#define        AR5K_CR_RXE     0x00000004      /* RX Enable */
+#define AR5K_CR_TXD0   0x00000008      /* TX Disable for queue 0 on 5210 */
+#define AR5K_CR_TXD1   0x00000010      /* TX Disable for queue 1 on 5210 */
+#define        AR5K_CR_RXD     0x00000020      /* RX Disable */
+#define        AR5K_CR_SWI     0x00000040      /* Software Interrupt */
+
+/*
+ * RX Descriptor Pointer register
+ */
+#define        AR5K_RXDP       0x000c
+
+/*
+ * Configuration and status register
+ */
+#define        AR5K_CFG                0x0014                  /* Register Address */
+#define        AR5K_CFG_SWTD           0x00000001      /* Byte-swap TX descriptor (for big endian archs) */
+#define        AR5K_CFG_SWTB           0x00000002      /* Byte-swap TX buffer */
+#define        AR5K_CFG_SWRD           0x00000004      /* Byte-swap RX descriptor */
+#define        AR5K_CFG_SWRB           0x00000008      /* Byte-swap RX buffer */
+#define        AR5K_CFG_SWRG           0x00000010      /* Byte-swap Register access */
+#define AR5K_CFG_IBSS          0x00000020      /* 0-BSS, 1-IBSS [5211+] */
+#define AR5K_CFG_PHY_OK                0x00000100      /* [5211+] */
+#define AR5K_CFG_EEBS          0x00000200      /* EEPROM is busy */
+#define        AR5K_CFG_CLKGD          0x00000400      /* Clock gated (Disable dynamic clock) */
+#define AR5K_CFG_TXCNT         0x00007800      /* Tx frame count (?) [5210] */
+#define AR5K_CFG_TXCNT_S       11
+#define AR5K_CFG_TXFSTAT       0x00008000      /* Tx frame status (?) [5210] */
+#define AR5K_CFG_TXFSTRT       0x00010000      /* [5210] */
+#define        AR5K_CFG_PCI_THRES      0x00060000      /* PCI Master req q threshold [5211+] */
+#define        AR5K_CFG_PCI_THRES_S    17
+
+/*
+ * Interrupt enable register
+ */
+#define AR5K_IER               0x0024          /* Register Address */
+#define AR5K_IER_DISABLE       0x00000000      /* Disable card interrupts */
+#define AR5K_IER_ENABLE                0x00000001      /* Enable card interrupts */
+
+
+/*
+ * 0x0028 is Beacon Control Register on 5210
+ * and first RTS duration register on 5211
+ */
+
+/*
+ * Beacon control register [5210]
+ */
+#define AR5K_BCR               0x0028          /* Register Address */
+#define AR5K_BCR_AP            0x00000000      /* AP mode */
+#define AR5K_BCR_ADHOC         0x00000001      /* Ad-Hoc mode */
+#define AR5K_BCR_BDMAE         0x00000002      /* DMA enable */
+#define AR5K_BCR_TQ1FV         0x00000004      /* Use Queue1 for CAB traffic */
+#define AR5K_BCR_TQ1V          0x00000008      /* Use Queue1 for Beacon traffic */
+#define AR5K_BCR_BCGET         0x00000010
+
+/*
+ * First RTS duration register [5211]
+ */
+#define AR5K_RTSD0             0x0028          /* Register Address */
+#define        AR5K_RTSD0_6            0x000000ff      /* 6Mb RTS duration mask (?) */
+#define        AR5K_RTSD0_6_S          0               /* 6Mb RTS duration shift (?) */
+#define        AR5K_RTSD0_9            0x0000ff00      /* 9Mb*/
+#define        AR5K_RTSD0_9_S          8
+#define        AR5K_RTSD0_12           0x00ff0000      /* 12Mb*/
+#define        AR5K_RTSD0_12_S         16
+#define        AR5K_RTSD0_18           0xff000000      /* 16Mb*/
+#define        AR5K_RTSD0_18_S         24
+
+
+/*
+ * 0x002c is Beacon Status Register on 5210
+ * and second RTS duration register on 5211
+ */
+
+/*
+ * Beacon status register [5210]
+ *
+ * As i can see in ar5k_ar5210_tx_start Reyk uses some of the values of BCR
+ * for this register, so i guess TQ1V,TQ1FV and BDMAE have the same meaning
+ * here and SNP/SNAP means "snapshot" (so this register gets synced with BCR).
+ * So SNAPPEDBCRVALID sould also stand for "snapped BCR -values- valid", so i
+ * renamed it to SNAPSHOTSVALID to make more sense. I realy have no idea what
+ * else can it be. I also renamed SNPBCMD to SNPADHOC to match BCR.
+ */
+#define AR5K_BSR               0x002c                  /* Register Address */
+#define AR5K_BSR_BDLYSW                0x00000001      /* SW Beacon delay (?) */
+#define AR5K_BSR_BDLYDMA       0x00000002      /* DMA Beacon delay (?) */
+#define AR5K_BSR_TXQ1F         0x00000004      /* Beacon queue (1) finished */
+#define AR5K_BSR_ATIMDLY       0x00000008      /* ATIM delay (?) */
+#define AR5K_BSR_SNPADHOC      0x00000100      /* Ad-hoc mode set (?) */
+#define AR5K_BSR_SNPBDMAE      0x00000200      /* Beacon DMA enabled (?) */
+#define AR5K_BSR_SNPTQ1FV      0x00000400      /* Queue1 is used for CAB traffic (?) */
+#define AR5K_BSR_SNPTQ1V       0x00000800      /* Queue1 is used for Beacon traffic (?) */
+#define AR5K_BSR_SNAPSHOTSVALID        0x00001000      /* BCR snapshots are valid (?) */
+#define AR5K_BSR_SWBA_CNT      0x00ff0000
+
+/*
+ * Second RTS duration register [5211]
+ */
+#define AR5K_RTSD1             0x002c                  /* Register Address */
+#define        AR5K_RTSD1_24           0x000000ff      /* 24Mb */
+#define        AR5K_RTSD1_24_S         0
+#define        AR5K_RTSD1_36           0x0000ff00      /* 36Mb */
+#define        AR5K_RTSD1_36_S         8
+#define        AR5K_RTSD1_48           0x00ff0000      /* 48Mb */
+#define        AR5K_RTSD1_48_S         16
+#define        AR5K_RTSD1_54           0xff000000      /* 54Mb */
+#define        AR5K_RTSD1_54_S         24
+
+
+/*
+ * Transmit configuration register
+ */
+#define AR5K_TXCFG                     0x0030                  /* Register Address */
+#define AR5K_TXCFG_SDMAMR              0x00000007      /* DMA size (read) */
+#define AR5K_TXCFG_SDMAMR_S            0
+#define AR5K_TXCFG_B_MODE              0x00000008      /* Set b mode for 5111 (enable 2111) */
+#define AR5K_TXCFG_TXFSTP              0x00000008      /* TX DMA full Stop [5210] */
+#define AR5K_TXCFG_TXFULL              0x000003f0      /* TX Triger level mask */
+#define AR5K_TXCFG_TXFULL_S            4
+#define AR5K_TXCFG_TXFULL_0B           0x00000000
+#define AR5K_TXCFG_TXFULL_64B          0x00000010
+#define AR5K_TXCFG_TXFULL_128B         0x00000020
+#define AR5K_TXCFG_TXFULL_192B         0x00000030
+#define AR5K_TXCFG_TXFULL_256B         0x00000040
+#define AR5K_TXCFG_TXCONT_EN           0x00000080
+#define AR5K_TXCFG_DMASIZE             0x00000100      /* Flag for passing DMA size [5210] */
+#define AR5K_TXCFG_JUMBO_DESC_EN       0x00000400      /* Enable jumbo tx descriptors [5211+] */
+#define AR5K_TXCFG_ADHOC_BCN_ATIM      0x00000800      /* Adhoc Beacon ATIM Policy */
+#define AR5K_TXCFG_ATIM_WINDOW_DEF_DIS 0x00001000      /* Disable ATIM window defer [5211+] */
+#define AR5K_TXCFG_RTSRND              0x00001000      /* [5211+] */
+#define AR5K_TXCFG_FRMPAD_DIS          0x00002000      /* [5211+] */
+#define AR5K_TXCFG_RDY_CBR_DIS         0x00004000      /* Ready time CBR disable [5211+] */
+#define AR5K_TXCFG_JUMBO_FRM_MODE      0x00008000      /* Jumbo frame mode [5211+] */
+#define        AR5K_TXCFG_DCU_DBL_BUF_DIS      0x00008000      /* Disable double buffering on DCU */
+#define AR5K_TXCFG_DCU_CACHING_DIS     0x00010000      /* Disable DCU caching */
+
+/*
+ * Receive configuration register
+ */
+#define AR5K_RXCFG             0x0034                  /* Register Address */
+#define AR5K_RXCFG_SDMAMW      0x00000007      /* DMA size (write) */
+#define AR5K_RXCFG_SDMAMW_S    0
+#define AR5K_RXCFG_ZLFDMA      0x00000008      /* Enable Zero-length frame DMA */
+#define        AR5K_RXCFG_DEF_ANTENNA  0x00000010      /* Default antenna (?) */
+#define AR5K_RXCFG_JUMBO_RXE   0x00000020      /* Enable jumbo rx descriptors [5211+] */
+#define AR5K_RXCFG_JUMBO_WRAP  0x00000040      /* Wrap jumbo frames [5211+] */
+#define AR5K_RXCFG_SLE_ENTRY   0x00000080      /* Sleep entry policy */
+
+/*
+ * Receive jumbo descriptor last address register
+ * Only found in 5211 (?)
+ */
+#define AR5K_RXJLA             0x0038
+
+/*
+ * MIB control register
+ */
+#define AR5K_MIBC              0x0040                  /* Register Address */
+#define AR5K_MIBC_COW          0x00000001      /* Warn test indicator */
+#define AR5K_MIBC_FMC          0x00000002      /* Freeze MIB Counters  */
+#define AR5K_MIBC_CMC          0x00000004      /* Clean MIB Counters  */
+#define AR5K_MIBC_MCS          0x00000008      /* MIB counter strobe */
+
+/*
+ * Timeout prescale register
+ */
+#define AR5K_TOPS              0x0044
+#define        AR5K_TOPS_M             0x0000ffff
+
+/*
+ * Receive timeout register (no frame received)
+ */
+#define AR5K_RXNOFRM           0x0048
+#define        AR5K_RXNOFRM_M          0x000003ff
+
+/*
+ * Transmit timeout register (no frame sent)
+ */
+#define AR5K_TXNOFRM           0x004c
+#define        AR5K_TXNOFRM_M          0x000003ff
+#define        AR5K_TXNOFRM_QCU        0x000ffc00
+#define        AR5K_TXNOFRM_QCU_S      10
+
+/*
+ * Receive frame gap timeout register
+ */
+#define AR5K_RPGTO             0x0050
+#define AR5K_RPGTO_M           0x000003ff
+
+/*
+ * Receive frame count limit register
+ */
+#define AR5K_RFCNT             0x0054
+#define AR5K_RFCNT_M           0x0000001f      /* [5211+] (?) */
+#define AR5K_RFCNT_RFCL                0x0000000f      /* [5210] */
+
+/*
+ * Misc settings register
+ * (reserved0-3)
+ */
+#define AR5K_MISC              0x0058                  /* Register Address */
+#define        AR5K_MISC_DMA_OBS_M     0x000001e0
+#define        AR5K_MISC_DMA_OBS_S     5
+#define        AR5K_MISC_MISC_OBS_M    0x00000e00
+#define        AR5K_MISC_MISC_OBS_S    9
+#define        AR5K_MISC_MAC_OBS_LSB_M 0x00007000
+#define        AR5K_MISC_MAC_OBS_LSB_S 12
+#define        AR5K_MISC_MAC_OBS_MSB_M 0x00038000
+#define        AR5K_MISC_MAC_OBS_MSB_S 15
+#define AR5K_MISC_LED_DECAY    0x001c0000      /* [5210] */
+#define AR5K_MISC_LED_BLINK    0x00e00000      /* [5210] */
+
+/*
+ * QCU/DCU clock gating register (5311)
+ * (reserved4-5)
+ */
+#define        AR5K_QCUDCU_CLKGT       0x005c                  /* Register Address (?) */
+#define        AR5K_QCUDCU_CLKGT_QCU   0x0000ffff      /* Mask for QCU clock */
+#define        AR5K_QCUDCU_CLKGT_DCU   0x07ff0000      /* Mask for DCU clock */
+
+/*
+ * Interrupt Status Registers
+ *
+ * For 5210 there is only one status register but for
+ * 5211/5212 we have one primary and 4 secondary registers.
+ * So we have AR5K_ISR for 5210 and AR5K_PISR /SISRx for 5211/5212.
+ * Most of these bits are common for all chipsets.
+ */
+#define AR5K_ISR               0x001c                  /* Register Address [5210] */
+#define AR5K_PISR              0x0080                  /* Register Address [5211+] */
+#define AR5K_ISR_RXOK          0x00000001      /* Frame successfuly recieved */
+#define AR5K_ISR_RXDESC                0x00000002      /* RX descriptor request */
+#define AR5K_ISR_RXERR         0x00000004      /* Receive error */
+#define AR5K_ISR_RXNOFRM       0x00000008      /* No frame received (receive timeout) */
+#define AR5K_ISR_RXEOL         0x00000010      /* Empty RX descriptor */
+#define AR5K_ISR_RXORN         0x00000020      /* Receive FIFO overrun */
+#define AR5K_ISR_TXOK          0x00000040      /* Frame successfuly transmited */
+#define AR5K_ISR_TXDESC                0x00000080      /* TX descriptor request */
+#define AR5K_ISR_TXERR         0x00000100      /* Transmit error */
+#define AR5K_ISR_TXNOFRM       0x00000200      /* No frame transmited (transmit timeout) */
+#define AR5K_ISR_TXEOL         0x00000400      /* Empty TX descriptor */
+#define AR5K_ISR_TXURN         0x00000800      /* Transmit FIFO underrun */
+#define AR5K_ISR_MIB           0x00001000      /* Update MIB counters */
+#define AR5K_ISR_SWI           0x00002000      /* Software interrupt */
+#define AR5K_ISR_RXPHY         0x00004000      /* PHY error */
+#define AR5K_ISR_RXKCM         0x00008000      /* RX Key cache miss */
+#define AR5K_ISR_SWBA          0x00010000      /* Software beacon alert */
+#define AR5K_ISR_BRSSI         0x00020000      /* Beacon rssi below threshold (?) */
+#define AR5K_ISR_BMISS         0x00040000      /* Beacon missed */
+#define AR5K_ISR_HIUERR                0x00080000      /* Host Interface Unit error [5211+] */
+#define AR5K_ISR_BNR           0x00100000      /* Beacon not ready [5211+] */
+#define AR5K_ISR_MCABT         0x00100000      /* Master Cycle Abort [5210] */
+#define AR5K_ISR_RXCHIRP       0x00200000      /* CHIRP Received [5212+] */
+#define AR5K_ISR_SSERR         0x00200000      /* Signaled System Error [5210] */
+#define AR5K_ISR_DPERR         0x00400000      /* Det par Error (?) [5210] */
+#define AR5K_ISR_RXDOPPLER     0x00400000      /* Doppler chirp received [5212+] */
+#define AR5K_ISR_TIM           0x00800000      /* [5211+] */
+#define AR5K_ISR_BCNMISC       0x00800000      /* 'or' of TIM, CAB_END, DTIM_SYNC, BCN_TIMEOUT,
+                                               CAB_TIMEOUT and DTIM bits from SISR2 [5212+] */
+#define AR5K_ISR_GPIO          0x01000000      /* GPIO (rf kill) */
+#define AR5K_ISR_QCBRORN       0x02000000      /* QCU CBR overrun [5211+] */
+#define AR5K_ISR_QCBRURN       0x04000000      /* QCU CBR underrun [5211+] */
+#define AR5K_ISR_QTRIG         0x08000000      /* QCU scheduling trigger [5211+] */
+
+/*
+ * Secondary status registers [5211+] (0 - 4)
+ *
+ * These give the status for each QCU, only QCUs 0-9 are
+ * represented.
+ */
+#define AR5K_SISR0             0x0084                  /* Register Address [5211+] */
+#define AR5K_SISR0_QCU_TXOK    0x000003ff      /* Mask for QCU_TXOK */
+#define AR5K_SISR0_QCU_TXOK_S  0
+#define AR5K_SISR0_QCU_TXDESC  0x03ff0000      /* Mask for QCU_TXDESC */
+#define AR5K_SISR0_QCU_TXDESC_S        16
+
+#define AR5K_SISR1             0x0088                  /* Register Address [5211+] */
+#define AR5K_SISR1_QCU_TXERR   0x000003ff      /* Mask for QCU_TXERR */
+#define AR5K_SISR1_QCU_TXERR_S 0
+#define AR5K_SISR1_QCU_TXEOL   0x03ff0000      /* Mask for QCU_TXEOL */
+#define AR5K_SISR1_QCU_TXEOL_S 16
+
+#define AR5K_SISR2             0x008c                  /* Register Address [5211+] */
+#define AR5K_SISR2_QCU_TXURN   0x000003ff      /* Mask for QCU_TXURN */
+#define        AR5K_SISR2_QCU_TXURN_S  0
+#define        AR5K_SISR2_MCABT        0x00100000      /* Master Cycle Abort */
+#define        AR5K_SISR2_SSERR        0x00200000      /* Signaled System Error */
+#define        AR5K_SISR2_DPERR        0x00400000      /* Bus parity error */
+#define        AR5K_SISR2_TIM          0x01000000      /* [5212+] */
+#define        AR5K_SISR2_CAB_END      0x02000000      /* [5212+] */
+#define        AR5K_SISR2_DTIM_SYNC    0x04000000      /* DTIM sync lost [5212+] */
+#define        AR5K_SISR2_BCN_TIMEOUT  0x08000000      /* Beacon Timeout [5212+] */
+#define        AR5K_SISR2_CAB_TIMEOUT  0x10000000      /* CAB Timeout [5212+] */
+#define        AR5K_SISR2_DTIM         0x20000000      /* [5212+] */
+#define        AR5K_SISR2_TSFOOR       0x80000000      /* TSF OOR (?) */
+
+#define AR5K_SISR3             0x0090                  /* Register Address [5211+] */
+#define AR5K_SISR3_QCBRORN     0x000003ff      /* Mask for QCBRORN */
+#define AR5K_SISR3_QCBRORN_S   0
+#define AR5K_SISR3_QCBRURN     0x03ff0000      /* Mask for QCBRURN */
+#define AR5K_SISR3_QCBRURN_S   16
+
+#define AR5K_SISR4             0x0094                  /* Register Address [5211+] */
+#define AR5K_SISR4_QTRIG       0x000003ff      /* Mask for QTRIG */
+#define AR5K_SISR4_QTRIG_S     0
+
+/*
+ * Shadow read-and-clear interrupt status registers [5211+]
+ */
+#define AR5K_RAC_PISR          0x00c0          /* Read and clear PISR */
+#define AR5K_RAC_SISR0         0x00c4          /* Read and clear SISR0 */
+#define AR5K_RAC_SISR1         0x00c8          /* Read and clear SISR1 */
+#define AR5K_RAC_SISR2         0x00cc          /* Read and clear SISR2 */
+#define AR5K_RAC_SISR3         0x00d0          /* Read and clear SISR3 */
+#define AR5K_RAC_SISR4         0x00d4          /* Read and clear SISR4 */
+
+/*
+ * Interrupt Mask Registers
+ *
+ * As whith ISRs 5210 has one IMR (AR5K_IMR) and 5211/5212 has one primary
+ * (AR5K_PIMR) and 4 secondary IMRs (AR5K_SIMRx). Note that ISR/IMR flags match.
+ */
+#define        AR5K_IMR                0x0020                  /* Register Address [5210] */
+#define AR5K_PIMR              0x00a0                  /* Register Address [5211+] */
+#define AR5K_IMR_RXOK          0x00000001      /* Frame successfuly recieved*/
+#define AR5K_IMR_RXDESC                0x00000002      /* RX descriptor request*/
+#define AR5K_IMR_RXERR         0x00000004      /* Receive error*/
+#define AR5K_IMR_RXNOFRM       0x00000008      /* No frame received (receive timeout)*/
+#define AR5K_IMR_RXEOL         0x00000010      /* Empty RX descriptor*/
+#define AR5K_IMR_RXORN         0x00000020      /* Receive FIFO overrun*/
+#define AR5K_IMR_TXOK          0x00000040      /* Frame successfuly transmited*/
+#define AR5K_IMR_TXDESC                0x00000080      /* TX descriptor request*/
+#define AR5K_IMR_TXERR         0x00000100      /* Transmit error*/
+#define AR5K_IMR_TXNOFRM       0x00000200      /* No frame transmited (transmit timeout)*/
+#define AR5K_IMR_TXEOL         0x00000400      /* Empty TX descriptor*/
+#define AR5K_IMR_TXURN         0x00000800      /* Transmit FIFO underrun*/
+#define AR5K_IMR_MIB           0x00001000      /* Update MIB counters*/
+#define AR5K_IMR_SWI           0x00002000      /* Software interrupt */
+#define AR5K_IMR_RXPHY         0x00004000      /* PHY error*/
+#define AR5K_IMR_RXKCM         0x00008000      /* RX Key cache miss */
+#define AR5K_IMR_SWBA          0x00010000      /* Software beacon alert*/
+#define AR5K_IMR_BRSSI         0x00020000      /* Beacon rssi below threshold (?) */
+#define AR5K_IMR_BMISS         0x00040000      /* Beacon missed*/
+#define AR5K_IMR_HIUERR                0x00080000      /* Host Interface Unit error [5211+] */
+#define AR5K_IMR_BNR           0x00100000      /* Beacon not ready [5211+] */
+#define AR5K_IMR_MCABT         0x00100000      /* Master Cycle Abort [5210] */
+#define AR5K_IMR_RXCHIRP       0x00200000      /* CHIRP Received [5212+]*/
+#define AR5K_IMR_SSERR         0x00200000      /* Signaled System Error [5210] */
+#define AR5K_IMR_DPERR         0x00400000      /* Det par Error (?) [5210] */
+#define AR5K_IMR_RXDOPPLER     0x00400000      /* Doppler chirp received [5212+] */
+#define AR5K_IMR_TIM           0x00800000      /* [5211+] */
+#define AR5K_IMR_BCNMISC       0x00800000      /* 'or' of TIM, CAB_END, DTIM_SYNC, BCN_TIMEOUT,
+                                               CAB_TIMEOUT and DTIM bits from SISR2 [5212+] */
+#define AR5K_IMR_GPIO          0x01000000      /* GPIO (rf kill)*/
+#define AR5K_IMR_QCBRORN       0x02000000      /* QCU CBR overrun (?) [5211+] */
+#define AR5K_IMR_QCBRURN       0x04000000      /* QCU CBR underrun (?) [5211+] */
+#define AR5K_IMR_QTRIG         0x08000000      /* QCU scheduling trigger [5211+] */
+
+/*
+ * Secondary interrupt mask registers [5211+] (0 - 4)
+ */
+#define AR5K_SIMR0             0x00a4                  /* Register Address [5211+] */
+#define AR5K_SIMR0_QCU_TXOK    0x000003ff      /* Mask for QCU_TXOK */
+#define AR5K_SIMR0_QCU_TXOK_S  0
+#define AR5K_SIMR0_QCU_TXDESC  0x03ff0000      /* Mask for QCU_TXDESC */
+#define AR5K_SIMR0_QCU_TXDESC_S        16
+
+#define AR5K_SIMR1             0x00a8                  /* Register Address [5211+] */
+#define AR5K_SIMR1_QCU_TXERR   0x000003ff      /* Mask for QCU_TXERR */
+#define AR5K_SIMR1_QCU_TXERR_S 0
+#define AR5K_SIMR1_QCU_TXEOL   0x03ff0000      /* Mask for QCU_TXEOL */
+#define AR5K_SIMR1_QCU_TXEOL_S 16
+
+#define AR5K_SIMR2             0x00ac                  /* Register Address [5211+] */
+#define AR5K_SIMR2_QCU_TXURN   0x000003ff      /* Mask for QCU_TXURN */
+#define AR5K_SIMR2_QCU_TXURN_S 0
+#define        AR5K_SIMR2_MCABT        0x00100000      /* Master Cycle Abort */
+#define        AR5K_SIMR2_SSERR        0x00200000      /* Signaled System Error */
+#define        AR5K_SIMR2_DPERR        0x00400000      /* Bus parity error */
+#define        AR5K_SIMR2_TIM          0x01000000      /* [5212+] */
+#define        AR5K_SIMR2_CAB_END      0x02000000      /* [5212+] */
+#define        AR5K_SIMR2_DTIM_SYNC    0x04000000      /* DTIM Sync lost [5212+] */
+#define        AR5K_SIMR2_BCN_TIMEOUT  0x08000000      /* Beacon Timeout [5212+] */
+#define        AR5K_SIMR2_CAB_TIMEOUT  0x10000000      /* CAB Timeout [5212+] */
+#define        AR5K_SIMR2_DTIM         0x20000000      /* [5212+] */
+#define        AR5K_SIMR2_TSFOOR       0x80000000      /* TSF OOR (?) */
+
+#define AR5K_SIMR3             0x00b0                  /* Register Address [5211+] */
+#define AR5K_SIMR3_QCBRORN     0x000003ff      /* Mask for QCBRORN */
+#define AR5K_SIMR3_QCBRORN_S   0
+#define AR5K_SIMR3_QCBRURN     0x03ff0000      /* Mask for QCBRURN */
+#define AR5K_SIMR3_QCBRURN_S   16
+
+#define AR5K_SIMR4             0x00b4                  /* Register Address [5211+] */
+#define AR5K_SIMR4_QTRIG       0x000003ff      /* Mask for QTRIG */
+#define AR5K_SIMR4_QTRIG_S     0
+
+/*
+ * DMA Debug registers 0-7
+ * 0xe0 - 0xfc
+ */
+
+/*
+ * Decompression mask registers [5212+]
+ */
+#define AR5K_DCM_ADDR          0x0400          /*Decompression mask address (index) */
+#define AR5K_DCM_DATA          0x0404          /*Decompression mask data */
+
+/*
+ * Wake On Wireless pattern control register [5212+]
+ */
+#define        AR5K_WOW_PCFG                   0x0410                  /* Register Address */
+#define        AR5K_WOW_PCFG_PAT_MATCH_EN      0x00000001      /* Pattern match enable */
+#define        AR5K_WOW_PCFG_LONG_FRAME_POL    0x00000002      /* Long frame policy */
+#define        AR5K_WOW_PCFG_WOBMISS           0x00000004      /* Wake on bea(con) miss (?) */
+#define        AR5K_WOW_PCFG_PAT_0_EN          0x00000100      /* Enable pattern 0 */
+#define        AR5K_WOW_PCFG_PAT_1_EN          0x00000200      /* Enable pattern 1 */
+#define        AR5K_WOW_PCFG_PAT_2_EN          0x00000400      /* Enable pattern 2 */
+#define        AR5K_WOW_PCFG_PAT_3_EN          0x00000800      /* Enable pattern 3 */
+#define        AR5K_WOW_PCFG_PAT_4_EN          0x00001000      /* Enable pattern 4 */
+#define        AR5K_WOW_PCFG_PAT_5_EN          0x00002000      /* Enable pattern 5 */
+
+/*
+ * Wake On Wireless pattern index register (?) [5212+]
+ */
+#define        AR5K_WOW_PAT_IDX        0x0414
+
+/*
+ * Wake On Wireless pattern data register [5212+]
+ */
+#define        AR5K_WOW_PAT_DATA       0x0418                  /* Register Address */
+#define        AR5K_WOW_PAT_DATA_0_3_V 0x00000001      /* Pattern 0, 3 value */
+#define        AR5K_WOW_PAT_DATA_1_4_V 0x00000100      /* Pattern 1, 4 value */
+#define        AR5K_WOW_PAT_DATA_2_5_V 0x00010000      /* Pattern 2, 5 value */
+#define        AR5K_WOW_PAT_DATA_0_3_M 0x01000000      /* Pattern 0, 3 mask */
+#define        AR5K_WOW_PAT_DATA_1_4_M 0x04000000      /* Pattern 1, 4 mask */
+#define        AR5K_WOW_PAT_DATA_2_5_M 0x10000000      /* Pattern 2, 5 mask */
+
+/*
+ * Decompression configuration registers [5212+]
+ */
+#define AR5K_DCCFG             0x0420                  /* Register Address */
+#define AR5K_DCCFG_GLOBAL_EN   0x00000001      /* Enable decompression on all queues */
+#define AR5K_DCCFG_BYPASS_EN   0x00000002      /* Bypass decompression */
+#define AR5K_DCCFG_BCAST_EN    0x00000004      /* Enable decompression for bcast frames */
+#define AR5K_DCCFG_MCAST_EN    0x00000008      /* Enable decompression for mcast frames */
+
+/*
+ * Compression configuration registers [5212+]
+ */
+#define AR5K_CCFG              0x0600                  /* Register Address */
+#define        AR5K_CCFG_WINDOW_SIZE   0x00000007      /* Compression window size */
+#define        AR5K_CCFG_CPC_EN        0x00000008      /* Enable performance counters */
+
+#define AR5K_CCFG_CCU          0x0604                  /* Register Address */
+#define AR5K_CCFG_CCU_CUP_EN   0x00000001      /* CCU Catchup enable */
+#define AR5K_CCFG_CCU_CREDIT   0x00000002      /* CCU Credit (field) */
+#define AR5K_CCFG_CCU_CD_THRES 0x00000080      /* CCU Cyc(lic?) debt threshold (field) */
+#define AR5K_CCFG_CCU_CUP_LCNT 0x00010000      /* CCU Catchup lit(?) count */
+#define        AR5K_CCFG_CCU_INIT      0x00100200      /* Initial value during reset */
+
+/*
+ * Compression performance counter registers [5212+]
+ */
+#define AR5K_CPC0              0x0610          /* Compression performance counter 0 */
+#define AR5K_CPC1              0x0614          /* Compression performance counter 1*/
+#define AR5K_CPC2              0x0618          /* Compression performance counter 2 */
+#define AR5K_CPC3              0x061c          /* Compression performance counter 3 */
+#define AR5K_CPCOVF            0x0620          /* Compression performance overflow */
+
+
+/*
+ * Queue control unit (QCU) registers [5211+]
+ *
+ * Card has 12 TX Queues but i see that only 0-9 are used (?)
+ * both in binary HAL (see ah.h) and ar5k. Each queue has it's own
+ * TXDP at addresses 0x0800 - 0x082c, a CBR (Constant Bit Rate)
+ * configuration register (0x08c0 - 0x08ec), a ready time configuration
+ * register (0x0900 - 0x092c), a misc configuration register (0x09c0 -
+ * 0x09ec) and a status register (0x0a00 - 0x0a2c). We also have some
+ * global registers, QCU transmit enable/disable and "one shot arm (?)"
+ * set/clear, which contain status for all queues (we shift by 1 for each
+ * queue). To access these registers easily we define some macros here
+ * that are used inside HAL. For more infos check out *_tx_queue functs.
+ */
+
+/*
+ * Generic QCU Register access macros
+ */
+#define        AR5K_QUEUE_REG(_r, _q)          (((_q) << 2) + _r)
+#define AR5K_QCU_GLOBAL_READ(_r, _q)   (AR5K_REG_READ(_r) & (1 << _q))
+#define AR5K_QCU_GLOBAL_WRITE(_r, _q)  AR5K_REG_WRITE(_r, (1 << _q))
+
+/*
+ * QCU Transmit descriptor pointer registers
+ */
+#define AR5K_QCU_TXDP_BASE     0x0800          /* Register Address - Queue0 TXDP */
+#define AR5K_QUEUE_TXDP(_q)    AR5K_QUEUE_REG(AR5K_QCU_TXDP_BASE, _q)
+
+/*
+ * QCU Transmit enable register
+ */
+#define AR5K_QCU_TXE           0x0840
+#define AR5K_ENABLE_QUEUE(_q)  AR5K_QCU_GLOBAL_WRITE(AR5K_QCU_TXE, _q)
+#define AR5K_QUEUE_ENABLED(_q) AR5K_QCU_GLOBAL_READ(AR5K_QCU_TXE, _q)
+
+/*
+ * QCU Transmit disable register
+ */
+#define AR5K_QCU_TXD           0x0880
+#define AR5K_DISABLE_QUEUE(_q) AR5K_QCU_GLOBAL_WRITE(AR5K_QCU_TXD, _q)
+#define AR5K_QUEUE_DISABLED(_q)        AR5K_QCU_GLOBAL_READ(AR5K_QCU_TXD, _q)
+
+/*
+ * QCU Constant Bit Rate configuration registers
+ */
+#define        AR5K_QCU_CBRCFG_BASE            0x08c0  /* Register Address - Queue0 CBRCFG */
+#define        AR5K_QCU_CBRCFG_INTVAL          0x00ffffff      /* CBR Interval mask */
+#define AR5K_QCU_CBRCFG_INTVAL_S       0
+#define        AR5K_QCU_CBRCFG_ORN_THRES       0xff000000      /* CBR overrun threshold mask */
+#define AR5K_QCU_CBRCFG_ORN_THRES_S    24
+#define        AR5K_QUEUE_CBRCFG(_q)           AR5K_QUEUE_REG(AR5K_QCU_CBRCFG_BASE, _q)
+
+/*
+ * QCU Ready time configuration registers
+ */
+#define        AR5K_QCU_RDYTIMECFG_BASE        0x0900  /* Register Address - Queue0 RDYTIMECFG */
+#define        AR5K_QCU_RDYTIMECFG_INTVAL      0x00ffffff      /* Ready time interval mask */
+#define AR5K_QCU_RDYTIMECFG_INTVAL_S   0
+#define        AR5K_QCU_RDYTIMECFG_ENABLE      0x01000000      /* Ready time enable mask */
+#define AR5K_QUEUE_RDYTIMECFG(_q)      AR5K_QUEUE_REG(AR5K_QCU_RDYTIMECFG_BASE, _q)
+
+/*
+ * QCU one shot arm set registers
+ */
+#define        AR5K_QCU_ONESHOTARM_SET         0x0940  /* Register Address -QCU "one shot arm set (?)" */
+#define        AR5K_QCU_ONESHOTARM_SET_M       0x0000ffff
+
+/*
+ * QCU one shot arm clear registers
+ */
+#define        AR5K_QCU_ONESHOTARM_CLEAR       0x0980  /* Register Address -QCU "one shot arm clear (?)" */
+#define        AR5K_QCU_ONESHOTARM_CLEAR_M     0x0000ffff
+
+/*
+ * QCU misc registers
+ */
+#define AR5K_QCU_MISC_BASE             0x09c0                  /* Register Address -Queue0 MISC */
+#define        AR5K_QCU_MISC_FRSHED_M          0x0000000f      /* Frame sheduling mask */
+#define        AR5K_QCU_MISC_FRSHED_ASAP               0       /* ASAP */
+#define        AR5K_QCU_MISC_FRSHED_CBR                1       /* Constant Bit Rate */
+#define        AR5K_QCU_MISC_FRSHED_DBA_GT             2       /* DMA Beacon alert gated */
+#define        AR5K_QCU_MISC_FRSHED_TIM_GT             3       /* TIMT gated */
+#define        AR5K_QCU_MISC_FRSHED_BCN_SENT_GT        4       /* Beacon sent gated */
+#define        AR5K_QCU_MISC_ONESHOT_ENABLE    0x00000010      /* Oneshot enable */
+#define        AR5K_QCU_MISC_CBREXP_DIS        0x00000020      /* Disable CBR expired counter (normal queue) */
+#define        AR5K_QCU_MISC_CBREXP_BCN_DIS    0x00000040      /* Disable CBR expired counter (beacon queue) */
+#define        AR5K_QCU_MISC_BCN_ENABLE        0x00000080      /* Enable Beacon use */
+#define        AR5K_QCU_MISC_CBR_THRES_ENABLE  0x00000100      /* CBR expired threshold enabled */
+#define        AR5K_QCU_MISC_RDY_VEOL_POLICY   0x00000200      /* TXE reset when RDYTIME expired or VEOL */
+#define        AR5K_QCU_MISC_CBR_RESET_CNT     0x00000400      /* CBR threshold (counter) reset */
+#define        AR5K_QCU_MISC_DCU_EARLY         0x00000800      /* DCU early termination */
+#define AR5K_QCU_MISC_DCU_CMP_EN       0x00001000      /* Enable frame compression */
+#define AR5K_QUEUE_MISC(_q)            AR5K_QUEUE_REG(AR5K_QCU_MISC_BASE, _q)
+
+
+/*
+ * QCU status registers
+ */
+#define AR5K_QCU_STS_BASE      0x0a00                  /* Register Address - Queue0 STS */
+#define        AR5K_QCU_STS_FRMPENDCNT 0x00000003      /* Frames pending counter */
+#define        AR5K_QCU_STS_CBREXPCNT  0x0000ff00      /* CBR expired counter */
+#define        AR5K_QUEUE_STATUS(_q)   AR5K_QUEUE_REG(AR5K_QCU_STS_BASE, _q)
+
+/*
+ * QCU ready time shutdown register
+ */
+#define AR5K_QCU_RDYTIMESHDN   0x0a40
+#define AR5K_QCU_RDYTIMESHDN_M 0x000003ff
+
+/*
+ * QCU compression buffer base registers [5212+]
+ */
+#define AR5K_QCU_CBB_SELECT    0x0b00
+#define AR5K_QCU_CBB_ADDR      0x0b04
+#define AR5K_QCU_CBB_ADDR_S    9
+
+/*
+ * QCU compression buffer configuration register [5212+]
+ * (buffer size)
+ */
+#define AR5K_QCU_CBCFG         0x0b08
+
+
+
+/*
+ * Distributed Coordination Function (DCF) control unit (DCU)
+ * registers [5211+]
+ *
+ * These registers control the various characteristics of each queue
+ * for 802.11e (WME) combatibility so they go together with
+ * QCU registers in pairs. For each queue we have a QCU mask register,
+ * (0x1000 - 0x102c), a local-IFS settings register (0x1040 - 0x106c),
+ * a retry limit register (0x1080 - 0x10ac), a channel time register
+ * (0x10c0 - 0x10ec), a misc-settings register (0x1100 - 0x112c) and
+ * a sequence number register (0x1140 - 0x116c). It seems that "global"
+ * registers here afect all queues (see use of DCU_GBL_IFS_SLOT in ar5k).
+ * We use the same macros here for easier register access.
+ *
+ */
+
+/*
+ * DCU QCU mask registers
+ */
+#define AR5K_DCU_QCUMASK_BASE  0x1000          /* Register Address -Queue0 DCU_QCUMASK */
+#define AR5K_DCU_QCUMASK_M     0x000003ff
+#define AR5K_QUEUE_QCUMASK(_q) AR5K_QUEUE_REG(AR5K_DCU_QCUMASK_BASE, _q)
+
+/*
+ * DCU local Inter Frame Space settings register
+ */
+#define AR5K_DCU_LCL_IFS_BASE          0x1040                  /* Register Address -Queue0 DCU_LCL_IFS */
+#define        AR5K_DCU_LCL_IFS_CW_MIN         0x000003ff      /* Minimum Contention Window */
+#define        AR5K_DCU_LCL_IFS_CW_MIN_S       0
+#define        AR5K_DCU_LCL_IFS_CW_MAX         0x000ffc00      /* Maximum Contention Window */
+#define        AR5K_DCU_LCL_IFS_CW_MAX_S       10
+#define        AR5K_DCU_LCL_IFS_AIFS           0x0ff00000      /* Arbitrated Interframe Space */
+#define        AR5K_DCU_LCL_IFS_AIFS_S         20
+#define        AR5K_DCU_LCL_IFS_AIFS_MAX       0xfc            /* Anything above that can cause DCU to hang */
+#define        AR5K_QUEUE_DFS_LOCAL_IFS(_q)    AR5K_QUEUE_REG(AR5K_DCU_LCL_IFS_BASE, _q)
+
+/*
+ * DCU retry limit registers
+ */
+#define AR5K_DCU_RETRY_LMT_BASE                0x1080                  /* Register Address -Queue0 DCU_RETRY_LMT */
+#define AR5K_DCU_RETRY_LMT_SH_RETRY    0x0000000f      /* Short retry limit mask */
+#define AR5K_DCU_RETRY_LMT_SH_RETRY_S  0
+#define AR5K_DCU_RETRY_LMT_LG_RETRY    0x000000f0      /* Long retry limit mask */
+#define AR5K_DCU_RETRY_LMT_LG_RETRY_S  4
+#define AR5K_DCU_RETRY_LMT_SSH_RETRY   0x00003f00      /* Station short retry limit mask (?) */
+#define AR5K_DCU_RETRY_LMT_SSH_RETRY_S 8
+#define AR5K_DCU_RETRY_LMT_SLG_RETRY   0x000fc000      /* Station long retry limit mask (?) */
+#define AR5K_DCU_RETRY_LMT_SLG_RETRY_S 14
+#define        AR5K_QUEUE_DFS_RETRY_LIMIT(_q)  AR5K_QUEUE_REG(AR5K_DCU_RETRY_LMT_BASE, _q)
+
+/*
+ * DCU channel time registers
+ */
+#define AR5K_DCU_CHAN_TIME_BASE                0x10c0                  /* Register Address -Queue0 DCU_CHAN_TIME */
+#define        AR5K_DCU_CHAN_TIME_DUR          0x000fffff      /* Channel time duration */
+#define        AR5K_DCU_CHAN_TIME_DUR_S        0
+#define        AR5K_DCU_CHAN_TIME_ENABLE       0x00100000      /* Enable channel time */
+#define AR5K_QUEUE_DFS_CHANNEL_TIME(_q)        AR5K_QUEUE_REG(AR5K_DCU_CHAN_TIME_BASE, _q)
+
+/*
+ * DCU misc registers [5211+]
+ *
+ * Note: Arbiter lockout control controls the
+ * behaviour on low priority queues when we have multiple queues
+ * with pending frames. Intra-frame lockout means we wait until
+ * the queue's current frame transmits (with post frame backoff and bursting)
+ * before we transmit anything else and global lockout means we
+ * wait for the whole queue to finish before higher priority queues
+ * can transmit (this is used on beacon and CAB queues).
+ * No lockout means there is no special handling.
+ */
+#define AR5K_DCU_MISC_BASE             0x1100                  /* Register Address -Queue0 DCU_MISC */
+#define        AR5K_DCU_MISC_BACKOFF           0x0000003f      /* Mask for backoff threshold */
+#define        AR5K_DCU_MISC_ETS_RTS_POL       0x00000040      /* End of transmission series
+                                                       station RTS/data failure count
+                                                       reset policy (?) */
+#define AR5K_DCU_MISC_ETS_CW_POL       0x00000080      /* End of transmission series
+                                                       CW reset policy */
+#define        AR5K_DCU_MISC_FRAG_WAIT         0x00000100      /* Wait for next fragment */
+#define AR5K_DCU_MISC_BACKOFF_FRAG     0x00000200      /* Enable backoff while bursting */
+#define        AR5K_DCU_MISC_HCFPOLL_ENABLE    0x00000800      /* CF - Poll enable */
+#define        AR5K_DCU_MISC_BACKOFF_PERSIST   0x00001000      /* Persistent backoff */
+#define        AR5K_DCU_MISC_FRMPRFTCH_ENABLE  0x00002000      /* Enable frame pre-fetch */
+#define        AR5K_DCU_MISC_VIRTCOL           0x0000c000      /* Mask for Virtual Collision (?) */
+#define        AR5K_DCU_MISC_VIRTCOL_NORMAL    0
+#define        AR5K_DCU_MISC_VIRTCOL_IGNORE    1
+#define        AR5K_DCU_MISC_BCN_ENABLE        0x00010000      /* Enable Beacon use */
+#define        AR5K_DCU_MISC_ARBLOCK_CTL       0x00060000      /* Arbiter lockout control mask */
+#define        AR5K_DCU_MISC_ARBLOCK_CTL_S     17
+#define        AR5K_DCU_MISC_ARBLOCK_CTL_NONE          0       /* No arbiter lockout */
+#define        AR5K_DCU_MISC_ARBLOCK_CTL_INTFRM        1       /* Intra-frame lockout */
+#define        AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL        2       /* Global lockout */
+#define        AR5K_DCU_MISC_ARBLOCK_IGNORE    0x00080000      /* Ignore Arbiter lockout */
+#define        AR5K_DCU_MISC_SEQ_NUM_INCR_DIS  0x00100000      /* Disable sequence number increment */
+#define        AR5K_DCU_MISC_POST_FR_BKOFF_DIS 0x00200000      /* Disable post-frame backoff */
+#define        AR5K_DCU_MISC_VIRT_COLL_POLICY  0x00400000      /* Virtual Collision cw policy */
+#define        AR5K_DCU_MISC_BLOWN_IFS_POLICY  0x00800000      /* Blown IFS policy (?) */
+#define        AR5K_DCU_MISC_SEQNUM_CTL        0x01000000      /* Sequence number control (?) */
+#define AR5K_QUEUE_DFS_MISC(_q)                AR5K_QUEUE_REG(AR5K_DCU_MISC_BASE, _q)
+
+/*
+ * DCU frame sequence number registers
+ */
+#define AR5K_DCU_SEQNUM_BASE           0x1140
+#define        AR5K_DCU_SEQNUM_M               0x00000fff
+#define        AR5K_QUEUE_DCU_SEQNUM(_q)       AR5K_QUEUE_REG(AR5K_DCU_SEQNUM_BASE, _q)
+
+/*
+ * DCU global IFS SIFS register
+ */
+#define AR5K_DCU_GBL_IFS_SIFS  0x1030
+#define AR5K_DCU_GBL_IFS_SIFS_M        0x0000ffff
+
+/*
+ * DCU global IFS slot interval register
+ */
+#define AR5K_DCU_GBL_IFS_SLOT  0x1070
+#define AR5K_DCU_GBL_IFS_SLOT_M        0x0000ffff
+
+/*
+ * DCU global IFS EIFS register
+ */
+#define AR5K_DCU_GBL_IFS_EIFS  0x10b0
+#define AR5K_DCU_GBL_IFS_EIFS_M        0x0000ffff
+
+/*
+ * DCU global IFS misc register
+ *
+ * LFSR stands for Linear Feedback Shift Register
+ * and it's used for generating pseudo-random
+ * number sequences.
+ *
+ * (If i understand corectly, random numbers are
+ * used for idle sensing -multiplied with cwmin/max etc-)
+ */
+#define AR5K_DCU_GBL_IFS_MISC                  0x10f0                  /* Register Address */
+#define        AR5K_DCU_GBL_IFS_MISC_LFSR_SLICE        0x00000007      /* LFSR Slice Select */
+#define        AR5K_DCU_GBL_IFS_MISC_TURBO_MODE        0x00000008      /* Turbo mode */
+#define        AR5K_DCU_GBL_IFS_MISC_SIFS_DUR_USEC     0x000003f0      /* SIFS Duration mask */
+#define        AR5K_DCU_GBL_IFS_MISC_USEC_DUR          0x000ffc00      /* USEC Duration mask */
+#define        AR5K_DCU_GBL_IFS_MISC_USEC_DUR_S        10
+#define        AR5K_DCU_GBL_IFS_MISC_DCU_ARB_DELAY     0x00300000      /* DCU Arbiter delay mask */
+#define AR5K_DCU_GBL_IFS_MISC_SIFS_CNT_RST     0x00400000      /* SIFS cnt reset policy (?) */
+#define AR5K_DCU_GBL_IFS_MISC_AIFS_CNT_RST     0x00800000      /* AIFS cnt reset policy (?) */
+#define AR5K_DCU_GBL_IFS_MISC_RND_LFSR_SL_DIS  0x01000000      /* Disable random LFSR slice */
+
+/*
+ * DCU frame prefetch control register
+ */
+#define AR5K_DCU_FP                    0x1230                  /* Register Address */
+#define AR5K_DCU_FP_NOBURST_DCU_EN     0x00000001      /* Enable non-burst prefetch on DCU (?) */
+#define AR5K_DCU_FP_NOBURST_EN         0x00000010      /* Enable non-burst prefetch (?) */
+#define AR5K_DCU_FP_BURST_DCU_EN       0x00000020      /* Enable burst prefetch on DCU (?) */
+
+/*
+ * DCU transmit pause control/status register
+ */
+#define AR5K_DCU_TXP           0x1270                  /* Register Address */
+#define        AR5K_DCU_TXP_M          0x000003ff      /* Tx pause mask */
+#define        AR5K_DCU_TXP_STATUS     0x00010000      /* Tx pause status */
+
+/*
+ * DCU transmit filter table 0 (32 entries)
+ * each entry contains a 32bit slice of the
+ * 128bit tx filter for each DCU (4 slices per DCU)
+ */
+#define AR5K_DCU_TX_FILTER_0_BASE      0x1038
+#define        AR5K_DCU_TX_FILTER_0(_n)        (AR5K_DCU_TX_FILTER_0_BASE + (_n * 64))
+
+/*
+ * DCU transmit filter table 1 (16 entries)
+ */
+#define AR5K_DCU_TX_FILTER_1_BASE      0x103c
+#define        AR5K_DCU_TX_FILTER_1(_n)        (AR5K_DCU_TX_FILTER_1_BASE + (_n * 64))
+
+/*
+ * DCU clear transmit filter register
+ */
+#define AR5K_DCU_TX_FILTER_CLR 0x143c
+
+/*
+ * DCU set transmit filter register
+ */
+#define AR5K_DCU_TX_FILTER_SET 0x147c
+
+/*
+ * Reset control register
+ */
+#define AR5K_RESET_CTL         0x4000                  /* Register Address */
+#define AR5K_RESET_CTL_PCU     0x00000001      /* Protocol Control Unit reset */
+#define AR5K_RESET_CTL_DMA     0x00000002      /* DMA (Rx/Tx) reset [5210] */
+#define        AR5K_RESET_CTL_BASEBAND 0x00000002      /* Baseband reset [5211+] */
+#define AR5K_RESET_CTL_MAC     0x00000004      /* MAC reset (PCU+Baseband ?) [5210] */
+#define AR5K_RESET_CTL_PHY     0x00000008      /* PHY reset [5210] */
+#define AR5K_RESET_CTL_PCI     0x00000010      /* PCI Core reset (interrupts etc) */
+
+/*
+ * Sleep control register
+ */
+#define AR5K_SLEEP_CTL                 0x4004                  /* Register Address */
+#define AR5K_SLEEP_CTL_SLDUR           0x0000ffff      /* Sleep duration mask */
+#define AR5K_SLEEP_CTL_SLDUR_S         0
+#define AR5K_SLEEP_CTL_SLE             0x00030000      /* Sleep enable mask */
+#define AR5K_SLEEP_CTL_SLE_S           16
+#define AR5K_SLEEP_CTL_SLE_WAKE                0x00000000      /* Force chip awake */
+#define AR5K_SLEEP_CTL_SLE_SLP         0x00010000      /* Force chip sleep */
+#define AR5K_SLEEP_CTL_SLE_ALLOW       0x00020000      /* Normal sleep policy */
+#define AR5K_SLEEP_CTL_SLE_UNITS       0x00000008      /* [5211+] */
+#define AR5K_SLEEP_CTL_DUR_TIM_POL     0x00040000      /* Sleep duration timing policy */
+#define AR5K_SLEEP_CTL_DUR_WRITE_POL   0x00080000      /* Sleep duration write policy */
+#define AR5K_SLEEP_CTL_SLE_POL         0x00100000      /* Sleep policy mode */
+
+/*
+ * Interrupt pending register
+ */
+#define AR5K_INTPEND   0x4008
+#define AR5K_INTPEND_M 0x00000001
+
+/*
+ * Sleep force register
+ */
+#define AR5K_SFR       0x400c
+#define AR5K_SFR_EN    0x00000001
+
+/*
+ * PCI configuration register
+ * TODO: Fix LED stuff
+ */
+#define AR5K_PCICFG                    0x4010                  /* Register Address */
+#define AR5K_PCICFG_EEAE               0x00000001      /* Eeprom access enable [5210] */
+#define AR5K_PCICFG_SLEEP_CLOCK_EN     0x00000002      /* Enable sleep clock */
+#define AR5K_PCICFG_CLKRUNEN           0x00000004      /* CLKRUN enable [5211+] */
+#define AR5K_PCICFG_EESIZE             0x00000018      /* Mask for EEPROM size [5211+] */
+#define AR5K_PCICFG_EESIZE_S           3
+#define AR5K_PCICFG_EESIZE_4K          0               /* 4K */
+#define AR5K_PCICFG_EESIZE_8K          1               /* 8K */
+#define AR5K_PCICFG_EESIZE_16K         2               /* 16K */
+#define AR5K_PCICFG_EESIZE_FAIL                3               /* Failed to get size [5211+] */
+#define AR5K_PCICFG_LED                        0x00000060      /* Led status [5211+] */
+#define AR5K_PCICFG_LED_NONE           0x00000000      /* Default [5211+] */
+#define AR5K_PCICFG_LED_PEND           0x00000020      /* Scan / Auth pending */
+#define AR5K_PCICFG_LED_ASSOC          0x00000040      /* Associated */
+#define        AR5K_PCICFG_BUS_SEL             0x00000380      /* Mask for "bus select" [5211+] (?) */
+#define AR5K_PCICFG_CBEFIX_DIS         0x00000400      /* Disable CBE fix */
+#define AR5K_PCICFG_SL_INTEN           0x00000800      /* Enable interrupts when asleep */
+#define AR5K_PCICFG_LED_BCTL           0x00001000      /* Led blink (?) [5210] */
+#define AR5K_PCICFG_RETRY_FIX          0x00001000      /* Enable pci core retry fix */
+#define AR5K_PCICFG_SL_INPEN           0x00002000      /* Sleep even whith pending interrupts*/
+#define AR5K_PCICFG_SPWR_DN            0x00010000      /* Mask for power status */
+#define AR5K_PCICFG_LEDMODE            0x000e0000      /* Ledmode [5211+] */
+#define AR5K_PCICFG_LEDMODE_PROP       0x00000000      /* Blink on standard traffic [5211+] */
+#define AR5K_PCICFG_LEDMODE_PROM       0x00020000      /* Default mode (blink on any traffic) [5211+] */
+#define AR5K_PCICFG_LEDMODE_PWR                0x00040000      /* Some other blinking mode  (?) [5211+] */
+#define AR5K_PCICFG_LEDMODE_RAND       0x00060000      /* Random blinking (?) [5211+] */
+#define AR5K_PCICFG_LEDBLINK           0x00700000      /* Led blink rate */
+#define AR5K_PCICFG_LEDBLINK_S         20
+#define AR5K_PCICFG_LEDSLOW            0x00800000      /* Slowest led blink rate [5211+] */
+#define AR5K_PCICFG_LEDSTATE                           \
+       (AR5K_PCICFG_LED | AR5K_PCICFG_LEDMODE |        \
+       AR5K_PCICFG_LEDBLINK | AR5K_PCICFG_LEDSLOW)
+#define        AR5K_PCICFG_SLEEP_CLOCK_RATE    0x03000000      /* Sleep clock rate */
+#define        AR5K_PCICFG_SLEEP_CLOCK_RATE_S  24
+
+/*
+ * "General Purpose Input/Output" (GPIO) control register
+ *
+ * I'm not sure about this but after looking at the code
+ * for all chipsets here is what i got.
+ *
+ * We have 6 GPIOs (pins), each GPIO has 4 modes (2 bits)
+ * Mode 0 -> always input
+ * Mode 1 -> output when GPIODO for this GPIO is set to 0
+ * Mode 2 -> output when GPIODO for this GPIO is set to 1
+ * Mode 3 -> always output
+ *
+ * For more infos check out get_gpio/set_gpio and
+ * set_gpio_input/set_gpio_output functs.
+ * For more infos on gpio interrupt check out set_gpio_intr.
+ */
+#define AR5K_NUM_GPIO  6
+
+#define AR5K_GPIOCR            0x4014                          /* Register Address */
+#define AR5K_GPIOCR_INT_ENA    0x00008000              /* Enable GPIO interrupt */
+#define AR5K_GPIOCR_INT_SELL   0x00000000              /* Generate interrupt when pin is low */
+#define AR5K_GPIOCR_INT_SELH   0x00010000              /* Generate interrupt when pin is high */
+#define AR5K_GPIOCR_IN(n)      (0 << ((n) * 2))        /* Mode 0 for pin n */
+#define AR5K_GPIOCR_OUT0(n)    (1 << ((n) * 2))        /* Mode 1 for pin n */
+#define AR5K_GPIOCR_OUT1(n)    (2 << ((n) * 2))        /* Mode 2 for pin n */
+#define AR5K_GPIOCR_OUT(n)     (3 << ((n) * 2))        /* Mode 3 for pin n */
+#define AR5K_GPIOCR_INT_SEL(n) ((n) << 12)             /* Interrupt for GPIO pin n */
+
+/*
+ * "General Purpose Input/Output" (GPIO) data output register
+ */
+#define AR5K_GPIODO    0x4018
+
+/*
+ * "General Purpose Input/Output" (GPIO) data input register
+ */
+#define AR5K_GPIODI    0x401c
+#define AR5K_GPIODI_M  0x0000002f
+
+/*
+ * Silicon revision register
+ */
+#define AR5K_SREV              0x4020                  /* Register Address */
+#define AR5K_SREV_REV          0x0000000f      /* Mask for revision */
+#define AR5K_SREV_REV_S                0
+#define AR5K_SREV_VER          0x000000ff      /* Mask for version */
+#define AR5K_SREV_VER_S                4
+
+/*
+ * TXE write posting register
+ */
+#define        AR5K_TXEPOST    0x4028
+
+/*
+ * QCU sleep mask
+ */
+#define        AR5K_QCU_SLEEP_MASK     0x402c
+
+/* 0x4068 is compression buffer configuration
+ * register on 5414 and pm configuration register
+ * on 5424 and newer pci-e chips. */
+
+/*
+ * Compression buffer configuration
+ * register (enable/disable) [5414]
+ */
+#define AR5K_5414_CBCFG                0x4068
+#define AR5K_5414_CBCFG_BUF_DIS        0x10    /* Disable buffer */
+
+/*
+ * PCI-E Power managment configuration
+ * and status register [5424+]
+ */
+#define        AR5K_PCIE_PM_CTL                0x4068                  /* Register address */
+/* Only 5424 */
+#define        AR5K_PCIE_PM_CTL_L1_WHEN_D2     0x00000001      /* enable PCIe core enter L1
+                                                       when d2_sleep_en is asserted */
+#define        AR5K_PCIE_PM_CTL_L0_L0S_CLEAR   0x00000002      /* Clear L0 and L0S counters */
+#define        AR5K_PCIE_PM_CTL_L0_L0S_EN      0x00000004      /* Start L0 nd L0S counters */
+#define        AR5K_PCIE_PM_CTL_LDRESET_EN     0x00000008      /* Enable reset when link goes
+                                                       down */
+/* Wake On Wireless */
+#define        AR5K_PCIE_PM_CTL_PME_EN         0x00000010      /* PME Enable */
+#define        AR5K_PCIE_PM_CTL_AUX_PWR_DET    0x00000020      /* Aux power detect */
+#define        AR5K_PCIE_PM_CTL_PME_CLEAR      0x00000040      /* Clear PME */
+#define        AR5K_PCIE_PM_CTL_PSM_D0         0x00000080
+#define        AR5K_PCIE_PM_CTL_PSM_D1         0x00000100
+#define        AR5K_PCIE_PM_CTL_PSM_D2         0x00000200
+#define        AR5K_PCIE_PM_CTL_PSM_D3         0x00000400
+
+/*
+ * PCI-E Workaround enable register
+ */
+#define        AR5K_PCIE_WAEN  0x407c
+
+/*
+ * PCI-E Serializer/Desirializer
+ * registers
+ */
+#define        AR5K_PCIE_SERDES        0x4080
+#define        AR5K_PCIE_SERDES_RESET  0x4084
+
+/*====EEPROM REGISTERS====*/
+
+/*
+ * EEPROM access registers
+ *
+ * Here we got a difference between 5210/5211-12
+ * read data register for 5210 is at 0x6800 and
+ * status register is at 0x6c00. There is also
+ * no eeprom command register on 5210 and the
+ * offsets are different.
+ *
+ * To read eeprom data for a specific offset:
+ * 5210 - enable eeprom access (AR5K_PCICFG_EEAE)
+ *        read AR5K_EEPROM_BASE +(4 * offset)
+ *        check the eeprom status register
+ *        and read eeprom data register.
+ *
+ * 5211 - write offset to AR5K_EEPROM_BASE
+ * 5212   write AR5K_EEPROM_CMD_READ on AR5K_EEPROM_CMD
+ *        check the eeprom status register
+ *        and read eeprom data register.
+ *
+ * To write eeprom data for a specific offset:
+ * 5210 - enable eeprom access (AR5K_PCICFG_EEAE)
+ *        write data to AR5K_EEPROM_BASE +(4 * offset)
+ *        check the eeprom status register
+ * 5211 - write AR5K_EEPROM_CMD_RESET on AR5K_EEPROM_CMD
+ * 5212   write offset to AR5K_EEPROM_BASE
+ *        write data to data register
+ *       write AR5K_EEPROM_CMD_WRITE on AR5K_EEPROM_CMD
+ *        check the eeprom status register
+ *
+ * For more infos check eeprom_* functs and the ar5k.c
+ * file posted in madwifi-devel mailing list.
+ * http://sourceforge.net/mailarchive/message.php?msg_id=8966525
+ *
+ */
+#define AR5K_EEPROM_BASE       0x6000
+
+/*
+ * EEPROM data register
+ */
+#define AR5K_EEPROM_DATA_5211  0x6004
+#define AR5K_EEPROM_DATA_5210  0x6800
+#define        AR5K_EEPROM_DATA        (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_EEPROM_DATA_5210 : AR5K_EEPROM_DATA_5211)
+
+/*
+ * EEPROM command register
+ */
+#define AR5K_EEPROM_CMD                0x6008                  /* Register Addres */
+#define AR5K_EEPROM_CMD_READ   0x00000001      /* EEPROM read */
+#define AR5K_EEPROM_CMD_WRITE  0x00000002      /* EEPROM write */
+#define AR5K_EEPROM_CMD_RESET  0x00000004      /* EEPROM reset */
+
+/*
+ * EEPROM status register
+ */
+#define AR5K_EEPROM_STAT_5210  0x6c00                  /* Register Address [5210] */
+#define AR5K_EEPROM_STAT_5211  0x600c                  /* Register Address [5211+] */
+#define        AR5K_EEPROM_STATUS      (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_EEPROM_STAT_5210 : AR5K_EEPROM_STAT_5211)
+#define AR5K_EEPROM_STAT_RDERR 0x00000001      /* EEPROM read failed */
+#define AR5K_EEPROM_STAT_RDDONE        0x00000002      /* EEPROM read successful */
+#define AR5K_EEPROM_STAT_WRERR 0x00000004      /* EEPROM write failed */
+#define AR5K_EEPROM_STAT_WRDONE        0x00000008      /* EEPROM write successful */
+
+/*
+ * EEPROM config register
+ */
+#define AR5K_EEPROM_CFG                        0x6010                  /* Register Addres */
+#define AR5K_EEPROM_CFG_SIZE           0x00000003              /* Size determination override */
+#define AR5K_EEPROM_CFG_SIZE_AUTO      0
+#define AR5K_EEPROM_CFG_SIZE_4KBIT     1
+#define AR5K_EEPROM_CFG_SIZE_8KBIT     2
+#define AR5K_EEPROM_CFG_SIZE_16KBIT    3
+#define AR5K_EEPROM_CFG_WR_WAIT_DIS    0x00000004      /* Disable write wait */
+#define AR5K_EEPROM_CFG_CLK_RATE       0x00000018      /* Clock rate */
+#define AR5K_EEPROM_CFG_CLK_RATE_S             3
+#define AR5K_EEPROM_CFG_CLK_RATE_156KHZ        0
+#define AR5K_EEPROM_CFG_CLK_RATE_312KHZ        1
+#define AR5K_EEPROM_CFG_CLK_RATE_625KHZ        2
+#define AR5K_EEPROM_CFG_PROT_KEY       0x00ffff00      /* Protection key */
+#define AR5K_EEPROM_CFG_PROT_KEY_S     8
+#define AR5K_EEPROM_CFG_LIND_EN                0x01000000      /* Enable length indicator (?) */
+
+
+/*
+ * TODO: Wake On Wireless registers
+ * Range 0x7000 - 0x7ce0
+ */
+
+/*
+ * Protocol Control Unit (PCU) registers
+ */
+/*
+ * Used for checking initial register writes
+ * during channel reset (see reset func)
+ */
+#define AR5K_PCU_MIN   0x8000
+#define AR5K_PCU_MAX   0x8fff
+
+/*
+ * First station id register (Lower 32 bits of MAC address)
+ */
+#define AR5K_STA_ID0           0x8000
+#define        AR5K_STA_ID0_ARRD_L32   0xffffffff
+
+/*
+ * Second station id register (Upper 16 bits of MAC address + PCU settings)
+ */
+#define AR5K_STA_ID1                   0x8004                  /* Register Address */
+#define        AR5K_STA_ID1_ADDR_U16           0x0000ffff      /* Upper 16 bits of MAC addres */
+#define AR5K_STA_ID1_AP                        0x00010000      /* Set AP mode */
+#define AR5K_STA_ID1_ADHOC             0x00020000      /* Set Ad-Hoc mode */
+#define AR5K_STA_ID1_PWR_SV            0x00040000      /* Power save reporting */
+#define AR5K_STA_ID1_NO_KEYSRCH                0x00080000      /* No key search */
+#define AR5K_STA_ID1_NO_PSPOLL         0x00100000      /* No power save polling [5210] */
+#define AR5K_STA_ID1_PCF_5211          0x00100000      /* Enable PCF on [5211+] */
+#define AR5K_STA_ID1_PCF_5210          0x00200000      /* Enable PCF on [5210]*/
+#define        AR5K_STA_ID1_PCF                (ah->ah_version == AR5K_AR5210 ? \
+                                       AR5K_STA_ID1_PCF_5210 : AR5K_STA_ID1_PCF_5211)
+#define AR5K_STA_ID1_DEFAULT_ANTENNA   0x00200000      /* Use default antenna */
+#define AR5K_STA_ID1_DESC_ANTENNA      0x00400000      /* Update antenna from descriptor */
+#define AR5K_STA_ID1_RTS_DEF_ANTENNA   0x00800000      /* Use default antenna for RTS */
+#define AR5K_STA_ID1_ACKCTS_6MB                0x01000000      /* Use 6Mbit/s for ACK/CTS */
+#define AR5K_STA_ID1_BASE_RATE_11B     0x02000000      /* Use 11b base rate for ACK/CTS [5211+] */
+#define AR5K_STA_ID1_SELFGEN_DEF_ANT   0x04000000      /* Use def. antenna for self generated frames */
+#define AR5K_STA_ID1_CRYPT_MIC_EN      0x08000000      /* Enable MIC */
+#define AR5K_STA_ID1_KEYSRCH_MODE      0x10000000      /* Look up key when key id != 0 */
+#define AR5K_STA_ID1_PRESERVE_SEQ_NUM  0x20000000      /* Preserve sequence number */
+#define AR5K_STA_ID1_CBCIV_ENDIAN      0x40000000      /* ??? */
+#define AR5K_STA_ID1_KEYSRCH_MCAST     0x80000000      /* Do key cache search for mcast frames */
+
+/*
+ * First BSSID register (MAC address, lower 32bits)
+ */
+#define AR5K_BSS_ID0   0x8008
+
+/*
+ * Second BSSID register (MAC address in upper 16 bits)
+ *
+ * AID: Association ID
+ */
+#define AR5K_BSS_ID1           0x800c
+#define AR5K_BSS_ID1_AID       0xffff0000
+#define AR5K_BSS_ID1_AID_S     16
+
+/*
+ * Backoff slot time register
+ */
+#define AR5K_SLOT_TIME 0x8010
+
+/*
+ * ACK/CTS timeout register
+ */
+#define AR5K_TIME_OUT          0x8014                  /* Register Address */
+#define AR5K_TIME_OUT_ACK      0x00001fff      /* ACK timeout mask */
+#define AR5K_TIME_OUT_ACK_S    0
+#define AR5K_TIME_OUT_CTS      0x1fff0000      /* CTS timeout mask */
+#define AR5K_TIME_OUT_CTS_S    16
+
+/*
+ * RSSI threshold register
+ */
+#define AR5K_RSSI_THR                  0x8018          /* Register Address */
+#define AR5K_RSSI_THR_M                        0x000000ff      /* Mask for RSSI threshold [5211+] */
+#define AR5K_RSSI_THR_BMISS_5210       0x00000700      /* Mask for Beacon Missed threshold [5210] */
+#define AR5K_RSSI_THR_BMISS_5210_S     8
+#define AR5K_RSSI_THR_BMISS_5211       0x0000ff00      /* Mask for Beacon Missed threshold [5211+] */
+#define AR5K_RSSI_THR_BMISS_5211_S     8
+#define        AR5K_RSSI_THR_BMISS             (ah->ah_version == AR5K_AR5210 ? \
+                                       AR5K_RSSI_THR_BMISS_5210 : AR5K_RSSI_THR_BMISS_5211)
+#define        AR5K_RSSI_THR_BMISS_S           8
+
+/*
+ * 5210 has more PCU registers because there is no QCU/DCU
+ * so queue parameters are set here, this way a lot common
+ * registers have different address for 5210. To make things
+ * easier we define a macro based on ah->ah_version for common
+ * registers with different addresses and common flags.
+ */
+
+/*
+ * Retry limit register
+ *
+ * Retry limit register for 5210 (no QCU/DCU so it's done in PCU)
+ */
+#define AR5K_NODCU_RETRY_LMT           0x801c                  /* Register Address */
+#define AR5K_NODCU_RETRY_LMT_SH_RETRY  0x0000000f      /* Short retry limit mask */
+#define AR5K_NODCU_RETRY_LMT_SH_RETRY_S        0
+#define AR5K_NODCU_RETRY_LMT_LG_RETRY  0x000000f0      /* Long retry mask */
+#define AR5K_NODCU_RETRY_LMT_LG_RETRY_S        4
+#define AR5K_NODCU_RETRY_LMT_SSH_RETRY 0x00003f00      /* Station short retry limit mask */
+#define AR5K_NODCU_RETRY_LMT_SSH_RETRY_S       8
+#define AR5K_NODCU_RETRY_LMT_SLG_RETRY 0x000fc000      /* Station long retry limit mask */
+#define AR5K_NODCU_RETRY_LMT_SLG_RETRY_S       14
+#define AR5K_NODCU_RETRY_LMT_CW_MIN    0x3ff00000      /* Minimum contention window mask */
+#define AR5K_NODCU_RETRY_LMT_CW_MIN_S  20
+
+/*
+ * Transmit latency register
+ */
+#define AR5K_USEC_5210                 0x8020                  /* Register Address [5210] */
+#define AR5K_USEC_5211                 0x801c                  /* Register Address [5211+] */
+#define AR5K_USEC                      (ah->ah_version == AR5K_AR5210 ? \
+                                       AR5K_USEC_5210 : AR5K_USEC_5211)
+#define AR5K_USEC_1                    0x0000007f      /* clock cycles for 1us */
+#define AR5K_USEC_1_S                  0
+#define AR5K_USEC_32                   0x00003f80      /* clock cycles for 1us while on 32Mhz clock */
+#define AR5K_USEC_32_S                 7
+#define AR5K_USEC_TX_LATENCY_5211      0x007fc000
+#define AR5K_USEC_TX_LATENCY_5211_S    14
+#define AR5K_USEC_RX_LATENCY_5211      0x1f800000
+#define AR5K_USEC_RX_LATENCY_5211_S    23
+#define AR5K_USEC_TX_LATENCY_5210      0x000fc000      /* also for 5311 */
+#define AR5K_USEC_TX_LATENCY_5210_S    14
+#define AR5K_USEC_RX_LATENCY_5210      0x03f00000      /* also for 5311 */
+#define AR5K_USEC_RX_LATENCY_5210_S    20
+
+/*
+ * PCU beacon control register
+ */
+#define AR5K_BEACON_5210       0x8024                  /*Register Address [5210] */
+#define AR5K_BEACON_5211       0x8020                  /*Register Address [5211+] */
+#define AR5K_BEACON            (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_BEACON_5210 : AR5K_BEACON_5211)
+#define AR5K_BEACON_PERIOD     0x0000ffff      /* Mask for beacon period */
+#define AR5K_BEACON_PERIOD_S   0
+#define AR5K_BEACON_TIM                0x007f0000      /* Mask for TIM offset */
+#define AR5K_BEACON_TIM_S      16
+#define AR5K_BEACON_ENABLE     0x00800000      /* Enable beacons */
+#define AR5K_BEACON_RESET_TSF  0x01000000      /* Force TSF reset */
+
+/*
+ * CFP period register
+ */
+#define AR5K_CFP_PERIOD_5210   0x8028
+#define AR5K_CFP_PERIOD_5211   0x8024
+#define AR5K_CFP_PERIOD                (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_CFP_PERIOD_5210 : AR5K_CFP_PERIOD_5211)
+
+/*
+ * Next beacon time register
+ */
+#define AR5K_TIMER0_5210       0x802c
+#define AR5K_TIMER0_5211       0x8028
+#define AR5K_TIMER0            (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_TIMER0_5210 : AR5K_TIMER0_5211)
+
+/*
+ * Next DMA beacon alert register
+ */
+#define AR5K_TIMER1_5210       0x8030
+#define AR5K_TIMER1_5211       0x802c
+#define AR5K_TIMER1            (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_TIMER1_5210 : AR5K_TIMER1_5211)
+
+/*
+ * Next software beacon alert register
+ */
+#define AR5K_TIMER2_5210       0x8034
+#define AR5K_TIMER2_5211       0x8030
+#define AR5K_TIMER2            (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_TIMER2_5210 : AR5K_TIMER2_5211)
+
+/*
+ * Next ATIM window time register
+ */
+#define AR5K_TIMER3_5210       0x8038
+#define AR5K_TIMER3_5211       0x8034
+#define AR5K_TIMER3            (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_TIMER3_5210 : AR5K_TIMER3_5211)
+
+
+/*
+ * 5210 First inter frame spacing register (IFS)
+ */
+#define AR5K_IFS0              0x8040
+#define AR5K_IFS0_SIFS         0x000007ff
+#define AR5K_IFS0_SIFS_S       0
+#define AR5K_IFS0_DIFS         0x007ff800
+#define AR5K_IFS0_DIFS_S       11
+
+/*
+ * 5210 Second inter frame spacing register (IFS)
+ */
+#define AR5K_IFS1              0x8044
+#define AR5K_IFS1_PIFS         0x00000fff
+#define AR5K_IFS1_PIFS_S       0
+#define AR5K_IFS1_EIFS         0x03fff000
+#define AR5K_IFS1_EIFS_S       12
+#define AR5K_IFS1_CS_EN                0x04000000
+
+
+/*
+ * CFP duration register
+ */
+#define AR5K_CFP_DUR_5210      0x8048
+#define AR5K_CFP_DUR_5211      0x8038
+#define AR5K_CFP_DUR           (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_CFP_DUR_5210 : AR5K_CFP_DUR_5211)
+
+/*
+ * Receive filter register
+ */
+#define AR5K_RX_FILTER_5210    0x804c                  /* Register Address [5210] */
+#define AR5K_RX_FILTER_5211    0x803c                  /* Register Address [5211+] */
+#define AR5K_RX_FILTER         (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_RX_FILTER_5210 : AR5K_RX_FILTER_5211)
+#define        AR5K_RX_FILTER_UCAST    0x00000001      /* Don't filter unicast frames */
+#define        AR5K_RX_FILTER_MCAST    0x00000002      /* Don't filter multicast frames */
+#define        AR5K_RX_FILTER_BCAST    0x00000004      /* Don't filter broadcast frames */
+#define        AR5K_RX_FILTER_CONTROL  0x00000008      /* Don't filter control frames */
+#define        AR5K_RX_FILTER_BEACON   0x00000010      /* Don't filter beacon frames */
+#define        AR5K_RX_FILTER_PROM     0x00000020      /* Set promiscuous mode */
+#define        AR5K_RX_FILTER_XRPOLL   0x00000040      /* Don't filter XR poll frame [5212+] */
+#define        AR5K_RX_FILTER_PROBEREQ 0x00000080      /* Don't filter probe requests [5212+] */
+#define        AR5K_RX_FILTER_PHYERR_5212      0x00000100      /* Don't filter phy errors [5212+] */
+#define        AR5K_RX_FILTER_RADARERR_5212    0x00000200      /* Don't filter phy radar errors [5212+] */
+#define AR5K_RX_FILTER_PHYERR_5211     0x00000040      /* [5211] */
+#define AR5K_RX_FILTER_RADARERR_5211   0x00000080      /* [5211] */
+#define AR5K_RX_FILTER_PHYERR  \
+       ((ah->ah_version == AR5K_AR5211 ? \
+       AR5K_RX_FILTER_PHYERR_5211 : AR5K_RX_FILTER_PHYERR_5212))
+#define        AR5K_RX_FILTER_RADARERR \
+       ((ah->ah_version == AR5K_AR5211 ? \
+       AR5K_RX_FILTER_RADARERR_5211 : AR5K_RX_FILTER_RADARERR_5212))
+
+/*
+ * Multicast filter register (lower 32 bits)
+ */
+#define AR5K_MCAST_FILTER0_5210        0x8050
+#define AR5K_MCAST_FILTER0_5211        0x8040
+#define AR5K_MCAST_FILTER0     (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_MCAST_FILTER0_5210 : AR5K_MCAST_FILTER0_5211)
+
+/*
+ * Multicast filter register (higher 16 bits)
+ */
+#define AR5K_MCAST_FILTER1_5210        0x8054
+#define AR5K_MCAST_FILTER1_5211        0x8044
+#define AR5K_MCAST_FILTER1     (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_MCAST_FILTER1_5210 : AR5K_MCAST_FILTER1_5211)
+
+
+/*
+ * Transmit mask register (lower 32 bits) [5210]
+ */
+#define AR5K_TX_MASK0  0x8058
+
+/*
+ * Transmit mask register (higher 16 bits) [5210]
+ */
+#define AR5K_TX_MASK1  0x805c
+
+/*
+ * Clear transmit mask [5210]
+ */
+#define AR5K_CLR_TMASK 0x8060
+
+/*
+ * Trigger level register (before transmission) [5210]
+ */
+#define AR5K_TRIG_LVL  0x8064
+
+
+/*
+ * PCU control register
+ *
+ * Only DIS_RX is used in the code, the rest i guess are
+ * for tweaking/diagnostics.
+ */
+#define AR5K_DIAG_SW_5210              0x8068                  /* Register Address [5210] */
+#define AR5K_DIAG_SW_5211              0x8048                  /* Register Address [5211+] */
+#define AR5K_DIAG_SW                   (ah->ah_version == AR5K_AR5210 ? \
+                                       AR5K_DIAG_SW_5210 : AR5K_DIAG_SW_5211)
+#define AR5K_DIAG_SW_DIS_WEP_ACK       0x00000001      /* Disable ACKs if WEP key is invalid */
+#define AR5K_DIAG_SW_DIS_ACK           0x00000002      /* Disable ACKs */
+#define AR5K_DIAG_SW_DIS_CTS           0x00000004      /* Disable CTSs */
+#define AR5K_DIAG_SW_DIS_ENC           0x00000008      /* Disable encryption */
+#define AR5K_DIAG_SW_DIS_DEC           0x00000010      /* Disable decryption */
+#define AR5K_DIAG_SW_DIS_TX            0x00000020      /* Disable transmit [5210] */
+#define AR5K_DIAG_SW_DIS_RX_5210       0x00000040      /* Disable recieve */
+#define AR5K_DIAG_SW_DIS_RX_5211       0x00000020
+#define        AR5K_DIAG_SW_DIS_RX             (ah->ah_version == AR5K_AR5210 ? \
+                                       AR5K_DIAG_SW_DIS_RX_5210 : AR5K_DIAG_SW_DIS_RX_5211)
+#define AR5K_DIAG_SW_LOOP_BACK_5210    0x00000080      /* Loopback (i guess it goes with DIS_TX) [5210] */
+#define AR5K_DIAG_SW_LOOP_BACK_5211    0x00000040
+#define AR5K_DIAG_SW_LOOP_BACK         (ah->ah_version == AR5K_AR5210 ? \
+                                       AR5K_DIAG_SW_LOOP_BACK_5210 : AR5K_DIAG_SW_LOOP_BACK_5211)
+#define AR5K_DIAG_SW_CORR_FCS_5210     0x00000100      /* Corrupted FCS */
+#define AR5K_DIAG_SW_CORR_FCS_5211     0x00000080
+#define AR5K_DIAG_SW_CORR_FCS          (ah->ah_version == AR5K_AR5210 ? \
+                                       AR5K_DIAG_SW_CORR_FCS_5210 : AR5K_DIAG_SW_CORR_FCS_5211)
+#define AR5K_DIAG_SW_CHAN_INFO_5210    0x00000200      /* Dump channel info */
+#define AR5K_DIAG_SW_CHAN_INFO_5211    0x00000100
+#define AR5K_DIAG_SW_CHAN_INFO         (ah->ah_version == AR5K_AR5210 ? \
+                                       AR5K_DIAG_SW_CHAN_INFO_5210 : AR5K_DIAG_SW_CHAN_INFO_5211)
+#define AR5K_DIAG_SW_EN_SCRAM_SEED_5210        0x00000400      /* Enable fixed scrambler seed */
+#define AR5K_DIAG_SW_EN_SCRAM_SEED_5211        0x00000200
+#define AR5K_DIAG_SW_EN_SCRAM_SEED     (ah->ah_version == AR5K_AR5210 ? \
+                                       AR5K_DIAG_SW_EN_SCRAM_SEED_5210 : AR5K_DIAG_SW_EN_SCRAM_SEED_5211)
+#define AR5K_DIAG_SW_ECO_ENABLE                0x00000400      /* [5211+] */
+#define AR5K_DIAG_SW_SCVRAM_SEED       0x0003f800      /* [5210] */
+#define AR5K_DIAG_SW_SCRAM_SEED_M      0x0001fc00      /* Scrambler seed mask */
+#define AR5K_DIAG_SW_SCRAM_SEED_S      10
+#define AR5K_DIAG_SW_DIS_SEQ_INC       0x00040000      /* Disable seqnum increment (?)[5210] */
+#define AR5K_DIAG_SW_FRAME_NV0_5210    0x00080000
+#define AR5K_DIAG_SW_FRAME_NV0_5211    0x00020000      /* Accept frames of non-zero protocol number */
+#define        AR5K_DIAG_SW_FRAME_NV0          (ah->ah_version == AR5K_AR5210 ? \
+                                       AR5K_DIAG_SW_FRAME_NV0_5210 : AR5K_DIAG_SW_FRAME_NV0_5211)
+#define AR5K_DIAG_SW_OBSPT_M           0x000c0000      /* Observation point select (?) */
+#define AR5K_DIAG_SW_OBSPT_S           18
+#define AR5K_DIAG_SW_RX_CLEAR_HIGH     0x0010000       /* Force RX Clear high */
+#define AR5K_DIAG_SW_IGNORE_CARR_SENSE 0x0020000       /* Ignore virtual carrier sense */
+#define AR5K_DIAG_SW_CHANEL_IDLE_HIGH  0x0040000       /* Force channel idle high */
+#define AR5K_DIAG_SW_PHEAR_ME          0x0080000       /* ??? */
+
+/*
+ * TSF (clock) register (lower 32 bits)
+ */
+#define AR5K_TSF_L32_5210      0x806c
+#define AR5K_TSF_L32_5211      0x804c
+#define        AR5K_TSF_L32            (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_TSF_L32_5210 : AR5K_TSF_L32_5211)
+
+/*
+ * TSF (clock) register (higher 32 bits)
+ */
+#define AR5K_TSF_U32_5210      0x8070
+#define AR5K_TSF_U32_5211      0x8050
+#define        AR5K_TSF_U32            (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_TSF_U32_5210 : AR5K_TSF_U32_5211)
+
+/*
+ * Last beacon timestamp register (Read Only)
+ */
+#define AR5K_LAST_TSTP 0x8080
+
+/*
+ * ADDAC test register [5211+]
+ */
+#define AR5K_ADDAC_TEST                        0x8054                  /* Register Address */
+#define AR5K_ADDAC_TEST_TXCONT                 0x00000001      /* Test continuous tx */
+#define AR5K_ADDAC_TEST_TST_MODE       0x00000002      /* Test mode */
+#define AR5K_ADDAC_TEST_LOOP_EN                0x00000004      /* Enable loop */
+#define AR5K_ADDAC_TEST_LOOP_LEN       0x00000008      /* Loop length (field) */
+#define AR5K_ADDAC_TEST_USE_U8         0x00004000      /* Use upper 8 bits */
+#define AR5K_ADDAC_TEST_MSB            0x00008000      /* State of MSB */
+#define AR5K_ADDAC_TEST_TRIG_SEL       0x00010000      /* Trigger select */
+#define AR5K_ADDAC_TEST_TRIG_PTY       0x00020000      /* Trigger polarity */
+#define AR5K_ADDAC_TEST_RXCONT         0x00040000      /* Continuous capture */
+#define AR5K_ADDAC_TEST_CAPTURE                0x00080000      /* Begin capture */
+#define AR5K_ADDAC_TEST_TST_ARM                0x00100000      /* ARM rx buffer for capture */
+
+/*
+ * Default antenna register [5211+]
+ */
+#define AR5K_DEFAULT_ANTENNA   0x8058
+
+/*
+ * Frame control QoS mask register (?) [5211+]
+ * (FC_QOS_MASK)
+ */
+#define AR5K_FRAME_CTL_QOSM    0x805c
+
+/*
+ * Seq mask register (?) [5211+]
+ */
+#define AR5K_SEQ_MASK  0x8060
+
+/*
+ * Retry count register [5210]
+ */
+#define AR5K_RETRY_CNT         0x8084                  /* Register Address [5210] */
+#define AR5K_RETRY_CNT_SSH     0x0000003f      /* Station short retry count (?) */
+#define AR5K_RETRY_CNT_SLG     0x00000fc0      /* Station long retry count (?) */
+
+/*
+ * Back-off status register [5210]
+ */
+#define AR5K_BACKOFF           0x8088                  /* Register Address [5210] */
+#define AR5K_BACKOFF_CW                0x000003ff      /* Backoff Contention Window (?) */
+#define AR5K_BACKOFF_CNT       0x03ff0000      /* Backoff count (?) */
+
+
+
+/*
+ * NAV register (current)
+ */
+#define AR5K_NAV_5210          0x808c
+#define AR5K_NAV_5211          0x8084
+#define        AR5K_NAV                (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_NAV_5210 : AR5K_NAV_5211)
+
+/*
+ * RTS success register
+ */
+#define AR5K_RTS_OK_5210       0x8090
+#define AR5K_RTS_OK_5211       0x8088
+#define        AR5K_RTS_OK             (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_RTS_OK_5210 : AR5K_RTS_OK_5211)
+
+/*
+ * RTS failure register
+ */
+#define AR5K_RTS_FAIL_5210     0x8094
+#define AR5K_RTS_FAIL_5211     0x808c
+#define        AR5K_RTS_FAIL           (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_RTS_FAIL_5210 : AR5K_RTS_FAIL_5211)
+
+/*
+ * ACK failure register
+ */
+#define AR5K_ACK_FAIL_5210     0x8098
+#define AR5K_ACK_FAIL_5211     0x8090
+#define        AR5K_ACK_FAIL           (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_ACK_FAIL_5210 : AR5K_ACK_FAIL_5211)
+
+/*
+ * FCS failure register
+ */
+#define AR5K_FCS_FAIL_5210     0x809c
+#define AR5K_FCS_FAIL_5211     0x8094
+#define        AR5K_FCS_FAIL           (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_FCS_FAIL_5210 : AR5K_FCS_FAIL_5211)
+
+/*
+ * Beacon count register
+ */
+#define AR5K_BEACON_CNT_5210   0x80a0
+#define AR5K_BEACON_CNT_5211   0x8098
+#define        AR5K_BEACON_CNT         (ah->ah_version == AR5K_AR5210 ? \
+                               AR5K_BEACON_CNT_5210 : AR5K_BEACON_CNT_5211)
+
+
+/*===5212 Specific PCU registers===*/
+
+/*
+ * Transmit power control register
+ */
+#define AR5K_TPC                       0x80e8
+#define AR5K_TPC_ACK                   0x0000003f      /* ack frames */
+#define AR5K_TPC_ACK_S                 0
+#define AR5K_TPC_CTS                   0x00003f00      /* cts frames */
+#define AR5K_TPC_CTS_S                 8
+#define AR5K_TPC_CHIRP                 0x003f0000      /* chirp frames */
+#define AR5K_TPC_CHIRP_S               16
+#define AR5K_TPC_DOPPLER               0x0f000000      /* doppler chirp span */
+#define AR5K_TPC_DOPPLER_S             24
+
+/*
+ * XR (eXtended Range) mode register
+ */
+#define AR5K_XRMODE                    0x80c0                  /* Register Address */
+#define        AR5K_XRMODE_POLL_TYPE_M         0x0000003f      /* Mask for Poll type (?) */
+#define        AR5K_XRMODE_POLL_TYPE_S         0
+#define        AR5K_XRMODE_POLL_SUBTYPE_M      0x0000003c      /* Mask for Poll subtype (?) */
+#define        AR5K_XRMODE_POLL_SUBTYPE_S      2
+#define        AR5K_XRMODE_POLL_WAIT_ALL       0x00000080      /* Wait for poll */
+#define        AR5K_XRMODE_SIFS_DELAY          0x000fff00      /* Mask for SIFS delay */
+#define        AR5K_XRMODE_FRAME_HOLD_M        0xfff00000      /* Mask for frame hold (?) */
+#define        AR5K_XRMODE_FRAME_HOLD_S        20
+
+/*
+ * XR delay register
+ */
+#define AR5K_XRDELAY                   0x80c4                  /* Register Address */
+#define AR5K_XRDELAY_SLOT_DELAY_M      0x0000ffff      /* Mask for slot delay */
+#define AR5K_XRDELAY_SLOT_DELAY_S      0
+#define AR5K_XRDELAY_CHIRP_DELAY_M     0xffff0000      /* Mask for CHIRP data delay */
+#define AR5K_XRDELAY_CHIRP_DELAY_S     16
+
+/*
+ * XR timeout register
+ */
+#define AR5K_XRTIMEOUT                 0x80c8                  /* Register Address */
+#define AR5K_XRTIMEOUT_CHIRP_M         0x0000ffff      /* Mask for CHIRP timeout */
+#define AR5K_XRTIMEOUT_CHIRP_S         0
+#define AR5K_XRTIMEOUT_POLL_M          0xffff0000      /* Mask for Poll timeout */
+#define AR5K_XRTIMEOUT_POLL_S          16
+
+/*
+ * XR chirp register
+ */
+#define AR5K_XRCHIRP                   0x80cc                  /* Register Address */
+#define AR5K_XRCHIRP_SEND              0x00000001      /* Send CHIRP */
+#define AR5K_XRCHIRP_GAP               0xffff0000      /* Mask for CHIRP gap (?) */
+
+/*
+ * XR stomp register
+ */
+#define AR5K_XRSTOMP                   0x80d0                  /* Register Address */
+#define AR5K_XRSTOMP_TX                        0x00000001      /* Stomp Tx (?) */
+#define AR5K_XRSTOMP_RX                        0x00000002      /* Stomp Rx (?) */
+#define AR5K_XRSTOMP_TX_RSSI           0x00000004      /* Stomp Tx RSSI (?) */
+#define AR5K_XRSTOMP_TX_BSSID          0x00000008      /* Stomp Tx BSSID (?) */
+#define AR5K_XRSTOMP_DATA              0x00000010      /* Stomp data (?)*/
+#define AR5K_XRSTOMP_RSSI_THRES                0x0000ff00      /* Mask for XR RSSI threshold */
+
+/*
+ * First enhanced sleep register
+ */
+#define AR5K_SLEEP0                    0x80d4                  /* Register Address */
+#define AR5K_SLEEP0_NEXT_DTIM          0x0007ffff      /* Mask for next DTIM (?) */
+#define AR5K_SLEEP0_NEXT_DTIM_S                0
+#define AR5K_SLEEP0_ASSUME_DTIM                0x00080000      /* Assume DTIM */
+#define AR5K_SLEEP0_ENH_SLEEP_EN       0x00100000      /* Enable enchanced sleep control */
+#define AR5K_SLEEP0_CABTO              0xff000000      /* Mask for CAB Time Out */
+#define AR5K_SLEEP0_CABTO_S            24
+
+/*
+ * Second enhanced sleep register
+ */
+#define AR5K_SLEEP1                    0x80d8                  /* Register Address */
+#define AR5K_SLEEP1_NEXT_TIM           0x0007ffff      /* Mask for next TIM (?) */
+#define AR5K_SLEEP1_NEXT_TIM_S         0
+#define AR5K_SLEEP1_BEACON_TO          0xff000000      /* Mask for Beacon Time Out */
+#define AR5K_SLEEP1_BEACON_TO_S                24
+
+/*
+ * Third enhanced sleep register
+ */
+#define AR5K_SLEEP2                    0x80dc                  /* Register Address */
+#define AR5K_SLEEP2_TIM_PER            0x0000ffff      /* Mask for TIM period (?) */
+#define AR5K_SLEEP2_TIM_PER_S          0
+#define AR5K_SLEEP2_DTIM_PER           0xffff0000      /* Mask for DTIM period (?) */
+#define AR5K_SLEEP2_DTIM_PER_S         16
+
+/*
+ * BSSID mask registers
+ */
+#define AR5K_BSS_IDM0                  0x80e0  /* Upper bits */
+#define AR5K_BSS_IDM1                  0x80e4  /* Lower bits */
+
+/*
+ * TX power control (TPC) register
+ *
+ * XXX: PCDAC steps (0.5dbm) or DBM ?
+ *
+ */
+#define AR5K_TXPC                      0x80e8                  /* Register Address */
+#define AR5K_TXPC_ACK_M                        0x0000003f      /* ACK tx power */
+#define AR5K_TXPC_ACK_S                        0
+#define AR5K_TXPC_CTS_M                        0x00003f00      /* CTS tx power */
+#define AR5K_TXPC_CTS_S                        8
+#define AR5K_TXPC_CHIRP_M              0x003f0000      /* CHIRP tx power */
+#define AR5K_TXPC_CHIRP_S              16
+#define AR5K_TXPC_DOPPLER              0x0f000000      /* Doppler chirp span (?) */
+#define AR5K_TXPC_DOPPLER_S            24
+
+/*
+ * Profile count registers
+ */
+#define AR5K_PROFCNT_TX                        0x80ec  /* Tx count */
+#define AR5K_PROFCNT_RX                        0x80f0  /* Rx count */
+#define AR5K_PROFCNT_RXCLR             0x80f4  /* Clear Rx count */
+#define AR5K_PROFCNT_CYCLE             0x80f8  /* Cycle count (?) */
+
+/*
+ * Quiet period control registers
+ */
+#define AR5K_QUIET_CTL1                        0x80fc                  /* Register Address */
+#define AR5K_QUIET_CTL1_NEXT_QT_TSF    0x0000ffff      /* Next quiet period TSF (TU) */
+#define AR5K_QUIET_CTL1_NEXT_QT_TSF_S  0
+#define AR5K_QUIET_CTL1_QT_EN          0x00010000      /* Enable quiet period */
+#define AR5K_QUIET_CTL1_ACK_CTS_EN     0x00020000      /* Send ACK/CTS during quiet period */
+
+#define AR5K_QUIET_CTL2                        0x8100                  /* Register Address */
+#define AR5K_QUIET_CTL2_QT_PER         0x0000ffff      /* Mask for quiet period periodicity */
+#define AR5K_QUIET_CTL2_QT_PER_S       0
+#define AR5K_QUIET_CTL2_QT_DUR         0xffff0000      /* Mask for quiet period duration */
+#define AR5K_QUIET_CTL2_QT_DUR_S       16
+
+/*
+ * TSF parameter register
+ */
+#define AR5K_TSF_PARM                  0x8104                  /* Register Address */
+#define AR5K_TSF_PARM_INC              0x000000ff      /* Mask for TSF increment */
+#define AR5K_TSF_PARM_INC_S            0
+
+/*
+ * QoS NOACK policy
+ */
+#define AR5K_QOS_NOACK                 0x8108                  /* Register Address */
+#define AR5K_QOS_NOACK_2BIT_VALUES     0x0000000f      /* ??? */
+#define AR5K_QOS_NOACK_2BIT_VALUES_S   0
+#define AR5K_QOS_NOACK_BIT_OFFSET      0x00000070      /* ??? */
+#define AR5K_QOS_NOACK_BIT_OFFSET_S    4
+#define AR5K_QOS_NOACK_BYTE_OFFSET     0x00000180      /* ??? */
+#define AR5K_QOS_NOACK_BYTE_OFFSET_S   7
+
+/*
+ * PHY error filter register
+ */
+#define AR5K_PHY_ERR_FIL               0x810c
+#define AR5K_PHY_ERR_FIL_RADAR         0x00000020      /* Radar signal */
+#define AR5K_PHY_ERR_FIL_OFDM          0x00020000      /* OFDM false detect (ANI) */
+#define AR5K_PHY_ERR_FIL_CCK           0x02000000      /* CCK false detect (ANI) */
+
+/*
+ * XR latency register
+ */
+#define AR5K_XRLAT_TX          0x8110
+
+/*
+ * ACK SIFS register
+ */
+#define AR5K_ACKSIFS           0x8114                  /* Register Address */
+#define AR5K_ACKSIFS_INC       0x00000000      /* ACK SIFS Increment (field) */
+
+/*
+ * MIC QoS control register (?)
+ */
+#define        AR5K_MIC_QOS_CTL                0x8118                  /* Register Address */
+#define        AR5K_MIC_QOS_CTL_OFF(_n)        (1 << (_n * 2))
+#define        AR5K_MIC_QOS_CTL_MQ_EN          0x00010000      /* Enable MIC QoS */
+
+/*
+ * MIC QoS select register (?)
+ */
+#define        AR5K_MIC_QOS_SEL                0x811c
+#define        AR5K_MIC_QOS_SEL_OFF(_n)        (1 << (_n * 4))
+
+/*
+ * Misc mode control register (?)
+ */
+#define        AR5K_MISC_MODE                  0x8120                  /* Register Address */
+#define        AR5K_MISC_MODE_FBSSID_MATCH     0x00000001      /* Force BSSID match */
+#define        AR5K_MISC_MODE_ACKSIFS_MEM      0x00000002      /* ACK SIFS memory (?) */
+#define        AR5K_MISC_MODE_COMBINED_MIC     0x00000004      /* use rx/tx MIC key */
+/* more bits */
+
+/*
+ * OFDM Filter counter
+ */
+#define        AR5K_OFDM_FIL_CNT               0x8124
+
+/*
+ * CCK Filter counter
+ */
+#define        AR5K_CCK_FIL_CNT                0x8128
+
+/*
+ * PHY Error Counters (?)
+ */
+#define        AR5K_PHYERR_CNT1                0x812c
+#define        AR5K_PHYERR_CNT1_MASK           0x8130
+
+#define        AR5K_PHYERR_CNT2                0x8134
+#define        AR5K_PHYERR_CNT2_MASK           0x8138
+
+/*
+ * TSF Threshold register (?)
+ */
+#define        AR5K_TSF_THRES                  0x813c
+
+/*
+ * TODO: Wake On Wireless registers
+ * Range: 0x8147 - 0x818c
+ */
+
+/*
+ * Rate -> ACK SIFS mapping table (32 entries)
+ */
+#define        AR5K_RATE_ACKSIFS_BASE          0x8680                  /* Register Address */
+#define        AR5K_RATE_ACKSIFS(_n)           (AR5K_RATE_ACKSIFS_BSE + ((_n) << 2))
+#define        AR5K_RATE_ACKSIFS_NORMAL        0x00000001      /* Normal SIFS (field) */
+#define        AR5K_RATE_ACKSIFS_TURBO         0x00000400      /* Turbo SIFS (field) */
+
+/*
+ * Rate -> duration mapping table (32 entries)
+ */
+#define AR5K_RATE_DUR_BASE             0x8700
+#define AR5K_RATE_DUR(_n)              (AR5K_RATE_DUR_BASE + ((_n) << 2))
+
+/*
+ * Rate -> db mapping table
+ * (8 entries, each one has 4 8bit fields)
+ */
+#define AR5K_RATE2DB_BASE              0x87c0
+#define AR5K_RATE2DB(_n)               (AR5K_RATE2DB_BASE + ((_n) << 2))
+
+/*
+ * db -> Rate mapping table
+ * (8 entries, each one has 4 8bit fields)
+ */
+#define AR5K_DB2RATE_BASE              0x87e0
+#define AR5K_DB2RATE(_n)               (AR5K_DB2RATE_BASE + ((_n) << 2))
+
+/*===5212 end===*/
+
+/*
+ * Key table (WEP) register
+ */
+#define AR5K_KEYTABLE_0_5210           0x9000
+#define AR5K_KEYTABLE_0_5211           0x8800
+#define AR5K_KEYTABLE_5210(_n)         (AR5K_KEYTABLE_0_5210 + ((_n) << 5))
+#define AR5K_KEYTABLE_5211(_n)         (AR5K_KEYTABLE_0_5211 + ((_n) << 5))
+#define        AR5K_KEYTABLE(_n)               (ah->ah_version == AR5K_AR5210 ? \
+                                       AR5K_KEYTABLE_5210(_n) : AR5K_KEYTABLE_5211(_n))
+#define AR5K_KEYTABLE_OFF(_n, x)       (AR5K_KEYTABLE(_n) + (x << 2))
+#define AR5K_KEYTABLE_TYPE(_n)         AR5K_KEYTABLE_OFF(_n, 5)
+#define AR5K_KEYTABLE_TYPE_40          0x00000000
+#define AR5K_KEYTABLE_TYPE_104         0x00000001
+#define AR5K_KEYTABLE_TYPE_128         0x00000003
+#define AR5K_KEYTABLE_TYPE_TKIP                0x00000004      /* [5212+] */
+#define AR5K_KEYTABLE_TYPE_AES         0x00000005      /* [5211+] */
+#define AR5K_KEYTABLE_TYPE_CCM         0x00000006      /* [5212+] */
+#define AR5K_KEYTABLE_TYPE_NULL                0x00000007      /* [5211+] */
+#define AR5K_KEYTABLE_ANTENNA          0x00000008      /* [5212+] */
+#define AR5K_KEYTABLE_MAC0(_n)         AR5K_KEYTABLE_OFF(_n, 6)
+#define AR5K_KEYTABLE_MAC1(_n)         AR5K_KEYTABLE_OFF(_n, 7)
+#define AR5K_KEYTABLE_VALID            0x00008000
+
+/* If key type is TKIP and MIC is enabled
+ * MIC key goes in offset entry + 64 */
+#define        AR5K_KEYTABLE_MIC_OFFSET        64
+
+/* WEP 40-bit  = 40-bit  entered key + 24 bit IV = 64-bit
+ * WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit
+ * WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit
+ *
+ * Some vendors have introduced bigger WEP keys to address
+ * security vulnerabilities in WEP. This includes:
+ *
+ * WEP 232-bit = 232-bit entered key + 24 bit IV = 256-bit
+ *
+ * We can expand this if we find ar5k Atheros cards with a larger
+ * key table size.
+ */
+#define AR5K_KEYTABLE_SIZE_5210                64
+#define AR5K_KEYTABLE_SIZE_5211                128
+#define        AR5K_KEYTABLE_SIZE              (ah->ah_version == AR5K_AR5210 ? \
+                                       AR5K_KEYTABLE_SIZE_5210 : AR5K_KEYTABLE_SIZE_5211)
+
+
+/*===PHY REGISTERS===*/
+
+/*
+ * PHY registers start
+ */
+#define        AR5K_PHY_BASE                   0x9800
+#define        AR5K_PHY(_n)                    (AR5K_PHY_BASE + ((_n) << 2))
+
+/*
+ * TST_2 (Misc config parameters)
+ */
+#define        AR5K_PHY_TST2                   0x9800                  /* Register Address */
+#define AR5K_PHY_TST2_TRIG_SEL         0x00000007      /* Trigger select (?)*/
+#define AR5K_PHY_TST2_TRIG             0x00000010      /* Trigger (?) */
+#define AR5K_PHY_TST2_CBUS_MODE                0x00000060      /* Cardbus mode (?) */
+#define AR5K_PHY_TST2_CLK32            0x00000400      /* CLK_OUT is CLK32 (32Khz external) */
+#define AR5K_PHY_TST2_CHANCOR_DUMP_EN  0x00000800      /* Enable Chancor dump (?) */
+#define AR5K_PHY_TST2_EVEN_CHANCOR_DUMP        0x00001000      /* Even Chancor dump (?) */
+#define AR5K_PHY_TST2_RFSILENT_EN      0x00002000      /* Enable RFSILENT */
+#define AR5K_PHY_TST2_ALT_RFDATA       0x00004000      /* Alternate RFDATA (5-2GHz switch ?) */
+#define AR5K_PHY_TST2_MINI_OBS_EN      0x00008000      /* Enable mini OBS (?) */
+#define AR5K_PHY_TST2_RX2_IS_RX5_INV   0x00010000      /* 2GHz rx path is the 5GHz path inverted (?) */
+#define AR5K_PHY_TST2_SLOW_CLK160      0x00020000      /* Slow CLK160 (?) */
+#define AR5K_PHY_TST2_AGC_OBS_SEL_3    0x00040000      /* AGC OBS Select 3 (?) */
+#define AR5K_PHY_TST2_BBB_OBS_SEL      0x00080000      /* BB OBS Select (field ?) */
+#define AR5K_PHY_TST2_ADC_OBS_SEL      0x00800000      /* ADC OBS Select (field ?) */
+#define AR5K_PHY_TST2_RX_CLR_SEL       0x08000000      /* RX Clear Select (?) */
+#define AR5K_PHY_TST2_FORCE_AGC_CLR    0x10000000      /* Force AGC clear (?) */
+#define AR5K_PHY_SHIFT_2GHZ            0x00004007      /* Used to access 2GHz radios */
+#define AR5K_PHY_SHIFT_5GHZ            0x00000007      /* Used to access 5GHz radios (default) */
+
+/*
+ * PHY frame control register [5110] /turbo mode register [5111+]
+ *
+ * There is another frame control register for [5111+]
+ * at address 0x9944 (see below) but the 2 first flags
+ * are common here between 5110 frame control register
+ * and [5111+] turbo mode register, so this also works as
+ * a "turbo mode register" for 5110. We treat this one as
+ * a frame control register for 5110 below.
+ */
+#define        AR5K_PHY_TURBO                  0x9804                  /* Register Address */
+#define        AR5K_PHY_TURBO_MODE             0x00000001      /* Enable turbo mode */
+#define        AR5K_PHY_TURBO_SHORT            0x00000002      /* Set short symbols to turbo mode */
+#define        AR5K_PHY_TURBO_MIMO             0x00000004      /* Set turbo for mimo mimo */
+
+/*
+ * PHY agility command register
+ * (aka TST_1)
+ */
+#define        AR5K_PHY_AGC                    0x9808                  /* Register Address */
+#define        AR5K_PHY_TST1                   0x9808
+#define        AR5K_PHY_AGC_DISABLE            0x08000000      /* Disable AGC to A2 (?)*/
+#define        AR5K_PHY_TST1_TXHOLD            0x00003800      /* Set tx hold (?) */
+#define        AR5K_PHY_TST1_TXSRC_SRC         0x00000002      /* Used with bit 7 (?) */
+#define        AR5K_PHY_TST1_TXSRC_SRC_S       1
+#define        AR5K_PHY_TST1_TXSRC_ALT         0x00000080      /* Set input to tsdac (?) */
+#define        AR5K_PHY_TST1_TXSRC_ALT_S       7
+
+
+/*
+ * PHY timing register 3 [5112+]
+ */
+#define        AR5K_PHY_TIMING_3               0x9814
+#define        AR5K_PHY_TIMING_3_DSC_MAN       0xfffe0000
+#define        AR5K_PHY_TIMING_3_DSC_MAN_S     17
+#define        AR5K_PHY_TIMING_3_DSC_EXP       0x0001e000
+#define        AR5K_PHY_TIMING_3_DSC_EXP_S     13
+
+/*
+ * PHY chip revision register
+ */
+#define        AR5K_PHY_CHIP_ID                0x9818
+
+/*
+ * PHY activation register
+ */
+#define        AR5K_PHY_ACT                    0x981c                  /* Register Address */
+#define        AR5K_PHY_ACT_ENABLE             0x00000001      /* Activate PHY */
+#define        AR5K_PHY_ACT_DISABLE            0x00000002      /* Deactivate PHY */
+
+/*
+ * PHY RF control registers
+ */
+#define AR5K_PHY_RF_CTL2               0x9824                  /* Register Address */
+#define        AR5K_PHY_RF_CTL2_TXF2TXD_START  0x0000000f      /* TX frame to TX data start */
+#define        AR5K_PHY_RF_CTL2_TXF2TXD_START_S        0
+
+#define AR5K_PHY_RF_CTL3               0x9828                  /* Register Address */
+#define AR5K_PHY_RF_CTL3_TXE2XLNA_ON   0x0000ff00      /* TX end to XLNA on */
+#define        AR5K_PHY_RF_CTL3_TXE2XLNA_ON_S  8
+
+#define        AR5K_PHY_ADC_CTL                        0x982c
+#define        AR5K_PHY_ADC_CTL_INBUFGAIN_OFF          0x00000003
+#define        AR5K_PHY_ADC_CTL_INBUFGAIN_OFF_S        0
+#define        AR5K_PHY_ADC_CTL_PWD_DAC_OFF            0x00002000
+#define        AR5K_PHY_ADC_CTL_PWD_BAND_GAP_OFF       0x00004000
+#define        AR5K_PHY_ADC_CTL_PWD_ADC_OFF            0x00008000
+#define        AR5K_PHY_ADC_CTL_INBUFGAIN_ON           0x00030000
+#define        AR5K_PHY_ADC_CTL_INBUFGAIN_ON_S         16
+
+#define AR5K_PHY_RF_CTL4               0x9834                  /* Register Address */
+#define AR5K_PHY_RF_CTL4_TXF2XPA_A_ON  0x00000001      /* TX frame to XPA A on (field) */
+#define AR5K_PHY_RF_CTL4_TXF2XPA_B_ON  0x00000100      /* TX frame to XPA B on (field) */
+#define        AR5K_PHY_RF_CTL4_TXE2XPA_A_OFF  0x00010000      /* TX end to XPA A off (field) */
+#define AR5K_PHY_RF_CTL4_TXE2XPA_B_OFF 0x01000000      /* TX end to XPA B off (field) */
+
+/*
+ * Pre-Amplifier control register
+ * (XPA -> external pre-amplifier)
+ */
+#define        AR5K_PHY_PA_CTL                 0x9838                  /* Register Address */
+#define        AR5K_PHY_PA_CTL_XPA_A_HI        0x00000001      /* XPA A high (?) */
+#define        AR5K_PHY_PA_CTL_XPA_B_HI        0x00000002      /* XPA B high (?) */
+#define        AR5K_PHY_PA_CTL_XPA_A_EN        0x00000004      /* Enable XPA A */
+#define        AR5K_PHY_PA_CTL_XPA_B_EN        0x00000008      /* Enable XPA B */
+
+/*
+ * PHY settling register
+ */
+#define AR5K_PHY_SETTLING              0x9844                  /* Register Address */
+#define        AR5K_PHY_SETTLING_AGC           0x0000007f      /* AGC settling time */
+#define        AR5K_PHY_SETTLING_AGC_S         0
+#define        AR5K_PHY_SETTLING_SWITCH        0x00003f80      /* Switch settlig time */
+#define        AR5K_PHY_SETTLING_SWITCH_S      7
+
+/*
+ * PHY Gain registers
+ */
+#define AR5K_PHY_GAIN                  0x9848                  /* Register Address */
+#define        AR5K_PHY_GAIN_TXRX_ATTEN        0x0003f000      /* TX-RX Attenuation */
+#define        AR5K_PHY_GAIN_TXRX_ATTEN_S      12
+#define        AR5K_PHY_GAIN_TXRX_RF_MAX       0x007c0000
+#define        AR5K_PHY_GAIN_TXRX_RF_MAX_S     18
+
+#define        AR5K_PHY_GAIN_OFFSET            0x984c                  /* Register Address */
+#define        AR5K_PHY_GAIN_OFFSET_RXTX_FLAG  0x00020000      /* RX-TX flag (?) */
+
+/*
+ * Desired ADC/PGA size register
+ * (for more infos read ANI patent)
+ */
+#define AR5K_PHY_DESIRED_SIZE          0x9850                  /* Register Address */
+#define        AR5K_PHY_DESIRED_SIZE_ADC       0x000000ff      /* ADC desired size */
+#define        AR5K_PHY_DESIRED_SIZE_ADC_S     0
+#define        AR5K_PHY_DESIRED_SIZE_PGA       0x0000ff00      /* PGA desired size */
+#define        AR5K_PHY_DESIRED_SIZE_PGA_S     8
+#define        AR5K_PHY_DESIRED_SIZE_TOT       0x0ff00000      /* Total desired size */
+#define        AR5K_PHY_DESIRED_SIZE_TOT_S     20
+
+/*
+ * PHY signal register
+ * (for more infos read ANI patent)
+ */
+#define        AR5K_PHY_SIG                    0x9858                  /* Register Address */
+#define        AR5K_PHY_SIG_FIRSTEP            0x0003f000      /* FIRSTEP */
+#define        AR5K_PHY_SIG_FIRSTEP_S          12
+#define        AR5K_PHY_SIG_FIRPWR             0x03fc0000      /* FIPWR */
+#define        AR5K_PHY_SIG_FIRPWR_S           18
+
+/*
+ * PHY coarse agility control register
+ * (for more infos read ANI patent)
+ */
+#define        AR5K_PHY_AGCCOARSE              0x985c                  /* Register Address */
+#define        AR5K_PHY_AGCCOARSE_LO           0x00007f80      /* AGC Coarse low */
+#define        AR5K_PHY_AGCCOARSE_LO_S         7
+#define        AR5K_PHY_AGCCOARSE_HI           0x003f8000      /* AGC Coarse high */
+#define        AR5K_PHY_AGCCOARSE_HI_S         15
+
+/*
+ * PHY agility control register
+ */
+#define        AR5K_PHY_AGCCTL                 0x9860                  /* Register address */
+#define        AR5K_PHY_AGCCTL_CAL             0x00000001      /* Enable PHY calibration */
+#define        AR5K_PHY_AGCCTL_NF              0x00000002      /* Enable Noise Floor calibration */
+#define        AR5K_PHY_AGCCTL_NF_EN           0x00008000      /* Enable nf calibration to happen (?) */
+#define        AR5K_PHY_AGCCTL_NF_NOUPDATE     0x00020000      /* Don't update nf automaticaly */
+
+/*
+ * PHY noise floor status register
+ */
+#define AR5K_PHY_NF                    0x9864                  /* Register address */
+#define AR5K_PHY_NF_M                  0x000001ff      /* Noise floor mask */
+#define AR5K_PHY_NF_ACTIVE             0x00000100      /* Noise floor calibration still active */
+#define AR5K_PHY_NF_RVAL(_n)           (((_n) >> 19) & AR5K_PHY_NF_M)
+#define AR5K_PHY_NF_AVAL(_n)           (-((_n) ^ AR5K_PHY_NF_M) + 1)
+#define AR5K_PHY_NF_SVAL(_n)           (((_n) & AR5K_PHY_NF_M) | (1 << 9))
+#define        AR5K_PHY_NF_THRESH62            0x0007f000      /* Thresh62 -check ANI patent- (field) */
+#define        AR5K_PHY_NF_THRESH62_S          12
+#define        AR5K_PHY_NF_MINCCA_PWR          0x0ff80000      /* ??? */
+#define        AR5K_PHY_NF_MINCCA_PWR_S        19
+
+/*
+ * PHY ADC saturation register [5110]
+ */
+#define        AR5K_PHY_ADCSAT                 0x9868
+#define        AR5K_PHY_ADCSAT_ICNT            0x0001f800
+#define        AR5K_PHY_ADCSAT_ICNT_S          11
+#define        AR5K_PHY_ADCSAT_THR             0x000007e0
+#define        AR5K_PHY_ADCSAT_THR_S           5
+
+/*
+ * PHY Weak ofdm signal detection threshold registers (ANI) [5212+]
+ */
+
+/* High thresholds */
+#define AR5K_PHY_WEAK_OFDM_HIGH_THR            0x9868
+#define AR5K_PHY_WEAK_OFDM_HIGH_THR_M2_COUNT   0x0000001f
+#define AR5K_PHY_WEAK_OFDM_HIGH_THR_M2_COUNT_S 0
+#define AR5K_PHY_WEAK_OFDM_HIGH_THR_M1         0x00fe0000
+#define AR5K_PHY_WEAK_OFDM_HIGH_THR_M1_S       17
+#define AR5K_PHY_WEAK_OFDM_HIGH_THR_M2         0x7f000000
+#define AR5K_PHY_WEAK_OFDM_HIGH_THR_M2_S       24
+
+/* Low thresholds */
+#define AR5K_PHY_WEAK_OFDM_LOW_THR             0x986c
+#define AR5K_PHY_WEAK_OFDM_LOW_THR_SELFCOR_EN  0x00000001
+#define AR5K_PHY_WEAK_OFDM_LOW_THR_M2_COUNT    0x00003f00
+#define AR5K_PHY_WEAK_OFDM_LOW_THR_M2_COUNT_S  8
+#define AR5K_PHY_WEAK_OFDM_LOW_THR_M1          0x001fc000
+#define AR5K_PHY_WEAK_OFDM_LOW_THR_M1_S                14
+#define AR5K_PHY_WEAK_OFDM_LOW_THR_M2          0x0fe00000
+#define AR5K_PHY_WEAK_OFDM_LOW_THR_M2_S                21
+
+
+/*
+ * PHY sleep registers [5112+]
+ */
+#define AR5K_PHY_SCR                   0x9870
+
+#define AR5K_PHY_SLMT                  0x9874
+#define AR5K_PHY_SLMT_32MHZ            0x0000007f
+
+#define AR5K_PHY_SCAL                  0x9878
+#define AR5K_PHY_SCAL_32MHZ            0x0000000e
+#define        AR5K_PHY_SCAL_32MHZ_2417        0x0000000a
+#define        AR5K_PHY_SCAL_32MHZ_HB63        0x00000032
+
+/*
+ * PHY PLL (Phase Locked Loop) control register
+ */
+#define        AR5K_PHY_PLL                    0x987c
+#define        AR5K_PHY_PLL_20MHZ              0x00000013      /* For half rate (?) */
+/* 40MHz -> 5GHz band */
+#define        AR5K_PHY_PLL_40MHZ_5211         0x00000018
+#define        AR5K_PHY_PLL_40MHZ_5212         0x000000aa
+#define        AR5K_PHY_PLL_40MHZ_5413         0x00000004
+#define        AR5K_PHY_PLL_40MHZ              (ah->ah_version == AR5K_AR5211 ? \
+                                       AR5K_PHY_PLL_40MHZ_5211 : AR5K_PHY_PLL_40MHZ_5212)
+/* 44MHz -> 2.4GHz band */
+#define        AR5K_PHY_PLL_44MHZ_5211         0x00000019
+#define        AR5K_PHY_PLL_44MHZ_5212         0x000000ab
+#define        AR5K_PHY_PLL_44MHZ              (ah->ah_version == AR5K_AR5211 ? \
+                                       AR5K_PHY_PLL_44MHZ_5211 : AR5K_PHY_PLL_44MHZ_5212)
+
+#define AR5K_PHY_PLL_RF5111            0x00000000
+#define AR5K_PHY_PLL_RF5112            0x00000040
+#define        AR5K_PHY_PLL_HALF_RATE          0x00000100
+#define        AR5K_PHY_PLL_QUARTER_RATE       0x00000200
+
+/*
+ * RF Buffer register
+ *
+ * It's obvious from the code that 0x989c is the buffer register but
+ * for the other special registers that we write to after sending each
+ * packet, i have no idea. So i'll name them BUFFER_CONTROL_X registers
+ * for now. It's interesting that they are also used for some other operations.
+ */
+
+#define AR5K_RF_BUFFER                 0x989c
+#define AR5K_RF_BUFFER_CONTROL_0       0x98c0  /* Channel on 5110 */
+#define AR5K_RF_BUFFER_CONTROL_1       0x98c4  /* Bank 7 on 5112 */
+#define AR5K_RF_BUFFER_CONTROL_2       0x98cc  /* Bank 7 on 5111 */
+
+#define AR5K_RF_BUFFER_CONTROL_3       0x98d0  /* Bank 2 on 5112 */
+                                               /* Channel set on 5111 */
+                                               /* Used to read radio revision*/
+
+#define AR5K_RF_BUFFER_CONTROL_4       0x98d4  /* RF Stage register on 5110 */
+                                               /* Bank 0,1,2,6 on 5111 */
+                                               /* Bank 1 on 5112 */
+                                               /* Used during activation on 5111 */
+
+#define AR5K_RF_BUFFER_CONTROL_5       0x98d8  /* Bank 3 on 5111 */
+                                               /* Used during activation on 5111 */
+                                               /* Channel on 5112 */
+                                               /* Bank 6 on 5112 */
+
+#define AR5K_RF_BUFFER_CONTROL_6       0x98dc  /* Bank 3 on 5112 */
+
+/*
+ * PHY RF stage register [5210]
+ */
+#define AR5K_PHY_RFSTG                 0x98d4
+#define AR5K_PHY_RFSTG_DISABLE         0x00000021
+
+/*
+ * BIN masks (?)
+ */
+#define        AR5K_PHY_BIN_MASK_1     0x9900
+#define        AR5K_PHY_BIN_MASK_2     0x9904
+#define        AR5K_PHY_BIN_MASK_3     0x9908
+
+#define        AR5K_PHY_BIN_MASK_CTL           0x990c
+#define        AR5K_PHY_BIN_MASK_CTL_MASK_4    0x00003fff
+#define        AR5K_PHY_BIN_MASK_CTL_MASK_4_S  0
+#define        AR5K_PHY_BIN_MASK_CTL_RATE      0xff000000
+#define        AR5K_PHY_BIN_MASK_CTL_RATE_S    24
+
+/*
+ * PHY Antenna control register
+ */
+#define AR5K_PHY_ANT_CTL               0x9910                  /* Register Address */
+#define        AR5K_PHY_ANT_CTL_TXRX_EN        0x00000001      /* Enable TX/RX (?) */
+#define        AR5K_PHY_ANT_CTL_SECTORED_ANT   0x00000004      /* Sectored Antenna */
+#define        AR5K_PHY_ANT_CTL_HITUNE5        0x00000008      /* Hitune5 (?) */
+#define        AR5K_PHY_ANT_CTL_SWTABLE_IDLE   0x000003f0      /* Switch table idle (?) */
+#define        AR5K_PHY_ANT_CTL_SWTABLE_IDLE_S 4
+
+/*
+ * PHY receiver delay register [5111+]
+ */
+#define        AR5K_PHY_RX_DELAY               0x9914                  /* Register Address */
+#define        AR5K_PHY_RX_DELAY_M             0x00003fff      /* Mask for RX activate to receive delay (/100ns) */
+
+/*
+ * PHY max rx length register (?) [5111]
+ */
+#define        AR5K_PHY_MAX_RX_LEN             0x991c
+
+/*
+ * PHY timing register 4
+ * I(nphase)/Q(adrature) calibration register [5111+]
+ */
+#define        AR5K_PHY_IQ                     0x9920                  /* Register Address */
+#define        AR5K_PHY_IQ_CORR_Q_Q_COFF       0x0000001f      /* Mask for q correction info */
+#define        AR5K_PHY_IQ_CORR_Q_I_COFF       0x000007e0      /* Mask for i correction info */
+#define        AR5K_PHY_IQ_CORR_Q_I_COFF_S     5
+#define        AR5K_PHY_IQ_CORR_ENABLE         0x00000800      /* Enable i/q correction */
+#define        AR5K_PHY_IQ_CAL_NUM_LOG_MAX     0x0000f000      /* Mask for max number of samples in log scale */
+#define        AR5K_PHY_IQ_CAL_NUM_LOG_MAX_S   12
+#define        AR5K_PHY_IQ_RUN                 0x00010000      /* Run i/q calibration */
+#define        AR5K_PHY_IQ_USE_PT_DF           0x00020000      /* Use pilot track df (?) */
+#define        AR5K_PHY_IQ_EARLY_TRIG_THR      0x00200000      /* Early trigger threshold (?) (field) */
+#define        AR5K_PHY_IQ_PILOT_MASK_EN       0x10000000      /* Enable pilot mask (?) */
+#define        AR5K_PHY_IQ_CHAN_MASK_EN        0x20000000      /* Enable channel mask (?) */
+#define        AR5K_PHY_IQ_SPUR_FILT_EN        0x40000000      /* Enable spur filter */
+#define        AR5K_PHY_IQ_SPUR_RSSI_EN        0x80000000      /* Enable spur rssi */
+
+/*
+ * PHY timing register 5
+ * OFDM Self-correlator Cyclic RSSI threshold params
+ * (Check out bb_cycpwr_thr1 on ANI patent)
+ */
+#define        AR5K_PHY_OFDM_SELFCORR                  0x9924                  /* Register Address */
+#define        AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1_EN    0x00000001      /* Enable cyclic RSSI thr 1 */
+#define        AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1       0x000000fe      /* Mask for Cyclic RSSI threshold 1 */
+#define        AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1_S     1
+#define        AR5K_PHY_OFDM_SELFCORR_CYPWR_THR3       0x00000100      /* Cyclic RSSI threshold 3 (field) (?) */
+#define        AR5K_PHY_OFDM_SELFCORR_RSSI_1ATHR_EN    0x00008000      /* Enable 1A RSSI threshold (?) */
+#define        AR5K_PHY_OFDM_SELFCORR_RSSI_1ATHR       0x00010000      /* 1A RSSI threshold (field) (?) */
+#define        AR5K_PHY_OFDM_SELFCORR_LSCTHR_HIRSSI    0x00800000      /* Long sc threshold hi rssi (?) */
+
+/*
+ * PHY-only warm reset register
+ */
+#define        AR5K_PHY_WARM_RESET             0x9928
+
+/*
+ * PHY-only control register
+ */
+#define AR5K_PHY_CTL                   0x992c                  /* Register Address */
+#define        AR5K_PHY_CTL_RX_DRAIN_RATE      0x00000001      /* RX drain rate (?) */
+#define        AR5K_PHY_CTL_LATE_TX_SIG_SYM    0x00000002      /* Late tx signal symbol (?) */
+#define        AR5K_PHY_CTL_GEN_SCRAMBLER      0x00000004      /* Generate scrambler */
+#define        AR5K_PHY_CTL_TX_ANT_SEL         0x00000008      /* TX antenna select */
+#define        AR5K_PHY_CTL_TX_ANT_STATIC      0x00000010      /* Static TX antenna */
+#define        AR5K_PHY_CTL_RX_ANT_SEL         0x00000020      /* RX antenna select */
+#define        AR5K_PHY_CTL_RX_ANT_STATIC      0x00000040      /* Static RX antenna */
+#define        AR5K_PHY_CTL_LOW_FREQ_SLE_EN    0x00000080      /* Enable low freq sleep */
+
+/*
+ * PHY PAPD probe register [5111+]
+ */
+#define        AR5K_PHY_PAPD_PROBE             0x9930
+#define        AR5K_PHY_PAPD_PROBE_SH_HI_PAR   0x00000001
+#define        AR5K_PHY_PAPD_PROBE_PCDAC_BIAS  0x00000002
+#define        AR5K_PHY_PAPD_PROBE_COMP_GAIN   0x00000040
+#define        AR5K_PHY_PAPD_PROBE_TXPOWER     0x00007e00
+#define        AR5K_PHY_PAPD_PROBE_TXPOWER_S   9
+#define        AR5K_PHY_PAPD_PROBE_TX_NEXT     0x00008000
+#define        AR5K_PHY_PAPD_PROBE_PREDIST_EN  0x00010000
+#define        AR5K_PHY_PAPD_PROBE_TYPE        0x01800000      /* [5112+] */
+#define        AR5K_PHY_PAPD_PROBE_TYPE_S      23
+#define        AR5K_PHY_PAPD_PROBE_TYPE_OFDM   0
+#define        AR5K_PHY_PAPD_PROBE_TYPE_XR     1
+#define        AR5K_PHY_PAPD_PROBE_TYPE_CCK    2
+#define        AR5K_PHY_PAPD_PROBE_GAINF       0xfe000000
+#define        AR5K_PHY_PAPD_PROBE_GAINF_S     25
+#define        AR5K_PHY_PAPD_PROBE_INI_5111    0x00004883      /* [5212+] */
+#define        AR5K_PHY_PAPD_PROBE_INI_5112    0x00004882      /* [5212+] */
+
+/*
+ * PHY TX rate power registers [5112+]
+ */
+#define        AR5K_PHY_TXPOWER_RATE1                  0x9934
+#define        AR5K_PHY_TXPOWER_RATE2                  0x9938
+#define        AR5K_PHY_TXPOWER_RATE_MAX               0x993c
+#define        AR5K_PHY_TXPOWER_RATE_MAX_TPC_ENABLE    0x00000040
+#define        AR5K_PHY_TXPOWER_RATE3                  0xa234
+#define        AR5K_PHY_TXPOWER_RATE4                  0xa238
+
+/*
+ * PHY frame control register [5111+]
+ */
+#define        AR5K_PHY_FRAME_CTL_5210         0x9804
+#define        AR5K_PHY_FRAME_CTL_5211         0x9944
+#define        AR5K_PHY_FRAME_CTL              (ah->ah_version == AR5K_AR5210 ? \
+                                       AR5K_PHY_FRAME_CTL_5210 : AR5K_PHY_FRAME_CTL_5211)
+/*---[5111+]---*/
+#define        AR5K_PHY_FRAME_CTL_TX_CLIP      0x00000038      /* Mask for tx clip (?) */
+#define        AR5K_PHY_FRAME_CTL_TX_CLIP_S    3
+#define        AR5K_PHY_FRAME_CTL_PREP_CHINFO  0x00010000      /* Prepend chan info */
+#define        AR5K_PHY_FRAME_CTL_EMU          0x80000000
+#define        AR5K_PHY_FRAME_CTL_EMU_S        31
+/*---[5110/5111]---*/
+#define        AR5K_PHY_FRAME_CTL_TIMING_ERR   0x01000000      /* PHY timing error */
+#define        AR5K_PHY_FRAME_CTL_PARITY_ERR   0x02000000      /* Parity error */
+#define        AR5K_PHY_FRAME_CTL_ILLRATE_ERR  0x04000000      /* Illegal rate */
+#define        AR5K_PHY_FRAME_CTL_ILLLEN_ERR   0x08000000      /* Illegal length */
+#define        AR5K_PHY_FRAME_CTL_SERVICE_ERR  0x20000000
+#define        AR5K_PHY_FRAME_CTL_TXURN_ERR    0x40000000      /* TX underrun */
+#define AR5K_PHY_FRAME_CTL_INI         AR5K_PHY_FRAME_CTL_SERVICE_ERR | \
+                       AR5K_PHY_FRAME_CTL_TXURN_ERR | \
+                       AR5K_PHY_FRAME_CTL_ILLLEN_ERR | \
+                       AR5K_PHY_FRAME_CTL_ILLRATE_ERR | \
+                       AR5K_PHY_FRAME_CTL_PARITY_ERR | \
+                       AR5K_PHY_FRAME_CTL_TIMING_ERR
+
+/*
+ * PHY Tx Power adjustment register [5212A+]
+ */
+#define        AR5K_PHY_TX_PWR_ADJ                     0x994c
+#define        AR5K_PHY_TX_PWR_ADJ_CCK_GAIN_DELTA      0x00000fc0
+#define        AR5K_PHY_TX_PWR_ADJ_CCK_GAIN_DELTA_S    6
+#define        AR5K_PHY_TX_PWR_ADJ_CCK_PCDAC_INDEX     0x00fc0000
+#define        AR5K_PHY_TX_PWR_ADJ_CCK_PCDAC_INDEX_S   18
+
+/*
+ * PHY radar detection register [5111+]
+ */
+#define        AR5K_PHY_RADAR                  0x9954
+#define        AR5K_PHY_RADAR_ENABLE           0x00000001
+#define        AR5K_PHY_RADAR_DISABLE          0x00000000
+#define AR5K_PHY_RADAR_INBANDTHR       0x0000003e      /* Inband threshold
+                                                       5-bits, units unknown {0..31}
+                                                       (? MHz ?) */
+#define AR5K_PHY_RADAR_INBANDTHR_S     1
+
+#define AR5K_PHY_RADAR_PRSSI_THR       0x00000fc0      /* Pulse RSSI/SNR threshold
+                                                       6-bits, dBm range {0..63}
+                                                       in dBm units. */
+#define AR5K_PHY_RADAR_PRSSI_THR_S     6
+
+#define AR5K_PHY_RADAR_PHEIGHT_THR     0x0003f000      /* Pulse height threshold
+                                                       6-bits, dBm range {0..63}
+                                                       in dBm units. */
+#define AR5K_PHY_RADAR_PHEIGHT_THR_S   12
+
+#define AR5K_PHY_RADAR_RSSI_THR        0x00fc0000      /* Radar RSSI/SNR threshold.
+                                                       6-bits, dBm range {0..63}
+                                                       in dBm units. */
+#define AR5K_PHY_RADAR_RSSI_THR_S      18
+
+#define AR5K_PHY_RADAR_FIRPWR_THR      0x7f000000      /* Finite Impulse Response
+                                                       filter power out threshold.
+                                                       7-bits, standard power range
+                                                       {0..127} in 1/2 dBm units. */
+#define AR5K_PHY_RADAR_FIRPWR_THRS     24
+
+/*
+ * PHY antenna switch table registers
+ */
+#define AR5K_PHY_ANT_SWITCH_TABLE_0    0x9960
+#define AR5K_PHY_ANT_SWITCH_TABLE_1    0x9964
+
+/*
+ * PHY Noise floor threshold
+ */
+#define AR5K_PHY_NFTHRES               0x9968
+
+/*
+ * Sigma Delta register (?) [5213]
+ */
+#define AR5K_PHY_SIGMA_DELTA           0x996C
+#define AR5K_PHY_SIGMA_DELTA_ADC_SEL   0x00000003
+#define AR5K_PHY_SIGMA_DELTA_ADC_SEL_S 0
+#define AR5K_PHY_SIGMA_DELTA_FILT2     0x000000f8
+#define AR5K_PHY_SIGMA_DELTA_FILT2_S   3
+#define AR5K_PHY_SIGMA_DELTA_FILT1     0x00001f00
+#define AR5K_PHY_SIGMA_DELTA_FILT1_S   8
+#define AR5K_PHY_SIGMA_DELTA_ADC_CLIP  0x01ffe000
+#define AR5K_PHY_SIGMA_DELTA_ADC_CLIP_S        13
+
+/*
+ * RF restart register [5112+] (?)
+ */
+#define AR5K_PHY_RESTART               0x9970          /* restart */
+#define AR5K_PHY_RESTART_DIV_GC                0x001c0000      /* Fast diversity gc_limit (?) */
+#define AR5K_PHY_RESTART_DIV_GC_S      18
+
+/*
+ * RF Bus access request register (for synth-oly channel switching)
+ */
+#define AR5K_PHY_RFBUS_REQ             0x997C
+#define AR5K_PHY_RFBUS_REQ_REQUEST     0x00000001
+
+/*
+ * Spur mitigation masks (?)
+ */
+#define AR5K_PHY_TIMING_7              0x9980
+#define AR5K_PHY_TIMING_8              0x9984
+#define AR5K_PHY_TIMING_8_PILOT_MASK_2         0x000fffff
+#define AR5K_PHY_TIMING_8_PILOT_MASK_2_S       0
+
+#define AR5K_PHY_BIN_MASK2_1           0x9988
+#define AR5K_PHY_BIN_MASK2_2           0x998c
+#define AR5K_PHY_BIN_MASK2_3           0x9990
+
+#define AR5K_PHY_BIN_MASK2_4           0x9994
+#define AR5K_PHY_BIN_MASK2_4_MASK_4    0x00003fff
+#define AR5K_PHY_BIN_MASK2_4_MASK_4_S  0
+
+#define AR5K_PHY_TIMING_9                      0x9998
+#define AR5K_PHY_TIMING_10                     0x999c
+#define AR5K_PHY_TIMING_10_PILOT_MASK_2                0x000fffff
+#define AR5K_PHY_TIMING_10_PILOT_MASK_2_S      0
+
+/*
+ * Spur mitigation control
+ */
+#define AR5K_PHY_TIMING_11                     0x99a0          /* Register address */
+#define AR5K_PHY_TIMING_11_SPUR_DELTA_PHASE    0x000fffff      /* Spur delta phase */
+#define AR5K_PHY_TIMING_11_SPUR_DELTA_PHASE_S  0
+#define AR5K_PHY_TIMING_11_SPUR_FREQ_SD                0x3ff00000      /* Freq sigma delta */
+#define AR5K_PHY_TIMING_11_SPUR_FREQ_SD_S      20
+#define AR5K_PHY_TIMING_11_USE_SPUR_IN_AGC     0x40000000      /* Spur filter in AGC detector */
+#define AR5K_PHY_TIMING_11_USE_SPUR_IN_SELFCOR 0x80000000      /* Spur filter in OFDM self correlator */
+
+/*
+ * Gain tables
+ */
+#define        AR5K_BB_GAIN_BASE               0x9b00  /* BaseBand Amplifier Gain table base address */
+#define AR5K_BB_GAIN(_n)               (AR5K_BB_GAIN_BASE + ((_n) << 2))
+#define        AR5K_RF_GAIN_BASE               0x9a00  /* RF Amplrifier Gain table base address */
+#define AR5K_RF_GAIN(_n)               (AR5K_RF_GAIN_BASE + ((_n) << 2))
+
+/*
+ * PHY timing IQ calibration result register [5111+]
+ */
+#define        AR5K_PHY_IQRES_CAL_PWR_I        0x9c10  /* I (Inphase) power value */
+#define        AR5K_PHY_IQRES_CAL_PWR_Q        0x9c14  /* Q (Quadrature) power value */
+#define        AR5K_PHY_IQRES_CAL_CORR         0x9c18  /* I/Q Correlation */
+
+/*
+ * PHY current RSSI register [5111+]
+ */
+#define        AR5K_PHY_CURRENT_RSSI   0x9c1c
+
+/*
+ * PHY RF Bus grant register
+ */
+#define        AR5K_PHY_RFBUS_GRANT    0x9c20
+#define        AR5K_PHY_RFBUS_GRANT_OK 0x00000001
+
+/*
+ * PHY ADC test register
+ */
+#define        AR5K_PHY_ADC_TEST       0x9c24
+#define        AR5K_PHY_ADC_TEST_I     0x00000001
+#define        AR5K_PHY_ADC_TEST_Q     0x00000200
+
+/*
+ * PHY DAC test register
+ */
+#define        AR5K_PHY_DAC_TEST       0x9c28
+#define        AR5K_PHY_DAC_TEST_I     0x00000001
+#define        AR5K_PHY_DAC_TEST_Q     0x00000200
+
+/*
+ * PHY PTAT register (?)
+ */
+#define        AR5K_PHY_PTAT           0x9c2c
+
+/*
+ * PHY Illegal TX rate register [5112+]
+ */
+#define        AR5K_PHY_BAD_TX_RATE    0x9c30
+
+/*
+ * PHY SPUR Power register [5112+]
+ */
+#define        AR5K_PHY_SPUR_PWR       0x9c34                  /* Register Address */
+#define        AR5K_PHY_SPUR_PWR_I     0x00000001      /* SPUR Power estimate for I (field) */
+#define        AR5K_PHY_SPUR_PWR_Q     0x00000100      /* SPUR Power estimate for Q (field) */
+#define        AR5K_PHY_SPUR_PWR_FILT  0x00010000      /* Power with SPUR removed (field) */
+
+/*
+ * PHY Channel status register [5112+] (?)
+ */
+#define        AR5K_PHY_CHAN_STATUS            0x9c38
+#define        AR5K_PHY_CHAN_STATUS_BT_ACT     0x00000001
+#define        AR5K_PHY_CHAN_STATUS_RX_CLR_RAW 0x00000002
+#define        AR5K_PHY_CHAN_STATUS_RX_CLR_MAC 0x00000004
+#define        AR5K_PHY_CHAN_STATUS_RX_CLR_PAP 0x00000008
+
+/*
+ * Heavy clip enable register
+ */
+#define        AR5K_PHY_HEAVY_CLIP_ENABLE      0x99e0
+
+/*
+ * PHY clock sleep registers [5112+]
+ */
+#define AR5K_PHY_SCLOCK                        0x99f0
+#define AR5K_PHY_SCLOCK_32MHZ          0x0000000c
+#define AR5K_PHY_SDELAY                        0x99f4
+#define AR5K_PHY_SDELAY_32MHZ          0x000000ff
+#define AR5K_PHY_SPENDING              0x99f8
+
+
+/*
+ * PHY PAPD I (power?) table (?)
+ * (92! entries)
+ */
+#define        AR5K_PHY_PAPD_I_BASE    0xa000
+#define        AR5K_PHY_PAPD_I(_n)     (AR5K_PHY_PAPD_I_BASE + ((_n) << 2))
+
+/*
+ * PHY PCDAC TX power table
+ */
+#define        AR5K_PHY_PCDAC_TXPOWER_BASE     0xa180
+#define        AR5K_PHY_PCDAC_TXPOWER(_n)      (AR5K_PHY_PCDAC_TXPOWER_BASE + ((_n) << 2))
+
+/*
+ * PHY mode register [5111+]
+ */
+#define        AR5K_PHY_MODE                   0x0a200                 /* Register Address */
+#define        AR5K_PHY_MODE_MOD               0x00000001      /* PHY Modulation bit */
+#define AR5K_PHY_MODE_MOD_OFDM         0
+#define AR5K_PHY_MODE_MOD_CCK          1
+#define AR5K_PHY_MODE_FREQ             0x00000002      /* Freq mode bit */
+#define        AR5K_PHY_MODE_FREQ_5GHZ         0
+#define        AR5K_PHY_MODE_FREQ_2GHZ         2
+#define AR5K_PHY_MODE_MOD_DYN          0x00000004      /* Enable Dynamic OFDM/CCK mode [5112+] */
+#define AR5K_PHY_MODE_RAD              0x00000008      /* [5212+] */
+#define AR5K_PHY_MODE_RAD_RF5111       0
+#define AR5K_PHY_MODE_RAD_RF5112       8
+#define AR5K_PHY_MODE_XR               0x00000010      /* Enable XR mode [5112+] */
+#define        AR5K_PHY_MODE_HALF_RATE         0x00000020      /* Enable Half rate (test) */
+#define        AR5K_PHY_MODE_QUARTER_RATE      0x00000040      /* Enable Quarter rat (test) */
+
+/*
+ * PHY CCK transmit control register [5111+ (?)]
+ */
+#define AR5K_PHY_CCKTXCTL              0xa204
+#define AR5K_PHY_CCKTXCTL_WORLD                0x00000000
+#define AR5K_PHY_CCKTXCTL_JAPAN                0x00000010
+#define        AR5K_PHY_CCKTXCTL_SCRAMBLER_DIS 0x00000001
+#define        AR5K_PHY_CCKTXCTK_DAC_SCALE     0x00000004
+
+/*
+ * PHY CCK Cross-correlator Barker RSSI threshold register [5212+]
+ */
+#define AR5K_PHY_CCK_CROSSCORR                 0xa208
+#define AR5K_PHY_CCK_CROSSCORR_WEAK_SIG_THR    0x0000000f
+#define AR5K_PHY_CCK_CROSSCORR_WEAK_SIG_THR_S  0
+
+/* Same address is used for antenna diversity activation */
+#define        AR5K_PHY_FAST_ANT_DIV           0xa208
+#define        AR5K_PHY_FAST_ANT_DIV_EN        0x00002000
+
+/*
+ * PHY 2GHz gain register [5111+]
+ */
+#define        AR5K_PHY_GAIN_2GHZ                      0xa20c
+#define        AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX          0x00fc0000
+#define        AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX_S        18
+#define        AR5K_PHY_GAIN_2GHZ_INI_5111             0x6480416c
+
+#define        AR5K_PHY_CCK_RX_CTL_4                   0xa21c
+#define        AR5K_PHY_CCK_RX_CTL_4_FREQ_EST_SHORT    0x01f80000
+#define        AR5K_PHY_CCK_RX_CTL_4_FREQ_EST_SHORT_S  19
+
+#define        AR5K_PHY_DAG_CCK_CTL                    0xa228
+#define        AR5K_PHY_DAG_CCK_CTL_EN_RSSI_THR        0x00000200
+#define        AR5K_PHY_DAG_CCK_CTL_RSSI_THR           0x0001fc00
+#define        AR5K_PHY_DAG_CCK_CTL_RSSI_THR_S         10
+
+#define        AR5K_PHY_FAST_ADC       0xa24c
+
+#define        AR5K_PHY_BLUETOOTH      0xa254
+
+/*
+ * Transmit Power Control register
+ * [2413+]
+ */
+#define        AR5K_PHY_TPC_RG1                0xa258
+#define        AR5K_PHY_TPC_RG1_NUM_PD_GAIN    0x0000c000
+#define        AR5K_PHY_TPC_RG1_NUM_PD_GAIN_S  14
+#define AR5K_PHY_TPC_RG1_PDGAIN_1      0x00030000
+#define AR5K_PHY_TPC_RG1_PDGAIN_1_S    16
+#define AR5K_PHY_TPC_RG1_PDGAIN_2      0x000c0000
+#define AR5K_PHY_TPC_RG1_PDGAIN_2_S    18
+#define AR5K_PHY_TPC_RG1_PDGAIN_3      0x00300000
+#define AR5K_PHY_TPC_RG1_PDGAIN_3_S    20
+
+#define        AR5K_PHY_TPC_RG5                        0xa26C
+#define        AR5K_PHY_TPC_RG5_PD_GAIN_OVERLAP        0x0000000F
+#define        AR5K_PHY_TPC_RG5_PD_GAIN_OVERLAP_S      0
+#define        AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_1     0x000003F0
+#define        AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_1_S   4
+#define        AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_2     0x0000FC00
+#define        AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_2_S   10
+#define        AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_3     0x003F0000
+#define        AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_3_S   16
+#define        AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_4     0x0FC00000
+#define        AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_4_S   22
+
+/*
+ * PHY PDADC Tx power table
+ */
+#define AR5K_PHY_PDADC_TXPOWER_BASE    0xa280
+#define        AR5K_PHY_PDADC_TXPOWER(_n)      (AR5K_PHY_PDADC_TXPOWER_BASE + ((_n) << 2))
diff --git a/src/drivers/net/ath5k/rfbuffer.h b/src/drivers/net/ath5k/rfbuffer.h
new file mode 100644 (file)
index 0000000..e50baff
--- /dev/null
@@ -0,0 +1,1181 @@
+/*
+ * RF Buffer handling functions
+ *
+ * Copyright (c) 2009 Nick Kossifidis <mickflemm@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+
+/*
+ * There are some special registers on the RF chip
+ * that control various operation settings related mostly to
+ * the analog parts (channel, gain adjustment etc).
+ *
+ * We don't write on those registers directly but
+ * we send a data packet on the chip, using a special register,
+ * that holds all the settings we need. After we 've sent the
+ * data packet, we write on another special register to notify hw
+ * to apply the settings. This is done so that control registers
+ * can be dynamicaly programmed during operation and the settings
+ * are applied faster on the hw.
+ *
+ * We call each data packet an "RF Bank" and all the data we write
+ * (all RF Banks) "RF Buffer". This file holds initial RF Buffer
+ * data for the different RF chips, and various info to match RF
+ * Buffer offsets with specific RF registers so that we can access
+ * them. We tweak these settings on rfregs_init function.
+ *
+ * Also check out reg.h and U.S. Patent 6677779 B1 (about buffer
+ * registers and control registers):
+ *
+ * http://www.google.com/patents?id=qNURAAAAEBAJ
+ */
+
+
+/*
+ * Struct to hold default mode specific RF
+ * register values (RF Banks)
+ */
+struct ath5k_ini_rfbuffer {
+       u8      rfb_bank;               /* RF Bank number */
+       u16     rfb_ctrl_register;      /* RF Buffer control register */
+       u32     rfb_mode_data[5];       /* RF Buffer data for each mode */
+};
+
+/*
+ * Struct to hold RF Buffer field
+ * infos used to access certain RF
+ * analog registers
+ */
+struct ath5k_rfb_field {
+       u8      len;    /* Field length */
+       u16     pos;    /* Offset on the raw packet */
+       u8      col;    /* Column -used for shifting */
+};
+
+/*
+ * RF analog register definition
+ */
+struct ath5k_rf_reg {
+       u8                      bank;   /* RF Buffer Bank number */
+       u8                      index;  /* Register's index on rf_regs_idx */
+       struct ath5k_rfb_field  field;  /* RF Buffer field for this register */
+};
+
+/* Map RF registers to indexes
+ * We do this to handle common bits and make our
+ * life easier by using an index for each register
+ * instead of a full rfb_field */
+enum ath5k_rf_regs_idx {
+       /* BANK 6 */
+       AR5K_RF_OB_2GHZ = 0,
+       AR5K_RF_OB_5GHZ,
+       AR5K_RF_DB_2GHZ,
+       AR5K_RF_DB_5GHZ,
+       AR5K_RF_FIXED_BIAS_A,
+       AR5K_RF_FIXED_BIAS_B,
+       AR5K_RF_PWD_XPD,
+       AR5K_RF_XPD_SEL,
+       AR5K_RF_XPD_GAIN,
+       AR5K_RF_PD_GAIN_LO,
+       AR5K_RF_PD_GAIN_HI,
+       AR5K_RF_HIGH_VC_CP,
+       AR5K_RF_MID_VC_CP,
+       AR5K_RF_LOW_VC_CP,
+       AR5K_RF_PUSH_UP,
+       AR5K_RF_PAD2GND,
+       AR5K_RF_XB2_LVL,
+       AR5K_RF_XB5_LVL,
+       AR5K_RF_PWD_ICLOBUF_2G,
+       AR5K_RF_PWD_84,
+       AR5K_RF_PWD_90,
+       AR5K_RF_PWD_130,
+       AR5K_RF_PWD_131,
+       AR5K_RF_PWD_132,
+       AR5K_RF_PWD_136,
+       AR5K_RF_PWD_137,
+       AR5K_RF_PWD_138,
+       AR5K_RF_PWD_166,
+       AR5K_RF_PWD_167,
+       AR5K_RF_DERBY_CHAN_SEL_MODE,
+       /* BANK 7 */
+       AR5K_RF_GAIN_I,
+       AR5K_RF_PLO_SEL,
+       AR5K_RF_RFGAIN_SEL,
+       AR5K_RF_RFGAIN_STEP,
+       AR5K_RF_WAIT_S,
+       AR5K_RF_WAIT_I,
+       AR5K_RF_MAX_TIME,
+       AR5K_RF_MIXVGA_OVR,
+       AR5K_RF_MIXGAIN_OVR,
+       AR5K_RF_MIXGAIN_STEP,
+       AR5K_RF_PD_DELAY_A,
+       AR5K_RF_PD_DELAY_B,
+       AR5K_RF_PD_DELAY_XR,
+       AR5K_RF_PD_PERIOD_A,
+       AR5K_RF_PD_PERIOD_B,
+       AR5K_RF_PD_PERIOD_XR,
+};
+
+
+/*******************\
+* RF5111 (Sombrero) *
+\*******************/
+
+/* BANK 6                              len  pos col */
+#define        AR5K_RF5111_OB_2GHZ             { 3, 119, 0 }
+#define        AR5K_RF5111_DB_2GHZ             { 3, 122, 0 }
+
+#define        AR5K_RF5111_OB_5GHZ             { 3, 104, 0 }
+#define        AR5K_RF5111_DB_5GHZ             { 3, 107, 0 }
+
+#define        AR5K_RF5111_PWD_XPD             { 1, 95,  0 }
+#define        AR5K_RF5111_XPD_GAIN            { 4, 96,  0 }
+
+/* Access to PWD registers */
+#define AR5K_RF5111_PWD(_n)            { 1, (135 - _n), 3 }
+
+/* BANK 7                              len  pos col */
+#define        AR5K_RF5111_GAIN_I              { 6, 29,  0 }
+#define        AR5K_RF5111_PLO_SEL             { 1, 4,   0 }
+#define        AR5K_RF5111_RFGAIN_SEL          { 1, 36,  0 }
+#define AR5K_RF5111_RFGAIN_STEP                { 6, 37,  0 }
+/* Only on AR5212 BaseBand and up */
+#define        AR5K_RF5111_WAIT_S              { 5, 19,  0 }
+#define        AR5K_RF5111_WAIT_I              { 5, 24,  0 }
+#define        AR5K_RF5111_MAX_TIME            { 2, 49,  0 }
+
+static const struct ath5k_rf_reg rf_regs_5111[] = {
+       {6, AR5K_RF_OB_2GHZ,            AR5K_RF5111_OB_2GHZ},
+       {6, AR5K_RF_DB_2GHZ,            AR5K_RF5111_DB_2GHZ},
+       {6, AR5K_RF_OB_5GHZ,            AR5K_RF5111_OB_5GHZ},
+       {6, AR5K_RF_DB_5GHZ,            AR5K_RF5111_DB_5GHZ},
+       {6, AR5K_RF_PWD_XPD,            AR5K_RF5111_PWD_XPD},
+       {6, AR5K_RF_XPD_GAIN,           AR5K_RF5111_XPD_GAIN},
+       {6, AR5K_RF_PWD_84,             AR5K_RF5111_PWD(84)},
+       {6, AR5K_RF_PWD_90,             AR5K_RF5111_PWD(90)},
+       {7, AR5K_RF_GAIN_I,             AR5K_RF5111_GAIN_I},
+       {7, AR5K_RF_PLO_SEL,            AR5K_RF5111_PLO_SEL},
+       {7, AR5K_RF_RFGAIN_SEL,         AR5K_RF5111_RFGAIN_SEL},
+       {7, AR5K_RF_RFGAIN_STEP,        AR5K_RF5111_RFGAIN_STEP},
+       {7, AR5K_RF_WAIT_S,             AR5K_RF5111_WAIT_S},
+       {7, AR5K_RF_WAIT_I,             AR5K_RF5111_WAIT_I},
+       {7, AR5K_RF_MAX_TIME,           AR5K_RF5111_MAX_TIME}
+};
+
+/* Default mode specific settings */
+static const struct ath5k_ini_rfbuffer rfb_5111[] = {
+       { 0, 0x989c,
+       /*     mode a/XR  mode aTurbo    mode b     mode g    mode gTurbo */
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 0, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 0, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 0, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 0, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 0, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 0, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 0, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 0, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 0, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 0, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 0, 0x989c,
+           { 0x00380000, 0x00380000, 0x00380000, 0x00380000, 0x00380000 } },
+       { 0, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 0, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 0, 0x989c,
+           { 0x00000000, 0x00000000, 0x000000c0, 0x00000080, 0x00000080 } },
+       { 0, 0x989c,
+           { 0x000400f9, 0x000400f9, 0x000400ff, 0x000400fd, 0x000400fd } },
+       { 0, 0x98d4,
+           { 0x00000000, 0x00000000, 0x00000004, 0x00000004, 0x00000004 } },
+       { 1, 0x98d4,
+           { 0x00000020, 0x00000020, 0x00000020, 0x00000020, 0x00000020 } },
+       { 2, 0x98d4,
+           { 0x00000010, 0x00000014, 0x00000010, 0x00000010, 0x00000014 } },
+       { 3, 0x98d8,
+           { 0x00601068, 0x00601068, 0x00601068, 0x00601068, 0x00601068 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x10000000, 0x10000000, 0x10000000, 0x10000000, 0x10000000 } },
+       { 6, 0x989c,
+           { 0x04000000, 0x04000000, 0x04000000, 0x04000000, 0x04000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x0a000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x003800c0, 0x00380080, 0x023800c0, 0x003800c0, 0x003800c0 } },
+       { 6, 0x989c,
+           { 0x00020006, 0x00020006, 0x00000006, 0x00020006, 0x00020006 } },
+       { 6, 0x989c,
+           { 0x00000089, 0x00000089, 0x00000089, 0x00000089, 0x00000089 } },
+       { 6, 0x989c,
+           { 0x000000a0, 0x000000a0, 0x000000a0, 0x000000a0, 0x000000a0 } },
+       { 6, 0x989c,
+           { 0x00040007, 0x00040007, 0x00040007, 0x00040007, 0x00040007 } },
+       { 6, 0x98d4,
+           { 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a } },
+       { 7, 0x989c,
+           { 0x00000040, 0x00000048, 0x00000040, 0x00000040, 0x00000040 } },
+       { 7, 0x989c,
+           { 0x00000010, 0x00000010, 0x00000010, 0x00000010, 0x00000010 } },
+       { 7, 0x989c,
+           { 0x00000008, 0x00000008, 0x00000008, 0x00000008, 0x00000008 } },
+       { 7, 0x989c,
+           { 0x0000004f, 0x0000004f, 0x0000004f, 0x0000004f, 0x0000004f } },
+       { 7, 0x989c,
+           { 0x000000f1, 0x000000f1, 0x00000061, 0x000000f1, 0x000000f1 } },
+       { 7, 0x989c,
+           { 0x0000904f, 0x0000904f, 0x0000904c, 0x0000904f, 0x0000904f } },
+       { 7, 0x989c,
+           { 0x0000125a, 0x0000125a, 0x0000129a, 0x0000125a, 0x0000125a } },
+       { 7, 0x98cc,
+           { 0x0000000e, 0x0000000e, 0x0000000f, 0x0000000e, 0x0000000e } },
+};
+
+
+
+/***********************\
+* RF5112/RF2112 (Derby) *
+\***********************/
+
+/* BANK 7 (Common)                     len  pos col */
+#define        AR5K_RF5112X_GAIN_I             { 6, 14,  0 }
+#define        AR5K_RF5112X_MIXVGA_OVR         { 1, 36,  0 }
+#define        AR5K_RF5112X_MIXGAIN_OVR        { 2, 37,  0 }
+#define AR5K_RF5112X_MIXGAIN_STEP      { 4, 32,  0 }
+#define        AR5K_RF5112X_PD_DELAY_A         { 4, 58,  0 }
+#define        AR5K_RF5112X_PD_DELAY_B         { 4, 62,  0 }
+#define        AR5K_RF5112X_PD_DELAY_XR        { 4, 66,  0 }
+#define        AR5K_RF5112X_PD_PERIOD_A        { 4, 70,  0 }
+#define        AR5K_RF5112X_PD_PERIOD_B        { 4, 74,  0 }
+#define        AR5K_RF5112X_PD_PERIOD_XR       { 4, 78,  0 }
+
+/* RFX112 (Derby 1) */
+
+/* BANK 6                              len  pos col */
+#define        AR5K_RF5112_OB_2GHZ             { 3, 269, 0 }
+#define        AR5K_RF5112_DB_2GHZ             { 3, 272, 0 }
+
+#define        AR5K_RF5112_OB_5GHZ             { 3, 261, 0 }
+#define        AR5K_RF5112_DB_5GHZ             { 3, 264, 0 }
+
+#define        AR5K_RF5112_FIXED_BIAS_A        { 1, 260, 0 }
+#define        AR5K_RF5112_FIXED_BIAS_B        { 1, 259, 0 }
+
+#define        AR5K_RF5112_XPD_SEL             { 1, 284, 0 }
+#define        AR5K_RF5112_XPD_GAIN            { 2, 252, 0 }
+
+/* Access to PWD registers */
+#define AR5K_RF5112_PWD(_n)            { 1, (302 - _n), 3 }
+
+static const struct ath5k_rf_reg rf_regs_5112[] = {
+       {6, AR5K_RF_OB_2GHZ,            AR5K_RF5112_OB_2GHZ},
+       {6, AR5K_RF_DB_2GHZ,            AR5K_RF5112_DB_2GHZ},
+       {6, AR5K_RF_OB_5GHZ,            AR5K_RF5112_OB_5GHZ},
+       {6, AR5K_RF_DB_5GHZ,            AR5K_RF5112_DB_5GHZ},
+       {6, AR5K_RF_FIXED_BIAS_A,       AR5K_RF5112_FIXED_BIAS_A},
+       {6, AR5K_RF_FIXED_BIAS_B,       AR5K_RF5112_FIXED_BIAS_B},
+       {6, AR5K_RF_XPD_SEL,            AR5K_RF5112_XPD_SEL},
+       {6, AR5K_RF_XPD_GAIN,           AR5K_RF5112_XPD_GAIN},
+       {6, AR5K_RF_PWD_130,            AR5K_RF5112_PWD(130)},
+       {6, AR5K_RF_PWD_131,            AR5K_RF5112_PWD(131)},
+       {6, AR5K_RF_PWD_132,            AR5K_RF5112_PWD(132)},
+       {6, AR5K_RF_PWD_136,            AR5K_RF5112_PWD(136)},
+       {6, AR5K_RF_PWD_137,            AR5K_RF5112_PWD(137)},
+       {6, AR5K_RF_PWD_138,            AR5K_RF5112_PWD(138)},
+       {7, AR5K_RF_GAIN_I,             AR5K_RF5112X_GAIN_I},
+       {7, AR5K_RF_MIXVGA_OVR,         AR5K_RF5112X_MIXVGA_OVR},
+       {7, AR5K_RF_MIXGAIN_OVR,        AR5K_RF5112X_MIXGAIN_OVR},
+       {7, AR5K_RF_MIXGAIN_STEP,       AR5K_RF5112X_MIXGAIN_STEP},
+       {7, AR5K_RF_PD_DELAY_A,         AR5K_RF5112X_PD_DELAY_A},
+       {7, AR5K_RF_PD_DELAY_B,         AR5K_RF5112X_PD_DELAY_B},
+       {7, AR5K_RF_PD_DELAY_XR,        AR5K_RF5112X_PD_DELAY_XR},
+       {7, AR5K_RF_PD_PERIOD_A,        AR5K_RF5112X_PD_PERIOD_A},
+       {7, AR5K_RF_PD_PERIOD_B,        AR5K_RF5112X_PD_PERIOD_B},
+       {7, AR5K_RF_PD_PERIOD_XR,       AR5K_RF5112X_PD_PERIOD_XR},
+};
+
+/* Default mode specific settings */
+static const struct ath5k_ini_rfbuffer rfb_5112[] = {
+       { 1, 0x98d4,
+       /*     mode a/XR  mode aTurbo    mode b     mode g    mode gTurbo */
+           { 0x00000020, 0x00000020, 0x00000020, 0x00000020, 0x00000020 } },
+       { 2, 0x98d0,
+           { 0x03060408, 0x03070408, 0x03060408, 0x03060408, 0x03070408 } },
+       { 3, 0x98dc,
+           { 0x00a0c0c0, 0x00a0c0c0, 0x00e0c0c0, 0x00e0c0c0, 0x00e0c0c0 } },
+       { 6, 0x989c,
+           { 0x00a00000, 0x00a00000, 0x00a00000, 0x00a00000, 0x00a00000 } },
+       { 6, 0x989c,
+           { 0x000a0000, 0x000a0000, 0x000a0000, 0x000a0000, 0x000a0000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00660000, 0x00660000, 0x00660000, 0x00660000, 0x00660000 } },
+       { 6, 0x989c,
+           { 0x00db0000, 0x00db0000, 0x00db0000, 0x00db0000, 0x00db0000 } },
+       { 6, 0x989c,
+           { 0x00f10000, 0x00f10000, 0x00f10000, 0x00f10000, 0x00f10000 } },
+       { 6, 0x989c,
+           { 0x00120000, 0x00120000, 0x00120000, 0x00120000, 0x00120000 } },
+       { 6, 0x989c,
+           { 0x00120000, 0x00120000, 0x00120000, 0x00120000, 0x00120000 } },
+       { 6, 0x989c,
+           { 0x00730000, 0x00730000, 0x00730000, 0x00730000, 0x00730000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x000c0000, 0x000c0000, 0x000c0000, 0x000c0000, 0x000c0000 } },
+       { 6, 0x989c,
+           { 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
+       { 6, 0x989c,
+           { 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
+       { 6, 0x989c,
+           { 0x008b0000, 0x008b0000, 0x008b0000, 0x008b0000, 0x008b0000 } },
+       { 6, 0x989c,
+           { 0x00600000, 0x00600000, 0x00600000, 0x00600000, 0x00600000 } },
+       { 6, 0x989c,
+           { 0x000c0000, 0x000c0000, 0x000c0000, 0x000c0000, 0x000c0000 } },
+       { 6, 0x989c,
+           { 0x00840000, 0x00840000, 0x00840000, 0x00840000, 0x00840000 } },
+       { 6, 0x989c,
+           { 0x00640000, 0x00640000, 0x00640000, 0x00640000, 0x00640000 } },
+       { 6, 0x989c,
+           { 0x00200000, 0x00200000, 0x00200000, 0x00200000, 0x00200000 } },
+       { 6, 0x989c,
+           { 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000 } },
+       { 6, 0x989c,
+           { 0x00250000, 0x00250000, 0x00250000, 0x00250000, 0x00250000 } },
+       { 6, 0x989c,
+           { 0x00110000, 0x00110000, 0x00110000, 0x00110000, 0x00110000 } },
+       { 6, 0x989c,
+           { 0x00110000, 0x00110000, 0x00110000, 0x00110000, 0x00110000 } },
+       { 6, 0x989c,
+           { 0x00510000, 0x00510000, 0x00510000, 0x00510000, 0x00510000 } },
+       { 6, 0x989c,
+           { 0x1c040000, 0x1c040000, 0x1c040000, 0x1c040000, 0x1c040000 } },
+       { 6, 0x989c,
+           { 0x000a0000, 0x000a0000, 0x000a0000, 0x000a0000, 0x000a0000 } },
+       { 6, 0x989c,
+           { 0x00a10000, 0x00a10000, 0x00a10000, 0x00a10000, 0x00a10000 } },
+       { 6, 0x989c,
+           { 0x00400000, 0x00400000, 0x00400000, 0x00400000, 0x00400000 } },
+       { 6, 0x989c,
+           { 0x03090000, 0x03090000, 0x03090000, 0x03090000, 0x03090000 } },
+       { 6, 0x989c,
+           { 0x06000000, 0x06000000, 0x06000000, 0x06000000, 0x06000000 } },
+       { 6, 0x989c,
+           { 0x000000b0, 0x000000b0, 0x000000a8, 0x000000a8, 0x000000a8 } },
+       { 6, 0x989c,
+           { 0x0000002e, 0x0000002e, 0x0000002e, 0x0000002e, 0x0000002e } },
+       { 6, 0x989c,
+           { 0x006c4a41, 0x006c4a41, 0x006c4af1, 0x006c4a61, 0x006c4a61 } },
+       { 6, 0x989c,
+           { 0x0050892a, 0x0050892a, 0x0050892b, 0x0050892b, 0x0050892b } },
+       { 6, 0x989c,
+           { 0x00842400, 0x00842400, 0x00842400, 0x00842400, 0x00842400 } },
+       { 6, 0x989c,
+           { 0x00c69200, 0x00c69200, 0x00c69200, 0x00c69200, 0x00c69200 } },
+       { 6, 0x98d0,
+           { 0x0002000c, 0x0002000c, 0x0002000c, 0x0002000c, 0x0002000c } },
+       { 7, 0x989c,
+           { 0x00000094, 0x00000094, 0x00000094, 0x00000094, 0x00000094 } },
+       { 7, 0x989c,
+           { 0x00000091, 0x00000091, 0x00000091, 0x00000091, 0x00000091 } },
+       { 7, 0x989c,
+           { 0x0000000a, 0x0000000a, 0x00000012, 0x00000012, 0x00000012 } },
+       { 7, 0x989c,
+           { 0x00000080, 0x00000080, 0x00000080, 0x00000080, 0x00000080 } },
+       { 7, 0x989c,
+           { 0x000000c1, 0x000000c1, 0x000000c1, 0x000000c1, 0x000000c1 } },
+       { 7, 0x989c,
+           { 0x00000060, 0x00000060, 0x00000060, 0x00000060, 0x00000060 } },
+       { 7, 0x989c,
+           { 0x000000f0, 0x000000f0, 0x000000f0, 0x000000f0, 0x000000f0 } },
+       { 7, 0x989c,
+           { 0x00000022, 0x00000022, 0x00000022, 0x00000022, 0x00000022 } },
+       { 7, 0x989c,
+           { 0x00000092, 0x00000092, 0x00000092, 0x00000092, 0x00000092 } },
+       { 7, 0x989c,
+           { 0x000000d4, 0x000000d4, 0x000000d4, 0x000000d4, 0x000000d4 } },
+       { 7, 0x989c,
+           { 0x000014cc, 0x000014cc, 0x000014cc, 0x000014cc, 0x000014cc } },
+       { 7, 0x989c,
+           { 0x0000048c, 0x0000048c, 0x0000048c, 0x0000048c, 0x0000048c } },
+       { 7, 0x98c4,
+           { 0x00000003, 0x00000003, 0x00000003, 0x00000003, 0x00000003 } },
+};
+
+/* RFX112A (Derby 2) */
+
+/* BANK 6                              len  pos col */
+#define        AR5K_RF5112A_OB_2GHZ            { 3, 287, 0 }
+#define        AR5K_RF5112A_DB_2GHZ            { 3, 290, 0 }
+
+#define        AR5K_RF5112A_OB_5GHZ            { 3, 279, 0 }
+#define        AR5K_RF5112A_DB_5GHZ            { 3, 282, 0 }
+
+#define        AR5K_RF5112A_FIXED_BIAS_A       { 1, 278, 0 }
+#define        AR5K_RF5112A_FIXED_BIAS_B       { 1, 277, 0 }
+
+#define        AR5K_RF5112A_XPD_SEL            { 1, 302, 0 }
+#define        AR5K_RF5112A_PDGAINLO           { 2, 270, 0 }
+#define        AR5K_RF5112A_PDGAINHI           { 2, 257, 0 }
+
+/* Access to PWD registers */
+#define AR5K_RF5112A_PWD(_n)           { 1, (306 - _n), 3 }
+
+/* Voltage regulators */
+#define        AR5K_RF5112A_HIGH_VC_CP         { 2, 90,  2 }
+#define        AR5K_RF5112A_MID_VC_CP          { 2, 92,  2 }
+#define        AR5K_RF5112A_LOW_VC_CP          { 2, 94,  2 }
+#define        AR5K_RF5112A_PUSH_UP            { 1, 254,  2 }
+
+/* Power consumption */
+#define        AR5K_RF5112A_PAD2GND            { 1, 281, 1 }
+#define        AR5K_RF5112A_XB2_LVL            { 2, 1,   3 }
+#define        AR5K_RF5112A_XB5_LVL            { 2, 3,   3 }
+
+static const struct ath5k_rf_reg rf_regs_5112a[] = {
+       {6, AR5K_RF_OB_2GHZ,            AR5K_RF5112A_OB_2GHZ},
+       {6, AR5K_RF_DB_2GHZ,            AR5K_RF5112A_DB_2GHZ},
+       {6, AR5K_RF_OB_5GHZ,            AR5K_RF5112A_OB_5GHZ},
+       {6, AR5K_RF_DB_5GHZ,            AR5K_RF5112A_DB_5GHZ},
+       {6, AR5K_RF_FIXED_BIAS_A,       AR5K_RF5112A_FIXED_BIAS_A},
+       {6, AR5K_RF_FIXED_BIAS_B,       AR5K_RF5112A_FIXED_BIAS_B},
+       {6, AR5K_RF_XPD_SEL,            AR5K_RF5112A_XPD_SEL},
+       {6, AR5K_RF_PD_GAIN_LO,         AR5K_RF5112A_PDGAINLO},
+       {6, AR5K_RF_PD_GAIN_HI,         AR5K_RF5112A_PDGAINHI},
+       {6, AR5K_RF_PWD_130,            AR5K_RF5112A_PWD(130)},
+       {6, AR5K_RF_PWD_131,            AR5K_RF5112A_PWD(131)},
+       {6, AR5K_RF_PWD_132,            AR5K_RF5112A_PWD(132)},
+       {6, AR5K_RF_PWD_136,            AR5K_RF5112A_PWD(136)},
+       {6, AR5K_RF_PWD_137,            AR5K_RF5112A_PWD(137)},
+       {6, AR5K_RF_PWD_138,            AR5K_RF5112A_PWD(138)},
+       {6, AR5K_RF_PWD_166,            AR5K_RF5112A_PWD(166)},
+       {6, AR5K_RF_PWD_167,            AR5K_RF5112A_PWD(167)},
+       {6, AR5K_RF_HIGH_VC_CP,         AR5K_RF5112A_HIGH_VC_CP},
+       {6, AR5K_RF_MID_VC_CP,          AR5K_RF5112A_MID_VC_CP},
+       {6, AR5K_RF_LOW_VC_CP,          AR5K_RF5112A_LOW_VC_CP},
+       {6, AR5K_RF_PUSH_UP,            AR5K_RF5112A_PUSH_UP},
+       {6, AR5K_RF_PAD2GND,            AR5K_RF5112A_PAD2GND},
+       {6, AR5K_RF_XB2_LVL,            AR5K_RF5112A_XB2_LVL},
+       {6, AR5K_RF_XB5_LVL,            AR5K_RF5112A_XB5_LVL},
+       {7, AR5K_RF_GAIN_I,             AR5K_RF5112X_GAIN_I},
+       {7, AR5K_RF_MIXVGA_OVR,         AR5K_RF5112X_MIXVGA_OVR},
+       {7, AR5K_RF_MIXGAIN_OVR,        AR5K_RF5112X_MIXGAIN_OVR},
+       {7, AR5K_RF_MIXGAIN_STEP,       AR5K_RF5112X_MIXGAIN_STEP},
+       {7, AR5K_RF_PD_DELAY_A,         AR5K_RF5112X_PD_DELAY_A},
+       {7, AR5K_RF_PD_DELAY_B,         AR5K_RF5112X_PD_DELAY_B},
+       {7, AR5K_RF_PD_DELAY_XR,        AR5K_RF5112X_PD_DELAY_XR},
+       {7, AR5K_RF_PD_PERIOD_A,        AR5K_RF5112X_PD_PERIOD_A},
+       {7, AR5K_RF_PD_PERIOD_B,        AR5K_RF5112X_PD_PERIOD_B},
+       {7, AR5K_RF_PD_PERIOD_XR,       AR5K_RF5112X_PD_PERIOD_XR},
+};
+
+/* Default mode specific settings */
+static const struct ath5k_ini_rfbuffer rfb_5112a[] = {
+       { 1, 0x98d4,
+       /*     mode a/XR  mode aTurbo    mode b     mode g    mode gTurbo */
+           { 0x00000020, 0x00000020, 0x00000020, 0x00000020, 0x00000020 } },
+       { 2, 0x98d0,
+           { 0x03060408, 0x03070408, 0x03060408, 0x03060408, 0x03070408 } },
+       { 3, 0x98dc,
+           { 0x00a020c0, 0x00a020c0, 0x00e020c0, 0x00e020c0, 0x00e020c0 } },
+       { 6, 0x989c,
+           { 0x0f000000, 0x0f000000, 0x0f000000, 0x0f000000, 0x0f000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00800000, 0x00800000, 0x00800000, 0x00800000, 0x00800000 } },
+       { 6, 0x989c,
+           { 0x002a0000, 0x002a0000, 0x002a0000, 0x002a0000, 0x002a0000 } },
+       { 6, 0x989c,
+           { 0x00010000, 0x00010000, 0x00010000, 0x00010000, 0x00010000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00180000, 0x00180000, 0x00180000, 0x00180000, 0x00180000 } },
+       { 6, 0x989c,
+           { 0x00600000, 0x00600000, 0x006e0000, 0x006e0000, 0x006e0000 } },
+       { 6, 0x989c,
+           { 0x00c70000, 0x00c70000, 0x00c70000, 0x00c70000, 0x00c70000 } },
+       { 6, 0x989c,
+           { 0x004b0000, 0x004b0000, 0x004b0000, 0x004b0000, 0x004b0000 } },
+       { 6, 0x989c,
+           { 0x04480000, 0x04480000, 0x04480000, 0x04480000, 0x04480000 } },
+       { 6, 0x989c,
+           { 0x004c0000, 0x004c0000, 0x004c0000, 0x004c0000, 0x004c0000 } },
+       { 6, 0x989c,
+           { 0x00e40000, 0x00e40000, 0x00e40000, 0x00e40000, 0x00e40000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00fc0000, 0x00fc0000, 0x00fc0000, 0x00fc0000, 0x00fc0000 } },
+       { 6, 0x989c,
+           { 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
+       { 6, 0x989c,
+           { 0x043f0000, 0x043f0000, 0x043f0000, 0x043f0000, 0x043f0000 } },
+       { 6, 0x989c,
+           { 0x000c0000, 0x000c0000, 0x000c0000, 0x000c0000, 0x000c0000 } },
+       { 6, 0x989c,
+           { 0x02190000, 0x02190000, 0x02190000, 0x02190000, 0x02190000 } },
+       { 6, 0x989c,
+           { 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000 } },
+       { 6, 0x989c,
+           { 0x00b40000, 0x00b40000, 0x00b40000, 0x00b40000, 0x00b40000 } },
+       { 6, 0x989c,
+           { 0x00990000, 0x00990000, 0x00990000, 0x00990000, 0x00990000 } },
+       { 6, 0x989c,
+           { 0x00500000, 0x00500000, 0x00500000, 0x00500000, 0x00500000 } },
+       { 6, 0x989c,
+           { 0x002a0000, 0x002a0000, 0x002a0000, 0x002a0000, 0x002a0000 } },
+       { 6, 0x989c,
+           { 0x00120000, 0x00120000, 0x00120000, 0x00120000, 0x00120000 } },
+       { 6, 0x989c,
+           { 0xc0320000, 0xc0320000, 0xc0320000, 0xc0320000, 0xc0320000 } },
+       { 6, 0x989c,
+           { 0x01740000, 0x01740000, 0x01740000, 0x01740000, 0x01740000 } },
+       { 6, 0x989c,
+           { 0x00110000, 0x00110000, 0x00110000, 0x00110000, 0x00110000 } },
+       { 6, 0x989c,
+           { 0x86280000, 0x86280000, 0x86280000, 0x86280000, 0x86280000 } },
+       { 6, 0x989c,
+           { 0x31840000, 0x31840000, 0x31840000, 0x31840000, 0x31840000 } },
+       { 6, 0x989c,
+           { 0x00f20080, 0x00f20080, 0x00f20080, 0x00f20080, 0x00f20080 } },
+       { 6, 0x989c,
+           { 0x00270019, 0x00270019, 0x00270019, 0x00270019, 0x00270019 } },
+       { 6, 0x989c,
+           { 0x00000003, 0x00000003, 0x00000003, 0x00000003, 0x00000003 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x000000b2, 0x000000b2, 0x000000b2, 0x000000b2, 0x000000b2 } },
+       { 6, 0x989c,
+           { 0x00b02084, 0x00b02084, 0x00b02084, 0x00b02084, 0x00b02084 } },
+       { 6, 0x989c,
+           { 0x004125a4, 0x004125a4, 0x004125a4, 0x004125a4, 0x004125a4 } },
+       { 6, 0x989c,
+           { 0x00119220, 0x00119220, 0x00119220, 0x00119220, 0x00119220 } },
+       { 6, 0x989c,
+           { 0x001a4800, 0x001a4800, 0x001a4800, 0x001a4800, 0x001a4800 } },
+       { 6, 0x98d8,
+           { 0x000b0230, 0x000b0230, 0x000b0230, 0x000b0230, 0x000b0230 } },
+       { 7, 0x989c,
+           { 0x00000094, 0x00000094, 0x00000094, 0x00000094, 0x00000094 } },
+       { 7, 0x989c,
+           { 0x00000091, 0x00000091, 0x00000091, 0x00000091, 0x00000091 } },
+       { 7, 0x989c,
+           { 0x00000012, 0x00000012, 0x00000012, 0x00000012, 0x00000012 } },
+       { 7, 0x989c,
+           { 0x00000080, 0x00000080, 0x00000080, 0x00000080, 0x00000080 } },
+       { 7, 0x989c,
+           { 0x000000d9, 0x000000d9, 0x000000d9, 0x000000d9, 0x000000d9 } },
+       { 7, 0x989c,
+           { 0x00000060, 0x00000060, 0x00000060, 0x00000060, 0x00000060 } },
+       { 7, 0x989c,
+           { 0x000000f0, 0x000000f0, 0x000000f0, 0x000000f0, 0x000000f0 } },
+       { 7, 0x989c,
+           { 0x000000a2, 0x000000a2, 0x000000a2, 0x000000a2, 0x000000a2 } },
+       { 7, 0x989c,
+           { 0x00000052, 0x00000052, 0x00000052, 0x00000052, 0x00000052 } },
+       { 7, 0x989c,
+           { 0x000000d4, 0x000000d4, 0x000000d4, 0x000000d4, 0x000000d4 } },
+       { 7, 0x989c,
+           { 0x000014cc, 0x000014cc, 0x000014cc, 0x000014cc, 0x000014cc } },
+       { 7, 0x989c,
+           { 0x0000048c, 0x0000048c, 0x0000048c, 0x0000048c, 0x0000048c } },
+       { 7, 0x98c4,
+           { 0x00000003, 0x00000003, 0x00000003, 0x00000003, 0x00000003 } },
+};
+
+
+
+/******************\
+* RF2413 (Griffin) *
+\******************/
+
+/* BANK 6                              len  pos col */
+#define        AR5K_RF2413_OB_2GHZ             { 3, 168, 0 }
+#define        AR5K_RF2413_DB_2GHZ             { 3, 165, 0 }
+
+static const struct ath5k_rf_reg rf_regs_2413[] = {
+       {6, AR5K_RF_OB_2GHZ,            AR5K_RF2413_OB_2GHZ},
+       {6, AR5K_RF_DB_2GHZ,            AR5K_RF2413_DB_2GHZ},
+};
+
+/* Default mode specific settings
+ * XXX: a/aTurbo ???
+ */
+static const struct ath5k_ini_rfbuffer rfb_2413[] = {
+       { 1, 0x98d4,
+       /*     mode a/XR  mode aTurbo    mode b     mode g    mode gTurbo */
+           { 0x00000020, 0x00000020, 0x00000020, 0x00000020, 0x00000020 } },
+       { 2, 0x98d0,
+           { 0x02001408, 0x02011408, 0x02001408, 0x02001408, 0x02011408 } },
+       { 3, 0x98dc,
+           { 0x00a020c0, 0x00a020c0, 0x00e020c0, 0x00e020c0, 0x00e020c0 } },
+       { 6, 0x989c,
+           { 0xf0000000, 0xf0000000, 0xf0000000, 0xf0000000, 0xf0000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x03000000, 0x03000000, 0x03000000, 0x03000000, 0x03000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x40400000, 0x40400000, 0x40400000, 0x40400000, 0x40400000 } },
+       { 6, 0x989c,
+           { 0x65050000, 0x65050000, 0x65050000, 0x65050000, 0x65050000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00420000, 0x00420000, 0x00420000, 0x00420000, 0x00420000 } },
+       { 6, 0x989c,
+           { 0x00b50000, 0x00b50000, 0x00b50000, 0x00b50000, 0x00b50000 } },
+       { 6, 0x989c,
+           { 0x00030000, 0x00030000, 0x00030000, 0x00030000, 0x00030000 } },
+       { 6, 0x989c,
+           { 0x00f70000, 0x00f70000, 0x00f70000, 0x00f70000, 0x00f70000 } },
+       { 6, 0x989c,
+           { 0x009d0000, 0x009d0000, 0x009d0000, 0x009d0000, 0x009d0000 } },
+       { 6, 0x989c,
+           { 0x00220000, 0x00220000, 0x00220000, 0x00220000, 0x00220000 } },
+       { 6, 0x989c,
+           { 0x04220000, 0x04220000, 0x04220000, 0x04220000, 0x04220000 } },
+       { 6, 0x989c,
+           { 0x00230018, 0x00230018, 0x00230018, 0x00230018, 0x00230018 } },
+       { 6, 0x989c,
+           { 0x00280000, 0x00280000, 0x00280060, 0x00280060, 0x00280060 } },
+       { 6, 0x989c,
+           { 0x005000c0, 0x005000c0, 0x005000c3, 0x005000c3, 0x005000c3 } },
+       { 6, 0x989c,
+           { 0x0004007f, 0x0004007f, 0x0004007f, 0x0004007f, 0x0004007f } },
+       { 6, 0x989c,
+           { 0x00000458, 0x00000458, 0x00000458, 0x00000458, 0x00000458 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x0000c000, 0x0000c000, 0x0000c000, 0x0000c000, 0x0000c000 } },
+       { 6, 0x98d8,
+           { 0x00400230, 0x00400230, 0x00400230, 0x00400230, 0x00400230 } },
+       { 7, 0x989c,
+           { 0x00006400, 0x00006400, 0x00006400, 0x00006400, 0x00006400 } },
+       { 7, 0x989c,
+           { 0x00000800, 0x00000800, 0x00000800, 0x00000800, 0x00000800 } },
+       { 7, 0x98cc,
+           { 0x0000000e, 0x0000000e, 0x0000000e, 0x0000000e, 0x0000000e } },
+};
+
+
+
+/***************************\
+* RF2315/RF2316 (Cobra SoC) *
+\***************************/
+
+/* BANK 6                              len  pos col */
+#define        AR5K_RF2316_OB_2GHZ             { 3, 178, 0 }
+#define        AR5K_RF2316_DB_2GHZ             { 3, 175, 0 }
+
+static const struct ath5k_rf_reg rf_regs_2316[] = {
+       {6, AR5K_RF_OB_2GHZ,            AR5K_RF2316_OB_2GHZ},
+       {6, AR5K_RF_DB_2GHZ,            AR5K_RF2316_DB_2GHZ},
+};
+
+/* Default mode specific settings */
+static const struct ath5k_ini_rfbuffer rfb_2316[] = {
+       { 1, 0x98d4,
+       /*     mode a/XR  mode aTurbo    mode b     mode g    mode gTurbo */
+           { 0x00000020, 0x00000020, 0x00000020, 0x00000020, 0x00000020 } },
+       { 2, 0x98d0,
+           { 0x02001408, 0x02011408, 0x02001408, 0x02001408, 0x02011408 } },
+       { 3, 0x98dc,
+           { 0x00a020c0, 0x00a020c0, 0x00e020c0, 0x00e020c0, 0x00e020c0 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0xc0000000, 0xc0000000, 0xc0000000, 0xc0000000, 0xc0000000 } },
+       { 6, 0x989c,
+           { 0x0f000000, 0x0f000000, 0x0f000000, 0x0f000000, 0x0f000000 } },
+       { 6, 0x989c,
+           { 0x02000000, 0x02000000, 0x02000000, 0x02000000, 0x02000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0xf8000000, 0xf8000000, 0xf8000000, 0xf8000000, 0xf8000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x95150000, 0x95150000, 0x95150000, 0x95150000, 0x95150000 } },
+       { 6, 0x989c,
+           { 0xc1000000, 0xc1000000, 0xc1000000, 0xc1000000, 0xc1000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000 } },
+       { 6, 0x989c,
+           { 0x00d50000, 0x00d50000, 0x00d50000, 0x00d50000, 0x00d50000 } },
+       { 6, 0x989c,
+           { 0x000e0000, 0x000e0000, 0x000e0000, 0x000e0000, 0x000e0000 } },
+       { 6, 0x989c,
+           { 0x00dc0000, 0x00dc0000, 0x00dc0000, 0x00dc0000, 0x00dc0000 } },
+       { 6, 0x989c,
+           { 0x00770000, 0x00770000, 0x00770000, 0x00770000, 0x00770000 } },
+       { 6, 0x989c,
+           { 0x008a0000, 0x008a0000, 0x008a0000, 0x008a0000, 0x008a0000 } },
+       { 6, 0x989c,
+           { 0x10880000, 0x10880000, 0x10880000, 0x10880000, 0x10880000 } },
+       { 6, 0x989c,
+           { 0x008c0060, 0x008c0060, 0x008c0060, 0x008c0060, 0x008c0060 } },
+       { 6, 0x989c,
+           { 0x00a00000, 0x00a00000, 0x00a00080, 0x00a00080, 0x00a00080 } },
+       { 6, 0x989c,
+           { 0x00400000, 0x00400000, 0x0040000d, 0x0040000d, 0x0040000d } },
+       { 6, 0x989c,
+           { 0x00110400, 0x00110400, 0x00110400, 0x00110400, 0x00110400 } },
+       { 6, 0x989c,
+           { 0x00000060, 0x00000060, 0x00000060, 0x00000060, 0x00000060 } },
+       { 6, 0x989c,
+           { 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001 } },
+       { 6, 0x989c,
+           { 0x00000b00, 0x00000b00, 0x00000b00, 0x00000b00, 0x00000b00 } },
+       { 6, 0x989c,
+           { 0x00000be8, 0x00000be8, 0x00000be8, 0x00000be8, 0x00000be8 } },
+       { 6, 0x98c0,
+           { 0x00010000, 0x00010000, 0x00010000, 0x00010000, 0x00010000 } },
+       { 7, 0x989c,
+           { 0x00006400, 0x00006400, 0x00006400, 0x00006400, 0x00006400 } },
+       { 7, 0x989c,
+           { 0x00000800, 0x00000800, 0x00000800, 0x00000800, 0x00000800 } },
+       { 7, 0x98cc,
+           { 0x0000000e, 0x0000000e, 0x0000000e, 0x0000000e, 0x0000000e } },
+};
+
+
+
+/******************************\
+* RF5413/RF5424 (Eagle/Condor) *
+\******************************/
+
+/* BANK 6                              len  pos col */
+#define        AR5K_RF5413_OB_2GHZ             { 3, 241, 0 }
+#define        AR5K_RF5413_DB_2GHZ             { 3, 238, 0 }
+
+#define        AR5K_RF5413_OB_5GHZ             { 3, 247, 0 }
+#define        AR5K_RF5413_DB_5GHZ             { 3, 244, 0 }
+
+#define        AR5K_RF5413_PWD_ICLOBUF2G       { 3, 131, 3 }
+#define        AR5K_RF5413_DERBY_CHAN_SEL_MODE { 1, 291, 2 }
+
+static const struct ath5k_rf_reg rf_regs_5413[] = {
+       {6, AR5K_RF_OB_2GHZ,             AR5K_RF5413_OB_2GHZ},
+       {6, AR5K_RF_DB_2GHZ,             AR5K_RF5413_DB_2GHZ},
+       {6, AR5K_RF_OB_5GHZ,             AR5K_RF5413_OB_5GHZ},
+       {6, AR5K_RF_DB_5GHZ,             AR5K_RF5413_DB_5GHZ},
+       {6, AR5K_RF_PWD_ICLOBUF_2G,      AR5K_RF5413_PWD_ICLOBUF2G},
+       {6, AR5K_RF_DERBY_CHAN_SEL_MODE, AR5K_RF5413_DERBY_CHAN_SEL_MODE},
+};
+
+/* Default mode specific settings */
+static const struct ath5k_ini_rfbuffer rfb_5413[] = {
+       { 1, 0x98d4,
+       /*     mode a/XR  mode aTurbo    mode b     mode g    mode gTurbo */
+           { 0x00000020, 0x00000020, 0x00000020, 0x00000020, 0x00000020 } },
+       { 2, 0x98d0,
+           { 0x00000008, 0x00000008, 0x00000008, 0x00000008, 0x00000008 } },
+       { 3, 0x98dc,
+           { 0x00a000c0, 0x00a000c0, 0x00e000c0, 0x00e000c0, 0x00e000c0 } },
+       { 6, 0x989c,
+           { 0x33000000, 0x33000000, 0x33000000, 0x33000000, 0x33000000 } },
+       { 6, 0x989c,
+           { 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x1f000000, 0x1f000000, 0x1f000000, 0x1f000000, 0x1f000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00b80000, 0x00b80000, 0x00b80000, 0x00b80000, 0x00b80000 } },
+       { 6, 0x989c,
+           { 0x00b70000, 0x00b70000, 0x00b70000, 0x00b70000, 0x00b70000 } },
+       { 6, 0x989c,
+           { 0x00840000, 0x00840000, 0x00840000, 0x00840000, 0x00840000 } },
+       { 6, 0x989c,
+           { 0x00980000, 0x00980000, 0x00980000, 0x00980000, 0x00980000 } },
+       { 6, 0x989c,
+           { 0x00c00000, 0x00c00000, 0x00c00000, 0x00c00000, 0x00c00000 } },
+       { 6, 0x989c,
+           { 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
+       { 6, 0x989c,
+           { 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
+       { 6, 0x989c,
+           { 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
+       { 6, 0x989c,
+           { 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
+       { 6, 0x989c,
+           { 0x00d70000, 0x00d70000, 0x00d70000, 0x00d70000, 0x00d70000 } },
+       { 6, 0x989c,
+           { 0x00610000, 0x00610000, 0x00610000, 0x00610000, 0x00610000 } },
+       { 6, 0x989c,
+           { 0x00fe0000, 0x00fe0000, 0x00fe0000, 0x00fe0000, 0x00fe0000 } },
+       { 6, 0x989c,
+           { 0x00de0000, 0x00de0000, 0x00de0000, 0x00de0000, 0x00de0000 } },
+       { 6, 0x989c,
+           { 0x007f0000, 0x007f0000, 0x007f0000, 0x007f0000, 0x007f0000 } },
+       { 6, 0x989c,
+           { 0x043d0000, 0x043d0000, 0x043d0000, 0x043d0000, 0x043d0000 } },
+       { 6, 0x989c,
+           { 0x00770000, 0x00770000, 0x00770000, 0x00770000, 0x00770000 } },
+       { 6, 0x989c,
+           { 0x00440000, 0x00440000, 0x00440000, 0x00440000, 0x00440000 } },
+       { 6, 0x989c,
+           { 0x00980000, 0x00980000, 0x00980000, 0x00980000, 0x00980000 } },
+       { 6, 0x989c,
+           { 0x00100080, 0x00100080, 0x00100080, 0x00100080, 0x00100080 } },
+       { 6, 0x989c,
+           { 0x0005c034, 0x0005c034, 0x0005c034, 0x0005c034, 0x0005c034 } },
+       { 6, 0x989c,
+           { 0x003100f0, 0x003100f0, 0x003100f0, 0x003100f0, 0x003100f0 } },
+       { 6, 0x989c,
+           { 0x000c011f, 0x000c011f, 0x000c011f, 0x000c011f, 0x000c011f } },
+       { 6, 0x989c,
+           { 0x00510040, 0x00510040, 0x00510040, 0x00510040, 0x00510040 } },
+       { 6, 0x989c,
+           { 0x005000da, 0x005000da, 0x005000da, 0x005000da, 0x005000da } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00004044, 0x00004044, 0x00004044, 0x00004044, 0x00004044 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x000060c0, 0x000060c0, 0x000060c0, 0x000060c0, 0x000060c0 } },
+       { 6, 0x989c,
+           { 0x00002c00, 0x00002c00, 0x00003600, 0x00003600, 0x00002c00 } },
+       { 6, 0x98c8,
+           { 0x00000403, 0x00000403, 0x00040403, 0x00040403, 0x00040403 } },
+       { 7, 0x989c,
+           { 0x00006400, 0x00006400, 0x00006400, 0x00006400, 0x00006400 } },
+       { 7, 0x989c,
+           { 0x00000800, 0x00000800, 0x00000800, 0x00000800, 0x00000800 } },
+       { 7, 0x98cc,
+           { 0x0000000e, 0x0000000e, 0x0000000e, 0x0000000e, 0x0000000e } },
+};
+
+
+
+/***************************\
+* RF2425/RF2417 (Swan/Nala) *
+* AR2317 (Spider SoC)       *
+\***************************/
+
+/* BANK 6                              len  pos col */
+#define        AR5K_RF2425_OB_2GHZ             { 3, 193, 0 }
+#define        AR5K_RF2425_DB_2GHZ             { 3, 190, 0 }
+
+static const struct ath5k_rf_reg rf_regs_2425[] = {
+       {6, AR5K_RF_OB_2GHZ,            AR5K_RF2425_OB_2GHZ},
+       {6, AR5K_RF_DB_2GHZ,            AR5K_RF2425_DB_2GHZ},
+};
+
+/* Default mode specific settings
+ * XXX: a/aTurbo ?
+ */
+static const struct ath5k_ini_rfbuffer rfb_2425[] = {
+       { 1, 0x98d4,
+       /*     mode a/XR  mode aTurbo    mode b     mode g    mode gTurbo */
+           { 0x00000020, 0x00000020, 0x00000020, 0x00000020, 0x00000020 } },
+       { 2, 0x98d0,
+           { 0x02001408, 0x02001408, 0x02001408, 0x02001408, 0x02001408 } },
+       { 3, 0x98dc,
+           { 0x00a020c0, 0x00a020c0, 0x00e020c0, 0x00e020c0, 0x00e020c0 } },
+       { 6, 0x989c,
+           { 0x10000000, 0x10000000, 0x10000000, 0x10000000, 0x10000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x002a0000, 0x002a0000, 0x002a0000, 0x002a0000, 0x002a0000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00100000, 0x00100000, 0x00100000, 0x00100000, 0x00100000 } },
+       { 6, 0x989c,
+           { 0x00020000, 0x00020000, 0x00020000, 0x00020000, 0x00020000 } },
+       { 6, 0x989c,
+           { 0x00730000, 0x00730000, 0x00730000, 0x00730000, 0x00730000 } },
+       { 6, 0x989c,
+           { 0x00f80000, 0x00f80000, 0x00f80000, 0x00f80000, 0x00f80000 } },
+       { 6, 0x989c,
+           { 0x00e70000, 0x00e70000, 0x00e70000, 0x00e70000, 0x00e70000 } },
+       { 6, 0x989c,
+           { 0x00140000, 0x00140000, 0x00140000, 0x00140000, 0x00140000 } },
+       { 6, 0x989c,
+           { 0x00910040, 0x00910040, 0x00910040, 0x00910040, 0x00910040 } },
+       { 6, 0x989c,
+           { 0x0007001a, 0x0007001a, 0x0007001a, 0x0007001a, 0x0007001a } },
+       { 6, 0x989c,
+           { 0x00410000, 0x00410000, 0x00410000, 0x00410000, 0x00410000 } },
+       { 6, 0x989c,
+           { 0x00810000, 0x00810000, 0x00810060, 0x00810060, 0x00810060 } },
+       { 6, 0x989c,
+           { 0x00020800, 0x00020800, 0x00020803, 0x00020803, 0x00020803 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00001660, 0x00001660, 0x00001660, 0x00001660, 0x00001660 } },
+       { 6, 0x989c,
+           { 0x00001688, 0x00001688, 0x00001688, 0x00001688, 0x00001688 } },
+       { 6, 0x98c4,
+           { 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001 } },
+       { 7, 0x989c,
+           { 0x00006400, 0x00006400, 0x00006400, 0x00006400, 0x00006400 } },
+       { 7, 0x989c,
+           { 0x00000800, 0x00000800, 0x00000800, 0x00000800, 0x00000800 } },
+       { 7, 0x98cc,
+           { 0x0000000e, 0x0000000e, 0x0000000e, 0x0000000e, 0x0000000e } },
+};
+
+/*
+ * TODO: Handle the few differences with swan during
+ * bank modification and get rid of this
+ */
+static const struct ath5k_ini_rfbuffer rfb_2317[] = {
+       { 1, 0x98d4,
+       /*     mode a/XR  mode aTurbo    mode b     mode g    mode gTurbo */
+           { 0x00000020, 0x00000020, 0x00000020, 0x00000020, 0x00000020 } },
+       { 2, 0x98d0,
+           { 0x02001408, 0x02011408, 0x02001408, 0x02001408, 0x02011408 } },
+       { 3, 0x98dc,
+           { 0x00a020c0, 0x00a020c0, 0x00e020c0, 0x00e020c0, 0x00e020c0 } },
+       { 6, 0x989c,
+           { 0x10000000, 0x10000000, 0x10000000, 0x10000000, 0x10000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x002a0000, 0x002a0000, 0x002a0000, 0x002a0000, 0x002a0000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00100000, 0x00100000, 0x00100000, 0x00100000, 0x00100000 } },
+       { 6, 0x989c,
+           { 0x00020000, 0x00020000, 0x00020000, 0x00020000, 0x00020000 } },
+       { 6, 0x989c,
+           { 0x00730000, 0x00730000, 0x00730000, 0x00730000, 0x00730000 } },
+       { 6, 0x989c,
+           { 0x00f80000, 0x00f80000, 0x00f80000, 0x00f80000, 0x00f80000 } },
+       { 6, 0x989c,
+           { 0x00e70000, 0x00e70000, 0x00e70000, 0x00e70000, 0x00e70000 } },
+       { 6, 0x989c,
+           { 0x00140100, 0x00140100, 0x00140100, 0x00140100, 0x00140100 } },
+       { 6, 0x989c,
+           { 0x00910040, 0x00910040, 0x00910040, 0x00910040, 0x00910040 } },
+       { 6, 0x989c,
+           { 0x0007001a, 0x0007001a, 0x0007001a, 0x0007001a, 0x0007001a } },
+       { 6, 0x989c,
+           { 0x00410000, 0x00410000, 0x00410000, 0x00410000, 0x00410000 } },
+       { 6, 0x989c,
+           { 0x00810000, 0x00810000, 0x00810060, 0x00810060, 0x00810060 } },
+       { 6, 0x989c,
+           { 0x00020800, 0x00020800, 0x00020803, 0x00020803, 0x00020803 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00001660, 0x00001660, 0x00001660, 0x00001660, 0x00001660 } },
+       { 6, 0x989c,
+           { 0x00009688, 0x00009688, 0x00009688, 0x00009688, 0x00009688 } },
+       { 6, 0x98c4,
+           { 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001 } },
+       { 7, 0x989c,
+           { 0x00006400, 0x00006400, 0x00006400, 0x00006400, 0x00006400 } },
+       { 7, 0x989c,
+           { 0x00000800, 0x00000800, 0x00000800, 0x00000800, 0x00000800 } },
+       { 7, 0x98cc,
+           { 0x0000000e, 0x0000000e, 0x0000000e, 0x0000000e, 0x0000000e } },
+};
+
+/*
+ * TODO: Handle the few differences with swan during
+ * bank modification and get rid of this
+ * XXX: a/aTurbo ?
+ */
+static const struct ath5k_ini_rfbuffer rfb_2417[] = {
+       { 1, 0x98d4,
+       /*     mode a/XR  mode aTurbo    mode b     mode g    mode gTurbo */
+           { 0x00000020, 0x00000020, 0x00000020, 0x00000020, 0x00000020 } },
+       { 2, 0x98d0,
+           { 0x02001408, 0x02001408, 0x02001408, 0x02001408, 0x02001408 } },
+       { 3, 0x98dc,
+           { 0x00a020c0, 0x00a020c0, 0x00e020c0, 0x00e020c0, 0x00e020c0 } },
+       { 6, 0x989c,
+           { 0x10000000, 0x10000000, 0x10000000, 0x10000000, 0x10000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x002a0000, 0x002a0000, 0x002a0000, 0x002a0000, 0x002a0000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00100000, 0x00100000, 0x00100000, 0x00100000, 0x00100000 } },
+       { 6, 0x989c,
+           { 0x00020000, 0x00020000, 0x00020000, 0x00020000, 0x00020000 } },
+       { 6, 0x989c,
+           { 0x00730000, 0x00730000, 0x00730000, 0x00730000, 0x00730000 } },
+       { 6, 0x989c,
+           { 0x00f80000, 0x00f80000, 0x00f80000, 0x00f80000, 0x00f80000 } },
+       { 6, 0x989c,
+           { 0x00e70000, 0x00e70000, 0x80e70000, 0x80e70000, 0x00e70000 } },
+       { 6, 0x989c,
+           { 0x00140000, 0x00140000, 0x00140000, 0x00140000, 0x00140000 } },
+       { 6, 0x989c,
+           { 0x00910040, 0x00910040, 0x00910040, 0x00910040, 0x00910040 } },
+       { 6, 0x989c,
+           { 0x0007001a, 0x0007001a, 0x0207001a, 0x0207001a, 0x0007001a } },
+       { 6, 0x989c,
+           { 0x00410000, 0x00410000, 0x00410000, 0x00410000, 0x00410000 } },
+       { 6, 0x989c,
+           { 0x00810000, 0x00810000, 0x00810060, 0x00810060, 0x00810060 } },
+       { 6, 0x989c,
+           { 0x00020800, 0x00020800, 0x00020803, 0x00020803, 0x00020803 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
+       { 6, 0x989c,
+           { 0x00001660, 0x00001660, 0x00001660, 0x00001660, 0x00001660 } },
+       { 6, 0x989c,
+           { 0x00001688, 0x00001688, 0x00001688, 0x00001688, 0x00001688 } },
+       { 6, 0x98c4,
+           { 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001 } },
+       { 7, 0x989c,
+           { 0x00006400, 0x00006400, 0x00006400, 0x00006400, 0x00006400 } },
+       { 7, 0x989c,
+           { 0x00000800, 0x00000800, 0x00000800, 0x00000800, 0x00000800 } },
+       { 7, 0x98cc,
+           { 0x0000000e, 0x0000000e, 0x0000000e, 0x0000000e, 0x0000000e } },
+};
diff --git a/src/drivers/net/ath5k/rfgain.h b/src/drivers/net/ath5k/rfgain.h
new file mode 100644 (file)
index 0000000..1354d8c
--- /dev/null
@@ -0,0 +1,516 @@
+/*
+ * RF Gain optimization
+ *
+ * Copyright (c) 2004-2009 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2006-2009 Nick Kossifidis <mickflemm@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/*
+ * Mode-specific RF Gain table (64bytes) for RF5111/5112
+ * (RF5110 only comes with AR5210 and only supports a/turbo a mode so initial
+ * RF Gain values are included in AR5K_AR5210_INI)
+ */
+struct ath5k_ini_rfgain {
+       u16     rfg_register;   /* RF Gain register address */
+       u32     rfg_value[2];   /* [freq (see below)] */
+};
+
+/* Initial RF Gain settings for RF5111 */
+static const struct ath5k_ini_rfgain rfgain_5111[] = {
+       /*                            5Ghz      2Ghz    */
+       { AR5K_RF_GAIN(0),      { 0x000001a9, 0x00000000 } },
+       { AR5K_RF_GAIN(1),      { 0x000001e9, 0x00000040 } },
+       { AR5K_RF_GAIN(2),      { 0x00000029, 0x00000080 } },
+       { AR5K_RF_GAIN(3),      { 0x00000069, 0x00000150 } },
+       { AR5K_RF_GAIN(4),      { 0x00000199, 0x00000190 } },
+       { AR5K_RF_GAIN(5),      { 0x000001d9, 0x000001d0 } },
+       { AR5K_RF_GAIN(6),      { 0x00000019, 0x00000010 } },
+       { AR5K_RF_GAIN(7),      { 0x00000059, 0x00000044 } },
+       { AR5K_RF_GAIN(8),      { 0x00000099, 0x00000084 } },
+       { AR5K_RF_GAIN(9),      { 0x000001a5, 0x00000148 } },
+       { AR5K_RF_GAIN(10),     { 0x000001e5, 0x00000188 } },
+       { AR5K_RF_GAIN(11),     { 0x00000025, 0x000001c8 } },
+       { AR5K_RF_GAIN(12),     { 0x000001c8, 0x00000014 } },
+       { AR5K_RF_GAIN(13),     { 0x00000008, 0x00000042 } },
+       { AR5K_RF_GAIN(14),     { 0x00000048, 0x00000082 } },
+       { AR5K_RF_GAIN(15),     { 0x00000088, 0x00000178 } },
+       { AR5K_RF_GAIN(16),     { 0x00000198, 0x000001b8 } },
+       { AR5K_RF_GAIN(17),     { 0x000001d8, 0x000001f8 } },
+       { AR5K_RF_GAIN(18),     { 0x00000018, 0x00000012 } },
+       { AR5K_RF_GAIN(19),     { 0x00000058, 0x00000052 } },
+       { AR5K_RF_GAIN(20),     { 0x00000098, 0x00000092 } },
+       { AR5K_RF_GAIN(21),     { 0x000001a4, 0x0000017c } },
+       { AR5K_RF_GAIN(22),     { 0x000001e4, 0x000001bc } },
+       { AR5K_RF_GAIN(23),     { 0x00000024, 0x000001fc } },
+       { AR5K_RF_GAIN(24),     { 0x00000064, 0x0000000a } },
+       { AR5K_RF_GAIN(25),     { 0x000000a4, 0x0000004a } },
+       { AR5K_RF_GAIN(26),     { 0x000000e4, 0x0000008a } },
+       { AR5K_RF_GAIN(27),     { 0x0000010a, 0x0000015a } },
+       { AR5K_RF_GAIN(28),     { 0x0000014a, 0x0000019a } },
+       { AR5K_RF_GAIN(29),     { 0x0000018a, 0x000001da } },
+       { AR5K_RF_GAIN(30),     { 0x000001ca, 0x0000000e } },
+       { AR5K_RF_GAIN(31),     { 0x0000000a, 0x0000004e } },
+       { AR5K_RF_GAIN(32),     { 0x0000004a, 0x0000008e } },
+       { AR5K_RF_GAIN(33),     { 0x0000008a, 0x0000015e } },
+       { AR5K_RF_GAIN(34),     { 0x000001ba, 0x0000019e } },
+       { AR5K_RF_GAIN(35),     { 0x000001fa, 0x000001de } },
+       { AR5K_RF_GAIN(36),     { 0x0000003a, 0x00000009 } },
+       { AR5K_RF_GAIN(37),     { 0x0000007a, 0x00000049 } },
+       { AR5K_RF_GAIN(38),     { 0x00000186, 0x00000089 } },
+       { AR5K_RF_GAIN(39),     { 0x000001c6, 0x00000179 } },
+       { AR5K_RF_GAIN(40),     { 0x00000006, 0x000001b9 } },
+       { AR5K_RF_GAIN(41),     { 0x00000046, 0x000001f9 } },
+       { AR5K_RF_GAIN(42),     { 0x00000086, 0x00000039 } },
+       { AR5K_RF_GAIN(43),     { 0x000000c6, 0x00000079 } },
+       { AR5K_RF_GAIN(44),     { 0x000000c6, 0x000000b9 } },
+       { AR5K_RF_GAIN(45),     { 0x000000c6, 0x000001bd } },
+       { AR5K_RF_GAIN(46),     { 0x000000c6, 0x000001fd } },
+       { AR5K_RF_GAIN(47),     { 0x000000c6, 0x0000003d } },
+       { AR5K_RF_GAIN(48),     { 0x000000c6, 0x0000007d } },
+       { AR5K_RF_GAIN(49),     { 0x000000c6, 0x000000bd } },
+       { AR5K_RF_GAIN(50),     { 0x000000c6, 0x000000fd } },
+       { AR5K_RF_GAIN(51),     { 0x000000c6, 0x000000fd } },
+       { AR5K_RF_GAIN(52),     { 0x000000c6, 0x000000fd } },
+       { AR5K_RF_GAIN(53),     { 0x000000c6, 0x000000fd } },
+       { AR5K_RF_GAIN(54),     { 0x000000c6, 0x000000fd } },
+       { AR5K_RF_GAIN(55),     { 0x000000c6, 0x000000fd } },
+       { AR5K_RF_GAIN(56),     { 0x000000c6, 0x000000fd } },
+       { AR5K_RF_GAIN(57),     { 0x000000c6, 0x000000fd } },
+       { AR5K_RF_GAIN(58),     { 0x000000c6, 0x000000fd } },
+       { AR5K_RF_GAIN(59),     { 0x000000c6, 0x000000fd } },
+       { AR5K_RF_GAIN(60),     { 0x000000c6, 0x000000fd } },
+       { AR5K_RF_GAIN(61),     { 0x000000c6, 0x000000fd } },
+       { AR5K_RF_GAIN(62),     { 0x000000c6, 0x000000fd } },
+       { AR5K_RF_GAIN(63),     { 0x000000c6, 0x000000fd } },
+};
+
+/* Initial RF Gain settings for RF5112 */
+static const struct ath5k_ini_rfgain rfgain_5112[] = {
+       /*                            5Ghz      2Ghz    */
+       { AR5K_RF_GAIN(0),      { 0x00000007, 0x00000007 } },
+       { AR5K_RF_GAIN(1),      { 0x00000047, 0x00000047 } },
+       { AR5K_RF_GAIN(2),      { 0x00000087, 0x00000087 } },
+       { AR5K_RF_GAIN(3),      { 0x000001a0, 0x000001a0 } },
+       { AR5K_RF_GAIN(4),      { 0x000001e0, 0x000001e0 } },
+       { AR5K_RF_GAIN(5),      { 0x00000020, 0x00000020 } },
+       { AR5K_RF_GAIN(6),      { 0x00000060, 0x00000060 } },
+       { AR5K_RF_GAIN(7),      { 0x000001a1, 0x000001a1 } },
+       { AR5K_RF_GAIN(8),      { 0x000001e1, 0x000001e1 } },
+       { AR5K_RF_GAIN(9),      { 0x00000021, 0x00000021 } },
+       { AR5K_RF_GAIN(10),     { 0x00000061, 0x00000061 } },
+       { AR5K_RF_GAIN(11),     { 0x00000162, 0x00000162 } },
+       { AR5K_RF_GAIN(12),     { 0x000001a2, 0x000001a2 } },
+       { AR5K_RF_GAIN(13),     { 0x000001e2, 0x000001e2 } },
+       { AR5K_RF_GAIN(14),     { 0x00000022, 0x00000022 } },
+       { AR5K_RF_GAIN(15),     { 0x00000062, 0x00000062 } },
+       { AR5K_RF_GAIN(16),     { 0x00000163, 0x00000163 } },
+       { AR5K_RF_GAIN(17),     { 0x000001a3, 0x000001a3 } },
+       { AR5K_RF_GAIN(18),     { 0x000001e3, 0x000001e3 } },
+       { AR5K_RF_GAIN(19),     { 0x00000023, 0x00000023 } },
+       { AR5K_RF_GAIN(20),     { 0x00000063, 0x00000063 } },
+       { AR5K_RF_GAIN(21),     { 0x00000184, 0x00000184 } },
+       { AR5K_RF_GAIN(22),     { 0x000001c4, 0x000001c4 } },
+       { AR5K_RF_GAIN(23),     { 0x00000004, 0x00000004 } },
+       { AR5K_RF_GAIN(24),     { 0x000001ea, 0x0000000b } },
+       { AR5K_RF_GAIN(25),     { 0x0000002a, 0x0000004b } },
+       { AR5K_RF_GAIN(26),     { 0x0000006a, 0x0000008b } },
+       { AR5K_RF_GAIN(27),     { 0x000000aa, 0x000001ac } },
+       { AR5K_RF_GAIN(28),     { 0x000001ab, 0x000001ec } },
+       { AR5K_RF_GAIN(29),     { 0x000001eb, 0x0000002c } },
+       { AR5K_RF_GAIN(30),     { 0x0000002b, 0x00000012 } },
+       { AR5K_RF_GAIN(31),     { 0x0000006b, 0x00000052 } },
+       { AR5K_RF_GAIN(32),     { 0x000000ab, 0x00000092 } },
+       { AR5K_RF_GAIN(33),     { 0x000001ac, 0x00000193 } },
+       { AR5K_RF_GAIN(34),     { 0x000001ec, 0x000001d3 } },
+       { AR5K_RF_GAIN(35),     { 0x0000002c, 0x00000013 } },
+       { AR5K_RF_GAIN(36),     { 0x0000003a, 0x00000053 } },
+       { AR5K_RF_GAIN(37),     { 0x0000007a, 0x00000093 } },
+       { AR5K_RF_GAIN(38),     { 0x000000ba, 0x00000194 } },
+       { AR5K_RF_GAIN(39),     { 0x000001bb, 0x000001d4 } },
+       { AR5K_RF_GAIN(40),     { 0x000001fb, 0x00000014 } },
+       { AR5K_RF_GAIN(41),     { 0x0000003b, 0x0000003a } },
+       { AR5K_RF_GAIN(42),     { 0x0000007b, 0x0000007a } },
+       { AR5K_RF_GAIN(43),     { 0x000000bb, 0x000000ba } },
+       { AR5K_RF_GAIN(44),     { 0x000001bc, 0x000001bb } },
+       { AR5K_RF_GAIN(45),     { 0x000001fc, 0x000001fb } },
+       { AR5K_RF_GAIN(46),     { 0x0000003c, 0x0000003b } },
+       { AR5K_RF_GAIN(47),     { 0x0000007c, 0x0000007b } },
+       { AR5K_RF_GAIN(48),     { 0x000000bc, 0x000000bb } },
+       { AR5K_RF_GAIN(49),     { 0x000000fc, 0x000001bc } },
+       { AR5K_RF_GAIN(50),     { 0x000000fc, 0x000001fc } },
+       { AR5K_RF_GAIN(51),     { 0x000000fc, 0x0000003c } },
+       { AR5K_RF_GAIN(52),     { 0x000000fc, 0x0000007c } },
+       { AR5K_RF_GAIN(53),     { 0x000000fc, 0x000000bc } },
+       { AR5K_RF_GAIN(54),     { 0x000000fc, 0x000000fc } },
+       { AR5K_RF_GAIN(55),     { 0x000000fc, 0x000000fc } },
+       { AR5K_RF_GAIN(56),     { 0x000000fc, 0x000000fc } },
+       { AR5K_RF_GAIN(57),     { 0x000000fc, 0x000000fc } },
+       { AR5K_RF_GAIN(58),     { 0x000000fc, 0x000000fc } },
+       { AR5K_RF_GAIN(59),     { 0x000000fc, 0x000000fc } },
+       { AR5K_RF_GAIN(60),     { 0x000000fc, 0x000000fc } },
+       { AR5K_RF_GAIN(61),     { 0x000000fc, 0x000000fc } },
+       { AR5K_RF_GAIN(62),     { 0x000000fc, 0x000000fc } },
+       { AR5K_RF_GAIN(63),     { 0x000000fc, 0x000000fc } },
+};
+
+/* Initial RF Gain settings for RF2413 */
+static const struct ath5k_ini_rfgain rfgain_2413[] = {
+       { AR5K_RF_GAIN(0),      { 0x00000000, 0x00000000 } },
+       { AR5K_RF_GAIN(1),      { 0x00000000, 0x00000040 } },
+       { AR5K_RF_GAIN(2),      { 0x00000000, 0x00000080 } },
+       { AR5K_RF_GAIN(3),      { 0x00000000, 0x00000181 } },
+       { AR5K_RF_GAIN(4),      { 0x00000000, 0x000001c1 } },
+       { AR5K_RF_GAIN(5),      { 0x00000000, 0x00000001 } },
+       { AR5K_RF_GAIN(6),      { 0x00000000, 0x00000041 } },
+       { AR5K_RF_GAIN(7),      { 0x00000000, 0x00000081 } },
+       { AR5K_RF_GAIN(8),      { 0x00000000, 0x00000168 } },
+       { AR5K_RF_GAIN(9),      { 0x00000000, 0x000001a8 } },
+       { AR5K_RF_GAIN(10),     { 0x00000000, 0x000001e8 } },
+       { AR5K_RF_GAIN(11),     { 0x00000000, 0x00000028 } },
+       { AR5K_RF_GAIN(12),     { 0x00000000, 0x00000068 } },
+       { AR5K_RF_GAIN(13),     { 0x00000000, 0x00000189 } },
+       { AR5K_RF_GAIN(14),     { 0x00000000, 0x000001c9 } },
+       { AR5K_RF_GAIN(15),     { 0x00000000, 0x00000009 } },
+       { AR5K_RF_GAIN(16),     { 0x00000000, 0x00000049 } },
+       { AR5K_RF_GAIN(17),     { 0x00000000, 0x00000089 } },
+       { AR5K_RF_GAIN(18),     { 0x00000000, 0x00000190 } },
+       { AR5K_RF_GAIN(19),     { 0x00000000, 0x000001d0 } },
+       { AR5K_RF_GAIN(20),     { 0x00000000, 0x00000010 } },
+       { AR5K_RF_GAIN(21),     { 0x00000000, 0x00000050 } },
+       { AR5K_RF_GAIN(22),     { 0x00000000, 0x00000090 } },
+       { AR5K_RF_GAIN(23),     { 0x00000000, 0x00000191 } },
+       { AR5K_RF_GAIN(24),     { 0x00000000, 0x000001d1 } },
+       { AR5K_RF_GAIN(25),     { 0x00000000, 0x00000011 } },
+       { AR5K_RF_GAIN(26),     { 0x00000000, 0x00000051 } },
+       { AR5K_RF_GAIN(27),     { 0x00000000, 0x00000091 } },
+       { AR5K_RF_GAIN(28),     { 0x00000000, 0x00000178 } },
+       { AR5K_RF_GAIN(29),     { 0x00000000, 0x000001b8 } },
+       { AR5K_RF_GAIN(30),     { 0x00000000, 0x000001f8 } },
+       { AR5K_RF_GAIN(31),     { 0x00000000, 0x00000038 } },
+       { AR5K_RF_GAIN(32),     { 0x00000000, 0x00000078 } },
+       { AR5K_RF_GAIN(33),     { 0x00000000, 0x00000199 } },
+       { AR5K_RF_GAIN(34),     { 0x00000000, 0x000001d9 } },
+       { AR5K_RF_GAIN(35),     { 0x00000000, 0x00000019 } },
+       { AR5K_RF_GAIN(36),     { 0x00000000, 0x00000059 } },
+       { AR5K_RF_GAIN(37),     { 0x00000000, 0x00000099 } },
+       { AR5K_RF_GAIN(38),     { 0x00000000, 0x000000d9 } },
+       { AR5K_RF_GAIN(39),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(40),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(41),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(42),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(43),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(44),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(45),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(46),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(47),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(48),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(49),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(50),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(51),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(52),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(53),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(54),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(55),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(56),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(57),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(58),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(59),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(60),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(61),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(62),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(63),     { 0x00000000, 0x000000f9 } },
+};
+
+/* Initial RF Gain settings for AR2316 */
+static const struct ath5k_ini_rfgain rfgain_2316[] = {
+       { AR5K_RF_GAIN(0),      { 0x00000000, 0x00000000 } },
+       { AR5K_RF_GAIN(1),      { 0x00000000, 0x00000040 } },
+       { AR5K_RF_GAIN(2),      { 0x00000000, 0x00000080 } },
+       { AR5K_RF_GAIN(3),      { 0x00000000, 0x000000c0 } },
+       { AR5K_RF_GAIN(4),      { 0x00000000, 0x000000e0 } },
+       { AR5K_RF_GAIN(5),      { 0x00000000, 0x000000e0 } },
+       { AR5K_RF_GAIN(6),      { 0x00000000, 0x00000128 } },
+       { AR5K_RF_GAIN(7),      { 0x00000000, 0x00000128 } },
+       { AR5K_RF_GAIN(8),      { 0x00000000, 0x00000128 } },
+       { AR5K_RF_GAIN(9),      { 0x00000000, 0x00000168 } },
+       { AR5K_RF_GAIN(10),     { 0x00000000, 0x000001a8 } },
+       { AR5K_RF_GAIN(11),     { 0x00000000, 0x000001e8 } },
+       { AR5K_RF_GAIN(12),     { 0x00000000, 0x00000028 } },
+       { AR5K_RF_GAIN(13),     { 0x00000000, 0x00000068 } },
+       { AR5K_RF_GAIN(14),     { 0x00000000, 0x000000a8 } },
+       { AR5K_RF_GAIN(15),     { 0x00000000, 0x000000e8 } },
+       { AR5K_RF_GAIN(16),     { 0x00000000, 0x000000e8 } },
+       { AR5K_RF_GAIN(17),     { 0x00000000, 0x00000130 } },
+       { AR5K_RF_GAIN(18),     { 0x00000000, 0x00000130 } },
+       { AR5K_RF_GAIN(19),     { 0x00000000, 0x00000170 } },
+       { AR5K_RF_GAIN(20),     { 0x00000000, 0x000001b0 } },
+       { AR5K_RF_GAIN(21),     { 0x00000000, 0x000001f0 } },
+       { AR5K_RF_GAIN(22),     { 0x00000000, 0x00000030 } },
+       { AR5K_RF_GAIN(23),     { 0x00000000, 0x00000070 } },
+       { AR5K_RF_GAIN(24),     { 0x00000000, 0x000000b0 } },
+       { AR5K_RF_GAIN(25),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(26),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(27),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(28),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(29),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(30),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(31),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(32),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(33),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(34),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(35),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(36),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(37),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(38),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(39),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(40),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(41),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(42),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(43),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(44),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(45),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(46),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(47),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(48),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(49),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(50),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(51),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(52),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(53),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(54),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(55),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(56),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(57),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(58),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(59),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(60),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(61),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(62),     { 0x00000000, 0x000000f0 } },
+       { AR5K_RF_GAIN(63),     { 0x00000000, 0x000000f0 } },
+};
+
+
+/* Initial RF Gain settings for RF5413 */
+static const struct ath5k_ini_rfgain rfgain_5413[] = {
+       /*                            5Ghz      2Ghz    */
+       { AR5K_RF_GAIN(0),      { 0x00000000, 0x00000000 } },
+       { AR5K_RF_GAIN(1),      { 0x00000040, 0x00000040 } },
+       { AR5K_RF_GAIN(2),      { 0x00000080, 0x00000080 } },
+       { AR5K_RF_GAIN(3),      { 0x000001a1, 0x00000161 } },
+       { AR5K_RF_GAIN(4),      { 0x000001e1, 0x000001a1 } },
+       { AR5K_RF_GAIN(5),      { 0x00000021, 0x000001e1 } },
+       { AR5K_RF_GAIN(6),      { 0x00000061, 0x00000021 } },
+       { AR5K_RF_GAIN(7),      { 0x00000188, 0x00000061 } },
+       { AR5K_RF_GAIN(8),      { 0x000001c8, 0x00000188 } },
+       { AR5K_RF_GAIN(9),      { 0x00000008, 0x000001c8 } },
+       { AR5K_RF_GAIN(10),     { 0x00000048, 0x00000008 } },
+       { AR5K_RF_GAIN(11),     { 0x00000088, 0x00000048 } },
+       { AR5K_RF_GAIN(12),     { 0x000001a9, 0x00000088 } },
+       { AR5K_RF_GAIN(13),     { 0x000001e9, 0x00000169 } },
+       { AR5K_RF_GAIN(14),     { 0x00000029, 0x000001a9 } },
+       { AR5K_RF_GAIN(15),     { 0x00000069, 0x000001e9 } },
+       { AR5K_RF_GAIN(16),     { 0x000001d0, 0x00000029 } },
+       { AR5K_RF_GAIN(17),     { 0x00000010, 0x00000069 } },
+       { AR5K_RF_GAIN(18),     { 0x00000050, 0x00000190 } },
+       { AR5K_RF_GAIN(19),     { 0x00000090, 0x000001d0 } },
+       { AR5K_RF_GAIN(20),     { 0x000001b1, 0x00000010 } },
+       { AR5K_RF_GAIN(21),     { 0x000001f1, 0x00000050 } },
+       { AR5K_RF_GAIN(22),     { 0x00000031, 0x00000090 } },
+       { AR5K_RF_GAIN(23),     { 0x00000071, 0x00000171 } },
+       { AR5K_RF_GAIN(24),     { 0x000001b8, 0x000001b1 } },
+       { AR5K_RF_GAIN(25),     { 0x000001f8, 0x000001f1 } },
+       { AR5K_RF_GAIN(26),     { 0x00000038, 0x00000031 } },
+       { AR5K_RF_GAIN(27),     { 0x00000078, 0x00000071 } },
+       { AR5K_RF_GAIN(28),     { 0x00000199, 0x00000198 } },
+       { AR5K_RF_GAIN(29),     { 0x000001d9, 0x000001d8 } },
+       { AR5K_RF_GAIN(30),     { 0x00000019, 0x00000018 } },
+       { AR5K_RF_GAIN(31),     { 0x00000059, 0x00000058 } },
+       { AR5K_RF_GAIN(32),     { 0x00000099, 0x00000098 } },
+       { AR5K_RF_GAIN(33),     { 0x000000d9, 0x00000179 } },
+       { AR5K_RF_GAIN(34),     { 0x000000f9, 0x000001b9 } },
+       { AR5K_RF_GAIN(35),     { 0x000000f9, 0x000001f9 } },
+       { AR5K_RF_GAIN(36),     { 0x000000f9, 0x00000039 } },
+       { AR5K_RF_GAIN(37),     { 0x000000f9, 0x00000079 } },
+       { AR5K_RF_GAIN(38),     { 0x000000f9, 0x000000b9 } },
+       { AR5K_RF_GAIN(39),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(40),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(41),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(42),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(43),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(44),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(45),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(46),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(47),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(48),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(49),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(50),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(51),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(52),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(53),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(54),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(55),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(56),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(57),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(58),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(59),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(60),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(61),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(62),     { 0x000000f9, 0x000000f9 } },
+       { AR5K_RF_GAIN(63),     { 0x000000f9, 0x000000f9 } },
+};
+
+
+/* Initial RF Gain settings for RF2425 */
+static const struct ath5k_ini_rfgain rfgain_2425[] = {
+       { AR5K_RF_GAIN(0),      { 0x00000000, 0x00000000 } },
+       { AR5K_RF_GAIN(1),      { 0x00000000, 0x00000040 } },
+       { AR5K_RF_GAIN(2),      { 0x00000000, 0x00000080 } },
+       { AR5K_RF_GAIN(3),      { 0x00000000, 0x00000181 } },
+       { AR5K_RF_GAIN(4),      { 0x00000000, 0x000001c1 } },
+       { AR5K_RF_GAIN(5),      { 0x00000000, 0x00000001 } },
+       { AR5K_RF_GAIN(6),      { 0x00000000, 0x00000041 } },
+       { AR5K_RF_GAIN(7),      { 0x00000000, 0x00000081 } },
+       { AR5K_RF_GAIN(8),      { 0x00000000, 0x00000188 } },
+       { AR5K_RF_GAIN(9),      { 0x00000000, 0x000001c8 } },
+       { AR5K_RF_GAIN(10),     { 0x00000000, 0x00000008 } },
+       { AR5K_RF_GAIN(11),     { 0x00000000, 0x00000048 } },
+       { AR5K_RF_GAIN(12),     { 0x00000000, 0x00000088 } },
+       { AR5K_RF_GAIN(13),     { 0x00000000, 0x00000189 } },
+       { AR5K_RF_GAIN(14),     { 0x00000000, 0x000001c9 } },
+       { AR5K_RF_GAIN(15),     { 0x00000000, 0x00000009 } },
+       { AR5K_RF_GAIN(16),     { 0x00000000, 0x00000049 } },
+       { AR5K_RF_GAIN(17),     { 0x00000000, 0x00000089 } },
+       { AR5K_RF_GAIN(18),     { 0x00000000, 0x000001b0 } },
+       { AR5K_RF_GAIN(19),     { 0x00000000, 0x000001f0 } },
+       { AR5K_RF_GAIN(20),     { 0x00000000, 0x00000030 } },
+       { AR5K_RF_GAIN(21),     { 0x00000000, 0x00000070 } },
+       { AR5K_RF_GAIN(22),     { 0x00000000, 0x00000171 } },
+       { AR5K_RF_GAIN(23),     { 0x00000000, 0x000001b1 } },
+       { AR5K_RF_GAIN(24),     { 0x00000000, 0x000001f1 } },
+       { AR5K_RF_GAIN(25),     { 0x00000000, 0x00000031 } },
+       { AR5K_RF_GAIN(26),     { 0x00000000, 0x00000071 } },
+       { AR5K_RF_GAIN(27),     { 0x00000000, 0x000001b8 } },
+       { AR5K_RF_GAIN(28),     { 0x00000000, 0x000001f8 } },
+       { AR5K_RF_GAIN(29),     { 0x00000000, 0x00000038 } },
+       { AR5K_RF_GAIN(30),     { 0x00000000, 0x00000078 } },
+       { AR5K_RF_GAIN(31),     { 0x00000000, 0x000000b8 } },
+       { AR5K_RF_GAIN(32),     { 0x00000000, 0x000001b9 } },
+       { AR5K_RF_GAIN(33),     { 0x00000000, 0x000001f9 } },
+       { AR5K_RF_GAIN(34),     { 0x00000000, 0x00000039 } },
+       { AR5K_RF_GAIN(35),     { 0x00000000, 0x00000079 } },
+       { AR5K_RF_GAIN(36),     { 0x00000000, 0x000000b9 } },
+       { AR5K_RF_GAIN(37),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(38),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(39),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(40),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(41),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(42),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(43),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(44),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(45),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(46),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(47),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(48),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(49),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(50),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(51),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(52),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(53),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(54),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(55),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(56),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(57),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(58),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(59),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(60),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(61),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(62),     { 0x00000000, 0x000000f9 } },
+       { AR5K_RF_GAIN(63),     { 0x00000000, 0x000000f9 } },
+};
+
+#define AR5K_GAIN_CRN_FIX_BITS_5111            4
+#define AR5K_GAIN_CRN_FIX_BITS_5112            7
+#define AR5K_GAIN_CRN_MAX_FIX_BITS             AR5K_GAIN_CRN_FIX_BITS_5112
+#define AR5K_GAIN_DYN_ADJUST_HI_MARGIN         15
+#define AR5K_GAIN_DYN_ADJUST_LO_MARGIN         20
+#define AR5K_GAIN_CCK_PROBE_CORR               5
+#define AR5K_GAIN_CCK_OFDM_GAIN_DELTA          15
+#define AR5K_GAIN_STEP_COUNT                   10
+
+/* Check if our current measurement is inside our
+ * current variable attenuation window */
+#define AR5K_GAIN_CHECK_ADJUST(_g)             \
+       ((_g)->g_current <= (_g)->g_low || (_g)->g_current >= (_g)->g_high)
+
+struct ath5k_gain_opt_step {
+       s8                              gos_param[AR5K_GAIN_CRN_MAX_FIX_BITS];
+       s8                              gos_gain;
+};
+
+struct ath5k_gain_opt {
+       u8                              go_default;
+       u8                              go_steps_count;
+       const struct ath5k_gain_opt_step        go_step[AR5K_GAIN_STEP_COUNT];
+};
+
+/*
+ * Parameters on gos_param:
+ * 1) Tx clip PHY register
+ * 2) PWD 90 RF register
+ * 3) PWD 84 RF register
+ * 4) RFGainSel RF register
+ */
+static const struct ath5k_gain_opt rfgain_opt_5111 = {
+       4,
+       9,
+       {
+               { { 4, 1, 1, 1 }, 6 },
+               { { 4, 0, 1, 1 }, 4 },
+               { { 3, 1, 1, 1 }, 3 },
+               { { 4, 0, 0, 1 }, 1 },
+               { { 4, 1, 1, 0 }, 0 },
+               { { 4, 0, 1, 0 }, -2 },
+               { { 3, 1, 1, 0 }, -3 },
+               { { 4, 0, 0, 0 }, -4 },
+               { { 2, 1, 1, 0 }, -6 }
+       }
+};
+
+/*
+ * Parameters on gos_param:
+ * 1) Mixgain ovr RF register
+ * 2) PWD 138 RF register
+ * 3) PWD 137 RF register
+ * 4) PWD 136 RF register
+ * 5) PWD 132 RF register
+ * 6) PWD 131 RF register
+ * 7) PWD 130 RF register
+ */
+static const struct ath5k_gain_opt rfgain_opt_5112 = {
+       1,
+       8,
+       {
+               { { 3, 0, 0, 0, 0, 0, 0 }, 6 },
+               { { 2, 0, 0, 0, 0, 0, 0 }, 0 },
+               { { 1, 0, 0, 0, 0, 0, 0 }, -3 },
+               { { 0, 0, 0, 0, 0, 0, 0 }, -6 },
+               { { 0, 1, 1, 0, 0, 0, 0 }, -8 },
+               { { 0, 1, 1, 0, 1, 1, 0 }, -10 },
+               { { 0, 1, 0, 1, 1, 1, 0 }, -13 },
+               { { 0, 1, 0, 1, 1, 0, 1 }, -16 },
+       }
+};
+
index 46a75d9a7eea6d38ce34953ca7df56b71a652ede..aac6ca94ce15efa9eac414d7d74f169dbc282ad7 100644 (file)
@@ -112,6 +112,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #define ERRFILE_b44                 ( ERRFILE_DRIVER | 0x004d0000 )
 #define ERRFILE_rtl818x                     ( ERRFILE_DRIVER | 0x004e0000 )
 #define ERRFILE_sky2                 ( ERRFILE_DRIVER | 0x004f0000 )
+#define ERRFILE_ath5k               ( ERRFILE_DRIVER | 0x00500000 )
 
 #define ERRFILE_scsi                ( ERRFILE_DRIVER | 0x00700000 )
 #define ERRFILE_arbel               ( ERRFILE_DRIVER | 0x00710000 )