1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_IB_IBTL_IBTI_COMMON_H
27 #define	_SYS_IB_IBTL_IBTI_COMMON_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * ibti_common.h
33  *
34  * This file contains the shared/common transport data types and function
35  * prototypes.
36  */
37 #include <sys/ib/ibtl/ibtl_types.h>
38 #include <sys/ib/ibtl/ibti_cm.h>
39 #include <sys/isa_defs.h>
40 #include <sys/byteorder.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /*
47  * Max number of paths that can be requested in an ibt_get_paths() call,
48  * if IBT_PATH_PERF or IBT_PATH_AVAIL flag (ibt_path_flags_t) is set.
49  */
50 #define	IBT_MAX_SPECIAL_PATHS	2
51 
52 /*
53  * The name of DDI Event, generated when the properties of IOC device
54  * node properties were modified.
55  */
56 #define	IB_PROP_UPDATE_EVENT	"SUNW,IB:IB_PROP_UPDATE"
57 
58 
59 /* Transport Interface version */
60 typedef enum ibt_version_e {
61 	IBTI_V1 = 1,
62 	IBTI_V2 = 2		/* FMR Support */
63 } ibt_version_t;
64 
65 /*
66  * Driver class type. Identifies a type of client driver so that
67  * "IBTF Policy" decisions can be made on a driver class basis.
68  * The last class should always be IBT_CLNT_NUM, and any new classes added
69  * must be defined before IBT_CLNT_NUM. The class values must be above 0.
70  * Any class values below or equal to 0 shall be invalid
71  */
72 typedef enum ibt_clnt_class_e {
73 	IBT_STORAGE_DEV = 0x1,	/* SCSI, FC, etc.. */
74 	IBT_NETWORK_DEV,	/* Network driver with associated client H/W */
75 	IBT_GENERIC_DEV,	/* Generic client H/W device driver */
76 	IBT_NETWORK,		/* Network driver with no associated */
77 				/* client H/W, e.g., IPoIB */
78 	IBT_GENERIC,		/* A generic IB driver not */
79 				/* associated with client H/W */
80 	IBT_USER,		/* A user application IBT interface driver */
81 	IBT_IBMA,		/* The IBMA Module */
82 	IBT_CM,			/* The CM Module */
83 	IBT_DM,			/* The DM Module */
84 	IBT_CLASS_NUM		/* Place holder for class count */
85 } ibt_clnt_class_t;
86 
87 #define	IBT_TEST_DEV	999	/* Place holder for modules that test IBTL */
88 
89 #define	IBT_CLNT_DEVICE_CLASS(class)	((class) == IBT_STORAGE_DEV || \
90 					(class) == IBT_NETWORK_DEV || \
91 					(class) == IBT_GENERIC_DEV)
92 
93 #define	IBT_CLNT_GENERAL_CLASS(class)	((class) == IBT_NETWORK || \
94 					(class) == IBT_GENERIC || \
95 					(class) == IBT_USER)
96 
97 #define	IBT_CLNT_MGMT_CLASS(class)	((class) == IBT_IBMA || \
98 					(class) == IBT_CM || \
99 					(class) == IBT_DM || \
100 					(class) == IBT_TEST_DEV)
101 /*
102  * Event record & status returns for asynchronous events and errors.
103  */
104 typedef struct ibt_async_event_s {
105 	uint64_t		ev_fma_ena;		/* FMA Error data */
106 	ibt_channel_hdl_t	ev_chan_hdl;		/* Channel handle */
107 	ibt_cq_hdl_t		ev_cq_hdl;		/* CQ handle */
108 	ib_guid_t		ev_hca_guid;		/* HCA node GUID */
109 	uint8_t			ev_port;		/* HCA port */
110 	ibt_srq_hdl_t		ev_srq_hdl;		/* SRQ handle */
111 } ibt_async_event_t;
112 
113 /*
114  * IBT Client Callback function typedefs.
115  *
116  * ibt_async_handler_t
117  *	Pointer to an async event/error handler function.  This function is
118  *	called when an async event/error is detected on a HCA that is being
119  *	used by the IBT client driver that registered the function.
120  */
121 typedef void (*ibt_async_handler_t)(void *clnt_private,
122     ibt_hca_hdl_t hca_hdl, ibt_async_code_t code, ibt_async_event_t *event);
123 
124 /*
125  * IBT Client Memory Error Callback function typedefs.
126  *
127  * ibt_memory_handler_t
128  *	Pointer to an memory event/error handler function.
129  */
130 typedef void (*ibt_memory_handler_t)(void *clnt_private,
131     ibt_hca_hdl_t hca_hdl, ibt_mem_code_t code, ibt_mem_data_t *data);
132 
133 /*
134  * Define a client module information structure. All clients MUST
135  * define a global of type ibt_clnt_modinfo_t. A pointer to this global
136  * is passed into the IBTF by a client when calling ibt_attach().
137  * This struct must persist during the life of the client.
138  *
139  * The client's mi_async_handler is called when an async event/error is
140  * detected on a HCA that is being used by this client.
141  */
142 typedef struct ibt_clnt_modinfo_s {
143 	ibt_version_t		mi_ibt_version;		/* TI version */
144 	ibt_clnt_class_t	mi_clnt_class;		/* Type of client */
145 	ibt_async_handler_t	mi_async_handler;	/* Async Handler */
146 	ibt_memory_handler_t	mi_reserved;		/* Memory handler */
147 	char			*mi_clnt_name;		/* Client Name. */
148 } ibt_clnt_modinfo_t;
149 
150 
151 /*
152  * Definitions for use with ibt_register_subnet_notices()
153  */
154 typedef enum ibt_subnet_event_code_e {
155 	IBT_SM_EVENT_MCG_CREATED = 1,
156 	IBT_SM_EVENT_MCG_DELETED = 2,
157 	IBT_SM_EVENT_AVAILABLE	 = 3,
158 	IBT_SM_EVENT_UNAVAILABLE = 4,
159 	IBT_SM_EVENT_GID_AVAIL	 = 5,
160 	IBT_SM_EVENT_GID_UNAVAIL = 6
161 } ibt_subnet_event_code_t;
162 
163 typedef struct ibt_subnet_event_s {
164 	ib_gid_t sm_notice_gid;
165 } ibt_subnet_event_t;
166 
167 typedef void (*ibt_sm_notice_handler_t)(void *private, ib_gid_t gid,
168     ibt_subnet_event_code_t code, ibt_subnet_event_t *event);
169 
170 
171 /*
172  * MTU Request type.
173  */
174 typedef struct ibt_mtu_req_s {
175 	ib_mtu_t	r_mtu;		/* Requested MTU */
176 	ibt_selector_t	r_selector;	/* Qualifier for r_mtu */
177 } ibt_mtu_req_t;
178 
179 
180 /*
181  * Qflags, used by ibt_resize_queues().
182  */
183 typedef enum ibt_qflags_e {
184 	IBT_SEND_Q	= 1 << 0,	/* Op applies to the Send Q */
185 	IBT_RECV_Q	= 1 << 1	/* Op applies to the Recv Q */
186 } ibt_qflags_t;
187 
188 /*
189  * CQ priorities
190  * The IBTF will attempt to implement a coarse 3 level priority scheme
191  * (IBT_CQ_LOW, IBT_CQ_MEDIUM, IBT_CQ_HIGH) based on the class of client
192  * driver. The requested priority is not guaranteed. If a CI implementation
193  * has the ability to implement priority CQs, then the IBTF will take advantage
194  * of that when calling the CI to create a CQ by passing a priority indicator
195  * to the CI.
196  */
197 typedef enum ibt_cq_priority_e {
198 	IBT_CQ_DEFAULT		= 0x0,
199 	IBT_CQ_LOW		= 0x1,
200 	IBT_CQ_MEDIUM		= 0x2,
201 	IBT_CQ_HIGH		= 0x3,
202 	IBT_CQ_OPAQUE_1		= 0x4,
203 	IBT_CQ_OPAQUE_2		= 0x5,
204 	IBT_CQ_OPAQUE_3		= 0x6,
205 	IBT_CQ_OPAQUE_4		= 0x7,
206 	IBT_CQ_OPAQUE_5		= 0x8,
207 	IBT_CQ_OPAQUE_6		= 0x9,
208 	IBT_CQ_OPAQUE_7		= 0xA,
209 	IBT_CQ_OPAQUE_8		= 0xB,
210 	IBT_CQ_OPAQUE_9		= 0xC,
211 	IBT_CQ_OPAQUE_10	= 0xD,
212 	IBT_CQ_OPAQUE_11	= 0xE,
213 	IBT_CQ_OPAQUE_12	= 0xF,
214 	IBT_CQ_OPAQUE_13	= 0x10,
215 	IBT_CQ_OPAQUE_14	= 0x11,
216 	IBT_CQ_OPAQUE_15	= 0x12,
217 	IBT_CQ_OPAQUE_16	= 0x13
218 } ibt_cq_priority_t;
219 
220 /*
221  * Attributes when creating a Completion Queue Scheduling Handle.
222  */
223 typedef struct ibt_cq_sched_attr_s {
224 	ibt_cq_sched_flags_t	cqs_flags;
225 	ibt_cq_priority_t	cqs_priority;
226 	uint_t			cqs_load;
227 	ibt_sched_hdl_t		cqs_affinity_hdl;
228 } ibt_cq_sched_attr_t;
229 
230 
231 /*
232  * ibt_cq_handler_t
233  *	Pointer to a work request completion handler function.  This function
234  *	is called when a WR completes on a CQ that is being used by the IBTF
235  *	client driver that registered the function.
236  */
237 typedef void (*ibt_cq_handler_t)(ibt_cq_hdl_t ibt_cq, void *arg);
238 
239 /*
240  * Service Data and flags.
241  *	(IBTA Spec Release 1.1, Vol-1 Ref: 15.2.5.14.4)
242  *
243  * The ServiceData8.1 (sb_data8[0]) through ServiceData64.2 (sb_data64[1])
244  * components together constitutes a 64-byte area in which any data may be
245  * placed. It is intended to be a convenient way for a service to provide its
246  * clients with some initial data.
247  *
248  * In addition, this 64-byte area is formally divided into a total of 30
249  * components, 16 8-bit (uint8_t) components, then 8 16-bit (uint16_t)
250  * components, then 6 32-bit (uint32_t) components, then 2 64-bit (uint64_t)
251  * components,  thereby assigning ComponentMask bits (ibt_srv_data_flags_t) to
252  * variously-sized segments of the data. All data are in host endian format.
253  * This allows query operations (ibt_get_paths()) to be used which match
254  * parts of the Service Data, making it possible, for example, for
255  * service-specific parts of the ServiceData to serve as a binary-coded
256  * extension to the ServiceName for purposes of lookup.
257  */
258 typedef enum ibt_srv_data_flags_e {
259 	IBT_NO_SDATA	= 0,
260 
261 	IBT_SDATA8_0	= (1 << 0),
262 	IBT_SDATA8_1	= (1 << 1),
263 	IBT_SDATA8_2	= (1 << 2),
264 	IBT_SDATA8_3	= (1 << 3),
265 	IBT_SDATA8_4	= (1 << 4),
266 	IBT_SDATA8_5	= (1 << 5),
267 	IBT_SDATA8_6	= (1 << 6),
268 	IBT_SDATA8_7	= (1 << 7),
269 	IBT_SDATA8_8	= (1 << 8),
270 	IBT_SDATA8_9	= (1 << 9),
271 	IBT_SDATA8_10	= (1 << 10),
272 	IBT_SDATA8_11	= (1 << 11),
273 	IBT_SDATA8_12	= (1 << 12),
274 	IBT_SDATA8_13	= (1 << 13),
275 	IBT_SDATA8_14	= (1 << 14),
276 	IBT_SDATA8_15	= (1 << 15),
277 
278 	IBT_SDATA16_0	= (1 << 16),
279 	IBT_SDATA16_1	= (1 << 17),
280 	IBT_SDATA16_2	= (1 << 18),
281 	IBT_SDATA16_3	= (1 << 19),
282 	IBT_SDATA16_4	= (1 << 20),
283 	IBT_SDATA16_5	= (1 << 21),
284 	IBT_SDATA16_6	= (1 << 22),
285 	IBT_SDATA16_7	= (1 << 23),
286 
287 	IBT_SDATA32_0	= (1 << 24),
288 	IBT_SDATA32_1	= (1 << 25),
289 	IBT_SDATA32_2	= (1 << 26),
290 	IBT_SDATA32_3	= (1 << 27),
291 
292 	IBT_SDATA64_0	= (1 << 28),
293 	IBT_SDATA64_1	= (1 << 29),
294 
295 	IBT_SDATA_ALL	= 0x3FFFFFFF
296 } ibt_srv_data_flags_t;
297 
298 typedef struct ibt_srv_data_s {
299 	uint8_t		s_data8[16];	/* 8-bit service data fields. */
300 	uint16_t	s_data16[8];	/* 16-bit service data fields. */
301 	uint32_t	s_data32[4];	/* 32-bit service data fields. */
302 	uint64_t	s_data64[2];	/* 64-bit service data fields. */
303 } ibt_srv_data_t;
304 
305 /*
306  * Path flags, used in ibt_get_paths()
307  */
308 typedef enum ibt_path_flags_e {
309 	IBT_PATH_NO_FLAGS	= 0,
310 	IBT_PATH_APM		= 1 << 0,	/* APM is desired. */
311 	IBT_PATH_AVAIL		= 1 << 2,
312 	IBT_PATH_PERF		= 1 << 3,
313 	IBT_PATH_MULTI_SVC_DEST	= 1 << 4,	/* Multiple ServiceRecords */
314 	IBT_PATH_HOP		= 1 << 5,	/* pa_hop is specified. */
315 	IBT_PATH_PKEY		= 1 << 6	/* pa_pkey is specified. */
316 } ibt_path_flags_t;
317 
318 /*
319  * Path attributes.
320  *
321  * The ibt_path_attr_t structure is used to specify required attributes in a
322  * path from the requesting (source) node to a specified destination node.
323  * Attributes that are don't care should be set to NULL or '0'.
324  * A destination must be specified, where a destination can be defined as
325  * one of the following:
326  *
327  *	o Service Name
328  *	o Service ID (SID)
329  *	o Array of DGIDs.
330  *	o Service Name and Array of DGIDs.
331  */
332 typedef struct ibt_path_attr_s {
333 	ib_gid_t		*pa_dgids;	/* Array of DGIDs */
334 	ib_gid_t		pa_sgid;
335 	ib_guid_t		pa_hca_guid;
336 	char			*pa_sname;	/* ASCII Service name  */
337 						/* NULL Terminated */
338 	ib_svc_id_t		pa_sid;		/* Service ID */
339 	ibt_srv_data_flags_t	pa_sd_flags;	/* Service Data flags. */
340 	ibt_srv_data_t		pa_sdata;	/* Service Data */
341 	uint8_t			pa_hca_port_num;
342 	uint8_t			pa_num_dgids;	/* size of pa_dgids array */
343 	uint8_t			pa_sl:4;
344 	ibt_mtu_req_t		pa_mtu;
345 	ibt_srate_req_t		pa_srate;
346 	ibt_pkt_lt_req_t	pa_pkt_lt;	/* Packet Life Time Request */
347 	uint_t			pa_flow:20;
348 	uint8_t			pa_hop;		/* IBT_PATH_HOP */
349 	uint8_t			pa_tclass;
350 	ib_pkey_t		pa_pkey;	/* IBT_PATH_PKEY */
351 } ibt_path_attr_t;
352 
353 /*
354  * Path Information.
355  *
356  * The ibt_get_paths() performs SA Path record lookups to select a path(s) to
357  * a given destination(s), details of selected path(s) are returned in this
358  * structure.
359  *
360  * The ibt_path_info_t contains all the attributes of the best path(s), as
361  * as determined by IBTL, to the specified destination(s), including the
362  * local HCA and HCA port to use to access the fabric.
363  *
364  * The Service ID (pi_sid) and Service Data (pi_sdata) are returned only for
365  * lookups based on Service ID or/and Service Name.
366  */
367 typedef struct ibt_path_info_s {
368 	ib_guid_t	pi_hca_guid;		/* Local HCA GUID; 0 implies */
369 						/* this record is invalid */
370 	ib_svc_id_t	pi_sid;			/* Service ID */
371 	ibt_srv_data_t	pi_sdata;		/* Service Data */
372 
373 	ibt_cep_path_t	pi_prim_cep_path;	/* Contains CEP adds info */
374 	ibt_cep_path_t	pi_alt_cep_path;	/* RC & UC Only, valid if */
375 						/* cep_hca_port_num is not */
376 						/* '0' */
377 	ib_mtu_t	pi_path_mtu;		/* Common path MTU */
378 	ib_time_t	pi_prim_pkt_lt;
379 	ib_time_t	pi_alt_pkt_lt;
380 } ibt_path_info_t;
381 
382 /*
383  * Optional Alternate Path attributes.
384  *
385  * The ibt_alt_path_attr_t structure is used to specify additional optional
386  * attributes when requesting an alternate path for an existing channel.
387  *
388  * Attributes that are don't care should be set to NULL or '0'.
389  */
390 typedef struct ibt_alt_path_attr_s {
391 	ib_gid_t		apa_sgid;
392 	ib_gid_t		apa_dgid;
393 	ibt_srate_req_t		apa_srate;
394 	ibt_pkt_lt_req_t	apa_pkt_lt;	/* Packet Life Time Request */
395 	uint_t			apa_flow:20;
396 	uint8_t			apa_sl:4;
397 	uint8_t			apa_hop;
398 	uint8_t			apa_tclass;
399 } ibt_alt_path_attr_t;
400 
401 /*
402  * Path Information for Alternate Path - input to ibt_set_alt_path().
403  */
404 typedef struct ibt_alt_path_info_s {
405 	ibt_cep_path_t	ap_alt_cep_path;	/* RC & UC Only, valid if */
406 						/* cep_hca_port_num is not */
407 						/* '0' */
408 	ib_time_t	ap_alt_pkt_lt;
409 } ibt_alt_path_info_t;
410 
411 /*
412  * Open Channel flags, Used in ibt_open_rc_channel call
413  */
414 typedef enum ibt_chan_open_flags_e {
415 	IBT_OCHAN_NO_FLAGS		= 0,
416 	IBT_OCHAN_REDIRECTED		= 1 << 0,
417 	IBT_OCHAN_PORT_REDIRECTED	= 1 << 1,
418 	IBT_OCHAN_DUP			= 1 << 2,
419 	IBT_OCHAN_PORT_FIXED		= 1 << 3,
420 	IBT_OCHAN_OPAQUE1		= 1 << 4,
421 	IBT_OCHAN_OPAQUE2		= 1 << 5,
422 	IBT_OCHAN_OPAQUE3		= 1 << 6,
423 	IBT_OCHAN_OPAQUE4		= 1 << 7,
424 	IBT_OCHAN_OPAQUE5		= 1 << 8
425 } ibt_chan_open_flags_t;
426 
427 /*
428  * Arguments for ibt_open_rc_channel().
429  *
430  * oc_priv_data should be NULL or point to a buffer allocated by the caller,
431  * the size of which should be in oc_priv_data_len, where oc_priv_data_len <=
432  * IBT_REQ_PRIV_DATA_SZ.
433  *
434  * When ibt_open_rc_channel returns with ibt_cm_reason_t of
435  * IBT_CM_REDIRECT_PORT, the client can re-issue ibt_open_rc_channel setting
436  * new fields as follows:
437  *
438  * Set (ibt_chan_args_t)->oc_cm_cep_path  =
439  *    original (ibt_chan_open_args_t)->oc_path->pi_prim_cep_path.
440  * Set (ibt_chan_args_t)->oc_cm_pkt_lt  =
441  *    original (ibt_chan_open_args_t)->oc_prim_pkt_lt.
442  * Update (ibt_chan_args_t)->oc_path based on path information returned
443  * from ibt_get_paths using the gid in the return data below:
444  * 	(ibt_rc_returns_t)->rc_arej_info.ari_redirect_info.ari_gid.
445  * Set flags to IBT_OCHAN_PORT_REDIRECTED.
446  *
447  * Note : oc_cm_path is not used for any other scenario, and must be set for
448  * IBT_OCHAN_PORT_REDIRECTED.
449  *
450  * When ibt_open_rc_channel returns with ibt_cm_reason_t of
451  * IBT_CM_REDIRECT_CM, the client can re-issue ibt_open_rc_channel setting
452  * new fields as follows:
453  *
454  * Update (ibt_chan_args_t)->oc_path based on path information returned
455  * from ibt_get_paths using the return data in
456  * (ibt_rc_returns_t)->rc_arej_info.ari_redirect_info.
457  *
458  * Set (ibt_chan_args_t)->oc_cm_redirect_info =
459  *    Returned (ibt_rc_returns_t)->rc_arej_info.ari_redirect_info.
460  * Set flags to IBT_OCHAN_REDIRECTED.
461  *
462  * Note:
463  *
464  * IBT_OCHAN_PORT_REDIRECTED flag cannot be used to specify a remote CM MAD
465  * address, that is on a different subnet than the RC connection itself.
466  *
467  * Not specified attributes should be set to "NULL" or "0".
468  */
469 typedef struct ibt_chan_open_args_s {
470 	ibt_path_info_t 	*oc_path;	/* Primary & Alternate */
471 	ibt_cm_handler_t 	oc_cm_handler;	/* cm_handler - required */
472 	void			*oc_cm_clnt_private;	/* First argument to */
473 							/* cm_handler */
474 	ibt_rnr_retry_cnt_t	oc_path_rnr_retry_cnt;
475 	uint8_t			oc_path_retry_cnt:3;
476 	uint8_t			oc_rdma_ra_out;
477 	uint8_t			oc_rdma_ra_in;
478 	ibt_priv_data_len_t	oc_priv_data_len;	/* Number of bytes of */
479 							/* REQ Private data */
480 	void			*oc_priv_data;		/* REQ private data */
481 	ibt_channel_hdl_t	oc_dup_channel; 	/* IBT_OCHAN_DUP */
482 	ibt_redirect_info_t	*oc_cm_redirect_info;	/* Redirect params */
483 							/* for port and CM */
484 							/* redirection */
485 	ibt_cep_path_t		*oc_cm_cep_path;	/* Optional Path for */
486 							/* CM MADs on */
487 							/* port redirection */
488 	ib_time_t		oc_cm_pkt_lt;		/* Pkt life time for */
489 							/* CM MADs */
490 	uint32_t		oc_opaque1:4;
491 	uint32_t		oc_opaque2:24;
492 	uint32_t		oc_opaque3;
493 	uint32_t		oc_opaque4;
494 } ibt_chan_open_args_t;
495 
496 
497 /*
498  * Define an optional RC return arguments structure. This contains return
499  * parameters from ibt_open_rc_channel() when called in BLOCKING mode.
500  *
501  * rc_priv_data should be NULL or point to a buffer allocated by the caller,
502  * the size of which should be in rc_priv_data_len, where rc_priv_data_len <=
503  * IBT_REP_PRIV_DATA_SZ.
504  */
505 typedef struct ibt_rc_returns_s {
506 	uint8_t			rc_rdma_ra_in;	/* Arbitrated resp resources */
507 	uint8_t			rc_rdma_ra_out;	/* Arbitrated initiator depth */
508 	ibt_arej_info_t		rc_arej_info;
509 	ibt_cm_reason_t		rc_status;
510 	uint8_t			rc_failover_status;	/* Failover status */
511 	ibt_priv_data_len_t	rc_priv_data_len;
512 	void			*rc_priv_data;
513 } ibt_rc_returns_t;
514 
515 /*
516  * Define a callback function that can be used in Non-Blocking calls to
517  * ibt_recycle_rc().
518  */
519 
520 typedef	void	(*ibt_recycle_handler_t)(ibt_status_t ibt_status, void *arg);
521 
522 /*
523  * Define an optional return arguments structure from ibt_set_alt_path()
524  * This contains return parameters, when called in BLOCKING mode.
525  *
526  * ap_priv_data should be NULL or point to a buffer allocated by the caller,
527  * the size of which should be in ap_priv_data_len, where ap_priv_data_len <=
528  * IBT_APR_PRIV_DATA_SZ.
529  * The private data from APR is returned in ap_priv_data.
530  * The caller specifies amount of APR private data to be returned in
531  * ap_priv_data_len.
532  */
533 typedef struct ibt_ap_returns_s {
534 	ibt_ap_status_t		ap_status;
535 	boolean_t		ap_arej_info_valid;
536 	ibt_arej_info_t		ap_arej_info;	/* Only valid if redirect */
537 	ibt_priv_data_len_t	ap_priv_data_len;
538 	void			*ap_priv_data;
539 } ibt_ap_returns_t;
540 
541 /*
542  * UD remote destination attributes.
543  *
544  * ud_sid, ud_addr, ud_pkt_lt and ud_pkey_ix must be specified.
545  * These values can be as returned in an ibt_path_info_t struct from an
546  * ibt_get_paths() call.
547  *
548  * ud_priv_data should be NULL or point to a buffer allocated by the caller,
549  * the size of which is in ud_priv_data_len, where ud_priv_data_len <=
550  * IBT_SIDR_REQ_PRIV_DATA_SZ.
551  */
552 typedef struct ibt_ud_dest_attr_s {
553 	ib_svc_id_t		ud_sid;		/* Service ID */
554 	ibt_adds_vect_t		*ud_addr;	/* Address Info */
555 	uint16_t		ud_pkey_ix;	/* Pkey Index */
556 	ib_time_t		ud_pkt_lt;
557 	ibt_cm_ud_handler_t	ud_cm_handler;	/* An optional CM UD event */
558 						/* which must be NULL */
559 						/* if not specified. */
560 	void			*ud_cm_private; /* First arg to ud_cm_handler */
561 	ibt_priv_data_len_t	ud_priv_data_len;
562 	void			*ud_priv_data;	/* SIDR REQ private data */
563 } ibt_ud_dest_attr_t;
564 
565 /*
566  * Define an optional UD return arguments structure.
567  *
568  * ud_priv_data should be NULL or point to a buffer allocated by the caller,
569  * the size of which should be in ud_priv_data_len, where ud_priv_data_len <=
570  * IBT_SIDR_REP_PRIV_DATA_SZ.
571  */
572 typedef struct ibt_ud_returns_s {
573 	ibt_sidr_status_t	ud_status;
574 	ibt_redirect_info_t	ud_redirect;
575 	ib_qpn_t		ud_dqpn;	/* Returned destination QPN */
576 	ib_qkey_t		ud_qkey;	/* Q_Key for destination QPN */
577 	ibt_priv_data_len_t	ud_priv_data_len;
578 	void			*ud_priv_data;
579 } ibt_ud_returns_t;
580 
581 /*
582  * Multicast group attributes
583  * Not specified attributes should be set to "NULL" or "0".
584  * Used by ibt_join_mcg()/ibt_query_mcg().
585  *
586  * mc_qkey, mc_pkey, mc_flow, mc_tclass, mc_sl, mc_join_state are required for
587  * create - ibt_join_mcg().
588  */
589 typedef struct ibt_mcg_attr_s {
590 	ib_gid_t		mc_mgid;	/* MGID */
591 	ib_gid_t		mc_pgid;	/* SGID of the end port being */
592 						/* added to the MCG. */
593 	ib_qkey_t		mc_qkey;	/* Q_Key */
594 	ib_pkey_t		mc_pkey;	/* Partition key for this MCG */
595 	ibt_mtu_req_t		mc_mtu_req;	/* MTU */
596 	ibt_srate_req_t		mc_rate_req;	/* Static rate */
597 	ibt_pkt_lt_req_t	mc_pkt_lt_req;	/* Packet Life Time Request */
598 	uint_t			mc_flow:20;	/* FlowLabel. */
599 	uint8_t			mc_hop;		/* HopLimit */
600 	uint8_t			mc_tclass;	/* Traffic Class. */
601 	uint8_t			mc_sl:4;	/* Service Level */
602 	uint8_t			mc_scope:4,	/* Multicast Address Scope */
603 				mc_join_state:4; /* FULL For create */
604 	ib_lid_t		mc_opaque1;
605 } ibt_mcg_attr_t;
606 
607 /*
608  * Multicast group attributes.
609  * returned by ibt_join_mcg()/ibt_query_mcg().
610  */
611 typedef struct ibt_mcg_info_s {
612 	ibt_adds_vect_t		mc_adds_vect;   /* Address information */
613 	ib_mtu_t		mc_mtu;		/* MTU */
614 	ib_qkey_t		mc_qkey;	/* Q_Key */
615 	uint16_t		mc_pkey_ix;	/* Pkey Index */
616 	uint8_t			mc_scope:4;	/* Multicast Address Scope */
617 	clock_t			mc_opaque2;
618 } ibt_mcg_info_t;
619 
620 /*
621  * Define a callback function that can be used in Non-Blocking calls to
622  * ibt_join_mcg().
623  */
624 typedef void (*ibt_mcg_handler_t)(void *arg, ibt_status_t retval,
625     ibt_mcg_info_t *mcg_info_p);
626 
627 
628 /*
629  * Service Flags - sd_flags
630  *
631  *    IBT_SRV_PEER_TYPE_SID	Peer-to-peer Service IDs.
632  */
633 
634 typedef enum ibt_service_flags_e {
635 	IBT_SRV_NO_FLAGS	= 0x0,
636 	IBT_SRV_PEER_TYPE_SID	= 0x1
637 } ibt_service_flags_t;
638 
639 /*
640  * Define a Service ID Registration structure.
641  */
642 typedef struct ibt_srv_desc_s {
643 	ibt_cm_ud_handler_t	sd_ud_handler;	/* UD Service Handler */
644 	ibt_cm_handler_t	sd_handler;	/* Non-UD Service Handler */
645 	ibt_service_flags_t	sd_flags;	/* Flags */
646 } ibt_srv_desc_t;
647 
648 /*
649  * Flag to indicate ibt_bind_service() to or NOT-to clean-up Stale matching
650  * Local Service Records with SA prior to binding the new request.
651  */
652 #define	IBT_SBIND_NO_FLAGS	0
653 #define	IBT_SBIND_NO_CLEANUP	1
654 
655 /*
656  * Define a Service ID Binding structure (data for service records).
657  */
658 typedef struct ibt_srv_bind_s {
659 	uint64_t	sb_key[2];	/* Service Key */
660 	char		*sb_name;	/* Service Name (up to 63 chars) */
661 	uint32_t	sb_lease;	/* Service Lease period (in seconds) */
662 	ib_pkey_t	sb_pkey;	/* Service P_Key */
663 	ibt_srv_data_t	sb_data;	/* Service Data */
664 	uint_t		sb_flag;	/* indicates to/not-to clean-up stale */
665 					/* matching local service records. */
666 } ibt_srv_bind_t;
667 
668 /*
669  * ibt_cm_delay() flags.
670  *
671  * Refer to InfiniBand Architecture Release Volume 1 Rev 1.0a:
672  * Section 12.6.6 MRA
673  */
674 typedef enum ibt_cmdelay_flags_e {
675 	IBT_CM_DELAY_REQ	= 0,
676 	IBT_CM_DELAY_REP	= 1,
677 	IBT_CM_DELAY_LAP	= 2
678 } ibt_cmdelay_flags_t;
679 
680 /*
681  * The payload for DDI events passed on IB_PROP_UPDATE_EVENT.
682  * This is passed as the bus nexus data to event_handler(9e).
683  */
684 typedef struct ibt_prop_update_payload_s {
685 	union {
686 		struct {
687 			uint32_t	srv_updated:1;
688 			uint32_t	gid_updated:1;
689 		} _ib_prop_update_struct;
690 		uint32_t	prop_updated;
691 	} _ib_prop_update_union;
692 	ibt_status_t		ib_reprobe_status;
693 
694 #define	ib_srv_prop_updated	\
695     _ib_prop_update_union._ib_prop_update_struct.srv_updated
696 #define	ib_gid_prop_updated	\
697     _ib_prop_update_union._ib_prop_update_struct.gid_updated
698 #define	ib_prop_updated		\
699     _ib_prop_update_union.prop_updated
700 } ibt_prop_update_payload_t;
701 
702 
703 /*
704  * FUNCTION PROTOTYPES.
705  */
706 
707 /*
708  * ibt_attach() and ibt_detach():
709  *	These are the calls into IBTF used during client driver attach() and
710  *	detach().
711  *
712  *	The IBTF returns an ibt_clnt_hdl_t to the client. This handle is used
713  *	to identify this client device in all subsequent calls into the IBTF.
714  *
715  *	The ibt_detach() routine is called from a client driver's detach()
716  *	routine to deregister itself from the IBTF.
717  */
718 ibt_status_t ibt_attach(ibt_clnt_modinfo_t *mod_infop, dev_info_t *arg,
719     void *clnt_private, ibt_clnt_hdl_t *ibt_hdl_p);
720 
721 ibt_status_t ibt_detach(ibt_clnt_hdl_t ibt_hdl);
722 
723 /*
724  * HCA FUNCTIONS
725  */
726 
727 /*
728  * ibt_get_hca_list()
729  *	Returns the number of HCAs in a system and their node GUIDS.
730  *
731  *	If hca_list_p is not NULL then the memory for the array of GUIDs is
732  *	allocated by the IBTF and should be freed by the caller using
733  *	ibt_free_hca_list(). If hca_list_p is NULL then no memory is allocated
734  *	by ibt_get_hca_list and only the number of HCAs in a system is returned.
735  *
736  *	It is assumed that the caller can block in kmem_alloc.
737  *
738  * ibt_free_hca_list()
739  *	Free the memory allocated by ibt_get_hca_list().
740  */
741 uint_t ibt_get_hca_list(ib_guid_t **hca_list_p);
742 
743 void ibt_free_hca_list(ib_guid_t *hca_list, uint_t entries);
744 
745 /*
746  * ibt_open_hca()	- Open/Close a HCA. HCA can only be opened/closed
747  * ibt_close_hca()	  once. ibt_open_hca() takes a client's ibt handle
748  *			  and a GUID and returns a unique IBT client HCA
749  *			  handle.
750  *
751  * These routines can not be called from interrupt context.
752  */
753 ibt_status_t ibt_open_hca(ibt_clnt_hdl_t ibt_hdl, ib_guid_t hca_guid,
754     ibt_hca_hdl_t *hca_hdl);
755 
756 ibt_status_t ibt_close_hca(ibt_hca_hdl_t hca_hdl);
757 
758 
759 /*
760  * ibt_query_hca()
761  * ibt_query_hca_byguid()
762  * 	Returns the static attributes of the specified HCA
763  */
764 ibt_status_t ibt_query_hca(ibt_hca_hdl_t hca_hdl, ibt_hca_attr_t *hca_attrs);
765 
766 ibt_status_t ibt_query_hca_byguid(ib_guid_t hca_guid,
767     ibt_hca_attr_t *hca_attrs);
768 
769 
770 /*
771  * ibt_query_hca_ports()
772  * ibt_query_hca_ports_byguid()
773  *	Returns HCA port/ports attributes for the specified HCA port/ports.
774  *	ibt_query_hca_ports() allocates the memory required for the
775  *	ibt_hca_portinfo_t struct as well as the memory required for the SGID
776  *	and P_Key tables contained within that struct.
777  *
778  * ibt_free_portinfo()
779  *	Frees the memory allocated for a specified ibt_hca_portinfo_t struct.
780  */
781 ibt_status_t ibt_query_hca_ports(ibt_hca_hdl_t hca_hdl, uint8_t port,
782     ibt_hca_portinfo_t **port_info_p, uint_t *ports_p, uint_t *size_p);
783 
784 ibt_status_t ibt_query_hca_ports_byguid(ib_guid_t hca_guid, uint8_t port,
785     ibt_hca_portinfo_t **port_info_p, uint_t *ports_p, uint_t *size_p);
786 
787 void ibt_free_portinfo(ibt_hca_portinfo_t *port_info, uint_t size);
788 
789 /*
790  * ibt_set_hca_private()	- Set/get the client private data.
791  * ibt_get_hca_private()
792  */
793 void ibt_set_hca_private(ibt_hca_hdl_t hca_hdl, void *clnt_private);
794 void *ibt_get_hca_private(ibt_hca_hdl_t hca_hdl);
795 
796 /*
797  * ibt_hca_handle_to_guid()
798  *	A helper function to retrieve HCA GUID for the specified handle.
799  *	Returns HCA GUID on which the specified Channel is allocated. Valid
800  *	if it is non-NULL on return.
801  */
802 ib_guid_t ibt_hca_handle_to_guid(ibt_hca_hdl_t hca);
803 
804 /*
805  * ibt_hca_guid_to_handle()
806  *	A helper function to retrieve a hca handle from a HCA GUID.
807  */
808 ibt_status_t ibt_hca_guid_to_handle(ibt_clnt_hdl_t ibt_hdl, ib_guid_t hca_guid,
809     ibt_hca_hdl_t *hca_hdl);
810 
811 /*
812  * CONNECTION ESTABLISHMENT/TEAR DOWN FUNCTIONS.
813  */
814 
815 /*
816  * ibt_get_paths
817  *	Finds the best path to a specified destination (as determined by the
818  *	IBTL) that satisfies the requirements specified in an ibt_path_attr_t
819  *	struct.
820  */
821 ibt_status_t ibt_get_paths(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags,
822     ibt_path_attr_t *attr, uint8_t max_paths, ibt_path_info_t *paths,
823     uint8_t *num_paths_p);
824 
825 
826 /*
827  * Callback function that can be used in ibt_aget_paths(), a Non-Blocking
828  * version of ibt_get_paths().
829  */
830 typedef void (*ibt_path_handler_t)(void *arg, ibt_status_t retval,
831     ibt_path_info_t *paths, uint8_t num_paths);
832 
833 /*
834  * Find path(s) to a given destination or service asynchronously.
835  * ibt_aget_paths() is a Non-Blocking version of ibt_get_paths().
836  */
837 ibt_status_t ibt_aget_paths(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags,
838     ibt_path_attr_t *attr, uint8_t max_paths, ibt_path_handler_t func,
839     void  *arg);
840 
841 /*
842  * ibt_get_alt_path
843  *	Finds the best alternate path to a specified channel (as determined by
844  *	the IBTL) that satisfies the requirements specified in an
845  *	ibt_alt_path_attr_t struct.  The specified channel must have been
846  *	previously opened successfully using ibt_open_rc_channel.
847  */
848 ibt_status_t ibt_get_alt_path(ibt_channel_hdl_t chan, ibt_path_flags_t flags,
849     ibt_alt_path_attr_t *attr, ibt_alt_path_info_t *alt_path);
850 
851 /*
852  * ibt_open_rc_channel
853  * 	ibt_open_rc_channel() opens a previously allocated RC communication
854  *	channel. The IBTL initiates the channel establishment protocol.
855  */
856 ibt_status_t ibt_open_rc_channel(ibt_channel_hdl_t rc_chan,
857     ibt_chan_open_flags_t flags, ibt_execution_mode_t mode,
858     ibt_chan_open_args_t *args, ibt_rc_returns_t *returns);
859 
860 /*
861  * ibt_close_rc_channel
862  *	Close the specified channel. Outstanding work requests are flushed
863  *	so that the client can do the associated clean up. After that, the
864  *	client will usually deregister the previously registered memory,
865  *	then free the channel by calling ibt_free_rc_channel().
866  *
867  *	This function will reuse CM event Handler provided in
868  *	ibt_open_rc_channel().
869  */
870 ibt_status_t ibt_close_rc_channel(ibt_channel_hdl_t rc_chan,
871     ibt_execution_mode_t mode, void *priv_data,
872     ibt_priv_data_len_t priv_data_len, uint8_t *ret_status,
873     void *ret_priv_data, ibt_priv_data_len_t *ret_priv_data_len_p);
874 
875 /*
876  * ibt_prime_close_rc_channel
877  *
878  *	Allocates resources required for a close rc channel operation.
879  *	Calling ibt_prime_close_rc_channel() allows a channel to be
880  *	subsequently closed in interrupt context.
881  *
882  *	A call is first made to ibt_prime_close_rc_channel in non-interrupt
883  *	context, followed by ibt_close_rc_channel in non-blocking mode from
884  *	interrupt context
885  *
886  *	ibt_prime_close_rc_channel() can only be called on a previously opened
887  *	channel.
888  */
889 ibt_status_t ibt_prime_close_rc_channel(ibt_channel_hdl_t rc_chan);
890 
891 /*
892  * ibt_recycle_rc
893  *
894  *      Recycle a RC channel which has transitioned to Error state. The
895  *      ibt_recycle_rc() function transitions the channel from Error
896  *      state (IBT_STATE_ERROR) to the state ready for use by
897  *      ibt_open_rc_channel. Basically, this function is very similar to
898  *      ibt_alloc_rc_channel, but reuses an existing RC channel.
899  *
900  * Clients are allowed to make resource clean up/free calls in the CM handler
901  *
902  * Client(s) must not invoke blocking version (ie., func specified as NULL) of
903  * ibt_recycle_rc from cm callback for IBT_CM_EVENT_CONN_CLOSED
904  *
905  * Clients are strongly advised not to issue blocking calls from  func, as this
906  * would block the CM threads, and could delay or block other client connections
907  * and ibtl related API invocations.
908  */
909 ibt_status_t ibt_recycle_rc(ibt_channel_hdl_t rc_chan, ibt_cep_flags_t control,
910     uint8_t hca_port_num, ibt_recycle_handler_t func, void *arg);
911 
912 /*
913  * ibt_recycle_ud
914  *
915  *      Recycle a UD channel which has transitioned to Error state. The
916  *      ibt_recycle_ud() function transitions the channel from Error
917  *      state (IBT_STATE_ERROR) to a usable state (IBT_STATE_RTS).
918  *      Basically, this function is very similar to ibt_alloc_ud_channel,
919  *	but reuses an existing UD channel.
920  */
921 ibt_status_t ibt_recycle_ud(ibt_channel_hdl_t ud_chan, uint8_t hca_port_num,
922     uint16_t pkey_ix, ib_qkey_t qkey);
923 
924 /*
925  * MODIFY CHANNEL ATTRIBUTE FUNCTIONs.
926  */
927 
928 /*
929  * ibt_pause_sendq
930  * ibt_unpause_sendq
931  *	Place the send queue of the specified channel into the send queue
932  *	drained state.
933  *	Applicable for both RC and UD channels.
934  */
935 ibt_status_t ibt_pause_sendq(ibt_channel_hdl_t chan,
936     ibt_cep_modify_flags_t modify_flags);
937 
938 ibt_status_t ibt_unpause_sendq(ibt_channel_hdl_t chan);
939 
940 /*
941  * ibt_resize_queues()
942  *	Resize the SendQ/RecvQ sizes of a channel.
943  *
944  *	Applicable for both RC and UD channels.
945  */
946 ibt_status_t ibt_resize_queues(ibt_channel_hdl_t chan, ibt_qflags_t flags,
947     ibt_queue_sizes_t *request_sz, ibt_queue_sizes_t *actual_sz);
948 
949 /*
950  * ibt_query_queues()
951  *
952  *	Query the SendQ/RecvQ sizes of a channel.
953  *	Applicable for both RC and UD channels.
954  */
955 ibt_status_t ibt_query_queues(ibt_channel_hdl_t chan,
956     ibt_queue_sizes_t *actual_sz);
957 
958 /*
959  * ibt_modify_rdma
960  *	Enable/disable RDMA operations.
961  *
962  *	Applicable for RC channels only.
963  */
964 ibt_status_t ibt_modify_rdma(ibt_channel_hdl_t rc_chan,
965     ibt_cep_modify_flags_t modify_flags, ibt_cep_flags_t flags);
966 
967 
968 /*
969  * ibt_set_rdma_resource
970  *	Change the number of resources to be used for incoming and outgoing
971  *	RDMA reads & Atomics.
972  */
973 ibt_status_t ibt_set_rdma_resource(ibt_channel_hdl_t rc_chan,
974     ibt_cep_modify_flags_t modify_flags, uint8_t rdma_ra_out,
975     uint8_t rdma_ra_in);
976 
977 /*
978  * ibt_change_port
979  *	Change the primary physical port of an RC channel. (This is done only
980  *	if HCA supports this capability).  Can only be called on a paused
981  *	channel.
982  *	Applicable for RC channels only.
983  */
984 ibt_status_t ibt_change_port(ibt_channel_hdl_t rc_chan, uint8_t port_num);
985 
986 
987 /*
988  * SERVICE REGISTRATION FUNCTIONS
989  */
990 
991 /*
992  * ibt_register_service()
993  * ibt_deregister_service()
994  *	Register/deregister a Service (range of Service IDs) with the IBTF.
995  *
996  * ibt_bind_service()
997  * ibt_unbind_service()
998  * ibt_unbind_all_services()
999  *	Bind a Service to a given port (GID), and optionally create
1000  *	service record(s) with the SA for ibt_get_paths() to find.
1001  */
1002 ibt_status_t ibt_register_service(ibt_clnt_hdl_t ibt_hdl,
1003     ibt_srv_desc_t *service, ib_svc_id_t sid, int num_sids,
1004     ibt_srv_hdl_t *srv_hdl_p, ib_svc_id_t *ret_sid_p);
1005 
1006 ibt_status_t ibt_deregister_service(ibt_clnt_hdl_t ibt_hdl,
1007     ibt_srv_hdl_t srv_hdl);
1008 
1009 ibt_status_t ibt_bind_service(ibt_srv_hdl_t srv_hdl, ib_gid_t gid,
1010     ibt_srv_bind_t *srv_bind, void *cm_private, ibt_sbind_hdl_t *sb_hdl_p);
1011 
1012 ibt_status_t ibt_unbind_service(ibt_srv_hdl_t srv_hdl, ibt_sbind_hdl_t sb_hdl);
1013 ibt_status_t ibt_unbind_all_services(ibt_srv_hdl_t srv_hdl);
1014 
1015 /*
1016  * ibt_cm_delay
1017  *	A client CM handler/srv_handler function can call this function to
1018  *	extend its response time to a CM event.
1019  *	Applicable for RC channels only.
1020  */
1021 ibt_status_t ibt_cm_delay(ibt_cmdelay_flags_t flags, void *cm_session_id,
1022     clock_t service_time, void *priv_data, ibt_priv_data_len_t priv_data_len);
1023 
1024 /*
1025  * ibt_cm_proceed
1026  *
1027  * An IBT client calls ibt_cm_proceed() to proceed with a connection that
1028  * previously deferred by the client returning IBT_CM_DEFER on a CM handler
1029  * callback. CM events that can be deferred and continued with ibt_cm_proceed()
1030  * are REQ_RCV, REP_RCV, LAP_RCV, and DREQ_RCV.
1031  *
1032  * NOTE :
1033  *
1034  * Typically CM completes processing of a client's CM handler return, with
1035  * IBT_CM_DEFER status, before  processing of the corresponding ibt_cm_proceed()
1036  * is started. However a race exists where by CM may not have completed the
1037  * client's handler return processing when ibt_cm_proceed() is called by a
1038  * client. In this case ibt_cm_proceed() will block until processing of the
1039  * client's CM handler return is complete.
1040  *
1041  * A client that returns IBT_CM_DEFER from the cm handler must
1042  * subsequently make a call to ibt_cm_proceed(). It is illegal to call
1043  * ibt_cm_proceed() on a channel that has not had the connection
1044  * establishment deferred.
1045  *
1046  * Client cannot call ibt_cm_proceed from the cm handler.
1047  */
1048 ibt_status_t ibt_cm_proceed(ibt_cm_event_type_t event, void *session_id,
1049     ibt_cm_status_t status, ibt_cm_proceed_reply_t *cm_event_data,
1050     void *priv_data, ibt_priv_data_len_t priv_data_len);
1051 
1052 /*
1053  * ibt_cm_ud_proceed
1054  *
1055  * An IBT client calls ibt_cm_ud_proceed() to proceed with an
1056  * IBT_CM_UD_EVENT_SIDR_REQ  UD event that was previously deferred by the
1057  * client returning IBT_CM_DEFER on a CM UD handler callback.
1058  * NOTE :
1059  *
1060  * Typically CM completes processing of a client's CM handler return, with
1061  * IBT_CM_DEFER status, before  processing of the corresponding
1062  * ibt_cm_ud_proceed() is started. However a race exists where by CM may not
1063  * have completed the client's handler return processing when
1064  * ibt_cm_ud_proceed() is called by a client. In this case ibt_cm_ud_proceed()
1065  * will block until processing of the client's CM handler return is complete.
1066  *
1067  * A client that returns IBT_CM_DEFER from the cm handler must
1068  * subsequently make a call to ibt_cm_ud_proceed(). It is illegal to call
1069  * ibt_cm_ud_proceed() on a channel that has not had the connection
1070  * establishment deferred.
1071  *
1072  * Client cannot call ibt_cm_ud_proceed from the cm handler.
1073  */
1074 ibt_status_t ibt_cm_ud_proceed(void *session_id, ibt_channel_hdl_t ud_channel,
1075     ibt_cm_status_t status, ibt_redirect_info_t *redirect_infop,
1076     void *priv_data, ibt_priv_data_len_t priv_data_len);
1077 
1078 
1079 /*
1080  * COMPLETION QUEUES.
1081  *
1082  * ibt_alloc_cq_sched()
1083  *	Reserve CQ scheduling class resources
1084  *
1085  * ibt_free_cq_sched()
1086  *	Free CQ scheduling class resources
1087  */
1088 ibt_status_t ibt_alloc_cq_sched(ibt_hca_hdl_t hca_hdl,
1089     ibt_cq_sched_attr_t *attr, ibt_sched_hdl_t *sched_hdl_p);
1090 
1091 ibt_status_t ibt_free_cq_sched(ibt_hca_hdl_t hca_hdl,
1092     ibt_sched_hdl_t sched_hdl, uint_t load);
1093 
1094 /*
1095  * ibt_alloc_cq()
1096  *	Allocate a completion queue.
1097  */
1098 ibt_status_t ibt_alloc_cq(ibt_hca_hdl_t hca_hdl, ibt_cq_attr_t *cq_attr,
1099     ibt_cq_hdl_t *ibt_cq_p, uint_t *real_size);
1100 
1101 /*
1102  * ibt_free_cq()
1103  *	Free allocated CQ resources.
1104  */
1105 ibt_status_t ibt_free_cq(ibt_cq_hdl_t ibt_cq);
1106 
1107 
1108 /*
1109  * ibt_enable_cq_notify()
1110  *	Enable notification requests on the specified CQ.
1111  *	Applicable for both RC and UD channels.
1112  *
1113  *	Completion notifications are disabled by setting the completion
1114  *	handler to NULL by calling ibt_set_cq_handler().
1115  */
1116 ibt_status_t ibt_enable_cq_notify(ibt_cq_hdl_t ibt_cq,
1117     ibt_cq_notify_flags_t notify_type);
1118 
1119 /*
1120  * ibt_set_cq_handler()
1121  *	Register a work request completion handler with the IBTF.
1122  *	Applicable for both RC and UD channels.
1123  *
1124  *	Completion notifications are disabled by setting the completion
1125  *	handler to NULL. When setting the handler to NULL, no additional
1126  *	calls to the CQ handler will be initiated.
1127  *
1128  *	This function does not otherwise change the state of previous
1129  *	calls to ibt_enable_cq_notify().
1130  */
1131 void ibt_set_cq_handler(ibt_cq_hdl_t ibt_cq,
1132     ibt_cq_handler_t completion_handler, void *arg);
1133 
1134 /*
1135  * ibt_poll_cq()
1136  *	Poll the specified CQ for the completion of work requests (WRs).
1137  *	If the CQ contains completed WRs, up to num_wc of them are returned.
1138  *	Applicable for both RC and UD channels.
1139  */
1140 ibt_status_t ibt_poll_cq(ibt_cq_hdl_t ibt_cq, ibt_wc_t *work_completions,
1141     uint_t num_wc, uint_t *num_polled);
1142 
1143 /*
1144  * ibt_query_cq()
1145  *	Return the total number of entries in the CQ.
1146  */
1147 ibt_status_t ibt_query_cq(ibt_cq_hdl_t ibt_cq, uint_t *entries);
1148 
1149 /*
1150  * ibt_resize_cq()
1151  *	Change the size of a CQ.
1152  */
1153 ibt_status_t ibt_resize_cq(ibt_cq_hdl_t ibt_cq, uint_t new_sz, uint_t *real_sz);
1154 
1155 /*
1156  * ibt_set_cq_private()
1157  * ibt_get_cq_private()
1158  *	Set/get the client private data.
1159  */
1160 void ibt_set_cq_private(ibt_cq_hdl_t ibt_cq, void *clnt_private);
1161 void *ibt_get_cq_private(ibt_cq_hdl_t ibt_cq);
1162 
1163 
1164 /*
1165  * Memory Management Functions.
1166  *	Applicable for both RC and UD channels.
1167  *
1168  * ibt_register_mr()
1169  * 	Prepares a virtually addressed memory region for use by a HCA. A
1170  *	description of the registered memory suitable for use in Work Requests
1171  *	(WRs) is returned in the ibt_mr_desc_t parameter.
1172  *
1173  * ibt_register_buf()
1174  * 	Prepares a memory region described by a buf(9S) struct for use by a
1175  *	HCA. A description of the registered memory suitable for use in
1176  *	Work Requests (WRs) is returned in the ibt_mr_desc_t parameter.
1177  *
1178  * ibt_query_mr()
1179  *	Retrieves information about a specified memory region.
1180  *
1181  * ibt_deregister_mr()
1182  *	Remove a memory region from a HCA translation table, and free all
1183  *	resources associated with the memory region.
1184  *
1185  * ibt_reregister_mr()
1186  * ibt_reregister_buf()
1187  *	Modify the attributes of an existing memory region.
1188  *
1189  * ibt_register_shared_mr()
1190  *	Given an existing memory region, a new memory region associated with
1191  *	the same physical locations is created.
1192  *
1193  * ibt_sync_mr()
1194  *	Sync a memory region for either RDMA reads or RDMA writes
1195  *
1196  * ibt_alloc_mw()
1197  *	Allocate a memory window.
1198  *
1199  * ibt_query_mw()
1200  *	Retrieves information about a specified memory window.
1201  *
1202  * ibt_free_mw()
1203  *	De-allocate the Memory Window.
1204  */
1205 ibt_status_t ibt_register_mr(ibt_hca_hdl_t hca_hdl, ibt_pd_hdl_t pd,
1206     ibt_mr_attr_t *mem_attr, ibt_mr_hdl_t *mr_hdl_p, ibt_mr_desc_t *mem_desc);
1207 
1208 ibt_status_t ibt_register_buf(ibt_hca_hdl_t hca_hdl, ibt_pd_hdl_t pd,
1209     ibt_smr_attr_t *mem_bpattr, struct buf *bp, ibt_mr_hdl_t *mr_hdl_p,
1210     ibt_mr_desc_t *mem_desc);
1211 
1212 ibt_status_t ibt_query_mr(ibt_hca_hdl_t hca_hdl, ibt_mr_hdl_t mr_hdl,
1213     ibt_mr_query_attr_t *attr);
1214 
1215 ibt_status_t ibt_deregister_mr(ibt_hca_hdl_t hca_hdl, ibt_mr_hdl_t mr_hdl);
1216 
1217 ibt_status_t ibt_reregister_mr(ibt_hca_hdl_t hca_hdl, ibt_mr_hdl_t mr_hdl,
1218     ibt_pd_hdl_t pd, ibt_mr_attr_t *mem_attr, ibt_mr_hdl_t *mr_hdl_p,
1219     ibt_mr_desc_t *mem_desc);
1220 
1221 ibt_status_t ibt_reregister_buf(ibt_hca_hdl_t hca_hdl, ibt_mr_hdl_t mr_hdl,
1222     ibt_pd_hdl_t pd, ibt_smr_attr_t *mem_bpattr, struct buf *bp,
1223     ibt_mr_hdl_t *mr_hdl_p, ibt_mr_desc_t *mem_desc);
1224 
1225 ibt_status_t ibt_register_shared_mr(ibt_hca_hdl_t hca_hdl, ibt_mr_hdl_t mr_hdl,
1226     ibt_pd_hdl_t pd, ibt_smr_attr_t *mem_sattr, ibt_mr_hdl_t *mr_hdl_p,
1227     ibt_mr_desc_t *mem_desc);
1228 
1229 ibt_status_t ibt_sync_mr(ibt_hca_hdl_t hca_hdl, ibt_mr_sync_t *mr_segments,
1230     size_t num_segments);
1231 
1232 ibt_status_t ibt_alloc_mw(ibt_hca_hdl_t hca_hdl, ibt_pd_hdl_t pd,
1233     ibt_mw_flags_t flags, ibt_mw_hdl_t *mw_hdl_p, ibt_rkey_t *rkey);
1234 
1235 ibt_status_t ibt_query_mw(ibt_hca_hdl_t hca_hdl, ibt_mw_hdl_t mw_hdl,
1236     ibt_mw_query_attr_t *mw_attr_p);
1237 
1238 ibt_status_t ibt_free_mw(ibt_hca_hdl_t hca_hdl, ibt_mw_hdl_t mw_hdl);
1239 
1240 /*
1241  * ibt_alloc_lkey()
1242  * 	Allocates physical buffer list resources for use in memory
1243  *	registrations.
1244  *
1245  *	Applicable for both RC and UD channels.
1246  */
1247 ibt_status_t ibt_alloc_lkey(ibt_hca_hdl_t hca_hdl, ibt_pd_hdl_t pd,
1248     ibt_lkey_flags_t flags, uint_t phys_buf_list_sz, ibt_mr_hdl_t *mr_p,
1249     ibt_pmr_desc_t *mem_desc_p);
1250 
1251 
1252 /*
1253  * Physical Memory Management Functions.
1254  *	Applicable for both RC and UD channels.
1255  *
1256  * ibt_register_phys_mr()
1257  *	Prepares a physically addressed memory region for use by a HCA.
1258  *
1259  * ibt_reregister_phys_mr()
1260  *	Modify the attributes of an existing memory region.
1261  */
1262 ibt_status_t ibt_register_phys_mr(ibt_hca_hdl_t hca_hdl, ibt_pd_hdl_t pd,
1263     ibt_pmr_attr_t *mem_pattr, ibt_mr_hdl_t *mr_hdl_p,
1264     ibt_pmr_desc_t *mem_desc_p);
1265 
1266 ibt_status_t ibt_reregister_phys_mr(ibt_hca_hdl_t hca_hdl, ibt_mr_hdl_t mr_hdl,
1267     ibt_pd_hdl_t pd, ibt_pmr_attr_t *mem_pattr, ibt_mr_hdl_t *mr_hdl_p,
1268     ibt_pmr_desc_t *mem_desc_p);
1269 
1270 
1271 /*
1272  * Address Translation.
1273  */
1274 
1275 /*
1276  * ibt_map_mem_area()
1277  *	Translate a kernel virtual address range into HCA physical addresses.
1278  *	A set of physical addresses, that can be used with "Reserved L_Key",
1279  *	register physical,  and "Fast Registration Work Request" operations
1280  *	is returned.
1281  */
1282 ibt_status_t ibt_map_mem_area(ibt_hca_hdl_t hca_hdl, ibt_va_attr_t *va_attrs,
1283     uint_t paddr_list_len, ibt_phys_buf_t *paddr_list_p, uint_t *num_paddr_p,
1284     size_t *paddr_bufsz_p, ib_memlen_t *paddr_offset_p, ibt_ma_hdl_t *ma_hdl_p);
1285 
1286 /*
1287  * ibt_unmap_mem_area()
1288  *	Un pin physical pages pinned during an ibt_map_mem_area() call.
1289  */
1290 ibt_status_t ibt_unmap_mem_area(ibt_hca_hdl_t hca_hdl, ibt_ma_hdl_t ma_hdl);
1291 
1292 /*
1293  * Work Request Functions
1294  *	Applicable for RC and UD channels.
1295  *
1296  * ibt_post_send()
1297  *	Post send work requests to the specified channel.
1298  *
1299  * ibt_post_recv()
1300  * ibt_post_srq()
1301  *	Post receive work requests to the specified channel.
1302  */
1303 ibt_status_t ibt_post_send(ibt_channel_hdl_t chan, ibt_send_wr_t *wr_list,
1304     uint_t num_wr, uint_t *posted);
1305 
1306 ibt_status_t ibt_post_recv(ibt_channel_hdl_t chan, ibt_recv_wr_t *wr_list,
1307     uint_t num_wr, uint_t *posted);
1308 
1309 ibt_status_t ibt_post_srq(ibt_srq_hdl_t srq, ibt_recv_wr_t *wr_list,
1310     uint_t num_wr, uint_t *posted);
1311 
1312 
1313 /*
1314  * Alternate Path Migration Functions.
1315  *	Applicable for RC channels only.
1316  *
1317  *
1318  * ibt_get_alt_path()
1319  *	Finds the best alternate path to a specified channel (as determined by
1320  *	the IBTL) that satisfies the requirements specified in an
1321  *	ibt_alt_path_attr_t struct.  The specified channel must have been
1322  *	previously opened successfully using ibt_open_rc_channel.
1323  *	This function also ensures that the service being accessed by the
1324  *	channel is available at the selected alternate port.
1325  *
1326  *	Note: The apa_dgid must be on the same destination channel adapter,
1327  *	if specified.
1328  *
1329  *
1330  * ibt_set_alt_path()
1331  *	Load the specified alternate path. Causes the CM to send an LAP message
1332  *	to the remote node. If successful, the local channel is updated with
1333  *	the new alternate path and the channel migration state is set to REARM.
1334  *	Can only be called on a previously opened RC channel. The channel must
1335  *	be either in RTS or paused state.
1336  *
1337  *
1338  * ibt_migrate_path()
1339  *	Force the CI to use the alternate path. The alternate path becomes
1340  *	the primary path. A new alternate path should be loaded and enabled.
1341  */
1342 ibt_status_t ibt_get_alt_path(ibt_channel_hdl_t rc_chan, ibt_path_flags_t flags,
1343     ibt_alt_path_attr_t *attr, ibt_alt_path_info_t *alt_pathp);
1344 
1345 ibt_status_t ibt_set_alt_path(ibt_channel_hdl_t rc_chan,
1346     ibt_execution_mode_t mode, ibt_alt_path_info_t *alt_pinfo, void *priv_data,
1347     ibt_priv_data_len_t priv_data_len, ibt_ap_returns_t *ret_args);
1348 
1349 ibt_status_t ibt_migrate_path(ibt_channel_hdl_t rc_chan);
1350 
1351 
1352 /*
1353  * Multicast group Functions.
1354  *	Applicable for UD channels only.
1355  */
1356 
1357 /*
1358  * ibt_attach_mcg()
1359  *	Attaches a UD channel to the specified multicast group. On successful
1360  *	completion, this channel will be provided with a copy of every
1361  *	multicast message addressed to the group specified by the MGID
1362  *	(mcg_info->mc_adds_vect.av_dgid) and received on the HCA port with
1363  *	which the channel is associated.
1364  */
1365 ibt_status_t ibt_attach_mcg(ibt_channel_hdl_t ud_chan,
1366     ibt_mcg_info_t *mcg_info);
1367 
1368 /*
1369  * ibt_detach_mcg()
1370  *	Detach the specified UD channel from the specified multicast group.
1371  */
1372 ibt_status_t ibt_detach_mcg(ibt_channel_hdl_t ud_chan,
1373     ibt_mcg_info_t *mcg_info);
1374 
1375 /*
1376  * ibt_join_mcg()
1377  *	Join a multicast group.  The first full member "join" causes the MCG
1378  *	to be created.
1379  */
1380 ibt_status_t ibt_join_mcg(ib_gid_t rgid, ibt_mcg_attr_t *mcg_attr,
1381     ibt_mcg_info_t *mcg_info_p,  ibt_mcg_handler_t func, void  *arg);
1382 
1383 /*
1384  * ibt_leave_mcg()
1385  *	The port associated with the port GID shall be removed from the
1386  *	multicast group specified by MGID (mc_gid) or from all the multicast
1387  *	groups of which it is a member if the MGID (mc_gid) is not specified
1388  *	(i.e. mc_gid.mgid_prefix must have 8-bits of 11111111 at the start of
1389  *	the GID to identify this as being a multicast GID).
1390  *
1391  *	The last full member to leave causes the destruction of the Multicast
1392  *	Group.
1393  */
1394 ibt_status_t ibt_leave_mcg(ib_gid_t rgid, ib_gid_t mc_gid, ib_gid_t port_gid,
1395     uint8_t mc_join_state);
1396 
1397 /*
1398  * ibt_query_mcg()
1399  *	Request information on multicast groups that match the parameters
1400  *	specified in mcg_attr. Information on each multicast group is returned
1401  *	to the caller in the form of an array of ibt_mcg_info_t.
1402  *	ibt_query_mcg() allocates the memory for this array and returns a
1403  *	pointer to the array (mcgs_p) and the number of entries in the array
1404  *	(entries_p). This memory should be freed by the client using
1405  *	ibt_free_mcg_info().
1406  */
1407 ibt_status_t ibt_query_mcg(ib_gid_t rgid, ibt_mcg_attr_t *mcg_attr,
1408     uint_t mcgs_max_num, ibt_mcg_info_t **mcgs_info_p, uint_t *entries_p);
1409 
1410 /*
1411  * ibt_free_mcg_info()
1412  *	Free the memory allocated by successful ibt_query_mcg()
1413  */
1414 void ibt_free_mcg_info(ibt_mcg_info_t *mcgs_info, uint_t entries);
1415 
1416 
1417 /*
1418  * ibt_register_subnet_notices()
1419  *	Register a handler to be called for subnet notifications.
1420  */
1421 void ibt_register_subnet_notices(ibt_clnt_hdl_t ibt_hdl,
1422     ibt_sm_notice_handler_t sm_notice_handler, void *private);
1423 
1424 
1425 /*
1426  * Protection Domain Functions.
1427  *
1428  * ibt_alloc_pd()
1429  * ibt_free_pd()
1430  * 	Allocate/Release a protection domain
1431  */
1432 ibt_status_t ibt_alloc_pd(ibt_hca_hdl_t hca_hdl, ibt_pd_flags_t flags,
1433     ibt_pd_hdl_t *pd);
1434 ibt_status_t ibt_free_pd(ibt_hca_hdl_t hca_hdl, ibt_pd_hdl_t pd);
1435 
1436 /*
1437  * P_Key to P_Key Index conversion Functions.
1438  *
1439  * ibt_pkey2index_byguid
1440  * ibt_pkey2index	Convert a P_Key into a P_Key index.
1441  *
1442  * ibt_index2pkey_byguid
1443  * ibt_index2pkey	Convert a P_Key Index into a P_Key.
1444  */
1445 ibt_status_t ibt_pkey2index(ibt_hca_hdl_t hca_hdl, uint8_t port_num,
1446     ib_pkey_t pkey, uint16_t *pkey_ix);
1447 
1448 ibt_status_t ibt_index2pkey(ibt_hca_hdl_t hca_hdl, uint8_t port_num,
1449     uint16_t pkey_ix, ib_pkey_t *pkey);
1450 
1451 ibt_status_t ibt_pkey2index_byguid(ib_guid_t hca_guid, uint8_t port_num,
1452     ib_pkey_t pkey, uint16_t *pkey_ix);
1453 
1454 ibt_status_t ibt_index2pkey_byguid(ib_guid_t hca_guid, uint8_t port_num,
1455     uint16_t pkey_ix, ib_pkey_t *pkey);
1456 
1457 /*
1458  *  ibt_ci_data_in()
1459  *
1460  *  Pass CI specific userland data for CI objects to the CI.
1461  */
1462 ibt_status_t ibt_ci_data_in(ibt_hca_hdl_t hca, ibt_ci_data_flags_t flags,
1463     ibt_object_type_t object, void *ibt_object_handle, void *data_p,
1464     size_t data_sz);
1465 
1466 /*
1467  *  ibt_ci_data_out()
1468  *
1469  *  Obtain CI specific userland data for CI objects.
1470  */
1471 ibt_status_t ibt_ci_data_out(ibt_hca_hdl_t hca, ibt_ci_data_flags_t flags,
1472     ibt_object_type_t object, void *ibt_object_handle, void *data_p,
1473     size_t data_sz);
1474 
1475 
1476 /*
1477  * Node Information.
1478  */
1479 
1480 /* Node type : n_node_type */
1481 #define	IBT_NODE_TYPE_CHANNEL_ADAPTER	1	/* HCA or TCA */
1482 #define	IBT_NODE_TYPE_SWITCH		2
1483 #define	IBT_NODE_TYPE_ROUTER		3
1484 
1485 typedef struct ibt_node_info_s {
1486 	ib_guid_t	n_sys_img_guid;	/* System Image GUID */
1487 	ib_guid_t	n_node_guid;	/* Node GUID */
1488 	ib_guid_t	n_port_guid;	/* Port GUID */
1489 	uint16_t	n_dev_id;	/* Device ID */
1490 	uint32_t	n_revision;	/* Device Revision */
1491 	uint32_t	n_vendor_id:24;	/* Device Vendor ID */
1492 	uint8_t		n_num_ports;	/* Number of ports on this node. */
1493 	uint8_t		n_port_num;	/* Port number. */
1494 	uint8_t		n_node_type;	/* Node type */
1495 	char		n_description[64]; /* NULL terminated ASCII string */
1496 } ibt_node_info_t;
1497 
1498 
1499 /*
1500  * ibt_gid_to_node_info()
1501  *	Retrieve node information for the specified GID.
1502  */
1503 ibt_status_t ibt_gid_to_node_info(ib_gid_t gid, ibt_node_info_t *node_info_p);
1504 
1505 /*
1506  * ibt_reprobe_dev
1507  *	Reprobe properties for IOC device node.
1508  */
1509 ibt_status_t	ibt_reprobe_dev(dev_info_t *dip);
1510 
1511 /*
1512  * ibt_get_companion_port_gids()
1513  *
1514  *	Get list of GID's available on a companion port(s) of the specified
1515  *	GID or list of GIDs available on a specified Node GUID/System Image
1516  *	GUID.
1517  */
1518 ibt_status_t ibt_get_companion_port_gids(ib_gid_t gid, ib_guid_t hca_guid,
1519     ib_guid_t sysimg_guid, ib_gid_t **gids_p, uint_t *num_gids_p);
1520 
1521 /*
1522  * SHARED RECEIVE QUEUE
1523  */
1524 
1525 
1526 /*
1527  * ibt_alloc_srq()
1528  *	Allocate a shared receive queue.
1529  */
1530 ibt_status_t ibt_alloc_srq(ibt_hca_hdl_t hca_hdl, ibt_srq_flags_t flags,
1531     ibt_pd_hdl_t pd, ibt_srq_sizes_t *sizes, ibt_srq_hdl_t *ibt_srq_p,
1532     ibt_srq_sizes_t *real_size_p);
1533 
1534 /*
1535  * ibt_free_srq()
1536  *	Free allocated SRQ resources.
1537  */
1538 ibt_status_t ibt_free_srq(ibt_srq_hdl_t ibt_srq);
1539 
1540 /*
1541  * ibt_query_srq()
1542  *	Query a shared receive queue.
1543  */
1544 ibt_status_t ibt_query_srq(ibt_srq_hdl_t ibt_srq, ibt_pd_hdl_t *pd_p,
1545     ibt_srq_sizes_t *sizes_p, uint_t *limit_p);
1546 
1547 /*
1548  * ibt_modify_srq()
1549  *	Modify a shared receive queue.
1550  */
1551 ibt_status_t ibt_modify_srq(ibt_srq_hdl_t ibt_srq, ibt_srq_modify_flags_t flags,
1552     uint_t size, uint_t limit, uint_t *real_size_p);
1553 
1554 /*
1555  * ibt_set_srq_private()
1556  * ibt_get_srq_private()
1557  *	Set/get the SRQ client private data.
1558  */
1559 void ibt_set_srq_private(ibt_srq_hdl_t ibt_srq, void *clnt_private);
1560 void *ibt_get_srq_private(ibt_srq_hdl_t ibt_srq);
1561 
1562 /*
1563  * ibt_check_failure()
1564  * 	Function to test for special case failures
1565  */
1566 ibt_failure_type_t ibt_check_failure(ibt_status_t status, uint64_t *reserved_p);
1567 
1568 
1569 /*
1570  * ibt_hw_is_present() returns 0 when there is no IB hardware actively
1571  * running.  This is primarily useful for modules like rpcmod which needs a
1572  * quick check to decide whether or not it should try to use InfiniBand.
1573  */
1574 int ibt_hw_is_present();
1575 
1576 /*
1577  * Fast Memory Registration (FMR).
1578  *
1579  * ibt_create_fmr_pool
1580  *	Not fast-path.
1581  *	ibt_create_fmr_pool() verifies that the HCA supports FMR and allocates
1582  *	and initializes an "FMR pool".  This pool contains state specific to
1583  *	this registration, including the watermark setting to determine when
1584  *	to sync, and the total number of FMR regions available within this pool.
1585  *
1586  * ibt_destroy_fmr_pool
1587  *	ibt_destroy_fmr_pool() deallocates all of the FMR regions in a specific
1588  *	pool.  All state and information regarding the pool are destroyed and
1589  *	returned as free space once again.  No more use of FMR regions in this
1590  *	pool are possible without a subsequent call to ibt_create_fmr_pool().
1591  *
1592  * ibt_flush_fmr_pool
1593  *	ibt_flush_fmr_pool forces a flush to occur.  At the client's request,
1594  *	any unmapped FMR regions (See 'ibt_deregister_mr())') are returned to
1595  *	a free state.  This function allows for an asynchronous cleanup of
1596  *	formerly used FMR regions.  Sync operation is also performed internally
1597  *	by HCA driver, when 'watermark' settings for the number of free FMR
1598  *	regions left in the "pool" is reached.
1599  *
1600  * ibt_register_physical_fmr
1601  *	ibt_register_physical_fmr() assigns a "free" entry from the FMR Pool.
1602  *	It first consults the "FMR cache" to see if this is a duplicate memory
1603  *	registration to something already in use.  If not, then a free entry
1604  *	in the "pool" is marked used.
1605  *
1606  * ibt_deregister_fmr
1607  *	The ibt_deregister_fmr un-maps the resources reserved from the FMR
1608  *	pool by ibt_register_physical_fmr().   The ibt_deregister_fmr() will
1609  *	mark the region as free in the FMR Pool.
1610  */
1611 ibt_status_t ibt_create_fmr_pool(ibt_hca_hdl_t hca_hdl, ibt_pd_hdl_t pd,
1612     ibt_fmr_pool_attr_t *fmr_params, ibt_fmr_pool_hdl_t *fmr_pool_p);
1613 
1614 ibt_status_t ibt_destroy_fmr_pool(ibt_hca_hdl_t hca_hdl,
1615     ibt_fmr_pool_hdl_t fmr_pool);
1616 
1617 ibt_status_t ibt_flush_fmr_pool(ibt_hca_hdl_t hca_hdl,
1618     ibt_fmr_pool_hdl_t fmr_pool);
1619 
1620 ibt_status_t ibt_register_physical_fmr(ibt_hca_hdl_t hca_hdl,
1621     ibt_fmr_pool_hdl_t fmr_pool, ibt_pmr_attr_t *mem_pattr,
1622     ibt_mr_hdl_t *mr_hdl_p, ibt_pmr_desc_t *mem_desc_p);
1623 
1624 ibt_status_t ibt_deregister_fmr(ibt_hca_hdl_t hca, ibt_mr_hdl_t mr_hdl);
1625 
1626 /*
1627  * IP SUPPORT
1628  */
1629 
1630 /*
1631  * IP get_paths
1632  * Returns an array (or single) of paths and source IP addresses. In the
1633  * simplest form just the destination IP address is specified, and one path
1634  * is requested, then one ibt_path_info_t struct and one source IP.
1635  *
1636  * More than one path can be requested to a single destination, in which case
1637  * the requested number of ibt_path_info_t's are returned, and the same
1638  * number of SRC IP address, with the first SRC IP address corrosponding
1639  * to the first ibt_path_info_t, etc.
1640  *
1641  * Restrictions on the source end point can be specified, in the form of a
1642  * source IP address (this implicitly defines the HCA, HCA port and Pkey)
1643  * HCA, HCA port, and sgid (implicitly defines HCA and HCA port).
1644  * Combinations are allowed but they  must be consistent.
1645  *
1646  * Path attributes can also be specified, these can also affect local HCA
1647  * selection.
1648  *
1649  * ibt_get_ip_paths()  internally does (among other things):
1650  *
1651  *   o ibt_get_list_of_ibd_ipaddr_and_macaddr( OUT list_ipaddr_macaddr)
1652  *
1653  *   o extract_pkey_and_sgid(IN list_ipaddr_macaddr, OUT list_pkey_and_sgid)
1654  *
1655  *   o map_dst_ip_addr(IN dst_ip_addr, OUT dst_pkey, OUT dgid) - See Note
1656  *
1657  *   o filter_by_pkey(IN list_pkey_and_sgid, IN dst_pkey, OUT list_of_sgid)
1658  *
1659  *   o do_multipath_query(IN list_of_sgid, IN dst_pkey, IN dgid, OUT path_list)
1660  *
1661  *   o pick_a_good_path(IN path_list, OUT the_path)
1662  *
1663  *   o find_matching_src_ip(IN the_path, IN list_ipaddr_macaddr, OUT src_ip)
1664  *
1665  * The ibd instance which got the ARP response is only on one P_Key
1666  * knowing the ibd instance (or which IPonIB MCG) got the ARP response
1667  * determins the P_Key associated with a dgid. If the proposedi "ip2mac()"
1668  * API is used to get an IP to GID translations, then returned 'sockaddr_dl'
1669  * contains the interface name and index.
1670  *
1671  *
1672  * Example:
1673  *   ip_path_attr.ipa_dst_ip = dst_ip_addr;
1674  *   ip_path_attr.ipa_ndst = 1;
1675  *   ip_path_attr.ipa_max_paths = 1;
1676  *
1677  *   status = ibt_get_ip_paths(clnt_hdl, flags, &ip_path_attr, &paths,
1678  *      &num_paths_p, &src_ip);
1679  *
1680  *   sid = ibt_get_ip_sid(protocol_num, dst_port);
1681  *   path_info->sid = sid;
1682  *
1683  *   ip_cm_info.src_addr = src_ip;
1684  *   ip_cm_info.dst_addr = dst_ip_addr;
1685  *   ip_cm_info.src_port = src_port
1686  *
1687  *   ibt_format_ip_private_data(ip_cm_info, priv_data_len, &priv_data);
1688  *   ibt_open_rc_channel(chan, private_data);
1689  */
1690 typedef struct ibt_ip_path_attr_s {
1691 	ibt_ip_addr_t		*ipa_dst_ip;		/* Required */
1692 	ibt_ip_addr_t		ipa_src_ip;		/* Optional */
1693 	ib_guid_t		ipa_hca_guid;		/* Optional */
1694 	uint8_t			ipa_hca_port_num;	/* Optional */
1695 	uint8_t			ipa_max_paths;		/* Required */
1696 	uint8_t			ipa_ndst;		/* Required */
1697 	uint8_t			ipa_sl:4;		/* Optional */
1698 	ibt_mtu_req_t		ipa_mtu;		/* Optional */
1699 	ibt_srate_req_t		ipa_srate;		/* Optional */
1700 	ibt_pkt_lt_req_t	ipa_pkt_lt;		/* Optional */
1701 	uint_t			ipa_flow:20;		/* Optional */
1702 	uint8_t			ipa_hop;		/* Optional */
1703 	uint8_t			ipa_tclass;		/* Optional */
1704 } ibt_ip_path_attr_t;
1705 
1706 /*
1707  * Path SRC IP addresses
1708  */
1709 typedef struct ibt_path_ip_src_s {
1710 	ibt_ip_addr_t	ip_primary;
1711 	ibt_ip_addr_t	ip_alternate;
1712 } ibt_path_ip_src_t;
1713 
1714 
1715 ibt_status_t ibt_get_ip_paths(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags,
1716     ibt_ip_path_attr_t *attr, ibt_path_info_t *paths_p, uint8_t *num_paths_p,
1717     ibt_path_ip_src_t *src_ip_p);
1718 
1719 ibt_status_t ibt_get_src_ip(ib_gid_t gid, ib_pkey_t pkey,
1720     ibt_ip_addr_t *src_ip);
1721 
1722 /*
1723  * Callback function that can be used in ibt_aget_ip_paths(), a Non-Blocking
1724  * version of ibt_get_ip_paths().
1725  */
1726 typedef void (*ibt_ip_path_handler_t)(void *arg, ibt_status_t retval,
1727     ibt_path_info_t *paths_p, uint8_t num_paths, ibt_path_ip_src_t *src_ip_p);
1728 
1729 /*
1730  * Find path(s) to a given destination or service asynchronously.
1731  * ibt_aget_ip_paths() is a Non-Blocking version of ibt_get_ip_paths().
1732  */
1733 ibt_status_t ibt_aget_ip_paths(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags,
1734     ibt_ip_path_attr_t *attr, ibt_ip_path_handler_t func, void  *arg);
1735 
1736 /*
1737  * IP RDMA protocol functions
1738  */
1739 
1740 /*
1741  * IBTF manages the port number space for non well known ports. If a ULP
1742  * is not using TCP/UDP and a well known port, then ibt_get_ip_sid() returns
1743  * an sid based on the IP protocol number '0' (reserved) and an IBTF assigned
1744  * port number.  ibt_release_ip_sid() should be used to release the hold
1745  * of SID created by ibt_get_ip_sid().
1746  */
1747 ib_svc_id_t ibt_get_ip_sid(uint8_t protocol_num, in_port_t dst_port);
1748 ibt_status_t ibt_release_ip_sid(ib_svc_id_t sid);
1749 
1750 uint8_t ibt_get_ip_protocol_num(ib_svc_id_t sid);
1751 in_port_t ibt_get_ip_dst_port(ib_svc_id_t sid);
1752 
1753 /*
1754  * Functions to format/extract the RDMA IP CM private data
1755  */
1756 typedef struct ibt_ip_cm_info_s {
1757 	ibt_ip_addr_t	src_addr;
1758 	ibt_ip_addr_t	dst_addr;
1759 	in_port_t	src_port;
1760 } ibt_ip_cm_info_t;
1761 
1762 /*
1763  * If a ULP is using IP addressing as defined by the RDMA IP CM Service IBTA
1764  * Annex 11, then it must always allocate a private data buffer for use in
1765  * the ibt_open_rc_channel(9F) call. The minimum size of the buffer is
1766  * IBT_IP_HDR_PRIV_DATA_SZ, if the ULP has no ULP specific private data.
1767  * This allows ibt_format_ip_private_data() to place the RDMA IP CM service
1768  * hello message in the private data of the REQ. If the ULP has some ULP
1769  * specific private data then it should allocate a buffer big enough to
1770  * contain that data plus an additional IBT_IP_HDR_PRIV_DATA_SZ bytes.
1771  * The ULP should place its  ULP specific private data at offset
1772  * IBT_IP_HDR_PRIV_DATA_SZ in the allocated buffer before calling
1773  * ibt_format_ip_private_data().
1774  */
1775 ibt_status_t ibt_format_ip_private_data(ibt_ip_cm_info_t *ip_cm_info,
1776     ibt_priv_data_len_t priv_data_len, void *priv_data_p);
1777 ibt_status_t ibt_get_ip_data(ibt_priv_data_len_t priv_data_len,
1778     void *priv_data, ibt_ip_cm_info_t *ip_info_p);
1779 
1780 /*
1781  * The ibt_alt_ip_path_attr_t structure is used to specify additional optional
1782  * attributes when requesting an alternate path for an existing channel.
1783  *
1784  * Attributes that are don't care should be set to NULL or '0'.
1785  */
1786 typedef struct ibt_alt_ip_path_attr_s {
1787 	ibt_ip_addr_t		apa_dst_ip;
1788 	ibt_ip_addr_t		apa_src_ip;
1789 	ibt_srate_req_t		apa_srate;
1790 	ibt_pkt_lt_req_t	apa_pkt_lt;	/* Packet Life Time Request */
1791 	uint_t			apa_flow:20;
1792 	uint8_t			apa_sl:4;
1793 	uint8_t			apa_hop;
1794 	uint8_t			apa_tclass;
1795 } ibt_alt_ip_path_attr_t;
1796 
1797 ibt_status_t ibt_get_ip_alt_path(ibt_channel_hdl_t rc_chan,
1798     ibt_path_flags_t flags, ibt_alt_ip_path_attr_t *attr,
1799     ibt_alt_path_info_t *alt_path);
1800 
1801 /*
1802  * CONTRACT PRIVATE ONLY INTERFACES
1803  *
1804  * DO NOT USE THE FOLLOWING FUNCTIONS WITHOUT SIGNING THE CONTRACT
1805  * WITH IBTF GROUP.
1806  */
1807 
1808 /* Define an Address Record structure (data for ATS service records). */
1809 typedef struct ibt_ar_s {
1810 	ib_gid_t	ar_gid;		/* GID of local HCA port */
1811 	ib_pkey_t	ar_pkey;	/* P_Key valid on port of ar_gid */
1812 	uint8_t		ar_data[16];	/* Data affiliated with GID/P_Key */
1813 } ibt_ar_t;
1814 
1815 /*
1816  * ibt_register_ar()
1817  * ibt_deregister_ar()
1818  *	Register/deregister an Address Record with the SA.
1819  * ibt_query_ar()
1820  *	Query the SA for Address Records matching either GID/P_Key or Data.
1821  */
1822 ibt_status_t ibt_register_ar(ibt_clnt_hdl_t ibt_hdl, ibt_ar_t *arp);
1823 
1824 ibt_status_t ibt_deregister_ar(ibt_clnt_hdl_t ibt_hdl, ibt_ar_t *arp);
1825 
1826 ibt_status_t ibt_query_ar(ib_gid_t *sgid, ibt_ar_t *queryp, ibt_ar_t *resultp);
1827 
1828 
1829 /*
1830  * ibt_modify_system_image()
1831  * ibt_modify_system_image_byguid()
1832  *	Modify specified HCA's system image GUID.
1833  */
1834 ibt_status_t ibt_modify_system_image(ibt_hca_hdl_t hca_hdl, ib_guid_t sys_guid);
1835 
1836 ibt_status_t ibt_modify_system_image_byguid(ib_guid_t hca_guid,
1837     ib_guid_t sys_guid);
1838 
1839 
1840 /*
1841  * ibt_modify_port()
1842  * ibt_modify_port_byguid()
1843  *	Modify the specified port, or all ports attribute(s).
1844  */
1845 ibt_status_t ibt_modify_port(ibt_hca_hdl_t hca_hdl, uint8_t port,
1846     ibt_port_modify_flags_t flags, uint8_t init_type);
1847 
1848 ibt_status_t ibt_modify_port_byguid(ib_guid_t hca_guid, uint8_t port,
1849     ibt_port_modify_flags_t flags, uint8_t init_type);
1850 
1851 
1852 /*
1853  * ibt_get_port_state()
1854  * ibt_get_port_state_byguid()
1855  *	Return the most commonly requested attributes of an HCA port.
1856  *	If the link state is not IBT_PORT_ACTIVE, the other returned values
1857  *	are undefined.
1858  */
1859 ibt_status_t ibt_get_port_state(ibt_hca_hdl_t hca_hdl, uint8_t port,
1860     ib_gid_t *sgid_p, ib_lid_t *base_lid_p);
1861 
1862 ibt_status_t ibt_get_port_state_byguid(ib_guid_t hca_guid, uint8_t port,
1863     ib_gid_t *sgid_p, ib_lid_t *base_lid_p);
1864 
1865 #ifdef __cplusplus
1866 }
1867 #endif
1868 
1869 #endif /* _SYS_IB_IBTL_IBTI_COMMON_H */
1870