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
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
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
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;
63 enum ib_cm_lap_state {
72 enum ib_cm_event_type {
78 IB_CM_USER_ESTABLISHED,
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 IB_CM_COMPARE_SIZE = 64
113 struct ib_cm_req_event_param {
114 struct ib_cm_id *listen_id;
117 struct ib_sa_path_rec *primary_path;
118 struct ib_sa_path_rec *alternate_path;
120 __be64 remote_ca_guid;
123 enum ib_qp_type qp_type;
126 u8 responder_resources;
128 unsigned int local_cm_response_timeout:5;
129 unsigned int flow_control:1;
130 unsigned int remote_cm_response_timeout:5;
131 unsigned int retry_count:3;
132 unsigned int rnr_retry_count:3;
136 struct ib_cm_rep_event_param {
137 __be64 remote_ca_guid;
141 u8 responder_resources;
143 unsigned int target_ack_delay:5;
144 unsigned int failover_accepted:2;
145 unsigned int flow_control:1;
146 unsigned int rnr_retry_count:3;
150 enum ib_cm_rej_reason {
152 IB_CM_REJ_NO_EEC = 2,
153 IB_CM_REJ_NO_RESOURCES = 3,
154 IB_CM_REJ_TIMEOUT = 4,
155 IB_CM_REJ_UNSUPPORTED = 5,
156 IB_CM_REJ_INVALID_COMM_ID = 6,
157 IB_CM_REJ_INVALID_COMM_INSTANCE = 7,
158 IB_CM_REJ_INVALID_SERVICE_ID = 8,
159 IB_CM_REJ_INVALID_TRANSPORT_TYPE = 9,
160 IB_CM_REJ_STALE_CONN = 10,
161 IB_CM_REJ_RDC_NOT_EXIST = 11,
162 IB_CM_REJ_INVALID_GID = 12,
163 IB_CM_REJ_INVALID_LID = 13,
164 IB_CM_REJ_INVALID_SL = 14,
165 IB_CM_REJ_INVALID_TRAFFIC_CLASS = 15,
166 IB_CM_REJ_INVALID_HOP_LIMIT = 16,
167 IB_CM_REJ_INVALID_PACKET_RATE = 17,
168 IB_CM_REJ_INVALID_ALT_GID = 18,
169 IB_CM_REJ_INVALID_ALT_LID = 19,
170 IB_CM_REJ_INVALID_ALT_SL = 20,
171 IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS = 21,
172 IB_CM_REJ_INVALID_ALT_HOP_LIMIT = 22,
173 IB_CM_REJ_INVALID_ALT_PACKET_RATE = 23,
174 IB_CM_REJ_PORT_CM_REDIRECT = 24,
175 IB_CM_REJ_PORT_REDIRECT = 25,
176 IB_CM_REJ_INVALID_MTU = 26,
177 IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES = 27,
178 IB_CM_REJ_CONSUMER_DEFINED = 28,
179 IB_CM_REJ_INVALID_RNR_RETRY = 29,
180 IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID = 30,
181 IB_CM_REJ_INVALID_CLASS_VERSION = 31,
182 IB_CM_REJ_INVALID_FLOW_LABEL = 32,
183 IB_CM_REJ_INVALID_ALT_FLOW_LABEL = 33
186 struct ib_cm_rej_event_param {
187 enum ib_cm_rej_reason reason;
192 struct ib_cm_mra_event_param {
196 struct ib_cm_lap_event_param {
197 struct ib_sa_path_rec *alternate_path;
200 enum ib_cm_apr_status {
202 IB_CM_APR_INVALID_COMM_ID,
203 IB_CM_APR_UNSUPPORTED,
206 IB_CM_APR_IS_CURRENT,
207 IB_CM_APR_INVALID_QPN_EECN,
208 IB_CM_APR_INVALID_LID,
209 IB_CM_APR_INVALID_GID,
210 IB_CM_APR_INVALID_FLOW_LABEL,
211 IB_CM_APR_INVALID_TCLASS,
212 IB_CM_APR_INVALID_HOP_LIMIT,
213 IB_CM_APR_INVALID_PACKET_RATE,
217 struct ib_cm_apr_event_param {
218 enum ib_cm_apr_status ap_status;
223 struct ib_cm_sidr_req_event_param {
224 struct ib_cm_id *listen_id;
229 enum ib_cm_sidr_status {
235 IB_SIDR_UNSUPPORTED_VERSION
238 struct ib_cm_sidr_rep_event_param {
239 enum ib_cm_sidr_status status;
247 enum ib_cm_event_type event;
249 struct ib_cm_req_event_param req_rcvd;
250 struct ib_cm_rep_event_param rep_rcvd;
251 /* No data for RTU received events. */
252 struct ib_cm_rej_event_param rej_rcvd;
253 struct ib_cm_mra_event_param mra_rcvd;
254 struct ib_cm_lap_event_param lap_rcvd;
255 struct ib_cm_apr_event_param apr_rcvd;
256 /* No data for DREQ/DREP received events. */
257 struct ib_cm_sidr_req_event_param sidr_req_rcvd;
258 struct ib_cm_sidr_rep_event_param sidr_rep_rcvd;
259 enum ib_wc_status send_status;
265 #define CM_REQ_ATTR_ID cpu_to_be16(0x0010)
266 #define CM_MRA_ATTR_ID cpu_to_be16(0x0011)
267 #define CM_REJ_ATTR_ID cpu_to_be16(0x0012)
268 #define CM_REP_ATTR_ID cpu_to_be16(0x0013)
269 #define CM_RTU_ATTR_ID cpu_to_be16(0x0014)
270 #define CM_DREQ_ATTR_ID cpu_to_be16(0x0015)
271 #define CM_DREP_ATTR_ID cpu_to_be16(0x0016)
272 #define CM_SIDR_REQ_ATTR_ID cpu_to_be16(0x0017)
273 #define CM_SIDR_REP_ATTR_ID cpu_to_be16(0x0018)
274 #define CM_LAP_ATTR_ID cpu_to_be16(0x0019)
275 #define CM_APR_ATTR_ID cpu_to_be16(0x001A)
278 * ib_cm_handler - User-defined callback to process communication events.
279 * @cm_id: Communication identifier associated with the reported event.
280 * @event: Information about the communication event.
282 * IB_CM_REQ_RECEIVED and IB_CM_SIDR_REQ_RECEIVED communication events
283 * generated as a result of listen requests result in the allocation of a
284 * new @cm_id. The new @cm_id is returned to the user through this callback.
285 * Clients are responsible for destroying the new @cm_id. For peer-to-peer
286 * IB_CM_REQ_RECEIVED and all other events, the returned @cm_id corresponds
287 * to a user's existing communication identifier.
289 * Users may not call ib_destroy_cm_id while in the context of this callback;
290 * however, returning a non-zero value instructs the communication manager to
291 * destroy the @cm_id after the callback completes.
293 typedef int (*ib_cm_handler)(struct ib_cm_id *cm_id,
294 struct ib_cm_event *event);
297 ib_cm_handler cm_handler;
299 struct ib_device *device;
302 enum ib_cm_state state; /* internal CM/debug use */
303 enum ib_cm_lap_state lap_state; /* internal CM/debug use */
306 u32 remote_cm_qpn; /* 1 unless redirected */
310 * ib_create_cm_id - Allocate a communication identifier.
311 * @device: Device associated with the cm_id. All related communication will
312 * be associated with the specified device.
313 * @cm_handler: Callback invoked to notify the user of CM events.
314 * @context: User specified context associated with the communication
317 * Communication identifiers are used to track connection states, service
318 * ID resolution requests, and listen requests.
320 struct ib_cm_id *ib_create_cm_id(struct ib_device *device,
321 ib_cm_handler cm_handler,
325 * ib_destroy_cm_id - Destroy a connection identifier.
326 * @cm_id: Connection identifier to destroy.
328 * This call blocks until the connection identifier is destroyed.
330 void ib_destroy_cm_id(struct ib_cm_id *cm_id);
332 #define IB_SERVICE_ID_AGN_MASK cpu_to_be64(0xFF00000000000000ULL)
333 #define IB_CM_ASSIGN_SERVICE_ID cpu_to_be64(0x0200000000000000ULL)
334 #define IB_CMA_SERVICE_ID cpu_to_be64(0x0000000001000000ULL)
335 #define IB_CMA_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFF000000ULL)
336 #define IB_SDP_SERVICE_ID cpu_to_be64(0x0000000000010000ULL)
337 #define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL)
339 struct ib_cm_compare_data {
340 u8 data[IB_CM_COMPARE_SIZE];
341 u8 mask[IB_CM_COMPARE_SIZE];
345 * ib_cm_listen - Initiates listening on the specified service ID for
346 * connection and service ID resolution requests.
347 * @cm_id: Connection identifier associated with the listen request.
348 * @service_id: Service identifier matched against incoming connection
349 * and service ID resolution requests. The service ID should be specified
350 * network-byte order. If set to IB_CM_ASSIGN_SERVICE_ID, the CM will
351 * assign a service ID to the caller.
352 * @service_mask: Mask applied to service ID used to listen across a
353 * range of service IDs. If set to 0, the service ID is matched
354 * exactly. This parameter is ignored if %service_id is set to
355 * IB_CM_ASSIGN_SERVICE_ID.
356 * @compare_data: This parameter is optional. It specifies data that must
357 * appear in the private data of a connection request for the specified
360 int ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id, __be64 service_mask,
361 struct ib_cm_compare_data *compare_data);
363 struct ib_cm_req_param {
364 struct ib_sa_path_rec *primary_path;
365 struct ib_sa_path_rec *alternate_path;
368 enum ib_qp_type qp_type;
370 const void *private_data;
373 u8 responder_resources;
375 u8 remote_cm_response_timeout;
377 u8 local_cm_response_timeout;
385 * ib_send_cm_req - Sends a connection request to the remote node.
386 * @cm_id: Connection identifier that will be associated with the
387 * connection request.
388 * @param: Connection request information needed to establish the
391 int ib_send_cm_req(struct ib_cm_id *cm_id,
392 struct ib_cm_req_param *param);
394 struct ib_cm_rep_param {
397 const void *private_data;
399 u8 responder_resources;
401 u8 failover_accepted;
408 * ib_send_cm_rep - Sends a connection reply in response to a connection
410 * @cm_id: Connection identifier that will be associated with the
411 * connection request.
412 * @param: Connection reply information needed to establish the
415 int ib_send_cm_rep(struct ib_cm_id *cm_id,
416 struct ib_cm_rep_param *param);
419 * ib_send_cm_rtu - Sends a connection ready to use message in response
420 * to a connection reply message.
421 * @cm_id: Connection identifier associated with the connection request.
422 * @private_data: Optional user-defined private data sent with the
423 * ready to use message.
424 * @private_data_len: Size of the private data buffer, in bytes.
426 int ib_send_cm_rtu(struct ib_cm_id *cm_id,
427 const void *private_data,
428 u8 private_data_len);
431 * ib_send_cm_dreq - Sends a disconnection request for an existing
433 * @cm_id: Connection identifier associated with the connection being
435 * @private_data: Optional user-defined private data sent with the
436 * disconnection request message.
437 * @private_data_len: Size of the private data buffer, in bytes.
439 int ib_send_cm_dreq(struct ib_cm_id *cm_id,
440 const void *private_data,
441 u8 private_data_len);
444 * ib_send_cm_drep - Sends a disconnection reply to a disconnection request.
445 * @cm_id: Connection identifier associated with the connection being
447 * @private_data: Optional user-defined private data sent with the
448 * disconnection reply message.
449 * @private_data_len: Size of the private data buffer, in bytes.
451 * If the cm_id is in the correct state, the CM will transition the connection
452 * to the timewait state, even if an error occurs sending the DREP message.
454 int ib_send_cm_drep(struct ib_cm_id *cm_id,
455 const void *private_data,
456 u8 private_data_len);
459 * ib_cm_notify - Notifies the CM of an event reported to the consumer.
460 * @cm_id: Connection identifier to transition to established.
461 * @event: Type of event.
463 * This routine should be invoked by users to notify the CM of relevant
464 * communication events. Events that should be reported to the CM and
465 * when to report them are:
467 * IB_EVENT_COMM_EST - Used when a message is received on a connected
468 * QP before an RTU has been received.
469 * IB_EVENT_PATH_MIG - Notifies the CM that the connection has failed over
470 * to the alternate path.
472 int ib_cm_notify(struct ib_cm_id *cm_id, enum ib_event_type event);
475 * ib_send_cm_rej - Sends a connection rejection message to the
477 * @cm_id: Connection identifier associated with the connection being
479 * @reason: Reason for the connection request rejection.
480 * @ari: Optional additional rejection information.
481 * @ari_length: Size of the additional rejection information, in bytes.
482 * @private_data: Optional user-defined private data sent with the
484 * @private_data_len: Size of the private data buffer, in bytes.
486 int ib_send_cm_rej(struct ib_cm_id *cm_id,
487 enum ib_cm_rej_reason reason,
490 const void *private_data,
491 u8 private_data_len);
493 #define IB_CM_MRA_FLAG_DELAY 0x80 /* Send MRA only after a duplicate msg */
496 * ib_send_cm_mra - Sends a message receipt acknowledgement to a connection
498 * @cm_id: Connection identifier associated with the connection message.
499 * @service_timeout: The lower 5-bits specify the maximum time required for
500 * the sender to reply to the connection message. The upper 3-bits
501 * specify additional control flags.
502 * @private_data: Optional user-defined private data sent with the
503 * message receipt acknowledgement.
504 * @private_data_len: Size of the private data buffer, in bytes.
506 int ib_send_cm_mra(struct ib_cm_id *cm_id,
508 const void *private_data,
509 u8 private_data_len);
512 * ib_send_cm_lap - Sends a load alternate path request.
513 * @cm_id: Connection identifier associated with the load alternate path
515 * @alternate_path: A path record that identifies the alternate path to
517 * @private_data: Optional user-defined private data sent with the
518 * load alternate path message.
519 * @private_data_len: Size of the private data buffer, in bytes.
521 int ib_send_cm_lap(struct ib_cm_id *cm_id,
522 struct ib_sa_path_rec *alternate_path,
523 const void *private_data,
524 u8 private_data_len);
527 * ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning
528 * to a specified QP state.
529 * @cm_id: Communication identifier associated with the QP attributes to
531 * @qp_attr: On input, specifies the desired QP state. On output, the
532 * mandatory and desired optional attributes will be set in order to
533 * modify the QP to the specified state.
534 * @qp_attr_mask: The QP attribute mask that may be used to transition the
535 * QP to the specified state.
537 * Users must set the @qp_attr->qp_state to the desired QP state. This call
538 * will set all required attributes for the given transition, along with
539 * known optional attributes. Users may override the attributes returned from
540 * this call before calling ib_modify_qp.
542 int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
543 struct ib_qp_attr *qp_attr,
547 * ib_send_cm_apr - Sends an alternate path response message in response to
548 * a load alternate path request.
549 * @cm_id: Connection identifier associated with the alternate path response.
550 * @status: Reply status sent with the alternate path response.
551 * @info: Optional additional information sent with the alternate path
553 * @info_length: Size of the additional information, in bytes.
554 * @private_data: Optional user-defined private data sent with the
555 * alternate path response message.
556 * @private_data_len: Size of the private data buffer, in bytes.
558 int ib_send_cm_apr(struct ib_cm_id *cm_id,
559 enum ib_cm_apr_status status,
562 const void *private_data,
563 u8 private_data_len);
565 struct ib_cm_sidr_req_param {
566 struct ib_sa_path_rec *path;
569 const void *private_data;
575 * ib_send_cm_sidr_req - Sends a service ID resolution request to the
577 * @cm_id: Communication identifier that will be associated with the
578 * service ID resolution request.
579 * @param: Service ID resolution request information.
581 int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
582 struct ib_cm_sidr_req_param *param);
584 struct ib_cm_sidr_rep_param {
587 enum ib_cm_sidr_status status;
590 const void *private_data;
595 * ib_send_cm_sidr_rep - Sends a service ID resolution reply to the
597 * @cm_id: Communication identifier associated with the received service ID
598 * resolution request.
599 * @param: Service ID resolution reply information.
601 int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
602 struct ib_cm_sidr_rep_param *param);