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