Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | ||
39 | #if !defined( IB_MAD_H ) | |
40 | #define IB_MAD_H | |
41 | ||
824c8ae7 HR |
42 | #include <linux/pci.h> |
43 | ||
1da177e4 LT |
44 | #include <ib_verbs.h> |
45 | ||
46 | /* Management base version */ | |
47 | #define IB_MGMT_BASE_VERSION 1 | |
48 | ||
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 | |
60 | ||
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 | |
70 | ||
71 | #define IB_MGMT_METHOD_RESP 0x80 | |
72 | ||
73 | #define IB_MGMT_MAX_METHODS 128 | |
74 | ||
75 | #define IB_QP0 0 | |
76 | #define IB_QP1 __constant_htonl(1) | |
77 | #define IB_QP1_QKEY 0x80010000 | |
824c8ae7 | 78 | #define IB_QP_SET_QKEY 0x80000000 |
1da177e4 | 79 | |
1da177e4 LT |
80 | struct ib_mad_hdr { |
81 | u8 base_version; | |
82 | u8 mgmt_class; | |
83 | u8 class_version; | |
84 | u8 method; | |
85 | u16 status; | |
86 | u16 class_specific; | |
87 | u64 tid; | |
88 | u16 attr_id; | |
89 | u16 resv; | |
90 | u32 attr_mod; | |
91 | } __attribute__ ((packed)); | |
92 | ||
93 | struct ib_rmpp_hdr { | |
94 | u8 rmpp_version; | |
95 | u8 rmpp_type; | |
96 | u8 rmpp_rtime_flags; | |
97 | u8 rmpp_status; | |
98 | u32 seg_num; | |
99 | u32 paylen_newwin; | |
100 | } __attribute__ ((packed)); | |
101 | ||
102 | struct ib_mad { | |
103 | struct ib_mad_hdr mad_hdr; | |
104 | u8 data[232]; | |
105 | } __attribute__ ((packed)); | |
106 | ||
107 | struct ib_rmpp_mad { | |
108 | struct ib_mad_hdr mad_hdr; | |
109 | struct ib_rmpp_hdr rmpp_hdr; | |
110 | u8 data[220]; | |
111 | } __attribute__ ((packed)); | |
112 | ||
113 | struct ib_vendor_mad { | |
114 | struct ib_mad_hdr mad_hdr; | |
115 | struct ib_rmpp_hdr rmpp_hdr; | |
116 | u8 reserved; | |
117 | u8 oui[3]; | |
118 | u8 data[216]; | |
119 | } __attribute__ ((packed)); | |
120 | ||
824c8ae7 HR |
121 | /** |
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 | |
130 | * data structure. | |
131 | * @sge: A scatter-gather list referenced by the work request. | |
132 | * | |
133 | * Users are responsible for initializing the MAD buffer itself, with the | |
134 | * exception of specifying the payload length field in any RMPP MAD. | |
135 | */ | |
136 | struct ib_mad_send_buf { | |
137 | struct ib_mad *mad; | |
138 | DECLARE_PCI_UNMAP_ADDR(mapping) | |
139 | struct ib_mad_agent *mad_agent; | |
140 | void *context[2]; | |
141 | struct ib_send_wr send_wr; | |
142 | struct ib_sge sge; | |
143 | }; | |
144 | ||
1da177e4 LT |
145 | struct ib_mad_agent; |
146 | struct ib_mad_send_wc; | |
147 | struct ib_mad_recv_wc; | |
148 | ||
149 | /** | |
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. | |
153 | */ | |
154 | typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent, | |
155 | struct ib_mad_send_wc *mad_send_wc); | |
156 | ||
157 | /** | |
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. | |
163 | * | |
164 | * Clients snooping MADs should not modify data referenced by the @send_wr | |
165 | * or @mad_send_wc. | |
166 | */ | |
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); | |
170 | ||
171 | /** | |
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. | |
175 | * | |
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. | |
181 | */ | |
182 | typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent, | |
183 | struct ib_mad_recv_wc *mad_recv_wc); | |
184 | ||
185 | /** | |
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 | |
197 | */ | |
198 | struct ib_mad_agent { | |
199 | struct ib_device *device; | |
200 | struct ib_qp *qp; | |
b82cab6b | 201 | struct ib_mr *mr; |
1da177e4 LT |
202 | ib_mad_recv_handler recv_handler; |
203 | ib_mad_send_handler send_handler; | |
204 | ib_mad_snoop_handler snoop_handler; | |
205 | void *context; | |
206 | u32 hi_tid; | |
207 | u8 port_num; | |
208 | }; | |
209 | ||
210 | /** | |
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 | |
215 | * request. | |
216 | */ | |
217 | struct ib_mad_send_wc { | |
218 | u64 wr_id; | |
219 | enum ib_wc_status status; | |
220 | u32 vendor_err; | |
221 | }; | |
222 | ||
223 | /** | |
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 | |
228 | * valid. | |
229 | * @mad: References the start of the received MAD. | |
230 | */ | |
231 | struct ib_mad_recv_buf { | |
232 | struct list_head list; | |
233 | struct ib_grh *grh; | |
234 | struct ib_mad *mad; | |
235 | }; | |
236 | ||
237 | /** | |
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. | |
242 | * | |
243 | * For received response, the wr_id field of the wc is set to the wr_id | |
244 | * for the corresponding send request. | |
245 | */ | |
246 | struct ib_mad_recv_wc { | |
247 | struct ib_wc *wc; | |
248 | struct ib_mad_recv_buf recv_buf; | |
249 | int mad_len; | |
250 | }; | |
251 | ||
252 | /** | |
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. | |
263 | */ | |
264 | struct ib_mad_reg_req { | |
265 | u8 mgmt_class; | |
266 | u8 mgmt_class_version; | |
267 | u8 oui[3]; | |
268 | DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS); | |
269 | }; | |
270 | ||
271 | /** | |
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 | |
286 | * MAD. | |
287 | * @context: User specified context associated with the registration. | |
288 | */ | |
289 | struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device, | |
290 | u8 port_num, | |
291 | enum ib_qp_type qp_type, | |
292 | struct ib_mad_reg_req *mad_reg_req, | |
293 | u8 rmpp_version, | |
294 | ib_mad_send_handler send_handler, | |
295 | ib_mad_recv_handler recv_handler, | |
296 | void *context); | |
297 | ||
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)*/ | |
306 | }; | |
307 | ||
308 | /** | |
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. | |
318 | */ | |
319 | struct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device, | |
320 | u8 port_num, | |
321 | enum ib_qp_type qp_type, | |
322 | int mad_snoop_flags, | |
323 | ib_mad_snoop_handler snoop_handler, | |
324 | ib_mad_recv_handler recv_handler, | |
325 | void *context); | |
326 | ||
327 | /** | |
328 | * ib_unregister_mad_agent - Unregisters a client from using MAD services. | |
329 | * @mad_agent: Corresponding MAD registration request to deregister. | |
330 | * | |
331 | * After invoking this routine, MAD services are no longer usable by the | |
332 | * client on the associated QP. | |
333 | */ | |
334 | int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent); | |
335 | ||
336 | /** | |
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. | |
342 | * | |
343 | * Sent MADs are not guaranteed to complete in the order that they were posted. | |
344 | */ | |
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); | |
348 | ||
349 | /** | |
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 | |
354 | * by @mad_recv_wc. | |
355 | * | |
356 | * This call copies a chain of received RMPP MADs into a single data buffer, | |
357 | * removing duplicated headers. | |
358 | */ | |
df9f9ead | 359 | void ib_coalesce_recv_mad(struct ib_mad_recv_wc *mad_recv_wc, void *buf); |
1da177e4 LT |
360 | |
361 | /** | |
362 | * ib_free_recv_mad - Returns data buffers used to receive a MAD to the | |
363 | * access layer. | |
364 | * @mad_recv_wc: Work completion information for a received MAD. | |
365 | * | |
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. | |
368 | */ | |
369 | void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc); | |
370 | ||
371 | /** | |
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. | |
375 | * | |
376 | * MADs will be returned to the user through the corresponding | |
377 | * ib_mad_send_handler. | |
378 | */ | |
03b61ad2 HR |
379 | void ib_cancel_mad(struct ib_mad_agent *mad_agent, u64 wr_id); |
380 | ||
381 | /** | |
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. | |
386 | * | |
387 | * This call will reset the timeout value for a sent MAD to the specified | |
388 | * value. | |
389 | */ | |
390 | int ib_modify_mad(struct ib_mad_agent *mad_agent, u64 wr_id, u32 timeout_ms); | |
1da177e4 LT |
391 | |
392 | /** | |
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 | |
401 | * MAD. | |
402 | * @context: User specified context associated with the registration. | |
403 | * | |
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. | |
407 | */ | |
408 | struct ib_mad_agent *ib_redirect_mad_qp(struct ib_qp *qp, | |
409 | u8 rmpp_version, | |
410 | ib_mad_send_handler send_handler, | |
411 | ib_mad_recv_handler recv_handler, | |
412 | void *context); | |
413 | ||
414 | /** | |
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 | |
419 | * MAD segment. | |
420 | * | |
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. | |
428 | */ | |
429 | int ib_process_mad_wc(struct ib_mad_agent *mad_agent, | |
430 | struct ib_wc *wc); | |
431 | ||
824c8ae7 HR |
432 | /** |
433 | * ib_create_send_mad - Allocate and initialize a data buffer and work request | |
434 | * for sending a MAD. | |
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 | |
442 | * specific header. | |
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. | |
447 | * | |
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. | |
452 | */ | |
453 | struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent, | |
454 | u32 remote_qpn, u16 pkey_index, | |
455 | struct ib_ah *ah, | |
456 | int hdr_len, int data_len, | |
457 | unsigned int __nocast gfp_mask); | |
458 | ||
459 | /** | |
460 | * ib_free_send_mad - Returns data buffers used to send a MAD. | |
461 | * @send_buf: Previously allocated send data buffer. | |
462 | */ | |
463 | void ib_free_send_mad(struct ib_mad_send_buf *send_buf); | |
464 | ||
1da177e4 | 465 | #endif /* IB_MAD_H */ |