hyperv/vmbus: Use post message Hypercall APIs for unload

MFC after:	1 week
Sponsored by:	Microsoft OSTC
Differential Revision:	https://reviews.freebsd.org/D6861
This commit is contained in:
Sepherosa Ziehau 2016-07-11 07:28:15 +00:00
parent 789872f2e9
commit 1ecb24660f
3 changed files with 36 additions and 7 deletions

View File

@ -92,19 +92,13 @@ hv_vmbus_connect(struct vmbus_softc *sc)
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

View File

@ -99,6 +99,7 @@ static int vmbus_init(struct vmbus_softc *);
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 @@ vmbus_init(struct vmbus_softc *sc)
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 @@ vmbus_detach(device_t dev)
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) {

View File

@ -86,6 +86,7 @@ CTASSERT(sizeof(struct vmbus_evtflags) == VMBUS_EVTFLAGS_SIZE);
#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_channel_req {
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_ */