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