Skip to content

Commit be92ab2

Browse files
Bence Csókásbroonie
authored andcommitted
spi: atmel-qspi: Memory barriers after memory-mapped I/O
The QSPI peripheral control and status registers are accessible via the SoC's APB bus, whereas MMIO transactions' data travels on the AHB bus. Microchip documentation and even sample code from Atmel emphasises the need for a memory barrier before the first MMIO transaction to the AHB-connected QSPI, and before the last write to its registers via APB. This is achieved by the following lines in `atmel_qspi_transfer()`: /* Dummy read of QSPI_IFR to synchronize APB and AHB accesses */ (void)atmel_qspi_read(aq, QSPI_IFR); However, the current documentation makes no mention to synchronization requirements in the other direction, i.e. after the last data written via AHB, and before the first register access on APB. In our case, we were facing an issue where the QSPI peripheral would cease to send any new CSR (nCS Rise) interrupts, leading to a timeout in `atmel_qspi_wait_for_completion()` and ultimately this panic in higher levels: ubi0 error: ubi_io_write: error -110 while writing 63108 bytes to PEB 491:128, written 63104 bytes After months of extensive research of the codebase, fiddling around the debugger with kgdb, and back-and-forth with Microchip, we came to the conclusion that the issue is probably that the peripheral is still busy receiving on AHB when the LASTXFER bit is written to its Control Register on APB, therefore this write gets lost, and the peripheral still thinks there is more data to come in the MMIO transfer. This was first formulated when we noticed that doubling the write() of QSPI_CR_LASTXFER seemed to solve the problem. Ultimately, the solution is to introduce memory barriers after the AHB-mapped MMIO transfers, to ensure ordering. Fixes: d5433de ("mtd: spi-nor: atmel-quadspi: Add spi-mem support to atmel-quadspi") Cc: Hari.PrasathGE@microchip.com Cc: Mahesh.Abotula@microchip.com Cc: Marco.Cardellini@microchip.com Cc: stable@vger.kernel.org # c0a0203: ("spi: atmel-quadspi: Create `atmel_qspi_ops`"...) Cc: stable@vger.kernel.org # 6.x.y Signed-off-by: Bence Csókás <csokas.bence@prolan.hu> Link: https://patch.msgid.link/20241219091258.395187-1-csokas.bence@prolan.hu Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent b69386f commit be92ab2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/spi/atmel-quadspi.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,13 +661,20 @@ static int atmel_qspi_transfer(struct spi_mem *mem,
661661
(void)atmel_qspi_read(aq, QSPI_IFR);
662662

663663
/* Send/Receive data */
664-
if (op->data.dir == SPI_MEM_DATA_IN)
664+
if (op->data.dir == SPI_MEM_DATA_IN) {
665665
memcpy_fromio(op->data.buf.in, aq->mem + offset,
666666
op->data.nbytes);
667-
else
667+
668+
/* Synchronize AHB and APB accesses again */
669+
rmb();
670+
} else {
668671
memcpy_toio(aq->mem + offset, op->data.buf.out,
669672
op->data.nbytes);
670673

674+
/* Synchronize AHB and APB accesses again */
675+
wmb();
676+
}
677+
671678
/* Release the chip-select */
672679
atmel_qspi_write(QSPI_CR_LASTXFER, aq, QSPI_CR);
673680

0 commit comments

Comments
 (0)