summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorsephe <sephe@FreeBSD.org>2017-01-05 06:11:53 +0000
committersephe <sephe@FreeBSD.org>2017-01-05 06:11:53 +0000
commitbd94ba508fbe154d01aa2799029931b8a8b32da8 (patch)
treec5c6b57074706cf5f29a5e35530e82590a044ab1 /sys
parent39ca2a59d0256577dbaaab2b02d90fabd0926f46 (diff)
downloadFreeBSD-src-bd94ba508fbe154d01aa2799029931b8a8b32da8.zip
FreeBSD-src-bd94ba508fbe154d01aa2799029931b8a8b32da8.tar.gz
MFC 309346,309348,309353
309346 hyperv/hn: Add HN_DEBUG kernel option. If bufring is used for per-TX ring descs, don't update "available" counter, which is only used to help debugging. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8674 309348 hyperv/hn: Don't hold txdesc, if no BPFs are attached. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8675 309353 hyperv/hn: Add 'options RSS' support. Reviewed by: adrian Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8676
Diffstat (limited to 'sys')
-rw-r--r--sys/conf/options3
-rw-r--r--sys/dev/hyperv/netvsc/if_hn.c97
-rw-r--r--sys/modules/hyperv/netvsc/Makefile3
3 files changed, 88 insertions, 15 deletions
diff --git a/sys/conf/options b/sys/conf/options
index 3fa7d3b..612de3d 100644
--- a/sys/conf/options
+++ b/sys/conf/options
@@ -992,3 +992,6 @@ GPIO_SPI_DEBUG opt_gpio.h
EVDEV_SUPPORT opt_evdev.h
EVDEV_DEBUG opt_evdev.h
UINPUT_DEBUG opt_evdev.h
+
+# Hyper-V network driver
+HN_DEBUG opt_hn.h
diff --git a/sys/dev/hyperv/netvsc/if_hn.c b/sys/dev/hyperv/netvsc/if_hn.c
index f8d2967..983fdc3 100644
--- a/sys/dev/hyperv/netvsc/if_hn.c
+++ b/sys/dev/hyperv/netvsc/if_hn.c
@@ -55,8 +55,10 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include "opt_hn.h"
#include "opt_inet6.h"
#include "opt_inet.h"
+#include "opt_rss.h"
#include <sys/param.h>
#include <sys/bus.h>
@@ -86,6 +88,9 @@ __FBSDID("$FreeBSD$");
#include <net/if_types.h>
#include <net/if_var.h>
#include <net/rndis.h>
+#ifdef RSS
+#include <net/rss_config.h>
+#endif
#include <netinet/in_systm.h>
#include <netinet/in.h>
@@ -169,7 +174,11 @@ do { \
#define HN_PKTSIZE(m, align) \
roundup2((m)->m_pkthdr.len + HN_RNDIS_PKT_LEN, (align))
+#ifdef RSS
+#define HN_RING_IDX2CPU(sc, idx) rss_getcpu((idx) % rss_getnumbuckets())
+#else
#define HN_RING_IDX2CPU(sc, idx) (((sc)->hn_cpu + (idx)) % mp_ncpus)
+#endif
struct hn_txdesc {
#ifndef HN_USE_TXDESC_BUFRING
@@ -275,8 +284,10 @@ static int hn_ndis_version_sysctl(SYSCTL_HANDLER_ARGS);
static int hn_caps_sysctl(SYSCTL_HANDLER_ARGS);
static int hn_hwassist_sysctl(SYSCTL_HANDLER_ARGS);
static int hn_rxfilter_sysctl(SYSCTL_HANDLER_ARGS);
+#ifndef RSS
static int hn_rss_key_sysctl(SYSCTL_HANDLER_ARGS);
static int hn_rss_ind_sysctl(SYSCTL_HANDLER_ARGS);
+#endif
static int hn_rss_hash_sysctl(SYSCTL_HANDLER_ARGS);
static int hn_txagg_size_sysctl(SYSCTL_HANDLER_ARGS);
static int hn_txagg_pkts_sysctl(SYSCTL_HANDLER_ARGS);
@@ -320,7 +331,9 @@ static int hn_create_rx_data(struct hn_softc *, int);
static void hn_destroy_rx_data(struct hn_softc *);
static int hn_check_iplen(const struct mbuf *, int);
static int hn_set_rxfilter(struct hn_softc *);
+#ifndef RSS
static int hn_rss_reconfig(struct hn_softc *);
+#endif
static void hn_rss_ind_fixup(struct hn_softc *);
static int hn_rxpkt(struct hn_rx_ring *, const void *,
int, const struct hn_rxinfo *);
@@ -477,6 +490,7 @@ SYSCTL_INT(_hw_hn, OID_AUTO, tx_agg_pkts, CTLFLAG_RDTUN,
static u_int hn_cpu_index; /* next CPU for channel */
static struct taskqueue **hn_tx_taskque;/* shared TX taskqueues */
+#ifndef RSS
static const uint8_t
hn_rss_key_default[NDIS_HASH_KEYSIZE_TOEPLITZ] = {
0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
@@ -485,6 +499,7 @@ hn_rss_key_default[NDIS_HASH_KEYSIZE_TOEPLITZ] = {
0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa
};
+#endif /* !RSS */
static device_method_t hn_methods[] = {
/* Device interface */
@@ -782,6 +797,7 @@ hn_get_txswq_depth(const struct hn_tx_ring *txr)
return hn_tx_swq_depth;
}
+#ifndef RSS
static int
hn_rss_reconfig(struct hn_softc *sc)
{
@@ -820,6 +836,7 @@ hn_rss_reconfig(struct hn_softc *sc)
}
return (0);
}
+#endif /* !RSS */
static void
hn_rss_ind_fixup(struct hn_softc *sc)
@@ -968,6 +985,10 @@ hn_attach(device_t dev)
} else if (ring_cnt > mp_ncpus) {
ring_cnt = mp_ncpus;
}
+#ifdef RSS
+ if (ring_cnt > rss_getnumbuckets())
+ ring_cnt = rss_getnumbuckets();
+#endif
tx_ring_cnt = hn_tx_ring_cnt;
if (tx_ring_cnt <= 0 || tx_ring_cnt > ring_cnt)
@@ -1067,12 +1088,17 @@ hn_attach(device_t dev)
hn_rss_hash_sysctl, "A", "RSS hash");
SYSCTL_ADD_INT(ctx, child, OID_AUTO, "rss_ind_size",
CTLFLAG_RD, &sc->hn_rss_ind_size, 0, "RSS indirect entry count");
+#ifndef RSS
+ /*
+ * Don't allow RSS key/indirect table changes, if RSS is defined.
+ */
SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rss_key",
CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, 0,
hn_rss_key_sysctl, "IU", "RSS key");
SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rss_ind",
CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, 0,
hn_rss_ind_sysctl, "IU", "RSS indirect table");
+#endif
SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "rndis_agg_size",
CTLFLAG_RD, &sc->hn_rndis_agg_size, 0,
"RNDIS offered packet transmission aggregation size limit");
@@ -1428,10 +1454,12 @@ hn_txdesc_put(struct hn_tx_ring *txr, struct hn_txdesc *txd)
txr->hn_txdesc_avail++;
SLIST_INSERT_HEAD(&txr->hn_txlist, txd, link);
mtx_unlock_spin(&txr->hn_txlist_spin);
-#else
+#else /* HN_USE_TXDESC_BUFRING */
+#ifdef HN_DEBUG
atomic_add_int(&txr->hn_txdesc_avail, 1);
- buf_ring_enqueue(txr->hn_txdesc_br, txd);
#endif
+ buf_ring_enqueue(txr->hn_txdesc_br, txd);
+#endif /* !HN_USE_TXDESC_BUFRING */
return 1;
}
@@ -1457,8 +1485,10 @@ hn_txdesc_get(struct hn_tx_ring *txr)
if (txd != NULL) {
#ifdef HN_USE_TXDESC_BUFRING
+#ifdef HN_DEBUG
atomic_subtract_int(&txr->hn_txdesc_avail, 1);
#endif
+#endif /* HN_USE_TXDESC_BUFRING */
KASSERT(txd->m == NULL && txd->refs == 0 &&
STAILQ_EMPTY(&txd->agg_list) &&
txd->chim_index == HN_NVS_CHIM_IDX_INVALID &&
@@ -1919,17 +1949,20 @@ done:
static int
hn_txpkt(struct ifnet *ifp, struct hn_tx_ring *txr, struct hn_txdesc *txd)
{
- int error, send_failed = 0;
+ int error, send_failed = 0, has_bpf;
again:
- /*
- * Make sure that this txd and any aggregated txds are not freed
- * before ETHER_BPF_MTAP.
- */
- hn_txdesc_hold(txd);
+ has_bpf = bpf_peers_present(ifp->if_bpf);
+ if (has_bpf) {
+ /*
+ * Make sure that this txd and any aggregated txds are not
+ * freed before ETHER_BPF_MTAP.
+ */
+ hn_txdesc_hold(txd);
+ }
error = txr->hn_sendpkt(txr, txd);
if (!error) {
- if (bpf_peers_present(ifp->if_bpf)) {
+ if (has_bpf) {
const struct hn_txdesc *tmp_txd;
ETHER_BPF_MTAP(ifp, txd->m);
@@ -1952,7 +1985,8 @@ again:
txr->hn_pkts += txr->hn_stat_pkts;
txr->hn_sends++;
}
- hn_txdesc_put(txr, txd);
+ if (has_bpf)
+ hn_txdesc_put(txr, txd);
if (__predict_false(error)) {
int freed;
@@ -2896,6 +2930,8 @@ hn_rxfilter_sysctl(SYSCTL_HANDLER_ARGS)
return sysctl_handle_string(oidp, filter_str, sizeof(filter_str), req);
}
+#ifndef RSS
+
static int
hn_rss_key_sysctl(SYSCTL_HANDLER_ARGS)
{
@@ -2957,6 +2993,8 @@ back:
return (error);
}
+#endif /* !RSS */
+
static int
hn_rss_hash_sysctl(SYSCTL_HANDLER_ARGS)
{
@@ -3467,9 +3505,11 @@ hn_tx_ring_create(struct hn_softc *sc, int id)
if (txr->hn_tx_sysctl_tree != NULL) {
child = SYSCTL_CHILDREN(txr->hn_tx_sysctl_tree);
+#ifdef HN_DEBUG
SYSCTL_ADD_INT(ctx, child, OID_AUTO, "txdesc_avail",
CTLFLAG_RD, &txr->hn_txdesc_avail, 0,
"# of available TX descs");
+#endif
#ifdef HN_IFSTART_SUPPORT
if (!hn_use_if_start)
#endif
@@ -4074,8 +4114,17 @@ hn_transmit(struct ifnet *ifp, struct mbuf *m)
/*
* Select the TX ring based on flowid
*/
- if (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE)
- idx = m->m_pkthdr.flowid % sc->hn_tx_ring_inuse;
+ if (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE) {
+#ifdef RSS
+ uint32_t bid;
+
+ if (rss_hash2bucket(m->m_pkthdr.flowid, M_HASHTYPE_GET(m),
+ &bid) == 0)
+ idx = bid % sc->hn_tx_ring_inuse;
+ else
+#endif
+ idx = m->m_pkthdr.flowid % sc->hn_tx_ring_inuse;
+ }
txr = &sc->hn_tx_ring[idx];
error = drbr_enqueue(ifp, txr->hn_mbuf_br, m);
@@ -4531,7 +4580,11 @@ hn_synth_attach(struct hn_softc *sc, int mtu)
*/
if (bootverbose)
if_printf(sc->hn_ifp, "setup default RSS key\n");
+#ifdef RSS
+ rss_getkey(rss->rss_key);
+#else
memcpy(rss->rss_key, hn_rss_key_default, sizeof(rss->rss_key));
+#endif
sc->hn_flags |= HN_FLAG_HAS_RSSKEY;
}
@@ -4544,8 +4597,16 @@ hn_synth_attach(struct hn_softc *sc, int mtu)
if_printf(sc->hn_ifp, "setup default RSS indirect "
"table\n");
}
- for (i = 0; i < NDIS_HASH_INDCNT; ++i)
- rss->rss_ind[i] = i % nchan;
+ for (i = 0; i < NDIS_HASH_INDCNT; ++i) {
+ uint32_t subidx;
+
+#ifdef RSS
+ subidx = rss_get_indirection_to_bucket(i);
+#else
+ subidx = i;
+#endif
+ rss->rss_ind[i] = subidx % nchan;
+ }
sc->hn_flags |= HN_FLAG_HAS_RSSIND;
} else {
/*
@@ -4622,6 +4683,14 @@ hn_set_ring_inuse(struct hn_softc *sc, int ring_cnt)
sc->hn_tx_ring_inuse = sc->hn_tx_ring_cnt;
sc->hn_rx_ring_inuse = ring_cnt;
+#ifdef RSS
+ if (sc->hn_rx_ring_inuse != rss_getnumbuckets()) {
+ if_printf(sc->hn_ifp, "# of RX rings (%d) does not match "
+ "# of RSS buckets (%d)\n", sc->hn_rx_ring_inuse,
+ rss_getnumbuckets());
+ }
+#endif
+
if (bootverbose) {
if_printf(sc->hn_ifp, "%d TX ring, %d RX ring\n",
sc->hn_tx_ring_inuse, sc->hn_rx_ring_inuse);
diff --git a/sys/modules/hyperv/netvsc/Makefile b/sys/modules/hyperv/netvsc/Makefile
index 1d572cb..e2a2533 100644
--- a/sys/modules/hyperv/netvsc/Makefile
+++ b/sys/modules/hyperv/netvsc/Makefile
@@ -5,7 +5,8 @@
KMOD= hv_netvsc
SRCS= hn_nvs.c hn_rndis.c if_hn.c
-SRCS+= bus_if.h device_if.h opt_inet.h opt_inet6.h vmbus_if.h
+SRCS+= bus_if.h device_if.h vmbus_if.h
+SRCS+= opt_hn.h opt_inet.h opt_inet6.h opt_rss.h
CFLAGS+= -I${.CURDIR}/../../../dev/hyperv/netvsc
OpenPOWER on IntegriCloud