Commit efaaa8b8 authored by Amitkumar Karwar's avatar Amitkumar Karwar Committed by John W. Linville

mwifiex: use separate wait condition for each command node

Currently global wait condition (adapter->cmd_wait_q.condition)
is used while sending synchronous commands to FW. When two threads
enter in mwifiex_send_cmd_sync() routine at the same time, both the
threads wait for their command responses. Since wait condition is
same for both, they wake up simultaneously after getting response
of 1st command. After this when a thread is waiting for command
response of 3rd command, it wakes up after getting response of 2nd
command and so on. Therefore we don't wait for the response of last
command(0xaa) during unload. Hence while next time loading the driver
command time out is seen for INIT command.

This problem is resolved by having separate wait condition flag for
each command(except scan command). Since scan command is treated
differently (by maintaining scan pending q etc.), newly defined flag
(scan_wait_q_woken) is used as a scan wait condition.
Signed-off-by: default avatarAmitkumar Karwar <akarwar@marvell.com>
Signed-off-by: default avatarYogesh Ashok Powar <yogeshp@marvell.com>
Signed-off-by: default avatarBing Zhao <bzhao@marvell.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 207ae4a3
...@@ -40,8 +40,12 @@ mwifiex_init_cmd_node(struct mwifiex_private *priv, ...@@ -40,8 +40,12 @@ mwifiex_init_cmd_node(struct mwifiex_private *priv,
{ {
cmd_node->priv = priv; cmd_node->priv = priv;
cmd_node->cmd_oid = cmd_oid; cmd_node->cmd_oid = cmd_oid;
cmd_node->wait_q_enabled = priv->adapter->cmd_wait_q_required; if (priv->adapter->cmd_wait_q_required) {
priv->adapter->cmd_wait_q_required = false; cmd_node->wait_q_enabled = priv->adapter->cmd_wait_q_required;
priv->adapter->cmd_wait_q_required = false;
cmd_node->cmd_wait_q_woken = false;
cmd_node->condition = &cmd_node->cmd_wait_q_woken;
}
cmd_node->data_buf = data_buf; cmd_node->data_buf = data_buf;
cmd_node->cmd_skb = cmd_node->skb; cmd_node->cmd_skb = cmd_node->skb;
} }
...@@ -418,7 +422,6 @@ int mwifiex_send_cmd_sync(struct mwifiex_private *priv, uint16_t cmd_no, ...@@ -418,7 +422,6 @@ int mwifiex_send_cmd_sync(struct mwifiex_private *priv, uint16_t cmd_no,
struct mwifiex_adapter *adapter = priv->adapter; struct mwifiex_adapter *adapter = priv->adapter;
adapter->cmd_wait_q_required = true; adapter->cmd_wait_q_required = true;
adapter->cmd_wait_q.condition = false;
ret = mwifiex_send_cmd_async(priv, cmd_no, cmd_action, cmd_oid, ret = mwifiex_send_cmd_async(priv, cmd_no, cmd_action, cmd_oid,
data_buf); data_buf);
...@@ -511,10 +514,12 @@ int mwifiex_send_cmd_async(struct mwifiex_private *priv, uint16_t cmd_no, ...@@ -511,10 +514,12 @@ int mwifiex_send_cmd_async(struct mwifiex_private *priv, uint16_t cmd_no,
} }
/* Send command */ /* Send command */
if (cmd_no == HostCmd_CMD_802_11_SCAN) if (cmd_no == HostCmd_CMD_802_11_SCAN) {
mwifiex_queue_scan_cmd(priv, cmd_node); mwifiex_queue_scan_cmd(priv, cmd_node);
else } else {
adapter->cmd_queued = cmd_node;
mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true); mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
}
return ret; return ret;
} }
...@@ -535,7 +540,7 @@ mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter *adapter, ...@@ -535,7 +540,7 @@ mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter *adapter,
return; return;
if (cmd_node->wait_q_enabled) if (cmd_node->wait_q_enabled)
mwifiex_complete_cmd(adapter); mwifiex_complete_cmd(adapter, cmd_node);
/* Clean the node */ /* Clean the node */
mwifiex_clean_cmd_node(adapter, cmd_node); mwifiex_clean_cmd_node(adapter, cmd_node);
...@@ -882,7 +887,7 @@ mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter) ...@@ -882,7 +887,7 @@ mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter)
adapter->curr_cmd->wait_q_enabled = false; adapter->curr_cmd->wait_q_enabled = false;
spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
adapter->cmd_wait_q.status = -1; adapter->cmd_wait_q.status = -1;
mwifiex_complete_cmd(adapter); mwifiex_complete_cmd(adapter, adapter->curr_cmd);
} }
/* Cancel all pending command */ /* Cancel all pending command */
spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
...@@ -893,7 +898,7 @@ mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter) ...@@ -893,7 +898,7 @@ mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter)
if (cmd_node->wait_q_enabled) { if (cmd_node->wait_q_enabled) {
adapter->cmd_wait_q.status = -1; adapter->cmd_wait_q.status = -1;
mwifiex_complete_cmd(adapter); mwifiex_complete_cmd(adapter, cmd_node);
cmd_node->wait_q_enabled = false; cmd_node->wait_q_enabled = false;
} }
mwifiex_insert_cmd_to_free_q(adapter, cmd_node); mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
...@@ -976,7 +981,7 @@ mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter) ...@@ -976,7 +981,7 @@ mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter)
spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags); spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
} }
adapter->cmd_wait_q.status = -1; adapter->cmd_wait_q.status = -1;
mwifiex_complete_cmd(adapter); mwifiex_complete_cmd(adapter, adapter->curr_cmd);
} }
/* /*
......
...@@ -98,7 +98,6 @@ struct mwifiex_802_11_ssid { ...@@ -98,7 +98,6 @@ struct mwifiex_802_11_ssid {
struct mwifiex_wait_queue { struct mwifiex_wait_queue {
wait_queue_head_t wait; wait_queue_head_t wait;
u16 condition;
int status; int status;
}; };
......
...@@ -685,8 +685,8 @@ mwifiex_add_card(void *card, struct semaphore *sem, ...@@ -685,8 +685,8 @@ mwifiex_add_card(void *card, struct semaphore *sem,
init_waitqueue_head(&adapter->hs_activate_wait_q); init_waitqueue_head(&adapter->hs_activate_wait_q);
adapter->cmd_wait_q_required = false; adapter->cmd_wait_q_required = false;
init_waitqueue_head(&adapter->cmd_wait_q.wait); init_waitqueue_head(&adapter->cmd_wait_q.wait);
adapter->cmd_wait_q.condition = false;
adapter->cmd_wait_q.status = 0; adapter->cmd_wait_q.status = 0;
adapter->scan_wait_q_woken = false;
adapter->workqueue = create_workqueue("MWIFIEX_WORK_QUEUE"); adapter->workqueue = create_workqueue("MWIFIEX_WORK_QUEUE");
if (!adapter->workqueue) if (!adapter->workqueue)
......
...@@ -520,6 +520,8 @@ struct cmd_ctrl_node { ...@@ -520,6 +520,8 @@ struct cmd_ctrl_node {
void *data_buf; void *data_buf;
u32 wait_q_enabled; u32 wait_q_enabled;
struct sk_buff *skb; struct sk_buff *skb;
u8 *condition;
u8 cmd_wait_q_woken;
}; };
struct mwifiex_if_ops { struct mwifiex_if_ops {
...@@ -651,6 +653,8 @@ struct mwifiex_adapter { ...@@ -651,6 +653,8 @@ struct mwifiex_adapter {
u32 arp_filter_size; u32 arp_filter_size;
u16 cmd_wait_q_required; u16 cmd_wait_q_required;
struct mwifiex_wait_queue cmd_wait_q; struct mwifiex_wait_queue cmd_wait_q;
u8 scan_wait_q_woken;
struct cmd_ctrl_node *cmd_queued;
}; };
int mwifiex_init_lock_list(struct mwifiex_adapter *adapter); int mwifiex_init_lock_list(struct mwifiex_adapter *adapter);
...@@ -670,7 +674,8 @@ int mwifiex_recv_packet(struct mwifiex_adapter *, struct sk_buff *skb); ...@@ -670,7 +674,8 @@ int mwifiex_recv_packet(struct mwifiex_adapter *, struct sk_buff *skb);
int mwifiex_process_event(struct mwifiex_adapter *adapter); int mwifiex_process_event(struct mwifiex_adapter *adapter);
int mwifiex_complete_cmd(struct mwifiex_adapter *adapter); int mwifiex_complete_cmd(struct mwifiex_adapter *adapter,
struct cmd_ctrl_node *cmd_node);
int mwifiex_send_cmd_async(struct mwifiex_private *priv, uint16_t cmd_no, int mwifiex_send_cmd_async(struct mwifiex_private *priv, uint16_t cmd_no,
u16 cmd_action, u32 cmd_oid, void *data_buf); u16 cmd_action, u32 cmd_oid, void *data_buf);
......
...@@ -185,7 +185,7 @@ int mwifiex_set_user_scan_ioctl(struct mwifiex_private *priv, ...@@ -185,7 +185,7 @@ int mwifiex_set_user_scan_ioctl(struct mwifiex_private *priv,
{ {
int status; int status;
priv->adapter->cmd_wait_q.condition = false; priv->adapter->scan_wait_q_woken = false;
status = mwifiex_scan_networks(priv, scan_req); status = mwifiex_scan_networks(priv, scan_req);
if (!status) if (!status)
...@@ -1380,6 +1380,7 @@ int mwifiex_scan_networks(struct mwifiex_private *priv, ...@@ -1380,6 +1380,7 @@ int mwifiex_scan_networks(struct mwifiex_private *priv,
list_del(&cmd_node->list); list_del(&cmd_node->list);
spin_unlock_irqrestore(&adapter->scan_pending_q_lock, spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
flags); flags);
adapter->cmd_queued = cmd_node;
mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
true); true);
} else { } else {
...@@ -1788,7 +1789,7 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv, ...@@ -1788,7 +1789,7 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
/* Need to indicate IOCTL complete */ /* Need to indicate IOCTL complete */
if (adapter->curr_cmd->wait_q_enabled) { if (adapter->curr_cmd->wait_q_enabled) {
adapter->cmd_wait_q.status = 0; adapter->cmd_wait_q.status = 0;
mwifiex_complete_cmd(adapter); mwifiex_complete_cmd(adapter, adapter->curr_cmd);
} }
if (priv->report_scan_result) if (priv->report_scan_result)
priv->report_scan_result = false; priv->report_scan_result = false;
...@@ -1845,6 +1846,7 @@ mwifiex_queue_scan_cmd(struct mwifiex_private *priv, ...@@ -1845,6 +1846,7 @@ mwifiex_queue_scan_cmd(struct mwifiex_private *priv,
unsigned long flags; unsigned long flags;
cmd_node->wait_q_enabled = true; cmd_node->wait_q_enabled = true;
cmd_node->condition = &adapter->scan_wait_q_woken;
spin_lock_irqsave(&adapter->scan_pending_q_lock, flags); spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
list_add_tail(&cmd_node->list, &adapter->scan_pending_q); list_add_tail(&cmd_node->list, &adapter->scan_pending_q);
spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags); spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
...@@ -1911,7 +1913,7 @@ int mwifiex_request_scan(struct mwifiex_private *priv, ...@@ -1911,7 +1913,7 @@ int mwifiex_request_scan(struct mwifiex_private *priv,
} }
priv->scan_pending_on_block = true; priv->scan_pending_on_block = true;
priv->adapter->cmd_wait_q.condition = false; priv->adapter->scan_wait_q_woken = false;
if (req_ssid && req_ssid->ssid_len != 0) if (req_ssid && req_ssid->ssid_len != 0)
/* Specific SSID scan */ /* Specific SSID scan */
......
...@@ -55,7 +55,9 @@ int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter) ...@@ -55,7 +55,9 @@ int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter)
{ {
bool cancel_flag = false; bool cancel_flag = false;
int status = adapter->cmd_wait_q.status; int status = adapter->cmd_wait_q.status;
struct cmd_ctrl_node *cmd_queued = adapter->cmd_queued;
adapter->cmd_queued = NULL;
dev_dbg(adapter->dev, "cmd pending\n"); dev_dbg(adapter->dev, "cmd pending\n");
atomic_inc(&adapter->cmd_pending); atomic_inc(&adapter->cmd_pending);
...@@ -64,8 +66,8 @@ int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter) ...@@ -64,8 +66,8 @@ int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter)
/* Wait for completion */ /* Wait for completion */
wait_event_interruptible(adapter->cmd_wait_q.wait, wait_event_interruptible(adapter->cmd_wait_q.wait,
adapter->cmd_wait_q.condition); *(cmd_queued->condition));
if (!adapter->cmd_wait_q.condition) if (!*(cmd_queued->condition))
cancel_flag = true; cancel_flag = true;
if (cancel_flag) { if (cancel_flag) {
......
...@@ -185,13 +185,14 @@ int mwifiex_recv_packet(struct mwifiex_adapter *adapter, struct sk_buff *skb) ...@@ -185,13 +185,14 @@ int mwifiex_recv_packet(struct mwifiex_adapter *adapter, struct sk_buff *skb)
* corresponding waiting function. Otherwise, it processes the * corresponding waiting function. Otherwise, it processes the
* IOCTL response and frees the response buffer. * IOCTL response and frees the response buffer.
*/ */
int mwifiex_complete_cmd(struct mwifiex_adapter *adapter) int mwifiex_complete_cmd(struct mwifiex_adapter *adapter,
struct cmd_ctrl_node *cmd_node)
{ {
atomic_dec(&adapter->cmd_pending); atomic_dec(&adapter->cmd_pending);
dev_dbg(adapter->dev, "cmd completed: status=%d\n", dev_dbg(adapter->dev, "cmd completed: status=%d\n",
adapter->cmd_wait_q.status); adapter->cmd_wait_q.status);
adapter->cmd_wait_q.condition = true; *(cmd_node->condition) = true;
if (adapter->cmd_wait_q.status == -ETIMEDOUT) if (adapter->cmd_wait_q.status == -ETIMEDOUT)
dev_err(adapter->dev, "cmd timeout\n"); dev_err(adapter->dev, "cmd timeout\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment