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