Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev Set virtqueues in virtio_child_attach_finish



details:   https://anonhg.NetBSD.org/src/rev/87573f48deba
branches:  trunk
changeset: 373972:87573f48deba
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Thu Mar 23 03:27:48 2023 +0000

description:
Set virtqueues in virtio_child_attach_finish

The number of virtqueue maybe change in a part of VirtIO devices
(e.g. vioif(4)). And it is fixed after negotiation of features.
So the configuration is moved into the function.

diffstat:

 sys/dev/pci/if_vioif.c   |  32 +++++++++++++++----------
 sys/dev/pci/ld_virtio.c  |  10 ++++----
 sys/dev/pci/vio9p.c      |  17 +++++--------
 sys/dev/pci/viomb.c      |  10 ++++----
 sys/dev/pci/viornd.c     |   9 ++++---
 sys/dev/pci/vioscsi.c    |  11 ++++----
 sys/dev/pci/virtio.c     |  58 ++++++++++++++++++++++-------------------------
 sys/dev/pci/virtio_pci.c |  30 +++++++++++++-----------
 sys/dev/pci/virtiovar.h  |  14 ++++------
 sys/dev/virtio/viocon.c  |  13 ++++-----
 10 files changed, 102 insertions(+), 102 deletions(-)

diffs (truncated from 626 to 300 lines):

diff -r 9645d93420a1 -r 87573f48deba sys/dev/pci/if_vioif.c
--- a/sys/dev/pci/if_vioif.c    Thu Mar 23 03:02:17 2023 +0000
+++ b/sys/dev/pci/if_vioif.c    Thu Mar 23 03:27:48 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_vioif.c,v 1.102 2023/03/23 03:02:17 yamaguchi Exp $ */
+/*     $NetBSD: if_vioif.c,v 1.103 2023/03/23 03:27:48 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.102 2023/03/23 03:02:17 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.103 2023/03/23 03:27:48 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -465,7 +465,7 @@
        u_int softint_flags;
        int r, i, req_flags;
        char xnamebuf[MAXCOMLEN];
-       size_t netq_num;
+       size_t nvqs;
 
        if (virtio_child(vsc) != NULL) {
                aprint_normal(": child already attached for %s; "
@@ -509,11 +509,11 @@
 #ifdef VIOIF_MULTIQ
        req_features |= VIRTIO_NET_F_MQ;
 #endif
-       virtio_child_attach_start(vsc, self, IPL_NET, NULL,
-           vioif_config_change, virtio_vq_intrhand, req_flags,
+
+       virtio_child_attach_start(vsc, self, IPL_NET,
            req_features, VIRTIO_NET_FLAG_BITS);
-
        features = virtio_features(vsc);
+
        if (features == 0)
                goto err;
 
@@ -565,10 +565,12 @@
 
                /* Limit the number of queue pairs to use */
                sc->sc_req_nvq_pairs = MIN(sc->sc_max_nvq_pairs, ncpu);
+
+               if (sc->sc_max_nvq_pairs > 1)
+                       req_flags |= VIRTIO_F_INTR_PERVQ;
        }
 
        vioif_alloc_queues(sc);
-       virtio_child_attach_set_vqs(vsc, sc->sc_vqs, sc->sc_req_nvq_pairs);
 
 #ifdef VIOIF_MPSAFE
        softint_flags = SOFTINT_NET | SOFTINT_MPSAFE;
@@ -579,15 +581,17 @@
        /*
         * Initialize network queues
         */
-       netq_num = sc->sc_max_nvq_pairs * 2;
-       for (i = 0; i < netq_num; i++) {
+       nvqs = sc->sc_max_nvq_pairs * 2;
+       for (i = 0; i < nvqs; i++) {
                r = vioif_netqueue_init(sc, vsc, i, softint_flags);
                if (r != 0)
                        goto err;
        }
 
        if (sc->sc_has_ctrl) {
-               int ctrlq_idx = sc->sc_max_nvq_pairs * 2;
+               int ctrlq_idx = nvqs;
+
+               nvqs++;
                /*
                 * Allocating a virtqueue for control channel
                 */
@@ -618,7 +622,9 @@
        if (vioif_alloc_mems(sc) < 0)
                goto err;
 
-       if (virtio_child_attach_finish(vsc) != 0)
+       r = virtio_child_attach_finish(vsc, sc->sc_vqs, nvqs,
+           vioif_config_change, virtio_vq_intrhand, req_flags);
+       if (r != 0)
                goto err;
 
        if (vioif_setup_sysctl(sc) != 0) {
@@ -656,8 +662,8 @@
        return;
 
 err:
-       netq_num = sc->sc_max_nvq_pairs * 2;
-       for (i = 0; i < netq_num; i++) {
+       nvqs = sc->sc_max_nvq_pairs * 2;
+       for (i = 0; i < nvqs; i++) {
                vioif_netqueue_teardown(sc, vsc, i);
        }
 
diff -r 9645d93420a1 -r 87573f48deba sys/dev/pci/ld_virtio.c
--- a/sys/dev/pci/ld_virtio.c   Thu Mar 23 03:02:17 2023 +0000
+++ b/sys/dev/pci/ld_virtio.c   Thu Mar 23 03:27:48 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ld_virtio.c,v 1.30 2022/04/13 10:42:12 uwe Exp $       */
+/*     $NetBSD: ld_virtio.c,v 1.31 2023/03/23 03:27:48 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.30 2022/04/13 10:42:12 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.31 2023/03/23 03:27:48 yamaguchi Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -275,8 +275,7 @@
        sc->sc_dev = self;
        sc->sc_virtio = vsc;
 
-       virtio_child_attach_start(vsc, self, IPL_BIO, &sc->sc_vq,
-           NULL, virtio_vq_intr, VIRTIO_F_INTR_MSIX,
+       virtio_child_attach_start(vsc, self, IPL_BIO,
            (VIRTIO_BLK_F_SIZE_MAX | VIRTIO_BLK_F_SEG_MAX |
             VIRTIO_BLK_F_GEOMETRY | VIRTIO_BLK_F_RO | VIRTIO_BLK_F_BLK_SIZE |
             VIRTIO_BLK_F_FLUSH | VIRTIO_BLK_F_CONFIG_WCE),
@@ -340,7 +339,8 @@
        qsize = sc->sc_vq.vq_num;
        sc->sc_vq.vq_done = ld_virtio_vq_done;
 
-       if (virtio_child_attach_finish(vsc) != 0)
+       if (virtio_child_attach_finish(vsc, &sc->sc_vq, 1,
+           NULL, virtio_vq_intr, VIRTIO_F_INTR_MSIX) != 0)
                goto err;
 
        ld->sc_dv = self;
diff -r 9645d93420a1 -r 87573f48deba sys/dev/pci/vio9p.c
--- a/sys/dev/pci/vio9p.c       Thu Mar 23 03:02:17 2023 +0000
+++ b/sys/dev/pci/vio9p.c       Thu Mar 23 03:27:48 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vio9p.c,v 1.9 2022/04/20 22:08:10 uwe Exp $    */
+/*     $NetBSD: vio9p.c,v 1.10 2023/03/23 03:27:48 yamaguchi Exp $     */
 
 /*
  * Copyright (c) 2019 Internet Initiative Japan, Inc.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vio9p.c,v 1.9 2022/04/20 22:08:10 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vio9p.c,v 1.10 2023/03/23 03:27:48 yamaguchi Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -500,11 +500,8 @@
        sc->sc_dev = self;
        sc->sc_virtio = vsc;
 
-       virtio_child_attach_start(vsc, self, IPL_VM, sc->sc_vq,
-           NULL, virtio_vq_intr,
-           VIRTIO_F_INTR_MPSAFE | VIRTIO_F_INTR_SOFTINT,
-           VIO9P_F_MOUNT_TAG,
-           VIO9P_FLAG_BITS);
+       virtio_child_attach_start(vsc, self, IPL_VM,
+           VIO9P_F_MOUNT_TAG, VIO9P_FLAG_BITS);
 
        features = virtio_features(vsc);
        if ((features & VIO9P_F_MOUNT_TAG) == 0)
@@ -517,8 +514,6 @@
 
        sc->sc_vq[0].vq_done = vio9p_request_done;
 
-       virtio_child_attach_set_vqs(vsc, sc->sc_vq, 1);
-
        sc->sc_buf_tx = kmem_alloc(VIO9P_MAX_REQLEN, KM_SLEEP);
        sc->sc_buf_rx = kmem_alloc(VIO9P_MAX_REQLEN, KM_SLEEP);
 
@@ -559,7 +554,9 @@
        vio9p_read_config(sc);
        aprint_normal_dev(self, "tagged as %s\n", sc->sc_tag);
 
-       error = virtio_child_attach_finish(vsc);
+       error = virtio_child_attach_finish(vsc, sc->sc_vq,
+           __arraycount(sc->sc_vq), NULL, virtio_vq_intr,
+           VIRTIO_F_INTR_MPSAFE | VIRTIO_F_INTR_SOFTINT);
        if (error != 0)
                goto err_mutex;
 
diff -r 9645d93420a1 -r 87573f48deba sys/dev/pci/viomb.c
--- a/sys/dev/pci/viomb.c       Thu Mar 23 03:02:17 2023 +0000
+++ b/sys/dev/pci/viomb.c       Thu Mar 23 03:27:48 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: viomb.c,v 1.13 2022/04/13 10:42:12 uwe Exp $   */
+/*     $NetBSD: viomb.c,v 1.14 2023/03/23 03:27:48 yamaguchi Exp $     */
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: viomb.c,v 1.13 2022/04/13 10:42:12 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: viomb.c,v 1.14 2023/03/23 03:27:48 yamaguchi Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -148,8 +148,7 @@
        sc->sc_dev = self;
        sc->sc_virtio = vsc;
 
-       virtio_child_attach_start(vsc, self, IPL_VM, sc->sc_vq,
-           viomb_config_change, virtio_vq_intr, 0,
+       virtio_child_attach_start(vsc, self, IPL_VM,
            VIRTIO_BALLOON_F_MUST_TELL_HOST, VIRTIO_BALLOON_FLAG_BITS);
 
        features = virtio_features(vsc);
@@ -190,7 +189,8 @@
                goto err_dmamap;
        }
 
-       if (virtio_child_attach_finish(vsc) != 0)
+       if (virtio_child_attach_finish(vsc, sc->sc_vq, __arraycount(sc->sc_vq),
+           viomb_config_change, virtio_vq_intr, 0) != 0)
                goto err_out;
 
        if (kthread_create(PRI_IDLE, KTHREAD_MPSAFE, NULL,
diff -r 9645d93420a1 -r 87573f48deba sys/dev/pci/viornd.c
--- a/sys/dev/pci/viornd.c      Thu Mar 23 03:02:17 2023 +0000
+++ b/sys/dev/pci/viornd.c      Thu Mar 23 03:27:48 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: viornd.c,v 1.18 2022/04/14 19:47:14 riastradh Exp $ */
+/*     $NetBSD: viornd.c,v 1.19 2023/03/23 03:27:48 yamaguchi Exp $ */
 /*     $OpenBSD: viornd.c,v 1.1 2014/01/21 21:14:58 sf Exp $   */
 
 /*
@@ -176,8 +176,7 @@
                goto load_failed;
        }
 
-       virtio_child_attach_start(vsc, self, IPL_NET, &sc->sc_vq,
-           NULL, virtio_vq_intr, 0,
+       virtio_child_attach_start(vsc, self, IPL_NET,
            0, VIRTIO_COMMON_FLAG_BITS);
 
        error = virtio_alloc_vq(vsc, &sc->sc_vq, 0, VIORND_BUFSIZE, 1,
@@ -189,7 +188,9 @@
        }
        sc->sc_vq.vq_done = viornd_vq_done;
 
-       if (virtio_child_attach_finish(vsc) != 0) {
+       error = virtio_child_attach_finish(vsc, &sc->sc_vq, 1,
+           NULL, virtio_vq_intr, 0);
+       if (error) {
                virtio_free_vq(vsc, &sc->sc_vq);
                goto vio_failed;
        }
diff -r 9645d93420a1 -r 87573f48deba sys/dev/pci/vioscsi.c
--- a/sys/dev/pci/vioscsi.c     Thu Mar 23 03:02:17 2023 +0000
+++ b/sys/dev/pci/vioscsi.c     Thu Mar 23 03:27:48 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vioscsi.c,v 1.30 2022/10/11 22:03:37 andvar Exp $      */
+/*     $NetBSD: vioscsi.c,v 1.31 2023/03/23 03:27:48 yamaguchi Exp $   */
 /*     $OpenBSD: vioscsi.c,v 1.3 2015/03/14 03:38:49 jsg Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vioscsi.c,v 1.30 2022/10/11 22:03:37 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vioscsi.c,v 1.31 2023/03/23 03:27:48 yamaguchi Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -128,8 +128,7 @@
 
        sc->sc_dev = self;
 
-       virtio_child_attach_start(vsc, self, ipl, sc->sc_vqs,
-           NULL, virtio_vq_intr, VIRTIO_F_INTR_MSIX,
+       virtio_child_attach_start(vsc, self, ipl,
            0, VIRTIO_COMMON_FLAG_BITS);
 
        mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, ipl);
@@ -171,7 +170,9 @@
            " max_lun %u\n",
            cmd_per_lun, qsize, seg_max, max_target, max_lun);
 
-       if (virtio_child_attach_finish(vsc) != 0)
+       if (virtio_child_attach_finish(vsc, sc->sc_vqs,
+           __arraycount(sc->sc_vqs), NULL, virtio_vq_intr,
+           VIRTIO_F_INTR_MSIX) != 0)
                goto err;
 
        /*
diff -r 9645d93420a1 -r 87573f48deba sys/dev/pci/virtio.c
--- a/sys/dev/pci/virtio.c      Thu Mar 23 03:02:17 2023 +0000
+++ b/sys/dev/pci/virtio.c      Thu Mar 23 03:27:48 2023 +0000
@@ -1,4 +1,4 @@



Home | Main Index | Thread Index | Old Index