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