xref: /titanic_51/usr/src/uts/common/sys/sunmdi.h (revision 1dbc1fed8be6e82e676ff3f124628dc470058bfb)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_SUNMDI_H
27 #define	_SYS_SUNMDI_H
28 
29 /*
30  * Multiplexed I/O global include
31  */
32 
33 #include <sys/note.h>
34 #include <sys/esunddi.h>
35 #include <sys/sunddi.h>
36 #include <sys/ddipropdefs.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Most MDI functions return success or failure
44  */
45 #define	MDI_SUCCESS		0	/* Call Success */
46 #define	MDI_FAILURE		-1	/* Unspecified Error */
47 #define	MDI_NOMEM		-2	/* No resources available */
48 #define	MDI_ACCEPT		-3	/* Request accepted */
49 #define	MDI_BUSY		-4	/* Busy */
50 #define	MDI_NOPATH		-5	/* No more paths are available */
51 #define	MDI_EINVAL		-6	/* Invalid parameter */
52 #define	MDI_NOT_SUPPORTED	-8	/* Device not supported */
53 #define	MDI_DEVI_ONLINING	-9	/* Devi is onlining */
54 
55 /*
56  * handle to mdi_pathinfo node
57  */
58 typedef struct x_mdi_pathinfo *mdi_pathinfo_t;
59 
60 /*
61  * Path info node state definitions
62  */
63 typedef enum {
64 	MDI_PATHINFO_STATE_INIT,
65 	MDI_PATHINFO_STATE_ONLINE,
66 	MDI_PATHINFO_STATE_STANDBY,
67 	MDI_PATHINFO_STATE_FAULT,
68 	MDI_PATHINFO_STATE_OFFLINE
69 } mdi_pathinfo_state_t;
70 
71 /*
72  * MDI vHCI class definitions
73  */
74 #define	MDI_HCI_CLASS_SCSI	"scsi_vhci"
75 #define	MDI_HCI_CLASS_IB	"ib"
76 
77 #ifdef _KERNEL
78 
79 /*
80  * mpxio component definitions:  Every registered component of the
81  * mpxio system has a "mpxio-component" property attached to it.
82  * Identify its function
83  */
84 #define	MDI_COMPONENT_NONE	0
85 #define	MDI_COMPONENT_VHCI	0x1
86 #define	MDI_COMPONENT_PHCI	0x2
87 #define	MDI_COMPONENT_CLIENT	0x4
88 
89 /*
90  * mdi_pathinfo node state utility definitions (bits in mdi_pathinfo_state_t)
91  *
92  * NOTE: having mdi_pathinfo_state_t contain both state and flags is error
93  * prone.  For new flags, please consider using MDI_PATHINFO_FLAG_ (and
94  * moving existing EXT_STATE_MASK flags over would be good too).
95  */
96 #define	MDI_PATHINFO_STATE_TRANSIENT			0x00010000
97 #define	MDI_PATHINFO_STATE_USER_DISABLE			0x00100000
98 #define	MDI_PATHINFO_STATE_DRV_DISABLE			0x00200000
99 #define	MDI_PATHINFO_STATE_DRV_DISABLE_TRANSIENT	0x00400000
100 #define	MDI_PATHINFO_STATE_MASK				0x0000FFFF
101 #define	MDI_PATHINFO_EXT_STATE_MASK			0xFFF00000
102 
103 /*
104  * mdi_pathinfo flags definitions
105  */
106 #define	MDI_PATHINFO_FLAGS_HIDDEN			0x00000001
107 #define	MDI_PATHINFO_FLAGS_DEVICE_REMOVED		0x00000002
108 
109 #define	USER_DISABLE			1
110 #define	DRIVER_DISABLE			2
111 #define	DRIVER_DISABLE_TRANSIENT	3
112 
113 
114 /*
115  * Most MDI functions return success or failure
116  */
117 #define	MDI_SUCCESS		0	/* Call Success			*/
118 #define	MDI_FAILURE		-1	/* Unspecified Error		*/
119 #define	MDI_NOMEM		-2	/* No resources available	*/
120 #define	MDI_ACCEPT		-3	/* Request accepted		*/
121 #define	MDI_BUSY		-4	/* Busy				*/
122 #define	MDI_NOPATH		-5	/* No more paths are available	*/
123 #define	MDI_EINVAL		-6	/* Invalid parameter		*/
124 #define	MDI_NOT_SUPPORTED	-8	/* Device not supported		*/
125 #define	MDI_DEVI_ONLINING	-9	/* Devi is onlining		*/
126 
127 /*
128  * MDI operation vector structure definition
129  */
130 #define	MDI_OPS_REV_1			1
131 #define	MDI_OPS_REV			MDI_OPS_REV_1
132 
133 #define	MDI_VHCI(dip)	(DEVI(dip)->devi_mdi_component & MDI_COMPONENT_VHCI)
134 #define	MDI_PHCI(dip)	(DEVI(dip)->devi_mdi_component & MDI_COMPONENT_PHCI)
135 #define	MDI_CLIENT(dip)	(DEVI(dip)->devi_mdi_component & MDI_COMPONENT_CLIENT)
136 
137 /*
138  * MDI device hotplug notification
139  */
140 int mdi_devi_online(dev_info_t *, uint_t);
141 int mdi_devi_offline(dev_info_t *, uint_t);
142 
143 /*
144  * MDI path retire interfaces
145  */
146 void mdi_phci_mark_retiring(dev_info_t *dip, char **cons_array);
147 void mdi_phci_retire_notify(dev_info_t *dip, int *constraint);
148 void mdi_phci_retire_finalize(dev_info_t *dip, int phci_only);
149 void mdi_phci_unretire(dev_info_t *dip);
150 
151 /*
152  * MDI devinfo locking functions.
153  */
154 void mdi_devi_enter(dev_info_t *, int *);
155 int mdi_devi_tryenter(dev_info_t *, int *);
156 void mdi_devi_exit_phci(dev_info_t *, int);
157 void mdi_devi_enter_phci(dev_info_t *, int *);
158 void mdi_devi_exit(dev_info_t *, int);
159 
160 /*
161  * MDI device support functions.
162  */
163 dev_info_t *mdi_devi_get_vdip(dev_info_t *);
164 int mdi_devi_pdip_entered(dev_info_t *);
165 
166 /*
167  * MDI component device instance attach/detach notification
168  */
169 int mdi_pre_attach(dev_info_t *, ddi_attach_cmd_t);
170 void mdi_post_attach(dev_info_t *, ddi_attach_cmd_t, int);
171 int mdi_pre_detach(dev_info_t *, ddi_detach_cmd_t);
172 void mdi_post_detach(dev_info_t *, ddi_detach_cmd_t, int);
173 
174 /*
175  * mdi_pathinfo management functions.
176  *
177  * Find, allocate and Free functions.
178  */
179 mdi_pathinfo_t *mdi_pi_find(dev_info_t *, char *, char *);
180 int mdi_pi_alloc(dev_info_t *, char *, char *, char *, int, mdi_pathinfo_t **);
181 int mdi_pi_alloc_compatible(dev_info_t *, char *, char *, char *,
182 	char **, int, int, mdi_pathinfo_t **);
183 int mdi_pi_free(mdi_pathinfo_t *, int);
184 
185 void mdi_hold_path(mdi_pathinfo_t *);
186 void mdi_rele_path(mdi_pathinfo_t *);
187 
188 /*
189  * mdi_pathinfo node state change functions.
190  */
191 int mdi_pi_online(mdi_pathinfo_t *, int);
192 int mdi_pi_standby(mdi_pathinfo_t *, int);
193 int mdi_pi_fault(mdi_pathinfo_t *, int);
194 int mdi_pi_offline(mdi_pathinfo_t *, int);
195 /*
196  * NOTE: the next 2 interfaces will be removed once the NWS files are
197  * changed to use the new mdi_{enable,disable}_path interfaces
198  */
199 int mdi_pi_disable(dev_info_t *, dev_info_t *, int);
200 int mdi_pi_enable(dev_info_t *, dev_info_t *, int);
201 int mdi_pi_disable_path(mdi_pathinfo_t *, int);
202 int mdi_pi_enable_path(mdi_pathinfo_t *, int);
203 
204 int mdi_pi_ishidden(mdi_pathinfo_t *);
205 
206 int mdi_pi_device_isremoved(mdi_pathinfo_t *);
207 int mdi_pi_device_remove(mdi_pathinfo_t *);
208 int mdi_pi_device_insert(mdi_pathinfo_t *);
209 
210 /*
211  * MPxIO-PM stuff
212  */
213 typedef enum {
214 	MDI_PM_PRE_CONFIG = 0,
215 	MDI_PM_POST_CONFIG,
216 	MDI_PM_PRE_UNCONFIG,
217 	MDI_PM_POST_UNCONFIG,
218 	MDI_PM_HOLD_POWER,
219 	MDI_PM_RELE_POWER
220 } mdi_pm_op_t;
221 
222 int
223 mdi_bus_power(dev_info_t *, void *, pm_bus_power_op_t, void *, void *);
224 
225 int
226 mdi_power(dev_info_t *, mdi_pm_op_t, void *, char *, int);
227 
228 /*
229  * mdi_pathinfo node walker function.
230  */
231 int mdi_component_is_vhci(dev_info_t *, const char **);
232 int mdi_component_is_phci(dev_info_t *, const char **);
233 int mdi_component_is_client(dev_info_t *, const char **);
234 mdi_pathinfo_t *mdi_get_next_phci_path(dev_info_t *, mdi_pathinfo_t *);
235 mdi_pathinfo_t *mdi_get_next_client_path(dev_info_t *, mdi_pathinfo_t *);
236 
237 /*
238  * mdi_pathinfo node member functions
239  */
240 void mdi_pi_lock(mdi_pathinfo_t *);
241 void mdi_pi_unlock(mdi_pathinfo_t *);
242 dev_info_t *mdi_pi_get_client(mdi_pathinfo_t *);
243 dev_info_t *mdi_pi_get_phci(mdi_pathinfo_t *);
244 char *mdi_pi_get_node_name(mdi_pathinfo_t *);
245 char *mdi_pi_get_addr(mdi_pathinfo_t *);
246 mdi_pathinfo_state_t mdi_pi_get_state(mdi_pathinfo_t *);
247 uint_t mdi_pi_get_flags(mdi_pathinfo_t *);
248 int mdi_pi_get_path_instance(mdi_pathinfo_t *);
249 char *mdi_pi_pathname_by_instance(int);
250 char *mdi_pi_pathname(mdi_pathinfo_t *);
251 char *mdi_pi_pathname_obp(mdi_pathinfo_t *, char *);
252 int mdi_pi_pathname_obp_set(mdi_pathinfo_t *, char *);
253 char *mdi_pi_spathname_by_instance(int);
254 char *mdi_pi_spathname(mdi_pathinfo_t *);
255 
256 /*
257  * mdi_pathinfo Property handling functions
258  */
259 int mdi_prop_remove(mdi_pathinfo_t *, char *);
260 int mdi_prop_update_byte_array(mdi_pathinfo_t *, char *, uchar_t *, uint_t);
261 int mdi_prop_update_int(mdi_pathinfo_t *, char *, int);
262 int mdi_prop_update_int64(mdi_pathinfo_t *, char *, int64_t);
263 int mdi_prop_update_int_array(mdi_pathinfo_t *, char *, int *, uint_t);
264 int mdi_prop_update_string(mdi_pathinfo_t *, char *, char *);
265 int mdi_prop_update_string_array(mdi_pathinfo_t *, char *, char **, uint_t);
266 nvpair_t *mdi_pi_get_next_prop(mdi_pathinfo_t *, nvpair_t *);
267 
268 int mdi_prop_lookup_byte_array(mdi_pathinfo_t *, char *, uchar_t **, uint_t *);
269 int mdi_prop_lookup_int(mdi_pathinfo_t *, char *, int *);
270 int mdi_prop_lookup_int64(mdi_pathinfo_t *, char *, int64_t *);
271 int mdi_prop_lookup_int_array(mdi_pathinfo_t *, char *, int **, uint_t *);
272 int mdi_prop_lookup_string(mdi_pathinfo_t *, char *, char **);
273 int mdi_prop_lookup_string_array(mdi_pathinfo_t *, char *, char ***, uint_t *);
274 int mdi_prop_free(void *);
275 
276 /*
277  * pHCI driver instance registration/unregistration
278  *
279  * mdi_phci_register() is called by a pHCI drivers to register itself as a
280  * transport provider for a specific 'class' (see mdi_vhci_register() above);
281  * it should be called from attach(9e).
282  *
283  * mdi_phci_unregister() is called from detach(9e) to unregister a pHCI
284  * instance from the framework.
285  */
286 int		mdi_phci_register(char *, dev_info_t *, int);
287 int		mdi_phci_unregister(dev_info_t *, int);
288 
289 /* get set phci private data */
290 caddr_t mdi_pi_get_phci_private(mdi_pathinfo_t *);
291 void mdi_pi_set_phci_private(mdi_pathinfo_t *, caddr_t);
292 
293 int mdi_vhci_bus_config(dev_info_t *, uint_t, ddi_bus_config_op_t, void *,
294     dev_info_t **, char *);
295 
296 /*
297  * mdi_vhci node walker function
298  */
299 void mdi_walk_vhcis(int (*f)(dev_info_t *, void *), void *arg);
300 
301 /*
302  * mdi_phci node walker function
303  */
304 void mdi_vhci_walk_phcis(dev_info_t *, int (*f)(dev_info_t *, void *),
305     void *arg);
306 
307 /*
308  * mdi_client node walker function
309  */
310 void mdi_vhci_walk_clients(dev_info_t *, int (*f)(dev_info_t *, void *),
311     void *arg);
312 
313 /*
314  * MDI PHCI driver list helper functions
315  */
316 char **mdi_get_phci_driver_list(char *vhci_class, int	*ndrivers);
317 void mdi_free_phci_driver_list(char **driver_list, int ndrivers);
318 
319 #endif /* _KERNEL */
320 
321 #ifdef	__cplusplus
322 }
323 #endif
324 
325 #endif	/* _SYS_SUNMDI_H */
326