From owner-svn-src-stable-11@freebsd.org Thu Jan 5 08:02:39 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 05C73CA0FA9; Thu, 5 Jan 2017 08:02:39 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C829D1CDB; Thu, 5 Jan 2017 08:02:38 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v0582cTN064991; Thu, 5 Jan 2017 08:02:38 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v0582bI4064983; Thu, 5 Jan 2017 08:02:37 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201701050802.v0582bI4064983@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 5 Jan 2017 08:02:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r311379 - stable/11/sys/dev/hyperv/utilities X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Jan 2017 08:02:39 -0000 Author: sephe Date: Thu Jan 5 08:02:37 2017 New Revision: 311379 URL: https://svnweb.freebsd.org/changeset/base/311379 Log: MFC 310312-310314 310312 hyperv/ic: Factor out function to send IC response Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8844 310313 hyperv/ic: Cleanup common struct and functions. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8845 310314 hyperv/ic: Rename cleaned up header file. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8846 Added: stable/11/sys/dev/hyperv/utilities/vmbus_icvar.h - copied unchanged from r310314, head/sys/dev/hyperv/utilities/vmbus_icvar.h Deleted: stable/11/sys/dev/hyperv/utilities/hv_util.h Modified: stable/11/sys/dev/hyperv/utilities/hv_heartbeat.c stable/11/sys/dev/hyperv/utilities/hv_kvp.c stable/11/sys/dev/hyperv/utilities/hv_shutdown.c stable/11/sys/dev/hyperv/utilities/hv_snapshot.c stable/11/sys/dev/hyperv/utilities/hv_timesync.c stable/11/sys/dev/hyperv/utilities/hv_util.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/hyperv/utilities/hv_heartbeat.c ============================================================================== --- stable/11/sys/dev/hyperv/utilities/hv_heartbeat.c Thu Jan 5 07:55:17 2017 (r311378) +++ stable/11/sys/dev/hyperv/utilities/hv_heartbeat.c Thu Jan 5 08:02:37 2017 (r311379) @@ -35,8 +35,8 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include +#include #include "vmbus_if.h" @@ -61,7 +61,7 @@ static const struct vmbus_ic_desc vmbus_ 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 /* * 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 } /* - * 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; Modified: stable/11/sys/dev/hyperv/utilities/hv_kvp.c ============================================================================== --- stable/11/sys/dev/hyperv/utilities/hv_kvp.c Thu Jan 5 07:55:17 2017 (r311378) +++ stable/11/sys/dev/hyperv/utilities/hv_kvp.c Thu Jan 5 08:02:37 2017 (r311379) @@ -64,8 +64,8 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include -#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, in 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[] = { Modified: stable/11/sys/dev/hyperv/utilities/hv_shutdown.c ============================================================================== --- stable/11/sys/dev/hyperv/utilities/hv_shutdown.c Thu Jan 5 07:55:17 2017 (r311378) +++ stable/11/sys/dev/hyperv/utilities/hv_shutdown.c Thu Jan 5 08:02:37 2017 (r311379) @@ -36,8 +36,8 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include +#include #include "vmbus_if.h" @@ -62,7 +62,7 @@ static const struct vmbus_ic_desc vmbus_ 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 * /* * 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 * } /* - * 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; Modified: stable/11/sys/dev/hyperv/utilities/hv_snapshot.c ============================================================================== --- stable/11/sys/dev/hyperv/utilities/hv_snapshot.c Thu Jan 5 07:55:17 2017 (r311378) +++ stable/11/sys/dev/hyperv/utilities/hv_snapshot.c Thu Jan 5 08:02:37 2017 (r311379) @@ -57,8 +57,8 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include -#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, in 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[] = { Modified: stable/11/sys/dev/hyperv/utilities/hv_timesync.c ============================================================================== --- stable/11/sys/dev/hyperv/utilities/hv_timesync.c Thu Jan 5 07:55:17 2017 (r311378) +++ stable/11/sys/dev/hyperv/utilities/hv_timesync.c Thu Jan 5 08:02:37 2017 (r311379) @@ -37,8 +37,8 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include +#include #include "vmbus_if.h" @@ -85,7 +85,7 @@ SYSCTL_INT(_hw_hvtimesync, OID_AUTO, sam &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, ui 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 * /* * 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 * } /* - * 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; Modified: stable/11/sys/dev/hyperv/utilities/hv_util.c ============================================================================== --- stable/11/sys/dev/hyperv/utilities/hv_util.c Thu Jan 5 07:55:17 2017 (r311378) +++ stable/11/sys/dev/hyperv/utilities/hv_util.c Thu Jan 5 08:02:37 2017 (r311379) @@ -42,8 +42,8 @@ #include #include -#include #include +#include #include "vmbus_if.h" @@ -58,7 +58,7 @@ static int vmbus_ic_fwver_sysctl(SYSCTL_ 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 struc } 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_ 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_ 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_ 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_ARG 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_AR } 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); +} Copied: stable/11/sys/dev/hyperv/utilities/vmbus_icvar.h (from r310314, head/sys/dev/hyperv/utilities/vmbus_icvar.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/sys/dev/hyperv/utilities/vmbus_icvar.h Thu Jan 5 08:02:37 2017 (r311379, copy of r310314, head/sys/dev/hyperv/utilities/vmbus_icvar.h) @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 2009-2012,2016 Microsoft Corp. + * Copyright (c) 2012 NetApp Inc. + * Copyright (c) 2012 Citrix Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _VMBUS_ICVAR_H_ +#define _VMBUS_ICVAR_H_ + +#include +#include + +struct vmbus_ic_softc { + device_t ic_dev; + uint8_t *ic_buf; + int ic_buflen; + uint32_t ic_fwver; /* framework version */ + uint32_t ic_msgver; /* message version */ +}; + +struct vmbus_ic_desc { + const struct hyperv_guid ic_guid; + const char *ic_desc; +}; + +#define VMBUS_IC_DESC_END { .ic_desc = NULL } + +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 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 /* !_VMBUS_ICVAR_H_ */