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