]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
authorLinus Torvalds <torvalds@g5.osdl.org>
Wed, 9 Nov 2005 16:34:36 +0000 (08:34 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Wed, 9 Nov 2005 16:34:36 +0000 (08:34 -0800)
1  2 
drivers/net/Kconfig
drivers/net/b44.c
drivers/net/s2io.c
drivers/net/wireless/ipw2100.h
drivers/net/wireless/ipw2200.c
drivers/net/wireless/ipw2200.h
drivers/net/wireless/prism54/isl_38xx.c
drivers/net/wireless/prism54/islpci_eth.c

diff --combined drivers/net/Kconfig
index 24f1691b84f90d37b684acb665efc66a12f40d8f,e70315a85447c95b3cabb27b2587751ef5dbfd10..5c69d57f8548aa41b84f45e5cf2101fa80f47d64
@@@ -447,7 -447,7 +447,7 @@@ config NET_SB1250_MA
  
  config SGI_IOC3_ETH
        bool "SGI IOC3 Ethernet"
-       depends on NET_ETHERNET && PCI && SGI_IP27 && BROKEN
+       depends on NET_ETHERNET && PCI && SGI_IP27
        select CRC32
        select MII
        help
@@@ -2523,19 -2523,6 +2523,19 @@@ config PPP_BSDCOM
          module; it is called bsd_comp and will show up in the directory
          modules once you have said "make modules". If unsure, say N.
  
 +config PPP_MPPE
 +       tristate "PPP MPPE compression (encryption) (EXPERIMENTAL)"
 +       depends on PPP && EXPERIMENTAL
 +       select CRYPTO
 +       select CRYPTO_SHA1
 +       select CRYPTO_ARC4
 +       ---help---
 +         Support for the MPPE Encryption protocol, as employed by the
 +       Microsoft Point-to-Point Tunneling Protocol.
 +
 +       See http://pptpclient.sourceforge.net/ for information on
 +       configuring PPTP clients and servers to utilize this method.
 +
  config PPPOE
        tristate "PPP over Ethernet (EXPERIMENTAL)"
        depends on EXPERIMENTAL && PPP
diff --combined drivers/net/b44.c
index 819a17921cb999a48de593859870c59e1266b424,b38fa245a607f417c17cac0b645e7f906ab5a84a..c53848f787ebb600632d4f8b05964de4b7b919dd
@@@ -18,6 -18,7 +18,6 @@@
  #include <linux/pci.h>
  #include <linux/delay.h>
  #include <linux/init.h>
 -#include <linux/version.h>
  #include <linux/dma-mapping.h>
  
  #include <asm/uaccess.h>
@@@ -28,8 -29,8 +28,8 @@@
  
  #define DRV_MODULE_NAME               "b44"
  #define PFX DRV_MODULE_NAME   ": "
- #define DRV_MODULE_VERSION    "0.95"
- #define DRV_MODULE_RELDATE    "Aug 3, 2004"
+ #define DRV_MODULE_VERSION    "0.96"
+ #define DRV_MODULE_RELDATE    "Nov 8, 2005"
  
  #define B44_DEF_MSG_ENABLE      \
        (NETIF_MSG_DRV          | \
@@@ -101,14 -102,16 +101,16 @@@ MODULE_DEVICE_TABLE(pci, b44_pci_tbl)
  static void b44_halt(struct b44 *);
  static void b44_init_rings(struct b44 *);
  static void b44_init_hw(struct b44 *);
- static int b44_poll(struct net_device *dev, int *budget);
- #ifdef CONFIG_NET_POLL_CONTROLLER
- static void b44_poll_controller(struct net_device *dev);
- #endif
  
  static int dma_desc_align_mask;
  static int dma_desc_sync_size;
  
+ static const char b44_gstrings[][ETH_GSTRING_LEN] = {
+ #define _B44(x...)    # x,
+ B44_STAT_REG_DECLARE
+ #undef _B44
+ };
  static inline void b44_sync_dma_desc_for_device(struct pci_dev *pdev,
                                                  dma_addr_t dma_base,
                                                  unsigned long offset,
@@@ -501,7 -504,10 +503,10 @@@ static void b44_stats_update(struct b4
        for (reg = B44_TX_GOOD_O; reg <= B44_TX_PAUSE; reg += 4UL) {
                *val++ += br32(bp, reg);
        }
-       val = &bp->hw_stats.rx_good_octets;
+       /* Pad */
+       reg += 8*4UL;
        for (reg = B44_RX_GOOD_O; reg <= B44_RX_NPAUSE; reg += 4UL) {
                *val++ += br32(bp, reg);
        }
@@@ -652,7 -658,7 +657,7 @@@ static int b44_alloc_rx_skb(struct b44 
  
        /* Hardware bug work-around, the chip is unable to do PCI DMA
           to/from anything above 1GB :-( */
-       if(mapping+RX_PKT_BUF_SZ > B44_DMA_MASK) {
+       if (mapping + RX_PKT_BUF_SZ > B44_DMA_MASK) {
                /* Sigh... */
                pci_unmap_single(bp->pdev, mapping, RX_PKT_BUF_SZ,PCI_DMA_FROMDEVICE);
                dev_kfree_skb_any(skb);
                mapping = pci_map_single(bp->pdev, skb->data,
                                         RX_PKT_BUF_SZ,
                                         PCI_DMA_FROMDEVICE);
-               if(mapping+RX_PKT_BUF_SZ > B44_DMA_MASK) {
+               if (mapping + RX_PKT_BUF_SZ > B44_DMA_MASK) {
                        pci_unmap_single(bp->pdev, mapping, RX_PKT_BUF_SZ,PCI_DMA_FROMDEVICE);
                        dev_kfree_skb_any(skb);
                        return -ENOMEM;
@@@ -889,11 -895,10 +894,10 @@@ static irqreturn_t b44_interrupt(int ir
  {
        struct net_device *dev = dev_id;
        struct b44 *bp = netdev_priv(dev);
-       unsigned long flags;
        u32 istat, imask;
        int handled = 0;
  
-       spin_lock_irqsave(&bp->lock, flags);
+       spin_lock(&bp->lock);
  
        istat = br32(bp, B44_ISTAT);
        imask = br32(bp, B44_IMASK);
        istat &= imask;
        if (istat) {
                handled = 1;
+               if (unlikely(!netif_running(dev))) {
+                       printk(KERN_INFO "%s: late interrupt.\n", dev->name);
+                       goto irq_ack;
+               }
                if (netif_rx_schedule_prep(dev)) {
                        /* NOTE: These writes are posted by the readback of
                         *       the ISTAT register below.
                               dev->name);
                }
  
+ irq_ack:
                bw32(bp, B44_ISTAT, istat);
                br32(bp, B44_ISTAT);
        }
-       spin_unlock_irqrestore(&bp->lock, flags);
+       spin_unlock(&bp->lock);
        return IRQ_RETVAL(handled);
  }
  
@@@ -947,6 -959,7 +958,7 @@@ static int b44_start_xmit(struct sk_buf
  {
        struct b44 *bp = netdev_priv(dev);
        struct sk_buff *bounce_skb;
+       int rc = NETDEV_TX_OK;
        dma_addr_t mapping;
        u32 len, entry, ctrl;
  
        /* This is a hard error, log it. */
        if (unlikely(TX_BUFFS_AVAIL(bp) < 1)) {
                netif_stop_queue(dev);
-               spin_unlock_irq(&bp->lock);
                printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n",
                       dev->name);
-               return 1;
+               goto err_out;
        }
  
        mapping = pci_map_single(bp->pdev, skb->data, len, PCI_DMA_TODEVICE);
-       if(mapping+len > B44_DMA_MASK) {
+       if (mapping + len > B44_DMA_MASK) {
                /* Chip can't handle DMA to/from >1GB, use bounce buffer */
                pci_unmap_single(bp->pdev, mapping, len, PCI_DMA_TODEVICE);
  
                bounce_skb = __dev_alloc_skb(TX_PKT_BUF_SZ,
                                             GFP_ATOMIC|GFP_DMA);
                if (!bounce_skb)
-                       return NETDEV_TX_BUSY;
+                       goto err_out;
  
                mapping = pci_map_single(bp->pdev, bounce_skb->data,
                                         len, PCI_DMA_TODEVICE);
-               if(mapping+len > B44_DMA_MASK) {
+               if (mapping + len > B44_DMA_MASK) {
                        pci_unmap_single(bp->pdev, mapping,
                                         len, PCI_DMA_TODEVICE);
                        dev_kfree_skb_any(bounce_skb);
-                       return NETDEV_TX_BUSY;
+                       goto err_out;
                }
  
                memcpy(skb_put(bounce_skb, len), skb->data, skb->len);
        if (TX_BUFFS_AVAIL(bp) < 1)
                netif_stop_queue(dev);
  
+       dev->trans_start = jiffies;
+ out_unlock:
        spin_unlock_irq(&bp->lock);
  
-       dev->trans_start = jiffies;
+       return rc;
  
-       return 0;
+ err_out:
+       rc = NETDEV_TX_BUSY;
+       goto out_unlock;
  }
  
  static int b44_change_mtu(struct net_device *dev, int new_mtu)
@@@ -1096,8 -1113,7 +1112,7 @@@ static void b44_free_rings(struct b44 *
   *
   * The chip has been shut down and the driver detached from
   * the networking, so no interrupts or new tx packets will
-  * end up in the driver.  bp->lock is not held and we are not
-  * in an interrupt context and thus may sleep.
+  * end up in the driver.
   */
  static void b44_init_rings(struct b44 *bp)
  {
@@@ -1169,16 -1185,14 +1184,14 @@@ static int b44_alloc_consistent(struct 
        int size;
  
        size  = B44_RX_RING_SIZE * sizeof(struct ring_info);
-       bp->rx_buffers = kmalloc(size, GFP_KERNEL);
+       bp->rx_buffers = kzalloc(size, GFP_KERNEL);
        if (!bp->rx_buffers)
                goto out_err;
-       memset(bp->rx_buffers, 0, size);
  
        size = B44_TX_RING_SIZE * sizeof(struct ring_info);
-       bp->tx_buffers = kmalloc(size, GFP_KERNEL);
+       bp->tx_buffers = kzalloc(size, GFP_KERNEL);
        if (!bp->tx_buffers)
                goto out_err;
-       memset(bp->tx_buffers, 0, size);
  
        size = DMA_TABLE_BYTES;
        bp->rx_ring = pci_alloc_consistent(bp->pdev, size, &bp->rx_ring_dma);
                struct dma_desc *rx_ring;
                dma_addr_t rx_ring_dma;
  
-               if (!(rx_ring = (struct dma_desc *)kmalloc(size, GFP_KERNEL)))
+               rx_ring = kzalloc(size, GFP_KERNEL);
+               if (!rx_ring)
                        goto out_err;
  
-               memset(rx_ring, 0, size);
                rx_ring_dma = dma_map_single(&bp->pdev->dev, rx_ring,
                                             DMA_TABLE_BYTES,
                                             DMA_BIDIRECTIONAL);
                struct dma_desc *tx_ring;
                dma_addr_t tx_ring_dma;
  
-               if (!(tx_ring = (struct dma_desc *)kmalloc(size, GFP_KERNEL)))
+               tx_ring = kzalloc(size, GFP_KERNEL);
+               if (!tx_ring)
                        goto out_err;
  
-               memset(tx_ring, 0, size);
                tx_ring_dma = dma_map_single(&bp->pdev->dev, tx_ring,
                                             DMA_TABLE_BYTES,
                                             DMA_TO_DEVICE);
@@@ -1381,22 -1395,21 +1394,21 @@@ static int b44_open(struct net_device *
  
        err = b44_alloc_consistent(bp);
        if (err)
-               return err;
-       err = request_irq(dev->irq, b44_interrupt, SA_SHIRQ, dev->name, dev);
-       if (err)
-               goto err_out_free;
-       spin_lock_irq(&bp->lock);
+               goto out;
  
        b44_init_rings(bp);
        b44_init_hw(bp);
-       bp->flags |= B44_FLAG_INIT_COMPLETE;
  
        netif_carrier_off(dev);
        b44_check_phy(bp);
  
-       spin_unlock_irq(&bp->lock);
+       err = request_irq(dev->irq, b44_interrupt, SA_SHIRQ, dev->name, dev);
+       if (unlikely(err < 0)) {
+               b44_chip_reset(bp);
+               b44_free_rings(bp);
+               b44_free_consistent(bp);
+               goto out;
+       }
  
        init_timer(&bp->timer);
        bp->timer.expires = jiffies + HZ;
        add_timer(&bp->timer);
  
        b44_enable_ints(bp);
-       return 0;
- err_out_free:
-       b44_free_consistent(bp);
+ out:
        return err;
  }
  
@@@ -1444,6 -1453,8 +1452,8 @@@ static int b44_close(struct net_device 
  
        netif_stop_queue(dev);
  
+       netif_poll_disable(dev);
        del_timer_sync(&bp->timer);
  
        spin_lock_irq(&bp->lock);
  #endif
        b44_halt(bp);
        b44_free_rings(bp);
-       bp->flags &= ~B44_FLAG_INIT_COMPLETE;
        netif_carrier_off(bp->dev);
  
        spin_unlock_irq(&bp->lock);
  
        free_irq(dev->irq, dev);
  
+       netif_poll_enable(dev);
        b44_free_consistent(bp);
  
        return 0;
@@@ -1524,8 -1536,6 +1535,6 @@@ static void __b44_set_rx_mode(struct ne
  {
        struct b44 *bp = netdev_priv(dev);
        u32 val;
-       int i=0;
-       unsigned char zero[6] = {0,0,0,0,0,0};
  
        val = br32(bp, B44_RXCONFIG);
        val &= ~(RXCONFIG_PROMISC | RXCONFIG_ALLMULTI);
                val |= RXCONFIG_PROMISC;
                bw32(bp, B44_RXCONFIG, val);
        } else {
+               unsigned char zero[6] = {0, 0, 0, 0, 0, 0};
+               int i = 0;
                __b44_set_mac_addr(bp);
  
                if (dev->flags & IFF_ALLMULTI)
                        val |= RXCONFIG_ALLMULTI;
                else
-                       i=__b44_load_mcast(bp, dev);
+                       i = __b44_load_mcast(bp, dev);
                
-               for(;i<64;i++) {
+               for (; i < 64; i++) {
                        __b44_cam_write(bp, zero, i);                   
                }
                bw32(bp, B44_RXCONFIG, val);
@@@ -1604,7 -1617,7 +1616,7 @@@ static int b44_get_settings(struct net_
  {
        struct b44 *bp = netdev_priv(dev);
  
-       if (!(bp->flags & B44_FLAG_INIT_COMPLETE))
+       if (!netif_running(dev))
                return -EAGAIN;
        cmd->supported = (SUPPORTED_Autoneg);
        cmd->supported |= (SUPPORTED_100baseT_Half |
@@@ -1642,7 -1655,7 +1654,7 @@@ static int b44_set_settings(struct net_
  {
        struct b44 *bp = netdev_priv(dev);
  
-       if (!(bp->flags & B44_FLAG_INIT_COMPLETE))
+       if (!netif_running(dev))
                return -EAGAIN;
  
        /* We do not support gigabit. */
@@@ -1772,6 -1785,37 +1784,37 @@@ static int b44_set_pauseparam(struct ne
        return 0;
  }
  
+ static void b44_get_strings(struct net_device *dev, u32 stringset, u8 *data)
+ {
+       switch(stringset) {
+       case ETH_SS_STATS:
+               memcpy(data, *b44_gstrings, sizeof(b44_gstrings));
+               break;
+       }
+ }
+ static int b44_get_stats_count(struct net_device *dev)
+ {
+       return ARRAY_SIZE(b44_gstrings);
+ }
+ static void b44_get_ethtool_stats(struct net_device *dev,
+                                 struct ethtool_stats *stats, u64 *data)
+ {
+       struct b44 *bp = netdev_priv(dev);
+       u32 *val = &bp->hw_stats.tx_good_octets;
+       u32 i;
+       spin_lock_irq(&bp->lock);
+       b44_stats_update(bp);
+       for (i = 0; i < ARRAY_SIZE(b44_gstrings); i++)
+               *data++ = *val++;
+       spin_unlock_irq(&bp->lock);
+ }
  static struct ethtool_ops b44_ethtool_ops = {
        .get_drvinfo            = b44_get_drvinfo,
        .get_settings           = b44_get_settings,
        .set_pauseparam         = b44_set_pauseparam,
        .get_msglevel           = b44_get_msglevel,
        .set_msglevel           = b44_set_msglevel,
+       .get_strings            = b44_get_strings,
+       .get_stats_count        = b44_get_stats_count,
+       .get_ethtool_stats      = b44_get_ethtool_stats,
        .get_perm_addr          = ethtool_op_get_perm_addr,
  };
  
@@@ -1892,9 -1939,9 +1938,9 @@@ static int __devinit b44_init_one(struc
        
        err = pci_set_consistent_dma_mask(pdev, (u64) B44_DMA_MASK);
        if (err) {
-         printk(KERN_ERR PFX "No usable DMA configuration, "
-                "aborting.\n");
-         goto err_out_free_res;
+               printk(KERN_ERR PFX "No usable DMA configuration, "
+                      "aborting.\n");
+               goto err_out_free_res;
        }
  
        b44reg_base = pci_resource_start(pdev, 0);
        bp = netdev_priv(dev);
        bp->pdev = pdev;
        bp->dev = dev;
-       if (b44_debug >= 0)
-               bp->msg_enable = (1 << b44_debug) - 1;
-       else
-               bp->msg_enable = B44_DEF_MSG_ENABLE;
+       bp->msg_enable = netif_msg_init(b44_debug, B44_DEF_MSG_ENABLE);
  
        spin_lock_init(&bp->lock);
  
@@@ -2009,17 -2054,14 +2053,14 @@@ err_out_disable_pdev
  static void __devexit b44_remove_one(struct pci_dev *pdev)
  {
        struct net_device *dev = pci_get_drvdata(pdev);
+       struct b44 *bp = netdev_priv(dev);
  
-       if (dev) {
-               struct b44 *bp = netdev_priv(dev);
-               unregister_netdev(dev);
-               iounmap(bp->regs);
-               free_netdev(dev);
-               pci_release_regions(pdev);
-               pci_disable_device(pdev);
-               pci_set_drvdata(pdev, NULL);
-       }
+       unregister_netdev(dev);
+       iounmap(bp->regs);
+       free_netdev(dev);
+       pci_release_regions(pdev);
+       pci_disable_device(pdev);
+       pci_set_drvdata(pdev, NULL);
  }
  
  static int b44_suspend(struct pci_dev *pdev, pm_message_t state)
diff --combined drivers/net/s2io.c
index 8e41f4cea272fbd5dc00127b4113f698b9394589,24b7233a803c01dc0a1d0a66be0e8299597643e5..e57df8dfe6b4ec29b0c81b2f71d9c5809b1fa228
@@@ -55,6 -55,7 +55,6 @@@
  #include <linux/timex.h>
  #include <linux/sched.h>
  #include <linux/ethtool.h>
 -#include <linux/version.h>
  #include <linux/workqueue.h>
  #include <linux/if_vlan.h>
  
@@@ -1531,7 -1532,7 +1531,7 @@@ static int init_nic(struct s2io_nic *ni
  #define LINK_UP_DOWN_INTERRUPT                1
  #define MAC_RMAC_ERR_TIMER            2
  
- int s2io_link_fault_indication(nic_t *nic)
static int s2io_link_fault_indication(nic_t *nic)
  {
        if (nic->intr_type != INTA)
                return MAC_RMAC_ERR_TIMER;
@@@ -1863,7 -1864,7 +1863,7 @@@ static int verify_xena_quiescence(nic_
   *
   */
  
- void fix_mac_address(nic_t * sp)
static void fix_mac_address(nic_t * sp)
  {
        XENA_dev_config_t __iomem *bar0 = sp->bar0;
        u64 val64;
@@@ -2159,7 -2160,7 +2159,7 @@@ int fill_rxd_3buf(nic_t *nic, RxD_t *rx
   *  SUCCESS on success or an appropriate -ve value on failure.
   */
  
- int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
  {
        struct net_device *dev = nic->dev;
        struct sk_buff *skb;
@@@ -2830,7 -2831,7 +2830,7 @@@ static void alarm_intr_handler(struct s
   *   SUCCESS on success and FAILURE on failure.
   */
  
- int wait_for_cmd_complete(nic_t * sp)
static int wait_for_cmd_complete(nic_t * sp)
  {
        XENA_dev_config_t __iomem *bar0 = sp->bar0;
        int ret = FAILURE, cnt = 0;
@@@ -3076,7 -3077,7 +3076,7 @@@ int s2io_set_swapper(nic_t * sp
        return SUCCESS;
  }
  
- int wait_for_msix_trans(nic_t *nic, int i)
static int wait_for_msix_trans(nic_t *nic, int i)
  {
        XENA_dev_config_t *bar0 = (XENA_dev_config_t *) nic->bar0;
        u64 val64;
@@@ -3115,7 -3116,7 +3115,7 @@@ void restore_xmsi_data(nic_t *nic
        }
  }
  
- void store_xmsi_data(nic_t *nic)
static void store_xmsi_data(nic_t *nic)
  {
        XENA_dev_config_t *bar0 = (XENA_dev_config_t *) nic->bar0;
        u64 val64, addr, data;
@@@ -3287,7 -3288,7 +3287,7 @@@ int s2io_enable_msi_x(nic_t *nic
   *   file on failure.
   */
  
- int s2io_open(struct net_device *dev)
static int s2io_open(struct net_device *dev)
  {
        nic_t *sp = dev->priv;
        int err = 0;
@@@ -3417,7 -3418,7 +3417,7 @@@ hw_init_failed
   *  file on failure.
   */
  
- int s2io_close(struct net_device *dev)
static int s2io_close(struct net_device *dev)
  {
        nic_t *sp = dev->priv;
        int i;
   *  0 on success & 1 on failure.
   */
  
- int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
  {
        nic_t *sp = dev->priv;
        u16 frg_cnt, frg_len, i, queue, queue_len, put_off, get_off;
@@@ -3912,7 -3913,7 +3912,7 @@@ static void s2io_updt_stats(nic_t *sp
   *  pointer to the updated net_device_stats structure.
   */
  
- struct net_device_stats *s2io_get_stats(struct net_device *dev)
+ static struct net_device_stats *s2io_get_stats(struct net_device *dev)
  {
        nic_t *sp = dev->priv;
        mac_info_t *mac_control;
@@@ -5105,19 -5106,20 +5105,20 @@@ static void s2io_get_ethtool_stats(stru
        tmp_stats[i++] = stat_info->sw_stat.double_ecc_errs;
  }
  
- int s2io_ethtool_get_regs_len(struct net_device *dev)
static int s2io_ethtool_get_regs_len(struct net_device *dev)
  {
        return (XENA_REG_SPACE);
  }
  
  
- u32 s2io_ethtool_get_rx_csum(struct net_device * dev)
static u32 s2io_ethtool_get_rx_csum(struct net_device * dev)
  {
        nic_t *sp = dev->priv;
  
        return (sp->rx_csum);
  }
- int s2io_ethtool_set_rx_csum(struct net_device *dev, u32 data)
+ static int s2io_ethtool_set_rx_csum(struct net_device *dev, u32 data)
  {
        nic_t *sp = dev->priv;
  
  
        return 0;
  }
- int s2io_get_eeprom_len(struct net_device *dev)
+ static int s2io_get_eeprom_len(struct net_device *dev)
  {
        return (XENA_EEPROM_SPACE);
  }
  
- int s2io_ethtool_self_test_count(struct net_device *dev)
static int s2io_ethtool_self_test_count(struct net_device *dev)
  {
        return (S2IO_TEST_LEN);
  }
- void s2io_ethtool_get_strings(struct net_device *dev,
-                             u32 stringset, u8 * data)
+ static void s2io_ethtool_get_strings(struct net_device *dev,
+                                    u32 stringset, u8 * data)
  {
        switch (stringset) {
        case ETH_SS_TEST:
@@@ -5154,7 -5158,7 +5157,7 @@@ static int s2io_ethtool_get_stats_count
        return (S2IO_STAT_LEN);
  }
  
- int s2io_ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
static int s2io_ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
  {
        if (data)
                dev->features |= NETIF_F_IP_CSUM;
@@@ -5207,7 -5211,7 +5210,7 @@@ static struct ethtool_ops netdev_ethtoo
   *  function always return EOPNOTSUPPORTED
   */
  
- int s2io_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
static int s2io_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  {
        return -EOPNOTSUPP;
  }
   *   file on failure.
   */
  
- int s2io_change_mtu(struct net_device *dev, int new_mtu)
static int s2io_change_mtu(struct net_device *dev, int new_mtu)
  {
        nic_t *sp = dev->priv;
  
index 1f23650c077f3e96952e492ab0191d701bbcaca4,a1a9cbcf6c2f13f959cc21d3a2a53a016ba111ab..140fdf2a0a09a58afdcbe36658a07476c16474c4
@@@ -1,6 -1,6 +1,6 @@@
  /******************************************************************************
  
-   Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
+   Copyright(c) 2003 - 2004 Intel Corporation. All rights reserved.
  
    This program is free software; you can redistribute it and/or modify it
    under the terms of version 2 of the GNU General Public License as
@@@ -37,6 -37,7 +37,6 @@@
  #include <linux/socket.h>
  #include <linux/if_arp.h>
  #include <linux/wireless.h>
 -#include <linux/version.h>
  #include <net/iw_handler.h>   // new driver API
  
  #include <net/ieee80211.h>
@@@ -92,7 -93,6 +92,6 @@@ struct ipw2100_rx_packet
  #define IPW_DL_IOCTL         (1<<14)
  #define IPW_DL_RF_KILL       (1<<17)
  
  #define IPW_DL_MANAGE        (1<<15)
  #define IPW_DL_FW            (1<<16)
  
@@@ -155,7 -155,9 +154,9 @@@ extern const char *band_str[]
  
  struct bd_status {
        union {
-               struct { u8 nlf:1, txType:2, intEnabled:1, reserved:4;} fields;
+               struct {
+                       u8 nlf:1, txType:2, intEnabled:1, reserved:4;
+               } fields;
                u8 field;
        } info;
  } __attribute__ ((packed));
@@@ -164,7 -166,7 +165,7 @@@ struct ipw2100_bd 
        u32 host_addr;
        u32 buf_length;
        struct bd_status status;
-         /* number of fragments for frame (should be set only for
+       /* number of fragments for frame (should be set only for
         * 1st TBD) */
        u8 num_fragments;
        u8 reserved[6];
@@@ -292,10 -294,10 +293,10 @@@ struct ipw2100_cmd_header 
  struct ipw2100_data_header {
        u32 host_command_reg;
        u32 host_command_reg1;
-       u8 encrypted;   // BOOLEAN in win! TRUE if frame is enc by driver
+       u8 encrypted;           // BOOLEAN in win! TRUE if frame is enc by driver
        u8 needs_encryption;    // BOOLEAN in win! TRUE if frma need to be enc in NIC
        u8 wep_index;           // 0 no key, 1-4 key index, 0xff immediate key
-       u8 key_size;    // 0 no imm key, 0x5 64bit encr, 0xd 128bit encr, 0x10 128bit encr and 128bit IV
+       u8 key_size;            // 0 no imm key, 0x5 64bit encr, 0xd 128bit encr, 0x10 128bit encr and 128bit IV
        u8 key[16];
        u8 reserved[10];        // f/w reserved
        u8 src_addr[ETH_ALEN];
  
  /* Host command data structure */
  struct host_command {
-       u32 host_command;               // COMMAND ID
-       u32 host_command1;              // COMMAND ID
+       u32 host_command;       // COMMAND ID
+       u32 host_command1;      // COMMAND ID
        u32 host_command_sequence;      // UNIQUE COMMAND NUMBER (ID)
        u32 host_command_length;        // LENGTH
        u32 host_command_parameters[HOST_COMMAND_PARAMS_REG_LEN];       // COMMAND PARAMETERS
  } __attribute__ ((packed));
  
  typedef enum {
        POWER_ON_RESET,
        EXIT_POWER_DOWN_RESET,
@@@ -327,17 -328,16 +327,16 @@@ enum 
        RX
  };
  
  struct ipw2100_tx_packet {
        int type;
        int index;
        union {
-               struct { /* COMMAND */
-                       struct ipw2100_cmd_headercmd;
+               struct {        /* COMMAND */
+                       struct ipw2100_cmd_header *cmd;
                        dma_addr_t cmd_phys;
                } c_struct;
-               struct { /* DATA */
-                       struct ipw2100_data_headerdata;
+               struct {        /* DATA */
+                       struct ipw2100_data_header *data;
                        dma_addr_t data_phys;
                        struct ieee80211_txb *txb;
                } d_struct;
        struct list_head list;
  };
  
  struct ipw2100_rx_packet {
        struct ipw2100_rx *rxp;
        dma_addr_t dma_addr;
@@@ -431,13 -430,13 +429,13 @@@ enum 
  };
  
  #define STATUS_POWERED          (1<<0)
- #define STATUS_CMD_ACTIVE       (1<<1)  /**< host command in progress */
- #define STATUS_RUNNING          (1<<2)  /* Card initialized, but not enabled */
- #define STATUS_ENABLED          (1<<3)  /* Card enabled -- can scan,Tx,Rx */
- #define STATUS_STOPPING         (1<<4)  /* Card is in shutdown phase */
- #define STATUS_INITIALIZED      (1<<5)  /* Card is ready for external calls */
- #define STATUS_ASSOCIATING      (1<<9)  /* Associated, but no BSSID yet */
- #define STATUS_ASSOCIATED       (1<<10) /* Associated and BSSID valid */
+ #define STATUS_CMD_ACTIVE       (1<<1)        /**< host command in progress */
+ #define STATUS_RUNNING          (1<<2)        /* Card initialized, but not enabled */
+ #define STATUS_ENABLED          (1<<3)        /* Card enabled -- can scan,Tx,Rx */
+ #define STATUS_STOPPING         (1<<4)        /* Card is in shutdown phase */
+ #define STATUS_INITIALIZED      (1<<5)        /* Card is ready for external calls */
+ #define STATUS_ASSOCIATING      (1<<9)        /* Associated, but no BSSID yet */
+ #define STATUS_ASSOCIATED       (1<<10)       /* Associated and BSSID valid */
  #define STATUS_INT_ENABLED      (1<<11)
  #define STATUS_RF_KILL_HW       (1<<12)
  #define STATUS_RF_KILL_SW       (1<<13)
  #define STATUS_SCAN_COMPLETE    (1<<26)
  #define STATUS_WX_EVENT_PENDING (1<<27)
  #define STATUS_RESET_PENDING    (1<<29)
- #define STATUS_SECURITY_UPDATED (1<<30) /* Security sync needed */
+ #define STATUS_SECURITY_UPDATED (1<<30)       /* Security sync needed */
  
  /* Internal NIC states */
  #define IPW_STATE_INITIALIZED (1<<0)
  #define IPW_STATE_POWER_DOWN  (1<<10)
  #define IPW_STATE_SCANNING      (1<<11)
  
- #define CFG_STATIC_CHANNEL      (1<<0) /* Restrict assoc. to single channel */
- #define CFG_STATIC_ESSID        (1<<1) /* Restrict assoc. to single SSID */
- #define CFG_STATIC_BSSID        (1<<2) /* Restrict assoc. to single BSSID */
+ #define CFG_STATIC_CHANNEL      (1<<0)        /* Restrict assoc. to single channel */
+ #define CFG_STATIC_ESSID        (1<<1)        /* Restrict assoc. to single SSID */
+ #define CFG_STATIC_BSSID        (1<<2)        /* Restrict assoc. to single BSSID */
  #define CFG_CUSTOM_MAC          (1<<3)
  #define CFG_LONG_PREAMBLE       (1<<4)
  #define CFG_ASSOCIATE           (1<<6)
  #define CFG_ADHOC_CREATE        (1<<8)
  #define CFG_C3_DISABLED         (1<<9)
  #define CFG_PASSIVE_SCAN        (1<<10)
+ #ifdef CONFIG_IPW2100_MONITOR
+ #define CFG_CRC_CHECK           (1<<11)
+ #endif
  
- #define CAP_SHARED_KEY          (1<<0) /* Off = OPEN */
- #define CAP_PRIVACY_ON          (1<<1) /* Off = No privacy */
+ #define CAP_SHARED_KEY          (1<<0)        /* Off = OPEN */
+ #define CAP_PRIVACY_ON          (1<<1)        /* Off = No privacy */
  
  struct ipw2100_priv {
  
-       int stop_hang_check; /* Set 1 when shutting down to kill hang_check */
-       int stop_rf_kill; /* Set 1 when shutting down to kill rf_kill */
+       int stop_hang_check;    /* Set 1 when shutting down to kill hang_check */
+       int stop_rf_kill;       /* Set 1 when shutting down to kill rf_kill */
  
        struct ieee80211_device *ieee;
        unsigned long status;
        unsigned long hw_features;
        int hangs;
        u32 last_rtc;
-       int dump_raw; /* 1 to dump raw bytes in /sys/.../memory */
-       u8snapshot[0x30];
+       int dump_raw;           /* 1 to dump raw bytes in /sys/.../memory */
+       u8 *snapshot[0x30];
  
        u8 mandatory_bssid_mac[ETH_ALEN];
        u8 mac_addr[ETH_ALEN];
  
        int power_mode;
  
-       /* WEP data */
-       struct ieee80211_security sec;
        int messages_sent;
  
        int short_retry_limit;
        int long_retry_limit;
  
        wait_queue_head_t wait_command_queue;
  };
  
  /*********************************************************
   * Host Command -> From Driver to FW
   *********************************************************/
  #define CARD_DISABLE_PHY_OFF   61
  #define MSDU_TX_RATES          62
  
  /* Rogue AP Detection */
  #define SET_STATION_STAT_BITS      64
  #define CLEAR_STATIONS_STAT_BITS   65
  #define DISASSOCIATION_BSSID     68
  #define SET_WPA_IE                 69
  
  /* system configuration bit mask: */
  #define IPW_CFG_MONITOR               0x00004
  #define IPW_CFG_PREAMBLE_AUTO        0x00010
  #define IPW2100_INTA_TX_TRANSFER               (0x00000001)   // Bit 0 (LSB)
  #define IPW2100_INTA_RX_TRANSFER               (0x00000002)   // Bit 1
  #define IPW2100_INTA_TX_COMPLETE             (0x00000004)     // Bit 2
- #define IPW2100_INTA_EVENT_INTERRUPT           (0x00000008)     // Bit 3
+ #define IPW2100_INTA_EVENT_INTERRUPT           (0x00000008)   // Bit 3
  #define IPW2100_INTA_STATUS_CHANGE             (0x00000010)   // Bit 4
  #define IPW2100_INTA_BEACON_PERIOD_EXPIRED     (0x00000020)   // Bit 5
  #define IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE  (0x00010000)       // Bit 16
  #define IPW_CARD_DISABLE_PHY_OFF_COMPLETE_WAIT            100 // 100 milli
  #define IPW_PREPARE_POWER_DOWN_COMPLETE_WAIT      100 // 100 milli
  
  #define IPW_HEADER_802_11_SIZE                 sizeof(struct ieee80211_hdr_3addr)
  #define IPW_MAX_80211_PAYLOAD_SIZE              2304U
  #define IPW_MAX_802_11_PAYLOAD_LENGTH         2312
@@@ -842,8 -830,8 +829,8 @@@ struct ipw2100_rx 
  #define IPW_TX_POWER_MIN_DBM         (-12)
  #define IPW_TX_POWER_MAX_DBM         16
  
- #define FW_SCAN_DONOT_ASSOCIATE     0x0001 // Dont Attempt to Associate after Scan
- #define FW_SCAN_PASSIVE             0x0008 // Force PASSSIVE Scan
+ #define FW_SCAN_DONOT_ASSOCIATE     0x0001    // Dont Attempt to Associate after Scan
+ #define FW_SCAN_PASSIVE             0x0008    // Force PASSSIVE Scan
  
  #define REG_MIN_CHANNEL             0
  #define REG_MAX_CHANNEL             14
  #define DIVERSITY_ANTENNA_A         1 // Use antenna A
  #define DIVERSITY_ANTENNA_B         2 // Use antenna B
  
  #define HOST_COMMAND_WAIT 0
  #define HOST_COMMAND_NO_WAIT 1
  
  #define TYPE_ASSOCIATION_REQUEST      0x0013
  #define TYPE_REASSOCIATION_REQUEST    0x0014
  
- #define HW_FEATURE_RFKILL (0x0001)
- #define RF_KILLSWITCH_OFF (1)
- #define RF_KILLSWITCH_ON  (0)
+ #define HW_FEATURE_RFKILL 0x0001
+ #define RF_KILLSWITCH_OFF 1
+ #define RF_KILLSWITCH_ON  0
  
  #define IPW_COMMAND_POOL_SIZE        40
  
  // Fixed size data: Ordinal Table 1
  typedef enum _ORDINAL_TABLE_1 {       // NS - means Not Supported by FW
  // Transmit statistics
-       IPW_ORD_STAT_TX_HOST_REQUESTS = 1,// # of requested Host Tx's (MSDU)
+       IPW_ORD_STAT_TX_HOST_REQUESTS = 1,      // # of requested Host Tx's (MSDU)
        IPW_ORD_STAT_TX_HOST_COMPLETE,  // # of successful Host Tx's (MSDU)
        IPW_ORD_STAT_TX_DIR_DATA,       // # of successful Directed Tx's (MSDU)
  
        IPW_ORD_STAT_TX_DIR_DATA11,     // # of successful Directed Tx's (MSDU) @ 11MB
        IPW_ORD_STAT_TX_DIR_DATA22,     // # of successful Directed Tx's (MSDU) @ 22MB
  
-       IPW_ORD_STAT_TX_NODIR_DATA1 = 13,// # of successful Non_Directed Tx's (MSDU) @ 1MB
+       IPW_ORD_STAT_TX_NODIR_DATA1 = 13,       // # of successful Non_Directed Tx's (MSDU) @ 1MB
        IPW_ORD_STAT_TX_NODIR_DATA2,    // # of successful Non_Directed Tx's (MSDU) @ 2MB
        IPW_ORD_STAT_TX_NODIR_DATA5_5,  // # of successful Non_Directed Tx's (MSDU) @ 5.5MB
        IPW_ORD_STAT_TX_NODIR_DATA11,   // # of successful Non_Directed Tx's (MSDU) @ 11MB
  
        IPW_ORD_STAT_NULL_DATA = 21,    // # of successful NULL data Tx's
-       IPW_ORD_STAT_TX_RTS,            // # of successful Tx RTS
-       IPW_ORD_STAT_TX_CTS,            // # of successful Tx CTS
-       IPW_ORD_STAT_TX_ACK,            // # of successful Tx ACK
-       IPW_ORD_STAT_TX_ASSN,           // # of successful Association Tx's
+       IPW_ORD_STAT_TX_RTS,    // # of successful Tx RTS
+       IPW_ORD_STAT_TX_CTS,    // # of successful Tx CTS
+       IPW_ORD_STAT_TX_ACK,    // # of successful Tx ACK
+       IPW_ORD_STAT_TX_ASSN,   // # of successful Association Tx's
        IPW_ORD_STAT_TX_ASSN_RESP,      // # of successful Association response Tx's
-       IPW_ORD_STAT_TX_REASSN,         // # of successful Reassociation Tx's
+       IPW_ORD_STAT_TX_REASSN, // # of successful Reassociation Tx's
        IPW_ORD_STAT_TX_REASSN_RESP,    // # of successful Reassociation response Tx's
-       IPW_ORD_STAT_TX_PROBE,          // # of probes successfully transmitted
+       IPW_ORD_STAT_TX_PROBE,  // # of probes successfully transmitted
        IPW_ORD_STAT_TX_PROBE_RESP,     // # of probe responses successfully transmitted
-       IPW_ORD_STAT_TX_BEACON,         // # of tx beacon
-       IPW_ORD_STAT_TX_ATIM,           // # of Tx ATIM
+       IPW_ORD_STAT_TX_BEACON, // # of tx beacon
+       IPW_ORD_STAT_TX_ATIM,   // # of Tx ATIM
        IPW_ORD_STAT_TX_DISASSN,        // # of successful Disassociation TX
-       IPW_ORD_STAT_TX_AUTH,           // # of successful Authentication Tx
-       IPW_ORD_STAT_TX_DEAUTH,         // # of successful Deauthentication TX
+       IPW_ORD_STAT_TX_AUTH,   // # of successful Authentication Tx
+       IPW_ORD_STAT_TX_DEAUTH, // # of successful Deauthentication TX
  
-       IPW_ORD_STAT_TX_TOTAL_BYTES = 41,// Total successful Tx data bytes
-       IPW_ORD_STAT_TX_RETRIES,         // # of Tx retries
-       IPW_ORD_STAT_TX_RETRY1,          // # of Tx retries at 1MBPS
-       IPW_ORD_STAT_TX_RETRY2,          // # of Tx retries at 2MBPS
-       IPW_ORD_STAT_TX_RETRY5_5,        // # of Tx retries at 5.5MBPS
-       IPW_ORD_STAT_TX_RETRY11,         // # of Tx retries at 11MBPS
+       IPW_ORD_STAT_TX_TOTAL_BYTES = 41,       // Total successful Tx data bytes
+       IPW_ORD_STAT_TX_RETRIES,        // # of Tx retries
+       IPW_ORD_STAT_TX_RETRY1, // # of Tx retries at 1MBPS
+       IPW_ORD_STAT_TX_RETRY2, // # of Tx retries at 2MBPS
+       IPW_ORD_STAT_TX_RETRY5_5,       // # of Tx retries at 5.5MBPS
+       IPW_ORD_STAT_TX_RETRY11,        // # of Tx retries at 11MBPS
  
        IPW_ORD_STAT_TX_FAILURES = 51,  // # of Tx Failures
        IPW_ORD_STAT_TX_ABORT_AT_HOP,   //NS // # of Tx's aborted at hop time
-       IPW_ORD_STAT_TX_MAX_TRIES_IN_HOP,// # of times max tries in a hop failed
+       IPW_ORD_STAT_TX_MAX_TRIES_IN_HOP,       // # of times max tries in a hop failed
        IPW_ORD_STAT_TX_ABORT_LATE_DMA, //NS // # of times tx aborted due to late dma setup
        IPW_ORD_STAT_TX_ABORT_STX,      //NS // # of times backoff aborted
        IPW_ORD_STAT_TX_DISASSN_FAIL,   // # of times disassociation failed
-       IPW_ORD_STAT_TX_ERR_CTS,         // # of missed/bad CTS frames
-       IPW_ORD_STAT_TX_BPDU,           //NS // # of spanning tree BPDUs sent
+       IPW_ORD_STAT_TX_ERR_CTS,        // # of missed/bad CTS frames
+       IPW_ORD_STAT_TX_BPDU,   //NS // # of spanning tree BPDUs sent
        IPW_ORD_STAT_TX_ERR_ACK,        // # of tx err due to acks
  
        // Receive statistics
        IPW_ORD_STAT_RX_DIR_DATA11,     // # of directed packets at 11MB
        IPW_ORD_STAT_RX_DIR_DATA22,     // # of directed packets at 22MB
  
-       IPW_ORD_STAT_RX_NODIR_DATA = 71,// # of nondirected packets
+       IPW_ORD_STAT_RX_NODIR_DATA = 71,        // # of nondirected packets
        IPW_ORD_STAT_RX_NODIR_DATA1,    // # of nondirected packets at 1MB
        IPW_ORD_STAT_RX_NODIR_DATA2,    // # of nondirected packets at 2MB
        IPW_ORD_STAT_RX_NODIR_DATA5_5,  // # of nondirected packets at 5.5MB
        IPW_ORD_STAT_RX_AUTH,   // # of authentication Rx
        IPW_ORD_STAT_RX_DEAUTH, // # of deauthentication Rx
  
-       IPW_ORD_STAT_RX_TOTAL_BYTES = 101,// Total rx data bytes received
-       IPW_ORD_STAT_RX_ERR_CRC,         // # of packets with Rx CRC error
-       IPW_ORD_STAT_RX_ERR_CRC1,        // # of Rx CRC errors at 1MB
-       IPW_ORD_STAT_RX_ERR_CRC2,        // # of Rx CRC errors at 2MB
-       IPW_ORD_STAT_RX_ERR_CRC5_5,      // # of Rx CRC errors at 5.5MB
-       IPW_ORD_STAT_RX_ERR_CRC11,       // # of Rx CRC errors at 11MB
+       IPW_ORD_STAT_RX_TOTAL_BYTES = 101,      // Total rx data bytes received
+       IPW_ORD_STAT_RX_ERR_CRC,        // # of packets with Rx CRC error
+       IPW_ORD_STAT_RX_ERR_CRC1,       // # of Rx CRC errors at 1MB
+       IPW_ORD_STAT_RX_ERR_CRC2,       // # of Rx CRC errors at 2MB
+       IPW_ORD_STAT_RX_ERR_CRC5_5,     // # of Rx CRC errors at 5.5MB
+       IPW_ORD_STAT_RX_ERR_CRC11,      // # of Rx CRC errors at 11MB
  
-       IPW_ORD_STAT_RX_DUPLICATE1 = 112, // # of duplicate rx packets at 1MB
-       IPW_ORD_STAT_RX_DUPLICATE2,      // # of duplicate rx packets at 2MB
-       IPW_ORD_STAT_RX_DUPLICATE5_5,    // # of duplicate rx packets at 5.5MB
-       IPW_ORD_STAT_RX_DUPLICATE11,     // # of duplicate rx packets at 11MB
-       IPW_ORD_STAT_RX_DUPLICATE = 119, // # of duplicate rx packets
+       IPW_ORD_STAT_RX_DUPLICATE1 = 112,       // # of duplicate rx packets at 1MB
+       IPW_ORD_STAT_RX_DUPLICATE2,     // # of duplicate rx packets at 2MB
+       IPW_ORD_STAT_RX_DUPLICATE5_5,   // # of duplicate rx packets at 5.5MB
+       IPW_ORD_STAT_RX_DUPLICATE11,    // # of duplicate rx packets at 11MB
+       IPW_ORD_STAT_RX_DUPLICATE = 119,        // # of duplicate rx packets
  
        IPW_ORD_PERS_DB_LOCK = 120,     // # locking fw permanent  db
        IPW_ORD_PERS_DB_SIZE,   // # size of fw permanent  db
        IPW_ORD_STAT_RX_ICV_ERRORS,     // # of ICV errors during decryption
  
  // PSP Statistics
-       IPW_ORD_STAT_PSP_SUSPENSION = 137,// # of times adapter suspended
+       IPW_ORD_STAT_PSP_SUSPENSION = 137,      // # of times adapter suspended
        IPW_ORD_STAT_PSP_BCN_TIMEOUT,   // # of beacon timeout
        IPW_ORD_STAT_PSP_POLL_TIMEOUT,  // # of poll response timeouts
-       IPW_ORD_STAT_PSP_NONDIR_TIMEOUT,// # of timeouts waiting for last broadcast/muticast pkt
+       IPW_ORD_STAT_PSP_NONDIR_TIMEOUT,        // # of timeouts waiting for last broadcast/muticast pkt
        IPW_ORD_STAT_PSP_RX_DTIMS,      // # of PSP DTIMs received
        IPW_ORD_STAT_PSP_RX_TIMS,       // # of PSP TIMs received
        IPW_ORD_STAT_PSP_STATION_ID,    // PSP Station ID
  
  // Association and roaming
        IPW_ORD_LAST_ASSN_TIME = 147,   // RTC time of last association
-       IPW_ORD_STAT_PERCENT_MISSED_BCNS,// current calculation of % missed beacons
+       IPW_ORD_STAT_PERCENT_MISSED_BCNS,       // current calculation of % missed beacons
        IPW_ORD_STAT_PERCENT_RETRIES,   // current calculation of % missed tx retries
        IPW_ORD_ASSOCIATED_AP_PTR,      // If associated, this is ptr to the associated
        // AP table entry. set to 0 if not associated
@@@ -1150,7 -1136,7 +1135,7 @@@ struct ipw2100_fw_chunk 
  };
  
  struct ipw2100_fw_chunk_set {
-       const void *data;
+       const void *data;
        unsigned long size;
  };
  
@@@ -1163,4 -1149,4 +1148,4 @@@ struct ipw2100_fw 
  
  #define MAX_FW_VERSION_LEN 14
  
- #endif /* _IPW2100_H */
+ #endif                                /* _IPW2100_H */
index 589aef8ba4e67f766f3b8440ea553816442836c3,136884cef9084b33b1058323cecea93bce605e1a..b0d195d1721a6b490107c864043596d0a0768d10
@@@ -1,6 -1,6 +1,6 @@@
  /******************************************************************************
  
-   Copyright(c) 2003 - 2004 Intel Corporation. All rights reserved.
+   Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
  
    802.11 status code portion of this file from ethereal-0.10.6:
      Copyright 2000, Axis Communications AB
  ******************************************************************************/
  
  #include "ipw2200.h"
 +#include <linux/version.h>
  
- #define IPW2200_VERSION "1.0.0"
+ #define IPW2200_VERSION "git-1.0.8"
  #define DRV_DESCRIPTION       "Intel(R) PRO/Wireless 2200/2915 Network Driver"
- #define DRV_COPYRIGHT "Copyright(c) 2003-2004 Intel Corporation"
+ #define DRV_COPYRIGHT "Copyright(c) 2003-2005 Intel Corporation"
  #define DRV_VERSION     IPW2200_VERSION
  
+ #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
  MODULE_DESCRIPTION(DRV_DESCRIPTION);
  MODULE_VERSION(DRV_VERSION);
  MODULE_AUTHOR(DRV_COPYRIGHT);
  MODULE_LICENSE("GPL");
  
+ static int cmdlog = 0;
  static int debug = 0;
  static int channel = 0;
- static char *ifname;
  static int mode = 0;
  
  static u32 ipw_debug_level;
  static int associate = 1;
  static int auto_create = 1;
+ static int led = 0;
  static int disable = 0;
+ static int hwcrypto = 1;
  static const char ipw_modes[] = {
        'a', 'b', 'g', '?'
  };
  
+ #ifdef CONFIG_IPW_QOS
+ static int qos_enable = 0;
+ static int qos_burst_enable = 0;
+ static int qos_no_ack_mask = 0;
+ static int burst_duration_CCK = 0;
+ static int burst_duration_OFDM = 0;
+ static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
+       {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
+        QOS_TX3_CW_MIN_OFDM},
+       {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
+        QOS_TX3_CW_MAX_OFDM},
+       {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
+       {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
+       {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
+        QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
+ };
+ static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
+       {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
+        QOS_TX3_CW_MIN_CCK},
+       {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
+        QOS_TX3_CW_MAX_CCK},
+       {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
+       {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
+       {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
+        QOS_TX3_TXOP_LIMIT_CCK}
+ };
+ static struct ieee80211_qos_parameters def_parameters_OFDM = {
+       {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
+        DEF_TX3_CW_MIN_OFDM},
+       {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
+        DEF_TX3_CW_MAX_OFDM},
+       {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
+       {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
+       {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
+        DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
+ };
+ static struct ieee80211_qos_parameters def_parameters_CCK = {
+       {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
+        DEF_TX3_CW_MIN_CCK},
+       {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
+        DEF_TX3_CW_MAX_CCK},
+       {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
+       {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
+       {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
+        DEF_TX3_TXOP_LIMIT_CCK}
+ };
+ static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
+ static int from_priority_to_tx_queue[] = {
+       IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
+       IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
+ };
+ static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
+ static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
+                                      *qos_param);
+ static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
+                                    *qos_param);
+ #endif                                /* CONFIG_IPW_QOS */
+ static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
+ static void ipw_remove_current_network(struct ipw_priv *priv);
  static void ipw_rx(struct ipw_priv *priv);
  static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
                                struct clx2_tx_queue *txq, int qindex);
@@@ -69,42 -140,24 +141,24 @@@ static void ipw_tx_queue_free(struct ip
  static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
  static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
  static void ipw_rx_queue_replenish(void *);
  static int ipw_up(struct ipw_priv *);
+ static void ipw_bg_up(void *);
  static void ipw_down(struct ipw_priv *);
+ static void ipw_bg_down(void *);
  static int ipw_config(struct ipw_priv *);
  static int init_supported_rates(struct ipw_priv *priv,
                                struct ipw_supported_rates *prates);
+ static void ipw_set_hwcrypto_keys(struct ipw_priv *);
+ static void ipw_send_wep_keys(struct ipw_priv *, int);
  
- static u8 band_b_active_channel[MAX_B_CHANNELS] = {
-       1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0
- };
- static u8 band_a_active_channel[MAX_A_CHANNELS] = {
-       36, 40, 44, 48, 149, 153, 157, 161, 165, 52, 56, 60, 64, 0
- };
- static int is_valid_channel(int mode_mask, int channel)
- {
-       int i;
-       if (!channel)
-               return 0;
-       if (mode_mask & IEEE_A)
-               for (i = 0; i < MAX_A_CHANNELS; i++)
-                       if (band_a_active_channel[i] == channel)
-                               return IEEE_A;
-       if (mode_mask & (IEEE_B | IEEE_G))
-               for (i = 0; i < MAX_B_CHANNELS; i++)
-                       if (band_b_active_channel[i] == channel)
-                               return mode_mask & (IEEE_B | IEEE_G);
+ static int ipw_is_valid_channel(struct ieee80211_device *, u8);
+ static int ipw_channel_to_index(struct ieee80211_device *, u8);
+ static u8 ipw_freq_to_channel(struct ieee80211_device *, u32);
+ static int ipw_set_geo(struct ieee80211_device *, const struct ieee80211_geo *);
+ static const struct ieee80211_geo *ipw_get_geo(struct ieee80211_device *);
  
-       return 0;
- }
- static char *snprint_line(char *buf, size_t count,
-                         const u8 * data, u32 len, u32 ofs)
+ static int snprint_line(char *buf, size_t count,
+                       const u8 * data, u32 len, u32 ofs)
  {
        int out, i, j, l;
        char c;
                        out += snprintf(buf + out, count - out, " ");
        }
  
-       return buf;
+       return out;
  }
  
  static void printk_buf(int level, const u8 * data, u32 len)
                return;
  
        while (len) {
-               printk(KERN_DEBUG "%s\n",
-                      snprint_line(line, sizeof(line), &data[ofs],
-                                   min(len, 16U), ofs));
+               snprint_line(line, sizeof(line), &data[ofs],
+                            min(len, 16U), ofs);
+               printk(KERN_DEBUG "%s\n", line);
                ofs += 16;
                len -= min(len, 16U);
        }
  }
  
+ static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
+ {
+       size_t out = size;
+       u32 ofs = 0;
+       int total = 0;
+       while (size && len) {
+               out = snprint_line(output, size, &data[ofs],
+                                  min_t(size_t, len, 16U), ofs);
+               ofs += 16;
+               output += out;
+               size -= out;
+               len -= min_t(size_t, len, 16U);
+               total += out;
+       }
+       return total;
+ }
  static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
  #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
  
@@@ -227,38 -299,42 +300,42 @@@ static inline u32 __ipw_read32(char *f
  #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
  
  static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
- #define ipw_read_indirect(a, b, c, d) \
-       IPW_DEBUG_IO("%s %d: read_inddirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
-       _ipw_read_indirect(a, b, c, d)
+ static inline void __ipw_read_indirect(const char *f, int l,
+                                      struct ipw_priv *a, u32 b, u8 * c, int d)
+ {
+       IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
+                    d);
+       _ipw_read_indirect(a, b, c, d);
+ }
+ #define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
  
  static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
                                int num);
  #define ipw_write_indirect(a, b, c, d) \
        IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
-         _ipw_write_indirect(a, b, c, d)
+       _ipw_write_indirect(a, b, c, d)
  
  /* indirect write s */
  static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
  {
        IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
-       _ipw_write32(priv, CX2_INDIRECT_ADDR, reg);
-       _ipw_write32(priv, CX2_INDIRECT_DATA, value);
+       _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
+       _ipw_write32(priv, IPW_INDIRECT_DATA, value);
  }
  
  static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
  {
        IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
-       _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
-       _ipw_write8(priv, CX2_INDIRECT_DATA, value);
-       IPW_DEBUG_IO(" reg = 0x%8lX : value = 0x%8X\n",
-                    (unsigned long)(priv->hw_base + CX2_INDIRECT_DATA), value);
+       _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
+       _ipw_write8(priv, IPW_INDIRECT_DATA, value);
  }
  
  static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
  {
        IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
-       _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
-       _ipw_write16(priv, CX2_INDIRECT_DATA, value);
+       _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
+       _ipw_write16(priv, IPW_INDIRECT_DATA, value);
  }
  
  /* indirect read s */
  static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
  {
        u32 word;
-       _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
+       _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
        IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
-       word = _ipw_read32(priv, CX2_INDIRECT_DATA);
+       word = _ipw_read32(priv, IPW_INDIRECT_DATA);
        return (word >> ((reg & 0x3) * 8)) & 0xff;
  }
  
@@@ -278,8 -354,8 +355,8 @@@ static u32 _ipw_read_reg32(struct ipw_p
  
        IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
  
-       _ipw_write32(priv, CX2_INDIRECT_ADDR, reg);
-       value = _ipw_read32(priv, CX2_INDIRECT_DATA);
+       _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
+       value = _ipw_read32(priv, IPW_INDIRECT_DATA);
        IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
        return value;
  }
  static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
                               int num)
  {
-       u32 aligned_addr = addr & CX2_INDIRECT_ADDR_MASK;
+       u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK;
        u32 dif_len = addr - aligned_addr;
-       u32 aligned_len;
        u32 i;
  
        IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
  
+       if (num <= 0) {
+               return;
+       }
        /* Read the first nibble byte by byte */
        if (unlikely(dif_len)) {
+               _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
                /* Start reading at aligned_addr + dif_len */
-               _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
-               for (i = dif_len; i < 4; i++, buf++)
-                       *buf = _ipw_read8(priv, CX2_INDIRECT_DATA + i);
-               num -= dif_len;
+               for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
+                       *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
                aligned_addr += 4;
        }
  
-       /* Read DWs through autoinc register */
-       _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr);
-       aligned_len = num & CX2_INDIRECT_ADDR_MASK;
-       for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
-               *(u32 *) buf = ipw_read32(priv, CX2_AUTOINC_DATA);
+       _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
+       for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
+               *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
  
        /* Copy the last nibble */
-       dif_len = num - aligned_len;
-       _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
-       for (i = 0; i < dif_len; i++, buf++)
-               *buf = ipw_read8(priv, CX2_INDIRECT_DATA + i);
+       if (unlikely(num)) {
+               _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
+               for (i = 0; num > 0; i++, num--)
+                       *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
+       }
  }
  
  static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
                                int num)
  {
-       u32 aligned_addr = addr & CX2_INDIRECT_ADDR_MASK;
+       u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK;
        u32 dif_len = addr - aligned_addr;
-       u32 aligned_len;
        u32 i;
  
        IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
  
+       if (num <= 0) {
+               return;
+       }
        /* Write the first nibble byte by byte */
        if (unlikely(dif_len)) {
-               /* Start writing at aligned_addr + dif_len */
-               _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
-               for (i = dif_len; i < 4; i++, buf++)
-                       _ipw_write8(priv, CX2_INDIRECT_DATA + i, *buf);
-               num -= dif_len;
+               _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
+               /* Start reading at aligned_addr + dif_len */
+               for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
+                       _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
                aligned_addr += 4;
        }
  
-       /* Write DWs through autoinc register */
-       _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr);
-       aligned_len = num & CX2_INDIRECT_ADDR_MASK;
-       for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
-               _ipw_write32(priv, CX2_AUTOINC_DATA, *(u32 *) buf);
+       _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
+       for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
+               _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
  
        /* Copy the last nibble */
-       dif_len = num - aligned_len;
-       _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
-       for (i = 0; i < dif_len; i++, buf++)
-               _ipw_write8(priv, CX2_INDIRECT_DATA + i, *buf);
+       if (unlikely(num)) {
+               _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
+               for (i = 0; num > 0; i++, num--, buf++)
+                       _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
+       }
  }
  
  static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
@@@ -372,7 -450,7 +451,7 @@@ static inline void ipw_enable_interrupt
        if (priv->status & STATUS_INT_ENABLED)
                return;
        priv->status |= STATUS_INT_ENABLED;
-       ipw_write32(priv, CX2_INTA_MASK_R, CX2_INTA_MASK_ALL);
+       ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
  }
  
  static inline void ipw_disable_interrupts(struct ipw_priv *priv)
        if (!(priv->status & STATUS_INT_ENABLED))
                return;
        priv->status &= ~STATUS_INT_ENABLED;
-       ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
+       ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
  }
  
+ #ifdef CONFIG_IPW_DEBUG
  static char *ipw_error_desc(u32 val)
  {
        switch (val) {
        case IPW_FW_ERROR_MEMORY_OVERFLOW:
                return "MEMORY_OVERFLOW";
        case IPW_FW_ERROR_BAD_PARAM:
-               return "ERROR_BAD_PARAM";
+               return "BAD_PARAM";
        case IPW_FW_ERROR_BAD_CHECKSUM:
-               return "ERROR_BAD_CHECKSUM";
+               return "BAD_CHECKSUM";
        case IPW_FW_ERROR_NMI_INTERRUPT:
-               return "ERROR_NMI_INTERRUPT";
+               return "NMI_INTERRUPT";
        case IPW_FW_ERROR_BAD_DATABASE:
-               return "ERROR_BAD_DATABASE";
+               return "BAD_DATABASE";
        case IPW_FW_ERROR_ALLOC_FAIL:
-               return "ERROR_ALLOC_FAIL";
+               return "ALLOC_FAIL";
        case IPW_FW_ERROR_DMA_UNDERRUN:
-               return "ERROR_DMA_UNDERRUN";
+               return "DMA_UNDERRUN";
        case IPW_FW_ERROR_DMA_STATUS:
-               return "ERROR_DMA_STATUS";
-       case IPW_FW_ERROR_DINOSTATUS_ERROR:
-               return "ERROR_DINOSTATUS_ERROR";
-       case IPW_FW_ERROR_EEPROMSTATUS_ERROR:
-               return "ERROR_EEPROMSTATUS_ERROR";
+               return "DMA_STATUS";
+       case IPW_FW_ERROR_DINO_ERROR:
+               return "DINO_ERROR";
+       case IPW_FW_ERROR_EEPROM_ERROR:
+               return "EEPROM_ERROR";
        case IPW_FW_ERROR_SYSASSERT:
-               return "ERROR_SYSASSERT";
+               return "SYSASSERT";
        case IPW_FW_ERROR_FATAL_ERROR:
-               return "ERROR_FATALSTATUS_ERROR";
+               return "FATAL_ERROR";
        default:
-               return "UNKNOWNSTATUS_ERROR";
+               return "UNKNOWN_ERROR";
        }
  }
  
- static void ipw_dump_nic_error_log(struct ipw_priv *priv)
+ static void ipw_dump_error_log(struct ipw_priv *priv,
+                              struct ipw_fw_error *error)
  {
-       u32 desc, time, blink1, blink2, ilink1, ilink2, idata, i, count, base;
-       base = ipw_read32(priv, IPWSTATUS_ERROR_LOG);
-       count = ipw_read_reg32(priv, base);
+       u32 i;
  
-       if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
-               IPW_ERROR("Start IPW Error Log Dump:\n");
-               IPW_ERROR("Status: 0x%08X, Config: %08X\n",
-                         priv->status, priv->config);
+       if (!error) {
+               IPW_ERROR("Error allocating and capturing error log.  "
+                         "Nothing to dump.\n");
+               return;
        }
  
-       for (i = ERROR_START_OFFSET;
-            i <= count * ERROR_ELEM_SIZE; i += ERROR_ELEM_SIZE) {
-               desc = ipw_read_reg32(priv, base + i);
-               time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
-               blink1 = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
-               blink2 = ipw_read_reg32(priv, base + i + 3 * sizeof(u32));
-               ilink1 = ipw_read_reg32(priv, base + i + 4 * sizeof(u32));
-               ilink2 = ipw_read_reg32(priv, base + i + 5 * sizeof(u32));
-               idata = ipw_read_reg32(priv, base + i + 6 * sizeof(u32));
+       IPW_ERROR("Start IPW Error Log Dump:\n");
+       IPW_ERROR("Status: 0x%08X, Config: %08X\n",
+                 error->status, error->config);
  
+       for (i = 0; i < error->elem_len; i++)
                IPW_ERROR("%s %i 0x%08x  0x%08x  0x%08x  0x%08x  0x%08x\n",
-                         ipw_error_desc(desc), time, blink1, blink2,
-                         ilink1, ilink2, idata);
-       }
+                         ipw_error_desc(error->elem[i].desc),
+                         error->elem[i].time,
+                         error->elem[i].blink1,
+                         error->elem[i].blink2,
+                         error->elem[i].link1,
+                         error->elem[i].link2, error->elem[i].data);
+       for (i = 0; i < error->log_len; i++)
+               IPW_ERROR("%i\t0x%08x\t%i\n",
+                         error->log[i].time,
+                         error->log[i].data, error->log[i].event);
  }
+ #endif
  
- static void ipw_dump_nic_event_log(struct ipw_priv *priv)
+ static inline int ipw_is_init(struct ipw_priv *priv)
  {
-       u32 ev, time, data, i, count, base;
-       base = ipw_read32(priv, IPW_EVENT_LOG);
-       count = ipw_read_reg32(priv, base);
-       if (EVENT_START_OFFSET <= count * EVENT_ELEM_SIZE)
-               IPW_ERROR("Start IPW Event Log Dump:\n");
-       for (i = EVENT_START_OFFSET;
-            i <= count * EVENT_ELEM_SIZE; i += EVENT_ELEM_SIZE) {
-               ev = ipw_read_reg32(priv, base + i);
-               time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
-               data = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
- #ifdef CONFIG_IPW_DEBUG
-               IPW_ERROR("%i\t0x%08x\t%i\n", time, data, ev);
- #endif
-       }
+       return (priv->status & STATUS_INIT) ? 1 : 0;
  }
  
  static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
@@@ -637,6 -700,340 +701,340 @@@ static void ipw_init_ordinals(struct ip
  
  }
  
+ u32 ipw_register_toggle(u32 reg)
+ {
+       reg &= ~IPW_START_STANDBY;
+       if (reg & IPW_GATE_ODMA)
+               reg &= ~IPW_GATE_ODMA;
+       if (reg & IPW_GATE_IDMA)
+               reg &= ~IPW_GATE_IDMA;
+       if (reg & IPW_GATE_ADMA)
+               reg &= ~IPW_GATE_ADMA;
+       return reg;
+ }
+ /*
+  * LED behavior:
+  * - On radio ON, turn on any LEDs that require to be on during start
+  * - On initialization, start unassociated blink
+  * - On association, disable unassociated blink
+  * - On disassociation, start unassociated blink
+  * - On radio OFF, turn off any LEDs started during radio on
+  *
+  */
+ #define LD_TIME_LINK_ON 300
+ #define LD_TIME_LINK_OFF 2700
+ #define LD_TIME_ACT_ON 250
+ void ipw_led_link_on(struct ipw_priv *priv)
+ {
+       unsigned long flags;
+       u32 led;
+       /* If configured to not use LEDs, or nic_type is 1,
+        * then we don't toggle a LINK led */
+       if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
+               return;
+       spin_lock_irqsave(&priv->lock, flags);
+       if (!(priv->status & STATUS_RF_KILL_MASK) &&
+           !(priv->status & STATUS_LED_LINK_ON)) {
+               IPW_DEBUG_LED("Link LED On\n");
+               led = ipw_read_reg32(priv, IPW_EVENT_REG);
+               led |= priv->led_association_on;
+               led = ipw_register_toggle(led);
+               IPW_DEBUG_LED("Reg: 0x%08X\n", led);
+               ipw_write_reg32(priv, IPW_EVENT_REG, led);
+               priv->status |= STATUS_LED_LINK_ON;
+               /* If we aren't associated, schedule turning the LED off */
+               if (!(priv->status & STATUS_ASSOCIATED))
+                       queue_delayed_work(priv->workqueue,
+                                          &priv->led_link_off,
+                                          LD_TIME_LINK_ON);
+       }
+       spin_unlock_irqrestore(&priv->lock, flags);
+ }
+ static void ipw_bg_led_link_on(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_led_link_on(data);
+       up(&priv->sem);
+ }
+ void ipw_led_link_off(struct ipw_priv *priv)
+ {
+       unsigned long flags;
+       u32 led;
+       /* If configured not to use LEDs, or nic type is 1,
+        * then we don't goggle the LINK led. */
+       if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
+               return;
+       spin_lock_irqsave(&priv->lock, flags);
+       if (priv->status & STATUS_LED_LINK_ON) {
+               led = ipw_read_reg32(priv, IPW_EVENT_REG);
+               led &= priv->led_association_off;
+               led = ipw_register_toggle(led);
+               IPW_DEBUG_LED("Reg: 0x%08X\n", led);
+               ipw_write_reg32(priv, IPW_EVENT_REG, led);
+               IPW_DEBUG_LED("Link LED Off\n");
+               priv->status &= ~STATUS_LED_LINK_ON;
+               /* If we aren't associated and the radio is on, schedule
+                * turning the LED on (blink while unassociated) */
+               if (!(priv->status & STATUS_RF_KILL_MASK) &&
+                   !(priv->status & STATUS_ASSOCIATED))
+                       queue_delayed_work(priv->workqueue, &priv->led_link_on,
+                                          LD_TIME_LINK_OFF);
+       }
+       spin_unlock_irqrestore(&priv->lock, flags);
+ }
+ static void ipw_bg_led_link_off(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_led_link_off(data);
+       up(&priv->sem);
+ }
+ static inline void __ipw_led_activity_on(struct ipw_priv *priv)
+ {
+       u32 led;
+       if (priv->config & CFG_NO_LED)
+               return;
+       if (priv->status & STATUS_RF_KILL_MASK)
+               return;
+       if (!(priv->status & STATUS_LED_ACT_ON)) {
+               led = ipw_read_reg32(priv, IPW_EVENT_REG);
+               led |= priv->led_activity_on;
+               led = ipw_register_toggle(led);
+               IPW_DEBUG_LED("Reg: 0x%08X\n", led);
+               ipw_write_reg32(priv, IPW_EVENT_REG, led);
+               IPW_DEBUG_LED("Activity LED On\n");
+               priv->status |= STATUS_LED_ACT_ON;
+               cancel_delayed_work(&priv->led_act_off);
+               queue_delayed_work(priv->workqueue, &priv->led_act_off,
+                                  LD_TIME_ACT_ON);
+       } else {
+               /* Reschedule LED off for full time period */
+               cancel_delayed_work(&priv->led_act_off);
+               queue_delayed_work(priv->workqueue, &priv->led_act_off,
+                                  LD_TIME_ACT_ON);
+       }
+ }
+ void ipw_led_activity_on(struct ipw_priv *priv)
+ {
+       unsigned long flags;
+       spin_lock_irqsave(&priv->lock, flags);
+       __ipw_led_activity_on(priv);
+       spin_unlock_irqrestore(&priv->lock, flags);
+ }
+ void ipw_led_activity_off(struct ipw_priv *priv)
+ {
+       unsigned long flags;
+       u32 led;
+       if (priv->config & CFG_NO_LED)
+               return;
+       spin_lock_irqsave(&priv->lock, flags);
+       if (priv->status & STATUS_LED_ACT_ON) {
+               led = ipw_read_reg32(priv, IPW_EVENT_REG);
+               led &= priv->led_activity_off;
+               led = ipw_register_toggle(led);
+               IPW_DEBUG_LED("Reg: 0x%08X\n", led);
+               ipw_write_reg32(priv, IPW_EVENT_REG, led);
+               IPW_DEBUG_LED("Activity LED Off\n");
+               priv->status &= ~STATUS_LED_ACT_ON;
+       }
+       spin_unlock_irqrestore(&priv->lock, flags);
+ }
+ static void ipw_bg_led_activity_off(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_led_activity_off(data);
+       up(&priv->sem);
+ }
+ void ipw_led_band_on(struct ipw_priv *priv)
+ {
+       unsigned long flags;
+       u32 led;
+       /* Only nic type 1 supports mode LEDs */
+       if (priv->config & CFG_NO_LED ||
+           priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
+               return;
+       spin_lock_irqsave(&priv->lock, flags);
+       led = ipw_read_reg32(priv, IPW_EVENT_REG);
+       if (priv->assoc_network->mode == IEEE_A) {
+               led |= priv->led_ofdm_on;
+               led &= priv->led_association_off;
+               IPW_DEBUG_LED("Mode LED On: 802.11a\n");
+       } else if (priv->assoc_network->mode == IEEE_G) {
+               led |= priv->led_ofdm_on;
+               led |= priv->led_association_on;
+               IPW_DEBUG_LED("Mode LED On: 802.11g\n");
+       } else {
+               led &= priv->led_ofdm_off;
+               led |= priv->led_association_on;
+               IPW_DEBUG_LED("Mode LED On: 802.11b\n");
+       }
+       led = ipw_register_toggle(led);
+       IPW_DEBUG_LED("Reg: 0x%08X\n", led);
+       ipw_write_reg32(priv, IPW_EVENT_REG, led);
+       spin_unlock_irqrestore(&priv->lock, flags);
+ }
+ void ipw_led_band_off(struct ipw_priv *priv)
+ {
+       unsigned long flags;
+       u32 led;
+       /* Only nic type 1 supports mode LEDs */
+       if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
+               return;
+       spin_lock_irqsave(&priv->lock, flags);
+       led = ipw_read_reg32(priv, IPW_EVENT_REG);
+       led &= priv->led_ofdm_off;
+       led &= priv->led_association_off;
+       led = ipw_register_toggle(led);
+       IPW_DEBUG_LED("Reg: 0x%08X\n", led);
+       ipw_write_reg32(priv, IPW_EVENT_REG, led);
+       spin_unlock_irqrestore(&priv->lock, flags);
+ }
+ void ipw_led_radio_on(struct ipw_priv *priv)
+ {
+       ipw_led_link_on(priv);
+ }
+ void ipw_led_radio_off(struct ipw_priv *priv)
+ {
+       ipw_led_activity_off(priv);
+       ipw_led_link_off(priv);
+ }
+ void ipw_led_link_up(struct ipw_priv *priv)
+ {
+       /* Set the Link Led on for all nic types */
+       ipw_led_link_on(priv);
+ }
+ void ipw_led_link_down(struct ipw_priv *priv)
+ {
+       ipw_led_activity_off(priv);
+       ipw_led_link_off(priv);
+       if (priv->status & STATUS_RF_KILL_MASK)
+               ipw_led_radio_off(priv);
+ }
+ void ipw_led_init(struct ipw_priv *priv)
+ {
+       priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
+       /* Set the default PINs for the link and activity leds */
+       priv->led_activity_on = IPW_ACTIVITY_LED;
+       priv->led_activity_off = ~(IPW_ACTIVITY_LED);
+       priv->led_association_on = IPW_ASSOCIATED_LED;
+       priv->led_association_off = ~(IPW_ASSOCIATED_LED);
+       /* Set the default PINs for the OFDM leds */
+       priv->led_ofdm_on = IPW_OFDM_LED;
+       priv->led_ofdm_off = ~(IPW_OFDM_LED);
+       switch (priv->nic_type) {
+       case EEPROM_NIC_TYPE_1:
+               /* In this NIC type, the LEDs are reversed.... */
+               priv->led_activity_on = IPW_ASSOCIATED_LED;
+               priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
+               priv->led_association_on = IPW_ACTIVITY_LED;
+               priv->led_association_off = ~(IPW_ACTIVITY_LED);
+               if (!(priv->config & CFG_NO_LED))
+                       ipw_led_band_on(priv);
+               /* And we don't blink link LEDs for this nic, so
+                * just return here */
+               return;
+       case EEPROM_NIC_TYPE_3:
+       case EEPROM_NIC_TYPE_2:
+       case EEPROM_NIC_TYPE_4:
+       case EEPROM_NIC_TYPE_0:
+               break;
+       default:
+               IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
+                              priv->nic_type);
+               priv->nic_type = EEPROM_NIC_TYPE_0;
+               break;
+       }
+       if (!(priv->config & CFG_NO_LED)) {
+               if (priv->status & STATUS_ASSOCIATED)
+                       ipw_led_link_on(priv);
+               else
+                       ipw_led_link_off(priv);
+       }
+ }
+ void ipw_led_shutdown(struct ipw_priv *priv)
+ {
+       ipw_led_activity_off(priv);
+       ipw_led_link_off(priv);
+       ipw_led_band_off(priv);
+       cancel_delayed_work(&priv->led_link_on);
+       cancel_delayed_work(&priv->led_link_off);
+       cancel_delayed_work(&priv->led_act_off);
+ }
  /*
   * The following adds a new attribute to the sysfs representation
   * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
@@@ -648,8 -1045,9 +1046,9 @@@ static ssize_t show_debug_level(struct 
  {
        return sprintf(buf, "0x%08X\n", ipw_debug_level);
  }
- static ssize_t store_debug_level(struct device_driver *d,
-                                const char *buf, size_t count)
+ static ssize_t store_debug_level(struct device_driver *d, const char *buf,
+                                size_t count)
  {
        char *p = (char *)buf;
        u32 val;
  static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
                   show_debug_level, store_debug_level);
  
- static ssize_t show_status(struct device *d,
-                          struct device_attribute *attr, char *buf)
+ static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
  {
-       struct ipw_priv *p = d->driver_data;
-       return sprintf(buf, "0x%08x\n", (int)p->status);
+       return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
  }
  
- static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
- static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
-                       char *buf)
+ static void ipw_capture_event_log(struct ipw_priv *priv,
+                                 u32 log_len, struct ipw_event *log)
  {
-       struct ipw_priv *p = d->driver_data;
-       return sprintf(buf, "0x%08x\n", (int)p->config);
- }
+       u32 base;
  
- static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
+       if (log_len) {
+               base = ipw_read32(priv, IPW_EVENT_LOG);
+               ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
+                                 (u8 *) log, sizeof(*log) * log_len);
+       }
+ }
  
- static ssize_t show_nic_type(struct device *d,
-                            struct device_attribute *attr, char *buf)
+ static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
  {
-       struct ipw_priv *p = d->driver_data;
-       u8 type = p->eeprom[EEPROM_NIC_TYPE];
+       struct ipw_fw_error *error;
+       u32 log_len = ipw_get_event_log_len(priv);
+       u32 base = ipw_read32(priv, IPW_ERROR_LOG);
+       u32 elem_len = ipw_read_reg32(priv, base);
  
-       switch (type) {
-       case EEPROM_NIC_TYPE_STANDARD:
-               return sprintf(buf, "STANDARD\n");
-       case EEPROM_NIC_TYPE_DELL:
-               return sprintf(buf, "DELL\n");
-       case EEPROM_NIC_TYPE_FUJITSU:
-               return sprintf(buf, "FUJITSU\n");
-       case EEPROM_NIC_TYPE_IBM:
-               return sprintf(buf, "IBM\n");
-       case EEPROM_NIC_TYPE_HP:
-               return sprintf(buf, "HP\n");
+       error = kmalloc(sizeof(*error) +
+                       sizeof(*error->elem) * elem_len +
+                       sizeof(*error->log) * log_len, GFP_ATOMIC);
+       if (!error) {
+               IPW_ERROR("Memory allocation for firmware error log "
+                         "failed.\n");
+               return NULL;
        }
+       error->jiffies = jiffies;
+       error->status = priv->status;
+       error->config = priv->config;
+       error->elem_len = elem_len;
+       error->log_len = log_len;
+       error->elem = (struct ipw_error_elem *)error->payload;
+       error->log = (struct ipw_event *)(error->elem +
+                                         (sizeof(*error->elem) * elem_len));
+       ipw_capture_event_log(priv, log_len, error->log);
  
-       return sprintf(buf, "UNKNOWN\n");
+       if (elem_len)
+               ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
+                                 sizeof(*error->elem) * elem_len);
+       return error;
  }
  
- static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
+ static void ipw_free_error_log(struct ipw_fw_error *error)
+ {
+       if (error)
+               kfree(error);
+ }
  
- static ssize_t dump_error_log(struct device *d,
-                             struct device_attribute *attr, const char *buf,
-                             size_t count)
+ static ssize_t show_event_log(struct device *d,
+                             struct device_attribute *attr, char *buf)
  {
-       char *p = (char *)buf;
+       struct ipw_priv *priv = dev_get_drvdata(d);
+       u32 log_len = ipw_get_event_log_len(priv);
+       struct ipw_event log[log_len];
+       u32 len = 0, i;
  
-       if (p[0] == '1')
-               ipw_dump_nic_error_log((struct ipw_priv *)d->driver_data);
+       ipw_capture_event_log(priv, log_len, log);
  
-       return strnlen(buf, count);
+       len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
+       for (i = 0; i < log_len; i++)
+               len += snprintf(buf + len, PAGE_SIZE - len,
+                               "\n%08X%08X%08X",
+                               log[i].time, log[i].event, log[i].data);
+       len += snprintf(buf + len, PAGE_SIZE - len, "\n");
+       return len;
  }
  
- static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
+ static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
  
- static ssize_t dump_event_log(struct device *d,
-                             struct device_attribute *attr, const char *buf,
-                             size_t count)
+ static ssize_t show_error(struct device *d,
+                         struct device_attribute *attr, char *buf)
  {
-       char *p = (char *)buf;
+       struct ipw_priv *priv = dev_get_drvdata(d);
+       u32 len = 0, i;
+       if (!priv->error)
+               return 0;
+       len += snprintf(buf + len, PAGE_SIZE - len,
+                       "%08lX%08X%08X%08X",
+                       priv->error->jiffies,
+                       priv->error->status,
+                       priv->error->config, priv->error->elem_len);
+       for (i = 0; i < priv->error->elem_len; i++)
+               len += snprintf(buf + len, PAGE_SIZE - len,
+                               "\n%08X%08X%08X%08X%08X%08X%08X",
+                               priv->error->elem[i].time,
+                               priv->error->elem[i].desc,
+                               priv->error->elem[i].blink1,
+                               priv->error->elem[i].blink2,
+                               priv->error->elem[i].link1,
+                               priv->error->elem[i].link2,
+                               priv->error->elem[i].data);
+       len += snprintf(buf + len, PAGE_SIZE - len,
+                       "\n%08X", priv->error->log_len);
+       for (i = 0; i < priv->error->log_len; i++)
+               len += snprintf(buf + len, PAGE_SIZE - len,
+                               "\n%08X%08X%08X",
+                               priv->error->log[i].time,
+                               priv->error->log[i].event,
+                               priv->error->log[i].data);
+       len += snprintf(buf + len, PAGE_SIZE - len, "\n");
+       return len;
+ }
+ static ssize_t clear_error(struct device *d,
+                          struct device_attribute *attr,
+                          const char *buf, size_t count)
+ {
+       struct ipw_priv *priv = dev_get_drvdata(d);
+       if (priv->error) {
+               ipw_free_error_log(priv->error);
+               priv->error = NULL;
+       }
+       return count;
+ }
  
-       if (p[0] == '1')
-               ipw_dump_nic_event_log((struct ipw_priv *)d->driver_data);
+ static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
  
-       return strnlen(buf, count);
+ static ssize_t show_cmd_log(struct device *d,
+                           struct device_attribute *attr, char *buf)
+ {
+       struct ipw_priv *priv = dev_get_drvdata(d);
+       u32 len = 0, i;
+       if (!priv->cmdlog)
+               return 0;
+       for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
+            (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
+            i = (i + 1) % priv->cmdlog_len) {
+               len +=
+                   snprintf(buf + len, PAGE_SIZE - len,
+                            "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
+                            priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
+                            priv->cmdlog[i].cmd.len);
+               len +=
+                   snprintk_buf(buf + len, PAGE_SIZE - len,
+                                (u8 *) priv->cmdlog[i].cmd.param,
+                                priv->cmdlog[i].cmd.len);
+               len += snprintf(buf + len, PAGE_SIZE - len, "\n");
+       }
+       len += snprintf(buf + len, PAGE_SIZE - len, "\n");
+       return len;
  }
  
- static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
+ static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
  
- static ssize_t show_ucode_version(struct device *d,
-                                 struct device_attribute *attr, char *buf)
+ static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
+                            char *buf)
  {
-       u32 len = sizeof(u32), tmp = 0;
-       struct ipw_priv *p = d->driver_data;
+       struct ipw_priv *priv = dev_get_drvdata(d);
+       return sprintf(buf, "%d\n", priv->ieee->scan_age);
+ }
+ static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
+                             const char *buf, size_t count)
+ {
+       struct ipw_priv *priv = dev_get_drvdata(d);
+ #ifdef CONFIG_IPW_DEBUG
+       struct net_device *dev = priv->net_dev;
+ #endif
+       char buffer[] = "00000000";
+       unsigned long len =
+           (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
+       unsigned long val;
+       char *p = buffer;
+       IPW_DEBUG_INFO("enter\n");
+       strncpy(buffer, buf, len);
+       buffer[len] = 0;
+       if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
+               p++;
+               if (p[0] == 'x' || p[0] == 'X')
+                       p++;
+               val = simple_strtoul(p, &p, 16);
+       } else
+               val = simple_strtoul(p, &p, 10);
+       if (p == buffer) {
+               IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
+       } else {
+               priv->ieee->scan_age = val;
+               IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
+       }
+       IPW_DEBUG_INFO("exit\n");
+       return len;
+ }
+ static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
+ static ssize_t show_led(struct device *d, struct device_attribute *attr,
+                       char *buf)
+ {
+       struct ipw_priv *priv = dev_get_drvdata(d);
+       return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
+ }
+ static ssize_t store_led(struct device *d, struct device_attribute *attr,
+                        const char *buf, size_t count)
+ {
+       struct ipw_priv *priv = dev_get_drvdata(d);
+       IPW_DEBUG_INFO("enter\n");
+       if (count == 0)
+               return 0;
+       if (*buf == 0) {
+               IPW_DEBUG_LED("Disabling LED control.\n");
+               priv->config |= CFG_NO_LED;
+               ipw_led_shutdown(priv);
+       } else {
+               IPW_DEBUG_LED("Enabling LED control.\n");
+               priv->config &= ~CFG_NO_LED;
+               ipw_led_init(priv);
+       }
+       IPW_DEBUG_INFO("exit\n");
+       return count;
+ }
+ static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
+ static ssize_t show_status(struct device *d,
+                          struct device_attribute *attr, char *buf)
+ {
+       struct ipw_priv *p = d->driver_data;
+       return sprintf(buf, "0x%08x\n", (int)p->status);
+ }
+ static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
+ static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
+                       char *buf)
+ {
+       struct ipw_priv *p = d->driver_data;
+       return sprintf(buf, "0x%08x\n", (int)p->config);
+ }
+ static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
+ static ssize_t show_nic_type(struct device *d,
+                            struct device_attribute *attr, char *buf)
+ {
+       struct ipw_priv *priv = d->driver_data;
+       return sprintf(buf, "TYPE: %d\n", priv->nic_type);
+ }
+ static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
+ static ssize_t show_ucode_version(struct device *d,
+                                 struct device_attribute *attr, char *buf)
+ {
+       u32 len = sizeof(u32), tmp = 0;
+       struct ipw_priv *p = d->driver_data;
  
        if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
                return 0;
@@@ -799,7 -1385,7 +1386,7 @@@ static ssize_t show_command_event_reg(s
        u32 reg = 0;
        struct ipw_priv *p = d->driver_data;
  
-       reg = ipw_read_reg32(p, CX2_INTERNAL_CMD_EVENT);
+       reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
        return sprintf(buf, "0x%08x\n", reg);
  }
  static ssize_t store_command_event_reg(struct device *d,
        struct ipw_priv *p = d->driver_data;
  
        sscanf(buf, "%x", &reg);
-       ipw_write_reg32(p, CX2_INTERNAL_CMD_EVENT, reg);
+       ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
        return strnlen(buf, count);
  }
  
@@@ -846,6 -1432,7 +1433,7 @@@ static ssize_t show_indirect_dword(stru
  {
        u32 reg = 0;
        struct ipw_priv *priv = d->driver_data;
        if (priv->status & STATUS_INDIRECT_DWORD)
                reg = ipw_read_reg32(priv, priv->indirect_dword);
        else
@@@ -872,6 -1459,7 +1460,7 @@@ static ssize_t show_indirect_byte(struc
  {
        u8 reg = 0;
        struct ipw_priv *priv = d->driver_data;
        if (priv->status & STATUS_INDIRECT_BYTE)
                reg = ipw_read_reg8(priv, priv->indirect_byte);
        else
@@@ -946,7 -1534,7 +1535,7 @@@ static ssize_t show_rf_kill(struct devi
  static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
  {
        if ((disable_radio ? 1 : 0) ==
-           (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
+           ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
                return 0;
  
        IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO  %s\n",
        if (disable_radio) {
                priv->status |= STATUS_RF_KILL_SW;
  
-               if (priv->workqueue) {
+               if (priv->workqueue)
                        cancel_delayed_work(&priv->request_scan);
-               }
-               wake_up_interruptible(&priv->wait_command_queue);
                queue_work(priv->workqueue, &priv->down);
        } else {
                priv->status &= ~STATUS_RF_KILL_SW;
@@@ -988,6 -1574,93 +1575,93 @@@ static ssize_t store_rf_kill(struct dev
  
  static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
  
+ static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
+                              char *buf)
+ {
+       struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
+       int pos = 0, len = 0;
+       if (priv->config & CFG_SPEED_SCAN) {
+               while (priv->speed_scan[pos] != 0)
+                       len += sprintf(&buf[len], "%d ",
+                                      priv->speed_scan[pos++]);
+               return len + sprintf(&buf[len], "\n");
+       }
+       return sprintf(buf, "0\n");
+ }
+ static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
+                               const char *buf, size_t count)
+ {
+       struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
+       int channel, pos = 0;
+       const char *p = buf;
+       /* list of space separated channels to scan, optionally ending with 0 */
+       while ((channel = simple_strtol(p, NULL, 0))) {
+               if (pos == MAX_SPEED_SCAN - 1) {
+                       priv->speed_scan[pos] = 0;
+                       break;
+               }
+               if (ipw_is_valid_channel(priv->ieee, channel))
+                       priv->speed_scan[pos++] = channel;
+               else
+                       IPW_WARNING("Skipping invalid channel request: %d\n",
+                                   channel);
+               p = strchr(p, ' ');
+               if (!p)
+                       break;
+               while (*p == ' ' || *p == '\t')
+                       p++;
+       }
+       if (pos == 0)
+               priv->config &= ~CFG_SPEED_SCAN;
+       else {
+               priv->speed_scan_pos = 0;
+               priv->config |= CFG_SPEED_SCAN;
+       }
+       return count;
+ }
+ static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
+                  store_speed_scan);
+ static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
+                             char *buf)
+ {
+       struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
+       return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
+ }
+ static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
+                              const char *buf, size_t count)
+ {
+       struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
+       if (buf[0] == '1')
+               priv->config |= CFG_NET_STATS;
+       else
+               priv->config &= ~CFG_NET_STATS;
+       return count;
+ }
+ static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
+                  show_net_stats, store_net_stats);
+ static void notify_wx_assoc_event(struct ipw_priv *priv)
+ {
+       union iwreq_data wrqu;
+       wrqu.ap_addr.sa_family = ARPHRD_ETHER;
+       if (priv->status & STATUS_ASSOCIATED)
+               memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
+       else
+               memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
+       wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
+ }
  static void ipw_irq_tasklet(struct ipw_priv *priv)
  {
        u32 inta, inta_mask, handled = 0;
  
        spin_lock_irqsave(&priv->lock, flags);
  
-       inta = ipw_read32(priv, CX2_INTA_RW);
-       inta_mask = ipw_read32(priv, CX2_INTA_MASK_R);
-       inta &= (CX2_INTA_MASK_ALL & inta_mask);
+       inta = ipw_read32(priv, IPW_INTA_RW);
+       inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
+       inta &= (IPW_INTA_MASK_ALL & inta_mask);
  
        /* Add any cached INTA values that need to be handled */
        inta |= priv->isr_inta;
  
        /* handle all the justifications for the interrupt */
-       if (inta & CX2_INTA_BIT_RX_TRANSFER) {
+       if (inta & IPW_INTA_BIT_RX_TRANSFER) {
                ipw_rx(priv);
-               handled |= CX2_INTA_BIT_RX_TRANSFER;
+               handled |= IPW_INTA_BIT_RX_TRANSFER;
        }
  
-       if (inta & CX2_INTA_BIT_TX_CMD_QUEUE) {
+       if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
                IPW_DEBUG_HC("Command completed.\n");
                rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
                priv->status &= ~STATUS_HCMD_ACTIVE;
                wake_up_interruptible(&priv->wait_command_queue);
-               handled |= CX2_INTA_BIT_TX_CMD_QUEUE;
+               handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
        }
  
-       if (inta & CX2_INTA_BIT_TX_QUEUE_1) {
+       if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
                IPW_DEBUG_TX("TX_QUEUE_1\n");
                rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
-               handled |= CX2_INTA_BIT_TX_QUEUE_1;
+               handled |= IPW_INTA_BIT_TX_QUEUE_1;
        }
  
-       if (inta & CX2_INTA_BIT_TX_QUEUE_2) {
+       if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
                IPW_DEBUG_TX("TX_QUEUE_2\n");
                rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
-               handled |= CX2_INTA_BIT_TX_QUEUE_2;
+               handled |= IPW_INTA_BIT_TX_QUEUE_2;
        }
  
-       if (inta & CX2_INTA_BIT_TX_QUEUE_3) {
+       if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
                IPW_DEBUG_TX("TX_QUEUE_3\n");
                rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
-               handled |= CX2_INTA_BIT_TX_QUEUE_3;
+               handled |= IPW_INTA_BIT_TX_QUEUE_3;
        }
  
-       if (inta & CX2_INTA_BIT_TX_QUEUE_4) {
+       if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
                IPW_DEBUG_TX("TX_QUEUE_4\n");
                rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
-               handled |= CX2_INTA_BIT_TX_QUEUE_4;
+               handled |= IPW_INTA_BIT_TX_QUEUE_4;
        }
  
-       if (inta & CX2_INTA_BIT_STATUS_CHANGE) {
+       if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
                IPW_WARNING("STATUS_CHANGE\n");
-               handled |= CX2_INTA_BIT_STATUS_CHANGE;
+               handled |= IPW_INTA_BIT_STATUS_CHANGE;
        }
  
-       if (inta & CX2_INTA_BIT_BEACON_PERIOD_EXPIRED) {
+       if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
                IPW_WARNING("TX_PERIOD_EXPIRED\n");
-               handled |= CX2_INTA_BIT_BEACON_PERIOD_EXPIRED;
+               handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
        }
  
-       if (inta & CX2_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
+       if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
                IPW_WARNING("HOST_CMD_DONE\n");
-               handled |= CX2_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
+               handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
        }
  
-       if (inta & CX2_INTA_BIT_FW_INITIALIZATION_DONE) {
+       if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
                IPW_WARNING("FW_INITIALIZATION_DONE\n");
-               handled |= CX2_INTA_BIT_FW_INITIALIZATION_DONE;
+               handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
        }
  
-       if (inta & CX2_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
+       if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
                IPW_WARNING("PHY_OFF_DONE\n");
-               handled |= CX2_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
+               handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
        }
  
-       if (inta & CX2_INTA_BIT_RF_KILL_DONE) {
+       if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
                IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
                priv->status |= STATUS_RF_KILL_HW;
                wake_up_interruptible(&priv->wait_command_queue);
-               netif_carrier_off(priv->net_dev);
-               netif_stop_queue(priv->net_dev);
+               priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
                cancel_delayed_work(&priv->request_scan);
+               schedule_work(&priv->link_down);
                queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
-               handled |= CX2_INTA_BIT_RF_KILL_DONE;
+               handled |= IPW_INTA_BIT_RF_KILL_DONE;
        }
  
-       if (inta & CX2_INTA_BIT_FATAL_ERROR) {
+       if (inta & IPW_INTA_BIT_FATAL_ERROR) {
                IPW_ERROR("Firmware error detected.  Restarting.\n");
+               if (priv->error) {
+                       IPW_ERROR("Sysfs 'error' log already exists.\n");
  #ifdef CONFIG_IPW_DEBUG
-               if (ipw_debug_level & IPW_DL_FW_ERRORS) {
-                       ipw_dump_nic_error_log(priv);
-                       ipw_dump_nic_event_log(priv);
-               }
+                       if (ipw_debug_level & IPW_DL_FW_ERRORS) {
+                               struct ipw_fw_error *error =
+                                   ipw_alloc_error_log(priv);
+                               ipw_dump_error_log(priv, error);
+                               if (error)
+                                       ipw_free_error_log(error);
+                       }
+ #endif
+               } else {
+                       priv->error = ipw_alloc_error_log(priv);
+                       if (priv->error)
+                               IPW_ERROR("Sysfs 'error' log captured.\n");
+                       else
+                               IPW_ERROR("Error allocating sysfs 'error' "
+                                         "log.\n");
+ #ifdef CONFIG_IPW_DEBUG
+                       if (ipw_debug_level & IPW_DL_FW_ERRORS)
+                               ipw_dump_error_log(priv, priv->error);
  #endif
+               }
+               /* XXX: If hardware encryption is for WPA/WPA2,
+                * we have to notify the supplicant. */
+               if (priv->ieee->sec.encrypt) {
+                       priv->status &= ~STATUS_ASSOCIATED;
+                       notify_wx_assoc_event(priv);
+               }
+               /* Keep the restart process from trying to send host
+                * commands by clearing the INIT status bit */
+               priv->status &= ~STATUS_INIT;
+               /* Cancel currently queued command. */
+               priv->status &= ~STATUS_HCMD_ACTIVE;
+               wake_up_interruptible(&priv->wait_command_queue);
                queue_work(priv->workqueue, &priv->adapter_restart);
-               handled |= CX2_INTA_BIT_FATAL_ERROR;
+               handled |= IPW_INTA_BIT_FATAL_ERROR;
        }
  
-       if (inta & CX2_INTA_BIT_PARITY_ERROR) {
+       if (inta & IPW_INTA_BIT_PARITY_ERROR) {
                IPW_ERROR("Parity error\n");
-               handled |= CX2_INTA_BIT_PARITY_ERROR;
+               handled |= IPW_INTA_BIT_PARITY_ERROR;
        }
  
        if (handled != inta) {
        spin_unlock_irqrestore(&priv->lock, flags);
  }
  
- #ifdef CONFIG_IPW_DEBUG
  #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
  static char *get_cmd_string(u8 cmd)
  {
                return "UNKNOWN";
        }
  }
- #endif                                /* CONFIG_IPW_DEBUG */
  
  #define HOST_COMPLETE_TIMEOUT HZ
  static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
  {
        int rc = 0;
+       unsigned long flags;
  
+       spin_lock_irqsave(&priv->lock, flags);
        if (priv->status & STATUS_HCMD_ACTIVE) {
-               IPW_ERROR("Already sending a command\n");
-               return -1;
+               IPW_ERROR("Failed to send %s: Already sending a command.\n",
+                         get_cmd_string(cmd->cmd));
+               spin_unlock_irqrestore(&priv->lock, flags);
+               return -EAGAIN;
        }
  
        priv->status |= STATUS_HCMD_ACTIVE;
  
-       IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
-                    get_cmd_string(cmd->cmd), cmd->cmd, cmd->len);
+       if (priv->cmdlog) {
+               priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
+               priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
+               priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
+               memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
+                      cmd->len);
+               priv->cmdlog[priv->cmdlog_pos].retcode = -1;
+       }
+       IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
+                    get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
+                    priv->status);
        printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
  
        rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
-       if (rc)
-               return rc;
+       if (rc) {
+               priv->status &= ~STATUS_HCMD_ACTIVE;
+               IPW_ERROR("Failed to send %s: Reason %d\n",
+                         get_cmd_string(cmd->cmd), rc);
+               spin_unlock_irqrestore(&priv->lock, flags);
+               goto exit;
+       }
+       spin_unlock_irqrestore(&priv->lock, flags);
  
        rc = wait_event_interruptible_timeout(priv->wait_command_queue,
                                              !(priv->
                                                status & STATUS_HCMD_ACTIVE),
                                              HOST_COMPLETE_TIMEOUT);
        if (rc == 0) {
-               IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
-                              jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
-               priv->status &= ~STATUS_HCMD_ACTIVE;
-               return -EIO;
-       }
-       if (priv->status & STATUS_RF_KILL_MASK) {
-               IPW_DEBUG_INFO("Command aborted due to RF Kill Switch\n");
-               return -EIO;
+               spin_lock_irqsave(&priv->lock, flags);
+               if (priv->status & STATUS_HCMD_ACTIVE) {
+                       IPW_ERROR("Failed to send %s: Command timed out.\n",
+                                 get_cmd_string(cmd->cmd));
+                       priv->status &= ~STATUS_HCMD_ACTIVE;
+                       spin_unlock_irqrestore(&priv->lock, flags);
+                       rc = -EIO;
+                       goto exit;
+               }
+               spin_unlock_irqrestore(&priv->lock, flags);
+       } else
+               rc = 0;
+       if (priv->status & STATUS_RF_KILL_HW) {
+               IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
+                         get_cmd_string(cmd->cmd));
+               rc = -EIO;
+               goto exit;
        }
  
-       return 0;
+       exit:
+       if (priv->cmdlog) {
+               priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
+               priv->cmdlog_pos %= priv->cmdlog_len;
+       }
+       return rc;
  }
  
  static int ipw_send_host_complete(struct ipw_priv *priv)
                return -1;
        }
  
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send HOST_COMPLETE command\n");
-               return -1;
-       }
-       return 0;
+       return ipw_send_cmd(priv, &cmd);
  }
  
  static int ipw_send_system_config(struct ipw_priv *priv,
                return -1;
        }
  
-       memcpy(&cmd.param, config, sizeof(*config));
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send SYSTEM_CONFIG command\n");
-               return -1;
-       }
-       return 0;
+       memcpy(cmd.param, config, sizeof(*config));
+       return ipw_send_cmd(priv, &cmd);
  }
  
  static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
                return -1;
        }
  
-       memcpy(&cmd.param, ssid, cmd.len);
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send SSID command\n");
-               return -1;
-       }
-       return 0;
+       memcpy(cmd.param, ssid, cmd.len);
+       return ipw_send_cmd(priv, &cmd);
  }
  
  static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
        IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
                       priv->net_dev->name, MAC_ARG(mac));
  
-       memcpy(&cmd.param, mac, ETH_ALEN);
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send ADAPTER_ADDRESS command\n");
-               return -1;
-       }
-       return 0;
+       memcpy(cmd.param, mac, ETH_ALEN);
+       return ipw_send_cmd(priv, &cmd);
  }
  
+ /*
+  * NOTE: This must be executed from our workqueue as it results in udelay
+  * being called which may corrupt the keyboard if executed on default
+  * workqueue
+  */
  static void ipw_adapter_restart(void *adapter)
  {
        struct ipw_priv *priv = adapter;
                return;
  
        ipw_down(priv);
+       if (priv->assoc_network &&
+           (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
+               ipw_remove_current_network(priv);
        if (ipw_up(priv)) {
                IPW_ERROR("Failed to up device\n");
                return;
        }
  }
  
+ static void ipw_bg_adapter_restart(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_adapter_restart(data);
+       up(&priv->sem);
+ }
  #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
  
  static void ipw_scan_check(void *data)
                IPW_DEBUG_SCAN("Scan completion watchdog resetting "
                               "adapter (%dms).\n",
                               IPW_SCAN_CHECK_WATCHDOG / 100);
-               ipw_adapter_restart(priv);
+               queue_work(priv->workqueue, &priv->adapter_restart);
        }
  }
  
+ static void ipw_bg_scan_check(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_scan_check(data);
+       up(&priv->sem);
+ }
  static int ipw_send_scan_request_ext(struct ipw_priv *priv,
                                     struct ipw_scan_request_ext *request)
  {
                .len = sizeof(*request)
        };
  
-       if (!priv || !request) {
-               IPW_ERROR("Invalid args\n");
-               return -1;
-       }
-       memcpy(&cmd.param, request, sizeof(*request));
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send SCAN_REQUEST_EXT command\n");
-               return -1;
-       }
-       queue_delayed_work(priv->workqueue, &priv->scan_check,
-                          IPW_SCAN_CHECK_WATCHDOG);
-       return 0;
+       memcpy(cmd.param, request, sizeof(*request));
+       return ipw_send_cmd(priv, &cmd);
  }
  
  static int ipw_send_scan_abort(struct ipw_priv *priv)
                return -1;
        }
  
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send SCAN_ABORT command\n");
-               return -1;
-       }
-       return 0;
+       return ipw_send_cmd(priv, &cmd);
  }
  
  static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
        struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
            &cmd.param;
        calib->beacon_rssi_raw = sens;
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send SENSITIVITY CALIB command\n");
-               return -1;
-       }
-       return 0;
+       return ipw_send_cmd(priv, &cmd);
  }
  
  static int ipw_send_associate(struct ipw_priv *priv,
                .len = sizeof(*associate)
        };
  
+       struct ipw_associate tmp_associate;
+       memcpy(&tmp_associate, associate, sizeof(*associate));
+       tmp_associate.policy_support =
+           cpu_to_le16(tmp_associate.policy_support);
+       tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
+       tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
+       tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
+       tmp_associate.listen_interval =
+           cpu_to_le16(tmp_associate.listen_interval);
+       tmp_associate.beacon_interval =
+           cpu_to_le16(tmp_associate.beacon_interval);
+       tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
        if (!priv || !associate) {
                IPW_ERROR("Invalid args\n");
                return -1;
        }
  
-       memcpy(&cmd.param, associate, sizeof(*associate));
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send ASSOCIATE command\n");
-               return -1;
-       }
-       return 0;
+       memcpy(cmd.param, &tmp_associate, sizeof(*associate));
+       return ipw_send_cmd(priv, &cmd);
  }
  
  static int ipw_send_supported_rates(struct ipw_priv *priv,
                return -1;
        }
  
-       memcpy(&cmd.param, rates, sizeof(*rates));
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send SUPPORTED_RATES command\n");
-               return -1;
-       }
-       return 0;
+       memcpy(cmd.param, rates, sizeof(*rates));
+       return ipw_send_cmd(priv, &cmd);
  }
  
  static int ipw_set_random_seed(struct ipw_priv *priv)
  
        get_random_bytes(&cmd.param, sizeof(u32));
  
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send SEED_NUMBER command\n");
-               return -1;
-       }
-       return 0;
+       return ipw_send_cmd(priv, &cmd);
  }
  
- #if 0
  static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
  {
        struct host_cmd cmd = {
  
        *((u32 *) & cmd.param) = phy_off;
  
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send CARD_DISABLE command\n");
-               return -1;
-       }
-       return 0;
+       return ipw_send_cmd(priv, &cmd);
  }
- #endif
  
  static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
  {
                return -1;
        }
  
-       memcpy(&cmd.param, power, sizeof(*power));
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send TX_POWER command\n");
-               return -1;
+       memcpy(cmd.param, power, sizeof(*power));
+       return ipw_send_cmd(priv, &cmd);
+ }
+ static int ipw_set_tx_power(struct ipw_priv *priv)
+ {
+       const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
+       struct ipw_tx_power tx_power;
+       s8 max_power;
+       int i;
+       memset(&tx_power, 0, sizeof(tx_power));
+       /* configure device for 'G' band */
+       tx_power.ieee_mode = IPW_G_MODE;
+       tx_power.num_channels = geo->bg_channels;
+       for (i = 0; i < geo->bg_channels; i++) {
+               max_power = geo->bg[i].max_power;
+               tx_power.channels_tx_power[i].channel_number =
+                   geo->bg[i].channel;
+               tx_power.channels_tx_power[i].tx_power = max_power ?
+                   min(max_power, priv->tx_power) : priv->tx_power;
        }
+       if (ipw_send_tx_power(priv, &tx_power))
+               return -EIO;
+       /* configure device to also handle 'B' band */
+       tx_power.ieee_mode = IPW_B_MODE;
+       if (ipw_send_tx_power(priv, &tx_power))
+               return -EIO;
  
+       /* configure device to also handle 'A' band */
+       if (priv->ieee->abg_true) {
+               tx_power.ieee_mode = IPW_A_MODE;
+               tx_power.num_channels = geo->a_channels;
+               for (i = 0; i < tx_power.num_channels; i++) {
+                       max_power = geo->a[i].max_power;
+                       tx_power.channels_tx_power[i].channel_number =
+                           geo->a[i].channel;
+                       tx_power.channels_tx_power[i].tx_power = max_power ?
+                           min(max_power, priv->tx_power) : priv->tx_power;
+               }
+               if (ipw_send_tx_power(priv, &tx_power))
+                       return -EIO;
+       }
        return 0;
  }
  
@@@ -1505,13 -2257,8 +2258,8 @@@ static int ipw_send_rts_threshold(struc
                return -1;
        }
  
-       memcpy(&cmd.param, &rts_threshold, sizeof(rts_threshold));
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send RTS_THRESHOLD command\n");
-               return -1;
-       }
-       return 0;
+       memcpy(cmd.param, &rts_threshold, sizeof(rts_threshold));
+       return ipw_send_cmd(priv, &cmd);
  }
  
  static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
                return -1;
        }
  
-       memcpy(&cmd.param, &frag_threshold, sizeof(frag_threshold));
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send FRAG_THRESHOLD command\n");
-               return -1;
-       }
-       return 0;
+       memcpy(cmd.param, &frag_threshold, sizeof(frag_threshold));
+       return ipw_send_cmd(priv, &cmd);
  }
  
  static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
                break;
        }
  
-       if (ipw_send_cmd(priv, &cmd)) {
-               IPW_ERROR("failed to send POWER_MODE command\n");
-               return -1;
-       }
-       return 0;
+       return ipw_send_cmd(priv, &cmd);
  }
  
- /*
-  * The IPW device contains a Microwire compatible EEPROM that stores
+ static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
+ {
+       struct ipw_retry_limit retry_limit = {
+               .short_retry_limit = slimit,
+               .long_retry_limit = llimit
+       };
+       struct host_cmd cmd = {
+               .cmd = IPW_CMD_RETRY_LIMIT,
+               .len = sizeof(retry_limit)
+       };
+       if (!priv) {
+               IPW_ERROR("Invalid args\n");
+               return -1;
+       }
+       memcpy(cmd.param, &retry_limit, sizeof(retry_limit));
+       return ipw_send_cmd(priv, &cmd);
+ }
+ /*
+  * The IPW device contains a Microwire compatible EEPROM that stores
   * various data like the MAC address.  Usually the firmware has exclusive
   * access to the eeprom, but during device initialization (before the
   * device driver has sent the HostComplete command to the firmware) the
@@@ -1672,8 -2429,7 +2430,7 @@@ static u16 eeprom_read_u16(struct ipw_p
  /* data's copy of the eeprom data                                 */
  static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
  {
-       u8 *ee = (u8 *) priv->eeprom;
-       memcpy(mac, &ee[EEPROM_MAC_ADDRESS], 6);
+       memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
  }
  
  /*
@@@ -1693,7 -2449,7 +2450,7 @@@ static void ipw_eeprom_init_sram(struc
  
        /* read entire contents of eeprom into private buffer */
        for (i = 0; i < 128; i++)
-               eeprom[i] = eeprom_read_u16(priv, (u8) i);
+               eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
  
        /*
           If the data looks correct, then copy it to our private
                IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
  
                /* write the eeprom data to sram */
-               for (i = 0; i < CX2_EEPROM_IMAGE_SIZE; i++)
+               for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
                        ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
  
                /* Do not load eeprom data on fatal error or suspend */
@@@ -1724,14 -2480,14 +2481,14 @@@ static inline void ipw_zero_memory(stru
        count >>= 2;
        if (!count)
                return;
-       _ipw_write32(priv, CX2_AUTOINC_ADDR, start);
+       _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
        while (count--)
-               _ipw_write32(priv, CX2_AUTOINC_DATA, 0);
+               _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
  }
  
  static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
  {
-       ipw_zero_memory(priv, CX2_SHARED_SRAM_DMA_CONTROL,
+       ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
                        CB_NUMBER_OF_ELEMENTS_SMALL *
                        sizeof(struct command_block));
  }
@@@ -1745,7 -2501,7 +2502,7 @@@ static int ipw_fw_dma_enable(struct ipw
        ipw_fw_dma_reset_command_blocks(priv);
  
        /* Write CB base address */
-       ipw_write_reg32(priv, CX2_DMA_I_CB_BASE, CX2_SHARED_SRAM_DMA_CONTROL);
+       ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
  
        IPW_DEBUG_FW("<< : \n");
        return 0;
@@@ -1759,7 -2515,7 +2516,7 @@@ static void ipw_fw_dma_abort(struct ipw
  
        //set the Stop and Abort bit
        control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
-       ipw_write_reg32(priv, CX2_DMA_I_DMA_CONTROL, control);
+       ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
        priv->sram_desc.last_cb_index = 0;
  
        IPW_DEBUG_FW("<< \n");
@@@ -1769,7 -2525,7 +2526,7 @@@ static int ipw_fw_dma_write_command_blo
                                          struct command_block *cb)
  {
        u32 address =
-           CX2_SHARED_SRAM_DMA_CONTROL +
+           IPW_SHARED_SRAM_DMA_CONTROL +
            (sizeof(struct command_block) * index);
        IPW_DEBUG_FW(">> :\n");
  
@@@ -1793,13 -2549,13 +2550,13 @@@ static int ipw_fw_dma_kick(struct ipw_p
                                               &priv->sram_desc.cb_list[index]);
  
        /* Enable the DMA in the CSR register */
-       ipw_clear_bit(priv, CX2_RESET_REG,
-                     CX2_RESET_REG_MASTER_DISABLED |
-                     CX2_RESET_REG_STOP_MASTER);
+       ipw_clear_bit(priv, IPW_RESET_REG,
+                     IPW_RESET_REG_MASTER_DISABLED |
+                     IPW_RESET_REG_STOP_MASTER);
  
        /* Set the Start bit. */
        control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
-       ipw_write_reg32(priv, CX2_DMA_I_DMA_CONTROL, control);
+       ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
  
        IPW_DEBUG_FW("<< :\n");
        return 0;
@@@ -1812,12 -2568,12 +2569,12 @@@ static void ipw_fw_dma_dump_command_blo
        u32 cb_fields_address = 0;
  
        IPW_DEBUG_FW(">> :\n");
-       address = ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB);
+       address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
        IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
  
        /* Read the DMA Controlor register */
-       register_value = ipw_read_reg32(priv, CX2_DMA_I_DMA_CONTROL);
-       IPW_DEBUG_FW_INFO("CX2_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
+       register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
+       IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
  
        /* Print the CB values */
        cb_fields_address = address;
@@@ -1846,9 -2602,9 +2603,9 @@@ static int ipw_fw_dma_command_block_ind
        u32 current_cb_index = 0;
  
        IPW_DEBUG_FW("<< :\n");
-       current_cb_address = ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB);
+       current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
  
-       current_cb_index = (current_cb_address - CX2_SHARED_SRAM_DMA_CONTROL) /
+       current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
            sizeof(struct command_block);
  
        IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
@@@ -1977,8 -2733,8 +2734,8 @@@ static int ipw_fw_dma_wait(struct ipw_p
        ipw_fw_dma_abort(priv);
  
        /*Disable the DMA in the CSR register */
-       ipw_set_bit(priv, CX2_RESET_REG,
-                   CX2_RESET_REG_MASTER_DISABLED | CX2_RESET_REG_STOP_MASTER);
+       ipw_set_bit(priv, IPW_RESET_REG,
+                   IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
  
        IPW_DEBUG_FW("<< dmaWaitSync \n");
        return 0;
@@@ -1988,6 -2744,9 +2745,9 @@@ static void ipw_remove_current_network(
  {
        struct list_head *element, *safe;
        struct ieee80211_network *network = NULL;
+       unsigned long flags;
+       spin_lock_irqsave(&priv->ieee->lock, flags);
        list_for_each_safe(element, safe, &priv->ieee->network_list) {
                network = list_entry(element, struct ieee80211_network, list);
                if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
                                      &priv->ieee->network_free_list);
                }
        }
+       spin_unlock_irqrestore(&priv->ieee->lock, flags);
  }
  
  /**
@@@ -2038,10 -2798,10 +2799,10 @@@ static int ipw_stop_master(struct ipw_p
  
        IPW_DEBUG_TRACE(">> \n");
        /* stop master. typical delay - 0 */
-       ipw_set_bit(priv, CX2_RESET_REG, CX2_RESET_REG_STOP_MASTER);
+       ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
  
-       rc = ipw_poll_bit(priv, CX2_RESET_REG,
-                         CX2_RESET_REG_MASTER_DISABLED, 100);
+       rc = ipw_poll_bit(priv, IPW_RESET_REG,
+                         IPW_RESET_REG_MASTER_DISABLED, 100);
        if (rc < 0) {
                IPW_ERROR("stop master failed in 10ms\n");
                return -1;
@@@ -2057,7 -2817,7 +2818,7 @@@ static void ipw_arc_release(struct ipw_
        IPW_DEBUG_TRACE(">> \n");
        mdelay(5);
  
-       ipw_clear_bit(priv, CX2_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
+       ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
  
        /* no one knows timing, for safety add some delay */
        mdelay(5);
@@@ -2074,13 -2834,12 +2835,12 @@@ struct fw_chunk 
  };
  
  #define IPW_FW_MAJOR_VERSION 2
- #define IPW_FW_MINOR_VERSION 2
+ #define IPW_FW_MINOR_VERSION 4
  
  #define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
  #define IPW_FW_MAJOR(x) (x & 0xff)
  
- #define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | \
-                          IPW_FW_MAJOR_VERSION)
+ #define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION)
  
  #define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
  "." __stringify(IPW_FW_MINOR_VERSION) "-"
@@@ -2108,8 -2867,8 +2868,8 @@@ static int ipw_load_ucode(struct ipw_pr
  
  //      spin_lock_irqsave(&priv->lock, flags);
  
-       for (addr = CX2_SHARED_LOWER_BOUND;
-            addr < CX2_REGISTER_DOMAIN1_END; addr += 4) {
+       for (addr = IPW_SHARED_LOWER_BOUND;
+            addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
                ipw_write32(priv, addr, 0);
        }
  
        /* destroy DMA queues */
        /* reset sequence */
  
-       ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_ON);
+       ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
        ipw_arc_release(priv);
-       ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_OFF);
+       ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
        mdelay(1);
  
        /* reset PHY */
-       ipw_write_reg32(priv, CX2_INTERNAL_CMD_EVENT, CX2_BASEBAND_POWER_DOWN);
+       ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
        mdelay(1);
  
-       ipw_write_reg32(priv, CX2_INTERNAL_CMD_EVENT, 0);
+       ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
        mdelay(1);
  
        /* enable ucode store */
         */
        /* load new ipw uCode */
        for (i = 0; i < len / 2; i++)
-               ipw_write_reg16(priv, CX2_BASEBAND_CONTROL_STORE, image[i]);
+               ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
+                               cpu_to_le16(image[i]));
  
        /* enable DINO */
-       ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0);
-       ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
+       ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
+       ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
  
        /* this is where the igx / win driver deveates from the VAP driver. */
  
        /* wait for alive response */
        for (i = 0; i < 100; i++) {
                /* poll for incoming data */
-               cr = ipw_read_reg8(priv, CX2_BASEBAND_CONTROL_STATUS);
+               cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
                if (cr & DINO_RXFIFO_DATA)
                        break;
                mdelay(1);
  
                for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
                        response_buffer[i] =
-                           ipw_read_reg32(priv, CX2_BASEBAND_RX_FIFO_READ);
+                           le32_to_cpu(ipw_read_reg32(priv,
+                                                      IPW_BASEBAND_RX_FIFO_READ));
                memcpy(&priv->dino_alive, response_buffer,
                       sizeof(priv->dino_alive));
                if (priv->dino_alive.alive_command == 1
  
        /* disable DINO, otherwise for some reason
           firmware have problem getting alive resp. */
-       ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0);
+       ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
  
  //      spin_unlock_irqrestore(&priv->lock, flags);
  
@@@ -2237,13 -2998,14 +2999,14 @@@ static int ipw_load_firmware(struct ipw
                 * offeset*/
                /* Dma loading */
                rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
-                                          chunk->address, chunk->length);
+                                          le32_to_cpu(chunk->address),
+                                          le32_to_cpu(chunk->length));
                if (rc) {
                        IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
                        goto out;
                }
  
-               offset += chunk->length;
+               offset += le32_to_cpu(chunk->length);
        } while (offset < len);
  
        /* Run the DMA and wait for the answer */
@@@ -2269,16 -3031,16 +3032,16 @@@ static int ipw_stop_nic(struct ipw_pri
        int rc = 0;
  
        /* stop */
-       ipw_write32(priv, CX2_RESET_REG, CX2_RESET_REG_STOP_MASTER);
+       ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
  
-       rc = ipw_poll_bit(priv, CX2_RESET_REG,
-                         CX2_RESET_REG_MASTER_DISABLED, 500);
+       rc = ipw_poll_bit(priv, IPW_RESET_REG,
+                         IPW_RESET_REG_MASTER_DISABLED, 500);
        if (rc < 0) {
                IPW_ERROR("wait for reg master disabled failed\n");
                return rc;
        }
  
-       ipw_set_bit(priv, CX2_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
+       ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
  
        return rc;
  }
@@@ -2288,14 -3050,14 +3051,14 @@@ static void ipw_start_nic(struct ipw_pr
        IPW_DEBUG_TRACE(">>\n");
  
        /* prvHwStartNic  release ARC */
-       ipw_clear_bit(priv, CX2_RESET_REG,
-                     CX2_RESET_REG_MASTER_DISABLED |
-                     CX2_RESET_REG_STOP_MASTER |
+       ipw_clear_bit(priv, IPW_RESET_REG,
+                     IPW_RESET_REG_MASTER_DISABLED |
+                     IPW_RESET_REG_STOP_MASTER |
                      CBD_RESET_REG_PRINCETON_RESET);
  
        /* enable power management */
-       ipw_set_bit(priv, CX2_GP_CNTRL_RW,
-                   CX2_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
+       ipw_set_bit(priv, IPW_GP_CNTRL_RW,
+                   IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
  
        IPW_DEBUG_TRACE("<<\n");
  }
@@@ -2308,25 -3070,25 +3071,25 @@@ static int ipw_init_nic(struct ipw_pri
        /* reset */
        /*prvHwInitNic */
        /* set "initialization complete" bit to move adapter to D0 state */
-       ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_INIT_DONE);
+       ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
  
        /* low-level PLL activation */
-       ipw_write32(priv, CX2_READ_INT_REGISTER,
-                   CX2_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
+       ipw_write32(priv, IPW_READ_INT_REGISTER,
+                   IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
  
        /* wait for clock stabilization */
-       rc = ipw_poll_bit(priv, CX2_GP_CNTRL_RW,
-                         CX2_GP_CNTRL_BIT_CLOCK_READY, 250);
+       rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
+                         IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
        if (rc < 0)
                IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
  
        /* assert SW reset */
-       ipw_set_bit(priv, CX2_RESET_REG, CX2_RESET_REG_SW_RESET);
+       ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
  
        udelay(10);
  
        /* set "initialization complete" bit to move adapter to D0 state */
-       ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_INIT_DONE);
+       ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
  
        IPW_DEBUG_TRACE(">>\n");
        return 0;
  static int ipw_reset_nic(struct ipw_priv *priv)
  {
        int rc = 0;
+       unsigned long flags;
  
        IPW_DEBUG_TRACE(">>\n");
  
        rc = ipw_init_nic(priv);
  
+       spin_lock_irqsave(&priv->lock, flags);
        /* Clear the 'host command active' bit... */
        priv->status &= ~STATUS_HCMD_ACTIVE;
        wake_up_interruptible(&priv->wait_command_queue);
+       priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
+       wake_up_interruptible(&priv->wait_state);
+       spin_unlock_irqrestore(&priv->lock, flags);
  
        IPW_DEBUG_TRACE("<<\n");
        return rc;
@@@ -2365,22 -3132,23 +3133,23 @@@ static int ipw_get_fw(struct ipw_priv *
        }
  
        header = (struct fw_header *)(*fw)->data;
-       if (IPW_FW_MAJOR(header->version) != IPW_FW_MAJOR_VERSION) {
+       if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
                IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
                          name,
-                         IPW_FW_MAJOR(header->version), IPW_FW_MAJOR_VERSION);
+                         IPW_FW_MAJOR(le32_to_cpu(header->version)),
+                         IPW_FW_MAJOR_VERSION);
                return -EINVAL;
        }
  
        IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
                       name,
-                      IPW_FW_MAJOR(header->version),
-                      IPW_FW_MINOR(header->version),
+                      IPW_FW_MAJOR(le32_to_cpu(header->version)),
+                      IPW_FW_MINOR(le32_to_cpu(header->version)),
                       (*fw)->size - sizeof(struct fw_header));
        return 0;
  }
  
- #define CX2_RX_BUF_SIZE (3000)
+ #define IPW_RX_BUF_SIZE (3000)
  
  static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
                                      struct ipw_rx_queue *rxq)
                 * to an SKB, so we need to unmap and free potential storage */
                if (rxq->pool[i].skb != NULL) {
                        pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
-                                        CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
+                                        IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
                        dev_kfree_skb(rxq->pool[i].skb);
+                       rxq->pool[i].skb = NULL;
                }
                list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
        }
@@@ -2418,6 -3187,19 +3188,19 @@@ static int fw_loaded = 0
  static const struct firmware *bootfw = NULL;
  static const struct firmware *firmware = NULL;
  static const struct firmware *ucode = NULL;
+ static void free_firmware(void)
+ {
+       if (fw_loaded) {
+               release_firmware(bootfw);
+               release_firmware(ucode);
+               release_firmware(firmware);
+               bootfw = ucode = firmware = NULL;
+               fw_loaded = 0;
+       }
+ }
+ #else
+ #define free_firmware() do {} while (0)
  #endif
  
  static int ipw_load(struct ipw_priv *priv)
                        rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
                        break;
  
- #ifdef CONFIG_IPW_PROMISC
+ #ifdef CONFIG_IPW2200_MONITOR
                case IW_MODE_MONITOR:
                        rc = ipw_get_fw(priv, &ucode,
-                                       IPW_FW_NAME("ibss_ucode"));
+                                       IPW_FW_NAME("sniffer_ucode"));
                        if (rc)
                                goto error;
  
  
        retry:
        /* Ensure interrupts are disabled */
-       ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
+       ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
        priv->status &= ~STATUS_INT_ENABLED;
  
        /* ack pending interrupts */
-       ipw_write32(priv, CX2_INTA_RW, CX2_INTA_MASK_ALL);
+       ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
  
        ipw_stop_nic(priv);
  
                goto error;
        }
  
-       ipw_zero_memory(priv, CX2_NIC_SRAM_LOWER_BOUND,
-                       CX2_NIC_SRAM_UPPER_BOUND - CX2_NIC_SRAM_LOWER_BOUND);
+       ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
+                       IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
  
        /* DMA the initial boot firmware into the device */
        rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
                               bootfw->size - sizeof(struct fw_header));
        if (rc < 0) {
-               IPW_ERROR("Unable to load boot firmware\n");
+               IPW_ERROR("Unable to load boot firmware: %d\n", rc);
                goto error;
        }
  
        ipw_start_nic(priv);
  
        /* wait for the device to finish it's initial startup sequence */
-       rc = ipw_poll_bit(priv, CX2_INTA_RW,
-                         CX2_INTA_BIT_FW_INITIALIZATION_DONE, 500);
+       rc = ipw_poll_bit(priv, IPW_INTA_RW,
+                         IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
        if (rc < 0) {
                IPW_ERROR("device failed to boot initial fw image\n");
                goto error;
        IPW_DEBUG_INFO("initial device response after %dms\n", rc);
  
        /* ack fw init done interrupt */
-       ipw_write32(priv, CX2_INTA_RW, CX2_INTA_BIT_FW_INITIALIZATION_DONE);
+       ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
  
        /* DMA the ucode into the device */
        rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
                            ucode->size - sizeof(struct fw_header));
        if (rc < 0) {
-               IPW_ERROR("Unable to load ucode\n");
+               IPW_ERROR("Unable to load ucode: %d\n", rc);
                goto error;
        }
  
                               sizeof(struct fw_header),
                               firmware->size - sizeof(struct fw_header));
        if (rc < 0) {
-               IPW_ERROR("Unable to load firmware\n");
+               IPW_ERROR("Unable to load firmware: %d\n", rc);
                goto error;
        }
  
        }
  
        /* Ensure interrupts are disabled */
-       ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
+       ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
+       /* ack pending interrupts */
+       ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
  
        /* kick start the device */
        ipw_start_nic(priv);
  
-       if (ipw_read32(priv, CX2_INTA_RW) & CX2_INTA_BIT_PARITY_ERROR) {
+       if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
                if (retries > 0) {
                        IPW_WARNING("Parity error.  Retrying init.\n");
                        retries--;
        }
  
        /* wait for the device */
-       rc = ipw_poll_bit(priv, CX2_INTA_RW,
-                         CX2_INTA_BIT_FW_INITIALIZATION_DONE, 500);
+       rc = ipw_poll_bit(priv, IPW_INTA_RW,
+                         IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
        if (rc < 0) {
                IPW_ERROR("device failed to start after 500ms\n");
                goto error;
        IPW_DEBUG_INFO("device response after %dms\n", rc);
  
        /* ack fw init done interrupt */
-       ipw_write32(priv, CX2_INTA_RW, CX2_INTA_BIT_FW_INITIALIZATION_DONE);
+       ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
  
        /* read eeprom data and initialize the eeprom region of sram */
        priv->eeprom_delay = 1;
        /* Ensure our queue has valid packets */
        ipw_rx_queue_replenish(priv);
  
-       ipw_write32(priv, CX2_RX_READ_INDEX, priv->rxq->read);
+       ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
  
        /* ack pending interrupts */
-       ipw_write32(priv, CX2_INTA_RW, CX2_INTA_MASK_ALL);
+       ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
  
  #ifndef CONFIG_PM
        release_firmware(bootfw);
@@@ -2756,16 -3540,18 +3541,18 @@@ static void ipw_queue_tx_free_tfd(struc
                return;
  
        /* sanity check */
-       if (bd->u.data.num_chunks > NUM_TFD_CHUNKS) {
-               IPW_ERROR("Too many chunks: %i\n", bd->u.data.num_chunks);
+       if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
+               IPW_ERROR("Too many chunks: %i\n",
+                         le32_to_cpu(bd->u.data.num_chunks));
                /** @todo issue fatal error, it is quite serious situation */
                return;
        }
  
        /* unmap chunks if any */
-       for (i = 0; i < bd->u.data.num_chunks; i++) {
-               pci_unmap_single(dev, bd->u.data.chunk_ptr[i],
-                                bd->u.data.chunk_len[i], PCI_DMA_TODEVICE);
+       for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
+               pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
+                                le16_to_cpu(bd->u.data.chunk_len[i]),
+                                PCI_DMA_TODEVICE);
                if (txq->txb[txq->q.last_used]) {
                        ieee80211_txb_free(txq->txb[txq->q.last_used]);
                        txq->txb[txq->q.last_used] = NULL;
@@@ -2822,21 -3608,6 +3609,6 @@@ static void ipw_tx_queue_free(struct ip
        ipw_queue_tx_free(priv, &priv->txq[3]);
  }
  
- static void inline __maybe_wake_tx(struct ipw_priv *priv)
- {
-       if (netif_running(priv->net_dev)) {
-               switch (priv->port_type) {
-               case DCR_TYPE_MU_BSS:
-               case DCR_TYPE_MU_IBSS:
-                       if (!(priv->status & STATUS_ASSOCIATED)) {
-                               return;
-                       }
-               }
-               netif_wake_queue(priv->net_dev);
-       }
- }
  static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
  {
        /* First 3 bytes are manufacturer */
@@@ -2899,7 -3670,13 +3671,13 @@@ static void ipw_send_disassociate(struc
  {
        int err;
  
-       if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))) {
+       if (priv->status & STATUS_ASSOCIATING) {
+               IPW_DEBUG_ASSOC("Disassociating while associating.\n");
+               queue_work(priv->workqueue, &priv->disassociate);
+               return;
+       }
+       if (!(priv->status & STATUS_ASSOCIATED)) {
                IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
                return;
        }
                priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
        else
                priv->assoc_request.assoc_type = HC_DISASSOCIATE;
        err = ipw_send_associate(priv, &priv->assoc_request);
        if (err) {
                IPW_DEBUG_HC("Attempt to send [dis]associate command "
  
  }
  
- static void ipw_disassociate(void *data)
+ static int ipw_disassociate(void *data)
  {
+       struct ipw_priv *priv = data;
+       if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
+               return 0;
        ipw_send_disassociate(data, 0);
+       return 1;
  }
  
- static void notify_wx_assoc_event(struct ipw_priv *priv)
+ static void ipw_bg_disassociate(void *data)
  {
-       union iwreq_data wrqu;
-       wrqu.ap_addr.sa_family = ARPHRD_ETHER;
-       if (priv->status & STATUS_ASSOCIATED)
-               memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
-       else
-               memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
-       wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_disassociate(data);
+       up(&priv->sem);
+ }
+ static void ipw_system_config(void *data)
+ {
+       struct ipw_priv *priv = data;
+       ipw_send_system_config(priv, &priv->sys_config);
  }
  
  struct ipw_status_code {
@@@ -2998,7 -3783,7 +3784,7 @@@ static const char *ipw_get_status_code(
  {
        int i;
        for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
-               if (ipw_status_codes[i].status == status)
+               if (ipw_status_codes[i].status == (status & 0xff))
                        return ipw_status_codes[i].reason;
        return "Unknown status value.";
  }
@@@ -3077,18 -3862,30 +3863,30 @@@ static inline u32 ipw_get_max_rate(stru
        while (i && !(mask & i))
                i >>= 1;
        switch (i) {
-       case IEEE80211_CCK_RATE_1MB_MASK:       return 1000000;
-       case IEEE80211_CCK_RATE_2MB_MASK:       return 2000000;
-       case IEEE80211_CCK_RATE_5MB_MASK:       return 5500000;
-       case IEEE80211_OFDM_RATE_6MB_MASK:      return 6000000;
-       case IEEE80211_OFDM_RATE_9MB_MASK:      return 9000000;
-       case IEEE80211_CCK_RATE_11MB_MASK:      return 11000000;
-       case IEEE80211_OFDM_RATE_12MB_MASK:     return 12000000;
-       case IEEE80211_OFDM_RATE_18MB_MASK:     return 18000000;
-       case IEEE80211_OFDM_RATE_24MB_MASK:     return 24000000;
-       case IEEE80211_OFDM_RATE_36MB_MASK:     return 36000000;
-       case IEEE80211_OFDM_RATE_48MB_MASK:     return 48000000;
-       case IEEE80211_OFDM_RATE_54MB_MASK:     return 54000000;
+       case IEEE80211_CCK_RATE_1MB_MASK:
+               return 1000000;
+       case IEEE80211_CCK_RATE_2MB_MASK:
+               return 2000000;
+       case IEEE80211_CCK_RATE_5MB_MASK:
+               return 5500000;
+       case IEEE80211_OFDM_RATE_6MB_MASK:
+               return 6000000;
+       case IEEE80211_OFDM_RATE_9MB_MASK:
+               return 9000000;
+       case IEEE80211_CCK_RATE_11MB_MASK:
+               return 11000000;
+       case IEEE80211_OFDM_RATE_12MB_MASK:
+               return 12000000;
+       case IEEE80211_OFDM_RATE_18MB_MASK:
+               return 18000000;
+       case IEEE80211_OFDM_RATE_24MB_MASK:
+               return 24000000;
+       case IEEE80211_OFDM_RATE_36MB_MASK:
+               return 36000000;
+       case IEEE80211_OFDM_RATE_48MB_MASK:
+               return 48000000;
+       case IEEE80211_OFDM_RATE_54MB_MASK:
+               return 54000000;
        }
  
        if (priv->ieee->mode == IEEE_B)
@@@ -3116,25 -3913,35 +3914,35 @@@ static u32 ipw_get_current_rate(struct 
                return ipw_get_max_rate(priv);
  
        switch (rate) {
-       case IPW_TX_RATE_1MB:   return 1000000;
-       case IPW_TX_RATE_2MB:   return 2000000;
-       case IPW_TX_RATE_5MB:   return 5500000;
-       case IPW_TX_RATE_6MB:   return 6000000;
-       case IPW_TX_RATE_9MB:   return 9000000;
-       case IPW_TX_RATE_11MB:  return 11000000;
-       case IPW_TX_RATE_12MB:  return 12000000;
-       case IPW_TX_RATE_18MB:  return 18000000;
-       case IPW_TX_RATE_24MB:  return 24000000;
-       case IPW_TX_RATE_36MB:  return 36000000;
-       case IPW_TX_RATE_48MB:  return 48000000;
-       case IPW_TX_RATE_54MB:  return 54000000;
+       case IPW_TX_RATE_1MB:
+               return 1000000;
+       case IPW_TX_RATE_2MB:
+               return 2000000;
+       case IPW_TX_RATE_5MB:
+               return 5500000;
+       case IPW_TX_RATE_6MB:
+               return 6000000;
+       case IPW_TX_RATE_9MB:
+               return 9000000;
+       case IPW_TX_RATE_11MB:
+               return 11000000;
+       case IPW_TX_RATE_12MB:
+               return 12000000;
+       case IPW_TX_RATE_18MB:
+               return 18000000;
+       case IPW_TX_RATE_24MB:
+               return 24000000;
+       case IPW_TX_RATE_36MB:
+               return 36000000;
+       case IPW_TX_RATE_48MB:
+               return 48000000;
+       case IPW_TX_RATE_54MB:
+               return 54000000;
        }
  
        return 0;
  }
  
- #define PERFECT_RSSI (-50)
- #define WORST_RSSI   (-85)
  #define IPW_STATS_INTERVAL (2 * HZ)
  static void ipw_gather_stats(struct ipw_priv *priv)
  {
        s16 rssi;
        u32 beacon_quality, signal_quality, tx_quality, rx_quality,
            rate_quality;
+       u32 max_rate;
  
        if (!(priv->status & STATUS_ASSOCIATED)) {
                priv->quality = 0;
                        beacon_quality, missed_beacons_percent);
  
        priv->last_rate = ipw_get_current_rate(priv);
-       rate_quality = priv->last_rate * 40 / priv->last_rate + 60;
+       max_rate = ipw_get_max_rate(priv);
+       rate_quality = priv->last_rate * 40 / max_rate + 60;
        IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
                        rate_quality, priv->last_rate / 1000000);
  
                        tx_quality, tx_failures_delta, tx_packets_delta);
  
        rssi = average_value(&priv->average_rssi);
-       if (rssi > PERFECT_RSSI)
+       signal_quality =
+           (100 *
+            (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
+            (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
+            (priv->ieee->perfect_rssi - rssi) *
+            (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
+             62 * (priv->ieee->perfect_rssi - rssi))) /
+           ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
+            (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
+       if (signal_quality > 100)
                signal_quality = 100;
-       else if (rssi < WORST_RSSI)
+       else if (signal_quality < 1)
                signal_quality = 0;
-       else
-               signal_quality = (rssi - WORST_RSSI) * 100 /
-                   (PERFECT_RSSI - WORST_RSSI);
        IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
                        signal_quality, rssi);
  
                           IPW_STATS_INTERVAL);
  }
  
+ static void ipw_bg_gather_stats(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_gather_stats(data);
+       up(&priv->sem);
+ }
+ /* Missed beacon behavior:
+  * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
+  * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
+  * Above disassociate threshold, give up and stop scanning.
+  * Roaming is disabled if disassociate_threshold <= roaming_threshold  */
+ static inline void ipw_handle_missed_beacon(struct ipw_priv *priv,
+                                           int missed_count)
+ {
+       priv->notif_missed_beacons = missed_count;
+       if (missed_count > priv->disassociate_threshold &&
+           priv->status & STATUS_ASSOCIATED) {
+               /* If associated and we've hit the missed
+                * beacon threshold, disassociate, turn
+                * off roaming, and abort any active scans */
+               IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
+                         IPW_DL_STATE | IPW_DL_ASSOC,
+                         "Missed beacon: %d - disassociate\n", missed_count);
+               priv->status &= ~STATUS_ROAMING;
+               if (priv->status & STATUS_SCANNING) {
+                       IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
+                                 IPW_DL_STATE,
+                                 "Aborting scan with missed beacon.\n");
+                       queue_work(priv->workqueue, &priv->abort_scan);
+               }
+               queue_work(priv->workqueue, &priv->disassociate);
+               return;
+       }
+       if (priv->status & STATUS_ROAMING) {
+               /* If we are currently roaming, then just
+                * print a debug statement... */
+               IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
+                         "Missed beacon: %d - roam in progress\n",
+                         missed_count);
+               return;
+       }
+       if (missed_count > priv->roaming_threshold &&
+           missed_count <= priv->disassociate_threshold) {
+               /* If we are not already roaming, set the ROAM
+                * bit in the status and kick off a scan.
+                * This can happen several times before we reach
+                * disassociate_threshold. */
+               IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
+                         "Missed beacon: %d - initiate "
+                         "roaming\n", missed_count);
+               if (!(priv->status & STATUS_ROAMING)) {
+                       priv->status |= STATUS_ROAMING;
+                       if (!(priv->status & STATUS_SCANNING))
+                               queue_work(priv->workqueue,
+                                          &priv->request_scan);
+               }
+               return;
+       }
+       if (priv->status & STATUS_SCANNING) {
+               /* Stop scan to keep fw from getting
+                * stuck (only if we aren't roaming --
+                * otherwise we'll never scan more than 2 or 3
+                * channels..) */
+               IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
+                         "Aborting scan with missed beacon.\n");
+               queue_work(priv->workqueue, &priv->abort_scan);
+       }
+       IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
+ }
  /**
   * Handle host notification packet.
   * Called from interrupt routine
  static inline void ipw_rx_notification(struct ipw_priv *priv,
                                       struct ipw_rx_notification *notif)
  {
+       notif->size = le16_to_cpu(notif->size);
        IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
  
        switch (notif->subtype) {
  
                                        priv->status &= ~STATUS_ASSOCIATING;
                                        priv->status |= STATUS_ASSOCIATED;
-                                       netif_carrier_on(priv->net_dev);
-                                       if (netif_queue_stopped(priv->net_dev)) {
-                                               IPW_DEBUG_NOTIF
-                                                   ("waking queue\n");
-                                               netif_wake_queue(priv->net_dev);
-                                       } else {
-                                               IPW_DEBUG_NOTIF
-                                                   ("starting queue\n");
-                                               netif_start_queue(priv->
-                                                                 net_dev);
+                                       queue_work(priv->workqueue,
+                                                  &priv->system_config);
+ #ifdef CONFIG_IPW_QOS
+ #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
+                        le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
+                                       if ((priv->status & STATUS_AUTH) &&
+                                           (IPW_GET_PACKET_STYPE(&notif->u.raw)
+                                            == IEEE80211_STYPE_ASSOC_RESP)) {
+                                               if ((sizeof
+                                                    (struct
+                                                     ieee80211_assoc_response)
+                                                    <= notif->size)
+                                                   && (notif->size <= 2314)) {
+                                                       struct
+                                                       ieee80211_rx_stats
+                                                           stats = {
+                                                               .len =
+                                                                   notif->
+                                                                   size - 1,
+                                                       };
+                                                       IPW_DEBUG_QOS
+                                                           ("QoS Associate "
+                                                            "size %d\n",
+                                                            notif->size);
+                                                       ieee80211_rx_mgt(priv->
+                                                                        ieee,
+                                                                        (struct
+                                                                         ieee80211_hdr_4addr
+                                                                         *)
+                                                                        &notif->u.raw, &stats);
+                                               }
                                        }
+ #endif
  
-                                       ipw_reset_stats(priv);
-                                       /* Ensure the rate is updated immediately */
-                                       priv->last_rate =
-                                           ipw_get_current_rate(priv);
-                                       schedule_work(&priv->gather_stats);
-                                       notify_wx_assoc_event(priv);
+                                       schedule_work(&priv->link_up);
  
- /*                    queue_delayed_work(priv->workqueue,
-                                          &priv->request_scan,
-                                          SCAN_ASSOCIATED_INTERVAL);
- */
                                        break;
                                }
  
                                                      STATUS_AUTH |
                                                      STATUS_ASSOCIATED);
  
-                                               netif_carrier_off(priv->
-                                                                 net_dev);
-                                               netif_stop_queue(priv->net_dev);
-                                               queue_work(priv->workqueue,
-                                                          &priv->request_scan);
-                                               notify_wx_assoc_event(priv);
+                                               schedule_work(&priv->link_down);
                                                break;
                                        }
  
                                }
  
                        case CMAS_INIT:{
+                                       if (priv->status & STATUS_AUTH) {
+                                               struct
+                                                   ieee80211_assoc_response
+                                               *resp;
+                                               resp =
+                                                   (struct
+                                                    ieee80211_assoc_response
+                                                    *)&notif->u.raw;
+                                               IPW_DEBUG(IPW_DL_NOTIF |
+                                                         IPW_DL_STATE |
+                                                         IPW_DL_ASSOC,
+                                                         "association failed (0x%04X): %s\n",
+                                                         ntohs(resp->status),
+                                                         ipw_get_status_code
+                                                         (ntohs
+                                                          (resp->status)));
+                                       }
                                        IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
                                                  IPW_DL_ASSOC,
                                                  "disassociated: '%s' " MAC_FMT
                                            ~(STATUS_DISASSOCIATING |
                                              STATUS_ASSOCIATING |
                                              STATUS_ASSOCIATED | STATUS_AUTH);
+                                       if (priv->assoc_network
+                                           && (priv->assoc_network->
+                                               capability &
+                                               WLAN_CAPABILITY_IBSS))
+                                               ipw_remove_current_network
+                                                   (priv);
  
-                                       netif_stop_queue(priv->net_dev);
-                                       if (!(priv->status & STATUS_ROAMING)) {
-                                               netif_carrier_off(priv->
-                                                                 net_dev);
-                                               notify_wx_assoc_event(priv);
-                                               /* Cancel any queued work ... */
-                                               cancel_delayed_work(&priv->
-                                                                   request_scan);
-                                               cancel_delayed_work(&priv->
-                                                                   adhoc_check);
-                                               /* Queue up another scan... */
-                                               queue_work(priv->workqueue,
-                                                          &priv->request_scan);
-                                               cancel_delayed_work(&priv->
-                                                                   gather_stats);
-                                       } else {
-                                               priv->status |= STATUS_ROAMING;
-                                               queue_work(priv->workqueue,
-                                                          &priv->request_scan);
-                                       }
+                                       schedule_work(&priv->link_down);
  
-                                       ipw_reset_stats(priv);
                                        break;
                                }
  
+                       case CMAS_RX_ASSOC_RESP:
+                               break;
                        default:
                                IPW_ERROR("assoc: unknown (%d)\n",
                                          assoc->state);
                                                  STATUS_AUTH |
                                                  STATUS_ASSOCIATED);
  
-                               netif_carrier_off(priv->net_dev);
-                               netif_stop_queue(priv->net_dev);
-                               queue_work(priv->workqueue,
-                                          &priv->request_scan);
-                               notify_wx_assoc_event(priv);
+                               schedule_work(&priv->link_down);
                                break;
  
                        case CMAS_TX_AUTH_SEQ_1:
                        case CMAS_RX_ASSOC_RESP:
                                IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
                                          IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
                                break;
                        case CMAS_ASSOCIATED:
                                IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
                        priv->status &=
                            ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
  
+                       wake_up_interruptible(&priv->wait_state);
                        cancel_delayed_work(&priv->scan_check);
  
+                       if (priv->status & STATUS_EXIT_PENDING)
+                               break;
+                       priv->ieee->scans++;
+ #ifdef CONFIG_IPW2200_MONITOR
+                       if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
+                               priv->status |= STATUS_SCAN_FORCED;
+                               queue_work(priv->workqueue,
+                                          &priv->request_scan);
+                               break;
+                       }
+                       priv->status &= ~STATUS_SCAN_FORCED;
+ #endif                                /* CONFIG_IPW2200_MONITOR */
                        if (!(priv->status & (STATUS_ASSOCIATED |
                                              STATUS_ASSOCIATING |
                                              STATUS_ROAMING |
                                              STATUS_DISASSOCIATING)))
                                queue_work(priv->workqueue, &priv->associate);
                        else if (priv->status & STATUS_ROAMING) {
-                               /* If a scan completed and we are in roam mode, then
-                                * the scan that completed was the one requested as a
-                                * result of entering roam... so, schedule the
-                                * roam work */
-                               queue_work(priv->workqueue, &priv->roam);
+                               if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
+                                       /* If a scan completed and we are in roam mode, then
+                                        * the scan that completed was the one requested as a
+                                        * result of entering roam... so, schedule the
+                                        * roam work */
+                                       queue_work(priv->workqueue,
+                                                  &priv->roam);
+                               else
+                                       /* Don't schedule if we aborted the scan */
+                                       priv->status &= ~STATUS_ROAMING;
                        } else if (priv->status & STATUS_SCAN_PENDING)
                                queue_work(priv->workqueue,
                                           &priv->request_scan);
-                       priv->ieee->scans++;
+                       else if (priv->config & CFG_BACKGROUND_SCAN
+                                && priv->status & STATUS_ASSOCIATED)
+                               queue_delayed_work(priv->workqueue,
+                                                  &priv->request_scan, HZ);
                        break;
                }
  
        case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
                        struct notif_frag_length *x = &notif->u.frag_len;
  
-                       if (notif->size == sizeof(*x)) {
-                               IPW_ERROR("Frag length: %d\n", x->frag_length);
-                       } else {
+                       if (notif->size == sizeof(*x))
+                               IPW_ERROR("Frag length: %d\n",
+                                         le16_to_cpu(x->frag_length));
+                       else
                                IPW_ERROR("Frag length of wrong size %d "
                                          "(should be %zd)\n",
                                          notif->size, sizeof(*x));
-                       }
                        break;
                }
  
        case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
                        struct notif_link_deterioration *x =
                            &notif->u.link_deterioration;
                        if (notif->size == sizeof(*x)) {
                                IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
                                          "link deterioration: '%s' " MAC_FMT
        case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
                        IPW_ERROR("Dino config\n");
                        if (priv->hcmd
-                           && priv->hcmd->cmd == HOST_CMD_DINO_CONFIG) {
-                               /* TODO: Do anything special? */
-                       } else {
+                           && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
                                IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
-                       }
                        break;
                }
  
                                break;
                        }
  
-                       if (x->state == HOST_NOTIFICATION_STATUS_BEACON_MISSING) {
-                               if (priv->status & STATUS_SCANNING) {
-                                       /* Stop scan to keep fw from getting
-                                        * stuck... */
-                                       queue_work(priv->workqueue,
-                                                  &priv->abort_scan);
-                               }
-                               if (x->number > priv->missed_beacon_threshold &&
-                                   priv->status & STATUS_ASSOCIATED) {
-                                       IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
-                                                 IPW_DL_STATE,
-                                                 "Missed beacon: %d - disassociate\n",
-                                                 x->number);
-                                       queue_work(priv->workqueue,
-                                                  &priv->disassociate);
-                               } else if (x->number > priv->roaming_threshold) {
-                                       IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
-                                                 "Missed beacon: %d - initiate "
-                                                 "roaming\n", x->number);
-                                       queue_work(priv->workqueue,
-                                                  &priv->roam);
-                               } else {
-                                       IPW_DEBUG_NOTIF("Missed beacon: %d\n",
-                                                       x->number);
-                               }
-                               priv->notif_missed_beacons = x->number;
-                       }
+                       if (le32_to_cpu(x->state) ==
+                           HOST_NOTIFICATION_STATUS_BEACON_MISSING)
+                               ipw_handle_missed_beacon(priv,
+                                                        le32_to_cpu(x->
+                                                                    number));
  
                        break;
                }
        case HOST_NOTIFICATION_NOISE_STATS:{
                        if (notif->size == sizeof(u32)) {
                                priv->last_noise =
-                                   (u8) (notif->u.noise.value & 0xff);
+                                   (u8) (le32_to_cpu(notif->u.noise.value) &
+                                         0xff);
                                average_add(&priv->average_noise,
                                            priv->last_noise);
                                break;
@@@ -3731,43 -4636,43 +4637,43 @@@ static int ipw_queue_reset(struct ipw_p
        ipw_tx_queue_free(priv);
        /* Tx CMD queue */
        rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
-                              CX2_TX_CMD_QUEUE_READ_INDEX,
-                              CX2_TX_CMD_QUEUE_WRITE_INDEX,
-                              CX2_TX_CMD_QUEUE_BD_BASE,
-                              CX2_TX_CMD_QUEUE_BD_SIZE);
+                              IPW_TX_CMD_QUEUE_READ_INDEX,
+                              IPW_TX_CMD_QUEUE_WRITE_INDEX,
+                              IPW_TX_CMD_QUEUE_BD_BASE,
+                              IPW_TX_CMD_QUEUE_BD_SIZE);
        if (rc) {
                IPW_ERROR("Tx Cmd queue init failed\n");
                goto error;
        }
        /* Tx queue(s) */
        rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
-                              CX2_TX_QUEUE_0_READ_INDEX,
-                              CX2_TX_QUEUE_0_WRITE_INDEX,
-                              CX2_TX_QUEUE_0_BD_BASE, CX2_TX_QUEUE_0_BD_SIZE);
+                              IPW_TX_QUEUE_0_READ_INDEX,
+                              IPW_TX_QUEUE_0_WRITE_INDEX,
+                              IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
        if (rc) {
                IPW_ERROR("Tx 0 queue init failed\n");
                goto error;
        }
        rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
-                              CX2_TX_QUEUE_1_READ_INDEX,
-                              CX2_TX_QUEUE_1_WRITE_INDEX,
-                              CX2_TX_QUEUE_1_BD_BASE, CX2_TX_QUEUE_1_BD_SIZE);
+                              IPW_TX_QUEUE_1_READ_INDEX,
+                              IPW_TX_QUEUE_1_WRITE_INDEX,
+                              IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
        if (rc) {
                IPW_ERROR("Tx 1 queue init failed\n");
                goto error;
        }
        rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
-                              CX2_TX_QUEUE_2_READ_INDEX,
-                              CX2_TX_QUEUE_2_WRITE_INDEX,
-                              CX2_TX_QUEUE_2_BD_BASE, CX2_TX_QUEUE_2_BD_SIZE);
+                              IPW_TX_QUEUE_2_READ_INDEX,
+                              IPW_TX_QUEUE_2_WRITE_INDEX,
+                              IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
        if (rc) {
                IPW_ERROR("Tx 2 queue init failed\n");
                goto error;
        }
        rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
-                              CX2_TX_QUEUE_3_READ_INDEX,
-                              CX2_TX_QUEUE_3_WRITE_INDEX,
-                              CX2_TX_QUEUE_3_BD_BASE, CX2_TX_QUEUE_3_BD_SIZE);
+                              IPW_TX_QUEUE_3_READ_INDEX,
+                              IPW_TX_QUEUE_3_WRITE_INDEX,
+                              IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
        if (rc) {
                IPW_ERROR("Tx 3 queue init failed\n");
                goto error;
@@@ -3815,9 -4720,10 +4721,10 @@@ static int ipw_queue_tx_reclaim(struct 
                priv->tx_packets++;
        }
        done:
-       if (ipw_queue_space(q) > q->low_mark && qindex >= 0) {
-               __maybe_wake_tx(priv);
-       }
+       if ((ipw_queue_space(q) > q->low_mark) &&
+           (qindex >= 0) &&
+           (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
+               netif_wake_queue(priv->net_dev);
        used = q->first_empty - q->last_used;
        if (used < 0)
                used += q->n_bd;
@@@ -3858,7 -4764,7 +4765,7 @@@ static int ipw_queue_tx_hcmd(struct ipw
   * Rx theory of operation
   *
   * The host allocates 32 DMA target addresses and passes the host address
-  * to the firmware at register CX2_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
+  * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
   * 0 to 31
   *
   * Rx Queue Indexes
@@@ -3942,7 -4848,7 +4849,7 @@@ static void ipw_rx_queue_restock(struc
                rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
                list_del(element);
  
-               ipw_write32(priv, CX2_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
+               ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
                            rxb->dma_addr);
                rxq->queue[rxq->write] = rxb;
                rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
  
        /* If we've added more space for the firmware to place data, tell it */
        if (write != rxq->write)
-               ipw_write32(priv, CX2_RX_WRITE_INDEX, rxq->write);
+               ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
  }
  
  /*
@@@ -3978,7 -4884,7 +4885,7 @@@ static void ipw_rx_queue_replenish(voi
        while (!list_empty(&rxq->rx_used)) {
                element = rxq->rx_used.next;
                rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
-               rxb->skb = alloc_skb(CX2_RX_BUF_SIZE, GFP_ATOMIC);
+               rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
                if (!rxb->skb) {
                        printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
                               priv->net_dev->name);
                rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
                rxb->dma_addr =
                    pci_map_single(priv->pci_dev, rxb->skb->data,
-                                  CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
+                                  IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  
                list_add_tail(&rxb->list, &rxq->rx_free);
                rxq->free_count++;
        ipw_rx_queue_restock(priv);
  }
  
+ static void ipw_bg_rx_queue_replenish(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_rx_queue_replenish(data);
+       up(&priv->sem);
+ }
  /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
   * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
   * This free routine walks the list of POOL entries and if SKB is set to
@@@ -4017,7 -4931,7 +4932,7 @@@ static void ipw_rx_queue_free(struct ip
        for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
                if (rxq->pool[i].skb != NULL) {
                        pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
-                                        CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
+                                        IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
                        dev_kfree_skb(rxq->pool[i].skb);
                }
        }
@@@ -4136,8 -5050,18 +5051,18 @@@ static int ipw_compatible_rates(struct 
        num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
        rates->num_rates = 0;
        for (i = 0; i < num_rates; i++) {
-               if (!ipw_is_rate_in_mask
-                   (priv, network->mode, network->rates[i])) {
+               if (!ipw_is_rate_in_mask(priv, network->mode,
+                                        network->rates[i])) {
+                       if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
+                               IPW_DEBUG_SCAN("Adding masked mandatory "
+                                              "rate %02X\n",
+                                              network->rates[i]);
+                               rates->supported_rates[rates->num_rates++] =
+                                   network->rates[i];
+                               continue;
+                       }
                        IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
                                       network->rates[i], priv->rates_mask);
                        continue;
                rates->supported_rates[rates->num_rates++] = network->rates[i];
        }
  
-       num_rates =
-           min(network->rates_ex_len, (u8) (IPW_MAX_RATES - num_rates));
+       num_rates = min(network->rates_ex_len,
+                       (u8) (IPW_MAX_RATES - num_rates));
        for (i = 0; i < num_rates; i++) {
-               if (!ipw_is_rate_in_mask
-                   (priv, network->mode, network->rates_ex[i])) {
+               if (!ipw_is_rate_in_mask(priv, network->mode,
+                                        network->rates_ex[i])) {
+                       if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
+                               IPW_DEBUG_SCAN("Adding masked mandatory "
+                                              "rate %02X\n",
+                                              network->rates_ex[i]);
+                               rates->supported_rates[rates->num_rates++] =
+                                   network->rates[i];
+                               continue;
+                       }
                        IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
                                       network->rates_ex[i], priv->rates_mask);
                        continue;
                    network->rates_ex[i];
        }
  
-       return rates->num_rates;
+       return 1;
  }
  
  static inline void ipw_copy_rates(struct ipw_supported_rates *dest,
@@@ -4242,19 -5175,18 +5176,18 @@@ struct ipw_network_match 
        struct ipw_supported_rates rates;
  };
  
- static int ipw_best_network(struct ipw_priv *priv,
-                           struct ipw_network_match *match,
-                           struct ieee80211_network *network, int roaming)
+ static int ipw_find_adhoc_network(struct ipw_priv *priv,
+                                 struct ipw_network_match *match,
+                                 struct ieee80211_network *network,
+                                 int roaming)
  {
        struct ipw_supported_rates rates;
  
        /* Verify that this network's capability is compatible with the
         * current mode (AdHoc or Infrastructure) */
-       if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
-            !(network->capability & WLAN_CAPABILITY_ESS)) ||
-           (priv->ieee->iw_mode == IW_MODE_ADHOC &&
+       if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
             !(network->capability & WLAN_CAPABILITY_IBSS))) {
-               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
+               IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
                                "capability mismatch.\n",
                                escape_essid(network->ssid, network->ssid_len),
                                MAC_ARG(network->bssid));
        /* If we do not have an ESSID for this AP, we can not associate with
         * it */
        if (network->flags & NETWORK_EMPTY_ESSID) {
-               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+               IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
                                "because of hidden ESSID.\n",
                                escape_essid(network->ssid, network->ssid_len),
                                MAC_ARG(network->bssid));
                if ((network->ssid_len != match->network->ssid_len) ||
                    memcmp(network->ssid, match->network->ssid,
                           network->ssid_len)) {
-                       IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
+                       IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
                                        "because of non-network ESSID.\n",
                                        escape_essid(network->ssid,
                                                     network->ssid_len),
                     memcmp(network->ssid, priv->essid,
                            min(network->ssid_len, priv->essid_len)))) {
                        char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
                        strncpy(escaped,
                                escape_essid(network->ssid, network->ssid_len),
                                sizeof(escaped));
-                       IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+                       IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
                                        "because of ESSID mismatch: '%s'.\n",
                                        escaped, MAC_ARG(network->bssid),
                                        escape_essid(priv->essid,
  
        /* If the old network rate is better than this one, don't bother
         * testing everything else. */
-       if (match->network && match->network->stats.rssi > network->stats.rssi) {
-               char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
-               strncpy(escaped,
-                       escape_essid(network->ssid, network->ssid_len),
-                       sizeof(escaped));
-               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
-                               "'%s (" MAC_FMT ")' has a stronger signal.\n",
-                               escaped, MAC_ARG(network->bssid),
+       if (network->time_stamp[0] < match->network->time_stamp[0]) {
+               IPW_DEBUG_MERGE("Network '%s excluded because newer than "
+                               "current network.\n",
                                escape_essid(match->network->ssid,
-                                            match->network->ssid_len),
-                               MAC_ARG(match->network->bssid));
+                                            match->network->ssid_len));
                return 0;
-       }
-       /* If this network has already had an association attempt within the
-        * last 3 seconds, do not try and associate again... */
-       if (network->last_associate &&
-           time_after(network->last_associate + (HZ * 5UL), jiffies)) {
-               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
-                               "because of storming (%lu since last "
-                               "assoc attempt).\n",
-                               escape_essid(network->ssid, network->ssid_len),
-                               MAC_ARG(network->bssid),
-                               (jiffies - network->last_associate) / HZ);
+       } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
+               IPW_DEBUG_MERGE("Network '%s excluded because newer than "
+                               "current network.\n",
+                               escape_essid(match->network->ssid,
+                                            match->network->ssid_len));
                return 0;
        }
  
        /* Now go through and see if the requested network is valid... */
        if (priv->ieee->scan_age != 0 &&
-           jiffies - network->last_scanned > priv->ieee->scan_age) {
-               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+           time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
+               IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
                                "because of age: %lums.\n",
                                escape_essid(network->ssid, network->ssid_len),
                                MAC_ARG(network->bssid),
-                               (jiffies - network->last_scanned) / (HZ / 100));
+                               1000 * (jiffies - network->last_scanned) / HZ);
                return 0;
        }
  
        if ((priv->config & CFG_STATIC_CHANNEL) &&
            (network->channel != priv->channel)) {
-               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+               IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
                                "because of channel mismatch: %d != %d.\n",
                                escape_essid(network->ssid, network->ssid_len),
                                MAC_ARG(network->bssid),
        /* Verify privacy compatability */
        if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
            ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
-               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+               IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
                                "because of privacy mismatch: %s != %s.\n",
                                escape_essid(network->ssid, network->ssid_len),
                                MAC_ARG(network->bssid),
-                               priv->capability & CAP_PRIVACY_ON ? "on" :
-                               "off",
-                               network->capability &
-                               WLAN_CAPABILITY_PRIVACY ? "on" : "off");
+                               priv->
+                               capability & CAP_PRIVACY_ON ? "on" : "off",
+                               network->
+                               capability & WLAN_CAPABILITY_PRIVACY ? "on" :
+                               "off");
                return 0;
        }
  
-       if ((priv->config & CFG_STATIC_BSSID) &&
-           memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
-               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
-                               "because of BSSID mismatch: " MAC_FMT ".\n",
-                               escape_essid(network->ssid, network->ssid_len),
+       if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
+               IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
+                               "because of the same BSSID match: " MAC_FMT
+                               ".\n", escape_essid(network->ssid,
+                                                   network->ssid_len),
                                MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
                return 0;
        }
  
        /* Filter out any incompatible freq / mode combinations */
        if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
-               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+               IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
                                "because of invalid frequency/mode "
                                "combination.\n",
                                escape_essid(network->ssid, network->ssid_len),
                return 0;
        }
  
-       ipw_compatible_rates(priv, network, &rates);
+       /* Ensure that the rates supported by the driver are compatible with
+        * this AP, including verification of basic rates (mandatory) */
+       if (!ipw_compatible_rates(priv, network, &rates)) {
+               IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
+                               "because configured rate mask excludes "
+                               "AP mandatory rate.\n",
+                               escape_essid(network->ssid, network->ssid_len),
+                               MAC_ARG(network->bssid));
+               return 0;
+       }
        if (rates.num_rates == 0) {
-               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+               IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
                                "because of no compatible rates.\n",
                                escape_essid(network->ssid, network->ssid_len),
                                MAC_ARG(network->bssid));
        /* Set up 'new' AP to this network */
        ipw_copy_rates(&match->rates, &rates);
        match->network = network;
-       IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
+       IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
                        escape_essid(network->ssid, network->ssid_len),
                        MAC_ARG(network->bssid));
  
        return 1;
  }
  
- static void ipw_adhoc_create(struct ipw_priv *priv,
-                            struct ieee80211_network *network)
+ static void ipw_merge_adhoc_network(void *data)
  {
-       /*
-        * For the purposes of scanning, we can set our wireless mode
-        * to trigger scans across combinations of bands, but when it
-        * comes to creating a new ad-hoc network, we have tell the FW
-        * exactly which band to use.
-        *
-        * We also have the possibility of an invalid channel for the
-        * chossen band.  Attempting to create a new ad-hoc network
-        * with an invalid channel for wireless mode will trigger a
-        * FW fatal error.
-        */
-       network->mode = is_valid_channel(priv->ieee->mode, priv->channel);
-       if (network->mode) {
-               network->channel = priv->channel;
-       } else {
-               IPW_WARNING("Overriding invalid channel\n");
-               if (priv->ieee->mode & IEEE_A) {
-                       network->mode = IEEE_A;
-                       priv->channel = band_a_active_channel[0];
-               } else if (priv->ieee->mode & IEEE_G) {
-                       network->mode = IEEE_G;
-                       priv->channel = band_b_active_channel[0];
-               } else {
-                       network->mode = IEEE_B;
-                       priv->channel = band_b_active_channel[0];
+       struct ipw_priv *priv = data;
+       struct ieee80211_network *network = NULL;
+       struct ipw_network_match match = {
+               .network = priv->assoc_network
+       };
+       if ((priv->status & STATUS_ASSOCIATED) &&
+           (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
+               /* First pass through ROAM process -- look for a better
+                * network */
+               unsigned long flags;
+               spin_lock_irqsave(&priv->ieee->lock, flags);
+               list_for_each_entry(network, &priv->ieee->network_list, list) {
+                       if (network != priv->assoc_network)
+                               ipw_find_adhoc_network(priv, &match, network,
+                                                      1);
+               }
+               spin_unlock_irqrestore(&priv->ieee->lock, flags);
+               if (match.network == priv->assoc_network) {
+                       IPW_DEBUG_MERGE("No better ADHOC in this network to "
+                                       "merge to.\n");
+                       return;
+               }
+               down(&priv->sem);
+               if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
+                       IPW_DEBUG_MERGE("remove network %s\n",
+                                       escape_essid(priv->essid,
+                                                    priv->essid_len));
+                       ipw_remove_current_network(priv);
                }
+               ipw_disassociate(priv);
+               priv->assoc_network = match.network;
+               up(&priv->sem);
+               return;
        }
+ }
  
-       network->channel = priv->channel;
-       priv->config |= CFG_ADHOC_PERSIST;
-       ipw_create_bssid(priv, network->bssid);
-       network->ssid_len = priv->essid_len;
-       memcpy(network->ssid, priv->essid, priv->essid_len);
-       memset(&network->stats, 0, sizeof(network->stats));
+ static int ipw_best_network(struct ipw_priv *priv,
+                           struct ipw_network_match *match,
+                           struct ieee80211_network *network, int roaming)
+ {
+       struct ipw_supported_rates rates;
+       /* Verify that this network's capability is compatible with the
+        * current mode (AdHoc or Infrastructure) */
+       if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
+            !(network->capability & WLAN_CAPABILITY_ESS)) ||
+           (priv->ieee->iw_mode == IW_MODE_ADHOC &&
+            !(network->capability & WLAN_CAPABILITY_IBSS))) {
+               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
+                               "capability mismatch.\n",
+                               escape_essid(network->ssid, network->ssid_len),
+                               MAC_ARG(network->bssid));
+               return 0;
+       }
+       /* If we do not have an ESSID for this AP, we can not associate with
+        * it */
+       if (network->flags & NETWORK_EMPTY_ESSID) {
+               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+                               "because of hidden ESSID.\n",
+                               escape_essid(network->ssid, network->ssid_len),
+                               MAC_ARG(network->bssid));
+               return 0;
+       }
+       if (unlikely(roaming)) {
+               /* If we are roaming, then ensure check if this is a valid
+                * network to try and roam to */
+               if ((network->ssid_len != match->network->ssid_len) ||
+                   memcmp(network->ssid, match->network->ssid,
+                          network->ssid_len)) {
+                       IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
+                                       "because of non-network ESSID.\n",
+                                       escape_essid(network->ssid,
+                                                    network->ssid_len),
+                                       MAC_ARG(network->bssid));
+                       return 0;
+               }
+       } else {
+               /* If an ESSID has been configured then compare the broadcast
+                * ESSID to ours */
+               if ((priv->config & CFG_STATIC_ESSID) &&
+                   ((network->ssid_len != priv->essid_len) ||
+                    memcmp(network->ssid, priv->essid,
+                           min(network->ssid_len, priv->essid_len)))) {
+                       char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
+                       strncpy(escaped,
+                               escape_essid(network->ssid, network->ssid_len),
+                               sizeof(escaped));
+                       IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+                                       "because of ESSID mismatch: '%s'.\n",
+                                       escaped, MAC_ARG(network->bssid),
+                                       escape_essid(priv->essid,
+                                                    priv->essid_len));
+                       return 0;
+               }
+       }
+       /* If the old network rate is better than this one, don't bother
+        * testing everything else. */
+       if (match->network && match->network->stats.rssi > network->stats.rssi) {
+               char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
+               strncpy(escaped,
+                       escape_essid(network->ssid, network->ssid_len),
+                       sizeof(escaped));
+               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
+                               "'%s (" MAC_FMT ")' has a stronger signal.\n",
+                               escaped, MAC_ARG(network->bssid),
+                               escape_essid(match->network->ssid,
+                                            match->network->ssid_len),
+                               MAC_ARG(match->network->bssid));
+               return 0;
+       }
+       /* If this network has already had an association attempt within the
+        * last 3 seconds, do not try and associate again... */
+       if (network->last_associate &&
+           time_after(network->last_associate + (HZ * 3UL), jiffies)) {
+               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+                               "because of storming (%lus since last "
+                               "assoc attempt).\n",
+                               escape_essid(network->ssid, network->ssid_len),
+                               MAC_ARG(network->bssid),
+                               (jiffies - network->last_associate) / HZ);
+               return 0;
+       }
+       /* Now go through and see if the requested network is valid... */
+       if (priv->ieee->scan_age != 0 &&
+           time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
+               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+                               "because of age: %lums.\n",
+                               escape_essid(network->ssid, network->ssid_len),
+                               MAC_ARG(network->bssid),
+                               1000 * (jiffies - network->last_scanned) / HZ);
+               return 0;
+       }
+       if ((priv->config & CFG_STATIC_CHANNEL) &&
+           (network->channel != priv->channel)) {
+               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+                               "because of channel mismatch: %d != %d.\n",
+                               escape_essid(network->ssid, network->ssid_len),
+                               MAC_ARG(network->bssid),
+                               network->channel, priv->channel);
+               return 0;
+       }
+       /* Verify privacy compatability */
+       if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
+           ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
+               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+                               "because of privacy mismatch: %s != %s.\n",
+                               escape_essid(network->ssid, network->ssid_len),
+                               MAC_ARG(network->bssid),
+                               priv->capability & CAP_PRIVACY_ON ? "on" :
+                               "off",
+                               network->capability &
+                               WLAN_CAPABILITY_PRIVACY ? "on" : "off");
+               return 0;
+       }
+       if (!priv->ieee->wpa_enabled && (network->wpa_ie_len > 0 ||
+                                        network->rsn_ie_len > 0)) {
+               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+                               "because of WPA capability mismatch.\n",
+                               escape_essid(network->ssid, network->ssid_len),
+                               MAC_ARG(network->bssid));
+               return 0;
+       }
+       if ((priv->config & CFG_STATIC_BSSID) &&
+           memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
+               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+                               "because of BSSID mismatch: " MAC_FMT ".\n",
+                               escape_essid(network->ssid, network->ssid_len),
+                               MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
+               return 0;
+       }
+       /* Filter out any incompatible freq / mode combinations */
+       if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
+               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+                               "because of invalid frequency/mode "
+                               "combination.\n",
+                               escape_essid(network->ssid, network->ssid_len),
+                               MAC_ARG(network->bssid));
+               return 0;
+       }
+       /* Filter out invalid channel in current GEO */
+       if (!ipw_is_valid_channel(priv->ieee, network->channel)) {
+               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+                               "because of invalid channel in current GEO\n",
+                               escape_essid(network->ssid, network->ssid_len),
+                               MAC_ARG(network->bssid));
+               return 0;
+       }
+       /* Ensure that the rates supported by the driver are compatible with
+        * this AP, including verification of basic rates (mandatory) */
+       if (!ipw_compatible_rates(priv, network, &rates)) {
+               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+                               "because configured rate mask excludes "
+                               "AP mandatory rate.\n",
+                               escape_essid(network->ssid, network->ssid_len),
+                               MAC_ARG(network->bssid));
+               return 0;
+       }
+       if (rates.num_rates == 0) {
+               IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
+                               "because of no compatible rates.\n",
+                               escape_essid(network->ssid, network->ssid_len),
+                               MAC_ARG(network->bssid));
+               return 0;
+       }
+       /* TODO: Perform any further minimal comparititive tests.  We do not
+        * want to put too much policy logic here; intelligent scan selection
+        * should occur within a generic IEEE 802.11 user space tool.  */
+       /* Set up 'new' AP to this network */
+       ipw_copy_rates(&match->rates, &rates);
+       match->network = network;
+       IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
+                       escape_essid(network->ssid, network->ssid_len),
+                       MAC_ARG(network->bssid));
+       return 1;
+ }
+ static void ipw_adhoc_create(struct ipw_priv *priv,
+                            struct ieee80211_network *network)
+ {
+       const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
+       int i;
+       /*
+        * For the purposes of scanning, we can set our wireless mode
+        * to trigger scans across combinations of bands, but when it
+        * comes to creating a new ad-hoc network, we have tell the FW
+        * exactly which band to use.
+        *
+        * We also have the possibility of an invalid channel for the
+        * chossen band.  Attempting to create a new ad-hoc network
+        * with an invalid channel for wireless mode will trigger a
+        * FW fatal error.
+        *
+        */
+       switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
+       case IEEE80211_52GHZ_BAND:
+               network->mode = IEEE_A;
+               i = ipw_channel_to_index(priv->ieee, priv->channel);
+               if (i == -1)
+                       BUG();
+               if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
+                       IPW_WARNING("Overriding invalid channel\n");
+                       priv->channel = geo->a[0].channel;
+               }
+               break;
+       case IEEE80211_24GHZ_BAND:
+               if (priv->ieee->mode & IEEE_G)
+                       network->mode = IEEE_G;
+               else
+                       network->mode = IEEE_B;
+               i = ipw_channel_to_index(priv->ieee, priv->channel);
+               if (i == -1)
+                       BUG();
+               if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
+                       IPW_WARNING("Overriding invalid channel\n");
+                       priv->channel = geo->bg[0].channel;
+               }
+               break;
+       default:
+               IPW_WARNING("Overriding invalid channel\n");
+               if (priv->ieee->mode & IEEE_A) {
+                       network->mode = IEEE_A;
+                       priv->channel = geo->a[0].channel;
+               } else if (priv->ieee->mode & IEEE_G) {
+                       network->mode = IEEE_G;
+                       priv->channel = geo->bg[0].channel;
+               } else {
+                       network->mode = IEEE_B;
+                       priv->channel = geo->bg[0].channel;
+               }
+               break;
+       }
+       network->channel = priv->channel;
+       priv->config |= CFG_ADHOC_PERSIST;
+       ipw_create_bssid(priv, network->bssid);
+       network->ssid_len = priv->essid_len;
+       memcpy(network->ssid, priv->essid, priv->essid_len);
+       memset(&network->stats, 0, sizeof(network->stats));
        network->capability = WLAN_CAPABILITY_IBSS;
+       if (!(priv->config & CFG_PREAMBLE_LONG))
+               network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
        if (priv->capability & CAP_PRIVACY_ON)
                network->capability |= WLAN_CAPABILITY_PRIVACY;
        network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
        network->beacon_interval = 100; /* Default */
        network->listen_interval = 10;  /* Default */
        network->atim_window = 0;       /* Default */
- #ifdef CONFIG_IEEE80211_WPA
        network->wpa_ie_len = 0;
        network->rsn_ie_len = 0;
- #endif                                /* CONFIG_IEEE80211_WPA */
  }
  
- static void ipw_send_wep_keys(struct ipw_priv *priv)
+ static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
+ {
+       struct ipw_tgi_tx_key *key;
+       struct host_cmd cmd = {
+               .cmd = IPW_CMD_TGI_TX_KEY,
+               .len = sizeof(*key)
+       };
+       if (!(priv->ieee->sec.flags & (1 << index)))
+               return;
+       key = (struct ipw_tgi_tx_key *)&cmd.param;
+       key->key_id = index;
+       memcpy(key->key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
+       key->security_type = type;
+       key->station_index = 0; /* always 0 for BSS */
+       key->flags = 0;
+       /* 0 for new key; previous value of counter (after fatal error) */
+       key->tx_counter[0] = 0;
+       key->tx_counter[1] = 0;
+       ipw_send_cmd(priv, &cmd);
+ }
+ static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
  {
        struct ipw_wep_key *key;
        int i;
        key->cmd_id = DINO_CMD_WEP_KEY;
        key->seq_num = 0;
  
+       /* Note: AES keys cannot be set for multiple times.
+        * Only set it at the first time. */
        for (i = 0; i < 4; i++) {
-               key->key_index = i;
-               if (!(priv->sec.flags & (1 << i))) {
+               key->key_index = i | type;
+               if (!(priv->ieee->sec.flags & (1 << i))) {
                        key->key_size = 0;
-               } else {
-                       key->key_size = priv->sec.key_sizes[i];
-                       memcpy(key->key, priv->sec.keys[i], key->key_size);
+                       continue;
                }
  
-               if (ipw_send_cmd(priv, &cmd)) {
-                       IPW_ERROR("failed to send WEP_KEY command\n");
-                       return;
-               }
+               key->key_size = priv->ieee->sec.key_sizes[i];
+               memcpy(key->key, priv->ieee->sec.keys[i], key->key_size);
+               ipw_send_cmd(priv, &cmd);
        }
  }
  
- static void ipw_adhoc_check(void *data)
+ static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
  {
-       struct ipw_priv *priv = data;
-       if (priv->missed_adhoc_beacons++ > priv->missed_beacon_threshold &&
-           !(priv->config & CFG_ADHOC_PERSIST)) {
-               IPW_DEBUG_SCAN("Disassociating due to missed beacons\n");
-               ipw_remove_current_network(priv);
-               ipw_disassociate(priv);
+       if (priv->ieee->host_encrypt)
                return;
-       }
-       queue_delayed_work(priv->workqueue, &priv->adhoc_check,
-                          priv->assoc_request.beacon_interval);
- }
  
- #ifdef CONFIG_IPW_DEBUG
- static void ipw_debug_config(struct ipw_priv *priv)
+       switch (level) {
+       case SEC_LEVEL_3:
+               priv->sys_config.disable_unicast_decryption = 0;
+               priv->ieee->host_decrypt = 0;
+               break;
+       case SEC_LEVEL_2:
+               priv->sys_config.disable_unicast_decryption = 1;
+               priv->ieee->host_decrypt = 1;
+               break;
+       case SEC_LEVEL_1:
+               priv->sys_config.disable_unicast_decryption = 0;
+               priv->ieee->host_decrypt = 0;
+               break;
+       case SEC_LEVEL_0:
+               priv->sys_config.disable_unicast_decryption = 1;
+               break;
+       default:
+               break;
+       }
+ }
+ static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
+ {
+       if (priv->ieee->host_encrypt)
+               return;
+       switch (level) {
+       case SEC_LEVEL_3:
+               priv->sys_config.disable_multicast_decryption = 0;
+               break;
+       case SEC_LEVEL_2:
+               priv->sys_config.disable_multicast_decryption = 1;
+               break;
+       case SEC_LEVEL_1:
+               priv->sys_config.disable_multicast_decryption = 0;
+               break;
+       case SEC_LEVEL_0:
+               priv->sys_config.disable_multicast_decryption = 1;
+               break;
+       default:
+               break;
+       }
+ }
+ static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
+ {
+       switch (priv->ieee->sec.level) {
+       case SEC_LEVEL_3:
+               if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
+                       ipw_send_tgi_tx_key(priv,
+                                           DCT_FLAG_EXT_SECURITY_CCM,
+                                           priv->ieee->sec.active_key);
+               if (!priv->ieee->host_mc_decrypt)
+                       ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
+               break;
+       case SEC_LEVEL_2:
+               if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
+                       ipw_send_tgi_tx_key(priv,
+                                           DCT_FLAG_EXT_SECURITY_TKIP,
+                                           priv->ieee->sec.active_key);
+               break;
+       case SEC_LEVEL_1:
+               ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
+               ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
+               ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
+               break;
+       case SEC_LEVEL_0:
+       default:
+               break;
+       }
+ }
+ static void ipw_adhoc_check(void *data)
+ {
+       struct ipw_priv *priv = data;
+       if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
+           !(priv->config & CFG_ADHOC_PERSIST)) {
+               IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
+                         IPW_DL_STATE | IPW_DL_ASSOC,
+                         "Missed beacon: %d - disassociate\n",
+                         priv->missed_adhoc_beacons);
+               ipw_remove_current_network(priv);
+               ipw_disassociate(priv);
+               return;
+       }
+       queue_delayed_work(priv->workqueue, &priv->adhoc_check,
+                          priv->assoc_request.beacon_interval);
+ }
+ static void ipw_bg_adhoc_check(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_adhoc_check(data);
+       up(&priv->sem);
+ }
+ #ifdef CONFIG_IPW_DEBUG
+ static void ipw_debug_config(struct ipw_priv *priv)
  {
        IPW_DEBUG_INFO("Scan completed, no valid APs matched "
                       "[CFG 0x%08X]\n", priv->config);
        else
                IPW_DEBUG_INFO("ESSID unlocked.\n");
        if (priv->config & CFG_STATIC_BSSID)
-               IPW_DEBUG_INFO("BSSID locked to %d\n", priv->channel);
+               IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
+                              MAC_ARG(priv->bssid));
        else
                IPW_DEBUG_INFO("BSSID unlocked.\n");
        if (priv->capability & CAP_PRIVACY_ON)
  #define ipw_debug_config(x) do {} while (0)
  #endif
  
- static inline void ipw_set_fixed_rate(struct ipw_priv *priv,
-                                     struct ieee80211_network *network)
+ static inline void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
  {
        /* TODO: Verify that this works... */
        struct ipw_fixed_rate fr = {
                /* IEEE_A */
                if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
                        /* Invalid fixed rate mask */
+                       IPW_DEBUG_WX
+                           ("invalid fixed rate mask in ipw_set_fixed_rate\n");
+                       fr.tx_rates = 0;
+                       break;
+               }
+               fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
+               break;
+       default:                /* 2.4Ghz or Mixed */
+               /* IEEE_B */
+               if (mode == IEEE_B) {
+                       if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
+                               /* Invalid fixed rate mask */
+                               IPW_DEBUG_WX
+                                   ("invalid fixed rate mask in ipw_set_fixed_rate\n");
+                               fr.tx_rates = 0;
+                       }
+                       break;
+               }
+               /* IEEE_G */
+               if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
+                                   IEEE80211_OFDM_RATES_MASK)) {
+                       /* Invalid fixed rate mask */
+                       IPW_DEBUG_WX
+                           ("invalid fixed rate mask in ipw_set_fixed_rate\n");
                        fr.tx_rates = 0;
                        break;
                }
  
-               fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
-               break;
+               if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
+                       mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
+                       fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
+               }
+               if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
+                       mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
+                       fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
+               }
+               if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
+                       mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
+                       fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
+               }
+               fr.tx_rates |= mask;
+               break;
+       }
+       reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
+       ipw_write_reg32(priv, reg, *(u32 *) & fr);
+ }
+ static void ipw_abort_scan(struct ipw_priv *priv)
+ {
+       int err;
+       if (priv->status & STATUS_SCAN_ABORTING) {
+               IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
+               return;
+       }
+       priv->status |= STATUS_SCAN_ABORTING;
+       err = ipw_send_scan_abort(priv);
+       if (err)
+               IPW_DEBUG_HC("Request to abort scan failed.\n");
+ }
+ static void ipw_add_scan_channels(struct ipw_priv *priv,
+                                 struct ipw_scan_request_ext *scan,
+                                 int scan_type)
+ {
+       int channel_index = 0;
+       const struct ieee80211_geo *geo;
+       int i;
+       geo = ipw_get_geo(priv->ieee);
+       if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
+               int start = channel_index;
+               for (i = 0; i < geo->a_channels; i++) {
+                       if ((priv->status & STATUS_ASSOCIATED) &&
+                           geo->a[i].channel == priv->channel)
+                               continue;
+                       channel_index++;
+                       scan->channels_list[channel_index] = geo->a[i].channel;
+                       ipw_set_scan_type(scan, channel_index,
+                                         geo->a[i].
+                                         flags & IEEE80211_CH_PASSIVE_ONLY ?
+                                         IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
+                                         scan_type);
+               }
+               if (start != channel_index) {
+                       scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
+                           (channel_index - start);
+                       channel_index++;
+               }
+       }
+       if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
+               int start = channel_index;
+               if (priv->config & CFG_SPEED_SCAN) {
+                       int index;
+                       u8 channels[IEEE80211_24GHZ_CHANNELS] = {
+                               /* nop out the list */
+                               [0] = 0
+                       };
+                       u8 channel;
+                       while (channel_index < IPW_SCAN_CHANNELS) {
+                               channel =
+                                   priv->speed_scan[priv->speed_scan_pos];
+                               if (channel == 0) {
+                                       priv->speed_scan_pos = 0;
+                                       channel = priv->speed_scan[0];
+                               }
+                               if ((priv->status & STATUS_ASSOCIATED) &&
+                                   channel == priv->channel) {
+                                       priv->speed_scan_pos++;
+                                       continue;
+                               }
+                               /* If this channel has already been
+                                * added in scan, break from loop
+                                * and this will be the first channel
+                                * in the next scan.
+                                */
+                               if (channels[channel - 1] != 0)
+                                       break;
+                               channels[channel - 1] = 1;
+                               priv->speed_scan_pos++;
+                               channel_index++;
+                               scan->channels_list[channel_index] = channel;
+                               index =
+                                   ipw_channel_to_index(priv->ieee, channel);
+                               ipw_set_scan_type(scan, channel_index,
+                                                 geo->bg[index].
+                                                 flags &
+                                                 IEEE80211_CH_PASSIVE_ONLY ?
+                                                 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
+                                                 : scan_type);
+                       }
+               } else {
+                       for (i = 0; i < geo->bg_channels; i++) {
+                               if ((priv->status & STATUS_ASSOCIATED) &&
+                                   geo->bg[i].channel == priv->channel)
+                                       continue;
+                               channel_index++;
+                               scan->channels_list[channel_index] =
+                                   geo->bg[i].channel;
+                               ipw_set_scan_type(scan, channel_index,
+                                                 geo->bg[i].
+                                                 flags &
+                                                 IEEE80211_CH_PASSIVE_ONLY ?
+                                                 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
+                                                 : scan_type);
+                       }
+               }
+               if (start != channel_index) {
+                       scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
+                           (channel_index - start);
+               }
+       }
+ }
+ static int ipw_request_scan(struct ipw_priv *priv)
+ {
+       struct ipw_scan_request_ext scan;
+       int err = 0, scan_type;
+       if (!(priv->status & STATUS_INIT) ||
+           (priv->status & STATUS_EXIT_PENDING))
+               return 0;
+       down(&priv->sem);
+       if (priv->status & STATUS_SCANNING) {
+               IPW_DEBUG_HC("Concurrent scan requested.  Ignoring.\n");
+               priv->status |= STATUS_SCAN_PENDING;
+               goto done;
+       }
+       if (!(priv->status & STATUS_SCAN_FORCED) &&
+           priv->status & STATUS_SCAN_ABORTING) {
+               IPW_DEBUG_HC("Scan request while abort pending.  Queuing.\n");
+               priv->status |= STATUS_SCAN_PENDING;
+               goto done;
+       }
+       if (priv->status & STATUS_RF_KILL_MASK) {
+               IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
+               priv->status |= STATUS_SCAN_PENDING;
+               goto done;
+       }
+       memset(&scan, 0, sizeof(scan));
+       if (priv->config & CFG_SPEED_SCAN)
+               scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
+                   cpu_to_le16(30);
+       else
+               scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
+                   cpu_to_le16(20);
+       scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
+           cpu_to_le16(20);
+       scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
+       scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
+ #ifdef CONFIG_IPW2200_MONITOR
+       if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
+               u8 channel;
+               u8 band = 0;
+               switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
+               case IEEE80211_52GHZ_BAND:
+                       band = (u8) (IPW_A_MODE << 6) | 1;
+                       channel = priv->channel;
+                       break;
+               case IEEE80211_24GHZ_BAND:
+                       band = (u8) (IPW_B_MODE << 6) | 1;
+                       channel = priv->channel;
+                       break;
+               default:
+                       band = (u8) (IPW_B_MODE << 6) | 1;
+                       channel = 9;
+                       break;
+               }
+               scan.channels_list[0] = band;
+               scan.channels_list[1] = channel;
+               ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
+               /* NOTE:  The card will sit on this channel for this time
+                * period.  Scan aborts are timing sensitive and frequently
+                * result in firmware restarts.  As such, it is best to
+                * set a small dwell_time here and just keep re-issuing
+                * scans.  Otherwise fast channel hopping will not actually
+                * hop channels.
+                *
+                * TODO: Move SPEED SCAN support to all modes and bands */
+               scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
+                   cpu_to_le16(2000);
+       } else {
+ #endif                                /* CONFIG_IPW2200_MONITOR */
+               /* If we are roaming, then make this a directed scan for the
+                * current network.  Otherwise, ensure that every other scan
+                * is a fast channel hop scan */
+               if ((priv->status & STATUS_ROAMING)
+                   || (!(priv->status & STATUS_ASSOCIATED)
+                       && (priv->config & CFG_STATIC_ESSID)
+                       && (le32_to_cpu(scan.full_scan_index) % 2))) {
+                       err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
+                       if (err) {
+                               IPW_DEBUG_HC("Attempt to send SSID command "
+                                            "failed.\n");
+                               goto done;
+                       }
+                       scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
+               } else
+                       scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
+               ipw_add_scan_channels(priv, &scan, scan_type);
+ #ifdef CONFIG_IPW2200_MONITOR
+       }
+ #endif
+       err = ipw_send_scan_request_ext(priv, &scan);
+       if (err) {
+               IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
+               goto done;
+       }
+       priv->status |= STATUS_SCANNING;
+       priv->status &= ~STATUS_SCAN_PENDING;
+       queue_delayed_work(priv->workqueue, &priv->scan_check,
+                          IPW_SCAN_CHECK_WATCHDOG);
+       done:
+       up(&priv->sem);
+       return err;
+ }
+ static void ipw_bg_abort_scan(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_abort_scan(data);
+       up(&priv->sem);
+ }
+ static int ipw_wpa_enable(struct ipw_priv *priv, int value)
+ {
+       /* This is called when wpa_supplicant loads and closes the driver
+        * interface. */
+       priv->ieee->wpa_enabled = value;
+       return 0;
+ }
+ static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
+ {
+       struct ieee80211_device *ieee = priv->ieee;
+       struct ieee80211_security sec = {
+               .flags = SEC_AUTH_MODE,
+       };
+       int ret = 0;
+       if (value & IW_AUTH_ALG_SHARED_KEY) {
+               sec.auth_mode = WLAN_AUTH_SHARED_KEY;
+               ieee->open_wep = 0;
+       } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
+               sec.auth_mode = WLAN_AUTH_OPEN;
+               ieee->open_wep = 1;
+       } else
+               return -EINVAL;
+       if (ieee->set_security)
+               ieee->set_security(ieee->dev, &sec);
+       else
+               ret = -EOPNOTSUPP;
+       return ret;
+ }
+ void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, int wpa_ie_len)
+ {
+       /* make sure WPA is enabled */
+       ipw_wpa_enable(priv, 1);
+       ipw_disassociate(priv);
+ }
+ static int ipw_set_rsn_capa(struct ipw_priv *priv,
+                           char *capabilities, int length)
+ {
+       struct host_cmd cmd = {
+               .cmd = IPW_CMD_RSN_CAPABILITIES,
+               .len = length,
+       };
+       IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
+       memcpy(cmd.param, capabilities, length);
+       return ipw_send_cmd(priv, &cmd);
+ }
+ /*
+  * WE-18 support
+  */
+ /* SIOCSIWGENIE */
+ static int ipw_wx_set_genie(struct net_device *dev,
+                           struct iw_request_info *info,
+                           union iwreq_data *wrqu, char *extra)
+ {
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       struct ieee80211_device *ieee = priv->ieee;
+       u8 *buf;
+       int err = 0;
+       if (wrqu->data.length > MAX_WPA_IE_LEN ||
+           (wrqu->data.length && extra == NULL))
+               return -EINVAL;
+       //down(&priv->sem);
+       //if (!ieee->wpa_enabled) {
+       //      err = -EOPNOTSUPP;
+       //      goto out;
+       //}
+       if (wrqu->data.length) {
+               buf = kmalloc(wrqu->data.length, GFP_KERNEL);
+               if (buf == NULL) {
+                       err = -ENOMEM;
+                       goto out;
+               }
+               memcpy(buf, extra, wrqu->data.length);
+               kfree(ieee->wpa_ie);
+               ieee->wpa_ie = buf;
+               ieee->wpa_ie_len = wrqu->data.length;
+       } else {
+               kfree(ieee->wpa_ie);
+               ieee->wpa_ie = NULL;
+               ieee->wpa_ie_len = 0;
+       }
+       ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
+       out:
+       //up(&priv->sem);
+       return err;
+ }
+ /* SIOCGIWGENIE */
+ static int ipw_wx_get_genie(struct net_device *dev,
+                           struct iw_request_info *info,
+                           union iwreq_data *wrqu, char *extra)
+ {
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       struct ieee80211_device *ieee = priv->ieee;
+       int err = 0;
+       //down(&priv->sem);
+       //if (!ieee->wpa_enabled) {
+       //      err = -EOPNOTSUPP;
+       //      goto out;
+       //}
+       if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
+               wrqu->data.length = 0;
+               goto out;
+       }
+       if (wrqu->data.length < ieee->wpa_ie_len) {
+               err = -E2BIG;
+               goto out;
+       }
+       wrqu->data.length = ieee->wpa_ie_len;
+       memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
+       out:
+       //up(&priv->sem);
+       return err;
+ }
+ static int wext_cipher2level(int cipher)
+ {
+       switch (cipher) {
+       case IW_AUTH_CIPHER_NONE:
+               return SEC_LEVEL_0;
+       case IW_AUTH_CIPHER_WEP40:
+       case IW_AUTH_CIPHER_WEP104:
+               return SEC_LEVEL_1;
+       case IW_AUTH_CIPHER_TKIP:
+               return SEC_LEVEL_2;
+       case IW_AUTH_CIPHER_CCMP:
+               return SEC_LEVEL_3;
+       default:
+               return -1;
+       }
+ }
+ /* SIOCSIWAUTH */
+ static int ipw_wx_set_auth(struct net_device *dev,
+                          struct iw_request_info *info,
+                          union iwreq_data *wrqu, char *extra)
+ {
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       struct ieee80211_device *ieee = priv->ieee;
+       struct iw_param *param = &wrqu->param;
+       struct ieee80211_crypt_data *crypt;
+       unsigned long flags;
+       int ret = 0;
+       switch (param->flags & IW_AUTH_INDEX) {
+       case IW_AUTH_WPA_VERSION:
+               break;
+       case IW_AUTH_CIPHER_PAIRWISE:
+               ipw_set_hw_decrypt_unicast(priv,
+                                          wext_cipher2level(param->value));
+               break;
+       case IW_AUTH_CIPHER_GROUP:
+               ipw_set_hw_decrypt_multicast(priv,
+                                            wext_cipher2level(param->value));
+               break;
+       case IW_AUTH_KEY_MGMT:
+               /*
+                * ipw2200 does not use these parameters
+                */
+               break;
+       case IW_AUTH_TKIP_COUNTERMEASURES:
+               crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
+               if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
+                       break;
+               flags = crypt->ops->get_flags(crypt->priv);
+               if (param->value)
+                       flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
+               else
+                       flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
+               crypt->ops->set_flags(flags, crypt->priv);
+               break;
+       case IW_AUTH_DROP_UNENCRYPTED:{
+                       /* HACK:
+                        *
+                        * wpa_supplicant calls set_wpa_enabled when the driver
+                        * is loaded and unloaded, regardless of if WPA is being
+                        * used.  No other calls are made which can be used to
+                        * determine if encryption will be used or not prior to
+                        * association being expected.  If encryption is not being
+                        * used, drop_unencrypted is set to false, else true -- we
+                        * can use this to determine if the CAP_PRIVACY_ON bit should
+                        * be set.
+                        */
+                       struct ieee80211_security sec = {
+                               .flags = SEC_ENABLED,
+                               .enabled = param->value,
+                       };
+                       priv->ieee->drop_unencrypted = param->value;
+                       /* We only change SEC_LEVEL for open mode. Others
+                        * are set by ipw_wpa_set_encryption.
+                        */
+                       if (!param->value) {
+                               sec.flags |= SEC_LEVEL;
+                               sec.level = SEC_LEVEL_0;
+                       } else {
+                               sec.flags |= SEC_LEVEL;
+                               sec.level = SEC_LEVEL_1;
+                       }
+                       if (priv->ieee->set_security)
+                               priv->ieee->set_security(priv->ieee->dev, &sec);
+                       break;
+               }
+       case IW_AUTH_80211_AUTH_ALG:
+               ret = ipw_wpa_set_auth_algs(priv, param->value);
+               break;
+       case IW_AUTH_WPA_ENABLED:
+               ret = ipw_wpa_enable(priv, param->value);
+               break;
+       case IW_AUTH_RX_UNENCRYPTED_EAPOL:
+               ieee->ieee802_1x = param->value;
+               break;
+               //case IW_AUTH_ROAMING_CONTROL:
+       case IW_AUTH_PRIVACY_INVOKED:
+               ieee->privacy_invoked = param->value;
+               break;
+       default:
+               return -EOPNOTSUPP;
+       }
+       return ret;
+ }
+ /* SIOCGIWAUTH */
+ static int ipw_wx_get_auth(struct net_device *dev,
+                          struct iw_request_info *info,
+                          union iwreq_data *wrqu, char *extra)
+ {
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       struct ieee80211_device *ieee = priv->ieee;
+       struct ieee80211_crypt_data *crypt;
+       struct iw_param *param = &wrqu->param;
+       int ret = 0;
+       switch (param->flags & IW_AUTH_INDEX) {
+       case IW_AUTH_WPA_VERSION:
+       case IW_AUTH_CIPHER_PAIRWISE:
+       case IW_AUTH_CIPHER_GROUP:
+       case IW_AUTH_KEY_MGMT:
+               /*
+                * wpa_supplicant will control these internally
+                */
+               ret = -EOPNOTSUPP;
+               break;
+       case IW_AUTH_TKIP_COUNTERMEASURES:
+               crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
+               if (!crypt || !crypt->ops->get_flags)
+                       break;
+               param->value = (crypt->ops->get_flags(crypt->priv) &
+                               IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
+               break;
+       case IW_AUTH_DROP_UNENCRYPTED:
+               param->value = ieee->drop_unencrypted;
+               break;
+       case IW_AUTH_80211_AUTH_ALG:
+               param->value = ieee->sec.auth_mode;
+               break;
+       case IW_AUTH_WPA_ENABLED:
+               param->value = ieee->wpa_enabled;
+               break;
+       case IW_AUTH_RX_UNENCRYPTED_EAPOL:
+               param->value = ieee->ieee802_1x;
+               break;
+       case IW_AUTH_ROAMING_CONTROL:
+       case IW_AUTH_PRIVACY_INVOKED:
+               param->value = ieee->privacy_invoked;
+               break;
+       default:
+               return -EOPNOTSUPP;
+       }
+       return 0;
+ }
+ /* SIOCSIWENCODEEXT */
+ static int ipw_wx_set_encodeext(struct net_device *dev,
+                               struct iw_request_info *info,
+                               union iwreq_data *wrqu, char *extra)
+ {
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
+       if (hwcrypto) {
+               if (ext->alg == IW_ENCODE_ALG_TKIP) {
+                       /* IPW HW can't build TKIP MIC,
+                          host decryption still needed */
+                       if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
+                               priv->ieee->host_mc_decrypt = 1;
+                       else {
+                               priv->ieee->host_encrypt = 0;
+                               priv->ieee->host_encrypt_msdu = 1;
+                               priv->ieee->host_decrypt = 1;
+                       }
+               } else {
+                       priv->ieee->host_encrypt = 0;
+                       priv->ieee->host_encrypt_msdu = 0;
+                       priv->ieee->host_decrypt = 0;
+                       priv->ieee->host_mc_decrypt = 0;
+               }
+       }
+       return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
+ }
+ /* SIOCGIWENCODEEXT */
+ static int ipw_wx_get_encodeext(struct net_device *dev,
+                               struct iw_request_info *info,
+                               union iwreq_data *wrqu, char *extra)
+ {
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
+ }
+ /* SIOCSIWMLME */
+ static int ipw_wx_set_mlme(struct net_device *dev,
+                          struct iw_request_info *info,
+                          union iwreq_data *wrqu, char *extra)
+ {
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       struct iw_mlme *mlme = (struct iw_mlme *)extra;
+       u16 reason;
+       reason = cpu_to_le16(mlme->reason_code);
+       switch (mlme->cmd) {
+       case IW_MLME_DEAUTH:
+               // silently ignore
+               break;
+       case IW_MLME_DISASSOC:
+               ipw_disassociate(priv);
+               break;
+       default:
+               return -EOPNOTSUPP;
+       }
+       return 0;
+ }
+ #ifdef CONFIG_IPW_QOS
+ /* QoS */
+ /*
+ * get the modulation type of the current network or
+ * the card current mode
+ */
+ u8 ipw_qos_current_mode(struct ipw_priv * priv)
+ {
+       u8 mode = 0;
+       if (priv->status & STATUS_ASSOCIATED) {
+               unsigned long flags;
+               spin_lock_irqsave(&priv->ieee->lock, flags);
+               mode = priv->assoc_network->mode;
+               spin_unlock_irqrestore(&priv->ieee->lock, flags);
+       } else {
+               mode = priv->ieee->mode;
+       }
+       IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
+       return mode;
+ }
+ /*
+ * Handle management frame beacon and probe response
+ */
+ static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
+                                        int active_network,
+                                        struct ieee80211_network *network)
+ {
+       u32 size = sizeof(struct ieee80211_qos_parameters);
+       if (network->capability & WLAN_CAPABILITY_IBSS)
+               network->qos_data.active = network->qos_data.supported;
+       if (network->flags & NETWORK_HAS_QOS_MASK) {
+               if (active_network &&
+                   (network->flags & NETWORK_HAS_QOS_PARAMETERS))
+                       network->qos_data.active = network->qos_data.supported;
+               if ((network->qos_data.active == 1) && (active_network == 1) &&
+                   (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
+                   (network->qos_data.old_param_count !=
+                    network->qos_data.param_count)) {
+                       network->qos_data.old_param_count =
+                           network->qos_data.param_count;
+                       schedule_work(&priv->qos_activate);
+                       IPW_DEBUG_QOS("QoS parameters change call "
+                                     "qos_activate\n");
+               }
+       } else {
+               if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
+                       memcpy(&network->qos_data.parameters,
+                              &def_parameters_CCK, size);
+               else
+                       memcpy(&network->qos_data.parameters,
+                              &def_parameters_OFDM, size);
+               if ((network->qos_data.active == 1) && (active_network == 1)) {
+                       IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
+                       schedule_work(&priv->qos_activate);
+               }
+               network->qos_data.active = 0;
+               network->qos_data.supported = 0;
+       }
+       if ((priv->status & STATUS_ASSOCIATED) &&
+           (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
+               if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
+                       if ((network->capability & WLAN_CAPABILITY_IBSS) &&
+                           !(network->flags & NETWORK_EMPTY_ESSID))
+                               if ((network->ssid_len ==
+                                    priv->assoc_network->ssid_len) &&
+                                   !memcmp(network->ssid,
+                                           priv->assoc_network->ssid,
+                                           network->ssid_len)) {
+                                       queue_work(priv->workqueue,
+                                                  &priv->merge_networks);
+                               }
+       }
+       return 0;
+ }
+ /*
+ * This function set up the firmware to support QoS. It sends
+ * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
+ */
+ static int ipw_qos_activate(struct ipw_priv *priv,
+                           struct ieee80211_qos_data *qos_network_data)
+ {
+       int err;
+       struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
+       struct ieee80211_qos_parameters *active_one = NULL;
+       u32 size = sizeof(struct ieee80211_qos_parameters);
+       u32 burst_duration;
+       int i;
+       u8 type;
+       type = ipw_qos_current_mode(priv);
+       active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
+       memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
+       active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
+       memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
+       if (qos_network_data == NULL) {
+               if (type == IEEE_B) {
+                       IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
+                       active_one = &def_parameters_CCK;
+               } else
+                       active_one = &def_parameters_OFDM;
+               memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
+               burst_duration = ipw_qos_get_burst_duration(priv);
+               for (i = 0; i < QOS_QUEUE_NUM; i++)
+                       qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
+                           (u16) burst_duration;
+       } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
+               if (type == IEEE_B) {
+                       IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
+                                     type);
+                       if (priv->qos_data.qos_enable == 0)
+                               active_one = &def_parameters_CCK;
+                       else
+                               active_one = priv->qos_data.def_qos_parm_CCK;
+               } else {
+                       if (priv->qos_data.qos_enable == 0)
+                               active_one = &def_parameters_OFDM;
+                       else
+                               active_one = priv->qos_data.def_qos_parm_OFDM;
+               }
+               memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
+       } else {
+               unsigned long flags;
+               int active;
+               spin_lock_irqsave(&priv->ieee->lock, flags);
+               active_one = &(qos_network_data->parameters);
+               qos_network_data->old_param_count =
+                   qos_network_data->param_count;
+               memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
+               active = qos_network_data->supported;
+               spin_unlock_irqrestore(&priv->ieee->lock, flags);
+               if (active == 0) {
+                       burst_duration = ipw_qos_get_burst_duration(priv);
+                       for (i = 0; i < QOS_QUEUE_NUM; i++)
+                               qos_parameters[QOS_PARAM_SET_ACTIVE].
+                                   tx_op_limit[i] = (u16) burst_duration;
+               }
+       }
+       IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
+       err = ipw_send_qos_params_command(priv,
+                                         (struct ieee80211_qos_parameters *)
+                                         &(qos_parameters[0]));
+       if (err)
+               IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
+       return err;
+ }
+ /*
+ * send IPW_CMD_WME_INFO to the firmware
+ */
+ static int ipw_qos_set_info_element(struct ipw_priv *priv)
+ {
+       int ret = 0;
+       struct ieee80211_qos_information_element qos_info;
+       if (priv == NULL)
+               return -1;
+       qos_info.elementID = QOS_ELEMENT_ID;
+       qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
+       qos_info.version = QOS_VERSION_1;
+       qos_info.ac_info = 0;
+       memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
+       qos_info.qui_type = QOS_OUI_TYPE;
+       qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
+       ret = ipw_send_qos_info_command(priv, &qos_info);
+       if (ret != 0) {
+               IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
+       }
+       return ret;
+ }
+ /*
+ * Set the QoS parameter with the association request structure
+ */
+ static int ipw_qos_association(struct ipw_priv *priv,
+                              struct ieee80211_network *network)
+ {
+       int err = 0;
+       struct ieee80211_qos_data *qos_data = NULL;
+       struct ieee80211_qos_data ibss_data = {
+               .supported = 1,
+               .active = 1,
+       };
+       switch (priv->ieee->iw_mode) {
+       case IW_MODE_ADHOC:
+               if (!(network->capability & WLAN_CAPABILITY_IBSS))
+                       BUG();
+               qos_data = &ibss_data;
+               break;
+       case IW_MODE_INFRA:
+               qos_data = &network->qos_data;
+               break;
+       default:
+               BUG();
+               break;
+       }
+       err = ipw_qos_activate(priv, qos_data);
+       if (err) {
+               priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
+               return err;
+       }
+       if (priv->qos_data.qos_enable && qos_data->supported) {
+               IPW_DEBUG_QOS("QoS will be enabled for this association\n");
+               priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
+               return ipw_qos_set_info_element(priv);
+       }
+       return 0;
+ }
+ /*
+ * handling the beaconing responces. if we get different QoS setting
+ * of the network from the the associated setting adjust the QoS
+ * setting
+ */
+ static int ipw_qos_association_resp(struct ipw_priv *priv,
+                                   struct ieee80211_network *network)
+ {
+       int ret = 0;
+       unsigned long flags;
+       u32 size = sizeof(struct ieee80211_qos_parameters);
+       int set_qos_param = 0;
+       if ((priv == NULL) || (network == NULL) ||
+           (priv->assoc_network == NULL))
+               return ret;
+       if (!(priv->status & STATUS_ASSOCIATED))
+               return ret;
+       if ((priv->ieee->iw_mode != IW_MODE_INFRA))
+               return ret;
+       spin_lock_irqsave(&priv->ieee->lock, flags);
+       if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
+               memcpy(&priv->assoc_network->qos_data, &network->qos_data,
+                      sizeof(struct ieee80211_qos_data));
+               priv->assoc_network->qos_data.active = 1;
+               if ((network->qos_data.old_param_count !=
+                    network->qos_data.param_count)) {
+                       set_qos_param = 1;
+                       network->qos_data.old_param_count =
+                           network->qos_data.param_count;
+               }
+       } else {
+               if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
+                       memcpy(&priv->assoc_network->qos_data.parameters,
+                              &def_parameters_CCK, size);
+               else
+                       memcpy(&priv->assoc_network->qos_data.parameters,
+                              &def_parameters_OFDM, size);
+               priv->assoc_network->qos_data.active = 0;
+               priv->assoc_network->qos_data.supported = 0;
+               set_qos_param = 1;
+       }
+       spin_unlock_irqrestore(&priv->ieee->lock, flags);
+       if (set_qos_param == 1)
+               schedule_work(&priv->qos_activate);
+       return ret;
+ }
+ static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
+ {
+       u32 ret = 0;
+       if ((priv == NULL))
+               return 0;
+       if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
+               ret = priv->qos_data.burst_duration_CCK;
+       else
+               ret = priv->qos_data.burst_duration_OFDM;
+       return ret;
+ }
+ /*
+ * Initialize the setting of QoS global
+ */
+ static void ipw_qos_init(struct ipw_priv *priv, int enable,
+                        int burst_enable, u32 burst_duration_CCK,
+                        u32 burst_duration_OFDM)
+ {
+       priv->qos_data.qos_enable = enable;
+       if (priv->qos_data.qos_enable) {
+               priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
+               priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
+               IPW_DEBUG_QOS("QoS is enabled\n");
+       } else {
+               priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
+               priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
+               IPW_DEBUG_QOS("QoS is not enabled\n");
+       }
+       priv->qos_data.burst_enable = burst_enable;
+       if (burst_enable) {
+               priv->qos_data.burst_duration_CCK = burst_duration_CCK;
+               priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
+       } else {
+               priv->qos_data.burst_duration_CCK = 0;
+               priv->qos_data.burst_duration_OFDM = 0;
+       }
+ }
+ /*
+ * map the packet priority to the right TX Queue
+ */
+ static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
+ {
+       if (priority > 7 || !priv->qos_data.qos_enable)
+               priority = 0;
+       return from_priority_to_tx_queue[priority] - 1;
+ }
+ /*
+ * add QoS parameter to the TX command
+ */
+ static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
+                                       u16 priority,
+                                       struct tfd_data *tfd, u8 unicast)
+ {
+       int ret = 0;
+       int tx_queue_id = 0;
+       struct ieee80211_qos_data *qos_data = NULL;
+       int active, supported;
+       unsigned long flags;
+       if (!(priv->status & STATUS_ASSOCIATED))
+               return 0;
+       qos_data = &priv->assoc_network->qos_data;
+       spin_lock_irqsave(&priv->ieee->lock, flags);
+       if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
+               if (unicast == 0)
+                       qos_data->active = 0;
+               else
+                       qos_data->active = qos_data->supported;
+       }
+       active = qos_data->active;
+       supported = qos_data->supported;
+       spin_unlock_irqrestore(&priv->ieee->lock, flags);
+       IPW_DEBUG_QOS("QoS  %d network is QoS active %d  supported %d  "
+                     "unicast %d\n",
+                     priv->qos_data.qos_enable, active, supported, unicast);
+       if (active && priv->qos_data.qos_enable) {
+               ret = from_priority_to_tx_queue[priority];
+               tx_queue_id = ret - 1;
+               IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
+               if (priority <= 7) {
+                       tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
+                       tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
+                       tfd->tfd.tfd_26.mchdr.frame_ctl |=
+                           IEEE80211_STYPE_QOS_DATA;
+                       if (priv->qos_data.qos_no_ack_mask &
+                           (1UL << tx_queue_id)) {
+                               tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
+                               tfd->tfd.tfd_26.mchdr.qos_ctrl |=
+                                   CTRL_QOS_NO_ACK;
+                       }
+               }
+       }
+       return ret;
+ }
+ /*
+ * background support to run QoS activate functionality
+ */
+ static void ipw_bg_qos_activate(void *data)
+ {
+       struct ipw_priv *priv = data;
+       if (priv == NULL)
+               return;
+       down(&priv->sem);
+       if (priv->status & STATUS_ASSOCIATED)
+               ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
+       up(&priv->sem);
+ }
+ static int ipw_handle_probe_response(struct net_device *dev,
+                                    struct ieee80211_probe_response *resp,
+                                    struct ieee80211_network *network)
+ {
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       int active_network = ((priv->status & STATUS_ASSOCIATED) &&
+                             (network == priv->assoc_network));
  
-       default:                /* 2.4Ghz or Mixed */
-               /* IEEE_B */
-               if (network->mode == IEEE_B) {
-                       if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
-                               /* Invalid fixed rate mask */
-                               fr.tx_rates = 0;
-                       }
-                       break;
-               }
+       ipw_qos_handle_probe_response(priv, active_network, network);
  
-               /* IEEE_G */
-               if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
-                                   IEEE80211_OFDM_RATES_MASK)) {
-                       /* Invalid fixed rate mask */
-                       fr.tx_rates = 0;
-                       break;
-               }
+       return 0;
+ }
  
-               if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
-                       mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
-                       fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
-               }
+ static int ipw_handle_beacon(struct net_device *dev,
+                            struct ieee80211_beacon *resp,
+                            struct ieee80211_network *network)
+ {
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       int active_network = ((priv->status & STATUS_ASSOCIATED) &&
+                             (network == priv->assoc_network));
  
-               if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
-                       mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
-                       fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
-               }
+       ipw_qos_handle_probe_response(priv, active_network, network);
  
-               if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
-                       mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
-                       fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
-               }
+       return 0;
+ }
  
-               fr.tx_rates |= mask;
-               break;
-       }
+ static int ipw_handle_assoc_response(struct net_device *dev,
+                                    struct ieee80211_assoc_response *resp,
+                                    struct ieee80211_network *network)
+ {
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       ipw_qos_association_resp(priv, network);
+       return 0;
+ }
  
-       reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
-       ipw_write_reg32(priv, reg, *(u32 *) & fr);
+ static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
+                                      *qos_param)
+ {
+       struct host_cmd cmd = {
+               .cmd = IPW_CMD_QOS_PARAMETERS,
+               .len = (sizeof(struct ieee80211_qos_parameters) * 3)
+       };
+       memcpy(cmd.param, qos_param, sizeof(*qos_param) * 3);
+       return ipw_send_cmd(priv, &cmd);
+ }
+ static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
+                                    *qos_param)
+ {
+       struct host_cmd cmd = {
+               .cmd = IPW_CMD_WME_INFO,
+               .len = sizeof(*qos_param)
+       };
+       memcpy(cmd.param, qos_param, sizeof(*qos_param));
+       return ipw_send_cmd(priv, &cmd);
  }
  
+ #endif                                /* CONFIG_IPW_QOS */
  static int ipw_associate_network(struct ipw_priv *priv,
                                 struct ieee80211_network *network,
                                 struct ipw_supported_rates *rates, int roaming)
        int err;
  
        if (priv->config & CFG_FIXED_RATE)
-               ipw_set_fixed_rate(priv, network);
+               ipw_set_fixed_rate(priv, network->mode);
  
        if (!(priv->config & CFG_STATIC_ESSID)) {
                priv->essid_len = min(network->ssid_len,
        if ((priv->capability & CAP_PRIVACY_ON) &&
            (priv->capability & CAP_SHARED_KEY)) {
                priv->assoc_request.auth_type = AUTH_SHARED_KEY;
-               priv->assoc_request.auth_key = priv->sec.active_key;
+               priv->assoc_request.auth_key = priv->ieee->sec.active_key;
+               if ((priv->capability & CAP_PRIVACY_ON) &&
+                   (priv->ieee->sec.level == SEC_LEVEL_1) &&
+                   !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
+                       ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
        } else {
                priv->assoc_request.auth_type = AUTH_OPEN;
                priv->assoc_request.auth_key = 0;
        }
  
-       if (priv->capability & CAP_PRIVACY_ON)
-               ipw_send_wep_keys(priv);
+       if (priv->ieee->wpa_ie_len) {
+               priv->assoc_request.policy_support = 0x02;      /* RSN active */
+               ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
+                                priv->ieee->wpa_ie_len);
+       }
  
        /*
         * It is valid for our ieee device to support multiple modes, but
        else if (network->mode & priv->ieee->mode & IEEE_B)
                priv->assoc_request.ieee_mode = IPW_B_MODE;
  
+       priv->assoc_request.capability = network->capability;
+       if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
+           && !(priv->config & CFG_PREAMBLE_LONG)) {
+               priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
+       } else {
+               priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
+               /* Clear the short preamble if we won't be supporting it */
+               priv->assoc_request.capability &=
+                   ~WLAN_CAPABILITY_SHORT_PREAMBLE;
+       }
+       /* Clear capability bits that aren't used in Ad Hoc */
+       if (priv->ieee->iw_mode == IW_MODE_ADHOC)
+               priv->assoc_request.capability &=
+                   ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
        IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
-                       "802.11%c [%d], enc=%s%s%s%c%c\n",
+                       "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
                        roaming ? "Rea" : "A",
                        escape_essid(priv->essid, priv->essid_len),
                        network->channel,
                        ipw_modes[priv->assoc_request.ieee_mode],
                        rates->num_rates,
+                       (priv->assoc_request.preamble_length ==
+                        DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
+                       network->capability &
+                       WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
                        priv->capability & CAP_PRIVACY_ON ? "on " : "off",
                        priv->capability & CAP_PRIVACY_ON ?
                        (priv->capability & CAP_SHARED_KEY ? "(shared)" :
                         "(open)") : "",
                        priv->capability & CAP_PRIVACY_ON ? " key=" : "",
                        priv->capability & CAP_PRIVACY_ON ?
-                       '1' + priv->sec.active_key : '.',
+                       '1' + priv->ieee->sec.active_key : '.',
                        priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
  
        priv->assoc_request.beacon_interval = network->beacon_interval;
                priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
        }
  
-       memcpy(&priv->assoc_request.bssid, network->bssid, ETH_ALEN);
+       memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
  
        if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
                memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
                priv->assoc_request.atim_window = network->atim_window;
        } else {
-               memcpy(&priv->assoc_request.dest, network->bssid, ETH_ALEN);
+               memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
                priv->assoc_request.atim_window = 0;
        }
  
-       priv->assoc_request.capability = network->capability;
        priv->assoc_request.listen_interval = network->listen_interval;
  
        err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
                priv->sys_config.dot11g_auto_detection = 1;
        else
                priv->sys_config.dot11g_auto_detection = 0;
+       if (priv->ieee->iw_mode == IW_MODE_ADHOC)
+               priv->sys_config.answer_broadcast_ssid_probe = 1;
+       else
+               priv->sys_config.answer_broadcast_ssid_probe = 0;
        err = ipw_send_system_config(priv, &priv->sys_config);
        if (err) {
                IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
        }
  
        IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
-       err = ipw_set_sensitivity(priv, network->stats.rssi);
+       err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
        if (err) {
                IPW_DEBUG_HC("Attempt to send associate command failed.\n");
                return err;
  
        priv->assoc_network = network;
  
+ #ifdef CONFIG_IPW_QOS
+       ipw_qos_association(priv, network);
+ #endif
        err = ipw_send_associate(priv, &priv->assoc_request);
        if (err) {
                IPW_DEBUG_HC("Attempt to send associate command failed.\n");
@@@ -4783,12 -7245,15 +7246,15 @@@ static void ipw_roam(void *data
        if (priv->status & STATUS_ASSOCIATED) {
                /* First pass through ROAM process -- look for a better
                 * network */
+               unsigned long flags;
                u8 rssi = priv->assoc_network->stats.rssi;
                priv->assoc_network->stats.rssi = -128;
+               spin_lock_irqsave(&priv->ieee->lock, flags);
                list_for_each_entry(network, &priv->ieee->network_list, list) {
                        if (network != priv->assoc_network)
                                ipw_best_network(priv, &match, network, 1);
                }
+               spin_unlock_irqrestore(&priv->ieee->lock, flags);
                priv->assoc_network->stats.rssi = rssi;
  
                if (match.network == priv->assoc_network) {
        priv->status &= ~STATUS_ROAMING;
  }
  
- static void ipw_associate(void *data)
+ static void ipw_bg_roam(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_roam(data);
+       up(&priv->sem);
+ }
+ static int ipw_associate(void *data)
  {
        struct ipw_priv *priv = data;
  
        };
        struct ipw_supported_rates *rates;
        struct list_head *element;
+       unsigned long flags;
+       if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
+               IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
+               return 0;
+       }
+       if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
+               IPW_DEBUG_ASSOC("Not attempting association (already in "
+                               "progress)\n");
+               return 0;
+       }
+       if (priv->status & STATUS_DISASSOCIATING) {
+               IPW_DEBUG_ASSOC("Not attempting association (in "
+                               "disassociating)\n ");
+               queue_work(priv->workqueue, &priv->associate);
+               return 0;
+       }
+       if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
+               IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
+                               "initialized)\n");
+               return 0;
+       }
  
        if (!(priv->config & CFG_ASSOCIATE) &&
            !(priv->config & (CFG_STATIC_ESSID |
                              CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
                IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
-               return;
+               return 0;
        }
  
+       /* Protect our use of the network_list */
+       spin_lock_irqsave(&priv->ieee->lock, flags);
        list_for_each_entry(network, &priv->ieee->network_list, list)
            ipw_best_network(priv, &match, network, 0);
  
            priv->ieee->iw_mode == IW_MODE_ADHOC &&
            priv->config & CFG_ADHOC_CREATE &&
            priv->config & CFG_STATIC_ESSID &&
+           priv->config & CFG_STATIC_CHANNEL &&
            !list_empty(&priv->ieee->network_free_list)) {
                element = priv->ieee->network_free_list.next;
                network = list_entry(element, struct ieee80211_network, list);
                list_del(element);
                list_add_tail(&network->list, &priv->ieee->network_list);
        }
+       spin_unlock_irqrestore(&priv->ieee->lock, flags);
  
        /* If we reached the end of the list, then we don't have any valid
         * matching APs */
        if (!network) {
                ipw_debug_config(priv);
  
-               queue_delayed_work(priv->workqueue, &priv->request_scan,
-                                  SCAN_INTERVAL);
+               if (!(priv->status & STATUS_SCANNING)) {
+                       if (!(priv->config & CFG_SPEED_SCAN))
+                               queue_delayed_work(priv->workqueue,
+                                                  &priv->request_scan,
+                                                  SCAN_INTERVAL);
+                       else
+                               queue_work(priv->workqueue,
+                                          &priv->request_scan);
+               }
  
-               return;
+               return 0;
        }
  
        ipw_associate_network(priv, network, rates, 0);
+       return 1;
+ }
+ static void ipw_bg_associate(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_associate(data);
+       up(&priv->sem);
+ }
+ static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
+                                     struct sk_buff *skb)
+ {
+       struct ieee80211_hdr *hdr;
+       u16 fc;
+       hdr = (struct ieee80211_hdr *)skb->data;
+       fc = le16_to_cpu(hdr->frame_ctl);
+       if (!(fc & IEEE80211_FCTL_PROTECTED))
+               return;
+       fc &= ~IEEE80211_FCTL_PROTECTED;
+       hdr->frame_ctl = cpu_to_le16(fc);
+       switch (priv->ieee->sec.level) {
+       case SEC_LEVEL_3:
+               /* Remove CCMP HDR */
+               memmove(skb->data + IEEE80211_3ADDR_LEN,
+                       skb->data + IEEE80211_3ADDR_LEN + 8,
+                       skb->len - IEEE80211_3ADDR_LEN - 8);
+               skb_trim(skb, skb->len - 16);   /* CCMP_HDR_LEN + CCMP_MIC_LEN */
+               break;
+       case SEC_LEVEL_2:
+               break;
+       case SEC_LEVEL_1:
+               /* Remove IV */
+               memmove(skb->data + IEEE80211_3ADDR_LEN,
+                       skb->data + IEEE80211_3ADDR_LEN + 4,
+                       skb->len - IEEE80211_3ADDR_LEN - 4);
+               skb_trim(skb, skb->len - 8);    /* IV + ICV */
+               break;
+       case SEC_LEVEL_0:
+               break;
+       default:
+               printk(KERN_ERR "Unknow security level %d\n",
+                      priv->ieee->sec.level);
+               break;
+       }
  }
  
- static inline void ipw_handle_data_packet(struct ipw_priv *priv,
-                                         struct ipw_rx_mem_buffer *rxb,
-                                         struct ieee80211_rx_stats *stats)
+ static void ipw_handle_data_packet(struct ipw_priv *priv,
+                                  struct ipw_rx_mem_buffer *rxb,
+                                  struct ieee80211_rx_stats *stats)
  {
+       struct ieee80211_hdr_4addr *hdr;
        struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
  
        /* We received data from the HW, so stop the watchdog */
  
        /* We only process data packets if the
         * interface is open */
-       if (unlikely((pkt->u.frame.length + IPW_RX_FRAME_SIZE) >
+       if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
                     skb_tailroom(rxb->skb))) {
                priv->ieee->stats.rx_errors++;
                priv->wstats.discard.misc++;
        skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
  
        /* Set the size of the skb to the size of the frame */
-       skb_put(rxb->skb, pkt->u.frame.length);
+       skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
+       IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
+       /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
+       hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
+       if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
+           ((is_multicast_ether_addr(hdr->addr1) ||
+             is_broadcast_ether_addr(hdr->addr1)) ?
+            !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
+               ipw_rebuild_decrypted_skb(priv, rxb->skb);
+       if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
+               priv->ieee->stats.rx_errors++;
+       else {                  /* ieee80211_rx succeeded, so it now owns the SKB */
+               rxb->skb = NULL;
+               __ipw_led_activity_on(priv);
+       }
+ }
+ #ifdef CONFIG_IEEE80211_RADIOTAP
+ static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
+                                          struct ipw_rx_mem_buffer *rxb,
+                                          struct ieee80211_rx_stats *stats)
+ {
+       struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
+       struct ipw_rx_frame *frame = &pkt->u.frame;
+       /* initial pull of some data */
+       u16 received_channel = frame->received_channel;
+       u8 antennaAndPhy = frame->antennaAndPhy;
+       s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM;       /* call it signed anyhow */
+       u16 pktrate = frame->rate;
+       /* Magic struct that slots into the radiotap header -- no reason
+        * to build this manually element by element, we can write it much
+        * more efficiently than we can parse it. ORDER MATTERS HERE */
+       struct ipw_rt_hdr {
+               struct ieee80211_radiotap_header rt_hdr;
+               u8 rt_flags;    /* radiotap packet flags */
+               u8 rt_rate;     /* rate in 500kb/s */
+               u16 rt_channel; /* channel in mhz */
+               u16 rt_chbitmask;       /* channel bitfield */
+               s8 rt_dbmsignal;        /* signal in dbM, kluged to signed */
+               u8 rt_antenna;  /* antenna number */
+       } *ipw_rt;
+       short len = le16_to_cpu(pkt->u.frame.length);
+       /* We received data from the HW, so stop the watchdog */
+       priv->net_dev->trans_start = jiffies;
+       /* We only process data packets if the
+        * interface is open */
+       if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
+                    skb_tailroom(rxb->skb))) {
+               priv->ieee->stats.rx_errors++;
+               priv->wstats.discard.misc++;
+               IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
+               return;
+       } else if (unlikely(!netif_running(priv->net_dev))) {
+               priv->ieee->stats.rx_dropped++;
+               priv->wstats.discard.misc++;
+               IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
+               return;
+       }
+       /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
+        * that now */
+       if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
+               /* FIXME: Should alloc bigger skb instead */
+               priv->ieee->stats.rx_dropped++;
+               priv->wstats.discard.misc++;
+               IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
+               return;
+       }
+       /* copy the frame itself */
+       memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
+               rxb->skb->data + IPW_RX_FRAME_SIZE, len);
+       /* Zero the radiotap static buffer  ...  We only need to zero the bytes NOT
+        * part of our real header, saves a little time.
+        *
+        * No longer necessary since we fill in all our data.  Purge before merging
+        * patch officially.
+        * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
+        *        IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
+        */
+       ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
+       ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
+       ipw_rt->rt_hdr.it_pad = 0;      /* always good to zero */
+       ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr);      /* total header+data */
+       /* Big bitfield of all the fields we provide in radiotap */
+       ipw_rt->rt_hdr.it_present =
+           ((1 << IEEE80211_RADIOTAP_FLAGS) |
+            (1 << IEEE80211_RADIOTAP_RATE) |
+            (1 << IEEE80211_RADIOTAP_CHANNEL) |
+            (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
+            (1 << IEEE80211_RADIOTAP_ANTENNA));
+       /* Zero the flags, we'll add to them as we go */
+       ipw_rt->rt_flags = 0;
+       /* Convert signal to DBM */
+       ipw_rt->rt_dbmsignal = antsignal;
+       /* Convert the channel data and set the flags */
+       ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
+       if (received_channel > 14) {    /* 802.11a */
+               ipw_rt->rt_chbitmask =
+                   cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
+       } else if (antennaAndPhy & 32) {        /* 802.11b */
+               ipw_rt->rt_chbitmask =
+                   cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
+       } else {                /* 802.11g */
+               ipw_rt->rt_chbitmask =
+                   (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
+       }
+       /* set the rate in multiples of 500k/s */
+       switch (pktrate) {
+       case IPW_TX_RATE_1MB:
+               ipw_rt->rt_rate = 2;
+               break;
+       case IPW_TX_RATE_2MB:
+               ipw_rt->rt_rate = 4;
+               break;
+       case IPW_TX_RATE_5MB:
+               ipw_rt->rt_rate = 10;
+               break;
+       case IPW_TX_RATE_6MB:
+               ipw_rt->rt_rate = 12;
+               break;
+       case IPW_TX_RATE_9MB:
+               ipw_rt->rt_rate = 18;
+               break;
+       case IPW_TX_RATE_11MB:
+               ipw_rt->rt_rate = 22;
+               break;
+       case IPW_TX_RATE_12MB:
+               ipw_rt->rt_rate = 24;
+               break;
+       case IPW_TX_RATE_18MB:
+               ipw_rt->rt_rate = 36;
+               break;
+       case IPW_TX_RATE_24MB:
+               ipw_rt->rt_rate = 48;
+               break;
+       case IPW_TX_RATE_36MB:
+               ipw_rt->rt_rate = 72;
+               break;
+       case IPW_TX_RATE_48MB:
+               ipw_rt->rt_rate = 96;
+               break;
+       case IPW_TX_RATE_54MB:
+               ipw_rt->rt_rate = 108;
+               break;
+       default:
+               ipw_rt->rt_rate = 0;
+               break;
+       }
+       /* antenna number */
+       ipw_rt->rt_antenna = (antennaAndPhy & 3);       /* Is this right? */
+       /* set the preamble flag if we have it */
+       if ((antennaAndPhy & 64))
+               ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
+       /* Set the size of the skb to the size of the frame */
+       skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
  
        IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
  
        if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
                priv->ieee->stats.rx_errors++;
-       else                    /* ieee80211_rx succeeded, so it now owns the SKB */
+       else {                  /* ieee80211_rx succeeded, so it now owns the SKB */
+               rxb->skb = NULL;
+               /* no LED during capture */
+       }
+ }
+ #endif
+ static inline int is_network_packet(struct ipw_priv *priv,
+                                   struct ieee80211_hdr_4addr *header)
+ {
+       /* Filter incoming packets to determine if they are targetted toward
+        * this network, discarding packets coming from ourselves */
+       switch (priv->ieee->iw_mode) {
+       case IW_MODE_ADHOC:     /* Header: Dest. | Source    | BSSID */
+               /* packets from our adapter are dropped (echo) */
+               if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
+                       return 0;
+               /* {broad,multi}cast packets to our BSSID go through */
+               if (is_multicast_ether_addr(header->addr1) ||
+                   is_broadcast_ether_addr(header->addr1))
+                       return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
+               /* packets to our adapter go through */
+               return !memcmp(header->addr1, priv->net_dev->dev_addr,
+                              ETH_ALEN);
+       case IW_MODE_INFRA:     /* Header: Dest. | BSSID | Source */
+               /* packets from our adapter are dropped (echo) */
+               if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
+                       return 0;
+               /* {broad,multi}cast packets to our BSS go through */
+               if (is_multicast_ether_addr(header->addr1) ||
+                   is_broadcast_ether_addr(header->addr1))
+                       return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
+               /* packets to our adapter go through */
+               return !memcmp(header->addr1, priv->net_dev->dev_addr,
+                              ETH_ALEN);
+       }
+       return 1;
+ }
+ #define IPW_PACKET_RETRY_TIME HZ
+ static inline int is_duplicate_packet(struct ipw_priv *priv,
+                                     struct ieee80211_hdr_4addr *header)
+ {
+       u16 sc = le16_to_cpu(header->seq_ctl);
+       u16 seq = WLAN_GET_SEQ_SEQ(sc);
+       u16 frag = WLAN_GET_SEQ_FRAG(sc);
+       u16 *last_seq, *last_frag;
+       unsigned long *last_time;
+       switch (priv->ieee->iw_mode) {
+       case IW_MODE_ADHOC:
+               {
+                       struct list_head *p;
+                       struct ipw_ibss_seq *entry = NULL;
+                       u8 *mac = header->addr2;
+                       int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
+                       __list_for_each(p, &priv->ibss_mac_hash[index]) {
+                               entry =
+                                   list_entry(p, struct ipw_ibss_seq, list);
+                               if (!memcmp(entry->mac, mac, ETH_ALEN))
+                                       break;
+                       }
+                       if (p == &priv->ibss_mac_hash[index]) {
+                               entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
+                               if (!entry) {
+                                       IPW_ERROR
+                                           ("Cannot malloc new mac entry\n");
+                                       return 0;
+                               }
+                               memcpy(entry->mac, mac, ETH_ALEN);
+                               entry->seq_num = seq;
+                               entry->frag_num = frag;
+                               entry->packet_time = jiffies;
+                               list_add(&entry->list,
+                                        &priv->ibss_mac_hash[index]);
+                               return 0;
+                       }
+                       last_seq = &entry->seq_num;
+                       last_frag = &entry->frag_num;
+                       last_time = &entry->packet_time;
+                       break;
+               }
+       case IW_MODE_INFRA:
+               last_seq = &priv->last_seq_num;
+               last_frag = &priv->last_frag_num;
+               last_time = &priv->last_packet_time;
+               break;
+       default:
+               return 0;
+       }
+       if ((*last_seq == seq) &&
+           time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
+               if (*last_frag == frag)
+                       goto drop;
+               if (*last_frag + 1 != frag)
+                       /* out-of-order fragment */
+                       goto drop;
+       } else
+               *last_seq = seq;
+       *last_frag = frag;
+       *last_time = jiffies;
+       return 0;
+       drop:
+       /* Comment this line now since we observed the card receives
+        * duplicate packets but the FCTL_RETRY bit is not set in the
+        * IBSS mode with fragmentation enabled.
+        BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
+       return 1;
+ }
+ static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
+                                  struct ipw_rx_mem_buffer *rxb,
+                                  struct ieee80211_rx_stats *stats)
+ {
+       struct sk_buff *skb = rxb->skb;
+       struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
+       struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
+           (skb->data + IPW_RX_FRAME_SIZE);
+       ieee80211_rx_mgt(priv->ieee, header, stats);
+       if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
+           ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
+             IEEE80211_STYPE_PROBE_RESP) ||
+            (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
+             IEEE80211_STYPE_BEACON))) {
+               if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
+                       ipw_add_station(priv, header->addr2);
+       }
+       if (priv->config & CFG_NET_STATS) {
+               IPW_DEBUG_HC("sending stat packet\n");
+               /* Set the size of the skb to the size of the full
+                * ipw header and 802.11 frame */
+               skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
+                       IPW_RX_FRAME_SIZE);
+               /* Advance past the ipw packet header to the 802.11 frame */
+               skb_pull(skb, IPW_RX_FRAME_SIZE);
+               /* Push the ieee80211_rx_stats before the 802.11 frame */
+               memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
+               skb->dev = priv->ieee->dev;
+               /* Point raw at the ieee80211_stats */
+               skb->mac.raw = skb->data;
+               skb->pkt_type = PACKET_OTHERHOST;
+               skb->protocol = __constant_htons(ETH_P_80211_STATS);
+               memset(skb->cb, 0, sizeof(rxb->skb->cb));
+               netif_rx(skb);
                rxb->skb = NULL;
+       }
  }
  
  /*
@@@ -4913,8 -7809,8 +7810,8 @@@ static void ipw_rx(struct ipw_priv *pri
        u32 r, w, i;
        u8 network_packet;
  
-       r = ipw_read32(priv, CX2_RX_READ_INDEX);
-       w = ipw_read32(priv, CX2_RX_WRITE_INDEX);
+       r = ipw_read32(priv, IPW_RX_READ_INDEX);
+       w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
        i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
  
        while (i != r) {
                priv->rxq->queue[i] = NULL;
  
                pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
-                                           CX2_RX_BUF_SIZE,
+                                           IPW_RX_BUF_SIZE,
                                            PCI_DMA_FROMDEVICE);
  
                pkt = (struct ipw_rx_packet *)rxb->skb->data;
                switch (pkt->header.message_type) {
                case RX_FRAME_TYPE:     /* 802.11 frame */  {
                                struct ieee80211_rx_stats stats = {
-                                       .rssi = pkt->u.frame.rssi_dbm -
+                                       .rssi =
+                                           le16_to_cpu(pkt->u.frame.rssi_dbm) -
                                            IPW_RSSI_TO_DBM,
-                                       .signal = pkt->u.frame.signal,
+                                       .signal =
+                                           le16_to_cpu(pkt->u.frame.signal),
+                                       .noise =
+                                           le16_to_cpu(pkt->u.frame.noise),
                                        .rate = pkt->u.frame.rate,
                                        .mac_time = jiffies,
                                        .received_channel =
                                             control & (1 << 0)) ?
                                            IEEE80211_24GHZ_BAND :
                                            IEEE80211_52GHZ_BAND,
-                                       .len = pkt->u.frame.length,
+                                       .len = le16_to_cpu(pkt->u.frame.length),
                                };
  
                                if (stats.rssi != 0)
                                        stats.mask |= IEEE80211_STATMASK_RSSI;
                                if (stats.signal != 0)
                                        stats.mask |= IEEE80211_STATMASK_SIGNAL;
+                               if (stats.noise != 0)
+                                       stats.mask |= IEEE80211_STATMASK_NOISE;
                                if (stats.rate != 0)
                                        stats.mask |= IEEE80211_STATMASK_RATE;
  
                                priv->rx_packets++;
  
- #ifdef CONFIG_IPW_PROMISC
+ #ifdef CONFIG_IPW2200_MONITOR
                                if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
+ #ifdef CONFIG_IEEE80211_RADIOTAP
+                                       ipw_handle_data_packet_monitor(priv,
+                                                                      rxb,
+                                                                      &stats);
+ #else
                                        ipw_handle_data_packet(priv, rxb,
                                                               &stats);
+ #endif
                                        break;
                                }
  #endif
                                 * correctly -- we should probably use the
                                 * frame control of the packet and disregard
                                 * the current iw_mode */
-                               switch (priv->ieee->iw_mode) {
-                               case IW_MODE_ADHOC:
-                                       network_packet =
-                                           !memcmp(header->addr1,
-                                                   priv->net_dev->dev_addr,
-                                                   ETH_ALEN) ||
-                                           !memcmp(header->addr3,
-                                                   priv->bssid, ETH_ALEN) ||
-                                           is_broadcast_ether_addr(header->
-                                                                   addr1)
-                                           || is_multicast_ether_addr(header->
-                                                                      addr1);
-                                       break;
-                               case IW_MODE_INFRA:
-                               default:
-                                       network_packet =
-                                           !memcmp(header->addr3,
-                                                   priv->bssid, ETH_ALEN) ||
-                                           !memcmp(header->addr1,
-                                                   priv->net_dev->dev_addr,
-                                                   ETH_ALEN) ||
-                                           is_broadcast_ether_addr(header->
-                                                                   addr1)
-                                           || is_multicast_ether_addr(header->
-                                                                      addr1);
-                                       break;
-                               }
  
+                               network_packet =
+                                   is_network_packet(priv, header);
                                if (network_packet && priv->assoc_network) {
                                        priv->assoc_network->stats.rssi =
                                            stats.rssi;
                                }
  
                                IPW_DEBUG_RX("Frame: len=%u\n",
-                                            pkt->u.frame.length);
+                                            le16_to_cpu(pkt->u.frame.length));
  
-                               if (pkt->u.frame.length < frame_hdr_len(header)) {
+                               if (le16_to_cpu(pkt->u.frame.length) <
+                                   frame_hdr_len(header)) {
                                        IPW_DEBUG_DROP
                                            ("Received packet is too small. "
                                             "Dropping.\n");
                                        break;
                                }
  
-                               switch (WLAN_FC_GET_TYPE(header->frame_ctl)) {
+                               switch (WLAN_FC_GET_TYPE
+                                       (le16_to_cpu(header->frame_ctl))) {
                                case IEEE80211_FTYPE_MGMT:
-                                       ieee80211_rx_mgt(priv->ieee, header,
-                                                        &stats);
-                                       if (priv->ieee->iw_mode == IW_MODE_ADHOC
-                                           &&
-                                           ((WLAN_FC_GET_STYPE
-                                             (header->frame_ctl) ==
-                                             IEEE80211_STYPE_PROBE_RESP)
-                                            ||
-                                            (WLAN_FC_GET_STYPE
-                                             (header->frame_ctl) ==
-                                             IEEE80211_STYPE_BEACON))
-                                           && !memcmp(header->addr3,
-                                                      priv->bssid, ETH_ALEN))
-                                               ipw_add_station(priv,
-                                                               header->addr2);
+                                       ipw_handle_mgmt_packet(priv, rxb,
+                                                              &stats);
                                        break;
  
                                case IEEE80211_FTYPE_CTL:
                                        break;
  
                                case IEEE80211_FTYPE_DATA:
-                                       if (network_packet)
-                                               ipw_handle_data_packet(priv,
-                                                                      rxb,
-                                                                      &stats);
-                                       else
+                                       if (unlikely(!network_packet ||
+                                                    is_duplicate_packet(priv,
+                                                                        header)))
+                                       {
                                                IPW_DEBUG_DROP("Dropping: "
                                                               MAC_FMT ", "
                                                               MAC_FMT ", "
                                                                       addr2),
                                                               MAC_ARG(header->
                                                                       addr3));
+                                               break;
+                                       }
+                                       ipw_handle_data_packet(priv, rxb,
+                                                              &stats);
                                        break;
                                }
                                break;
                }
  
                pci_unmap_single(priv->pci_dev, rxb->dma_addr,
-                                CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
+                                IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
                list_add_tail(&rxb->list, &priv->rxq->rx_used);
  
                i = (i + 1) % RX_QUEUE_SIZE;
        ipw_rx_queue_restock(priv);
  }
  
- static void ipw_abort_scan(struct ipw_priv *priv)
+ #define DEFAULT_RTS_THRESHOLD     2304U
+ #define MIN_RTS_THRESHOLD         1U
+ #define MAX_RTS_THRESHOLD         2304U
+ #define DEFAULT_BEACON_INTERVAL   100U
+ #define       DEFAULT_SHORT_RETRY_LIMIT 7U
+ #define       DEFAULT_LONG_RETRY_LIMIT  4U
+ static int ipw_sw_reset(struct ipw_priv *priv, int init)
  {
-       int err;
+       int band, modulation;
+       int old_mode = priv->ieee->iw_mode;
  
-       if (priv->status & STATUS_SCAN_ABORTING) {
-               IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
-               return;
-       }
-       priv->status |= STATUS_SCAN_ABORTING;
+       /* Initialize module parameter values here */
+       priv->config = 0;
  
-       err = ipw_send_scan_abort(priv);
-       if (err)
-               IPW_DEBUG_HC("Request to abort scan failed.\n");
- }
+       /* We default to disabling the LED code as right now it causes
+        * too many systems to lock up... */
+       if (!led)
+               priv->config |= CFG_NO_LED;
  
- static int ipw_request_scan(struct ipw_priv *priv)
- {
-       struct ipw_scan_request_ext scan;
-       int channel_index = 0;
-       int i, err, scan_type;
+       if (associate)
+               priv->config |= CFG_ASSOCIATE;
+       else
+               IPW_DEBUG_INFO("Auto associate disabled.\n");
  
-       if (priv->status & STATUS_EXIT_PENDING) {
-               IPW_DEBUG_SCAN("Aborting scan due to device shutdown\n");
-               priv->status |= STATUS_SCAN_PENDING;
-               return 0;
-       }
+       if (auto_create)
+               priv->config |= CFG_ADHOC_CREATE;
+       else
+               IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
  
-       if (priv->status & STATUS_SCANNING) {
-               IPW_DEBUG_HC("Concurrent scan requested.  Aborting first.\n");
-               priv->status |= STATUS_SCAN_PENDING;
-               ipw_abort_scan(priv);
-               return 0;
+       if (disable) {
+               priv->status |= STATUS_RF_KILL_SW;
+               IPW_DEBUG_INFO("Radio disabled.\n");
        }
  
-       if (priv->status & STATUS_SCAN_ABORTING) {
-               IPW_DEBUG_HC("Scan request while abort pending.  Queuing.\n");
-               priv->status |= STATUS_SCAN_PENDING;
-               return 0;
+       if (channel != 0) {
+               priv->config |= CFG_STATIC_CHANNEL;
+               priv->channel = channel;
+               IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
+               /* TODO: Validate that provided channel is in range */
        }
+ #ifdef CONFIG_IPW_QOS
+       ipw_qos_init(priv, qos_enable, qos_burst_enable,
+                    burst_duration_CCK, burst_duration_OFDM);
+ #endif                                /* CONFIG_IPW_QOS */
  
-       if (priv->status & STATUS_RF_KILL_MASK) {
-               IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
-               priv->status |= STATUS_SCAN_PENDING;
-               return 0;
+       switch (mode) {
+       case 1:
+               priv->ieee->iw_mode = IW_MODE_ADHOC;
+               priv->net_dev->type = ARPHRD_ETHER;
+               break;
+ #ifdef CONFIG_IPW2200_MONITOR
+       case 2:
+               priv->ieee->iw_mode = IW_MODE_MONITOR;
+ #ifdef CONFIG_IEEE80211_RADIOTAP
+               priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
+ #else
+               priv->net_dev->type = ARPHRD_IEEE80211;
+ #endif
+               break;
+ #endif
+       default:
+       case 0:
+               priv->net_dev->type = ARPHRD_ETHER;
+               priv->ieee->iw_mode = IW_MODE_INFRA;
+               break;
        }
  
-       memset(&scan, 0, sizeof(scan));
+       if (hwcrypto) {
+               priv->ieee->host_encrypt = 0;
+               priv->ieee->host_encrypt_msdu = 0;
+               priv->ieee->host_decrypt = 0;
+               priv->ieee->host_mc_decrypt = 0;
+       }
+       IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
  
-       scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = 20;
-       scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = 20;
-       scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = 20;
-       scan.full_scan_index = ieee80211_get_scans(priv->ieee);
-       /* If we are roaming, then make this a directed scan for the current
-        * network.  Otherwise, ensure that every other scan is a fast
-        * channel hop scan */
-       if ((priv->status & STATUS_ROAMING)
-           || (!(priv->status & STATUS_ASSOCIATED)
-               && (priv->config & CFG_STATIC_ESSID)
-               && (scan.full_scan_index % 2))) {
-               err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
-               if (err) {
-                       IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
-                       return err;
-               }
+       /* IPW2200/2915 is abled to do hardware fragmentation. */
+       priv->ieee->host_open_frag = 0;
  
-               scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
+       if ((priv->pci_dev->device == 0x4223) ||
+           (priv->pci_dev->device == 0x4224)) {
+               if (init)
+                       printk(KERN_INFO DRV_NAME
+                              ": Detected Intel PRO/Wireless 2915ABG Network "
+                              "Connection\n");
+               priv->ieee->abg_true = 1;
+               band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
+               modulation = IEEE80211_OFDM_MODULATION |
+                   IEEE80211_CCK_MODULATION;
+               priv->adapter = IPW_2915ABG;
+               priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
        } else {
-               scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
-       }
-       if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
-               int start = channel_index;
-               for (i = 0; i < MAX_A_CHANNELS; i++) {
-                       if (band_a_active_channel[i] == 0)
-                               break;
-                       if ((priv->status & STATUS_ASSOCIATED) &&
-                           band_a_active_channel[i] == priv->channel)
-                               continue;
-                       channel_index++;
-                       scan.channels_list[channel_index] =
-                           band_a_active_channel[i];
-                       ipw_set_scan_type(&scan, channel_index, scan_type);
-               }
+               if (init)
+                       printk(KERN_INFO DRV_NAME
+                              ": Detected Intel PRO/Wireless 2200BG Network "
+                              "Connection\n");
  
-               if (start != channel_index) {
-                       scan.channels_list[start] = (u8) (IPW_A_MODE << 6) |
-                           (channel_index - start);
-                       channel_index++;
-               }
+               priv->ieee->abg_true = 0;
+               band = IEEE80211_24GHZ_BAND;
+               modulation = IEEE80211_OFDM_MODULATION |
+                   IEEE80211_CCK_MODULATION;
+               priv->adapter = IPW_2200BG;
+               priv->ieee->mode = IEEE_G | IEEE_B;
        }
  
-       if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
-               int start = channel_index;
-               for (i = 0; i < MAX_B_CHANNELS; i++) {
-                       if (band_b_active_channel[i] == 0)
-                               break;
-                       if ((priv->status & STATUS_ASSOCIATED) &&
-                           band_b_active_channel[i] == priv->channel)
-                               continue;
-                       channel_index++;
-                       scan.channels_list[channel_index] =
-                           band_b_active_channel[i];
-                       ipw_set_scan_type(&scan, channel_index, scan_type);
-               }
+       priv->ieee->freq_band = band;
+       priv->ieee->modulation = modulation;
  
-               if (start != channel_index) {
-                       scan.channels_list[start] = (u8) (IPW_B_MODE << 6) |
-                           (channel_index - start);
-               }
-       }
+       priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
  
-       err = ipw_send_scan_request_ext(priv, &scan);
-       if (err) {
-               IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
-               return -EIO;
-       }
+       priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
+       priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
  
-       priv->status |= STATUS_SCANNING;
-       priv->status &= ~STATUS_SCAN_PENDING;
+       priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
+       priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
+       priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
  
-       return 0;
+       /* If power management is turned on, default to AC mode */
+       priv->power_mode = IPW_POWER_AC;
+       priv->tx_power = IPW_TX_POWER_DEFAULT;
+       return old_mode == priv->ieee->iw_mode;
  }
  
  /*
@@@ -5248,12 -8126,16 +8127,16 @@@ static int ipw_wx_get_name(struct net_d
                           union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
-       if (!(priv->status & STATUS_ASSOCIATED))
+       down(&priv->sem);
+       if (priv->status & STATUS_RF_KILL_MASK)
+               strcpy(wrqu->name, "radio off");
+       else if (!(priv->status & STATUS_ASSOCIATED))
                strcpy(wrqu->name, "unassociated");
        else
                snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
                         ipw_modes[priv->assoc_request.ieee_mode]);
        IPW_DEBUG_WX("Name: %s\n", wrqu->name);
+       up(&priv->sem);
        return 0;
  }
  
@@@ -5262,13 -8144,9 +8145,9 @@@ static int ipw_set_channel(struct ipw_p
        if (channel == 0) {
                IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
                priv->config &= ~CFG_STATIC_CHANNEL;
-               if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
-                                     STATUS_ASSOCIATING))) {
-                       IPW_DEBUG_ASSOC("Attempting to associate with new "
-                                       "parameters.\n");
-                       ipw_associate(priv);
-               }
+               IPW_DEBUG_ASSOC("Attempting to associate with new "
+                               "parameters.\n");
+               ipw_associate(priv);
                return 0;
        }
  
        IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
        priv->channel = channel;
  
-       /* If we are currently associated, or trying to associate
-        * then see if this is a new channel (causing us to disassociate) */
-       if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
-               IPW_DEBUG_ASSOC("Disassociating due to channel change.\n");
-               ipw_disassociate(priv);
-       } else {
-               ipw_associate(priv);
+ #ifdef CONFIG_IPW2200_MONITOR
+       if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
+               int i;
+               if (priv->status & STATUS_SCANNING) {
+                       IPW_DEBUG_SCAN("Scan abort triggered due to "
+                                      "channel change.\n");
+                       ipw_abort_scan(priv);
+               }
+               for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
+                       udelay(10);
+               if (priv->status & STATUS_SCANNING)
+                       IPW_DEBUG_SCAN("Still scanning...\n");
+               else
+                       IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
+                                      1000 - i);
+               return 0;
        }
+ #endif                                /* CONFIG_IPW2200_MONITOR */
+       /* Network configuration changed -- force [re]association */
+       IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
+       if (!ipw_disassociate(priv))
+               ipw_associate(priv);
  
        return 0;
  }
@@@ -5300,29 -8196,48 +8197,48 @@@ static int ipw_wx_set_freq(struct net_d
                           union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
+       const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
        struct iw_freq *fwrq = &wrqu->freq;
+       int ret = 0, i;
+       u8 channel, flags;
+       int band;
+       if (fwrq->m == 0) {
+               IPW_DEBUG_WX("SET Freq/Channel -> any\n");
+               down(&priv->sem);
+               ret = ipw_set_channel(priv, 0);
+               up(&priv->sem);
+               return ret;
+       }
        /* if setting by freq convert to channel */
        if (fwrq->e == 1) {
-               if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) {
-                       int f = fwrq->m / 100000;
-                       int c = 0;
+               channel = ipw_freq_to_channel(priv->ieee, fwrq->m);
+               if (channel == 0)
+                       return -EINVAL;
+       } else
+               channel = fwrq->m;
  
-                       while ((c < REG_MAX_CHANNEL) &&
-                              (f != ipw_frequencies[c]))
-                               c++;
+       if (!(band = ipw_is_valid_channel(priv->ieee, channel)))
+               return -EINVAL;
+       if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
+               i = ipw_channel_to_index(priv->ieee, channel);
+               if (i == -1)
+                       return -EINVAL;
  
-                       /* hack to fall through */
-                       fwrq->e = 0;
-                       fwrq->m = c + 1;
+               flags = (band == IEEE80211_24GHZ_BAND) ?
+                   geo->bg[i].flags : geo->a[i].flags;
+               if (flags & IEEE80211_CH_PASSIVE_ONLY) {
+                       IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
+                       return -EINVAL;
                }
        }
  
-       if (fwrq->e > 0 || fwrq->m > 1000)
-               return -EOPNOTSUPP;
        IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
-       return ipw_set_channel(priv, (u8) fwrq->m);
+       down(&priv->sem);
+       ret = ipw_set_channel(priv, channel);
+       up(&priv->sem);
+       return ret;
  }
  
  static int ipw_wx_get_freq(struct net_device *dev,
  
        /* If we are associated, trying to associate, or have a statically
         * configured CHANNEL then return that; otherwise return ANY */
+       down(&priv->sem);
        if (priv->config & CFG_STATIC_CHANNEL ||
            priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
                wrqu->freq.m = priv->channel;
        else
                wrqu->freq.m = 0;
  
+       up(&priv->sem);
        IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
        return 0;
  }
@@@ -5354,11 -8271,8 +8272,8 @@@ static int ipw_wx_set_mode(struct net_d
  
        IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
  
-       if (wrqu->mode == priv->ieee->iw_mode)
-               return 0;
        switch (wrqu->mode) {
- #ifdef CONFIG_IPW_PROMISC
+ #ifdef CONFIG_IPW2200_MONITOR
        case IW_MODE_MONITOR:
  #endif
        case IW_MODE_ADHOC:
        default:
                return -EINVAL;
        }
+       if (wrqu->mode == priv->ieee->iw_mode)
+               return 0;
+       down(&priv->sem);
  
- #ifdef CONFIG_IPW_PROMISC
+       ipw_sw_reset(priv, 0);
+ #ifdef CONFIG_IPW2200_MONITOR
        if (priv->ieee->iw_mode == IW_MODE_MONITOR)
                priv->net_dev->type = ARPHRD_ETHER;
  
        if (wrqu->mode == IW_MODE_MONITOR)
+ #ifdef CONFIG_IEEE80211_RADIOTAP
+               priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
+ #else
                priv->net_dev->type = ARPHRD_IEEE80211;
- #endif                                /* CONFIG_IPW_PROMISC */
+ #endif
+ #endif                                /* CONFIG_IPW2200_MONITOR */
  
- #ifdef CONFIG_PM
        /* Free the existing firmware and reset the fw_loaded
         * flag so ipw_load() will bring in the new firmawre */
-       if (fw_loaded) {
-               fw_loaded = 0;
-       }
-       release_firmware(bootfw);
-       release_firmware(ucode);
-       release_firmware(firmware);
-       bootfw = ucode = firmware = NULL;
- #endif
+       free_firmware();
  
        priv->ieee->iw_mode = wrqu->mode;
-       ipw_adapter_restart(priv);
  
+       queue_work(priv->workqueue, &priv->adapter_restart);
+       up(&priv->sem);
        return err;
  }
  
@@@ -5403,20 -8319,13 +8320,13 @@@ static int ipw_wx_get_mode(struct net_d
                           union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
+       down(&priv->sem);
        wrqu->mode = priv->ieee->iw_mode;
        IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
+       up(&priv->sem);
        return 0;
  }
  
- #define DEFAULT_RTS_THRESHOLD     2304U
- #define MIN_RTS_THRESHOLD         1U
- #define MAX_RTS_THRESHOLD         2304U
- #define DEFAULT_BEACON_INTERVAL   100U
- #define       DEFAULT_SHORT_RETRY_LIMIT 7U
- #define       DEFAULT_LONG_RETRY_LIMIT  4U
  /* Values are in microsecond */
  static const s32 timeout_duration[] = {
        350000,
@@@ -5440,8 -8349,8 +8350,8 @@@ static int ipw_wx_get_range(struct net_
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
        struct iw_range *range = (struct iw_range *)extra;
-       u16 val;
-       int i;
+       const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
+       int i = 0, j;
  
        wrqu->data.length = sizeof(*range);
        memset(range, 0, sizeof(*range));
        range->max_qual.qual = 100;
        /* TODO: Find real max RSSI and stick here */
        range->max_qual.level = 0;
-       range->max_qual.noise = 0;
+       range->max_qual.noise = priv->ieee->worst_rssi + 0x100;
        range->max_qual.updated = 7;    /* Updated all three */
  
        range->avg_qual.qual = 70;
        range->avg_qual.level = 0;      /* FIXME to real average level */
        range->avg_qual.noise = 0;
        range->avg_qual.updated = 7;    /* Updated all three */
+       down(&priv->sem);
        range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
  
        for (i = 0; i < range->num_bitrates; i++)
        range->we_version_compiled = WIRELESS_EXT;
        range->we_version_source = 16;
  
-       range->num_channels = FREQ_COUNT;
-       val = 0;
-       for (i = 0; i < FREQ_COUNT; i++) {
-               range->freq[val].i = i + 1;
-               range->freq[val].m = ipw_frequencies[i] * 100000;
-               range->freq[val].e = 1;
-               val++;
+       i = 0;
+       if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
+               for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES;
+                    i++, j++) {
+                       range->freq[i].i = geo->bg[j].channel;
+                       range->freq[i].m = geo->bg[j].freq * 100000;
+                       range->freq[i].e = 1;
+               }
+       }
  
-               if (val == IW_MAX_FREQUENCIES)
-                       break;
+       if (priv->ieee->mode & IEEE_A) {
+               for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES;
+                    i++, j++) {
+                       range->freq[i].i = geo->a[j].channel;
+                       range->freq[i].m = geo->a[j].freq * 100000;
+                       range->freq[i].e = 1;
+               }
        }
-       range->num_frequency = val;
+       range->num_channels = i;
+       range->num_frequency = i;
+       up(&priv->sem);
+       /* Event capability (kernel + driver) */
+       range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
+                               IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
+                               IW_EVENT_CAPA_MASK(SIOCGIWAP));
+       range->event_capa[1] = IW_EVENT_CAPA_K_1;
  
        IPW_DEBUG_WX("GET Range\n");
        return 0;
@@@ -5513,25 -8438,23 +8439,23 @@@ static int ipw_wx_set_wap(struct net_de
  
        if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
                return -EINVAL;
+       down(&priv->sem);
        if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
            !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
                /* we disable mandatory BSSID association */
                IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
                priv->config &= ~CFG_STATIC_BSSID;
-               if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
-                                     STATUS_ASSOCIATING))) {
-                       IPW_DEBUG_ASSOC("Attempting to associate with new "
-                                       "parameters.\n");
-                       ipw_associate(priv);
-               }
+               IPW_DEBUG_ASSOC("Attempting to associate with new "
+                               "parameters.\n");
+               ipw_associate(priv);
+               up(&priv->sem);
                return 0;
        }
  
        priv->config |= CFG_STATIC_BSSID;
        if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
                IPW_DEBUG_WX("BSSID set to current BSSID.\n");
+               up(&priv->sem);
                return 0;
        }
  
  
        memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
  
-       /* If we are currently associated, or trying to associate
-        * then see if this is a new BSSID (causing us to disassociate) */
-       if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
-               IPW_DEBUG_ASSOC("Disassociating due to BSSID change.\n");
-               ipw_disassociate(priv);
-       } else {
+       /* Network configuration changed -- force [re]association */
+       IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
+       if (!ipw_disassociate(priv))
                ipw_associate(priv);
-       }
  
+       up(&priv->sem);
        return 0;
  }
  
@@@ -5559,15 -8479,17 +8480,17 @@@ static int ipw_wx_get_wap(struct net_de
        struct ipw_priv *priv = ieee80211_priv(dev);
        /* If we are associated, trying to associate, or have a statically
         * configured BSSID then return that; otherwise return ANY */
+       down(&priv->sem);
        if (priv->config & CFG_STATIC_BSSID ||
            priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
                wrqu->ap_addr.sa_family = ARPHRD_ETHER;
-               memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN);
+               memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
        } else
                memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
  
        IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
                     MAC_ARG(wrqu->ap_addr.sa_data));
+       up(&priv->sem);
        return 0;
  }
  
@@@ -5578,21 -8500,22 +8501,22 @@@ static int ipw_wx_set_essid(struct net_
        struct ipw_priv *priv = ieee80211_priv(dev);
        char *essid = "";       /* ANY */
        int length = 0;
+       down(&priv->sem);
        if (wrqu->essid.flags && wrqu->essid.length) {
                length = wrqu->essid.length - 1;
                essid = extra;
        }
        if (length == 0) {
                IPW_DEBUG_WX("Setting ESSID to ANY\n");
-               priv->config &= ~CFG_STATIC_ESSID;
-               if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
+               if ((priv->config & CFG_STATIC_ESSID) &&
+                   !(priv->status & (STATUS_ASSOCIATED |
                                      STATUS_ASSOCIATING))) {
                        IPW_DEBUG_ASSOC("Attempting to associate with new "
                                        "parameters.\n");
+                       priv->config &= ~CFG_STATIC_ESSID;
                        ipw_associate(priv);
                }
+               up(&priv->sem);
                return 0;
        }
  
  
        if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
                IPW_DEBUG_WX("ESSID set to current ESSID.\n");
+               up(&priv->sem);
                return 0;
        }
  
        priv->essid_len = length;
        memcpy(priv->essid, essid, priv->essid_len);
  
-       /* If we are currently associated, or trying to associate
-        * then see if this is a new ESSID (causing us to disassociate) */
-       if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
-               IPW_DEBUG_ASSOC("Disassociating due to ESSID change.\n");
-               ipw_disassociate(priv);
-       } else {
+       /* Network configuration changed -- force [re]association */
+       IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
+       if (!ipw_disassociate(priv))
                ipw_associate(priv);
-       }
  
+       up(&priv->sem);
        return 0;
  }
  
@@@ -5631,6 -8552,7 +8553,7 @@@ static int ipw_wx_get_essid(struct net_
  
        /* If we are associated, trying to associate, or have a statically
         * configured ESSID then return that; otherwise return ANY */
+       down(&priv->sem);
        if (priv->config & CFG_STATIC_ESSID ||
            priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
                IPW_DEBUG_WX("Getting essid: '%s'\n",
                wrqu->essid.length = 0;
                wrqu->essid.flags = 0;  /* active */
        }
+       up(&priv->sem);
        return 0;
  }
  
@@@ -5656,11 -8578,12 +8579,12 @@@ static int ipw_wx_set_nick(struct net_d
        IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
        if (wrqu->data.length > IW_ESSID_MAX_SIZE)
                return -E2BIG;
+       down(&priv->sem);
        wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
        memset(priv->nick, 0, sizeof(priv->nick));
        memcpy(priv->nick, extra, wrqu->data.length);
        IPW_DEBUG_TRACE("<<\n");
+       up(&priv->sem);
        return 0;
  
  }
@@@ -5671,9 -8594,11 +8595,11 @@@ static int ipw_wx_get_nick(struct net_d
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
        IPW_DEBUG_WX("Getting nick\n");
+       down(&priv->sem);
        wrqu->data.length = strlen(priv->nick) + 1;
        memcpy(extra, priv->nick, wrqu->data.length);
        wrqu->data.flags = 1;   /* active */
+       up(&priv->sem);
        return 0;
  }
  
@@@ -5681,8 -8606,113 +8607,113 @@@ static int ipw_wx_set_rate(struct net_d
                           struct iw_request_info *info,
                           union iwreq_data *wrqu, char *extra)
  {
-       IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu);
-       return -EOPNOTSUPP;
+       /* TODO: We should use semaphores or locks for access to priv */
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       u32 target_rate = wrqu->bitrate.value;
+       u32 fixed, mask;
+       /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
+       /* value = X, fixed = 1 means only rate X */
+       /* value = X, fixed = 0 means all rates lower equal X */
+       if (target_rate == -1) {
+               fixed = 0;
+               mask = IEEE80211_DEFAULT_RATES_MASK;
+               /* Now we should reassociate */
+               goto apply;
+       }
+       mask = 0;
+       fixed = wrqu->bitrate.fixed;
+       if (target_rate == 1000000 || !fixed)
+               mask |= IEEE80211_CCK_RATE_1MB_MASK;
+       if (target_rate == 1000000)
+               goto apply;
+       if (target_rate == 2000000 || !fixed)
+               mask |= IEEE80211_CCK_RATE_2MB_MASK;
+       if (target_rate == 2000000)
+               goto apply;
+       if (target_rate == 5500000 || !fixed)
+               mask |= IEEE80211_CCK_RATE_5MB_MASK;
+       if (target_rate == 5500000)
+               goto apply;
+       if (target_rate == 6000000 || !fixed)
+               mask |= IEEE80211_OFDM_RATE_6MB_MASK;
+       if (target_rate == 6000000)
+               goto apply;
+       if (target_rate == 9000000 || !fixed)
+               mask |= IEEE80211_OFDM_RATE_9MB_MASK;
+       if (target_rate == 9000000)
+               goto apply;
+       if (target_rate == 11000000 || !fixed)
+               mask |= IEEE80211_CCK_RATE_11MB_MASK;
+       if (target_rate == 11000000)
+               goto apply;
+       if (target_rate == 12000000 || !fixed)
+               mask |= IEEE80211_OFDM_RATE_12MB_MASK;
+       if (target_rate == 12000000)
+               goto apply;
+       if (target_rate == 18000000 || !fixed)
+               mask |= IEEE80211_OFDM_RATE_18MB_MASK;
+       if (target_rate == 18000000)
+               goto apply;
+       if (target_rate == 24000000 || !fixed)
+               mask |= IEEE80211_OFDM_RATE_24MB_MASK;
+       if (target_rate == 24000000)
+               goto apply;
+       if (target_rate == 36000000 || !fixed)
+               mask |= IEEE80211_OFDM_RATE_36MB_MASK;
+       if (target_rate == 36000000)
+               goto apply;
+       if (target_rate == 48000000 || !fixed)
+               mask |= IEEE80211_OFDM_RATE_48MB_MASK;
+       if (target_rate == 48000000)
+               goto apply;
+       if (target_rate == 54000000 || !fixed)
+               mask |= IEEE80211_OFDM_RATE_54MB_MASK;
+       if (target_rate == 54000000)
+               goto apply;
+       IPW_DEBUG_WX("invalid rate specified, returning error\n");
+       return -EINVAL;
+       apply:
+       IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
+                    mask, fixed ? "fixed" : "sub-rates");
+       down(&priv->sem);
+       if (mask == IEEE80211_DEFAULT_RATES_MASK) {
+               priv->config &= ~CFG_FIXED_RATE;
+               ipw_set_fixed_rate(priv, priv->ieee->mode);
+       } else
+               priv->config |= CFG_FIXED_RATE;
+       if (priv->rates_mask == mask) {
+               IPW_DEBUG_WX("Mask set to current mask.\n");
+               up(&priv->sem);
+               return 0;
+       }
+       priv->rates_mask = mask;
+       /* Network configuration changed -- force [re]association */
+       IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
+       if (!ipw_disassociate(priv))
+               ipw_associate(priv);
+       up(&priv->sem);
+       return 0;
  }
  
  static int ipw_wx_get_rate(struct net_device *dev,
                           union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
+       down(&priv->sem);
        wrqu->bitrate.value = priv->last_rate;
+       up(&priv->sem);
        IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
        return 0;
  }
@@@ -5701,18 -8732,20 +8733,20 @@@ static int ipw_wx_set_rts(struct net_de
                          union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
+       down(&priv->sem);
        if (wrqu->rts.disabled)
                priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
        else {
                if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
-                   wrqu->rts.value > MAX_RTS_THRESHOLD)
+                   wrqu->rts.value > MAX_RTS_THRESHOLD) {
+                       up(&priv->sem);
                        return -EINVAL;
+               }
                priv->rts_threshold = wrqu->rts.value;
        }
  
        ipw_send_rts_threshold(priv, priv->rts_threshold);
+       up(&priv->sem);
        IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
        return 0;
  }
@@@ -5722,10 -8755,11 +8756,11 @@@ static int ipw_wx_get_rts(struct net_de
                          union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
+       down(&priv->sem);
        wrqu->rts.value = priv->rts_threshold;
        wrqu->rts.fixed = 0;    /* no auto select */
        wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
+       up(&priv->sem);
        IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
        return 0;
  }
@@@ -5735,41 -8769,33 +8770,33 @@@ static int ipw_wx_set_txpow(struct net_
                            union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
-       struct ipw_tx_power tx_power;
-       int i;
-       if (ipw_radio_kill_sw(priv, wrqu->power.disabled))
-               return -EINPROGRESS;
-       if (wrqu->power.flags != IW_TXPOW_DBM)
-               return -EINVAL;
-       if ((wrqu->power.value > 20) || (wrqu->power.value < -12))
-               return -EINVAL;
-       priv->tx_power = wrqu->power.value;
-       memset(&tx_power, 0, sizeof(tx_power));
+       int err = 0;
  
-       /* configure device for 'G' band */
-       tx_power.ieee_mode = IPW_G_MODE;
-       tx_power.num_channels = 11;
-       for (i = 0; i < 11; i++) {
-               tx_power.channels_tx_power[i].channel_number = i + 1;
-               tx_power.channels_tx_power[i].tx_power = priv->tx_power;
+       down(&priv->sem);
+       if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
+               err = -EINPROGRESS;
+               goto out;
        }
-       if (ipw_send_tx_power(priv, &tx_power))
-               goto error;
  
-       /* configure device to also handle 'B' band */
-       tx_power.ieee_mode = IPW_B_MODE;
-       if (ipw_send_tx_power(priv, &tx_power))
-               goto error;
+       if (!wrqu->power.fixed)
+               wrqu->power.value = IPW_TX_POWER_DEFAULT;
+       if (wrqu->power.flags != IW_TXPOW_DBM) {
+               err = -EINVAL;
+               goto out;
+       }
  
-       return 0;
+       if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
+           (wrqu->power.value < IPW_TX_POWER_MIN)) {
+               err = -EINVAL;
+               goto out;
+       }
  
-       error:
-       return -EIO;
+       priv->tx_power = wrqu->power.value;
+       err = ipw_set_tx_power(priv);
+       out:
+       up(&priv->sem);
+       return err;
  }
  
  static int ipw_wx_get_txpow(struct net_device *dev,
                            union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
+       down(&priv->sem);
        wrqu->power.value = priv->tx_power;
        wrqu->power.fixed = 1;
        wrqu->power.flags = IW_TXPOW_DBM;
        wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
+       up(&priv->sem);
  
        IPW_DEBUG_WX("GET TX Power -> %s %d \n",
-                    wrqu->power.disabled ? "ON" : "OFF", wrqu->power.value);
+                    wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
  
        return 0;
  }
@@@ -5794,18 -8821,21 +8822,21 @@@ static int ipw_wx_set_frag(struct net_d
                           union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
+       down(&priv->sem);
        if (wrqu->frag.disabled)
                priv->ieee->fts = DEFAULT_FTS;
        else {
                if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
-                   wrqu->frag.value > MAX_FRAG_THRESHOLD)
+                   wrqu->frag.value > MAX_FRAG_THRESHOLD) {
+                       up(&priv->sem);
                        return -EINVAL;
+               }
  
                priv->ieee->fts = wrqu->frag.value & ~0x1;
        }
  
        ipw_send_frag_threshold(priv, wrqu->frag.value);
+       up(&priv->sem);
        IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
        return 0;
  }
@@@ -5815,10 -8845,11 +8846,11 @@@ static int ipw_wx_get_frag(struct net_d
                           union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
+       down(&priv->sem);
        wrqu->frag.value = priv->ieee->fts;
        wrqu->frag.fixed = 0;   /* no auto select */
        wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
+       up(&priv->sem);
        IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
  
        return 0;
@@@ -5828,16 -8859,128 +8860,128 @@@ static int ipw_wx_set_retry(struct net_
                            struct iw_request_info *info,
                            union iwreq_data *wrqu, char *extra)
  {
-       IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu);
-       return -EOPNOTSUPP;
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
+               return -EINVAL;
+       if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
+               return 0;
+       if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
+               return -EINVAL;
+       down(&priv->sem);
+       if (wrqu->retry.flags & IW_RETRY_MIN)
+               priv->short_retry_limit = (u8) wrqu->retry.value;
+       else if (wrqu->retry.flags & IW_RETRY_MAX)
+               priv->long_retry_limit = (u8) wrqu->retry.value;
+       else {
+               priv->short_retry_limit = (u8) wrqu->retry.value;
+               priv->long_retry_limit = (u8) wrqu->retry.value;
+       }
+       ipw_send_retry_limit(priv, priv->short_retry_limit,
+                            priv->long_retry_limit);
+       up(&priv->sem);
+       IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
+                    priv->short_retry_limit, priv->long_retry_limit);
+       return 0;
  }
  
  static int ipw_wx_get_retry(struct net_device *dev,
                            struct iw_request_info *info,
                            union iwreq_data *wrqu, char *extra)
  {
-       IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu);
-       return -EOPNOTSUPP;
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       down(&priv->sem);
+       wrqu->retry.disabled = 0;
+       if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
+               up(&priv->sem);
+               return -EINVAL;
+       }
+       if (wrqu->retry.flags & IW_RETRY_MAX) {
+               wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
+               wrqu->retry.value = priv->long_retry_limit;
+       } else if (wrqu->retry.flags & IW_RETRY_MIN) {
+               wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
+               wrqu->retry.value = priv->short_retry_limit;
+       } else {
+               wrqu->retry.flags = IW_RETRY_LIMIT;
+               wrqu->retry.value = priv->short_retry_limit;
+       }
+       up(&priv->sem);
+       IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
+       return 0;
+ }
+ static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
+                                  int essid_len)
+ {
+       struct ipw_scan_request_ext scan;
+       int err = 0, scan_type;
+       down(&priv->sem);
+       if (priv->status & STATUS_RF_KILL_MASK) {
+               IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
+               priv->status |= STATUS_SCAN_PENDING;
+               goto done;
+       }
+       IPW_DEBUG_HC("starting request direct scan!\n");
+       if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
+               err = wait_event_interruptible(priv->wait_state,
+                                              !(priv->
+                                                status & (STATUS_SCANNING |
+                                                          STATUS_SCAN_ABORTING)));
+               if (err) {
+                       IPW_DEBUG_HC("aborting direct scan");
+                       goto done;
+               }
+       }
+       memset(&scan, 0, sizeof(scan));
+       if (priv->config & CFG_SPEED_SCAN)
+               scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
+                   cpu_to_le16(30);
+       else
+               scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
+                   cpu_to_le16(20);
+       scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
+           cpu_to_le16(20);
+       scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
+       scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
+       scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
+       err = ipw_send_ssid(priv, essid, essid_len);
+       if (err) {
+               IPW_DEBUG_HC("Attempt to send SSID command failed\n");
+               goto done;
+       }
+       scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
+       ipw_add_scan_channels(priv, &scan, scan_type);
+       err = ipw_send_scan_request_ext(priv, &scan);
+       if (err) {
+               IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
+               goto done;
+       }
+       priv->status |= STATUS_SCANNING;
+       done:
+       up(&priv->sem);
+       return err;
  }
  
  static int ipw_wx_set_scan(struct net_device *dev,
                           union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
+       struct iw_scan_req *req = NULL;
+       if (wrqu->data.length
+           && wrqu->data.length == sizeof(struct iw_scan_req)) {
+               req = (struct iw_scan_req *)extra;
+               if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
+                       ipw_request_direct_scan(priv, req->essid,
+                                               req->essid_len);
+                       return 0;
+               }
+       }
        IPW_DEBUG_WX("Start scan\n");
-       if (ipw_request_scan(priv))
-               return -EIO;
+       queue_work(priv->workqueue, &priv->request_scan);
        return 0;
  }
  
@@@ -5864,7 -9019,21 +9020,21 @@@ static int ipw_wx_set_encode(struct net
                             union iwreq_data *wrqu, char *key)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
-       return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
+       int ret;
+       u32 cap = priv->capability;
+       down(&priv->sem);
+       ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
+       /* In IBSS mode, we need to notify the firmware to update
+        * the beacon info after we changed the capability. */
+       if (cap != priv->capability &&
+           priv->ieee->iw_mode == IW_MODE_ADHOC &&
+           priv->status & STATUS_ASSOCIATED)
+               ipw_disassociate(priv);
+       up(&priv->sem);
+       return ret;
  }
  
  static int ipw_wx_get_encode(struct net_device *dev,
@@@ -5881,17 -9050,17 +9051,17 @@@ static int ipw_wx_set_power(struct net_
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
        int err;
+       down(&priv->sem);
        if (wrqu->power.disabled) {
                priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
                err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
                if (err) {
                        IPW_DEBUG_WX("failed setting power mode.\n");
+                       up(&priv->sem);
                        return err;
                }
                IPW_DEBUG_WX("SET Power Management Mode -> off\n");
+               up(&priv->sem);
                return 0;
        }
  
        default:                /* Otherwise we don't support it */
                IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
                             wrqu->power.flags);
+               up(&priv->sem);
                return -EOPNOTSUPP;
        }
  
        err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
        if (err) {
                IPW_DEBUG_WX("failed setting power mode.\n");
+               up(&priv->sem);
                return err;
        }
  
        IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
+       up(&priv->sem);
        return 0;
  }
  
@@@ -5928,13 -9099,13 +9100,13 @@@ static int ipw_wx_get_power(struct net_
                            union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
-       if (!(priv->power_mode & IPW_POWER_ENABLED)) {
+       down(&priv->sem);
+       if (!(priv->power_mode & IPW_POWER_ENABLED))
                wrqu->power.disabled = 1;
-       } else {
+       else
                wrqu->power.disabled = 0;
-       }
  
+       up(&priv->sem);
        IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
  
        return 0;
@@@ -5947,7 -9118,7 +9119,7 @@@ static int ipw_wx_set_powermode(struct 
        struct ipw_priv *priv = ieee80211_priv(dev);
        int mode = *(int *)extra;
        int err;
+       down(&priv->sem);
        if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
                mode = IPW_POWER_AC;
                priv->power_mode = mode;
  
                if (err) {
                        IPW_DEBUG_WX("failed setting power mode.\n");
+                       up(&priv->sem);
                        return err;
                }
        }
+       up(&priv->sem);
        return 0;
  }
  
@@@ -6012,7 -9184,7 +9185,7 @@@ static int ipw_wx_set_wireless_mode(str
                IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
                return -EINVAL;
        }
+       down(&priv->sem);
        if (priv->adapter == IPW_2915ABG) {
                priv->ieee->abg_true = 1;
                if (mode & IEEE_A) {
                if (mode & IEEE_A) {
                        IPW_WARNING("Attempt to set 2200BG into "
                                    "802.11a mode\n");
+                       up(&priv->sem);
                        return -EINVAL;
                }
  
        priv->ieee->modulation = modulation;
        init_supported_rates(priv, &priv->rates);
  
-       /* If we are currently associated, or trying to associate
-        * then see if this is a new configuration (causing us to
-        * disassociate) */
-       if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
-               /* The resulting association will trigger
-                * the new rates to be sent to the device */
-               IPW_DEBUG_ASSOC("Disassociating due to mode change.\n");
-               ipw_disassociate(priv);
-       } else
+       /* Network configuration changed -- force [re]association */
+       IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
+       if (!ipw_disassociate(priv)) {
                ipw_send_supported_rates(priv, &priv->rates);
+               ipw_associate(priv);
+       }
+       /* Update the band LEDs */
+       ipw_led_band_on(priv);
  
        IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
                     mode & IEEE_A ? 'a' : '.',
                     mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
+       up(&priv->sem);
        return 0;
  }
  
@@@ -6069,124 -9242,234 +9243,234 @@@ static int ipw_wx_get_wireless_mode(str
                                    union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
-       switch (priv->ieee->freq_band) {
-       case IEEE80211_24GHZ_BAND:
-               switch (priv->ieee->modulation) {
-               case IEEE80211_CCK_MODULATION:
-                       strncpy(extra, "802.11b (2)", MAX_WX_STRING);
-                       break;
-               case IEEE80211_OFDM_MODULATION:
-                       strncpy(extra, "802.11g (4)", MAX_WX_STRING);
-                       break;
-               default:
-                       strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
-                       break;
-               }
-               break;
-       case IEEE80211_52GHZ_BAND:
+       down(&priv->sem);
+       switch (priv->ieee->mode) {
+       case IEEE_A:
                strncpy(extra, "802.11a (1)", MAX_WX_STRING);
                break;
-       default:                /* Mixed Band */
-               switch (priv->ieee->modulation) {
-               case IEEE80211_CCK_MODULATION:
-                       strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
-                       break;
-               case IEEE80211_OFDM_MODULATION:
-                       strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
-                       break;
-               default:
-                       strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
-                       break;
-               }
+       case IEEE_B:
+               strncpy(extra, "802.11b (2)", MAX_WX_STRING);
+               break;
+       case IEEE_A | IEEE_B:
+               strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
+               break;
+       case IEEE_G:
+               strncpy(extra, "802.11g (4)", MAX_WX_STRING);
+               break;
+       case IEEE_A | IEEE_G:
+               strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
+               break;
+       case IEEE_B | IEEE_G:
+               strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
+               break;
+       case IEEE_A | IEEE_B | IEEE_G:
+               strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
+               break;
+       default:
+               strncpy(extra, "unknown", MAX_WX_STRING);
                break;
        }
  
        IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
  
        wrqu->data.length = strlen(extra) + 1;
+       up(&priv->sem);
+       return 0;
+ }
+ static int ipw_wx_set_preamble(struct net_device *dev,
+                              struct iw_request_info *info,
+                              union iwreq_data *wrqu, char *extra)
+ {
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       int mode = *(int *)extra;
+       down(&priv->sem);
+       /* Switching from SHORT -> LONG requires a disassociation */
+       if (mode == 1) {
+               if (!(priv->config & CFG_PREAMBLE_LONG)) {
+                       priv->config |= CFG_PREAMBLE_LONG;
+                       /* Network configuration changed -- force [re]association */
+                       IPW_DEBUG_ASSOC
+                           ("[re]association triggered due to preamble change.\n");
+                       if (!ipw_disassociate(priv))
+                               ipw_associate(priv);
+               }
+               goto done;
+       }
  
+       if (mode == 0) {
+               priv->config &= ~CFG_PREAMBLE_LONG;
+               goto done;
+       }
+       up(&priv->sem);
+       return -EINVAL;
+       done:
+       up(&priv->sem);
+       return 0;
+ }
+ static int ipw_wx_get_preamble(struct net_device *dev,
+                              struct iw_request_info *info,
+                              union iwreq_data *wrqu, char *extra)
+ {
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       down(&priv->sem);
+       if (priv->config & CFG_PREAMBLE_LONG)
+               snprintf(wrqu->name, IFNAMSIZ, "long (1)");
+       else
+               snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
+       up(&priv->sem);
        return 0;
  }
  
- #ifdef CONFIG_IPW_PROMISC
- static int ipw_wx_set_promisc(struct net_device *dev,
+ #ifdef CONFIG_IPW2200_MONITOR
+ static int ipw_wx_set_monitor(struct net_device *dev,
                              struct iw_request_info *info,
                              union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
        int *parms = (int *)extra;
        int enable = (parms[0] > 0);
-       IPW_DEBUG_WX("SET PROMISC: %d %d\n", enable, parms[1]);
+       down(&priv->sem);
+       IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
        if (enable) {
                if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
+ #ifdef CONFIG_IEEE80211_RADIOTAP
+                       priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
+ #else
                        priv->net_dev->type = ARPHRD_IEEE80211;
-                       ipw_adapter_restart(priv);
+ #endif
+                       queue_work(priv->workqueue, &priv->adapter_restart);
                }
  
                ipw_set_channel(priv, parms[1]);
        } else {
-               if (priv->ieee->iw_mode != IW_MODE_MONITOR)
+               if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
+                       up(&priv->sem);
                        return 0;
+               }
                priv->net_dev->type = ARPHRD_ETHER;
-               ipw_adapter_restart(priv);
+               queue_work(priv->workqueue, &priv->adapter_restart);
        }
+       up(&priv->sem);
        return 0;
  }
  
+ #endif                                // CONFIG_IPW2200_MONITOR
  static int ipw_wx_reset(struct net_device *dev,
                        struct iw_request_info *info,
                        union iwreq_data *wrqu, char *extra)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
        IPW_DEBUG_WX("RESET\n");
-       ipw_adapter_restart(priv);
+       queue_work(priv->workqueue, &priv->adapter_restart);
+       return 0;
+ }
+ static int ipw_wx_sw_reset(struct net_device *dev,
+                          struct iw_request_info *info,
+                          union iwreq_data *wrqu, char *extra)
+ {
+       struct ipw_priv *priv = ieee80211_priv(dev);
+       union iwreq_data wrqu_sec = {
+               .encoding = {
+                            .flags = IW_ENCODE_DISABLED,
+                            },
+       };
+       int ret;
+       IPW_DEBUG_WX("SW_RESET\n");
+       down(&priv->sem);
+       ret = ipw_sw_reset(priv, 0);
+       if (!ret) {
+               free_firmware();
+               ipw_adapter_restart(priv);
+       }
+       /* The SW reset bit might have been toggled on by the 'disable'
+        * module parameter, so take appropriate action */
+       ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
+       up(&priv->sem);
+       ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
+       down(&priv->sem);
+       if (!(priv->status & STATUS_RF_KILL_MASK)) {
+               /* Configuration likely changed -- force [re]association */
+               IPW_DEBUG_ASSOC("[re]association triggered due to sw "
+                               "reset.\n");
+               if (!ipw_disassociate(priv))
+                       ipw_associate(priv);
+       }
+       up(&priv->sem);
        return 0;
  }
- #endif                                // CONFIG_IPW_PROMISC
  
  /* Rebase the WE IOCTLs to zero for the handler array */
  #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
  static iw_handler ipw_wx_handlers[] = {
-       IW_IOCTL(SIOCGIWNAME)   = ipw_wx_get_name,
-       IW_IOCTL(SIOCSIWFREQ)   = ipw_wx_set_freq,
-       IW_IOCTL(SIOCGIWFREQ)   = ipw_wx_get_freq,
-       IW_IOCTL(SIOCSIWMODE)   = ipw_wx_set_mode,
-       IW_IOCTL(SIOCGIWMODE)   = ipw_wx_get_mode,
-       IW_IOCTL(SIOCGIWRANGE)  = ipw_wx_get_range,
-       IW_IOCTL(SIOCSIWAP)     = ipw_wx_set_wap,
-       IW_IOCTL(SIOCGIWAP)     = ipw_wx_get_wap,
-       IW_IOCTL(SIOCSIWSCAN)   = ipw_wx_set_scan,
-       IW_IOCTL(SIOCGIWSCAN)   = ipw_wx_get_scan,
-       IW_IOCTL(SIOCSIWESSID)  = ipw_wx_set_essid,
-       IW_IOCTL(SIOCGIWESSID)  = ipw_wx_get_essid,
-       IW_IOCTL(SIOCSIWNICKN)  = ipw_wx_set_nick,
-       IW_IOCTL(SIOCGIWNICKN)  = ipw_wx_get_nick,
-       IW_IOCTL(SIOCSIWRATE)   = ipw_wx_set_rate,
-       IW_IOCTL(SIOCGIWRATE)   = ipw_wx_get_rate,
-       IW_IOCTL(SIOCSIWRTS)    = ipw_wx_set_rts,
-       IW_IOCTL(SIOCGIWRTS)    = ipw_wx_get_rts,
-       IW_IOCTL(SIOCSIWFRAG)   = ipw_wx_set_frag,
-       IW_IOCTL(SIOCGIWFRAG)   = ipw_wx_get_frag,
-       IW_IOCTL(SIOCSIWTXPOW)  = ipw_wx_set_txpow,
-       IW_IOCTL(SIOCGIWTXPOW)  = ipw_wx_get_txpow,
-       IW_IOCTL(SIOCSIWRETRY)  = ipw_wx_set_retry,
-       IW_IOCTL(SIOCGIWRETRY)  = ipw_wx_get_retry,
-       IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
-       IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
-       IW_IOCTL(SIOCSIWPOWER)  = ipw_wx_set_power,
-       IW_IOCTL(SIOCGIWPOWER)  = ipw_wx_get_power,
+       IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
+       IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
+       IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
+       IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
+       IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
+       IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
+       IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
+       IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
+       IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
+       IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
+       IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
+       IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
+       IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
+       IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
+       IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
+       IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
+       IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
+       IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
+       IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
+       IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
+       IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
+       IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
+       IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
+       IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
+       IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
+       IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
+       IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
+       IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
+       IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
+       IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
+       IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
+       IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
+       IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
+       IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
+       IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
+       IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
+       IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
+       IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
+       IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
  };
  
- #define IPW_PRIV_SET_POWER    SIOCIWFIRSTPRIV
- #define IPW_PRIV_GET_POWER    SIOCIWFIRSTPRIV+1
- #define IPW_PRIV_SET_MODE     SIOCIWFIRSTPRIV+2
- #define IPW_PRIV_GET_MODE     SIOCIWFIRSTPRIV+3
- #define IPW_PRIV_SET_PROMISC  SIOCIWFIRSTPRIV+4
- #define IPW_PRIV_RESET                SIOCIWFIRSTPRIV+5
+ enum {
+       IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
+       IPW_PRIV_GET_POWER,
+       IPW_PRIV_SET_MODE,
+       IPW_PRIV_GET_MODE,
+       IPW_PRIV_SET_PREAMBLE,
+       IPW_PRIV_GET_PREAMBLE,
+       IPW_PRIV_RESET,
+       IPW_PRIV_SW_RESET,
+ #ifdef CONFIG_IPW2200_MONITOR
+       IPW_PRIV_SET_MONITOR,
+ #endif
+ };
  
  static struct iw_priv_args ipw_priv_args[] = {
        {
         .cmd = IPW_PRIV_GET_MODE,
         .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
         .name = "get_mode"},
- #ifdef CONFIG_IPW_PROMISC
        {
-        IPW_PRIV_SET_PROMISC,
-        IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
+        .cmd = IPW_PRIV_SET_PREAMBLE,
+        .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
+        .name = "set_preamble"},
+       {
+        .cmd = IPW_PRIV_GET_PREAMBLE,
+        .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
+        .name = "get_preamble"},
        {
         IPW_PRIV_RESET,
         IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
- #endif                                /* CONFIG_IPW_PROMISC */
+       {
+        IPW_PRIV_SW_RESET,
+        IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
+ #ifdef CONFIG_IPW2200_MONITOR
+       {
+        IPW_PRIV_SET_MONITOR,
+        IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
+ #endif                                /* CONFIG_IPW2200_MONITOR */
  };
  
  static iw_handler ipw_priv_handler[] = {
        ipw_wx_get_powermode,
        ipw_wx_set_wireless_mode,
        ipw_wx_get_wireless_mode,
- #ifdef CONFIG_IPW_PROMISC
-       ipw_wx_set_promisc,
+       ipw_wx_set_preamble,
+       ipw_wx_get_preamble,
        ipw_wx_reset,
+       ipw_wx_sw_reset,
+ #ifdef CONFIG_IPW2200_MONITOR
+       ipw_wx_set_monitor,
  #endif
  };
  
  static struct iw_handler_def ipw_wx_handler_def = {
-       .standard               = ipw_wx_handlers,
-       .num_standard           = ARRAY_SIZE(ipw_wx_handlers),
-       .num_private            = ARRAY_SIZE(ipw_priv_handler),
-       .num_private_args       = ARRAY_SIZE(ipw_priv_args),
-       .private                = ipw_priv_handler,
-       .private_args           = ipw_priv_args,
+       .standard = ipw_wx_handlers,
+       .num_standard = ARRAY_SIZE(ipw_wx_handlers),
+       .num_private = ARRAY_SIZE(ipw_priv_handler),
+       .num_private_args = ARRAY_SIZE(ipw_priv_args),
+       .private = ipw_priv_handler,
+       .private_args = ipw_priv_args,
+       .get_wireless_stats = ipw_get_wireless_stats,
  };
  
  /*
@@@ -6247,8 -9545,8 +9546,8 @@@ static struct iw_statistics *ipw_get_wi
  
        wstats = &priv->wstats;
  
-       /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
-        * ipw2100_wx_wireless_stats seems to be called before fw is
+       /* if hw is disabled, then ipw_get_ordinal() can't be called.
+        * netdev->get_wireless_stats seems to be called before fw is
         * initialized.  STATUS_ASSOCIATED will only be set if the hw is up
         * and associated; if not associcated, the values are all meaningless
         * anyway, so set them all to NULL and INVALID */
@@@ -6299,7 -9597,7 +9598,7 @@@ static inline void init_sys_config(stru
        sys_config->dot11g_auto_detection = 0;
        sys_config->enable_cts_to_self = 0;
        sys_config->bt_coexist_collision_thr = 0;
-       sys_config->pass_noise_stats_to_host = 1;
+       sys_config->pass_noise_stats_to_host = 1;       //1 -- fix for 256
  }
  
  static int ipw_net_open(struct net_device *dev)
        struct ipw_priv *priv = ieee80211_priv(dev);
        IPW_DEBUG_INFO("dev->open\n");
        /* we should be verifying the device is ready to be opened */
+       down(&priv->sem);
        if (!(priv->status & STATUS_RF_KILL_MASK) &&
            (priv->status & STATUS_ASSOCIATED))
                netif_start_queue(dev);
+       up(&priv->sem);
        return 0;
  }
  
@@@ -6327,22 -9627,34 +9628,34 @@@ modify to send one tfd per fragment ins
  we need to heavily modify the ieee80211_skb_to_txb.
  */
  
- static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
+ static inline int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
+                            int pri)
  {
        struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
            txb->fragments[0]->data;
        int i = 0;
        struct tfd_frame *tfd;
+ #ifdef CONFIG_IPW_QOS
+       int tx_id = ipw_get_tx_queue_number(priv, pri);
+       struct clx2_tx_queue *txq = &priv->txq[tx_id];
+ #else
        struct clx2_tx_queue *txq = &priv->txq[0];
+ #endif
        struct clx2_queue *q = &txq->q;
        u8 id, hdr_len, unicast;
        u16 remaining_bytes;
+       int fc;
+       /* If there isn't room in the queue, we return busy and let the
+        * network stack requeue the packet for us */
+       if (ipw_queue_space(q) < q->high_mark)
+               return NETDEV_TX_BUSY;
  
        switch (priv->ieee->iw_mode) {
        case IW_MODE_ADHOC:
                hdr_len = IEEE80211_3ADDR_LEN;
-               unicast = !is_broadcast_ether_addr(hdr->addr1) &&
-                   !is_multicast_ether_addr(hdr->addr1);
+               unicast = !(is_multicast_ether_addr(hdr->addr1) ||
+                           is_broadcast_ether_addr(hdr->addr1));
                id = ipw_find_station(priv, hdr->addr1);
                if (id == IPW_INVALID_STATION) {
                        id = ipw_add_station(priv, hdr->addr1);
  
        case IW_MODE_INFRA:
        default:
-               unicast = !is_broadcast_ether_addr(hdr->addr3) &&
-                   !is_multicast_ether_addr(hdr->addr3);
+               unicast = !(is_multicast_ether_addr(hdr->addr3) ||
+                           is_broadcast_ether_addr(hdr->addr3));
                hdr_len = IEEE80211_3ADDR_LEN;
                id = 0;
                break;
        tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
  
        tfd->u.data.cmd_id = DINO_CMD_TX;
-       tfd->u.data.len = txb->payload_size;
+       tfd->u.data.len = cpu_to_le16(txb->payload_size);
        remaining_bytes = txb->payload_size;
-       if (unlikely(!unicast))
-               tfd->u.data.tx_flags = DCT_FLAG_NO_WEP;
-       else
-               tfd->u.data.tx_flags = DCT_FLAG_NO_WEP | DCT_FLAG_ACK_REQD;
  
        if (priv->assoc_request.ieee_mode == IPW_B_MODE)
-               tfd->u.data.tx_flags_ext = DCT_FLAG_EXT_MODE_CCK;
+               tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
        else
-               tfd->u.data.tx_flags_ext = DCT_FLAG_EXT_MODE_OFDM;
+               tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
+       if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
+               tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
  
-       if (priv->config & CFG_PREAMBLE)
-               tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREMBL;
+       fc = le16_to_cpu(hdr->frame_ctl);
+       hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
  
        memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
  
+       if (likely(unicast))
+               tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
+       if (txb->encrypted && !priv->ieee->host_encrypt) {
+               switch (priv->ieee->sec.level) {
+               case SEC_LEVEL_3:
+                       tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
+                           IEEE80211_FCTL_PROTECTED;
+                       /* XXX: ACK flag must be set for CCMP even if it
+                        * is a multicast/broadcast packet, because CCMP
+                        * group communication encrypted by GTK is
+                        * actually done by the AP. */
+                       if (!unicast)
+                               tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
+                       tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
+                       tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
+                       tfd->u.data.key_index = 0;
+                       tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
+                       break;
+               case SEC_LEVEL_2:
+                       tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
+                           IEEE80211_FCTL_PROTECTED;
+                       tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
+                       tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
+                       tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
+                       break;
+               case SEC_LEVEL_1:
+                       tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
+                           IEEE80211_FCTL_PROTECTED;
+                       tfd->u.data.key_index = priv->ieee->tx_keyidx;
+                       if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
+                           40)
+                               tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
+                       else
+                               tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
+                       break;
+               case SEC_LEVEL_0:
+                       break;
+               default:
+                       printk(KERN_ERR "Unknow security level %d\n",
+                              priv->ieee->sec.level);
+                       break;
+               }
+       } else
+               /* No hardware encryption */
+               tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
+ #ifdef CONFIG_IPW_QOS
+       ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
+ #endif                                /* CONFIG_IPW_QOS */
        /* payload */
-       tfd->u.data.num_chunks = min((u8) (NUM_TFD_CHUNKS - 2), txb->nr_frags);
-       for (i = 0; i < tfd->u.data.num_chunks; i++) {
+       tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
+                                                txb->nr_frags));
+       IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
+                      txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
+       for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
+               IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
+                              i, le32_to_cpu(tfd->u.data.num_chunks),
+                              txb->fragments[i]->len - hdr_len);
                IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
                             i, tfd->u.data.num_chunks,
                             txb->fragments[i]->len - hdr_len);
                           txb->fragments[i]->len - hdr_len);
  
                tfd->u.data.chunk_ptr[i] =
-                   pci_map_single(priv->pci_dev,
-                                  txb->fragments[i]->data + hdr_len,
-                                  txb->fragments[i]->len - hdr_len,
-                                  PCI_DMA_TODEVICE);
-               tfd->u.data.chunk_len[i] = txb->fragments[i]->len - hdr_len;
+                   cpu_to_le32(pci_map_single
+                               (priv->pci_dev,
+                                txb->fragments[i]->data + hdr_len,
+                                txb->fragments[i]->len - hdr_len,
+                                PCI_DMA_TODEVICE));
+               tfd->u.data.chunk_len[i] =
+                   cpu_to_le16(txb->fragments[i]->len - hdr_len);
        }
  
        if (i != txb->nr_frags) {
                       remaining_bytes);
                skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
                if (skb != NULL) {
-                       tfd->u.data.chunk_len[i] = remaining_bytes;
+                       tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
                        for (j = i; j < txb->nr_frags; j++) {
                                int size = txb->fragments[j]->len - hdr_len;
                                printk(KERN_INFO "Adding frag %d %d...\n",
                                       j, size);
                                memcpy(skb_put(skb, size),
                        dev_kfree_skb_any(txb->fragments[i]);
                        txb->fragments[i] = skb;
                        tfd->u.data.chunk_ptr[i] =
-                           pci_map_single(priv->pci_dev, skb->data,
-                                          tfd->u.data.chunk_len[i],
-                                          PCI_DMA_TODEVICE);
-                       tfd->u.data.num_chunks++;
+                           cpu_to_le32(pci_map_single
+                                       (priv->pci_dev, skb->data,
+                                        tfd->u.data.chunk_len[i],
+                                        PCI_DMA_TODEVICE));
+                       tfd->u.data.num_chunks =
+                           cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
+                                       1);
                }
        }
  
        q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
        ipw_write32(priv, q->reg_w, q->first_empty);
  
-       if (ipw_queue_space(q) < q->high_mark)
-               netif_stop_queue(priv->net_dev);
-       return;
+       return NETDEV_TX_OK;
  
        drop:
        IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
        ieee80211_txb_free(txb);
+       return NETDEV_TX_OK;
+ }
+ static int ipw_net_is_queue_full(struct net_device *dev, int pri)
+ {
+       struct ipw_priv *priv = ieee80211_priv(dev);
+ #ifdef CONFIG_IPW_QOS
+       int tx_id = ipw_get_tx_queue_number(priv, pri);
+       struct clx2_tx_queue *txq = &priv->txq[tx_id];
+ #else
+       struct clx2_tx_queue *txq = &priv->txq[0];
+ #endif                                /* CONFIG_IPW_QOS */
+       if (ipw_queue_space(&txq->q) < txq->q.high_mark)
+               return 1;
+       return 0;
  }
  
  static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
        unsigned long flags;
+       int ret;
  
        IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
        spin_lock_irqsave(&priv->lock, flags);
  
        if (!(priv->status & STATUS_ASSOCIATED)) {
                goto fail_unlock;
        }
  
-       ipw_tx_skb(priv, txb);
+       ret = ipw_tx_skb(priv, txb, pri);
+       if (ret == NETDEV_TX_OK)
+               __ipw_led_activity_on(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
-       return 0;
+       return ret;
  
        fail_unlock:
        spin_unlock_irqrestore(&priv->lock, flags);
@@@ -6498,11 -9890,13 +9891,13 @@@ static int ipw_net_set_mac_address(stru
        struct sockaddr *addr = p;
        if (!is_valid_ether_addr(addr->sa_data))
                return -EADDRNOTAVAIL;
+       down(&priv->sem);
        priv->config |= CFG_CUSTOM_MAC;
        memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
        printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
               priv->net_dev->name, MAC_ARG(priv->mac_addr));
-       ipw_adapter_restart(priv);
+       queue_work(priv->workqueue, &priv->adapter_restart);
+       up(&priv->sem);
        return 0;
  }
  
@@@ -6525,7 -9919,7 +9920,7 @@@ static void ipw_ethtool_get_drvinfo(str
        snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
                 vers, date);
        strcpy(info->bus_info, pci_name(p->pci_dev));
-       info->eedump_len = CX2_EEPROM_IMAGE_SIZE;
+       info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
  }
  
  static u32 ipw_ethtool_get_link(struct net_device *dev)
  
  static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
  {
-       return CX2_EEPROM_IMAGE_SIZE;
+       return IPW_EEPROM_IMAGE_SIZE;
  }
  
  static int ipw_ethtool_get_eeprom(struct net_device *dev,
  {
        struct ipw_priv *p = ieee80211_priv(dev);
  
-       if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE)
+       if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
                return -EINVAL;
-       memcpy(bytes, &((u8 *) p->eeprom)[eeprom->offset], eeprom->len);
+       down(&p->sem);
+       memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
+       up(&p->sem);
        return 0;
  }
  
@@@ -6557,23 -9952,23 +9953,23 @@@ static int ipw_ethtool_set_eeprom(struc
        struct ipw_priv *p = ieee80211_priv(dev);
        int i;
  
-       if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE)
+       if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
                return -EINVAL;
-       memcpy(&((u8 *) p->eeprom)[eeprom->offset], bytes, eeprom->len);
+       down(&p->sem);
+       memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
        for (i = IPW_EEPROM_DATA;
-            i < IPW_EEPROM_DATA + CX2_EEPROM_IMAGE_SIZE; i++)
+            i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++)
                ipw_write8(p, i, p->eeprom[i]);
+       up(&p->sem);
        return 0;
  }
  
  static struct ethtool_ops ipw_ethtool_ops = {
-       .get_link       = ipw_ethtool_get_link,
-       .get_drvinfo    = ipw_ethtool_get_drvinfo,
-       .get_eeprom_len = ipw_ethtool_get_eeprom_len,
-       .get_eeprom     = ipw_ethtool_get_eeprom,
-       .set_eeprom     = ipw_ethtool_set_eeprom,
+       .get_link = ipw_ethtool_get_link,
+       .get_drvinfo = ipw_ethtool_get_drvinfo,
+       .get_eeprom_len = ipw_ethtool_get_eeprom_len,
+       .get_eeprom = ipw_ethtool_get_eeprom,
+       .set_eeprom = ipw_ethtool_set_eeprom,
  };
  
  static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
                goto none;
        }
  
-       inta = ipw_read32(priv, CX2_INTA_RW);
-       inta_mask = ipw_read32(priv, CX2_INTA_MASK_R);
+       inta = ipw_read32(priv, IPW_INTA_RW);
+       inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
  
        if (inta == 0xFFFFFFFF) {
                /* Hardware disappeared */
                goto none;
        }
  
-       if (!(inta & (CX2_INTA_MASK_ALL & inta_mask))) {
+       if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
                /* Shared interrupt */
                goto none;
        }
        ipw_disable_interrupts(priv);
  
        /* ack current interrupts */
-       inta &= (CX2_INTA_MASK_ALL & inta_mask);
-       ipw_write32(priv, CX2_INTA_RW, inta);
+       inta &= (IPW_INTA_MASK_ALL & inta_mask);
+       ipw_write32(priv, IPW_INTA_RW, inta);
  
        /* Cache INTA value for our tasklet */
        priv->isr_inta = inta;
@@@ -6652,8 -10047,79 +10048,79 @@@ static void ipw_rf_kill(void *adapter
                IPW_DEBUG_RF_KILL("HW RF Kill deactivated.  SW RF Kill still "
                                  "enabled\n");
  
-       exit_unlock:
-       spin_unlock_irqrestore(&priv->lock, flags);
+       exit_unlock:
+       spin_unlock_irqrestore(&priv->lock, flags);
+ }
+ static void ipw_bg_rf_kill(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_rf_kill(data);
+       up(&priv->sem);
+ }
+ void ipw_link_up(struct ipw_priv *priv)
+ {
+       priv->last_seq_num = -1;
+       priv->last_frag_num = -1;
+       priv->last_packet_time = 0;
+       netif_carrier_on(priv->net_dev);
+       if (netif_queue_stopped(priv->net_dev)) {
+               IPW_DEBUG_NOTIF("waking queue\n");
+               netif_wake_queue(priv->net_dev);
+       } else {
+               IPW_DEBUG_NOTIF("starting queue\n");
+               netif_start_queue(priv->net_dev);
+       }
+       cancel_delayed_work(&priv->request_scan);
+       ipw_reset_stats(priv);
+       /* Ensure the rate is updated immediately */
+       priv->last_rate = ipw_get_current_rate(priv);
+       ipw_gather_stats(priv);
+       ipw_led_link_up(priv);
+       notify_wx_assoc_event(priv);
+       if (priv->config & CFG_BACKGROUND_SCAN)
+               queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
+ }
+ static void ipw_bg_link_up(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_link_up(data);
+       up(&priv->sem);
+ }
+ void ipw_link_down(struct ipw_priv *priv)
+ {
+       ipw_led_link_down(priv);
+       netif_carrier_off(priv->net_dev);
+       netif_stop_queue(priv->net_dev);
+       notify_wx_assoc_event(priv);
+       /* Cancel any queued work ... */
+       cancel_delayed_work(&priv->request_scan);
+       cancel_delayed_work(&priv->adhoc_check);
+       cancel_delayed_work(&priv->gather_stats);
+       ipw_reset_stats(priv);
+       if (!(priv->status & STATUS_EXIT_PENDING)) {
+               /* Queue up another scan... */
+               queue_work(priv->workqueue, &priv->request_scan);
+       }
+ }
+ static void ipw_bg_link_down(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_link_down(data);
+       up(&priv->sem);
  }
  
  static int ipw_setup_deferred_work(struct ipw_priv *priv)
  
        priv->workqueue = create_workqueue(DRV_NAME);
        init_waitqueue_head(&priv->wait_command_queue);
-       INIT_WORK(&priv->adhoc_check, ipw_adhoc_check, priv);
-       INIT_WORK(&priv->associate, ipw_associate, priv);
-       INIT_WORK(&priv->disassociate, ipw_disassociate, priv);
-       INIT_WORK(&priv->rx_replenish, ipw_rx_queue_replenish, priv);
-       INIT_WORK(&priv->adapter_restart, ipw_adapter_restart, priv);
-       INIT_WORK(&priv->rf_kill, ipw_rf_kill, priv);
-       INIT_WORK(&priv->up, (void (*)(void *))ipw_up, priv);
-       INIT_WORK(&priv->down, (void (*)(void *))ipw_down, priv);
+       init_waitqueue_head(&priv->wait_state);
+       INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
+       INIT_WORK(&priv->associate, ipw_bg_associate, priv);
+       INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
+       INIT_WORK(&priv->system_config, ipw_system_config, priv);
+       INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
+       INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
+       INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
+       INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
+       INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
        INIT_WORK(&priv->request_scan,
                  (void (*)(void *))ipw_request_scan, priv);
        INIT_WORK(&priv->gather_stats,
-                 (void (*)(void *))ipw_gather_stats, priv);
-       INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_abort_scan, priv);
-       INIT_WORK(&priv->roam, ipw_roam, priv);
-       INIT_WORK(&priv->scan_check, ipw_scan_check, priv);
+                 (void (*)(void *))ipw_bg_gather_stats, priv);
+       INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
+       INIT_WORK(&priv->roam, ipw_bg_roam, priv);
+       INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
+       INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
+       INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
+       INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
+                 priv);
+       INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
+                 priv);
+       INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
+                 priv);
+       INIT_WORK(&priv->merge_networks,
+                 (void (*)(void *))ipw_merge_adhoc_network, priv);
+ #ifdef CONFIG_IPW_QOS
+       INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
+                 priv);
+ #endif                                /* CONFIG_IPW_QOS */
  
        tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
                     ipw_irq_tasklet, (unsigned long)priv);
@@@ -6690,34 -10173,36 +10174,36 @@@ static void shim__set_security(struct n
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
        int i;
        for (i = 0; i < 4; i++) {
                if (sec->flags & (1 << i)) {
-                       priv->sec.key_sizes[i] = sec->key_sizes[i];
+                       priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
+                       priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
                        if (sec->key_sizes[i] == 0)
-                               priv->sec.flags &= ~(1 << i);
-                       else
-                               memcpy(priv->sec.keys[i], sec->keys[i],
+                               priv->ieee->sec.flags &= ~(1 << i);
+                       else {
+                               memcpy(priv->ieee->sec.keys[i], sec->keys[i],
                                       sec->key_sizes[i]);
-                       priv->sec.flags |= (1 << i);
+                               priv->ieee->sec.flags |= (1 << i);
+                       }
                        priv->status |= STATUS_SECURITY_UPDATED;
-               }
+               } else if (sec->level != SEC_LEVEL_1)
+                       priv->ieee->sec.flags &= ~(1 << i);
        }
  
-       if ((sec->flags & SEC_ACTIVE_KEY) &&
-           priv->sec.active_key != sec->active_key) {
+       if (sec->flags & SEC_ACTIVE_KEY) {
                if (sec->active_key <= 3) {
-                       priv->sec.active_key = sec->active_key;
-                       priv->sec.flags |= SEC_ACTIVE_KEY;
+                       priv->ieee->sec.active_key = sec->active_key;
+                       priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
                } else
-                       priv->sec.flags &= ~SEC_ACTIVE_KEY;
+                       priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
                priv->status |= STATUS_SECURITY_UPDATED;
-       }
+       } else
+               priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
  
        if ((sec->flags & SEC_AUTH_MODE) &&
-           (priv->sec.auth_mode != sec->auth_mode)) {
-               priv->sec.auth_mode = sec->auth_mode;
-               priv->sec.flags |= SEC_AUTH_MODE;
+           (priv->ieee->sec.auth_mode != sec->auth_mode)) {
+               priv->ieee->sec.auth_mode = sec->auth_mode;
+               priv->ieee->sec.flags |= SEC_AUTH_MODE;
                if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
                        priv->capability |= CAP_SHARED_KEY;
                else
                priv->status |= STATUS_SECURITY_UPDATED;
        }
  
-       if (sec->flags & SEC_ENABLED && priv->sec.enabled != sec->enabled) {
-               priv->sec.flags |= SEC_ENABLED;
-               priv->sec.enabled = sec->enabled;
+       if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
+               priv->ieee->sec.flags |= SEC_ENABLED;
+               priv->ieee->sec.enabled = sec->enabled;
                priv->status |= STATUS_SECURITY_UPDATED;
                if (sec->enabled)
                        priv->capability |= CAP_PRIVACY_ON;
                        priv->capability &= ~CAP_PRIVACY_ON;
        }
  
-       if (sec->flags & SEC_LEVEL && priv->sec.level != sec->level) {
-               priv->sec.level = sec->level;
-               priv->sec.flags |= SEC_LEVEL;
+       if (sec->flags & SEC_ENCRYPT)
+               priv->ieee->sec.encrypt = sec->encrypt;
+       if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
+               priv->ieee->sec.level = sec->level;
+               priv->ieee->sec.flags |= SEC_LEVEL;
                priv->status |= STATUS_SECURITY_UPDATED;
        }
  
+       if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
+               ipw_set_hwcrypto_keys(priv);
        /* To match current functionality of ipw2100 (which works well w/
         * various supplicants, we don't force a disassociate if the
         * privacy capability changes ... */
@@@ -6789,29 -10280,10 +10281,10 @@@ static int init_supported_rates(struct 
  
  static int ipw_config(struct ipw_priv *priv)
  {
-       int i;
-       struct ipw_tx_power tx_power;
-       memset(&priv->sys_config, 0, sizeof(priv->sys_config));
-       memset(&tx_power, 0, sizeof(tx_power));
        /* This is only called from ipw_up, which resets/reloads the firmware
           so, we don't need to first disable the card before we configure
           it */
-       /* configure device for 'G' band */
-       tx_power.ieee_mode = IPW_G_MODE;
-       tx_power.num_channels = 11;
-       for (i = 0; i < 11; i++) {
-               tx_power.channels_tx_power[i].channel_number = i + 1;
-               tx_power.channels_tx_power[i].tx_power = priv->tx_power;
-       }
-       if (ipw_send_tx_power(priv, &tx_power))
-               goto error;
-       /* configure device to also handle 'B' band */
-       tx_power.ieee_mode = IPW_B_MODE;
-       if (ipw_send_tx_power(priv, &tx_power))
+       if (ipw_set_tx_power(priv))
                goto error;
  
        /* initialize adapter address */
  
        /* set basic system config settings */
        init_sys_config(&priv->sys_config);
+       if (priv->ieee->iw_mode == IW_MODE_ADHOC)
+               priv->sys_config.answer_broadcast_ssid_probe = 1;
+       else
+               priv->sys_config.answer_broadcast_ssid_probe = 0;
        if (ipw_send_system_config(priv, &priv->sys_config))
                goto error;
  
                if (ipw_send_rts_threshold(priv, priv->rts_threshold))
                        goto error;
        }
+ #ifdef CONFIG_IPW_QOS
+       IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
+       ipw_qos_activate(priv, NULL);
+ #endif                                /* CONFIG_IPW_QOS */
  
        if (ipw_set_random_seed(priv))
                goto error;
        if (ipw_send_host_complete(priv))
                goto error;
  
-       /* If configured to try and auto-associate, kick off a scan */
-       if ((priv->config & CFG_ASSOCIATE) && ipw_request_scan(priv))
-               goto error;
+       priv->status |= STATUS_INIT;
+       ipw_led_init(priv);
+       ipw_led_radio_on(priv);
+       priv->notif_missed_beacons = 0;
+       /* Set hardware WEP key if it is configured. */
+       if ((priv->capability & CAP_PRIVACY_ON) &&
+           (priv->ieee->sec.level == SEC_LEVEL_1) &&
+           !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
+               ipw_set_hwcrypto_keys(priv);
  
        return 0;
  
        return -EIO;
  }
  
+ /*
+  * NOTE:
+  *
+  * These tables have been tested in conjunction with the
+  * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
+  *
+  * Altering this values, using it on other hardware, or in geographies
+  * not intended for resale of the above mentioned Intel adapters has
+  * not been tested.
+  *
+  */
+ static const struct ieee80211_geo ipw_geos[] = {
+       {                       /* Restricted */
+        "---",
+        .bg_channels = 11,
+        .bg = {{2412, 1}, {2417, 2}, {2422, 3},
+               {2427, 4}, {2432, 5}, {2437, 6},
+               {2442, 7}, {2447, 8}, {2452, 9},
+               {2457, 10}, {2462, 11}},
+        },
+       {                       /* Custom US/Canada */
+        "ZZF",
+        .bg_channels = 11,
+        .bg = {{2412, 1}, {2417, 2}, {2422, 3},
+               {2427, 4}, {2432, 5}, {2437, 6},
+               {2442, 7}, {2447, 8}, {2452, 9},
+               {2457, 10}, {2462, 11}},
+        .a_channels = 8,
+        .a = {{5180, 36},
+              {5200, 40},
+              {5220, 44},
+              {5240, 48},
+              {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
+              {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
+              {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
+              {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
+        },
+       {                       /* Rest of World */
+        "ZZD",
+        .bg_channels = 13,
+        .bg = {{2412, 1}, {2417, 2}, {2422, 3},
+               {2427, 4}, {2432, 5}, {2437, 6},
+               {2442, 7}, {2447, 8}, {2452, 9},
+               {2457, 10}, {2462, 11}, {2467, 12},
+               {2472, 13}},
+        },
+       {                       /* Custom USA & Europe & High */
+        "ZZA",
+        .bg_channels = 11,
+        .bg = {{2412, 1}, {2417, 2}, {2422, 3},
+               {2427, 4}, {2432, 5}, {2437, 6},
+               {2442, 7}, {2447, 8}, {2452, 9},
+               {2457, 10}, {2462, 11}},
+        .a_channels = 13,
+        .a = {{5180, 36},
+              {5200, 40},
+              {5220, 44},
+              {5240, 48},
+              {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
+              {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
+              {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
+              {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
+              {5745, 149},
+              {5765, 153},
+              {5785, 157},
+              {5805, 161},
+              {5825, 165}},
+        },
+       {                       /* Custom NA & Europe */
+        "ZZB",
+        .bg_channels = 11,
+        .bg = {{2412, 1}, {2417, 2}, {2422, 3},
+               {2427, 4}, {2432, 5}, {2437, 6},
+               {2442, 7}, {2447, 8}, {2452, 9},
+               {2457, 10}, {2462, 11}},
+        .a_channels = 13,
+        .a = {{5180, 36},
+              {5200, 40},
+              {5220, 44},
+              {5240, 48},
+              {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
+              {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
+              {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
+              {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
+              {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
+              {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
+              {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
+              {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
+              {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
+        },
+       {                       /* Custom Japan */
+        "ZZC",
+        .bg_channels = 11,
+        .bg = {{2412, 1}, {2417, 2}, {2422, 3},
+               {2427, 4}, {2432, 5}, {2437, 6},
+               {2442, 7}, {2447, 8}, {2452, 9},
+               {2457, 10}, {2462, 11}},
+        .a_channels = 4,
+        .a = {{5170, 34}, {5190, 38},
+              {5210, 42}, {5230, 46}},
+        },
+       {                       /* Custom */
+        "ZZM",
+        .bg_channels = 11,
+        .bg = {{2412, 1}, {2417, 2}, {2422, 3},
+               {2427, 4}, {2432, 5}, {2437, 6},
+               {2442, 7}, {2447, 8}, {2452, 9},
+               {2457, 10}, {2462, 11}},
+        },
+       {                       /* Europe */
+        "ZZE",
+        .bg_channels = 13,
+        .bg = {{2412, 1}, {2417, 2}, {2422, 3},
+               {2427, 4}, {2432, 5}, {2437, 6},
+               {2442, 7}, {2447, 8}, {2452, 9},
+               {2457, 10}, {2462, 11}, {2467, 12},
+               {2472, 13}},
+        .a_channels = 19,
+        .a = {{5180, 36},
+              {5200, 40},
+              {5220, 44},
+              {5240, 48},
+              {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
+              {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
+              {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
+              {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
+              {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
+              {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
+              {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
+              {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
+              {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
+              {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
+              {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
+              {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
+              {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
+              {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
+              {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
+        },
+       {                       /* Custom Japan */
+        "ZZJ",
+        .bg_channels = 14,
+        .bg = {{2412, 1}, {2417, 2}, {2422, 3},
+               {2427, 4}, {2432, 5}, {2437, 6},
+               {2442, 7}, {2447, 8}, {2452, 9},
+               {2457, 10}, {2462, 11}, {2467, 12},
+               {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
+        .a_channels = 4,
+        .a = {{5170, 34}, {5190, 38},
+              {5210, 42}, {5230, 46}},
+        },
+       {                       /* Rest of World */
+        "ZZR",
+        .bg_channels = 14,
+        .bg = {{2412, 1}, {2417, 2}, {2422, 3},
+               {2427, 4}, {2432, 5}, {2437, 6},
+               {2442, 7}, {2447, 8}, {2452, 9},
+               {2457, 10}, {2462, 11}, {2467, 12},
+               {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
+                            IEEE80211_CH_PASSIVE_ONLY}},
+        },
+       {                       /* High Band */
+        "ZZH",
+        .bg_channels = 13,
+        .bg = {{2412, 1}, {2417, 2}, {2422, 3},
+               {2427, 4}, {2432, 5}, {2437, 6},
+               {2442, 7}, {2447, 8}, {2452, 9},
+               {2457, 10}, {2462, 11},
+               {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
+               {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
+        .a_channels = 4,
+        .a = {{5745, 149}, {5765, 153},
+              {5785, 157}, {5805, 161}},
+        },
+       {                       /* Custom Europe */
+        "ZZG",
+        .bg_channels = 13,
+        .bg = {{2412, 1}, {2417, 2}, {2422, 3},
+               {2427, 4}, {2432, 5}, {2437, 6},
+               {2442, 7}, {2447, 8}, {2452, 9},
+               {2457, 10}, {2462, 11},
+               {2467, 12}, {2472, 13}},
+        .a_channels = 4,
+        .a = {{5180, 36}, {5200, 40},
+              {5220, 44}, {5240, 48}},
+        },
+       {                       /* Europe */
+        "ZZK",
+        .bg_channels = 13,
+        .bg = {{2412, 1}, {2417, 2}, {2422, 3},
+               {2427, 4}, {2432, 5}, {2437, 6},
+               {2442, 7}, {2447, 8}, {2452, 9},
+               {2457, 10}, {2462, 11},
+               {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
+               {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
+        .a_channels = 24,
+        .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
+              {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
+              {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
+              {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
+              {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
+              {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
+              {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
+              {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
+              {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
+              {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
+              {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
+              {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
+              {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
+              {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
+              {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
+              {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
+              {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
+              {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
+              {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
+              {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
+              {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
+              {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
+              {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
+              {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
+        },
+       {                       /* Europe */
+        "ZZL",
+        .bg_channels = 11,
+        .bg = {{2412, 1}, {2417, 2}, {2422, 3},
+               {2427, 4}, {2432, 5}, {2437, 6},
+               {2442, 7}, {2447, 8}, {2452, 9},
+               {2457, 10}, {2462, 11}},
+        .a_channels = 13,
+        .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
+              {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
+              {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
+              {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
+              {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
+              {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
+              {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
+              {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
+              {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
+              {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
+              {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
+              {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
+              {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
+        }
+ };
+ /* GEO code borrowed from ieee80211_geo.c */
+ static int ipw_is_valid_channel(struct ieee80211_device *ieee, u8 channel)
+ {
+       int i;
+       /* Driver needs to initialize the geography map before using
+        * these helper functions */
+       BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
+       if (ieee->freq_band & IEEE80211_24GHZ_BAND)
+               for (i = 0; i < ieee->geo.bg_channels; i++)
+                       /* NOTE: If G mode is currently supported but
+                        * this is a B only channel, we don't see it
+                        * as valid. */
+                       if ((ieee->geo.bg[i].channel == channel) &&
+                           (!(ieee->mode & IEEE_G) ||
+                            !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY)))
+                               return IEEE80211_24GHZ_BAND;
+       if (ieee->freq_band & IEEE80211_52GHZ_BAND)
+               for (i = 0; i < ieee->geo.a_channels; i++)
+                       if (ieee->geo.a[i].channel == channel)
+                               return IEEE80211_52GHZ_BAND;
+       return 0;
+ }
+ static int ipw_channel_to_index(struct ieee80211_device *ieee, u8 channel)
+ {
+       int i;
+       /* Driver needs to initialize the geography map before using
+        * these helper functions */
+       BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
+       if (ieee->freq_band & IEEE80211_24GHZ_BAND)
+               for (i = 0; i < ieee->geo.bg_channels; i++)
+                       if (ieee->geo.bg[i].channel == channel)
+                               return i;
+       if (ieee->freq_band & IEEE80211_52GHZ_BAND)
+               for (i = 0; i < ieee->geo.a_channels; i++)
+                       if (ieee->geo.a[i].channel == channel)
+                               return i;
+       return -1;
+ }
+ static u8 ipw_freq_to_channel(struct ieee80211_device *ieee, u32 freq)
+ {
+       int i;
+       /* Driver needs to initialize the geography map before using
+        * these helper functions */
+       BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
+       freq /= 100000;
+       if (ieee->freq_band & IEEE80211_24GHZ_BAND)
+               for (i = 0; i < ieee->geo.bg_channels; i++)
+                       if (ieee->geo.bg[i].freq == freq)
+                               return ieee->geo.bg[i].channel;
+       if (ieee->freq_band & IEEE80211_52GHZ_BAND)
+               for (i = 0; i < ieee->geo.a_channels; i++)
+                       if (ieee->geo.a[i].freq == freq)
+                               return ieee->geo.a[i].channel;
+       return 0;
+ }
+ static int ipw_set_geo(struct ieee80211_device *ieee,
+                      const struct ieee80211_geo *geo)
+ {
+       memcpy(ieee->geo.name, geo->name, 3);
+       ieee->geo.name[3] = '\0';
+       ieee->geo.bg_channels = geo->bg_channels;
+       ieee->geo.a_channels = geo->a_channels;
+       memcpy(ieee->geo.bg, geo->bg, geo->bg_channels *
+              sizeof(struct ieee80211_channel));
+       memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels *
+              sizeof(struct ieee80211_channel));
+       return 0;
+ }
+ static const struct ieee80211_geo *ipw_get_geo(struct ieee80211_device *ieee)
+ {
+       return &ieee->geo;
+ }
  #define MAX_HW_RESTARTS 5
  static int ipw_up(struct ipw_priv *priv)
  {
-       int rc, i;
+       int rc, i, j;
  
        if (priv->status & STATUS_EXIT_PENDING)
                return -EIO;
  
+       if (cmdlog && !priv->cmdlog) {
+               priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
+                                      GFP_KERNEL);
+               if (priv->cmdlog == NULL) {
+                       IPW_ERROR("Error allocating %d command log entries.\n",
+                                 cmdlog);
+               } else {
+                       memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
+                       priv->cmdlog_len = cmdlog;
+               }
+       }
        for (i = 0; i < MAX_HW_RESTARTS; i++) {
                /* Load the microcode, firmware, and eeprom.
                 * Also start the clocks. */
                rc = ipw_load(priv);
                if (rc) {
-                       IPW_ERROR("Unable to load firmware: 0x%08X\n", rc);
+                       IPW_ERROR("Unable to load firmware: %d\n", rc);
                        return rc;
                }
  
                        eeprom_parse_mac(priv, priv->mac_addr);
                memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
  
-               if (priv->status & STATUS_RF_KILL_MASK)
+               for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
+                       if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
+                                   ipw_geos[j].name, 3))
+                               break;
+               }
+               if (j == ARRAY_SIZE(ipw_geos)) {
+                       IPW_WARNING("SKU [%c%c%c] not recognized.\n",
+                                   priv->eeprom[EEPROM_COUNTRY_CODE + 0],
+                                   priv->eeprom[EEPROM_COUNTRY_CODE + 1],
+                                   priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
+                       j = 0;
+               }
+               if (ipw_set_geo(priv->ieee, &ipw_geos[j])) {
+                       IPW_WARNING("Could not set geography.");
+                       return 0;
+               }
+               IPW_DEBUG_INFO("Geography %03d [%s] detected.\n",
+                              j, priv->ieee->geo.name);
+               if (priv->status & STATUS_RF_KILL_SW) {
+                       IPW_WARNING("Radio disabled by module parameter.\n");
+                       return 0;
+               } else if (rf_kill_active(priv)) {
+                       IPW_WARNING("Radio Frequency Kill Switch is On:\n"
+                                   "Kill switch must be turned off for "
+                                   "wireless networking to work.\n");
+                       queue_delayed_work(priv->workqueue, &priv->rf_kill,
+                                          2 * HZ);
                        return 0;
+               }
  
                rc = ipw_config(priv);
                if (!rc) {
                        IPW_DEBUG_INFO("Configured device on count %i\n", i);
-                       priv->notif_missed_beacons = 0;
-                       netif_start_queue(priv->net_dev);
+                       /* If configure to try and auto-associate, kick
+                        * off a scan. */
+                       queue_work(priv->workqueue, &priv->request_scan);
                        return 0;
-               } else {
-                       IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n",
-                                      rc);
                }
  
+               IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
                IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
                               i, MAX_HW_RESTARTS);
  
        /* tried to restart and config the device for as long as our
         * patience could withstand */
        IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
        return -EIO;
  }
  
- static void ipw_down(struct ipw_priv *priv)
+ static void ipw_bg_up(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_up(data);
+       up(&priv->sem);
+ }
+ static void ipw_deinit(struct ipw_priv *priv)
  {
+       int i;
+       if (priv->status & STATUS_SCANNING) {
+               IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
+               ipw_abort_scan(priv);
+       }
+       if (priv->status & STATUS_ASSOCIATED) {
+               IPW_DEBUG_INFO("Disassociating during shutdown.\n");
+               ipw_disassociate(priv);
+       }
+       ipw_led_shutdown(priv);
+       /* Wait up to 1s for status to change to not scanning and not
+        * associated (disassociation can take a while for a ful 802.11
+        * exchange */
+       for (i = 1000; i && (priv->status &
+                            (STATUS_DISASSOCIATING |
+                             STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
+               udelay(10);
+       if (priv->status & (STATUS_DISASSOCIATING |
+                           STATUS_ASSOCIATED | STATUS_SCANNING))
+               IPW_DEBUG_INFO("Still associated or scanning...\n");
+       else
+               IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
        /* Attempt to disable the card */
- #if 0
        ipw_send_card_disable(priv, 0);
- #endif
+       priv->status &= ~STATUS_INIT;
+ }
+ static void ipw_down(struct ipw_priv *priv)
+ {
+       int exit_pending = priv->status & STATUS_EXIT_PENDING;
+       priv->status |= STATUS_EXIT_PENDING;
+       if (ipw_is_init(priv))
+               ipw_deinit(priv);
+       /* Wipe out the EXIT_PENDING status bit if we are not actually
+        * exiting the module */
+       if (!exit_pending)
+               priv->status &= ~STATUS_EXIT_PENDING;
  
        /* tell the device to stop sending interrupts */
        ipw_disable_interrupts(priv);
  
        /* Clear all bits but the RF Kill */
-       priv->status &= STATUS_RF_KILL_MASK;
+       priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
        netif_carrier_off(priv->net_dev);
        netif_stop_queue(priv->net_dev);
  
        ipw_stop_nic(priv);
+       ipw_led_radio_off(priv);
+ }
+ static void ipw_bg_down(void *data)
+ {
+       struct ipw_priv *priv = data;
+       down(&priv->sem);
+       ipw_down(data);
+       up(&priv->sem);
  }
  
  /* Called by register_netdev() */
  static int ipw_net_init(struct net_device *dev)
  {
        struct ipw_priv *priv = ieee80211_priv(dev);
+       down(&priv->sem);
  
-       if (priv->status & STATUS_RF_KILL_SW) {
-               IPW_WARNING("Radio disabled by module parameter.\n");
-               return 0;
-       } else if (rf_kill_active(priv)) {
-               IPW_WARNING("Radio Frequency Kill Switch is On:\n"
-                           "Kill switch must be turned off for "
-                           "wireless networking to work.\n");
-               queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
-               return 0;
-       }
-       if (ipw_up(priv))
+       if (ipw_up(priv)) {
+               up(&priv->sem);
                return -EIO;
+       }
  
+       up(&priv->sem);
        return 0;
  }
  
@@@ -6962,7 -10894,7 +10895,7 @@@ static struct pci_device_id card_ids[] 
        {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
        {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
        {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
-       {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 2225BG */
+       {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
        {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
        {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
  
@@@ -6982,11 -10914,16 +10915,16 @@@ static struct attribute *ipw_sysfs_entr
        &dev_attr_nic_type.attr,
        &dev_attr_status.attr,
        &dev_attr_cfg.attr,
-       &dev_attr_dump_errors.attr,
-       &dev_attr_dump_events.attr,
+       &dev_attr_error.attr,
+       &dev_attr_event_log.attr,
+       &dev_attr_cmd_log.attr,
        &dev_attr_eeprom_delay.attr,
        &dev_attr_ucode_version.attr,
        &dev_attr_rtc.attr,
+       &dev_attr_scan_age.attr,
+       &dev_attr_led.attr,
+       &dev_attr_speed_scan.attr,
+       &dev_attr_net_stats.attr,
        NULL
  };
  
@@@ -7002,7 -10939,7 +10940,7 @@@ static int ipw_pci_probe(struct pci_de
        void __iomem *base;
        u32 length, val;
        struct ipw_priv *priv;
-       int band, modulation;
+       int i;
  
        net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
        if (net_dev == NULL) {
  
        priv = ieee80211_priv(net_dev);
        priv->ieee = netdev_priv(net_dev);
        priv->net_dev = net_dev;
        priv->pci_dev = pdev;
  #ifdef CONFIG_IPW_DEBUG
        ipw_debug_level = debug;
  #endif
        spin_lock_init(&priv->lock);
+       for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
+               INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
  
+       init_MUTEX(&priv->sem);
        if (pci_enable_device(pdev)) {
                err = -ENODEV;
                goto out_free_ieee80211;
                goto out_iounmap;
        }
  
-       /* Initialize module parameter values here */
-       if (ifname)
-               strncpy(net_dev->name, ifname, IFNAMSIZ);
-       if (associate)
-               priv->config |= CFG_ASSOCIATE;
-       else
-               IPW_DEBUG_INFO("Auto associate disabled.\n");
-       if (auto_create)
-               priv->config |= CFG_ADHOC_CREATE;
-       else
-               IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
-       if (disable) {
-               priv->status |= STATUS_RF_KILL_SW;
-               IPW_DEBUG_INFO("Radio disabled.\n");
-       }
-       if (channel != 0) {
-               priv->config |= CFG_STATIC_CHANNEL;
-               priv->channel = channel;
-               IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
-               IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
-               /* TODO: Validate that provided channel is in range */
-       }
-       switch (mode) {
-       case 1:
-               priv->ieee->iw_mode = IW_MODE_ADHOC;
-               break;
- #ifdef CONFIG_IPW_PROMISC
-       case 2:
-               priv->ieee->iw_mode = IW_MODE_MONITOR;
-               break;
- #endif
-       default:
-       case 0:
-               priv->ieee->iw_mode = IW_MODE_INFRA;
-               break;
-       }
-       if ((priv->pci_dev->device == 0x4223) ||
-           (priv->pci_dev->device == 0x4224)) {
-               printk(KERN_INFO DRV_NAME
-                      ": Detected Intel PRO/Wireless 2915ABG Network "
-                      "Connection\n");
-               priv->ieee->abg_true = 1;
-               band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
-               modulation = IEEE80211_OFDM_MODULATION |
-                   IEEE80211_CCK_MODULATION;
-               priv->adapter = IPW_2915ABG;
-               priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
-       } else {
-               if (priv->pci_dev->device == 0x4221)
-                       printk(KERN_INFO DRV_NAME
-                              ": Detected Intel PRO/Wireless 2225BG Network "
-                              "Connection\n");
-               else
-                       printk(KERN_INFO DRV_NAME
-                              ": Detected Intel PRO/Wireless 2200BG Network "
-                              "Connection\n");
-               priv->ieee->abg_true = 0;
-               band = IEEE80211_24GHZ_BAND;
-               modulation = IEEE80211_OFDM_MODULATION |
-                   IEEE80211_CCK_MODULATION;
-               priv->adapter = IPW_2200BG;
-               priv->ieee->mode = IEEE_G | IEEE_B;
-       }
-       priv->ieee->freq_band = band;
-       priv->ieee->modulation = modulation;
-       priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
-       priv->missed_beacon_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
-       priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
-       priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
-       /* If power management is turned on, default to AC mode */
-       priv->power_mode = IPW_POWER_AC;
-       priv->tx_power = IPW_DEFAULT_TX_POWER;
+       ipw_sw_reset(priv, 1);
  
        err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
        if (err) {
        SET_MODULE_OWNER(net_dev);
        SET_NETDEV_DEV(net_dev, &pdev->dev);
  
+       down(&priv->sem);
        priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
        priv->ieee->set_security = shim__set_security;
+       priv->ieee->is_queue_full = ipw_net_is_queue_full;
+ #ifdef CONFIG_IPW_QOS
+       priv->ieee->handle_probe_response = ipw_handle_beacon;
+       priv->ieee->handle_beacon = ipw_handle_probe_response;
+       priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
+ #endif                                /* CONFIG_IPW_QOS */
+       priv->ieee->perfect_rssi = -20;
+       priv->ieee->worst_rssi = -85;
  
        net_dev->open = ipw_net_open;
        net_dev->stop = ipw_net_stop;
        net_dev->get_stats = ipw_net_get_stats;
        net_dev->set_multicast_list = ipw_net_set_multicast_list;
        net_dev->set_mac_address = ipw_net_set_mac_address;
-       net_dev->get_wireless_stats = ipw_get_wireless_stats;
+       priv->wireless_data.spy_data = &priv->ieee->spy_data;
+       priv->wireless_data.ieee80211 = priv->ieee;
+       net_dev->wireless_data = &priv->wireless_data;
        net_dev->wireless_handlers = &ipw_wx_handler_def;
        net_dev->ethtool_ops = &ipw_ethtool_ops;
        net_dev->irq = pdev->irq;
        err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
        if (err) {
                IPW_ERROR("failed to create sysfs device attributes\n");
+               up(&priv->sem);
                goto out_release_irq;
        }
  
+       up(&priv->sem);
        err = register_netdev(net_dev);
        if (err) {
                IPW_ERROR("failed to register network device\n");
-               goto out_remove_group;
+               goto out_remove_sysfs;
        }
        return 0;
  
-       out_remove_group:
+       out_remove_sysfs:
        sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
        out_release_irq:
        free_irq(pdev->irq, priv);
  static void ipw_pci_remove(struct pci_dev *pdev)
  {
        struct ipw_priv *priv = pci_get_drvdata(pdev);
+       struct list_head *p, *q;
+       int i;
        if (!priv)
                return;
  
-       priv->status |= STATUS_EXIT_PENDING;
+       down(&priv->sem);
  
+       priv->status |= STATUS_EXIT_PENDING;
+       ipw_down(priv);
        sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
  
-       ipw_down(priv);
+       up(&priv->sem);
  
        unregister_netdev(priv->net_dev);
  
        }
        ipw_tx_queue_free(priv);
  
+       if (priv->cmdlog) {
+               kfree(priv->cmdlog);
+               priv->cmdlog = NULL;
+       }
        /* ipw_down will ensure that there is no more pending work
         * in the workqueue's, so we can safely remove them now. */
-       if (priv->workqueue) {
-               cancel_delayed_work(&priv->adhoc_check);
-               cancel_delayed_work(&priv->gather_stats);
-               cancel_delayed_work(&priv->request_scan);
-               cancel_delayed_work(&priv->rf_kill);
-               cancel_delayed_work(&priv->scan_check);
-               destroy_workqueue(priv->workqueue);
-               priv->workqueue = NULL;
+       cancel_delayed_work(&priv->adhoc_check);
+       cancel_delayed_work(&priv->gather_stats);
+       cancel_delayed_work(&priv->request_scan);
+       cancel_delayed_work(&priv->rf_kill);
+       cancel_delayed_work(&priv->scan_check);
+       destroy_workqueue(priv->workqueue);
+       priv->workqueue = NULL;
+       /* Free MAC hash list for ADHOC */
+       for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
+               list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
+                       kfree(list_entry(p, struct ipw_ibss_seq, list));
+                       list_del(p);
+               }
+       }
+       if (priv->error) {
+               ipw_free_error_log(priv->error);
+               priv->error = NULL;
        }
  
        free_irq(pdev->irq, priv);
        pci_disable_device(pdev);
        pci_set_drvdata(pdev, NULL);
        free_ieee80211(priv->net_dev);
- #ifdef CONFIG_PM
-       if (fw_loaded) {
-               release_firmware(bootfw);
-               release_firmware(ucode);
-               release_firmware(firmware);
-               fw_loaded = 0;
-       }
- #endif
+       free_firmware();
  }
  
  #ifdef CONFIG_PM
@@@ -7288,13 -11173,10 +11174,10 @@@ static int ipw_pci_resume(struct pci_de
  
        printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
  
-       pci_set_power_state(pdev, 0);
+       pci_set_power_state(pdev, PCI_D0);
        pci_enable_device(pdev);
- #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
-       pci_restore_state(pdev, priv->pm_state);
- #else
        pci_restore_state(pdev);
- #endif
        /*
         * Suspend/Resume resets the PCI configuration space, so we have to
         * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
@@@ -7366,16 -11248,33 +11249,33 @@@ MODULE_PARM_DESC(associate, "auto assoc
  module_param(auto_create, int, 0444);
  MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
  
+ module_param(led, int, 0444);
+ MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
  module_param(debug, int, 0444);
  MODULE_PARM_DESC(debug, "debug output mask");
  
  module_param(channel, int, 0444);
  MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
  
- module_param(ifname, charp, 0444);
- MODULE_PARM_DESC(ifname, "network device name (default eth%d)");
+ #ifdef CONFIG_IPW_QOS
+ module_param(qos_enable, int, 0444);
+ MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
+ module_param(qos_burst_enable, int, 0444);
+ MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
+ module_param(qos_no_ack_mask, int, 0444);
+ MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
  
- #ifdef CONFIG_IPW_PROMISC
+ module_param(burst_duration_CCK, int, 0444);
+ MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
+ module_param(burst_duration_OFDM, int, 0444);
+ MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
+ #endif                                /* CONFIG_IPW_QOS */
+ #ifdef CONFIG_IPW2200_MONITOR
  module_param(mode, int, 0444);
  MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
  #else
@@@ -7383,5 -11282,12 +11283,12 @@@ module_param(mode, int, 0444)
  MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
  #endif
  
+ module_param(hwcrypto, int, 0444);
+ MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default on)");
+ module_param(cmdlog, int, 0444);
+ MODULE_PARM_DESC(cmdlog,
+                "allocate a ring buffer for logging firmware commands");
  module_exit(ipw_exit);
  module_init(ipw_init);
index 0873b758f499556df75dbbd95d2eb0179e444fde,617ec4dba17a6a3a5ab969e608bc9c0a2edc385a..1c98db0652c9458a9c61079e8e91cd8a6edb4d39
@@@ -1,6 -1,6 +1,6 @@@
  /******************************************************************************
  
-   Copyright(c) 2003 - 2004 Intel Corporation. All rights reserved.
+   Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
  
    This program is free software; you can redistribute it and/or modify it
    under the terms of version 2 of the GNU General Public License as
@@@ -34,6 -34,7 +34,6 @@@
  #include <linux/config.h>
  #include <linux/init.h>
  
 -#include <linux/version.h>
  #include <linux/pci.h>
  #include <linux/netdevice.h>
  #include <linux/ethtool.h>
@@@ -49,6 -50,7 +49,7 @@@
  #include <asm/io.h>
  
  #include <net/ieee80211.h>
+ #include <net/ieee80211_radiotap.h>
  
  #define DRV_NAME      "ipw2200"
  
@@@ -160,6 -162,16 +161,16 @@@ enum connection_manager_assoc_states 
   * TX Queue Flag Definitions
   */
  
+ /* tx wep key definition */
+ #define DCT_WEP_KEY_NOT_IMMIDIATE     0x00
+ #define DCT_WEP_KEY_64Bit             0x40
+ #define DCT_WEP_KEY_128Bit            0x80
+ #define DCT_WEP_KEY_128bitIV          0xC0
+ #define DCT_WEP_KEY_SIZE_MASK         0xC0
+ #define DCT_WEP_KEY_INDEX_MASK                0x0F
+ #define DCT_WEP_INDEX_USE_IMMEDIATE   0x20
  /* abort attempt if mgmt frame is rx'd */
  #define DCT_FLAG_ABORT_MGMT                0x01
  
  #define DCT_FLAG_CTS_REQUIRED              0x02
  
  /* use short preamble */
- #define DCT_FLAG_SHORT_PREMBL              0x04
+ #define DCT_FLAG_LONG_PREAMBLE             0x00
+ #define DCT_FLAG_SHORT_PREAMBLE            0x04
  
  /* RTS/CTS first */
  #define DCT_FLAG_RTS_REQD                  0x08
  /* ACK rx is expected to follow */
  #define DCT_FLAG_ACK_REQD                  0x80
  
+ /* TX flags extension */
  #define DCT_FLAG_EXT_MODE_CCK  0x01
  #define DCT_FLAG_EXT_MODE_OFDM 0x00
  
+ #define DCT_FLAG_EXT_SECURITY_WEP     0x00
+ #define DCT_FLAG_EXT_SECURITY_NO      DCT_FLAG_EXT_SECURITY_WEP
+ #define DCT_FLAG_EXT_SECURITY_CKIP    0x04
+ #define DCT_FLAG_EXT_SECURITY_CCM     0x08
+ #define DCT_FLAG_EXT_SECURITY_TKIP    0x0C
+ #define DCT_FLAG_EXT_SECURITY_MASK    0x0C
+ #define DCT_FLAG_EXT_QOS_ENABLED      0x10
+ #define DCT_FLAG_EXT_HC_NO_SIFS_PIFS  0x00
+ #define DCT_FLAG_EXT_HC_SIFS          0x20
+ #define DCT_FLAG_EXT_HC_PIFS          0x40
  #define TX_RX_TYPE_MASK                    0xFF
  #define TX_FRAME_TYPE                      0x00
  #define TX_HOST_COMMAND_TYPE               0x01
  #define DCR_TYPE_SNIFFER                  0x06
  #define DCR_TYPE_MU_BSS        DCR_TYPE_MU_ESS
  
+ /* QoS  definitions */
+ #define CW_MIN_OFDM          15
+ #define CW_MAX_OFDM          1023
+ #define CW_MIN_CCK           31
+ #define CW_MAX_CCK           1023
+ #define QOS_TX0_CW_MIN_OFDM      CW_MIN_OFDM
+ #define QOS_TX1_CW_MIN_OFDM      CW_MIN_OFDM
+ #define QOS_TX2_CW_MIN_OFDM      ( (CW_MIN_OFDM + 1) / 2 - 1 )
+ #define QOS_TX3_CW_MIN_OFDM      ( (CW_MIN_OFDM + 1) / 4 - 1 )
+ #define QOS_TX0_CW_MIN_CCK       CW_MIN_CCK
+ #define QOS_TX1_CW_MIN_CCK       CW_MIN_CCK
+ #define QOS_TX2_CW_MIN_CCK       ( (CW_MIN_CCK + 1) / 2 - 1 )
+ #define QOS_TX3_CW_MIN_CCK       ( (CW_MIN_CCK + 1) / 4 - 1 )
+ #define QOS_TX0_CW_MAX_OFDM      CW_MAX_OFDM
+ #define QOS_TX1_CW_MAX_OFDM      CW_MAX_OFDM
+ #define QOS_TX2_CW_MAX_OFDM      CW_MIN_OFDM
+ #define QOS_TX3_CW_MAX_OFDM      ( (CW_MIN_OFDM + 1) / 2 - 1 )
+ #define QOS_TX0_CW_MAX_CCK       CW_MAX_CCK
+ #define QOS_TX1_CW_MAX_CCK       CW_MAX_CCK
+ #define QOS_TX2_CW_MAX_CCK       CW_MIN_CCK
+ #define QOS_TX3_CW_MAX_CCK       ( (CW_MIN_CCK + 1) / 2 - 1 )
+ #define QOS_TX0_AIFS            (3 - QOS_AIFSN_MIN_VALUE)
+ #define QOS_TX1_AIFS            (7 - QOS_AIFSN_MIN_VALUE)
+ #define QOS_TX2_AIFS            (2 - QOS_AIFSN_MIN_VALUE)
+ #define QOS_TX3_AIFS            (2 - QOS_AIFSN_MIN_VALUE)
+ #define QOS_TX0_ACM             0
+ #define QOS_TX1_ACM             0
+ #define QOS_TX2_ACM             0
+ #define QOS_TX3_ACM             0
+ #define QOS_TX0_TXOP_LIMIT_CCK          0
+ #define QOS_TX1_TXOP_LIMIT_CCK          0
+ #define QOS_TX2_TXOP_LIMIT_CCK          6016
+ #define QOS_TX3_TXOP_LIMIT_CCK          3264
+ #define QOS_TX0_TXOP_LIMIT_OFDM      0
+ #define QOS_TX1_TXOP_LIMIT_OFDM      0
+ #define QOS_TX2_TXOP_LIMIT_OFDM      3008
+ #define QOS_TX3_TXOP_LIMIT_OFDM      1504
+ #define DEF_TX0_CW_MIN_OFDM      CW_MIN_OFDM
+ #define DEF_TX1_CW_MIN_OFDM      CW_MIN_OFDM
+ #define DEF_TX2_CW_MIN_OFDM      CW_MIN_OFDM
+ #define DEF_TX3_CW_MIN_OFDM      CW_MIN_OFDM
+ #define DEF_TX0_CW_MIN_CCK       CW_MIN_CCK
+ #define DEF_TX1_CW_MIN_CCK       CW_MIN_CCK
+ #define DEF_TX2_CW_MIN_CCK       CW_MIN_CCK
+ #define DEF_TX3_CW_MIN_CCK       CW_MIN_CCK
+ #define DEF_TX0_CW_MAX_OFDM      CW_MAX_OFDM
+ #define DEF_TX1_CW_MAX_OFDM      CW_MAX_OFDM
+ #define DEF_TX2_CW_MAX_OFDM      CW_MAX_OFDM
+ #define DEF_TX3_CW_MAX_OFDM      CW_MAX_OFDM
+ #define DEF_TX0_CW_MAX_CCK       CW_MAX_CCK
+ #define DEF_TX1_CW_MAX_CCK       CW_MAX_CCK
+ #define DEF_TX2_CW_MAX_CCK       CW_MAX_CCK
+ #define DEF_TX3_CW_MAX_CCK       CW_MAX_CCK
+ #define DEF_TX0_AIFS            0
+ #define DEF_TX1_AIFS            0
+ #define DEF_TX2_AIFS            0
+ #define DEF_TX3_AIFS            0
+ #define DEF_TX0_ACM             0
+ #define DEF_TX1_ACM             0
+ #define DEF_TX2_ACM             0
+ #define DEF_TX3_ACM             0
+ #define DEF_TX0_TXOP_LIMIT_CCK        0
+ #define DEF_TX1_TXOP_LIMIT_CCK        0
+ #define DEF_TX2_TXOP_LIMIT_CCK        0
+ #define DEF_TX3_TXOP_LIMIT_CCK        0
+ #define DEF_TX0_TXOP_LIMIT_OFDM       0
+ #define DEF_TX1_TXOP_LIMIT_OFDM       0
+ #define DEF_TX2_TXOP_LIMIT_OFDM       0
+ #define DEF_TX3_TXOP_LIMIT_OFDM       0
+ #define QOS_QOS_SETS                  3
+ #define QOS_PARAM_SET_ACTIVE          0
+ #define QOS_PARAM_SET_DEF_CCK         1
+ #define QOS_PARAM_SET_DEF_OFDM        2
+ #define CTRL_QOS_NO_ACK               (0x0020)
+ #define IPW_TX_QUEUE_1        1
+ #define IPW_TX_QUEUE_2        2
+ #define IPW_TX_QUEUE_3        3
+ #define IPW_TX_QUEUE_4        4
+ /* QoS sturctures */
+ struct ipw_qos_info {
+       int qos_enable;
+       struct ieee80211_qos_parameters *def_qos_parm_OFDM;
+       struct ieee80211_qos_parameters *def_qos_parm_CCK;
+       u32 burst_duration_CCK;
+       u32 burst_duration_OFDM;
+       u16 qos_no_ack_mask;
+       int burst_enable;
+ };
+ /**************************************************************/
  /**
   * Generic queue structure
   *
@@@ -401,9 -539,9 +538,9 @@@ struct clx2_tx_queue 
  #define RX_FREE_BUFFERS 32
  #define RX_LOW_WATERMARK 8
  
- #define SUP_RATE_11A_MAX_NUM_CHANNELS  (8)
- #define SUP_RATE_11B_MAX_NUM_CHANNELS  (4)
- #define SUP_RATE_11G_MAX_NUM_CHANNELS  (12)
+ #define SUP_RATE_11A_MAX_NUM_CHANNELS  8
+ #define SUP_RATE_11B_MAX_NUM_CHANNELS  4
+ #define SUP_RATE_11G_MAX_NUM_CHANNELS  12
  
  // Used for passing to driver number of successes and failures per rate
  struct rate_histogram {
@@@ -452,6 -590,9 +589,9 @@@ struct notif_channel_result 
        u8 uReserved;
  } __attribute__ ((packed));
  
+ #define SCAN_COMPLETED_STATUS_COMPLETE  1
+ #define SCAN_COMPLETED_STATUS_ABORTED   2
  struct notif_scan_complete {
        u8 scan_type;
        u8 num_channels;
@@@ -562,8 -703,8 +702,8 @@@ struct ipw_rx_packet 
  } __attribute__ ((packed));
  
  #define IPW_RX_NOTIFICATION_SIZE sizeof(struct ipw_rx_header) + 12
- #define IPW_RX_FRAME_SIZE        sizeof(struct ipw_rx_header) + \
-                                  sizeof(struct ipw_rx_frame)
+ #define IPW_RX_FRAME_SIZE        (unsigned int)(sizeof(struct ipw_rx_header) + \
+                                  sizeof(struct ipw_rx_frame))
  
  struct ipw_rx_mem_buffer {
        dma_addr_t dma_addr;
@@@ -656,6 -797,19 +796,19 @@@ struct ipw_multicast_addr 
        u8 mac4[6];
  } __attribute__ ((packed));
  
+ #define DCW_WEP_KEY_INDEX_MASK                0x03    /* bits [0:1] */
+ #define DCW_WEP_KEY_SEC_TYPE_MASK     0x30    /* bits [4:5] */
+ #define DCW_WEP_KEY_SEC_TYPE_WEP      0x00
+ #define DCW_WEP_KEY_SEC_TYPE_CCM      0x20
+ #define DCW_WEP_KEY_SEC_TYPE_TKIP     0x30
+ #define DCW_WEP_KEY_INVALID_SIZE      0x00    /* 0 = Invalid key */
+ #define DCW_WEP_KEY64Bit_SIZE         0x05    /* 64-bit encryption */
+ #define DCW_WEP_KEY128Bit_SIZE                0x0D    /* 128-bit encryption */
+ #define DCW_CCM_KEY128Bit_SIZE                0x10    /* 128-bit key */
+ //#define DCW_WEP_KEY128BitIV_SIZE      0x10    /* 128-bit key and 128-bit IV */
  struct ipw_wep_key {
        u8 cmd_id;
        u8 seq_num;
@@@ -817,14 -971,6 +970,6 @@@ struct ipw_tx_power 
        struct ipw_channel_tx_power channels_tx_power[MAX_A_CHANNELS];
  } __attribute__ ((packed));
  
- struct ipw_qos_parameters {
-       u16 cw_min[4];
-       u16 cw_max[4];
-       u8 aifs[4];
-       u8 flag[4];
-       u16 tx_op_limit[4];
- } __attribute__ ((packed));
  struct ipw_rsn_capabilities {
        u8 id;
        u8 length;
@@@ -887,6 -1033,10 +1032,10 @@@ struct ipw_cmd 
  #define STATUS_SCAN_PENDING     (1<<20)
  #define STATUS_SCANNING         (1<<21)
  #define STATUS_SCAN_ABORTING    (1<<22)
+ #define STATUS_SCAN_FORCED      (1<<23)
+ #define STATUS_LED_LINK_ON      (1<<24)
+ #define STATUS_LED_ACT_ON       (1<<25)
  
  #define STATUS_INDIRECT_BYTE    (1<<28)       /* sysfs entry configured for access */
  #define STATUS_INDIRECT_DWORD   (1<<29)       /* sysfs entry configured for access */
  #define CFG_STATIC_ESSID        (1<<1)        /* Restrict assoc. to single SSID */
  #define CFG_STATIC_BSSID        (1<<2)        /* Restrict assoc. to single BSSID */
  #define CFG_CUSTOM_MAC          (1<<3)
- #define CFG_PREAMBLE            (1<<4)
+ #define CFG_PREAMBLE_LONG       (1<<4)
  #define CFG_ADHOC_PERSIST       (1<<5)
  #define CFG_ASSOCIATE           (1<<6)
  #define CFG_FIXED_RATE          (1<<7)
  #define CFG_ADHOC_CREATE        (1<<8)
+ #define CFG_NO_LED              (1<<9)
+ #define CFG_BACKGROUND_SCAN     (1<<10)
+ #define CFG_SPEED_SCAN          (1<<11)
+ #define CFG_NET_STATS           (1<<12)
  
  #define CAP_SHARED_KEY          (1<<0)        /* Off = OPEN */
  #define CAP_PRIVACY_ON          (1<<1)        /* Off = No privacy */
@@@ -924,13 -1078,50 +1077,50 @@@ struct average 
        s32 sum;
  };
  
+ #define MAX_SPEED_SCAN 100
+ #define IPW_IBSS_MAC_HASH_SIZE 31
+ struct ipw_ibss_seq {
+       u8 mac[ETH_ALEN];
+       u16 seq_num;
+       u16 frag_num;
+       unsigned long packet_time;
+       struct list_head list;
+ };
+ struct ipw_error_elem {
+       u32 desc;
+       u32 time;
+       u32 blink1;
+       u32 blink2;
+       u32 link1;
+       u32 link2;
+       u32 data;
+ };
+ struct ipw_event {
+       u32 event;
+       u32 time;
+       u32 data;
+ } __attribute__ ((packed));
+ struct ipw_fw_error {
+       unsigned long jiffies;
+       u32 status;
+       u32 config;
+       u32 elem_len;
+       u32 log_len;
+       struct ipw_error_elem *elem;
+       struct ipw_event *log;
+       u8 payload[0];
+ } __attribute__ ((packed));
  struct ipw_priv {
        /* ieee device used by generic ieee processing code */
        struct ieee80211_device *ieee;
-       struct ieee80211_security sec;
  
-       /* spinlock */
        spinlock_t lock;
+       struct semaphore sem;
  
        /* basic pci-network driver stuff */
        struct pci_dev *pci_dev;
        int rx_bufs_min;          /**< minimum number of bufs in Rx queue */
        int rx_pend_max;          /**< maximum pending buffers for one IRQ */
        u32 hcmd_seq;             /**< sequence number for hcmd */
-       u32 missed_beacon_threshold;
+       u32 disassociate_threshold;
        u32 roaming_threshold;
  
        struct ipw_associate assoc_request;
        u8 mac_addr[ETH_ALEN];
        u8 num_stations;
        u8 stations[MAX_STATIONS][ETH_ALEN];
+       u8 short_retry_limit;
+       u8 long_retry_limit;
  
        u32 notif_missed_beacons;
  
        u32 tx_packets;
        u32 quality;
  
+       u8 speed_scan[MAX_SPEED_SCAN];
+       u8 speed_scan_pos;
+       u16 last_seq_num;
+       u16 last_frag_num;
+       unsigned long last_packet_time;
+       struct list_head ibss_mac_hash[IPW_IBSS_MAC_HASH_SIZE];
        /* eeprom */
        u8 eeprom[0x100];       /* 256 bytes of eeprom */
+       u8 country[4];
        int eeprom_delay;
  
        struct iw_statistics wstats;
  
+       struct iw_public_data wireless_data;
        struct workqueue_struct *workqueue;
  
        struct work_struct adhoc_check;
        struct work_struct associate;
        struct work_struct disassociate;
+       struct work_struct system_config;
        struct work_struct rx_replenish;
        struct work_struct request_scan;
        struct work_struct adapter_restart;
        struct work_struct abort_scan;
        struct work_struct roam;
        struct work_struct scan_check;
+       struct work_struct link_up;
+       struct work_struct link_down;
  
        struct tasklet_struct irq_tasklet;
  
+       /* LED related variables and work_struct */
+       u8 nic_type;
+       u32 led_activity_on;
+       u32 led_activity_off;
+       u32 led_association_on;
+       u32 led_association_off;
+       u32 led_ofdm_on;
+       u32 led_ofdm_off;
+       struct work_struct led_link_on;
+       struct work_struct led_link_off;
+       struct work_struct led_act_off;
+       struct work_struct merge_networks;
+       struct ipw_cmd_log *cmdlog;
+       int cmdlog_len;
+       int cmdlog_pos;
  #define IPW_2200BG  1
  #define IPW_2915ABG 2
        u8 adapter;
  
- #define IPW_DEFAULT_TX_POWER 0x14
-       u8 tx_power;
+       s8 tx_power;
  
  #ifdef CONFIG_PM
        u32 pm_state[16];
  #endif
  
+       struct ipw_fw_error *error;
        /* network state */
  
        /* Used to pass the current INTA value from ISR to Tasklet */
        u32 isr_inta;
  
+       /* QoS */
+       struct ipw_qos_info qos_data;
+       struct work_struct qos_activate;
+       /*********************************/
        /* debugging info */
        u32 indirect_dword;
        u32 direct_dword;
@@@ -1124,6 -1355,8 +1354,8 @@@ do { if (ipw_debug_level & (level)) 
  #define IPW_DL_RF_KILL       (1<<17)
  #define IPW_DL_FW_ERRORS     (1<<18)
  
+ #define IPW_DL_LED           (1<<19)
  #define IPW_DL_ORD           (1<<20)
  
  #define IPW_DL_FRAG          (1<<21)
  #define IPW_DL_TRACE         (1<<28)
  
  #define IPW_DL_STATS         (1<<29)
+ #define IPW_DL_MERGE         (1<<30)
+ #define IPW_DL_QOS           (1<<31)
  
  #define IPW_ERROR(f, a...) printk(KERN_ERR DRV_NAME ": " f, ## a)
  #define IPW_WARNING(f, a...) printk(KERN_WARNING DRV_NAME ": " f, ## a)
  #define IPW_DEBUG_TX(f, a...)     IPW_DEBUG(IPW_DL_TX, f, ## a)
  #define IPW_DEBUG_ISR(f, a...)    IPW_DEBUG(IPW_DL_ISR, f, ## a)
  #define IPW_DEBUG_MANAGEMENT(f, a...) IPW_DEBUG(IPW_DL_MANAGE, f, ## a)
+ #define IPW_DEBUG_LED(f, a...) IPW_DEBUG(IPW_DL_LED, f, ## a)
  #define IPW_DEBUG_WEP(f, a...)    IPW_DEBUG(IPW_DL_WEP, f, ## a)
  #define IPW_DEBUG_HC(f, a...) IPW_DEBUG(IPW_DL_HOST_COMMAND, f, ## a)
  #define IPW_DEBUG_FRAG(f, a...) IPW_DEBUG(IPW_DL_FRAG, f, ## a)
  #define IPW_DEBUG_STATE(f, a...) IPW_DEBUG(IPW_DL_STATE | IPW_DL_ASSOC | IPW_DL_INFO, f, ## a)
  #define IPW_DEBUG_ASSOC(f, a...) IPW_DEBUG(IPW_DL_ASSOC | IPW_DL_INFO, f, ## a)
  #define IPW_DEBUG_STATS(f, a...) IPW_DEBUG(IPW_DL_STATS, f, ## a)
+ #define IPW_DEBUG_MERGE(f, a...) IPW_DEBUG(IPW_DL_MERGE, f, ## a)
+ #define IPW_DEBUG_QOS(f, a...)   IPW_DEBUG(IPW_DL_QOS, f, ## a)
  
  #include <linux/ctype.h>
  
  #define DINO_RXFIFO_DATA   0x01
  #define DINO_CONTROL_REG   0x00200000
  
- #define CX2_INTA_RW       0x00000008
- #define CX2_INTA_MASK_R   0x0000000C
- #define CX2_INDIRECT_ADDR 0x00000010
- #define CX2_INDIRECT_DATA 0x00000014
- #define CX2_AUTOINC_ADDR  0x00000018
- #define CX2_AUTOINC_DATA  0x0000001C
- #define CX2_RESET_REG     0x00000020
- #define CX2_GP_CNTRL_RW   0x00000024
+ #define IPW_INTA_RW       0x00000008
+ #define IPW_INTA_MASK_R   0x0000000C
+ #define IPW_INDIRECT_ADDR 0x00000010
+ #define IPW_INDIRECT_DATA 0x00000014
+ #define IPW_AUTOINC_ADDR  0x00000018
+ #define IPW_AUTOINC_DATA  0x0000001C
+ #define IPW_RESET_REG     0x00000020
+ #define IPW_GP_CNTRL_RW   0x00000024
  
- #define CX2_READ_INT_REGISTER 0xFF4
+ #define IPW_READ_INT_REGISTER 0xFF4
  
- #define CX2_GP_CNTRL_BIT_INIT_DONE    0x00000004
+ #define IPW_GP_CNTRL_BIT_INIT_DONE    0x00000004
  
- #define CX2_REGISTER_DOMAIN1_END        0x00001000
- #define CX2_SRAM_READ_INT_REGISTER    0x00000ff4
+ #define IPW_REGISTER_DOMAIN1_END        0x00001000
+ #define IPW_SRAM_READ_INT_REGISTER    0x00000ff4
  
- #define CX2_SHARED_LOWER_BOUND          0x00000200
- #define CX2_INTERRUPT_AREA_LOWER_BOUND  0x00000f80
+ #define IPW_SHARED_LOWER_BOUND          0x00000200
+ #define IPW_INTERRUPT_AREA_LOWER_BOUND  0x00000f80
  
- #define CX2_NIC_SRAM_LOWER_BOUND        0x00000000
- #define CX2_NIC_SRAM_UPPER_BOUND        0x00030000
+ #define IPW_NIC_SRAM_LOWER_BOUND        0x00000000
+ #define IPW_NIC_SRAM_UPPER_BOUND        0x00030000
  
- #define CX2_BIT_INT_HOST_SRAM_READ_INT_REGISTER (1 << 29)
- #define CX2_GP_CNTRL_BIT_CLOCK_READY    0x00000001
- #define CX2_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY 0x00000002
+ #define IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER (1 << 29)
+ #define IPW_GP_CNTRL_BIT_CLOCK_READY    0x00000001
+ #define IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY 0x00000002
  
  /*
   * RESET Register Bit Indexes
   */
- #define CBD_RESET_REG_PRINCETON_RESET 0x00000001      /* Bit 0 (LSB) */
- #define CX2_RESET_REG_SW_RESET        0x00000080      /* Bit 7       */
- #define CX2_RESET_REG_MASTER_DISABLED 0x00000100      /* Bit 8       */
- #define CX2_RESET_REG_STOP_MASTER     0x00000200      /* Bit 9       */
- #define CX2_ARC_KESHET_CONFIG         0x08000000      /* Bit 27      */
- #define CX2_START_STANDBY             0x00000004      /* Bit 2       */
- #define CX2_CSR_CIS_UPPER_BOUND       0x00000200
- #define CX2_DOMAIN_0_END 0x1000
+ #define CBD_RESET_REG_PRINCETON_RESET (1<<0)
+ #define IPW_START_STANDBY             (1<<2)
+ #define IPW_ACTIVITY_LED              (1<<4)
+ #define IPW_ASSOCIATED_LED            (1<<5)
+ #define IPW_OFDM_LED                  (1<<6)
+ #define IPW_RESET_REG_SW_RESET        (1<<7)
+ #define IPW_RESET_REG_MASTER_DISABLED (1<<8)
+ #define IPW_RESET_REG_STOP_MASTER     (1<<9)
+ #define IPW_GATE_ODMA                 (1<<25)
+ #define IPW_GATE_IDMA                 (1<<26)
+ #define IPW_ARC_KESHET_CONFIG         (1<<27)
+ #define IPW_GATE_ADMA                 (1<<29)
+ #define IPW_CSR_CIS_UPPER_BOUND       0x00000200
+ #define IPW_DOMAIN_0_END 0x1000
  #define CLX_MEM_BAR_SIZE 0x1000
  
- #define CX2_BASEBAND_CONTROL_STATUS   0X00200000
- #define CX2_BASEBAND_TX_FIFO_WRITE    0X00200004
- #define CX2_BASEBAND_RX_FIFO_READ     0X00200004
- #define CX2_BASEBAND_CONTROL_STORE    0X00200010
+ #define IPW_BASEBAND_CONTROL_STATUS   0X00200000
+ #define IPW_BASEBAND_TX_FIFO_WRITE    0X00200004
+ #define IPW_BASEBAND_RX_FIFO_READ     0X00200004
+ #define IPW_BASEBAND_CONTROL_STORE    0X00200010
  
- #define CX2_INTERNAL_CMD_EVENT        0X00300004
- #define CX2_BASEBAND_POWER_DOWN 0x00000001
+ #define IPW_INTERNAL_CMD_EVENT        0X00300004
+ #define IPW_BASEBAND_POWER_DOWN 0x00000001
  
- #define CX2_MEM_HALT_AND_RESET  0x003000e0
+ #define IPW_MEM_HALT_AND_RESET  0x003000e0
  
  /* defgroup bits_halt_reset MEM_HALT_AND_RESET register bits */
- #define CX2_BIT_HALT_RESET_ON 0x80000000
- #define CX2_BIT_HALT_RESET_OFF        0x00000000
+ #define IPW_BIT_HALT_RESET_ON 0x80000000
+ #define IPW_BIT_HALT_RESET_OFF        0x00000000
  
  #define CB_LAST_VALID     0x20000000
  #define CB_INT_ENABLED    0x40000000
  #define DMA_CB_STOP_AND_ABORT            0x00000C00
  #define DMA_CB_START                     0x00000100
  
- #define CX2_SHARED_SRAM_SIZE               0x00030000
- #define CX2_SHARED_SRAM_DMA_CONTROL        0x00027000
+ #define IPW_SHARED_SRAM_SIZE               0x00030000
+ #define IPW_SHARED_SRAM_DMA_CONTROL        0x00027000
  #define CB_MAX_LENGTH                      0x1FFF
  
- #define CX2_HOST_EEPROM_DATA_SRAM_SIZE 0xA18
- #define CX2_EEPROM_IMAGE_SIZE          0x100
+ #define IPW_HOST_EEPROM_DATA_SRAM_SIZE 0xA18
+ #define IPW_EEPROM_IMAGE_SIZE          0x100
  
  /* DMA defs */
- #define CX2_DMA_I_CURRENT_CB  0x003000D0
- #define CX2_DMA_O_CURRENT_CB  0x003000D4
- #define CX2_DMA_I_DMA_CONTROL 0x003000A4
- #define CX2_DMA_I_CB_BASE     0x003000A0
- #define CX2_TX_CMD_QUEUE_BD_BASE        (0x00000200)
- #define CX2_TX_CMD_QUEUE_BD_SIZE        (0x00000204)
- #define CX2_TX_QUEUE_0_BD_BASE          (0x00000208)
- #define CX2_TX_QUEUE_0_BD_SIZE          (0x0000020C)
- #define CX2_TX_QUEUE_1_BD_BASE          (0x00000210)
- #define CX2_TX_QUEUE_1_BD_SIZE          (0x00000214)
- #define CX2_TX_QUEUE_2_BD_BASE          (0x00000218)
- #define CX2_TX_QUEUE_2_BD_SIZE          (0x0000021C)
- #define CX2_TX_QUEUE_3_BD_BASE          (0x00000220)
- #define CX2_TX_QUEUE_3_BD_SIZE          (0x00000224)
- #define CX2_RX_BD_BASE                  (0x00000240)
- #define CX2_RX_BD_SIZE                  (0x00000244)
- #define CX2_RFDS_TABLE_LOWER            (0x00000500)
- #define CX2_TX_CMD_QUEUE_READ_INDEX     (0x00000280)
- #define CX2_TX_QUEUE_0_READ_INDEX       (0x00000284)
- #define CX2_TX_QUEUE_1_READ_INDEX       (0x00000288)
- #define CX2_TX_QUEUE_2_READ_INDEX       (0x0000028C)
- #define CX2_TX_QUEUE_3_READ_INDEX       (0x00000290)
- #define CX2_RX_READ_INDEX               (0x000002A0)
- #define CX2_TX_CMD_QUEUE_WRITE_INDEX    (0x00000F80)
- #define CX2_TX_QUEUE_0_WRITE_INDEX      (0x00000F84)
- #define CX2_TX_QUEUE_1_WRITE_INDEX      (0x00000F88)
- #define CX2_TX_QUEUE_2_WRITE_INDEX      (0x00000F8C)
- #define CX2_TX_QUEUE_3_WRITE_INDEX      (0x00000F90)
- #define CX2_RX_WRITE_INDEX              (0x00000FA0)
+ #define IPW_DMA_I_CURRENT_CB  0x003000D0
+ #define IPW_DMA_O_CURRENT_CB  0x003000D4
+ #define IPW_DMA_I_DMA_CONTROL 0x003000A4
+ #define IPW_DMA_I_CB_BASE     0x003000A0
+ #define IPW_TX_CMD_QUEUE_BD_BASE        0x00000200
+ #define IPW_TX_CMD_QUEUE_BD_SIZE        0x00000204
+ #define IPW_TX_QUEUE_0_BD_BASE          0x00000208
+ #define IPW_TX_QUEUE_0_BD_SIZE          (0x0000020C)
+ #define IPW_TX_QUEUE_1_BD_BASE          0x00000210
+ #define IPW_TX_QUEUE_1_BD_SIZE          0x00000214
+ #define IPW_TX_QUEUE_2_BD_BASE          0x00000218
+ #define IPW_TX_QUEUE_2_BD_SIZE          (0x0000021C)
+ #define IPW_TX_QUEUE_3_BD_BASE          0x00000220
+ #define IPW_TX_QUEUE_3_BD_SIZE          0x00000224
+ #define IPW_RX_BD_BASE                  0x00000240
+ #define IPW_RX_BD_SIZE                  0x00000244
+ #define IPW_RFDS_TABLE_LOWER            0x00000500
+ #define IPW_TX_CMD_QUEUE_READ_INDEX     0x00000280
+ #define IPW_TX_QUEUE_0_READ_INDEX       0x00000284
+ #define IPW_TX_QUEUE_1_READ_INDEX       0x00000288
+ #define IPW_TX_QUEUE_2_READ_INDEX       (0x0000028C)
+ #define IPW_TX_QUEUE_3_READ_INDEX       0x00000290
+ #define IPW_RX_READ_INDEX               (0x000002A0)
+ #define IPW_TX_CMD_QUEUE_WRITE_INDEX    (0x00000F80)
+ #define IPW_TX_QUEUE_0_WRITE_INDEX      (0x00000F84)
+ #define IPW_TX_QUEUE_1_WRITE_INDEX      (0x00000F88)
+ #define IPW_TX_QUEUE_2_WRITE_INDEX      (0x00000F8C)
+ #define IPW_TX_QUEUE_3_WRITE_INDEX      (0x00000F90)
+ #define IPW_RX_WRITE_INDEX              (0x00000FA0)
  
  /*
   * EEPROM Related Definitions
   */
  
- #define IPW_EEPROM_DATA_SRAM_ADDRESS (CX2_SHARED_LOWER_BOUND + 0x814)
- #define IPW_EEPROM_DATA_SRAM_SIZE    (CX2_SHARED_LOWER_BOUND + 0x818)
- #define IPW_EEPROM_LOAD_DISABLE      (CX2_SHARED_LOWER_BOUND + 0x81C)
- #define IPW_EEPROM_DATA              (CX2_SHARED_LOWER_BOUND + 0x820)
- #define IPW_EEPROM_UPPER_ADDRESS     (CX2_SHARED_LOWER_BOUND + 0x9E0)
+ #define IPW_EEPROM_DATA_SRAM_ADDRESS (IPW_SHARED_LOWER_BOUND + 0x814)
+ #define IPW_EEPROM_DATA_SRAM_SIZE    (IPW_SHARED_LOWER_BOUND + 0x818)
+ #define IPW_EEPROM_LOAD_DISABLE      (IPW_SHARED_LOWER_BOUND + 0x81C)
+ #define IPW_EEPROM_DATA              (IPW_SHARED_LOWER_BOUND + 0x820)
+ #define IPW_EEPROM_UPPER_ADDRESS     (IPW_SHARED_LOWER_BOUND + 0x9E0)
  
- #define IPW_STATION_TABLE_LOWER      (CX2_SHARED_LOWER_BOUND + 0xA0C)
- #define IPW_STATION_TABLE_UPPER      (CX2_SHARED_LOWER_BOUND + 0xB0C)
- #define IPW_REQUEST_ATIM             (CX2_SHARED_LOWER_BOUND + 0xB0C)
- #define IPW_ATIM_SENT                (CX2_SHARED_LOWER_BOUND + 0xB10)
- #define IPW_WHO_IS_AWAKE             (CX2_SHARED_LOWER_BOUND + 0xB14)
- #define IPW_DURING_ATIM_WINDOW       (CX2_SHARED_LOWER_BOUND + 0xB18)
+ #define IPW_STATION_TABLE_LOWER      (IPW_SHARED_LOWER_BOUND + 0xA0C)
+ #define IPW_STATION_TABLE_UPPER      (IPW_SHARED_LOWER_BOUND + 0xB0C)
+ #define IPW_REQUEST_ATIM             (IPW_SHARED_LOWER_BOUND + 0xB0C)
+ #define IPW_ATIM_SENT                (IPW_SHARED_LOWER_BOUND + 0xB10)
+ #define IPW_WHO_IS_AWAKE             (IPW_SHARED_LOWER_BOUND + 0xB14)
+ #define IPW_DURING_ATIM_WINDOW       (IPW_SHARED_LOWER_BOUND + 0xB18)
  
  #define MSB                             1
  #define LSB                             0
  #define EEPROM_HW_VERSION       (GET_EEPROM_ADDR(0x72,LSB))   /* 2 bytes  */
  
  /* NIC type as found in the one byte EEPROM_NIC_TYPE  offset*/
- #define EEPROM_NIC_TYPE_STANDARD        0
- #define EEPROM_NIC_TYPE_DELL            1
- #define EEPROM_NIC_TYPE_FUJITSU         2
- #define EEPROM_NIC_TYPE_IBM             3
- #define EEPROM_NIC_TYPE_HP              4
+ #define EEPROM_NIC_TYPE_0 0
+ #define EEPROM_NIC_TYPE_1 1
+ #define EEPROM_NIC_TYPE_2 2
+ #define EEPROM_NIC_TYPE_3 3
+ #define EEPROM_NIC_TYPE_4 4
  
  #define FW_MEM_REG_LOWER_BOUND          0x00300000
  #define FW_MEM_REG_EEPROM_ACCESS        (FW_MEM_REG_LOWER_BOUND + 0x40)
+ #define IPW_EVENT_REG                   (FW_MEM_REG_LOWER_BOUND + 0x04)
  #define EEPROM_BIT_SK                   (1<<0)
  #define EEPROM_BIT_CS                   (1<<1)
  #define EEPROM_BIT_DI                   (1<<2)
  #define EEPROM_CMD_READ                 0x2
  
  /* Interrupts masks */
- #define CX2_INTA_NONE   0x00000000
+ #define IPW_INTA_NONE   0x00000000
  
- #define CX2_INTA_BIT_RX_TRANSFER                   0x00000002
- #define CX2_INTA_BIT_STATUS_CHANGE                 0x00000010
- #define CX2_INTA_BIT_BEACON_PERIOD_EXPIRED         0x00000020
+ #define IPW_INTA_BIT_RX_TRANSFER                   0x00000002
+ #define IPW_INTA_BIT_STATUS_CHANGE                 0x00000010
+ #define IPW_INTA_BIT_BEACON_PERIOD_EXPIRED         0x00000020
  
  //Inta Bits for CF
- #define CX2_INTA_BIT_TX_CMD_QUEUE                  0x00000800
- #define CX2_INTA_BIT_TX_QUEUE_1                    0x00001000
- #define CX2_INTA_BIT_TX_QUEUE_2                    0x00002000
- #define CX2_INTA_BIT_TX_QUEUE_3                    0x00004000
- #define CX2_INTA_BIT_TX_QUEUE_4                    0x00008000
+ #define IPW_INTA_BIT_TX_CMD_QUEUE                  0x00000800
+ #define IPW_INTA_BIT_TX_QUEUE_1                    0x00001000
+ #define IPW_INTA_BIT_TX_QUEUE_2                    0x00002000
+ #define IPW_INTA_BIT_TX_QUEUE_3                    0x00004000
+ #define IPW_INTA_BIT_TX_QUEUE_4                    0x00008000
  
- #define CX2_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE      0x00010000
+ #define IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE      0x00010000
  
- #define CX2_INTA_BIT_PREPARE_FOR_POWER_DOWN        0x00100000
- #define CX2_INTA_BIT_POWER_DOWN                    0x00200000
+ #define IPW_INTA_BIT_PREPARE_FOR_POWER_DOWN        0x00100000
+ #define IPW_INTA_BIT_POWER_DOWN                    0x00200000
  
- #define CX2_INTA_BIT_FW_INITIALIZATION_DONE        0x01000000
- #define CX2_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE  0x02000000
- #define CX2_INTA_BIT_RF_KILL_DONE                  0x04000000
- #define CX2_INTA_BIT_FATAL_ERROR             0x40000000
- #define CX2_INTA_BIT_PARITY_ERROR            0x80000000
+ #define IPW_INTA_BIT_FW_INITIALIZATION_DONE        0x01000000
+ #define IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE  0x02000000
+ #define IPW_INTA_BIT_RF_KILL_DONE                  0x04000000
+ #define IPW_INTA_BIT_FATAL_ERROR             0x40000000
+ #define IPW_INTA_BIT_PARITY_ERROR            0x80000000
  
  /* Interrupts enabled at init time. */
- #define CX2_INTA_MASK_ALL                        \
-         (CX2_INTA_BIT_TX_QUEUE_1               | \
-        CX2_INTA_BIT_TX_QUEUE_2               | \
-        CX2_INTA_BIT_TX_QUEUE_3               | \
-        CX2_INTA_BIT_TX_QUEUE_4               | \
-        CX2_INTA_BIT_TX_CMD_QUEUE             | \
-        CX2_INTA_BIT_RX_TRANSFER              | \
-        CX2_INTA_BIT_FATAL_ERROR              | \
-        CX2_INTA_BIT_PARITY_ERROR             | \
-        CX2_INTA_BIT_STATUS_CHANGE            | \
-        CX2_INTA_BIT_FW_INITIALIZATION_DONE   | \
-        CX2_INTA_BIT_BEACON_PERIOD_EXPIRED    | \
-        CX2_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE | \
-        CX2_INTA_BIT_PREPARE_FOR_POWER_DOWN   | \
-        CX2_INTA_BIT_POWER_DOWN               | \
-          CX2_INTA_BIT_RF_KILL_DONE )
- #define IPWSTATUS_ERROR_LOG     (CX2_SHARED_LOWER_BOUND + 0x410)
- #define IPW_EVENT_LOG     (CX2_SHARED_LOWER_BOUND + 0x414)
+ #define IPW_INTA_MASK_ALL                        \
+         (IPW_INTA_BIT_TX_QUEUE_1               | \
+        IPW_INTA_BIT_TX_QUEUE_2               | \
+        IPW_INTA_BIT_TX_QUEUE_3               | \
+        IPW_INTA_BIT_TX_QUEUE_4               | \
+        IPW_INTA_BIT_TX_CMD_QUEUE             | \
+        IPW_INTA_BIT_RX_TRANSFER              | \
+        IPW_INTA_BIT_FATAL_ERROR              | \
+        IPW_INTA_BIT_PARITY_ERROR             | \
+        IPW_INTA_BIT_STATUS_CHANGE            | \
+        IPW_INTA_BIT_FW_INITIALIZATION_DONE   | \
+        IPW_INTA_BIT_BEACON_PERIOD_EXPIRED    | \
+        IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE | \
+        IPW_INTA_BIT_PREPARE_FOR_POWER_DOWN   | \
+        IPW_INTA_BIT_POWER_DOWN               | \
+          IPW_INTA_BIT_RF_KILL_DONE )
  
  /* FW event log definitions */
  #define EVENT_ELEM_SIZE     (3 * sizeof(u32))
  #define ERROR_ELEM_SIZE     (7 * sizeof(u32))
  #define ERROR_START_OFFSET  (1 * sizeof(u32))
  
+ /* TX power level (dbm) */
+ #define IPW_TX_POWER_MIN      -12
+ #define IPW_TX_POWER_MAX      20
+ #define IPW_TX_POWER_DEFAULT  IPW_TX_POWER_MAX
  enum {
        IPW_FW_ERROR_OK = 0,
        IPW_FW_ERROR_FAIL,
        IPW_FW_ERROR_ALLOC_FAIL,
        IPW_FW_ERROR_DMA_UNDERRUN,
        IPW_FW_ERROR_DMA_STATUS,
-       IPW_FW_ERROR_DINOSTATUS_ERROR,
-       IPW_FW_ERROR_EEPROMSTATUS_ERROR,
+       IPW_FW_ERROR_DINO_ERROR,
+       IPW_FW_ERROR_EEPROM_ERROR,
        IPW_FW_ERROR_SYSASSERT,
        IPW_FW_ERROR_FATAL_ERROR
  };
  #define HC_IBSS_RECONF    4
  #define HC_DISASSOC_QUIET 5
  
+ #define HC_QOS_SUPPORT_ASSOC  0x01
  #define IPW_RATE_CAPABILITIES 1
  #define IPW_RATE_CONNECT      0
  
@@@ -1594,18 -1842,20 +1841,20 @@@ enum 
        IPW_ORD_TABLE_7_LAST
  };
  
- #define IPW_ORDINALS_TABLE_LOWER        (CX2_SHARED_LOWER_BOUND + 0x500)
- #define IPW_ORDINALS_TABLE_0            (CX2_SHARED_LOWER_BOUND + 0x180)
- #define IPW_ORDINALS_TABLE_1            (CX2_SHARED_LOWER_BOUND + 0x184)
- #define IPW_ORDINALS_TABLE_2            (CX2_SHARED_LOWER_BOUND + 0x188)
- #define IPW_MEM_FIXED_OVERRIDE          (CX2_SHARED_LOWER_BOUND + 0x41C)
+ #define IPW_ERROR_LOG     (IPW_SHARED_LOWER_BOUND + 0x410)
+ #define IPW_EVENT_LOG     (IPW_SHARED_LOWER_BOUND + 0x414)
+ #define IPW_ORDINALS_TABLE_LOWER        (IPW_SHARED_LOWER_BOUND + 0x500)
+ #define IPW_ORDINALS_TABLE_0            (IPW_SHARED_LOWER_BOUND + 0x180)
+ #define IPW_ORDINALS_TABLE_1            (IPW_SHARED_LOWER_BOUND + 0x184)
+ #define IPW_ORDINALS_TABLE_2            (IPW_SHARED_LOWER_BOUND + 0x188)
+ #define IPW_MEM_FIXED_OVERRIDE          (IPW_SHARED_LOWER_BOUND + 0x41C)
  
  struct ipw_fixed_rate {
        u16 tx_rates;
        u16 reserved;
  } __attribute__ ((packed));
  
- #define CX2_INDIRECT_ADDR_MASK (~0x3ul)
+ #define IPW_INDIRECT_ADDR_MASK (~0x3ul)
  
  struct host_cmd {
        u8 cmd;
        u32 param[TFD_CMD_IMMEDIATE_PAYLOAD_LENGTH];
  } __attribute__ ((packed));
  
+ struct ipw_cmd_log {
+       unsigned long jiffies;
+       int retcode;
+       struct host_cmd cmd;
+ };
  #define CFG_BT_COEXISTENCE_MIN                  0x00
  #define CFG_BT_COEXISTENCE_DEFER                0x02
  #define CFG_BT_COEXISTENCE_KILL                 0x04
  #define REG_CHANNEL_MASK            0x00003FFF
  #define IPW_IBSS_11B_DEFAULT_MASK   0x87ff
  
- static const long ipw_frequencies[] = {
-       2412, 2417, 2422, 2427,
-       2432, 2437, 2442, 2447,
-       2452, 2457, 2462, 2467,
-       2472, 2484
- };
- #define FREQ_COUNT ARRAY_SIZE(ipw_frequencies)
  #define IPW_MAX_CONFIG_RETRIES 10
  
  static inline u32 frame_hdr_len(struct ieee80211_hdr_4addr *hdr)
index aaa958798f3fe033b22da25124407d347dfaef55,866c476933c337e7506063702b97ecd07f168b7c..109a96d90007ba53ad39a15cec8be73ed56945f4
@@@ -18,6 -18,7 +18,6 @@@
   *
   */
  
 -#include <linux/version.h>
  #include <linux/module.h>
  #include <linux/types.h>
  #include <linux/delay.h>
@@@ -111,9 -112,10 +111,10 @@@ isl38xx_handle_wakeup(isl38xx_control_b
  void
  isl38xx_trigger_device(int asleep, void __iomem *device_base)
  {
-       u32 reg, counter = 0;
+       u32 reg;
  
  #if VERBOSE > SHOW_ERROR_MESSAGES
+       u32 counter = 0;
        struct timeval current_time;
        DEBUG(SHOW_FUNCTION_CALLS, "isl38xx trigger device\n");
  #endif
                      current_time.tv_sec, (long)current_time.tv_usec,
                      readl(device_base + ISL38XX_CTRL_STAT_REG));
  #endif
-               udelay(ISL38XX_WRITEIO_DELAY);
  
                reg = readl(device_base + ISL38XX_INT_IDENT_REG);
                if (reg == 0xabadface) {
                        while (reg = readl(device_base + ISL38XX_CTRL_STAT_REG),
                               (reg & ISL38XX_CTRL_STAT_SLEEPMODE) == 0) {
                                udelay(ISL38XX_WRITEIO_DELAY);
+ #if VERBOSE > SHOW_ERROR_MESSAGES
                                counter++;
+ #endif
                        }
  
  #if VERBOSE > SHOW_ERROR_MESSAGES
                              "%08li.%08li Device register read %08x\n",
                              current_time.tv_sec, (long)current_time.tv_usec,
                              readl(device_base + ISL38XX_CTRL_STAT_REG));
- #endif
-                       udelay(ISL38XX_WRITEIO_DELAY);
- #if VERBOSE > SHOW_ERROR_MESSAGES
                        do_gettimeofday(&current_time);
                        DEBUG(SHOW_TRACING,
                              "%08li.%08li Device asleep counter %i\n",
  
                /* perform another read on the Device Status Register */
                reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
-               udelay(ISL38XX_WRITEIO_DELAY);
  
  #if VERBOSE > SHOW_ERROR_MESSAGES
                do_gettimeofday(&current_time);
  
                isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_UPDATE,
                                  ISL38XX_DEV_INT_REG);
-               udelay(ISL38XX_WRITEIO_DELAY);
        }
  }
  
index 80ae081ab4b77821c612de37551c99ee9c1d072d,a92ce3af3fa94d5dda326b667017e8da7b095dc1..33d64d2ee53f7397fb3b9db833a6e6a89611f1ee
@@@ -17,6 -17,7 +17,6 @@@
   *
   */
  
 -#include <linux/version.h>
  #include <linux/module.h>
  
  #include <linux/pci.h>
@@@ -226,17 -227,17 +226,17 @@@ islpci_eth_transmit(struct sk_buff *skb
                priv->data_low_tx_full = 1;
        }
  
+       /* set the transmission time */
+       ndev->trans_start = jiffies;
+       priv->statistics.tx_packets++;
+       priv->statistics.tx_bytes += skb->len;
        /* trigger the device */
        islpci_trigger(priv);
  
        /* unlock the driver code */
        spin_unlock_irqrestore(&priv->slock, flags);
  
-       /* set the transmission time */
-       ndev->trans_start = jiffies;
-       priv->statistics.tx_packets++;
-       priv->statistics.tx_bytes += skb->len;
        return 0;
  
        drop_free: