Linux-2.6.12-rc2
[linux-2.6/next.git] / drivers / infiniband / include / ib_mad.h
blob4a6bf6763a97d4506e9b8e04b018cd01f217c4f9
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.
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
16 * conditions are met:
18 * - Redistributions of source code must retain the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer.
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
34 * SOFTWARE.
36 * $Id: ib_mad.h 1389 2004-12-27 22:56:47Z roland $
39 #if !defined( IB_MAD_H )
40 #define IB_MAD_H
42 #include <ib_verbs.h>
44 /* Management base version */
45 #define IB_MGMT_BASE_VERSION 1
47 /* Management classes */
48 #define IB_MGMT_CLASS_SUBN_LID_ROUTED 0x01
49 #define IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE 0x81
50 #define IB_MGMT_CLASS_SUBN_ADM 0x03
51 #define IB_MGMT_CLASS_PERF_MGMT 0x04
52 #define IB_MGMT_CLASS_BM 0x05
53 #define IB_MGMT_CLASS_DEVICE_MGMT 0x06
54 #define IB_MGMT_CLASS_CM 0x07
55 #define IB_MGMT_CLASS_SNMP 0x08
56 #define IB_MGMT_CLASS_VENDOR_RANGE2_START 0x30
57 #define IB_MGMT_CLASS_VENDOR_RANGE2_END 0x4F
59 /* Management methods */
60 #define IB_MGMT_METHOD_GET 0x01
61 #define IB_MGMT_METHOD_SET 0x02
62 #define IB_MGMT_METHOD_GET_RESP 0x81
63 #define IB_MGMT_METHOD_SEND 0x03
64 #define IB_MGMT_METHOD_TRAP 0x05
65 #define IB_MGMT_METHOD_REPORT 0x06
66 #define IB_MGMT_METHOD_REPORT_RESP 0x86
67 #define IB_MGMT_METHOD_TRAP_REPRESS 0x07
69 #define IB_MGMT_METHOD_RESP 0x80
71 #define IB_MGMT_MAX_METHODS 128
73 #define IB_QP0 0
74 #define IB_QP1 __constant_htonl(1)
75 #define IB_QP1_QKEY 0x80010000
77 struct ib_grh {
78 u32 version_tclass_flow;
79 u16 paylen;
80 u8 next_hdr;
81 u8 hop_limit;
82 union ib_gid sgid;
83 union ib_gid dgid;
84 } __attribute__ ((packed));
86 struct ib_mad_hdr {
87 u8 base_version;
88 u8 mgmt_class;
89 u8 class_version;
90 u8 method;
91 u16 status;
92 u16 class_specific;
93 u64 tid;
94 u16 attr_id;
95 u16 resv;
96 u32 attr_mod;
97 } __attribute__ ((packed));
99 struct ib_rmpp_hdr {
100 u8 rmpp_version;
101 u8 rmpp_type;
102 u8 rmpp_rtime_flags;
103 u8 rmpp_status;
104 u32 seg_num;
105 u32 paylen_newwin;
106 } __attribute__ ((packed));
108 struct ib_mad {
109 struct ib_mad_hdr mad_hdr;
110 u8 data[232];
111 } __attribute__ ((packed));
113 struct ib_rmpp_mad {
114 struct ib_mad_hdr mad_hdr;
115 struct ib_rmpp_hdr rmpp_hdr;
116 u8 data[220];
117 } __attribute__ ((packed));
119 struct ib_vendor_mad {
120 struct ib_mad_hdr mad_hdr;
121 struct ib_rmpp_hdr rmpp_hdr;
122 u8 reserved;
123 u8 oui[3];
124 u8 data[216];
125 } __attribute__ ((packed));
127 struct ib_mad_agent;
128 struct ib_mad_send_wc;
129 struct ib_mad_recv_wc;
132 * ib_mad_send_handler - callback handler for a sent MAD.
133 * @mad_agent: MAD agent that sent the MAD.
134 * @mad_send_wc: Send work completion information on the sent MAD.
136 typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent,
137 struct ib_mad_send_wc *mad_send_wc);
140 * ib_mad_snoop_handler - Callback handler for snooping sent MADs.
141 * @mad_agent: MAD agent that snooped the MAD.
142 * @send_wr: Work request information on the sent MAD.
143 * @mad_send_wc: Work completion information on the sent MAD. Valid
144 * only for snooping that occurs on a send completion.
146 * Clients snooping MADs should not modify data referenced by the @send_wr
147 * or @mad_send_wc.
149 typedef void (*ib_mad_snoop_handler)(struct ib_mad_agent *mad_agent,
150 struct ib_send_wr *send_wr,
151 struct ib_mad_send_wc *mad_send_wc);
154 * ib_mad_recv_handler - callback handler for a received MAD.
155 * @mad_agent: MAD agent requesting the received MAD.
156 * @mad_recv_wc: Received work completion information on the received MAD.
158 * MADs received in response to a send request operation will be handed to
159 * the user after the send operation completes. All data buffers given
160 * to registered agents through this routine are owned by the receiving
161 * client, except for snooping agents. Clients snooping MADs should not
162 * modify the data referenced by @mad_recv_wc.
164 typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,
165 struct ib_mad_recv_wc *mad_recv_wc);
168 * ib_mad_agent - Used to track MAD registration with the access layer.
169 * @device: Reference to device registration is on.
170 * @qp: Reference to QP used for sending and receiving MADs.
171 * @recv_handler: Callback handler for a received MAD.
172 * @send_handler: Callback handler for a sent MAD.
173 * @snoop_handler: Callback handler for snooped sent MADs.
174 * @context: User-specified context associated with this registration.
175 * @hi_tid: Access layer assigned transaction ID for this client.
176 * Unsolicited MADs sent by this client will have the upper 32-bits
177 * of their TID set to this value.
178 * @port_num: Port number on which QP is registered
180 struct ib_mad_agent {
181 struct ib_device *device;
182 struct ib_qp *qp;
183 ib_mad_recv_handler recv_handler;
184 ib_mad_send_handler send_handler;
185 ib_mad_snoop_handler snoop_handler;
186 void *context;
187 u32 hi_tid;
188 u8 port_num;
192 * ib_mad_send_wc - MAD send completion information.
193 * @wr_id: Work request identifier associated with the send MAD request.
194 * @status: Completion status.
195 * @vendor_err: Optional vendor error information returned with a failed
196 * request.
198 struct ib_mad_send_wc {
199 u64 wr_id;
200 enum ib_wc_status status;
201 u32 vendor_err;
205 * ib_mad_recv_buf - received MAD buffer information.
206 * @list: Reference to next data buffer for a received RMPP MAD.
207 * @grh: References a data buffer containing the global route header.
208 * The data refereced by this buffer is only valid if the GRH is
209 * valid.
210 * @mad: References the start of the received MAD.
212 struct ib_mad_recv_buf {
213 struct list_head list;
214 struct ib_grh *grh;
215 struct ib_mad *mad;
219 * ib_mad_recv_wc - received MAD information.
220 * @wc: Completion information for the received data.
221 * @recv_buf: Specifies the location of the received data buffer(s).
222 * @mad_len: The length of the received MAD, without duplicated headers.
224 * For received response, the wr_id field of the wc is set to the wr_id
225 * for the corresponding send request.
227 struct ib_mad_recv_wc {
228 struct ib_wc *wc;
229 struct ib_mad_recv_buf recv_buf;
230 int mad_len;
234 * ib_mad_reg_req - MAD registration request
235 * @mgmt_class: Indicates which management class of MADs should be receive
236 * by the caller. This field is only required if the user wishes to
237 * receive unsolicited MADs, otherwise it should be 0.
238 * @mgmt_class_version: Indicates which version of MADs for the given
239 * management class to receive.
240 * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
241 * in the range from 0x30 to 0x4f. Otherwise not used.
242 * @method_mask: The caller will receive unsolicited MADs for any method
243 * where @method_mask = 1.
245 struct ib_mad_reg_req {
246 u8 mgmt_class;
247 u8 mgmt_class_version;
248 u8 oui[3];
249 DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS);
253 * ib_register_mad_agent - Register to send/receive MADs.
254 * @device: The device to register with.
255 * @port_num: The port on the specified device to use.
256 * @qp_type: Specifies which QP to access. Must be either
257 * IB_QPT_SMI or IB_QPT_GSI.
258 * @mad_reg_req: Specifies which unsolicited MADs should be received
259 * by the caller. This parameter may be NULL if the caller only
260 * wishes to receive solicited responses.
261 * @rmpp_version: If set, indicates that the client will send
262 * and receive MADs that contain the RMPP header for the given version.
263 * If set to 0, indicates that RMPP is not used by this client.
264 * @send_handler: The completion callback routine invoked after a send
265 * request has completed.
266 * @recv_handler: The completion callback routine invoked for a received
267 * MAD.
268 * @context: User specified context associated with the registration.
270 struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
271 u8 port_num,
272 enum ib_qp_type qp_type,
273 struct ib_mad_reg_req *mad_reg_req,
274 u8 rmpp_version,
275 ib_mad_send_handler send_handler,
276 ib_mad_recv_handler recv_handler,
277 void *context);
279 enum ib_mad_snoop_flags {
280 /*IB_MAD_SNOOP_POSTED_SENDS = 1,*/
281 /*IB_MAD_SNOOP_RMPP_SENDS = (1<<1),*/
282 IB_MAD_SNOOP_SEND_COMPLETIONS = (1<<2),
283 /*IB_MAD_SNOOP_RMPP_SEND_COMPLETIONS = (1<<3),*/
284 IB_MAD_SNOOP_RECVS = (1<<4)
285 /*IB_MAD_SNOOP_RMPP_RECVS = (1<<5),*/
286 /*IB_MAD_SNOOP_REDIRECTED_QPS = (1<<6)*/
290 * ib_register_mad_snoop - Register to snoop sent and received MADs.
291 * @device: The device to register with.
292 * @port_num: The port on the specified device to use.
293 * @qp_type: Specifies which QP traffic to snoop. Must be either
294 * IB_QPT_SMI or IB_QPT_GSI.
295 * @mad_snoop_flags: Specifies information where snooping occurs.
296 * @send_handler: The callback routine invoked for a snooped send.
297 * @recv_handler: The callback routine invoked for a snooped receive.
298 * @context: User specified context associated with the registration.
300 struct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device,
301 u8 port_num,
302 enum ib_qp_type qp_type,
303 int mad_snoop_flags,
304 ib_mad_snoop_handler snoop_handler,
305 ib_mad_recv_handler recv_handler,
306 void *context);
309 * ib_unregister_mad_agent - Unregisters a client from using MAD services.
310 * @mad_agent: Corresponding MAD registration request to deregister.
312 * After invoking this routine, MAD services are no longer usable by the
313 * client on the associated QP.
315 int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);
318 * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated
319 * with the registered client.
320 * @mad_agent: Specifies the associated registration to post the send to.
321 * @send_wr: Specifies the information needed to send the MAD(s).
322 * @bad_send_wr: Specifies the MAD on which an error was encountered.
324 * Sent MADs are not guaranteed to complete in the order that they were posted.
326 int ib_post_send_mad(struct ib_mad_agent *mad_agent,
327 struct ib_send_wr *send_wr,
328 struct ib_send_wr **bad_send_wr);
331 * ib_coalesce_recv_mad - Coalesces received MAD data into a single buffer.
332 * @mad_recv_wc: Work completion information for a received MAD.
333 * @buf: User-provided data buffer to receive the coalesced buffers. The
334 * referenced buffer should be at least the size of the mad_len specified
335 * by @mad_recv_wc.
337 * This call copies a chain of received RMPP MADs into a single data buffer,
338 * removing duplicated headers.
340 void ib_coalesce_recv_mad(struct ib_mad_recv_wc *mad_recv_wc,
341 void *buf);
344 * ib_free_recv_mad - Returns data buffers used to receive a MAD to the
345 * access layer.
346 * @mad_recv_wc: Work completion information for a received MAD.
348 * Clients receiving MADs through their ib_mad_recv_handler must call this
349 * routine to return the work completion buffers to the access layer.
351 void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);
354 * ib_cancel_mad - Cancels an outstanding send MAD operation.
355 * @mad_agent: Specifies the registration associated with sent MAD.
356 * @wr_id: Indicates the work request identifier of the MAD to cancel.
358 * MADs will be returned to the user through the corresponding
359 * ib_mad_send_handler.
361 void ib_cancel_mad(struct ib_mad_agent *mad_agent,
362 u64 wr_id);
365 * ib_redirect_mad_qp - Registers a QP for MAD services.
366 * @qp: Reference to a QP that requires MAD services.
367 * @rmpp_version: If set, indicates that the client will send
368 * and receive MADs that contain the RMPP header for the given version.
369 * If set to 0, indicates that RMPP is not used by this client.
370 * @send_handler: The completion callback routine invoked after a send
371 * request has completed.
372 * @recv_handler: The completion callback routine invoked for a received
373 * MAD.
374 * @context: User specified context associated with the registration.
376 * Use of this call allows clients to use MAD services, such as RMPP,
377 * on user-owned QPs. After calling this routine, users may send
378 * MADs on the specified QP by calling ib_mad_post_send.
380 struct ib_mad_agent *ib_redirect_mad_qp(struct ib_qp *qp,
381 u8 rmpp_version,
382 ib_mad_send_handler send_handler,
383 ib_mad_recv_handler recv_handler,
384 void *context);
387 * ib_process_mad_wc - Processes a work completion associated with a
388 * MAD sent or received on a redirected QP.
389 * @mad_agent: Specifies the registered MAD service using the redirected QP.
390 * @wc: References a work completion associated with a sent or received
391 * MAD segment.
393 * This routine is used to complete or continue processing on a MAD request.
394 * If the work completion is associated with a send operation, calling
395 * this routine is required to continue an RMPP transfer or to wait for a
396 * corresponding response, if it is a request. If the work completion is
397 * associated with a receive operation, calling this routine is required to
398 * process an inbound or outbound RMPP transfer, or to match a response MAD
399 * with its corresponding request.
401 int ib_process_mad_wc(struct ib_mad_agent *mad_agent,
402 struct ib_wc *wc);
404 #endif /* IB_MAD_H */