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