blob: 5aa8a9c76aa0de04b50576180f27c87dfd6b6ac6 [file] [log] [blame]
Tom Tucker922a8e92006-08-03 16:02:40 -05001/*
2 * Copyright (c) 2005 Network Appliance, Inc. All rights reserved.
3 * Copyright (c) 2005 Open Grid Computing, Inc. 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#ifndef IW_CM_H
34#define IW_CM_H
35
36#include <linux/in.h>
37#include <rdma/ib_cm.h>
38
39struct iw_cm_id;
40
41enum iw_cm_event_type {
42 IW_CM_EVENT_CONNECT_REQUEST = 1, /* connect request received */
43 IW_CM_EVENT_CONNECT_REPLY, /* reply from active connect request */
44 IW_CM_EVENT_ESTABLISHED, /* passive side accept successful */
45 IW_CM_EVENT_DISCONNECT, /* orderly shutdown */
46 IW_CM_EVENT_CLOSE /* close complete */
47};
48
Tom Tucker922a8e92006-08-03 16:02:40 -050049struct iw_cm_event {
50 enum iw_cm_event_type event;
Roland Dreierd0c49bf2011-05-09 22:23:57 -070051 int status;
Steve Wise24d44a32013-07-04 16:10:44 +053052 struct sockaddr_storage local_addr;
53 struct sockaddr_storage remote_addr;
Tom Tucker922a8e92006-08-03 16:02:40 -050054 void *private_data;
Dotan Barak4deccd62008-07-14 23:48:44 -070055 void *provider_data;
Kumar Sanghvi3ebeebc2011-09-25 20:17:43 +053056 u8 private_data_len;
57 u8 ord;
58 u8 ird;
Tom Tucker922a8e92006-08-03 16:02:40 -050059};
60
61/**
62 * iw_cm_handler - Function to be called by the IW CM when delivering events
63 * to the client.
64 *
65 * @cm_id: The IW CM identifier associated with the event.
66 * @event: Pointer to the event structure.
67 */
68typedef int (*iw_cm_handler)(struct iw_cm_id *cm_id,
69 struct iw_cm_event *event);
70
71/**
72 * iw_event_handler - Function called by the provider when delivering provider
73 * events to the IW CM. Returns either 0 indicating the event was processed
74 * or -errno if the event could not be processed.
75 *
76 * @cm_id: The IW CM identifier associated with the event.
77 * @event: Pointer to the event structure.
78 */
79typedef int (*iw_event_handler)(struct iw_cm_id *cm_id,
80 struct iw_cm_event *event);
81
82struct iw_cm_id {
83 iw_cm_handler cm_handler; /* client callback function */
84 void *context; /* client cb context */
85 struct ib_device *device;
Faisal Latifb493d912016-02-26 09:18:00 -060086 struct sockaddr_storage local_addr; /* local addr */
Steve Wise24d44a32013-07-04 16:10:44 +053087 struct sockaddr_storage remote_addr;
Faisal Latifb493d912016-02-26 09:18:00 -060088 struct sockaddr_storage m_local_addr; /* nmapped local addr */
89 struct sockaddr_storage m_remote_addr; /* nmapped rem addr */
Tom Tucker922a8e92006-08-03 16:02:40 -050090 void *provider_data; /* provider private data */
91 iw_event_handler event_handler; /* cb for provider
92 events */
93 /* Used by provider to add and remove refs on IW cm_id */
94 void (*add_ref)(struct iw_cm_id *);
95 void (*rem_ref)(struct iw_cm_id *);
Steve Wise68cdba02015-05-18 15:27:10 -050096 u8 tos;
Steve Wise926ba192019-02-01 12:44:32 -080097 bool tos_set:1;
98 bool mapped:1;
Tom Tucker922a8e92006-08-03 16:02:40 -050099};
100
101struct iw_cm_conn_param {
102 const void *private_data;
103 u16 private_data_len;
104 u32 ord;
105 u32 ird;
106 u32 qpn;
107};
108
Steve Wiseb0bad9a2019-01-29 13:33:16 -0800109enum iw_flags {
110
111 /*
112 * This flag allows the iwcm and iwpmd to still advertise
113 * mappings but the real and mapped port numbers are the
114 * same. Further, iwpmd will not bind any user socket to
115 * reserve the port. This is required for soft iwarp
116 * to play in the port mapped iwarp space.
117 */
118 IW_F_NO_PORT_MAP = (1 << 0),
119};
120
Tom Tucker922a8e92006-08-03 16:02:40 -0500121/**
122 * iw_create_cm_id - Create an IW CM identifier.
123 *
124 * @device: The IB device on which to create the IW CM identier.
125 * @event_handler: User callback invoked to report events associated with the
126 * returned IW CM identifier.
127 * @context: User specified context associated with the id.
128 */
129struct iw_cm_id *iw_create_cm_id(struct ib_device *device,
130 iw_cm_handler cm_handler, void *context);
131
132/**
133 * iw_destroy_cm_id - Destroy an IW CM identifier.
134 *
135 * @cm_id: The previously created IW CM identifier to destroy.
136 *
137 * The client can assume that no events will be delivered for the CM ID after
138 * this function returns.
139 */
140void iw_destroy_cm_id(struct iw_cm_id *cm_id);
141
142/**
143 * iw_cm_bind_qp - Unbind the specified IW CM identifier and QP
144 *
145 * @cm_id: The IW CM idenfier to unbind from the QP.
146 * @qp: The QP
147 *
148 * This is called by the provider when destroying the QP to ensure
149 * that any references held by the IWCM are released. It may also
150 * be called by the IWCM when destroying a CM_ID to that any
151 * references held by the provider are released.
152 */
153void iw_cm_unbind_qp(struct iw_cm_id *cm_id, struct ib_qp *qp);
154
155/**
156 * iw_cm_get_qp - Return the ib_qp associated with a QPN
157 *
158 * @ib_device: The IB device
159 * @qpn: The queue pair number
160 */
161struct ib_qp *iw_cm_get_qp(struct ib_device *device, int qpn);
162
163/**
164 * iw_cm_listen - Listen for incoming connection requests on the
165 * specified IW CM id.
166 *
167 * @cm_id: The IW CM identifier.
168 * @backlog: The maximum number of outstanding un-accepted inbound listen
169 * requests to queue.
170 *
171 * The source address and port number are specified in the IW CM identifier
172 * structure.
173 */
174int iw_cm_listen(struct iw_cm_id *cm_id, int backlog);
175
176/**
177 * iw_cm_accept - Called to accept an incoming connect request.
178 *
179 * @cm_id: The IW CM identifier associated with the connection request.
180 * @iw_param: Pointer to a structure containing connection establishment
181 * parameters.
182 *
183 * The specified cm_id will have been provided in the event data for a
184 * CONNECT_REQUEST event. Subsequent events related to this connection will be
185 * delivered to the specified IW CM identifier prior and may occur prior to
186 * the return of this function. If this function returns a non-zero value, the
187 * client can assume that no events will be delivered to the specified IW CM
188 * identifier.
189 */
190int iw_cm_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param);
191
192/**
193 * iw_cm_reject - Reject an incoming connection request.
194 *
195 * @cm_id: Connection identifier associated with the request.
196 * @private_daa: Pointer to data to deliver to the remote peer as part of the
197 * reject message.
198 * @private_data_len: The number of bytes in the private_data parameter.
199 *
200 * The client can assume that no events will be delivered to the specified IW
201 * CM identifier following the return of this function. The private_data
202 * buffer is available for reuse when this function returns.
203 */
204int iw_cm_reject(struct iw_cm_id *cm_id, const void *private_data,
205 u8 private_data_len);
206
207/**
208 * iw_cm_connect - Called to request a connection to a remote peer.
209 *
210 * @cm_id: The IW CM identifier for the connection.
211 * @iw_param: Pointer to a structure containing connection establishment
212 * parameters.
213 *
214 * Events may be delivered to the specified IW CM identifier prior to the
215 * return of this function. If this function returns a non-zero value, the
216 * client can assume that no events will be delivered to the specified IW CM
217 * identifier.
218 */
219int iw_cm_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param);
220
221/**
222 * iw_cm_disconnect - Close the specified connection.
223 *
224 * @cm_id: The IW CM identifier to close.
225 * @abrupt: If 0, the connection will be closed gracefully, otherwise, the
226 * connection will be reset.
227 *
228 * The IW CM identifier is still active until the IW_CM_EVENT_CLOSE event is
229 * delivered.
230 */
231int iw_cm_disconnect(struct iw_cm_id *cm_id, int abrupt);
232
233/**
234 * iw_cm_init_qp_attr - Called to initialize the attributes of the QP
235 * associated with a IW CM identifier.
236 *
237 * @cm_id: The IW CM identifier associated with the QP
238 * @qp_attr: Pointer to the QP attributes structure.
239 * @qp_attr_mask: Pointer to a bit vector specifying which QP attributes are
240 * valid.
241 */
242int iw_cm_init_qp_attr(struct iw_cm_id *cm_id, struct ib_qp_attr *qp_attr,
243 int *qp_attr_mask);
244
Steve Wise77a5db12016-10-26 12:36:40 -0700245/**
246 * iwcm_reject_msg - return a pointer to a reject message string.
247 * @reason: Value returned in the REJECT event status field.
248 */
249const char *__attribute_const__ iwcm_reject_msg(int reason);
250
Tom Tucker922a8e92006-08-03 16:02:40 -0500251#endif /* IW_CM_H */