Module Name: src
Committed By: yamaguchi
Date: Mon May 25 07:52:16 UTC 2020
Modified Files:
src/sys/dev/pci: if_vioif.c virtio.c virtio_pci.c virtiovar.h
Log Message:
Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function
To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/dev/pci/if_vioif.c
cvs rdiff -u -r1.40 -r1.41 src/sys/dev/pci/virtio.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/pci/virtio_pci.c
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/pci/virtiovar.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/pci/if_vioif.c
diff -u src/sys/dev/pci/if_vioif.c:1.53 src/sys/dev/pci/if_vioif.c:1.54
--- src/sys/dev/pci/if_vioif.c:1.53 Mon May 25 07:20:15 2020
+++ src/sys/dev/pci/if_vioif.c Mon May 25 07:52:16 2020
@@ -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(stru
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_promisc(struct vioi
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 @@ vioif_attach(device_t parent, device_t s
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 @@ vioif_attach(device_t parent, device_t s
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 @@ vioif_attach(device_t parent, device_t s
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 @@ vioif_attach(device_t parent, device_t s
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 @@ vioif_watchdog(struct ifnet *ifp)
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 @@ vioif_rx_deq_locked(struct vioif_rxqueue
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 @@ vioif_rx_deq_locked(struct vioif_rxqueue
/* 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 @@ vioif_rx_drain(struct vioif_rxqueue *rxq
}
}
-
/*
* Transmition implementation
*/
@@ -1507,12 +1508,13 @@ vioif_rx_drain(struct vioif_rxqueue *rxq
* 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 @@ vioif_tx_vq_done(struct virtqueue *vq)
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 @@ out:
}
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 @@ vioif_tx_vq_done_locked(struct virtqueue
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 @@ vioif_ctrl_mq_vq_pairs_set(struct vioif_
/* 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;
Index: src/sys/dev/pci/virtio.c
diff -u src/sys/dev/pci/virtio.c:1.40 src/sys/dev/pci/virtio.c:1.41
--- src/sys/dev/pci/virtio.c:1.40 Mon May 25 07:37:47 2020
+++ src/sys/dev/pci/virtio.c Mon May 25 07:52:16 2020
@@ -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 @@ vq_sync_indirect(struct virtio_softc *sc
* 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 @@ virtio_vq_intr_common(struct virtqueue *
}
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 @@ virtio_vq_intr(struct virtio_softc *sc)
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;
+
+ for (i = 0; i < sc->sc_nvqs; i++) {
+ vq = &sc->sc_vqs[i];
+ r |= (vq->vq_intrhand)(vq->vq_intrhand_arg);
+ }
- return virtio_vq_intr_common(vq);
+ return r;
}
/*
@@ -428,7 +431,6 @@ virtio_alloc_vq(struct virtio_softc *sc,
/* 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;
Index: src/sys/dev/pci/virtio_pci.c
diff -u src/sys/dev/pci/virtio_pci.c:1.9 src/sys/dev/pci/virtio_pci.c:1.10
--- src/sys/dev/pci/virtio_pci.c:1.9 Mon May 25 07:37:47 2020
+++ src/sys/dev/pci/virtio_pci.c Mon May 25 07:52:16 2020
@@ -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 $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -545,7 +545,7 @@ virtio_pci_setup_msix_interrupts(struct
}
psc->sc_ihs[n] = pci_intr_establish_xname(pc, psc->sc_ihp[n],
- sc->sc_ipl, vq->vq_intrhand, vq, intr_xname);
+ sc->sc_ipl, vq->vq_intrhand, vq->vq_intrhand_arg, intr_xname);
if (psc->sc_ihs[n] == NULL) {
aprint_error_dev(self, "couldn't establish MSI-X for a vq\n");
goto error;
Index: src/sys/dev/pci/virtiovar.h
diff -u src/sys/dev/pci/virtiovar.h:1.15 src/sys/dev/pci/virtiovar.h:1.16
--- src/sys/dev/pci/virtiovar.h:1.15 Mon May 25 07:37:47 2020
+++ src/sys/dev/pci/virtiovar.h Mon May 25 07:52:16 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: virtiovar.h,v 1.15 2020/05/25 07:37:47 yamaguchi Exp $ */
+/* $NetBSD: virtiovar.h,v 1.16 2020/05/25 07:52:16 yamaguchi Exp $ */
/*
* Copyright (c) 2010 Minoura Makoto.
@@ -116,8 +116,8 @@ struct virtqueue {
/* interrupt handler */
int (*vq_done)(struct virtqueue*);
- void *vq_done_ctx;
int (*vq_intrhand)(void *);
+ void *vq_intrhand_arg;
};
struct virtio_attach_args {
@@ -217,7 +217,9 @@ int virtio_enqueue_abort(struct virtio_s
int virtio_dequeue(struct virtio_softc*, struct virtqueue*, int *, int *);
int virtio_dequeue_commit(struct virtio_softc*, struct virtqueue*, int);
+bool virtio_vq_is_enqueued(struct virtio_softc *, struct virtqueue *);
int virtio_vq_intr(struct virtio_softc *);
+int virtio_vq_intrhand(struct virtio_softc *);
void virtio_stop_vq_intr(struct virtio_softc *, struct virtqueue *);
void virtio_start_vq_intr(struct virtio_softc *, struct virtqueue *);