Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/hyperv/vmbus/hv_channel_mgmt.c
Show All 33 Lines | |||||
#include <dev/hyperv/vmbus/hv_vmbus_priv.h> | #include <dev/hyperv/vmbus/hv_vmbus_priv.h> | ||||
#include <dev/hyperv/vmbus/vmbus_reg.h> | #include <dev/hyperv/vmbus/vmbus_reg.h> | ||||
#include <dev/hyperv/vmbus/vmbus_var.h> | #include <dev/hyperv/vmbus/vmbus_var.h> | ||||
typedef void (*vmbus_chanmsg_proc_t) | typedef void (*vmbus_chanmsg_proc_t) | ||||
(struct vmbus_softc *, const struct vmbus_message *); | (struct vmbus_softc *, const struct vmbus_message *); | ||||
static void vmbus_channel_on_offer_internal(void *context); | static void vmbus_channel_on_offer_internal( | ||||
const hv_vmbus_channel_offer_channel *offer); | |||||
static void vmbus_channel_on_offer_rescind_internal(void *context); | static void vmbus_channel_on_offer_rescind_internal(void *context); | ||||
static void vmbus_channel_on_offer(struct vmbus_softc *, | static void vmbus_channel_on_offer(struct vmbus_softc *, | ||||
const struct vmbus_message *); | const struct vmbus_message *); | ||||
static void vmbus_channel_on_open_result(struct vmbus_softc *, | static void vmbus_channel_on_open_result(struct vmbus_softc *, | ||||
const struct vmbus_message *); | const struct vmbus_message *); | ||||
static void vmbus_channel_on_offer_rescind(struct vmbus_softc *, | static void vmbus_channel_on_offer_rescind(struct vmbus_softc *, | ||||
const struct vmbus_message *); | const struct vmbus_message *); | ||||
▲ Show 20 Lines • Show All 309 Lines • ▼ Show 20 Lines | vmbus_channel_select_defcpu(struct hv_vmbus_channel *channel) | ||||
/* mp_ncpus should have the number cpus currently online */ | /* mp_ncpus should have the number cpus currently online */ | ||||
current_cpu = (++next_vcpu % mp_ncpus); | current_cpu = (++next_vcpu % mp_ncpus); | ||||
vmbus_channel_cpu_set(channel, current_cpu); | vmbus_channel_cpu_set(channel, current_cpu); | ||||
} | } | ||||
/** | /** | ||||
* @brief Handler for channel offers from Hyper-V/Azure | * @brief Handler for channel offers from Hyper-V/Azure | ||||
* | * | ||||
* Handler for channel offers from vmbus in parent partition. We ignore | * Handler for channel offers from vmbus in parent partition. | ||||
* all offers except network and storage offers. For each network and storage | |||||
* offers, we create a channel object and queue a work item to the channel | |||||
* object to process the offer synchronously | |||||
*/ | */ | ||||
static void | static void | ||||
vmbus_channel_on_offer(struct vmbus_softc *sc, const struct vmbus_message *msg) | vmbus_channel_on_offer(struct vmbus_softc *sc, const struct vmbus_message *msg) | ||||
{ | { | ||||
const hv_vmbus_channel_msg_header *hdr = | |||||
(const hv_vmbus_channel_msg_header *)msg->msg_data; | |||||
const hv_vmbus_channel_offer_channel *offer; | const hv_vmbus_channel_offer_channel *offer; | ||||
hv_vmbus_channel_offer_channel *copied; | |||||
offer = (const hv_vmbus_channel_offer_channel *)hdr; | |||||
// copy offer data | |||||
copied = malloc(sizeof(*copied), M_DEVBUF, M_NOWAIT); | |||||
if (copied == NULL) { | |||||
printf("fail to allocate memory\n"); | |||||
return; | |||||
} | |||||
memcpy(copied, hdr, sizeof(*copied)); | |||||
hv_queue_work_item(vmbus_channel_on_offer_internal, copied); | |||||
mtx_lock(&vmbus_chwait_lock); | mtx_lock(&vmbus_chwait_lock); | ||||
if ((vmbus_chancnt & VMBUS_CHANCNT_DONE) == 0) | if ((vmbus_chancnt & VMBUS_CHANCNT_DONE) == 0) | ||||
vmbus_chancnt++; | vmbus_chancnt++; | ||||
mtx_unlock(&vmbus_chwait_lock); | mtx_unlock(&vmbus_chwait_lock); | ||||
offer = (const hv_vmbus_channel_offer_channel *)msg->msg_data; | |||||
vmbus_channel_on_offer_internal(offer); | |||||
} | } | ||||
static void | static void | ||||
vmbus_channel_on_offer_internal(void* context) | vmbus_channel_on_offer_internal(const hv_vmbus_channel_offer_channel *offer) | ||||
{ | { | ||||
hv_vmbus_channel* new_channel; | hv_vmbus_channel* new_channel; | ||||
hv_vmbus_channel_offer_channel* offer = (hv_vmbus_channel_offer_channel*)context; | |||||
/* Allocate the channel object and save this offer */ | /* Allocate the channel object and save this offer */ | ||||
new_channel = hv_vmbus_allocate_channel(); | new_channel = hv_vmbus_allocate_channel(); | ||||
/* | /* | ||||
* By default we setup state to enable batched | * By default we setup state to enable batched | ||||
* reading. A specific service can choose to | * reading. A specific service can choose to | ||||
* disable this prior to opening the channel. | * disable this prior to opening the channel. | ||||
*/ | */ | ||||
Show All 22 Lines | memcpy(&new_channel->offer_msg, offer, | ||||
sizeof(hv_vmbus_channel_offer_channel)); | sizeof(hv_vmbus_channel_offer_channel)); | ||||
new_channel->monitor_group = (uint8_t) offer->monitor_id / 32; | new_channel->monitor_group = (uint8_t) offer->monitor_id / 32; | ||||
new_channel->monitor_bit = (uint8_t) offer->monitor_id % 32; | new_channel->monitor_bit = (uint8_t) offer->monitor_id % 32; | ||||
/* Select default cpu for this channel. */ | /* Select default cpu for this channel. */ | ||||
vmbus_channel_select_defcpu(new_channel); | vmbus_channel_select_defcpu(new_channel); | ||||
vmbus_channel_process_offer(new_channel); | vmbus_channel_process_offer(new_channel); | ||||
free(offer, M_DEVBUF); | |||||
} | } | ||||
/** | /** | ||||
* @brief Rescind offer handler. | * @brief Rescind offer handler. | ||||
* | * | ||||
* We queue a work item to process this offer | * We queue a work item to process this offer | ||||
* synchronously | * synchronously | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 347 Lines • Show Last 20 Lines |