svn commit: r307029 - in stable/10/sys/dev/hyperv: include vmbus
Sepherosa Ziehau
sephe at FreeBSD.org
Tue Oct 11 08:29:06 UTC 2016
Author: sephe
Date: Tue Oct 11 08:29:04 2016
New Revision: 307029
URL: https://svnweb.freebsd.org/changeset/base/307029
Log:
MFC 302819,302823
302819
hyperv/vmbus: Sub-channel related fields renaming
And reorganize comment.
Sponsored by: Microsoft OSTC
Differential Revision: https://reviews.freebsd.org/D7113
302823
hyperv/vmbus: Move bus related message processing into vmbus.
Sponsored by: Microsoft OSTC
Differential Revision: https://reviews.freebsd.org/D7125
Modified:
stable/10/sys/dev/hyperv/include/hyperv.h
stable/10/sys/dev/hyperv/vmbus/hv_channel.c
stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c
stable/10/sys/dev/hyperv/vmbus/vmbus.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 Tue Oct 11 08:22:17 2016 (r307028)
+++ stable/10/sys/dev/hyperv/include/hyperv.h Tue Oct 11 08:29:04 2016 (r307029)
@@ -293,30 +293,17 @@ typedef struct hv_vmbus_channel {
uint32_t target_cpu;
/*
- * Support for multi-channels.
- * The initial offer is considered the primary channel and this
- * offer message will indicate if the host supports multi-channels.
- * The guest is free to ask for multi-channels to be offerred and can
- * open these multi-channels as a normal "primary" channel. However,
- * all multi-channels will have the same type and instance guids as the
- * primary channel. Requests sent on a given channel will result in a
- * response on the same channel.
+ * If this is a primary channel, ch_subchan* fields
+ * contain sub-channels belonging to this primary
+ * channel.
*/
-
- struct mtx sc_lock;
-
- /*
- * Link list of all the multi-channels if this is a primary channel
- */
- TAILQ_HEAD(, hv_vmbus_channel) sc_list_anchor;
- TAILQ_ENTRY(hv_vmbus_channel) sc_list_entry;
- int subchan_cnt;
-
- /*
- * The primary channel this sub-channle belongs to.
- * This will be NULL for the primary channel.
- */
- struct hv_vmbus_channel *primary_channel;
+ struct mtx ch_subchan_lock;
+ TAILQ_HEAD(, hv_vmbus_channel) ch_subchans;
+ int ch_subchan_cnt;
+
+ /* If this is a sub-channel */
+ TAILQ_ENTRY(hv_vmbus_channel) ch_sublink; /* sub-channel link */
+ struct hv_vmbus_channel *ch_prichan; /* owner primary chan */
/*
* Driver private data
Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_channel.c Tue Oct 11 08:22:17 2016 (r307028)
+++ stable/10/sys/dev/hyperv/vmbus/hv_channel.c Tue Oct 11 08:29:04 2016 (r307029)
@@ -100,7 +100,7 @@ vmbus_channel_sysctl_create(hv_vmbus_cha
uint16_t sub_ch_id;
char name[16];
- hv_vmbus_channel* primary_ch = channel->primary_channel;
+ hv_vmbus_channel* primary_ch = channel->ch_prichan;
if (primary_ch == NULL) {
dev = channel->ch_dev;
@@ -563,7 +563,7 @@ hv_vmbus_channel_close(struct hv_vmbus_c
/*
* Close all sub-channels, if any.
*/
- subchan_cnt = chan->subchan_cnt;
+ subchan_cnt = chan->ch_subchan_cnt;
if (subchan_cnt > 0) {
struct hv_vmbus_channel **subchan;
int i;
Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Tue Oct 11 08:22:17 2016 (r307028)
+++ stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Tue Oct 11 08:29:04 2016 (r307029)
@@ -40,13 +40,8 @@ __FBSDID("$FreeBSD$");
#include <dev/hyperv/vmbus/vmbus_reg.h>
#include <dev/hyperv/vmbus/vmbus_var.h>
-typedef void (*vmbus_chanmsg_proc_t)
- (struct vmbus_softc *, const struct vmbus_message *);
-
static void vmbus_chan_detach_task(void *, int);
-static void vmbus_channel_on_offers_delivered(struct vmbus_softc *,
- const struct vmbus_message *);
static void vmbus_chan_msgproc_choffer(struct vmbus_softc *,
const struct vmbus_message *);
static void vmbus_chan_msgproc_chrescind(struct vmbus_softc *,
@@ -55,27 +50,16 @@ static void vmbus_chan_msgproc_chrescind
/*
* Vmbus channel message processing.
*/
-
-#define VMBUS_CHANMSG_PROC(name, func) \
- [VMBUS_CHANMSG_TYPE_##name] = func
-#define VMBUS_CHANMSG_PROC_WAKEUP(name) \
- VMBUS_CHANMSG_PROC(name, vmbus_msghc_wakeup)
-
static const vmbus_chanmsg_proc_t
-vmbus_chanmsg_process[VMBUS_CHANMSG_TYPE_MAX] = {
+vmbus_chan_msgprocs[VMBUS_CHANMSG_TYPE_MAX] = {
VMBUS_CHANMSG_PROC(CHOFFER, vmbus_chan_msgproc_choffer),
VMBUS_CHANMSG_PROC(CHRESCIND, vmbus_chan_msgproc_chrescind),
- VMBUS_CHANMSG_PROC(CHOFFER_DONE,vmbus_channel_on_offers_delivered),
VMBUS_CHANMSG_PROC_WAKEUP(CHOPEN_RESP),
VMBUS_CHANMSG_PROC_WAKEUP(GPADL_CONNRESP),
- VMBUS_CHANMSG_PROC_WAKEUP(GPADL_DISCONNRESP),
- VMBUS_CHANMSG_PROC_WAKEUP(CONNECT_RESP)
+ VMBUS_CHANMSG_PROC_WAKEUP(GPADL_DISCONNRESP)
};
-#undef VMBUS_CHANMSG_PROC_WAKEUP
-#undef VMBUS_CHANMSG_PROC
-
static struct hv_vmbus_channel *
vmbus_chan_alloc(struct vmbus_softc *sc)
{
@@ -93,8 +77,8 @@ vmbus_chan_alloc(struct vmbus_softc *sc)
}
chan->vmbus_sc = sc;
- mtx_init(&chan->sc_lock, "vmbus multi channel", NULL, MTX_DEF);
- TAILQ_INIT(&chan->sc_list_anchor);
+ mtx_init(&chan->ch_subchan_lock, "vmbus subchan", NULL, MTX_DEF);
+ TAILQ_INIT(&chan->ch_subchans);
TASK_INIT(&chan->ch_detach_task, 0, vmbus_chan_detach_task, chan);
return chan;
@@ -107,7 +91,7 @@ vmbus_chan_free(struct hv_vmbus_channel
/* TODO: asset no longer on the primary channel's sub-channel list */
/* TODO: asset no longer on the vmbus channel list */
hyperv_dmamem_free(&chan->ch_monprm_dma, chan->ch_monprm);
- mtx_destroy(&chan->sc_lock);
+ mtx_destroy(&chan->ch_subchan_lock);
free(chan, M_DEVBUF);
}
@@ -139,6 +123,10 @@ vmbus_chan_add(struct hv_vmbus_channel *
mtx_lock(&sc->vmbus_prichan_lock);
TAILQ_FOREACH(prichan, &sc->vmbus_prichans, ch_prilink) {
+ /*
+ * Sub-channel will have the same type GUID and instance
+ * GUID as its primary channel.
+ */
if (memcmp(&prichan->ch_guid_type, &newchan->ch_guid_type,
sizeof(struct hyperv_guid)) == 0 &&
memcmp(&prichan->ch_guid_inst, &newchan->ch_guid_inst,
@@ -181,18 +169,18 @@ vmbus_chan_add(struct hv_vmbus_channel *
("new channel is not sub-channel"));
KASSERT(prichan != NULL, ("no primary channel"));
- newchan->primary_channel = prichan;
+ newchan->ch_prichan = prichan;
newchan->ch_dev = prichan->ch_dev;
- mtx_lock(&prichan->sc_lock);
- TAILQ_INSERT_TAIL(&prichan->sc_list_anchor, newchan, sc_list_entry);
+ mtx_lock(&prichan->ch_subchan_lock);
+ TAILQ_INSERT_TAIL(&prichan->ch_subchans, newchan, ch_sublink);
/*
* Bump up sub-channel count and notify anyone that is
* interested in this sub-channel, after this sub-channel
* is setup.
*/
- prichan->subchan_cnt++;
- mtx_unlock(&prichan->sc_lock);
+ prichan->ch_subchan_cnt++;
+ mtx_unlock(&prichan->ch_subchan_lock);
wakeup(prichan);
return 0;
@@ -345,7 +333,7 @@ vmbus_chan_detach_task(void *xchan, int
/* NOTE: DO NOT free primary channel for now */
} else {
struct vmbus_softc *sc = chan->vmbus_sc;
- struct hv_vmbus_channel *pri_chan = chan->primary_channel;
+ struct hv_vmbus_channel *pri_chan = chan->ch_prichan;
struct vmbus_chanmsg_chfree *req;
struct vmbus_msghc *mh;
int error;
@@ -377,31 +365,18 @@ vmbus_chan_detach_task(void *xchan, int
}
}
remove:
- mtx_lock(&pri_chan->sc_lock);
- TAILQ_REMOVE(&pri_chan->sc_list_anchor, chan, sc_list_entry);
- KASSERT(pri_chan->subchan_cnt > 0,
- ("invalid subchan_cnt %d", pri_chan->subchan_cnt));
- pri_chan->subchan_cnt--;
- mtx_unlock(&pri_chan->sc_lock);
+ mtx_lock(&pri_chan->ch_subchan_lock);
+ TAILQ_REMOVE(&pri_chan->ch_subchans, chan, ch_sublink);
+ KASSERT(pri_chan->ch_subchan_cnt > 0,
+ ("invalid subchan_cnt %d", pri_chan->ch_subchan_cnt));
+ pri_chan->ch_subchan_cnt--;
+ mtx_unlock(&pri_chan->ch_subchan_lock);
wakeup(pri_chan);
vmbus_chan_free(chan);
}
}
-/**
- *
- * @brief Invoked when all offers have been delivered.
- */
-static void
-vmbus_channel_on_offers_delivered(struct vmbus_softc *sc,
- const struct vmbus_message *msg __unused)
-{
-
- /* No more new channels for the channel request. */
- vmbus_scan_done(sc);
-}
-
/*
* Detach all devices and destroy the corresponding primary channels.
*/
@@ -445,7 +420,7 @@ vmbus_select_outgoing_channel(struct hv_
int cur_vcpu = 0;
int smp_pro_id = PCPU_GET(cpuid);
- if (TAILQ_EMPTY(&primary->sc_list_anchor)) {
+ if (TAILQ_EMPTY(&primary->ch_subchans)) {
return outgoing_channel;
}
@@ -455,7 +430,8 @@ vmbus_select_outgoing_channel(struct hv_
cur_vcpu = VMBUS_PCPU_GET(primary->vmbus_sc, vcpuid, smp_pro_id);
- TAILQ_FOREACH(new_channel, &primary->sc_list_anchor, sc_list_entry) {
+ /* XXX need lock */
+ TAILQ_FOREACH(new_channel, &primary->ch_subchans, ch_sublink) {
if ((new_channel->ch_stflags & VMBUS_CHAN_ST_OPENED) == 0) {
continue;
}
@@ -491,13 +467,13 @@ vmbus_get_subchan(struct hv_vmbus_channe
ret = malloc(subchan_cnt * sizeof(struct hv_vmbus_channel *), M_TEMP,
M_WAITOK);
- mtx_lock(&pri_chan->sc_lock);
+ mtx_lock(&pri_chan->ch_subchan_lock);
- while (pri_chan->subchan_cnt < subchan_cnt)
- mtx_sleep(pri_chan, &pri_chan->sc_lock, 0, "subch", 0);
+ while (pri_chan->ch_subchan_cnt < subchan_cnt)
+ mtx_sleep(pri_chan, &pri_chan->ch_subchan_lock, 0, "subch", 0);
i = 0;
- TAILQ_FOREACH(chan, &pri_chan->sc_list_anchor, sc_list_entry) {
+ TAILQ_FOREACH(chan, &pri_chan->ch_subchans, ch_sublink) {
/* TODO: refcnt chan */
ret[i] = chan;
@@ -506,9 +482,9 @@ vmbus_get_subchan(struct hv_vmbus_channe
break;
}
KASSERT(i == subchan_cnt, ("invalid subchan count %d, should be %d",
- pri_chan->subchan_cnt, subchan_cnt));
+ pri_chan->ch_subchan_cnt, subchan_cnt));
- mtx_unlock(&pri_chan->sc_lock);
+ mtx_unlock(&pri_chan->ch_subchan_lock);
return ret;
}
@@ -523,10 +499,10 @@ vmbus_rel_subchan(struct hv_vmbus_channe
void
vmbus_drain_subchan(struct hv_vmbus_channel *pri_chan)
{
- mtx_lock(&pri_chan->sc_lock);
- while (pri_chan->subchan_cnt > 0)
- mtx_sleep(pri_chan, &pri_chan->sc_lock, 0, "dsubch", 0);
- mtx_unlock(&pri_chan->sc_lock);
+ mtx_lock(&pri_chan->ch_subchan_lock);
+ while (pri_chan->ch_subchan_cnt > 0)
+ mtx_sleep(pri_chan, &pri_chan->ch_subchan_lock, 0, "dsubch", 0);
+ mtx_unlock(&pri_chan->ch_subchan_lock);
}
void
@@ -536,13 +512,10 @@ vmbus_chan_msgproc(struct vmbus_softc *s
uint32_t msg_type;
msg_type = ((const struct vmbus_chanmsg_hdr *)msg->msg_data)->chm_type;
- if (msg_type >= VMBUS_CHANMSG_TYPE_MAX) {
- device_printf(sc->vmbus_dev, "unknown message type 0x%x\n",
- msg_type);
- return;
- }
+ KASSERT(msg_type < VMBUS_CHANMSG_TYPE_MAX,
+ ("invalid message type %u", msg_type));
- msg_proc = vmbus_chanmsg_process[msg_type];
+ msg_proc = vmbus_chan_msgprocs[msg_type];
if (msg_proc != NULL)
msg_proc(sc, msg);
}
Modified: stable/10/sys/dev/hyperv/vmbus/vmbus.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/vmbus.c Tue Oct 11 08:22:17 2016 (r307028)
+++ stable/10/sys/dev/hyperv/vmbus/vmbus.c Tue Oct 11 08:29:04 2016 (r307029)
@@ -98,7 +98,12 @@ static int vmbus_req_channels(struct v
static void vmbus_disconnect(struct vmbus_softc *);
static int vmbus_scan(struct vmbus_softc *);
static void vmbus_scan_wait(struct vmbus_softc *);
+static void vmbus_scan_newchan(struct vmbus_softc *);
static void vmbus_scan_newdev(struct vmbus_softc *);
+static void vmbus_scan_done(struct vmbus_softc *,
+ const struct vmbus_message *);
+static void vmbus_chanmsg_handle(struct vmbus_softc *,
+ const struct vmbus_message *);
static int vmbus_sysctl_version(SYSCTL_HANDLER_ARGS);
@@ -122,6 +127,12 @@ static const uint32_t vmbus_version[] =
VMBUS_VERSION_WS2008
};
+static const vmbus_chanmsg_proc_t
+vmbus_chanmsg_handlers[VMBUS_CHANMSG_TYPE_MAX] = {
+ VMBUS_CHANMSG_PROC(CHOFFER_DONE, vmbus_scan_done),
+ VMBUS_CHANMSG_PROC_WAKEUP(CONNECT_RESP)
+};
+
static struct vmbus_msghc *
vmbus_msghc_alloc(bus_dma_tag_t parent_dtag)
{
@@ -480,7 +491,7 @@ vmbus_req_channels(struct vmbus_softc *s
return error;
}
-void
+static void
vmbus_scan_newchan(struct vmbus_softc *sc)
{
mtx_lock(&sc->vmbus_scan_lock);
@@ -489,8 +500,9 @@ vmbus_scan_newchan(struct vmbus_softc *s
mtx_unlock(&sc->vmbus_scan_lock);
}
-void
-vmbus_scan_done(struct vmbus_softc *sc)
+static void
+vmbus_scan_done(struct vmbus_softc *sc,
+ const struct vmbus_message *msg __unused)
{
mtx_lock(&sc->vmbus_scan_lock);
sc->vmbus_scan_chcnt |= VMBUS_SCAN_CHCNT_DONE;
@@ -560,6 +572,27 @@ vmbus_scan(struct vmbus_softc *sc)
}
static void
+vmbus_chanmsg_handle(struct vmbus_softc *sc, const struct vmbus_message *msg)
+{
+ vmbus_chanmsg_proc_t msg_proc;
+ uint32_t msg_type;
+
+ msg_type = ((const struct vmbus_chanmsg_hdr *)msg->msg_data)->chm_type;
+ if (msg_type >= VMBUS_CHANMSG_TYPE_MAX) {
+ device_printf(sc->vmbus_dev, "unknown message type 0x%x\n",
+ msg_type);
+ return;
+ }
+
+ msg_proc = vmbus_chanmsg_handlers[msg_type];
+ if (msg_proc != NULL)
+ msg_proc(sc, msg);
+
+ /* Channel specific processing */
+ vmbus_chan_msgproc(sc, msg);
+}
+
+static void
vmbus_msg_task(void *xsc, int pending __unused)
{
struct vmbus_softc *sc = xsc;
@@ -572,7 +605,7 @@ vmbus_msg_task(void *xsc, int pending __
break;
} else if (msg->msg_type == HYPERV_MSGTYPE_CHANNEL) {
/* Channel message */
- vmbus_chan_msgproc(sc,
+ vmbus_chanmsg_handle(sc,
__DEVOLATILE(const struct vmbus_message *, msg));
}
Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Tue Oct 11 08:22:17 2016 (r307028)
+++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Tue Oct 11 08:29:04 2016 (r307029)
@@ -51,6 +51,17 @@
#define VMBUS_CONNID_MESSAGE 1
#define VMBUS_CONNID_EVENT 2
+struct vmbus_message;
+struct vmbus_softc;
+
+typedef void (*vmbus_chanmsg_proc_t)(struct vmbus_softc *,
+ const struct vmbus_message *);
+
+#define VMBUS_CHANMSG_PROC(name, func) \
+ [VMBUS_CHANMSG_TYPE_##name] = func
+#define VMBUS_CHANMSG_PROC_WAKEUP(name) \
+ VMBUS_CHANMSG_PROC(name, vmbus_msghc_wakeup)
+
struct vmbus_pcpu_data {
u_long *intr_cnt; /* Hyper-V interrupt counter */
struct vmbus_message *message; /* shared messages */
@@ -150,9 +161,6 @@ const struct vmbus_message *vmbus_msghc_
void vmbus_msghc_wakeup(struct vmbus_softc *, const struct vmbus_message *);
void vmbus_msghc_reset(struct vmbus_msghc *, size_t);
-void vmbus_scan_done(struct vmbus_softc *);
-void vmbus_scan_newchan(struct vmbus_softc *);
-
uint32_t vmbus_gpadl_alloc(struct vmbus_softc *);
#endif /* !_VMBUS_VAR_H_ */
More information about the svn-src-stable-10
mailing list