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