mmc: card: stop BKOPS in mmc_blk_cmdq_issue_rq

In case there are no pending requests, runtime idle API can be
invoked and start manual BKOPS.
We need to check if manual BKOPS is enabled on the device and stop
it before serving new incoming requests in CQ mode.

Change-Id: I870eff40ea9fa91eedb4c0d2600c32d8534a3868
Signed-off-by: Maya Erez <merez@codeaurora.org>
[xiaonian@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Xiaonian Wang <xiaonian@codeaurora.org>
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 9d3dcd1..faa8148 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -3726,14 +3726,27 @@
 	struct mmc_card *card = md->queue.card;
 
 	mmc_get_card(card);
+
+	if (!card->host->cmdq_ctx.active_reqs && mmc_card_doing_bkops(card)) {
+		ret = mmc_cmdq_halt(card->host, true);
+		if (ret)
+			goto out;
+		ret = mmc_stop_bkops(card);
+		if (ret) {
+			pr_err("%s: %s: mmc_stop_bkops failed %d\n",
+					md->disk->disk_name, __func__, ret);
+			goto out;
+		}
+		ret = mmc_cmdq_halt(card->host, false);
+		if (ret)
+			goto out;
+	}
+
 	ret = mmc_blk_cmdq_part_switch(card, md);
 	if (ret) {
 		pr_err("%s: %s: partition switch failed %d\n",
 				md->disk->disk_name, __func__, ret);
-		if (req)
-			blk_end_request_all(req, ret);
-		mmc_put_card(card);
-		goto switch_failure;
+		goto out;
 	}
 
 	if (req) {
@@ -3751,7 +3764,13 @@
 		}
 	}
 
-switch_failure:
+	return ret;
+
+out:
+	if (req)
+		blk_end_request_all(req, ret);
+	mmc_put_card(card);
+
 	return ret;
 }