Index: sys/dev/hyperv/vmbus/hv_connection.c =================================================================== --- sys/dev/hyperv/vmbus/hv_connection.c +++ sys/dev/hyperv/vmbus/hv_connection.c @@ -92,19 +92,13 @@ int hv_vmbus_disconnect(void) { - int ret = 0; - hv_vmbus_channel_unload msg; - - msg.message_type = HV_CHANNEL_MESSAGE_UNLOAD; - - ret = hv_vmbus_post_message(&msg, sizeof(hv_vmbus_channel_unload)); mtx_destroy(&hv_vmbus_g_connection.channel_msg_lock); free(hv_vmbus_g_connection.channels, M_DEVBUF); hv_vmbus_g_connection.connect_state = HV_DISCONNECTED; - return (ret); + return (0); } static __inline void Index: sys/dev/hyperv/vmbus/vmbus.c =================================================================== --- sys/dev/hyperv/vmbus/vmbus.c +++ sys/dev/hyperv/vmbus/vmbus.c @@ -99,6 +99,7 @@ static int vmbus_init_contact(struct vmbus_softc *, uint32_t); static int vmbus_req_channels(struct vmbus_softc *sc); +static void vmbus_uninit(struct vmbus_softc *); static int vmbus_sysctl_version(SYSCTL_HANDLER_ARGS); @@ -420,6 +421,32 @@ return ENXIO; } +static void +vmbus_uninit(struct vmbus_softc *sc) +{ + struct vmbus_chanmsg_unload *req; + struct vmbus_msghc *mh; + int error; + + mh = vmbus_msghc_get(sc, sizeof(*req)); + if (mh == NULL) { + device_printf(sc->vmbus_dev, + "can not get msg hypercall for unload\n"); + return; + } + + req = vmbus_msghc_dataptr(mh); + req->chm_hdr.chm_type = VMBUS_CHANMSG_TYPE_UNLOAD; + + error = vmbus_msghc_exec_noresult(mh); + vmbus_msghc_put(sc, mh); + + if (error) { + device_printf(sc->vmbus_dev, + "unload msg hypercall failed\n"); + } +} + static int vmbus_req_channels(struct vmbus_softc *sc) { @@ -1134,6 +1161,8 @@ struct vmbus_softc *sc = device_get_softc(dev); hv_vmbus_release_unattached_channels(); + + vmbus_uninit(sc); hv_vmbus_disconnect(); if (sc->vmbus_flags & VMBUS_FLAG_SYNIC) { Index: sys/dev/hyperv/vmbus/vmbus_reg.h =================================================================== --- sys/dev/hyperv/vmbus/vmbus_reg.h +++ sys/dev/hyperv/vmbus/vmbus_reg.h @@ -86,6 +86,7 @@ #define VMBUS_CHANMSG_TYPE_CHANNEL_REQ 3 /* REQ */ #define VMBUS_CHANMSG_TYPE_INIT_CONTACT 14 /* REQ */ #define VMBUS_CHANMSG_TYPE_VERSION_RESP 15 /* RESP */ +#define VMBUS_CHANMSG_TYPE_UNLOAD 16 /* REQ */ struct vmbus_chanmsg_hdr { uint32_t chm_type; /* VMBUS_CHANMSG_TYPE_ */ @@ -113,4 +114,9 @@ struct vmbus_chanmsg_hdr chm_hdr; } __packed; +/* VMBUS_CHANMSG_TYPE_UNLOAD */ +struct vmbus_chanmsg_unload { + struct vmbus_chanmsg_hdr chm_hdr; +} __packed; + #endif /* !_VMBUS_REG_H_ */