rds.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. #include <linux/in6.h> /* For struct in6_addr. */
  39. #define RDS_IB_ABI_VERSION 0x301
  40. #define SOL_RDS 276
  41. /*
  42. * setsockopt/getsockopt for SOL_RDS
  43. */
  44. #define RDS_CANCEL_SENT_TO 1
  45. #define RDS_GET_MR 2
  46. #define RDS_FREE_MR 3
  47. /* deprecated: RDS_BARRIER 4 */
  48. #define RDS_RECVERR 5
  49. #define RDS_CONG_MONITOR 6
  50. #define RDS_GET_MR_FOR_DEST 7
  51. #define SO_RDS_TRANSPORT 8
  52. /* Socket option to tap receive path latency
  53. * SO_RDS: SO_RDS_MSG_RXPATH_LATENCY
  54. * Format used struct rds_rx_trace_so
  55. */
  56. #define SO_RDS_MSG_RXPATH_LATENCY 10
  57. /* supported values for SO_RDS_TRANSPORT */
  58. #define RDS_TRANS_IB 0
  59. #define RDS_TRANS_GAP 1
  60. #define RDS_TRANS_TCP 2
  61. #define RDS_TRANS_COUNT 3
  62. #define RDS_TRANS_NONE (~0)
  63. /* don't use RDS_TRANS_IWARP - it is deprecated */
  64. #define RDS_TRANS_IWARP RDS_TRANS_GAP
  65. /* IOCTLS commands for SOL_RDS */
  66. #define SIOCRDSSETTOS (SIOCPROTOPRIVATE)
  67. #define SIOCRDSGETTOS (SIOCPROTOPRIVATE + 1)
  68. typedef __u8 rds_tos_t;
  69. /*
  70. * Control message types for SOL_RDS.
  71. *
  72. * CMSG_RDMA_ARGS (sendmsg)
  73. * Request a RDMA transfer to/from the specified
  74. * memory ranges.
  75. * The cmsg_data is a struct rds_rdma_args.
  76. * RDS_CMSG_RDMA_DEST (recvmsg, sendmsg)
  77. * Kernel informs application about intended
  78. * source/destination of a RDMA transfer
  79. * RDS_CMSG_RDMA_MAP (sendmsg)
  80. * Application asks kernel to map the given
  81. * memory range into a IB MR, and send the
  82. * R_Key along in an RDS extension header.
  83. * The cmsg_data is a struct rds_get_mr_args,
  84. * the same as for the GET_MR setsockopt.
  85. * RDS_CMSG_RDMA_STATUS (recvmsg)
  86. * Returns the status of a completed RDMA operation.
  87. * RDS_CMSG_RXPATH_LATENCY(recvmsg)
  88. * Returns rds message latencies in various stages of receive
  89. * path in nS. Its set per socket using SO_RDS_MSG_RXPATH_LATENCY
  90. * socket option. Legitimate points are defined in
  91. * enum rds_message_rxpath_latency. More points can be added in
  92. * future. CSMG format is struct rds_cmsg_rx_trace.
  93. */
  94. #define RDS_CMSG_RDMA_ARGS 1
  95. #define RDS_CMSG_RDMA_DEST 2
  96. #define RDS_CMSG_RDMA_MAP 3
  97. #define RDS_CMSG_RDMA_STATUS 4
  98. #define RDS_CMSG_CONG_UPDATE 5
  99. #define RDS_CMSG_ATOMIC_FADD 6
  100. #define RDS_CMSG_ATOMIC_CSWP 7
  101. #define RDS_CMSG_MASKED_ATOMIC_FADD 8
  102. #define RDS_CMSG_MASKED_ATOMIC_CSWP 9
  103. #define RDS_CMSG_RXPATH_LATENCY 11
  104. #define RDS_CMSG_ZCOPY_COOKIE 12
  105. #define RDS_CMSG_ZCOPY_COMPLETION 13
  106. #define RDS_INFO_FIRST 10000
  107. #define RDS_INFO_COUNTERS 10000
  108. #define RDS_INFO_CONNECTIONS 10001
  109. /* 10002 aka RDS_INFO_FLOWS is deprecated */
  110. #define RDS_INFO_SEND_MESSAGES 10003
  111. #define RDS_INFO_RETRANS_MESSAGES 10004
  112. #define RDS_INFO_RECV_MESSAGES 10005
  113. #define RDS_INFO_SOCKETS 10006
  114. #define RDS_INFO_TCP_SOCKETS 10007
  115. #define RDS_INFO_IB_CONNECTIONS 10008
  116. #define RDS_INFO_CONNECTION_STATS 10009
  117. #define RDS_INFO_IWARP_CONNECTIONS 10010
  118. /* PF_RDS6 options */
  119. #define RDS6_INFO_CONNECTIONS 10011
  120. #define RDS6_INFO_SEND_MESSAGES 10012
  121. #define RDS6_INFO_RETRANS_MESSAGES 10013
  122. #define RDS6_INFO_RECV_MESSAGES 10014
  123. #define RDS6_INFO_SOCKETS 10015
  124. #define RDS6_INFO_TCP_SOCKETS 10016
  125. #define RDS6_INFO_IB_CONNECTIONS 10017
  126. #define RDS_INFO_LAST 10017
  127. struct rds_info_counter {
  128. __u8 name[32];
  129. __u64 value;
  130. } __attribute__((packed));
  131. #define RDS_INFO_CONNECTION_FLAG_SENDING 0x01
  132. #define RDS_INFO_CONNECTION_FLAG_CONNECTING 0x02
  133. #define RDS_INFO_CONNECTION_FLAG_CONNECTED 0x04
  134. #define TRANSNAMSIZ 16
  135. struct rds_info_connection {
  136. __u64 next_tx_seq;
  137. __u64 next_rx_seq;
  138. __be32 laddr;
  139. __be32 faddr;
  140. __u8 transport[TRANSNAMSIZ]; /* null term ascii */
  141. __u8 flags;
  142. __u8 tos;
  143. } __attribute__((packed));
  144. struct rds6_info_connection {
  145. __u64 next_tx_seq;
  146. __u64 next_rx_seq;
  147. struct in6_addr laddr;
  148. struct in6_addr faddr;
  149. __u8 transport[TRANSNAMSIZ]; /* null term ascii */
  150. __u8 flags;
  151. } __attribute__((packed));
  152. #define RDS_INFO_MESSAGE_FLAG_ACK 0x01
  153. #define RDS_INFO_MESSAGE_FLAG_FAST_ACK 0x02
  154. struct rds_info_message {
  155. __u64 seq;
  156. __u32 len;
  157. __be32 laddr;
  158. __be32 faddr;
  159. __be16 lport;
  160. __be16 fport;
  161. __u8 flags;
  162. __u8 tos;
  163. } __attribute__((packed));
  164. struct rds6_info_message {
  165. __u64 seq;
  166. __u32 len;
  167. struct in6_addr laddr;
  168. struct in6_addr faddr;
  169. __be16 lport;
  170. __be16 fport;
  171. __u8 flags;
  172. __u8 tos;
  173. } __attribute__((packed));
  174. struct rds_info_socket {
  175. __u32 sndbuf;
  176. __be32 bound_addr;
  177. __be32 connected_addr;
  178. __be16 bound_port;
  179. __be16 connected_port;
  180. __u32 rcvbuf;
  181. __u64 inum;
  182. } __attribute__((packed));
  183. struct rds6_info_socket {
  184. __u32 sndbuf;
  185. struct in6_addr bound_addr;
  186. struct in6_addr connected_addr;
  187. __be16 bound_port;
  188. __be16 connected_port;
  189. __u32 rcvbuf;
  190. __u64 inum;
  191. } __attribute__((packed));
  192. struct rds_info_tcp_socket {
  193. __be32 local_addr;
  194. __be16 local_port;
  195. __be32 peer_addr;
  196. __be16 peer_port;
  197. __u64 hdr_rem;
  198. __u64 data_rem;
  199. __u32 last_sent_nxt;
  200. __u32 last_expected_una;
  201. __u32 last_seen_una;
  202. __u8 tos;
  203. } __attribute__((packed));
  204. struct rds6_info_tcp_socket {
  205. struct in6_addr local_addr;
  206. __be16 local_port;
  207. struct in6_addr peer_addr;
  208. __be16 peer_port;
  209. __u64 hdr_rem;
  210. __u64 data_rem;
  211. __u32 last_sent_nxt;
  212. __u32 last_expected_una;
  213. __u32 last_seen_una;
  214. } __attribute__((packed));
  215. #define RDS_IB_GID_LEN 16
  216. struct rds_info_rdma_connection {
  217. __be32 src_addr;
  218. __be32 dst_addr;
  219. __u8 src_gid[RDS_IB_GID_LEN];
  220. __u8 dst_gid[RDS_IB_GID_LEN];
  221. __u32 max_send_wr;
  222. __u32 max_recv_wr;
  223. __u32 max_send_sge;
  224. __u32 rdma_mr_max;
  225. __u32 rdma_mr_size;
  226. __u8 tos;
  227. __u8 sl;
  228. __u32 cache_allocs;
  229. };
  230. struct rds6_info_rdma_connection {
  231. struct in6_addr src_addr;
  232. struct in6_addr dst_addr;
  233. __u8 src_gid[RDS_IB_GID_LEN];
  234. __u8 dst_gid[RDS_IB_GID_LEN];
  235. __u32 max_send_wr;
  236. __u32 max_recv_wr;
  237. __u32 max_send_sge;
  238. __u32 rdma_mr_max;
  239. __u32 rdma_mr_size;
  240. __u8 tos;
  241. __u8 sl;
  242. __u32 cache_allocs;
  243. };
  244. /* RDS message Receive Path Latency points */
  245. enum rds_message_rxpath_latency {
  246. RDS_MSG_RX_HDR_TO_DGRAM_START = 0,
  247. RDS_MSG_RX_DGRAM_REASSEMBLE,
  248. RDS_MSG_RX_DGRAM_DELIVERED,
  249. RDS_MSG_RX_DGRAM_TRACE_MAX
  250. };
  251. struct rds_rx_trace_so {
  252. __u8 rx_traces;
  253. __u8 rx_trace_pos[RDS_MSG_RX_DGRAM_TRACE_MAX];
  254. };
  255. struct rds_cmsg_rx_trace {
  256. __u8 rx_traces;
  257. __u8 rx_trace_pos[RDS_MSG_RX_DGRAM_TRACE_MAX];
  258. __u64 rx_trace[RDS_MSG_RX_DGRAM_TRACE_MAX];
  259. };
  260. /*
  261. * Congestion monitoring.
  262. * Congestion control in RDS happens at the host connection
  263. * level by exchanging a bitmap marking congested ports.
  264. * By default, a process sleeping in poll() is always woken
  265. * up when the congestion map is updated.
  266. * With explicit monitoring, an application can have more
  267. * fine-grained control.
  268. * The application installs a 64bit mask value in the socket,
  269. * where each bit corresponds to a group of ports.
  270. * When a congestion update arrives, RDS checks the set of
  271. * ports that are now uncongested against the list bit mask
  272. * installed in the socket, and if they overlap, we queue a
  273. * cong_notification on the socket.
  274. *
  275. * To install the congestion monitor bitmask, use RDS_CONG_MONITOR
  276. * with the 64bit mask.
  277. * Congestion updates are received via RDS_CMSG_CONG_UPDATE
  278. * control messages.
  279. *
  280. * The correspondence between bits and ports is
  281. * 1 << (portnum % 64)
  282. */
  283. #define RDS_CONG_MONITOR_SIZE 64
  284. #define RDS_CONG_MONITOR_BIT(port) (((unsigned int) port) % RDS_CONG_MONITOR_SIZE)
  285. #define RDS_CONG_MONITOR_MASK(port) (1ULL << RDS_CONG_MONITOR_BIT(port))
  286. /*
  287. * RDMA related types
  288. */
  289. /*
  290. * This encapsulates a remote memory location.
  291. * In the current implementation, it contains the R_Key
  292. * of the remote memory region, and the offset into it
  293. * (so that the application does not have to worry about
  294. * alignment).
  295. */
  296. typedef __u64 rds_rdma_cookie_t;
  297. struct rds_iovec {
  298. __u64 addr;
  299. __u64 bytes;
  300. };
  301. struct rds_get_mr_args {
  302. struct rds_iovec vec;
  303. __u64 cookie_addr;
  304. __u64 flags;
  305. };
  306. struct rds_get_mr_for_dest_args {
  307. struct __kernel_sockaddr_storage dest_addr;
  308. struct rds_iovec vec;
  309. __u64 cookie_addr;
  310. __u64 flags;
  311. };
  312. struct rds_free_mr_args {
  313. rds_rdma_cookie_t cookie;
  314. __u64 flags;
  315. };
  316. struct rds_rdma_args {
  317. rds_rdma_cookie_t cookie;
  318. struct rds_iovec remote_vec;
  319. __u64 local_vec_addr;
  320. __u64 nr_local;
  321. __u64 flags;
  322. __u64 user_token;
  323. };
  324. struct rds_atomic_args {
  325. rds_rdma_cookie_t cookie;
  326. __u64 local_addr;
  327. __u64 remote_addr;
  328. union {
  329. struct {
  330. __u64 compare;
  331. __u64 swap;
  332. } cswp;
  333. struct {
  334. __u64 add;
  335. } fadd;
  336. struct {
  337. __u64 compare;
  338. __u64 swap;
  339. __u64 compare_mask;
  340. __u64 swap_mask;
  341. } m_cswp;
  342. struct {
  343. __u64 add;
  344. __u64 nocarry_mask;
  345. } m_fadd;
  346. };
  347. __u64 flags;
  348. __u64 user_token;
  349. };
  350. struct rds_rdma_notify {
  351. __u64 user_token;
  352. __s32 status;
  353. };
  354. #define RDS_RDMA_SUCCESS 0
  355. #define RDS_RDMA_REMOTE_ERROR 1
  356. #define RDS_RDMA_CANCELED 2
  357. #define RDS_RDMA_DROPPED 3
  358. #define RDS_RDMA_OTHER_ERROR 4
  359. #define RDS_MAX_ZCOOKIES 8
  360. struct rds_zcopy_cookies {
  361. __u32 num;
  362. __u32 cookies[RDS_MAX_ZCOOKIES];
  363. };
  364. /*
  365. * Common set of flags for all RDMA related structs
  366. */
  367. #define RDS_RDMA_READWRITE 0x0001
  368. #define RDS_RDMA_FENCE 0x0002 /* use FENCE for immediate send */
  369. #define RDS_RDMA_INVALIDATE 0x0004 /* invalidate R_Key after freeing MR */
  370. #define RDS_RDMA_USE_ONCE 0x0008 /* free MR after use */
  371. #define RDS_RDMA_DONTWAIT 0x0010 /* Don't wait in SET_BARRIER */
  372. #define RDS_RDMA_NOTIFY_ME 0x0020 /* Notify when operation completes */
  373. #define RDS_RDMA_SILENT 0x0040 /* Do not interrupt remote */
  374. #endif /* IB_RDS_H */