1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
3 * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.
4 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
5 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
6 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
7 * Copyright (c) 2019, Mellanox Technologies inc. All rights reserved.
12 #include <rdma/ib_mad.h>
13 #include <rdma/ib_sa.h>
14 #include <rdma/rdma_cm.h>
16 /* ib_cm and ib_user_cm modules share /sys/class/infiniband_cm */
17 extern struct class cm_class
;
38 enum ib_cm_lap_state
{
47 enum ib_cm_event_type
{
53 IB_CM_USER_ESTABLISHED
,
64 IB_CM_SIDR_REQ_RECEIVED
,
65 IB_CM_SIDR_REP_RECEIVED
68 enum ib_cm_data_size
{
69 IB_CM_REQ_PRIVATE_DATA_SIZE
= 92,
70 IB_CM_MRA_PRIVATE_DATA_SIZE
= 222,
71 IB_CM_REJ_PRIVATE_DATA_SIZE
= 148,
72 IB_CM_REP_PRIVATE_DATA_SIZE
= 196,
73 IB_CM_RTU_PRIVATE_DATA_SIZE
= 224,
74 IB_CM_DREQ_PRIVATE_DATA_SIZE
= 220,
75 IB_CM_DREP_PRIVATE_DATA_SIZE
= 224,
76 IB_CM_REJ_ARI_LENGTH
= 72,
77 IB_CM_LAP_PRIVATE_DATA_SIZE
= 168,
78 IB_CM_APR_PRIVATE_DATA_SIZE
= 148,
79 IB_CM_APR_INFO_LENGTH
= 72,
80 IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE
= 216,
81 IB_CM_SIDR_REP_PRIVATE_DATA_SIZE
= 136,
82 IB_CM_SIDR_REP_INFO_LENGTH
= 72,
87 struct ib_cm_req_event_param
{
88 struct ib_cm_id
*listen_id
;
90 /* P_Key that was used by the GMP's BTH header */
95 struct sa_path_rec
*primary_path
;
96 struct sa_path_rec
*alternate_path
;
99 * SGID attribute of the primary path. Currently only
100 * useful for RoCE. Alternate path GID attributes
101 * are not yet supported.
103 const struct ib_gid_attr
*ppath_sgid_attr
;
105 __be64 remote_ca_guid
;
108 enum ib_qp_type qp_type
;
111 u8 responder_resources
;
113 unsigned int local_cm_response_timeout
:5;
114 unsigned int flow_control
:1;
115 unsigned int remote_cm_response_timeout
:5;
116 unsigned int retry_count
:3;
117 unsigned int rnr_retry_count
:3;
119 struct rdma_ucm_ece ece
;
122 struct ib_cm_rep_event_param
{
123 __be64 remote_ca_guid
;
127 u8 responder_resources
;
129 unsigned int target_ack_delay
:5;
130 unsigned int failover_accepted
:2;
131 unsigned int flow_control
:1;
132 unsigned int rnr_retry_count
:3;
134 struct rdma_ucm_ece ece
;
137 enum ib_cm_rej_reason
{
139 IB_CM_REJ_NO_EEC
= 2,
140 IB_CM_REJ_NO_RESOURCES
= 3,
141 IB_CM_REJ_TIMEOUT
= 4,
142 IB_CM_REJ_UNSUPPORTED
= 5,
143 IB_CM_REJ_INVALID_COMM_ID
= 6,
144 IB_CM_REJ_INVALID_COMM_INSTANCE
= 7,
145 IB_CM_REJ_INVALID_SERVICE_ID
= 8,
146 IB_CM_REJ_INVALID_TRANSPORT_TYPE
= 9,
147 IB_CM_REJ_STALE_CONN
= 10,
148 IB_CM_REJ_RDC_NOT_EXIST
= 11,
149 IB_CM_REJ_INVALID_GID
= 12,
150 IB_CM_REJ_INVALID_LID
= 13,
151 IB_CM_REJ_INVALID_SL
= 14,
152 IB_CM_REJ_INVALID_TRAFFIC_CLASS
= 15,
153 IB_CM_REJ_INVALID_HOP_LIMIT
= 16,
154 IB_CM_REJ_INVALID_PACKET_RATE
= 17,
155 IB_CM_REJ_INVALID_ALT_GID
= 18,
156 IB_CM_REJ_INVALID_ALT_LID
= 19,
157 IB_CM_REJ_INVALID_ALT_SL
= 20,
158 IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS
= 21,
159 IB_CM_REJ_INVALID_ALT_HOP_LIMIT
= 22,
160 IB_CM_REJ_INVALID_ALT_PACKET_RATE
= 23,
161 IB_CM_REJ_PORT_CM_REDIRECT
= 24,
162 IB_CM_REJ_PORT_REDIRECT
= 25,
163 IB_CM_REJ_INVALID_MTU
= 26,
164 IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES
= 27,
165 IB_CM_REJ_CONSUMER_DEFINED
= 28,
166 IB_CM_REJ_INVALID_RNR_RETRY
= 29,
167 IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID
= 30,
168 IB_CM_REJ_INVALID_CLASS_VERSION
= 31,
169 IB_CM_REJ_INVALID_FLOW_LABEL
= 32,
170 IB_CM_REJ_INVALID_ALT_FLOW_LABEL
= 33,
171 IB_CM_REJ_VENDOR_OPTION_NOT_SUPPORTED
= 35,
174 struct ib_cm_rej_event_param
{
175 enum ib_cm_rej_reason reason
;
180 struct ib_cm_mra_event_param
{
184 struct ib_cm_lap_event_param
{
185 struct sa_path_rec
*alternate_path
;
188 enum ib_cm_apr_status
{
190 IB_CM_APR_INVALID_COMM_ID
,
191 IB_CM_APR_UNSUPPORTED
,
194 IB_CM_APR_IS_CURRENT
,
195 IB_CM_APR_INVALID_QPN_EECN
,
196 IB_CM_APR_INVALID_LID
,
197 IB_CM_APR_INVALID_GID
,
198 IB_CM_APR_INVALID_FLOW_LABEL
,
199 IB_CM_APR_INVALID_TCLASS
,
200 IB_CM_APR_INVALID_HOP_LIMIT
,
201 IB_CM_APR_INVALID_PACKET_RATE
,
205 struct ib_cm_apr_event_param
{
206 enum ib_cm_apr_status ap_status
;
211 struct ib_cm_sidr_req_event_param
{
212 struct ib_cm_id
*listen_id
;
216 * SGID attribute of the request. Currently only
219 const struct ib_gid_attr
*sgid_attr
;
220 /* P_Key that was used by the GMP's BTH header */
226 enum ib_cm_sidr_status
{
232 IB_SIDR_UNSUPPORTED_VERSION
235 struct ib_cm_sidr_rep_event_param
{
236 enum ib_cm_sidr_status status
;
240 const struct ib_gid_attr
*sgid_attr
;
245 enum ib_cm_event_type event
;
247 struct ib_cm_req_event_param req_rcvd
;
248 struct ib_cm_rep_event_param rep_rcvd
;
249 /* No data for RTU received events. */
250 struct ib_cm_rej_event_param rej_rcvd
;
251 struct ib_cm_mra_event_param mra_rcvd
;
252 struct ib_cm_lap_event_param lap_rcvd
;
253 struct ib_cm_apr_event_param apr_rcvd
;
254 /* No data for DREQ/DREP received events. */
255 struct ib_cm_sidr_req_event_param sidr_req_rcvd
;
256 struct ib_cm_sidr_rep_event_param sidr_rep_rcvd
;
257 enum ib_wc_status send_status
;
263 #define CM_REQ_ATTR_ID cpu_to_be16(0x0010)
264 #define CM_MRA_ATTR_ID cpu_to_be16(0x0011)
265 #define CM_REJ_ATTR_ID cpu_to_be16(0x0012)
266 #define CM_REP_ATTR_ID cpu_to_be16(0x0013)
267 #define CM_RTU_ATTR_ID cpu_to_be16(0x0014)
268 #define CM_DREQ_ATTR_ID cpu_to_be16(0x0015)
269 #define CM_DREP_ATTR_ID cpu_to_be16(0x0016)
270 #define CM_SIDR_REQ_ATTR_ID cpu_to_be16(0x0017)
271 #define CM_SIDR_REP_ATTR_ID cpu_to_be16(0x0018)
272 #define CM_LAP_ATTR_ID cpu_to_be16(0x0019)
273 #define CM_APR_ATTR_ID cpu_to_be16(0x001A)
276 * ib_cm_handler - User-defined callback to process communication events.
277 * @cm_id: Communication identifier associated with the reported event.
278 * @event: Information about the communication event.
280 * IB_CM_REQ_RECEIVED and IB_CM_SIDR_REQ_RECEIVED communication events
281 * generated as a result of listen requests result in the allocation of a
282 * new @cm_id. The new @cm_id is returned to the user through this callback.
283 * Clients are responsible for destroying the new @cm_id. For peer-to-peer
284 * IB_CM_REQ_RECEIVED and all other events, the returned @cm_id corresponds
285 * to a user's existing communication identifier.
287 * Users may not call ib_destroy_cm_id while in the context of this callback;
288 * however, returning a non-zero value instructs the communication manager to
289 * destroy the @cm_id after the callback completes.
291 typedef int (*ib_cm_handler
)(struct ib_cm_id
*cm_id
,
292 const struct ib_cm_event
*event
);
295 ib_cm_handler cm_handler
;
297 struct ib_device
*device
;
300 enum ib_cm_state state
; /* internal CM/debug use */
301 enum ib_cm_lap_state lap_state
; /* internal CM/debug use */
304 u32 remote_cm_qpn
; /* 1 unless redirected */
308 * ib_create_cm_id - Allocate a communication identifier.
309 * @device: Device associated with the cm_id. All related communication will
310 * be associated with the specified device.
311 * @cm_handler: Callback invoked to notify the user of CM events.
312 * @context: User specified context associated with the communication
315 * Communication identifiers are used to track connection states, service
316 * ID resolution requests, and listen requests.
318 struct ib_cm_id
*ib_create_cm_id(struct ib_device
*device
,
319 ib_cm_handler cm_handler
,
323 * ib_destroy_cm_id - Destroy a connection identifier.
324 * @cm_id: Connection identifier to destroy.
326 * This call blocks until the connection identifier is destroyed.
328 void ib_destroy_cm_id(struct ib_cm_id
*cm_id
);
330 #define IB_SERVICE_ID_AGN_MASK cpu_to_be64(0xFF00000000000000ULL)
331 #define IB_CM_ASSIGN_SERVICE_ID cpu_to_be64(0x0200000000000000ULL)
332 #define IB_CMA_SERVICE_ID cpu_to_be64(0x0000000001000000ULL)
333 #define IB_CMA_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFF000000ULL)
334 #define IB_SDP_SERVICE_ID cpu_to_be64(0x0000000000010000ULL)
335 #define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL)
338 * ib_cm_listen - Initiates listening on the specified service ID for
339 * connection and service ID resolution requests.
340 * @cm_id: Connection identifier associated with the listen request.
341 * @service_id: Service identifier matched against incoming connection
342 * and service ID resolution requests. The service ID should be specified
343 * network-byte order. If set to IB_CM_ASSIGN_SERVICE_ID, the CM will
344 * assign a service ID to the caller.
345 * @service_mask: Mask applied to service ID used to listen across a
346 * range of service IDs. If set to 0, the service ID is matched
347 * exactly. This parameter is ignored if %service_id is set to
348 * IB_CM_ASSIGN_SERVICE_ID.
350 int ib_cm_listen(struct ib_cm_id
*cm_id
, __be64 service_id
,
351 __be64 service_mask
);
353 struct ib_cm_id
*ib_cm_insert_listen(struct ib_device
*device
,
354 ib_cm_handler cm_handler
,
357 struct ib_cm_req_param
{
358 struct sa_path_rec
*primary_path
;
359 struct sa_path_rec
*alternate_path
;
360 const struct ib_gid_attr
*ppath_sgid_attr
;
363 enum ib_qp_type qp_type
;
365 const void *private_data
;
367 u8 responder_resources
;
369 u8 remote_cm_response_timeout
;
371 u8 local_cm_response_timeout
;
376 struct rdma_ucm_ece ece
;
380 * ib_send_cm_req - Sends a connection request to the remote node.
381 * @cm_id: Connection identifier that will be associated with the
382 * connection request.
383 * @param: Connection request information needed to establish the
386 int ib_send_cm_req(struct ib_cm_id
*cm_id
,
387 struct ib_cm_req_param
*param
);
389 struct ib_cm_rep_param
{
392 const void *private_data
;
394 u8 responder_resources
;
396 u8 failover_accepted
;
400 struct rdma_ucm_ece ece
;
404 * ib_send_cm_rep - Sends a connection reply in response to a connection
406 * @cm_id: Connection identifier that will be associated with the
407 * connection request.
408 * @param: Connection reply information needed to establish the
411 int ib_send_cm_rep(struct ib_cm_id
*cm_id
,
412 struct ib_cm_rep_param
*param
);
415 * ib_send_cm_rtu - Sends a connection ready to use message in response
416 * to a connection reply message.
417 * @cm_id: Connection identifier associated with the connection request.
418 * @private_data: Optional user-defined private data sent with the
419 * ready to use message.
420 * @private_data_len: Size of the private data buffer, in bytes.
422 int ib_send_cm_rtu(struct ib_cm_id
*cm_id
,
423 const void *private_data
,
424 u8 private_data_len
);
427 * ib_send_cm_dreq - Sends a disconnection request for an existing
429 * @cm_id: Connection identifier associated with the connection being
431 * @private_data: Optional user-defined private data sent with the
432 * disconnection request message.
433 * @private_data_len: Size of the private data buffer, in bytes.
435 int ib_send_cm_dreq(struct ib_cm_id
*cm_id
,
436 const void *private_data
,
437 u8 private_data_len
);
440 * ib_send_cm_drep - Sends a disconnection reply to a disconnection request.
441 * @cm_id: Connection identifier associated with the connection being
443 * @private_data: Optional user-defined private data sent with the
444 * disconnection reply message.
445 * @private_data_len: Size of the private data buffer, in bytes.
447 * If the cm_id is in the correct state, the CM will transition the connection
448 * to the timewait state, even if an error occurs sending the DREP message.
450 int ib_send_cm_drep(struct ib_cm_id
*cm_id
,
451 const void *private_data
,
452 u8 private_data_len
);
455 * ib_cm_notify - Notifies the CM of an event reported to the consumer.
456 * @cm_id: Connection identifier to transition to established.
457 * @event: Type of event.
459 * This routine should be invoked by users to notify the CM of relevant
460 * communication events. Events that should be reported to the CM and
461 * when to report them are:
463 * IB_EVENT_COMM_EST - Used when a message is received on a connected
464 * QP before an RTU has been received.
465 * IB_EVENT_PATH_MIG - Notifies the CM that the connection has failed over
466 * to the alternate path.
468 int ib_cm_notify(struct ib_cm_id
*cm_id
, enum ib_event_type event
);
471 * ib_send_cm_rej - Sends a connection rejection message to the
473 * @cm_id: Connection identifier associated with the connection being
475 * @reason: Reason for the connection request rejection.
476 * @ari: Optional additional rejection information.
477 * @ari_length: Size of the additional rejection information, in bytes.
478 * @private_data: Optional user-defined private data sent with the
480 * @private_data_len: Size of the private data buffer, in bytes.
482 int ib_send_cm_rej(struct ib_cm_id
*cm_id
,
483 enum ib_cm_rej_reason reason
,
486 const void *private_data
,
487 u8 private_data_len
);
489 #define IB_CM_MRA_FLAG_DELAY 0x80 /* Send MRA only after a duplicate msg */
492 * ib_send_cm_mra - Sends a message receipt acknowledgement to a connection
494 * @cm_id: Connection identifier associated with the connection message.
495 * @service_timeout: The lower 5-bits specify the maximum time required for
496 * the sender to reply to the connection message. The upper 3-bits
497 * specify additional control flags.
498 * @private_data: Optional user-defined private data sent with the
499 * message receipt acknowledgement.
500 * @private_data_len: Size of the private data buffer, in bytes.
502 int ib_send_cm_mra(struct ib_cm_id
*cm_id
,
504 const void *private_data
,
505 u8 private_data_len
);
508 * ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning
509 * to a specified QP state.
510 * @cm_id: Communication identifier associated with the QP attributes to
512 * @qp_attr: On input, specifies the desired QP state. On output, the
513 * mandatory and desired optional attributes will be set in order to
514 * modify the QP to the specified state.
515 * @qp_attr_mask: The QP attribute mask that may be used to transition the
516 * QP to the specified state.
518 * Users must set the @qp_attr->qp_state to the desired QP state. This call
519 * will set all required attributes for the given transition, along with
520 * known optional attributes. Users may override the attributes returned from
521 * this call before calling ib_modify_qp.
523 int ib_cm_init_qp_attr(struct ib_cm_id
*cm_id
,
524 struct ib_qp_attr
*qp_attr
,
527 struct ib_cm_sidr_req_param
{
528 struct sa_path_rec
*path
;
529 const struct ib_gid_attr
*sgid_attr
;
531 unsigned long timeout_ms
;
532 const void *private_data
;
538 * ib_send_cm_sidr_req - Sends a service ID resolution request to the
540 * @cm_id: Communication identifier that will be associated with the
541 * service ID resolution request.
542 * @param: Service ID resolution request information.
544 int ib_send_cm_sidr_req(struct ib_cm_id
*cm_id
,
545 struct ib_cm_sidr_req_param
*param
);
547 struct ib_cm_sidr_rep_param
{
550 enum ib_cm_sidr_status status
;
553 const void *private_data
;
555 struct rdma_ucm_ece ece
;
559 * ib_send_cm_sidr_rep - Sends a service ID resolution reply to the
561 * @cm_id: Communication identifier associated with the received service ID
562 * resolution request.
563 * @param: Service ID resolution reply information.
565 int ib_send_cm_sidr_rep(struct ib_cm_id
*cm_id
,
566 struct ib_cm_sidr_rep_param
*param
);
569 * ibcm_reject_msg - return a pointer to a reject message string.
570 * @reason: Value returned in the REJECT event status field.
572 const char *__attribute_const__
ibcm_reject_msg(int reason
);