Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Oct 2016 02:45:08 +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: r307168 - stable/10/sys/dev/hyperv/utilities
Message-ID:  <201610130245.u9D2j8cS007779@repo.freebsd.org>

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

Log:
  MFC 304270,304273
  
  304270
      hyperv/util: Don't reference hn_softc in KVP
  
      hn_softc is private data struct.
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7519
  
  304273
      hyperv/util: Factor out helper for IC device_probe DEVMETHOD
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7530

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

Modified: stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c
==============================================================================
--- stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c	Thu Oct 13 02:38:46 2016	(r307167)
+++ stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c	Thu Oct 13 02:45:08 2016	(r307168)
@@ -41,10 +41,15 @@
 #include "hv_util.h"
 #include "vmbus_if.h"
 
-/* Heartbeat Service */
-static const struct hyperv_guid service_guid = { .hv_guid =
-	{0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e,
-	0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d} };
+static const struct vmbus_ic_desc vmbus_heartbeat_descs[] = {
+	{
+		.ic_guid = { .hv_guid = {
+		    0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e,
+		    0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d} },
+		.ic_desc = "Hyper-V Heartbeat"
+	},
+	VMBUS_IC_DESC_END
+};
 
 /**
  * Process heartbeat message
@@ -96,14 +101,8 @@ hv_heartbeat_cb(struct vmbus_channel *ch
 static int
 hv_heartbeat_probe(device_t dev)
 {
-	if (resource_disabled("hvheartbeat", 0))
-		return ENXIO;
 
-	if (VMBUS_PROBE_GUID(device_get_parent(dev), dev, &service_guid) == 0) {
-		device_set_desc(dev, "Hyper-V Heartbeat Service");
-		return BUS_PROBE_DEFAULT;
-	}
-	return ENXIO;
+	return (vmbus_ic_probe(dev, vmbus_heartbeat_descs));
 }
 
 static int

Modified: stable/10/sys/dev/hyperv/utilities/hv_kvp.c
==============================================================================
--- stable/10/sys/dev/hyperv/utilities/hv_kvp.c	Thu Oct 13 02:38:46 2016	(r307167)
+++ stable/10/sys/dev/hyperv/utilities/hv_kvp.c	Thu Oct 13 02:45:08 2016	(r307168)
@@ -54,17 +54,13 @@ __FBSDID("$FreeBSD$");
 #include <sys/un.h>
 #include <sys/endian.h>
 #include <sys/_null.h>
+#include <sys/sema.h>
 #include <sys/signal.h>
 #include <sys/syslog.h>
 #include <sys/systm.h>
 #include <sys/mutex.h>
 
-#include <net/if.h>
-#include <net/if_arp.h>
-#include <net/if_var.h>
-
 #include <dev/hyperv/include/hyperv.h>
-#include <dev/hyperv/netvsc/hv_net_vsc.h>
 #include <dev/hyperv/utilities/hv_utilreg.h>
 
 #include "hv_util.h"
@@ -91,9 +87,15 @@ static int hv_kvp_log = 0;
 		log(LOG_INFO, "hv_kvp: " __VA_ARGS__);		\
 } while (0)
 
-static const struct hyperv_guid service_guid = { .hv_guid =
-	{0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d,
-	0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3,  0xe6} };
+static const struct vmbus_ic_desc vmbus_kvp_descs[] = {
+	{
+		.ic_guid = { .hv_guid = {
+		    0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d,
+		    0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3,  0xe6 } },
+		.ic_desc = "Hyper-V KVP"
+	},
+	VMBUS_IC_DESC_END
+};
 
 /* character device prototypes */
 static d_open_t		hv_kvp_dev_open;
@@ -333,13 +335,11 @@ hv_kvp_convert_utf16_ipinfo_to_utf8(stru
 		for (devcnt = devcnt - 1; devcnt >= 0; devcnt--) {
 			/* XXX access other driver's softc?  are you kidding? */
 			device_t dev = devs[devcnt];
-			struct hn_softc *sc = device_get_softc(dev);
 			struct vmbus_channel *chan;
 			char buf[HYPERV_GUID_STRLEN];
 
 			/*
 			 * Trying to find GUID of Network Device
-			 * TODO: need vmbus interface.
 			 */
 			chan = vmbus_get_channel(dev);
 			hyperv_guid2str(vmbus_chan_guid_inst(chan),
@@ -348,7 +348,7 @@ hv_kvp_convert_utf16_ipinfo_to_utf8(stru
 			if (strncmp(buf, (char *)umsg->body.kvp_ip_val.adapter_id,
 			    HYPERV_GUID_STRLEN - 1) == 0) {
 				strlcpy((char *)umsg->body.kvp_ip_val.adapter_id,
-				    sc->hn_ifp->if_xname, MAX_ADAPTER_ID_SIZE);
+				    device_get_nameunit(dev), MAX_ADAPTER_ID_SIZE);
 				break;
 			}
 		}
@@ -873,14 +873,8 @@ hv_kvp_dev_daemon_poll(struct cdev *dev,
 static int
 hv_kvp_probe(device_t dev)
 {
-	if (resource_disabled("hvkvp", 0))
-		return ENXIO;
 
-	if (VMBUS_PROBE_GUID(device_get_parent(dev), dev, &service_guid) == 0) {
-		device_set_desc(dev, "Hyper-V KVP Service");
-		return BUS_PROBE_DEFAULT;
-	}
-	return ENXIO;
+	return (vmbus_ic_probe(dev, vmbus_kvp_descs));
 }
 
 static int

Modified: stable/10/sys/dev/hyperv/utilities/hv_shutdown.c
==============================================================================
--- stable/10/sys/dev/hyperv/utilities/hv_shutdown.c	Thu Oct 13 02:38:46 2016	(r307167)
+++ stable/10/sys/dev/hyperv/utilities/hv_shutdown.c	Thu Oct 13 02:45:08 2016	(r307168)
@@ -46,9 +46,15 @@
 #include "hv_util.h"
 #include "vmbus_if.h"
 
-static const struct hyperv_guid service_guid = { .hv_guid =
-	{0x31, 0x60, 0x0B, 0X0E, 0x13, 0x52, 0x34, 0x49,
-	0x81, 0x8B, 0x38, 0XD9, 0x0C, 0xED, 0x39, 0xDB} };
+static const struct vmbus_ic_desc vmbus_shutdown_descs[] = {
+	{
+		.ic_guid = { .hv_guid = {
+		    0x31, 0x60, 0x0b, 0x0e, 0x13, 0x52, 0x34, 0x49,
+		    0x81, 0x8b, 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb } },
+		.ic_desc = "Hyper-V Shutdown"
+	},
+	VMBUS_IC_DESC_END
+};
 
 /**
  * Shutdown
@@ -118,14 +124,8 @@ hv_shutdown_cb(struct vmbus_channel *cha
 static int
 hv_shutdown_probe(device_t dev)
 {
-	if (resource_disabled("hvshutdown", 0))
-		return ENXIO;
 
-	if (VMBUS_PROBE_GUID(device_get_parent(dev), dev, &service_guid) == 0) {
-		device_set_desc(dev, "Hyper-V Shutdown Service");
-		return BUS_PROBE_DEFAULT;
-	}
-	return ENXIO;
+	return (vmbus_ic_probe(dev, vmbus_shutdown_descs));
 }
 
 static int

Modified: stable/10/sys/dev/hyperv/utilities/hv_timesync.c
==============================================================================
--- stable/10/sys/dev/hyperv/utilities/hv_timesync.c	Thu Oct 13 02:38:46 2016	(r307167)
+++ stable/10/sys/dev/hyperv/utilities/hv_timesync.c	Thu Oct 13 02:45:08 2016	(r307168)
@@ -58,10 +58,15 @@ typedef struct {
 	uint64_t data;
 } time_sync_data;
 
-        /* Time Synch Service */
-static const struct hyperv_guid service_guid = {.hv_guid =
-	{0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49,
-	0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf } };
+static const struct vmbus_ic_desc vmbus_timesync_descs[] = {
+	{
+		.ic_guid = { .hv_guid = {
+		    0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49,
+		    0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf } },
+		.ic_desc = "Hyper-V Timesync"
+	},
+	VMBUS_IC_DESC_END
+};
 
 struct hv_ictimesync_data {
 	uint64_t    parenttime;
@@ -174,14 +179,8 @@ hv_timesync_cb(struct vmbus_channel *cha
 static int
 hv_timesync_probe(device_t dev)
 {
-	if (resource_disabled("hvtimesync", 0))
-		return ENXIO;
 
-	if (VMBUS_PROBE_GUID(device_get_parent(dev), dev, &service_guid) == 0) {
-		device_set_desc(dev, "Hyper-V Time Synch Service");
-		return BUS_PROBE_DEFAULT;
-	}
-	return ENXIO;
+	return (vmbus_ic_probe(dev, vmbus_timesync_descs));
 }
 
 static int

Modified: stable/10/sys/dev/hyperv/utilities/hv_util.c
==============================================================================
--- stable/10/sys/dev/hyperv/utilities/hv_util.c	Thu Oct 13 02:38:46 2016	(r307167)
+++ stable/10/sys/dev/hyperv/utilities/hv_util.c	Thu Oct 13 02:45:08 2016	(r307168)
@@ -42,7 +42,9 @@
 #include <dev/hyperv/include/hyperv.h>
 #include <dev/hyperv/include/vmbus.h>
 #include <dev/hyperv/utilities/hv_utilreg.h>
-#include "hv_util.h"
+#include <dev/hyperv/utilities/hv_util.h>
+
+#include "vmbus_if.h"
 
 #define VMBUS_IC_BRSIZE		(4 * PAGE_SIZE)
 
@@ -75,6 +77,24 @@ hv_negotiate_version(struct hv_vmbus_icm
 }
 
 int
+vmbus_ic_probe(device_t dev, const struct vmbus_ic_desc descs[])
+{
+	device_t bus = device_get_parent(dev);
+	const struct vmbus_ic_desc *d;
+
+	if (resource_disabled(device_get_name(dev), 0))
+		return (ENXIO);
+
+	for (d = descs; d->ic_desc != NULL; ++d) {
+		if (VMBUS_PROBE_GUID(bus, dev, &d->ic_guid) == 0) {
+			device_set_desc(dev, d->ic_desc);
+			return (BUS_PROBE_DEFAULT);
+		}
+	}
+	return (ENXIO);
+}
+
+int
 hv_util_attach(device_t dev, vmbus_chan_callback_t cb)
 {
 	struct hv_util_sc *sc = device_get_softc(dev);

Modified: stable/10/sys/dev/hyperv/utilities/hv_util.h
==============================================================================
--- stable/10/sys/dev/hyperv/utilities/hv_util.h	Thu Oct 13 02:38:46 2016	(r307167)
+++ stable/10/sys/dev/hyperv/utilities/hv_util.h	Thu Oct 13 02:45:08 2016	(r307168)
@@ -31,6 +31,7 @@
 #ifndef _HVUTIL_H_
 #define _HVUTIL_H_
 
+#include <dev/hyperv/include/hyperv.h>
 #include <dev/hyperv/include/vmbus.h>
 
 /**
@@ -42,9 +43,17 @@ typedef struct hv_util_sc {
 	int			ic_buflen;
 } hv_util_sc;
 
+struct vmbus_ic_desc {
+	const struct hyperv_guid	ic_guid;
+	const char			*ic_desc;
+};
+
+#define VMBUS_IC_DESC_END	{ .ic_desc = NULL }
+
 void hv_negotiate_version(struct hv_vmbus_icmsg_hdr *icmsghdrp, uint8_t *buf);
 
-int hv_util_attach(device_t dev, vmbus_chan_callback_t cb);
-int hv_util_detach(device_t dev);
+int		hv_util_attach(device_t dev, vmbus_chan_callback_t cb);
+int		hv_util_detach(device_t dev);
+int		vmbus_ic_probe(device_t dev, const struct vmbus_ic_desc descs[]);
 
 #endif



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