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 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_SCSI_IMPL_TRANSPORT_H 27 #define _SYS_SCSI_IMPL_TRANSPORT_H 28 29 /* 30 * Include the loadable module wrapper. 31 */ 32 #include <sys/modctl.h> 33 #include <sys/note.h> 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 #ifdef _KERNEL 40 41 /* 42 * Opaque handles to address maps 43 */ 44 typedef struct __scsi_iportmap scsi_hba_iportmap_t; 45 typedef struct __scsi_tgtmap scsi_hba_tgtmap_t; 46 47 /* 48 * SCSI transport structures 49 * 50 * As each Host Adapter makes itself known to the system, 51 * it will create and register with the library the structure 52 * described below. This is so that the library knows how to route 53 * packets, resource control requests, and capability requests 54 * for any particular host adapter. The 'a_hba_tran' field of a 55 * scsi_address structure made known to a Target driver will 56 * point to one of these transport structures. 57 */ 58 59 typedef struct scsi_hba_tran scsi_hba_tran_t; 60 61 struct scsi_hba_tran { 62 /* 63 * Ptr to the device info structure for this particular HBA. If a SCSA 64 * HBA driver separates initiator port function from HBA function, 65 * this field still refers to the HBA and is used to manage DMA. 66 */ 67 dev_info_t *tran_hba_dip; 68 69 /* 70 * Private fields for use by the HBA itself. 71 */ 72 void *tran_hba_private; /* HBA softstate */ 73 74 /* 75 * The following two fields are only used in the deprecated 76 * SCSI_HBA_TRAN_CLONE case. Use SCSI_HBA_ADDR_COMPLEX instead. 77 */ 78 void *tran_tgt_private; 79 struct scsi_device *tran_sd; 80 81 /* 82 * Vectors to point to specific HBA entry points 83 */ 84 int (*tran_tgt_init)( 85 dev_info_t *hba_dip, 86 dev_info_t *tgt_dip, 87 scsi_hba_tran_t *tran, 88 struct scsi_device *sd); 89 90 int (*tran_tgt_probe)( 91 struct scsi_device *sd, 92 int (*callback)( 93 void)); 94 void (*tran_tgt_free)( 95 dev_info_t *hba_dip, 96 dev_info_t *tgt_dip, 97 scsi_hba_tran_t *tran, 98 struct scsi_device *sd); 99 100 int (*tran_start)( 101 struct scsi_address *ap, 102 struct scsi_pkt *pkt); 103 104 int (*tran_reset)( 105 struct scsi_address *ap, 106 int level); 107 108 int (*tran_abort)( 109 struct scsi_address *ap, 110 struct scsi_pkt *pkt); 111 112 int (*tran_getcap)( 113 struct scsi_address *ap, 114 char *cap, 115 int whom); 116 117 int (*tran_setcap)( 118 struct scsi_address *ap, 119 char *cap, 120 int value, 121 int whom); 122 123 struct scsi_pkt *(*tran_init_pkt)( 124 struct scsi_address *ap, 125 struct scsi_pkt *pkt, 126 struct buf *bp, 127 int cmdlen, 128 int statuslen, 129 int tgtlen, 130 int flags, 131 int (*callback)( 132 caddr_t arg), 133 caddr_t callback_arg); 134 135 void (*tran_destroy_pkt)( 136 struct scsi_address *ap, 137 struct scsi_pkt *pkt); 138 139 void (*tran_dmafree)( 140 struct scsi_address *ap, 141 struct scsi_pkt *pkt); 142 143 void (*tran_sync_pkt)( 144 struct scsi_address *ap, 145 struct scsi_pkt *pkt); 146 147 int (*tran_reset_notify)( 148 struct scsi_address *ap, 149 int flag, 150 void (*callback)(caddr_t), 151 caddr_t arg); 152 153 int (*tran_get_bus_addr)( 154 struct scsi_device *sd, 155 char *name, 156 int len); 157 158 int (*tran_get_name)( 159 struct scsi_device *sd, 160 char *name, 161 int len); 162 163 int (*tran_clear_aca)( 164 struct scsi_address *ap); 165 166 int (*tran_clear_task_set)( 167 struct scsi_address *ap); 168 169 int (*tran_terminate_task)( 170 struct scsi_address *ap, 171 struct scsi_pkt *pkt); 172 173 int (*tran_get_eventcookie)( 174 dev_info_t *hba_dip, 175 dev_info_t *tgt_dip, 176 char *name, 177 ddi_eventcookie_t *eventp); 178 179 int (*tran_add_eventcall)( 180 dev_info_t *hba_dip, 181 dev_info_t *tgt_dip, 182 ddi_eventcookie_t event, 183 void (*callback)( 184 dev_info_t *tgt_dip, 185 ddi_eventcookie_t event, 186 void *arg, 187 void *bus_impldata), 188 void *arg, 189 ddi_callback_id_t *cb_id); 190 191 int (*tran_remove_eventcall)(dev_info_t *devi, 192 ddi_callback_id_t cb_id); 193 194 int (*tran_post_event)( 195 dev_info_t *hba_dip, 196 dev_info_t *tgt_dip, 197 ddi_eventcookie_t event, 198 void *bus_impldata); 199 200 int (*tran_quiesce)( 201 dev_info_t *hba_dip); 202 203 int (*tran_unquiesce)( 204 dev_info_t *hba_dip); 205 206 int (*tran_bus_reset)( 207 dev_info_t *hba_dip, 208 int level); 209 210 /* 211 * Implementation-private specifics. 212 * No HBA should refer to any of the fields below. 213 * This information can and will change. 214 */ 215 int tran_hba_flags; /* flag options */ 216 217 uint_t tran_obs1; 218 uchar_t tran_obs2; 219 uchar_t tran_obs3; 220 221 /* 222 * open_lock: protect tran_minor_isopen 223 * open_flag: bit field indicating which minor nodes are open. 224 * 0 = closed, 1 = shared open, all bits 1 = excl open. 225 * 226 * NOTE: Unused if HBA driver implements its own open(9e) entry point. 227 */ 228 kmutex_t tran_open_lock; 229 uint64_t tran_open_flag; 230 231 /* 232 * bus_config vectors - ON Consolidation Private 233 * These interfaces are subject to change. 234 */ 235 int (*tran_bus_config)( 236 dev_info_t *hba_dip, 237 uint_t flag, 238 ddi_bus_config_op_t op, 239 void *arg, 240 dev_info_t **tgt_dipp); 241 242 int (*tran_bus_unconfig)( 243 dev_info_t *hba_dip, 244 uint_t flag, 245 ddi_bus_config_op_t op, 246 void *arg); 247 248 int (*tran_bus_power)( 249 dev_info_t *dip, 250 void *impl_arg, 251 pm_bus_power_op_t op, 252 void *arg, 253 void *result); 254 255 /* 256 * Inter-Connect type of transport as defined in 257 * usr/src/uts/common/sys/scsi/impl/services.h 258 */ 259 int tran_interconnect_type; 260 261 /* tran_setup_pkt(9E) related scsi_pkt fields */ 262 int (*tran_pkt_constructor)( 263 struct scsi_pkt *pkt, 264 scsi_hba_tran_t *tran, 265 int kmflag); 266 void (*tran_pkt_destructor)( 267 struct scsi_pkt *pkt, 268 scsi_hba_tran_t *tran); 269 kmem_cache_t *tran_pkt_cache_ptr; 270 uint_t tran_hba_len; 271 int (*tran_setup_pkt)( 272 struct scsi_pkt *pkt, 273 int (*callback)( 274 caddr_t arg), 275 caddr_t callback_arg); 276 void (*tran_teardown_pkt)( 277 struct scsi_pkt *pkt); 278 ddi_dma_attr_t tran_dma_attr; 279 280 void *tran_extension; 281 282 /* 283 * An fm_capable HBA driver can set tran_fm_capable prior to 284 * scsi_hba_attach_setup(). If not set, SCSA provides a default 285 * implementation. 286 */ 287 int tran_fm_capable; 288 289 /* 290 * Ptr to the device info structure for initiator port. If a SCSA HBA 291 * driver separates initiator port function from HBA function, this 292 * field still refers to the initiator port. 293 */ 294 dev_info_t *tran_iport_dip; 295 296 /* 297 * map of initiator ports below HBA 298 */ 299 scsi_hba_iportmap_t *tran_iportmap; 300 301 /* 302 * map of targets below initiator 303 */ 304 scsi_hba_tgtmap_t *tran_tgtmap; 305 306 #ifdef SCSI_SIZE_CLEAN_VERIFY 307 /* 308 * Must be last: Building a driver with-and-without 309 * -DSCSI_SIZE_CLEAN_VERIFY, and checking driver modules for 310 * differences with a tools like 'wsdiff' allows a developer to verify 311 * that their driver has no dependencies on scsi*(9S) size. 312 */ 313 int _pad[8]; 314 #endif /* SCSI_SIZE_CLEAN_VERIFY */ 315 }; 316 size_t scsi_hba_tran_size(); /* private */ 317 318 #ifdef __lock_lint 319 _NOTE(SCHEME_PROTECTS_DATA("stable data", 320 scsi_hba_tran::tran_sd 321 scsi_hba_tran::tran_hba_dip 322 scsi_hba_tran::tran_hba_flags 323 scsi_hba_tran::tran_open_flag 324 scsi_hba_tran::tran_pkt_cache_ptr)) 325 /* 326 * we only modify the dma attributes (like dma_attr_granular) upon 327 * attach and in response to a setcap. It is also up to the target 328 * driver to not have any outstanding I/Os when it is changing the 329 * capabilities of the transport. 330 */ 331 _NOTE(SCHEME_PROTECTS_DATA("serialized by target driver", \ 332 scsi_hba_tran::tran_dma_attr.dma_attr_granular)) 333 #endif 334 335 /* 336 * Prototypes for SCSI HBA interface functions 337 * 338 * All these functions are public interfaces, with the 339 * exception of: 340 * interface called by 341 * scsi_initialize_hba_interface() _init() of scsi module 342 * scsi_uninitialize_hba_interface() _fini() of scsi module 343 */ 344 345 void scsi_initialize_hba_interface(void); 346 347 #ifdef NO_SCSI_FINI_YET 348 void scsi_uninitialize_hba_interface(void); 349 #endif /* NO_SCSI_FINI_YET */ 350 351 int scsi_hba_init( 352 struct modlinkage *modlp); 353 354 void scsi_hba_fini( 355 struct modlinkage *modlp); 356 357 int scsi_hba_attach( 358 dev_info_t *hba_dip, 359 ddi_dma_lim_t *hba_lim, 360 scsi_hba_tran_t *tran, 361 int flags, 362 void *hba_options); 363 364 int scsi_hba_attach_setup( 365 dev_info_t *hba_dip, 366 ddi_dma_attr_t *hba_dma_attr, 367 scsi_hba_tran_t *tran, 368 int flags); 369 370 int scsi_hba_detach( 371 dev_info_t *hba_dip); 372 373 scsi_hba_tran_t *scsi_hba_tran_alloc( 374 dev_info_t *hba_dip, 375 int flags); 376 377 int scsi_tran_ext_alloc( 378 scsi_hba_tran_t *tran, 379 size_t length, 380 int flags); 381 382 void scsi_tran_ext_free( 383 scsi_hba_tran_t *tran, 384 size_t length); 385 386 void scsi_hba_tran_free( 387 scsi_hba_tran_t *tran); 388 389 int scsi_hba_probe( 390 struct scsi_device *sd, 391 int (*callback)(void)); 392 393 int scsi_hba_probe_pi( 394 struct scsi_device *sd, 395 int (*callback)(void), 396 int pi); 397 398 int scsi_hba_ua_get_reportdev( 399 struct scsi_device *sd, 400 char *ba, 401 int len); 402 403 int scsi_hba_ua_get( 404 struct scsi_device *sd, 405 char *ua, 406 int len); 407 408 char *scsi_get_device_type_string( 409 char *prop_name, 410 dev_info_t *hba_dip, 411 struct scsi_device *sd); 412 413 int scsi_get_scsi_maxluns( 414 struct scsi_device *sd); 415 416 int scsi_get_scsi_options( 417 struct scsi_device *sd, 418 int default_scsi_options); 419 420 int scsi_get_device_type_scsi_options( 421 dev_info_t *hba_dip, 422 struct scsi_device *sd, 423 int default_scsi_options); 424 425 struct scsi_pkt *scsi_hba_pkt_alloc( 426 dev_info_t *hba_dip, 427 struct scsi_address *ap, 428 int cmdlen, 429 int statuslen, 430 int tgtlen, 431 int hbalen, 432 int (*callback)(caddr_t), 433 caddr_t arg); 434 435 void scsi_hba_pkt_free( 436 struct scsi_address *ap, 437 struct scsi_pkt *pkt); 438 439 440 int scsi_hba_lookup_capstr( 441 char *capstr); 442 443 int scsi_hba_in_panic(void); 444 445 int scsi_hba_open( 446 dev_t *devp, 447 int flags, 448 int otyp, 449 cred_t *credp); 450 451 int scsi_hba_close( 452 dev_t dev, 453 int flag, 454 int otyp, 455 cred_t *credp); 456 457 int scsi_hba_ioctl( 458 dev_t dev, 459 int cmd, 460 intptr_t arg, 461 int mode, 462 cred_t *credp, 463 int *rvalp); 464 465 void scsi_hba_nodename_compatible_get( 466 struct scsi_inquiry *inq, 467 char *binding_set, 468 int dtype_node, 469 char *compat0, 470 char **nodenamep, 471 char ***compatiblep, 472 int *ncompatiblep); 473 474 void scsi_hba_nodename_compatible_free( 475 char *nodename, 476 char **compatible); 477 478 int scsi_device_prop_update_inqstring( 479 struct scsi_device *sd, 480 char *name, 481 char *data, 482 size_t len); 483 484 void scsi_hba_pkt_comp( 485 struct scsi_pkt *pkt); 486 487 int scsi_device_identity( 488 struct scsi_device *sd, 489 int (*callback)(void)); 490 491 char *scsi_hba_iport_unit_address( 492 dev_info_t *dip); 493 494 int scsi_hba_iport_register( 495 dev_info_t *dip, 496 char *port); 497 498 int scsi_hba_iport_exist( 499 dev_info_t *dip); 500 501 dev_info_t *scsi_hba_iport_find( 502 dev_info_t *pdip, 503 char *portnm); 504 505 506 /* 507 * Flags for scsi_hba_attach 508 * 509 * SCSI_HBA_ADDR_SPI The host adapter driver wants the 510 * scsi_address(9S) structure to be maintained 511 * in legacy SPI 'a_target'/'a_lun' form (default). 512 * 513 * SCSI_HBA_ADDR_COMPLEX The host adapter has a complex unit-address 514 * space, and the HBA driver wants to maintain 515 * per-scsi_device(9S) HBA private data using 516 * scsi_address_device(9F) and 517 * scsi_device_hba_private_[gs]et(9F). The HBA 518 * driver must maintain a private representation 519 * of the scsi_device(9S) unit-address - typically 520 * established during tran_tgt_init(9F) based on 521 * property values. 522 * 523 * SCSI_HBA_TRAN_PHCI The host adapter is an mpxio/scsi_vhci pHCI. 524 * The framework should take care of 525 * mdi_phci_register() stuff. 526 * 527 * SCSI_HBA_HBA The host adapter node (associated with a PCI 528 * function) is just an HBA, all SCSI initiator 529 * port function is provided by separate 'iport' 530 * children of the host adapter node. These iport 531 * children bind to the same driver as the host 532 * adapter node. Both nodes are managed by the 533 * same driver. The driver can distinguish context 534 * by calling scsi_hba_iport_unit_address(). 535 * 536 * ::SCSI_HBA_TRAN_CLONE Deprecated: use SCSI_HBA_ADDR_COMPLEX instead. 537 * SCSI_HBA_TRAN_CLONE was a KLUDGE to address 538 * limitations of the scsi_address(9S) structure 539 * via duplication of scsi_hba_tran(9S) and 540 * use of tran_tgt_private. 541 * 542 */ 543 #define SCSI_HBA_TRAN_CLONE 0x01 /* Deprecated */ 544 #define SCSI_HBA_TRAN_PHCI 0x02 /* treat HBA as mpxio 'pHCI' */ 545 #define SCSI_HBA_TRAN_CDB 0x04 /* allocate cdb */ 546 #define SCSI_HBA_TRAN_SCB 0x08 /* allocate sense */ 547 #define SCSI_HBA_HBA 0x10 /* all HBA children are iports */ 548 549 #define SCSI_HBA_ADDR_SPI 0x20 /* scsi_address in SPI form */ 550 #define SCSI_HBA_ADDR_COMPLEX 0x40 /* scsi_address is COMPLEX */ 551 552 /* upper bits used to record SCSA configuration state */ 553 #define SCSI_HBA_SCSA_PHCI 0x10000 /* need mdi_phci_unregister */ 554 #define SCSI_HBA_SCSA_TA 0x20000 /* scsi_hba_tran_alloc used */ 555 #define SCSI_HBA_SCSA_FM 0x40000 /* using common ddi_fm_* */ 556 557 /* 558 * Flags for scsi_hba allocation functions 559 */ 560 #define SCSI_HBA_CANSLEEP 0x01 /* can sleep */ 561 562 /* 563 * Support extra flavors for SCSA children 564 */ 565 #define SCSA_FLAVOR_SCSI_DEVICE NDI_FLAVOR_VANILLA 566 #define SCSA_FLAVOR_SMP 1 567 #define SCSA_FLAVOR_IPORT 2 568 #define SCSA_NFLAVORS 3 569 570 /* 571 * Maximum number of iport nodes under PCI function 572 */ 573 #define SCSI_HBA_MAX_IPORTS 32 574 575 /* 576 * SCSI iport map interfaces 577 */ 578 int scsi_hba_iportmap_create( 579 dev_info_t *hba_dip, 580 clock_t stable_ms, 581 scsi_hba_iportmap_t **iportmapp); 582 583 int scsi_hba_iportmap_iport_add( 584 scsi_hba_iportmap_t *iportmap, 585 char *iport_addr, 586 void *iport_priv); 587 588 int scsi_hba_iportmap_iport_remove( 589 scsi_hba_iportmap_t *iportmap, 590 char *iport_addr); 591 592 void scsi_hba_iportmap_destroy(scsi_hba_iportmap_t *iportmap); 593 594 /* 595 * SCSI target map interfaces 596 */ 597 typedef enum { SCSI_TM_FULLSET = 0, SCSI_TM_PERADDR } scsi_tgtmap_mode_t; 598 typedef enum { 599 SCSI_TGT_SCSI_DEVICE = 0, SCSI_TGT_SMP_DEVICE, SCSI_TGT_NTYPES 600 } scsi_tgtmap_tgt_type_t; 601 602 typedef void (*scsi_tgt_activate_cb_t)( 603 void *tgtmap_priv, 604 char *tgt_addr, 605 scsi_tgtmap_tgt_type_t tgt_type, 606 void **tgt_privp); 607 typedef void (*scsi_tgt_deactivate_cb_t)( 608 void *tgtmap_priv, 609 char *tgt_addr, 610 scsi_tgtmap_tgt_type_t tgt_type, 611 void *tgt_priv); 612 int scsi_hba_tgtmap_create( 613 dev_info_t *iport_dip, 614 scsi_tgtmap_mode_t rpt_mode, 615 clock_t stable_ms, 616 void *tgtmap_priv, 617 scsi_tgt_activate_cb_t activate_cb, 618 scsi_tgt_deactivate_cb_t deactivate_cb, 619 scsi_hba_tgtmap_t **tgtmapp); 620 621 int scsi_hba_tgtmap_set_begin(scsi_hba_tgtmap_t *tgtmap); 622 623 int scsi_hba_tgtmap_set_add( 624 scsi_hba_tgtmap_t *tgtmap, 625 scsi_tgtmap_tgt_type_t tgt_type, 626 char *tgt_addr, 627 void *tgt_priv); 628 629 int scsi_hba_tgtmap_set_end( 630 scsi_hba_tgtmap_t *tgtmap, 631 uint_t flags); 632 633 int scsi_hba_tgtmap_tgt_add( 634 scsi_hba_tgtmap_t *tgtmap, 635 scsi_tgtmap_tgt_type_t tgt_type, 636 char *tgt_addr, 637 void *tgt_priv); 638 639 int scsi_hba_tgtmap_tgt_remove( 640 scsi_hba_tgtmap_t *tgtmap, 641 scsi_tgtmap_tgt_type_t tgt_type, 642 char *tgt_addr); 643 644 void scsi_hba_tgtmap_destroy(scsi_hba_tgtmap_t *tgt_map); 645 646 647 /* 648 * For minor nodes created by the SCSA framework, minor numbers are 649 * formed by left-shifting instance by INST_MINOR_SHIFT and OR in a 650 * number less than 64. 651 * 652 * - Numbers 0 - 31 are reserved by the framework, part of the range are 653 * in use, as defined below. 654 * 655 * - Numbers 32 - 63 are available for HBA driver use. 656 */ 657 #define INST_MINOR_SHIFT 6 658 #define TRAN_MINOR_MASK ((1 << INST_MINOR_SHIFT) - 1) 659 #define TRAN_OPEN_EXCL (uint64_t)-1 660 661 #define DEVCTL_MINOR 0 662 #define SCSI_MINOR 1 663 664 #define INST2DEVCTL(x) (((x) << INST_MINOR_SHIFT) | DEVCTL_MINOR) 665 #define INST2SCSI(x) (((x) << INST_MINOR_SHIFT) | SCSI_MINOR) 666 #define MINOR2INST(x) ((x) >> INST_MINOR_SHIFT) 667 668 #endif /* _KERNEL */ 669 670 #ifdef __cplusplus 671 } 672 #endif 673 674 #endif /* _SYS_SCSI_IMPL_TRANSPORT_H */ 675