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