pvtcp_off.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 Offload common definitions.
  24. * This file is meant to only be included via pvtcp.h.
  25. */
  26. #ifndef _PVTCP_OFF_H_
  27. #define _PVTCP_OFF_H_
  28. #define PVTCP_OFF_SOCK_COMMON_FIELDS \
  29. volatile unsigned int opFlags; /* Saves op codes as bit mask. */ \
  30. volatile unsigned int flags /* General purpose flags. */
  31. /* General purpose socket flags */
  32. enum PvtcpOffPvskFlags {
  33. PVTCP_OFF_PVSKF_IPV6_LOOP = 0, /* Used for IPV6 loopback morphing/reset. */
  34. PVTCP_OFF_PVSKF_SHUT_RD, /* Set to initiate socket recv shutdown. */
  35. PVTCP_OFF_PVSKF_SHUT_WR, /* Set to initiate socket send shutdown. */
  36. PVTCP_OFF_PVSKF_TCP_NODELAY, /* Caches the TCP_NODELAY socket option. */
  37. PVTCP_OFF_PVSKF_TCP_CORK, /* Caches the TCP_CORK socket option. */
  38. PVTCP_OFF_PVSKF_DISCONNECT, /* Set do indicate connect()/AF_UNSPEC. */
  39. PVTCP_OFF_PVSKF_INVALID = 32
  40. };
  41. /*
  42. * Include OS-dependent PvtcpSock structure and functions.
  43. */
  44. #if defined(__linux__)
  45. #include "pvtcp_off_linux.h"
  46. #else
  47. #error "Unsupported OS."
  48. #endif
  49. /*
  50. * Offload packet payload data structure.
  51. */
  52. typedef struct PvtcpOffBuf {
  53. CommOSList link; /* Link in socket queue. */
  54. unsigned short len;
  55. unsigned short off;
  56. char data[1];
  57. } PvtcpOffBuf;
  58. /**
  59. * @brief Returns net buffer given private data structure pointer and based
  60. * on the internal offset pointer
  61. * @param arg pointer to PvtcpOffBuf wrapper structure
  62. * @return address of buffer or NULL
  63. */
  64. static inline void *
  65. PvtcpOffBufFromInternalOff(PvtcpOffBuf *arg)
  66. {
  67. return arg ?
  68. &arg->data[arg->off] :
  69. NULL;
  70. }
  71. /**
  72. * @brief Returns net buffer given private data structure pointer
  73. * @param arg pointer to PvtcpOffBuf wrapper structure
  74. * @return address of buffer or NULL
  75. */
  76. static inline void *
  77. PvtcpOffBufFromInternal(PvtcpOffBuf *arg)
  78. {
  79. return arg ?
  80. &arg->data[0] :
  81. NULL;
  82. }
  83. /**
  84. * @brief Returns internal data structure given net buffer pointer
  85. * @param arg pointer to PvtcpOffBuf wrapper structure
  86. * @return address of internal data structure or NULL
  87. */
  88. static inline PvtcpOffBuf *
  89. PvtcpOffInternalFromBuf(void *arg)
  90. {
  91. return arg ?
  92. (PvtcpOffBuf *)((char *)arg - offsetof(PvtcpOffBuf, data)) :
  93. NULL;
  94. }
  95. /**
  96. * @brief Tests operation flag for AIO processing.
  97. * @param pvsk socket to test operation on.
  98. * @param op operation to test if set.
  99. * @return non-zero if operation set, zero otherwise.
  100. * @sideeffect socket processing by AIO threads affected according to operation.
  101. */
  102. static inline int
  103. PvskTestOpFlag(struct PvtcpSock *pvsk,
  104. int op)
  105. {
  106. return pvsk->opFlags & (1 << op);
  107. }
  108. /**
  109. * @brief Sets operation flag for AIO processing; acquires the state lock.
  110. * @param[in,out] pvsk socket to set operation on.
  111. * @param op operation to set.
  112. * @sideeffect socket processing by AIO threads affected according to operation.
  113. */
  114. static inline void
  115. PvskSetOpFlag(struct PvtcpSock *pvsk,
  116. int op)
  117. {
  118. unsigned int ops;
  119. SOCK_STATE_LOCK(pvsk);
  120. ops = pvsk->opFlags | (1 << op);
  121. pvsk->opFlags = ops;
  122. SOCK_STATE_UNLOCK(pvsk);
  123. }
  124. /**
  125. * @brief Resets operation flag for AIO processing; acquires the state lock.
  126. * @param[in,out] pvsk socket to reset operation on.
  127. * @param op operation to reset.
  128. * @sideeffect socket processing by AIO threads affected according to operation.
  129. */
  130. static inline void
  131. PvskResetOpFlag(struct PvtcpSock *pvsk,
  132. int op)
  133. {
  134. unsigned int ops;
  135. SOCK_STATE_LOCK(pvsk);
  136. ops = pvsk->opFlags & ~(1 << op);
  137. pvsk->opFlags = ops;
  138. SOCK_STATE_UNLOCK(pvsk);
  139. }
  140. /**
  141. * @brief Tests general purpose socket flags.
  142. * @param pvsk socket.
  143. * @param flag flag to test.
  144. * @return non-zero if flag set, zero otherwise.
  145. */
  146. static inline int
  147. PvskTestFlag(struct PvtcpSock *pvsk,
  148. int flag)
  149. {
  150. return (flag < PVTCP_OFF_PVSKF_INVALID) && (pvsk->flags & (1 << flag));
  151. }
  152. /**
  153. * @brief Sets general purpose socket flags; acquires the state lock.
  154. * @param[in,out] pvsk socket.
  155. * @param flag flag to set or clear.
  156. * @param onOff whether to set or clear the flag.
  157. */
  158. static inline void
  159. PvskSetFlag(struct PvtcpSock *pvsk,
  160. int flag,
  161. int onOff)
  162. {
  163. unsigned int flags;
  164. SOCK_STATE_LOCK(pvsk);
  165. if (flag < PVTCP_OFF_PVSKF_INVALID) {
  166. if (onOff) {
  167. flags = pvsk->flags | (1 << flag);
  168. } else {
  169. flags = pvsk->flags & ~(1 << flag);
  170. }
  171. pvsk->flags = flags;
  172. }
  173. SOCK_STATE_UNLOCK(pvsk);
  174. }
  175. int PvtcpOffSockInit(PvtcpSock *pvsk, CommChannel channel);
  176. #endif /* _PVTCP_OFF_H_ */