2 * Copyright (c) 2009-2012 Microsoft Corp.
3 * Copyright (c) 2012 NetApp Inc.
4 * Copyright (c) 2012 Citrix Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/malloc.h>
34 #include <sys/systm.h>
37 #include <sys/mutex.h>
38 #include <machine/bus.h>
40 #include <vm/vm_param.h>
43 #include "hv_vmbus_priv.h"
45 static int vmbus_channel_create_gpadl_header(
46 /* must be phys and virt contiguous*/
48 /* page-size multiple */
50 hv_vmbus_channel_msg_info** msg_info,
51 uint32_t* message_count);
53 static void vmbus_channel_set_event(hv_vmbus_channel* channel);
56 * @brief Trigger an event notification on the specified channel
59 vmbus_channel_set_event(hv_vmbus_channel *channel)
61 hv_vmbus_monitor_page *monitor_page;
63 if (channel->offer_msg.monitor_allocated) {
64 /* Each uint32_t represents 32 channels */
65 synch_set_bit((channel->offer_msg.child_rel_id & 31),
66 ((uint32_t *)hv_vmbus_g_connection.send_interrupt_page
67 + ((channel->offer_msg.child_rel_id >> 5))));
69 monitor_page = (hv_vmbus_monitor_page *)
70 hv_vmbus_g_connection.monitor_pages;
72 monitor_page++; /* Get the child to parent monitor page */
74 synch_set_bit(channel->monitor_bit,
75 (uint32_t *)&monitor_page->
76 trigger_group[channel->monitor_group].u.pending);
78 hv_vmbus_set_event(channel->offer_msg.child_rel_id);
84 * @brief Open the specified channel
87 hv_vmbus_channel_open(
88 hv_vmbus_channel* new_channel,
89 uint32_t send_ring_buffer_size,
90 uint32_t recv_ring_buffer_size,
92 uint32_t user_data_len,
93 hv_vmbus_pfn_channel_callback pfn_on_channel_callback,
99 hv_vmbus_channel_open_channel* open_msg;
100 hv_vmbus_channel_msg_info* open_info;
102 new_channel->on_channel_callback = pfn_on_channel_callback;
103 new_channel->channel_callback_context = context;
105 /* Allocate the ring buffer */
106 out = contigmalloc((send_ring_buffer_size + recv_ring_buffer_size),
107 M_DEVBUF, M_ZERO, 0UL, BUS_SPACE_MAXADDR, PAGE_SIZE, 0);
109 ("Error VMBUS: contigmalloc failed to allocate Ring Buffer!"));
113 in = ((uint8_t *) out + send_ring_buffer_size);
115 new_channel->ring_buffer_pages = out;
116 new_channel->ring_buffer_page_count = (send_ring_buffer_size
117 + recv_ring_buffer_size) >> PAGE_SHIFT;
119 hv_vmbus_ring_buffer_init(
120 &new_channel->outbound,
122 send_ring_buffer_size);
124 hv_vmbus_ring_buffer_init(
125 &new_channel->inbound,
127 recv_ring_buffer_size);
130 * Establish the gpadl for the ring buffer
132 new_channel->ring_buffer_gpadl_handle = 0;
134 ret = hv_vmbus_channel_establish_gpadl(new_channel,
135 new_channel->outbound.ring_buffer,
136 send_ring_buffer_size + recv_ring_buffer_size,
137 &new_channel->ring_buffer_gpadl_handle);
140 * Create and init the channel open message
142 open_info = (hv_vmbus_channel_msg_info*) malloc(
143 sizeof(hv_vmbus_channel_msg_info) +
144 sizeof(hv_vmbus_channel_open_channel),
147 KASSERT(open_info != NULL,
148 ("Error VMBUS: malloc failed to allocate Open Channel message!"));
150 if (open_info == NULL)
153 sema_init(&open_info->wait_sema, 0, "Open Info Sema");
155 open_msg = (hv_vmbus_channel_open_channel*) open_info->msg;
156 open_msg->header.message_type = HV_CHANNEL_MESSAGE_OPEN_CHANNEL;
157 open_msg->open_id = new_channel->offer_msg.child_rel_id;
158 open_msg->child_rel_id = new_channel->offer_msg.child_rel_id;
159 open_msg->ring_buffer_gpadl_handle =
160 new_channel->ring_buffer_gpadl_handle;
161 open_msg->downstream_ring_buffer_page_offset = send_ring_buffer_size
163 open_msg->server_context_area_gpadl_handle = 0;
166 memcpy(open_msg->user_data, user_data, user_data_len);
168 mtx_lock_spin(&hv_vmbus_g_connection.channel_msg_lock);
170 &hv_vmbus_g_connection.channel_msg_anchor,
173 mtx_unlock_spin(&hv_vmbus_g_connection.channel_msg_lock);
175 ret = hv_vmbus_post_message(
176 open_msg, sizeof(hv_vmbus_channel_open_channel));
181 ret = sema_timedwait(&open_info->wait_sema, 500); /* KYS 5 seconds */
186 if (open_info->response.open_result.status == 0) {
188 printf("VMBUS: channel <%p> open success.\n", new_channel);
191 printf("Error VMBUS: channel <%p> open failed - %d!\n",
192 new_channel, open_info->response.open_result.status);
196 mtx_lock_spin(&hv_vmbus_g_connection.channel_msg_lock);
198 &hv_vmbus_g_connection.channel_msg_anchor,
201 mtx_unlock_spin(&hv_vmbus_g_connection.channel_msg_lock);
202 sema_destroy(&open_info->wait_sema);
203 free(open_info, M_DEVBUF);
209 * @brief Create a gpadl for the specified buffer
212 vmbus_channel_create_gpadl_header(
214 uint32_t size, /* page-size multiple */
215 hv_vmbus_channel_msg_info** msg_info,
216 uint32_t* message_count)
220 unsigned long long pfn;
222 hv_vmbus_channel_gpadl_header* gpa_header;
223 hv_vmbus_channel_gpadl_body* gpadl_body;
224 hv_vmbus_channel_msg_info* msg_header;
225 hv_vmbus_channel_msg_info* msg_body;
227 int pfnSum, pfnCount, pfnLeft, pfnCurr, pfnSize;
229 page_count = size >> PAGE_SHIFT;
230 pfn = hv_get_phys_addr(contig_buffer) >> PAGE_SHIFT;
232 /*do we need a gpadl body msg */
233 pfnSize = HV_MAX_SIZE_CHANNEL_MESSAGE
234 - sizeof(hv_vmbus_channel_gpadl_header)
235 - sizeof(hv_gpa_range);
236 pfnCount = pfnSize / sizeof(uint64_t);
238 if (page_count > pfnCount) { /* if(we need a gpadl body) */
239 /* fill in the header */
240 msg_size = sizeof(hv_vmbus_channel_msg_info)
241 + sizeof(hv_vmbus_channel_gpadl_header)
242 + sizeof(hv_gpa_range)
243 + pfnCount * sizeof(uint64_t);
244 msg_header = malloc(msg_size, M_DEVBUF, M_NOWAIT | M_ZERO);
247 ("Error VMBUS: malloc failed to allocate Gpadl Message!"));
248 if (msg_header == NULL)
251 TAILQ_INIT(&msg_header->sub_msg_list_anchor);
252 msg_header->message_size = msg_size;
254 gpa_header = (hv_vmbus_channel_gpadl_header*) msg_header->msg;
255 gpa_header->range_count = 1;
256 gpa_header->range_buf_len = sizeof(hv_gpa_range)
257 + page_count * sizeof(uint64_t);
258 gpa_header->range[0].byte_offset = 0;
259 gpa_header->range[0].byte_count = size;
260 for (i = 0; i < pfnCount; i++) {
261 gpa_header->range[0].pfn_array[i] = pfn + i;
263 *msg_info = msg_header;
267 pfnLeft = page_count - pfnCount;
270 * figure out how many pfns we can fit
272 pfnSize = HV_MAX_SIZE_CHANNEL_MESSAGE
273 - sizeof(hv_vmbus_channel_gpadl_body);
274 pfnCount = pfnSize / sizeof(uint64_t);
280 if (pfnLeft > pfnCount) {
286 msg_size = sizeof(hv_vmbus_channel_msg_info) +
287 sizeof(hv_vmbus_channel_gpadl_body) +
288 pfnCurr * sizeof(uint64_t);
289 msg_body = malloc(msg_size, M_DEVBUF, M_NOWAIT | M_ZERO);
292 ("Error VMBUS: malloc failed to allocate Gpadl msg_body!"));
293 if (msg_body == NULL)
296 msg_body->message_size = msg_size;
299 (hv_vmbus_channel_gpadl_body*) msg_body->msg;
301 * gpadl_body->gpadl = kbuffer;
303 for (i = 0; i < pfnCurr; i++) {
304 gpadl_body->pfn[i] = pfn + pfnSum + i;
308 &msg_header->sub_msg_list_anchor,
314 } else { /* else everything fits in a header */
316 msg_size = sizeof(hv_vmbus_channel_msg_info) +
317 sizeof(hv_vmbus_channel_gpadl_header) +
318 sizeof(hv_gpa_range) +
319 page_count * sizeof(uint64_t);
320 msg_header = malloc(msg_size, M_DEVBUF, M_NOWAIT | M_ZERO);
323 ("Error VMBUS: malloc failed to allocate Gpadl Message!"));
324 if (msg_header == NULL)
327 msg_header->message_size = msg_size;
329 gpa_header = (hv_vmbus_channel_gpadl_header*) msg_header->msg;
330 gpa_header->range_count = 1;
331 gpa_header->range_buf_len = sizeof(hv_gpa_range) +
332 page_count * sizeof(uint64_t);
333 gpa_header->range[0].byte_offset = 0;
334 gpa_header->range[0].byte_count = size;
335 for (i = 0; i < page_count; i++) {
336 gpa_header->range[0].pfn_array[i] = pfn + i;
339 *msg_info = msg_header;
347 * @brief Establish a GPADL for the specified buffer
350 hv_vmbus_channel_establish_gpadl(
351 hv_vmbus_channel* channel,
353 uint32_t size, /* page-size multiple */
354 uint32_t* gpadl_handle)
358 hv_vmbus_channel_gpadl_header* gpadl_msg;
359 hv_vmbus_channel_gpadl_body* gpadl_body;
360 hv_vmbus_channel_msg_info* msg_info;
361 hv_vmbus_channel_msg_info* sub_msg_info;
363 hv_vmbus_channel_msg_info* curr;
364 uint32_t next_gpadl_handle;
366 next_gpadl_handle = hv_vmbus_g_connection.next_gpadl_handle;
367 atomic_add_int((int*) &hv_vmbus_g_connection.next_gpadl_handle, 1);
369 ret = vmbus_channel_create_gpadl_header(
370 contig_buffer, size, &msg_info, &msg_count);
372 if(ret != 0) { /* if(allocation failed) return immediately */
373 /* reverse atomic_add_int above */
374 atomic_subtract_int((int*)
375 &hv_vmbus_g_connection.next_gpadl_handle, 1);
379 sema_init(&msg_info->wait_sema, 0, "Open Info Sema");
380 gpadl_msg = (hv_vmbus_channel_gpadl_header*) msg_info->msg;
381 gpadl_msg->header.message_type = HV_CHANNEL_MESSAGEL_GPADL_HEADER;
382 gpadl_msg->child_rel_id = channel->offer_msg.child_rel_id;
383 gpadl_msg->gpadl = next_gpadl_handle;
385 mtx_lock_spin(&hv_vmbus_g_connection.channel_msg_lock);
387 &hv_vmbus_g_connection.channel_msg_anchor,
391 mtx_unlock_spin(&hv_vmbus_g_connection.channel_msg_lock);
393 ret = hv_vmbus_post_message(
395 msg_info->message_size -
396 (uint32_t) sizeof(hv_vmbus_channel_msg_info));
403 &msg_info->sub_msg_list_anchor, msg_list_entry) {
406 (hv_vmbus_channel_gpadl_body*) sub_msg_info->msg;
408 gpadl_body->header.message_type =
409 HV_CHANNEL_MESSAGE_GPADL_BODY;
410 gpadl_body->gpadl = next_gpadl_handle;
412 ret = hv_vmbus_post_message(
414 sub_msg_info->message_size
415 - (uint32_t) sizeof(hv_vmbus_channel_msg_info));
416 /* if (the post message failed) give up and clean up */
422 ret = sema_timedwait(&msg_info->wait_sema, 500); /* KYS 5 seconds*/
426 *gpadl_handle = gpadl_msg->gpadl;
430 mtx_lock_spin(&hv_vmbus_g_connection.channel_msg_lock);
431 TAILQ_REMOVE(&hv_vmbus_g_connection.channel_msg_anchor,
432 msg_info, msg_list_entry);
433 mtx_unlock_spin(&hv_vmbus_g_connection.channel_msg_lock);
435 sema_destroy(&msg_info->wait_sema);
436 free(msg_info, M_DEVBUF);
442 * @brief Teardown the specified GPADL handle
445 hv_vmbus_channel_teardown_gpdal(
446 hv_vmbus_channel* channel,
447 uint32_t gpadl_handle)
450 hv_vmbus_channel_gpadl_teardown* msg;
451 hv_vmbus_channel_msg_info* info;
453 info = (hv_vmbus_channel_msg_info *)
454 malloc( sizeof(hv_vmbus_channel_msg_info) +
455 sizeof(hv_vmbus_channel_gpadl_teardown),
457 KASSERT(info != NULL,
458 ("Error VMBUS: malloc failed to allocate Gpadl Teardown Msg!"));
464 sema_init(&info->wait_sema, 0, "Open Info Sema");
466 msg = (hv_vmbus_channel_gpadl_teardown*) info->msg;
468 msg->header.message_type = HV_CHANNEL_MESSAGE_GPADL_TEARDOWN;
469 msg->child_rel_id = channel->offer_msg.child_rel_id;
470 msg->gpadl = gpadl_handle;
472 mtx_lock_spin(&hv_vmbus_g_connection.channel_msg_lock);
473 TAILQ_INSERT_TAIL(&hv_vmbus_g_connection.channel_msg_anchor,
474 info, msg_list_entry);
475 mtx_unlock_spin(&hv_vmbus_g_connection.channel_msg_lock);
477 ret = hv_vmbus_post_message(msg,
478 sizeof(hv_vmbus_channel_gpadl_teardown));
482 ret = sema_timedwait(&info->wait_sema, 500); /* KYS 5 seconds */
486 * Received a torndown response
488 mtx_lock_spin(&hv_vmbus_g_connection.channel_msg_lock);
489 TAILQ_REMOVE(&hv_vmbus_g_connection.channel_msg_anchor,
490 info, msg_list_entry);
491 mtx_unlock_spin(&hv_vmbus_g_connection.channel_msg_lock);
492 sema_destroy(&info->wait_sema);
493 free(info, M_DEVBUF);
499 * @brief Close the specified channel
502 hv_vmbus_channel_close(hv_vmbus_channel *channel)
505 hv_vmbus_channel_close_channel* msg;
506 hv_vmbus_channel_msg_info* info;
508 mtx_lock(&channel->inbound_lock);
509 channel->on_channel_callback = NULL;
510 mtx_unlock(&channel->inbound_lock);
513 * Send a closing message
515 info = (hv_vmbus_channel_msg_info *)
516 malloc( sizeof(hv_vmbus_channel_msg_info) +
517 sizeof(hv_vmbus_channel_close_channel),
519 KASSERT(info != NULL, ("VMBUS: malloc failed hv_vmbus_channel_close!"));
523 msg = (hv_vmbus_channel_close_channel*) info->msg;
524 msg->header.message_type = HV_CHANNEL_MESSAGE_CLOSE_CHANNEL;
525 msg->child_rel_id = channel->offer_msg.child_rel_id;
527 ret = hv_vmbus_post_message(
528 msg, sizeof(hv_vmbus_channel_close_channel));
530 /* Tear down the gpadl for the channel's ring buffer */
531 if (channel->ring_buffer_gpadl_handle) {
532 hv_vmbus_channel_teardown_gpdal(channel,
533 channel->ring_buffer_gpadl_handle);
536 /* TODO: Send a msg to release the childRelId */
538 /* cleanup the ring buffers for this channel */
539 hv_ring_buffer_cleanup(&channel->outbound);
540 hv_ring_buffer_cleanup(&channel->inbound);
543 channel->ring_buffer_pages,
544 channel->ring_buffer_page_count,
547 free(info, M_DEVBUF);
550 * If we are closing the channel during an error path in
551 * opening the channel, don't free the channel
552 * since the caller will free the channel
554 if (channel->state == HV_CHANNEL_OPEN_STATE) {
555 mtx_lock_spin(&hv_vmbus_g_connection.channel_lock);
557 &hv_vmbus_g_connection.channel_anchor,
560 mtx_unlock_spin(&hv_vmbus_g_connection.channel_lock);
562 hv_vmbus_free_vmbus_channel(channel);
568 * @brief Send the specified buffer on the given channel
571 hv_vmbus_channel_send_packet(
572 hv_vmbus_channel* channel,
576 hv_vmbus_packet_type type,
580 hv_vm_packet_descriptor desc;
582 uint64_t aligned_data;
583 uint32_t packet_len_aligned;
584 hv_vmbus_sg_buffer_list buffer_list[3];
586 packet_len = sizeof(hv_vm_packet_descriptor) + buffer_len;
587 packet_len_aligned = HV_ALIGN_UP(packet_len, sizeof(uint64_t));
590 /* Setup the descriptor */
591 desc.type = type; /* HV_VMBUS_PACKET_TYPE_DATA_IN_BAND; */
592 desc.flags = flags; /* HV_VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED */
593 /* in 8-bytes granularity */
594 desc.data_offset8 = sizeof(hv_vm_packet_descriptor) >> 3;
595 desc.length8 = (uint16_t) (packet_len_aligned >> 3);
596 desc.transaction_id = request_id;
598 buffer_list[0].data = &desc;
599 buffer_list[0].length = sizeof(hv_vm_packet_descriptor);
601 buffer_list[1].data = buffer;
602 buffer_list[1].length = buffer_len;
604 buffer_list[2].data = &aligned_data;
605 buffer_list[2].length = packet_len_aligned - packet_len;
607 ret = hv_ring_buffer_write(&channel->outbound, buffer_list, 3);
609 /* TODO: We should determine if this is optional */
611 && !hv_vmbus_get_ring_buffer_interrupt_mask(
612 &channel->outbound)) {
613 vmbus_channel_set_event(channel);
620 * @brief Send a range of single-page buffer packets using
621 * a GPADL Direct packet type
624 hv_vmbus_channel_send_packet_pagebuffer(
625 hv_vmbus_channel* channel,
626 hv_vmbus_page_buffer page_buffers[],
636 uint32_t packetLen_aligned;
637 hv_vmbus_sg_buffer_list buffer_list[3];
638 hv_vmbus_channel_packet_page_buffer desc;
640 uint64_t alignedData = 0;
642 if (page_count > HV_MAX_PAGE_BUFFER_COUNT)
646 * Adjust the size down since hv_vmbus_channel_packet_page_buffer
647 * is the largest size we support
649 descSize = sizeof(hv_vmbus_channel_packet_page_buffer) -
650 ((HV_MAX_PAGE_BUFFER_COUNT - page_count) *
651 sizeof(hv_vmbus_page_buffer));
652 packet_len = descSize + buffer_len;
653 packetLen_aligned = HV_ALIGN_UP(packet_len, sizeof(uint64_t));
655 /* Setup the descriptor */
656 desc.type = HV_VMBUS_PACKET_TYPE_DATA_USING_GPA_DIRECT;
657 desc.flags = HV_VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
658 desc.data_offset8 = descSize >> 3; /* in 8-bytes granularity */
659 desc.length8 = (uint16_t) (packetLen_aligned >> 3);
660 desc.transaction_id = request_id;
661 desc.range_count = page_count;
663 for (i = 0; i < page_count; i++) {
664 desc.range[i].length = page_buffers[i].length;
665 desc.range[i].offset = page_buffers[i].offset;
666 desc.range[i].pfn = page_buffers[i].pfn;
669 buffer_list[0].data = &desc;
670 buffer_list[0].length = descSize;
672 buffer_list[1].data = buffer;
673 buffer_list[1].length = buffer_len;
675 buffer_list[2].data = &alignedData;
676 buffer_list[2].length = packetLen_aligned - packet_len;
678 ret = hv_ring_buffer_write(&channel->outbound, buffer_list, 3);
680 /* TODO: We should determine if this is optional */
682 !hv_vmbus_get_ring_buffer_interrupt_mask(&channel->outbound)) {
683 vmbus_channel_set_event(channel);
690 * @brief Send a multi-page buffer packet using a GPADL Direct packet type
693 hv_vmbus_channel_send_packet_multipagebuffer(
694 hv_vmbus_channel* channel,
695 hv_vmbus_multipage_buffer* multi_page_buffer,
704 uint32_t packet_len_aligned;
706 uint64_t aligned_data = 0;
707 hv_vmbus_sg_buffer_list buffer_list[3];
708 hv_vmbus_channel_packet_multipage_buffer desc;
711 HV_NUM_PAGES_SPANNED(
712 multi_page_buffer->offset,
713 multi_page_buffer->length);
715 if ((pfn_count == 0) || (pfn_count > HV_MAX_MULTIPAGE_BUFFER_COUNT))
718 * Adjust the size down since hv_vmbus_channel_packet_multipage_buffer
719 * is the largest size we support
722 sizeof(hv_vmbus_channel_packet_multipage_buffer) -
723 ((HV_MAX_MULTIPAGE_BUFFER_COUNT - pfn_count) *
725 packet_len = desc_size + buffer_len;
726 packet_len_aligned = HV_ALIGN_UP(packet_len, sizeof(uint64_t));
729 * Setup the descriptor
731 desc.type = HV_VMBUS_PACKET_TYPE_DATA_USING_GPA_DIRECT;
732 desc.flags = HV_VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
733 desc.data_offset8 = desc_size >> 3; /* in 8-bytes granularity */
734 desc.length8 = (uint16_t) (packet_len_aligned >> 3);
735 desc.transaction_id = request_id;
736 desc.range_count = 1;
738 desc.range.length = multi_page_buffer->length;
739 desc.range.offset = multi_page_buffer->offset;
741 memcpy(desc.range.pfn_array, multi_page_buffer->pfn_array,
742 pfn_count * sizeof(uint64_t));
744 buffer_list[0].data = &desc;
745 buffer_list[0].length = desc_size;
747 buffer_list[1].data = buffer;
748 buffer_list[1].length = buffer_len;
750 buffer_list[2].data = &aligned_data;
751 buffer_list[2].length = packet_len_aligned - packet_len;
753 ret = hv_ring_buffer_write(&channel->outbound, buffer_list, 3);
755 /* TODO: We should determine if this is optional */
757 !hv_vmbus_get_ring_buffer_interrupt_mask(&channel->outbound)) {
758 vmbus_channel_set_event(channel);
765 * @brief Retrieve the user packet on the specified channel
768 hv_vmbus_channel_recv_packet(
769 hv_vmbus_channel* channel,
772 uint32_t* buffer_actual_len,
773 uint64_t* request_id)
778 hv_vm_packet_descriptor desc;
780 *buffer_actual_len = 0;
783 ret = hv_ring_buffer_peek(&channel->inbound, &desc,
784 sizeof(hv_vm_packet_descriptor));
788 packet_len = desc.length8 << 3;
789 user_len = packet_len - (desc.data_offset8 << 3);
791 *buffer_actual_len = user_len;
793 if (user_len > buffer_len)
796 *request_id = desc.transaction_id;
798 /* Copy over the packet to the user buffer */
799 ret = hv_ring_buffer_read(&channel->inbound, Buffer, user_len,
800 (desc.data_offset8 << 3));
806 * @brief Retrieve the raw packet on the specified channel
809 hv_vmbus_channel_recv_packet_raw(
810 hv_vmbus_channel* channel,
813 uint32_t* buffer_actual_len,
814 uint64_t* request_id)
819 hv_vm_packet_descriptor desc;
821 *buffer_actual_len = 0;
824 ret = hv_ring_buffer_peek(
825 &channel->inbound, &desc,
826 sizeof(hv_vm_packet_descriptor));
831 packetLen = desc.length8 << 3;
832 userLen = packetLen - (desc.data_offset8 << 3);
834 *buffer_actual_len = packetLen;
836 if (packetLen > buffer_len)
839 *request_id = desc.transaction_id;
841 /* Copy over the entire packet to the user buffer */
842 ret = hv_ring_buffer_read(&channel->inbound, buffer, packetLen, 0);