iw_cm.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. };
  66. struct iw_cm_conn_param {
  67. const void *private_data;
  68. u16 private_data_len;
  69. u32 ord;
  70. u32 ird;
  71. u32 qpn;
  72. };
  73. enum iw_flags {
  74. /*
  75. * This flag allows the iwcm and iwpmd to still advertise
  76. * mappings but the real and mapped port numbers are the
  77. * same. Further, iwpmd will not bind any user socket to
  78. * reserve the port. This is required for soft iwarp
  79. * to play in the port mapped iwarp space.
  80. */
  81. IW_F_NO_PORT_MAP = (1 << 0),
  82. };
  83. /**
  84. * iw_create_cm_id - Create an IW CM identifier.
  85. *
  86. * @device: The IB device on which to create the IW CM identier.
  87. * @event_handler: User callback invoked to report events associated with the
  88. * returned IW CM identifier.
  89. * @context: User specified context associated with the id.
  90. */
  91. struct iw_cm_id *iw_create_cm_id(struct ib_device *device,
  92. iw_cm_handler cm_handler, void *context);
  93. /**
  94. * iw_destroy_cm_id - Destroy an IW CM identifier.
  95. *
  96. * @cm_id: The previously created IW CM identifier to destroy.
  97. *
  98. * The client can assume that no events will be delivered for the CM ID after
  99. * this function returns.
  100. */
  101. void iw_destroy_cm_id(struct iw_cm_id *cm_id);
  102. /**
  103. * iw_cm_bind_qp - Unbind the specified IW CM identifier and QP
  104. *
  105. * @cm_id: The IW CM idenfier to unbind from the QP.
  106. * @qp: The QP
  107. *
  108. * This is called by the provider when destroying the QP to ensure
  109. * that any references held by the IWCM are released. It may also
  110. * be called by the IWCM when destroying a CM_ID to that any
  111. * references held by the provider are released.
  112. */
  113. void iw_cm_unbind_qp(struct iw_cm_id *cm_id, struct ib_qp *qp);
  114. /**
  115. * iw_cm_get_qp - Return the ib_qp associated with a QPN
  116. *
  117. * @ib_device: The IB device
  118. * @qpn: The queue pair number
  119. */
  120. struct ib_qp *iw_cm_get_qp(struct ib_device *device, int qpn);
  121. /**
  122. * iw_cm_listen - Listen for incoming connection requests on the
  123. * specified IW CM id.
  124. *
  125. * @cm_id: The IW CM identifier.
  126. * @backlog: The maximum number of outstanding un-accepted inbound listen
  127. * requests to queue.
  128. *
  129. * The source address and port number are specified in the IW CM identifier
  130. * structure.
  131. */
  132. int iw_cm_listen(struct iw_cm_id *cm_id, int backlog);
  133. /**
  134. * iw_cm_accept - Called to accept an incoming connect request.
  135. *
  136. * @cm_id: The IW CM identifier associated with the connection request.
  137. * @iw_param: Pointer to a structure containing connection establishment
  138. * parameters.
  139. *
  140. * The specified cm_id will have been provided in the event data for a
  141. * CONNECT_REQUEST event. Subsequent events related to this connection will be
  142. * delivered to the specified IW CM identifier prior and may occur prior to
  143. * the return of this function. If this function returns a non-zero value, the
  144. * client can assume that no events will be delivered to the specified IW CM
  145. * identifier.
  146. */
  147. int iw_cm_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param);
  148. /**
  149. * iw_cm_reject - Reject an incoming connection request.
  150. *
  151. * @cm_id: Connection identifier associated with the request.
  152. * @private_daa: Pointer to data to deliver to the remote peer as part of the
  153. * reject message.
  154. * @private_data_len: The number of bytes in the private_data parameter.
  155. *
  156. * The client can assume that no events will be delivered to the specified IW
  157. * CM identifier following the return of this function. The private_data
  158. * buffer is available for reuse when this function returns.
  159. */
  160. int iw_cm_reject(struct iw_cm_id *cm_id, const void *private_data,
  161. u8 private_data_len);
  162. /**
  163. * iw_cm_connect - Called to request a connection to a remote peer.
  164. *
  165. * @cm_id: The IW CM identifier for the connection.
  166. * @iw_param: Pointer to a structure containing connection establishment
  167. * parameters.
  168. *
  169. * Events may be delivered to the specified IW CM identifier prior to the
  170. * return of this function. If this function returns a non-zero value, the
  171. * client can assume that no events will be delivered to the specified IW CM
  172. * identifier.
  173. */
  174. int iw_cm_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param);
  175. /**
  176. * iw_cm_disconnect - Close the specified connection.
  177. *
  178. * @cm_id: The IW CM identifier to close.
  179. * @abrupt: If 0, the connection will be closed gracefully, otherwise, the
  180. * connection will be reset.
  181. *
  182. * The IW CM identifier is still active until the IW_CM_EVENT_CLOSE event is
  183. * delivered.
  184. */
  185. int iw_cm_disconnect(struct iw_cm_id *cm_id, int abrupt);
  186. /**
  187. * iw_cm_init_qp_attr - Called to initialize the attributes of the QP
  188. * associated with a IW CM identifier.
  189. *
  190. * @cm_id: The IW CM identifier associated with the QP
  191. * @qp_attr: Pointer to the QP attributes structure.
  192. * @qp_attr_mask: Pointer to a bit vector specifying which QP attributes are
  193. * valid.
  194. */
  195. int iw_cm_init_qp_attr(struct iw_cm_id *cm_id, struct ib_qp_attr *qp_attr,
  196. int *qp_attr_mask);
  197. /**
  198. * iwcm_reject_msg - return a pointer to a reject message string.
  199. * @reason: Value returned in the REJECT event status field.
  200. */
  201. const char *__attribute_const__ iwcm_reject_msg(int reason);
  202. #endif /* IW_CM_H */