hyperv/vmbus: Make channel id a field of hv_vmbus_channel.

This prepares to remove the unnecessary offer message embedding in
hv_vmbus_channel.

MFC after:	1 week
Sponsored by:	Microsoft OSTC
Differential Revision:	https://reviews.freebsd.org/D7014
This commit is contained in:
Sepherosa Ziehau 2016-07-13 03:24:29 +00:00
parent e71d17193d
commit 2c4888c75b
4 changed files with 38 additions and 36 deletions

View File

@ -538,6 +538,7 @@ typedef struct hv_vmbus_channel {
struct vmbus_softc *vmbus_sc; struct vmbus_softc *vmbus_sc;
hv_vmbus_channel_state state; hv_vmbus_channel_state state;
hv_vmbus_channel_offer_channel offer_msg; hv_vmbus_channel_offer_channel offer_msg;
uint32_t ch_id; /* channel id */
/* /*
* These are based on the offer_msg.monitor_id. * These are based on the offer_msg.monitor_id.
* Save it here for easy access. * Save it here for easy access.

View File

@ -2953,7 +2953,7 @@ hn_channel_attach(struct hn_softc *sc, struct hv_vmbus_channel *chan)
chan->hv_chan_rxr = rxr; chan->hv_chan_rxr = rxr;
if (bootverbose) { if (bootverbose) {
if_printf(sc->hn_ifp, "link RX ring %d to channel%u\n", if_printf(sc->hn_ifp, "link RX ring %d to channel%u\n",
idx, chan->offer_msg.child_rel_id); idx, chan->ch_id);
} }
if (idx < sc->hn_tx_ring_inuse) { if (idx < sc->hn_tx_ring_inuse) {
@ -2967,7 +2967,7 @@ hn_channel_attach(struct hn_softc *sc, struct hv_vmbus_channel *chan)
txr->hn_chan = chan; txr->hn_chan = chan;
if (bootverbose) { if (bootverbose) {
if_printf(sc->hn_ifp, "link TX ring %d to channel%u\n", if_printf(sc->hn_ifp, "link TX ring %d to channel%u\n",
idx, chan->offer_msg.child_rel_id); idx, chan->ch_id);
} }
} }

View File

@ -62,7 +62,7 @@ static void
vmbus_channel_set_event(hv_vmbus_channel *channel) vmbus_channel_set_event(hv_vmbus_channel *channel)
{ {
struct vmbus_softc *sc = channel->vmbus_sc; struct vmbus_softc *sc = channel->vmbus_sc;
uint32_t chanid = channel->offer_msg.child_rel_id; uint32_t chanid = channel->ch_id;
atomic_set_long(&sc->vmbus_tx_evtflags[chanid >> VMBUS_EVTFLAG_SHIFT], atomic_set_long(&sc->vmbus_tx_evtflags[chanid >> VMBUS_EVTFLAG_SHIFT],
1UL << (chanid & VMBUS_EVTFLAG_MASK)); 1UL << (chanid & VMBUS_EVTFLAG_MASK));
@ -107,10 +107,10 @@ vmbus_channel_sysctl_create(hv_vmbus_channel* channel)
if (primary_ch == NULL) { if (primary_ch == NULL) {
dev = channel->device->device; dev = channel->device->device;
ch_id = channel->offer_msg.child_rel_id; ch_id = channel->ch_id;
} else { } else {
dev = primary_ch->device->device; dev = primary_ch->device->device;
ch_id = primary_ch->offer_msg.child_rel_id; ch_id = primary_ch->ch_id;
sub_ch_id = channel->offer_msg.offer.sub_channel_index; sub_ch_id = channel->offer_msg.offer.sub_channel_index;
} }
ctx = &channel->ch_sysctl_ctx; ctx = &channel->ch_sysctl_ctx;
@ -136,7 +136,7 @@ vmbus_channel_sysctl_create(hv_vmbus_channel* channel)
SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(devch_id_sysctl), SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(devch_id_sysctl),
OID_AUTO, "chanid", CTLFLAG_RD, OID_AUTO, "chanid", CTLFLAG_RD,
&channel->offer_msg.child_rel_id, 0, "channel id"); &channel->ch_id, 0, "channel id");
} }
SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(devch_id_sysctl), OID_AUTO, SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(devch_id_sysctl), OID_AUTO,
"cpu", CTLFLAG_RD, &channel->target_cpu, 0, "owner CPU id"); "cpu", CTLFLAG_RD, &channel->target_cpu, 0, "owner CPU id");
@ -190,7 +190,7 @@ hv_vmbus_channel_open(
if (user_data_len > VMBUS_CHANMSG_CHOPEN_UDATA_SIZE) { if (user_data_len > VMBUS_CHANMSG_CHOPEN_UDATA_SIZE) {
device_printf(sc->vmbus_dev, device_printf(sc->vmbus_dev,
"invalid udata len %u for chan%u\n", "invalid udata len %u for chan%u\n",
user_data_len, new_channel->offer_msg.child_rel_id); user_data_len, new_channel->ch_id);
return EINVAL; return EINVAL;
} }
@ -261,14 +261,14 @@ hv_vmbus_channel_open(
if (mh == NULL) { if (mh == NULL) {
device_printf(sc->vmbus_dev, device_printf(sc->vmbus_dev,
"can not get msg hypercall for chopen(chan%u)\n", "can not get msg hypercall for chopen(chan%u)\n",
new_channel->offer_msg.child_rel_id); new_channel->ch_id);
return ENXIO; return ENXIO;
} }
req = vmbus_msghc_dataptr(mh); req = vmbus_msghc_dataptr(mh);
req->chm_hdr.chm_type = VMBUS_CHANMSG_TYPE_CHOPEN; req->chm_hdr.chm_type = VMBUS_CHANMSG_TYPE_CHOPEN;
req->chm_chanid = new_channel->offer_msg.child_rel_id; req->chm_chanid = new_channel->ch_id;
req->chm_openid = new_channel->offer_msg.child_rel_id; req->chm_openid = new_channel->ch_id;
req->chm_gpadl = new_channel->ring_buffer_gpadl_handle; req->chm_gpadl = new_channel->ring_buffer_gpadl_handle;
req->chm_vcpuid = new_channel->target_vcpu; req->chm_vcpuid = new_channel->target_vcpu;
req->chm_rxbr_pgofs = send_ring_buffer_size >> PAGE_SHIFT; req->chm_rxbr_pgofs = send_ring_buffer_size >> PAGE_SHIFT;
@ -279,7 +279,7 @@ hv_vmbus_channel_open(
if (ret != 0) { if (ret != 0) {
device_printf(sc->vmbus_dev, device_printf(sc->vmbus_dev,
"chopen(chan%u) msg hypercall exec failed: %d\n", "chopen(chan%u) msg hypercall exec failed: %d\n",
new_channel->offer_msg.child_rel_id, ret); new_channel->ch_id, ret);
vmbus_msghc_put(sc, mh); vmbus_msghc_put(sc, mh);
return ret; return ret;
} }
@ -294,11 +294,11 @@ hv_vmbus_channel_open(
new_channel->state = HV_CHANNEL_OPENED_STATE; new_channel->state = HV_CHANNEL_OPENED_STATE;
if (bootverbose) { if (bootverbose) {
device_printf(sc->vmbus_dev, "chan%u opened\n", device_printf(sc->vmbus_dev, "chan%u opened\n",
new_channel->offer_msg.child_rel_id); new_channel->ch_id);
} }
} else { } else {
device_printf(sc->vmbus_dev, "failed to open chan%u\n", device_printf(sc->vmbus_dev, "failed to open chan%u\n",
new_channel->offer_msg.child_rel_id); new_channel->ch_id);
ret = ENXIO; ret = ENXIO;
} }
return (ret); return (ret);
@ -369,13 +369,13 @@ hv_vmbus_channel_establish_gpadl(struct hv_vmbus_channel *channel,
if (mh == NULL) { if (mh == NULL) {
device_printf(sc->vmbus_dev, device_printf(sc->vmbus_dev,
"can not get msg hypercall for gpadl->chan%u\n", "can not get msg hypercall for gpadl->chan%u\n",
channel->offer_msg.child_rel_id); channel->ch_id);
return EIO; return EIO;
} }
req = vmbus_msghc_dataptr(mh); req = vmbus_msghc_dataptr(mh);
req->chm_hdr.chm_type = VMBUS_CHANMSG_TYPE_GPADL_CONN; req->chm_hdr.chm_type = VMBUS_CHANMSG_TYPE_GPADL_CONN;
req->chm_chanid = channel->offer_msg.child_rel_id; req->chm_chanid = channel->ch_id;
req->chm_gpadl = gpadl; req->chm_gpadl = gpadl;
req->chm_range_len = range_len; req->chm_range_len = range_len;
req->chm_range_cnt = 1; req->chm_range_cnt = 1;
@ -388,7 +388,7 @@ hv_vmbus_channel_establish_gpadl(struct hv_vmbus_channel *channel,
if (error) { if (error) {
device_printf(sc->vmbus_dev, device_printf(sc->vmbus_dev,
"gpadl->chan%u msg hypercall exec failed: %d\n", "gpadl->chan%u msg hypercall exec failed: %d\n",
channel->offer_msg.child_rel_id, error); channel->ch_id, error);
vmbus_msghc_put(sc, mh); vmbus_msghc_put(sc, mh);
return error; return error;
} }
@ -424,12 +424,12 @@ hv_vmbus_channel_establish_gpadl(struct hv_vmbus_channel *channel,
if (status != 0) { if (status != 0) {
device_printf(sc->vmbus_dev, "gpadl->chan%u failed: " device_printf(sc->vmbus_dev, "gpadl->chan%u failed: "
"status %u\n", channel->offer_msg.child_rel_id, status); "status %u\n", channel->ch_id, status);
return EIO; return EIO;
} else { } else {
if (bootverbose) { if (bootverbose) {
device_printf(sc->vmbus_dev, "gpadl->chan%u " device_printf(sc->vmbus_dev, "gpadl->chan%u "
"succeeded\n", channel->offer_msg.child_rel_id); "succeeded\n", channel->ch_id);
} }
} }
return 0; return 0;
@ -450,20 +450,20 @@ hv_vmbus_channel_teardown_gpdal(struct hv_vmbus_channel *chan, uint32_t gpadl)
if (mh == NULL) { if (mh == NULL) {
device_printf(sc->vmbus_dev, device_printf(sc->vmbus_dev,
"can not get msg hypercall for gpa x->chan%u\n", "can not get msg hypercall for gpa x->chan%u\n",
chan->offer_msg.child_rel_id); chan->ch_id);
return EBUSY; return EBUSY;
} }
req = vmbus_msghc_dataptr(mh); req = vmbus_msghc_dataptr(mh);
req->chm_hdr.chm_type = VMBUS_CHANMSG_TYPE_GPADL_DISCONN; req->chm_hdr.chm_type = VMBUS_CHANMSG_TYPE_GPADL_DISCONN;
req->chm_chanid = chan->offer_msg.child_rel_id; req->chm_chanid = chan->ch_id;
req->chm_gpadl = gpadl; req->chm_gpadl = gpadl;
error = vmbus_msghc_exec(sc, mh); error = vmbus_msghc_exec(sc, mh);
if (error) { if (error) {
device_printf(sc->vmbus_dev, device_printf(sc->vmbus_dev,
"gpa x->chan%u msg hypercall exec failed: %d\n", "gpa x->chan%u msg hypercall exec failed: %d\n",
chan->offer_msg.child_rel_id, error); chan->ch_id, error);
vmbus_msghc_put(sc, mh); vmbus_msghc_put(sc, mh);
return error; return error;
} }
@ -502,13 +502,13 @@ hv_vmbus_channel_close_internal(hv_vmbus_channel *channel)
if (mh == NULL) { if (mh == NULL) {
device_printf(sc->vmbus_dev, device_printf(sc->vmbus_dev,
"can not get msg hypercall for chclose(chan%u)\n", "can not get msg hypercall for chclose(chan%u)\n",
channel->offer_msg.child_rel_id); channel->ch_id);
return; return;
} }
req = vmbus_msghc_dataptr(mh); req = vmbus_msghc_dataptr(mh);
req->chm_hdr.chm_type = VMBUS_CHANMSG_TYPE_CHCLOSE; req->chm_hdr.chm_type = VMBUS_CHANMSG_TYPE_CHCLOSE;
req->chm_chanid = channel->offer_msg.child_rel_id; req->chm_chanid = channel->ch_id;
error = vmbus_msghc_exec_noresult(mh); error = vmbus_msghc_exec_noresult(mh);
vmbus_msghc_put(sc, mh); vmbus_msghc_put(sc, mh);
@ -516,11 +516,11 @@ hv_vmbus_channel_close_internal(hv_vmbus_channel *channel)
if (error) { if (error) {
device_printf(sc->vmbus_dev, device_printf(sc->vmbus_dev,
"chclose(chan%u) msg hypercall exec failed: %d\n", "chclose(chan%u) msg hypercall exec failed: %d\n",
channel->offer_msg.child_rel_id, error); channel->ch_id, error);
return; return;
} else if (bootverbose) { } else if (bootverbose) {
device_printf(sc->vmbus_dev, "close chan%u\n", device_printf(sc->vmbus_dev, "close chan%u\n",
channel->offer_msg.child_rel_id); channel->ch_id);
} }
/* Tear down the gpadl for the channel's ring buffer */ /* Tear down the gpadl for the channel's ring buffer */
@ -957,7 +957,7 @@ vmbus_chan_update_evtflagcnt(struct vmbus_softc *sc,
volatile int *flag_cnt_ptr; volatile int *flag_cnt_ptr;
int flag_cnt; int flag_cnt;
flag_cnt = (chan->offer_msg.child_rel_id / VMBUS_EVTFLAG_LEN) + 1; flag_cnt = (chan->ch_id / VMBUS_EVTFLAG_LEN) + 1;
flag_cnt_ptr = VMBUS_PCPU_PTR(sc, event_flags_cnt, chan->target_cpu); flag_cnt_ptr = VMBUS_PCPU_PTR(sc, event_flags_cnt, chan->target_cpu);
for (;;) { for (;;) {
@ -970,7 +970,7 @@ vmbus_chan_update_evtflagcnt(struct vmbus_softc *sc,
if (bootverbose) { if (bootverbose) {
device_printf(sc->vmbus_dev, device_printf(sc->vmbus_dev,
"channel%u update cpu%d flag_cnt to %d\n", "channel%u update cpu%d flag_cnt to %d\n",
chan->offer_msg.child_rel_id, chan->ch_id,
chan->target_cpu, flag_cnt); chan->target_cpu, flag_cnt);
} }
break; break;

View File

@ -112,7 +112,7 @@ vmbus_channel_process_offer(hv_vmbus_channel *new_channel)
hv_vmbus_channel* channel; hv_vmbus_channel* channel;
uint32_t relid; uint32_t relid;
relid = new_channel->offer_msg.child_rel_id; relid = new_channel->ch_id;
/* /*
* Make sure this is a new offer * Make sure this is a new offer
*/ */
@ -148,10 +148,10 @@ vmbus_channel_process_offer(hv_vmbus_channel *new_channel)
logstr[0] = '\0'; logstr[0] = '\0';
if (channel != NULL) { if (channel != NULL) {
snprintf(logstr, sizeof(logstr), ", primary chan%u", snprintf(logstr, sizeof(logstr), ", primary chan%u",
channel->offer_msg.child_rel_id); channel->ch_id);
} }
device_printf(sc->vmbus_dev, "chan%u subchanid%u offer%s\n", device_printf(sc->vmbus_dev, "chan%u subchanid%u offer%s\n",
new_channel->offer_msg.child_rel_id, new_channel->ch_id,
new_channel->offer_msg.offer.sub_channel_index, logstr); new_channel->offer_msg.offer.sub_channel_index, logstr);
} }
@ -200,7 +200,7 @@ vmbus_channel_process_offer(hv_vmbus_channel *new_channel)
} }
printf("VMBUS: duplicated primary channel%u\n", printf("VMBUS: duplicated primary channel%u\n",
new_channel->offer_msg.child_rel_id); new_channel->ch_id);
hv_vmbus_free_vmbus_channel(new_channel); hv_vmbus_free_vmbus_channel(new_channel);
return; return;
} }
@ -241,7 +241,7 @@ vmbus_channel_cpu_set(struct hv_vmbus_channel *chan, int cpu)
if (bootverbose) { if (bootverbose) {
printf("vmbus_chan%u: assigned to cpu%u [vcpu%u]\n", printf("vmbus_chan%u: assigned to cpu%u [vcpu%u]\n",
chan->offer_msg.child_rel_id, chan->ch_id,
chan->target_cpu, chan->target_vcpu); chan->target_cpu, chan->target_vcpu);
} }
} }
@ -292,6 +292,7 @@ vmbus_channel_on_offer_internal(struct vmbus_softc *sc,
/* Allocate the channel object and save this offer */ /* Allocate the channel object and save this offer */
new_channel = hv_vmbus_allocate_channel(sc); new_channel = hv_vmbus_allocate_channel(sc);
new_channel->ch_id = offer->child_rel_id;
/* /*
* By default we setup state to enable batched * By default we setup state to enable batched
@ -379,13 +380,13 @@ vmbus_chan_detach_task(void *xchan, int pending __unused)
if (mh == NULL) { if (mh == NULL) {
device_printf(sc->vmbus_dev, device_printf(sc->vmbus_dev,
"can not get msg hypercall for chfree(chan%u)\n", "can not get msg hypercall for chfree(chan%u)\n",
chan->offer_msg.child_rel_id); chan->ch_id);
goto remove; goto remove;
} }
req = vmbus_msghc_dataptr(mh); req = vmbus_msghc_dataptr(mh);
req->chm_hdr.chm_type = VMBUS_CHANMSG_TYPE_CHFREE; req->chm_hdr.chm_type = VMBUS_CHANMSG_TYPE_CHFREE;
req->chm_chanid = chan->offer_msg.child_rel_id; req->chm_chanid = chan->ch_id;
error = vmbus_msghc_exec_noresult(mh); error = vmbus_msghc_exec_noresult(mh);
vmbus_msghc_put(sc, mh); vmbus_msghc_put(sc, mh);
@ -393,12 +394,12 @@ vmbus_chan_detach_task(void *xchan, int pending __unused)
if (error) { if (error) {
device_printf(sc->vmbus_dev, device_printf(sc->vmbus_dev,
"chfree(chan%u) failed: %d", "chfree(chan%u) failed: %d",
chan->offer_msg.child_rel_id, error); chan->ch_id, error);
/* NOTE: Move on! */ /* NOTE: Move on! */
} else { } else {
if (bootverbose) { if (bootverbose) {
device_printf(sc->vmbus_dev, "chan%u freed\n", device_printf(sc->vmbus_dev, "chan%u freed\n",
chan->offer_msg.child_rel_id); chan->ch_id);
} }
} }
remove: remove: