2 * Copyright (c) 2009, Microsoft Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
18 * Haiyang Zhang <haiyangz@microsoft.com>
19 * Hank Janssen <hjanssen@microsoft.com>
21 #include <linux/kernel.h>
23 #include <linux/slab.h>
24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/completion.h>
29 #include "vmbus_private.h"
32 struct vmbus_channel_message_table_entry
{
33 enum vmbus_channel_message_type messageType
;
34 void (*messageHandler
)(struct vmbus_channel_message_header
*msg
);
37 #define MAX_MSG_TYPES 3
38 #define MAX_NUM_DEVICE_CLASSES_SUPPORTED 7
40 static const struct hv_guid
41 gSupportedDeviceClasses
[MAX_NUM_DEVICE_CLASSES_SUPPORTED
] = {
42 /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */
46 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d,
47 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f
51 /* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */
55 0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46,
56 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E
60 /* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */
64 0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c,
65 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A
69 /* {32412632-86cb-44a2-9b5c-50d1417354f5} */
73 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44,
74 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5
77 /* 0E0B6031-5213-4934-818B-38D90CED39DB */
81 0x31, 0x60, 0x0B, 0X0E, 0x13, 0x52, 0x34, 0x49,
82 0x81, 0x8B, 0x38, 0XD9, 0x0C, 0xED, 0x39, 0xDB
85 /* {9527E630-D0AE-497b-ADCE-E80AB0175CAF} */
89 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49,
90 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf
93 /* {57164f39-9115-4e78-ab55-382f3bd5422d} */
97 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e,
98 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d
105 * prep_negotiate_resp() - Create default response for Hyper-V Negotiate message
106 * @icmsghdrp: Pointer to msg header structure
107 * @icmsg_negotiate: Pointer to negotiate message structure
108 * @buf: Raw buffer channel data
110 * @icmsghdrp is of type &struct icmsg_hdr.
111 * @negop is of type &struct icmsg_negotiate.
112 * Set up and fill in default negotiate response message. This response can
113 * come from both the vmbus driver and the hv_utils driver. The current api
114 * will respond properly to both Windows 2008 and Windows 2008-R2 operating
117 * Mainly used by Hyper-V drivers.
119 void prep_negotiate_resp(struct icmsg_hdr
*icmsghdrp
,
120 struct icmsg_negotiate
*negop
,
123 if (icmsghdrp
->icmsgtype
== ICMSGTYPE_NEGOTIATE
) {
124 icmsghdrp
->icmsgsize
= 0x10;
126 negop
= (struct icmsg_negotiate
*)&buf
[
127 sizeof(struct vmbuspipe_hdr
) +
128 sizeof(struct icmsg_hdr
)];
130 if (negop
->icframe_vercnt
== 2 &&
131 negop
->icversion_data
[1].major
== 3) {
132 negop
->icversion_data
[0].major
= 3;
133 negop
->icversion_data
[0].minor
= 0;
134 negop
->icversion_data
[1].major
= 3;
135 negop
->icversion_data
[1].minor
= 0;
137 negop
->icversion_data
[0].major
= 1;
138 negop
->icversion_data
[0].minor
= 0;
139 negop
->icversion_data
[1].major
= 1;
140 negop
->icversion_data
[1].minor
= 0;
143 negop
->icframe_vercnt
= 1;
144 negop
->icmsg_vercnt
= 1;
147 EXPORT_SYMBOL(prep_negotiate_resp
);
150 * chn_cb_negotiate() - Default handler for non IDE/SCSI/NETWORK
152 * @context: Pointer to argument structure.
154 * Set up the default handler for non device driver specific requests
155 * from Hyper-V. This stub responds to the default negotiate messages
156 * that come in for every non IDE/SCSI/Network request.
157 * This behavior is normally overwritten in the hv_utils driver. That
158 * driver handles requests like gracefull shutdown, heartbeats etc.
160 * Mainly used by Hyper-V drivers.
162 void chn_cb_negotiate(void *context
)
164 struct vmbus_channel
*channel
= context
;
169 struct icmsg_hdr
*icmsghdrp
;
170 struct icmsg_negotiate
*negop
= NULL
;
173 buf
= kmalloc(buflen
, GFP_ATOMIC
);
175 vmbus_recvpacket(channel
, buf
, buflen
, &recvlen
, &requestid
);
178 icmsghdrp
= (struct icmsg_hdr
*)&buf
[
179 sizeof(struct vmbuspipe_hdr
)];
181 prep_negotiate_resp(icmsghdrp
, negop
, buf
);
183 icmsghdrp
->icflags
= ICMSGHDRFLAG_TRANSACTION
184 | ICMSGHDRFLAG_RESPONSE
;
186 vmbus_sendpacket(channel
, buf
,
188 VmbusPacketTypeDataInBand
, 0);
193 EXPORT_SYMBOL(chn_cb_negotiate
);
196 * Function table used for message responses for non IDE/SCSI/Network type
197 * messages. (Such as KVP/Shutdown etc)
199 struct hyperv_service_callback hv_cb_utils
[MAX_MSG_TYPES
] = {
200 /* 0E0B6031-5213-4934-818B-38D90CED39DB */
203 .msg_type
= HV_SHUTDOWN_MSG
,
205 0x31, 0x60, 0x0B, 0X0E, 0x13, 0x52, 0x34, 0x49,
206 0x81, 0x8B, 0x38, 0XD9, 0x0C, 0xED, 0x39, 0xDB
208 .callback
= chn_cb_negotiate
,
209 .log_msg
= "Shutdown channel functionality initialized"
212 /* {9527E630-D0AE-497b-ADCE-E80AB0175CAF} */
215 .msg_type
= HV_TIMESYNC_MSG
,
217 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49,
218 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf
220 .callback
= chn_cb_negotiate
,
221 .log_msg
= "Timesync channel functionality initialized"
223 /* {57164f39-9115-4e78-ab55-382f3bd5422d} */
226 .msg_type
= HV_HEARTBEAT_MSG
,
228 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e,
229 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d
231 .callback
= chn_cb_negotiate
,
232 .log_msg
= "Heartbeat channel functionality initialized"
235 EXPORT_SYMBOL(hv_cb_utils
);
238 * alloc_channel - Allocate and initialize a vmbus channel object
240 static struct vmbus_channel
*alloc_channel(void)
242 struct vmbus_channel
*channel
;
244 channel
= kzalloc(sizeof(*channel
), GFP_ATOMIC
);
248 spin_lock_init(&channel
->inbound_lock
);
250 init_timer(&channel
->poll_timer
);
251 channel
->poll_timer
.data
= (unsigned long)channel
;
252 channel
->poll_timer
.function
= vmbus_ontimer
;
254 channel
->controlwq
= create_workqueue("hv_vmbus_ctl");
255 if (!channel
->controlwq
) {
264 * release_hannel - Release the vmbus channel object itself
266 static inline void release_channel(void *context
)
268 struct vmbus_channel
*channel
= context
;
270 DPRINT_DBG(VMBUS
, "releasing channel (%p)", channel
);
271 destroy_workqueue(channel
->controlwq
);
272 DPRINT_DBG(VMBUS
, "channel released (%p)", channel
);
278 * free_channel - Release the resources used by the vmbus channel object
280 void free_channel(struct vmbus_channel
*channel
)
282 del_timer_sync(&channel
->poll_timer
);
285 * We have to release the channel's workqueue/thread in the vmbus's
286 * workqueue/thread context
287 * ie we can't destroy ourselves.
289 osd_schedule_callback(gVmbusConnection
.WorkQueue
, release_channel
,
294 DECLARE_COMPLETION(hv_channel_ready
);
297 * Count initialized channels, and ensure all channels are ready when hv_vmbus
298 * module loading completes.
300 static void count_hv_channel(void)
305 spin_lock_irqsave(&gVmbusConnection
.channel_lock
, flags
);
306 if (++counter
== MAX_MSG_TYPES
)
307 complete(&hv_channel_ready
);
308 spin_unlock_irqrestore(&gVmbusConnection
.channel_lock
, flags
);
313 * vmbus_process_offer - Process the offer by creating a channel/device
314 * associated with this offer
316 static void vmbus_process_offer(void *context
)
318 struct vmbus_channel
*newchannel
= context
;
319 struct vmbus_channel
*channel
;
325 /* Make sure this is a new offer */
326 spin_lock_irqsave(&gVmbusConnection
.channel_lock
, flags
);
328 list_for_each_entry(channel
, &gVmbusConnection
.ChannelList
, listentry
) {
329 if (!memcmp(&channel
->offermsg
.offer
.InterfaceType
,
330 &newchannel
->offermsg
.offer
.InterfaceType
,
331 sizeof(struct hv_guid
)) &&
332 !memcmp(&channel
->offermsg
.offer
.InterfaceInstance
,
333 &newchannel
->offermsg
.offer
.InterfaceInstance
,
334 sizeof(struct hv_guid
))) {
341 list_add_tail(&newchannel
->listentry
,
342 &gVmbusConnection
.ChannelList
);
344 spin_unlock_irqrestore(&gVmbusConnection
.channel_lock
, flags
);
347 DPRINT_DBG(VMBUS
, "Ignoring duplicate offer for relid (%d)",
348 newchannel
->offermsg
.child_relid
);
349 free_channel(newchannel
);
354 * Start the process of binding this offer to the driver
355 * We need to set the DeviceObject field before calling
356 * VmbusChildDeviceAdd()
358 newchannel
->device_obj
= VmbusChildDeviceCreate(
359 &newchannel
->offermsg
.offer
.InterfaceType
,
360 &newchannel
->offermsg
.offer
.InterfaceInstance
,
363 DPRINT_DBG(VMBUS
, "child device object allocated - %p",
364 newchannel
->device_obj
);
367 * Add the new device to the bus. This will kick off device-driver
368 * binding which eventually invokes the device driver's AddDevice()
371 ret
= VmbusChildDeviceAdd(newchannel
->device_obj
);
374 "unable to add child device object (relid %d)",
375 newchannel
->offermsg
.child_relid
);
377 spin_lock_irqsave(&gVmbusConnection
.channel_lock
, flags
);
378 list_del(&newchannel
->listentry
);
379 spin_unlock_irqrestore(&gVmbusConnection
.channel_lock
, flags
);
381 free_channel(newchannel
);
384 * This state is used to indicate a successful open
385 * so that when we do close the channel normally, we
386 * can cleanup properly
388 newchannel
->state
= CHANNEL_OPEN_STATE
;
390 /* Open IC channels */
391 for (cnt
= 0; cnt
< MAX_MSG_TYPES
; cnt
++) {
392 if (memcmp(&newchannel
->offermsg
.offer
.InterfaceType
,
393 &hv_cb_utils
[cnt
].data
,
394 sizeof(struct hv_guid
)) == 0 &&
395 vmbus_open(newchannel
, 2 * PAGE_SIZE
,
396 2 * PAGE_SIZE
, NULL
, 0,
397 hv_cb_utils
[cnt
].callback
,
399 hv_cb_utils
[cnt
].channel
= newchannel
;
400 DPRINT_INFO(VMBUS
, "%s",
401 hv_cb_utils
[cnt
].log_msg
);
409 * vmbus_process_rescind_offer -
410 * Rescind the offer by initiating a device removal
412 static void vmbus_process_rescind_offer(void *context
)
414 struct vmbus_channel
*channel
= context
;
416 VmbusChildDeviceRemove(channel
->device_obj
);
420 * vmbus_onoffer - Handler for channel offers from vmbus in parent partition.
422 * We ignore all offers except network and storage offers. For each network and
423 * storage offers, we create a channel object and queue a work item to the
424 * channel object to process the offer synchronously
426 static void vmbus_onoffer(struct vmbus_channel_message_header
*hdr
)
428 struct vmbus_channel_offer_channel
*offer
;
429 struct vmbus_channel
*newchannel
;
430 struct hv_guid
*guidtype
;
431 struct hv_guid
*guidinstance
;
435 offer
= (struct vmbus_channel_offer_channel
*)hdr
;
436 for (i
= 0; i
< MAX_NUM_DEVICE_CLASSES_SUPPORTED
; i
++) {
437 if (memcmp(&offer
->offer
.InterfaceType
,
438 &gSupportedDeviceClasses
[i
], sizeof(struct hv_guid
)) == 0) {
445 DPRINT_DBG(VMBUS
, "Ignoring channel offer notification for "
446 "child relid %d", offer
->child_relid
);
450 guidtype
= &offer
->offer
.InterfaceType
;
451 guidinstance
= &offer
->offer
.InterfaceInstance
;
453 DPRINT_INFO(VMBUS
, "Channel offer notification - "
454 "child relid %d monitor id %d allocated %d, "
455 "type {%02x%02x%02x%02x-%02x%02x-%02x%02x-"
456 "%02x%02x%02x%02x%02x%02x%02x%02x} "
457 "instance {%02x%02x%02x%02x-%02x%02x-%02x%02x-"
458 "%02x%02x%02x%02x%02x%02x%02x%02x}",
459 offer
->child_relid
, offer
->monitorid
,
460 offer
->monitor_allocated
,
461 guidtype
->data
[3], guidtype
->data
[2],
462 guidtype
->data
[1], guidtype
->data
[0],
463 guidtype
->data
[5], guidtype
->data
[4],
464 guidtype
->data
[7], guidtype
->data
[6],
465 guidtype
->data
[8], guidtype
->data
[9],
466 guidtype
->data
[10], guidtype
->data
[11],
467 guidtype
->data
[12], guidtype
->data
[13],
468 guidtype
->data
[14], guidtype
->data
[15],
469 guidinstance
->data
[3], guidinstance
->data
[2],
470 guidinstance
->data
[1], guidinstance
->data
[0],
471 guidinstance
->data
[5], guidinstance
->data
[4],
472 guidinstance
->data
[7], guidinstance
->data
[6],
473 guidinstance
->data
[8], guidinstance
->data
[9],
474 guidinstance
->data
[10], guidinstance
->data
[11],
475 guidinstance
->data
[12], guidinstance
->data
[13],
476 guidinstance
->data
[14], guidinstance
->data
[15]);
478 /* Allocate the channel object and save this offer. */
479 newchannel
= alloc_channel();
481 DPRINT_ERR(VMBUS
, "unable to allocate channel object");
485 DPRINT_DBG(VMBUS
, "channel object allocated - %p", newchannel
);
487 memcpy(&newchannel
->offermsg
, offer
,
488 sizeof(struct vmbus_channel_offer_channel
));
489 newchannel
->monitor_grp
= (u8
)offer
->monitorid
/ 32;
490 newchannel
->monitor_bit
= (u8
)offer
->monitorid
% 32;
492 /* TODO: Make sure the offer comes from our parent partition */
493 osd_schedule_callback(newchannel
->controlwq
, vmbus_process_offer
,
498 * vmbus_onoffer_rescind - Rescind offer handler.
500 * We queue a work item to process this offer synchronously
502 static void vmbus_onoffer_rescind(struct vmbus_channel_message_header
*hdr
)
504 struct vmbus_channel_rescind_offer
*rescind
;
505 struct vmbus_channel
*channel
;
507 rescind
= (struct vmbus_channel_rescind_offer
*)hdr
;
508 channel
= GetChannelFromRelId(rescind
->child_relid
);
509 if (channel
== NULL
) {
510 DPRINT_DBG(VMBUS
, "channel not found for relId %d",
511 rescind
->child_relid
);
515 osd_schedule_callback(channel
->controlwq
,
516 vmbus_process_rescind_offer
,
521 * vmbus_onoffers_delivered -
522 * This is invoked when all offers have been delivered.
524 * Nothing to do here.
526 static void vmbus_onoffers_delivered(
527 struct vmbus_channel_message_header
*hdr
)
532 * vmbus_onopen_result - Open result handler.
534 * This is invoked when we received a response to our channel open request.
535 * Find the matching request, copy the response and signal the requesting
538 static void vmbus_onopen_result(struct vmbus_channel_message_header
*hdr
)
540 struct vmbus_channel_open_result
*result
;
541 struct list_head
*curr
;
542 struct vmbus_channel_msginfo
*msginfo
;
543 struct vmbus_channel_message_header
*requestheader
;
544 struct vmbus_channel_open_channel
*openmsg
;
547 result
= (struct vmbus_channel_open_result
*)hdr
;
548 DPRINT_DBG(VMBUS
, "vmbus open result - %d", result
->status
);
551 * Find the open msg, copy the result and signal/unblock the wait event
553 spin_lock_irqsave(&gVmbusConnection
.channelmsg_lock
, flags
);
555 list_for_each(curr
, &gVmbusConnection
.ChannelMsgList
) {
556 /* FIXME: this should probably use list_entry() instead */
557 msginfo
= (struct vmbus_channel_msginfo
*)curr
;
559 (struct vmbus_channel_message_header
*)msginfo
->msg
;
561 if (requestheader
->msgtype
== CHANNELMSG_OPENCHANNEL
) {
563 (struct vmbus_channel_open_channel
*)msginfo
->msg
;
564 if (openmsg
->child_relid
== result
->child_relid
&&
565 openmsg
->openid
== result
->openid
) {
566 memcpy(&msginfo
->response
.open_result
,
568 sizeof(struct vmbus_channel_open_result
));
569 osd_WaitEventSet(msginfo
->waitevent
);
574 spin_unlock_irqrestore(&gVmbusConnection
.channelmsg_lock
, flags
);
578 * vmbus_ongpadl_created - GPADL created handler.
580 * This is invoked when we received a response to our gpadl create request.
581 * Find the matching request, copy the response and signal the requesting
584 static void vmbus_ongpadl_created(struct vmbus_channel_message_header
*hdr
)
586 struct vmbus_channel_gpadl_created
*gpadlcreated
;
587 struct list_head
*curr
;
588 struct vmbus_channel_msginfo
*msginfo
;
589 struct vmbus_channel_message_header
*requestheader
;
590 struct vmbus_channel_gpadl_header
*gpadlheader
;
593 gpadlcreated
= (struct vmbus_channel_gpadl_created
*)hdr
;
594 DPRINT_DBG(VMBUS
, "vmbus gpadl created result - %d",
595 gpadlcreated
->creation_status
);
598 * Find the establish msg, copy the result and signal/unblock the wait
601 spin_lock_irqsave(&gVmbusConnection
.channelmsg_lock
, flags
);
603 list_for_each(curr
, &gVmbusConnection
.ChannelMsgList
) {
604 /* FIXME: this should probably use list_entry() instead */
605 msginfo
= (struct vmbus_channel_msginfo
*)curr
;
607 (struct vmbus_channel_message_header
*)msginfo
->msg
;
609 if (requestheader
->msgtype
== CHANNELMSG_GPADL_HEADER
) {
611 (struct vmbus_channel_gpadl_header
*)requestheader
;
613 if ((gpadlcreated
->child_relid
==
614 gpadlheader
->child_relid
) &&
615 (gpadlcreated
->gpadl
== gpadlheader
->gpadl
)) {
616 memcpy(&msginfo
->response
.gpadl_created
,
618 sizeof(struct vmbus_channel_gpadl_created
));
619 osd_WaitEventSet(msginfo
->waitevent
);
624 spin_unlock_irqrestore(&gVmbusConnection
.channelmsg_lock
, flags
);
628 * vmbus_ongpadl_torndown - GPADL torndown handler.
630 * This is invoked when we received a response to our gpadl teardown request.
631 * Find the matching request, copy the response and signal the requesting
634 static void vmbus_ongpadl_torndown(
635 struct vmbus_channel_message_header
*hdr
)
637 struct vmbus_channel_gpadl_torndown
*gpadl_torndown
;
638 struct list_head
*curr
;
639 struct vmbus_channel_msginfo
*msginfo
;
640 struct vmbus_channel_message_header
*requestheader
;
641 struct vmbus_channel_gpadl_teardown
*gpadl_teardown
;
644 gpadl_torndown
= (struct vmbus_channel_gpadl_torndown
*)hdr
;
647 * Find the open msg, copy the result and signal/unblock the wait event
649 spin_lock_irqsave(&gVmbusConnection
.channelmsg_lock
, flags
);
651 list_for_each(curr
, &gVmbusConnection
.ChannelMsgList
) {
652 /* FIXME: this should probably use list_entry() instead */
653 msginfo
= (struct vmbus_channel_msginfo
*)curr
;
655 (struct vmbus_channel_message_header
*)msginfo
->msg
;
657 if (requestheader
->msgtype
== CHANNELMSG_GPADL_TEARDOWN
) {
659 (struct vmbus_channel_gpadl_teardown
*)requestheader
;
661 if (gpadl_torndown
->gpadl
== gpadl_teardown
->gpadl
) {
662 memcpy(&msginfo
->response
.gpadl_torndown
,
664 sizeof(struct vmbus_channel_gpadl_torndown
));
665 osd_WaitEventSet(msginfo
->waitevent
);
670 spin_unlock_irqrestore(&gVmbusConnection
.channelmsg_lock
, flags
);
674 * vmbus_onversion_response - Version response handler
676 * This is invoked when we received a response to our initiate contact request.
677 * Find the matching request, copy the response and signal the requesting
680 static void vmbus_onversion_response(
681 struct vmbus_channel_message_header
*hdr
)
683 struct list_head
*curr
;
684 struct vmbus_channel_msginfo
*msginfo
;
685 struct vmbus_channel_message_header
*requestheader
;
686 struct vmbus_channel_initiate_contact
*initiate
;
687 struct vmbus_channel_version_response
*version_response
;
690 version_response
= (struct vmbus_channel_version_response
*)hdr
;
691 spin_lock_irqsave(&gVmbusConnection
.channelmsg_lock
, flags
);
693 list_for_each(curr
, &gVmbusConnection
.ChannelMsgList
) {
694 /* FIXME: this should probably use list_entry() instead */
695 msginfo
= (struct vmbus_channel_msginfo
*)curr
;
697 (struct vmbus_channel_message_header
*)msginfo
->msg
;
699 if (requestheader
->msgtype
==
700 CHANNELMSG_INITIATE_CONTACT
) {
702 (struct vmbus_channel_initiate_contact
*)requestheader
;
703 memcpy(&msginfo
->response
.version_response
,
705 sizeof(struct vmbus_channel_version_response
));
706 osd_WaitEventSet(msginfo
->waitevent
);
709 spin_unlock_irqrestore(&gVmbusConnection
.channelmsg_lock
, flags
);
712 /* Channel message dispatch table */
713 static struct vmbus_channel_message_table_entry
714 gChannelMessageTable
[CHANNELMSG_COUNT
] = {
715 {CHANNELMSG_INVALID
, NULL
},
716 {CHANNELMSG_OFFERCHANNEL
, vmbus_onoffer
},
717 {CHANNELMSG_RESCIND_CHANNELOFFER
, vmbus_onoffer_rescind
},
718 {CHANNELMSG_REQUESTOFFERS
, NULL
},
719 {CHANNELMSG_ALLOFFERS_DELIVERED
, vmbus_onoffers_delivered
},
720 {CHANNELMSG_OPENCHANNEL
, NULL
},
721 {CHANNELMSG_OPENCHANNEL_RESULT
, vmbus_onopen_result
},
722 {CHANNELMSG_CLOSECHANNEL
, NULL
},
723 {CHANNELMSG_GPADL_HEADER
, NULL
},
724 {CHANNELMSG_GPADL_BODY
, NULL
},
725 {CHANNELMSG_GPADL_CREATED
, vmbus_ongpadl_created
},
726 {CHANNELMSG_GPADL_TEARDOWN
, NULL
},
727 {CHANNELMSG_GPADL_TORNDOWN
, vmbus_ongpadl_torndown
},
728 {CHANNELMSG_RELID_RELEASED
, NULL
},
729 {CHANNELMSG_INITIATE_CONTACT
, NULL
},
730 {CHANNELMSG_VERSION_RESPONSE
, vmbus_onversion_response
},
731 {CHANNELMSG_UNLOAD
, NULL
},
735 * vmbus_onmessage - Handler for channel protocol messages.
737 * This is invoked in the vmbus worker thread context.
739 void vmbus_onmessage(void *context
)
741 struct hv_message
*msg
= context
;
742 struct vmbus_channel_message_header
*hdr
;
745 hdr
= (struct vmbus_channel_message_header
*)msg
->u
.Payload
;
746 size
= msg
->Header
.PayloadSize
;
748 DPRINT_DBG(VMBUS
, "message type %d size %d", hdr
->msgtype
, size
);
750 if (hdr
->msgtype
>= CHANNELMSG_COUNT
) {
752 "Received invalid channel message type %d size %d",
754 print_hex_dump_bytes("", DUMP_PREFIX_NONE
,
755 (unsigned char *)msg
->u
.Payload
, size
);
760 if (gChannelMessageTable
[hdr
->msgtype
].messageHandler
)
761 gChannelMessageTable
[hdr
->msgtype
].messageHandler(hdr
);
763 DPRINT_ERR(VMBUS
, "Unhandled channel message type %d",
766 /* Free the msg that was allocated in VmbusOnMsgDPC() */
771 * vmbus_request_offers - Send a request to get all our pending offers.
773 int vmbus_request_offers(void)
775 struct vmbus_channel_message_header
*msg
;
776 struct vmbus_channel_msginfo
*msginfo
;
779 msginfo
= kmalloc(sizeof(*msginfo
) +
780 sizeof(struct vmbus_channel_message_header
),
785 msginfo
->waitevent
= osd_WaitEventCreate();
786 if (!msginfo
->waitevent
) {
791 msg
= (struct vmbus_channel_message_header
*)msginfo
->msg
;
793 msg
->msgtype
= CHANNELMSG_REQUESTOFFERS
;
795 /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
796 INSERT_TAIL_LIST(&gVmbusConnection.channelMsgList,
797 &msgInfo->msgListEntry);
798 SpinlockRelease(gVmbusConnection.channelMsgLock);*/
800 ret
= VmbusPostMessage(msg
,
801 sizeof(struct vmbus_channel_message_header
));
803 DPRINT_ERR(VMBUS
, "Unable to request offers - %d", ret
);
805 /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
806 REMOVE_ENTRY_LIST(&msgInfo->msgListEntry);
807 SpinlockRelease(gVmbusConnection.channelMsgLock);*/
811 /* osd_WaitEventWait(msgInfo->waitEvent); */
813 /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
814 REMOVE_ENTRY_LIST(&msgInfo->msgListEntry);
815 SpinlockRelease(gVmbusConnection.channelMsgLock);*/
820 kfree(msginfo
->waitevent
);
828 * vmbus_release_unattached_channels - Release channels that are
829 * unattached/unconnected ie (no drivers associated)
831 void vmbus_release_unattached_channels(void)
833 struct vmbus_channel
*channel
, *pos
;
834 struct vmbus_channel
*start
= NULL
;
837 spin_lock_irqsave(&gVmbusConnection
.channel_lock
, flags
);
839 list_for_each_entry_safe(channel
, pos
, &gVmbusConnection
.ChannelList
,
841 if (channel
== start
)
844 if (!channel
->device_obj
->Driver
) {
845 list_del(&channel
->listentry
);
847 "Releasing unattached device object %p",
848 channel
->device_obj
);
850 VmbusChildDeviceRemove(channel
->device_obj
);
851 free_channel(channel
);
858 spin_unlock_irqrestore(&gVmbusConnection
.channel_lock
, flags
);