Index: head/sys/dev/hyperv/include/hyperv.h =================================================================== --- head/sys/dev/hyperv/include/hyperv.h +++ head/sys/dev/hyperv/include/hyperv.h @@ -523,12 +523,13 @@ hv_vmbus_channel_state state; uint32_t ch_flags; /* VMBUS_CHAN_FLAG_ */ uint32_t ch_id; /* channel id */ + /* * These are based on the offer_msg.monitor_id. * Save it here for easy access. */ - uint8_t monitor_group; - uint8_t monitor_bit; + int ch_montrig_idx; /* MNF trig index */ + uint32_t ch_montrig_mask;/* MNF trig mask */ uint32_t ring_buffer_gpadl_handle; /* Index: head/sys/dev/hyperv/vmbus/hv_channel.c =================================================================== --- head/sys/dev/hyperv/vmbus/hv_channel.c +++ head/sys/dev/hyperv/vmbus/hv_channel.c @@ -50,7 +50,7 @@ #include #include -static void vmbus_channel_set_event(hv_vmbus_channel* channel); +static void vmbus_chan_send_event(hv_vmbus_channel* channel); static void vmbus_chan_update_evtflagcnt(struct vmbus_softc *, const struct hv_vmbus_channel *); static void vmbus_chan_task(void *, int); @@ -60,7 +60,7 @@ * @brief Trigger an event notification on the specified channel */ static void -vmbus_channel_set_event(hv_vmbus_channel *channel) +vmbus_chan_send_event(hv_vmbus_channel *channel) { struct vmbus_softc *sc = channel->vmbus_sc; uint32_t chanid = channel->ch_id; @@ -69,16 +69,12 @@ 1UL << (chanid & VMBUS_EVTFLAG_MASK)); if (channel->ch_flags & VMBUS_CHAN_FLAG_HASMNF) { - hv_vmbus_monitor_page *monitor_page; - - monitor_page = sc->vmbus_mnf2; - synch_set_bit(channel->monitor_bit, - (uint32_t *)&monitor_page-> - trigger_group[channel->monitor_group].u.pending); + atomic_set_int( + &sc->vmbus_mnf2->mnf_trigs[channel->ch_montrig_idx].mt_pending, + channel->ch_montrig_mask); } else { hypercall_signal_event(channel->ch_monprm_dma.hv_paddr); } - } static int @@ -622,9 +618,8 @@ &need_sig); /* TODO: We should determine if this is optional */ - if (ret == 0 && need_sig) { - vmbus_channel_set_event(channel); - } + if (ret == 0 && need_sig) + vmbus_chan_send_event(channel); return (ret); } @@ -690,9 +685,8 @@ &need_sig); /* TODO: We should determine if this is optional */ - if (ret == 0 && need_sig) { - vmbus_channel_set_event(channel); - } + if (ret == 0 && need_sig) + vmbus_chan_send_event(channel); return (ret); } @@ -766,9 +760,8 @@ &need_sig); /* TODO: We should determine if this is optional */ - if (ret == 0 && need_sig) { - vmbus_channel_set_event(channel); - } + if (ret == 0 && need_sig) + vmbus_chan_send_event(channel); return (ret); } Index: head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c =================================================================== --- head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c +++ head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c @@ -311,8 +311,14 @@ if (sc->vmbus_version != VMBUS_VERSION_WS2008) new_channel->ch_monprm->mp_connid = offer->connection_id; - new_channel->monitor_group = (uint8_t) offer->monitor_id / 32; - new_channel->monitor_bit = (uint8_t) offer->monitor_id % 32; + if (new_channel->ch_flags & VMBUS_CHAN_FLAG_HASMNF) { + new_channel->ch_montrig_idx = + offer->monitor_id / VMBUS_MONTRIG_LEN; + if (new_channel->ch_montrig_idx >= VMBUS_MONTRIGS_MAX) + panic("invalid monitor id %u", offer->monitor_id); + new_channel->ch_montrig_mask = + 1 << (offer->monitor_id % VMBUS_MONTRIG_LEN); + } /* Select default cpu for this channel. */ vmbus_channel_select_defcpu(new_channel); Index: head/sys/dev/hyperv/vmbus/vmbus.c =================================================================== --- head/sys/dev/hyperv/vmbus/vmbus.c +++ head/sys/dev/hyperv/vmbus/vmbus.c @@ -835,7 +835,8 @@ return ENOMEM; sc->vmbus_mnf2 = hyperv_dmamem_alloc(parent_dtag, PAGE_SIZE, 0, - PAGE_SIZE, &sc->vmbus_mnf2_dma, BUS_DMA_WAITOK | BUS_DMA_ZERO); + sizeof(struct vmbus_mnf), &sc->vmbus_mnf2_dma, + BUS_DMA_WAITOK | BUS_DMA_ZERO); if (sc->vmbus_mnf2 == NULL) return ENOMEM; Index: head/sys/dev/hyperv/vmbus/vmbus_reg.h =================================================================== --- head/sys/dev/hyperv/vmbus/vmbus_reg.h +++ head/sys/dev/hyperv/vmbus/vmbus_reg.h @@ -72,6 +72,34 @@ CTASSERT(sizeof(struct vmbus_evtflags) == VMBUS_EVTFLAGS_SIZE); /* + * Hyper-V Monitor Notification Facility + */ + +struct vmbus_mon_trig { + uint32_t mt_pending; + uint32_t mt_armed; +} __packed; + +#define VMBUS_MONTRIGS_MAX 4 +#define VMBUS_MONTRIG_LEN 32 + +struct vmbus_mnf { + uint32_t mnf_state; + uint32_t mnf_rsvd1; + + struct vmbus_mon_trig mnf_trigs[VMBUS_MONTRIGS_MAX]; + uint8_t mnf_rsvd2[536]; + + uint16_t mnf_lat[VMBUS_MONTRIGS_MAX][VMBUS_MONTRIG_LEN]; + uint8_t mnf_rsvd3[256]; + + struct hyperv_mon_param + mnf_param[VMBUS_MONTRIGS_MAX][VMBUS_MONTRIG_LEN]; + uint8_t mnf_rsvd4[1984]; +} __packed; +CTASSERT(sizeof(struct vmbus_mnf) == PAGE_SIZE); + +/* * Channel */ Index: head/sys/dev/hyperv/vmbus/vmbus_var.h =================================================================== --- head/sys/dev/hyperv/vmbus/vmbus_var.h +++ head/sys/dev/hyperv/vmbus/vmbus_var.h @@ -71,7 +71,7 @@ void (*vmbus_event_proc)(struct vmbus_softc *, int); u_long *vmbus_tx_evtflags; /* event flags to host */ - void *vmbus_mnf2; /* monitored by host */ + struct vmbus_mnf *vmbus_mnf2; /* monitored by host */ u_long *vmbus_rx_evtflags; /* compat evtflgs from host */