Module Name:    src
Committed By:   ozaki-r
Date:           Thu Oct 29 02:09:02 UTC 2015

Modified Files:
        src/sys/dev/pci: if_vioif.c

Log Message:
Name virtqueue index


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/pci/if_vioif.c

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.18 src/sys/dev/pci/if_vioif.c:1.19
--- src/sys/dev/pci/if_vioif.c:1.18	Tue Oct 27 15:56:21 2015
+++ src/sys/dev/pci/if_vioif.c	Thu Oct 29 02:09:02 2015
@@ -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 vioif_softc {
 
 	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 @@ vioif_alloc_mems(struct vioif_softc *sc)
 	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 @@ vioif_attach(device_t parent, device_t s
 	/*
 	 * 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 @@ vioif_attach(device_t parent, device_t s
 			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 @@ err:
 		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 @@ vioif_stop(struct ifnet *ifp, int disabl
 
 	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 @@ vioif_start(struct ifnet *ifp)
 {
 	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 @@ vioif_watchdog(struct ifnet *ifp)
 	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 @@ vioif_populate_rx_mbufs_locked(struct vi
 {
 	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 @@ static int
 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 @@ vioif_rx_softint(void *arg)
 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 @@ static void
 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 @@ static int
 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 @@ vioif_set_rx_filter(struct vioif_softc *
 {
 	/* 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)

Reply via email to