From patchwork Thu Aug 3 13:27:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 9879109 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 0B10C603B4 for ; Thu, 3 Aug 2017 13:28:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2AFB288EC for ; Thu, 3 Aug 2017 13:28:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7871288F9; Thu, 3 Aug 2017 13:28:15 +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 541A8288EC for ; Thu, 3 Aug 2017 13:28:15 +0000 (UTC) Received: from localhost ([::1]:42678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddGAg-0006NS-GD for patchwork-qemu-devel@patchwork.kernel.org; Thu, 03 Aug 2017 09:28:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddG9e-0006L3-EO for qemu-devel@nongnu.org; Thu, 03 Aug 2017 09:27:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddG9a-0007CK-KS for qemu-devel@nongnu.org; Thu, 03 Aug 2017 09:27:10 -0400 Received: from mx2.suse.de ([195.135.220.15]:47245 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddG9a-00075H-Ca for qemu-devel@nongnu.org; Thu, 03 Aug 2017 09:27:06 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 97580AF15; Thu, 3 Aug 2017 13:27:03 +0000 (UTC) From: Hannes Reinecke To: Paolo Bonzini Date: Thu, 3 Aug 2017 15:27:00 +0200 Message-Id: <1501766821-76419-2-git-send-email-hare@suse.de> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1501766821-76419-1-git-send-email-hare@suse.de> References: <1501766821-76419-1-git-send-email-hare@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 195.135.220.15 Subject: [Qemu-devel] [PATCH 1/2] scsi: Make LUN 0 a simple enclosure 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: Hannes Reinecke , qemu-devel@nongnu.org, Hannes Reinecke Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of having an 'invisible' LUN0 (in case LUN 0 is not connected) this patch maks LUN0 a enclosure service, exposing it to the OS. Signed-off-by: Hannes Reinecke --- hw/scsi/scsi-bus.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 23c51de..c89e82d 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -493,10 +493,11 @@ static bool scsi_target_emulate_inquiry(SCSITargetReq *r) if (r->req.lun != 0) { r->buf[0] = TYPE_NO_LUN; } else { - r->buf[0] = TYPE_NOT_PRESENT | TYPE_INACTIVE; + r->buf[0] = TYPE_ENCLOSURE; r->buf[2] = 5; /* Version */ r->buf[3] = 2 | 0x10; /* HiSup, response data format */ r->buf[4] = r->len - 5; /* Additional Length = (Len - 1) - 4 */ + r->buf[6] = 0x40; /* Enclosure service */ r->buf[7] = 0x10 | (r->req.bus->info->tcq ? 0x02 : 0); /* Sync, TCQ. */ memcpy(&r->buf[8], "QEMU ", 8); memcpy(&r->buf[16], "QEMU TARGET ", 16); @@ -505,6 +506,54 @@ static bool scsi_target_emulate_inquiry(SCSITargetReq *r) return true; } +static bool scsi_target_emulate_receive_diagnostic(SCSITargetReq *r) +{ + uint8_t page_code = r->req.cmd.buf[2]; + unsigned char *enc_desc, *type_desc; + + assert(r->req.dev->lun != r->req.lun); + + scsi_target_alloc_buf(&r->req, 0x38); + + switch (page_code) { + case 0x00: + r->buf[r->len++] = page_code ; /* this page */ + r->buf[r->len++] = 0x00; + r->buf[r->len++] = 0x00; + r->buf[r->len++] = 0x03; + r->buf[r->len++] = 0x00; + r->buf[r->len++] = 0x01; + r->buf[r->len++] = 0x08; + break; + case 0x01: + memset(r->buf, 0, 0x38); + r->buf[0] = page_code; + r->buf[3] = 0x30; + enc_desc = &r->buf[8]; + enc_desc[0] = 0x09; + enc_desc[2] = 1; + enc_desc[3] = 0x24; + memcpy(&enc_desc[12], "QEMU ", 8); + memcpy(&enc_desc[20], "QEMU TARGET ", 16); + pstrcpy((char *)&enc_desc[36], 4, qemu_hw_version()); + type_desc = &r->buf[48]; + type_desc[1] = 1; + r->len = 0x38; + break; + case 0x08: + r->buf[0] = page_code; + r->buf[1] = 0x00; + r->buf[2] = 0x00; + r->buf[3] = 0x00; + r->len = 4; + break; + default: + return false; + } + r->len = MIN(r->req.cmd.xfer, r->len); + return true; +} + static size_t scsi_sense_len(SCSIRequest *req) { if (req->dev->type == TYPE_SCANNER) @@ -528,6 +577,11 @@ static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf) goto illegal_request; } break; + case RECEIVE_DIAGNOSTIC: + if (!scsi_target_emulate_receive_diagnostic(r)) { + goto illegal_request; + } + break; case REQUEST_SENSE: scsi_target_alloc_buf(&r->req, scsi_sense_len(req)); r->len = scsi_device_get_sense(r->req.dev, r->buf,