xref: /titanic_51/usr/src/uts/common/sys/ib/ibnex/ibnex.h (revision d9638e547d8811f2c689977f8dd2a353938b61fd)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_IB_IBNEX_IBNEX_H
28 #define	_SYS_IB_IBNEX_IBNEX_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * ibnex.h
34  * This file contains defines and structures used within the IB Nexus
35  */
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #include <sys/sunndi.h>
42 
43 /* Defines for return codes within the IB nexus driver */
44 typedef enum {
45 	IBNEX_SUCCESS =	0,
46 	IBNEX_FAILURE = -1,
47 	IBNEX_OFFLINE_FAILED = -2,
48 	IBNEX_BUSY = -3,
49 	IBNEX_INVALID_NODE = -4
50 } ibnex_rval_t;
51 
52 
53 /* IOC device node specific data */
54 typedef struct ibnex_ioc_node_s {
55 	ib_guid_t		iou_guid;	/* GUID of the IOU */
56 	ib_guid_t		ioc_guid;	/* GUID of the IOC */
57 	char			ioc_id_string[IB_DM_IOC_ID_STRING_LEN];
58 	uint32_t		ioc_ngids;
59 	/* This field will be non NULL only for diconnected IOCs */
60 	ib_dm_ioc_ctrl_profile_t	*ioc_profile;
61 } ibnex_ioc_node_t;
62 
63 /* DLPI device node specific data */
64 typedef struct ibnex_port_node_s {
65 	uint8_t			port_num;
66 	int			port_commsvc_idx;
67 	ib_guid_t		port_guid;
68 	ib_guid_t		port_hcaguid;
69 	ib_pkey_t		port_pkey;
70 } ibnex_port_node_t;
71 
72 /* Pseudo device node specific data */
73 typedef struct ibnex_pseudo_node_s {
74 	char			*pseudo_node_addr;	/* node addr of drvr */
75 	char			*pseudo_unit_addr;	/* unit addr of drvr */
76 	int			pseudo_unit_addr_len;	/* unit addr len */
77 	char			*pseudo_devi_name;	/* name of driver */
78 	int			pseudo_new_node;	/* new node */
79 	int			pseudo_merge_node;	/* merge node */
80 } ibnex_pseudo_node_t;
81 
82 /*
83  * Defines for Child device node types. Note that these values are also
84  * in use by usr/src/lib/cfgadm_plugins/ib/common/cfga_ib.h.
85  * Any changes to these need to be reflected in that file as well.
86  */
87 typedef enum {
88 	IBNEX_PORT_COMMSVC_NODE,
89 	IBNEX_VPPA_COMMSVC_NODE,
90 	IBNEX_HCASVC_COMMSVC_NODE,
91 	IBNEX_IOC_NODE,
92 	IBNEX_PSEUDO_NODE
93 } ibnex_node_type_t;
94 
95 
96 /*
97  * Defines for Child device node state:
98  *
99  * By default the node is set to CONFIGURED state.
100  *	CONFIGURED:---(bus_config/cfgadm configure)---->CONFIGURED
101  *	CONFIGURED:----(cfgadm unconfigure:success)--->UNCONFIGURED
102  *	CONFIGURED:----(cfgadm unconfigure:fail)--->still CONFIGURED
103  *	UNCONFIGURED:----(cfgadm configure:success)--->CONFIGURED
104  *
105  * We maintain two additional states:
106  *	CONFIGURING:---(bus_config/cfgadm configure in progress
107  *	UNCONFIGURING:--(cfgadm unconfigure in progress)
108  * This is maintained to avoid race conditions between multiple cfgadm
109  * operations.
110  */
111 typedef enum ibnex_node_state_e {
112 	IBNEX_CFGADM_CONFIGURED,	/* node is "configured" */
113 	IBNEX_CFGADM_UNCONFIGURED,	/* node is "unconfigured" */
114 	IBNEX_CFGADM_CONFIGURING,	/* node getting configured */
115 	IBNEX_CFGADM_UNCONFIGURING	/* node getting unconfigured */
116 } ibnex_node_state_t;
117 
118 /*
119  * Defines for reprobe_state:
120  * 	IBNEX_NODE_REPROBE_NOTIFY_ON_UPDATE
121  *		Reprobe and notify if there is a property update
122  *	IBNEX_NODE_REPROBE_NOTIFY_ALWAYS
123  *		Reprobe and notify always.
124  *	IBNEX_NODE_REPROBE_IOC_WAIT
125  *		Reprobe for IOC apid waiting
126  *
127  * Device reprobes triggered by ibt_reprobe_dev will result in an DDI
128  * event, even though no prepoerties have changed.
129  */
130 #define	IBNEX_NODE_REPROBE_NOTIFY_ON_UPDATE	0x01
131 #define	IBNEX_NODE_REPROBE_NOTIFY_ALWAYS	0x02
132 #define	IBNEX_NODE_REPROBE_IOC_WAIT			0x04
133 
134 /* Node specific information, stored as dev_info_t private data */
135 typedef struct ibnex_node_data_s {
136 	dev_info_t		*node_dip;
137 	union {
138 		ibnex_ioc_node_t	ioc_node;
139 		ibnex_port_node_t	port_node;
140 		ibnex_pseudo_node_t	pseudo_node;
141 	} node_data;
142 	struct ibnex_node_data_s *node_next;
143 	struct ibnex_node_data_s *node_prev;
144 	ibnex_node_type_t	node_type;
145 	ibnex_node_state_t	node_state;
146 	int			node_reprobe_state;	/* Node reprobe flag */
147 } ibnex_node_data_t;
148 
149 /*
150  * The fields of IOC and Port node are initialized when the
151  * device node is created. These are read only for the rest
152  * of the IBnexus driver.
153  */
154 _NOTE(SCHEME_PROTECTS_DATA("stable data", ibnex_ioc_node_s))
155 _NOTE(SCHEME_PROTECTS_DATA("stable data", ibnex_port_node_s))
156 _NOTE(SCHEME_PROTECTS_DATA("stable data", ibnex_pseudo_node_s))
157 _NOTE(SCHEME_PROTECTS_DATA("stable data", ibnex_node_data_s))
158 
159 #define	IBNEX_VALID_NODE_TYPE(n)	\
160 	(((n)->node_type == IBNEX_PORT_COMMSVC_NODE) || \
161 	((n)->node_type == IBNEX_VPPA_COMMSVC_NODE) || \
162 	((n)->node_type == IBNEX_HCASVC_COMMSVC_NODE) || \
163 	((n)->node_type == IBNEX_IOC_NODE) || \
164 	((n)->node_type == IBNEX_PSEUDO_NODE))
165 
166 #define	IBNEX_COMMSVC_NODE_TYPE(n)	\
167 	(((n)->node_type == IBNEX_PORT_COMMSVC_NODE) || \
168 	((n)->node_type == IBNEX_VPPA_COMMSVC_NODE) || \
169 	((n)->node_type == IBNEX_HCASVC_COMMSVC_NODE))
170 
171 /*
172  * Definition for the IB nexus global per-instance structure.
173  * IB nexus supports only one instance.
174  */
175 typedef struct ibnex_s {
176 	dev_info_t		*ibnex_dip;
177 	kmutex_t		ibnex_mutex;
178 	int			ibnex_num_comm_svcs;
179 	char			**ibnex_comm_svc_names;
180 	int			ibnex_nvppa_comm_svcs;
181 	char			**ibnex_vppa_comm_svc_names;
182 	int			ibnex_nhcasvc_comm_svcs;
183 	char			**ibnex_hcasvc_comm_svc_names;
184 	ibnex_node_data_t	*ibnex_port_node_head;
185 	ibnex_node_data_t	*ibnex_ioc_node_head;
186 	ibnex_node_data_t	*ibnex_pseudo_node_head;
187 
188 	/*
189 	 * NDI Event handle for -all- ibnexus events
190 	 * Event Cookie for IB_PROP_UPDATE_EVENT event
191 	 */
192 	ndi_event_hdl_t		ibnex_ndi_event_hdl;
193 	ddi_eventcookie_t	ibnex_prop_update_evt_cookie;
194 
195 	/* Flags & condition variables for reprobe handling */
196 	int					ibnex_reprobe_state;
197 	kcondvar_t			ibnex_reprobe_cv;
198 
199 	/* Count of disconnected IOCs still configured */
200 	int					ibnex_num_disconnect_iocs;
201 
202 	/* Pseudo nodes inited from ibnex_get_snapshot? */
203 	int			ibnex_pseudo_inited;
204 } ibnex_t;
205 
206 /*
207  * States for ibnex_reprobe_state
208  *	0 to REPROBE_ALL_PROGRESS
209  *		Reprobe all when no reprobes pending
210  *	REPROBE_ALL_PROGRESS to REPROBE_ALL_WAIT
211  *		Reprobe all request when another in progress
212  *	0 to REPROBE_IOC_WAIT
213  *		Waiting for One or more reprobe_ioc to complete
214  *
215  * Reprobe logic will ensure :
216  *	1. A single reprobe all at any time.
217  *	2. No individual IOC reprobe overlaps with reprobe all.
218  *	3. Reprobe for multiple IOCs can be in parallel
219  *	4. Single reprobe for each IOC.
220  */
221 #define	IBNEX_REPROBE_ALL_PROGRESS	0x01
222 #define	IBNEX_REPROBE_ALL_WAIT		0x02
223 #define	IBNEX_REPROBE_IOC_WAIT		0x04
224 
225 /* Defines for creating and binding device nodes.  */
226 #define	IBNEX_MAX_COMPAT_NAMES		6
227 #define	IBNEX_MAX_IBPORT_COMPAT_NAMES	3
228 #define	IBNEX_MAX_COMPAT_LEN		48
229 #define	IBNEX_MAX_COMPAT_PROP_SZ	\
230 	IBNEX_MAX_COMPAT_NAMES * IBNEX_MAX_COMPAT_LEN
231 #define	IBNEX_MAX_IBPORT_COMPAT_PROP_SZ	\
232 	IBNEX_MAX_IBPORT_COMPAT_NAMES * IBNEX_MAX_COMPAT_LEN
233 #define	IBNEX_DEVFS_ENUMERATE		0x1	/* enumerate via devfs(7fs) */
234 #define	IBNEX_CFGADM_ENUMERATE		0x2	/* enumerate via cfgadm */
235 
236 #define	IBNEX_MAX_NODEADDR_SZ		35
237 
238 /* Define for forming the unit address from GUID and class string */
239 #define	IBNEX_FORM_GUID(buf, size, guid) \
240 		(void) snprintf((buf), (size), "%llX", (longlong_t)guid);
241 
242 #define	IBNEX_INVALID_PKEY(pkey)	\
243 		(((pkey) == IB_PKEY_INVALID_FULL) || \
244 		((pkey) == IB_PKEY_INVALID_LIMITED))
245 
246 /*
247  * Defines for the tags of IB DDI events
248  */
249 typedef enum {
250 		IB_EVENT_TAG_PROP_UPDATE = 0
251 } ib_ddi_event_tag_t;
252 
253 /* Definations for IB HW in device tree status */
254 #define	IBNEX_DEVTREE_NOT_CHECKED	-1
255 #define	IBNEX_HW_NOT_IN_DEVTREE		0
256 #define	IBNEX_HW_IN_DEVTREE		1
257 
258 #ifdef __cplusplus
259 }
260 #endif
261 
262 #endif	/* _SYS_IB_IBNEX_IBNEX_H */
263