improve ahci test suite
cover improve ahci test suite
From: Niklas Cassel <[email protected]>
Hello John,
This series should be applied on top of the series called:
"[PATCH v2 0/8] misc AHCI cleanups"
which can be found here:
https://lists.nongnu.org/archive/html/qemu-block/2023-06/msg00038.html
This series improves the ahci test suite to be in line with the AHCI specification when it comes to taskfile errors.
Theoretically these commits could be squashed with the corresponding patch for the QEMU model, however, that would lose the commit log for the test patches, so I prefer to keep them separate.
Please review.
Kind regards,
Niklas
Niklas Cassel (5):
libqos/ahci: fix ahci_command_wait() libqos/ahci: fix ahci_port_check_nonbusy() libqos/ahci: simplify ahci_port_check_error() libqos/ahci: improve ahci_port_check_error() libqos/ahci: perform mandatory error recovery on error
tests/qtest/libqos/ahci.c | 106 ++++++++++++++++++++++++++++---------- tests/qtest/libqos/ahci.h | 8 ++- 2 files changed, 83 insertions(+), 31 deletions(-)
Signature · 1 line
2.40.1
PATCH 1/5 libqos/ahci: fix ahci_command_wait()
From: Niklas Cassel <[email protected]>
A command that has ERR_STAT set, does not get to clear PxCI. See AHCI 1.3.1, section 5.3.8, states RegFIS:Entry and RegFIS:ClearCI, and 5.3.16.5 ERR:FatalTaskfile.
Some tests, e.g. test_atapi_tray() call ahci_atapi_test_ready() with ready == false, intentionally sending a command that will cause an error.
Thus, ahci_command_wait() cannot simply wait indefinitely for PxCI to be cleared, it also has to take ERR_STAT into account.
--- tests/qtest/libqos/ahci.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
tests/qtest/libqos/ahci.c +4 -3
@@ -1207,9 +1207,10 @@ void ahci_command_wait(AHCIQState *ahci, AHCICommand *cmd)#define RSET (REG ,MASK ) (BITSET(ahci_px_rreg(ahci, cmd->port, (REG)), (MASK))) -while (RSET (AHCI_PX_TFD ,AHCI_PX_TFD_STS_BSY ) || -RSET (AHCI_PX_CI ,1 << cmd->slot) || - (cmd->props->ncq &&RSET (AHCI_PX_SACT ,1 << cmd->slot))) { +while (!RSET (AHCI_PX_TFD ,AHCI_PX_TFD_STS_ERR ) && + (RSET (AHCI_PX_TFD ,AHCI_PX_TFD_STS_BSY ) || +RSET (AHCI_PX_CI ,1 << cmd->slot) || + (cmd->props->ncq &&RSET (AHCI_PX_SACT ,1 << cmd->slot)))) {usleep (50 ); }
Signature · 1 line
2.40.1
PATCH 2/5 libqos/ahci: fix ahci_port_check_nonbusy()
In reply to Niklas CasselFrom: Niklas Cassel <[email protected]>
A command that has ERR_STAT set, does not get to clear PxCI. See AHCI 1.3.1, section 5.3.8, states RegFIS:Entry and RegFIS:ClearCI, and 5.3.16.5 ERR:FatalTaskfile.
Some tests, e.g. test_atapi_tray() call ahci_atapi_test_ready() with ready == false, intentionally sending a command that will cause an error.
Thus, ahci_port_check_nonbusy() cannot assume that PxCI and PxSACT will always be cleared for the executed command.
--- tests/qtest/libqos/ahci.c | 27 +++++++++++++++++++++------ tests/qtest/libqos/ahci.h | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-)
tests/qtest/libqos/ahci.c +21 -6
@@ -444,17 +444,32 @@ void ahci_port_check_interrupts(AHCIQState *ahci, uint8_t port, g_assert_cmphex(ahci_px_rreg(ahci, port, AHCI_PX_IS), ==, 0); } -void ahci_port_check_nonbusy (AHCIQState *ahci,uint8_t port,uint8_t slot) +void ahci_port_check_nonbusy (AHCIQState *ahci,AHCICommand *cmd) { +uint8_t slot = cmd->slot; +uint8_t port = cmd->port;uint32_t reg; -/* Assert that the command slot is no longer busy (NCQ) */ +/* For NCQ command with error PxSACT bit should still be set. +* For NCQ command without error, PxSACT bit should be cleared. +* For non-NCQ command, PxSACT bit should always be cleared. */ reg =ahci_px_rreg (ahci, port,AHCI_PX_SACT ); -ASSERT_BIT_CLEAR (reg, (1 << slot)); +if (cmd->props->ncq && cmd->errors) { +ASSERT_BIT_SET (reg, (1 << slot)); + }else { +ASSERT_BIT_CLEAR (reg, (1 << slot)); + } -/* Non-NCQ */ +/* For non-NCQ command with error, PxCI bit should still be set. +* For non-NCQ command without error, PxCI bit should be cleared. +* For NCQ command without error, PxCI bit should be cleared. +* For NCQ command with error, PxCI bit may or may not be cleared. */ reg =ahci_px_rreg (ahci, port,AHCI_PX_CI ); -ASSERT_BIT_CLEAR (reg, (1 << slot)); +if (!cmd->props->ncq && cmd->errors) { +ASSERT_BIT_SET (reg, (1 << slot)); + }else if (!cmd->errors) { +ASSERT_BIT_CLEAR (reg, (1 << slot)); + }/* And assert that we are generally not busy. */ reg =ahci_px_rreg (ahci, port,AHCI_PX_TFD );
@@ -1229,7 +1244,7 @@ void ahci_command_verify(AHCIQState *ahci, AHCICommand *cmd)ahci_port_check_error (ahci, port, cmd->interrupts, cmd->errors);ahci_port_check_interrupts (ahci, port, cmd->interrupts); -ahci_port_check_nonbusy (ahci, port, slot); +ahci_port_check_nonbusy (ahci, cmd);ahci_port_check_cmd_sanity (ahci, cmd);if (cmd->interrupts &AHCI_PX_IS_DHRS ) {ahci_port_check_d2h_sanity (ahci, port, slot);
tests/qtest/libqos/ahci.h +1 -1
@@ -594,7 +594,7 @@ void ahci_port_check_error(AHCIQState *ahci, uint8_t port, uint32_t imask, uint8_t emask);void ahci_port_check_interrupts (AHCIQState *ahci,uint8_t port,uint32_t intr_mask); -void ahci_port_check_nonbusy (AHCIQState *ahci,uint8_t port,uint8_t slot); +void ahci_port_check_nonbusy (AHCIQState *ahci,AHCICommand *cmd);void ahci_port_check_d2h_sanity (AHCIQState *ahci,uint8_t port,uint8_t slot);void ahci_port_check_pio_sanity (AHCIQState *ahci,AHCICommand *cmd);void ahci_port_check_cmd_sanity (AHCIQState *ahci,AHCICommand *cmd);
Signature · 1 line
2.40.1
PATCH 3/5 libqos/ahci: simplify ahci_port_check_error()
In reply to Niklas CasselFrom: Niklas Cassel <[email protected]>
Modify ahci_port_check_error() to simply take a struct AHCICommand. This way, the conditionals are in line which the existing code, e.g. ahci_port_check_nonbusy(), which checks for cmd->errors.
This makes the code easier to reason with, we don't want to use cmd->errors in some functions and emask in some functions.
No functional changes intended.
--- tests/qtest/libqos/ahci.c | 14 +++++++------- tests/qtest/libqos/ahci.h | 3 +-- 2 files changed, 8 insertions(+), 9 deletions(-)
tests/qtest/libqos/ahci.c +7 -7
@@ -404,14 +404,14 @@ void ahci_port_clear(AHCIQState *ahci, uint8_t port)/** * Check a port for errors. */ -void ahci_port_check_error (AHCIQState *ahci,uint8_t port, -uint32_t imask,uint8_t emask) +void ahci_port_check_error (AHCIQState *ahci,AHCICommand *cmd) { +uint8_t port = cmd->port;uint32_t reg;/* The upper 9 bits of the IS register all indicate errors. */ reg =ahci_px_rreg (ahci, port,AHCI_PX_IS ); - reg &= ~imask; + reg &= ~cmd->interrupts; reg >>=23 ; g_assert_cmphex(reg, ==, 0);
@@ -421,13 +421,13 @@ void ahci_port_check_error(AHCIQState *ahci, uint8_t port,/* The TFD also has two error sections. */ reg =ahci_px_rreg (ahci, port,AHCI_PX_TFD ); -if (!emask) { +if (!cmd->errors) {ASSERT_BIT_CLEAR (reg,AHCI_PX_TFD_STS_ERR ); }else {ASSERT_BIT_SET (reg,AHCI_PX_TFD_STS_ERR ); } -ASSERT_BIT_CLEAR (reg,AHCI_PX_TFD_ERR & (~emask <<8 )); -ASSERT_BIT_SET (reg,AHCI_PX_TFD_ERR & (emask <<8 )); +ASSERT_BIT_CLEAR (reg,AHCI_PX_TFD_ERR & (~cmd->errors <<8 )); +ASSERT_BIT_SET (reg,AHCI_PX_TFD_ERR & (cmd->errors <<8 )); } void ahci_port_check_interrupts(AHCIQState *ahci, uint8_t port,
@@ -1242,7 +1242,7 @@ void ahci_command_verify(AHCIQState *ahci, AHCICommand *cmd)uint8_t slot = cmd->slot;uint8_t port = cmd->port; -ahci_port_check_error (ahci, port, cmd->interrupts, cmd->errors); +ahci_port_check_error (ahci, cmd);ahci_port_check_interrupts (ahci, port, cmd->interrupts);ahci_port_check_nonbusy (ahci, cmd);ahci_port_check_cmd_sanity (ahci, cmd);
tests/qtest/libqos/ahci.h +1 -2
@@ -590,8 +590,7 @@ void ahci_set_command_header(AHCIQState *ahci, uint8_t port,void ahci_destroy_command (AHCIQState *ahci,uint8_t port,uint8_t slot);/* AHCI sanity check routines */ -void ahci_port_check_error (AHCIQState *ahci,uint8_t port, -uint32_t imask,uint8_t emask); +void ahci_port_check_error (AHCIQState *ahci,AHCICommand *cmd);void ahci_port_check_interrupts (AHCIQState *ahci,uint8_t port,uint32_t intr_mask);void ahci_port_check_nonbusy (AHCIQState *ahci,AHCICommand *cmd);
Signature · 1 line
2.40.1
PATCH 4/5 libqos/ahci: improve ahci_port_check_error()
In reply to Niklas CasselFrom: Niklas Cassel <[email protected]>
Improve ahci_port_check_error() to also assert that PxIS.TFES is set when expecting errors.
--- tests/qtest/libqos/ahci.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
tests/qtest/libqos/ahci.c +12 -6
@@ -409,13 +409,19 @@ void ahci_port_check_error(AHCIQState *ahci, AHCICommand *cmd)uint8_t port = cmd->port;uint32_t reg; -/* The upper 9 bits of the IS register all indicate errors. */ - reg =ahci_px_rreg (ahci, port,AHCI_PX_IS ); - reg &= ~cmd->interrupts; - reg >>=23 ; - g_assert_cmphex(reg, ==, 0); +/* If expecting TF error, ensure that TFES is set. */ +if (cmd->errors) { + reg =ahci_px_rreg (ahci, port,AHCI_PX_IS ); +ASSERT_BIT_SET (reg,AHCI_PX_IS_TFES ); + }else { +/* The upper 9 bits of the IS register all indicate errors. */ + reg =ahci_px_rreg (ahci, port,AHCI_PX_IS ); + reg &= ~cmd->interrupts; + reg >>=23 ; + g_assert_cmphex(reg, ==, 0); + } -/* The Sata Error Register should be empty. */ +/* The Sata Error Register should be empty, even when expecting TF error. */ reg =ahci_px_rreg (ahci, port,AHCI_PX_SERR ); g_assert_cmphex(reg, ==, 0);
Signature · 1 line
2.40.1
PATCH 5/5 libqos/ahci: perform mandatory error recovery on error
In reply to Niklas CasselFrom: Niklas Cassel <[email protected]>
When the HBA encouters an error, the host has to perform error recovery, see AHCI 1.3.1 section 6.2.2.1, in order to be able issue new commands. If we don't do this, all the commands that we queue will get aborted.
Some tests, e.g. test_atapi_tray() call ahci_atapi_test_ready() with ready == false, intentionally sending a command that will cause an error.
After test_atapi_tray() has called ahci_atapi_test_ready(), it directly calls ahci_atapi_get_sense() to send a REQUEST SENSE command.
If we don't perform error recovery, the REQUEST SENSE command will get aborted, and will not return the sense data that the test case expects.
Since the error recovery will clear PxCI, we also need to move the ahci_port_check_nonbusy() call to before the error handling takes place.
--- tests/qtest/libqos/ahci.c | 44 +++++++++++++++++++++++++++++++++------ tests/qtest/libqos/ahci.h | 3 +-- 2 files changed, 39 insertions(+), 8 deletions(-)
tests/qtest/libqos/ahci.c +38 -6
@@ -425,6 +425,31 @@ void ahci_port_check_error(AHCIQState *ahci, AHCICommand *cmd) reg =ahci_px_rreg (ahci, port,AHCI_PX_SERR ); g_assert_cmphex(reg, ==, 0); +/* If expecting TF error, and TFES was set, perform error recovery +* (see AHCI 1.3 section 6.2.2.1) such that we can send new commands. */ +if (cmd->errors) { +/* This will clear PxCI. */ +ahci_px_clr (ahci, port,AHCI_PX_CMD ,AHCI_PX_CMD_ST ); + +/* The port has 500ms to disengage. */ +usleep (500000 ); + reg =ahci_px_rreg (ahci, port,AHCI_PX_CMD ); +ASSERT_BIT_CLEAR (reg,AHCI_PX_CMD_CR ); + +/* Clear PxIS. */ + reg =ahci_px_rreg (ahci, port,AHCI_PX_IS ); +ahci_px_wreg (ahci, port,AHCI_PX_IS , reg); + +/* Check if we need to perform a COMRESET. +* Not implemented right now, as there is no reason why our QEMU model +* should need a COMRESET when expecting TF error. */ + reg =ahci_px_rreg (ahci, port,AHCI_PX_TFD ); +ASSERT_BIT_CLEAR (reg,AHCI_PX_TFD_STS_BSY |AHCI_PX_TFD_STS_DRQ ); + +/* Enable issuing new commands. */ +ahci_px_set (ahci, port,AHCI_PX_CMD ,AHCI_PX_CMD_ST ); + } +/* The TFD also has two error sections. */ reg =ahci_px_rreg (ahci, port,AHCI_PX_TFD );if (!cmd->errors) {
@@ -436,17 +461,24 @@ void ahci_port_check_error(AHCIQState *ahci, AHCICommand *cmd)ASSERT_BIT_SET (reg,AHCI_PX_TFD_ERR & (cmd->errors <<8 )); } -void ahci_port_check_interrupts (AHCIQState *ahci,uint8_t port, -uint32_t intr_mask) +void ahci_port_check_interrupts (AHCIQState *ahci,AHCICommand *cmd) { +uint8_t port = cmd->port;uint32_t reg; +/* If we expect errors, error handling in ahci_port_check_error() will +* already have cleared PxIS, so in that case this function cannot verify +* and clear expected interrupts. */ +if (cmd->errors) { +return ; + } +/* Check for expected interrupts */ reg =ahci_px_rreg (ahci, port,AHCI_PX_IS ); -ASSERT_BIT_SET (reg, intr_mask); +ASSERT_BIT_SET (reg, cmd->interrupts);/* Clear expected interrupts and assert all interrupts now cleared. */ -ahci_px_wreg (ahci, port,AHCI_PX_IS , intr_mask); +ahci_px_wreg (ahci, port,AHCI_PX_IS , cmd->interrupts); g_assert_cmphex(ahci_px_rreg(ahci, port, AHCI_PX_IS), ==, 0); }
@@ -1248,9 +1280,9 @@ void ahci_command_verify(AHCIQState *ahci, AHCICommand *cmd)uint8_t slot = cmd->slot;uint8_t port = cmd->port; -ahci_port_check_error (ahci, cmd); -ahci_port_check_interrupts (ahci, port, cmd->interrupts);ahci_port_check_nonbusy (ahci, cmd); +ahci_port_check_error (ahci, cmd); +ahci_port_check_interrupts (ahci, cmd);ahci_port_check_cmd_sanity (ahci, cmd);if (cmd->interrupts &AHCI_PX_IS_DHRS ) {ahci_port_check_d2h_sanity (ahci, port, slot);
tests/qtest/libqos/ahci.h +1 -2
@@ -591,8 +591,7 @@ void ahci_destroy_command(AHCIQState *ahci, uint8_t port, uint8_t slot);/* AHCI sanity check routines */ void ahci_port_check_error (AHCIQState *ahci,AHCICommand *cmd); -void ahci_port_check_interrupts (AHCIQState *ahci,uint8_t port, -uint32_t intr_mask); +void ahci_port_check_interrupts (AHCIQState *ahci,AHCICommand *cmd);void ahci_port_check_nonbusy (AHCIQState *ahci,AHCICommand *cmd);void ahci_port_check_d2h_sanity (AHCIQState *ahci,uint8_t port,uint8_t slot);void ahci_port_check_pio_sanity (AHCIQState *ahci,AHCICommand *cmd);
Signature · 1 line
2.40.1
Quoted 9 lines · Niklas Cassel
From: Niklas Cassel <[email protected]>
Hello John,
This series should be applied on top of the series called:
"[PATCH v2 0/8] misc AHCI cleanups"
which can be found here:
https://lists.nongnu.org/archive/html/qemu-block/2023-06/msg00038.html
Quoted 9 lines
This series improves the ahci test suite to be in line with the AHCI specification when it comes to taskfile errors.
Theoretically these commits could be squashed with the corresponding patch for the QEMU model, however, that would lose the commit log for the test patches, so I prefer to keep them separate.
Please review.
We need to squash them, because we can't have any regressions that might appear during git bisect.
Will test and review shortly.
Quoted 19 lines
Kind regards,
NiklasNiklas Cassel (5):
libqos/ahci: fixahci_command_wait()libqos/ahci: fixahci_port_check_nonbusy()libqos/ahci: simplifyahci_port_check_error()libqos/ahci: improveahci_port_check_error()libqos/ahci: perform mandatory error recovery on errortests/qtest/libqos/ahci.c | 106 ++++++++++++++++++++++++++++---------- tests/qtest/libqos/ahci.h | 8 ++- 2 files changed, 83 insertions(+), 31 deletions(-)--
2.40.1