Staging: hv: remove wrapper functions for bit operations
[linux-2.6-block.git] / drivers / staging / hv / Channel.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
5654e932 24#include <linux/kernel.h>
09d50ff8
GKH
25#include "include/osd.h"
26#include "include/logging.h"
3e7ee490
HJ
27
28#include "VmbusPrivate.h"
29
454f18a9 30/* Internal routines */
3e7ee490
HJ
31static int
32VmbusChannelCreateGpadlHeader(
454f18a9
BP
33 void * Kbuffer, /* must be phys and virt contiguous */
34 u32 Size, /* page-size multiple */
3e7ee490 35 VMBUS_CHANNEL_MSGINFO **msgInfo,
4d643114 36 u32 *MessageCount
3e7ee490
HJ
37 );
38
39static void
40DumpVmbusChannel(
41 VMBUS_CHANNEL *Channel
42 );
43
44
45static void
46VmbusChannelSetEvent(
47 VMBUS_CHANNEL *Channel
48 );
49
50
51#if 0
52static void
53DumpMonitorPage(
54 HV_MONITOR_PAGE *MonitorPage
55 )
56{
57 int i=0;
58 int j=0;
59
60 DPRINT_DBG(VMBUS, "monitorPage - %p, trigger state - %d", MonitorPage, MonitorPage->TriggerState);
61
62 for (i=0; i<4; i++)
63 {
64 DPRINT_DBG(VMBUS, "trigger group (%d) - %llx", i, MonitorPage->TriggerGroup[i].AsUINT64);
65 }
66
67 for (i=0; i<4; i++)
68 {
69 for (j=0; j<32; j++)
70 {
71 DPRINT_DBG(VMBUS, "latency (%d)(%d) - %llx", i, j, MonitorPage->Latency[i][j]);
72 }
73 }
74 for (i=0; i<4; i++)
75 {
76 for (j=0; j<32; j++)
77 {
4d643114 78 DPRINT_DBG(VMBUS, "param-conn id (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].ConnectionId.Asu32);
3e7ee490
HJ
79 DPRINT_DBG(VMBUS, "param-flag (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].FlagNumber);
80
81 }
82 }
83}
84#endif
85
86/*++
87
88Name:
89 VmbusChannelSetEvent()
90
91Description:
92 Trigger an event notification on the specified channel.
93
94--*/
95static void
96VmbusChannelSetEvent(
97 VMBUS_CHANNEL *Channel
98 )
99{
100 HV_MONITOR_PAGE *monitorPage;
101
102 DPRINT_ENTER(VMBUS);
103
104 if (Channel->OfferMsg.MonitorAllocated)
105 {
454f18a9 106 /* Each u32 represents 32 channels */
7c369f40
BP
107 set_bit(Channel->OfferMsg.ChildRelId & 31,
108 (unsigned long *) gVmbusConnection.SendInterruptPage +
109 (Channel->OfferMsg.ChildRelId >> 5) );
3e7ee490
HJ
110
111 monitorPage = (HV_MONITOR_PAGE*)gVmbusConnection.MonitorPages;
454f18a9 112 monitorPage++; /* Get the child to parent monitor page */
3e7ee490 113
7c369f40
BP
114 set_bit(Channel->MonitorBit,
115 (unsigned long *) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending);
116
3e7ee490
HJ
117 }
118 else
119 {
120 VmbusSetEvent(Channel->OfferMsg.ChildRelId);
121 }
122
123 DPRINT_EXIT(VMBUS);
124}
125
126#if 0
127static void
128VmbusChannelClearEvent(
129 VMBUS_CHANNEL *Channel
130 )
131{
132 HV_MONITOR_PAGE *monitorPage;
133
134 DPRINT_ENTER(VMBUS);
135
136 if (Channel->OfferMsg.MonitorAllocated)
137 {
454f18a9 138 /* Each u32 represents 32 channels */
7c369f40
BP
139 clear_bit(Channel->OfferMsg.ChildRelId & 31,
140 (unsigned long *) gVmbusConnection.SendInterruptPage + (Channel->OfferMsg.ChildRelId >> 5));
3e7ee490
HJ
141
142 monitorPage = (HV_MONITOR_PAGE*)gVmbusConnection.MonitorPages;
454f18a9 143 monitorPage++; /* Get the child to parent monitor page */
3e7ee490 144
7c369f40
BP
145 clear_bit(Channel->MonitorBit,
146 (unsigned long *) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending);
3e7ee490
HJ
147 }
148
149 DPRINT_EXIT(VMBUS);
150}
151
152#endif
153/*++;
154
155Name:
156 VmbusChannelGetDebugInfo()
157
158Description:
159 Retrieve various channel debug info
160
161--*/
bd1de709 162static void
3e7ee490
HJ
163VmbusChannelGetDebugInfo(
164 VMBUS_CHANNEL *Channel,
165 VMBUS_CHANNEL_DEBUG_INFO *DebugInfo
166 )
167{
168 HV_MONITOR_PAGE *monitorPage;
5654e932
GKH
169 u8 monitorGroup = (u8)Channel->OfferMsg.MonitorId / 32;
170 u8 monitorOffset = (u8)Channel->OfferMsg.MonitorId % 32;
454f18a9 171 /* u32 monitorBit = 1 << monitorOffset; */
3e7ee490
HJ
172
173 DebugInfo->RelId = Channel->OfferMsg.ChildRelId;
174 DebugInfo->State = Channel->State;
175 memcpy(&DebugInfo->InterfaceType, &Channel->OfferMsg.Offer.InterfaceType, sizeof(GUID));
176 memcpy(&DebugInfo->InterfaceInstance, &Channel->OfferMsg.Offer.InterfaceInstance, sizeof(GUID));
177
178 monitorPage = (HV_MONITOR_PAGE*)gVmbusConnection.MonitorPages;
179
180 DebugInfo->MonitorId = Channel->OfferMsg.MonitorId;
181
182 DebugInfo->ServerMonitorPending = monitorPage->TriggerGroup[monitorGroup].Pending;
183 DebugInfo->ServerMonitorLatency = monitorPage->Latency[monitorGroup][ monitorOffset];
184 DebugInfo->ServerMonitorConnectionId = monitorPage->Parameter[monitorGroup][ monitorOffset].ConnectionId.u.Id;
185
186 monitorPage++;
187
188 DebugInfo->ClientMonitorPending = monitorPage->TriggerGroup[monitorGroup].Pending;
189 DebugInfo->ClientMonitorLatency = monitorPage->Latency[monitorGroup][ monitorOffset];
190 DebugInfo->ClientMonitorConnectionId = monitorPage->Parameter[monitorGroup][ monitorOffset].ConnectionId.u.Id;
191
192 RingBufferGetDebugInfo(&Channel->Inbound, &DebugInfo->Inbound);
193 RingBufferGetDebugInfo(&Channel->Outbound, &DebugInfo->Outbound);
194}
195
196
197/*++;
198
199Name:
200 VmbusChannelOpen()
201
202Description:
203 Open the specified channel.
204
205--*/
bd1de709 206static int
3e7ee490
HJ
207VmbusChannelOpen(
208 VMBUS_CHANNEL *NewChannel,
4d643114
GKH
209 u32 SendRingBufferSize,
210 u32 RecvRingBufferSize,
8282c400 211 void * UserData,
4d643114 212 u32 UserDataLen,
3e7ee490 213 PFN_CHANNEL_CALLBACK pfnOnChannelCallback,
8282c400 214 void * Context
3e7ee490
HJ
215 )
216{
217 int ret=0;
218 VMBUS_CHANNEL_OPEN_CHANNEL* openMsg;
219 VMBUS_CHANNEL_MSGINFO* openInfo;
220 void *in, *out;
dd0813b6 221 unsigned long flags;
3e7ee490
HJ
222
223 DPRINT_ENTER(VMBUS);
224
454f18a9 225 /* Aligned to page size */
3e7ee490
HJ
226 ASSERT(!(SendRingBufferSize & (PAGE_SIZE -1)));
227 ASSERT(!(RecvRingBufferSize & (PAGE_SIZE -1)));
228
229 NewChannel->OnChannelCallback = pfnOnChannelCallback;
230 NewChannel->ChannelCallbackContext = Context;
231
454f18a9 232 /* Allocate the ring buffer */
3e7ee490 233 out = PageAlloc((SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT);
454f18a9 234 /* out = kzalloc(sendRingBufferSize + recvRingBufferSize, GFP_KERNEL); */
3e7ee490 235 ASSERT(out);
c4b0bc94 236 ASSERT(((unsigned long)out & (PAGE_SIZE-1)) == 0);
3e7ee490 237
c4b0bc94 238 in = (void*)((unsigned long)out + SendRingBufferSize);
3e7ee490
HJ
239
240 NewChannel->RingBufferPages = out;
241 NewChannel->RingBufferPageCount = (SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT;
242
243 RingBufferInit(&NewChannel->Outbound, out, SendRingBufferSize);
244
245 RingBufferInit(&NewChannel->Inbound, in, RecvRingBufferSize);
246
454f18a9 247 /* Establish the gpadl for the ring buffer */
3e7ee490
HJ
248 DPRINT_DBG(VMBUS, "Establishing ring buffer's gpadl for channel %p...", NewChannel);
249
250 NewChannel->RingBufferGpadlHandle = 0;
251
252 ret = VmbusChannelEstablishGpadl(NewChannel,
253 NewChannel->Outbound.RingBuffer,
254 SendRingBufferSize + RecvRingBufferSize,
255 &NewChannel->RingBufferGpadlHandle);
256
257 DPRINT_DBG(VMBUS, "channel %p <relid %d gpadl 0x%x send ring %p size %d recv ring %p size %d, downstreamoffset %d>",
258 NewChannel,
259 NewChannel->OfferMsg.ChildRelId,
260 NewChannel->RingBufferGpadlHandle,
261 NewChannel->Outbound.RingBuffer,
262 NewChannel->Outbound.RingSize,
263 NewChannel->Inbound.RingBuffer,
264 NewChannel->Inbound.RingSize,
265 SendRingBufferSize);
266
454f18a9 267 /* Create and init the channel open message */
e40d37cc 268 openInfo = kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_OPEN_CHANNEL), GFP_KERNEL);
3e7ee490
HJ
269 ASSERT(openInfo != NULL);
270
271 openInfo->WaitEvent = WaitEventCreate();
272
273 openMsg = (VMBUS_CHANNEL_OPEN_CHANNEL*)openInfo->Msg;
274 openMsg->Header.MessageType = ChannelMessageOpenChannel;
454f18a9 275 openMsg->OpenId = NewChannel->OfferMsg.ChildRelId; /* FIXME */
3e7ee490
HJ
276 openMsg->ChildRelId = NewChannel->OfferMsg.ChildRelId;
277 openMsg->RingBufferGpadlHandle = NewChannel->RingBufferGpadlHandle;
278 ASSERT(openMsg->RingBufferGpadlHandle);
279 openMsg->DownstreamRingBufferPageOffset = SendRingBufferSize >> PAGE_SHIFT;
454f18a9 280 openMsg->ServerContextAreaGpadlHandle = 0; /* TODO */
3e7ee490
HJ
281
282 ASSERT(UserDataLen <= MAX_USER_DEFINED_BYTES);
283 if (UserDataLen)
284 {
285 memcpy(openMsg->UserData, UserData, UserDataLen);
286 }
287
dd0813b6 288 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490 289 INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &openInfo->MsgListEntry);
dd0813b6 290 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490
HJ
291
292 DPRINT_DBG(VMBUS, "Sending channel open msg...");
293
294 ret = VmbusPostMessage(openMsg, sizeof(VMBUS_CHANNEL_OPEN_CHANNEL));
295 if (ret != 0)
296 {
297 DPRINT_ERR(VMBUS, "unable to open channel - %d", ret);
298 goto Cleanup;
299 }
300
454f18a9 301 /* FIXME: Need to time-out here */
3e7ee490
HJ
302 WaitEventWait(openInfo->WaitEvent);
303
304 if (openInfo->Response.OpenResult.Status == 0)
305 {
306 DPRINT_INFO(VMBUS, "channel <%p> open success!!", NewChannel);
307 }
308 else
309 {
310 DPRINT_INFO(VMBUS, "channel <%p> open failed - %d!!", NewChannel, openInfo->Response.OpenResult.Status);
311 }
312
313Cleanup:
dd0813b6 314 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490 315 REMOVE_ENTRY_LIST(&openInfo->MsgListEntry);
dd0813b6 316 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490 317
420beac4 318 kfree(openInfo->WaitEvent);
8c69f52a 319 kfree(openInfo);
3e7ee490
HJ
320
321 DPRINT_EXIT(VMBUS);
322
323 return 0;
324}
325
326/*++;
327
328Name:
329 DumpGpadlBody()
330
331Description:
332 Dump the gpadl body message to the console for debugging purposes.
333
334--*/
335static void DumpGpadlBody(
336 VMBUS_CHANNEL_GPADL_BODY *Gpadl,
4d643114 337 u32 Len)
3e7ee490
HJ
338{
339 int i=0;
340 int pfnCount=0;
341
59471438 342 pfnCount = (Len - sizeof(VMBUS_CHANNEL_GPADL_BODY))/ sizeof(u64);
3e7ee490
HJ
343 DPRINT_DBG(VMBUS, "gpadl body - len %d pfn count %d", Len, pfnCount);
344
345 for (i=0; i< pfnCount; i++)
346 {
347 DPRINT_DBG(VMBUS, "gpadl body - %d) pfn %llu", i, Gpadl->Pfn[i]);
348 }
349}
350
351
352/*++;
353
354Name:
355 DumpGpadlHeader()
356
357Description:
358 Dump the gpadl header message to the console for debugging purposes.
359
360--*/
361static void DumpGpadlHeader(
362 VMBUS_CHANNEL_GPADL_HEADER *Gpadl
363 )
364{
365 int i=0,j=0;
366 int pageCount=0;
367
368
369 DPRINT_DBG(VMBUS, "gpadl header - relid %d, range count %d, range buflen %d",
370 Gpadl->ChildRelId,
371 Gpadl->RangeCount,
372 Gpadl->RangeBufLen);
373 for (i=0; i< Gpadl->RangeCount; i++)
374 {
375 pageCount = Gpadl->Range[i].ByteCount >> PAGE_SHIFT;
376 pageCount = (pageCount > 26)? 26 : pageCount;
377
378 DPRINT_DBG(VMBUS, "gpadl range %d - len %d offset %d page count %d",
379 i, Gpadl->Range[i].ByteCount, Gpadl->Range[i].ByteOffset, pageCount);
380
381 for (j=0; j< pageCount; j++)
382 {
383 DPRINT_DBG(VMBUS, "%d) pfn %llu", j, Gpadl->Range[i].PfnArray[j]);
384 }
385 }
386}
387
388/*++;
389
390Name:
391 VmbusChannelCreateGpadlHeader()
392
393Description:
394 Creates a gpadl for the specified buffer
395
396--*/
397static int
398VmbusChannelCreateGpadlHeader(
454f18a9
BP
399 void * Kbuffer, /* from kmalloc() */
400 u32 Size, /* page-size multiple */
3e7ee490 401 VMBUS_CHANNEL_MSGINFO **MsgInfo,
4d643114 402 u32 *MessageCount)
3e7ee490
HJ
403{
404 int i;
405 int pageCount;
406 unsigned long long pfn;
407 VMBUS_CHANNEL_GPADL_HEADER* gpaHeader;
408 VMBUS_CHANNEL_GPADL_BODY* gpadlBody;
409 VMBUS_CHANNEL_MSGINFO* msgHeader;
410 VMBUS_CHANNEL_MSGINFO* msgBody;
4d643114 411 u32 msgSize;
3e7ee490
HJ
412
413 int pfnSum, pfnCount, pfnLeft, pfnCurr, pfnSize;
414
454f18a9 415 /* ASSERT( (kbuffer & (PAGE_SIZE-1)) == 0); */
3e7ee490
HJ
416 ASSERT( (Size & (PAGE_SIZE-1)) == 0);
417
418 pageCount = Size >> PAGE_SHIFT;
419 pfn = GetPhysicalAddress(Kbuffer) >> PAGE_SHIFT;
420
454f18a9 421 /* do we need a gpadl body msg */
3e7ee490 422 pfnSize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(VMBUS_CHANNEL_GPADL_HEADER) - sizeof(GPA_RANGE);
59471438 423 pfnCount = pfnSize / sizeof(u64);
3e7ee490 424
454f18a9 425 if (pageCount > pfnCount) /* we need a gpadl body */
3e7ee490 426 {
454f18a9 427 /* fill in the header */
59471438 428 msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_HEADER) + sizeof(GPA_RANGE) + pfnCount*sizeof(u64);
e276a3a5 429 msgHeader = kzalloc(msgSize, GFP_KERNEL);
3e7ee490
HJ
430
431 INITIALIZE_LIST_HEAD(&msgHeader->SubMsgList);
432 msgHeader->MessageSize=msgSize;
433
434 gpaHeader = (VMBUS_CHANNEL_GPADL_HEADER*)msgHeader->Msg;
435 gpaHeader->RangeCount = 1;
59471438 436 gpaHeader->RangeBufLen = sizeof(GPA_RANGE) + pageCount*sizeof(u64);
3e7ee490
HJ
437 gpaHeader->Range[0].ByteOffset = 0;
438 gpaHeader->Range[0].ByteCount = Size;
439 for (i=0; i<pfnCount; i++)
440 {
441 gpaHeader->Range[0].PfnArray[i] = pfn+i;
442 }
443 *MsgInfo = msgHeader;
444 *MessageCount = 1;
445
446 pfnSum = pfnCount;
447 pfnLeft = pageCount - pfnCount;
448
454f18a9 449 /* how many pfns can we fit */
3e7ee490 450 pfnSize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(VMBUS_CHANNEL_GPADL_BODY);
59471438 451 pfnCount = pfnSize / sizeof(u64);
3e7ee490 452
454f18a9 453 /* fill in the body */
3e7ee490
HJ
454 while (pfnLeft)
455 {
456 if (pfnLeft > pfnCount)
457 {
458 pfnCurr = pfnCount;
459 }
460 else
461 {
462 pfnCurr = pfnLeft;
463 }
464
59471438 465 msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_BODY) + pfnCurr*sizeof(u64);
e276a3a5 466 msgBody = kzalloc(msgSize, GFP_KERNEL);
3e7ee490
HJ
467 ASSERT(msgBody);
468 msgBody->MessageSize = msgSize;
469 (*MessageCount)++;
470 gpadlBody = (VMBUS_CHANNEL_GPADL_BODY*)msgBody->Msg;
471
454f18a9
BP
472 /* FIXME: Gpadl is u32 and we are using a pointer which could be 64-bit */
473 /* gpadlBody->Gpadl = kbuffer; */
3e7ee490
HJ
474 for (i=0; i<pfnCurr; i++)
475 {
476 gpadlBody->Pfn[i] = pfn + pfnSum + i;
477 }
478
454f18a9 479 /* add to msg header */
3e7ee490
HJ
480 INSERT_TAIL_LIST(&msgHeader->SubMsgList, &msgBody->MsgListEntry);
481 pfnSum += pfnCurr;
482 pfnLeft -= pfnCurr;
483 }
484 }
485 else
486 {
454f18a9 487 /* everything fits in a header */
59471438 488 msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_HEADER) + sizeof(GPA_RANGE) + pageCount*sizeof(u64);
e276a3a5 489 msgHeader = kzalloc(msgSize, GFP_KERNEL);
3e7ee490
HJ
490 msgHeader->MessageSize=msgSize;
491
492 gpaHeader = (VMBUS_CHANNEL_GPADL_HEADER*)msgHeader->Msg;
493 gpaHeader->RangeCount = 1;
59471438 494 gpaHeader->RangeBufLen = sizeof(GPA_RANGE) + pageCount*sizeof(u64);
3e7ee490
HJ
495 gpaHeader->Range[0].ByteOffset = 0;
496 gpaHeader->Range[0].ByteCount = Size;
497 for (i=0; i<pageCount; i++)
498 {
499 gpaHeader->Range[0].PfnArray[i] = pfn+i;
500 }
501
502 *MsgInfo = msgHeader;
503 *MessageCount = 1;
504 }
505
506 return 0;
507}
508
509
510/*++;
511
512Name:
513 VmbusChannelEstablishGpadl()
514
515Description:
516 Estabish a GPADL for the specified buffer
517
518--*/
bd1de709 519static int
3e7ee490
HJ
520VmbusChannelEstablishGpadl(
521 VMBUS_CHANNEL *Channel,
454f18a9
BP
522 void * Kbuffer, /* from kmalloc() */
523 u32 Size, /* page-size multiple */
4d643114 524 u32 *GpadlHandle
3e7ee490
HJ
525 )
526{
527 int ret=0;
528 VMBUS_CHANNEL_GPADL_HEADER* gpadlMsg;
529 VMBUS_CHANNEL_GPADL_BODY* gpadlBody;
454f18a9 530 /* VMBUS_CHANNEL_GPADL_CREATED* gpadlCreated; */
3e7ee490
HJ
531
532 VMBUS_CHANNEL_MSGINFO *msgInfo;
533 VMBUS_CHANNEL_MSGINFO *subMsgInfo;
534
4d643114 535 u32 msgCount;
3e7ee490
HJ
536 LIST_ENTRY* anchor;
537 LIST_ENTRY* curr;
4d643114 538 u32 nextGpadlHandle;
dd0813b6 539 unsigned long flags;
3e7ee490
HJ
540
541 DPRINT_ENTER(VMBUS);
542
543 nextGpadlHandle = gVmbusConnection.NextGpadlHandle;
544 InterlockedIncrement((int*)&gVmbusConnection.NextGpadlHandle);
545
546 VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
547 ASSERT(msgInfo != NULL);
548 ASSERT(msgCount >0);
549
550 msgInfo->WaitEvent = WaitEventCreate();
551 gpadlMsg = (VMBUS_CHANNEL_GPADL_HEADER*)msgInfo->Msg;
552 gpadlMsg->Header.MessageType = ChannelMessageGpadlHeader;
553 gpadlMsg->ChildRelId = Channel->OfferMsg.ChildRelId;
554 gpadlMsg->Gpadl = nextGpadlHandle;
555
556 DumpGpadlHeader(gpadlMsg);
557
dd0813b6 558 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490 559 INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &msgInfo->MsgListEntry);
dd0813b6 560 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490
HJ
561
562 DPRINT_DBG(VMBUS, "buffer %p, size %d msg cnt %d", Kbuffer, Size, msgCount);
563
b7d7ae6f 564 DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd", msgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO));
3e7ee490
HJ
565
566 ret = VmbusPostMessage(gpadlMsg, msgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO));
567 if (ret != 0)
568 {
569 DPRINT_ERR(VMBUS, "Unable to open channel - %d", ret);
570 goto Cleanup;
571 }
572
573 if (msgCount>1)
574 {
575 ITERATE_LIST_ENTRIES(anchor, curr, &msgInfo->SubMsgList)
576 {
577 subMsgInfo = (VMBUS_CHANNEL_MSGINFO*) curr;
578 gpadlBody = (VMBUS_CHANNEL_GPADL_BODY*)subMsgInfo->Msg;
579
580 gpadlBody->Header.MessageType = ChannelMessageGpadlBody;
581 gpadlBody->Gpadl = nextGpadlHandle;
582
b7d7ae6f 583 DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd", subMsgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO));
3e7ee490
HJ
584
585 DumpGpadlBody(gpadlBody, subMsgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO));
586 ret = VmbusPostMessage(gpadlBody, subMsgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO));
587 ASSERT(ret == 0);
588 }
589 }
590 WaitEventWait(msgInfo->WaitEvent);
591
454f18a9 592 /* At this point, we received the gpadl created msg */
3e7ee490
HJ
593 DPRINT_DBG(VMBUS, "Received GPADL created (relid %d, status %d handle %x)",
594 Channel->OfferMsg.ChildRelId,
595 msgInfo->Response.GpadlCreated.CreationStatus,
596 gpadlMsg->Gpadl);
597
598 *GpadlHandle = gpadlMsg->Gpadl;
599
600Cleanup:
dd0813b6 601 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490 602 REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry);
dd0813b6 603 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490 604
420beac4 605 kfree(msgInfo->WaitEvent);
8c69f52a 606 kfree(msgInfo);
3e7ee490
HJ
607
608 DPRINT_EXIT(VMBUS);
609
610 return ret;
611}
612
613
614
615/*++;
616
617Name:
618 VmbusChannelTeardownGpadl()
619
620Description:
621 Teardown the specified GPADL handle
622
623--*/
bd1de709 624static int
3e7ee490
HJ
625VmbusChannelTeardownGpadl(
626 VMBUS_CHANNEL *Channel,
4d643114 627 u32 GpadlHandle
3e7ee490
HJ
628 )
629{
630 int ret=0;
631 VMBUS_CHANNEL_GPADL_TEARDOWN *msg;
632 VMBUS_CHANNEL_MSGINFO* info;
dd0813b6 633 unsigned long flags;
3e7ee490
HJ
634
635 DPRINT_ENTER(VMBUS);
636
637 ASSERT(GpadlHandle != 0);
638
e40d37cc 639 info = kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_TEARDOWN), GFP_KERNEL);
3e7ee490
HJ
640 ASSERT(info != NULL);
641
642 info->WaitEvent = WaitEventCreate();
643
644 msg = (VMBUS_CHANNEL_GPADL_TEARDOWN*)info->Msg;
645
646 msg->Header.MessageType = ChannelMessageGpadlTeardown;
647 msg->ChildRelId = Channel->OfferMsg.ChildRelId;
648 msg->Gpadl = GpadlHandle;
649
dd0813b6 650 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490 651 INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &info->MsgListEntry);
dd0813b6 652 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490
HJ
653
654 ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_GPADL_TEARDOWN));
655 if (ret != 0)
656 {
454f18a9 657 /* TODO: */
3e7ee490
HJ
658 }
659
660 WaitEventWait(info->WaitEvent);
661
454f18a9 662 /* Received a torndown response */
dd0813b6 663 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490 664 REMOVE_ENTRY_LIST(&info->MsgListEntry);
dd0813b6 665 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
3e7ee490 666
420beac4 667 kfree(info->WaitEvent);
8c69f52a 668 kfree(info);
3e7ee490
HJ
669
670 DPRINT_EXIT(VMBUS);
671
672 return ret;
673}
674
675
676/*++
677
678Name:
679 VmbusChannelClose()
680
681Description:
682 Close the specified channel
683
684--*/
bd1de709 685static void
3e7ee490
HJ
686VmbusChannelClose(
687 VMBUS_CHANNEL *Channel
688 )
689{
690 int ret=0;
691 VMBUS_CHANNEL_CLOSE_CHANNEL* msg;
692 VMBUS_CHANNEL_MSGINFO* info;
0f5e44ca 693 unsigned long flags;
3e7ee490
HJ
694
695 DPRINT_ENTER(VMBUS);
696
454f18a9 697 /* Stop callback and cancel the timer asap */
3e7ee490
HJ
698 Channel->OnChannelCallback = NULL;
699 TimerStop(Channel->PollTimer);
700
454f18a9 701 /* Send a closing message */
e40d37cc 702 info = kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_CLOSE_CHANNEL), GFP_KERNEL);
3e7ee490
HJ
703 ASSERT(info != NULL);
704
454f18a9 705 /* info->waitEvent = WaitEventCreate(); */
3e7ee490
HJ
706
707 msg = (VMBUS_CHANNEL_CLOSE_CHANNEL*)info->Msg;
708 msg->Header.MessageType = ChannelMessageCloseChannel;
709 msg->ChildRelId = Channel->OfferMsg.ChildRelId;
710
711 ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_CLOSE_CHANNEL));
712 if (ret != 0)
713 {
454f18a9 714 /* TODO: */
3e7ee490
HJ
715 }
716
454f18a9 717 /* Tear down the gpadl for the channel's ring buffer */
3e7ee490
HJ
718 if (Channel->RingBufferGpadlHandle)
719 {
720 VmbusChannelTeardownGpadl(Channel, Channel->RingBufferGpadlHandle);
721 }
722
454f18a9 723 /* TODO: Send a msg to release the childRelId */
3e7ee490 724
454f18a9 725 /* Cleanup the ring buffers for this channel */
3e7ee490
HJ
726 RingBufferCleanup(&Channel->Outbound);
727 RingBufferCleanup(&Channel->Inbound);
728
729 PageFree(Channel->RingBufferPages, Channel->RingBufferPageCount);
730
8c69f52a 731 kfree(info);
3e7ee490 732
454f18a9
BP
733
734 /*
735 * If we are closing the channel during an error path in
736 * opening the channel, don't free the channel since the
737 * caller will free the channel
738 */
739
3e7ee490
HJ
740 if (Channel->State == CHANNEL_OPEN_STATE)
741 {
0f5e44ca 742 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
3e7ee490 743 REMOVE_ENTRY_LIST(&Channel->ListEntry);
0f5e44ca 744 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
3e7ee490
HJ
745
746 FreeVmbusChannel(Channel);
747 }
748
749 DPRINT_EXIT(VMBUS);
750}
751
752
753/*++
754
755Name:
756 VmbusChannelSendPacket()
757
758Description:
759 Send the specified buffer on the given channel
760
761--*/
bd1de709 762static int
3e7ee490
HJ
763VmbusChannelSendPacket(
764 VMBUS_CHANNEL *Channel,
8282c400 765 const void * Buffer,
4d643114 766 u32 BufferLen,
59471438 767 u64 RequestId,
3e7ee490 768 VMBUS_PACKET_TYPE Type,
4d643114 769 u32 Flags
3e7ee490
HJ
770)
771{
772 int ret=0;
773 VMPACKET_DESCRIPTOR desc;
4d643114 774 u32 packetLen = sizeof(VMPACKET_DESCRIPTOR) + BufferLen;
59471438 775 u32 packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
3e7ee490 776 SG_BUFFER_LIST bufferList[3];
59471438 777 u64 alignedData=0;
3e7ee490
HJ
778
779 DPRINT_ENTER(VMBUS);
780 DPRINT_DBG(VMBUS, "channel %p buffer %p len %d", Channel, Buffer, BufferLen);
781
782 DumpVmbusChannel(Channel);
783
59471438 784 ASSERT((packetLenAligned - packetLen) < sizeof(u64));
3e7ee490 785
454f18a9
BP
786 /* Setup the descriptor */
787 desc.Type = Type; /* VmbusPacketTypeDataInBand; */
788 desc.Flags = Flags; /* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; */
789 desc.DataOffset8 = sizeof(VMPACKET_DESCRIPTOR) >> 3; /* in 8-bytes granularity */
790 desc.Length8 = (u16)(packetLenAligned >> 3);
791 desc.TransactionId = RequestId;
3e7ee490
HJ
792
793 bufferList[0].Data = &desc;
794 bufferList[0].Length = sizeof(VMPACKET_DESCRIPTOR);
795
796 bufferList[1].Data = Buffer;
797 bufferList[1].Length = BufferLen;
798
799 bufferList[2].Data = &alignedData;
800 bufferList[2].Length = packetLenAligned - packetLen;
801
802 ret = RingBufferWrite(
803 &Channel->Outbound,
804 bufferList,
805 3);
806
454f18a9 807 /* TODO: We should determine if this is optional */
3e7ee490
HJ
808 if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
809 {
810 VmbusChannelSetEvent(Channel);
811 }
812
813 DPRINT_EXIT(VMBUS);
814
815 return ret;
816}
817
818
819/*++
820
821Name:
822 VmbusChannelSendPacketPageBuffer()
823
824Description:
825 Send a range of single-page buffer packets using a GPADL Direct packet type.
826
827--*/
bd1de709 828static int
3e7ee490
HJ
829VmbusChannelSendPacketPageBuffer(
830 VMBUS_CHANNEL *Channel,
831 PAGE_BUFFER PageBuffers[],
4d643114 832 u32 PageCount,
8282c400 833 void * Buffer,
4d643114 834 u32 BufferLen,
59471438 835 u64 RequestId
3e7ee490
HJ
836)
837{
838 int ret=0;
839 int i=0;
0cf4fa80 840 struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER desc;
4d643114
GKH
841 u32 descSize;
842 u32 packetLen;
843 u32 packetLenAligned;
3e7ee490 844 SG_BUFFER_LIST bufferList[3];
59471438 845 u64 alignedData=0;
3e7ee490
HJ
846
847 DPRINT_ENTER(VMBUS);
848
849 ASSERT(PageCount <= MAX_PAGE_BUFFER_COUNT);
850
851 DumpVmbusChannel(Channel);
852
454f18a9 853 /* Adjust the size down since VMBUS_CHANNEL_PACKET_PAGE_BUFFER is the largest size we support */
0cf4fa80 854 descSize = sizeof(struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER) - ((MAX_PAGE_BUFFER_COUNT - PageCount)*sizeof(PAGE_BUFFER));
3e7ee490 855 packetLen = descSize + BufferLen;
59471438 856 packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
3e7ee490 857
59471438 858 ASSERT((packetLenAligned - packetLen) < sizeof(u64));
3e7ee490 859
454f18a9 860 /* Setup the descriptor */
3e7ee490
HJ
861 desc.Type = VmbusPacketTypeDataUsingGpaDirect;
862 desc.Flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
454f18a9
BP
863 desc.DataOffset8 = descSize >> 3; /* in 8-bytes grandularity */
864 desc.Length8 = (u16)(packetLenAligned >> 3);
865 desc.TransactionId = RequestId;
3e7ee490
HJ
866 desc.RangeCount = PageCount;
867
868 for (i=0; i<PageCount; i++)
869 {
870 desc.Range[i].Length = PageBuffers[i].Length;
871 desc.Range[i].Offset = PageBuffers[i].Offset;
872 desc.Range[i].Pfn = PageBuffers[i].Pfn;
873 }
874
875 bufferList[0].Data = &desc;
876 bufferList[0].Length = descSize;
877
878 bufferList[1].Data = Buffer;
879 bufferList[1].Length = BufferLen;
880
881 bufferList[2].Data = &alignedData;
882 bufferList[2].Length = packetLenAligned - packetLen;
883
884 ret = RingBufferWrite(
885 &Channel->Outbound,
886 bufferList,
887 3);
888
454f18a9 889 /* TODO: We should determine if this is optional */
3e7ee490
HJ
890 if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
891 {
892 VmbusChannelSetEvent(Channel);
893 }
894
895 DPRINT_EXIT(VMBUS);
896
897 return ret;
898}
899
900
901
902/*++
903
904Name:
905 VmbusChannelSendPacketMultiPageBuffer()
906
907Description:
908 Send a multi-page buffer packet using a GPADL Direct packet type.
909
910--*/
bd1de709 911static int
3e7ee490
HJ
912VmbusChannelSendPacketMultiPageBuffer(
913 VMBUS_CHANNEL *Channel,
914 MULTIPAGE_BUFFER *MultiPageBuffer,
8282c400 915 void * Buffer,
4d643114 916 u32 BufferLen,
59471438 917 u64 RequestId
3e7ee490
HJ
918)
919{
920 int ret=0;
3fcc523a 921 struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER desc;
4d643114
GKH
922 u32 descSize;
923 u32 packetLen;
924 u32 packetLenAligned;
3e7ee490 925 SG_BUFFER_LIST bufferList[3];
59471438 926 u64 alignedData=0;
4d643114 927 u32 PfnCount = NUM_PAGES_SPANNED(MultiPageBuffer->Offset, MultiPageBuffer->Length);
3e7ee490
HJ
928
929 DPRINT_ENTER(VMBUS);
930
931 DumpVmbusChannel(Channel);
932
933 DPRINT_DBG(VMBUS, "data buffer - offset %u len %u pfn count %u", MultiPageBuffer->Offset, MultiPageBuffer->Length, PfnCount);
934
935 ASSERT(PfnCount > 0);
936 ASSERT(PfnCount <= MAX_MULTIPAGE_BUFFER_COUNT);
937
454f18a9 938 /* Adjust the size down since VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER is the largest size we support */
3fcc523a 939 descSize = sizeof(struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER) - ((MAX_MULTIPAGE_BUFFER_COUNT - PfnCount)*sizeof(u64));
3e7ee490 940 packetLen = descSize + BufferLen;
59471438 941 packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
3e7ee490 942
59471438 943 ASSERT((packetLenAligned - packetLen) < sizeof(u64));
3e7ee490 944
454f18a9 945 /* Setup the descriptor */
3e7ee490
HJ
946 desc.Type = VmbusPacketTypeDataUsingGpaDirect;
947 desc.Flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
454f18a9
BP
948 desc.DataOffset8 = descSize >> 3; /* in 8-bytes grandularity */
949 desc.Length8 = (u16)(packetLenAligned >> 3);
950 desc.TransactionId = RequestId;
3e7ee490
HJ
951 desc.RangeCount = 1;
952
953 desc.Range.Length = MultiPageBuffer->Length;
954 desc.Range.Offset = MultiPageBuffer->Offset;
955
59471438 956 memcpy(desc.Range.PfnArray, MultiPageBuffer->PfnArray, PfnCount*sizeof(u64));
3e7ee490
HJ
957
958 bufferList[0].Data = &desc;
959 bufferList[0].Length = descSize;
960
961 bufferList[1].Data = Buffer;
962 bufferList[1].Length = BufferLen;
963
964 bufferList[2].Data = &alignedData;
965 bufferList[2].Length = packetLenAligned - packetLen;
966
967 ret = RingBufferWrite(
968 &Channel->Outbound,
969 bufferList,
970 3);
971
454f18a9 972 /* TODO: We should determine if this is optional */
3e7ee490
HJ
973 if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
974 {
975 VmbusChannelSetEvent(Channel);
976 }
977
978 DPRINT_EXIT(VMBUS);
979
980 return ret;
981}
982
983
984/*++
985
986Name:
987 VmbusChannelRecvPacket()
988
989Description:
990 Retrieve the user packet on the specified channel
991
992--*/
454f18a9 993/* TODO: Do we ever receive a gpa direct packet other than the ones we send ? */
bd1de709 994static int
3e7ee490
HJ
995VmbusChannelRecvPacket(
996 VMBUS_CHANNEL *Channel,
8282c400 997 void * Buffer,
4d643114
GKH
998 u32 BufferLen,
999 u32* BufferActualLen,
59471438 1000 u64* RequestId
3e7ee490
HJ
1001 )
1002{
1003 VMPACKET_DESCRIPTOR desc;
4d643114
GKH
1004 u32 packetLen;
1005 u32 userLen;
3e7ee490 1006 int ret;
54411c42 1007 unsigned long flags;
3e7ee490
HJ
1008
1009 DPRINT_ENTER(VMBUS);
1010
1011 *BufferActualLen = 0;
1012 *RequestId = 0;
1013
54411c42 1014 spin_lock_irqsave(&Channel->inbound_lock, flags);
3e7ee490
HJ
1015
1016 ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(VMPACKET_DESCRIPTOR));
1017 if (ret != 0)
1018 {
54411c42 1019 spin_unlock_irqrestore(&Channel->inbound_lock, flags);
3e7ee490 1020
454f18a9 1021 /* DPRINT_DBG(VMBUS, "nothing to read!!"); */
3e7ee490
HJ
1022 DPRINT_EXIT(VMBUS);
1023 return 0;
1024 }
1025
454f18a9 1026 /* VmbusChannelClearEvent(Channel); */
3e7ee490
HJ
1027
1028 packetLen = desc.Length8 << 3;
1029 userLen = packetLen - (desc.DataOffset8 << 3);
454f18a9 1030 /* ASSERT(userLen > 0); */
3e7ee490
HJ
1031
1032 DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ",
1033 Channel,
1034 Channel->OfferMsg.ChildRelId,
1035 desc.Type,
1036 desc.Flags,
1037 desc.TransactionId, packetLen, userLen);
1038
1039 *BufferActualLen = userLen;
1040
1041 if (userLen > BufferLen)
1042 {
54411c42 1043 spin_unlock_irqrestore(&Channel->inbound_lock, flags);
3e7ee490
HJ
1044
1045 DPRINT_ERR(VMBUS, "buffer too small - got %d needs %d", BufferLen, userLen);
1046 DPRINT_EXIT(VMBUS);
1047
1048 return -1;
1049 }
1050
1051 *RequestId = desc.TransactionId;
1052
454f18a9 1053 /* Copy over the packet to the user buffer */
3e7ee490
HJ
1054 ret = RingBufferRead(&Channel->Inbound, Buffer, userLen, (desc.DataOffset8 << 3));
1055
54411c42 1056 spin_unlock_irqrestore(&Channel->inbound_lock, flags);
3e7ee490
HJ
1057
1058 DPRINT_EXIT(VMBUS);
1059
1060 return 0;
1061}
1062
1063/*++
1064
1065Name:
1066 VmbusChannelRecvPacketRaw()
1067
1068Description:
1069 Retrieve the raw packet on the specified channel
1070
1071--*/
bd1de709 1072static int
3e7ee490
HJ
1073VmbusChannelRecvPacketRaw(
1074 VMBUS_CHANNEL *Channel,
8282c400 1075 void * Buffer,
4d643114
GKH
1076 u32 BufferLen,
1077 u32* BufferActualLen,
59471438 1078 u64* RequestId
3e7ee490
HJ
1079 )
1080{
1081 VMPACKET_DESCRIPTOR desc;
4d643114
GKH
1082 u32 packetLen;
1083 u32 userLen;
3e7ee490 1084 int ret;
54411c42 1085 unsigned long flags;
3e7ee490
HJ
1086
1087 DPRINT_ENTER(VMBUS);
1088
1089 *BufferActualLen = 0;
1090 *RequestId = 0;
1091
54411c42 1092 spin_lock_irqsave(&Channel->inbound_lock, flags);
3e7ee490
HJ
1093
1094 ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(VMPACKET_DESCRIPTOR));
1095 if (ret != 0)
1096 {
54411c42 1097 spin_unlock_irqrestore(&Channel->inbound_lock, flags);
3e7ee490 1098
454f18a9 1099 /* DPRINT_DBG(VMBUS, "nothing to read!!"); */
3e7ee490
HJ
1100 DPRINT_EXIT(VMBUS);
1101 return 0;
1102 }
1103
454f18a9 1104 /* VmbusChannelClearEvent(Channel); */
3e7ee490
HJ
1105
1106 packetLen = desc.Length8 << 3;
1107 userLen = packetLen - (desc.DataOffset8 << 3);
1108
1109 DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ",
1110 Channel,
1111 Channel->OfferMsg.ChildRelId,
1112 desc.Type,
1113 desc.Flags,
1114 desc.TransactionId, packetLen, userLen);
1115
1116 *BufferActualLen = packetLen;
1117
1118 if (packetLen > BufferLen)
1119 {
54411c42 1120 spin_unlock_irqrestore(&Channel->inbound_lock, flags);
3e7ee490
HJ
1121
1122 DPRINT_ERR(VMBUS, "buffer too small - needed %d bytes but got space for only %d bytes", packetLen, BufferLen);
1123 DPRINT_EXIT(VMBUS);
1124 return -2;
1125 }
1126
1127 *RequestId = desc.TransactionId;
1128
454f18a9 1129 /* Copy over the entire packet to the user buffer */
3e7ee490
HJ
1130 ret = RingBufferRead(&Channel->Inbound, Buffer, packetLen, 0);
1131
54411c42 1132 spin_unlock_irqrestore(&Channel->inbound_lock, flags);
3e7ee490
HJ
1133
1134 DPRINT_EXIT(VMBUS);
1135
1136 return 0;
1137}
1138
1139
1140/*++
1141
1142Name:
1143 VmbusChannelOnChannelEvent()
1144
1145Description:
1146 Channel event callback
1147
1148--*/
bd1de709 1149static void
3e7ee490
HJ
1150VmbusChannelOnChannelEvent(
1151 VMBUS_CHANNEL *Channel
1152 )
1153{
1154 DumpVmbusChannel(Channel);
1155 ASSERT(Channel->OnChannelCallback);
1156#ifdef ENABLE_POLLING
1157 TimerStop(Channel->PollTimer);
1158 Channel->OnChannelCallback(Channel->ChannelCallbackContext);
1159 TimerStart(Channel->PollTimer, 100 /* 100us */);
1160#else
1161 Channel->OnChannelCallback(Channel->ChannelCallbackContext);
1162#endif
1163}
1164
1165/*++
1166
1167Name:
1168 VmbusChannelOnTimer()
1169
1170Description:
1171 Timer event callback
1172
1173--*/
bd1de709 1174static void
3e7ee490
HJ
1175VmbusChannelOnTimer(
1176 void *Context
1177 )
1178{
1179 VMBUS_CHANNEL *channel = (VMBUS_CHANNEL*)Context;
1180
1181 if (channel->OnChannelCallback)
1182 {
1183 channel->OnChannelCallback(channel->ChannelCallbackContext);
1184#ifdef ENABLE_POLLING
1185 TimerStart(channel->PollTimer, 100 /* 100us */);
1186#endif
1187 }
1188}
1189
1190
1191/*++
1192
1193Name:
1194 DumpVmbusChannel()
1195
1196Description:
1197 Dump vmbus channel info to the console
1198
1199--*/
1200static void
1201DumpVmbusChannel(
1202 VMBUS_CHANNEL *Channel
1203 )
1204{
1205 DPRINT_DBG(VMBUS, "Channel (%d)", Channel->OfferMsg.ChildRelId);
1206 DumpRingInfo(&Channel->Outbound, "Outbound ");
1207 DumpRingInfo(&Channel->Inbound, "Inbound ");
1208}
1209
1210
454f18a9 1211/* eof */