Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Oct 2016 08:58:04 +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: r307133 - in stable/10/sys/dev/hyperv: include netvsc storvsc utilities vmbus
Message-ID:  <201610120858.u9C8w491096708@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sephe
Date: Wed Oct 12 08:58:03 2016
New Revision: 307133
URL: https://svnweb.freebsd.org/changeset/base/307133

Log:
  MFC 303421,303422,303470-303473
  
  303421
      hyperv/vmbus: Avoid unnecessary mb()
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7333
  
  303422
      hyperv/vmbus: Inclusion cleanup
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7334
  
  303470
      hyperv/vmbus: Reindent function declarations.
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7344
  
  303471
      hyperv/vmbus: Forward declare static functions
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7346
  
  303472
      hyperv/vmbus: Move driver glue to the beginning of the files
  
      Just as most of other drivers do.  And move sysinit function close
      to its SYSINIT.
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7347
  
  303473
      hyperv/vmbus: Revoke unnecessary exposure of vmbus softc
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7348

Modified:
  stable/10/sys/dev/hyperv/include/hyperv.h
  stable/10/sys/dev/hyperv/include/hyperv_busdma.h
  stable/10/sys/dev/hyperv/include/vmbus.h
  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/storvsc/hv_storvsc_drv_freebsd.c
  stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c
  stable/10/sys/dev/hyperv/utilities/hv_shutdown.c
  stable/10/sys/dev/hyperv/utilities/hv_timesync.c
  stable/10/sys/dev/hyperv/vmbus/hyperv.c
  stable/10/sys/dev/hyperv/vmbus/vmbus.c
  stable/10/sys/dev/hyperv/vmbus/vmbus_br.c
  stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c
  stable/10/sys/dev/hyperv/vmbus/vmbus_chanvar.h
  stable/10/sys/dev/hyperv/vmbus/vmbus_et.c
  stable/10/sys/dev/hyperv/vmbus/vmbus_var.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/hyperv/include/hyperv.h
==============================================================================
--- stable/10/sys/dev/hyperv/include/hyperv.h	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/include/hyperv.h	Wed Oct 12 08:58:03 2016	(r307133)
@@ -28,43 +28,21 @@
  * $FreeBSD$
  */
 
-/**
- * HyperV definitions for messages that are sent between instances of the
- * Channel Management Library in separate partitions, or in some cases,
- * back to itself.
- */
-
-#ifndef __HYPERV_H__
-#define __HYPERV_H__
+#ifndef _HYPERV_H_
+#define _HYPERV_H_
 
 #include <sys/param.h>
-#include <sys/mbuf.h>
-#include <sys/queue.h>
-#include <sys/malloc.h>
-#include <sys/kthread.h>
-#include <sys/taskqueue.h>
-#include <sys/systm.h>
-#include <sys/lock.h>
-#include <sys/sema.h>
-#include <sys/smp.h>
-#include <sys/mutex.h>
-#include <sys/bus.h>
-#include <sys/sysctl.h>
+
 #include <vm/vm.h>
-#include <vm/vm_param.h>
 #include <vm/pmap.h>
 
-#include <amd64/include/xen/synch_bitops.h>
-#include <amd64/include/atomic.h>
-#include <dev/hyperv/include/hyperv_busdma.h>
-
 struct hyperv_guid {
 	uint8_t		hv_guid[16];
 } __packed;
 
 #define HYPERV_GUID_STRLEN	40
 
-int	hyperv_guid2str(const struct hyperv_guid *, char *, size_t);
+int		hyperv_guid2str(const struct hyperv_guid *, char *, size_t);
 
 /**
  * @brief Get physical address from virtual
@@ -77,4 +55,4 @@ hv_get_phys_addr(void *virt)
 	return (ret);
 }
 
-#endif  /* __HYPERV_H__ */
+#endif  /* _HYPERV_H_ */

Modified: stable/10/sys/dev/hyperv/include/hyperv_busdma.h
==============================================================================
--- stable/10/sys/dev/hyperv/include/hyperv_busdma.h	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/include/hyperv_busdma.h	Wed Oct 12 08:58:03 2016	(r307133)
@@ -39,11 +39,11 @@ struct hyperv_dma {
 	bus_dmamap_t	hv_dmap;
 };
 
-void	hyperv_dma_map_paddr(void *arg, bus_dma_segment_t *segs, int nseg,
-	    int error);
-void	*hyperv_dmamem_alloc(bus_dma_tag_t parent_dtag, bus_size_t alignment,
-	    bus_addr_t boundary, bus_size_t size, struct hyperv_dma *dma,
-	    int flags);
-void	hyperv_dmamem_free(struct hyperv_dma *dma, void *ptr);
+void		hyperv_dma_map_paddr(void *arg, bus_dma_segment_t *segs,
+		    int nseg, int error);
+void		*hyperv_dmamem_alloc(bus_dma_tag_t parent_dtag,
+		    bus_size_t alignment, bus_addr_t boundary, bus_size_t size,
+		    struct hyperv_dma *dma, int flags);
+void		hyperv_dmamem_free(struct hyperv_dma *dma, void *ptr);
 
 #endif	/* !_HYPERV_BUSDMA_H_ */

Modified: stable/10/sys/dev/hyperv/include/vmbus.h
==============================================================================
--- stable/10/sys/dev/hyperv/include/vmbus.h	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/include/vmbus.h	Wed Oct 12 08:58:03 2016	(r307133)
@@ -30,6 +30,8 @@
 #define _VMBUS_H_
 
 #include <sys/param.h>
+#include <sys/bus.h>
+#include <machine/bus.h>
 
 /*
  * VMBUS version is 32 bit, upper 16 bit for major_number and lower
@@ -115,45 +117,47 @@ vmbus_get_channel(device_t dev)
 	return device_get_ivars(dev);
 }
 
-int	vmbus_chan_open(struct vmbus_channel *chan,
-	    int txbr_size, int rxbr_size, const void *udata, int udlen,
-	    vmbus_chan_callback_t cb, void *cbarg);
-void	vmbus_chan_close(struct vmbus_channel *chan);
-
-int	vmbus_chan_gpadl_connect(struct vmbus_channel *chan,
-	    bus_addr_t paddr, int size, uint32_t *gpadl);
-int	vmbus_chan_gpadl_disconnect(struct vmbus_channel *chan,
-	    uint32_t gpadl);
+int		vmbus_chan_open(struct vmbus_channel *chan,
+		    int txbr_size, int rxbr_size, const void *udata, int udlen,
+		    vmbus_chan_callback_t cb, void *cbarg);
+void		vmbus_chan_close(struct vmbus_channel *chan);
+
+int		vmbus_chan_gpadl_connect(struct vmbus_channel *chan,
+		    bus_addr_t paddr, int size, uint32_t *gpadl);
+int		vmbus_chan_gpadl_disconnect(struct vmbus_channel *chan,
+		    uint32_t gpadl);
 
-void	vmbus_chan_cpu_set(struct vmbus_channel *chan, int cpu);
-void	vmbus_chan_cpu_rr(struct vmbus_channel *chan);
+void		vmbus_chan_cpu_set(struct vmbus_channel *chan, int cpu);
+void		vmbus_chan_cpu_rr(struct vmbus_channel *chan);
 struct vmbus_channel *
-	vmbus_chan_cpu2chan(struct vmbus_channel *chan, int cpu);
-void	vmbus_chan_set_readbatch(struct vmbus_channel *chan, bool on);
+		vmbus_chan_cpu2chan(struct vmbus_channel *chan, int cpu);
+void		vmbus_chan_set_readbatch(struct vmbus_channel *chan, bool on);
 
 struct vmbus_channel **
-	vmbus_subchan_get(struct vmbus_channel *pri_chan, int subchan_cnt);
-void	vmbus_subchan_rel(struct vmbus_channel **subchan, int subchan_cnt);
-void	vmbus_subchan_drain(struct vmbus_channel *pri_chan);
-
-int	vmbus_chan_recv(struct vmbus_channel *chan, void *data, int *dlen,
-	    uint64_t *xactid);
-int	vmbus_chan_recv_pkt(struct vmbus_channel *chan,
-	    struct vmbus_chanpkt_hdr *pkt, int *pktlen);
-
-int	vmbus_chan_send(struct vmbus_channel *chan, uint16_t type,
-	    uint16_t flags, void *data, int dlen, uint64_t xactid);
-int	vmbus_chan_send_sglist(struct vmbus_channel *chan,
-	    struct vmbus_gpa sg[], int sglen, void *data, int dlen,
-	    uint64_t xactid);
-int	vmbus_chan_send_prplist(struct vmbus_channel *chan,
-	    struct vmbus_gpa_range *prp, int prp_cnt, void *data, int dlen,
-	    uint64_t xactid);
-
-uint32_t vmbus_chan_id(const struct vmbus_channel *chan);
-uint32_t vmbus_chan_subidx(const struct vmbus_channel *chan);
-bool	vmbus_chan_is_primary(const struct vmbus_channel *chan);
+		vmbus_subchan_get(struct vmbus_channel *pri_chan,
+		    int subchan_cnt);
+void		vmbus_subchan_rel(struct vmbus_channel **subchan,
+		    int subchan_cnt);
+void		vmbus_subchan_drain(struct vmbus_channel *pri_chan);
+
+int		vmbus_chan_recv(struct vmbus_channel *chan, void *data, int *dlen,
+		    uint64_t *xactid);
+int		vmbus_chan_recv_pkt(struct vmbus_channel *chan,
+		    struct vmbus_chanpkt_hdr *pkt, int *pktlen);
+
+int		vmbus_chan_send(struct vmbus_channel *chan, uint16_t type,
+		    uint16_t flags, void *data, int dlen, uint64_t xactid);
+int		vmbus_chan_send_sglist(struct vmbus_channel *chan,
+		    struct vmbus_gpa sg[], int sglen, void *data, int dlen,
+		    uint64_t xactid);
+int		vmbus_chan_send_prplist(struct vmbus_channel *chan,
+		    struct vmbus_gpa_range *prp, int prp_cnt, void *data,
+		    int dlen, uint64_t xactid);
+
+uint32_t	vmbus_chan_id(const struct vmbus_channel *chan);
+uint32_t	vmbus_chan_subidx(const struct vmbus_channel *chan);
+bool		vmbus_chan_is_primary(const struct vmbus_channel *chan);
 const struct hyperv_guid *
-	vmbus_chan_guid_inst(const struct vmbus_channel *chan);
+		vmbus_chan_guid_inst(const struct vmbus_channel *chan);
 
 #endif	/* !_VMBUS_H_ */

Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h
==============================================================================
--- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h	Wed Oct 12 08:58:03 2016	(r307133)
@@ -44,6 +44,7 @@
 #include <sys/malloc.h>
 #include <sys/queue.h>
 #include <sys/taskqueue.h>
+#include <sys/sema.h>
 #include <sys/sx.h>
 
 #include <machine/bus.h>

Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
==============================================================================
--- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c	Wed Oct 12 08:58:03 2016	(r307133)
@@ -70,6 +70,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/queue.h>
 #include <sys/lock.h>
 #include <sys/sx.h>
+#include <sys/smp.h>
 #include <sys/sysctl.h>
 #include <sys/buf_ring.h>
 

Modified: stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c
==============================================================================
--- stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c	Wed Oct 12 08:58:03 2016	(r307133)
@@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <sys/mutex.h>
 #include <sys/callout.h>
+#include <sys/smp.h>
 #include <vm/vm.h>
 #include <vm/pmap.h>
 #include <vm/uma.h>

Modified: stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c
==============================================================================
--- stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c	Wed Oct 12 08:58:03 2016	(r307133)
@@ -33,6 +33,7 @@
 #include <sys/module.h>
 #include <sys/timetc.h>
 #include <sys/syscallsubr.h>
+#include <sys/systm.h>
 
 #include <dev/hyperv/include/hyperv.h>
 #include <dev/hyperv/include/vmbus.h>

Modified: stable/10/sys/dev/hyperv/utilities/hv_shutdown.c
==============================================================================
--- stable/10/sys/dev/hyperv/utilities/hv_shutdown.c	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/utilities/hv_shutdown.c	Wed Oct 12 08:58:03 2016	(r307133)
@@ -38,6 +38,7 @@
 #include <sys/reboot.h>
 #include <sys/timetc.h>
 #include <sys/syscallsubr.h>
+#include <sys/systm.h>
 
 #include <dev/hyperv/include/hyperv.h>
 #include <dev/hyperv/include/vmbus.h>

Modified: stable/10/sys/dev/hyperv/utilities/hv_timesync.c
==============================================================================
--- stable/10/sys/dev/hyperv/utilities/hv_timesync.c	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/utilities/hv_timesync.c	Wed Oct 12 08:58:03 2016	(r307133)
@@ -38,6 +38,8 @@
 #include <sys/reboot.h>
 #include <sys/timetc.h>
 #include <sys/syscallsubr.h>
+#include <sys/systm.h>
+#include <sys/taskqueue.h>
 
 #include <dev/hyperv/include/hyperv.h>
 #include <dev/hyperv/include/vmbus.h>

Modified: stable/10/sys/dev/hyperv/vmbus/hyperv.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hyperv.c	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/vmbus/hyperv.c	Wed Oct 12 08:58:03 2016	(r307133)
@@ -34,23 +34,14 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
-#include <sys/malloc.h>
-#include <sys/pcpu.h>
+#include <sys/systm.h>
 #include <sys/timetc.h>
-#include <machine/bus.h>
-#include <machine/md_var.h>
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
 
 #include <dev/hyperv/include/hyperv.h>
 #include <dev/hyperv/include/hyperv_busdma.h>
 #include <dev/hyperv/vmbus/hyperv_machdep.h>
 #include <dev/hyperv/vmbus/hyperv_reg.h>
 #include <dev/hyperv/vmbus/hyperv_var.h>
-#if 0
-#include <dev/hyperv/vmbus/vmbus_var.h>
-#endif
 
 #define HYPERV_FREEBSD_BUILD		0ULL
 #define HYPERV_FREEBSD_VERSION		((uint64_t)__FreeBSD_version)
@@ -76,13 +67,15 @@ struct hypercall_ctx {
 	struct hyperv_dma	hc_dma;
 };
 
-static u_int	hyperv_get_timecount(struct timecounter *tc);
+static u_int			hyperv_get_timecount(struct timecounter *);
+static bool			hyperv_identify(void);
+static void			hypercall_memfree(void);
 
-u_int		hyperv_features;
-u_int		hyperv_recommends;
+u_int				hyperv_features;
+u_int				hyperv_recommends;
 
-static u_int	hyperv_pm_features;
-static u_int	hyperv_features3;
+static u_int			hyperv_pm_features;
+static u_int			hyperv_features3;
 
 static struct timecounter	hyperv_timecounter = {
 	.tc_get_timecount	= hyperv_get_timecount,

Modified: stable/10/sys/dev/hyperv/vmbus/vmbus.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/vmbus.c	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/vmbus/vmbus.c	Wed Oct 12 08:58:03 2016	(r307133)
@@ -38,26 +38,18 @@ __FBSDID("$FreeBSD$");
 #include <sys/lock.h>
 #include <sys/malloc.h>
 #include <sys/module.h>
+#include <sys/mutex.h>
 #include <sys/proc.h>
+#include <sys/smp.h>
 #include <sys/sysctl.h>
-#include <sys/syslog.h>
 #include <sys/systm.h>
-#include <sys/rtprio.h>
-#include <sys/interrupt.h>
-#include <sys/sx.h>
 #include <sys/taskqueue.h>
-#include <sys/mutex.h>
-#include <sys/smp.h>
 
-#include <machine/resource.h>
-#include <sys/rman.h>
-
-#include <machine/stdarg.h>
 #include <machine/intr_machdep.h>
-#include <machine/md_var.h>
-#include <machine/segments.h>
-#include <sys/pcpu.h>
 #include <machine/apicvar.h>
+#include <machine/md_var.h>
+
+#include <contrib/dev/acpica/include/acpi.h>
 
 #include <dev/hyperv/include/hyperv.h>
 #include <dev/hyperv/vmbus/hyperv_reg.h>
@@ -66,7 +58,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/hyperv/vmbus/vmbus_var.h>
 #include <dev/hyperv/vmbus/vmbus_chanvar.h>
 
-#include <contrib/dev/acpica/include/acpi.h>
 #include "acpi_if.h"
 #include "vmbus_if.h"
 
@@ -92,6 +83,17 @@ struct vmbus_msghc_ctx {
 
 #define VMBUS_MSGHC_CTXF_DESTROY	0x0001
 
+static int			vmbus_probe(device_t);
+static int			vmbus_attach(device_t);
+static int			vmbus_detach(device_t);
+static int			vmbus_read_ivar(device_t, device_t, int,
+				    uintptr_t *);
+static int			vmbus_child_pnpinfo_str(device_t, device_t,
+				    char *, size_t);
+static uint32_t			vmbus_get_version_method(device_t, device_t);
+static int			vmbus_probe_guid_method(device_t, device_t,
+				    const struct hyperv_guid *);
+
 static int			vmbus_init(struct vmbus_softc *);
 static int			vmbus_connect(struct vmbus_softc *, uint32_t);
 static int			vmbus_req_channels(struct vmbus_softc *sc);
@@ -104,8 +106,17 @@ static void			vmbus_scan_done(struct vmb
 				    const struct vmbus_message *);
 static void			vmbus_chanmsg_handle(struct vmbus_softc *,
 				    const struct vmbus_message *);
-
+static void			vmbus_msg_task(void *, int);
+static void			vmbus_synic_setup(void *);
+static void			vmbus_synic_teardown(void *);
 static int			vmbus_sysctl_version(SYSCTL_HANDLER_ARGS);
+static int			vmbus_dma_alloc(struct vmbus_softc *);
+static void			vmbus_dma_free(struct vmbus_softc *);
+static int			vmbus_intr_setup(struct vmbus_softc *);
+static void			vmbus_intr_teardown(struct vmbus_softc *);
+static int			vmbus_doattach(struct vmbus_softc *);
+static void			vmbus_event_proc_dummy(struct vmbus_softc *,
+				    int);
 
 static struct vmbus_msghc_ctx	*vmbus_msghc_ctx_create(bus_dma_tag_t);
 static void			vmbus_msghc_ctx_destroy(
@@ -116,7 +127,7 @@ static void			vmbus_msghc_free(struct vm
 static struct vmbus_msghc	*vmbus_msghc_get1(struct vmbus_msghc_ctx *,
 				    uint32_t);
 
-struct vmbus_softc	*vmbus_sc;
+static struct vmbus_softc	*vmbus_sc;
 
 extern inthand_t IDTVEC(rsvd), IDTVEC(vmbus_isr);
 
@@ -133,6 +144,46 @@ vmbus_chanmsg_handlers[VMBUS_CHANMSG_TYP
 	VMBUS_CHANMSG_PROC_WAKEUP(CONNECT_RESP)
 };
 
+static device_method_t vmbus_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,			vmbus_probe),
+	DEVMETHOD(device_attach,		vmbus_attach),
+	DEVMETHOD(device_detach,		vmbus_detach),
+	DEVMETHOD(device_shutdown,		bus_generic_shutdown),
+	DEVMETHOD(device_suspend,		bus_generic_suspend),
+	DEVMETHOD(device_resume,		bus_generic_resume),
+
+	/* Bus interface */
+	DEVMETHOD(bus_add_child,		bus_generic_add_child),
+	DEVMETHOD(bus_print_child,		bus_generic_print_child),
+	DEVMETHOD(bus_read_ivar,		vmbus_read_ivar),
+	DEVMETHOD(bus_child_pnpinfo_str,	vmbus_child_pnpinfo_str),
+
+	/* Vmbus interface */
+	DEVMETHOD(vmbus_get_version,		vmbus_get_version_method),
+	DEVMETHOD(vmbus_probe_guid,		vmbus_probe_guid_method),
+
+	DEVMETHOD_END
+};
+
+static driver_t vmbus_driver = {
+	"vmbus",
+	vmbus_methods,
+	sizeof(struct vmbus_softc)
+};
+
+static devclass_t vmbus_devclass;
+
+DRIVER_MODULE(vmbus, acpi, vmbus_driver, vmbus_devclass, NULL, NULL);
+MODULE_DEPEND(vmbus, acpi, 1, 1, 1);
+MODULE_VERSION(vmbus, 1);
+
+static __inline struct vmbus_softc *
+vmbus_get_softc(void)
+{
+	return vmbus_sc;
+}
+
 static struct vmbus_msghc *
 vmbus_msghc_alloc(bus_dma_tag_t parent_dtag)
 {
@@ -1316,24 +1367,6 @@ vmbus_attach(device_t dev)
 	return (0);
 }
 
-static void
-vmbus_sysinit(void *arg __unused)
-{
-	struct vmbus_softc *sc = vmbus_get_softc();
-
-	if (vm_guest != VM_GUEST_HV || sc == NULL)
-		return;
-
-	/* 
-	 * If the system has already booted and thread
-	 * scheduling is possible, as indicated by the
-	 * global cold set to zero, we just call the driver
-	 * initialization directly.
-	 */
-	if (!cold) 
-		vmbus_doattach(sc);
-}
-
 static int
 vmbus_detach(device_t dev)
 {
@@ -1363,44 +1396,26 @@ vmbus_detach(device_t dev)
 	return (0);
 }
 
-static device_method_t vmbus_methods[] = {
-	/* Device interface */
-	DEVMETHOD(device_probe,			vmbus_probe),
-	DEVMETHOD(device_attach,		vmbus_attach),
-	DEVMETHOD(device_detach,		vmbus_detach),
-	DEVMETHOD(device_shutdown,		bus_generic_shutdown),
-	DEVMETHOD(device_suspend,		bus_generic_suspend),
-	DEVMETHOD(device_resume,		bus_generic_resume),
-
-	/* Bus interface */
-	DEVMETHOD(bus_add_child,		bus_generic_add_child),
-	DEVMETHOD(bus_print_child,		bus_generic_print_child),
-	DEVMETHOD(bus_read_ivar,		vmbus_read_ivar),
-	DEVMETHOD(bus_child_pnpinfo_str,	vmbus_child_pnpinfo_str),
-
-	/* Vmbus interface */
-	DEVMETHOD(vmbus_get_version,		vmbus_get_version_method),
-	DEVMETHOD(vmbus_probe_guid,		vmbus_probe_guid_method),
-
-	DEVMETHOD_END
-};
-
-static driver_t vmbus_driver = {
-	"vmbus",
-	vmbus_methods,
-	sizeof(struct vmbus_softc)
-};
-
-static devclass_t vmbus_devclass;
+static void
+vmbus_sysinit(void *arg __unused)
+{
+	struct vmbus_softc *sc = vmbus_get_softc();
 
-DRIVER_MODULE(vmbus, acpi, vmbus_driver, vmbus_devclass, NULL, NULL);
-MODULE_DEPEND(vmbus, acpi, 1, 1, 1);
-MODULE_VERSION(vmbus, 1);
+	if (vm_guest != VM_GUEST_HV || sc == NULL)
+		return;
 
+	/* 
+	 * If the system has already booted and thread
+	 * scheduling is possible, as indicated by the
+	 * global cold set to zero, we just call the driver
+	 * initialization directly.
+	 */
+	if (!cold) 
+		vmbus_doattach(sc);
+}
 /*
  * NOTE:
  * We have to start as the last step of SI_SUB_SMP, i.e. after SMP is
  * initialized.
  */
 SYSINIT(vmbus_initialize, SI_SUB_SMP, SI_ORDER_ANY, vmbus_sysinit, NULL);
-

Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_br.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/vmbus_br.c	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/vmbus/vmbus_br.c	Wed Oct 12 08:58:03 2016	(r307133)
@@ -44,6 +44,10 @@ __FBSDID("$FreeBSD$");
 /* Increase bufing index */
 #define VMBUS_BR_IDXINC(idx, inc, sz)	(((idx) + (inc)) % (sz))
 
+static int			vmbus_br_sysctl_state(SYSCTL_HANDLER_ARGS);
+static int			vmbus_br_sysctl_state_bin(SYSCTL_HANDLER_ARGS);
+static void			vmbus_br_setup(struct vmbus_br *, void *, int);
+
 static int
 vmbus_br_sysctl_state(SYSCTL_HANDLER_ARGS)
 {
@@ -212,9 +216,7 @@ vmbus_txbr_need_signal(const struct vmbu
 	if (tbr->txbr_imask)
 		return (FALSE);
 
-	/* XXX only compiler fence is needed */
-	/* Read memory barrier */
-	rmb();
+	__compiler_membar();
 
 	/*
 	 * This is the only case we need to signal when the
@@ -311,15 +313,10 @@ vmbus_txbr_write(struct vmbus_txbr *tbr,
 	    sizeof(save_windex));
 
 	/*
-	 * XXX only compiler fence is needed.
-	 * Full memory barrier before upding the write index. 
-	 */
-	mb();
-
-	/*
 	 * Update the write index _after_ the channel packet
 	 * is copied.
 	 */
+	__compiler_membar();
 	tbr->txbr_windex = windex;
 
 	mtx_unlock_spin(&tbr->txbr_lock);
@@ -399,16 +396,9 @@ vmbus_rxbr_read(struct vmbus_rxbr *rbr, 
 	rindex = VMBUS_BR_IDXINC(rindex, sizeof(uint64_t), br_dsize);
 
 	/*
-	 * XXX only compiler fence is needed.
-	 * Make sure all reads are done before we update the read index since
-	 * the writer may start writing to the read area once the read index
-	 * is updated.
-	 */
-	wmb();
-
-	/*
 	 * Update the read index _after_ the channel packet is fetched.
 	 */
+	__compiler_membar();
 	rbr->rxbr_rindex = rindex;
 
 	mtx_unlock_spin(&rbr->rxbr_lock);

Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c	Wed Oct 12 08:58:03 2016	(r307133)
@@ -31,19 +31,14 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
-#include <sys/malloc.h>
-#include <sys/systm.h>
-#include <sys/mbuf.h>
 #include <sys/lock.h>
+#include <sys/malloc.h>
 #include <sys/mutex.h>
+#include <sys/smp.h>
 #include <sys/sysctl.h>
+#include <sys/systm.h>
 
 #include <machine/atomic.h>
-#include <machine/bus.h>
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
 
 #include <dev/hyperv/include/hyperv_busdma.h>
 #include <dev/hyperv/vmbus/hyperv_var.h>
@@ -52,17 +47,28 @@ __FBSDID("$FreeBSD$");
 #include <dev/hyperv/vmbus/vmbus_brvar.h>
 #include <dev/hyperv/vmbus/vmbus_chanvar.h>
 
-static void	vmbus_chan_update_evtflagcnt(struct vmbus_softc *,
-		    const struct vmbus_channel *);
-
-static void	vmbus_chan_task(void *, int);
-static void	vmbus_chan_task_nobatch(void *, int);
-static void	vmbus_chan_detach_task(void *, int);
-
-static void	vmbus_chan_msgproc_choffer(struct vmbus_softc *,
-		    const struct vmbus_message *);
-static void	vmbus_chan_msgproc_chrescind(struct vmbus_softc *,
-		    const struct vmbus_message *);
+static void			vmbus_chan_update_evtflagcnt(
+				    struct vmbus_softc *,
+				    const struct vmbus_channel *);
+static void			vmbus_chan_close_internal(
+				    struct vmbus_channel *);
+static int			vmbus_chan_sysctl_mnf(SYSCTL_HANDLER_ARGS);
+static void			vmbus_chan_sysctl_create(
+				    struct vmbus_channel *);
+static struct vmbus_channel	*vmbus_chan_alloc(struct vmbus_softc *);
+static void			vmbus_chan_free(struct vmbus_channel *);
+static int			vmbus_chan_add(struct vmbus_channel *);
+static void			vmbus_chan_cpu_default(struct vmbus_channel *);
+
+static void			vmbus_chan_task(void *, int);
+static void			vmbus_chan_task_nobatch(void *, int);
+static void			vmbus_chan_detach_task(void *, int);
+
+static void			vmbus_chan_msgproc_choffer(struct vmbus_softc *,
+				    const struct vmbus_message *);
+static void			vmbus_chan_msgproc_chrescind(
+				    struct vmbus_softc *,
+				    const struct vmbus_message *);
 
 /*
  * Vmbus channel message processing.

Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_chanvar.h
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/vmbus_chanvar.h	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/vmbus/vmbus_chanvar.h	Wed Oct 12 08:58:03 2016	(r307133)
@@ -155,9 +155,10 @@ struct vmbus_channel {
 struct vmbus_softc;
 struct vmbus_message;
 
-void	vmbus_event_proc(struct vmbus_softc *, int);
-void	vmbus_event_proc_compat(struct vmbus_softc *, int);
-void	vmbus_chan_msgproc(struct vmbus_softc *, const struct vmbus_message *);
-void	vmbus_chan_destroy_all(struct vmbus_softc *);
+void		vmbus_event_proc(struct vmbus_softc *, int);
+void		vmbus_event_proc_compat(struct vmbus_softc *, int);
+void		vmbus_chan_msgproc(struct vmbus_softc *,
+		    const struct vmbus_message *);
+void		vmbus_chan_destroy_all(struct vmbus_softc *);
 
 #endif	/* !_VMBUS_CHANVAR_H_ */

Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_et.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/vmbus_et.c	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/vmbus/vmbus_et.c	Wed Oct 12 08:58:03 2016	(r307133)
@@ -32,9 +32,8 @@ __FBSDID("$FreeBSD$");
 #include <sys/kernel.h>
 #include <sys/module.h>
 #include <sys/proc.h>
-#include <sys/systm.h>
 #include <sys/smp.h>
-#include <sys/time.h>
+#include <sys/systm.h>
 #include <sys/timeet.h>
 
 #include <machine/cpu.h>
@@ -59,8 +58,35 @@ __FBSDID("$FreeBSD$");
 					 CPUID_HV_MSR_SYNIC |		\
 					 CPUID_HV_MSR_SYNTIMER)
 
+static void			vmbus_et_identify(driver_t *, device_t);
+static int			vmbus_et_probe(device_t);
+static int			vmbus_et_attach(device_t);
+static int			vmbus_et_detach(device_t);
+static int			vmbus_et_start(struct eventtimer *, sbintime_t,
+				    sbintime_t);
+
 static struct eventtimer	vmbus_et;
 
+static device_method_t vmbus_et_methods[] = {
+	DEVMETHOD(device_identify,	vmbus_et_identify),
+	DEVMETHOD(device_probe,		vmbus_et_probe),
+	DEVMETHOD(device_attach,	vmbus_et_attach),
+	DEVMETHOD(device_detach,	vmbus_et_detach),
+
+	DEVMETHOD_END
+};
+
+static driver_t vmbus_et_driver = {
+	VMBUS_ET_NAME,
+	vmbus_et_methods,
+	0
+};
+
+static devclass_t vmbus_et_devclass;
+
+DRIVER_MODULE(hv_et, vmbus, vmbus_et_driver, vmbus_et_devclass, NULL, NULL);
+MODULE_VERSION(hv_et, 1);
+
 static __inline uint64_t
 hyperv_sbintime2count(sbintime_t time)
 {
@@ -177,22 +203,3 @@ vmbus_et_detach(device_t dev)
 {
 	return (et_deregister(&vmbus_et));
 }
-
-static device_method_t vmbus_et_methods[] = {
-	DEVMETHOD(device_identify,	vmbus_et_identify),
-	DEVMETHOD(device_probe,		vmbus_et_probe),
-	DEVMETHOD(device_attach,	vmbus_et_attach),
-	DEVMETHOD(device_detach,	vmbus_et_detach),
-
-	DEVMETHOD_END
-};
-
-static driver_t vmbus_et_driver = {
-	VMBUS_ET_NAME,
-	vmbus_et_methods,
-	0
-};
-
-static devclass_t vmbus_et_devclass;
-DRIVER_MODULE(hv_et, vmbus, vmbus_et_driver, vmbus_et_devclass, NULL, NULL);
-MODULE_VERSION(hv_et, 1);

Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/vmbus_var.h	Wed Oct 12 08:25:13 2016	(r307132)
+++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h	Wed Oct 12 08:58:03 2016	(r307133)
@@ -120,20 +120,6 @@ struct vmbus_softc {
 #define VMBUS_FLAG_ATTACHED	0x0001	/* vmbus was attached */
 #define VMBUS_FLAG_SYNIC	0x0002	/* SynIC was setup */
 
-extern struct vmbus_softc	*vmbus_sc;
-
-static __inline struct vmbus_softc *
-vmbus_get_softc(void)
-{
-	return vmbus_sc;
-}
-
-static __inline device_t
-vmbus_get_device(void)
-{
-	return vmbus_sc->vmbus_dev;
-}
-
 #define VMBUS_PCPU_GET(sc, field, cpu)	(sc)->vmbus_pcpu[(cpu)].field
 #define VMBUS_PCPU_PTR(sc, field, cpu)	&(sc)->vmbus_pcpu[(cpu)].field
 
@@ -142,20 +128,23 @@ struct trapframe;
 struct vmbus_message;
 struct vmbus_msghc;
 
-void	vmbus_handle_intr(struct trapframe *);
-int	vmbus_add_child(struct vmbus_channel *);
-int	vmbus_delete_child(struct vmbus_channel *);
-void	vmbus_et_intr(struct trapframe *);
-uint32_t vmbus_gpadl_alloc(struct vmbus_softc *);
-
-struct vmbus_msghc *vmbus_msghc_get(struct vmbus_softc *, size_t);
-void	vmbus_msghc_put(struct vmbus_softc *, struct vmbus_msghc *);
-void	*vmbus_msghc_dataptr(struct vmbus_msghc *);
-int	vmbus_msghc_exec_noresult(struct vmbus_msghc *);
-int	vmbus_msghc_exec(struct vmbus_softc *, struct vmbus_msghc *);
-const struct vmbus_message *vmbus_msghc_wait_result(struct vmbus_softc *,
-	    struct vmbus_msghc *);
-void	vmbus_msghc_wakeup(struct vmbus_softc *, const struct vmbus_message *);
-void	vmbus_msghc_reset(struct vmbus_msghc *, size_t);
+void		vmbus_handle_intr(struct trapframe *);
+int		vmbus_add_child(struct vmbus_channel *);
+int		vmbus_delete_child(struct vmbus_channel *);
+void		vmbus_et_intr(struct trapframe *);
+uint32_t	vmbus_gpadl_alloc(struct vmbus_softc *);
+
+struct vmbus_msghc *
+		vmbus_msghc_get(struct vmbus_softc *, size_t);
+void		vmbus_msghc_put(struct vmbus_softc *, struct vmbus_msghc *);
+void		*vmbus_msghc_dataptr(struct vmbus_msghc *);
+int		vmbus_msghc_exec_noresult(struct vmbus_msghc *);
+int		vmbus_msghc_exec(struct vmbus_softc *, struct vmbus_msghc *);
+const struct vmbus_message *
+		vmbus_msghc_wait_result(struct vmbus_softc *,
+		    struct vmbus_msghc *);
+void		vmbus_msghc_wakeup(struct vmbus_softc *,
+		    const struct vmbus_message *);
+void		vmbus_msghc_reset(struct vmbus_msghc *, size_t);
 
 #endif	/* !_VMBUS_VAR_H_ */



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