Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Jul 2016 08:40:59 +0000 (UTC)
From:      Sepherosa Ziehau <sephe@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r302823 - head/sys/dev/hyperv/vmbus
Message-ID:  <201607140840.u6E8ex0E012362@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sephe
Date: Thu Jul 14 08:40:59 2016
New Revision: 302823
URL: https://svnweb.freebsd.org/changeset/base/302823

Log:
  hyperv/vmbus: Move bus related message processing into vmbus.
  
  MFC after:	1 week
  Sponsored by:	Microsoft OSTC
  Differential Revision:	https://reviews.freebsd.org/D7125

Modified:
  head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c
  head/sys/dev/hyperv/vmbus/vmbus.c
  head/sys/dev/hyperv/vmbus/vmbus_var.h

Modified: head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c
==============================================================================
--- head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c	Thu Jul 14 08:20:17 2016	(r302822)
+++ head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c	Thu Jul 14 08:40:59 2016	(r302823)
@@ -37,13 +37,8 @@
 #include <dev/hyperv/vmbus/vmbus_reg.h>
 #include <dev/hyperv/vmbus/vmbus_var.h>
 
-typedef void	(*vmbus_chanmsg_proc_t)
-		(struct vmbus_softc *, const struct vmbus_message *);
-
 static void	vmbus_chan_detach_task(void *, int);
 
-static void	vmbus_channel_on_offers_delivered(struct vmbus_softc *,
-		    const struct vmbus_message *);
 static void	vmbus_chan_msgproc_choffer(struct vmbus_softc *,
 		    const struct vmbus_message *);
 static void	vmbus_chan_msgproc_chrescind(struct vmbus_softc *,
@@ -52,27 +47,16 @@ static void	vmbus_chan_msgproc_chrescind
 /*
  * Vmbus channel message processing.
  */
-
-#define VMBUS_CHANMSG_PROC(name, func)	\
-	[VMBUS_CHANMSG_TYPE_##name] = func
-#define VMBUS_CHANMSG_PROC_WAKEUP(name)	\
-	VMBUS_CHANMSG_PROC(name, vmbus_msghc_wakeup)
-
 static const vmbus_chanmsg_proc_t
-vmbus_chanmsg_process[VMBUS_CHANMSG_TYPE_MAX] = {
+vmbus_chan_msgprocs[VMBUS_CHANMSG_TYPE_MAX] = {
 	VMBUS_CHANMSG_PROC(CHOFFER,	vmbus_chan_msgproc_choffer),
 	VMBUS_CHANMSG_PROC(CHRESCIND,	vmbus_chan_msgproc_chrescind),
-	VMBUS_CHANMSG_PROC(CHOFFER_DONE,vmbus_channel_on_offers_delivered),
 
 	VMBUS_CHANMSG_PROC_WAKEUP(CHOPEN_RESP),
 	VMBUS_CHANMSG_PROC_WAKEUP(GPADL_CONNRESP),
-	VMBUS_CHANMSG_PROC_WAKEUP(GPADL_DISCONNRESP),
-	VMBUS_CHANMSG_PROC_WAKEUP(CONNECT_RESP)
+	VMBUS_CHANMSG_PROC_WAKEUP(GPADL_DISCONNRESP)
 };
 
-#undef VMBUS_CHANMSG_PROC_WAKEUP
-#undef VMBUS_CHANMSG_PROC
-
 static struct hv_vmbus_channel *
 vmbus_chan_alloc(struct vmbus_softc *sc)
 {
@@ -390,19 +374,6 @@ remove:
 	}
 }
 
-/**
- *
- * @brief Invoked when all offers have been delivered.
- */
-static void
-vmbus_channel_on_offers_delivered(struct vmbus_softc *sc,
-    const struct vmbus_message *msg __unused)
-{
-
-	/* No more new channels for the channel request. */
-	vmbus_scan_done(sc);
-}
-
 /*
  * Detach all devices and destroy the corresponding primary channels.
  */
@@ -538,13 +509,10 @@ vmbus_chan_msgproc(struct vmbus_softc *s
 	uint32_t msg_type;
 
 	msg_type = ((const struct vmbus_chanmsg_hdr *)msg->msg_data)->chm_type;
-	if (msg_type >= VMBUS_CHANMSG_TYPE_MAX) {
-		device_printf(sc->vmbus_dev, "unknown message type 0x%x\n",
-		    msg_type);
-		return;
-	}
+	KASSERT(msg_type < VMBUS_CHANMSG_TYPE_MAX,
+	    ("invalid message type %u", msg_type));
 
-	msg_proc = vmbus_chanmsg_process[msg_type];
+	msg_proc = vmbus_chan_msgprocs[msg_type];
 	if (msg_proc != NULL)
 		msg_proc(sc, msg);
 }

Modified: head/sys/dev/hyperv/vmbus/vmbus.c
==============================================================================
--- head/sys/dev/hyperv/vmbus/vmbus.c	Thu Jul 14 08:20:17 2016	(r302822)
+++ head/sys/dev/hyperv/vmbus/vmbus.c	Thu Jul 14 08:40:59 2016	(r302823)
@@ -98,7 +98,12 @@ static int			vmbus_req_channels(struct v
 static void			vmbus_disconnect(struct vmbus_softc *);
 static int			vmbus_scan(struct vmbus_softc *);
 static void			vmbus_scan_wait(struct vmbus_softc *);
+static void			vmbus_scan_newchan(struct vmbus_softc *);
 static void			vmbus_scan_newdev(struct vmbus_softc *);
+static void			vmbus_scan_done(struct vmbus_softc *,
+				    const struct vmbus_message *);
+static void			vmbus_chanmsg_handle(struct vmbus_softc *,
+				    const struct vmbus_message *);
 
 static int			vmbus_sysctl_version(SYSCTL_HANDLER_ARGS);
 
@@ -122,6 +127,12 @@ static const uint32_t		vmbus_version[] =
 	VMBUS_VERSION_WS2008
 };
 
+static const vmbus_chanmsg_proc_t
+vmbus_chanmsg_handlers[VMBUS_CHANMSG_TYPE_MAX] = {
+	VMBUS_CHANMSG_PROC(CHOFFER_DONE, vmbus_scan_done),
+	VMBUS_CHANMSG_PROC_WAKEUP(CONNECT_RESP)
+};
+
 static struct vmbus_msghc *
 vmbus_msghc_alloc(bus_dma_tag_t parent_dtag)
 {
@@ -480,7 +491,7 @@ vmbus_req_channels(struct vmbus_softc *s
 	return error;
 }
 
-void
+static void
 vmbus_scan_newchan(struct vmbus_softc *sc)
 {
 	mtx_lock(&sc->vmbus_scan_lock);
@@ -489,8 +500,9 @@ vmbus_scan_newchan(struct vmbus_softc *s
 	mtx_unlock(&sc->vmbus_scan_lock);
 }
 
-void
-vmbus_scan_done(struct vmbus_softc *sc)
+static void
+vmbus_scan_done(struct vmbus_softc *sc,
+    const struct vmbus_message *msg __unused)
 {
 	mtx_lock(&sc->vmbus_scan_lock);
 	sc->vmbus_scan_chcnt |= VMBUS_SCAN_CHCNT_DONE;
@@ -560,6 +572,27 @@ vmbus_scan(struct vmbus_softc *sc)
 }
 
 static void
+vmbus_chanmsg_handle(struct vmbus_softc *sc, const struct vmbus_message *msg)
+{
+	vmbus_chanmsg_proc_t msg_proc;
+	uint32_t msg_type;
+
+	msg_type = ((const struct vmbus_chanmsg_hdr *)msg->msg_data)->chm_type;
+	if (msg_type >= VMBUS_CHANMSG_TYPE_MAX) {
+		device_printf(sc->vmbus_dev, "unknown message type 0x%x\n",
+		    msg_type);
+		return;
+	}
+
+	msg_proc = vmbus_chanmsg_handlers[msg_type];
+	if (msg_proc != NULL)
+		msg_proc(sc, msg);
+
+	/* Channel specific processing */
+	vmbus_chan_msgproc(sc, msg);
+}
+
+static void
 vmbus_msg_task(void *xsc, int pending __unused)
 {
 	struct vmbus_softc *sc = xsc;
@@ -572,7 +605,7 @@ vmbus_msg_task(void *xsc, int pending __
 			break;
 		} else if (msg->msg_type == HYPERV_MSGTYPE_CHANNEL) {
 			/* Channel message */
-			vmbus_chan_msgproc(sc,
+			vmbus_chanmsg_handle(sc,
 			    __DEVOLATILE(const struct vmbus_message *, msg));
 		}
 

Modified: head/sys/dev/hyperv/vmbus/vmbus_var.h
==============================================================================
--- head/sys/dev/hyperv/vmbus/vmbus_var.h	Thu Jul 14 08:20:17 2016	(r302822)
+++ head/sys/dev/hyperv/vmbus/vmbus_var.h	Thu Jul 14 08:40:59 2016	(r302823)
@@ -52,6 +52,17 @@
 #define VMBUS_CONNID_MESSAGE		1
 #define VMBUS_CONNID_EVENT		2
 
+struct vmbus_message;
+struct vmbus_softc;
+
+typedef void		(*vmbus_chanmsg_proc_t)(struct vmbus_softc *,
+			    const struct vmbus_message *);
+
+#define VMBUS_CHANMSG_PROC(name, func)	\
+	[VMBUS_CHANMSG_TYPE_##name] = func
+#define VMBUS_CHANMSG_PROC_WAKEUP(name)	\
+	VMBUS_CHANMSG_PROC(name, vmbus_msghc_wakeup)
+
 struct vmbus_pcpu_data {
 	u_long			*intr_cnt;	/* Hyper-V interrupt counter */
 	struct vmbus_message	*message;	/* shared messages */
@@ -151,9 +162,6 @@ const struct vmbus_message *vmbus_msghc_
 void	vmbus_msghc_wakeup(struct vmbus_softc *, const struct vmbus_message *);
 void	vmbus_msghc_reset(struct vmbus_msghc *, size_t);
 
-void	vmbus_scan_done(struct vmbus_softc *);
-void	vmbus_scan_newchan(struct vmbus_softc *);
-
 uint32_t vmbus_gpadl_alloc(struct vmbus_softc *);
 
 #endif	/* !_VMBUS_VAR_H_ */



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