~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201210021442

« back to all changes in this revision

Viewing changes to modules/linux/vmci/shared/vmci_page_channel.h

  • Committer: Package Import Robot
  • Author(s): Nate Muench
  • Date: 2012-06-20 15:59:51 UTC
  • mfrom: (1.4.8)
  • Revision ID: package-import@ubuntu.com-20120620155951-6rupmpb0f70b52zr
Tags: 2012.05.21-724730-0ubuntu1
* Merging upstream version 2012.05.21-724730.
  - Fixes building against the current Quantal kernel. (LP: #1000344)
  - Fixes Quantal installation issues. (LP: #1019031)

* Sync with Debian
  - Updating to debhelper version 9.
  - Updating to standards version 3.9.3.
  - Updating copyright file machine-readable format version 1.0.
  - Building without multiarch paths for now

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*********************************************************
2
 
 * Copyright (C) 2011 VMware, Inc. All rights reserved.
 
2
 * Copyright (C) 2011-2012 VMware, Inc. All rights reserved.
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify it
5
5
 * under the terms of the GNU General Public License as published by the
33
33
#include "vmci_defs.h"
34
34
#include "vmci_call_defs.h"
35
35
 
36
 
/* Max size of a single tx buffer. */
 
36
/** \cond PRIVATE */
37
37
#define VPAGECHANNEL_MAX_TX_BUF_SIZE (1 << 14)
38
38
#define VPAGECHANNEL_MAX_PAGES_PER_TX_BUFFER \
39
39
   (VPAGECHANNEL_MAX_TX_BUF_SIZE / PAGE_SIZE + 1)
 
40
/** \endcond */
 
41
 
 
42
/**
 
43
 * \brief Get a pointer to the elements in a packet.
 
44
 *
 
45
 * Returns a pointer to the elements at the end of a page channel packet.
 
46
 *
 
47
 * \see VPageChannelElem
 
48
 * \see VPageChannelPacket
 
49
 */
40
50
 
41
51
#define VPAGECHANNEL_PACKET_ELEMS(packet)             \
42
52
   (VPageChannelElem *)((char *)(packet) +            \
43
53
                         sizeof(VPageChannelPacket) + \
44
54
                         packet->msgLen)
 
55
 
 
56
/**
 
57
 * \brief Get a pointer to the message in a packet.
 
58
 *
 
59
 * Returns a pointer to the message embedded in a page channel packet.
 
60
 *
 
61
 * \see VPageChannelPacket
 
62
 */
 
63
 
45
64
#define VPAGECHANNEL_PACKET_MESSAGE(packet) \
46
65
   (char *)((char *)(packet) + sizeof(VPageChannelPacket))
47
66
 
 
67
/**
 
68
 * \brief Notify client directly, and do not read packets.
 
69
 *
 
70
 * This flag indicates that the channel should invoke the client's receive
 
71
 * callback directly when any packets are available.  If not specified, then
 
72
 * when a notification is received, packets are read from the channel and the
 
73
 * callback invoked for each one separately.
 
74
 *
 
75
 * \note Not applicable to VMKernel.
 
76
 *
 
77
 * \see VPageChannel_CreateInVM()
 
78
 */
 
79
 
 
80
#define VPAGECHANNEL_FLAGS_NOTIFY_ONLY 0x1
 
81
 
 
82
/**
 
83
 * \brief Invoke client's receive callback in delayed context.
 
84
 *
 
85
 * This flag indicates that all callbacks run in a delayed context, and the
 
86
 * caller and callback are allowed to block.  If not specified, then callbacks
 
87
 * run in interrupt context and the channel will not block, and the caller
 
88
 * is not allowed to block.
 
89
 *
 
90
 * \note Not applicable to VMKernel.
 
91
 *
 
92
 * \see VPageChannel_CreateInVM()
 
93
 */
 
94
 
 
95
#define VPAGECHANNEL_FLAGS_RECV_DELAYED 0x2
 
96
 
 
97
/**
 
98
 * \brief Send from an atomic context.
 
99
 *
 
100
 * This flag indicates that the client wishes to call Send() from an atomic
 
101
 * context and that the channel should not block.  If the channel is not
 
102
 * allowed to block, then the channel's pages are permanently mapped and
 
103
 * pinned.  Note that this will limit the total size of the channel to
 
104
 * VMCI_MAX_PINNED_QP_MEMORY.
 
105
 *
 
106
 * \note Not applicable to VMKernel.
 
107
 *
 
108
 * \see VPageChannel_CreateInVM()
 
109
 */
 
110
 
 
111
#define VPAGECHANNEL_FLAGS_SEND_WHILE_ATOMIC 0x4
 
112
 
 
113
/**
 
114
 * \brief An element describing a data range.
 
115
 *
 
116
 * Describes a data range, starting at a base address and for a given
 
117
 * length, i.e., an element of a scatter-gather list.  Indicates physical
 
118
 * address for the guest and machine address for hypervisor.  Can be passed
 
119
 * via packets or buffers.
 
120
 *
 
121
 * \note Structure is packed.
 
122
 *
 
123
 * \see VPageChannelPacket
 
124
 * \see VPageChanelBuffer
 
125
 */
48
126
 
49
127
typedef
50
128
#include "vmware_pack_begin.h"
51
129
struct VPageChannelElem {
52
130
   union {
53
 
      uint64 pa;     // For guest
54
 
      uint64 ma;     // For hypervisor
 
131
      /** \brief Physical address for guest. */
 
132
      uint64 pa;
 
133
 
 
134
      /** \brief Machine address for hypervisor. */
 
135
      uint64 ma;
55
136
   };
 
137
 
 
138
   /** \brief Length of range. */
56
139
   uint32 le;
57
140
}
58
141
#include "vmware_pack_end.h"
59
142
VPageChannelElem;
60
143
 
 
144
/**
 
145
 * \brief Page channel page types.
 
146
 *
 
147
 * The various types of page channel packets.
 
148
 *
 
149
 * \see VPageChannelPacket
 
150
 */
61
151
typedef enum {
 
152
   /** \brief Data packet. */
62
153
   VPCPacket_Data = 1,
63
 
   VPCPacket_Completion_Notify, // Hypervisor to guest only.
64
 
   VPCPacket_GuestConnect,      // Connect to hypervisor.  Internal use only.
65
 
   VPCPacket_HyperConnect,      // Complete connection handshake.  Internal.
66
 
   VPCPacket_RequestBuffer,     // Request buffers.  Internal use only.
67
 
   VPCPacket_SetRecvBuffer,     // Set buffers.  Internal use only.
 
154
 
 
155
   /** \brief Completion notification, from hypervisor to guest. */
 
156
   VPCPacket_Completion_Notify,
 
157
 
 
158
   /** \cond PRIVATE */
 
159
   /** \brief Connect to hypervisor, internal. */
 
160
   VPCPacket_GuestConnect,
 
161
 
 
162
   /** \brief Complete connection handshake, internal. */
 
163
   VPCPacket_HyperConnect,
 
164
 
 
165
   /** \brief Request buffers, internal. */
 
166
   VPCPacket_RequestBuffer,
 
167
 
 
168
   /** \brief Set buffers, internal. */
 
169
   VPCPacket_SetRecvBuffer,
 
170
 
 
171
   /** \brief Hypervisor channel disconnect, internal. */
 
172
   VPCPacket_HyperDisconnect,
 
173
 
 
174
   /** \brief Guest channel ACK hypervisor disconnect, internal. */
 
175
   VPCPacket_GuestDisconnect,
 
176
   /** \endcond */
68
177
} VPageChannelPacketType;
69
178
 
 
179
/**
 
180
 * \brief Page channel packet structure.
 
181
 *
 
182
 * A packet structure for passing control/data between guest and hypervisor.
 
183
 * Can optionally contain a message and also a number of elements.
 
184
 *
 
185
 * \note Structure is packed.
 
186
 *
 
187
 * \see VPageChannelPacketType
 
188
 */
70
189
typedef
71
190
#include "vmware_pack_begin.h"
72
191
struct VPageChannelPacket {
 
192
   /** \brief Type of packet. */
73
193
   VPageChannelPacketType type;
 
194
 
 
195
   /** \brief Length of optional message. */
74
196
   uint32 msgLen;
 
197
 
 
198
   /** \brief Number of optional elements in packet. */
75
199
   uint32 numElems;
76
 
   /*
77
 
    * Followed by msgLen of message and numElems of VPageChannelElem.
78
 
    */
 
200
 
 
201
   /** \brief Followed by msgLen of message and numElems VPageChannelElem. */
79
202
}
80
203
#include "vmware_pack_end.h"
81
204
VPageChannelPacket;
82
205
 
 
206
/**
 
207
 * \brief Page channel buffer structure.
 
208
 *
 
209
 * A buffer of elements (a scatter-gather list).
 
210
 *
 
211
 * \note Structure is packed.
 
212
 *
 
213
 * \see VPageChannelElem
 
214
 */
 
215
 
83
216
typedef
84
217
#include "vmware_pack_begin.h"
85
218
struct VPageChannelBuffer {
 
219
   /** \brief Number of elements. */
86
220
   uint32 numElems;
 
221
 
 
222
   /** \brief First element. */
87
223
   VPageChannelElem elems[1];
88
 
   /*
89
 
    * Followed by numElems - 1 of VPageChannelElem.
90
 
    */
 
224
 
 
225
   /** \brief Followed by numElems - 1 of VPageChannelElem. */
91
226
}
92
227
#include "vmware_pack_end.h"
93
228
VPageChannelBuffer;
94
229
 
 
230
/** \cond PRIVATE */
95
231
typedef
96
232
#include "vmware_pack_begin.h"
97
233
struct VPageChannelGuestConnectMessage {
 
234
 
 
235
   /** \brief Guest channel's datagram handle for control channel. */
98
236
   VMCIHandle dgHandle;
 
237
 
 
238
   /** \brief Guest channel's queuepair handle. */
99
239
   VMCIHandle qpHandle;
 
240
 
 
241
   /** \brief Size of producer queue in queuepair in bytes. */
100
242
   uint64 produceQSize;
 
243
 
 
244
   /** \brief Size of consumer queue in queuepair in bytes. */
101
245
   uint64 consumeQSize;
 
246
 
 
247
   /** \brief Guest channel's doorbell handle. */
102
248
   VMCIHandle doorbellHandle;
103
249
}
104
250
#include "vmware_pack_end.h"
107
253
typedef
108
254
#include "vmware_pack_begin.h"
109
255
struct VPageChannelHyperConnectMessage {
 
256
   /** \brief Hypervisor's doorbell handle. */
110
257
   VMCIHandle doorbellHandle;
111
258
}
112
259
#include "vmware_pack_end.h"
113
260
VPageChannelHyperConnectMessage;
 
261
/** \endcond PRIVATE */
 
262
 
 
263
/** \cond PRIVATE */
 
264
typedef enum VPageChannelState {
 
265
   VPCState_Free = 0,
 
266
   VPCState_Unconnected,
 
267
   VPCState_Connecting,
 
268
   VPCState_Connected,
 
269
   VPCState_Disconnecting,
 
270
   VPCState_Disconnected,
 
271
} VPageChannelState;
 
272
/** \endcond PRIVATE */
 
273
 
 
274
/**
 
275
 * \brief Opaque page channel type.
 
276
 */
114
277
 
115
278
struct VPageChannel;
116
279
typedef struct VPageChannel VPageChannel;
117
280
 
 
281
/**
 
282
 * \brief Client receive callback type.
 
283
 *
 
284
 * Type of receive callback, invoked when there are data packets in the
 
285
 * channel.  The client provides a callback with this type to
 
286
 * VPageChannel_CreateInVM().  If VPAGECHANNEL_FLAGS_NOTIFY_ONLY is specified
 
287
 * in the channel creation flags, then \c packet is \c NULL; otherwise,
 
288
 * \c packet points to a channel packet.
 
289
 *
 
290
 * \see VPageChannel_CreateInVM()
 
291
 * \see VPageChannelPacket
 
292
 */
 
293
 
118
294
typedef void (*VPageChannelRecvCB)(void *clientData,
119
295
                                   VPageChannelPacket *packet);
120
296
 
121
297
 
122
298
#if !defined(VMKERNEL)
123
299
 
 
300
/**
 
301
 * \brief Client element allocation callback type.
 
302
 *
 
303
 * Type of element allocation callback, invoked when the channel needs
 
304
 * elements.  The client provides a callback of this type to
 
305
 * VPageChannel_CreateInVM().
 
306
 *
 
307
 * \see VPageChannel_CreateInVM()
 
308
 * \see VPageChannelElem
 
309
 * \see VPageChannelFreeElemFn
 
310
 */
 
311
 
124
312
typedef int (*VPageChannelAllocElemFn)(void *clientData,
125
313
                                       VPageChannelElem *elems,
126
314
                                       int numElems);
127
315
 
 
316
/**
 
317
 * \brief Client element release callback type.
 
318
 *
 
319
 * Type of element release callback, invoked when the channel releases
 
320
 * elements.  The client provides a callback of this type to
 
321
 * VPageChannel_CreateInVM().
 
322
 *
 
323
 * \see VPageChannel_CreateInVM()
 
324
 * \see VPageChannelElem
 
325
 * \see VPageChannelAllocElemFn
 
326
 */
 
327
 
128
328
typedef void (*VPageChannelFreeElemFn)(void *clientData,
129
329
                                       VPageChannelElem *elems,
130
330
                                       int numElems);
131
331
 
 
332
/*
 
333
 ************************************************************************
 
334
 * VPageChannel_CreateInVM                                         */ /**
 
335
 *
 
336
 * \brief Create guest page channel.
 
337
 *
 
338
 * Creates a page channel in the guest.  The channel should be released
 
339
 * with VPageChannel_Destroy().
 
340
 *
 
341
 * \note Only applicable in the guest.
 
342
 *
 
343
 * \see VPageChannel_CreateInVMK()
 
344
 * \see VPageChannel_Destroy()
 
345
 *
 
346
 * \param[out] channel           Pointer to a newly constructed page
 
347
 *                               channel if successful.
 
348
 * \param[in]  resourceId        Resource ID on which the channel should
 
349
 *                               register its control channel.
 
350
 * \param[in]  peerResourceId    Resource ID of peer's control channel.
 
351
 * \param[in]  produceQSize      Size of producer queue in queuepair in
 
352
 *                               bytes.
 
353
 * \param[in]  consumeQSize      Size of consumer queue in queuepair in
 
354
 *                               bytes.
 
355
 * \param[in]  flags             Channel flags.
 
356
 * \param[in]  recvCB            Client's receive callback.
 
357
 * \param[in]  clientRecvData    Client data for client's receive
 
358
 *                               callback.
 
359
 * \param[in]  elemAlloc         Element allocation callback for
 
360
 *                               allocating page ranges (scatter-gather
 
361
 *                               elements).
 
362
 * \param[in]  allocClientData   Client data for element allocation
 
363
 *                               callback.
 
364
 * \param[in]  elemFree          Element release callback for elements.
 
365
 * \param[in]  freeClientData    Client data for element release
 
366
 *                               callback.
 
367
 * \param[in]  defRecvBufs       Default number of elements sent to
 
368
 *                               hypervisor channel.
 
369
 * \param[in]  maxRecvBufs       Maximum number of elements that can be
 
370
 *                               sent to the hypervisor channel.
 
371
 *
 
372
 * \retval     VMCI_SUCCESS      Creation succeeded, \c *channel contains
 
373
 *                               a pointer to a valid channel.
 
374
 * \retval     other             Failure.
 
375
 *
 
376
 ************************************************************************
 
377
 */
 
378
 
132
379
int VPageChannel_CreateInVM(VPageChannel **channel,
133
380
                            VMCIId resourceId,
134
381
                            VMCIId peerResourceId,
135
382
                            uint64 produceQSize,
136
383
                            uint64 consumeQSize,
 
384
                            uint32 flags,
137
385
                            VPageChannelRecvCB recvCB,
138
386
                            void *clientRecvData,
139
 
                            Bool notifyOnly,
140
387
                            VPageChannelAllocElemFn elemAlloc,
141
388
                            void *allocClientData,
142
389
                            VPageChannelFreeElemFn elemFree,
143
390
                            void *freeClientData,
144
 
                            int defaultRecvBuffers,
145
 
                            int maxRecvBuffers);
 
391
                            int defRecvBufs,
 
392
                            int maxRecvBufs);
146
393
 
147
394
#else // VMKERNEL
148
395
 
 
396
/**
 
397
 * \brief Type of VM memory access off callback.
 
398
 *
 
399
 * This callback is invoked when the memory of the VM containing the peer
 
400
 * endpoint becomes inaccessible, for example due to a crash.  When this
 
401
 * occurs, the client should unmap any guest pages and cleanup any state.
 
402
 * This callback runs in a blockable context.  The client is not allowed to
 
403
 * call VPageChannel_Destroy() from inside the callback, or it will deadlock,
 
404
 * since that function will wait for the callback to complete.
 
405
 *
 
406
 * \note Only applicable on VMKernel.
 
407
 *
 
408
 * \see VPageChannel_CreateInVMK()
 
409
 */
 
410
 
 
411
typedef void (*VPageChannelMemAccessOffCB)(void *clientData);
 
412
 
 
413
/*
 
414
 ************************************************************************
 
415
 * VPageChannel_CreateInVMK                                        */ /**
 
416
 *
 
417
 * \brief Create a page channel in VMKernel.
 
418
 *
 
419
 * Creates a page channel.  The channel should be released with
 
420
 * VPageChannel_Destroy().
 
421
 *
 
422
 * \note Only applicable on VMKernel.
 
423
 *
 
424
 * \see VPageChannel_CreateInVM()
 
425
 * \see VPageChannel_Destroy()
 
426
 *
 
427
 * \param[out] channel           Pointer to a newly constructed page
 
428
 *                               channel if successful.
 
429
 * \param[in]  resourceId        Resource ID on which to register
 
430
 *                               control channel.
 
431
 * \param[in]  recvCB            Client's receive callback.
 
432
 * \param[in]  clientRecvData    Client data for receive callback.
 
433
 * \param[in]  memAccessOffCB    Client's mem access off callback.
 
434
 * \param[in]  memAccessOffData  Client data for mem access off.
 
435
 *
 
436
 * \retval     VMCI_SUCCESS      Creation succeeded, \c *channel
 
437
 *                               contains a pointer to a valid channel.
 
438
 * \retval     other             Failure.
 
439
 *
 
440
 ***********************************************************************
 
441
 */
 
442
 
149
443
int VPageChannel_CreateInVMK(VPageChannel **channel,
150
444
                             VMCIId resourceId,
151
445
                             VPageChannelRecvCB recvCB,
152
 
                             void *clientRecvData);
 
446
                             void *clientRecvData,
 
447
                             VPageChannelMemAccessOffCB memAccessOffCB,
 
448
                             void *memAccessOffData);
 
449
 
 
450
/*
 
451
 ************************************************************************
 
452
 * VPageChannel_ReserveBuffers                                     */ /**
 
453
 *
 
454
 * \brief Reserve guest elements.
 
455
 *
 
456
 * Reserve sufficient guest elements to cover the given length.  The
 
457
 * buffers can then be posted to the guest.  This allocates both the
 
458
 * buffer and the elements within the buffer.
 
459
 *
 
460
 * \note Only applicable on VMKernel.
 
461
 *
 
462
 * \see VPageChannel_ReleaseBuffers()
 
463
 *
 
464
 * \param[in]  channel  Page channel.
 
465
 * \param[in]  dataLen  Length to reserve in bytes.
 
466
 * \param[out] buffer   Pointer to a buffer containing elements to cover
 
467
 *                      the given length if successful.
 
468
 *
 
469
 * \retval     VMCI_SUCCESS   Reservation succeeded, \c *buffer contains
 
470
 *                            a pointer to a valid buffer.
 
471
 * \retval     other          Failure.
 
472
 *
 
473
 ************************************************************************
 
474
 */
153
475
 
154
476
int VPageChannel_ReserveBuffers(VPageChannel *channel,
155
477
                                size_t dataLen,
156
478
                                VPageChannelBuffer **buffer);
 
479
 
 
480
/*
 
481
 ************************************************************************
 
482
 * VPageChannel_ReleaseBuffers                                     */ /**
 
483
 *
 
484
 * \brief Release guest elements.
 
485
 *
 
486
 * \note Only applicable on VMKernel.
 
487
 *
 
488
 * \see VPageChannel_ReserveBuffers()
 
489
 *
 
490
 * Release guest elements previous reserved with
 
491
 * VPageChannel_ReserveBuffers().  If the buffers were sent to the guest,
 
492
 * then only the buffer itself should be released, i.e.,
 
493
 * \c returnToFreePool should be \c FALSE; the guest will release the
 
494
 * buffers on completion.  Otherwise, if for some reason they are not
 
495
 * sent after reserving them, then \c returnToFreePool should be set to
 
496
 * \c TRUE.
 
497
 *
 
498
 * \param[in]  channel           Page channel.
 
499
 * \param[in]  buffer            Buffer to be released.
 
500
 * \param[in]  returnToFreePool  If \c TRUE, then release the elements
 
501
 *                               of the buffer along with the buffer
 
502
 *                               itself.  If \c FALSE, then release only
 
503
 *                               the buffer pointer itself.
 
504
 *
 
505
 ************************************************************************
 
506
 */
 
507
 
157
508
void VPageChannel_ReleaseBuffers(VPageChannel *channel,
158
509
                                 VPageChannelBuffer *buffer,
159
510
                                 Bool returnToFreePool);
160
511
 
161
512
/*
162
 
 * This function is called when the client is finished using the
163
 
 * scatter-gather list of a packet. This will generate a notification to the
164
 
 * guest to pass the ownership of buffers back to the guest. This can also be
165
 
 * used to read back the data from hypervisor and send it the to guest.
 
513
 ************************************************************************
 
514
 * VPageChannel_CompletionNotify                                   */ /**
 
515
 *
 
516
 * \brief Notify channel of completion.
 
517
 *
 
518
 * This function is called when the client is finished using the elements
 
519
 * (scatter-gather list) of a packet.  This will generated a notification
 
520
 * to the guest to pass ownership of the buffers back to the guest.  This
 
521
 * can also be used to read back the data from the hypervisor and send
 
522
 * it to the guest.
 
523
 *
 
524
 * \note Only applicable on VMKernel.
 
525
 *
 
526
 * \see VPageChannel_ReserveBuffers
 
527
 *
 
528
 * \param[in]  channel  Channel on which I/O is complete.
 
529
 * \param[in]  message  Optional message to send to guest.
 
530
 * \param[in]  len      Length of optional message.
 
531
 * \param[in]  buffer   Buffer used for I/O.
 
532
 *
 
533
 ************************************************************************
166
534
 */
167
535
 
168
536
int VPageChannel_CompletionNotify(VPageChannel *channel,
170
538
                                  int len,
171
539
                                  VPageChannelBuffer *buffer);
172
540
 
 
541
/*
 
542
 ************************************************************************
 
543
 * VPageChannel_MapToMa                                           */ /**
 
544
 *
 
545
 * \brief Map guest PA in an element to a list of MAs.
 
546
 *
 
547
 * Map a guest physical address to a list of hypervisor machine
 
548
 * addresses.
 
549
 *
 
550
 * \note Only applicable on VMKernel.
 
551
 *
 
552
 * \param[in]     channel    Channel on which to map.
 
553
 * \param[in]     paElem     Guest's physical address.
 
554
 * \param[out]    maElems    Hypervisor machine addresses.
 
555
 * \param[in]     numElems   Max number of hypervisor elements.
 
556
 *
 
557
 * \retval  elems    Number of mapped elements.
 
558
 *
 
559
 ************************************************************************
 
560
 */
 
561
 
173
562
int VPageChannel_MapToMa(VPageChannel *channel,
174
563
                         VPageChannelElem paElem,
175
564
                         VPageChannelElem *maElems,
176
565
                         uint32 numElems);
 
566
 
 
567
/*
 
568
 ************************************************************************
 
569
 * VPageChannel_UnmapMa                                            */ /**
 
570
 *
 
571
 * \brief Unmap MA for a buffer.
 
572
 *
 
573
 * Unmap hypervisor machine addresses referring to a guest physical
 
574
 * addresses.
 
575
 *
 
576
 * \note Only applicable on VMKernel.
 
577
 *
 
578
 * \see VPageChannel_MapToMa
 
579
 *
 
580
 * \param[in]  channel     Channel for which to unmap.
 
581
 * \param[in]  buffer      Buffer containing elements to unmap.
 
582
 * \param[in]  numElems    Number of elements to unmap.
 
583
 *
 
584
 * \retval  0     Unmap successful.
 
585
 * \retval  -1    World not found for channel.
 
586
 *
 
587
 ************************************************************************
 
588
 */
 
589
 
177
590
int VPageChannel_UnmapMa(VPageChannel *channel,
178
591
                         VPageChannelBuffer *buffer,
179
592
                         int numElems);
181
594
#endif // VMKERNEL
182
595
 
183
596
/*
184
 
 * Common functions.
 
597
 ************************************************************************
 
598
 * VPageChannel_Destroy                                            */ /**
 
599
 *
 
600
 * \brief Destroy the given channel.
 
601
 *
 
602
 * Destroy the given channel.  This will disconnect from the peer
 
603
 * channel (if connected) and release all resources.
 
604
 *
 
605
 * \see VPageChannel_CreateInVMK
 
606
 * \see VPageChannel_CreateInVM
 
607
 *
 
608
 * \param[in]  channel  The channel to be destroyed.
 
609
 *
 
610
 ************************************************************************
185
611
 */
186
612
 
187
613
void VPageChannel_Destroy(VPageChannel *channel);
 
614
 
 
615
/*
 
616
 ************************************************************************
 
617
 * VPageChannel_Send                                               */ /**
 
618
 *
 
619
 * \brief Send a packet to the channel's peer.
 
620
 *
 
621
 * Send a packet to the channel's peer.  A message and a number of
 
622
 * elements may optionally be sent.  If the send is successful, the
 
623
 * elements are owned by the peer and only the buffer itself should
 
624
 * be released, but not the elements within.  If the send fails, the
 
625
 * client should release the buffer and the elements.
 
626
 *
 
627
 * \see VPageChannel_SendPacket
 
628
 *
 
629
 * \param[in]  channel     Channel on which to send.
 
630
 * \param[in]  type        Type of packet to send.
 
631
 * \param[in]  message     Optional message to send.
 
632
 * \param[in]  len         Length of optional message.
 
633
 * \param[in]  buffer      Buffer (of elements) to send.
 
634
 *
 
635
 * \retval  VMCI_SUCCESS   Packet successfully sent, buffer elements
 
636
 *                         owned by peer.
 
637
 * \retval  other          Failure to send, client should release
 
638
 *                         elements.
 
639
 *
 
640
 ************************************************************************
 
641
 */
 
642
 
188
643
int VPageChannel_Send(VPageChannel *channel,
189
644
                      VPageChannelPacketType type,
190
645
                      char *message,
191
646
                      int len,
192
647
                      VPageChannelBuffer *buffer);
 
648
 
 
649
/*
 
650
 ************************************************************************
 
651
 * VPageChannel_SendPacket                                         */ /**
 
652
 *
 
653
 * \brief Send the given packet to the channel's peer.
 
654
 *
 
655
 * Send a client-constructed packet to the channel's peer.  If the
 
656
 * send is successful, any elements in the packet are owned by the
 
657
 * peer.  Otherwise, the client retains ownership.
 
658
 *
 
659
 * \see VPageChannel_Send
 
660
 *
 
661
 * \param[in]  channel  Channel on which to send.
 
662
 * \param[in]  packet   Packet to be sent.
 
663
 *
 
664
 * \retval  VMCI_SUCCESS   Packet successfully sent, buffer elements
 
665
 *                         owned by peer.
 
666
 * \retval  other          Failure to send, client should release
 
667
 *                         elements.
 
668
 *
 
669
 ************************************************************************
 
670
 */
 
671
 
193
672
int VPageChannel_SendPacket(VPageChannel *channel,
194
673
                            VPageChannelPacket *packet);
 
674
 
 
675
/*
 
676
 ************************************************************************
 
677
 * VPageChannel_PollRecvQ                                          */ /**
 
678
 *
 
679
 * \brief Poll the channel's receive queue for packets.
 
680
 *
 
681
 * Poll the channel's receive queue for packets from the peer.  If any
 
682
 * packets are available, the channel's receive callback will be invoked.
 
683
 *
 
684
 * \param[in]  channel  Channel to poll.
 
685
 *
 
686
 ************************************************************************
 
687
 */
 
688
 
195
689
void VPageChannel_PollRecvQ(VPageChannel *channel);
196
690
 
197
 
 
198
691
/*
199
 
 *-----------------------------------------------------------------------------
200
 
 *
201
 
 * VPageChannelPacket_BufferLen --
202
 
 *
203
 
 *      Calculate the length of the given packet.
204
 
 *
205
 
 * Results:
206
 
 *      The length of the given packet in bytes.
207
 
 *
208
 
 * Side effects:
209
 
 *      None.
210
 
 *
211
 
 *-----------------------------------------------------------------------------
 
692
 ************************************************************************
 
693
 * VPageChannel_BufferLen                                          */ /**
 
694
 *
 
695
 * \brief Determine the length of a packet.
 
696
 *
 
697
 * Determine the length of the given packet in bytes.
 
698
 *
 
699
 * \param[in]  packet   Packet for which length is to be determined.
 
700
 *
 
701
 * \retval     bytes    Size of the packet in bytes.
 
702
 *
 
703
 ************************************************************************
212
704
 */
213
705
 
214
706
static INLINE size_t
228
720
   return len;
229
721
}
230
722
 
231
 
 
 
723
/** \cond PRIVATE */
232
724
#if defined(linux) && !defined(VMKERNEL)
233
725
#include "compat_pci.h"
234
726
#define vmci_pci_map_page(_pg, _off, _sz, _dir) \
236
728
#define vmci_pci_unmap_page(_dma, _sz, _dir) \
237
729
   pci_unmap_page(NULL, (_dma), (_sz), (_dir))
238
730
#endif // linux && !VMKERNEL
 
731
/** \endcond PRIVATE */
239
732
 
240
733
#endif // _VMCI_PACKET_H_