xref: /linux-6.15/include/uapi/linux/rds.h (revision 6ae0a628)
1 /*
2  * Copyright (c) 2008 Oracle.  All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  *
32  */
33 
34 #ifndef _LINUX_RDS_H
35 #define _LINUX_RDS_H
36 
37 #include <linux/types.h>
38 
39 #define RDS_IB_ABI_VERSION		0x301
40 
41 #define	SOL_RDS		276
42 
43 /*
44  * setsockopt/getsockopt for SOL_RDS
45  */
46 #define RDS_CANCEL_SENT_TO      	1
47 #define RDS_GET_MR			2
48 #define RDS_FREE_MR			3
49 /* deprecated: RDS_BARRIER 4 */
50 #define RDS_RECVERR			5
51 #define RDS_CONG_MONITOR		6
52 #define RDS_GET_MR_FOR_DEST		7
53 #define SO_RDS_TRANSPORT		8
54 
55 /* Socket option to tap receive path latency
56  *	SO_RDS: SO_RDS_MSG_RXPATH_LATENCY
57  *	Format used struct rds_rx_trace_so
58  */
59 #define SO_RDS_MSG_RXPATH_LATENCY	10
60 
61 
62 /* supported values for SO_RDS_TRANSPORT */
63 #define	RDS_TRANS_IB	0
64 #define	RDS_TRANS_IWARP	1
65 #define	RDS_TRANS_TCP	2
66 #define RDS_TRANS_COUNT	3
67 #define	RDS_TRANS_NONE	(~0)
68 
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 
105 #define RDS_INFO_FIRST			10000
106 #define RDS_INFO_COUNTERS		10000
107 #define RDS_INFO_CONNECTIONS		10001
108 /* 10002 aka RDS_INFO_FLOWS is deprecated */
109 #define RDS_INFO_SEND_MESSAGES		10003
110 #define RDS_INFO_RETRANS_MESSAGES       10004
111 #define RDS_INFO_RECV_MESSAGES          10005
112 #define RDS_INFO_SOCKETS                10006
113 #define RDS_INFO_TCP_SOCKETS            10007
114 #define RDS_INFO_IB_CONNECTIONS		10008
115 #define RDS_INFO_CONNECTION_STATS	10009
116 #define RDS_INFO_IWARP_CONNECTIONS	10010
117 #define RDS_INFO_LAST			10010
118 
119 struct rds_info_counter {
120 	uint8_t	name[32];
121 	uint64_t	value;
122 } __attribute__((packed));
123 
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 
128 #define TRANSNAMSIZ	16
129 
130 struct rds_info_connection {
131 	uint64_t	next_tx_seq;
132 	uint64_t	next_rx_seq;
133 	__be32		laddr;
134 	__be32		faddr;
135 	uint8_t	transport[TRANSNAMSIZ];		/* null term ascii */
136 	uint8_t	flags;
137 } __attribute__((packed));
138 
139 #define RDS_INFO_MESSAGE_FLAG_ACK               0x01
140 #define RDS_INFO_MESSAGE_FLAG_FAST_ACK          0x02
141 
142 struct rds_info_message {
143 	uint64_t	seq;
144 	uint32_t	len;
145 	__be32		laddr;
146 	__be32		faddr;
147 	__be16		lport;
148 	__be16		fport;
149 	uint8_t	flags;
150 } __attribute__((packed));
151 
152 struct rds_info_socket {
153 	uint32_t	sndbuf;
154 	__be32		bound_addr;
155 	__be32		connected_addr;
156 	__be16		bound_port;
157 	__be16		connected_port;
158 	uint32_t	rcvbuf;
159 	uint64_t	inum;
160 } __attribute__((packed));
161 
162 struct rds_info_tcp_socket {
163 	__be32          local_addr;
164 	__be16          local_port;
165 	__be32          peer_addr;
166 	__be16          peer_port;
167 	uint64_t       hdr_rem;
168 	uint64_t       data_rem;
169 	uint32_t       last_sent_nxt;
170 	uint32_t       last_expected_una;
171 	uint32_t       last_seen_una;
172 } __attribute__((packed));
173 
174 #define RDS_IB_GID_LEN	16
175 struct rds_info_rdma_connection {
176 	__be32		src_addr;
177 	__be32		dst_addr;
178 	uint8_t		src_gid[RDS_IB_GID_LEN];
179 	uint8_t		dst_gid[RDS_IB_GID_LEN];
180 
181 	uint32_t	max_send_wr;
182 	uint32_t	max_recv_wr;
183 	uint32_t	max_send_sge;
184 	uint32_t	rdma_mr_max;
185 	uint32_t	rdma_mr_size;
186 };
187 
188 /* RDS message Receive Path Latency points */
189 enum rds_message_rxpath_latency {
190 	RDS_MSG_RX_HDR_TO_DGRAM_START = 0,
191 	RDS_MSG_RX_DGRAM_REASSEMBLE,
192 	RDS_MSG_RX_DGRAM_DELIVERED,
193 	RDS_MSG_RX_DGRAM_TRACE_MAX
194 };
195 
196 struct rds_rx_trace_so {
197 	u8 rx_traces;
198 	u8 rx_trace_pos[RDS_MSG_RX_DGRAM_TRACE_MAX];
199 };
200 
201 struct rds_cmsg_rx_trace {
202 	u8 rx_traces;
203 	u8 rx_trace_pos[RDS_MSG_RX_DGRAM_TRACE_MAX];
204 	u64 rx_trace[RDS_MSG_RX_DGRAM_TRACE_MAX];
205 };
206 
207 /*
208  * Congestion monitoring.
209  * Congestion control in RDS happens at the host connection
210  * level by exchanging a bitmap marking congested ports.
211  * By default, a process sleeping in poll() is always woken
212  * up when the congestion map is updated.
213  * With explicit monitoring, an application can have more
214  * fine-grained control.
215  * The application installs a 64bit mask value in the socket,
216  * where each bit corresponds to a group of ports.
217  * When a congestion update arrives, RDS checks the set of
218  * ports that are now uncongested against the list bit mask
219  * installed in the socket, and if they overlap, we queue a
220  * cong_notification on the socket.
221  *
222  * To install the congestion monitor bitmask, use RDS_CONG_MONITOR
223  * with the 64bit mask.
224  * Congestion updates are received via RDS_CMSG_CONG_UPDATE
225  * control messages.
226  *
227  * The correspondence between bits and ports is
228  *	1 << (portnum % 64)
229  */
230 #define RDS_CONG_MONITOR_SIZE	64
231 #define RDS_CONG_MONITOR_BIT(port)  (((unsigned int) port) % RDS_CONG_MONITOR_SIZE)
232 #define RDS_CONG_MONITOR_MASK(port) (1ULL << RDS_CONG_MONITOR_BIT(port))
233 
234 /*
235  * RDMA related types
236  */
237 
238 /*
239  * This encapsulates a remote memory location.
240  * In the current implementation, it contains the R_Key
241  * of the remote memory region, and the offset into it
242  * (so that the application does not have to worry about
243  * alignment).
244  */
245 typedef uint64_t	rds_rdma_cookie_t;
246 
247 struct rds_iovec {
248 	uint64_t	addr;
249 	uint64_t	bytes;
250 };
251 
252 struct rds_get_mr_args {
253 	struct rds_iovec vec;
254 	uint64_t	cookie_addr;
255 	uint64_t	flags;
256 };
257 
258 struct rds_get_mr_for_dest_args {
259 	struct sockaddr_storage	dest_addr;
260 	struct rds_iovec 	vec;
261 	uint64_t		cookie_addr;
262 	uint64_t		flags;
263 };
264 
265 struct rds_free_mr_args {
266 	rds_rdma_cookie_t cookie;
267 	uint64_t	flags;
268 };
269 
270 struct rds_rdma_args {
271 	rds_rdma_cookie_t cookie;
272 	struct rds_iovec remote_vec;
273 	uint64_t	local_vec_addr;
274 	uint64_t	nr_local;
275 	uint64_t	flags;
276 	uint64_t	user_token;
277 };
278 
279 struct rds_atomic_args {
280 	rds_rdma_cookie_t cookie;
281 	uint64_t 	local_addr;
282 	uint64_t 	remote_addr;
283 	union {
284 		struct {
285 			uint64_t	compare;
286 			uint64_t	swap;
287 		} cswp;
288 		struct {
289 			uint64_t	add;
290 		} fadd;
291 		struct {
292 			uint64_t	compare;
293 			uint64_t	swap;
294 			uint64_t	compare_mask;
295 			uint64_t	swap_mask;
296 		} m_cswp;
297 		struct {
298 			uint64_t	add;
299 			uint64_t	nocarry_mask;
300 		} m_fadd;
301 	};
302 	uint64_t	flags;
303 	uint64_t	user_token;
304 };
305 
306 struct rds_rdma_notify {
307 	uint64_t	user_token;
308 	int32_t		status;
309 };
310 
311 #define RDS_RDMA_SUCCESS	0
312 #define RDS_RDMA_REMOTE_ERROR	1
313 #define RDS_RDMA_CANCELED	2
314 #define RDS_RDMA_DROPPED	3
315 #define RDS_RDMA_OTHER_ERROR	4
316 
317 /*
318  * Common set of flags for all RDMA related structs
319  */
320 #define RDS_RDMA_READWRITE	0x0001
321 #define RDS_RDMA_FENCE		0x0002	/* use FENCE for immediate send */
322 #define RDS_RDMA_INVALIDATE	0x0004	/* invalidate R_Key after freeing MR */
323 #define RDS_RDMA_USE_ONCE	0x0008	/* free MR after use */
324 #define RDS_RDMA_DONTWAIT	0x0010	/* Don't wait in SET_BARRIER */
325 #define RDS_RDMA_NOTIFY_ME	0x0020	/* Notify when operation completes */
326 #define RDS_RDMA_SILENT		0x0040	/* Do not interrupt remote */
327 
328 #endif /* IB_RDS_H */
329