2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
4 * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.
5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
7 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
9 * This software is available to you under a choice of one of two
10 * licenses. You may choose to be licensed under the terms of the GNU
11 * General Public License (GPL) Version 2, available from the file
12 * COPYING in the main directory of this source tree, or the
13 * OpenIB.org BSD license below:
15 * Redistribution and use in source and binary forms, with or
16 * without modification, are permitted provided that the following
19 * - Redistributions of source code must retain the above
20 * copyright notice, this list of conditions and the following
23 * - Redistributions in binary form must reproduce the above
24 * copyright notice, this list of conditions and the following
25 * disclaimer in the documentation and/or other materials
26 * provided with the distribution.
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
32 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
33 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43 #include <rdma/ib_mad.h>
44 #include <rdma/ib_sa.h>
46 /* ib_cm and ib_user_cm modules share /sys/class/infiniband_cm */
47 extern struct class cm_class;
68 enum ib_cm_lap_state {
77 enum ib_cm_event_type {
83 IB_CM_USER_ESTABLISHED,
94 IB_CM_SIDR_REQ_RECEIVED,
95 IB_CM_SIDR_REP_RECEIVED
98 enum ib_cm_data_size {
99 IB_CM_REQ_PRIVATE_DATA_SIZE = 92,
100 IB_CM_MRA_PRIVATE_DATA_SIZE = 222,
101 IB_CM_REJ_PRIVATE_DATA_SIZE = 148,
102 IB_CM_REP_PRIVATE_DATA_SIZE = 196,
103 IB_CM_RTU_PRIVATE_DATA_SIZE = 224,
104 IB_CM_DREQ_PRIVATE_DATA_SIZE = 220,
105 IB_CM_DREP_PRIVATE_DATA_SIZE = 224,
106 IB_CM_REJ_ARI_LENGTH = 72,
107 IB_CM_LAP_PRIVATE_DATA_SIZE = 168,
108 IB_CM_APR_PRIVATE_DATA_SIZE = 148,
109 IB_CM_APR_INFO_LENGTH = 72,
110 IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE = 216,
111 IB_CM_SIDR_REP_PRIVATE_DATA_SIZE = 136,
112 IB_CM_SIDR_REP_INFO_LENGTH = 72,
117 struct ib_cm_req_event_param {
118 struct ib_cm_id *listen_id;
120 /* P_Key that was used by the GMP's BTH header */
125 struct ib_sa_path_rec *primary_path;
126 struct ib_sa_path_rec *alternate_path;
129 * SGID index of the primary path. Currently only
130 * useful for RoCE. Alternate path GID attributes
131 * are not yet supported.
135 __be64 remote_ca_guid;
138 enum ib_qp_type qp_type;
141 u8 responder_resources;
143 unsigned int local_cm_response_timeout:5;
144 unsigned int flow_control:1;
145 unsigned int remote_cm_response_timeout:5;
146 unsigned int retry_count:3;
147 unsigned int rnr_retry_count:3;
151 struct ib_cm_rep_event_param {
152 __be64 remote_ca_guid;
156 u8 responder_resources;
158 unsigned int target_ack_delay:5;
159 unsigned int failover_accepted:2;
160 unsigned int flow_control:1;
161 unsigned int rnr_retry_count:3;
165 enum ib_cm_rej_reason {
167 IB_CM_REJ_NO_EEC = 2,
168 IB_CM_REJ_NO_RESOURCES = 3,
169 IB_CM_REJ_TIMEOUT = 4,
170 IB_CM_REJ_UNSUPPORTED = 5,
171 IB_CM_REJ_INVALID_COMM_ID = 6,
172 IB_CM_REJ_INVALID_COMM_INSTANCE = 7,
173 IB_CM_REJ_INVALID_SERVICE_ID = 8,
174 IB_CM_REJ_INVALID_TRANSPORT_TYPE = 9,
175 IB_CM_REJ_STALE_CONN = 10,
176 IB_CM_REJ_RDC_NOT_EXIST = 11,
177 IB_CM_REJ_INVALID_GID = 12,
178 IB_CM_REJ_INVALID_LID = 13,
179 IB_CM_REJ_INVALID_SL = 14,
180 IB_CM_REJ_INVALID_TRAFFIC_CLASS = 15,
181 IB_CM_REJ_INVALID_HOP_LIMIT = 16,
182 IB_CM_REJ_INVALID_PACKET_RATE = 17,
183 IB_CM_REJ_INVALID_ALT_GID = 18,
184 IB_CM_REJ_INVALID_ALT_LID = 19,
185 IB_CM_REJ_INVALID_ALT_SL = 20,
186 IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS = 21,
187 IB_CM_REJ_INVALID_ALT_HOP_LIMIT = 22,
188 IB_CM_REJ_INVALID_ALT_PACKET_RATE = 23,
189 IB_CM_REJ_PORT_CM_REDIRECT = 24,
190 IB_CM_REJ_PORT_REDIRECT = 25,
191 IB_CM_REJ_INVALID_MTU = 26,
192 IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES = 27,
193 IB_CM_REJ_CONSUMER_DEFINED = 28,
194 IB_CM_REJ_INVALID_RNR_RETRY = 29,
195 IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID = 30,
196 IB_CM_REJ_INVALID_CLASS_VERSION = 31,
197 IB_CM_REJ_INVALID_FLOW_LABEL = 32,
198 IB_CM_REJ_INVALID_ALT_FLOW_LABEL = 33
201 struct ib_cm_rej_event_param {
202 enum ib_cm_rej_reason reason;
207 struct ib_cm_mra_event_param {
211 struct ib_cm_lap_event_param {
212 struct ib_sa_path_rec *alternate_path;
215 enum ib_cm_apr_status {
217 IB_CM_APR_INVALID_COMM_ID,
218 IB_CM_APR_UNSUPPORTED,
221 IB_CM_APR_IS_CURRENT,
222 IB_CM_APR_INVALID_QPN_EECN,
223 IB_CM_APR_INVALID_LID,
224 IB_CM_APR_INVALID_GID,
225 IB_CM_APR_INVALID_FLOW_LABEL,
226 IB_CM_APR_INVALID_TCLASS,
227 IB_CM_APR_INVALID_HOP_LIMIT,
228 IB_CM_APR_INVALID_PACKET_RATE,
232 struct ib_cm_apr_event_param {
233 enum ib_cm_apr_status ap_status;
238 struct ib_cm_sidr_req_event_param {
239 struct ib_cm_id *listen_id;
243 * SGID index of the request. Currently only
248 /* P_Key that was used by the GMP's BTH header */
254 enum ib_cm_sidr_status {
260 IB_SIDR_UNSUPPORTED_VERSION
263 struct ib_cm_sidr_rep_event_param {
264 enum ib_cm_sidr_status status;
272 enum ib_cm_event_type event;
274 struct ib_cm_req_event_param req_rcvd;
275 struct ib_cm_rep_event_param rep_rcvd;
276 /* No data for RTU received events. */
277 struct ib_cm_rej_event_param rej_rcvd;
278 struct ib_cm_mra_event_param mra_rcvd;
279 struct ib_cm_lap_event_param lap_rcvd;
280 struct ib_cm_apr_event_param apr_rcvd;
281 /* No data for DREQ/DREP received events. */
282 struct ib_cm_sidr_req_event_param sidr_req_rcvd;
283 struct ib_cm_sidr_rep_event_param sidr_rep_rcvd;
284 enum ib_wc_status send_status;
290 #define CM_REQ_ATTR_ID cpu_to_be16(0x0010)
291 #define CM_MRA_ATTR_ID cpu_to_be16(0x0011)
292 #define CM_REJ_ATTR_ID cpu_to_be16(0x0012)
293 #define CM_REP_ATTR_ID cpu_to_be16(0x0013)
294 #define CM_RTU_ATTR_ID cpu_to_be16(0x0014)
295 #define CM_DREQ_ATTR_ID cpu_to_be16(0x0015)
296 #define CM_DREP_ATTR_ID cpu_to_be16(0x0016)
297 #define CM_SIDR_REQ_ATTR_ID cpu_to_be16(0x0017)
298 #define CM_SIDR_REP_ATTR_ID cpu_to_be16(0x0018)
299 #define CM_LAP_ATTR_ID cpu_to_be16(0x0019)
300 #define CM_APR_ATTR_ID cpu_to_be16(0x001A)
303 * ib_cm_handler - User-defined callback to process communication events.
304 * @cm_id: Communication identifier associated with the reported event.
305 * @event: Information about the communication event.
307 * IB_CM_REQ_RECEIVED and IB_CM_SIDR_REQ_RECEIVED communication events
308 * generated as a result of listen requests result in the allocation of a
309 * new @cm_id. The new @cm_id is returned to the user through this callback.
310 * Clients are responsible for destroying the new @cm_id. For peer-to-peer
311 * IB_CM_REQ_RECEIVED and all other events, the returned @cm_id corresponds
312 * to a user's existing communication identifier.
314 * Users may not call ib_destroy_cm_id while in the context of this callback;
315 * however, returning a non-zero value instructs the communication manager to
316 * destroy the @cm_id after the callback completes.
318 typedef int (*ib_cm_handler)(struct ib_cm_id *cm_id,
319 struct ib_cm_event *event);
322 ib_cm_handler cm_handler;
324 struct ib_device *device;
327 enum ib_cm_state state; /* internal CM/debug use */
328 enum ib_cm_lap_state lap_state; /* internal CM/debug use */
331 u32 remote_cm_qpn; /* 1 unless redirected */
335 * ib_create_cm_id - Allocate a communication identifier.
336 * @device: Device associated with the cm_id. All related communication will
337 * be associated with the specified device.
338 * @cm_handler: Callback invoked to notify the user of CM events.
339 * @context: User specified context associated with the communication
342 * Communication identifiers are used to track connection states, service
343 * ID resolution requests, and listen requests.
345 struct ib_cm_id *ib_create_cm_id(struct ib_device *device,
346 ib_cm_handler cm_handler,
350 * ib_destroy_cm_id - Destroy a connection identifier.
351 * @cm_id: Connection identifier to destroy.
353 * This call blocks until the connection identifier is destroyed.
355 void ib_destroy_cm_id(struct ib_cm_id *cm_id);
357 #define IB_SERVICE_ID_AGN_MASK cpu_to_be64(0xFF00000000000000ULL)
358 #define IB_CM_ASSIGN_SERVICE_ID cpu_to_be64(0x0200000000000000ULL)
359 #define IB_CMA_SERVICE_ID cpu_to_be64(0x0000000001000000ULL)
360 #define IB_CMA_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFF000000ULL)
361 #define IB_SDP_SERVICE_ID cpu_to_be64(0x0000000000010000ULL)
362 #define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL)
365 * ib_cm_listen - Initiates listening on the specified service ID for
366 * connection and service ID resolution requests.
367 * @cm_id: Connection identifier associated with the listen request.
368 * @service_id: Service identifier matched against incoming connection
369 * and service ID resolution requests. The service ID should be specified
370 * network-byte order. If set to IB_CM_ASSIGN_SERVICE_ID, the CM will
371 * assign a service ID to the caller.
372 * @service_mask: Mask applied to service ID used to listen across a
373 * range of service IDs. If set to 0, the service ID is matched
374 * exactly. This parameter is ignored if %service_id is set to
375 * IB_CM_ASSIGN_SERVICE_ID.
377 int ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id,
378 __be64 service_mask);
380 struct ib_cm_id *ib_cm_insert_listen(struct ib_device *device,
381 ib_cm_handler cm_handler,
384 struct ib_cm_req_param {
385 struct ib_sa_path_rec *primary_path;
386 struct ib_sa_path_rec *alternate_path;
389 enum ib_qp_type qp_type;
391 const void *private_data;
394 u8 responder_resources;
396 u8 remote_cm_response_timeout;
398 u8 local_cm_response_timeout;
406 * ib_send_cm_req - Sends a connection request to the remote node.
407 * @cm_id: Connection identifier that will be associated with the
408 * connection request.
409 * @param: Connection request information needed to establish the
412 int ib_send_cm_req(struct ib_cm_id *cm_id,
413 struct ib_cm_req_param *param);
415 struct ib_cm_rep_param {
418 const void *private_data;
420 u8 responder_resources;
422 u8 failover_accepted;
429 * ib_send_cm_rep - Sends a connection reply in response to a connection
431 * @cm_id: Connection identifier that will be associated with the
432 * connection request.
433 * @param: Connection reply information needed to establish the
436 int ib_send_cm_rep(struct ib_cm_id *cm_id,
437 struct ib_cm_rep_param *param);
440 * ib_send_cm_rtu - Sends a connection ready to use message in response
441 * to a connection reply message.
442 * @cm_id: Connection identifier associated with the connection request.
443 * @private_data: Optional user-defined private data sent with the
444 * ready to use message.
445 * @private_data_len: Size of the private data buffer, in bytes.
447 int ib_send_cm_rtu(struct ib_cm_id *cm_id,
448 const void *private_data,
449 u8 private_data_len);
452 * ib_send_cm_dreq - Sends a disconnection request for an existing
454 * @cm_id: Connection identifier associated with the connection being
456 * @private_data: Optional user-defined private data sent with the
457 * disconnection request message.
458 * @private_data_len: Size of the private data buffer, in bytes.
460 int ib_send_cm_dreq(struct ib_cm_id *cm_id,
461 const void *private_data,
462 u8 private_data_len);
465 * ib_send_cm_drep - Sends a disconnection reply to a disconnection request.
466 * @cm_id: Connection identifier associated with the connection being
468 * @private_data: Optional user-defined private data sent with the
469 * disconnection reply message.
470 * @private_data_len: Size of the private data buffer, in bytes.
472 * If the cm_id is in the correct state, the CM will transition the connection
473 * to the timewait state, even if an error occurs sending the DREP message.
475 int ib_send_cm_drep(struct ib_cm_id *cm_id,
476 const void *private_data,
477 u8 private_data_len);
480 * ib_cm_notify - Notifies the CM of an event reported to the consumer.
481 * @cm_id: Connection identifier to transition to established.
482 * @event: Type of event.
484 * This routine should be invoked by users to notify the CM of relevant
485 * communication events. Events that should be reported to the CM and
486 * when to report them are:
488 * IB_EVENT_COMM_EST - Used when a message is received on a connected
489 * QP before an RTU has been received.
490 * IB_EVENT_PATH_MIG - Notifies the CM that the connection has failed over
491 * to the alternate path.
493 int ib_cm_notify(struct ib_cm_id *cm_id, enum ib_event_type event);
496 * ib_send_cm_rej - Sends a connection rejection message to the
498 * @cm_id: Connection identifier associated with the connection being
500 * @reason: Reason for the connection request rejection.
501 * @ari: Optional additional rejection information.
502 * @ari_length: Size of the additional rejection information, in bytes.
503 * @private_data: Optional user-defined private data sent with the
505 * @private_data_len: Size of the private data buffer, in bytes.
507 int ib_send_cm_rej(struct ib_cm_id *cm_id,
508 enum ib_cm_rej_reason reason,
511 const void *private_data,
512 u8 private_data_len);
514 #define IB_CM_MRA_FLAG_DELAY 0x80 /* Send MRA only after a duplicate msg */
517 * ib_send_cm_mra - Sends a message receipt acknowledgement to a connection
519 * @cm_id: Connection identifier associated with the connection message.
520 * @service_timeout: The lower 5-bits specify the maximum time required for
521 * the sender to reply to the connection message. The upper 3-bits
522 * specify additional control flags.
523 * @private_data: Optional user-defined private data sent with the
524 * message receipt acknowledgement.
525 * @private_data_len: Size of the private data buffer, in bytes.
527 int ib_send_cm_mra(struct ib_cm_id *cm_id,
529 const void *private_data,
530 u8 private_data_len);
533 * ib_send_cm_lap - Sends a load alternate path request.
534 * @cm_id: Connection identifier associated with the load alternate path
536 * @alternate_path: A path record that identifies the alternate path to
538 * @private_data: Optional user-defined private data sent with the
539 * load alternate path message.
540 * @private_data_len: Size of the private data buffer, in bytes.
542 int ib_send_cm_lap(struct ib_cm_id *cm_id,
543 struct ib_sa_path_rec *alternate_path,
544 const void *private_data,
545 u8 private_data_len);
548 * ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning
549 * to a specified QP state.
550 * @cm_id: Communication identifier associated with the QP attributes to
552 * @qp_attr: On input, specifies the desired QP state. On output, the
553 * mandatory and desired optional attributes will be set in order to
554 * modify the QP to the specified state.
555 * @qp_attr_mask: The QP attribute mask that may be used to transition the
556 * QP to the specified state.
558 * Users must set the @qp_attr->qp_state to the desired QP state. This call
559 * will set all required attributes for the given transition, along with
560 * known optional attributes. Users may override the attributes returned from
561 * this call before calling ib_modify_qp.
563 int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
564 struct ib_qp_attr *qp_attr,
568 * ib_send_cm_apr - Sends an alternate path response message in response to
569 * a load alternate path request.
570 * @cm_id: Connection identifier associated with the alternate path response.
571 * @status: Reply status sent with the alternate path response.
572 * @info: Optional additional information sent with the alternate path
574 * @info_length: Size of the additional information, in bytes.
575 * @private_data: Optional user-defined private data sent with the
576 * alternate path response message.
577 * @private_data_len: Size of the private data buffer, in bytes.
579 int ib_send_cm_apr(struct ib_cm_id *cm_id,
580 enum ib_cm_apr_status status,
583 const void *private_data,
584 u8 private_data_len);
586 struct ib_cm_sidr_req_param {
587 struct ib_sa_path_rec *path;
590 const void *private_data;
596 * ib_send_cm_sidr_req - Sends a service ID resolution request to the
598 * @cm_id: Communication identifier that will be associated with the
599 * service ID resolution request.
600 * @param: Service ID resolution request information.
602 int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
603 struct ib_cm_sidr_req_param *param);
605 struct ib_cm_sidr_rep_param {
608 enum ib_cm_sidr_status status;
611 const void *private_data;
616 * ib_send_cm_sidr_rep - Sends a service ID resolution reply to the
618 * @cm_id: Communication identifier associated with the received service ID
619 * resolution request.
620 * @param: Service ID resolution reply information.
622 int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
623 struct ib_cm_sidr_rep_param *param);
626 * ibcm_reject_msg - return a pointer to a reject message string.
627 * @reason: Value returned in the REJECT event status field.
629 const char *__attribute_const__ ibcm_reject_msg(int reason);