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