/*1* Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.2* Copyright (c) 2004 Topspin Corporation. All rights reserved.3* Copyright (c) 2004 Voltaire Corporation. All rights reserved.4* Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.5*6* This software is available to you under a choice of one of two7* licenses. You may choose to be licensed under the terms of the GNU8* General Public License (GPL) Version 2, available from the file9* COPYING in the main directory of this source tree, or the10* OpenIB.org BSD license below:11*12* Redistribution and use in source and binary forms, with or13* without modification, are permitted provided that the following14* conditions are met:15*16* - Redistributions of source code must retain the above17* copyright notice, this list of conditions and the following18* disclaimer.19*20* - Redistributions in binary form must reproduce the above21* copyright notice, this list of conditions and the following22* disclaimer in the documentation and/or other materials23* provided with the distribution.24*25* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,26* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF27* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND28* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS29* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN30* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN31* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE32* SOFTWARE.33*/34#if !defined(IB_CM_H)35#define IB_CM_H3637#include <rdma/ib_mad.h>38#include <rdma/ib_sa.h>3940enum ib_cm_state {41IB_CM_IDLE,42IB_CM_LISTEN,43IB_CM_REQ_SENT,44IB_CM_REQ_RCVD,45IB_CM_MRA_REQ_SENT,46IB_CM_MRA_REQ_RCVD,47IB_CM_REP_SENT,48IB_CM_REP_RCVD,49IB_CM_MRA_REP_SENT,50IB_CM_MRA_REP_RCVD,51IB_CM_ESTABLISHED,52IB_CM_DREQ_SENT,53IB_CM_DREQ_RCVD,54IB_CM_TIMEWAIT,55IB_CM_SIDR_REQ_SENT,56IB_CM_SIDR_REQ_RCVD57};5859enum ib_cm_lap_state {60IB_CM_LAP_UNINIT,61IB_CM_LAP_IDLE,62IB_CM_LAP_SENT,63IB_CM_LAP_RCVD,64IB_CM_MRA_LAP_SENT,65IB_CM_MRA_LAP_RCVD,66};6768enum ib_cm_event_type {69IB_CM_REQ_ERROR,70IB_CM_REQ_RECEIVED,71IB_CM_REP_ERROR,72IB_CM_REP_RECEIVED,73IB_CM_RTU_RECEIVED,74IB_CM_USER_ESTABLISHED,75IB_CM_DREQ_ERROR,76IB_CM_DREQ_RECEIVED,77IB_CM_DREP_RECEIVED,78IB_CM_TIMEWAIT_EXIT,79IB_CM_MRA_RECEIVED,80IB_CM_REJ_RECEIVED,81IB_CM_LAP_ERROR,82IB_CM_LAP_RECEIVED,83IB_CM_APR_RECEIVED,84IB_CM_SIDR_REQ_ERROR,85IB_CM_SIDR_REQ_RECEIVED,86IB_CM_SIDR_REP_RECEIVED87};8889enum ib_cm_data_size {90IB_CM_REQ_PRIVATE_DATA_SIZE = 92,91IB_CM_MRA_PRIVATE_DATA_SIZE = 222,92IB_CM_REJ_PRIVATE_DATA_SIZE = 148,93IB_CM_REP_PRIVATE_DATA_SIZE = 196,94IB_CM_RTU_PRIVATE_DATA_SIZE = 224,95IB_CM_DREQ_PRIVATE_DATA_SIZE = 220,96IB_CM_DREP_PRIVATE_DATA_SIZE = 224,97IB_CM_REJ_ARI_LENGTH = 72,98IB_CM_LAP_PRIVATE_DATA_SIZE = 168,99IB_CM_APR_PRIVATE_DATA_SIZE = 148,100IB_CM_APR_INFO_LENGTH = 72,101IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE = 216,102IB_CM_SIDR_REP_PRIVATE_DATA_SIZE = 136,103IB_CM_SIDR_REP_INFO_LENGTH = 72,104IB_CM_COMPARE_SIZE = 64105};106107struct ib_cm_id;108109struct ib_cm_req_event_param {110struct ib_cm_id *listen_id;111u8 port;112113struct ib_sa_path_rec *primary_path;114struct ib_sa_path_rec *alternate_path;115116__be64 remote_ca_guid;117u32 remote_qkey;118u32 remote_qpn;119enum ib_qp_type qp_type;120121u32 starting_psn;122u8 responder_resources;123u8 initiator_depth;124unsigned int local_cm_response_timeout:5;125unsigned int flow_control:1;126unsigned int remote_cm_response_timeout:5;127unsigned int retry_count:3;128unsigned int rnr_retry_count:3;129unsigned int srq:1;130};131132struct ib_cm_rep_event_param {133__be64 remote_ca_guid;134u32 remote_qkey;135u32 remote_qpn;136u32 starting_psn;137u8 responder_resources;138u8 initiator_depth;139unsigned int target_ack_delay:5;140unsigned int failover_accepted:2;141unsigned int flow_control:1;142unsigned int rnr_retry_count:3;143unsigned int srq:1;144};145146enum ib_cm_rej_reason {147IB_CM_REJ_NO_QP = 1,148IB_CM_REJ_NO_EEC = 2,149IB_CM_REJ_NO_RESOURCES = 3,150IB_CM_REJ_TIMEOUT = 4,151IB_CM_REJ_UNSUPPORTED = 5,152IB_CM_REJ_INVALID_COMM_ID = 6,153IB_CM_REJ_INVALID_COMM_INSTANCE = 7,154IB_CM_REJ_INVALID_SERVICE_ID = 8,155IB_CM_REJ_INVALID_TRANSPORT_TYPE = 9,156IB_CM_REJ_STALE_CONN = 10,157IB_CM_REJ_RDC_NOT_EXIST = 11,158IB_CM_REJ_INVALID_GID = 12,159IB_CM_REJ_INVALID_LID = 13,160IB_CM_REJ_INVALID_SL = 14,161IB_CM_REJ_INVALID_TRAFFIC_CLASS = 15,162IB_CM_REJ_INVALID_HOP_LIMIT = 16,163IB_CM_REJ_INVALID_PACKET_RATE = 17,164IB_CM_REJ_INVALID_ALT_GID = 18,165IB_CM_REJ_INVALID_ALT_LID = 19,166IB_CM_REJ_INVALID_ALT_SL = 20,167IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS = 21,168IB_CM_REJ_INVALID_ALT_HOP_LIMIT = 22,169IB_CM_REJ_INVALID_ALT_PACKET_RATE = 23,170IB_CM_REJ_PORT_CM_REDIRECT = 24,171IB_CM_REJ_PORT_REDIRECT = 25,172IB_CM_REJ_INVALID_MTU = 26,173IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES = 27,174IB_CM_REJ_CONSUMER_DEFINED = 28,175IB_CM_REJ_INVALID_RNR_RETRY = 29,176IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID = 30,177IB_CM_REJ_INVALID_CLASS_VERSION = 31,178IB_CM_REJ_INVALID_FLOW_LABEL = 32,179IB_CM_REJ_INVALID_ALT_FLOW_LABEL = 33180};181182struct ib_cm_rej_event_param {183enum ib_cm_rej_reason reason;184void *ari;185u8 ari_length;186};187188struct ib_cm_mra_event_param {189u8 service_timeout;190};191192struct ib_cm_lap_event_param {193struct ib_sa_path_rec *alternate_path;194};195196enum ib_cm_apr_status {197IB_CM_APR_SUCCESS,198IB_CM_APR_INVALID_COMM_ID,199IB_CM_APR_UNSUPPORTED,200IB_CM_APR_REJECT,201IB_CM_APR_REDIRECT,202IB_CM_APR_IS_CURRENT,203IB_CM_APR_INVALID_QPN_EECN,204IB_CM_APR_INVALID_LID,205IB_CM_APR_INVALID_GID,206IB_CM_APR_INVALID_FLOW_LABEL,207IB_CM_APR_INVALID_TCLASS,208IB_CM_APR_INVALID_HOP_LIMIT,209IB_CM_APR_INVALID_PACKET_RATE,210IB_CM_APR_INVALID_SL211};212213struct ib_cm_apr_event_param {214enum ib_cm_apr_status ap_status;215void *apr_info;216u8 info_len;217};218219struct ib_cm_sidr_req_event_param {220struct ib_cm_id *listen_id;221u8 port;222u16 pkey;223};224225enum ib_cm_sidr_status {226IB_SIDR_SUCCESS,227IB_SIDR_UNSUPPORTED,228IB_SIDR_REJECT,229IB_SIDR_NO_QP,230IB_SIDR_REDIRECT,231IB_SIDR_UNSUPPORTED_VERSION232};233234struct ib_cm_sidr_rep_event_param {235enum ib_cm_sidr_status status;236u32 qkey;237u32 qpn;238void *info;239u8 info_len;240};241242struct ib_cm_event {243enum ib_cm_event_type event;244union {245struct ib_cm_req_event_param req_rcvd;246struct ib_cm_rep_event_param rep_rcvd;247/* No data for RTU received events. */248struct ib_cm_rej_event_param rej_rcvd;249struct ib_cm_mra_event_param mra_rcvd;250struct ib_cm_lap_event_param lap_rcvd;251struct ib_cm_apr_event_param apr_rcvd;252/* No data for DREQ/DREP received events. */253struct ib_cm_sidr_req_event_param sidr_req_rcvd;254struct ib_cm_sidr_rep_event_param sidr_rep_rcvd;255enum ib_wc_status send_status;256} param;257258void *private_data;259};260261/**262* ib_cm_handler - User-defined callback to process communication events.263* @cm_id: Communication identifier associated with the reported event.264* @event: Information about the communication event.265*266* IB_CM_REQ_RECEIVED and IB_CM_SIDR_REQ_RECEIVED communication events267* generated as a result of listen requests result in the allocation of a268* new @cm_id. The new @cm_id is returned to the user through this callback.269* Clients are responsible for destroying the new @cm_id. For peer-to-peer270* IB_CM_REQ_RECEIVED and all other events, the returned @cm_id corresponds271* to a user's existing communication identifier.272*273* Users may not call ib_destroy_cm_id while in the context of this callback;274* however, returning a non-zero value instructs the communication manager to275* destroy the @cm_id after the callback completes.276*/277typedef int (*ib_cm_handler)(struct ib_cm_id *cm_id,278struct ib_cm_event *event);279280struct ib_cm_id {281ib_cm_handler cm_handler;282void *context;283struct ib_device *device;284__be64 service_id;285__be64 service_mask;286enum ib_cm_state state; /* internal CM/debug use */287enum ib_cm_lap_state lap_state; /* internal CM/debug use */288__be32 local_id;289__be32 remote_id;290u32 remote_cm_qpn; /* 1 unless redirected */291};292293/**294* ib_create_cm_id - Allocate a communication identifier.295* @device: Device associated with the cm_id. All related communication will296* be associated with the specified device.297* @cm_handler: Callback invoked to notify the user of CM events.298* @context: User specified context associated with the communication299* identifier.300*301* Communication identifiers are used to track connection states, service302* ID resolution requests, and listen requests.303*/304struct ib_cm_id *ib_create_cm_id(struct ib_device *device,305ib_cm_handler cm_handler,306void *context);307308/**309* ib_destroy_cm_id - Destroy a connection identifier.310* @cm_id: Connection identifier to destroy.311*312* This call blocks until the connection identifier is destroyed.313*/314void ib_destroy_cm_id(struct ib_cm_id *cm_id);315316#define IB_SERVICE_ID_AGN_MASK cpu_to_be64(0xFF00000000000000ULL)317#define IB_CM_ASSIGN_SERVICE_ID cpu_to_be64(0x0200000000000000ULL)318#define IB_CMA_SERVICE_ID cpu_to_be64(0x0000000001000000ULL)319#define IB_CMA_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFF000000ULL)320#define IB_SDP_SERVICE_ID cpu_to_be64(0x0000000000010000ULL)321#define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL)322323struct ib_cm_compare_data {324u8 data[IB_CM_COMPARE_SIZE];325u8 mask[IB_CM_COMPARE_SIZE];326};327328/**329* ib_cm_listen - Initiates listening on the specified service ID for330* connection and service ID resolution requests.331* @cm_id: Connection identifier associated with the listen request.332* @service_id: Service identifier matched against incoming connection333* and service ID resolution requests. The service ID should be specified334* network-byte order. If set to IB_CM_ASSIGN_SERVICE_ID, the CM will335* assign a service ID to the caller.336* @service_mask: Mask applied to service ID used to listen across a337* range of service IDs. If set to 0, the service ID is matched338* exactly. This parameter is ignored if %service_id is set to339* IB_CM_ASSIGN_SERVICE_ID.340* @compare_data: This parameter is optional. It specifies data that must341* appear in the private data of a connection request for the specified342* listen request.343*/344int ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id, __be64 service_mask,345struct ib_cm_compare_data *compare_data);346347struct ib_cm_req_param {348struct ib_sa_path_rec *primary_path;349struct ib_sa_path_rec *alternate_path;350__be64 service_id;351u32 qp_num;352enum ib_qp_type qp_type;353u32 starting_psn;354const void *private_data;355u8 private_data_len;356u8 peer_to_peer;357u8 responder_resources;358u8 initiator_depth;359u8 remote_cm_response_timeout;360u8 flow_control;361u8 local_cm_response_timeout;362u8 retry_count;363u8 rnr_retry_count;364u8 max_cm_retries;365u8 srq;366};367368/**369* ib_send_cm_req - Sends a connection request to the remote node.370* @cm_id: Connection identifier that will be associated with the371* connection request.372* @param: Connection request information needed to establish the373* connection.374*/375int ib_send_cm_req(struct ib_cm_id *cm_id,376struct ib_cm_req_param *param);377378struct ib_cm_rep_param {379u32 qp_num;380u32 starting_psn;381const void *private_data;382u8 private_data_len;383u8 responder_resources;384u8 initiator_depth;385u8 failover_accepted;386u8 flow_control;387u8 rnr_retry_count;388u8 srq;389};390391/**392* ib_send_cm_rep - Sends a connection reply in response to a connection393* request.394* @cm_id: Connection identifier that will be associated with the395* connection request.396* @param: Connection reply information needed to establish the397* connection.398*/399int ib_send_cm_rep(struct ib_cm_id *cm_id,400struct ib_cm_rep_param *param);401402/**403* ib_send_cm_rtu - Sends a connection ready to use message in response404* to a connection reply message.405* @cm_id: Connection identifier associated with the connection request.406* @private_data: Optional user-defined private data sent with the407* ready to use message.408* @private_data_len: Size of the private data buffer, in bytes.409*/410int ib_send_cm_rtu(struct ib_cm_id *cm_id,411const void *private_data,412u8 private_data_len);413414/**415* ib_send_cm_dreq - Sends a disconnection request for an existing416* connection.417* @cm_id: Connection identifier associated with the connection being418* released.419* @private_data: Optional user-defined private data sent with the420* disconnection request message.421* @private_data_len: Size of the private data buffer, in bytes.422*/423int ib_send_cm_dreq(struct ib_cm_id *cm_id,424const void *private_data,425u8 private_data_len);426427/**428* ib_send_cm_drep - Sends a disconnection reply to a disconnection request.429* @cm_id: Connection identifier associated with the connection being430* released.431* @private_data: Optional user-defined private data sent with the432* disconnection reply message.433* @private_data_len: Size of the private data buffer, in bytes.434*435* If the cm_id is in the correct state, the CM will transition the connection436* to the timewait state, even if an error occurs sending the DREP message.437*/438int ib_send_cm_drep(struct ib_cm_id *cm_id,439const void *private_data,440u8 private_data_len);441442/**443* ib_cm_notify - Notifies the CM of an event reported to the consumer.444* @cm_id: Connection identifier to transition to established.445* @event: Type of event.446*447* This routine should be invoked by users to notify the CM of relevant448* communication events. Events that should be reported to the CM and449* when to report them are:450*451* IB_EVENT_COMM_EST - Used when a message is received on a connected452* QP before an RTU has been received.453* IB_EVENT_PATH_MIG - Notifies the CM that the connection has failed over454* to the alternate path.455*/456int ib_cm_notify(struct ib_cm_id *cm_id, enum ib_event_type event);457458/**459* ib_send_cm_rej - Sends a connection rejection message to the460* remote node.461* @cm_id: Connection identifier associated with the connection being462* rejected.463* @reason: Reason for the connection request rejection.464* @ari: Optional additional rejection information.465* @ari_length: Size of the additional rejection information, in bytes.466* @private_data: Optional user-defined private data sent with the467* rejection message.468* @private_data_len: Size of the private data buffer, in bytes.469*/470int ib_send_cm_rej(struct ib_cm_id *cm_id,471enum ib_cm_rej_reason reason,472void *ari,473u8 ari_length,474const void *private_data,475u8 private_data_len);476477#define IB_CM_MRA_FLAG_DELAY 0x80 /* Send MRA only after a duplicate msg */478479/**480* ib_send_cm_mra - Sends a message receipt acknowledgement to a connection481* message.482* @cm_id: Connection identifier associated with the connection message.483* @service_timeout: The lower 5-bits specify the maximum time required for484* the sender to reply to the connection message. The upper 3-bits485* specify additional control flags.486* @private_data: Optional user-defined private data sent with the487* message receipt acknowledgement.488* @private_data_len: Size of the private data buffer, in bytes.489*/490int ib_send_cm_mra(struct ib_cm_id *cm_id,491u8 service_timeout,492const void *private_data,493u8 private_data_len);494495/**496* ib_send_cm_lap - Sends a load alternate path request.497* @cm_id: Connection identifier associated with the load alternate path498* message.499* @alternate_path: A path record that identifies the alternate path to500* load.501* @private_data: Optional user-defined private data sent with the502* load alternate path message.503* @private_data_len: Size of the private data buffer, in bytes.504*/505int ib_send_cm_lap(struct ib_cm_id *cm_id,506struct ib_sa_path_rec *alternate_path,507const void *private_data,508u8 private_data_len);509510/**511* ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning512* to a specified QP state.513* @cm_id: Communication identifier associated with the QP attributes to514* initialize.515* @qp_attr: On input, specifies the desired QP state. On output, the516* mandatory and desired optional attributes will be set in order to517* modify the QP to the specified state.518* @qp_attr_mask: The QP attribute mask that may be used to transition the519* QP to the specified state.520*521* Users must set the @qp_attr->qp_state to the desired QP state. This call522* will set all required attributes for the given transition, along with523* known optional attributes. Users may override the attributes returned from524* this call before calling ib_modify_qp.525*/526int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,527struct ib_qp_attr *qp_attr,528int *qp_attr_mask);529530/**531* ib_send_cm_apr - Sends an alternate path response message in response to532* a load alternate path request.533* @cm_id: Connection identifier associated with the alternate path response.534* @status: Reply status sent with the alternate path response.535* @info: Optional additional information sent with the alternate path536* response.537* @info_length: Size of the additional information, in bytes.538* @private_data: Optional user-defined private data sent with the539* alternate path response message.540* @private_data_len: Size of the private data buffer, in bytes.541*/542int ib_send_cm_apr(struct ib_cm_id *cm_id,543enum ib_cm_apr_status status,544void *info,545u8 info_length,546const void *private_data,547u8 private_data_len);548549struct ib_cm_sidr_req_param {550struct ib_sa_path_rec *path;551__be64 service_id;552int timeout_ms;553const void *private_data;554u8 private_data_len;555u8 max_cm_retries;556};557558/**559* ib_send_cm_sidr_req - Sends a service ID resolution request to the560* remote node.561* @cm_id: Communication identifier that will be associated with the562* service ID resolution request.563* @param: Service ID resolution request information.564*/565int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,566struct ib_cm_sidr_req_param *param);567568struct ib_cm_sidr_rep_param {569u32 qp_num;570u32 qkey;571enum ib_cm_sidr_status status;572const void *info;573u8 info_length;574const void *private_data;575u8 private_data_len;576};577578/**579* ib_send_cm_sidr_rep - Sends a service ID resolution reply to the580* remote node.581* @cm_id: Communication identifier associated with the received service ID582* resolution request.583* @param: Service ID resolution reply information.584*/585int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,586struct ib_cm_sidr_rep_param *param);587588#endif /* IB_CM_H */589590591