diff mbox series

[V2,03/27] mmc: mmci: convert dma_setup callback to return an int

Message ID 1537523181-14578-4-git-send-email-ludovic.Barre@st.com (mailing list archive)
State New, archived
Headers show
Series mmc: mmci: add sdmmc variant for stm32 | expand

Commit Message

Ludovic BARRE Sept. 21, 2018, 9:45 a.m. UTC
From: Ludovic Barre <ludovic.barre@st.com>

This patch converts dma_setup callback to return an integer
This patch is needed to prepare sdmmc variant with internal dma

Signed-off-by: Ludovic Barre <ludovic.barre@st.com>
---
 drivers/mmc/host/mmci.c          | 14 ++++++++++----
 drivers/mmc/host/mmci.h          |  2 +-
 drivers/mmc/host/mmci_qcom_dml.c |  6 ++++--
 3 files changed, 15 insertions(+), 7 deletions(-)

Comments

Ulf Hansson Sept. 24, 2018, 2:28 p.m. UTC | #1
On 21 September 2018 at 11:45, Ludovic Barre <ludovic.Barre@st.com> wrote:
> From: Ludovic Barre <ludovic.barre@st.com>
>
> This patch converts dma_setup callback to return an integer
> This patch is needed to prepare sdmmc variant with internal dma
>
> Signed-off-by: Ludovic Barre <ludovic.barre@st.com>
> ---
>  drivers/mmc/host/mmci.c          | 14 ++++++++++----
>  drivers/mmc/host/mmci.h          |  2 +-
>  drivers/mmc/host/mmci_qcom_dml.c |  6 ++++--
>  3 files changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
> index cbd67bc..2f845f3 100644
> --- a/drivers/mmc/host/mmci.c
> +++ b/drivers/mmc/host/mmci.c
> @@ -415,7 +415,7 @@ static void mmci_init_sg(struct mmci_host *host, struct mmc_data *data)
>   * no custom DMA interfaces are supported.
>   */
>  #ifdef CONFIG_DMA_ENGINE
> -static void mmci_dma_setup(struct mmci_host *host)
> +static int mmci_dma_setup(struct mmci_host *host)
>  {
>         const char *rxname, *txname;
>
> @@ -466,7 +466,9 @@ static void mmci_dma_setup(struct mmci_host *host)
>         }
>
>         if (host->ops && host->ops->dma_setup)
> -               host->ops->dma_setup(host);
> +               return host->ops->dma_setup(host);
> +

Looks like you need to implement a error handling, instead of just
returning the error code.

> +       return 0;
>  }
>
>  /*
> @@ -741,8 +743,10 @@ static void mmci_post_request(struct mmc_host *mmc, struct mmc_request *mrq,
>  static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data)
>  {
>  }
> -static inline void mmci_dma_setup(struct mmci_host *host)
> +
> +static inline int mmci_dma_setup(struct mmci_host *host)
>  {
> +       return 0;
>  }
>
>  static inline void mmci_dma_release(struct mmci_host *host)
> @@ -1796,7 +1800,9 @@ static int mmci_probe(struct amba_device *dev,
>                  amba_rev(dev), (unsigned long long)dev->res.start,
>                  dev->irq[0], dev->irq[1]);
>
> -       mmci_dma_setup(host);
> +       ret = mmci_dma_setup(host);
> +       if (ret)
> +               goto clk_disable;
>
>         pm_runtime_set_autosuspend_delay(&dev->dev, 50);
>         pm_runtime_use_autosuspend(&dev->dev);
> diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h
> index 21aaf9a..06299ac 100644
> --- a/drivers/mmc/host/mmci.h
> +++ b/drivers/mmc/host/mmci.h
> @@ -273,7 +273,7 @@ struct variant_data {
>
>  /* mmci variant callbacks */
>  struct mmci_host_ops {
> -       void (*dma_setup)(struct mmci_host *host);
> +       int (*dma_setup)(struct mmci_host *host);
>  };
>
>  struct mmci_host_next {
> diff --git a/drivers/mmc/host/mmci_qcom_dml.c b/drivers/mmc/host/mmci_qcom_dml.c
> index be3fab5..1bb59cf 100644
> --- a/drivers/mmc/host/mmci_qcom_dml.c
> +++ b/drivers/mmc/host/mmci_qcom_dml.c
> @@ -119,7 +119,7 @@ static int of_get_dml_pipe_index(struct device_node *np, const char *name)
>  }
>
>  /* Initialize the dml hardware connected to SD Card controller */
> -static void qcom_dma_setup(struct mmci_host *host)
> +static int qcom_dma_setup(struct mmci_host *host)
>  {
>         u32 config;
>         void __iomem *base;
> @@ -131,7 +131,7 @@ static void qcom_dma_setup(struct mmci_host *host)
>
>         if (producer_id < 0 || consumer_id < 0) {
>                 host->variant->qcom_dml = false;

It seems like the existing code is an attempt to fallback to use pio
mode. However, I doubt it works as is.

> -               return;
> +               return -EINVAL;

My point is, if you return an error code here, it means that the error
code becomes propagated and ->probe() will fail.

Ideally, we should be able fall back to pio mode when dma doesn't
work. I have looped in Srinivas who implemented the qcom dml support,
let's see if he can explains the intent with the code.

I also volunteer to help out running some tests on the 410c platform,
however allow me a day or two to do that.

>         }
>
>         base = host->base + DML_OFFSET;
> @@ -175,6 +175,8 @@ static void qcom_dma_setup(struct mmci_host *host)
>
>         /* Make sure dml initialization is finished */
>         mb();
> +
> +       return 0;
>  }
>
>  static struct mmci_host_ops qcom_variant_ops = {
> --
> 2.7.4
>

Kind regards
Uffe
Ludovic BARRE Sept. 24, 2018, 4:12 p.m. UTC | #2
hi Ulf

On 09/24/2018 04:28 PM, Ulf Hansson wrote:
> On 21 September 2018 at 11:45, Ludovic Barre <ludovic.Barre@st.com> wrote:
>> From: Ludovic Barre <ludovic.barre@st.com>
>>
>> This patch converts dma_setup callback to return an integer
>> This patch is needed to prepare sdmmc variant with internal dma
>>
>> Signed-off-by: Ludovic Barre <ludovic.barre@st.com>
>> ---
>>   drivers/mmc/host/mmci.c          | 14 ++++++++++----
>>   drivers/mmc/host/mmci.h          |  2 +-
>>   drivers/mmc/host/mmci_qcom_dml.c |  6 ++++--
>>   3 files changed, 15 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
>> index cbd67bc..2f845f3 100644
>> --- a/drivers/mmc/host/mmci.c
>> +++ b/drivers/mmc/host/mmci.c
>> @@ -415,7 +415,7 @@ static void mmci_init_sg(struct mmci_host *host, struct mmc_data *data)
>>    * no custom DMA interfaces are supported.
>>    */
>>   #ifdef CONFIG_DMA_ENGINE
>> -static void mmci_dma_setup(struct mmci_host *host)
>> +static int mmci_dma_setup(struct mmci_host *host)
>>   {
>>          const char *rxname, *txname;
>>
>> @@ -466,7 +466,9 @@ static void mmci_dma_setup(struct mmci_host *host)
>>          }
>>
>>          if (host->ops && host->ops->dma_setup)
>> -               host->ops->dma_setup(host);
>> +               return host->ops->dma_setup(host);
>> +
> 
> Looks like you need to implement a error handling, instead of just
> returning the error code.

yes, today if a dma_setup is defined, we can't fallback to pio mode.
A use_dma variable (defined in mmci_host) could be setted follow the 
return code of ops->dma_setup

example:

void mmci_dma_setup(struct mmci_host *host)
{
	int err;

	if (!host->ops || !host->ops->dma_setup)
		return;

	err = host->ops->dma_setup(host);
	if (err)
		return;
	
	host->use_dma = true;
	
	/* initialize pre request cookie */
	host->next_cookie = 1;
}

use_dma variable could be check by mmci_host_ops variant functions.

are you agree with this proposal?

> 
>> +       return 0;
>>   }
>>
>>   /*
>> @@ -741,8 +743,10 @@ static void mmci_post_request(struct mmc_host *mmc, struct mmc_request *mrq,
>>   static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data)
>>   {
>>   }
>> -static inline void mmci_dma_setup(struct mmci_host *host)
>> +
>> +static inline int mmci_dma_setup(struct mmci_host *host)
>>   {
>> +       return 0;
>>   }
>>
>>   static inline void mmci_dma_release(struct mmci_host *host)
>> @@ -1796,7 +1800,9 @@ static int mmci_probe(struct amba_device *dev,
>>                   amba_rev(dev), (unsigned long long)dev->res.start,
>>                   dev->irq[0], dev->irq[1]);
>>
>> -       mmci_dma_setup(host);
>> +       ret = mmci_dma_setup(host);
>> +       if (ret)
>> +               goto clk_disable;
>>
>>          pm_runtime_set_autosuspend_delay(&dev->dev, 50);
>>          pm_runtime_use_autosuspend(&dev->dev);
>> diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h
>> index 21aaf9a..06299ac 100644
>> --- a/drivers/mmc/host/mmci.h
>> +++ b/drivers/mmc/host/mmci.h
>> @@ -273,7 +273,7 @@ struct variant_data {
>>
>>   /* mmci variant callbacks */
>>   struct mmci_host_ops {
>> -       void (*dma_setup)(struct mmci_host *host);
>> +       int (*dma_setup)(struct mmci_host *host);
>>   };
>>
>>   struct mmci_host_next {
>> diff --git a/drivers/mmc/host/mmci_qcom_dml.c b/drivers/mmc/host/mmci_qcom_dml.c
>> index be3fab5..1bb59cf 100644
>> --- a/drivers/mmc/host/mmci_qcom_dml.c
>> +++ b/drivers/mmc/host/mmci_qcom_dml.c
>> @@ -119,7 +119,7 @@ static int of_get_dml_pipe_index(struct device_node *np, const char *name)
>>   }
>>
>>   /* Initialize the dml hardware connected to SD Card controller */
>> -static void qcom_dma_setup(struct mmci_host *host)
>> +static int qcom_dma_setup(struct mmci_host *host)
>>   {
>>          u32 config;
>>          void __iomem *base;
>> @@ -131,7 +131,7 @@ static void qcom_dma_setup(struct mmci_host *host)
>>
>>          if (producer_id < 0 || consumer_id < 0) {
>>                  host->variant->qcom_dml = false;
> 
> It seems like the existing code is an attempt to fallback to use pio
> mode. However, I doubt it works as is.

oops, I seen that like a variant identification issue, so if it's a
fallback to pio mode it doesn't work.

> 
>> -               return;
>> +               return -EINVAL;
> 
> My point is, if you return an error code here, it means that the error
> code becomes propagated and ->probe() will fail.
> 
> Ideally, we should be able fall back to pio mode when dma doesn't
> work. I have looped in Srinivas who implemented the qcom dml support,
> let's see if he can explains the intent with the code.
> 
> I also volunteer to help out running some tests on the 410c platform,
> however allow me a day or two to do that.

yes, I would be more reassured

> 
>>          }
>>
>>          base = host->base + DML_OFFSET;
>> @@ -175,6 +175,8 @@ static void qcom_dma_setup(struct mmci_host *host)
>>
>>          /* Make sure dml initialization is finished */
>>          mb();
>> +
>> +       return 0;
>>   }
>>
>>   static struct mmci_host_ops qcom_variant_ops = {
>> --
>> 2.7.4
>>
> 
> Kind regards
> Uffe
>
Ulf Hansson Sept. 26, 2018, 11:49 p.m. UTC | #3
On 24 September 2018 at 18:12, Ludovic BARRE <ludovic.barre@st.com> wrote:
> hi Ulf
>
>
> On 09/24/2018 04:28 PM, Ulf Hansson wrote:
>>
>> On 21 September 2018 at 11:45, Ludovic Barre <ludovic.Barre@st.com> wrote:
>>>
>>> From: Ludovic Barre <ludovic.barre@st.com>
>>>
>>> This patch converts dma_setup callback to return an integer
>>> This patch is needed to prepare sdmmc variant with internal dma
>>>
>>> Signed-off-by: Ludovic Barre <ludovic.barre@st.com>
>>> ---
>>>   drivers/mmc/host/mmci.c          | 14 ++++++++++----
>>>   drivers/mmc/host/mmci.h          |  2 +-
>>>   drivers/mmc/host/mmci_qcom_dml.c |  6 ++++--
>>>   3 files changed, 15 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
>>> index cbd67bc..2f845f3 100644
>>> --- a/drivers/mmc/host/mmci.c
>>> +++ b/drivers/mmc/host/mmci.c
>>> @@ -415,7 +415,7 @@ static void mmci_init_sg(struct mmci_host *host,
>>> struct mmc_data *data)
>>>    * no custom DMA interfaces are supported.
>>>    */
>>>   #ifdef CONFIG_DMA_ENGINE
>>> -static void mmci_dma_setup(struct mmci_host *host)
>>> +static int mmci_dma_setup(struct mmci_host *host)
>>>   {
>>>          const char *rxname, *txname;
>>>
>>> @@ -466,7 +466,9 @@ static void mmci_dma_setup(struct mmci_host *host)
>>>          }
>>>
>>>          if (host->ops && host->ops->dma_setup)
>>> -               host->ops->dma_setup(host);
>>> +               return host->ops->dma_setup(host);
>>> +
>>
>>
>> Looks like you need to implement a error handling, instead of just
>> returning the error code.
>
>
> yes, today if a dma_setup is defined, we can't fallback to pio mode.
> A use_dma variable (defined in mmci_host) could be setted follow the return
> code of ops->dma_setup
>
> example:
>
> void mmci_dma_setup(struct mmci_host *host)
> {
>         int err;
>
>         if (!host->ops || !host->ops->dma_setup)
>                 return;
>
>         err = host->ops->dma_setup(host);
>         if (err)
>                 return;
>
>         host->use_dma = true;
>
>         /* initialize pre request cookie */
>         host->next_cookie = 1;
> }
>
> use_dma variable could be check by mmci_host_ops variant functions.
>
> are you agree with this proposal?
>

Yep, makes sense!

>
>>
>>> +       return 0;
>>>   }
>>>
>>>   /*
>>> @@ -741,8 +743,10 @@ static void mmci_post_request(struct mmc_host *mmc,
>>> struct mmc_request *mrq,
>>>   static void mmci_get_next_data(struct mmci_host *host, struct mmc_data
>>> *data)
>>>   {
>>>   }
>>> -static inline void mmci_dma_setup(struct mmci_host *host)
>>> +
>>> +static inline int mmci_dma_setup(struct mmci_host *host)
>>>   {
>>> +       return 0;
>>>   }
>>>
>>>   static inline void mmci_dma_release(struct mmci_host *host)
>>> @@ -1796,7 +1800,9 @@ static int mmci_probe(struct amba_device *dev,
>>>                   amba_rev(dev), (unsigned long long)dev->res.start,
>>>                   dev->irq[0], dev->irq[1]);
>>>
>>> -       mmci_dma_setup(host);
>>> +       ret = mmci_dma_setup(host);
>>> +       if (ret)
>>> +               goto clk_disable;
>>>
>>>          pm_runtime_set_autosuspend_delay(&dev->dev, 50);
>>>          pm_runtime_use_autosuspend(&dev->dev);
>>> diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h
>>> index 21aaf9a..06299ac 100644
>>> --- a/drivers/mmc/host/mmci.h
>>> +++ b/drivers/mmc/host/mmci.h
>>> @@ -273,7 +273,7 @@ struct variant_data {
>>>
>>>   /* mmci variant callbacks */
>>>   struct mmci_host_ops {
>>> -       void (*dma_setup)(struct mmci_host *host);
>>> +       int (*dma_setup)(struct mmci_host *host);
>>>   };
>>>
>>>   struct mmci_host_next {
>>> diff --git a/drivers/mmc/host/mmci_qcom_dml.c
>>> b/drivers/mmc/host/mmci_qcom_dml.c
>>> index be3fab5..1bb59cf 100644
>>> --- a/drivers/mmc/host/mmci_qcom_dml.c
>>> +++ b/drivers/mmc/host/mmci_qcom_dml.c
>>> @@ -119,7 +119,7 @@ static int of_get_dml_pipe_index(struct device_node
>>> *np, const char *name)
>>>   }
>>>
>>>   /* Initialize the dml hardware connected to SD Card controller */
>>> -static void qcom_dma_setup(struct mmci_host *host)
>>> +static int qcom_dma_setup(struct mmci_host *host)
>>>   {
>>>          u32 config;
>>>          void __iomem *base;
>>> @@ -131,7 +131,7 @@ static void qcom_dma_setup(struct mmci_host *host)
>>>
>>>          if (producer_id < 0 || consumer_id < 0) {
>>>                  host->variant->qcom_dml = false;
>>
>>
>> It seems like the existing code is an attempt to fallback to use pio
>> mode. However, I doubt it works as is.
>
>
> oops, I seen that like a variant identification issue, so if it's a
> fallback to pio mode it doesn't work.

Right. Let's see if we can get some input from Srinivas, else I will
run some test on my 410c board to see the behavior - very soon.

[...]

Kind regards
Uffe
Srinivas Kandagatla Sept. 27, 2018, 8:55 a.m. UTC | #4
Thanks for looping me!

On 24/09/18 15:28, Ulf Hansson wrote:
>>   /* Initialize the dml hardware connected to SD Card controller */
>> -static void qcom_dma_setup(struct mmci_host *host)
>> +static int qcom_dma_setup(struct mmci_host *host)
>>   {
>>          u32 config;
>>          void __iomem *base;
>> @@ -131,7 +131,7 @@ static void qcom_dma_setup(struct mmci_host *host)
>>
>>          if (producer_id < 0 || consumer_id < 0) {
>>                  host->variant->qcom_dml = false;
> It seems like the existing code is an attempt to fallback to use pio
> mode. However, I doubt it works as is.

If I remember it correctly, Yes, that was the intent. we should still be 
able to use the pio mode if the dma setup fails.

I believe pio mode should work, Last time when I tried (3-4 years back) 
it did work!

> 
>> -               return;
>> +               return -EINVAL;
> My point is, if you return an error code here, it means that the error
> code becomes propagated and ->probe() will fail.
That would be very bad!, We should report it and may be just continue 
with pio mode.

> 
> Ideally, we should be able fall back to pio mode when dma doesn't
> work. I have looped in Srinivas who implemented the qcom dml support,
> let's see if he can explains the intent with the code.
> 
> I also volunteer to help out running some tests on the 410c platform,
I think you meant IFC6410.. DB410c uses sdhci.


--srini
> however allow me a day or two to do that.
>
diff mbox series

Patch

diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index cbd67bc..2f845f3 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -415,7 +415,7 @@  static void mmci_init_sg(struct mmci_host *host, struct mmc_data *data)
  * no custom DMA interfaces are supported.
  */
 #ifdef CONFIG_DMA_ENGINE
-static void mmci_dma_setup(struct mmci_host *host)
+static int mmci_dma_setup(struct mmci_host *host)
 {
 	const char *rxname, *txname;
 
@@ -466,7 +466,9 @@  static void mmci_dma_setup(struct mmci_host *host)
 	}
 
 	if (host->ops && host->ops->dma_setup)
-		host->ops->dma_setup(host);
+		return host->ops->dma_setup(host);
+
+	return 0;
 }
 
 /*
@@ -741,8 +743,10 @@  static void mmci_post_request(struct mmc_host *mmc, struct mmc_request *mrq,
 static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data)
 {
 }
-static inline void mmci_dma_setup(struct mmci_host *host)
+
+static inline int mmci_dma_setup(struct mmci_host *host)
 {
+	return 0;
 }
 
 static inline void mmci_dma_release(struct mmci_host *host)
@@ -1796,7 +1800,9 @@  static int mmci_probe(struct amba_device *dev,
 		 amba_rev(dev), (unsigned long long)dev->res.start,
 		 dev->irq[0], dev->irq[1]);
 
-	mmci_dma_setup(host);
+	ret = mmci_dma_setup(host);
+	if (ret)
+		goto clk_disable;
 
 	pm_runtime_set_autosuspend_delay(&dev->dev, 50);
 	pm_runtime_use_autosuspend(&dev->dev);
diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h
index 21aaf9a..06299ac 100644
--- a/drivers/mmc/host/mmci.h
+++ b/drivers/mmc/host/mmci.h
@@ -273,7 +273,7 @@  struct variant_data {
 
 /* mmci variant callbacks */
 struct mmci_host_ops {
-	void (*dma_setup)(struct mmci_host *host);
+	int (*dma_setup)(struct mmci_host *host);
 };
 
 struct mmci_host_next {
diff --git a/drivers/mmc/host/mmci_qcom_dml.c b/drivers/mmc/host/mmci_qcom_dml.c
index be3fab5..1bb59cf 100644
--- a/drivers/mmc/host/mmci_qcom_dml.c
+++ b/drivers/mmc/host/mmci_qcom_dml.c
@@ -119,7 +119,7 @@  static int of_get_dml_pipe_index(struct device_node *np, const char *name)
 }
 
 /* Initialize the dml hardware connected to SD Card controller */
-static void qcom_dma_setup(struct mmci_host *host)
+static int qcom_dma_setup(struct mmci_host *host)
 {
 	u32 config;
 	void __iomem *base;
@@ -131,7 +131,7 @@  static void qcom_dma_setup(struct mmci_host *host)
 
 	if (producer_id < 0 || consumer_id < 0) {
 		host->variant->qcom_dml = false;
-		return;
+		return -EINVAL;
 	}
 
 	base = host->base + DML_OFFSET;
@@ -175,6 +175,8 @@  static void qcom_dma_setup(struct mmci_host *host)
 
 	/* Make sure dml initialization is finished */
 	mb();
+
+	return 0;
 }
 
 static struct mmci_host_ops qcom_variant_ops = {