mtd: spi-nor: stm32-quadspi: fix prefetching outside fsize

When memory-mapped mode is used, a prefetching mechanism fully
managed by the hardware allows to optimize the read from external
the QSPI memory. A 32-bytes FIFO is used for prefetching.
When the limit of flash size - fifo size is reached the prefetching
mechanism tries to read outside the fsize.
The stm32 quadspi hardware become busy and should be aborted.

Signed-off-by: Ludovic Barre <ludovic.barre@st.com>
Reported-by: Bruno Herrera <bruherrera@gmail.com>
Tested-by: Bruno Herrera <bruherrera@gmail.com>
Signed-off-by: Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>
This commit is contained in:
Ludovic Barre 2017-10-26 17:12:34 +02:00 коммит произвёл Cyrille Pitchen
Родитель e812963b91
Коммит 10cd4b7b74
1 изменённых файлов: 11 добавлений и 1 удалений

Просмотреть файл

@ -126,6 +126,7 @@
#define STM32_MAX_MMAP_SZ SZ_256M #define STM32_MAX_MMAP_SZ SZ_256M
#define STM32_MAX_NORCHIP 2 #define STM32_MAX_NORCHIP 2
#define STM32_QSPI_FIFO_SZ 32
#define STM32_QSPI_FIFO_TIMEOUT_US 30000 #define STM32_QSPI_FIFO_TIMEOUT_US 30000
#define STM32_QSPI_BUSY_TIMEOUT_US 100000 #define STM32_QSPI_BUSY_TIMEOUT_US 100000
@ -137,6 +138,7 @@ struct stm32_qspi_flash {
u32 presc; u32 presc;
u32 read_mode; u32 read_mode;
bool registered; bool registered;
u32 prefetch_limit;
}; };
struct stm32_qspi { struct stm32_qspi {
@ -285,6 +287,7 @@ static int stm32_qspi_send(struct stm32_qspi_flash *flash,
{ {
struct stm32_qspi *qspi = flash->qspi; struct stm32_qspi *qspi = flash->qspi;
u32 ccr, dcr, cr; u32 ccr, dcr, cr;
u32 last_byte;
int err; int err;
err = stm32_qspi_wait_nobusy(qspi); err = stm32_qspi_wait_nobusy(qspi);
@ -327,6 +330,10 @@ static int stm32_qspi_send(struct stm32_qspi_flash *flash,
if (err) if (err)
goto abort; goto abort;
writel_relaxed(FCR_CTCF, qspi->io_base + QUADSPI_FCR); writel_relaxed(FCR_CTCF, qspi->io_base + QUADSPI_FCR);
} else {
last_byte = cmd->addr + cmd->len;
if (last_byte > flash->prefetch_limit)
goto abort;
} }
return err; return err;
@ -335,7 +342,9 @@ abort:
cr = readl_relaxed(qspi->io_base + QUADSPI_CR) | CR_ABORT; cr = readl_relaxed(qspi->io_base + QUADSPI_CR) | CR_ABORT;
writel_relaxed(cr, qspi->io_base + QUADSPI_CR); writel_relaxed(cr, qspi->io_base + QUADSPI_CR);
if (err)
dev_err(qspi->dev, "%s abort err:%d\n", __func__, err); dev_err(qspi->dev, "%s abort err:%d\n", __func__, err);
return err; return err;
} }
@ -563,6 +572,7 @@ static int stm32_qspi_flash_setup(struct stm32_qspi *qspi,
} }
flash->fsize = FSIZE_VAL(mtd->size); flash->fsize = FSIZE_VAL(mtd->size);
flash->prefetch_limit = mtd->size - STM32_QSPI_FIFO_SZ;
flash->read_mode = CCR_FMODE_MM; flash->read_mode = CCR_FMODE_MM;
if (mtd->size > qspi->mm_size) if (mtd->size > qspi->mm_size)