[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-arm] [PATCH v2 17/21] aspeed/smc: inject errors in DMA checksum
From: |
Cédric Le Goater |
Subject: |
[Qemu-arm] [PATCH v2 17/21] aspeed/smc: inject errors in DMA checksum |
Date: |
Tue, 18 Jun 2019 18:53:07 +0200 |
Emulate read errors in the DMA Checksum Register for high frequencies
and optimistic settings of the Read Timing Compensation Register. This
will help in tuning the SPI timing calibration algorithm.
The values below are those to expect from the first flash device of
the FMC controller of a palmetto-bmc machine.
Signed-off-by: Cédric Le Goater <address@hidden>
Reviewed-by: Joel Stanley <address@hidden>
---
Changes since v1:
- introduced a "inject-failure" property as suggested by Philippe
include/hw/ssi/aspeed_smc.h | 1 +
hw/ssi/aspeed_smc.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/include/hw/ssi/aspeed_smc.h b/include/hw/ssi/aspeed_smc.h
index 453357cc09bf..ba496956cd5e 100644
--- a/include/hw/ssi/aspeed_smc.h
+++ b/include/hw/ssi/aspeed_smc.h
@@ -87,6 +87,7 @@ typedef struct AspeedSMCState {
uint32_t num_cs;
qemu_irq *cs_lines;
+ bool inject_failure;
SSIBus *spi;
diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
index 4a2e3a9135b6..5c017f631ffd 100644
--- a/hw/ssi/aspeed_smc.c
+++ b/hw/ssi/aspeed_smc.c
@@ -867,6 +867,36 @@ static void aspeed_smc_dma_calibration(AspeedSMCState *s)
s->regs[s->r_ctrl0 + cs] |= CE_CTRL_CLOCK_FREQ(hclk_div);
}
+/*
+ * Emulate read errors in the DMA Checksum Register for high
+ * frequencies and optimistic settings of the Read Timing Compensation
+ * Register. This will help in tuning the SPI timing calibration
+ * algorithm.
+ */
+static bool aspeed_smc_inject_read_failure(AspeedSMCState *s)
+{
+ uint8_t delay =
+ (s->regs[R_DMA_CTRL] >> DMA_CTRL_DELAY_SHIFT) & DMA_CTRL_DELAY_MASK;
+ uint8_t hclk_mask =
+ (s->regs[R_DMA_CTRL] >> DMA_CTRL_FREQ_SHIFT) & DMA_CTRL_FREQ_MASK;
+
+ /*
+ * Typical values of a palmetto-bmc machine.
+ */
+ switch (aspeed_smc_hclk_divisor(hclk_mask)) {
+ case 4 ... 16:
+ return false;
+ case 3: /* at least one HCLK cycle delay */
+ return (delay & 0x7) < 1;
+ case 2: /* at least two HCLK cycle delay */
+ return (delay & 0x7) < 2;
+ case 1: /* (> 100MHz) is above the max freq of the controller */
+ return true;
+ default:
+ g_assert_not_reached();
+ }
+}
+
/*
* Accumulate the result of the reads to provide a checksum that will
* be used to validate the read timing settings.
@@ -904,6 +934,11 @@ static void aspeed_smc_dma_checksum(AspeedSMCState *s)
s->regs[R_DMA_FLASH_ADDR] += 4;
s->regs[R_DMA_LEN] -= 4;
}
+
+ if (s->inject_failure && aspeed_smc_inject_read_failure(s)) {
+ s->regs[R_DMA_CHECKSUM] = 0xbadc0de;
+ }
+
}
static void aspeed_smc_dma_rw(AspeedSMCState *s)
@@ -1189,6 +1224,7 @@ static const VMStateDescription vmstate_aspeed_smc = {
static Property aspeed_smc_properties[] = {
DEFINE_PROP_UINT32("num-cs", AspeedSMCState, num_cs, 1),
+ DEFINE_PROP_BOOL("inject-failure", AspeedSMCState, inject_failure, false),
DEFINE_PROP_UINT64("sdram-base", AspeedSMCState, sdram_base, 0),
DEFINE_PROP_LINK("dram", AspeedSMCState, dram_mr,
TYPE_MEMORY_REGION, MemoryRegion *),
--
2.21.0
- [Qemu-arm] [PATCH v2 10/21] aspeed/timer: Provide back-pressure information for short periods, (continued)
- [Qemu-arm] [PATCH v2 10/21] aspeed/timer: Provide back-pressure information for short periods, Cédric Le Goater, 2019/06/18
- [Qemu-arm] [PATCH v2 11/21] aspeed/timer: Ensure positive muldiv delta, Cédric Le Goater, 2019/06/18
- [Qemu-arm] [PATCH v2 12/21] aspeed: remove the "ram" link, Cédric Le Goater, 2019/06/18
- [Qemu-arm] [PATCH v2 13/21] aspeed: add a RAM memory region container, Cédric Le Goater, 2019/06/18
- [Qemu-arm] [PATCH v2 14/21] aspeed/smc: add a 'sdram_base' property, Cédric Le Goater, 2019/06/18
- [Qemu-arm] [PATCH v2 15/21] aspeed/smc: add support for DMAs, Cédric Le Goater, 2019/06/18
- [Qemu-arm] [PATCH v2 18/21] aspeed/smc: Calculate checksum on normal DMA, Cédric Le Goater, 2019/06/18
- [Qemu-arm] [PATCH v2 16/21] aspeed/smc: add DMA calibration settings, Cédric Le Goater, 2019/06/18
- [Qemu-arm] [PATCH v2 17/21] aspeed/smc: inject errors in DMA checksum,
Cédric Le Goater <=
- [Qemu-arm] [PATCH v2 19/21] aspeed: Add support for the swift-bmc board, Cédric Le Goater, 2019/06/18
- [Qemu-arm] [PATCH v2 20/21] hw/misc/aspeed_xdma: New device, Cédric Le Goater, 2019/06/18
- [Qemu-arm] [PATCH v2 21/21] aspeed: vic: Add support for legacy register interface, Cédric Le Goater, 2019/06/18