rdma_cma.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /*
  2. * Copyright (c) 2005 Voltaire Inc. All rights reserved.
  3. * Copyright (c) 2005-2014 Intel Corporation. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #if !defined(RDMA_CMA_H)
  34. #define RDMA_CMA_H
  35. #include <netinet/in.h>
  36. #include <sys/socket.h>
  37. #include <infiniband/verbs.h>
  38. #include <infiniband/sa.h>
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /*
  43. * Upon receiving a device removal event, users must destroy the associated
  44. * RDMA identifier and release all resources allocated with the device.
  45. */
  46. enum rdma_cm_event_type {
  47. RDMA_CM_EVENT_ADDR_RESOLVED,
  48. RDMA_CM_EVENT_ADDR_ERROR,
  49. RDMA_CM_EVENT_ROUTE_RESOLVED,
  50. RDMA_CM_EVENT_ROUTE_ERROR,
  51. RDMA_CM_EVENT_CONNECT_REQUEST,
  52. RDMA_CM_EVENT_CONNECT_RESPONSE,
  53. RDMA_CM_EVENT_CONNECT_ERROR,
  54. RDMA_CM_EVENT_UNREACHABLE,
  55. RDMA_CM_EVENT_REJECTED,
  56. RDMA_CM_EVENT_ESTABLISHED,
  57. RDMA_CM_EVENT_DISCONNECTED,
  58. RDMA_CM_EVENT_DEVICE_REMOVAL,
  59. RDMA_CM_EVENT_MULTICAST_JOIN,
  60. RDMA_CM_EVENT_MULTICAST_ERROR,
  61. RDMA_CM_EVENT_ADDR_CHANGE,
  62. RDMA_CM_EVENT_TIMEWAIT_EXIT
  63. };
  64. enum rdma_port_space {
  65. RDMA_PS_IPOIB = 0x0002,
  66. RDMA_PS_TCP = 0x0106,
  67. RDMA_PS_UDP = 0x0111,
  68. RDMA_PS_IB = 0x013F,
  69. };
  70. #define RDMA_IB_IP_PS_MASK 0xFFFFFFFFFFFF0000ULL
  71. #define RDMA_IB_IP_PORT_MASK 0x000000000000FFFFULL
  72. #define RDMA_IB_IP_PS_TCP 0x0000000001060000ULL
  73. #define RDMA_IB_IP_PS_UDP 0x0000000001110000ULL
  74. #define RDMA_IB_PS_IB 0x00000000013F0000ULL
  75. /*
  76. * Global qkey value for UDP QPs and multicast groups created via the
  77. * RDMA CM.
  78. */
  79. #define RDMA_UDP_QKEY 0x01234567
  80. struct rdma_ib_addr {
  81. union ibv_gid sgid;
  82. union ibv_gid dgid;
  83. __be16 pkey;
  84. };
  85. struct rdma_addr {
  86. union {
  87. struct sockaddr src_addr;
  88. struct sockaddr_in src_sin;
  89. struct sockaddr_in6 src_sin6;
  90. struct sockaddr_storage src_storage;
  91. };
  92. union {
  93. struct sockaddr dst_addr;
  94. struct sockaddr_in dst_sin;
  95. struct sockaddr_in6 dst_sin6;
  96. struct sockaddr_storage dst_storage;
  97. };
  98. union {
  99. struct rdma_ib_addr ibaddr;
  100. } addr;
  101. };
  102. struct rdma_route {
  103. struct rdma_addr addr;
  104. struct ibv_sa_path_rec *path_rec;
  105. int num_paths;
  106. };
  107. struct rdma_event_channel {
  108. int fd;
  109. };
  110. struct rdma_cm_id {
  111. struct ibv_context *verbs;
  112. struct rdma_event_channel *channel;
  113. void *context;
  114. struct ibv_qp *qp;
  115. struct rdma_route route;
  116. enum rdma_port_space ps;
  117. uint8_t port_num;
  118. struct rdma_cm_event *event;
  119. struct ibv_comp_channel *send_cq_channel;
  120. struct ibv_cq *send_cq;
  121. struct ibv_comp_channel *recv_cq_channel;
  122. struct ibv_cq *recv_cq;
  123. struct ibv_srq *srq;
  124. struct ibv_pd *pd;
  125. enum ibv_qp_type qp_type;
  126. };
  127. enum {
  128. RDMA_MAX_RESP_RES = 0xFF,
  129. RDMA_MAX_INIT_DEPTH = 0xFF
  130. };
  131. struct rdma_conn_param {
  132. const void *private_data;
  133. uint8_t private_data_len;
  134. uint8_t responder_resources;
  135. uint8_t initiator_depth;
  136. uint8_t flow_control;
  137. uint8_t retry_count; /* ignored when accepting */
  138. uint8_t rnr_retry_count;
  139. /* Fields below ignored if a QP is created on the rdma_cm_id. */
  140. uint8_t srq;
  141. uint32_t qp_num;
  142. };
  143. struct rdma_ud_param {
  144. const void *private_data;
  145. uint8_t private_data_len;
  146. struct ibv_ah_attr ah_attr;
  147. uint32_t qp_num;
  148. uint32_t qkey;
  149. };
  150. struct rdma_cm_event {
  151. struct rdma_cm_id *id;
  152. struct rdma_cm_id *listen_id;
  153. enum rdma_cm_event_type event;
  154. int status;
  155. union {
  156. struct rdma_conn_param conn;
  157. struct rdma_ud_param ud;
  158. } param;
  159. };
  160. #define RAI_PASSIVE 0x00000001
  161. #define RAI_NUMERICHOST 0x00000002
  162. #define RAI_NOROUTE 0x00000004
  163. #define RAI_FAMILY 0x00000008
  164. struct rdma_addrinfo {
  165. int ai_flags;
  166. int ai_family;
  167. int ai_qp_type;
  168. int ai_port_space;
  169. socklen_t ai_src_len;
  170. socklen_t ai_dst_len;
  171. struct sockaddr *ai_src_addr;
  172. struct sockaddr *ai_dst_addr;
  173. char *ai_src_canonname;
  174. char *ai_dst_canonname;
  175. size_t ai_route_len;
  176. void *ai_route;
  177. size_t ai_connect_len;
  178. void *ai_connect;
  179. struct rdma_addrinfo *ai_next;
  180. };
  181. /* Multicast join compatibility mask attributes */
  182. enum rdma_cm_join_mc_attr_mask {
  183. RDMA_CM_JOIN_MC_ATTR_ADDRESS = 1 << 0,
  184. RDMA_CM_JOIN_MC_ATTR_JOIN_FLAGS = 1 << 1,
  185. RDMA_CM_JOIN_MC_ATTR_RESERVED = 1 << 2,
  186. };
  187. /* Multicast join flags */
  188. enum rdma_cm_mc_join_flags {
  189. RDMA_MC_JOIN_FLAG_FULLMEMBER,
  190. RDMA_MC_JOIN_FLAG_SENDONLY_FULLMEMBER,
  191. RDMA_MC_JOIN_FLAG_RESERVED,
  192. };
  193. struct rdma_cm_join_mc_attr_ex {
  194. /* Bitwise OR between "rdma_cm_join_mc_attr_mask" enum */
  195. uint32_t comp_mask;
  196. /* Use a flag from "rdma_cm_mc_join_flags" enum */
  197. uint32_t join_flags;
  198. /* Multicast address identifying the group to join */
  199. struct sockaddr *addr;
  200. };
  201. /**
  202. * rdma_create_event_channel - Open a channel used to report communication events.
  203. * Description:
  204. * Asynchronous events are reported to users through event channels. Each
  205. * event channel maps to a file descriptor.
  206. * Notes:
  207. * All created event channels must be destroyed by calling
  208. * rdma_destroy_event_channel. Users should call rdma_get_cm_event to
  209. * retrieve events on an event channel.
  210. * See also:
  211. * rdma_get_cm_event, rdma_destroy_event_channel
  212. */
  213. struct rdma_event_channel *rdma_create_event_channel(void);
  214. /**
  215. * rdma_destroy_event_channel - Close an event communication channel.
  216. * @channel: The communication channel to destroy.
  217. * Description:
  218. * Release all resources associated with an event channel and closes the
  219. * associated file descriptor.
  220. * Notes:
  221. * All rdma_cm_id's associated with the event channel must be destroyed,
  222. * and all returned events must be acked before calling this function.
  223. * See also:
  224. * rdma_create_event_channel, rdma_get_cm_event, rdma_ack_cm_event
  225. */
  226. void rdma_destroy_event_channel(struct rdma_event_channel *channel);
  227. /**
  228. * rdma_create_id - Allocate a communication identifier.
  229. * @channel: The communication channel that events associated with the
  230. * allocated rdma_cm_id will be reported on.
  231. * @id: A reference where the allocated communication identifier will be
  232. * returned.
  233. * @context: User specified context associated with the rdma_cm_id.
  234. * @ps: RDMA port space.
  235. * Description:
  236. * Creates an identifier that is used to track communication information.
  237. * Notes:
  238. * Rdma_cm_id's are conceptually equivalent to a socket for RDMA
  239. * communication. The difference is that RDMA communication requires
  240. * explicitly binding to a specified RDMA device before communication
  241. * can occur, and most operations are asynchronous in nature. Communication
  242. * events on an rdma_cm_id are reported through the associated event
  243. * channel. Users must release the rdma_cm_id by calling rdma_destroy_id.
  244. * See also:
  245. * rdma_create_event_channel, rdma_destroy_id, rdma_get_devices,
  246. * rdma_bind_addr, rdma_resolve_addr, rdma_connect, rdma_listen,
  247. */
  248. int rdma_create_id(struct rdma_event_channel *channel,
  249. struct rdma_cm_id **id, void *context,
  250. enum rdma_port_space ps);
  251. /**
  252. * rdma_create_ep - Allocate a communication identifier and qp.
  253. * @id: A reference where the allocated communication identifier will be
  254. * returned.
  255. * @res: Result from rdma_getaddrinfo, which specifies the source and
  256. * destination addresses, plus optional routing and connection information.
  257. * @pd: Optional protection domain. This parameter is ignored if qp_init_attr
  258. * is NULL.
  259. * @qp_init_attr: Optional attributes for a QP created on the rdma_cm_id.
  260. * Description:
  261. * Create an identifier and option QP used for communication.
  262. * Notes:
  263. * If qp_init_attr is provided, then a queue pair will be allocated and
  264. * associated with the rdma_cm_id. If a pd is provided, the QP will be
  265. * created on that PD. Otherwise, the QP will be allocated on a default
  266. * PD.
  267. * The rdma_cm_id will be set to use synchronous operations (connect,
  268. * listen, and get_request). To convert to asynchronous operation, the
  269. * rdma_cm_id should be migrated to a user allocated event channel.
  270. * See also:
  271. * rdma_create_id, rdma_create_qp, rdma_migrate_id, rdma_connect,
  272. * rdma_listen
  273. */
  274. int rdma_create_ep(struct rdma_cm_id **id, struct rdma_addrinfo *res,
  275. struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr);
  276. /**
  277. * rdma_destroy_ep - Deallocates a communication identifier and qp.
  278. * @id: The communication identifier to destroy.
  279. * Description:
  280. * Destroys the specified rdma_cm_id and any associated QP created
  281. * on that id.
  282. * See also:
  283. * rdma_create_ep
  284. */
  285. void rdma_destroy_ep(struct rdma_cm_id *id);
  286. /**
  287. * rdma_destroy_id - Release a communication identifier.
  288. * @id: The communication identifier to destroy.
  289. * Description:
  290. * Destroys the specified rdma_cm_id and cancels any outstanding
  291. * asynchronous operation.
  292. * Notes:
  293. * Users must free any associated QP with the rdma_cm_id before
  294. * calling this routine and ack an related events.
  295. * See also:
  296. * rdma_create_id, rdma_destroy_qp, rdma_ack_cm_event
  297. */
  298. int rdma_destroy_id(struct rdma_cm_id *id);
  299. /**
  300. * rdma_bind_addr - Bind an RDMA identifier to a source address.
  301. * @id: RDMA identifier.
  302. * @addr: Local address information. Wildcard values are permitted.
  303. * Description:
  304. * Associates a source address with an rdma_cm_id. The address may be
  305. * wildcarded. If binding to a specific local address, the rdma_cm_id
  306. * will also be bound to a local RDMA device.
  307. * Notes:
  308. * Typically, this routine is called before calling rdma_listen to bind
  309. * to a specific port number, but it may also be called on the active side
  310. * of a connection before calling rdma_resolve_addr to bind to a specific
  311. * address.
  312. * See also:
  313. * rdma_create_id, rdma_listen, rdma_resolve_addr, rdma_create_qp
  314. */
  315. int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr);
  316. /**
  317. * rdma_resolve_addr - Resolve destination and optional source addresses.
  318. * @id: RDMA identifier.
  319. * @src_addr: Source address information. This parameter may be NULL.
  320. * @dst_addr: Destination address information.
  321. * @timeout_ms: Time to wait for resolution to complete.
  322. * Description:
  323. * Resolve destination and optional source addresses from IP addresses
  324. * to an RDMA address. If successful, the specified rdma_cm_id will
  325. * be bound to a local device.
  326. * Notes:
  327. * This call is used to map a given destination IP address to a usable RDMA
  328. * address. If a source address is given, the rdma_cm_id is bound to that
  329. * address, the same as if rdma_bind_addr were called. If no source
  330. * address is given, and the rdma_cm_id has not yet been bound to a device,
  331. * then the rdma_cm_id will be bound to a source address based on the
  332. * local routing tables. After this call, the rdma_cm_id will be bound to
  333. * an RDMA device. This call is typically made from the active side of a
  334. * connection before calling rdma_resolve_route and rdma_connect.
  335. * See also:
  336. * rdma_create_id, rdma_resolve_route, rdma_connect, rdma_create_qp,
  337. * rdma_get_cm_event, rdma_bind_addr
  338. */
  339. int rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr,
  340. struct sockaddr *dst_addr, int timeout_ms);
  341. /**
  342. * rdma_resolve_route - Resolve the route information needed to establish a connection.
  343. * @id: RDMA identifier.
  344. * @timeout_ms: Time to wait for resolution to complete.
  345. * Description:
  346. * Resolves an RDMA route to the destination address in order to establish
  347. * a connection. The destination address must have already been resolved
  348. * by calling rdma_resolve_addr.
  349. * Notes:
  350. * This is called on the client side of a connection after calling
  351. * rdma_resolve_addr, but before calling rdma_connect.
  352. * See also:
  353. * rdma_resolve_addr, rdma_connect, rdma_get_cm_event
  354. */
  355. int rdma_resolve_route(struct rdma_cm_id *id, int timeout_ms);
  356. /**
  357. * rdma_create_qp - Allocate a QP.
  358. * @id: RDMA identifier.
  359. * @pd: Optional protection domain for the QP.
  360. * @qp_init_attr: initial QP attributes.
  361. * Description:
  362. * Allocate a QP associated with the specified rdma_cm_id and transition it
  363. * for sending and receiving.
  364. * Notes:
  365. * The rdma_cm_id must be bound to a local RDMA device before calling this
  366. * function, and the protection domain must be for that same device.
  367. * QPs allocated to an rdma_cm_id are automatically transitioned by the
  368. * librdmacm through their states. After being allocated, the QP will be
  369. * ready to handle posting of receives. If the QP is unconnected, it will
  370. * be ready to post sends.
  371. * If pd is NULL, then the QP will be allocated using a default protection
  372. * domain associated with the underlying RDMA device.
  373. * See also:
  374. * rdma_bind_addr, rdma_resolve_addr, rdma_destroy_qp, ibv_create_qp,
  375. * ibv_modify_qp
  376. */
  377. int rdma_create_qp(struct rdma_cm_id *id, struct ibv_pd *pd,
  378. struct ibv_qp_init_attr *qp_init_attr);
  379. int rdma_create_qp_ex(struct rdma_cm_id *id,
  380. struct ibv_qp_init_attr_ex *qp_init_attr);
  381. /**
  382. * rdma_destroy_qp - Deallocate a QP.
  383. * @id: RDMA identifier.
  384. * Description:
  385. * Destroy a QP allocated on the rdma_cm_id.
  386. * Notes:
  387. * Users must destroy any QP associated with an rdma_cm_id before
  388. * destroying the ID.
  389. * See also:
  390. * rdma_create_qp, rdma_destroy_id, ibv_destroy_qp
  391. */
  392. void rdma_destroy_qp(struct rdma_cm_id *id);
  393. /**
  394. * rdma_connect - Initiate an active connection request.
  395. * @id: RDMA identifier.
  396. * @conn_param: optional connection parameters.
  397. * Description:
  398. * For a connected rdma_cm_id, this call initiates a connection request
  399. * to a remote destination. For an unconnected rdma_cm_id, it initiates
  400. * a lookup of the remote QP providing the datagram service.
  401. * Notes:
  402. * Users must have resolved a route to the destination address
  403. * by having called rdma_resolve_route before calling this routine.
  404. * A user may override the default connection parameters and exchange
  405. * private data as part of the connection by using the conn_param parameter.
  406. * See also:
  407. * rdma_resolve_route, rdma_disconnect, rdma_listen, rdma_get_cm_event
  408. */
  409. int rdma_connect(struct rdma_cm_id *id, struct rdma_conn_param *conn_param);
  410. /**
  411. * rdma_establish - Complete an active connection request.
  412. * @id: RDMA identifier.
  413. * Description:
  414. * Acknowledge an incoming connection response event and complete the
  415. * connection establishment.
  416. * Notes:
  417. * If a QP has not been created on the rdma_cm_id, this function should be
  418. * called by the active side to complete the connection, after getting connect
  419. * response event. This will trigger a connection established event on the
  420. * passive side.
  421. * This function should not be used on an rdma_cm_id on which a QP has been
  422. * created.
  423. * See also:
  424. * rdma_connect, rdma_disconnect, rdma_get_cm_event
  425. */
  426. int rdma_establish(struct rdma_cm_id *id);
  427. /**
  428. * rdma_listen - Listen for incoming connection requests.
  429. * @id: RDMA identifier.
  430. * @backlog: backlog of incoming connection requests.
  431. * Description:
  432. * Initiates a listen for incoming connection requests or datagram service
  433. * lookup. The listen will be restricted to the locally bound source
  434. * address.
  435. * Notes:
  436. * Users must have bound the rdma_cm_id to a local address by calling
  437. * rdma_bind_addr before calling this routine. If the rdma_cm_id is
  438. * bound to a specific IP address, the listen will be restricted to that
  439. * address and the associated RDMA device. If the rdma_cm_id is bound
  440. * to an RDMA port number only, the listen will occur across all RDMA
  441. * devices.
  442. * See also:
  443. * rdma_bind_addr, rdma_connect, rdma_accept, rdma_reject, rdma_get_cm_event
  444. */
  445. int rdma_listen(struct rdma_cm_id *id, int backlog);
  446. /**
  447. * rdma_get_request
  448. */
  449. int rdma_get_request(struct rdma_cm_id *listen, struct rdma_cm_id **id);
  450. /**
  451. * rdma_accept - Called to accept a connection request.
  452. * @id: Connection identifier associated with the request.
  453. * @conn_param: Optional information needed to establish the connection.
  454. * Description:
  455. * Called from the listening side to accept a connection or datagram
  456. * service lookup request.
  457. * Notes:
  458. * Unlike the socket accept routine, rdma_accept is not called on a
  459. * listening rdma_cm_id. Instead, after calling rdma_listen, the user
  460. * waits for a connection request event to occur. Connection request
  461. * events give the user a newly created rdma_cm_id, similar to a new
  462. * socket, but the rdma_cm_id is bound to a specific RDMA device.
  463. * rdma_accept is called on the new rdma_cm_id.
  464. * A user may override the default connection parameters and exchange
  465. * private data as part of the connection by using the conn_param parameter.
  466. * See also:
  467. * rdma_listen, rdma_reject, rdma_get_cm_event
  468. */
  469. int rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param);
  470. /**
  471. * rdma_reject - Called to reject a connection request.
  472. * @id: Connection identifier associated with the request.
  473. * @private_data: Optional private data to send with the reject message.
  474. * @private_data_len: Size of the private_data to send, in bytes.
  475. * Description:
  476. * Called from the listening side to reject a connection or datagram
  477. * service lookup request.
  478. * Notes:
  479. * After receiving a connection request event, a user may call rdma_reject
  480. * to reject the request. If the underlying RDMA transport supports
  481. * private data in the reject message, the specified data will be passed to
  482. * the remote side.
  483. * See also:
  484. * rdma_listen, rdma_accept, rdma_get_cm_event
  485. */
  486. int rdma_reject(struct rdma_cm_id *id, const void *private_data,
  487. uint8_t private_data_len);
  488. /**
  489. * rdma_reject_ece - Called to reject a connection request with ECE
  490. * rejected reason.
  491. * The same as rdma_reject()
  492. */
  493. int rdma_reject_ece(struct rdma_cm_id *id, const void *private_data,
  494. uint8_t private_data_len);
  495. /**
  496. * rdma_notify - Notifies the librdmacm of an asynchronous event.
  497. * @id: RDMA identifier.
  498. * @event: Asynchronous event.
  499. * Description:
  500. * Used to notify the librdmacm of asynchronous events that have occurred
  501. * on a QP associated with the rdma_cm_id.
  502. * Notes:
  503. * Asynchronous events that occur on a QP are reported through the user's
  504. * device event handler. This routine is used to notify the librdmacm of
  505. * communication events. In most cases, use of this routine is not
  506. * necessary, however if connection establishment is done out of band
  507. * (such as done through Infiniband), it's possible to receive data on a
  508. * QP that is not yet considered connected. This routine forces the
  509. * connection into an established state in this case in order to handle
  510. * the rare situation where the connection never forms on its own.
  511. * Events that should be reported to the CM are: IB_EVENT_COMM_EST.
  512. * See also:
  513. * rdma_connect, rdma_accept, rdma_listen
  514. */
  515. int rdma_notify(struct rdma_cm_id *id, enum ibv_event_type event);
  516. /**
  517. * rdma_disconnect - This function disconnects a connection.
  518. * @id: RDMA identifier.
  519. * Description:
  520. * Disconnects a connection and transitions any associated QP to the
  521. * error state.
  522. * See also:
  523. * rdma_connect, rdma_listen, rdma_accept
  524. */
  525. int rdma_disconnect(struct rdma_cm_id *id);
  526. /**
  527. * rdma_join_multicast - Joins a multicast group.
  528. * @id: Communication identifier associated with the request.
  529. * @addr: Multicast address identifying the group to join.
  530. * @context: User-defined context associated with the join request.
  531. * Description:
  532. * Joins a multicast group and attaches an associated QP to the group.
  533. * Notes:
  534. * Before joining a multicast group, the rdma_cm_id must be bound to
  535. * an RDMA device by calling rdma_bind_addr or rdma_resolve_addr. Use of
  536. * rdma_resolve_addr requires the local routing tables to resolve the
  537. * multicast address to an RDMA device. The user must call
  538. * rdma_leave_multicast to leave the multicast group and release any
  539. * multicast resources. The context is returned to the user through
  540. * the private_data field in the rdma_cm_event.
  541. * See also:
  542. * rdma_leave_multicast, rdma_bind_addr, rdma_resolve_addr, rdma_create_qp
  543. */
  544. int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,
  545. void *context);
  546. /**
  547. * rdma_leave_multicast - Leaves a multicast group.
  548. * @id: Communication identifier associated with the request.
  549. * @addr: Multicast address identifying the group to leave.
  550. * Description:
  551. * Leaves a multicast group and detaches an associated QP from the group.
  552. * Notes:
  553. * Calling this function before a group has been fully joined results in
  554. * canceling the join operation. Users should be aware that messages
  555. * received from the multicast group may stilled be queued for
  556. * completion processing immediately after leaving a multicast group.
  557. * Destroying an rdma_cm_id will automatically leave all multicast groups.
  558. * See also:
  559. * rdma_join_multicast, rdma_destroy_qp
  560. */
  561. int rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr);
  562. /**
  563. * rdma_multicast_ex - Joins a multicast group with options.
  564. * @id: Communication identifier associated with the request.
  565. * @mc_join_attr: Extensive struct containing multicast join parameters.
  566. * @context: User-defined context associated with the join request.
  567. * Description:
  568. * Joins a multicast group with options. Currently supporting MC join flags.
  569. * The QP will be attached based on the given join flag.
  570. * Join message will be sent according to the join flag.
  571. * Notes:
  572. * Before joining a multicast group, the rdma_cm_id must be bound to
  573. * an RDMA device by calling rdma_bind_addr or rdma_resolve_addr. Use of
  574. * rdma_resolve_addr requires the local routing tables to resolve the
  575. * multicast address to an RDMA device. The user must call
  576. * rdma_leave_multicast to leave the multicast group and release any
  577. * multicast resources. The context is returned to the user through
  578. * the private_data field in the rdma_cm_event.
  579. * See also:
  580. * rdma_leave_multicast, rdma_bind_addr, rdma_resolve_addr, rdma_create_qp
  581. */
  582. int rdma_join_multicast_ex(struct rdma_cm_id *id,
  583. struct rdma_cm_join_mc_attr_ex *mc_join_attr,
  584. void *context);
  585. /**
  586. * rdma_get_cm_event - Retrieves the next pending communication event.
  587. * @channel: Event channel to check for events.
  588. * @event: Allocated information about the next communication event.
  589. * Description:
  590. * Retrieves a communication event. If no events are pending, by default,
  591. * the call will block until an event is received.
  592. * Notes:
  593. * The default synchronous behavior of this routine can be changed by
  594. * modifying the file descriptor associated with the given channel. All
  595. * events that are reported must be acknowledged by calling rdma_ack_cm_event.
  596. * Destruction of an rdma_cm_id will block until related events have been
  597. * acknowledged.
  598. * See also:
  599. * rdma_ack_cm_event, rdma_create_event_channel, rdma_event_str
  600. */
  601. int rdma_get_cm_event(struct rdma_event_channel *channel,
  602. struct rdma_cm_event **event);
  603. /**
  604. * rdma_ack_cm_event - Free a communication event.
  605. * @event: Event to be released.
  606. * Description:
  607. * All events which are allocated by rdma_get_cm_event must be released,
  608. * there should be a one-to-one correspondence between successful gets
  609. * and acks.
  610. * See also:
  611. * rdma_get_cm_event, rdma_destroy_id
  612. */
  613. int rdma_ack_cm_event(struct rdma_cm_event *event);
  614. __be16 rdma_get_src_port(struct rdma_cm_id *id);
  615. __be16 rdma_get_dst_port(struct rdma_cm_id *id);
  616. static inline struct sockaddr *rdma_get_local_addr(struct rdma_cm_id *id)
  617. {
  618. return &id->route.addr.src_addr;
  619. }
  620. static inline struct sockaddr *rdma_get_peer_addr(struct rdma_cm_id *id)
  621. {
  622. return &id->route.addr.dst_addr;
  623. }
  624. /**
  625. * rdma_get_devices - Get list of RDMA devices currently available.
  626. * @num_devices: If non-NULL, set to the number of devices returned.
  627. * Description:
  628. * Return a NULL-terminated array of opened RDMA devices. Callers can use
  629. * this routine to allocate resources on specific RDMA devices that will be
  630. * shared across multiple rdma_cm_id's.
  631. * Notes:
  632. * The returned array must be released by calling rdma_free_devices. Devices
  633. * remain opened while the librdmacm is loaded.
  634. * See also:
  635. * rdma_free_devices
  636. */
  637. struct ibv_context **rdma_get_devices(int *num_devices);
  638. /**
  639. * rdma_free_devices - Frees the list of devices returned by rdma_get_devices.
  640. * @list: List of devices returned from rdma_get_devices.
  641. * Description:
  642. * Frees the device array returned by rdma_get_devices.
  643. * See also:
  644. * rdma_get_devices
  645. */
  646. void rdma_free_devices(struct ibv_context **list);
  647. /**
  648. * rdma_event_str - Returns a string representation of an rdma cm event.
  649. * @event: Asynchronous event.
  650. * Description:
  651. * Returns a string representation of an asynchronous event.
  652. * See also:
  653. * rdma_get_cm_event
  654. */
  655. const char *rdma_event_str(enum rdma_cm_event_type event);
  656. /* Option levels */
  657. enum {
  658. RDMA_OPTION_ID = 0,
  659. RDMA_OPTION_IB = 1
  660. };
  661. /* Option details */
  662. enum {
  663. RDMA_OPTION_ID_TOS = 0, /* uint8_t: RFC 2474 */
  664. RDMA_OPTION_ID_REUSEADDR = 1, /* int: ~SO_REUSEADDR */
  665. RDMA_OPTION_ID_AFONLY = 2, /* int: ~IPV6_V6ONLY */
  666. RDMA_OPTION_ID_ACK_TIMEOUT = 3 /* uint8_t */
  667. };
  668. enum {
  669. RDMA_OPTION_IB_PATH = 1 /* struct ibv_path_data[] */
  670. };
  671. /**
  672. * rdma_set_option - Set options for an rdma_cm_id.
  673. * @id: Communication identifier to set option for.
  674. * @level: Protocol level of the option to set.
  675. * @optname: Name of the option to set.
  676. * @optval: Reference to the option data.
  677. * @optlen: The size of the %optval buffer.
  678. */
  679. int rdma_set_option(struct rdma_cm_id *id, int level, int optname,
  680. void *optval, size_t optlen);
  681. /**
  682. * rdma_migrate_id - Move an rdma_cm_id to a new event channel.
  683. * @id: Communication identifier to migrate.
  684. * @channel: New event channel for rdma_cm_id events.
  685. */
  686. int rdma_migrate_id(struct rdma_cm_id *id, struct rdma_event_channel *channel);
  687. /**
  688. * rdma_getaddrinfo - RDMA address and route resolution service.
  689. */
  690. int rdma_getaddrinfo(const char *node, const char *service,
  691. const struct rdma_addrinfo *hints,
  692. struct rdma_addrinfo **res);
  693. void rdma_freeaddrinfo(struct rdma_addrinfo *res);
  694. /**
  695. * rdma_init_qp_attr - Returns QP attributes.
  696. * @id: Communication identifier.
  697. * @qp_attr: A reference to a QP attributes struct containing
  698. * response information.
  699. * @qp_attr_mask: A reference to a QP attributes mask containing
  700. * response information.
  701. */
  702. int rdma_init_qp_attr(struct rdma_cm_id *id, struct ibv_qp_attr *qp_attr,
  703. int *qp_attr_mask);
  704. /**
  705. * rdma_set_local_ece - Set local ECE options to be used for REQ/REP
  706. * communication. In use to implement ECE handshake in external QP.
  707. * @id: Communication identifier to establish connection
  708. * @ece: ECE parameters
  709. */
  710. int rdma_set_local_ece(struct rdma_cm_id *id, struct ibv_ece *ece);
  711. /**
  712. * rdma_get_remote_ece - Provide remote ECE parameters as received
  713. * in REQ/REP events. In use to implement ECE handshake in external QP.
  714. * @id: Communication identifier to establish connection
  715. * @ece: ECE parameters
  716. */
  717. int rdma_get_remote_ece(struct rdma_cm_id *id, struct ibv_ece *ece);
  718. #ifdef __cplusplus
  719. }
  720. #endif
  721. #endif /* RDMA_CMA_H */