iwlwifi: add missing rcu_read_lock
[safe/jmp/linux-2.6] / drivers / net / wireless / libertas / cmd.c
index c455b9a..cdb9b96 100644 (file)
@@ -3,20 +3,21 @@
   * It prepares command and sends it to firmware when it is ready.
   */
 
-#include <net/iw_handler.h>
-#include <net/lib80211.h>
 #include <linux/kfifo.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+
 #include "host.h"
-#include "hostcmd.h"
 #include "decl.h"
 #include "defs.h"
 #include "dev.h"
 #include "assoc.h"
 #include "wext.h"
+#include "scan.h"
 #include "cmd.h"
 
-static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
 
+static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
 
 /**
  *  @brief Simple callback that copies response back into command
@@ -76,6 +77,30 @@ static u8 is_command_allowed_in_ps(u16 cmd)
 }
 
 /**
+ *  @brief This function checks if the command is allowed.
+ *
+ *  @param priv         A pointer to lbs_private structure
+ *  @return             allowed or not allowed.
+ */
+
+static int lbs_is_cmd_allowed(struct lbs_private *priv)
+{
+       int ret = 1;
+
+       lbs_deb_enter(LBS_DEB_CMD);
+
+       if (!priv->is_auto_deep_sleep_enabled) {
+               if (priv->is_deep_sleep) {
+                       lbs_deb_cmd("command not allowed in deep sleep\n");
+                       ret = 0;
+               }
+       }
+
+       lbs_deb_leave(LBS_DEB_CMD);
+       return ret;
+}
+
+/**
  *  @brief Updates the hardware details like MAC address and regulatory region
  *
  *  @param priv        A pointer to struct lbs_private structure
@@ -119,24 +144,17 @@ int lbs_update_hw_spec(struct lbs_private *priv)
        lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
                    cmd.hwifversion, cmd.version);
 
-       /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
-       /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
-       /* 5.110.22 have mesh command with 0xa3 command id */
-       /* 10.0.0.p0 FW brings in mesh config command with different id */
-       /* Check FW version MSB and initialize mesh_fw_ver */
-       if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5)
-               priv->mesh_fw_ver = MESH_FW_OLD;
-       else if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
-               (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK))
-               priv->mesh_fw_ver = MESH_FW_NEW;
-       else
-               priv->mesh_fw_ver = MESH_NONE;
-
        /* Clamp region code to 8-bit since FW spec indicates that it should
         * only ever be 8-bit, even though the field size is 16-bit.  Some firmware
         * returns non-zero high 8 bits here.
+        *
+        * Firmware version 4.0.102 used in CF8381 has region code shifted.  We
+        * need to check for this problem and handle it properly.
         */
-       priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
+       if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V4)
+               priv->regioncode = (le16_to_cpu(cmd.regioncode) >> 8) & 0xFF;
+       else
+               priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
 
        for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
                /* use the region code to search for the index */
@@ -162,11 +180,6 @@ int lbs_update_hw_spec(struct lbs_private *priv)
                goto out;
        }
 
-       if (lbs_set_universaltable(priv, 0)) {
-               ret = -1;
-               goto out;
-       }
-
 out:
        lbs_deb_leave(LBS_DEB_CMD);
        return ret;
@@ -215,7 +228,7 @@ static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *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);
+                               sizeof(struct cmd_header));
        psm->action = cpu_to_le16(cmd_action);
        psm->multipledtim = 0;
        switch (cmd_action) {
@@ -244,33 +257,6 @@ static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
        return 0;
 }
 
-int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
-                                     uint16_t cmd_action, uint16_t *timeout)
-{
-       struct cmd_ds_802_11_inactivity_timeout cmd;
-       int ret;
-
-       lbs_deb_enter(LBS_DEB_CMD);
-
-       cmd.hdr.command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
-       cmd.hdr.size = cpu_to_le16(sizeof(cmd));
-
-       cmd.action = cpu_to_le16(cmd_action);
-
-       if (cmd_action == CMD_ACT_SET)
-               cmd.timeout = cpu_to_le16(*timeout);
-       else
-               cmd.timeout = 0;
-
-       ret = lbs_cmd_with_response(priv, CMD_802_11_INACTIVITY_TIMEOUT, &cmd);
-
-       if (!ret)
-               *timeout = le16_to_cpu(cmd.timeout);
-
-       lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
-       return 0;
-}
-
 int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
                                struct sleep_params *sp)
 {
@@ -313,190 +299,53 @@ int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
        return 0;
 }
 
-int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action,
-                          struct assoc_request *assoc)
+static int lbs_wait_for_ds_awake(struct lbs_private *priv)
 {
-       struct cmd_ds_802_11_set_wep cmd;
        int ret = 0;
 
        lbs_deb_enter(LBS_DEB_CMD);
 
-       memset(&cmd, 0, sizeof(cmd));
-       cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP);
-       cmd.hdr.size = cpu_to_le16(sizeof(cmd));
-
-       cmd.action = cpu_to_le16(cmd_action);
-
-       if (cmd_action == CMD_ACT_ADD) {
-               int i;
-
-               /* default tx key index */
-               cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx &
-                                          CMD_WEP_KEY_INDEX_MASK);
-
-               /* Copy key types and material to host command structure */
-               for (i = 0; i < 4; i++) {
-                       struct enc_key *pkey = &assoc->wep_keys[i];
-
-                       switch (pkey->len) {
-                       case KEY_LEN_WEP_40:
-                               cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
-                               memmove(cmd.keymaterial[i], pkey->key, pkey->len);
-                               lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
-                               break;
-                       case KEY_LEN_WEP_104:
-                               cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
-                               memmove(cmd.keymaterial[i], pkey->key, pkey->len);
-                               lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
-                               break;
-                       case 0:
-                               break;
-                       default:
-                               lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
-                                           i, pkey->len);
-                               ret = -1;
-                               goto done;
-                               break;
-                       }
+       if (priv->is_deep_sleep) {
+               if (!wait_event_interruptible_timeout(priv->ds_awake_q,
+                                       !priv->is_deep_sleep, (10 * HZ))) {
+                       lbs_pr_err("ds_awake_q: timer expired\n");
+                       ret = -1;
                }
-       } else if (cmd_action == CMD_ACT_REMOVE) {
-               /* ACT_REMOVE clears _all_ WEP keys */
-
-               /* default tx key index */
-               cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx &
-                                          CMD_WEP_KEY_INDEX_MASK);
-               lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
-       }
-
-       ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
-done:
-       lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
-       return ret;
-}
-
-int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action,
-                             uint16_t *enable)
-{
-       struct cmd_ds_802_11_enable_rsn cmd;
-       int ret;
-
-       lbs_deb_enter(LBS_DEB_CMD);
-
-       cmd.hdr.size = cpu_to_le16(sizeof(cmd));
-       cmd.action = cpu_to_le16(cmd_action);
-
-       if (cmd_action == CMD_ACT_GET)
-               cmd.enable = 0;
-       else {
-               if (*enable)
-                       cmd.enable = cpu_to_le16(CMD_ENABLE_RSN);
-               else
-                       cmd.enable = cpu_to_le16(CMD_DISABLE_RSN);
-               lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
        }
 
-       ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
-       if (!ret && cmd_action == CMD_ACT_GET)
-               *enable = le16_to_cpu(cmd.enable);
-
        lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
        return ret;
 }
 
-static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam,
-                            struct enc_key *key)
+int lbs_set_deep_sleep(struct lbs_private *priv, int deep_sleep)
 {
-       lbs_deb_enter(LBS_DEB_CMD);
-
-       if (key->flags & KEY_INFO_WPA_ENABLED)
-               keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
-       if (key->flags & KEY_INFO_WPA_UNICAST)
-               keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
-       if (key->flags & KEY_INFO_WPA_MCAST)
-               keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
-
-       keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
-       keyparam->keytypeid = cpu_to_le16(key->type);
-       keyparam->keylen = cpu_to_le16(key->len);
-       memcpy(keyparam->key, key->key, key->len);
-
-       /* Length field doesn't include the {type,length} header */
-       keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4);
-       lbs_deb_leave(LBS_DEB_CMD);
-}
-
-int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action,
-                               struct assoc_request *assoc)
-{
-       struct cmd_ds_802_11_key_material cmd;
-       int ret = 0;
-       int index = 0;
+       int ret =  0;
 
        lbs_deb_enter(LBS_DEB_CMD);
 
-       cmd.action = cpu_to_le16(cmd_action);
-       cmd.hdr.size = cpu_to_le16(sizeof(cmd));
-
-       if (cmd_action == CMD_ACT_GET) {
-               cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2);
-       } else {
-               memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet));
-
-               if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) {
-                       set_one_wpa_key(&cmd.keyParamSet[index],
-                                       &assoc->wpa_unicast_key);
-                       index++;
-               }
-
-               if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) {
-                       set_one_wpa_key(&cmd.keyParamSet[index],
-                                       &assoc->wpa_mcast_key);
-                       index++;
+       if (deep_sleep) {
+               if (priv->is_deep_sleep != 1) {
+                       lbs_deb_cmd("deep sleep: sleep\n");
+                       BUG_ON(!priv->enter_deep_sleep);
+                       ret = priv->enter_deep_sleep(priv);
+                       if (!ret) {
+                               netif_stop_queue(priv->dev);
+                               netif_carrier_off(priv->dev);
+                       }
+               } else {
+                       lbs_pr_err("deep sleep: already enabled\n");
                }
-
-               /* The common header and as many keys as we included */
-               cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd),
-                                                   keyParamSet[index]));
-       }
-       ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
-       /* Copy the returned key to driver private data */
-       if (!ret && cmd_action == CMD_ACT_GET) {
-               void *buf_ptr = cmd.keyParamSet;
-               void *resp_end = &(&cmd)[1];
-
-               while (buf_ptr < resp_end) {
-                       struct MrvlIEtype_keyParamSet *keyparam = buf_ptr;
-                       struct enc_key *key;
-                       uint16_t param_set_len = le16_to_cpu(keyparam->length);
-                       uint16_t key_len = le16_to_cpu(keyparam->keylen);
-                       uint16_t key_flags = le16_to_cpu(keyparam->keyinfo);
-                       uint16_t key_type = le16_to_cpu(keyparam->keytypeid);
-                       void *end;
-
-                       end = (void *)keyparam + sizeof(keyparam->type)
-                               + sizeof(keyparam->length) + param_set_len;
-
-                       /* Make sure we don't access past the end of the IEs */
-                       if (end > resp_end)
-                               break;
-
-                       if (key_flags & KEY_INFO_WPA_UNICAST)
-                               key = &priv->wpa_unicast_key;
-                       else if (key_flags & KEY_INFO_WPA_MCAST)
-                               key = &priv->wpa_mcast_key;
-                       else
-                               break;
-
-                       /* Copy returned key into driver */
-                       memset(key, 0, sizeof(struct enc_key));
-                       if (key_len > sizeof(key->key))
-                               break;
-                       key->type = key_type;
-                       key->flags = key_flags;
-                       key->len = key_len;
-                       memcpy(key->key, keyparam->key, key->len);
-
-                       buf_ptr = end + 1;
+       } else {
+               if (priv->is_deep_sleep) {
+                       lbs_deb_cmd("deep sleep: wakeup\n");
+                       BUG_ON(!priv->exit_deep_sleep);
+                       ret = priv->exit_deep_sleep(priv);
+                       if (!ret) {
+                               ret = lbs_wait_for_ds_awake(priv);
+                               if (ret)
+                                       lbs_pr_err("deep sleep: wakeup"
+                                                       "failed\n");
+                       }
                }
        }
 
@@ -528,7 +377,7 @@ int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
        switch (oid) {
        case SNMP_MIB_OID_BSS_TYPE:
                cmd.bufsize = cpu_to_le16(sizeof(u8));
-               cmd.value[0] = (val == IW_MODE_ADHOC) ? 2 : 1;
+               cmd.value[0] = val;
                break;
        case SNMP_MIB_OID_11D_ENABLE:
        case SNMP_MIB_OID_FRAG_THRESHOLD:
@@ -581,13 +430,7 @@ int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
 
        switch (le16_to_cpu(cmd.bufsize)) {
        case sizeof(u8):
-               if (oid == SNMP_MIB_OID_BSS_TYPE) {
-                       if (cmd.value[0] == 2)
-                               *out_val = IW_MODE_ADHOC;
-                       else
-                               *out_val = IW_MODE_INFRA;
-               } else
-                       *out_val = cmd.value[0];
+               *out_val = cmd.value[0];
                break;
        case sizeof(u16):
                *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
@@ -674,7 +517,7 @@ static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
        cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
        cmd->size =
            cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
-                            S_DS_GEN);
+                            sizeof(struct cmd_header));
 
        monitor->action = cpu_to_le16(cmd_action);
        if (cmd_action == CMD_ACT_SET) {
@@ -685,111 +528,6 @@ static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
        return 0;
 }
 
-static __le16 lbs_rate_to_fw_bitmap(int rate, int lower_rates_ok)
-{
-/*             Bit     Rate
-*              15:13 Reserved
-*              12    54 Mbps
-*              11    48 Mbps
-*              10    36 Mbps
-*              9     24 Mbps
-*              8     18 Mbps
-*              7     12 Mbps
-*              6     9 Mbps
-*              5     6 Mbps
-*              4     Reserved
-*              3     11 Mbps
-*              2     5.5 Mbps
-*              1     2 Mbps
-*              0     1 Mbps
-**/
-
-       uint16_t ratemask;
-       int i = lbs_data_rate_to_fw_index(rate);
-       if (lower_rates_ok)
-               ratemask = (0x1fef >> (12 - i));
-       else
-               ratemask = (1 << i);
-       return cpu_to_le16(ratemask);
-}
-
-int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
-                                     uint16_t cmd_action)
-{
-       struct cmd_ds_802_11_rate_adapt_rateset cmd;
-       int ret;
-
-       lbs_deb_enter(LBS_DEB_CMD);
-
-       if (!priv->cur_rate && !priv->enablehwauto)
-               return -EINVAL;
-
-       cmd.hdr.size = cpu_to_le16(sizeof(cmd));
-
-       cmd.action = cpu_to_le16(cmd_action);
-       cmd.enablehwauto = cpu_to_le16(priv->enablehwauto);
-       cmd.bitmap = lbs_rate_to_fw_bitmap(priv->cur_rate, priv->enablehwauto);
-       ret = lbs_cmd_with_response(priv, CMD_802_11_RATE_ADAPT_RATESET, &cmd);
-       if (!ret && cmd_action == CMD_ACT_GET) {
-               priv->ratebitmap = le16_to_cpu(cmd.bitmap);
-               priv->enablehwauto = le16_to_cpu(cmd.enablehwauto);
-       }
-
-       lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
-       return ret;
-}
-EXPORT_SYMBOL_GPL(lbs_cmd_802_11_rate_adapt_rateset);
-
-/**
- *  @brief Set the data rate
- *
- *  @param priv        A pointer to struct lbs_private structure
- *  @param rate        The desired data rate, or 0 to clear a locked rate
- *
- *  @return            0 on success, error on failure
- */
-int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
-{
-       struct cmd_ds_802_11_data_rate cmd;
-       int ret = 0;
-
-       lbs_deb_enter(LBS_DEB_CMD);
-
-       memset(&cmd, 0, sizeof(cmd));
-       cmd.hdr.size = cpu_to_le16(sizeof(cmd));
-
-       if (rate > 0) {
-               cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
-               cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
-               if (cmd.rates[0] == 0) {
-                       lbs_deb_cmd("DATA_RATE: invalid requested rate of"
-                                   " 0x%02X\n", rate);
-                       ret = 0;
-                       goto out;
-               }
-               lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
-       } else {
-               cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
-               lbs_deb_cmd("DATA_RATE: setting auto\n");
-       }
-
-       ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
-       if (ret)
-               goto out;
-
-       lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
-
-       /* FIXME: get actual rates FW can do if this command actually returns
-        * all data rates supported.
-        */
-       priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
-       lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
-
-out:
-       lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
-       return ret;
-}
-
 /**
  *  @brief Get the radio channel
  *
@@ -797,7 +535,7 @@ out:
  *
  *  @return            The channel on success, error on failure
  */
-int lbs_get_channel(struct lbs_private *priv)
+static int lbs_get_channel(struct lbs_private *priv)
 {
        struct cmd_ds_802_11_rf_channel cmd;
        int ret = 0;
@@ -829,7 +567,7 @@ int lbs_update_channel(struct lbs_private *priv)
 
        ret = lbs_get_channel(priv);
        if (ret > 0) {
-               priv->curbssparams.channel = ret;
+               priv->channel = ret;
                ret = 0;
        }
        lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
@@ -848,7 +586,7 @@ int lbs_set_channel(struct lbs_private *priv, u8 channel)
 {
        struct cmd_ds_802_11_rf_channel cmd;
 #ifdef DEBUG
-       u8 old_channel = priv->curbssparams.channel;
+       u8 old_channel = priv->channel;
 #endif
        int ret = 0;
 
@@ -863,36 +601,15 @@ int lbs_set_channel(struct lbs_private *priv, u8 channel)
        if (ret)
                goto out;
 
-       priv->curbssparams.channel = (uint8_t) le16_to_cpu(cmd.channel);
+       priv->channel = (uint8_t) le16_to_cpu(cmd.channel);
        lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
-               priv->curbssparams.channel);
+               priv->channel);
 
 out:
        lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
        return ret;
 }
 
-static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
-                               struct cmd_ds_command *cmd)
-{
-
-       lbs_deb_enter(LBS_DEB_CMD);
-       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 = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
-
-       /* reset Beacon SNR/NF/RSSI values */
-       priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
-       priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
-       priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
-       priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
-       priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
-       priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
-
-       lbs_deb_leave(LBS_DEB_CMD);
-       return 0;
-}
-
 static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
                               u8 cmd_action, void *pdata_buf)
 {
@@ -909,7 +626,7 @@ static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
 
                        cmdptr->size =
                            cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
-                                       + S_DS_GEN);
+                                       + sizeof(struct cmd_header));
                        macreg =
                            (struct cmd_ds_mac_reg_access *)&cmdptr->params.
                            macreg;
@@ -928,7 +645,7 @@ static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
                        cmdptr->size =
                            cpu_to_le16(sizeof
                                             (struct cmd_ds_bbp_reg_access)
-                                            + S_DS_GEN);
+                                            + sizeof(struct cmd_header));
                        bbpreg =
                            (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
                            bbpreg;
@@ -947,7 +664,7 @@ static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
                        cmdptr->size =
                            cpu_to_le16(sizeof
                                             (struct cmd_ds_rf_reg_access) +
-                                            S_DS_GEN);
+                                            sizeof(struct cmd_header));
                        rfreg =
                            (struct cmd_ds_rf_reg_access *)&cmdptr->params.
                            rfreg;
@@ -967,192 +684,6 @@ static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
        return 0;
 }
 
-static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
-                              u16 cmd_action, void *pdata_buf)
-{
-       struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
-       lbs_deb_enter_args(LBS_DEB_CMD, "action %d", 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->result = 0;
-       bt_access->action = cpu_to_le16(cmd_action);
-
-       switch (cmd_action) {
-       case CMD_ACT_BT_ACCESS_ADD:
-               memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
-               lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
-               break;
-       case CMD_ACT_BT_ACCESS_DEL:
-               memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
-               lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
-               break;
-       case CMD_ACT_BT_ACCESS_LIST:
-               bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
-               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;
-       }
-       lbs_deb_leave(LBS_DEB_CMD);
-       return 0;
-}
-
-static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
-                              u16 cmd_action, void *pdata_buf)
-{
-       struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
-       lbs_deb_enter_args(LBS_DEB_CMD, "action %d", 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->result = 0;
-
-       if (pdata_buf)
-               memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
-       else
-               memset(fwt_access, 0, sizeof(*fwt_access));
-
-       fwt_access->action = cpu_to_le16(cmd_action);
-
-       lbs_deb_leave(LBS_DEB_CMD);
-       return 0;
-}
-
-int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
-                   struct cmd_ds_mesh_access *cmd)
-{
-       int ret;
-
-       lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
-
-       cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
-       cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
-       cmd->hdr.result = 0;
-
-       cmd->action = cpu_to_le16(cmd_action);
-
-       ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
-
-       lbs_deb_leave(LBS_DEB_CMD);
-       return ret;
-}
-
-static int __lbs_mesh_config_send(struct lbs_private *priv,
-                                 struct cmd_ds_mesh_config *cmd,
-                                 uint16_t action, uint16_t type)
-{
-       int ret;
-       u16 command = CMD_MESH_CONFIG_OLD;
-
-       lbs_deb_enter(LBS_DEB_CMD);
-
-       /*
-        * Command id is 0xac for v10 FW along with mesh interface
-        * id in bits 14-13-12.
-        */
-       if (priv->mesh_fw_ver == MESH_FW_NEW)
-               command = CMD_MESH_CONFIG |
-                         (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
-
-       cmd->hdr.command = cpu_to_le16(command);
-       cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
-       cmd->hdr.result = 0;
-
-       cmd->type = cpu_to_le16(type);
-       cmd->action = cpu_to_le16(action);
-
-       ret = lbs_cmd_with_response(priv, command, cmd);
-
-       lbs_deb_leave(LBS_DEB_CMD);
-       return ret;
-}
-
-int lbs_mesh_config_send(struct lbs_private *priv,
-                        struct cmd_ds_mesh_config *cmd,
-                        uint16_t action, uint16_t type)
-{
-       int ret;
-
-       if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
-               return -EOPNOTSUPP;
-
-       ret = __lbs_mesh_config_send(priv, cmd, action, type);
-       return ret;
-}
-
-/* This function is the CMD_MESH_CONFIG legacy function.  It only handles the
- * START and STOP actions.  The extended actions supported by CMD_MESH_CONFIG
- * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
- * lbs_mesh_config_send.
- */
-int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
-{
-       struct cmd_ds_mesh_config cmd;
-       struct mrvl_meshie *ie;
-       DECLARE_SSID_BUF(ssid);
-
-       memset(&cmd, 0, sizeof(cmd));
-       cmd.channel = cpu_to_le16(chan);
-       ie = (struct mrvl_meshie *)cmd.data;
-
-       switch (action) {
-       case CMD_ACT_MESH_CONFIG_START:
-               ie->id = WLAN_EID_GENERIC;
-               ie->val.oui[0] = 0x00;
-               ie->val.oui[1] = 0x50;
-               ie->val.oui[2] = 0x43;
-               ie->val.type = MARVELL_MESH_IE_TYPE;
-               ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
-               ie->val.version = MARVELL_MESH_IE_VERSION;
-               ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
-               ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
-               ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
-               ie->val.mesh_id_len = priv->mesh_ssid_len;
-               memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
-               ie->len = sizeof(struct mrvl_meshie_val) -
-                       IW_ESSID_MAX_SIZE + priv->mesh_ssid_len;
-               cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
-               break;
-       case CMD_ACT_MESH_CONFIG_STOP:
-               break;
-       default:
-               return -1;
-       }
-       lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
-                   action, priv->mesh_tlv, chan,
-                   print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
-
-       return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
-}
-
-static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
-                               struct cmd_ds_command *cmd,
-                               u16 cmd_action)
-{
-       struct cmd_ds_802_11_beacon_control
-               *bcn_ctrl = &cmd->params.bcn_ctrl;
-
-       lbs_deb_enter(LBS_DEB_CMD);
-       cmd->size =
-           cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
-                            + S_DS_GEN);
-       cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
-
-       bcn_ctrl->action = cpu_to_le16(cmd_action);
-       bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
-       bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
-
-       lbs_deb_leave(LBS_DEB_CMD);
-       return 0;
-}
-
 static void lbs_queue_cmd(struct lbs_private *priv,
                          struct cmd_ctrl_node *cmdnode)
 {
@@ -1220,8 +751,7 @@ static void lbs_submit_command(struct lbs_private *priv,
        command = le16_to_cpu(cmd->command);
 
        /* These commands take longer */
-       if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE ||
-           command == CMD_802_11_AUTHENTICATE)
+       if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
                timeo = 5 * HZ;
 
        lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
@@ -1237,8 +767,17 @@ static void lbs_submit_command(struct lbs_private *priv,
                timeo = HZ/4;
        }
 
-       /* Setup the timer after transmit command */
-       mod_timer(&priv->command_timer, jiffies + timeo);
+       if (command == CMD_802_11_DEEP_SLEEP) {
+               if (priv->is_auto_deep_sleep_enabled) {
+                       priv->wakeup_dev_required = 1;
+                       priv->dnld_sent = 0;
+               }
+               priv->is_deep_sleep = 1;
+               lbs_complete_command(priv, cmdnode, 0);
+       } else {
+               /* Setup the timer after transmit command */
+               mod_timer(&priv->command_timer, jiffies + timeo);
+       }
 
        lbs_deb_leave(LBS_DEB_HOST);
 }
@@ -1304,9 +843,6 @@ int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
        if (priv->fwrelease < 0x09000000) {
                switch (preamble) {
                case RADIO_PREAMBLE_SHORT:
-                       if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
-                               goto out;
-                       /* Fall through */
                case RADIO_PREAMBLE_AUTO:
                case RADIO_PREAMBLE_LONG:
                        cmd.control = cpu_to_le16(preamble);
@@ -1385,6 +921,11 @@ int lbs_prepare_and_send_command(struct lbs_private *priv,
                goto done;
        }
 
+       if (!lbs_is_cmd_allowed(priv)) {
+               ret = -EBUSY;
+               goto done;
+       }
+
        cmdnode = lbs_get_cmd_ctrl_node(priv);
 
        if (cmdnode == NULL) {
@@ -1415,15 +956,6 @@ int lbs_prepare_and_send_command(struct lbs_private *priv,
                ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
                break;
 
-       case CMD_802_11_ASSOCIATE:
-       case CMD_802_11_REASSOCIATE:
-               ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf);
-               break;
-
-       case CMD_802_11_AUTHENTICATE:
-               ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
-               break;
-
        case CMD_MAC_REG_ACCESS:
        case CMD_BBP_REG_ACCESS:
        case CMD_RF_REG_ACCESS:
@@ -1444,7 +976,7 @@ int lbs_prepare_and_send_command(struct lbs_private *priv,
 
                cmdptr->command = cpu_to_le16(cmd_no);
                cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
-                                          S_DS_GEN);
+                                          sizeof(struct cmd_header));
 
                memmove(&cmdptr->params.afc,
                        pdata_buf, sizeof(struct cmd_ds_802_11_afc));
@@ -1452,45 +984,19 @@ int lbs_prepare_and_send_command(struct lbs_private *priv,
                ret = 0;
                goto done;
 
-       case CMD_802_11D_DOMAIN_INFO:
-               ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
-                                                  cmd_no, cmd_action);
-               break;
-
        case CMD_802_11_TPC_CFG:
                cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
                cmdptr->size =
                    cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
-                                    S_DS_GEN);
+                                    sizeof(struct cmd_header));
 
                memmove(&cmdptr->params.tpccfg,
                        pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
 
                ret = 0;
                break;
-       case CMD_802_11_LED_GPIO_CTRL:
-               {
-                       struct mrvlietypes_ledgpio *gpio =
-                           (struct mrvlietypes_ledgpio*)
-                           cmdptr->params.ledgpio.data;
 
-                       memmove(&cmdptr->params.ledgpio,
-                               pdata_buf,
-                               sizeof(struct cmd_ds_802_11_led_ctrl));
-
-                       cmdptr->command =
-                           cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
-
-#define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
-                       cmdptr->size =
-                           cpu_to_le16(le16_to_cpu(gpio->header.len)
-                               + S_DS_GEN
-                               + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
-                       gpio->header.len = gpio->header.len;
-
-                       ret = 0;
-                       break;
-               }
+#ifdef CONFIG_LIBERTAS_MESH
 
        case CMD_BT_ACCESS:
                ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
@@ -1500,15 +1006,15 @@ int lbs_prepare_and_send_command(struct lbs_private *priv,
                ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
                break;
 
-       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);
-               ret = 0;
-               break;
+#endif
+
        case CMD_802_11_BEACON_CTRL:
                ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
                break;
+       case CMD_802_11_DEEP_SLEEP:
+               cmdptr->command = cpu_to_le16(CMD_802_11_DEEP_SLEEP);
+               cmdptr->size = cpu_to_le16(sizeof(struct cmd_header));
+               break;
        default:
                lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
                ret = -1;
@@ -1800,7 +1306,7 @@ int lbs_execute_next_command(struct lbs_private *priv)
                if ((priv->psmode != LBS802_11POWERMODECAM) &&
                    (priv->psstate == PS_STATE_FULL_POWER) &&
                    ((priv->connect_status == LBS_CONNECTED) ||
-                   (priv->mesh_connect_status == LBS_CONNECTED))) {
+                   lbs_mesh_connected(priv))) {
                        if (priv->secinfo.WPAenabled ||
                            priv->secinfo.WPA2enabled) {
                                /* check for valid WPA group keys */
@@ -1826,30 +1332,6 @@ done:
        return ret;
 }
 
-void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
-{
-       union iwreq_data iwrq;
-       u8 buf[50];
-
-       lbs_deb_enter(LBS_DEB_WEXT);
-
-       memset(&iwrq, 0, sizeof(union iwreq_data));
-       memset(buf, 0, sizeof(buf));
-
-       snprintf(buf, sizeof(buf) - 1, "%s", str);
-
-       iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
-
-       /* Send Event to upper layer */
-       lbs_deb_wext("event indication string %s\n", (char *)buf);
-       lbs_deb_wext("event indication length %d\n", iwrq.data.length);
-       lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
-
-       wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
-
-       lbs_deb_leave(LBS_DEB_WEXT);
-}
-
 static void lbs_send_confirmsleep(struct lbs_private *priv)
 {
        unsigned long flags;
@@ -1872,7 +1354,7 @@ static void lbs_send_confirmsleep(struct lbs_private *priv)
        priv->dnld_sent = DNLD_RES_RECEIVED;
 
        /* If nothing to do, go back to sleep (?) */
-       if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
+       if (!kfifo_len(&priv->event_fifo) && !priv->resp_len[priv->resp_idx])
                priv->psstate = PS_STATE_SLEEP;
 
        spin_unlock_irqrestore(&priv->driver_lock, flags);
@@ -1946,7 +1428,7 @@ void lbs_ps_confirm_sleep(struct lbs_private *priv)
        }
 
        /* Pending events or command responses? */
-       if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
+       if (kfifo_len(&priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
                allowed = 0;
                lbs_deb_host("pending events or command responses\n");
        }
@@ -2027,7 +1509,7 @@ int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
 }
 
 
-static struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
+struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
        uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
        int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
        unsigned long callback_arg)
@@ -2042,6 +1524,11 @@ static struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
                goto done;
        }
 
+       if (!lbs_is_cmd_allowed(priv)) {
+               cmdnode = ERR_PTR(-EBUSY);
+               goto done;
+       }
+
        cmdnode = lbs_get_cmd_ctrl_node(priv);
        if (cmdnode == NULL) {
                lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
@@ -2120,5 +1607,3 @@ done:
        return ret;
 }
 EXPORT_SYMBOL_GPL(__lbs_cmd);
-
-