/*1* Copyright (c) 2005 Voltaire Inc. All rights reserved.2* Copyright (c) 2005 Intel Corporation. All rights reserved.3*4* This software is available to you under a choice of one of two5* licenses. You may choose to be licensed under the terms of the GNU6* General Public License (GPL) Version 2, available from the file7* COPYING in the main directory of this source tree, or the8* OpenIB.org BSD license below:9*10* Redistribution and use in source and binary forms, with or11* without modification, are permitted provided that the following12* conditions are met:13*14* - Redistributions of source code must retain the above15* copyright notice, this list of conditions and the following16* disclaimer.17*18* - Redistributions in binary form must reproduce the above19* copyright notice, this list of conditions and the following20* disclaimer in the documentation and/or other materials21* provided with the distribution.22*23* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,24* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF25* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND26* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS27* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN28* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN29* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE30* SOFTWARE.31*/3233#if !defined(RDMA_CM_H)34#define RDMA_CM_H3536#include <linux/socket.h>37#include <linux/in6.h>38#include <rdma/ib_addr.h>39#include <rdma/ib_sa.h>4041/*42* Upon receiving a device removal event, users must destroy the associated43* RDMA identifier and release all resources allocated with the device.44*/45enum rdma_cm_event_type {46RDMA_CM_EVENT_ADDR_RESOLVED,47RDMA_CM_EVENT_ADDR_ERROR,48RDMA_CM_EVENT_ROUTE_RESOLVED,49RDMA_CM_EVENT_ROUTE_ERROR,50RDMA_CM_EVENT_CONNECT_REQUEST,51RDMA_CM_EVENT_CONNECT_RESPONSE,52RDMA_CM_EVENT_CONNECT_ERROR,53RDMA_CM_EVENT_UNREACHABLE,54RDMA_CM_EVENT_REJECTED,55RDMA_CM_EVENT_ESTABLISHED,56RDMA_CM_EVENT_DISCONNECTED,57RDMA_CM_EVENT_DEVICE_REMOVAL,58RDMA_CM_EVENT_MULTICAST_JOIN,59RDMA_CM_EVENT_MULTICAST_ERROR,60RDMA_CM_EVENT_ADDR_CHANGE,61RDMA_CM_EVENT_TIMEWAIT_EXIT62};6364enum rdma_port_space {65RDMA_PS_SDP = 0x0001,66RDMA_PS_IPOIB = 0x0002,67RDMA_PS_TCP = 0x0106,68RDMA_PS_UDP = 0x0111,69};7071struct rdma_addr {72struct sockaddr_storage src_addr;73struct sockaddr_storage dst_addr;74struct rdma_dev_addr dev_addr;75};7677struct rdma_route {78struct rdma_addr addr;79struct ib_sa_path_rec *path_rec;80int num_paths;81};8283struct rdma_conn_param {84const void *private_data;85u8 private_data_len;86u8 responder_resources;87u8 initiator_depth;88u8 flow_control;89u8 retry_count; /* ignored when accepting */90u8 rnr_retry_count;91/* Fields below ignored if a QP is created on the rdma_cm_id. */92u8 srq;93u32 qp_num;94};9596struct rdma_ud_param {97const void *private_data;98u8 private_data_len;99struct ib_ah_attr ah_attr;100u32 qp_num;101u32 qkey;102};103104struct rdma_cm_event {105enum rdma_cm_event_type event;106int status;107union {108struct rdma_conn_param conn;109struct rdma_ud_param ud;110} param;111};112113enum rdma_cm_state {114RDMA_CM_IDLE,115RDMA_CM_ADDR_QUERY,116RDMA_CM_ADDR_RESOLVED,117RDMA_CM_ROUTE_QUERY,118RDMA_CM_ROUTE_RESOLVED,119RDMA_CM_CONNECT,120RDMA_CM_DISCONNECT,121RDMA_CM_ADDR_BOUND,122RDMA_CM_LISTEN,123RDMA_CM_DEVICE_REMOVAL,124RDMA_CM_DESTROYING125};126127struct rdma_cm_id;128129/**130* rdma_cm_event_handler - Callback used to report user events.131*132* Notes: Users may not call rdma_destroy_id from this callback to destroy133* the passed in id, or a corresponding listen id. Returning a134* non-zero value from the callback will destroy the passed in id.135*/136typedef int (*rdma_cm_event_handler)(struct rdma_cm_id *id,137struct rdma_cm_event *event);138139struct rdma_cm_id {140struct ib_device *device;141void *context;142struct ib_qp *qp;143rdma_cm_event_handler event_handler;144struct rdma_route route;145enum rdma_port_space ps;146enum ib_qp_type qp_type;147u8 port_num;148};149150/**151* rdma_create_id - Create an RDMA identifier.152*153* @event_handler: User callback invoked to report events associated with the154* returned rdma_id.155* @context: User specified context associated with the id.156* @ps: RDMA port space.157* @qp_type: type of queue pair associated with the id.158*/159struct rdma_cm_id *rdma_create_id(rdma_cm_event_handler event_handler,160void *context, enum rdma_port_space ps,161enum ib_qp_type qp_type);162163/**164* rdma_destroy_id - Destroys an RDMA identifier.165*166* @id: RDMA identifier.167*168* Note: calling this function has the effect of canceling in-flight169* asynchronous operations associated with the id.170*/171void rdma_destroy_id(struct rdma_cm_id *id);172173/**174* rdma_bind_addr - Bind an RDMA identifier to a source address and175* associated RDMA device, if needed.176*177* @id: RDMA identifier.178* @addr: Local address information. Wildcard values are permitted.179*180* This associates a source address with the RDMA identifier before calling181* rdma_listen. If a specific local address is given, the RDMA identifier will182* be bound to a local RDMA device.183*/184int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr);185186/**187* rdma_resolve_addr - Resolve destination and optional source addresses188* from IP addresses to an RDMA address. If successful, the specified189* rdma_cm_id will be bound to a local device.190*191* @id: RDMA identifier.192* @src_addr: Source address information. This parameter may be NULL.193* @dst_addr: Destination address information.194* @timeout_ms: Time to wait for resolution to complete.195*/196int rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr,197struct sockaddr *dst_addr, int timeout_ms);198199/**200* rdma_resolve_route - Resolve the RDMA address bound to the RDMA identifier201* into route information needed to establish a connection.202*203* This is called on the client side of a connection.204* Users must have first called rdma_resolve_addr to resolve a dst_addr205* into an RDMA address before calling this routine.206*/207int rdma_resolve_route(struct rdma_cm_id *id, int timeout_ms);208209/**210* rdma_create_qp - Allocate a QP and associate it with the specified RDMA211* identifier.212*213* QPs allocated to an rdma_cm_id will automatically be transitioned by the CMA214* through their states.215*/216int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd,217struct ib_qp_init_attr *qp_init_attr);218219/**220* rdma_destroy_qp - Deallocate the QP associated with the specified RDMA221* identifier.222*223* Users must destroy any QP associated with an RDMA identifier before224* destroying the RDMA ID.225*/226void rdma_destroy_qp(struct rdma_cm_id *id);227228/**229* rdma_init_qp_attr - Initializes the QP attributes for use in transitioning230* to a specified QP state.231* @id: Communication identifier associated with the QP attributes to232* initialize.233* @qp_attr: On input, specifies the desired QP state. On output, the234* mandatory and desired optional attributes will be set in order to235* modify the QP to the specified state.236* @qp_attr_mask: The QP attribute mask that may be used to transition the237* QP to the specified state.238*239* Users must set the @qp_attr->qp_state to the desired QP state. This call240* will set all required attributes for the given transition, along with241* known optional attributes. Users may override the attributes returned from242* this call before calling ib_modify_qp.243*244* Users that wish to have their QP automatically transitioned through its245* states can associate a QP with the rdma_cm_id by calling rdma_create_qp().246*/247int rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr,248int *qp_attr_mask);249250/**251* rdma_connect - Initiate an active connection request.252* @id: Connection identifier to connect.253* @conn_param: Connection information used for connected QPs.254*255* Users must have resolved a route for the rdma_cm_id to connect with256* by having called rdma_resolve_route before calling this routine.257*258* This call will either connect to a remote QP or obtain remote QP259* information for unconnected rdma_cm_id's. The actual operation is260* based on the rdma_cm_id's port space.261*/262int rdma_connect(struct rdma_cm_id *id, struct rdma_conn_param *conn_param);263264/**265* rdma_listen - This function is called by the passive side to266* listen for incoming connection requests.267*268* Users must have bound the rdma_cm_id to a local address by calling269* rdma_bind_addr before calling this routine.270*/271int rdma_listen(struct rdma_cm_id *id, int backlog);272273/**274* rdma_accept - Called to accept a connection request or response.275* @id: Connection identifier associated with the request.276* @conn_param: Information needed to establish the connection. This must be277* provided if accepting a connection request. If accepting a connection278* response, this parameter must be NULL.279*280* Typically, this routine is only called by the listener to accept a connection281* request. It must also be called on the active side of a connection if the282* user is performing their own QP transitions.283*284* In the case of error, a reject message is sent to the remote side and the285* state of the qp associated with the id is modified to error, such that any286* previously posted receive buffers would be flushed.287*/288int rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param);289290/**291* rdma_notify - Notifies the RDMA CM of an asynchronous event that has292* occurred on the connection.293* @id: Connection identifier to transition to established.294* @event: Asynchronous event.295*296* This routine should be invoked by users to notify the CM of relevant297* communication events. Events that should be reported to the CM and298* when to report them are:299*300* IB_EVENT_COMM_EST - Used when a message is received on a connected301* QP before an RTU has been received.302*/303int rdma_notify(struct rdma_cm_id *id, enum ib_event_type event);304305/**306* rdma_reject - Called to reject a connection request or response.307*/308int rdma_reject(struct rdma_cm_id *id, const void *private_data,309u8 private_data_len);310311/**312* rdma_disconnect - This function disconnects the associated QP and313* transitions it into the error state.314*/315int rdma_disconnect(struct rdma_cm_id *id);316317/**318* rdma_join_multicast - Join the multicast group specified by the given319* address.320* @id: Communication identifier associated with the request.321* @addr: Multicast address identifying the group to join.322* @context: User-defined context associated with the join request, returned323* to the user through the private_data pointer in multicast events.324*/325int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,326void *context);327328/**329* rdma_leave_multicast - Leave the multicast group specified by the given330* address.331*/332void rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr);333334/**335* rdma_set_service_type - Set the type of service associated with a336* connection identifier.337* @id: Communication identifier to associated with service type.338* @tos: Type of service.339*340* The type of service is interpretted as a differentiated service341* field (RFC 2474). The service type should be specified before342* performing route resolution, as existing communication on the343* connection identifier may be unaffected. The type of service344* requested may not be supported by the network to all destinations.345*/346void rdma_set_service_type(struct rdma_cm_id *id, int tos);347348/**349* rdma_set_reuseaddr - Allow the reuse of local addresses when binding350* the rdma_cm_id.351* @id: Communication identifier to configure.352* @reuse: Value indicating if the bound address is reusable.353*354* Reuse must be set before an address is bound to the id.355*/356int rdma_set_reuseaddr(struct rdma_cm_id *id, int reuse);357358#endif /* RDMA_CM_H */359360361