iw_cm.h 8.6 KB

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