xref: /titanic_52/usr/src/uts/common/sys/ib/ibnex/ibnex.h (revision fa9e4066f08beec538e775443c5be79dd423fcab)
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 } ibnex_pseudo_node_t;
80 
81 /*
82  * Defines for Child device node types. Note that these values are also
83  * in use by usr/src/lib/cfgadm_plugins/ib/common/cfga_ib.h.
84  * Any changes to these need to be reflected in that file as well.
85  */
86 typedef enum {
87 	IBNEX_PORT_COMMSVC_NODE,
88 	IBNEX_VPPA_COMMSVC_NODE,
89 	IBNEX_HCASVC_COMMSVC_NODE,
90 	IBNEX_IOC_NODE,
91 	IBNEX_PSEUDO_NODE
92 } ibnex_node_type_t;
93 
94 
95 /*
96  * Defines for Child device node state:
97  *
98  * By default the node is set to CONFIGURED state.
99  *	CONFIGURED:---(bus_config/cfgadm configure)---->CONFIGURED
100  *	CONFIGURED:----(cfgadm unconfigure:success)--->UNCONFIGURED
101  *	CONFIGURED:----(cfgadm unconfigure:fail)--->still CONFIGURED
102  *	UNCONFIGURED:----(cfgadm configure:success)--->CONFIGURED
103  *
104  * We maintain two additional states:
105  *	CONFIGURING:---(bus_config/cfgadm configure in progress
106  *	UNCONFIGURING:--(cfgadm unconfigure in progress)
107  * This is maintained to avoid race conditions between multiple cfgadm
108  * operations.
109  */
110 typedef enum ibnex_node_state_e {
111 	IBNEX_CFGADM_CONFIGURED,	/* node is "configured" */
112 	IBNEX_CFGADM_UNCONFIGURED,	/* node is "unconfigured" */
113 	IBNEX_CFGADM_CONFIGURING,	/* node getting configured */
114 	IBNEX_CFGADM_UNCONFIGURING	/* node getting unconfigured */
115 } ibnex_node_state_t;
116 
117 /*
118  * Defines for reprobe_state:
119  * 	IBNEX_NODE_REPROBE_NOTIFY_ON_UPDATE
120  *		Reprobe and notify if there is a property update
121  *	IBNEX_NODE_REPROBE_NOTIFY_ALWAYS
122  *		Reprobe and notify always.
123  *	IBNEX_NODE_REPROBE_IOC_WAIT
124  *		Reprobe for IOC apid waiting
125  *
126  * Device reprobes triggered by ibt_reprobe_dev will result in an DDI
127  * event, even though no prepoerties have changed.
128  */
129 #define	IBNEX_NODE_REPROBE_NOTIFY_ON_UPDATE	0x01
130 #define	IBNEX_NODE_REPROBE_NOTIFY_ALWAYS	0x02
131 #define	IBNEX_NODE_REPROBE_IOC_WAIT			0x04
132 
133 /* Node specific information, stored as dev_info_t private data */
134 typedef struct ibnex_node_data_s {
135 	dev_info_t		*node_dip;
136 	union {
137 		ibnex_ioc_node_t	ioc_node;
138 		ibnex_port_node_t	port_node;
139 		ibnex_pseudo_node_t	pseudo_node;
140 	} node_data;
141 	struct ibnex_node_data_s *node_next;
142 	struct ibnex_node_data_s *node_prev;
143 	ibnex_node_type_t	node_type;
144 	ibnex_node_state_t	node_state;
145 	int			node_reprobe_state;	/* Node reprobe flag */
146 } ibnex_node_data_t;
147 
148 /*
149  * The fields of IOC and Port node are initialized when the
150  * device node is created. These are read only for the rest
151  * of the IBnexus driver.
152  */
153 _NOTE(SCHEME_PROTECTS_DATA("stable data", ibnex_ioc_node_s))
154 _NOTE(SCHEME_PROTECTS_DATA("stable data", ibnex_port_node_s))
155 _NOTE(SCHEME_PROTECTS_DATA("stable data", ibnex_pseudo_node_s))
156 _NOTE(SCHEME_PROTECTS_DATA("stable data", ibnex_node_data_s))
157 
158 #define	IBNEX_VALID_NODE_TYPE(n)	\
159 	(((n)->node_type == IBNEX_PORT_COMMSVC_NODE) || \
160 	((n)->node_type == IBNEX_VPPA_COMMSVC_NODE) || \
161 	((n)->node_type == IBNEX_HCASVC_COMMSVC_NODE) || \
162 	((n)->node_type == IBNEX_IOC_NODE) || \
163 	((n)->node_type == IBNEX_PSEUDO_NODE))
164 
165 #define	IBNEX_COMMSVC_NODE_TYPE(n)	\
166 	(((n)->node_type == IBNEX_PORT_COMMSVC_NODE) || \
167 	((n)->node_type == IBNEX_VPPA_COMMSVC_NODE) || \
168 	((n)->node_type == IBNEX_HCASVC_COMMSVC_NODE))
169 
170 /*
171  * Definition for the IB nexus global per-instance structure.
172  * IB nexus supports only one instance.
173  */
174 typedef struct ibnex_s {
175 	dev_info_t		*ibnex_dip;
176 	kmutex_t		ibnex_mutex;
177 	int			ibnex_num_comm_svcs;
178 	char			**ibnex_comm_svc_names;
179 	int			ibnex_nvppa_comm_svcs;
180 	char			**ibnex_vppa_comm_svc_names;
181 	int			ibnex_nhcasvc_comm_svcs;
182 	char			**ibnex_hcasvc_comm_svc_names;
183 	ibnex_node_data_t	*ibnex_port_node_head;
184 	ibnex_node_data_t	*ibnex_ioc_node_head;
185 	ibnex_node_data_t	*ibnex_pseudo_node_head;
186 
187 	/*
188 	 * NDI Event handle for -all- ibnexus events
189 	 * Event Cookie for IB_PROP_UPDATE_EVENT event
190 	 */
191 	ndi_event_hdl_t		ibnex_ndi_event_hdl;
192 	ddi_eventcookie_t	ibnex_prop_update_evt_cookie;
193 
194 	/* Flags & condition variables for reprobe handling */
195 	int					ibnex_reprobe_state;
196 	kcondvar_t			ibnex_reprobe_cv;
197 
198 	/* Count of disconnected IOCs still configured */
199 	int					ibnex_num_disconnect_iocs;
200 
201 	/* Pseudo nodes inited from ibnex_get_snapshot? */
202 	int			ibnex_pseudo_inited;
203 } ibnex_t;
204 
205 /*
206  * States for ibnex_reprobe_state
207  *	0 to REPROBE_ALL_PROGRESS
208  *		Reprobe all when no reprobes pending
209  *	REPROBE_ALL_PROGRESS to REPROBE_ALL_WAIT
210  *		Reprobe all request when another in progress
211  *	0 to REPROBE_IOC_WAIT
212  *		Waiting for One or more reprobe_ioc to complete
213  *
214  * Reprobe logic will ensure :
215  *	1. A single reprobe all at any time.
216  *	2. No individual IOC reprobe overlaps with reprobe all.
217  *	3. Reprobe for multiple IOCs can be in parallel
218  *	4. Single reprobe for each IOC.
219  */
220 #define	IBNEX_REPROBE_ALL_PROGRESS	0x01
221 #define	IBNEX_REPROBE_ALL_WAIT		0x02
222 #define	IBNEX_REPROBE_IOC_WAIT		0x04
223 
224 /* Defines for creating and binding device nodes.  */
225 #define	IBNEX_MAX_COMPAT_NAMES		6
226 #define	IBNEX_MAX_IBPORT_COMPAT_NAMES	3
227 #define	IBNEX_MAX_COMPAT_LEN		48
228 #define	IBNEX_MAX_COMPAT_PROP_SZ	\
229 	IBNEX_MAX_COMPAT_NAMES * IBNEX_MAX_COMPAT_LEN
230 #define	IBNEX_MAX_IBPORT_COMPAT_PROP_SZ	\
231 	IBNEX_MAX_IBPORT_COMPAT_NAMES * IBNEX_MAX_COMPAT_LEN
232 #define	IBNEX_DEVFS_ENUMERATE		0x1	/* enumerate via devfs(7fs) */
233 #define	IBNEX_CFGADM_ENUMERATE		0x2	/* enumerate via cfgadm */
234 
235 #define	IBNEX_MAX_NODEADDR_SZ		35
236 
237 /* Define for forming the unit address from GUID and class string */
238 #define	IBNEX_FORM_GUID(buf, size, guid) \
239 		(void) snprintf((buf), (size), "%llX", (longlong_t)guid);
240 
241 #define	IBNEX_INVALID_PKEY(pkey)	\
242 		(((pkey) == IB_PKEY_INVALID_FULL) || \
243 		((pkey) == IB_PKEY_INVALID_LIMITED))
244 
245 /*
246  * Defines for the tags of IB DDI events
247  */
248 typedef enum {
249 		IB_EVENT_TAG_PROP_UPDATE = 0
250 } ib_ddi_event_tag_t;
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 
256 #endif	/* _SYS_IB_IBNEX_IBNEX_H */
257