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.
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:
14 * Redistribution and use in source and binary forms, with or
15 * without modification, are permitted provided that the following
18 * - Redistributions of source code must retain the above
19 * copyright notice, this list of conditions and the following
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.
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
36 * $Id: ib_mad.h 1389 2004-12-27 22:56:47Z roland $
39 #if !defined( IB_MAD_H )
42 #include <linux/pci.h>
46 /* Management base version */
47 #define IB_MGMT_BASE_VERSION 1
49 /* Management classes */
50 #define IB_MGMT_CLASS_SUBN_LID_ROUTED 0x01
51 #define IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE 0x81
52 #define IB_MGMT_CLASS_SUBN_ADM 0x03
53 #define IB_MGMT_CLASS_PERF_MGMT 0x04
54 #define IB_MGMT_CLASS_BM 0x05
55 #define IB_MGMT_CLASS_DEVICE_MGMT 0x06
56 #define IB_MGMT_CLASS_CM 0x07
57 #define IB_MGMT_CLASS_SNMP 0x08
58 #define IB_MGMT_CLASS_VENDOR_RANGE2_START 0x30
59 #define IB_MGMT_CLASS_VENDOR_RANGE2_END 0x4F
61 /* Management methods */
62 #define IB_MGMT_METHOD_GET 0x01
63 #define IB_MGMT_METHOD_SET 0x02
64 #define IB_MGMT_METHOD_GET_RESP 0x81
65 #define IB_MGMT_METHOD_SEND 0x03
66 #define IB_MGMT_METHOD_TRAP 0x05
67 #define IB_MGMT_METHOD_REPORT 0x06
68 #define IB_MGMT_METHOD_REPORT_RESP 0x86
69 #define IB_MGMT_METHOD_TRAP_REPRESS 0x07
71 #define IB_MGMT_METHOD_RESP 0x80
73 #define IB_MGMT_MAX_METHODS 128
76 #define IB_QP1 __constant_htonl(1)
77 #define IB_QP1_QKEY 0x80010000
78 #define IB_QP_SET_QKEY 0x80000000
81 u32 version_tclass_flow;
87 } __attribute__ ((packed));
100 } __attribute__ ((packed));
109 } __attribute__ ((packed));
112 struct ib_mad_hdr mad_hdr;
114 } __attribute__ ((packed));
117 struct ib_mad_hdr mad_hdr;
118 struct ib_rmpp_hdr rmpp_hdr;
120 } __attribute__ ((packed));
122 struct ib_vendor_mad {
123 struct ib_mad_hdr mad_hdr;
124 struct ib_rmpp_hdr rmpp_hdr;
128 } __attribute__ ((packed));
131 * ib_mad_send_buf - MAD data buffer and work request for sends.
132 * @mad: References an allocated MAD data buffer. The size of the data
133 * buffer is specified in the @send_wr.length field.
134 * @mapping: DMA mapping information.
135 * @mad_agent: MAD agent that allocated the buffer.
136 * @context: User-controlled context fields.
137 * @send_wr: An initialized work request structure used when sending the MAD.
138 * The wr_id field of the work request is initialized to reference this
140 * @sge: A scatter-gather list referenced by the work request.
142 * Users are responsible for initializing the MAD buffer itself, with the
143 * exception of specifying the payload length field in any RMPP MAD.
145 struct ib_mad_send_buf {
147 DECLARE_PCI_UNMAP_ADDR(mapping)
148 struct ib_mad_agent *mad_agent;
150 struct ib_send_wr send_wr;
155 struct ib_mad_send_wc;
156 struct ib_mad_recv_wc;
159 * ib_mad_send_handler - callback handler for a sent MAD.
160 * @mad_agent: MAD agent that sent the MAD.
161 * @mad_send_wc: Send work completion information on the sent MAD.
163 typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent,
164 struct ib_mad_send_wc *mad_send_wc);
167 * ib_mad_snoop_handler - Callback handler for snooping sent MADs.
168 * @mad_agent: MAD agent that snooped the MAD.
169 * @send_wr: Work request information on the sent MAD.
170 * @mad_send_wc: Work completion information on the sent MAD. Valid
171 * only for snooping that occurs on a send completion.
173 * Clients snooping MADs should not modify data referenced by the @send_wr
176 typedef void (*ib_mad_snoop_handler)(struct ib_mad_agent *mad_agent,
177 struct ib_send_wr *send_wr,
178 struct ib_mad_send_wc *mad_send_wc);
181 * ib_mad_recv_handler - callback handler for a received MAD.
182 * @mad_agent: MAD agent requesting the received MAD.
183 * @mad_recv_wc: Received work completion information on the received MAD.
185 * MADs received in response to a send request operation will be handed to
186 * the user after the send operation completes. All data buffers given
187 * to registered agents through this routine are owned by the receiving
188 * client, except for snooping agents. Clients snooping MADs should not
189 * modify the data referenced by @mad_recv_wc.
191 typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,
192 struct ib_mad_recv_wc *mad_recv_wc);
195 * ib_mad_agent - Used to track MAD registration with the access layer.
196 * @device: Reference to device registration is on.
197 * @qp: Reference to QP used for sending and receiving MADs.
198 * @recv_handler: Callback handler for a received MAD.
199 * @send_handler: Callback handler for a sent MAD.
200 * @snoop_handler: Callback handler for snooped sent MADs.
201 * @context: User-specified context associated with this registration.
202 * @hi_tid: Access layer assigned transaction ID for this client.
203 * Unsolicited MADs sent by this client will have the upper 32-bits
204 * of their TID set to this value.
205 * @port_num: Port number on which QP is registered
207 struct ib_mad_agent {
208 struct ib_device *device;
211 ib_mad_recv_handler recv_handler;
212 ib_mad_send_handler send_handler;
213 ib_mad_snoop_handler snoop_handler;
220 * ib_mad_send_wc - MAD send completion information.
221 * @wr_id: Work request identifier associated with the send MAD request.
222 * @status: Completion status.
223 * @vendor_err: Optional vendor error information returned with a failed
226 struct ib_mad_send_wc {
228 enum ib_wc_status status;
233 * ib_mad_recv_buf - received MAD buffer information.
234 * @list: Reference to next data buffer for a received RMPP MAD.
235 * @grh: References a data buffer containing the global route header.
236 * The data refereced by this buffer is only valid if the GRH is
238 * @mad: References the start of the received MAD.
240 struct ib_mad_recv_buf {
241 struct list_head list;
247 * ib_mad_recv_wc - received MAD information.
248 * @wc: Completion information for the received data.
249 * @recv_buf: Specifies the location of the received data buffer(s).
250 * @mad_len: The length of the received MAD, without duplicated headers.
252 * For received response, the wr_id field of the wc is set to the wr_id
253 * for the corresponding send request.
255 struct ib_mad_recv_wc {
257 struct ib_mad_recv_buf recv_buf;
262 * ib_mad_reg_req - MAD registration request
263 * @mgmt_class: Indicates which management class of MADs should be receive
264 * by the caller. This field is only required if the user wishes to
265 * receive unsolicited MADs, otherwise it should be 0.
266 * @mgmt_class_version: Indicates which version of MADs for the given
267 * management class to receive.
268 * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
269 * in the range from 0x30 to 0x4f. Otherwise not used.
270 * @method_mask: The caller will receive unsolicited MADs for any method
271 * where @method_mask = 1.
273 struct ib_mad_reg_req {
275 u8 mgmt_class_version;
277 DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS);
281 * ib_register_mad_agent - Register to send/receive MADs.
282 * @device: The device to register with.
283 * @port_num: The port on the specified device to use.
284 * @qp_type: Specifies which QP to access. Must be either
285 * IB_QPT_SMI or IB_QPT_GSI.
286 * @mad_reg_req: Specifies which unsolicited MADs should be received
287 * by the caller. This parameter may be NULL if the caller only
288 * wishes to receive solicited responses.
289 * @rmpp_version: If set, indicates that the client will send
290 * and receive MADs that contain the RMPP header for the given version.
291 * If set to 0, indicates that RMPP is not used by this client.
292 * @send_handler: The completion callback routine invoked after a send
293 * request has completed.
294 * @recv_handler: The completion callback routine invoked for a received
296 * @context: User specified context associated with the registration.
298 struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
300 enum ib_qp_type qp_type,
301 struct ib_mad_reg_req *mad_reg_req,
303 ib_mad_send_handler send_handler,
304 ib_mad_recv_handler recv_handler,
307 enum ib_mad_snoop_flags {
308 /*IB_MAD_SNOOP_POSTED_SENDS = 1,*/
309 /*IB_MAD_SNOOP_RMPP_SENDS = (1<<1),*/
310 IB_MAD_SNOOP_SEND_COMPLETIONS = (1<<2),
311 /*IB_MAD_SNOOP_RMPP_SEND_COMPLETIONS = (1<<3),*/
312 IB_MAD_SNOOP_RECVS = (1<<4)
313 /*IB_MAD_SNOOP_RMPP_RECVS = (1<<5),*/
314 /*IB_MAD_SNOOP_REDIRECTED_QPS = (1<<6)*/
318 * ib_register_mad_snoop - Register to snoop sent and received MADs.
319 * @device: The device to register with.
320 * @port_num: The port on the specified device to use.
321 * @qp_type: Specifies which QP traffic to snoop. Must be either
322 * IB_QPT_SMI or IB_QPT_GSI.
323 * @mad_snoop_flags: Specifies information where snooping occurs.
324 * @send_handler: The callback routine invoked for a snooped send.
325 * @recv_handler: The callback routine invoked for a snooped receive.
326 * @context: User specified context associated with the registration.
328 struct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device,
330 enum ib_qp_type qp_type,
332 ib_mad_snoop_handler snoop_handler,
333 ib_mad_recv_handler recv_handler,
337 * ib_unregister_mad_agent - Unregisters a client from using MAD services.
338 * @mad_agent: Corresponding MAD registration request to deregister.
340 * After invoking this routine, MAD services are no longer usable by the
341 * client on the associated QP.
343 int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);
346 * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated
347 * with the registered client.
348 * @mad_agent: Specifies the associated registration to post the send to.
349 * @send_wr: Specifies the information needed to send the MAD(s).
350 * @bad_send_wr: Specifies the MAD on which an error was encountered.
352 * Sent MADs are not guaranteed to complete in the order that they were posted.
354 int ib_post_send_mad(struct ib_mad_agent *mad_agent,
355 struct ib_send_wr *send_wr,
356 struct ib_send_wr **bad_send_wr);
359 * ib_coalesce_recv_mad - Coalesces received MAD data into a single buffer.
360 * @mad_recv_wc: Work completion information for a received MAD.
361 * @buf: User-provided data buffer to receive the coalesced buffers. The
362 * referenced buffer should be at least the size of the mad_len specified
365 * This call copies a chain of received RMPP MADs into a single data buffer,
366 * removing duplicated headers.
368 void ib_coalesce_recv_mad(struct ib_mad_recv_wc *mad_recv_wc, void *buf);
371 * ib_free_recv_mad - Returns data buffers used to receive a MAD to the
373 * @mad_recv_wc: Work completion information for a received MAD.
375 * Clients receiving MADs through their ib_mad_recv_handler must call this
376 * routine to return the work completion buffers to the access layer.
378 void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);
381 * ib_cancel_mad - Cancels an outstanding send MAD operation.
382 * @mad_agent: Specifies the registration associated with sent MAD.
383 * @wr_id: Indicates the work request identifier of the MAD to cancel.
385 * MADs will be returned to the user through the corresponding
386 * ib_mad_send_handler.
388 void ib_cancel_mad(struct ib_mad_agent *mad_agent, u64 wr_id);
391 * ib_modify_mad - Modifies an outstanding send MAD operation.
392 * @mad_agent: Specifies the registration associated with sent MAD.
393 * @wr_id: Indicates the work request identifier of the MAD to modify.
394 * @timeout_ms: New timeout value for sent MAD.
396 * This call will reset the timeout value for a sent MAD to the specified
399 int ib_modify_mad(struct ib_mad_agent *mad_agent, u64 wr_id, u32 timeout_ms);
402 * ib_redirect_mad_qp - Registers a QP for MAD services.
403 * @qp: Reference to a QP that requires MAD services.
404 * @rmpp_version: If set, indicates that the client will send
405 * and receive MADs that contain the RMPP header for the given version.
406 * If set to 0, indicates that RMPP is not used by this client.
407 * @send_handler: The completion callback routine invoked after a send
408 * request has completed.
409 * @recv_handler: The completion callback routine invoked for a received
411 * @context: User specified context associated with the registration.
413 * Use of this call allows clients to use MAD services, such as RMPP,
414 * on user-owned QPs. After calling this routine, users may send
415 * MADs on the specified QP by calling ib_mad_post_send.
417 struct ib_mad_agent *ib_redirect_mad_qp(struct ib_qp *qp,
419 ib_mad_send_handler send_handler,
420 ib_mad_recv_handler recv_handler,
424 * ib_process_mad_wc - Processes a work completion associated with a
425 * MAD sent or received on a redirected QP.
426 * @mad_agent: Specifies the registered MAD service using the redirected QP.
427 * @wc: References a work completion associated with a sent or received
430 * This routine is used to complete or continue processing on a MAD request.
431 * If the work completion is associated with a send operation, calling
432 * this routine is required to continue an RMPP transfer or to wait for a
433 * corresponding response, if it is a request. If the work completion is
434 * associated with a receive operation, calling this routine is required to
435 * process an inbound or outbound RMPP transfer, or to match a response MAD
436 * with its corresponding request.
438 int ib_process_mad_wc(struct ib_mad_agent *mad_agent,
442 * ib_create_send_mad - Allocate and initialize a data buffer and work request
444 * @mad_agent: Specifies the registered MAD service to associate with the MAD.
445 * @remote_qpn: Specifies the QPN of the receiving node.
446 * @pkey_index: Specifies which PKey the MAD will be sent using. This field
447 * is valid only if the remote_qpn is QP 1.
448 * @ah: References the address handle used to transfer to the remote node.
449 * @hdr_len: Indicates the size of the data header of the MAD. This length
450 * should include the common MAD header, RMPP header, plus any class
452 * @data_len: Indicates the size of any user-transfered data. The call will
453 * automatically adjust the allocated buffer size to account for any
454 * additional padding that may be necessary.
455 * @gfp_mask: GFP mask used for the memory allocation.
457 * This is a helper routine that may be used to allocate a MAD. Users are
458 * not required to allocate outbound MADs using this call. The returned
459 * MAD send buffer will reference a data buffer usable for sending a MAD, along
460 * with an intialized work request structure.
462 struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
463 u32 remote_qpn, u16 pkey_index,
465 int hdr_len, int data_len,
466 unsigned int __nocast gfp_mask);
469 * ib_free_send_mad - Returns data buffers used to send a MAD.
470 * @send_buf: Previously allocated send data buffer.
472 void ib_free_send_mad(struct ib_mad_send_buf *send_buf);
474 #endif /* IB_MAD_H */