rds.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. #include <linux/socket.h> /* For __kernel_sockaddr_storage. */
  37. #define RDS_IB_ABI_VERSION 0x301
  38. #define SOL_RDS 276
  39. /*
  40. * setsockopt/getsockopt for SOL_RDS
  41. */
  42. #define RDS_CANCEL_SENT_TO 1
  43. #define RDS_GET_MR 2
  44. #define RDS_FREE_MR 3
  45. /* deprecated: RDS_BARRIER 4 */
  46. #define RDS_RECVERR 5
  47. #define RDS_CONG_MONITOR 6
  48. #define RDS_GET_MR_FOR_DEST 7
  49. #define SO_RDS_TRANSPORT 8
  50. /* supported values for SO_RDS_TRANSPORT */
  51. #define RDS_TRANS_IB 0
  52. #define RDS_TRANS_IWARP 1
  53. #define RDS_TRANS_TCP 2
  54. #define RDS_TRANS_COUNT 3
  55. #define RDS_TRANS_NONE (~0)
  56. /*
  57. * Control message types for SOL_RDS.
  58. *
  59. * CMSG_RDMA_ARGS (sendmsg)
  60. * Request a RDMA transfer to/from the specified
  61. * memory ranges.
  62. * The cmsg_data is a struct rds_rdma_args.
  63. * RDS_CMSG_RDMA_DEST (recvmsg, sendmsg)
  64. * Kernel informs application about intended
  65. * source/destination of a RDMA transfer
  66. * RDS_CMSG_RDMA_MAP (sendmsg)
  67. * Application asks kernel to map the given
  68. * memory range into a IB MR, and send the
  69. * R_Key along in an RDS extension header.
  70. * The cmsg_data is a struct rds_get_mr_args,
  71. * the same as for the GET_MR setsockopt.
  72. * RDS_CMSG_RDMA_STATUS (recvmsg)
  73. * Returns the status of a completed RDMA operation.
  74. */
  75. #define RDS_CMSG_RDMA_ARGS 1
  76. #define RDS_CMSG_RDMA_DEST 2
  77. #define RDS_CMSG_RDMA_MAP 3
  78. #define RDS_CMSG_RDMA_STATUS 4
  79. #define RDS_CMSG_CONG_UPDATE 5
  80. #define RDS_CMSG_ATOMIC_FADD 6
  81. #define RDS_CMSG_ATOMIC_CSWP 7
  82. #define RDS_CMSG_MASKED_ATOMIC_FADD 8
  83. #define RDS_CMSG_MASKED_ATOMIC_CSWP 9
  84. #define RDS_INFO_FIRST 10000
  85. #define RDS_INFO_COUNTERS 10000
  86. #define RDS_INFO_CONNECTIONS 10001
  87. /* 10002 aka RDS_INFO_FLOWS is deprecated */
  88. #define RDS_INFO_SEND_MESSAGES 10003
  89. #define RDS_INFO_RETRANS_MESSAGES 10004
  90. #define RDS_INFO_RECV_MESSAGES 10005
  91. #define RDS_INFO_SOCKETS 10006
  92. #define RDS_INFO_TCP_SOCKETS 10007
  93. #define RDS_INFO_IB_CONNECTIONS 10008
  94. #define RDS_INFO_CONNECTION_STATS 10009
  95. #define RDS_INFO_IWARP_CONNECTIONS 10010
  96. #define RDS_INFO_LAST 10010
  97. struct rds_info_counter {
  98. __u8 name[32];
  99. __u64 value;
  100. } __attribute__((packed));
  101. #define RDS_INFO_CONNECTION_FLAG_SENDING 0x01
  102. #define RDS_INFO_CONNECTION_FLAG_CONNECTING 0x02
  103. #define RDS_INFO_CONNECTION_FLAG_CONNECTED 0x04
  104. #define TRANSNAMSIZ 16
  105. struct rds_info_connection {
  106. __u64 next_tx_seq;
  107. __u64 next_rx_seq;
  108. __be32 laddr;
  109. __be32 faddr;
  110. __u8 transport[TRANSNAMSIZ]; /* null term ascii */
  111. __u8 flags;
  112. } __attribute__((packed));
  113. #define RDS_INFO_MESSAGE_FLAG_ACK 0x01
  114. #define RDS_INFO_MESSAGE_FLAG_FAST_ACK 0x02
  115. struct rds_info_message {
  116. __u64 seq;
  117. __u32 len;
  118. __be32 laddr;
  119. __be32 faddr;
  120. __be16 lport;
  121. __be16 fport;
  122. __u8 flags;
  123. } __attribute__((packed));
  124. struct rds_info_socket {
  125. __u32 sndbuf;
  126. __be32 bound_addr;
  127. __be32 connected_addr;
  128. __be16 bound_port;
  129. __be16 connected_port;
  130. __u32 rcvbuf;
  131. __u64 inum;
  132. } __attribute__((packed));
  133. struct rds_info_tcp_socket {
  134. __be32 local_addr;
  135. __be16 local_port;
  136. __be32 peer_addr;
  137. __be16 peer_port;
  138. __u64 hdr_rem;
  139. __u64 data_rem;
  140. __u32 last_sent_nxt;
  141. __u32 last_expected_una;
  142. __u32 last_seen_una;
  143. } __attribute__((packed));
  144. #define RDS_IB_GID_LEN 16
  145. struct rds_info_rdma_connection {
  146. __be32 src_addr;
  147. __be32 dst_addr;
  148. __u8 src_gid[RDS_IB_GID_LEN];
  149. __u8 dst_gid[RDS_IB_GID_LEN];
  150. __u32 max_send_wr;
  151. __u32 max_recv_wr;
  152. __u32 max_send_sge;
  153. __u32 rdma_mr_max;
  154. __u32 rdma_mr_size;
  155. };
  156. /*
  157. * Congestion monitoring.
  158. * Congestion control in RDS happens at the host connection
  159. * level by exchanging a bitmap marking congested ports.
  160. * By default, a process sleeping in poll() is always woken
  161. * up when the congestion map is updated.
  162. * With explicit monitoring, an application can have more
  163. * fine-grained control.
  164. * The application installs a 64bit mask value in the socket,
  165. * where each bit corresponds to a group of ports.
  166. * When a congestion update arrives, RDS checks the set of
  167. * ports that are now uncongested against the list bit mask
  168. * installed in the socket, and if they overlap, we queue a
  169. * cong_notification on the socket.
  170. *
  171. * To install the congestion monitor bitmask, use RDS_CONG_MONITOR
  172. * with the 64bit mask.
  173. * Congestion updates are received via RDS_CMSG_CONG_UPDATE
  174. * control messages.
  175. *
  176. * The correspondence between bits and ports is
  177. * 1 << (portnum % 64)
  178. */
  179. #define RDS_CONG_MONITOR_SIZE 64
  180. #define RDS_CONG_MONITOR_BIT(port) (((unsigned int) port) % RDS_CONG_MONITOR_SIZE)
  181. #define RDS_CONG_MONITOR_MASK(port) (1ULL << RDS_CONG_MONITOR_BIT(port))
  182. /*
  183. * RDMA related types
  184. */
  185. /*
  186. * This encapsulates a remote memory location.
  187. * In the current implementation, it contains the R_Key
  188. * of the remote memory region, and the offset into it
  189. * (so that the application does not have to worry about
  190. * alignment).
  191. */
  192. typedef __u64 rds_rdma_cookie_t;
  193. struct rds_iovec {
  194. __u64 addr;
  195. __u64 bytes;
  196. };
  197. struct rds_get_mr_args {
  198. struct rds_iovec vec;
  199. __u64 cookie_addr;
  200. __u64 flags;
  201. };
  202. struct rds_get_mr_for_dest_args {
  203. struct __kernel_sockaddr_storage dest_addr;
  204. struct rds_iovec vec;
  205. __u64 cookie_addr;
  206. __u64 flags;
  207. };
  208. struct rds_free_mr_args {
  209. rds_rdma_cookie_t cookie;
  210. __u64 flags;
  211. };
  212. struct rds_rdma_args {
  213. rds_rdma_cookie_t cookie;
  214. struct rds_iovec remote_vec;
  215. __u64 local_vec_addr;
  216. __u64 nr_local;
  217. __u64 flags;
  218. __u64 user_token;
  219. };
  220. struct rds_atomic_args {
  221. rds_rdma_cookie_t cookie;
  222. __u64 local_addr;
  223. __u64 remote_addr;
  224. union {
  225. struct {
  226. __u64 compare;
  227. __u64 swap;
  228. } cswp;
  229. struct {
  230. __u64 add;
  231. } fadd;
  232. struct {
  233. __u64 compare;
  234. __u64 swap;
  235. __u64 compare_mask;
  236. __u64 swap_mask;
  237. } m_cswp;
  238. struct {
  239. __u64 add;
  240. __u64 nocarry_mask;
  241. } m_fadd;
  242. };
  243. __u64 flags;
  244. __u64 user_token;
  245. };
  246. struct rds_rdma_notify {
  247. __u64 user_token;
  248. __s32 status;
  249. };
  250. #define RDS_RDMA_SUCCESS 0
  251. #define RDS_RDMA_REMOTE_ERROR 1
  252. #define RDS_RDMA_CANCELED 2
  253. #define RDS_RDMA_DROPPED 3
  254. #define RDS_RDMA_OTHER_ERROR 4
  255. /*
  256. * Common set of flags for all RDMA related structs
  257. */
  258. #define RDS_RDMA_READWRITE 0x0001
  259. #define RDS_RDMA_FENCE 0x0002 /* use FENCE for immediate send */
  260. #define RDS_RDMA_INVALIDATE 0x0004 /* invalidate R_Key after freeing MR */
  261. #define RDS_RDMA_USE_ONCE 0x0008 /* free MR after use */
  262. #define RDS_RDMA_DONTWAIT 0x0010 /* Don't wait in SET_BARRIER */
  263. #define RDS_RDMA_NOTIFY_ME 0x0020 /* Notify when operation completes */
  264. #define RDS_RDMA_SILENT 0x0040 /* Do not interrupt remote */
  265. #endif /* IB_RDS_H */