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
91 } __attribute__ ((packed));
100 } __attribute__ ((packed));
103 struct ib_mad_hdr mad_hdr;
105 } __attribute__ ((packed));
108 struct ib_mad_hdr mad_hdr;
109 struct ib_rmpp_hdr rmpp_hdr;
111 } __attribute__ ((packed));
113 struct ib_vendor_mad {
114 struct ib_mad_hdr mad_hdr;
115 struct ib_rmpp_hdr rmpp_hdr;
119 } __attribute__ ((packed));
122 * ib_mad_send_buf - MAD data buffer and work request for sends.
123 * @mad: References an allocated MAD data buffer. The size of the data
124 * buffer is specified in the @send_wr.length field.
125 * @mapping: DMA mapping information.
126 * @mad_agent: MAD agent that allocated the buffer.
127 * @context: User-controlled context fields.
128 * @send_wr: An initialized work request structure used when sending the MAD.
129 * The wr_id field of the work request is initialized to reference this
131 * @sge: A scatter-gather list referenced by the work request.
133 * Users are responsible for initializing the MAD buffer itself, with the
134 * exception of specifying the payload length field in any RMPP MAD.
136 struct ib_mad_send_buf {
138 DECLARE_PCI_UNMAP_ADDR(mapping)
139 struct ib_mad_agent *mad_agent;
141 struct ib_send_wr send_wr;
146 struct ib_mad_send_wc;
147 struct ib_mad_recv_wc;
150 * ib_mad_send_handler - callback handler for a sent MAD.
151 * @mad_agent: MAD agent that sent the MAD.
152 * @mad_send_wc: Send work completion information on the sent MAD.
154 typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent,
155 struct ib_mad_send_wc *mad_send_wc);
158 * ib_mad_snoop_handler - Callback handler for snooping sent MADs.
159 * @mad_agent: MAD agent that snooped the MAD.
160 * @send_wr: Work request information on the sent MAD.
161 * @mad_send_wc: Work completion information on the sent MAD. Valid
162 * only for snooping that occurs on a send completion.
164 * Clients snooping MADs should not modify data referenced by the @send_wr
167 typedef void (*ib_mad_snoop_handler)(struct ib_mad_agent *mad_agent,
168 struct ib_send_wr *send_wr,
169 struct ib_mad_send_wc *mad_send_wc);
172 * ib_mad_recv_handler - callback handler for a received MAD.
173 * @mad_agent: MAD agent requesting the received MAD.
174 * @mad_recv_wc: Received work completion information on the received MAD.
176 * MADs received in response to a send request operation will be handed to
177 * the user after the send operation completes. All data buffers given
178 * to registered agents through this routine are owned by the receiving
179 * client, except for snooping agents. Clients snooping MADs should not
180 * modify the data referenced by @mad_recv_wc.
182 typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,
183 struct ib_mad_recv_wc *mad_recv_wc);
186 * ib_mad_agent - Used to track MAD registration with the access layer.
187 * @device: Reference to device registration is on.
188 * @qp: Reference to QP used for sending and receiving MADs.
189 * @recv_handler: Callback handler for a received MAD.
190 * @send_handler: Callback handler for a sent MAD.
191 * @snoop_handler: Callback handler for snooped sent MADs.
192 * @context: User-specified context associated with this registration.
193 * @hi_tid: Access layer assigned transaction ID for this client.
194 * Unsolicited MADs sent by this client will have the upper 32-bits
195 * of their TID set to this value.
196 * @port_num: Port number on which QP is registered
198 struct ib_mad_agent {
199 struct ib_device *device;
202 ib_mad_recv_handler recv_handler;
203 ib_mad_send_handler send_handler;
204 ib_mad_snoop_handler snoop_handler;
211 * ib_mad_send_wc - MAD send completion information.
212 * @wr_id: Work request identifier associated with the send MAD request.
213 * @status: Completion status.
214 * @vendor_err: Optional vendor error information returned with a failed
217 struct ib_mad_send_wc {
219 enum ib_wc_status status;
224 * ib_mad_recv_buf - received MAD buffer information.
225 * @list: Reference to next data buffer for a received RMPP MAD.
226 * @grh: References a data buffer containing the global route header.
227 * The data refereced by this buffer is only valid if the GRH is
229 * @mad: References the start of the received MAD.
231 struct ib_mad_recv_buf {
232 struct list_head list;
238 * ib_mad_recv_wc - received MAD information.
239 * @wc: Completion information for the received data.
240 * @recv_buf: Specifies the location of the received data buffer(s).
241 * @mad_len: The length of the received MAD, without duplicated headers.
243 * For received response, the wr_id field of the wc is set to the wr_id
244 * for the corresponding send request.
246 struct ib_mad_recv_wc {
248 struct ib_mad_recv_buf recv_buf;
253 * ib_mad_reg_req - MAD registration request
254 * @mgmt_class: Indicates which management class of MADs should be receive
255 * by the caller. This field is only required if the user wishes to
256 * receive unsolicited MADs, otherwise it should be 0.
257 * @mgmt_class_version: Indicates which version of MADs for the given
258 * management class to receive.
259 * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
260 * in the range from 0x30 to 0x4f. Otherwise not used.
261 * @method_mask: The caller will receive unsolicited MADs for any method
262 * where @method_mask = 1.
264 struct ib_mad_reg_req {
266 u8 mgmt_class_version;
268 DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS);
272 * ib_register_mad_agent - Register to send/receive MADs.
273 * @device: The device to register with.
274 * @port_num: The port on the specified device to use.
275 * @qp_type: Specifies which QP to access. Must be either
276 * IB_QPT_SMI or IB_QPT_GSI.
277 * @mad_reg_req: Specifies which unsolicited MADs should be received
278 * by the caller. This parameter may be NULL if the caller only
279 * wishes to receive solicited responses.
280 * @rmpp_version: If set, indicates that the client will send
281 * and receive MADs that contain the RMPP header for the given version.
282 * If set to 0, indicates that RMPP is not used by this client.
283 * @send_handler: The completion callback routine invoked after a send
284 * request has completed.
285 * @recv_handler: The completion callback routine invoked for a received
287 * @context: User specified context associated with the registration.
289 struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
291 enum ib_qp_type qp_type,
292 struct ib_mad_reg_req *mad_reg_req,
294 ib_mad_send_handler send_handler,
295 ib_mad_recv_handler recv_handler,
298 enum ib_mad_snoop_flags {
299 /*IB_MAD_SNOOP_POSTED_SENDS = 1,*/
300 /*IB_MAD_SNOOP_RMPP_SENDS = (1<<1),*/
301 IB_MAD_SNOOP_SEND_COMPLETIONS = (1<<2),
302 /*IB_MAD_SNOOP_RMPP_SEND_COMPLETIONS = (1<<3),*/
303 IB_MAD_SNOOP_RECVS = (1<<4)
304 /*IB_MAD_SNOOP_RMPP_RECVS = (1<<5),*/
305 /*IB_MAD_SNOOP_REDIRECTED_QPS = (1<<6)*/
309 * ib_register_mad_snoop - Register to snoop sent and received MADs.
310 * @device: The device to register with.
311 * @port_num: The port on the specified device to use.
312 * @qp_type: Specifies which QP traffic to snoop. Must be either
313 * IB_QPT_SMI or IB_QPT_GSI.
314 * @mad_snoop_flags: Specifies information where snooping occurs.
315 * @send_handler: The callback routine invoked for a snooped send.
316 * @recv_handler: The callback routine invoked for a snooped receive.
317 * @context: User specified context associated with the registration.
319 struct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device,
321 enum ib_qp_type qp_type,
323 ib_mad_snoop_handler snoop_handler,
324 ib_mad_recv_handler recv_handler,
328 * ib_unregister_mad_agent - Unregisters a client from using MAD services.
329 * @mad_agent: Corresponding MAD registration request to deregister.
331 * After invoking this routine, MAD services are no longer usable by the
332 * client on the associated QP.
334 int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);
337 * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated
338 * with the registered client.
339 * @mad_agent: Specifies the associated registration to post the send to.
340 * @send_wr: Specifies the information needed to send the MAD(s).
341 * @bad_send_wr: Specifies the MAD on which an error was encountered.
343 * Sent MADs are not guaranteed to complete in the order that they were posted.
345 int ib_post_send_mad(struct ib_mad_agent *mad_agent,
346 struct ib_send_wr *send_wr,
347 struct ib_send_wr **bad_send_wr);
350 * ib_coalesce_recv_mad - Coalesces received MAD data into a single buffer.
351 * @mad_recv_wc: Work completion information for a received MAD.
352 * @buf: User-provided data buffer to receive the coalesced buffers. The
353 * referenced buffer should be at least the size of the mad_len specified
356 * This call copies a chain of received RMPP MADs into a single data buffer,
357 * removing duplicated headers.
359 void ib_coalesce_recv_mad(struct ib_mad_recv_wc *mad_recv_wc, void *buf);
362 * ib_free_recv_mad - Returns data buffers used to receive a MAD to the
364 * @mad_recv_wc: Work completion information for a received MAD.
366 * Clients receiving MADs through their ib_mad_recv_handler must call this
367 * routine to return the work completion buffers to the access layer.
369 void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);
372 * ib_cancel_mad - Cancels an outstanding send MAD operation.
373 * @mad_agent: Specifies the registration associated with sent MAD.
374 * @wr_id: Indicates the work request identifier of the MAD to cancel.
376 * MADs will be returned to the user through the corresponding
377 * ib_mad_send_handler.
379 void ib_cancel_mad(struct ib_mad_agent *mad_agent, u64 wr_id);
382 * ib_modify_mad - Modifies an outstanding send MAD operation.
383 * @mad_agent: Specifies the registration associated with sent MAD.
384 * @wr_id: Indicates the work request identifier of the MAD to modify.
385 * @timeout_ms: New timeout value for sent MAD.
387 * This call will reset the timeout value for a sent MAD to the specified
390 int ib_modify_mad(struct ib_mad_agent *mad_agent, u64 wr_id, u32 timeout_ms);
393 * ib_redirect_mad_qp - Registers a QP for MAD services.
394 * @qp: Reference to a QP that requires MAD services.
395 * @rmpp_version: If set, indicates that the client will send
396 * and receive MADs that contain the RMPP header for the given version.
397 * If set to 0, indicates that RMPP is not used by this client.
398 * @send_handler: The completion callback routine invoked after a send
399 * request has completed.
400 * @recv_handler: The completion callback routine invoked for a received
402 * @context: User specified context associated with the registration.
404 * Use of this call allows clients to use MAD services, such as RMPP,
405 * on user-owned QPs. After calling this routine, users may send
406 * MADs on the specified QP by calling ib_mad_post_send.
408 struct ib_mad_agent *ib_redirect_mad_qp(struct ib_qp *qp,
410 ib_mad_send_handler send_handler,
411 ib_mad_recv_handler recv_handler,
415 * ib_process_mad_wc - Processes a work completion associated with a
416 * MAD sent or received on a redirected QP.
417 * @mad_agent: Specifies the registered MAD service using the redirected QP.
418 * @wc: References a work completion associated with a sent or received
421 * This routine is used to complete or continue processing on a MAD request.
422 * If the work completion is associated with a send operation, calling
423 * this routine is required to continue an RMPP transfer or to wait for a
424 * corresponding response, if it is a request. If the work completion is
425 * associated with a receive operation, calling this routine is required to
426 * process an inbound or outbound RMPP transfer, or to match a response MAD
427 * with its corresponding request.
429 int ib_process_mad_wc(struct ib_mad_agent *mad_agent,
433 * ib_create_send_mad - Allocate and initialize a data buffer and work request
435 * @mad_agent: Specifies the registered MAD service to associate with the MAD.
436 * @remote_qpn: Specifies the QPN of the receiving node.
437 * @pkey_index: Specifies which PKey the MAD will be sent using. This field
438 * is valid only if the remote_qpn is QP 1.
439 * @ah: References the address handle used to transfer to the remote node.
440 * @hdr_len: Indicates the size of the data header of the MAD. This length
441 * should include the common MAD header, RMPP header, plus any class
443 * @data_len: Indicates the size of any user-transfered data. The call will
444 * automatically adjust the allocated buffer size to account for any
445 * additional padding that may be necessary.
446 * @gfp_mask: GFP mask used for the memory allocation.
448 * This is a helper routine that may be used to allocate a MAD. Users are
449 * not required to allocate outbound MADs using this call. The returned
450 * MAD send buffer will reference a data buffer usable for sending a MAD, along
451 * with an intialized work request structure.
453 struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
454 u32 remote_qpn, u16 pkey_index,
456 int hdr_len, int data_len,
457 unsigned int __nocast gfp_mask);
460 * ib_free_send_mad - Returns data buffers used to send a MAD.
461 * @send_buf: Previously allocated send data buffer.
463 void ib_free_send_mad(struct ib_mad_send_buf *send_buf);
465 #endif /* IB_MAD_H */