diff mbox series

mtd: spi-nor: handle unsupported FSR opcodes properly

Message ID 20220610191548.3626218-1-oocheret@cisco.com (mailing list archive)
State Superseded
Headers show
Series mtd: spi-nor: handle unsupported FSR opcodes properly | expand

Commit Message

Oleksandr Ocheretnyi June 10, 2022, 7:15 p.m. UTC
Commit 094d3b9 ("mtd: spi-nor: Add USE_FSR flag for n25q* entries")
and following one 8f93826 ("mtd: spi-nor: micron-st: convert USE_FSR
to a manufacturer flag") enables SPINOR_OP_RDFSR opcode handling ability,
however some controller drivers still cannot handle it properly in
the micron_st_nor_ready() call what breaks some mtd callbacks with
next error logs:

mtdblock: erase of region [address1, size1] on "BIOS" failed
mtdblock: erase of region [address2, size2] on "BIOS" failed

Just skip subsequent processing of the SPINOR_OP_RDFSR opcode's results
because of -ENOTSUPP return value of the micron_st_nor_read_fsr()
if there is no proper handling of that opcode as it's been before
commit 094d3b9 ("mtd: spi-nor: Add USE_FSR flag for n25q* entries")

Signed-off-by: Oleksandr Ocheretnyi <oocheret@cisco.com>
---
 drivers/mtd/spi-nor/micron-st.c | 6 +++++-
 drivers/spi/spi-intel.c         | 3 ++-
 2 files changed, 7 insertions(+), 2 deletions(-)

Comments

Mika Westerberg June 13, 2022, 6:18 a.m. UTC | #1
Hi,

On Fri, Jun 10, 2022 at 12:15:48PM -0700, Oleksandr Ocheretnyi wrote:
> Commit 094d3b9 ("mtd: spi-nor: Add USE_FSR flag for n25q* entries")
> and following one 8f93826 ("mtd: spi-nor: micron-st: convert USE_FSR
> to a manufacturer flag") enables SPINOR_OP_RDFSR opcode handling ability,
> however some controller drivers still cannot handle it properly in
> the micron_st_nor_ready() call what breaks some mtd callbacks with
> next error logs:
> 
> mtdblock: erase of region [address1, size1] on "BIOS" failed
> mtdblock: erase of region [address2, size2] on "BIOS" failed
> 
> Just skip subsequent processing of the SPINOR_OP_RDFSR opcode's results
> because of -ENOTSUPP return value of the micron_st_nor_read_fsr()
> if there is no proper handling of that opcode as it's been before
> commit 094d3b9 ("mtd: spi-nor: Add USE_FSR flag for n25q* entries")
> 
> Signed-off-by: Oleksandr Ocheretnyi <oocheret@cisco.com>

I sent similar patch some time ago here:

https://lore.kernel.org/linux-mtd/20220506105158.43613-1-mika.westerberg@linux.intel.com/#t

but so far it has not been picked up by the maintainers. I'm fine if we
go with your patch instead, just one minor comment:

> ---
>  drivers/mtd/spi-nor/micron-st.c | 6 +++++-
>  drivers/spi/spi-intel.c         | 3 ++-
>  2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/micron-st.c b/drivers/mtd/spi-nor/micron-st.c
> index a96f74e0f568..507e675d81e0 100644
> --- a/drivers/mtd/spi-nor/micron-st.c
> +++ b/drivers/mtd/spi-nor/micron-st.c
> @@ -399,8 +399,12 @@ static int micron_st_nor_ready(struct spi_nor *nor)
>  		return sr_ready;
>  
>  	ret = micron_st_nor_read_fsr(nor, nor->bouncebuf);
> -	if (ret)
> +	if (ret < 0) {
> +		/* Check if read FSR is supported. If not, skip it. */
> +		if (ret == -ENOTSUPP)
> +			return sr_ready;
>  		return ret;
> +	}
>  
>  	if (nor->bouncebuf[0] & (FSR_E_ERR | FSR_P_ERR)) {
>  		if (nor->bouncebuf[0] & FSR_E_ERR)
> diff --git a/drivers/spi/spi-intel.c b/drivers/spi/spi-intel.c
> index 50f42983b950..f0313a718d1b 100644
> --- a/drivers/spi/spi-intel.c
> +++ b/drivers/spi/spi-intel.c
> @@ -352,7 +352,8 @@ static int intel_spi_hw_cycle(struct intel_spi *ispi, u8 opcode, size_t len)
>  		val |= HSFSTS_CTL_FCYCLE_RDSR;
>  		break;
>  	default:
> -		return -EINVAL;
> +		dev_dbg(ispi->dev, "%#x not supported\n", opcode);
> +		return -ENOTSUPP;

I don't think this is necessary because we already return -EOPNOTSUPP in
intel_spi_exec_mem_op() so we can just check that one in
micron_st_nor_ready().

With that changed feel free to add my,

Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Mika Westerberg June 15, 2022, 9:49 a.m. UTC | #2
Hi,

On Tue, Jun 14, 2022 at 05:56:54PM +0000, Oleksandr Ocheretnyi -X (oocheret - GLOBALLOGIC INC at Cisco) wrote:
>    Hello Mika,
> 
>    in my case (I work with memory chip n25q128a13 for recent kernels) I'm
>    getting return value -ENOTSUPP from spi_mem_exec_op() call in the
>    micron_st_nor_read_fsr() method
>    [[1]https://elixir.bootlin.com/linux/v5.19-rc2/source/drivers/spi/spi-m
>    em.c#L326]. So I decided to provide the same errorcode to
>    intel_spi_hw_cycle() method because older kernel versions throw the
>    error there. It is fine to use -EOPNOTSUPP return value instead.
> 
>    I suspect we need to cover both cases to check -ENOTSUPP as well as
>    -EOPNOTSUPP to let the driver work properly.
> 
>    if (ret == -ENOTSUPP || ret == -EOPNOTSUPP)

I think we should follow the same in the Intel driver and return
-ENOTSUPP too.
Michael Walle June 15, 2022, 6:10 p.m. UTC | #3
Am 15. Juni 2022 11:49:22 OEZ schrieb Mika Westerberg <mika.westerberg@linux.intel.com>:
>Hi,
>
>On Tue, Jun 14, 2022 at 05:56:54PM +0000, Oleksandr Ocheretnyi -X (oocheret - GLOBALLOGIC INC at Cisco) wrote:
>>    Hello Mika,
>> 
>>    in my case (I work with memory chip n25q128a13 for recent kernels) I'm
>>    getting return value -ENOTSUPP from spi_mem_exec_op() call in the
>>    micron_st_nor_read_fsr() method
>>    [[1]https://elixir.bootlin.com/linux/v5.19-rc2/source/drivers/spi/spi-m
>>    em.c#L326]. So I decided to provide the same errorcode to
>>    intel_spi_hw_cycle() method because older kernel versions throw the
>>    error there. It is fine to use -EOPNOTSUPP return value instead.
>> 
>>    I suspect we need to cover both cases to check -ENOTSUPP as well as
>>    -EOPNOTSUPP to let the driver work properly.
>> 
>>    if (ret == -ENOTSUPP || ret == -EOPNOTSUPP)
>
>I think we should follow the same in the Intel driver and return
>-ENOTSUPP too.

AFAIK ENOTSUPP is for nfs and shouldn't be used.

-michael
Mika Westerberg June 16, 2022, 5:29 a.m. UTC | #4
On Wed, Jun 15, 2022 at 08:10:13PM +0200, Michael Walle wrote:
> Am 15. Juni 2022 11:49:22 OEZ schrieb Mika Westerberg <mika.westerberg@linux.intel.com>:
> >Hi,
> >
> >On Tue, Jun 14, 2022 at 05:56:54PM +0000, Oleksandr Ocheretnyi -X (oocheret - GLOBALLOGIC INC at Cisco) wrote:
> >>    Hello Mika,
> >> 
> >>    in my case (I work with memory chip n25q128a13 for recent kernels) I'm
> >>    getting return value -ENOTSUPP from spi_mem_exec_op() call in the
> >>    micron_st_nor_read_fsr() method
> >>    [[1]https://elixir.bootlin.com/linux/v5.19-rc2/source/drivers/spi/spi-m
> >>    em.c#L326]. So I decided to provide the same errorcode to
> >>    intel_spi_hw_cycle() method because older kernel versions throw the
> >>    error there. It is fine to use -EOPNOTSUPP return value instead.
> >> 
> >>    I suspect we need to cover both cases to check -ENOTSUPP as well as
> >>    -EOPNOTSUPP to let the driver work properly.
> >> 
> >>    if (ret == -ENOTSUPP || ret == -EOPNOTSUPP)
> >
> >I think we should follow the same in the Intel driver and return
> >-ENOTSUPP too.
> 
> AFAIK ENOTSUPP is for nfs and shouldn't be used.

Yes, but that's what the SPI-NOR core is using so I think we want to be
consistent with it.
diff mbox series

Patch

diff --git a/drivers/mtd/spi-nor/micron-st.c b/drivers/mtd/spi-nor/micron-st.c
index a96f74e0f568..507e675d81e0 100644
--- a/drivers/mtd/spi-nor/micron-st.c
+++ b/drivers/mtd/spi-nor/micron-st.c
@@ -399,8 +399,12 @@  static int micron_st_nor_ready(struct spi_nor *nor)
 		return sr_ready;
 
 	ret = micron_st_nor_read_fsr(nor, nor->bouncebuf);
-	if (ret)
+	if (ret < 0) {
+		/* Check if read FSR is supported. If not, skip it. */
+		if (ret == -ENOTSUPP)
+			return sr_ready;
 		return ret;
+	}
 
 	if (nor->bouncebuf[0] & (FSR_E_ERR | FSR_P_ERR)) {
 		if (nor->bouncebuf[0] & FSR_E_ERR)
diff --git a/drivers/spi/spi-intel.c b/drivers/spi/spi-intel.c
index 50f42983b950..f0313a718d1b 100644
--- a/drivers/spi/spi-intel.c
+++ b/drivers/spi/spi-intel.c
@@ -352,7 +352,8 @@  static int intel_spi_hw_cycle(struct intel_spi *ispi, u8 opcode, size_t len)
 		val |= HSFSTS_CTL_FCYCLE_RDSR;
 		break;
 	default:
-		return -EINVAL;
+		dev_dbg(ispi->dev, "%#x not supported\n", opcode);
+		return -ENOTSUPP;
 	}
 
 	if (len > INTEL_SPI_FIFO_SZ)