Loading...
1/*
2 * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.
3 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
4 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
5 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
6 *
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
12 *
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
15 * conditions are met:
16 *
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer.
20 *
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 * SOFTWARE.
34 */
35#if !defined(IB_CM_H)
36#define IB_CM_H
37
38#include <rdma/ib_mad.h>
39#include <rdma/ib_sa.h>
40
41enum ib_cm_state {
42 IB_CM_IDLE,
43 IB_CM_LISTEN,
44 IB_CM_REQ_SENT,
45 IB_CM_REQ_RCVD,
46 IB_CM_MRA_REQ_SENT,
47 IB_CM_MRA_REQ_RCVD,
48 IB_CM_REP_SENT,
49 IB_CM_REP_RCVD,
50 IB_CM_MRA_REP_SENT,
51 IB_CM_MRA_REP_RCVD,
52 IB_CM_ESTABLISHED,
53 IB_CM_DREQ_SENT,
54 IB_CM_DREQ_RCVD,
55 IB_CM_TIMEWAIT,
56 IB_CM_SIDR_REQ_SENT,
57 IB_CM_SIDR_REQ_RCVD
58};
59
60enum ib_cm_lap_state {
61 IB_CM_LAP_UNINIT,
62 IB_CM_LAP_IDLE,
63 IB_CM_LAP_SENT,
64 IB_CM_LAP_RCVD,
65 IB_CM_MRA_LAP_SENT,
66 IB_CM_MRA_LAP_RCVD,
67};
68
69enum ib_cm_event_type {
70 IB_CM_REQ_ERROR,
71 IB_CM_REQ_RECEIVED,
72 IB_CM_REP_ERROR,
73 IB_CM_REP_RECEIVED,
74 IB_CM_RTU_RECEIVED,
75 IB_CM_USER_ESTABLISHED,
76 IB_CM_DREQ_ERROR,
77 IB_CM_DREQ_RECEIVED,
78 IB_CM_DREP_RECEIVED,
79 IB_CM_TIMEWAIT_EXIT,
80 IB_CM_MRA_RECEIVED,
81 IB_CM_REJ_RECEIVED,
82 IB_CM_LAP_ERROR,
83 IB_CM_LAP_RECEIVED,
84 IB_CM_APR_RECEIVED,
85 IB_CM_SIDR_REQ_ERROR,
86 IB_CM_SIDR_REQ_RECEIVED,
87 IB_CM_SIDR_REP_RECEIVED
88};
89
90enum ib_cm_data_size {
91 IB_CM_REQ_PRIVATE_DATA_SIZE = 92,
92 IB_CM_MRA_PRIVATE_DATA_SIZE = 222,
93 IB_CM_REJ_PRIVATE_DATA_SIZE = 148,
94 IB_CM_REP_PRIVATE_DATA_SIZE = 196,
95 IB_CM_RTU_PRIVATE_DATA_SIZE = 224,
96 IB_CM_DREQ_PRIVATE_DATA_SIZE = 220,
97 IB_CM_DREP_PRIVATE_DATA_SIZE = 224,
98 IB_CM_REJ_ARI_LENGTH = 72,
99 IB_CM_LAP_PRIVATE_DATA_SIZE = 168,
100 IB_CM_APR_PRIVATE_DATA_SIZE = 148,
101 IB_CM_APR_INFO_LENGTH = 72,
102 IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE = 216,
103 IB_CM_SIDR_REP_PRIVATE_DATA_SIZE = 136,
104 IB_CM_SIDR_REP_INFO_LENGTH = 72,
105 IB_CM_COMPARE_SIZE = 64
106};
107
108struct ib_cm_id;
109
110struct ib_cm_req_event_param {
111 struct ib_cm_id *listen_id;
112 u8 port;
113
114 struct ib_sa_path_rec *primary_path;
115 struct ib_sa_path_rec *alternate_path;
116
117 __be64 remote_ca_guid;
118 u32 remote_qkey;
119 u32 remote_qpn;
120 enum ib_qp_type qp_type;
121
122 u32 starting_psn;
123 u8 responder_resources;
124 u8 initiator_depth;
125 unsigned int local_cm_response_timeout:5;
126 unsigned int flow_control:1;
127 unsigned int remote_cm_response_timeout:5;
128 unsigned int retry_count:3;
129 unsigned int rnr_retry_count:3;
130 unsigned int srq:1;
131};
132
133struct ib_cm_rep_event_param {
134 __be64 remote_ca_guid;
135 u32 remote_qkey;
136 u32 remote_qpn;
137 u32 starting_psn;
138 u8 responder_resources;
139 u8 initiator_depth;
140 unsigned int target_ack_delay:5;
141 unsigned int failover_accepted:2;
142 unsigned int flow_control:1;
143 unsigned int rnr_retry_count:3;
144 unsigned int srq:1;
145};
146
147enum ib_cm_rej_reason {
148 IB_CM_REJ_NO_QP = 1,
149 IB_CM_REJ_NO_EEC = 2,
150 IB_CM_REJ_NO_RESOURCES = 3,
151 IB_CM_REJ_TIMEOUT = 4,
152 IB_CM_REJ_UNSUPPORTED = 5,
153 IB_CM_REJ_INVALID_COMM_ID = 6,
154 IB_CM_REJ_INVALID_COMM_INSTANCE = 7,
155 IB_CM_REJ_INVALID_SERVICE_ID = 8,
156 IB_CM_REJ_INVALID_TRANSPORT_TYPE = 9,
157 IB_CM_REJ_STALE_CONN = 10,
158 IB_CM_REJ_RDC_NOT_EXIST = 11,
159 IB_CM_REJ_INVALID_GID = 12,
160 IB_CM_REJ_INVALID_LID = 13,
161 IB_CM_REJ_INVALID_SL = 14,
162 IB_CM_REJ_INVALID_TRAFFIC_CLASS = 15,
163 IB_CM_REJ_INVALID_HOP_LIMIT = 16,
164 IB_CM_REJ_INVALID_PACKET_RATE = 17,
165 IB_CM_REJ_INVALID_ALT_GID = 18,
166 IB_CM_REJ_INVALID_ALT_LID = 19,
167 IB_CM_REJ_INVALID_ALT_SL = 20,
168 IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS = 21,
169 IB_CM_REJ_INVALID_ALT_HOP_LIMIT = 22,
170 IB_CM_REJ_INVALID_ALT_PACKET_RATE = 23,
171 IB_CM_REJ_PORT_CM_REDIRECT = 24,
172 IB_CM_REJ_PORT_REDIRECT = 25,
173 IB_CM_REJ_INVALID_MTU = 26,
174 IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES = 27,
175 IB_CM_REJ_CONSUMER_DEFINED = 28,
176 IB_CM_REJ_INVALID_RNR_RETRY = 29,
177 IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID = 30,
178 IB_CM_REJ_INVALID_CLASS_VERSION = 31,
179 IB_CM_REJ_INVALID_FLOW_LABEL = 32,
180 IB_CM_REJ_INVALID_ALT_FLOW_LABEL = 33
181};
182
183struct ib_cm_rej_event_param {
184 enum ib_cm_rej_reason reason;
185 void *ari;
186 u8 ari_length;
187};
188
189struct ib_cm_mra_event_param {
190 u8 service_timeout;
191};
192
193struct ib_cm_lap_event_param {
194 struct ib_sa_path_rec *alternate_path;
195};
196
197enum ib_cm_apr_status {
198 IB_CM_APR_SUCCESS,
199 IB_CM_APR_INVALID_COMM_ID,
200 IB_CM_APR_UNSUPPORTED,
201 IB_CM_APR_REJECT,
202 IB_CM_APR_REDIRECT,
203 IB_CM_APR_IS_CURRENT,
204 IB_CM_APR_INVALID_QPN_EECN,
205 IB_CM_APR_INVALID_LID,
206 IB_CM_APR_INVALID_GID,
207 IB_CM_APR_INVALID_FLOW_LABEL,
208 IB_CM_APR_INVALID_TCLASS,
209 IB_CM_APR_INVALID_HOP_LIMIT,
210 IB_CM_APR_INVALID_PACKET_RATE,
211 IB_CM_APR_INVALID_SL
212};
213
214struct ib_cm_apr_event_param {
215 enum ib_cm_apr_status ap_status;
216 void *apr_info;
217 u8 info_len;
218};
219
220struct ib_cm_sidr_req_event_param {
221 struct ib_cm_id *listen_id;
222 u8 port;
223 u16 pkey;
224};
225
226enum ib_cm_sidr_status {
227 IB_SIDR_SUCCESS,
228 IB_SIDR_UNSUPPORTED,
229 IB_SIDR_REJECT,
230 IB_SIDR_NO_QP,
231 IB_SIDR_REDIRECT,
232 IB_SIDR_UNSUPPORTED_VERSION
233};
234
235struct ib_cm_sidr_rep_event_param {
236 enum ib_cm_sidr_status status;
237 u32 qkey;
238 u32 qpn;
239 void *info;
240 u8 info_len;
241};
242
243struct ib_cm_event {
244 enum ib_cm_event_type event;
245 union {
246 struct ib_cm_req_event_param req_rcvd;
247 struct ib_cm_rep_event_param rep_rcvd;
248 /* No data for RTU received events. */
249 struct ib_cm_rej_event_param rej_rcvd;
250 struct ib_cm_mra_event_param mra_rcvd;
251 struct ib_cm_lap_event_param lap_rcvd;
252 struct ib_cm_apr_event_param apr_rcvd;
253 /* No data for DREQ/DREP received events. */
254 struct ib_cm_sidr_req_event_param sidr_req_rcvd;
255 struct ib_cm_sidr_rep_event_param sidr_rep_rcvd;
256 enum ib_wc_status send_status;
257 } param;
258
259 void *private_data;
260};
261
262/**
263 * ib_cm_handler - User-defined callback to process communication events.
264 * @cm_id: Communication identifier associated with the reported event.
265 * @event: Information about the communication event.
266 *
267 * IB_CM_REQ_RECEIVED and IB_CM_SIDR_REQ_RECEIVED communication events
268 * generated as a result of listen requests result in the allocation of a
269 * new @cm_id. The new @cm_id is returned to the user through this callback.
270 * Clients are responsible for destroying the new @cm_id. For peer-to-peer
271 * IB_CM_REQ_RECEIVED and all other events, the returned @cm_id corresponds
272 * to a user's existing communication identifier.
273 *
274 * Users may not call ib_destroy_cm_id while in the context of this callback;
275 * however, returning a non-zero value instructs the communication manager to
276 * destroy the @cm_id after the callback completes.
277 */
278typedef int (*ib_cm_handler)(struct ib_cm_id *cm_id,
279 struct ib_cm_event *event);
280
281struct ib_cm_id {
282 ib_cm_handler cm_handler;
283 void *context;
284 struct ib_device *device;
285 __be64 service_id;
286 __be64 service_mask;
287 enum ib_cm_state state; /* internal CM/debug use */
288 enum ib_cm_lap_state lap_state; /* internal CM/debug use */
289 __be32 local_id;
290 __be32 remote_id;
291 u32 remote_cm_qpn; /* 1 unless redirected */
292};
293
294/**
295 * ib_create_cm_id - Allocate a communication identifier.
296 * @device: Device associated with the cm_id. All related communication will
297 * be associated with the specified device.
298 * @cm_handler: Callback invoked to notify the user of CM events.
299 * @context: User specified context associated with the communication
300 * identifier.
301 *
302 * Communication identifiers are used to track connection states, service
303 * ID resolution requests, and listen requests.
304 */
305struct ib_cm_id *ib_create_cm_id(struct ib_device *device,
306 ib_cm_handler cm_handler,
307 void *context);
308
309/**
310 * ib_destroy_cm_id - Destroy a connection identifier.
311 * @cm_id: Connection identifier to destroy.
312 *
313 * This call blocks until the connection identifier is destroyed.
314 */
315void ib_destroy_cm_id(struct ib_cm_id *cm_id);
316
317#define IB_SERVICE_ID_AGN_MASK cpu_to_be64(0xFF00000000000000ULL)
318#define IB_CM_ASSIGN_SERVICE_ID cpu_to_be64(0x0200000000000000ULL)
319#define IB_CMA_SERVICE_ID cpu_to_be64(0x0000000001000000ULL)
320#define IB_CMA_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFF000000ULL)
321#define IB_SDP_SERVICE_ID cpu_to_be64(0x0000000000010000ULL)
322#define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL)
323
324struct ib_cm_compare_data {
325 u8 data[IB_CM_COMPARE_SIZE];
326 u8 mask[IB_CM_COMPARE_SIZE];
327};
328
329/**
330 * ib_cm_listen - Initiates listening on the specified service ID for
331 * connection and service ID resolution requests.
332 * @cm_id: Connection identifier associated with the listen request.
333 * @service_id: Service identifier matched against incoming connection
334 * and service ID resolution requests. The service ID should be specified
335 * network-byte order. If set to IB_CM_ASSIGN_SERVICE_ID, the CM will
336 * assign a service ID to the caller.
337 * @service_mask: Mask applied to service ID used to listen across a
338 * range of service IDs. If set to 0, the service ID is matched
339 * exactly. This parameter is ignored if %service_id is set to
340 * IB_CM_ASSIGN_SERVICE_ID.
341 * @compare_data: This parameter is optional. It specifies data that must
342 * appear in the private data of a connection request for the specified
343 * listen request.
344 */
345int ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id, __be64 service_mask,
346 struct ib_cm_compare_data *compare_data);
347
348struct ib_cm_req_param {
349 struct ib_sa_path_rec *primary_path;
350 struct ib_sa_path_rec *alternate_path;
351 __be64 service_id;
352 u32 qp_num;
353 enum ib_qp_type qp_type;
354 u32 starting_psn;
355 const void *private_data;
356 u8 private_data_len;
357 u8 peer_to_peer;
358 u8 responder_resources;
359 u8 initiator_depth;
360 u8 remote_cm_response_timeout;
361 u8 flow_control;
362 u8 local_cm_response_timeout;
363 u8 retry_count;
364 u8 rnr_retry_count;
365 u8 max_cm_retries;
366 u8 srq;
367};
368
369/**
370 * ib_send_cm_req - Sends a connection request to the remote node.
371 * @cm_id: Connection identifier that will be associated with the
372 * connection request.
373 * @param: Connection request information needed to establish the
374 * connection.
375 */
376int ib_send_cm_req(struct ib_cm_id *cm_id,
377 struct ib_cm_req_param *param);
378
379struct ib_cm_rep_param {
380 u32 qp_num;
381 u32 starting_psn;
382 const void *private_data;
383 u8 private_data_len;
384 u8 responder_resources;
385 u8 initiator_depth;
386 u8 failover_accepted;
387 u8 flow_control;
388 u8 rnr_retry_count;
389 u8 srq;
390};
391
392/**
393 * ib_send_cm_rep - Sends a connection reply in response to a connection
394 * request.
395 * @cm_id: Connection identifier that will be associated with the
396 * connection request.
397 * @param: Connection reply information needed to establish the
398 * connection.
399 */
400int ib_send_cm_rep(struct ib_cm_id *cm_id,
401 struct ib_cm_rep_param *param);
402
403/**
404 * ib_send_cm_rtu - Sends a connection ready to use message in response
405 * to a connection reply message.
406 * @cm_id: Connection identifier associated with the connection request.
407 * @private_data: Optional user-defined private data sent with the
408 * ready to use message.
409 * @private_data_len: Size of the private data buffer, in bytes.
410 */
411int ib_send_cm_rtu(struct ib_cm_id *cm_id,
412 const void *private_data,
413 u8 private_data_len);
414
415/**
416 * ib_send_cm_dreq - Sends a disconnection request for an existing
417 * connection.
418 * @cm_id: Connection identifier associated with the connection being
419 * released.
420 * @private_data: Optional user-defined private data sent with the
421 * disconnection request message.
422 * @private_data_len: Size of the private data buffer, in bytes.
423 */
424int ib_send_cm_dreq(struct ib_cm_id *cm_id,
425 const void *private_data,
426 u8 private_data_len);
427
428/**
429 * ib_send_cm_drep - Sends a disconnection reply to a disconnection request.
430 * @cm_id: Connection identifier associated with the connection being
431 * released.
432 * @private_data: Optional user-defined private data sent with the
433 * disconnection reply message.
434 * @private_data_len: Size of the private data buffer, in bytes.
435 *
436 * If the cm_id is in the correct state, the CM will transition the connection
437 * to the timewait state, even if an error occurs sending the DREP message.
438 */
439int ib_send_cm_drep(struct ib_cm_id *cm_id,
440 const void *private_data,
441 u8 private_data_len);
442
443/**
444 * ib_cm_notify - Notifies the CM of an event reported to the consumer.
445 * @cm_id: Connection identifier to transition to established.
446 * @event: Type of event.
447 *
448 * This routine should be invoked by users to notify the CM of relevant
449 * communication events. Events that should be reported to the CM and
450 * when to report them are:
451 *
452 * IB_EVENT_COMM_EST - Used when a message is received on a connected
453 * QP before an RTU has been received.
454 * IB_EVENT_PATH_MIG - Notifies the CM that the connection has failed over
455 * to the alternate path.
456 */
457int ib_cm_notify(struct ib_cm_id *cm_id, enum ib_event_type event);
458
459/**
460 * ib_send_cm_rej - Sends a connection rejection message to the
461 * remote node.
462 * @cm_id: Connection identifier associated with the connection being
463 * rejected.
464 * @reason: Reason for the connection request rejection.
465 * @ari: Optional additional rejection information.
466 * @ari_length: Size of the additional rejection information, in bytes.
467 * @private_data: Optional user-defined private data sent with the
468 * rejection message.
469 * @private_data_len: Size of the private data buffer, in bytes.
470 */
471int ib_send_cm_rej(struct ib_cm_id *cm_id,
472 enum ib_cm_rej_reason reason,
473 void *ari,
474 u8 ari_length,
475 const void *private_data,
476 u8 private_data_len);
477
478#define IB_CM_MRA_FLAG_DELAY 0x80 /* Send MRA only after a duplicate msg */
479
480/**
481 * ib_send_cm_mra - Sends a message receipt acknowledgement to a connection
482 * message.
483 * @cm_id: Connection identifier associated with the connection message.
484 * @service_timeout: The lower 5-bits specify the maximum time required for
485 * the sender to reply to the connection message. The upper 3-bits
486 * specify additional control flags.
487 * @private_data: Optional user-defined private data sent with the
488 * message receipt acknowledgement.
489 * @private_data_len: Size of the private data buffer, in bytes.
490 */
491int ib_send_cm_mra(struct ib_cm_id *cm_id,
492 u8 service_timeout,
493 const void *private_data,
494 u8 private_data_len);
495
496/**
497 * ib_send_cm_lap - Sends a load alternate path request.
498 * @cm_id: Connection identifier associated with the load alternate path
499 * message.
500 * @alternate_path: A path record that identifies the alternate path to
501 * load.
502 * @private_data: Optional user-defined private data sent with the
503 * load alternate path message.
504 * @private_data_len: Size of the private data buffer, in bytes.
505 */
506int ib_send_cm_lap(struct ib_cm_id *cm_id,
507 struct ib_sa_path_rec *alternate_path,
508 const void *private_data,
509 u8 private_data_len);
510
511/**
512 * ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning
513 * to a specified QP state.
514 * @cm_id: Communication identifier associated with the QP attributes to
515 * initialize.
516 * @qp_attr: On input, specifies the desired QP state. On output, the
517 * mandatory and desired optional attributes will be set in order to
518 * modify the QP to the specified state.
519 * @qp_attr_mask: The QP attribute mask that may be used to transition the
520 * QP to the specified state.
521 *
522 * Users must set the @qp_attr->qp_state to the desired QP state. This call
523 * will set all required attributes for the given transition, along with
524 * known optional attributes. Users may override the attributes returned from
525 * this call before calling ib_modify_qp.
526 */
527int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
528 struct ib_qp_attr *qp_attr,
529 int *qp_attr_mask);
530
531/**
532 * ib_send_cm_apr - Sends an alternate path response message in response to
533 * a load alternate path request.
534 * @cm_id: Connection identifier associated with the alternate path response.
535 * @status: Reply status sent with the alternate path response.
536 * @info: Optional additional information sent with the alternate path
537 * response.
538 * @info_length: Size of the additional information, in bytes.
539 * @private_data: Optional user-defined private data sent with the
540 * alternate path response message.
541 * @private_data_len: Size of the private data buffer, in bytes.
542 */
543int ib_send_cm_apr(struct ib_cm_id *cm_id,
544 enum ib_cm_apr_status status,
545 void *info,
546 u8 info_length,
547 const void *private_data,
548 u8 private_data_len);
549
550struct ib_cm_sidr_req_param {
551 struct ib_sa_path_rec *path;
552 __be64 service_id;
553 int timeout_ms;
554 const void *private_data;
555 u8 private_data_len;
556 u8 max_cm_retries;
557};
558
559/**
560 * ib_send_cm_sidr_req - Sends a service ID resolution request to the
561 * remote node.
562 * @cm_id: Communication identifier that will be associated with the
563 * service ID resolution request.
564 * @param: Service ID resolution request information.
565 */
566int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
567 struct ib_cm_sidr_req_param *param);
568
569struct ib_cm_sidr_rep_param {
570 u32 qp_num;
571 u32 qkey;
572 enum ib_cm_sidr_status status;
573 const void *info;
574 u8 info_length;
575 const void *private_data;
576 u8 private_data_len;
577};
578
579/**
580 * ib_send_cm_sidr_rep - Sends a service ID resolution reply to the
581 * remote node.
582 * @cm_id: Communication identifier associated with the received service ID
583 * resolution request.
584 * @param: Service ID resolution reply information.
585 */
586int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
587 struct ib_cm_sidr_rep_param *param);
588
589#endif /* IB_CM_H */
1/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2/*
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.
8 */
9
10#ifndef IB_CM_H
11#define IB_CM_H
12
13#include <rdma/ib_mad.h>
14#include <rdma/ib_sa.h>
15#include <rdma/rdma_cm.h>
16
17/* ib_cm and ib_user_cm modules share /sys/class/infiniband_cm */
18extern struct class cm_class;
19
20enum ib_cm_state {
21 IB_CM_IDLE,
22 IB_CM_LISTEN,
23 IB_CM_REQ_SENT,
24 IB_CM_REQ_RCVD,
25 IB_CM_MRA_REQ_SENT,
26 IB_CM_MRA_REQ_RCVD,
27 IB_CM_REP_SENT,
28 IB_CM_REP_RCVD,
29 IB_CM_MRA_REP_SENT,
30 IB_CM_MRA_REP_RCVD,
31 IB_CM_ESTABLISHED,
32 IB_CM_DREQ_SENT,
33 IB_CM_DREQ_RCVD,
34 IB_CM_TIMEWAIT,
35 IB_CM_SIDR_REQ_SENT,
36 IB_CM_SIDR_REQ_RCVD
37};
38
39enum ib_cm_lap_state {
40 IB_CM_LAP_UNINIT,
41 IB_CM_LAP_IDLE,
42 IB_CM_LAP_SENT,
43 IB_CM_LAP_RCVD,
44 IB_CM_MRA_LAP_SENT,
45 IB_CM_MRA_LAP_RCVD,
46};
47
48enum ib_cm_event_type {
49 IB_CM_REQ_ERROR,
50 IB_CM_REQ_RECEIVED,
51 IB_CM_REP_ERROR,
52 IB_CM_REP_RECEIVED,
53 IB_CM_RTU_RECEIVED,
54 IB_CM_USER_ESTABLISHED,
55 IB_CM_DREQ_ERROR,
56 IB_CM_DREQ_RECEIVED,
57 IB_CM_DREP_RECEIVED,
58 IB_CM_TIMEWAIT_EXIT,
59 IB_CM_MRA_RECEIVED,
60 IB_CM_REJ_RECEIVED,
61 IB_CM_LAP_ERROR,
62 IB_CM_LAP_RECEIVED,
63 IB_CM_APR_RECEIVED,
64 IB_CM_SIDR_REQ_ERROR,
65 IB_CM_SIDR_REQ_RECEIVED,
66 IB_CM_SIDR_REP_RECEIVED
67};
68
69enum 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,
84};
85
86struct ib_cm_id;
87
88struct ib_cm_req_event_param {
89 struct ib_cm_id *listen_id;
90
91 /* P_Key that was used by the GMP's BTH header */
92 u16 bth_pkey;
93
94 u8 port;
95
96 struct sa_path_rec *primary_path;
97 struct sa_path_rec *alternate_path;
98
99 /*
100 * SGID attribute of the primary path. Currently only
101 * useful for RoCE. Alternate path GID attributes
102 * are not yet supported.
103 */
104 const struct ib_gid_attr *ppath_sgid_attr;
105
106 __be64 remote_ca_guid;
107 u32 remote_qkey;
108 u32 remote_qpn;
109 enum ib_qp_type qp_type;
110
111 u32 starting_psn;
112 u8 responder_resources;
113 u8 initiator_depth;
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;
119 unsigned int srq:1;
120 struct rdma_ucm_ece ece;
121};
122
123struct ib_cm_rep_event_param {
124 __be64 remote_ca_guid;
125 u32 remote_qkey;
126 u32 remote_qpn;
127 u32 starting_psn;
128 u8 responder_resources;
129 u8 initiator_depth;
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;
134 unsigned int srq:1;
135 struct rdma_ucm_ece ece;
136};
137
138enum ib_cm_rej_reason {
139 IB_CM_REJ_NO_QP = 1,
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,
173};
174
175struct ib_cm_rej_event_param {
176 enum ib_cm_rej_reason reason;
177 void *ari;
178 u8 ari_length;
179};
180
181struct ib_cm_mra_event_param {
182 u8 service_timeout;
183};
184
185struct ib_cm_lap_event_param {
186 struct sa_path_rec *alternate_path;
187};
188
189enum ib_cm_apr_status {
190 IB_CM_APR_SUCCESS,
191 IB_CM_APR_INVALID_COMM_ID,
192 IB_CM_APR_UNSUPPORTED,
193 IB_CM_APR_REJECT,
194 IB_CM_APR_REDIRECT,
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,
203 IB_CM_APR_INVALID_SL
204};
205
206struct ib_cm_apr_event_param {
207 enum ib_cm_apr_status ap_status;
208 void *apr_info;
209 u8 info_len;
210};
211
212struct ib_cm_sidr_req_event_param {
213 struct ib_cm_id *listen_id;
214 __be64 service_id;
215
216 /*
217 * SGID attribute of the request. Currently only
218 * useful for RoCE.
219 */
220 const struct ib_gid_attr *sgid_attr;
221 /* P_Key that was used by the GMP's BTH header */
222 u16 bth_pkey;
223 u8 port;
224 u16 pkey;
225};
226
227enum ib_cm_sidr_status {
228 IB_SIDR_SUCCESS,
229 IB_SIDR_UNSUPPORTED,
230 IB_SIDR_REJECT,
231 IB_SIDR_NO_QP,
232 IB_SIDR_REDIRECT,
233 IB_SIDR_UNSUPPORTED_VERSION
234};
235
236struct ib_cm_sidr_rep_event_param {
237 enum ib_cm_sidr_status status;
238 u32 qkey;
239 u32 qpn;
240 void *info;
241 const struct ib_gid_attr *sgid_attr;
242 u8 info_len;
243};
244
245struct ib_cm_event {
246 enum ib_cm_event_type event;
247 union {
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;
259 } param;
260
261 void *private_data;
262};
263
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)
275
276/**
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.
280 *
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.
287 *
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.
291 */
292typedef int (*ib_cm_handler)(struct ib_cm_id *cm_id,
293 const struct ib_cm_event *event);
294
295struct ib_cm_id {
296 ib_cm_handler cm_handler;
297 void *context;
298 struct ib_device *device;
299 __be64 service_id;
300 __be64 service_mask;
301 enum ib_cm_state state; /* internal CM/debug use */
302 enum ib_cm_lap_state lap_state; /* internal CM/debug use */
303 __be32 local_id;
304 __be32 remote_id;
305 u32 remote_cm_qpn; /* 1 unless redirected */
306};
307
308/**
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
314 * identifier.
315 *
316 * Communication identifiers are used to track connection states, service
317 * ID resolution requests, and listen requests.
318 */
319struct ib_cm_id *ib_create_cm_id(struct ib_device *device,
320 ib_cm_handler cm_handler,
321 void *context);
322
323/**
324 * ib_destroy_cm_id - Destroy a connection identifier.
325 * @cm_id: Connection identifier to destroy.
326 *
327 * This call blocks until the connection identifier is destroyed.
328 */
329void ib_destroy_cm_id(struct ib_cm_id *cm_id);
330
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)
337
338/**
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.
350 */
351int ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id,
352 __be64 service_mask);
353
354struct ib_cm_id *ib_cm_insert_listen(struct ib_device *device,
355 ib_cm_handler cm_handler,
356 __be64 service_id);
357
358struct 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;
362 __be64 service_id;
363 u32 qp_num;
364 enum ib_qp_type qp_type;
365 u32 starting_psn;
366 const void *private_data;
367 u8 private_data_len;
368 u8 responder_resources;
369 u8 initiator_depth;
370 u8 remote_cm_response_timeout;
371 u8 flow_control;
372 u8 local_cm_response_timeout;
373 u8 retry_count;
374 u8 rnr_retry_count;
375 u8 max_cm_retries;
376 u8 srq;
377 struct rdma_ucm_ece ece;
378};
379
380/**
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
385 * connection.
386 */
387int ib_send_cm_req(struct ib_cm_id *cm_id,
388 struct ib_cm_req_param *param);
389
390struct ib_cm_rep_param {
391 u32 qp_num;
392 u32 starting_psn;
393 const void *private_data;
394 u8 private_data_len;
395 u8 responder_resources;
396 u8 initiator_depth;
397 u8 failover_accepted;
398 u8 flow_control;
399 u8 rnr_retry_count;
400 u8 srq;
401 struct rdma_ucm_ece ece;
402};
403
404/**
405 * ib_send_cm_rep - Sends a connection reply in response to a connection
406 * request.
407 * @cm_id: Connection identifier that will be associated with the
408 * connection request.
409 * @param: Connection reply information needed to establish the
410 * connection.
411 */
412int ib_send_cm_rep(struct ib_cm_id *cm_id,
413 struct ib_cm_rep_param *param);
414
415/**
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.
422 */
423int ib_send_cm_rtu(struct ib_cm_id *cm_id,
424 const void *private_data,
425 u8 private_data_len);
426
427/**
428 * ib_send_cm_dreq - Sends a disconnection request for an existing
429 * connection.
430 * @cm_id: Connection identifier associated with the connection being
431 * released.
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.
435 */
436int ib_send_cm_dreq(struct ib_cm_id *cm_id,
437 const void *private_data,
438 u8 private_data_len);
439
440/**
441 * ib_send_cm_drep - Sends a disconnection reply to a disconnection request.
442 * @cm_id: Connection identifier associated with the connection being
443 * released.
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.
447 *
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.
450 */
451int ib_send_cm_drep(struct ib_cm_id *cm_id,
452 const void *private_data,
453 u8 private_data_len);
454
455/**
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.
459 *
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:
463 *
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.
468 */
469int ib_cm_notify(struct ib_cm_id *cm_id, enum ib_event_type event);
470
471/**
472 * ib_send_cm_rej - Sends a connection rejection message to the
473 * remote node.
474 * @cm_id: Connection identifier associated with the connection being
475 * rejected.
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
480 * rejection message.
481 * @private_data_len: Size of the private data buffer, in bytes.
482 */
483int ib_send_cm_rej(struct ib_cm_id *cm_id,
484 enum ib_cm_rej_reason reason,
485 void *ari,
486 u8 ari_length,
487 const void *private_data,
488 u8 private_data_len);
489
490#define IB_CM_MRA_FLAG_DELAY 0x80 /* Send MRA only after a duplicate msg */
491
492/**
493 * ib_send_cm_mra - Sends a message receipt acknowledgement to a connection
494 * message.
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.
502 */
503int ib_send_cm_mra(struct ib_cm_id *cm_id,
504 u8 service_timeout,
505 const void *private_data,
506 u8 private_data_len);
507
508/**
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
512 * initialize.
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.
518 *
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.
523 */
524int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
525 struct ib_qp_attr *qp_attr,
526 int *qp_attr_mask);
527
528struct ib_cm_sidr_req_param {
529 struct sa_path_rec *path;
530 const struct ib_gid_attr *sgid_attr;
531 __be64 service_id;
532 unsigned long timeout_ms;
533 const void *private_data;
534 u8 private_data_len;
535 u8 max_cm_retries;
536};
537
538/**
539 * ib_send_cm_sidr_req - Sends a service ID resolution request to the
540 * remote node.
541 * @cm_id: Communication identifier that will be associated with the
542 * service ID resolution request.
543 * @param: Service ID resolution request information.
544 */
545int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
546 struct ib_cm_sidr_req_param *param);
547
548struct ib_cm_sidr_rep_param {
549 u32 qp_num;
550 u32 qkey;
551 enum ib_cm_sidr_status status;
552 const void *info;
553 u8 info_length;
554 const void *private_data;
555 u8 private_data_len;
556 struct rdma_ucm_ece ece;
557};
558
559/**
560 * ib_send_cm_sidr_rep - Sends a service ID resolution reply to the
561 * remote node.
562 * @cm_id: Communication identifier associated with the received service ID
563 * resolution request.
564 * @param: Service ID resolution reply information.
565 */
566int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
567 struct ib_cm_sidr_rep_param *param);
568
569/**
570 * ibcm_reject_msg - return a pointer to a reject message string.
571 * @reason: Value returned in the REJECT event status field.
572 */
573const char *__attribute_const__ ibcm_reject_msg(int reason);
574
575#endif /* IB_CM_H */