xref: /titanic_44/usr/src/uts/common/sys/devinfo_impl.h (revision c28749e97052f09388969427adf7df641cdcdc22)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_DEVINFO_IMPL_H
28 #define	_SYS_DEVINFO_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * This file is separate from libdevinfo.h because the devinfo driver
34  * needs to know about the stuff. Library consumer should not care
35  * about stuff defined here.
36  *
37  * The only exception is di_priv_data (consolidation private) and
38  * DINFO* ioctls.
39  */
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /* ioctl commands for devinfo driver */
46 
47 #define	DIIOC		(0xdf<<8)
48 #define	DIIOC_MASK	(0xffff00ff)
49 
50 /*
51  * Any combination of the following ORed together will take a snapshot
52  * of the device configuration data.
53  */
54 #define	DINFOSUBTREE	(DIIOC | 0x01)	/* include subtree */
55 #define	DINFOMINOR	(DIIOC | 0x02)	/* include minor data */
56 #define	DINFOPROP	(DIIOC | 0x04)	/* include properties */
57 
58 /* private bits */
59 #define	DINFOPATH	(DIIOC | 0x08)	/* include i/o pathing information */
60 #define	DINFOPRIVDATA	(DIIOC | 0x10)	/* include private data */
61 #define	DINFOFORCE	(DIIOC | 0x20)	/* force load all drivers */
62 #define	DINFOCACHE	(DIIOC | 0x100000) /* use cached data  */
63 #define	DINFOCLEANUP	(DIIOC | 0x200000) /* cleanup /etc/devices files */
64 
65 /* new public flag for the layered drivers framework */
66 #define	DINFOLYR	(DIIOC | 0x40)	/* get device layering information */
67 
68 /*
69  * Straight ioctl commands, not bitwise operation
70  */
71 #define	DINFOUSRLD	(DIIOC | 0x80)	/* copy snapshot to usrland */
72 #define	DINFOLODRV	(DIIOC | 0x81)	/* force load a driver */
73 #define	DINFOIDENT	(DIIOC | 0x82)	/* identify the driver */
74 
75 /*
76  * ioctl for taking a snapshot a single node and all nodes
77  */
78 #define	DINFOCPYONE	DIIOC
79 #define	DINFOCPYALL	(DINFOSUBTREE | DINFOPROP | DINFOMINOR)
80 
81 #define	DI_MAGIC	0xdfdf	/* magic number returned by DINFOIDENT */
82 
83 /* driver ops encoding */
84 
85 #define	DI_BUS_OPS	0x1
86 #define	DI_CB_OPS	0x2
87 #define	DI_STREAM_OPS	0x4
88 
89 /* property list enumeration */
90 
91 #define	DI_PROP_DRV_LIST	0
92 #define	DI_PROP_SYS_LIST	1
93 #define	DI_PROP_GLB_LIST	2
94 #define	DI_PROP_HW_LIST		3
95 
96 /* misc parameters */
97 
98 #define	MAX_TREE_DEPTH	64
99 #define	MAX_PTR_IN_PRV	5
100 #define	DI_SNAPSHOT_VERSION_0	0	/* reserved */
101 #define	DI_SNAPSHOT_VERSION_1	1	/* reserved */
102 #define	DI_SNAPSHOT_VERSION	DI_SNAPSHOT_VERSION_1	/* 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 /*
283  * chain of ddi_minor_data structure
284  */
285 struct di_minor {
286 	di_off_t	self;		/* make it self addressable */
287 	di_off_t	next;		/* next one in the chain */
288 	di_off_t	name;		/* name of node */
289 	di_off_t	node_type;	/* block, byte, serial, network */
290 	ddi_minor_type	type;		/* data type */
291 	major_t		dev_major;	/* dev_t can be 64-bit */
292 	minor_t		dev_minor;
293 	int		spec_type;	/* block or char */
294 	unsigned int	mdclass;	/* no longer used, may be removed */
295 	di_off_t	node;		/* address of di_node */
296 	uint64_t 	user_private_data;
297 };
298 
299 typedef enum {
300 	DI_PATH_STATE_UNKNOWN,
301 	DI_PATH_STATE_OFFLINE,
302 	DI_PATH_STATE_STANDBY,
303 	DI_PATH_STATE_ONLINE,
304 	DI_PATH_STATE_FAULT
305 } di_path_state_t;
306 
307 /*
308  * multipathing information structures
309  */
310 struct di_path {
311 	di_off_t	self;		/* make it self addressable */
312 	di_off_t	path_c_link;	/* next pathinfo via client linkage */
313 	di_off_t	path_p_link;	/* next pathinfo via phci linkage */
314 	di_off_t	path_client;	/* reference to client node */
315 	di_off_t	path_phci;	/* reference to phci node */
316 	di_off_t	path_prop;	/* property list */
317 	di_off_t	path_addr;	/* path addressing information */
318 	di_path_state_t path_state;	/* path state */
319 	uint_t		path_snap_state;	/* describes valid fields */
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 length 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