[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 26/35] ahci: add rwerror=stop support for ncq
From: |
John Snow |
Subject: |
[Qemu-devel] [PULL 26/35] ahci: add rwerror=stop support for ncq |
Date: |
Sat, 4 Jul 2015 02:07:05 -0400 |
Handle NCQ failures for cases where we want to halt the VM on IO errors.
Upon a VM state change, retry the halted NCQ commands.
Signed-off-by: John Snow <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Message-id: address@hidden
---
hw/ide/ahci.c | 36 ++++++++++++++++++++++++++++++++++--
hw/ide/ahci.h | 1 +
hw/ide/core.c | 7 +++++++
hw/ide/internal.h | 2 ++
4 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index b0b9b41..d996f37 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -581,6 +581,7 @@ static void ahci_reset_port(AHCIState *s, int port)
/* reset ncq queue */
for (i = 0; i < AHCI_MAX_CMDS; i++) {
NCQTransferState *ncq_tfs = &s->dev[port].ncq_tfs[i];
+ ncq_tfs->halt = false;
if (!ncq_tfs->used) {
continue;
}
@@ -960,12 +961,23 @@ static void ncq_cb(void *opaque, int ret)
}
if (ret < 0) {
- ncq_err(ncq_tfs);
+ bool is_read = ncq_tfs->cmd == READ_FPDMA_QUEUED;
+ BlockErrorAction action = blk_get_error_action(ide_state->blk,
+ is_read, -ret);
+ if (action == BLOCK_ERROR_ACTION_STOP) {
+ ncq_tfs->halt = true;
+ ide_state->bus->error_status = IDE_RETRY_HBA;
+ } else if (action == BLOCK_ERROR_ACTION_REPORT) {
+ ncq_err(ncq_tfs);
+ }
+ blk_error_action(ide_state->blk, action, is_read, -ret);
} else {
ide_state->status = READY_STAT | SEEK_STAT;
}
- ncq_finish(ncq_tfs);
+ if (!ncq_tfs->halt) {
+ ncq_finish(ncq_tfs);
+ }
}
static int is_ncq(uint8_t ata_cmd)
@@ -988,7 +1000,9 @@ static void execute_ncq_command(NCQTransferState *ncq_tfs)
AHCIDevice *ad = ncq_tfs->drive;
IDEState *ide_state = &ad->port.ifs[0];
int port = ad->port_no;
+
g_assert(is_ncq(ncq_tfs->cmd));
+ ncq_tfs->halt = false;
switch (ncq_tfs->cmd) {
case READ_FPDMA_QUEUED:
@@ -1319,6 +1333,23 @@ static void ahci_restart_dma(IDEDMA *dma)
}
/**
+ * IDE/PIO restarts are handled by the core layer, but NCQ commands
+ * need an extra kick from the AHCI HBA.
+ */
+static void ahci_restart(IDEDMA *dma)
+{
+ AHCIDevice *ad = DO_UPCAST(AHCIDevice, dma, dma);
+ int i;
+
+ for (i = 0; i < AHCI_MAX_CMDS; i++) {
+ NCQTransferState *ncq_tfs = &ad->ncq_tfs[i];
+ if (ncq_tfs->halt) {
+ execute_ncq_command(ncq_tfs);
+ }
+ }
+}
+
+/**
* Called in DMA R/W chains to read the PRDT, utilizing ahci_populate_sglist.
* Not currently invoked by PIO R/W chains,
* which invoke ahci_populate_sglist via ahci_start_transfer.
@@ -1406,6 +1437,7 @@ static void ahci_irq_set(void *opaque, int n, int level)
static const IDEDMAOps ahci_dma_ops = {
.start_dma = ahci_start_dma,
+ .restart = ahci_restart,
.restart_dma = ahci_restart_dma,
.start_transfer = ahci_start_transfer,
.prepare_buf = ahci_dma_prepare_buf,
diff --git a/hw/ide/ahci.h b/hw/ide/ahci.h
index 33607d7..47a3122 100644
--- a/hw/ide/ahci.h
+++ b/hw/ide/ahci.h
@@ -262,6 +262,7 @@ typedef struct NCQTransferState {
uint8_t cmd;
int slot;
int used;
+ bool halt;
} NCQTransferState;
struct AHCIDevice {
diff --git a/hw/ide/core.c b/hw/ide/core.c
index be7c350..122e955 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2371,6 +2371,13 @@ static void ide_restart_bh(void *opaque)
* called function can set a new error status. */
bus->error_status = 0;
+ /* The HBA has generically asked to be kicked on retry */
+ if (error_status & IDE_RETRY_HBA) {
+ if (s->bus->dma->ops->restart) {
+ s->bus->dma->ops->restart(s->bus->dma);
+ }
+ }
+
if (error_status & IDE_RETRY_DMA) {
if (error_status & IDE_RETRY_TRIM) {
ide_restart_dma(s, IDE_DMA_TRIM);
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 3736e1b..30fdcbc 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -436,6 +436,7 @@ struct IDEDMAOps {
DMAInt32Func *prepare_buf;
DMAu32Func *commit_buf;
DMAIntFunc *rw_buf;
+ DMAVoidFunc *restart;
DMAVoidFunc *restart_dma;
DMAStopFunc *set_inactive;
DMAVoidFunc *cmd_done;
@@ -499,6 +500,7 @@ struct IDEDevice {
#define IDE_RETRY_READ 0x20
#define IDE_RETRY_FLUSH 0x40
#define IDE_RETRY_TRIM 0x80
+#define IDE_RETRY_HBA 0x100
static inline IDEState *idebus_active_if(IDEBus *bus)
{
--
2.1.0
- [Qemu-devel] [PULL 15/35] libqos/ahci: edit wait to be ncq aware, (continued)
- [Qemu-devel] [PULL 15/35] libqos/ahci: edit wait to be ncq aware, John Snow, 2015/07/04
- [Qemu-devel] [PULL 16/35] libqos/ahci: adjust expected NCQ interrupts, John Snow, 2015/07/04
- [Qemu-devel] [PULL 18/35] libqos/ahci: Force all NCQ commands to be LBA48, John Snow, 2015/07/04
- [Qemu-devel] [PULL 19/35] qtest/ahci: simple ncq data test, John Snow, 2015/07/04
- [Qemu-devel] [PULL 20/35] qtest/ahci: ncq migration test, John Snow, 2015/07/04
- [Qemu-devel] [PULL 22/35] ahci: stash ncq command, John Snow, 2015/07/04
- [Qemu-devel] [PULL 23/35] ahci: assert is_ncq for process_ncq, John Snow, 2015/07/04
- [Qemu-devel] [PULL 24/35] ahci: refactor process_ncq_command, John Snow, 2015/07/04
- [Qemu-devel] [PULL 25/35] ahci: factor ncq_finish out of ncq_cb, John Snow, 2015/07/04
- [Qemu-devel] [PULL 21/35] ide: add limit to .prepare_buf(), John Snow, 2015/07/04
- [Qemu-devel] [PULL 26/35] ahci: add rwerror=stop support for ncq,
John Snow <=
- [Qemu-devel] [PULL 27/35] ahci: correct types in NCQTransferState, John Snow, 2015/07/04
- [Qemu-devel] [PULL 28/35] ahci: correct ncq sector count, John Snow, 2015/07/04
- [Qemu-devel] [PULL 29/35] qtest/ahci: halted NCQ test, John Snow, 2015/07/04
- [Qemu-devel] [PULL 31/35] ahci: add get_cmd_header helper, John Snow, 2015/07/04
- [Qemu-devel] [PULL 32/35] ahci: ncq migration, John Snow, 2015/07/04
- [Qemu-devel] [PULL 30/35] ahci: add cmd header to ncq transfer state, John Snow, 2015/07/04
- [Qemu-devel] [PULL 34/35] qtest/ahci: halted ncq migration test, John Snow, 2015/07/04
- [Qemu-devel] [PULL 33/35] ahci: Do not map cmd_fis to generate response, John Snow, 2015/07/04
- [Qemu-devel] [PULL 35/35] ahci: fix sdb fis semantics, John Snow, 2015/07/04