rds.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. * Copyright (c) 2008 Oracle. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. */
  33. #ifndef _LINUX_RDS_H
  34. #define _LINUX_RDS_H
  35. #include <linux/types.h>
  36. #define RDS_IB_ABI_VERSION 0x301
  37. #define SOL_RDS 276
  38. /*
  39. * setsockopt/getsockopt for SOL_RDS
  40. */
  41. #define RDS_CANCEL_SENT_TO 1
  42. #define RDS_GET_MR 2
  43. #define RDS_FREE_MR 3
  44. /* deprecated: RDS_BARRIER 4 */
  45. #define RDS_RECVERR 5
  46. #define RDS_CONG_MONITOR 6
  47. #define RDS_GET_MR_FOR_DEST 7
  48. #define SO_RDS_TRANSPORT 8
  49. /* Socket option to tap receive path latency
  50. * SO_RDS: SO_RDS_MSG_RXPATH_LATENCY
  51. * Format used struct rds_rx_trace_so
  52. */
  53. #define SO_RDS_MSG_RXPATH_LATENCY 10
  54. /* supported values for SO_RDS_TRANSPORT */
  55. #define RDS_TRANS_IB 0
  56. #define RDS_TRANS_IWARP 1
  57. #define RDS_TRANS_TCP 2
  58. #define RDS_TRANS_COUNT 3
  59. #define RDS_TRANS_NONE (~0)
  60. /*
  61. * Control message types for SOL_RDS.
  62. *
  63. * CMSG_RDMA_ARGS (sendmsg)
  64. * Request a RDMA transfer to/from the specified
  65. * memory ranges.
  66. * The cmsg_data is a struct rds_rdma_args.
  67. * RDS_CMSG_RDMA_DEST (recvmsg, sendmsg)
  68. * Kernel informs application about intended
  69. * source/destination of a RDMA transfer
  70. * RDS_CMSG_RDMA_MAP (sendmsg)
  71. * Application asks kernel to map the given
  72. * memory range into a IB MR, and send the
  73. * R_Key along in an RDS extension header.
  74. * The cmsg_data is a struct rds_get_mr_args,
  75. * the same as for the GET_MR setsockopt.
  76. * RDS_CMSG_RDMA_STATUS (recvmsg)
  77. * Returns the status of a completed RDMA operation.
  78. * RDS_CMSG_RXPATH_LATENCY(recvmsg)
  79. * Returns rds message latencies in various stages of receive
  80. * path in nS. Its set per socket using SO_RDS_MSG_RXPATH_LATENCY
  81. * socket option. Legitimate points are defined in
  82. * enum rds_message_rxpath_latency. More points can be added in
  83. * future. CSMG format is struct rds_cmsg_rx_trace.
  84. */
  85. #define RDS_CMSG_RDMA_ARGS 1
  86. #define RDS_CMSG_RDMA_DEST 2
  87. #define RDS_CMSG_RDMA_MAP 3
  88. #define RDS_CMSG_RDMA_STATUS 4
  89. #define RDS_CMSG_CONG_UPDATE 5
  90. #define RDS_CMSG_ATOMIC_FADD 6
  91. #define RDS_CMSG_ATOMIC_CSWP 7
  92. #define RDS_CMSG_MASKED_ATOMIC_FADD 8
  93. #define RDS_CMSG_MASKED_ATOMIC_CSWP 9
  94. #define RDS_CMSG_RXPATH_LATENCY 11
  95. #define RDS_INFO_FIRST 10000
  96. #define RDS_INFO_COUNTERS 10000
  97. #define RDS_INFO_CONNECTIONS 10001
  98. /* 10002 aka RDS_INFO_FLOWS is deprecated */
  99. #define RDS_INFO_SEND_MESSAGES 10003
  100. #define RDS_INFO_RETRANS_MESSAGES 10004
  101. #define RDS_INFO_RECV_MESSAGES 10005
  102. #define RDS_INFO_SOCKETS 10006
  103. #define RDS_INFO_TCP_SOCKETS 10007
  104. #define RDS_INFO_IB_CONNECTIONS 10008
  105. #define RDS_INFO_CONNECTION_STATS 10009
  106. #define RDS_INFO_IWARP_CONNECTIONS 10010
  107. #define RDS_INFO_LAST 10010
  108. struct rds_info_counter {
  109. uint8_t name[32];
  110. uint64_t value;
  111. } __attribute__((packed));
  112. #define RDS_INFO_CONNECTION_FLAG_SENDING 0x01
  113. #define RDS_INFO_CONNECTION_FLAG_CONNECTING 0x02
  114. #define RDS_INFO_CONNECTION_FLAG_CONNECTED 0x04
  115. #define TRANSNAMSIZ 16
  116. struct rds_info_connection {
  117. uint64_t next_tx_seq;
  118. uint64_t next_rx_seq;
  119. __be32 laddr;
  120. __be32 faddr;
  121. uint8_t transport[TRANSNAMSIZ]; /* null term ascii */
  122. uint8_t flags;
  123. } __attribute__((packed));
  124. #define RDS_INFO_MESSAGE_FLAG_ACK 0x01
  125. #define RDS_INFO_MESSAGE_FLAG_FAST_ACK 0x02
  126. struct rds_info_message {
  127. uint64_t seq;
  128. uint32_t len;
  129. __be32 laddr;
  130. __be32 faddr;
  131. __be16 lport;
  132. __be16 fport;
  133. uint8_t flags;
  134. } __attribute__((packed));
  135. struct rds_info_socket {
  136. uint32_t sndbuf;
  137. __be32 bound_addr;
  138. __be32 connected_addr;
  139. __be16 bound_port;
  140. __be16 connected_port;
  141. uint32_t rcvbuf;
  142. uint64_t inum;
  143. } __attribute__((packed));
  144. struct rds_info_tcp_socket {
  145. __be32 local_addr;
  146. __be16 local_port;
  147. __be32 peer_addr;
  148. __be16 peer_port;
  149. uint64_t hdr_rem;
  150. uint64_t data_rem;
  151. uint32_t last_sent_nxt;
  152. uint32_t last_expected_una;
  153. uint32_t last_seen_una;
  154. } __attribute__((packed));
  155. #define RDS_IB_GID_LEN 16
  156. struct rds_info_rdma_connection {
  157. __be32 src_addr;
  158. __be32 dst_addr;
  159. uint8_t src_gid[RDS_IB_GID_LEN];
  160. uint8_t dst_gid[RDS_IB_GID_LEN];
  161. uint32_t max_send_wr;
  162. uint32_t max_recv_wr;
  163. uint32_t max_send_sge;
  164. uint32_t rdma_mr_max;
  165. uint32_t rdma_mr_size;
  166. };
  167. /* RDS message Receive Path Latency points */
  168. enum rds_message_rxpath_latency {
  169. RDS_MSG_RX_HDR_TO_DGRAM_START = 0,
  170. RDS_MSG_RX_DGRAM_REASSEMBLE,
  171. RDS_MSG_RX_DGRAM_DELIVERED,
  172. RDS_MSG_RX_DGRAM_TRACE_MAX
  173. };
  174. struct rds_rx_trace_so {
  175. u8 rx_traces;
  176. u8 rx_trace_pos[RDS_MSG_RX_DGRAM_TRACE_MAX];
  177. };
  178. struct rds_cmsg_rx_trace {
  179. u8 rx_traces;
  180. u8 rx_trace_pos[RDS_MSG_RX_DGRAM_TRACE_MAX];
  181. u64 rx_trace[RDS_MSG_RX_DGRAM_TRACE_MAX];
  182. };
  183. /*
  184. * Congestion monitoring.
  185. * Congestion control in RDS happens at the host connection
  186. * level by exchanging a bitmap marking congested ports.
  187. * By default, a process sleeping in poll() is always woken
  188. * up when the congestion map is updated.
  189. * With explicit monitoring, an application can have more
  190. * fine-grained control.
  191. * The application installs a 64bit mask value in the socket,
  192. * where each bit corresponds to a group of ports.
  193. * When a congestion update arrives, RDS checks the set of
  194. * ports that are now uncongested against the list bit mask
  195. * installed in the socket, and if they overlap, we queue a
  196. * cong_notification on the socket.
  197. *
  198. * To install the congestion monitor bitmask, use RDS_CONG_MONITOR
  199. * with the 64bit mask.
  200. * Congestion updates are received via RDS_CMSG_CONG_UPDATE
  201. * control messages.
  202. *
  203. * The correspondence between bits and ports is
  204. * 1 << (portnum % 64)
  205. */
  206. #define RDS_CONG_MONITOR_SIZE 64
  207. #define RDS_CONG_MONITOR_BIT(port) (((unsigned int) port) % RDS_CONG_MONITOR_SIZE)
  208. #define RDS_CONG_MONITOR_MASK(port) (1ULL << RDS_CONG_MONITOR_BIT(port))
  209. /*
  210. * RDMA related types
  211. */
  212. /*
  213. * This encapsulates a remote memory location.
  214. * In the current implementation, it contains the R_Key
  215. * of the remote memory region, and the offset into it
  216. * (so that the application does not have to worry about
  217. * alignment).
  218. */
  219. typedef uint64_t rds_rdma_cookie_t;
  220. struct rds_iovec {
  221. uint64_t addr;
  222. uint64_t bytes;
  223. };
  224. struct rds_get_mr_args {
  225. struct rds_iovec vec;
  226. uint64_t cookie_addr;
  227. uint64_t flags;
  228. };
  229. struct rds_get_mr_for_dest_args {
  230. struct sockaddr_storage dest_addr;
  231. struct rds_iovec vec;
  232. uint64_t cookie_addr;
  233. uint64_t flags;
  234. };
  235. struct rds_free_mr_args {
  236. rds_rdma_cookie_t cookie;
  237. uint64_t flags;
  238. };
  239. struct rds_rdma_args {
  240. rds_rdma_cookie_t cookie;
  241. struct rds_iovec remote_vec;
  242. uint64_t local_vec_addr;
  243. uint64_t nr_local;
  244. uint64_t flags;
  245. uint64_t user_token;
  246. };
  247. struct rds_atomic_args {
  248. rds_rdma_cookie_t cookie;
  249. uint64_t local_addr;
  250. uint64_t remote_addr;
  251. union {
  252. struct {
  253. uint64_t compare;
  254. uint64_t swap;
  255. } cswp;
  256. struct {
  257. uint64_t add;
  258. } fadd;
  259. struct {
  260. uint64_t compare;
  261. uint64_t swap;
  262. uint64_t compare_mask;
  263. uint64_t swap_mask;
  264. } m_cswp;
  265. struct {
  266. uint64_t add;
  267. uint64_t nocarry_mask;
  268. } m_fadd;
  269. };
  270. uint64_t flags;
  271. uint64_t user_token;
  272. };
  273. struct rds_rdma_notify {
  274. uint64_t user_token;
  275. int32_t status;
  276. };
  277. #define RDS_RDMA_SUCCESS 0
  278. #define RDS_RDMA_REMOTE_ERROR 1
  279. #define RDS_RDMA_CANCELED 2
  280. #define RDS_RDMA_DROPPED 3
  281. #define RDS_RDMA_OTHER_ERROR 4
  282. /*
  283. * Common set of flags for all RDMA related structs
  284. */
  285. #define RDS_RDMA_READWRITE 0x0001
  286. #define RDS_RDMA_FENCE 0x0002 /* use FENCE for immediate send */
  287. #define RDS_RDMA_INVALIDATE 0x0004 /* invalidate R_Key after freeing MR */
  288. #define RDS_RDMA_USE_ONCE 0x0008 /* free MR after use */
  289. #define RDS_RDMA_DONTWAIT 0x0010 /* Don't wait in SET_BARRIER */
  290. #define RDS_RDMA_NOTIFY_ME 0x0020 /* Notify when operation completes */
  291. #define RDS_RDMA_SILENT 0x0040 /* Do not interrupt remote */
  292. #endif /* IB_RDS_H */