svn commit: r307472 - stable/11/sys/dev/hyperv/utilities

Sepherosa Ziehau sephe at FreeBSD.org
Mon Oct 17 05:33:43 UTC 2016


Author: sephe
Date: Mon Oct 17 05:33:41 2016
New Revision: 307472
URL: https://svnweb.freebsd.org/changeset/base/307472

Log:
  MFC 303822-303824
  
  303822
      hyperv/ic: Remove never used second parameter of hv_negotiate_version()
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7422
  
  303823
      hyperv/ic: Expose the receive buffer length for callers to use.
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7423
  
  303824
      hyperv/ic: Pass the channel callback to hv_util_attach()
  
      The saved channel callback in util softc is actually never used.
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7424

Modified:
  stable/11/sys/dev/hyperv/utilities/hv_heartbeat.c
  stable/11/sys/dev/hyperv/utilities/hv_kvp.c
  stable/11/sys/dev/hyperv/utilities/hv_shutdown.c
  stable/11/sys/dev/hyperv/utilities/hv_timesync.c
  stable/11/sys/dev/hyperv/utilities/hv_util.c
  stable/11/sys/dev/hyperv/utilities/hv_util.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/hyperv/utilities/hv_heartbeat.c
==============================================================================
--- stable/11/sys/dev/hyperv/utilities/hv_heartbeat.c	Mon Oct 17 05:28:06 2016	(r307471)
+++ stable/11/sys/dev/hyperv/utilities/hv_heartbeat.c	Mon Oct 17 05:33:41 2016	(r307472)
@@ -64,7 +64,7 @@ hv_heartbeat_cb(struct vmbus_channel *ch
 	softc = (hv_util_sc*)context;
 	buf = softc->receive_buffer;
 
-	recvlen = PAGE_SIZE;
+	recvlen = softc->ic_buflen;
 	ret = vmbus_chan_recv(channel, buf, &recvlen, &requestid);
 	KASSERT(ret != ENOBUFS, ("hvheartbeat recvbuf is not large enough"));
 	/* XXX check recvlen to make sure that it contains enough data */
@@ -75,8 +75,7 @@ hv_heartbeat_cb(struct vmbus_channel *ch
 		&buf[sizeof(struct hv_vmbus_pipe_hdr)];
 
 	    if (icmsghdrp->icmsgtype == HV_ICMSGTYPE_NEGOTIATE) {
-		hv_negotiate_version(icmsghdrp, NULL, buf);
-
+		hv_negotiate_version(icmsghdrp, buf);
 	    } else {
 		heartbeat_msg =
 		    (struct hv_vmbus_heartbeat_msg_data *)
@@ -110,11 +109,7 @@ hv_heartbeat_probe(device_t dev)
 static int
 hv_heartbeat_attach(device_t dev)
 {
-	hv_util_sc *softc = (hv_util_sc*)device_get_softc(dev);
-
-	softc->callback = hv_heartbeat_cb;
-
-	return hv_util_attach(dev);
+	return hv_util_attach(dev, hv_heartbeat_cb);
 }
 
 static device_method_t heartbeat_methods[] = {

Modified: stable/11/sys/dev/hyperv/utilities/hv_kvp.c
==============================================================================
--- stable/11/sys/dev/hyperv/utilities/hv_kvp.c	Mon Oct 17 05:28:06 2016	(r307471)
+++ stable/11/sys/dev/hyperv/utilities/hv_kvp.c	Mon Oct 17 05:33:41 2016	(r307472)
@@ -629,7 +629,7 @@ hv_kvp_process_request(void *context, in
 	kvp_buf = sc->util_sc.receive_buffer;
 	channel = vmbus_get_channel(sc->dev);
 
-	recvlen = 2 * PAGE_SIZE;
+	recvlen = sc->util_sc.ic_buflen;
 	ret = vmbus_chan_recv(channel, kvp_buf, &recvlen, &requestid);
 	KASSERT(ret != ENOBUFS, ("hvkvp recvbuf is not large enough"));
 	/* XXX check recvlen to make sure that it contains enough data */
@@ -696,7 +696,7 @@ hv_kvp_process_request(void *context, in
 		/*
 		 * Try reading next buffer
 		 */
-		recvlen = 2 * PAGE_SIZE;
+		recvlen = sc->util_sc.ic_buflen;
 		ret = vmbus_chan_recv(channel, kvp_buf, &recvlen, &requestid);
 		KASSERT(ret != ENOBUFS, ("hvkvp recvbuf is not large enough"));
 		/* XXX check recvlen to make sure that it contains enough data */
@@ -892,7 +892,6 @@ hv_kvp_attach(device_t dev)
 
 	hv_kvp_sc *sc = (hv_kvp_sc*)device_get_softc(dev);
 
-	sc->util_sc.callback = hv_kvp_callback;
 	sc->dev = dev;
 	sema_init(&sc->dev_sema, 0, "hv_kvp device semaphore");
 	mtx_init(&sc->pending_mutex, "hv-kvp pending mutex",
@@ -920,7 +919,7 @@ hv_kvp_attach(device_t dev)
 		return (error);
 	sc->hv_kvp_dev->si_drv1 = sc;
 
-	return hv_util_attach(dev);
+	return hv_util_attach(dev, hv_kvp_callback);
 }
 
 static int

Modified: stable/11/sys/dev/hyperv/utilities/hv_shutdown.c
==============================================================================
--- stable/11/sys/dev/hyperv/utilities/hv_shutdown.c	Mon Oct 17 05:28:06 2016	(r307471)
+++ stable/11/sys/dev/hyperv/utilities/hv_shutdown.c	Mon Oct 17 05:33:41 2016	(r307472)
@@ -68,7 +68,7 @@ hv_shutdown_cb(struct vmbus_channel *cha
 	softc = (hv_util_sc*)context;
 	buf = softc->receive_buffer;
 
-	recv_len = PAGE_SIZE;
+	recv_len = softc->ic_buflen;
 	ret = vmbus_chan_recv(channel, buf, &recv_len, &request_id);
 	KASSERT(ret != ENOBUFS, ("hvshutdown recvbuf is not large enough"));
 	/* XXX check recv_len to make sure that it contains enough data */
@@ -79,8 +79,7 @@ hv_shutdown_cb(struct vmbus_channel *cha
 		&buf[sizeof(struct hv_vmbus_pipe_hdr)];
 
 	    if (icmsghdrp->icmsgtype == HV_ICMSGTYPE_NEGOTIATE) {
-		hv_negotiate_version(icmsghdrp, NULL, buf);
-
+		hv_negotiate_version(icmsghdrp, buf);
 	    } else {
 		shutdown_msg =
 		    (struct hv_vmbus_shutdown_msg_data *)
@@ -132,11 +131,7 @@ hv_shutdown_probe(device_t dev)
 static int
 hv_shutdown_attach(device_t dev)
 {
-	hv_util_sc *softc = (hv_util_sc*)device_get_softc(dev);
-
-	softc->callback = hv_shutdown_cb;
-
-	return hv_util_attach(dev);
+	return hv_util_attach(dev, hv_shutdown_cb);
 }
 
 static device_method_t shutdown_methods[] = {

Modified: stable/11/sys/dev/hyperv/utilities/hv_timesync.c
==============================================================================
--- stable/11/sys/dev/hyperv/utilities/hv_timesync.c	Mon Oct 17 05:28:06 2016	(r307471)
+++ stable/11/sys/dev/hyperv/utilities/hv_timesync.c	Mon Oct 17 05:33:41 2016	(r307472)
@@ -145,7 +145,7 @@ hv_timesync_cb(struct vmbus_channel *cha
 	softc = (hv_timesync_sc*)context;
 	time_buf = softc->util_sc.receive_buffer;
 
-	recvlen = PAGE_SIZE;
+	recvlen = softc->util_sc.ic_buflen;
 	ret = vmbus_chan_recv(channel, time_buf, &recvlen, &requestId);
 	KASSERT(ret != ENOBUFS, ("hvtimesync recvbuf is not large enough"));
 	/* XXX check recvlen to make sure that it contains enough data */
@@ -155,7 +155,7 @@ hv_timesync_cb(struct vmbus_channel *cha
 		sizeof(struct hv_vmbus_pipe_hdr)];
 
 	    if (icmsghdrp->icmsgtype == HV_ICMSGTYPE_NEGOTIATE) {
-		hv_negotiate_version(icmsghdrp, NULL, time_buf);
+		hv_negotiate_version(icmsghdrp, time_buf);
 	    } else {
 		timedatap = (struct hv_ictimesync_data *) &time_buf[
 		    sizeof(struct hv_vmbus_pipe_hdr) +
@@ -189,18 +189,16 @@ hv_timesync_attach(device_t dev)
 {
 	hv_timesync_sc *softc = device_get_softc(dev);
 
-	softc->util_sc.callback = hv_timesync_cb;
 	TASK_INIT(&softc->task, 1, hv_set_host_time, softc);
-
-	return hv_util_attach(dev);
+	return hv_util_attach(dev, hv_timesync_cb);
 }
 
 static int
 hv_timesync_detach(device_t dev)
 {
 	hv_timesync_sc *softc = device_get_softc(dev);
-	taskqueue_drain(taskqueue_thread, &softc->task);
 
+	taskqueue_drain(taskqueue_thread, &softc->task);
 	return hv_util_detach(dev);
 }
 

Modified: stable/11/sys/dev/hyperv/utilities/hv_util.c
==============================================================================
--- stable/11/sys/dev/hyperv/utilities/hv_util.c	Mon Oct 17 05:28:06 2016	(r307471)
+++ stable/11/sys/dev/hyperv/utilities/hv_util.c	Mon Oct 17 05:33:41 2016	(r307472)
@@ -44,12 +44,13 @@
 #include <dev/hyperv/utilities/hv_utilreg.h>
 #include "hv_util.h"
 
+#define VMBUS_IC_BRSIZE		(4 * PAGE_SIZE)
+
 void
-hv_negotiate_version(
-	struct hv_vmbus_icmsg_hdr*		icmsghdrp,
-	struct hv_vmbus_icmsg_negotiate*	negop,
-	uint8_t*				buf)
+hv_negotiate_version(struct hv_vmbus_icmsg_hdr *icmsghdrp, uint8_t *buf)
 {
+	struct hv_vmbus_icmsg_negotiate *negop;
+
 	icmsghdrp->icmsgsize = 0x10;
 
 	negop = (struct hv_vmbus_icmsg_negotiate *)&buf[
@@ -74,16 +75,15 @@ hv_negotiate_version(
 }
 
 int
-hv_util_attach(device_t dev)
+hv_util_attach(device_t dev, vmbus_chan_callback_t cb)
 {
-	struct hv_util_sc*	softc;
-	struct vmbus_channel *chan;
-	int			ret;
-
-	softc = device_get_softc(dev);
-	softc->receive_buffer =
-		malloc(4 * PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO);
-	chan = vmbus_get_channel(dev);
+	struct hv_util_sc *sc = device_get_softc(dev);
+	struct vmbus_channel *chan = vmbus_get_channel(dev);
+	int error;
+
+	sc->ic_buflen = VMBUS_IC_BRSIZE;
+	sc->receive_buffer = malloc(VMBUS_IC_BRSIZE, M_DEVBUF,
+	    M_WAITOK | M_ZERO);
 
 	/*
 	 * These services are not performance critical and do not need
@@ -94,17 +94,13 @@ hv_util_attach(device_t dev)
 	 */
 	vmbus_chan_set_readbatch(chan, false);
 
-	ret = vmbus_chan_open(chan, 4 * PAGE_SIZE, 4 * PAGE_SIZE, NULL, 0,
-	    softc->callback, softc);
-
-	if (ret)
-		goto error0;
-
+	error = vmbus_chan_open(chan, VMBUS_IC_BRSIZE, VMBUS_IC_BRSIZE, NULL, 0,
+	    cb, sc);
+	if (error) {
+		free(sc->receive_buffer, M_DEVBUF);
+		return (error);
+	}
 	return (0);
-
-error0:
-	free(softc->receive_buffer, M_DEVBUF);
-	return (ret);
 }
 
 int

Modified: stable/11/sys/dev/hyperv/utilities/hv_util.h
==============================================================================
--- stable/11/sys/dev/hyperv/utilities/hv_util.h	Mon Oct 17 05:28:06 2016	(r307471)
+++ stable/11/sys/dev/hyperv/utilities/hv_util.h	Mon Oct 17 05:33:41 2016	(r307472)
@@ -31,23 +31,20 @@
 #ifndef _HVUTIL_H_
 #define _HVUTIL_H_
 
+#include <dev/hyperv/include/vmbus.h>
+
 /**
  * hv_util related structures
  *
  */
 typedef struct hv_util_sc {
-	/*
-	 * function to process Hyper-V messages
-	 */
-	void (*callback)(struct vmbus_channel *, void *);
 	uint8_t			*receive_buffer;
+	int			ic_buflen;
 } hv_util_sc;
 
-void hv_negotiate_version(
-	struct hv_vmbus_icmsg_hdr*		icmsghdrp,
-	struct hv_vmbus_icmsg_negotiate*	negop,
-	uint8_t*				buf);
+void hv_negotiate_version(struct hv_vmbus_icmsg_hdr *icmsghdrp, uint8_t *buf);
 
-int hv_util_attach(device_t dev);
+int hv_util_attach(device_t dev, vmbus_chan_callback_t cb);
 int hv_util_detach(device_t dev);
+
 #endif


More information about the svn-src-all mailing list