| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
 | 42 | #include <ib_verbs.h> | 
 | 43 |  | 
 | 44 | /* Management base version */ | 
 | 45 | #define IB_MGMT_BASE_VERSION			1 | 
 | 46 |  | 
 | 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 | 
 | 58 |  | 
 | 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 | 
 | 68 |  | 
 | 69 | #define IB_MGMT_METHOD_RESP			0x80 | 
 | 70 |  | 
 | 71 | #define IB_MGMT_MAX_METHODS			128 | 
 | 72 |  | 
 | 73 | #define IB_QP0		0 | 
 | 74 | #define IB_QP1		__constant_htonl(1) | 
 | 75 | #define IB_QP1_QKEY	0x80010000 | 
 | 76 |  | 
 | 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)); | 
 | 85 |  | 
 | 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)); | 
 | 98 |  | 
 | 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)); | 
 | 107 |  | 
 | 108 | struct ib_mad { | 
 | 109 | 	struct ib_mad_hdr	mad_hdr; | 
 | 110 | 	u8			data[232]; | 
 | 111 | } __attribute__ ((packed)); | 
 | 112 |  | 
 | 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)); | 
 | 118 |  | 
 | 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)); | 
 | 126 |  | 
 | 127 | struct ib_mad_agent; | 
 | 128 | struct ib_mad_send_wc; | 
 | 129 | struct ib_mad_recv_wc; | 
 | 130 |  | 
 | 131 | /** | 
 | 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. | 
 | 135 |  */ | 
 | 136 | typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent, | 
 | 137 | 				    struct ib_mad_send_wc *mad_send_wc); | 
 | 138 |  | 
 | 139 | /** | 
 | 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. | 
 | 145 |  * | 
 | 146 |  * Clients snooping MADs should not modify data referenced by the @send_wr | 
 | 147 |  * or @mad_send_wc. | 
 | 148 |  */ | 
 | 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); | 
 | 152 |  | 
 | 153 | /** | 
 | 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. | 
 | 157 |  * | 
 | 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. | 
 | 163 |  */ | 
 | 164 | typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent, | 
 | 165 | 				    struct ib_mad_recv_wc *mad_recv_wc); | 
 | 166 |  | 
 | 167 | /** | 
 | 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 | 
 | 179 |  */ | 
 | 180 | struct ib_mad_agent { | 
 | 181 | 	struct ib_device	*device; | 
 | 182 | 	struct ib_qp		*qp; | 
| Hal Rosenstock | b82cab6 | 2005-07-27 11:45:22 -0700 | [diff] [blame^] | 183 | 	struct ib_mr		*mr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | 	ib_mad_recv_handler	recv_handler; | 
 | 185 | 	ib_mad_send_handler	send_handler; | 
 | 186 | 	ib_mad_snoop_handler	snoop_handler; | 
 | 187 | 	void			*context; | 
 | 188 | 	u32			hi_tid; | 
 | 189 | 	u8			port_num; | 
 | 190 | }; | 
 | 191 |  | 
 | 192 | /** | 
 | 193 |  * ib_mad_send_wc - MAD send completion information. | 
 | 194 |  * @wr_id: Work request identifier associated with the send MAD request. | 
 | 195 |  * @status: Completion status. | 
 | 196 |  * @vendor_err: Optional vendor error information returned with a failed | 
 | 197 |  *   request. | 
 | 198 |  */ | 
 | 199 | struct ib_mad_send_wc { | 
 | 200 | 	u64			wr_id; | 
 | 201 | 	enum ib_wc_status	status; | 
 | 202 | 	u32			vendor_err; | 
 | 203 | }; | 
 | 204 |  | 
 | 205 | /** | 
 | 206 |  * ib_mad_recv_buf - received MAD buffer information. | 
 | 207 |  * @list: Reference to next data buffer for a received RMPP MAD. | 
 | 208 |  * @grh: References a data buffer containing the global route header. | 
 | 209 |  *   The data refereced by this buffer is only valid if the GRH is | 
 | 210 |  *   valid. | 
 | 211 |  * @mad: References the start of the received MAD. | 
 | 212 |  */ | 
 | 213 | struct ib_mad_recv_buf { | 
 | 214 | 	struct list_head	list; | 
 | 215 | 	struct ib_grh		*grh; | 
 | 216 | 	struct ib_mad		*mad; | 
 | 217 | }; | 
 | 218 |  | 
 | 219 | /** | 
 | 220 |  * ib_mad_recv_wc - received MAD information. | 
 | 221 |  * @wc: Completion information for the received data. | 
 | 222 |  * @recv_buf: Specifies the location of the received data buffer(s). | 
 | 223 |  * @mad_len: The length of the received MAD, without duplicated headers. | 
 | 224 |  * | 
 | 225 |  * For received response, the wr_id field of the wc is set to the wr_id | 
 | 226 |  *   for the corresponding send request. | 
 | 227 |  */ | 
 | 228 | struct ib_mad_recv_wc { | 
 | 229 | 	struct ib_wc		*wc; | 
 | 230 | 	struct ib_mad_recv_buf	recv_buf; | 
 | 231 | 	int			mad_len; | 
 | 232 | }; | 
 | 233 |  | 
 | 234 | /** | 
 | 235 |  * ib_mad_reg_req - MAD registration request | 
 | 236 |  * @mgmt_class: Indicates which management class of MADs should be receive | 
 | 237 |  *   by the caller.  This field is only required if the user wishes to | 
 | 238 |  *   receive unsolicited MADs, otherwise it should be 0. | 
 | 239 |  * @mgmt_class_version: Indicates which version of MADs for the given | 
 | 240 |  *   management class to receive. | 
 | 241 |  * @oui: Indicates IEEE OUI when mgmt_class is a vendor class | 
 | 242 |  *   in the range from 0x30 to 0x4f. Otherwise not used. | 
 | 243 |  * @method_mask: The caller will receive unsolicited MADs for any method | 
 | 244 |  *   where @method_mask = 1. | 
 | 245 |  */ | 
 | 246 | struct ib_mad_reg_req { | 
 | 247 | 	u8	mgmt_class; | 
 | 248 | 	u8	mgmt_class_version; | 
 | 249 | 	u8	oui[3]; | 
 | 250 | 	DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS); | 
 | 251 | }; | 
 | 252 |  | 
 | 253 | /** | 
 | 254 |  * ib_register_mad_agent - Register to send/receive MADs. | 
 | 255 |  * @device: The device to register with. | 
 | 256 |  * @port_num: The port on the specified device to use. | 
 | 257 |  * @qp_type: Specifies which QP to access.  Must be either | 
 | 258 |  *   IB_QPT_SMI or IB_QPT_GSI. | 
 | 259 |  * @mad_reg_req: Specifies which unsolicited MADs should be received | 
 | 260 |  *   by the caller.  This parameter may be NULL if the caller only | 
 | 261 |  *   wishes to receive solicited responses. | 
 | 262 |  * @rmpp_version: If set, indicates that the client will send | 
 | 263 |  *   and receive MADs that contain the RMPP header for the given version. | 
 | 264 |  *   If set to 0, indicates that RMPP is not used by this client. | 
 | 265 |  * @send_handler: The completion callback routine invoked after a send | 
 | 266 |  *   request has completed. | 
 | 267 |  * @recv_handler: The completion callback routine invoked for a received | 
 | 268 |  *   MAD. | 
 | 269 |  * @context: User specified context associated with the registration. | 
 | 270 |  */ | 
 | 271 | struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device, | 
 | 272 | 					   u8 port_num, | 
 | 273 | 					   enum ib_qp_type qp_type, | 
 | 274 | 					   struct ib_mad_reg_req *mad_reg_req, | 
 | 275 | 					   u8 rmpp_version, | 
 | 276 | 					   ib_mad_send_handler send_handler, | 
 | 277 | 					   ib_mad_recv_handler recv_handler, | 
 | 278 | 					   void *context); | 
 | 279 |  | 
 | 280 | enum ib_mad_snoop_flags { | 
 | 281 | 	/*IB_MAD_SNOOP_POSTED_SENDS	   = 1,*/ | 
 | 282 | 	/*IB_MAD_SNOOP_RMPP_SENDS	   = (1<<1),*/ | 
 | 283 | 	IB_MAD_SNOOP_SEND_COMPLETIONS	   = (1<<2), | 
 | 284 | 	/*IB_MAD_SNOOP_RMPP_SEND_COMPLETIONS = (1<<3),*/ | 
 | 285 | 	IB_MAD_SNOOP_RECVS		   = (1<<4) | 
 | 286 | 	/*IB_MAD_SNOOP_RMPP_RECVS	   = (1<<5),*/ | 
 | 287 | 	/*IB_MAD_SNOOP_REDIRECTED_QPS	   = (1<<6)*/ | 
 | 288 | }; | 
 | 289 |  | 
 | 290 | /** | 
 | 291 |  * ib_register_mad_snoop - Register to snoop sent and received MADs. | 
 | 292 |  * @device: The device to register with. | 
 | 293 |  * @port_num: The port on the specified device to use. | 
 | 294 |  * @qp_type: Specifies which QP traffic to snoop.  Must be either | 
 | 295 |  *   IB_QPT_SMI or IB_QPT_GSI. | 
 | 296 |  * @mad_snoop_flags: Specifies information where snooping occurs. | 
 | 297 |  * @send_handler: The callback routine invoked for a snooped send. | 
 | 298 |  * @recv_handler: The callback routine invoked for a snooped receive. | 
 | 299 |  * @context: User specified context associated with the registration. | 
 | 300 |  */ | 
 | 301 | struct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device, | 
 | 302 | 					   u8 port_num, | 
 | 303 | 					   enum ib_qp_type qp_type, | 
 | 304 | 					   int mad_snoop_flags, | 
 | 305 | 					   ib_mad_snoop_handler snoop_handler, | 
 | 306 | 					   ib_mad_recv_handler recv_handler, | 
 | 307 | 					   void *context); | 
 | 308 |  | 
 | 309 | /** | 
 | 310 |  * ib_unregister_mad_agent - Unregisters a client from using MAD services. | 
 | 311 |  * @mad_agent: Corresponding MAD registration request to deregister. | 
 | 312 |  * | 
 | 313 |  * After invoking this routine, MAD services are no longer usable by the | 
 | 314 |  * client on the associated QP. | 
 | 315 |  */ | 
 | 316 | int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent); | 
 | 317 |  | 
 | 318 | /** | 
 | 319 |  * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated | 
 | 320 |  *   with the registered client. | 
 | 321 |  * @mad_agent: Specifies the associated registration to post the send to. | 
 | 322 |  * @send_wr: Specifies the information needed to send the MAD(s). | 
 | 323 |  * @bad_send_wr: Specifies the MAD on which an error was encountered. | 
 | 324 |  * | 
 | 325 |  * Sent MADs are not guaranteed to complete in the order that they were posted. | 
 | 326 |  */ | 
 | 327 | int ib_post_send_mad(struct ib_mad_agent *mad_agent, | 
 | 328 | 		     struct ib_send_wr *send_wr, | 
 | 329 | 		     struct ib_send_wr **bad_send_wr); | 
 | 330 |  | 
 | 331 | /** | 
 | 332 |  * ib_coalesce_recv_mad - Coalesces received MAD data into a single buffer. | 
 | 333 |  * @mad_recv_wc: Work completion information for a received MAD. | 
 | 334 |  * @buf: User-provided data buffer to receive the coalesced buffers.  The | 
 | 335 |  *   referenced buffer should be at least the size of the mad_len specified | 
 | 336 |  *   by @mad_recv_wc. | 
 | 337 |  * | 
 | 338 |  * This call copies a chain of received RMPP MADs into a single data buffer, | 
 | 339 |  * removing duplicated headers. | 
 | 340 |  */ | 
 | 341 | void ib_coalesce_recv_mad(struct ib_mad_recv_wc *mad_recv_wc, | 
 | 342 | 			  void *buf); | 
 | 343 |  | 
 | 344 | /** | 
 | 345 |  * ib_free_recv_mad - Returns data buffers used to receive a MAD to the | 
 | 346 |  *   access layer. | 
 | 347 |  * @mad_recv_wc: Work completion information for a received MAD. | 
 | 348 |  * | 
 | 349 |  * Clients receiving MADs through their ib_mad_recv_handler must call this | 
 | 350 |  * routine to return the work completion buffers to the access layer. | 
 | 351 |  */ | 
 | 352 | void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc); | 
 | 353 |  | 
 | 354 | /** | 
 | 355 |  * ib_cancel_mad - Cancels an outstanding send MAD operation. | 
 | 356 |  * @mad_agent: Specifies the registration associated with sent MAD. | 
 | 357 |  * @wr_id: Indicates the work request identifier of the MAD to cancel. | 
 | 358 |  * | 
 | 359 |  * MADs will be returned to the user through the corresponding | 
 | 360 |  * ib_mad_send_handler. | 
 | 361 |  */ | 
 | 362 | void ib_cancel_mad(struct ib_mad_agent *mad_agent, | 
 | 363 | 		   u64 wr_id); | 
 | 364 |  | 
 | 365 | /** | 
 | 366 |  * ib_redirect_mad_qp - Registers a QP for MAD services. | 
 | 367 |  * @qp: Reference to a QP that requires MAD services. | 
 | 368 |  * @rmpp_version: If set, indicates that the client will send | 
 | 369 |  *   and receive MADs that contain the RMPP header for the given version. | 
 | 370 |  *   If set to 0, indicates that RMPP is not used by this client. | 
 | 371 |  * @send_handler: The completion callback routine invoked after a send | 
 | 372 |  *   request has completed. | 
 | 373 |  * @recv_handler: The completion callback routine invoked for a received | 
 | 374 |  *   MAD. | 
 | 375 |  * @context: User specified context associated with the registration. | 
 | 376 |  * | 
 | 377 |  * Use of this call allows clients to use MAD services, such as RMPP, | 
 | 378 |  * on user-owned QPs.  After calling this routine, users may send | 
 | 379 |  * MADs on the specified QP by calling ib_mad_post_send. | 
 | 380 |  */ | 
 | 381 | struct ib_mad_agent *ib_redirect_mad_qp(struct ib_qp *qp, | 
 | 382 | 					u8 rmpp_version, | 
 | 383 | 					ib_mad_send_handler send_handler, | 
 | 384 | 					ib_mad_recv_handler recv_handler, | 
 | 385 | 					void *context); | 
 | 386 |  | 
 | 387 | /** | 
 | 388 |  * ib_process_mad_wc - Processes a work completion associated with a | 
 | 389 |  *   MAD sent or received on a redirected QP. | 
 | 390 |  * @mad_agent: Specifies the registered MAD service using the redirected QP. | 
 | 391 |  * @wc: References a work completion associated with a sent or received | 
 | 392 |  *   MAD segment. | 
 | 393 |  * | 
 | 394 |  * This routine is used to complete or continue processing on a MAD request. | 
 | 395 |  * If the work completion is associated with a send operation, calling | 
 | 396 |  * this routine is required to continue an RMPP transfer or to wait for a | 
 | 397 |  * corresponding response, if it is a request.  If the work completion is | 
 | 398 |  * associated with a receive operation, calling this routine is required to | 
 | 399 |  * process an inbound or outbound RMPP transfer, or to match a response MAD | 
 | 400 |  * with its corresponding request. | 
 | 401 |  */ | 
 | 402 | int ib_process_mad_wc(struct ib_mad_agent *mad_agent, | 
 | 403 | 		      struct ib_wc *wc); | 
 | 404 |  | 
 | 405 | #endif /* IB_MAD_H */ |