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