All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, jsnow@redhat.com
Subject: [Qemu-devel] [PULL 8/9] libqos/ahci: Add get_sense and test_ready
Date: Fri, 11 Nov 2016 13:49:54 -0500	[thread overview]
Message-ID: <1478890195-30841-9-git-send-email-jsnow@redhat.com> (raw)
In-Reply-To: <1478890195-30841-1-git-send-email-jsnow@redhat.com>

Required for tray tests once a medium may have changed.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 1478553214-497-6-git-send-email-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
---
 tests/libqos/ahci.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/libqos/ahci.h | 16 ++++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/tests/libqos/ahci.c b/tests/libqos/ahci.c
index 603ecb6..924c6a8 100644
--- a/tests/libqos/ahci.c
+++ b/tests/libqos/ahci.c
@@ -882,6 +882,49 @@ AHCICommand *ahci_atapi_command_create(uint8_t scsi_cmd, uint16_t bcl)
     return cmd;
 }
 
+void ahci_atapi_test_ready(AHCIQState *ahci, uint8_t port,
+                           bool ready, uint8_t expected_sense)
+{
+    AHCICommand *cmd = ahci_atapi_command_create(CMD_ATAPI_TEST_UNIT_READY, 0);
+    ahci_command_set_size(cmd, 0);
+    if (!ready) {
+        cmd->interrupts |= AHCI_PX_IS_TFES;
+        cmd->errors |= expected_sense << 4;
+    }
+    ahci_command_commit(ahci, cmd, port);
+    ahci_command_issue(ahci, cmd);
+    ahci_command_verify(ahci, cmd);
+    ahci_command_free(cmd);
+}
+
+static int copy_buffer(AHCIQState *ahci, AHCICommand *cmd,
+                        const AHCIOpts *opts)
+{
+    unsigned char *rx = opts->opaque;
+    bufread(opts->buffer, rx, opts->size);
+    return 0;
+}
+
+void ahci_atapi_get_sense(AHCIQState *ahci, uint8_t port,
+                          uint8_t *sense, uint8_t *asc)
+{
+    unsigned char *rx;
+    AHCIOpts opts = {
+        .size = 18,
+        .atapi = true,
+        .post_cb = copy_buffer,
+    };
+    rx = g_malloc(18);
+    opts.opaque = rx;
+
+    ahci_exec(ahci, port, CMD_ATAPI_REQUEST_SENSE, &opts);
+
+    *sense = rx[2];
+    *asc = rx[12];
+
+    g_free(rx);
+}
+
 void ahci_atapi_eject(AHCIQState *ahci, uint8_t port)
 {
     AHCICommand *cmd = ahci_atapi_command_create(CMD_ATAPI_START_STOP_UNIT, 0);
@@ -934,6 +977,8 @@ static void ahci_atapi_command_set_offset(AHCICommand *cmd, uint64_t lba)
         g_assert_cmpuint(lba, <=, UINT32_MAX);
         stl_be_p(&cbd[2], lba);
         break;
+    case CMD_ATAPI_REQUEST_SENSE:
+    case CMD_ATAPI_TEST_UNIT_READY:
     case CMD_ATAPI_START_STOP_UNIT:
         g_assert_cmpuint(lba, ==, 0x00);
         break;
@@ -1003,6 +1048,11 @@ static void ahci_atapi_set_size(AHCICommand *cmd, uint64_t xbytes)
         cbd[7] = (tmp & 0xFF00) >> 8;
         cbd[8] = (tmp & 0xFF);
         break;
+    case CMD_ATAPI_REQUEST_SENSE:
+        g_assert_cmpuint(xbytes, <=, UINT8_MAX);
+        cbd[4] = (uint8_t)xbytes;
+        break;
+    case CMD_ATAPI_TEST_UNIT_READY:
     case CMD_ATAPI_START_STOP_UNIT:
         g_assert_cmpuint(xbytes, ==, 0);
         break;
diff --git a/tests/libqos/ahci.h b/tests/libqos/ahci.h
index 05ce3de..ca83afc 100644
--- a/tests/libqos/ahci.h
+++ b/tests/libqos/ahci.h
@@ -287,11 +287,24 @@ enum {
 
 /* ATAPI Commands */
 enum {
+    CMD_ATAPI_TEST_UNIT_READY = 0x00,
+    CMD_ATAPI_REQUEST_SENSE   = 0x03,
     CMD_ATAPI_START_STOP_UNIT = 0x1b,
     CMD_ATAPI_READ_10         = 0x28,
     CMD_ATAPI_READ_CD         = 0xbe,
 };
 
+enum {
+    SENSE_NO_SENSE       = 0x00,
+    SENSE_NOT_READY      = 0x02,
+    SENSE_UNIT_ATTENTION = 0x06,
+};
+
+enum {
+    ASC_MEDIUM_MAY_HAVE_CHANGED = 0x28,
+    ASC_MEDIUM_NOT_PRESENT      = 0x3a,
+};
+
 /* AHCI Command Header Flags & Masks*/
 #define CMDH_CFL        (0x1F)
 #define CMDH_ATAPI      (0x20)
@@ -601,6 +614,9 @@ void ahci_io(AHCIQState *ahci, uint8_t port, uint8_t ide_cmd,
              void *buffer, size_t bufsize, uint64_t sector);
 void ahci_exec(AHCIQState *ahci, uint8_t port,
                uint8_t op, const AHCIOpts *opts);
+void ahci_atapi_test_ready(AHCIQState *ahci, uint8_t port, bool ready, uint8_t expected_sense);
+void ahci_atapi_get_sense(AHCIQState *ahci, uint8_t port,
+                          uint8_t *sense, uint8_t *asc);
 void ahci_atapi_eject(AHCIQState *ahci, uint8_t port);
 void ahci_atapi_load(AHCIQState *ahci, uint8_t port);
 
-- 
2.7.4

  parent reply	other threads:[~2016-11-11 18:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-11 18:49 [Qemu-devel] [PULL 0/9] Ide patches John Snow
2016-11-11 18:49 ` [Qemu-devel] [PULL 1/9] atapi: classify read_cd as conditionally returning data John Snow
2016-11-11 18:49 ` [Qemu-devel] [PULL 2/9] ahci-test: Create smaller test ISO images John Snow
2016-11-11 18:49 ` [Qemu-devel] [PULL 3/9] ahci-test: test atapi read_cd with bcl, nb_sectors = 0 John Snow
2016-11-11 18:49 ` [Qemu-devel] [PULL 4/9] block-backend: Always notify on blk_eject John Snow
2016-11-11 18:49 ` [Qemu-devel] [PULL 5/9] libqtest: add qmp_eventwait_ref John Snow
2016-11-11 18:49 ` [Qemu-devel] [PULL 6/9] libqos/ahci: Support expected errors John Snow
2016-11-11 18:49 ` [Qemu-devel] [PULL 7/9] libqos/ahci: Add ATAPI tray macros John Snow
2016-11-11 18:49 ` John Snow [this message]
2016-11-11 18:49 ` [Qemu-devel] [PULL 9/9] ahci-test: add QMP tray test for ATAPI John Snow
2016-11-13  3:32 ` [Qemu-devel] [PULL 0/9] Ide patches no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1478890195-30841-9-git-send-email-jsnow@redhat.com \
    --to=jsnow@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.