/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */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* Copyright (c) 2019, Mellanox Technologies inc. All rights reserved.7*/89#ifndef IB_CM_H10#define IB_CM_H1112#include <rdma/ib_mad.h>13#include <rdma/ib_sa.h>14#include <rdma/rdma_cm.h>1516enum ib_cm_state {17IB_CM_IDLE,18IB_CM_LISTEN,19IB_CM_REQ_SENT,20IB_CM_REQ_RCVD,21IB_CM_MRA_REQ_SENT,22IB_CM_MRA_REQ_RCVD,23IB_CM_REP_SENT,24IB_CM_REP_RCVD,25IB_CM_MRA_REP_SENT,26IB_CM_MRA_REP_RCVD,27IB_CM_ESTABLISHED,28IB_CM_DREQ_SENT,29IB_CM_DREQ_RCVD,30IB_CM_TIMEWAIT,31IB_CM_SIDR_REQ_SENT,32IB_CM_SIDR_REQ_RCVD33};3435enum ib_cm_lap_state {36IB_CM_LAP_UNINIT,37IB_CM_LAP_IDLE,38IB_CM_LAP_SENT,39IB_CM_LAP_RCVD,40IB_CM_MRA_LAP_SENT,41IB_CM_MRA_LAP_RCVD,42};4344enum ib_cm_event_type {45IB_CM_REQ_ERROR,46IB_CM_REQ_RECEIVED,47IB_CM_REP_ERROR,48IB_CM_REP_RECEIVED,49IB_CM_RTU_RECEIVED,50IB_CM_USER_ESTABLISHED,51IB_CM_DREQ_ERROR,52IB_CM_DREQ_RECEIVED,53IB_CM_DREP_RECEIVED,54IB_CM_TIMEWAIT_EXIT,55IB_CM_MRA_RECEIVED,56IB_CM_REJ_RECEIVED,57IB_CM_LAP_ERROR,58IB_CM_LAP_RECEIVED,59IB_CM_APR_RECEIVED,60IB_CM_SIDR_REQ_ERROR,61IB_CM_SIDR_REQ_RECEIVED,62IB_CM_SIDR_REP_RECEIVED63};6465enum ib_cm_data_size {66IB_CM_REQ_PRIVATE_DATA_SIZE = 92,67IB_CM_MRA_PRIVATE_DATA_SIZE = 222,68IB_CM_REJ_PRIVATE_DATA_SIZE = 148,69IB_CM_REP_PRIVATE_DATA_SIZE = 196,70IB_CM_RTU_PRIVATE_DATA_SIZE = 224,71IB_CM_DREQ_PRIVATE_DATA_SIZE = 220,72IB_CM_DREP_PRIVATE_DATA_SIZE = 224,73IB_CM_REJ_ARI_LENGTH = 72,74IB_CM_LAP_PRIVATE_DATA_SIZE = 168,75IB_CM_APR_PRIVATE_DATA_SIZE = 148,76IB_CM_APR_INFO_LENGTH = 72,77IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE = 216,78IB_CM_SIDR_REP_PRIVATE_DATA_SIZE = 136,79IB_CM_SIDR_REP_INFO_LENGTH = 72,80};8182struct ib_cm_id;8384struct ib_cm_req_event_param {85struct ib_cm_id *listen_id;8687/* P_Key that was used by the GMP's BTH header */88u16 bth_pkey;8990u8 port;9192struct sa_path_rec *primary_path;93struct sa_path_rec *alternate_path;9495/*96* SGID attribute of the primary path. Currently only97* useful for RoCE. Alternate path GID attributes98* are not yet supported.99*/100const struct ib_gid_attr *ppath_sgid_attr;101102__be64 remote_ca_guid;103u32 remote_qkey;104u32 remote_qpn;105enum ib_qp_type qp_type;106107u32 starting_psn;108u8 responder_resources;109u8 initiator_depth;110unsigned int local_cm_response_timeout:5;111unsigned int flow_control:1;112unsigned int remote_cm_response_timeout:5;113unsigned int retry_count:3;114unsigned int rnr_retry_count:3;115unsigned int srq:1;116struct rdma_ucm_ece ece;117};118119struct ib_cm_rep_event_param {120__be64 remote_ca_guid;121u32 remote_qkey;122u32 remote_qpn;123u32 starting_psn;124u8 responder_resources;125u8 initiator_depth;126unsigned int target_ack_delay:5;127unsigned int failover_accepted:2;128unsigned int flow_control:1;129unsigned int rnr_retry_count:3;130unsigned int srq:1;131struct rdma_ucm_ece ece;132};133134enum ib_cm_rej_reason {135IB_CM_REJ_NO_QP = 1,136IB_CM_REJ_NO_EEC = 2,137IB_CM_REJ_NO_RESOURCES = 3,138IB_CM_REJ_TIMEOUT = 4,139IB_CM_REJ_UNSUPPORTED = 5,140IB_CM_REJ_INVALID_COMM_ID = 6,141IB_CM_REJ_INVALID_COMM_INSTANCE = 7,142IB_CM_REJ_INVALID_SERVICE_ID = 8,143IB_CM_REJ_INVALID_TRANSPORT_TYPE = 9,144IB_CM_REJ_STALE_CONN = 10,145IB_CM_REJ_RDC_NOT_EXIST = 11,146IB_CM_REJ_INVALID_GID = 12,147IB_CM_REJ_INVALID_LID = 13,148IB_CM_REJ_INVALID_SL = 14,149IB_CM_REJ_INVALID_TRAFFIC_CLASS = 15,150IB_CM_REJ_INVALID_HOP_LIMIT = 16,151IB_CM_REJ_INVALID_PACKET_RATE = 17,152IB_CM_REJ_INVALID_ALT_GID = 18,153IB_CM_REJ_INVALID_ALT_LID = 19,154IB_CM_REJ_INVALID_ALT_SL = 20,155IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS = 21,156IB_CM_REJ_INVALID_ALT_HOP_LIMIT = 22,157IB_CM_REJ_INVALID_ALT_PACKET_RATE = 23,158IB_CM_REJ_PORT_CM_REDIRECT = 24,159IB_CM_REJ_PORT_REDIRECT = 25,160IB_CM_REJ_INVALID_MTU = 26,161IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES = 27,162IB_CM_REJ_CONSUMER_DEFINED = 28,163IB_CM_REJ_INVALID_RNR_RETRY = 29,164IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID = 30,165IB_CM_REJ_INVALID_CLASS_VERSION = 31,166IB_CM_REJ_INVALID_FLOW_LABEL = 32,167IB_CM_REJ_INVALID_ALT_FLOW_LABEL = 33,168IB_CM_REJ_VENDOR_OPTION_NOT_SUPPORTED = 35,169};170171struct ib_cm_rej_event_param {172enum ib_cm_rej_reason reason;173void *ari;174u8 ari_length;175};176177struct ib_cm_mra_event_param {178u8 service_timeout;179};180181struct ib_cm_lap_event_param {182struct sa_path_rec *alternate_path;183};184185enum ib_cm_apr_status {186IB_CM_APR_SUCCESS,187IB_CM_APR_INVALID_COMM_ID,188IB_CM_APR_UNSUPPORTED,189IB_CM_APR_REJECT,190IB_CM_APR_REDIRECT,191IB_CM_APR_IS_CURRENT,192IB_CM_APR_INVALID_QPN_EECN,193IB_CM_APR_INVALID_LID,194IB_CM_APR_INVALID_GID,195IB_CM_APR_INVALID_FLOW_LABEL,196IB_CM_APR_INVALID_TCLASS,197IB_CM_APR_INVALID_HOP_LIMIT,198IB_CM_APR_INVALID_PACKET_RATE,199IB_CM_APR_INVALID_SL200};201202struct ib_cm_apr_event_param {203enum ib_cm_apr_status ap_status;204void *apr_info;205u8 info_len;206};207208struct ib_cm_sidr_req_event_param {209struct ib_cm_id *listen_id;210__be64 service_id;211212/*213* SGID attribute of the request. Currently only214* useful for RoCE.215*/216const struct ib_gid_attr *sgid_attr;217/* P_Key that was used by the GMP's BTH header */218u16 bth_pkey;219u8 port;220u16 pkey;221};222223enum ib_cm_sidr_status {224IB_SIDR_SUCCESS,225IB_SIDR_UNSUPPORTED,226IB_SIDR_REJECT,227IB_SIDR_NO_QP,228IB_SIDR_REDIRECT,229IB_SIDR_UNSUPPORTED_VERSION230};231232struct ib_cm_sidr_rep_event_param {233enum ib_cm_sidr_status status;234u32 qkey;235u32 qpn;236void *info;237const struct ib_gid_attr *sgid_attr;238u8 info_len;239};240241struct ib_cm_event {242enum ib_cm_event_type event;243union {244struct ib_cm_req_event_param req_rcvd;245struct ib_cm_rep_event_param rep_rcvd;246/* No data for RTU received events. */247struct ib_cm_rej_event_param rej_rcvd;248struct ib_cm_mra_event_param mra_rcvd;249struct ib_cm_lap_event_param lap_rcvd;250struct ib_cm_apr_event_param apr_rcvd;251/* No data for DREQ/DREP received events. */252struct ib_cm_sidr_req_event_param sidr_req_rcvd;253struct ib_cm_sidr_rep_event_param sidr_rep_rcvd;254enum ib_wc_status send_status;255} param;256257void *private_data;258};259260#define CM_REQ_ATTR_ID cpu_to_be16(0x0010)261#define CM_MRA_ATTR_ID cpu_to_be16(0x0011)262#define CM_REJ_ATTR_ID cpu_to_be16(0x0012)263#define CM_REP_ATTR_ID cpu_to_be16(0x0013)264#define CM_RTU_ATTR_ID cpu_to_be16(0x0014)265#define CM_DREQ_ATTR_ID cpu_to_be16(0x0015)266#define CM_DREP_ATTR_ID cpu_to_be16(0x0016)267#define CM_SIDR_REQ_ATTR_ID cpu_to_be16(0x0017)268#define CM_SIDR_REP_ATTR_ID cpu_to_be16(0x0018)269#define CM_LAP_ATTR_ID cpu_to_be16(0x0019)270#define CM_APR_ATTR_ID cpu_to_be16(0x001A)271272/**273* ib_cm_handler - User-defined callback to process communication events.274* @cm_id: Communication identifier associated with the reported event.275* @event: Information about the communication event.276*277* IB_CM_REQ_RECEIVED and IB_CM_SIDR_REQ_RECEIVED communication events278* generated as a result of listen requests result in the allocation of a279* new @cm_id. The new @cm_id is returned to the user through this callback.280* Clients are responsible for destroying the new @cm_id. For peer-to-peer281* IB_CM_REQ_RECEIVED and all other events, the returned @cm_id corresponds282* to a user's existing communication identifier.283*284* Users may not call ib_destroy_cm_id while in the context of this callback;285* however, returning a non-zero value instructs the communication manager to286* destroy the @cm_id after the callback completes.287*/288typedef int (*ib_cm_handler)(struct ib_cm_id *cm_id,289const struct ib_cm_event *event);290291struct ib_cm_id {292ib_cm_handler cm_handler;293void *context;294struct ib_device *device;295__be64 service_id;296enum ib_cm_state state; /* internal CM/debug use */297enum ib_cm_lap_state lap_state; /* internal CM/debug use */298__be32 local_id;299__be32 remote_id;300u32 remote_cm_qpn; /* 1 unless redirected */301};302303/**304* ib_create_cm_id - Allocate a communication identifier.305* @device: Device associated with the cm_id. All related communication will306* be associated with the specified device.307* @cm_handler: Callback invoked to notify the user of CM events.308* @context: User specified context associated with the communication309* identifier.310*311* Communication identifiers are used to track connection states, service312* ID resolution requests, and listen requests.313*/314struct ib_cm_id *ib_create_cm_id(struct ib_device *device,315ib_cm_handler cm_handler,316void *context);317318/**319* ib_destroy_cm_id - Destroy a connection identifier.320* @cm_id: Connection identifier to destroy.321*322* This call blocks until the connection identifier is destroyed.323*/324void ib_destroy_cm_id(struct ib_cm_id *cm_id);325326#define IB_SERVICE_ID_AGN_MASK cpu_to_be64(0xFF00000000000000ULL)327#define IB_CM_ASSIGN_SERVICE_ID cpu_to_be64(0x0200000000000000ULL)328#define IB_CMA_SERVICE_ID cpu_to_be64(0x0000000001000000ULL)329#define IB_CMA_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFF000000ULL)330#define IB_SDP_SERVICE_ID cpu_to_be64(0x0000000000010000ULL)331#define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL)332333/**334* ib_cm_listen - Initiates listening on the specified service ID for335* connection and service ID resolution requests.336* @cm_id: Connection identifier associated with the listen request.337* @service_id: Service identifier matched against incoming connection338* and service ID resolution requests. The service ID should be specified339* network-byte order. If set to IB_CM_ASSIGN_SERVICE_ID, the CM will340* assign a service ID to the caller.341*/342int ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id);343344struct ib_cm_id *ib_cm_insert_listen(struct ib_device *device,345ib_cm_handler cm_handler,346__be64 service_id);347348struct ib_cm_req_param {349struct sa_path_rec *primary_path;350struct sa_path_rec *primary_path_inbound;351struct sa_path_rec *primary_path_outbound;352struct sa_path_rec *alternate_path;353const struct ib_gid_attr *ppath_sgid_attr;354__be64 service_id;355u32 qp_num;356enum ib_qp_type qp_type;357u32 starting_psn;358const void *private_data;359u8 private_data_len;360u8 responder_resources;361u8 initiator_depth;362u8 remote_cm_response_timeout;363u8 flow_control;364u8 local_cm_response_timeout;365u8 retry_count;366u8 rnr_retry_count;367u8 max_cm_retries;368u8 srq;369struct rdma_ucm_ece ece;370};371372/**373* ib_send_cm_req - Sends a connection request to the remote node.374* @cm_id: Connection identifier that will be associated with the375* connection request.376* @param: Connection request information needed to establish the377* connection.378*/379int ib_send_cm_req(struct ib_cm_id *cm_id,380struct ib_cm_req_param *param);381382struct ib_cm_rep_param {383u32 qp_num;384u32 starting_psn;385const void *private_data;386u8 private_data_len;387u8 responder_resources;388u8 initiator_depth;389u8 failover_accepted;390u8 flow_control;391u8 rnr_retry_count;392u8 srq;393struct rdma_ucm_ece ece;394};395396/**397* ib_send_cm_rep - Sends a connection reply in response to a connection398* request.399* @cm_id: Connection identifier that will be associated with the400* connection request.401* @param: Connection reply information needed to establish the402* connection.403*/404int ib_send_cm_rep(struct ib_cm_id *cm_id,405struct ib_cm_rep_param *param);406407/**408* ib_send_cm_rtu - Sends a connection ready to use message in response409* to a connection reply message.410* @cm_id: Connection identifier associated with the connection request.411* @private_data: Optional user-defined private data sent with the412* ready to use message.413* @private_data_len: Size of the private data buffer, in bytes.414*/415int ib_send_cm_rtu(struct ib_cm_id *cm_id,416const void *private_data,417u8 private_data_len);418419/**420* ib_send_cm_dreq - Sends a disconnection request for an existing421* connection.422* @cm_id: Connection identifier associated with the connection being423* released.424* @private_data: Optional user-defined private data sent with the425* disconnection request message.426* @private_data_len: Size of the private data buffer, in bytes.427*/428int ib_send_cm_dreq(struct ib_cm_id *cm_id,429const void *private_data,430u8 private_data_len);431432/**433* ib_send_cm_drep - Sends a disconnection reply to a disconnection request.434* @cm_id: Connection identifier associated with the connection being435* released.436* @private_data: Optional user-defined private data sent with the437* disconnection reply message.438* @private_data_len: Size of the private data buffer, in bytes.439*440* If the cm_id is in the correct state, the CM will transition the connection441* to the timewait state, even if an error occurs sending the DREP message.442*/443int ib_send_cm_drep(struct ib_cm_id *cm_id,444const void *private_data,445u8 private_data_len);446447/**448* ib_cm_notify - Notifies the CM of an event reported to the consumer.449* @cm_id: Connection identifier to transition to established.450* @event: Type of event.451*452* This routine should be invoked by users to notify the CM of relevant453* communication events. Events that should be reported to the CM and454* when to report them are:455*456* IB_EVENT_COMM_EST - Used when a message is received on a connected457* QP before an RTU has been received.458* IB_EVENT_PATH_MIG - Notifies the CM that the connection has failed over459* to the alternate path.460*/461int ib_cm_notify(struct ib_cm_id *cm_id, enum ib_event_type event);462463/**464* ib_send_cm_rej - Sends a connection rejection message to the465* remote node.466* @cm_id: Connection identifier associated with the connection being467* rejected.468* @reason: Reason for the connection request rejection.469* @ari: Optional additional rejection information.470* @ari_length: Size of the additional rejection information, in bytes.471* @private_data: Optional user-defined private data sent with the472* rejection message.473* @private_data_len: Size of the private data buffer, in bytes.474*/475int ib_send_cm_rej(struct ib_cm_id *cm_id,476enum ib_cm_rej_reason reason,477void *ari,478u8 ari_length,479const void *private_data,480u8 private_data_len);481482/**483* ib_prepare_cm_mra - Prepares to send a message receipt acknowledgment to a484connection message in case duplicates are received.485* @cm_id: Connection identifier associated with the connection message.486*/487int ib_prepare_cm_mra(struct ib_cm_id *cm_id);488489/**490* ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning491* to a specified QP state.492* @cm_id: Communication identifier associated with the QP attributes to493* initialize.494* @qp_attr: On input, specifies the desired QP state. On output, the495* mandatory and desired optional attributes will be set in order to496* modify the QP to the specified state.497* @qp_attr_mask: The QP attribute mask that may be used to transition the498* QP to the specified state.499*500* Users must set the @qp_attr->qp_state to the desired QP state. This call501* will set all required attributes for the given transition, along with502* known optional attributes. Users may override the attributes returned from503* this call before calling ib_modify_qp.504*/505int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,506struct ib_qp_attr *qp_attr,507int *qp_attr_mask);508509struct ib_cm_sidr_req_param {510struct sa_path_rec *path;511const struct ib_gid_attr *sgid_attr;512__be64 service_id;513unsigned long timeout_ms;514const void *private_data;515u8 private_data_len;516u8 max_cm_retries;517};518519/**520* ib_send_cm_sidr_req - Sends a service ID resolution request to the521* remote node.522* @cm_id: Communication identifier that will be associated with the523* service ID resolution request.524* @param: Service ID resolution request information.525*/526int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,527struct ib_cm_sidr_req_param *param);528529struct ib_cm_sidr_rep_param {530u32 qp_num;531u32 qkey;532enum ib_cm_sidr_status status;533const void *info;534u8 info_length;535const void *private_data;536u8 private_data_len;537struct rdma_ucm_ece ece;538};539540/**541* ib_send_cm_sidr_rep - Sends a service ID resolution reply to the542* remote node.543* @cm_id: Communication identifier associated with the received service ID544* resolution request.545* @param: Service ID resolution reply information.546*/547int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,548struct ib_cm_sidr_rep_param *param);549550/**551* ibcm_reject_msg - return a pointer to a reject message string.552* @reason: Value returned in the REJECT event status field.553*/554const char *__attribute_const__ ibcm_reject_msg(int reason);555556#endif /* IB_CM_H */557558559