xref: /illumos-gate/usr/src/uts/common/sys/devinfo_impl.h (revision 581cede61ac9c14d8d4ea452562a567189eead78)
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_DEVINFO_IMPL_H
27 #define	_SYS_DEVINFO_IMPL_H
28 
29 #include <sys/ddi_impldefs.h>
30 
31 /*
32  * This file is separate from libdevinfo.h because the devinfo driver
33  * needs to know about the stuff. Library consumer should not care
34  * about stuff defined here.
35  *
36  * The only exception is di_priv_data (consolidation private) and
37  * DINFO* ioctls.
38  */
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 /* ioctl commands for devinfo driver */
45 
46 #define	DIIOC		(0xdf<<8)
47 #define	DIIOC_MASK	(0xffff00ff)
48 
49 /*
50  * Any combination of the following ORed together will take a snapshot
51  * of the device configuration data.
52  */
53 #define	DINFOSUBTREE	(DIIOC | 0x01)	/* include subtree */
54 #define	DINFOMINOR	(DIIOC | 0x02)	/* include minor data */
55 #define	DINFOPROP	(DIIOC | 0x04)	/* include properties */
56 #define	DINFOPATH	(DIIOC | 0x08)	/* include i/o pathing information */
57 
58 /* private bits */
59 #define	DINFOPRIVDATA	(DIIOC | 0x10)	/* include private data */
60 #define	DINFOFORCE	(DIIOC | 0x20)	/* force load all drivers */
61 #define	DINFOCACHE	(DIIOC | 0x100000) /* use cached data  */
62 #define	DINFOCLEANUP	(DIIOC | 0x200000) /* cleanup /etc/devices files */
63 
64 /* new public flag for the layered drivers framework */
65 #define	DINFOLYR	(DIIOC | 0x40)	/* get device layering information */
66 
67 /*
68  * Straight ioctl commands, not bitwise operation
69  */
70 #define	DINFOUSRLD	(DIIOC | 0x80)	/* copy snapshot to usrland */
71 #define	DINFOLODRV	(DIIOC | 0x81)	/* force load a driver */
72 #define	DINFOIDENT	(DIIOC | 0x82)	/* identify the driver */
73 
74 /*
75  * ioctl for taking a snapshot a single node and all nodes
76  */
77 #define	DINFOCPYONE	DIIOC
78 #define	DINFOCPYALL	(DINFOSUBTREE | DINFOPROP | DINFOMINOR)
79 
80 #define	DI_MAGIC	0xdfdf	/* magic number returned by DINFOIDENT */
81 
82 /* driver ops encoding */
83 
84 #define	DI_BUS_OPS	0x1
85 #define	DI_CB_OPS	0x2
86 #define	DI_STREAM_OPS	0x4
87 
88 /* property list enumeration */
89 
90 #define	DI_PROP_DRV_LIST	0
91 #define	DI_PROP_SYS_LIST	1
92 #define	DI_PROP_GLB_LIST	2
93 #define	DI_PROP_HW_LIST		3
94 
95 /* misc parameters */
96 
97 #define	MAX_TREE_DEPTH	64
98 #define	MAX_PTR_IN_PRV	5
99 #define	DI_SNAPSHOT_VERSION_0	0	/* reserved */
100 #define	DI_SNAPSHOT_VERSION_1	1	/* reserved */
101 #define	DI_SNAPSHOT_VERSION_2	2	/* reserved */
102 #define	DI_SNAPSHOT_VERSION	DI_SNAPSHOT_VERSION_2	/* current version */
103 #define	DI_PRIVDATA_VERSION_0	10	/* Start from 10 so caller must set */
104 #define	DI_BIG_ENDIAN		0	/* reserved */
105 #define	DI_LITTLE_ENDIAN	1	/* reserved */
106 
107 #define	DI_CACHE_MAGIC		0xdfcac6ed	/* magic # for cache */
108 #define	DI_CACHE_PERMS		(0444)
109 #define	DI_CACHE_SNAPSHOT_FLAGS	\
110 	(DINFOFORCE|DINFOSUBTREE|DINFOMINOR|DINFOPROP|DINFOPATH)
111 
112 #define	DI_NODE(addr)		((struct di_node *)((void *)(addr)))
113 #define	DI_MINOR(addr)		((struct di_minor *)((void *)(addr)))
114 #define	DI_PROP(addr)		((struct di_prop *)((void *)(addr)))
115 #define	DI_PATH(addr)		((struct di_path *)((void *)(addr)))
116 #define	DI_PATHPROP(addr)	((struct di_path_prop *)((void *)(addr)))
117 #define	DI_ALL(addr)		((struct di_all *)((void *)(addr)))
118 #define	DI_DEVNM(addr)		((struct di_devnm *)((void *)(addr)))
119 #define	DI_LINK(addr)		((struct di_link *)((void *)(addr)))
120 #define	DI_LNODE(addr)		((struct di_lnode *)((void *)(addr)))
121 #define	DI_PRIV_FORMAT(addr)	((struct di_priv_format *)((void *)(addr)))
122 
123 /*
124  * multipath component definitions:  Follows the registered component of
125  * the mpxio system.
126  */
127 #define	MULTIPATH_COMPONENT_NONE	0
128 #define	MULTIPATH_COMPONENT_VHCI	0x1
129 #define	MULTIPATH_COMPONENT_PHCI	0x2
130 #define	MULTIPATH_COMPONENT_CLIENT	0x4
131 
132 typedef int32_t di_off_t;
133 
134 /*
135  * devinfo driver snapshot data structure
136  */
137 struct di_all {
138 	int	version;	/* snapshot version, reserved */
139 	int	cache_magic;	/* magic number for cached snapshot */
140 	int	pd_version;	/* private data format version */
141 	int	endianness;	/* reserved for future use */
142 	int	generation;	/* reserved for future use */
143 	uint32_t	cache_checksum;	/* snapshot checksum */
144 	uint64_t	snapshot_time;	/* snapshot timestamp */
145 	di_off_t	top_devinfo;
146 	di_off_t	top_vhci_devinfo;
147 	di_off_t	devnames;
148 	di_off_t	ppdata_format;	/* parent priv data format array */
149 	di_off_t	dpdata_format;	/* driver priv data format array */
150 	int	n_ppdata;	/* size of ppdata_format array */
151 	int	n_dpdata;	/* size of pddata_format array */
152 	int	devcnt;		/* size of devnames array */
153 	uint_t	command;	/* same as in di_init() */
154 	uint_t	map_size;	/* size of the snapshot */
155 	char	root_path[1];	/* path to snapshot root */
156 };
157 
158 struct di_devnm {
159 	di_off_t name;
160 	di_off_t global_prop;
161 	di_off_t head;	/* head of per instance list */
162 	int flags;	/* driver attachment info */
163 	int instance;	/* next instance to assign */
164 	uint_t ops;	/* bit-encoded driver ops */
165 };
166 
167 
168 struct di_lnode;
169 
170 struct di_link {
171 	di_off_t	self;
172 	int		count;
173 	int		spec_type;	/* block or char access type */
174 	di_off_t	src_lnode;	/* src di_lnode */
175 	di_off_t	tgt_lnode;	/* tgt di_lnode */
176 	di_off_t	src_link_next;	/* next src di_link /w same di_lnode */
177 	di_off_t	tgt_link_next;	/* next tgt di_link /w same di_lnode */
178 	di_off_t	src_node_next;	/* next src di_link /w same di_node */
179 	di_off_t	tgt_node_next;	/* next tgt di_link /w same di_node */
180 	uint64_t 	user_private_data;
181 };
182 
183 struct di_lnode {
184 	di_off_t	self;
185 
186 	/*
187 	 * public information describing a link endpoint
188 	 */
189 	major_t		dev_major;	/* dev_t can be 64-bit */
190 	minor_t		dev_minor;	/* dev_t can be 64-bit */
191 	di_off_t	node;		/* offset of di_node */
192 
193 	/*
194 	 * di_link ptr to links comming into this node
195 	 * (this lnode is the target of these di_links)
196 	 */
197 	di_off_t	link_in;
198 
199 	/*
200 	 * di_link ptr to links going out of this node
201 	 * (this lnode is the source of these di_links)
202 	 */
203 	di_off_t	link_out;
204 
205 	/*
206 	 * di_lnode pointer to the next lnode associated with the
207 	 * same di_node
208 	 */
209 	di_off_t	node_next;
210 
211 	uint64_t 	user_private_data;
212 };
213 
214 struct di_node {	/* useful info to export for each tree node */
215 	/*
216 	 * offset to di_node structures
217 	 */
218 	di_off_t self;		/* make it self addressable */
219 	di_off_t parent;	/* offset of parent node */
220 	di_off_t child;		/* offset of child node */
221 	di_off_t sibling;	/* offset of sibling */
222 	di_off_t next;		/* next node on per-instance list */
223 	/*
224 	 * offset to char strings of current node
225 	 */
226 	di_off_t node_name;	/* offset of device node name */
227 	di_off_t address;	/* offset of address part of name */
228 	di_off_t bind_name;	/* offset of binding name */
229 	di_off_t compat_names;	/* offset of compatible names */
230 	/*
231 	 * offset to property lists, private data, etc.
232 	 */
233 	di_off_t minor_data;
234 	di_off_t drv_prop;
235 	di_off_t sys_prop;
236 	di_off_t glob_prop;
237 	di_off_t hw_prop;
238 	di_off_t parent_data;
239 	di_off_t driver_data;
240 	di_off_t multipath_client;
241 	di_off_t multipath_phci;
242 	di_off_t devid;		/* registered device id */
243 	di_off_t pm_info;	/* RESERVED FOR FUTURE USE */
244 	/*
245 	 * misc values
246 	 */
247 	int compat_length;	/* size of compatible name list */
248 	int drv_major;		/* for indexing into devnames array */
249 	/*
250 	 * value attributes of current node
251 	 */
252 	int instance;		/* instance number */
253 	int nodeid;		/* node id */
254 	ddi_node_class_t node_class;	/* node class */
255 	int attributes;		/* node attributes */
256 	uint_t state;		/* hotplugging device state */
257 	ddi_node_state_t node_state;	/* devinfo state */
258 
259 	di_off_t lnodes;	/* lnodes associated with this di_node */
260 	di_off_t tgt_links;
261 	di_off_t src_links;
262 
263 	uint32_t di_pad1;	/* 4 byte padding for 32bit x86 app. */
264 	uint64_t user_private_data;
265 	/*
266 	 * offset to link vhci/phci nodes.
267 	 */
268 	di_off_t next_vhci;
269 	di_off_t top_phci;
270 	di_off_t next_phci;
271 	uint32_t multipath_component;	/* stores MDI_COMPONENT_* value. */
272 
273 	/*
274 	 * devi_flags field
275 	 */
276 	uint32_t flags;
277 	uint32_t di_pad2;	/* 4 byte padding for 32bit x86 app. */
278 };
279 
280 /*
281  * chain of ddi_minor_data structure
282  */
283 struct di_minor {
284 	di_off_t	self;		/* make it self addressable */
285 	di_off_t	next;		/* next one in the chain */
286 	di_off_t	name;		/* name of node */
287 	di_off_t	node_type;	/* block, byte, serial, network */
288 	ddi_minor_type	type;		/* data type */
289 	major_t		dev_major;	/* dev_t can be 64-bit */
290 	minor_t		dev_minor;
291 	int		spec_type;	/* block or char */
292 	unsigned int	mdclass;	/* no longer used, may be removed */
293 	di_off_t	node;		/* address of di_node */
294 	uint64_t 	user_private_data;
295 };
296 
297 typedef enum {
298 	DI_PATH_STATE_UNKNOWN,
299 	DI_PATH_STATE_OFFLINE,
300 	DI_PATH_STATE_STANDBY,
301 	DI_PATH_STATE_ONLINE,
302 	DI_PATH_STATE_FAULT
303 } di_path_state_t;
304 
305 /*
306  * multipathing information structures
307  */
308 struct di_path {
309 	di_off_t	self;		/* make it self addressable */
310 	di_off_t	path_c_link;	/* next pathinfo via client linkage */
311 	di_off_t	path_p_link;	/* next pathinfo via phci linkage */
312 	di_off_t	path_client;	/* reference to client node */
313 	di_off_t	path_phci;	/* reference to phci node */
314 	di_off_t	path_prop;	/* property list */
315 	di_off_t	path_addr;	/* path addressing information */
316 	di_path_state_t path_state;	/* path state */
317 	uint_t		path_snap_state; /* describes valid fields */
318 	int		path_instance;	/* path instance */
319 	uint64_t 	user_private_data;
320 };
321 
322 /*
323  * Flags for snap_state
324  */
325 #define	DI_PATH_SNAP_NOCLIENT	0x01	/* client endpt not in snapshot */
326 #define	DI_PATH_SNAP_NOPHCI	0x02	/* phci endpt not in snapshot */
327 #define	DI_PATH_SNAP_ENDPTS	0x04	/* Endpoints have been postprocessed */
328 
329 #define	DI_PATH_SNAP_NOCLINK	0x10	/* client linkage not in snapshot */
330 #define	DI_PATH_SNAP_NOPLINK	0x20	/* phci linkage not in snapshot */
331 #define	DI_PATH_SNAP_LINKS	0x40	/* linkages have been postprocessed */
332 
333 /*
334  * path properties
335  */
336 struct di_path_prop {
337 	di_off_t	self;		/* make it self addressable */
338 	di_off_t	prop_next;	/* next property linkage */
339 	di_off_t	prop_name;	/* property name */
340 	di_off_t	prop_data;	/* property data */
341 	int		prop_type;	/* property data type */
342 	int		prop_len;	/* prop length in bytes */
343 };
344 
345 /*
346  * Now the properties.
347  */
348 struct di_prop {
349 	di_off_t	self;		/* make it self addressable */
350 	di_off_t	next;
351 	di_off_t	prop_name;	/* Property name */
352 	di_off_t	prop_data;	/* property data */
353 	major_t		dev_major;	/* dev_t can be 64 bit */
354 	minor_t		dev_minor;
355 	int		prop_flags;	/* mark prop value types & more */
356 	int		prop_len;	/* prop len in bytes (boolean if 0) */
357 	int		prop_list;	/* which list (DI_PROP_SYS_LIST), etc */
358 };
359 
360 /*
361  * Private data stuff for supporting prtconf.
362  * Allows one level of indirection of fixed sized obj or obj array.
363  * The array size may be an int member of the array.
364  */
365 
366 struct di_priv_format {
367 	char drv_name[MAXPATHLEN];	/* name of parent drv for ppdata */
368 	size_t bytes;			/* size in bytes of this struct */
369 	struct {			/* ptrs to dereference */
370 		int size;	/* size of object assoc. this ptr */
371 		int offset;	/* location of pointer within struct */
372 		int len_offset;	/* offset to var. containing the len */
373 	} ptr[MAX_PTR_IN_PRV];
374 };
375 
376 struct di_priv_data {
377 	int version;
378 	int n_parent;
379 	int n_driver;
380 	struct di_priv_format *parent;
381 	struct di_priv_format *driver;
382 };
383 
384 /*
385  * structure passed in from ioctl
386  */
387 struct dinfo_io {
388 	char root_path[MAXPATHLEN];
389 	struct di_priv_data priv;
390 };
391 
392 #ifdef	__cplusplus
393 }
394 #endif
395 
396 #endif	/* _SYS_DEVINFO_IMPL_H */
397