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;
118 new_channel->ring_buffer_size = send_ring_buffer_size +
119 recv_ring_buffer_size;
121 hv_vmbus_ring_buffer_init(
122 &new_channel->outbound,
124 send_ring_buffer_size);
126 hv_vmbus_ring_buffer_init(
127 &new_channel->inbound,
129 recv_ring_buffer_size);
132 * Establish the gpadl for the ring buffer
134 new_channel->ring_buffer_gpadl_handle = 0;
136 ret = hv_vmbus_channel_establish_gpadl(new_channel,
137 new_channel->outbound.ring_buffer,
138 send_ring_buffer_size + recv_ring_buffer_size,
139 &new_channel->ring_buffer_gpadl_handle);
142 * Create and init the channel open message
144 open_info = (hv_vmbus_channel_msg_info*) malloc(
145 sizeof(hv_vmbus_channel_msg_info) +
146 sizeof(hv_vmbus_channel_open_channel),
149 KASSERT(open_info != NULL,
150 ("Error VMBUS: malloc failed to allocate Open Channel message!"));
152 if (open_info == NULL)
155 sema_init(&open_info->wait_sema, 0, "Open Info Sema");
157 open_msg = (hv_vmbus_channel_open_channel*) open_info->msg;
158 open_msg->header.message_type = HV_CHANNEL_MESSAGE_OPEN_CHANNEL;
159 open_msg->open_id = new_channel->offer_msg.child_rel_id;
160 open_msg->child_rel_id = new_channel->offer_msg.child_rel_id;
161 open_msg->ring_buffer_gpadl_handle =
162 new_channel->ring_buffer_gpadl_handle;
163 open_msg->downstream_ring_buffer_page_offset = send_ring_buffer_size
165 open_msg->server_context_area_gpadl_handle = 0;
168 memcpy(open_msg->user_data, user_data, user_data_len);
170 mtx_lock_spin(&hv_vmbus_g_connection.channel_msg_lock);
172 &hv_vmbus_g_connection.channel_msg_anchor,
175 mtx_unlock_spin(&hv_vmbus_g_connection.channel_msg_lock);
177 ret = hv_vmbus_post_message(
178 open_msg, sizeof(hv_vmbus_channel_open_channel));
183 ret = sema_timedwait(&open_info->wait_sema, 500); /* KYS 5 seconds */
188 if (open_info->response.open_result.status == 0) {
190 printf("VMBUS: channel <%p> open success.\n", new_channel);
193 printf("Error VMBUS: channel <%p> open failed - %d!\n",
194 new_channel, open_info->response.open_result.status);
198 mtx_lock_spin(&hv_vmbus_g_connection.channel_msg_lock);
200 &hv_vmbus_g_connection.channel_msg_anchor,
203 mtx_unlock_spin(&hv_vmbus_g_connection.channel_msg_lock);
204 sema_destroy(&open_info->wait_sema);
205 free(open_info, M_DEVBUF);
211 * @brief Create a gpadl for the specified buffer
214 vmbus_channel_create_gpadl_header(
216 uint32_t size, /* page-size multiple */
217 hv_vmbus_channel_msg_info** msg_info,
218 uint32_t* message_count)
222 unsigned long long pfn;
224 hv_vmbus_channel_gpadl_header* gpa_header;
225 hv_vmbus_channel_gpadl_body* gpadl_body;
226 hv_vmbus_channel_msg_info* msg_header;
227 hv_vmbus_channel_msg_info* msg_body;
229 int pfnSum, pfnCount, pfnLeft, pfnCurr, pfnSize;
231 page_count = size >> PAGE_SHIFT;
232 pfn = hv_get_phys_addr(contig_buffer) >> PAGE_SHIFT;
234 /*do we need a gpadl body msg */
235 pfnSize = HV_MAX_SIZE_CHANNEL_MESSAGE
236 - sizeof(hv_vmbus_channel_gpadl_header)
237 - sizeof(hv_gpa_range);
238 pfnCount = pfnSize / sizeof(uint64_t);
240 if (page_count > pfnCount) { /* if(we need a gpadl body) */
241 /* fill in the header */
242 msg_size = sizeof(hv_vmbus_channel_msg_info)
243 + sizeof(hv_vmbus_channel_gpadl_header)
244 + sizeof(hv_gpa_range)
245 + pfnCount * sizeof(uint64_t);
246 msg_header = malloc(msg_size, M_DEVBUF, M_NOWAIT | M_ZERO);
249 ("Error VMBUS: malloc failed to allocate Gpadl Message!"));
250 if (msg_header == NULL)
253 TAILQ_INIT(&msg_header->sub_msg_list_anchor);
254 msg_header->message_size = msg_size;
256 gpa_header = (hv_vmbus_channel_gpadl_header*) msg_header->msg;
257 gpa_header->range_count = 1;
258 gpa_header->range_buf_len = sizeof(hv_gpa_range)
259 + page_count * sizeof(uint64_t);
260 gpa_header->range[0].byte_offset = 0;
261 gpa_header->range[0].byte_count = size;
262 for (i = 0; i < pfnCount; i++) {
263 gpa_header->range[0].pfn_array[i] = pfn + i;
265 *msg_info = msg_header;
269 pfnLeft = page_count - pfnCount;
272 * figure out how many pfns we can fit
274 pfnSize = HV_MAX_SIZE_CHANNEL_MESSAGE
275 - sizeof(hv_vmbus_channel_gpadl_body);
276 pfnCount = pfnSize / sizeof(uint64_t);
282 if (pfnLeft > pfnCount) {
288 msg_size = sizeof(hv_vmbus_channel_msg_info) +
289 sizeof(hv_vmbus_channel_gpadl_body) +
290 pfnCurr * sizeof(uint64_t);
291 msg_body = malloc(msg_size, M_DEVBUF, M_NOWAIT | M_ZERO);
294 ("Error VMBUS: malloc failed to allocate Gpadl msg_body!"));
295 if (msg_body == NULL)
298 msg_body->message_size = msg_size;
301 (hv_vmbus_channel_gpadl_body*) msg_body->msg;
303 * gpadl_body->gpadl = kbuffer;
305 for (i = 0; i < pfnCurr; i++) {
306 gpadl_body->pfn[i] = pfn + pfnSum + i;
310 &msg_header->sub_msg_list_anchor,
316 } else { /* else everything fits in a header */
318 msg_size = sizeof(hv_vmbus_channel_msg_info) +
319 sizeof(hv_vmbus_channel_gpadl_header) +
320 sizeof(hv_gpa_range) +
321 page_count * sizeof(uint64_t);
322 msg_header = malloc(msg_size, M_DEVBUF, M_NOWAIT | M_ZERO);
325 ("Error VMBUS: malloc failed to allocate Gpadl Message!"));
326 if (msg_header == NULL)
329 msg_header->message_size = msg_size;
331 gpa_header = (hv_vmbus_channel_gpadl_header*) msg_header->msg;
332 gpa_header->range_count = 1;
333 gpa_header->range_buf_len = sizeof(hv_gpa_range) +
334 page_count * sizeof(uint64_t);
335 gpa_header->range[0].byte_offset = 0;
336 gpa_header->range[0].byte_count = size;
337 for (i = 0; i < page_count; i++) {
338 gpa_header->range[0].pfn_array[i] = pfn + i;
341 *msg_info = msg_header;
349 * @brief Establish a GPADL for the specified buffer
352 hv_vmbus_channel_establish_gpadl(
353 hv_vmbus_channel* channel,
355 uint32_t size, /* page-size multiple */
356 uint32_t* gpadl_handle)
360 hv_vmbus_channel_gpadl_header* gpadl_msg;
361 hv_vmbus_channel_gpadl_body* gpadl_body;
362 hv_vmbus_channel_msg_info* msg_info;
363 hv_vmbus_channel_msg_info* sub_msg_info;
365 hv_vmbus_channel_msg_info* curr;
366 uint32_t next_gpadl_handle;
368 next_gpadl_handle = hv_vmbus_g_connection.next_gpadl_handle;
369 atomic_add_int((int*) &hv_vmbus_g_connection.next_gpadl_handle, 1);
371 ret = vmbus_channel_create_gpadl_header(
372 contig_buffer, size, &msg_info, &msg_count);
374 if(ret != 0) { /* if(allocation failed) return immediately */
375 /* reverse atomic_add_int above */
376 atomic_subtract_int((int*)
377 &hv_vmbus_g_connection.next_gpadl_handle, 1);
381 sema_init(&msg_info->wait_sema, 0, "Open Info Sema");
382 gpadl_msg = (hv_vmbus_channel_gpadl_header*) msg_info->msg;
383 gpadl_msg->header.message_type = HV_CHANNEL_MESSAGEL_GPADL_HEADER;
384 gpadl_msg->child_rel_id = channel->offer_msg.child_rel_id;
385 gpadl_msg->gpadl = next_gpadl_handle;
387 mtx_lock_spin(&hv_vmbus_g_connection.channel_msg_lock);
389 &hv_vmbus_g_connection.channel_msg_anchor,
393 mtx_unlock_spin(&hv_vmbus_g_connection.channel_msg_lock);
395 ret = hv_vmbus_post_message(
397 msg_info->message_size -
398 (uint32_t) sizeof(hv_vmbus_channel_msg_info));
405 &msg_info->sub_msg_list_anchor, msg_list_entry) {
408 (hv_vmbus_channel_gpadl_body*) sub_msg_info->msg;
410 gpadl_body->header.message_type =
411 HV_CHANNEL_MESSAGE_GPADL_BODY;
412 gpadl_body->gpadl = next_gpadl_handle;
414 ret = hv_vmbus_post_message(
416 sub_msg_info->message_size
417 - (uint32_t) sizeof(hv_vmbus_channel_msg_info));
418 /* if (the post message failed) give up and clean up */
424 ret = sema_timedwait(&msg_info->wait_sema, 500); /* KYS 5 seconds*/
428 *gpadl_handle = gpadl_msg->gpadl;
432 mtx_lock_spin(&hv_vmbus_g_connection.channel_msg_lock);
433 TAILQ_REMOVE(&hv_vmbus_g_connection.channel_msg_anchor,
434 msg_info, msg_list_entry);
435 mtx_unlock_spin(&hv_vmbus_g_connection.channel_msg_lock);
437 sema_destroy(&msg_info->wait_sema);
438 free(msg_info, M_DEVBUF);
444 * @brief Teardown the specified GPADL handle
447 hv_vmbus_channel_teardown_gpdal(
448 hv_vmbus_channel* channel,
449 uint32_t gpadl_handle)
452 hv_vmbus_channel_gpadl_teardown* msg;
453 hv_vmbus_channel_msg_info* info;
455 info = (hv_vmbus_channel_msg_info *)
456 malloc( sizeof(hv_vmbus_channel_msg_info) +
457 sizeof(hv_vmbus_channel_gpadl_teardown),
459 KASSERT(info != NULL,
460 ("Error VMBUS: malloc failed to allocate Gpadl Teardown Msg!"));
466 sema_init(&info->wait_sema, 0, "Open Info Sema");
468 msg = (hv_vmbus_channel_gpadl_teardown*) info->msg;
470 msg->header.message_type = HV_CHANNEL_MESSAGE_GPADL_TEARDOWN;
471 msg->child_rel_id = channel->offer_msg.child_rel_id;
472 msg->gpadl = gpadl_handle;
474 mtx_lock_spin(&hv_vmbus_g_connection.channel_msg_lock);
475 TAILQ_INSERT_TAIL(&hv_vmbus_g_connection.channel_msg_anchor,
476 info, msg_list_entry);
477 mtx_unlock_spin(&hv_vmbus_g_connection.channel_msg_lock);
479 ret = hv_vmbus_post_message(msg,
480 sizeof(hv_vmbus_channel_gpadl_teardown));
484 ret = sema_timedwait(&info->wait_sema, 500); /* KYS 5 seconds */
488 * Received a torndown response
490 mtx_lock_spin(&hv_vmbus_g_connection.channel_msg_lock);
491 TAILQ_REMOVE(&hv_vmbus_g_connection.channel_msg_anchor,
492 info, msg_list_entry);
493 mtx_unlock_spin(&hv_vmbus_g_connection.channel_msg_lock);
494 sema_destroy(&info->wait_sema);
495 free(info, M_DEVBUF);
501 * @brief Close the specified channel
504 hv_vmbus_channel_close(hv_vmbus_channel *channel)
507 hv_vmbus_channel_close_channel* msg;
508 hv_vmbus_channel_msg_info* info;
510 mtx_lock(&channel->inbound_lock);
511 channel->on_channel_callback = NULL;
512 mtx_unlock(&channel->inbound_lock);
515 * Send a closing message
517 info = (hv_vmbus_channel_msg_info *)
518 malloc( sizeof(hv_vmbus_channel_msg_info) +
519 sizeof(hv_vmbus_channel_close_channel),
521 KASSERT(info != NULL, ("VMBUS: malloc failed hv_vmbus_channel_close!"));
525 msg = (hv_vmbus_channel_close_channel*) info->msg;
526 msg->header.message_type = HV_CHANNEL_MESSAGE_CLOSE_CHANNEL;
527 msg->child_rel_id = channel->offer_msg.child_rel_id;
529 ret = hv_vmbus_post_message(
530 msg, sizeof(hv_vmbus_channel_close_channel));
532 /* Tear down the gpadl for the channel's ring buffer */
533 if (channel->ring_buffer_gpadl_handle) {
534 hv_vmbus_channel_teardown_gpdal(channel,
535 channel->ring_buffer_gpadl_handle);
538 /* TODO: Send a msg to release the childRelId */
540 /* cleanup the ring buffers for this channel */
541 hv_ring_buffer_cleanup(&channel->outbound);
542 hv_ring_buffer_cleanup(&channel->inbound);
544 contigfree(channel->ring_buffer_pages, channel->ring_buffer_size,
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);