Skip to contentSkip to conversation

mmc: Add Command Queue support

PATCH Applied Adrian Hunter 2 participants 18 messages Aug 25, 2017 – Aug 30, 2017

Subsystems (4)

v6 of 15 Applied Latest is v15 →

lore
Share & tools
lore

Adrian Hunter

author maintainer
#0 lore raw

v6 cover mmc: Add Command Queue support

Hi

Here is V6 of the hardware command queue patches without the software command queue patches. Patches "mmc: host: Add CQE interface" and "mmc: core: Turn off CQE before sending commands" have been applied to Ulf's next branch. "mmc: host: Add CQE interface" needs to be dropped in favour of the new version.

HW CMDQ offers 25% - 50% better random multi-threaded I/O. I see a slight 2% drop in sequential read speed but no change to sequential write.

We need to start with the legacy block API because people want to backport CQ to earlier kernels (we really need to get features upstream more quickly), but blk-mq has been evolving a lot (e.g. elevator support), so backporters face having either something quite different from upstream or trying to backport great chunks of the block layer.

We also don't know how blk-mq will perform so it would be prudent to start with support for both the legacy API and blk-mq (as scsi does) so that we can find out first.

RFC patches to support blk-mq can be found here:

	https://marc.info/?l=linux-block&m=150349582124880

Changes since V5:
Re-based
mmc: core: Add mmc_retune_hold_now()
Dropped because it has been applied
mmc: core: Add members to mmc_request and mmc_data for CQE's
Dropped because it has been applied
mmc: core: Move mmc_start_areq() declaration
New patch at Ulf's request
mmc: block: Fix block status codes
Another un-related patch
mmc: host: Add CQE interface
Move recovery_notifier() callback to struct mmc_request
mmc: core: Add support for handling CQE requests
Roll __mmc_cqe_request_done() into mmc_cqe_request_done() Move function declarations requested by Ulf
mmc: core: Remove unused MMC_CAP2_PACKED_CMD
Dropped because it has been applied
mmc: block: Add CQE support
Add explanation to commit message
Adjustment for changed recovery_notifier() callback
mmc: cqhci: support for command queue enabled host
Adjustment for changed recovery_notifier() callback
mmc: sdhci-pci: Add CQHCI support for Intel GLK
Add DCMD capability for Intel controllers except GLK

Changes since V4:
mmc: core: Add mmc_retune_hold_now()
Add explanation to commit message.
mmc: host: Add CQE interface
Add comments to callback declarations.
mmc: core: Turn off CQE before sending commands
Add explanation to commit message.
mmc: core: Add support for handling CQE requests
Add comments as requested by Ulf.
mmc: core: Remove unused MMC_CAP2_PACKED_CMD
New patch.
mmc: mmc: Enable Command Queuing
Adjust for removal of MMC_CAP2_PACKED_CMD.
Add a comment about Packed Commands.
mmc: mmc: Enable CQE's
Remove un-necessary check for MMC_CAP2_CQE
mmc: block: Use local variables in mmc_blk_data_prep()
New patch.
mmc: block: Prepare CQE data
Adjust due to "mmc: block: Use local variables in mmc_blk_data_prep()" Remove priority setting.
Add explanation to commit message.
mmc: cqhci: support for command queue enabled host
Fix transfer descriptor setting in cqhci_set_tran_desc() for 32-bit DMA

Changes since V3:
Adjusted ...blk_end_request...() for new block status codes Fixed CQHCI transaction descriptor for "no DCMD" case

Changes since V2:
Dropped patches that have been applied. Re-based
Added "mmc: sdhci-pci: Add CQHCI support for Intel GLK"

Changes since V1:

"Share mmc request array between partitions" is dependent on changes in "Introduce queue semantics", so added that and block fixes:

Added "Fix is_waiting_last_req set incorrectly" Added "Fix cmd error reset failure path" Added "Use local var for mqrq_cur" Added "Introduce queue semantics"

Changes since RFC:

Re-based on next.
Added comment about command queue priority. Added some acks and reviews.

Adrian Hunter (11):
mmc: core: Move mmc_start_areq() declaration
mmc: block: Fix block status codes
mmc: host: Add CQE interface
mmc: core: Turn off CQE before sending commands
mmc: core: Add support for handling CQE requests
mmc: mmc: Enable Command Queuing
mmc: mmc: Enable CQE's
mmc: block: Use local variables in mmc_blk_data_prep()
mmc: block: Prepare CQE data
mmc: block: Add CQE support
mmc: sdhci-pci: Add CQHCI support for Intel GLK

Venkat Gopalakrishnan (1):
mmc: cqhci: support for command queue enabled host

 drivers/mmc/core/block.c          |  246 +++++++-
 drivers/mmc/core/block.h          |    7 +
 drivers/mmc/core/bus.c            |    7 +
 drivers/mmc/core/core.c           |  172 +++++-
 drivers/mmc/core/core.h           |   10 +
 drivers/mmc/core/mmc.c            |   29 +
 drivers/mmc/core/queue.c          |  270 ++++++++-
 drivers/mmc/core/queue.h          |   43 +-
 drivers/mmc/host/Kconfig          |   14 +
 drivers/mmc/host/Makefile         |    1 +
 drivers/mmc/host/cqhci.c          | 1154 +++++++++++++++++++++++++++++++++++++
 drivers/mmc/host/cqhci.h          |  240 ++++++++
 drivers/mmc/host/sdhci-pci-core.c |  154 ++++-
 include/linux/mmc/core.h          |   10 +-
 include/linux/mmc/host.h          |   55 ++
 15 files changed, 2381 insertions(+), 31 deletions(-)
 create mode 100644 drivers/mmc/host/cqhci.c
 create mode 100644 drivers/mmc/host/cqhci.h

Regards
Adrian

author maintainer
#1 lore raw

PATCH v6 1/12 mmc: core: Move mmc_start_areq() declaration

mmc_start_areq() is an internal mmc core API. Move the declaration accordingly.

---
 drivers/mmc/core/core.h  | 6 ++++++
 include/linux/mmc/core.h | 4 ----
 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/mmc/core/core.h +6 -0
index 55f543fd37c4..ca861091a776 100644
@@ -107,6 +107,12 @@ static inline void mmc_unregister_pm_notifier(struct mmc_host *host) { }
 void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq);
 bool mmc_is_req_done(struct mmc_host *host, struct mmc_request *mrq);
 
+struct mmc_async_req;
+
+struct mmc_async_req *mmc_start_areq(struct mmc_host *host,
+				     struct mmc_async_req *areq,
+				     enum mmc_blk_status *ret_stat);
+
 int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
 		unsigned int arg);
 int mmc_can_erase(struct mmc_card *card);
include/linux/mmc/core.h +0 -4
index bf1788a224e6..178f699ac172 100644
@@ -165,11 +165,7 @@ struct mmc_request {
 };
 
 struct mmc_card;
-struct mmc_async_req;
 
-struct mmc_async_req *mmc_start_areq(struct mmc_host *host,
-				struct mmc_async_req *areq,
-				enum mmc_blk_status *ret_stat);
 void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq);
 int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd,
 		int retries);
Signature · 1 line
1.9.1
author maintainer
#3 lore raw

PATCH v6 2/12 mmc: block: Fix block status codes

In reply to Adrian Hunter

Commit 2a842acab109 ("block: introduce new block status code type") changed the error type but not in patches merged through the mmc tree, like commit 0493f6fe5bde ("mmc: block: Move boot partition locking into a driver op"). Fix one error code that is incorrect and also use BLK_STS_OK in preference to 0.

Fixes 17ece345a042 ("Merge tag 'mmc-v4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc")
---
 drivers/mmc/core/block.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mmc/core/block.c +3 -3
index 0eebc2f726c3..2f00d11adfa9 100644
@@ -1223,7 +1223,7 @@ static void mmc_blk_issue_drv_op(struct mmc_queue *mq, struct request *req)
 		break;
 	}
 	mq_rq->drv_op_result = ret;
-	blk_end_request_all(req, ret);
+	blk_end_request_all(req, ret ? BLK_STS_IOERR : BLK_STS_OK);
 }
 
 static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
@@ -1728,9 +1728,9 @@ static bool mmc_blk_rw_cmd_err(struct mmc_blk_data *md, struct mmc_card *card,
 		if (err)
 			req_pending = old_req_pending;
 		else
-			req_pending = blk_end_request(req, 0, blocks << 9);
+			req_pending = blk_end_request(req, BLK_STS_OK, blocks << 9);
 	} else {
-		req_pending = blk_end_request(req, 0, brq->data.bytes_xfered);
+		req_pending = blk_end_request(req, BLK_STS_OK, brq->data.bytes_xfered);
 	}
 	return req_pending;
 }
Signature · 1 line
1.9.1
author maintainer
#7 lore raw

PATCH v6 4/12 mmc: core: Turn off CQE before sending commands

In reply to Adrian Hunter

CQE needs to be off for the host controller to accept non-CQ commands. Turn off the CQE before sending commands, and ensure it is off in any reset or power management paths, or re-tuning.

---
 drivers/mmc/core/core.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/mmc/core/core.c +9 -0
index 5dd1c00d95f5..66c9cf49ad2f 100644
@@ -260,6 +260,9 @@ static void __mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
 
 	trace_mmc_request_start(host, mrq);
 
+	if (host->cqe_on)
+		host->cqe_ops->cqe_off(host);
+
 	host->ops->request(host, mrq);
 }
 
@@ -979,6 +982,9 @@ int mmc_execute_tuning(struct mmc_card *card)
 	if (!host->ops->execute_tuning)
 		return 0;
 
+	if (host->cqe_on)
+		host->cqe_ops->cqe_off(host);
+
 	if (mmc_card_mmc(card))
 		opcode = MMC_SEND_TUNING_BLOCK_HS200;
 	else
@@ -1018,6 +1024,9 @@ void mmc_set_bus_width(struct mmc_host *host, unsigned int width)
  */
 void mmc_set_initial_state(struct mmc_host *host)
 {
+	if (host->cqe_on)
+		host->cqe_ops->cqe_off(host);
+
 	mmc_retune_disable(host);
 
 	if (mmc_host_is_spi(host))
Signature · 1 line
1.9.1
author maintainer
#10 lore raw

PATCH v6 6/12 mmc: mmc: Enable Command Queuing

In reply to Adrian Hunter

Enable the Command Queue if the host controller supports a command queue engine. It is not compatible with Packed Commands, so make a note of that in the comment.

---
 drivers/mmc/core/mmc.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/mmc/core/mmc.c +17 -0
index a7eb623f8daa..194cf2082e73 100644
@@ -1784,6 +1784,23 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
 	}
 
 	/*
+	 * Enable Command Queue if supported. Note that Packed Commands cannot
+	 * be used with Command Queue.
+	 */
+	card->ext_csd.cmdq_en = false;
+	if (card->ext_csd.cmdq_support && host->caps2 & MMC_CAP2_CQE) {
+		err = mmc_cmdq_enable(card);
+		if (err && err != -EBADMSG)
+			goto free_card;
+		if (err) {
+			pr_warn("%s: Enabling CMDQ failed\n",
+				mmc_hostname(card->host));
+			card->ext_csd.cmdq_support = false;
+			card->ext_csd.cmdq_depth = 0;
+			err = 0;
+		}
+	}
+	/*
 	 * In some cases (e.g. RPMB or mmc_test), the Command Queue must be
 	 * disabled for a time, so a flag is needed to indicate to re-enable the
 	 * Command Queue.
Signature · 1 line
1.9.1
author maintainer
#11 lore raw

PATCH v6 7/12 mmc: mmc: Enable CQE's

In reply to Adrian Hunter

Enable or disable CQE when a card is added or removed respectively.

---
 drivers/mmc/core/bus.c |  7 +++++++
 drivers/mmc/core/mmc.c | 12 ++++++++++++
 2 files changed, 19 insertions(+)
drivers/mmc/core/bus.c +7 -0
index 301246513a37..a4b49e25fe96 100644
@@ -369,10 +369,17 @@ int mmc_add_card(struct mmc_card *card)
  */
 void mmc_remove_card(struct mmc_card *card)
 {
+	struct mmc_host *host = card->host;
+
 #ifdef CONFIG_DEBUG_FS
 	mmc_remove_card_debugfs(card);
 #endif
 
+	if (host->cqe_enabled) {
+		host->cqe_ops->cqe_disable(host);
+		host->cqe_enabled = false;
+	}
+
 	if (mmc_card_present(card)) {
 		if (mmc_host_is_spi(card->host)) {
 			pr_info("%s: SPI card removed\n",
drivers/mmc/core/mmc.c +12 -0
index 194cf2082e73..0dcbd25126a1 100644
@@ -1807,6 +1807,18 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
 	 */
 	card->reenable_cmdq = card->ext_csd.cmdq_en;
 
+	if (card->ext_csd.cmdq_en && !host->cqe_enabled) {
+		err = host->cqe_ops->cqe_enable(host, card);
+		if (err) {
+			pr_err("%s: Failed to enable CQE, error %d\n",
+				mmc_hostname(host), err);
+		} else {
+			host->cqe_enabled = true;
+			pr_info("%s: Command Queue Engine enabled\n",
+				mmc_hostname(host));
+		}
+	}
+
 	if (!oldcard)
 		host->card = card;
 
Signature · 1 line
1.9.1
author maintainer
#5 lore raw

PATCH v6 3/12 mmc: host: Add CQE interface

In reply to Adrian Hunter

Add CQE host operations, capabilities, and host members.

---
 include/linux/mmc/core.h |  6 ++++++
 include/linux/mmc/host.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)
include/linux/mmc/core.h +6 -0
index 178f699ac172..927519385482 100644
@@ -156,6 +156,12 @@ struct mmc_request {
 	struct completion	completion;
 	struct completion	cmd_completion;
 	void			(*done)(struct mmc_request *);/* completion function */
+	/*
+	 * Notify uppers layers (e.g. mmc block driver) that recovery is needed
+	 * due to an error associated with the mmc_request. Currently used only
+	 * by CQE.
+	 */
+	void			(*recovery_notifier)(struct mmc_request *);
 	struct mmc_host		*host;
 
 	/* Allow other commands during this ongoing data transfer or busy wait */
include/linux/mmc/host.h +53 -0

71 lines not on this page · raw message

Signature · 1 line
1.9.1
author maintainer
#9 lore raw

PATCH v6 5/12 mmc: core: Add support for handling CQE requests

In reply to Adrian Hunter

Add core support for handling CQE requests, including starting, completing and recovering.

---
 drivers/mmc/core/core.c  | 163 +++++++++++++++++++++++++++++++++++++++++++++--
 drivers/mmc/core/core.h  |   4 ++
 include/linux/mmc/host.h |   2 +
 3 files changed, 164 insertions(+), 5 deletions(-)
drivers/mmc/core/core.c +158 -5
index 66c9cf49ad2f..cc146e1dd2e3 100644
@@ -266,7 +266,8 @@ static void __mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
 	host->ops->request(host, mrq);
 }
 
-static void mmc_mrq_pr_debug(struct mmc_host *host, struct mmc_request *mrq)
+static void mmc_mrq_pr_debug(struct mmc_host *host, struct mmc_request *mrq,
+			     bool cqe)
 {
 	if (mrq->sbc) {
 		pr_debug("<%s: starting CMD%u arg %08x flags %08x>\n",
@@ -275,9 +276,12 @@ static void mmc_mrq_pr_debug(struct mmc_host *host, struct mmc_request *mrq)
 	}
 
 	if (mrq->cmd) {
-		pr_debug("%s: starting CMD%u arg %08x flags %08x\n",
-			 mmc_hostname(host), mrq->cmd->opcode, mrq->cmd->arg,
-			 mrq->cmd->flags);
+		pr_debug("%s: starting %sCMD%u arg %08x flags %08x\n",
+			 mmc_hostname(host), cqe ? "CQE direct " : "",
+			 mrq->cmd->opcode, mrq->cmd->arg, mrq->cmd->flags);
+	} else if (cqe) {
+		pr_debug("%s: starting CQE transfer for tag %d blkaddr %u\n",
+			 mmc_hostname(host), mrq->tag, mrq->data->blk_addr);
 	}
 
 	if (mrq->data) {
@@ -342,7 +346,7 @@ static int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
 	if (mmc_card_removed(host->card))
 		return -ENOMEDIUM;
 
-	mmc_mrq_pr_debug(host, mrq);
+	mmc_mrq_pr_debug(host, mrq, false);
 
 	WARN_ON(!host->claimed);
 
@@ -482,6 +486,155 @@ void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq)
 }
 EXPORT_SYMBOL(mmc_wait_for_req_done);
 
+/*
+ * mmc_cqe_start_req - Start a CQE request.
+ * @host: MMC host to start the request
+ * @mrq: request to start
+ *
+ * Start the request, re-tuning if needed and it is possible. Returns an error
+ * code if the request fails to start or -EBUSY if CQE is busy.
+ */
+int mmc_cqe_start_req(struct mmc_host *host, struct mmc_request *mrq)
+{
+	int err;
+
+	/*
+	 * CQE cannot process re-tuning commands. Caller must hold retuning
+	 * while CQE is in use.  Re-tuning can happen here only when CQE has no
+	 * active requests i.e. this is the first.  Note, re-tuning will call
+	 * ->cqe_off().
+	 */
+	err = mmc_retune(host);
+	if (err)
+		goto out_err;
+
+	mrq->host = host;
+
+	mmc_mrq_pr_debug(host, mrq, true);
+
+	err = mmc_mrq_prep(host, mrq);
+	if (err)
+		goto out_err;
+
+	err = host->cqe_ops->cqe_request(host, mrq);
+	if (err)
+		goto out_err;
+
+	trace_mmc_request_start(host, mrq);
+
+	return 0;
+
+out_err:
+	if (mrq->cmd) {
+		pr_debug("%s: failed to start CQE direct CMD%u, error %d\n",
+			 mmc_hostname(host), mrq->cmd->opcode, err);
+	} else {
+		pr_debug("%s: failed to start CQE transfer for tag %d, error %d\n",
+			 mmc_hostname(host), mrq->tag, err);
+	}
+	return err;
+}
+EXPORT_SYMBOL(mmc_cqe_start_req);
+
+/**
+ *	mmc_cqe_request_done - CQE has finished processing an MMC request
+ *	@host: MMC host which completed request
+ *	@mrq: MMC request which completed
+ *
+ *	CQE drivers should call this function when they have completed
+ *	their processing of a request.
+ */
+void mmc_cqe_request_done(struct mmc_host *host, struct mmc_request *mrq)
+{
+	mmc_should_fail_request(host, mrq);
+
+	/* Flag re-tuning needed on CRC errors */
+	if ((mrq->cmd && mrq->cmd->error == -EILSEQ) ||
+	    (mrq->data && mrq->data->error == -EILSEQ))
+		mmc_retune_needed(host);
+
+	trace_mmc_request_done(host, mrq);
+
+	if (mrq->cmd) {
+		pr_debug("%s: CQE req done (direct CMD%u): %d\n",
+			 mmc_hostname(host), mrq->cmd->opcode, mrq->cmd->error);
+	} else {
+		pr_debug("%s: CQE transfer done tag %d\n",
+			 mmc_hostname(host), mrq->tag);
+	}
+
+	if (mrq->data) {
+		pr_debug("%s:     %d bytes transferred: %d\n",
+			 mmc_hostname(host),
+			 mrq->data->bytes_xfered, mrq->data->error);
+	}
+
+	mrq->done(mrq);
+}
+EXPORT_SYMBOL(mmc_cqe_request_done);
+
+/**
+ *	mmc_cqe_post_req - CQE post process of a completed MMC request
+ *	@host: MMC host
+ *	@mrq: MMC request to be processed
+ */
+void mmc_cqe_post_req(struct mmc_host *host, struct mmc_request *mrq)
+{
+	if (host->cqe_ops->cqe_post_req)
+		host->cqe_ops->cqe_post_req(host, mrq);
+}
+EXPORT_SYMBOL(mmc_cqe_post_req);
+
+/* Arbitrary 1 second timeout */
+#define MMC_CQE_RECOVERY_TIMEOUT	1000
+
+/*
+ * mmc_cqe_recovery - Recover from CQE errors.
+ * @host: MMC host to recover
+ *
+ * Recovery consists of stopping CQE, stopping eMMC, discarding the queue in
+ * in eMMC, and discarding the queue in CQE. CQE must call
+ * mmc_cqe_request_done() on all requests. An error is returned if the eMMC
+ * fails to discard its queue.
+ */
+int mmc_cqe_recovery(struct mmc_host *host)
+{
+	struct mmc_command cmd;
+	int err;
+
+	mmc_retune_hold_now(host);
+
+	/*
+	 * Recovery is expected seldom, if at all, but it reduces performance,
+	 * so make sure it is not completely silent.
+	 */
+	pr_warn("%s: running CQE recovery\n", mmc_hostname(host));
+
+	host->cqe_ops->cqe_recovery_start(host);
+
+	memset(&cmd, 0, sizeof(cmd));
+	cmd.opcode       = MMC_STOP_TRANSMISSION,
+	cmd.flags        = MMC_RSP_R1B | MMC_CMD_AC,
+	cmd.flags       &= ~MMC_RSP_CRC; /* Ignore CRC */
+	cmd.busy_timeout = MMC_CQE_RECOVERY_TIMEOUT,
+	mmc_wait_for_cmd(host, &cmd, 0);
+
+	memset(&cmd, 0, sizeof(cmd));
+	cmd.opcode       = MMC_CMDQ_TASK_MGMT;
+	cmd.arg          = 1; /* Discard entire queue */
+	cmd.flags        = MMC_RSP_R1B | MMC_CMD_AC;
+	cmd.flags       &= ~MMC_RSP_CRC; /* Ignore CRC */
+	cmd.busy_timeout = MMC_CQE_RECOVERY_TIMEOUT,
+	err = mmc_wait_for_cmd(host, &cmd, 0);
+
+	host->cqe_ops->cqe_recovery_finish(host);
+
+	mmc_retune_release(host);
+
+	return err;
+}
+EXPORT_SYMBOL(mmc_cqe_recovery);
+
 /**
  *	mmc_is_req_done - Determine if a 'cap_cmd_during_tfr' request is done
  *	@host: MMC host
drivers/mmc/core/core.h +4 -0
index ca861091a776..90ce8f2a9343 100644
@@ -144,4 +144,8 @@ static inline void mmc_claim_host(struct mmc_host *host)
 	__mmc_claim_host(host, NULL);
 }
 
+int mmc_cqe_start_req(struct mmc_host *host, struct mmc_request *mrq);
+void mmc_cqe_post_req(struct mmc_host *host, struct mmc_request *mrq);
+int mmc_cqe_recovery(struct mmc_host *host);
+
 #endif
include/linux/mmc/host.h +2 -0
index f3f2d07feb2a..4c16c5813c73 100644
@@ -469,6 +469,8 @@ static inline void *mmc_priv(struct mmc_host *host)
 void mmc_request_done(struct mmc_host *, struct mmc_request *);
 void mmc_command_done(struct mmc_host *host, struct mmc_request *mrq);
 
+void mmc_cqe_request_done(struct mmc_host *host, struct mmc_request *mrq);
+
 static inline void mmc_signal_sdio_irq(struct mmc_host *host)
 {
 	host->ops->enable_sdio_irq(host, 0);
Signature · 1 line
1.9.1
author maintainer
#12 lore raw

PATCH v6 8/12 mmc: block: Use local variables in mmc_blk_data_prep()

In reply to Adrian Hunter

Use local variables in mmc_blk_data_prep() in preparation for adding CQE support which doesn't use the output variables.

---
 drivers/mmc/core/block.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)
drivers/mmc/core/block.c +18 -11
index 2f00d11adfa9..cc950cb1cfd7 100644
@@ -1534,21 +1534,22 @@ static enum mmc_blk_status mmc_blk_err_check(struct mmc_card *card,
 }
 
 static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
-			      int disable_multi, bool *do_rel_wr,
-			      bool *do_data_tag)
+			      int disable_multi, bool *do_rel_wr_p,
+			      bool *do_data_tag_p)
 {
 	struct mmc_blk_data *md = mq->blkdata;
 	struct mmc_card *card = md->queue.card;
 	struct mmc_blk_request *brq = &mqrq->brq;
 	struct request *req = mmc_queue_req_to_req(mqrq);
+	bool do_rel_wr, do_data_tag;
 
 	/*
 	 * Reliable writes are used to implement Forced Unit Access and
 	 * are supported only on MMCs.
 	 */
-	*do_rel_wr = (req->cmd_flags & REQ_FUA) &&
-		     rq_data_dir(req) == WRITE &&
-		     (md->flags & MMC_BLK_REL_WR);
+	do_rel_wr = (req->cmd_flags & REQ_FUA) &&
+		    rq_data_dir(req) == WRITE &&
+		    (md->flags & MMC_BLK_REL_WR);
 
 	memset(brq, 0, sizeof(struct mmc_blk_request));
 
@@ -1596,18 +1597,18 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
 						brq->data.blocks);
 	}
 
-	if (*do_rel_wr)
+	if (do_rel_wr)
 		mmc_apply_rel_rw(brq, card, req);
 
 	/*
 	 * Data tag is used only during writing meta data to speed
 	 * up write and any subsequent read of this meta data
 	 */
-	*do_data_tag = card->ext_csd.data_tag_unit_size &&
-		       (req->cmd_flags & REQ_META) &&
-		       (rq_data_dir(req) == WRITE) &&
-		       ((brq->data.blocks * brq->data.blksz) >=
-			card->ext_csd.data_tag_unit_size);
+	do_data_tag = card->ext_csd.data_tag_unit_size &&
+		      (req->cmd_flags & REQ_META) &&
+		      (rq_data_dir(req) == WRITE) &&
+		      ((brq->data.blocks * brq->data.blksz) >=
+		       card->ext_csd.data_tag_unit_size);
 
 	mmc_set_data_timeout(&brq->data, card);
 
@@ -1636,6 +1637,12 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
 	mqrq->areq.mrq = &brq->mrq;
 
 	mmc_queue_bounce_pre(mqrq);
+
+	if (do_rel_wr_p)
+		*do_rel_wr_p = do_rel_wr;
+
+	if (do_data_tag_p)
+		*do_data_tag_p = do_data_tag;
 }
 
 static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
Signature · 1 line
1.9.1
author maintainer
#13 lore raw

PATCH v6 9/12 mmc: block: Prepare CQE data

In reply to Adrian Hunter

Enhance mmc_blk_data_prep() to support CQE requests. That means adding some things that for non-CQE requests would be encoded into the command arguments - such as the block address, reliable-write flag, and data tag flag. Also the request tag is needed to provide the command queue task id, and a comment is added to explain the future possibility of defining a priority.

---
 drivers/mmc/core/block.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/mmc/core/block.c +15 -1
index cc950cb1cfd7..f9ead0701e8d 100644
@@ -1554,6 +1554,7 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
 	memset(brq, 0, sizeof(struct mmc_blk_request));
 
 	brq->mrq.data = &brq->data;
+	brq->mrq.tag = req->tag;
 
 	brq->stop.opcode = MMC_STOP_TRANSMISSION;
 	brq->stop.arg = 0;
@@ -1568,6 +1569,14 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
 
 	brq->data.blksz = 512;
 	brq->data.blocks = blk_rq_sectors(req);
+	brq->data.blk_addr = blk_rq_pos(req);
+
+	/*
+	 * The command queue supports 2 priorities: "high" (1) and "simple" (0).
+	 * The eMMC will give "high" priority tasks priority over "simple"
+	 * priority tasks. Here we always set "simple" priority by not setting
+	 * MMC_DATA_PRIO.
+	 */
 
 	/*
 	 * The block layer doesn't support all sector count
@@ -1597,8 +1606,10 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
 						brq->data.blocks);
 	}
 
-	if (do_rel_wr)
+	if (do_rel_wr) {
 		mmc_apply_rel_rw(brq, card, req);
+		brq->data.flags |= MMC_DATA_REL_WR;
+	}
 
 	/*
 	 * Data tag is used only during writing meta data to speed
@@ -1610,6 +1621,9 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
 		      ((brq->data.blocks * brq->data.blksz) >=
 		       card->ext_csd.data_tag_unit_size);
 
+	if (do_data_tag)
+		brq->data.flags |= MMC_DATA_DAT_TAG;
+
 	mmc_set_data_timeout(&brq->data, card);
 
 	brq->data.sg = mqrq->sg;
Signature · 1 line
1.9.1
author maintainer
#14 lore raw

PATCH v6 10/12 mmc: block: Add CQE support

In reply to Adrian Hunter

Add CQE support to the block driver, including:
- optionally using DCMD for flush requests
- "manually" issuing discard requests
- issuing read / write requests to the CQE
- supporting block-layer timeouts
- handling recovery
- supporting re-tuning

CQE offers 25% - 50% better random multi-threaded I/O. There is a slight (e.g. 2%) drop in sequential read speed but no observable change to sequential write.

CQE automatically sends the commands to complete requests. However it only supports reads / writes and so-called "direct commands" (DCMD). Furthermore DCMD is limited to one command at a time, but discards require 3 commands. That makes issuing discards through CQE very awkward, but some CQE's don't support DCMD anyway. So for discards, the existing non-CQE approach is taken, where the mmc core code issues the 3 commands one at a time i.e. mmc_erase(). Where DCMD is used, is for issuing flushes.

We need to start with the legacy block API because people want to backport CQ to earlier kernels (we really need to get features upstream more quickly), but blk-mq has been evolving a lot (e.g. elevator support), so backporters face having either something quite different from upstream or trying to backport great chunks of the block layer.

We also don't know how blk-mq will perform so it would be prudent to start with support for both the legacy API and blk-mq (as scsi does) so that we can find out first.

This implementation for CQE support continues to use a thread to fetch requests from the block layer and issue them. This is slightly complicated by the different ways that requests can be issued (refer mmc_cqe_issue_type() and mmc_blk_cqe_issue_rq()). Also allowance must be made for runtime pm and re-tuning which cannot be performed while CQE is active.

Block layer timeouts are useful for CQE. While CQE will detect timeout for a task, the block layer timeouts ensure that the driver will notice if CQE itself gets stuck or somehow does not process a task.

---
 drivers/mmc/core/block.c | 197 +++++++++++++++++++++++++++++++++-
 drivers/mmc/core/block.h |   7 ++
 drivers/mmc/core/queue.c | 270 ++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/mmc/core/queue.h |  43 +++++++-
 4 files changed, 510 insertions(+), 7 deletions(-)
drivers/mmc/core/block.c +196 -1
index f9ead0701e8d..94dea83d51aa 100644
@@ -109,6 +109,7 @@ struct mmc_blk_data {
 #define MMC_BLK_WRITE		BIT(1)
 #define MMC_BLK_DISCARD		BIT(2)
 #define MMC_BLK_SECDISCARD	BIT(3)
+#define MMC_BLK_CQE_RECOVERY	BIT(4)
 
 	/*
 	 * Only set in main mmc_blk_data associated
@@ -1659,6 +1660,200 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
 		*do_data_tag_p = do_data_tag;
 }
 
+#define MMC_CQE_RETRIES 2
+
+void mmc_blk_cqe_complete_rq(struct request *req)
+{
+	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
+	struct mmc_request *mrq = &mqrq->brq.mrq;
+	struct request_queue *q = req->q;
+	struct mmc_queue *mq = q->queuedata;
+	struct mmc_host *host = mq->card->host;
+	unsigned long flags;
+	bool put_card;
+	int err;
+
+	mmc_cqe_post_req(host, mrq);
+
+	spin_lock_irqsave(q->queue_lock, flags);
+
+	mq->cqe_in_flight[mmc_cqe_issue_type(host, req)] -= 1;
+
+	put_card = mmc_cqe_tot_in_flight(mq) == 0;
+
+	if (mrq->cmd && mrq->cmd->error)
+		err = mrq->cmd->error;
+	else if (mrq->data && mrq->data->error)
+		err = mrq->data->error;
+	else
+		err = 0;
+
+	if (err) {
+		if (mqrq->retries++ < MMC_CQE_RETRIES)
+			blk_requeue_request(q, req);
+		else
+			__blk_end_request_all(req, BLK_STS_IOERR);
+	} else if (mrq->data) {
+		if (__blk_end_request(req, BLK_STS_OK, mrq->data->bytes_xfered))
+			blk_requeue_request(q, req);
+	} else {
+		__blk_end_request_all(req, BLK_STS_OK);
+	}
+
+	mmc_cqe_kick_queue(mq);
+
+	spin_unlock_irqrestore(q->queue_lock, flags);
+
+	if (put_card)
+		mmc_put_card(mq->card);
+}
+
+void mmc_blk_cqe_recovery(struct mmc_queue *mq)
+{
+	struct mmc_card *card = mq->card;
+	struct mmc_host *host = card->host;
+	int err;
+
+	mmc_get_card(card);
+
+	pr_debug("%s: CQE recovery start\n", mmc_hostname(host));
+
+	mq->cqe_in_recovery = true;
+
+	err = mmc_cqe_recovery(host);
+	if (err)
+		mmc_blk_reset(mq->blkdata, host, MMC_BLK_CQE_RECOVERY);
+	else
+		mmc_blk_reset_success(mq->blkdata, MMC_BLK_CQE_RECOVERY);
+
+	mq->cqe_in_recovery = false;
+
+	pr_debug("%s: CQE recovery done\n", mmc_hostname(host));
+
+	mmc_put_card(card);
+}
+
+static void mmc_blk_cqe_req_done(struct mmc_request *mrq)
+{
+	struct mmc_queue_req *mqrq = container_of(mrq, struct mmc_queue_req,
+						  brq.mrq);
+	struct request *req = mmc_queue_req_to_req(mqrq);
+	struct request_queue *q = req->q;
+	struct mmc_queue *mq = q->queuedata;
+
+	/*
+	 * Block layer timeouts race with completions which means the normal
+	 * completion path cannot be used during recovery.
+	 */
+	if (mq->cqe_in_recovery)
+		mmc_blk_cqe_complete_rq(req);
+	else
+		blk_complete_request(req);
+}
+
+static int mmc_blk_cqe_start_req(struct mmc_host *host, struct mmc_request *mrq)
+{
+	mrq->done		= mmc_blk_cqe_req_done;
+	mrq->recovery_notifier	= mmc_cqe_recovery_notifier;
+
+	return mmc_cqe_start_req(host, mrq);
+}
+
+static struct mmc_request *mmc_blk_cqe_prep_dcmd(struct mmc_queue_req *mqrq,
+						 struct request *req)
+{
+	struct mmc_blk_request *brq = &mqrq->brq;
+
+	memset(brq, 0, sizeof(*brq));
+
+	brq->mrq.cmd = &brq->cmd;
+	brq->mrq.tag = req->tag;
+
+	return &brq->mrq;
+}
+
+static int mmc_blk_cqe_issue_flush(struct mmc_queue *mq, struct request *req)
+{
+	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
+	struct mmc_request *mrq = mmc_blk_cqe_prep_dcmd(mqrq, req);
+
+	mrq->cmd->opcode = MMC_SWITCH;
+	mrq->cmd->arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) |
+			(EXT_CSD_FLUSH_CACHE << 16) |
+			(1 << 8) |
+			EXT_CSD_CMD_SET_NORMAL;
+	mrq->cmd->flags = MMC_CMD_AC | MMC_RSP_R1B;
+
+	return mmc_blk_cqe_start_req(mq->card->host, mrq);
+}
+
+static int mmc_blk_cqe_issue_rw_rq(struct mmc_queue *mq, struct request *req)
+{
+	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
+
+	mmc_blk_data_prep(mq, mqrq, 0, NULL, NULL);
+
+	return mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+}
+
+enum mmc_issued mmc_blk_cqe_issue_rq(struct mmc_queue *mq, struct request *req)
+{
+	struct mmc_blk_data *md = mq->blkdata;
+	struct mmc_card *card = md->queue.card;
+	struct mmc_host *host = card->host;
+	int ret;
+
+	ret = mmc_blk_part_switch(card, md->part_type);
+	if (ret)
+		return MMC_REQ_FAILED_TO_START;
+
+	switch (mmc_cqe_issue_type(host, req)) {
+	case MMC_ISSUE_SYNC:
+		ret = host->cqe_ops->cqe_wait_for_idle(host);
+		if (ret)
+			return MMC_REQ_BUSY;
+		switch (req_op(req)) {
+		case REQ_OP_DRV_IN:
+		case REQ_OP_DRV_OUT:
+			mmc_blk_issue_drv_op(mq, req);
+			break;
+		case REQ_OP_DISCARD:
+			mmc_blk_issue_discard_rq(mq, req);
+			break;
+		case REQ_OP_SECURE_ERASE:
+			mmc_blk_issue_secdiscard_rq(mq, req);
+			break;
+		case REQ_OP_FLUSH:
+			mmc_blk_issue_flush(mq, req);
+			break;
+		default:
+			WARN_ON_ONCE(1);
+			return MMC_REQ_FAILED_TO_START;
+		}
+		return MMC_REQ_FINISHED;
+	case MMC_ISSUE_DCMD:
+	case MMC_ISSUE_ASYNC:
+		switch (req_op(req)) {
+		case REQ_OP_FLUSH:
+			ret = mmc_blk_cqe_issue_flush(mq, req);
+			break;
+		case REQ_OP_READ:
+		case REQ_OP_WRITE:
+			ret = mmc_blk_cqe_issue_rw_rq(mq, req);
+			break;
+		default:
+			WARN_ON_ONCE(1);
+			ret = -EINVAL;
+		}
+		if (!ret)
+			return MMC_REQ_STARTED;
+		return ret == -EBUSY ? MMC_REQ_BUSY : MMC_REQ_FAILED_TO_START;
+	default:
+		WARN_ON_ONCE(1);
+		return MMC_REQ_FAILED_TO_START;
+	}
+}
+
 static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
 			       struct mmc_card *card,
 			       int disable_multi,
@@ -2082,7 +2277,7 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
 	INIT_LIST_HEAD(&md->part);
 	md->usage = 1;
 
-	ret = mmc_init_queue(&md->queue, card, &md->lock, subname);
+	ret = mmc_init_queue(&md->queue, card, &md->lock, subname, area_type);
 	if (ret)
 		goto err_putdisk;
 
drivers/mmc/core/block.h +7 -0
index 860ca7c8df86..d7b3d7008b00 100644
@@ -6,4 +6,11 @@
 
 void mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req);
 
+enum mmc_issued;
+
+enum mmc_issued mmc_blk_cqe_issue_rq(struct mmc_queue *mq,
+				     struct request *req);
+void mmc_blk_cqe_complete_rq(struct request *rq);
+void mmc_blk_cqe_recovery(struct mmc_queue *mq);
+
 #endif
drivers/mmc/core/queue.c +265 -5

308 lines not on this page · raw message

drivers/mmc/core/queue.h +42 -1

68 lines not on this page · raw message

Signature · 1 line
1.9.1
author maintainer
#15 lore raw

PATCH v6 11/12 mmc: cqhci: support for command queue enabled host

In reply to Adrian Hunter

From: Venkat Gopalakrishnan <[email protected]>

This patch adds CMDQ support for command-queue compatible hosts.

Command queue is added in eMMC-5.1 specification. This enables the controller to process upto 32 requests at a time.

Adrian Hunter contributed renaming to cqhci, recovery, suspend and resume, cqhci_off, cqhci_wait_for_idle, and external timeout handling.

---
 drivers/mmc/host/Kconfig  |   13 +
 drivers/mmc/host/Makefile |    1 +
 drivers/mmc/host/cqhci.c  | 1154 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/host/cqhci.h  |  240 ++++++++++
 4 files changed, 1408 insertions(+)
 create mode 100644 drivers/mmc/host/cqhci.c
 create mode 100644 drivers/mmc/host/cqhci.h
drivers/mmc/host/Kconfig +13 -0
index 60f90d49e7a9..ccf7dab4a9f8 100644
@@ -843,6 +843,19 @@ config MMC_SUNXI
 	  This selects support for the SD/MMC Host Controller on
 	  Allwinner sunxi SoCs.
 
+config MMC_CQHCI
+	tristate "Command Queue Host Controller Interface support"
+	depends on HAS_DMA
+	help
+	  This selects the Command Queue Host Controller Interface (CQHCI)
+	  support present in host controllers of Qualcomm Technologies, Inc
+	  amongst others.
+	  This controller supports eMMC devices with command queue support.
+
+	  If you have a controller with this interface, say Y or M here.
+
+	  If unsure, say N.
+
 config MMC_TOSHIBA_PCI
 	tristate "Toshiba Type A SD/MMC Card Interface Driver"
 	depends on PCI
drivers/mmc/host/Makefile +1 -0
index 8c46766c000c..3ae71e006890 100644
@@ -88,6 +88,7 @@ obj-$(CONFIG_MMC_SDHCI_MSM)		+= sdhci-msm.o
 obj-$(CONFIG_MMC_SDHCI_ST)		+= sdhci-st.o
 obj-$(CONFIG_MMC_SDHCI_MICROCHIP_PIC32)	+= sdhci-pic32.o
 obj-$(CONFIG_MMC_SDHCI_BRCMSTB)		+= sdhci-brcmstb.o
+obj-$(CONFIG_MMC_CQHCI)			+= cqhci.o
 
 ifeq ($(CONFIG_CB710_DEBUG),y)
 	CFLAGS-cb710-mmc	+= -DDEBUG
drivers/mmc/host/cqhci.c new file +1154 -0

1,154 lines not on this page · raw message

drivers/mmc/host/cqhci.h new file +240 -0

240 lines not on this page · raw message

Signature · 1 line
1.9.1
author maintainer
#16 lore raw

PATCH v6 12/12 mmc: sdhci-pci: Add CQHCI support for Intel GLK

In reply to Adrian Hunter

Add CQHCI initialization and implement CQHCI operations for Intel GLK.

---
 drivers/mmc/host/Kconfig          |   1 +
 drivers/mmc/host/sdhci-pci-core.c | 154 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 154 insertions(+), 1 deletion(-)
drivers/mmc/host/Kconfig +1 -0
index ccf7dab4a9f8..b8c9ea5cb8cd 100644
@@ -81,6 +81,7 @@ config MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER
 config MMC_SDHCI_PCI
 	tristate "SDHCI support on PCI bus"
 	depends on MMC_SDHCI && PCI
+	select MMC_CQHCI
 	help
 	  This selects the PCI Secure Digital Host Controller Interface.
 	  Most controllers found today are PCI devices.
drivers/mmc/host/sdhci-pci-core.c +153 -1

205 lines not on this page · raw message

Signature · 1 line
1.9.1
author maintainer
#17 lore raw
In reply to Adrian Hunter
Quoted 5 lines · Adrian Hunter

Here is V6 of the hardware command queue patches without the software command queue patches. Patches "mmc: host: Add CQE interface" and "mmc: core: Turn off CQE before sending commands" have been applied to Ulf's next branch. "mmc: host: Add CQE interface" needs to be dropped in favour of the new version.

Any comments?

Applied
#4 lore raw

Re: [PATCH V6 02/12] mmc: block: Fix block status codes

In reply to Adrian Hunter
Quoted 8 lines · Adrian Hunter

Commit 2a842acab109 ("block: introduce new block status code type") changed the error type but not in patches merged through the mmc tree, like commit 0493f6fe5bde ("mmc: block: Move boot partition locking into a driver op"). Fix one error code that is incorrect and also use BLK_STS_OK in preference to 0.

Fixes 17ece345a042 ("Merge tag 'mmc-v4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc")

Thanks, applied for fixes!

Kind regards
Uffe

Quoted 32 lines
---
 drivers/mmc/core/block.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mmc/core/block.c +3 -4
index 0eebc2f726c3..2f00d11adfa9 100644
@@ -1223,7 +1223,7 @@ static void mmc_blk_issue_drv_op(struct mmc_queue *mq, struct request *req)
                break;
        }
        mq_rq->drv_op_result = ret;
-       blk_end_request_all(req, ret);
+       blk_end_request_all(req, ret ? BLK_STS_IOERR : BLK_STS_OK);
 }
 
 static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
@@ -1728,9 +1728,9 @@ static bool mmc_blk_rw_cmd_err(struct mmc_blk_data *md, struct mmc_card *card,
                if (err)
                        req_pending = old_req_pending;
                else
-                       req_pending = blk_end_request(req, 0, blocks << 9);
+                       req_pending = blk_end_request(req, BLK_STS_OK, blocks << 9);
        } else {
-               req_pending = blk_end_request(req, 0, brq->data.bytes_xfered);
+               req_pending = blk_end_request(req, BLK_STS_OK, brq->data.bytes_xfered);
        }
        return req_pending;
 }
--

1.9.1

Applied
#2 lore raw

Re: [PATCH V6 01/12] mmc: core: Move mmc_start_areq() declaration

In reply to Adrian Hunter
Quoted 4 lines · Adrian Hunter

mmc_start_areq() is an internal mmc core API. Move the declaration accordingly.

Thanks, applied for next!

Kind regards
Uffe

Quoted 41 lines
---
 drivers/mmc/core/core.h  | 6 ++++++
 include/linux/mmc/core.h | 4 ----
 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/mmc/core/core.h +6 -0
index 55f543fd37c4..ca861091a776 100644
@@ -107,6 +107,12 @@ static inline void mmc_unregister_pm_notifier(struct mmc_host *host) { }
 void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq);
 bool mmc_is_req_done(struct mmc_host *host, struct mmc_request *mrq);
 
+struct mmc_async_req;
+
+struct mmc_async_req *mmc_start_areq(struct mmc_host *host,
+                                    struct mmc_async_req *areq,
+                                    enum mmc_blk_status *ret_stat);
+
 int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
                unsigned int arg);
 int mmc_can_erase(struct mmc_card *card);
include/linux/mmc/core.h +0 -5
index bf1788a224e6..178f699ac172 100644
@@ -165,11 +165,7 @@ struct mmc_request {
 };
 
 struct mmc_card;
-struct mmc_async_req;
 
-struct mmc_async_req *mmc_start_areq(struct mmc_host *host,
-                               struct mmc_async_req *areq,
-                               enum mmc_blk_status *ret_stat);
 void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq);
 int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd,
                int retries);
--

1.9.1

#6 lore raw

Re: [PATCH V6 03/12] mmc: host: Add CQE interface

In reply to Adrian Hunter
Quoted 3 lines · Adrian Hunter

Add CQE host operations, capabilities, and host members.

I have now replaced the previous version with this one, applied for next! Thanks!

Kind regards
Uffe

Quoted 103 lines
---
 include/linux/mmc/core.h |  6 ++++++
 include/linux/mmc/host.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)
include/linux/mmc/core.h +6 -0
index 178f699ac172..927519385482 100644
@@ -156,6 +156,12 @@ struct mmc_request {
        struct completion       completion;
        struct completion       cmd_completion;
        void                    (*done)(struct mmc_request *);/* completion function */
+       /*
+        * Notify uppers layers (e.g. mmc block driver) that recovery is needed
+        * due to an error associated with the mmc_request. Currently used only
+        * by CQE.
+        */
+       void                    (*recovery_notifier)(struct mmc_request *);
        struct mmc_host         *host;
 
        /* Allow other commands during this ongoing data transfer or busy wait */
include/linux/mmc/host.h +53 -1
index e92629518f68..f3f2d07feb2a 100644
@@ -162,6 +162,50 @@ struct mmc_host_ops {
                                  unsigned int direction, int blk_size);
 };
 
+struct mmc_cqe_ops {
+       /* Allocate resources, and make the CQE operational */
+       int     (*cqe_enable)(struct mmc_host *host, struct mmc_card *card);
+       /* Free resources, and make the CQE non-operational */
+       void    (*cqe_disable)(struct mmc_host *host);
+       /*
+        * Issue a read, write or DCMD request to the CQE. Also deal with the
+        * effect of ->cqe_off().
+        */
+       int     (*cqe_request)(struct mmc_host *host, struct mmc_request *mrq);
+       /* Free resources (e.g. DMA mapping) associated with the request */
+       void    (*cqe_post_req)(struct mmc_host *host, struct mmc_request *mrq);
+       /*
+        * Prepare the CQE and host controller to accept non-CQ commands. There
+        * is no corresponding ->cqe_on(), instead ->cqe_request() is required
+        * to deal with that.
+        */
+       void    (*cqe_off)(struct mmc_host *host);
+       /*
+        * Wait for all CQE tasks to complete. Return an error if recovery
+        * becomes necessary.
+        */
+       int     (*cqe_wait_for_idle)(struct mmc_host *host);
+       /*
+        * Notify CQE that a request has timed out. Return false if the request
+        * completed or true if a timeout happened in which case indicate if
+        * recovery is needed.
+        */
+       bool    (*cqe_timeout)(struct mmc_host *host, struct mmc_request *mrq,
+                              bool *recovery_needed);
+       /*
+        * Stop all CQE activity and prepare the CQE and host controller to
+        * accept recovery commands.
+        */
+       void    (*cqe_recovery_start)(struct mmc_host *host);
+       /*
+        * Clear the queue and call mmc_cqe_request_done() on all requests.
+        * Requests that errored will have the error set on the mmc_request
+        * (data->error or cmd->error for DCMD).  Requests that did not error
+        * will have zero data bytes transferred.
+        */
+       void    (*cqe_recovery_finish)(struct mmc_host *host);
+};
+
 struct mmc_async_req {
        /* active mmc request */
        struct mmc_request      *mrq;
@@ -303,6 +347,8 @@ struct mmc_host {
 #define MMC_CAP2_HS400_ES      (1 << 20)       /* Host supports enhanced strobe */
 #define MMC_CAP2_NO_SD         (1 << 21)       /* Do not send SD commands during initialization */
 #define MMC_CAP2_NO_MMC                (1 << 22)       /* Do not send (e)MMC commands during initialization */
+#define MMC_CAP2_CQE           (1 << 23)       /* Has eMMC command queue engine */
+#define MMC_CAP2_CQE_DCMD      (1 << 24)       /* CQE can issue a direct command */
 
        mmc_pm_flag_t           pm_caps;        /* supported pm features */
 
@@ -386,6 +432,13 @@ struct mmc_host {
        int                     dsr_req;        /* DSR value is valid */
        u32                     dsr;    /* optional driver stage (DSR) value */
 
+       /* Command Queue Engine (CQE) support */
+       const struct mmc_cqe_ops *cqe_ops;
+       void                    *cqe_private;
+       int                     cqe_qdepth;
+       bool                    cqe_enabled;
+       bool                    cqe_on;
+
        unsigned long           private[0] ____cacheline_aligned;
 };
 
--

1.9.1

#8 lore raw

Re: [PATCH V6 04/12] mmc: core: Turn off CQE before sending commands

In reply to Adrian Hunter
Quoted 7 lines · Adrian Hunter

CQE needs to be off for the host controller to accept non-CQ commands. Turn off the CQE before sending commands, and ensure it is off in any reset or power management paths, or re-tuning.

This one was already applied.

Kind regards
Uffe

Quoted 41 lines
---
 drivers/mmc/core/core.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/mmc/core/core.c +9 -1
index 5dd1c00d95f5..66c9cf49ad2f 100644
@@ -260,6 +260,9 @@ static void __mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
 
        trace_mmc_request_start(host, mrq);
 
+       if (host->cqe_on)
+               host->cqe_ops->cqe_off(host);
+
        host->ops->request(host, mrq);
 }
 
@@ -979,6 +982,9 @@ int mmc_execute_tuning(struct mmc_card *card)
        if (!host->ops->execute_tuning)
                return 0;
 
+       if (host->cqe_on)
+               host->cqe_ops->cqe_off(host);
+
        if (mmc_card_mmc(card))
                opcode = MMC_SEND_TUNING_BLOCK_HS200;
        else
@@ -1018,6 +1024,9 @@ void mmc_set_bus_width(struct mmc_host *host, unsigned int width)
  */
 void mmc_set_initial_state(struct mmc_host *host)
 {
+       if (host->cqe_on)
+               host->cqe_ops->cqe_off(host);
+
        mmc_retune_disable(host);
 
        if (mmc_host_is_spi(host))
--

1.9.1