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