xref: /illumos-gate/usr/src/uts/common/sys/rds.h (revision 7417cfde)
1 /*
2  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3  */
4 
5 /*
6  * This file contains definitions used in OFED defined user/kernel
7  * interfaces. These are imported from the OFED header <linux/rds.h>. Oracle
8  * elects to have and use the contents of <linux/rds.h> under and governed
9  * by the OpenIB.org BSD license (see below for full license text). However,
10  * the following notice accompanied the original version of this file:
11  */
12 
13 /*
14  * Copyright (c) 2008 Oracle.  All rights reserved.
15  *
16  * This software is available to you under a choice of one of two
17  * licenses.  You may choose to be licensed under the terms of the GNU
18  * General Public License (GPL) Version 2, available from the file
19  * COPYING in the main directory of this source tree, or the
20  * OpenIB.org BSD license below:
21  *
22  *     Redistribution and use in source and binary forms, with or
23  *     without modification, are permitted provided that the following
24  *     conditions are met:
25  *
26  *      - Redistributions of source code must retain the above
27  *        copyright notice, this list of conditions and the following
28  *        disclaimer.
29  *
30  *      - Redistributions in binary form must reproduce the above
31  *        copyright notice, this list of conditions and the following
32  *        disclaimer in the documentation and/or other materials
33  *        provided with the distribution.
34  *
35  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
36  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
38  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
39  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
40  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
41  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
42  * SOFTWARE.
43  *
44  */
45 
46 /*
47  * Include this file if the application uses rdsv3 sockets.
48  */
49 
50 /*
51  * This file contains definitions from the ofed rds.h and rds_rdma.h
52  * header file.
53  */
54 #ifndef _RDSV3_RDS_H
55 #define	_RDSV3_RDS_H
56 
57 #include <sys/types.h>
58 #include <sys/socket.h>
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 #define	RDS_IB_ABI_VERSION		0x301
65 
66 #define	AF_RDS				AF_INET_OFFLOAD
67 #define	PF_RDS				AF_INET_OFFLOAD
68 
69 #define	SOL_RDS				272
70 
71 /*
72  * setsockopt/getsockopt for SOL_RDS
73  */
74 #define	RDSV3_CANCEL_SENT_TO		1
75 #define	RDSV3_GET_MR			2
76 #define	RDSV3_FREE_MR			3
77 /* deprecated: RDS_BARRIER 4 */
78 #define	RDSV3_RECVERR			5
79 #define	RDSV3_CONG_MONITOR		6
80 #define	RDSV3_GET_MR_FOR_DEST		7
81 
82 /*
83  * Control message types for SOL_RDS.
84  *
85  * RDS_CMSG_RDMA_ARGS (sendmsg)
86  *	Request a RDMA transfer to/from the specified
87  *	memory ranges.
88  *	The cmsg_data is a struct rdsv3_rdma_args.
89  * RDS_CMSG_RDMA_DEST (recvmsg, sendmsg)
90  *	Kernel informs application about intended
91  *	source/destination of a RDMA transfer
92  * RDS_CMSG_RDMA_MAP (sendmsg)
93  *	Application asks kernel to map the given
94  *	memory range into a IB MR, and send the
95  *	R_Key along in an RDS extension header.
96  *	The cmsg_data is a struct rdsv3_get_mr_args,
97  *	the same as for the GET_MR setsockopt.
98  * RDS_CMSG_RDMA_STATUS (recvmsg)
99  *	Returns the status of a completed RDMA operation.
100  */
101 #define	RDSV3_CMSG_RDMA_ARGS		1
102 #define	RDSV3_CMSG_RDMA_DEST		2
103 #define	RDSV3_CMSG_RDMA_MAP		3
104 #define	RDSV3_CMSG_RDMA_STATUS		4
105 #define	RDSV3_CMSG_CONG_UPDATE		5
106 
107 /* rds-info related */
108 
109 #define	RDSV3_INFO_FIRST		10000
110 #define	RDSV3_INFO_COUNTERS		10000
111 #define	RDSV3_INFO_CONNECTIONS		10001
112 /* 10002 aka RDS_INFO_FLOWS is deprecated */
113 #define	RDSV3_INFO_SEND_MESSAGES	10003
114 #define	RDSV3_INFO_RETRANS_MESSAGES	10004
115 #define	RDSV3_INFO_RECV_MESSAGES	10005
116 #define	RDSV3_INFO_SOCKETS		10006
117 #define	RDSV3_INFO_TCP_SOCKETS		10007
118 #define	RDSV3_INFO_IB_CONNECTIONS	10008
119 #define	RDSV3_INFO_CONNECTION_STATS	10009
120 #define	RDSV3_INFO_IWARP_CONNECTIONS	10010
121 #define	RDSV3_INFO_LAST			10010
122 
123 struct rds_info_arg {
124 	uint64_t	lenp;
125 	uint64_t	datap;
126 };
127 
128 #ifndef __lock_lint
129 #pragma pack(1)
130 struct rdsv3_info_counter {
131 	uint8_t	name[32];
132 	uint64_t	value;
133 } __attribute__((packed));
134 #pragma pack()
135 #else
136 struct rdsv3_info_counter {
137 	uint8_t	name[32];
138 	uint64_t	value;
139 };
140 #endif
141 
142 #define	RDSV3_INFO_CONNECTION_FLAG_SENDING	0x01
143 #define	RDSV3_INFO_CONNECTION_FLAG_CONNECTING	0x02
144 #define	RDSV3_INFO_CONNECTION_FLAG_CONNECTED	0x04
145 
146 #define	TRANSNAMSIZ	16
147 
148 #ifndef __lock_lint
149 #pragma pack(1)
150 struct rdsv3_info_connection {
151 	uint64_t	next_tx_seq;
152 	uint64_t	next_rx_seq;
153 	uint32_t	laddr;			/* network order */
154 	uint32_t	faddr;			/* network order */
155 	uint8_t		transport[15];		/* null term ascii */
156 	uint8_t		flags;
157 } __attribute__((packed));
158 #pragma pack()
159 #else
160 struct rdsv3_info_connection {
161 	uint64_t	next_tx_seq;
162 	uint64_t	next_rx_seq;
163 	uint32_t	laddr;			/* network order */
164 	uint32_t	faddr;			/* network order */
165 	uint8_t		transport[15];		/* null term ascii */
166 	uint8_t		flags;
167 };
168 #endif
169 
170 #ifndef __lock_lint
171 #pragma pack(1)
172 struct rdsv3_info_flow {
173 	uint32_t	laddr;			/* network order */
174 	uint32_t	faddr;			/* network order */
175 	uint32_t	bytes;
176 	uint16_t	lport;			/* network order */
177 	uint16_t	fport;			/* network order */
178 } __attribute__((packed));
179 #pragma pack()
180 #else
181 struct rdsv3_info_flow {
182 	uint32_t	laddr;			/* network order */
183 	uint32_t	faddr;			/* network order */
184 	uint32_t	bytes;
185 	uint16_t	lport;			/* network order */
186 	uint16_t	fport;			/* network order */
187 };
188 #endif
189 
190 #define	RDSV3_INFO_MESSAGE_FLAG_ACK		0x01
191 #define	RDSV3_INFO_MESSAGE_FLAG_FAST_ACK	0x02
192 
193 #ifndef __lock_lint
194 #pragma pack(1)
195 struct rdsv3_info_message {
196 	uint64_t	seq;
197 	uint32_t	len;
198 	uint32_t	laddr;			/* network order */
199 	uint32_t	faddr;			/* network order */
200 	uint16_t	lport;			/* network order */
201 	uint16_t	fport;			/* network order */
202 	uint8_t		flags;
203 } __attribute__((packed));
204 #pragma pack()
205 #else
206 struct rdsv3_info_message {
207 	uint64_t	seq;
208 	uint32_t	len;
209 	uint32_t	laddr;			/* network order */
210 	uint32_t	faddr;			/* network order */
211 	uint16_t	lport;			/* network order */
212 	uint16_t	fport;			/* network order */
213 	uint8_t		flags;
214 };
215 #endif
216 
217 #ifndef __lock_lint
218 #pragma pack(1)
219 struct rdsv3_info_socket {
220 	uint32_t	sndbuf;
221 	uint32_t	bound_addr;		/* network order */
222 	uint32_t	connected_addr;		/* network order */
223 	uint16_t	bound_port;		/* network order */
224 	uint16_t	connected_port;		/* network order */
225 	uint32_t	rcvbuf;
226 	uint64_t	inum;
227 } __attribute__((packed));
228 #pragma pack()
229 #else
230 struct rdsv3_info_socket {
231 	uint32_t	sndbuf;
232 	uint32_t	bound_addr;		/* network order */
233 	uint32_t	connected_addr;		/* network order */
234 	uint16_t	bound_port;		/* network order */
235 	uint16_t	connected_port;		/* network order */
236 	uint32_t	rcvbuf;
237 	uint64_t	inum;
238 };
239 #endif
240 
241 #ifndef __lock_lint
242 #pragma pack(1)
243 struct rdsv3_info_socket_v1 {
244 	uint32_t	sndbuf;
245 	uint32_t	bound_addr;		/* network order */
246 	uint32_t	connected_addr;		/* network order */
247 	uint16_t	bound_port;		/* network order */
248 	uint16_t	connected_port;		/* network order */
249 	uint32_t	rcvbuf;
250 } __attribute__((packed));
251 #pragma pack()
252 #else
253 struct rdsv3_info_socket_v1 {
254 	uint32_t	sndbuf;
255 	uint32_t	bound_addr;		/* network order */
256 	uint32_t	connected_addr;		/* network order */
257 	uint16_t	bound_port;		/* network order */
258 	uint16_t	connected_port;		/* network order */
259 	uint32_t	rcvbuf;
260 };
261 #endif
262 
263 #define	RDS_IB_GID_LEN	16
264 struct rdsv3_info_rdma_connection {
265 	uint32_t	src_addr;		/* network order */
266 	uint32_t	dst_addr;		/* network order */
267 	uint8_t		src_gid[RDS_IB_GID_LEN];
268 	uint8_t		dst_gid[RDS_IB_GID_LEN];
269 
270 	uint32_t	max_send_wr;
271 	uint32_t	max_recv_wr;
272 	uint32_t	max_send_sge;
273 	uint32_t	rdma_mr_max;
274 	uint32_t	rdma_mr_size;
275 };
276 
277 #define	rdsv3_info_ib_connection rdsv3_info_rdma_connection
278 #define	rdma_fmr_max rdma_mr_max
279 #define	rdma_fmr_size rdma_mr_size
280 
281 /*
282  * Congestion monitoring.
283  * Congestion control in RDS happens at the host connection
284  * level by exchanging a bitmap marking congested ports.
285  * By default, a process sleeping in poll() is always woken
286  * up when the congestion map is updated.
287  * With explicit monitoring, an application can have more
288  * fine-grained control.
289  * The application installs a 64bit mask value in the socket,
290  * where each bit corresponds to a group of ports.
291  * When a congestion update arrives, RDS checks the set of
292  * ports that are now uncongested against the list bit mask
293  * installed in the socket, and if they overlap, we queue a
294  * cong_notification on the socket.
295  *
296  * To install the congestion monitor bitmask, use RDS_CONG_MONITOR
297  * with the 64bit mask.
298  * Congestion updates are received via RDS_CMSG_CONG_UPDATE
299  * control messages.
300  *
301  * The correspondence between bits and ports is
302  *	1 << (portnum % 64)
303  */
304 #define	RDSV3_CONG_MONITOR_SIZE	64
305 #define	RDSV3_CONG_MONITOR_BIT(port)	\
306 	(((unsigned int) port) % RDSV3_CONG_MONITOR_SIZE)
307 #define	RDSV3_CONG_MONITOR_MASK(port) (1ULL << RDSV3_CONG_MONITOR_BIT(port))
308 
309 /*
310  * RDMA related types
311  */
312 
313 /*
314  * This encapsulates a remote memory location.
315  * In the current implementation, it contains the R_Key
316  * of the remote memory region, and the offset into it
317  * (so that the application does not have to worry about
318  * alignment).
319  */
320 typedef uint64_t	rdsv3_rdma_cookie_t;
321 
322 struct rdsv3_iovec {
323 	uint64_t	addr;
324 	uint64_t	bytes;
325 };
326 
327 struct rdsv3_get_mr_args {
328 	struct rdsv3_iovec vec;
329 	uint64_t	cookie_addr;
330 	uint64_t	flags;
331 };
332 
333 struct rdsv3_get_mr_for_dest_args {
334 	struct sockaddr_storage	dest_addr;
335 	struct rdsv3_iovec 	vec;
336 	uint64_t		cookie_addr;
337 	uint64_t		flags;
338 };
339 
340 struct rdsv3_free_mr_args {
341 	rdsv3_rdma_cookie_t cookie;
342 	uint64_t	flags;
343 };
344 
345 struct rdsv3_rdma_args {
346 	rdsv3_rdma_cookie_t cookie;
347 	struct rdsv3_iovec remote_vec;
348 	uint64_t	local_vec_addr;
349 	uint64_t	nr_local;
350 	uint64_t	flags;
351 	uint64_t	user_token;
352 };
353 
354 struct rdsv3_rdma_notify {
355 	uint64_t	user_token;
356 	int32_t		status;
357 };
358 
359 #define	RDSV3_RDMA_SUCCESS	0
360 #define	RDSV3_RDMA_REMOTE_ERROR	1
361 #define	RDSV3_RDMA_CANCELED	2
362 #define	RDSV3_RDMA_DROPPED	3
363 #define	RDSV3_RDMA_OTHER_ERROR	4
364 
365 /*
366  * Common set of flags for all RDMA related structs
367  */
368 #define	RDSV3_RDMA_READWRITE	0x0001
369 #define	RDSV3_RDMA_FENCE	0x0002	/* use FENCE for immediate send */
370 #define	RDSV3_RDMA_INVALIDATE	0x0004	/* invalidate R_Key after freeing MR */
371 #define	RDSV3_RDMA_USE_ONCE	0x0008	/* free MR after use */
372 #define	RDSV3_RDMA_DONTWAIT	0x0010	/* Don't wait in SET_BARRIER */
373 #define	RDSV3_RDMA_NOTIFY_ME	0x0020	/* Notify when operation completes */
374 
375 #ifdef	__cplusplus
376 }
377 #endif
378 
379 #endif /* _RDSV3_RDS_H */
380