1e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/*
2e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * Copyright (c) 2005 Voltaire Inc.  All rights reserved.
3e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * Copyright (c) 2005 Intel Corporation.  All rights reserved.
4e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *
5a9474917099e007c0f51d5474394b5890111614fSean Hefty * This software is available to you under a choice of one of two
6a9474917099e007c0f51d5474394b5890111614fSean Hefty * licenses.  You may choose to be licensed under the terms of the GNU
7a9474917099e007c0f51d5474394b5890111614fSean Hefty * General Public License (GPL) Version 2, available from the file
8a9474917099e007c0f51d5474394b5890111614fSean Hefty * COPYING in the main directory of this source tree, or the
9a9474917099e007c0f51d5474394b5890111614fSean Hefty * OpenIB.org BSD license below:
10a9474917099e007c0f51d5474394b5890111614fSean Hefty *
11a9474917099e007c0f51d5474394b5890111614fSean Hefty *     Redistribution and use in source and binary forms, with or
12a9474917099e007c0f51d5474394b5890111614fSean Hefty *     without modification, are permitted provided that the following
13a9474917099e007c0f51d5474394b5890111614fSean Hefty *     conditions are met:
14a9474917099e007c0f51d5474394b5890111614fSean Hefty *
15a9474917099e007c0f51d5474394b5890111614fSean Hefty *      - Redistributions of source code must retain the above
16a9474917099e007c0f51d5474394b5890111614fSean Hefty *        copyright notice, this list of conditions and the following
17a9474917099e007c0f51d5474394b5890111614fSean Hefty *        disclaimer.
18a9474917099e007c0f51d5474394b5890111614fSean Hefty *
19a9474917099e007c0f51d5474394b5890111614fSean Hefty *      - Redistributions in binary form must reproduce the above
20a9474917099e007c0f51d5474394b5890111614fSean Hefty *        copyright notice, this list of conditions and the following
21a9474917099e007c0f51d5474394b5890111614fSean Hefty *        disclaimer in the documentation and/or other materials
22a9474917099e007c0f51d5474394b5890111614fSean Hefty *        provided with the distribution.
23a9474917099e007c0f51d5474394b5890111614fSean Hefty *
24a9474917099e007c0f51d5474394b5890111614fSean Hefty * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25a9474917099e007c0f51d5474394b5890111614fSean Hefty * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26a9474917099e007c0f51d5474394b5890111614fSean Hefty * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27a9474917099e007c0f51d5474394b5890111614fSean Hefty * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28a9474917099e007c0f51d5474394b5890111614fSean Hefty * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29a9474917099e007c0f51d5474394b5890111614fSean Hefty * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30a9474917099e007c0f51d5474394b5890111614fSean Hefty * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31a9474917099e007c0f51d5474394b5890111614fSean Hefty * SOFTWARE.
32e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
33e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
34e51060f08a61965c4dd91516d82fe90617152590Sean Hefty#if !defined(RDMA_CM_H)
35e51060f08a61965c4dd91516d82fe90617152590Sean Hefty#define RDMA_CM_H
36e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
37e51060f08a61965c4dd91516d82fe90617152590Sean Hefty#include <linux/socket.h>
38e51060f08a61965c4dd91516d82fe90617152590Sean Hefty#include <linux/in6.h>
39e51060f08a61965c4dd91516d82fe90617152590Sean Hefty#include <rdma/ib_addr.h>
40e51060f08a61965c4dd91516d82fe90617152590Sean Hefty#include <rdma/ib_sa.h>
41e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
42e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/*
43e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * Upon receiving a device removal event, users must destroy the associated
44e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * RDMA identifier and release all resources allocated with the device.
45e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
46e51060f08a61965c4dd91516d82fe90617152590Sean Heftyenum rdma_cm_event_type {
47e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	RDMA_CM_EVENT_ADDR_RESOLVED,
48e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	RDMA_CM_EVENT_ADDR_ERROR,
49e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	RDMA_CM_EVENT_ROUTE_RESOLVED,
50e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	RDMA_CM_EVENT_ROUTE_ERROR,
51e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	RDMA_CM_EVENT_CONNECT_REQUEST,
52e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	RDMA_CM_EVENT_CONNECT_RESPONSE,
53e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	RDMA_CM_EVENT_CONNECT_ERROR,
54e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	RDMA_CM_EVENT_UNREACHABLE,
55e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	RDMA_CM_EVENT_REJECTED,
56e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	RDMA_CM_EVENT_ESTABLISHED,
57e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	RDMA_CM_EVENT_DISCONNECTED,
58e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	RDMA_CM_EVENT_DEVICE_REMOVAL,
59c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty	RDMA_CM_EVENT_MULTICAST_JOIN,
60dd5bdff83b19d9174126e0398b47117c3a80e22dOr Gerlitz	RDMA_CM_EVENT_MULTICAST_ERROR,
6138ca83a588662f0af684ba2567dd910a564268abAmir Vadai	RDMA_CM_EVENT_ADDR_CHANGE,
6238ca83a588662f0af684ba2567dd910a564268abAmir Vadai	RDMA_CM_EVENT_TIMEWAIT_EXIT
63e51060f08a61965c4dd91516d82fe90617152590Sean Hefty};
64e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
65e51060f08a61965c4dd91516d82fe90617152590Sean Heftyenum rdma_port_space {
664deccd6d95f1f1536dad3c842e39c1ace577329dDotan Barak	RDMA_PS_SDP   = 0x0001,
674deccd6d95f1f1536dad3c842e39c1ace577329dDotan Barak	RDMA_PS_IPOIB = 0x0002,
682d2e94152928209de13dea0535242c0e457bdcbbSean Hefty	RDMA_PS_IB    = 0x013F,
694deccd6d95f1f1536dad3c842e39c1ace577329dDotan Barak	RDMA_PS_TCP   = 0x0106,
704deccd6d95f1f1536dad3c842e39c1ace577329dDotan Barak	RDMA_PS_UDP   = 0x0111,
71e51060f08a61965c4dd91516d82fe90617152590Sean Hefty};
72e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
7358afdcb7382234ebd780e43b17edde92a5853ccaSean Hefty#define RDMA_IB_IP_PS_MASK   0xFFFFFFFFFFFF0000ULL
7458afdcb7382234ebd780e43b17edde92a5853ccaSean Hefty#define RDMA_IB_IP_PS_TCP    0x0000000001060000ULL
7558afdcb7382234ebd780e43b17edde92a5853ccaSean Hefty#define RDMA_IB_IP_PS_UDP    0x0000000001110000ULL
7658afdcb7382234ebd780e43b17edde92a5853ccaSean Hefty#define RDMA_IB_IP_PS_IB     0x00000000013F0000ULL
7758afdcb7382234ebd780e43b17edde92a5853ccaSean Hefty
78e51060f08a61965c4dd91516d82fe90617152590Sean Heftystruct rdma_addr {
793f44675439b136d51179d31eb5a498383cb38624Roland Dreier	struct sockaddr_storage src_addr;
803f44675439b136d51179d31eb5a498383cb38624Roland Dreier	struct sockaddr_storage dst_addr;
81e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	struct rdma_dev_addr dev_addr;
82e51060f08a61965c4dd91516d82fe90617152590Sean Hefty};
83e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
84e51060f08a61965c4dd91516d82fe90617152590Sean Heftystruct rdma_route {
85e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	struct rdma_addr addr;
86e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	struct ib_sa_path_rec *path_rec;
87e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	int num_paths;
88e51060f08a61965c4dd91516d82fe90617152590Sean Hefty};
89e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
90a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Heftystruct rdma_conn_param {
91a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty	const void *private_data;
92a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty	u8 private_data_len;
93a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty	u8 responder_resources;
94a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty	u8 initiator_depth;
95a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty	u8 flow_control;
96a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty	u8 retry_count;		/* ignored when accepting */
97a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty	u8 rnr_retry_count;
98a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty	/* Fields below ignored if a QP is created on the rdma_cm_id. */
99a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty	u8 srq;
100a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty	u32 qp_num;
1015c438135adf90b33cb00e5351becf1e557bbdd9dSean Hefty	u32 qkey;
102a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty};
103a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty
104628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Heftystruct rdma_ud_param {
105628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Hefty	const void *private_data;
106628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Hefty	u8 private_data_len;
107628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Hefty	struct ib_ah_attr ah_attr;
108628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Hefty	u32 qp_num;
109628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Hefty	u32 qkey;
110628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Hefty};
111628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Hefty
112e51060f08a61965c4dd91516d82fe90617152590Sean Heftystruct rdma_cm_event {
113e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	enum rdma_cm_event_type	 event;
114e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	int			 status;
115a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty	union {
116a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty		struct rdma_conn_param	conn;
117628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Hefty		struct rdma_ud_param	ud;
118a1b1b61f80aba49f1e0f32b0e4b1c35be91c57faSean Hefty	} param;
119e51060f08a61965c4dd91516d82fe90617152590Sean Hefty};
120e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
121550e5ca77e96989c5e19f60e017205b2bcc615a5Nir Muchtarenum rdma_cm_state {
122550e5ca77e96989c5e19f60e017205b2bcc615a5Nir Muchtar	RDMA_CM_IDLE,
123550e5ca77e96989c5e19f60e017205b2bcc615a5Nir Muchtar	RDMA_CM_ADDR_QUERY,
124550e5ca77e96989c5e19f60e017205b2bcc615a5Nir Muchtar	RDMA_CM_ADDR_RESOLVED,
125550e5ca77e96989c5e19f60e017205b2bcc615a5Nir Muchtar	RDMA_CM_ROUTE_QUERY,
126550e5ca77e96989c5e19f60e017205b2bcc615a5Nir Muchtar	RDMA_CM_ROUTE_RESOLVED,
127550e5ca77e96989c5e19f60e017205b2bcc615a5Nir Muchtar	RDMA_CM_CONNECT,
128550e5ca77e96989c5e19f60e017205b2bcc615a5Nir Muchtar	RDMA_CM_DISCONNECT,
129550e5ca77e96989c5e19f60e017205b2bcc615a5Nir Muchtar	RDMA_CM_ADDR_BOUND,
130550e5ca77e96989c5e19f60e017205b2bcc615a5Nir Muchtar	RDMA_CM_LISTEN,
131550e5ca77e96989c5e19f60e017205b2bcc615a5Nir Muchtar	RDMA_CM_DEVICE_REMOVAL,
132550e5ca77e96989c5e19f60e017205b2bcc615a5Nir Muchtar	RDMA_CM_DESTROYING
133550e5ca77e96989c5e19f60e017205b2bcc615a5Nir Muchtar};
134550e5ca77e96989c5e19f60e017205b2bcc615a5Nir Muchtar
135e51060f08a61965c4dd91516d82fe90617152590Sean Heftystruct rdma_cm_id;
136e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
137e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/**
138e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_cm_event_handler - Callback used to report user events.
139e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *
140e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * Notes: Users may not call rdma_destroy_id from this callback to destroy
141e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   the passed in id, or a corresponding listen id.  Returning a
142e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   non-zero value from the callback will destroy the passed in id.
143e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
144e51060f08a61965c4dd91516d82fe90617152590Sean Heftytypedef int (*rdma_cm_event_handler)(struct rdma_cm_id *id,
145e51060f08a61965c4dd91516d82fe90617152590Sean Hefty				     struct rdma_cm_event *event);
146e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
147e51060f08a61965c4dd91516d82fe90617152590Sean Heftystruct rdma_cm_id {
148e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	struct ib_device	*device;
149e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	void			*context;
150e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	struct ib_qp		*qp;
151e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	rdma_cm_event_handler	 event_handler;
152e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	struct rdma_route	 route;
153e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	enum rdma_port_space	 ps;
154b26f9b9949013fec31b23c426fc463164ae08891Sean Hefty	enum ib_qp_type		 qp_type;
155e51060f08a61965c4dd91516d82fe90617152590Sean Hefty	u8			 port_num;
156e51060f08a61965c4dd91516d82fe90617152590Sean Hefty};
157e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
158e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/**
159e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_create_id - Create an RDMA identifier.
160e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *
161e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * @event_handler: User callback invoked to report events associated with the
162e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   returned rdma_id.
163e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * @context: User specified context associated with the id.
164e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * @ps: RDMA port space.
165b26f9b9949013fec31b23c426fc463164ae08891Sean Hefty * @qp_type: type of queue pair associated with the id.
166e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
167e51060f08a61965c4dd91516d82fe90617152590Sean Heftystruct rdma_cm_id *rdma_create_id(rdma_cm_event_handler event_handler,
168b26f9b9949013fec31b23c426fc463164ae08891Sean Hefty				  void *context, enum rdma_port_space ps,
169b26f9b9949013fec31b23c426fc463164ae08891Sean Hefty				  enum ib_qp_type qp_type);
170e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
17107eeec0627e93a1a753c4df004a97a4d0a7b9cebOr Gerlitz/**
17207eeec0627e93a1a753c4df004a97a4d0a7b9cebOr Gerlitz  * rdma_destroy_id - Destroys an RDMA identifier.
17307eeec0627e93a1a753c4df004a97a4d0a7b9cebOr Gerlitz  *
17407eeec0627e93a1a753c4df004a97a4d0a7b9cebOr Gerlitz  * @id: RDMA identifier.
17507eeec0627e93a1a753c4df004a97a4d0a7b9cebOr Gerlitz  *
17607eeec0627e93a1a753c4df004a97a4d0a7b9cebOr Gerlitz  * Note: calling this function has the effect of canceling in-flight
17707eeec0627e93a1a753c4df004a97a4d0a7b9cebOr Gerlitz  * asynchronous operations associated with the id.
17807eeec0627e93a1a753c4df004a97a4d0a7b9cebOr Gerlitz  */
179e51060f08a61965c4dd91516d82fe90617152590Sean Heftyvoid rdma_destroy_id(struct rdma_cm_id *id);
180e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
181e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/**
182e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_bind_addr - Bind an RDMA identifier to a source address and
183e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   associated RDMA device, if needed.
184e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *
185e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * @id: RDMA identifier.
186e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * @addr: Local address information.  Wildcard values are permitted.
187e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *
188e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * This associates a source address with the RDMA identifier before calling
189e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_listen.  If a specific local address is given, the RDMA identifier will
190e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * be bound to a local RDMA device.
191e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
192e51060f08a61965c4dd91516d82fe90617152590Sean Heftyint rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr);
193e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
194e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/**
195e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_resolve_addr - Resolve destination and optional source addresses
196e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   from IP addresses to an RDMA address.  If successful, the specified
197e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   rdma_cm_id will be bound to a local device.
198e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *
199e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * @id: RDMA identifier.
200e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * @src_addr: Source address information.  This parameter may be NULL.
201e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * @dst_addr: Destination address information.
202e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * @timeout_ms: Time to wait for resolution to complete.
203e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
204e51060f08a61965c4dd91516d82fe90617152590Sean Heftyint rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr,
205e51060f08a61965c4dd91516d82fe90617152590Sean Hefty		      struct sockaddr *dst_addr, int timeout_ms);
206e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
207e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/**
208e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_resolve_route - Resolve the RDMA address bound to the RDMA identifier
209e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   into route information needed to establish a connection.
210e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *
211e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * This is called on the client side of a connection.
212e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * Users must have first called rdma_resolve_addr to resolve a dst_addr
213e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * into an RDMA address before calling this routine.
214e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
215e51060f08a61965c4dd91516d82fe90617152590Sean Heftyint rdma_resolve_route(struct rdma_cm_id *id, int timeout_ms);
216e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
217e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/**
218e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_create_qp - Allocate a QP and associate it with the specified RDMA
219e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * identifier.
220e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *
221e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * QPs allocated to an rdma_cm_id will automatically be transitioned by the CMA
222e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * through their states.
223e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
224e51060f08a61965c4dd91516d82fe90617152590Sean Heftyint rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd,
225e51060f08a61965c4dd91516d82fe90617152590Sean Hefty		   struct ib_qp_init_attr *qp_init_attr);
226e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
227e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/**
228e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_destroy_qp - Deallocate the QP associated with the specified RDMA
229e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * identifier.
230e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *
231e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * Users must destroy any QP associated with an RDMA identifier before
232e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * destroying the RDMA ID.
233e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
234e51060f08a61965c4dd91516d82fe90617152590Sean Heftyvoid rdma_destroy_qp(struct rdma_cm_id *id);
235e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
236e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/**
237e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_init_qp_attr - Initializes the QP attributes for use in transitioning
238e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   to a specified QP state.
239e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * @id: Communication identifier associated with the QP attributes to
240e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   initialize.
241e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * @qp_attr: On input, specifies the desired QP state.  On output, the
242e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   mandatory and desired optional attributes will be set in order to
243e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   modify the QP to the specified state.
244e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * @qp_attr_mask: The QP attribute mask that may be used to transition the
245e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   QP to the specified state.
246e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *
247e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * Users must set the @qp_attr->qp_state to the desired QP state.  This call
248e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * will set all required attributes for the given transition, along with
249e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * known optional attributes.  Users may override the attributes returned from
250e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * this call before calling ib_modify_qp.
251e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *
252e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * Users that wish to have their QP automatically transitioned through its
253e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * states can associate a QP with the rdma_cm_id by calling rdma_create_qp().
254e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
255e51060f08a61965c4dd91516d82fe90617152590Sean Heftyint rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr,
256e51060f08a61965c4dd91516d82fe90617152590Sean Hefty		       int *qp_attr_mask);
257e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
258e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/**
259e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_connect - Initiate an active connection request.
260628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Hefty * @id: Connection identifier to connect.
261628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Hefty * @conn_param: Connection information used for connected QPs.
262e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *
263e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * Users must have resolved a route for the rdma_cm_id to connect with
264e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * by having called rdma_resolve_route before calling this routine.
265628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Hefty *
266628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Hefty * This call will either connect to a remote QP or obtain remote QP
267628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Hefty * information for unconnected rdma_cm_id's.  The actual operation is
268628e5f6d39d5a6be96c1272a6709f2dd3ec8b7ceSean Hefty * based on the rdma_cm_id's port space.
269e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
270e51060f08a61965c4dd91516d82fe90617152590Sean Heftyint rdma_connect(struct rdma_cm_id *id, struct rdma_conn_param *conn_param);
271e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
272e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/**
273e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_listen - This function is called by the passive side to
274e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   listen for incoming connection requests.
275e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *
276e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * Users must have bound the rdma_cm_id to a local address by calling
277e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_bind_addr before calling this routine.
278e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
279e51060f08a61965c4dd91516d82fe90617152590Sean Heftyint rdma_listen(struct rdma_cm_id *id, int backlog);
280e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
281e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/**
282e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_accept - Called to accept a connection request or response.
283e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * @id: Connection identifier associated with the request.
284e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * @conn_param: Information needed to establish the connection.  This must be
285e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   provided if accepting a connection request.  If accepting a connection
286e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   response, this parameter must be NULL.
287e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *
288e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * Typically, this routine is only called by the listener to accept a connection
289e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * request.  It must also be called on the active side of a connection if the
290e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * user is performing their own QP transitions.
291951f7fc1372da3d826b1d975b3cc5e3db92af5d0Or Gerlitz *
292951f7fc1372da3d826b1d975b3cc5e3db92af5d0Or Gerlitz * In the case of error, a reject message is sent to the remote side and the
293951f7fc1372da3d826b1d975b3cc5e3db92af5d0Or Gerlitz * state of the qp associated with the id is modified to error, such that any
294951f7fc1372da3d826b1d975b3cc5e3db92af5d0Or Gerlitz * previously posted receive buffers would be flushed.
295e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
296e51060f08a61965c4dd91516d82fe90617152590Sean Heftyint rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param);
297e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
298e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/**
2990fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Hefty * rdma_notify - Notifies the RDMA CM of an asynchronous event that has
3000fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Hefty * occurred on the connection.
3010fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Hefty * @id: Connection identifier to transition to established.
3020fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Hefty * @event: Asynchronous event.
3030fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Hefty *
3040fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Hefty * This routine should be invoked by users to notify the CM of relevant
3050fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Hefty * communication events.  Events that should be reported to the CM and
3060fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Hefty * when to report them are:
3070fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Hefty *
3080fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Hefty * IB_EVENT_COMM_EST - Used when a message is received on a connected
3090fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Hefty *    QP before an RTU has been received.
3100fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Hefty */
3110fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Heftyint rdma_notify(struct rdma_cm_id *id, enum ib_event_type event);
3120fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Hefty
3130fe313b000b6a699afbbb59ef9c47a2b22146f1eSean Hefty/**
314e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_reject - Called to reject a connection request or response.
315e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
316e51060f08a61965c4dd91516d82fe90617152590Sean Heftyint rdma_reject(struct rdma_cm_id *id, const void *private_data,
317e51060f08a61965c4dd91516d82fe90617152590Sean Hefty		u8 private_data_len);
318e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
319e51060f08a61965c4dd91516d82fe90617152590Sean Hefty/**
320e51060f08a61965c4dd91516d82fe90617152590Sean Hefty * rdma_disconnect - This function disconnects the associated QP and
321e51060f08a61965c4dd91516d82fe90617152590Sean Hefty *   transitions it into the error state.
322e51060f08a61965c4dd91516d82fe90617152590Sean Hefty */
323e51060f08a61965c4dd91516d82fe90617152590Sean Heftyint rdma_disconnect(struct rdma_cm_id *id);
324e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
325c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty/**
326c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty * rdma_join_multicast - Join the multicast group specified by the given
327c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty *   address.
328c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty * @id: Communication identifier associated with the request.
329c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty * @addr: Multicast address identifying the group to join.
330c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty * @context: User-defined context associated with the join request, returned
331c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty * to the user through the private_data pointer in multicast events.
332c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty */
333c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Heftyint rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,
334c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty			void *context);
335e51060f08a61965c4dd91516d82fe90617152590Sean Hefty
336c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty/**
337c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty * rdma_leave_multicast - Leave the multicast group specified by the given
338c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty *   address.
339c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty */
340c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Heftyvoid rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr);
341c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty
342a81c994d5eef87ed77cb30d8343d6be296528b3fSean Hefty/**
343a81c994d5eef87ed77cb30d8343d6be296528b3fSean Hefty * rdma_set_service_type - Set the type of service associated with a
344a81c994d5eef87ed77cb30d8343d6be296528b3fSean Hefty *   connection identifier.
345a81c994d5eef87ed77cb30d8343d6be296528b3fSean Hefty * @id: Communication identifier to associated with service type.
346a81c994d5eef87ed77cb30d8343d6be296528b3fSean Hefty * @tos: Type of service.
347a81c994d5eef87ed77cb30d8343d6be296528b3fSean Hefty *
348a81c994d5eef87ed77cb30d8343d6be296528b3fSean Hefty * The type of service is interpretted as a differentiated service
349a81c994d5eef87ed77cb30d8343d6be296528b3fSean Hefty * field (RFC 2474).  The service type should be specified before
350a81c994d5eef87ed77cb30d8343d6be296528b3fSean Hefty * performing route resolution, as existing communication on the
351a81c994d5eef87ed77cb30d8343d6be296528b3fSean Hefty * connection identifier may be unaffected.  The type of service
352a81c994d5eef87ed77cb30d8343d6be296528b3fSean Hefty * requested may not be supported by the network to all destinations.
353a81c994d5eef87ed77cb30d8343d6be296528b3fSean Hefty */
354a81c994d5eef87ed77cb30d8343d6be296528b3fSean Heftyvoid rdma_set_service_type(struct rdma_cm_id *id, int tos);
355a81c994d5eef87ed77cb30d8343d6be296528b3fSean Hefty
356a9bb79128aa659f97b774b97c9bb1bdc74444595Hefty, Sean/**
357a9bb79128aa659f97b774b97c9bb1bdc74444595Hefty, Sean * rdma_set_reuseaddr - Allow the reuse of local addresses when binding
358a9bb79128aa659f97b774b97c9bb1bdc74444595Hefty, Sean *    the rdma_cm_id.
359a9bb79128aa659f97b774b97c9bb1bdc74444595Hefty, Sean * @id: Communication identifier to configure.
360a9bb79128aa659f97b774b97c9bb1bdc74444595Hefty, Sean * @reuse: Value indicating if the bound address is reusable.
361a9bb79128aa659f97b774b97c9bb1bdc74444595Hefty, Sean *
362a9bb79128aa659f97b774b97c9bb1bdc74444595Hefty, Sean * Reuse must be set before an address is bound to the id.
363a9bb79128aa659f97b774b97c9bb1bdc74444595Hefty, Sean */
364a9bb79128aa659f97b774b97c9bb1bdc74444595Hefty, Seanint rdma_set_reuseaddr(struct rdma_cm_id *id, int reuse);
365a9bb79128aa659f97b774b97c9bb1bdc74444595Hefty, Sean
36668602120e496a31d8e3b36d0bfc7d9d2456fb05cSean Hefty/**
36768602120e496a31d8e3b36d0bfc7d9d2456fb05cSean Hefty * rdma_set_afonly - Specify that listens are restricted to the
36868602120e496a31d8e3b36d0bfc7d9d2456fb05cSean Hefty *    bound address family only.
36968602120e496a31d8e3b36d0bfc7d9d2456fb05cSean Hefty * @id: Communication identifer to configure.
37068602120e496a31d8e3b36d0bfc7d9d2456fb05cSean Hefty * @afonly: Value indicating if listens are restricted.
37168602120e496a31d8e3b36d0bfc7d9d2456fb05cSean Hefty *
37268602120e496a31d8e3b36d0bfc7d9d2456fb05cSean Hefty * Must be set before identifier is in the listening state.
37368602120e496a31d8e3b36d0bfc7d9d2456fb05cSean Hefty */
37468602120e496a31d8e3b36d0bfc7d9d2456fb05cSean Heftyint rdma_set_afonly(struct rdma_cm_id *id, int afonly);
37568602120e496a31d8e3b36d0bfc7d9d2456fb05cSean Hefty
376cf53936f229d81131fef475919f163ce566a205fSean Hefty /**
377cf53936f229d81131fef475919f163ce566a205fSean Hefty * rdma_get_service_id - Return the IB service ID for a specified address.
378cf53936f229d81131fef475919f163ce566a205fSean Hefty * @id: Communication identifier associated with the address.
379cf53936f229d81131fef475919f163ce566a205fSean Hefty * @addr: Address for the service ID.
380cf53936f229d81131fef475919f163ce566a205fSean Hefty */
381cf53936f229d81131fef475919f163ce566a205fSean Hefty__be64 rdma_get_service_id(struct rdma_cm_id *id, struct sockaddr *addr);
382cf53936f229d81131fef475919f163ce566a205fSean Hefty
383c8f6a362bf3eb28ade6027b49bb160a336dd51c0Sean Hefty#endif /* RDMA_CM_H */
384