1219820Sjeff/*
2219820Sjeff * Copyright (c) 2004, 2005 Intel Corporation.  All rights reserved.
3219820Sjeff * Copyright (c) 2004 Topspin Corporation.  All rights reserved.
4219820Sjeff * Copyright (c) 2004 Voltaire Corporation.  All rights reserved.
5219820Sjeff * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
6219820Sjeff *
7219820Sjeff * This software is available to you under a choice of one of two
8219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
9219820Sjeff * General Public License (GPL) Version 2, available from the file
10219820Sjeff * COPYING in the main directory of this source tree, or the
11219820Sjeff * OpenIB.org BSD license below:
12219820Sjeff *
13219820Sjeff *     Redistribution and use in source and binary forms, with or
14219820Sjeff *     without modification, are permitted provided that the following
15219820Sjeff *     conditions are met:
16219820Sjeff *
17219820Sjeff *      - Redistributions of source code must retain the above
18219820Sjeff *        copyright notice, this list of conditions and the following
19219820Sjeff *        disclaimer.
20219820Sjeff *
21219820Sjeff *      - Redistributions in binary form must reproduce the above
22219820Sjeff *        copyright notice, this list of conditions and the following
23219820Sjeff *        disclaimer in the documentation and/or other materials
24219820Sjeff *        provided with the distribution.
25219820Sjeff *
26219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33219820Sjeff * SOFTWARE.
34219820Sjeff */
35219820Sjeff#if !defined(IB_CM_H)
36219820Sjeff#define IB_CM_H
37219820Sjeff
38219820Sjeff#include <rdma/ib_mad.h>
39219820Sjeff#include <rdma/ib_sa.h>
40219820Sjeff
41219820Sjeffenum ib_cm_state {
42219820Sjeff	IB_CM_IDLE,
43219820Sjeff	IB_CM_LISTEN,
44219820Sjeff	IB_CM_REQ_SENT,
45219820Sjeff	IB_CM_REQ_RCVD,
46219820Sjeff	IB_CM_MRA_REQ_SENT,
47219820Sjeff	IB_CM_MRA_REQ_RCVD,
48219820Sjeff	IB_CM_REP_SENT,
49219820Sjeff	IB_CM_REP_RCVD,
50219820Sjeff	IB_CM_MRA_REP_SENT,
51219820Sjeff	IB_CM_MRA_REP_RCVD,
52219820Sjeff	IB_CM_ESTABLISHED,
53219820Sjeff	IB_CM_DREQ_SENT,
54219820Sjeff	IB_CM_DREQ_RCVD,
55219820Sjeff	IB_CM_TIMEWAIT,
56219820Sjeff	IB_CM_SIDR_REQ_SENT,
57219820Sjeff	IB_CM_SIDR_REQ_RCVD
58219820Sjeff};
59219820Sjeff
60219820Sjeffenum ib_cm_lap_state {
61219820Sjeff	IB_CM_LAP_UNINIT,
62219820Sjeff	IB_CM_LAP_IDLE,
63219820Sjeff	IB_CM_LAP_SENT,
64219820Sjeff	IB_CM_LAP_RCVD,
65219820Sjeff	IB_CM_MRA_LAP_SENT,
66219820Sjeff	IB_CM_MRA_LAP_RCVD,
67219820Sjeff};
68219820Sjeff
69219820Sjeffenum ib_cm_event_type {
70219820Sjeff	IB_CM_REQ_ERROR,
71219820Sjeff	IB_CM_REQ_RECEIVED,
72219820Sjeff	IB_CM_REP_ERROR,
73219820Sjeff	IB_CM_REP_RECEIVED,
74219820Sjeff	IB_CM_RTU_RECEIVED,
75219820Sjeff	IB_CM_USER_ESTABLISHED,
76219820Sjeff	IB_CM_DREQ_ERROR,
77219820Sjeff	IB_CM_DREQ_RECEIVED,
78219820Sjeff	IB_CM_DREP_RECEIVED,
79219820Sjeff	IB_CM_TIMEWAIT_EXIT,
80219820Sjeff	IB_CM_MRA_RECEIVED,
81219820Sjeff	IB_CM_REJ_RECEIVED,
82219820Sjeff	IB_CM_LAP_ERROR,
83219820Sjeff	IB_CM_LAP_RECEIVED,
84219820Sjeff	IB_CM_APR_RECEIVED,
85219820Sjeff	IB_CM_SIDR_REQ_ERROR,
86219820Sjeff	IB_CM_SIDR_REQ_RECEIVED,
87219820Sjeff	IB_CM_SIDR_REP_RECEIVED
88219820Sjeff};
89219820Sjeff
90219820Sjeffenum ib_cm_data_size {
91219820Sjeff	IB_CM_REQ_PRIVATE_DATA_SIZE	 = 92,
92219820Sjeff	IB_CM_MRA_PRIVATE_DATA_SIZE	 = 222,
93219820Sjeff	IB_CM_REJ_PRIVATE_DATA_SIZE	 = 148,
94219820Sjeff	IB_CM_REP_PRIVATE_DATA_SIZE	 = 196,
95219820Sjeff	IB_CM_RTU_PRIVATE_DATA_SIZE	 = 224,
96219820Sjeff	IB_CM_DREQ_PRIVATE_DATA_SIZE	 = 220,
97219820Sjeff	IB_CM_DREP_PRIVATE_DATA_SIZE	 = 224,
98219820Sjeff	IB_CM_REJ_ARI_LENGTH		 = 72,
99219820Sjeff	IB_CM_LAP_PRIVATE_DATA_SIZE	 = 168,
100219820Sjeff	IB_CM_APR_PRIVATE_DATA_SIZE	 = 148,
101219820Sjeff	IB_CM_APR_INFO_LENGTH		 = 72,
102219820Sjeff	IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE = 216,
103219820Sjeff	IB_CM_SIDR_REP_PRIVATE_DATA_SIZE = 136,
104219820Sjeff	IB_CM_SIDR_REP_INFO_LENGTH	 = 72,
105219820Sjeff	IB_CM_COMPARE_SIZE		 = 64
106219820Sjeff};
107219820Sjeff
108219820Sjeffstruct ib_cm_id;
109219820Sjeff
110219820Sjeffstruct ib_cm_req_event_param {
111219820Sjeff	struct ib_cm_id		*listen_id;
112219820Sjeff	u8			port;
113219820Sjeff
114219820Sjeff	struct ib_sa_path_rec	*primary_path;
115219820Sjeff	struct ib_sa_path_rec	*alternate_path;
116219820Sjeff
117219820Sjeff	__be64			remote_ca_guid;
118219820Sjeff	u32			remote_qkey;
119219820Sjeff	u32			remote_qpn;
120219820Sjeff	enum ib_qp_type		qp_type;
121219820Sjeff
122219820Sjeff	u32			starting_psn;
123219820Sjeff	u8			responder_resources;
124219820Sjeff	u8			initiator_depth;
125219820Sjeff	unsigned int		local_cm_response_timeout:5;
126219820Sjeff	unsigned int		flow_control:1;
127219820Sjeff	unsigned int		remote_cm_response_timeout:5;
128219820Sjeff	unsigned int		retry_count:3;
129219820Sjeff	unsigned int		rnr_retry_count:3;
130219820Sjeff	unsigned int		srq:1;
131219820Sjeff};
132219820Sjeff
133219820Sjeffstruct ib_cm_rep_event_param {
134219820Sjeff	__be64			remote_ca_guid;
135219820Sjeff	u32			remote_qkey;
136219820Sjeff	u32			remote_qpn;
137219820Sjeff	u32			starting_psn;
138219820Sjeff	u8			responder_resources;
139219820Sjeff	u8			initiator_depth;
140219820Sjeff	unsigned int		target_ack_delay:5;
141219820Sjeff	unsigned int		failover_accepted:2;
142219820Sjeff	unsigned int		flow_control:1;
143219820Sjeff	unsigned int		rnr_retry_count:3;
144219820Sjeff	unsigned int		srq:1;
145219820Sjeff};
146219820Sjeff
147219820Sjeffenum ib_cm_rej_reason {
148219820Sjeff	IB_CM_REJ_NO_QP				= 1,
149219820Sjeff	IB_CM_REJ_NO_EEC			= 2,
150219820Sjeff	IB_CM_REJ_NO_RESOURCES			= 3,
151219820Sjeff	IB_CM_REJ_TIMEOUT			= 4,
152219820Sjeff	IB_CM_REJ_UNSUPPORTED			= 5,
153219820Sjeff	IB_CM_REJ_INVALID_COMM_ID		= 6,
154219820Sjeff	IB_CM_REJ_INVALID_COMM_INSTANCE		= 7,
155219820Sjeff	IB_CM_REJ_INVALID_SERVICE_ID		= 8,
156219820Sjeff	IB_CM_REJ_INVALID_TRANSPORT_TYPE	= 9,
157219820Sjeff	IB_CM_REJ_STALE_CONN			= 10,
158219820Sjeff	IB_CM_REJ_RDC_NOT_EXIST			= 11,
159219820Sjeff	IB_CM_REJ_INVALID_GID			= 12,
160219820Sjeff	IB_CM_REJ_INVALID_LID			= 13,
161219820Sjeff	IB_CM_REJ_INVALID_SL			= 14,
162219820Sjeff	IB_CM_REJ_INVALID_TRAFFIC_CLASS		= 15,
163219820Sjeff	IB_CM_REJ_INVALID_HOP_LIMIT		= 16,
164219820Sjeff	IB_CM_REJ_INVALID_PACKET_RATE		= 17,
165219820Sjeff	IB_CM_REJ_INVALID_ALT_GID		= 18,
166219820Sjeff	IB_CM_REJ_INVALID_ALT_LID		= 19,
167219820Sjeff	IB_CM_REJ_INVALID_ALT_SL		= 20,
168219820Sjeff	IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS	= 21,
169219820Sjeff	IB_CM_REJ_INVALID_ALT_HOP_LIMIT		= 22,
170219820Sjeff	IB_CM_REJ_INVALID_ALT_PACKET_RATE	= 23,
171219820Sjeff	IB_CM_REJ_PORT_CM_REDIRECT		= 24,
172219820Sjeff	IB_CM_REJ_PORT_REDIRECT			= 25,
173219820Sjeff	IB_CM_REJ_INVALID_MTU			= 26,
174219820Sjeff	IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES	= 27,
175219820Sjeff	IB_CM_REJ_CONSUMER_DEFINED		= 28,
176219820Sjeff	IB_CM_REJ_INVALID_RNR_RETRY		= 29,
177219820Sjeff	IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID	= 30,
178219820Sjeff	IB_CM_REJ_INVALID_CLASS_VERSION		= 31,
179219820Sjeff	IB_CM_REJ_INVALID_FLOW_LABEL		= 32,
180219820Sjeff	IB_CM_REJ_INVALID_ALT_FLOW_LABEL	= 33
181219820Sjeff};
182219820Sjeff
183219820Sjeffstruct ib_cm_rej_event_param {
184219820Sjeff	enum ib_cm_rej_reason	reason;
185219820Sjeff	void			*ari;
186219820Sjeff	u8			ari_length;
187219820Sjeff};
188219820Sjeff
189219820Sjeffstruct ib_cm_mra_event_param {
190219820Sjeff	u8	service_timeout;
191219820Sjeff};
192219820Sjeff
193219820Sjeffstruct ib_cm_lap_event_param {
194219820Sjeff	struct ib_sa_path_rec	*alternate_path;
195219820Sjeff};
196219820Sjeff
197219820Sjeffenum ib_cm_apr_status {
198219820Sjeff	IB_CM_APR_SUCCESS,
199219820Sjeff	IB_CM_APR_INVALID_COMM_ID,
200219820Sjeff	IB_CM_APR_UNSUPPORTED,
201219820Sjeff	IB_CM_APR_REJECT,
202219820Sjeff	IB_CM_APR_REDIRECT,
203219820Sjeff	IB_CM_APR_IS_CURRENT,
204219820Sjeff	IB_CM_APR_INVALID_QPN_EECN,
205219820Sjeff	IB_CM_APR_INVALID_LID,
206219820Sjeff	IB_CM_APR_INVALID_GID,
207219820Sjeff	IB_CM_APR_INVALID_FLOW_LABEL,
208219820Sjeff	IB_CM_APR_INVALID_TCLASS,
209219820Sjeff	IB_CM_APR_INVALID_HOP_LIMIT,
210219820Sjeff	IB_CM_APR_INVALID_PACKET_RATE,
211219820Sjeff	IB_CM_APR_INVALID_SL
212219820Sjeff};
213219820Sjeff
214219820Sjeffstruct ib_cm_apr_event_param {
215219820Sjeff	enum ib_cm_apr_status	ap_status;
216219820Sjeff	void			*apr_info;
217219820Sjeff	u8			info_len;
218219820Sjeff};
219219820Sjeff
220219820Sjeffstruct ib_cm_sidr_req_event_param {
221219820Sjeff	struct ib_cm_id		*listen_id;
222219820Sjeff	u8			port;
223219820Sjeff	u16			pkey;
224219820Sjeff};
225219820Sjeff
226219820Sjeffenum ib_cm_sidr_status {
227219820Sjeff	IB_SIDR_SUCCESS,
228219820Sjeff	IB_SIDR_UNSUPPORTED,
229219820Sjeff	IB_SIDR_REJECT,
230219820Sjeff	IB_SIDR_NO_QP,
231219820Sjeff	IB_SIDR_REDIRECT,
232219820Sjeff	IB_SIDR_UNSUPPORTED_VERSION
233219820Sjeff};
234219820Sjeff
235219820Sjeffstruct ib_cm_sidr_rep_event_param {
236219820Sjeff	enum ib_cm_sidr_status	status;
237219820Sjeff	u32			qkey;
238219820Sjeff	u32			qpn;
239219820Sjeff	void			*info;
240219820Sjeff	u8			info_len;
241219820Sjeff};
242219820Sjeff
243219820Sjeffstruct ib_cm_event {
244219820Sjeff	enum ib_cm_event_type	event;
245219820Sjeff	union {
246219820Sjeff		struct ib_cm_req_event_param	req_rcvd;
247219820Sjeff		struct ib_cm_rep_event_param	rep_rcvd;
248219820Sjeff		/* No data for RTU received events. */
249219820Sjeff		struct ib_cm_rej_event_param	rej_rcvd;
250219820Sjeff		struct ib_cm_mra_event_param	mra_rcvd;
251219820Sjeff		struct ib_cm_lap_event_param	lap_rcvd;
252219820Sjeff		struct ib_cm_apr_event_param	apr_rcvd;
253219820Sjeff		/* No data for DREQ/DREP received events. */
254219820Sjeff		struct ib_cm_sidr_req_event_param sidr_req_rcvd;
255219820Sjeff		struct ib_cm_sidr_rep_event_param sidr_rep_rcvd;
256219820Sjeff		enum ib_wc_status		send_status;
257219820Sjeff	} param;
258219820Sjeff
259219820Sjeff	void			*private_data;
260219820Sjeff};
261219820Sjeff
262219820Sjeff/**
263219820Sjeff * ib_cm_handler - User-defined callback to process communication events.
264219820Sjeff * @cm_id: Communication identifier associated with the reported event.
265219820Sjeff * @event: Information about the communication event.
266219820Sjeff *
267219820Sjeff * IB_CM_REQ_RECEIVED and IB_CM_SIDR_REQ_RECEIVED communication events
268219820Sjeff * generated as a result of listen requests result in the allocation of a
269219820Sjeff * new @cm_id.  The new @cm_id is returned to the user through this callback.
270219820Sjeff * Clients are responsible for destroying the new @cm_id.  For peer-to-peer
271219820Sjeff * IB_CM_REQ_RECEIVED and all other events, the returned @cm_id corresponds
272219820Sjeff * to a user's existing communication identifier.
273219820Sjeff *
274219820Sjeff * Users may not call ib_destroy_cm_id while in the context of this callback;
275219820Sjeff * however, returning a non-zero value instructs the communication manager to
276219820Sjeff * destroy the @cm_id after the callback completes.
277219820Sjeff */
278219820Sjefftypedef int (*ib_cm_handler)(struct ib_cm_id *cm_id,
279219820Sjeff			     struct ib_cm_event *event);
280219820Sjeff
281219820Sjeffstruct ib_cm_id {
282219820Sjeff	ib_cm_handler		cm_handler;
283219820Sjeff	void			*context;
284219820Sjeff	struct ib_device	*device;
285219820Sjeff	__be64			service_id;
286219820Sjeff	__be64			service_mask;
287219820Sjeff	enum ib_cm_state	state;		/* internal CM/debug use */
288219820Sjeff	enum ib_cm_lap_state	lap_state;	/* internal CM/debug use */
289219820Sjeff	__be32			local_id;
290219820Sjeff	__be32			remote_id;
291219820Sjeff	u32			remote_cm_qpn;  /* 1 unless redirected */
292219820Sjeff};
293219820Sjeff
294219820Sjeff/**
295219820Sjeff * ib_create_cm_id - Allocate a communication identifier.
296219820Sjeff * @device: Device associated with the cm_id.  All related communication will
297219820Sjeff * be associated with the specified device.
298219820Sjeff * @cm_handler: Callback invoked to notify the user of CM events.
299219820Sjeff * @context: User specified context associated with the communication
300219820Sjeff *   identifier.
301219820Sjeff *
302219820Sjeff * Communication identifiers are used to track connection states, service
303219820Sjeff * ID resolution requests, and listen requests.
304219820Sjeff */
305219820Sjeffstruct ib_cm_id *ib_create_cm_id(struct ib_device *device,
306219820Sjeff				 ib_cm_handler cm_handler,
307219820Sjeff				 void *context);
308219820Sjeff
309219820Sjeff/**
310219820Sjeff * ib_destroy_cm_id - Destroy a connection identifier.
311219820Sjeff * @cm_id: Connection identifier to destroy.
312219820Sjeff *
313219820Sjeff * This call blocks until the connection identifier is destroyed.
314219820Sjeff */
315219820Sjeffvoid ib_destroy_cm_id(struct ib_cm_id *cm_id);
316219820Sjeff
317219820Sjeff#define IB_SERVICE_ID_AGN_MASK	cpu_to_be64(0xFF00000000000000ULL)
318219820Sjeff#define IB_CM_ASSIGN_SERVICE_ID	cpu_to_be64(0x0200000000000000ULL)
319219820Sjeff#define IB_CMA_SERVICE_ID	cpu_to_be64(0x0000000001000000ULL)
320219820Sjeff#define IB_CMA_SERVICE_ID_MASK	cpu_to_be64(0xFFFFFFFFFF000000ULL)
321219820Sjeff#define IB_SDP_SERVICE_ID	cpu_to_be64(0x0000000000010000ULL)
322219820Sjeff#define IB_SDP_SERVICE_ID_MASK	cpu_to_be64(0xFFFFFFFFFFFF0000ULL)
323219820Sjeff
324219820Sjeffstruct ib_cm_compare_data {
325219820Sjeff	u8  data[IB_CM_COMPARE_SIZE];
326219820Sjeff	u8  mask[IB_CM_COMPARE_SIZE];
327219820Sjeff};
328219820Sjeff
329219820Sjeff/**
330219820Sjeff * ib_cm_listen - Initiates listening on the specified service ID for
331219820Sjeff *   connection and service ID resolution requests.
332219820Sjeff * @cm_id: Connection identifier associated with the listen request.
333219820Sjeff * @service_id: Service identifier matched against incoming connection
334219820Sjeff *   and service ID resolution requests.  The service ID should be specified
335219820Sjeff *   network-byte order.  If set to IB_CM_ASSIGN_SERVICE_ID, the CM will
336219820Sjeff *   assign a service ID to the caller.
337219820Sjeff * @service_mask: Mask applied to service ID used to listen across a
338219820Sjeff *   range of service IDs.  If set to 0, the service ID is matched
339219820Sjeff *   exactly.  This parameter is ignored if %service_id is set to
340219820Sjeff *   IB_CM_ASSIGN_SERVICE_ID.
341219820Sjeff * @compare_data: This parameter is optional.  It specifies data that must
342219820Sjeff *   appear in the private data of a connection request for the specified
343219820Sjeff *   listen request.
344219820Sjeff */
345219820Sjeffint ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id, __be64 service_mask,
346219820Sjeff		 struct ib_cm_compare_data *compare_data);
347219820Sjeff
348219820Sjeffstruct ib_cm_req_param {
349219820Sjeff	struct ib_sa_path_rec	*primary_path;
350219820Sjeff	struct ib_sa_path_rec	*alternate_path;
351219820Sjeff	__be64			service_id;
352219820Sjeff	u32			qp_num;
353219820Sjeff	enum ib_qp_type		qp_type;
354219820Sjeff	u32			starting_psn;
355219820Sjeff	const void		*private_data;
356219820Sjeff	u8			private_data_len;
357219820Sjeff	u8			peer_to_peer;
358219820Sjeff	u8			responder_resources;
359219820Sjeff	u8			initiator_depth;
360219820Sjeff	u8			remote_cm_response_timeout;
361219820Sjeff	u8			flow_control;
362219820Sjeff	u8			local_cm_response_timeout;
363219820Sjeff	u8			retry_count;
364219820Sjeff	u8			rnr_retry_count;
365219820Sjeff	u8			max_cm_retries;
366219820Sjeff	u8			srq;
367219820Sjeff};
368219820Sjeff
369219820Sjeff/**
370219820Sjeff * ib_send_cm_req - Sends a connection request to the remote node.
371219820Sjeff * @cm_id: Connection identifier that will be associated with the
372219820Sjeff *   connection request.
373219820Sjeff * @param: Connection request information needed to establish the
374219820Sjeff *   connection.
375219820Sjeff */
376219820Sjeffint ib_send_cm_req(struct ib_cm_id *cm_id,
377219820Sjeff		   struct ib_cm_req_param *param);
378219820Sjeff
379219820Sjeffstruct ib_cm_rep_param {
380219820Sjeff	u32		qp_num;
381219820Sjeff	u32		starting_psn;
382219820Sjeff	const void	*private_data;
383219820Sjeff	u8		private_data_len;
384219820Sjeff	u8		responder_resources;
385219820Sjeff	u8		initiator_depth;
386219820Sjeff	u8		failover_accepted;
387219820Sjeff	u8		flow_control;
388219820Sjeff	u8		rnr_retry_count;
389219820Sjeff	u8		srq;
390219820Sjeff};
391219820Sjeff
392219820Sjeff/**
393219820Sjeff * ib_send_cm_rep - Sends a connection reply in response to a connection
394219820Sjeff *   request.
395219820Sjeff * @cm_id: Connection identifier that will be associated with the
396219820Sjeff *   connection request.
397219820Sjeff * @param: Connection reply information needed to establish the
398219820Sjeff *   connection.
399219820Sjeff */
400219820Sjeffint ib_send_cm_rep(struct ib_cm_id *cm_id,
401219820Sjeff		   struct ib_cm_rep_param *param);
402219820Sjeff
403219820Sjeff/**
404219820Sjeff * ib_send_cm_rtu - Sends a connection ready to use message in response
405219820Sjeff *   to a connection reply message.
406219820Sjeff * @cm_id: Connection identifier associated with the connection request.
407219820Sjeff * @private_data: Optional user-defined private data sent with the
408219820Sjeff *   ready to use message.
409219820Sjeff * @private_data_len: Size of the private data buffer, in bytes.
410219820Sjeff */
411219820Sjeffint ib_send_cm_rtu(struct ib_cm_id *cm_id,
412219820Sjeff		   const void *private_data,
413219820Sjeff		   u8 private_data_len);
414219820Sjeff
415219820Sjeff/**
416219820Sjeff * ib_send_cm_dreq - Sends a disconnection request for an existing
417219820Sjeff *   connection.
418219820Sjeff * @cm_id: Connection identifier associated with the connection being
419219820Sjeff *   released.
420219820Sjeff * @private_data: Optional user-defined private data sent with the
421219820Sjeff *   disconnection request message.
422219820Sjeff * @private_data_len: Size of the private data buffer, in bytes.
423219820Sjeff */
424219820Sjeffint ib_send_cm_dreq(struct ib_cm_id *cm_id,
425219820Sjeff		    const void *private_data,
426219820Sjeff		    u8 private_data_len);
427219820Sjeff
428219820Sjeff/**
429219820Sjeff * ib_send_cm_drep - Sends a disconnection reply to a disconnection request.
430219820Sjeff * @cm_id: Connection identifier associated with the connection being
431219820Sjeff *   released.
432219820Sjeff * @private_data: Optional user-defined private data sent with the
433219820Sjeff *   disconnection reply message.
434219820Sjeff * @private_data_len: Size of the private data buffer, in bytes.
435219820Sjeff *
436219820Sjeff * If the cm_id is in the correct state, the CM will transition the connection
437219820Sjeff * to the timewait state, even if an error occurs sending the DREP message.
438219820Sjeff */
439219820Sjeffint ib_send_cm_drep(struct ib_cm_id *cm_id,
440219820Sjeff		    const void *private_data,
441219820Sjeff		    u8 private_data_len);
442219820Sjeff
443219820Sjeff/**
444219820Sjeff * ib_cm_notify - Notifies the CM of an event reported to the consumer.
445219820Sjeff * @cm_id: Connection identifier to transition to established.
446219820Sjeff * @event: Type of event.
447219820Sjeff *
448219820Sjeff * This routine should be invoked by users to notify the CM of relevant
449219820Sjeff * communication events.  Events that should be reported to the CM and
450219820Sjeff * when to report them are:
451219820Sjeff *
452219820Sjeff * IB_EVENT_COMM_EST - Used when a message is received on a connected
453219820Sjeff *    QP before an RTU has been received.
454219820Sjeff * IB_EVENT_PATH_MIG - Notifies the CM that the connection has failed over
455219820Sjeff *   to the alternate path.
456219820Sjeff */
457219820Sjeffint ib_cm_notify(struct ib_cm_id *cm_id, enum ib_event_type event);
458219820Sjeff
459219820Sjeff/**
460219820Sjeff * ib_send_cm_rej - Sends a connection rejection message to the
461219820Sjeff *   remote node.
462219820Sjeff * @cm_id: Connection identifier associated with the connection being
463219820Sjeff *   rejected.
464219820Sjeff * @reason: Reason for the connection request rejection.
465219820Sjeff * @ari: Optional additional rejection information.
466219820Sjeff * @ari_length: Size of the additional rejection information, in bytes.
467219820Sjeff * @private_data: Optional user-defined private data sent with the
468219820Sjeff *   rejection message.
469219820Sjeff * @private_data_len: Size of the private data buffer, in bytes.
470219820Sjeff */
471219820Sjeffint ib_send_cm_rej(struct ib_cm_id *cm_id,
472219820Sjeff		   enum ib_cm_rej_reason reason,
473219820Sjeff		   void *ari,
474219820Sjeff		   u8 ari_length,
475219820Sjeff		   const void *private_data,
476219820Sjeff		   u8 private_data_len);
477219820Sjeff
478219820Sjeff#define IB_CM_MRA_FLAG_DELAY 0x80  /* Send MRA only after a duplicate msg */
479219820Sjeff
480219820Sjeff/**
481219820Sjeff * ib_send_cm_mra - Sends a message receipt acknowledgement to a connection
482219820Sjeff *   message.
483219820Sjeff * @cm_id: Connection identifier associated with the connection message.
484219820Sjeff * @service_timeout: The lower 5-bits specify the maximum time required for
485219820Sjeff *   the sender to reply to to the connection message.  The upper 3-bits
486219820Sjeff *   specify additional control flags.
487219820Sjeff * @private_data: Optional user-defined private data sent with the
488219820Sjeff *   message receipt acknowledgement.
489219820Sjeff * @private_data_len: Size of the private data buffer, in bytes.
490219820Sjeff */
491219820Sjeffint ib_send_cm_mra(struct ib_cm_id *cm_id,
492219820Sjeff		   u8 service_timeout,
493219820Sjeff		   const void *private_data,
494219820Sjeff		   u8 private_data_len);
495219820Sjeff
496219820Sjeff/**
497219820Sjeff * ib_send_cm_lap - Sends a load alternate path request.
498219820Sjeff * @cm_id: Connection identifier associated with the load alternate path
499219820Sjeff *   message.
500219820Sjeff * @alternate_path: A path record that identifies the alternate path to
501219820Sjeff *   load.
502219820Sjeff * @private_data: Optional user-defined private data sent with the
503219820Sjeff *   load alternate path message.
504219820Sjeff * @private_data_len: Size of the private data buffer, in bytes.
505219820Sjeff */
506219820Sjeffint ib_send_cm_lap(struct ib_cm_id *cm_id,
507219820Sjeff		   struct ib_sa_path_rec *alternate_path,
508219820Sjeff		   const void *private_data,
509219820Sjeff		   u8 private_data_len);
510219820Sjeff
511219820Sjeff/**
512219820Sjeff * ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning
513219820Sjeff *   to a specified QP state.
514219820Sjeff * @cm_id: Communication identifier associated with the QP attributes to
515219820Sjeff *   initialize.
516219820Sjeff * @qp_attr: On input, specifies the desired QP state.  On output, the
517219820Sjeff *   mandatory and desired optional attributes will be set in order to
518219820Sjeff *   modify the QP to the specified state.
519219820Sjeff * @qp_attr_mask: The QP attribute mask that may be used to transition the
520219820Sjeff *   QP to the specified state.
521219820Sjeff *
522219820Sjeff * Users must set the @qp_attr->qp_state to the desired QP state.  This call
523219820Sjeff * will set all required attributes for the given transition, along with
524219820Sjeff * known optional attributes.  Users may override the attributes returned from
525219820Sjeff * this call before calling ib_modify_qp.
526219820Sjeff */
527219820Sjeffint ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
528219820Sjeff		       struct ib_qp_attr *qp_attr,
529219820Sjeff		       int *qp_attr_mask);
530219820Sjeff
531219820Sjeff/**
532219820Sjeff * ib_send_cm_apr - Sends an alternate path response message in response to
533219820Sjeff *   a load alternate path request.
534219820Sjeff * @cm_id: Connection identifier associated with the alternate path response.
535219820Sjeff * @status: Reply status sent with the alternate path response.
536219820Sjeff * @info: Optional additional information sent with the alternate path
537219820Sjeff *   response.
538219820Sjeff * @info_length: Size of the additional information, in bytes.
539219820Sjeff * @private_data: Optional user-defined private data sent with the
540219820Sjeff *   alternate path response message.
541219820Sjeff * @private_data_len: Size of the private data buffer, in bytes.
542219820Sjeff */
543219820Sjeffint ib_send_cm_apr(struct ib_cm_id *cm_id,
544219820Sjeff		   enum ib_cm_apr_status status,
545219820Sjeff		   void *info,
546219820Sjeff		   u8 info_length,
547219820Sjeff		   const void *private_data,
548219820Sjeff		   u8 private_data_len);
549219820Sjeff
550219820Sjeffstruct ib_cm_sidr_req_param {
551219820Sjeff	struct ib_sa_path_rec	*path;
552219820Sjeff	__be64			service_id;
553219820Sjeff	int			timeout_ms;
554219820Sjeff	const void		*private_data;
555219820Sjeff	u8			private_data_len;
556219820Sjeff	u8			max_cm_retries;
557219820Sjeff};
558219820Sjeff
559219820Sjeff/**
560219820Sjeff * ib_send_cm_sidr_req - Sends a service ID resolution request to the
561219820Sjeff *   remote node.
562219820Sjeff * @cm_id: Communication identifier that will be associated with the
563219820Sjeff *   service ID resolution request.
564219820Sjeff * @param: Service ID resolution request information.
565219820Sjeff */
566219820Sjeffint ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
567219820Sjeff			struct ib_cm_sidr_req_param *param);
568219820Sjeff
569219820Sjeffstruct ib_cm_sidr_rep_param {
570219820Sjeff	u32			qp_num;
571219820Sjeff	u32			qkey;
572219820Sjeff	enum ib_cm_sidr_status	status;
573219820Sjeff	const void		*info;
574219820Sjeff	u8			info_length;
575219820Sjeff	const void		*private_data;
576219820Sjeff	u8			private_data_len;
577219820Sjeff};
578219820Sjeff
579219820Sjeff/**
580219820Sjeff * ib_send_cm_sidr_rep - Sends a service ID resolution reply to the
581219820Sjeff *   remote node.
582219820Sjeff * @cm_id: Communication identifier associated with the received service ID
583219820Sjeff *   resolution request.
584219820Sjeff * @param: Service ID resolution reply information.
585219820Sjeff */
586219820Sjeffint ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
587219820Sjeff			struct ib_cm_sidr_rep_param *param);
588219820Sjeff
589219820Sjeff#endif /* IB_CM_H */
590