These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / net / wireless / mwifiex / cmdevt.c
index c5a14ff..45ae38e 100644 (file)
@@ -62,7 +62,8 @@ mwifiex_get_cmd_node(struct mwifiex_adapter *adapter)
 
        spin_lock_irqsave(&adapter->cmd_free_q_lock, flags);
        if (list_empty(&adapter->cmd_free_q)) {
-               dev_err(adapter->dev, "GET_CMD_NODE: cmd node not available\n");
+               mwifiex_dbg(adapter, ERROR,
+                           "GET_CMD_NODE: cmd node not available\n");
                spin_unlock_irqrestore(&adapter->cmd_free_q_lock, flags);
                return NULL;
        }
@@ -116,7 +117,8 @@ static int mwifiex_cmd_host_cmd(struct mwifiex_private *priv,
 {
        /* Copy the HOST command to command buffer */
        memcpy(cmd, pcmd_ptr->cmd, pcmd_ptr->len);
-       dev_dbg(priv->adapter->dev, "cmd: host cmd size = %d\n", pcmd_ptr->len);
+       mwifiex_dbg(priv->adapter, CMD,
+                   "cmd: host cmd size = %d\n", pcmd_ptr->len);
        return 0;
 }
 
@@ -147,8 +149,9 @@ static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private *priv,
 
        /* Sanity test */
        if (host_cmd == NULL || host_cmd->size == 0) {
-               dev_err(adapter->dev, "DNLD_CMD: host_cmd is null"
-                       " or cmd size is 0, not sending\n");
+               mwifiex_dbg(adapter, ERROR,
+                           "DNLD_CMD: host_cmd is null\t"
+                           "or cmd size is 0, not sending\n");
                if (cmd_node->wait_q_enabled)
                        adapter->cmd_wait_q.status = -1;
                mwifiex_recycle_cmd_node(adapter, cmd_node);
@@ -161,11 +164,9 @@ static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private *priv,
        if (adapter->hw_status == MWIFIEX_HW_STATUS_RESET &&
            cmd_code != HostCmd_CMD_FUNC_SHUTDOWN &&
            cmd_code != HostCmd_CMD_FUNC_INIT) {
-               dev_err(adapter->dev,
-                       "DNLD_CMD: FW in reset state, ignore cmd %#x\n",
+               mwifiex_dbg(adapter, ERROR,
+                           "DNLD_CMD: FW in reset state, ignore cmd %#x\n",
                        cmd_code);
-               if (cmd_node->wait_q_enabled)
-                       mwifiex_complete_cmd(adapter, cmd_node);
                mwifiex_recycle_cmd_node(adapter, cmd_node);
                queue_work(adapter->workqueue, &adapter->main_work);
                return -1;
@@ -197,10 +198,12 @@ static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private *priv,
                 */
                skb_put(cmd_node->cmd_skb, cmd_size - cmd_node->cmd_skb->len);
 
-       dev_dbg(adapter->dev,
-               "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n", cmd_code,
-               le16_to_cpu(*(__le16 *) ((u8 *) host_cmd + S_DS_GEN)), cmd_size,
-               le16_to_cpu(host_cmd->seq_num));
+       mwifiex_dbg(adapter, CMD,
+                   "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n",
+                   cmd_code,
+                   le16_to_cpu(*(__le16 *)((u8 *)host_cmd + S_DS_GEN)),
+                   cmd_size, le16_to_cpu(host_cmd->seq_num));
+       mwifiex_dbg_dump(adapter, CMD_D, "cmd buffer:", host_cmd, cmd_size);
 
        if (adapter->iface_type == MWIFIEX_USB) {
                tmp = cpu_to_le32(MWIFIEX_USB_TYPE_CMD);
@@ -221,7 +224,8 @@ static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private *priv,
        }
 
        if (ret == -1) {
-               dev_err(adapter->dev, "DNLD_CMD: host to card failed\n");
+               mwifiex_dbg(adapter, ERROR,
+                           "DNLD_CMD: host to card failed\n");
                if (adapter->iface_type == MWIFIEX_USB)
                        adapter->cmd_sent = false;
                if (cmd_node->wait_q_enabled)
@@ -280,12 +284,14 @@ static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter *adapter)
                                        (adapter->seq_num, priv->bss_num,
                                         priv->bss_type)));
 
-       dev_dbg(adapter->dev,
-               "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n",
+       mwifiex_dbg(adapter, CMD,
+                   "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n",
                le16_to_cpu(sleep_cfm_buf->command),
                le16_to_cpu(sleep_cfm_buf->action),
                le16_to_cpu(sleep_cfm_buf->size),
                le16_to_cpu(sleep_cfm_buf->seq_num));
+       mwifiex_dbg_dump(adapter, CMD_D, "SLEEP_CFM buffer: ", sleep_cfm_buf,
+                        le16_to_cpu(sleep_cfm_buf->size));
 
        if (adapter->iface_type == MWIFIEX_USB) {
                sleep_cfm_tmp =
@@ -311,7 +317,7 @@ static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter *adapter)
        }
 
        if (ret == -1) {
-               dev_err(adapter->dev, "SLEEP_CFM: failed\n");
+               mwifiex_dbg(adapter, ERROR, "SLEEP_CFM: failed\n");
                adapter->dbg.num_cmd_sleep_cfm_host_to_card_failure++;
                return -1;
        }
@@ -362,8 +368,9 @@ int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter *adapter)
        for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) {
                cmd_array[i].skb = dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER);
                if (!cmd_array[i].skb) {
-                       dev_err(adapter->dev, "ALLOC_CMD_BUF: out of memory\n");
-                       return -1;
+                       mwifiex_dbg(adapter, ERROR,
+                                   "unable to allocate command buffer\n");
+                       return -ENOMEM;
                }
        }
 
@@ -386,7 +393,8 @@ int mwifiex_free_cmd_buffer(struct mwifiex_adapter *adapter)
 
        /* Need to check if cmd pool is allocated or not */
        if (!adapter->cmd_pool) {
-               dev_dbg(adapter->dev, "info: FREE_CMD_BUF: cmd_pool is null\n");
+               mwifiex_dbg(adapter, FATAL,
+                           "info: FREE_CMD_BUF: cmd_pool is null\n");
                return 0;
        }
 
@@ -395,7 +403,8 @@ int mwifiex_free_cmd_buffer(struct mwifiex_adapter *adapter)
        /* Release shared memory buffers */
        for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) {
                if (cmd_array[i].skb) {
-                       dev_dbg(adapter->dev, "cmd: free cmd buffer %d\n", i);
+                       mwifiex_dbg(adapter, CMD,
+                                   "cmd: free cmd buffer %d\n", i);
                        dev_kfree_skb_any(cmd_array[i].skb);
                }
                if (!cmd_array[i].resp_skb)
@@ -409,7 +418,8 @@ int mwifiex_free_cmd_buffer(struct mwifiex_adapter *adapter)
        }
        /* Release struct cmd_ctrl_node */
        if (adapter->cmd_pool) {
-               dev_dbg(adapter->dev, "cmd: free cmd pool\n");
+               mwifiex_dbg(adapter, CMD,
+                           "cmd: free cmd pool\n");
                kfree(adapter->cmd_pool);
                adapter->cmd_pool = NULL;
        }
@@ -457,9 +467,11 @@ int mwifiex_process_event(struct mwifiex_adapter *adapter)
                memset(rx_info, 0, sizeof(*rx_info));
                rx_info->bss_num = priv->bss_num;
                rx_info->bss_type = priv->bss_type;
+               mwifiex_dbg_dump(adapter, EVT_D, "Event Buf:",
+                                skb->data, skb->len);
        }
 
-       dev_dbg(adapter->dev, "EVENT: cause: %#x\n", eventcause);
+       mwifiex_dbg(adapter, EVENT, "EVENT: cause: %#x\n", eventcause);
 
        if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
                ret = mwifiex_process_uap_event(priv);
@@ -498,28 +510,33 @@ int mwifiex_send_cmd(struct mwifiex_private *priv, u16 cmd_no,
        }
 
        if (adapter->is_suspended) {
-               dev_err(adapter->dev, "PREP_CMD: device in suspended state\n");
+               mwifiex_dbg(adapter, ERROR,
+                           "PREP_CMD: device in suspended state\n");
                return -1;
        }
 
        if (adapter->hs_enabling && cmd_no != HostCmd_CMD_802_11_HS_CFG_ENH) {
-               dev_err(adapter->dev, "PREP_CMD: host entering sleep state\n");
+               mwifiex_dbg(adapter, ERROR,
+                           "PREP_CMD: host entering sleep state\n");
                return -1;
        }
 
        if (adapter->surprise_removed) {
-               dev_err(adapter->dev, "PREP_CMD: card is removed\n");
+               mwifiex_dbg(adapter, ERROR,
+                           "PREP_CMD: card is removed\n");
                return -1;
        }
 
        if (adapter->is_cmd_timedout) {
-               dev_err(adapter->dev, "PREP_CMD: FW is in bad state\n");
+               mwifiex_dbg(adapter, ERROR,
+                           "PREP_CMD: FW is in bad state\n");
                return -1;
        }
 
        if (adapter->hw_status == MWIFIEX_HW_STATUS_RESET) {
                if (cmd_no != HostCmd_CMD_FUNC_INIT) {
-                       dev_err(adapter->dev, "PREP_CMD: FW in reset state\n");
+                       mwifiex_dbg(adapter, ERROR,
+                                   "PREP_CMD: FW in reset state\n");
                        return -1;
                }
        }
@@ -528,7 +545,8 @@ int mwifiex_send_cmd(struct mwifiex_private *priv, u16 cmd_no,
        cmd_node = mwifiex_get_cmd_node(adapter);
 
        if (!cmd_node) {
-               dev_err(adapter->dev, "PREP_CMD: no free cmd node\n");
+               mwifiex_dbg(adapter, ERROR,
+                           "PREP_CMD: no free cmd node\n");
                return -1;
        }
 
@@ -536,7 +554,8 @@ int mwifiex_send_cmd(struct mwifiex_private *priv, u16 cmd_no,
        mwifiex_init_cmd_node(priv, cmd_node, cmd_oid, data_buf, sync);
 
        if (!cmd_node->cmd_skb) {
-               dev_err(adapter->dev, "PREP_CMD: no free cmd buf\n");
+               mwifiex_dbg(adapter, ERROR,
+                           "PREP_CMD: no free cmd buf\n");
                return -1;
        }
 
@@ -554,6 +573,8 @@ int mwifiex_send_cmd(struct mwifiex_private *priv, u16 cmd_no,
                case HostCmd_CMD_UAP_BSS_START:
                case HostCmd_CMD_UAP_BSS_STOP:
                case HostCmd_CMD_UAP_STA_DEAUTH:
+               case HOST_CMD_APCMD_SYS_RESET:
+               case HOST_CMD_APCMD_STA_LIST:
                        ret = mwifiex_uap_prepare_cmd(priv, cmd_no, cmd_action,
                                                      cmd_oid, data_buf,
                                                      cmd_ptr);
@@ -571,7 +592,8 @@ int mwifiex_send_cmd(struct mwifiex_private *priv, u16 cmd_no,
 
        /* Return error, since the command preparation failed */
        if (ret) {
-               dev_err(adapter->dev, "PREP_CMD: cmd %#x preparation failed\n",
+               mwifiex_dbg(adapter, ERROR,
+                           "PREP_CMD: cmd %#x preparation failed\n",
                        cmd_no);
                mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
                return -1;
@@ -626,7 +648,8 @@ void mwifiex_recycle_cmd_node(struct mwifiex_adapter *adapter,
        mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
 
        atomic_dec(&adapter->cmd_pending);
-       dev_dbg(adapter->dev, "cmd: FREE_CMD: cmd=%#x, cmd_pending=%d\n",
+       mwifiex_dbg(adapter, CMD,
+                   "cmd: FREE_CMD: cmd=%#x, cmd_pending=%d\n",
                le16_to_cpu(host_cmd->command),
                atomic_read(&adapter->cmd_pending));
 }
@@ -648,7 +671,7 @@ mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter *adapter,
 
        host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
        if (!host_cmd) {
-               dev_err(adapter->dev, "QUEUE_CMD: host_cmd is NULL\n");
+               mwifiex_dbg(adapter, ERROR, "QUEUE_CMD: host_cmd is NULL\n");
                return;
        }
 
@@ -673,7 +696,8 @@ mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter *adapter,
        spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
 
        atomic_inc(&adapter->cmd_pending);
-       dev_dbg(adapter->dev, "cmd: QUEUE_CMD: cmd=%#x, cmd_pending=%d\n",
+       mwifiex_dbg(adapter, CMD,
+                   "cmd: QUEUE_CMD: cmd=%#x, cmd_pending=%d\n",
                command, atomic_read(&adapter->cmd_pending));
 }
 
@@ -699,7 +723,8 @@ int mwifiex_exec_next_cmd(struct mwifiex_adapter *adapter)
 
        /* Check if already in processing */
        if (adapter->curr_cmd) {
-               dev_err(adapter->dev, "EXEC_NEXT_CMD: cmd in processing\n");
+               mwifiex_dbg(adapter, FATAL,
+                           "EXEC_NEXT_CMD: cmd in processing\n");
                return -1;
        }
 
@@ -721,8 +746,9 @@ int mwifiex_exec_next_cmd(struct mwifiex_adapter *adapter)
        priv = cmd_node->priv;
 
        if (adapter->ps_state != PS_STATE_AWAKE) {
-               dev_err(adapter->dev, "%s: cannot send cmd in sleep state,"
-                               " this should not happen\n", __func__);
+               mwifiex_dbg(adapter, ERROR,
+                           "%s: cannot send cmd in sleep state,\t"
+                           "this should not happen\n", __func__);
                spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
                return ret;
        }
@@ -772,29 +798,21 @@ int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter)
 
        if (!adapter->curr_cmd || !adapter->curr_cmd->resp_skb) {
                resp = (struct host_cmd_ds_command *) adapter->upld_buf;
-               dev_err(adapter->dev, "CMD_RESP: NULL curr_cmd, %#x\n",
-                       le16_to_cpu(resp->command));
+               mwifiex_dbg(adapter, ERROR,
+                           "CMD_RESP: NULL curr_cmd, %#x\n",
+                           le16_to_cpu(resp->command));
                return -1;
        }
 
        adapter->is_cmd_timedout = 0;
 
        resp = (struct host_cmd_ds_command *) adapter->curr_cmd->resp_skb->data;
-       if (adapter->curr_cmd->cmd_flag & CMD_F_CANCELED) {
-               dev_err(adapter->dev, "CMD_RESP: %#x been canceled\n",
-                       le16_to_cpu(resp->command));
-               mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
-               spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
-               adapter->curr_cmd = NULL;
-               spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
-               return -1;
-       }
-
        if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) {
                /* Copy original response back to response buffer */
                struct mwifiex_ds_misc_cmd *hostcmd;
                uint16_t size = le16_to_cpu(resp->size);
-               dev_dbg(adapter->dev, "info: host cmd resp size = %d\n", size);
+               mwifiex_dbg(adapter, INFO,
+                           "info: host cmd resp size = %d\n", size);
                size = min_t(u16, size, MWIFIEX_SIZE_OF_CMD_BUFFER);
                if (adapter->curr_cmd->data_buf) {
                        hostcmd = adapter->curr_cmd->data_buf;
@@ -822,13 +840,15 @@ int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter)
        adapter->dbg.last_cmd_resp_id[adapter->dbg.last_cmd_resp_index] =
                                                                orig_cmdresp_no;
 
-       dev_dbg(adapter->dev,
-               "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
-               orig_cmdresp_no, cmdresp_result,
-               le16_to_cpu(resp->size), le16_to_cpu(resp->seq_num));
+       mwifiex_dbg(adapter, CMD,
+                   "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
+                   orig_cmdresp_no, cmdresp_result,
+                   le16_to_cpu(resp->size), le16_to_cpu(resp->seq_num));
+       mwifiex_dbg_dump(adapter, CMD_D, "CMD_RESP buffer:", resp,
+                        le16_to_cpu(resp->size));
 
        if (!(orig_cmdresp_no & HostCmd_RET_BIT)) {
-               dev_err(adapter->dev, "CMD_RESP: invalid cmd resp\n");
+               mwifiex_dbg(adapter, ERROR, "CMD_RESP: invalid cmd resp\n");
                if (adapter->curr_cmd->wait_q_enabled)
                        adapter->cmd_wait_q.status = -1;
 
@@ -852,8 +872,9 @@ int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter)
        /* Check init command response */
        if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING) {
                if (ret) {
-                       dev_err(adapter->dev, "%s: cmd %#x failed during "
-                               "initialization\n", __func__, cmdresp_no);
+                       mwifiex_dbg(adapter, ERROR,
+                                   "%s: cmd %#x failed during\t"
+                                   "initialization\n", __func__, cmdresp_no);
                        mwifiex_init_fw_complete(adapter);
                        return -1;
                } else if (adapter->last_init_cmd == cmdresp_no)
@@ -888,7 +909,8 @@ mwifiex_cmd_timeout_func(unsigned long function_context)
 
        adapter->is_cmd_timedout = 1;
        if (!adapter->curr_cmd) {
-               dev_dbg(adapter->dev, "cmd: empty curr_cmd\n");
+               mwifiex_dbg(adapter, ERROR,
+                           "cmd: empty curr_cmd\n");
                return;
        }
        cmd_node = adapter->curr_cmd;
@@ -897,59 +919,73 @@ mwifiex_cmd_timeout_func(unsigned long function_context)
                        adapter->dbg.last_cmd_id[adapter->dbg.last_cmd_index];
                adapter->dbg.timeout_cmd_act =
                        adapter->dbg.last_cmd_act[adapter->dbg.last_cmd_index];
-               dev_err(adapter->dev,
-                       "%s: Timeout cmd id = %#x, act = %#x\n", __func__,
-                       adapter->dbg.timeout_cmd_id,
-                       adapter->dbg.timeout_cmd_act);
-
-               dev_err(adapter->dev, "num_data_h2c_failure = %d\n",
-                       adapter->dbg.num_tx_host_to_card_failure);
-               dev_err(adapter->dev, "num_cmd_h2c_failure = %d\n",
-                       adapter->dbg.num_cmd_host_to_card_failure);
-
-               dev_err(adapter->dev, "is_cmd_timedout = %d\n",
-                       adapter->is_cmd_timedout);
-               dev_err(adapter->dev, "num_tx_timeout = %d\n",
-                       adapter->dbg.num_tx_timeout);
-
-               dev_err(adapter->dev, "last_cmd_index = %d\n",
-                       adapter->dbg.last_cmd_index);
-               dev_err(adapter->dev, "last_cmd_id: %*ph\n",
-                       (int)sizeof(adapter->dbg.last_cmd_id),
-                       adapter->dbg.last_cmd_id);
-               dev_err(adapter->dev, "last_cmd_act: %*ph\n",
-                       (int)sizeof(adapter->dbg.last_cmd_act),
-                       adapter->dbg.last_cmd_act);
-
-               dev_err(adapter->dev, "last_cmd_resp_index = %d\n",
-                       adapter->dbg.last_cmd_resp_index);
-               dev_err(adapter->dev, "last_cmd_resp_id: %*ph\n",
-                       (int)sizeof(adapter->dbg.last_cmd_resp_id),
-                       adapter->dbg.last_cmd_resp_id);
-
-               dev_err(adapter->dev, "last_event_index = %d\n",
-                       adapter->dbg.last_event_index);
-               dev_err(adapter->dev, "last_event: %*ph\n",
-                       (int)sizeof(adapter->dbg.last_event),
-                       adapter->dbg.last_event);
-
-               dev_err(adapter->dev, "data_sent=%d cmd_sent=%d\n",
-                       adapter->data_sent, adapter->cmd_sent);
-
-               dev_err(adapter->dev, "ps_mode=%d ps_state=%d\n",
-                       adapter->ps_mode, adapter->ps_state);
+               mwifiex_dbg(adapter, MSG,
+                           "%s: Timeout cmd id = %#x, act = %#x\n", __func__,
+                           adapter->dbg.timeout_cmd_id,
+                           adapter->dbg.timeout_cmd_act);
+
+               mwifiex_dbg(adapter, MSG,
+                           "num_data_h2c_failure = %d\n",
+                           adapter->dbg.num_tx_host_to_card_failure);
+               mwifiex_dbg(adapter, MSG,
+                           "num_cmd_h2c_failure = %d\n",
+                           adapter->dbg.num_cmd_host_to_card_failure);
+
+               mwifiex_dbg(adapter, MSG,
+                           "is_cmd_timedout = %d\n",
+                           adapter->is_cmd_timedout);
+               mwifiex_dbg(adapter, MSG,
+                           "num_tx_timeout = %d\n",
+                           adapter->dbg.num_tx_timeout);
+
+               mwifiex_dbg(adapter, MSG,
+                           "last_cmd_index = %d\n",
+                           adapter->dbg.last_cmd_index);
+               mwifiex_dbg(adapter, MSG,
+                           "last_cmd_id: %*ph\n",
+                           (int)sizeof(adapter->dbg.last_cmd_id),
+                           adapter->dbg.last_cmd_id);
+               mwifiex_dbg(adapter, MSG,
+                           "last_cmd_act: %*ph\n",
+                           (int)sizeof(adapter->dbg.last_cmd_act),
+                           adapter->dbg.last_cmd_act);
+
+               mwifiex_dbg(adapter, MSG,
+                           "last_cmd_resp_index = %d\n",
+                           adapter->dbg.last_cmd_resp_index);
+               mwifiex_dbg(adapter, MSG,
+                           "last_cmd_resp_id: %*ph\n",
+                           (int)sizeof(adapter->dbg.last_cmd_resp_id),
+                           adapter->dbg.last_cmd_resp_id);
+
+               mwifiex_dbg(adapter, MSG,
+                           "last_event_index = %d\n",
+                           adapter->dbg.last_event_index);
+               mwifiex_dbg(adapter, MSG,
+                           "last_event: %*ph\n",
+                           (int)sizeof(adapter->dbg.last_event),
+                           adapter->dbg.last_event);
+
+               mwifiex_dbg(adapter, MSG,
+                           "data_sent=%d cmd_sent=%d\n",
+                           adapter->data_sent, adapter->cmd_sent);
+
+               mwifiex_dbg(adapter, MSG,
+                           "ps_mode=%d ps_state=%d\n",
+                           adapter->ps_mode, adapter->ps_state);
 
                if (cmd_node->wait_q_enabled) {
                        adapter->cmd_wait_q.status = -ETIMEDOUT;
-                       wake_up_interruptible(&adapter->cmd_wait_q.wait);
                        mwifiex_cancel_pending_ioctl(adapter);
                }
        }
-       if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING)
+       if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING) {
                mwifiex_init_fw_complete(adapter);
+               return;
+       }
 
-       if (adapter->if_ops.fw_dump)
-               adapter->if_ops.fw_dump(adapter);
+       if (adapter->if_ops.device_dump)
+               adapter->if_ops.device_dump(adapter);
 
        if (adapter->if_ops.card_reset)
                adapter->if_ops.card_reset(adapter);
@@ -976,6 +1012,7 @@ mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter)
                adapter->curr_cmd->wait_q_enabled = false;
                adapter->cmd_wait_q.status = -1;
                mwifiex_complete_cmd(adapter, adapter->curr_cmd);
+               /* no recycle probably wait for response */
        }
        /* Cancel all pending command */
        spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
@@ -984,11 +1021,8 @@ mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter)
                list_del(&cmd_node->list);
                spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
 
-               if (cmd_node->wait_q_enabled) {
+               if (cmd_node->wait_q_enabled)
                        adapter->cmd_wait_q.status = -1;
-                       mwifiex_complete_cmd(adapter, cmd_node);
-                       cmd_node->wait_q_enabled = false;
-               }
                mwifiex_recycle_cmd_node(adapter, cmd_node);
                spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
        }
@@ -1015,7 +1049,7 @@ mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter)
                        if (!priv)
                                continue;
                        if (priv->scan_request) {
-                               dev_dbg(adapter->dev, "info: aborting scan\n");
+                               mwifiex_dbg(adapter, WARN, "info: aborting scan\n");
                                cfg80211_scan_done(priv->scan_request, 1);
                                priv->scan_request = NULL;
                        }
@@ -1046,12 +1080,18 @@ mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter)
            (adapter->curr_cmd->wait_q_enabled)) {
                spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
                cmd_node = adapter->curr_cmd;
-               cmd_node->wait_q_enabled = false;
-               cmd_node->cmd_flag |= CMD_F_CANCELED;
-               mwifiex_recycle_cmd_node(adapter, cmd_node);
-               mwifiex_complete_cmd(adapter, adapter->curr_cmd);
+               /* setting curr_cmd to NULL is quite dangerous, because
+                * mwifiex_process_cmdresp checks curr_cmd to be != NULL
+                * at the beginning then relies on it and dereferences
+                * it at will
+                * this probably works since mwifiex_cmd_timeout_func
+                * is the only caller of this function and responses
+                * at that point
+                */
                adapter->curr_cmd = NULL;
                spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
+
+               mwifiex_recycle_cmd_node(adapter, cmd_node);
        }
 
        /* Cancel all pending scan command */
@@ -1075,13 +1115,12 @@ mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter)
                        if (!priv)
                                continue;
                        if (priv->scan_request) {
-                               dev_dbg(adapter->dev, "info: aborting scan\n");
+                               mwifiex_dbg(adapter, WARN, "info: aborting scan\n");
                                cfg80211_scan_done(priv->scan_request, 1);
                                priv->scan_request = NULL;
                        }
                }
        }
-       adapter->cmd_wait_q.status = -1;
 }
 
 /*
@@ -1100,11 +1139,11 @@ mwifiex_check_ps_cond(struct mwifiex_adapter *adapter)
            !adapter->curr_cmd && !IS_CARD_RX_RCVD(adapter))
                mwifiex_dnld_sleep_confirm_cmd(adapter);
        else
-               dev_dbg(adapter->dev,
-                       "cmd: Delay Sleep Confirm (%s%s%s)\n",
-                       (adapter->cmd_sent) ? "D" : "",
-                       (adapter->curr_cmd) ? "C" : "",
-                       (IS_CARD_RX_RCVD(adapter)) ? "R" : "");
+               mwifiex_dbg(adapter, CMD,
+                           "cmd: Delay Sleep Confirm (%s%s%s)\n",
+                           (adapter->cmd_sent) ? "D" : "",
+                           (adapter->curr_cmd) ? "C" : "",
+                           (IS_CARD_RX_RCVD(adapter)) ? "R" : "");
 }
 
 /*
@@ -1120,15 +1159,18 @@ mwifiex_hs_activated_event(struct mwifiex_private *priv, u8 activated)
                        priv->adapter->hs_activated = true;
                        mwifiex_update_rxreor_flags(priv->adapter,
                                                    RXREOR_FORCE_NO_DROP);
-                       dev_dbg(priv->adapter->dev, "event: hs_activated\n");
+                       mwifiex_dbg(priv->adapter, EVENT,
+                                   "event: hs_activated\n");
                        priv->adapter->hs_activate_wait_q_woken = true;
                        wake_up_interruptible(
                                &priv->adapter->hs_activate_wait_q);
                } else {
-                       dev_dbg(priv->adapter->dev, "event: HS not configured\n");
+                       mwifiex_dbg(priv->adapter, EVENT,
+                                   "event: HS not configured\n");
                }
        } else {
-               dev_dbg(priv->adapter->dev, "event: hs_deactivated\n");
+               mwifiex_dbg(priv->adapter, EVENT,
+                           "event: hs_deactivated\n");
                priv->adapter->hs_activated = false;
        }
 }
@@ -1156,11 +1198,12 @@ int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private *priv,
                mwifiex_hs_activated_event(priv, true);
                return 0;
        } else {
-               dev_dbg(adapter->dev, "cmd: CMD_RESP: HS_CFG cmd reply"
-                       " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
-                       resp->result, conditions,
-                       phs_cfg->params.hs_config.gpio,
-                       phs_cfg->params.hs_config.gap);
+               mwifiex_dbg(adapter, CMD,
+                           "cmd: CMD_RESP: HS_CFG cmd reply\t"
+                           " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
+                           resp->result, conditions,
+                           phs_cfg->params.hs_config.gpio,
+                           phs_cfg->params.hs_config.gap);
        }
        if (conditions != HS_CFG_CANCEL) {
                adapter->is_hs_configured = true;
@@ -1182,8 +1225,10 @@ int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private *priv,
 void
 mwifiex_process_hs_config(struct mwifiex_adapter *adapter)
 {
-       dev_dbg(adapter->dev, "info: %s: auto cancelling host sleep"
-               " since there is interrupt from the firmware\n", __func__);
+       mwifiex_dbg(adapter, INFO,
+                   "info: %s: auto cancelling host sleep\t"
+                   "since there is interrupt from the firmware\n",
+                   __func__);
 
        adapter->if_ops.wakeup(adapter);
        adapter->hs_activated = false;
@@ -1212,13 +1257,14 @@ mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter *adapter,
        uint16_t seq_num = le16_to_cpu(cmd->seq_num);
 
        if (!upld_len) {
-               dev_err(adapter->dev, "%s: cmd size is 0\n", __func__);
+               mwifiex_dbg(adapter, ERROR,
+                           "%s: cmd size is 0\n", __func__);
                return;
        }
 
-       dev_dbg(adapter->dev,
-               "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
-               command, result, le16_to_cpu(cmd->size), seq_num);
+       mwifiex_dbg(adapter, CMD,
+                   "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
+                   command, result, le16_to_cpu(cmd->size), seq_num);
 
        /* Get BSS number and corresponding priv */
        priv = mwifiex_get_priv_by_id(adapter, HostCmd_GET_BSS_NO(seq_num),
@@ -1232,15 +1278,16 @@ mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter *adapter,
        command &= HostCmd_CMD_ID_MASK;
 
        if (command != HostCmd_CMD_802_11_PS_MODE_ENH) {
-               dev_err(adapter->dev,
-                       "%s: rcvd unexpected resp for cmd %#x, result = %x\n",
-                       __func__, command, result);
+               mwifiex_dbg(adapter, ERROR,
+                           "%s: rcvd unexpected resp for cmd %#x, result = %x\n",
+                           __func__, command, result);
                return;
        }
 
        if (result) {
-               dev_err(adapter->dev, "%s: sleep confirm cmd failed\n",
-                       __func__);
+               mwifiex_dbg(adapter, ERROR,
+                           "%s: sleep confirm cmd failed\n",
+                           __func__);
                adapter->pm_wakeup_card_req = false;
                adapter->ps_state = PS_STATE_AWAKE;
                return;
@@ -1305,7 +1352,8 @@ int mwifiex_cmd_enh_power_mode(struct mwifiex_private *priv,
                                        sizeof(struct mwifiex_ie_types_header));
                        cmd_size += sizeof(*ps_tlv);
                        tlv += sizeof(*ps_tlv);
-                       dev_dbg(adapter->dev, "cmd: PS Command: Enter PS\n");
+                       mwifiex_dbg(priv->adapter, CMD,
+                                   "cmd: PS Command: Enter PS\n");
                        ps_mode->null_pkt_interval =
                                        cpu_to_le16(adapter->null_pkt_interval);
                        ps_mode->multiple_dtims =
@@ -1335,8 +1383,8 @@ int mwifiex_cmd_enh_power_mode(struct mwifiex_private *priv,
                        tlv += sizeof(*auto_ds_tlv);
                        if (auto_ds)
                                idletime = auto_ds->idle_time;
-                       dev_dbg(priv->adapter->dev,
-                               "cmd: PS Command: Enter Auto Deep Sleep\n");
+                       mwifiex_dbg(priv->adapter, CMD,
+                                   "cmd: PS Command: Enter Auto Deep Sleep\n");
                        auto_ds_tlv->deep_sleep_timeout = cpu_to_le16(idletime);
                }
                cmd->size = cpu_to_le16(cmd_size);
@@ -1363,27 +1411,31 @@ int mwifiex_ret_enh_power_mode(struct mwifiex_private *priv,
        uint16_t auto_ps_bitmap =
                le16_to_cpu(ps_mode->params.ps_bitmap);
 
-       dev_dbg(adapter->dev,
-               "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
-               __func__, resp->result, action);
+       mwifiex_dbg(adapter, INFO,
+                   "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
+                   __func__, resp->result, action);
        if (action == EN_AUTO_PS) {
                if (auto_ps_bitmap & BITMAP_AUTO_DS) {
-                       dev_dbg(adapter->dev, "cmd: Enabled auto deep sleep\n");
+                       mwifiex_dbg(adapter, CMD,
+                                   "cmd: Enabled auto deep sleep\n");
                        priv->adapter->is_deep_sleep = true;
                }
                if (auto_ps_bitmap & BITMAP_STA_PS) {
-                       dev_dbg(adapter->dev, "cmd: Enabled STA power save\n");
+                       mwifiex_dbg(adapter, CMD,
+                                   "cmd: Enabled STA power save\n");
                        if (adapter->sleep_period.period)
-                               dev_dbg(adapter->dev,
-                                       "cmd: set to uapsd/pps mode\n");
+                               mwifiex_dbg(adapter, CMD,
+                                           "cmd: set to uapsd/pps mode\n");
                }
        } else if (action == DIS_AUTO_PS) {
                if (ps_bitmap & BITMAP_AUTO_DS) {
                        priv->adapter->is_deep_sleep = false;
-                       dev_dbg(adapter->dev, "cmd: Disabled auto deep sleep\n");
+                       mwifiex_dbg(adapter, CMD,
+                                   "cmd: Disabled auto deep sleep\n");
                }
                if (ps_bitmap & BITMAP_STA_PS) {
-                       dev_dbg(adapter->dev, "cmd: Disabled STA power save\n");
+                       mwifiex_dbg(adapter, CMD,
+                                   "cmd: Disabled STA power save\n");
                        if (adapter->sleep_period.period) {
                                adapter->delay_null_pkt = false;
                                adapter->tx_lock_flag = false;
@@ -1396,7 +1448,8 @@ int mwifiex_ret_enh_power_mode(struct mwifiex_private *priv,
                else
                        adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
 
-               dev_dbg(adapter->dev, "cmd: ps_bitmap=%#x\n", ps_bitmap);
+               mwifiex_dbg(adapter, CMD,
+                           "cmd: ps_bitmap=%#x\n", ps_bitmap);
 
                if (pm_cfg) {
                        /* This section is for get power save mode */
@@ -1533,29 +1586,29 @@ int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv,
                                                        api_rev->major_ver;
                                        adapter->key_api_minor_ver =
                                                        api_rev->minor_ver;
-                                       dev_dbg(adapter->dev,
-                                               "key_api v%d.%d\n",
-                                               adapter->key_api_major_ver,
-                                               adapter->key_api_minor_ver);
+                                       mwifiex_dbg(adapter, INFO,
+                                                   "key_api v%d.%d\n",
+                                                   adapter->key_api_major_ver,
+                                                   adapter->key_api_minor_ver);
                                        break;
                                case FW_API_VER_ID:
                                        adapter->fw_api_ver =
                                                        api_rev->major_ver;
-                                       dev_dbg(adapter->dev,
-                                               "Firmware api version %d\n",
-                                               adapter->fw_api_ver);
+                                       mwifiex_dbg(adapter, INFO,
+                                                   "Firmware api version %d\n",
+                                                   adapter->fw_api_ver);
                                        break;
                                default:
-                                       dev_warn(adapter->dev,
-                                                "Unknown api_id: %d\n",
-                                                api_id);
+                                       mwifiex_dbg(adapter, FATAL,
+                                                   "Unknown api_id: %d\n",
+                                                   api_id);
                                        break;
                                }
                                break;
                        default:
-                               dev_warn(adapter->dev,
-                                        "Unknown GET_HW_SPEC TLV type: %#x\n",
-                                        le16_to_cpu(tlv->type));
+                               mwifiex_dbg(adapter, FATAL,
+                                           "Unknown GET_HW_SPEC TLV type: %#x\n",
+                                           le16_to_cpu(tlv->type));
                                break;
                        }
                        parsed_len += le16_to_cpu(tlv->len) +
@@ -1565,14 +1618,16 @@ int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv,
                }
        }
 
-       dev_dbg(adapter->dev, "info: GET_HW_SPEC: fw_release_number- %#x\n",
-               adapter->fw_release_number);
-       dev_dbg(adapter->dev, "info: GET_HW_SPEC: permanent addr: %pM\n",
-               hw_spec->permanent_addr);
-       dev_dbg(adapter->dev,
-               "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
-               le16_to_cpu(hw_spec->hw_if_version),
-               le16_to_cpu(hw_spec->version));
+       mwifiex_dbg(adapter, INFO,
+                   "info: GET_HW_SPEC: fw_release_number- %#x\n",
+                   adapter->fw_release_number);
+       mwifiex_dbg(adapter, INFO,
+                   "info: GET_HW_SPEC: permanent addr: %pM\n",
+                   hw_spec->permanent_addr);
+       mwifiex_dbg(adapter, INFO,
+                   "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
+                   le16_to_cpu(hw_spec->hw_if_version),
+                   le16_to_cpu(hw_spec->version));
 
        ether_addr_copy(priv->adapter->perm_addr, hw_spec->permanent_addr);
        adapter->region_code = le16_to_cpu(hw_spec->region_code);
@@ -1585,8 +1640,8 @@ int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv,
        /* If it's unidentified region code, use the default (USA) */
        if (i >= MWIFIEX_MAX_REGION_CODE) {
                adapter->region_code = 0x10;
-               dev_dbg(adapter->dev,
-                       "cmd: unknown region code, use default (USA)\n");
+               mwifiex_dbg(adapter, WARN,
+                           "cmd: unknown region code, use default (USA)\n");
        }
 
        adapter->hw_dot_11n_dev_cap = le32_to_cpu(hw_spec->dot_11n_dev_cap);