mwl8k: get rid of mwl8k_config() workqueue use
[pandora-kernel.git] / drivers / net / wireless / mwl8k.c
index 682b820..77e280a 100644 (file)
@@ -1,5 +1,6 @@
 /*
- * drivers/net/wireless/mwl8k.c driver for Marvell TOPDOG 802.11 Wireless cards
+ * drivers/net/wireless/mwl8k.c
+ * Driver for Marvell TOPDOG 802.11 Wireless cards
  *
  * Copyright (C) 2008 Marvell Semiconductor Inc.
  *
@@ -40,12 +41,12 @@ MODULE_DEVICE_TABLE(pci, mwl8k_table);
 
 /* Register definitions */
 #define MWL8K_HIU_GEN_PTR                      0x00000c10
-#define  MWL8K_MODE_STA                                0x0000005a
-#define  MWL8K_MODE_AP                         0x000000a5
+#define  MWL8K_MODE_STA                                 0x0000005a
+#define  MWL8K_MODE_AP                          0x000000a5
 #define MWL8K_HIU_INT_CODE                     0x00000c14
-#define  MWL8K_FWSTA_READY                     0xf0f1f2f4
-#define  MWL8K_FWAP_READY                      0xf1f2f4a5
-#define  MWL8K_INT_CODE_CMD_FINISHED           0x00000005
+#define  MWL8K_FWSTA_READY                      0xf0f1f2f4
+#define  MWL8K_FWAP_READY                       0xf1f2f4a5
+#define  MWL8K_INT_CODE_CMD_FINISHED            0x00000005
 #define MWL8K_HIU_SCRATCH                      0x00000c40
 
 /* Host->device communications */
@@ -54,10 +55,10 @@ MODULE_DEVICE_TABLE(pci, mwl8k_table);
 #define MWL8K_HIU_H2A_INTERRUPT_MASK           0x00000c20
 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL      0x00000c24
 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK    0x00000c28
-#define  MWL8K_H2A_INT_DUMMY                   (1 << 20)
-#define  MWL8K_H2A_INT_RESET                   (1 << 15)
-#define  MWL8K_H2A_INT_DOORBELL                        (1 << 1)
-#define  MWL8K_H2A_INT_PPA_READY               (1 << 0)
+#define  MWL8K_H2A_INT_DUMMY                    (1 << 20)
+#define  MWL8K_H2A_INT_RESET                    (1 << 15)
+#define  MWL8K_H2A_INT_DOORBELL                         (1 << 1)
+#define  MWL8K_H2A_INT_PPA_READY                (1 << 0)
 
 /* Device->host communications */
 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS         0x00000c2c
@@ -65,16 +66,16 @@ MODULE_DEVICE_TABLE(pci, mwl8k_table);
 #define MWL8K_HIU_A2H_INTERRUPT_MASK           0x00000c34
 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL      0x00000c38
 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK    0x00000c3c
-#define  MWL8K_A2H_INT_DUMMY                   (1 << 20)
-#define  MWL8K_A2H_INT_CHNL_SWITCHED           (1 << 11)
-#define  MWL8K_A2H_INT_QUEUE_EMPTY             (1 << 10)
-#define  MWL8K_A2H_INT_RADAR_DETECT            (1 << 7)
-#define  MWL8K_A2H_INT_RADIO_ON                        (1 << 6)
-#define  MWL8K_A2H_INT_RADIO_OFF               (1 << 5)
-#define  MWL8K_A2H_INT_MAC_EVENT               (1 << 3)
-#define  MWL8K_A2H_INT_OPC_DONE                        (1 << 2)
-#define  MWL8K_A2H_INT_RX_READY                        (1 << 1)
-#define  MWL8K_A2H_INT_TX_DONE                 (1 << 0)
+#define  MWL8K_A2H_INT_DUMMY                    (1 << 20)
+#define  MWL8K_A2H_INT_CHNL_SWITCHED            (1 << 11)
+#define  MWL8K_A2H_INT_QUEUE_EMPTY              (1 << 10)
+#define  MWL8K_A2H_INT_RADAR_DETECT             (1 << 7)
+#define  MWL8K_A2H_INT_RADIO_ON                         (1 << 6)
+#define  MWL8K_A2H_INT_RADIO_OFF                (1 << 5)
+#define  MWL8K_A2H_INT_MAC_EVENT                (1 << 3)
+#define  MWL8K_A2H_INT_OPC_DONE                         (1 << 2)
+#define  MWL8K_A2H_INT_RX_READY                         (1 << 1)
+#define  MWL8K_A2H_INT_TX_DONE                  (1 << 0)
 
 #define MWL8K_A2H_EVENTS       (MWL8K_A2H_INT_DUMMY | \
                                 MWL8K_A2H_INT_CHNL_SWITCHED | \
@@ -110,17 +111,6 @@ struct mwl8k_rx_queue {
        struct sk_buff **rx_skb;
 };
 
-struct mwl8k_skb {
-       /*
-        * The DMA engine requires a modification to the payload.
-        * If the skbuff is shared/cloned, it needs to be unshared.
-        * This method is used to ensure the stack always gets back
-        * the skbuff it sent for transmission.
-        */
-       struct sk_buff *clone;
-       struct sk_buff *skb;
-};
-
 struct mwl8k_tx_queue {
        /* hw transmits here */
        int tx_head;
@@ -131,7 +121,7 @@ struct mwl8k_tx_queue {
        struct ieee80211_tx_queue_stats tx_stats;
        struct mwl8k_tx_desc *tx_desc_area;
        dma_addr_t tx_desc_dma;
-       struct mwl8k_skb *tx_skb;
+       struct sk_buff **tx_skb;
 };
 
 /* Pointers to the firmware data and meta information about it.  */
@@ -149,13 +139,18 @@ struct mwl8k_priv {
 
        struct pci_dev *pdev;
        u8 name[16];
-       /* firmware access lock */
-       spinlock_t fw_lock;
 
        /* firmware files and meta data */
        struct mwl8k_firmware fw;
        u32 part_num;
 
+       /* firmware access */
+       struct mutex fw_mutex;
+       struct task_struct *fw_mutex_owner;
+       int fw_mutex_depth;
+       struct completion *tx_wait;
+       struct completion *hostcmd_wait;
+
        /* lock held over TX and TX reap */
        spinlock_t tx_lock;
 
@@ -185,15 +180,9 @@ struct mwl8k_priv {
        struct ieee80211_channel channels[14];
        struct ieee80211_rate rates[12];
 
-       /* RF preamble: Short, Long or Auto */
-       u8      radio_preamble;
-       u8      radio_state;
-
-       /* WMM MODE 1 for enabled; 0 for disabled */
-       bool wmm_mode;
-
-       /* Set if PHY config is in progress */
-       bool inconfig;
+       bool radio_on;
+       bool radio_short_preamble;
+       bool wmm_enabled;
 
        /* XXX need to convert this to handle multiple interfaces */
        bool capture_beacon;
@@ -213,8 +202,6 @@ struct mwl8k_priv {
 
        /* Work thread to serialize configuration requests */
        struct workqueue_struct *config_wq;
-       struct completion *hostcmd_wait;
-       struct completion *tx_wait;
 };
 
 /* Per interface specific private data */
@@ -276,28 +263,6 @@ static const struct ieee80211_rate mwl8k_rates[] = {
        { .bitrate = 540, .hw_value = 108, },
 };
 
-/* Radio settings */
-#define MWL8K_RADIO_FORCE              0x2
-#define MWL8K_RADIO_ENABLE             0x1
-#define MWL8K_RADIO_DISABLE            0x0
-#define MWL8K_RADIO_AUTO_PREAMBLE      0x0005
-#define MWL8K_RADIO_SHORT_PREAMBLE     0x0003
-#define MWL8K_RADIO_LONG_PREAMBLE      0x0001
-
-/* WMM */
-#define MWL8K_WMM_ENABLE               1
-#define MWL8K_WMM_DISABLE              0
-
-#define MWL8K_RADIO_DEFAULT_PREAMBLE   MWL8K_RADIO_LONG_PREAMBLE
-
-/* Slot time */
-
-/* Short Slot: 9us slot time */
-#define MWL8K_SHORT_SLOTTIME           1
-
-/* Long slot: 20us slot time */
-#define MWL8K_LONG_SLOTTIME            0
-
 /* Set or get info from Firmware */
 #define MWL8K_CMD_SET                  0x0001
 #define MWL8K_CMD_GET                  0x0000
@@ -331,7 +296,7 @@ static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
                                        snprintf(buf, bufsize, "%s", #x);\
                                        return buf;\
                                        } while (0)
-       switch (cmd & (~0x8000)) {
+       switch (cmd & ~0x8000) {
                MWL8K_CMDNAME(CODE_DNLD);
                MWL8K_CMDNAME(GET_HW_SPEC);
                MWL8K_CMDNAME(MAC_MULTICAST_ADR);
@@ -446,7 +411,6 @@ mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
 {
        void __iomem *regs = priv->regs;
        dma_addr_t dma_addr;
-       int rc;
        int loops;
 
        dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
@@ -460,7 +424,6 @@ mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
        iowrite32(MWL8K_H2A_INT_DUMMY,
                regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
 
-       rc = -ETIMEDOUT;
        loops = 1000;
        do {
                u32 int_code;
@@ -468,7 +431,6 @@ mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
                int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
                if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
                        iowrite32(0, regs + MWL8K_HIU_INT_CODE);
-                       rc = 0;
                        break;
                }
 
@@ -477,26 +439,7 @@ mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
 
        pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
 
-       /*
-        * Clear 'command done' interrupt bit.
-        */
-       loops = 1000;
-       do {
-               u32 status;
-
-               status = ioread32(priv->regs +
-                               MWL8K_HIU_A2H_INTERRUPT_STATUS);
-               if (status & MWL8K_A2H_INT_OPC_DONE) {
-                       iowrite32(~MWL8K_A2H_INT_OPC_DONE,
-                               priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
-                       ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
-                       break;
-               }
-
-               udelay(1);
-       } while (--loops);
-
-       return rc;
+       return loops ? 0 : -ETIMEDOUT;
 }
 
 static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
@@ -738,12 +681,11 @@ struct mwl8k_dma_data {
 } __attribute__((packed));
 
 /* Routines to add/remove DMA header from skb.  */
-static inline int mwl8k_remove_dma_header(struct sk_buff *skb)
+static inline void mwl8k_remove_dma_header(struct sk_buff *skb)
 {
-       struct mwl8k_dma_data *tr = (struct mwl8k_dma_data *)(skb->data);
+       struct mwl8k_dma_data *tr = (struct mwl8k_dma_data *)skb->data;
        void *dst, *src = &tr->wh;
-       __le16 fc = tr->wh.frame_control;
-       int hdrlen = ieee80211_hdrlen(fc);
+       int hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
        u16 space = sizeof(struct mwl8k_dma_data) - hdrlen;
 
        dst = (void *)tr + space;
@@ -751,11 +693,9 @@ static inline int mwl8k_remove_dma_header(struct sk_buff *skb)
                memmove(dst, src, hdrlen);
                skb_pull(skb, space);
        }
-
-       return 0;
 }
 
-static inline struct sk_buff *mwl8k_add_dma_header(struct sk_buff *skb)
+static inline void mwl8k_add_dma_header(struct sk_buff *skb)
 {
        struct ieee80211_hdr *wh;
        u32 hdrlen, pktlen;
@@ -787,8 +727,6 @@ static inline struct sk_buff *mwl8k_add_dma_header(struct sk_buff *skb)
         * This includes all crypto material including the MIC.
         */
        tr->fwlen = cpu_to_le16(pktlen - hdrlen);
-
-       return skb;
 }
 
 
@@ -991,10 +929,7 @@ static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
                                        MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
 
                skb_put(skb, le16_to_cpu(rx_desc->pkt_len));
-               if (mwl8k_remove_dma_header(skb)) {
-                       dev_kfree_skb(skb);
-                       continue;
-               }
+               mwl8k_remove_dma_header(skb);
 
                wh = (struct ieee80211_hdr *)skb->data;
 
@@ -1078,8 +1013,7 @@ static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
        int size;
        int i;
 
-       memset(&txq->tx_stats, 0,
-               sizeof(struct ieee80211_tx_queue_stats));
+       memset(&txq->tx_stats, 0, sizeof(struct ieee80211_tx_queue_stats));
        txq->tx_stats.limit = MWL8K_TX_DESCS;
        txq->tx_head = 0;
        txq->tx_tail = 0;
@@ -1146,17 +1080,17 @@ struct mwl8k_txq_info {
 };
 
 static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
-                               struct mwl8k_txq_info txinfo[],
-                               u32 num_queues)
+                               struct mwl8k_txq_info *txinfo)
 {
        int count, desc, status;
        struct mwl8k_tx_queue *txq;
        struct mwl8k_tx_desc *tx_desc;
        int ndescs = 0;
 
-       memset(txinfo, 0, num_queues * sizeof(struct mwl8k_txq_info));
+       memset(txinfo, 0, MWL8K_TX_QUEUES * sizeof(struct mwl8k_txq_info));
+
        spin_lock_bh(&priv->tx_lock);
-       for (count = 0; count < num_queues; count++) {
+       for (count = 0; count < MWL8K_TX_QUEUES; count++) {
                txq = priv->txq + count;
                txinfo[count].len = txq->tx_stats.len;
                txinfo[count].head = txq->tx_head;
@@ -1179,34 +1113,34 @@ static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
        return ndescs;
 }
 
-static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw, u32 delay_ms)
+/*
+ * Must be called with hw->fw_mutex held and tx queues stopped.
+ */
+static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
 {
-       u32 count = 0;
-       unsigned long timeout = 0;
        struct mwl8k_priv *priv = hw->priv;
        DECLARE_COMPLETION_ONSTACK(cmd_wait);
+       u32 count;
+       unsigned long timeout;
 
        might_sleep();
 
-       if (priv->tx_wait != NULL)
-               printk(KERN_ERR "WARNING Previous TXWaitEmpty instance\n");
-
        spin_lock_bh(&priv->tx_lock);
        count = mwl8k_txq_busy(priv);
        if (count) {
                priv->tx_wait = &cmd_wait;
-               if (priv->radio_state)
+               if (priv->radio_on)
                        mwl8k_tx_start(priv);
        }
        spin_unlock_bh(&priv->tx_lock);
 
        if (count) {
-               struct mwl8k_txq_info txinfo[4];
+               struct mwl8k_txq_info txinfo[MWL8K_TX_QUEUES];
                int index;
                int newcount;
 
                timeout = wait_for_completion_timeout(&cmd_wait,
-                                       msecs_to_jiffies(delay_ms));
+                                       msecs_to_jiffies(5000));
                if (timeout)
                        return 0;
 
@@ -1215,11 +1149,11 @@ static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw, u32 delay_ms)
                newcount = mwl8k_txq_busy(priv);
                spin_unlock_bh(&priv->tx_lock);
 
-               printk(KERN_ERR "%s(%u) TIMEDOUT:%ums Pend:%u-->%u\n",
-                      __func__, __LINE__, delay_ms, count, newcount);
+               printk(KERN_ERR "%s(%u) TIMEDOUT:5000ms Pend:%u-->%u\n",
+                      __func__, __LINE__, count, newcount);
 
-               mwl8k_scan_tx_ring(priv, txinfo, 4);
-               for (index = 0 ; index < 4; index++)
+               mwl8k_scan_tx_ring(priv, txinfo);
+               for (index = 0; index < MWL8K_TX_QUEUES; index++)
                        printk(KERN_ERR
                                "TXQ:%u L:%u H:%u T:%u FW:%u DRV:%u U:%u\n",
                                        index,
@@ -1229,6 +1163,7 @@ static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw, u32 delay_ms)
                                        txinfo[index].fw_owned,
                                        txinfo[index].drv_owned,
                                        txinfo[index].unused);
+
                return -ETIMEDOUT;
        }
 
@@ -1248,15 +1183,13 @@ static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
 
        while (txq->tx_stats.len > 0) {
                int tx;
-               int rc;
                struct mwl8k_tx_desc *tx_desc;
                unsigned long addr;
-               size_t size;
+               int size;
                struct sk_buff *skb;
                struct ieee80211_tx_info *info;
                u32 status;
 
-               rc = 0;
                tx = txq->tx_head;
                tx_desc = txq->tx_desc_area + tx;
 
@@ -1275,56 +1208,30 @@ static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
                priv->pending_tx_pkts--;
 
                addr = le32_to_cpu(tx_desc->pkt_phys_addr);
-               size = (u32)(le16_to_cpu(tx_desc->pkt_len));
-               skb = txq->tx_skb[tx].skb;
-               txq->tx_skb[tx].skb = NULL;
+               size = le16_to_cpu(tx_desc->pkt_len);
+               skb = txq->tx_skb[tx];
+               txq->tx_skb[tx] = NULL;
 
                BUG_ON(skb == NULL);
                pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
 
-               rc = mwl8k_remove_dma_header(skb);
+               mwl8k_remove_dma_header(skb);
 
                /* Mark descriptor as unused */
                tx_desc->pkt_phys_addr = 0;
                tx_desc->pkt_len = 0;
 
-               if (txq->tx_skb[tx].clone) {
-                       /* Replace with original skb
-                        * before returning to stack
-                        * as buffer has been cloned
-                        */
-                       dev_kfree_skb(skb);
-                       skb = txq->tx_skb[tx].clone;
-                       txq->tx_skb[tx].clone = NULL;
-               }
-
-               if (rc) {
-                       /* Something has gone wrong here.
-                        * Failed to remove DMA header.
-                        * Print error message and drop packet.
-                        */
-                       printk(KERN_ERR "%s: Error removing DMA header from "
-                                       "tx skb 0x%p.\n", priv->name, skb);
-
-                       dev_kfree_skb(skb);
-                       continue;
-               }
-
                info = IEEE80211_SKB_CB(skb);
                ieee80211_tx_info_clear_status(info);
-
-               /* Convert firmware status stuff into tx_status */
-               if (MWL8K_TXD_SUCCESS(status)) {
-                       /* Transmit OK */
+               if (MWL8K_TXD_SUCCESS(status))
                        info->flags |= IEEE80211_TX_STAT_ACK;
-               }
 
                ieee80211_tx_status_irqsafe(hw, skb);
 
-               wake = !priv->inconfig && priv->radio_state;
+               wake = 1;
        }
 
-       if (wake)
+       if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
                ieee80211_wake_queue(hw, index);
 }
 
@@ -1350,56 +1257,60 @@ mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
 {
        struct mwl8k_priv *priv = hw->priv;
        struct ieee80211_tx_info *tx_info;
+       struct mwl8k_vif *mwl8k_vif;
        struct ieee80211_hdr *wh;
        struct mwl8k_tx_queue *txq;
        struct mwl8k_tx_desc *tx;
-       struct mwl8k_dma_data *tr;
-       struct mwl8k_vif *mwl8k_vif;
-       struct sk_buff *org_skb = skb;
        dma_addr_t dma;
-       u16 qos = 0;
-       bool qosframe = false, ampduframe = false;
-       bool mcframe = false, eapolframe = false;
-       bool amsduframe = false;
-       __le16 fc;
-
-       txq = priv->txq + index;
-       tx = txq->tx_desc_area + txq->tx_tail;
-
-       BUG_ON(txq->tx_skb[txq->tx_tail].skb != NULL);
+       u32 txstatus;
+       u8 txdatarate;
+       u16 qos;
 
-       /*
-        * Append HW DMA header to start of packet.  Drop packet if
-        * there is not enough space or a failure to unshare/unclone
-        * the skb.
-        */
-       skb = mwl8k_add_dma_header(skb);
+       wh = (struct ieee80211_hdr *)skb->data;
+       if (ieee80211_is_data_qos(wh->frame_control))
+               qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
+       else
+               qos = 0;
 
-       if (skb == NULL) {
-               printk(KERN_DEBUG "%s: failed to prepend HW DMA "
-                       "header, dropping TX frame.\n", priv->name);
-               dev_kfree_skb(org_skb);
-               return NETDEV_TX_OK;
-       }
+       mwl8k_add_dma_header(skb);
+       wh = &((struct mwl8k_dma_data *)skb->data)->wh;
 
        tx_info = IEEE80211_SKB_CB(skb);
        mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
-       tr = (struct mwl8k_dma_data *)skb->data;
-       wh = &tr->wh;
-       fc = wh->frame_control;
-       qosframe = ieee80211_is_data_qos(fc);
-       mcframe = is_multicast_ether_addr(wh->addr1);
-       ampduframe = !!(tx_info->flags & IEEE80211_TX_CTL_AMPDU);
 
        if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
                u16 seqno = mwl8k_vif->seqno;
+
                wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
                wh->seq_ctrl |= cpu_to_le16(seqno << 4);
                mwl8k_vif->seqno = seqno++ % 4096;
        }
 
-       if (qosframe)
-               qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
+       /* Setup firmware control bit fields for each frame type.  */
+       txstatus = 0;
+       txdatarate = 0;
+       if (ieee80211_is_mgmt(wh->frame_control) ||
+           ieee80211_is_ctl(wh->frame_control)) {
+               txdatarate = 0;
+               qos = mwl8k_qos_setbit_eosp(qos);
+               /* Set Queue size to unspecified */
+               qos = mwl8k_qos_setbit_qlen(qos, 0xff);
+       } else if (ieee80211_is_data(wh->frame_control)) {
+               txdatarate = 1;
+               if (is_multicast_ether_addr(wh->addr1))
+                       txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
+
+               /* Send pkt in an aggregate if AMPDU frame.  */
+               if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
+                       qos = mwl8k_qos_setbit_ack(qos,
+                               MWL8K_TXD_ACK_POLICY_BLOCKACK);
+               else
+                       qos = mwl8k_qos_setbit_ack(qos,
+                               MWL8K_TXD_ACK_POLICY_NORMAL);
+
+               if (qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
+                       qos = mwl8k_qos_setbit_amsdu(qos);
+       }
 
        dma = pci_map_single(priv->pdev, skb->data,
                                skb->len, PCI_DMA_TODEVICE);
@@ -1407,99 +1318,40 @@ mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
        if (pci_dma_mapping_error(priv->pdev, dma)) {
                printk(KERN_DEBUG "%s: failed to dma map skb, "
                        "dropping TX frame.\n", priv->name);
-
-               if (org_skb != NULL)
-                       dev_kfree_skb(org_skb);
-               if (skb != NULL)
-                       dev_kfree_skb(skb);
+               dev_kfree_skb(skb);
                return NETDEV_TX_OK;
        }
 
-       /* Set desc header, cpu bit order.  */
-       tx->status = 0;
-       tx->data_rate = 0;
-       tx->tx_priority = index;
-       tx->qos_control = 0;
-       tx->rate_info = 0;
-       tx->peer_id = mwl8k_vif->peer_id;
-
-       amsduframe = !!(qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT);
-
-       /* Setup firmware control bit fields for each frame type.  */
-       if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)) {
-               tx->data_rate = 0;
-               qos = mwl8k_qos_setbit_eosp(qos);
-               /* Set Queue size to unspecified */
-               qos = mwl8k_qos_setbit_qlen(qos, 0xff);
-       } else if (ieee80211_is_data(fc)) {
-               tx->data_rate = 1;
-               if (mcframe)
-                       tx->status |= MWL8K_TXD_STATUS_MULTICAST_TX;
+       spin_lock_bh(&priv->tx_lock);
 
-               /*
-                * Tell firmware to not send EAPOL pkts in an
-                * aggregate.  Verify against mac80211 tx path.  If
-                * stack turns off AMPDU for an EAPOL frame this
-                * check will be removed.
-                */
-               if (eapolframe) {
-                       qos = mwl8k_qos_setbit_ack(qos,
-                               MWL8K_TXD_ACK_POLICY_NORMAL);
-               } else {
-                       /* Send pkt in an aggregate if AMPDU frame.  */
-                       if (ampduframe)
-                               qos = mwl8k_qos_setbit_ack(qos,
-                                       MWL8K_TXD_ACK_POLICY_BLOCKACK);
-                       else
-                               qos = mwl8k_qos_setbit_ack(qos,
-                                       MWL8K_TXD_ACK_POLICY_NORMAL);
+       txq = priv->txq + index;
 
-                       if (amsduframe)
-                               qos = mwl8k_qos_setbit_amsdu(qos);
-               }
-       }
+       BUG_ON(txq->tx_skb[txq->tx_tail] != NULL);
+       txq->tx_skb[txq->tx_tail] = skb;
 
-       /* Convert to little endian */
+       tx = txq->tx_desc_area + txq->tx_tail;
+       tx->data_rate = txdatarate;
+       tx->tx_priority = index;
        tx->qos_control = cpu_to_le16(qos);
-       tx->status = cpu_to_le32(tx->status);
        tx->pkt_phys_addr = cpu_to_le32(dma);
        tx->pkt_len = cpu_to_le16(skb->len);
-
-       txq->tx_skb[txq->tx_tail].skb = skb;
-       txq->tx_skb[txq->tx_tail].clone =
-               skb == org_skb ? NULL : org_skb;
-
-       spin_lock_bh(&priv->tx_lock);
-
-       tx->status = cpu_to_le32(MWL8K_TXD_STATUS_OK |
-                                       MWL8K_TXD_STATUS_FW_OWNED);
+       tx->rate_info = 0;
+       tx->peer_id = mwl8k_vif->peer_id;
        wmb();
+       tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
+
+       txq->tx_stats.count++;
        txq->tx_stats.len++;
        priv->pending_tx_pkts++;
-       txq->tx_stats.count++;
-       txq->tx_tail++;
 
+       txq->tx_tail++;
        if (txq->tx_tail == MWL8K_TX_DESCS)
                txq->tx_tail = 0;
+
        if (txq->tx_head == txq->tx_tail)
                ieee80211_stop_queue(hw, index);
 
-       if (priv->inconfig) {
-               /*
-                * Silently queue packet when we are in the middle of
-                * a config cycle.  Notify firmware only if we are
-                * waiting for TXQs to empty.  If a packet is sent
-                * before .config() is complete, perhaps it is better
-                * to drop the packet, as the channel is being changed
-                * and the packet will end up on the wrong channel.
-                */
-               printk(KERN_ERR "%s(): WARNING TX activity while "
-                       "in config\n", __func__);
-
-               if (priv->tx_wait != NULL)
-                       mwl8k_tx_start(priv);
-       } else
-               mwl8k_tx_start(priv);
+       mwl8k_tx_start(priv);
 
        spin_unlock_bh(&priv->tx_lock);
 
@@ -1507,6 +1359,60 @@ mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
 }
 
 
+/*
+ * Firmware access.
+ *
+ * We have the following requirements for issuing firmware commands:
+ * - Some commands require that the packet transmit path is idle when
+ *   the command is issued.  (For simplicity, we'll just quiesce the
+ *   transmit path for every command.)
+ * - There are certain sequences of commands that need to be issued to
+ *   the hardware sequentially, with no other intervening commands.
+ *
+ * This leads to an implementation of a "firmware lock" as a mutex that
+ * can be taken recursively, and which is taken by both the low-level
+ * command submission function (mwl8k_post_cmd) as well as any users of
+ * that function that require issuing of an atomic sequence of commands,
+ * and quiesces the transmit path whenever it's taken.
+ */
+static int mwl8k_fw_lock(struct ieee80211_hw *hw)
+{
+       struct mwl8k_priv *priv = hw->priv;
+
+       if (priv->fw_mutex_owner != current) {
+               int rc;
+
+               mutex_lock(&priv->fw_mutex);
+               ieee80211_stop_queues(hw);
+
+               rc = mwl8k_tx_wait_empty(hw);
+               if (rc) {
+                       ieee80211_wake_queues(hw);
+                       mutex_unlock(&priv->fw_mutex);
+
+                       return rc;
+               }
+
+               priv->fw_mutex_owner = current;
+       }
+
+       priv->fw_mutex_depth++;
+
+       return 0;
+}
+
+static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
+{
+       struct mwl8k_priv *priv = hw->priv;
+
+       if (!--priv->fw_mutex_depth) {
+               ieee80211_wake_queues(hw);
+               priv->fw_mutex_owner = NULL;
+               mutex_unlock(&priv->fw_mutex);
+       }
+}
+
+
 /*
  * Command processing.
  */
@@ -1522,7 +1428,6 @@ static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
        dma_addr_t dma_addr;
        unsigned int dma_size;
        int rc;
-       u16 __iomem *result;
        unsigned long timeout = 0;
        u8 buf[32];
 
@@ -1533,41 +1438,40 @@ static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
        if (pci_dma_mapping_error(priv->pdev, dma_addr))
                return -ENOMEM;
 
-       if (priv->hostcmd_wait != NULL)
-               printk(KERN_ERR "WARNING host command in progress\n");
+       rc = mwl8k_fw_lock(hw);
+       if (rc)
+               return rc;
 
-       spin_lock_irq(&priv->fw_lock);
        priv->hostcmd_wait = &cmd_wait;
        iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
        iowrite32(MWL8K_H2A_INT_DOORBELL,
                regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
        iowrite32(MWL8K_H2A_INT_DUMMY,
                regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
-       spin_unlock_irq(&priv->fw_lock);
 
        timeout = wait_for_completion_timeout(&cmd_wait,
                                msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
 
+       priv->hostcmd_wait = NULL;
+
+       mwl8k_fw_unlock(hw);
+
        pci_unmap_single(priv->pdev, dma_addr, dma_size,
                                        PCI_DMA_BIDIRECTIONAL);
 
-       result = &cmd->result;
        if (!timeout) {
-               spin_lock_irq(&priv->fw_lock);
-               priv->hostcmd_wait = NULL;
-               spin_unlock_irq(&priv->fw_lock);
                printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
                       priv->name,
                       mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
                       MWL8K_CMD_TIMEOUT_MS);
                rc = -ETIMEDOUT;
        } else {
-               rc = *result ? -EINVAL : 0;
+               rc = cmd->result ? -EINVAL : 0;
                if (rc)
                        printk(KERN_ERR "%s: Command %s error 0x%x\n",
                               priv->name,
                               mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
-                              *result);
+                              cmd->result);
        }
 
        return rc;
@@ -1638,41 +1542,44 @@ struct mwl8k_cmd_mac_multicast_adr {
        struct mwl8k_cmd_pkt header;
        __le16 action;
        __le16 numaddr;
-       __u8 addr[1][ETH_ALEN];
+       __u8 addr[0][ETH_ALEN];
 };
 
 #define MWL8K_ENABLE_RX_MULTICAST 0x000F
-static int mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw,
-                                       int mc_count,
-                                       struct dev_addr_list *mclist)
+
+static struct mwl8k_cmd_pkt *
+__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw,
+                             int mc_count, struct dev_addr_list *mclist)
 {
+       struct mwl8k_priv *priv = hw->priv;
        struct mwl8k_cmd_mac_multicast_adr *cmd;
-       int index = 0;
-       int rc;
-       int size = sizeof(*cmd) + ((mc_count - 1) * ETH_ALEN);
-       cmd = kzalloc(size, GFP_KERNEL);
+       int size;
+       int i;
+
+       if (mc_count > priv->num_mcaddrs)
+               mc_count = priv->num_mcaddrs;
+
+       size = sizeof(*cmd) + mc_count * ETH_ALEN;
+
+       cmd = kzalloc(size, GFP_ATOMIC);
        if (cmd == NULL)
-               return -ENOMEM;
+               return NULL;
 
        cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
        cmd->header.length = cpu_to_le16(size);
        cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
        cmd->numaddr = cpu_to_le16(mc_count);
-       while ((index < mc_count) && mclist) {
+
+       for (i = 0; i < mc_count && mclist; i++) {
                if (mclist->da_addrlen != ETH_ALEN) {
-                       rc = -EINVAL;
-                       goto mwl8k_cmd_mac_multicast_adr_exit;
+                       kfree(cmd);
+                       return NULL;
                }
-               memcpy(cmd->addr[index], mclist->da_addr, ETH_ALEN);
-               index++;
+               memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
                mclist = mclist->next;
        }
 
-       rc = mwl8k_post_cmd(hw, &cmd->header);
-
-mwl8k_cmd_mac_multicast_adr_exit:
-       kfree(cmd);
-       return rc;
+       return &cmd->header;
 }
 
 /*
@@ -1729,18 +1636,16 @@ struct mwl8k_cmd_802_11_radio_control {
        __le16 radio_on;
 } __attribute__((packed));
 
-static int mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, int enable)
+static int
+mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
 {
        struct mwl8k_priv *priv = hw->priv;
        struct mwl8k_cmd_802_11_radio_control *cmd;
        int rc;
 
-       if (((enable & MWL8K_RADIO_ENABLE) == priv->radio_state) &&
-           !(enable & MWL8K_RADIO_FORCE))
+       if (enable == priv->radio_on && !force)
                return 0;
 
-       enable &= MWL8K_RADIO_ENABLE;
-
        cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
        if (cmd == NULL)
                return -ENOMEM;
@@ -1748,18 +1653,28 @@ static int mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, int enable)
        cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
        cmd->header.length = cpu_to_le16(sizeof(*cmd));
        cmd->action = cpu_to_le16(MWL8K_CMD_SET);
-       cmd->control = cpu_to_le16(priv->radio_preamble);
+       cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
        cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
 
        rc = mwl8k_post_cmd(hw, &cmd->header);
        kfree(cmd);
 
        if (!rc)
-               priv->radio_state = enable;
+               priv->radio_on = enable;
 
        return rc;
 }
 
+static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw *hw)
+{
+       return mwl8k_cmd_802_11_radio_control(hw, 0, 0);
+}
+
+static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw *hw)
+{
+       return mwl8k_cmd_802_11_radio_control(hw, 1, 0);
+}
+
 static int
 mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
 {
@@ -1769,12 +1684,9 @@ mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
                return -EINVAL;
        priv = hw->priv;
 
-       priv->radio_preamble = (short_preamble ?
-               MWL8K_RADIO_SHORT_PREAMBLE :
-               MWL8K_RADIO_LONG_PREAMBLE);
+       priv->radio_short_preamble = short_preamble;
 
-       return mwl8k_cmd_802_11_radio_control(hw,
-                       MWL8K_RADIO_ENABLE | MWL8K_RADIO_FORCE);
+       return mwl8k_cmd_802_11_radio_control(hw, 1, 1);
 }
 
 /*
@@ -1846,7 +1758,7 @@ struct mwl8k_cmd_set_post_scan {
 } __attribute__((packed));
 
 static int
-mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 mac[ETH_ALEN])
+mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac)
 {
        struct mwl8k_cmd_set_post_scan *cmd;
        int rc;
@@ -1910,7 +1822,7 @@ struct mwl8k_cmd_set_slot {
        __u8 short_slot;
 } __attribute__((packed));
 
-static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, int slot_time)
+static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
 {
        struct mwl8k_cmd_set_slot *cmd;
        int rc;
@@ -1922,7 +1834,7 @@ static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, int slot_time)
        cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
        cmd->header.length = cpu_to_le16(sizeof(*cmd));
        cmd->action = cpu_to_le16(MWL8K_CMD_SET);
-       cmd->short_slot = slot_time == MWL8K_SHORT_SLOTTIME ? 1 : 0;
+       cmd->short_slot = short_slot_time;
 
        rc = mwl8k_post_cmd(hw, &cmd->header);
        kfree(cmd);
@@ -1980,7 +1892,7 @@ static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
 
        cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
        cmd->header.length = cpu_to_le16(sizeof(*cmd));
-       cmd->action = enable ? cpu_to_le32((u32)MWL8K_CMD_SET) : 0;
+       cmd->action = cpu_to_le32(!!enable);
 
        rc = mwl8k_post_cmd(hw, &cmd->header);
        kfree(cmd);
@@ -1989,7 +1901,7 @@ static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
 }
 
 /*
- * CMD_SET_RATE_ADAPT_MODE.
+ * CMD_SET_RATEADAPT_MODE.
  */
 struct mwl8k_cmd_set_rate_adapt_mode {
        struct mwl8k_cmd_pkt header;
@@ -2037,13 +1949,13 @@ static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable)
 
        cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
        cmd->header.length = cpu_to_le16(sizeof(*cmd));
-       cmd->action = enable ? cpu_to_le16(MWL8K_CMD_SET) : 0;
+       cmd->action = cpu_to_le16(!!enable);
 
        rc = mwl8k_post_cmd(hw, &cmd->header);
        kfree(cmd);
 
        if (!rc)
-               priv->wmm_mode = enable;
+               priv->wmm_enabled = enable;
 
        return rc;
 }
@@ -2117,22 +2029,18 @@ mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
                __u8 aifs, __u16 txop)
 {
        struct mwl8k_cmd_set_edca_params *cmd;
-       u32 log_cw_min, log_cw_max;
        int rc;
 
        cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
        if (cmd == NULL)
                return -ENOMEM;
 
-       log_cw_min = ilog2(cw_min+1);
-       log_cw_max = ilog2(cw_max+1);
        cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
        cmd->header.length = cpu_to_le16(sizeof(*cmd));
-
        cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
        cmd->txop = cpu_to_le16(txop);
-       cmd->log_cw_max = (u8)log_cw_max;
-       cmd->log_cw_min = (u8)log_cw_min;
+       cmd->log_cw_max = (u8)ilog2(cw_max + 1);
+       cmd->log_cw_min = (u8)ilog2(cw_min + 1);
        cmd->aifs = aifs;
        cmd->txq = qnum;
 
@@ -2173,11 +2081,7 @@ static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
 
        cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
        cmd->header.length = cpu_to_le16(sizeof(*cmd));
-
-       if (dtim)
-               cmd->sleep_interval = cpu_to_le32(dtim);
-       else
-               cmd->sleep_interval = cpu_to_le32(1);
+       cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
 
        hdrlen = ieee80211_hdrlen(payload->frame_control);
 
@@ -2189,8 +2093,8 @@ static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
                        "sent to firmware. Sz=%u MAX=%u\n", __func__,
                        payload_len, MWL8K_FJ_BEACON_MAXLEN);
 
-       payload_len = payload_len > MWL8K_FJ_BEACON_MAXLEN ?
-                               MWL8K_FJ_BEACON_MAXLEN : payload_len;
+       if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
+               payload_len = MWL8K_FJ_BEACON_MAXLEN;
 
        if (payload && payload_len)
                memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
@@ -2250,7 +2154,7 @@ static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw,
                peer_info->amsdu_enabled = 0;
 
                rates = peer_info->legacy_rates;
-               for (count = 0 ; count < mv_vif->legacy_nrates; count++)
+               for (count = 0; count < mv_vif->legacy_nrates; count++)
                        rates[count] = bitrates[count].hw_value;
 
                rc = mwl8k_post_cmd(hw, &cmd->header);
@@ -2313,8 +2217,6 @@ static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
 
        memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
 
-       prot_mode = MWL8K_FRAME_PROT_DISABLED;
-
        if (info->use_cts_prot) {
                prot_mode = MWL8K_FRAME_PROT_11G;
        } else {
@@ -2331,7 +2233,6 @@ static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
                        break;
                }
        }
-
        cmd->protection_mode = cpu_to_le16(prot_mode);
 
        for (count = 0; count < mv_vif->legacy_nrates; count++)
@@ -2489,17 +2390,14 @@ static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
        }
 
        if (status & MWL8K_A2H_INT_OPC_DONE) {
-               if (priv->hostcmd_wait != NULL) {
+               if (priv->hostcmd_wait != NULL)
                        complete(priv->hostcmd_wait);
-                       priv->hostcmd_wait = NULL;
-               }
        }
 
        if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
-               if (!priv->inconfig &&
-                       priv->radio_state &&
-                       mwl8k_txq_busy(priv))
-                               mwl8k_tx_start(priv);
+               if (!mutex_is_locked(&priv->fw_mutex) &&
+                   priv->radio_on && mwl8k_txq_busy(priv))
+                       mwl8k_tx_start(priv);
        }
 
        return IRQ_HANDLED;
@@ -2542,350 +2440,117 @@ struct mwl8k_work_struct {
 
        /* Result code.  */
        int rc;
-
-       /*
-        * Optional field. Refer to explanation of MWL8K_WQ_XXX_XXX
-        * flags for explanation.  Defaults to MWL8K_WQ_DEFAULT_OPTIONS.
-        */
-       u32 options;
-
-       /* Optional field.  Defaults to MWL8K_CONFIG_TIMEOUT_MS.  */
-       unsigned long timeout_ms;
-
-       /* Optional field.  Defaults to MWL8K_WQ_TXWAIT_ATTEMPTS.  */
-       u32 txwait_attempts;
-
-       /* Optional field.  Defaults to MWL8K_TXWAIT_MS.  */
-       u32 tx_timeout_ms;
-       u32 step;
 };
 
-/* Flags controlling behavior of config queue requests */
-
-/* Caller spins while waiting for completion.  */
-#define MWL8K_WQ_SPIN                  0x00000001
-
-/* Wait for TX queues to empty before proceeding with configuration.  */
-#define MWL8K_WQ_TX_WAIT_EMPTY         0x00000002
-
-/* Queue request and return immediately.  */
-#define MWL8K_WQ_POST_REQUEST          0x00000004
-
-/*
- * Caller sleeps and waits for task complete notification.
- * Do not use in atomic context.
- */
-#define MWL8K_WQ_SLEEP                 0x00000008
-
-/* Free work struct when task is done.  */
-#define MWL8K_WQ_FREE_WORKSTRUCT       0x00000010
-
-/*
- * Config request is queued and returns to caller imediately.  Use
- * this in atomic context. Work struct is freed by mwl8k_queue_work()
- * when this flag is set.
- */
-#define MWL8K_WQ_QUEUE_ONLY    (MWL8K_WQ_POST_REQUEST | \
-                                MWL8K_WQ_FREE_WORKSTRUCT)
-
-/* Default work queue behavior is to sleep and wait for tx completion.  */
-#define MWL8K_WQ_DEFAULT_OPTIONS (MWL8K_WQ_SLEEP | MWL8K_WQ_TX_WAIT_EMPTY)
-
-/*
- * Default config request timeout.  Add adjustments to make sure the
- * config thread waits long enough for both tx wait and cmd wait before
- * timing out.
- */
-
-/* Time to wait for all TXQs to drain.  TX Doorbell is pressed each time.  */
-#define MWL8K_TXWAIT_TIMEOUT_MS                1000
-
-/* Default number of TX wait attempts.  */
-#define MWL8K_WQ_TXWAIT_ATTEMPTS       4
-
-/* Total time to wait for TXQ to drain.  */
-#define MWL8K_TXWAIT_MS                        (MWL8K_TXWAIT_TIMEOUT_MS * \
-                                               MWL8K_WQ_TXWAIT_ATTEMPTS)
-
-/* Scheduling slop.  */
-#define MWL8K_OS_SCHEDULE_OVERHEAD_MS  200
-
-#define MWL8K_CONFIG_TIMEOUT_MS        (MWL8K_CMD_TIMEOUT_MS + \
-                                MWL8K_TXWAIT_MS + \
-                                MWL8K_OS_SCHEDULE_OVERHEAD_MS)
-
 static void mwl8k_config_thread(struct work_struct *wt)
 {
        struct mwl8k_work_struct *worker = (struct mwl8k_work_struct *)wt;
        struct ieee80211_hw *hw = worker->hw;
-       struct mwl8k_priv *priv = hw->priv;
        int rc = 0;
 
-       spin_lock_irq(&priv->tx_lock);
-       priv->inconfig = true;
-       spin_unlock_irq(&priv->tx_lock);
-
-       ieee80211_stop_queues(hw);
-
-       /*
-        * Wait for host queues to drain before doing PHY
-        * reconfiguration. This avoids interrupting any in-flight
-        * DMA transfers to the hardware.
-        */
-       if (worker->options & MWL8K_WQ_TX_WAIT_EMPTY) {
-               u32 timeout;
-               u32 time_remaining;
-               u32 iter;
-               u32 tx_wait_attempts = worker->txwait_attempts;
-
-               time_remaining = worker->tx_timeout_ms;
-               if (!tx_wait_attempts)
-                       tx_wait_attempts = 1;
-
-               timeout = worker->tx_timeout_ms/tx_wait_attempts;
-               if (!timeout)
-                       timeout = 1;
-
-               iter = tx_wait_attempts;
-               do {
-                       int wait_time;
-
-                       if (time_remaining > timeout) {
-                               time_remaining -= timeout;
-                               wait_time = timeout;
-                       } else
-                               wait_time = time_remaining;
-
-                       if (!wait_time)
-                               wait_time = 1;
-
-                       rc = mwl8k_tx_wait_empty(hw, wait_time);
-                       if (rc)
-                               printk(KERN_ERR "%s() txwait timeout=%ums "
-                                       "Retry:%u/%u\n", __func__, timeout,
-                                       tx_wait_attempts - iter + 1,
-                                       tx_wait_attempts);
-
-               } while (rc && --iter);
-
-               rc = iter ? 0 : -ETIMEDOUT;
-       }
-       if (!rc)
+       rc = mwl8k_fw_lock(hw);
+       if (!rc) {
                rc = worker->wfunc(wt);
-
-       spin_lock_irq(&priv->tx_lock);
-       priv->inconfig = false;
-       if (priv->pending_tx_pkts && priv->radio_state)
-               mwl8k_tx_start(priv);
-       spin_unlock_irq(&priv->tx_lock);
-       ieee80211_wake_queues(hw);
+               mwl8k_fw_unlock(hw);
+       }
 
        worker->rc = rc;
-       if (worker->options & MWL8K_WQ_SLEEP)
-               complete(worker->cmd_wait);
-
-       if (worker->options & MWL8K_WQ_FREE_WORKSTRUCT)
-               kfree(wt);
+       complete(worker->cmd_wait);
 }
 
 static int mwl8k_queue_work(struct ieee80211_hw *hw,
                                struct mwl8k_work_struct *worker,
-                               struct workqueue_struct *wqueue,
                                int (*wfunc)(struct work_struct *w))
 {
+       struct mwl8k_priv *priv = hw->priv;
        unsigned long timeout = 0;
        int rc = 0;
 
        DECLARE_COMPLETION_ONSTACK(cmd_wait);
 
-       if (!worker->timeout_ms)
-               worker->timeout_ms = MWL8K_CONFIG_TIMEOUT_MS;
-
-       if (!worker->options)
-               worker->options = MWL8K_WQ_DEFAULT_OPTIONS;
-
-       if (!worker->txwait_attempts)
-               worker->txwait_attempts = MWL8K_WQ_TXWAIT_ATTEMPTS;
-
-       if (!worker->tx_timeout_ms)
-               worker->tx_timeout_ms = MWL8K_TXWAIT_MS;
-
        worker->hw = hw;
        worker->cmd_wait = &cmd_wait;
        worker->rc = 1;
        worker->wfunc = wfunc;
 
        INIT_WORK(&worker->wt, mwl8k_config_thread);
-       queue_work(wqueue, &worker->wt);
-
-       if (worker->options & MWL8K_WQ_POST_REQUEST) {
-               rc = 0;
-       } else {
-               if (worker->options & MWL8K_WQ_SPIN) {
-                       timeout = worker->timeout_ms;
-                       while (timeout && (worker->rc > 0)) {
-                               mdelay(1);
-                               timeout--;
-                       }
-               } else if (worker->options & MWL8K_WQ_SLEEP)
-                       timeout = wait_for_completion_timeout(&cmd_wait,
-                               msecs_to_jiffies(worker->timeout_ms));
-
-               if (timeout)
-                       rc = worker->rc;
-               else {
-                       cancel_work_sync(&worker->wt);
-                       rc = -ETIMEDOUT;
-               }
-       }
-
-       return rc;
-}
-
-struct mwl8k_start_worker {
-       struct mwl8k_work_struct header;
-};
+       queue_work(priv->config_wq, &worker->wt);
 
-static int mwl8k_start_wt(struct work_struct *wt)
-{
-       struct mwl8k_start_worker *worker = (struct mwl8k_start_worker *)wt;
-       struct ieee80211_hw *hw = worker->header.hw;
-       struct mwl8k_priv *priv = hw->priv;
-       int rc = 0;
-
-       if (priv->vif != NULL) {
-               rc = -EIO;
-               goto mwl8k_start_exit;
-       }
-
-       /* Turn on radio */
-       if (mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_ENABLE)) {
-               rc = -EIO;
-               goto mwl8k_start_exit;
-       }
-
-       /* Purge TX/RX HW queues */
-       if (mwl8k_cmd_set_pre_scan(hw)) {
-               rc = -EIO;
-               goto mwl8k_start_exit;
-       }
-
-       if (mwl8k_cmd_set_post_scan(hw, "\x00\x00\x00\x00\x00\x00")) {
-               rc = -EIO;
-               goto mwl8k_start_exit;
-       }
-
-       /* Enable firmware rate adaptation */
-       if (mwl8k_cmd_setrateadaptmode(hw, 0)) {
-               rc = -EIO;
-               goto mwl8k_start_exit;
-       }
+       timeout = wait_for_completion_timeout(&cmd_wait,
+               msecs_to_jiffies(10000));
 
-       /* Disable WMM. WMM gets enabled when stack sends WMM parms */
-       if (mwl8k_set_wmm(hw, MWL8K_WMM_DISABLE)) {
-               rc = -EIO;
-               goto mwl8k_start_exit;
+       if (timeout)
+               rc = worker->rc;
+       else {
+               cancel_work_sync(&worker->wt);
+               rc = -ETIMEDOUT;
        }
 
-       /* Disable sniffer mode */
-       if (mwl8k_enable_sniffer(hw, 0))
-               rc = -EIO;
-
-mwl8k_start_exit:
        return rc;
 }
 
 static int mwl8k_start(struct ieee80211_hw *hw)
 {
-       struct mwl8k_start_worker *worker;
        struct mwl8k_priv *priv = hw->priv;
        int rc;
 
-       /* Enable tx reclaim tasklet */
-       tasklet_enable(&priv->tx_reclaim_task);
-
        rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
                         IRQF_SHARED, MWL8K_NAME, hw);
        if (rc) {
                printk(KERN_ERR "%s: failed to register IRQ handler\n",
                       priv->name);
-               rc = -EIO;
-               goto mwl8k_start_disable_tasklet;
+               return -EIO;
        }
 
+       /* Enable tx reclaim tasklet */
+       tasklet_enable(&priv->tx_reclaim_task);
+
        /* Enable interrupts */
        iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
 
-       worker = kzalloc(sizeof(*worker), GFP_KERNEL);
-       if (worker == NULL) {
-               rc = -ENOMEM;
-               goto mwl8k_start_disable_irq;
-       }
-
-       rc = mwl8k_queue_work(hw, &worker->header,
-                             priv->config_wq, mwl8k_start_wt);
-       kfree(worker);
-       if (!rc)
-               return rc;
-
-       if (rc == -ETIMEDOUT)
-               printk(KERN_ERR "%s() timed out\n", __func__);
+       rc = mwl8k_fw_lock(hw);
+       if (!rc) {
+               rc = mwl8k_cmd_802_11_radio_enable(hw);
 
-       rc = -EIO;
+               if (!rc)
+                       rc = mwl8k_cmd_set_pre_scan(hw);
 
-mwl8k_start_disable_irq:
-       spin_lock_irq(&priv->tx_lock);
-       iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
-       spin_unlock_irq(&priv->tx_lock);
-       free_irq(priv->pdev->irq, hw);
+               if (!rc)
+                       rc = mwl8k_cmd_set_post_scan(hw,
+                                       "\x00\x00\x00\x00\x00\x00");
 
-mwl8k_start_disable_tasklet:
-       tasklet_disable(&priv->tx_reclaim_task);
+               if (!rc)
+                       rc = mwl8k_cmd_setrateadaptmode(hw, 0);
 
-       return rc;
-}
+               if (!rc)
+                       rc = mwl8k_set_wmm(hw, 0);
 
-struct mwl8k_stop_worker {
-       struct mwl8k_work_struct header;
-};
+               if (!rc)
+                       rc = mwl8k_enable_sniffer(hw, 0);
 
-static int mwl8k_stop_wt(struct work_struct *wt)
-{
-       struct mwl8k_stop_worker *worker = (struct mwl8k_stop_worker *)wt;
-       struct ieee80211_hw *hw = worker->header.hw;
-       int rc;
+               mwl8k_fw_unlock(hw);
+       }
 
-       rc = mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_DISABLE);
+       if (rc) {
+               iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
+               free_irq(priv->pdev->irq, hw);
+               tasklet_disable(&priv->tx_reclaim_task);
+       }
 
        return rc;
 }
 
 static void mwl8k_stop(struct ieee80211_hw *hw)
 {
-       int rc;
-       struct mwl8k_stop_worker *worker;
        struct mwl8k_priv *priv = hw->priv;
        int i;
 
-       if (priv->vif != NULL)
-               return;
+       mwl8k_cmd_802_11_radio_disable(hw);
 
        ieee80211_stop_queues(hw);
 
-       worker = kzalloc(sizeof(*worker), GFP_KERNEL);
-       if (worker == NULL)
-               return;
-
-       rc = mwl8k_queue_work(hw, &worker->header,
-                             priv->config_wq, mwl8k_stop_wt);
-       kfree(worker);
-       if (rc == -ETIMEDOUT)
-               printk(KERN_ERR "%s() timed out\n", __func__);
-
        /* Disable interrupts */
-       spin_lock_irq(&priv->tx_lock);
        iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
-       spin_unlock_irq(&priv->tx_lock);
        free_irq(priv->pdev->irq, hw);
 
        /* Stop finalize join worker */
@@ -2919,8 +2584,7 @@ static int mwl8k_add_interface(struct ieee80211_hw *hw,
        /*
         * We only support managed interfaces for now.
         */
-       if (conf->type != NL80211_IFTYPE_STATION &&
-           conf->type != NL80211_IFTYPE_MONITOR)
+       if (conf->type != NL80211_IFTYPE_STATION)
                return -EINVAL;
 
        /* Clean out driver private area */
@@ -2934,7 +2598,7 @@ static int mwl8k_add_interface(struct ieee80211_hw *hw,
        mwl8k_vif->priv = priv;
 
        /* Setup initial PHY parameters */
-       memcpy(mwl8k_vif->legacy_rates ,
+       memcpy(mwl8k_vif->legacy_rates,
                priv->rates, sizeof(mwl8k_vif->legacy_rates));
        mwl8k_vif->legacy_nrates = ARRAY_SIZE(priv->rates);
 
@@ -2958,72 +2622,45 @@ static void mwl8k_remove_interface(struct ieee80211_hw *hw,
        priv->vif = NULL;
 }
 
-struct mwl8k_config_worker {
-       struct mwl8k_work_struct header;
-       u32 changed;
-};
-
-static int mwl8k_config_wt(struct work_struct *wt)
+static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
 {
-       struct mwl8k_config_worker *worker =
-               (struct mwl8k_config_worker *)wt;
-       struct ieee80211_hw *hw = worker->header.hw;
        struct ieee80211_conf *conf = &hw->conf;
        struct mwl8k_priv *priv = hw->priv;
-       int rc = 0;
+       int rc;
 
-       if (mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_ENABLE)) {
-               rc = -EINVAL;
-               goto mwl8k_config_exit;
+       if (conf->flags & IEEE80211_CONF_IDLE) {
+               mwl8k_cmd_802_11_radio_disable(hw);
+               priv->current_channel = NULL;
+               return 0;
        }
 
-       priv->current_channel = conf->channel;
+       rc = mwl8k_fw_lock(hw);
+       if (rc)
+               return rc;
 
-       if (mwl8k_cmd_set_rf_channel(hw, conf->channel)) {
-               rc = -EINVAL;
-               goto mwl8k_config_exit;
-       }
+       rc = mwl8k_cmd_802_11_radio_enable(hw);
+       if (rc)
+               goto out;
+
+       rc = mwl8k_cmd_set_rf_channel(hw, conf->channel);
+       if (rc)
+               goto out;
+
+       priv->current_channel = conf->channel;
 
        if (conf->power_level > 18)
                conf->power_level = 18;
-       if (mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level)) {
-               rc = -EINVAL;
-               goto mwl8k_config_exit;
-       }
+       rc = mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level);
+       if (rc)
+               goto out;
 
        if (mwl8k_cmd_mimo_config(hw, 0x7, 0x7))
                rc = -EINVAL;
 
-mwl8k_config_exit:
-       return rc;
-}
-
-static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
-{
-       int rc = 0;
-       struct mwl8k_config_worker *worker;
-       struct mwl8k_priv *priv = hw->priv;
-
-       worker = kzalloc(sizeof(*worker), GFP_KERNEL);
-       if (worker == NULL)
-               return -ENOMEM;
-
-       worker->changed = changed;
-       rc = mwl8k_queue_work(hw, &worker->header,
-                             priv->config_wq, mwl8k_config_wt);
-       if (rc == -ETIMEDOUT) {
-               printk(KERN_ERR "%s() timed out.\n", __func__);
-               rc = -EINVAL;
-       }
-
-       kfree(worker);
+out:
+       mwl8k_fw_unlock(hw);
 
-       /*
-        * mac80211 will crash on anything other than -EINVAL on
-        * error. Looks like wireless extensions which calls mac80211
-        * may be the actual culprit...
-        */
-       return rc ? -EINVAL : 0;
+       return rc;
 }
 
 struct mwl8k_bss_info_changed_worker {
@@ -3063,13 +2700,11 @@ static int mwl8k_bss_info_changed_wt(struct work_struct *wt)
                        goto mwl8k_bss_info_changed_exit;
 
                /* Set radio preamble */
-               if (mwl8k_set_radio_preamble(hw,
-                               info->use_short_preamble))
+               if (mwl8k_set_radio_preamble(hw, info->use_short_preamble))
                        goto mwl8k_bss_info_changed_exit;
 
                /* Set slot time */
-               if (mwl8k_cmd_set_slot(hw, info->use_short_slot ?
-                               MWL8K_SHORT_SLOTTIME : MWL8K_LONG_SLOTTIME))
+               if (mwl8k_cmd_set_slot(hw, info->use_short_slot))
                        goto mwl8k_bss_info_changed_exit;
 
                /* Update peer rate info */
@@ -3105,7 +2740,6 @@ static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
                                   u32 changed)
 {
        struct mwl8k_bss_info_changed_worker *worker;
-       struct mwl8k_priv *priv = hw->priv;
        struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
        int rc;
 
@@ -3122,20 +2756,27 @@ static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
        worker->vif = vif;
        worker->info = info;
        worker->changed = changed;
-       rc = mwl8k_queue_work(hw, &worker->header,
-                             priv->config_wq,
-                             mwl8k_bss_info_changed_wt);
+       rc = mwl8k_queue_work(hw, &worker->header, mwl8k_bss_info_changed_wt);
        kfree(worker);
        if (rc == -ETIMEDOUT)
                printk(KERN_ERR "%s() timed out\n", __func__);
 }
 
+static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
+                                  int mc_count, struct dev_addr_list *mclist)
+{
+       struct mwl8k_cmd_pkt *cmd;
+
+       cmd = __mwl8k_cmd_mac_multicast_adr(hw, mc_count, mclist);
+
+       return (unsigned long)cmd;
+}
+
 struct mwl8k_configure_filter_worker {
        struct mwl8k_work_struct header;
        unsigned int changed_flags;
-       unsigned int *total_flags;
-       int mc_count;
-       struct dev_addr_list *mclist;
+       unsigned int total_flags;
+       struct mwl8k_cmd_pkt *multicast_adr_cmd;
 };
 
 #define MWL8K_SUPPORTED_IF_FLAGS       FIF_BCN_PRBRESP_PROMISC
@@ -3144,18 +2785,12 @@ static int mwl8k_configure_filter_wt(struct work_struct *wt)
 {
        struct mwl8k_configure_filter_worker *worker =
                (struct mwl8k_configure_filter_worker *)wt;
-
        struct ieee80211_hw *hw = worker->header.hw;
-       unsigned int changed_flags = worker->changed_flags;
-       unsigned int *total_flags = worker->total_flags;
-       int mc_count = worker->mc_count;
-       struct dev_addr_list *mclist = worker->mclist;
-
        struct mwl8k_priv *priv = hw->priv;
        int rc = 0;
 
-       if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
-               if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
+       if (worker->changed_flags & FIF_BCN_PRBRESP_PROMISC) {
+               if (worker->total_flags & FIF_BCN_PRBRESP_PROMISC)
                        rc = mwl8k_cmd_set_pre_scan(hw);
                else {
                        u8 *bssid;
@@ -3168,53 +2803,19 @@ static int mwl8k_configure_filter_wt(struct work_struct *wt)
                }
        }
 
-       if (rc)
-               goto mwl8k_configure_filter_exit;
-       if (mc_count) {
-               mc_count = mc_count < priv->num_mcaddrs ?
-                               mc_count : priv->num_mcaddrs;
-               rc = mwl8k_cmd_mac_multicast_adr(hw, mc_count, mclist);
-               if (rc)
-                       printk(KERN_ERR
-                       "%s()Error setting multicast addresses\n",
-                       __func__);
-       }
+       if (!rc && worker->multicast_adr_cmd != NULL)
+               rc = mwl8k_post_cmd(hw, worker->multicast_adr_cmd);
+       kfree(worker->multicast_adr_cmd);
 
-mwl8k_configure_filter_exit:
        return rc;
 }
 
-static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
-                                  int mc_count, struct dev_addr_list *mclist)
-{
-       struct mwl8k_configure_filter_worker *worker;
-
-       worker = kzalloc(sizeof(*worker), GFP_ATOMIC);
-
-       if (!worker)
-               return 0;
-
-       /*
-        * XXX: This is _HORRIBLY_ broken!!
-        *
-        *      No locking, the mclist pointer might be invalid as soon as this
-        *      function returns, something in the list might be invalidated
-        *      once we get to the worker, etc...
-        */
-       worker->mc_count = mc_count;
-       worker->mclist = mclist;
-
-       return (u64)worker;
-}
-
 static void mwl8k_configure_filter(struct ieee80211_hw *hw,
                                   unsigned int changed_flags,
                                   unsigned int *total_flags,
                                   u64 multicast)
 {
-
-       struct mwl8k_configure_filter_worker *worker = (void *)multicast;
-       struct mwl8k_priv *priv = hw->priv;
+       struct mwl8k_configure_filter_worker *worker;
 
        /* Clear unsupported feature flags */
        *total_flags &= MWL8K_SUPPORTED_IF_FLAGS;
@@ -3222,15 +2823,15 @@ static void mwl8k_configure_filter(struct ieee80211_hw *hw,
        if (!(changed_flags & MWL8K_SUPPORTED_IF_FLAGS))
                return;
 
+       worker = kzalloc(sizeof(*worker), GFP_ATOMIC);
        if (worker == NULL)
                return;
 
-       worker->header.options = MWL8K_WQ_QUEUE_ONLY | MWL8K_WQ_TX_WAIT_EMPTY;
        worker->changed_flags = changed_flags;
-       worker->total_flags = total_flags;
+       worker->total_flags = *total_flags;
+       worker->multicast_adr_cmd = (void *)(unsigned long)multicast;
 
-       mwl8k_queue_work(hw, &worker->header, priv->config_wq,
-                        mwl8k_configure_filter_wt);
+       mwl8k_queue_work(hw, &worker->header, mwl8k_configure_filter_wt);
 }
 
 struct mwl8k_set_rts_threshold_worker {
@@ -3256,7 +2857,6 @@ static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
 {
        int rc;
        struct mwl8k_set_rts_threshold_worker *worker;
-       struct mwl8k_priv *priv = hw->priv;
 
        worker = kzalloc(sizeof(*worker), GFP_KERNEL);
        if (worker == NULL)
@@ -3264,9 +2864,7 @@ static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
 
        worker->value = value;
 
-       rc = mwl8k_queue_work(hw, &worker->header,
-                             priv->config_wq,
-                             mwl8k_set_rts_threshold_wt);
+       rc = mwl8k_queue_work(hw, &worker->header, mwl8k_set_rts_threshold_wt);
        kfree(worker);
 
        if (rc == -ETIMEDOUT) {
@@ -3295,10 +2893,11 @@ static int mwl8k_conf_tx_wt(struct work_struct *wt)
        struct mwl8k_priv *priv = hw->priv;
        int rc = 0;
 
-       if (priv->wmm_mode == MWL8K_WMM_DISABLE)
-               if (mwl8k_set_wmm(hw, MWL8K_WMM_ENABLE)) {
+       if (!priv->wmm_enabled) {
+               if (mwl8k_set_wmm(hw, 1)) {
                        rc = -EINVAL;
                        goto mwl8k_conf_tx_exit;
+               }
        }
 
        if (mwl8k_set_edca_params(hw, GET_TXQ(queue), params->cw_min,
@@ -3313,7 +2912,6 @@ static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
 {
        int rc;
        struct mwl8k_conf_tx_worker *worker;
-       struct mwl8k_priv *priv = hw->priv;
 
        worker = kzalloc(sizeof(*worker), GFP_KERNEL);
        if (worker == NULL)
@@ -3321,8 +2919,7 @@ static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
 
        worker->queue = queue;
        worker->params = params;
-       rc = mwl8k_queue_work(hw, &worker->header,
-                             priv->config_wq, mwl8k_conf_tx_wt);
+       rc = mwl8k_queue_work(hw, &worker->header, mwl8k_conf_tx_wt);
        kfree(worker);
        if (rc == -ETIMEDOUT) {
                printk(KERN_ERR "%s() timed out\n", __func__);
@@ -3366,15 +2963,13 @@ static int mwl8k_get_stats(struct ieee80211_hw *hw,
 {
        int rc;
        struct mwl8k_get_stats_worker *worker;
-       struct mwl8k_priv *priv = hw->priv;
 
        worker = kzalloc(sizeof(*worker), GFP_KERNEL);
        if (worker == NULL)
                return -ENOMEM;
 
        worker->stats = stats;
-       rc = mwl8k_queue_work(hw, &worker->header,
-                             priv->config_wq, mwl8k_get_stats_wt);
+       rc = mwl8k_queue_work(hw, &worker->header, mwl8k_get_stats_wt);
 
        kfree(worker);
        if (rc == -ETIMEDOUT) {
@@ -3411,12 +3006,9 @@ static void mwl8k_tx_reclaim_handler(unsigned long data)
        for (i = 0; i < MWL8K_TX_QUEUES; i++)
                mwl8k_txq_reclaim(hw, i, 0);
 
-       if (priv->tx_wait != NULL) {
-               int count = mwl8k_txq_busy(priv);
-               if (count == 0) {
-                       complete(priv->tx_wait);
-                       priv->tx_wait = NULL;
-               }
+       if (priv->tx_wait != NULL && mwl8k_txq_busy(priv) == 0) {
+               complete(priv->tx_wait);
+               priv->tx_wait = NULL;
        }
        spin_unlock_bh(&priv->tx_lock);
 }
@@ -3426,7 +3018,7 @@ static void mwl8k_finalize_join_worker(struct work_struct *work)
        struct mwl8k_priv *priv =
                container_of(work, struct mwl8k_priv, finalize_join_worker);
        struct sk_buff *skb = priv->beacon_skb;
-       u8 dtim = (MWL8K_VIF(priv->vif))->bss_info.dtim_period;
+       u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period;
 
        mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim);
        dev_kfree_skb(skb);
@@ -3469,15 +3061,10 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
        priv = hw->priv;
        priv->hw = hw;
        priv->pdev = pdev;
-       priv->hostcmd_wait = NULL;
-       priv->tx_wait = NULL;
-       priv->inconfig = false;
-       priv->wmm_mode = false;
+       priv->wmm_enabled = false;
        priv->pending_tx_pkts = 0;
        strncpy(priv->name, MWL8K_NAME, sizeof(priv->name));
 
-       spin_lock_init(&priv->fw_lock);
-
        SET_IEEE80211_DEV(hw, &pdev->dev);
        pci_set_drvdata(pdev, hw);
 
@@ -3509,17 +3096,16 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
 
        hw->queues = MWL8K_TX_QUEUES;
 
-       hw->wiphy->interface_modes =
-               BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_MONITOR);
+       hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
 
        /* Set rssi and noise values to dBm */
-       hw->flags |= (IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM);
+       hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
        hw->vif_data_size = sizeof(struct mwl8k_vif);
        priv->vif = NULL;
 
        /* Set default radio state and preamble */
-       priv->radio_preamble = MWL8K_RADIO_DEFAULT_PREAMBLE;
-       priv->radio_state = MWL8K_RADIO_DISABLE;
+       priv->radio_on = 0;
+       priv->radio_short_preamble = 0;
 
        /* Finalize join worker */
        INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
@@ -3544,6 +3130,12 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
                goto err_iounmap;
        rxq_refill(hw, 0, INT_MAX);
 
+       mutex_init(&priv->fw_mutex);
+       priv->fw_mutex_owner = NULL;
+       priv->fw_mutex_depth = 0;
+       priv->tx_wait = NULL;
+       priv->hostcmd_wait = NULL;
+
        spin_lock_init(&priv->tx_lock);
 
        for (i = 0; i < MWL8K_TX_QUEUES; i++) {
@@ -3600,16 +3192,14 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
        }
 
        /* Turn radio off */
-       rc = mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_DISABLE);
+       rc = mwl8k_cmd_802_11_radio_disable(hw);
        if (rc) {
                printk(KERN_ERR "%s: Cannot disable\n", priv->name);
                goto err_stop_firmware;
        }
 
        /* Disable interrupts */
-       spin_lock_irq(&priv->tx_lock);
        iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
-       spin_unlock_irq(&priv->tx_lock);
        free_irq(priv->pdev->irq, hw);
 
        rc = ieee80211_register_hw(hw);
@@ -3633,9 +3223,7 @@ err_stop_firmware:
        mwl8k_release_firmware(priv);
 
 err_free_irq:
-       spin_lock_irq(&priv->tx_lock);
        iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
-       spin_unlock_irq(&priv->tx_lock);
        free_irq(priv->pdev->irq, hw);
 
 err_free_queues: