Staging: hv: Replace typedef SG_BUFFER_LIST by struct scatterlist
[deliverable/linux.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 */
bfc30aae 233 out = osd_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
bfc30aae 271 openInfo->WaitEvent = osd_WaitEventCreate();
3e7ee490
HJ
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 */
bfc30aae 302 osd_WaitEventWait(openInfo->WaitEvent);
3e7ee490
HJ
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;
fa56d361 419 pfn = virt_to_phys(Kbuffer) >> PAGE_SHIFT;
3e7ee490 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
f4888417
BP
543 nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle);
544 atomic_inc(&gVmbusConnection.NextGpadlHandle);
3e7ee490
HJ
545
546 VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
547 ASSERT(msgInfo != NULL);
548 ASSERT(msgCount >0);
549
bfc30aae 550 msgInfo->WaitEvent = osd_WaitEventCreate();
3e7ee490
HJ
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 }
bfc30aae 590 osd_WaitEventWait(msgInfo->WaitEvent);
3e7ee490 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
bfc30aae 642 info->WaitEvent = osd_WaitEventCreate();
3e7ee490
HJ
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
bfc30aae 660 osd_WaitEventWait(info->WaitEvent);
3e7ee490 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 698 Channel->OnChannelCallback = NULL;
c8a429a4 699 del_timer(&Channel->poll_timer);
3e7ee490 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
bfc30aae 705 /* info->waitEvent = osd_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
bfc30aae 729 osd_PageFree(Channel->RingBufferPages, Channel->RingBufferPageCount);
3e7ee490 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));
b219b3f7 776 struct scatterlist 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 792
b219b3f7
NP
793 sg_init_table(bufferList,3);
794 sg_set_buf(&bufferList[0], &desc, sizeof(VMPACKET_DESCRIPTOR));
795 sg_set_buf(&bufferList[1], Buffer, BufferLen);
796 sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen);
3e7ee490
HJ
797
798 ret = RingBufferWrite(
799 &Channel->Outbound,
800 bufferList,
801 3);
802
454f18a9 803 /* TODO: We should determine if this is optional */
3e7ee490
HJ
804 if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
805 {
806 VmbusChannelSetEvent(Channel);
807 }
808
809 DPRINT_EXIT(VMBUS);
810
811 return ret;
812}
813
814
815/*++
816
817Name:
818 VmbusChannelSendPacketPageBuffer()
819
820Description:
821 Send a range of single-page buffer packets using a GPADL Direct packet type.
822
823--*/
bd1de709 824static int
3e7ee490
HJ
825VmbusChannelSendPacketPageBuffer(
826 VMBUS_CHANNEL *Channel,
827 PAGE_BUFFER PageBuffers[],
4d643114 828 u32 PageCount,
8282c400 829 void * Buffer,
4d643114 830 u32 BufferLen,
59471438 831 u64 RequestId
3e7ee490
HJ
832)
833{
834 int ret=0;
835 int i=0;
0cf4fa80 836 struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER desc;
4d643114
GKH
837 u32 descSize;
838 u32 packetLen;
839 u32 packetLenAligned;
b219b3f7 840 struct scatterlist bufferList[3];
59471438 841 u64 alignedData=0;
3e7ee490
HJ
842
843 DPRINT_ENTER(VMBUS);
844
845 ASSERT(PageCount <= MAX_PAGE_BUFFER_COUNT);
846
847 DumpVmbusChannel(Channel);
848
454f18a9 849 /* Adjust the size down since VMBUS_CHANNEL_PACKET_PAGE_BUFFER is the largest size we support */
0cf4fa80 850 descSize = sizeof(struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER) - ((MAX_PAGE_BUFFER_COUNT - PageCount)*sizeof(PAGE_BUFFER));
3e7ee490 851 packetLen = descSize + BufferLen;
59471438 852 packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
3e7ee490 853
59471438 854 ASSERT((packetLenAligned - packetLen) < sizeof(u64));
3e7ee490 855
454f18a9 856 /* Setup the descriptor */
3e7ee490
HJ
857 desc.Type = VmbusPacketTypeDataUsingGpaDirect;
858 desc.Flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
454f18a9
BP
859 desc.DataOffset8 = descSize >> 3; /* in 8-bytes grandularity */
860 desc.Length8 = (u16)(packetLenAligned >> 3);
861 desc.TransactionId = RequestId;
3e7ee490
HJ
862 desc.RangeCount = PageCount;
863
864 for (i=0; i<PageCount; i++)
865 {
866 desc.Range[i].Length = PageBuffers[i].Length;
867 desc.Range[i].Offset = PageBuffers[i].Offset;
868 desc.Range[i].Pfn = PageBuffers[i].Pfn;
869 }
870
b219b3f7
NP
871 sg_init_table(bufferList,3);
872 sg_set_buf(&bufferList[0], &desc, descSize);
873 sg_set_buf(&bufferList[1], Buffer, BufferLen);
874 sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen);
3e7ee490
HJ
875
876 ret = RingBufferWrite(
877 &Channel->Outbound,
878 bufferList,
879 3);
880
454f18a9 881 /* TODO: We should determine if this is optional */
3e7ee490
HJ
882 if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
883 {
884 VmbusChannelSetEvent(Channel);
885 }
886
887 DPRINT_EXIT(VMBUS);
888
889 return ret;
890}
891
892
893
894/*++
895
896Name:
897 VmbusChannelSendPacketMultiPageBuffer()
898
899Description:
900 Send a multi-page buffer packet using a GPADL Direct packet type.
901
902--*/
bd1de709 903static int
3e7ee490
HJ
904VmbusChannelSendPacketMultiPageBuffer(
905 VMBUS_CHANNEL *Channel,
906 MULTIPAGE_BUFFER *MultiPageBuffer,
8282c400 907 void * Buffer,
4d643114 908 u32 BufferLen,
59471438 909 u64 RequestId
3e7ee490
HJ
910)
911{
912 int ret=0;
3fcc523a 913 struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER desc;
4d643114
GKH
914 u32 descSize;
915 u32 packetLen;
916 u32 packetLenAligned;
b219b3f7 917 struct scatterlist bufferList[3];
59471438 918 u64 alignedData=0;
4d643114 919 u32 PfnCount = NUM_PAGES_SPANNED(MultiPageBuffer->Offset, MultiPageBuffer->Length);
3e7ee490
HJ
920
921 DPRINT_ENTER(VMBUS);
922
923 DumpVmbusChannel(Channel);
924
925 DPRINT_DBG(VMBUS, "data buffer - offset %u len %u pfn count %u", MultiPageBuffer->Offset, MultiPageBuffer->Length, PfnCount);
926
927 ASSERT(PfnCount > 0);
928 ASSERT(PfnCount <= MAX_MULTIPAGE_BUFFER_COUNT);
929
454f18a9 930 /* Adjust the size down since VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER is the largest size we support */
3fcc523a 931 descSize = sizeof(struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER) - ((MAX_MULTIPAGE_BUFFER_COUNT - PfnCount)*sizeof(u64));
3e7ee490 932 packetLen = descSize + BufferLen;
59471438 933 packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
3e7ee490 934
59471438 935 ASSERT((packetLenAligned - packetLen) < sizeof(u64));
3e7ee490 936
454f18a9 937 /* Setup the descriptor */
3e7ee490
HJ
938 desc.Type = VmbusPacketTypeDataUsingGpaDirect;
939 desc.Flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
454f18a9
BP
940 desc.DataOffset8 = descSize >> 3; /* in 8-bytes grandularity */
941 desc.Length8 = (u16)(packetLenAligned >> 3);
942 desc.TransactionId = RequestId;
3e7ee490
HJ
943 desc.RangeCount = 1;
944
945 desc.Range.Length = MultiPageBuffer->Length;
946 desc.Range.Offset = MultiPageBuffer->Offset;
947
59471438 948 memcpy(desc.Range.PfnArray, MultiPageBuffer->PfnArray, PfnCount*sizeof(u64));
3e7ee490 949
b219b3f7
NP
950 sg_init_table(bufferList,3);
951 sg_set_buf(&bufferList[0], &desc, descSize);
952 sg_set_buf(&bufferList[1], Buffer, BufferLen);
953 sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen);
3e7ee490
HJ
954
955 ret = RingBufferWrite(
956 &Channel->Outbound,
957 bufferList,
958 3);
959
454f18a9 960 /* TODO: We should determine if this is optional */
3e7ee490
HJ
961 if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
962 {
963 VmbusChannelSetEvent(Channel);
964 }
965
966 DPRINT_EXIT(VMBUS);
967
968 return ret;
969}
970
971
972/*++
973
974Name:
975 VmbusChannelRecvPacket()
976
977Description:
978 Retrieve the user packet on the specified channel
979
980--*/
454f18a9 981/* TODO: Do we ever receive a gpa direct packet other than the ones we send ? */
bd1de709 982static int
3e7ee490
HJ
983VmbusChannelRecvPacket(
984 VMBUS_CHANNEL *Channel,
8282c400 985 void * Buffer,
4d643114
GKH
986 u32 BufferLen,
987 u32* BufferActualLen,
59471438 988 u64* RequestId
3e7ee490
HJ
989 )
990{
991 VMPACKET_DESCRIPTOR desc;
4d643114
GKH
992 u32 packetLen;
993 u32 userLen;
3e7ee490 994 int ret;
54411c42 995 unsigned long flags;
3e7ee490
HJ
996
997 DPRINT_ENTER(VMBUS);
998
999 *BufferActualLen = 0;
1000 *RequestId = 0;
1001
54411c42 1002 spin_lock_irqsave(&Channel->inbound_lock, flags);
3e7ee490
HJ
1003
1004 ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(VMPACKET_DESCRIPTOR));
1005 if (ret != 0)
1006 {
54411c42 1007 spin_unlock_irqrestore(&Channel->inbound_lock, flags);
3e7ee490 1008
454f18a9 1009 /* DPRINT_DBG(VMBUS, "nothing to read!!"); */
3e7ee490
HJ
1010 DPRINT_EXIT(VMBUS);
1011 return 0;
1012 }
1013
454f18a9 1014 /* VmbusChannelClearEvent(Channel); */
3e7ee490
HJ
1015
1016 packetLen = desc.Length8 << 3;
1017 userLen = packetLen - (desc.DataOffset8 << 3);
454f18a9 1018 /* ASSERT(userLen > 0); */
3e7ee490
HJ
1019
1020 DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ",
1021 Channel,
1022 Channel->OfferMsg.ChildRelId,
1023 desc.Type,
1024 desc.Flags,
1025 desc.TransactionId, packetLen, userLen);
1026
1027 *BufferActualLen = userLen;
1028
1029 if (userLen > BufferLen)
1030 {
54411c42 1031 spin_unlock_irqrestore(&Channel->inbound_lock, flags);
3e7ee490
HJ
1032
1033 DPRINT_ERR(VMBUS, "buffer too small - got %d needs %d", BufferLen, userLen);
1034 DPRINT_EXIT(VMBUS);
1035
1036 return -1;
1037 }
1038
1039 *RequestId = desc.TransactionId;
1040
454f18a9 1041 /* Copy over the packet to the user buffer */
3e7ee490
HJ
1042 ret = RingBufferRead(&Channel->Inbound, Buffer, userLen, (desc.DataOffset8 << 3));
1043
54411c42 1044 spin_unlock_irqrestore(&Channel->inbound_lock, flags);
3e7ee490
HJ
1045
1046 DPRINT_EXIT(VMBUS);
1047
1048 return 0;
1049}
1050
1051/*++
1052
1053Name:
1054 VmbusChannelRecvPacketRaw()
1055
1056Description:
1057 Retrieve the raw packet on the specified channel
1058
1059--*/
bd1de709 1060static int
3e7ee490
HJ
1061VmbusChannelRecvPacketRaw(
1062 VMBUS_CHANNEL *Channel,
8282c400 1063 void * Buffer,
4d643114
GKH
1064 u32 BufferLen,
1065 u32* BufferActualLen,
59471438 1066 u64* RequestId
3e7ee490
HJ
1067 )
1068{
1069 VMPACKET_DESCRIPTOR desc;
4d643114
GKH
1070 u32 packetLen;
1071 u32 userLen;
3e7ee490 1072 int ret;
54411c42 1073 unsigned long flags;
3e7ee490
HJ
1074
1075 DPRINT_ENTER(VMBUS);
1076
1077 *BufferActualLen = 0;
1078 *RequestId = 0;
1079
54411c42 1080 spin_lock_irqsave(&Channel->inbound_lock, flags);
3e7ee490
HJ
1081
1082 ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(VMPACKET_DESCRIPTOR));
1083 if (ret != 0)
1084 {
54411c42 1085 spin_unlock_irqrestore(&Channel->inbound_lock, flags);
3e7ee490 1086
454f18a9 1087 /* DPRINT_DBG(VMBUS, "nothing to read!!"); */
3e7ee490
HJ
1088 DPRINT_EXIT(VMBUS);
1089 return 0;
1090 }
1091
454f18a9 1092 /* VmbusChannelClearEvent(Channel); */
3e7ee490
HJ
1093
1094 packetLen = desc.Length8 << 3;
1095 userLen = packetLen - (desc.DataOffset8 << 3);
1096
1097 DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ",
1098 Channel,
1099 Channel->OfferMsg.ChildRelId,
1100 desc.Type,
1101 desc.Flags,
1102 desc.TransactionId, packetLen, userLen);
1103
1104 *BufferActualLen = packetLen;
1105
1106 if (packetLen > BufferLen)
1107 {
54411c42 1108 spin_unlock_irqrestore(&Channel->inbound_lock, flags);
3e7ee490
HJ
1109
1110 DPRINT_ERR(VMBUS, "buffer too small - needed %d bytes but got space for only %d bytes", packetLen, BufferLen);
1111 DPRINT_EXIT(VMBUS);
1112 return -2;
1113 }
1114
1115 *RequestId = desc.TransactionId;
1116
454f18a9 1117 /* Copy over the entire packet to the user buffer */
3e7ee490
HJ
1118 ret = RingBufferRead(&Channel->Inbound, Buffer, packetLen, 0);
1119
54411c42 1120 spin_unlock_irqrestore(&Channel->inbound_lock, flags);
3e7ee490
HJ
1121
1122 DPRINT_EXIT(VMBUS);
1123
1124 return 0;
1125}
1126
1127
1128/*++
1129
1130Name:
1131 VmbusChannelOnChannelEvent()
1132
1133Description:
1134 Channel event callback
1135
1136--*/
bd1de709 1137static void
3e7ee490
HJ
1138VmbusChannelOnChannelEvent(
1139 VMBUS_CHANNEL *Channel
1140 )
1141{
1142 DumpVmbusChannel(Channel);
1143 ASSERT(Channel->OnChannelCallback);
1144#ifdef ENABLE_POLLING
c8a429a4 1145 del_timer(&Channel->poll_timer);
3e7ee490 1146 Channel->OnChannelCallback(Channel->ChannelCallbackContext);
c8a429a4
GKH
1147 channel->poll_timer.expires(jiffies + usecs_to_jiffies(100);
1148 add_timer(&channel->poll_timer);
3e7ee490
HJ
1149#else
1150 Channel->OnChannelCallback(Channel->ChannelCallbackContext);
1151#endif
1152}
1153
1154/*++
1155
1156Name:
1157 VmbusChannelOnTimer()
1158
1159Description:
1160 Timer event callback
1161
1162--*/
c8a429a4 1163static void VmbusChannelOnTimer(unsigned long data)
3e7ee490 1164{
c8a429a4 1165 VMBUS_CHANNEL *channel = (VMBUS_CHANNEL*)data;
3e7ee490
HJ
1166
1167 if (channel->OnChannelCallback)
1168 {
1169 channel->OnChannelCallback(channel->ChannelCallbackContext);
1170#ifdef ENABLE_POLLING
c8a429a4
GKH
1171 channel->poll_timer.expires(jiffies + usecs_to_jiffies(100);
1172 add_timer(&channel->poll_timer);
3e7ee490
HJ
1173#endif
1174 }
1175}
1176
1177
1178/*++
1179
1180Name:
1181 DumpVmbusChannel()
1182
1183Description:
1184 Dump vmbus channel info to the console
1185
1186--*/
1187static void
1188DumpVmbusChannel(
1189 VMBUS_CHANNEL *Channel
1190 )
1191{
1192 DPRINT_DBG(VMBUS, "Channel (%d)", Channel->OfferMsg.ChildRelId);
1193 DumpRingInfo(&Channel->Outbound, "Outbound ");
1194 DumpRingInfo(&Channel->Inbound, "Inbound ");
1195}
1196
1197
454f18a9 1198/* eof */
This page took 0.08225 seconds and 5 git commands to generate.