1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /*
26  * Copyright (c) 2005 SilverStorm Technologies, Inc. All rights reserved.
27  *
28  * This software is available to you under a choice of one of two
29  * licenses.  You may choose to be licensed under the terms of the GNU
30  * General Public License (GPL) Version 2, available from the file
31  * COPYING in the main directory of this source tree, or the
32  * OpenIB.org BSD license below:
33  *
34  *     Redistribution and use in source and binary forms, with or
35  *     without modification, are permitted provided that the following
36  *     conditions are met:
37  *
38  *	- Redistributions of source code must retain the above
39  *	  copyright notice, this list of conditions and the following
40  *	  disclaimer.
41  *
42  *	- Redistributions in binary form must reproduce the above
43  *	  copyright notice, this list of conditions and the following
44  *	  disclaimer in the documentation and/or other materials
45  *	  provided with the distribution.
46  *
47  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
51  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
52  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
53  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
54  * SOFTWARE.
55  *
56  */
57 /*
58  * Sun elects to include this software in Sun product
59  * under the OpenIB BSD license.
60  *
61  *
62  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
63  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
66  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
67  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
68  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
69  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
70  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
71  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
72  * POSSIBILITY OF SUCH DAMAGE.
73  */
74 
75 #ifndef _RDSIB_PROTOCOL_H
76 #define	_RDSIB_PROTOCOL_H
77 
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81 
82 #include <netinet/in.h>
83 
84 #define	RDS_VERSION	4
85 
86 /*
87  * RDS Well known service id
88  * Format: 0x1h00144Fhhhhhhhh
89  *         "00144F" is the Sun OUI
90  * 'h' can be any hex-decimal digit.
91  */
92 #define	RDS_SERVICE_ID		0x1000144F00000001ULL
93 
94 /* Max number of nodes supported with the default configuration */
95 #define	RDS_MAX_NODES	8
96 
97 /* packet size */
98 #define	RDS_USER_DATA_BUFFER_SIZE	4096 /* 4K */
99 
100 /* per session */
101 #define	RDS_MAX_DATA_RECV_BUFFERS	3000
102 #define	RDS_MAX_DATA_SEND_BUFFERS	2000
103 #define	RDS_MAX_CTRL_RECV_BUFFERS	100
104 #define	RDS_MAX_CTRL_SEND_BUFFERS	50
105 
106 /* RQ low water mark in percentage. More RWR have to be posted */
107 #define	RDS_DATA_RECV_BUFFER_LWM	90
108 #define	RDS_CTRL_RECV_BUFFER_LWM	50
109 
110 /*
111  * High water mark in percentage of pkts pending on sockets.
112  * Incoming traffic should be controlled or stopped for all sockets
113  * or some sockets that are above their quota
114  */
115 #define	RDS_PENDING_RX_PKTS_HWM	75
116 
117 /*
118  * Only interoperate with homogeneous Solaris (x32, x64, sparcv9).
119  */
120 #if defined(__sparcv9)
121 #define	RDS_THIS_ARCH	1
122 #elif defined(__amd64)
123 #define	RDS_THIS_ARCH	2
124 #elif defined(__i386)
125 #define	RDS_THIS_ARCH	3
126 #else
127 #error "ISA not supported"
128 #endif
129 
130 /*
131  * CM Private Data
132  *
133  * This data is sent with the CM REQ message by the initiater of the
134  * RC channel.
135  *
136  * cm_ip_pvt - ibt_ip_cm_info_t
137  * version - RDS version
138  * arch - only interoperate with homogeneous Solaris (x32, x64, sparcv9).
139  * eptype - RDS_EP_TYPE_CTRL or RDS_EP_TYPE_DATA
140  * failover - flag to indicate failover.
141  * last_bufid - used during failover, indicates the last buffer the remote
142  *     received.
143  * user_buffer_size - Packet size on the sending node. This is also the size
144  *     of the SGL buffer used in the send and receive WRs. This should be
145  *     same size on the both active and passive nodes.
146  * ack_rkey - RKEY for the RDMA acknowledgement buffer.
147  * ack_addr - Registered MR address to receive RDMA acknowledgement.
148  */
149 typedef struct rds_cm_private_data_s {
150 	uint8_t		cmp_ip_pvt[IBT_IP_HDR_PRIV_DATA_SZ];
151 	uint8_t		cmp_version;
152 	uint8_t		cmp_arch;
153 	uint8_t		cmp_eptype;
154 	uint8_t		cmp_failover;
155 	uintptr_t	cmp_last_bufid;
156 	uint32_t	cmp_user_buffer_size;
157 	ibt_rkey_t	cmp_ack_rkey;
158 	uintptr_t	cmp_ack_addr;
159 } rds_cm_private_data_t;
160 
161 /*
162  * Data Header
163  * This header is transmitted with every WR.
164  *
165  * bufid - Ponter to the send buffer that is used to send this packet.
166  * datalen - Number of bytes of data (not including the header)
167  * npkts - number of remaining pkts(including this one) for the message.
168  *         It is set to 1 for single packet messages.
169  * psn - Packet sequence number(starts at 0). Zero for single packet messages.
170  * sendport - Port number of the sending socket
171  * recvport - Port number of the receiving socket
172  */
173 typedef struct rds_data_hdr_s {
174 	uintptr_t		dh_bufid;
175 	uint32_t		dh_datalen;
176 	uint32_t		dh_npkts;
177 	uint32_t		dh_psn;
178 	in_port_t		dh_sendport;
179 	in_port_t		dh_recvport;
180 } rds_data_hdr_t;
181 
182 #define	RDS_DATA_HDR_SZ		sizeof (rds_data_hdr_t)
183 
184 /*
185  * List of control commands sent on a session:
186  *
187  * STALL: This command is sent to inform remote RDS that a port is stalled.
188  *	  Always sent on all existing sessions.
189  * UNSTALL: This command is sent to inform remote RDS that a port is unstalled.
190  *	  Always sent on all existing sessions.
191  * STALL_PORTS: Inform remote RDS that all local ports are stalled.
192  * UNSTALL_PORTS: Inform remote RDS that all local ports are unstalled.
193  * HEARTBEAT: Sent to check if the connection is still alive
194  */
195 #define	RDS_CTRL_CODE_STALL		1
196 #define	RDS_CTRL_CODE_UNSTALL		2
197 #define	RDS_CTRL_CODE_STALL_PORTS	3
198 #define	RDS_CTRL_CODE_UNSTALL_PORTS	4
199 #define	RDS_CTRL_CODE_HEARTBEAT		5
200 #define	RDS_CTRL_CODE_CLOSE_SESSION	6
201 
202 /*
203  * RDS ctrl packet
204  *
205  * port - Socket to be stalled/unstalled
206  * code - STALL/UNSTALL (other codes are currently not used)
207  */
208 
209 typedef struct rds_ctrl_pkt_s {
210 	uint16_t	rcp_port;
211 	uint8_t		rcp_code;
212 } rds_ctrl_pkt_t;
213 
214 #define	RDS_CTRLPKT_SIZE	sizeof (rds_ctrl_pkt_t)
215 
216 #ifdef __cplusplus
217 }
218 #endif
219 
220 #endif	/* _RDSIB_PROTOCOL_H */
221