From nobody Tue Apr 23 22:45:09 2024 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) by mx.zohomail.com with SMTPS id 1537949492728988.3892976282183; Wed, 26 Sep 2018 01:11:32 -0700 (PDT) Received: from [127.0.0.1] (helo=ra.coreboot.org) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1g54v0-0004uG-ON; Wed, 26 Sep 2018 10:11:34 +0200 Received: from mga02.intel.com ([134.134.136.20]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_2) (envelope-from ) id 1g54uo-0004u5-8B for seabios@seabios.org; Wed, 26 Sep 2018 10:11:33 +0200 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Sep 2018 01:11:00 -0700 Received: from fedora.sh.intel.com ([10.67.114.176]) by orsmga008.jf.intel.com with ESMTP; 26 Sep 2018 01:10:58 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,305,1534834800"; d="scan'208";a="76285828" From: Changpeng Liu To: seabios@seabios.org Date: Wed, 26 Sep 2018 16:24:29 +0800 Message-Id: <1537950269-25739-1-git-send-email-changpeng.liu@intel.com> X-Mailer: git-send-email 1.9.3 X-Spam-Score: -3.0 (---) Subject: [SeaBIOS] [PATCH] virtio-blk/scsi: enable multi-queues support when starting device 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: , Cc: piotr.zedlewski@intel.com, stefanha@redhat.com, james.r.harris@intel.com 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: RDMRC_1 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" QEMU will not start all the queues since commit fb20fbb76 "vhost: avoid to start/stop virtqueue which is not read", because seabios only use one queue when starting, this will not work for some vhost slave targets which expect the exact number of queues defined in virtio-pci configuration space, while here, we also enable those queues in the BIOS phase. Signed-off-by: Changpeng Liu --- src/hw/virtio-blk.c | 26 +++++++++++++++++++------- src/hw/virtio-ring.h | 1 + src/hw/virtio-scsi.c | 28 +++++++++++++++++++--------- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 88d7e54..79638ec 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -25,7 +25,7 @@ =20 struct virtiodrive_s { struct drive_s drive; - struct vring_virtqueue *vq; + struct vring_virtqueue *vq[MAX_NUM_QUEUES]; struct vp_device vp; }; =20 @@ -34,7 +34,7 @@ virtio_blk_op(struct disk_op_s *op, int write) { struct virtiodrive_s *vdrive =3D container_of(op->drive_fl, struct virtiodrive_s, drive); - struct vring_virtqueue *vq =3D vdrive->vq; + struct vring_virtqueue *vq =3D vdrive->vq[0]; struct virtio_blk_outhdr hdr =3D { .type =3D write ? VIRTIO_BLK_T_OUT : VIRTIO_BLK_T_IN, .ioprio =3D 0, @@ -96,6 +96,7 @@ virtio_blk_process_op(struct disk_op_s *op) static void init_virtio_blk(void *data) { + u32 i, num_queues =3D 1; struct pci_device *pci =3D data; u8 status =3D VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER; dprintf(1, "found virtio-blk at %pP\n", pci); @@ -109,10 +110,6 @@ init_virtio_blk(void *data) vdrive->drive.cntl_id =3D pci->bdf; =20 vp_init_simple(&vdrive->vp, pci); - if (vp_find_vq(&vdrive->vp, 0, &vdrive->vq) < 0 ) { - dprintf(1, "fail to find vq for virtio-blk %pP\n", pci); - goto fail; - } =20 if (vdrive->vp.use_modern) { struct vp_device *vp =3D &vdrive->vp; @@ -156,6 +153,11 @@ init_virtio_blk(void *data) vp_read(&vp->device, struct virtio_blk_config, heads); vdrive->drive.pchs.sector =3D vp_read(&vp->device, struct virtio_blk_config, sectors); + + num_queues =3D vp_read(&vp->common, virtio_pci_common_cfg, num_que= ues); + if (num_queues < 1 || num_queues > MAX_NUM_QUEUES) { + num_queues =3D 1; + } } else { struct virtio_blk_config cfg; vp_get_legacy(&vdrive->vp, 0, &cfg, sizeof(cfg)); @@ -178,6 +180,13 @@ init_virtio_blk(void *data) vdrive->drive.pchs.sector =3D cfg.sectors; } =20 + for (i =3D 0; i < num_queues; i++) { + if (vp_find_vq(&vdrive->vp, i, &vdrive->vq[i]) < 0 ) { + dprintf(1, "fail to find vq %u for virtio-blk %pP\n", i, pci); + goto fail_vq; + } + } + char *desc =3D znprintf(MAXDESCSIZE, "Virtio disk PCI:%pP", pci); boot_add_hd(&vdrive->drive, desc, bootprio_find_pci_device(pci)); =20 @@ -185,9 +194,12 @@ init_virtio_blk(void *data) vp_set_status(&vdrive->vp, status); return; =20 +fail_vq: + for (i =3D 0; i < num_queues; i++) { + free(vdrive->vq[i]); + } fail: vp_reset(&vdrive->vp); - free(vdrive->vq); free(vdrive); } =20 diff --git a/src/hw/virtio-ring.h b/src/hw/virtio-ring.h index 8604a01..3c8a2d1 100644 --- a/src/hw/virtio-ring.h +++ b/src/hw/virtio-ring.h @@ -21,6 +21,7 @@ #define VIRTIO_F_IOMMU_PLATFORM 33 =20 #define MAX_QUEUE_NUM (128) +#define MAX_NUM_QUEUES (128) =20 #define VRING_DESC_F_NEXT 1 #define VRING_DESC_F_WRITE 2 diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index a87cad8..d08643f 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -148,9 +148,10 @@ virtio_scsi_scan_target(struct pci_device *pci, struct= vp_device *vp, static void init_virtio_scsi(void *data) { + u32 i, num_queues =3D 3; struct pci_device *pci =3D data; dprintf(1, "found virtio-scsi at %pP\n", pci); - struct vring_virtqueue *vq =3D NULL; + struct vring_virtqueue *vq[MAX_NUM_QUEUES]; struct vp_device *vp =3D malloc_high(sizeof(*vp)); if (!vp) { warn_noalloc(); @@ -175,29 +176,38 @@ init_virtio_scsi(void *data) dprintf(1, "device didn't accept features: %pP\n", pci); goto fail; } + + num_queues =3D vp_read(&vp->common, virtio_pci_common_cfg, num_queues); + if (num_queues < 3 || num_queues > MAX_NUM_QUEUES) { + num_queues =3D 3; + } } =20 - if (vp_find_vq(vp, 2, &vq) < 0 ) { - dprintf(1, "fail to find vq for virtio-scsi %pP\n", pci); - goto fail; + for (i =3D 0; i < num_queues; i++) { + if (vp_find_vq(vp, i, &vq[i]) < 0 ) { + dprintf(1, "fail to find vq %u for virtio-scsi %pP\n", i, pci); + goto fail; + } } =20 status |=3D VIRTIO_CONFIG_S_DRIVER_OK; vp_set_status(vp, status); =20 - int i, tot; + int tot; for (tot =3D 0, i =3D 0; i < 256; i++) - tot +=3D virtio_scsi_scan_target(pci, vp, vq, i); + tot +=3D virtio_scsi_scan_target(pci, vp, vq[2], i); =20 if (!tot) - goto fail; + goto fail_vq; =20 return; - +fail_vq: + for (i =3D 0; i < num_queues; i++) { + free(vq[i]); + } fail: vp_reset(vp); free(vp); - free(vq); } =20 void --=20 1.9.3 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://mail.coreboot.org/mailman/listinfo/seabios