mtd: spi-nor: Ensure operation completion before shutdown

Message ID 20231012055148.2445303-1-quic_mdalam@quicinc.com
State New
Headers
Series mtd: spi-nor: Ensure operation completion before shutdown |

Commit Message

Md Sadre Alam Oct. 12, 2023, 5:51 a.m. UTC
  Ensure that there are no pending spi operation inprogress
when system halts.

Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---
 drivers/mtd/spi-nor/core.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Michael Walle Oct. 12, 2023, 9:11 a.m. UTC | #1
Hi,

Am 2023-10-12 07:51, schrieb Md Sadre Alam:
> Ensure that there are no pending spi operation inprogress
> when system halts.

What operation might be in progress here? Did you encounter some 
problems?
Please explain it in more detail in the commit message.

Fixes tag?

-michael

> Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
> ---
>  drivers/mtd/spi-nor/core.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 1c443fe568cf..adc4d2c68695 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -3690,6 +3690,9 @@ static void spi_nor_shutdown(struct spi_mem 
> *spimem)
>  {
>  	struct spi_nor *nor = spi_mem_get_drvdata(spimem);
> 
> +	/* Ensure no pending spi operation in progress */
> +	spi_nor_wait_till_ready(nor);
> +
>  	spi_nor_restore(nor);
>  }
  
Pratyush Yadav Oct. 12, 2023, 10:06 a.m. UTC | #2
On Thu, Oct 12 2023, Michael Walle wrote:

> Hi,
>
> Am 2023-10-12 07:51, schrieb Md Sadre Alam:
>> Ensure that there are no pending spi operation inprogress
>> when system halts.
>
> What operation might be in progress here? Did you encounter some problems?
> Please explain it in more detail in the commit message.

+1

Ideally we should never reach this function with a pending operation. I
think we should do a proper wait in the place we did the operation that
needs waiting rather than here. That would make sure operations other
than shutdown, like reads, also work properly.
  
Md Sadre Alam Oct. 18, 2023, 11:06 a.m. UTC | #3
On 10/12/2023 2:41 PM, Michael Walle wrote:
> Hi,
> 
> Am 2023-10-12 07:51, schrieb Md Sadre Alam:
>> Ensure that there are no pending spi operation inprogress
>> when system halts.
> 
> What operation might be in progress here? Did you encounter some problems?
> Please explain it in more detail in the commit message.
> 
> Fixes tag?

   We have faced issue while doing nor flash read/write test with specific nor part.
   Will check once again with the same part and post new patch.
> 
> -michael
> 
>> Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
>> ---
>>  drivers/mtd/spi-nor/core.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
>> index 1c443fe568cf..adc4d2c68695 100644
>> --- a/drivers/mtd/spi-nor/core.c
>> +++ b/drivers/mtd/spi-nor/core.c
>> @@ -3690,6 +3690,9 @@ static void spi_nor_shutdown(struct spi_mem *spimem)
>>  {
>>      struct spi_nor *nor = spi_mem_get_drvdata(spimem);
>>
>> +    /* Ensure no pending spi operation in progress */
>> +    spi_nor_wait_till_ready(nor);
>> +
>>      spi_nor_restore(nor);
>>  }
  
Md Sadre Alam Oct. 18, 2023, 11:07 a.m. UTC | #4
On 10/12/2023 3:36 PM, Pratyush Yadav wrote:
> On Thu, Oct 12 2023, Michael Walle wrote:
> 
>> Hi,
>>
>> Am 2023-10-12 07:51, schrieb Md Sadre Alam:
>>> Ensure that there are no pending spi operation inprogress
>>> when system halts.
>>
>> What operation might be in progress here? Did you encounter some problems?
>> Please explain it in more detail in the commit message.
> 
> +1
> 
> Ideally we should never reach this function with a pending operation. I
> think we should do a proper wait in the place we did the operation that
> needs waiting rather than here. That would make sure operations other
> than shutdown, like reads, also work properly.
> 

   We have faced issue while doing nor flash read/write test with specific nor part.
   Will check once again with the same part and post new patch.
  

Patch

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 1c443fe568cf..adc4d2c68695 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -3690,6 +3690,9 @@  static void spi_nor_shutdown(struct spi_mem *spimem)
 {
 	struct spi_nor *nor = spi_mem_get_drvdata(spimem);
 
+	/* Ensure no pending spi operation in progress */
+	spi_nor_wait_till_ready(nor);
+
 	spi_nor_restore(nor);
 }