xref: /freebsd/sys/ofed/include/rdma/iw_cm.h (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3  *
4  * Copyright (c) 2005 Network Appliance, Inc. All rights reserved.
5  * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
6  *
7  * This software is available to you under a choice of one of two
8  * licenses.  You may choose to be licensed under the terms of the GNU
9  * General Public License (GPL) Version 2, available from the file
10  * COPYING in the main directory of this source tree, or the
11  * OpenIB.org BSD license below:
12  *
13  *     Redistribution and use in source and binary forms, with or
14  *     without modification, are permitted provided that the following
15  *     conditions are met:
16  *
17  *      - Redistributions of source code must retain the above
18  *        copyright notice, this list of conditions and the following
19  *        disclaimer.
20  *
21  *      - Redistributions in binary form must reproduce the above
22  *        copyright notice, this list of conditions and the following
23  *        disclaimer in the documentation and/or other materials
24  *        provided with the distribution.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33  * SOFTWARE.
34  *
35  * $FreeBSD$
36  */
37 
38 #ifndef IW_CM_H
39 #define IW_CM_H
40 
41 #include <linux/in.h>
42 #include <rdma/ib_cm.h>
43 
44 struct iw_cm_id;
45 
46 enum iw_cm_event_type {
47 	IW_CM_EVENT_CONNECT_REQUEST = 1, /* connect request received */
48 	IW_CM_EVENT_CONNECT_REPLY,	 /* reply from active connect request */
49 	IW_CM_EVENT_ESTABLISHED,	 /* passive side accept successful */
50 	IW_CM_EVENT_DISCONNECT,		 /* orderly shutdown */
51 	IW_CM_EVENT_CLOSE		 /* close complete */
52 };
53 
54 struct iw_cm_event {
55 	enum iw_cm_event_type event;
56 	int			 status;
57 	struct sockaddr_storage local_addr;
58 	struct sockaddr_storage remote_addr;
59 	void *private_data;
60 	void *provider_data;
61 	u8 private_data_len;
62 	u8 ord;
63 	u8 ird;
64 };
65 
66 /**
67  * iw_cm_handler - Function to be called by the IW CM when delivering events
68  * to the client.
69  *
70  * @cm_id: The IW CM identifier associated with the event.
71  * @event: Pointer to the event structure.
72  */
73 typedef int (*iw_cm_handler)(struct iw_cm_id *cm_id,
74 			     struct iw_cm_event *event);
75 
76 /**
77  * iw_event_handler - Function called by the provider when delivering provider
78  * events to the IW CM.  Returns either 0 indicating the event was processed
79  * or -errno if the event could not be processed.
80  *
81  * @cm_id: The IW CM identifier associated with the event.
82  * @event: Pointer to the event structure.
83  */
84 typedef int (*iw_event_handler)(struct iw_cm_id *cm_id,
85 				 struct iw_cm_event *event);
86 
87 struct iw_cm_id {
88 	iw_cm_handler		cm_handler;      /* client callback function */
89 	void		        *context;	 /* client cb context */
90 	struct ib_device	*device;
91 	struct sockaddr_storage local_addr;      /* local addr */
92 	struct sockaddr_storage	remote_addr;
93 	struct sockaddr_storage m_local_addr;	 /* nmapped local addr */
94 	struct sockaddr_storage	m_remote_addr;	 /* nmapped rem addr */
95 	void			*provider_data;	 /* provider private data */
96 	iw_event_handler        event_handler;   /* cb for provider
97 						    events */
98 	/* Used by provider to add and remove refs on IW cm_id */
99 	void (*add_ref)(struct iw_cm_id *);
100 	void (*rem_ref)(struct iw_cm_id *);
101 	u8  tos;
102 };
103 
104 struct iw_cm_conn_param {
105 	const void *private_data;
106 	u16 private_data_len;
107 	u32 ord;
108 	u32 ird;
109 	u32 qpn;
110 };
111 
112 struct iw_cm_verbs {
113 	void		(*add_ref)(struct ib_qp *qp);
114 
115 	void		(*rem_ref)(struct ib_qp *qp);
116 
117 	struct ib_qp *	(*get_qp)(struct ib_device *device,
118 				  int qpn);
119 
120 	int		(*connect)(struct iw_cm_id *cm_id,
121 				   struct iw_cm_conn_param *conn_param);
122 
123 	int		(*accept)(struct iw_cm_id *cm_id,
124 				  struct iw_cm_conn_param *conn_param);
125 
126 	int		(*reject)(struct iw_cm_id *cm_id,
127 				  const void *pdata, u8 pdata_len);
128 
129 	int		(*create_listen)(struct iw_cm_id *cm_id,
130 					 int backlog);
131 
132 	int		(*destroy_listen)(struct iw_cm_id *cm_id);
133 	char		ifname[IFNAMSIZ];
134 };
135 
136 /**
137  * iw_create_cm_id - Create an IW CM identifier.
138  *
139  * @device: The IB device on which to create the IW CM identier.
140  * @event_handler: User callback invoked to report events associated with the
141  *   returned IW CM identifier.
142  * @context: User specified context associated with the id.
143  */
144 struct iw_cm_id *iw_create_cm_id(struct ib_device *device,
145 				 iw_cm_handler cm_handler, void *context);
146 
147 /**
148  * iw_destroy_cm_id - Destroy an IW CM identifier.
149  *
150  * @cm_id: The previously created IW CM identifier to destroy.
151  *
152  * The client can assume that no events will be delivered for the CM ID after
153  * this function returns.
154  */
155 void iw_destroy_cm_id(struct iw_cm_id *cm_id);
156 
157 /**
158  * iw_cm_bind_qp - Unbind the specified IW CM identifier and QP
159  *
160  * @cm_id: The IW CM idenfier to unbind from the QP.
161  * @qp: The QP
162  *
163  * This is called by the provider when destroying the QP to ensure
164  * that any references held by the IWCM are released. It may also
165  * be called by the IWCM when destroying a CM_ID to that any
166  * references held by the provider are released.
167  */
168 void iw_cm_unbind_qp(struct iw_cm_id *cm_id, struct ib_qp *qp);
169 
170 /**
171  * iw_cm_get_qp - Return the ib_qp associated with a QPN
172  *
173  * @ib_device: The IB device
174  * @qpn: The queue pair number
175  */
176 struct ib_qp *iw_cm_get_qp(struct ib_device *device, int qpn);
177 
178 /**
179  * iw_cm_listen - Listen for incoming connection requests on the
180  * specified IW CM id.
181  *
182  * @cm_id: The IW CM identifier.
183  * @backlog: The maximum number of outstanding un-accepted inbound listen
184  *   requests to queue.
185  *
186  * The source address and port number are specified in the IW CM identifier
187  * structure.
188  */
189 int iw_cm_listen(struct iw_cm_id *cm_id, int backlog);
190 
191 /**
192  * iw_cm_accept - Called to accept an incoming connect request.
193  *
194  * @cm_id: The IW CM identifier associated with the connection request.
195  * @iw_param: Pointer to a structure containing connection establishment
196  *   parameters.
197  *
198  * The specified cm_id will have been provided in the event data for a
199  * CONNECT_REQUEST event. Subsequent events related to this connection will be
200  * delivered to the specified IW CM identifier prior and may occur prior to
201  * the return of this function. If this function returns a non-zero value, the
202  * client can assume that no events will be delivered to the specified IW CM
203  * identifier.
204  */
205 int iw_cm_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param);
206 
207 /**
208  * iw_cm_reject - Reject an incoming connection request.
209  *
210  * @cm_id: Connection identifier associated with the request.
211  * @private_daa: Pointer to data to deliver to the remote peer as part of the
212  *   reject message.
213  * @private_data_len: The number of bytes in the private_data parameter.
214  *
215  * The client can assume that no events will be delivered to the specified IW
216  * CM identifier following the return of this function. The private_data
217  * buffer is available for reuse when this function returns.
218  */
219 int iw_cm_reject(struct iw_cm_id *cm_id, const void *private_data,
220 		 u8 private_data_len);
221 
222 /**
223  * iw_cm_connect - Called to request a connection to a remote peer.
224  *
225  * @cm_id: The IW CM identifier for the connection.
226  * @iw_param: Pointer to a structure containing connection  establishment
227  *   parameters.
228  *
229  * Events may be delivered to the specified IW CM identifier prior to the
230  * return of this function. If this function returns a non-zero value, the
231  * client can assume that no events will be delivered to the specified IW CM
232  * identifier.
233  */
234 int iw_cm_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param);
235 
236 /**
237  * iw_cm_disconnect - Close the specified connection.
238  *
239  * @cm_id: The IW CM identifier to close.
240  * @abrupt: If 0, the connection will be closed gracefully, otherwise, the
241  *   connection will be reset.
242  *
243  * The IW CM identifier is still active until the IW_CM_EVENT_CLOSE event is
244  * delivered.
245  */
246 int iw_cm_disconnect(struct iw_cm_id *cm_id, int abrupt);
247 
248 /**
249  * iw_cm_init_qp_attr - Called to initialize the attributes of the QP
250  * associated with a IW CM identifier.
251  *
252  * @cm_id: The IW CM identifier associated with the QP
253  * @qp_attr: Pointer to the QP attributes structure.
254  * @qp_attr_mask: Pointer to a bit vector specifying which QP attributes are
255  *   valid.
256  */
257 int iw_cm_init_qp_attr(struct iw_cm_id *cm_id, struct ib_qp_attr *qp_attr,
258 		       int *qp_attr_mask);
259 
260 #endif /* IW_CM_H */
261