From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
John Snow <jsnow@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL 22/26] ide: Implement VPD response for ATAPI
Date: Fri, 9 Jan 2015 10:17:02 +0000 [thread overview]
Message-ID: <1420798626-11428-23-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1420798626-11428-1-git-send-email-stefanha@redhat.com>
From: John Snow <jsnow@redhat.com>
SCSI devices have multiple kinds of queries they need to respond
to, as defined in the "cmd inquiry" section in MMC-6 and SPC-3.
Relevent sections:
MMC-6 revision 2g:
Non-VPD response data and pointer to SPC-3;
Section 6.8 "Inquiry Command"
SPC-3 revision 23:
Inquiry command and error handling:
Section 6.4 "INQUIRY command"
VPD data pages format:
Section 7.6 "Vital product data parameters"
We implement these Vital Product Data queries for SCSI, but not for
ATAPI through IDE. The result is that if you are looking for the WWN
identifier via tools such as sg3_utils, you will be unable to query
our CD/DVD rom device to obtain it.
This patch adds the minimum number of mandatory responses as defined
by SPC-3, which include the "supported pages" response (page 0x00)
and the "Device Identification" response (page 0x83). It also correctly
responds when it receives a request for an illegal page to improve
error output from related tools.
The Device ID page contains an arbitrary list of identification
strings of various formats; the ID strings included in this patch
were chosen to mimic those provided by the libata driver when
emulating this SCSI query (model, serial, and wwn when present.)
Example:
# libata emulated response
[root@localhost ~]# sg_inq --id /dev/sda
VPD INQUIRY: Device Identification page
Designation descriptor number 1, descriptor length: 24
designator_type: vendor specific [0x0], code_set: ASCII
associated with the addressed logical unit
vendor specific: QM00001
Designation descriptor number 2, descriptor length: 72
designator_type: T10 vendor identification, code_set: ASCII
associated with the addressed logical unit
vendor id: ATA
vendor specific: QEMU HARDDISK QM00001
# QEMU generated ATAPI response, with WWN
[root@localhost ~]# sg_inq --id /dev/sr0
VPD INQUIRY: Device Identification page
Designation descriptor number 1, descriptor length: 24
designator_type: vendor specific [0x0], code_set: ASCII
associated with the addressed logical unit
vendor specific: QM00005
Designation descriptor number 2, descriptor length: 72
designator_type: T10 vendor identification, code_set: ASCII
associated with the addressed logical unit
vendor id: ATA
vendor specific: QEMU DVD-ROM QM00005
Designation descriptor number 3, descriptor length: 12
designator_type: NAA, code_set: Binary
associated with the addressed logical unit
NAA 5, IEEE Company_id: 0xc50
Vendor Specific Identifier: 0x15ea71bb
[0x5000c50015ea71bb]
See also: hw/scsi/scsi-disk.c, scsi_disk_emulate_inquiry()
Signed-off-by: John Snow <jsnow@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/ide/atapi.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++------
hw/ide/internal.h | 1 +
2 files changed, 100 insertions(+), 12 deletions(-)
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index c63b7e5..a71e6e0 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -621,20 +621,107 @@ static void cmd_request_sense(IDEState *s, uint8_t *buf)
static void cmd_inquiry(IDEState *s, uint8_t *buf)
{
+ uint8_t page_code = buf[2];
int max_len = buf[4];
- buf[0] = 0x05; /* CD-ROM */
- buf[1] = 0x80; /* removable */
- buf[2] = 0x00; /* ISO */
- buf[3] = 0x21; /* ATAPI-2 (XXX: put ATAPI-4 ?) */
- buf[4] = 31; /* additional length */
- buf[5] = 0; /* reserved */
- buf[6] = 0; /* reserved */
- buf[7] = 0; /* reserved */
- padstr8(buf + 8, 8, "QEMU");
- padstr8(buf + 16, 16, "QEMU DVD-ROM");
- padstr8(buf + 32, 4, s->version);
- ide_atapi_cmd_reply(s, 36, max_len);
+ unsigned idx = 0;
+ unsigned size_idx;
+ unsigned preamble_len;
+
+ /* If the EVPD (Enable Vital Product Data) bit is set in byte 1,
+ * we are being asked for a specific page of info indicated by byte 2. */
+ if (buf[1] & 0x01) {
+ preamble_len = 4;
+ size_idx = 3;
+
+ buf[idx++] = 0x05; /* CD-ROM */
+ buf[idx++] = page_code; /* Page Code */
+ buf[idx++] = 0x00; /* reserved */
+ idx++; /* length (set later) */
+
+ switch (page_code) {
+ case 0x00:
+ /* Supported Pages: List of supported VPD responses. */
+ buf[idx++] = 0x00; /* 0x00: Supported Pages, and: */
+ buf[idx++] = 0x83; /* 0x83: Device Identification. */
+ break;
+
+ case 0x83:
+ /* Device Identification. Each entry is optional, but the entries
+ * included here are modeled after libata's VPD responses.
+ * If the response is given, at least one entry must be present. */
+
+ /* Entry 1: Serial */
+ if (idx + 24 > max_len) {
+ /* Not enough room for even the first entry: */
+ /* 4 byte header + 20 byte string */
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
+ ASC_DATA_PHASE_ERROR);
+ return;
+ }
+ buf[idx++] = 0x02; /* Ascii */
+ buf[idx++] = 0x00; /* Vendor Specific */
+ buf[idx++] = 0x00;
+ buf[idx++] = 20; /* Remaining length */
+ padstr8(buf + idx, 20, s->drive_serial_str);
+ idx += 20;
+
+ /* Entry 2: Drive Model and Serial */
+ if (idx + 72 > max_len) {
+ /* 4 (header) + 8 (vendor) + 60 (model & serial) */
+ goto out;
+ }
+ buf[idx++] = 0x02; /* Ascii */
+ buf[idx++] = 0x01; /* T10 Vendor */
+ buf[idx++] = 0x00;
+ buf[idx++] = 68;
+ padstr8(buf + idx, 8, "ATA"); /* Generic T10 vendor */
+ idx += 8;
+ padstr8(buf + idx, 40, s->drive_model_str);
+ idx += 40;
+ padstr8(buf + idx, 20, s->drive_serial_str);
+ idx += 20;
+
+ /* Entry 3: WWN */
+ if (s->wwn && (idx + 12 <= max_len)) {
+ /* 4 byte header + 8 byte wwn */
+ buf[idx++] = 0x01; /* Binary */
+ buf[idx++] = 0x03; /* NAA */
+ buf[idx++] = 0x00;
+ buf[idx++] = 0x08;
+ stq_be_p(&buf[idx], s->wwn);
+ idx += 8;
+ }
+ break;
+
+ default:
+ /* SPC-3, revision 23 sec. 6.4 */
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
+ ASC_INV_FIELD_IN_CMD_PACKET);
+ return;
+ }
+ } else {
+ preamble_len = 5;
+ size_idx = 4;
+
+ buf[0] = 0x05; /* CD-ROM */
+ buf[1] = 0x80; /* removable */
+ buf[2] = 0x00; /* ISO */
+ buf[3] = 0x21; /* ATAPI-2 (XXX: put ATAPI-4 ?) */
+ /* buf[size_idx] set below. */
+ buf[5] = 0; /* reserved */
+ buf[6] = 0; /* reserved */
+ buf[7] = 0; /* reserved */
+ padstr8(buf + 8, 8, "QEMU");
+ padstr8(buf + 16, 16, "QEMU DVD-ROM");
+ padstr8(buf + 32, 4, s->version);
+ idx = 36;
+ }
+
+ out:
+ buf[size_idx] = idx - preamble_len;
+ ide_atapi_cmd_reply(s, idx, max_len);
+ return;
}
static void cmd_get_configuration(IDEState *s, uint8_t *buf)
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 8a3eca4..c998003 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -296,6 +296,7 @@ typedef struct IDEDMAOps IDEDMAOps;
#define ASC_INCOMPATIBLE_FORMAT 0x30
#define ASC_MEDIUM_NOT_PRESENT 0x3a
#define ASC_SAVING_PARAMETERS_NOT_SUPPORTED 0x39
+#define ASC_DATA_PHASE_ERROR 0x4b
#define ASC_MEDIA_REMOVAL_PREVENTED 0x53
#define CFA_NO_ERROR 0x00
--
2.1.0
next prev parent reply other threads:[~2015-01-09 10:18 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-09 10:16 [Qemu-devel] [PULL 00/26] Block patches Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 01/26] libqos: Convert malloc-pc allocator to a generic allocator Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 02/26] libqos: Change use of pointers to uint64_t in virtio Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 03/26] tests: Prepare virtio-blk-test for multi-arch implementation Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 04/26] libqos: Remove PCI assumptions in constants of virtio driver Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 05/26] libqos: Add malloc generic Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 06/26] libqos: Add virtio MMIO support Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 07/26] block/raw-posix.c: Fixes raw_getlength() on Mac OS X so that it reports the correct length of a real CD Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 08/26] .gitignore: Ignore generated "common.env" Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 09/26] qemu-iotests: Replace "/bin/true" with "true" Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 10/26] qemu-iotests: Add "_supported_os Linux" to 058 Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 11/26] tests/Makefile: Add check-block to make check on Linux Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 12/26] qemu-iotests: Add supported os parameter for python tests Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 13/26] coroutine-ucontext: use __thread Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 14/26] qemu-thread: add per-thread atexit functions Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 15/26] test-coroutine: avoid overflow on 32-bit systems Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 16/26] QSLIST: add lock-free operations Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 17/26] coroutine: rewrite pool to avoid mutex Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 18/26] coroutine: drop qemu_coroutine_adjust_pool_size Stefan Hajnoczi
2015-01-09 10:16 ` [Qemu-devel] [PULL 19/26] coroutine: try harder not to delete coroutines Stefan Hajnoczi
2015-01-09 10:17 ` [Qemu-devel] [PULL 20/26] block: limited request size in write zeroes unsupported path Stefan Hajnoczi
2015-01-09 10:17 ` [Qemu-devel] [PULL 21/26] block: Split BLOCK_OP_TYPE_COMMIT to BLOCK_OP_TYPE_COMMIT_{SOURCE, TARGET} Stefan Hajnoczi
2015-01-09 10:17 ` Stefan Hajnoczi [this message]
2015-01-09 10:17 ` [Qemu-devel] [PULL 23/26] nvme: Fix get/set number of queues feature Stefan Hajnoczi
2015-01-09 10:17 ` [Qemu-devel] [PULL 24/26] MAINTAINERS: Update email addresses for Chrysostomos Nanakos Stefan Hajnoczi
2015-01-09 10:17 ` [Qemu-devel] [PULL 25/26] MAINTAINERS: Add migration/block* to block subsystem Stefan Hajnoczi
2015-01-09 10:17 ` [Qemu-devel] [PULL 26/26] NVMe: Set correct VS Value for 1.1 Compliant Controllers Stefan Hajnoczi
2015-01-10 19:05 ` [Qemu-devel] [PULL 00/26] Block patches Peter Maydell
2015-01-10 19:10 ` Peter Maydell
2015-01-12 9:52 ` Fam Zheng
2015-01-12 10:32 ` Paolo Bonzini
2015-01-12 14:25 ` Stefan Hajnoczi
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=1420798626-11428-23-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).