From nobody Sat May 10 07:49:12 2025 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) client-ip=80.81.252.135; envelope-from=seabios-bounces@seabios.org; helo=mail.coreboot.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; Return-Path: Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) by mx.zohomail.com with SMTPS id 14978893075597.539738773821227; Mon, 19 Jun 2017 09:21:47 -0700 (PDT) Received: from [127.0.0.1] (helo=ra.coresystems.de) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1dMzPd-0003cN-4L; Mon, 19 Jun 2017 18:20:25 +0200 Received: from mx1.redhat.com ([209.132.183.28]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_2) (envelope-from ) id 1dMzPP-0003ad-K9 for seabios@seabios.org; Mon, 19 Jun 2017 18:20:23 +0200 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C0BCB80C15; Mon, 19 Jun 2017 16:21:14 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-163.ams2.redhat.com [10.36.117.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AE1F17C36; Mon, 19 Jun 2017 16:21:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C0BCB80C15 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C0BCB80C15 From: Paolo Bonzini To: seabios@seabios.org Date: Mon, 19 Jun 2017 18:21:10 +0200 Message-Id: <20170619162110.28156-3-pbonzini@redhat.com> In-Reply-To: <20170619162110.28156-1-pbonzini@redhat.com> References: <20170619162110.28156-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 19 Jun 2017 16:21:14 +0000 (UTC) X-Spam-Score: -6.5 (------) Subject: [SeaBIOS] [PATCH 2/2] virtio-scsi: speed up SCSI bus scan X-BeenThere: seabios@seabios.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SeaBIOS mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: seabios-bounces@seabios.org Sender: "SeaBIOS" X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The introduction of REPORT LUNS caused virtio-scsi to send two SCSI commands (INQUIRY and REPORT LUNS) to each target rather than just one. However, INQUIRY will only fail if _no_ LUN is present on that target. If all devices have LUN>0 is present, INQUIRY will report a dummy device. Therefore, the LUN0 scan can be used to prepare a compact bitmap of targets that we have to scan, and omit sending REPORT LUNS to the others. Signed-off-by: Paolo Bonzini --- src/hw/blockcmd.c | 2 ++ src/hw/virtio-scsi.c | 45 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index af9cd4d..32d8d68 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -276,6 +276,8 @@ int scsi_sequential_scan(struct drive_s *tmp_drive, u32= maxluns, } =20 // Validate drive, find block size / sector count, and register drive. +// Return positive value if disk error, 0 if success, negative if +// not a disk or the disk parameters are invalid. int scsi_drive_setup(struct drive_s *drive, const char *s, int prio) { diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index 3e8f13e..ad09701 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -130,22 +130,40 @@ virtio_scsi_add_lun(u32 lun, struct drive_s *tmpl_drv) =20 fail: free(vlun); - return -1; + return ret; } =20 static int virtio_scsi_scan_target(struct pci_device *pci, struct vp_device *vp, - struct vring_virtqueue *vq, u16 target, u8 report_= luns) + struct vring_virtqueue *vq, u16 target, u32 *targe= ts, + u8 report_luns) { =20 struct virtio_lun_s vlun0; =20 virtio_scsi_init_lun(&vlun0, pci, vp, vq, target, 0); - if (!report_luns) - return !virtio_scsi_add_lun(0, &vlun0.drive); - - int ret =3D scsi_rep_luns_scan(&vlun0.drive, virtio_scsi_add_lun); - return ret < 0 ? 0 : ret; + dprintf(3, "scanning target %d, pass %d\n", target, report_luns); + if (!report_luns) { + int ret =3D virtio_scsi_add_lun(0, &vlun0.drive); + if (ret > 0) { + /* Target error */ + return 0; + } + /* Found a SCSI device (maybe not a disk if ret < 0). Search high= er + * LUNs in the second pass. + */ + dprintf(1, "will scan target %d\n", target); + targets[target >> 5] |=3D 1 << (target & 31); + return !ret; + } else { + int ret =3D 0; + if (targets[target >> 5] & (1 << (target & 31))) { + ret =3D scsi_rep_luns_scan(&vlun0.drive, virtio_scsi_add_lun); + if (ret < 0) + ret =3D 0; + } + return ret; + } } =20 static void @@ -188,11 +206,18 @@ init_virtio_scsi(void *data) vp_set_status(vp, status); =20 int tot =3D 0; + u32 targets[256 / 32]; int i; + memset(targets, 0, sizeof(targets)); for (i =3D 0; i < 256; i++) - tot +=3D virtio_scsi_scan_target(pci, vp, vq, i, 0); - for (i =3D 0; i < 256; i++) - tot +=3D virtio_scsi_scan_target(pci, vp, vq, i, 1); + tot +=3D virtio_scsi_scan_target(pci, vp, vq, i, targets, 0); + for (i =3D 0; i < 256; i++) { + if (!targets[i >> 5]) { + i |=3D 31; + continue; + } + tot +=3D virtio_scsi_scan_target(pci, vp, vq, i, targets, 1); + } =20 if (!tot) goto fail; --=20 2.13.0 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://mail.coreboot.org/mailman/listinfo/seabios