1 /* 2 * This file contains definitions used in OFED defined user/kernel 3 * interfaces. These are imported from the OFED header rdma_cm.h. Oracle 4 * elects to have and use the contents of rdma_cm.h under and governed 5 * by the OpenIB.org BSD license (see below for details). However, 6 * the following notice accompanied the original version of this file: 7 */ 8 9 /* 10 * Copyright (c) 2005 Voltaire Inc. All rights reserved. 11 * Copyright (c) 2005 Intel Corporation. All rights reserved. 12 * 13 * This Software is licensed under one of the following licenses: 14 * 15 * 1) under the terms of the "Common Public License 1.0" a copy of which is 16 * available from the Open Source Initiative, see 17 * http://www.opensource.org/licenses/cpl.php. 18 * 19 * 2) under the terms of the "The BSD License" a copy of which is 20 * available from the Open Source Initiative, see 21 * http://www.opensource.org/licenses/bsd-license.php. 22 * 23 * 3) under the terms of the "GNU General Public License (GPL) Version 2" a 24 * copy of which is available from the Open Source Initiative, see 25 * http://www.opensource.org/licenses/gpl-license.php. 26 * 27 * Licensee has the right to choose one of the above licenses. 28 * 29 * Redistributions of source code must retain the above copyright 30 * notice and one of the license notices. 31 * 32 * Redistributions in binary form must reproduce both the above copyright 33 * notice, one of the license notices in the documentation 34 * and/or other materials provided with the distribution. 35 * 36 */ 37 38 #ifndef _SYS_IB_CLIENTS_OF_RDMA_RDMA_CM_H 39 #define _SYS_IB_CLIENTS_OF_RDMA_RDMA_CM_H 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 #include <sys/socket.h> 46 47 /* 48 * Upon receiving a device removal event, users must destroy the associated 49 * RDMA identifier and release all resources allocated with the device. 50 */ 51 enum rdma_cm_event_type { 52 RDMA_CM_EVENT_ADDR_RESOLVED, 53 RDMA_CM_EVENT_ADDR_ERROR, 54 RDMA_CM_EVENT_ROUTE_RESOLVED, 55 RDMA_CM_EVENT_ROUTE_ERROR, 56 RDMA_CM_EVENT_CONNECT_REQUEST, 57 RDMA_CM_EVENT_CONNECT_RESPONSE, 58 RDMA_CM_EVENT_CONNECT_ERROR, 59 RDMA_CM_EVENT_UNREACHABLE, 60 RDMA_CM_EVENT_REJECTED, 61 RDMA_CM_EVENT_ESTABLISHED, 62 RDMA_CM_EVENT_DISCONNECTED, 63 RDMA_CM_EVENT_DEVICE_REMOVAL, 64 RDMA_CM_EVENT_MULTICAST_JOIN, 65 RDMA_CM_EVENT_MULTICAST_ERROR 66 }; 67 68 enum rdma_port_space { 69 RDMA_PS_SDP = 0x0001, 70 RDMA_PS_IPOIB = 0x0002, 71 RDMA_PS_TCP = 0x0106, 72 RDMA_PS_UDP = 0x0111, 73 RDMA_PS_SCTP = 0x0183 74 }; 75 76 struct rdma_addr { 77 struct sockaddr src_addr; 78 uint8_t src_pad[sizeof (struct sockaddr_in6) - 79 sizeof (struct sockaddr)]; 80 struct sockaddr dst_addr; 81 uint8_t dst_pad[sizeof (struct sockaddr_in6) - 82 sizeof (struct sockaddr)]; 83 struct rdma_dev_addr dev_addr; 84 }; 85 86 struct rdma_route { 87 struct rdma_addr addr; 88 struct ib_sa_path_rec *path_rec; 89 int num_paths; 90 }; 91 92 struct rdma_conn_param { 93 const void *private_data; 94 uint8_t private_data_len; 95 uint8_t responder_resources; 96 uint8_t initiator_depth; 97 uint8_t flow_control; 98 uint8_t retry_count; /* ignored when accepting */ 99 uint8_t rnr_retry_count; 100 /* Fields below ignored if a QP is created on the rdma_cm_id. */ 101 uint8_t srq; 102 uint32_t qp_num; 103 }; 104 105 struct rdma_ud_param { 106 const void *private_data; 107 uint8_t private_data_len; 108 struct ib_ah_attr ah_attr; 109 uint32_t qp_num; 110 uint32_t qkey; 111 }; 112 113 struct rdma_cm_event { 114 enum rdma_cm_event_type event; 115 int status; 116 union { 117 struct rdma_conn_param conn; 118 struct rdma_ud_param ud; 119 } param; 120 }; 121 122 struct rdma_cm_id; 123 124 /* 125 * rdma_cm_event_handler - Callback used to report user events. 126 * 127 * Notes: Users may not call rdma_destroy_id from this callback to destroy 128 * the passed in id, or a corresponding listen id. Returning a 129 * non-zero value from the callback will destroy the passed in id. 130 */ 131 typedef int (*rdma_cm_event_handler)(struct rdma_cm_id *id, 132 struct rdma_cm_event *event); 133 134 struct rdma_cm_id { 135 struct ib_device *device; 136 void *context; 137 struct ib_qp *qp; 138 rdma_cm_event_handler event_handler; 139 struct rdma_route route; 140 enum rdma_port_space ps; 141 uint8_t port_num; 142 }; 143 144 /* 145 * rdma_create_id - Create an RDMA identifier. 146 * 147 * @event_handler: User callback invoked to report events associated with the 148 * returned rdma_id. 149 * @context: User specified context associated with the id. 150 * @ps: RDMA port space. 151 */ 152 struct rdma_cm_id *rdma_create_id(rdma_cm_event_handler event_handler, 153 void *context, enum rdma_port_space ps); 154 155 /* 156 * rdma_map_id2clnthdl - 157 * Maps RDMA identifier with IBTF and / or ROF client handles. Either 158 * of the handles can be NULL, but both should not be NULL. This API 159 * is called just after calling rdma_create_id() on the passive side. 160 * 161 * rdma_map_id2qphdl - 162 * This is used to map RDMA-CM ID to IBTF or ROF client handle and 163 * the QP handle. This is called by the passive side just after 164 * rdma_create_id() and on the active side just before rdma_accept() 165 * in the CONNECTION_REQUEST event handler. 166 */ 167 void rdma_map_id2clnthdl(struct rdma_cm_id *id, void *ib_client_hdl, 168 void *iw_client_hdl); 169 void rdma_map_id2qphdl(struct rdma_cm_id *id, void *qp_hdl); 170 171 /* 172 * rdma_destroy_id - Destroys an RDMA identifier. 173 * 174 * @id: RDMA identifier. 175 * 176 * Note: calling this function has the effect of canceling in-flight 177 * asynchronous operations associated with the id. 178 */ 179 void rdma_destroy_id(struct rdma_cm_id *id); 180 181 /* 182 * rdma_bind_addr - Bind an RDMA identifier to a source address and 183 * associated RDMA device, if needed. 184 * 185 * @id: RDMA identifier. 186 * @addr: Local address information. Wildcard values are permitted. 187 * 188 * This associates a source address with the RDMA identifier before calling 189 * rdma_listen. If a specific local address is given, the RDMA identifier will 190 * be bound to a local RDMA device. 191 */ 192 int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr); 193 194 /* 195 * rdma_resolve_addr - Resolve destination and optional source addresses 196 * from IP addresses to an RDMA address. If successful, the specified 197 * rdma_cm_id will be bound to a local device. 198 * 199 * @id: RDMA identifier. 200 * @src_addr: Source address information. This parameter may be NULL. 201 * @dst_addr: Destination address information. 202 * @timeout_ms: Time to wait for resolution to complete. 203 */ 204 int rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr, 205 struct sockaddr *dst_addr, int timeout_ms); 206 207 /* 208 * rdma_resolve_route - Resolve the RDMA address bound to the RDMA identifier 209 * into route information needed to establish a connection. 210 * 211 * This is called on the client side of a connection. 212 * Users must have first called rdma_resolve_addr to resolve a dst_addr 213 * into an RDMA address before calling this routine. 214 */ 215 int rdma_resolve_route(struct rdma_cm_id *id, int timeout_ms); 216 217 218 /* 219 * rdma_init_qp_attr - Initializes the QP attributes for use in transitioning 220 * to a specified QP state. 221 * @id: Communication identifier associated with the QP attributes to 222 * initialize. 223 * @qp_attr: On input, specifies the desired QP state. On output, the 224 * mandatory and desired optional attributes will be set in order to 225 * modify the QP to the specified state. 226 * @qp_attr_mask: The QP attribute mask that may be used to transition the 227 * QP to the specified state. 228 * 229 * Users must set the @qp_attr->qp_state to the desired QP state. This call 230 * will set all required attributes for the given transition, along with 231 * known optional attributes. Users may override the attributes returned from 232 * this call before calling ib_modify_qp. 233 * 234 * Users that wish to have their QP automatically transitioned through its 235 * states can associate a QP with the rdma_cm_id by calling rdma_create_qp(). 236 */ 237 int rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr, 238 int *qp_attr_mask); 239 /* 240 * rdma_connect - Initiate an active connection request. 241 * @id: Connection identifier to connect. 242 * @conn_param: Connection information used for connected QPs. 243 * 244 * Users must have resolved a route for the rdma_cm_id to connect with 245 * by having called rdma_resolve_route before calling this routine. 246 * 247 * This call will either connect to a remote QP or obtain remote QP 248 * information for unconnected rdma_cm_id's. The actual operation is 249 * based on the rdma_cm_id's port space. 250 */ 251 int rdma_connect(struct rdma_cm_id *id, struct rdma_conn_param *conn_param); 252 253 /* 254 * rdma_listen - This function is called by the passive side to 255 * listen for incoming connection requests. 256 * 257 * Users must have bound the rdma_cm_id to a local address by calling 258 * rdma_bind_addr before calling this routine. 259 */ 260 int rdma_listen(struct rdma_cm_id *id, int backlog); 261 262 /* 263 * rdma_accept - Called to accept a connection request or response. 264 * @id: Connection identifier associated with the request. 265 * @conn_param: Information needed to establish the connection. This must be 266 * provided if accepting a connection request. If accepting a connection 267 * response, this parameter must be NULL. 268 * 269 * Typically, this routine is only called by the listener to accept a connection 270 * request. It must also be called on the active side of a connection if the 271 * user is performing their own QP transitions. 272 * 273 * In the case of error, a reject message is sent to the remote side and the 274 * state of the qp associated with the id is modified to error, such that any 275 * previously posted receive buffers would be flushed. 276 */ 277 int rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param); 278 279 /* 280 * rdma_notify - Notifies the RDMA CM of an asynchronous event that has 281 * occurred on the connection. 282 * @id: Connection identifier to transition to established. 283 * @event: Asynchronous event. 284 * 285 * This routine should be invoked by users to notify the CM of relevant 286 * communication events. Events that should be reported to the CM and 287 * when to report them are: 288 * 289 * IB_EVENT_COMM_EST - Used when a message is received on a connected 290 * QP before an RTU has been received. 291 */ 292 int rdma_notify(struct rdma_cm_id *id, enum ib_event_type event); 293 294 /* 295 * rdma_reject - Called to reject a connection request or response. 296 */ 297 int rdma_reject(struct rdma_cm_id *id, const void *private_data, 298 uint8_t private_data_len); 299 300 /* 301 * rdma_disconnect - This function disconnects the associated QP and 302 * transitions it into the error state. 303 */ 304 int rdma_disconnect(struct rdma_cm_id *id); 305 306 /* 307 * rdma_join_multicast - Join the multicast group specified by the given 308 * address. 309 * @id: Communication identifier associated with the request. 310 * @addr: Multicast address identifying the group to join. 311 * @context: User-defined context associated with the join request, returned 312 * to the user through the private_data pointer in multicast events. 313 */ 314 int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr, 315 void *context); 316 317 /* 318 * rdma_leave_multicast - Leave the multicast group specified by the given 319 * address. 320 */ 321 void rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr); 322 323 /* 324 * rdma_set_service_type - Set the type of service associated with a 325 * connection identifier. 326 * @id: Communication identifier to associated with service type. 327 * @tos: Type of service. 328 * 329 * The type of service is interpretted as a differentiated service 330 * field (RFC 2474). The service type should be specified before 331 * performing route resolution, as existing communication on the 332 * connection identifier may be unaffected. The type of service 333 * requested may not be supported by the network to all destinations. 334 */ 335 void rdma_set_service_type(struct rdma_cm_id *id, int tos); 336 337 338 /* 339 * rdma_create_qp - Allocate a QP and associate it with the specified RDMA 340 * identifier. 341 * 342 * QPs allocated to an rdma_cm_id will automatically be transitioned by the CMA 343 * through their states. 344 */ 345 int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd, 346 struct ib_qp_init_attr *qp_init_attr); 347 348 /* 349 * rdma_destroy_qp - Deallocate the QP associated with the specified RDMA 350 * identifier. 351 * 352 * Users must destroy any QP associated with an RDMA identifier before 353 * destroying the RDMA ID. 354 */ 355 void rdma_destroy_qp(struct rdma_cm_id *id); 356 357 #ifdef __cplusplus 358 } 359 #endif 360 #endif /* _SYS_IB_CLIENTS_OF_RDMA_RDMA_CM_H */