diff options
-rw-r--r-- | sys/dev/hyperv/utilities/hv_heartbeat.c | 24 | ||||
-rw-r--r-- | sys/dev/hyperv/utilities/hv_kvp.c | 10 | ||||
-rw-r--r-- | sys/dev/hyperv/utilities/hv_shutdown.c | 24 | ||||
-rw-r--r-- | sys/dev/hyperv/utilities/hv_snapshot.c | 10 | ||||
-rw-r--r-- | sys/dev/hyperv/utilities/hv_timesync.c | 26 | ||||
-rw-r--r-- | sys/dev/hyperv/utilities/hv_util.c | 41 | ||||
-rw-r--r-- | sys/dev/hyperv/utilities/vmbus_icvar.h (renamed from sys/dev/hyperv/utilities/hv_util.h) | 27 |
7 files changed, 89 insertions, 73 deletions
diff --git a/sys/dev/hyperv/utilities/hv_heartbeat.c b/sys/dev/hyperv/utilities/hv_heartbeat.c index 8fc7a09..04366c6 100644 --- a/sys/dev/hyperv/utilities/hv_heartbeat.c +++ b/sys/dev/hyperv/utilities/hv_heartbeat.c @@ -35,8 +35,8 @@ __FBSDID("$FreeBSD$"); #include <dev/hyperv/include/hyperv.h> #include <dev/hyperv/include/vmbus.h> -#include <dev/hyperv/utilities/hv_util.h> #include <dev/hyperv/utilities/vmbus_icreg.h> +#include <dev/hyperv/utilities/vmbus_icvar.h> #include "vmbus_if.h" @@ -61,7 +61,7 @@ static const struct vmbus_ic_desc vmbus_heartbeat_descs[] = { static void vmbus_heartbeat_cb(struct vmbus_channel *chan, void *xsc) { - struct hv_util_sc *sc = xsc; + struct vmbus_ic_softc *sc = xsc; struct vmbus_icmsg_hdr *hdr; int dlen, error; uint64_t xactid; @@ -70,7 +70,7 @@ vmbus_heartbeat_cb(struct vmbus_channel *chan, void *xsc) /* * Receive request. */ - data = sc->receive_buffer; + data = sc->ic_buf; dlen = sc->ic_buflen; error = vmbus_chan_recv(chan, data, &dlen, &xactid); KASSERT(error != ENOBUFS, ("icbuf is not large enough")); @@ -110,13 +110,9 @@ vmbus_heartbeat_cb(struct vmbus_channel *chan, void *xsc) } /* - * Send response by echoing the updated request back. + * Send response by echoing the request back. */ - hdr->ic_flags = VMBUS_ICMSG_FLAG_XACT | VMBUS_ICMSG_FLAG_RESP; - error = vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_INBAND, 0, - data, dlen, xactid); - if (error) - device_printf(sc->ic_dev, "resp send failed: %d\n", error); + vmbus_ic_sendresp(sc, chan, data, dlen, xactid); } static int @@ -130,18 +126,22 @@ static int hv_heartbeat_attach(device_t dev) { - return (hv_util_attach(dev, vmbus_heartbeat_cb)); + return (vmbus_ic_attach(dev, vmbus_heartbeat_cb)); } static device_method_t heartbeat_methods[] = { /* Device interface */ DEVMETHOD(device_probe, hv_heartbeat_probe), DEVMETHOD(device_attach, hv_heartbeat_attach), - DEVMETHOD(device_detach, hv_util_detach), + DEVMETHOD(device_detach, vmbus_ic_detach), { 0, 0 } }; -static driver_t heartbeat_driver = { "hvheartbeat", heartbeat_methods, sizeof(hv_util_sc)}; +static driver_t heartbeat_driver = { + "hvheartbeat", + heartbeat_methods, + sizeof(struct vmbus_ic_softc) +}; static devclass_t heartbeat_devclass; diff --git a/sys/dev/hyperv/utilities/hv_kvp.c b/sys/dev/hyperv/utilities/hv_kvp.c index 3753c2f..48218b8 100644 --- a/sys/dev/hyperv/utilities/hv_kvp.c +++ b/sys/dev/hyperv/utilities/hv_kvp.c @@ -64,8 +64,8 @@ __FBSDID("$FreeBSD$"); #include <dev/hyperv/include/vmbus.h> #include <dev/hyperv/utilities/hv_utilreg.h> #include <dev/hyperv/utilities/vmbus_icreg.h> +#include <dev/hyperv/utilities/vmbus_icvar.h> -#include "hv_util.h" #include "unicode.h" #include "hv_kvp.h" #include "vmbus_if.h" @@ -128,7 +128,7 @@ static struct cdevsw hv_kvp_cdevsw = * KVP transaction requests from the host. */ typedef struct hv_kvp_sc { - struct hv_util_sc util_sc; + struct vmbus_ic_softc util_sc; device_t dev; /* Unless specified the pending mutex should be @@ -590,7 +590,7 @@ hv_kvp_process_request(void *context, int pending) hv_kvp_log_info("%s: entering hv_kvp_process_request\n", __func__); sc = (hv_kvp_sc*)context; - kvp_buf = sc->util_sc.receive_buffer;; + kvp_buf = sc->util_sc.ic_buf; channel = vmbus_get_channel(sc->dev); recvlen = sc->util_sc.ic_buflen; @@ -885,7 +885,7 @@ hv_kvp_attach(device_t dev) return (error); sc->hv_kvp_dev->si_drv1 = sc; - return hv_util_attach(dev, hv_kvp_callback); + return (vmbus_ic_attach(dev, hv_kvp_callback)); } static int @@ -900,7 +900,7 @@ hv_kvp_detach(device_t dev) } destroy_dev(sc->hv_kvp_dev); - return hv_util_detach(dev); + return (vmbus_ic_detach(dev)); } static device_method_t kvp_methods[] = { diff --git a/sys/dev/hyperv/utilities/hv_shutdown.c b/sys/dev/hyperv/utilities/hv_shutdown.c index e511b21..701d64c 100644 --- a/sys/dev/hyperv/utilities/hv_shutdown.c +++ b/sys/dev/hyperv/utilities/hv_shutdown.c @@ -36,8 +36,8 @@ __FBSDID("$FreeBSD$"); #include <dev/hyperv/include/hyperv.h> #include <dev/hyperv/include/vmbus.h> -#include <dev/hyperv/utilities/hv_util.h> #include <dev/hyperv/utilities/vmbus_icreg.h> +#include <dev/hyperv/utilities/vmbus_icvar.h> #include "vmbus_if.h" @@ -62,7 +62,7 @@ static const struct vmbus_ic_desc vmbus_shutdown_descs[] = { static void vmbus_shutdown_cb(struct vmbus_channel *chan, void *xsc) { - struct hv_util_sc *sc = xsc; + struct vmbus_ic_softc *sc = xsc; struct vmbus_icmsg_hdr *hdr; struct vmbus_icmsg_shutdown *msg; int dlen, error, do_shutdown = 0; @@ -72,7 +72,7 @@ vmbus_shutdown_cb(struct vmbus_channel *chan, void *xsc) /* * Receive request. */ - data = sc->receive_buffer; + data = sc->ic_buf; dlen = sc->ic_buflen; error = vmbus_chan_recv(chan, data, &dlen, &xactid); KASSERT(error != ENOBUFS, ("icbuf is not large enough")); @@ -122,13 +122,9 @@ vmbus_shutdown_cb(struct vmbus_channel *chan, void *xsc) } /* - * Send response by echoing the updated request back. + * Send response by echoing the request back. */ - hdr->ic_flags = VMBUS_ICMSG_FLAG_XACT | VMBUS_ICMSG_FLAG_RESP; - error = vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_INBAND, 0, - data, dlen, xactid); - if (error) - device_printf(sc->ic_dev, "resp send failed: %d\n", error); + vmbus_ic_sendresp(sc, chan, data, dlen, xactid); if (do_shutdown) shutdown_nice(RB_POWEROFF); @@ -145,18 +141,22 @@ static int hv_shutdown_attach(device_t dev) { - return (hv_util_attach(dev, vmbus_shutdown_cb)); + return (vmbus_ic_attach(dev, vmbus_shutdown_cb)); } static device_method_t shutdown_methods[] = { /* Device interface */ DEVMETHOD(device_probe, hv_shutdown_probe), DEVMETHOD(device_attach, hv_shutdown_attach), - DEVMETHOD(device_detach, hv_util_detach), + DEVMETHOD(device_detach, vmbus_ic_detach), { 0, 0 } }; -static driver_t shutdown_driver = { "hvshutdown", shutdown_methods, sizeof(hv_util_sc)}; +static driver_t shutdown_driver = { + "hvshutdown", + shutdown_methods, + sizeof(struct vmbus_ic_softc) +}; static devclass_t shutdown_devclass; diff --git a/sys/dev/hyperv/utilities/hv_snapshot.c b/sys/dev/hyperv/utilities/hv_snapshot.c index 2316297..45defe1 100644 --- a/sys/dev/hyperv/utilities/hv_snapshot.c +++ b/sys/dev/hyperv/utilities/hv_snapshot.c @@ -57,8 +57,8 @@ __FBSDID("$FreeBSD$"); #include <dev/hyperv/include/hyperv.h> #include <dev/hyperv/utilities/hv_utilreg.h> #include <dev/hyperv/utilities/vmbus_icreg.h> +#include <dev/hyperv/utilities/vmbus_icvar.h> -#include "hv_util.h" #include "hv_snapshot.h" #include "vmbus_if.h" @@ -204,7 +204,7 @@ struct hv_vss_dev_sc { * https://clovertrail.github.io/assets/vssdot.png */ typedef struct hv_vss_sc { - struct hv_util_sc util_sc; + struct vmbus_ic_softc util_sc; device_t dev; struct task task; @@ -808,7 +808,7 @@ hv_vss_process_request(void *context, int pending __unused) hv_vss_log_info("%s: entering hv_vss_process_request\n", __func__); sc = (hv_vss_sc*)context; - vss_buf = sc->util_sc.receive_buffer; + vss_buf = sc->util_sc.ic_buf; channel = vmbus_get_channel(sc->dev); recvlen = sc->util_sc.ic_buflen; @@ -1020,7 +1020,7 @@ hv_vss_attach(device_t dev) sc->hv_appvss_dev->si_drv1 = &sc->app_sc; sc->app_sc.sc = sc; - return hv_util_attach(dev, hv_vss_callback); + return (vmbus_ic_attach(dev, hv_vss_callback)); } static int @@ -1041,7 +1041,7 @@ hv_vss_detach(device_t dev) hv_vss_destroy_send_receive_queue(dev); destroy_dev(sc->hv_vss_dev); destroy_dev(sc->hv_appvss_dev); - return hv_util_detach(dev); + return (vmbus_ic_detach(dev)); } static device_method_t vss_methods[] = { diff --git a/sys/dev/hyperv/utilities/hv_timesync.c b/sys/dev/hyperv/utilities/hv_timesync.c index 4d166b0..65bf634 100644 --- a/sys/dev/hyperv/utilities/hv_timesync.c +++ b/sys/dev/hyperv/utilities/hv_timesync.c @@ -37,8 +37,8 @@ __FBSDID("$FreeBSD$"); #include <dev/hyperv/include/hyperv.h> #include <dev/hyperv/include/vmbus.h> -#include <dev/hyperv/utilities/hv_util.h> #include <dev/hyperv/utilities/vmbus_icreg.h> +#include <dev/hyperv/utilities/vmbus_icvar.h> #include "vmbus_if.h" @@ -85,7 +85,7 @@ SYSCTL_INT(_hw_hvtimesync, OID_AUTO, sample_verbose, CTLFLAG_RWTUN, &vmbus_ts_sample_verbose, 0, "Increase sample request verbosity."); static void -vmbus_timesync(struct hv_util_sc *sc, uint64_t hvtime, uint64_t sent_tc, +vmbus_timesync(struct vmbus_ic_softc *sc, uint64_t hvtime, uint64_t sent_tc, uint8_t tsflags) { struct timespec vm_ts; @@ -150,7 +150,7 @@ vmbus_timesync(struct hv_util_sc *sc, uint64_t hvtime, uint64_t sent_tc, static void vmbus_timesync_cb(struct vmbus_channel *chan, void *xsc) { - struct hv_util_sc *sc = xsc; + struct vmbus_ic_softc *sc = xsc; struct vmbus_icmsg_hdr *hdr; const struct vmbus_icmsg_timesync *msg; int dlen, error; @@ -160,7 +160,7 @@ vmbus_timesync_cb(struct vmbus_channel *chan, void *xsc) /* * Receive request. */ - data = sc->receive_buffer; + data = sc->ic_buf; dlen = sc->ic_buflen; error = vmbus_chan_recv(chan, data, &dlen, &xactid); KASSERT(error != ENOBUFS, ("icbuf is not large enough")); @@ -203,13 +203,9 @@ vmbus_timesync_cb(struct vmbus_channel *chan, void *xsc) } /* - * Send response by echoing the updated request back. + * Send response by echoing the request back. */ - hdr->ic_flags = VMBUS_ICMSG_FLAG_XACT | VMBUS_ICMSG_FLAG_RESP; - error = vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_INBAND, 0, - data, dlen, xactid); - if (error) - device_printf(sc->ic_dev, "resp send failed: %d\n", error); + vmbus_ic_sendresp(sc, chan, data, dlen, xactid); } static int @@ -223,18 +219,22 @@ static int hv_timesync_attach(device_t dev) { - return (hv_util_attach(dev, vmbus_timesync_cb)); + return (vmbus_ic_attach(dev, vmbus_timesync_cb)); } static device_method_t timesync_methods[] = { /* Device interface */ DEVMETHOD(device_probe, hv_timesync_probe), DEVMETHOD(device_attach, hv_timesync_attach), - DEVMETHOD(device_detach, hv_util_detach), + DEVMETHOD(device_detach, vmbus_ic_detach), { 0, 0 } }; -static driver_t timesync_driver = { "hvtimesync", timesync_methods, sizeof(hv_util_sc)}; +static driver_t timesync_driver = { + "hvtimesync", + timesync_methods, + sizeof(struct vmbus_ic_softc) +}; static devclass_t timesync_devclass; diff --git a/sys/dev/hyperv/utilities/hv_util.c b/sys/dev/hyperv/utilities/hv_util.c index 20b8f84..fa15c5a 100644 --- a/sys/dev/hyperv/utilities/hv_util.c +++ b/sys/dev/hyperv/utilities/hv_util.c @@ -42,8 +42,8 @@ #include <dev/hyperv/include/hyperv.h> #include <dev/hyperv/include/vmbus.h> -#include <dev/hyperv/utilities/hv_util.h> #include <dev/hyperv/utilities/vmbus_icreg.h> +#include <dev/hyperv/utilities/vmbus_icvar.h> #include "vmbus_if.h" @@ -58,7 +58,7 @@ static int vmbus_ic_fwver_sysctl(SYSCTL_HANDLER_ARGS); static int vmbus_ic_msgver_sysctl(SYSCTL_HANDLER_ARGS); int -vmbus_ic_negomsg(struct hv_util_sc *sc, void *data, int *dlen0, +vmbus_ic_negomsg(struct vmbus_ic_softc *sc, void *data, int *dlen0, uint32_t fw_ver, uint32_t msg_ver) { struct vmbus_icmsg_negotiate *nego; @@ -214,9 +214,9 @@ vmbus_ic_probe(device_t dev, const struct vmbus_ic_desc descs[]) } int -hv_util_attach(device_t dev, vmbus_chan_callback_t cb) +vmbus_ic_attach(device_t dev, vmbus_chan_callback_t cb) { - struct hv_util_sc *sc = device_get_softc(dev); + struct vmbus_ic_softc *sc = device_get_softc(dev); struct vmbus_channel *chan = vmbus_get_channel(dev); struct sysctl_oid_list *child; struct sysctl_ctx_list *ctx; @@ -224,8 +224,7 @@ hv_util_attach(device_t dev, vmbus_chan_callback_t cb) sc->ic_dev = dev; sc->ic_buflen = VMBUS_IC_BRSIZE; - sc->receive_buffer = malloc(VMBUS_IC_BRSIZE, M_DEVBUF, - M_WAITOK | M_ZERO); + sc->ic_buf = malloc(VMBUS_IC_BRSIZE, M_DEVBUF, M_WAITOK | M_ZERO); /* * These services are not performance critical and do not need @@ -239,7 +238,7 @@ hv_util_attach(device_t dev, vmbus_chan_callback_t cb) error = vmbus_chan_open(chan, VMBUS_IC_BRSIZE, VMBUS_IC_BRSIZE, NULL, 0, cb, sc); if (error) { - free(sc->receive_buffer, M_DEVBUF); + free(sc->ic_buf, M_DEVBUF); return (error); } @@ -258,7 +257,7 @@ hv_util_attach(device_t dev, vmbus_chan_callback_t cb) static int vmbus_ic_fwver_sysctl(SYSCTL_HANDLER_ARGS) { - struct hv_util_sc *sc = arg1; + struct vmbus_ic_softc *sc = arg1; char verstr[16]; snprintf(verstr, sizeof(verstr), "%u.%u", @@ -269,7 +268,7 @@ vmbus_ic_fwver_sysctl(SYSCTL_HANDLER_ARGS) static int vmbus_ic_msgver_sysctl(SYSCTL_HANDLER_ARGS) { - struct hv_util_sc *sc = arg1; + struct vmbus_ic_softc *sc = arg1; char verstr[16]; snprintf(verstr, sizeof(verstr), "%u.%u", @@ -278,12 +277,30 @@ vmbus_ic_msgver_sysctl(SYSCTL_HANDLER_ARGS) } int -hv_util_detach(device_t dev) +vmbus_ic_detach(device_t dev) { - struct hv_util_sc *sc = device_get_softc(dev); + struct vmbus_ic_softc *sc = device_get_softc(dev); vmbus_chan_close(vmbus_get_channel(dev)); - free(sc->receive_buffer, M_DEVBUF); + free(sc->ic_buf, M_DEVBUF); return (0); } + +int +vmbus_ic_sendresp(struct vmbus_ic_softc *sc, struct vmbus_channel *chan, + void *data, int dlen, uint64_t xactid) +{ + struct vmbus_icmsg_hdr *hdr; + int error; + + KASSERT(dlen >= sizeof(*hdr), ("invalid data length %d", dlen)); + hdr = data; + + hdr->ic_flags = VMBUS_ICMSG_FLAG_XACT | VMBUS_ICMSG_FLAG_RESP; + error = vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_INBAND, 0, + data, dlen, xactid); + if (error) + device_printf(sc->ic_dev, "resp send failed: %d\n", error); + return (error); +} diff --git a/sys/dev/hyperv/utilities/hv_util.h b/sys/dev/hyperv/utilities/vmbus_icvar.h index 7cf8d31..a60ecfe 100644 --- a/sys/dev/hyperv/utilities/hv_util.h +++ b/sys/dev/hyperv/utilities/vmbus_icvar.h @@ -28,23 +28,19 @@ * $FreeBSD$ */ -#ifndef _HVUTIL_H_ -#define _HVUTIL_H_ +#ifndef _VMBUS_ICVAR_H_ +#define _VMBUS_ICVAR_H_ #include <dev/hyperv/include/hyperv.h> #include <dev/hyperv/include/vmbus.h> -/** - * hv_util related structures - * - */ -typedef struct hv_util_sc { +struct vmbus_ic_softc { device_t ic_dev; - uint8_t *receive_buffer; + uint8_t *ic_buf; int ic_buflen; uint32_t ic_fwver; /* framework version */ uint32_t ic_msgver; /* message version */ -} hv_util_sc; +}; struct vmbus_ic_desc { const struct hyperv_guid ic_guid; @@ -53,10 +49,13 @@ struct vmbus_ic_desc { #define VMBUS_IC_DESC_END { .ic_desc = NULL } -int hv_util_attach(device_t dev, vmbus_chan_callback_t cb); -int hv_util_detach(device_t dev); +int vmbus_ic_attach(device_t dev, vmbus_chan_callback_t cb); +int vmbus_ic_detach(device_t dev); int vmbus_ic_probe(device_t dev, const struct vmbus_ic_desc descs[]); -int vmbus_ic_negomsg(struct hv_util_sc *sc, void *data, int *dlen, - uint32_t fw_ver, uint32_t msg_ver); +int vmbus_ic_negomsg(struct vmbus_ic_softc *sc, void *data, + int *dlen, uint32_t fw_ver, uint32_t msg_ver); +int vmbus_ic_sendresp(struct vmbus_ic_softc *sc, + struct vmbus_channel *chan, void *data, int dlen, + uint64_t xactid); -#endif +#endif /* !_VMBUS_ICVAR_H_ */ |