iw_cm.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
  2. /*
  3. * Copyright (c) 2005 Network Appliance, Inc. All rights reserved.
  4. * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
  5. */
  6. #ifndef IW_CM_H
  7. #define IW_CM_H
  8. #include <linux/in.h>
  9. #include <rdma/ib_cm.h>
  10. struct iw_cm_id;
  11. enum iw_cm_event_type {
  12. IW_CM_EVENT_CONNECT_REQUEST = 1, /* connect request received */
  13. IW_CM_EVENT_CONNECT_REPLY, /* reply from active connect request */
  14. IW_CM_EVENT_ESTABLISHED, /* passive side accept successful */
  15. IW_CM_EVENT_DISCONNECT, /* orderly shutdown */
  16. IW_CM_EVENT_CLOSE /* close complete */
  17. };
  18. struct iw_cm_event {
  19. enum iw_cm_event_type event;
  20. int status;
  21. struct sockaddr_storage local_addr;
  22. struct sockaddr_storage remote_addr;
  23. void *private_data;
  24. void *provider_data;
  25. u8 private_data_len;
  26. u8 ord;
  27. u8 ird;
  28. };
  29. /**
  30. * iw_cm_handler - Function to be called by the IW CM when delivering events
  31. * to the client.
  32. *
  33. * @cm_id: The IW CM identifier associated with the event.
  34. * @event: Pointer to the event structure.
  35. */
  36. typedef int (*iw_cm_handler)(struct iw_cm_id *cm_id,
  37. struct iw_cm_event *event);
  38. /**
  39. * iw_event_handler - Function called by the provider when delivering provider
  40. * events to the IW CM. Returns either 0 indicating the event was processed
  41. * or -errno if the event could not be processed.
  42. *
  43. * @cm_id: The IW CM identifier associated with the event.
  44. * @event: Pointer to the event structure.
  45. */
  46. typedef int (*iw_event_handler)(struct iw_cm_id *cm_id,
  47. struct iw_cm_event *event);
  48. struct iw_cm_id {
  49. iw_cm_handler cm_handler; /* client callback function */
  50. void *context; /* client cb context */
  51. struct ib_device *device;
  52. struct sockaddr_storage local_addr; /* local addr */
  53. struct sockaddr_storage remote_addr;
  54. struct sockaddr_storage m_local_addr; /* nmapped local addr */
  55. struct sockaddr_storage m_remote_addr; /* nmapped rem addr */
  56. void *provider_data; /* provider private data */
  57. iw_event_handler event_handler; /* cb for provider
  58. events */
  59. /* Used by provider to add and remove refs on IW cm_id */
  60. void (*add_ref)(struct iw_cm_id *);
  61. void (*rem_ref)(struct iw_cm_id *);
  62. u8 tos;
  63. bool tos_set:1;
  64. bool mapped:1;
  65. bool afonly:1;
  66. };
  67. struct iw_cm_conn_param {
  68. const void *private_data;
  69. u16 private_data_len;
  70. u32 ord;
  71. u32 ird;
  72. u32 qpn;
  73. };
  74. enum iw_flags {
  75. /*
  76. * This flag allows the iwcm and iwpmd to still advertise
  77. * mappings but the real and mapped port numbers are the
  78. * same. Further, iwpmd will not bind any user socket to
  79. * reserve the port. This is required for soft iwarp
  80. * to play in the port mapped iwarp space.
  81. */
  82. IW_F_NO_PORT_MAP = (1 << 0),
  83. };
  84. /**
  85. * iw_create_cm_id - Create an IW CM identifier.
  86. *
  87. * @device: The IB device on which to create the IW CM identier.
  88. * @event_handler: User callback invoked to report events associated with the
  89. * returned IW CM identifier.
  90. * @context: User specified context associated with the id.
  91. */
  92. struct iw_cm_id *iw_create_cm_id(struct ib_device *device,
  93. iw_cm_handler cm_handler, void *context);
  94. /**
  95. * iw_destroy_cm_id - Destroy an IW CM identifier.
  96. *
  97. * @cm_id: The previously created IW CM identifier to destroy.
  98. *
  99. * The client can assume that no events will be delivered for the CM ID after
  100. * this function returns.
  101. */
  102. void iw_destroy_cm_id(struct iw_cm_id *cm_id);
  103. /**
  104. * iw_cm_bind_qp - Unbind the specified IW CM identifier and QP
  105. *
  106. * @cm_id: The IW CM idenfier to unbind from the QP.
  107. * @qp: The QP
  108. *
  109. * This is called by the provider when destroying the QP to ensure
  110. * that any references held by the IWCM are released. It may also
  111. * be called by the IWCM when destroying a CM_ID to that any
  112. * references held by the provider are released.
  113. */
  114. void iw_cm_unbind_qp(struct iw_cm_id *cm_id, struct ib_qp *qp);
  115. /**
  116. * iw_cm_get_qp - Return the ib_qp associated with a QPN
  117. *
  118. * @ib_device: The IB device
  119. * @qpn: The queue pair number
  120. */
  121. struct ib_qp *iw_cm_get_qp(struct ib_device *device, int qpn);
  122. /**
  123. * iw_cm_listen - Listen for incoming connection requests on the
  124. * specified IW CM id.
  125. *
  126. * @cm_id: The IW CM identifier.
  127. * @backlog: The maximum number of outstanding un-accepted inbound listen
  128. * requests to queue.
  129. *
  130. * The source address and port number are specified in the IW CM identifier
  131. * structure.
  132. */
  133. int iw_cm_listen(struct iw_cm_id *cm_id, int backlog);
  134. /**
  135. * iw_cm_accept - Called to accept an incoming connect request.
  136. *
  137. * @cm_id: The IW CM identifier associated with the connection request.
  138. * @iw_param: Pointer to a structure containing connection establishment
  139. * parameters.
  140. *
  141. * The specified cm_id will have been provided in the event data for a
  142. * CONNECT_REQUEST event. Subsequent events related to this connection will be
  143. * delivered to the specified IW CM identifier prior and may occur prior to
  144. * the return of this function. If this function returns a non-zero value, the
  145. * client can assume that no events will be delivered to the specified IW CM
  146. * identifier.
  147. */
  148. int iw_cm_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param);
  149. /**
  150. * iw_cm_reject - Reject an incoming connection request.
  151. *
  152. * @cm_id: Connection identifier associated with the request.
  153. * @private_daa: Pointer to data to deliver to the remote peer as part of the
  154. * reject message.
  155. * @private_data_len: The number of bytes in the private_data parameter.
  156. *
  157. * The client can assume that no events will be delivered to the specified IW
  158. * CM identifier following the return of this function. The private_data
  159. * buffer is available for reuse when this function returns.
  160. */
  161. int iw_cm_reject(struct iw_cm_id *cm_id, const void *private_data,
  162. u8 private_data_len);
  163. /**
  164. * iw_cm_connect - Called to request a connection to a remote peer.
  165. *
  166. * @cm_id: The IW CM identifier for the connection.
  167. * @iw_param: Pointer to a structure containing connection establishment
  168. * parameters.
  169. *
  170. * Events may be delivered to the specified IW CM identifier prior to the
  171. * return of this function. If this function returns a non-zero value, the
  172. * client can assume that no events will be delivered to the specified IW CM
  173. * identifier.
  174. */
  175. int iw_cm_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param);
  176. /**
  177. * iw_cm_disconnect - Close the specified connection.
  178. *
  179. * @cm_id: The IW CM identifier to close.
  180. * @abrupt: If 0, the connection will be closed gracefully, otherwise, the
  181. * connection will be reset.
  182. *
  183. * The IW CM identifier is still active until the IW_CM_EVENT_CLOSE event is
  184. * delivered.
  185. */
  186. int iw_cm_disconnect(struct iw_cm_id *cm_id, int abrupt);
  187. /**
  188. * iw_cm_init_qp_attr - Called to initialize the attributes of the QP
  189. * associated with a IW CM identifier.
  190. *
  191. * @cm_id: The IW CM identifier associated with the QP
  192. * @qp_attr: Pointer to the QP attributes structure.
  193. * @qp_attr_mask: Pointer to a bit vector specifying which QP attributes are
  194. * valid.
  195. */
  196. int iw_cm_init_qp_attr(struct iw_cm_id *cm_id, struct ib_qp_attr *qp_attr,
  197. int *qp_attr_mask);
  198. /**
  199. * iwcm_reject_msg - return a pointer to a reject message string.
  200. * @reason: Value returned in the REJECT event status field.
  201. */
  202. const char *__attribute_const__ iwcm_reject_msg(int reason);
  203. #endif /* IW_CM_H */