Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci Name virtqueue index



details:   https://anonhg.NetBSD.org/src/rev/39693f818e26
branches:  trunk
changeset: 811409:39693f818e26
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Thu Oct 29 02:09:02 2015 +0000

description:
Name virtqueue index

diffstat:

 sys/dev/pci/if_vioif.c |  57 ++++++++++++++++++++++++++-----------------------
 1 files changed, 30 insertions(+), 27 deletions(-)

diffs (201 lines):

diff -r 132d825b4b95 -r 39693f818e26 sys/dev/pci/if_vioif.c
--- a/sys/dev/pci/if_vioif.c    Thu Oct 29 01:56:12 2015 +0000
+++ b/sys/dev/pci/if_vioif.c    Thu Oct 29 02:09:02 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_vioif.c,v 1.18 2015/10/27 15:56:21 christos Exp $   */
+/*     $NetBSD: if_vioif.c,v 1.19 2015/10/29 02:09:02 ozaki-r Exp $    */
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.18 2015/10/27 15:56:21 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.19 2015/10/29 02:09:02 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -181,6 +181,9 @@
 
        struct virtio_softc     *sc_virtio;
        struct virtqueue        sc_vq[3];
+#define VQ_RX  0
+#define VQ_TX  1
+#define VQ_CTRL        2
 
        uint8_t                 sc_mac[ETHER_ADDR_LEN];
        struct ethercom         sc_ethercom;
@@ -318,8 +321,8 @@
        intptr_t p;
        int rxqsize, txqsize;
 
-       rxqsize = vsc->sc_vqs[0].vq_num;
-       txqsize = vsc->sc_vqs[1].vq_num;
+       rxqsize = vsc->sc_vqs[VQ_RX].vq_num;
+       txqsize = vsc->sc_vqs[VQ_TX].vq_num;
 
        allocsize = sizeof(struct virtio_net_hdr) * rxqsize;
        allocsize += sizeof(struct virtio_net_hdr) * txqsize;
@@ -597,33 +600,33 @@
        /*
         * Allocating a virtqueue for Rx
         */
-       r = virtio_alloc_vq(vsc, &sc->sc_vq[0], 0,
+       r = virtio_alloc_vq(vsc, &sc->sc_vq[VQ_RX], 0,
            MCLBYTES+sizeof(struct virtio_net_hdr), 2, "rx");
        if (r != 0)
                goto err;
        vsc->sc_nvqs = 1;
-       sc->sc_vq[0].vq_done = vioif_rx_vq_done;
+       sc->sc_vq[VQ_RX].vq_done = vioif_rx_vq_done;
 
        /*
         * Allocating a virtqueue for Tx
         */
-       r = virtio_alloc_vq(vsc, &sc->sc_vq[1], 1,
+       r = virtio_alloc_vq(vsc, &sc->sc_vq[VQ_TX], 1,
            (sizeof(struct virtio_net_hdr) + (ETHER_MAX_LEN - ETHER_HDR_LEN)),
            VIRTIO_NET_TX_MAXNSEGS + 1, "tx");
        if (r != 0)
                goto err;
        vsc->sc_nvqs = 2;
-       sc->sc_vq[1].vq_done = vioif_tx_vq_done;
+       sc->sc_vq[VQ_TX].vq_done = vioif_tx_vq_done;
 
-       virtio_start_vq_intr(vsc, &sc->sc_vq[0]);
-       virtio_stop_vq_intr(vsc, &sc->sc_vq[1]); /* not urgent; do it later */
+       virtio_start_vq_intr(vsc, &sc->sc_vq[VQ_RX]);
+       virtio_stop_vq_intr(vsc, &sc->sc_vq[VQ_TX]); /* not urgent; do it later */
 
        if ((features & VIRTIO_NET_F_CTRL_VQ) &&
            (features & VIRTIO_NET_F_CTRL_RX)) {
                /*
                 * Allocating a virtqueue for control channel
                 */
-               r = virtio_alloc_vq(vsc, &sc->sc_vq[2], 2,
+               r = virtio_alloc_vq(vsc, &sc->sc_vq[VQ_CTRL], 2,
                    NBPG, 1, "control");
                if (r != 0) {
                        aprint_error_dev(self, "failed to allocate "
@@ -631,11 +634,11 @@
                        goto skip;
                }
 
-               sc->sc_vq[2].vq_done = vioif_ctrl_vq_done;
+               sc->sc_vq[VQ_CTRL].vq_done = vioif_ctrl_vq_done;
                cv_init(&sc->sc_ctrl_wait, "ctrl_vq");
                mutex_init(&sc->sc_ctrl_wait_lock, MUTEX_DEFAULT, IPL_NET);
                sc->sc_ctrl_inuse = FREE;
-               virtio_start_vq_intr(vsc, &sc->sc_vq[2]);
+               virtio_start_vq_intr(vsc, &sc->sc_vq[VQ_CTRL]);
                vsc->sc_nvqs = 3;
        }
 skip:
@@ -678,17 +681,17 @@
                mutex_obj_free(sc->sc_rx_lock);
 
        if (vsc->sc_nvqs == 3) {
-               virtio_free_vq(vsc, &sc->sc_vq[2]);
+               virtio_free_vq(vsc, &sc->sc_vq[VQ_CTRL]);
                cv_destroy(&sc->sc_ctrl_wait);
                mutex_destroy(&sc->sc_ctrl_wait_lock);
                vsc->sc_nvqs = 2;
        }
        if (vsc->sc_nvqs == 2) {
-               virtio_free_vq(vsc, &sc->sc_vq[1]);
+               virtio_free_vq(vsc, &sc->sc_vq[VQ_TX]);
                vsc->sc_nvqs = 1;
        }
        if (vsc->sc_nvqs == 1) {
-               virtio_free_vq(vsc, &sc->sc_vq[0]);
+               virtio_free_vq(vsc, &sc->sc_vq[VQ_RX]);
                vsc->sc_nvqs = 0;
        }
        vsc->sc_child = (void*)1;
@@ -767,10 +770,10 @@
 
        virtio_reinit_start(vsc);
        virtio_negotiate_features(vsc, vsc->sc_features);
-       virtio_start_vq_intr(vsc, &sc->sc_vq[0]);
-       virtio_stop_vq_intr(vsc, &sc->sc_vq[1]);
+       virtio_start_vq_intr(vsc, &sc->sc_vq[VQ_RX]);
+       virtio_stop_vq_intr(vsc, &sc->sc_vq[VQ_TX]);
        if (vsc->sc_nvqs >= 3)
-               virtio_start_vq_intr(vsc, &sc->sc_vq[2]);
+               virtio_start_vq_intr(vsc, &sc->sc_vq[VQ_CTRL]);
        virtio_reinit_end(vsc);
        vioif_updown(sc, false);
 }
@@ -780,7 +783,7 @@
 {
        struct vioif_softc *sc = ifp->if_softc;
        struct virtio_softc *vsc = sc->sc_virtio;
-       struct virtqueue *vq = &sc->sc_vq[1]; /* tx vq */
+       struct virtqueue *vq = &sc->sc_vq[VQ_TX];
        struct mbuf *m;
        int queued = 0, retry = 0;
 
@@ -892,7 +895,7 @@
        struct vioif_softc *sc = ifp->if_softc;
 
        if (ifp->if_flags & IFF_RUNNING)
-               vioif_tx_vq_done(&sc->sc_vq[1]);
+               vioif_tx_vq_done(&sc->sc_vq[VQ_TX]);
 }
 
 
@@ -951,7 +954,7 @@
 {
        struct virtio_softc *vsc = sc->sc_virtio;
        int i, r, ndone = 0;
-       struct virtqueue *vq = &sc->sc_vq[0]; /* rx vq */
+       struct virtqueue *vq = &sc->sc_vq[VQ_RX];
 
        KASSERT(VIOIF_RX_LOCKED(sc));
 
@@ -1013,7 +1016,7 @@
 vioif_rx_deq_locked(struct vioif_softc *sc)
 {
        struct virtio_softc *vsc = sc->sc_virtio;
-       struct virtqueue *vq = &sc->sc_vq[0];
+       struct virtqueue *vq = &sc->sc_vq[VQ_RX];
        struct ifnet *ifp = &sc->sc_ethercom.ec_if;
        struct mbuf *m;
        int r = 0;
@@ -1094,7 +1097,7 @@
 static void
 vioif_rx_drain(struct vioif_softc *sc)
 {
-       struct virtqueue *vq = &sc->sc_vq[0];
+       struct virtqueue *vq = &sc->sc_vq[VQ_RX];
        int i;
 
        for (i = 0; i < vq->vq_num; i++) {
@@ -1171,7 +1174,7 @@
 vioif_tx_drain(struct vioif_softc *sc)
 {
        struct virtio_softc *vsc = sc->sc_virtio;
-       struct virtqueue *vq = &sc->sc_vq[1];
+       struct virtqueue *vq = &sc->sc_vq[VQ_TX];
        int i;
 
        KASSERT(sc->sc_stopping);
@@ -1193,7 +1196,7 @@
 vioif_ctrl_rx(struct vioif_softc *sc, int cmd, bool onoff)
 {
        struct virtio_softc *vsc = sc->sc_virtio;
-       struct virtqueue *vq = &sc->sc_vq[2];
+       struct virtqueue *vq = &sc->sc_vq[VQ_CTRL];
        int r, slot;
 
        if (vsc->sc_nvqs < 3)
@@ -1289,7 +1292,7 @@
 {
        /* filter already set in sc_ctrl_mac_tbl */
        struct virtio_softc *vsc = sc->sc_virtio;
-       struct virtqueue *vq = &sc->sc_vq[2];
+       struct virtqueue *vq = &sc->sc_vq[VQ_CTRL];
        int r, slot;
 
        if (vsc->sc_nvqs < 3)



Home | Main Index | Thread Index | Old Index