hw/{block,ssi}: Fix spi-nor flash dummy byte handling
Subsystems (2)
cover hw/{block,ssi}: Fix spi-nor flash dummy byte handling
This series fixes dummy-cycle accounting for SPI NOR fast-read operations across the m25p80 flash model and several SSI controller models.
The root problem is that the affected code paths mixed two different units. Flash datasheets and controller registers often describe fast-read dummy phases in clock cycles, while the SSI bus interface used by these models transfers byte-sized words to the flash. As a result, some paths treated cycle counts as byte counts directly, and other paths compensated in controller-specific ways that duplicated flash command semantics.
The first four patches fix the flash side. They make m25p80 keep needed_bytes as a byte count and convert manufacturer-specific dummy-cycle requirements to dummy byte transfers for Winbond, Numonyx/Micron, Macronix, and Spansion flashes. The Numonyx/Micron change also handles the standard-mode case where the dummy phase follows the address bus width for output fast-read commands.
The next patches fix controller-generated dummy phases. NPCM7xx FIU and Xilinx ZynqMP GQSPI now convert programmed dummy-cycle fields to SSI byte transfers using the bus width selected for the dummy phase. The ASPEED SMC direct-read path is updated the same way. The two ASPEED reverts then remove older workarounds that either hard-coded FAST_READ_4 dummy behavior or snooped manual user-mode SPI streams to inject extra dummy cycles. With m25p80 accounting fixed, user-mode byte streams should be forwarded as supplied by the guest.
The final patch documents the intended ownership boundary: flash models own command semantics and dummy-byte consumption, while controller models own hardware-generated dummy phases and cycle-to-byte conversion.
Some background:
While recently working on some device modeling, I hit this issue again. I then realized that I had sent a fix series for it more than five years ago, but it never made it upstream.
This series picks up that old work, refreshes it against the current tree, and fixes several issues in the SPI controller models. The original series is available at [1]. I have tried to verify all the SPI controller changes by booting real-world guest software to ensure the change does not break anything.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Bin Meng (10):
hw/block: m25p80: Fix dummy byte handling for Winbond flash hw/block: m25p80: Fix dummy byte handling for Numonyx/Micron flash hw/block: m25p80: Fix dummy byte handling for Macronix flash hw/block: m25p80: Fix dummy byte handling for Spansion flash hw/ssi: npcm7xx_fiu: Correct the dummy cycle emulation logic hw/ssi: xilinx_spips: Fix dummy phase handling
hw/ssi: aspeed_smc: Fix direct-read dummy bytes
Revert "aspeed/smc: Fix number of dummy cycles for FAST_READ_4
command"
Revert "aspeed/smc: snoop SPI transfers to fake dummy cycles" docs/devel: Document SSI dummy-cycle ownership
docs/devel/index-internals.rst | 1 + docs/devel/ssi.rst | 132 +++++++++++++++++++++++++++++ include/hw/ssi/aspeed_smc.h | 2 - include/hw/ssi/xilinx_spips.h | 2 +- hw/block/m25p80.c | 146 ++++++++++++++++++++++----------- hw/ssi/aspeed_smc.c | 135 ++++-------------------------- hw/ssi/npcm7xx_fiu.c | 25 ++---- hw/ssi/xilinx_spips.c | 120 +++++++++++++++++++-------- hw/ssi/trace-events | 1 - 9 files changed, 345 insertions(+), 219 deletions(-) create mode 100644 docs/devel/ssi.rst
Signature · 1 line
2.34.1
PATCH 2/10 hw/block: m25p80: Fix dummy byte handling for Numonyx/Micron flash
Numonyx/Micron flashes do not use one fixed dummy-phase width for all fast-read commands. The volatile configuration register stores a number of dummy clock cycles, and QEMU must convert that value to the number of SSI bytes consumed by the flash model.
Keep the existing default: 10 dummy clocks in Quad I/O mode and 8 dummy clocks otherwise. In Quad I/O and Dual I/O protocol modes, all command phases are transferred on 4 or 2 lines, so the dummy clock count still needs to be scaled by that bus width.
Standard SPI, also called extended SPI in the Micron datasheet, is more subtle. Quad Output Fast Read (6Bh) and Dual Output Fast Read (3Bh) keep the opcode and address phases on DQ0; their dummy phase is just a clock gap before data is returned on four or two output lines. Do not scale the dummy count for those output-only commands. Only Quad I/O Fast Read (EBh) and Dual I/O Fast Read (BBh) transfer the address and dummy phases on the 4-bit or 2-bit bus, so keep scaling those commands.
[1] https://media-www.micron.com/-/media/client/global/documents/products/
data-sheet/nor-flash/serial-nor/n25q/n25q_512mb_1ce_3v_65nm.pdf
---
hw/block/m25p80.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-)
hw/block/m25p80.c +39 -5
@@ -980,19 +980,53 @@ static uint8_t numonyx_extract_cfg_num_dummies(Flash *s) mode =numonyx_mode (s); num_dummies =extract32 (s->volatile_cfg,4 ,4 ); +/* +* The default nubmer of dummy cycles is only related to the SPI +* protocol mode. For QSPI it is 10, otherwise it is 8. +*/ if (num_dummies ==0x0 || num_dummies ==0xf ) { + num_dummies = (mode ==MODE_QIO ) ?10 :8 ; + } + +/* +* Convert the number of dummy cycles to bytes. +* +* In the Dual I/O and Quad I/O protocols, all command phases use 2 or 4 +* lines. In standard/extended SPI mode the phase width depends on the +* command sequence: output-only fast reads keep the dummy clocks on the +* single address line, while input/output fast reads use the same 2-line +* or 4-line phase as the address. +*/ + +if (mode ==MODE_QIO ) { + num_dummies *=4 ; + }else if (mode ==MODE_DIO ) { + num_dummies *=2 ; + }else {switch (s->cmd_in_progress) {case QIOR :case QIOR4 : - num_dummies =10 ; + num_dummies *=4 ;break ; -default : - num_dummies = (mode ==MODE_QIO ) ?10 :8 ; +case DIOR : +case DIOR4 : + num_dummies *=2 ;break ; - } + } + } + +/* +* If the total number of dummy bits is not multiple of 8, log an +* unimplemented message to notify user, and round it up. +*/ +if (num_dummies %8 ) { +qemu_log_mask (LOG_UNIMP , +"M25P80: the number of dummy bits is not multiple of 8" ); + num_dummies =ROUND_UP (num_dummies,8 ); } -return num_dummies; +/* return the number of dummy bytes */ +return num_dummies /8 ; }static void decode_fast_read_cmd (Flash *s)
Signature · 1 line
2.34.1
PATCH 4/10 hw/block: m25p80: Fix dummy byte handling for Spansion flash
In reply to Bin MengSpansion flashes expose the number of dummy clock cycles through CR2V register [1]. The value is a cycle count, not a byte count, so the m25p80 model has to convert it to the number of whole SSI transfer bytes consumed while collecting read command data.
Add a helper that multiplies the CR2V dummy cycle count by the phase width and rounds up non-byte-aligned counts, matching the byte-oriented SSI model. The default eight-cycle configuration keeps the same byte counts as before.
---
hw/block/m25p80.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
hw/block/m25p80.c +20 -12
@@ -1028,6 +1028,23 @@ static uint8_t numonyx_extract_cfg_num_dummies(Flash *s)return num_dummies /8 ; } +static uint8_t spansion_extract_cfg_num_dummies (Flash *s,uint8_t bus_width) +{ +uint8_t num_dummies; + + num_dummies =extract32 (s->spansion_cr2v,SPANSION_DUMMY_CLK_POS , +SPANSION_DUMMY_CLK_LEN ); + num_dummies *= bus_width; + +if (num_dummies %8 ) { +qemu_log_mask (LOG_UNIMP , +"M25P80: the number of dummy bits is not multiple of 8" ); + num_dummies =ROUND_UP (num_dummies,8 ); + } + +return num_dummies /8 ; +} +static uint8_t macronix_extract_cfg_num_dummies (Flash *s,uint8_t bus_width) {static const uint8_t dummy_cycles_fast[4 ] = {8 ,6 ,8 ,10 };
@@ -1081,10 +1098,7 @@ static void decode_fast_read_cmd(Flash *s) s->needed_bytes +=macronix_extract_cfg_num_dummies (s,1 );break ;case MAN_SPANSION : - s->needed_bytes +=extract32 (s->spansion_cr2v, -SPANSION_DUMMY_CLK_POS , -SPANSION_DUMMY_CLK_LEN - ); + s->needed_bytes +=spansion_extract_cfg_num_dummies (s,1 );break ;case MAN_ISSI :/*
@@ -1117,10 +1131,7 @@ static void decode_dio_read_cmd(Flash *s)break ;case MAN_SPANSION : s->needed_bytes +=SPANSION_CONTINUOUS_READ_MODE_CMD_LEN ; - s->needed_bytes +=extract32 (s->spansion_cr2v, -SPANSION_DUMMY_CLK_POS , -SPANSION_DUMMY_CLK_LEN - ); + s->needed_bytes +=spansion_extract_cfg_num_dummies (s,2 );break ;case MAN_NUMONYX : s->needed_bytes +=numonyx_extract_cfg_num_dummies (s);
@@ -1157,10 +1168,7 @@ static void decode_qio_read_cmd(Flash *s)break ;case MAN_SPANSION : s->needed_bytes +=SPANSION_CONTINUOUS_READ_MODE_CMD_LEN ; - s->needed_bytes +=extract32 (s->spansion_cr2v, -SPANSION_DUMMY_CLK_POS , -SPANSION_DUMMY_CLK_LEN - ); + s->needed_bytes +=spansion_extract_cfg_num_dummies (s,4 );break ;case MAN_NUMONYX : s->needed_bytes +=numonyx_extract_cfg_num_dummies (s);
Signature · 1 line
2.34.1
PATCH 5/10 hw/ssi: npcm7xx_fiu: Correct the dummy cycle emulation logic
In reply to Bin MengChange send_dummy_bits() to send_dummy_bytes() as the FIU register fields are programmed from spi_mem_op.dummy.nbytes, so they already describe byte transfers.
Verified the changes by booting OpenBMC image on gbs machine all the way to the Linux login shell:
$ qemu-system-arm -machine quanta-gbs-bmc -nographic \
-drive file=image.mtd,if=mtd,bus=0,unit=0,format=raw---
hw/ssi/npcm7xx_fiu.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-)
hw/ssi/npcm7xx_fiu.c +8 -17
@@ -150,7 +150,7 @@ static uint64_t npcm7xx_fiu_flash_read(void *opaque, hwaddr addr,NPCM7xxFIUState *fiu = f->fiu;uint64_t value =0 ;uint32_t drd_cfg; -int dummy_cycles; +int dummy_bytes;int i;if (fiu->active_cs !=-1 ) {
@@ -180,10 +180,8 @@ static uint64_t npcm7xx_fiu_flash_read(void *opaque, hwaddr addr,break ; } -/* Flash chip model expects one transfer per dummy bit, not byte */ - dummy_cycles = - (FIU_DRD_CFG_DBW (drd_cfg) *8 ) >>FIU_DRD_CFG_ACCTYPE (drd_cfg); -for (i =0 ; i < dummy_cycles; i++) { + dummy_bytes =FIU_DRD_CFG_DBW (drd_cfg); +for (i =0 ; i < dummy_bytes; i++) {ssi_transfer (fiu->spi,0 ); }
@@ -305,20 +303,13 @@ static void send_address(SSIBus *spi, unsigned int addsiz, uint32_t addr) } } -/* Send the number of dummy bits specified in the UMA config register. */ -static void send_dummy_bits (SSIBus *spi,uint32_t uma_cfg,uint32_t uma_cmd) +/* Send the number of dummy bytes specified in the UMA config register. */ +static void send_dummy_bytes (SSIBus *spi,uint32_t uma_cfg) { -unsigned int bits_per_clock =1U <<FIU_UMA_CFG_DBPCK (uma_cfg);unsigned int i;for (i =0 ; i <FIU_UMA_CFG_DBSIZ (uma_cfg); i++) { -/* Use bytes 0 and 1 first, then keep repeating byte 2 */ -unsigned int field = (i <2 ) ? ((i +1 ) *8 ) :24 ; -unsigned int j; - -for (j =0 ; j <8 ; j += bits_per_clock) { -ssi_transfer (spi,extract32 (uma_cmd, field + j, bits_per_clock)); - } +ssi_transfer (spi,0 ); } }
@@ -354,8 +345,8 @@ static void npcm7xx_fiu_uma_transaction(NPCM7xxFIUState *s)ssi_transfer (s->spi,extract32 (s->regs[reg], field,8 )); } -/* Send dummy bits, if present. */ -send_dummy_bits (s->spi, uma_cfg, s->regs[NPCM7XX_FIU_UMA_CMD ]); +/* Send dummy bytes, if present. */ +send_dummy_bytes (s->spi, uma_cfg);/* Read data, if present. */ for (i =0 ; i <FIU_UMA_CFG_RDATSIZ (uma_cfg); i++) {
Signature · 1 line
2.34.1
PATCH 10/10 docs/devel: Document SSI dummy-cycle ownership
In reply to Bin MengDocument the boundary between SPI/SSI controller models and SPI flash models when representing fast-read dummy cycles. It explains that flash models own command semantics, while controllers own hardware-generated dummy transfers and cycle-to-byte conversion.
---
docs/devel/index-internals.rst | 1 + docs/devel/ssi.rst | 132 +++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 docs/devel/ssi.rst
docs/devel/index-internals.rst +1 -0
@@ -19,6 +19,7 @@ Details about QEMU's various subsystems including how to add features to them. reset s390-cpu-topology s390-dasd-ipl + ssi tracing uefi-vars vfio-iommufd
docs/devel/ssi.rst new file +132 -0
132 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 7/10 hw/ssi: aspeed_smc: Fix direct-read dummy bytes
In reply to Bin Mengm25p80 now consumes fast-read dummy phases as byte counts. The ASPEED SMC direct-read path still treated the CEx dummy field as raw cycles and emitted field * 8 SSI transfers. Convert the ASPEED dummy field to SSI byte transfers using the selected direct-read data width.
---
hw/ssi/aspeed_smc.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
hw/ssi/aspeed_smc.c +15 -6
@@ -449,19 +449,28 @@ static uint32_t aspeed_smc_check_segment_addr(const AspeedSMCFlash *fl,return addr; } -static int aspeed_smc_flash_dummies (const AspeedSMCFlash *fl) +static int aspeed_smc_flash_dummy_bytes (const AspeedSMCFlash *fl) {const AspeedSMCState *s = fl->controller;uint32_t r_ctrl0 = s->regs[s->r_ctrl0 + fl->cs];uint32_t dummy_high = (r_ctrl0 >>CTRL_DUMMY_HIGH_SHIFT ) &0x1 ;uint32_t dummy_low = (r_ctrl0 >>CTRL_DUMMY_LOW_SHIFT ) &0x3 ; -uint32_t dummies = ((dummy_high <<2 ) | dummy_low) *8 ; +uint32_t dummy_byte = (dummy_high <<2 ) | dummy_low; -if (r_ctrl0 &CTRL_IO_DUAL_ADDR_DATA ) { - dummies /=2 ; +/* +* Scale the controller dummy field to SSI byte transfers using the +* direct-read dummy/address bus width. +*/ +if ((r_ctrl0 &CTRL_IO_QPI ) || + ((r_ctrl0 &CTRL_IO_QUAD_DATA ) && + (r_ctrl0 &CTRL_IO_QUAD_ADDR_DATA ))) { + dummy_byte *=4 ; + }else if ((r_ctrl0 &CTRL_IO_DUAL_DATA ) && + (r_ctrl0 &CTRL_IO_DUAL_ADDR_DATA )) { + dummy_byte *=2 ; } -return dummies; +return dummy_byte; }static void aspeed_smc_flash_setup (AspeedSMCFlash *fl,uint32_t addr)
@@ -487,7 +496,7 @@ static void aspeed_smc_flash_setup(AspeedSMCFlash *fl, uint32_t addr)* settings, let's check for fast read mode. */ if (aspeed_smc_flash_mode (fl) ==CTRL_FREADMODE ) { -for (i =0 ; i <aspeed_smc_flash_dummies (fl); i++) { +for (i =0 ; i <aspeed_smc_flash_dummy_bytes (fl); i++) {ssi_transfer (fl->controller->spi, s->regs[R_DUMMY_DATA ] &0xff ); } }
Signature · 1 line
2.34.1
PATCH 9/10 Revert "aspeed/smc: snoop SPI transfers to fake dummy cycles"
In reply to Bin MengThis reverts commit f95c4bffdc4c53b29f89762cab4adc5a43f95daf.
The m25p80 model now accounts for fast-read dummy bytes in its command decoder. In ASPEED SMC model user mode, guest software already sends the complete byte stream, including any dummy bytes needed by the flash. Hence the model should just forward exactly the bytes supplied by the guest without the need of decoding guest-supplied flash op codes to inject extra dummy transfers.
---
include/hw/ssi/aspeed_smc.h | 2 - hw/ssi/aspeed_smc.c | 114 +----------------------------------- hw/ssi/trace-events | 1 - 3 files changed, 2 insertions(+), 115 deletions(-)
include/hw/ssi/aspeed_smc.h +0 -2
@@ -80,8 +80,6 @@ struct AspeedSMCState {AspeedSMCFlash flashes[ASPEED_SMC_CS_MAX ]; -uint8_t snoop_index; -uint8_t snoop_dummies;bool unselect; };
hw/ssi/aspeed_smc.c +2 -112
152 lines not on this page · raw message
hw/ssi/trace-events +0 -1
@@ -2,7 +2,6 @@ aspeed_smc_flash_set_segment(int cs, uint64_t reg, uint64_t start, uint64_t end) "CS%d segreg=0x%"PRIx64" [ 0x%"PRIx64" - 0x%"PRIx64" ]" aspeed_smc_flash_read(int cs, uint64_t addr, uint32_t size, uint64_t data, int mode) "CS%d @0x%" PRIx64 " size %u: 0x%" PRIx64" mode:%d" -aspeed_smc_do_snoop(int cs, int index, int dummies, int data) "CS%d index:0x%x dummies:%d data:0x%x" aspeed_smc_flash_write(int cs, uint64_t addr, uint32_t size, uint64_t data, int mode) "CS%d @0x%" PRIx64 " size %u: 0x%" PRIx64" mode:%d" aspeed_smc_read(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64 aspeed_smc_dma_checksum(uint32_t addr, uint32_t data) "0x%08x: 0x%08x"
Signature · 1 line
2.34.1
PATCH 1/10 hw/block: m25p80: Fix dummy byte handling for Winbond flash
In reply to Bin MengThe m25p80 model uses s->needed_bytes to track how many bytes a controller must send after an opcode before the flash model can enter the data phase. For address-bearing commands this includes the address bytes. For fast-read commands it also includes the dummy phase.
The tricky part is that flash datasheets describe the dummy phase in clock cycles, while the QEMU SSI interface advances the flash model one transferred byte at a time. The dummy clock count therefore has to be converted to the number of SSI bytes that the controller will actually emit.
Some controllers have drivers that push these dummy bytes into a FIFO. Other controllers are programmed with a dummy-cycle count and generate the clocks themselves. The flash model still has to use the same byte count that a FIFO-style controller or the Linux spi-mem layer would use, otherwise the model waits too long and drops the first data bytes.
Let's fix the inconsistency from the flash side first. We start from an easy one, the Winbond flashes.
Per the Windbond W25Q256JV datasheet [1] instrunction set table (chapter 8.1.2, 8.1.3, 8.1.4, 8.1.5), fix the wrong number of dummy bytes needed for fast read commands.
[1] https://www.winbond.com/resource-files/w25q256jv%20spi%20revb%2009202016.pdf
---
hw/block/m25p80.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/block/m25p80.c +2 -2
@@ -1004,7 +1004,7 @@ static void decode_fast_read_cmd(Flash *s) s->needed_bytes +=1 ;break ;case MAN_WINBOND : - s->needed_bytes +=8 ; + s->needed_bytes +=1 ;break ;case MAN_NUMONYX : s->needed_bytes +=numonyx_extract_cfg_num_dummies (s);
@@ -1099,7 +1099,7 @@ static void decode_qio_read_cmd(Flash *s)switch (get_man (s)) {case MAN_WINBOND : s->needed_bytes +=WINBOND_CONTINUOUS_READ_MODE_CMD_LEN ; - s->needed_bytes +=4 ; + s->needed_bytes +=2 ;break ;case MAN_SPANSION : s->needed_bytes +=SPANSION_CONTINUOUS_READ_MODE_CMD_LEN ;
Signature · 1 line
2.34.1
PATCH 6/10 hw/ssi: xilinx_spips: Fix dummy phase handling
In reply to Bin MengThe ZynqMP generic FIFO encodes dummy phases as a number of dummy cycles. QEMU's SSI bus transfers whole bytes, so the controller model must convert the programmed cycle count to the number of SSI byte transfers needed for the selected SPI, dual SPI or quad SPI mode.
The legacy Xilinx QSPI snoop paths had the opposite problem after the m25p80 dummy handling was fixed. They still treated each dummy byte queued through the FIFO as a request to generate several SSI transfers based on the current link width. The flash model now consumes dummy phases as byte counts, so the manual FIFO path should forward one SSI transfer per dummy byte.
Update the Xilinx QSPI dummy accounting consistently for the generic FIFO, manual FIFO and LQSPI direct-read paths. Also make the command table report the dummy byte counts consumed by m25p80 for dual and quad output reads, and account for the mode byte before LQSPI data reads begin.
This matches the ZynqMP TRM (ug1085, v2.2 [1]) description of the generic FIFO dummy cycle entry and keeps the controller side aligned with the flash model's dummy byte ownership.
The description of the genenic command fifo register says:
When [receive, transmit, data_xfer] = [0,0,1], the [immediate_data] field represents the number of dummy cycle sent on the SPI interface.
[1] https://www.xilinx.com/support/documentation/user_guides/ug1085-zynq-ultrascale-trm.pdf
table 24‐22, an example of Generic FIFO Contents for Quad I/O Read Command (EBh)
---
include/hw/ssi/xilinx_spips.h | 2 +- hw/ssi/xilinx_spips.c | 120 ++++++++++++++++++++++++---------- 2 files changed, 88 insertions(+), 34 deletions(-)
include/hw/ssi/xilinx_spips.h +1 -1
@@ -69,7 +69,7 @@ struct XilinxSPIPS {uint8_t num_busses;uint8_t snoop_state; -int cmd_dummies; +int cmd_dummy_bytes;uint8_t link_state;uint8_t link_state_next;uint8_t link_state_next_when;
hw/ssi/xilinx_spips.c +87 -33
238 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 3/10 hw/block: m25p80: Fix dummy byte handling for Macronix flash
In reply to Bin MengMacronix flashes expose DC[1:0] bits in the volatile configuration register [1]. These bits select the number of dummy clock cycles used by the fast-read command families.
Convert the Macronix dummy-cycle settings through per-command-family tables and round up the non-byte-aligned cases that the byte-oriented SSI model cannot represent exactly.
[1] https://www.macronix.com/Lists/Datasheet/Attachments/8657/MX66L51235F,%203V,%20512Mb,%20v1.1.pdf
---
hw/block/m25p80.c | 66 +++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 28 deletions(-)
hw/block/m25p80.c +38 -28
@@ -975,7 +975,6 @@ static uint8_t numonyx_extract_cfg_num_dummies(Flash *s) {uint8_t num_dummies;uint8_t mode; -assert (get_man (s) ==MAN_NUMONYX ); mode =numonyx_mode (s); num_dummies =extract32 (s->volatile_cfg,4 ,4 );
@@ -1029,6 +1028,41 @@ static uint8_t numonyx_extract_cfg_num_dummies(Flash *s)return num_dummies /8 ; } +static uint8_t macronix_extract_cfg_num_dummies (Flash *s,uint8_t bus_width) +{ +static const uint8_t dummy_cycles_fast[4 ] = {8 ,6 ,8 ,10 }; +static const uint8_t dummy_cycles_dio[4 ] = {4 ,6 ,8 ,10 }; +static const uint8_t dummy_cycles_qio[4 ] = {6 ,4 ,8 ,10 }; +const uint8_t *dummy_cycles = dummy_cycles_fast; +uint8_t num_dummies; + +assert (get_man (s) ==MAN_MACRONIX ); + +switch (s->cmd_in_progress) { +case DIOR : +case DIOR4 : + dummy_cycles = dummy_cycles_dio; +break ; +case QIOR : +case QIOR4 : + dummy_cycles = dummy_cycles_qio; +break ; +default : +break ; + } + + num_dummies = dummy_cycles[extract32 (s->volatile_cfg,6 ,2 )]; + num_dummies *= bus_width; + +if (num_dummies %8 ) { +qemu_log_mask (LOG_UNIMP , +"M25P80: the number of dummy bits is not multiple of 8" ); + num_dummies =ROUND_UP (num_dummies,8 ); + } + +return num_dummies /8 ; +} +static void decode_fast_read_cmd (Flash *s) { s->needed_bytes =get_addr_length (s);
@@ -1044,11 +1078,7 @@ static void decode_fast_read_cmd(Flash *s) s->needed_bytes +=numonyx_extract_cfg_num_dummies (s);break ;case MAN_MACRONIX : -if (extract32 (s->volatile_cfg,6 ,2 ) ==1 ) { - s->needed_bytes +=6 ; - }else { - s->needed_bytes +=8 ; - } + s->needed_bytes +=macronix_extract_cfg_num_dummies (s,1 );break ;case MAN_SPANSION : s->needed_bytes += extract32(s->spansion_cr2v,
@@ -1096,17 +1126,7 @@ static void decode_dio_read_cmd(Flash *s) s->needed_bytes +=numonyx_extract_cfg_num_dummies (s);break ;case MAN_MACRONIX : -switch (extract32 (s->volatile_cfg,6 ,2 )) { -case 1 : - s->needed_bytes +=6 ; -break ; -case 2 : - s->needed_bytes +=8 ; -break ; -default : - s->needed_bytes +=4 ; -break ; - } + s->needed_bytes +=macronix_extract_cfg_num_dummies (s,2 );break ;case MAN_ISSI :/*
@@ -1146,17 +1166,7 @@ static void decode_qio_read_cmd(Flash *s) s->needed_bytes +=numonyx_extract_cfg_num_dummies (s);break ;case MAN_MACRONIX : -switch (extract32 (s->volatile_cfg,6 ,2 )) { -case 1 : - s->needed_bytes +=4 ; -break ; -case 2 : - s->needed_bytes +=8 ; -break ; -default : - s->needed_bytes +=6 ; -break ; - } + s->needed_bytes +=macronix_extract_cfg_num_dummies (s,4 );break ;case MAN_ISSI :/*
Signature · 1 line
2.34.1
PATCH 8/10 Revert "aspeed/smc: Fix number of dummy cycles for FAST_READ_4 command"
In reply to Bin MengThis reverts commit 7faf6f1790dddf9f3acf6ddd95f7bbc1b4a755d0.
The incorrect implementation of dummy cycles in m25p80 model is now corrected. Revert this commit.
---
hw/ssi/aspeed_smc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ssi/aspeed_smc.c +1 -1
@@ -568,11 +568,11 @@ static int aspeed_smc_num_dummies(uint8_t command)case FAST_READ :case DOR :case QOR : -case FAST_READ_4 :case DOR_4 :case QOR_4 :return 1 ;case DIOR : +case FAST_READ_4 :case DIOR_4 :return 2 ;case QIOR :
Signature · 1 line
2.34.1
+ Joel
Quoted 71 lines · Bin Meng
This series fixes dummy-cycle accounting for SPI NOR fast-read operations across the m25p80 flash model and several SSI controller models.
The root problem is that the affected code paths mixed two different units. Flash datasheets and controller registers often describe fast-read dummy phases in clock cycles, while the SSI bus interface used by these models transfers byte-sized words to the flash. As a result, some paths treated cycle counts as byte counts directly, and other paths compensated in controller-specific ways that duplicated flash command semantics.
The first four patches fix the flash side. They make m25p80 keep
needed_bytesas a byte count and convert manufacturer-specific dummy-cycle requirements to dummy byte transfers for Winbond, Numonyx/Micron, Macronix, and Spansion flashes. The Numonyx/Micron change also handles the standard-mode case where the dummy phase follows the address bus width for output fast-read commands.The next patches fix controller-generated dummy phases. NPCM7xx FIU and Xilinx ZynqMP GQSPI now convert programmed dummy-cycle fields to SSI byte transfers using the bus width selected for the dummy phase. The ASPEED SMC direct-read path is updated the same way. The two ASPEED reverts then remove older workarounds that either hard-coded
FAST_READ_4dummy behavior or snooped manual user-mode SPI streams to inject extra dummy cycles. With m25p80 accounting fixed, user-mode byte streams should be forwarded as supplied by the guest.The final patch documents the intended ownership boundary: flash models own command semantics and dummy-byte consumption, while controller models own hardware-generated dummy phases and cycle-to-byte conversion.
Some background:
While recently working on some device modeling, I hit this issue again. I then realized that I had sent a fix series for it more than five years ago, but it never made it upstream.
This series picks up that old work, refreshes it against the current tree, and fixes several issues in the SPI controller models. The original series is available at [1]. I have tried to verify all the SPI controller changes by booting real-world guest software to ensure the change does not break anything.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Bin Meng (10):
hw/block: m25p80: Fix dummy byte handling for Winbond flash hw/block: m25p80: Fix dummy byte handling for Numonyx/Micron flash hw/block: m25p80: Fix dummy byte handling for Macronix flash hw/block: m25p80: Fix dummy byte handling for Spansion flash hw/ssi:npcm7xx_fiu: Correct the dummy cycle emulation logic hw/ssi:xilinx_spips: Fix dummy phase handling
hw/ssi:aspeed_smc: Fix direct-read dummy bytes
Revert "aspeed/smc: Fix number of dummy cycles forFAST_READ_4
command"
Revert "aspeed/smc: snoop SPI transfers to fake dummy cycles" docs/devel: Document SSI dummy-cycle ownershipdocs/devel/index-internals.rst | 1 + docs/devel/ssi.rst | 132 +++++++++++++++++++++++++++++ include/hw/ssi/aspeed_smc.h | 2 - include/hw/ssi/xilinx_spips.h | 2 +- hw/block/m25p80.c | 146 ++++++++++++++++++++++----------- hw/ssi/aspeed_smc.c | 135 ++++-------------------------- hw/ssi/npcm7xx_fiu.c | 25 ++---- hw/ssi/xilinx_spips.c | 120 +++++++++++++++++++-------- hw/ssi/trace-events | 1 - 9 files changed, 345 insertions(+), 219 deletions(-)
Quoted 2 lines
create mode 100644
docs/devel/ssi.rst
Thanks for the cleanup, Bin.
C.
Re: [PATCH 07/10] hw/ssi: aspeed_smc: Fix direct-read dummy bytes
In reply to Bin MengQuoted 52 lines · Bin Meng
m25p80 now consumes fast-read dummy phases as byte counts. The ASPEED SMC direct-read path still treated the CEx dummy field as raw cycles and emitted field * 8 SSI transfers. Convert the ASPEED dummy field to SSI byte transfers using the selected direct-read data width.
Fixes ac2810defa9d ("aspeed/smc: handle dummy bytes when doing fast reads in command mode")Signed-off-by Bin Meng <[email protected]>---
hw/ssi/aspeed_smc.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)hw/ssi/aspeed_smc.c +14
-5@@ -449,19 +449,28 @@ static uint32_t aspeed_smc_check_segment_addr(const AspeedSMCFlash *fl,return addr; } -static int aspeed_smc_flash_dummies (const AspeedSMCFlash *fl) +static int aspeed_smc_flash_dummy_bytes (const AspeedSMCFlash *fl) {const AspeedSMCState *s = fl->controller;uint32_t r_ctrl0 = s->regs[s->r_ctrl0 + fl->cs];uint32_t dummy_high = (r_ctrl0 >>CTRL_DUMMY_HIGH_SHIFT ) &0x1 ;uint32_t dummy_low = (r_ctrl0 >>CTRL_DUMMY_LOW_SHIFT ) &0x3 ; -uint32_t dummies = ((dummy_high <<2 ) | dummy_low) *8 ; +uint32_t dummy_byte = (dummy_high <<2 ) | dummy_low; -if (r_ctrl0 &CTRL_IO_DUAL_ADDR_DATA ) { - dummies /=2 ; +/* +* Scale the controller dummy field to SSI byte transfers using the +* direct-read dummy/address bus width. +*/ +if ((r_ctrl0 &CTRL_IO_QPI ) || + ((r_ctrl0 &CTRL_IO_QUAD_DATA ) && + (r_ctrl0 &CTRL_IO_QUAD_ADDR_DATA ))) { + dummy_byte *=4 ; + }else if ((r_ctrl0 &CTRL_IO_DUAL_DATA ) && + (r_ctrl0 &CTRL_IO_DUAL_ADDR_DATA )) { + dummy_byte *=2 ; } -return dummies; +return dummy_byte; }static void aspeed_smc_flash_setup (AspeedSMCFlash *fl,uint32_t addr)
hw/ssi/aspeed_smc.c static void aspeed_smc_flash_setup(AspeedSMCFlash *fl, uint32_t addr) · line 502
Quoted 8 lines
hw/ssi/aspeed_smc.c +1
-1@@ -487,7 +496,7 @@ static void aspeed_smc_flash_setup(AspeedSMCFlash *fl, uint32_t addr)* settings, let's check for fast read mode. */ if (aspeed_smc_flash_mode (fl) ==CTRL_FREADMODE ) { -for (i =0 ; i <aspeed_smc_flash_dummies (fl); i++) { +for (i =0 ; i <aspeed_smc_flash_dummy_bytes (fl); i++) {ssi_transfer (fl->controller->spi, s->regs[R_DUMMY_DATA ] &0xff ); } }
Thanks,
C.
Re: [PATCH 08/10] Revert "aspeed/smc: Fix number of dummy cycles for FAST_READ_4 command"
In reply to Bin MengQuoted 18 lines · Bin Meng
This reverts commit
7faf6f1790dddf9f3acf6ddd95f7bbc1b4a755d0.The incorrect implementation of dummy cycles in m25p80 model is now corrected. Revert this commit.
Signed-off-by Bin Meng <[email protected]>---
hw/ssi/aspeed_smc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/ssi/aspeed_smc.c +0
-0@@ -568,11 +568,11 @@ static int aspeed_smc_num_dummies(uint8_t command)case FAST_READ :case DOR :
hw/ssi/aspeed_smc.c static int aspeed_smc_num_dummies(uint8_t command) · line 578
Quoted 10 lines
hw/ssi/aspeed_smc.c +1
-1case QOR : -case FAST_READ_4 :case DOR_4 :case QOR_4 :return 1 ;case DIOR : +case FAST_READ_4 :case DIOR_4 :return 2 ;case QIOR :
Thanks,
C.
Re: [PATCH 09/10] Revert "aspeed/smc: snoop SPI transfers to fake dummy cycles"
In reply to Bin MengQuoted 198 lines · Bin Meng
This reverts commit
f95c4bffdc4c53b29f89762cab4adc5a43f95daf.The m25p80 model now accounts for fast-read dummy bytes in its command decoder. In ASPEED SMC model user mode, guest software already sends the complete byte stream, including any dummy bytes needed by the flash. Hence the model should just forward exactly the bytes supplied by the guest without the need of decoding guest-supplied flash op codes to inject extra dummy transfers.
Signed-off-by Bin Meng <[email protected]>---
include/hw/ssi/aspeed_smc.h | 2 - hw/ssi/aspeed_smc.c | 114 +----------------------------------- hw/ssi/trace-events | 1 - 3 files changed, 2 insertions(+), 115 deletions(-)include/hw/ssi/aspeed_smc.h +0
-2@@ -80,8 +80,6 @@ struct AspeedSMCState {AspeedSMCFlash flashes[ASPEED_SMC_CS_MAX ]; -uint8_t snoop_index; -uint8_t snoop_dummies;bool unselect; };hw/ssi/aspeed_smc.c +2
-112@@ -197,9 +197,6 @@/* Flash opcodes. */ #define SPI_OP_READ 0x03/* Read data bytes (low frequency) */ -#define SNOOP_OFF 0xFF -#define SNOOP_START 0x0 -/* * Default segments mapping addresses and size for each peripheral per * controller. These can be changed when board is initialized with the @@ -537,104 +534,6 @@ static MemTxResult aspeed_smc_flash_read(void *opaque, hwaddr addr,return MEMTX_OK ; } -/* -* TODO ([email protected]): stolen from xilinx_spips.c. Should move to a -* common include header. -*/ -typedef enum { -READ =0x3 ,READ_4 =0x13 , -FAST_READ =0xb ,FAST_READ_4 =0x0c , -DOR =0x3b ,DOR_4 =0x3c , -QOR =0x6b ,QOR_4 =0x6c , -DIOR =0xbb ,DIOR_4 =0xbc , -QIOR =0xeb ,QIOR_4 =0xec , - -PP =0x2 ,PP_4 =0x12 , -DPP =0xa2 , -QPP =0x32 ,QPP_4 =0x34 , -}FlashCMD ; - -static int aspeed_smc_num_dummies (uint8_t command) -{ -switch (command) {/* check for dummies */ -case READ :/* no dummy bytes/cycles */ -case PP : -case DPP : -case QPP : -case READ_4 : -case PP_4 : -case QPP_4 : -return 0 ; -case FAST_READ : -case DOR : -case QOR : -case DOR_4 : -case QOR_4 : -return 1 ; -case DIOR : -case FAST_READ_4 : -case DIOR_4 : -return 2 ; -case QIOR : -case QIOR_4 : -return 4 ; -default : -return -1 ; - } -} - -static bool aspeed_smc_do_snoop (AspeedSMCFlash *fl,uint64_t data, -unsigned size) -{ -AspeedSMCState *s = fl->controller; -uint8_t addr_width =aspeed_smc_flash_addr_width (fl); - -trace_aspeed_smc_do_snoop (fl->cs, s->snoop_index, s->snoop_dummies, - (uint8_t ) data &0xff ); - -if (s->snoop_index ==SNOOP_OFF ) { -return false;/* Do nothing */ - - }else if (s->snoop_index ==SNOOP_START ) { -uint8_t cmd = data &0xff ; -int ndummies =aspeed_smc_num_dummies (cmd); - -/* -* No dummy cycles are expected with the current command. Turn -* off snooping and let the transfer proceed normally. -*/ -if (ndummies <=0 ) { - s->snoop_index =SNOOP_OFF ; -return false; - } - - s->snoop_dummies = ndummies *8 ; - - }else if (s->snoop_index >= addr_width +1 ) { - -/* The SPI transfer has reached the dummy cycles sequence */ -for (; s->snoop_dummies; s->snoop_dummies--) { -ssi_transfer (s->spi, s->regs[R_DUMMY_DATA ] &0xff ); - } - -/* If no more dummy cycles are expected, turn off snooping */ -if (!s->snoop_dummies) { - s->snoop_index =SNOOP_OFF ; - }else { - s->snoop_index += size; - } - -/* -* Dummy cycles have been faked already. Ignore the current -* SPI transfer -*/ -return true; - } - - s->snoop_index += size; -return false; -} -static MemTxResult aspeed_smc_flash_write (void *opaque,hwaddr addr,uint64_t data,unsigned size,MemTxAttrs attrs) {@@ -652,10 +551,6 @@ static MemTxResult aspeed_smc_flash_write(void *opaque, hwaddr addr,switch (aspeed_smc_flash_mode (fl)) {case CTRL_USERMODE : -if (aspeed_smc_do_snoop (fl, data, size)) { -break ; - } -for (i =0 ; i < size; i++) {ssi_transfer (s->spi, (data >> (8 * i)) &0xff ); }@@ -717,7 +612,6 @@ static void aspeed_smc_flash_update_ctrl(AspeedSMCFlash *fl, uint32_t value) s->regs[s->r_ctrl0 + fl->cs] = value;if (unselect != s->unselect) { - s->snoop_index = unselect ?SNOOP_OFF :SNOOP_START ;aspeed_smc_flash_do_select (fl, unselect); } }@@ -763,9 +657,6 @@ static void aspeed_smc_reset_hold(Object *obj, ResetType type)aspeed_smc_flash_set_segment_region (s, i, asc->segment_to_reg (s, &asc->segments[i])); } - - s->snoop_index =SNOOP_OFF ; - s->snoop_dummies =0 ; } static MemTxResult aspeed_smc_read(void *opaque, hwaddr addr, uint64_t *data,@@ -1293,11 +1184,10 @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp)static const VMStateDescription vmstate_aspeed_smc = { .name ="aspeed.smc" , .version_id =3 , - .minimum_version_id =2 , + .minimum_version_id =1 , .fields = (const VMStateField []) {VMSTATE_UINT32_ARRAY (regs, AspeedSMCState,ASPEED_SMC_R_MAX ), -VMSTATE_UINT8 (snoop_index, AspeedSMCState), -VMSTATE_UINT8 (snoop_dummies, AspeedSMCState), +VMSTATE_UNUSED_V (2 ,2 ),/* was snoop_index/snoop_dummies */ VMSTATE_BOOL_V (unselect, AspeedSMCState,3 ),VMSTATE_END_OF_LIST () }hw/ssi/trace-events +0
-0
hw/ssi/trace-events line 7
Quoted 7 lines
hw/ssi/trace-events +0
-1@@ -2,7 +2,6 @@ aspeed_smc_flash_set_segment(int cs, uint64_t reg, uint64_t start, uint64_t end) "CS%d segreg=0x%"PRIx64" [ 0x%"PRIx64" - 0x%"PRIx64" ]" aspeed_smc_flash_read(int cs, uint64_t addr, uint32_t size, uint64_t data, int mode) "CS%d @0x%" PRIx64 " size %u: 0x%" PRIx64" mode:%d" -aspeed_smc_do_snoop(int cs, int index, int dummies, int data) "CS%d index:0x%x dummies:%d data:0x%x" aspeed_smc_flash_write(int cs, uint64_t addr, uint32_t size, uint64_t data, int mode) "CS%d @0x%" PRIx64 " size %u: 0x%" PRIx64" mode:%d" aspeed_smc_read(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64 aspeed_smc_dma_checksum(uint32_t addr, uint32_t data) "0x%08x: 0x%08x"
Thanks,
C.
Hello,
Quoted 71 lines · Bin Meng
This series fixes dummy-cycle accounting for SPI NOR fast-read operations across the m25p80 flash model and several SSI controller models.
The root problem is that the affected code paths mixed two different units. Flash datasheets and controller registers often describe fast-read dummy phases in clock cycles, while the SSI bus interface used by these models transfers byte-sized words to the flash. As a result, some paths treated cycle counts as byte counts directly, and other paths compensated in controller-specific ways that duplicated flash command semantics.
The first four patches fix the flash side. They make m25p80 keep
needed_bytesas a byte count and convert manufacturer-specific dummy-cycle requirements to dummy byte transfers for Winbond, Numonyx/Micron, Macronix, and Spansion flashes. The Numonyx/Micron change also handles the standard-mode case where the dummy phase follows the address bus width for output fast-read commands.The next patches fix controller-generated dummy phases. NPCM7xx FIU and Xilinx ZynqMP GQSPI now convert programmed dummy-cycle fields to SSI byte transfers using the bus width selected for the dummy phase. The ASPEED SMC direct-read path is updated the same way. The two ASPEED reverts then remove older workarounds that either hard-coded
FAST_READ_4dummy behavior or snooped manual user-mode SPI streams to inject extra dummy cycles. With m25p80 accounting fixed, user-mode byte streams should be forwarded as supplied by the guest.The final patch documents the intended ownership boundary: flash models own command semantics and dummy-byte consumption, while controller models own hardware-generated dummy phases and cycle-to-byte conversion.
Some background:
While recently working on some device modeling, I hit this issue again. I then realized that I had sent a fix series for it more than five years ago, but it never made it upstream.
This series picks up that old work, refreshes it against the current tree, and fixes several issues in the SPI controller models. The original series is available at [1]. I have tried to verify all the SPI controller changes by booting real-world guest software to ensure the change does not break anything.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Bin Meng (10):
hw/block: m25p80: Fix dummy byte handling for Winbond flash hw/block: m25p80: Fix dummy byte handling for Numonyx/Micron flash hw/block: m25p80: Fix dummy byte handling for Macronix flash hw/block: m25p80: Fix dummy byte handling for Spansion flash hw/ssi:npcm7xx_fiu: Correct the dummy cycle emulation logic hw/ssi:xilinx_spips: Fix dummy phase handling
hw/ssi:aspeed_smc: Fix direct-read dummy bytes
Revert "aspeed/smc: Fix number of dummy cycles forFAST_READ_4
command"
Revert "aspeed/smc: snoop SPI transfers to fake dummy cycles" docs/devel: Document SSI dummy-cycle ownershipdocs/devel/index-internals.rst | 1 + docs/devel/ssi.rst | 132 +++++++++++++++++++++++++++++ include/hw/ssi/aspeed_smc.h | 2 - include/hw/ssi/xilinx_spips.h | 2 +- hw/block/m25p80.c | 146 ++++++++++++++++++++++----------- hw/ssi/aspeed_smc.c | 135 ++++-------------------------- hw/ssi/npcm7xx_fiu.c | 25 ++---- hw/ssi/xilinx_spips.c | 120 +++++++++++++++++++-------- hw/ssi/trace-events | 1 - 9 files changed, 345 insertions(+), 219 deletions(-)
Quoted 2 lines
create mode 100644
docs/devel/ssi.rst
Has anyone planned to merge this series ? I think it would be a good addition for QEMU 11.1. If not, I can take it through the aspeed queue.
Thanks,
C.
Re: [PATCH 01/10] hw/block: m25p80: Fix dummy byte handling for Winbond flash
In reply to Bin MengHi Bin,
Quoted 17 lines · Bin Meng
The m25p80 model uses
s->needed_bytesto track how many bytes a controller must send after an opcode before the flash model can enter the data phase. For address-bearing commands this includes the address bytes. For fast-read commands it also includes the dummy phase.The tricky part is that flash datasheets describe the dummy phase in clock cycles, while the QEMU SSI interface advances the flash model one transferred byte at a time. The dummy clock count therefore has to be converted to the number of SSI bytes that the controller will actually emit.
Some controllers have drivers that push these dummy bytes into a FIFO. Other controllers are programmed with a dummy-cycle count and generate the clocks themselves. The flash model still has to use the same byte count that a FIFO-style controller or the Linux spi-mem layer would use, otherwise the model waits too long and drops the first data bytes.
Quoted 4 lines
Let's fix the inconsistency from the flash side first. We start from an easy one, the Winbond flashes.
Per the Windbond W25Q256JV datasheet [1] instrunction set table
"instruction"
Quoted 19 lines
(chapter 8.1.2, 8.1.3, 8.1.4, 8.1.5), fix the wrong number of dummy bytes needed for fast read commands.
[1] https://www.winbond.com/resource-files/w25q256jv%20spi%20revb%2009202016.pdf
Fixes fe8477052831 ("m25p80: Fix QIOR/DIOR handling for Winbond")Fixes 3830c7a460b8 ("m25p80: Fix WINBOND fast read command handling")Fixes cf6f1efe0b57 ("m25p80: Fast read commands family changes")Signed-off-by Bin Meng <[email protected]>---
hw/block/m25p80.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/block/m25p80.c +0
-0
hw/block/m25p80.c static void decode_fast_read_cmd(Flash *s) · line 1007
Quoted 5 lines
hw/block/m25p80.c +1
-1@@ -1004,7 +1004,7 @@ static void decode_fast_read_cmd(Flash *s) s->needed_bytes +=1 ;break ;case MAN_WINBOND : - s->needed_bytes +=8 ; + s->needed_bytes +=1 ;
hw/block/m25p80.c-1224- case FAST_READ:
hw/block/m25p80.c-1225- case FAST_READ4:hw/block/m25p80.c:1226: decode_fast_read_cmd(s);
This method is handling 2 distinct commands. Should we pass the address count by argument? (IIUC that alters the dummy clock count)
hw/block/m25p80.c static void decode_qio_read_cmd(Flash *s) · line 1102
Quoted 9 lines
hw/block/m25p80.c +1
-1break ;case MAN_NUMONYX : s->needed_bytes +=numonyx_extract_cfg_num_dummies (s);@@ -1099,7 +1099,7 @@ static void decode_qio_read_cmd(Flash *s)switch (get_man (s)) {case MAN_WINBOND : s->needed_bytes +=WINBOND_CONTINUOUS_READ_MODE_CMD_LEN ; - s->needed_bytes +=4 ; + s->needed_bytes +=2 ;
Ditto:
hw/block/m25p80.c-1257- case QIOR:
hw/block/m25p80.c-1258- case QIOR4:
Quoted 3 lines
hw/block/m25p80.c +0
-0break ;case MAN_SPANSION : s->needed_bytes +=SPANSION_CONTINUOUS_READ_MODE_CMD_LEN ;
Re: [PATCH 03/10] hw/block: m25p80: Fix dummy byte handling for Macronix flash
In reply to Bin MengQuoted 38 lines · Bin Meng
Macronix flashes expose DC[1:0] bits in the volatile configuration register [1]. These bits select the number of dummy clock cycles used by the fast-read command families.
Convert the Macronix dummy-cycle settings through per-command-family tables and round up the non-byte-aligned cases that the byte-oriented SSI model cannot represent exactly.
[1] https://www.macronix.com/Lists/Datasheet/Attachments/8657/MX66L51235F,%203V,%20512Mb,%20v1.1.pdf
Fixes cf6f1efe0b57 ("m25p80: Fast read commands family changes")Signed-off-by Bin Meng <[email protected]>---
hw/block/m25p80.c | 66 +++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 28 deletions(-)hw/block/m25p80.c +20
-0+static uint8_t macronix_extract_cfg_num_dummies (Flash *s,uint8_t bus_width) +{ +static const uint8_t dummy_cycles_fast[4 ] = {8 ,6 ,8 ,10 }; +static const uint8_t dummy_cycles_dio[4 ] = {4 ,6 ,8 ,10 }; +static const uint8_t dummy_cycles_qio[4 ] = {6 ,4 ,8 ,10 }; +const uint8_t *dummy_cycles = dummy_cycles_fast; +uint8_t num_dummies; + +assert (get_man (s) ==MAN_MACRONIX ); + +switch (s->cmd_in_progress) { +case DIOR : +case DIOR4 : + dummy_cycles = dummy_cycles_dio; +break ; +case QIOR : +case QIOR4 : + dummy_cycles = dummy_cycles_qio; +break ; +default :
hw/block/m25p80.c static uint8_t numonyx_extract_cfg_num_dummies(Flash *s) · line 1060
Quoted 10 lines
hw/block/m25p80.c +10
-0+break ; + } + + num_dummies = dummy_cycles[extract32 (s->volatile_cfg,6 ,2 )]; + num_dummies *= bus_width; + +if (num_dummies %8 ) { +qemu_log_mask (LOG_UNIMP , +"M25P80: the number of dummy bits is not multiple of 8" ); + num_dummies =ROUND_UP (num_dummies,8 );
This is a programming error, I'd rather abort here and not let the guest continue.
Otherwise:
Quoted 4 lines
hw/block/m25p80.c +4
-0+ } + +return num_dummies /8 ; +}
Re: [PATCH 06/10] hw/ssi: xilinx_spips: Fix dummy phase handling
In reply to Bin MengQuoted 101 lines · Bin Meng
The ZynqMP generic FIFO encodes dummy phases as a number of dummy cycles. QEMU's SSI bus transfers whole bytes, so the controller model must convert the programmed cycle count to the number of SSI byte transfers needed for the selected SPI, dual SPI or quad SPI mode.
The legacy Xilinx QSPI snoop paths had the opposite problem after the m25p80 dummy handling was fixed. They still treated each dummy byte queued through the FIFO as a request to generate several SSI transfers based on the current link width. The flash model now consumes dummy phases as byte counts, so the manual FIFO path should forward one SSI transfer per dummy byte.
Update the Xilinx QSPI dummy accounting consistently for the generic FIFO, manual FIFO and LQSPI direct-read paths. Also make the command table report the dummy byte counts consumed by m25p80 for dual and quad output reads, and account for the mode byte before LQSPI data reads begin.
This matches the ZynqMP TRM (ug1085, v2.2 [1]) description of the generic FIFO dummy cycle entry and keeps the controller side aligned with the flash model's dummy byte ownership.
The description of the genenic command fifo register says:
When [receive, transmit,
data_xfer] = [0,0,1], the [immediate_data] field represents the number of dummy cycle sent on the SPI interface.[1] https://www.xilinx.com/support/documentation/user_guides/ug1085-zynq-ultrascale-trm.pdf
table 24‐22, an example of Generic FIFO Contents for Quad I/O Read Command (EBh)Fixes ef06ca3946e2 ("xilinx_spips: Add support for RX discard and RX drain")Fixes c95997a39de6 ("xilinx_spips: Add support for the ZynqMP Generic QSPI")Signed-off-by Bin Meng <[email protected]>---
include/hw/ssi/xilinx_spips.h | 2 +- hw/ssi/xilinx_spips.c | 120 ++++++++++++++++++++++++---------- 2 files changed, 88 insertions(+), 34 deletions(-)hw/ssi/xilinx_spips.c +38
-1@@ -192,6 +192,10 @@ FIELD(GQSPI_GF_SNAPSHOT, EXPONENT, 9, 1) FIELD(GQSPI_GF_SNAPSHOT, DATA_XFER, 8, 1) FIELD(GQSPI_GF_SNAPSHOT, IMMEDIATE_DATA, 0, 8) +#define GQSPI_GF_MODE_SPI 1 +#define GQSPI_GF_MODE_DSPI 2 +#define GQSPI_GF_MODE_QSPI 3@@ -457,6 +461,7 @@ static void xlnx_zynqmp_qspips_flush_fifo_g(XlnxZynqMPQSPIPS *s)int i;if (!s->regs[R_GQSPI_DATA_STS ]) { +uint32_t prev_gf_snapshot = s->regs[R_GQSPI_GF_SNAPSHOT ];uint8_t imm; s->regs[R_GQSPI_GF_SNAPSHOT ] =fifo32_pop (&s->fifo_g);@@ -484,7 +489,54 @@ static void xlnx_zynqmp_qspips_flush_fifo_g(XlnxZynqMPQSPIPS *s) } s->regs[R_GQSPI_DATA_STS ] =1ul << imm; }else { - s->regs[R_GQSPI_DATA_STS ] = imm; +/* +* When [receive, transmit, data_xfer] = [0,0,1], it represents +* the number of dummy cycle sent on the SPI interface. We need +* to convert the number of dummy cycles to bytes according to +* the SPI mode being used. +* +* Ref: ug1085 v2.2 (December 2020) table 24‐22, an example of +* Generic FIFO Contents for Quad I/O Read Command (EBh) +*/ +if (!ARRAY_FIELD_EX32 (s->regs,GQSPI_GF_SNAPSHOT ,TRANSMIT ) && + !ARRAY_FIELD_EX32 (s->regs,GQSPI_GF_SNAPSHOT ,RECIEVE )) { +uint8_t spi_mode =ARRAY_FIELD_EX32 (s->regs,GQSPI_GF_SNAPSHOT ,SPI_MODE ); +/* +* Some ZynqMP GQSPI drivers, such as Linux, use the data +* bus width in the dummy GENFIFO entry only to configure +* the controller mode. The immediate value is already +* the number of dummy cycles for the dummy phase, which +* follows the address bus width. Reuse the previous TX +* phase mode to convert cycles to SSI bytes. +* +* This does not make the model Linux-only. U-Boot emits +* the dummy entry with op->dummy.buswidth, so the entry +* mode already matches the dummy phase. Its opcode and +* address phases are immediate entries, not DATA_XFER TX +* entries, so the override below is not taken for U-Boot. +*/ +if (FIELD_EX32 (prev_gf_snapshot,GQSPI_GF_SNAPSHOT , +DATA_XFER ) && +FIELD_EX32 (prev_gf_snapshot,GQSPI_GF_SNAPSHOT , +TRANSMIT ) && + !FIELD_EX32 (prev_gf_snapshot,GQSPI_GF_SNAPSHOT , +RECIEVE )) { + spi_mode =FIELD_EX32 (prev_gf_snapshot, +GQSPI_GF_SNAPSHOT ,SPI_MODE );
hw/ssi/xilinx_spips.c static void xlnx_zynqmp_qspips_flush_fifo_g(XlnxZynqMPQSPIPS *s) · line 535
Quoted 10 lines
hw/ssi/xilinx_spips.c +10
-0+ } + +if (spi_mode ==GQSPI_GF_MODE_QSPI ) { + s->regs[R_GQSPI_DATA_STS ] =ROUND_UP (imm *4 ,8 ) /8 ; + }else if (spi_mode ==GQSPI_GF_MODE_DSPI ) { + s->regs[R_GQSPI_DATA_STS ] =ROUND_UP (imm *2 ,8 ) /8 ; + }else if (spi_mode ==GQSPI_GF_MODE_SPI ) { + s->regs[R_GQSPI_DATA_STS ] =ROUND_UP (imm *1 ,8 ) /8 ; + }else { +qemu_log_mask (LOG_GUEST_ERROR ,"Unknown SPI MODE: 0x%x " , spi_mode);
Is it safe to let the previous s->regs[R_GQSPI_DATA_STS] value?
Alternatively simpler as:
if (spi_mode) {
s->regs[R_GQSPI_DATA_STS] = 2 * (spi_mode - 1) * imm;Quoted 10 lines
hw/ssi/xilinx_spips.c +4
-0+ } + }else { + s->regs[R_GQSPI_DATA_STS ] = imm; + } } }/* Zero length transfer check */ @@ -550,7 +602,7 @@ static void xlnx_zynqmp_qspips_flush_fifo_g(XlnxZynqMPQSPIPS *s) } }
Re: [PATCH 10/10] docs/devel: Document SSI dummy-cycle ownership
In reply to Bin MengQuoted 5 lines · Bin Meng
Document the boundary between SPI/SSI controller models and SPI flash models when representing fast-read dummy cycles. It explains that flash models own command semantics, while controllers own hardware-generated dummy transfers and cycle-to-byte conversion.
Quoted 8 lines
Signed-off-by Bin Meng <[email protected]>---
docs/devel/index-internals.rst | 1 + docs/devel/ssi.rst | 132 +++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+)create mode 100644
docs/devel/ssi.rst
Hi Bin,
Quoted 14 lines · Bin Meng
This series fixes dummy-cycle accounting for SPI NOR fast-read operations across the m25p80 flash model and several SSI controller models.
The root problem is that the affected code paths mixed two different units. Flash datasheets and controller registers often describe fast-read dummy phases in clock cycles, while the SSI bus interface used by these models transfers byte-sized words to the flash. As a result, some paths treated cycle counts as byte counts directly, and other paths compensated in controller-specific ways that duplicated flash command semantics.
Quoted 3 lines
The final patch documents the intended ownership boundary: flash models own command semantics and dummy-byte consumption, while controller models own hardware-generated dummy phases and cycle-to-byte conversion.
I'd blame the API. I'd feel safer having the block/ layer use bit cycles, and a core layer converting bits to bytes when calling the SSI layer. Maybe too late to improve. The documentation you added is helpful, but I'm pretty sure we'll introduce more regressions. Anyway, thanks for your work :)
Quoted 6 lines
Some background:
While recently working on some device modeling, I hit this issue again. I then realized that I had sent a fix series for it more than five years ago, but it never made it upstream.
Quoted 7 lines
This series picks up that old work, refreshes it against the current tree, and fixes several issues in the SPI controller models. The original series is available at [1]. I have tried to verify all the SPI controller changes by booting real-world guest software to ensure the change does not break anything.
(Could we add this as a functional test?)
Quoted 39 lines · Philippe Mathieu-Daudé
Hi Bin,
Quoted 14 lines · Bin Meng
This series fixes dummy-cycle accounting for SPI NOR fast-read operations across the m25p80 flash model and several SSI controller models.
The root problem is that the affected code paths mixed two different units. Flash datasheets and controller registers often describe fast-read dummy phases in clock cycles, while the SSI bus interface used by these models transfers byte-sized words to the flash. As a result, some paths treated cycle counts as byte counts directly, and other paths compensated in controller-specific ways that duplicated flash command semantics.
Quoted 3 lines
The final patch documents the intended ownership boundary: flash models own command semantics and dummy-byte consumption, while controller models own hardware-generated dummy phases and cycle-to-byte conversion.
I'd blame the API. I'd feel safer having the
block/layer use bit cycles, and a core layer converting bits to bytes when calling the SSI layer. Maybe too late to improve. The documentation you added is helpful, but I'm pretty sure we'll introduce more regressions. Anyway, thanks for your work :)Quoted 12 lines
Some background:
While recently working on some device modeling, I hit this issue again. I then realized that I had sent a fix series for it more than five years ago, but it never made it upstream.
This series picks up that old work, refreshes it against the current tree, and fixes several issues in the SPI controller models. The original series is available at [1]. I have tried to verify all the SPI controller changes by booting real-world guest software to ensure the change does not break anything.
Quoted 3 lines
Quoted 1 line
(Could we add this as a functional test?)
Nearly all aspeed machines will test these changes when booting.
Thanks,
C.
Quoted 40 lines · Cédric Le Goater
Quoted 39 lines · Philippe Mathieu-Daudé
Hi Bin,
Quoted 14 lines · Bin Meng
This series fixes dummy-cycle accounting for SPI NOR fast-read operations across the m25p80 flash model and several SSI controller models.
The root problem is that the affected code paths mixed two different units. Flash datasheets and controller registers often describe fast-read dummy phases in clock cycles, while the SSI bus interface used by these models transfers byte-sized words to the flash. As a result, some paths treated cycle counts as byte counts directly, and other paths compensated in controller-specific ways that duplicated flash command semantics.
Quoted 3 lines
The final patch documents the intended ownership boundary: flash models own command semantics and dummy-byte consumption, while controller models own hardware-generated dummy phases and cycle-to-byte conversion.
I'd blame the API. I'd feel safer having the
block/layer use bit cycles, and a core layer converting bits to bytes when calling the SSI layer. Maybe too late to improve. The documentation you added is helpful, but I'm pretty sure we'll introduce more regressions. Anyway, thanks for your work :)Quoted 12 lines
Some background:
While recently working on some device modeling, I hit this issue again. I then realized that I had sent a fix series for it more than five years ago, but it never made it upstream.
This series picks up that old work, refreshes it against the current tree, and fixes several issues in the SPI controller models. The original series is available at [1]. I have tried to verify all the SPI controller changes by booting real-world guest software to ensure the change does not break anything.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
[1] https://lore.kernel.org/qemu-devel/20210114150902.11515-1- [email protected]/
(Could we add this as a functional test?)
Nearly all aspeed machines will test these changes when booting.
Are you saying that currently the Aspeed tests pass without this series?
Quoted 41 lines · Philippe Mathieu-Daudé
Quoted 40 lines · Cédric Le Goater
Quoted 39 lines · Philippe Mathieu-Daudé
Hi Bin,
Quoted 14 lines · Bin Meng
This series fixes dummy-cycle accounting for SPI NOR fast-read operations across the m25p80 flash model and several SSI controller models.
The root problem is that the affected code paths mixed two different units. Flash datasheets and controller registers often describe fast-read dummy phases in clock cycles, while the SSI bus interface used by these models transfers byte-sized words to the flash. As a result, some paths treated cycle counts as byte counts directly, and other paths compensated in controller-specific ways that duplicated flash command semantics.
Quoted 3 lines
The final patch documents the intended ownership boundary: flash models own command semantics and dummy-byte consumption, while controller models own hardware-generated dummy phases and cycle-to-byte conversion.
I'd blame the API. I'd feel safer having the
block/layer use bit cycles, and a core layer converting bits to bytes when calling the SSI layer. Maybe too late to improve. The documentation you added is helpful, but I'm pretty sure we'll introduce more regressions. Anyway, thanks for your work :)Quoted 12 lines
Some background:
While recently working on some device modeling, I hit this issue again. I then realized that I had sent a fix series for it more than five years ago, but it never made it upstream.
This series picks up that old work, refreshes it against the current tree, and fixes several issues in the SPI controller models. The original series is available at [1]. I have tried to verify all the SPI controller changes by booting real-world guest software to ensure the change does not break anything.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
[1] https://lore.kernel.org/qemu-devel/20210114150902.11515-1- [email protected]/
(Could we add this as a functional test?)
Nearly all aspeed machines will test these changes when booting.
Are you saying that currently the Aspeed tests pass without this series?
They do, and they also pass with the series.
The series fixes the dummy-cycle emulation and removes the ugly workarounds currently used by several SPI controller models, which rely on snooping transfers. This issue has been reported a few times in the past, with tentative fixes, but this is the first proposal that addresses it cleanly.
Thanks,
C.
Re: [PATCH 01/10] hw/block: m25p80: Fix dummy byte handling for Winbond flash
In reply to Philippe Mathieu-DaudéHI Philippe,
Quoted 57 lines · Philippe Mathieu-Daudé
Hi Bin,
Quoted 17 lines · Bin Meng
The m25p80 model uses
s->needed_bytesto track how many bytes a controller must send after an opcode before the flash model can enter the data phase. For address-bearing commands this includes the address bytes. For fast-read commands it also includes the dummy phase.The tricky part is that flash datasheets describe the dummy phase in clock cycles, while the QEMU SSI interface advances the flash model one transferred byte at a time. The dummy clock count therefore has to be converted to the number of SSI bytes that the controller will actually emit.
Some controllers have drivers that push these dummy bytes into a FIFO. Other controllers are programmed with a dummy-cycle count and generate the clocks themselves. The flash model still has to use the same byte count that a FIFO-style controller or the Linux spi-mem layer would use, otherwise the model waits too long and drops the first data bytes.
Quoted 4 lines
Let's fix the inconsistency from the flash side first. We start from an easy one, the Winbond flashes.
Per the Windbond W25Q256JV datasheet [1] instrunction set table
"instruction"
Quoted 19 lines
(chapter 8.1.2, 8.1.3, 8.1.4, 8.1.5), fix the wrong number of dummy bytes needed for fast read commands.
[1] https://www.winbond.com/resource-files/w25q256jv%20spi%20revb%2009202016.pdf
Fixes fe8477052831 ("m25p80: Fix QIOR/DIOR handling for Winbond")Fixes 3830c7a460b8 ("m25p80: Fix WINBOND fast read command handling")Fixes cf6f1efe0b57 ("m25p80: Fast read commands family changes")Signed-off-by Bin Meng <[email protected]>---
hw/block/m25p80.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/block/m25p80.c +0
-0hw/block/m25p80.c static void decode_fast_read_cmd(Flash *s) · line 1007
Quoted 5 lines
hw/block/m25p80.c +1
-1@@ -1004,7 +1004,7 @@ static void decode_fast_read_cmd(Flash *s) s->needed_bytes +=1 ;break ;case MAN_WINBOND : - s->needed_bytes +=8 ; + s->needed_bytes +=1 ;hw/block/m25p80.c-1224- case
FAST_READ:
hw/block/m25p80.c-1225- caseFAST_READ4:hw/block/m25p80.c:1226:decode_fast_read_cmd(s);
Quoted 3 lines
This method is handling 2 distinct commands. Should we pass the address count by argument? (IIUC that alters the dummy clock count)
Per the datasheet, the only difference is 3-byte address vs. 4-byte address. The number of dummy cycles are the same.
Quoted 12 lines
hw/block/m25p80.c static void decode_qio_read_cmd(Flash *s) · line 1102
Quoted 9 lines
hw/block/m25p80.c +1
-1break ;case MAN_NUMONYX : s->needed_bytes +=numonyx_extract_cfg_num_dummies (s);@@ -1099,7 +1099,7 @@ static void decode_qio_read_cmd(Flash *s)switch (get_man (s)) {case MAN_WINBOND : s->needed_bytes +=WINBOND_CONTINUOUS_READ_MODE_CMD_LEN ; - s->needed_bytes +=4 ; + s->needed_bytes +=2 ;Ditto:
Quoted 7 lines
hw/block/m25p80.c-1257- case QIOR:
hw/block/m25p80.c-1258- case QIOR4:Quoted 3 lines
hw/block/m25p80.c +0
-0break ;case MAN_SPANSION : s->needed_bytes +=SPANSION_CONTINUOUS_READ_MODE_CMD_LEN ;
Regards,
Bin
Re: [PATCH 06/10] hw/ssi: xilinx_spips: Fix dummy phase handling
In reply to Philippe Mathieu-DaudéQuoted 107 lines · Philippe Mathieu-Daudé
Quoted 105 lines · Bin Meng
The ZynqMP generic FIFO encodes dummy phases as a number of dummy cycles. QEMU's SSI bus transfers whole bytes, so the controller model must convert the programmed cycle count to the number of SSI byte transfers needed for the selected SPI, dual SPI or quad SPI mode.
The legacy Xilinx QSPI snoop paths had the opposite problem after the m25p80 dummy handling was fixed. They still treated each dummy byte queued through the FIFO as a request to generate several SSI transfers based on the current link width. The flash model now consumes dummy phases as byte counts, so the manual FIFO path should forward one SSI transfer per dummy byte.
Update the Xilinx QSPI dummy accounting consistently for the generic FIFO, manual FIFO and LQSPI direct-read paths. Also make the command table report the dummy byte counts consumed by m25p80 for dual and quad output reads, and account for the mode byte before LQSPI data reads begin.
This matches the ZynqMP TRM (ug1085, v2.2 [1]) description of the generic FIFO dummy cycle entry and keeps the controller side aligned with the flash model's dummy byte ownership.
The description of the genenic command fifo register says:
When [receive, transmit,
data_xfer] = [0,0,1], the [immediate_data] field represents the number of dummy cycle sent on the SPI interface.[1] https://www.xilinx.com/support/documentation/user_guides/ug1085-zynq-ultrascale-trm.pdf
table 24‐22, an example of Generic FIFO Contents for Quad I/O Read Command (EBh)Fixes ef06ca3946e2 ("xilinx_spips: Add support for RX discard and RX drain")Fixes c95997a39de6 ("xilinx_spips: Add support for the ZynqMP Generic QSPI")Signed-off-by Bin Meng <[email protected]>---
include/hw/ssi/xilinx_spips.h | 2 +- hw/ssi/xilinx_spips.c | 120 ++++++++++++++++++++++++---------- 2 files changed, 88 insertions(+), 34 deletions(-)hw/ssi/xilinx_spips.c +42
-1@@ -192,6 +192,10 @@ FIELD(GQSPI_GF_SNAPSHOT, EXPONENT, 9, 1) FIELD(GQSPI_GF_SNAPSHOT, DATA_XFER, 8, 1) FIELD(GQSPI_GF_SNAPSHOT, IMMEDIATE_DATA, 0, 8) +#define GQSPI_GF_MODE_SPI 1 +#define GQSPI_GF_MODE_DSPI 2 +#define GQSPI_GF_MODE_QSPI 3@@ -457,6 +461,7 @@ static void xlnx_zynqmp_qspips_flush_fifo_g(XlnxZynqMPQSPIPS *s)int i;if (!s->regs[R_GQSPI_DATA_STS ]) { +uint32_t prev_gf_snapshot = s->regs[R_GQSPI_GF_SNAPSHOT ];uint8_t imm; s->regs[R_GQSPI_GF_SNAPSHOT ] =fifo32_pop (&s->fifo_g);@@ -484,7 +489,54 @@ static void xlnx_zynqmp_qspips_flush_fifo_g(XlnxZynqMPQSPIPS *s) } s->regs[R_GQSPI_DATA_STS ] =1ul << imm; }else { - s->regs[R_GQSPI_DATA_STS ] = imm; +/* +* When [receive, transmit, data_xfer] = [0,0,1], it represents +* the number of dummy cycle sent on the SPI interface. We need +* to convert the number of dummy cycles to bytes according to +* the SPI mode being used. +* +* Ref: ug1085 v2.2 (December 2020) table 24‐22, an example of +* Generic FIFO Contents for Quad I/O Read Command (EBh) +*/ +if (!ARRAY_FIELD_EX32 (s->regs,GQSPI_GF_SNAPSHOT ,TRANSMIT ) && + !ARRAY_FIELD_EX32 (s->regs,GQSPI_GF_SNAPSHOT ,RECIEVE )) { +uint8_t spi_mode =ARRAY_FIELD_EX32 (s->regs,GQSPI_GF_SNAPSHOT ,SPI_MODE ); +/* +* Some ZynqMP GQSPI drivers, such as Linux, use the data +* bus width in the dummy GENFIFO entry only to configure +* the controller mode. The immediate value is already +* the number of dummy cycles for the dummy phase, which +* follows the address bus width. Reuse the previous TX +* phase mode to convert cycles to SSI bytes. +* +* This does not make the model Linux-only. U-Boot emits +* the dummy entry with op->dummy.buswidth, so the entry +* mode already matches the dummy phase. Its opcode and +* address phases are immediate entries, not DATA_XFER TX +* entries, so the override below is not taken for U-Boot. +*/ +if (FIELD_EX32 (prev_gf_snapshot,GQSPI_GF_SNAPSHOT , +DATA_XFER ) && +FIELD_EX32 (prev_gf_snapshot,GQSPI_GF_SNAPSHOT , +TRANSMIT ) && + !FIELD_EX32 (prev_gf_snapshot,GQSPI_GF_SNAPSHOT , +RECIEVE )) { + spi_mode =FIELD_EX32 (prev_gf_snapshot, +GQSPI_GF_SNAPSHOT ,SPI_MODE ); + } + +if (spi_mode ==GQSPI_GF_MODE_QSPI ) { + s->regs[R_GQSPI_DATA_STS ] =ROUND_UP (imm *4 ,8 ) /8 ;
Quoted 8 lines
hw/ssi/xilinx_spips.c static void xlnx_zynqmp_qspips_flush_fifo_g(XlnxZynqMPQSPIPS *s) · line 535
Quoted 6 lines
hw/ssi/xilinx_spips.c +6
-0+ }else if (spi_mode ==GQSPI_GF_MODE_DSPI ) { + s->regs[R_GQSPI_DATA_STS ] =ROUND_UP (imm *2 ,8 ) /8 ; + }else if (spi_mode ==GQSPI_GF_MODE_SPI ) { + s->regs[R_GQSPI_DATA_STS ] =ROUND_UP (imm *1 ,8 ) /8 ; + }else { +qemu_log_mask (LOG_GUEST_ERROR ,"Unknown SPI MODE: 0x%x " , spi_mode);Is it safe to let the previous s->regs[R_GQSPI_DATA_STS] value?
Yes, the previous value remains zero and won't pass the sanity check below (see /* Zero length transfer check */)
Quoted 5 lines
Alternatively simpler as:
if (spi_mode) { s->regs[R_GQSPI_DATA_STS] = 2 * (spi_mode - 1) * imm;
No, imm should be divided by 8 as we are counting bytes here, not cycles.
Quoted 12 lines
hw/ssi/xilinx_spips.c static void xlnx_zynqmp_qspips_flush_fifo_g(XlnxZynqMPQSPIPS *s) · line 603
Quoted 11 lines
hw/ssi/xilinx_spips.c +4
-0+ } + }else { + s->regs[R_GQSPI_DATA_STS ] = imm; + } } }/* Zero length transfer check */ @@ -550,7 +602,7 @@ static void xlnx_zynqmp_qspips_flush_fifo_g(XlnxZynqMPQSPIPS *s) } }
Regards,
Bin