ib_mad.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /*
  2. * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
  3. * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
  4. * Copyright (c) 2004 Intel Corporation. All rights reserved.
  5. * Copyright (c) 2004 Topspin Corporation. All rights reserved.
  6. * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
  7. *
  8. * This software is available to you under a choice of one of two
  9. * licenses. You may choose to be licensed under the terms of the GNU
  10. * General Public License (GPL) Version 2, available from the file
  11. * COPYING in the main directory of this source tree, or the
  12. * OpenIB.org BSD license below:
  13. *
  14. * Redistribution and use in source and binary forms, with or
  15. * without modification, are permitted provided that the following
  16. * conditions are met:
  17. *
  18. * - Redistributions of source code must retain the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer.
  21. *
  22. * - Redistributions in binary form must reproduce the above
  23. * copyright notice, this list of conditions and the following
  24. * disclaimer in the documentation and/or other materials
  25. * provided with the distribution.
  26. *
  27. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  28. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  30. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  31. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  32. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  33. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  34. * SOFTWARE.
  35. *
  36. * $Id: ib_mad.h 1389 2004-12-27 22:56:47Z roland $
  37. */
  38. #if !defined( IB_MAD_H )
  39. #define IB_MAD_H
  40. #include <ib_verbs.h>
  41. /* Management base version */
  42. #define IB_MGMT_BASE_VERSION 1
  43. /* Management classes */
  44. #define IB_MGMT_CLASS_SUBN_LID_ROUTED 0x01
  45. #define IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE 0x81
  46. #define IB_MGMT_CLASS_SUBN_ADM 0x03
  47. #define IB_MGMT_CLASS_PERF_MGMT 0x04
  48. #define IB_MGMT_CLASS_BM 0x05
  49. #define IB_MGMT_CLASS_DEVICE_MGMT 0x06
  50. #define IB_MGMT_CLASS_CM 0x07
  51. #define IB_MGMT_CLASS_SNMP 0x08
  52. #define IB_MGMT_CLASS_VENDOR_RANGE2_START 0x30
  53. #define IB_MGMT_CLASS_VENDOR_RANGE2_END 0x4F
  54. /* Management methods */
  55. #define IB_MGMT_METHOD_GET 0x01
  56. #define IB_MGMT_METHOD_SET 0x02
  57. #define IB_MGMT_METHOD_GET_RESP 0x81
  58. #define IB_MGMT_METHOD_SEND 0x03
  59. #define IB_MGMT_METHOD_TRAP 0x05
  60. #define IB_MGMT_METHOD_REPORT 0x06
  61. #define IB_MGMT_METHOD_REPORT_RESP 0x86
  62. #define IB_MGMT_METHOD_TRAP_REPRESS 0x07
  63. #define IB_MGMT_METHOD_RESP 0x80
  64. #define IB_MGMT_MAX_METHODS 128
  65. #define IB_QP0 0
  66. #define IB_QP1 __constant_htonl(1)
  67. #define IB_QP1_QKEY 0x80010000
  68. struct ib_grh {
  69. u32 version_tclass_flow;
  70. u16 paylen;
  71. u8 next_hdr;
  72. u8 hop_limit;
  73. union ib_gid sgid;
  74. union ib_gid dgid;
  75. } __attribute__ ((packed));
  76. struct ib_mad_hdr {
  77. u8 base_version;
  78. u8 mgmt_class;
  79. u8 class_version;
  80. u8 method;
  81. u16 status;
  82. u16 class_specific;
  83. u64 tid;
  84. u16 attr_id;
  85. u16 resv;
  86. u32 attr_mod;
  87. } __attribute__ ((packed));
  88. struct ib_rmpp_hdr {
  89. u8 rmpp_version;
  90. u8 rmpp_type;
  91. u8 rmpp_rtime_flags;
  92. u8 rmpp_status;
  93. u32 seg_num;
  94. u32 paylen_newwin;
  95. } __attribute__ ((packed));
  96. struct ib_mad {
  97. struct ib_mad_hdr mad_hdr;
  98. u8 data[232];
  99. } __attribute__ ((packed));
  100. struct ib_rmpp_mad {
  101. struct ib_mad_hdr mad_hdr;
  102. struct ib_rmpp_hdr rmpp_hdr;
  103. u8 data[220];
  104. } __attribute__ ((packed));
  105. struct ib_vendor_mad {
  106. struct ib_mad_hdr mad_hdr;
  107. struct ib_rmpp_hdr rmpp_hdr;
  108. u8 reserved;
  109. u8 oui[3];
  110. u8 data[216];
  111. } __attribute__ ((packed));
  112. struct ib_mad_agent;
  113. struct ib_mad_send_wc;
  114. struct ib_mad_recv_wc;
  115. /**
  116. * ib_mad_send_handler - callback handler for a sent MAD.
  117. * @mad_agent: MAD agent that sent the MAD.
  118. * @mad_send_wc: Send work completion information on the sent MAD.
  119. */
  120. typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent,
  121. struct ib_mad_send_wc *mad_send_wc);
  122. /**
  123. * ib_mad_snoop_handler - Callback handler for snooping sent MADs.
  124. * @mad_agent: MAD agent that snooped the MAD.
  125. * @send_wr: Work request information on the sent MAD.
  126. * @mad_send_wc: Work completion information on the sent MAD. Valid
  127. * only for snooping that occurs on a send completion.
  128. *
  129. * Clients snooping MADs should not modify data referenced by the @send_wr
  130. * or @mad_send_wc.
  131. */
  132. typedef void (*ib_mad_snoop_handler)(struct ib_mad_agent *mad_agent,
  133. struct ib_send_wr *send_wr,
  134. struct ib_mad_send_wc *mad_send_wc);
  135. /**
  136. * ib_mad_recv_handler - callback handler for a received MAD.
  137. * @mad_agent: MAD agent requesting the received MAD.
  138. * @mad_recv_wc: Received work completion information on the received MAD.
  139. *
  140. * MADs received in response to a send request operation will be handed to
  141. * the user after the send operation completes. All data buffers given
  142. * to registered agents through this routine are owned by the receiving
  143. * client, except for snooping agents. Clients snooping MADs should not
  144. * modify the data referenced by @mad_recv_wc.
  145. */
  146. typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,
  147. struct ib_mad_recv_wc *mad_recv_wc);
  148. /**
  149. * ib_mad_agent - Used to track MAD registration with the access layer.
  150. * @device: Reference to device registration is on.
  151. * @qp: Reference to QP used for sending and receiving MADs.
  152. * @recv_handler: Callback handler for a received MAD.
  153. * @send_handler: Callback handler for a sent MAD.
  154. * @snoop_handler: Callback handler for snooped sent MADs.
  155. * @context: User-specified context associated with this registration.
  156. * @hi_tid: Access layer assigned transaction ID for this client.
  157. * Unsolicited MADs sent by this client will have the upper 32-bits
  158. * of their TID set to this value.
  159. * @port_num: Port number on which QP is registered
  160. */
  161. struct ib_mad_agent {
  162. struct ib_device *device;
  163. struct ib_qp *qp;
  164. ib_mad_recv_handler recv_handler;
  165. ib_mad_send_handler send_handler;
  166. ib_mad_snoop_handler snoop_handler;
  167. void *context;
  168. u32 hi_tid;
  169. u8 port_num;
  170. };
  171. /**
  172. * ib_mad_send_wc - MAD send completion information.
  173. * @wr_id: Work request identifier associated with the send MAD request.
  174. * @status: Completion status.
  175. * @vendor_err: Optional vendor error information returned with a failed
  176. * request.
  177. */
  178. struct ib_mad_send_wc {
  179. u64 wr_id;
  180. enum ib_wc_status status;
  181. u32 vendor_err;
  182. };
  183. /**
  184. * ib_mad_recv_buf - received MAD buffer information.
  185. * @list: Reference to next data buffer for a received RMPP MAD.
  186. * @grh: References a data buffer containing the global route header.
  187. * The data refereced by this buffer is only valid if the GRH is
  188. * valid.
  189. * @mad: References the start of the received MAD.
  190. */
  191. struct ib_mad_recv_buf {
  192. struct list_head list;
  193. struct ib_grh *grh;
  194. struct ib_mad *mad;
  195. };
  196. /**
  197. * ib_mad_recv_wc - received MAD information.
  198. * @wc: Completion information for the received data.
  199. * @recv_buf: Specifies the location of the received data buffer(s).
  200. * @mad_len: The length of the received MAD, without duplicated headers.
  201. *
  202. * For received response, the wr_id field of the wc is set to the wr_id
  203. * for the corresponding send request.
  204. */
  205. struct ib_mad_recv_wc {
  206. struct ib_wc *wc;
  207. struct ib_mad_recv_buf recv_buf;
  208. int mad_len;
  209. };
  210. /**
  211. * ib_mad_reg_req - MAD registration request
  212. * @mgmt_class: Indicates which management class of MADs should be receive
  213. * by the caller. This field is only required if the user wishes to
  214. * receive unsolicited MADs, otherwise it should be 0.
  215. * @mgmt_class_version: Indicates which version of MADs for the given
  216. * management class to receive.
  217. * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
  218. * in the range from 0x30 to 0x4f. Otherwise not used.
  219. * @method_mask: The caller will receive unsolicited MADs for any method
  220. * where @method_mask = 1.
  221. */
  222. struct ib_mad_reg_req {
  223. u8 mgmt_class;
  224. u8 mgmt_class_version;
  225. u8 oui[3];
  226. DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS);
  227. };
  228. /**
  229. * ib_register_mad_agent - Register to send/receive MADs.
  230. * @device: The device to register with.
  231. * @port_num: The port on the specified device to use.
  232. * @qp_type: Specifies which QP to access. Must be either
  233. * IB_QPT_SMI or IB_QPT_GSI.
  234. * @mad_reg_req: Specifies which unsolicited MADs should be received
  235. * by the caller. This parameter may be NULL if the caller only
  236. * wishes to receive solicited responses.
  237. * @rmpp_version: If set, indicates that the client will send
  238. * and receive MADs that contain the RMPP header for the given version.
  239. * If set to 0, indicates that RMPP is not used by this client.
  240. * @send_handler: The completion callback routine invoked after a send
  241. * request has completed.
  242. * @recv_handler: The completion callback routine invoked for a received
  243. * MAD.
  244. * @context: User specified context associated with the registration.
  245. */
  246. struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
  247. u8 port_num,
  248. enum ib_qp_type qp_type,
  249. struct ib_mad_reg_req *mad_reg_req,
  250. u8 rmpp_version,
  251. ib_mad_send_handler send_handler,
  252. ib_mad_recv_handler recv_handler,
  253. void *context);
  254. enum ib_mad_snoop_flags {
  255. /*IB_MAD_SNOOP_POSTED_SENDS = 1,*/
  256. /*IB_MAD_SNOOP_RMPP_SENDS = (1<<1),*/
  257. IB_MAD_SNOOP_SEND_COMPLETIONS = (1<<2),
  258. /*IB_MAD_SNOOP_RMPP_SEND_COMPLETIONS = (1<<3),*/
  259. IB_MAD_SNOOP_RECVS = (1<<4)
  260. /*IB_MAD_SNOOP_RMPP_RECVS = (1<<5),*/
  261. /*IB_MAD_SNOOP_REDIRECTED_QPS = (1<<6)*/
  262. };
  263. /**
  264. * ib_register_mad_snoop - Register to snoop sent and received MADs.
  265. * @device: The device to register with.
  266. * @port_num: The port on the specified device to use.
  267. * @qp_type: Specifies which QP traffic to snoop. Must be either
  268. * IB_QPT_SMI or IB_QPT_GSI.
  269. * @mad_snoop_flags: Specifies information where snooping occurs.
  270. * @send_handler: The callback routine invoked for a snooped send.
  271. * @recv_handler: The callback routine invoked for a snooped receive.
  272. * @context: User specified context associated with the registration.
  273. */
  274. struct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device,
  275. u8 port_num,
  276. enum ib_qp_type qp_type,
  277. int mad_snoop_flags,
  278. ib_mad_snoop_handler snoop_handler,
  279. ib_mad_recv_handler recv_handler,
  280. void *context);
  281. /**
  282. * ib_unregister_mad_agent - Unregisters a client from using MAD services.
  283. * @mad_agent: Corresponding MAD registration request to deregister.
  284. *
  285. * After invoking this routine, MAD services are no longer usable by the
  286. * client on the associated QP.
  287. */
  288. int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);
  289. /**
  290. * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated
  291. * with the registered client.
  292. * @mad_agent: Specifies the associated registration to post the send to.
  293. * @send_wr: Specifies the information needed to send the MAD(s).
  294. * @bad_send_wr: Specifies the MAD on which an error was encountered.
  295. *
  296. * Sent MADs are not guaranteed to complete in the order that they were posted.
  297. */
  298. int ib_post_send_mad(struct ib_mad_agent *mad_agent,
  299. struct ib_send_wr *send_wr,
  300. struct ib_send_wr **bad_send_wr);
  301. /**
  302. * ib_coalesce_recv_mad - Coalesces received MAD data into a single buffer.
  303. * @mad_recv_wc: Work completion information for a received MAD.
  304. * @buf: User-provided data buffer to receive the coalesced buffers. The
  305. * referenced buffer should be at least the size of the mad_len specified
  306. * by @mad_recv_wc.
  307. *
  308. * This call copies a chain of received RMPP MADs into a single data buffer,
  309. * removing duplicated headers.
  310. */
  311. void ib_coalesce_recv_mad(struct ib_mad_recv_wc *mad_recv_wc,
  312. void *buf);
  313. /**
  314. * ib_free_recv_mad - Returns data buffers used to receive a MAD to the
  315. * access layer.
  316. * @mad_recv_wc: Work completion information for a received MAD.
  317. *
  318. * Clients receiving MADs through their ib_mad_recv_handler must call this
  319. * routine to return the work completion buffers to the access layer.
  320. */
  321. void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);
  322. /**
  323. * ib_cancel_mad - Cancels an outstanding send MAD operation.
  324. * @mad_agent: Specifies the registration associated with sent MAD.
  325. * @wr_id: Indicates the work request identifier of the MAD to cancel.
  326. *
  327. * MADs will be returned to the user through the corresponding
  328. * ib_mad_send_handler.
  329. */
  330. void ib_cancel_mad(struct ib_mad_agent *mad_agent,
  331. u64 wr_id);
  332. /**
  333. * ib_redirect_mad_qp - Registers a QP for MAD services.
  334. * @qp: Reference to a QP that requires MAD services.
  335. * @rmpp_version: If set, indicates that the client will send
  336. * and receive MADs that contain the RMPP header for the given version.
  337. * If set to 0, indicates that RMPP is not used by this client.
  338. * @send_handler: The completion callback routine invoked after a send
  339. * request has completed.
  340. * @recv_handler: The completion callback routine invoked for a received
  341. * MAD.
  342. * @context: User specified context associated with the registration.
  343. *
  344. * Use of this call allows clients to use MAD services, such as RMPP,
  345. * on user-owned QPs. After calling this routine, users may send
  346. * MADs on the specified QP by calling ib_mad_post_send.
  347. */
  348. struct ib_mad_agent *ib_redirect_mad_qp(struct ib_qp *qp,
  349. u8 rmpp_version,
  350. ib_mad_send_handler send_handler,
  351. ib_mad_recv_handler recv_handler,
  352. void *context);
  353. /**
  354. * ib_process_mad_wc - Processes a work completion associated with a
  355. * MAD sent or received on a redirected QP.
  356. * @mad_agent: Specifies the registered MAD service using the redirected QP.
  357. * @wc: References a work completion associated with a sent or received
  358. * MAD segment.
  359. *
  360. * This routine is used to complete or continue processing on a MAD request.
  361. * If the work completion is associated with a send operation, calling
  362. * this routine is required to continue an RMPP transfer or to wait for a
  363. * corresponding response, if it is a request. If the work completion is
  364. * associated with a receive operation, calling this routine is required to
  365. * process an inbound or outbound RMPP transfer, or to match a response MAD
  366. * with its corresponding request.
  367. */
  368. int ib_process_mad_wc(struct ib_mad_agent *mad_agent,
  369. struct ib_wc *wc);
  370. #endif /* IB_MAD_H */