mtd: spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write
authorAlexander Sverdlin <alexander.sverdlin@nokia.com>
Tue, 19 Mar 2019 17:18:07 +0000 (17:18 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 21 May 2019 16:50:17 +0000 (18:50 +0200)
commit 2b75ebeea6f4937d4d05ec4982c471cef9a29b7f upstream.

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.

Fixes: 8afda8b26d01 ("spi-nor: Add support for Intel SPI serial flash controller")
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>
Reviewed-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/mtd/spi-nor/intel-spi.c

index 7802ac3ba934830a674c9dc3b396f0647d26e3c9..fa2983af4d2c65d0429107f75e65356b250a3c38 100644 (file)
@@ -503,6 +503,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 */
+               block_size = min_t(loff_t, from + block_size,
+                                  round_up(from + 1, SZ_4K)) - from;
+
                writel(from, ispi->base + FADDR);
 
                val = readl(ispi->base + HSFSTS_CTL);
@@ -553,6 +557,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 */
+               block_size = min_t(loff_t, to + block_size,
+                                  round_up(to + 1, SZ_4K)) - to;
+
                writel(to, ispi->base + FADDR);
 
                val = readl(ispi->base + HSFSTS_CTL);