Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci Set handlers implemented in child device of virt...



details:   https://anonhg.NetBSD.org/src/rev/1c2788e33853
branches:  trunk
changeset: 933347:1c2788e33853
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Mon May 25 07:52:16 2020 +0000

description:
Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function

diffstat:

 sys/dev/pci/if_vioif.c   |  59 +++++++++++++++++++++++++++--------------------
 sys/dev/pci/virtio.c     |  36 +++++++++++++++-------------
 sys/dev/pci/virtio_pci.c |   6 ++--
 sys/dev/pci/virtiovar.h  |   6 +++-
 4 files changed, 60 insertions(+), 47 deletions(-)

diffs (truncated from 340 to 300 lines):

diff -r c5979bea1383 -r 1c2788e33853 sys/dev/pci/if_vioif.c
--- a/sys/dev/pci/if_vioif.c    Mon May 25 07:37:47 2020 +0000
+++ b/sys/dev/pci/if_vioif.c    Mon May 25 07:52:16 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_vioif.c,v 1.53 2020/05/25 07:20:15 yamaguchi Exp $  */
+/*     $NetBSD: if_vioif.c,v 1.54 2020/05/25 07:52:16 yamaguchi Exp $  */
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.53 2020/05/25 07:20:15 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.54 2020/05/25 07:52:16 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -313,13 +313,13 @@
 static void    vioif_populate_rx_mbufs_locked(struct vioif_rxqueue *);
 static int     vioif_rx_deq(struct vioif_rxqueue *);
 static int     vioif_rx_deq_locked(struct vioif_rxqueue *);
-static int     vioif_rx_vq_done(struct virtqueue *);
+static int     vioif_rx_intr(void *);
 static void    vioif_rx_softint(void *);
 static void    vioif_rx_drain(struct vioif_rxqueue *);
 
 /* tx */
-static int     vioif_tx_vq_done(struct virtqueue *);
-static int     vioif_tx_vq_done_locked(struct virtqueue *);
+static int     vioif_tx_intr(void *);
+static int     vioif_tx_deq_locked(struct virtqueue *);
 static void    vioif_tx_drain(struct vioif_txqueue *);
 static void    vioif_deferred_transmit(void *);
 
@@ -331,7 +331,7 @@
 static int     vioif_set_allmulti(struct vioif_softc *, bool);
 static int     vioif_set_rx_filter(struct vioif_softc *);
 static int     vioif_rx_filter(struct vioif_softc *);
-static int     vioif_ctrl_vq_done(struct virtqueue *);
+static int     vioif_ctrl_intr(void *);
 static int     vioif_config_change(struct virtio_softc *);
 static void    vioif_ctl_softint(void *);
 static int     vioif_ctrl_mq_vq_pairs_set(struct vioif_softc *, int);
@@ -701,7 +701,7 @@
        req_features |= VIRTIO_NET_F_MQ;
 #endif
        virtio_child_attach_start(vsc, self, IPL_NET, NULL,
-           vioif_config_change, virtio_vq_intr, req_flags,
+           vioif_config_change, virtio_vq_intrhand, req_flags,
            req_features, VIRTIO_NET_FLAG_BITS);
 
        features = virtio_features(vsc);
@@ -780,8 +780,8 @@
                if (r != 0)
                        goto err;
                nvqs++;
-               rxq->rxq_vq->vq_done = vioif_rx_vq_done;
-               rxq->rxq_vq->vq_done_ctx = (void *)rxq;
+               rxq->rxq_vq->vq_intrhand = vioif_rx_intr;
+               rxq->rxq_vq->vq_intrhand_arg = (void *)rxq;
                rxq->rxq_stopping = true;
 
                txq->txq_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET);
@@ -799,8 +799,8 @@
                if (r != 0)
                        goto err;
                nvqs++;
-               txq->txq_vq->vq_done = vioif_tx_vq_done;
-               txq->txq_vq->vq_done_ctx = (void *)txq;
+               txq->txq_vq->vq_intrhand = vioif_tx_intr;
+               txq->txq_vq->vq_intrhand_arg = (void *)txq;
                txq->txq_link_active = sc->sc_link_active;
                txq->txq_stopping = false;
                txq->txq_intrq = pcq_create(txq->txq_vq->vq_num, KM_SLEEP);
@@ -822,8 +822,8 @@
                        mutex_destroy(&ctrlq->ctrlq_wait_lock);
                } else {
                        nvqs++;
-                       ctrlq->ctrlq_vq->vq_done = vioif_ctrl_vq_done;
-                       ctrlq->ctrlq_vq->vq_done_ctx = (void *) ctrlq;
+                       ctrlq->ctrlq_vq->vq_intrhand = vioif_ctrl_intr;
+                       ctrlq->ctrlq_vq->vq_intrhand_arg = (void *) ctrlq;
                }
        }
 
@@ -1290,11 +1290,10 @@
 
        if (ifp->if_flags & IFF_RUNNING) {
                for (i = 0; i < sc->sc_act_nvq_pairs; i++)
-                       vioif_tx_vq_done(sc->sc_txq[i].txq_vq);
+                       vioif_tx_intr(sc->sc_txq[i].txq_vq);
        }
 }
 
-
 /*
  * Receive implementation
  */
@@ -1426,6 +1425,9 @@
 
        KASSERT(mutex_owned(rxq->rxq_lock));
 
+       if (virtio_vq_is_enqueued(vsc, vq) == false)
+               return r;
+
        while (virtio_dequeue(vsc, vq, &slot, &len) == 0) {
                len -= sizeof(struct virtio_net_hdr);
                r = 1;
@@ -1454,9 +1456,9 @@
 
 /* rx interrupt; call _dequeue above and schedule a softint */
 static int
-vioif_rx_vq_done(struct virtqueue *vq)
+vioif_rx_intr(void *arg)
 {
-       struct vioif_rxqueue *rxq = vq->vq_done_ctx;
+       struct vioif_rxqueue *rxq = arg;
        int r = 0;
 
        mutex_enter(rxq->rxq_lock);
@@ -1496,7 +1498,6 @@
        }
 }
 
-
 /*
  * Transmition implementation
  */
@@ -1507,12 +1508,13 @@
  * tx vq full and watchdog
  */
 static int
-vioif_tx_vq_done(struct virtqueue *vq)
+vioif_tx_intr(void *arg)
 {
+       struct vioif_txqueue *txq = arg;
+       struct virtqueue *vq = txq->txq_vq;
        struct virtio_softc *vsc = vq->vq_owner;
        struct vioif_softc *sc = device_private(virtio_child(vsc));
        struct ifnet *ifp = &sc->sc_ethercom.ec_if;
-       struct vioif_txqueue *txq = vq->vq_done_ctx;
        int r = 0;
 
        mutex_enter(txq->txq_lock);
@@ -1520,7 +1522,7 @@
        if (txq->txq_stopping)
                goto out;
 
-       r = vioif_tx_vq_done_locked(vq);
+       r = vioif_tx_deq_locked(vq);
 
 out:
        mutex_exit(txq->txq_lock);
@@ -1534,11 +1536,11 @@
 }
 
 static int
-vioif_tx_vq_done_locked(struct virtqueue *vq)
+vioif_tx_deq_locked(struct virtqueue *vq)
 {
        struct virtio_softc *vsc = vq->vq_owner;
        struct vioif_softc *sc = device_private(virtio_child(vsc));
-       struct vioif_txqueue *txq = vq->vq_done_ctx;
+       struct vioif_txqueue *txq = vq->vq_intrhand_arg;
        struct ifnet *ifp = &sc->sc_ethercom.ec_if;
        struct mbuf *m;
        int r = 0;
@@ -1546,6 +1548,9 @@
 
        KASSERT(mutex_owned(txq->txq_lock));
 
+       if (virtio_vq_is_enqueued(vsc, vq) == false)
+               return r;
+
        while (virtio_dequeue(vsc, vq, &slot, &len) == 0) {
                r++;
                bus_dmamap_sync(virtio_dmat(vsc), txq->txq_hdr_dmamaps[slot],
@@ -1831,12 +1836,16 @@
 
 /* ctrl vq interrupt; wake up the command issuer */
 static int
-vioif_ctrl_vq_done(struct virtqueue *vq)
+vioif_ctrl_intr(void *arg)
 {
+       struct vioif_ctrlqueue *ctrlq = arg;
+       struct virtqueue *vq = ctrlq->ctrlq_vq;
        struct virtio_softc *vsc = vq->vq_owner;
-       struct vioif_ctrlqueue *ctrlq = vq->vq_done_ctx;
        int r, slot;
 
+       if (virtio_vq_is_enqueued(vsc, vq) == false)
+               return 0;
+
        r = virtio_dequeue(vsc, vq, &slot, NULL);
        if (r == ENOENT)
                return 0;
diff -r c5979bea1383 -r 1c2788e33853 sys/dev/pci/virtio.c
--- a/sys/dev/pci/virtio.c      Mon May 25 07:37:47 2020 +0000
+++ b/sys/dev/pci/virtio.c      Mon May 25 07:52:16 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: virtio.c,v 1.40 2020/05/25 07:37:47 yamaguchi Exp $    */
+/*     $NetBSD: virtio.c,v 1.41 2020/05/25 07:52:16 yamaguchi Exp $    */
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.40 2020/05/25 07:37:47 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.41 2020/05/25 07:52:16 yamaguchi Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -242,11 +242,9 @@
  * Scan vq, bus_dmamap_sync for the vqs (not for the payload),
  * and calls (*vq_done)() if some entries are consumed.
  */
-static int
-virtio_vq_intr_common(struct virtqueue *vq)
+bool
+virtio_vq_is_enqueued(struct virtio_softc *sc, struct virtqueue *vq)
 {
-       struct virtio_softc *sc = vq->vq_owner;
-       int r = 0;
 
        if (vq->vq_queued) {
                vq->vq_queued = 0;
@@ -254,12 +252,8 @@
        }
        vq_sync_uring(sc, vq, BUS_DMASYNC_POSTREAD);
        membar_consumer();
-       if (vq->vq_used_idx != vq->vq_used->idx) {
-               if (vq->vq_done)
-                       r |= (vq->vq_done)(vq);
-       }
 
-       return r;
+       return (vq->vq_used_idx != vq->vq_used->idx) ? 1 : 0;
 }
 
 int
@@ -270,18 +264,27 @@
 
        for (i = 0; i < sc->sc_nvqs; i++) {
                vq = &sc->sc_vqs[i];
-               r |= virtio_vq_intr_common(vq);
+               if (virtio_vq_is_enqueued(sc, vq) == 1) {
+                       if (vq->vq_done)
+                               r |= (vq->vq_done)(vq);
+               }
        }
 
        return r;
 }
 
-static int
-virtio_vq_mq_intr(void *arg)
+int
+virtio_vq_intrhand(struct virtio_softc *sc)
 {
-       struct virtqueue *vq = arg;
+       struct virtqueue *vq;
+       int i, r = 0;
 
-       return virtio_vq_intr_common(vq);
+       for (i = 0; i < sc->sc_nvqs; i++) {
+               vq = &sc->sc_vqs[i];
+               r |= (vq->vq_intrhand)(vq->vq_intrhand_arg);
+       }
+
+       return r;
 }
 
 /*
@@ -428,7 +431,6 @@
 
        /* remember addresses and offsets for later use */
        vq->vq_owner = sc;
-       vq->vq_intrhand = virtio_vq_mq_intr;
        vq->vq_num = vq_size;
        vq->vq_index = index;
        vq->vq_desc = vq->vq_vaddr;
diff -r c5979bea1383 -r 1c2788e33853 sys/dev/pci/virtio_pci.c
--- a/sys/dev/pci/virtio_pci.c  Mon May 25 07:37:47 2020 +0000
+++ b/sys/dev/pci/virtio_pci.c  Mon May 25 07:52:16 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.9 2020/05/25 07:37:47 yamaguchi Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.10 2020/05/25 07:52:16 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.9 2020/05/25 07:37:47 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.10 2020/05/25 07:52:16 yamaguchi Exp $");
 



Home | Main Index | Thread Index | Old Index