/*-1* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.02*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*8* This software is available to you under a choice of one of two9* licenses. You may choose to be licensed under the terms of the GNU10* General Public License (GPL) Version 2, available from the file11* COPYING in the main directory of this source tree, or the12* OpenIB.org BSD license below:13*14* Redistribution and use in source and binary forms, with or15* without modification, are permitted provided that the following16* conditions are met:17*18* - Redistributions of source code must retain the above19* copyright notice, this list of conditions and the following20* disclaimer.21*22* - Redistributions in binary form must reproduce the above23* copyright notice, this list of conditions and the following24* disclaimer in the documentation and/or other materials25* provided with the distribution.26*27* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,28* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF29* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND30* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS31* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN32* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN33* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE34* SOFTWARE.35*/3637#if !defined(IB_CM_H)38#define IB_CM_H3940#include <rdma/ib_mad.h>41#include <rdma/ib_sa.h>4243/* ib_cm and ib_user_cm modules share /sys/class/infiniband_cm */44extern struct class cm_class;4546enum ib_cm_state {47IB_CM_IDLE,48IB_CM_LISTEN,49IB_CM_REQ_SENT,50IB_CM_REQ_RCVD,51IB_CM_MRA_REQ_SENT,52IB_CM_MRA_REQ_RCVD,53IB_CM_REP_SENT,54IB_CM_REP_RCVD,55IB_CM_MRA_REP_SENT,56IB_CM_MRA_REP_RCVD,57IB_CM_ESTABLISHED,58IB_CM_DREQ_SENT,59IB_CM_DREQ_RCVD,60IB_CM_TIMEWAIT,61IB_CM_SIDR_REQ_SENT,62IB_CM_SIDR_REQ_RCVD63};6465enum ib_cm_lap_state {66IB_CM_LAP_UNINIT,67IB_CM_LAP_IDLE,68IB_CM_LAP_SENT,69IB_CM_LAP_RCVD,70IB_CM_MRA_LAP_SENT,71IB_CM_MRA_LAP_RCVD,72};7374enum ib_cm_event_type {75IB_CM_REQ_ERROR,76IB_CM_REQ_RECEIVED,77IB_CM_REP_ERROR,78IB_CM_REP_RECEIVED,79IB_CM_RTU_RECEIVED,80IB_CM_USER_ESTABLISHED,81IB_CM_DREQ_ERROR,82IB_CM_DREQ_RECEIVED,83IB_CM_DREP_RECEIVED,84IB_CM_TIMEWAIT_EXIT,85IB_CM_MRA_RECEIVED,86IB_CM_REJ_RECEIVED,87IB_CM_LAP_ERROR,88IB_CM_LAP_RECEIVED,89IB_CM_APR_RECEIVED,90IB_CM_SIDR_REQ_ERROR,91IB_CM_SIDR_REQ_RECEIVED,92IB_CM_SIDR_REP_RECEIVED93};9495enum ib_cm_data_size {96IB_CM_REQ_PRIVATE_DATA_SIZE = 92,97IB_CM_MRA_PRIVATE_DATA_SIZE = 222,98IB_CM_REJ_PRIVATE_DATA_SIZE = 148,99IB_CM_REP_PRIVATE_DATA_SIZE = 196,100IB_CM_RTU_PRIVATE_DATA_SIZE = 224,101IB_CM_DREQ_PRIVATE_DATA_SIZE = 220,102IB_CM_DREP_PRIVATE_DATA_SIZE = 224,103IB_CM_REJ_ARI_LENGTH = 72,104IB_CM_LAP_PRIVATE_DATA_SIZE = 168,105IB_CM_APR_PRIVATE_DATA_SIZE = 148,106IB_CM_APR_INFO_LENGTH = 72,107IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE = 216,108IB_CM_SIDR_REP_PRIVATE_DATA_SIZE = 136,109IB_CM_SIDR_REP_INFO_LENGTH = 72,110};111112struct ib_cm_id;113114struct ib_cm_req_event_param {115struct ib_cm_id *listen_id;116117/* P_Key that was used by the GMP's BTH header */118u16 bth_pkey;119120u8 port;121122struct ib_sa_path_rec *primary_path;123struct ib_sa_path_rec *alternate_path;124125/*126* SGID index of the primary path. Currently only127* useful for RoCE. Alternate path GID attributes128* are not yet supported.129*/130u8 ppath_sgid_index;131132__be64 remote_ca_guid;133u32 remote_qkey;134u32 remote_qpn;135enum ib_qp_type qp_type;136137u32 starting_psn;138u8 responder_resources;139u8 initiator_depth;140unsigned int local_cm_response_timeout:5;141unsigned int flow_control:1;142unsigned int remote_cm_response_timeout:5;143unsigned int retry_count:3;144unsigned int rnr_retry_count:3;145unsigned int srq:1;146};147148struct ib_cm_rep_event_param {149__be64 remote_ca_guid;150u32 remote_qkey;151u32 remote_qpn;152u32 starting_psn;153u8 responder_resources;154u8 initiator_depth;155unsigned int target_ack_delay:5;156unsigned int failover_accepted:2;157unsigned int flow_control:1;158unsigned int rnr_retry_count:3;159unsigned int srq:1;160};161162enum ib_cm_rej_reason {163IB_CM_REJ_NO_QP = 1,164IB_CM_REJ_NO_EEC = 2,165IB_CM_REJ_NO_RESOURCES = 3,166IB_CM_REJ_TIMEOUT = 4,167IB_CM_REJ_UNSUPPORTED = 5,168IB_CM_REJ_INVALID_COMM_ID = 6,169IB_CM_REJ_INVALID_COMM_INSTANCE = 7,170IB_CM_REJ_INVALID_SERVICE_ID = 8,171IB_CM_REJ_INVALID_TRANSPORT_TYPE = 9,172IB_CM_REJ_STALE_CONN = 10,173IB_CM_REJ_RDC_NOT_EXIST = 11,174IB_CM_REJ_INVALID_GID = 12,175IB_CM_REJ_INVALID_LID = 13,176IB_CM_REJ_INVALID_SL = 14,177IB_CM_REJ_INVALID_TRAFFIC_CLASS = 15,178IB_CM_REJ_INVALID_HOP_LIMIT = 16,179IB_CM_REJ_INVALID_PACKET_RATE = 17,180IB_CM_REJ_INVALID_ALT_GID = 18,181IB_CM_REJ_INVALID_ALT_LID = 19,182IB_CM_REJ_INVALID_ALT_SL = 20,183IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS = 21,184IB_CM_REJ_INVALID_ALT_HOP_LIMIT = 22,185IB_CM_REJ_INVALID_ALT_PACKET_RATE = 23,186IB_CM_REJ_PORT_CM_REDIRECT = 24,187IB_CM_REJ_PORT_REDIRECT = 25,188IB_CM_REJ_INVALID_MTU = 26,189IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES = 27,190IB_CM_REJ_CONSUMER_DEFINED = 28,191IB_CM_REJ_INVALID_RNR_RETRY = 29,192IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID = 30,193IB_CM_REJ_INVALID_CLASS_VERSION = 31,194IB_CM_REJ_INVALID_FLOW_LABEL = 32,195IB_CM_REJ_INVALID_ALT_FLOW_LABEL = 33196};197198struct ib_cm_rej_event_param {199enum ib_cm_rej_reason reason;200void *ari;201u8 ari_length;202};203204struct ib_cm_mra_event_param {205u8 service_timeout;206};207208struct ib_cm_lap_event_param {209struct ib_sa_path_rec *alternate_path;210};211212enum ib_cm_apr_status {213IB_CM_APR_SUCCESS,214IB_CM_APR_INVALID_COMM_ID,215IB_CM_APR_UNSUPPORTED,216IB_CM_APR_REJECT,217IB_CM_APR_REDIRECT,218IB_CM_APR_IS_CURRENT,219IB_CM_APR_INVALID_QPN_EECN,220IB_CM_APR_INVALID_LID,221IB_CM_APR_INVALID_GID,222IB_CM_APR_INVALID_FLOW_LABEL,223IB_CM_APR_INVALID_TCLASS,224IB_CM_APR_INVALID_HOP_LIMIT,225IB_CM_APR_INVALID_PACKET_RATE,226IB_CM_APR_INVALID_SL227};228229struct ib_cm_apr_event_param {230enum ib_cm_apr_status ap_status;231void *apr_info;232u8 info_len;233};234235struct ib_cm_sidr_req_event_param {236struct ib_cm_id *listen_id;237__be64 service_id;238239/*240* SGID index of the request. Currently only241* useful for RoCE.242*/243u8 sgid_index;244245/* P_Key that was used by the GMP's BTH header */246u16 bth_pkey;247u8 port;248u16 pkey;249};250251enum ib_cm_sidr_status {252IB_SIDR_SUCCESS,253IB_SIDR_UNSUPPORTED,254IB_SIDR_REJECT,255IB_SIDR_NO_QP,256IB_SIDR_REDIRECT,257IB_SIDR_UNSUPPORTED_VERSION258};259260struct ib_cm_sidr_rep_event_param {261enum ib_cm_sidr_status status;262u32 qkey;263u32 qpn;264void *info;265u8 info_len;266};267268struct ib_cm_event {269enum ib_cm_event_type event;270union {271struct ib_cm_req_event_param req_rcvd;272struct ib_cm_rep_event_param rep_rcvd;273/* No data for RTU received events. */274struct ib_cm_rej_event_param rej_rcvd;275struct ib_cm_mra_event_param mra_rcvd;276struct ib_cm_lap_event_param lap_rcvd;277struct ib_cm_apr_event_param apr_rcvd;278/* No data for DREQ/DREP received events. */279struct ib_cm_sidr_req_event_param sidr_req_rcvd;280struct ib_cm_sidr_rep_event_param sidr_rep_rcvd;281enum ib_wc_status send_status;282} param;283284void *private_data;285};286287#define CM_REQ_ATTR_ID cpu_to_be16(0x0010)288#define CM_MRA_ATTR_ID cpu_to_be16(0x0011)289#define CM_REJ_ATTR_ID cpu_to_be16(0x0012)290#define CM_REP_ATTR_ID cpu_to_be16(0x0013)291#define CM_RTU_ATTR_ID cpu_to_be16(0x0014)292#define CM_DREQ_ATTR_ID cpu_to_be16(0x0015)293#define CM_DREP_ATTR_ID cpu_to_be16(0x0016)294#define CM_SIDR_REQ_ATTR_ID cpu_to_be16(0x0017)295#define CM_SIDR_REP_ATTR_ID cpu_to_be16(0x0018)296#define CM_LAP_ATTR_ID cpu_to_be16(0x0019)297#define CM_APR_ATTR_ID cpu_to_be16(0x001A)298299/**300* ib_cm_handler - User-defined callback to process communication events.301* @cm_id: Communication identifier associated with the reported event.302* @event: Information about the communication event.303*304* IB_CM_REQ_RECEIVED and IB_CM_SIDR_REQ_RECEIVED communication events305* generated as a result of listen requests result in the allocation of a306* new @cm_id. The new @cm_id is returned to the user through this callback.307* Clients are responsible for destroying the new @cm_id. For peer-to-peer308* IB_CM_REQ_RECEIVED and all other events, the returned @cm_id corresponds309* to a user's existing communication identifier.310*311* Users may not call ib_destroy_cm_id while in the context of this callback;312* however, returning a non-zero value instructs the communication manager to313* destroy the @cm_id after the callback completes.314*/315typedef int (*ib_cm_handler)(struct ib_cm_id *cm_id,316struct ib_cm_event *event);317318struct ib_cm_id {319ib_cm_handler cm_handler;320void *context;321struct ib_device *device;322__be64 service_id;323__be64 service_mask;324enum ib_cm_state state; /* internal CM/debug use */325enum ib_cm_lap_state lap_state; /* internal CM/debug use */326__be32 local_id;327__be32 remote_id;328u32 remote_cm_qpn; /* 1 unless redirected */329};330331/**332* ib_create_cm_id - Allocate a communication identifier.333* @device: Device associated with the cm_id. All related communication will334* be associated with the specified device.335* @cm_handler: Callback invoked to notify the user of CM events.336* @context: User specified context associated with the communication337* identifier.338*339* Communication identifiers are used to track connection states, service340* ID resolution requests, and listen requests.341*/342struct ib_cm_id *ib_create_cm_id(struct ib_device *device,343ib_cm_handler cm_handler,344void *context);345346/**347* ib_destroy_cm_id - Destroy a connection identifier.348* @cm_id: Connection identifier to destroy.349*350* This call blocks until the connection identifier is destroyed.351*/352void ib_destroy_cm_id(struct ib_cm_id *cm_id);353354#define IB_SERVICE_ID_AGN_MASK cpu_to_be64(0xFF00000000000000ULL)355#define IB_CM_ASSIGN_SERVICE_ID cpu_to_be64(0x0200000000000000ULL)356#define IB_CMA_SERVICE_ID cpu_to_be64(0x0000000001000000ULL)357#define IB_CMA_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFF000000ULL)358#define IB_SDP_SERVICE_ID cpu_to_be64(0x0000000000010000ULL)359#define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL)360361/**362* ib_cm_listen - Initiates listening on the specified service ID for363* connection and service ID resolution requests.364* @cm_id: Connection identifier associated with the listen request.365* @service_id: Service identifier matched against incoming connection366* and service ID resolution requests. The service ID should be specified367* network-byte order. If set to IB_CM_ASSIGN_SERVICE_ID, the CM will368* assign a service ID to the caller.369* @service_mask: Mask applied to service ID used to listen across a370* range of service IDs. If set to 0, the service ID is matched371* exactly. This parameter is ignored if %service_id is set to372* IB_CM_ASSIGN_SERVICE_ID.373*/374int ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id,375__be64 service_mask);376377struct ib_cm_id *ib_cm_insert_listen(struct ib_device *device,378ib_cm_handler cm_handler,379__be64 service_id);380381struct ib_cm_req_param {382struct ib_sa_path_rec *primary_path;383struct ib_sa_path_rec *alternate_path;384__be64 service_id;385u32 qp_num;386enum ib_qp_type qp_type;387u32 starting_psn;388const void *private_data;389u8 private_data_len;390u8 peer_to_peer;391u8 responder_resources;392u8 initiator_depth;393u8 remote_cm_response_timeout;394u8 flow_control;395u8 local_cm_response_timeout;396u8 retry_count;397u8 rnr_retry_count;398u8 max_cm_retries;399u8 srq;400};401402/**403* ib_send_cm_req - Sends a connection request to the remote node.404* @cm_id: Connection identifier that will be associated with the405* connection request.406* @param: Connection request information needed to establish the407* connection.408*/409int ib_send_cm_req(struct ib_cm_id *cm_id,410struct ib_cm_req_param *param);411412struct ib_cm_rep_param {413u32 qp_num;414u32 starting_psn;415const void *private_data;416u8 private_data_len;417u8 responder_resources;418u8 initiator_depth;419u8 failover_accepted;420u8 flow_control;421u8 rnr_retry_count;422u8 srq;423};424425/**426* ib_send_cm_rep - Sends a connection reply in response to a connection427* request.428* @cm_id: Connection identifier that will be associated with the429* connection request.430* @param: Connection reply information needed to establish the431* connection.432*/433int ib_send_cm_rep(struct ib_cm_id *cm_id,434struct ib_cm_rep_param *param);435436/**437* ib_send_cm_rtu - Sends a connection ready to use message in response438* to a connection reply message.439* @cm_id: Connection identifier associated with the connection request.440* @private_data: Optional user-defined private data sent with the441* ready to use message.442* @private_data_len: Size of the private data buffer, in bytes.443*/444int ib_send_cm_rtu(struct ib_cm_id *cm_id,445const void *private_data,446u8 private_data_len);447448/**449* ib_send_cm_dreq - Sends a disconnection request for an existing450* connection.451* @cm_id: Connection identifier associated with the connection being452* released.453* @private_data: Optional user-defined private data sent with the454* disconnection request message.455* @private_data_len: Size of the private data buffer, in bytes.456*/457int ib_send_cm_dreq(struct ib_cm_id *cm_id,458const void *private_data,459u8 private_data_len);460461/**462* ib_send_cm_drep - Sends a disconnection reply to a disconnection request.463* @cm_id: Connection identifier associated with the connection being464* released.465* @private_data: Optional user-defined private data sent with the466* disconnection reply message.467* @private_data_len: Size of the private data buffer, in bytes.468*469* If the cm_id is in the correct state, the CM will transition the connection470* to the timewait state, even if an error occurs sending the DREP message.471*/472int ib_send_cm_drep(struct ib_cm_id *cm_id,473const void *private_data,474u8 private_data_len);475476/**477* ib_cm_notify - Notifies the CM of an event reported to the consumer.478* @cm_id: Connection identifier to transition to established.479* @event: Type of event.480*481* This routine should be invoked by users to notify the CM of relevant482* communication events. Events that should be reported to the CM and483* when to report them are:484*485* IB_EVENT_COMM_EST - Used when a message is received on a connected486* QP before an RTU has been received.487* IB_EVENT_PATH_MIG - Notifies the CM that the connection has failed over488* to the alternate path.489*/490int ib_cm_notify(struct ib_cm_id *cm_id, enum ib_event_type event);491492/**493* ib_send_cm_rej - Sends a connection rejection message to the494* remote node.495* @cm_id: Connection identifier associated with the connection being496* rejected.497* @reason: Reason for the connection request rejection.498* @ari: Optional additional rejection information.499* @ari_length: Size of the additional rejection information, in bytes.500* @private_data: Optional user-defined private data sent with the501* rejection message.502* @private_data_len: Size of the private data buffer, in bytes.503*/504int ib_send_cm_rej(struct ib_cm_id *cm_id,505enum ib_cm_rej_reason reason,506void *ari,507u8 ari_length,508const void *private_data,509u8 private_data_len);510511#define IB_CM_MRA_FLAG_DELAY 0x80 /* Send MRA only after a duplicate msg */512513/**514* ib_send_cm_mra - Sends a message receipt acknowledgement to a connection515* message.516* @cm_id: Connection identifier associated with the connection message.517* @service_timeout: The lower 5-bits specify the maximum time required for518* the sender to reply to the connection message. The upper 3-bits519* specify additional control flags.520* @private_data: Optional user-defined private data sent with the521* message receipt acknowledgement.522* @private_data_len: Size of the private data buffer, in bytes.523*/524int ib_send_cm_mra(struct ib_cm_id *cm_id,525u8 service_timeout,526const void *private_data,527u8 private_data_len);528529/**530* ib_send_cm_lap - Sends a load alternate path request.531* @cm_id: Connection identifier associated with the load alternate path532* message.533* @alternate_path: A path record that identifies the alternate path to534* load.535* @private_data: Optional user-defined private data sent with the536* load alternate path message.537* @private_data_len: Size of the private data buffer, in bytes.538*/539int ib_send_cm_lap(struct ib_cm_id *cm_id,540struct ib_sa_path_rec *alternate_path,541const void *private_data,542u8 private_data_len);543544/**545* ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning546* to a specified QP state.547* @cm_id: Communication identifier associated with the QP attributes to548* initialize.549* @qp_attr: On input, specifies the desired QP state. On output, the550* mandatory and desired optional attributes will be set in order to551* modify the QP to the specified state.552* @qp_attr_mask: The QP attribute mask that may be used to transition the553* QP to the specified state.554*555* Users must set the @qp_attr->qp_state to the desired QP state. This call556* will set all required attributes for the given transition, along with557* known optional attributes. Users may override the attributes returned from558* this call before calling ib_modify_qp.559*/560int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,561struct ib_qp_attr *qp_attr,562int *qp_attr_mask);563564/**565* ib_send_cm_apr - Sends an alternate path response message in response to566* a load alternate path request.567* @cm_id: Connection identifier associated with the alternate path response.568* @status: Reply status sent with the alternate path response.569* @info: Optional additional information sent with the alternate path570* response.571* @info_length: Size of the additional information, in bytes.572* @private_data: Optional user-defined private data sent with the573* alternate path response message.574* @private_data_len: Size of the private data buffer, in bytes.575*/576int ib_send_cm_apr(struct ib_cm_id *cm_id,577enum ib_cm_apr_status status,578void *info,579u8 info_length,580const void *private_data,581u8 private_data_len);582583struct ib_cm_sidr_req_param {584struct ib_sa_path_rec *path;585__be64 service_id;586int timeout_ms;587const void *private_data;588u8 private_data_len;589u8 max_cm_retries;590};591592/**593* ib_send_cm_sidr_req - Sends a service ID resolution request to the594* remote node.595* @cm_id: Communication identifier that will be associated with the596* service ID resolution request.597* @param: Service ID resolution request information.598*/599int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,600struct ib_cm_sidr_req_param *param);601602struct ib_cm_sidr_rep_param {603u32 qp_num;604u32 qkey;605enum ib_cm_sidr_status status;606const void *info;607u8 info_length;608const void *private_data;609u8 private_data_len;610};611612/**613* ib_send_cm_sidr_rep - Sends a service ID resolution reply to the614* remote node.615* @cm_id: Communication identifier associated with the received service ID616* resolution request.617* @param: Service ID resolution reply information.618*/619int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,620struct ib_cm_sidr_rep_param *param);621622/**623* ibcm_reject_msg - return a pointer to a reject message string.624* @reason: Value returned in the REJECT event status field.625*/626const char *__attribute_const__ ibcm_reject_msg(int reason);627628#endif /* IB_CM_H */629630631