rds.h 11 KB

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