Skip to contentSkip to conversation

Introduce the request_atomic() for the host

PATCH Superseded Baolin Wang 2 participants 8 messages Mar 17, 2020 – Mar 18, 2020

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Baolin Wang

author maintainer
#0 lore raw

v2 cover Introduce the request_atomic() for the host

This patch set introduces a new request_atomic() interface for the MMC host controller, which is used to submit a request to host in the atomic context, such as in the irq hard handler, to reduce the request latency.

Any comments are welcome. Thanks.

Note: Adrian pointed out that it is not good if moving the polling of inhibit bits in sdhci_send_command() into the interrupt context, but now I have not found a better way to address Adrian's concern. Moveover this is an unusual abnormal case and the original code has the same problem, so I plan to create another patch set to talk about and fix this issue.

Changes from v1:
- Re-split the changes to make them more clear suggested by Ulf.
- Factor out the auto CMD23 checking into a separate function.

Baolin Wang (3):
mmc: host: Introduce the request_atomic() for the host
mmc: host: sdhci: Implement the request_atomic() API
mmc: host: sdhci-sprd: Implement the request_atomic() API

 drivers/mmc/host/mmc_hsq.c    |  5 ++++-
 drivers/mmc/host/sdhci-sprd.c | 23 ++++++++++++++++++++---
 drivers/mmc/host/sdhci.c      | 27 +++++++++++++++++++--------
 drivers/mmc/host/sdhci.h      |  1 +
 include/linux/mmc/host.h      |  3 +++
 5 files changed, 47 insertions(+), 12 deletions(-)
Signature · 1 line
1.9.1
author maintainer
#1 lore raw

PATCH v2 1/3 mmc: host: Introduce the request_atomic() for the host

The SD host controller can process one request in the atomic context if the card is nonremovable, which means we can submit next request in the irq hard handler when using the MMC host software queue to reduce the latency. Thus this patch adds a new API request_atomic() for the host controller, as well as adding support for host software queue to submit a request by the new request_atomic() API.

---
 drivers/mmc/host/mmc_hsq.c | 5 ++++-
 include/linux/mmc/host.h   | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/mmc/host/mmc_hsq.c +4 -1
index 59d2776..fdbaa98 100644
@@ -41,7 +41,10 @@ static void mmc_hsq_pump_requests(struct mmc_hsq *hsq)
 
 	spin_unlock_irqrestore(&hsq->lock, flags);
 
-	mmc->ops->request(mmc, hsq->mrq);
+	if (mmc->ops->request_atomic)
+		mmc->ops->request_atomic(mmc, hsq->mrq);
+	else
+		mmc->ops->request(mmc, hsq->mrq);
 }
 
 static void mmc_hsq_update_next_tag(struct mmc_hsq *hsq, int remains)
include/linux/mmc/host.h +3 -0
index 562ed06..db5e59c 100644
@@ -92,6 +92,9 @@ struct mmc_host_ops {
 			    int err);
 	void	(*pre_req)(struct mmc_host *host, struct mmc_request *req);
 	void	(*request)(struct mmc_host *host, struct mmc_request *req);
+	/* Submit one request to host in atomic context. */
+	void	(*request_atomic)(struct mmc_host *host,
+				  struct mmc_request *req);
 
 	/*
 	 * Avoid calling the next three functions too often or in a "fast
Signature · 1 line
1.9.1
author maintainer
#2 lore raw

PATCH v2 2/3 mmc: host: sdhci: Implement the request_atomic() API

In reply to Baolin Wang

Implement the request_atomic() ops for the sdhci driver to process one request in the atomic context if the card is nonremovable.

---
 drivers/mmc/host/sdhci.c | 27 +++++++++++++++++++--------
 drivers/mmc/host/sdhci.h |  1 +
 2 files changed, 20 insertions(+), 8 deletions(-)
drivers/mmc/host/sdhci.c +19 -8
index 9c37451..4febbcb 100644
@@ -2016,17 +2016,12 @@ void sdhci_set_power(struct sdhci_host *host, unsigned char mode,
  *                                                                           *
 \*****************************************************************************/
 
-void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
+static void sdhci_start_request(struct mmc_host *mmc, struct mmc_request *mrq,
+				int present)
 {
-	struct sdhci_host *host;
-	int present;
+	struct sdhci_host *host = mmc_priv(mmc);
 	unsigned long flags;
 
-	host = mmc_priv(mmc);
-
-	/* Firstly check card presence */
-	present = mmc->ops->get_cd(mmc);
-
 	spin_lock_irqsave(&host->lock, flags);
 
 	sdhci_led_activate(host);
@@ -2043,6 +2038,22 @@ void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
 
 	spin_unlock_irqrestore(&host->lock, flags);
 }
+
+void sdhci_request_atomic(struct mmc_host *mmc, struct mmc_request *mrq)
+{
+	sdhci_start_request(mmc, mrq, 1);
+}
+EXPORT_SYMBOL_GPL(sdhci_request_atomic);
+
+void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
+{
+	int present;
+
+	/* Firstly check card presence */
+	present = mmc->ops->get_cd(mmc);
+
+	sdhci_start_request(mmc, mrq, present);
+}
 EXPORT_SYMBOL_GPL(sdhci_request);
 
 void sdhci_set_bus_width(struct sdhci_host *host, int width)
drivers/mmc/host/sdhci.h +1 -0
index cac2d97..5507a73 100644
@@ -775,6 +775,7 @@ void sdhci_set_power(struct sdhci_host *host, unsigned char mode,
 void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode,
 			   unsigned short vdd);
 void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq);
+void sdhci_request_atomic(struct mmc_host *mmc, struct mmc_request *mrq);
 void sdhci_set_bus_width(struct sdhci_host *host, int width);
 void sdhci_reset(struct sdhci_host *host, u8 mask);
 void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing);
Signature · 1 line
1.9.1
author maintainer
#3 lore raw

PATCH v2 3/3 mmc: host: sdhci-sprd: Implement the request_atomic() API

In reply to Baolin Wang

Implement the request_atomic() API for nonremovable cards, that means we can submit next request in the irq hard handler context to reduce latency.

Moreover factor out the AUTO CMD23 checking into a separate function to reduce duplicate code.

---
 drivers/mmc/host/sdhci-sprd.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/mmc/host/sdhci-sprd.c +20 -3
index 2ab42c5..9a08f70 100644
@@ -406,7 +406,8 @@ static void sdhci_sprd_request_done(struct sdhci_host *host,
 	.request_done = sdhci_sprd_request_done,
 };
 
-static void sdhci_sprd_request(struct mmc_host *mmc, struct mmc_request *mrq)
+static void sdhci_sprd_check_auto_cmd23(struct mmc_host *mmc,
+					struct mmc_request *mrq)
 {
 	struct sdhci_host *host = mmc_priv(mmc);
 	struct sdhci_sprd_host *sprd_host = TO_SPRD_HOST(host);
@@ -422,10 +423,23 @@ static void sdhci_sprd_request(struct mmc_host *mmc, struct mmc_request *mrq)
 	    mrq->sbc && (mrq->sbc->arg & SDHCI_SPRD_ARG2_STUFF) &&
 	    (host->flags & SDHCI_AUTO_CMD23))
 		host->flags &= ~SDHCI_AUTO_CMD23;
+}
+
+static void sdhci_sprd_request(struct mmc_host *mmc, struct mmc_request *mrq)
+{
+	sdhci_sprd_check_auto_cmd23(mmc, mrq);
 
 	sdhci_request(mmc, mrq);
 }
 
+static void sdhci_sprd_request_atomic(struct mmc_host *mmc,
+				      struct mmc_request *mrq)
+{
+	sdhci_sprd_check_auto_cmd23(mmc, mrq);
+
+	sdhci_request_atomic(mmc, mrq);
+}
+
 static int sdhci_sprd_voltage_switch(struct mmc_host *mmc, struct mmc_ios *ios)
 {
 	struct sdhci_host *host = mmc_priv(mmc);
@@ -561,6 +575,11 @@ static int sdhci_sprd_probe(struct platform_device *pdev)
 	if (ret)
 		goto pltfm_free;
 
+	if (!mmc_card_is_removable(host->mmc))
+		host->mmc_host_ops.request_atomic = sdhci_sprd_request_atomic;
+	else
+		host->always_defer_done = true;
+
 	sprd_host = TO_SPRD_HOST(host);
 	sdhci_sprd_phy_param_parse(sprd_host, pdev->dev.of_node);
 
@@ -654,8 +673,6 @@ static int sdhci_sprd_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_cleanup_host;
 
-	host->always_defer_done = true;
-
 	ret = __sdhci_add_host(host);
 	if (ret)
 		goto err_cleanup_host;
Signature · 1 line
1.9.1
maintainer
#4 lore raw
In reply to Baolin Wang
Quoted 5 lines · Baolin Wang

This patch set introduces a new request_atomic() interface for the MMC host controller, which is used to submit a request to host in the atomic context, such as in the irq hard handler, to reduce the request latency.

Quoted 8 lines

Any comments are welcome. Thanks.

Note: Adrian pointed out that it is not good if moving the polling of inhibit bits in sdhci_send_command() into the interrupt context, but now I have not found a better way to address Adrian's concern. Moveover this is an unusual abnormal case and the original code has the same problem, so I plan to create another patch set to talk about and fix this issue.

I tend to think the API requires the possibility for host controllers to return "busy", so that should be sorted out first.

Quoted 17 lines

Changes from v1:
- Re-split the changes to make them more clear suggested by Ulf.
- Factor out the auto CMD23 checking into a separate function.

Baolin Wang (3):
mmc: host: Introduce the request_atomic() for the host
mmc: host: sdhci: Implement the request_atomic() API
mmc: host: sdhci-sprd: Implement the request_atomic() API

 drivers/mmc/host/mmc_hsq.c    |  5 ++++-
 drivers/mmc/host/sdhci-sprd.c | 23 ++++++++++++++++++++---
 drivers/mmc/host/sdhci.c      | 27 +++++++++++++++++++--------
 drivers/mmc/host/sdhci.h      |  1 +
 include/linux/mmc/host.h      |  3 +++
 5 files changed, 47 insertions(+), 12 deletions(-)
author maintainer
#5 lore raw
Quoted 16 lines · Adrian Hunter
Quoted 5 lines · Baolin Wang

This patch set introduces a new request_atomic() interface for the MMC host controller, which is used to submit a request to host in the atomic context, such as in the irq hard handler, to reduce the request latency.

Quoted 8 lines

Any comments are welcome. Thanks.

Note: Adrian pointed out that it is not good if moving the polling of inhibit bits in sdhci_send_command() into the interrupt context, but now I have not found a better way to address Adrian's concern. Moveover this is an unusual abnormal case and the original code has the same problem, so I plan to create another patch set to talk about and fix this issue.

Quoted 2 lines

I tend to think the API requires the possibility for host controllers to return "busy", so that should be sorted out first.

If request_atomic() can return 'busy', the HSQ need queue a work to dispatch this request to host again?

I am thinking if I can introduce a new flag to avoid polling the status before sending commands, cause from the datasheet, I did not see we should need do this if the command complete and transfer complete interrupts are processed normally. At least on my platfrom, I did not see the inhibit bits are set. If we meet this issue, I think some abormal things are happened, we should give out errors. How do you think?

Quoted 18 lines
Quoted 17 lines

Changes from v1:
- Re-split the changes to make them more clear suggested by Ulf.
- Factor out the auto CMD23 checking into a separate function.

Baolin Wang (3):
mmc: host: Introduce the request_atomic() for the host
mmc: host: sdhci: Implement the request_atomic() API
mmc: host: sdhci-sprd: Implement the request_atomic() API

 drivers/mmc/host/mmc_hsq.c    |  5 ++++-
 drivers/mmc/host/sdhci-sprd.c | 23 ++++++++++++++++++++---
 drivers/mmc/host/sdhci.c      | 27 +++++++++++++++++++--------
 drivers/mmc/host/sdhci.h      |  1 +
 include/linux/mmc/host.h      |  3 +++
 5 files changed, 47 insertions(+), 12 deletions(-)
Signature · 1 line
Baolin Wang
maintainer
#6 lore raw
Quoted 17 lines · Baolin Wang
Quoted 16 lines · Adrian Hunter
Quoted 13 lines · Baolin Wang

This patch set introduces a new request_atomic() interface for the MMC host controller, which is used to submit a request to host in the atomic context, such as in the irq hard handler, to reduce the request latency.

Any comments are welcome. Thanks.

Note: Adrian pointed out that it is not good if moving the polling of inhibit bits in sdhci_send_command() into the interrupt context, but now I have not found a better way to address Adrian's concern. Moveover this is an unusual abnormal case and the original code has the same problem, so I plan to create another patch set to talk about and fix this issue.

Quoted 5 lines
Quoted 2 lines

I tend to think the API requires the possibility for host controllers to return "busy", so that should be sorted out first.

If request_atomic() can return 'busy', the HSQ need queue a work to dispatch this request to host again?

Sounds reasonable

Quoted 8 lines

I am thinking if I can introduce a new flag to avoid polling the status before sending commands, cause from the datasheet, I did not see we should need do this if the command complete and transfer complete interrupts are processed normally. At least on my platfrom, I did not see the inhibit bits are set. If we meet this issue, I think some abormal things are happened, we should give out errors. How do you think?

For the atomic path, some kind of warning would be ok.

Quoted 21 lines
Quoted 19 lines
Quoted 18 lines

Changes from v1:
- Re-split the changes to make them more clear suggested by Ulf.
- Factor out the auto CMD23 checking into a separate function.

Baolin Wang (3):
mmc: host: Introduce the request_atomic() for the host
mmc: host: sdhci: Implement the request_atomic() API
mmc: host: sdhci-sprd: Implement the request_atomic() API

 drivers/mmc/host/mmc_hsq.c    |  5 ++++-
 drivers/mmc/host/sdhci-sprd.c | 23 ++++++++++++++++++++---
 drivers/mmc/host/sdhci.c      | 27 +++++++++++++++++++--------
 drivers/mmc/host/sdhci.h      |  1 +
 include/linux/mmc/host.h      |  3 +++
 5 files changed, 47 insertions(+), 12 deletions(-)
author maintainer
#7 lore raw
Quoted 36 lines · Adrian Hunter
Quoted 17 lines · Baolin Wang
Quoted 16 lines · Adrian Hunter
Quoted 13 lines · Baolin Wang

This patch set introduces a new request_atomic() interface for the MMC host controller, which is used to submit a request to host in the atomic context, such as in the irq hard handler, to reduce the request latency.

Any comments are welcome. Thanks.

Note: Adrian pointed out that it is not good if moving the polling of inhibit bits in sdhci_send_command() into the interrupt context, but now I have not found a better way to address Adrian's concern. Moveover this is an unusual abnormal case and the original code has the same problem, so I plan to create another patch set to talk about and fix this issue.

Quoted 5 lines
Quoted 2 lines

I tend to think the API requires the possibility for host controllers to return "busy", so that should be sorted out first.

If request_atomic() can return 'busy', the HSQ need queue a work to dispatch this request to host again?

Sounds reasonable

Quoted 8 lines

I am thinking if I can introduce a new flag to avoid polling the status before sending commands, cause from the datasheet, I did not see we should need do this if the command complete and transfer complete interrupts are processed normally. At least on my platfrom, I did not see the inhibit bits are set. If we meet this issue, I think some abormal things are happened, we should give out errors. How do you think?

Quoted 1 line

For the atomic path, some kind of warning would be ok.

OK. I will try in next version. Thanks.

Quoted 22 lines
Quoted 21 lines
Quoted 19 lines
Quoted 18 lines

Changes from v1:
- Re-split the changes to make them more clear suggested by Ulf.
- Factor out the auto CMD23 checking into a separate function.

Baolin Wang (3):
mmc: host: Introduce the request_atomic() for the host
mmc: host: sdhci: Implement the request_atomic() API
mmc: host: sdhci-sprd: Implement the request_atomic() API

 drivers/mmc/host/mmc_hsq.c    |  5 ++++-
 drivers/mmc/host/sdhci-sprd.c | 23 ++++++++++++++++++++---
 drivers/mmc/host/sdhci.c      | 27 +++++++++++++++++++--------
 drivers/mmc/host/sdhci.h      |  1 +
 include/linux/mmc/host.h      |  3 +++
 5 files changed, 47 insertions(+), 12 deletions(-)
Signature · 1 line
Baolin Wang