Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Nov 2016 03:14:43 +0000 (UTC)
From:      Sepherosa Ziehau <sephe@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r308623 - in stable/11/sys: dev/hyperv/netvsc net
Message-ID:  <201611140314.uAE3Eh0q049046@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sephe
Date: Mon Nov 14 03:14:43 2016
New Revision: 308623
URL: https://svnweb.freebsd.org/changeset/base/308623

Log:
  MFC 307985-307988
  
  307985
      hyperv/hn: Nuke unnecessary M_NETVSC
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D8340
  
  307986
      hyperv/hn: Move %b format string for capabilities near their definition.
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D8341
  
  307987
      hyperv/hn: Define empty packet filter.
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D8342
  
  307988
      hyperv/hn: Shuffle chimney sending buffer alloc/free around.
  
      This paves way for more chimney sending buffer reorganization.
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D8343

Modified:
  stable/11/sys/dev/hyperv/netvsc/hv_net_vsc.c
  stable/11/sys/dev/hyperv/netvsc/hv_net_vsc.h
  stable/11/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
  stable/11/sys/dev/hyperv/netvsc/if_hnvar.h
  stable/11/sys/net/rndis.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/hyperv/netvsc/hv_net_vsc.c
==============================================================================
--- stable/11/sys/dev/hyperv/netvsc/hv_net_vsc.c	Mon Nov 14 03:07:48 2016	(r308622)
+++ stable/11/sys/dev/hyperv/netvsc/hv_net_vsc.c	Mon Nov 14 03:14:43 2016	(r308623)
@@ -52,8 +52,6 @@
 #include <dev/hyperv/netvsc/if_hnreg.h>
 #include <dev/hyperv/netvsc/if_hnvar.h>
 
-MALLOC_DEFINE(M_NETVSC, "netvsc", "Hyper-V netvsc driver");
-
 /*
  * Forward declarations
  */
@@ -75,33 +73,6 @@ static const uint32_t		hn_nvs_version[] 
 	HN_NVS_VERSION_1
 };
 
-uint32_t
-hn_chim_alloc(struct hn_softc *sc)
-{
-	int i, bmap_cnt = sc->hn_chim_bmap_cnt;
-	u_long *bmap = sc->hn_chim_bmap;
-	uint32_t ret = HN_NVS_CHIM_IDX_INVALID;
-
-	for (i = 0; i < bmap_cnt; ++i) {
-		int idx;
-
-		idx = ffsl(~bmap[i]);
-		if (idx == 0)
-			continue;
-
-		--idx; /* ffsl is 1-based */
-		KASSERT(i * LONG_BIT + idx < sc->hn_chim_cnt,
-		    ("invalid i %d and idx %d", i, idx));
-
-		if (atomic_testandset_long(&bmap[i], idx))
-			continue;
-
-		ret = i * LONG_BIT + idx;
-		break;
-	}
-	return (ret);
-}
-
 static const void *
 hn_nvs_xact_execute(struct hn_softc *sc, struct vmbus_xact *xact,
     void *req, int reqlen, size_t *resplen0, uint32_t type)
@@ -308,7 +279,7 @@ hn_nvs_conn_chim(struct hn_softc *sc)
 
 	sc->hn_chim_bmap_cnt = sc->hn_chim_cnt / LONG_BIT;
 	sc->hn_chim_bmap = malloc(sc->hn_chim_bmap_cnt * sizeof(u_long),
-	    M_NETVSC, M_WAITOK | M_ZERO);
+	    M_DEVBUF, M_WAITOK | M_ZERO);
 
 	/* Done! */
 	sc->hn_flags |= HN_FLAG_CHIM_CONNECTED;
@@ -427,7 +398,7 @@ hn_nvs_disconn_chim(struct hn_softc *sc)
 	}
 
 	if (sc->hn_chim_bmap != NULL) {
-		free(sc->hn_chim_bmap, M_NETVSC);
+		free(sc->hn_chim_bmap, M_DEVBUF);
 		sc->hn_chim_bmap = NULL;
 	}
 	return (0);
@@ -650,25 +621,6 @@ hn_nvs_sent_none(struct hn_send_ctx *snd
 	/* EMPTY */
 }
 
-void
-hn_chim_free(struct hn_softc *sc, uint32_t chim_idx)
-{
-	u_long mask;
-	uint32_t idx;
-
-	idx = chim_idx / LONG_BIT;
-	KASSERT(idx < sc->hn_chim_bmap_cnt,
-	    ("invalid chimney index 0x%x", chim_idx));
-
-	mask = 1UL << (chim_idx % LONG_BIT);
-	KASSERT(sc->hn_chim_bmap[idx] & mask,
-	    ("index bitmap 0x%lx, chimney index %u, "
-	     "bitmap idx %d, bitmask 0x%lx",
-	     sc->hn_chim_bmap[idx], chim_idx, idx, mask));
-
-	atomic_clear_long(&sc->hn_chim_bmap[idx], mask);
-}
-
 int
 hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch0)
 {

Modified: stable/11/sys/dev/hyperv/netvsc/hv_net_vsc.h
==============================================================================
--- stable/11/sys/dev/hyperv/netvsc/hv_net_vsc.h	Mon Nov 14 03:07:48 2016	(r308622)
+++ stable/11/sys/dev/hyperv/netvsc/hv_net_vsc.h	Mon Nov 14 03:14:43 2016	(r308623)
@@ -66,8 +66,6 @@
 
 #define HN_USE_TXDESC_BUFRING
 
-MALLOC_DECLARE(M_NETVSC);
-
 /*
  * The following arguably belongs in a separate header file
  */
@@ -277,6 +275,11 @@ struct hn_softc {
 #define HN_CAP_TSO6			0x0100
 #define HN_CAP_HASHVAL			0x0200
 
+/* Capability description for use with printf(9) %b identifier. */
+#define HN_CAP_BITS				\
+	"\020\1VLAN\2MTU\3IPCS\4TCP4CS\5TCP6CS"	\
+	"\6UDP4CS\7UDP6CS\10TSO4\11TSO6\12HASHVAL"
+
 #define HN_LINK_FLAG_LINKUP		0x0001
 #define HN_LINK_FLAG_NETCHG		0x0002
 

Modified: stable/11/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
==============================================================================
--- stable/11/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c	Mon Nov 14 03:07:48 2016	(r308622)
+++ stable/11/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c	Mon Nov 14 03:14:43 2016	(r308623)
@@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/sockio.h>
+#include <sys/limits.h>
 #include <sys/mbuf.h>
 #include <sys/malloc.h>
 #include <sys/module.h>
@@ -457,6 +458,52 @@ hn_sendpkt_rndis_chim(struct hn_tx_ring 
 	    &rndis, sizeof(rndis), &txd->send_ctx));
 }
 
+static __inline uint32_t
+hn_chim_alloc(struct hn_softc *sc)
+{
+	int i, bmap_cnt = sc->hn_chim_bmap_cnt;
+	u_long *bmap = sc->hn_chim_bmap;
+	uint32_t ret = HN_NVS_CHIM_IDX_INVALID;
+
+	for (i = 0; i < bmap_cnt; ++i) {
+		int idx;
+
+		idx = ffsl(~bmap[i]);
+		if (idx == 0)
+			continue;
+
+		--idx; /* ffsl is 1-based */
+		KASSERT(i * LONG_BIT + idx < sc->hn_chim_cnt,
+		    ("invalid i %d and idx %d", i, idx));
+
+		if (atomic_testandset_long(&bmap[i], idx))
+			continue;
+
+		ret = i * LONG_BIT + idx;
+		break;
+	}
+	return (ret);
+}
+
+static __inline void
+hn_chim_free(struct hn_softc *sc, uint32_t chim_idx)
+{
+	u_long mask;
+	uint32_t idx;
+
+	idx = chim_idx / LONG_BIT;
+	KASSERT(idx < sc->hn_chim_bmap_cnt,
+	    ("invalid chimney index 0x%x", chim_idx));
+
+	mask = 1UL << (chim_idx % LONG_BIT);
+	KASSERT(sc->hn_chim_bmap[idx] & mask,
+	    ("index bitmap 0x%lx, chimney index %u, "
+	     "bitmap idx %d, bitmask 0x%lx",
+	     sc->hn_chim_bmap[idx], chim_idx, idx, mask));
+
+	atomic_clear_long(&sc->hn_chim_bmap[idx], mask);
+}
+
 static int
 hn_set_rxfilter(struct hn_softc *sc)
 {
@@ -2379,18 +2426,7 @@ hn_caps_sysctl(SYSCTL_HANDLER_ARGS)
 	HN_LOCK(sc);
 	caps = sc->hn_caps;
 	HN_UNLOCK(sc);
-	snprintf(caps_str, sizeof(caps_str), "%b", caps,
-	    "\020"
-	    "\001VLAN"
-	    "\002MTU"
-	    "\003IPCS"
-	    "\004TCP4CS"
-	    "\005TCP6CS"
-	    "\006UDP4CS"
-	    "\007UDP6CS"
-	    "\010TSO4"
-	    "\011TSO6"
-	    "\012HASHVAL");
+	snprintf(caps_str, sizeof(caps_str), "%b", caps, HN_CAP_BITS);
 	return sysctl_handle_string(oidp, caps_str, sizeof(caps_str), req);
 }
 
@@ -2606,7 +2642,7 @@ hn_create_rx_data(struct hn_softc *sc, i
 	sc->hn_rx_ring_inuse = sc->hn_rx_ring_cnt;
 
 	sc->hn_rx_ring = malloc(sizeof(struct hn_rx_ring) * sc->hn_rx_ring_cnt,
-	    M_NETVSC, M_WAITOK | M_ZERO);
+	    M_DEVBUF, M_WAITOK | M_ZERO);
 
 #if defined(INET) || defined(INET6)
 #if __FreeBSD_version >= 1100095
@@ -2647,7 +2683,7 @@ hn_create_rx_data(struct hn_softc *sc, i
 		rxr->hn_ifp = sc->hn_ifp;
 		if (i < sc->hn_tx_ring_cnt)
 			rxr->hn_txr = &sc->hn_tx_ring[i];
-		rxr->hn_rdbuf = malloc(NETVSC_PACKET_SIZE, M_NETVSC, M_WAITOK);
+		rxr->hn_rdbuf = malloc(NETVSC_PACKET_SIZE, M_DEVBUF, M_WAITOK);
 		rxr->hn_rx_idx = i;
 		rxr->hn_rxbuf = sc->hn_rxbuf;
 
@@ -2794,9 +2830,9 @@ hn_destroy_rx_data(struct hn_softc *sc)
 #if defined(INET) || defined(INET6)
 		tcp_lro_free(&rxr->hn_lro);
 #endif
-		free(rxr->hn_rdbuf, M_NETVSC);
+		free(rxr->hn_rdbuf, M_DEVBUF);
 	}
-	free(sc->hn_rx_ring, M_NETVSC);
+	free(sc->hn_rx_ring, M_DEVBUF);
 	sc->hn_rx_ring = NULL;
 
 	sc->hn_rx_ring_cnt = 0;
@@ -2821,11 +2857,11 @@ hn_create_tx_ring(struct hn_softc *sc, i
 
 	txr->hn_txdesc_cnt = HN_TX_DESC_CNT;
 	txr->hn_txdesc = malloc(sizeof(struct hn_txdesc) * txr->hn_txdesc_cnt,
-	    M_NETVSC, M_WAITOK | M_ZERO);
+	    M_DEVBUF, M_WAITOK | M_ZERO);
 #ifndef HN_USE_TXDESC_BUFRING
 	SLIST_INIT(&txr->hn_txlist);
 #else
-	txr->hn_txdesc_br = buf_ring_alloc(txr->hn_txdesc_cnt, M_NETVSC,
+	txr->hn_txdesc_br = buf_ring_alloc(txr->hn_txdesc_cnt, M_DEVBUF,
 	    M_WAITOK, &txr->hn_tx_lock);
 #endif
 
@@ -2843,7 +2879,7 @@ hn_create_tx_ring(struct hn_softc *sc, i
 		TASK_INIT(&txr->hn_txeof_task, 0, hn_xmit_txeof_taskfunc, txr);
 
 		br_depth = hn_get_txswq_depth(txr);
-		txr->hn_mbuf_br = buf_ring_alloc(br_depth, M_NETVSC,
+		txr->hn_mbuf_br = buf_ring_alloc(br_depth, M_DEVBUF,
 		    M_WAITOK, &txr->hn_tx_lock);
 	}
 
@@ -3026,14 +3062,14 @@ hn_destroy_tx_ring(struct hn_tx_ring *tx
 		bus_dma_tag_destroy(txr->hn_tx_rndis_dtag);
 
 #ifdef HN_USE_TXDESC_BUFRING
-	buf_ring_free(txr->hn_txdesc_br, M_NETVSC);
+	buf_ring_free(txr->hn_txdesc_br, M_DEVBUF);
 #endif
 
-	free(txr->hn_txdesc, M_NETVSC);
+	free(txr->hn_txdesc, M_DEVBUF);
 	txr->hn_txdesc = NULL;
 
 	if (txr->hn_mbuf_br != NULL)
-		buf_ring_free(txr->hn_mbuf_br, M_NETVSC);
+		buf_ring_free(txr->hn_mbuf_br, M_DEVBUF);
 
 #ifndef HN_USE_TXDESC_BUFRING
 	mtx_destroy(&txr->hn_txlist_spin);
@@ -3065,7 +3101,7 @@ hn_create_tx_data(struct hn_softc *sc, i
 	sc->hn_tx_ring_inuse = sc->hn_tx_ring_cnt;
 
 	sc->hn_tx_ring = malloc(sizeof(struct hn_tx_ring) * sc->hn_tx_ring_cnt,
-	    M_NETVSC, M_WAITOK | M_ZERO);
+	    M_DEVBUF, M_WAITOK | M_ZERO);
 
 	ctx = device_get_sysctl_ctx(sc->hn_dev);
 	child = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->hn_dev));
@@ -3225,7 +3261,7 @@ hn_destroy_tx_data(struct hn_softc *sc)
 	for (i = 0; i < sc->hn_tx_ring_cnt; ++i)
 		hn_destroy_tx_ring(&sc->hn_tx_ring[i]);
 
-	free(sc->hn_tx_ring, M_NETVSC);
+	free(sc->hn_tx_ring, M_DEVBUF);
 	sc->hn_tx_ring = NULL;
 
 	sc->hn_tx_ring_cnt = 0;
@@ -3860,8 +3896,8 @@ hn_suspend_data(struct hn_softc *sc)
 	/*
 	 * Disable RX by clearing RX filter.
 	 */
-	hn_rndis_set_rxfilter(sc, 0);
-	sc->hn_rx_filter = 0;
+	sc->hn_rx_filter = NDIS_PACKET_TYPE_NONE;
+	hn_rndis_set_rxfilter(sc, sc->hn_rx_filter);
 
 	/*
 	 * Give RNDIS enough time to flush all pending data packets.
@@ -4175,12 +4211,12 @@ hn_chan_callback(struct vmbus_channel *c
 		} else if (ret == ENOBUFS) {
 			/* Handle large packet */
 			if (bufferlen > NETVSC_PACKET_SIZE) {
-				free(buffer, M_NETVSC);
+				free(buffer, M_DEVBUF);
 				buffer = NULL;
 			}
 
 			/* alloc new buffer */
-			buffer = malloc(bytes_rxed, M_NETVSC, M_NOWAIT);
+			buffer = malloc(bytes_rxed, M_DEVBUF, M_NOWAIT);
 			if (buffer == NULL) {
 				if_printf(rxr->hn_ifp,
 				    "hv_cb malloc buffer failed, len=%u\n",
@@ -4196,7 +4232,7 @@ hn_chan_callback(struct vmbus_channel *c
 	} while (1);
 
 	if (bufferlen > NETVSC_PACKET_SIZE)
-		free(buffer, M_NETVSC);
+		free(buffer, M_DEVBUF);
 
 	hv_rf_channel_rollup(rxr, rxr->hn_txr);
 }

Modified: stable/11/sys/dev/hyperv/netvsc/if_hnvar.h
==============================================================================
--- stable/11/sys/dev/hyperv/netvsc/if_hnvar.h	Mon Nov 14 03:07:48 2016	(r308622)
+++ stable/11/sys/dev/hyperv/netvsc/if_hnvar.h	Mon Nov 14 03:14:43 2016	(r308623)
@@ -94,9 +94,6 @@ hn_nvs_send_sglist(struct vmbus_channel 
 struct vmbus_xact;
 struct rndis_packet_msg;
 
-uint32_t	hn_chim_alloc(struct hn_softc *sc);
-void		hn_chim_free(struct hn_softc *sc, uint32_t chim_idx);
-
 int		hn_rndis_attach(struct hn_softc *sc, int mtu);
 void		hn_rndis_detach(struct hn_softc *sc);
 int		hn_rndis_conf_rss(struct hn_softc *sc, uint16_t flags);
@@ -106,7 +103,7 @@ int		hn_rndis_query_rsscaps(struct hn_so
 int		hn_rndis_get_eaddr(struct hn_softc *sc, uint8_t *eaddr);
 int		hn_rndis_get_linkstatus(struct hn_softc *sc,
 		    uint32_t *link_status);
-/* filter: NDIS_PACKET_TYPE_ or 0. */
+/* filter: NDIS_PACKET_TYPE_. */
 int		hn_rndis_set_rxfilter(struct hn_softc *sc, uint32_t filter);
 
 int		hn_nvs_attach(struct hn_softc *sc, int mtu);

Modified: stable/11/sys/net/rndis.h
==============================================================================
--- stable/11/sys/net/rndis.h	Mon Nov 14 03:07:48 2016	(r308622)
+++ stable/11/sys/net/rndis.h	Mon Nov 14 03:14:43 2016	(r308623)
@@ -352,6 +352,7 @@ struct rndis_keepalive_comp {
 };
 
 /* Packet filter bits used by OID_GEN_CURRENT_PACKET_FILTER */
+#define	NDIS_PACKET_TYPE_NONE			0x00000000
 #define	NDIS_PACKET_TYPE_DIRECTED		0x00000001
 #define	NDIS_PACKET_TYPE_MULTICAST		0x00000002
 #define	NDIS_PACKET_TYPE_ALL_MULTICAST		0x00000004



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201611140314.uAE3Eh0q049046>