From patchwork Fri Aug 4 08:36:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 9880839 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 10342603F4 for ; Fri, 4 Aug 2017 08:40:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 026CE289BB for ; Fri, 4 Aug 2017 08:40:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB252289BE; Fri, 4 Aug 2017 08:40:30 +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 7A941289C0 for ; Fri, 4 Aug 2017 08:40:29 +0000 (UTC) Received: from localhost ([::1]:45735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddY9I-0007Eo-4F for patchwork-qemu-devel@patchwork.kernel.org; Fri, 04 Aug 2017 04:40:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddY68-0005HM-5u for qemu-devel@nongnu.org; Fri, 04 Aug 2017 04:36:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddY63-00067P-LN for qemu-devel@nongnu.org; Fri, 04 Aug 2017 04:36:44 -0400 Received: from mx2.suse.de ([195.135.220.15]:50542 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 1ddY63-00065P-DB for qemu-devel@nongnu.org; Fri, 04 Aug 2017 04:36:39 -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 C793FAC1A; Fri, 4 Aug 2017 08:36:37 +0000 (UTC) From: Hannes Reinecke To: Paolo Bonzini Date: Fri, 4 Aug 2017 10:36:35 +0200 Message-Id: <1501835795-92331-5-git-send-email-hare@suse.de> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1501835795-92331-1-git-send-email-hare@suse.de> References: <1501835795-92331-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] [PATCHv2 4/4] scsi: Add 'enclosure' option for scsi devices 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 Make enclosure support optional with the 'enclosure' argument to the scsi device. Adding 'enclosure=on' as option to the SCSI device will present an enclosure service device on LUN0, either as a stand-alone LUN (in case LUN0 is not assigned) or by setting the EncServ bit int the inquiry data if LUN0 is assigned to a block devices. Signed-off-by: Hannes Reinecke --- hw/scsi/scsi-bus.c | 11 ++++++++--- hw/scsi/scsi-disk.c | 4 +++- include/hw/scsi/scsi.h | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 79a222f..c11422b 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -22,6 +22,7 @@ static Property scsi_props[] = { DEFINE_PROP_UINT32("channel", SCSIDevice, channel, 0), DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1), DEFINE_PROP_UINT32("lun", SCSIDevice, lun, -1), + DEFINE_PROP_BOOL("enclosure", SCSIDevice, enclosure, false), DEFINE_PROP_END_OF_LIST(), }; @@ -494,11 +495,14 @@ static bool scsi_target_emulate_inquiry(SCSITargetReq *r) if (r->req.lun != 0) { r->buf[0] = TYPE_NO_LUN; } else { - r->buf[0] = TYPE_ENCLOSURE; + r->buf[0] = r->req.dev->enclosure ? + TYPE_ENCLOSURE : TYPE_NOT_PRESENT | TYPE_INACTIVE; 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 */ + if (r->req.dev->enclosure) { + 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); @@ -600,7 +604,8 @@ static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf) } break; case RECEIVE_DIAGNOSTIC: - if (!scsi_target_emulate_receive_diagnostic(r)) { + if (!r->req.dev->enclosure || + !scsi_target_emulate_receive_diagnostic(r)) { goto illegal_request; } break; diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 5f1e5e8..153d97d 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -792,7 +792,9 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) the additional length is not adjusted */ outbuf[4] = 36 - 5; } - + if (s->qdev.lun == 0 && s->qdev.enclosure) { + outbuf[6] = 0x40; /* Enclosure service */ + } /* Sync data transfer and TCQ. */ outbuf[7] = 0x10 | (req->bus->info->tcq ? 0x02 : 0); return buflen; diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index 6b85786..243c185 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -100,6 +100,7 @@ struct SCSIDevice BlockConf conf; SCSISense unit_attention; bool sense_is_ua; + bool enclosure; uint8_t sense[SCSI_SENSE_BUF_SIZE]; uint32_t sense_len; QTAILQ_HEAD(, SCSIRequest) requests;