All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2] mtd: spi: Improve spi_nor_write_data() implementation
@ 2019-04-16 11:59 Rajat Srivastava
  2019-04-17 12:47 ` Vignesh Raghavendra
  0 siblings, 1 reply; 5+ messages in thread
From: Rajat Srivastava @ 2019-04-16 11:59 UTC (permalink / raw)
  To: u-boot

Maximum write size in a single write operation in
spi_nor_write_data() function can be equal to slave
tx buffer, which is adjusted in spi_mem_adjust_op_size()
and write operation gets fragmented.

Previously data write for the above fragmentation
didn't incorporate write enable and status checks.
It was sent to flash at page offsets only.

Signed-off-by: Rajat Srivastava <rajat.srivastava@nxp.com>
---
Changes in v2:
 Incorporating review comments given by Vignesh.
 [PATCH v1]: https://patchwork.ozlabs.org/patch/1078183/

 drivers/mtd/spi/spi-nor-core.c | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index c4e2f6a08f..8e754d445d 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -116,7 +116,6 @@ static ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len,
 				   SPI_MEM_OP_ADDR(nor->addr_width, to, 1),
 				   SPI_MEM_OP_NO_DUMMY,
 				   SPI_MEM_OP_DATA_OUT(len, buf, 1));
-	size_t remaining = len;
 	int ret;
 
 	/* get transfer protocols. */
@@ -127,22 +126,19 @@ static ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len,
 	if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
 		op.addr.nbytes = 0;
 
-	while (remaining) {
-		op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
-		ret = spi_mem_adjust_op_size(nor->spi, &op);
-		if (ret)
-			return ret;
+	op.data.nbytes = len < UINT_MAX ? len : UINT_MAX;
+	ret = spi_mem_adjust_op_size(nor->spi, &op);
+	if (ret)
+		return ret;
 
-		ret = spi_mem_exec_op(nor->spi, &op);
-		if (ret)
-			return ret;
+	ret = spi_mem_exec_op(nor->spi, &op);
+	if (ret)
+		return ret;
 
-		op.addr.val += op.data.nbytes;
-		remaining -= op.data.nbytes;
-		op.data.buf.out += op.data.nbytes;
-	}
+	op.addr.val += op.data.nbytes;
+	op.data.buf.out += op.data.nbytes;
 
-	return len;
+	return op.data.nbytes;
 }
 
 /*
@@ -1101,10 +1097,6 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 			goto write_err;
 		*retlen += written;
 		i += written;
-		if (written != page_remain) {
-			ret = -EIO;
-			goto write_err;
-		}
 	}
 
 write_err:
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v2] mtd: spi: Improve spi_nor_write_data() implementation
  2019-04-16 11:59 [U-Boot] [PATCH v2] mtd: spi: Improve spi_nor_write_data() implementation Rajat Srivastava
@ 2019-04-17 12:47 ` Vignesh Raghavendra
  2019-04-18 11:53   ` [U-Boot] [EXT] " Rajat Srivastava
  2019-05-17  7:49   ` Ashish Kumar
  0 siblings, 2 replies; 5+ messages in thread
From: Vignesh Raghavendra @ 2019-04-17 12:47 UTC (permalink / raw)
  To: u-boot



On 16/04/19 5:29 PM, Rajat Srivastava wrote:
> Maximum write size in a single write operation in
> spi_nor_write_data() function can be equal to slave
> tx buffer, which is adjusted in spi_mem_adjust_op_size()
> and write operation gets fragmented.
> 
> Previously data write for the above fragmentation
> didn't incorporate write enable and status checks.
> It was sent to flash at page offsets only.
> 
> Signed-off-by: Rajat Srivastava <rajat.srivastava@nxp.com>
> ---
> Changes in v2:
>   Incorporating review comments given by Vignesh.
>   [PATCH v1]: https://patchwork.ozlabs.org/patch/1078183/

Changes look good as such, but I cannot seem to apply these patch 
locally as mbox for testing. Looking at mail source, it seems to be sent 
in binary format instead of plain text. Could you resend in plain text?	

> 
>   drivers/mtd/spi/spi-nor-core.c | 28 ++++++++++------------------
>   1 file changed, 10 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
> index c4e2f6a08f..8e754d445d 100644
> --- a/drivers/mtd/spi/spi-nor-core.c
> +++ b/drivers/mtd/spi/spi-nor-core.c
> @@ -116,7 +116,6 @@ static ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len,
>   				   SPI_MEM_OP_ADDR(nor->addr_width, to, 1),
>   				   SPI_MEM_OP_NO_DUMMY,
>   				   SPI_MEM_OP_DATA_OUT(len, buf, 1));
> -	size_t remaining = len;
>   	int ret;
>   
>   	/* get transfer protocols. */
> @@ -127,22 +126,19 @@ static ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len,
>   	if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
>   		op.addr.nbytes = 0;
>   
> -	while (remaining) {
> -		op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
> -		ret = spi_mem_adjust_op_size(nor->spi, &op);
> -		if (ret)
> -			return ret;
> +	op.data.nbytes = len < UINT_MAX ? len : UINT_MAX;
> +	ret = spi_mem_adjust_op_size(nor->spi, &op);
> +	if (ret)
> +		return ret;
>   
> -		ret = spi_mem_exec_op(nor->spi, &op);
> -		if (ret)
> -			return ret;
> +	ret = spi_mem_exec_op(nor->spi, &op);
> +	if (ret)
> +		return ret;
>   
> -		op.addr.val += op.data.nbytes;
> -		remaining -= op.data.nbytes;
> -		op.data.buf.out += op.data.nbytes;
> -	}
> +	op.addr.val += op.data.nbytes;
> +	op.data.buf.out += op.data.nbytes;
>   
> -	return len;
> +	return op.data.nbytes;
>   }
>   
>   /*
> @@ -1101,10 +1097,6 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
>   			goto write_err;
>   		*retlen += written;
>   		i += written;
> -		if (written != page_remain) {
> -			ret = -EIO;
> -			goto write_err;
> -		}
>   	}
>   
>   write_err:
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [EXT] Re: [PATCH v2] mtd: spi: Improve spi_nor_write_data() implementation
  2019-04-17 12:47 ` Vignesh Raghavendra
@ 2019-04-18 11:53   ` Rajat Srivastava
  2019-05-17  7:49   ` Ashish Kumar
  1 sibling, 0 replies; 5+ messages in thread
From: Rajat Srivastava @ 2019-04-18 11:53 UTC (permalink / raw)
  To: u-boot



> -----Original Message-----
> From: Vignesh Raghavendra <vigneshr@ti.com>
> Sent: Wednesday, April 17, 2019 6:18 PM
> To: Rajat Srivastava <rajat.srivastava@nxp.com>; u-boot at lists.denx.de;
> trini at konsulko.com; marek.vasut at gmail.com;
> marek.vasut+renesas at gmail.com; jagan at openedev.com
> Cc: Ashish Kumar <ashish.kumar@nxp.com>
> Subject: [EXT] Re: [PATCH v2] mtd: spi: Improve spi_nor_write_data()
> implementation
> 
> WARNING: This email was created outside of NXP. DO NOT CLICK links or
> attachments unless you recognize the sender and know the content is safe.
> 
> 
> 
> On 16/04/19 5:29 PM, Rajat Srivastava wrote:
> > Maximum write size in a single write operation in
> > spi_nor_write_data() function can be equal to slave tx buffer, which
> > is adjusted in spi_mem_adjust_op_size() and write operation gets
> > fragmented.
> >
> > Previously data write for the above fragmentation didn't incorporate
> > write enable and status checks.
> > It was sent to flash at page offsets only.
> >
> > Signed-off-by: Rajat Srivastava <rajat.srivastava@nxp.com>
> > ---
> > Changes in v2:
> >   Incorporating review comments given by Vignesh.
> >   [PATCH v1]:
> >
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatc
> >
> hwork.ozlabs.org%2Fpatch%2F1078183%2F&amp;data=02%7C01%7Crajat.sri
> vast
> >
> ava%40nxp.com%7C774c432160da4264b0a308d6c332e381%7C686ea1d3bc2b
> 4c6fa92
> >
> cd99c5c301635%7C0%7C0%7C636911020672017024&amp;sdata=Kl3XDugF05y
> g4UiLk
> > rrBptYDm2TFTZMFhIMOEF9Znjw%3D&amp;reserved=0
> 
> Changes look good as such, but I cannot seem to apply these patch locally as
> mbox for testing. Looking at mail source, it seems to be sent in binary format
> instead of plain text. Could you resend in plain text?

This looks like an issue with using outlook.office365.com as smtp server, since the
the patch is getting corrupt even when I am sending it again.
I'm working with IT team here to resolve this.

Regards
Rajat

> 
> >
> >   drivers/mtd/spi/spi-nor-core.c | 28 ++++++++++------------------
> >   1 file changed, 10 insertions(+), 18 deletions(-)
> >
> > diff --git a/drivers/mtd/spi/spi-nor-core.c
> > b/drivers/mtd/spi/spi-nor-core.c index c4e2f6a08f..8e754d445d 100644
> > --- a/drivers/mtd/spi/spi-nor-core.c
> > +++ b/drivers/mtd/spi/spi-nor-core.c
> > @@ -116,7 +116,6 @@ static ssize_t spi_nor_write_data(struct spi_nor
> *nor, loff_t to, size_t len,
> >                                  SPI_MEM_OP_ADDR(nor->addr_width, to, 1),
> >                                  SPI_MEM_OP_NO_DUMMY,
> >                                  SPI_MEM_OP_DATA_OUT(len, buf, 1));
> > -     size_t remaining = len;
> >       int ret;
> >
> >       /* get transfer protocols. */
> > @@ -127,22 +126,19 @@ static ssize_t spi_nor_write_data(struct spi_nor
> *nor, loff_t to, size_t len,
> >       if (nor->program_opcode == SPINOR_OP_AAI_WP && nor-
> >sst_write_second)
> >               op.addr.nbytes = 0;
> >
> > -     while (remaining) {
> > -             op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
> > -             ret = spi_mem_adjust_op_size(nor->spi, &op);
> > -             if (ret)
> > -                     return ret;
> > +     op.data.nbytes = len < UINT_MAX ? len : UINT_MAX;
> > +     ret = spi_mem_adjust_op_size(nor->spi, &op);
> > +     if (ret)
> > +             return ret;
> >
> > -             ret = spi_mem_exec_op(nor->spi, &op);
> > -             if (ret)
> > -                     return ret;
> > +     ret = spi_mem_exec_op(nor->spi, &op);
> > +     if (ret)
> > +             return ret;
> >
> > -             op.addr.val += op.data.nbytes;
> > -             remaining -= op.data.nbytes;
> > -             op.data.buf.out += op.data.nbytes;
> > -     }
> > +     op.addr.val += op.data.nbytes;
> > +     op.data.buf.out += op.data.nbytes;
> >
> > -     return len;
> > +     return op.data.nbytes;
> >   }
> >
> >   /*
> > @@ -1101,10 +1097,6 @@ static int spi_nor_write(struct mtd_info *mtd,
> loff_t to, size_t len,
> >                       goto write_err;
> >               *retlen += written;
> >               i += written;
> > -             if (written != page_remain) {
> > -                     ret = -EIO;
> > -                     goto write_err;
> > -             }
> >       }
> >
> >   write_err:
> >

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [EXT] Re: [PATCH v2] mtd: spi: Improve spi_nor_write_data() implementation
  2019-04-17 12:47 ` Vignesh Raghavendra
  2019-04-18 11:53   ` [U-Boot] [EXT] " Rajat Srivastava
@ 2019-05-17  7:49   ` Ashish Kumar
  2019-05-17 14:34     ` Vignesh Raghavendra
  1 sibling, 1 reply; 5+ messages in thread
From: Ashish Kumar @ 2019-05-17  7:49 UTC (permalink / raw)
  To: u-boot



> -----Original Message-----
> From: Vignesh Raghavendra <vigneshr@ti.com>
> Sent: Wednesday, April 17, 2019 6:18 PM
> To: Rajat Srivastava <rajat.srivastava@nxp.com>; u-boot at lists.denx.de;
> trini at konsulko.com; marek.vasut at gmail.com;
> marek.vasut+renesas at gmail.com; jagan at openedev.com
> Cc: Ashish Kumar <ashish.kumar@nxp.com>
> Subject: [EXT] Re: [PATCH v2] mtd: spi: Improve spi_nor_write_data()
> implementation
> 
> WARNING: This email was created outside of NXP. DO NOT CLICK links or
> attachments unless you recognize the sender and know the content is safe.
> 
> 
> 
> On 16/04/19 5:29 PM, Rajat Srivastava wrote:
> > Maximum write size in a single write operation in
> > spi_nor_write_data() function can be equal to slave tx buffer, which
> > is adjusted in spi_mem_adjust_op_size() and write operation gets
> > fragmented.
> >
> > Previously data write for the above fragmentation didn't incorporate
> > write enable and status checks.
> > It was sent to flash at page offsets only.
> >
> > Signed-off-by: Rajat Srivastava <rajat.srivastava@nxp.com>
> > ---
> > Changes in v2:
> >   Incorporating review comments given by Vignesh.
> >   [PATCH v1]:
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatc
> >
> hwork.ozlabs.org%2Fpatch%2F1078183%2F&amp;data=02%7C01%7Cashish.
> kumar%
> >
> 40nxp.com%7C774c432160da4264b0a308d6c332e381%7C686ea1d3bc2b4c6
> fa92cd99
> >
> c5c301635%7C0%7C0%7C636911020672697602&amp;sdata=EK3zMXmkMdl
> cft04mh8GK
> > EkX6G8JpImEk7YK1SH%2FxQ8%3D&amp;reserved=0
> 
> Changes look good as such, but I cannot seem to apply these patch locally as
> mbox for testing. Looking at mail source, it seems to be sent in binary format
> instead of plain text. Could you resend in plain text?

Hi Vignesh

Is this taken care now, plain text version was posted here
http://patchwork.ozlabs.org/patch/1090121/

Regards
Ashish 

> 
> >
> >   drivers/mtd/spi/spi-nor-core.c | 28 ++++++++++------------------
> >   1 file changed, 10 insertions(+), 18 deletions(-)
> >
> > diff --git a/drivers/mtd/spi/spi-nor-core.c
> > b/drivers/mtd/spi/spi-nor-core.c index c4e2f6a08f..8e754d445d 100644
> > --- a/drivers/mtd/spi/spi-nor-core.c
> > +++ b/drivers/mtd/spi/spi-nor-core.c
> > @@ -116,7 +116,6 @@ static ssize_t spi_nor_write_data(struct spi_nor
> *nor, loff_t to, size_t len,
> >                                  SPI_MEM_OP_ADDR(nor->addr_width, to, 1),
> >                                  SPI_MEM_OP_NO_DUMMY,
> >                                  SPI_MEM_OP_DATA_OUT(len, buf, 1));
> > -     size_t remaining = len;
> >       int ret;
> >
> >       /* get transfer protocols. */
> > @@ -127,22 +126,19 @@ static ssize_t spi_nor_write_data(struct spi_nor
> *nor, loff_t to, size_t len,
> >       if (nor->program_opcode == SPINOR_OP_AAI_WP && nor-
> >sst_write_second)
> >               op.addr.nbytes = 0;
> >
> > -     while (remaining) {
> > -             op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
> > -             ret = spi_mem_adjust_op_size(nor->spi, &op);
> > -             if (ret)
> > -                     return ret;
> > +     op.data.nbytes = len < UINT_MAX ? len : UINT_MAX;
> > +     ret = spi_mem_adjust_op_size(nor->spi, &op);
> > +     if (ret)
> > +             return ret;
> >
> > -             ret = spi_mem_exec_op(nor->spi, &op);
> > -             if (ret)
> > -                     return ret;
> > +     ret = spi_mem_exec_op(nor->spi, &op);
> > +     if (ret)
> > +             return ret;
> >
> > -             op.addr.val += op.data.nbytes;
> > -             remaining -= op.data.nbytes;
> > -             op.data.buf.out += op.data.nbytes;
> > -     }
> > +     op.addr.val += op.data.nbytes;
> > +     op.data.buf.out += op.data.nbytes;
> >
> > -     return len;
> > +     return op.data.nbytes;
> >   }
> >
> >   /*
> > @@ -1101,10 +1097,6 @@ static int spi_nor_write(struct mtd_info *mtd,
> loff_t to, size_t len,
> >                       goto write_err;
> >               *retlen += written;
> >               i += written;
> > -             if (written != page_remain) {
> > -                     ret = -EIO;
> > -                     goto write_err;
> > -             }
> >       }
> >
> >   write_err:
> >

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [EXT] Re: [PATCH v2] mtd: spi: Improve spi_nor_write_data() implementation
  2019-05-17  7:49   ` Ashish Kumar
@ 2019-05-17 14:34     ` Vignesh Raghavendra
  0 siblings, 0 replies; 5+ messages in thread
From: Vignesh Raghavendra @ 2019-05-17 14:34 UTC (permalink / raw)
  To: u-boot

Hi Ashish,

> Hi Vignesh
> 

> Is this taken care now, plain text version was posted here
> http://patchwork.ozlabs.org/patch/1090121/
> 

A similar patch[1] was proposed in meantime which has been merged to
mainline U-Boot. So this issue must now be resolved. Let me know if the
issue still persists.


[1]
commit 60e2bf46784ebbd30ff29b3d3c7c97e56b11e86a
Author: Weijie Gao <weijie.gao@mediatek.com>
Date:   Fri Apr 26 17:22:19 2019 +0800

    mtd: spi-nor: fix page program issue when using spi-mem driver



> Regards
> Ashish 
> 
>>
>>>
>>>   drivers/mtd/spi/spi-nor-core.c | 28 ++++++++++------------------
>>>   1 file changed, 10 insertions(+), 18 deletions(-)
>>>
>>> diff --git a/drivers/mtd/spi/spi-nor-core.c
>>> b/drivers/mtd/spi/spi-nor-core.c index c4e2f6a08f..8e754d445d 100644
>>> --- a/drivers/mtd/spi/spi-nor-core.c
>>> +++ b/drivers/mtd/spi/spi-nor-core.c
>>> @@ -116,7 +116,6 @@ static ssize_t spi_nor_write_data(struct spi_nor
>> *nor, loff_t to, size_t len,
>>>                                  SPI_MEM_OP_ADDR(nor->addr_width, to, 1),
>>>                                  SPI_MEM_OP_NO_DUMMY,
>>>                                  SPI_MEM_OP_DATA_OUT(len, buf, 1));
>>> -     size_t remaining = len;
>>>       int ret;
>>>
>>>       /* get transfer protocols. */
>>> @@ -127,22 +126,19 @@ static ssize_t spi_nor_write_data(struct spi_nor
>> *nor, loff_t to, size_t len,
>>>       if (nor->program_opcode == SPINOR_OP_AAI_WP && nor-
>>> sst_write_second)
>>>               op.addr.nbytes = 0;
>>>
>>> -     while (remaining) {
>>> -             op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
>>> -             ret = spi_mem_adjust_op_size(nor->spi, &op);
>>> -             if (ret)
>>> -                     return ret;
>>> +     op.data.nbytes = len < UINT_MAX ? len : UINT_MAX;
>>> +     ret = spi_mem_adjust_op_size(nor->spi, &op);
>>> +     if (ret)
>>> +             return ret;
>>>
>>> -             ret = spi_mem_exec_op(nor->spi, &op);
>>> -             if (ret)
>>> -                     return ret;
>>> +     ret = spi_mem_exec_op(nor->spi, &op);
>>> +     if (ret)
>>> +             return ret;
>>>
>>> -             op.addr.val += op.data.nbytes;
>>> -             remaining -= op.data.nbytes;
>>> -             op.data.buf.out += op.data.nbytes;
>>> -     }
>>> +     op.addr.val += op.data.nbytes;
>>> +     op.data.buf.out += op.data.nbytes;
>>>
>>> -     return len;
>>> +     return op.data.nbytes;
>>>   }
>>>
>>>   /*
>>> @@ -1101,10 +1097,6 @@ static int spi_nor_write(struct mtd_info *mtd,
>> loff_t to, size_t len,
>>>                       goto write_err;
>>>               *retlen += written;
>>>               i += written;
>>> -             if (written != page_remain) {
>>> -                     ret = -EIO;
>>> -                     goto write_err;
>>> -             }
>>>       }
>>>
>>>   write_err:
>>>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-05-17 14:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-16 11:59 [U-Boot] [PATCH v2] mtd: spi: Improve spi_nor_write_data() implementation Rajat Srivastava
2019-04-17 12:47 ` Vignesh Raghavendra
2019-04-18 11:53   ` [U-Boot] [EXT] " Rajat Srivastava
2019-05-17  7:49   ` Ashish Kumar
2019-05-17 14:34     ` Vignesh Raghavendra

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.