All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Russell King <rmk+kernel@arm.linux.org.uk>,
	Ulf Hansson <ulf.hansson@linaro.org>
Cc: Gregory CLEMENT <gregory.clement@free-electrons.com>,
	linux-mmc@vger.kernel.org, Marcin Wojtas <mw@semihalf.com>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <kernel@pengutronix.de>
Subject: Re: [PATCH v3 09/25] mmc: sdhci: allocate alignment and DMA descriptor buffer together
Date: Wed, 27 Jan 2016 11:14:41 +0200	[thread overview]
Message-ID: <56A88A81.8090505@intel.com> (raw)
In-Reply-To: <E1aO3qd-0005iN-OG@rmk-PC.arm.linux.org.uk>

On 26/01/16 15:39, Russell King wrote:
> Allocate both the alignment and DMA descriptor buffers together.  The
> size of the alignment buffer will always be aligned to the hosts
> required alignment, which gives appropriate alignment to the DMA
> descriptors.
> 
> We have a maximum of 128 segments, and a maximum alignment of 64 bits.
> This gives a maximum alignment buffer size of 1024 bytes.
> 
> The DMA descriptors are a maximum of 12 bytes, and we allocate 128 * 2
> + 1 of these, which gives a maximum DMA descriptor buffer size of 3084
> bytes.
> 
> This means the allocation for a 4K page sized system will be an order-1
> allocation, since the resulting overall size is 4108.  This is more
> prone to failure than page-sized allocations, but since this allocation
> commonly occurs at startup, the chances of failure are small.
> 
> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
> ---
>  drivers/mmc/host/sdhci.c | 55 +++++++++++++++++-------------------------------
>  1 file changed, 19 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index c70a2d2eb6d9..f23fdb485393 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -2932,6 +2932,9 @@ int sdhci_add_host(struct sdhci_host *host)
>  		host->flags &= ~SDHCI_USE_SDMA;
>  
>  	if (host->flags & SDHCI_USE_ADMA) {
> +		dma_addr_t dma;
> +		void *buf;
> +
>  		/*
>  		 * The DMA descriptor table size is calculated as the maximum
>  		 * number of segments times 2, to allow for an alignment
> @@ -2947,45 +2950,27 @@ int sdhci_add_host(struct sdhci_host *host)
>  					      SDHCI_ADMA2_32_DESC_SZ;
>  			host->desc_sz = SDHCI_ADMA2_32_DESC_SZ;
>  		}
> -		host->adma_table = dma_alloc_coherent(mmc_dev(mmc),
> -						      host->adma_table_sz,
> -						      &host->adma_addr,
> -						      GFP_KERNEL);
> +
>  		host->align_buffer_sz = SDHCI_MAX_SEGS * SDHCI_ADMA2_ALIGN;
> -		host->align_buffer = dma_alloc_coherent(mmc_dev(mmc),
> -							host->align_buffer_sz,
> -							&host->align_addr,
> -							GFP_KERNEL);
> -		if (!host->adma_table || !host->align_buffer) {
> -			if (host->adma_table)
> -				dma_free_coherent(mmc_dev(mmc),
> -						  host->adma_table_sz,
> -						  host->adma_table,
> -						  host->adma_addr);
> -			if (host->align_buffer)
> -				dma_free_coherent(mmc_dev(mmc),
> -						  host->align_buffer_sz,
> -						  host->align_buffer,
> -						  host->align_addr);
> +		buf = dma_alloc_coherent(mmc_dev(mmc), host->align_buffer_sz +
> +					 host->adma_table_sz, &dma, GFP_KERNEL);
> +		if (!buf) {
>  			pr_warn("%s: Unable to allocate ADMA buffers - falling back to standard DMA\n",
>  				mmc_hostname(mmc));
>  			host->flags &= ~SDHCI_USE_ADMA;
> -			host->adma_table = NULL;
> -			host->align_buffer = NULL;
> -		} else if (host->adma_addr & (SDHCI_ADMA2_DESC_ALIGN - 1)) {
> +		} else if (dma & SDHCI_ADMA2_MASK) {

The descriptor table has a bigger alignment requirement, so that should remain the check i.e.

		} else if ((dma + host->align_buffer_sz) & (SDHCI_ADMA2_DESC_ALIGN - 1)) {


>  			pr_warn("%s: unable to allocate aligned ADMA descriptor\n",
>  				mmc_hostname(mmc));
>  			host->flags &= ~SDHCI_USE_ADMA;
> -			dma_free_coherent(mmc_dev(mmc), host->adma_table_sz,
> -					  host->adma_table, host->adma_addr);
> -			dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz,
> -					  host->align_buffer, host->align_addr);
> -			host->adma_table = NULL;
> -			host->align_buffer = NULL;
> -		}
> +			dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz +
> +					  host->adma_table_sz, buf, dma);
> +		} else {
> +			host->align_buffer = buf;
> +			host->align_addr = dma;
>  
> -		/* dma_alloc_coherent returns page aligned and sized buffers */
> -		BUG_ON(host->align_addr & SDHCI_ADMA2_MASK);
> +			host->adma_table = buf + host->align_buffer_sz;
> +			host->adma_addr = dma + host->align_buffer_sz;
> +		}
>  	}
>  
>  	/*
> @@ -3446,12 +3431,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
>  	if (!IS_ERR(mmc->supply.vqmmc))
>  		regulator_disable(mmc->supply.vqmmc);
>  
> -	if (host->adma_table)
> -		dma_free_coherent(mmc_dev(mmc), host->adma_table_sz,
> -				  host->adma_table, host->adma_addr);
>  	if (host->align_buffer)
> -		dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz,
> -				  host->align_buffer, host->align_addr);
> +		dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz +
> +				  host->adma_table_sz, host->align_buffer,
> +				  host->align_addr);
>  
>  	host->adma_table = NULL;
>  	host->align_buffer = NULL;
> 


  reply	other threads:[~2016-01-27  9:18 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-26 13:38 [PATCH v3 00/25] MMC/SDHCI fixes Russell King - ARM Linux
2016-01-26 13:39 ` [PATCH v3 01/25] mmc: core: shut up "voltage-ranges unspecified" pr_info() Russell King
2016-01-26 13:39 ` [PATCH v3 02/25] mmc: core: improve mmc_of_parse_voltage() to return better status Russell King
2016-01-26 13:39 ` [PATCH v3 03/25] mmc: block: shut up "retrying because a re-tune was needed" message Russell King
2016-01-26 13:39 ` [PATCH v3 04/25] mmc: core: report tuning command execution failure reason Russell King
2016-01-26 13:39 ` [PATCH v3 05/25] mmc: sdhci: move initialisation of command error member Russell King
2016-01-26 13:39 ` [PATCH v3 06/25] mmc: sdhci: clean up command error handling Russell King
2016-01-26 13:39 ` [PATCH v3 07/25] mmc: sdhci: command response CRC " Russell King
2016-01-26 14:10   ` kbuild test robot
2016-01-26 14:11   ` kbuild test robot
2016-01-26 13:39 ` [PATCH v3 08/25] mmc: sdhci: avoid unnecessary mapping/unmapping of align buffer Russell King
2016-01-26 13:39 ` [PATCH v3 09/25] mmc: sdhci: allocate alignment and DMA descriptor buffer together Russell King
2016-01-27  9:14   ` Adrian Hunter [this message]
2016-01-27 19:50     ` Russell King - ARM Linux
2016-01-26 13:40 ` [PATCH v3 10/25] mmc: sdhci: clean up coding style in sdhci_adma_table_pre() Russell King
2016-01-26 13:40 ` [PATCH v3 11/25] mmc: sdhci: avoid walking SG list for writes Russell King
2016-01-26 13:40 ` [PATCH v3 12/25] mmc: sdhci: factor out common DMA cleanup in sdhci_finish_data() Russell King
2016-01-26 13:40 ` [PATCH v3 13/25] mmc: sdhci: move sdhci_pre_dma_transfer() Russell King
2016-01-26 13:40 ` [PATCH v3 14/25] mmc: sdhci: factor out sdhci_pre_dma_transfer() from sdhci_adma_table_pre() Russell King
2016-01-26 13:40 ` [PATCH v3 15/25] mmc: sdhci: pass the cookie into sdhci_pre_dma_transfer() Russell King
2016-01-26 13:40 ` [PATCH v3 16/25] mmc: sdhci: always unmap a mapped data transfer in sdhci_post_req() Russell King
2016-01-26 13:40 ` [PATCH v3 17/25] mmc: sdhci: clean up host cookie handling Russell King
2016-01-26 13:40 ` [PATCH v3 18/25] mmc: sdhci: plug DMA mapping leak on error Russell King
2016-01-26 13:40 ` [PATCH v3 19/25] mmc: sdhci-pxav3: fix higher speed mode capabilities Russell King
2016-01-26 13:40 ` [PATCH v3 20/25] mmc: sdhci: further fix for DMA unmapping in sdhci_post_req() Russell King
2016-01-26 13:40 ` [PATCH v3 21/25] mmc: sdhci: fix data timeout (part 1) Russell King
2016-01-26 13:41 ` [PATCH v3 22/25] mmc: sdhci: fix data timeout (part 2) Russell King
2016-01-26 13:41 ` [PATCH v3 23/25] mmc: sdhci: prepare DMA address/size quirk handling consolidation Russell King
2016-01-26 13:41 ` [PATCH v3 24/25] mmc: sdhci: consolidate the DMA/ADMA size/address quicks Russell King
2016-01-26 13:41 ` [PATCH v3 25/25] mmc: sdhci: further code simplication Russell King
2016-01-26 15:33 ` [PATCH v3 00/25] MMC/SDHCI fixes Gregory CLEMENT

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56A88A81.8090505@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=gregory.clement@free-electrons.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-mmc@vger.kernel.org \
    --cc=mw@semihalf.com \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=shawnguo@kernel.org \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.