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