Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
authorLinus Torvalds <torvalds@woody.linux-foundation.org>
Wed, 13 Jun 2007 03:35:10 +0000 (20:35 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Wed, 13 Jun 2007 03:35:10 +0000 (20:35 -0700)
* 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik/netdev-2.6: (89 commits)
  myri10ge: update driver version
  myri10ge: report when the link partner is running in Myrinet mode
  myri10ge: limit the number of recoveries
  NetXen: Fix link status messages
  Revert "[netdrvr e100] experiment with doing RX in a similar manner to eepro100"
  [PATCH] libertas: convert libertas_mpp into anycast_mask
  [PATCH] libertas: actually send mesh frames to mesh netdev
  [PATCH] libertas: deauthenticate from AP in channel switch
  [PATCH] libertas: pull current channel from firmware on mesh autostart
  [PATCH] libertas: reduce SSID and BSSID mixed-case abuse
  [PATCH] libertas: remove WPA_SUPPLICANT structure
  [PATCH] libertas: remove structure WLAN_802_11_SSID and libertas_escape_essid
  [PATCH] libertas: tweak association debug output
  [PATCH] libertas: fix big-endian associate command.
  [PATCH] libertas: don't byte-swap firmware version number. It's a byte array.
  [PATCH] libertas: more endianness fixes, in tx.c this time
  [PATCH] libertas: More endianness fixes.
  [PATCH] libertas: first pass at fixing up endianness issues
  [PATCH] libertas: sparse fixes
  [PATCH] libertas: fix character set in README
  ...

49 files changed:
drivers/net/e100.c
drivers/net/ehea/ehea.h
drivers/net/ehea/ehea_main.c
drivers/net/ibmveth.c
drivers/net/myri10ge/myri10ge.c
drivers/net/netxen/netxen_nic.h
drivers/net/netxen/netxen_nic_ethtool.c
drivers/net/netxen/netxen_nic_hw.c
drivers/net/netxen/netxen_nic_init.c
drivers/net/netxen/netxen_nic_isr.c
drivers/net/netxen/netxen_nic_main.c
drivers/net/netxen/netxen_nic_niu.c
drivers/net/phy/marvell.c
drivers/net/usb/Kconfig
drivers/net/via-velocity.c
drivers/net/wireless/Kconfig
drivers/net/wireless/libertas/11d.c
drivers/net/wireless/libertas/11d.h
drivers/net/wireless/libertas/Makefile
drivers/net/wireless/libertas/README
drivers/net/wireless/libertas/assoc.c
drivers/net/wireless/libertas/assoc.h
drivers/net/wireless/libertas/cmd.c
drivers/net/wireless/libertas/cmdresp.c
drivers/net/wireless/libertas/debugfs.c
drivers/net/wireless/libertas/decl.h
drivers/net/wireless/libertas/defs.h
drivers/net/wireless/libertas/dev.h
drivers/net/wireless/libertas/ethtool.c
drivers/net/wireless/libertas/fw.c
drivers/net/wireless/libertas/fw.h [deleted file]
drivers/net/wireless/libertas/host.h
drivers/net/wireless/libertas/hostcmd.h
drivers/net/wireless/libertas/if_bootcmd.c
drivers/net/wireless/libertas/if_usb.c
drivers/net/wireless/libertas/if_usb.h
drivers/net/wireless/libertas/ioctl.c
drivers/net/wireless/libertas/join.c
drivers/net/wireless/libertas/join.h
drivers/net/wireless/libertas/main.c
drivers/net/wireless/libertas/rx.c
drivers/net/wireless/libertas/sbi.h [deleted file]
drivers/net/wireless/libertas/scan.c
drivers/net/wireless/libertas/scan.h
drivers/net/wireless/libertas/thread.h
drivers/net/wireless/libertas/tx.c
drivers/net/wireless/libertas/types.h
drivers/net/wireless/libertas/wext.c
drivers/net/wireless/libertas/wext.h

index 61696637a21edcc0b646e1c8894c3b89f632dadd..763810c7f33aa1e3bb682e1afdc780ac18ca8ce1 100644 (file)
@@ -285,6 +285,12 @@ enum scb_status {
        rus_mask         = 0x3C,
 };
 
+enum ru_state  {
+       RU_SUSPENDED = 0,
+       RU_RUNNING       = 1,
+       RU_UNINITIALIZED = -1,
+};
+
 enum scb_stat_ack {
        stat_ack_not_ours    = 0x00,
        stat_ack_sw_gen      = 0x04,
@@ -526,6 +532,7 @@ struct nic {
        struct rx *rx_to_use;
        struct rx *rx_to_clean;
        struct rfd blank_rfd;
+       enum ru_state ru_running;
 
        spinlock_t cb_lock                      ____cacheline_aligned;
        spinlock_t cmd_lock;
@@ -947,7 +954,7 @@ static void e100_get_defaults(struct nic *nic)
                ((nic->mac >= mac_82558_D101_A4) ? cb_cid : cb_i));
 
        /* Template for a freshly allocated RFD */
-       nic->blank_rfd.command = cpu_to_le16(cb_el & cb_s);
+       nic->blank_rfd.command = cpu_to_le16(cb_el);
        nic->blank_rfd.rbd = 0xFFFFFFFF;
        nic->blank_rfd.size = cpu_to_le16(VLAN_ETH_FRAME_LEN);
 
@@ -1742,11 +1749,19 @@ static int e100_alloc_cbs(struct nic *nic)
        return 0;
 }
 
-static inline void e100_start_receiver(struct nic *nic)
+static inline void e100_start_receiver(struct nic *nic, struct rx *rx)
 {
-       /* Start if RFA is non-NULL */
-       if(nic->rx_to_clean->skb)
-               e100_exec_cmd(nic, ruc_start, nic->rx_to_clean->dma_addr);
+       if(!nic->rxs) return;
+       if(RU_SUSPENDED != nic->ru_running) return;
+
+       /* handle init time starts */
+       if(!rx) rx = nic->rxs;
+
+       /* (Re)start RU if suspended or idle and RFA is non-NULL */
+       if(rx->skb) {
+               e100_exec_cmd(nic, ruc_start, rx->dma_addr);
+               nic->ru_running = RU_RUNNING;
+       }
 }
 
 #define RFD_BUF_LEN (sizeof(struct rfd) + VLAN_ETH_FRAME_LEN)
@@ -1775,7 +1790,7 @@ static int e100_rx_alloc_skb(struct nic *nic, struct rx *rx)
                put_unaligned(cpu_to_le32(rx->dma_addr),
                        (u32 *)&prev_rfd->link);
                wmb();
-               prev_rfd->command &= ~cpu_to_le16(cb_el & cb_s);
+               prev_rfd->command &= ~cpu_to_le16(cb_el);
                pci_dma_sync_single_for_device(nic->pdev, rx->prev->dma_addr,
                        sizeof(struct rfd), PCI_DMA_TODEVICE);
        }
@@ -1813,6 +1828,10 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,
        pci_unmap_single(nic->pdev, rx->dma_addr,
                RFD_BUF_LEN, PCI_DMA_FROMDEVICE);
 
+       /* this allows for a fast restart without re-enabling interrupts */
+       if(le16_to_cpu(rfd->command) & cb_el)
+               nic->ru_running = RU_SUSPENDED;
+
        /* Pull off the RFD and put the actual data (minus eth hdr) */
        skb_reserve(skb, sizeof(struct rfd));
        skb_put(skb, actual_size);
@@ -1843,18 +1862,45 @@ static void e100_rx_clean(struct nic *nic, unsigned int *work_done,
        unsigned int work_to_do)
 {
        struct rx *rx;
+       int restart_required = 0;
+       struct rx *rx_to_start = NULL;
+
+       /* are we already rnr? then pay attention!!! this ensures that
+        * the state machine progression never allows a start with a
+        * partially cleaned list, avoiding a race between hardware
+        * and rx_to_clean when in NAPI mode */
+       if(RU_SUSPENDED == nic->ru_running)
+               restart_required = 1;
 
        /* Indicate newly arrived packets */
        for(rx = nic->rx_to_clean; rx->skb; rx = nic->rx_to_clean = rx->next) {
-               if(e100_rx_indicate(nic, rx, work_done, work_to_do))
+               int err = e100_rx_indicate(nic, rx, work_done, work_to_do);
+               if(-EAGAIN == err) {
+                       /* hit quota so have more work to do, restart once
+                        * cleanup is complete */
+                       restart_required = 0;
+                       break;
+               } else if(-ENODATA == err)
                        break; /* No more to clean */
        }
 
+       /* save our starting point as the place we'll restart the receiver */
+       if(restart_required)
+               rx_to_start = nic->rx_to_clean;
+
        /* Alloc new skbs to refill list */
        for(rx = nic->rx_to_use; !rx->skb; rx = nic->rx_to_use = rx->next) {
                if(unlikely(e100_rx_alloc_skb(nic, rx)))
                        break; /* Better luck next time (see watchdog) */
        }
+
+       if(restart_required) {
+               // ack the rnr?
+               writeb(stat_ack_rnr, &nic->csr->scb.stat_ack);
+               e100_start_receiver(nic, rx_to_start);
+               if(work_done)
+                       (*work_done)++;
+       }
 }
 
 static void e100_rx_clean_list(struct nic *nic)
@@ -1862,6 +1908,8 @@ static void e100_rx_clean_list(struct nic *nic)
        struct rx *rx;
        unsigned int i, count = nic->params.rfds.count;
 
+       nic->ru_running = RU_UNINITIALIZED;
+
        if(nic->rxs) {
                for(rx = nic->rxs, i = 0; i < count; rx++, i++) {
                        if(rx->skb) {
@@ -1883,6 +1931,7 @@ static int e100_rx_alloc_list(struct nic *nic)
        unsigned int i, count = nic->params.rfds.count;
 
        nic->rx_to_use = nic->rx_to_clean = NULL;
+       nic->ru_running = RU_UNINITIALIZED;
 
        if(!(nic->rxs = kcalloc(count, sizeof(struct rx), GFP_ATOMIC)))
                return -ENOMEM;
@@ -1897,6 +1946,7 @@ static int e100_rx_alloc_list(struct nic *nic)
        }
 
        nic->rx_to_use = nic->rx_to_clean = nic->rxs;
+       nic->ru_running = RU_SUSPENDED;
 
        return 0;
 }
@@ -1916,6 +1966,10 @@ static irqreturn_t e100_intr(int irq, void *dev_id)
        /* Ack interrupt(s) */
        iowrite8(stat_ack, &nic->csr->scb.stat_ack);
 
+       /* We hit Receive No Resource (RNR); restart RU after cleaning */
+       if(stat_ack & stat_ack_rnr)
+               nic->ru_running = RU_SUSPENDED;
+
        if(likely(netif_rx_schedule_prep(netdev))) {
                e100_disable_irq(nic);
                __netif_rx_schedule(netdev);
@@ -2007,7 +2061,7 @@ static int e100_up(struct nic *nic)
        if((err = e100_hw_init(nic)))
                goto err_clean_cbs;
        e100_set_multicast_list(nic->netdev);
-       e100_start_receiver(nic);
+       e100_start_receiver(nic, NULL);
        mod_timer(&nic->watchdog, jiffies);
        if((err = request_irq(nic->pdev->irq, e100_intr, IRQF_SHARED,
                nic->netdev->name, nic->netdev)))
@@ -2088,7 +2142,7 @@ static int e100_loopback_test(struct nic *nic, enum loopback loopback_mode)
                mdio_write(nic->netdev, nic->mii.phy_id, MII_BMCR,
                        BMCR_LOOPBACK);
 
-       e100_start_receiver(nic);
+       e100_start_receiver(nic, NULL);
 
        if(!(skb = netdev_alloc_skb(nic->netdev, ETH_DATA_LEN))) {
                err = -ENOMEM;
index e85a933a47625e68bee0704b17d2a5675ac7d492..c0f81b5a30fb4737b0b89839d9d3cb93ae62b591 100644 (file)
@@ -39,7 +39,7 @@
 #include <asm/io.h>
 
 #define DRV_NAME       "ehea"
-#define DRV_VERSION    "EHEA_0061"
+#define DRV_VERSION    "EHEA_0064"
 
 #define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \
        | NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
index 152bb2016a2c94998e68c0094ab64d9425582dc7..9e13433a268a7a40c360a17ed7904281a89e245b 100644 (file)
@@ -451,7 +451,8 @@ static struct ehea_cqe *ehea_proc_rwqes(struct net_device *dev,
                                processed_rq3++;
                        }
 
-                       if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
+                       if ((cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
+                           && port->vgrp)
                                vlan_hwaccel_receive_skb(skb, port->vgrp,
                                                         cqe->vlan_tag);
                        else
@@ -1910,10 +1911,7 @@ static void ehea_vlan_rx_register(struct net_device *dev,
                goto out;
        }
 
-       if (grp)
-               memset(cb1->vlan_filter, 0, sizeof(cb1->vlan_filter));
-       else
-               memset(cb1->vlan_filter, 0xFF, sizeof(cb1->vlan_filter));
+       memset(cb1->vlan_filter, 0, sizeof(cb1->vlan_filter));
 
        hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
                                       H_PORT_CB1, H_PORT_CB1_ALL, cb1);
@@ -1947,7 +1945,7 @@ static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
        }
 
        index = (vid / 64);
-       cb1->vlan_filter[index] |= ((u64)(1 << (vid & 0x3F)));
+       cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
 
        hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
                                       H_PORT_CB1, H_PORT_CB1_ALL, cb1);
@@ -1982,7 +1980,7 @@ static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
        }
 
        index = (vid / 64);
-       cb1->vlan_filter[index] &= ~((u64)(1 << (vid & 0x3F)));
+       cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
 
        hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
                                       H_PORT_CB1, H_PORT_CB1_ALL, cb1);
index 3bec0f733f01e6a882bc60be9ee51cce807e965d..6ec3d500f3341ac491519c60d27d2f2c1b936c45 100644 (file)
@@ -915,17 +915,36 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
 {
        struct ibmveth_adapter *adapter = dev->priv;
        int new_mtu_oh = new_mtu + IBMVETH_BUFF_OH;
-       int i;
+       int reinit = 0;
+       int i, rc;
 
        if (new_mtu < IBMVETH_MAX_MTU)
                return -EINVAL;
 
+       for (i = 0; i < IbmVethNumBufferPools; i++)
+               if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size)
+                       break;
+
+       if (i == IbmVethNumBufferPools)
+               return -EINVAL;
+
        /* Look for an active buffer pool that can hold the new MTU */
        for(i = 0; i<IbmVethNumBufferPools; i++) {
-               if (!adapter->rx_buff_pool[i].active)
-                       continue;
+               if (!adapter->rx_buff_pool[i].active) {
+                       adapter->rx_buff_pool[i].active = 1;
+                       reinit = 1;
+               }
+
                if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) {
-                       dev->mtu = new_mtu;
+                       if (reinit && netif_running(adapter->netdev)) {
+                               adapter->pool_config = 1;
+                               ibmveth_close(adapter->netdev);
+                               adapter->pool_config = 0;
+                               dev->mtu = new_mtu;
+                               if ((rc = ibmveth_open(adapter->netdev)))
+                                       return rc;
+                       } else
+                               dev->mtu = new_mtu;
                        return 0;
                }
        }
@@ -1243,16 +1262,19 @@ const char * buf, size_t count)
 
        if (attr == &veth_active_attr) {
                if (value && !pool->active) {
-                       if(ibmveth_alloc_buffer_pool(pool)) {
-                                ibmveth_error_printk("unable to alloc pool\n");
-                                return -ENOMEM;
-                        }
-                       pool->active = 1;
-                       adapter->pool_config = 1;
-                       ibmveth_close(netdev);
-                       adapter->pool_config = 0;
-                       if ((rc = ibmveth_open(netdev)))
-                               return rc;
+                       if (netif_running(netdev)) {
+                               if(ibmveth_alloc_buffer_pool(pool)) {
+                                       ibmveth_error_printk("unable to alloc pool\n");
+                                       return -ENOMEM;
+                               }
+                               pool->active = 1;
+                               adapter->pool_config = 1;
+                               ibmveth_close(netdev);
+                               adapter->pool_config = 0;
+                               if ((rc = ibmveth_open(netdev)))
+                                       return rc;
+                       } else
+                               pool->active = 1;
                } else if (!value && pool->active) {
                        int mtu = netdev->mtu + IBMVETH_BUFF_OH;
                        int i;
@@ -1281,23 +1303,29 @@ const char * buf, size_t count)
                if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT)
                        return -EINVAL;
                else {
-                       adapter->pool_config = 1;
-                       ibmveth_close(netdev);
-                       adapter->pool_config = 0;
-                       pool->size = value;
-                       if ((rc = ibmveth_open(netdev)))
-                               return rc;
+                       if (netif_running(netdev)) {
+                               adapter->pool_config = 1;
+                               ibmveth_close(netdev);
+                               adapter->pool_config = 0;
+                               pool->size = value;
+                               if ((rc = ibmveth_open(netdev)))
+                                       return rc;
+                       } else
+                               pool->size = value;
                }
        } else if (attr == &veth_size_attr) {
                if (value <= IBMVETH_BUFF_OH || value > IBMVETH_MAX_BUF_SIZE)
                        return -EINVAL;
                else {
-                       adapter->pool_config = 1;
-                       ibmveth_close(netdev);
-                       adapter->pool_config = 0;
-                       pool->buff_size = value;
-                       if ((rc = ibmveth_open(netdev)))
-                               return rc;
+                       if (netif_running(netdev)) {
+                               adapter->pool_config = 1;
+                               ibmveth_close(netdev);
+                               adapter->pool_config = 0;
+                               pool->buff_size = value;
+                               if ((rc = ibmveth_open(netdev)))
+                                       return rc;
+                       } else
+                               pool->buff_size = value;
                }
        }
 
index b53b7ad999bcb58290b5f790b3afcb15b7eddbb0..0f9904fe3a5a2b4273ffe5901846f627233fa818 100644 (file)
@@ -71,7 +71,7 @@
 #include "myri10ge_mcp.h"
 #include "myri10ge_mcp_gen_header.h"
 
-#define MYRI10GE_VERSION_STR "1.3.0-1.233"
+#define MYRI10GE_VERSION_STR "1.3.1-1.248"
 
 MODULE_DESCRIPTION("Myricom 10G driver (10GbE)");
 MODULE_AUTHOR("Maintainer: help@myri.com");
@@ -279,6 +279,8 @@ static int myri10ge_fill_thresh = 256;
 module_param(myri10ge_fill_thresh, int, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(myri10ge_fill_thresh, "Number of empty rx slots allowed\n");
 
+static int myri10ge_reset_recover = 1;
+
 static int myri10ge_wcfifo = 0;
 module_param(myri10ge_wcfifo, int, S_IRUGO);
 MODULE_PARM_DESC(myri10ge_wcfifo, "Enable WC Fifo when WC is enabled\n");
@@ -1154,9 +1156,11 @@ static inline void myri10ge_check_statblock(struct myri10ge_priv *mgp)
        struct mcp_irq_data *stats = mgp->fw_stats;
 
        if (unlikely(stats->stats_updated)) {
-               if (mgp->link_state != stats->link_up) {
-                       mgp->link_state = stats->link_up;
-                       if (mgp->link_state) {
+               unsigned link_up = ntohl(stats->link_up);
+               if (mgp->link_state != link_up) {
+                       mgp->link_state = link_up;
+
+                       if (mgp->link_state == MXGEFW_LINK_UP) {
                                if (netif_msg_link(mgp))
                                        printk(KERN_INFO
                                               "myri10ge: %s: link up\n",
@@ -1166,8 +1170,11 @@ static inline void myri10ge_check_statblock(struct myri10ge_priv *mgp)
                        } else {
                                if (netif_msg_link(mgp))
                                        printk(KERN_INFO
-                                              "myri10ge: %s: link down\n",
-                                              mgp->dev->name);
+                                              "myri10ge: %s: link %s\n",
+                                              mgp->dev->name,
+                                              (link_up == MXGEFW_LINK_MYRINET ?
+                                               "mismatch (Myrinet detected)" :
+                                               "down"));
                                netif_carrier_off(mgp->dev);
                                mgp->link_changes++;
                        }
@@ -2730,8 +2737,14 @@ static void myri10ge_watchdog(struct work_struct *work)
                 * For now, just report it */
                reboot = myri10ge_read_reboot(mgp);
                printk(KERN_ERR
-                      "myri10ge: %s: NIC rebooted (0x%x), resetting\n",
-                      mgp->dev->name, reboot);
+                      "myri10ge: %s: NIC rebooted (0x%x),%s resetting\n",
+                      mgp->dev->name, reboot,
+                      myri10ge_reset_recover ? " " : " not");
+               if (myri10ge_reset_recover == 0)
+                       return;
+
+               myri10ge_reset_recover--;
+
                /*
                 * A rebooted nic will come back with config space as
                 * it was after power was applied to PCIe bus.
index ad6688eab265f741c5e3b8b385b40c35fdc7fd17..91f25e0a638ea64c21fd42910e4c0a2880abf649 100644 (file)
 #define _NETXEN_NIC_LINUX_SUBVERSION 2
 #define NETXEN_NIC_LINUX_VERSIONID  "3.4.2"
 
-#define NUM_FLASH_SECTORS (64)
-#define FLASH_SECTOR_SIZE (64 * 1024)
-#define FLASH_TOTAL_SIZE  (NUM_FLASH_SECTORS * FLASH_SECTOR_SIZE)
+#define NETXEN_NUM_FLASH_SECTORS (64)
+#define NETXEN_FLASH_SECTOR_SIZE (64 * 1024)
+#define NETXEN_FLASH_TOTAL_SIZE  (NETXEN_NUM_FLASH_SECTORS \
+                                       * NETXEN_FLASH_SECTOR_SIZE)
 
 #define PHAN_VENDOR_ID 0x4040
 
@@ -677,28 +678,28 @@ struct netxen_new_user_info {
 
 /* Flash memory map */
 typedef enum {
-       CRBINIT_START = 0,      /* Crbinit section */
-       BRDCFG_START = 0x4000,  /* board config */
-       INITCODE_START = 0x6000,        /* pegtune code */
-       BOOTLD_START = 0x10000, /* bootld */
-       IMAGE_START = 0x43000,  /* compressed image */
-       SECONDARY_START = 0x200000,     /* backup images */
-       PXE_START = 0x3E0000,   /* user defined region */
-       USER_START = 0x3E8000,  /* User defined region for new boards */
-       FIXED_START = 0x3F0000  /* backup of crbinit */
+       NETXEN_CRBINIT_START = 0,       /* Crbinit section */
+       NETXEN_BRDCFG_START = 0x4000,   /* board config */
+       NETXEN_INITCODE_START = 0x6000, /* pegtune code */
+       NETXEN_BOOTLD_START = 0x10000,  /* bootld */
+       NETXEN_IMAGE_START = 0x43000,   /* compressed image */
+       NETXEN_SECONDARY_START = 0x200000,      /* backup images */
+       NETXEN_PXE_START = 0x3E0000,    /* user defined region */
+       NETXEN_USER_START = 0x3E8000,   /* User defined region for new boards */
+       NETXEN_FIXED_START = 0x3F0000   /* backup of crbinit */
 } netxen_flash_map_t;
 
-#define USER_START_OLD PXE_START       /* for backward compatibility */
-
-#define FLASH_START            (CRBINIT_START)
-#define INIT_SECTOR            (0)
-#define PRIMARY_START          (BOOTLD_START)
-#define FLASH_CRBINIT_SIZE     (0x4000)
-#define FLASH_BRDCFG_SIZE      (sizeof(struct netxen_board_info))
-#define FLASH_USER_SIZE                (sizeof(struct netxen_user_info)/sizeof(u32))
-#define FLASH_SECONDARY_SIZE   (USER_START-SECONDARY_START)
-#define NUM_PRIMARY_SECTORS    (0x20)
-#define NUM_CONFIG_SECTORS     (1)
+#define NETXEN_USER_START_OLD NETXEN_PXE_START /* for backward compatibility */
+
+#define NETXEN_FLASH_START             (NETXEN_CRBINIT_START)
+#define NETXEN_INIT_SECTOR             (0)
+#define NETXEN_PRIMARY_START           (NETXEN_BOOTLD_START)
+#define NETXEN_FLASH_CRBINIT_SIZE      (0x4000)
+#define NETXEN_FLASH_BRDCFG_SIZE       (sizeof(struct netxen_board_info))
+#define NETXEN_FLASH_USER_SIZE         (sizeof(struct netxen_user_info)/sizeof(u32))
+#define NETXEN_FLASH_SECONDARY_SIZE    (NETXEN_USER_START-NETXEN_SECONDARY_START)
+#define NETXEN_NUM_PRIMARY_SECTORS     (0x20)
+#define NETXEN_NUM_CONFIG_SECTORS      (1)
 #define PFX "NetXen: "
 extern char netxen_nic_driver_name[];
 
@@ -1048,6 +1049,7 @@ int netxen_rom_se(struct netxen_adapter *adapter, int addr);
 int netxen_do_rom_se(struct netxen_adapter *adapter, int addr);
 
 /* Functions from netxen_nic_isr.c */
+int netxen_nic_link_ok(struct netxen_adapter *adapter);
 void netxen_nic_isr_other(struct netxen_adapter *adapter);
 void netxen_indicate_link_status(struct netxen_adapter *adapter, u32 link);
 void netxen_handle_port_int(struct netxen_adapter *adapter, u32 enable);
index 16fabb377488977646ff83906424196c44003bd7..0175f6c353f625d732a1ac08e4e5392346578cfc 100644 (file)
@@ -94,7 +94,7 @@ static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
 
 static int netxen_nic_get_eeprom_len(struct net_device *dev)
 {
-       return FLASH_TOTAL_SIZE;
+       return NETXEN_FLASH_TOTAL_SIZE;
 }
 
 static void
@@ -470,7 +470,7 @@ netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
                return 0;
        }
 
-       if (offset == BOOTLD_START) {
+       if (offset == NETXEN_BOOTLD_START) {
                ret = netxen_flash_erase_primary(adapter);
                if (ret != FLASH_SUCCESS) {
                        printk(KERN_ERR "%s: Flash erase failed.\n", 
@@ -478,10 +478,10 @@ netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
                        return ret;
                }
 
-               ret = netxen_rom_se(adapter, USER_START);
+               ret = netxen_rom_se(adapter, NETXEN_USER_START);
                if (ret != FLASH_SUCCESS)
                        return ret;
-               ret = netxen_rom_se(adapter, FIXED_START);
+               ret = netxen_rom_se(adapter, NETXEN_FIXED_START);
                if (ret != FLASH_SUCCESS)
                        return ret;
 
index baff17a24d633ba8a5eec76c9ad7dab9b8a73aaa..c012764d114578a2414132370a7752ae9d7e8656 100644 (file)
@@ -257,7 +257,7 @@ u64 ctx_addr_sig_regs[][3] = {
 #define ADDR_IN_RANGE(addr, low, high) \
        (((addr) <= (high)) && ((addr) >= (low)))
 
-#define NETXEN_FLASH_BASE      (BOOTLD_START)
+#define NETXEN_FLASH_BASE      (NETXEN_BOOTLD_START)
 #define NETXEN_PHANTOM_MEM_BASE        (NETXEN_FLASH_BASE)
 #define NETXEN_MAX_MTU         8000 + NETXEN_ENET_HEADER_SIZE + NETXEN_ETH_FCS_SIZE
 #define NETXEN_MIN_MTU         64
@@ -611,7 +611,7 @@ int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 mac[])
        u32 *pmac = (u32 *) & mac[0];
 
        if (netxen_get_flash_block(adapter,
-                                  USER_START +
+                                  NETXEN_USER_START +
                                   offsetof(struct netxen_new_user_info,
                                            mac_addr),
                                   FLASH_NUM_PORTS * sizeof(u64), pmac) == -1) {
@@ -619,7 +619,7 @@ int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 mac[])
        }
        if (*mac == ~0ULL) {
                if (netxen_get_flash_block(adapter,
-                                          USER_START_OLD +
+                                          NETXEN_USER_START_OLD +
                                           offsetof(struct netxen_user_old_info,
                                                    mac_addr),
                                           FLASH_NUM_PORTS * sizeof(u64),
@@ -942,7 +942,7 @@ netxen_nic_pci_set_window(struct netxen_adapter *adapter,
 int
 netxen_nic_erase_pxe(struct netxen_adapter *adapter)
 {
-       if (netxen_rom_fast_write(adapter, PXE_START, 0) == -1) {
+       if (netxen_rom_fast_write(adapter, NETXEN_PXE_START, 0) == -1) {
                printk(KERN_ERR "%s: erase pxe failed\n", 
                        netxen_nic_driver_name);
                return -1;
@@ -953,7 +953,7 @@ netxen_nic_erase_pxe(struct netxen_adapter *adapter)
 int netxen_nic_get_board_info(struct netxen_adapter *adapter)
 {
        int rv = 0;
-       int addr = BRDCFG_START;
+       int addr = NETXEN_BRDCFG_START;
        struct netxen_board_info *boardinfo;
        int index;
        u32 *ptr32;
@@ -1115,7 +1115,7 @@ void netxen_nic_flash_print(struct netxen_adapter *adapter)
        u32 fw_build = 0;
        char brd_name[NETXEN_MAX_SHORT_NAME];
        struct netxen_new_user_info user_info;
-       int i, addr = USER_START;
+       int i, addr = NETXEN_USER_START;
        __le32 *ptr32;
 
        struct netxen_board_info *board_info = &(adapter->ahw.boardcfg);
index a36892457761321adaf634daa031d6d7dfd6afa5..bb23f4c360db39368db8681d8bb74289a5d760a7 100644 (file)
@@ -585,7 +585,7 @@ int netxen_backup_crbinit(struct netxen_adapter *adapter)
 {
        int ret = FLASH_SUCCESS;
        int val;
-       char *buffer = kmalloc(FLASH_SECTOR_SIZE, GFP_KERNEL);
+       char *buffer = kmalloc(NETXEN_FLASH_SECTOR_SIZE, GFP_KERNEL);
 
        if (!buffer)
                return -ENOMEM; 
@@ -601,13 +601,13 @@ int netxen_backup_crbinit(struct netxen_adapter *adapter)
                goto out_kfree;
 
        /* copy  sector 0 to sector 63 */
-       ret = netxen_rom_fast_read_words(adapter, CRBINIT_START, 
-                                               buffer, FLASH_SECTOR_SIZE);
+       ret = netxen_rom_fast_read_words(adapter, NETXEN_CRBINIT_START, 
+                                       buffer, NETXEN_FLASH_SECTOR_SIZE);
        if (ret != FLASH_SUCCESS)
                goto out_kfree;
 
-       ret = netxen_rom_fast_write_words(adapter, FIXED_START, 
-                                               buffer, FLASH_SECTOR_SIZE);
+       ret = netxen_rom_fast_write_words(adapter, NETXEN_FIXED_START, 
+                                       buffer, NETXEN_FLASH_SECTOR_SIZE);
        if (ret != FLASH_SUCCESS)
                goto out_kfree;
 
@@ -654,7 +654,8 @@ void check_erased_flash(struct netxen_adapter *adapter, int addr)
        int count = 0, erased_errors = 0;
        int range;
 
-       range = (addr == USER_START) ? FIXED_START : addr + FLASH_SECTOR_SIZE;
+       range = (addr == NETXEN_USER_START) ? 
+               NETXEN_FIXED_START : addr + NETXEN_FLASH_SECTOR_SIZE;
        
        for (i = addr; i < range; i += 4) {
                netxen_rom_fast_read(adapter, i, &val);
@@ -689,7 +690,7 @@ netxen_flash_erase_sections(struct netxen_adapter *adapter, int start, int end)
        int i;
 
        for (i = start; i < end; i++) {
-               ret = netxen_rom_se(adapter, i * FLASH_SECTOR_SIZE);
+               ret = netxen_rom_se(adapter, i * NETXEN_FLASH_SECTOR_SIZE);
                if (ret)
                        break;
                ret = netxen_rom_wip_poll(adapter);
@@ -706,8 +707,8 @@ netxen_flash_erase_secondary(struct netxen_adapter *adapter)
        int ret = FLASH_SUCCESS;
        int start, end;
 
-       start = SECONDARY_START / FLASH_SECTOR_SIZE;
-       end   = USER_START / FLASH_SECTOR_SIZE;
+       start = NETXEN_SECONDARY_START / NETXEN_FLASH_SECTOR_SIZE;
+       end   = NETXEN_USER_START / NETXEN_FLASH_SECTOR_SIZE;
        ret = netxen_flash_erase_sections(adapter, start, end);
 
        return ret;
@@ -719,8 +720,8 @@ netxen_flash_erase_primary(struct netxen_adapter *adapter)
        int ret = FLASH_SUCCESS;
        int start, end;
 
-       start = PRIMARY_START / FLASH_SECTOR_SIZE;
-       end   = SECONDARY_START / FLASH_SECTOR_SIZE;
+       start = NETXEN_PRIMARY_START / NETXEN_FLASH_SECTOR_SIZE;
+       end   = NETXEN_SECONDARY_START / NETXEN_FLASH_SECTOR_SIZE;
        ret = netxen_flash_erase_sections(adapter, start, end);
 
        return ret;
@@ -1036,18 +1037,23 @@ void netxen_watchdog_task(struct work_struct *work)
        if ((adapter->portnum  == 0) && netxen_nic_check_temp(adapter))
                return;
 
+       if (adapter->handle_phy_intr)
+               adapter->handle_phy_intr(adapter);
+
        netdev = adapter->netdev;
-       if ((netif_running(netdev)) && !netif_carrier_ok(netdev)) {
-               printk(KERN_INFO "%s port %d, %s carrier is now ok\n",
-                      netxen_nic_driver_name, adapter->portnum, netdev->name);
+       if ((netif_running(netdev)) && !netif_carrier_ok(netdev) &&
+                       netxen_nic_link_ok(adapter) ) {
+               printk(KERN_INFO "%s %s (port %d), Link is up\n",
+                              netxen_nic_driver_name, netdev->name, adapter->portnum);
                netif_carrier_on(netdev);
-       }
-
-       if (netif_queue_stopped(netdev))
                netif_wake_queue(netdev);
+       } else if(!(netif_running(netdev)) && netif_carrier_ok(netdev)) {
+               printk(KERN_ERR "%s %s Link is Down\n",
+                               netxen_nic_driver_name, netdev->name);
+               netif_carrier_off(netdev);
+               netif_stop_queue(netdev);
+       }
 
-       if (adapter->handle_phy_intr)
-               adapter->handle_phy_intr(adapter);
        mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
 }
 
index b213b062eb567fe777651c1c196ff5d716712a38..b2de6b6c2a7f1f2dc32a0414b823a272c10a1473 100644 (file)
@@ -169,6 +169,24 @@ void netxen_nic_gbe_handle_phy_intr(struct netxen_adapter *adapter)
        netxen_nic_isr_other(adapter);
 }
 
+int netxen_nic_link_ok(struct netxen_adapter *adapter)
+{
+       switch (adapter->ahw.board_type) {
+       case NETXEN_NIC_GBE:
+               return ((adapter->ahw.qg_linksup) & 1);
+
+       case NETXEN_NIC_XGBE:
+               return ((adapter->ahw.xg_linkup) & 1);
+
+       default:
+               printk(KERN_ERR"%s: Function: %s, Unknown board type\n",
+                       netxen_nic_driver_name, __FUNCTION__);
+               break;
+       }
+
+       return 0;
+}
+
 void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter)
 {
        struct net_device *netdev = adapter->netdev;
@@ -183,6 +201,10 @@ void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter)
                printk(KERN_INFO "%s: %s NIC Link is down\n",
                       netxen_nic_driver_name, netdev->name);
                adapter->ahw.xg_linkup = 0;
+               if (netif_running(netdev)) {
+                       netif_carrier_off(netdev);
+                       netif_stop_queue(netdev);
+               }
                /* read twice to clear sticky bits */
                /* WINDOW = 0 */
                netxen_nic_read_w0(adapter, NETXEN_NIU_XG_STATUS, &val1);
@@ -196,5 +218,7 @@ void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter)
                printk(KERN_INFO "%s: %s NIC Link is up\n",
                       netxen_nic_driver_name, netdev->name);
                adapter->ahw.xg_linkup = 1;
+               netif_carrier_on(netdev);
+               netif_wake_queue(netdev);
        }
 }
index c61181f23bd58dce16d347240b39da5f04f3fb40..6167b58d2731fea3d5941a424108e2033f98b51c 100644 (file)
@@ -542,6 +542,13 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                                NETXEN_ROMUSB_GLB_PEGTUNE_DONE));
                /* Handshake with the card before we register the devices. */
                netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
+
+              /* leave the hw in the same state as reboot */
+              writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
+              netxen_pinit_from_rom(adapter, 0);
+              udelay(500);
+              netxen_load_firmware(adapter);
+              netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
        }
 
        /*
index cef90a78351e91d51d5bb5f2c8c758cd979592bf..75102d30730f0cdecf3942485211cfbcfe5eb59f 100644 (file)
@@ -454,16 +454,12 @@ int netxen_niu_gbe_init_port(struct netxen_adapter *adapter, int port)
 
 int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port)
 {
-       u32 reg;
        u32 portnum = physical_port[adapter->portnum];
 
        netxen_crb_writelit_adapter(adapter,
-               NETXEN_NIU_XGE_CONFIG_0+(0x10000*portnum), 0x5);
-       netxen_nic_hw_read_wx(adapter,
-               NETXEN_NIU_XGE_CONFIG_1+(0x10000*portnum), &reg, 4);
-       reg = (reg & ~0x2000UL);
+               NETXEN_NIU_XGE_CONFIG_1+(0x10000*portnum), 0x1447);
        netxen_crb_writelit_adapter(adapter,
-               NETXEN_NIU_XGE_CONFIG_1+(0x10000*portnum), reg);
+               NETXEN_NIU_XGE_CONFIG_0+(0x10000*portnum), 0x5);
 
        return 0;
 }
index 22aec5cce68310ab6e4128b2ec30435fcff5c375..b87f8d2a888bb409af90e36a99662c2310ad54d3 100644 (file)
 #define MII_M1111_PHY_LED_CONTROL      0x18
 #define MII_M1111_PHY_LED_DIRECT       0x4100
 #define MII_M1111_PHY_LED_COMBINE      0x411c
+#define MII_M1111_PHY_EXT_CR           0x14
+#define MII_M1111_RX_DELAY             0x80
+#define MII_M1111_TX_DELAY             0x2
+#define MII_M1111_PHY_EXT_SR           0x1b
+#define MII_M1111_HWCFG_MODE_MASK      0xf
+#define MII_M1111_HWCFG_MODE_RGMII     0xb
 
 MODULE_DESCRIPTION("Marvell PHY driver");
 MODULE_AUTHOR("Andy Fleming");
@@ -131,6 +137,45 @@ static int marvell_config_aneg(struct phy_device *phydev)
        return err;
 }
 
+static int m88e1111_config_init(struct phy_device *phydev)
+{
+       int err;
+
+       if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) ||
+           (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)) {
+               int temp;
+
+               if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
+                       temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
+                       if (temp < 0)
+                               return temp;
+
+                       temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY);
+
+                       err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp);
+                       if (err < 0)
+                               return err;
+               }
+
+               temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
+               if (temp < 0)
+                       return temp;
+
+               temp &= ~(MII_M1111_HWCFG_MODE_MASK);
+               temp |= MII_M1111_HWCFG_MODE_RGMII;
+
+               err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
+               if (err < 0)
+                       return err;
+       }
+
+       err = phy_write(phydev, MII_BMCR, BMCR_RESET);
+       if (err < 0)
+               return err;
+
+       return 0;
+}
+
 static int m88e1145_config_init(struct phy_device *phydev)
 {
        int err;
@@ -152,7 +197,7 @@ static int m88e1145_config_init(struct phy_device *phydev)
        if (err < 0)
                return err;
 
-       if (phydev->interface == PHY_INTERFACE_MODE_RGMII) {
+       if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
                int temp = phy_read(phydev, MII_M1145_PHY_EXT_CR);
                if (temp < 0)
                        return temp;
@@ -206,7 +251,7 @@ static struct phy_driver m88e1101_driver = {
        .driver = {.owner = THIS_MODULE,},
 };
 
-static struct phy_driver m88e1111s_driver = {
+static struct phy_driver m88e1111_driver = {
        .phy_id = 0x01410cc0,
        .phy_id_mask = 0xfffffff0,
        .name = "Marvell 88E1111",
@@ -216,6 +261,7 @@ static struct phy_driver m88e1111s_driver = {
        .read_status = &genphy_read_status,
        .ack_interrupt = &marvell_ack_interrupt,
        .config_intr = &marvell_config_intr,
+       .config_init = &m88e1111_config_init,
        .driver = {.owner = THIS_MODULE,},
 };
 
@@ -241,9 +287,9 @@ static int __init marvell_init(void)
        if (ret)
                return ret;
 
-       ret = phy_driver_register(&m88e1111s_driver);
+       ret = phy_driver_register(&m88e1111_driver);
        if (ret)
-               goto err1111s;
+               goto err1111;
 
        ret = phy_driver_register(&m88e1145_driver);
        if (ret)
@@ -251,9 +297,9 @@ static int __init marvell_init(void)
 
        return 0;
 
-      err1145:
-       phy_driver_unregister(&m88e1111s_driver);
-      err1111s:
+err1145:
+       phy_driver_unregister(&m88e1111_driver);
+err1111:
        phy_driver_unregister(&m88e1101_driver);
        return ret;
 }
@@ -261,7 +307,7 @@ static int __init marvell_init(void)
 static void __exit marvell_exit(void)
 {
        phy_driver_unregister(&m88e1101_driver);
-       phy_driver_unregister(&m88e1111s_driver);
+       phy_driver_unregister(&m88e1111_driver);
        phy_driver_unregister(&m88e1145_driver);
 }
 
index 3de564b2314799b98a805d017f19ca2542db53e6..8dc09a3790cb4fe8b15d6595ae8cf0877bf850d7 100644 (file)
@@ -313,8 +313,8 @@ config USB_KC2190
        boolean "KT Technology KC2190 based cables (InstaNet)"
        depends on USB_NET_CDC_SUBSET && EXPERIMENTAL
        help
-         Choose this option if you're using a host-to-host cable
-         with one of these chips.
+         Choose this option if you're using a host-to-host cable
+         with one of these chips.
 
 config USB_NET_ZAURUS
        tristate "Sharp Zaurus (stock ROMs) and compatible"
index 25b75b615188ff521c238a0da54021cce20e9100..b670b97bcfde488a7de7a2e4bbe47985a0597a22 100644 (file)
@@ -1562,7 +1562,7 @@ static void velocity_print_link_status(struct velocity_info *vptr)
        if (vptr->mii_status & VELOCITY_LINK_FAIL) {
                VELOCITY_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: failed to detect cable link\n", vptr->dev->name);
        } else if (vptr->options.spd_dpx == SPD_DPX_AUTO) {
-               VELOCITY_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: Link autonegation", vptr->dev->name);
+               VELOCITY_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: Link auto-negotiation", vptr->dev->name);
 
                if (vptr->mii_status & VELOCITY_SPEED_1000)
                        VELOCITY_PRT(MSG_LEVEL_INFO, " speed 1000M bps");
index e3f5bb0fe603cf66eab0dc6118bbd1d6a4e34e21..fa2399cbd5cab472074b51d64a117bff1feb1d59 100644 (file)
@@ -266,16 +266,23 @@ config IPW2200_DEBUG
 
          If you are not sure, say N here.
 
-config LIBERTAS_USB
-       tristate "Marvell Libertas 8388 802.11a/b/g cards"
-       depends on USB && WLAN_80211
+config LIBERTAS
+       tristate "Marvell 8xxx Libertas WLAN driver support"
+       depends on WLAN_80211
+       select IEEE80211
        select FW_LOADER
+       ---help---
+         A library for Marvell Libertas 8xxx devices.
+
+config LIBERTAS_USB
+       tristate "Marvell Libertas 8388 USB 802.11b/g cards"
+       depends on LIBERTAS && USB
        ---help---
          A driver for Marvell Libertas 8388 USB devices.
 
-config LIBERTAS_USB_DEBUG
-       bool "Enable full debugging output in the Libertas USB module."
-       depends on LIBERTAS_USB
+config LIBERTAS_DEBUG
+       bool "Enable full debugging output in the Libertas module."
+       depends on LIBERTAS
        ---help---
          Debugging support.
 
index e0ecc4d483bb773edc269013ecb7000c8c17d869..4cf0ff7b833d6e77d6c99e5ba36c066f1b61b037 100644 (file)
@@ -95,7 +95,7 @@ static u8 wlan_get_chan_11d(u8 band, u8 firstchan, u8 nrchan, u8 * chan)
 
        for (i = 0; i < cfp_no; i++) {
                if ((cfp + i)->channel == firstchan) {
-                       lbs_pr_debug(1, "firstchan found\n");
+                       lbs_deb_11d("firstchan found\n");
                        break;
                }
        }
@@ -129,12 +129,12 @@ static u8 wlan_channel_known_11d(u8 chan,
 
        for (i = 0; i < nr_chan; i++) {
                if (chan == chanpwr[i].chan) {
-                       lbs_pr_debug(1, "11D: Found Chan:%d\n", chan);
+                       lbs_deb_11d("11D: Found Chan:%d\n", chan);
                        return 1;
                }
        }
 
-       lbs_pr_debug(1, "11D: Not Find Chan:%d\n", chan);
+       lbs_deb_11d("11D: Not Find Chan:%d\n", chan);
        return 0;
 }
 
@@ -174,7 +174,7 @@ static int generate_domain_info_11d(struct parsed_region_chan_11d
        memcpy(domaininfo->countrycode, parsed_region_chan->countrycode,
               COUNTRY_CODE_LEN);
 
-       lbs_pr_debug(1, "11D:nrchan=%d\n", nr_chan);
+       lbs_deb_11d("11D:nrchan=%d\n", nr_chan);
        lbs_dbg_hex("11D:parsed_region_chan:", (char *)parsed_region_chan,
                sizeof(struct parsed_region_chan_11d));
 
@@ -212,7 +212,7 @@ static int generate_domain_info_11d(struct parsed_region_chan_11d
        }
        domaininfo->nr_subband = nr_subband;
 
-       lbs_pr_debug(1, "nr_subband=%x\n", domaininfo->nr_subband);
+       lbs_deb_11d("nr_subband=%x\n", domaininfo->nr_subband);
        lbs_dbg_hex("11D:domaininfo:", (char *)domaininfo,
                COUNTRY_CODE_LEN + 1 +
                sizeof(struct ieeetypes_subbandset) * nr_subband);
@@ -233,13 +233,13 @@ static void wlan_generate_parsed_region_chan_11d(struct region_channel * region_
        struct chan_freq_power *cfp;
 
        if (region_chan == NULL) {
-               lbs_pr_debug(1, "11D: region_chan is NULL\n");
+               lbs_deb_11d("11D: region_chan is NULL\n");
                return;
        }
 
        cfp = region_chan->CFP;
        if (cfp == NULL) {
-               lbs_pr_debug(1, "11D: cfp equal NULL \n");
+               lbs_deb_11d("11D: cfp equal NULL \n");
                return;
        }
 
@@ -248,19 +248,19 @@ static void wlan_generate_parsed_region_chan_11d(struct region_channel * region_
        memcpy(parsed_region_chan->countrycode,
               wlan_code_2_region(region_chan->region), COUNTRY_CODE_LEN);
 
-       lbs_pr_debug(1, "11D: region[0x%x] band[%d]\n", parsed_region_chan->region,
+       lbs_deb_11d("11D: region[0x%x] band[%d]\n", parsed_region_chan->region,
               parsed_region_chan->band);
 
        for (i = 0; i < region_chan->nrcfp; i++, cfp++) {
                parsed_region_chan->chanpwr[i].chan = cfp->channel;
                parsed_region_chan->chanpwr[i].pwr = cfp->maxtxpower;
-               lbs_pr_debug(1, "11D: Chan[%d] Pwr[%d]\n",
+               lbs_deb_11d("11D: Chan[%d] Pwr[%d]\n",
                       parsed_region_chan->chanpwr[i].chan,
                       parsed_region_chan->chanpwr[i].pwr);
        }
        parsed_region_chan->nr_chan = region_chan->nrcfp;
 
-       lbs_pr_debug(1, "11D: nrchan[%d]\n", parsed_region_chan->nr_chan);
+       lbs_deb_11d("11D: nrchan[%d]\n", parsed_region_chan->nr_chan);
 
        return;
 }
@@ -277,8 +277,9 @@ static u8 wlan_region_chan_supported_11d(u8 region, u8 band, u8 chan)
        struct chan_freq_power *cfp;
        int cfp_no;
        u8 idx;
+       int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_11D);
 
        cfp = libertas_get_region_cfp_table(region, band, &cfp_no);
        if (cfp == NULL)
@@ -288,16 +289,19 @@ static u8 wlan_region_chan_supported_11d(u8 region, u8 band, u8 chan)
                if (chan == (cfp + idx)->channel) {
                        /* If Mrvl Chip Supported? */
                        if ((cfp + idx)->unsupported) {
-                               return 0;
+                               ret = 0;
                        } else {
-                               return 1;
+                               ret = 1;
                        }
+                       goto done;
                }
        }
 
        /*chan is not in the region table */
-       LEAVE();
-       return 0;
+
+done:
+       lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
+       return ret;
 }
 
 /**
@@ -321,7 +325,7 @@ static int parse_domain_info_11d(struct ieeetypes_countryinfofullset*
 
        u8 j, i;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_11D);
 
        /*validation Rules:
           1. valid region Code
@@ -337,15 +341,14 @@ static int parse_domain_info_11d(struct ieeetypes_countryinfofullset*
        if ((*(countryinfo->countrycode)) == 0
            || (countryinfo->len <= COUNTRY_CODE_LEN)) {
                /* No region Info or Wrong region info: treat as No 11D info */
-               LEAVE();
-               return 0;
+               goto done;
        }
 
        /*Step1: check region_code */
        parsed_region_chan->region = region =
            wlan_region_2_code(countryinfo->countrycode);
 
-       lbs_pr_debug(1, "regioncode=%x\n", (u8) parsed_region_chan->region);
+       lbs_deb_11d("regioncode=%x\n", (u8) parsed_region_chan->region);
        lbs_dbg_hex("CountryCode:", (char *)countryinfo->countrycode,
                COUNTRY_CODE_LEN);
 
@@ -361,7 +364,7 @@ static int parse_domain_info_11d(struct ieeetypes_countryinfofullset*
 
                if (countryinfo->subband[j].firstchan <= lastchan) {
                        /*Step2&3. Check First Chan Num increment and no overlap */
-                       lbs_pr_debug(1, "11D: Chan[%d>%d] Overlap\n",
+                       lbs_deb_11d("11D: Chan[%d>%d] Overlap\n",
                               countryinfo->subband[j].firstchan, lastchan);
                        continue;
                }
@@ -374,7 +377,7 @@ static int parse_domain_info_11d(struct ieeetypes_countryinfofullset*
 
                        if (!wlan_get_chan_11d(band, firstchan, i, &curchan)) {
                                /* Chan is not found in UN table */
-                               lbs_pr_debug(1, "chan is not supported: %d \n", i);
+                               lbs_deb_11d("chan is not supported: %d \n", i);
                                break;
                        }
 
@@ -389,7 +392,7 @@ static int parse_domain_info_11d(struct ieeetypes_countryinfofullset*
                                idx++;
                        } else {
                                /*not supported and ignore the chan */
-                               lbs_pr_debug(1,
+                               lbs_deb_11d(
                                       "11D:i[%d] chan[%d] unsupported in region[%x] band[%d]\n",
                                       i, curchan, region, band);
                        }
@@ -401,11 +404,12 @@ static int parse_domain_info_11d(struct ieeetypes_countryinfofullset*
 
        parsed_region_chan->nr_chan = idx;
 
-       lbs_pr_debug(1, "nrchan=%x\n", parsed_region_chan->nr_chan);
+       lbs_deb_11d("nrchan=%x\n", parsed_region_chan->nr_chan);
        lbs_dbg_hex("11D:parsed_region_chan:", (u8 *) parsed_region_chan,
                2 + COUNTRY_CODE_LEN + sizeof(struct parsed_region_chan_11d) * idx);
 
-       LEAVE();
+done:
+       lbs_deb_enter(LBS_DEB_11D);
        return 0;
 }
 
@@ -420,16 +424,16 @@ u8 libertas_get_scan_type_11d(u8 chan,
 {
        u8 scan_type = cmd_scan_type_passive;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_11D);
 
        if (wlan_channel_known_11d(chan, parsed_region_chan)) {
-               lbs_pr_debug(1, "11D: Found and do Active Scan\n");
+               lbs_deb_11d("11D: Found and do Active Scan\n");
                scan_type = cmd_scan_type_active;
        } else {
-               lbs_pr_debug(1, "11D: Not Find and do Passive Scan\n");
+               lbs_deb_11d("11D: Not Find and do Passive Scan\n");
        }
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_11D, "ret scan_type %d", scan_type);
        return scan_type;
 
 }
@@ -456,7 +460,7 @@ static int wlan_enable_11d(wlan_private * priv, u8 flag)
                                    OID_802_11D_ENABLE,
                                    &priv->adapter->enable11d);
        if (ret)
-               lbs_pr_debug(1, "11D: Fail to enable 11D \n");
+               lbs_deb_11d("11D: Fail to enable 11D \n");
 
        return 0;
 }
@@ -471,7 +475,7 @@ static int set_domain_info_11d(wlan_private * priv)
        int ret;
 
        if (!priv->adapter->enable11d) {
-               lbs_pr_debug(1, "11D: dnld domain Info with 11d disabled\n");
+               lbs_deb_11d("11D: dnld domain Info with 11d disabled\n");
                return 0;
        }
 
@@ -479,7 +483,7 @@ static int set_domain_info_11d(wlan_private * priv)
                                    cmd_act_set,
                                    cmd_option_waitforrsp, 0, NULL);
        if (ret)
-               lbs_pr_debug(1, "11D: Fail to dnld domain Info\n");
+               lbs_deb_11d("11D: Fail to dnld domain Info\n");
 
        return ret;
 }
@@ -501,7 +505,7 @@ int libertas_set_universaltable(wlan_private * priv, u8 band)
 
        adapter->universal_channel[i].nrcfp =
            sizeof(channel_freq_power_UN_BG) / size;
-       lbs_pr_debug(1, "11D: BG-band nrcfp=%d\n",
+       lbs_deb_11d("11D: BG-band nrcfp=%d\n",
               adapter->universal_channel[i].nrcfp);
 
        adapter->universal_channel[i].CFP = channel_freq_power_UN_BG;
@@ -531,9 +535,9 @@ int libertas_cmd_802_11d_domain_info(wlan_private * priv,
        wlan_adapter *adapter = priv->adapter;
        u8 nr_subband = adapter->domainreg.nr_subband;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_11D);
 
-       lbs_pr_debug(1, "nr_subband=%x\n", nr_subband);
+       lbs_deb_11d("nr_subband=%x\n", nr_subband);
 
        cmd->command = cpu_to_le16(cmdno);
        pdomaininfo->action = cpu_to_le16(cmdoption);
@@ -542,8 +546,7 @@ int libertas_cmd_802_11d_domain_info(wlan_private * priv,
                    cpu_to_le16(sizeof(pdomaininfo->action) + S_DS_GEN);
                lbs_dbg_hex("11D: 802_11D_DOMAIN_INFO:", (u8 *) cmd,
                        (int)(cmd->size));
-               LEAVE();
-               return 0;
+               goto done;
        }
 
        domain->header.type = cpu_to_le16(TLV_TYPE_DOMAIN);
@@ -567,10 +570,10 @@ int libertas_cmd_802_11d_domain_info(wlan_private * priv,
                    cpu_to_le16(sizeof(pdomaininfo->action) + S_DS_GEN);
        }
 
-       lbs_dbg_hex("11D:802_11D_DOMAIN_INFO:", (u8 *) cmd, (int)(cmd->size));
-
-       LEAVE();
+       lbs_dbg_hex("11D:802_11D_DOMAIN_INFO:", (u8 *) cmd, le16_to_cpu(cmd->size));
 
+done:
+       lbs_deb_enter(LBS_DEB_11D);
        return 0;
 }
 
@@ -585,17 +588,17 @@ int libertas_cmd_enable_11d(wlan_private * priv, struct iwreq *wrq)
        int data = 0;
        int *val;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_11D);
        data = SUBCMD_DATA(wrq);
 
-       lbs_pr_debug(1, "enable 11D: %s\n",
+       lbs_deb_11d("enable 11D: %s\n",
               (data == 1) ? "enable" : "Disable");
 
        wlan_enable_11d(priv, data);
        val = (int *)wrq->u.name;
        *val = priv->adapter->enable11d;
 
-       LEAVE();
+       lbs_deb_enter(LBS_DEB_11D);
        return 0;
 }
 
@@ -608,25 +611,24 @@ int libertas_cmd_enable_11d(wlan_private * priv, struct iwreq *wrq)
 int libertas_ret_802_11d_domain_info(wlan_private * priv,
                                 struct cmd_ds_command *resp)
 {
-       struct cmd_ds_802_11d_domain_info
-       *domaininfo = &resp->params.domaininforesp;
+       struct cmd_ds_802_11d_domain_info *domaininfo = &resp->params.domaininforesp;
        struct mrvlietypes_domainparamset *domain = &domaininfo->domain;
        u16 action = le16_to_cpu(domaininfo->action);
        s16 ret = 0;
        u8 nr_subband = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_11D);
 
        lbs_dbg_hex("11D DOMAIN Info Rsp Data:", (u8 *) resp,
                (int)le16_to_cpu(resp->size));
 
-       nr_subband = (domain->header.len - 3) / sizeof(struct ieeetypes_subbandset);
-       /* countrycode 3 bytes */
+       nr_subband = (le16_to_cpu(domain->header.len) - COUNTRY_CODE_LEN) /
+                     sizeof(struct ieeetypes_subbandset);
 
-       lbs_pr_debug(1, "11D Domain Info Resp: nr_subband=%d\n", nr_subband);
+       lbs_deb_11d("11D Domain Info Resp: nr_subband=%d\n", nr_subband);
 
        if (nr_subband > MRVDRV_MAX_SUBBAND_802_11D) {
-               lbs_pr_debug(1, "Invalid Numrer of Subband returned!!\n");
+               lbs_deb_11d("Invalid Numrer of Subband returned!!\n");
                return -1;
        }
 
@@ -637,12 +639,12 @@ int libertas_ret_802_11d_domain_info(wlan_private * priv,
        case cmd_act_get:
                break;
        default:
-               lbs_pr_debug(1, "Invalid action:%d\n", domaininfo->action);
+               lbs_deb_11d("Invalid action:%d\n", domaininfo->action);
                ret = -1;
                break;
        }
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
        return ret;
 }
 
@@ -651,23 +653,22 @@ int libertas_ret_802_11d_domain_info(wlan_private * priv,
  *  @param priv    pointer to wlan_private
  *  @return       0; -1
  */
-int libertas_parse_dnld_countryinfo_11d(wlan_private * priv)
+int libertas_parse_dnld_countryinfo_11d(wlan_private * priv,
+                                        struct bss_descriptor * bss)
 {
        int ret;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_11D);
        if (priv->adapter->enable11d) {
                memset(&adapter->parsed_region_chan, 0,
                       sizeof(struct parsed_region_chan_11d));
-               ret = parse_domain_info_11d(&adapter->pattemptedbssdesc->
-                                              countryinfo, 0,
+               ret = parse_domain_info_11d(&bss->countryinfo, 0,
                                               &adapter->parsed_region_chan);
 
                if (ret == -1) {
-                       lbs_pr_debug(1, "11D: Err Parse domain_info from AP..\n");
-                       LEAVE();
-                       return ret;
+                       lbs_deb_11d("11D: Err Parse domain_info from AP..\n");
+                       goto done;
                }
 
                memset(&adapter->domainreg, 0,
@@ -678,13 +679,15 @@ int libertas_parse_dnld_countryinfo_11d(wlan_private * priv)
                ret = set_domain_info_11d(priv);
 
                if (ret) {
-                       lbs_pr_debug(1, "11D: Err set domainInfo to FW\n");
-                       LEAVE();
-                       return ret;
+                       lbs_deb_11d("11D: Err set domainInfo to FW\n");
+                       goto done;
                }
        }
-       LEAVE();
-       return 0;
+       ret = 0;
+
+done:
+       lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
+       return ret;
 }
 
 /**
@@ -699,8 +702,8 @@ int libertas_create_dnld_countryinfo_11d(wlan_private * priv)
        struct region_channel *region_chan;
        u8 j;
 
-       ENTER();
-       lbs_pr_debug(1, "11D:curbssparams.band[%d]\n", adapter->curbssparams.band);
+       lbs_deb_enter(LBS_DEB_11D);
+       lbs_deb_11d("11D:curbssparams.band[%d]\n", adapter->curbssparams.band);
 
        if (priv->adapter->enable11d) {
                /* update parsed_region_chan_11; dnld domaininf to FW */
@@ -709,7 +712,7 @@ int libertas_create_dnld_countryinfo_11d(wlan_private * priv)
                     sizeof(adapter->region_channel[0]); j++) {
                        region_chan = &adapter->region_channel[j];
 
-                       lbs_pr_debug(1, "11D:[%d] region_chan->band[%d]\n", j,
+                       lbs_deb_11d("11D:[%d] region_chan->band[%d]\n", j,
                               region_chan->band);
 
                        if (!region_chan || !region_chan->valid
@@ -722,10 +725,10 @@ int libertas_create_dnld_countryinfo_11d(wlan_private * priv)
 
                if (j >= sizeof(adapter->region_channel) /
                    sizeof(adapter->region_channel[0])) {
-                       lbs_pr_debug(1, "11D:region_chan not found. band[%d]\n",
+                       lbs_deb_11d("11D:region_chan not found. band[%d]\n",
                               adapter->curbssparams.band);
-                       LEAVE();
-                       return -1;
+                       ret = -1;
+                       goto done;
                }
 
                memset(&adapter->parsed_region_chan, 0,
@@ -742,13 +745,14 @@ int libertas_create_dnld_countryinfo_11d(wlan_private * priv)
                ret = set_domain_info_11d(priv);
 
                if (ret) {
-                       lbs_pr_debug(1, "11D: Err set domainInfo to FW\n");
-                       LEAVE();
-                       return ret;
+                       lbs_deb_11d("11D: Err set domainInfo to FW\n");
+                       goto done;
                }
 
        }
+       ret = 0;
 
-       LEAVE();
-       return 0;
+done:
+       lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
+       return ret;
 }
index db2ebea9f23180738788d739cf76c6e75da47550..73e42e7129110a3da2fefc377fbdd8a10676ef0a 100644 (file)
@@ -47,7 +47,7 @@ struct mrvlietypes_domainparamset {
 } __attribute__ ((packed));
 
 struct cmd_ds_802_11d_domain_info {
-       u16 action;
+       __le16 action;
        struct mrvlietypes_domainparamset domain;
 } __attribute__ ((packed));
 
@@ -98,7 +98,9 @@ int libertas_cmd_enable_11d(wlan_private * priv, struct iwreq *wrq);
 int libertas_ret_802_11d_domain_info(wlan_private * priv,
                                 struct cmd_ds_command *resp);
 
-int libertas_parse_dnld_countryinfo_11d(wlan_private * priv);
+struct bss_descriptor;
+int libertas_parse_dnld_countryinfo_11d(wlan_private * priv,
+                                        struct bss_descriptor * bss);
 
 int libertas_create_dnld_countryinfo_11d(wlan_private * priv);
 
index 56a8ea1fbf041a6c24d8baea4efd298c089bb248..a1097f59fd4667241e3a2331de83b9ec06dbb41a 100644 (file)
@@ -1,4 +1,4 @@
-usb8xxx-objs := main.o fw.o wext.o \
+libertas-objs := main.o fw.o wext.o \
                rx.o tx.o cmd.o           \
                cmdresp.o scan.o          \
                join.o 11d.o              \
@@ -8,5 +8,5 @@ usb8xxx-objs := main.o fw.o wext.o \
 usb8xxx-objs += if_bootcmd.o
 usb8xxx-objs += if_usb.o
 
+obj-$(CONFIG_LIBERTAS)     += libertas.o
 obj-$(CONFIG_LIBERTAS_USB) += usb8xxx.o
-
index 378577200b56c5f3e81fe849c1c8d44aecb81723..1f92f50b643c7a9eac13d1eda1d7a601dace886f 100644 (file)
@@ -1,7 +1,7 @@
 ================================================================================
                        README for USB8388
 
- (c) Copyright © 2003-2006, Marvell International Ltd.
+ (c) Copyright Â© 2003-2006, Marvell International Ltd.
  All Rights Reserved
 
  This software file (the "File") is distributed by Marvell International
@@ -47,15 +47,19 @@ Version 5 Command:
        iwpriv ethX ledgpio <n>
 
 BT Commands:
-       The blinding table (BT) contains a list of mac addresses that should be
-       ignored by the firmware.  It is primarily used for debugging and
-       testing networks.  It can be edited and inspected with the following
-       commands:
+       The blinding table (BT) contains a list of mac addresses that will be,
+       by default, ignored by the firmware. It is also possible to invert this
+       behavior so that we will ignore all traffic except for the portion
+       coming from mac addresess in the list. It is primarily used for
+       debugging and testing networks.  It can be edited and inspected with
+       the following commands:
 
        iwpriv ethX bt_reset
        iwpriv ethX bt_add <mac_address>
        iwpriv ethX bt_del <mac_address>
        iwpriv ethX bt_list <id>
+       iwpriv ethX bt_get_invert <n>
+       iwpriv ethX bt_set_invert <n>
 
 FWT Commands:
        The forwarding table (FWT) is a feature used to manage mesh network
@@ -135,7 +139,7 @@ fwt_add
        This command is used to insert an entry into the FWT table. The list of
        parameters must follow the following structure:
 
-       iwpriv ethX fwt_add da ra [metric dir ssn dsn hopcount ttl expiration sleepmode snr]
+       iwpriv ethX fwt_add da ra [metric dir rate ssn dsn hopcount ttl expiration sleepmode snr]
 
        The parameters between brackets are optional, but they must appear in
        the order specified.  For example, if you want to specify the metric,
@@ -150,6 +154,9 @@ fwt_add
                                   preferred, default is 0)
                dir             -- direction (1 for direct, 0 for reverse,
                                   default is 1)
+               rate            -- data rate used for transmission to the RA,
+                                  as specified for the rateadapt command,
+                                  default is 3 (11Mbps)
                ssn             -- Source Sequence Number (time at the RA for
                                   reverse routes.  Default is 0)
                dsn             -- Destination Sequence Number (time at the DA
@@ -207,13 +214,17 @@ fwt_list
 
        The output is a string of the following form:
 
-               da ra metric dir ssn dsn hopcount ttl expiration sleepmode snr
+               da ra valid metric dir rate ssn dsn hopcount ttl expiration
+               sleepmode snr precursor
 
        where the different fields are:-
                da              -- DA MAC address (in the form "00:11:22:33:44:55")
                ra              -- RA MAC address (in the form "00:11:22:33:44:55")
+               valid           -- whether the route is valid (0 if not valid)
                metric          -- route metric (cost: smaller-metric routes are preferred)
                dir             -- direction (1 for direct, 0 for reverse)
+               rate            -- data rate used for transmission to the RA,
+                                  as specified for the rateadapt command
                ssn             -- Source Sequence Number (time at the RA for reverse routes)
                dsn             -- Destination Sequence Number (time at the DA for direct routes)
                hopcount        -- hop count (currently unused)
@@ -221,33 +232,10 @@ fwt_list
                expiration      -- entry expiration (in ticks, where a tick is 1024us, or ~ 1ms. Use 0 for an indefinite entry)
                sleepmode       -- RA's sleep mode (currently unused)
                snr             -- SNR in the link to RA (currently unused)
+               precursor       -- predecessor in direct routes
 
 fwt_list_route
-       This command is used to list a route from the FWT table. The only
-       parameter is the route ID. If you want to list all the routes in a
-       table, start with rid=0, and keep incrementing rid until you get a
-       "(null)" string. This function is similar to fwt_list. The only
-       difference is the output format.  Also note that this command is meant
-       for debugging.  It is expected that users will use fwt_lookup and
-       fwt_list.  One important reason for this is that the route id may change
-       as the route table is altered.
-
-               iwpriv ethX fwt_list_route rid
-
-       The output is a string of the following form:
-
-               da metric dir nid ssn dsn hopcount ttl expiration
-
-       where the different fields are:-
-               da              -- DA MAC address (in the form "00:11:22:33:44:55")
-               metric          -- route metric (cost: smaller-metric routes are preferred)
-               dir             -- direction (1 for direct, 0 for reverse)
-               nid             -- Next-hop (neighbor) host ID (nid)
-               ssn             -- Source Sequence Number (time at the RA for reverse routes)
-               dsn             -- Destination Sequence Number (time at the DA for direct routes)
-               hopcount        -- hop count (currently unused)
-               ttl             -- TTL count (only used in reverse entries)
-               expiration      -- entry expiration (in ticks, where a tick is 1024us, or ~ 1ms. Use 0 for an indefinite entry)
+       This command is equivalent to fwt_list.
 
 fwt_list_neigh
        This command is used to list a neighbor from the FWT table. The only
index c260bd1b3d46667df8cd32f2beb3fd2a06a59eb0..f67efa0815fe0f5b7fe5905f708eae0e8c2014da 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <linux/bitops.h>
 #include <net/ieee80211.h>
+#include <linux/etherdevice.h>
 
 #include "assoc.h"
 #include "join.h"
 static const u8 bssid_any[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
 static const u8 bssid_off[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 
+static void print_assoc_req(const char * extra, struct assoc_request * assoc_req)
+{
+       lbs_deb_assoc(
+              "#### Association Request: %s\n"
+              "       flags:      0x%08lX\n"
+              "       SSID:       '%s'\n"
+              "       channel:    %d\n"
+              "       band:       %d\n"
+              "       mode:       %d\n"
+              "       BSSID:      " MAC_FMT "\n"
+              "       Encryption:%s%s%s\n"
+              "       auth:       %d\n",
+              extra, assoc_req->flags,
+              escape_essid(assoc_req->ssid, assoc_req->ssid_len),
+              assoc_req->channel, assoc_req->band, assoc_req->mode,
+              MAC_ARG(assoc_req->bssid),
+              assoc_req->secinfo.WPAenabled ? " WPA" : "",
+              assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
+              assoc_req->secinfo.wep_enabled ? " WEP" : "",
+              assoc_req->secinfo.auth_mode);
+}
+
+
 static int assoc_helper_essid(wlan_private *priv,
                               struct assoc_request * assoc_req)
 {
        wlan_adapter *adapter = priv->adapter;
        int ret = 0;
-       int i;
+       struct bss_descriptor * bss;
+       int channel = -1;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_ASSOC);
 
-       lbs_pr_debug(1, "New SSID requested: %s\n", assoc_req->ssid.ssid);
+       /* FIXME: take channel into account when picking SSIDs if a channel
+        * is set.
+        */
+
+       if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
+               channel = assoc_req->channel;
+
+       lbs_deb_assoc("New SSID requested: '%s'\n",
+                     escape_essid(assoc_req->ssid, assoc_req->ssid_len));
        if (assoc_req->mode == IW_MODE_INFRA) {
                if (adapter->prescan) {
-                       libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 1);
+                       libertas_send_specific_ssid_scan(priv, assoc_req->ssid,
+                               assoc_req->ssid_len, 0);
                }
 
-               i = libertas_find_SSID_in_list(adapter, &assoc_req->ssid,
-                               NULL, IW_MODE_INFRA);
-               if (i >= 0) {
-                       lbs_pr_debug(1,
-                              "SSID found in scan list ... associating...\n");
-
-                       ret = wlan_associate(priv, &adapter->scantable[i]);
-                       if (ret == 0) {
-                               memcpy(&assoc_req->bssid,
-                                      &adapter->scantable[i].macaddress,
-                                      ETH_ALEN);
-                       }
+               bss = libertas_find_ssid_in_list(adapter, assoc_req->ssid,
+                               assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel);
+               if (bss != NULL) {
+                       lbs_deb_assoc("SSID found in scan list, associating\n");
+                       memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
+                       ret = wlan_associate(priv, assoc_req);
                } else {
-                       lbs_pr_debug(1, "SSID '%s' not found; cannot associate\n",
-                               assoc_req->ssid.ssid);
+                       lbs_deb_assoc("SSID not found; cannot associate\n");
                }
        } else if (assoc_req->mode == IW_MODE_ADHOC) {
                /* Scan for the network, do not save previous results.  Stale
                 *   scan data will cause us to join a non-existant adhoc network
                 */
-               libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 0);
+               libertas_send_specific_ssid_scan(priv, assoc_req->ssid,
+                       assoc_req->ssid_len, 1);
 
                /* Search for the requested SSID in the scan table */
-               i = libertas_find_SSID_in_list(adapter, &assoc_req->ssid, NULL,
-                               IW_MODE_ADHOC);
-               if (i >= 0) {
-                       lbs_pr_debug(1, "SSID found at %d in List, so join\n", ret);
-                       libertas_join_adhoc_network(priv, &adapter->scantable[i]);
+               bss = libertas_find_ssid_in_list(adapter, assoc_req->ssid,
+                               assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel);
+               if (bss != NULL) {
+                       lbs_deb_assoc("SSID found, will join\n");
+                       memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
+                       libertas_join_adhoc_network(priv, assoc_req);
                } else {
                        /* else send START command */
-                       lbs_pr_debug(1, "SSID not found in list, so creating adhoc"
-                               " with SSID '%s'\n", assoc_req->ssid.ssid);
-                       libertas_start_adhoc_network(priv, &assoc_req->ssid);
+                       lbs_deb_assoc("SSID not found, creating adhoc network\n");
+                       memcpy(&assoc_req->bss.ssid, &assoc_req->ssid,
+                               IW_ESSID_MAX_SIZE);
+                       assoc_req->bss.ssid_len = assoc_req->ssid_len;
+                       libertas_start_adhoc_network(priv, assoc_req);
                }
-               memcpy(&assoc_req->bssid, &adapter->current_addr, ETH_ALEN);
        }
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
 
@@ -74,33 +104,31 @@ static int assoc_helper_bssid(wlan_private *priv,
                               struct assoc_request * assoc_req)
 {
        wlan_adapter *adapter = priv->adapter;
-       int i, ret = 0;
-
-       ENTER();
+       int ret = 0;
+       struct bss_descriptor * bss;
 
-       lbs_pr_debug(1, "ASSOC: WAP: BSSID = " MAC_FMT "\n",
+       lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID " MAC_FMT,
                MAC_ARG(assoc_req->bssid));
 
        /* Search for index position in list for requested MAC */
-       i = libertas_find_BSSID_in_list(adapter, assoc_req->bssid,
+       bss = libertas_find_bssid_in_list(adapter, assoc_req->bssid,
                            assoc_req->mode);
-       if (i < 0) {
-               lbs_pr_debug(1, "ASSOC: WAP: BSSID " MAC_FMT " not found, "
+       if (bss == NULL) {
+               lbs_deb_assoc("ASSOC: WAP: BSSID " MAC_FMT " not found, "
                        "cannot associate.\n", MAC_ARG(assoc_req->bssid));
                goto out;
        }
 
+       memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
        if (assoc_req->mode == IW_MODE_INFRA) {
-               ret = wlan_associate(priv, &adapter->scantable[i]);
-               lbs_pr_debug(1, "ASSOC: return from wlan_associate(bssd) was %d\n", ret);
+               ret = wlan_associate(priv, assoc_req);
+               lbs_deb_assoc("ASSOC: wlan_associate(bssid) returned %d\n", ret);
        } else if (assoc_req->mode == IW_MODE_ADHOC) {
-               libertas_join_adhoc_network(priv, &adapter->scantable[i]);
+               libertas_join_adhoc_network(priv, assoc_req);
        }
-       memcpy(&assoc_req->ssid, &adapter->scantable[i].ssid,
-               sizeof(struct WLAN_802_11_SSID));
 
 out:
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
 
@@ -113,12 +141,12 @@ static int assoc_helper_associate(wlan_private *priv,
        /* If we're given and 'any' BSSID, try associating based on SSID */
 
        if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
-               if (memcmp(bssid_any, assoc_req->bssid, ETH_ALEN)
-                   && memcmp(bssid_off, assoc_req->bssid, ETH_ALEN)) {
+               if (compare_ether_addr(bssid_any, assoc_req->bssid)
+                   && compare_ether_addr(bssid_off, assoc_req->bssid)) {
                        ret = assoc_helper_bssid(priv, assoc_req);
                        done = 1;
                        if (ret) {
-                               lbs_pr_debug(1, "ASSOC: bssid: ret = %d\n", ret);
+                               lbs_deb_assoc("ASSOC: bssid: ret = %d\n", ret);
                        }
                }
        }
@@ -126,7 +154,7 @@ static int assoc_helper_associate(wlan_private *priv,
        if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
                ret = assoc_helper_essid(priv, assoc_req);
                if (ret) {
-                       lbs_pr_debug(1, "ASSOC: bssid: ret = %d\n", ret);
+                       lbs_deb_assoc("ASSOC: bssid: ret = %d\n", ret);
                }
        }
 
@@ -140,12 +168,10 @@ static int assoc_helper_mode(wlan_private *priv,
        wlan_adapter *adapter = priv->adapter;
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_ASSOC);
 
-       if (assoc_req->mode == adapter->mode) {
-               LEAVE();
-               return 0;
-       }
+       if (assoc_req->mode == adapter->mode)
+               goto done;
 
        if (assoc_req->mode == IW_MODE_INFRA) {
                if (adapter->psstate != PS_STATE_FULL_POWER)
@@ -158,9 +184,81 @@ static int assoc_helper_mode(wlan_private *priv,
                                    cmd_802_11_snmp_mib,
                                    0, cmd_option_waitforrsp,
                                    OID_802_11_INFRASTRUCTURE_MODE,
-                                   (void *) (size_t) assoc_req->mode);
+               /* Shoot me now */  (void *) (size_t) assoc_req->mode);
 
-       LEAVE();
+done:
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
+       return ret;
+}
+
+
+static int update_channel(wlan_private * priv)
+{
+       /* the channel in f/w could be out of sync, get the current channel */
+       return libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
+                                   cmd_opt_802_11_rf_channel_get,
+                                   cmd_option_waitforrsp, 0, NULL);
+}
+
+void libertas_sync_channel(struct work_struct *work)
+{
+       wlan_private *priv = container_of(work, wlan_private, sync_channel);
+
+       if (update_channel(priv) != 0)
+               lbs_pr_info("Channel synchronization failed.");
+}
+
+static int assoc_helper_channel(wlan_private *priv,
+                                struct assoc_request * assoc_req)
+{
+       wlan_adapter *adapter = priv->adapter;
+       int ret = 0;
+
+       lbs_deb_enter(LBS_DEB_ASSOC);
+
+       ret = update_channel(priv);
+       if (ret < 0) {
+               lbs_deb_assoc("ASSOC: channel: error getting channel.");
+       }
+
+       if (assoc_req->channel == adapter->curbssparams.channel)
+               goto done;
+
+       lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
+              adapter->curbssparams.channel, assoc_req->channel);
+
+       ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
+                               cmd_opt_802_11_rf_channel_set,
+                               cmd_option_waitforrsp, 0, &assoc_req->channel);
+       if (ret < 0) {
+               lbs_deb_assoc("ASSOC: channel: error setting channel.");
+       }
+
+       ret = update_channel(priv);
+       if (ret < 0) {
+               lbs_deb_assoc("ASSOC: channel: error getting channel.");
+       }
+
+       if (assoc_req->channel != adapter->curbssparams.channel) {
+               lbs_deb_assoc("ASSOC: channel: failed to update channel to %d",
+                             assoc_req->channel);
+               goto done;
+       }
+
+       if (   assoc_req->secinfo.wep_enabled
+           &&   (assoc_req->wep_keys[0].len
+              || assoc_req->wep_keys[1].len
+              || assoc_req->wep_keys[2].len
+              || assoc_req->wep_keys[3].len)) {
+               /* Make sure WEP keys are re-sent to firmware */
+               set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
+       }
+
+       /* Must restart/rejoin adhoc networks after channel change */
+       set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
+
+done:
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
 
@@ -172,7 +270,7 @@ static int assoc_helper_wep_keys(wlan_private *priv,
        int i;
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_ASSOC);
 
        /* Set or remove WEP keys */
        if (   assoc_req->wep_keys[0].len
@@ -216,7 +314,7 @@ static int assoc_helper_wep_keys(wlan_private *priv,
        mutex_unlock(&adapter->lock);
 
 out:
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
 
@@ -226,14 +324,24 @@ static int assoc_helper_secinfo(wlan_private *priv,
        wlan_adapter *adapter = priv->adapter;
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_ASSOC);
 
        memcpy(&adapter->secinfo, &assoc_req->secinfo,
                sizeof(struct wlan_802_11_security));
 
        ret = libertas_set_mac_packet_filter(priv);
+       if (ret)
+               goto out;
 
-       LEAVE();
+       /* enable/disable RSN */
+       ret = libertas_prepare_and_send_command(priv,
+                                   cmd_802_11_enable_rsn,
+                                   cmd_act_set,
+                                   cmd_option_waitforrsp,
+                                   0, assoc_req);
+
+out:
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
 
@@ -243,16 +351,7 @@ static int assoc_helper_wpa_keys(wlan_private *priv,
 {
        int ret = 0;
 
-       ENTER();
-
-       /* enable/Disable RSN */
-       ret = libertas_prepare_and_send_command(priv,
-                                   cmd_802_11_enable_rsn,
-                                   cmd_act_set,
-                                   cmd_option_waitforrsp,
-                                   0, assoc_req);
-       if (ret)
-               goto out;
+       lbs_deb_enter(LBS_DEB_ASSOC);
 
        ret = libertas_prepare_and_send_command(priv,
                                    cmd_802_11_key_material,
@@ -260,8 +359,7 @@ static int assoc_helper_wpa_keys(wlan_private *priv,
                                    cmd_option_waitforrsp,
                                    0, assoc_req);
 
-out:
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
 
@@ -272,7 +370,7 @@ static int assoc_helper_wpa_ie(wlan_private *priv,
        wlan_adapter *adapter = priv->adapter;
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_ASSOC);
 
        if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
                memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
@@ -282,7 +380,7 @@ static int assoc_helper_wpa_ie(wlan_private *priv,
                adapter->wpa_ie_len = 0;
        }
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
 
@@ -294,25 +392,30 @@ static int should_deauth_infrastructure(wlan_adapter *adapter,
                return 0;
 
        if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
-               lbs_pr_debug(1, "Deauthenticating due to new SSID in "
+               lbs_deb_assoc("Deauthenticating due to new SSID in "
                        " configuration request.\n");
                return 1;
        }
 
        if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
                if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
-                       lbs_pr_debug(1, "Deauthenticating due to updated security "
+                       lbs_deb_assoc("Deauthenticating due to updated security "
                                "info in configuration request.\n");
                        return 1;
                }
        }
 
        if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
-               lbs_pr_debug(1, "Deauthenticating due to new BSSID in "
+               lbs_deb_assoc("Deauthenticating due to new BSSID in "
                        " configuration request.\n");
                return 1;
        }
 
+       if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
+               lbs_deb_assoc("Deauthenticating due to channel switch.\n");
+               return 1;
+       }
+
        /* FIXME: deal with 'auto' mode somehow */
        if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
                if (assoc_req->mode != IW_MODE_INFRA)
@@ -329,10 +432,9 @@ static int should_stop_adhoc(wlan_adapter *adapter,
        if (adapter->connect_status != libertas_connected)
                return 0;
 
-       if (adapter->curbssparams.ssid.ssidlength != assoc_req->ssid.ssidlength)
-               return 1;
-       if (memcmp(adapter->curbssparams.ssid.ssid, assoc_req->ssid.ssid,
-                       adapter->curbssparams.ssid.ssidlength))
+       if (libertas_ssid_cmp(adapter->curbssparams.ssid,
+                             adapter->curbssparams.ssid_len,
+                             assoc_req->ssid, assoc_req->ssid_len) != 0)
                return 1;
 
        /* FIXME: deal with 'auto' mode somehow */
@@ -341,11 +443,16 @@ static int should_stop_adhoc(wlan_adapter *adapter,
                        return 1;
        }
 
+       if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
+               if (assoc_req->channel != adapter->curbssparams.channel)
+                       return 1;
+       }
+
        return 0;
 }
 
 
-void wlan_association_worker(struct work_struct *work)
+void libertas_association_worker(struct work_struct *work)
 {
        wlan_private *priv = container_of(work, wlan_private, assoc_work.work);
        wlan_adapter *adapter = priv->adapter;
@@ -353,40 +460,38 @@ void wlan_association_worker(struct work_struct *work)
        int ret = 0;
        int find_any_ssid = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_ASSOC);
 
        mutex_lock(&adapter->lock);
-       assoc_req = adapter->assoc_req;
-       adapter->assoc_req = NULL;
+       assoc_req = adapter->pending_assoc_req;
+       adapter->pending_assoc_req = NULL;
+       adapter->in_progress_assoc_req = assoc_req;
        mutex_unlock(&adapter->lock);
 
-       if (!assoc_req) {
-               LEAVE();
-               return;
-       }
+       if (!assoc_req)
+               goto done;
 
-       lbs_pr_debug(1, "ASSOC: starting new association request: flags = 0x%lX\n",
-               assoc_req->flags);
+       print_assoc_req(__func__, assoc_req);
 
        /* If 'any' SSID was specified, find an SSID to associate with */
        if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
-           && !assoc_req->ssid.ssidlength)
+           && !assoc_req->ssid_len)
                find_any_ssid = 1;
 
        /* But don't use 'any' SSID if there's a valid locked BSSID to use */
        if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
-               if (memcmp(&assoc_req->bssid, bssid_any, ETH_ALEN)
-                   && memcmp(&assoc_req->bssid, bssid_off, ETH_ALEN))
+               if (compare_ether_addr(assoc_req->bssid, bssid_any)
+                   && compare_ether_addr(assoc_req->bssid, bssid_off))
                        find_any_ssid = 0;
        }
 
        if (find_any_ssid) {
                u8 new_mode;
 
-               ret = libertas_find_best_network_SSID(priv, &assoc_req->ssid,
-                               assoc_req->mode, &new_mode);
+               ret = libertas_find_best_network_ssid(priv, assoc_req->ssid,
+                               &assoc_req->ssid_len, assoc_req->mode, &new_mode);
                if (ret) {
-                       lbs_pr_debug(1, "Could not find best network\n");
+                       lbs_deb_assoc("Could not find best network\n");
                        ret = -ENETUNREACH;
                        goto out;
                }
@@ -406,7 +511,7 @@ void wlan_association_worker(struct work_struct *work)
                if (should_deauth_infrastructure(adapter, assoc_req)) {
                        ret = libertas_send_deauthentication(priv);
                        if (ret) {
-                               lbs_pr_debug(1, "Deauthentication due to new "
+                               lbs_deb_assoc("Deauthentication due to new "
                                        "configuration request failed: %d\n",
                                        ret);
                        }
@@ -415,7 +520,7 @@ void wlan_association_worker(struct work_struct *work)
                if (should_stop_adhoc(adapter, assoc_req)) {
                        ret = libertas_stop_adhoc_network(priv);
                        if (ret) {
-                               lbs_pr_debug(1, "Teardown of AdHoc network due to "
+                               lbs_deb_assoc("Teardown of AdHoc network due to "
                                        "new configuration request failed: %d\n",
                                        ret);
                        }
@@ -427,7 +532,16 @@ void wlan_association_worker(struct work_struct *work)
        if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
                ret = assoc_helper_mode(priv, assoc_req);
                if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) mode: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) mode: ret = %d\n", __LINE__, ret);
+                       goto out;
+               }
+       }
+
+       if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
+               ret = assoc_helper_channel(priv, assoc_req);
+               if (ret) {
+                       lbs_deb_assoc("ASSOC(:%d) channel: ret = %d\n",
+                                     __LINE__, ret);
                        goto out;
                }
        }
@@ -436,7 +550,7 @@ lbs_pr_debug(1, "ASSOC(:%d) mode: ret = %d\n", __LINE__, ret);
            || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
                ret = assoc_helper_wep_keys(priv, assoc_req);
                if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) wep_keys: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) wep_keys: ret = %d\n", __LINE__, ret);
                        goto out;
                }
        }
@@ -444,7 +558,7 @@ lbs_pr_debug(1, "ASSOC(:%d) wep_keys: ret = %d\n", __LINE__, ret);
        if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
                ret = assoc_helper_secinfo(priv, assoc_req);
                if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) secinfo: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) secinfo: ret = %d\n", __LINE__, ret);
                        goto out;
                }
        }
@@ -452,7 +566,7 @@ lbs_pr_debug(1, "ASSOC(:%d) secinfo: ret = %d\n", __LINE__, ret);
        if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
                ret = assoc_helper_wpa_ie(priv, assoc_req);
                if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret);
                        goto out;
                }
        }
@@ -461,7 +575,7 @@ lbs_pr_debug(1, "ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret);
            || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
                ret = assoc_helper_wpa_keys(priv, assoc_req);
                if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
                        goto out;
                }
        }
@@ -475,21 +589,23 @@ lbs_pr_debug(1, "ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
 
                ret = assoc_helper_associate(priv, assoc_req);
                if (ret) {
-                       lbs_pr_debug(1, "ASSOC: association attempt unsuccessful: %d\n",
+                       lbs_deb_assoc("ASSOC: association attempt unsuccessful: %d\n",
                                ret);
                        success = 0;
                }
 
                if (adapter->connect_status != libertas_connected) {
-                       lbs_pr_debug(1, "ASSOC: assoication attempt unsuccessful, "
+                       lbs_deb_assoc("ASSOC: assoication attempt unsuccessful, "
                                "not connected.\n");
                        success = 0;
                }
 
                if (success) {
-                       lbs_pr_debug(1, "ASSOC: association attempt successful. "
+                       lbs_deb_assoc("ASSOC: association attempt successful. "
                                "Associated to '%s' (" MAC_FMT ")\n",
-                               assoc_req->ssid.ssid, MAC_ARG(assoc_req->bssid));
+                               escape_essid(adapter->curbssparams.ssid,
+                                            adapter->curbssparams.ssid_len),
+                               MAC_ARG(adapter->curbssparams.bssid));
                        libertas_prepare_and_send_command(priv,
                                cmd_802_11_rssi,
                                0, cmd_option_waitforrsp, 0, NULL);
@@ -498,18 +614,23 @@ lbs_pr_debug(1, "ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
                                cmd_802_11_get_log,
                                0, cmd_option_waitforrsp, 0, NULL);
                } else {
-
                        ret = -1;
                }
        }
 
 out:
        if (ret) {
-               lbs_pr_debug(1, "ASSOC: reconfiguration attempt unsuccessful: %d\n",
+               lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
                        ret);
        }
+
+       mutex_lock(&adapter->lock);
+       adapter->in_progress_assoc_req = NULL;
+       mutex_unlock(&adapter->lock);
        kfree(assoc_req);
-       LEAVE();
+
+done:
+       lbs_deb_leave(LBS_DEB_ASSOC);
 }
 
 
@@ -520,9 +641,10 @@ struct assoc_request * wlan_get_association_request(wlan_adapter *adapter)
 {
        struct assoc_request * assoc_req;
 
-       if (!adapter->assoc_req) {
-               adapter->assoc_req = kzalloc(sizeof(struct assoc_request), GFP_KERNEL);
-               if (!adapter->assoc_req) {
+       if (!adapter->pending_assoc_req) {
+               adapter->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
+                                                    GFP_KERNEL);
+               if (!adapter->pending_assoc_req) {
                        lbs_pr_info("Not enough memory to allocate association"
                                " request!\n");
                        return NULL;
@@ -532,15 +654,19 @@ struct assoc_request * wlan_get_association_request(wlan_adapter *adapter)
        /* Copy current configuration attributes to the association request,
         * but don't overwrite any that are already set.
         */
-       assoc_req = adapter->assoc_req;
+       assoc_req = adapter->pending_assoc_req;
        if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
-               memcpy(&assoc_req->ssid, adapter->curbssparams.ssid.ssid,
-                       adapter->curbssparams.ssid.ssidlength);
+               memcpy(&assoc_req->ssid, &adapter->curbssparams.ssid,
+                      IW_ESSID_MAX_SIZE);
+               assoc_req->ssid_len = adapter->curbssparams.ssid_len;
        }
 
        if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
                assoc_req->channel = adapter->curbssparams.channel;
 
+       if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
+               assoc_req->band = adapter->curbssparams.band;
+
        if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
                assoc_req->mode = adapter->mode;
 
@@ -581,7 +707,7 @@ struct assoc_request * wlan_get_association_request(wlan_adapter *adapter)
                assoc_req->wpa_ie_len = adapter->wpa_ie_len;
        }
 
+       print_assoc_req(__func__, assoc_req);
+
        return assoc_req;
 }
-
-
index 2ffd82d99b340a7e9ae2aba95dea150d2a019782..5e9c31f0932b1d64377184c5fa038c16dbbdd19f 100644 (file)
@@ -5,10 +5,12 @@
 
 #include "dev.h"
 
-void wlan_association_worker(struct work_struct *work);
+void libertas_association_worker(struct work_struct *work);
 
 struct assoc_request * wlan_get_association_request(wlan_adapter *adapter);
 
+void libertas_sync_channel(struct work_struct *work);
+
 #define ASSOC_DELAY (HZ / 2)
 static inline void wlan_postpone_association_work(wlan_private *priv)
 {
@@ -21,9 +23,9 @@ static inline void wlan_postpone_association_work(wlan_private *priv)
 static inline void wlan_cancel_association_work(wlan_private *priv)
 {
        cancel_delayed_work(&priv->assoc_work);
-       if (priv->adapter->assoc_req) {
-               kfree(priv->adapter->assoc_req);
-               priv->adapter->assoc_req = NULL;
+       if (priv->adapter->pending_assoc_req) {
+               kfree(priv->adapter->pending_assoc_req);
+               priv->adapter->pending_assoc_req = NULL;
        }
 }
 
index de9cb46a70fffaa726879cc44affb5a3144a6575..124e029f1bf412105d0f02e643be55c9cb1ffc71 100644 (file)
@@ -6,7 +6,6 @@
 #include <net/iw_handler.h>
 #include "host.h"
 #include "hostcmd.h"
-#include "sbi.h"
 #include "decl.h"
 #include "defs.h"
 #include "dev.h"
@@ -26,13 +25,11 @@ static u16 commands_allowed_in_ps[] = {
  *  @param command the command ID
  *  @return       TRUE or FALSE
  */
-static u8 is_command_allowed_in_ps(u16 command)
+static u8 is_command_allowed_in_ps(__le16 command)
 {
-       int count = sizeof(commands_allowed_in_ps)
-           / sizeof(commands_allowed_in_ps[0]);
        int i;
 
-       for (i = 0; i < count; i++) {
+       for (i = 0; i < ARRAY_SIZE(commands_allowed_in_ps); i++) {
                if (command == cpu_to_le16(commands_allowed_in_ps[i]))
                        return 1;
        }
@@ -44,14 +41,13 @@ static int wlan_cmd_hw_spec(wlan_private * priv, struct cmd_ds_command *cmd)
 {
        struct cmd_ds_get_hw_spec *hwspec = &cmd->params.hwspec;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        cmd->command = cpu_to_le16(cmd_get_hw_spec);
-       cmd->size =
-           cpu_to_le16(sizeof(struct cmd_ds_get_hw_spec) + S_DS_GEN);
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_get_hw_spec) + S_DS_GEN);
        memcpy(hwspec->permanentaddr, priv->adapter->current_addr, ETH_ALEN);
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_CMD);
        return 0;
 }
 
@@ -60,21 +56,19 @@ static int wlan_cmd_802_11_ps_mode(wlan_private * priv,
                                   u16 cmd_action)
 {
        struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
-       u16 action = cmd_action;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        cmd->command = cpu_to_le16(cmd_802_11_ps_mode);
-       cmd->size =
-           cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
-                            S_DS_GEN);
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
+                               S_DS_GEN);
        psm->action = cpu_to_le16(cmd_action);
        psm->multipledtim = 0;
-       switch (action) {
+       switch (cmd_action) {
        case cmd_subcmd_enter_ps:
-               lbs_pr_debug(1, "PS command:" "SubCode- Enter PS\n");
-               lbs_pr_debug(1, "locallisteninterval = %d\n",
+               lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
+               lbs_deb_cmd("locallisteninterval = %d\n",
                       adapter->locallisteninterval);
 
                psm->locallisteninterval =
@@ -86,18 +80,18 @@ static int wlan_cmd_802_11_ps_mode(wlan_private * priv,
                break;
 
        case cmd_subcmd_exit_ps:
-               lbs_pr_debug(1, "PS command:" "SubCode- Exit PS\n");
+               lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
                break;
 
        case cmd_subcmd_sleep_confirmed:
-               lbs_pr_debug(1, "PS command: SubCode- sleep confirm\n");
+               lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
                break;
 
        default:
                break;
        }
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_CMD);
        return 0;
 }
 
@@ -115,8 +109,7 @@ static int wlan_cmd_802_11_inactivity_timeout(wlan_private * priv,
        cmd->params.inactivity_timeout.action = cpu_to_le16(cmd_action);
 
        if (cmd_action)
-               cmd->params.inactivity_timeout.timeout =
-                   cpu_to_le16(*timeout);
+               cmd->params.inactivity_timeout.timeout = cpu_to_le16(*timeout);
        else
                cmd->params.inactivity_timeout.timeout = 0;
 
@@ -130,11 +123,10 @@ static int wlan_cmd_802_11_sleep_params(wlan_private * priv,
        wlan_adapter *adapter = priv->adapter;
        struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
-       cmd->size =
-           cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
-                            S_DS_GEN);
+       cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
+                               S_DS_GEN);
        cmd->command = cpu_to_le16(cmd_802_11_sleep_params);
 
        if (cmd_action == cmd_act_get) {
@@ -151,7 +143,7 @@ static int wlan_cmd_802_11_sleep_params(wlan_private * priv,
                sp->reserved = cpu_to_le16(adapter->sp.sp_reserved);
        }
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_CMD);
        return 0;
 }
 
@@ -165,17 +157,16 @@ static int wlan_cmd_802_11_set_wep(wlan_private * priv,
        int ret = 0;
        struct assoc_request * assoc_req = pdata_buf;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        cmd->command = cpu_to_le16(cmd_802_11_set_wep);
-       cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_set_wep))
-                                    + S_DS_GEN);
+       cmd->size = cpu_to_le16(sizeof(*wep) + S_DS_GEN);
 
        if (cmd_act == cmd_act_add) {
                int i;
 
                if (!assoc_req) {
-                       lbs_pr_debug(1, "Invalid association request!");
+                       lbs_deb_cmd("Invalid association request!");
                        ret = -1;
                        goto done;
                }
@@ -183,11 +174,10 @@ static int wlan_cmd_802_11_set_wep(wlan_private * priv,
                wep->action = cpu_to_le16(cmd_act_add);
 
                /* default tx key index */
-               wep->keyindex = cpu_to_le16((u16)
-                                                (assoc_req->wep_tx_keyidx &
-                                                (u32)cmd_WEP_KEY_INDEX_MASK));
+               wep->keyindex = cpu_to_le16((u16)(assoc_req->wep_tx_keyidx &
+                                                 (u32)cmd_WEP_KEY_INDEX_MASK));
 
-               lbs_pr_debug(1, "Tx key Index: %u\n", wep->keyindex);
+               lbs_deb_cmd("Tx key Index: %u\n", le16_to_cpu(wep->keyindex));
 
                /* Copy key types and material to host command structure */
                for (i = 0; i < 4; i++) {
@@ -195,19 +185,21 @@ static int wlan_cmd_802_11_set_wep(wlan_private * priv,
 
                        switch (pkey->len) {
                        case KEY_LEN_WEP_40:
-                               wep->keytype[i] = cmd_type_wep_40_bit;
+                               wep->keytype[i] =
+                                       cpu_to_le16(cmd_type_wep_40_bit);
                                memmove(&wep->keymaterial[i], pkey->key,
                                        pkey->len);
                                break;
                        case KEY_LEN_WEP_104:
-                               wep->keytype[i] = cmd_type_wep_104_bit;
+                               wep->keytype[i] =
+                                       cpu_to_le16(cmd_type_wep_104_bit);
                                memmove(&wep->keymaterial[i], pkey->key,
                                        pkey->len);
                                break;
                        case 0:
                                break;
                        default:
-                               lbs_pr_debug(1, "Invalid WEP key %d length of %d\n",
+                               lbs_deb_cmd("Invalid WEP key %d length of %d\n",
                                       i, pkey->len);
                                ret = -1;
                                goto done;
@@ -219,36 +211,37 @@ static int wlan_cmd_802_11_set_wep(wlan_private * priv,
                wep->action = cpu_to_le16(cmd_act_remove);
 
                /* default tx key index */
-               wep->keyindex = cpu_to_le16((u16)
-                                                (adapter->wep_tx_keyidx &
-                                                (u32)cmd_WEP_KEY_INDEX_MASK));
+               wep->keyindex = cpu_to_le16((u16)(adapter->wep_tx_keyidx &
+                                                 (u32)cmd_WEP_KEY_INDEX_MASK));
        }
 
        ret = 0;
 
 done:
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
        return ret;
 }
 
 static int wlan_cmd_802_11_enable_rsn(wlan_private * priv,
                                      struct cmd_ds_command *cmd,
-                                     u16 cmd_action)
+                                     u16 cmd_action,
+                                     void * pdata_buf)
 {
        struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn;
-       wlan_adapter *adapter = priv->adapter;
+       struct assoc_request * assoc_req = pdata_buf;
+
+       lbs_deb_enter(LBS_DEB_CMD);
 
        cmd->command = cpu_to_le16(cmd_802_11_enable_rsn);
-       cmd->size =
-           cpu_to_le16(sizeof(struct cmd_ds_802_11_enable_rsn) +
-                            S_DS_GEN);
+       cmd->size = cpu_to_le16(sizeof(*penableRSN) + S_DS_GEN);
        penableRSN->action = cpu_to_le16(cmd_action);
-       if (adapter->secinfo.WPAenabled || adapter->secinfo.WPA2enabled) {
+       if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
                penableRSN->enable = cpu_to_le16(cmd_enable_rsn);
        } else {
                penableRSN->enable = cpu_to_le16(cmd_disable_rsn);
        }
 
+       lbs_deb_leave(LBS_DEB_CMD);
        return 0;
 }
 
@@ -259,14 +252,12 @@ static void set_one_wpa_key(struct MrvlIEtype_keyParamSet * pkeyparamset,
        pkeyparamset->keytypeid = cpu_to_le16(pkey->type);
 
        if (pkey->flags & KEY_INFO_WPA_ENABLED) {
-               pkeyparamset->keyinfo = cpu_to_le16(KEY_INFO_WPA_ENABLED);
-       } else {
-               pkeyparamset->keyinfo = cpu_to_le16(!KEY_INFO_WPA_ENABLED);
+               pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
        }
-
        if (pkey->flags & KEY_INFO_WPA_UNICAST) {
                pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
-       } else if (pkey->flags & KEY_INFO_WPA_MCAST) {
+       }
+       if (pkey->flags & KEY_INFO_WPA_MCAST) {
                pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
        }
 
@@ -284,46 +275,45 @@ static int wlan_cmd_802_11_key_material(wlan_private * priv,
                                        u16 cmd_action,
                                        u32 cmd_oid, void *pdata_buf)
 {
-       wlan_adapter *adapter = priv->adapter;
        struct cmd_ds_802_11_key_material *pkeymaterial =
            &cmd->params.keymaterial;
+       struct assoc_request * assoc_req = pdata_buf;
        int ret = 0;
        int index = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        cmd->command = cpu_to_le16(cmd_802_11_key_material);
        pkeymaterial->action = cpu_to_le16(cmd_action);
 
        if (cmd_action == cmd_act_get) {
-               cmd->size = cpu_to_le16(  S_DS_GEN
-                                            + sizeof (pkeymaterial->action));
+               cmd->size = cpu_to_le16(S_DS_GEN + sizeof (pkeymaterial->action));
                ret = 0;
                goto done;
        }
 
        memset(&pkeymaterial->keyParamSet, 0, sizeof(pkeymaterial->keyParamSet));
 
-       if (adapter->wpa_unicast_key.len) {
+       if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
                set_one_wpa_key(&pkeymaterial->keyParamSet[index],
-                               &adapter->wpa_unicast_key);
+                               &assoc_req->wpa_unicast_key);
                index++;
        }
 
-       if (adapter->wpa_mcast_key.len) {
+       if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
                set_one_wpa_key(&pkeymaterial->keyParamSet[index],
-                               &adapter->wpa_mcast_key);
+                               &assoc_req->wpa_mcast_key);
                index++;
        }
 
        cmd->size = cpu_to_le16(  S_DS_GEN
-                                    + sizeof (pkeymaterial->action)
-                                    + index * sizeof(struct MrvlIEtype_keyParamSet));
+                               + sizeof (pkeymaterial->action)
+                               + (index * sizeof(struct MrvlIEtype_keyParamSet)));
 
        ret = 0;
 
 done:
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
        return ret;
 }
 
@@ -354,8 +344,7 @@ static int wlan_cmd_802_11_get_stat(wlan_private * priv,
 {
        cmd->command = cpu_to_le16(cmd_802_11_get_stat);
        cmd->size =
-           cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) +
-                            S_DS_GEN);
+           cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) + S_DS_GEN);
 
        return 0;
 }
@@ -369,14 +358,12 @@ static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
        wlan_adapter *adapter = priv->adapter;
        u8 ucTemp;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
-       lbs_pr_debug(1, "SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
+       lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
 
        cmd->command = cpu_to_le16(cmd_802_11_snmp_mib);
-       cmd->size =
-           cpu_to_le16(sizeof(struct cmd_ds_802_11_snmp_mib) +
-                            S_DS_GEN);
+       cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN);
 
        switch (cmd_oid) {
        case OID_802_11_INFRASTRUCTURE_MODE:
@@ -407,7 +394,7 @@ static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
                                pSNMPMIB->querytype = cmd_act_set;
                                pSNMPMIB->bufsize = sizeof(u16);
                                ulTemp = *(u32 *)pdata_buf;
-                               *((unsigned short *)(pSNMPMIB->value)) =
+                               *((__le16 *)(pSNMPMIB->value)) =
                                    cpu_to_le16((u16) ulTemp);
                        }
                        break;
@@ -420,15 +407,12 @@ static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
                        pSNMPMIB->oid = cpu_to_le16((u16) fragthresh_i);
 
                        if (cmd_action == cmd_act_get) {
-                               pSNMPMIB->querytype =
-                                   cpu_to_le16(cmd_act_get);
+                               pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
                        } else if (cmd_action == cmd_act_set) {
-                               pSNMPMIB->querytype =
-                                   cpu_to_le16(cmd_act_set);
-                               pSNMPMIB->bufsize =
-                                   cpu_to_le16(sizeof(u16));
+                               pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
+                               pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
                                ulTemp = *((u32 *) pdata_buf);
-                               *((unsigned short *)(pSNMPMIB->value)) =
+                               *((__le16 *)(pSNMPMIB->value)) =
                                    cpu_to_le16((u16) ulTemp);
 
                        }
@@ -443,16 +427,12 @@ static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
                        pSNMPMIB->oid = le16_to_cpu((u16) rtsthresh_i);
 
                        if (cmd_action == cmd_act_get) {
-                               pSNMPMIB->querytype =
-                                   cpu_to_le16(cmd_act_get);
+                               pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
                        } else if (cmd_action == cmd_act_set) {
-                               pSNMPMIB->querytype =
-                                   cpu_to_le16(cmd_act_set);
-                               pSNMPMIB->bufsize =
-                                   cpu_to_le16(sizeof(u16));
-                               ulTemp = *((u32 *)
-                                          pdata_buf);
-                               *(unsigned short *)(pSNMPMIB->value) =
+                               pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
+                               pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
+                               ulTemp = *((u32 *)pdata_buf);
+                               *(__le16 *)(pSNMPMIB->value) =
                                    cpu_to_le16((u16) ulTemp);
 
                        }
@@ -462,13 +442,11 @@ static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
                pSNMPMIB->oid = cpu_to_le16((u16) short_retrylim_i);
 
                if (cmd_action == cmd_act_get) {
-                       pSNMPMIB->querytype =
-                           cpu_to_le16(cmd_act_get);
+                       pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
                } else if (cmd_action == cmd_act_set) {
-                       pSNMPMIB->querytype =
-                           cpu_to_le16(cmd_act_set);
+                       pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
                        pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
-                       *((unsigned short *)(pSNMPMIB->value)) =
+                       *((__le16 *)(pSNMPMIB->value)) =
                            cpu_to_le16((u16) adapter->txretrycount);
                }
 
@@ -477,16 +455,18 @@ static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
                break;
        }
 
-       lbs_pr_debug(1,
+       lbs_deb_cmd(
               "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
-              cmd->command, cmd->size, cmd->seqnum, cmd->result);
+              le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
+              le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result));
 
-       lbs_pr_debug(1,
+       lbs_deb_cmd(
               "SNMP_CMD: action=0x%x, oid=0x%x, oidsize=0x%x, value=0x%x\n",
-              pSNMPMIB->querytype, pSNMPMIB->oid, pSNMPMIB->bufsize,
-              *(u16 *) pSNMPMIB->value);
+              le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid),
+              le16_to_cpu(pSNMPMIB->bufsize),
+              le16_to_cpu(*(__le16 *) pSNMPMIB->value));
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_CMD);
        return 0;
 }
 
@@ -495,10 +475,9 @@ static int wlan_cmd_802_11_radio_control(wlan_private * priv,
                                         int cmd_action)
 {
        wlan_adapter *adapter = priv->adapter;
-       struct cmd_ds_802_11_radio_control *pradiocontrol =
-           &cmd->params.radio;
+       struct cmd_ds_802_11_radio_control *pradiocontrol = &cmd->params.radio;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        cmd->size =
            cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control)) +
@@ -527,7 +506,7 @@ static int wlan_cmd_802_11_radio_control(wlan_private * priv,
        else
                pradiocontrol->control &= cpu_to_le16(~TURN_ON_RF);
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_CMD);
        return 0;
 }
 
@@ -538,16 +517,16 @@ static int wlan_cmd_802_11_rf_tx_power(wlan_private * priv,
 
        struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        cmd->size =
-           cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) +
-                            S_DS_GEN);
+           cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
        cmd->command = cpu_to_le16(cmd_802_11_rf_tx_power);
-       prtp->action = cmd_action;
+       prtp->action = cpu_to_le16(cmd_action);
 
-       lbs_pr_debug(1, "RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n", cmd->size,
-              cmd->command, prtp->action);
+       lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
+                   le16_to_cpu(cmd->size), le16_to_cpu(cmd->command),
+                   le16_to_cpu(prtp->action));
 
        switch (cmd_action) {
        case cmd_act_tx_power_opt_get:
@@ -557,14 +536,12 @@ static int wlan_cmd_802_11_rf_tx_power(wlan_private * priv,
 
        case cmd_act_tx_power_opt_set_high:
                prtp->action = cpu_to_le16(cmd_act_set);
-               prtp->currentlevel =
-                   cpu_to_le16(cmd_act_tx_power_index_high);
+               prtp->currentlevel = cpu_to_le16(cmd_act_tx_power_index_high);
                break;
 
        case cmd_act_tx_power_opt_set_mid:
                prtp->action = cpu_to_le16(cmd_act_set);
-               prtp->currentlevel =
-                   cpu_to_le16(cmd_act_tx_power_index_mid);
+               prtp->currentlevel = cpu_to_le16(cmd_act_tx_power_index_mid);
                break;
 
        case cmd_act_tx_power_opt_set_low:
@@ -572,7 +549,8 @@ static int wlan_cmd_802_11_rf_tx_power(wlan_private * priv,
                prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
                break;
        }
-       LEAVE();
+
+       lbs_deb_leave(LBS_DEB_CMD);
        return 0;
 }
 
@@ -583,15 +561,12 @@ static int wlan_cmd_802_11_rf_antenna(wlan_private * priv,
        struct cmd_ds_802_11_rf_antenna *rant = &cmd->params.rant;
 
        cmd->command = cpu_to_le16(cmd_802_11_rf_antenna);
-       cmd->size =
-           cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_antenna) +
-                            S_DS_GEN);
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_antenna) +
+                               S_DS_GEN);
 
        rant->action = cpu_to_le16(cmd_action);
-       if ((cmd_action == cmd_act_set_rx) ||
-           (cmd_action == cmd_act_set_tx)) {
-               rant->antennamode =
-                   cpu_to_le16((u16) (*(u32 *) pdata_buf));
+       if ((cmd_action == cmd_act_set_rx) || (cmd_action == cmd_act_set_tx)) {
+               rant->antennamode = cpu_to_le16((u16) (*(u32 *) pdata_buf));
        }
 
        return 0;
@@ -610,13 +585,13 @@ static int wlan_cmd_802_11_rate_adapt_rateset(wlan_private * priv,
                             + S_DS_GEN);
        cmd->command = cpu_to_le16(cmd_802_11_rate_adapt_rateset);
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
-       rateadapt->action = cmd_action;
-       rateadapt->enablehwauto = adapter->enablehwauto;
-       rateadapt->bitmap = adapter->ratebitmap;
+       rateadapt->action = cpu_to_le16(cmd_action);
+       rateadapt->enablehwauto = cpu_to_le16(adapter->enablehwauto);
+       rateadapt->bitmap = cpu_to_le16(adapter->ratebitmap);
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_CMD);
        return 0;
 }
 
@@ -626,12 +601,10 @@ static int wlan_cmd_802_11_data_rate(wlan_private * priv,
 {
        struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
        wlan_adapter *adapter = priv->adapter;
-       u16 action = cmd_action;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
-       cmd->size =
-           cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
                             S_DS_GEN);
 
        cmd->command = cpu_to_le16(cmd_802_11_data_rate);
@@ -640,15 +613,15 @@ static int wlan_cmd_802_11_data_rate(wlan_private * priv,
 
        pdatarate->action = cpu_to_le16(cmd_action);
 
-       if (action == cmd_act_set_tx_fix_rate) {
+       if (cmd_action == cmd_act_set_tx_fix_rate) {
                pdatarate->datarate[0] = libertas_data_rate_to_index(adapter->datarate);
-               lbs_pr_debug(1, "Setting FW for fixed rate 0x%02X\n",
+               lbs_deb_cmd("Setting FW for fixed rate 0x%02X\n",
                       adapter->datarate);
-       } else if (action == cmd_act_set_tx_auto) {
-               lbs_pr_debug(1, "Setting FW for AUTO rate\n");
+       } else if (cmd_action == cmd_act_set_tx_auto) {
+               lbs_deb_cmd("Setting FW for AUTO rate\n");
        }
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_CMD);
        return 0;
 }
 
@@ -659,8 +632,7 @@ static int wlan_cmd_mac_multicast_adr(wlan_private * priv,
        struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
        wlan_adapter *adapter = priv->adapter;
 
-       cmd->size =
-           cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
                             S_DS_GEN);
        cmd->command = cpu_to_le16(cmd_mac_multicast_adr);
 
@@ -680,8 +652,8 @@ static int wlan_cmd_802_11_rf_channel(wlan_private * priv,
        struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
 
        cmd->command = cpu_to_le16(cmd_802_11_rf_channel);
-       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel)
-                                    + S_DS_GEN);
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel) +
+                               S_DS_GEN);
 
        if (option == cmd_opt_802_11_rf_channel_set) {
                rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
@@ -698,9 +670,8 @@ static int wlan_cmd_802_11_rssi(wlan_private * priv,
        wlan_adapter *adapter = priv->adapter;
 
        cmd->command = cpu_to_le16(cmd_802_11_rssi);
-       cmd->size =
-           cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
-       cmd->params.rssi.N = priv->adapter->bcn_avg_factor;
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
+       cmd->params.rssi.N = cpu_to_le16(priv->adapter->bcn_avg_factor);
 
        /* reset Beacon SNR/NF/RSSI values */
        adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
@@ -719,7 +690,7 @@ static int wlan_cmd_reg_access(wlan_private * priv,
 {
        struct wlan_offset_value *offval;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        offval = (struct wlan_offset_value *)pdata_buf;
 
@@ -729,9 +700,8 @@ static int wlan_cmd_reg_access(wlan_private * priv,
                        struct cmd_ds_mac_reg_access *macreg;
 
                        cmdptr->size =
-                           cpu_to_le16(sizeof
-                                            (struct cmd_ds_mac_reg_access)
-                                            + S_DS_GEN);
+                           cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
+                                       + S_DS_GEN);
                        macreg =
                            (struct cmd_ds_mac_reg_access *)&cmdptr->params.
                            macreg;
@@ -785,7 +755,7 @@ static int wlan_cmd_reg_access(wlan_private * priv,
                break;
        }
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_CMD);
        return 0;
 }
 
@@ -796,8 +766,7 @@ static int wlan_cmd_802_11_mac_address(wlan_private * priv,
        wlan_adapter *adapter = priv->adapter;
 
        cmd->command = cpu_to_le16(cmd_802_11_mac_address);
-       cmd->size =
-           cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
                             S_DS_GEN);
        cmd->result = 0;
 
@@ -818,12 +787,11 @@ static int wlan_cmd_802_11_eeprom_access(wlan_private * priv,
 {
        struct wlan_ioctl_regrdwr *ea = pdata_buf;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        cmd->command = cpu_to_le16(cmd_802_11_eeprom_access);
-       cmd->size =
-           cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
-                            S_DS_GEN);
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
+                               S_DS_GEN);
        cmd->result = 0;
 
        cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
@@ -839,11 +807,10 @@ static int wlan_cmd_bt_access(wlan_private * priv,
                               u16 cmd_action, void *pdata_buf)
 {
        struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
-       lbs_pr_debug(1, "BT CMD(%d)\n", cmd_action);
+       lbs_deb_cmd("BT CMD(%d)\n", cmd_action);
 
        cmd->command = cpu_to_le16(cmd_bt_access);
-       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access)
-                                    + S_DS_GEN);
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
        cmd->result = 0;
        bt_access->action = cpu_to_le16(cmd_action);
 
@@ -861,6 +828,11 @@ static int wlan_cmd_bt_access(wlan_private * priv,
                break;
        case cmd_act_bt_access_reset:
                break;
+       case cmd_act_bt_access_set_invert:
+               bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
+               break;
+       case cmd_act_bt_access_get_invert:
+               break;
        default:
                break;
        }
@@ -872,11 +844,10 @@ static int wlan_cmd_fwt_access(wlan_private * priv,
                               u16 cmd_action, void *pdata_buf)
 {
        struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
-       lbs_pr_debug(1, "FWT CMD(%d)\n", cmd_action);
+       lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
 
        cmd->command = cpu_to_le16(cmd_fwt_access);
-       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access)
-                                    + S_DS_GEN);
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
        cmd->result = 0;
 
        if (pdata_buf)
@@ -894,11 +865,10 @@ static int wlan_cmd_mesh_access(wlan_private * priv,
                                u16 cmd_action, void *pdata_buf)
 {
        struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
-       lbs_pr_debug(1, "FWT CMD(%d)\n", cmd_action);
+       lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
 
        cmd->command = cpu_to_le16(cmd_mesh_access);
-       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access)
-                                    + S_DS_GEN);
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access) + S_DS_GEN);
        cmd->result = 0;
 
        if (pdata_buf)
@@ -916,23 +886,23 @@ void libertas_queue_cmd(wlan_adapter * adapter, struct cmd_ctrl_node *cmdnode, u
        unsigned long flags;
        struct cmd_ds_command *cmdptr;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        if (!cmdnode) {
-               lbs_pr_debug(1, "QUEUE_CMD: cmdnode is NULL\n");
+               lbs_deb_cmd("QUEUE_CMD: cmdnode is NULL\n");
                goto done;
        }
 
        cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
        if (!cmdptr) {
-               lbs_pr_debug(1, "QUEUE_CMD: cmdptr is NULL\n");
+               lbs_deb_cmd("QUEUE_CMD: cmdptr is NULL\n");
                goto done;
        }
 
        /* Exit_PS command needs to be queued in the header always. */
        if (cmdptr->command == cmd_802_11_ps_mode) {
                struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
-               if (psm->action == cmd_subcmd_exit_ps) {
+               if (psm->action == cpu_to_le16(cmd_subcmd_exit_ps)) {
                        if (adapter->psstate != PS_STATE_FULL_POWER)
                                addtail = 0;
                }
@@ -948,13 +918,12 @@ void libertas_queue_cmd(wlan_adapter * adapter, struct cmd_ctrl_node *cmdnode, u
 
        spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
-       lbs_pr_debug(1, "QUEUE_CMD: Inserted node=%p, cmd=0x%x in cmdpendingq\n",
+       lbs_deb_cmd("QUEUE_CMD: Inserted node=%p, cmd=0x%x in cmdpendingq\n",
               cmdnode,
-              ((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command);
+              le16_to_cpu(((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command));
 
 done:
-       LEAVE();
-       return;
+       lbs_deb_leave(LBS_DEB_CMD);
 }
 
 /*
@@ -974,10 +943,10 @@ static int DownloadcommandToStation(wlan_private * priv,
        u16 cmdsize;
        u16 command;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        if (!adapter || !cmdnode) {
-               lbs_pr_debug(1, "DNLD_CMD: adapter = %p, cmdnode = %p\n",
+               lbs_deb_cmd("DNLD_CMD: adapter = %p, cmdnode = %p\n",
                       adapter, cmdnode);
                if (cmdnode) {
                        spin_lock_irqsave(&adapter->driver_lock, flags);
@@ -993,7 +962,7 @@ static int DownloadcommandToStation(wlan_private * priv,
 
        spin_lock_irqsave(&adapter->driver_lock, flags);
        if (!cmdptr || !cmdptr->size) {
-               lbs_pr_debug(1, "DNLD_CMD: cmdptr is Null or cmd size is Zero, "
+               lbs_deb_cmd("DNLD_CMD: cmdptr is Null or cmd size is Zero, "
                       "Not sending\n");
                __libertas_cleanup_and_insert_cmd(priv, cmdnode);
                spin_unlock_irqrestore(&adapter->driver_lock, flags);
@@ -1004,8 +973,8 @@ static int DownloadcommandToStation(wlan_private * priv,
        adapter->cur_cmd = cmdnode;
        adapter->cur_cmd_retcode = 0;
        spin_unlock_irqrestore(&adapter->driver_lock, flags);
-       lbs_pr_debug(1, "DNLD_CMD:: Before download, size of cmd = %d\n",
-              cmdptr->size);
+       lbs_deb_cmd("DNLD_CMD:: Before download, size of cmd = %d\n",
+                   le16_to_cpu(cmdptr->size));
 
        cmdsize = cmdptr->size;
 
@@ -1014,10 +983,10 @@ static int DownloadcommandToStation(wlan_private * priv,
        cmdnode->cmdwaitqwoken = 0;
        cmdsize = cpu_to_le16(cmdsize);
 
-       ret = libertas_sbi_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
+       ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
 
        if (ret != 0) {
-               lbs_pr_debug(1, "DNLD_CMD: Host to Card failed\n");
+               lbs_deb_cmd("DNLD_CMD: Host to Card failed\n");
                spin_lock_irqsave(&adapter->driver_lock, flags);
                __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
                adapter->cur_cmd = NULL;
@@ -1026,12 +995,11 @@ static int DownloadcommandToStation(wlan_private * priv,
                goto done;
        }
 
-       lbs_pr_debug(1, "DNLD_CMD: Sent command 0x%x @ %lu\n", command, jiffies);
+       lbs_deb_cmd("DNLD_CMD: Sent command 0x%x @ %lu\n", command, jiffies);
        lbs_dbg_hex("DNLD_CMD: command", cmdnode->bufvirtualaddr, cmdsize);
 
        /* Setup the timer after transmit command */
-       if (command == cmd_802_11_scan
-           || command == cmd_802_11_authenticate
+       if (command == cmd_802_11_scan || command == cmd_802_11_authenticate
            || command == cmd_802_11_associate)
                mod_timer(&adapter->command_timer, jiffies + (10*HZ));
        else
@@ -1039,8 +1007,8 @@ static int DownloadcommandToStation(wlan_private * priv,
 
        ret = 0;
 
-      done:
-       LEAVE();
+done:
+       lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
        return ret;
 }
 
@@ -1049,17 +1017,16 @@ static int wlan_cmd_mac_control(wlan_private * priv,
 {
        struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        cmd->command = cpu_to_le16(cmd_mac_control);
-       cmd->size =
-           cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
        mac->action = cpu_to_le16(priv->adapter->currentpacketfilter);
 
-       lbs_pr_debug(1, "wlan_cmd_mac_control(): action=0x%X size=%d\n",
-              mac->action, cmd->size);
+       lbs_deb_cmd("wlan_cmd_mac_control(): action=0x%X size=%d\n",
+                   le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_CMD);
        return 0;
 }
 
@@ -1093,17 +1060,17 @@ int libertas_set_radio_control(wlan_private * priv)
 {
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        ret = libertas_prepare_and_send_command(priv,
                                    cmd_802_11_radio_control,
                                    cmd_act_set,
                                    cmd_option_waitforrsp, 0, NULL);
 
-       lbs_pr_debug(1, "RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
+       lbs_deb_cmd("RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
               priv->adapter->radioon, priv->adapter->preamble);
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
        return ret;
 }
 
@@ -1111,16 +1078,16 @@ int libertas_set_mac_packet_filter(wlan_private * priv)
 {
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
-       lbs_pr_debug(1, "libertas_set_mac_packet_filter value = %x\n",
+       lbs_deb_cmd("libertas_set_mac_packet_filter value = %x\n",
               priv->adapter->currentpacketfilter);
 
        /* Send MAC control command to station */
        ret = libertas_prepare_and_send_command(priv,
                                    cmd_mac_control, 0, 0, 0, NULL);
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
        return ret;
 }
 
@@ -1146,16 +1113,16 @@ int libertas_prepare_and_send_command(wlan_private * priv,
        struct cmd_ds_command *cmdptr;
        unsigned long flags;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        if (!adapter) {
-               lbs_pr_debug(1, "PREP_CMD: adapter is Null\n");
+               lbs_deb_cmd("PREP_CMD: adapter is Null\n");
                ret = -1;
                goto done;
        }
 
        if (adapter->surpriseremoved) {
-               lbs_pr_debug(1, "PREP_CMD: Card is Removed\n");
+               lbs_deb_cmd("PREP_CMD: Card is Removed\n");
                ret = -1;
                goto done;
        }
@@ -1163,7 +1130,7 @@ int libertas_prepare_and_send_command(wlan_private * priv,
        cmdnode = libertas_get_free_cmd_ctrl_node(priv);
 
        if (cmdnode == NULL) {
-               lbs_pr_debug(1, "PREP_CMD: No free cmdnode\n");
+               lbs_deb_cmd("PREP_CMD: No free cmdnode\n");
 
                /* Wake up main thread to execute next command */
                wake_up_interruptible(&priv->mainthread.waitq);
@@ -1175,11 +1142,11 @@ int libertas_prepare_and_send_command(wlan_private * priv,
 
        cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
 
-       lbs_pr_debug(1, "PREP_CMD: Val of cmd ptr=%p, command=0x%X\n",
+       lbs_deb_cmd("PREP_CMD: Val of cmd ptr=%p, command=0x%X\n",
               cmdptr, cmd_no);
 
        if (!cmdptr) {
-               lbs_pr_debug(1, "PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
+               lbs_deb_cmd("PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
                libertas_cleanup_and_insert_cmd(priv, cmdnode);
                ret = -1;
                goto done;
@@ -1189,7 +1156,7 @@ int libertas_prepare_and_send_command(wlan_private * priv,
        adapter->seqnum++;
        cmdptr->seqnum = cpu_to_le16(adapter->seqnum);
 
-       cmdptr->command = cmd_no;
+       cmdptr->command = cpu_to_le16(cmd_no);
        cmdptr->result = 0;
 
        switch (cmd_no) {
@@ -1298,13 +1265,13 @@ int libertas_prepare_and_send_command(wlan_private * priv,
                break;
 
        case cmd_802_11_enable_rsn:
-               ret = wlan_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action);
+               ret = wlan_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action,
+                               pdata_buf);
                break;
 
        case cmd_802_11_key_material:
-               ret = wlan_cmd_802_11_key_material(priv, cmdptr,
-                                                  cmd_action, cmd_oid,
-                                                  pdata_buf);
+               ret = wlan_cmd_802_11_key_material(priv, cmdptr, cmd_action,
+                               cmd_oid, pdata_buf);
                break;
 
        case cmd_802_11_pairwise_tsc:
@@ -1325,9 +1292,8 @@ int libertas_prepare_and_send_command(wlan_private * priv,
        case cmd_802_11_get_afc:
 
                cmdptr->command = cpu_to_le16(cmd_no);
-               cmdptr->size =
-                   cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
-                                    S_DS_GEN);
+               cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
+                                          S_DS_GEN);
 
                memmove(&cmdptr->params.afc,
                        pdata_buf, sizeof(struct cmd_ds_802_11_afc));
@@ -1406,29 +1372,26 @@ int libertas_prepare_and_send_command(wlan_private * priv,
 
        case cmd_get_tsf:
                cmdptr->command = cpu_to_le16(cmd_get_tsf);
-               cmdptr->size =
-                   cpu_to_le16(sizeof(struct cmd_ds_get_tsf)
-                                    + S_DS_GEN);
+               cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
+                                          S_DS_GEN);
                ret = 0;
                break;
        case cmd_802_11_tx_rate_query:
-               cmdptr->command =
-                   cpu_to_le16(cmd_802_11_tx_rate_query);
-               cmdptr->size =
-                   cpu_to_le16(sizeof(struct cmd_tx_rate_query) +
-                                    S_DS_GEN);
+               cmdptr->command = cpu_to_le16(cmd_802_11_tx_rate_query);
+               cmdptr->size = cpu_to_le16(sizeof(struct cmd_tx_rate_query) +
+                                          S_DS_GEN);
                adapter->txrate = 0;
                ret = 0;
                break;
        default:
-               lbs_pr_debug(1, "PREP_CMD: unknown command- %#x\n", cmd_no);
+               lbs_deb_cmd("PREP_CMD: unknown command- %#x\n", cmd_no);
                ret = -1;
                break;
        }
 
        /* return error, since the command preparation failed */
        if (ret != 0) {
-               lbs_pr_debug(1, "PREP_CMD: command preparation failed\n");
+               lbs_deb_cmd("PREP_CMD: command preparation failed\n");
                libertas_cleanup_and_insert_cmd(priv, cmdnode);
                ret = -1;
                goto done;
@@ -1441,7 +1404,7 @@ int libertas_prepare_and_send_command(wlan_private * priv,
        wake_up_interruptible(&priv->mainthread.waitq);
 
        if (wait_option & cmd_option_waitforrsp) {
-               lbs_pr_debug(1, "PREP_CMD: Wait for CMD response\n");
+               lbs_deb_cmd("PREP_CMD: Wait for CMD response\n");
                might_sleep();
                wait_event_interruptible(cmdnode->cmdwait_q,
                                         cmdnode->cmdwaitqwoken);
@@ -1449,7 +1412,7 @@ int libertas_prepare_and_send_command(wlan_private * priv,
 
        spin_lock_irqsave(&adapter->driver_lock, flags);
        if (adapter->cur_cmd_retcode) {
-               lbs_pr_debug(1, "PREP_CMD: command failed with return code=%d\n",
+               lbs_deb_cmd("PREP_CMD: command failed with return code=%d\n",
                       adapter->cur_cmd_retcode);
                adapter->cur_cmd_retcode = 0;
                ret = -1;
@@ -1457,9 +1420,10 @@ int libertas_prepare_and_send_command(wlan_private * priv,
        spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
 done:
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
        return ret;
 }
+EXPORT_SYMBOL_GPL(libertas_prepare_and_send_command);
 
 /**
  *  @brief This function allocates the command buffer and link
@@ -1477,33 +1441,29 @@ int libertas_allocate_cmd_buffer(wlan_private * priv)
        u8 *ptempvirtualaddr;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        /* Allocate and initialize cmdCtrlNode */
        ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
 
-       if (!(tempcmd_array = kmalloc(ulbufsize, GFP_KERNEL))) {
-               lbs_pr_debug(1,
+       if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
+               lbs_deb_cmd(
                       "ALLOC_CMD_BUF: failed to allocate tempcmd_array\n");
                ret = -1;
                goto done;
        }
-
        adapter->cmd_array = tempcmd_array;
-       memset(adapter->cmd_array, 0, ulbufsize);
 
        /* Allocate and initialize command buffers */
        ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
        for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
-               if (!(ptempvirtualaddr = kmalloc(ulbufsize, GFP_KERNEL))) {
-                       lbs_pr_debug(1,
+               if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
+                       lbs_deb_cmd(
                               "ALLOC_CMD_BUF: ptempvirtualaddr: out of memory\n");
                        ret = -1;
                        goto done;
                }
 
-               memset(ptempvirtualaddr, 0, ulbufsize);
-
                /* Update command buffer virtual */
                tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
        }
@@ -1514,8 +1474,9 @@ int libertas_allocate_cmd_buffer(wlan_private * priv)
        }
 
        ret = 0;
-      done:
-       LEAVE();
+
+done:
+       lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
        return ret;
 }
 
@@ -1527,16 +1488,16 @@ int libertas_allocate_cmd_buffer(wlan_private * priv)
  */
 int libertas_free_cmd_buffer(wlan_private * priv)
 {
-       u32 ulbufsize;
+       u32 ulbufsize; /* Someone needs to die for this. Slowly and painfully */
        unsigned int i;
        struct cmd_ctrl_node *tempcmd_array;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        /* need to check if cmd array is allocated or not */
        if (adapter->cmd_array == NULL) {
-               lbs_pr_debug(1, "FREE_CMD_BUF: cmd_array is Null\n");
+               lbs_deb_cmd("FREE_CMD_BUF: cmd_array is Null\n");
                goto done;
        }
 
@@ -1546,7 +1507,7 @@ int libertas_free_cmd_buffer(wlan_private * priv)
        ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
        for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
                if (tempcmd_array[i].bufvirtualaddr) {
-                       lbs_pr_debug(1, "Free all the array\n");
+                       lbs_deb_cmd("Free all the array\n");
                        kfree(tempcmd_array[i].bufvirtualaddr);
                        tempcmd_array[i].bufvirtualaddr = NULL;
                }
@@ -1554,13 +1515,13 @@ int libertas_free_cmd_buffer(wlan_private * priv)
 
        /* Release cmd_ctrl_node */
        if (adapter->cmd_array) {
-               lbs_pr_debug(1, "Free cmd_array\n");
+               lbs_deb_cmd("Free cmd_array\n");
                kfree(adapter->cmd_array);
                adapter->cmd_array = NULL;
        }
 
 done:
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_CMD);
        return 0;
 }
 
@@ -1586,16 +1547,18 @@ struct cmd_ctrl_node *libertas_get_free_cmd_ctrl_node(wlan_private * priv)
                tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next;
                list_del((struct list_head *)tempnode);
        } else {
-               lbs_pr_debug(1, "GET_CMD_NODE: cmd_ctrl_node is not available\n");
+               lbs_deb_cmd("GET_CMD_NODE: cmd_ctrl_node is not available\n");
                tempnode = NULL;
        }
 
        spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
        if (tempnode) {
+               /*
                lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode available\n");
                lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode Address = %p\n",
                       tempnode);
+               */
                cleanup_cmdnode(tempnode);
        }
 
@@ -1638,7 +1601,7 @@ void libertas_set_cmd_ctrl_node(wlan_private * priv,
                    struct cmd_ctrl_node *ptempnode,
                    u32 cmd_oid, u16 wait_option, void *pdata_buf)
 {
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        if (!ptempnode)
                return;
@@ -1647,7 +1610,7 @@ void libertas_set_cmd_ctrl_node(wlan_private * priv,
        ptempnode->wait_option = wait_option;
        ptempnode->pdata_buf = pdata_buf;
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_CMD);
 }
 
 /**
@@ -1666,7 +1629,7 @@ int libertas_execute_next_command(wlan_private * priv)
        unsigned long flags;
        int ret = 0;
 
-       lbs_pr_debug(1, "libertas_execute_next_command\n");
+       lbs_deb_enter(LBS_DEB_CMD);
 
        spin_lock_irqsave(&adapter->driver_lock, flags);
 
@@ -1685,23 +1648,24 @@ int libertas_execute_next_command(wlan_private * priv)
        spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
        if (cmdnode) {
-               lbs_pr_debug(1,
+               lbs_deb_cmd(
                       "EXEC_NEXT_CMD: Got next command from cmdpendingq\n");
                cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
 
                if (is_command_allowed_in_ps(cmdptr->command)) {
-                       if ((adapter->psstate == PS_STATE_SLEEP)
-                           || (adapter->psstate == PS_STATE_PRE_SLEEP)
-                           ) {
-                               lbs_pr_debug(1,
+                       if ((adapter->psstate == PS_STATE_SLEEP) ||
+                           (adapter->psstate == PS_STATE_PRE_SLEEP)) {
+                               lbs_deb_cmd(
                                       "EXEC_NEXT_CMD: Cannot send cmd 0x%x in psstate %d\n",
-                                      cmdptr->command, adapter->psstate);
+                                      le16_to_cpu(cmdptr->command),
+                                      adapter->psstate);
                                ret = -1;
                                goto done;
                        }
-                       lbs_pr_debug(1, "EXEC_NEXT_CMD: OK to send command "
+                       lbs_deb_cmd("EXEC_NEXT_CMD: OK to send command "
                               "0x%x in psstate %d\n",
-                              cmdptr->command, adapter->psstate);
+                                   le16_to_cpu(cmdptr->command),
+                                   adapter->psstate);
                } else if (adapter->psstate != PS_STATE_FULL_POWER) {
                        /*
                         * 1. Non-PS command:
@@ -1737,12 +1701,12 @@ int libertas_execute_next_command(wlan_private * priv)
                                struct cmd_ds_802_11_ps_mode *psm =
                                    &cmdptr->params.psmode;
 
-                               lbs_pr_debug(1,
+                               lbs_deb_cmd(
                                       "EXEC_NEXT_CMD: PS cmd- action=0x%x\n",
                                       psm->action);
                                if (psm->action !=
                                    cpu_to_le16(cmd_subcmd_exit_ps)) {
-                                       lbs_pr_debug(1,
+                                       lbs_deb_cmd(
                                               "EXEC_NEXT_CMD: Ignore Enter PS cmd\n");
                                        list_del((struct list_head *)cmdnode);
                                        libertas_cleanup_and_insert_cmd(priv, cmdnode);
@@ -1751,10 +1715,9 @@ int libertas_execute_next_command(wlan_private * priv)
                                        goto done;
                                }
 
-                               if ((adapter->psstate == PS_STATE_SLEEP)
-                                   || (adapter->psstate == PS_STATE_PRE_SLEEP)
-                                   ) {
-                                       lbs_pr_debug(1,
+                               if ((adapter->psstate == PS_STATE_SLEEP) ||
+                                   (adapter->psstate == PS_STATE_PRE_SLEEP)) {
+                                       lbs_deb_cmd(
                                               "EXEC_NEXT_CMD: Ignore ExitPS cmd in sleep\n");
                                        list_del((struct list_head *)cmdnode);
                                        libertas_cleanup_and_insert_cmd(priv, cmdnode);
@@ -1764,13 +1727,13 @@ int libertas_execute_next_command(wlan_private * priv)
                                        goto done;
                                }
 
-                               lbs_pr_debug(1,
+                               lbs_deb_cmd(
                                       "EXEC_NEXT_CMD: Sending Exit_PS down...\n");
                        }
                }
                list_del((struct list_head *)cmdnode);
-               lbs_pr_debug(1, "EXEC_NEXT_CMD: Sending 0x%04X command\n",
-                      cmdptr->command);
+               lbs_deb_cmd("EXEC_NEXT_CMD: Sending 0x%04X command\n",
+                           le16_to_cpu(cmdptr->command));
                DownloadcommandToStation(priv, cmdnode);
        } else {
                /*
@@ -1780,18 +1743,18 @@ int libertas_execute_next_command(wlan_private * priv)
                if ((adapter->psmode != wlan802_11powermodecam) &&
                    (adapter->psstate == PS_STATE_FULL_POWER) &&
                    (adapter->connect_status == libertas_connected)) {
-                       if (adapter->secinfo.WPAenabled
-                           || adapter->secinfo.WPA2enabled) {
+                       if (adapter->secinfo.WPAenabled ||
+                           adapter->secinfo.WPA2enabled) {
                                /* check for valid WPA group keys */
-                               if (adapter->wpa_mcast_key.len
-                                   || adapter->wpa_unicast_key.len) {
-                                       lbs_pr_debug(1,
+                               if (adapter->wpa_mcast_key.len ||
+                                   adapter->wpa_unicast_key.len) {
+                                       lbs_deb_cmd(
                                               "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
                                               " go back to PS_SLEEP");
                                        libertas_ps_sleep(priv, 0);
                                }
                        } else {
-                               lbs_pr_debug(1,
+                               lbs_deb_cmd(
                                       "EXEC_NEXT_CMD: command PendQ is empty,"
                                       " go back to PS_SLEEP");
                                libertas_ps_sleep(priv, 0);
@@ -1801,6 +1764,7 @@ int libertas_execute_next_command(wlan_private * priv)
 
        ret = 0;
 done:
+       lbs_deb_leave(LBS_DEB_CMD);
        return ret;
 }
 
@@ -1809,7 +1773,7 @@ void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str)
        union iwreq_data iwrq;
        u8 buf[50];
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        memset(&iwrq, 0, sizeof(union iwreq_data));
        memset(buf, 0, sizeof(buf));
@@ -1819,15 +1783,13 @@ void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str)
        iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
 
        /* Send Event to upper layer */
-       lbs_pr_debug(1, "Event Indication string = %s\n",
-              (char *)buf);
-       lbs_pr_debug(1, "Event Indication String length = %d\n", iwrq.data.length);
+       lbs_deb_cmd("Event Indication string = %s\n", (char *)buf);
+       lbs_deb_cmd("Event Indication String length = %d\n", iwrq.data.length);
 
-       lbs_pr_debug(1, "Sending wireless event IWEVCUSTOM for %s\n", str);
-       wireless_send_event(priv->wlan_dev.netdev, IWEVCUSTOM, &iwrq, buf);
+       lbs_deb_cmd("Sending wireless event IWEVCUSTOM for %s\n", str);
+       wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
 
-       LEAVE();
-       return;
+       lbs_deb_leave(LBS_DEB_CMD);
 }
 
 static int sendconfirmsleep(wlan_private * priv, u8 * cmdptr, u16 size)
@@ -1836,19 +1798,19 @@ static int sendconfirmsleep(wlan_private * priv, u8 * cmdptr, u16 size)
        wlan_adapter *adapter = priv->adapter;
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
-       lbs_pr_debug(1, "SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
+       lbs_deb_cmd("SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
               size);
 
        lbs_dbg_hex("SEND_SLEEPC_CMD: Sleep confirm command", cmdptr, size);
 
-       ret = libertas_sbi_host_to_card(priv, MVMS_CMD, cmdptr, size);
-       priv->wlan_dev.dnld_sent = DNLD_RES_RECEIVED;
+       ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
+       priv->dnld_sent = DNLD_RES_RECEIVED;
 
        spin_lock_irqsave(&adapter->driver_lock, flags);
        if (adapter->intcounter || adapter->currenttxskb)
-               lbs_pr_debug(1, "SEND_SLEEPC_CMD: intcounter=%d currenttxskb=%p\n",
+               lbs_deb_cmd("SEND_SLEEPC_CMD: intcounter=%d currenttxskb=%p\n",
                       adapter->intcounter, adapter->currenttxskb);
        spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
@@ -1860,23 +1822,22 @@ static int sendconfirmsleep(wlan_private * priv, u8 * cmdptr, u16 size)
                if (!adapter->intcounter) {
                        adapter->psstate = PS_STATE_SLEEP;
                } else {
-                       lbs_pr_debug(1, "SEND_SLEEPC_CMD: After sent,IntC=%d\n",
+                       lbs_deb_cmd("SEND_SLEEPC_CMD: After sent,IntC=%d\n",
                               adapter->intcounter);
                }
                spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
-               lbs_pr_debug(1, "SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
-               lbs_pr_debug(1, "+");
+               lbs_deb_cmd("SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
+               lbs_deb_cmd("+");
        }
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
        return ret;
 }
 
 void libertas_ps_sleep(wlan_private * priv, int wait_option)
 {
-
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        /*
         * PS is currently supported only in Infrastructure mode
@@ -1886,8 +1847,7 @@ void libertas_ps_sleep(wlan_private * priv, int wait_option)
        libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
                              cmd_subcmd_enter_ps, wait_option, 0, NULL);
 
-       LEAVE();
-       return;
+       lbs_deb_leave(LBS_DEB_CMD);
 }
 
 /**
@@ -1899,20 +1859,19 @@ void libertas_ps_sleep(wlan_private * priv, int wait_option)
  */
 void libertas_ps_wakeup(wlan_private * priv, int wait_option)
 {
-       enum WLAN_802_11_POWER_MODE Localpsmode;
+       __le32 Localpsmode;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
-       Localpsmode = wlan802_11powermodecam;
+       Localpsmode = cpu_to_le32(wlan802_11powermodecam);
 
-       lbs_pr_debug(1, "Exit_PS: Localpsmode = %d\n", Localpsmode);
+       lbs_deb_cmd("Exit_PS: Localpsmode = %d\n", wlan802_11powermodecam);
 
        libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
                              cmd_subcmd_exit_ps,
                              wait_option, 0, &Localpsmode);
 
-       LEAVE();
-       return;
+       lbs_deb_leave(LBS_DEB_CMD);
 }
 
 /**
@@ -1929,31 +1888,31 @@ void libertas_ps_confirm_sleep(wlan_private * priv, u16 psmode)
        wlan_adapter *adapter = priv->adapter;
        u8 allowed = 1;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
-       if (priv->wlan_dev.dnld_sent) {
+       if (priv->dnld_sent) {
                allowed = 0;
-               lbs_pr_debug(1, "D");
+               lbs_deb_cmd("D");
        }
 
        spin_lock_irqsave(&adapter->driver_lock, flags);
        if (adapter->cur_cmd) {
                allowed = 0;
-               lbs_pr_debug(1, "C");
+               lbs_deb_cmd("C");
        }
        if (adapter->intcounter > 0) {
                allowed = 0;
-               lbs_pr_debug(1, "I%d", adapter->intcounter);
+               lbs_deb_cmd("I%d", adapter->intcounter);
        }
        spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
        if (allowed) {
-               lbs_pr_debug(1, "Sending libertas_ps_confirm_sleep\n");
+               lbs_deb_cmd("Sending libertas_ps_confirm_sleep\n");
                sendconfirmsleep(priv, (u8 *) & adapter->libertas_ps_confirm_sleep,
                                 sizeof(struct PS_CMD_ConfirmSleep));
        } else {
-               lbs_pr_debug(1, "Sleep Confirm has been delayed\n");
+               lbs_deb_cmd("Sleep Confirm has been delayed\n");
        }
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_CMD);
 }
index c86454034b5839c64dd9a40f92d07c8c928b6aac..0c3b9a583d83cab84b4d44eb5e0d625a59b3f9d5 100644 (file)
@@ -9,7 +9,6 @@
 #include <net/iw_handler.h>
 
 #include "host.h"
-#include "sbi.h"
 #include "decl.h"
 #include "defs.h"
 #include "dev.h"
@@ -32,7 +31,7 @@ void libertas_mac_event_disconnected(wlan_private * priv)
        if (adapter->connect_status != libertas_connected)
                return;
 
-       lbs_pr_debug(1, "Handles disconnect event.\n");
+       lbs_deb_cmd("Handles disconnect event.\n");
 
        memset(wrqu.ap_addr.sa_data, 0x00, ETH_ALEN);
        wrqu.ap_addr.sa_family = ARPHRD_ETHER;
@@ -43,15 +42,15 @@ void libertas_mac_event_disconnected(wlan_private * priv)
         */
 
        msleep_interruptible(1000);
-       wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL);
+       wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
 
        /* Free Tx and Rx packets */
        kfree_skb(priv->adapter->currenttxskb);
        priv->adapter->currenttxskb = NULL;
 
        /* report disconnect to upper layer */
-       netif_stop_queue(priv->wlan_dev.netdev);
-       netif_carrier_off(priv->wlan_dev.netdev);
+       netif_stop_queue(priv->dev);
+       netif_carrier_off(priv->dev);
 
        /* reset SNR/NF/RSSI values */
        memset(adapter->SNR, 0x00, sizeof(adapter->SNR));
@@ -62,35 +61,32 @@ void libertas_mac_event_disconnected(wlan_private * priv)
        adapter->nextSNRNF = 0;
        adapter->numSNRNF = 0;
        adapter->rxpd_rate = 0;
-       lbs_pr_debug(1, "Current SSID=%s, ssid length=%u\n",
-              adapter->curbssparams.ssid.ssid,
-              adapter->curbssparams.ssid.ssidlength);
-       lbs_pr_debug(1, "Previous SSID=%s, ssid length=%u\n",
-              adapter->previousssid.ssid, adapter->previousssid.ssidlength);
-
-       /* reset internal flags */
-       adapter->secinfo.WPAenabled = 0;
-       adapter->secinfo.WPA2enabled = 0;
-       adapter->wpa_ie_len = 0;
+       lbs_deb_cmd("Current SSID='%s', ssid length=%u\n",
+                   escape_essid(adapter->curbssparams.ssid,
+                                adapter->curbssparams.ssid_len),
+                   adapter->curbssparams.ssid_len);
+       lbs_deb_cmd("Previous SSID='%s', ssid length=%u\n",
+                   escape_essid(adapter->prev_ssid, adapter->prev_ssid_len),
+                   adapter->prev_ssid_len);
 
        adapter->connect_status = libertas_disconnected;
 
-       /*
-        * memorize the previous SSID and BSSID
-        * it could be used for re-assoc
-        */
-       memcpy(&adapter->previousssid,
-              &adapter->curbssparams.ssid, sizeof(struct WLAN_802_11_SSID));
-       memcpy(adapter->previousbssid,
-              adapter->curbssparams.bssid, ETH_ALEN);
+       /* Save previous SSID and BSSID for possible reassociation */
+       memcpy(&adapter->prev_ssid, &adapter->curbssparams.ssid,
+              IW_ESSID_MAX_SIZE);
+       adapter->prev_ssid_len = adapter->curbssparams.ssid_len;
+       memcpy(adapter->prev_bssid, adapter->curbssparams.bssid, ETH_ALEN);
 
-       /* need to erase the current SSID and BSSID info */
-       adapter->pattemptedbssdesc = NULL;
-       memset(&adapter->curbssparams, 0, sizeof(adapter->curbssparams));
+       /* Clear out associated SSID and BSSID since connection is
+        * no longer valid.
+        */
+       memset(&adapter->curbssparams.bssid, 0, ETH_ALEN);
+       memset(&adapter->curbssparams.ssid, 0, IW_ESSID_MAX_SIZE);
+       adapter->curbssparams.ssid_len = 0;
 
        if (adapter->psstate != PS_STATE_FULL_POWER) {
                /* make firmware to exit PS mode */
-               lbs_pr_debug(1, "Disconnected, so exit PS mode.\n");
+               lbs_deb_cmd("Disconnected, so exit PS mode.\n");
                libertas_ps_wakeup(priv, 0);
        }
 }
@@ -122,55 +118,45 @@ static void handle_mic_failureevent(wlan_private * priv, u32 event)
 static int wlan_ret_reg_access(wlan_private * priv,
                               u16 type, struct cmd_ds_command *resp)
 {
+       int ret = 0;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        switch (type) {
        case cmd_ret_mac_reg_access:
                {
-                       struct cmd_ds_mac_reg_access *reg;
-
-                       reg =
-                           (struct cmd_ds_mac_reg_access *)&resp->params.
-                           macreg;
+                       struct cmd_ds_mac_reg_access *reg = &resp->params.macreg;
 
-                       adapter->offsetvalue.offset = reg->offset;
-                       adapter->offsetvalue.value = reg->value;
+                       adapter->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
+                       adapter->offsetvalue.value = le32_to_cpu(reg->value);
                        break;
                }
 
        case cmd_ret_bbp_reg_access:
                {
-                       struct cmd_ds_bbp_reg_access *reg;
-                       reg =
-                           (struct cmd_ds_bbp_reg_access *)&resp->params.
-                           bbpreg;
+                       struct cmd_ds_bbp_reg_access *reg = &resp->params.bbpreg;
 
-                       adapter->offsetvalue.offset = reg->offset;
+                       adapter->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
                        adapter->offsetvalue.value = reg->value;
                        break;
                }
 
        case cmd_ret_rf_reg_access:
                {
-                       struct cmd_ds_rf_reg_access *reg;
-                       reg =
-                           (struct cmd_ds_rf_reg_access *)&resp->params.
-                           rfreg;
+                       struct cmd_ds_rf_reg_access *reg = &resp->params.rfreg;
 
-                       adapter->offsetvalue.offset = reg->offset;
+                       adapter->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
                        adapter->offsetvalue.value = reg->value;
                        break;
                }
 
        default:
-               LEAVE();
-               return -1;
+               ret = -1;
        }
 
-       LEAVE();
-       return 0;
+       lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);
+       return ret;
 }
 
 static int wlan_ret_get_hw_spec(wlan_private * priv,
@@ -181,19 +167,20 @@ static int wlan_ret_get_hw_spec(wlan_private * priv,
        wlan_adapter *adapter = priv->adapter;
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        adapter->fwcapinfo = le32_to_cpu(hwspec->fwcapinfo);
 
-       adapter->fwreleasenumber = hwspec->fwreleasenumber;
+       memcpy(adapter->fwreleasenumber, hwspec->fwreleasenumber, 4);
 
-       lbs_pr_debug(1, "GET_HW_SPEC: FWReleaseVersion- 0x%X\n",
-              adapter->fwreleasenumber);
-       lbs_pr_debug(1, "GET_HW_SPEC: Permanent addr- %2x:%2x:%2x:%2x:%2x:%2x\n",
+       lbs_deb_cmd("GET_HW_SPEC: FWReleaseVersion- %u.%u.%u.p%u\n",
+                   adapter->fwreleasenumber[2], adapter->fwreleasenumber[1],
+                   adapter->fwreleasenumber[0], adapter->fwreleasenumber[3]);
+       lbs_deb_cmd("GET_HW_SPEC: Permanent addr- %2x:%2x:%2x:%2x:%2x:%2x\n",
               hwspec->permanentaddr[0], hwspec->permanentaddr[1],
               hwspec->permanentaddr[2], hwspec->permanentaddr[3],
               hwspec->permanentaddr[4], hwspec->permanentaddr[5]);
-       lbs_pr_debug(1, "GET_HW_SPEC: hwifversion=0x%X  version=0x%X\n",
+       lbs_deb_cmd("GET_HW_SPEC: hwifversion=0x%X  version=0x%X\n",
               hwspec->hwifversion, hwspec->version);
 
        adapter->regioncode = le16_to_cpu(hwspec->regioncode);
@@ -210,17 +197,15 @@ static int wlan_ret_get_hw_spec(wlan_private * priv,
        if (i >= MRVDRV_MAX_REGION_CODE) {
                adapter->regioncode = 0x10;
                adapter->regiontableindex = 0;
-               lbs_pr_info(
-                      "unidentified region code, use the default (USA)\n");
+               lbs_pr_info("unidentified region code; using the default (USA)\n");
        }
 
-       if (adapter->current_addr[0] == 0xff) {
-               memmove(adapter->current_addr, hwspec->permanentaddr,
-                       ETH_ALEN);
-       }
+       if (adapter->current_addr[0] == 0xff)
+               memmove(adapter->current_addr, hwspec->permanentaddr, ETH_ALEN);
 
-       memcpy(priv->wlan_dev.netdev->dev_addr, adapter->current_addr, ETH_ALEN);
-       memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
+       memcpy(priv->dev->dev_addr, adapter->current_addr, ETH_ALEN);
+       if (priv->mesh_dev)
+               memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
 
        if (libertas_set_regiontable(priv, adapter->regioncode, 0)) {
                ret = -1;
@@ -232,8 +217,8 @@ static int wlan_ret_get_hw_spec(wlan_private * priv,
                goto done;
        }
 
-      done:
-       LEAVE();
+done:
+       lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);
        return ret;
 }
 
@@ -243,19 +228,21 @@ static int wlan_ret_802_11_sleep_params(wlan_private * priv,
        struct cmd_ds_802_11_sleep_params *sp = &resp->params.sleep_params;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
+
+       lbs_deb_cmd("error=%x offset=%x stabletime=%x calcontrol=%x\n"
+                   " extsleepclk=%x\n", le16_to_cpu(sp->error),
+                   le16_to_cpu(sp->offset), le16_to_cpu(sp->stabletime),
+                   sp->calcontrol, sp->externalsleepclk);
 
-       lbs_pr_debug(1, "error=%x offset=%x stabletime=%x calcontrol=%x\n"
-              " extsleepclk=%x\n", sp->error, sp->offset,
-              sp->stabletime, sp->calcontrol, sp->externalsleepclk);
        adapter->sp.sp_error = le16_to_cpu(sp->error);
        adapter->sp.sp_offset = le16_to_cpu(sp->offset);
        adapter->sp.sp_stabletime = le16_to_cpu(sp->stabletime);
-       adapter->sp.sp_calcontrol = le16_to_cpu(sp->calcontrol);
-       adapter->sp.sp_extsleepclk = le16_to_cpu(sp->externalsleepclk);
+       adapter->sp.sp_calcontrol = sp->calcontrol;
+       adapter->sp.sp_extsleepclk = sp->externalsleepclk;
        adapter->sp.sp_reserved = le16_to_cpu(sp->reserved);
 
-       LEAVE();
+       lbs_deb_enter(LBS_DEB_CMD);
        return 0;
 }
 
@@ -281,42 +268,38 @@ static int wlan_ret_802_11_snmp_mib(wlan_private * priv,
        u16 oid = le16_to_cpu(smib->oid);
        u16 querytype = le16_to_cpu(smib->querytype);
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
-       lbs_pr_debug(1, "SNMP_RESP: value of the oid = %x, querytype=%x\n", oid,
+       lbs_deb_cmd("SNMP_RESP: value of the oid = %x, querytype=%x\n", oid,
               querytype);
-       lbs_pr_debug(1, "SNMP_RESP: Buf size  = %x\n",
-              le16_to_cpu(smib->bufsize));
+       lbs_deb_cmd("SNMP_RESP: Buf size  = %x\n", le16_to_cpu(smib->bufsize));
 
        if (querytype == cmd_act_get) {
                switch (oid) {
                case fragthresh_i:
                        priv->adapter->fragthsd =
-                           le16_to_cpu(*
-                                            ((unsigned short *)(smib->value)));
-                       lbs_pr_debug(1, "SNMP_RESP: fragthsd =%u\n",
-                              priv->adapter->fragthsd);
+                               le16_to_cpu(*((__le16 *)(smib->value)));
+                       lbs_deb_cmd("SNMP_RESP: fragthsd =%u\n",
+                                   priv->adapter->fragthsd);
                        break;
                case rtsthresh_i:
                        priv->adapter->rtsthsd =
-                           le16_to_cpu(*
-                                            ((unsigned short *)(smib->value)));
-                       lbs_pr_debug(1, "SNMP_RESP: rtsthsd =%u\n",
-                              priv->adapter->rtsthsd);
+                               le16_to_cpu(*((__le16 *)(smib->value)));
+                       lbs_deb_cmd("SNMP_RESP: rtsthsd =%u\n",
+                                   priv->adapter->rtsthsd);
                        break;
                case short_retrylim_i:
                        priv->adapter->txretrycount =
-                           le16_to_cpu(*
-                                            ((unsigned short *)(smib->value)));
-                       lbs_pr_debug(1, "SNMP_RESP: txretrycount =%u\n",
-                              priv->adapter->rtsthsd);
+                               le16_to_cpu(*((__le16 *)(smib->value)));
+                       lbs_deb_cmd("SNMP_RESP: txretrycount =%u\n",
+                                   priv->adapter->rtsthsd);
                        break;
                default:
                        break;
                }
        }
 
-       LEAVE();
+       lbs_deb_enter(LBS_DEB_CMD);
        return 0;
 }
 
@@ -328,7 +311,7 @@ static int wlan_ret_802_11_key_material(wlan_private * priv,
        wlan_adapter *adapter = priv->adapter;
        u16 action = le16_to_cpu(pkeymaterial->action);
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        /* Copy the returned key to driver private data */
        if (action == cmd_act_get) {
@@ -371,7 +354,7 @@ static int wlan_ret_802_11_key_material(wlan_private * priv,
                }
        }
 
-       LEAVE();
+       lbs_deb_enter(LBS_DEB_CMD);
        return 0;
 }
 
@@ -381,11 +364,11 @@ static int wlan_ret_802_11_mac_address(wlan_private * priv,
        struct cmd_ds_802_11_mac_address *macadd = &resp->params.macadd;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        memcpy(adapter->current_addr, macadd->macadd, ETH_ALEN);
 
-       LEAVE();
+       lbs_deb_enter(LBS_DEB_CMD);
        return 0;
 }
 
@@ -395,13 +378,13 @@ static int wlan_ret_802_11_rf_tx_power(wlan_private * priv,
        struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        adapter->txpowerlevel = le16_to_cpu(rtp->currentlevel);
 
-       lbs_pr_debug(1, "Current TxPower Level = %d\n", adapter->txpowerlevel);
+       lbs_deb_cmd("Current TxPower Level = %d\n", adapter->txpowerlevel);
 
-       LEAVE();
+       lbs_deb_enter(LBS_DEB_CMD);
        return 0;
 }
 
@@ -413,14 +396,12 @@ static int wlan_ret_802_11_rf_antenna(wlan_private * priv,
        u16 action = le16_to_cpu(pAntenna->action);
 
        if (action == cmd_act_get_rx)
-               adapter->rxantennamode =
-                   le16_to_cpu(pAntenna->antennamode);
+               adapter->rxantennamode = le16_to_cpu(pAntenna->antennamode);
 
        if (action == cmd_act_get_tx)
-               adapter->txantennamode =
-                   le16_to_cpu(pAntenna->antennamode);
+               adapter->txantennamode = le16_to_cpu(pAntenna->antennamode);
 
-       lbs_pr_debug(1, "RF_ANT_RESP: action = 0x%x, mode = 0x%04x\n",
+       lbs_deb_cmd("RF_ANT_RESP: action = 0x%x, mode = 0x%04x\n",
               action, le16_to_cpu(pAntenna->antennamode));
 
        return 0;
@@ -429,19 +410,17 @@ static int wlan_ret_802_11_rf_antenna(wlan_private * priv,
 static int wlan_ret_802_11_rate_adapt_rateset(wlan_private * priv,
                                              struct cmd_ds_command *resp)
 {
-       struct cmd_ds_802_11_rate_adapt_rateset *rates =
-           &resp->params.rateset;
+       struct cmd_ds_802_11_rate_adapt_rateset *rates = &resp->params.rateset;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        if (rates->action == cmd_act_get) {
-               adapter->enablehwauto = rates->enablehwauto;
-               adapter->ratebitmap = rates->bitmap;
+               adapter->enablehwauto = le16_to_cpu(rates->enablehwauto);
+               adapter->ratebitmap = le16_to_cpu(rates->bitmap);
        }
 
-       LEAVE();
-
+       lbs_deb_enter(LBS_DEB_CMD);
        return 0;
 }
 
@@ -452,43 +431,42 @@ static int wlan_ret_802_11_data_rate(wlan_private * priv,
        wlan_adapter *adapter = priv->adapter;
        u8 dot11datarate;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        lbs_dbg_hex("DATA_RATE_RESP: data_rate- ",
                (u8 *) pdatarate, sizeof(struct cmd_ds_802_11_data_rate));
 
        dot11datarate = pdatarate->datarate[0];
-       if (pdatarate->action == cmd_act_get_tx_rate) {
+       if (pdatarate->action == cpu_to_le16(cmd_act_get_tx_rate)) {
                memcpy(adapter->libertas_supported_rates, pdatarate->datarate,
                       sizeof(adapter->libertas_supported_rates));
        }
        adapter->datarate = libertas_index_to_data_rate(dot11datarate);
 
-       LEAVE();
+       lbs_deb_enter(LBS_DEB_CMD);
        return 0;
 }
 
 static int wlan_ret_802_11_rf_channel(wlan_private * priv,
                                      struct cmd_ds_command *resp)
 {
-       struct cmd_ds_802_11_rf_channel *rfchannel =
-           &resp->params.rfchannel;
+       struct cmd_ds_802_11_rf_channel *rfchannel = &resp->params.rfchannel;
        wlan_adapter *adapter = priv->adapter;
        u16 action = le16_to_cpu(rfchannel->action);
        u16 newchannel = le16_to_cpu(rfchannel->currentchannel);
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
        if (action == cmd_opt_802_11_rf_channel_get
            && adapter->curbssparams.channel != newchannel) {
-               lbs_pr_debug(1, "channel Switch: %d to %d\n",
+               lbs_deb_cmd("channel Switch: %d to %d\n",
                       adapter->curbssparams.channel, newchannel);
 
                /* Update the channel again */
                adapter->curbssparams.channel = newchannel;
        }
 
-       LEAVE();
+       lbs_deb_enter(LBS_DEB_CMD);
        return 0;
 }
 
@@ -500,12 +478,10 @@ static int wlan_ret_802_11_rssi(wlan_private * priv,
 
        /* store the non average value */
        adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR);
-       adapter->NF[TYPE_BEACON][TYPE_NOAVG] =
-           le16_to_cpu(rssirsp->noisefloor);
+       adapter->NF[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->noisefloor);
 
        adapter->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR);
-       adapter->NF[TYPE_BEACON][TYPE_AVG] =
-           le16_to_cpu(rssirsp->avgnoisefloor);
+       adapter->NF[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgnoisefloor);
 
        adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] =
            CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
@@ -515,7 +491,7 @@ static int wlan_ret_802_11_rssi(wlan_private * priv,
            CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
                     adapter->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
 
-       lbs_pr_debug(1, "Beacon RSSI value = 0x%x\n",
+       lbs_deb_cmd("Beacon RSSI value = 0x%x\n",
               adapter->RSSI[TYPE_BEACON][TYPE_AVG]);
 
        return 0;
@@ -528,11 +504,11 @@ static int wlan_ret_802_11_eeprom_access(wlan_private * priv,
        struct wlan_ioctl_regrdwr *pbuf;
        pbuf = (struct wlan_ioctl_regrdwr *) adapter->prdeeprom;
 
-       lbs_pr_debug(1, "eeprom read len=%x\n",
+       lbs_deb_cmd("eeprom read len=%x\n",
               le16_to_cpu(resp->params.rdeeprom.bytecount));
        if (pbuf->NOB < le16_to_cpu(resp->params.rdeeprom.bytecount)) {
                pbuf->NOB = 0;
-               lbs_pr_debug(1, "eeprom read return length is too big\n");
+               lbs_deb_cmd("eeprom read return length is too big\n");
                return -1;
        }
        pbuf->NOB = le16_to_cpu(resp->params.rdeeprom.bytecount);
@@ -549,17 +525,15 @@ static int wlan_ret_802_11_eeprom_access(wlan_private * priv,
 static int wlan_ret_get_log(wlan_private * priv,
                            struct cmd_ds_command *resp)
 {
-       struct cmd_ds_802_11_get_log *logmessage =
-           (struct cmd_ds_802_11_get_log *)&resp->params.glog;
+       struct cmd_ds_802_11_get_log *logmessage = &resp->params.glog;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
-       /* TODO Convert it to Big Endian before copy */
-       memcpy(&adapter->logmsg, logmessage,
-              sizeof(struct cmd_ds_802_11_get_log));
+       /* Stored little-endian */
+       memcpy(&adapter->logmsg, logmessage, sizeof(struct cmd_ds_802_11_get_log));
 
-       LEAVE();
+       lbs_deb_enter(LBS_DEB_CMD);
        return 0;
 }
 
@@ -620,8 +594,7 @@ static inline int handle_cmd_response(u16 respcmd,
        case cmd_ret_802_11_set_afc:
        case cmd_ret_802_11_get_afc:
                spin_lock_irqsave(&adapter->driver_lock, flags);
-               memmove(adapter->cur_cmd->pdata_buf,
-                       &resp->params.afc,
+               memmove(adapter->cur_cmd->pdata_buf, &resp->params.afc,
                        sizeof(struct cmd_ds_802_11_afc));
                spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
@@ -663,7 +636,7 @@ static inline int handle_cmd_response(u16 respcmd,
                break;
 
        case cmd_ret_802_11_key_material:
-               lbs_pr_debug(1, "CMD_RESP: KEY_MATERIAL command response\n");
+               lbs_deb_cmd("CMD_RESP: KEY_MATERIAL command response\n");
                ret = wlan_ret_802_11_key_material(priv, resp);
                break;
 
@@ -687,22 +660,19 @@ static inline int handle_cmd_response(u16 respcmd,
 
        case cmd_ret_802_11_tpc_cfg:
                spin_lock_irqsave(&adapter->driver_lock, flags);
-               memmove(adapter->cur_cmd->pdata_buf,
-                       &resp->params.tpccfg,
+               memmove(adapter->cur_cmd->pdata_buf, &resp->params.tpccfg,
                        sizeof(struct cmd_ds_802_11_tpc_cfg));
                spin_unlock_irqrestore(&adapter->driver_lock, flags);
                break;
        case cmd_ret_802_11_led_gpio_ctrl:
                spin_lock_irqsave(&adapter->driver_lock, flags);
-               memmove(adapter->cur_cmd->pdata_buf,
-                       &resp->params.ledgpio,
+               memmove(adapter->cur_cmd->pdata_buf, &resp->params.ledgpio,
                        sizeof(struct cmd_ds_802_11_led_ctrl));
                spin_unlock_irqrestore(&adapter->driver_lock, flags);
                break;
        case cmd_ret_802_11_pwr_cfg:
                spin_lock_irqsave(&adapter->driver_lock, flags);
-               memmove(adapter->cur_cmd->pdata_buf,
-                       &resp->params.pwrcfg,
+               memmove(adapter->cur_cmd->pdata_buf, &resp->params.pwrcfg,
                        sizeof(struct cmd_ds_802_11_pwr_cfg));
                spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
@@ -724,23 +694,21 @@ static inline int handle_cmd_response(u16 respcmd,
        case cmd_ret_fwt_access:
                spin_lock_irqsave(&adapter->driver_lock, flags);
                if (adapter->cur_cmd->pdata_buf)
-                       memcpy(adapter->cur_cmd->pdata_buf,
-                              &resp->params.fwt,
-                               sizeof(resp->params.fwt));
+                       memcpy(adapter->cur_cmd->pdata_buf, &resp->params.fwt,
+                              sizeof(resp->params.fwt));
                spin_unlock_irqrestore(&adapter->driver_lock, flags);
                break;
        case cmd_ret_mesh_access:
                if (adapter->cur_cmd->pdata_buf)
-                       memcpy(adapter->cur_cmd->pdata_buf,
-                              &resp->params.mesh,
+                       memcpy(adapter->cur_cmd->pdata_buf, &resp->params.mesh,
                               sizeof(resp->params.mesh));
                break;
        case cmd_rte_802_11_tx_rate_query:
                priv->adapter->txrate = resp->params.txrate.txrate;
                break;
        default:
-               lbs_pr_debug(1, "CMD_RESP: Unknown command response %#x\n",
-                      resp->command);
+               lbs_deb_cmd("CMD_RESP: Unknown command response %#x\n",
+                           resp->command);
                break;
        }
        return ret;
@@ -755,9 +723,9 @@ int libertas_process_rx_command(wlan_private * priv)
        ulong flags;
        u16 result;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
-       lbs_pr_debug(1, "CMD_RESP: @ %lu\n", jiffies);
+       lbs_deb_cmd("CMD_RESP: @ %lu\n", jiffies);
 
        /* Now we got response from FW, cancel the command timer */
        del_timer(&adapter->command_timer);
@@ -766,7 +734,7 @@ int libertas_process_rx_command(wlan_private * priv)
        spin_lock_irqsave(&adapter->driver_lock, flags);
 
        if (!adapter->cur_cmd) {
-               lbs_pr_debug(1, "CMD_RESP: NULL cur_cmd=%p\n", adapter->cur_cmd);
+               lbs_deb_cmd("CMD_RESP: NULL cur_cmd=%p\n", adapter->cur_cmd);
                ret = -1;
                spin_unlock_irqrestore(&adapter->driver_lock, flags);
                goto done;
@@ -774,17 +742,17 @@ int libertas_process_rx_command(wlan_private * priv)
        resp = (struct cmd_ds_command *)(adapter->cur_cmd->bufvirtualaddr);
 
        lbs_dbg_hex("CMD_RESP:", adapter->cur_cmd->bufvirtualaddr,
-               priv->wlan_dev.upld_len);
+                   priv->upld_len);
 
        respcmd = le16_to_cpu(resp->command);
 
        result = le16_to_cpu(resp->result);
 
-       lbs_pr_debug(1, "CMD_RESP: %x result: %d length: %d\n", respcmd,
-              result, priv->wlan_dev.upld_len);
+       lbs_deb_cmd("CMD_RESP: %x result: %d length: %d\n", respcmd,
+                   result, priv->upld_len);
 
        if (!(respcmd & 0x8000)) {
-               lbs_pr_debug(1, "Invalid response to command!");
+               lbs_deb_cmd("Invalid response to command!");
                adapter->cur_cmd_retcode = -1;
                __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
                adapter->nr_cmd_pending--;
@@ -795,56 +763,52 @@ int libertas_process_rx_command(wlan_private * priv)
        }
 
        /* Store the response code to cur_cmd_retcode. */
-       adapter->cur_cmd_retcode = le16_to_cpu(resp->result);
+       adapter->cur_cmd_retcode = result;;
 
        if (respcmd == cmd_ret_802_11_ps_mode) {
-               struct cmd_ds_802_11_ps_mode *psmode;
+               struct cmd_ds_802_11_ps_mode *psmode = &resp->params.psmode;
+               u16 action = le16_to_cpu(psmode->action);
 
-               psmode = &resp->params.psmode;
-               lbs_pr_debug(1,
+               lbs_deb_cmd(
                       "CMD_RESP: PS_MODE cmd reply result=%#x action=0x%X\n",
-                      resp->result, psmode->action);
-               psmode->action = cpu_to_le16(psmode->action);
+                      result, action);
 
                if (result) {
-                       lbs_pr_debug(1, "CMD_RESP: PS command failed- %#x \n",
-                              resp->result);
-                       if (adapter->mode == IW_MODE_ADHOC) {
-                               /*
-                                * We should not re-try enter-ps command in
-                                * ad-hoc mode. It takes place in
-                                * libertas_execute_next_command().
-                                */
-                               if (psmode->action == cmd_subcmd_enter_ps)
-                                       adapter->psmode =
-                                           wlan802_11powermodecam;
-                       }
-               } else if (psmode->action == cmd_subcmd_enter_ps) {
+                       lbs_deb_cmd("CMD_RESP: PS command failed- %#x \n",
+                                   result);
+                       /*
+                        * We should not re-try enter-ps command in
+                        * ad-hoc mode. It takes place in
+                        * libertas_execute_next_command().
+                        */
+                       if (adapter->mode == IW_MODE_ADHOC &&
+                           action == cmd_subcmd_enter_ps)
+                               adapter->psmode = wlan802_11powermodecam;
+               } else if (action == cmd_subcmd_enter_ps) {
                        adapter->needtowakeup = 0;
                        adapter->psstate = PS_STATE_AWAKE;
 
-                       lbs_pr_debug(1, "CMD_RESP: Enter_PS command response\n");
+                       lbs_deb_cmd("CMD_RESP: Enter_PS command response\n");
                        if (adapter->connect_status != libertas_connected) {
                                /*
                                 * When Deauth Event received before Enter_PS command
                                 * response, We need to wake up the firmware.
                                 */
-                               lbs_pr_debug(1,
+                               lbs_deb_cmd(
                                       "Disconnected, Going to invoke libertas_ps_wakeup\n");
 
-                               mutex_unlock(&adapter->lock);
                                spin_unlock_irqrestore(&adapter->driver_lock, flags);
+                               mutex_unlock(&adapter->lock);
                                libertas_ps_wakeup(priv, 0);
                                mutex_lock(&adapter->lock);
                                spin_lock_irqsave(&adapter->driver_lock, flags);
                        }
-               } else if (psmode->action == cmd_subcmd_exit_ps) {
+               } else if (action == cmd_subcmd_exit_ps) {
                        adapter->needtowakeup = 0;
                        adapter->psstate = PS_STATE_FULL_POWER;
-                       lbs_pr_debug(1, "CMD_RESP: Exit_PS command response\n");
+                       lbs_deb_cmd("CMD_RESP: Exit_PS command response\n");
                } else {
-                       lbs_pr_debug(1, "CMD_RESP: PS- action=0x%X\n",
-                              psmode->action);
+                       lbs_deb_cmd("CMD_RESP: PS- action=0x%X\n", action);
                }
 
                __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
@@ -865,15 +829,15 @@ int libertas_process_rx_command(wlan_private * priv)
 
        /* If the command is not successful, cleanup and return failure */
        if ((result != 0 || !(respcmd & 0x8000))) {
-               lbs_pr_debug(1, "CMD_RESP: command reply %#x result=%#x\n",
-                      resp->command, resp->result);
+               lbs_deb_cmd("CMD_RESP: command reply %#x result=%#x\n",
+                      respcmd, result);
                /*
                 * Handling errors here
                 */
                switch (respcmd) {
                case cmd_ret_hw_spec_info:
                case cmd_ret_802_11_reset:
-                       lbs_pr_debug(1, "CMD_RESP: Reset command failed\n");
+                       lbs_deb_cmd("CMD_RESP: Reset command failed\n");
                        break;
 
                }
@@ -903,7 +867,7 @@ int libertas_process_rx_command(wlan_private * priv)
 
 done:
        mutex_unlock(&adapter->lock);
-       LEAVE();
+       lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);
        return ret;
 }
 
@@ -917,37 +881,37 @@ int libertas_process_event(wlan_private * priv)
        eventcause = adapter->eventcause;
        spin_unlock_irq(&adapter->driver_lock);
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_CMD);
 
-       lbs_pr_debug(1, "EVENT Cause %x\n", eventcause);
+       lbs_deb_cmd("EVENT Cause %x\n", eventcause);
 
        switch (eventcause >> SBI_EVENT_CAUSE_SHIFT) {
        case MACREG_INT_CODE_LINK_SENSED:
-               lbs_pr_debug(1, "EVENT: MACREG_INT_CODE_LINK_SENSED\n");
+               lbs_deb_cmd("EVENT: MACREG_INT_CODE_LINK_SENSED\n");
                break;
 
        case MACREG_INT_CODE_DEAUTHENTICATED:
-               lbs_pr_debug(1, "EVENT: Deauthenticated\n");
+               lbs_deb_cmd("EVENT: Deauthenticated\n");
                libertas_mac_event_disconnected(priv);
                break;
 
        case MACREG_INT_CODE_DISASSOCIATED:
-               lbs_pr_debug(1, "EVENT: Disassociated\n");
+               lbs_deb_cmd("EVENT: Disassociated\n");
                libertas_mac_event_disconnected(priv);
                break;
 
        case MACREG_INT_CODE_LINK_LOSE_NO_SCAN:
-               lbs_pr_debug(1, "EVENT: Link lost\n");
+               lbs_deb_cmd("EVENT: Link lost\n");
                libertas_mac_event_disconnected(priv);
                break;
 
        case MACREG_INT_CODE_PS_SLEEP:
-               lbs_pr_debug(1, "EVENT: SLEEP\n");
-               lbs_pr_debug(1, "_");
+               lbs_deb_cmd("EVENT: SLEEP\n");
+               lbs_deb_cmd("_");
 
                /* handle unexpected PS SLEEP event */
                if (adapter->psstate == PS_STATE_FULL_POWER) {
-                       lbs_pr_debug(1,
+                       lbs_deb_cmd(
                               "EVENT: In FULL POWER mode - ignore PS SLEEP\n");
                        break;
                }
@@ -958,12 +922,12 @@ int libertas_process_event(wlan_private * priv)
                break;
 
        case MACREG_INT_CODE_PS_AWAKE:
-               lbs_pr_debug(1, "EVENT: AWAKE \n");
-               lbs_pr_debug(1, "|");
+               lbs_deb_cmd("EVENT: AWAKE \n");
+               lbs_deb_cmd("|");
 
                /* handle unexpected PS AWAKE event */
                if (adapter->psstate == PS_STATE_FULL_POWER) {
-                       lbs_pr_debug(1,
+                       lbs_deb_cmd(
                               "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
                        break;
                }
@@ -977,18 +941,18 @@ int libertas_process_event(wlan_private * priv)
                         * adapter->needtowakeup will be set to FALSE
                         * in libertas_ps_wakeup()
                         */
-                       lbs_pr_debug(1, "Waking up...\n");
+                       lbs_deb_cmd("Waking up...\n");
                        libertas_ps_wakeup(priv, 0);
                }
                break;
 
        case MACREG_INT_CODE_MIC_ERR_UNICAST:
-               lbs_pr_debug(1, "EVENT: UNICAST MIC ERROR\n");
+               lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
                handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
                break;
 
        case MACREG_INT_CODE_MIC_ERR_MULTICAST:
-               lbs_pr_debug(1, "EVENT: MULTICAST MIC ERROR\n");
+               lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
                handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
                break;
        case MACREG_INT_CODE_MIB_CHANGED:
@@ -996,7 +960,7 @@ int libertas_process_event(wlan_private * priv)
                break;
 
        case MACREG_INT_CODE_ADHOC_BCN_LOST:
-               lbs_pr_debug(1, "EVENT: HWAC - ADHOC BCN LOST\n");
+               lbs_deb_cmd("EVENT: HWAC - ADHOC BCN LOST\n");
                break;
 
        case MACREG_INT_CODE_RSSI_LOW:
@@ -1015,6 +979,17 @@ int libertas_process_event(wlan_private * priv)
                lbs_pr_alert( "EVENT: SNR_HIGH\n");
                break;
 
+       case MACREG_INT_CODE_MESH_AUTO_STARTED:
+               lbs_pr_alert( "EVENT: MESH_AUTO_STARTED\n");
+               adapter->connect_status = libertas_connected ;
+               if (priv->mesh_open == 1) {
+                       netif_wake_queue(priv->mesh_dev) ;
+                       netif_carrier_on(priv->mesh_dev) ;
+               }
+               adapter->mode = IW_MODE_ADHOC ;
+               schedule_work(&priv->sync_channel);
+               break;
+
        default:
                lbs_pr_alert( "EVENT: unknown event id: %#x\n",
                       eventcause >> SBI_EVENT_CAUSE_SHIFT);
@@ -1024,6 +999,7 @@ int libertas_process_event(wlan_private * priv)
        spin_lock_irq(&adapter->driver_lock);
        adapter->eventcause = 0;
        spin_unlock_irq(&adapter->driver_lock);
-       LEAVE();
+
+       lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);
        return ret;
 }
index 7d7bc5e86a5663610e8d31fc08c7f9020d9aac63..715cbdaa1d4bcf17170717b6148d409e4907ef8d 100644 (file)
@@ -4,6 +4,7 @@
 #include <linux/delay.h>
 #include <linux/mm.h>
 #include <net/iw_handler.h>
+
 #include "dev.h"
 #include "decl.h"
 #include "host.h"
@@ -15,7 +16,9 @@ static char *szStates[] = {
        "Disconnected"
 };
 
-void libertas_debug_init(wlan_private * priv, struct net_device *dev);
+#ifdef PROC_DEBUG
+static void libertas_debug_init(wlan_private * priv, struct net_device *dev);
+#endif
 
 static int open_file_generic(struct inode *inode, struct file *file)
 {
@@ -60,43 +63,33 @@ static ssize_t libertas_getscantable(struct file *file, char __user *userbuf,
        int numscansdone = 0, res;
        unsigned long addr = get_zeroed_page(GFP_KERNEL);
        char *buf = (char *)addr;
+       struct bss_descriptor * iter_bss;
 
-       pos += snprintf(buf+pos, len-pos,
-                       "---------------------------------------");
-       pos += snprintf(buf+pos, len-pos,
-                       "---------------------------------------\n");
        pos += snprintf(buf+pos, len-pos,
                "# | ch  | ss  |       bssid       |   cap    |    TSF   | Qual | SSID \n");
-       pos += snprintf(buf+pos, len-pos,
-               "---------------------------------------");
-       pos += snprintf(buf+pos, len-pos,
-               "---------------------------------------\n");
 
-       while (numscansdone < priv->adapter->numinscantable) {
-               struct bss_descriptor *pbssinfo;
+       mutex_lock(&priv->adapter->lock);
+       list_for_each_entry (iter_bss, &priv->adapter->network_list, list) {
                u16 cap;
 
-               pbssinfo = &priv->adapter->scantable[numscansdone];
-               memcpy(&cap, &pbssinfo->cap, sizeof(cap));
+               memcpy(&cap, &iter_bss->cap, sizeof(cap));
                pos += snprintf(buf+pos, len-pos,
-                       "%02u| %03d | %03ld | %02x:%02x:%02x:%02x:%02x:%02x |",
-                       numscansdone, pbssinfo->channel, pbssinfo->rssi,
-                       pbssinfo->macaddress[0], pbssinfo->macaddress[1],
-                       pbssinfo->macaddress[2], pbssinfo->macaddress[3],
-                       pbssinfo->macaddress[4], pbssinfo->macaddress[5]);
+                       "%02u| %03d | %03ld | " MAC_FMT " |",
+                       numscansdone, iter_bss->channel, iter_bss->rssi,
+                       MAC_ARG(iter_bss->bssid));
                pos += snprintf(buf+pos, len-pos, " %04x-", cap);
                pos += snprintf(buf+pos, len-pos, "%c%c%c |",
-                               pbssinfo->cap.ibss ? 'A' : 'I',
-                               pbssinfo->cap.privacy ? 'P' : ' ',
-                               pbssinfo->cap.spectrummgmt ? 'S' : ' ');
-               pos += snprintf(buf+pos, len-pos, " %08llx |", pbssinfo->networktsf);
-               pos += snprintf(buf+pos, len-pos, " %d |",
-                       SCAN_RSSI(priv->adapter->scantable[numscansdone].rssi));
-
-               pos += snprintf(buf+pos, len-pos, " %s\n", pbssinfo->ssid.ssid);
+                               iter_bss->cap.ibss ? 'A' : 'I',
+                               iter_bss->cap.privacy ? 'P' : ' ',
+                               iter_bss->cap.spectrummgmt ? 'S' : ' ');
+               pos += snprintf(buf+pos, len-pos, " %08llx |", iter_bss->networktsf);
+               pos += snprintf(buf+pos, len-pos, " %d |", SCAN_RSSI(iter_bss->rssi));
+               pos += snprintf(buf+pos, len-pos, " %s\n",
+                               escape_essid(iter_bss->ssid, iter_bss->ssid_len));
 
                numscansdone++;
        }
+       mutex_unlock(&priv->adapter->lock);
 
        res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
 
@@ -111,7 +104,6 @@ static ssize_t libertas_sleepparams_write(struct file *file,
        wlan_private *priv = file->private_data;
        ssize_t buf_size, res;
        int p1, p2, p3, p4, p5, p6;
-       struct sleep_params sp;
        unsigned long addr = get_zeroed_page(GFP_KERNEL);
        char *buf = (char *)addr;
 
@@ -125,14 +117,12 @@ static ssize_t libertas_sleepparams_write(struct file *file,
                res = -EFAULT;
                goto out_unlock;
        }
-       sp.sp_error = p1;
-       sp.sp_offset = p2;
-       sp.sp_stabletime = p3;
-       sp.sp_calcontrol = p4;
-       sp.sp_extsleepclk = p5;
-       sp.sp_reserved = p6;
-
-       memcpy(&priv->adapter->sp, &sp, sizeof(struct sleep_params));
+       priv->adapter->sp.sp_error = p1;
+       priv->adapter->sp.sp_offset = p2;
+       priv->adapter->sp.sp_stabletime = p3;
+       priv->adapter->sp.sp_calcontrol = p4;
+       priv->adapter->sp.sp_extsleepclk = p5;
+       priv->adapter->sp.sp_reserved = p6;
 
         res = libertas_prepare_and_send_command(priv,
                                cmd_802_11_sleep_params,
@@ -185,7 +175,6 @@ static ssize_t libertas_extscan(struct file *file, const char __user *userbuf,
 {
        wlan_private *priv = file->private_data;
        ssize_t res, buf_size;
-       struct WLAN_802_11_SSID extscan_ssid;
        union iwreq_data wrqu;
        unsigned long addr = get_zeroed_page(GFP_KERNEL);
        char *buf = (char *)addr;
@@ -196,13 +185,10 @@ static ssize_t libertas_extscan(struct file *file, const char __user *userbuf,
                goto out_unlock;
        }
 
-       memcpy(&extscan_ssid.ssid, buf, strlen(buf)-1);
-       extscan_ssid.ssidlength = strlen(buf)-1;
-
-       libertas_send_specific_SSID_scan(priv, &extscan_ssid, 1);
+       libertas_send_specific_ssid_scan(priv, buf, strlen(buf)-1, 0);
 
        memset(&wrqu, 0, sizeof(union iwreq_data));
-       wireless_send_event(priv->wlan_dev.netdev, SIOCGIWSCAN, &wrqu, NULL);
+       wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
 
 out_unlock:
        free_page(addr);
@@ -251,16 +237,13 @@ static void libertas_parse_bssid(char *buf, size_t count,
 {
        char *hold;
        unsigned int mac[ETH_ALEN];
-       int i;
 
        hold = strstr(buf, "bssid=");
        if (!hold)
                return;
        hold += 6;
-       sscanf(hold, "%2x:%2x:%2x:%2x:%2x:%2x", mac, mac+1, mac+2, mac+3,
-                       mac+4, mac+5);
-       for(i=0;i<ETH_ALEN;i++)
-               scan_cfg->specificBSSID[i] = mac[i];
+       sscanf(hold, MAC_FMT, mac, mac+1, mac+2, mac+3, mac+4, mac+5);
+       memcpy(scan_cfg->bssid, mac, ETH_ALEN);
 }
 
 static void libertas_parse_ssid(char *buf, size_t count,
@@ -278,28 +261,26 @@ static void libertas_parse_ssid(char *buf, size_t count,
                end = buf + count - 1;
 
        size = min((size_t)IW_ESSID_MAX_SIZE, (size_t) (end - hold));
-       strncpy(scan_cfg->specificSSID, hold, size);
+       strncpy(scan_cfg->ssid, hold, size);
 
        return;
 }
 
-static void libertas_parse_keep(char *buf, size_t count,
-                        struct wlan_ioctl_user_scan_cfg *scan_cfg)
+static int libertas_parse_clear(char *buf, size_t count, const char *tag)
 {
        char *hold;
        int val;
 
-       hold = strstr(buf, "keep=");
+       hold = strstr(buf, tag);
        if (!hold)
-               return;
-       hold += 5;
+               return 0;
+       hold += strlen(tag);
        sscanf(hold, "%d", &val);
 
        if (val != 0)
                val = 1;
 
-       scan_cfg->keeppreviousscan = val;
-       return;
+       return val;
 }
 
 static int libertas_parse_dur(char *buf, size_t count,
@@ -382,17 +363,18 @@ static ssize_t libertas_setuserscan(struct file *file,
        dur = libertas_parse_dur(buf, count, scan_cfg);
        libertas_parse_chan(buf, count, scan_cfg, dur);
        libertas_parse_bssid(buf, count, scan_cfg);
+       scan_cfg->clear_bssid = libertas_parse_clear(buf, count, "clear_bssid=");
        libertas_parse_ssid(buf, count, scan_cfg);
-       libertas_parse_keep(buf, count, scan_cfg);
+       scan_cfg->clear_ssid = libertas_parse_clear(buf, count, "clear_ssid=");
        libertas_parse_probes(buf, count, scan_cfg);
        libertas_parse_type(buf, count, scan_cfg);
 
-       wlan_scan_networks(priv, scan_cfg);
+       wlan_scan_networks(priv, scan_cfg, 1);
        wait_event_interruptible(priv->adapter->cmd_pending,
                                 !priv->adapter->nr_cmd_pending);
 
        memset(&wrqu, 0x00, sizeof(union iwreq_data));
-       wireless_send_event(priv->wlan_dev.netdev, SIOCGIWSCAN, &wrqu, NULL);
+       wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
 
 out_unlock:
        free_page(addr);
@@ -407,11 +389,11 @@ static int libertas_event_initcmd(wlan_private *priv, void **response_buf,
        u16 wait_option = cmd_option_waitforrsp;
 
        if (!(*cmdnode = libertas_get_free_cmd_ctrl_node(priv))) {
-               lbs_pr_debug(1, "failed libertas_get_free_cmd_ctrl_node\n");
+               lbs_deb_debugfs("failed libertas_get_free_cmd_ctrl_node\n");
                return -ENOMEM;
        }
        if (!(*response_buf = kmalloc(3000, GFP_KERNEL))) {
-               lbs_pr_debug(1, "failed to allocate response buffer!\n");
+               lbs_deb_debugfs("failed to allocate response buffer!\n");
                return -ENOMEM;
        }
        libertas_set_cmd_ctrl_node(priv, *cmdnode, 0, wait_option, NULL);
@@ -420,8 +402,8 @@ static int libertas_event_initcmd(wlan_private *priv, void **response_buf,
        (*cmdnode)->cmdflags |= CMD_F_HOSTCMD;
        (*cmdnode)->cmdwaitqwoken = 0;
        *cmd = (struct cmd_ds_command *)(*cmdnode)->bufvirtualaddr;
-       (*cmd)->command = cmd_802_11_subscribe_event;
-       (*cmd)->seqnum = ++priv->adapter->seqnum;
+       (*cmd)->command = cpu_to_le16(cmd_802_11_subscribe_event);
+       (*cmd)->seqnum = cpu_to_le16(++priv->adapter->seqnum);
        (*cmd)->result = 0;
        return 0;
 }
@@ -447,26 +429,25 @@ static ssize_t libertas_lowrssi_read(struct file *file, char __user *userbuf,
        }
 
        event = &pcmdptr->params.subscribe_event;
-       event->action = cmd_act_get;
-       pcmdptr->size =
-       cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+       event->action = cpu_to_le16(cmd_act_get);
+       pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
        libertas_queue_cmd(adapter, pcmdnode, 1);
        wake_up_interruptible(&priv->mainthread.waitq);
 
        /* Sleep until response is generated by FW */
        wait_event_interruptible(pcmdnode->cmdwait_q,
-                               pcmdnode->cmdwaitqwoken);
+                                pcmdnode->cmdwaitqwoken);
 
        pcmdptr = response_buf;
        if (pcmdptr->result) {
-               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-                       pcmdptr->result);
+               lbs_pr_err("%s: fail, result=%d\n", __func__,
+                          le16_to_cpu(pcmdptr->result));
                kfree(response_buf);
                free_page(addr);
                return 0;
        }
 
-       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+       if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
                lbs_pr_err("command response incorrect!\n");
                kfree(response_buf);
                free_page(addr);
@@ -474,17 +455,17 @@ static ssize_t libertas_lowrssi_read(struct file *file, char __user *userbuf,
        }
 
        cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
-       event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
-       while (cmd_len < pcmdptr->size) {
-               struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
-               switch(header->type) {
+       event = (void *)(response_buf + S_DS_GEN);
+       while (cmd_len < le16_to_cpu(pcmdptr->size)) {
+               struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
+               switch (header->type) {
                struct mrvlietypes_rssithreshold  *Lowrssi;
-               case TLV_TYPE_RSSI_LOW:
-               Lowrssi = (struct mrvlietypes_rssithreshold *)(response_buf + cmd_len);
-               pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
-                               Lowrssi->rssivalue,
-                               Lowrssi->rssifreq,
-                               (event->events & 0x0001)?1:0);
+               case __constant_cpu_to_le16(TLV_TYPE_RSSI_LOW):
+                       Lowrssi = (void *)(response_buf + cmd_len);
+                       pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+                                       Lowrssi->rssivalue,
+                                       Lowrssi->rssifreq,
+                                       (event->events & cpu_to_le16(0x0001))?1:0);
                default:
                        cmd_len += sizeof(struct mrvlietypes_snrthreshold);
                        break;
@@ -512,21 +493,20 @@ static u16 libertas_get_events_bitmap(wlan_private *priv)
                return res;
 
        event = &pcmdptr->params.subscribe_event;
-       event->action = cmd_act_get;
-       pcmdptr->size =
-       cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+       event->action = cpu_to_le16(cmd_act_get);
+       pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
        libertas_queue_cmd(adapter, pcmdnode, 1);
        wake_up_interruptible(&priv->mainthread.waitq);
 
        /* Sleep until response is generated by FW */
        wait_event_interruptible(pcmdnode->cmdwait_q,
-                               pcmdnode->cmdwaitqwoken);
+                                pcmdnode->cmdwaitqwoken);
 
        pcmdptr = response_buf;
 
        if (pcmdptr->result) {
-               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-                       pcmdptr->result);
+               lbs_pr_err("%s: fail, result=%d\n", __func__,
+                          le16_to_cpu(pcmdptr->result));
                kfree(response_buf);
                return 0;
        }
@@ -538,7 +518,7 @@ static u16 libertas_get_events_bitmap(wlan_private *priv)
        }
 
        event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
-       event_bitmap = event->events;
+       event_bitmap = le16_to_cpu(event->events);
        kfree(response_buf);
        return event_bitmap;
 }
@@ -579,7 +559,7 @@ static ssize_t libertas_lowrssi_write(struct file *file,
                goto out_unlock;
 
        event = &pcmdptr->params.subscribe_event;
-       event->action = cmd_act_set;
+       event->action = cpu_to_le16(cmd_act_set);
        pcmdptr->size = cpu_to_le16(S_DS_GEN +
                sizeof(struct cmd_ds_802_11_subscribe_event) +
                sizeof(struct mrvlietypes_rssithreshold));
@@ -588,30 +568,30 @@ static ssize_t libertas_lowrssi_write(struct file *file,
        ptr = (u8*) pcmdptr+cmd_len;
        rssi_threshold = (struct mrvlietypes_rssithreshold *)(ptr);
        rssi_threshold->header.type = cpu_to_le16(0x0104);
-       rssi_threshold->header.len = 2;
-       rssi_threshold->rssivalue = cpu_to_le16(value);
-       rssi_threshold->rssifreq = cpu_to_le16(freq);
+       rssi_threshold->header.len = cpu_to_le16(2);
+       rssi_threshold->rssivalue = value;
+       rssi_threshold->rssifreq = freq;
        event_bitmap |= subscribed ? 0x0001 : 0x0;
-       event->events = event_bitmap;
+       event->events = cpu_to_le16(event_bitmap);
 
        libertas_queue_cmd(adapter, pcmdnode, 1);
        wake_up_interruptible(&priv->mainthread.waitq);
 
        /* Sleep until response is generated by FW */
        wait_event_interruptible(pcmdnode->cmdwait_q,
-                               pcmdnode->cmdwaitqwoken);
+                                pcmdnode->cmdwaitqwoken);
 
        pcmdptr = response_buf;
 
        if (pcmdptr->result) {
-               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-                       pcmdptr->result);
+               lbs_pr_err("%s: fail, result=%d\n", __func__,
+                          le16_to_cpu(pcmdptr->result));
                kfree(response_buf);
                free_page(addr);
                return 0;
        }
 
-       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+       if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
                lbs_pr_err("command response incorrect!\n");
                kfree(response_buf);
                free_page(addr);
@@ -645,27 +625,26 @@ static ssize_t libertas_lowsnr_read(struct file *file, char __user *userbuf,
        }
 
        event = &pcmdptr->params.subscribe_event;
-       event->action = cmd_act_get;
-       pcmdptr->size =
-       cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+       event->action = cpu_to_le16(cmd_act_get);
+       pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
        libertas_queue_cmd(adapter, pcmdnode, 1);
        wake_up_interruptible(&priv->mainthread.waitq);
 
        /* Sleep until response is generated by FW */
        wait_event_interruptible(pcmdnode->cmdwait_q,
-                               pcmdnode->cmdwaitqwoken);
+                                pcmdnode->cmdwaitqwoken);
 
        pcmdptr = response_buf;
 
        if (pcmdptr->result) {
-               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-                       pcmdptr->result);
+               lbs_pr_err("%s: fail, result=%d\n", __func__,
+                          le16_to_cpu(pcmdptr->result));
                kfree(response_buf);
                free_page(addr);
                return 0;
        }
 
-       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+       if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
                lbs_pr_err("command response incorrect!\n");
                kfree(response_buf);
                free_page(addr);
@@ -673,17 +652,17 @@ static ssize_t libertas_lowsnr_read(struct file *file, char __user *userbuf,
        }
 
        cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
-       event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
-       while (cmd_len < pcmdptr->size) {
-               struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
-               switch(header->type) {
+       event = (void *)(response_buf + S_DS_GEN);
+       while (cmd_len < le16_to_cpu(pcmdptr->size)) {
+               struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
+               switch (header->type) {
                struct mrvlietypes_snrthreshold *LowSnr;
-               case TLV_TYPE_SNR_LOW:
-               LowSnr = (struct mrvlietypes_snrthreshold *)(response_buf + cmd_len);
-               pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
-                               LowSnr->snrvalue,
-                               LowSnr->snrfreq,
-                               (event->events & 0x0002)?1:0);
+               case __constant_cpu_to_le16(TLV_TYPE_SNR_LOW):
+                       LowSnr = (void *)(response_buf + cmd_len);
+                       pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+                                       LowSnr->snrvalue,
+                                       LowSnr->snrfreq,
+                                       (event->events & cpu_to_le16(0x0002))?1:0);
                default:
                        cmd_len += sizeof(struct mrvlietypes_snrthreshold);
                        break;
@@ -733,7 +712,7 @@ static ssize_t libertas_lowsnr_write(struct file *file,
                goto out_unlock;
 
        event = &pcmdptr->params.subscribe_event;
-       event->action = cmd_act_set;
+       event->action = cpu_to_le16(cmd_act_set);
        pcmdptr->size = cpu_to_le16(S_DS_GEN +
                sizeof(struct cmd_ds_802_11_subscribe_event) +
                sizeof(struct mrvlietypes_snrthreshold));
@@ -741,30 +720,30 @@ static ssize_t libertas_lowsnr_write(struct file *file,
        ptr = (u8*) pcmdptr+cmd_len;
        snr_threshold = (struct mrvlietypes_snrthreshold *)(ptr);
        snr_threshold->header.type = cpu_to_le16(TLV_TYPE_SNR_LOW);
-       snr_threshold->header.len = 2;
-       snr_threshold->snrvalue = cpu_to_le16(value);
-       snr_threshold->snrfreq = cpu_to_le16(freq);
+       snr_threshold->header.len = cpu_to_le16(2);
+       snr_threshold->snrvalue = value;
+       snr_threshold->snrfreq = freq;
        event_bitmap |= subscribed ? 0x0002 : 0x0;
-       event->events = event_bitmap;
+       event->events = cpu_to_le16(event_bitmap);
 
        libertas_queue_cmd(adapter, pcmdnode, 1);
        wake_up_interruptible(&priv->mainthread.waitq);
 
        /* Sleep until response is generated by FW */
        wait_event_interruptible(pcmdnode->cmdwait_q,
-                               pcmdnode->cmdwaitqwoken);
+                                pcmdnode->cmdwaitqwoken);
 
        pcmdptr = response_buf;
 
        if (pcmdptr->result) {
-               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-                       pcmdptr->result);
+               lbs_pr_err("%s: fail, result=%d\n", __func__,
+                          le16_to_cpu(pcmdptr->result));
                kfree(response_buf);
                free_page(addr);
                return 0;
        }
 
-       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+       if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
                lbs_pr_err("command response incorrect!\n");
                kfree(response_buf);
                free_page(addr);
@@ -799,27 +778,26 @@ static ssize_t libertas_failcount_read(struct file *file, char __user *userbuf,
        }
 
        event = &pcmdptr->params.subscribe_event;
-       event->action = cmd_act_get;
-       pcmdptr->size =
-       cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+       event->action = cpu_to_le16(cmd_act_get);
+       pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
        libertas_queue_cmd(adapter, pcmdnode, 1);
        wake_up_interruptible(&priv->mainthread.waitq);
 
        /* Sleep until response is generated by FW */
        wait_event_interruptible(pcmdnode->cmdwait_q,
-                               pcmdnode->cmdwaitqwoken);
+                                pcmdnode->cmdwaitqwoken);
 
        pcmdptr = response_buf;
 
        if (pcmdptr->result) {
-               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-                       pcmdptr->result);
+               lbs_pr_err("%s: fail, result=%d\n", __func__,
+                          le16_to_cpu(pcmdptr->result));
                kfree(response_buf);
                free_page(addr);
                return 0;
        }
 
-       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+       if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
                lbs_pr_err("command response incorrect!\n");
                kfree(response_buf);
                free_page(addr);
@@ -827,17 +805,17 @@ static ssize_t libertas_failcount_read(struct file *file, char __user *userbuf,
        }
 
        cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
-       event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
-       while (cmd_len < pcmdptr->size) {
-               struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
-               switch(header->type) {
+       event = (void *)(response_buf + S_DS_GEN);
+       while (cmd_len < le16_to_cpu(pcmdptr->size)) {
+               struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
+               switch (header->type) {
                struct mrvlietypes_failurecount *failcount;
-               case TLV_TYPE_FAILCOUNT:
-               failcount = (struct mrvlietypes_failurecount *)(response_buf + cmd_len);
-               pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
-                               failcount->failvalue,
-                               failcount->Failfreq,
-                               (event->events & 0x0004)?1:0);
+               case __constant_cpu_to_le16(TLV_TYPE_FAILCOUNT):
+                       failcount = (void *)(response_buf + cmd_len);
+                       pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+                                       failcount->failvalue,
+                                       failcount->Failfreq,
+                                       (event->events & cpu_to_le16(0x0004))?1:0);
                default:
                        cmd_len += sizeof(struct mrvlietypes_failurecount);
                        break;
@@ -886,7 +864,7 @@ static ssize_t libertas_failcount_write(struct file *file,
                goto out_unlock;
 
        event = &pcmdptr->params.subscribe_event;
-       event->action = cmd_act_set;
+       event->action = cpu_to_le16(cmd_act_set);
        pcmdptr->size = cpu_to_le16(S_DS_GEN +
                sizeof(struct cmd_ds_802_11_subscribe_event) +
                sizeof(struct mrvlietypes_failurecount));
@@ -894,30 +872,30 @@ static ssize_t libertas_failcount_write(struct file *file,
        ptr = (u8*) pcmdptr+cmd_len;
        failcount = (struct mrvlietypes_failurecount *)(ptr);
        failcount->header.type = cpu_to_le16(TLV_TYPE_FAILCOUNT);
-       failcount->header.len = 2;
-       failcount->failvalue = cpu_to_le16(value);
-       failcount->Failfreq = cpu_to_le16(freq);
+       failcount->header.len = cpu_to_le16(2);
+       failcount->failvalue = value;
+       failcount->Failfreq = freq;
        event_bitmap |= subscribed ? 0x0004 : 0x0;
-       event->events = event_bitmap;
+       event->events = cpu_to_le16(event_bitmap);
 
        libertas_queue_cmd(adapter, pcmdnode, 1);
        wake_up_interruptible(&priv->mainthread.waitq);
 
        /* Sleep until response is generated by FW */
        wait_event_interruptible(pcmdnode->cmdwait_q,
-                               pcmdnode->cmdwaitqwoken);
+                                pcmdnode->cmdwaitqwoken);
 
        pcmdptr = (struct cmd_ds_command *)response_buf;
 
        if (pcmdptr->result) {
-               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-                       pcmdptr->result);
+               lbs_pr_err("%s: fail, result=%d\n", __func__,
+                          le16_to_cpu(pcmdptr->result));
                kfree(response_buf);
                free_page(addr);
                return 0;
        }
 
-       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+       if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
                lbs_pr_err("command response incorrect!\n");
                kfree(response_buf);
                free_page(addr);
@@ -951,27 +929,26 @@ static ssize_t libertas_bcnmiss_read(struct file *file, char __user *userbuf,
        }
 
        event = &pcmdptr->params.subscribe_event;
-       event->action = cmd_act_get;
-       pcmdptr->size =
-       cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+       event->action = cpu_to_le16(cmd_act_get);
+       pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
        libertas_queue_cmd(adapter, pcmdnode, 1);
        wake_up_interruptible(&priv->mainthread.waitq);
 
        /* Sleep until response is generated by FW */
        wait_event_interruptible(pcmdnode->cmdwait_q,
-                               pcmdnode->cmdwaitqwoken);
+                                pcmdnode->cmdwaitqwoken);
 
        pcmdptr = response_buf;
 
        if (pcmdptr->result) {
-               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-                       pcmdptr->result);
+               lbs_pr_err("%s: fail, result=%d\n", __func__,
+                          le16_to_cpu(pcmdptr->result));
                free_page(addr);
                kfree(response_buf);
                return 0;
        }
 
-       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+       if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
                lbs_pr_err("command response incorrect!\n");
                free_page(addr);
                kfree(response_buf);
@@ -979,16 +956,16 @@ static ssize_t libertas_bcnmiss_read(struct file *file, char __user *userbuf,
        }
 
        cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
-       event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
-       while (cmd_len < pcmdptr->size) {
-               struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
-               switch(header->type) {
+       event = (void *)(response_buf + S_DS_GEN);
+       while (cmd_len < le16_to_cpu(pcmdptr->size)) {
+               struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
+               switch (header->type) {
                struct mrvlietypes_beaconsmissed *bcnmiss;
-               case TLV_TYPE_BCNMISS:
-               bcnmiss = (struct mrvlietypes_beaconsmissed *)(response_buf + cmd_len);
-               pos += snprintf(buf+pos, len-pos, "%d N/A %d\n",
-                               bcnmiss->beaconmissed,
-                               (event->events & 0x0008)?1:0);
+               case __constant_cpu_to_le16(TLV_TYPE_BCNMISS):
+                       bcnmiss = (void *)(response_buf + cmd_len);
+                       pos += snprintf(buf+pos, len-pos, "%d N/A %d\n",
+                                       bcnmiss->beaconmissed,
+                                       (event->events & cpu_to_le16(0x0008))?1:0);
                default:
                        cmd_len += sizeof(struct mrvlietypes_beaconsmissed);
                        break;
@@ -1038,7 +1015,7 @@ static ssize_t libertas_bcnmiss_write(struct file *file,
                goto out_unlock;
 
        event = &pcmdptr->params.subscribe_event;
-       event->action = cmd_act_set;
+       event->action = cpu_to_le16(cmd_act_set);
        pcmdptr->size = cpu_to_le16(S_DS_GEN +
                sizeof(struct cmd_ds_802_11_subscribe_event) +
                sizeof(struct mrvlietypes_beaconsmissed));
@@ -1046,29 +1023,29 @@ static ssize_t libertas_bcnmiss_write(struct file *file,
        ptr = (u8*) pcmdptr+cmd_len;
        bcnmiss = (struct mrvlietypes_beaconsmissed *)(ptr);
        bcnmiss->header.type = cpu_to_le16(TLV_TYPE_BCNMISS);
-       bcnmiss->header.len = 2;
-       bcnmiss->beaconmissed = cpu_to_le16(value);
+       bcnmiss->header.len = cpu_to_le16(2);
+       bcnmiss->beaconmissed = value;
        event_bitmap |= subscribed ? 0x0008 : 0x0;
-       event->events = event_bitmap;
+       event->events = cpu_to_le16(event_bitmap);
 
        libertas_queue_cmd(adapter, pcmdnode, 1);
        wake_up_interruptible(&priv->mainthread.waitq);
 
        /* Sleep until response is generated by FW */
        wait_event_interruptible(pcmdnode->cmdwait_q,
-                               pcmdnode->cmdwaitqwoken);
+                                pcmdnode->cmdwaitqwoken);
 
        pcmdptr = response_buf;
 
        if (pcmdptr->result) {
-               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-                       pcmdptr->result);
+               lbs_pr_err("%s: fail, result=%d\n", __func__,
+                          le16_to_cpu(pcmdptr->result));
                kfree(response_buf);
                free_page(addr);
                return 0;
        }
 
-       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+       if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
                lbs_pr_err("command response incorrect!\n");
                free_page(addr);
                kfree(response_buf);
@@ -1102,27 +1079,26 @@ static ssize_t libertas_highrssi_read(struct file *file, char __user *userbuf,
        }
 
        event = &pcmdptr->params.subscribe_event;
-       event->action = cmd_act_get;
-       pcmdptr->size =
-       cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+       event->action = cpu_to_le16(cmd_act_get);
+       pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
        libertas_queue_cmd(adapter, pcmdnode, 1);
        wake_up_interruptible(&priv->mainthread.waitq);
 
        /* Sleep until response is generated by FW */
        wait_event_interruptible(pcmdnode->cmdwait_q,
-                               pcmdnode->cmdwaitqwoken);
+                                pcmdnode->cmdwaitqwoken);
 
        pcmdptr = response_buf;
 
        if (pcmdptr->result) {
-               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-                       pcmdptr->result);
+               lbs_pr_err("%s: fail, result=%d\n", __func__,
+                          le16_to_cpu(pcmdptr->result));
                kfree(response_buf);
                free_page(addr);
                return 0;
        }
 
-       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+       if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
                lbs_pr_err("command response incorrect!\n");
                kfree(response_buf);
                free_page(addr);
@@ -1130,17 +1106,17 @@ static ssize_t libertas_highrssi_read(struct file *file, char __user *userbuf,
        }
 
        cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
-       event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
-       while (cmd_len < pcmdptr->size) {
-               struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
-               switch(header->type) {
+       event = (void *)(response_buf + S_DS_GEN);
+       while (cmd_len < le16_to_cpu(pcmdptr->size)) {
+               struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
+               switch (header->type) {
                struct mrvlietypes_rssithreshold  *Highrssi;
-               case TLV_TYPE_RSSI_HIGH:
-               Highrssi = (struct mrvlietypes_rssithreshold *)(response_buf + cmd_len);
-               pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
-                               Highrssi->rssivalue,
-                               Highrssi->rssifreq,
-                               (event->events & 0x0010)?1:0);
+               case __constant_cpu_to_le16(TLV_TYPE_RSSI_HIGH):
+                       Highrssi = (void *)(response_buf + cmd_len);
+                       pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+                                       Highrssi->rssivalue,
+                                       Highrssi->rssifreq,
+                                       (event->events & cpu_to_le16(0x0010))?1:0);
                default:
                        cmd_len += sizeof(struct mrvlietypes_snrthreshold);
                        break;
@@ -1190,7 +1166,7 @@ static ssize_t libertas_highrssi_write(struct file *file,
                goto out_unlock;
 
        event = &pcmdptr->params.subscribe_event;
-       event->action = cmd_act_set;
+       event->action = cpu_to_le16(cmd_act_set);
        pcmdptr->size = cpu_to_le16(S_DS_GEN +
                sizeof(struct cmd_ds_802_11_subscribe_event) +
                sizeof(struct mrvlietypes_rssithreshold));
@@ -1198,29 +1174,29 @@ static ssize_t libertas_highrssi_write(struct file *file,
        ptr = (u8*) pcmdptr+cmd_len;
        rssi_threshold = (struct mrvlietypes_rssithreshold *)(ptr);
        rssi_threshold->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
-       rssi_threshold->header.len = 2;
-       rssi_threshold->rssivalue = cpu_to_le16(value);
-       rssi_threshold->rssifreq = cpu_to_le16(freq);
+       rssi_threshold->header.len = cpu_to_le16(2);
+       rssi_threshold->rssivalue = value;
+       rssi_threshold->rssifreq = freq;
        event_bitmap |= subscribed ? 0x0010 : 0x0;
-       event->events = event_bitmap;
+       event->events = cpu_to_le16(event_bitmap);
 
        libertas_queue_cmd(adapter, pcmdnode, 1);
        wake_up_interruptible(&priv->mainthread.waitq);
 
        /* Sleep until response is generated by FW */
        wait_event_interruptible(pcmdnode->cmdwait_q,
-                               pcmdnode->cmdwaitqwoken);
+                                pcmdnode->cmdwaitqwoken);
 
        pcmdptr = response_buf;
 
        if (pcmdptr->result) {
-               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-                       pcmdptr->result);
+               lbs_pr_err("%s: fail, result=%d\n", __func__,
+                          le16_to_cpu(pcmdptr->result));
                kfree(response_buf);
                return 0;
        }
 
-       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+       if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
                lbs_pr_err("command response incorrect!\n");
                kfree(response_buf);
                return 0;
@@ -1253,27 +1229,26 @@ static ssize_t libertas_highsnr_read(struct file *file, char __user *userbuf,
        }
 
        event = &pcmdptr->params.subscribe_event;
-       event->action = cmd_act_get;
-       pcmdptr->size =
-       cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+       event->action = cpu_to_le16(cmd_act_get);
+       pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
        libertas_queue_cmd(adapter, pcmdnode, 1);
        wake_up_interruptible(&priv->mainthread.waitq);
 
        /* Sleep until response is generated by FW */
        wait_event_interruptible(pcmdnode->cmdwait_q,
-                               pcmdnode->cmdwaitqwoken);
+                                pcmdnode->cmdwaitqwoken);
 
        pcmdptr = response_buf;
 
        if (pcmdptr->result) {
-               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-                       pcmdptr->result);
+               lbs_pr_err("%s: fail, result=%d\n", __func__,
+                          le16_to_cpu(pcmdptr->result));
                kfree(response_buf);
                free_page(addr);
                return 0;
        }
 
-       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+       if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
                lbs_pr_err("command response incorrect!\n");
                kfree(response_buf);
                free_page(addr);
@@ -1281,17 +1256,17 @@ static ssize_t libertas_highsnr_read(struct file *file, char __user *userbuf,
        }
 
        cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
-       event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
-       while (cmd_len < pcmdptr->size) {
-               struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
-               switch(header->type) {
+       event = (void *)(response_buf + S_DS_GEN);
+       while (cmd_len < le16_to_cpu(pcmdptr->size)) {
+               struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
+               switch (header->type) {
                struct mrvlietypes_snrthreshold *HighSnr;
-               case TLV_TYPE_SNR_HIGH:
-               HighSnr = (struct mrvlietypes_snrthreshold *)(response_buf + cmd_len);
-               pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
-                               HighSnr->snrvalue,
-                               HighSnr->snrfreq,
-                               (event->events & 0x0020)?1:0);
+               case __constant_cpu_to_le16(TLV_TYPE_SNR_HIGH):
+                       HighSnr = (void *)(response_buf + cmd_len);
+                       pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+                                       HighSnr->snrvalue,
+                                       HighSnr->snrfreq,
+                                       (event->events & cpu_to_le16(0x0020))?1:0);
                default:
                        cmd_len += sizeof(struct mrvlietypes_snrthreshold);
                        break;
@@ -1341,7 +1316,7 @@ static ssize_t libertas_highsnr_write(struct file *file,
                goto out_unlock;
 
        event = &pcmdptr->params.subscribe_event;
-       event->action = cmd_act_set;
+       event->action = cpu_to_le16(cmd_act_set);
        pcmdptr->size = cpu_to_le16(S_DS_GEN +
                sizeof(struct cmd_ds_802_11_subscribe_event) +
                sizeof(struct mrvlietypes_snrthreshold));
@@ -1349,30 +1324,30 @@ static ssize_t libertas_highsnr_write(struct file *file,
        ptr = (u8*) pcmdptr+cmd_len;
        snr_threshold = (struct mrvlietypes_snrthreshold *)(ptr);
        snr_threshold->header.type = cpu_to_le16(TLV_TYPE_SNR_HIGH);
-       snr_threshold->header.len = 2;
-       snr_threshold->snrvalue = cpu_to_le16(value);
-       snr_threshold->snrfreq = cpu_to_le16(freq);
+       snr_threshold->header.len = cpu_to_le16(2);
+       snr_threshold->snrvalue = value;
+       snr_threshold->snrfreq = freq;
        event_bitmap |= subscribed ? 0x0020 : 0x0;
-       event->events = event_bitmap;
+       event->events = cpu_to_le16(event_bitmap);
 
        libertas_queue_cmd(adapter, pcmdnode, 1);
        wake_up_interruptible(&priv->mainthread.waitq);
 
        /* Sleep until response is generated by FW */
        wait_event_interruptible(pcmdnode->cmdwait_q,
-                               pcmdnode->cmdwaitqwoken);
+                                pcmdnode->cmdwaitqwoken);
 
        pcmdptr = response_buf;
 
        if (pcmdptr->result) {
-               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-                       pcmdptr->result);
+               lbs_pr_err("%s: fail, result=%d\n", __func__,
+                          le16_to_cpu(pcmdptr->result));
                kfree(response_buf);
                free_page(addr);
                return 0;
        }
 
-       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+       if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
                lbs_pr_err("command response incorrect!\n");
                kfree(response_buf);
                free_page(addr);
@@ -1760,7 +1735,7 @@ void libertas_debugfs_remove_one(wlan_private *priv)
 
        debugfs_remove(priv->regs_dir);
 
-       for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
+       for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
                debugfs_remove(priv->debugfs_events_files[i]);
 
        debugfs_remove(priv->events_dir);
@@ -1769,13 +1744,19 @@ void libertas_debugfs_remove_one(wlan_private *priv)
 #endif
        for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
                debugfs_remove(priv->debugfs_files[i]);
+       debugfs_remove(priv->debugfs_dir);
 }
 
+
+
 /* debug entry */
 
+#ifdef PROC_DEBUG
+
 #define item_size(n)   (FIELD_SIZEOF(wlan_adapter, n))
 #define item_addr(n)   (offsetof(wlan_adapter, n))
 
+
 struct debug_data {
        char name[32];
        u32 size;
@@ -1863,7 +1844,7 @@ static ssize_t wlan_debugfs_write(struct file *f, const char __user *buf,
                return 0;
 
        if (copy_from_user(pdata, buf, cnt)) {
-               lbs_pr_debug(1, "Copy from user failed\n");
+               lbs_deb_debugfs("Copy from user failed\n");
                kfree(pdata);
                return 0;
        }
@@ -1913,7 +1894,7 @@ static struct file_operations libertas_debug_fops = {
  *  @param dev     pointer net_device
  *  @return       N/A
  */
-void libertas_debug_init(wlan_private * priv, struct net_device *dev)
+static void libertas_debug_init(wlan_private * priv, struct net_device *dev)
 {
        int i;
 
@@ -1927,4 +1908,5 @@ void libertas_debug_init(wlan_private * priv, struct net_device *dev)
                                                  priv->debugfs_dir, &items[0],
                                                  &libertas_debug_fops);
 }
+#endif
 
index dfe27642322c9d49f264fe277f940cc338ff9987..40f56bb1eac8332aa9b172df9778d8778d2116e4 100644 (file)
@@ -6,6 +6,8 @@
 #ifndef _WLAN_DECL_H_
 #define _WLAN_DECL_H_
 
+#include <linux/device.h>
+
 #include "defs.h"
 
 /** Function Prototype Declaration */
@@ -66,18 +68,24 @@ void libertas_ps_wakeup(wlan_private * priv, int wait_option);
 
 void libertas_tx_runqueue(wlan_private *priv);
 
-extern struct chan_freq_power *libertas_find_cfp_by_band_and_channel(
+struct chan_freq_power *libertas_find_cfp_by_band_and_channel(
                                wlan_adapter * adapter, u8 band, u16 channel);
 
-extern void libertas_mac_event_disconnected(wlan_private * priv);
+void libertas_mac_event_disconnected(wlan_private * priv);
 
 void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str);
 
-int reset_device(wlan_private *priv);
+/* fw.c */
+int libertas_init_fw(wlan_private * priv, char *fw_name);
+
 /* main.c */
-extern struct chan_freq_power *libertas_get_region_cfp_table(u8 region, u8 band,
+struct chan_freq_power *libertas_get_region_cfp_table(u8 region, u8 band,
                                                             int *cfp_no);
-wlan_private *wlan_add_card(void *card);
-int wlan_remove_card(void *card);
+wlan_private *libertas_add_card(void *card, struct device *dmdev);
+int libertas_activate_card(wlan_private *priv, char *fw_name);
+int libertas_remove_card(wlan_private *priv);
+int libertas_add_mesh(wlan_private *priv, struct device *dev);
+void libertas_remove_mesh(wlan_private *priv);
+
 
 #endif                         /* _WLAN_DECL_H_ */
index 80dd9ea19c8e4b7ea2faa8c4cbf5874acc77e0a6..4dd43e59bda004422ddfd6ca5b8540edb54cc702 100644 (file)
@@ -7,14 +7,79 @@
 
 #include <linux/spinlock.h>
 
-extern unsigned int libertas_debug;
-
 #ifdef CONFIG_LIBERTAS_DEBUG
 #define DEBUG
 #define PROC_DEBUG
 #endif
 
-#define DRV_NAME               "usb8xxx"
+#ifndef DRV_NAME
+#define DRV_NAME "libertas"
+#endif
+
+
+#define LBS_DEB_ENTER  0x00000001
+#define LBS_DEB_LEAVE  0x00000002
+#define LBS_DEB_MAIN   0x00000004
+#define LBS_DEB_NET    0x00000008
+#define LBS_DEB_MESH   0x00000010
+#define LBS_DEB_WEXT   0x00000020
+#define LBS_DEB_IOCTL  0x00000040
+#define LBS_DEB_SCAN   0x00000080
+#define LBS_DEB_ASSOC  0x00000100
+#define LBS_DEB_JOIN   0x00000200
+#define LBS_DEB_11D    0x00000400
+#define LBS_DEB_DEBUGFS        0x00000800
+#define LBS_DEB_ETHTOOL        0x00001000
+#define LBS_DEB_HOST   0x00002000
+#define LBS_DEB_CMD    0x00004000
+#define LBS_DEB_RX     0x00008000
+#define LBS_DEB_TX     0x00010000
+#define LBS_DEB_USB    0x00020000
+#define LBS_DEB_CS     0x00040000
+#define LBS_DEB_FW     0x00080000
+#define LBS_DEB_THREAD 0x00100000
+#define LBS_DEB_HEX    0x00200000
+
+extern unsigned int libertas_debug;
+
+#ifdef DEBUG
+#define LBS_DEB_LL(grp, fmt, args...) \
+do { if ((libertas_debug & (grp)) == (grp)) \
+  printk(KERN_DEBUG DRV_NAME "%s: " fmt, \
+         in_interrupt() ? " (INT)" : "", ## args); } while (0)
+#else
+#define LBS_DEB_LL(grp, fmt, args...) do {} while (0)
+#endif
+
+#define lbs_deb_enter(grp) \
+  LBS_DEB_LL(grp | LBS_DEB_ENTER, "%s():%d enter\n", __FUNCTION__, __LINE__);
+#define lbs_deb_enter_args(grp, fmt, args...) \
+  LBS_DEB_LL(grp | LBS_DEB_ENTER, "%s(" fmt "):%d\n", __FUNCTION__, ## args, __LINE__);
+#define lbs_deb_leave(grp) \
+  LBS_DEB_LL(grp | LBS_DEB_LEAVE, "%s():%d leave\n", __FUNCTION__, __LINE__);
+#define lbs_deb_leave_args(grp, fmt, args...) \
+  LBS_DEB_LL(grp | LBS_DEB_LEAVE, "%s():%d leave, " fmt "\n", \
+  __FUNCTION__, __LINE__, ##args);
+#define lbs_deb_main(fmt, args...)      LBS_DEB_LL(LBS_DEB_MAIN, fmt, ##args)
+#define lbs_deb_net(fmt, args...)       LBS_DEB_LL(LBS_DEB_NET, fmt, ##args)
+#define lbs_deb_mesh(fmt, args...)      LBS_DEB_LL(LBS_DEB_MESH, fmt, ##args)
+#define lbs_deb_wext(fmt, args...)      LBS_DEB_LL(LBS_DEB_WEXT, fmt, ##args)
+#define lbs_deb_ioctl(fmt, args...)     LBS_DEB_LL(LBS_DEB_IOCTL, fmt, ##args)
+#define lbs_deb_scan(fmt, args...)      LBS_DEB_LL(LBS_DEB_SCAN, fmt, ##args)
+#define lbs_deb_assoc(fmt, args...)     LBS_DEB_LL(LBS_DEB_ASSOC, fmt, ##args)
+#define lbs_deb_join(fmt, args...)      LBS_DEB_LL(LBS_DEB_JOIN, fmt, ##args)
+#define lbs_deb_11d(fmt, args...)       LBS_DEB_LL(LBS_DEB_11D, fmt, ##args)
+#define lbs_deb_debugfs(fmt, args...)   LBS_DEB_LL(LBS_DEB_DEBUGFS, fmt, ##args)
+#define lbs_deb_ethtool(fmt, args...)   LBS_DEB_LL(LBS_DEB_ETHTOOL, fmt, ##args)
+#define lbs_deb_host(fmt, args...)      LBS_DEB_LL(LBS_DEB_HOST, fmt, ##args)
+#define lbs_deb_cmd(fmt, args...)       LBS_DEB_LL(LBS_DEB_CMD, fmt, ##args)
+#define lbs_deb_rx(fmt, args...)        LBS_DEB_LL(LBS_DEB_RX, fmt, ##args)
+#define lbs_deb_tx(fmt, args...)        LBS_DEB_LL(LBS_DEB_TX, fmt, ##args)
+#define lbs_deb_fw(fmt, args...)        LBS_DEB_LL(LBS_DEB_FW, fmt, ##args)
+#define lbs_deb_usb(fmt, args...)       LBS_DEB_LL(LBS_DEB_USB, fmt, ##args)
+#define lbs_deb_usbd(dev, fmt, args...) LBS_DEB_LL(LBS_DEB_USB, "%s:" fmt, (dev)->bus_id, ##args)
+#define lbs_deb_cs(fmt, args...)        LBS_DEB_LL(LBS_DEB_CS, fmt, ##args)
+#define lbs_deb_thread(fmt, args...)    LBS_DEB_LL(LBS_DEB_THREAD, fmt, ##args)
 
 #define lbs_pr_info(format, args...) \
        printk(KERN_INFO DRV_NAME": " format, ## args)
@@ -24,37 +89,25 @@ extern unsigned int libertas_debug;
        printk(KERN_ALERT DRV_NAME": " format, ## args)
 
 #ifdef DEBUG
-#define lbs_pr_debug(level, format, args...) \
-       do { if (libertas_debug >= level) \
-       printk(KERN_INFO DRV_NAME": " format, ##args); } while (0)
-#define lbs_dev_dbg(level, device, format, args...) \
-        lbs_pr_debug(level, "%s: " format, \
-        (device)->bus_id , ## args)
-
 static inline void lbs_dbg_hex(char *prompt, u8 * buf, int len)
 {
        int i = 0;
 
-       if (!libertas_debug)
+       if (!(libertas_debug & LBS_DEB_HEX))
                return;
 
        printk(KERN_DEBUG "%s: ", prompt);
        for (i = 1; i <= len; i++) {
-               printk(KERN_DEBUG "%02x ", (u8) * buf);
+               printk("%02x ", (u8) * buf);
                buf++;
        }
        printk("\n");
 }
 #else
-#define lbs_pr_debug(level, format, args...)           do {} while (0)
-#define lbs_dev_dbg(level, device, format, args...)    do {} while (0)
 #define lbs_dbg_hex(x,y,z)                             do {} while (0)
 #endif
 
-#define        ENTER()                 lbs_pr_debug(1, "Enter: %s, %s:%i\n", \
-                                       __FUNCTION__, __FILE__, __LINE__)
-#define        LEAVE()                 lbs_pr_debug(1, "Leave: %s, %s:%i\n", \
-                                       __FUNCTION__, __FILE__, __LINE__)
+
 
 /** Buffer Constants */
 
@@ -74,7 +127,6 @@ static inline void lbs_dbg_hex(char *prompt, u8 * buf, int len)
 #define MRVDRV_NUM_OF_CMD_BUFFER        10
 #define MRVDRV_SIZE_OF_CMD_BUFFER       (2 * 1024)
 #define MRVDRV_MAX_CHANNEL_SIZE                14
-#define MRVDRV_MAX_BSSID_LIST          64
 #define MRVDRV_ASSOCIATION_TIME_OUT    255
 #define MRVDRV_SNAP_HEADER_LEN          8
 
@@ -104,6 +156,13 @@ static inline void lbs_dbg_hex(char *prompt, u8 * buf, int len)
 #define MRVDRV_MAX_BEACON_INTERVAL             1000
 #define MRVDRV_BEACON_INTERVAL                 100
 
+/** INT status Bit Definition*/
+#define his_cmddnldrdy                 0x01
+#define his_cardevent                  0x02
+#define his_cmdupldrdy                 0x04
+
+#define SBI_EVENT_CAUSE_SHIFT          3
+
 /** TxPD status */
 
 /*     Station firmware use TxPD status field to report final Tx transmit
@@ -205,8 +264,6 @@ typedef struct _wlan_adapter wlan_adapter;
 extern const char libertas_driver_version[];
 extern u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE];
 
-extern u8 libertas_wlan_data_rates[WLAN_SUPPORTED_RATES];
-
 extern u8 libertas_supported_rates[G_SUPPORTED_RATES];
 
 extern u8 libertas_adhoc_rates_g[G_SUPPORTED_RATES];
@@ -316,6 +373,8 @@ enum SNMP_MIB_VALUE_e {
 /* Default values for fwt commands. */
 #define FWT_DEFAULT_METRIC 0
 #define FWT_DEFAULT_DIR 1
+/* Default Rate, 11Mbps */
+#define FWT_DEFAULT_RATE 3
 #define FWT_DEFAULT_SSN 0xffffffff
 #define FWT_DEFAULT_DSN 0
 #define FWT_DEFAULT_HOPCOUNT 0
index e8b9020f9bd69676654177a54944cbd4e1fb5751..785192b884bc27c1419d7aff773c8d477b1fb21a 100644 (file)
@@ -63,11 +63,11 @@ struct wlan_802_11_security {
 
 /** Current Basic Service Set State Structure */
 struct current_bss_params {
-       struct bss_descriptor bssdescriptor;
        /** bssid */
        u8 bssid[ETH_ALEN];
        /** ssid */
-       struct WLAN_802_11_SSID ssid;
+       u8 ssid[IW_ESSID_MAX_SIZE + 1];
+       u8 ssid_len;
 
        /** band */
        u8 band;
@@ -89,31 +89,6 @@ struct sleep_params {
        u16 sp_reserved;
 };
 
-/** Data structure for the Marvell WLAN device */
-typedef struct _wlan_dev {
-       /** device name */
-       char name[DEV_NAME_LEN];
-       /** card pointer */
-       void *card;
-       /** IO port */
-       u32 ioport;
-       /** Upload received */
-       u32 upld_rcv;
-       /** Upload type */
-       u32 upld_typ;
-       /** Upload length */
-       u32 upld_len;
-       /** netdev pointer */
-       struct net_device *netdev;
-       /* Upload buffer */
-       u8 upld_buf[WLAN_UPLD_SIZE];
-       /* Download sent:
-          bit0 1/0=data_sent/data_tx_done,
-          bit1 1/0=cmd_sent/cmd_tx_done,
-          all other bits reserved 0 */
-       u8 dnld_sent;
-} wlan_dev_t, *pwlan_dev_t;
-
 /* Mesh statistics */
 struct wlan_mesh_stats {
        u32     fwd_bcast_cnt;          /* Fwd: Broadcast counter */
@@ -123,6 +98,7 @@ struct wlan_mesh_stats {
        u32     fwd_drop_noroute;       /* Fwd: No route to Destination */
        u32     fwd_drop_nobuf;         /* Fwd: Run out of internal buffers */
        u32     drop_blind;             /* Rx:  Dropped by blinding table */
+       u32     tx_failed_cnt;          /* Tx:  Failed transmissions */
 };
 
 /** Private structure for the MV device */
@@ -131,8 +107,11 @@ struct _wlan_private {
        int mesh_open;
        int infra_open;
 
+       char name[DEV_NAME_LEN];
+
+       void *card;
        wlan_adapter *adapter;
-       wlan_dev_t wlan_dev;
+       struct net_device *dev;
 
        struct net_device_stats stats;
        struct net_device *mesh_dev ; /* Virtual device */
@@ -153,6 +132,16 @@ struct _wlan_private {
        u32 bbp_offset;
        u32 rf_offset;
 
+       /** Upload length */
+       u32 upld_len;
+       /* Upload buffer */
+       u8 upld_buf[WLAN_UPLD_SIZE];
+       /* Download sent:
+          bit0 1/0=data_sent/data_tx_done,
+          bit1 1/0=cmd_sent/cmd_tx_done,
+          all other bits reserved 0 */
+       u8 dnld_sent;
+
        const struct firmware *firmware;
        struct device *hotplug_device;
 
@@ -161,6 +150,15 @@ struct _wlan_private {
 
        struct delayed_work assoc_work;
        struct workqueue_struct *assoc_thread;
+       struct work_struct sync_channel;
+
+       /** Hardware access */
+       int (*hw_register_dev) (wlan_private * priv);
+       int (*hw_unregister_dev) (wlan_private *);
+       int (*hw_prog_firmware) (wlan_private *);
+       int (*hw_host_to_card) (wlan_private * priv, u8 type, u8 * payload, u16 nb);
+       int (*hw_get_int_status) (wlan_private * priv, u8 *);
+       int (*hw_read_event_cause) (wlan_private *);
 };
 
 /** Association request
@@ -171,18 +169,21 @@ struct _wlan_private {
 struct assoc_request {
 #define ASSOC_FLAG_SSID                        1
 #define ASSOC_FLAG_CHANNEL             2
-#define ASSOC_FLAG_MODE                        3
-#define ASSOC_FLAG_BSSID               4
-#define ASSOC_FLAG_WEP_KEYS            5
-#define ASSOC_FLAG_WEP_TX_KEYIDX       6
-#define ASSOC_FLAG_WPA_MCAST_KEY       7
-#define ASSOC_FLAG_WPA_UCAST_KEY       8
-#define ASSOC_FLAG_SECINFO             9
-#define ASSOC_FLAG_WPA_IE              10
+#define ASSOC_FLAG_BAND                        3
+#define ASSOC_FLAG_MODE                        4
+#define ASSOC_FLAG_BSSID               5
+#define ASSOC_FLAG_WEP_KEYS            6
+#define ASSOC_FLAG_WEP_TX_KEYIDX       7
+#define ASSOC_FLAG_WPA_MCAST_KEY       8
+#define ASSOC_FLAG_WPA_UCAST_KEY       9
+#define ASSOC_FLAG_SECINFO             10
+#define ASSOC_FLAG_WPA_IE              11
        unsigned long flags;
 
-       struct WLAN_802_11_SSID ssid;
+       u8 ssid[IW_ESSID_MAX_SIZE + 1];
+       u8 ssid_len;
        u8 channel;
+       u8 band;
        u8 mode;
        u8 bssid[ETH_ALEN];