2 * Copyright (c) 2004-2006 Intel Corporation. All rights reserved.
3 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
4 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 #include <infiniband/verbs.h>
40 #include <infiniband/sa.h>
41 #include <infiniband/byteorder.h>
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
86 struct ibv_context *device_context;
92 struct ib_cm_device *device;
96 struct ib_cm_req_event_param {
97 struct ib_cm_id *listen_id;
100 struct ibv_sa_path_rec *primary_path;
101 struct ibv_sa_path_rec *alternate_path;
103 uint64_t remote_ca_guid; /* netork-byte order */
104 uint32_t remote_qkey;
106 enum ibv_qp_type qp_type;
108 uint32_t starting_psn;
109 uint8_t responder_resources;
110 uint8_t initiator_depth;
111 unsigned int local_cm_response_timeout:5;
112 unsigned int flow_control:1;
113 unsigned int remote_cm_response_timeout:5;
114 unsigned int retry_count:3;
115 unsigned int rnr_retry_count:3;
119 struct ib_cm_rep_event_param {
120 uint64_t remote_ca_guid; /* network-byte order */
121 uint32_t remote_qkey;
123 uint32_t starting_psn;
124 uint8_t responder_resources;
125 uint8_t initiator_depth;
126 unsigned int target_ack_delay:5;
127 unsigned int failover_accepted:2;
128 unsigned int flow_control:1;
129 unsigned int rnr_retry_count:3;
133 enum ib_cm_rej_reason {
135 IB_CM_REJ_NO_EEC = 2,
136 IB_CM_REJ_NO_RESOURCES = 3,
137 IB_CM_REJ_TIMEOUT = 4,
138 IB_CM_REJ_UNSUPPORTED = 5,
139 IB_CM_REJ_INVALID_COMM_ID = 6,
140 IB_CM_REJ_INVALID_COMM_INSTANCE = 7,
141 IB_CM_REJ_INVALID_SERVICE_ID = 8,
142 IB_CM_REJ_INVALID_TRANSPORT_TYPE = 9,
143 IB_CM_REJ_STALE_CONN = 10,
144 IB_CM_REJ_RDC_NOT_EXIST = 11,
145 IB_CM_REJ_INVALID_GID = 12,
146 IB_CM_REJ_INVALID_LID = 13,
147 IB_CM_REJ_INVALID_SL = 14,
148 IB_CM_REJ_INVALID_TRAFFIC_CLASS = 15,
149 IB_CM_REJ_INVALID_HOP_LIMIT = 16,
150 IB_CM_REJ_INVALID_PACKET_RATE = 17,
151 IB_CM_REJ_INVALID_ALT_GID = 18,
152 IB_CM_REJ_INVALID_ALT_LID = 19,
153 IB_CM_REJ_INVALID_ALT_SL = 20,
154 IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS = 21,
155 IB_CM_REJ_INVALID_ALT_HOP_LIMIT = 22,
156 IB_CM_REJ_INVALID_ALT_PACKET_RATE = 23,
157 IB_CM_REJ_PORT_CM_REDIRECT = 24,
158 IB_CM_REJ_PORT_REDIRECT = 25,
159 IB_CM_REJ_INVALID_MTU = 26,
160 IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES = 27,
161 IB_CM_REJ_CONSUMER_DEFINED = 28,
162 IB_CM_REJ_INVALID_RNR_RETRY = 29,
163 IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID = 30,
164 IB_CM_REJ_INVALID_CLASS_VERSION = 31,
165 IB_CM_REJ_INVALID_FLOW_LABEL = 32,
166 IB_CM_REJ_INVALID_ALT_FLOW_LABEL = 33
169 struct ib_cm_rej_event_param {
170 enum ib_cm_rej_reason reason;
175 struct ib_cm_mra_event_param {
176 uint8_t service_timeout;
179 struct ib_cm_lap_event_param {
180 struct ibv_sa_path_rec *alternate_path;
183 enum ib_cm_apr_status {
185 IB_CM_APR_INVALID_COMM_ID,
186 IB_CM_APR_UNSUPPORTED,
189 IB_CM_APR_IS_CURRENT,
190 IB_CM_APR_INVALID_QPN_EECN,
191 IB_CM_APR_INVALID_LID,
192 IB_CM_APR_INVALID_GID,
193 IB_CM_APR_INVALID_FLOW_LABEL,
194 IB_CM_APR_INVALID_TCLASS,
195 IB_CM_APR_INVALID_HOP_LIMIT,
196 IB_CM_APR_INVALID_PACKET_RATE,
200 struct ib_cm_apr_event_param {
201 enum ib_cm_apr_status ap_status;
206 struct ib_cm_sidr_req_event_param {
207 struct ib_cm_id *listen_id;
212 enum ib_cm_sidr_status {
218 IB_SIDR_UNSUPPORTED_VERSION
221 struct ib_cm_sidr_rep_event_param {
222 enum ib_cm_sidr_status status;
230 struct ib_cm_id *cm_id;
231 enum ib_cm_event_type event;
233 struct ib_cm_req_event_param req_rcvd;
234 struct ib_cm_rep_event_param rep_rcvd;
235 /* No data for RTU received events. */
236 struct ib_cm_rej_event_param rej_rcvd;
237 struct ib_cm_mra_event_param mra_rcvd;
238 struct ib_cm_lap_event_param lap_rcvd;
239 struct ib_cm_apr_event_param apr_rcvd;
240 /* No data for DREQ/DREP received events. */
241 struct ib_cm_sidr_req_event_param sidr_req_rcvd;
242 struct ib_cm_sidr_rep_event_param sidr_rep_rcvd;
243 enum ibv_wc_status send_status;
250 * ib_cm_get_event - Retrieves the next pending communications event,
251 * if no event is pending waits for an event.
252 * @device: CM device to retrieve the event.
253 * @event: Allocated information about the next communication event.
254 * Event should be freed using ib_cm_ack_event()
256 * IB_CM_REQ_RECEIVED and IB_CM_SIDR_REQ_RECEIVED communication events
257 * generated as a result of listen requests result in the allocation of a
259 * Clients are responsible for destroying the new @cm_id. For peer-to-peer
260 * IB_CM_REQ_RECEIVED and all other events, the returned @cm_id corresponds
261 * to a user's existing communication identifier.
263 int ib_cm_get_event(struct ib_cm_device *device, struct ib_cm_event **event);
266 * ib_cm_ack_event - Free a communications event.
267 * @event: Event to be released.
269 * All events which are allocated by ib_cm_get_event() must be released,
270 * there should be a one-to-one correspondence between successful gets
273 int ib_cm_ack_event(struct ib_cm_event *event);
276 * ib_cm_open_device - Returns the device the CM uses to submit requests
277 * and retrieve events, corresponding to the specified verbs device.
279 * The CM device contains the file descriptor that the CM uses to
280 * communicate with the kernel CM component. The primary use of the
281 * file descriptor is to test for CM readiness events. When the CM
282 * becomes ready to READ there is a pending event ready, and a subsequent
283 * call to ib_cm_get_event will not block.
284 * Note: The user should not read or write directly to the CM file
285 * descriptor, it will likely result in an error or unexpected
288 struct ib_cm_device* ib_cm_open_device(struct ibv_context *device_context);
291 * ib_cm_close_device - Close a CM device.
292 * @device: Device to close.
294 void ib_cm_close_device(struct ib_cm_device *device);
297 * ib_cm_create_id - Allocate a communication identifier.
299 * Communication identifiers are used to track connection states, service
300 * ID resolution requests, and listen requests.
302 int ib_cm_create_id(struct ib_cm_device *device,
303 struct ib_cm_id **cm_id, void *context);
306 * ib_cm_destroy_id - Destroy a connection identifier.
307 * @cm_id: Connection identifier to destroy.
309 int ib_cm_destroy_id(struct ib_cm_id *cm_id);
311 struct ib_cm_attr_param {
312 uint64_t service_id; /* network-byte order */
313 uint64_t service_mask; /* network-byte order */
319 * ib_cm_attr_id - Get connection identifier attributes.
320 * @cm_id: Connection identifier to retrieve attributes.
321 * @param: Destination of retreived parameters.
323 * Not all parameters are valid during all connection states.
325 int ib_cm_attr_id(struct ib_cm_id *cm_id,
326 struct ib_cm_attr_param *param);
328 #define IB_CM_ASSIGN_SERVICE_ID_MASK __constant_cpu_to_be64(0xFF00000000000000ULL)
329 #define IB_CM_ASSIGN_SERVICE_ID __constant_cpu_to_be64(0x0200000000000000ULL)
332 * ib_cm_listen - Initiates listening on the specified service ID for
333 * connection and service ID resolution requests.
334 * @cm_id: Connection identifier associated with the listen request.
335 * @service_id: Service identifier matched against incoming connection
336 * and service ID resolution requests. The service ID should be specified
337 * network-byte order.
338 * @service_mask: Mask applied to service ID used to listen across a
339 * range of service IDs. If set to 0, the service ID is matched
342 int ib_cm_listen(struct ib_cm_id *cm_id,
344 uint64_t service_mask);
346 struct ib_cm_req_param {
347 struct ibv_sa_path_rec *primary_path;
348 struct ibv_sa_path_rec *alternate_path;
349 uint64_t service_id; /* network-byte order */
351 enum ibv_qp_type qp_type;
352 uint32_t starting_psn;
354 uint8_t private_data_len;
355 uint8_t peer_to_peer;
356 uint8_t responder_resources;
357 uint8_t initiator_depth;
358 uint8_t remote_cm_response_timeout;
359 uint8_t flow_control;
360 uint8_t local_cm_response_timeout;
362 uint8_t rnr_retry_count;
363 uint8_t max_cm_retries;
368 * ib_cm_send_req - Sends a connection request to the remote node.
369 * @cm_id: Connection identifier that will be associated with the
370 * connection request.
371 * @param: Connection request information needed to establish the
374 int ib_cm_send_req(struct ib_cm_id *cm_id,
375 struct ib_cm_req_param *param);
377 struct ib_cm_rep_param {
379 uint32_t starting_psn;
381 uint8_t private_data_len;
382 uint8_t responder_resources;
383 uint8_t initiator_depth;
384 uint8_t target_ack_delay;
385 uint8_t failover_accepted;
386 uint8_t flow_control;
387 uint8_t rnr_retry_count;
392 * ib_cm_send_rep - Sends a connection reply in response to a connection
394 * @cm_id: Connection identifier that will be associated with the
395 * connection request.
396 * @param: Connection reply information needed to establish the
399 int ib_cm_send_rep(struct ib_cm_id *cm_id,
400 struct ib_cm_rep_param *param);
403 * ib_cm_send_rtu - Sends a connection ready to use message in response
404 * to a connection reply message.
405 * @cm_id: Connection identifier associated with the connection request.
406 * @private_data: Optional user-defined private data sent with the
407 * ready to use message.
408 * @private_data_len: Size of the private data buffer, in bytes.
410 int ib_cm_send_rtu(struct ib_cm_id *cm_id,
412 uint8_t private_data_len);
415 * ib_cm_send_dreq - Sends a disconnection request for an existing
417 * @cm_id: Connection identifier associated with the connection being
419 * @private_data: Optional user-defined private data sent with the
420 * disconnection request message.
421 * @private_data_len: Size of the private data buffer, in bytes.
423 int ib_cm_send_dreq(struct ib_cm_id *cm_id,
425 uint8_t private_data_len);
428 * ib_cm_send_drep - Sends a disconnection reply to a disconnection request.
429 * @cm_id: Connection identifier associated with the connection being
431 * @private_data: Optional user-defined private data sent with the
432 * disconnection reply message.
433 * @private_data_len: Size of the private data buffer, in bytes.
435 int ib_cm_send_drep(struct ib_cm_id *cm_id,
437 uint8_t private_data_len);
440 * ib_cm_notify - Notifies the CM of an event reported to the consumer.
441 * @cm_id: Connection identifier to transition to established.
442 * @event: Type of event.
444 * This routine should be invoked by users to notify the CM of relevant
445 * communication events. Events that should be reported to the CM and
446 * when to report them are:
448 * IBV_EVENT_COMM_EST - Used when a message is received on a connected
449 * QP before an RTU has been received.
450 * IBV_EVENT_PATH_MIG - Notifies the CM that the connection has failed over
451 * to the alternate path.
453 int ib_cm_notify(struct ib_cm_id *cm_id, enum ibv_event_type event);
456 * ib_cm_send_rej - Sends a connection rejection message to the
458 * @cm_id: Connection identifier associated with the connection being
460 * @reason: Reason for the connection request rejection.
461 * @ari: Optional additional rejection information.
462 * @ari_length: Size of the additional rejection information, in bytes.
463 * @private_data: Optional user-defined private data sent with the
465 * @private_data_len: Size of the private data buffer, in bytes.
467 int ib_cm_send_rej(struct ib_cm_id *cm_id,
468 enum ib_cm_rej_reason reason,
472 uint8_t private_data_len);
475 * ib_cm_send_mra - Sends a message receipt acknowledgement to a connection
477 * @cm_id: Connection identifier associated with the connection message.
478 * @service_timeout: The maximum time required for the sender to reply to
479 * to the connection message.
480 * @private_data: Optional user-defined private data sent with the
481 * message receipt acknowledgement.
482 * @private_data_len: Size of the private data buffer, in bytes.
484 int ib_cm_send_mra(struct ib_cm_id *cm_id,
485 uint8_t service_timeout,
487 uint8_t private_data_len);
490 * ib_cm_send_lap - Sends a load alternate path request.
491 * @cm_id: Connection identifier associated with the load alternate path
493 * @alternate_path: A path record that identifies the alternate path to
495 * @private_data: Optional user-defined private data sent with the
496 * load alternate path message.
497 * @private_data_len: Size of the private data buffer, in bytes.
499 int ib_cm_send_lap(struct ib_cm_id *cm_id,
500 struct ibv_sa_path_rec *alternate_path,
502 uint8_t private_data_len);
505 * ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning
506 * to a specified QP state.
507 * @cm_id: Communication identifier associated with the QP attributes to
509 * @qp_attr: On input, specifies the desired QP state. On output, the
510 * mandatory and desired optional attributes will be set in order to
511 * modify the QP to the specified state.
512 * @qp_attr_mask: The QP attribute mask that may be used to transition the
513 * QP to the specified state.
515 * Users must set the @qp_attr->qp_state to the desired QP state. This call
516 * will set all required attributes for the given transition, along with
517 * known optional attributes. Users may override the attributes returned from
518 * this call before calling ib_modify_qp.
520 int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
521 struct ibv_qp_attr *qp_attr,
525 * ib_cm_send_apr - Sends an alternate path response message in response to
526 * a load alternate path request.
527 * @cm_id: Connection identifier associated with the alternate path response.
528 * @status: Reply status sent with the alternate path response.
529 * @info: Optional additional information sent with the alternate path
531 * @info_length: Size of the additional information, in bytes.
532 * @private_data: Optional user-defined private data sent with the
533 * alternate path response message.
534 * @private_data_len: Size of the private data buffer, in bytes.
536 int ib_cm_send_apr(struct ib_cm_id *cm_id,
537 enum ib_cm_apr_status status,
541 uint8_t private_data_len);
543 struct ib_cm_sidr_req_param {
544 struct ibv_sa_path_rec *path;
545 uint64_t service_id; /* network-byte order */
548 uint8_t private_data_len;
549 uint8_t max_cm_retries;
553 * ib_cm_send_sidr_req - Sends a service ID resolution request to the
555 * @cm_id: Communication identifier that will be associated with the
556 * service ID resolution request.
557 * @param: Service ID resolution request information.
559 int ib_cm_send_sidr_req(struct ib_cm_id *cm_id,
560 struct ib_cm_sidr_req_param *param);
562 struct ib_cm_sidr_rep_param {
565 enum ib_cm_sidr_status status;
569 uint8_t private_data_len;
573 * ib_cm_send_sidr_rep - Sends a service ID resolution reply to the
575 * @cm_id: Communication identifier associated with the received service ID
576 * resolution request.
577 * @param: Service ID resolution reply information.
579 int ib_cm_send_sidr_rep(struct ib_cm_id *cm_id,
580 struct ib_cm_sidr_rep_param *param);