rds.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR Linux-OpenIB) */
  2. /*
  3. * Copyright (c) 2008, 2018 Oracle and/or its affiliates. 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. /* PF_RDS6 options */
  112. #define RDS6_INFO_CONNECTIONS 10011
  113. #define RDS6_INFO_SEND_MESSAGES 10012
  114. #define RDS6_INFO_RETRANS_MESSAGES 10013
  115. #define RDS6_INFO_RECV_MESSAGES 10014
  116. #define RDS6_INFO_SOCKETS 10015
  117. #define RDS6_INFO_TCP_SOCKETS 10016
  118. #define RDS6_INFO_IB_CONNECTIONS 10017
  119. #define RDS_INFO_LAST 10017
  120. struct rds_info_counter {
  121. __u8 name[32];
  122. __u64 value;
  123. } __attribute__((packed));
  124. #define RDS_INFO_CONNECTION_FLAG_SENDING 0x01
  125. #define RDS_INFO_CONNECTION_FLAG_CONNECTING 0x02
  126. #define RDS_INFO_CONNECTION_FLAG_CONNECTED 0x04
  127. #define TRANSNAMSIZ 16
  128. struct rds_info_connection {
  129. __u64 next_tx_seq;
  130. __u64 next_rx_seq;
  131. __be32 laddr;
  132. __be32 faddr;
  133. __u8 transport[TRANSNAMSIZ]; /* null term ascii */
  134. __u8 flags;
  135. } __attribute__((packed));
  136. struct rds6_info_connection {
  137. __u64 next_tx_seq;
  138. __u64 next_rx_seq;
  139. struct in6_addr laddr;
  140. struct in6_addr faddr;
  141. __u8 transport[TRANSNAMSIZ]; /* null term ascii */
  142. __u8 flags;
  143. } __attribute__((packed));
  144. #define RDS_INFO_MESSAGE_FLAG_ACK 0x01
  145. #define RDS_INFO_MESSAGE_FLAG_FAST_ACK 0x02
  146. struct rds_info_message {
  147. __u64 seq;
  148. __u32 len;
  149. __be32 laddr;
  150. __be32 faddr;
  151. __be16 lport;
  152. __be16 fport;
  153. __u8 flags;
  154. } __attribute__((packed));
  155. struct rds6_info_message {
  156. __u64 seq;
  157. __u32 len;
  158. struct in6_addr laddr;
  159. struct in6_addr faddr;
  160. __be16 lport;
  161. __be16 fport;
  162. __u8 flags;
  163. __u8 tos;
  164. } __attribute__((packed));
  165. struct rds_info_socket {
  166. __u32 sndbuf;
  167. __be32 bound_addr;
  168. __be32 connected_addr;
  169. __be16 bound_port;
  170. __be16 connected_port;
  171. __u32 rcvbuf;
  172. __u64 inum;
  173. } __attribute__((packed));
  174. struct rds6_info_socket {
  175. __u32 sndbuf;
  176. struct in6_addr bound_addr;
  177. struct in6_addr connected_addr;
  178. __be16 bound_port;
  179. __be16 connected_port;
  180. __u32 rcvbuf;
  181. __u64 inum;
  182. } __attribute__((packed));
  183. struct rds_info_tcp_socket {
  184. __be32 local_addr;
  185. __be16 local_port;
  186. __be32 peer_addr;
  187. __be16 peer_port;
  188. __u64 hdr_rem;
  189. __u64 data_rem;
  190. __u32 last_sent_nxt;
  191. __u32 last_expected_una;
  192. __u32 last_seen_una;
  193. } __attribute__((packed));
  194. struct rds6_info_tcp_socket {
  195. struct in6_addr local_addr;
  196. __be16 local_port;
  197. struct in6_addr peer_addr;
  198. __be16 peer_port;
  199. __u64 hdr_rem;
  200. __u64 data_rem;
  201. __u32 last_sent_nxt;
  202. __u32 last_expected_una;
  203. __u32 last_seen_una;
  204. } __attribute__((packed));
  205. #define RDS_IB_GID_LEN 16
  206. struct rds_info_rdma_connection {
  207. __be32 src_addr;
  208. __be32 dst_addr;
  209. __u8 src_gid[RDS_IB_GID_LEN];
  210. __u8 dst_gid[RDS_IB_GID_LEN];
  211. __u32 max_send_wr;
  212. __u32 max_recv_wr;
  213. __u32 max_send_sge;
  214. __u32 rdma_mr_max;
  215. __u32 rdma_mr_size;
  216. };
  217. struct rds6_info_rdma_connection {
  218. struct in6_addr src_addr;
  219. struct in6_addr dst_addr;
  220. __u8 src_gid[RDS_IB_GID_LEN];
  221. __u8 dst_gid[RDS_IB_GID_LEN];
  222. __u32 max_send_wr;
  223. __u32 max_recv_wr;
  224. __u32 max_send_sge;
  225. __u32 rdma_mr_max;
  226. __u32 rdma_mr_size;
  227. };
  228. /* RDS message Receive Path Latency points */
  229. enum rds_message_rxpath_latency {
  230. RDS_MSG_RX_HDR_TO_DGRAM_START = 0,
  231. RDS_MSG_RX_DGRAM_REASSEMBLE,
  232. RDS_MSG_RX_DGRAM_DELIVERED,
  233. RDS_MSG_RX_DGRAM_TRACE_MAX
  234. };
  235. struct rds_rx_trace_so {
  236. __u8 rx_traces;
  237. __u8 rx_trace_pos[RDS_MSG_RX_DGRAM_TRACE_MAX];
  238. };
  239. struct rds_cmsg_rx_trace {
  240. __u8 rx_traces;
  241. __u8 rx_trace_pos[RDS_MSG_RX_DGRAM_TRACE_MAX];
  242. __u64 rx_trace[RDS_MSG_RX_DGRAM_TRACE_MAX];
  243. };
  244. /*
  245. * Congestion monitoring.
  246. * Congestion control in RDS happens at the host connection
  247. * level by exchanging a bitmap marking congested ports.
  248. * By default, a process sleeping in poll() is always woken
  249. * up when the congestion map is updated.
  250. * With explicit monitoring, an application can have more
  251. * fine-grained control.
  252. * The application installs a 64bit mask value in the socket,
  253. * where each bit corresponds to a group of ports.
  254. * When a congestion update arrives, RDS checks the set of
  255. * ports that are now uncongested against the list bit mask
  256. * installed in the socket, and if they overlap, we queue a
  257. * cong_notification on the socket.
  258. *
  259. * To install the congestion monitor bitmask, use RDS_CONG_MONITOR
  260. * with the 64bit mask.
  261. * Congestion updates are received via RDS_CMSG_CONG_UPDATE
  262. * control messages.
  263. *
  264. * The correspondence between bits and ports is
  265. * 1 << (portnum % 64)
  266. */
  267. #define RDS_CONG_MONITOR_SIZE 64
  268. #define RDS_CONG_MONITOR_BIT(port) (((unsigned int) port) % RDS_CONG_MONITOR_SIZE)
  269. #define RDS_CONG_MONITOR_MASK(port) (1ULL << RDS_CONG_MONITOR_BIT(port))
  270. /*
  271. * RDMA related types
  272. */
  273. /*
  274. * This encapsulates a remote memory location.
  275. * In the current implementation, it contains the R_Key
  276. * of the remote memory region, and the offset into it
  277. * (so that the application does not have to worry about
  278. * alignment).
  279. */
  280. typedef __u64 rds_rdma_cookie_t;
  281. struct rds_iovec {
  282. __u64 addr;
  283. __u64 bytes;
  284. };
  285. struct rds_get_mr_args {
  286. struct rds_iovec vec;
  287. __u64 cookie_addr;
  288. __u64 flags;
  289. };
  290. struct rds_get_mr_for_dest_args {
  291. struct __kernel_sockaddr_storage dest_addr;
  292. struct rds_iovec vec;
  293. __u64 cookie_addr;
  294. __u64 flags;
  295. };
  296. struct rds_free_mr_args {
  297. rds_rdma_cookie_t cookie;
  298. __u64 flags;
  299. };
  300. struct rds_rdma_args {
  301. rds_rdma_cookie_t cookie;
  302. struct rds_iovec remote_vec;
  303. __u64 local_vec_addr;
  304. __u64 nr_local;
  305. __u64 flags;
  306. __u64 user_token;
  307. };
  308. struct rds_atomic_args {
  309. rds_rdma_cookie_t cookie;
  310. __u64 local_addr;
  311. __u64 remote_addr;
  312. union {
  313. struct {
  314. __u64 compare;
  315. __u64 swap;
  316. } cswp;
  317. struct {
  318. __u64 add;
  319. } fadd;
  320. struct {
  321. __u64 compare;
  322. __u64 swap;
  323. __u64 compare_mask;
  324. __u64 swap_mask;
  325. } m_cswp;
  326. struct {
  327. __u64 add;
  328. __u64 nocarry_mask;
  329. } m_fadd;
  330. };
  331. __u64 flags;
  332. __u64 user_token;
  333. };
  334. struct rds_rdma_notify {
  335. __u64 user_token;
  336. __s32 status;
  337. };
  338. #define RDS_RDMA_SUCCESS 0
  339. #define RDS_RDMA_REMOTE_ERROR 1
  340. #define RDS_RDMA_CANCELED 2
  341. #define RDS_RDMA_DROPPED 3
  342. #define RDS_RDMA_OTHER_ERROR 4
  343. #define RDS_MAX_ZCOOKIES 8
  344. struct rds_zcopy_cookies {
  345. __u32 num;
  346. __u32 cookies[RDS_MAX_ZCOOKIES];
  347. };
  348. /*
  349. * Common set of flags for all RDMA related structs
  350. */
  351. #define RDS_RDMA_READWRITE 0x0001
  352. #define RDS_RDMA_FENCE 0x0002 /* use FENCE for immediate send */
  353. #define RDS_RDMA_INVALIDATE 0x0004 /* invalidate R_Key after freeing MR */
  354. #define RDS_RDMA_USE_ONCE 0x0008 /* free MR after use */
  355. #define RDS_RDMA_DONTWAIT 0x0010 /* Don't wait in SET_BARRIER */
  356. #define RDS_RDMA_NOTIFY_ME 0x0020 /* Notify when operation completes */
  357. #define RDS_RDMA_SILENT 0x0040 /* Do not interrupt remote */
  358. #endif /* IB_RDS_H */