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