xref: /titanic_52/usr/src/uts/common/sys/devinfo_impl.h (revision bd0f52d78d701efcad2c460df61b45677d041c35)
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 2007 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
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 
57 /* private bits */
58 #define	DINFOPATH	(DIIOC | 0x08)	/* include i/o pathing information */
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 
122 /*
123  * For compatibility only
124  */
125 #define	DINO(addr)		DI_NODE(addr)
126 #define	DIMI(addr)		DI_MINOR(addr)
127 #define	DIPROP(addr)		DI_PROP(addr)
128 #define	DIPATH(addr)		DI_PATH(addr)
129 #define	DIPATHPROP(addr)	DI_PATHPROP(addr)
130 
131 /*
132  * multipath component definitions:  Follows the registered component of
133  * the mpxio system.
134  */
135 #define	MULTIPATH_COMPONENT_NONE	0
136 #define	MULTIPATH_COMPONENT_VHCI	0x1
137 #define	MULTIPATH_COMPONENT_PHCI	0x2
138 #define	MULTIPATH_COMPONENT_CLIENT	0x4
139 
140 typedef int32_t di_off_t;
141 
142 /*
143  * devinfo driver snapshot data structure
144  */
145 struct di_all {
146 	int	version;	/* snapshot version, reserved */
147 	int	cache_magic;	/* magic number for cached snapshot */
148 	int	pd_version;	/* private data format version */
149 	int	endianness;	/* reserved for future use */
150 	int	generation;	/* reserved for future use */
151 	uint32_t	cache_checksum;	/* snapshot checksum */
152 	uint64_t	snapshot_time;	/* snapshot timestamp */
153 	di_off_t	top_devinfo;
154 	di_off_t	top_vhci_devinfo;
155 	di_off_t	devnames;
156 	di_off_t	ppdata_format;	/* parent priv data format array */
157 	di_off_t	dpdata_format;	/* driver priv data format array */
158 	int	n_ppdata;	/* size of ppdata_format array */
159 	int	n_dpdata;	/* size of pddata_format array */
160 	int	devcnt;		/* size of devnames array */
161 	uint_t	command;	/* same as in di_init() */
162 	uint_t	map_size;	/* size of the snapshot */
163 	char	root_path[1];	/* path to snapshot root */
164 };
165 
166 struct di_devnm {
167 	di_off_t name;
168 	di_off_t global_prop;
169 	di_off_t head;	/* head of per instance list */
170 	int flags;	/* driver attachment info */
171 	int instance;	/* next instance to assign */
172 	uint_t ops;	/* bit-encoded driver ops */
173 };
174 
175 
176 struct di_lnode;
177 
178 struct di_link {
179 	di_off_t	self;
180 	int		count;
181 	int		spec_type;	/* block or char access type */
182 	di_off_t	src_lnode;	/* src di_lnode */
183 	di_off_t	tgt_lnode;	/* tgt di_lnode */
184 	di_off_t	src_link_next;	/* next src di_link /w same di_lnode */
185 	di_off_t	tgt_link_next;	/* next tgt di_link /w same di_lnode */
186 	di_off_t	src_node_next;	/* next src di_link /w same di_node */
187 	di_off_t	tgt_node_next;	/* next tgt di_link /w same di_node */
188 	uint64_t 	user_private_data;
189 };
190 
191 struct di_lnode {
192 	di_off_t	self;
193 
194 	/*
195 	 * public information describing a link endpoint
196 	 */
197 	major_t		dev_major;	/* dev_t can be 64-bit */
198 	minor_t		dev_minor;	/* dev_t can be 64-bit */
199 	di_off_t	node;		/* offset of di_node */
200 
201 	/*
202 	 * di_link ptr to links comming into this node
203 	 * (this lnode is the target of these di_links)
204 	 */
205 	di_off_t	link_in;
206 
207 	/*
208 	 * di_link ptr to links going out of this node
209 	 * (this lnode is the source of these di_links)
210 	 */
211 	di_off_t	link_out;
212 
213 	/*
214 	 * di_lnode pointer to the next lnode associated with the
215 	 * same di_node
216 	 */
217 	di_off_t	node_next;
218 
219 	uint64_t 	user_private_data;
220 };
221 
222 struct di_node {	/* useful info to export for each tree node */
223 	/*
224 	 * offset to di_node structures
225 	 */
226 	di_off_t self;		/* make it self addressable */
227 	di_off_t parent;	/* offset of parent node */
228 	di_off_t child;		/* offset of child node */
229 	di_off_t sibling;	/* offset of sibling */
230 	di_off_t next;		/* next node on per-instance list */
231 	/*
232 	 * offset to char strings of current node
233 	 */
234 	di_off_t node_name;	/* offset of device node name */
235 	di_off_t address;	/* offset of address part of name */
236 	di_off_t bind_name;	/* offset of binding name */
237 	di_off_t compat_names;	/* offset of compatible names */
238 	/*
239 	 * offset to property lists, private data, etc.
240 	 */
241 	di_off_t minor_data;
242 	di_off_t drv_prop;
243 	di_off_t sys_prop;
244 	di_off_t glob_prop;
245 	di_off_t hw_prop;
246 	di_off_t parent_data;
247 	di_off_t driver_data;
248 	di_off_t multipath_client;
249 	di_off_t multipath_phci;
250 	di_off_t devid;		/* registered device id */
251 	di_off_t pm_info;	/* RESERVED FOR FUTURE USE */
252 	/*
253 	 * misc values
254 	 */
255 	int compat_length;	/* size of compatible name list */
256 	int drv_major;		/* for indexing into devnames array */
257 	/*
258 	 * value attributes of current node
259 	 */
260 	int instance;		/* instance number */
261 	int nodeid;		/* node id */
262 	ddi_node_class_t node_class;	/* node class */
263 	int attributes;		/* node attributes */
264 	uint_t state;		/* hotplugging device state */
265 	ddi_node_state_t node_state;	/* devinfo state */
266 
267 	di_off_t lnodes;	/* lnodes associated with this di_node */
268 	di_off_t tgt_links;
269 	di_off_t src_links;
270 
271 	uint32_t di_pad1;	/* 4 byte padding for 32bit x86 app. */
272 	uint64_t user_private_data;
273 	/*
274 	 * offset to link vhci/phci nodes.
275 	 */
276 	di_off_t next_vhci;
277 	di_off_t top_phci;
278 	di_off_t next_phci;
279 	uint32_t multipath_component;	/* stores MDI_COMPONENT_* value. */
280 
281 	/*
282 	 * devi_flags field
283 	 */
284 	uint32_t flags;
285 	uint32_t di_pad2;	/* 4 byte padding for 32bit x86 app. */
286 };
287 
288 /*
289  * chain of ddi_minor_data structure
290  */
291 struct di_minor {
292 	di_off_t	self;		/* make it self addressable */
293 	di_off_t	next;		/* next one in the chain */
294 	di_off_t	name;		/* name of node */
295 	di_off_t	node_type;	/* block, byte, serial, network */
296 	ddi_minor_type	type;		/* data type */
297 	major_t		dev_major;	/* dev_t can be 64-bit */
298 	minor_t		dev_minor;
299 	int		spec_type;	/* block or char */
300 	unsigned int	mdclass;	/* no longer used, may be removed */
301 	di_off_t	node;		/* address of di_node */
302 	uint64_t 	user_private_data;
303 };
304 
305 typedef enum {
306 	DI_PATH_STATE_UNKNOWN,
307 	DI_PATH_STATE_OFFLINE,
308 	DI_PATH_STATE_STANDBY,
309 	DI_PATH_STATE_ONLINE,
310 	DI_PATH_STATE_FAULT
311 } di_path_state_t;
312 
313 /*
314  * multipathing information structures
315  */
316 struct di_path {
317 	di_off_t	self;		/* make it self addressable */
318 	di_off_t	path_c_link;	/* next pathinfo via client linkage */
319 	di_off_t	path_p_link;	/* next pathinfo via phci linkage */
320 	di_off_t	path_client;	/* reference to client node */
321 	di_off_t	path_phci;	/* reference to phci node */
322 	di_off_t	path_prop;	/* property list */
323 	di_off_t	path_addr;	/* path addressing information */
324 	di_path_state_t path_state;	/* path state */
325 	uint_t		path_snap_state;	/* describes valid fields */
326 };
327 
328 /*
329  * Flags for snap_state
330  */
331 #define	DI_PATH_SNAP_NOCLIENT	0x01	/* client endpt not in snapshot */
332 #define	DI_PATH_SNAP_NOPHCI	0x02	/* phci endpt not in snapshot */
333 #define	DI_PATH_SNAP_ENDPTS	0x04	/* Endpoints have been postprocessed */
334 
335 #define	DI_PATH_SNAP_NOCLINK	0x10	/* client linkage not in snapshot */
336 #define	DI_PATH_SNAP_NOPLINK	0x20	/* phci linkage not in snapshot */
337 #define	DI_PATH_SNAP_LINKS	0x40	/* linkages have been postprocessed */
338 
339 /*
340  * path properties
341  */
342 struct di_path_prop {
343 	di_off_t	self;		/* make it self addressable */
344 	di_off_t	prop_next;	/* next property linkage */
345 	di_off_t	prop_name;	/* property name */
346 	di_off_t	prop_data;	/* property data */
347 	int		prop_type;	/* property data type */
348 	int		prop_len;	/* prop length in bytes */
349 };
350 
351 /*
352  * Now the properties.
353  */
354 struct di_prop {
355 	di_off_t	self;		/* make it self addressable */
356 	di_off_t	next;
357 	di_off_t	prop_name;	/* Property name */
358 	di_off_t	prop_data;	/* property data */
359 	major_t		dev_major;	/* dev_t can be 64 bit */
360 	minor_t		dev_minor;
361 	int	prop_flags;	/* mark prop value types & more */
362 	int	prop_len;	/* prop length in bytes (boolean if 0) */
363 	int	prop_list;	/* which list (DI_PROP_SYS_LIST), etc */
364 };
365 
366 /*
367  * Private data stuff for supporting prtconf.
368  * Allows one level of indirection of fixed sized obj or obj array.
369  * The array size may be an int member of the array.
370  */
371 
372 struct di_priv_format {
373 	char drv_name[MAXPATHLEN];	/* name of parent drv for ppdata */
374 	size_t bytes;			/* size in bytes of this struct */
375 	struct {			/* ptrs to dereference */
376 		int size;	/* size of object assoc. this ptr */
377 		int offset;	/* location of pointer within struct */
378 		int len_offset;	/* offset to var. containing the len */
379 	} ptr[MAX_PTR_IN_PRV];
380 };
381 
382 struct di_priv_data {
383 	int version;
384 	int n_parent;
385 	int n_driver;
386 	struct di_priv_format *parent;
387 	struct di_priv_format *driver;
388 };
389 
390 /*
391  * structure passed in from ioctl
392  */
393 struct dinfo_io {
394 	char root_path[MAXPATHLEN];
395 	struct di_priv_data priv;
396 };
397 
398 #ifdef	__cplusplus
399 }
400 #endif
401 
402 #endif	/* _SYS_DEVINFO_IMPL_H */
403