From patchwork Thu Oct 13 11:03:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 119510 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 992ABB6F87 for ; Fri, 14 Oct 2011 00:26:29 +1100 (EST) Received: from localhost ([::1]:49663 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REJ6c-0007vZ-3J for incoming@patchwork.ozlabs.org; Thu, 13 Oct 2011 07:05:42 -0400 Received: from eggs.gnu.org ([140.186.70.92]:55337) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REJ5m-0006Pb-VV for qemu-devel@nongnu.org; Thu, 13 Oct 2011 07:04:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1REJ5k-0004F3-Bg for qemu-devel@nongnu.org; Thu, 13 Oct 2011 07:04:50 -0400 Received: from mail-wy0-f173.google.com ([74.125.82.173]:61406) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REJ5k-00048s-1m for qemu-devel@nongnu.org; Thu, 13 Oct 2011 07:04:48 -0400 Received: by mail-wy0-f173.google.com with SMTP id 22so1888325wyh.4 for ; Thu, 13 Oct 2011 04:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=hIaSm06v7u0cF4+f0fyr6P3q37b29vlO4Zx/1f45sYs=; b=MFUWKgbhxvxv99MrAwpbIKkK3SD4YywNwKuqdfML68wcxhCNp7eamVxWgDL200zGc5 +gzs31/bMw0wDbMhWZeSs+gS/Q50SR3jwFyoeXfySxaOO47GBsfIQU6DZdgnkavu0iPw Zyme3DTMQjXG506rba0Nf4ZeTuqMo+yAackl4= Received: by 10.216.143.222 with SMTP id l72mr1099404wej.46.1318503887654; Thu, 13 Oct 2011 04:04:47 -0700 (PDT) Received: from localhost.localdomain (nat-pool-mxp-t.redhat.com. [209.132.186.18]) by mx.google.com with ESMTPS id g20sm5290288wbp.13.2011.10.13.04.04.46 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Oct 2011 04:04:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 13 Oct 2011 13:03:47 +0200 Message-Id: <1318503845-11473-18-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1318503845-11473-1-git-send-email-pbonzini@redhat.com> References: <1318503845-11473-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 74.125.82.173 Subject: [Qemu-devel] [PATCH 17/35] scsi: allow arbitrary LUNs 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 only requires changes in two places: in SCSIBus, we need to look for a free LUN if somebody creates a device with a pre-existing scsi-id but the default LUN (-1, meaning "search for a free spot"); in vSCSI, we need to actually parse the LUN according to the SCSI spec. Signed-off-by: Paolo Bonzini --- hw/esp.c | 3 ++- hw/lsi53c895a.c | 3 ++- hw/scsi-bus.c | 48 ++++++++++++++++++++++++++++++++---------------- hw/scsi.h | 3 ++- hw/spapr_vscsi.c | 39 +++++++++++++++++++++++++++++++++++---- hw/usb-msd.c | 3 ++- 6 files changed, 75 insertions(+), 24 deletions(-) diff --git a/hw/esp.c b/hw/esp.c index 8e17005..0ebc181 100644 --- a/hw/esp.c +++ b/hw/esp.c @@ -723,7 +723,8 @@ void esp_init(target_phys_addr_t espaddr, int it_shift, static const struct SCSIBusInfo esp_scsi_info = { .tcq = false, - .ndev = ESP_MAX_DEVS, + .max_target = ESP_MAX_DEVS, + .max_lun = 7, .transfer_data = esp_transfer_data, .complete = esp_command_complete, diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c index c15f167..d26e442 100644 --- a/hw/lsi53c895a.c +++ b/hw/lsi53c895a.c @@ -2085,7 +2085,8 @@ static int lsi_scsi_uninit(PCIDevice *d) static const struct SCSIBusInfo lsi_scsi_info = { .tcq = true, - .ndev = LSI_MAX_DEVS, + .max_target = LSI_MAX_DEVS, + .max_lun = 0, /* LUN support is buggy */ .transfer_data = lsi_transfer_data, .complete = lsi_command_complete, diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index a2d57a7..cec06db 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -17,7 +17,7 @@ static struct BusInfo scsi_bus_info = { .get_fw_dev_path = scsibus_get_fw_dev_path, .props = (Property[]) { DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1), - DEFINE_PROP_UINT32("lun", SCSIDevice, lun, 0), + DEFINE_PROP_UINT32("lun", SCSIDevice, lun, -1), DEFINE_PROP_END_OF_LIST(), }, }; @@ -37,26 +37,42 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base) SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev); SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev, base); SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus); - SCSIDevice *olddev; + SCSIDevice *d; int rc = -1; - if (dev->id == -1) { - int id; - for (id = 0; id < bus->info->ndev; id++) { - if (!scsi_device_find(bus, id, 0)) { - dev->id = id; - break; - } - } - } - if (dev->id >= bus->info->ndev) { + if (dev->id != -1 && dev->id > bus->info->max_target) { error_report("bad scsi device id: %d", dev->id); goto err; } - olddev = scsi_device_find(bus, dev->id, dev->lun); - if (olddev && dev->lun == olddev->lun) { - qdev_free(&olddev->qdev); + if (dev->id == -1) { + int id = -1; + if (dev->lun == -1) { + dev->lun = 0; + } + do { + d = scsi_device_find(bus, ++id, dev->lun); + } while (d && d->lun == dev->lun && id <= bus->info->max_target); + if (id > bus->info->max_target) { + error_report("no free target"); + goto err; + } + dev->id = id; + } else if (dev->lun == -1) { + int lun = -1; + do { + d = scsi_device_find(bus, dev->id, ++lun); + } while (d && d->lun == lun && lun < bus->info->max_lun); + if (lun > bus->info->max_lun) { + error_report("no free lun"); + goto err; + } + dev->lun = lun; + } else { + d = scsi_device_find(bus, dev->id, dev->lun); + if (dev->lun == d->lun && dev != d) { + qdev_free(&d->qdev); + } } dev->info = info; @@ -115,7 +131,7 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus) int res = 0, unit; loc_push_none(&loc); - for (unit = 0; unit < bus->info->ndev; unit++) { + for (unit = 0; unit < bus->info->max_target; unit++) { dinfo = drive_get(IF_SCSI, bus->busnr, unit); if (dinfo == NULL) { continue; diff --git a/hw/scsi.h b/hw/scsi.h index add3d2d..401d8d3 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -98,7 +98,8 @@ struct SCSIDeviceInfo { }; struct SCSIBusInfo { - int tcq, ndev; + int tcq; + int max_target, max_lun; void (*transfer_data)(SCSIRequest *req, uint32_t arg); void (*complete)(SCSIRequest *req, uint32_t arg); void (*cancel)(SCSIRequest *req); diff --git a/hw/spapr_vscsi.c b/hw/spapr_vscsi.c index aae845a..334b2e6 100644 --- a/hw/spapr_vscsi.c +++ b/hw/spapr_vscsi.c @@ -131,9 +131,39 @@ static void vscsi_put_req(vscsi_req *req) static SCSIDevice *vscsi_device_find(SCSIBus *bus, uint64_t srp_lun, int *lun) { - /* XXX Figure that one out properly ! This is crackpot */ - int id = (srp_lun >> 56) & 0x7f; - *lun = (srp_lun >> 48) & 0xff; + int channel = 0, id = 0; + +retry: + switch (srp_lun >> 62) { + case 0: + if ((srp_lun >> 56) != 0) { + channel = (srp_lun >> 56) & 0x3f; + id = (srp_lun >> 48) & 0xff; + srp_lun <<= 16; + goto retry; + } + *lun = (srp_lun >> 48) & 0xff; + break; + + case 1: + *lun = (srp_lun >> 48) & 0x3fff; + break; + case 2: + channel = (srp_lun >> 53) & 0x7; + id = (srp_lun >> 56) & 0x3f; + *lun = (srp_lun >> 48) & 0x1f; + break; + case 3: + *lun = -1; + return NULL; + default: + abort(); + } + + if (channel) { + *lun = -1; + return NULL; + } return scsi_device_find (bus, id, *lun); } @@ -862,7 +892,8 @@ static int vscsi_do_crq(struct VIOsPAPRDevice *dev, uint8_t *crq_data) static const struct SCSIBusInfo vscsi_scsi_info = { .tcq = true, - .ndev = 63, /* logical unit addressing format */ + .max_target = 63, /* logical unit addressing format */ + .max_lun = 31, .transfer_data = vscsi_transfer_data, .complete = vscsi_command_complete, diff --git a/hw/usb-msd.c b/hw/usb-msd.c index d0e0cd3..2d88596 100644 --- a/hw/usb-msd.c +++ b/hw/usb-msd.c @@ -494,7 +494,8 @@ static void usb_msd_password_cb(void *opaque, int err) static const struct SCSIBusInfo usb_msd_scsi_info = { .tcq = false, - .ndev = 1, + .max_target = 0, + .max_lun = 0, .transfer_data = usb_msd_transfer_data, .complete = usb_msd_command_complete,