@samitouri / QOSamiQemu / commits / 5e16adf555

tests/qtest/libqos/ahci: allow a count and an expected error

A command that transfers no data can still take an argument in the count register of the register FIS, and a test may well expect such a command to be aborted. AHCICommand is private to the library, so add two setters: ahci_command_set_count() writes the count of a non-data command, and ahci_command_expect_error() records the error register bits the command is expected to complete with, which is what ahci_atapi_test_ready() does inline for a sense key today. INITIALIZE DEVICE PARAMETERS is the first user of both, so describe it in the command properties table as well. Cc: John Snow <jsnow@redhat.com> Cc: Peter Maydell <peter.maydell@linaro.org> Cc: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Signed-off-by: Denis V. Lunev <den@openvz.org>

Denis V. Lunev committed Aug 14, 2026 at 15:35 UTC 5e16adf5550e50e7d792d7a328f4bc0b17a53673
2 files changed +20
tests/qtest/libqos/ahci.c
+14
@@ -74,6 +74,7 @@ AHCICommandProp ahci_command_properties[] = {
74 { .cmd = CMD_READ_MAX, .lba28 = true },
75 { .cmd = CMD_READ_MAX_EXT, .lba48 = true },
76 { .cmd = CMD_FLUSH_CACHE, .data = false },
77 + { .cmd = CMD_INIT_DP, .data = false },
78 { .cmd = CMD_PACKET, .data = true, .size = 16,
79 .atapi = true, .pio = true },
80 { .cmd = CMD_PACKET_ID, .data = true, .pio = true,
@@ -1180,6 +1181,19 @@ void ahci_command_set_prd_size(AHCICommand *cmd, unsigned prd_size)
1181 ahci_command_set_sizes(cmd, cmd->xbytes, prd_size);
1182 }
1183
1184 +/* For a no-data command, whose count carries an argument of its own */
1185 +void ahci_command_set_count(AHCICommand *cmd, uint16_t count)
1186 +{
1187 + g_assert(!cmd->props->data);
1188 + cmd->fis.count = count;
1189 +}
1190 +
1191 +void ahci_command_expect_error(AHCICommand *cmd, uint8_t err)
1192 +{
1193 + cmd->interrupts |= AHCI_PX_IS_TFES;
1194 + cmd->errors |= err;
1195 +}
1196 +
1197 void ahci_command_adjust(AHCICommand *cmd, uint64_t offset, uint64_t buffer,
1198 uint64_t xbytes, unsigned prd_size)
1199 {
tests/qtest/libqos/ahci.h
+6
@@ -278,6 +278,7 @@ enum {
278 CMD_READ_MAX = 0xF8,
279 CMD_READ_MAX_EXT = 0x27,
280 CMD_FLUSH_CACHE = 0xE7,
281 + CMD_INIT_DP = 0x91, /* INITIALIZE DEVICE PARAMETERS */
282 CMD_IDENTIFY = 0xEC,
283 CMD_PACKET = 0xA0,
284 CMD_PACKET_ID = 0xA1,
@@ -324,6 +325,9 @@ enum {
325 #define ATA_DEVICE_DRIVE 0x10
326 #define ATA_DEVICE_HEAD 0x0F
327
328 +/* ATA error register bits */
329 +#define ATA_ERR_ABRT 0x04
330 +
331 /*** Structures ***/
332
333 typedef struct AHCIPortQState {
@@ -638,6 +642,8 @@ void ahci_command_set_size(AHCICommand *cmd, uint64_t xbytes);
642 void ahci_command_set_prd_size(AHCICommand *cmd, unsigned prd_size);
643 void ahci_command_set_sizes(AHCICommand *cmd, uint64_t xbytes,
644 unsigned prd_size);
645 +void ahci_command_set_count(AHCICommand *cmd, uint16_t count);
646 +void ahci_command_expect_error(AHCICommand *cmd, uint8_t err);
647 void ahci_command_set_acmd(AHCICommand *cmd, void *acmd);
648 void ahci_command_enable_atapi_dma(AHCICommand *cmd);
649 void ahci_command_adjust(AHCICommand *cmd, uint64_t lba_sect, uint64_t gbuffer,