xref: /titanic_51/usr/src/uts/common/sys/sunmdi.h (revision 26594249d18446b4a5ff8ff6d34611c718757251)
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
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 int mdi_devi_tryenter(dev_info_t *, int *);
146 void mdi_devi_exit_phci(dev_info_t *, int);
147 void mdi_devi_enter_phci(dev_info_t *, int *);
148 void mdi_devi_exit(dev_info_t *, int);
149 
150 /*
151  * MDI device support functions.
152  */
153 dev_info_t *mdi_devi_get_vdip(dev_info_t *);
154 int mdi_devi_pdip_entered(dev_info_t *);
155 
156 /*
157  * MDI component device instance attach/detach notification
158  */
159 int mdi_pre_attach(dev_info_t *, ddi_attach_cmd_t);
160 void mdi_post_attach(dev_info_t *, ddi_attach_cmd_t, int);
161 int mdi_pre_detach(dev_info_t *, ddi_detach_cmd_t);
162 void mdi_post_detach(dev_info_t *, ddi_detach_cmd_t, int);
163 
164 /*
165  * mdi_pathinfo management functions.
166  *
167  * Find, allocate and Free functions.
168  */
169 mdi_pathinfo_t *mdi_pi_find(dev_info_t *, char *, char *);
170 int mdi_pi_alloc(dev_info_t *, char *, char *, char *, int, mdi_pathinfo_t **);
171 int mdi_pi_alloc_compatible(dev_info_t *, char *, char *, char *,
172 	char **, int, int, mdi_pathinfo_t **);
173 int mdi_pi_free(mdi_pathinfo_t *, int);
174 
175 void mdi_hold_path(mdi_pathinfo_t *);
176 void mdi_rele_path(mdi_pathinfo_t *);
177 
178 /*
179  * mdi_pathinfo node state change functions.
180  */
181 int mdi_pi_online(mdi_pathinfo_t *, int);
182 int mdi_pi_standby(mdi_pathinfo_t *, int);
183 int mdi_pi_fault(mdi_pathinfo_t *, int);
184 int mdi_pi_offline(mdi_pathinfo_t *, int);
185 /*
186  * NOTE: the next 2 interfaces will be removed once the NWS files are
187  * changed to use the new mdi_{enable,disable}_path interfaces
188  */
189 int mdi_pi_disable(dev_info_t *, dev_info_t *, int);
190 int mdi_pi_enable(dev_info_t *, dev_info_t *, int);
191 int mdi_pi_disable_path(mdi_pathinfo_t *, int);
192 int mdi_pi_enable_path(mdi_pathinfo_t *, int);
193 
194 /*
195  * MPxIO-PM stuff
196  */
197 typedef enum {
198 	MDI_PM_PRE_CONFIG = 0,
199 	MDI_PM_POST_CONFIG,
200 	MDI_PM_PRE_UNCONFIG,
201 	MDI_PM_POST_UNCONFIG,
202 	MDI_PM_HOLD_POWER,
203 	MDI_PM_RELE_POWER
204 } mdi_pm_op_t;
205 
206 int
207 mdi_bus_power(dev_info_t *, void *, pm_bus_power_op_t, void *, void *);
208 
209 int
210 mdi_power(dev_info_t *, mdi_pm_op_t, void *, char *, int);
211 
212 /*
213  * mdi_pathinfo node walker function.
214  */
215 int mdi_component_is_vhci(dev_info_t *, const char **);
216 int mdi_component_is_phci(dev_info_t *, const char **);
217 int mdi_component_is_client(dev_info_t *, const char **);
218 mdi_pathinfo_t *mdi_get_next_phci_path(dev_info_t *, mdi_pathinfo_t *);
219 mdi_pathinfo_t *mdi_get_next_client_path(dev_info_t *, mdi_pathinfo_t *);
220 
221 /*
222  * mdi_pathinfo node member functions
223  */
224 void mdi_pi_lock(mdi_pathinfo_t *);
225 void mdi_pi_unlock(mdi_pathinfo_t *);
226 dev_info_t *mdi_pi_get_client(mdi_pathinfo_t *);
227 dev_info_t *mdi_pi_get_phci(mdi_pathinfo_t *);
228 char *mdi_pi_get_node_name(mdi_pathinfo_t *);
229 char *mdi_pi_get_addr(mdi_pathinfo_t *);
230 mdi_pathinfo_state_t mdi_pi_get_state(mdi_pathinfo_t *);
231 int mdi_pi_get_path_instance(mdi_pathinfo_t *);
232 char *mdi_pi_pathname_by_instance(int path_instance);
233 char *mdi_pi_pathname(mdi_pathinfo_t *);
234 char *mdi_pi_pathname_obp(mdi_pathinfo_t *, char *);
235 int mdi_pi_pathname_obp_set(mdi_pathinfo_t *, char *);
236 
237 /*
238  * mdi_pathinfo Property handling functions
239  */
240 int mdi_prop_remove(mdi_pathinfo_t *, char *);
241 int mdi_prop_update_byte_array(mdi_pathinfo_t *, char *, uchar_t *, uint_t);
242 int mdi_prop_update_int(mdi_pathinfo_t *, char *, int);
243 int mdi_prop_update_int64(mdi_pathinfo_t *, char *, int64_t);
244 int mdi_prop_update_int_array(mdi_pathinfo_t *, char *, int *, uint_t);
245 int mdi_prop_update_string(mdi_pathinfo_t *, char *, char *);
246 int mdi_prop_update_string_array(mdi_pathinfo_t *, char *, char **, uint_t);
247 nvpair_t *mdi_pi_get_next_prop(mdi_pathinfo_t *, nvpair_t *);
248 
249 int mdi_prop_lookup_byte_array(mdi_pathinfo_t *, char *, uchar_t **, uint_t *);
250 int mdi_prop_lookup_int(mdi_pathinfo_t *, char *, int *);
251 int mdi_prop_lookup_int64(mdi_pathinfo_t *, char *, int64_t *);
252 int mdi_prop_lookup_int_array(mdi_pathinfo_t *, char *, int **, uint_t *);
253 int mdi_prop_lookup_string(mdi_pathinfo_t *, char *, char **);
254 int mdi_prop_lookup_string_array(mdi_pathinfo_t *, char *, char ***, uint_t *);
255 int mdi_prop_free(void *);
256 
257 /*
258  * pHCI driver instance registration/unregistration
259  *
260  * mdi_phci_register() is called by a pHCI drivers to register itself as a
261  * transport provider for a specific 'class' (see mdi_vhci_register() above);
262  * it should be called from attach(9e).
263  *
264  * mdi_phci_unregister() is called from detach(9e) to unregister a pHCI
265  * instance from the framework.
266  */
267 int		mdi_phci_register(char *, dev_info_t *, int);
268 int		mdi_phci_unregister(dev_info_t *, int);
269 
270 /* get set phci private data */
271 caddr_t mdi_pi_get_phci_private(mdi_pathinfo_t *);
272 void mdi_pi_set_phci_private(mdi_pathinfo_t *, caddr_t);
273 
274 int mdi_vhci_bus_config(dev_info_t *, uint_t, ddi_bus_config_op_t, void *,
275     dev_info_t **, char *);
276 
277 /*
278  * mdi_vhci node walker function
279  */
280 void mdi_walk_vhcis(int (*f)(dev_info_t *, void *), void *arg);
281 
282 /*
283  * mdi_phci node walker function
284  */
285 void mdi_vhci_walk_phcis(dev_info_t *, int (*f)(dev_info_t *, void *),
286     void *arg);
287 
288 /*
289  * mdi_client node walker function
290  */
291 void mdi_vhci_walk_clients(dev_info_t *, int (*f)(dev_info_t *, void *),
292     void *arg);
293 
294 /*
295  * MDI PHCI driver list helper functions
296  */
297 char **mdi_get_phci_driver_list(char *vhci_class, int	*ndrivers);
298 void mdi_free_phci_driver_list(char **driver_list, int ndrivers);
299 
300 #endif /* _KERNEL */
301 
302 #ifdef	__cplusplus
303 }
304 #endif
305 
306 #endif	/* _SYS_SUNMDI_H */
307