mwifiex: cleanup ioctl wait queue and abstraction layer

1) remove mwifiex_alloc_fill_wait_queue() and
mwifiex_request_ioctl()
2) avoid dynamic allocation of wait queue
3) remove unnecessary mwifiex_error_code macros that
were used mainly by the wait queue status code
4) remove some abstraction functions
5) split mwifiex_prepare_cmd() to mwifiex_send_cmd_async()
and mwifiex_send_sync() to handle asynchronous and
synchronous commands respectively

Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
diff --git a/drivers/net/wireless/mwifiex/scan.c b/drivers/net/wireless/mwifiex/scan.c
index 6bb52d0..12fe021 100644
--- a/drivers/net/wireless/mwifiex/scan.c
+++ b/drivers/net/wireless/mwifiex/scan.c
@@ -178,9 +178,8 @@
  * with requisite parameters and calls the IOCTL handler.
  */
 int mwifiex_find_best_bss(struct mwifiex_private *priv,
-			  u8 wait_option, struct mwifiex_ssid_bssid *ssid_bssid)
+			  struct mwifiex_ssid_bssid *ssid_bssid)
 {
-	struct mwifiex_wait_queue *wait = NULL;
 	struct mwifiex_ssid_bssid tmp_ssid_bssid;
 	int ret = 0;
 	u8 *mac = NULL;
@@ -188,14 +187,9 @@
 	if (!ssid_bssid)
 		return -1;
 
-	/* Allocate wait request buffer */
-	wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
-	if (!wait)
-		return -ENOMEM;
-
 	memcpy(&tmp_ssid_bssid, ssid_bssid,
 	       sizeof(struct mwifiex_ssid_bssid));
-	ret = mwifiex_bss_ioctl_find_bss(priv, wait, &tmp_ssid_bssid);
+	ret = mwifiex_bss_ioctl_find_bss(priv, &tmp_ssid_bssid);
 
 	if (!ret) {
 		memcpy(ssid_bssid, &tmp_ssid_bssid,
@@ -205,7 +199,6 @@
 				" %pM\n", ssid_bssid->ssid.ssid, mac);
 	}
 
-	kfree(wait);
 	return ret;
 }
 
@@ -221,22 +214,14 @@
 int mwifiex_set_user_scan_ioctl(struct mwifiex_private *priv,
 				struct mwifiex_user_scan_cfg *scan_req)
 {
-	struct mwifiex_wait_queue *wait = NULL;
 	int status = 0;
-	u8 wait_option = MWIFIEX_IOCTL_WAIT;
 
-	/* Allocate an IOCTL request buffer */
-	wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
-	if (!wait)
-		return -ENOMEM;
+	priv->adapter->cmd_wait_q.condition = false;
 
-	status = mwifiex_scan_networks(priv, wait, HostCmd_ACT_GEN_SET,
-				       scan_req, NULL);
+	status = mwifiex_scan_networks(priv, scan_req);
+	if (!status)
+		status = mwifiex_wait_queue_complete(priv->adapter);
 
-	status = mwifiex_request_ioctl(priv, wait, status, wait_option);
-
-	if (wait && (status != -EINPROGRESS))
-		kfree(wait);
 	return status;
 }
 
@@ -674,7 +659,7 @@
  * along with the other TLVs, to the firmware.
  */
 static int
-mwifiex_scan_channel_list(struct mwifiex_private *priv, void *wait_buf,
+mwifiex_scan_channel_list(struct mwifiex_private *priv,
 			  u32 max_chan_per_scan, u8 filtered_scan,
 			  struct mwifiex_scan_cmd_config *scan_cfg_out,
 			  struct mwifiex_ie_types_chan_list_param_set
@@ -808,9 +793,9 @@
 
 		/* Send the scan command to the firmware with the specified
 		   cfg */
-		ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_SCAN,
-					  HostCmd_ACT_GEN_SET,
-					  0, wait_buf, scan_cfg_out);
+		ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SCAN,
+					     HostCmd_ACT_GEN_SET, 0,
+					     scan_cfg_out);
 		if (ret)
 			break;
 	}
@@ -2271,9 +2256,7 @@
  * update the internal driver scan table.
  */
 int mwifiex_scan_networks(struct mwifiex_private *priv,
-			  void *wait_buf, u16 action,
-			  const struct mwifiex_user_scan_cfg *user_scan_in,
-			  struct mwifiex_scan_resp *scan_resp)
+			  const struct mwifiex_user_scan_cfg *user_scan_in)
 {
 	int ret = 0;
 	struct mwifiex_adapter *adapter = priv->adapter;
@@ -2288,18 +2271,7 @@
 	u8 max_chan_per_scan;
 	unsigned long flags;
 
-	if (action == HostCmd_ACT_GEN_GET) {
-		if (scan_resp) {
-			scan_resp->scan_table = (u8 *) adapter->scan_table;
-			scan_resp->num_in_scan_table =
-				adapter->num_in_scan_table;
-		} else {
-			ret = -1;
-		}
-		return ret;
-	}
-
-	if (adapter->scan_processing && action == HostCmd_ACT_GEN_SET) {
+	if (adapter->scan_processing) {
 		dev_dbg(adapter->dev, "cmd: Scan already in process...\n");
 		return ret;
 	}
@@ -2308,7 +2280,7 @@
 	adapter->scan_processing = true;
 	spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
 
-	if (priv->scan_block && action == HostCmd_ACT_GEN_SET) {
+	if (priv->scan_block) {
 		dev_dbg(adapter->dev,
 			"cmd: Scan is blocked during association...\n");
 		return ret;
@@ -2348,9 +2320,9 @@
 		adapter->bcn_buf_end = adapter->bcn_buf;
 	}
 
-	ret = mwifiex_scan_channel_list(priv, wait_buf, max_chan_per_scan,
-					filtered_scan, &scan_cfg_out->config,
-					chan_list_out, scan_chan_list);
+	ret = mwifiex_scan_channel_list(priv, max_chan_per_scan, filtered_scan,
+					&scan_cfg_out->config, chan_list_out,
+					scan_chan_list);
 
 	/* Get scan command from scan_pending_q and put to cmd_pending_q */
 	if (!ret) {
@@ -2367,7 +2339,6 @@
 			spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
 					       flags);
 		}
-		ret = -EINPROGRESS;
 	} else {
 		spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
 		adapter->scan_processing = true;
@@ -2437,11 +2408,10 @@
  *      .-------------------------------------------------------------.
  */
 int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
-			    struct host_cmd_ds_command *resp, void *wq_buf)
+			    struct host_cmd_ds_command *resp)
 {
 	int ret = 0;
 	struct mwifiex_adapter *adapter = priv->adapter;
-	struct mwifiex_wait_queue *wait_queue = NULL;
 	struct cmd_ctrl_node *cmd_node = NULL;
 	struct host_cmd_ds_802_11_scan_rsp *scan_rsp = NULL;
 	struct mwifiex_bssdescriptor *bss_new_entry = NULL;
@@ -2653,13 +2623,9 @@
 		mwifiex_process_scan_results(priv);
 
 		/* Need to indicate IOCTL complete */
-		wait_queue = (struct mwifiex_wait_queue *) wq_buf;
-		if (wait_queue) {
-			wait_queue->status = MWIFIEX_ERROR_NO_ERROR;
-
-			/* Indicate ioctl complete */
-			mwifiex_ioctl_complete(adapter,
-			       (struct mwifiex_wait_queue *) wait_queue, 0);
+		if (adapter->curr_cmd->wait_q_enabled) {
+			adapter->cmd_wait_q.status = 0;
+			mwifiex_complete_cmd(adapter);
 		}
 		if (priv->report_scan_result)
 			priv->report_scan_result = false;
@@ -2853,6 +2819,7 @@
 	struct mwifiex_adapter *adapter = priv->adapter;
 	unsigned long flags;
 
+	cmd_node->wait_q_enabled = true;
 	spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
 	list_add_tail(&cmd_node->list, &adapter->scan_pending_q);
 	spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
@@ -2899,9 +2866,7 @@
  * firmware, filtered on a specific SSID.
  */
 static int mwifiex_scan_specific_ssid(struct mwifiex_private *priv,
-				      void *wait_buf, u16 action,
-				      struct mwifiex_802_11_ssid *req_ssid,
-				      struct mwifiex_scan_resp *scan_resp)
+				      struct mwifiex_802_11_ssid *req_ssid)
 {
 	struct mwifiex_adapter *adapter = priv->adapter;
 	int ret = 0;
@@ -2910,24 +2875,12 @@
 	if (!req_ssid)
 		return -1;
 
-	if (action == HostCmd_ACT_GEN_GET) {
-		if (scan_resp) {
-			scan_resp->scan_table =
-				(u8 *) &priv->curr_bss_params.bss_descriptor;
-			scan_resp->num_in_scan_table =
-				adapter->num_in_scan_table;
-		} else {
-			ret = -1;
-		}
-		return ret;
-	}
-
-	if (adapter->scan_processing && action == HostCmd_ACT_GEN_SET) {
+	if (adapter->scan_processing) {
 		dev_dbg(adapter->dev, "cmd: Scan already in process...\n");
 		return ret;
 	}
 
-	if (priv->scan_block && action == HostCmd_ACT_GEN_SET) {
+	if (priv->scan_block) {
 		dev_dbg(adapter->dev,
 			"cmd: Scan is blocked during association...\n");
 		return ret;
@@ -2945,7 +2898,7 @@
 	       req_ssid->ssid_len);
 	scan_cfg->keep_previous_scan = true;
 
-	ret = mwifiex_scan_networks(priv, wait_buf, action, scan_cfg, NULL);
+	ret = mwifiex_scan_networks(priv, scan_cfg);
 
 	kfree(scan_cfg);
 	return ret;
@@ -2960,12 +2913,10 @@
  * Scan command can be issued for both normal scan and specific SSID
  * scan, depending upon whether an SSID is provided or not.
  */
-int mwifiex_request_scan(struct mwifiex_private *priv, u8 wait_option,
+int mwifiex_request_scan(struct mwifiex_private *priv,
 			 struct mwifiex_802_11_ssid *req_ssid)
 {
 	int ret = 0;
-	struct mwifiex_wait_queue *wait = NULL;
-	int status = 0;
 
 	if (down_interruptible(&priv->async_sem)) {
 		dev_err(priv->adapter->dev, "%s: acquire semaphore\n",
@@ -2974,32 +2925,23 @@
 	}
 	priv->scan_pending_on_block = true;
 
-	/* Allocate wait request buffer */
-	wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
-	if (!wait) {
-		ret = -1;
-		goto done;
-	}
+	priv->adapter->cmd_wait_q.condition = false;
 
 	if (req_ssid && req_ssid->ssid_len != 0)
 		/* Specific SSID scan */
-		status = mwifiex_scan_specific_ssid(priv, wait,
-						    HostCmd_ACT_GEN_SET,
-						    req_ssid, NULL);
+		ret = mwifiex_scan_specific_ssid(priv, req_ssid);
 	else
 		/* Normal scan */
-		status = mwifiex_scan_networks(priv, wait, HostCmd_ACT_GEN_SET,
-					       NULL, NULL);
-	status = mwifiex_request_ioctl(priv, wait, status, wait_option);
-	if (status == -1)
-		ret = -1;
-done:
-	if ((wait) && (status != -EINPROGRESS))
-		kfree(wait);
+		ret = mwifiex_scan_networks(priv, NULL);
+
+	if (!ret)
+		ret = mwifiex_wait_queue_complete(priv->adapter);
+
 	if (ret == -1) {
 		priv->scan_pending_on_block = false;
 		up(&priv->async_sem);
 	}
+
 	return ret;
 }