]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/staging/hv/ChannelMgmt.c
Staging: hv: typedef removal for ChannelMessages.h
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / hv / ChannelMgmt.c
CommitLineData
3e7ee490
HJ
1/*
2 *
3 * Copyright (c) 2009, Microsoft Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place - Suite 330, Boston, MA 02111-1307 USA.
17 *
18 * Authors:
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
21 *
22 */
23
24
a0086dc5
GKH
25#include <linux/kernel.h>
26#include <linux/mm.h>
4983b39a 27#include "osd.h"
09d50ff8 28#include "include/logging.h"
3e7ee490
HJ
29
30#include "VmbusPrivate.h"
31
454f18a9 32/* Data types */
3e7ee490 33
82250213 34typedef void (*PFN_CHANNEL_MESSAGE_HANDLER)(struct vmbus_channel_message_header *msg);
3e7ee490
HJ
35
36typedef struct _VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY {
82250213 37 enum vmbus_channel_message_type messageType;
3e7ee490
HJ
38 PFN_CHANNEL_MESSAGE_HANDLER messageHandler;
39} VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY;
40
454f18a9 41/* Internal routines */
82250213
GKH
42static void VmbusChannelOnOffer(struct vmbus_channel_message_header *hdr);
43static void VmbusChannelOnOpenResult(struct vmbus_channel_message_header *hdr);
44static void VmbusChannelOnOfferRescind(struct vmbus_channel_message_header *hdr);
45static void VmbusChannelOnGpadlCreated(struct vmbus_channel_message_header *hdr);
46static void VmbusChannelOnGpadlTorndown(struct vmbus_channel_message_header *hdr);
47static void VmbusChannelOnOffersDelivered(struct vmbus_channel_message_header *hdr);
48static void VmbusChannelOnVersionResponse(struct vmbus_channel_message_header *hdr);
49static void VmbusChannelProcessOffer(void * context);
50static void VmbusChannelProcessRescindOffer(void * context);
3e7ee490
HJ
51
52
454f18a9 53/* Globals */
3e7ee490
HJ
54
55#define MAX_NUM_DEVICE_CLASSES_SUPPORTED 4
56
caf26a31 57static const struct hv_guid gSupportedDeviceClasses[MAX_NUM_DEVICE_CLASSES_SUPPORTED] = {
454f18a9 58 /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */
caf26a31
GKH
59 /* Storage - SCSI */
60 {
61 .data = {
62 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d,
63 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f
64 }
65 },
66
454f18a9 67 /* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */
caf26a31
GKH
68 /* Network */
69 {
70 .data = {
71 0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46,
72 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E
73 }
74 },
75
454f18a9 76 /* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */
caf26a31
GKH
77 /* Input */
78 {
79 .data = {
80 0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c,
81 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A
82 }
83 },
3e7ee490 84
caf26a31
GKH
85 /* {32412632-86cb-44a2-9b5c-50d1417354f5} */
86 /* IDE */
87 {
88 .data = {
89 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44,
90 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5
91 }
92 },
3e7ee490
HJ
93};
94
454f18a9 95/* Channel message dispatch table */
bd1de709 96static VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY gChannelMessageTable[ChannelMessageCount]= {
3e7ee490
HJ
97 {ChannelMessageInvalid, NULL},
98 {ChannelMessageOfferChannel, VmbusChannelOnOffer},
99 {ChannelMessageRescindChannelOffer, VmbusChannelOnOfferRescind},
100 {ChannelMessageRequestOffers, NULL},
101 {ChannelMessageAllOffersDelivered, VmbusChannelOnOffersDelivered},
102 {ChannelMessageOpenChannel, NULL},
103 {ChannelMessageOpenChannelResult, VmbusChannelOnOpenResult},
104 {ChannelMessageCloseChannel, NULL},
105 {ChannelMessageGpadlHeader, NULL},
106 {ChannelMessageGpadlBody, NULL},
107 {ChannelMessageGpadlCreated, VmbusChannelOnGpadlCreated},
108 {ChannelMessageGpadlTeardown, NULL},
109 {ChannelMessageGpadlTorndown, VmbusChannelOnGpadlTorndown},
110 {ChannelMessageRelIdReleased, NULL},
111 {ChannelMessageInitiateContact, NULL},
112 {ChannelMessageVersionResponse, VmbusChannelOnVersionResponse},
113 {ChannelMessageUnload, NULL},
114};
115
116/*++
117
118Name:
119 AllocVmbusChannel()
120
121Description:
122 Allocate and initialize a vmbus channel object
123
124--*/
aded7165 125struct vmbus_channel *AllocVmbusChannel(void)
3e7ee490 126{
aded7165 127 struct vmbus_channel *channel;
3e7ee490 128
aded7165 129 channel = kzalloc(sizeof(*channel), GFP_ATOMIC);
3e7ee490
HJ
130 if (!channel)
131 {
132 return NULL;
133 }
134
54411c42 135 spin_lock_init(&channel->inbound_lock);
3e7ee490 136
c8a429a4
GKH
137 init_timer(&channel->poll_timer);
138 channel->poll_timer.data = (unsigned long)channel;
139 channel->poll_timer.function = VmbusChannelOnTimer;
3e7ee490 140
454f18a9 141 /* channel->dataWorkQueue = WorkQueueCreate("data"); */
de65a384 142 channel->ControlWQ = create_workqueue("hv_vmbus_ctl");
3e7ee490
HJ
143 if (!channel->ControlWQ)
144 {
8c69f52a 145 kfree(channel);
3e7ee490
HJ
146 return NULL;
147 }
148
149 return channel;
150}
151
152/*++
153
154Name:
155 ReleaseVmbusChannel()
156
157Description:
158 Release the vmbus channel object itself
159
160--*/
161static inline void ReleaseVmbusChannel(void* Context)
162{
aded7165 163 struct vmbus_channel *channel = Context;
3e7ee490
HJ
164
165 DPRINT_ENTER(VMBUS);
166
167 DPRINT_DBG(VMBUS, "releasing channel (%p)", channel);
de65a384 168 destroy_workqueue(channel->ControlWQ);
3e7ee490
HJ
169 DPRINT_DBG(VMBUS, "channel released (%p)", channel);
170
8c69f52a 171 kfree(channel);
3e7ee490
HJ
172
173 DPRINT_EXIT(VMBUS);
174}
175
176/*++
177
178Name:
179 FreeVmbusChannel()
180
181Description:
182 Release the resources used by the vmbus channel object
183
184--*/
aded7165 185void FreeVmbusChannel(struct vmbus_channel *Channel)
3e7ee490 186{
c8a429a4 187 del_timer(&Channel->poll_timer);
3e7ee490 188
454f18a9
BP
189 /* We have to release the channel's workqueue/thread in the vmbus's workqueue/thread context */
190 /* ie we can't destroy ourselves. */
de65a384
BP
191 osd_schedule_callback(gVmbusConnection.WorkQueue, ReleaseVmbusChannel,
192 (void *)Channel);
3e7ee490
HJ
193}
194
195
196/*++
197
198Name:
199 VmbusChannelProcessOffer()
200
201Description:
202 Process the offer by creating a channel/device associated with this offer
203
204--*/
205static void
206VmbusChannelProcessOffer(
8282c400 207 void * context
3e7ee490
HJ
208 )
209{
210 int ret=0;
aded7165
GKH
211 struct vmbus_channel *newChannel = context;
212 struct vmbus_channel *channel;
3e7ee490
HJ
213 LIST_ENTRY* anchor;
214 LIST_ENTRY* curr;
0e727613 215 bool fNew = true;
0f5e44ca 216 unsigned long flags;
3e7ee490
HJ
217
218 DPRINT_ENTER(VMBUS);
219
454f18a9 220 /* Make sure this is a new offer */
0f5e44ca 221 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
3e7ee490
HJ
222
223 ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelList)
224 {
aded7165 225 channel = CONTAINING_RECORD(curr, struct vmbus_channel, ListEntry);
3e7ee490 226
caf26a31
GKH
227 if (!memcmp(&channel->OfferMsg.Offer.InterfaceType, &newChannel->OfferMsg.Offer.InterfaceType,sizeof(struct hv_guid)) &&
228 !memcmp(&channel->OfferMsg.Offer.InterfaceInstance, &newChannel->OfferMsg.Offer.InterfaceInstance, sizeof(struct hv_guid)))
3e7ee490 229 {
0e727613 230 fNew = false;
3e7ee490
HJ
231 break;
232 }
233 }
234
235 if (fNew)
236 {
237 INSERT_TAIL_LIST(&gVmbusConnection.ChannelList, &newChannel->ListEntry);
238 }
0f5e44ca 239 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
3e7ee490
HJ
240
241 if (!fNew)
242 {
243 DPRINT_DBG(VMBUS, "Ignoring duplicate offer for relid (%d)", newChannel->OfferMsg.ChildRelId);
244 FreeVmbusChannel(newChannel);
245 DPRINT_EXIT(VMBUS);
246 return;
247 }
248
454f18a9
BP
249 /* Start the process of binding this offer to the driver */
250 /* We need to set the DeviceObject field before calling VmbusChildDeviceAdd() */
3e7ee490 251 newChannel->DeviceObject = VmbusChildDeviceCreate(
daaa8cc3
GKH
252 &newChannel->OfferMsg.Offer.InterfaceType,
253 &newChannel->OfferMsg.Offer.InterfaceInstance,
3e7ee490
HJ
254 newChannel);
255
256 DPRINT_DBG(VMBUS, "child device object allocated - %p", newChannel->DeviceObject);
257
454f18a9
BP
258 /*
259 * Add the new device to the bus. This will kick off device-driver
260 * binding which eventually invokes the device driver's AddDevice()
261 * method.
262 */
263
3e7ee490
HJ
264 ret = VmbusChildDeviceAdd(newChannel->DeviceObject);
265 if (ret != 0)
266 {
267 DPRINT_ERR(VMBUS, "unable to add child device object (relid %d)",
268 newChannel->OfferMsg.ChildRelId);
269
0f5e44ca 270 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
3e7ee490 271 REMOVE_ENTRY_LIST(&newChannel->ListEntry);
0f5e44ca 272 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
3e7ee490
HJ
273
274 FreeVmbusChannel(newChannel);
275 }
276 else
277 {
454f18a9
BP
278 /*
279 * This state is used to indicate a successful open
280 * so that when we do close the channel normally, we
281 * can cleanup properly
282 */
3e7ee490
HJ
283 newChannel->State = CHANNEL_OPEN_STATE;
284 }
285 DPRINT_EXIT(VMBUS);
286}
287
288/*++
289
290Name:
291 VmbusChannelProcessRescindOffer()
292
293Description:
294 Rescind the offer by initiating a device removal
295
296--*/
297static void
298VmbusChannelProcessRescindOffer(
8282c400 299 void * context
3e7ee490
HJ
300 )
301{
aded7165 302 struct vmbus_channel *channel = context;
3e7ee490
HJ
303
304 DPRINT_ENTER(VMBUS);
305
306 VmbusChildDeviceRemove(channel->DeviceObject);
307
308 DPRINT_EXIT(VMBUS);
309}
310
311
312/*++
313
314Name:
315 VmbusChannelOnOffer()
316
317Description:
318 Handler for channel offers from vmbus in parent partition. We ignore all offers except
319 network and storage offers. For each network and storage offers, we create a channel object
320 and queue a work item to the channel object to process the offer synchronously
321
322--*/
82250213 323static void VmbusChannelOnOffer(struct vmbus_channel_message_header *hdr)
3e7ee490 324{
82250213 325 struct vmbus_channel_offer_channel *offer = (struct vmbus_channel_offer_channel *)hdr;
aded7165 326 struct vmbus_channel *newChannel;
3e7ee490 327
caf26a31
GKH
328 struct hv_guid *guidType;
329 struct hv_guid *guidInstance;
3e7ee490
HJ
330 int i;
331 int fSupported=0;
332
333 DPRINT_ENTER(VMBUS);
334
335 for (i=0; i<MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++)
336 {
caf26a31 337 if (memcmp(&offer->Offer.InterfaceType, &gSupportedDeviceClasses[i], sizeof(struct hv_guid)) == 0)
3e7ee490
HJ
338 {
339 fSupported = 1;
340 break;
341 }
342 }
343
344 if (!fSupported)
345 {
346 DPRINT_DBG(VMBUS, "Ignoring channel offer notification for child relid %d", offer->ChildRelId);
347 DPRINT_EXIT(VMBUS);
348
349 return;
350 }
351
352 guidType = &offer->Offer.InterfaceType;
353 guidInstance = &offer->Offer.InterfaceInstance;
354
355 DPRINT_INFO(VMBUS, "Channel offer notification - child relid %d monitor id %d allocated %d, "
356 "type {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x} "
357 "instance {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}",
358 offer->ChildRelId,
359 offer->MonitorId,
360 offer->MonitorAllocated,
caf26a31
GKH
361 guidType->data[3], guidType->data[2], guidType->data[1], guidType->data[0],
362 guidType->data[5], guidType->data[4], guidType->data[7], guidType->data[6],
363 guidType->data[8], guidType->data[9], guidType->data[10], guidType->data[11],
364 guidType->data[12], guidType->data[13], guidType->data[14], guidType->data[15],
365 guidInstance->data[3], guidInstance->data[2], guidInstance->data[1], guidInstance->data[0],
366 guidInstance->data[5], guidInstance->data[4], guidInstance->data[7], guidInstance->data[6],
367 guidInstance->data[8], guidInstance->data[9], guidInstance->data[10], guidInstance->data[11],
368 guidInstance->data[12], guidInstance->data[13], guidInstance->data[14], guidInstance->data[15]);
3e7ee490 369
454f18a9 370 /* Allocate the channel object and save this offer. */
3e7ee490
HJ
371 newChannel = AllocVmbusChannel();
372 if (!newChannel)
373 {
374 DPRINT_ERR(VMBUS, "unable to allocate channel object");
375 return;
376 }
377
378 DPRINT_DBG(VMBUS, "channel object allocated - %p", newChannel);
379
82250213 380 memcpy(&newChannel->OfferMsg, offer, sizeof(struct vmbus_channel_offer_channel));
5654e932
GKH
381 newChannel->MonitorGroup = (u8)offer->MonitorId / 32;
382 newChannel->MonitorBit = (u8)offer->MonitorId % 32;
3e7ee490 383
454f18a9 384 /* TODO: Make sure the offer comes from our parent partition */
de65a384
BP
385 osd_schedule_callback(newChannel->ControlWQ, VmbusChannelProcessOffer,
386 newChannel);
3e7ee490
HJ
387
388 DPRINT_EXIT(VMBUS);
389}
390
391
392/*++
393
394Name:
395 VmbusChannelOnOfferRescind()
396
397Description:
398 Rescind offer handler. We queue a work item to process this offer
399 synchronously
400
401--*/
82250213 402static void VmbusChannelOnOfferRescind(struct vmbus_channel_message_header *hdr)
3e7ee490 403{
82250213 404 struct vmbus_channel_rescind_offer *rescind = (struct vmbus_channel_rescind_offer *)hdr;
aded7165 405 struct vmbus_channel *channel;
3e7ee490
HJ
406
407 DPRINT_ENTER(VMBUS);
408
409 channel = GetChannelFromRelId(rescind->ChildRelId);
410 if (channel == NULL)
411 {
412 DPRINT_DBG(VMBUS, "channel not found for relId %d", rescind->ChildRelId);
413 return;
414 }
415
de65a384
BP
416 osd_schedule_callback(channel->ControlWQ,
417 VmbusChannelProcessRescindOffer,
418 channel);
3e7ee490
HJ
419
420 DPRINT_EXIT(VMBUS);
421}
422
423
424/*++
425
426Name:
427 VmbusChannelOnOffersDelivered()
428
429Description:
430 This is invoked when all offers have been delivered.
431 Nothing to do here.
432
433--*/
82250213 434static void VmbusChannelOnOffersDelivered(struct vmbus_channel_message_header *hdr)
3e7ee490
HJ
435{
436 DPRINT_ENTER(VMBUS);
437 DPRINT_EXIT(VMBUS);
438}
439
440
441/*++
442
443Name:
444 VmbusChannelOnOpenResult()
445
446Description:
447 Open result handler. This is invoked when we received a response
448 to our channel open request. Find the matching request, copy the
449 response and signal the requesting thread.
450
451--*/
82250213 452static void VmbusChannelOnOpenResult(struct vmbus_channel_message_header *hdr)
3e7ee490 453{
82250213 454 struct vmbus_channel_open_result *result = (struct vmbus_channel_open_result *)hdr;
3e7ee490
HJ
455 LIST_ENTRY* anchor;
456 LIST_ENTRY* curr;
aded7165 457 struct vmbus_channel_msginfo *msgInfo;
82250213
GKH
458 struct vmbus_channel_message_header *requestHeader;
459 struct vmbus_channel_open_channel *openMsg;
dd0813b6 460 unsigned long flags;
3e7ee490
HJ
461
462 DPRINT_ENTER(VMBUS);
463
464 DPRINT_DBG(VMBUS, "vmbus open result - %d", result->Status);
465
454f18a9 466 /* Find the open msg, copy the result and signal/unblock the wait event */
dd0813b6 467 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490
HJ
468
469 ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
470 {
aded7165 471 msgInfo = (struct vmbus_channel_msginfo *)curr;
82250213 472 requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg;
3e7ee490
HJ
473
474 if (requestHeader->MessageType == ChannelMessageOpenChannel)
475 {
82250213 476 openMsg = (struct vmbus_channel_open_channel *)msgInfo->Msg;
3e7ee490
HJ
477 if (openMsg->ChildRelId == result->ChildRelId &&
478 openMsg->OpenId == result->OpenId)
479 {
82250213 480 memcpy(&msgInfo->Response.OpenResult, result, sizeof(struct vmbus_channel_open_result));
bfc30aae 481 osd_WaitEventSet(msgInfo->WaitEvent);
3e7ee490
HJ
482 break;
483 }
484 }
485 }
dd0813b6 486 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490
HJ
487
488 DPRINT_EXIT(VMBUS);
489}
490
491
492/*++
493
494Name:
495 VmbusChannelOnGpadlCreated()
496
497Description:
498 GPADL created handler. This is invoked when we received a response
499 to our gpadl create request. Find the matching request, copy the
500 response and signal the requesting thread.
501
502--*/
82250213 503static void VmbusChannelOnGpadlCreated(struct vmbus_channel_message_header *hdr)
3e7ee490 504{
82250213 505 struct vmbus_channel_gpadl_created *gpadlCreated = (struct vmbus_channel_gpadl_created *)hdr;
3e7ee490
HJ
506 LIST_ENTRY *anchor;
507 LIST_ENTRY *curr;
aded7165 508 struct vmbus_channel_msginfo *msgInfo;
82250213
GKH
509 struct vmbus_channel_message_header *requestHeader;
510 struct vmbus_channel_gpadl_header *gpadlHeader;
dd0813b6 511 unsigned long flags;
3e7ee490
HJ
512
513 DPRINT_ENTER(VMBUS);
514
515 DPRINT_DBG(VMBUS, "vmbus gpadl created result - %d", gpadlCreated->CreationStatus);
516
454f18a9 517 /* Find the establish msg, copy the result and signal/unblock the wait event */
dd0813b6 518 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490
HJ
519
520 ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
521 {
aded7165 522 msgInfo = (struct vmbus_channel_msginfo *)curr;
82250213 523 requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg;
3e7ee490
HJ
524
525 if (requestHeader->MessageType == ChannelMessageGpadlHeader)
526 {
82250213 527 gpadlHeader = (struct vmbus_channel_gpadl_header *)requestHeader;
3e7ee490
HJ
528
529 if ((gpadlCreated->ChildRelId == gpadlHeader->ChildRelId) &&
530 (gpadlCreated->Gpadl == gpadlHeader->Gpadl))
531 {
82250213 532 memcpy(&msgInfo->Response.GpadlCreated, gpadlCreated, sizeof(struct vmbus_channel_gpadl_created));
bfc30aae 533 osd_WaitEventSet(msgInfo->WaitEvent);
3e7ee490
HJ
534 break;
535 }
536 }
537 }
dd0813b6 538 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490
HJ
539
540 DPRINT_EXIT(VMBUS);
541}
542
543
544/*++
545
546Name:
547 VmbusChannelOnGpadlTorndown()
548
549Description:
550 GPADL torndown handler. This is invoked when we received a response
551 to our gpadl teardown request. Find the matching request, copy the
552 response and signal the requesting thread.
553
554--*/
82250213 555static void VmbusChannelOnGpadlTorndown(struct vmbus_channel_message_header *hdr)
3e7ee490 556{
82250213 557 struct vmbus_channel_gpadl_torndown* gpadlTorndown = (struct vmbus_channel_gpadl_torndown *)hdr;
3e7ee490
HJ
558 LIST_ENTRY* anchor;
559 LIST_ENTRY* curr;
aded7165 560 struct vmbus_channel_msginfo *msgInfo;
82250213
GKH
561 struct vmbus_channel_message_header *requestHeader;
562 struct vmbus_channel_gpadl_teardown *gpadlTeardown;
dd0813b6 563 unsigned long flags;
3e7ee490
HJ
564
565 DPRINT_ENTER(VMBUS);
566
454f18a9 567 /* Find the open msg, copy the result and signal/unblock the wait event */
dd0813b6 568 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490
HJ
569
570 ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
571 {
aded7165 572 msgInfo = (struct vmbus_channel_msginfo *)curr;
82250213 573 requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg;
3e7ee490
HJ
574
575 if (requestHeader->MessageType == ChannelMessageGpadlTeardown)
576 {
82250213 577 gpadlTeardown = (struct vmbus_channel_gpadl_teardown *)requestHeader;
3e7ee490
HJ
578
579 if (gpadlTorndown->Gpadl == gpadlTeardown->Gpadl)
580 {
82250213 581 memcpy(&msgInfo->Response.GpadlTorndown, gpadlTorndown, sizeof(struct vmbus_channel_gpadl_torndown));
bfc30aae 582 osd_WaitEventSet(msgInfo->WaitEvent);
3e7ee490
HJ
583 break;
584 }
585 }
586 }
dd0813b6 587 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490
HJ
588
589 DPRINT_EXIT(VMBUS);
590}
591
592
593/*++
594
595Name:
596 VmbusChannelOnVersionResponse()
597
598Description:
599 Version response handler. This is invoked when we received a response
600 to our initiate contact request. Find the matching request, copy the
601 response and signal the requesting thread.
602
603--*/
82250213 604static void VmbusChannelOnVersionResponse(struct vmbus_channel_message_header *hdr)
3e7ee490
HJ
605{
606 LIST_ENTRY* anchor;
607 LIST_ENTRY* curr;
aded7165 608 struct vmbus_channel_msginfo *msgInfo;
82250213
GKH
609 struct vmbus_channel_message_header *requestHeader;
610 struct vmbus_channel_initiate_contact *initiate;
611 struct vmbus_channel_version_response *versionResponse = (struct vmbus_channel_version_response *)hdr;
dd0813b6 612 unsigned long flags;
3e7ee490
HJ
613
614 DPRINT_ENTER(VMBUS);
615
dd0813b6 616 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490
HJ
617
618 ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
619 {
aded7165 620 msgInfo = (struct vmbus_channel_msginfo *)curr;
82250213 621 requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg;
3e7ee490
HJ
622
623 if (requestHeader->MessageType == ChannelMessageInitiateContact)
624 {
82250213
GKH
625 initiate = (struct vmbus_channel_initiate_contact *)requestHeader;
626 memcpy(&msgInfo->Response.VersionResponse, versionResponse, sizeof(struct vmbus_channel_version_response));
bfc30aae 627 osd_WaitEventSet(msgInfo->WaitEvent);
3e7ee490
HJ
628 }
629 }
dd0813b6 630 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490
HJ
631
632 DPRINT_EXIT(VMBUS);
633}
634
635
636/*++
637
638Name:
639 VmbusOnChannelMessage()
640
641Description:
642 Handler for channel protocol messages.
643 This is invoked in the vmbus worker thread context.
644
645--*/
b239549c 646void VmbusOnChannelMessage(void *Context)
3e7ee490 647{
eacb1b4d 648 struct hv_message *msg = Context;
82250213 649 struct vmbus_channel_message_header *hdr;
3e7ee490
HJ
650 int size;
651
652 DPRINT_ENTER(VMBUS);
653
82250213 654 hdr = (struct vmbus_channel_message_header *)msg->u.Payload;
3e7ee490
HJ
655 size=msg->Header.PayloadSize;
656
657 DPRINT_DBG(VMBUS, "message type %d size %d", hdr->MessageType, size);
658
659 if (hdr->MessageType >= ChannelMessageCount)
660 {
661 DPRINT_ERR(VMBUS, "Received invalid channel message type %d size %d", hdr->MessageType, size);
04f50c4d
GKH
662 print_hex_dump_bytes("", DUMP_PREFIX_NONE,
663 (unsigned char *)msg->u.Payload, size);
8c69f52a 664 kfree(msg);
3e7ee490
HJ
665 return;
666 }
667
668 if (gChannelMessageTable[hdr->MessageType].messageHandler)
669 {
670 gChannelMessageTable[hdr->MessageType].messageHandler(hdr);
671 }
672 else
673 {
674 DPRINT_ERR(VMBUS, "Unhandled channel message type %d", hdr->MessageType);
675 }
676
454f18a9 677 /* Free the msg that was allocated in VmbusOnMsgDPC() */
8c69f52a 678 kfree(msg);
3e7ee490
HJ
679 DPRINT_EXIT(VMBUS);
680}
681
682
683/*++
684
685Name:
686 VmbusChannelRequestOffers()
687
688Description:
689 Send a request to get all our pending offers.
690
691--*/
b239549c 692int VmbusChannelRequestOffers(void)
3e7ee490
HJ
693{
694 int ret=0;
82250213 695 struct vmbus_channel_message_header *msg;
aded7165 696 struct vmbus_channel_msginfo *msgInfo;
3e7ee490
HJ
697
698 DPRINT_ENTER(VMBUS);
699
82250213 700 msgInfo = kmalloc(sizeof(*msgInfo) + sizeof(struct vmbus_channel_message_header), GFP_KERNEL);
3e7ee490
HJ
701 ASSERT(msgInfo != NULL);
702
bfc30aae 703 msgInfo->WaitEvent = osd_WaitEventCreate();
82250213 704 msg = (struct vmbus_channel_message_header *)msgInfo->Msg;
3e7ee490
HJ
705
706 msg->MessageType = ChannelMessageRequestOffers;
707
708 /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
709 INSERT_TAIL_LIST(&gVmbusConnection.channelMsgList, &msgInfo->msgListEntry);
710 SpinlockRelease(gVmbusConnection.channelMsgLock);*/
711
82250213 712 ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_message_header));
3e7ee490
HJ
713 if (ret != 0)
714 {
715 DPRINT_ERR(VMBUS, "Unable to request offers - %d", ret);
716
717 /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
718 REMOVE_ENTRY_LIST(&msgInfo->msgListEntry);
719 SpinlockRelease(gVmbusConnection.channelMsgLock);*/
720
721 goto Cleanup;
722 }
bfc30aae 723 /* osd_WaitEventWait(msgInfo->waitEvent); */
3e7ee490
HJ
724
725 /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
726 REMOVE_ENTRY_LIST(&msgInfo->msgListEntry);
727 SpinlockRelease(gVmbusConnection.channelMsgLock);*/
728
729
730Cleanup:
731 if (msgInfo)
732 {
420beac4 733 kfree(msgInfo->WaitEvent);
8c69f52a 734 kfree(msgInfo);
3e7ee490
HJ
735 }
736
737 DPRINT_EXIT(VMBUS);
738
739 return ret;
740}
741
742/*++
743
744Name:
745 VmbusChannelReleaseUnattachedChannels()
746
747Description:
748 Release channels that are unattached/unconnected ie (no drivers associated)
749
750--*/
b239549c 751void VmbusChannelReleaseUnattachedChannels(void)
3e7ee490
HJ
752{
753 LIST_ENTRY *entry;
aded7165
GKH
754 struct vmbus_channel *channel;
755 struct vmbus_channel *start = NULL;
0f5e44ca 756 unsigned long flags;
3e7ee490 757
0f5e44ca 758 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
3e7ee490
HJ
759
760 while (!IsListEmpty(&gVmbusConnection.ChannelList))
761 {
762 entry = TOP_LIST_ENTRY(&gVmbusConnection.ChannelList);
aded7165 763 channel = CONTAINING_RECORD(entry, struct vmbus_channel, ListEntry);
3e7ee490
HJ
764
765 if (channel == start)
766 break;
767
768 if (!channel->DeviceObject->Driver)
769 {
770 REMOVE_ENTRY_LIST(&channel->ListEntry);
771 DPRINT_INFO(VMBUS, "Releasing unattached device object %p", channel->DeviceObject);
772
773 VmbusChildDeviceRemove(channel->DeviceObject);
774 FreeVmbusChannel(channel);
775 }
776 else
777 {
778 if (!start)
779 {
780 start = channel;
781 }
782 }
783 }
784
0f5e44ca 785 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
3e7ee490
HJ
786}
787
454f18a9 788/* eof */