ib_mad.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. struct ib_mr *mr;
  165. ib_mad_recv_handler recv_handler;
  166. ib_mad_send_handler send_handler;
  167. ib_mad_snoop_handler snoop_handler;
  168. void *context;
  169. u32 hi_tid;
  170. u8 port_num;
  171. };
  172. /**
  173. * ib_mad_send_wc - MAD send completion information.
  174. * @wr_id: Work request identifier associated with the send MAD request.
  175. * @status: Completion status.
  176. * @vendor_err: Optional vendor error information returned with a failed
  177. * request.
  178. */
  179. struct ib_mad_send_wc {
  180. u64 wr_id;
  181. enum ib_wc_status status;
  182. u32 vendor_err;
  183. };
  184. /**
  185. * ib_mad_recv_buf - received MAD buffer information.
  186. * @list: Reference to next data buffer for a received RMPP MAD.
  187. * @grh: References a data buffer containing the global route header.
  188. * The data refereced by this buffer is only valid if the GRH is
  189. * valid.
  190. * @mad: References the start of the received MAD.
  191. */
  192. struct ib_mad_recv_buf {
  193. struct list_head list;
  194. struct ib_grh *grh;
  195. struct ib_mad *mad;
  196. };
  197. /**
  198. * ib_mad_recv_wc - received MAD information.
  199. * @wc: Completion information for the received data.
  200. * @recv_buf: Specifies the location of the received data buffer(s).
  201. * @mad_len: The length of the received MAD, without duplicated headers.
  202. *
  203. * For received response, the wr_id field of the wc is set to the wr_id
  204. * for the corresponding send request.
  205. */
  206. struct ib_mad_recv_wc {
  207. struct ib_wc *wc;
  208. struct ib_mad_recv_buf recv_buf;
  209. int mad_len;
  210. };
  211. /**
  212. * ib_mad_reg_req - MAD registration request
  213. * @mgmt_class: Indicates which management class of MADs should be receive
  214. * by the caller. This field is only required if the user wishes to
  215. * receive unsolicited MADs, otherwise it should be 0.
  216. * @mgmt_class_version: Indicates which version of MADs for the given
  217. * management class to receive.
  218. * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
  219. * in the range from 0x30 to 0x4f. Otherwise not used.
  220. * @method_mask: The caller will receive unsolicited MADs for any method
  221. * where @method_mask = 1.
  222. */
  223. struct ib_mad_reg_req {
  224. u8 mgmt_class;
  225. u8 mgmt_class_version;
  226. u8 oui[3];
  227. DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS);
  228. };
  229. /**
  230. * ib_register_mad_agent - Register to send/receive MADs.
  231. * @device: The device to register with.
  232. * @port_num: The port on the specified device to use.
  233. * @qp_type: Specifies which QP to access. Must be either
  234. * IB_QPT_SMI or IB_QPT_GSI.
  235. * @mad_reg_req: Specifies which unsolicited MADs should be received
  236. * by the caller. This parameter may be NULL if the caller only
  237. * wishes to receive solicited responses.
  238. * @rmpp_version: If set, indicates that the client will send
  239. * and receive MADs that contain the RMPP header for the given version.
  240. * If set to 0, indicates that RMPP is not used by this client.
  241. * @send_handler: The completion callback routine invoked after a send
  242. * request has completed.
  243. * @recv_handler: The completion callback routine invoked for a received
  244. * MAD.
  245. * @context: User specified context associated with the registration.
  246. */
  247. struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
  248. u8 port_num,
  249. enum ib_qp_type qp_type,
  250. struct ib_mad_reg_req *mad_reg_req,
  251. u8 rmpp_version,
  252. ib_mad_send_handler send_handler,
  253. ib_mad_recv_handler recv_handler,
  254. void *context);
  255. enum ib_mad_snoop_flags {
  256. /*IB_MAD_SNOOP_POSTED_SENDS = 1,*/
  257. /*IB_MAD_SNOOP_RMPP_SENDS = (1<<1),*/
  258. IB_MAD_SNOOP_SEND_COMPLETIONS = (1<<2),
  259. /*IB_MAD_SNOOP_RMPP_SEND_COMPLETIONS = (1<<3),*/
  260. IB_MAD_SNOOP_RECVS = (1<<4)
  261. /*IB_MAD_SNOOP_RMPP_RECVS = (1<<5),*/
  262. /*IB_MAD_SNOOP_REDIRECTED_QPS = (1<<6)*/
  263. };
  264. /**
  265. * ib_register_mad_snoop - Register to snoop sent and received MADs.
  266. * @device: The device to register with.
  267. * @port_num: The port on the specified device to use.
  268. * @qp_type: Specifies which QP traffic to snoop. Must be either
  269. * IB_QPT_SMI or IB_QPT_GSI.
  270. * @mad_snoop_flags: Specifies information where snooping occurs.
  271. * @send_handler: The callback routine invoked for a snooped send.
  272. * @recv_handler: The callback routine invoked for a snooped receive.
  273. * @context: User specified context associated with the registration.
  274. */
  275. struct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device,
  276. u8 port_num,
  277. enum ib_qp_type qp_type,
  278. int mad_snoop_flags,
  279. ib_mad_snoop_handler snoop_handler,
  280. ib_mad_recv_handler recv_handler,
  281. void *context);
  282. /**
  283. * ib_unregister_mad_agent - Unregisters a client from using MAD services.
  284. * @mad_agent: Corresponding MAD registration request to deregister.
  285. *
  286. * After invoking this routine, MAD services are no longer usable by the
  287. * client on the associated QP.
  288. */
  289. int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);
  290. /**
  291. * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated
  292. * with the registered client.
  293. * @mad_agent: Specifies the associated registration to post the send to.
  294. * @send_wr: Specifies the information needed to send the MAD(s).
  295. * @bad_send_wr: Specifies the MAD on which an error was encountered.
  296. *
  297. * Sent MADs are not guaranteed to complete in the order that they were posted.
  298. */
  299. int ib_post_send_mad(struct ib_mad_agent *mad_agent,
  300. struct ib_send_wr *send_wr,
  301. struct ib_send_wr **bad_send_wr);
  302. /**
  303. * ib_coalesce_recv_mad - Coalesces received MAD data into a single buffer.
  304. * @mad_recv_wc: Work completion information for a received MAD.
  305. * @buf: User-provided data buffer to receive the coalesced buffers. The
  306. * referenced buffer should be at least the size of the mad_len specified
  307. * by @mad_recv_wc.
  308. *
  309. * This call copies a chain of received RMPP MADs into a single data buffer,
  310. * removing duplicated headers.
  311. */
  312. void ib_coalesce_recv_mad(struct ib_mad_recv_wc *mad_recv_wc,
  313. void *buf);
  314. /**
  315. * ib_free_recv_mad - Returns data buffers used to receive a MAD to the
  316. * access layer.
  317. * @mad_recv_wc: Work completion information for a received MAD.
  318. *
  319. * Clients receiving MADs through their ib_mad_recv_handler must call this
  320. * routine to return the work completion buffers to the access layer.
  321. */
  322. void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);
  323. /**
  324. * ib_cancel_mad - Cancels an outstanding send MAD operation.
  325. * @mad_agent: Specifies the registration associated with sent MAD.
  326. * @wr_id: Indicates the work request identifier of the MAD to cancel.
  327. *
  328. * MADs will be returned to the user through the corresponding
  329. * ib_mad_send_handler.
  330. */
  331. void ib_cancel_mad(struct ib_mad_agent *mad_agent,
  332. u64 wr_id);
  333. /**
  334. * ib_redirect_mad_qp - Registers a QP for MAD services.
  335. * @qp: Reference to a QP that requires MAD services.
  336. * @rmpp_version: If set, indicates that the client will send
  337. * and receive MADs that contain the RMPP header for the given version.
  338. * If set to 0, indicates that RMPP is not used by this client.
  339. * @send_handler: The completion callback routine invoked after a send
  340. * request has completed.
  341. * @recv_handler: The completion callback routine invoked for a received
  342. * MAD.
  343. * @context: User specified context associated with the registration.
  344. *
  345. * Use of this call allows clients to use MAD services, such as RMPP,
  346. * on user-owned QPs. After calling this routine, users may send
  347. * MADs on the specified QP by calling ib_mad_post_send.
  348. */
  349. struct ib_mad_agent *ib_redirect_mad_qp(struct ib_qp *qp,
  350. u8 rmpp_version,
  351. ib_mad_send_handler send_handler,
  352. ib_mad_recv_handler recv_handler,
  353. void *context);
  354. /**
  355. * ib_process_mad_wc - Processes a work completion associated with a
  356. * MAD sent or received on a redirected QP.
  357. * @mad_agent: Specifies the registered MAD service using the redirected QP.
  358. * @wc: References a work completion associated with a sent or received
  359. * MAD segment.
  360. *
  361. * This routine is used to complete or continue processing on a MAD request.
  362. * If the work completion is associated with a send operation, calling
  363. * this routine is required to continue an RMPP transfer or to wait for a
  364. * corresponding response, if it is a request. If the work completion is
  365. * associated with a receive operation, calling this routine is required to
  366. * process an inbound or outbound RMPP transfer, or to match a response MAD
  367. * with its corresponding request.
  368. */
  369. int ib_process_mad_wc(struct ib_mad_agent *mad_agent,
  370. struct ib_wc *wc);
  371. #endif /* IB_MAD_H */