From patchwork Fri Nov 11 18:49:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 9423531 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 53AC360484 for ; Fri, 11 Nov 2016 19:17:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D8D229AEE for ; Fri, 11 Nov 2016 19:17:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 303B829AF2; Fri, 11 Nov 2016 19:17:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C374229AEE for ; Fri, 11 Nov 2016 19:17:17 +0000 (UTC) Received: from localhost ([::1]:54944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c5HK9-0007Zz-4e for patchwork-qemu-devel@patchwork.kernel.org; Fri, 11 Nov 2016 14:17:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39223) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c5Gtp-0004Du-0J for qemu-devel@nongnu.org; Fri, 11 Nov 2016 13:50:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c5Gtn-0003Hr-L2 for qemu-devel@nongnu.org; Fri, 11 Nov 2016 13:50:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44134) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c5Gtn-0003H7-Dx for qemu-devel@nongnu.org; Fri, 11 Nov 2016 13:50:03 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3DC73D97C; Fri, 11 Nov 2016 18:50:02 +0000 (UTC) Received: from scv.usersys.redhat.com (dhcp-17-171.bos.redhat.com [10.18.17.171]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uABInv81030215; Fri, 11 Nov 2016 13:50:02 -0500 From: John Snow To: qemu-devel@nongnu.org Date: Fri, 11 Nov 2016 13:49:54 -0500 Message-Id: <1478890195-30841-9-git-send-email-jsnow@redhat.com> In-Reply-To: <1478890195-30841-1-git-send-email-jsnow@redhat.com> References: <1478890195-30841-1-git-send-email-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 11 Nov 2016 18:50:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 8/9] libqos/ahci: Add get_sense and test_ready X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Required for tray tests once a medium may have changed. Signed-off-by: John Snow Message-id: 1478553214-497-6-git-send-email-jsnow@redhat.com Signed-off-by: John Snow --- 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);