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.
13 #include <rdma/ib_mad.h>
14 #include <rdma/ib_sa.h>
15 #include <rdma/rdma_cm.h>
17 /* ib_cm and ib_user_cm modules share /sys/class/infiniband_cm */
18 extern struct class cm_class;
39 enum ib_cm_lap_state {
48 enum ib_cm_event_type {
54 IB_CM_USER_ESTABLISHED,
65 IB_CM_SIDR_REQ_RECEIVED,
66 IB_CM_SIDR_REP_RECEIVED
69 enum ib_cm_data_size {
70 IB_CM_REQ_PRIVATE_DATA_SIZE = 92,
71 IB_CM_MRA_PRIVATE_DATA_SIZE = 222,
72 IB_CM_REJ_PRIVATE_DATA_SIZE = 148,
73 IB_CM_REP_PRIVATE_DATA_SIZE = 196,
74 IB_CM_RTU_PRIVATE_DATA_SIZE = 224,
75 IB_CM_DREQ_PRIVATE_DATA_SIZE = 220,
76 IB_CM_DREP_PRIVATE_DATA_SIZE = 224,
77 IB_CM_REJ_ARI_LENGTH = 72,
78 IB_CM_LAP_PRIVATE_DATA_SIZE = 168,
79 IB_CM_APR_PRIVATE_DATA_SIZE = 148,
80 IB_CM_APR_INFO_LENGTH = 72,
81 IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE = 216,
82 IB_CM_SIDR_REP_PRIVATE_DATA_SIZE = 136,
83 IB_CM_SIDR_REP_INFO_LENGTH = 72,
88 struct ib_cm_req_event_param {
89 struct ib_cm_id *listen_id;
91 /* P_Key that was used by the GMP's BTH header */
96 struct sa_path_rec *primary_path;
97 struct sa_path_rec *alternate_path;
100 * SGID attribute of the primary path. Currently only
101 * useful for RoCE. Alternate path GID attributes
102 * are not yet supported.
104 const struct ib_gid_attr *ppath_sgid_attr;
106 __be64 remote_ca_guid;
109 enum ib_qp_type qp_type;
112 u8 responder_resources;
114 unsigned int local_cm_response_timeout:5;
115 unsigned int flow_control:1;
116 unsigned int remote_cm_response_timeout:5;
117 unsigned int retry_count:3;
118 unsigned int rnr_retry_count:3;
120 struct rdma_ucm_ece ece;
123 struct ib_cm_rep_event_param {
124 __be64 remote_ca_guid;
128 u8 responder_resources;
130 unsigned int target_ack_delay:5;
131 unsigned int failover_accepted:2;
132 unsigned int flow_control:1;
133 unsigned int rnr_retry_count:3;
135 struct rdma_ucm_ece ece;
138 enum ib_cm_rej_reason {
140 IB_CM_REJ_NO_EEC = 2,
141 IB_CM_REJ_NO_RESOURCES = 3,
142 IB_CM_REJ_TIMEOUT = 4,
143 IB_CM_REJ_UNSUPPORTED = 5,
144 IB_CM_REJ_INVALID_COMM_ID = 6,
145 IB_CM_REJ_INVALID_COMM_INSTANCE = 7,
146 IB_CM_REJ_INVALID_SERVICE_ID = 8,
147 IB_CM_REJ_INVALID_TRANSPORT_TYPE = 9,
148 IB_CM_REJ_STALE_CONN = 10,
149 IB_CM_REJ_RDC_NOT_EXIST = 11,
150 IB_CM_REJ_INVALID_GID = 12,
151 IB_CM_REJ_INVALID_LID = 13,
152 IB_CM_REJ_INVALID_SL = 14,
153 IB_CM_REJ_INVALID_TRAFFIC_CLASS = 15,
154 IB_CM_REJ_INVALID_HOP_LIMIT = 16,
155 IB_CM_REJ_INVALID_PACKET_RATE = 17,
156 IB_CM_REJ_INVALID_ALT_GID = 18,
157 IB_CM_REJ_INVALID_ALT_LID = 19,
158 IB_CM_REJ_INVALID_ALT_SL = 20,
159 IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS = 21,
160 IB_CM_REJ_INVALID_ALT_HOP_LIMIT = 22,
161 IB_CM_REJ_INVALID_ALT_PACKET_RATE = 23,
162 IB_CM_REJ_PORT_CM_REDIRECT = 24,
163 IB_CM_REJ_PORT_REDIRECT = 25,
164 IB_CM_REJ_INVALID_MTU = 26,
165 IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES = 27,
166 IB_CM_REJ_CONSUMER_DEFINED = 28,
167 IB_CM_REJ_INVALID_RNR_RETRY = 29,
168 IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID = 30,
169 IB_CM_REJ_INVALID_CLASS_VERSION = 31,
170 IB_CM_REJ_INVALID_FLOW_LABEL = 32,
171 IB_CM_REJ_INVALID_ALT_FLOW_LABEL = 33,
172 IB_CM_REJ_VENDOR_OPTION_NOT_SUPPORTED = 35,
175 struct ib_cm_rej_event_param {
176 enum ib_cm_rej_reason reason;
181 struct ib_cm_mra_event_param {
185 struct ib_cm_lap_event_param {
186 struct sa_path_rec *alternate_path;
189 enum ib_cm_apr_status {
191 IB_CM_APR_INVALID_COMM_ID,
192 IB_CM_APR_UNSUPPORTED,
195 IB_CM_APR_IS_CURRENT,
196 IB_CM_APR_INVALID_QPN_EECN,
197 IB_CM_APR_INVALID_LID,
198 IB_CM_APR_INVALID_GID,
199 IB_CM_APR_INVALID_FLOW_LABEL,
200 IB_CM_APR_INVALID_TCLASS,
201 IB_CM_APR_INVALID_HOP_LIMIT,
202 IB_CM_APR_INVALID_PACKET_RATE,
206 struct ib_cm_apr_event_param {
207 enum ib_cm_apr_status ap_status;
212 struct ib_cm_sidr_req_event_param {
213 struct ib_cm_id *listen_id;
217 * SGID attribute of the request. Currently only
220 const struct ib_gid_attr *sgid_attr;
221 /* P_Key that was used by the GMP's BTH header */
227 enum ib_cm_sidr_status {
233 IB_SIDR_UNSUPPORTED_VERSION
236 struct ib_cm_sidr_rep_event_param {
237 enum ib_cm_sidr_status status;
241 const struct ib_gid_attr *sgid_attr;
246 enum ib_cm_event_type event;
248 struct ib_cm_req_event_param req_rcvd;
249 struct ib_cm_rep_event_param rep_rcvd;
250 /* No data for RTU received events. */
251 struct ib_cm_rej_event_param rej_rcvd;
252 struct ib_cm_mra_event_param mra_rcvd;
253 struct ib_cm_lap_event_param lap_rcvd;
254 struct ib_cm_apr_event_param apr_rcvd;
255 /* No data for DREQ/DREP received events. */
256 struct ib_cm_sidr_req_event_param sidr_req_rcvd;
257 struct ib_cm_sidr_rep_event_param sidr_rep_rcvd;
258 enum ib_wc_status send_status;
264 #define CM_REQ_ATTR_ID cpu_to_be16(0x0010)
265 #define CM_MRA_ATTR_ID cpu_to_be16(0x0011)
266 #define CM_REJ_ATTR_ID cpu_to_be16(0x0012)
267 #define CM_REP_ATTR_ID cpu_to_be16(0x0013)
268 #define CM_RTU_ATTR_ID cpu_to_be16(0x0014)
269 #define CM_DREQ_ATTR_ID cpu_to_be16(0x0015)
270 #define CM_DREP_ATTR_ID cpu_to_be16(0x0016)
271 #define CM_SIDR_REQ_ATTR_ID cpu_to_be16(0x0017)
272 #define CM_SIDR_REP_ATTR_ID cpu_to_be16(0x0018)
273 #define CM_LAP_ATTR_ID cpu_to_be16(0x0019)
274 #define CM_APR_ATTR_ID cpu_to_be16(0x001A)
277 * ib_cm_handler - User-defined callback to process communication events.
278 * @cm_id: Communication identifier associated with the reported event.
279 * @event: Information about the communication event.
281 * IB_CM_REQ_RECEIVED and IB_CM_SIDR_REQ_RECEIVED communication events
282 * generated as a result of listen requests result in the allocation of a
283 * new @cm_id. The new @cm_id is returned to the user through this callback.
284 * Clients are responsible for destroying the new @cm_id. For peer-to-peer
285 * IB_CM_REQ_RECEIVED and all other events, the returned @cm_id corresponds
286 * to a user's existing communication identifier.
288 * Users may not call ib_destroy_cm_id while in the context of this callback;
289 * however, returning a non-zero value instructs the communication manager to
290 * destroy the @cm_id after the callback completes.
292 typedef int (*ib_cm_handler)(struct ib_cm_id *cm_id,
293 const struct ib_cm_event *event);
296 ib_cm_handler cm_handler;
298 struct ib_device *device;
301 enum ib_cm_state state; /* internal CM/debug use */
302 enum ib_cm_lap_state lap_state; /* internal CM/debug use */
305 u32 remote_cm_qpn; /* 1 unless redirected */
309 * ib_create_cm_id - Allocate a communication identifier.
310 * @device: Device associated with the cm_id. All related communication will
311 * be associated with the specified device.
312 * @cm_handler: Callback invoked to notify the user of CM events.
313 * @context: User specified context associated with the communication
316 * Communication identifiers are used to track connection states, service
317 * ID resolution requests, and listen requests.
319 struct ib_cm_id *ib_create_cm_id(struct ib_device *device,
320 ib_cm_handler cm_handler,
324 * ib_destroy_cm_id - Destroy a connection identifier.
325 * @cm_id: Connection identifier to destroy.
327 * This call blocks until the connection identifier is destroyed.
329 void ib_destroy_cm_id(struct ib_cm_id *cm_id);
331 #define IB_SERVICE_ID_AGN_MASK cpu_to_be64(0xFF00000000000000ULL)
332 #define IB_CM_ASSIGN_SERVICE_ID cpu_to_be64(0x0200000000000000ULL)
333 #define IB_CMA_SERVICE_ID cpu_to_be64(0x0000000001000000ULL)
334 #define IB_CMA_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFF000000ULL)
335 #define IB_SDP_SERVICE_ID cpu_to_be64(0x0000000000010000ULL)
336 #define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL)
339 * ib_cm_listen - Initiates listening on the specified service ID for
340 * connection and service ID resolution requests.
341 * @cm_id: Connection identifier associated with the listen request.
342 * @service_id: Service identifier matched against incoming connection
343 * and service ID resolution requests. The service ID should be specified
344 * network-byte order. If set to IB_CM_ASSIGN_SERVICE_ID, the CM will
345 * assign a service ID to the caller.
346 * @service_mask: Mask applied to service ID used to listen across a
347 * range of service IDs. If set to 0, the service ID is matched
348 * exactly. This parameter is ignored if %service_id is set to
349 * IB_CM_ASSIGN_SERVICE_ID.
351 int ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id,
352 __be64 service_mask);
354 struct ib_cm_id *ib_cm_insert_listen(struct ib_device *device,
355 ib_cm_handler cm_handler,
358 struct ib_cm_req_param {
359 struct sa_path_rec *primary_path;
360 struct sa_path_rec *alternate_path;
361 const struct ib_gid_attr *ppath_sgid_attr;
364 enum ib_qp_type qp_type;
366 const void *private_data;
368 u8 responder_resources;
370 u8 remote_cm_response_timeout;
372 u8 local_cm_response_timeout;
377 struct rdma_ucm_ece ece;
381 * ib_send_cm_req - Sends a connection request to the remote node.
382 * @cm_id: Connection identifier that will be associated with the
383 * connection request.
384 * @param: Connection request information needed to establish the
387 int ib_send_cm_req(struct ib_cm_id *cm_id,
388 struct ib_cm_req_param *param);
390 struct ib_cm_rep_param {
393 const void *private_data;
395 u8 responder_resources;
397 u8 failover_accepted;
401 struct rdma_ucm_ece ece;
405 * ib_send_cm_rep - Sends a connection reply in response to a connection
407 * @cm_id: Connection identifier that will be associated with the
408 * connection request.
409 * @param: Connection reply information needed to establish the
412 int ib_send_cm_rep(struct ib_cm_id *cm_id,
413 struct ib_cm_rep_param *param);
416 * ib_send_cm_rtu - Sends a connection ready to use message in response
417 * to a connection reply message.
418 * @cm_id: Connection identifier associated with the connection request.
419 * @private_data: Optional user-defined private data sent with the
420 * ready to use message.
421 * @private_data_len: Size of the private data buffer, in bytes.
423 int ib_send_cm_rtu(struct ib_cm_id *cm_id,
424 const void *private_data,
425 u8 private_data_len);
428 * ib_send_cm_dreq - Sends a disconnection request for an existing
430 * @cm_id: Connection identifier associated with the connection being
432 * @private_data: Optional user-defined private data sent with the
433 * disconnection request message.
434 * @private_data_len: Size of the private data buffer, in bytes.
436 int ib_send_cm_dreq(struct ib_cm_id *cm_id,
437 const void *private_data,
438 u8 private_data_len);
441 * ib_send_cm_drep - Sends a disconnection reply to a disconnection request.
442 * @cm_id: Connection identifier associated with the connection being
444 * @private_data: Optional user-defined private data sent with the
445 * disconnection reply message.
446 * @private_data_len: Size of the private data buffer, in bytes.
448 * If the cm_id is in the correct state, the CM will transition the connection
449 * to the timewait state, even if an error occurs sending the DREP message.
451 int ib_send_cm_drep(struct ib_cm_id *cm_id,
452 const void *private_data,
453 u8 private_data_len);
456 * ib_cm_notify - Notifies the CM of an event reported to the consumer.
457 * @cm_id: Connection identifier to transition to established.
458 * @event: Type of event.
460 * This routine should be invoked by users to notify the CM of relevant
461 * communication events. Events that should be reported to the CM and
462 * when to report them are:
464 * IB_EVENT_COMM_EST - Used when a message is received on a connected
465 * QP before an RTU has been received.
466 * IB_EVENT_PATH_MIG - Notifies the CM that the connection has failed over
467 * to the alternate path.
469 int ib_cm_notify(struct ib_cm_id *cm_id, enum ib_event_type event);
472 * ib_send_cm_rej - Sends a connection rejection message to the
474 * @cm_id: Connection identifier associated with the connection being
476 * @reason: Reason for the connection request rejection.
477 * @ari: Optional additional rejection information.
478 * @ari_length: Size of the additional rejection information, in bytes.
479 * @private_data: Optional user-defined private data sent with the
481 * @private_data_len: Size of the private data buffer, in bytes.
483 int ib_send_cm_rej(struct ib_cm_id *cm_id,
484 enum ib_cm_rej_reason reason,
487 const void *private_data,
488 u8 private_data_len);
490 #define IB_CM_MRA_FLAG_DELAY 0x80 /* Send MRA only after a duplicate msg */
493 * ib_send_cm_mra - Sends a message receipt acknowledgement to a connection
495 * @cm_id: Connection identifier associated with the connection message.
496 * @service_timeout: The lower 5-bits specify the maximum time required for
497 * the sender to reply to the connection message. The upper 3-bits
498 * specify additional control flags.
499 * @private_data: Optional user-defined private data sent with the
500 * message receipt acknowledgement.
501 * @private_data_len: Size of the private data buffer, in bytes.
503 int ib_send_cm_mra(struct ib_cm_id *cm_id,
505 const void *private_data,
506 u8 private_data_len);
509 * ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning
510 * to a specified QP state.
511 * @cm_id: Communication identifier associated with the QP attributes to
513 * @qp_attr: On input, specifies the desired QP state. On output, the
514 * mandatory and desired optional attributes will be set in order to
515 * modify the QP to the specified state.
516 * @qp_attr_mask: The QP attribute mask that may be used to transition the
517 * QP to the specified state.
519 * Users must set the @qp_attr->qp_state to the desired QP state. This call
520 * will set all required attributes for the given transition, along with
521 * known optional attributes. Users may override the attributes returned from
522 * this call before calling ib_modify_qp.
524 int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
525 struct ib_qp_attr *qp_attr,
528 struct ib_cm_sidr_req_param {
529 struct sa_path_rec *path;
530 const struct ib_gid_attr *sgid_attr;
532 unsigned long timeout_ms;
533 const void *private_data;
539 * ib_send_cm_sidr_req - Sends a service ID resolution request to the
541 * @cm_id: Communication identifier that will be associated with the
542 * service ID resolution request.
543 * @param: Service ID resolution request information.
545 int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
546 struct ib_cm_sidr_req_param *param);
548 struct ib_cm_sidr_rep_param {
551 enum ib_cm_sidr_status status;
554 const void *private_data;
556 struct rdma_ucm_ece ece;
560 * ib_send_cm_sidr_rep - Sends a service ID resolution reply to the
562 * @cm_id: Communication identifier associated with the received service ID
563 * resolution request.
564 * @param: Service ID resolution reply information.
566 int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
567 struct ib_cm_sidr_rep_param *param);
570 * ibcm_reject_msg - return a pointer to a reject message string.
571 * @reason: Value returned in the REJECT event status field.
573 const char *__attribute_const__ ibcm_reject_msg(int reason);