Merge tag 'nfs-for-5.8-2' of git://git.linux-nfs.org/projects/anna/linux-nfs
[linux/fpc-iii.git] / include / rdma / ib_cm.h
blob0f1ea5f2d01cd6adfa090e80ceebf32e04c0a40c
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 #ifndef IB_CM_H
10 #define IB_CM_H
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;
19 enum ib_cm_state {
20 IB_CM_IDLE,
21 IB_CM_LISTEN,
22 IB_CM_REQ_SENT,
23 IB_CM_REQ_RCVD,
24 IB_CM_MRA_REQ_SENT,
25 IB_CM_MRA_REQ_RCVD,
26 IB_CM_REP_SENT,
27 IB_CM_REP_RCVD,
28 IB_CM_MRA_REP_SENT,
29 IB_CM_MRA_REP_RCVD,
30 IB_CM_ESTABLISHED,
31 IB_CM_DREQ_SENT,
32 IB_CM_DREQ_RCVD,
33 IB_CM_TIMEWAIT,
34 IB_CM_SIDR_REQ_SENT,
35 IB_CM_SIDR_REQ_RCVD
38 enum ib_cm_lap_state {
39 IB_CM_LAP_UNINIT,
40 IB_CM_LAP_IDLE,
41 IB_CM_LAP_SENT,
42 IB_CM_LAP_RCVD,
43 IB_CM_MRA_LAP_SENT,
44 IB_CM_MRA_LAP_RCVD,
47 enum ib_cm_event_type {
48 IB_CM_REQ_ERROR,
49 IB_CM_REQ_RECEIVED,
50 IB_CM_REP_ERROR,
51 IB_CM_REP_RECEIVED,
52 IB_CM_RTU_RECEIVED,
53 IB_CM_USER_ESTABLISHED,
54 IB_CM_DREQ_ERROR,
55 IB_CM_DREQ_RECEIVED,
56 IB_CM_DREP_RECEIVED,
57 IB_CM_TIMEWAIT_EXIT,
58 IB_CM_MRA_RECEIVED,
59 IB_CM_REJ_RECEIVED,
60 IB_CM_LAP_ERROR,
61 IB_CM_LAP_RECEIVED,
62 IB_CM_APR_RECEIVED,
63 IB_CM_SIDR_REQ_ERROR,
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,
85 struct ib_cm_id;
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 */
91 u16 bth_pkey;
93 u8 port;
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;
106 u32 remote_qkey;
107 u32 remote_qpn;
108 enum ib_qp_type qp_type;
110 u32 starting_psn;
111 u8 responder_resources;
112 u8 initiator_depth;
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;
118 unsigned int srq:1;
119 struct rdma_ucm_ece ece;
122 struct ib_cm_rep_event_param {
123 __be64 remote_ca_guid;
124 u32 remote_qkey;
125 u32 remote_qpn;
126 u32 starting_psn;
127 u8 responder_resources;
128 u8 initiator_depth;
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;
133 unsigned int srq:1;
134 struct rdma_ucm_ece ece;
137 enum ib_cm_rej_reason {
138 IB_CM_REJ_NO_QP = 1,
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;
176 void *ari;
177 u8 ari_length;
180 struct ib_cm_mra_event_param {
181 u8 service_timeout;
184 struct ib_cm_lap_event_param {
185 struct sa_path_rec *alternate_path;
188 enum ib_cm_apr_status {
189 IB_CM_APR_SUCCESS,
190 IB_CM_APR_INVALID_COMM_ID,
191 IB_CM_APR_UNSUPPORTED,
192 IB_CM_APR_REJECT,
193 IB_CM_APR_REDIRECT,
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,
202 IB_CM_APR_INVALID_SL
205 struct ib_cm_apr_event_param {
206 enum ib_cm_apr_status ap_status;
207 void *apr_info;
208 u8 info_len;
211 struct ib_cm_sidr_req_event_param {
212 struct ib_cm_id *listen_id;
213 __be64 service_id;
216 * SGID attribute of the request. Currently only
217 * useful for RoCE.
219 const struct ib_gid_attr *sgid_attr;
220 /* P_Key that was used by the GMP's BTH header */
221 u16 bth_pkey;
222 u8 port;
223 u16 pkey;
226 enum 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
235 struct ib_cm_sidr_rep_event_param {
236 enum ib_cm_sidr_status status;
237 u32 qkey;
238 u32 qpn;
239 void *info;
240 const struct ib_gid_attr *sgid_attr;
241 u8 info_len;
244 struct ib_cm_event {
245 enum ib_cm_event_type event;
246 union {
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;
258 } param;
260 void *private_data;
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);
294 struct ib_cm_id {
295 ib_cm_handler cm_handler;
296 void *context;
297 struct ib_device *device;
298 __be64 service_id;
299 __be64 service_mask;
300 enum ib_cm_state state; /* internal CM/debug use */
301 enum ib_cm_lap_state lap_state; /* internal CM/debug use */
302 __be32 local_id;
303 __be32 remote_id;
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
313 * identifier.
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,
320 void *context);
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,
355 __be64 service_id);
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;
361 __be64 service_id;
362 u32 qp_num;
363 enum ib_qp_type qp_type;
364 u32 starting_psn;
365 const void *private_data;
366 u8 private_data_len;
367 u8 responder_resources;
368 u8 initiator_depth;
369 u8 remote_cm_response_timeout;
370 u8 flow_control;
371 u8 local_cm_response_timeout;
372 u8 retry_count;
373 u8 rnr_retry_count;
374 u8 max_cm_retries;
375 u8 srq;
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
384 * connection.
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 {
390 u32 qp_num;
391 u32 starting_psn;
392 const void *private_data;
393 u8 private_data_len;
394 u8 responder_resources;
395 u8 initiator_depth;
396 u8 failover_accepted;
397 u8 flow_control;
398 u8 rnr_retry_count;
399 u8 srq;
400 struct rdma_ucm_ece ece;
404 * ib_send_cm_rep - Sends a connection reply in response to a connection
405 * request.
406 * @cm_id: Connection identifier that will be associated with the
407 * connection request.
408 * @param: Connection reply information needed to establish the
409 * connection.
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
428 * connection.
429 * @cm_id: Connection identifier associated with the connection being
430 * released.
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
442 * released.
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
472 * remote node.
473 * @cm_id: Connection identifier associated with the connection being
474 * rejected.
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
479 * rejection message.
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,
484 void *ari,
485 u8 ari_length,
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
493 * message.
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,
503 u8 service_timeout,
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
511 * initialize.
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,
525 int *qp_attr_mask);
527 struct ib_cm_sidr_req_param {
528 struct sa_path_rec *path;
529 const struct ib_gid_attr *sgid_attr;
530 __be64 service_id;
531 unsigned long timeout_ms;
532 const void *private_data;
533 u8 private_data_len;
534 u8 max_cm_retries;
538 * ib_send_cm_sidr_req - Sends a service ID resolution request to the
539 * remote node.
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 {
548 u32 qp_num;
549 u32 qkey;
550 enum ib_cm_sidr_status status;
551 const void *info;
552 u8 info_length;
553 const void *private_data;
554 u8 private_data_len;
555 struct rdma_ucm_ece ece;
559 * ib_send_cm_sidr_rep - Sends a service ID resolution reply to the
560 * remote node.
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);
574 #endif /* IB_CM_H */