linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write
@ 2019-02-26 11:23 Sverdlin, Alexander (Nokia - DE/Ulm)
  2019-02-26 11:31 ` Mika Westerberg
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Sverdlin, Alexander (Nokia - DE/Ulm) @ 2019-02-26 11:23 UTC (permalink / raw)
  To: linux-mtd
  Cc: Porte, Romain (Nokia - FR/Paris-Saclay),
	Bin Meng, Mika Westerberg, Boris Brezillon, Richard Weinberger,
	Tudor Ambarus, stable, Marek Vasut, Sverdlin,
	Alexander (Nokia - DE/Ulm),
	Fabreges, Pascal (Nokia - FR/Paris-Saclay),
	Brian Norris, David Woodhouse

It was observed that reads crossing 4K address boundary are failing.

This limitation is mentioned in Intel documents:

Intel(R) 9 Series Chipset Family Platform Controller Hub (PCH) Datasheet:

"5.26.3 Flash Access
Program Register Access:
* Program Register Accesses are not allowed to cross a 4 KB boundary..."

Enhanced Serial Peripheral Interface (eSPI)
Interface Base Specification (for Client and Server Platforms):

"5.1.4 Address
For other memory transactions, the address may start or end at any byte
boundary. However, the address and payload length combination must not
cross the naturally aligned address boundary of the corresponding Maximum
Payload Size. It must not cross a 4 KB address boundary."

Avoid this by splitting an operation crossing the boundary into two
operations.

Cc: stable@vger.kernel.org
Reported-by: Romain Porte <romain.porte@nokia.com>
Tested-by: Pascal Fabreges <pascal.fabreges@nokia.com>
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
---
 drivers/mtd/spi-nor/intel-spi.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/mtd/spi-nor/intel-spi.c b/drivers/mtd/spi-nor/intel-spi.c
index af0a220..b83ea79 100644
--- a/drivers/mtd/spi-nor/intel-spi.c
+++ b/drivers/mtd/spi-nor/intel-spi.c
@@ -632,6 +632,10 @@ static ssize_t intel_spi_read(struct spi_nor *nor, loff_t from, size_t len,
 	while (len > 0) {
 		block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ);
 
+		/* Read cannot cross 4K boundary */
+		if ((from ^ (from + block_size - 1)) & ~(SZ_4K - 1LL))
+			block_size -= (from + block_size) & (SZ_4K - 1);
+
 		writel(from, ispi->base + FADDR);
 
 		val = readl(ispi->base + HSFSTS_CTL);
@@ -685,6 +689,10 @@ static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len,
 	while (len > 0) {
 		block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ);
 
+		/* Write cannot cross 4K boundary */
+		if ((to ^ (to + block_size - 1)) & ~(SZ_4K - 1LL))
+			block_size -= (to + block_size) & (SZ_4K - 1);
+
 		writel(to, ispi->base + FADDR);
 
 		val = readl(ispi->base + HSFSTS_CTL);
-- 
2.4.6


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write
  2019-02-26 11:23 [PATCH] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write Sverdlin, Alexander (Nokia - DE/Ulm)
@ 2019-02-26 11:31 ` Mika Westerberg
  2019-02-27  9:57 ` [PATCH v2] " Sverdlin, Alexander (Nokia - DE/Ulm)
  2019-02-27 13:23 ` [PATCH] " Sasha Levin
  2 siblings, 0 replies; 7+ messages in thread
From: Mika Westerberg @ 2019-02-26 11:31 UTC (permalink / raw)
  To: Sverdlin, Alexander (Nokia - DE/Ulm)
  Cc: Bin Meng, Porte, Romain (Nokia - FR/Paris-Saclay),
	Boris Brezillon, Richard Weinberger, Tudor Ambarus, stable,
	Marek Vasut, linux-mtd, Fabreges,
	Pascal (Nokia - FR/Paris-Saclay),
	Brian Norris, David Woodhouse

On Tue, Feb 26, 2019 at 11:23:49AM +0000, Sverdlin, Alexander (Nokia - DE/Ulm) wrote:
> It was observed that reads crossing 4K address boundary are failing.
> 
> This limitation is mentioned in Intel documents:
> 
> Intel(R) 9 Series Chipset Family Platform Controller Hub (PCH) Datasheet:
> 
> "5.26.3 Flash Access
> Program Register Access:
> * Program Register Accesses are not allowed to cross a 4 KB boundary..."
> 
> Enhanced Serial Peripheral Interface (eSPI)
> Interface Base Specification (for Client and Server Platforms):
> 
> "5.1.4 Address
> For other memory transactions, the address may start or end at any byte
> boundary. However, the address and payload length combination must not
> cross the naturally aligned address boundary of the corresponding Maximum
> Payload Size. It must not cross a 4 KB address boundary."
> 
> Avoid this by splitting an operation crossing the boundary into two
> operations.
> 
> Cc: stable@vger.kernel.org
> Reported-by: Romain Porte <romain.porte@nokia.com>
> Tested-by: Pascal Fabreges <pascal.fabreges@nokia.com>
> Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
> ---
>  drivers/mtd/spi-nor/intel-spi.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/mtd/spi-nor/intel-spi.c b/drivers/mtd/spi-nor/intel-spi.c
> index af0a220..b83ea79 100644
> --- a/drivers/mtd/spi-nor/intel-spi.c
> +++ b/drivers/mtd/spi-nor/intel-spi.c
> @@ -632,6 +632,10 @@ static ssize_t intel_spi_read(struct spi_nor *nor, loff_t from, size_t len,
>  	while (len > 0) {
>  		block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ);
>  
> +		/* Read cannot cross 4K boundary */
> +		if ((from ^ (from + block_size - 1)) & ~(SZ_4K - 1LL))

Don't we have existing macros in kernel.h that can be used here and
below?

> +			block_size -= (from + block_size) & (SZ_4K - 1);
> +
>  		writel(from, ispi->base + FADDR);
>  
>  		val = readl(ispi->base + HSFSTS_CTL);
> @@ -685,6 +689,10 @@ static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len,
>  	while (len > 0) {
>  		block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ);
>  
> +		/* Write cannot cross 4K boundary */
> +		if ((to ^ (to + block_size - 1)) & ~(SZ_4K - 1LL))
> +			block_size -= (to + block_size) & (SZ_4K - 1);
> +
>  		writel(to, ispi->base + FADDR);
>  
>  		val = readl(ispi->base + HSFSTS_CTL);
> -- 
> 2.4.6

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v2] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write
  2019-02-26 11:23 [PATCH] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write Sverdlin, Alexander (Nokia - DE/Ulm)
  2019-02-26 11:31 ` Mika Westerberg
@ 2019-02-27  9:57 ` Sverdlin, Alexander (Nokia - DE/Ulm)
  2019-02-27 10:27   ` Mika Westerberg
  2019-03-01 21:22   ` Sasha Levin
  2019-02-27 13:23 ` [PATCH] " Sasha Levin
  2 siblings, 2 replies; 7+ messages in thread
From: Sverdlin, Alexander (Nokia - DE/Ulm) @ 2019-02-27  9:57 UTC (permalink / raw)
  To: linux-mtd
  Cc: Porte, Romain (Nokia - FR/Paris-Saclay),
	Bin Meng, Mika Westerberg, Boris Brezillon, Richard Weinberger,
	Tudor Ambarus, stable, Marek Vasut, Sverdlin,
	Alexander (Nokia - DE/Ulm),
	Fabreges, Pascal (Nokia - FR/Paris-Saclay),
	Brian Norris, David Woodhouse

It was observed that reads crossing 4K address boundary are failing.

This limitation is mentioned in Intel documents:

Intel(R) 9 Series Chipset Family Platform Controller Hub (PCH) Datasheet:

"5.26.3 Flash Access
Program Register Access:
* Program Register Accesses are not allowed to cross a 4 KB boundary..."

Enhanced Serial Peripheral Interface (eSPI)
Interface Base Specification (for Client and Server Platforms):

"5.1.4 Address
For other memory transactions, the address may start or end at any byte
boundary. However, the address and payload length combination must not
cross the naturally aligned address boundary of the corresponding Maximum
Payload Size. It must not cross a 4 KB address boundary."

Avoid this by splitting an operation crossing the boundary into two
operations.

Cc: stable@vger.kernel.org
Reported-by: Romain Porte <romain.porte@nokia.com>
Tested-by: Pascal Fabreges <pascal.fabreges@nokia.com>
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
---
Changelog:
v2:	More macros! As Mika suggested.

 drivers/mtd/spi-nor/intel-spi.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/mtd/spi-nor/intel-spi.c b/drivers/mtd/spi-nor/intel-spi.c
index af0a220..8c279c4 100644
--- a/drivers/mtd/spi-nor/intel-spi.c
+++ b/drivers/mtd/spi-nor/intel-spi.c
@@ -632,6 +632,10 @@ static ssize_t intel_spi_read(struct spi_nor *nor, loff_t from, size_t len,
 	while (len > 0) {
 		block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ);
 
+		/* Read cannot cross 4K boundary */
+		blocksize = min(from + block_size, round_up(from + 1, SZ_4K)) -
+			    from;
+
 		writel(from, ispi->base + FADDR);
 
 		val = readl(ispi->base + HSFSTS_CTL);
@@ -685,6 +689,9 @@ static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len,
 	while (len > 0) {
 		block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ);
 
+		/* Write cannot cross 4K boundary */
+		blocksize = min(to + block_size, round_up(to + 1, SZ_4K)) - to;
+
 		writel(to, ispi->base + FADDR);
 
 		val = readl(ispi->base + HSFSTS_CTL);
-- 
2.4.6


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v2] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write
  2019-02-27  9:57 ` [PATCH v2] " Sverdlin, Alexander (Nokia - DE/Ulm)
@ 2019-02-27 10:27   ` Mika Westerberg
  2019-02-27 13:29     ` Sverdlin, Alexander (Nokia - DE/Ulm)
  2019-03-01 21:22   ` Sasha Levin
  1 sibling, 1 reply; 7+ messages in thread
From: Mika Westerberg @ 2019-02-27 10:27 UTC (permalink / raw)
  To: Sverdlin, Alexander (Nokia - DE/Ulm)
  Cc: Bin Meng, Porte, Romain (Nokia - FR/Paris-Saclay),
	Boris Brezillon, Richard Weinberger, Tudor Ambarus, stable,
	Marek Vasut, linux-mtd, Fabreges,
	Pascal (Nokia - FR/Paris-Saclay),
	Brian Norris, David Woodhouse

On Wed, Feb 27, 2019 at 09:57:15AM +0000, Sverdlin, Alexander (Nokia - DE/Ulm) wrote:
> It was observed that reads crossing 4K address boundary are failing.
> 
> This limitation is mentioned in Intel documents:
> 
> Intel(R) 9 Series Chipset Family Platform Controller Hub (PCH) Datasheet:
> 
> "5.26.3 Flash Access
> Program Register Access:
> * Program Register Accesses are not allowed to cross a 4 KB boundary..."
> 
> Enhanced Serial Peripheral Interface (eSPI)
> Interface Base Specification (for Client and Server Platforms):
> 
> "5.1.4 Address
> For other memory transactions, the address may start or end at any byte
> boundary. However, the address and payload length combination must not
> cross the naturally aligned address boundary of the corresponding Maximum
> Payload Size. It must not cross a 4 KB address boundary."
> 
> Avoid this by splitting an operation crossing the boundary into two
> operations.
> 
> Cc: stable@vger.kernel.org
> Reported-by: Romain Porte <romain.porte@nokia.com>
> Tested-by: Pascal Fabreges <pascal.fabreges@nokia.com>
> Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
> ---
> Changelog:
> v2:	More macros! As Mika suggested.
> 
>  drivers/mtd/spi-nor/intel-spi.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/mtd/spi-nor/intel-spi.c b/drivers/mtd/spi-nor/intel-spi.c
> index af0a220..8c279c4 100644
> --- a/drivers/mtd/spi-nor/intel-spi.c
> +++ b/drivers/mtd/spi-nor/intel-spi.c
> @@ -632,6 +632,10 @@ static ssize_t intel_spi_read(struct spi_nor *nor, loff_t from, size_t len,
>  	while (len > 0) {
>  		block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ);
>  
> +		/* Read cannot cross 4K boundary */
> +		blocksize = min(from + block_size, round_up(from + 1, SZ_4K)) -
> +			    from;

Nit:

It looks better if you put it into one line like:

		blocksize = min(from + block_size, round_up(from + 1, SZ_4K)) - from;


Regardless of that,

Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write
  2019-02-26 11:23 [PATCH] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write Sverdlin, Alexander (Nokia - DE/Ulm)
  2019-02-26 11:31 ` Mika Westerberg
  2019-02-27  9:57 ` [PATCH v2] " Sverdlin, Alexander (Nokia - DE/Ulm)
@ 2019-02-27 13:23 ` Sasha Levin
  2 siblings, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2019-02-27 13:23 UTC (permalink / raw)
  To: Sasha Levin, Sverdlin, Alexander (Nokia - DE/Ulm), linux-mtd
  Cc: , Sverdlin, Alexander (Nokia - DE/Ulm), stable

Hi,

[This is an automated email]

This commit has been processed because it contains a -stable tag.
The stable tag indicates that it's relevant for the following trees: all

The bot has tested the following trees: v4.20.12, v4.19.25, v4.14.103, v4.9.160, v4.4.176, v3.18.136.

v4.20.12: Build OK!
v4.19.25: Build OK!
v4.14.103: Build OK!
v4.9.160: Failed to apply! Possible dependencies:
    8afda8b26d01 ("spi-nor: Add support for Intel SPI serial flash controller")

v4.4.176: Failed to apply! Possible dependencies:
    8afda8b26d01 ("spi-nor: Add support for Intel SPI serial flash controller")

v3.18.136: Failed to apply! Possible dependencies:
    8afda8b26d01 ("spi-nor: Add support for Intel SPI serial flash controller")
    f617b9587c16 ("mtd: spi-nor: add driver for NXP SPI Flash Interface (SPIFI)")


How should we proceed with this patch?

--
Thanks,
Sasha

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v2] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write
  2019-02-27 10:27   ` Mika Westerberg
@ 2019-02-27 13:29     ` Sverdlin, Alexander (Nokia - DE/Ulm)
  0 siblings, 0 replies; 7+ messages in thread
From: Sverdlin, Alexander (Nokia - DE/Ulm) @ 2019-02-27 13:29 UTC (permalink / raw)
  To: Mika Westerberg
  Cc: Bin Meng, Porte, Romain (Nokia - FR/Paris-Saclay),
	Boris Brezillon, Richard Weinberger, Tudor Ambarus, stable,
	Marek Vasut, linux-mtd, Fabreges,
	Pascal (Nokia - FR/Paris-Saclay),
	Brian Norris, David Woodhouse

Hello Mika and all,

On 27/02/2019 11:27, Mika Westerberg wrote:
> On Wed, Feb 27, 2019 at 09:57:15AM +0000, Sverdlin, Alexander (Nokia - DE/Ulm) wrote:
>> It was observed that reads crossing 4K address boundary are failing.

[...]

>> Reported-by: Romain Porte <romain.porte@nokia.com>
>> Tested-by: Pascal Fabreges <pascal.fabreges@nokia.com>
>> Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
>> ---
>> Changelog:
>> v2:	More macros! As Mika suggested.
>>
>>  drivers/mtd/spi-nor/intel-spi.c | 7 +++++++
>>  1 file changed, 7 insertions(+)
>>
>> diff --git a/drivers/mtd/spi-nor/intel-spi.c b/drivers/mtd/spi-nor/intel-spi.c
>> index af0a220..8c279c4 100644
>> --- a/drivers/mtd/spi-nor/intel-spi.c
>> +++ b/drivers/mtd/spi-nor/intel-spi.c
>> @@ -632,6 +632,10 @@ static ssize_t intel_spi_read(struct spi_nor *nor, loff_t from, size_t len,
>>  	while (len > 0) {
>>  		block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ);
>>  
>> +		/* Read cannot cross 4K boundary */
>> +		blocksize = min(from + block_size, round_up(from + 1, SZ_4K)) -
>> +			    from;
> 
> Nit:
> 
> It looks better if you put it into one line like:
> 
> 		blocksize = min(from + block_size, round_up(from + 1, SZ_4K)) - from;
> 
> 
> Regardless of that,
> 
> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

Please ignore v2!
There was a failure in build/test process on my side.
I will send v3.

-- 
Best regards,
Alexander Sverdlin.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v2] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write
  2019-02-27  9:57 ` [PATCH v2] " Sverdlin, Alexander (Nokia - DE/Ulm)
  2019-02-27 10:27   ` Mika Westerberg
@ 2019-03-01 21:22   ` Sasha Levin
  1 sibling, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2019-03-01 21:22 UTC (permalink / raw)
  To: Sasha Levin, Sverdlin, Alexander (Nokia - DE/Ulm), linux-mtd
  Cc: , Sverdlin, Alexander (Nokia - DE/Ulm), stable

[-- Attachment #1: Type: text/plain, Size: 1741 bytes --]

Hi,

[This is an automated email]

This commit has been processed because it contains a -stable tag.
The stable tag indicates that it's relevant for the following trees: all

The bot has tested the following trees: v4.20.13, v4.19.26, v4.14.104, v4.9.161, v4.4.176, v3.18.136.

v4.20.13: Build failed! Errors:
    drivers/mtd/spi-nor/intel-spi.c:636:3: error: ‘blocksize’ undeclared (first use in this function); did you mean ‘block_size’?
    drivers/mtd/spi-nor/intel-spi.c:693:3: error: ‘blocksize’ undeclared (first use in this function); did you mean ‘block_size’?

v4.19.26: Build failed! Errors:
    drivers/mtd/spi-nor/intel-spi.c:636:3: error: ‘blocksize’ undeclared (first use in this function); did you mean ‘block_size’?
    drivers/mtd/spi-nor/intel-spi.c:693:3: error: ‘blocksize’ undeclared (first use in this function); did you mean ‘block_size’?

v4.14.104: Build failed! Errors:
    drivers/mtd/spi-nor/intel-spi.c:507:3: error: ‘blocksize’ undeclared (first use in this function); did you mean ‘block_size’?
    drivers/mtd/spi-nor/intel-spi.c:561:3: error: ‘blocksize’ undeclared (first use in this function); did you mean ‘block_size’?

v4.9.161: Failed to apply! Possible dependencies:
    8afda8b26d01 ("spi-nor: Add support for Intel SPI serial flash controller")

v4.4.176: Failed to apply! Possible dependencies:
    8afda8b26d01 ("spi-nor: Add support for Intel SPI serial flash controller")

v3.18.136: Failed to apply! Possible dependencies:
    8afda8b26d01 ("spi-nor: Add support for Intel SPI serial flash controller")
    f617b9587c16 ("mtd: spi-nor: add driver for NXP SPI Flash Interface (SPIFI)")


How should we proceed with this patch?

--
Thanks,
Sasha


[-- Attachment #2: Type: text/plain, Size: 144 bytes --]

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

end of thread, other threads:[~2019-03-01 21:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-26 11:23 [PATCH] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write Sverdlin, Alexander (Nokia - DE/Ulm)
2019-02-26 11:31 ` Mika Westerberg
2019-02-27  9:57 ` [PATCH v2] " Sverdlin, Alexander (Nokia - DE/Ulm)
2019-02-27 10:27   ` Mika Westerberg
2019-02-27 13:29     ` Sverdlin, Alexander (Nokia - DE/Ulm)
2019-03-01 21:22   ` Sasha Levin
2019-02-27 13:23 ` [PATCH] " Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).