Skip to contentSkip to conversation

mmc: Add Command Queue support

PATCH Superseded Adrian Hunter 4 participants 44 messages Sep 13, 2017 – Oct 24, 2017

Subsystems (4)

v8 of 15 Superseded Latest is v15 →

lore
Share & tools
lore

Adrian Hunter

author maintainer
#0 lore raw

v8 cover mmc: Add Command Queue support

Hi

Here is V8 of the hardware command queue patches without the software command queue patches, now using blk-mq and now with blk-mq support for non-CQE I/O.

After the unacceptable debacle of the last release cycle, I expect an immediate response to these patches.

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.

Non-CQE blk-mq showed a 3% decrease in sequential read performance. This seemed to be coming from the inferior latency of running work items compared with a dedicated thread. Hacking blk-mq workqueue to be unbound reduced the performance degradation from 3% to 1%.

While we should look at changing blk-mq to give better workqueue performance, a bigger gain is likely to be made by adding a new host API to enable the next already-prepared request to be issued directly from within ->done() callback of the current request.

Changes since V7:
Re-based
mmc: core: Introduce host claiming by context
Slightly simplified
mmc: core: Add parameter use_blk_mq
New patch.
mmc: core: Remove unnecessary host claim
New patch.
mmc: core: Export mmc_start_bkops()
New patch.
mmc: core: Export mmc_start_request()
New patch.
mmc: block: Add CQE and blk-mq support
Add blk-mq support for non_CQE requests

Changes since V6:
mmc: core: Introduce host claiming by context
New patch.
mmc: core: Move mmc_start_areq() declaration
Dropped because it has been applied
mmc: block: Fix block status codes
Dropped because it has been applied
mmc: host: Add CQE interface
Dropped because it has been applied
mmc: core: Turn off CQE before sending commands
Dropped because it has been applied
mmc: block: Factor out mmc_setup_queue()
New patch.
mmc: block: Add CQE support
Drop legacy support and add blk-mq support

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 (13):
mmc: core: Introduce host claiming by context
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: Factor out mmc_setup_queue()
mmc: core: Add parameter use_blk_mq
mmc: core: Remove unnecessary host claim
mmc: core: Export mmc_start_bkops()
mmc: core: Export mmc_start_request()
mmc: block: Add CQE and blk-mq support
mmc: sdhci-pci: Add CQHCI support for Intel GLK

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

 drivers/mmc/Kconfig               |   11 +
 drivers/mmc/core/block.c          |  777 ++++++++++++++++++++++++-
 drivers/mmc/core/block.h          |    8 +
 drivers/mmc/core/bus.c            |    7 +
 drivers/mmc/core/core.c           |  265 ++++++++-
 drivers/mmc/core/core.h           |   14 +
 drivers/mmc/core/host.c           |    2 +
 drivers/mmc/core/host.h           |    4 +
 drivers/mmc/core/mmc.c            |   29 +
 drivers/mmc/core/mmc_ops.c        |    6 +-
 drivers/mmc/core/queue.c          |  479 +++++++++++++--
 drivers/mmc/core/queue.h          |   54 +-
 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/host.h          |   10 +-
 18 files changed, 3146 insertions(+), 83 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 v8 1/14 mmc: core: Introduce host claiming by context

Currently the host can be claimed by a task. Change this so that the host can be claimed by a context that may or may not be a task. This provides for the host to be claimed by a block driver queue to support blk-mq, while maintaining compatibility with the existing use of mmc_claim_host().

---
 drivers/mmc/core/core.c  | 92 ++++++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/core/core.h  |  6 ++++
 include/linux/mmc/host.h |  7 +++-
 3 files changed, 97 insertions(+), 8 deletions(-)
drivers/mmc/core/core.c +85 -7
index 66c9cf49ad2f..09fdc467b804 100644
@@ -832,9 +832,38 @@ unsigned int mmc_align_data_size(struct mmc_card *card, unsigned int sz)
 }
 EXPORT_SYMBOL(mmc_align_data_size);
 
+/*
+ * Allow claiming an already claimed host if the context is the same or there is
+ * no context but the task is the same.
+ */
+static inline bool mmc_ctx_matches(struct mmc_host *host, struct mmc_ctx *ctx,
+				   struct task_struct *task)
+{
+	return host->claimer == ctx ||
+	       (!ctx && task && host->claimer->task == task);
+}
+
+static inline void mmc_ctx_set_claimer(struct mmc_host *host,
+				       struct mmc_ctx *ctx,
+				       struct task_struct *task)
+{
+	if (!host->claimer) {
+		if (ctx)
+			host->claimer = ctx;
+		else
+			host->claimer = &host->default_ctx;
+	}
+	if (task)
+		host->claimer->task = task;
+}
+
 /**
- *	__mmc_claim_host - exclusively claim a host
+ *	__mmc_ctx_task_claim_host - exclusively claim a host
  *	@host: mmc host to claim
+ *	@ctx: context that claims the host or NULL in which case the default
+ *	context will be used
+ *	@task: task that claims the host or NULL in which case @ctx must be
+ *	provided
  *	@abort: whether or not the operation should be aborted
  *
  *	Claim a host for a set of operations.  If @abort is non null and
@@ -842,7 +871,8 @@ unsigned int mmc_align_data_size(struct mmc_card *card, unsigned int sz)
  *	that non-zero value without acquiring the lock.  Returns zero
  *	with the lock held otherwise.
  */
-int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
+static int __mmc_ctx_task_claim_host(struct mmc_host *host, struct mmc_ctx *ctx,
+				     struct task_struct *task, atomic_t *abort)
 {
 	DECLARE_WAITQUEUE(wait, current);
 	unsigned long flags;
@@ -856,7 +886,7 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
 	while (1) {
 		set_current_state(TASK_UNINTERRUPTIBLE);
 		stop = abort ? atomic_read(abort) : 0;
-		if (stop || !host->claimed || host->claimer == current)
+		if (stop || !host->claimed || mmc_ctx_matches(host, ctx, task))
 			break;
 		spin_unlock_irqrestore(&host->lock, flags);
 		schedule();
@@ -865,7 +895,7 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
 	set_current_state(TASK_RUNNING);
 	if (!stop) {
 		host->claimed = 1;
-		host->claimer = current;
+		mmc_ctx_set_claimer(host, ctx, task);
 		host->claim_cnt += 1;
 		if (host->claim_cnt == 1)
 			pm = true;
@@ -879,8 +909,19 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
 
 	return stop;
 }
+
+int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
+{
+	return __mmc_ctx_task_claim_host(host, NULL, current, abort);
+}
 EXPORT_SYMBOL(__mmc_claim_host);
 
+void mmc_ctx_claim_host(struct mmc_host *host, struct mmc_ctx *ctx)
+{
+	__mmc_ctx_task_claim_host(host, ctx, NULL, NULL);
+}
+EXPORT_SYMBOL(mmc_ctx_claim_host);
+
 /**
  *	mmc_release_host - release a host
  *	@host: mmc host to release
@@ -888,18 +929,17 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
  *	Release a MMC host, allowing others to claim the host
  *	for their operations.
  */
-void mmc_release_host(struct mmc_host *host)
+static void __mmc_release_host(struct mmc_host *host)
 {
 	unsigned long flags;
 
-	WARN_ON(!host->claimed);
-
 	spin_lock_irqsave(&host->lock, flags);
 	if (--host->claim_cnt) {
 		/* Release for nested claim */
 		spin_unlock_irqrestore(&host->lock, flags);
 	} else {
 		host->claimed = 0;
+		host->claimer->task = NULL;
 		host->claimer = NULL;
 		spin_unlock_irqrestore(&host->lock, flags);
 		wake_up(&host->wq);
@@ -907,8 +947,23 @@ void mmc_release_host(struct mmc_host *host)
 		pm_runtime_put_autosuspend(mmc_dev(host));
 	}
 }
+
+void mmc_release_host(struct mmc_host *host)
+{
+	WARN_ON(!host->claimed);
+
+	__mmc_release_host(host);
+}
 EXPORT_SYMBOL(mmc_release_host);
 
+void mmc_ctx_release_host(struct mmc_host *host, struct mmc_ctx *ctx)
+{
+	WARN_ON(!host->claimed || host->claimer != ctx);
+
+	__mmc_release_host(host);
+}
+EXPORT_SYMBOL(mmc_ctx_release_host);
+
 /*
  * This is a helper function, which fetches a runtime pm reference for the
  * card device and also claims the host.
@@ -921,6 +976,17 @@ void mmc_get_card(struct mmc_card *card)
 EXPORT_SYMBOL(mmc_get_card);
 
 /*
+ * This is a helper function, which fetches a runtime pm reference for the
+ * card device and also claims the host for the mmc context.
+ */
+void mmc_ctx_get_card(struct mmc_card *card, struct mmc_ctx *ctx)
+{
+	pm_runtime_get_sync(&card->dev);
+	mmc_ctx_claim_host(card->host, ctx);
+}
+EXPORT_SYMBOL(mmc_ctx_get_card);
+
+/*
  * This is a helper function, which releases the host and drops the runtime
  * pm reference for the card device.
  */
@@ -933,6 +999,18 @@ void mmc_put_card(struct mmc_card *card)
 EXPORT_SYMBOL(mmc_put_card);
 
 /*
+ * This is a helper function, which releases the host and drops the runtime
+ * pm reference for the card device.
+ */
+void mmc_ctx_put_card(struct mmc_card *card, struct mmc_ctx *ctx)
+{
+	mmc_ctx_release_host(card->host, ctx);
+	pm_runtime_mark_last_busy(&card->dev);
+	pm_runtime_put_autosuspend(&card->dev);
+}
+EXPORT_SYMBOL(mmc_ctx_put_card);
+
+/*
  * Internal function that does the actual ios call to the host driver,
  * optionally printing some debug output.
  */
drivers/mmc/core/core.h +6 -0
index ca861091a776..a294c836a143 100644
@@ -144,4 +144,10 @@ static inline void mmc_claim_host(struct mmc_host *host)
 	__mmc_claim_host(host, NULL);
 }
 
+void mmc_ctx_claim_host(struct mmc_host *host, struct mmc_ctx *ctx);
+void mmc_ctx_release_host(struct mmc_host *host, struct mmc_ctx *ctx);
+
+void mmc_ctx_get_card(struct mmc_card *card, struct mmc_ctx *ctx);
+void mmc_ctx_put_card(struct mmc_card *card, struct mmc_ctx *ctx);
+
 #endif
include/linux/mmc/host.h +6 -1
index f3f2d07feb2a..228a493c3b25 100644
@@ -255,6 +255,10 @@ struct mmc_supply {
 	struct regulator *vqmmc;	/* Optional Vccq supply */
 };
 
+struct mmc_ctx {
+	struct task_struct *task;
+};
+
 struct mmc_host {
 	struct device		*parent;
 	struct device		class_dev;
@@ -388,8 +392,9 @@ struct mmc_host {
 	struct mmc_card		*card;		/* device attached to this host */
 
 	wait_queue_head_t	wq;
-	struct task_struct	*claimer;	/* task that has host claimed */
+	struct mmc_ctx		*claimer;	/* context that has host claimed */
 	int			claim_cnt;	/* "claim" nesting count */
+	struct mmc_ctx		default_ctx;	/* default context */
 
 	struct delayed_work	detect;
 	int			detect_change;	/* card detect flag */
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH V8 01/14] mmc: core: Introduce host claiming by context

Quoted 4 lines · Adrian Hunter

Currently the host can be claimed by a task. Change this so that the host can be claimed by a context that may or may not be a task. This provides for the host to be claimed by a block driver queue to support blk-mq, while maintaining compatibility with the existing use of mmc_claim_host().

As stated earlier, I think this is a good approach, which allows us to move forward.

Some comments below, most related how to avoid us from adding more wrapper functions.

Quoted 81 lines
---
 drivers/mmc/core/core.c  | 92 ++++++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/core/core.h  |  6 ++++
 include/linux/mmc/host.h |  7 +++-
 3 files changed, 97 insertions(+), 8 deletions(-)
drivers/mmc/core/core.c +34 -4
index 66c9cf49ad2f..09fdc467b804 100644
@@ -832,9 +832,38 @@ unsigned int mmc_align_data_size(struct mmc_card *card, unsigned int sz)
 }
 EXPORT_SYMBOL(mmc_align_data_size);
 
+/*
+ * Allow claiming an already claimed host if the context is the same or there is
+ * no context but the task is the same.
+ */
+static inline bool mmc_ctx_matches(struct mmc_host *host, struct mmc_ctx *ctx,
+                                  struct task_struct *task)
+{
+       return host->claimer == ctx ||
+              (!ctx && task && host->claimer->task == task);
+}
+
+static inline void mmc_ctx_set_claimer(struct mmc_host *host,
+                                      struct mmc_ctx *ctx,
+                                      struct task_struct *task)
+{
+       if (!host->claimer) {
+               if (ctx)
+                       host->claimer = ctx;
+               else
+                       host->claimer = &host->default_ctx;
+       }
+       if (task)
+               host->claimer->task = task;
+}
+
 /**
- *     __mmc_claim_host - exclusively claim a host
+ *     __mmc_ctx_task_claim_host - exclusively claim a host
  *     @host: mmc host to claim
+ *     @ctx: context that claims the host or NULL in which case the default
+ *     context will be used
+ *     @task: task that claims the host or NULL in which case @ctx must be
+ *     provided
  *     @abort: whether or not the operation should be aborted
  *
  *     Claim a host for a set of operations.  If @abort is non null and
@@ -842,7 +871,8 @@ unsigned int mmc_align_data_size(struct mmc_card *card, unsigned int sz)
  *     that non-zero value without acquiring the lock.  Returns zero
  *     with the lock held otherwise.
  */
-int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
+static int __mmc_ctx_task_claim_host(struct mmc_host *host, struct mmc_ctx *ctx,
+                                    struct task_struct *task, atomic_t *abort)
 {
        DECLARE_WAITQUEUE(wait, current);
        unsigned long flags;
@@ -856,7 +886,7 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
        while (1) {
                set_current_state(TASK_UNINTERRUPTIBLE);
                stop = abort ? atomic_read(abort) : 0;
-               if (stop || !host->claimed || host->claimer == current)
+               if (stop || !host->claimed || mmc_ctx_matches(host, ctx, task))
                        break;
                spin_unlock_irqrestore(&host->lock, flags);
                schedule();
@@ -865,7 +895,7 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
        set_current_state(TASK_RUNNING);
        if (!stop) {
                host->claimed = 1;
-               host->claimer = current;
+               mmc_ctx_set_claimer(host, ctx, task);
                host->claim_cnt += 1;
                if (host->claim_cnt == 1)
                        pm = true;

drivers/mmc/core/core.c int __mmc_claim_host(struct mmc_host *host, atomic_t *abort) · line 917

Quoted 9 lines
drivers/mmc/core/core.c +5 -0
@@ -879,8 +909,19 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
 
        return stop;
 }
+
+int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
+{
+       return __mmc_ctx_task_claim_host(host, NULL, current, abort);
+}
 EXPORT_SYMBOL(__mmc_claim_host);

There is currently only two users of __mmc_claim_host().

Instead of adding yet another layer of wrapper functions, let's keep the existing __mmc_claim_host(), but change its definition to take the new parameters. Then change the existing two users.

drivers/mmc/core/core.c int __mmc_claim_host(struct mmc_host *host, atomic_t *abort) · line 923

Quoted 6 lines
drivers/mmc/core/core.c +5 -0
+void mmc_ctx_claim_host(struct mmc_host *host, struct mmc_ctx *ctx)
+{
+       __mmc_ctx_task_claim_host(host, ctx, NULL, NULL);
+}
+EXPORT_SYMBOL(mmc_ctx_claim_host);

There is no need to make this an exported function, better to keep it static and only to core.c.

As a matter of fact, I suggest you remove this function altogether, and just call __mmc_claim_host(), with the new parameters, from mmc_ctx_get_card().

Quoted 46 lines
drivers/mmc/core/core.c +17 -3
+
 /**
  *     mmc_release_host - release a host
  *     @host: mmc host to release
@@ -888,18 +929,17 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
  *     Release a MMC host, allowing others to claim the host
  *     for their operations.
  */
-void mmc_release_host(struct mmc_host *host)
+static void __mmc_release_host(struct mmc_host *host)
 {
        unsigned long flags;
 
-       WARN_ON(!host->claimed);
-
        spin_lock_irqsave(&host->lock, flags);
        if (--host->claim_cnt) {
                /* Release for nested claim */
                spin_unlock_irqrestore(&host->lock, flags);
        } else {
                host->claimed = 0;
+               host->claimer->task = NULL;
                host->claimer = NULL;
                spin_unlock_irqrestore(&host->lock, flags);
                wake_up(&host->wq);
@@ -907,8 +947,23 @@ void mmc_release_host(struct mmc_host *host)
                pm_runtime_put_autosuspend(mmc_dev(host));
        }
 }
+
+void mmc_release_host(struct mmc_host *host)
+{
+       WARN_ON(!host->claimed);
+
+       __mmc_release_host(host);
+}
 EXPORT_SYMBOL(mmc_release_host);
 
+void mmc_ctx_release_host(struct mmc_host *host, struct mmc_ctx *ctx)
+{
+       WARN_ON(!host->claimed || host->claimer != ctx);
+
+       __mmc_release_host(host);
+}
+EXPORT_SYMBOL(mmc_ctx_release_host);
 
Quoted 1 line

From the same reasoning as above, I think this should be converted to

a static function.

Or more preferably, remove it altogether, and just call __mmc_release_host() from mmc_ctx_put_card().

Quoted 7 lines
drivers/mmc/core/core.c +1 -0
+
 /*
  * This is a helper function, which fetches a runtime pm reference for the
  * card device and also claims the host.
@@ -921,6 +976,17 @@ void mmc_get_card(struct mmc_card *card)
 EXPORT_SYMBOL(mmc_get_card);
 

drivers/mmc/core/core.c void mmc_get_card(struct mmc_card *card) · line 987

Quoted 10 lines
drivers/mmc/core/core.c +9 -0
 /*
+ * This is a helper function, which fetches a runtime pm reference for the
+ * card device and also claims the host for the mmc context.
+ */
+void mmc_ctx_get_card(struct mmc_card *card, struct mmc_ctx *ctx)
+{
+       pm_runtime_get_sync(&card->dev);
+       mmc_ctx_claim_host(card->host, ctx);
+}
+EXPORT_SYMBOL(mmc_ctx_get_card);

Again, please avoid adding yet another layer of wrapper functions.

Instead change the existing mmc_get_card() to take the parameter and then change the existing three users of it.

Quoted 9 lines
drivers/mmc/core/core.c +2 -0
+
+/*
  * This is a helper function, which releases the host and drops the runtime
  * pm reference for the card device.
  */
@@ -933,6 +999,18 @@ void mmc_put_card(struct mmc_card *card)
 EXPORT_SYMBOL(mmc_put_card);
 
 /*

drivers/mmc/core/core.c void mmc_put_card(struct mmc_card *card) · line 1011

Quoted 10 lines
drivers/mmc/core/core.c +10 -0
+ * This is a helper function, which releases the host and drops the runtime
+ * pm reference for the card device.
+ */
+void mmc_ctx_put_card(struct mmc_card *card, struct mmc_ctx *ctx)
+{
+       mmc_ctx_release_host(card->host, ctx);
+       pm_runtime_mark_last_busy(&card->dev);
+       pm_runtime_put_autosuspend(&card->dev);
+}
+EXPORT_SYMBOL(mmc_ctx_put_card);

Ditto.

Quoted 47 lines
drivers/mmc/core/core.c +2 -0
+
+/*
  * Internal function that does the actual ios call to the host driver,
  * optionally printing some debug output.
  */
drivers/mmc/core/core.h +6 -0
index ca861091a776..a294c836a143 100644
@@ -144,4 +144,10 @@ static inline void mmc_claim_host(struct mmc_host *host)
        __mmc_claim_host(host, NULL);
 }
 
+void mmc_ctx_claim_host(struct mmc_host *host, struct mmc_ctx *ctx);
+void mmc_ctx_release_host(struct mmc_host *host, struct mmc_ctx *ctx);
+
+void mmc_ctx_get_card(struct mmc_card *card, struct mmc_ctx *ctx);
+void mmc_ctx_put_card(struct mmc_card *card, struct mmc_ctx *ctx);
+
 #endif
include/linux/mmc/host.h +6 -2
index f3f2d07feb2a..228a493c3b25 100644
@@ -255,6 +255,10 @@ struct mmc_supply {
        struct regulator *vqmmc;        /* Optional Vccq supply */
 };
 
+struct mmc_ctx {
+       struct task_struct *task;
+};
+
 struct mmc_host {
        struct device           *parent;
        struct device           class_dev;
@@ -388,8 +392,9 @@ struct mmc_host {
        struct mmc_card         *card;          /* device attached to this host */
 
        wait_queue_head_t       wq;
-       struct task_struct      *claimer;       /* task that has host claimed */
+       struct mmc_ctx          *claimer;       /* context that has host claimed */
        int                     claim_cnt;      /* "claim" nesting count */
+       struct mmc_ctx          default_ctx;    /* default context */
 
        struct delayed_work     detect;
        int                     detect_change;  /* card detect flag */
--
Quoted 2 lines

1.9.1

Kind regards
Uffe

#3 lore raw

Re: [PATCH V8 01/14] mmc: core: Introduce host claiming by context

In reply to Adrian Hunter
Quoted 6 lines · Adrian Hunter

Currently the host can be claimed by a task. Change this so that the host can be claimed by a context that may or may not be a task. This provides for the host to be claimed by a block driver queue to support blk-mq, while maintaining compatibility with the existing use of mmc_claim_host().

I think this is a reasonable intermediate step as well. I am working to kill off the "big MMC host lock" by the following plan:

DONE:
- Convert all ioctl() ops to custom block layer requests (done)
- Convert all debugfs ops to custom block layer requests (done)
- Convert RPMB access to a character device to avoid one partition switch (just merged)

REMAINS:
- Convert boot and "general" partitions to be part of the main block device. Because they are. (This is really tricky and may require changes in the core kernel partition handling.)
- Delete the dual mode card support. (No-one seems to be using it.)
- Split the world in block access and SDIO with something like a simple mutex: either the host is a block device OR it is SDIO, and that state has the same lifetime as a card, since they are now either block devices or SDIO not both at the same time.
- Implement a lighter lock for SDIO host claiming.
- Now the lock should be gone...

As you can see it is not entirely trivial :/

Linus

author maintainer
#4 lore raw

PATCH v8 2/14 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 09fdc467b804..ef2d8aa1e7d2 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 a294c836a143..e941342ed450 100644
@@ -150,4 +150,8 @@ static inline void mmc_claim_host(struct mmc_host *host)
 void mmc_ctx_get_card(struct mmc_card *card, struct mmc_ctx *ctx);
 void mmc_ctx_put_card(struct mmc_card *card, struct mmc_ctx *ctx);
 
+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 228a493c3b25..54b0463443bd 100644
@@ -474,6 +474,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
#5 lore raw

PATCH v8 3/14 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
#6 lore raw

PATCH v8 4/14 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
#7 lore raw

PATCH v8 5/14 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 29fc1e662891..1ec5f0bc98d2 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
#8 lore raw

PATCH v8 6/14 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 1ec5f0bc98d2..2424c7360687 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
#9 lore raw

PATCH v8 7/14 mmc: block: Factor out mmc_setup_queue()

In reply to Adrian Hunter

Factor out some common code that will also be used with blk-mq.

---
 drivers/mmc/core/queue.c | 51 ++++++++++++++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 21 deletions(-)
drivers/mmc/core/queue.c +30 -21
index 74c663b1c0a7..da74fe4e638a 100644
@@ -223,6 +223,35 @@ static void mmc_exit_request(struct request_queue *q, struct request *req)
 	mq_rq->sg = NULL;
 }
 
+static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)
+{
+	struct mmc_host *host = card->host;
+	u64 limit = BLK_BOUNCE_HIGH;
+
+	if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
+		limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT;
+
+	queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue);
+	queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, mq->queue);
+	if (mmc_can_erase(card))
+		mmc_queue_setup_discard(mq->queue, card);
+
+	if (card->bouncesz) {
+		blk_queue_max_hw_sectors(mq->queue, card->bouncesz / 512);
+		blk_queue_max_segments(mq->queue, card->bouncesz / 512);
+		blk_queue_max_segment_size(mq->queue, card->bouncesz);
+	} else {
+		blk_queue_bounce_limit(mq->queue, limit);
+		blk_queue_max_hw_sectors(mq->queue,
+			min(host->max_blk_count, host->max_req_size / 512));
+		blk_queue_max_segments(mq->queue, host->max_segs);
+		blk_queue_max_segment_size(mq->queue, host->max_seg_size);
+	}
+
+	/* Initialize thread_sem even if it is not used */
+	sema_init(&mq->thread_sem, 1);
+}
+
 /**
  * mmc_init_queue - initialise a queue structure.
  * @mq: mmc queue
@@ -236,12 +265,8 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
 		   spinlock_t *lock, const char *subname)
 {
 	struct mmc_host *host = card->host;
-	u64 limit = BLK_BOUNCE_HIGH;
 	int ret = -ENOMEM;
 
-	if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
-		limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT;
-
 	/*
 	 * mmc_init_request() depends on card->bouncesz so it must be calculated
 	 * before blk_init_allocated_queue() starts allocating requests.
@@ -266,24 +291,8 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
 	}
 
 	blk_queue_prep_rq(mq->queue, mmc_prep_request);
-	queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue);
-	queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, mq->queue);
-	if (mmc_can_erase(card))
-		mmc_queue_setup_discard(mq->queue, card);
-
-	if (card->bouncesz) {
-		blk_queue_max_hw_sectors(mq->queue, card->bouncesz / 512);
-		blk_queue_max_segments(mq->queue, card->bouncesz / 512);
-		blk_queue_max_segment_size(mq->queue, card->bouncesz);
-	} else {
-		blk_queue_bounce_limit(mq->queue, limit);
-		blk_queue_max_hw_sectors(mq->queue,
-			min(host->max_blk_count, host->max_req_size / 512));
-		blk_queue_max_segments(mq->queue, host->max_segs);
-		blk_queue_max_segment_size(mq->queue, host->max_seg_size);
-	}
 
-	sema_init(&mq->thread_sem, 1);
+	mmc_setup_queue(mq, card);
 
 	mq->thread = kthread_run(mmc_queue_thread, mq, "mmcqd/%d%s",
 		host->index, subname ? subname : "");
Signature · 1 line
1.9.1
author maintainer
#10 lore raw

PATCH v8 8/14 mmc: core: Add parameter use_blk_mq

In reply to Adrian Hunter

Until mmc has blk-mq support fully implemented and tested, add a parameter use_blk_mq, default to false unless config option MMC_MQ_DEFAULT is selected.

---
 drivers/mmc/Kconfig      | 11 +++++++++++
 drivers/mmc/core/core.c  |  7 +++++++
 drivers/mmc/core/core.h  |  2 ++
 drivers/mmc/core/host.c  |  2 ++
 drivers/mmc/core/host.h  |  4 ++++
 include/linux/mmc/host.h |  1 +
 6 files changed, 27 insertions(+)
drivers/mmc/Kconfig +11 -0
index ec21388311db..98202934bd29 100644
@@ -12,6 +12,17 @@ menuconfig MMC
 	  If you want MMC/SD/SDIO support, you should say Y here and
 	  also to your specific host controller driver.
 
+config MMC_MQ_DEFAULT
+	bool "MMC: use blk-mq I/O path by default"
+	depends on MMC && BLOCK
+	---help---
+	  This option enables the new blk-mq based I/O path for MMC block
+	  devices by default.  With the option the mmc_core.use_blk_mq
+	  module/boot option defaults to Y, without it to N, but it can
+	  still be overridden either way.
+
+	  If unsure say N.
+
 if MMC
 
 source "drivers/mmc/core/Kconfig"
drivers/mmc/core/core.c +7 -0
index ef2d8aa1e7d2..3638ed4f0f9e 100644
@@ -66,6 +66,13 @@
 bool use_spi_crc = 1;
 module_param(use_spi_crc, bool, 0);
 
+#ifdef CONFIG_MMC_MQ_DEFAULT
+bool mmc_use_blk_mq = true;
+#else
+bool mmc_use_blk_mq = false;
+#endif
+module_param_named(use_blk_mq, mmc_use_blk_mq, bool, S_IWUSR | S_IRUGO);
+
 static int mmc_schedule_delayed_work(struct delayed_work *work,
 				     unsigned long delay)
 {
drivers/mmc/core/core.h +2 -0
index e941342ed450..535539a9e7eb 100644
@@ -35,6 +35,8 @@ struct mmc_bus_ops {
 	int (*reset)(struct mmc_host *);
 };
 
+extern bool mmc_use_blk_mq;
+
 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
 void mmc_detach_bus(struct mmc_host *host);
 
drivers/mmc/core/host.c +2 -0
index ad88deb2e8f3..b624dbb6cd15 100644
@@ -398,6 +398,8 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
 	host->max_blk_size = 512;
 	host->max_blk_count = PAGE_SIZE / 512;
 
+	host->use_blk_mq = mmc_use_blk_mq;
+
 	return host;
 }
 
drivers/mmc/core/host.h +4 -0
index 77d6f60d1bf9..170fe5947087 100644
@@ -69,6 +69,10 @@ static inline bool mmc_card_hs400es(struct mmc_card *card)
 	return card->host->ios.enhanced_strobe;
 }
 
+static inline bool mmc_host_use_blk_mq(struct mmc_host *host)
+{
+	return host->use_blk_mq;
+}
 
 #endif
 
include/linux/mmc/host.h +1 -0
index 54b0463443bd..5d1bd10991f7 100644
@@ -378,6 +378,7 @@ struct mmc_host {
 	unsigned int		doing_retune:1;	/* re-tuning in progress */
 	unsigned int		retune_now:1;	/* do re-tuning at next req */
 	unsigned int		retune_paused:1; /* re-tuning is temporarily disabled */
+	unsigned int		use_blk_mq:1;	/* use blk-mq */
 
 	int			rescan_disable;	/* disable card detection */
 	int			rescan_entered;	/* used with nonremovable devices */
Signature · 1 line
1.9.1
#11 lore raw

Re: [PATCH V8 08/14] mmc: core: Add parameter use_blk_mq

Quoted 24 lines · Adrian Hunter

Until mmc has blk-mq support fully implemented and tested, add a parameter use_blk_mq, default to false unless config option MMC_MQ_DEFAULT is selected.

---
 drivers/mmc/Kconfig      | 11 +++++++++++
 drivers/mmc/core/core.c  |  7 +++++++
 drivers/mmc/core/core.h  |  2 ++
 drivers/mmc/core/host.c  |  2 ++
 drivers/mmc/core/host.h  |  4 ++++
 include/linux/mmc/host.h |  1 +
 6 files changed, 27 insertions(+)
drivers/mmc/Kconfig +2 -0
index ec21388311db..98202934bd29 100644
@@ -12,6 +12,17 @@ menuconfig MMC
          If you want MMC/SD/SDIO support, you should say Y here and
          also to your specific host controller driver.
 
+config MMC_MQ_DEFAULT
+       bool "MMC: use blk-mq I/O path by default"

drivers/mmc/Kconfig menuconfig MMC · line 26

Quoted 10 lines
drivers/mmc/Kconfig +9 -0
+       depends on MMC && BLOCK
+       ---help---
+         This option enables the new blk-mq based I/O path for MMC block
+         devices by default.  With the option the mmc_core.use_blk_mq
+         module/boot option defaults to Y, without it to N, but it can
+         still be overridden either way.
+
+         If unsure say N.
+
 if MMC

I asume the goal of adding this option is to enable us to move slowly forward. In general that might be a good idea, however for this particular case I am not sure.

The main reason is simply that I find it unlikely that people and distributions will actually go in and change the default value, so in the end we will just be adding new code, which isn't really going to be much tested. That's what happened in scsi case.

As I also stated earlier, I do worry about the maintenance of the mmc block device code, and this approach make it worse, at least short term.

To me, the scsi case is also different, because the mq support was added long time ago and at that point one could worry a bit of maturity of the blkmq in general, that I assume have been sorted out by know.

Quoted 74 lines
drivers/mmc/Kconfig +0 -0
 source "drivers/mmc/core/Kconfig"
drivers/mmc/core/core.c +7 -0
index ef2d8aa1e7d2..3638ed4f0f9e 100644
@@ -66,6 +66,13 @@
 bool use_spi_crc = 1;
 module_param(use_spi_crc, bool, 0);
 
+#ifdef CONFIG_MMC_MQ_DEFAULT
+bool mmc_use_blk_mq = true;
+#else
+bool mmc_use_blk_mq = false;
+#endif
+module_param_named(use_blk_mq, mmc_use_blk_mq, bool, S_IWUSR | S_IRUGO);
+
 static int mmc_schedule_delayed_work(struct delayed_work *work,
                                     unsigned long delay)
 {
drivers/mmc/core/core.h +2 -0
index e941342ed450..535539a9e7eb 100644
@@ -35,6 +35,8 @@ struct mmc_bus_ops {
        int (*reset)(struct mmc_host *);
 };
 
+extern bool mmc_use_blk_mq;
+
 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
 void mmc_detach_bus(struct mmc_host *host);
 
drivers/mmc/core/host.c +2 -0
index ad88deb2e8f3..b624dbb6cd15 100644
@@ -398,6 +398,8 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
        host->max_blk_size = 512;
        host->max_blk_count = PAGE_SIZE / 512;
 
+       host->use_blk_mq = mmc_use_blk_mq;
+
        return host;
 }
 
drivers/mmc/core/host.h +4 -0
index 77d6f60d1bf9..170fe5947087 100644
@@ -69,6 +69,10 @@ static inline bool mmc_card_hs400es(struct mmc_card *card)
        return card->host->ios.enhanced_strobe;
 }
 
+static inline bool mmc_host_use_blk_mq(struct mmc_host *host)
+{
+       return host->use_blk_mq;
+}
 
 #endif
 
include/linux/mmc/host.h +1 -1
index 54b0463443bd..5d1bd10991f7 100644
@@ -378,6 +378,7 @@ struct mmc_host {
        unsigned int            doing_retune:1; /* re-tuning in progress */
        unsigned int            retune_now:1;   /* do re-tuning at next req */
        unsigned int            retune_paused:1; /* re-tuning is temporarily disabled */
+       unsigned int            use_blk_mq:1;   /* use blk-mq */
 
        int                     rescan_disable; /* disable card detection */
        int                     rescan_entered; /* used with nonremovable devices */
--
Quoted 2 lines

1.9.1

Kind regards
Uffe

author maintainer
#12 lore raw

Re: [PATCH V8 08/14] mmc: core: Add parameter use_blk_mq

Quoted 40 lines · Ulf Hansson
Quoted 24 lines · Adrian Hunter

Until mmc has blk-mq support fully implemented and tested, add a parameter use_blk_mq, default to false unless config option MMC_MQ_DEFAULT is selected.

---
 drivers/mmc/Kconfig      | 11 +++++++++++
 drivers/mmc/core/core.c  |  7 +++++++
 drivers/mmc/core/core.h  |  2 ++
 drivers/mmc/core/host.c  |  2 ++
 drivers/mmc/core/host.h  |  4 ++++
 include/linux/mmc/host.h |  1 +
 6 files changed, 27 insertions(+)
drivers/mmc/Kconfig +2 -0
index ec21388311db..98202934bd29 100644
@@ -12,6 +12,17 @@ menuconfig MMC
          If you want MMC/SD/SDIO support, you should say Y here and
          also to your specific host controller driver.
 
+config MMC_MQ_DEFAULT
+       bool "MMC: use blk-mq I/O path by default"

drivers/mmc/Kconfig menuconfig MMC · line 26

Quoted 10 lines
drivers/mmc/Kconfig +9 -0
+       depends on MMC && BLOCK
+       ---help---
+         This option enables the new blk-mq based I/O path for MMC block
+         devices by default.  With the option the mmc_core.use_blk_mq
+         module/boot option defaults to Y, without it to N, but it can
+         still be overridden either way.
+
+         If unsure say N.
+
 if MMC

I asume the goal of adding this option is to enable us to move slowly forward. In general that might be a good idea, however for this particular case I am not sure.

Quoted 4 lines

The main reason is simply that I find it unlikely that people and distributions will actually go in and change the default value, so in the end we will just be adding new code, which isn't really going to be much tested. That's what happened in scsi case.

The argument that no one is going to test anyway so we shouldn't give them the opportunity, is not a sustainable vision for the future. Instead we should reach out to relevant stakeholders and get them to do their testing with blk-mq first.

Quoted 4 lines

As I also stated earlier, I do worry about the maintenance of the mmc block device code, and this approach make it worse, at least short term.

What maintenance?

Quoted 5 lines

To me, the scsi case is also different, because the mq support was added long time ago and at that point one could worry a bit of maturity of the blkmq in general, that I assume have been sorted out by know.

But blk-mq still isn't fully ready for all of scsi, so you seem to be contradicting yourself.

Quoted 81 lines
Quoted 75 lines
drivers/mmc/Kconfig +0 -0
 source "drivers/mmc/core/Kconfig"
drivers/mmc/core/core.c +7 -0
index ef2d8aa1e7d2..3638ed4f0f9e 100644
@@ -66,6 +66,13 @@
 bool use_spi_crc = 1;
 module_param(use_spi_crc, bool, 0);
 
+#ifdef CONFIG_MMC_MQ_DEFAULT
+bool mmc_use_blk_mq = true;
+#else
+bool mmc_use_blk_mq = false;
+#endif
+module_param_named(use_blk_mq, mmc_use_blk_mq, bool, S_IWUSR | S_IRUGO);
+
 static int mmc_schedule_delayed_work(struct delayed_work *work,
                                     unsigned long delay)
 {
drivers/mmc/core/core.h +2 -0
index e941342ed450..535539a9e7eb 100644
@@ -35,6 +35,8 @@ struct mmc_bus_ops {
        int (*reset)(struct mmc_host *);
 };
 
+extern bool mmc_use_blk_mq;
+
 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
 void mmc_detach_bus(struct mmc_host *host);
 
drivers/mmc/core/host.c +2 -0
index ad88deb2e8f3..b624dbb6cd15 100644
@@ -398,6 +398,8 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
        host->max_blk_size = 512;
        host->max_blk_count = PAGE_SIZE / 512;
 
+       host->use_blk_mq = mmc_use_blk_mq;
+
        return host;
 }
 
drivers/mmc/core/host.h +4 -0
index 77d6f60d1bf9..170fe5947087 100644
@@ -69,6 +69,10 @@ static inline bool mmc_card_hs400es(struct mmc_card *card)
        return card->host->ios.enhanced_strobe;
 }
 
+static inline bool mmc_host_use_blk_mq(struct mmc_host *host)
+{
+       return host->use_blk_mq;
+}
 
 #endif
 
include/linux/mmc/host.h +1 -1
index 54b0463443bd..5d1bd10991f7 100644
@@ -378,6 +378,7 @@ struct mmc_host {
        unsigned int            doing_retune:1; /* re-tuning in progress */
        unsigned int            retune_now:1;   /* do re-tuning at next req */
        unsigned int            retune_paused:1; /* re-tuning is temporarily disabled */
+       unsigned int            use_blk_mq:1;   /* use blk-mq */
 
        int                     rescan_disable; /* disable card detection */
        int                     rescan_entered; /* used with nonremovable devices */
--
Quoted 2 lines

1.9.1

Kind regards
Uffe

#13 lore raw

Re: [PATCH V8 08/14] mmc: core: Add parameter use_blk_mq

Quoted 11 lines · Adrian Hunter
Quoted 8 lines · Ulf Hansson

I asume the goal of adding this option is to enable us to move slowly forward. In general that might be a good idea, however for this particular case I am not sure.

The main reason is simply that I find it unlikely that people and distributions will actually go in and change the default value, so in the end we will just be adding new code, which isn't really going to be much tested. That's what happened in scsi case.

Quoted 4 lines

The argument that no one is going to test anyway so we shouldn't give them the opportunity, is not a sustainable vision for the future. Instead we should reach out to relevant stakeholders and get them to do their testing with blk-mq first.

We *could* simply invert the option then. Default it to "y" and only leave it as a debugging aid so that people can set it to "n" if they want to test with MQ disabled.

This is also simple to revert by a oneliner just removing "default y" if there are problems with it.

Yours,
Linus Walleij

author maintainer
#14 lore raw

PATCH v8 9/14 mmc: core: Remove unnecessary host claim

In reply to Adrian Hunter

Callers already have the host claimed, so remove the unnecessary calls to mmc_claim_host() and mmc_release_host().

---
 drivers/mmc/core/mmc_ops.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/mmc/core/mmc_ops.c +1 -4
index 54686ca4bfb7..a6b0a232f24a 100644
@@ -977,7 +977,6 @@ void mmc_start_bkops(struct mmc_card *card, bool from_exception)
 	    from_exception)
 		return;
 
-	mmc_claim_host(card->host);
 	if (card->ext_csd.raw_bkops_status >= EXT_CSD_BKOPS_LEVEL_2) {
 		timeout = MMC_OPS_TIMEOUT_MS;
 		use_busy_signal = true;
@@ -995,7 +994,7 @@ void mmc_start_bkops(struct mmc_card *card, bool from_exception)
 		pr_warn("%s: Error %d starting bkops\n",
 			mmc_hostname(card->host), err);
 		mmc_retune_release(card->host);
-		goto out;
+		return;
 	}
 
 	/*
@@ -1007,8 +1006,6 @@ void mmc_start_bkops(struct mmc_card *card, bool from_exception)
 		mmc_card_set_doing_bkops(card);
 	else
 		mmc_retune_release(card->host);
-out:
-	mmc_release_host(card->host);
 }
 
 /*
Signature · 1 line
1.9.1
author maintainer
#15 lore raw

PATCH v8 10/14 mmc: core: Export mmc_start_bkops()

In reply to Adrian Hunter

Export mmc_start_bkops() so that the block driver can use it.

---
 drivers/mmc/core/mmc_ops.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mmc/core/mmc_ops.c +1 -0
index a6b0a232f24a..908e4db03535 100644
@@ -1007,6 +1007,7 @@ void mmc_start_bkops(struct mmc_card *card, bool from_exception)
 	else
 		mmc_retune_release(card->host);
 }
+EXPORT_SYMBOL(mmc_start_bkops);
 
 /*
  * Flush the cache to the non-volatile storage.
Signature · 1 line
1.9.1
author maintainer
#16 lore raw

PATCH v8 11/14 mmc: core: Export mmc_start_request()

In reply to Adrian Hunter

Export mmc_start_request() so that the block driver can use it.

---
 drivers/mmc/core/core.c | 3 ++-
 drivers/mmc/core/core.h | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/mmc/core/core.c +2 -1
index 3638ed4f0f9e..24a73f387482 100644
@@ -344,7 +344,7 @@ static int mmc_mrq_prep(struct mmc_host *host, struct mmc_request *mrq)
 	return 0;
 }
 
-static int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
+int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
 {
 	int err;
 
@@ -366,6 +366,7 @@ static int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
 
 	return 0;
 }
+EXPORT_SYMBOL(mmc_start_request);
 
 /*
  * mmc_wait_data_done() - done callback for data request
drivers/mmc/core/core.h +2 -0
index 535539a9e7eb..03e0f8384b1c 100644
@@ -109,6 +109,8 @@ 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);
 
+int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq);
+
 struct mmc_async_req;
 
 struct mmc_async_req *mmc_start_areq(struct mmc_host *host,
Signature · 1 line
1.9.1
author maintainer
#17 lore raw

PATCH v8 12/14 mmc: block: Add CQE and blk-mq 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.

For host controllers without CQE support, blk-mq support is extended to synchronous reads/writes or, if the host supports CAP_WAIT_WHILE_BUSY, asynchonous reads/writes. The advantage of asynchronous reads/writes is that it allows the preparation of the next request while the current request is in progress.

---
 drivers/mmc/core/block.c | 734 ++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/mmc/core/block.h |   8 +
 drivers/mmc/core/queue.c | 428 +++++++++++++++++++++++++--
 drivers/mmc/core/queue.h |  54 +++-
 4 files changed, 1192 insertions(+), 32 deletions(-)
drivers/mmc/core/block.c +727 -7
index 2424c7360687..eca81502d09f 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
@@ -1266,7 +1267,10 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
 	else
 		mmc_blk_reset_success(md, type);
 fail:
-	blk_end_request(req, status, blk_rq_bytes(req));
+	if (req->mq_ctx)
+		blk_mq_end_request(req, status);
+	else
+		blk_end_request(req, status, blk_rq_bytes(req));
 }
 
 static void mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
@@ -1336,7 +1340,10 @@ static void mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
 	if (!err)
 		mmc_blk_reset_success(md, type);
 out:
-	blk_end_request(req, status, blk_rq_bytes(req));
+	if (req->mq_ctx)
+		blk_mq_end_request(req, status);
+	else
+		blk_end_request(req, status, blk_rq_bytes(req));
 }
 
 static void mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req)
@@ -1346,7 +1353,10 @@ static void mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req)
 	int ret = 0;
 
 	ret = mmc_flush_cache(card);
-	blk_end_request_all(req, ret ? BLK_STS_IOERR : BLK_STS_OK);
+	if (req->mq_ctx)
+		blk_mq_end_request(req, ret ? BLK_STS_IOERR : BLK_STS_OK);
+	else
+		blk_end_request_all(req, ret ? BLK_STS_IOERR : BLK_STS_OK);
 }
 
 /*
@@ -1372,15 +1382,18 @@ static inline void mmc_apply_rel_rw(struct mmc_blk_request *brq,
 	}
 }
 
-#define CMD_ERRORS							\
-	(R1_OUT_OF_RANGE |	/* Command argument out of range */	\
-	 R1_ADDRESS_ERROR |	/* Misaligned address */		\
+#define CMD_ERRORS_EXCL_OOR						\
+	(R1_ADDRESS_ERROR |	/* Misaligned address */		\
 	 R1_BLOCK_LEN_ERROR |	/* Transferred block length incorrect */\
 	 R1_WP_VIOLATION |	/* Tried to write to protected block */	\
 	 R1_CARD_ECC_FAILED |	/* Card ECC failed */			\
 	 R1_CC_ERROR |		/* Card controller error */		\
 	 R1_ERROR)		/* General/unknown error */
 
+#define CMD_ERRORS							\
+	(CMD_ERRORS_EXCL_OOR |						\
+	 R1_OUT_OF_RANGE)	/* Command argument out of range */	\
+
 static void mmc_blk_eval_resp_error(struct mmc_blk_request *brq)
 {
 	u32 val;
@@ -1659,6 +1672,138 @@ 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
+
+static void mmc_blk_cqe_complete_rq(struct mmc_queue *mq, 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_host *host = mq->card->host;
+	unsigned long flags;
+	bool put_card;
+	int err;
+
+	mmc_cqe_post_req(host, mrq);
+
+	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_mq_requeue_request(req, true);
+		else
+			blk_mq_end_request(req, BLK_STS_IOERR);
+	} else if (mrq->data) {
+		if (blk_update_request(req, BLK_STS_OK, mrq->data->bytes_xfered))
+			blk_mq_requeue_request(req, true);
+		else
+			__blk_mq_end_request(req, BLK_STS_OK);
+	} else {
+		blk_mq_end_request(req, BLK_STS_OK);
+	}
+
+	spin_lock_irqsave(q->queue_lock, flags);
+
+	mq->in_flight[mmc_issue_type(mq, req)] -= 1;
+
+	put_card = mmc_tot_in_flight(mq) == 0;
+
+	mmc_cqe_check_busy(mq);
+
+	spin_unlock_irqrestore(q->queue_lock, flags);
+
+	if (!mq->cqe_busy)
+		blk_mq_run_hw_queues(q, true);
+
+	if (put_card)
+		mmc_ctx_put_card(mq->card, &mq->ctx);
+}
+
+void mmc_blk_cqe_recovery(struct mmc_queue *mq)
+{
+	struct mmc_card *card = mq->card;
+	struct mmc_host *host = card->host;
+	int err;
+
+	pr_debug("%s: CQE recovery start\n", mmc_hostname(host));
+
+	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);
+
+	pr_debug("%s: CQE recovery done\n", mmc_hostname(host));
+}
+
+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->in_recovery)
+		mmc_blk_cqe_complete_rq(mq, req);
+	else
+		blk_mq_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);
+}
+
 static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
 			       struct mmc_card *card,
 			       int disable_multi,
@@ -1727,6 +1872,581 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
 	mqrq->areq.err_check = mmc_blk_err_check;
 }
 
+#define MMC_MAX_RETRIES		5
+#define MMC_DATA_RETRIES	2
+#define MMC_NO_RETRIES		(MMC_MAX_RETRIES + 1)
+
+/* Single sector read during recovery */
+static void mmc_blk_ss_read(struct mmc_queue *mq, struct request *req)
+{
+	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
+	blk_status_t status;
+
+	while (1) {
+		mmc_blk_rw_rq_prep(mqrq, mq->card, 1, mq);
+
+		mmc_wait_for_req(mq->card->host, &mqrq->brq.mrq);
+
+		/*
+		 * Not expecting command errors, so just give up in that case.
+		 * If there are retries remaining, the request will get
+		 * requeued.
+		 */
+		if (mqrq->brq.cmd.error)
+			return;
+
+		if (blk_rq_bytes(req) <= 512)
+			break;
+
+		status = mqrq->brq.data.error ? BLK_STS_IOERR : BLK_STS_OK;
+
+		blk_update_request(req, status, 512);
+	}
+
+	mqrq->retries = MMC_NO_RETRIES;
+}
+
+static inline bool mmc_blk_oor_valid(struct mmc_blk_request *brq)
+{
+	return !!brq->mrq.sbc;
+}
+
+static inline u32 mmc_blk_stop_err_bits(struct mmc_blk_request *brq)
+{
+	return mmc_blk_oor_valid(brq) ? CMD_ERRORS : CMD_ERRORS_EXCL_OOR;
+}
+
+static inline bool mmc_blk_in_tran_state(u32 status)
+{
+	/*
+	 * Some cards mishandle the status bits, so make sure to check both the
+	 * busy indication and the card state.
+	 */
+	return status & R1_READY_FOR_DATA &&
+	       (R1_CURRENT_STATE(status) == R1_STATE_TRAN);
+}
+
+/*
+ * Check for errors the host controller driver might not have seen such as
+ * response mode errors or invalid card state.
+ */
+static bool mmc_blk_status_error(struct request *req, u32 status)
+{
+	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
+	struct mmc_blk_request *brq = &mqrq->brq;
+	u32 stop_err_bits = mmc_blk_stop_err_bits(brq);
+
+	return brq->cmd.resp[0]  & CMD_ERRORS    ||
+	       brq->stop.resp[0] & stop_err_bits ||
+	       status            & stop_err_bits ||
+	       (rq_data_dir(req) == WRITE && !mmc_blk_in_tran_state(status));
+}
+
+static inline bool mmc_blk_cmd_started(struct mmc_blk_request *brq)
+{
+	return !brq->sbc.error && !brq->cmd.error &&
+	       !(brq->cmd.resp[0] & CMD_ERRORS);
+}
+
+static unsigned int mmc_blk_clock_khz(struct mmc_host *host)
+{
+	if (host->actual_clock)
+		return host->actual_clock / 1000;
+
+	/* Clock may be subject to a divisor, fudge it by a factor of 2. */
+	if (host->ios.clock)
+		return host->ios.clock / 2000;
+
+	/* How can there be no clock */
+	WARN_ON_ONCE(1);
+	return 100; /* 100 kHz is minimum possible value */
+}
+
+static unsigned long mmc_blk_data_timeout_jiffies(struct mmc_host *host,
+						  struct mmc_data *data)
+{
+	unsigned int ms = DIV_ROUND_UP(data->timeout_ns, 1000000);
+	unsigned int khz;
+
+	if (data->timeout_clks) {
+		khz = mmc_blk_clock_khz(host);
+		ms += DIV_ROUND_UP(data->timeout_clks, khz);
+	}
+
+	return msecs_to_jiffies(ms);
+}
+
+static int mmc_blk_card_stuck(struct mmc_card *card, struct request *req,
+			      u32 *resp_errs)
+{
+	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
+	struct mmc_data *data = &mqrq->brq.data;
+	unsigned long timeout;
+	u32 status;
+	int err;
+
+	timeout = jiffies + mmc_blk_data_timeout_jiffies(card->host, data);
+
+	while (1) {
+		bool done = time_after(jiffies, timeout);
+
+		err = __mmc_send_status(card, &status, 5);
+		if (err) {
+			pr_err("%s: error %d requesting status\n",
+			       req->rq_disk->disk_name, err);
+			break;
+		}
+
+		/* Accumulate any response error bits seen */
+		if (resp_errs)
+			*resp_errs |= status;
+
+		if (mmc_blk_in_tran_state(status))
+			break;
+
+		/* Timeout if the device never becomes ready */
+		if (done) {
+			pr_err("%s: Card stuck in wrong state! %s %s\n",
+				mmc_hostname(card->host),
+				req->rq_disk->disk_name, __func__);
+			err = -ETIMEDOUT;
+			break;
+		}
+	}
+
+	return err;
+}
+
+static int mmc_blk_send_stop(struct mmc_card *card)
+{
+	struct mmc_command cmd = {
+		.opcode = MMC_STOP_TRANSMISSION,
+		.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC,
+	};
+
+	return mmc_wait_for_cmd(card->host, &cmd, 5);
+}
+
+static int mmc_blk_fix_state(struct mmc_card *card, struct request *req)
+{
+	int err;
+
+	mmc_retune_hold_now(card->host);
+
+	mmc_blk_send_stop(card);
+
+	err = mmc_blk_card_stuck(card, req, NULL);
+
+	mmc_retune_release(card->host);
+
+	return err;
+}
+
+static void mmc_blk_rw_recovery(struct mmc_queue *mq, struct request *req)
+{
+	int type = rq_data_dir(req) == READ ? MMC_BLK_READ : MMC_BLK_WRITE;
+	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
+	struct mmc_blk_request *brq = &mqrq->brq;
+	struct mmc_blk_data *md = mq->blkdata;
+	struct mmc_card *card = mq->card;
+	u32 status;
+	u32 blocks;
+	int err;
+
+	/*
+	 * Status error bits might get lost during re-tuning so don't allow
+	 * re-tuning yet.
+	 */
+	mmc_retune_hold_now(card->host);
+
+	/*
+	 * Some errors the host driver might not have seen. Set the number of
+	 * bytes transferred to zero in that case.
+	 */
+	err = __mmc_send_status(card, &status, 0);
+	if (err || mmc_blk_status_error(req, status))
+		brq->data.bytes_xfered = 0;
+
+	mmc_retune_release(card->host);
+
+	/*
+	 * Try again to get the status. This also provides an opportunity for
+	 * re-tuning.
+	 */
+	if (err)
+		err = __mmc_send_status(card, &status, 0);
+
+	/*
+	 * Nothing more to do after the number of bytes transferred has been
+	 * updated and there is no card.
+	 */
+	if (err && mmc_detect_card_removed(card->host))
+		return;
+
+	/* Try to get back to "tran" state */
+	if (err || !mmc_blk_in_tran_state(status))
+		err = mmc_blk_fix_state(mq->card, req);
+
+	/*
+	 * Special case for SD cards where the card might record the number of
+	 * blocks written.
+	 */
+	if (!err && mmc_blk_cmd_started(brq) && mmc_card_sd(card) &&
+	    rq_data_dir(req) == WRITE && !mmc_sd_num_wr_blocks(card, &blocks))
+		brq->data.bytes_xfered = blocks << 9;
+
+	/* Reset if the card is in a bad state */
+	if (err && mmc_blk_reset(md, card->host, type)) {
+		pr_err("%s: recovery failed!\n", req->rq_disk->disk_name);
+		mqrq->retries = MMC_NO_RETRIES;
+		return;
+	}
+
+	/*
+	 * If anything was done, just return and if there is anything remaining
+	 * on the request it will get requeued.
+	 */
+	if (brq->data.bytes_xfered)
+		return;
+
+	/* Reset before last retry */
+	if (mqrq->retries + 1 == MMC_MAX_RETRIES)
+		mmc_blk_reset(md, card->host, type);
+
+	/* Command errors fail fast, so use all MMC_MAX_RETRIES */
+	if (brq->sbc.error || brq->cmd.error)
+		return;
+
+	/* Reduce the remaining retries for data errors */
+	if (mqrq->retries < MMC_MAX_RETRIES - MMC_DATA_RETRIES) {
+		mqrq->retries = MMC_MAX_RETRIES - MMC_DATA_RETRIES;
+		return;
+	}
+
+	/* FIXME: Missing single sector read for large sector size */
+	if (rq_data_dir(req) == READ && !mmc_large_sector(card)) {
+		/* Read one sector at a time */
+		mmc_blk_ss_read(mq, req);
+		return;
+	}
+}
+
+static inline bool mmc_blk_rq_error(struct mmc_blk_request *brq)
+{
+	mmc_blk_eval_resp_error(brq);
+
+	return brq->sbc.error || brq->cmd.error || brq->stop.error ||
+	       brq->data.error || brq->cmd.resp[0] & CMD_ERRORS;
+}
+
+static int mmc_blk_card_busy(struct mmc_card *card, struct request *req)
+{
+	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
+	u32 status = 0;
+	int err;
+
+	if (mmc_host_is_spi(card->host) || rq_data_dir(req) == READ)
+		return 0;
+
+	mmc_retune_hold_now(card->host);
+
+	err = mmc_blk_card_stuck(card, req, &status);
+
+	mmc_retune_release(card->host);
+
+	/*
+	 * Do not assume data transferred correctly if there are any error bits
+	 * set.
+	 */
+	if (!err && status & mmc_blk_stop_err_bits(&mqrq->brq)) {
+		mqrq->brq.data.bytes_xfered = 0;
+		err = -EIO;
+	}
+
+	/* Copy the exception bit so it will be seen later on */
+	if (mmc_card_mmc(card) && status & R1_EXCEPTION_EVENT)
+		mqrq->brq.cmd.resp[0] |= R1_EXCEPTION_EVENT;
+
+	return err;
+}
+
+static inline void mmc_blk_rw_reset_success(struct mmc_queue *mq,
+					    struct request *req)
+{
+	int type = rq_data_dir(req) == READ ? MMC_BLK_READ : MMC_BLK_WRITE;
+
+	mmc_blk_reset_success(mq->blkdata, type);
+}
+
+static void mmc_blk_mq_complete_rq(struct mmc_queue *mq, struct request *req)
+{
+	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
+	unsigned int nr_bytes = mqrq->brq.data.bytes_xfered;
+
+	if (nr_bytes) {
+		if (blk_update_request(req, BLK_STS_OK, nr_bytes))
+			blk_mq_requeue_request(req, true);
+		else
+			__blk_mq_end_request(req, BLK_STS_OK);
+	} else if (mqrq->retries++ < MMC_MAX_RETRIES) {
+		blk_mq_requeue_request(req, true);
+	} else {
+		if (mmc_card_removed(mq->card))
+			req->rq_flags |= RQF_QUIET;
+		blk_mq_end_request(req, BLK_STS_IOERR);
+	}
+}
+
+static bool mmc_blk_urgent_bkops_needed(struct mmc_queue *mq,
+					struct mmc_queue_req *mqrq)
+{
+	return mmc_card_mmc(mq->card) &&
+	       (mqrq->brq.cmd.resp[0] & R1_EXCEPTION_EVENT ||
+		mqrq->brq.stop.resp[0] & R1_EXCEPTION_EVENT);
+}
+
+static void mmc_blk_urgent_bkops(struct mmc_queue *mq,
+				 struct mmc_queue_req *mqrq)
+{
+	if (mmc_blk_urgent_bkops_needed(mq, mqrq))
+		mmc_start_bkops(mq->card, true);
+}
+
+static int mmc_blk_card_busy_check(struct mmc_queue *mq, struct request *req)
+{
+	if (mmc_queue_rw_async(mq->card->host))
+		return 0;
+
+	return mmc_blk_card_busy(mq->card, req);
+}
+
+void mmc_blk_mq_complete(struct request *req)
+{
+	struct mmc_queue *mq = req->q->queuedata;
+
+	if (mq->use_cqe)
+		mmc_blk_cqe_complete_rq(mq, req);
+	else
+		mmc_blk_mq_complete_rq(mq, req);
+}
+
+static void mmc_blk_finish_rw_rq_blocking(struct mmc_queue *mq,
+					  struct request *req)
+{
+	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
+
+	if (mmc_blk_rq_error(&mqrq->brq) || mmc_blk_card_busy_check(mq, req))
+		mmc_blk_rw_recovery(mq, req);
+	else
+		mmc_blk_rw_reset_success(mq, req);
+
+	mmc_blk_urgent_bkops(mq, mqrq);
+
+	mq->rw_wait = false;
+
+	/*
+	 * Block layer timeouts race with completions which means the normal
+	 * completion path cannot be used during recovery.
+	 */
+	if (mq->in_recovery)
+		mmc_blk_mq_complete_rq(mq, req);
+	else
+		blk_mq_complete_request(req);
+}
+
+void mmc_blk_mq_recovery(struct mmc_queue *mq)
+{
+	struct request *req = mq->recovery_req;
+
+	mq->recovery_req = NULL;
+
+	mmc_blk_finish_rw_rq_blocking(mq, req);
+}
+
+static void mmc_blk_issue_rw_rq_blocking(struct mmc_queue *mq,
+					 struct request *req)
+{
+	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
+
+	mmc_blk_rw_rq_prep(mqrq, mq->card, 0, mq);
+
+	mmc_wait_for_req(mq->card->host, &mqrq->brq.mrq);
+
+	mmc_blk_finish_rw_rq_blocking(mq, req);
+}
+
+static void mmc_blk_mq_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;
+	struct mmc_host *host = mq->card->host;
+	unsigned long flags;
+	bool put_card;
+
+	if (mmc_blk_rq_error(&mqrq->brq) ||
+	    mmc_blk_urgent_bkops_needed(mq, mqrq)) {
+		mq->recovery_needed = true;
+		mq->recovery_req = req;
+		wake_up(&mq->wait);
+		schedule_work(&mq->recovery_work);
+		return;
+	}
+
+	mmc_blk_rw_reset_success(mq, req);
+
+	if (host->ops->post_req)
+		host->ops->post_req(host, mrq, 0);
+
+	mq->rw_wait = false;
+	wake_up(&mq->wait);
+
+	blk_mq_complete_request(req);
+
+	spin_lock_irqsave(q->queue_lock, flags);
+
+	mq->in_flight[mmc_issue_type(mq, req)] -= 1;
+
+	put_card = mmc_tot_in_flight(mq) == 0;
+
+	spin_unlock_irqrestore(q->queue_lock, flags);
+
+	if (put_card)
+		mmc_ctx_put_card(mq->card, &mq->ctx);
+}
+
+static bool mmc_blk_rw_wait_cond(struct mmc_queue *mq, int *err)
+{
+	if (mq->recovery_needed) {
+		*err = -EBUSY;
+		return true;
+	}
+
+	return !mq->rw_wait;
+}
+
+static int mmc_blk_rw_wait(struct mmc_queue *mq)
+{
+	int err = 0;
+
+	wait_event(mq->wait, mmc_blk_rw_wait_cond(mq, &err));
+
+	return err;
+}
+
+static int mmc_blk_mq_issue_rw_rq(struct mmc_queue *mq,
+				  struct request *req)
+{
+	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
+	struct mmc_host *host = mq->card->host;
+	int err = 0;
+
+	mmc_blk_rw_rq_prep(mqrq, mq->card, 0, mq);
+
+	mqrq->brq.mrq.done = mmc_blk_mq_req_done;
+
+	if (host->ops->pre_req)
+		host->ops->pre_req(host, &mqrq->brq.mrq);
+
+	err = mmc_blk_rw_wait(mq);
+	if (err)
+		goto out_post_req;
+
+	mq->rw_wait = true;
+
+	err = mmc_start_request(host, &mqrq->brq.mrq);
+
+	if (err)
+		mq->rw_wait = false;
+
+	/* Release re-tuning here where there is no synchronization required */
+	mmc_retune_release(host);
+
+out_post_req:
+	if (err && host->ops->post_req)
+		host->ops->post_req(host, &mqrq->brq.mrq, err);
+
+	return err;
+}
+
+static int mmc_blk_wait_for_idle(struct mmc_queue *mq, struct mmc_host *host)
+{
+	if (mq->use_cqe)
+		return host->cqe_ops->cqe_wait_for_idle(host);
+
+	if (mmc_queue_rw_async(host))
+		return mmc_blk_rw_wait(mq);
+
+	return 0;
+}
+
+enum mmc_issued mmc_blk_mq_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_issue_type(mq, req)) {
+	case MMC_ISSUE_SYNC:
+		ret = mmc_blk_wait_for_idle(mq, 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;
+		case REQ_OP_READ:
+		case REQ_OP_WRITE:
+			mmc_blk_issue_rw_rq_blocking(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:
+			if (mq->use_cqe)
+				ret = mmc_blk_cqe_issue_rw_rq(mq, req);
+			else
+				ret = mmc_blk_mq_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 bool mmc_blk_rw_cmd_err(struct mmc_blk_data *md, struct mmc_card *card,
 			       struct mmc_blk_request *brq, struct request *req,
 			       bool old_req_pending)
@@ -2094,7 +2814,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 +8 -0
index 860ca7c8df86..742aa4d27cbf 100644
@@ -6,4 +6,12 @@
 
 void mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req);
 
+enum mmc_issued;
+
+void mmc_blk_cqe_recovery(struct mmc_queue *mq);
+
+enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req);
+void mmc_blk_mq_complete(struct request *req);
+void mmc_blk_mq_recovery(struct mmc_queue *mq);
+
 #endif
drivers/mmc/core/queue.c +404 -24

507 lines not on this page · raw message

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

85 lines not on this page · raw message

Signature · 1 line
1.9.1
#18 lore raw

Re: [PATCH V8 12/14] mmc: block: Add CQE and blk-mq support

Quoted 26 lines · 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.

For host controllers without CQE support, blk-mq support is extended to synchronous reads/writes or, if the host supports CAP_WAIT_WHILE_BUSY, asynchonous reads/writes. The advantage of asynchronous reads/writes is that it allows the preparation of the next request while the current request is in progress.

Quoted 7 lines
---
 drivers/mmc/core/block.c | 734 ++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/mmc/core/block.h |   8 +
 drivers/mmc/core/queue.c | 428 +++++++++++++++++++++++++--
 drivers/mmc/core/queue.h |  54 +++-
 4 files changed, 1192 insertions(+), 32 deletions(-)

Adrian, this is just too hard for me to review. Please, can you split this up?

At least enabling mq support should be done in a separate and first step, then you could add the CQE bits on top.

I think that is important, because we want to make sure the mq deployment is done correctly first. Otherwise it becomes impossible to narrow down problems, because those could then be either CQE related or mq related.

[....]

Kind regards
Uffe

author maintainer
#19 lore raw

Re: [PATCH V8 12/14] mmc: block: Add CQE and blk-mq support

Quoted 37 lines · Ulf Hansson
Quoted 26 lines · 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.

For host controllers without CQE support, blk-mq support is extended to synchronous reads/writes or, if the host supports CAP_WAIT_WHILE_BUSY, asynchonous reads/writes. The advantage of asynchronous reads/writes is that it allows the preparation of the next request while the current request is in progress.

Quoted 7 lines
---
 drivers/mmc/core/block.c | 734 ++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/mmc/core/block.h |   8 +
 drivers/mmc/core/queue.c | 428 +++++++++++++++++++++++++--
 drivers/mmc/core/queue.h |  54 +++-
 4 files changed, 1192 insertions(+), 32 deletions(-)

Adrian, this is just too hard for me to review. Please, can you split this up?

Quoted 7 lines

At least enabling mq support should be done in a separate and first step, then you could add the CQE bits on top.

I think that is important, because we want to make sure the mq deployment is done correctly first. Otherwise it becomes impossible to narrow down problems, because those could then be either CQE related or mq related.

I looked at splitting it up, but it makes more sense together. Things are the way they are to support all the different issue types. It reads much better together. The CQE functions are named appropriately and practically all the code is new, so it is not as though there are any intermediate steps.

author maintainer
#20 lore raw

PATCH v8 13/14 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 8c15637178ff..6db8e46b4e12 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 303f5cd46cd9..4cec2a985a04 100644
@@ -89,6 +89,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
#21 lore raw

PATCH v8 14/14 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 6db8e46b4e12..23621c52d2f8 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
#22 lore raw

PATCH v9 14/14 mmc: sdhci-pci: Add CQHCI support for Intel GLK

Add CQHCI initialization and implement CQHCI operations for Intel GLK.

---

Changes since V8:

Re-base on top of patch "mmc: sdhci-pci: Fix voltage switch for some Intel host controllers"

 drivers/mmc/host/Kconfig          |   1 +
 drivers/mmc/host/sdhci-pci-core.c | 155 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 155 insertions(+), 1 deletion(-)
drivers/mmc/host/Kconfig +1 -0
index 6db8e46b4e12..23621c52d2f8 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 +154 -1

203 lines not on this page · raw message

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

Hi

Here is V8 of the hardware command queue patches without the software command queue patches, now using blk-mq and now with blk-mq support for non-CQE I/O.

After the unacceptable debacle of the last release cycle, I expect an immediate response to these patches.

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.

Non-CQE blk-mq showed a 3% decrease in sequential read performance. This seemed to be coming from the inferior latency of running work items compared with a dedicated thread. Hacking blk-mq workqueue to be unbound reduced the performance degradation from 3% to 1%.

Quoted 4 lines

While we should look at changing blk-mq to give better workqueue performance, a bigger gain is likely to be made by adding a new host API to enable the next already-prepared request to be issued directly from within ->done() callback of the current request.

Adrian, I am reviewing this series, however let me comment on each change individually.

I have also run some test on my ux500 board and enabling the blkmq path via the new MMC Kconfig option. My idea was to run some iozone comparisons between the legacy path and the new blkmq path, but I just couldn't get to that point because of the following errors.

I am using a Kingston 4GB SDHC card, which is detected and mounted nicely. However, when I decide to do some writes to the card I get the following errors.

root@ME:/mnt/sdcard dd if=/dev/zero of=testfile bs=8192 count=5000 conv=fsync

[  463.714294] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  464.722656] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  466.081481] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  467.111236] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  468.669647] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  469.685699] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  471.043334] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  472.052337] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  473.342651] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  474.323760] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  475.544769] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  476.539031] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  477.748474] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  478.724182] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!

I haven't yet got the point of investigating this any further, and unfortunate I have a busy schedule with traveling next week. I will do my best to look into this as soon as I can.

Perhaps you have some ideas?

Kind regards
Uffe

Quoted 153 lines

Changes since V7:
Re-based
mmc: core: Introduce host claiming by context
Slightly simplified
mmc: core: Add parameter use_blk_mq
New patch.
mmc: core: Remove unnecessary host claim
New patch.
mmc: core: Export mmc_start_bkops()
New patch.
mmc: core: Export mmc_start_request()
New patch.
mmc: block: Add CQE and blk-mq support
Add blk-mq support for non_CQE requests

Changes since V6:
mmc: core: Introduce host claiming by context
New patch.
mmc: core: Move mmc_start_areq() declaration
Dropped because it has been applied
mmc: block: Fix block status codes
Dropped because it has been applied
mmc: host: Add CQE interface
Dropped because it has been applied
mmc: core: Turn off CQE before sending commands
Dropped because it has been applied
mmc: block: Factor out mmc_setup_queue()
New patch.
mmc: block: Add CQE support
Drop legacy support and add blk-mq support

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 (13):
mmc: core: Introduce host claiming by context
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: Factor out mmc_setup_queue()
mmc: core: Add parameter use_blk_mq
mmc: core: Remove unnecessary host claim
mmc: core: Export mmc_start_bkops()
mmc: core: Export mmc_start_request()
mmc: block: Add CQE and blk-mq support
mmc: sdhci-pci: Add CQHCI support for Intel GLK

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

 drivers/mmc/Kconfig               |   11 +
 drivers/mmc/core/block.c          |  777 ++++++++++++++++++++++++-
 drivers/mmc/core/block.h          |    8 +
 drivers/mmc/core/bus.c            |    7 +
 drivers/mmc/core/core.c           |  265 ++++++++-
 drivers/mmc/core/core.h           |   14 +
 drivers/mmc/core/host.c           |    2 +
 drivers/mmc/core/host.h           |    4 +
 drivers/mmc/core/mmc.c            |   29 +
 drivers/mmc/core/mmc_ops.c        |    6 +-
 drivers/mmc/core/queue.c          |  479 +++++++++++++--
 drivers/mmc/core/queue.h          |   54 +-
 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/host.h          |   10 +-
 18 files changed, 3146 insertions(+), 83 deletions(-)
 create mode 100644 drivers/mmc/host/cqhci.c
 create mode 100644 drivers/mmc/host/cqhci.h

Regards
Adrian

author maintainer
#24 lore raw
Quoted 51 lines · Ulf Hansson
Quoted 17 lines · Adrian Hunter

Hi

Here is V8 of the hardware command queue patches without the software command queue patches, now using blk-mq and now with blk-mq support for non-CQE I/O.

After the unacceptable debacle of the last release cycle, I expect an immediate response to these patches.

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.

Non-CQE blk-mq showed a 3% decrease in sequential read performance. This seemed to be coming from the inferior latency of running work items compared with a dedicated thread. Hacking blk-mq workqueue to be unbound reduced the performance degradation from 3% to 1%.

Quoted 4 lines

While we should look at changing blk-mq to give better workqueue performance, a bigger gain is likely to be made by adding a new host API to enable the next already-prepared request to be issued directly from within ->done() callback of the current request.

Adrian, I am reviewing this series, however let me comment on each change individually.

I have also run some test on my ux500 board and enabling the blkmq path via the new MMC Kconfig option. My idea was to run some iozone comparisons between the legacy path and the new blkmq path, but I just couldn't get to that point because of the following errors.

I am using a Kingston 4GB SDHC card, which is detected and mounted nicely. However, when I decide to do some writes to the card I get the following errors.

root@ME:/mnt/sdcard dd if=/dev/zero of=testfile bs=8192 count=5000 conv=fsync

[  463.714294] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  464.722656] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  466.081481] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  467.111236] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  468.669647] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  469.685699] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  471.043334] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  472.052337] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  473.342651] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  474.323760] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  475.544769] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  476.539031] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  477.748474] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  478.724182] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
Quoted 5 lines

I haven't yet got the point of investigating this any further, and unfortunate I have a busy schedule with traveling next week. I will do my best to look into this as soon as I can.

Perhaps you have some ideas?

The behaviour depends on whether you have MMC_CAP_WAIT_WHILE_BUSY. Try changing that and see if it makes a difference.

#25 lore raw
Quoted 52 lines · Adrian Hunter
Quoted 51 lines · Ulf Hansson
Quoted 17 lines · Adrian Hunter

Hi

Here is V8 of the hardware command queue patches without the software command queue patches, now using blk-mq and now with blk-mq support for non-CQE I/O.

After the unacceptable debacle of the last release cycle, I expect an immediate response to these patches.

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.

Non-CQE blk-mq showed a 3% decrease in sequential read performance. This seemed to be coming from the inferior latency of running work items compared with a dedicated thread. Hacking blk-mq workqueue to be unbound reduced the performance degradation from 3% to 1%.

Quoted 4 lines

While we should look at changing blk-mq to give better workqueue performance, a bigger gain is likely to be made by adding a new host API to enable the next already-prepared request to be issued directly from within ->done() callback of the current request.

Adrian, I am reviewing this series, however let me comment on each change individually.

I have also run some test on my ux500 board and enabling the blkmq path via the new MMC Kconfig option. My idea was to run some iozone comparisons between the legacy path and the new blkmq path, but I just couldn't get to that point because of the following errors.

I am using a Kingston 4GB SDHC card, which is detected and mounted nicely. However, when I decide to do some writes to the card I get the following errors.

root@ME:/mnt/sdcard dd if=/dev/zero of=testfile bs=8192 count=5000 conv=fsync

[  463.714294] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  464.722656] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  466.081481] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  467.111236] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  468.669647] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  469.685699] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  471.043334] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  472.052337] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  473.342651] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  474.323760] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  475.544769] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  476.539031] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  477.748474] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  478.724182] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
Quoted 8 lines
Quoted 5 lines

I haven't yet got the point of investigating this any further, and unfortunate I have a busy schedule with traveling next week. I will do my best to look into this as soon as I can.

Perhaps you have some ideas?

The behaviour depends on whether you have MMC_CAP_WAIT_WHILE_BUSY. Try changing that and see if it makes a difference.

Yes, it does! I disabled MMC_CAP_WAIT_WHILE_BUSY (and its corresponding code in mmci.c) and the errors goes away.

When I use MMC_CAP_WAIT_WHILE_BUSY I get these problems:

[  223.820983] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  224.815795] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  226.034881] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.112884] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.220275] mmc0: Card stuck in wrong state! mmcblk0 mmc_blk_card_stuck
[  228.686798] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  229.892150] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  231.031890] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  232.239013] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!

5000+0 records in
5000+0 records out
root@ME:/mnt/sdcard

I looked at the new blkmq code from patch v10 13/15. It seems like the MMC_CAP_WAIT_WHILE_BUSY is used to determine whether the async request mechanism should be used or not. Perhaps I didn't looked close enough, but maybe you could elaborate on why this seems to be the case!?

Kind regards
Uffe

author maintainer
#26 lore raw
Quoted 76 lines · Ulf Hansson
Quoted 52 lines · Adrian Hunter
Quoted 51 lines · Ulf Hansson
Quoted 17 lines · Adrian Hunter

Hi

Here is V8 of the hardware command queue patches without the software command queue patches, now using blk-mq and now with blk-mq support for non-CQE I/O.

After the unacceptable debacle of the last release cycle, I expect an immediate response to these patches.

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.

Non-CQE blk-mq showed a 3% decrease in sequential read performance. This seemed to be coming from the inferior latency of running work items compared with a dedicated thread. Hacking blk-mq workqueue to be unbound reduced the performance degradation from 3% to 1%.

Quoted 4 lines

While we should look at changing blk-mq to give better workqueue performance, a bigger gain is likely to be made by adding a new host API to enable the next already-prepared request to be issued directly from within ->done() callback of the current request.

Adrian, I am reviewing this series, however let me comment on each change individually.

I have also run some test on my ux500 board and enabling the blkmq path via the new MMC Kconfig option. My idea was to run some iozone comparisons between the legacy path and the new blkmq path, but I just couldn't get to that point because of the following errors.

I am using a Kingston 4GB SDHC card, which is detected and mounted nicely. However, when I decide to do some writes to the card I get the following errors.

root@ME:/mnt/sdcard dd if=/dev/zero of=testfile bs=8192 count=5000 conv=fsync

[  463.714294] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  464.722656] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  466.081481] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  467.111236] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  468.669647] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  469.685699] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  471.043334] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  472.052337] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  473.342651] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  474.323760] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  475.544769] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  476.539031] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  477.748474] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  478.724182] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
Quoted 8 lines
Quoted 5 lines

I haven't yet got the point of investigating this any further, and unfortunate I have a busy schedule with traveling next week. I will do my best to look into this as soon as I can.

Perhaps you have some ideas?

The behaviour depends on whether you have MMC_CAP_WAIT_WHILE_BUSY. Try changing that and see if it makes a difference.

Yes, it does! I disabled MMC_CAP_WAIT_WHILE_BUSY (and its corresponding code in mmci.c) and the errors goes away.

When I use MMC_CAP_WAIT_WHILE_BUSY I get these problems:

[  223.820983] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  224.815795] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  226.034881] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.112884] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.220275] mmc0: Card stuck in wrong state! mmcblk0 mmc_blk_card_stuck
[  228.686798] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  229.892150] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  231.031890] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  232.239013] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
Quoted 8 lines

5000+0 records in
5000+0 records out
root@ME:/mnt/sdcard

I looked at the new blkmq code from patch v10 13/15. It seems like the MMC_CAP_WAIT_WHILE_BUSY is used to determine whether the async request mechanism should be used or not. Perhaps I didn't looked close enough, but maybe you could elaborate on why this seems to be the case!?

MMC_CAP_WAIT_WHILE_BUSY is necessary because it means that a data transfer request has finished when the host controller calls mmc_request_done(). i.e. polling the card is not necessary.

Have you tried V9 or V10. There was a fix in V9 related to calling ->post_req() which could mess up DMA.

The other thing that could go wrong with DMA is if it cannot accept ->post_req() being called from mmc_request_done().

#27 lore raw

[...]

Quoted 53 lines
Quoted 53 lines
Quoted 26 lines
Quoted 26 lines

I have also run some test on my ux500 board and enabling the blkmq path via the new MMC Kconfig option. My idea was to run some iozone comparisons between the legacy path and the new blkmq path, but I just couldn't get to that point because of the following errors.

I am using a Kingston 4GB SDHC card, which is detected and mounted nicely. However, when I decide to do some writes to the card I get the following errors.

root@ME:/mnt/sdcard dd if=/dev/zero of=testfile bs=8192 count=5000 conv=fsync

[  463.714294] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  464.722656] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  466.081481] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  467.111236] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  468.669647] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  469.685699] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  471.043334] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  472.052337] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  473.342651] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  474.323760] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  475.544769] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  476.539031] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  477.748474] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  478.724182] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
Quoted 8 lines
Quoted 5 lines

I haven't yet got the point of investigating this any further, and unfortunate I have a busy schedule with traveling next week. I will do my best to look into this as soon as I can.

Perhaps you have some ideas?

The behaviour depends on whether you have MMC_CAP_WAIT_WHILE_BUSY. Try changing that and see if it makes a difference.

Yes, it does! I disabled MMC_CAP_WAIT_WHILE_BUSY (and its corresponding code in mmci.c) and the errors goes away.

When I use MMC_CAP_WAIT_WHILE_BUSY I get these problems:

[  223.820983] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  224.815795] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  226.034881] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.112884] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.220275] mmc0: Card stuck in wrong state! mmcblk0 mmc_blk_card_stuck
[  228.686798] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  229.892150] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  231.031890] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  232.239013] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!

5000+0 records in
5000+0 records out
root@ME:/mnt/sdcard

Quoted 8 lines
Quoted 4 lines

I looked at the new blkmq code from patch v10 13/15. It seems like the MMC_CAP_WAIT_WHILE_BUSY is used to determine whether the async request mechanism should be used or not. Perhaps I didn't looked close enough, but maybe you could elaborate on why this seems to be the case!?

MMC_CAP_WAIT_WHILE_BUSY is necessary because it means that a data transfer request has finished when the host controller calls mmc_request_done(). i.e. polling the card is not necessary.

Well, that is a rather big change on its own. Earlier we polled with CMD13 to verify that the card has moved back to the transfer state, in case it was a write. And that was no matter of MMC_CAP_WAIT_WHILE_BUSY was set or not. Right!?

I am not sure it's a good idea to bypass that validation, it seems fragile to rely only on the busy detection on DAT line for writes.

Quoted 3 lines

Have you tried V9 or V10. There was a fix in V9 related to calling ->post_req() which could mess up DMA.

I have used V10.

Quoted 3 lines

The other thing that could go wrong with DMA is if it cannot accept ->post_req() being called from mmc_request_done().

I don't think mmci has a problem with that, however why do you want to do this? Wouldn't that defeat some of the benefits with the async request mechanism?

Kind regards
Uffe

author maintainer
#28 lore raw
Quoted 60 lines · Ulf Hansson

[...]

Quoted 58 lines
Quoted 57 lines
Quoted 26 lines
Quoted 26 lines

I have also run some test on my ux500 board and enabling the blkmq path via the new MMC Kconfig option. My idea was to run some iozone comparisons between the legacy path and the new blkmq path, but I just couldn't get to that point because of the following errors.

I am using a Kingston 4GB SDHC card, which is detected and mounted nicely. However, when I decide to do some writes to the card I get the following errors.

root@ME:/mnt/sdcard dd if=/dev/zero of=testfile bs=8192 count=5000 conv=fsync

[  463.714294] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  464.722656] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  466.081481] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  467.111236] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  468.669647] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  469.685699] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  471.043334] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  472.052337] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  473.342651] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  474.323760] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  475.544769] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  476.539031] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  477.748474] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  478.724182] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
Quoted 8 lines
Quoted 5 lines

I haven't yet got the point of investigating this any further, and unfortunate I have a busy schedule with traveling next week. I will do my best to look into this as soon as I can.

Perhaps you have some ideas?

The behaviour depends on whether you have MMC_CAP_WAIT_WHILE_BUSY. Try changing that and see if it makes a difference.

Yes, it does! I disabled MMC_CAP_WAIT_WHILE_BUSY (and its corresponding code in mmci.c) and the errors goes away.

When I use MMC_CAP_WAIT_WHILE_BUSY I get these problems:

[  223.820983] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  224.815795] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  226.034881] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.112884] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.220275] mmc0: Card stuck in wrong state! mmcblk0 mmc_blk_card_stuck
[  228.686798] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  229.892150] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  231.031890] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  232.239013] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!

5000+0 records in
5000+0 records out
root@ME:/mnt/sdcard

I looked at the new blkmq code from patch v10 13/15. It seems like the MMC_CAP_WAIT_WHILE_BUSY is used to determine whether the async request mechanism should be used or not. Perhaps I didn't looked close enough, but maybe you could elaborate on why this seems to be the case!?

Quoted 8 lines
Quoted 3 lines

MMC_CAP_WAIT_WHILE_BUSY is necessary because it means that a data transfer request has finished when the host controller calls mmc_request_done(). i.e. polling the card is not necessary.

Well, that is a rather big change on its own. Earlier we polled with CMD13 to verify that the card has moved back to the transfer state, in case it was a write. And that was no matter of MMC_CAP_WAIT_WHILE_BUSY was set or not. Right!?

Yes

Quoted 3 lines

I am not sure it's a good idea to bypass that validation, it seems fragile to rely only on the busy detection on DAT line for writes.

Can you cite something from the specifications that backs that up, because I couldn't find anything to suggest that CMD13 polling was expected.

Quoted 8 lines
Quoted 4 lines

Have you tried V9 or V10. There was a fix in V9 related to calling ->post_req() which could mess up DMA.

I have used V10.

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

The other thing that could go wrong with DMA is if it cannot accept ->post_req() being called from mmc_request_done().

I don't think mmci has a problem with that, however why do you want to do this? Wouldn't that defeat some of the benefits with the async request mechanism?

Perhaps - but it would need to be tested. If there are more requests waiting, one optimization could be to defer ->post_req() until after the next request is started.

#29 lore raw
Quoted 70 lines · Adrian Hunter
Quoted 60 lines · Ulf Hansson

[...]

Quoted 58 lines
Quoted 57 lines
Quoted 26 lines
Quoted 26 lines

I have also run some test on my ux500 board and enabling the blkmq path via the new MMC Kconfig option. My idea was to run some iozone comparisons between the legacy path and the new blkmq path, but I just couldn't get to that point because of the following errors.

I am using a Kingston 4GB SDHC card, which is detected and mounted nicely. However, when I decide to do some writes to the card I get the following errors.

root@ME:/mnt/sdcard dd if=/dev/zero of=testfile bs=8192 count=5000 conv=fsync

[  463.714294] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  464.722656] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  466.081481] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  467.111236] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  468.669647] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  469.685699] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  471.043334] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  472.052337] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  473.342651] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  474.323760] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  475.544769] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  476.539031] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  477.748474] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  478.724182] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
Quoted 8 lines
Quoted 5 lines

I haven't yet got the point of investigating this any further, and unfortunate I have a busy schedule with traveling next week. I will do my best to look into this as soon as I can.

Perhaps you have some ideas?

The behaviour depends on whether you have MMC_CAP_WAIT_WHILE_BUSY. Try changing that and see if it makes a difference.

Yes, it does! I disabled MMC_CAP_WAIT_WHILE_BUSY (and its corresponding code in mmci.c) and the errors goes away.

When I use MMC_CAP_WAIT_WHILE_BUSY I get these problems:

[  223.820983] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  224.815795] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  226.034881] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.112884] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.220275] mmc0: Card stuck in wrong state! mmcblk0 mmc_blk_card_stuck
[  228.686798] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  229.892150] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  231.031890] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  232.239013] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!

5000+0 records in
5000+0 records out
root@ME:/mnt/sdcard

I looked at the new blkmq code from patch v10 13/15. It seems like the MMC_CAP_WAIT_WHILE_BUSY is used to determine whether the async request mechanism should be used or not. Perhaps I didn't looked close enough, but maybe you could elaborate on why this seems to be the case!?

Quoted 8 lines
Quoted 3 lines

MMC_CAP_WAIT_WHILE_BUSY is necessary because it means that a data transfer request has finished when the host controller calls mmc_request_done(). i.e. polling the card is not necessary.

Well, that is a rather big change on its own. Earlier we polled with CMD13 to verify that the card has moved back to the transfer state, in case it was a write. And that was no matter of MMC_CAP_WAIT_WHILE_BUSY was set or not. Right!?

Quoted 8 lines

Yes

Quoted 3 lines

I am not sure it's a good idea to bypass that validation, it seems fragile to rely only on the busy detection on DAT line for writes.

Can you cite something from the specifications that backs that up, because I couldn't find anything to suggest that CMD13 polling was expected.

No I can't, but I don't see why that matters.

My point is, if we want to go down that road by avoiding the CMD13 polling, that needs to be a separate change, which we can test and confirm on its own.

Quoted 12 lines
Quoted 12 lines
Quoted 5 lines

Have you tried V9 or V10. There was a fix in V9 related to calling ->post_req() which could mess up DMA.

I have used V10.

Quoted 3 lines

The other thing that could go wrong with DMA is if it cannot accept ->post_req() being called from mmc_request_done().

Quoted 7 lines
Quoted 3 lines

I don't think mmci has a problem with that, however why do you want to do this? Wouldn't that defeat some of the benefits with the async request mechanism?

Perhaps - but it would need to be tested. If there are more requests waiting, one optimization could be to defer ->post_req() until after the next request is started.

This is already proven, because this how the existing mmc async request mechanism works.

In ->post_req() callbacks, host drivers may do dma_unmap_sg(), which is something that could be costly and therefore it's better to start a new request before, such these things can go on in parallel.

Kind regards
Uffe

author maintainer
#30 lore raw
Quoted 106 lines · Ulf Hansson
Quoted 70 lines · Adrian Hunter
Quoted 60 lines · Ulf Hansson

[...]

Quoted 58 lines
Quoted 57 lines
Quoted 26 lines
Quoted 26 lines

I have also run some test on my ux500 board and enabling the blkmq path via the new MMC Kconfig option. My idea was to run some iozone comparisons between the legacy path and the new blkmq path, but I just couldn't get to that point because of the following errors.

I am using a Kingston 4GB SDHC card, which is detected and mounted nicely. However, when I decide to do some writes to the card I get the following errors.

root@ME:/mnt/sdcard dd if=/dev/zero of=testfile bs=8192 count=5000 conv=fsync

[  463.714294] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  464.722656] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  466.081481] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  467.111236] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  468.669647] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  469.685699] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  471.043334] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  472.052337] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  473.342651] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  474.323760] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  475.544769] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  476.539031] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  477.748474] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  478.724182] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
Quoted 8 lines
Quoted 5 lines

I haven't yet got the point of investigating this any further, and unfortunate I have a busy schedule with traveling next week. I will do my best to look into this as soon as I can.

Perhaps you have some ideas?

The behaviour depends on whether you have MMC_CAP_WAIT_WHILE_BUSY. Try changing that and see if it makes a difference.

Yes, it does! I disabled MMC_CAP_WAIT_WHILE_BUSY (and its corresponding code in mmci.c) and the errors goes away.

When I use MMC_CAP_WAIT_WHILE_BUSY I get these problems:

[  223.820983] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  224.815795] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  226.034881] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.112884] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.220275] mmc0: Card stuck in wrong state! mmcblk0 mmc_blk_card_stuck
[  228.686798] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  229.892150] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  231.031890] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  232.239013] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!

5000+0 records in
5000+0 records out
root@ME:/mnt/sdcard

I looked at the new blkmq code from patch v10 13/15. It seems like the MMC_CAP_WAIT_WHILE_BUSY is used to determine whether the async request mechanism should be used or not. Perhaps I didn't looked close enough, but maybe you could elaborate on why this seems to be the case!?

Quoted 8 lines
Quoted 3 lines

MMC_CAP_WAIT_WHILE_BUSY is necessary because it means that a data transfer request has finished when the host controller calls mmc_request_done(). i.e. polling the card is not necessary.

Well, that is a rather big change on its own. Earlier we polled with CMD13 to verify that the card has moved back to the transfer state, in case it was a write. And that was no matter of MMC_CAP_WAIT_WHILE_BUSY was set or not. Right!?

Quoted 8 lines

Yes

Quoted 3 lines

I am not sure it's a good idea to bypass that validation, it seems fragile to rely only on the busy detection on DAT line for writes.

Can you cite something from the specifications that backs that up, because I couldn't find anything to suggest that CMD13 polling was expected.

No I can't, but I don't see why that matters.

My point is, if we want to go down that road by avoiding the CMD13 polling, that needs to be a separate change, which we can test and confirm on its own.

Quoted 12 lines
Quoted 12 lines
Quoted 5 lines

Have you tried V9 or V10. There was a fix in V9 related to calling ->post_req() which could mess up DMA.

I have used V10.

Quoted 3 lines

The other thing that could go wrong with DMA is if it cannot accept ->post_req() being called from mmc_request_done().

Quoted 7 lines
Quoted 3 lines

I don't think mmci has a problem with that, however why do you want to do this? Wouldn't that defeat some of the benefits with the async request mechanism?

Perhaps - but it would need to be tested. If there are more requests waiting, one optimization could be to defer ->post_req() until after the next request is started.

Quoted 6 lines

This is already proven, because this how the existing mmc async request mechanism works.

In ->post_req() callbacks, host drivers may do dma_unmap_sg(), which is something that could be costly and therefore it's better to start a new request before, such these things can go on in parallel.

OK I will make a patch that takes care of both issues. That will also mean the request is not completed in the ->done() callback because ->post_req() must precede block layer completion.

#31 lore raw
Quoted 110 lines · Adrian Hunter
Quoted 109 lines · Ulf Hansson
Quoted 70 lines · Adrian Hunter
Quoted 60 lines · Ulf Hansson

[...]

Quoted 58 lines
Quoted 57 lines
Quoted 26 lines
Quoted 26 lines

I have also run some test on my ux500 board and enabling the blkmq path via the new MMC Kconfig option. My idea was to run some iozone comparisons between the legacy path and the new blkmq path, but I just couldn't get to that point because of the following errors.

I am using a Kingston 4GB SDHC card, which is detected and mounted nicely. However, when I decide to do some writes to the card I get the following errors.

root@ME:/mnt/sdcard dd if=/dev/zero of=testfile bs=8192 count=5000 conv=fsync

[  463.714294] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  464.722656] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  466.081481] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  467.111236] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  468.669647] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  469.685699] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  471.043334] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  472.052337] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  473.342651] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  474.323760] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  475.544769] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  476.539031] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  477.748474] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  478.724182] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
Quoted 8 lines
Quoted 5 lines

I haven't yet got the point of investigating this any further, and unfortunate I have a busy schedule with traveling next week. I will do my best to look into this as soon as I can.

Perhaps you have some ideas?

The behaviour depends on whether you have MMC_CAP_WAIT_WHILE_BUSY. Try changing that and see if it makes a difference.

Yes, it does! I disabled MMC_CAP_WAIT_WHILE_BUSY (and its corresponding code in mmci.c) and the errors goes away.

When I use MMC_CAP_WAIT_WHILE_BUSY I get these problems:

[  223.820983] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  224.815795] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  226.034881] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.112884] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.220275] mmc0: Card stuck in wrong state! mmcblk0 mmc_blk_card_stuck
[  228.686798] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  229.892150] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  231.031890] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  232.239013] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!

5000+0 records in
5000+0 records out
root@ME:/mnt/sdcard

I looked at the new blkmq code from patch v10 13/15. It seems like the MMC_CAP_WAIT_WHILE_BUSY is used to determine whether the async request mechanism should be used or not. Perhaps I didn't looked close enough, but maybe you could elaborate on why this seems to be the case!?

Quoted 8 lines
Quoted 3 lines

MMC_CAP_WAIT_WHILE_BUSY is necessary because it means that a data transfer request has finished when the host controller calls mmc_request_done(). i.e. polling the card is not necessary.

Well, that is a rather big change on its own. Earlier we polled with CMD13 to verify that the card has moved back to the transfer state, in case it was a write. And that was no matter of MMC_CAP_WAIT_WHILE_BUSY was set or not. Right!?

Quoted 8 lines

Yes

Quoted 3 lines

I am not sure it's a good idea to bypass that validation, it seems fragile to rely only on the busy detection on DAT line for writes.

Can you cite something from the specifications that backs that up, because I couldn't find anything to suggest that CMD13 polling was expected.

No I can't, but I don't see why that matters.

My point is, if we want to go down that road by avoiding the CMD13 polling, that needs to be a separate change, which we can test and confirm on its own.

Quoted 12 lines
Quoted 12 lines
Quoted 5 lines

Have you tried V9 or V10. There was a fix in V9 related to calling ->post_req() which could mess up DMA.

I have used V10.

Quoted 3 lines

The other thing that could go wrong with DMA is if it cannot accept ->post_req() being called from mmc_request_done().

Quoted 7 lines
Quoted 3 lines

I don't think mmci has a problem with that, however why do you want to do this? Wouldn't that defeat some of the benefits with the async request mechanism?

Perhaps - but it would need to be tested. If there are more requests waiting, one optimization could be to defer ->post_req() until after the next request is started.

This is already proven, because this how the existing mmc async request mechanism works.

Quoted 7 lines
Quoted 3 lines

In ->post_req() callbacks, host drivers may do dma_unmap_sg(), which is something that could be costly and therefore it's better to start a new request before, such these things can go on in parallel.

OK I will make a patch that takes care of both issues. That will also mean the request is not completed in the ->done() callback because ->post_req() must precede block layer completion.

Right.

Actually completing the request in the ->done callback, may still be possible, because in principle it only needs to inform the other prepared request that it may start, before it continues to post process/completes the current one.

However, by looking at for example how mmci.c works, it actually holds its spinlock while it calls mmc_request_done(). The same spinlock is taken in the ->request() function, but not in the ->post_req() function. In other words, completing the request in the ->done() callback, would make mmci to keep the spinlock held throughout the post processing cycle, which then prevents the next request from being started.

So my conclusion is, let's start a as you suggested, by not completing the request in ->done() as to maintain existing behavior. Then we can address optimizations on top, which very likely will involve doing changes to host drivers as well.

Kind regards
Uffe

#32 lore raw
Quoted 4 lines · Ulf Hansson

Actually completing the request in the ->done callback, may still be possible, because in principle it only needs to inform the other prepared request that it may start, before it continues to post process/completes the current one.

I try to do that in this patch:
https://marc.info/?l=linux-mmc&m=148665460925587&w=2

I'm trying to rebase this work now.

Quoted 7 lines

However, by looking at for example how mmci.c works, it actually holds its spinlock while it calls mmc_request_done(). The same spinlock is taken in the ->request() function, but not in the ->post_req() function. In other words, completing the request in the ->done() callback, would make mmci to keep the spinlock held throughout the post processing cycle, which then prevents the next request from being started.

It seems my patch would not deliver in some drivers until we look into the locking semantics in the drivers.

Yours,
Linus Walleij

#33 lore raw
Quoted 9 lines · Linus Walleij
Quoted 4 lines · Ulf Hansson

Actually completing the request in the ->done callback, may still be possible, because in principle it only needs to inform the other prepared request that it may start, before it continues to post process/completes the current one.

I try to do that in this patch:
https://marc.info/?l=linux-mmc&m=148665460925587&w=2

Yeah, something like that!

Quoted 2 lines

I'm trying to rebase this work now.

Great!

Quoted 11 lines
Quoted 8 lines

However, by looking at for example how mmci.c works, it actually holds its spinlock while it calls mmc_request_done(). The same spinlock is taken in the ->request() function, but not in the ->post_req() function. In other words, completing the request in the ->done() callback, would make mmci to keep the spinlock held throughout the post processing cycle, which then prevents the next request from being started.

It seems my patch would not deliver in some drivers until we look into the locking semantics in the drivers.

Yes!

As a matter of fact the above change may actually introduce performance regressions, in case the behavior of the driver doesn't follow the expectations from the core. For that reason, either we have to invent a new MMC cap to allow drivers to opt-in using the "shortcut" or fix host drivers first.

Kind regards
Uffe

author maintainer
#34 lore raw
In reply to Ulf Hansson
Quoted 119 lines · Ulf Hansson
Quoted 110 lines · Adrian Hunter
Quoted 109 lines · Ulf Hansson
Quoted 70 lines · Adrian Hunter
Quoted 60 lines · Ulf Hansson

[...]

Quoted 58 lines
Quoted 57 lines
Quoted 26 lines
Quoted 26 lines

I have also run some test on my ux500 board and enabling the blkmq path via the new MMC Kconfig option. My idea was to run some iozone comparisons between the legacy path and the new blkmq path, but I just couldn't get to that point because of the following errors.

I am using a Kingston 4GB SDHC card, which is detected and mounted nicely. However, when I decide to do some writes to the card I get the following errors.

root@ME:/mnt/sdcard dd if=/dev/zero of=testfile bs=8192 count=5000 conv=fsync

[  463.714294] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  464.722656] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  466.081481] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  467.111236] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  468.669647] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  469.685699] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  471.043334] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  472.052337] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  473.342651] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  474.323760] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  475.544769] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  476.539031] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  477.748474] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  478.724182] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
Quoted 8 lines
Quoted 5 lines

I haven't yet got the point of investigating this any further, and unfortunate I have a busy schedule with traveling next week. I will do my best to look into this as soon as I can.

Perhaps you have some ideas?

The behaviour depends on whether you have MMC_CAP_WAIT_WHILE_BUSY. Try changing that and see if it makes a difference.

Yes, it does! I disabled MMC_CAP_WAIT_WHILE_BUSY (and its corresponding code in mmci.c) and the errors goes away.

When I use MMC_CAP_WAIT_WHILE_BUSY I get these problems:

[  223.820983] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  224.815795] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  226.034881] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.112884] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.220275] mmc0: Card stuck in wrong state! mmcblk0 mmc_blk_card_stuck
[  228.686798] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  229.892150] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  231.031890] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  232.239013] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!

5000+0 records in
5000+0 records out
root@ME:/mnt/sdcard

I looked at the new blkmq code from patch v10 13/15. It seems like the MMC_CAP_WAIT_WHILE_BUSY is used to determine whether the async request mechanism should be used or not. Perhaps I didn't looked close enough, but maybe you could elaborate on why this seems to be the case!?

Quoted 8 lines
Quoted 3 lines

MMC_CAP_WAIT_WHILE_BUSY is necessary because it means that a data transfer request has finished when the host controller calls mmc_request_done(). i.e. polling the card is not necessary.

Well, that is a rather big change on its own. Earlier we polled with CMD13 to verify that the card has moved back to the transfer state, in case it was a write. And that was no matter of MMC_CAP_WAIT_WHILE_BUSY was set or not. Right!?

Quoted 8 lines

Yes

Quoted 3 lines

I am not sure it's a good idea to bypass that validation, it seems fragile to rely only on the busy detection on DAT line for writes.

Can you cite something from the specifications that backs that up, because I couldn't find anything to suggest that CMD13 polling was expected.

No I can't, but I don't see why that matters.

My point is, if we want to go down that road by avoiding the CMD13 polling, that needs to be a separate change, which we can test and confirm on its own.

Quoted 12 lines
Quoted 12 lines
Quoted 5 lines

Have you tried V9 or V10. There was a fix in V9 related to calling ->post_req() which could mess up DMA.

I have used V10.

Quoted 3 lines

The other thing that could go wrong with DMA is if it cannot accept ->post_req() being called from mmc_request_done().

Quoted 7 lines
Quoted 3 lines

I don't think mmci has a problem with that, however why do you want to do this? Wouldn't that defeat some of the benefits with the async request mechanism?

Perhaps - but it would need to be tested. If there are more requests waiting, one optimization could be to defer ->post_req() until after the next request is started.

This is already proven, because this how the existing mmc async request mechanism works.

Quoted 7 lines
Quoted 3 lines

In ->post_req() callbacks, host drivers may do dma_unmap_sg(), which is something that could be costly and therefore it's better to start a new request before, such these things can go on in parallel.

OK I will make a patch that takes care of both issues. That will also mean the request is not completed in the ->done() callback because ->post_req() must precede block layer completion.

Quoted 6 lines

Right.

Actually completing the request in the ->done callback, may still be possible, because in principle it only needs to inform the other prepared request that it may start, before it continues to post process/completes the current one.

It already does that.

Quoted 8 lines

However, by looking at for example how mmci.c works, it actually holds its spinlock while it calls mmc_request_done(). The same spinlock is taken in the ->request() function, but not in the ->post_req() function. In other words, completing the request in the ->done() callback, would make mmci to keep the spinlock held throughout the post processing cycle, which then prevents the next request from being started.

It is in interrupt context also. So if the block layer work is on the same CPU it will anyway wait.

Quoted 5 lines

So my conclusion is, let's start a as you suggested, by not completing the request in ->done() as to maintain existing behavior. Then we can address optimizations on top, which very likely will involve doing changes to host drivers as well.

Ideally it should be possible to start the next already prepared request from the ->done() callback of the current request. Perhaps add a new host API.

author maintainer
#35 lore raw
In reply to Ulf Hansson
Quoted 134 lines · Ulf Hansson
Quoted 110 lines · Adrian Hunter
Quoted 109 lines · Ulf Hansson
Quoted 70 lines · Adrian Hunter
Quoted 60 lines · Ulf Hansson

[...]

Quoted 58 lines
Quoted 57 lines
Quoted 26 lines
Quoted 26 lines

I have also run some test on my ux500 board and enabling the blkmq path via the new MMC Kconfig option. My idea was to run some iozone comparisons between the legacy path and the new blkmq path, but I just couldn't get to that point because of the following errors.

I am using a Kingston 4GB SDHC card, which is detected and mounted nicely. However, when I decide to do some writes to the card I get the following errors.

root@ME:/mnt/sdcard dd if=/dev/zero of=testfile bs=8192 count=5000 conv=fsync

[  463.714294] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  464.722656] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  466.081481] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  467.111236] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  468.669647] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  469.685699] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  471.043334] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  472.052337] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  473.342651] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  474.323760] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  475.544769] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  476.539031] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  477.748474] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  478.724182] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
Quoted 8 lines
Quoted 5 lines

I haven't yet got the point of investigating this any further, and unfortunate I have a busy schedule with traveling next week. I will do my best to look into this as soon as I can.

Perhaps you have some ideas?

The behaviour depends on whether you have MMC_CAP_WAIT_WHILE_BUSY. Try changing that and see if it makes a difference.

Yes, it does! I disabled MMC_CAP_WAIT_WHILE_BUSY (and its corresponding code in mmci.c) and the errors goes away.

When I use MMC_CAP_WAIT_WHILE_BUSY I get these problems:

[  223.820983] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  224.815795] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  226.034881] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.112884] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.220275] mmc0: Card stuck in wrong state! mmcblk0 mmc_blk_card_stuck
[  228.686798] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  229.892150] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  231.031890] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  232.239013] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!

5000+0 records in
5000+0 records out
root@ME:/mnt/sdcard

I looked at the new blkmq code from patch v10 13/15. It seems like the MMC_CAP_WAIT_WHILE_BUSY is used to determine whether the async request mechanism should be used or not. Perhaps I didn't looked close enough, but maybe you could elaborate on why this seems to be the case!?

Quoted 8 lines
Quoted 3 lines

MMC_CAP_WAIT_WHILE_BUSY is necessary because it means that a data transfer request has finished when the host controller calls mmc_request_done(). i.e. polling the card is not necessary.

Well, that is a rather big change on its own. Earlier we polled with CMD13 to verify that the card has moved back to the transfer state, in case it was a write. And that was no matter of MMC_CAP_WAIT_WHILE_BUSY was set or not. Right!?

Quoted 8 lines

Yes

Quoted 3 lines

I am not sure it's a good idea to bypass that validation, it seems fragile to rely only on the busy detection on DAT line for writes.

Can you cite something from the specifications that backs that up, because I couldn't find anything to suggest that CMD13 polling was expected.

No I can't, but I don't see why that matters.

My point is, if we want to go down that road by avoiding the CMD13 polling, that needs to be a separate change, which we can test and confirm on its own.

Quoted 12 lines
Quoted 12 lines
Quoted 5 lines

Have you tried V9 or V10. There was a fix in V9 related to calling ->post_req() which could mess up DMA.

I have used V10.

Quoted 3 lines

The other thing that could go wrong with DMA is if it cannot accept ->post_req() being called from mmc_request_done().

Quoted 7 lines
Quoted 3 lines

I don't think mmci has a problem with that, however why do you want to do this? Wouldn't that defeat some of the benefits with the async request mechanism?

Perhaps - but it would need to be tested. If there are more requests waiting, one optimization could be to defer ->post_req() until after the next request is started.

This is already proven, because this how the existing mmc async request mechanism works.

Quoted 7 lines
Quoted 3 lines

In ->post_req() callbacks, host drivers may do dma_unmap_sg(), which is something that could be costly and therefore it's better to start a new request before, such these things can go on in parallel.

OK I will make a patch that takes care of both issues. That will also mean the request is not completed in the ->done() callback because ->post_req() must precede block layer completion.

Right.

Actually completing the request in the ->done callback, may still be possible, because in principle it only needs to inform the other prepared request that it may start, before it continues to post process/completes the current one.

However, by looking at for example how mmci.c works, it actually holds its spinlock while it calls mmc_request_done(). The same spinlock is taken in the ->request() function, but not in the ->post_req() function. In other words, completing the request in the ->done() callback, would make mmci to keep the spinlock held throughout the post processing cycle, which then prevents the next request from being started.

Quoted 4 lines

So my conclusion is, let's start a as you suggested, by not completing the request in ->done() as to maintain existing behavior. Then we can address optimizations on top, which very likely will involve doing changes to host drivers as well.

Have you tested the latest version now?

author maintainer
#36 lore raw
Quoted 135 lines · Adrian Hunter
Quoted 134 lines · Ulf Hansson
Quoted 110 lines · Adrian Hunter
Quoted 109 lines · Ulf Hansson
Quoted 70 lines · Adrian Hunter
Quoted 60 lines · Ulf Hansson

[...]

Quoted 58 lines
Quoted 57 lines
Quoted 26 lines
Quoted 26 lines

I have also run some test on my ux500 board and enabling the blkmq path via the new MMC Kconfig option. My idea was to run some iozone comparisons between the legacy path and the new blkmq path, but I just couldn't get to that point because of the following errors.

I am using a Kingston 4GB SDHC card, which is detected and mounted nicely. However, when I decide to do some writes to the card I get the following errors.

root@ME:/mnt/sdcard dd if=/dev/zero of=testfile bs=8192 count=5000 conv=fsync

[  463.714294] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  464.722656] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  466.081481] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  467.111236] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  468.669647] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  469.685699] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  471.043334] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  472.052337] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  473.342651] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  474.323760] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  475.544769] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  476.539031] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  477.748474] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  478.724182] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
Quoted 8 lines
Quoted 5 lines

I haven't yet got the point of investigating this any further, and unfortunate I have a busy schedule with traveling next week. I will do my best to look into this as soon as I can.

Perhaps you have some ideas?

The behaviour depends on whether you have MMC_CAP_WAIT_WHILE_BUSY. Try changing that and see if it makes a difference.

Yes, it does! I disabled MMC_CAP_WAIT_WHILE_BUSY (and its corresponding code in mmci.c) and the errors goes away.

When I use MMC_CAP_WAIT_WHILE_BUSY I get these problems:

[  223.820983] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  224.815795] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  226.034881] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.112884] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.220275] mmc0: Card stuck in wrong state! mmcblk0 mmc_blk_card_stuck
[  228.686798] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  229.892150] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  231.031890] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  232.239013] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!

5000+0 records in
5000+0 records out
root@ME:/mnt/sdcard

I looked at the new blkmq code from patch v10 13/15. It seems like the MMC_CAP_WAIT_WHILE_BUSY is used to determine whether the async request mechanism should be used or not. Perhaps I didn't looked close enough, but maybe you could elaborate on why this seems to be the case!?

Quoted 8 lines
Quoted 3 lines

MMC_CAP_WAIT_WHILE_BUSY is necessary because it means that a data transfer request has finished when the host controller calls mmc_request_done(). i.e. polling the card is not necessary.

Well, that is a rather big change on its own. Earlier we polled with CMD13 to verify that the card has moved back to the transfer state, in case it was a write. And that was no matter of MMC_CAP_WAIT_WHILE_BUSY was set or not. Right!?

Quoted 8 lines

Yes

Quoted 3 lines

I am not sure it's a good idea to bypass that validation, it seems fragile to rely only on the busy detection on DAT line for writes.

Can you cite something from the specifications that backs that up, because I couldn't find anything to suggest that CMD13 polling was expected.

No I can't, but I don't see why that matters.

My point is, if we want to go down that road by avoiding the CMD13 polling, that needs to be a separate change, which we can test and confirm on its own.

Quoted 12 lines
Quoted 12 lines
Quoted 5 lines

Have you tried V9 or V10. There was a fix in V9 related to calling ->post_req() which could mess up DMA.

I have used V10.

Quoted 3 lines

The other thing that could go wrong with DMA is if it cannot accept ->post_req() being called from mmc_request_done().

Quoted 7 lines
Quoted 3 lines

I don't think mmci has a problem with that, however why do you want to do this? Wouldn't that defeat some of the benefits with the async request mechanism?

Perhaps - but it would need to be tested. If there are more requests waiting, one optimization could be to defer ->post_req() until after the next request is started.

This is already proven, because this how the existing mmc async request mechanism works.

Quoted 7 lines
Quoted 3 lines

In ->post_req() callbacks, host drivers may do dma_unmap_sg(), which is something that could be costly and therefore it's better to start a new request before, such these things can go on in parallel.

OK I will make a patch that takes care of both issues. That will also mean the request is not completed in the ->done() callback because ->post_req() must precede block layer completion.

Right.

Actually completing the request in the ->done callback, may still be possible, because in principle it only needs to inform the other prepared request that it may start, before it continues to post process/completes the current one.

However, by looking at for example how mmci.c works, it actually holds its spinlock while it calls mmc_request_done(). The same spinlock is taken in the ->request() function, but not in the ->post_req() function. In other words, completing the request in the ->done() callback, would make mmci to keep the spinlock held throughout the post processing cycle, which then prevents the next request from being started.

Quoted 7 lines
Quoted 4 lines

So my conclusion is, let's start a as you suggested, by not completing the request in ->done() as to maintain existing behavior. Then we can address optimizations on top, which very likely will involve doing changes to host drivers as well.

Have you tested the latest version now?

Ping?

author maintainer
#37 lore raw
Quoted 141 lines · Adrian Hunter
Quoted 140 lines · Adrian Hunter
Quoted 138 lines · Ulf Hansson
Quoted 110 lines · Adrian Hunter
Quoted 109 lines · Ulf Hansson
Quoted 70 lines · Adrian Hunter
Quoted 60 lines · Ulf Hansson

[...]

Quoted 58 lines
Quoted 57 lines
Quoted 26 lines
Quoted 26 lines

I have also run some test on my ux500 board and enabling the blkmq path via the new MMC Kconfig option. My idea was to run some iozone comparisons between the legacy path and the new blkmq path, but I just couldn't get to that point because of the following errors.

I am using a Kingston 4GB SDHC card, which is detected and mounted nicely. However, when I decide to do some writes to the card I get the following errors.

root@ME:/mnt/sdcard dd if=/dev/zero of=testfile bs=8192 count=5000 conv=fsync

[  463.714294] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  464.722656] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  466.081481] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  467.111236] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  468.669647] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  469.685699] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  471.043334] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  472.052337] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  473.342651] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  474.323760] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  475.544769] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  476.539031] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  477.748474] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  478.724182] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
Quoted 8 lines
Quoted 5 lines

I haven't yet got the point of investigating this any further, and unfortunate I have a busy schedule with traveling next week. I will do my best to look into this as soon as I can.

Perhaps you have some ideas?

The behaviour depends on whether you have MMC_CAP_WAIT_WHILE_BUSY. Try changing that and see if it makes a difference.

Yes, it does! I disabled MMC_CAP_WAIT_WHILE_BUSY (and its corresponding code in mmci.c) and the errors goes away.

When I use MMC_CAP_WAIT_WHILE_BUSY I get these problems:

[  223.820983] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  224.815795] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  226.034881] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.112884] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.220275] mmc0: Card stuck in wrong state! mmcblk0 mmc_blk_card_stuck
[  228.686798] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  229.892150] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  231.031890] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  232.239013] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!

5000+0 records in
5000+0 records out
root@ME:/mnt/sdcard

I looked at the new blkmq code from patch v10 13/15. It seems like the MMC_CAP_WAIT_WHILE_BUSY is used to determine whether the async request mechanism should be used or not. Perhaps I didn't looked close enough, but maybe you could elaborate on why this seems to be the case!?

Quoted 8 lines
Quoted 3 lines

MMC_CAP_WAIT_WHILE_BUSY is necessary because it means that a data transfer request has finished when the host controller calls mmc_request_done(). i.e. polling the card is not necessary.

Well, that is a rather big change on its own. Earlier we polled with CMD13 to verify that the card has moved back to the transfer state, in case it was a write. And that was no matter of MMC_CAP_WAIT_WHILE_BUSY was set or not. Right!?

Quoted 8 lines

Yes

Quoted 3 lines

I am not sure it's a good idea to bypass that validation, it seems fragile to rely only on the busy detection on DAT line for writes.

Can you cite something from the specifications that backs that up, because I couldn't find anything to suggest that CMD13 polling was expected.

No I can't, but I don't see why that matters.

My point is, if we want to go down that road by avoiding the CMD13 polling, that needs to be a separate change, which we can test and confirm on its own.

Quoted 12 lines
Quoted 12 lines
Quoted 5 lines

Have you tried V9 or V10. There was a fix in V9 related to calling ->post_req() which could mess up DMA.

I have used V10.

Quoted 3 lines

The other thing that could go wrong with DMA is if it cannot accept ->post_req() being called from mmc_request_done().

Quoted 7 lines
Quoted 3 lines

I don't think mmci has a problem with that, however why do you want to do this? Wouldn't that defeat some of the benefits with the async request mechanism?

Perhaps - but it would need to be tested. If there are more requests waiting, one optimization could be to defer ->post_req() until after the next request is started.

This is already proven, because this how the existing mmc async request mechanism works.

Quoted 7 lines
Quoted 3 lines

In ->post_req() callbacks, host drivers may do dma_unmap_sg(), which is something that could be costly and therefore it's better to start a new request before, such these things can go on in parallel.

OK I will make a patch that takes care of both issues. That will also mean the request is not completed in the ->done() callback because ->post_req() must precede block layer completion.

Right.

Actually completing the request in the ->done callback, may still be possible, because in principle it only needs to inform the other prepared request that it may start, before it continues to post process/completes the current one.

However, by looking at for example how mmci.c works, it actually holds its spinlock while it calls mmc_request_done(). The same spinlock is taken in the ->request() function, but not in the ->post_req() function. In other words, completing the request in the ->done() callback, would make mmci to keep the spinlock held throughout the post processing cycle, which then prevents the next request from being started.

So my conclusion is, let's start a as you suggested, by not completing the request in ->done() as to maintain existing behavior. Then we can address optimizations on top, which very likely will involve doing changes to host drivers as well.

Quoted 4 lines
Quoted 2 lines

Have you tested the latest version now?

Ping?

Still ping?

author maintainer
#38 lore raw
Quoted 142 lines · Adrian Hunter
Quoted 141 lines · Adrian Hunter
Quoted 140 lines · Adrian Hunter
Quoted 138 lines · Ulf Hansson
Quoted 110 lines · Adrian Hunter
Quoted 109 lines · Ulf Hansson
Quoted 70 lines · Adrian Hunter
Quoted 60 lines · Ulf Hansson

[...]

Quoted 58 lines
Quoted 57 lines
Quoted 26 lines
Quoted 26 lines

I have also run some test on my ux500 board and enabling the blkmq path via the new MMC Kconfig option. My idea was to run some iozone comparisons between the legacy path and the new blkmq path, but I just couldn't get to that point because of the following errors.

I am using a Kingston 4GB SDHC card, which is detected and mounted nicely. However, when I decide to do some writes to the card I get the following errors.

root@ME:/mnt/sdcard dd if=/dev/zero of=testfile bs=8192 count=5000 conv=fsync

[  463.714294] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  464.722656] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  466.081481] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  467.111236] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  468.669647] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  469.685699] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  471.043334] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  472.052337] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  473.342651] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  474.323760] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  475.544769] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  476.539031] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  477.748474] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  478.724182] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
Quoted 8 lines
Quoted 5 lines

I haven't yet got the point of investigating this any further, and unfortunate I have a busy schedule with traveling next week. I will do my best to look into this as soon as I can.

Perhaps you have some ideas?

The behaviour depends on whether you have MMC_CAP_WAIT_WHILE_BUSY. Try changing that and see if it makes a difference.

Yes, it does! I disabled MMC_CAP_WAIT_WHILE_BUSY (and its corresponding code in mmci.c) and the errors goes away.

When I use MMC_CAP_WAIT_WHILE_BUSY I get these problems:

[  223.820983] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  224.815795] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  226.034881] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.112884] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  227.220275] mmc0: Card stuck in wrong state! mmcblk0 mmc_blk_card_stuck
[  228.686798] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  229.892150] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  231.031890] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!
[  232.239013] mmci-pl18x 80126000.sdi0_per1: error during DMA transfer!

5000+0 records in
5000+0 records out
root@ME:/mnt/sdcard

I looked at the new blkmq code from patch v10 13/15. It seems like the MMC_CAP_WAIT_WHILE_BUSY is used to determine whether the async request mechanism should be used or not. Perhaps I didn't looked close enough, but maybe you could elaborate on why this seems to be the case!?

Quoted 8 lines
Quoted 3 lines

MMC_CAP_WAIT_WHILE_BUSY is necessary because it means that a data transfer request has finished when the host controller calls mmc_request_done(). i.e. polling the card is not necessary.

Well, that is a rather big change on its own. Earlier we polled with CMD13 to verify that the card has moved back to the transfer state, in case it was a write. And that was no matter of MMC_CAP_WAIT_WHILE_BUSY was set or not. Right!?

Quoted 8 lines

Yes

Quoted 3 lines

I am not sure it's a good idea to bypass that validation, it seems fragile to rely only on the busy detection on DAT line for writes.

Can you cite something from the specifications that backs that up, because I couldn't find anything to suggest that CMD13 polling was expected.

No I can't, but I don't see why that matters.

My point is, if we want to go down that road by avoiding the CMD13 polling, that needs to be a separate change, which we can test and confirm on its own.

Quoted 12 lines
Quoted 12 lines
Quoted 5 lines

Have you tried V9 or V10. There was a fix in V9 related to calling ->post_req() which could mess up DMA.

I have used V10.

Quoted 3 lines

The other thing that could go wrong with DMA is if it cannot accept ->post_req() being called from mmc_request_done().

Quoted 7 lines
Quoted 3 lines

I don't think mmci has a problem with that, however why do you want to do this? Wouldn't that defeat some of the benefits with the async request mechanism?

Perhaps - but it would need to be tested. If there are more requests waiting, one optimization could be to defer ->post_req() until after the next request is started.

This is already proven, because this how the existing mmc async request mechanism works.

Quoted 7 lines
Quoted 3 lines

In ->post_req() callbacks, host drivers may do dma_unmap_sg(), which is something that could be costly and therefore it's better to start a new request before, such these things can go on in parallel.

OK I will make a patch that takes care of both issues. That will also mean the request is not completed in the ->done() callback because ->post_req() must precede block layer completion.

Right.

Actually completing the request in the ->done callback, may still be possible, because in principle it only needs to inform the other prepared request that it may start, before it continues to post process/completes the current one.

However, by looking at for example how mmci.c works, it actually holds its spinlock while it calls mmc_request_done(). The same spinlock is taken in the ->request() function, but not in the ->post_req() function. In other words, completing the request in the ->done() callback, would make mmci to keep the spinlock held throughout the post processing cycle, which then prevents the next request from being started.

So my conclusion is, let's start a as you suggested, by not completing the request in ->done() as to maintain existing behavior. Then we can address optimizations on top, which very likely will involve doing changes to host drivers as well.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Have you tested the latest version now?

Ping?

Still ping?

How is your silence in any way an acceptable way to execute your responsibilities as maintainer!

#39 lore raw

+ Bartlomiej

[...]

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

So my conclusion is, let's start a as you suggested, by not completing the request in ->done() as to maintain existing behavior. Then we can address optimizations on top, which very likely will involve doing changes to host drivers as well.

Have you tested the latest version now?

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Ping?

Still ping?

How is your silence in any way an acceptable way to execute your responsibilities as maintainer!

Seriously? You posted the new version Oct 13.

I had to make some late minute travel decisions, so unfortunate I won't be able to test this on HW from this Friday.

However, you have completely ignored mine, Linus and Bartlomiej's comments about that we want the blkmq port being a separate patch(es) and then make the CMDQ patches on top. This worries me, because it seems like our messages don't reach you.

Kind regards
Uffe

author maintainer
#40 lore raw
Quoted 12 lines · Ulf Hansson

+ Bartlomiej

[...]

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

So my conclusion is, let's start a as you suggested, by not completing the request in ->done() as to maintain existing behavior. Then we can address optimizations on top, which very likely will involve doing changes to host drivers as well.

Have you tested the latest version now?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Ping?

Still ping?

How is your silence in any way an acceptable way to execute your responsibilities as maintainer!

Seriously? You posted the new version Oct 13.

When you constantly go silent it looks like you are deliberately delaying the patches - which you have a long history of doing. Are you deliberately delaying again?

What are you plans for the patches?

Why do you think mmc work is so unimportant it can be left to whenever you deign to get around to it?

Quoted 8 lines

I had to make some late minute travel decisions, so unfortunate I won't be able to test this on HW from this Friday.

However, you have completely ignored mine, Linus and Bartlomiej's comments about that we want the blkmq port being a separate patch(es) and then make the CMDQ patches on top. This worries me, because it seems like our messages don't reach you.

Rubbish! I gave a very good reason for keeping the CQE code in - it is designed to work together. I also pointed out that it is trivial to see the CQE code and that it is all '+' lines anyway.

But not one question in response! Where is a single example of why it is difficult like it is. Where are the questions! Not even a request for documentation! How I am supposed to know what you do or don't understand if you don't ask any questions! There is no evidence that you guys have read a single line!

So, what are your plans for the patches? What don't you understand?

#41 lore raw

[...]

Quoted 8 lines
Quoted 4 lines

However, you have completely ignored mine, Linus and Bartlomiej's comments about that we want the blkmq port being a separate patch(es) and then make the CMDQ patches on top. This worries me, because it seems like our messages don't reach you.

Rubbish! I gave a very good reason for keeping the CQE code in - it is designed to work together. I also pointed out that it is trivial to see the CQE code and that it is all '+' lines anyway.

You gave reasons, but none of us bought them.

Quoted 6 lines

But not one question in response! Where is a single example of why it is difficult like it is. Where are the questions! Not even a request for documentation! How I am supposed to know what you do or don't understand if you don't ask any questions! There is no evidence that you guys have read a single line!

I have and I have also tested it, finding it not working. As reported.

However, I have also told you that I am having a *hard time* to review it, because it implements both blkmq and CMDQ in the same patch to code changes get complex.

Quoted 2 lines

So, what are your plans for the patches? What don't you understand?

I have told you this several time, so has Linus and Bartlomiej.

If you can split it up such the blkmq support comes first, then I can review/test and pick it up.

Kind regards
Uffe

author maintainer
#42 lore raw
Quoted 27 lines · Ulf Hansson

[...]

Quoted 8 lines
Quoted 4 lines

However, you have completely ignored mine, Linus and Bartlomiej's comments about that we want the blkmq port being a separate patch(es) and then make the CMDQ patches on top. This worries me, because it seems like our messages don't reach you.

Rubbish! I gave a very good reason for keeping the CQE code in - it is designed to work together. I also pointed out that it is trivial to see the CQE code and that it is all '+' lines anyway.

You gave reasons, but none of us bought them.

Quoted 6 lines

But not one question in response! Where is a single example of why it is difficult like it is. Where are the questions! Not even a request for documentation! How I am supposed to know what you do or don't understand if you don't ask any questions! There is no evidence that you guys have read a single line!

I have and I have also tested it, finding it not working. As reported.

However, I have also told you that I am having a *hard time* to review it, because it implements both blkmq and CMDQ in the same patch to code changes get complex.

Quoted 1 line
Quoted 6 lines
Quoted 1 line

So, what are your plans for the patches? What don't you understand?

I have told you this several time, so has Linus and Bartlomiej.

If you can split it up such the blkmq support comes first, then I can review/test and pick it up.

I have done the split, but of course the code is just the same.

#43 lore raw
In reply to Adrian Hunter
Quoted 4 lines · Adrian Hunter

Non-CQE blk-mq showed a 3% decrease in sequential read performance. This seemed to be coming from the inferior latency of running work items compared with a dedicated thread. Hacking blk-mq workqueue to be unbound reduced the performance degradation from 3% to 1%.

Can you start a discussion on just this on the linux-block lists?