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 4
38 #define MAX_NUM_DEVICE_CLASSES_SUPPORTED 8
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
101 /* {A9A0F4E7-5A45-4d96-B827-8A841E8C03E6} */
105 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d,
106 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6
114 * prep_negotiate_resp() - Create default response for Hyper-V Negotiate message
115 * @icmsghdrp: Pointer to msg header structure
116 * @icmsg_negotiate: Pointer to negotiate message structure
117 * @buf: Raw buffer channel data
119 * @icmsghdrp is of type &struct icmsg_hdr.
120 * @negop is of type &struct icmsg_negotiate.
121 * Set up and fill in default negotiate response message. This response can
122 * come from both the vmbus driver and the hv_utils driver. The current api
123 * will respond properly to both Windows 2008 and Windows 2008-R2 operating
126 * Mainly used by Hyper-V drivers.
128 void prep_negotiate_resp(struct icmsg_hdr
*icmsghdrp
,
129 struct icmsg_negotiate
*negop
,
132 if (icmsghdrp
->icmsgtype
== ICMSGTYPE_NEGOTIATE
) {
133 icmsghdrp
->icmsgsize
= 0x10;
135 negop
= (struct icmsg_negotiate
*)&buf
[
136 sizeof(struct vmbuspipe_hdr
) +
137 sizeof(struct icmsg_hdr
)];
139 if (negop
->icframe_vercnt
== 2 &&
140 negop
->icversion_data
[1].major
== 3) {
141 negop
->icversion_data
[0].major
= 3;
142 negop
->icversion_data
[0].minor
= 0;
143 negop
->icversion_data
[1].major
= 3;
144 negop
->icversion_data
[1].minor
= 0;
146 negop
->icversion_data
[0].major
= 1;
147 negop
->icversion_data
[0].minor
= 0;
148 negop
->icversion_data
[1].major
= 1;
149 negop
->icversion_data
[1].minor
= 0;
152 negop
->icframe_vercnt
= 1;
153 negop
->icmsg_vercnt
= 1;
156 EXPORT_SYMBOL(prep_negotiate_resp
);
159 * chn_cb_negotiate() - Default handler for non IDE/SCSI/NETWORK
161 * @context: Pointer to argument structure.
163 * Set up the default handler for non device driver specific requests
164 * from Hyper-V. This stub responds to the default negotiate messages
165 * that come in for every non IDE/SCSI/Network request.
166 * This behavior is normally overwritten in the hv_utils driver. That
167 * driver handles requests like gracefull shutdown, heartbeats etc.
169 * Mainly used by Hyper-V drivers.
171 void chn_cb_negotiate(void *context
)
173 struct vmbus_channel
*channel
= context
;
178 struct icmsg_hdr
*icmsghdrp
;
179 struct icmsg_negotiate
*negop
= NULL
;
182 buf
= kmalloc(buflen
, GFP_ATOMIC
);
184 vmbus_recvpacket(channel
, buf
, buflen
, &recvlen
, &requestid
);
187 icmsghdrp
= (struct icmsg_hdr
*)&buf
[
188 sizeof(struct vmbuspipe_hdr
)];
190 prep_negotiate_resp(icmsghdrp
, negop
, buf
);
192 icmsghdrp
->icflags
= ICMSGHDRFLAG_TRANSACTION
193 | ICMSGHDRFLAG_RESPONSE
;
195 vmbus_sendpacket(channel
, buf
,
197 VM_PKT_DATA_INBAND
, 0);
202 EXPORT_SYMBOL(chn_cb_negotiate
);
205 * Function table used for message responses for non IDE/SCSI/Network type
206 * messages. (Such as KVP/Shutdown etc)
208 struct hyperv_service_callback hv_cb_utils
[MAX_MSG_TYPES
] = {
209 /* 0E0B6031-5213-4934-818B-38D90CED39DB */
212 .msg_type
= HV_SHUTDOWN_MSG
,
214 0x31, 0x60, 0x0B, 0X0E, 0x13, 0x52, 0x34, 0x49,
215 0x81, 0x8B, 0x38, 0XD9, 0x0C, 0xED, 0x39, 0xDB
217 .callback
= chn_cb_negotiate
,
218 .log_msg
= "Shutdown channel functionality initialized"
221 /* {9527E630-D0AE-497b-ADCE-E80AB0175CAF} */
224 .msg_type
= HV_TIMESYNC_MSG
,
226 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49,
227 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf
229 .callback
= chn_cb_negotiate
,
230 .log_msg
= "Timesync channel functionality initialized"
232 /* {57164f39-9115-4e78-ab55-382f3bd5422d} */
235 .msg_type
= HV_HEARTBEAT_MSG
,
237 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e,
238 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d
240 .callback
= chn_cb_negotiate
,
241 .log_msg
= "Heartbeat channel functionality initialized"
243 /* {A9A0F4E7-5A45-4d96-B827-8A841E8C03E6} */
247 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d,
248 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6
250 .callback
= chn_cb_negotiate
,
251 .log_msg
= "KVP channel functionality initialized"
254 EXPORT_SYMBOL(hv_cb_utils
);
257 * alloc_channel - Allocate and initialize a vmbus channel object
259 static struct vmbus_channel
*alloc_channel(void)
261 struct vmbus_channel
*channel
;
263 channel
= kzalloc(sizeof(*channel
), GFP_ATOMIC
);
267 spin_lock_init(&channel
->inbound_lock
);
269 init_timer(&channel
->poll_timer
);
270 channel
->poll_timer
.data
= (unsigned long)channel
;
271 channel
->poll_timer
.function
= vmbus_ontimer
;
273 channel
->controlwq
= create_workqueue("hv_vmbus_ctl");
274 if (!channel
->controlwq
) {
283 * release_hannel - Release the vmbus channel object itself
285 static void release_channel(struct work_struct
*work
)
287 struct vmbus_channel
*channel
= container_of(work
,
288 struct vmbus_channel
,
291 DPRINT_DBG(VMBUS
, "releasing channel (%p)", channel
);
292 destroy_workqueue(channel
->controlwq
);
293 DPRINT_DBG(VMBUS
, "channel released (%p)", channel
);
299 * free_channel - Release the resources used by the vmbus channel object
301 void free_channel(struct vmbus_channel
*channel
)
303 del_timer_sync(&channel
->poll_timer
);
306 * We have to release the channel's workqueue/thread in the vmbus's
307 * workqueue/thread context
308 * ie we can't destroy ourselves.
310 INIT_WORK(&channel
->work
, release_channel
);
311 queue_work(vmbus_connection
.work_queue
, &channel
->work
);
315 DECLARE_COMPLETION(hv_channel_ready
);
318 * Count initialized channels, and ensure all channels are ready when hv_vmbus
319 * module loading completes.
321 static void count_hv_channel(void)
326 spin_lock_irqsave(&vmbus_connection
.channel_lock
, flags
);
327 if (++counter
== MAX_MSG_TYPES
)
328 complete(&hv_channel_ready
);
329 spin_unlock_irqrestore(&vmbus_connection
.channel_lock
, flags
);
333 * vmbus_process_rescind_offer -
334 * Rescind the offer by initiating a device removal
336 static void vmbus_process_rescind_offer(struct work_struct
*work
)
338 struct vmbus_channel
*channel
= container_of(work
,
339 struct vmbus_channel
,
342 vmbus_child_device_unregister(channel
->device_obj
);
346 * vmbus_process_offer - Process the offer by creating a channel/device
347 * associated with this offer
349 static void vmbus_process_offer(struct work_struct
*work
)
351 struct vmbus_channel
*newchannel
= container_of(work
,
352 struct vmbus_channel
,
354 struct vmbus_channel
*channel
;
360 /* The next possible work is rescind handling */
361 INIT_WORK(&newchannel
->work
, vmbus_process_rescind_offer
);
363 /* Make sure this is a new offer */
364 spin_lock_irqsave(&vmbus_connection
.channel_lock
, flags
);
366 list_for_each_entry(channel
, &vmbus_connection
.chn_list
, listentry
) {
367 if (!memcmp(&channel
->offermsg
.offer
.if_type
,
368 &newchannel
->offermsg
.offer
.if_type
,
369 sizeof(struct hv_guid
)) &&
370 !memcmp(&channel
->offermsg
.offer
.if_instance
,
371 &newchannel
->offermsg
.offer
.if_instance
,
372 sizeof(struct hv_guid
))) {
379 list_add_tail(&newchannel
->listentry
,
380 &vmbus_connection
.chn_list
);
382 spin_unlock_irqrestore(&vmbus_connection
.channel_lock
, flags
);
385 DPRINT_DBG(VMBUS
, "Ignoring duplicate offer for relid (%d)",
386 newchannel
->offermsg
.child_relid
);
387 free_channel(newchannel
);
392 * Start the process of binding this offer to the driver
393 * We need to set the DeviceObject field before calling
394 * vmbus_child_dev_add()
396 newchannel
->device_obj
= vmbus_child_device_create(
397 &newchannel
->offermsg
.offer
.if_type
,
398 &newchannel
->offermsg
.offer
.if_instance
,
401 DPRINT_DBG(VMBUS
, "child device object allocated - %p",
402 newchannel
->device_obj
);
405 * Add the new device to the bus. This will kick off device-driver
406 * binding which eventually invokes the device driver's AddDevice()
409 ret
= vmbus_child_dev_add(newchannel
->device_obj
);
412 "unable to add child device object (relid %d)",
413 newchannel
->offermsg
.child_relid
);
415 spin_lock_irqsave(&vmbus_connection
.channel_lock
, flags
);
416 list_del(&newchannel
->listentry
);
417 spin_unlock_irqrestore(&vmbus_connection
.channel_lock
, flags
);
419 free_channel(newchannel
);
422 * This state is used to indicate a successful open
423 * so that when we do close the channel normally, we
424 * can cleanup properly
426 newchannel
->state
= CHANNEL_OPEN_STATE
;
428 /* Open IC channels */
429 for (cnt
= 0; cnt
< MAX_MSG_TYPES
; cnt
++) {
430 if (memcmp(&newchannel
->offermsg
.offer
.if_type
,
431 &hv_cb_utils
[cnt
].data
,
432 sizeof(struct hv_guid
)) == 0 &&
433 vmbus_open(newchannel
, 2 * PAGE_SIZE
,
434 2 * PAGE_SIZE
, NULL
, 0,
435 hv_cb_utils
[cnt
].callback
,
437 hv_cb_utils
[cnt
].channel
= newchannel
;
438 DPRINT_INFO(VMBUS
, "%s",
439 hv_cb_utils
[cnt
].log_msg
);
447 * vmbus_onoffer - Handler for channel offers from vmbus in parent partition.
449 * We ignore all offers except network and storage offers. For each network and
450 * storage offers, we create a channel object and queue a work item to the
451 * channel object to process the offer synchronously
453 static void vmbus_onoffer(struct vmbus_channel_message_header
*hdr
)
455 struct vmbus_channel_offer_channel
*offer
;
456 struct vmbus_channel
*newchannel
;
457 struct hv_guid
*guidtype
;
458 struct hv_guid
*guidinstance
;
462 offer
= (struct vmbus_channel_offer_channel
*)hdr
;
463 for (i
= 0; i
< MAX_NUM_DEVICE_CLASSES_SUPPORTED
; i
++) {
464 if (memcmp(&offer
->offer
.if_type
,
465 &gSupportedDeviceClasses
[i
], sizeof(struct hv_guid
)) == 0) {
472 DPRINT_DBG(VMBUS
, "Ignoring channel offer notification for "
473 "child relid %d", offer
->child_relid
);
477 guidtype
= &offer
->offer
.if_type
;
478 guidinstance
= &offer
->offer
.if_instance
;
480 DPRINT_INFO(VMBUS
, "Channel offer notification - "
481 "child relid %d monitor id %d allocated %d, "
482 "type {%02x%02x%02x%02x-%02x%02x-%02x%02x-"
483 "%02x%02x%02x%02x%02x%02x%02x%02x} "
484 "instance {%02x%02x%02x%02x-%02x%02x-%02x%02x-"
485 "%02x%02x%02x%02x%02x%02x%02x%02x}",
486 offer
->child_relid
, offer
->monitorid
,
487 offer
->monitor_allocated
,
488 guidtype
->data
[3], guidtype
->data
[2],
489 guidtype
->data
[1], guidtype
->data
[0],
490 guidtype
->data
[5], guidtype
->data
[4],
491 guidtype
->data
[7], guidtype
->data
[6],
492 guidtype
->data
[8], guidtype
->data
[9],
493 guidtype
->data
[10], guidtype
->data
[11],
494 guidtype
->data
[12], guidtype
->data
[13],
495 guidtype
->data
[14], guidtype
->data
[15],
496 guidinstance
->data
[3], guidinstance
->data
[2],
497 guidinstance
->data
[1], guidinstance
->data
[0],
498 guidinstance
->data
[5], guidinstance
->data
[4],
499 guidinstance
->data
[7], guidinstance
->data
[6],
500 guidinstance
->data
[8], guidinstance
->data
[9],
501 guidinstance
->data
[10], guidinstance
->data
[11],
502 guidinstance
->data
[12], guidinstance
->data
[13],
503 guidinstance
->data
[14], guidinstance
->data
[15]);
505 /* Allocate the channel object and save this offer. */
506 newchannel
= alloc_channel();
508 DPRINT_ERR(VMBUS
, "unable to allocate channel object");
512 DPRINT_DBG(VMBUS
, "channel object allocated - %p", newchannel
);
514 memcpy(&newchannel
->offermsg
, offer
,
515 sizeof(struct vmbus_channel_offer_channel
));
516 newchannel
->monitor_grp
= (u8
)offer
->monitorid
/ 32;
517 newchannel
->monitor_bit
= (u8
)offer
->monitorid
% 32;
519 /* TODO: Make sure the offer comes from our parent partition */
520 INIT_WORK(&newchannel
->work
, vmbus_process_offer
);
521 queue_work(newchannel
->controlwq
, &newchannel
->work
);
525 * vmbus_onoffer_rescind - Rescind offer handler.
527 * We queue a work item to process this offer synchronously
529 static void vmbus_onoffer_rescind(struct vmbus_channel_message_header
*hdr
)
531 struct vmbus_channel_rescind_offer
*rescind
;
532 struct vmbus_channel
*channel
;
534 rescind
= (struct vmbus_channel_rescind_offer
*)hdr
;
535 channel
= relid2channel(rescind
->child_relid
);
536 if (channel
== NULL
) {
537 DPRINT_DBG(VMBUS
, "channel not found for relId %d",
538 rescind
->child_relid
);
542 /* work is initialized for vmbus_process_rescind_offer() from
543 * vmbus_process_offer() where the channel got created */
544 queue_work(channel
->controlwq
, &channel
->work
);
548 * vmbus_onoffers_delivered -
549 * This is invoked when all offers have been delivered.
551 * Nothing to do here.
553 static void vmbus_onoffers_delivered(
554 struct vmbus_channel_message_header
*hdr
)
559 * vmbus_onopen_result - Open result handler.
561 * This is invoked when we received a response to our channel open request.
562 * Find the matching request, copy the response and signal the requesting
565 static void vmbus_onopen_result(struct vmbus_channel_message_header
*hdr
)
567 struct vmbus_channel_open_result
*result
;
568 struct list_head
*curr
;
569 struct vmbus_channel_msginfo
*msginfo
;
570 struct vmbus_channel_message_header
*requestheader
;
571 struct vmbus_channel_open_channel
*openmsg
;
574 result
= (struct vmbus_channel_open_result
*)hdr
;
575 DPRINT_DBG(VMBUS
, "vmbus open result - %d", result
->status
);
578 * Find the open msg, copy the result and signal/unblock the wait event
580 spin_lock_irqsave(&vmbus_connection
.channelmsg_lock
, flags
);
582 list_for_each(curr
, &vmbus_connection
.chn_msg_list
) {
583 /* FIXME: this should probably use list_entry() instead */
584 msginfo
= (struct vmbus_channel_msginfo
*)curr
;
586 (struct vmbus_channel_message_header
*)msginfo
->msg
;
588 if (requestheader
->msgtype
== CHANNELMSG_OPENCHANNEL
) {
590 (struct vmbus_channel_open_channel
*)msginfo
->msg
;
591 if (openmsg
->child_relid
== result
->child_relid
&&
592 openmsg
->openid
== result
->openid
) {
593 memcpy(&msginfo
->response
.open_result
,
595 sizeof(struct vmbus_channel_open_result
));
596 osd_waitevent_set(msginfo
->waitevent
);
601 spin_unlock_irqrestore(&vmbus_connection
.channelmsg_lock
, flags
);
605 * vmbus_ongpadl_created - GPADL created handler.
607 * This is invoked when we received a response to our gpadl create request.
608 * Find the matching request, copy the response and signal the requesting
611 static void vmbus_ongpadl_created(struct vmbus_channel_message_header
*hdr
)
613 struct vmbus_channel_gpadl_created
*gpadlcreated
;
614 struct list_head
*curr
;
615 struct vmbus_channel_msginfo
*msginfo
;
616 struct vmbus_channel_message_header
*requestheader
;
617 struct vmbus_channel_gpadl_header
*gpadlheader
;
620 gpadlcreated
= (struct vmbus_channel_gpadl_created
*)hdr
;
621 DPRINT_DBG(VMBUS
, "vmbus gpadl created result - %d",
622 gpadlcreated
->creation_status
);
625 * Find the establish msg, copy the result and signal/unblock the wait
628 spin_lock_irqsave(&vmbus_connection
.channelmsg_lock
, flags
);
630 list_for_each(curr
, &vmbus_connection
.chn_msg_list
) {
631 /* FIXME: this should probably use list_entry() instead */
632 msginfo
= (struct vmbus_channel_msginfo
*)curr
;
634 (struct vmbus_channel_message_header
*)msginfo
->msg
;
636 if (requestheader
->msgtype
== CHANNELMSG_GPADL_HEADER
) {
638 (struct vmbus_channel_gpadl_header
*)requestheader
;
640 if ((gpadlcreated
->child_relid
==
641 gpadlheader
->child_relid
) &&
642 (gpadlcreated
->gpadl
== gpadlheader
->gpadl
)) {
643 memcpy(&msginfo
->response
.gpadl_created
,
645 sizeof(struct vmbus_channel_gpadl_created
));
646 osd_waitevent_set(msginfo
->waitevent
);
651 spin_unlock_irqrestore(&vmbus_connection
.channelmsg_lock
, flags
);
655 * vmbus_ongpadl_torndown - GPADL torndown handler.
657 * This is invoked when we received a response to our gpadl teardown request.
658 * Find the matching request, copy the response and signal the requesting
661 static void vmbus_ongpadl_torndown(
662 struct vmbus_channel_message_header
*hdr
)
664 struct vmbus_channel_gpadl_torndown
*gpadl_torndown
;
665 struct list_head
*curr
;
666 struct vmbus_channel_msginfo
*msginfo
;
667 struct vmbus_channel_message_header
*requestheader
;
668 struct vmbus_channel_gpadl_teardown
*gpadl_teardown
;
671 gpadl_torndown
= (struct vmbus_channel_gpadl_torndown
*)hdr
;
674 * Find the open msg, copy the result and signal/unblock the wait event
676 spin_lock_irqsave(&vmbus_connection
.channelmsg_lock
, flags
);
678 list_for_each(curr
, &vmbus_connection
.chn_msg_list
) {
679 /* FIXME: this should probably use list_entry() instead */
680 msginfo
= (struct vmbus_channel_msginfo
*)curr
;
682 (struct vmbus_channel_message_header
*)msginfo
->msg
;
684 if (requestheader
->msgtype
== CHANNELMSG_GPADL_TEARDOWN
) {
686 (struct vmbus_channel_gpadl_teardown
*)requestheader
;
688 if (gpadl_torndown
->gpadl
== gpadl_teardown
->gpadl
) {
689 memcpy(&msginfo
->response
.gpadl_torndown
,
691 sizeof(struct vmbus_channel_gpadl_torndown
));
692 osd_waitevent_set(msginfo
->waitevent
);
697 spin_unlock_irqrestore(&vmbus_connection
.channelmsg_lock
, flags
);
701 * vmbus_onversion_response - Version response handler
703 * This is invoked when we received a response to our initiate contact request.
704 * Find the matching request, copy the response and signal the requesting
707 static void vmbus_onversion_response(
708 struct vmbus_channel_message_header
*hdr
)
710 struct list_head
*curr
;
711 struct vmbus_channel_msginfo
*msginfo
;
712 struct vmbus_channel_message_header
*requestheader
;
713 struct vmbus_channel_initiate_contact
*initiate
;
714 struct vmbus_channel_version_response
*version_response
;
717 version_response
= (struct vmbus_channel_version_response
*)hdr
;
718 spin_lock_irqsave(&vmbus_connection
.channelmsg_lock
, flags
);
720 list_for_each(curr
, &vmbus_connection
.chn_msg_list
) {
721 /* FIXME: this should probably use list_entry() instead */
722 msginfo
= (struct vmbus_channel_msginfo
*)curr
;
724 (struct vmbus_channel_message_header
*)msginfo
->msg
;
726 if (requestheader
->msgtype
==
727 CHANNELMSG_INITIATE_CONTACT
) {
729 (struct vmbus_channel_initiate_contact
*)requestheader
;
730 memcpy(&msginfo
->response
.version_response
,
732 sizeof(struct vmbus_channel_version_response
));
733 osd_waitevent_set(msginfo
->waitevent
);
736 spin_unlock_irqrestore(&vmbus_connection
.channelmsg_lock
, flags
);
739 /* Channel message dispatch table */
740 static struct vmbus_channel_message_table_entry
741 gChannelMessageTable
[CHANNELMSG_COUNT
] = {
742 {CHANNELMSG_INVALID
, NULL
},
743 {CHANNELMSG_OFFERCHANNEL
, vmbus_onoffer
},
744 {CHANNELMSG_RESCIND_CHANNELOFFER
, vmbus_onoffer_rescind
},
745 {CHANNELMSG_REQUESTOFFERS
, NULL
},
746 {CHANNELMSG_ALLOFFERS_DELIVERED
, vmbus_onoffers_delivered
},
747 {CHANNELMSG_OPENCHANNEL
, NULL
},
748 {CHANNELMSG_OPENCHANNEL_RESULT
, vmbus_onopen_result
},
749 {CHANNELMSG_CLOSECHANNEL
, NULL
},
750 {CHANNELMSG_GPADL_HEADER
, NULL
},
751 {CHANNELMSG_GPADL_BODY
, NULL
},
752 {CHANNELMSG_GPADL_CREATED
, vmbus_ongpadl_created
},
753 {CHANNELMSG_GPADL_TEARDOWN
, NULL
},
754 {CHANNELMSG_GPADL_TORNDOWN
, vmbus_ongpadl_torndown
},
755 {CHANNELMSG_RELID_RELEASED
, NULL
},
756 {CHANNELMSG_INITIATE_CONTACT
, NULL
},
757 {CHANNELMSG_VERSION_RESPONSE
, vmbus_onversion_response
},
758 {CHANNELMSG_UNLOAD
, NULL
},
762 * vmbus_onmessage - Handler for channel protocol messages.
764 * This is invoked in the vmbus worker thread context.
766 void vmbus_onmessage(void *context
)
768 struct hv_message
*msg
= context
;
769 struct vmbus_channel_message_header
*hdr
;
772 hdr
= (struct vmbus_channel_message_header
*)msg
->u
.payload
;
773 size
= msg
->header
.payload_size
;
775 DPRINT_DBG(VMBUS
, "message type %d size %d", hdr
->msgtype
, size
);
777 if (hdr
->msgtype
>= CHANNELMSG_COUNT
) {
779 "Received invalid channel message type %d size %d",
781 print_hex_dump_bytes("", DUMP_PREFIX_NONE
,
782 (unsigned char *)msg
->u
.payload
, size
);
786 if (gChannelMessageTable
[hdr
->msgtype
].messageHandler
)
787 gChannelMessageTable
[hdr
->msgtype
].messageHandler(hdr
);
789 DPRINT_ERR(VMBUS
, "Unhandled channel message type %d",
794 * vmbus_request_offers - Send a request to get all our pending offers.
796 int vmbus_request_offers(void)
798 struct vmbus_channel_message_header
*msg
;
799 struct vmbus_channel_msginfo
*msginfo
;
802 msginfo
= kmalloc(sizeof(*msginfo
) +
803 sizeof(struct vmbus_channel_message_header
),
808 msginfo
->waitevent
= osd_waitevent_create();
809 if (!msginfo
->waitevent
) {
814 msg
= (struct vmbus_channel_message_header
*)msginfo
->msg
;
816 msg
->msgtype
= CHANNELMSG_REQUESTOFFERS
;
818 /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
819 INSERT_TAIL_LIST(&gVmbusConnection.channelMsgList,
820 &msgInfo->msgListEntry);
821 SpinlockRelease(gVmbusConnection.channelMsgLock);*/
823 ret
= vmbus_post_msg(msg
,
824 sizeof(struct vmbus_channel_message_header
));
826 DPRINT_ERR(VMBUS
, "Unable to request offers - %d", ret
);
828 /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
829 REMOVE_ENTRY_LIST(&msgInfo->msgListEntry);
830 SpinlockRelease(gVmbusConnection.channelMsgLock);*/
834 /* osd_waitevent_wait(msgInfo->waitEvent); */
836 /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
837 REMOVE_ENTRY_LIST(&msgInfo->msgListEntry);
838 SpinlockRelease(gVmbusConnection.channelMsgLock);*/
843 kfree(msginfo
->waitevent
);
851 * vmbus_release_unattached_channels - Release channels that are
852 * unattached/unconnected ie (no drivers associated)
854 void vmbus_release_unattached_channels(void)
856 struct vmbus_channel
*channel
, *pos
;
857 struct vmbus_channel
*start
= NULL
;
860 spin_lock_irqsave(&vmbus_connection
.channel_lock
, flags
);
862 list_for_each_entry_safe(channel
, pos
, &vmbus_connection
.chn_list
,
864 if (channel
== start
)
867 if (!channel
->device_obj
->drv
) {
868 list_del(&channel
->listentry
);
870 "Releasing unattached device object %p",
871 channel
->device_obj
);
873 vmbus_child_device_unregister(channel
->device_obj
);
874 free_channel(channel
);
881 spin_unlock_irqrestore(&vmbus_connection
.channel_lock
, flags
);