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;
128 __be64 remote_ca_guid;
131 enum ib_qp_type qp_type;
134 u8 responder_resources;
136 unsigned int local_cm_response_timeout:5;
137 unsigned int flow_control:1;
138 unsigned int remote_cm_response_timeout:5;
139 unsigned int retry_count:3;
140 unsigned int rnr_retry_count:3;
144 struct ib_cm_rep_event_param {
145 __be64 remote_ca_guid;
149 u8 responder_resources;
151 unsigned int target_ack_delay:5;
152 unsigned int failover_accepted:2;
153 unsigned int flow_control:1;
154 unsigned int rnr_retry_count:3;
158 enum ib_cm_rej_reason {
160 IB_CM_REJ_NO_EEC = 2,
161 IB_CM_REJ_NO_RESOURCES = 3,
162 IB_CM_REJ_TIMEOUT = 4,
163 IB_CM_REJ_UNSUPPORTED = 5,
164 IB_CM_REJ_INVALID_COMM_ID = 6,
165 IB_CM_REJ_INVALID_COMM_INSTANCE = 7,
166 IB_CM_REJ_INVALID_SERVICE_ID = 8,
167 IB_CM_REJ_INVALID_TRANSPORT_TYPE = 9,
168 IB_CM_REJ_STALE_CONN = 10,
169 IB_CM_REJ_RDC_NOT_EXIST = 11,
170 IB_CM_REJ_INVALID_GID = 12,
171 IB_CM_REJ_INVALID_LID = 13,
172 IB_CM_REJ_INVALID_SL = 14,
173 IB_CM_REJ_INVALID_TRAFFIC_CLASS = 15,
174 IB_CM_REJ_INVALID_HOP_LIMIT = 16,
175 IB_CM_REJ_INVALID_PACKET_RATE = 17,
176 IB_CM_REJ_INVALID_ALT_GID = 18,
177 IB_CM_REJ_INVALID_ALT_LID = 19,
178 IB_CM_REJ_INVALID_ALT_SL = 20,
179 IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS = 21,
180 IB_CM_REJ_INVALID_ALT_HOP_LIMIT = 22,
181 IB_CM_REJ_INVALID_ALT_PACKET_RATE = 23,
182 IB_CM_REJ_PORT_CM_REDIRECT = 24,
183 IB_CM_REJ_PORT_REDIRECT = 25,
184 IB_CM_REJ_INVALID_MTU = 26,
185 IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES = 27,
186 IB_CM_REJ_CONSUMER_DEFINED = 28,
187 IB_CM_REJ_INVALID_RNR_RETRY = 29,
188 IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID = 30,
189 IB_CM_REJ_INVALID_CLASS_VERSION = 31,
190 IB_CM_REJ_INVALID_FLOW_LABEL = 32,
191 IB_CM_REJ_INVALID_ALT_FLOW_LABEL = 33
194 struct ib_cm_rej_event_param {
195 enum ib_cm_rej_reason reason;
200 struct ib_cm_mra_event_param {
204 struct ib_cm_lap_event_param {
205 struct ib_sa_path_rec *alternate_path;
208 enum ib_cm_apr_status {
210 IB_CM_APR_INVALID_COMM_ID,
211 IB_CM_APR_UNSUPPORTED,
214 IB_CM_APR_IS_CURRENT,
215 IB_CM_APR_INVALID_QPN_EECN,
216 IB_CM_APR_INVALID_LID,
217 IB_CM_APR_INVALID_GID,
218 IB_CM_APR_INVALID_FLOW_LABEL,
219 IB_CM_APR_INVALID_TCLASS,
220 IB_CM_APR_INVALID_HOP_LIMIT,
221 IB_CM_APR_INVALID_PACKET_RATE,
225 struct ib_cm_apr_event_param {
226 enum ib_cm_apr_status ap_status;
231 struct ib_cm_sidr_req_event_param {
232 struct ib_cm_id *listen_id;
234 /* P_Key that was used by the GMP's BTH header */
240 enum ib_cm_sidr_status {
246 IB_SIDR_UNSUPPORTED_VERSION
249 struct ib_cm_sidr_rep_event_param {
250 enum ib_cm_sidr_status status;
258 enum ib_cm_event_type event;
260 struct ib_cm_req_event_param req_rcvd;
261 struct ib_cm_rep_event_param rep_rcvd;
262 /* No data for RTU received events. */
263 struct ib_cm_rej_event_param rej_rcvd;
264 struct ib_cm_mra_event_param mra_rcvd;
265 struct ib_cm_lap_event_param lap_rcvd;
266 struct ib_cm_apr_event_param apr_rcvd;
267 /* No data for DREQ/DREP received events. */
268 struct ib_cm_sidr_req_event_param sidr_req_rcvd;
269 struct ib_cm_sidr_rep_event_param sidr_rep_rcvd;
270 enum ib_wc_status send_status;
276 #define CM_REQ_ATTR_ID cpu_to_be16(0x0010)
277 #define CM_MRA_ATTR_ID cpu_to_be16(0x0011)
278 #define CM_REJ_ATTR_ID cpu_to_be16(0x0012)
279 #define CM_REP_ATTR_ID cpu_to_be16(0x0013)
280 #define CM_RTU_ATTR_ID cpu_to_be16(0x0014)
281 #define CM_DREQ_ATTR_ID cpu_to_be16(0x0015)
282 #define CM_DREP_ATTR_ID cpu_to_be16(0x0016)
283 #define CM_SIDR_REQ_ATTR_ID cpu_to_be16(0x0017)
284 #define CM_SIDR_REP_ATTR_ID cpu_to_be16(0x0018)
285 #define CM_LAP_ATTR_ID cpu_to_be16(0x0019)
286 #define CM_APR_ATTR_ID cpu_to_be16(0x001A)
289 * ib_cm_handler - User-defined callback to process communication events.
290 * @cm_id: Communication identifier associated with the reported event.
291 * @event: Information about the communication event.
293 * IB_CM_REQ_RECEIVED and IB_CM_SIDR_REQ_RECEIVED communication events
294 * generated as a result of listen requests result in the allocation of a
295 * new @cm_id. The new @cm_id is returned to the user through this callback.
296 * Clients are responsible for destroying the new @cm_id. For peer-to-peer
297 * IB_CM_REQ_RECEIVED and all other events, the returned @cm_id corresponds
298 * to a user's existing communication identifier.
300 * Users may not call ib_destroy_cm_id while in the context of this callback;
301 * however, returning a non-zero value instructs the communication manager to
302 * destroy the @cm_id after the callback completes.
304 typedef int (*ib_cm_handler)(struct ib_cm_id *cm_id,
305 struct ib_cm_event *event);
308 ib_cm_handler cm_handler;
310 struct ib_device *device;
313 enum ib_cm_state state; /* internal CM/debug use */
314 enum ib_cm_lap_state lap_state; /* internal CM/debug use */
317 u32 remote_cm_qpn; /* 1 unless redirected */
321 * ib_create_cm_id - Allocate a communication identifier.
322 * @device: Device associated with the cm_id. All related communication will
323 * be associated with the specified device.
324 * @cm_handler: Callback invoked to notify the user of CM events.
325 * @context: User specified context associated with the communication
328 * Communication identifiers are used to track connection states, service
329 * ID resolution requests, and listen requests.
331 struct ib_cm_id *ib_create_cm_id(struct ib_device *device,
332 ib_cm_handler cm_handler,
336 * ib_destroy_cm_id - Destroy a connection identifier.
337 * @cm_id: Connection identifier to destroy.
339 * This call blocks until the connection identifier is destroyed.
341 void ib_destroy_cm_id(struct ib_cm_id *cm_id);
343 #define IB_SERVICE_ID_AGN_MASK cpu_to_be64(0xFF00000000000000ULL)
344 #define IB_CM_ASSIGN_SERVICE_ID cpu_to_be64(0x0200000000000000ULL)
345 #define IB_CMA_SERVICE_ID cpu_to_be64(0x0000000001000000ULL)
346 #define IB_CMA_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFF000000ULL)
347 #define IB_SDP_SERVICE_ID cpu_to_be64(0x0000000000010000ULL)
348 #define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL)
351 * ib_cm_listen - Initiates listening on the specified service ID for
352 * connection and service ID resolution requests.
353 * @cm_id: Connection identifier associated with the listen request.
354 * @service_id: Service identifier matched against incoming connection
355 * and service ID resolution requests. The service ID should be specified
356 * network-byte order. If set to IB_CM_ASSIGN_SERVICE_ID, the CM will
357 * assign a service ID to the caller.
358 * @service_mask: Mask applied to service ID used to listen across a
359 * range of service IDs. If set to 0, the service ID is matched
360 * exactly. This parameter is ignored if %service_id is set to
361 * IB_CM_ASSIGN_SERVICE_ID.
363 int ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id,
364 __be64 service_mask);
366 struct ib_cm_id *ib_cm_insert_listen(struct ib_device *device,
367 ib_cm_handler cm_handler,
370 struct ib_cm_req_param {
371 struct ib_sa_path_rec *primary_path;
372 struct ib_sa_path_rec *alternate_path;
375 enum ib_qp_type qp_type;
377 const void *private_data;
380 u8 responder_resources;
382 u8 remote_cm_response_timeout;
384 u8 local_cm_response_timeout;
392 * ib_send_cm_req - Sends a connection request to the remote node.
393 * @cm_id: Connection identifier that will be associated with the
394 * connection request.
395 * @param: Connection request information needed to establish the
398 int ib_send_cm_req(struct ib_cm_id *cm_id,
399 struct ib_cm_req_param *param);
401 struct ib_cm_rep_param {
404 const void *private_data;
406 u8 responder_resources;
408 u8 failover_accepted;
415 * ib_send_cm_rep - Sends a connection reply in response to a connection
417 * @cm_id: Connection identifier that will be associated with the
418 * connection request.
419 * @param: Connection reply information needed to establish the
422 int ib_send_cm_rep(struct ib_cm_id *cm_id,
423 struct ib_cm_rep_param *param);
426 * ib_send_cm_rtu - Sends a connection ready to use message in response
427 * to a connection reply message.
428 * @cm_id: Connection identifier associated with the connection request.
429 * @private_data: Optional user-defined private data sent with the
430 * ready to use message.
431 * @private_data_len: Size of the private data buffer, in bytes.
433 int ib_send_cm_rtu(struct ib_cm_id *cm_id,
434 const void *private_data,
435 u8 private_data_len);
438 * ib_send_cm_dreq - Sends a disconnection request for an existing
440 * @cm_id: Connection identifier associated with the connection being
442 * @private_data: Optional user-defined private data sent with the
443 * disconnection request message.
444 * @private_data_len: Size of the private data buffer, in bytes.
446 int ib_send_cm_dreq(struct ib_cm_id *cm_id,
447 const void *private_data,
448 u8 private_data_len);
451 * ib_send_cm_drep - Sends a disconnection reply to a disconnection request.
452 * @cm_id: Connection identifier associated with the connection being
454 * @private_data: Optional user-defined private data sent with the
455 * disconnection reply message.
456 * @private_data_len: Size of the private data buffer, in bytes.
458 * If the cm_id is in the correct state, the CM will transition the connection
459 * to the timewait state, even if an error occurs sending the DREP message.
461 int ib_send_cm_drep(struct ib_cm_id *cm_id,
462 const void *private_data,
463 u8 private_data_len);
466 * ib_cm_notify - Notifies the CM of an event reported to the consumer.
467 * @cm_id: Connection identifier to transition to established.
468 * @event: Type of event.
470 * This routine should be invoked by users to notify the CM of relevant
471 * communication events. Events that should be reported to the CM and
472 * when to report them are:
474 * IB_EVENT_COMM_EST - Used when a message is received on a connected
475 * QP before an RTU has been received.
476 * IB_EVENT_PATH_MIG - Notifies the CM that the connection has failed over
477 * to the alternate path.
479 int ib_cm_notify(struct ib_cm_id *cm_id, enum ib_event_type event);
482 * ib_send_cm_rej - Sends a connection rejection message to the
484 * @cm_id: Connection identifier associated with the connection being
486 * @reason: Reason for the connection request rejection.
487 * @ari: Optional additional rejection information.
488 * @ari_length: Size of the additional rejection information, in bytes.
489 * @private_data: Optional user-defined private data sent with the
491 * @private_data_len: Size of the private data buffer, in bytes.
493 int ib_send_cm_rej(struct ib_cm_id *cm_id,
494 enum ib_cm_rej_reason reason,
497 const void *private_data,
498 u8 private_data_len);
500 #define IB_CM_MRA_FLAG_DELAY 0x80 /* Send MRA only after a duplicate msg */
503 * ib_send_cm_mra - Sends a message receipt acknowledgement to a connection
505 * @cm_id: Connection identifier associated with the connection message.
506 * @service_timeout: The lower 5-bits specify the maximum time required for
507 * the sender to reply to the connection message. The upper 3-bits
508 * specify additional control flags.
509 * @private_data: Optional user-defined private data sent with the
510 * message receipt acknowledgement.
511 * @private_data_len: Size of the private data buffer, in bytes.
513 int ib_send_cm_mra(struct ib_cm_id *cm_id,
515 const void *private_data,
516 u8 private_data_len);
519 * ib_send_cm_lap - Sends a load alternate path request.
520 * @cm_id: Connection identifier associated with the load alternate path
522 * @alternate_path: A path record that identifies the alternate path to
524 * @private_data: Optional user-defined private data sent with the
525 * load alternate path message.
526 * @private_data_len: Size of the private data buffer, in bytes.
528 int ib_send_cm_lap(struct ib_cm_id *cm_id,
529 struct ib_sa_path_rec *alternate_path,
530 const void *private_data,
531 u8 private_data_len);
534 * ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning
535 * to a specified QP state.
536 * @cm_id: Communication identifier associated with the QP attributes to
538 * @qp_attr: On input, specifies the desired QP state. On output, the
539 * mandatory and desired optional attributes will be set in order to
540 * modify the QP to the specified state.
541 * @qp_attr_mask: The QP attribute mask that may be used to transition the
542 * QP to the specified state.
544 * Users must set the @qp_attr->qp_state to the desired QP state. This call
545 * will set all required attributes for the given transition, along with
546 * known optional attributes. Users may override the attributes returned from
547 * this call before calling ib_modify_qp.
549 int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
550 struct ib_qp_attr *qp_attr,
554 * ib_send_cm_apr - Sends an alternate path response message in response to
555 * a load alternate path request.
556 * @cm_id: Connection identifier associated with the alternate path response.
557 * @status: Reply status sent with the alternate path response.
558 * @info: Optional additional information sent with the alternate path
560 * @info_length: Size of the additional information, in bytes.
561 * @private_data: Optional user-defined private data sent with the
562 * alternate path response message.
563 * @private_data_len: Size of the private data buffer, in bytes.
565 int ib_send_cm_apr(struct ib_cm_id *cm_id,
566 enum ib_cm_apr_status status,
569 const void *private_data,
570 u8 private_data_len);
572 struct ib_cm_sidr_req_param {
573 struct ib_sa_path_rec *path;
576 const void *private_data;
582 * ib_send_cm_sidr_req - Sends a service ID resolution request to the
584 * @cm_id: Communication identifier that will be associated with the
585 * service ID resolution request.
586 * @param: Service ID resolution request information.
588 int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
589 struct ib_cm_sidr_req_param *param);
591 struct ib_cm_sidr_rep_param {
594 enum ib_cm_sidr_status status;
597 const void *private_data;
602 * ib_send_cm_sidr_rep - Sends a service ID resolution reply to the
604 * @cm_id: Communication identifier associated with the received service ID
605 * resolution request.
606 * @param: Service ID resolution reply information.
608 int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
609 struct ib_cm_sidr_rep_param *param);