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