From patchwork Mon Jun 6 16:04:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 98961 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 70E0EB6FA1 for ; Tue, 7 Jun 2011 03:22:03 +1000 (EST) Received: from localhost ([::1]:34161 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTdV1-0000lP-4O for incoming@patchwork.ozlabs.org; Mon, 06 Jun 2011 13:21:59 -0400 Received: from eggs.gnu.org ([140.186.70.92]:54826) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTcIo-00062U-Cs for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:05:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QTcIl-0000Q8-TX for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:05:17 -0400 Received: from mail-px0-f174.google.com ([209.85.212.174]:49894) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTcIk-0000F3-Kb for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:05:15 -0400 Received: by mail-px0-f174.google.com with SMTP id 15so947212pxi.33 for ; Mon, 06 Jun 2011 09:05:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:subject:date:message-id:x-mailer :in-reply-to:references; bh=NhpGhe2NFwXT4cZHkWJulo7zXp8bvIDB3fSI8foS/iU=; b=MJGpBad1MH3kx0PDKsR2r8E0kRoZTZvHhA4iwINzm7G2DBSzsK0AYkYpus5JG0PZJn +4T/stxuJqGOKLNvO2WsTUo0Gsg7hJBffhRoTfmouJkjgJNgQd/NsGeb4kLtSuXE7Opg gUB8XjoUIzvmo15H8CaWAV4e4xc/JR/kIFjhc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; b=J4ZQNuojEzwJVGhl1g3YrXkDMZJR+mlplhyKdr0BlO3oX9Pk+M3MgdakQh6SqgP0E6 xxh1ocgYKpTTcNLj44a2xVlwh2eiJxhDxd2UlxOV3vIk9SM0hF1K/6z/GE6HZ4x0Trk/ /h8VoqElxxib6joWZsNpfadW68hMrN0NkStIU= Received: by 10.68.16.106 with SMTP id f10mr1979776pbd.458.1307376313930; Mon, 06 Jun 2011 09:05:13 -0700 (PDT) Received: from localhost.localdomain (93-34-184-88.ip51.fastwebnet.it [93.34.184.88]) by mx.google.com with ESMTPS id c3sm3770633pbk.77.2011.06.06.09.05.11 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 06 Jun 2011 09:05:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 6 Jun 2011 18:04:19 +0200 Message-Id: <1307376262-1255-11-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1307376262-1255-1-git-send-email-pbonzini@redhat.com> References: <1307376262-1255-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.212.174 Subject: [Qemu-devel] [RFC PATCH v2 10/13] scsi: include bus and device levels X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This gives each SCSIBus and SCSIDevice a position on the SCSI hierarchy: - a SCSI_HOST dispatches on the "path" (aka "bus" aka "channel") axis. - a SCSI_PATH dispatches on the target axis. - a SCSI_TARGET dispatches on the LUN axis and handles requests for REPORT LUNS commands, invalid LUNs, and well-known LUNs. It may also have children that are paths, though this is not very much supported by operating systems. - a SCSI_LUN is at the bottom of the hierarchy. This is used in the next patch to create missing layers in the qdev representation. Signed-off-by: Paolo Bonzini --- hw/esp.c | 2 +- hw/lsi53c895a.c | 2 +- hw/scsi-bus.c | 3 ++- hw/scsi-disk.c | 3 +++ hw/scsi-generic.c | 1 + hw/scsi-luns.c | 6 ++++-- hw/scsi.h | 11 ++++++++++- hw/spapr_vscsi.c | 2 +- hw/usb-msd.c | 2 +- 9 files changed, 24 insertions(+), 8 deletions(-) diff --git a/hw/esp.c b/hw/esp.c index a821a0a..0f16dcf 100644 --- a/hw/esp.c +++ b/hw/esp.c @@ -751,7 +751,7 @@ static int esp_init1(SysBusDevice *dev) qdev_init_gpio_in(&dev->qdev, esp_gpio_demux, 2); - scsi_bus_new(&s->bus, &dev->qdev, 0, ESP_MAX_DEVS, &esp_scsi_ops); + scsi_bus_new(&s->bus, &dev->qdev, 0, ESP_MAX_DEVS, SCSI_PATH, &esp_scsi_ops); return scsi_bus_legacy_handle_cmdline(&s->bus); } diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c index a908324..2e5dd42 100644 --- a/hw/lsi53c895a.c +++ b/hw/lsi53c895a.c @@ -2287,7 +2287,7 @@ static int lsi_scsi_init(PCIDevice *dev) PCI_BASE_ADDRESS_SPACE_MEMORY, lsi_ram_mapfunc); QTAILQ_INIT(&s->queue); - scsi_bus_new(&s->bus, &dev->qdev, 1, LSI_MAX_DEVS, &lsi_scsi_ops); + scsi_bus_new(&s->bus, &dev->qdev, 1, LSI_MAX_DEVS, SCSI_PATH, &lsi_scsi_ops); if (!dev->qdev.hotplugged) { return scsi_bus_legacy_handle_cmdline(&s->bus); } diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 54f308d..43a1cd7 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -21,10 +21,11 @@ static int next_scsi_bus; /* Create a scsi bus, and attach devices to it. */ void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev, - const SCSIBusOps *ops) + enum SCSIDeviceLevel level, const SCSIBusOps *ops) { qbus_create_inplace(&bus->qbus, &scsi_bus_info, host, NULL); bus->busnr = next_scsi_bus++; + bus->level = level; bus->tcq = tcq; bus->ndev = ndev; bus->ops = ops; diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index b2c8d6e..0a4fbee 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1263,6 +1263,7 @@ static SCSIDeviceInfo scsi_disk_info[] = { .qdev.fw_name = "disk", .qdev.desc = "virtual SCSI disk", .qdev.size = sizeof(SCSIDiskState), + .level = SCSI_LUN, .reset = scsi_disk_reset, .init = scsi_hd_initfn, .destroy = scsi_destroy, @@ -1284,6 +1285,7 @@ static SCSIDeviceInfo scsi_disk_info[] = { .qdev.fw_name = "disk", .qdev.desc = "virtual SCSI CD-ROM", .qdev.size = sizeof(SCSIDiskState), + .level = SCSI_LUN, .reset = scsi_disk_reset, .init = scsi_cd_initfn, .destroy = scsi_destroy, @@ -1304,6 +1306,7 @@ static SCSIDeviceInfo scsi_disk_info[] = { .qdev.fw_name = "disk", .qdev.desc = "virtual SCSI disk or CD-ROM (legacy)", .qdev.size = sizeof(SCSIDiskState), + .level = SCSI_LUN, .reset = scsi_disk_reset, .init = scsi_disk_initfn, .destroy = scsi_destroy, diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c index 1611023..e1f9d0e 100644 --- a/hw/scsi-generic.c +++ b/hw/scsi-generic.c @@ -561,6 +561,7 @@ static SCSIDeviceInfo scsi_generic_info = { .qdev.name = "scsi-generic", .qdev.desc = "pass through generic scsi device (/dev/sg*)", .qdev.size = sizeof(SCSIGenericState), + .level = SCSI_LUN, .init = scsi_generic_initfn, .destroy = scsi_destroy, .alloc_req = scsi_new_request, diff --git a/hw/scsi-luns.c b/hw/scsi-luns.c index 4b158a9..2cf36f0 100644 --- a/hw/scsi-luns.c +++ b/hw/scsi-luns.c @@ -319,7 +319,7 @@ static struct SCSIBusOps path_scsi_ops = { static int scsi_path_initfn(SCSIDevice *s) { s->children = qemu_mallocz(sizeof(SCSIBus)); - scsi_bus_new(s->children, &s->qdev, 1, MAX_SCSI_DEVS, + scsi_bus_new(s->children, &s->qdev, 1, MAX_SCSI_DEVS, SCSI_PATH, &path_scsi_ops); return 0; } @@ -329,6 +329,7 @@ static SCSIDeviceInfo scsi_path_info = { .qdev.desc = "SCSI initiator device connected to multiple targets", .qdev.size = sizeof(SCSIDevice), .init = scsi_path_initfn, + .level = SCSI_PATH, .qdev.props = (Property[]) { DEFINE_PROP_END_OF_LIST(), }, @@ -352,7 +353,7 @@ static int scsi_target_initfn(SCSIDevice *dev) } s->qdev.children = qemu_mallocz(sizeof(SCSIBus)); - scsi_bus_new(s->qdev.children, &dev->qdev, 1, MAX_SCSI_DEVS, + scsi_bus_new(s->qdev.children, &dev->qdev, 1, MAX_SCSI_DEVS, SCSI_TARGET, &target_scsi_ops); return 0; } @@ -361,6 +362,7 @@ static SCSIDeviceInfo scsi_target_info = { .qdev.name = "scsi-target", .qdev.desc = "SCSI target device connected to multiple logical units", .qdev.size = sizeof(SCSITargetState), + .level = SCSI_TARGET, .init = scsi_target_initfn, .alloc_req = scsi_new_request, .free_req = scsi_free_request, diff --git a/hw/scsi.h b/hw/scsi.h index 9f70771..f4fec61 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -27,6 +27,13 @@ enum SCSILun { LUN_WLUN_MASK = 255 }; +enum SCSIDeviceLevel { + SCSI_HOST = 0, + SCSI_PATH = 1, + SCSI_TARGET = 2, + SCSI_LUN = 3 +}; + typedef struct SCSISense { uint8_t key; uint8_t asc; @@ -73,6 +80,7 @@ int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num); /* scsi-bus.c */ struct SCSIDeviceInfo { DeviceInfo qdev; + enum SCSIDeviceLevel level; int (*init)(SCSIDevice *dev); void (*destroy)(SCSIDevice *s); void (*reset)(SCSIDevice *s); @@ -100,6 +108,7 @@ struct SCSIBus { BusState qbus; int busnr; + enum SCSIDeviceLevel level; int tcq, ndev; const SCSIBusOps *ops; @@ -107,7 +116,7 @@ struct SCSIBus { }; void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev, - const SCSIBusOps *ops); + enum SCSIDeviceLevel level, const SCSIBusOps *ops); void scsi_qdev_register(SCSIDeviceInfo *info); static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d, DeviceState *initiator) diff --git a/hw/spapr_vscsi.c b/hw/spapr_vscsi.c index ace9dac..36dba40 100644 --- a/hw/spapr_vscsi.c +++ b/hw/spapr_vscsi.c @@ -935,7 +935,7 @@ static int spapr_vscsi_init(VIOsPAPRDevice *dev) dev->crq.SendFunc = vscsi_do_crq; - scsi_bus_new(&s->bus, &dev->qdev, 1, VSCSI_REQ_LIMIT, + scsi_bus_new(&s->bus, &dev->qdev, 1, VSCSI_REQ_LIMIT, SCSI_HOST, &vscsi_scsi_ops); if (!dev->qdev.hotplugged) { scsi_bus_legacy_handle_cmdline(&s->bus); diff --git a/hw/usb-msd.c b/hw/usb-msd.c index 195089c..5b34b7b 100644 --- a/hw/usb-msd.c +++ b/hw/usb-msd.c @@ -537,7 +537,7 @@ static int usb_msd_initfn(USBDevice *dev) } usb_desc_init(dev); - scsi_bus_new(&s->bus, &s->dev.qdev, 0, 1, &usb_msd_scsi_ops); + scsi_bus_new(&s->bus, &s->dev.qdev, 0, 1, SCSI_PATH, &usb_msd_scsi_ops); s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable); if (!s->scsi_dev) { return -1;