comm.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Linux 2.6.32 and later Kernel module for VMware MVP PVTCP Server
  3. *
  4. * Copyright (C) 2010-2013 VMware, Inc. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; see the file COPYING. If not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #line 5
  20. /**
  21. * @file
  22. *
  23. * @brief Communication functions based on queue pair transport APIs.
  24. *
  25. * Comm is a shared memory-based mechanism that facilitates the implementation
  26. * of kernel components that require host-to-guest, or guest-to-guest
  27. * communication.
  28. * This facility assumes the availability of a minimal shared memory queue pair
  29. * implementation, such as MVP queue pairs or VMCI queue pairs. The latter must
  30. * provide primitives for queue pair creation and destruction, and reading and
  31. * writing from/to queue pairs.
  32. * Comm assumes that the queue pair (transport) layer is not concerned with
  33. * multi-threading, locking or flow control, and does not require such features.
  34. */
  35. #ifndef _COMM_H_
  36. #define _COMM_H_
  37. #define INCLUDE_ALLOW_MODULE
  38. #define INCLUDE_ALLOW_PV
  39. #define INCLUDE_ALLOW_GPL
  40. #include "include_check.h"
  41. #include "comm_os.h"
  42. #include "comm_transp.h"
  43. /* Default/maximum Comm timeouts (in milliseconds). */
  44. #define COMM_MAX_TO 60000ULL
  45. #define COMM_MAX_TO_UNINT (COMM_MAX_TO + 1)
  46. #define COMM_OPF_SET_ERR(flags) ((flags) |= 128)
  47. #define COMM_OPF_CLEAR_ERR(flags) ((flags) &= 127)
  48. #define COMM_OPF_TEST_ERR(flags) ((flags) & 128)
  49. #define COMM_OPF_SET_VAL(flags, val) ((flags) |= ((val) & 127))
  50. #define COMM_OPF_GET_VAL(flags) ((flags) & 127)
  51. /**
  52. * Packet (header) structure.
  53. * NB: Do not change this structure, especially the first three fields; there
  54. * will be consequences. It may be extended, but it's not recommended: all
  55. * operations carry this header, so it's better kept in its minimal form.
  56. */
  57. typedef struct CommPacket {
  58. unsigned int len; /* Total length */
  59. unsigned char flags; /* Operation flags */
  60. unsigned char opCode; /* Operation to call */
  61. unsigned short data16; /* Auxiliary data */
  62. unsigned long long data64;
  63. unsigned long long data64ex;
  64. union {
  65. struct {
  66. unsigned int data32;
  67. unsigned int data32ex;
  68. };
  69. unsigned long long data64ex2;
  70. };
  71. } CommPacket;
  72. /* Opaque structure representing a communication channel. */
  73. struct CommChannelPriv;
  74. typedef struct CommChannelPriv *CommChannel;
  75. /* Input operations associated with a comm channel. */
  76. typedef void (*CommOperationFunc)(CommChannel channel,
  77. void *state,
  78. CommPacket *packet,
  79. struct kvec *vec,
  80. unsigned int vecLen);
  81. /* Helper macros */
  82. #define COMM_DEFINE_OP(funcName) \
  83. void \
  84. funcName(CommChannel channel, \
  85. void *state, \
  86. CommPacket *packet, \
  87. struct kvec *vec, \
  88. unsigned int vecLen)
  89. /* Comm-based implementations. */
  90. typedef struct CommImpl {
  91. struct module *owner;
  92. int (*checkArgs)(CommTranspInitArgs *transpArgs);
  93. void *(*stateCtor)(CommChannel channel);
  94. void (*stateDtor)(void *state);
  95. void *(*dataAlloc)(unsigned int size,
  96. CommChannel channel,
  97. CommPacket *header,
  98. int (*copyFromChannel)(CommChannel channel,
  99. void *dest,
  100. unsigned int size,
  101. int kern));
  102. void (*dataFree)(void *data);
  103. const CommOperationFunc *operations;
  104. void (*closeNtf)(void *closeNtfData,
  105. const CommTranspInitArgs *transpArgs,
  106. int inBH);
  107. void *closeNtfData;
  108. void (*activateNtf)(void *activateNtfData,
  109. CommChannel channel);
  110. void *activateNtfData;
  111. unsigned long long openAtMillis;
  112. unsigned long long openTimeoutAtMillis;
  113. CommTranspID ntfCenterID;
  114. } CommImpl;
  115. int Comm_Init(unsigned int maxChannels);
  116. int Comm_Finish(unsigned long long *timeoutMillis);
  117. int Comm_RegisterImpl(const CommImpl *impl);
  118. void Comm_UnregisterImpl(const CommImpl *impl);
  119. int Comm_IsActive(CommChannel channel);
  120. CommTranspInitArgs Comm_GetTranspInitArgs(CommChannel channel);
  121. void *Comm_GetState(CommChannel channel);
  122. int Comm_Dispatch(CommChannel channel);
  123. unsigned int Comm_DispatchAll(void);
  124. void Comm_Put(CommChannel channel);
  125. void Comm_DispatchUnlock(CommChannel channel);
  126. int Comm_Lock(CommChannel channel);
  127. void Comm_Unlock(CommChannel channel);
  128. int Comm_Zombify(CommChannel channel, int inBH);
  129. int
  130. Comm_Alloc(const CommTranspInitArgs *transpArgs,
  131. const CommImpl *impl,
  132. int inBH,
  133. CommChannel *newChannel);
  134. int
  135. Comm_Write(CommChannel channel,
  136. const CommPacket *packet,
  137. unsigned long long *timeoutMillis);
  138. int
  139. Comm_WriteVec(CommChannel channel,
  140. const CommPacket *packet,
  141. struct kvec **vec,
  142. unsigned int *vecLen,
  143. unsigned long long *timeoutMillis,
  144. unsigned int *iovOffset,
  145. int kern);
  146. unsigned int Comm_RequestInlineEvents(CommChannel channel);
  147. unsigned int Comm_ReleaseInlineEvents(CommChannel channel);
  148. #endif /* _COMM_H_ */