Skip to contentSkip to conversation

Port am335 and am437 devices to sdhci-omap

PATCH Superseded Faiz Abbas 7 participants 29 messages Feb 15, 2019 – Apr 2, 2019

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Faiz Abbas

author
#0 lore raw

v2 cover Port am335 and am437 devices to sdhci-omap

The following add driver patches for porting TI's am335x and am437x devices to the sdhci-omap driver.

This involves adding external DMA support to sdhci (first 3 patches from Chunyan) plus some miscellaneous patches to take care of deviations of the controllers from the sdhci model.

DT changes will be posted in a separate series.

Untested versions of Chunyan's patches were posted before[1].

Tested on: am335x-evm, am335x-boneblack, am335x-sk, am437x-gpevm, am43xx-gpevm, am437x-idk, dra7xx-evm, dra72x-evm

v2:
1. sdhci is using two bottom halves. One threaded_rq for card detect and a tasklet for finishing mmc requests. Patch 1 removes the tasklet and moves its function to the threaded_irq. This enables me to terminate_sync() in sdhci_request_done()

2. Factored out common code for between the normal adn external dma case

3. Using existing API sdhci_data_timeout_irq for disabling DTO during erase commands.

4. Fixed subject line for dt-bindings patch.

[1] https://patchwork.kernel.org/project/linux-mmc/list/?series=54897

Chunyan Zhang (3):
mmc: sdhci: add support for using external DMA devices
dt-bindings: sdhci-omap: Add properties for using external dma
mmc: sdhci-omap: Add using external dma

Faiz Abbas (5):
mmc: sdhci: Get rid of finish_tasklet
mmc: sdhci: Add quirk for disabling DTO during erase command
mmc: sdhci-omap: Add DISABLE_DTO_FOR_ERASE Quirk
dt-bindings: sdhci-omap: Add am335x and am437x specific bindings
mmc: sdhci-omap: Add am335x and am437x specific compatibles

 .../devicetree/bindings/mmc/sdhci-omap.txt    |   9 +
 drivers/mmc/host/Kconfig                      |   4 +
 drivers/mmc/host/sdhci-omap.c                 |  27 +-
 drivers/mmc/host/sdhci.c                      | 333 +++++++++++++++---
 drivers/mmc/host/sdhci.h                      |  12 +-
 5 files changed, 328 insertions(+), 57 deletions(-)
Signature · 1 line
2.19.2
author
#1 lore raw

PATCH v2 1/8 mmc: sdhci: Get rid of finish_tasklet

sdhci.c has two bottom halves implemented. A threaded_irq for handling card insert/remove operations and a tasklet for finishing mmc requests. With the addition of external dma support, dmaengine APIs need to terminate in non-atomic context before unmapping the dma buffers.

To facilitate this, remove the finish_tasklet and move the call of sdhci_request_done() to the threaded_irq() callback. Also move the interrupt result variable to sdhci_host so it can be populated from anywhere inside the sdhci_irq handler.

---
 drivers/mmc/host/sdhci.c | 43 +++++++++++++++-------------------------
 drivers/mmc/host/sdhci.h |  2 +-
 2 files changed, 17 insertions(+), 28 deletions(-)
drivers/mmc/host/sdhci.c +16 -27
index eba9bcc92ad3..20ed09b896d7 100644
@@ -1232,7 +1232,7 @@ static void __sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq)
 
 	WARN_ON(i >= SDHCI_MAX_MRQS);
 
-	tasklet_schedule(&host->finish_tasklet);
+	host->result = IRQ_WAKE_THREAD;
 }
 
 static void sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq)
@@ -2705,14 +2705,6 @@ static bool sdhci_request_done(struct sdhci_host *host)
 	return false;
 }
 
-static void sdhci_tasklet_finish(unsigned long param)
-{
-	struct sdhci_host *host = (struct sdhci_host *)param;
-
-	while (!sdhci_request_done(host))
-		;
-}
-
 static void sdhci_timeout_timer(struct timer_list *t)
 {
 	struct sdhci_host *host;
@@ -2995,11 +2987,12 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
 
 static irqreturn_t sdhci_irq(int irq, void *dev_id)
 {
-	irqreturn_t result = IRQ_NONE;
 	struct sdhci_host *host = dev_id;
 	u32 intmask, mask, unexpected = 0;
 	int max_loops = 16;
 
+	host->result = IRQ_NONE;
+
 	spin_lock(&host->lock);
 
 	if (host->runtime_suspended && !sdhci_sdio_irq_enabled(host)) {
@@ -3009,7 +3002,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 
 	intmask = sdhci_readl(host, SDHCI_INT_STATUS);
 	if (!intmask || intmask == 0xffffffff) {
-		result = IRQ_NONE;
+		host->result = IRQ_NONE;
 		goto out;
 	}
 
@@ -3054,7 +3047,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 
 			host->thread_isr |= intmask & (SDHCI_INT_CARD_INSERT |
 						       SDHCI_INT_CARD_REMOVE);
-			result = IRQ_WAKE_THREAD;
+			host->result = IRQ_WAKE_THREAD;
 		}
 
 		if (intmask & SDHCI_INT_CMD_MASK)
@@ -3074,7 +3067,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 		    (host->ier & SDHCI_INT_CARD_INT)) {
 			sdhci_enable_sdio_irq_nolock(host, false);
 			host->thread_isr |= SDHCI_INT_CARD_INT;
-			result = IRQ_WAKE_THREAD;
+			host->result = IRQ_WAKE_THREAD;
 		}
 
 		intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE |
@@ -3087,8 +3080,8 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 			sdhci_writel(host, intmask, SDHCI_INT_STATUS);
 		}
 cont:
-		if (result == IRQ_NONE)
-			result = IRQ_HANDLED;
+		if (host->result == IRQ_NONE)
+			host->result = IRQ_HANDLED;
 
 		intmask = sdhci_readl(host, SDHCI_INT_STATUS);
 	} while (intmask && --max_loops);
@@ -3101,7 +3094,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 		sdhci_dumpregs(host);
 	}
 
-	return result;
+	return host->result;
 }
 
 static irqreturn_t sdhci_thread_irq(int irq, void *dev_id)
@@ -3131,6 +3124,12 @@ static irqreturn_t sdhci_thread_irq(int irq, void *dev_id)
 		spin_unlock_irqrestore(&host->lock, flags);
 	}
 
+	if (!isr) {
+		do {
+			isr = !sdhci_request_done(host);
+		} while (isr);
+	}
+
 	return isr ? IRQ_HANDLED : IRQ_NONE;
 }
 
@@ -4212,12 +4211,6 @@ int __sdhci_add_host(struct sdhci_host *host)
 	struct mmc_host *mmc = host->mmc;
 	int ret;
 
-	/*
-	 * Init tasklets.
-	 */
-	tasklet_init(&host->finish_tasklet,
-		sdhci_tasklet_finish, (unsigned long)host);
-
 	timer_setup(&host->timer, sdhci_timeout_timer, 0);
 	timer_setup(&host->data_timer, sdhci_timeout_data_timer, 0);
 
@@ -4230,7 +4223,7 @@ int __sdhci_add_host(struct sdhci_host *host)
 	if (ret) {
 		pr_err("%s: Failed to request IRQ %d: %d\n",
 		       mmc_hostname(mmc), host->irq, ret);
-		goto untasklet;
+		return ret;
 	}
 
 	ret = sdhci_led_register(host);
@@ -4263,8 +4256,6 @@ int __sdhci_add_host(struct sdhci_host *host)
 	sdhci_writel(host, 0, SDHCI_INT_ENABLE);
 	sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE);
 	free_irq(host->irq, host);
-untasklet:
-	tasklet_kill(&host->finish_tasklet);
 
 	return ret;
 }
@@ -4326,8 +4317,6 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
 	del_timer_sync(&host->timer);
 	del_timer_sync(&host->data_timer);
 
-	tasklet_kill(&host->finish_tasklet);
-
 	if (!IS_ERR(mmc->supply.vqmmc))
 		regulator_disable(mmc->supply.vqmmc);
 
drivers/mmc/host/sdhci.h +1 -1
index 6cc9a3c2ac66..624d5aa01995 100644
@@ -554,7 +554,7 @@ struct sdhci_host {
 
 	unsigned int desc_sz;	/* ADMA descriptor size */
 
-	struct tasklet_struct finish_tasklet;	/* Tasklet structures */
+	irqreturn_t result;	/* Result of IRQ handler */
 
 	struct timer_list timer;	/* Timer for timeouts */
 	struct timer_list data_timer;	/* Timer for data timeouts */
Signature · 1 line
2.19.2
maintainer
#2 lore raw

Re: [PATCH v2 1/8] mmc: sdhci: Get rid of finish_tasklet

Quoted 7 lines · Faiz Abbas

sdhci.c has two bottom halves implemented. A threaded_irq for handling card insert/remove operations and a tasklet for finishing mmc requests. With the addition of external dma support, dmaengine APIs need to terminate in non-atomic context before unmapping the dma buffers.

To facilitate this, remove the finish_tasklet and move the call of sdhci_request_done() to the threaded_irq() callback.

The irq thread has a higher latency than the tasklet. The performance drop is measurable on the system I tried:

Before:

# dd if=/dev/mmcblk1 of=/dev/null bs=1G count=1 &
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 4.44502 s, 242 MB/s

After:

# dd if=/dev/mmcblk1 of=/dev/null bs=1G count=1 &
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 4.50898 s, 238 MB/s

So we only want to resort to the thread for the error case.

author
#3 lore raw

Re: [PATCH v2 1/8] mmc: sdhci: Get rid of finish_tasklet

Adrian,

Quoted 19 lines · Adrian Hunter
Quoted 7 lines · Faiz Abbas

sdhci.c has two bottom halves implemented. A threaded_irq for handling card insert/remove operations and a tasklet for finishing mmc requests. With the addition of external dma support, dmaengine APIs need to terminate in non-atomic context before unmapping the dma buffers.

To facilitate this, remove the finish_tasklet and move the call of sdhci_request_done() to the threaded_irq() callback.

The irq thread has a higher latency than the tasklet. The performance drop is measurable on the system I tried:

Before:

# dd if=/dev/mmcblk1 of=/dev/null bs=1G count=1 &
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 4.44502 s, 242 MB/s
Quoted 9 lines

After:

# dd if=/dev/mmcblk1 of=/dev/null bs=1G count=1 &
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 4.50898 s, 238 MB/s

So we only want to resort to the thread for the error case.

Sorry for the late response here, but this is about 1.6% decrease. I tried out the same commands on a dra7xx board here (with about 5 consecutive dd of 1GB) and the average decrease was 0.3%. I believe you will also find a lesser percentage change if you average over multiple dd commands.

Is this really so significant that we have to maintain two different bottom halves and keep having difficulty with adding APIs that can sleep?

Also I am not sure how to implement only the error handling part in the threaded_irq. We need to enter sdhci_request_done() and get the current mrq before we can check for error conditions like I've done in patch 2:

/* Terminate and synchronize dma in case of an error */ if (data && (mrq->cmd->error || data->error) &&

    host->use_external_dma) {
	struct dma_chan *chan = sdhci_external_dma_channel(host, data);
	dmaengine_terminate_sync(chan);
}

On a related note, do we really need to protect everything in sdhci_request_done() with spinlocks? In patch 2 I have only removed lock for the terminate_sync() parts that I added but the whole dma_unmap/dma_sync parts should be left unprotected IMO.

Thanks,
Faiz

maintainer
#4 lore raw

Re: [PATCH v2 1/8] mmc: sdhci: Get rid of finish_tasklet

Quoted 32 lines · Faiz Abbas

Adrian,

Quoted 19 lines · Adrian Hunter
Quoted 7 lines · Faiz Abbas

sdhci.c has two bottom halves implemented. A threaded_irq for handling card insert/remove operations and a tasklet for finishing mmc requests. With the addition of external dma support, dmaengine APIs need to terminate in non-atomic context before unmapping the dma buffers.

To facilitate this, remove the finish_tasklet and move the call of sdhci_request_done() to the threaded_irq() callback.

The irq thread has a higher latency than the tasklet. The performance drop is measurable on the system I tried:

Before:

# dd if=/dev/mmcblk1 of=/dev/null bs=1G count=1 &
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 4.44502 s, 242 MB/s
Quoted 9 lines

After:

# dd if=/dev/mmcblk1 of=/dev/null bs=1G count=1 &
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 4.50898 s, 238 MB/s

So we only want to resort to the thread for the error case.

Quoted 8 lines

Sorry for the late response here, but this is about 1.6% decrease. I tried out the same commands on a dra7xx board here (with about 5 consecutive dd of 1GB) and the average decrease was 0.3%. I believe you will also find a lesser percentage change if you average over multiple dd commands.

Is this really so significant that we have to maintain two different bottom halves and keep having difficulty with adding APIs that can sleep?

It is a performance drop that can be avoided, so it might as well be. Splitting the success path from the failure path is common for I/O drivers for similar reasons as here: the success path can be optimized whereas the failure path potentially needs to sleep.

Quoted 12 lines

Also I am not sure how to implement only the error handling part in the threaded_irq. We need to enter sdhci_request_done() and get the current mrq before we can check for error conditions like I've done in patch 2:

/* Terminate and synchronize dma in case of an error */ if (data && (mrq->cmd->error || data->error) &&

    host->use_external_dma) {
	struct dma_chan *chan = sdhci_external_dma_channel(host, data);
	dmaengine_terminate_sync(chan);
}
Quoted 5 lines

On a related note, do we really need to protect everything in sdhci_request_done() with spinlocks?
In patch 2 I have only removed lock
for the terminate_sync() parts that I added but the whole dma_unmap/dma_sync parts should be left unprotected IMO.

As it is written, synchronization is needed to stop the same mrq being finished twice.

I suggest doing the dmaengine_terminate_sync() before calling sdhci_request_done(). Perhaps you could record the channel that needs to be sync'd and then do:

	struct dma_chan *chan = READ_ONCE(host->sync_chan);

	if (chan) {
		dmaengine_terminate_sync(chan);
		host->sync_chan = NULL;
	}
#5 lore raw

Re: [PATCH v2 1/8] mmc: sdhci: Get rid of finish_tasklet

Hi Adrian,

Quoted 39 lines · Adrian Hunter
Quoted 38 lines · Faiz Abbas

Adrian,

Quoted 19 lines · Adrian Hunter
Quoted 7 lines · Faiz Abbas

sdhci.c has two bottom halves implemented. A threaded_irq for handling card insert/remove operations and a tasklet for finishing mmc requests. With the addition of external dma support, dmaengine APIs need to terminate in non-atomic context before unmapping the dma buffers.

To facilitate this, remove the finish_tasklet and move the call of sdhci_request_done() to the threaded_irq() callback.

The irq thread has a higher latency than the tasklet. The performance drop is measurable on the system I tried:

Before:

# dd if=/dev/mmcblk1 of=/dev/null bs=1G count=1 &
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 4.44502 s, 242 MB/s
Quoted 9 lines

After:

# dd if=/dev/mmcblk1 of=/dev/null bs=1G count=1 &
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 4.50898 s, 238 MB/s

So we only want to resort to the thread for the error case.

Sorry for the late response here, but this is about 1.6% decrease. I tried out the same commands on a dra7xx board here (with about 5 consecutive dd of 1GB) and the average decrease was 0.3%. I believe you will also find a lesser percentage change if you average over multiple dd commands.

Quoted 7 lines
Quoted 2 lines

Is this really so significant that we have to maintain two different bottom halves and keep having difficulty with adding APIs that can sleep?

It is a performance drop that can be avoided, so it might as well be. Splitting the success path from the failure path is common for I/O drivers for similar reasons as here: the success path can be optimized whereas the failure path potentially needs to sleep.

Understood. You wanna keep the success path as fast as possible.

Quoted 26 lines
Quoted 13 lines

Also I am not sure how to implement only the error handling part in the threaded_irq. We need to enter sdhci_request_done() and get the current mrq before we can check for error conditions like I've done in patch 2:

/* Terminate and synchronize dma in case of an error */ if (data && (mrq->cmd->error || data->error) &&

    host->use_external_dma) {
	struct dma_chan *chan = sdhci_external_dma_channel(host, data);
	dmaengine_terminate_sync(chan);
}
Quoted 5 lines

On a related note, do we really need to protect everything in sdhci_request_done() with spinlocks?
In patch 2 I have only removed lock
for the terminate_sync() parts that I added but the whole dma_unmap/dma_sync parts should be left unprotected IMO.

As it is written, synchronization is needed to stop the same mrq being finished twice.

I suggest doing the dmaengine_terminate_sync() before calling sdhci_request_done(). Perhaps you could record the channel that needs to be sync'd and then do:

Quoted 7 lines
	struct dma_chan *chan = READ_ONCE(host->sync_chan);

	if (chan) {
		dmaengine_terminate_sync(chan);
		host->sync_chan = NULL;
	}

Will try this out and send next version.

Thanks,
Faiz

#6 lore raw

Re: [PATCH v2 1/8] mmc: sdhci: Get rid of finish_tasklet

Quoted 45 lines · Mohammad Faiz Abbas

Hi Adrian,

Quoted 42 lines · Adrian Hunter
Quoted 40 lines · Faiz Abbas

Adrian,

Quoted 19 lines · Adrian Hunter
Quoted 7 lines · Faiz Abbas

sdhci.c has two bottom halves implemented. A threaded_irq for handling card insert/remove operations and a tasklet for finishing mmc requests. With the addition of external dma support, dmaengine APIs need to terminate in non-atomic context before unmapping the dma buffers.

To facilitate this, remove the finish_tasklet and move the call of sdhci_request_done() to the threaded_irq() callback.

The irq thread has a higher latency than the tasklet. The performance drop is measurable on the system I tried:

Before:

# dd if=/dev/mmcblk1 of=/dev/null bs=1G count=1 &
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 4.44502 s, 242 MB/s
Quoted 9 lines

After:

# dd if=/dev/mmcblk1 of=/dev/null bs=1G count=1 &
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 4.50898 s, 238 MB/s

So we only want to resort to the thread for the error case.

Sorry for the late response here, but this is about 1.6% decrease. I tried out the same commands on a dra7xx board here (with about 5 consecutive dd of 1GB) and the average decrease was 0.3%. I believe you will also find a lesser percentage change if you average over multiple dd commands.

Is this really so significant that we have to maintain two different bottom halves and keep having difficulty with adding APIs that can sleep?

Quoted 6 lines
Quoted 4 lines

It is a performance drop that can be avoided, so it might as well be. Splitting the success path from the failure path is common for I/O drivers for similar reasons as here: the success path can be optimized whereas the failure path potentially needs to sleep.

Understood. You wanna keep the success path as fast as possible.

Sry, I've not completely followed this series, but I'd like to add 5c

It's good thing to get rid of tasklets hence RT Linux kernel is actively moving towards to LKML and there everything handled in threads (even networking trying to get rid of softirqs).

Performance is pretty relative thing here - just try to run network traffic in parallel, and there are no control over it comparing to threads. Now way to assign priority or pin to CPU.

Signature · 2 lines
Best regards,
grygorii
author
#7 lore raw

Re: [PATCH v2 1/8] mmc: sdhci: Get rid of finish_tasklet

Hi,

Quoted 55 lines · Grygorii Strashko
Quoted 45 lines · Mohammad Faiz Abbas

Hi Adrian,

Quoted 42 lines · Adrian Hunter
Quoted 40 lines · Faiz Abbas

Adrian,

Quoted 19 lines · Adrian Hunter
Quoted 7 lines · Faiz Abbas

sdhci.c has two bottom halves implemented. A threaded_irq for handling card insert/remove operations and a tasklet for finishing mmc requests. With the addition of external dma support, dmaengine APIs need to terminate in non-atomic context before unmapping the dma buffers.

To facilitate this, remove the finish_tasklet and move the call of sdhci_request_done() to the threaded_irq() callback.

The irq thread has a higher latency than the tasklet. The performance drop is measurable on the system I tried:

Before:

# dd if=/dev/mmcblk1 of=/dev/null bs=1G count=1 &
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 4.44502 s, 242 MB/s
Quoted 9 lines

After:

# dd if=/dev/mmcblk1 of=/dev/null bs=1G count=1 &
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 4.50898 s, 238 MB/s

So we only want to resort to the thread for the error case.

Sorry for the late response here, but this is about 1.6% decrease. I tried out the same commands on a dra7xx board here (with about 5 consecutive dd of 1GB) and the average decrease was 0.3%. I believe you will also find a lesser percentage change if you average over multiple dd commands.

Is this really so significant that we have to maintain two different bottom halves and keep having difficulty with adding APIs that can sleep?

Quoted 6 lines
Quoted 4 lines

It is a performance drop that can be avoided, so it might as well be. Splitting the success path from the failure path is common for I/O drivers for similar reasons as here: the success path can be optimized whereas the failure path potentially needs to sleep.

Understood. You wanna keep the success path as fast as possible.

Quoted 7 lines

Sry, I've not completely followed this series, but I'd like to add 5c

It's good thing to get rid of tasklets hence RT Linux kernel is actively moving towards to LKML and there everything handled in threads (even networking trying to get rid of softirqs).

Performance is pretty relative thing here - just try to run network traffic in parallel, and there are no control over it comparing to threads. Now way to assign priority or pin to CPU.

There is a 2007 LWN article(https://lwn.net/Articles/239633/) which talks about removing tasklets altogether. I wonder what happened after that.

Thanks,
Faiz

#8 lore raw

Re: [PATCH v2 1/8] mmc: sdhci: Get rid of finish_tasklet

In reply to Rizvi, Mohammad Faiz Abbas
Quoted 8 lines · Mohammad Faiz Abbas
Quoted 5 lines · Adrian Hunter

On 6/03/19 12:00 PM, Faiz Abbas wrote:
It is a performance drop that can be avoided, so it might as well be. Splitting the success path from the failure path is common for I/O drivers for similar reasons as here: the success path can be optimized whereas the failure path potentially needs to sleep.

Understood. You wanna keep the success path as fast as possible.

I looked at the sdhci_request_done() function and found that almost all of it is executed inside of a 'spin_lock_irqsave()', including the potentially expensive dma_sync_single_for_cpu() calls.

This means there is very little benefit in using the tasklet in the first place, it could just as well run in the hwirq context that triggered it.

The part that is actually run with interrupts enabled in the tasklet is mmc_blk_cqe_req_done(), but other drivers also call this from IRQ context.

Arnd

#9 lore raw

Re: [PATCH v2 1/8] mmc: sdhci: Get rid of finish_tasklet

In reply to Faiz Abbas

+ Arnd, Grygorii

Quoted 6 lines · Faiz Abbas

sdhci.c has two bottom halves implemented. A threaded_irq for handling card insert/remove operations and a tasklet for finishing mmc requests. With the addition of external dma support, dmaengine APIs need to terminate in non-atomic context before unmapping the dma buffers.

Quoted 6 lines

To facilitate this, remove the finish_tasklet and move the call of sdhci_request_done() to the threaded_irq() callback. Also move the interrupt result variable to sdhci_host so it can be populated from anywhere inside the sdhci_irq handler.

Adrian, I think it makes sense to apply this patch, even if there is very minor negative impact throughput wise.

To me, it doesn't seems like MMC/SD/SDIO has good justification for using tasklets, besides from the legacy point of view, of course. Instead, I think we should try to move all mmc hosts into using threaded IRQs.

So, what do you think? Can you overlook the throughput drop and instead we can try to recover this on top with other optimizations?

Kind regards
Uffe

Quoted 163 lines
---
 drivers/mmc/host/sdhci.c | 43 +++++++++++++++-------------------------
 drivers/mmc/host/sdhci.h |  2 +-
 2 files changed, 17 insertions(+), 28 deletions(-)
drivers/mmc/host/sdhci.c +16 -27
index eba9bcc92ad3..20ed09b896d7 100644
@@ -1232,7 +1232,7 @@ static void __sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq)
 
        WARN_ON(i >= SDHCI_MAX_MRQS);
 
-       tasklet_schedule(&host->finish_tasklet);
+       host->result = IRQ_WAKE_THREAD;
 }
 
 static void sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq)
@@ -2705,14 +2705,6 @@ static bool sdhci_request_done(struct sdhci_host *host)
        return false;
 }
 
-static void sdhci_tasklet_finish(unsigned long param)
-{
-       struct sdhci_host *host = (struct sdhci_host *)param;
-
-       while (!sdhci_request_done(host))
-               ;
-}
-
 static void sdhci_timeout_timer(struct timer_list *t)
 {
        struct sdhci_host *host;
@@ -2995,11 +2987,12 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
 
 static irqreturn_t sdhci_irq(int irq, void *dev_id)
 {
-       irqreturn_t result = IRQ_NONE;
        struct sdhci_host *host = dev_id;
        u32 intmask, mask, unexpected = 0;
        int max_loops = 16;
 
+       host->result = IRQ_NONE;
+
        spin_lock(&host->lock);
 
        if (host->runtime_suspended && !sdhci_sdio_irq_enabled(host)) {
@@ -3009,7 +3002,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 
        intmask = sdhci_readl(host, SDHCI_INT_STATUS);
        if (!intmask || intmask == 0xffffffff) {
-               result = IRQ_NONE;
+               host->result = IRQ_NONE;
                goto out;
        }
 
@@ -3054,7 +3047,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 
                        host->thread_isr |= intmask & (SDHCI_INT_CARD_INSERT |
                                                       SDHCI_INT_CARD_REMOVE);
-                       result = IRQ_WAKE_THREAD;
+                       host->result = IRQ_WAKE_THREAD;
                }
 
                if (intmask & SDHCI_INT_CMD_MASK)
@@ -3074,7 +3067,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
                    (host->ier & SDHCI_INT_CARD_INT)) {
                        sdhci_enable_sdio_irq_nolock(host, false);
                        host->thread_isr |= SDHCI_INT_CARD_INT;
-                       result = IRQ_WAKE_THREAD;
+                       host->result = IRQ_WAKE_THREAD;
                }
 
                intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE |
@@ -3087,8 +3080,8 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
                        sdhci_writel(host, intmask, SDHCI_INT_STATUS);
                }
 cont:
-               if (result == IRQ_NONE)
-                       result = IRQ_HANDLED;
+               if (host->result == IRQ_NONE)
+                       host->result = IRQ_HANDLED;
 
                intmask = sdhci_readl(host, SDHCI_INT_STATUS);
        } while (intmask && --max_loops);
@@ -3101,7 +3094,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
                sdhci_dumpregs(host);
        }
 
-       return result;
+       return host->result;
 }
 
 static irqreturn_t sdhci_thread_irq(int irq, void *dev_id)
@@ -3131,6 +3124,12 @@ static irqreturn_t sdhci_thread_irq(int irq, void *dev_id)
                spin_unlock_irqrestore(&host->lock, flags);
        }
 
+       if (!isr) {
+               do {
+                       isr = !sdhci_request_done(host);
+               } while (isr);
+       }
+
        return isr ? IRQ_HANDLED : IRQ_NONE;
 }
 
@@ -4212,12 +4211,6 @@ int __sdhci_add_host(struct sdhci_host *host)
        struct mmc_host *mmc = host->mmc;
        int ret;
 
-       /*
-        * Init tasklets.
-        */
-       tasklet_init(&host->finish_tasklet,
-               sdhci_tasklet_finish, (unsigned long)host);
-
        timer_setup(&host->timer, sdhci_timeout_timer, 0);
        timer_setup(&host->data_timer, sdhci_timeout_data_timer, 0);
 
@@ -4230,7 +4223,7 @@ int __sdhci_add_host(struct sdhci_host *host)
        if (ret) {
                pr_err("%s: Failed to request IRQ %d: %d\n",
                       mmc_hostname(mmc), host->irq, ret);
-               goto untasklet;
+               return ret;
        }
 
        ret = sdhci_led_register(host);
@@ -4263,8 +4256,6 @@ int __sdhci_add_host(struct sdhci_host *host)
        sdhci_writel(host, 0, SDHCI_INT_ENABLE);
        sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE);
        free_irq(host->irq, host);
-untasklet:
-       tasklet_kill(&host->finish_tasklet);
 
        return ret;
 }
@@ -4326,8 +4317,6 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
        del_timer_sync(&host->timer);
        del_timer_sync(&host->data_timer);
 
-       tasklet_kill(&host->finish_tasklet);
-
        if (!IS_ERR(mmc->supply.vqmmc))
                regulator_disable(mmc->supply.vqmmc);
 
drivers/mmc/host/sdhci.h +1 -2
index 6cc9a3c2ac66..624d5aa01995 100644
@@ -554,7 +554,7 @@ struct sdhci_host {
 
        unsigned int desc_sz;   /* ADMA descriptor size */
 
-       struct tasklet_struct finish_tasklet;   /* Tasklet structures */
+       irqreturn_t result;     /* Result of IRQ handler */
 
        struct timer_list timer;        /* Timer for timeouts */
        struct timer_list data_timer;   /* Timer for data timeouts */
--

2.19.2

maintainer
#10 lore raw

Re: [PATCH v2 1/8] mmc: sdhci: Get rid of finish_tasklet

Quoted 19 lines · Ulf Hansson

+ Arnd, Grygorii

Quoted 6 lines · Faiz Abbas

sdhci.c has two bottom halves implemented. A threaded_irq for handling card insert/remove operations and a tasklet for finishing mmc requests. With the addition of external dma support, dmaengine APIs need to terminate in non-atomic context before unmapping the dma buffers.

Quoted 6 lines

To facilitate this, remove the finish_tasklet and move the call of sdhci_request_done() to the threaded_irq() callback. Also move the interrupt result variable to sdhci_host so it can be populated from anywhere inside the sdhci_irq handler.

Adrian, I think it makes sense to apply this patch, even if there is very minor negative impact throughput wise.

Quoted 7 lines

To me, it doesn't seems like MMC/SD/SDIO has good justification for using tasklets, besides from the legacy point of view, of course. Instead, I think we should try to move all mmc hosts into using threaded IRQs.

So, what do you think? Can you overlook the throughput drop and instead we can try to recover this on top with other optimizations?

I tend to favour good results as expressed here:

	https://lkml.org/lkml/2007/6/22/360

So I want to do optimization first.

But performance is not the only problem with the patch. Give me a few days and I will see what I can come up with.

Quoted 168 lines

Kind regards
Uffe

Quoted 163 lines
---
 drivers/mmc/host/sdhci.c | 43 +++++++++++++++-------------------------
 drivers/mmc/host/sdhci.h |  2 +-
 2 files changed, 17 insertions(+), 28 deletions(-)
drivers/mmc/host/sdhci.c +16 -27
index eba9bcc92ad3..20ed09b896d7 100644
@@ -1232,7 +1232,7 @@ static void __sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq)
 
        WARN_ON(i >= SDHCI_MAX_MRQS);
 
-       tasklet_schedule(&host->finish_tasklet);
+       host->result = IRQ_WAKE_THREAD;
 }
 
 static void sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq)
@@ -2705,14 +2705,6 @@ static bool sdhci_request_done(struct sdhci_host *host)
        return false;
 }
 
-static void sdhci_tasklet_finish(unsigned long param)
-{
-       struct sdhci_host *host = (struct sdhci_host *)param;
-
-       while (!sdhci_request_done(host))
-               ;
-}
-
 static void sdhci_timeout_timer(struct timer_list *t)
 {
        struct sdhci_host *host;
@@ -2995,11 +2987,12 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
 
 static irqreturn_t sdhci_irq(int irq, void *dev_id)
 {
-       irqreturn_t result = IRQ_NONE;
        struct sdhci_host *host = dev_id;
        u32 intmask, mask, unexpected = 0;
        int max_loops = 16;
 
+       host->result = IRQ_NONE;
+
        spin_lock(&host->lock);
 
        if (host->runtime_suspended && !sdhci_sdio_irq_enabled(host)) {
@@ -3009,7 +3002,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 
        intmask = sdhci_readl(host, SDHCI_INT_STATUS);
        if (!intmask || intmask == 0xffffffff) {
-               result = IRQ_NONE;
+               host->result = IRQ_NONE;
                goto out;
        }
 
@@ -3054,7 +3047,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 
                        host->thread_isr |= intmask & (SDHCI_INT_CARD_INSERT |
                                                       SDHCI_INT_CARD_REMOVE);
-                       result = IRQ_WAKE_THREAD;
+                       host->result = IRQ_WAKE_THREAD;
                }
 
                if (intmask & SDHCI_INT_CMD_MASK)
@@ -3074,7 +3067,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
                    (host->ier & SDHCI_INT_CARD_INT)) {
                        sdhci_enable_sdio_irq_nolock(host, false);
                        host->thread_isr |= SDHCI_INT_CARD_INT;
-                       result = IRQ_WAKE_THREAD;
+                       host->result = IRQ_WAKE_THREAD;
                }
 
                intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE |
@@ -3087,8 +3080,8 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
                        sdhci_writel(host, intmask, SDHCI_INT_STATUS);
                }
 cont:
-               if (result == IRQ_NONE)
-                       result = IRQ_HANDLED;
+               if (host->result == IRQ_NONE)
+                       host->result = IRQ_HANDLED;
 
                intmask = sdhci_readl(host, SDHCI_INT_STATUS);
        } while (intmask && --max_loops);
@@ -3101,7 +3094,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
                sdhci_dumpregs(host);
        }
 
-       return result;
+       return host->result;
 }
 
 static irqreturn_t sdhci_thread_irq(int irq, void *dev_id)
@@ -3131,6 +3124,12 @@ static irqreturn_t sdhci_thread_irq(int irq, void *dev_id)
                spin_unlock_irqrestore(&host->lock, flags);
        }
 
+       if (!isr) {
+               do {
+                       isr = !sdhci_request_done(host);
+               } while (isr);
+       }
+
        return isr ? IRQ_HANDLED : IRQ_NONE;
 }
 
@@ -4212,12 +4211,6 @@ int __sdhci_add_host(struct sdhci_host *host)
        struct mmc_host *mmc = host->mmc;
        int ret;
 
-       /*
-        * Init tasklets.
-        */
-       tasklet_init(&host->finish_tasklet,
-               sdhci_tasklet_finish, (unsigned long)host);
-
        timer_setup(&host->timer, sdhci_timeout_timer, 0);
        timer_setup(&host->data_timer, sdhci_timeout_data_timer, 0);
 
@@ -4230,7 +4223,7 @@ int __sdhci_add_host(struct sdhci_host *host)
        if (ret) {
                pr_err("%s: Failed to request IRQ %d: %d\n",
                       mmc_hostname(mmc), host->irq, ret);
-               goto untasklet;
+               return ret;
        }
 
        ret = sdhci_led_register(host);
@@ -4263,8 +4256,6 @@ int __sdhci_add_host(struct sdhci_host *host)
        sdhci_writel(host, 0, SDHCI_INT_ENABLE);
        sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE);
        free_irq(host->irq, host);
-untasklet:
-       tasklet_kill(&host->finish_tasklet);
 
        return ret;
 }
@@ -4326,8 +4317,6 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
        del_timer_sync(&host->timer);
        del_timer_sync(&host->data_timer);
 
-       tasklet_kill(&host->finish_tasklet);
-
        if (!IS_ERR(mmc->supply.vqmmc))
                regulator_disable(mmc->supply.vqmmc);
 
drivers/mmc/host/sdhci.h +1 -2
index 6cc9a3c2ac66..624d5aa01995 100644
@@ -554,7 +554,7 @@ struct sdhci_host {
 
        unsigned int desc_sz;   /* ADMA descriptor size */
 
-       struct tasklet_struct finish_tasklet;   /* Tasklet structures */
+       irqreturn_t result;     /* Result of IRQ handler */
 
        struct timer_list timer;        /* Timer for timeouts */
        struct timer_list data_timer;   /* Timer for data timeouts */
--

2.19.2

author
#11 lore raw

Re: [PATCH v2 1/8] mmc: sdhci: Get rid of finish_tasklet

Hi Adrian,

Quoted 28 lines · Adrian Hunter
Quoted 19 lines · Ulf Hansson

+ Arnd, Grygorii

Quoted 6 lines · Faiz Abbas

sdhci.c has two bottom halves implemented. A threaded_irq for handling card insert/remove operations and a tasklet for finishing mmc requests. With the addition of external dma support, dmaengine APIs need to terminate in non-atomic context before unmapping the dma buffers.

Quoted 6 lines

To facilitate this, remove the finish_tasklet and move the call of sdhci_request_done() to the threaded_irq() callback. Also move the interrupt result variable to sdhci_host so it can be populated from anywhere inside the sdhci_irq handler.

Adrian, I think it makes sense to apply this patch, even if there is very minor negative impact throughput wise.

Quoted 7 lines

To me, it doesn't seems like MMC/SD/SDIO has good justification for using tasklets, besides from the legacy point of view, of course. Instead, I think we should try to move all mmc hosts into using threaded IRQs.

So, what do you think? Can you overlook the throughput drop and instead we can try to recover this on top with other optimizations?

Quoted 9 lines

I tend to favour good results as expressed here:

	https://lkml.org/lkml/2007/6/22/360

So I want to do optimization first.

But performance is not the only problem with the patch. Give me a few days and I will see what I can come up with.

Gentle ping on this.

Thanks,
Faiz

maintainer
#12 lore raw

Re: [PATCH v2 1/8] mmc: sdhci: Get rid of finish_tasklet

Quoted 35 lines · Faiz Abbas

Hi Adrian,

Quoted 32 lines · Adrian Hunter
Quoted 19 lines · Ulf Hansson

+ Arnd, Grygorii

Quoted 6 lines · Faiz Abbas

sdhci.c has two bottom halves implemented. A threaded_irq for handling card insert/remove operations and a tasklet for finishing mmc requests. With the addition of external dma support, dmaengine APIs need to terminate in non-atomic context before unmapping the dma buffers.

Quoted 6 lines

To facilitate this, remove the finish_tasklet and move the call of sdhci_request_done() to the threaded_irq() callback. Also move the interrupt result variable to sdhci_host so it can be populated from anywhere inside the sdhci_irq handler.

Adrian, I think it makes sense to apply this patch, even if there is very minor negative impact throughput wise.

Quoted 7 lines

To me, it doesn't seems like MMC/SD/SDIO has good justification for using tasklets, besides from the legacy point of view, of course. Instead, I think we should try to move all mmc hosts into using threaded IRQs.

So, what do you think? Can you overlook the throughput drop and instead we can try to recover this on top with other optimizations?

I tend to favour good results as expressed here:

	https://lkml.org/lkml/2007/6/22/360
Quoted 7 lines
Quoted 5 lines

So I want to do optimization first.

But performance is not the only problem with the patch. Give me a few days and I will see what I can come up with.

Gentle ping on this.

Working on it :-)

author
#13 lore raw

PATCH v2 2/8 mmc: sdhci: add support for using external DMA devices

In reply to Faiz Abbas

From: Chunyan Zhang <[email protected]>

Some standard SD host controllers can support both external dma controllers as well as ADMA/SDMA in which the SD host controller acts as DMA master. TI's omap controller is the case as an example.

Currently the generic SDHCI code supports ADMA/SDMA integrated in the host controller but does not have any support for external DMA controllers implemented using dmaengine, meaning that custom code is needed for any systems that use an external DMA controller with SDHCI.

Fixes by Faiz Abbas <[email protected]>:
1. Map scatterlists before dmaengine_prep_slave_sg()
2. Use dma_async() functions inside of the send_command() path and call terminate_sync() in non-atomic context in case of an error.

---
 drivers/mmc/host/Kconfig |   3 +
 drivers/mmc/host/sdhci.c | 285 +++++++++++++++++++++++++++++++++++----
 drivers/mmc/host/sdhci.h |   8 ++
 3 files changed, 268 insertions(+), 28 deletions(-)
drivers/mmc/host/Kconfig +3 -0
index a44ec8bb5418..f3b442528ed8 100644
@@ -999,3 +999,6 @@ config MMC_SDHCI_AM654
 	  If you have a controller with this interface, say Y or M here.
 
 	  If unsure, say N.
+
+config MMC_SDHCI_EXTERNAL_DMA
+        bool
drivers/mmc/host/sdhci.c +257 -28

371 lines not on this page · raw message

drivers/mmc/host/sdhci.h +8 -0
index 624d5aa01995..6ff3e29791ee 100644
@@ -482,6 +482,7 @@ struct sdhci_host {
 
 	int irq;		/* Device IRQ */
 	void __iomem *ioaddr;	/* Mapped address */
+	phys_addr_t mapbase;	/* physical address base */
 	char *bounce_buffer;	/* For packing SDMA reads/writes */
 	dma_addr_t bounce_addr;
 	unsigned int bounce_buffer_size;
@@ -531,6 +532,7 @@ struct sdhci_host {
 	bool pending_reset;	/* Cmd/data reset is pending */
 	bool irq_wake_enabled;	/* IRQ wakeup is enabled */
 	bool v4_mode;		/* Host Version 4 Enable */
+	bool use_external_dma;	/* Host selects to use external DMA */
 
 	struct mmc_request *mrqs_done[SDHCI_MAX_MRQS];	/* Requests done */
 	struct mmc_command *cmd;	/* Current command */
@@ -559,6 +561,11 @@ struct sdhci_host {
 	struct timer_list timer;	/* Timer for timeouts */
 	struct timer_list data_timer;	/* Timer for data timeouts */
 
+#if IS_ENABLED(CONFIG_MMC_SDHCI_EXTERNAL_DMA)
+	struct dma_chan	*rx_chan;
+	struct dma_chan	*tx_chan;
+#endif
+
 	u32 caps;		/* CAPABILITY_0 */
 	u32 caps1;		/* CAPABILITY_1 */
 	bool read_caps;		/* Capability flags have been read */
@@ -792,5 +799,6 @@ void sdhci_start_tuning(struct sdhci_host *host);
 void sdhci_end_tuning(struct sdhci_host *host);
 void sdhci_reset_tuning(struct sdhci_host *host);
 void sdhci_send_tuning(struct sdhci_host *host, u32 opcode);
+void sdhci_switch_external_dma(struct sdhci_host *host, bool en);
 
 #endif /* __SDHCI_HW_H */
Signature · 1 line
2.19.2
author
#14 lore raw

PATCH v2 3/8 dt-bindings: sdhci-omap: Add properties for using external dma

In reply to Faiz Abbas

From: Chunyan Zhang <[email protected]>

sdhci-omap can support both external dma controller via dmaengine framework as well as ADMA which standard SD host controller provides.

---
 Documentation/devicetree/bindings/mmc/sdhci-omap.txt | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/mmc/sdhci-omap.txt +7 -0
index 72c4dec7e1db..4485dbceb373 100644
@@ -14,6 +14,11 @@ Required properties:
 		 "ddr_1_8v-rev11", "ddr_1_8v" or "ddr_3_3v", "hs200_1_8v-rev11",
 		 "hs200_1_8v",
 - pinctrl-<n> : Pinctrl states as described in bindings/pinctrl/pinctrl-bindings.txt
+- dmas:		List of DMA specifiers with the controller specific format as described
+		in the generic DMA client binding. A tx and rx specifier is required.
+- dma-names:	List of DMA request names. These strings correspond 1:1 with the
+		DMA specifiers listed in dmas. The string naming is to be "tx"
+		and "rx" for TX and RX DMA requests, respectively.
 
 Example:
 	mmc1: mmc@4809c000 {
@@ -22,4 +27,6 @@ Example:
 		ti,hwmods = "mmc1";
 		bus-width = <4>;
 		vmmc-supply = <&vmmc>; /* phandle to regulator node */
+		dmas = <&sdma 61 &sdma 62>;
+		dma-names = "tx", "rx";
 	};
Signature · 1 line
2.19.2
#15 lore raw

Re: [PATCH v2 3/8] dt-bindings: sdhci-omap: Add properties for using external dma

Quoted 5 lines · Faiz Abbas

From: Chunyan Zhang <[email protected]>

sdhci-omap can support both external dma controller via dmaengine framework as well as ADMA which standard SD host controller provides.

Care to describe here also how to configure things for ADMA and instead of DMA? Just leave out dmas property?

Regards,

Tony

author
#16 lore raw

Re: [PATCH v2 3/8] dt-bindings: sdhci-omap: Add properties for using external dma

Hi Tony,

Quoted 10 lines · Tony Lindgren
Quoted 5 lines · Faiz Abbas

From: Chunyan Zhang <[email protected]>

sdhci-omap can support both external dma controller via dmaengine framework as well as ADMA which standard SD host controller provides.

Care to describe here also how to configure things for ADMA and instead of DMA? Just leave out dmas property?

That's correct. If dmas property is populated, then use external DMA. Otherwise use ADMA/SDMA depending on what you read from the CAPS register.

Thanks,
Faiz

#17 lore raw

Re: [PATCH v2 3/8] dt-bindings: sdhci-omap: Add properties for using external dma

Quoted 10 lines · Faiz Abbas

Hi Tony,

Quoted 7 lines · Tony Lindgren
Quoted 5 lines · Faiz Abbas

From: Chunyan Zhang <[email protected]>

sdhci-omap can support both external dma controller via dmaengine framework as well as ADMA which standard SD host controller provides.

Quoted 5 lines
Quoted 3 lines

Care to describe here also how to configure things for ADMA and instead of DMA? Just leave out dmas property?

That's correct. If dmas property is populated, then use external DMA. Otherwise use ADMA/SDMA depending on what you read from the CAPS register.

OK thanks.

Tony

#18 lore raw

Re: [PATCH v2 3/8] dt-bindings: sdhci-omap: Add properties for using external dma

Quoted 11 lines · Tony Lindgren
Quoted 10 lines · Faiz Abbas

Hi Tony,

Quoted 7 lines · Tony Lindgren
Quoted 5 lines · Faiz Abbas

From: Chunyan Zhang <[email protected]>

sdhci-omap can support both external dma controller via dmaengine framework as well as ADMA which standard SD host controller provides.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Care to describe here also how to configure things for ADMA and instead of DMA? Just leave out dmas property?

That's correct. If dmas property is populated, then use external DMA. Otherwise use ADMA/SDMA depending on what you read from the CAPS register.

OK thanks.

So I guess the dma properties should be under optional properties in the binding doc then.

Regards,

Tony

maintainer
#19 lore raw

Re: [PATCH v2 3/8] dt-bindings: sdhci-omap: Add properties for using external dma

In reply to Faiz Abbas
Quoted 10 lines · Faiz Abbas

Hi Tony,

Quoted 7 lines · Tony Lindgren
Quoted 5 lines · Faiz Abbas

From: Chunyan Zhang <[email protected]>

sdhci-omap can support both external dma controller via dmaengine framework as well as ADMA which standard SD host controller provides.

Quoted 6 lines
Quoted 3 lines

Care to describe here also how to configure things for ADMA and instead of DMA? Just leave out dmas property?

That's correct. If dmas property is populated, then use external DMA. Otherwise use ADMA/SDMA depending on what you read from the CAPS register.

Then the properties should be optional.

Rob

author
#20 lore raw

Re: [PATCH v2 3/8] dt-bindings: sdhci-omap: Add properties for using external dma

Hi Rob,

Quoted 11 lines · Rob Herring
Quoted 10 lines · Faiz Abbas

Hi Tony,

Quoted 7 lines · Tony Lindgren
Quoted 5 lines · Faiz Abbas

From: Chunyan Zhang <[email protected]>

sdhci-omap can support both external dma controller via dmaengine framework as well as ADMA which standard SD host controller provides.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

Care to describe here also how to configure things for ADMA and instead of DMA? Just leave out dmas property?

That's correct. If dmas property is populated, then use external DMA. Otherwise use ADMA/SDMA depending on what you read from the CAPS register.

Then the properties should be optional.

Will move it to optional in v3.

Thanks,
Faiz

author
#21 lore raw

PATCH v2 4/8 mmc: sdhci-omap: Add using external dma

In reply to Faiz Abbas

From: Chunyan Zhang <[email protected]>

sdhci-omap can support both external dma controller via dmaengine framework as well as ADMA which standard SD host controller provides.

Fixes by Faiz Abbas <[email protected]>:
1. Switch to DMA slave mode when using external DMA
2. Add offset to mapbase

---
 drivers/mmc/host/Kconfig      |  1 +
 drivers/mmc/host/sdhci-omap.c | 16 +++++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
drivers/mmc/host/Kconfig +1 -0
index f3b442528ed8..5d1189478ee0 100644
@@ -979,6 +979,7 @@ config MMC_SDHCI_OMAP
 	depends on MMC_SDHCI_PLTFM && OF
 	select THERMAL
 	imply TI_SOC_THERMAL
+	select MMC_SDHCI_EXTERNAL_DMA if DMA_ENGINE
 	help
 	  This selects the Secure Digital Host Controller Interface (SDHCI)
 	  support present in TI's DRA7 SOCs. The controller supports
drivers/mmc/host/sdhci-omap.c +15 -1
index c11c18a9aacb..8a05e94fe612 100644
@@ -696,7 +696,11 @@ static int sdhci_omap_enable_dma(struct sdhci_host *host)
 	struct sdhci_omap_host *omap_host = sdhci_pltfm_priv(pltfm_host);
 
 	reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CON);
-	reg |= CON_DMA_MASTER;
+	reg &= ~CON_DMA_MASTER;
+	/* Switch to DMA slave mode when using external DMA */
+	if (!host->use_external_dma)
+		reg |= CON_DMA_MASTER;
+
 	sdhci_omap_writel(omap_host, SDHCI_OMAP_CON, reg);
 
 	return 0;
@@ -1010,6 +1014,7 @@ static int sdhci_omap_probe(struct platform_device *pdev)
 	const struct of_device_id *match;
 	struct sdhci_omap_data *data;
 	const struct soc_device_attribute *soc;
+	struct resource *regs;
 
 	match = of_match_device(omap_sdhci_match, dev);
 	if (!match)
@@ -1022,6 +1027,10 @@ static int sdhci_omap_probe(struct platform_device *pdev)
 	}
 	offset = data->offset;
 
+	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!regs)
+		return -ENXIO;
+
 	host = sdhci_pltfm_init(pdev, &sdhci_omap_pdata,
 				sizeof(*omap_host));
 	if (IS_ERR(host)) {
@@ -1038,6 +1047,7 @@ static int sdhci_omap_probe(struct platform_device *pdev)
 	omap_host->timing = MMC_TIMING_LEGACY;
 	omap_host->flags = data->flags;
 	host->ioaddr += offset;
+	host->mapbase = regs->start + offset;
 
 	mmc = host->mmc;
 	sdhci_get_of_property(pdev);
@@ -1105,6 +1115,10 @@ static int sdhci_omap_probe(struct platform_device *pdev)
 	host->mmc_host_ops.execute_tuning = sdhci_omap_execute_tuning;
 	host->mmc_host_ops.enable_sdio_irq = sdhci_omap_enable_sdio_irq;
 
+	/* Switch to external DMA only if there is the "dmas" property */
+	if (of_find_property(dev->of_node, "dmas", NULL))
+		sdhci_switch_external_dma(host, true);
+
 	ret = sdhci_setup_host(host);
 	if (ret)
 		goto err_put_sync;
Signature · 1 line
2.19.2
author
#22 lore raw

PATCH v2 5/8 mmc: sdhci: Add quirk for disabling DTO during erase command

In reply to Faiz Abbas

Some controllers might prematurely issue a data timeout during an erase command. Add a quirk to disable the interrupt when an erase command is issued.

---
 drivers/mmc/host/sdhci.c | 5 +++++
 drivers/mmc/host/sdhci.h | 2 ++
 2 files changed, 7 insertions(+)
drivers/mmc/host/sdhci.c +5 -0
index 2f5f64efad16..608f7306742c 100644
@@ -1522,6 +1522,11 @@ void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
 	/* Initially, a command has no error */
 	cmd->error = 0;
 
+	if (cmd->opcode == MMC_ERASE &&
+	    (host->quirks2 & SDHCI_QUIRK2_DISABLE_DTO_FOR_ERASE)) {
+		sdhci_set_data_timeout_irq(host, false);
+	}
+
 	if ((host->quirks2 & SDHCI_QUIRK2_STOP_WITH_TC) &&
 	    cmd->opcode == MMC_STOP_TRANSMISSION)
 		cmd->flags |= MMC_RSP_BUSY;
drivers/mmc/host/sdhci.h +2 -0
index 6ff3e29791ee..60282721f827 100644
@@ -479,6 +479,8 @@ struct sdhci_host {
  * block count.
  */
 #define SDHCI_QUIRK2_USE_32BIT_BLK_CNT			(1<<18)
+/* Controller needs to disable DTO for erase command */
+#define SDHCI_QUIRK2_DISABLE_DTO_FOR_ERASE		(1<<19)
 
 	int irq;		/* Device IRQ */
 	void __iomem *ioaddr;	/* Mapped address */
Signature · 1 line
2.19.2
author
#23 lore raw

PATCH v2 6/8 mmc: sdhci-omap: Add DISABLE_DTO_FOR_ERASE Quirk

In reply to Faiz Abbas

Add a Quirk to disable DTO during an erase command.

---
 drivers/mmc/host/sdhci-omap.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mmc/host/sdhci-omap.c +1 -0
index 8a05e94fe612..ae9701d198d5 100644
@@ -852,6 +852,7 @@ static const struct sdhci_pltfm_data sdhci_omap_pdata = {
 	.quirks2 = SDHCI_QUIRK2_ACMD23_BROKEN |
 		   SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
 		   SDHCI_QUIRK2_RSP_136_HAS_CRC |
+		   SDHCI_QUIRK2_DISABLE_DTO_FOR_ERASE |
 		   SDHCI_QUIRK2_DISABLE_HW_TIMEOUT,
 	.ops = &sdhci_omap_ops,
 };
Signature · 1 line
2.19.2
author
#24 lore raw

PATCH v2 7/8 dt-bindings: sdhci-omap: Add am335x and am437x specific bindings

In reply to Faiz Abbas

Add binding for the TI's sdhci-omap controller present in am335x and am437x devices.

---
 Documentation/devicetree/bindings/mmc/sdhci-omap.txt | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/mmc/sdhci-omap.txt +2 -0
index 4485dbceb373..859291e83964 100644
@@ -7,6 +7,8 @@ For UHS devices which require tuning, the device tree should have a "cpu_thermal
 Required properties:
 - compatible: Should be "ti,dra7-sdhci" for DRA7 and DRA72 controllers
 	      Should be "ti,k2g-sdhci" for K2G
+	      Should be "ti,am335-sdhci" for am335x controllers
+	      Should be "ti,am437-sdhci" for am437x controllers
 - ti,hwmods: Must be "mmc<n>", <n> is controller instance starting 1
 	     (Not required for K2G).
 - pinctrl-names: Should be subset of "default", "hs", "sdr12", "sdr25", "sdr50",
Signature · 1 line
2.19.2
author
#25 lore raw

PATCH v2 8/8 mmc: sdhci-omap: Add am335x and am437x specific compatibles

In reply to Faiz Abbas

Add support for new compatible for TI's am335x and am437x devices.

---
 drivers/mmc/host/sdhci-omap.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/mmc/host/sdhci-omap.c +10 -0
index ae9701d198d5..2e246b5b744c 100644
@@ -861,6 +861,14 @@ static const struct sdhci_omap_data k2g_data = {
 	.offset = 0x200,
 };
 
+static const struct sdhci_omap_data am335_data = {
+	.offset = 0x200,
+};
+
+static const struct sdhci_omap_data am437_data = {
+	.offset = 0x200,
+};
+
 static const struct sdhci_omap_data dra7_data = {
 	.offset = 0x200,
 	.flags	= SDHCI_OMAP_REQUIRE_IODELAY,
@@ -869,6 +877,8 @@ static const struct sdhci_omap_data dra7_data = {
 static const struct of_device_id omap_sdhci_match[] = {
 	{ .compatible = "ti,dra7-sdhci", .data = &dra7_data },
 	{ .compatible = "ti,k2g-sdhci", .data = &k2g_data },
+	{ .compatible = "ti,am335-sdhci", .data = &am335_data },
+	{ .compatible = "ti,am437-sdhci", .data = &am437_data },
 	{},
 };
 MODULE_DEVICE_TABLE(of, omap_sdhci_match);
Signature · 1 line
2.19.2
#26 lore raw
In reply to Faiz Abbas
Quoted 6 lines · Faiz Abbas

The following add driver patches for porting TI's am335x and am437x devices to the sdhci-omap driver.

This involves adding external DMA support to sdhci (first 3 patches from Chunyan) plus some miscellaneous patches to take care of deviations of the controllers from the sdhci model.

Good to see this happening :)

I think am437x should have also the ADMA as it's mostly omap4 based? See the old omap4 ADMA series at [0] below.

Are you seeing any improvment in SDIO card read/write speeds between external DMA and ADM BTW?

Regards,

Tony

[0] https://linux-omap.vger.kernel.narkive.com/H4EbLW96/patch-0-4-omap4-hsmmc-adding-adma-support

author
#27 lore raw

Hi Tony,

Quoted 8 lines · Tony Lindgren
Quoted 6 lines · Faiz Abbas

The following add driver patches for porting TI's am335x and am437x devices to the sdhci-omap driver.

This involves adding external DMA support to sdhci (first 3 patches from Chunyan) plus some miscellaneous patches to take care of deviations of the controllers from the sdhci model.

Quoted 7 lines

Good to see this happening :)

I think am437x should have also the ADMA as it's mostly omap4 based? See the old omap4 ADMA series at [0] below.

Are you seeing any improvment in SDIO card read/write speeds between external DMA and ADM BTW

am437 is using dmaengine even in the old omap_hsmmc driver. I haven't tried to enable ADMA in am437x.

Thanks,
Faiz

#28 lore raw
Quoted 13 lines · Faiz Abbas

Hi Tony,

Quoted 10 lines · Tony Lindgren
Quoted 6 lines · Faiz Abbas

The following add driver patches for porting TI's am335x and am437x devices to the sdhci-omap driver.

This involves adding external DMA support to sdhci (first 3 patches from Chunyan) plus some miscellaneous patches to take care of deviations of the controllers from the sdhci model.

Good to see this happening :)

Quoted 8 lines
Quoted 5 lines

I think am437x should have also the ADMA as it's mostly omap4 based? See the old omap4 ADMA series at [0] below.

Are you seeing any improvment in SDIO card read/write speeds between external DMA and ADM BTW

am437 is using dmaengine even in the old omap_hsmmc driver. I haven't tried to enable ADMA in am437x.

Right, it's probably safest to keep it that way at least initially to avoid changing multiple things at once. Then ADMA can be configured later on if needed.

Regards,

Tony