Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Oct 2016 06:47:02 +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-10@freebsd.org
Subject:   svn commit: r307186 - stable/10/sys/dev/hyperv/netvsc
Message-ID:  <201610130647.u9D6l2Jp000140@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sephe
Date: Thu Oct 13 06:47:02 2016
New Revision: 307186
URL: https://svnweb.freebsd.org/changeset/base/307186

Log:
  MFC 305052-305054,305110
  
  305052
      hyperv/hn: Remove the useless rndis_device and related bits
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7687
  
  305053
      hyperv/hn: Log packet message alignment.
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7689
  
  305054
      hyperv/hn: Remove unnecessary NULL check.
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7690
  
  305110
      hyperv/hn: Consolidate NVS transaction execution.
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7704

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

Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c
==============================================================================
--- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c	Thu Oct 13 06:39:06 2016	(r307185)
+++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c	Thu Oct 13 06:47:02 2016	(r307186)
@@ -106,21 +106,45 @@ hn_chim_alloc(struct hn_softc *sc)
 
 const void *
 hn_nvs_xact_execute(struct hn_softc *sc, struct vmbus_xact *xact,
-    void *req, int reqlen, size_t *resp_len)
+    void *req, int reqlen, size_t *resplen0, uint32_t type)
 {
 	struct hn_send_ctx sndc;
+	size_t resplen, min_resplen = *resplen0;
+	const struct hn_nvs_hdr *hdr;
 	int error;
 
+	KASSERT(min_resplen >= sizeof(*hdr),
+	    ("invalid minimum response len %zu", min_resplen));
+
+	/*
+	 * Execute the xact setup by the caller.
+	 */
 	hn_send_ctx_init_simple(&sndc, hn_nvs_sent_xact, xact);
-	vmbus_xact_activate(xact);
 
+	vmbus_xact_activate(xact);
 	error = hn_nvs_send(sc->hn_prichan, VMBUS_CHANPKT_FLAG_RC,
 	    req, reqlen, &sndc);
 	if (error) {
 		vmbus_xact_deactivate(xact);
-		return NULL;
+		return (NULL);
 	}
-	return (vmbus_xact_wait(xact, resp_len));
+	hdr = vmbus_xact_wait(xact, &resplen);
+
+	/*
+	 * Check this NVS response message.
+	 */
+	if (resplen < min_resplen) {
+		if_printf(sc->hn_ifp, "invalid NVS resp len %zu\n", resplen);
+		return (NULL);
+	}
+	if (hdr->nvs_type != type) {
+		if_printf(sc->hn_ifp, "unexpected NVS resp 0x%08x, "
+		    "expect 0x%08x\n", hdr->nvs_type, type);
+		return (NULL);
+	}
+	/* All pass! */
+	*resplen0 = resplen;
+	return (hdr);
 }
 
 static __inline int
@@ -180,24 +204,14 @@ hv_nv_init_rx_buffer_with_net_vsp(struct
 	conn->nvs_gpadl = sc->hn_rxbuf_gpadl;
 	conn->nvs_sig = HN_NVS_RXBUF_SIG;
 
-	resp = hn_nvs_xact_execute(sc, xact, conn, sizeof(*conn), &resp_len);
+	resp_len = sizeof(*resp);
+	resp = hn_nvs_xact_execute(sc, xact, conn, sizeof(*conn), &resp_len,
+	    HN_NVS_TYPE_RXBUF_CONNRESP);
 	if (resp == NULL) {
 		if_printf(sc->hn_ifp, "exec rxbuf conn failed\n");
 		error = EIO;
 		goto cleanup;
 	}
-	if (resp_len < sizeof(*resp)) {
-		if_printf(sc->hn_ifp, "invalid rxbuf conn resp length %zu\n",
-		    resp_len);
-		error = EINVAL;
-		goto cleanup;
-	}
-	if (resp->nvs_type != HN_NVS_TYPE_RXBUF_CONNRESP) {
-		if_printf(sc->hn_ifp, "not rxbuf conn resp, type %u\n",
-		    resp->nvs_type);
-		error = EINVAL;
-		goto cleanup;
-	}
 
 	status = resp->nvs_status;
 	vmbus_xact_put(xact);
@@ -263,24 +277,14 @@ hv_nv_init_send_buffer_with_net_vsp(stru
 	chim->nvs_gpadl = sc->hn_chim_gpadl;
 	chim->nvs_sig = HN_NVS_CHIM_SIG;
 
-	resp = hn_nvs_xact_execute(sc, xact, chim, sizeof(*chim), &resp_len);
+	resp_len = sizeof(*resp);
+	resp = hn_nvs_xact_execute(sc, xact, chim, sizeof(*chim), &resp_len,
+	    HN_NVS_TYPE_CHIM_CONNRESP);
 	if (resp == NULL) {
 		if_printf(sc->hn_ifp, "exec chim conn failed\n");
 		error = EIO;
 		goto cleanup;
 	}
-	if (resp_len < sizeof(*resp)) {
-		if_printf(sc->hn_ifp, "invalid chim conn resp length %zu\n",
-		    resp_len);
-		error = EINVAL;
-		goto cleanup;
-	}
-	if (resp->nvs_type != HN_NVS_TYPE_CHIM_CONNRESP) {
-		if_printf(sc->hn_ifp, "not chim conn resp, type %u\n",
-		    resp->nvs_type);
-		error = EINVAL;
-		goto cleanup;
-	}
 
 	status = resp->nvs_status;
 	sectsz = resp->nvs_sectsz;
@@ -441,24 +445,14 @@ hv_nv_negotiate_nvsp_protocol(struct hn_
 	init->nvs_ver_min = nvs_ver;
 	init->nvs_ver_max = nvs_ver;
 
-	resp = hn_nvs_xact_execute(sc, xact, init, sizeof(*init), &resp_len);
+	resp_len = sizeof(*resp);
+	resp = hn_nvs_xact_execute(sc, xact, init, sizeof(*init), &resp_len,
+	    HN_NVS_TYPE_INIT_RESP);
 	if (resp == NULL) {
 		if_printf(sc->hn_ifp, "exec init failed\n");
 		vmbus_xact_put(xact);
 		return (EIO);
 	}
-	if (resp_len < sizeof(*resp)) {
-		if_printf(sc->hn_ifp, "invalid init resp length %zu\n",
-		    resp_len);
-		vmbus_xact_put(xact);
-		return (EINVAL);
-	}
-	if (resp->nvs_type != HN_NVS_TYPE_INIT_RESP) {
-		if_printf(sc->hn_ifp, "not init resp, type %u\n",
-		    resp->nvs_type);
-		vmbus_xact_put(xact);
-		return (EINVAL);
-	}
 
 	status = resp->nvs_status;
 	vmbus_xact_put(xact);
@@ -640,7 +634,7 @@ cleanup:
  * Net VSC on device remove
  */
 int
-hv_nv_on_device_remove(struct hn_softc *sc, boolean_t destroy_channel)
+hv_nv_on_device_remove(struct hn_softc *sc)
 {
 	
 	hv_nv_disconnect_from_vsp(sc);

Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h
==============================================================================
--- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h	Thu Oct 13 06:39:06 2016	(r307185)
+++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h	Thu Oct 13 06:47:02 2016	(r307186)
@@ -237,8 +237,8 @@ typedef void (*pfn_on_send_rx_completion
 #define TRANSPORT_TYPE_IPV6_UDP		((TYPE_IPV6 << 16) | TYPE_UDP)
 
 typedef struct {
-	uint8_t		mac_addr[6];  /* Assumption unsigned long */
-	uint8_t		link_state;
+	uint8_t		mac_addr[ETHER_ADDR_LEN];
+	uint32_t	link_state;
 } netvsc_device_info;
 
 #define HN_XACT_REQ_PGCNT		2
@@ -352,7 +352,6 @@ typedef struct hn_softc {
 	int             hn_initdone;
 	/* See hv_netvsc_drv_freebsd.c for rules on how to use */
 	int             temp_unusable;
-	struct rndis_device_ *rndis_dev;
 	struct vmbus_channel *hn_prichan;
 
 	int		hn_rx_ring_cnt;
@@ -401,8 +400,7 @@ struct hn_send_ctx;
 
 void netvsc_linkstatus_callback(struct hn_softc *sc, uint32_t status);
 int hv_nv_on_device_add(struct hn_softc *sc, struct hn_rx_ring *rxr);
-int hv_nv_on_device_remove(struct hn_softc *sc,
-    boolean_t destroy_channel);
+int hv_nv_on_device_remove(struct hn_softc *sc);
 int hv_nv_on_send(struct vmbus_channel *chan, uint32_t rndis_mtype,
 	struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt);
 void hv_nv_subchan_attach(struct vmbus_channel *chan,

Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
==============================================================================
--- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c	Thu Oct 13 06:39:06 2016	(r307185)
+++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c	Thu Oct 13 06:47:02 2016	(r307186)
@@ -156,8 +156,8 @@ __FBSDID("$FreeBSD$");
 #define HN_TX_DATA_BOUNDARY		PAGE_SIZE
 #define HN_TX_DATA_MAXSIZE		IP_MAXPACKET
 #define HN_TX_DATA_SEGSIZE		PAGE_SIZE
-#define HN_TX_DATA_SEGCNT_MAX		\
-    (NETVSC_PACKET_MAXPAGE - HV_RF_NUM_TX_RESERVED_PAGE_BUFS)
+/* -1 for RNDIS packet message */
+#define HN_TX_DATA_SEGCNT_MAX		(NETVSC_PACKET_MAXPAGE - 1)
 
 #define HN_DIRECT_TX_SIZE_DEF		128
 
@@ -663,7 +663,7 @@ netvsc_detach(device_t dev)
 	 * the netdevice.
 	 */
 
-	hv_rf_on_device_remove(sc, HV_RF_NV_DESTROY_CHANNEL);
+	hv_rf_on_device_remove(sc);
 
 	hn_stop_tx_tasks(sc);
 
@@ -1047,7 +1047,8 @@ hn_encap(struct hn_tx_ring *txr, struct 
 	}
 	*m_head0 = m_head;
 
-	txr->hn_gpa_cnt = nsegs + HV_RF_NUM_TX_RESERVED_PAGE_BUFS;
+	/* +1 RNDIS packet message */
+	txr->hn_gpa_cnt = nsegs + 1;
 
 	/* send packet with page buffer */
 	txr->hn_gpa[0].gpa_page = atop(txd->rndis_msg_paddr);
@@ -1055,12 +1056,11 @@ hn_encap(struct hn_tx_ring *txr, struct 
 	txr->hn_gpa[0].gpa_len = rndis_msg_size;
 
 	/*
-	 * Fill the page buffers with mbuf info starting at index
-	 * HV_RF_NUM_TX_RESERVED_PAGE_BUFS.
+	 * Fill the page buffers with mbuf info after the page
+	 * buffer for RNDIS packet message.
 	 */
 	for (i = 0; i < nsegs; ++i) {
-		struct vmbus_gpa *gpa = &txr->hn_gpa[
-		    i + HV_RF_NUM_TX_RESERVED_PAGE_BUFS];
+		struct vmbus_gpa *gpa = &txr->hn_gpa[i + 1];
 
 		gpa->gpa_page = atop(segs[i].ds_addr);
 		gpa->gpa_ofs = segs[i].ds_addr & PAGE_MASK;
@@ -1594,7 +1594,7 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, 
 		 * MTU to take effect.  This includes tearing down, but not
 		 * deleting the channel, then bringing it back up.
 		 */
-		error = hv_rf_on_device_remove(sc, HV_RF_NV_RETAIN_CHANNEL);
+		error = hv_rf_on_device_remove(sc);
 		if (error) {
 			NV_LOCK(sc);
 			sc->temp_unusable = FALSE;

Modified: stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c
==============================================================================
--- stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c	Thu Oct 13 06:39:06 2016	(r307185)
+++ stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c	Thu Oct 13 06:47:02 2016	(r307186)
@@ -72,15 +72,14 @@ __FBSDID("$FreeBSD$");
 /*
  * Forward declarations
  */
-static void hv_rf_receive_response(rndis_device *device,
-    const rndis_msg *response);
-static void hv_rf_receive_indicate_status(rndis_device *device,
+static void hv_rf_receive_indicate_status(struct hn_softc *sc,
     const rndis_msg *response);
 static void hv_rf_receive_data(struct hn_rx_ring *rxr,
     const void *data, int dlen);
-static inline int hv_rf_query_device_mac(rndis_device *device);
-static inline int hv_rf_query_device_link_status(rndis_device *device);
-static int  hv_rf_init_device(rndis_device *device);
+static int hv_rf_query_device_mac(struct hn_softc *sc, uint8_t *eaddr);
+static int hv_rf_query_device_link_status(struct hn_softc *sc,
+    uint32_t *link_status);
+static int  hv_rf_init_device(struct hn_softc *sc);
 
 static int hn_rndis_query(struct hn_softc *sc, uint32_t oid,
     const void *idata, size_t idlen, void *odata, size_t *odlen0);
@@ -158,94 +157,24 @@ hv_get_ppi_data(rndis_packet *rpkt, uint
 	return (NULL);
 }
 
-
-/*
- * Allow module_param to work and override to switch to promiscuous mode.
- */
-static inline rndis_device *
-hv_get_rndis_device(void)
-{
-	rndis_device *device;
-
-	device = malloc(sizeof(rndis_device), M_NETVSC, M_WAITOK | M_ZERO);
-
-	mtx_init(&device->req_lock, "HV-FRL", NULL, MTX_DEF);
-
-	/* Same effect as STAILQ_HEAD_INITIALIZER() static initializer */
-	STAILQ_INIT(&device->myrequest_list);
-
-	device->state = RNDIS_DEV_UNINITIALIZED;
-
-	return (device);
-}
-
-/*
- *
- */
-static inline void
-hv_put_rndis_device(rndis_device *device)
-{
-	mtx_destroy(&device->req_lock);
-	free(device, M_NETVSC);
-}
-
-/*
- * RNDIS filter receive response
- */
-static void 
-hv_rf_receive_response(rndis_device *device, const rndis_msg *response)
-{
-	rndis_request *request = NULL;
-	rndis_request *next_request;
-	boolean_t found = FALSE;
-
-	mtx_lock(&device->req_lock);
-	request = STAILQ_FIRST(&device->myrequest_list);
-	while (request != NULL) {
-		/*
-		 * All request/response message contains request_id as the
-		 * first field
-		 */
-		if (request->request_msg.msg.init_request.request_id ==
-				      response->msg.init_complete.request_id) {
-			found = TRUE;
-			break;
-		}
-		next_request = STAILQ_NEXT(request, mylist_entry);
-		request = next_request;
-	}
-	mtx_unlock(&device->req_lock);
-
-	if (found) {
-		if (response->msg_len <= sizeof(rndis_msg)) {
-			memcpy(&request->response_msg, response,
-			    response->msg_len);
-		} else {
-			request->response_msg.msg.init_complete.status =
-			    RNDIS_STATUS_BUFFER_OVERFLOW;
-		}
-		sema_post(&request->wait_sema);
-	}
-}
-
 /*
  * RNDIS filter receive indicate status
  */
 static void 
-hv_rf_receive_indicate_status(rndis_device *device, const rndis_msg *response)
+hv_rf_receive_indicate_status(struct hn_softc *sc, const rndis_msg *response)
 {
 	const rndis_indicate_status *indicate = &response->msg.indicate_status;
 		
 	switch(indicate->status) {
 	case RNDIS_STATUS_MEDIA_CONNECT:
-		netvsc_linkstatus_callback(device->sc, 1);
+		netvsc_linkstatus_callback(sc, 1);
 		break;
 	case RNDIS_STATUS_MEDIA_DISCONNECT:
-		netvsc_linkstatus_callback(device->sc, 0);
+		netvsc_linkstatus_callback(sc, 0);
 		break;
 	default:
 		/* TODO: */
-		device_printf(device->sc->hn_dev,
+		if_printf(sc->hn_ifp,
 		    "unknown status %d received\n", indicate->status);
 		break;
 	}
@@ -375,14 +304,9 @@ int
 hv_rf_on_receive(struct hn_softc *sc, struct hn_rx_ring *rxr,
     const void *data, int dlen)
 {
-	rndis_device *rndis_dev;
 	const rndis_msg *rndis_hdr;
 	const struct rndis_comp_hdr *comp;
 
-	rndis_dev = sc->rndis_dev;
-	if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED)
-		return (EINVAL);
-
 	rndis_hdr = data;
 	switch (rndis_hdr->ndis_msg_type) {
 	/* data message */
@@ -396,17 +320,14 @@ hv_rf_on_receive(struct hn_softc *sc, st
 	case REMOTE_NDIS_SET_CMPLT:
 	case REMOTE_NDIS_KEEPALIVE_CMPLT:
 		comp = data;
-		if (comp->rm_rid <= HN_RNDIS_RID_COMPAT_MAX) {
-			/* Transition time compat code */
-			hv_rf_receive_response(rndis_dev, rndis_hdr);
-		} else {
-			vmbus_xact_ctx_wakeup(sc->hn_xact, data, dlen);
-		}
+		KASSERT(comp->rm_rid > HN_RNDIS_RID_COMPAT_MAX,
+		    ("invalid rid 0x%08x\n", comp->rm_rid));
+		vmbus_xact_ctx_wakeup(sc->hn_xact, comp, dlen);
 		break;
 
 	/* notification message */
 	case REMOTE_NDIS_INDICATE_STATUS_MSG:
-		hv_rf_receive_indicate_status(rndis_dev, rndis_hdr);
+		hv_rf_receive_indicate_status(sc, rndis_hdr);
 		break;
 
 	case REMOTE_NDIS_RESET_CMPLT:
@@ -432,19 +353,18 @@ hv_rf_on_receive(struct hn_softc *sc, st
  * RNDIS filter query device MAC address
  */
 static int
-hv_rf_query_device_mac(rndis_device *device)
+hv_rf_query_device_mac(struct hn_softc *sc, uint8_t *eaddr)
 {
-	struct hn_softc *sc = device->sc;
-	size_t hwaddr_len;
+	size_t eaddr_len;
 	int error;
 
-	hwaddr_len = ETHER_ADDR_LEN;
+	eaddr_len = ETHER_ADDR_LEN;
 	error = hn_rndis_query(sc, OID_802_3_PERMANENT_ADDRESS, NULL, 0,
-	    device->hw_mac_addr, &hwaddr_len);
+	    eaddr, &eaddr_len);
 	if (error)
 		return (error);
-	if (hwaddr_len != ETHER_ADDR_LEN) {
-		if_printf(sc->hn_ifp, "invalid hwaddr len %zu\n", hwaddr_len);
+	if (eaddr_len != ETHER_ADDR_LEN) {
+		if_printf(sc->hn_ifp, "invalid eaddr len %zu\n", eaddr_len);
 		return (EINVAL);
 	}
 	return (0);
@@ -453,16 +373,15 @@ hv_rf_query_device_mac(rndis_device *dev
 /*
  * RNDIS filter query device link status
  */
-static inline int
-hv_rf_query_device_link_status(rndis_device *device)
+static int
+hv_rf_query_device_link_status(struct hn_softc *sc, uint32_t *link_status)
 {
-	struct hn_softc *sc = device->sc;
 	size_t size;
 	int error;
 
-	size = sizeof(uint32_t);
+	size = sizeof(*link_status);
 	error = hn_rndis_query(sc, OID_GEN_MEDIA_CONNECT_STATUS, NULL, 0,
-	    &device->link_status, &size);
+	    link_status, &size);
 	if (error)
 		return (error);
 	if (size != sizeof(uint32_t)) {
@@ -876,9 +795,8 @@ hn_rndis_set_rxfilter(struct hn_softc *s
  * RNDIS filter init device
  */
 static int
-hv_rf_init_device(rndis_device *device)
+hv_rf_init_device(struct hn_softc *sc)
 {
-	struct hn_softc *sc = device->sc;
 	struct rndis_init_req *req;
 	const struct rndis_init_comp *comp;
 	struct vmbus_xact *xact;
@@ -886,9 +804,6 @@ hv_rf_init_device(rndis_device *device)
 	uint32_t rid;
 	int error;
 
-	/* XXX */
-	device->state = RNDIS_DEV_INITIALIZED;
-
 	xact = vmbus_xact_get(sc->hn_xact, sizeof(*req));
 	if (xact == NULL) {
 		if_printf(sc->hn_ifp, "no xact for RNDIS init\n");
@@ -919,15 +834,14 @@ hv_rf_init_device(rndis_device *device)
 		goto done;
 	}
 	if (bootverbose) {
-		if_printf(sc->hn_ifp, "RNDIS ver %u.%u, pktsz %u, pktcnt %u\n",
-		    comp->rm_ver_major, comp->rm_ver_minor,
-		    comp->rm_pktmaxsz, comp->rm_pktmaxcnt);
+		if_printf(sc->hn_ifp, "RNDIS ver %u.%u, pktsz %u, pktcnt %u, "
+		    "align %u\n", comp->rm_ver_major, comp->rm_ver_minor,
+		    comp->rm_pktmaxsz, comp->rm_pktmaxcnt,
+		    1U << comp->rm_align);
 	}
 	error = 0;
-
 done:
-	if (xact != NULL)
-		vmbus_xact_put(xact);
+	vmbus_xact_put(xact);
 	return (error);
 }
 
@@ -970,7 +884,6 @@ hv_rf_on_device_add(struct hn_softc *sc,
     int *nchan0, struct hn_rx_ring *rxr)
 {
 	int ret;
-	rndis_device *rndis_dev;
 	netvsc_device_info *dev_info = (netvsc_device_info *)additl_info;
 	device_t dev = sc->hn_dev;
 	struct hn_nvs_subch_req *req;
@@ -981,13 +894,6 @@ hv_rf_on_device_add(struct hn_softc *sc,
 	int nchan = *nchan0;
 	int rxr_cnt;
 
-	rndis_dev = hv_get_rndis_device();
-	if (rndis_dev == NULL) {
-		return (ENOMEM);
-	}
-	sc->rndis_dev = rndis_dev;
-	rndis_dev->sc = sc;
-
 	/*
 	 * Let the inner driver handle this first to create the netvsc channel
 	 * NOTE! Once the channel is created, we may get a receive callback 
@@ -995,17 +901,15 @@ hv_rf_on_device_add(struct hn_softc *sc,
 	 * Note:  Earlier code used a function pointer here.
 	 */
 	ret = hv_nv_on_device_add(sc, rxr);
-	if (ret != 0) {
-		hv_put_rndis_device(rndis_dev);
+	if (ret != 0)
 		return (ret);
-	}
 
 	/*
 	 * Initialize the rndis device
 	 */
 
 	/* Send the rndis initialization message */
-	ret = hv_rf_init_device(rndis_dev);
+	ret = hv_rf_init_device(sc);
 	if (ret != 0) {
 		/*
 		 * TODO: If rndis init failed, we will need to shut down
@@ -1014,19 +918,15 @@ hv_rf_on_device_add(struct hn_softc *sc,
 	}
 
 	/* Get the mac address */
-	ret = hv_rf_query_device_mac(rndis_dev);
+	ret = hv_rf_query_device_mac(sc, dev_info->mac_addr);
 	if (ret != 0) {
 		/* TODO: shut down rndis device and the channel */
 	}
 
 	/* Configure NDIS offload settings */
 	hn_rndis_conf_offload(sc);
-	
-	memcpy(dev_info->mac_addr, rndis_dev->hw_mac_addr, ETHER_ADDR_LEN);
 
-	hv_rf_query_device_link_status(rndis_dev);
-	
-	dev_info->link_state = rndis_dev->link_status;
+	hv_rf_query_device_link_status(sc, &dev_info->link_state);
 
 	if (sc->hn_ndis_ver < NDIS_VERSION_6_30 || nchan == 1) {
 		/*
@@ -1071,24 +971,14 @@ hv_rf_on_device_add(struct hn_softc *sc,
 	req->nvs_op = HN_NVS_SUBCH_OP_ALLOC;
 	req->nvs_nsubch = nchan - 1;
 
-	resp = hn_nvs_xact_execute(sc, xact, req, sizeof(*req), &resp_len);
+	resp_len = sizeof(*resp);
+	resp = hn_nvs_xact_execute(sc, xact, req, sizeof(*req), &resp_len,
+	    HN_NVS_TYPE_SUBCH_RESP);
 	if (resp == NULL) {
 		if_printf(sc->hn_ifp, "exec subch failed\n");
 		ret = EIO;
 		goto out;
 	}
-	if (resp_len < sizeof(*resp)) {
-		if_printf(sc->hn_ifp, "invalid subch resp length %zu\n",
-		    resp_len);
-		ret = EINVAL;
-		goto out;
-	}
-	if (resp->nvs_type != HN_NVS_TYPE_SUBCH_RESP) {
-		if_printf(sc->hn_ifp, "not subch resp, type %u\n",
-		    resp->nvs_type);
-		ret = EINVAL;
-		goto out;
-	}
 
 	status = resp->nvs_status;
 	nsubch = resp->nvs_nsubch;
@@ -1122,19 +1012,15 @@ out:
  * RNDIS filter on device remove
  */
 int
-hv_rf_on_device_remove(struct hn_softc *sc, boolean_t destroy_channel)
+hv_rf_on_device_remove(struct hn_softc *sc)
 {
-	rndis_device *rndis_dev = sc->rndis_dev;
 	int ret;
 
 	/* Halt and release the rndis device */
 	ret = hv_rf_halt_device(sc);
 
-	sc->rndis_dev = NULL;
-	hv_put_rndis_device(rndis_dev);
-
 	/* Pass control to inner driver to remove the device */
-	ret |= hv_nv_on_device_remove(sc, destroy_channel);
+	ret |= hv_nv_on_device_remove(sc);
 
 	return (ret);
 }

Modified: stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.h
==============================================================================
--- stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.h	Thu Oct 13 06:39:06 2016	(r307185)
+++ stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.h	Thu Oct 13 06:47:02 2016	(r307186)
@@ -36,80 +36,6 @@
 #include <dev/hyperv/netvsc/if_hnvar.h>
 
 /*
- * Defines
- */
-
-/* Destroy or preserve channel on filter/netvsc teardown */
-#define HV_RF_NV_DESTROY_CHANNEL	TRUE
-#define HV_RF_NV_RETAIN_CHANNEL		FALSE
-
-/*
- * Number of page buffers to reserve for the RNDIS filter packet in the
- * transmitted message.
- */
-#define HV_RF_NUM_TX_RESERVED_PAGE_BUFS	1
-
-
-/*
- * Data types
- */
-
-typedef enum {
-	RNDIS_DEV_UNINITIALIZED = 0,
-	RNDIS_DEV_INITIALIZING,
-	RNDIS_DEV_INITIALIZED,
-	RNDIS_DEV_DATAINITIALIZED,
-} rndis_device_state;
-
-typedef struct rndis_request_ {
-	STAILQ_ENTRY(rndis_request_)	mylist_entry;
-	struct sema			wait_sema;	
-
-	/*
-	 * The max response size is sizeof(rndis_msg) + PAGE_SIZE.
-	 *
-	 * XXX
-	 * This is ugly and should be cleaned up once we busdma-fy
-	 * RNDIS request bits.
-	 */
-	rndis_msg			response_msg;
-	uint8_t				buf_resp[PAGE_SIZE];
-
-	/* Simplify allocation by having a netvsc packet inline */
-	struct hn_send_ctx		send_ctx;
-
-	/*
-	 * The max request size is sizeof(rndis_msg) + PAGE_SIZE.
-	 *
-	 * NOTE:
-	 * This is required for the large request like RSS settings.
-	 *
-	 * XXX
-	 * This is ugly and should be cleaned up once we busdma-fy
-	 * RNDIS request bits.
-	 */
-	rndis_msg			request_msg;
-	uint8_t				buf_req[PAGE_SIZE];
-
-	/* Fixme:  Poor man's semaphore. */
-	uint32_t			halt_complete_flag;
-} rndis_request;
-
-typedef struct rndis_device_ {
-	struct hn_softc			*sc;
-
-	rndis_device_state		state;
-	uint32_t			link_status;
-	uint32_t			new_request_id;
-
-	struct mtx			req_lock;
-
-	STAILQ_HEAD(RQ, rndis_request_)	myrequest_list;
-
-	uint8_t				hw_mac_addr[ETHER_ADDR_LEN];
-} rndis_device;
-
-/*
  * Externs
  */
 struct hn_rx_ring;
@@ -119,7 +45,7 @@ int hv_rf_on_receive(struct hn_softc *sc
 void hv_rf_channel_rollup(struct hn_rx_ring *rxr, struct hn_tx_ring *txr);
 int hv_rf_on_device_add(struct hn_softc *sc, void *additl_info, int *nchan,
     struct hn_rx_ring *rxr);
-int hv_rf_on_device_remove(struct hn_softc *sc, boolean_t destroy_channel);
+int hv_rf_on_device_remove(struct hn_softc *sc);
 int hv_rf_on_open(struct hn_softc *sc);
 int hv_rf_on_close(struct hn_softc *sc);
 

Modified: stable/10/sys/dev/hyperv/netvsc/if_hnvar.h
==============================================================================
--- stable/10/sys/dev/hyperv/netvsc/if_hnvar.h	Thu Oct 13 06:39:06 2016	(r307185)
+++ stable/10/sys/dev/hyperv/netvsc/if_hnvar.h	Thu Oct 13 06:47:02 2016	(r307186)
@@ -111,7 +111,7 @@ struct vmbus_xact;
 
 const void	*hn_nvs_xact_execute(struct hn_softc *sc,
 		    struct vmbus_xact *xact, void *req, int reqlen,
-		    size_t *resp_len);
+		    size_t *resp_len, uint32_t type);
 void		hn_nvs_sent_xact(struct hn_send_ctx *sndc, struct hn_softc *sc,
 		    struct vmbus_channel *chan, const void *data, int dlen);
 uint32_t	hn_chim_alloc(struct hn_softc *sc);



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