rds.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) */
  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_INFO_FIRST 10000
  98. #define RDS_INFO_COUNTERS 10000
  99. #define RDS_INFO_CONNECTIONS 10001
  100. /* 10002 aka RDS_INFO_FLOWS is deprecated */
  101. #define RDS_INFO_SEND_MESSAGES 10003
  102. #define RDS_INFO_RETRANS_MESSAGES 10004
  103. #define RDS_INFO_RECV_MESSAGES 10005
  104. #define RDS_INFO_SOCKETS 10006
  105. #define RDS_INFO_TCP_SOCKETS 10007
  106. #define RDS_INFO_IB_CONNECTIONS 10008
  107. #define RDS_INFO_CONNECTION_STATS 10009
  108. #define RDS_INFO_IWARP_CONNECTIONS 10010
  109. #define RDS_INFO_LAST 10010
  110. struct rds_info_counter {
  111. __u8 name[32];
  112. __u64 value;
  113. } __attribute__((packed));
  114. #define RDS_INFO_CONNECTION_FLAG_SENDING 0x01
  115. #define RDS_INFO_CONNECTION_FLAG_CONNECTING 0x02
  116. #define RDS_INFO_CONNECTION_FLAG_CONNECTED 0x04
  117. #define TRANSNAMSIZ 16
  118. struct rds_info_connection {
  119. __u64 next_tx_seq;
  120. __u64 next_rx_seq;
  121. __be32 laddr;
  122. __be32 faddr;
  123. __u8 transport[TRANSNAMSIZ]; /* null term ascii */
  124. __u8 flags;
  125. } __attribute__((packed));
  126. #define RDS_INFO_MESSAGE_FLAG_ACK 0x01
  127. #define RDS_INFO_MESSAGE_FLAG_FAST_ACK 0x02
  128. struct rds_info_message {
  129. __u64 seq;
  130. __u32 len;
  131. __be32 laddr;
  132. __be32 faddr;
  133. __be16 lport;
  134. __be16 fport;
  135. __u8 flags;
  136. } __attribute__((packed));
  137. struct rds_info_socket {
  138. __u32 sndbuf;
  139. __be32 bound_addr;
  140. __be32 connected_addr;
  141. __be16 bound_port;
  142. __be16 connected_port;
  143. __u32 rcvbuf;
  144. __u64 inum;
  145. } __attribute__((packed));
  146. struct rds_info_tcp_socket {
  147. __be32 local_addr;
  148. __be16 local_port;
  149. __be32 peer_addr;
  150. __be16 peer_port;
  151. __u64 hdr_rem;
  152. __u64 data_rem;
  153. __u32 last_sent_nxt;
  154. __u32 last_expected_una;
  155. __u32 last_seen_una;
  156. } __attribute__((packed));
  157. #define RDS_IB_GID_LEN 16
  158. struct rds_info_rdma_connection {
  159. __be32 src_addr;
  160. __be32 dst_addr;
  161. __u8 src_gid[RDS_IB_GID_LEN];
  162. __u8 dst_gid[RDS_IB_GID_LEN];
  163. __u32 max_send_wr;
  164. __u32 max_recv_wr;
  165. __u32 max_send_sge;
  166. __u32 rdma_mr_max;
  167. __u32 rdma_mr_size;
  168. };
  169. /* RDS message Receive Path Latency points */
  170. enum rds_message_rxpath_latency {
  171. RDS_MSG_RX_HDR_TO_DGRAM_START = 0,
  172. RDS_MSG_RX_DGRAM_REASSEMBLE,
  173. RDS_MSG_RX_DGRAM_DELIVERED,
  174. RDS_MSG_RX_DGRAM_TRACE_MAX
  175. };
  176. struct rds_rx_trace_so {
  177. __u8 rx_traces;
  178. __u8 rx_trace_pos[RDS_MSG_RX_DGRAM_TRACE_MAX];
  179. };
  180. struct rds_cmsg_rx_trace {
  181. __u8 rx_traces;
  182. __u8 rx_trace_pos[RDS_MSG_RX_DGRAM_TRACE_MAX];
  183. __u64 rx_trace[RDS_MSG_RX_DGRAM_TRACE_MAX];
  184. };
  185. /*
  186. * Congestion monitoring.
  187. * Congestion control in RDS happens at the host connection
  188. * level by exchanging a bitmap marking congested ports.
  189. * By default, a process sleeping in poll() is always woken
  190. * up when the congestion map is updated.
  191. * With explicit monitoring, an application can have more
  192. * fine-grained control.
  193. * The application installs a 64bit mask value in the socket,
  194. * where each bit corresponds to a group of ports.
  195. * When a congestion update arrives, RDS checks the set of
  196. * ports that are now uncongested against the list bit mask
  197. * installed in the socket, and if they overlap, we queue a
  198. * cong_notification on the socket.
  199. *
  200. * To install the congestion monitor bitmask, use RDS_CONG_MONITOR
  201. * with the 64bit mask.
  202. * Congestion updates are received via RDS_CMSG_CONG_UPDATE
  203. * control messages.
  204. *
  205. * The correspondence between bits and ports is
  206. * 1 << (portnum % 64)
  207. */
  208. #define RDS_CONG_MONITOR_SIZE 64
  209. #define RDS_CONG_MONITOR_BIT(port) (((unsigned int) port) % RDS_CONG_MONITOR_SIZE)
  210. #define RDS_CONG_MONITOR_MASK(port) (1ULL << RDS_CONG_MONITOR_BIT(port))
  211. /*
  212. * RDMA related types
  213. */
  214. /*
  215. * This encapsulates a remote memory location.
  216. * In the current implementation, it contains the R_Key
  217. * of the remote memory region, and the offset into it
  218. * (so that the application does not have to worry about
  219. * alignment).
  220. */
  221. typedef __u64 rds_rdma_cookie_t;
  222. struct rds_iovec {
  223. __u64 addr;
  224. __u64 bytes;
  225. };
  226. struct rds_get_mr_args {
  227. struct rds_iovec vec;
  228. __u64 cookie_addr;
  229. __u64 flags;
  230. };
  231. struct rds_get_mr_for_dest_args {
  232. struct __kernel_sockaddr_storage dest_addr;
  233. struct rds_iovec vec;
  234. __u64 cookie_addr;
  235. __u64 flags;
  236. };
  237. struct rds_free_mr_args {
  238. rds_rdma_cookie_t cookie;
  239. __u64 flags;
  240. };
  241. struct rds_rdma_args {
  242. rds_rdma_cookie_t cookie;
  243. struct rds_iovec remote_vec;
  244. __u64 local_vec_addr;
  245. __u64 nr_local;
  246. __u64 flags;
  247. __u64 user_token;
  248. };
  249. struct rds_atomic_args {
  250. rds_rdma_cookie_t cookie;
  251. __u64 local_addr;
  252. __u64 remote_addr;
  253. union {
  254. struct {
  255. __u64 compare;
  256. __u64 swap;
  257. } cswp;
  258. struct {
  259. __u64 add;
  260. } fadd;
  261. struct {
  262. __u64 compare;
  263. __u64 swap;
  264. __u64 compare_mask;
  265. __u64 swap_mask;
  266. } m_cswp;
  267. struct {
  268. __u64 add;
  269. __u64 nocarry_mask;
  270. } m_fadd;
  271. };
  272. __u64 flags;
  273. __u64 user_token;
  274. };
  275. struct rds_rdma_notify {
  276. __u64 user_token;
  277. __s32 status;
  278. };
  279. #define RDS_RDMA_SUCCESS 0
  280. #define RDS_RDMA_REMOTE_ERROR 1
  281. #define RDS_RDMA_CANCELED 2
  282. #define RDS_RDMA_DROPPED 3
  283. #define RDS_RDMA_OTHER_ERROR 4
  284. /*
  285. * Common set of flags for all RDMA related structs
  286. */
  287. #define RDS_RDMA_READWRITE 0x0001
  288. #define RDS_RDMA_FENCE 0x0002 /* use FENCE for immediate send */
  289. #define RDS_RDMA_INVALIDATE 0x0004 /* invalidate R_Key after freeing MR */
  290. #define RDS_RDMA_USE_ONCE 0x0008 /* free MR after use */
  291. #define RDS_RDMA_DONTWAIT 0x0010 /* Don't wait in SET_BARRIER */
  292. #define RDS_RDMA_NOTIFY_ME 0x0020 /* Notify when operation completes */
  293. #define RDS_RDMA_SILENT 0x0040 /* Do not interrupt remote */
  294. #endif /* IB_RDS_H */