rds.h 9.1 KB

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