Linux 4.1.18
[linux/fpc-iii.git] / include / rdma / ib_cm.h
blob39ed2d2fbd51452216586b031a3e25d236099169
1 /*
2 * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.
3 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
4 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
5 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
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:
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
15 * conditions are met:
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer.
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.
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.
35 #if !defined(IB_CM_H)
36 #define IB_CM_H
38 #include <rdma/ib_mad.h>
39 #include <rdma/ib_sa.h>
41 /* ib_cm and ib_user_cm modules share /sys/class/infiniband_cm */
42 extern struct class cm_class;
44 enum ib_cm_state {
45 IB_CM_IDLE,
46 IB_CM_LISTEN,
47 IB_CM_REQ_SENT,
48 IB_CM_REQ_RCVD,
49 IB_CM_MRA_REQ_SENT,
50 IB_CM_MRA_REQ_RCVD,
51 IB_CM_REP_SENT,
52 IB_CM_REP_RCVD,
53 IB_CM_MRA_REP_SENT,
54 IB_CM_MRA_REP_RCVD,
55 IB_CM_ESTABLISHED,
56 IB_CM_DREQ_SENT,
57 IB_CM_DREQ_RCVD,
58 IB_CM_TIMEWAIT,
59 IB_CM_SIDR_REQ_SENT,
60 IB_CM_SIDR_REQ_RCVD
63 enum ib_cm_lap_state {
64 IB_CM_LAP_UNINIT,
65 IB_CM_LAP_IDLE,
66 IB_CM_LAP_SENT,
67 IB_CM_LAP_RCVD,
68 IB_CM_MRA_LAP_SENT,
69 IB_CM_MRA_LAP_RCVD,
72 enum ib_cm_event_type {
73 IB_CM_REQ_ERROR,
74 IB_CM_REQ_RECEIVED,
75 IB_CM_REP_ERROR,
76 IB_CM_REP_RECEIVED,
77 IB_CM_RTU_RECEIVED,
78 IB_CM_USER_ESTABLISHED,
79 IB_CM_DREQ_ERROR,
80 IB_CM_DREQ_RECEIVED,
81 IB_CM_DREP_RECEIVED,
82 IB_CM_TIMEWAIT_EXIT,
83 IB_CM_MRA_RECEIVED,
84 IB_CM_REJ_RECEIVED,
85 IB_CM_LAP_ERROR,
86 IB_CM_LAP_RECEIVED,
87 IB_CM_APR_RECEIVED,
88 IB_CM_SIDR_REQ_ERROR,
89 IB_CM_SIDR_REQ_RECEIVED,
90 IB_CM_SIDR_REP_RECEIVED
93 enum ib_cm_data_size {
94 IB_CM_REQ_PRIVATE_DATA_SIZE = 92,
95 IB_CM_MRA_PRIVATE_DATA_SIZE = 222,
96 IB_CM_REJ_PRIVATE_DATA_SIZE = 148,
97 IB_CM_REP_PRIVATE_DATA_SIZE = 196,
98 IB_CM_RTU_PRIVATE_DATA_SIZE = 224,
99 IB_CM_DREQ_PRIVATE_DATA_SIZE = 220,
100 IB_CM_DREP_PRIVATE_DATA_SIZE = 224,
101 IB_CM_REJ_ARI_LENGTH = 72,
102 IB_CM_LAP_PRIVATE_DATA_SIZE = 168,
103 IB_CM_APR_PRIVATE_DATA_SIZE = 148,
104 IB_CM_APR_INFO_LENGTH = 72,
105 IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE = 216,
106 IB_CM_SIDR_REP_PRIVATE_DATA_SIZE = 136,
107 IB_CM_SIDR_REP_INFO_LENGTH = 72,
108 /* compare done u32 at a time */
109 IB_CM_COMPARE_SIZE = (64 / sizeof(u32))
112 struct ib_cm_id;
114 struct ib_cm_req_event_param {
115 struct ib_cm_id *listen_id;
116 u8 port;
118 struct ib_sa_path_rec *primary_path;
119 struct ib_sa_path_rec *alternate_path;
121 __be64 remote_ca_guid;
122 u32 remote_qkey;
123 u32 remote_qpn;
124 enum ib_qp_type qp_type;
126 u32 starting_psn;
127 u8 responder_resources;
128 u8 initiator_depth;
129 unsigned int local_cm_response_timeout:5;
130 unsigned int flow_control:1;
131 unsigned int remote_cm_response_timeout:5;
132 unsigned int retry_count:3;
133 unsigned int rnr_retry_count:3;
134 unsigned int srq:1;
137 struct ib_cm_rep_event_param {
138 __be64 remote_ca_guid;
139 u32 remote_qkey;
140 u32 remote_qpn;
141 u32 starting_psn;
142 u8 responder_resources;
143 u8 initiator_depth;
144 unsigned int target_ack_delay:5;
145 unsigned int failover_accepted:2;
146 unsigned int flow_control:1;
147 unsigned int rnr_retry_count:3;
148 unsigned int srq:1;
151 enum ib_cm_rej_reason {
152 IB_CM_REJ_NO_QP = 1,
153 IB_CM_REJ_NO_EEC = 2,
154 IB_CM_REJ_NO_RESOURCES = 3,
155 IB_CM_REJ_TIMEOUT = 4,
156 IB_CM_REJ_UNSUPPORTED = 5,
157 IB_CM_REJ_INVALID_COMM_ID = 6,
158 IB_CM_REJ_INVALID_COMM_INSTANCE = 7,
159 IB_CM_REJ_INVALID_SERVICE_ID = 8,
160 IB_CM_REJ_INVALID_TRANSPORT_TYPE = 9,
161 IB_CM_REJ_STALE_CONN = 10,
162 IB_CM_REJ_RDC_NOT_EXIST = 11,
163 IB_CM_REJ_INVALID_GID = 12,
164 IB_CM_REJ_INVALID_LID = 13,
165 IB_CM_REJ_INVALID_SL = 14,
166 IB_CM_REJ_INVALID_TRAFFIC_CLASS = 15,
167 IB_CM_REJ_INVALID_HOP_LIMIT = 16,
168 IB_CM_REJ_INVALID_PACKET_RATE = 17,
169 IB_CM_REJ_INVALID_ALT_GID = 18,
170 IB_CM_REJ_INVALID_ALT_LID = 19,
171 IB_CM_REJ_INVALID_ALT_SL = 20,
172 IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS = 21,
173 IB_CM_REJ_INVALID_ALT_HOP_LIMIT = 22,
174 IB_CM_REJ_INVALID_ALT_PACKET_RATE = 23,
175 IB_CM_REJ_PORT_CM_REDIRECT = 24,
176 IB_CM_REJ_PORT_REDIRECT = 25,
177 IB_CM_REJ_INVALID_MTU = 26,
178 IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES = 27,
179 IB_CM_REJ_CONSUMER_DEFINED = 28,
180 IB_CM_REJ_INVALID_RNR_RETRY = 29,
181 IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID = 30,
182 IB_CM_REJ_INVALID_CLASS_VERSION = 31,
183 IB_CM_REJ_INVALID_FLOW_LABEL = 32,
184 IB_CM_REJ_INVALID_ALT_FLOW_LABEL = 33
187 struct ib_cm_rej_event_param {
188 enum ib_cm_rej_reason reason;
189 void *ari;
190 u8 ari_length;
193 struct ib_cm_mra_event_param {
194 u8 service_timeout;
197 struct ib_cm_lap_event_param {
198 struct ib_sa_path_rec *alternate_path;
201 enum ib_cm_apr_status {
202 IB_CM_APR_SUCCESS,
203 IB_CM_APR_INVALID_COMM_ID,
204 IB_CM_APR_UNSUPPORTED,
205 IB_CM_APR_REJECT,
206 IB_CM_APR_REDIRECT,
207 IB_CM_APR_IS_CURRENT,
208 IB_CM_APR_INVALID_QPN_EECN,
209 IB_CM_APR_INVALID_LID,
210 IB_CM_APR_INVALID_GID,
211 IB_CM_APR_INVALID_FLOW_LABEL,
212 IB_CM_APR_INVALID_TCLASS,
213 IB_CM_APR_INVALID_HOP_LIMIT,
214 IB_CM_APR_INVALID_PACKET_RATE,
215 IB_CM_APR_INVALID_SL
218 struct ib_cm_apr_event_param {
219 enum ib_cm_apr_status ap_status;
220 void *apr_info;
221 u8 info_len;
224 struct ib_cm_sidr_req_event_param {
225 struct ib_cm_id *listen_id;
226 u8 port;
227 u16 pkey;
230 enum ib_cm_sidr_status {
231 IB_SIDR_SUCCESS,
232 IB_SIDR_UNSUPPORTED,
233 IB_SIDR_REJECT,
234 IB_SIDR_NO_QP,
235 IB_SIDR_REDIRECT,
236 IB_SIDR_UNSUPPORTED_VERSION
239 struct ib_cm_sidr_rep_event_param {
240 enum ib_cm_sidr_status status;
241 u32 qkey;
242 u32 qpn;
243 void *info;
244 u8 info_len;
247 struct ib_cm_event {
248 enum ib_cm_event_type event;
249 union {
250 struct ib_cm_req_event_param req_rcvd;
251 struct ib_cm_rep_event_param rep_rcvd;
252 /* No data for RTU received events. */
253 struct ib_cm_rej_event_param rej_rcvd;
254 struct ib_cm_mra_event_param mra_rcvd;
255 struct ib_cm_lap_event_param lap_rcvd;
256 struct ib_cm_apr_event_param apr_rcvd;
257 /* No data for DREQ/DREP received events. */
258 struct ib_cm_sidr_req_event_param sidr_req_rcvd;
259 struct ib_cm_sidr_rep_event_param sidr_rep_rcvd;
260 enum ib_wc_status send_status;
261 } param;
263 void *private_data;
266 #define CM_REQ_ATTR_ID cpu_to_be16(0x0010)
267 #define CM_MRA_ATTR_ID cpu_to_be16(0x0011)
268 #define CM_REJ_ATTR_ID cpu_to_be16(0x0012)
269 #define CM_REP_ATTR_ID cpu_to_be16(0x0013)
270 #define CM_RTU_ATTR_ID cpu_to_be16(0x0014)
271 #define CM_DREQ_ATTR_ID cpu_to_be16(0x0015)
272 #define CM_DREP_ATTR_ID cpu_to_be16(0x0016)
273 #define CM_SIDR_REQ_ATTR_ID cpu_to_be16(0x0017)
274 #define CM_SIDR_REP_ATTR_ID cpu_to_be16(0x0018)
275 #define CM_LAP_ATTR_ID cpu_to_be16(0x0019)
276 #define CM_APR_ATTR_ID cpu_to_be16(0x001A)
279 * ib_cm_handler - User-defined callback to process communication events.
280 * @cm_id: Communication identifier associated with the reported event.
281 * @event: Information about the communication event.
283 * IB_CM_REQ_RECEIVED and IB_CM_SIDR_REQ_RECEIVED communication events
284 * generated as a result of listen requests result in the allocation of a
285 * new @cm_id. The new @cm_id is returned to the user through this callback.
286 * Clients are responsible for destroying the new @cm_id. For peer-to-peer
287 * IB_CM_REQ_RECEIVED and all other events, the returned @cm_id corresponds
288 * to a user's existing communication identifier.
290 * Users may not call ib_destroy_cm_id while in the context of this callback;
291 * however, returning a non-zero value instructs the communication manager to
292 * destroy the @cm_id after the callback completes.
294 typedef int (*ib_cm_handler)(struct ib_cm_id *cm_id,
295 struct ib_cm_event *event);
297 struct ib_cm_id {
298 ib_cm_handler cm_handler;
299 void *context;
300 struct ib_device *device;
301 __be64 service_id;
302 __be64 service_mask;
303 enum ib_cm_state state; /* internal CM/debug use */
304 enum ib_cm_lap_state lap_state; /* internal CM/debug use */
305 __be32 local_id;
306 __be32 remote_id;
307 u32 remote_cm_qpn; /* 1 unless redirected */
311 * ib_create_cm_id - Allocate a communication identifier.
312 * @device: Device associated with the cm_id. All related communication will
313 * be associated with the specified device.
314 * @cm_handler: Callback invoked to notify the user of CM events.
315 * @context: User specified context associated with the communication
316 * identifier.
318 * Communication identifiers are used to track connection states, service
319 * ID resolution requests, and listen requests.
321 struct ib_cm_id *ib_create_cm_id(struct ib_device *device,
322 ib_cm_handler cm_handler,
323 void *context);
326 * ib_destroy_cm_id - Destroy a connection identifier.
327 * @cm_id: Connection identifier to destroy.
329 * This call blocks until the connection identifier is destroyed.
331 void ib_destroy_cm_id(struct ib_cm_id *cm_id);
333 #define IB_SERVICE_ID_AGN_MASK cpu_to_be64(0xFF00000000000000ULL)
334 #define IB_CM_ASSIGN_SERVICE_ID cpu_to_be64(0x0200000000000000ULL)
335 #define IB_CMA_SERVICE_ID cpu_to_be64(0x0000000001000000ULL)
336 #define IB_CMA_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFF000000ULL)
337 #define IB_SDP_SERVICE_ID cpu_to_be64(0x0000000000010000ULL)
338 #define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL)
340 struct ib_cm_compare_data {
341 u32 data[IB_CM_COMPARE_SIZE];
342 u32 mask[IB_CM_COMPARE_SIZE];
346 * ib_cm_listen - Initiates listening on the specified service ID for
347 * connection and service ID resolution requests.
348 * @cm_id: Connection identifier associated with the listen request.
349 * @service_id: Service identifier matched against incoming connection
350 * and service ID resolution requests. The service ID should be specified
351 * network-byte order. If set to IB_CM_ASSIGN_SERVICE_ID, the CM will
352 * assign a service ID to the caller.
353 * @service_mask: Mask applied to service ID used to listen across a
354 * range of service IDs. If set to 0, the service ID is matched
355 * exactly. This parameter is ignored if %service_id is set to
356 * IB_CM_ASSIGN_SERVICE_ID.
357 * @compare_data: This parameter is optional. It specifies data that must
358 * appear in the private data of a connection request for the specified
359 * listen request.
361 int ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id, __be64 service_mask,
362 struct ib_cm_compare_data *compare_data);
364 struct ib_cm_req_param {
365 struct ib_sa_path_rec *primary_path;
366 struct ib_sa_path_rec *alternate_path;
367 __be64 service_id;
368 u32 qp_num;
369 enum ib_qp_type qp_type;
370 u32 starting_psn;
371 const void *private_data;
372 u8 private_data_len;
373 u8 peer_to_peer;
374 u8 responder_resources;
375 u8 initiator_depth;
376 u8 remote_cm_response_timeout;
377 u8 flow_control;
378 u8 local_cm_response_timeout;
379 u8 retry_count;
380 u8 rnr_retry_count;
381 u8 max_cm_retries;
382 u8 srq;
386 * ib_send_cm_req - Sends a connection request to the remote node.
387 * @cm_id: Connection identifier that will be associated with the
388 * connection request.
389 * @param: Connection request information needed to establish the
390 * connection.
392 int ib_send_cm_req(struct ib_cm_id *cm_id,
393 struct ib_cm_req_param *param);
395 struct ib_cm_rep_param {
396 u32 qp_num;
397 u32 starting_psn;
398 const void *private_data;
399 u8 private_data_len;
400 u8 responder_resources;
401 u8 initiator_depth;
402 u8 failover_accepted;
403 u8 flow_control;
404 u8 rnr_retry_count;
405 u8 srq;
409 * ib_send_cm_rep - Sends a connection reply in response to a connection
410 * request.
411 * @cm_id: Connection identifier that will be associated with the
412 * connection request.
413 * @param: Connection reply information needed to establish the
414 * connection.
416 int ib_send_cm_rep(struct ib_cm_id *cm_id,
417 struct ib_cm_rep_param *param);
420 * ib_send_cm_rtu - Sends a connection ready to use message in response
421 * to a connection reply message.
422 * @cm_id: Connection identifier associated with the connection request.
423 * @private_data: Optional user-defined private data sent with the
424 * ready to use message.
425 * @private_data_len: Size of the private data buffer, in bytes.
427 int ib_send_cm_rtu(struct ib_cm_id *cm_id,
428 const void *private_data,
429 u8 private_data_len);
432 * ib_send_cm_dreq - Sends a disconnection request for an existing
433 * connection.
434 * @cm_id: Connection identifier associated with the connection being
435 * released.
436 * @private_data: Optional user-defined private data sent with the
437 * disconnection request message.
438 * @private_data_len: Size of the private data buffer, in bytes.
440 int ib_send_cm_dreq(struct ib_cm_id *cm_id,
441 const void *private_data,
442 u8 private_data_len);
445 * ib_send_cm_drep - Sends a disconnection reply to a disconnection request.
446 * @cm_id: Connection identifier associated with the connection being
447 * released.
448 * @private_data: Optional user-defined private data sent with the
449 * disconnection reply message.
450 * @private_data_len: Size of the private data buffer, in bytes.
452 * If the cm_id is in the correct state, the CM will transition the connection
453 * to the timewait state, even if an error occurs sending the DREP message.
455 int ib_send_cm_drep(struct ib_cm_id *cm_id,
456 const void *private_data,
457 u8 private_data_len);
460 * ib_cm_notify - Notifies the CM of an event reported to the consumer.
461 * @cm_id: Connection identifier to transition to established.
462 * @event: Type of event.
464 * This routine should be invoked by users to notify the CM of relevant
465 * communication events. Events that should be reported to the CM and
466 * when to report them are:
468 * IB_EVENT_COMM_EST - Used when a message is received on a connected
469 * QP before an RTU has been received.
470 * IB_EVENT_PATH_MIG - Notifies the CM that the connection has failed over
471 * to the alternate path.
473 int ib_cm_notify(struct ib_cm_id *cm_id, enum ib_event_type event);
476 * ib_send_cm_rej - Sends a connection rejection message to the
477 * remote node.
478 * @cm_id: Connection identifier associated with the connection being
479 * rejected.
480 * @reason: Reason for the connection request rejection.
481 * @ari: Optional additional rejection information.
482 * @ari_length: Size of the additional rejection information, in bytes.
483 * @private_data: Optional user-defined private data sent with the
484 * rejection message.
485 * @private_data_len: Size of the private data buffer, in bytes.
487 int ib_send_cm_rej(struct ib_cm_id *cm_id,
488 enum ib_cm_rej_reason reason,
489 void *ari,
490 u8 ari_length,
491 const void *private_data,
492 u8 private_data_len);
494 #define IB_CM_MRA_FLAG_DELAY 0x80 /* Send MRA only after a duplicate msg */
497 * ib_send_cm_mra - Sends a message receipt acknowledgement to a connection
498 * message.
499 * @cm_id: Connection identifier associated with the connection message.
500 * @service_timeout: The lower 5-bits specify the maximum time required for
501 * the sender to reply to the connection message. The upper 3-bits
502 * specify additional control flags.
503 * @private_data: Optional user-defined private data sent with the
504 * message receipt acknowledgement.
505 * @private_data_len: Size of the private data buffer, in bytes.
507 int ib_send_cm_mra(struct ib_cm_id *cm_id,
508 u8 service_timeout,
509 const void *private_data,
510 u8 private_data_len);
513 * ib_send_cm_lap - Sends a load alternate path request.
514 * @cm_id: Connection identifier associated with the load alternate path
515 * message.
516 * @alternate_path: A path record that identifies the alternate path to
517 * load.
518 * @private_data: Optional user-defined private data sent with the
519 * load alternate path message.
520 * @private_data_len: Size of the private data buffer, in bytes.
522 int ib_send_cm_lap(struct ib_cm_id *cm_id,
523 struct ib_sa_path_rec *alternate_path,
524 const void *private_data,
525 u8 private_data_len);
528 * ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning
529 * to a specified QP state.
530 * @cm_id: Communication identifier associated with the QP attributes to
531 * initialize.
532 * @qp_attr: On input, specifies the desired QP state. On output, the
533 * mandatory and desired optional attributes will be set in order to
534 * modify the QP to the specified state.
535 * @qp_attr_mask: The QP attribute mask that may be used to transition the
536 * QP to the specified state.
538 * Users must set the @qp_attr->qp_state to the desired QP state. This call
539 * will set all required attributes for the given transition, along with
540 * known optional attributes. Users may override the attributes returned from
541 * this call before calling ib_modify_qp.
543 int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
544 struct ib_qp_attr *qp_attr,
545 int *qp_attr_mask);
548 * ib_send_cm_apr - Sends an alternate path response message in response to
549 * a load alternate path request.
550 * @cm_id: Connection identifier associated with the alternate path response.
551 * @status: Reply status sent with the alternate path response.
552 * @info: Optional additional information sent with the alternate path
553 * response.
554 * @info_length: Size of the additional information, in bytes.
555 * @private_data: Optional user-defined private data sent with the
556 * alternate path response message.
557 * @private_data_len: Size of the private data buffer, in bytes.
559 int ib_send_cm_apr(struct ib_cm_id *cm_id,
560 enum ib_cm_apr_status status,
561 void *info,
562 u8 info_length,
563 const void *private_data,
564 u8 private_data_len);
566 struct ib_cm_sidr_req_param {
567 struct ib_sa_path_rec *path;
568 __be64 service_id;
569 int timeout_ms;
570 const void *private_data;
571 u8 private_data_len;
572 u8 max_cm_retries;
576 * ib_send_cm_sidr_req - Sends a service ID resolution request to the
577 * remote node.
578 * @cm_id: Communication identifier that will be associated with the
579 * service ID resolution request.
580 * @param: Service ID resolution request information.
582 int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
583 struct ib_cm_sidr_req_param *param);
585 struct ib_cm_sidr_rep_param {
586 u32 qp_num;
587 u32 qkey;
588 enum ib_cm_sidr_status status;
589 const void *info;
590 u8 info_length;
591 const void *private_data;
592 u8 private_data_len;
596 * ib_send_cm_sidr_rep - Sends a service ID resolution reply to the
597 * remote node.
598 * @cm_id: Communication identifier associated with the received service ID
599 * resolution request.
600 * @param: Service ID resolution reply information.
602 int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
603 struct ib_cm_sidr_rep_param *param);
605 #endif /* IB_CM_H */