xref: /titanic_44/usr/src/uts/common/sys/sunmdi.h (revision b3f3b44f9fd6c859d1cedebb73934b93d4b83856)
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 2008 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
91  */
92 #define	MDI_PATHINFO_STATE_TRANSIENT			0x00010000
93 #define	MDI_PATHINFO_STATE_USER_DISABLE			0x00100000
94 #define	MDI_PATHINFO_STATE_DRV_DISABLE			0x00200000
95 #define	MDI_PATHINFO_STATE_DRV_DISABLE_TRANSIENT	0x00400000
96 #define	MDI_PATHINFO_STATE_MASK				0x0000FFFF
97 #define	MDI_PATHINFO_EXT_STATE_MASK			0xFFF00000
98 
99 #define	USER_DISABLE			1
100 #define	DRIVER_DISABLE			2
101 #define	DRIVER_DISABLE_TRANSIENT	3
102 
103 
104 /*
105  * Most MDI functions return success or failure
106  */
107 #define	MDI_SUCCESS		0	/* Call Success			*/
108 #define	MDI_FAILURE		-1	/* Unspecified Error		*/
109 #define	MDI_NOMEM		-2	/* No resources available	*/
110 #define	MDI_ACCEPT		-3	/* Request accepted		*/
111 #define	MDI_BUSY		-4	/* Busy				*/
112 #define	MDI_NOPATH		-5	/* No more paths are available	*/
113 #define	MDI_EINVAL		-6	/* Invalid parameter		*/
114 #define	MDI_NOT_SUPPORTED	-8	/* Device not supported		*/
115 #define	MDI_DEVI_ONLINING	-9	/* Devi is onlining		*/
116 
117 /*
118  * MDI operation vector structure definition
119  */
120 #define	MDI_OPS_REV_1			1
121 #define	MDI_OPS_REV			MDI_OPS_REV_1
122 
123 #define	MDI_VHCI(dip)	(DEVI(dip)->devi_mdi_component & MDI_COMPONENT_VHCI)
124 #define	MDI_PHCI(dip)	(DEVI(dip)->devi_mdi_component & MDI_COMPONENT_PHCI)
125 #define	MDI_CLIENT(dip)	(DEVI(dip)->devi_mdi_component & MDI_COMPONENT_CLIENT)
126 
127 /*
128  * MDI device hotplug notification
129  */
130 int mdi_devi_online(dev_info_t *, uint_t);
131 int mdi_devi_offline(dev_info_t *, uint_t);
132 
133 /*
134  * MDI path retire interfaces
135  */
136 void mdi_phci_mark_retiring(dev_info_t *dip, char **cons_array);
137 void mdi_phci_retire_notify(dev_info_t *dip, int *constraint);
138 void mdi_phci_retire_finalize(dev_info_t *dip, int phci_only);
139 void mdi_phci_unretire(dev_info_t *dip);
140 
141 /*
142  * MDI devinfo locking functions.
143  */
144 void mdi_devi_enter(dev_info_t *, int *);
145 void mdi_devi_exit_phci(dev_info_t *, int);
146 void mdi_devi_enter_phci(dev_info_t *, int *);
147 void mdi_devi_exit(dev_info_t *, int);
148 
149 /*
150  * MDI device support functions.
151  */
152 dev_info_t *mdi_devi_get_vdip(dev_info_t *);
153 int mdi_devi_pdip_entered(dev_info_t *);
154 
155 /*
156  * MDI component device instance attach/detach notification
157  */
158 int mdi_pre_attach(dev_info_t *, ddi_attach_cmd_t);
159 void mdi_post_attach(dev_info_t *, ddi_attach_cmd_t, int);
160 int mdi_pre_detach(dev_info_t *, ddi_detach_cmd_t);
161 void mdi_post_detach(dev_info_t *, ddi_detach_cmd_t, int);
162 
163 /*
164  * mdi_pathinfo management functions.
165  *
166  * Find, allocate and Free functions.
167  */
168 mdi_pathinfo_t *mdi_pi_find(dev_info_t *, char *, char *);
169 int mdi_pi_alloc(dev_info_t *, char *, char *, char *, int, mdi_pathinfo_t **);
170 int mdi_pi_alloc_compatible(dev_info_t *, char *, char *, char *,
171 	char **, int, int, mdi_pathinfo_t **);
172 int mdi_pi_free(mdi_pathinfo_t *, int);
173 
174 void mdi_hold_path(mdi_pathinfo_t *);
175 void mdi_rele_path(mdi_pathinfo_t *);
176 
177 /*
178  * mdi_pathinfo node state change functions.
179  */
180 int mdi_pi_online(mdi_pathinfo_t *, int);
181 int mdi_pi_standby(mdi_pathinfo_t *, int);
182 int mdi_pi_fault(mdi_pathinfo_t *, int);
183 int mdi_pi_offline(mdi_pathinfo_t *, int);
184 /*
185  * NOTE: the next 2 interfaces will be removed once the NWS files are
186  * changed to use the new mdi_{enable,disable}_path interfaces
187  */
188 int mdi_pi_disable(dev_info_t *, dev_info_t *, int);
189 int mdi_pi_enable(dev_info_t *, dev_info_t *, int);
190 int mdi_pi_disable_path(mdi_pathinfo_t *, int);
191 int mdi_pi_enable_path(mdi_pathinfo_t *, int);
192 
193 /*
194  * MPxIO-PM stuff
195  */
196 typedef enum {
197 	MDI_PM_PRE_CONFIG = 0,
198 	MDI_PM_POST_CONFIG,
199 	MDI_PM_PRE_UNCONFIG,
200 	MDI_PM_POST_UNCONFIG,
201 	MDI_PM_HOLD_POWER,
202 	MDI_PM_RELE_POWER
203 } mdi_pm_op_t;
204 
205 int
206 mdi_bus_power(dev_info_t *, void *, pm_bus_power_op_t, void *, void *);
207 
208 int
209 mdi_power(dev_info_t *, mdi_pm_op_t, void *, char *, int);
210 
211 /*
212  * mdi_pathinfo node walker function.
213  */
214 int mdi_component_is_vhci(dev_info_t *, const char **);
215 int mdi_component_is_phci(dev_info_t *, const char **);
216 int mdi_component_is_client(dev_info_t *, const char **);
217 mdi_pathinfo_t *mdi_get_next_phci_path(dev_info_t *, mdi_pathinfo_t *);
218 mdi_pathinfo_t *mdi_get_next_client_path(dev_info_t *, mdi_pathinfo_t *);
219 
220 /*
221  * mdi_pathinfo node member functions
222  */
223 void mdi_pi_lock(mdi_pathinfo_t *);
224 void mdi_pi_unlock(mdi_pathinfo_t *);
225 dev_info_t *mdi_pi_get_client(mdi_pathinfo_t *);
226 dev_info_t *mdi_pi_get_phci(mdi_pathinfo_t *);
227 char *mdi_pi_get_addr(mdi_pathinfo_t *);
228 mdi_pathinfo_state_t mdi_pi_get_state(mdi_pathinfo_t *);
229 int mdi_pi_get_path_instance(mdi_pathinfo_t *);
230 char *mdi_pi_pathname_by_instance(int path_instance);
231 char *mdi_pi_pathname(mdi_pathinfo_t *);
232 char *mdi_pi_pathname_obp(mdi_pathinfo_t *, char *);
233 int mdi_pi_pathname_obp_set(mdi_pathinfo_t *, char *);
234 
235 /*
236  * mdi_pathinfo Property handling functions
237  */
238 int mdi_prop_remove(mdi_pathinfo_t *, char *);
239 int mdi_prop_update_byte_array(mdi_pathinfo_t *, char *, uchar_t *, uint_t);
240 int mdi_prop_update_int(mdi_pathinfo_t *, char *, int);
241 int mdi_prop_update_int64(mdi_pathinfo_t *, char *, int64_t);
242 int mdi_prop_update_int_array(mdi_pathinfo_t *, char *, int *, uint_t);
243 int mdi_prop_update_string(mdi_pathinfo_t *, char *, char *);
244 int mdi_prop_update_string_array(mdi_pathinfo_t *, char *, char **, uint_t);
245 nvpair_t *mdi_pi_get_next_prop(mdi_pathinfo_t *, nvpair_t *);
246 
247 int mdi_prop_lookup_byte_array(mdi_pathinfo_t *, char *, uchar_t **, uint_t *);
248 int mdi_prop_lookup_int(mdi_pathinfo_t *, char *, int *);
249 int mdi_prop_lookup_int64(mdi_pathinfo_t *, char *, int64_t *);
250 int mdi_prop_lookup_int_array(mdi_pathinfo_t *, char *, int **, uint_t *);
251 int mdi_prop_lookup_string(mdi_pathinfo_t *, char *, char **);
252 int mdi_prop_lookup_string_array(mdi_pathinfo_t *, char *, char ***, uint_t *);
253 int mdi_prop_free(void *);
254 
255 /*
256  * pHCI driver instance registration/unregistration
257  *
258  * mdi_phci_register() is called by a pHCI drivers to register itself as a
259  * transport provider for a specific 'class' (see mdi_vhci_register() above);
260  * it should be called from attach(9e).
261  *
262  * mdi_phci_unregister() is called from detach(9e) to unregister a pHCI
263  * instance from the framework.
264  */
265 int		mdi_phci_register(char *, dev_info_t *, int);
266 int		mdi_phci_unregister(dev_info_t *, int);
267 
268 /* get set phci private data */
269 caddr_t mdi_pi_get_phci_private(mdi_pathinfo_t *);
270 void mdi_pi_set_phci_private(mdi_pathinfo_t *, caddr_t);
271 
272 int mdi_vhci_bus_config(dev_info_t *, uint_t, ddi_bus_config_op_t, void *,
273     dev_info_t **, char *);
274 
275 /*
276  * mdi_vhci node walker function
277  */
278 void mdi_walk_vhcis(int (*f)(dev_info_t *, void *), void *arg);
279 
280 /*
281  * mdi_phci node walker function
282  */
283 void mdi_vhci_walk_phcis(dev_info_t *, int (*f)(dev_info_t *, void *),
284     void *arg);
285 
286 /*
287  * mdi_client node walker function
288  */
289 void mdi_vhci_walk_clients(dev_info_t *, int (*f)(dev_info_t *, void *),
290     void *arg);
291 
292 /*
293  * MDI PHCI driver list helper functions
294  */
295 char **mdi_get_phci_driver_list(char *vhci_class, int	*ndrivers);
296 void mdi_free_phci_driver_list(char **driver_list, int ndrivers);
297 
298 #endif /* _KERNEL */
299 
300 #ifdef	__cplusplus
301 }
302 #endif
303 
304 #endif	/* _SYS_SUNMDI_H */
305