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 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_MDI_IMPLDEFS_H 27 #define _SYS_MDI_IMPLDEFS_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #include <sys/note.h> 32 #include <sys/types.h> 33 #include <sys/sunmdi.h> 34 #include <sys/modhash.h> 35 #include <sys/callb.h> 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 #ifdef _KERNEL 42 43 /* 44 * Multipath Driver Interfaces 45 * 46 * The multipathing framework is provided in two modules. The 'mpxio' misc. 47 * module provides the core multipath framework and the 'scsi_vhci' nexus 48 * driver provides the SCSI-III command set driver functionality for 49 * managing Fibre-Channel storage devices. 50 * 51 * As in any multipathing solution there are three major problems to solve: 52 * 53 * 1) Identification and enumeration of multipath client devices. 54 * 2) Optimal path selection when routing I/O requests. 55 * 3) Observability interfaces to snapshot the multipath configuration, 56 * and infrastructure to provide performance and error statistics. 57 * 58 * The mpxio framework consists of several major components: 59 * 60 * 1) The MDI is the Multiplexed Device Interface; this is the core glue which 61 * holds the following components together. 62 * 2) vHCI (Virtual Host Controller Interconnect) drivers provide multipathing 63 * services for a given bus technology (example: 'scsi_vhci' provides 64 * multipathing support for SCSI-III fibre-channel devices). 65 * 3) pHCI (Physical Host Controller Interconnect) drivers provide transport 66 * services for a given host controller (example: 'fcp' provides transport 67 * for fibre-channel devices). 68 * 4) Client Devices are standard Solaris target (or leaf) drivers 69 * (example: 'ssd' is the standard disk driver for fibre-channel arrays). 70 * 5) Multipath information nodes ('pathinfo' nodes) connect client device 71 * nodes and pHCI device nodes in the device tree. 72 * 73 * With the scsi_vhci, a QLC card, and mpxio enabled, the device tree might 74 * look like this: 75 * 76 * +-----------+ +-----------+ 77 * | scsi_vhci | | pci@1f,0 | 78 * +-----------+ +-----------+ 79 * / \ \ 80 * +----------+ +-----------+ +-------------+ 81 * | ssd1 | | ssd2 | | qlc@0,0 | 82 * +----------+ +-----------+ +-------------+ 83 * | | / \ 84 * | | +-------------+ +------------+ 85 * | | | pHCI 1 | | pHCI 2 | 86 * | | +-------------+ +------------+ 87 * | | / | / | 88 * | | +------+ | +------+ | 89 * | | | ssd | | | ssd | | 90 * | | | (OBP)| | | (OBP)| | 91 * | | +------+ | +------+ | 92 * | | | | 93 * | | +-------+ +--------+ 94 * | +-------------->| path |---------->| path | 95 * | | info | | info | 96 * | | node 1| | node 3 | 97 * | +-------+ +--------+ 98 * | | | 99 * | +-------+ +--------+ 100 * +------------------------->| path |---------->| path | 101 * | info | | info | 102 * | node 2| | node 4 | 103 * +-------+ +--------+ 104 * 105 * The multipath information nodes (mdi_pathinfo nodes) establish the 106 * relationship between the pseudo client driver instance nodes and the 107 * physical host controller interconnect (pHCI drivers) forming a matrix 108 * structure. 109 * 110 * The mpxio module implements locking at multiple granularity levels to 111 * support the needs of various consumers. The multipath matrix can be 112 * globally locked, column locked, or row locked depending on the consumer. 113 * The intention is to balance simplicity and performance. 114 * 115 * Locking: 116 * 117 * The current implementation utilizes the following locks: 118 * 119 * mdi_mutex: protects the vHCI list, per-vHCI structure and the 120 * list of pHCIs and Client devices registered against them (protection 121 * against multi-threaded add/remove). 122 * 123 * devinfo_tree_lock (rw): protects system wide creation/removal of 124 * mdi_pathinfo nodes into the multipath matrix. Consumers (like the devinfo 125 * driver) can freeze the configuration by acquiring this as a reader. 126 * 127 * per-pHCI (mutex) lock: protects the column (pHCI-mdi_pathinfo node list) 128 * and per-pHCI structure fields. mdi_pathinfo node creation, deletion and 129 * child mdi_pathinfo node state changes are serialized on per pHCI basis 130 * (Protection against DR). 131 * 132 * per-client (mutex) lock: protects the row (client-mdi_pathinfo node list) 133 * and per-client structure fields. The client-mdi_pathinfo node list is 134 * typically walked to select an optimal path when routing I/O requests. 135 * 136 * per-mdi_pathinfo (mutex) lock: protects the mdi_pathinfo node structure 137 * fields. 138 * 139 * Note that per-Client structure and per-pHCI fields are freely readable when 140 * corresponding mdi_pathinfo locks are held, since holding an mdi_pathinfo 141 * node guarantees that its corresponding client and pHCI devices will not be 142 * freed. 143 */ 144 145 /* 146 * MDI Client global unique identifier property name string definition 147 */ 148 extern const char *mdi_client_guid_prop; 149 #define MDI_CLIENT_GUID_PROP (char *)mdi_client_guid_prop 150 151 /* 152 * MDI Client load balancing policy definitions 153 * 154 * Load balancing policies are determined on a per-vHCI basis and are 155 * configurable via the vHCI's driver.conf file. 156 */ 157 typedef enum { 158 LOAD_BALANCE_NONE, /* Alternate pathing */ 159 LOAD_BALANCE_RR, /* Round Robin */ 160 LOAD_BALANCE_LBA /* Logical Block Addressing */ 161 } client_lb_t; 162 163 typedef struct { 164 int region_size; 165 }client_lb_args_t; 166 167 /* 168 * MDI client load balancing property name/value string definitions 169 */ 170 extern const char *mdi_load_balance; 171 extern const char *mdi_load_balance_none; 172 extern const char *mdi_load_balance_ap; 173 extern const char *mdi_load_balance_rr; 174 extern const char *mdi_load_balance_lba; 175 176 #define LOAD_BALANCE_PROP (char *)mdi_load_balance 177 #define LOAD_BALANCE_PROP_NONE (char *)mdi_load_balance_none 178 #define LOAD_BALANCE_PROP_AP (char *)mdi_load_balance_ap 179 #define LOAD_BALANCE_PROP_RR (char *)mdi_load_balance_rr 180 #define LOAD_BALANCE_PROP_LBA (char *)mdi_load_balance_lba 181 182 /* default for region size */ 183 #define LOAD_BALANCE_DEFAULT_REGION_SIZE 18 184 185 /* 186 * vHCI drivers: 187 * 188 * vHCI drivers are pseudo nexus drivers which implement multipath services 189 * for a specific command set or bus architecture ('class'). There is a 190 * single instance of the vHCI driver for each command set which supports 191 * multipath devices. 192 * 193 * Each vHCI driver registers the following callbacks from attach(9e). 194 */ 195 #define MDI_VHCI_OPS_REV_1 1 196 /* 197 * Change MDI_VHCI_OPS_REV_NAME as per MDI_VHCI_OPS_REV 198 */ 199 #define MDI_VHCI_OPS_REV MDI_VHCI_OPS_REV_1 200 #define MDI_VHCI_OPS_REV_NAME "1" 201 202 typedef struct mdi_vhci_ops { 203 /* revision management */ 204 int vo_revision; 205 206 /* mdi_pathinfo node init callback */ 207 int (*vo_pi_init)(dev_info_t *vdip, mdi_pathinfo_t *pip, int flags); 208 209 /* mdi_pathinfo node uninit callback */ 210 int (*vo_pi_uninit)(dev_info_t *vdip, mdi_pathinfo_t *pip, 211 int flags); 212 213 /* mdi_pathinfo node state change callback */ 214 int (*vo_pi_state_change)(dev_info_t *vdip, mdi_pathinfo_t *pip, 215 mdi_pathinfo_state_t state, uint32_t, int flags); 216 217 /* Client path failover callback */ 218 int (*vo_failover)(dev_info_t *vdip, dev_info_t *cdip, int flags); 219 } mdi_vhci_ops_t; 220 221 /* 222 * An mdi_vhci structure is created and bound to the devinfo node of every 223 * registered vHCI class driver; this happens when a vHCI registers itself from 224 * attach(9e). This structure is unbound and freed when the vHCI unregisters 225 * at detach(9e) time; 226 * 227 * Each vHCI driver is associated with a vHCI class name; this is the handle 228 * used to register and unregister pHCI drivers for a given transport. 229 * 230 * Locking: This structure is guarded by the mdi_mutex; however, depending 231 * on the context, some of the fields can be freely read without holding any 232 * locks (ex. holding a child's lock also guarantees that the vHCI (parent) 233 * cannot be unexpectedly freed). 234 */ 235 typedef struct mdi_vhci { 236 struct mdi_vhci *vh_next; /* next link */ 237 struct mdi_vhci *vh_prev; /* prev link */ 238 int vh_flags; /* Operation flags */ 239 dev_info_t *vh_dip; /* devi handle */ 240 char *vh_class; /* Class name */ 241 struct mdi_vhci_ops *vh_ops; /* Callback vectors */ 242 client_lb_t vh_lb; /* Global cache */ 243 int vh_phci_count; /* pHCI device count */ 244 struct mdi_phci *vh_phci_head; /* pHCI list head */ 245 struct mdi_phci *vh_phci_tail; /* pHCI list tail */ 246 int vh_client_count; /* Client count */ 247 struct client_hash *vh_client_table; /* Client hash */ 248 int vh_refcnt; /* reference count */ 249 struct mdi_vhci_config *vh_config; /* vhci config */ 250 } mdi_vhci_t; 251 252 /* 253 * GUID Hash definitions 254 * 255 * Since all the mpxio managed devices for a given class are enumerated under 256 * the single vHCI instance for that class, sequentially walking through the 257 * client device link to find a client would be prohibitively slow. 258 */ 259 260 #define CLIENT_HASH_TABLE_SIZE (32) /* GUID hash */ 261 262 /* 263 * Client hash table structure 264 */ 265 struct client_hash { 266 struct mdi_client *ct_hash_head; /* Client hash head */ 267 int ct_hash_count; /* Client hash count */ 268 }; 269 270 271 /* 272 * pHCI Drivers: 273 * 274 * Physical HBA drivers provide transport services for mpxio-managed devices. 275 * As each pHCI instance is attached, it must register itself with the mpxio 276 * framework using mdi_phci_register(). When the pHCI is detached it must 277 * similarly call mdi_phci_unregister(). 278 * 279 * The framework maintains a list of registered pHCI device instances for each 280 * vHCI. This list is vHCI->vh_phci_count, vHCI->vh_phci_head, 281 * vHCI->vh_phci_tail and pHCI->ph_next. This list is protected by the global 282 * mdi_mutex. 283 * 284 * Locking order: 285 * 286 * _NOTE(LOCK_ORDER(mdi_mutex, mdi_phci::ph_mutex)) 287 * _NOTE(LOCK_ORDER(mdi_phci::ph_mutex devinfo_tree_lock)) 288 */ 289 typedef struct mdi_phci { 290 kmutex_t ph_mutex; /* per-pHCI mutex */ 291 struct mdi_phci *ph_next; /* next link */ 292 struct mdi_phci *ph_prev; /* prev link */ 293 dev_info_t *ph_dip; /* devi handle */ 294 struct mdi_vhci *ph_vhci; /* back ref. to vHCI */ 295 int ph_flags; /* pHCI operation flags */ 296 int ph_path_count; /* child pi count */ 297 mdi_pathinfo_t *ph_path_head; /* pi list head */ 298 mdi_pathinfo_t *ph_path_tail; /* pi list tail */ 299 int ph_unstable; /* Paths in transient state */ 300 kcondvar_t ph_unstable_cv; /* Paths in transient state */ 301 kcondvar_t ph_powerchange_cv; 302 /* Paths in transient state */ 303 void *ph_vprivate; /* vHCI driver private */ 304 } mdi_phci_t; 305 306 /* 307 * A pHCI device is 'unstable' while one or more paths are in a transitional 308 * state. Hotplugging is prevented during this state. 309 */ 310 #define MDI_PHCI_UNSTABLE(ph) (ph)->ph_unstable++; 311 #define MDI_PHCI_STABLE(ph) { \ 312 (ph)->ph_unstable--; \ 313 if ((ph)->ph_unstable == 0) { \ 314 cv_broadcast(&(ph)->ph_unstable_cv); \ 315 } \ 316 } 317 318 /* 319 * per-pHCI lock macros 320 */ 321 #define MDI_PHCI_LOCK(ph) mutex_enter(&((ph))->ph_mutex) 322 #define MDI_PHCI_TRYLOCK(ph) mutex_tryenter(&((ph))->ph_mutex) 323 #define MDI_PHCI_UNLOCK(ph) mutex_exit(&((ph))->ph_mutex) 324 325 /* 326 * pHCI state definitions and macros to track the pHCI driver instance state 327 */ 328 #define MDI_PHCI_FLAGS_OFFLINE 0x1 /* pHCI is offline */ 329 #define MDI_PHCI_FLAGS_SUSPEND 0x2 /* pHCI is suspended */ 330 #define MDI_PHCI_FLAGS_POWER_DOWN 0x4 /* pHCI is power down */ 331 #define MDI_PHCI_FLAGS_DETACH 0x8 /* pHCI is detached */ 332 #define MDI_PHCI_FLAGS_USER_DISABLE 0x10 /* pHCI is disabled,user */ 333 #define MDI_PHCI_FLAGS_D_DISABLE 0x20 /* pHCI is disabled,driver */ 334 #define MDI_PHCI_FLAGS_D_DISABLE_TRANS 0x40 /* pHCI is disabled,transient */ 335 #define MDI_PHCI_FLAGS_POWER_TRANSITION 0x80 /* pHCI is power transition */ 336 337 #define MDI_PHCI_DISABLE_MASK (~(MDI_PHCI_FLAGS_USER_DISABLE | \ 338 MDI_PHCI_FLAGS_D_DISABLE | \ 339 MDI_PHCI_FLAGS_D_DISABLE_TRANS)) 340 #define MDI_PHCI_IS_READY(ph) \ 341 (((ph)->ph_flags & (MDI_PHCI_DISABLE_MASK)) == 0) 342 343 #define MDI_PHCI_SET_OFFLINE(ph) \ 344 ((ph)->ph_flags |= MDI_PHCI_FLAGS_OFFLINE) 345 346 #define MDI_PHCI_SET_ONLINE(ph) \ 347 ((ph)->ph_flags &= ~MDI_PHCI_FLAGS_OFFLINE) 348 349 #define MDI_PHCI_SET_SUSPEND(ph) \ 350 ((ph)->ph_flags |= MDI_PHCI_FLAGS_SUSPEND) 351 352 #define MDI_PHCI_SET_RESUME(ph) \ 353 ((ph)->ph_flags &= ~MDI_PHCI_FLAGS_SUSPEND) 354 355 #define MDI_PHCI_IS_OFFLINE(ph) \ 356 ((ph)->ph_flags & MDI_PHCI_FLAGS_OFFLINE) 357 358 #define MDI_PHCI_IS_SUSPENDED(ph) \ 359 ((ph)->ph_flags & MDI_PHCI_FLAGS_SUSPEND) 360 361 #define MDI_PHCI_SET_DETACH(ph) \ 362 ((ph)->ph_flags |= MDI_PHCI_FLAGS_DETACH) 363 364 #define MDI_PHCI_SET_ATTACH(ph) \ 365 ((ph)->ph_flags &= ~MDI_PHCI_FLAGS_DETACH) 366 367 #define MDI_PHCI_SET_POWER_DOWN(ph) \ 368 ((ph)->ph_flags |= MDI_PHCI_FLAGS_POWER_DOWN) 369 370 #define MDI_PHCI_SET_POWER_UP(ph) \ 371 ((ph)->ph_flags &= ~MDI_PHCI_FLAGS_POWER_DOWN) 372 373 #define MDI_PHCI_SET_USER_ENABLE(ph) \ 374 ((ph)->ph_flags &= ~MDI_PHCI_FLAGS_USER_DISABLE) 375 376 #define MDI_PHCI_SET_USER_DISABLE(ph) \ 377 ((ph)->ph_flags |= MDI_PHCI_FLAGS_USER_DISABLE) 378 379 #define MDI_PHCI_SET_DRV_ENABLE(ph) \ 380 ((ph)->ph_flags &= ~MDI_PHCI_FLAGS_D_DISABLE) 381 382 #define MDI_PHCI_SET_DRV_DISABLE(ph) \ 383 ((ph)->ph_flags |= MDI_PHCI_FLAGS_D_DISABLE) 384 385 #define MDI_PHCI_SET_DRV_ENABLE_TRANSIENT(ph) \ 386 ((ph)->ph_flags &= ~MDI_PHCI_FLAGS_D_DISABLE_TRANS) 387 388 #define MDI_PHCI_SET_DRV_DISABLE_TRANSIENT(ph) \ 389 ((ph)->ph_flags |= MDI_PHCI_FLAGS_D_DISABLE_TRANS) 390 391 #define MDI_PHCI_IS_USER_DISABLED(ph) \ 392 ((ph)->ph_flags & MDI_PHCI_FLAGS_USER_DISABLE) 393 394 #define MDI_PHCI_IS_DRV_DISABLED_TRANSIENT(ph) \ 395 ((ph)->ph_flags & MDI_PHCI_FLAGS_D_DISABLE_TRANS) 396 397 #define MDI_PHCI_IS_DRV_DISABLED(ph) \ 398 ((ph)->ph_flags & MDI_PHCI_FLAGS_D_DISABLE) 399 400 #define MDI_PHCI_IS_POWERED_DOWN(ph) \ 401 ((ph)->ph_flags & MDI_PHCI_FLAGS_POWER_DOWN) 402 403 #define MDI_PHCI_SET_POWER_TRANSITION(ph) \ 404 ((ph)->ph_flags |= MDI_PHCI_FLAGS_POWER_TRANSITION) 405 406 #define MDI_PHCI_CLEAR_POWER_TRANSITION(ph) \ 407 ((ph)->ph_flags &= ~MDI_PHCI_FLAGS_POWER_TRANSITION) 408 409 #define MDI_PHCI_IS_POWER_TRANSITION(ph) \ 410 ((ph)->ph_flags & MDI_PHCI_FLAGS_POWER_TRANSITION) 411 412 /* 413 * mpxio Managed Clients: 414 * 415 * This framework creates a struct mdi_client for every client device created 416 * by the framework as a result of self-enumeration of target devices by the 417 * registered pHCI devices. This structure is bound to client device dev_info 418 * node at the time of client device allocation (ndi_devi_alloc(9e)). This 419 * structure is unbound from the dev_info node when mpxio framework removes a 420 * client device node from the system. 421 * 422 * This structure is created when a first path is enumerated and removed when 423 * last path is de-enumerated from the system. 424 * 425 * Multipath client devices are instantiated as children of corresponding vHCI 426 * driver instance. Each client device is uniquely identified by a GUID 427 * provided by target device itself. The parent vHCI device also maintains a 428 * hashed list of client devices, protected by the global mdi_mutex. 429 * 430 * Typically pHCI devices self-enumerate their child devices using taskq, 431 * resulting in multiple paths to the same client device to be enumerated by 432 * competing threads. mdi_mutex is also used to serialize the client device 433 * creation. 434 * 435 * Currently this framework supports two kinds of load-balancing policy 436 * configurable through the vHCI driver configuration files. 437 * 438 * NONE - Legacy AP mode 439 * Round Robin - Balance the pHCI load in a Round Robin fashion. 440 * 441 * This framework identifies the client device in three distinct states: 442 * 443 * OPTIMAL - Client device has atleast one redundant path. 444 * DEGRADED - No redundant paths (critical). Failure in the current active 445 * path would result in data access failures. 446 * FAILED - No paths are available to access this device. 447 * 448 * Locking order: 449 * 450 * _NOTE(LOCK_ORDER(mdi_mutex, mdi_client::ct_mutex)) 451 * _NOTE(LOCK_ORDER(mdi_client::ct_mutex devinfo_tree_lock)) 452 */ 453 typedef struct mdi_client { 454 kmutex_t ct_mutex; /* per-client mutex */ 455 struct mdi_client *ct_hnext; /* next client */ 456 struct mdi_client *ct_hprev; /* prev client */ 457 dev_info_t *ct_dip; /* client devi handle */ 458 struct mdi_vhci *ct_vhci; /* vHCI back ref */ 459 char *ct_drvname; /* client driver name */ 460 char *ct_guid; /* client guid */ 461 void *ct_cprivate; /* client driver private */ 462 client_lb_t ct_lb; /* load balancing scheme */ 463 client_lb_args_t *ct_lb_args; /* load balancing args */ 464 int ct_flags; /* Driver op. flags */ 465 int ct_state; /* state information */ 466 int ct_failover_flags; /* Failover args */ 467 int ct_failover_status; /* last fo status */ 468 kcondvar_t ct_failover_cv; /* Failover status cv */ 469 int ct_path_count; /* multi path count */ 470 mdi_pathinfo_t *ct_path_head; /* multi path list head */ 471 mdi_pathinfo_t *ct_path_tail; /* multi path list tail */ 472 mdi_pathinfo_t *ct_path_last; /* last path used for i/o */ 473 int ct_unstable; /* Paths in transient state */ 474 kcondvar_t ct_unstable_cv; /* Paths in transient state */ 475 int ct_power_cnt; /* Hold count on parent power */ 476 kcondvar_t ct_powerchange_cv; 477 /* Paths in power transient state */ 478 short ct_powercnt_config; 479 /* held in pre/post config */ 480 short ct_powercnt_unconfig; 481 /* held in pre/post unconfig */ 482 int ct_powercnt_reset; 483 /* ct_power_cnt was resetted */ 484 void *ct_vprivate; /* vHCI driver private */ 485 } mdi_client_t; 486 487 /* 488 * per-Client device locking definitions 489 */ 490 #define MDI_CLIENT_LOCK(ct) mutex_enter(&((ct))->ct_mutex) 491 #define MDI_CLIENT_TRYLOCK(ct) mutex_tryenter(&((ct))->ct_mutex) 492 #define MDI_CLIENT_UNLOCK(ct) mutex_exit(&((ct))->ct_mutex) 493 494 /* 495 * A Client device is in unstable while one or more paths are in transitional 496 * state. We do not allow failover to take place while paths are in transient 497 * state. Similarly we do not allow state transition while client device 498 * failover is in progress. 499 */ 500 #define MDI_CLIENT_UNSTABLE(ct) (ct)->ct_unstable++; 501 #define MDI_CLIENT_STABLE(ct) { \ 502 (ct)->ct_unstable--; \ 503 if ((ct)->ct_unstable == 0) { \ 504 cv_broadcast(&(ct)->ct_unstable_cv); \ 505 } \ 506 } 507 508 /* 509 * Client driver instance state definitions: 510 */ 511 #define MDI_CLIENT_FLAGS_OFFLINE 0x00000001 512 #define MDI_CLIENT_FLAGS_SUSPEND 0x00000002 513 #define MDI_CLIENT_FLAGS_POWER_DOWN 0x00000004 514 #define MDI_CLIENT_FLAGS_DETACH 0x00000008 515 #define MDI_CLIENT_FLAGS_FAILOVER 0x00000010 516 #define MDI_CLIENT_FLAGS_REPORT_DEV 0x00000020 517 #define MDI_CLIENT_FLAGS_PATH_FREE_IN_PROGRESS 0x00000040 518 #define MDI_CLIENT_FLAGS_ASYNC_FREE 0x00000080 519 #define MDI_CLIENT_FLAGS_DEV_NOT_SUPPORTED 0x00000100 520 #define MDI_CLIENT_FLAGS_POWER_TRANSITION 0x00000200 521 522 #define MDI_CLIENT_SET_OFFLINE(ct) \ 523 ((ct)->ct_flags |= MDI_CLIENT_FLAGS_OFFLINE) 524 525 #define MDI_CLIENT_SET_ONLINE(ct) \ 526 ((ct)->ct_flags &= ~MDI_CLIENT_FLAGS_OFFLINE) 527 528 #define MDI_CLIENT_IS_OFFLINE(ct) \ 529 ((ct)->ct_flags & MDI_CLIENT_FLAGS_OFFLINE) 530 531 #define MDI_CLIENT_SET_SUSPEND(ct) \ 532 ((ct)->ct_flags |= MDI_CLIENT_FLAGS_SUSPEND) 533 534 #define MDI_CLIENT_SET_RESUME(ct) \ 535 ((ct)->ct_flags &= ~MDI_CLIENT_FLAGS_SUSPEND) 536 537 #define MDI_CLIENT_IS_SUSPENDED(ct) \ 538 ((ct)->ct_flags & MDI_CLIENT_FLAGS_SUSPEND) 539 540 #define MDI_CLIENT_SET_POWER_DOWN(ct) \ 541 ((ct)->ct_flags |= MDI_CLIENT_FLAGS_POWER_DOWN) 542 543 #define MDI_CLIENT_SET_POWER_UP(ct) \ 544 ((ct)->ct_flags &= ~MDI_CLIENT_FLAGS_POWER_DOWN) 545 546 #define MDI_CLIENT_IS_POWERED_DOWN(ct) \ 547 ((ct)->ct_flags & MDI_CLIENT_FLAGS_POWER_DOWN) 548 549 #define MDI_CLIENT_SET_POWER_TRANSITION(ct) \ 550 ((ct)->ct_flags |= MDI_CLIENT_FLAGS_POWER_TRANSITION) 551 552 #define MDI_CLIENT_CLEAR_POWER_TRANSITION(ct) \ 553 ((ct)->ct_flags &= ~MDI_CLIENT_FLAGS_POWER_TRANSITION) 554 555 #define MDI_CLIENT_IS_POWER_TRANSITION(ct) \ 556 ((ct)->ct_flags & MDI_CLIENT_FLAGS_POWER_TRANSITION) 557 558 #define MDI_CLIENT_SET_DETACH(ct) \ 559 ((ct)->ct_flags |= MDI_CLIENT_FLAGS_DETACH) 560 561 #define MDI_CLIENT_SET_ATTACH(ct) \ 562 ((ct)->ct_flags &= ~MDI_CLIENT_FLAGS_DETACH) 563 564 #define MDI_CLIENT_IS_DETACHED(ct) \ 565 ((ct)->ct_flags & MDI_CLIENT_FLAGS_DETACH) 566 567 #define MDI_CLIENT_SET_FAILOVER_IN_PROGRESS(ct) \ 568 ((ct)->ct_flags |= MDI_CLIENT_FLAGS_FAILOVER) 569 570 #define MDI_CLIENT_CLEAR_FAILOVER_IN_PROGRESS(ct) \ 571 ((ct)->ct_flags &= ~MDI_CLIENT_FLAGS_FAILOVER) 572 573 #define MDI_CLIENT_IS_FAILOVER_IN_PROGRESS(ct) \ 574 ((ct)->ct_flags & MDI_CLIENT_FLAGS_FAILOVER) 575 576 #define MDI_CLIENT_SET_REPORT_DEV_NEEDED(ct) \ 577 ((ct)->ct_flags |= MDI_CLIENT_FLAGS_REPORT_DEV) 578 579 #define MDI_CLIENT_CLEAR_REPORT_DEV_NEEDED(ct) \ 580 ((ct)->ct_flags &= ~MDI_CLIENT_FLAGS_REPORT_DEV) 581 582 #define MDI_CLIENT_IS_REPORT_DEV_NEEDED(ct) \ 583 ((ct)->ct_flags & MDI_CLIENT_FLAGS_REPORT_DEV) 584 585 #define MDI_CLIENT_SET_PATH_FREE_IN_PROGRESS(ct) \ 586 ((ct)->ct_flags |= MDI_CLIENT_FLAGS_PATH_FREE_IN_PROGRESS) 587 588 #define MDI_CLIENT_CLEAR_PATH_FREE_IN_PROGRESS(ct) \ 589 ((ct)->ct_flags &= ~MDI_CLIENT_FLAGS_PATH_FREE_IN_PROGRESS) 590 591 #define MDI_CLIENT_IS_PATH_FREE_IN_PROGRESS(ct) \ 592 ((ct)->ct_flags & MDI_CLIENT_FLAGS_PATH_FREE_IN_PROGRESS) 593 594 #define MDI_CLIENT_SET_DEV_NOT_SUPPORTED(ct) \ 595 ((ct)->ct_flags |= MDI_CLIENT_FLAGS_DEV_NOT_SUPPORTED) 596 597 #define MDI_CLIENT_IS_DEV_NOT_SUPPORTED(ct) \ 598 ((ct)->ct_flags & MDI_CLIENT_FLAGS_DEV_NOT_SUPPORTED) 599 600 /* 601 * Client operating states. 602 */ 603 #define MDI_CLIENT_STATE_OPTIMAL 1 604 #define MDI_CLIENT_STATE_DEGRADED 2 605 #define MDI_CLIENT_STATE_FAILED 3 606 607 #define MDI_CLIENT_STATE(ct) ((ct)->ct_state) 608 #define MDI_CLIENT_SET_STATE(ct, state) ((ct)->ct_state = state) 609 610 #define MDI_CLIENT_IS_FAILED(ct) \ 611 ((ct)->ct_state == MDI_CLIENT_STATE_FAILED) 612 613 /* 614 * mdi_pathinfo nodes: 615 * 616 * From this framework's perspective, a 'path' is a tuple consisting of a 617 * client or end device, a host controller which provides device 618 * identification and transport services (pHCI), and bus specific unit 619 * addressing information. A path may be decorated with properties which 620 * describe the capabilities of the path; such properties are analogous to 621 * device node and minor node properties. 622 * 623 * The framework maintains link list of mdi_pathinfo nodes created by every 624 * pHCI driver instance via the pi_phci_link linkage; this is used (for example) 625 * to make sure that all relevant pathinfo nodes are freed before the pHCI 626 * is unregistered. 627 * 628 * Locking order: 629 * 630 * _NOTE(LOCK_ORDER(mdi_phci::ph_mutex mdi_pathinfo::pi_mutex)) 631 * _NOTE(LOCK_ORDER(mdi_client::ct_mutex mdi_pathinfo::pi_mutex)) 632 * _NOTE(LOCK_ORDER(mdi_phci::ph_mutex mdi_client::ct_mutex)) 633 * _NOTE(LOCK_ORDER(devinfo_tree_lock mdi_pathinfo::pi_mutex)) 634 * 635 * mdi_pathinfo node structure definition 636 */ 637 struct mdi_pathinfo { 638 kmutex_t pi_mutex; /* per path mutex */ 639 mdi_pathinfo_state_t pi_state; /* path state */ 640 mdi_pathinfo_state_t pi_old_state; /* path state */ 641 kcondvar_t pi_state_cv; /* path state condvar */ 642 mdi_client_t *pi_client; /* client */ 643 mdi_phci_t *pi_phci; /* pHCI dev_info node */ 644 char *pi_addr; /* path unit address */ 645 nvlist_t *pi_prop; /* Properties */ 646 void *pi_cprivate; /* client private info */ 647 void *pi_pprivate; /* phci private info */ 648 struct mdi_pathinfo *pi_client_link; /* next path in client list */ 649 struct mdi_pathinfo *pi_phci_link; /* next path in phci list */ 650 int pi_ref_cnt; /* pi reference count */ 651 kcondvar_t pi_ref_cv; /* condition variable */ 652 struct mdi_pi_kstats *pi_kstats; /* aggregate kstats */ 653 int pi_pm_held; /* phci's kidsup incremented */ 654 int pi_preferred; /* Preferred path */ 655 void *pi_vprivate; /* vhci private info */ 656 }; 657 658 /* 659 * pathinfo statistics: 660 * 661 * The mpxio architecture allows for multiple pathinfo nodes for each 662 * client-pHCI combination. For statistics purposes, these statistics are 663 * aggregated into a single client-pHCI set of kstats. 664 */ 665 struct mdi_pi_kstats { 666 int pi_kstat_ref; /* # paths aggregated, also a ref cnt */ 667 kstat_t *pi_kstat_iostats; /* mdi:iopath statistic set */ 668 kstat_t *pi_kstat_errstats; /* error statistics */ 669 }; 670 671 /* 672 * pathinfo error kstat 673 */ 674 struct pi_errs { 675 struct kstat_named pi_softerrs; /* "Soft" Error */ 676 struct kstat_named pi_harderrs; /* "Hard" Error */ 677 struct kstat_named pi_transerrs; /* Transport Errors */ 678 struct kstat_named pi_icnt_busy; /* Interconnect Busy */ 679 struct kstat_named pi_icnt_errors; /* Interconnect Errors */ 680 struct kstat_named pi_phci_rsrc; /* pHCI No Resources */ 681 struct kstat_named pi_phci_localerr; /* pHCI Local Errors */ 682 struct kstat_named pi_phci_invstate; /* pHCI Invalid State */ 683 struct kstat_named pi_failedfrom; /* Failover: Failed From */ 684 struct kstat_named pi_failedto; /* Failover: Failed To */ 685 }; 686 687 /* 688 * increment an error counter 689 */ 690 #define MDI_PI_ERRSTAT(pip, x) { \ 691 if (MDI_PI((pip))->pi_kstats != NULL) { \ 692 struct pi_errs *pep; \ 693 pep = MDI_PI(pip)->pi_kstats->pi_kstat_errstats->ks_data; \ 694 pep->x.value.ui32++; \ 695 } \ 696 } 697 698 /* 699 * error codes which can be passed to MDI_PI_ERRSTAT 700 */ 701 #define MDI_PI_SOFTERR pi_softerrs 702 #define MDI_PI_HARDERR pi_harderrs 703 #define MDI_PI_TRANSERR pi_transerrs 704 #define MDI_PI_ICNTBUSY pi_icnt_busy 705 #define MDI_PI_ICNTERR pi_icnt_errors 706 #define MDI_PI_PHCIRSRC pi_phci_rsrc 707 #define MDI_PI_PHCILOCL pi_phci_localerr 708 #define MDI_PI_PHCIINVS pi_phci_invstate 709 #define MDI_PI_FAILFROM pi_failedfrom 710 #define MDI_PI_FAILTO pi_failedto 711 712 #define MDI_PI(type) ((struct mdi_pathinfo *)(type)) 713 714 #define MDI_PI_LOCK(pip) mutex_enter(&MDI_PI((pip))->pi_mutex) 715 #define MDI_PI_UNLOCK(pip) mutex_exit(&MDI_PI((pip))->pi_mutex) 716 #define MDI_PI_HOLD(pip) (++MDI_PI((pip))->pi_ref_cnt) 717 #define MDI_PI_RELE(pip) (--MDI_PI((pip))->pi_ref_cnt) 718 719 #define MDI_EXT_STATE_CHANGE 0x10000000 720 721 722 #define MDI_DISABLE_OP 0x1 723 #define MDI_ENABLE_OP 0x2 724 #define MDI_BEFORE_STATE_CHANGE 0x4 725 #define MDI_AFTER_STATE_CHANGE 0x8 726 #define MDI_SYNC_FLAG 0x10 727 728 #define MDI_PI_STATE(pip) \ 729 (MDI_PI((pip))->pi_state & MDI_PATHINFO_STATE_MASK) 730 731 #define MDI_PI_OLD_STATE(pip) \ 732 (MDI_PI((pip))->pi_old_state & MDI_PATHINFO_STATE_MASK) 733 734 #define MDI_PI_EXT_STATE(pip) \ 735 (MDI_PI((pip))->pi_state & MDI_PATHINFO_EXT_STATE_MASK) 736 737 #define MDI_PI_OLD_EXT_STATE(pip) \ 738 (MDI_PI((pip))->pi_old_state & MDI_PATHINFO_EXT_STATE_MASK) 739 740 #define MDI_PI_SET_TRANSIENT(pip) \ 741 (MDI_PI(pip)->pi_state |= MDI_PATHINFO_STATE_TRANSIENT) 742 743 #define MDI_PI_CLEAR_TRANSIENT(pip) \ 744 (MDI_PI(pip)->pi_state &= ~MDI_PATHINFO_STATE_TRANSIENT) 745 746 #define MDI_PI_IS_TRANSIENT(pip) \ 747 (MDI_PI(pip)->pi_state & MDI_PATHINFO_STATE_TRANSIENT) 748 749 #define MDI_PI_SET_USER_DISABLE(pip) \ 750 (MDI_PI(pip)->pi_state |= MDI_PATHINFO_STATE_USER_DISABLE) 751 752 #define MDI_PI_SET_DRV_DISABLE(pip) \ 753 (MDI_PI(pip)->pi_state |= MDI_PATHINFO_STATE_DRV_DISABLE) 754 755 #define MDI_PI_SET_DRV_DISABLE_TRANS(pip) \ 756 (MDI_PI(pip)->pi_state |= MDI_PATHINFO_STATE_DRV_DISABLE_TRANSIENT) 757 758 #define MDI_PI_SET_USER_ENABLE(pip) \ 759 (MDI_PI(pip)->pi_state &= ~MDI_PATHINFO_STATE_USER_DISABLE) 760 761 #define MDI_PI_SET_DRV_ENABLE(pip) \ 762 (MDI_PI(pip)->pi_state &= ~MDI_PATHINFO_STATE_DRV_DISABLE) 763 764 #define MDI_PI_SET_DRV_ENABLE_TRANS(pip) \ 765 (MDI_PI(pip)->pi_state &= ~MDI_PATHINFO_STATE_DRV_DISABLE_TRANSIENT) 766 767 #define MDI_PI_IS_USER_DISABLE(pip) \ 768 (MDI_PI(pip)->pi_state & MDI_PATHINFO_STATE_USER_DISABLE) 769 770 #define MDI_PI_IS_DRV_DISABLE(pip) \ 771 (MDI_PI(pip)->pi_state & MDI_PATHINFO_STATE_DRV_DISABLE) 772 773 #define MDI_PI_IS_DRV_DISABLE_TRANSIENT(pip) \ 774 (MDI_PI(pip)->pi_state & MDI_PATHINFO_STATE_DRV_DISABLE_TRANSIENT) 775 776 #define MDI_PI_IS_DISABLE(pip) \ 777 (MDI_PI_IS_USER_DISABLE(pip) || \ 778 MDI_PI_IS_DRV_DISABLE(pip) || \ 779 MDI_PI_IS_DRV_DISABLE_TRANSIENT(pip)) 780 781 #define MDI_PI_IS_INIT(pip) \ 782 ((MDI_PI(pip)->pi_state & MDI_PATHINFO_STATE_MASK) == \ 783 MDI_PATHINFO_STATE_INIT) 784 785 #define MDI_PI_IS_INITING(pip) \ 786 ((MDI_PI(pip)->pi_state & ~MDI_PATHINFO_EXT_STATE_MASK) == \ 787 (MDI_PATHINFO_STATE_INIT | MDI_PATHINFO_STATE_TRANSIENT)) 788 789 #define MDI_PI_SET_INIT(pip) \ 790 (MDI_PI(pip)->pi_state = MDI_PATHINFO_STATE_INIT) 791 792 #define MDI_PI_SET_ONLINING(pip) { \ 793 uint32_t ext_state; \ 794 ext_state = MDI_PI(pip)->pi_state & MDI_PATHINFO_EXT_STATE_MASK; \ 795 MDI_PI(pip)->pi_old_state = MDI_PI_STATE(pip); \ 796 MDI_PI(pip)->pi_state = \ 797 (MDI_PATHINFO_STATE_ONLINE | MDI_PATHINFO_STATE_TRANSIENT); \ 798 MDI_PI(pip)->pi_state |= ext_state; \ 799 } 800 801 #define MDI_PI_IS_ONLINING(pip) \ 802 ((MDI_PI(pip)->pi_state & ~MDI_PATHINFO_EXT_STATE_MASK) == \ 803 (MDI_PATHINFO_STATE_ONLINE | MDI_PATHINFO_STATE_TRANSIENT)) 804 805 #define MDI_PI_SET_ONLINE(pip) { \ 806 uint32_t ext_state; \ 807 ext_state = MDI_PI(pip)->pi_state & MDI_PATHINFO_EXT_STATE_MASK; \ 808 MDI_PI(pip)->pi_state = MDI_PATHINFO_STATE_ONLINE; \ 809 MDI_PI(pip)->pi_state |= ext_state; \ 810 } 811 812 813 #define MDI_PI_IS_ONLINE(pip) \ 814 ((MDI_PI(pip)->pi_state & MDI_PATHINFO_STATE_MASK) == \ 815 MDI_PATHINFO_STATE_ONLINE) 816 817 #define MDI_PI_SET_OFFLINING(pip) { \ 818 uint32_t ext_state; \ 819 ext_state = MDI_PI(pip)->pi_state & MDI_PATHINFO_EXT_STATE_MASK; \ 820 MDI_PI(pip)->pi_old_state = MDI_PI_STATE(pip); \ 821 MDI_PI(pip)->pi_state = \ 822 (MDI_PATHINFO_STATE_OFFLINE | MDI_PATHINFO_STATE_TRANSIENT); \ 823 MDI_PI(pip)->pi_state |= ext_state; \ 824 } 825 826 #define MDI_PI_IS_OFFLINING(pip) \ 827 ((MDI_PI(pip)->pi_state & ~MDI_PATHINFO_EXT_STATE_MASK) == \ 828 (MDI_PATHINFO_STATE_OFFLINE | MDI_PATHINFO_STATE_TRANSIENT)) 829 830 #define MDI_PI_SET_OFFLINE(pip) { \ 831 uint32_t ext_state; \ 832 ext_state = MDI_PI(pip)->pi_state & MDI_PATHINFO_EXT_STATE_MASK; \ 833 MDI_PI(pip)->pi_state = MDI_PATHINFO_STATE_OFFLINE; \ 834 MDI_PI(pip)->pi_state |= ext_state; \ 835 } 836 837 #define MDI_PI_IS_OFFLINE(pip) \ 838 ((MDI_PI(pip)->pi_state & MDI_PATHINFO_STATE_MASK) == \ 839 MDI_PATHINFO_STATE_OFFLINE) 840 841 #define MDI_PI_SET_STANDBYING(pip) { \ 842 uint32_t ext_state; \ 843 ext_state = MDI_PI(pip)->pi_state & MDI_PATHINFO_EXT_STATE_MASK; \ 844 MDI_PI(pip)->pi_old_state = MDI_PI_STATE(pip); \ 845 MDI_PI(pip)->pi_state = \ 846 (MDI_PATHINFO_STATE_STANDBY | MDI_PATHINFO_STATE_TRANSIENT); \ 847 MDI_PI(pip)->pi_state |= ext_state; \ 848 } 849 850 #define MDI_PI_SET_STANDBY(pip) { \ 851 uint32_t ext_state; \ 852 ext_state = MDI_PI(pip)->pi_state & MDI_PATHINFO_EXT_STATE_MASK; \ 853 MDI_PI(pip)->pi_state = MDI_PATHINFO_STATE_STANDBY; \ 854 MDI_PI(pip)->pi_state |= ext_state; \ 855 } 856 857 #define MDI_PI_IS_STANDBY(pip) \ 858 ((MDI_PI(pip)->pi_state & MDI_PATHINFO_STATE_MASK) == \ 859 MDI_PATHINFO_STATE_STANDBY) 860 861 #define MDI_PI_SET_FAULTING(pip) { \ 862 uint32_t ext_state; \ 863 ext_state = MDI_PI(pip)->pi_state & MDI_PATHINFO_EXT_STATE_MASK; \ 864 MDI_PI(pip)->pi_old_state = MDI_PI_STATE(pip); \ 865 MDI_PI(pip)->pi_state = \ 866 (MDI_PATHINFO_STATE_FAULT | MDI_PATHINFO_STATE_TRANSIENT); \ 867 MDI_PI(pip)->pi_state |= ext_state; \ 868 } 869 870 #define MDI_PI_SET_FAULT(pip) { \ 871 uint32_t ext_state; \ 872 ext_state = MDI_PI(pip)->pi_state & MDI_PATHINFO_EXT_STATE_MASK; \ 873 MDI_PI(pip)->pi_state = MDI_PATHINFO_STATE_FAULT; \ 874 MDI_PI(pip)->pi_state |= ext_state; \ 875 } 876 877 #define MDI_PI_IS_FAULT(pip) \ 878 ((MDI_PI(pip)->pi_state & MDI_PATHINFO_STATE_MASK) == \ 879 MDI_PATHINFO_STATE_FAULT) 880 881 #define MDI_PI_IS_SUSPENDED(pip) \ 882 ((MDI_PI(pip))->pi_phci->ph_flags & MDI_PHCI_FLAGS_SUSPEND) 883 884 /* 885 * mdi_vhcache_client, mdi_vhcache_pathinfo, and mdi_vhcache_phci structures 886 * hold the vhci to phci client mappings of the on-disk vhci busconfig cache. 887 */ 888 889 /* phci structure of vhci cache */ 890 typedef struct mdi_vhcache_phci { 891 char *cphci_path; /* phci path name */ 892 uint32_t cphci_id; /* used when building nvlist */ 893 mdi_phci_t *cphci_phci; /* pointer to actual phci */ 894 struct mdi_vhcache_phci *cphci_next; /* next in vhci phci list */ 895 } mdi_vhcache_phci_t; 896 897 /* pathinfo structure of vhci cache */ 898 typedef struct mdi_vhcache_pathinfo { 899 char *cpi_addr; /* path address */ 900 mdi_vhcache_phci_t *cpi_cphci; /* phci the path belongs to */ 901 struct mdi_pathinfo *cpi_pip; /* ptr to actual pathinfo */ 902 uint32_t cpi_flags; /* see below */ 903 struct mdi_vhcache_pathinfo *cpi_next; /* next path for the client */ 904 } mdi_vhcache_pathinfo_t; 905 906 /* 907 * cpi_flags 908 * 909 * MDI_CPI_HINT_PATH_DOES_NOT_EXIST - set when configuration of the path has 910 * failed. 911 */ 912 #define MDI_CPI_HINT_PATH_DOES_NOT_EXIST 0x0001 913 914 /* client structure of vhci cache */ 915 typedef struct mdi_vhcache_client { 916 char *cct_name_addr; /* client address */ 917 mdi_vhcache_pathinfo_t *cct_cpi_head; /* client's path list head */ 918 mdi_vhcache_pathinfo_t *cct_cpi_tail; /* client's path list tail */ 919 struct mdi_vhcache_client *cct_next; /* next in vhci client list */ 920 } mdi_vhcache_client_t; 921 922 /* vhci cache structure - one for vhci instance */ 923 typedef struct mdi_vhci_cache { 924 mdi_vhcache_phci_t *vhcache_phci_head; /* phci list head */ 925 mdi_vhcache_phci_t *vhcache_phci_tail; /* phci list tail */ 926 mdi_vhcache_client_t *vhcache_client_head; /* client list head */ 927 mdi_vhcache_client_t *vhcache_client_tail; /* client list tail */ 928 mod_hash_t *vhcache_client_hash; /* client hash */ 929 int vhcache_flags; /* see below */ 930 int64_t vhcache_clean_time; /* last clean time */ 931 krwlock_t vhcache_lock; /* cache lock */ 932 } mdi_vhci_cache_t; 933 934 /* vhcache_flags */ 935 #define MDI_VHCI_CACHE_SETUP_DONE 0x0001 /* cache setup completed */ 936 937 /* vhci bus config structure - one for vhci instance */ 938 typedef struct mdi_vhci_config { 939 char *vhc_vhcache_filename; /* on-disk file name */ 940 mdi_vhci_cache_t vhc_vhcache; /* vhci cache */ 941 kmutex_t vhc_lock; /* vhci config lock */ 942 kcondvar_t vhc_cv; 943 int vhc_flags; /* see below */ 944 945 /* flush vhci cache when lbolt reaches vhc_flush_at_ticks */ 946 clock_t vhc_flush_at_ticks; 947 948 /* 949 * Head and tail of the client list whose paths are being configured 950 * asynchronously. vhc_acc_count is the number of clients on this list. 951 * vhc_acc_thrcount is the number threads running to configure 952 * the paths for these clients. 953 */ 954 struct mdi_async_client_config *vhc_acc_list_head; 955 struct mdi_async_client_config *vhc_acc_list_tail; 956 int vhc_acc_count; 957 int vhc_acc_thrcount; 958 959 /* callback id - for flushing the cache during system shutdown */ 960 callb_id_t vhc_cbid; 961 962 /* 963 * vhc_path_discovery_boot - number of times path discovery will be 964 * attempted during early boot. 965 * vhc_path_discovery_postboot number of times path discovery will be 966 * attempted during late boot. 967 * vhc_path_discovery_cutoff_time - time at which paths were last 968 * discovered + some timeout 969 */ 970 int vhc_path_discovery_boot; 971 int vhc_path_discovery_postboot; 972 int64_t vhc_path_discovery_cutoff_time; 973 } mdi_vhci_config_t; 974 975 /* vhc_flags */ 976 #define MDI_VHC_SINGLE_THREADED 0x0001 /* config single threaded */ 977 #define MDI_VHC_EXIT 0x0002 /* exit all config activity */ 978 #define MDI_VHC_VHCACHE_DIRTY 0x0004 /* cache dirty */ 979 #define MDI_VHC_VHCACHE_FLUSH_THREAD 0x0008 /* cache flush thead running */ 980 #define MDI_VHC_VHCACHE_FLUSH_ERROR 0x0010 /* failed to flush cache */ 981 #define MDI_VHC_READONLY_FS 0x0020 /* filesys is readonly */ 982 983 typedef struct mdi_phys_path { 984 char *phys_path; 985 struct mdi_phys_path *phys_path_next; 986 } mdi_phys_path_t; 987 988 /* 989 * Lookup tokens are used to cache the result of the vhci cache client lookup 990 * operations (to reduce the number of real lookup operations). 991 */ 992 typedef struct mdi_vhcache_lookup_token { 993 mdi_vhcache_client_t *lt_cct; /* vhcache client */ 994 int64_t lt_cct_lookup_time; /* last lookup time */ 995 } mdi_vhcache_lookup_token_t; 996 997 /* asynchronous configuration of client paths */ 998 typedef struct mdi_async_client_config { 999 char *acc_ct_name; /* client name */ 1000 char *acc_ct_addr; /* client address */ 1001 mdi_phys_path_t *acc_phclient_path_list_head; /* path head */ 1002 mdi_vhcache_lookup_token_t acc_token; /* lookup token */ 1003 struct mdi_async_client_config *acc_next; /* next in vhci acc list */ 1004 } mdi_async_client_config_t; 1005 1006 /* 1007 * vHCI driver instance registration/unregistration 1008 * 1009 * mdi_vhci_register() is called by a vHCI driver to register itself as the 1010 * manager of devices from a particular 'class'. This should be called from 1011 * attach(9e). 1012 * 1013 * mdi_vhci_unregister() is called from detach(9E) to unregister a vHCI 1014 * instance from the framework. 1015 */ 1016 int mdi_vhci_register(char *, dev_info_t *, mdi_vhci_ops_t *, int); 1017 int mdi_vhci_unregister(dev_info_t *, int); 1018 1019 /* 1020 * Utility functions 1021 */ 1022 int mdi_phci_get_path_count(dev_info_t *); 1023 dev_info_t *mdi_phci_path2devinfo(dev_info_t *, caddr_t); 1024 1025 1026 /* 1027 * Path Selection Functions: 1028 * 1029 * mdi_select_path() is called by a vHCI driver to select to which path an 1030 * I/O request should be routed. The caller passes the 'buf' structure as 1031 * one of the parameters. The mpxio framework uses the buf's contents to 1032 * maintain per path statistics (total I/O size / count pending). If more 1033 * than one online path is available, the framework automatically selects 1034 * a suitable one. If a failover operation is active for this client device 1035 * the call fails, returning MDI_BUSY. 1036 * 1037 * By default this function returns a suitable path in the 'online' state, 1038 * based on the current load balancing policy. Currently we support 1039 * LOAD_BALANCE_NONE (Previously selected online path will continue to be 1040 * used as long as the path is usable) and LOAD_BALANCE_RR (Online paths 1041 * will be selected in a round robin fashion). The load balancing scheme 1042 * can be configured in the vHCI driver's configuration file (driver.conf). 1043 * 1044 * vHCI drivers may override this default behaviour by specifying appropriate 1045 * flags. If start_pip is specified (non NULL), it is used as the routine's 1046 * starting point; it starts walking from there to find the next appropriate 1047 * path. 1048 * 1049 * The following values for 'flags' are currently defined: 1050 * 1051 * MDI_SELECT_ONLINE_PATH: select an ONLINE path 1052 * MDI_SELECT_STANDBY_PATH: select a STANDBY path 1053 * MDI_SELECT_USER_DISABLE_PATH: select user disable for failover and 1054 * auto_failback 1055 * 1056 * The selected paths are returned in a held state (ref_cnt) and caller should 1057 * release the hold by calling mdi_rele_path() at the end of operation. 1058 */ 1059 int mdi_select_path(dev_info_t *, struct buf *, int, 1060 mdi_pathinfo_t *, mdi_pathinfo_t **); 1061 void mdi_hold_path(mdi_pathinfo_t *); 1062 void mdi_rele_path(mdi_pathinfo_t *); 1063 int mdi_set_lb_policy(dev_info_t *, client_lb_t); 1064 int mdi_set_lb_region_size(dev_info_t *, int); 1065 client_lb_t mdi_get_lb_policy(dev_info_t *); 1066 1067 /* 1068 * flags for mdi_select_path() routine 1069 */ 1070 #define MDI_SELECT_ONLINE_PATH 0x0001 1071 #define MDI_SELECT_STANDBY_PATH 0x0002 1072 #define MDI_SELECT_USER_DISABLE_PATH 0x0004 1073 1074 /* 1075 * MDI client device utility functions 1076 */ 1077 int mdi_client_get_path_count(dev_info_t *); 1078 dev_info_t *mdi_client_path2devinfo(dev_info_t *, caddr_t); 1079 1080 /* 1081 * Failover: 1082 * 1083 * The vHCI driver calls mdi_failover() to initiate a failover operation. 1084 * mdi_failover() calls back into the vHCI driver's vo_failover() 1085 * entry point to perform the actual failover operation. The reason 1086 * for requiring the vHCI driver to initiate failover by calling 1087 * mdi_failover(), instead of directly executing vo_failover() itself, 1088 * is to ensure that the mdi framework can keep track of the client 1089 * state properly. Additionally, mdi_failover() provides as a 1090 * convenience the option of performing the failover operation 1091 * synchronously or asynchronously 1092 * 1093 * Upon successful completion of the failover operation, the paths that were 1094 * previously ONLINE will be in the STANDBY state, and the newly activated 1095 * paths will be in the ONLINE state. 1096 * 1097 * The flags modifier determines whether the activation is done synchronously 1098 */ 1099 int mdi_failover(dev_info_t *, dev_info_t *, int); 1100 1101 /* 1102 * Client device failover mode of operation 1103 */ 1104 #define MDI_FAILOVER_SYNC 1 /* Syncronous Failover */ 1105 #define MDI_FAILOVER_ASYNC 2 /* Asyncronous Failover */ 1106 1107 /* 1108 * mdi_pathinfo node state change functions. 1109 */ 1110 void mdi_pi_kstat_iosupdate(mdi_pathinfo_t *, struct buf *); 1111 1112 /* 1113 * mdi_pathinfo node extended state change functions. 1114 */ 1115 int mdi_pi_get_state2(mdi_pathinfo_t *, mdi_pathinfo_state_t *, uint32_t *); 1116 int mdi_pi_get_preferred(mdi_pathinfo_t *); 1117 1118 /* 1119 * mdi_pathinfo node member functions 1120 */ 1121 void *mdi_pi_get_client_private(mdi_pathinfo_t *); 1122 void mdi_pi_set_client_private(mdi_pathinfo_t *, void *); 1123 void mdi_pi_set_state(mdi_pathinfo_t *, mdi_pathinfo_state_t); 1124 void mdi_pi_set_preferred(mdi_pathinfo_t *, int); 1125 1126 /* get/set vhci private data */ 1127 void *mdi_client_get_vhci_private(dev_info_t *); 1128 void mdi_client_set_vhci_private(dev_info_t *, void *); 1129 void *mdi_phci_get_vhci_private(dev_info_t *); 1130 void mdi_phci_set_vhci_private(dev_info_t *, void *); 1131 void *mdi_pi_get_vhci_private(mdi_pathinfo_t *); 1132 void mdi_pi_set_vhci_private(mdi_pathinfo_t *, void *); 1133 1134 /* 1135 * mdi_pathinfo Property utilities 1136 */ 1137 int mdi_prop_size(mdi_pathinfo_t *, size_t *); 1138 int mdi_prop_pack(mdi_pathinfo_t *, char **, uint_t); 1139 1140 /* obsolete interface, to be removed */ 1141 void mdi_get_next_path(dev_info_t *, mdi_pathinfo_t *, mdi_pathinfo_t **); 1142 int mdi_get_component_type(dev_info_t *); 1143 1144 #endif /* _KERNEL */ 1145 1146 #ifdef __cplusplus 1147 } 1148 #endif 1149 1150 #endif /* _SYS_MDI_IMPLDEFS_H */ 1151