socsvn commit: r288618 - soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network
stefano at FreeBSD.org
stefano at FreeBSD.org
Tue Jul 21 14:19:52 UTC 2015
Author: stefano
Date: Tue Jul 21 14:19:50 2015
New Revision: 288618
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=288618
Log:
add ptnetmap support on virtio-net
Modified:
soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/if_vtnet.c
soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/if_vtnetvar.h
soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/virtio_net.h
Modified: soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/if_vtnet.c
==============================================================================
--- soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/if_vtnet.c Tue Jul 21 14:19:04 2015 (r288617)
+++ soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/if_vtnet.c Tue Jul 21 14:19:50 2015 (r288618)
@@ -30,6 +30,7 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
+#include <sys/eventhandler.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/sockio.h>
@@ -50,6 +51,7 @@
#include <net/ethernet.h>
#include <net/if.h>
+#include <net/if_var.h>
#include <net/if_arp.h>
#include <net/if_dl.h>
#include <net/if_types.h>
@@ -105,6 +107,7 @@
static int vtnet_setup_interface(struct vtnet_softc *);
static int vtnet_change_mtu(struct vtnet_softc *, int);
static int vtnet_ioctl(struct ifnet *, u_long, caddr_t);
+static uint64_t vtnet_get_counter(struct ifnet *, ift_counter);
static int vtnet_rxq_populate(struct vtnet_rxq *);
static void vtnet_rxq_free_mbufs(struct vtnet_rxq *);
@@ -158,11 +161,8 @@
#endif
static int vtnet_watchdog(struct vtnet_txq *);
-static void vtnet_rxq_accum_stats(struct vtnet_rxq *,
- struct vtnet_rxq_stats *);
-static void vtnet_txq_accum_stats(struct vtnet_txq *,
- struct vtnet_txq_stats *);
-static void vtnet_accumulate_stats(struct vtnet_softc *);
+static void vtnet_accum_stats(struct vtnet_softc *,
+ struct vtnet_rxq_stats *, struct vtnet_txq_stats *);
static void vtnet_tick(void *);
static void vtnet_start_taskqueues(struct vtnet_softc *);
@@ -267,6 +267,7 @@
{ VIRTIO_NET_F_GUEST_ANNOUNCE, "GuestAnnounce" },
{ VIRTIO_NET_F_MQ, "Multiqueue" },
{ VIRTIO_NET_F_CTRL_MAC_ADDR, "SetMacAddress" },
+ { VIRTIO_NET_F_PTNETMAP, "PTNetmap" },
{ 0, NULL }
};
@@ -289,6 +290,8 @@
#ifdef DEV_NETMAP
#include <dev/netmap/if_vtnet_netmap.h>
+#else
+#define VTNET_PTNETMAP_ON(_na) 0
#endif /* DEV_NETMAP */
static driver_t vtnet_driver = {
@@ -298,6 +301,8 @@
};
static devclass_t vtnet_devclass;
+DRIVER_MODULE(vtnet, virtio_mmio, vtnet_driver, vtnet_devclass,
+ vtnet_modevent, 0);
DRIVER_MODULE(vtnet, virtio_pci, vtnet_driver, vtnet_devclass,
vtnet_modevent, 0);
MODULE_VERSION(vtnet, 1);
@@ -916,12 +921,12 @@
}
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
- if_initbaudrate(ifp, IF_Gbps(10)); /* Approx. */
+ ifp->if_baudrate = IF_Gbps(10); /* Approx. */
ifp->if_softc = sc;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
ifp->if_init = vtnet_init;
ifp->if_ioctl = vtnet_ioctl;
-
+ ifp->if_get_counter = vtnet_get_counter;
#ifndef VTNET_LEGACY_TX
ifp->if_transmit = vtnet_txq_mq_start;
ifp->if_qflush = vtnet_qflush;
@@ -947,7 +952,7 @@
ifp->if_capabilities |= IFCAP_LINKSTATE;
/* Tell the upper layer(s) we support long frames. */
- ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
+ ifp->if_hdrlen = sizeof(struct ether_vlan_header);
ifp->if_capabilities |= IFCAP_JUMBO_MTU | IFCAP_VLAN_MTU;
if (virtio_with_feature(dev, VIRTIO_NET_F_CSUM)) {
@@ -1854,7 +1859,7 @@
}
more = vtnet_rxq_eof(rxq);
- if (more || vtnet_rxq_enable_intr(rxq) != 0) {
+ if (!VTNET_PTNETMAP_ON(NA(ifp)) && (more || vtnet_rxq_enable_intr(rxq) != 0)) {
if (!more)
vtnet_rxq_disable_intr(rxq);
/*
@@ -1891,7 +1896,7 @@
}
more = vtnet_rxq_eof(rxq);
- if (more || vtnet_rxq_enable_intr(rxq) != 0) {
+ if (!VTNET_PTNETMAP_ON(NA(ifp)) && (more || vtnet_rxq_enable_intr(rxq) != 0)) {
if (!more)
vtnet_rxq_disable_intr(rxq);
rxq->vtnrx_stats.vrxs_rescheduled++;
@@ -2573,74 +2578,62 @@
}
static void
-vtnet_rxq_accum_stats(struct vtnet_rxq *rxq, struct vtnet_rxq_stats *accum)
+vtnet_accum_stats(struct vtnet_softc *sc, struct vtnet_rxq_stats *rxacc,
+ struct vtnet_txq_stats *txacc)
{
- struct vtnet_rxq_stats *st;
- st = &rxq->vtnrx_stats;
+ bzero(rxacc, sizeof(struct vtnet_rxq_stats));
+ bzero(txacc, sizeof(struct vtnet_txq_stats));
- accum->vrxs_ipackets += st->vrxs_ipackets;
- accum->vrxs_ibytes += st->vrxs_ibytes;
- accum->vrxs_iqdrops += st->vrxs_iqdrops;
- accum->vrxs_csum += st->vrxs_csum;
- accum->vrxs_csum_failed += st->vrxs_csum_failed;
- accum->vrxs_rescheduled += st->vrxs_rescheduled;
-}
+ for (int i = 0; i < sc->vtnet_max_vq_pairs; i++) {
+ struct vtnet_rxq_stats *rxst;
+ struct vtnet_txq_stats *txst;
-static void
-vtnet_txq_accum_stats(struct vtnet_txq *txq, struct vtnet_txq_stats *accum)
-{
- struct vtnet_txq_stats *st;
+ rxst = &sc->vtnet_rxqs[i].vtnrx_stats;
+ rxacc->vrxs_ipackets += rxst->vrxs_ipackets;
+ rxacc->vrxs_ibytes += rxst->vrxs_ibytes;
+ rxacc->vrxs_iqdrops += rxst->vrxs_iqdrops;
+ rxacc->vrxs_csum += rxst->vrxs_csum;
+ rxacc->vrxs_csum_failed += rxst->vrxs_csum_failed;
+ rxacc->vrxs_rescheduled += rxst->vrxs_rescheduled;
- st = &txq->vtntx_stats;
-
- accum->vtxs_opackets += st->vtxs_opackets;
- accum->vtxs_obytes += st->vtxs_obytes;
- accum->vtxs_csum += st->vtxs_csum;
- accum->vtxs_tso += st->vtxs_tso;
- accum->vtxs_rescheduled += st->vtxs_rescheduled;
+ txst = &sc->vtnet_txqs[i].vtntx_stats;
+ txacc->vtxs_opackets += txst->vtxs_opackets;
+ txacc->vtxs_obytes += txst->vtxs_obytes;
+ txacc->vtxs_csum += txst->vtxs_csum;
+ txacc->vtxs_tso += txst->vtxs_tso;
+ txacc->vtxs_rescheduled += txst->vtxs_rescheduled;
+ }
}
-static void
-vtnet_accumulate_stats(struct vtnet_softc *sc)
+static uint64_t
+vtnet_get_counter(if_t ifp, ift_counter cnt)
{
- struct ifnet *ifp;
- struct vtnet_statistics *st;
+ struct vtnet_softc *sc;
struct vtnet_rxq_stats rxaccum;
struct vtnet_txq_stats txaccum;
- int i;
-
- ifp = sc->vtnet_ifp;
- st = &sc->vtnet_stats;
- bzero(&rxaccum, sizeof(struct vtnet_rxq_stats));
- bzero(&txaccum, sizeof(struct vtnet_txq_stats));
- for (i = 0; i < sc->vtnet_max_vq_pairs; i++) {
- vtnet_rxq_accum_stats(&sc->vtnet_rxqs[i], &rxaccum);
- vtnet_txq_accum_stats(&sc->vtnet_txqs[i], &txaccum);
- }
+ sc = if_getsoftc(ifp);
+ vtnet_accum_stats(sc, &rxaccum, &txaccum);
- st->rx_csum_offloaded = rxaccum.vrxs_csum;
- st->rx_csum_failed = rxaccum.vrxs_csum_failed;
- st->rx_task_rescheduled = rxaccum.vrxs_rescheduled;
- st->tx_csum_offloaded = txaccum.vtxs_csum;
- st->tx_tso_offloaded = txaccum.vtxs_tso;
- st->tx_task_rescheduled = txaccum.vtxs_rescheduled;
-
- /*
- * With the exception of if_ierrors, these ifnet statistics are
- * only updated in the driver, so just set them to our accumulated
- * values. if_ierrors is updated in ether_input() for malformed
- * frames that we should have already discarded.
- */
- ifp->if_ipackets = rxaccum.vrxs_ipackets;
- ifp->if_iqdrops = rxaccum.vrxs_iqdrops;
- ifp->if_ierrors = rxaccum.vrxs_ierrors;
- ifp->if_opackets = txaccum.vtxs_opackets;
+ switch (cnt) {
+ case IFCOUNTER_IPACKETS:
+ return (rxaccum.vrxs_ipackets);
+ case IFCOUNTER_IQDROPS:
+ return (rxaccum.vrxs_iqdrops);
+ case IFCOUNTER_IERRORS:
+ return (rxaccum.vrxs_ierrors);
+ case IFCOUNTER_OPACKETS:
+ return (txaccum.vtxs_opackets);
#ifndef VTNET_LEGACY_TX
- ifp->if_obytes = txaccum.vtxs_obytes;
- ifp->if_omcasts = txaccum.vtxs_omcasts;
+ case IFCOUNTER_OBYTES:
+ return (txaccum.vtxs_obytes);
+ case IFCOUNTER_OMCASTS:
+ return (txaccum.vtxs_omcasts);
#endif
+ default:
+ return (if_get_counter_default(ifp, cnt));
+ }
}
static void
@@ -2655,7 +2648,6 @@
timedout = 0;
VTNET_CORE_LOCK_ASSERT(sc);
- vtnet_accumulate_stats(sc);
for (i = 0; i < sc->vtnet_act_vq_pairs; i++)
timedout |= vtnet_watchdog(&sc->vtnet_txqs[i]);
@@ -3767,8 +3759,18 @@
struct sysctl_oid_list *child, struct vtnet_softc *sc)
{
struct vtnet_statistics *stats;
+ struct vtnet_rxq_stats rxaccum;
+ struct vtnet_txq_stats txaccum;
+
+ vtnet_accum_stats(sc, &rxaccum, &txaccum);
stats = &sc->vtnet_stats;
+ stats->rx_csum_offloaded = rxaccum.vrxs_csum;
+ stats->rx_csum_failed = rxaccum.vrxs_csum_failed;
+ stats->rx_task_rescheduled = rxaccum.vrxs_rescheduled;
+ stats->tx_csum_offloaded = txaccum.vtxs_csum;
+ stats->tx_tso_offloaded = txaccum.vtxs_tso;
+ stats->tx_task_rescheduled = txaccum.vtxs_rescheduled;
SYSCTL_ADD_UQUAD(ctx, child, OID_AUTO, "mbuf_alloc_failed",
CTLFLAG_RD, &stats->mbuf_alloc_failed,
Modified: soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/if_vtnetvar.h
==============================================================================
--- soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/if_vtnetvar.h Tue Jul 21 14:19:04 2015 (r288617)
+++ soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/if_vtnetvar.h Tue Jul 21 14:19:50 2015 (r288618)
@@ -285,7 +285,8 @@
VIRTIO_NET_F_MRG_RXBUF | \
VIRTIO_NET_F_MQ | \
VIRTIO_RING_F_EVENT_IDX | \
- VIRTIO_RING_F_INDIRECT_DESC)
+ VIRTIO_RING_F_INDIRECT_DESC | \
+ VIRTIO_NET_F_PTNETMAP)
/*
* The VIRTIO_NET_F_HOST_TSO[46] features permit us to send the host
Modified: soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/virtio_net.h
==============================================================================
--- soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/virtio_net.h Tue Jul 21 14:19:04 2015 (r288617)
+++ soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/virtio_net.h Tue Jul 21 14:19:50 2015 (r288618)
@@ -53,6 +53,7 @@
#define VIRTIO_NET_F_GUEST_ANNOUNCE 0x200000 /* Announce device on network */
#define VIRTIO_NET_F_MQ 0x400000 /* Device supports RFS */
#define VIRTIO_NET_F_CTRL_MAC_ADDR 0x800000 /* Set MAC address */
+#define VIRTIO_NET_F_PTNETMAP 0x2000000 /* ptnetmap available */
#define VIRTIO_NET_S_LINK_UP 1 /* Link is up */
More information about the svn-soc-all
mailing list