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 2008 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 * SCSI transport structures 43 * 44 * As each Host Adapter makes itself known to the system, 45 * it will create and register with the library the structure 46 * described below. This is so that the library knows how to route 47 * packets, resource control requests, and capability requests 48 * for any particular host adapter. The 'a_hba_tran' field of a 49 * scsi_address structure made known to a Target driver will 50 * point to one of these transport structures. 51 */ 52 53 typedef struct scsi_hba_tran scsi_hba_tran_t; 54 55 struct scsi_hba_tran { 56 /* 57 * Ptr to the device info structure for this particular HBA. 58 */ 59 dev_info_t *tran_hba_dip; 60 61 /* 62 * Private fields for use by the HBA itself. 63 */ 64 void *tran_hba_private; /* HBA softstate */ 65 66 /* 67 * The following two fields are only used in the SCSI_HBA_TRAN_CLONE 68 * case. 69 */ 70 void *tran_tgt_private; /* target-specific info */ 71 struct scsi_device *tran_sd; 72 73 /* 74 * Vectors to point to specific HBA entry points 75 */ 76 int (*tran_tgt_init)( 77 dev_info_t *hba_dip, 78 dev_info_t *tgt_dip, 79 scsi_hba_tran_t *hba_tran, 80 struct scsi_device *sd); 81 82 int (*tran_tgt_probe)( 83 struct scsi_device *sd, 84 int (*callback)( 85 void)); 86 void (*tran_tgt_free)( 87 dev_info_t *hba_dip, 88 dev_info_t *tgt_dip, 89 scsi_hba_tran_t *hba_tran, 90 struct scsi_device *sd); 91 92 int (*tran_start)( 93 struct scsi_address *ap, 94 struct scsi_pkt *pkt); 95 96 int (*tran_reset)( 97 struct scsi_address *ap, 98 int level); 99 100 int (*tran_abort)( 101 struct scsi_address *ap, 102 struct scsi_pkt *pkt); 103 104 int (*tran_getcap)( 105 struct scsi_address *ap, 106 char *cap, 107 int whom); 108 109 int (*tran_setcap)( 110 struct scsi_address *ap, 111 char *cap, 112 int value, 113 int whom); 114 115 struct scsi_pkt *(*tran_init_pkt)( 116 struct scsi_address *ap, 117 struct scsi_pkt *pkt, 118 struct buf *bp, 119 int cmdlen, 120 int statuslen, 121 int tgtlen, 122 int flags, 123 int (*callback)( 124 caddr_t arg), 125 caddr_t callback_arg); 126 127 void (*tran_destroy_pkt)( 128 struct scsi_address *ap, 129 struct scsi_pkt *pkt); 130 131 void (*tran_dmafree)( 132 struct scsi_address *ap, 133 struct scsi_pkt *pkt); 134 135 void (*tran_sync_pkt)( 136 struct scsi_address *ap, 137 struct scsi_pkt *pkt); 138 139 int (*tran_reset_notify)( 140 struct scsi_address *ap, 141 int flag, 142 void (*callback)(caddr_t), 143 caddr_t arg); 144 145 int (*tran_get_bus_addr)( 146 struct scsi_device *devp, 147 char *name, 148 int len); 149 150 int (*tran_get_name)( 151 struct scsi_device *devp, 152 char *name, 153 int len); 154 155 int (*tran_clear_aca)( 156 struct scsi_address *ap); 157 158 int (*tran_clear_task_set)( 159 struct scsi_address *ap); 160 161 int (*tran_terminate_task)( 162 struct scsi_address *ap, 163 struct scsi_pkt *pkt); 164 165 int (*tran_get_eventcookie)( 166 dev_info_t *hba_dip, 167 dev_info_t *tgt_dip, 168 char *name, 169 ddi_eventcookie_t *eventp); 170 171 int (*tran_add_eventcall)( 172 dev_info_t *hba_dip, 173 dev_info_t *tgt_dip, 174 ddi_eventcookie_t event, 175 void (*callback)( 176 dev_info_t *tgt_dip, 177 ddi_eventcookie_t event, 178 void *arg, 179 void *bus_impldata), 180 void *arg, 181 ddi_callback_id_t *cb_id); 182 183 int (*tran_remove_eventcall)(dev_info_t *devi, 184 ddi_callback_id_t cb_id); 185 186 int (*tran_post_event)( 187 dev_info_t *hba_dip, 188 dev_info_t *tgt_dip, 189 ddi_eventcookie_t event, 190 void *bus_impldata); 191 192 int (*tran_quiesce)( 193 dev_info_t *hba_dip); 194 195 int (*tran_unquiesce)( 196 dev_info_t *hba_dip); 197 198 int (*tran_bus_reset)( 199 dev_info_t *hba_dip, 200 int level); 201 202 /* 203 * Implementation-private specifics. 204 * No HBA should refer to any of the fields below. 205 * This information can and will change. 206 */ 207 int tran_hba_flags; /* flag options */ 208 209 uint_t tran_obs1; 210 uchar_t tran_obs2; 211 uchar_t tran_obs3; 212 213 /* 214 * open_lock: protect tran_minor_isopen 215 * open_flag: bit field indicating which minor nodes are open. 216 * 0 = closed, 1 = shared open, all bits 1 = excl open. 217 * 218 * XXX Unused if hba driver chooses to implement own 219 * xxopen(9e) entry point 220 */ 221 kmutex_t tran_open_lock; 222 uint64_t tran_open_flag; 223 224 /* 225 * bus_config vectors - ON Consolidation Private 226 * These interfaces are subject to change. 227 */ 228 int (*tran_bus_config)( 229 dev_info_t *hba_dip, 230 uint_t flag, 231 ddi_bus_config_op_t op, 232 void *arg, 233 dev_info_t **tgt_dipp); 234 235 int (*tran_bus_unconfig)( 236 dev_info_t *hba_dip, 237 uint_t flag, 238 ddi_bus_config_op_t op, 239 void *arg); 240 241 int (*tran_bus_power)( 242 dev_info_t *dip, 243 void *impl_arg, 244 pm_bus_power_op_t op, 245 void *arg, 246 void *result); 247 248 /* 249 * Inter-Connect type of trasnport as defined in 250 * usr/src/uts/common/sys/scsi/impl/services.h 251 */ 252 int tran_interconnect_type; 253 254 /* tran_setup_pkt(9E) related scsi_pkt fields */ 255 int (*tran_pkt_constructor)( 256 struct scsi_pkt *pkt, 257 scsi_hba_tran_t *tran, 258 int kmflag); 259 void (*tran_pkt_destructor)( 260 struct scsi_pkt *pkt, 261 scsi_hba_tran_t *tran); 262 kmem_cache_t *tran_pkt_cache_ptr; 263 uint_t tran_hba_len; 264 int (*tran_setup_pkt)( 265 struct scsi_pkt *pkt, 266 int (*callback)( 267 caddr_t arg), 268 caddr_t callback_arg); 269 void (*tran_teardown_pkt)( 270 struct scsi_pkt *pkt); 271 ddi_dma_attr_t tran_dma_attr; 272 273 void *tran_extension; 274 275 /* 276 * An fm_capable HBA driver can set tran_fm_capable prior to 277 * scsi_hba_attach_setup(). If not set, SCSA provides a default 278 * implementation. 279 */ 280 int tran_fm_capable; 281 282 #ifdef SCSI_SIZE_CLEAN_VERIFY 283 /* 284 * Must be last: Building a driver with-and-without 285 * -DSCSI_SIZE_CLEAN_VERIFY, and checking driver modules for 286 * differences with a tools like 'wsdiff' allows a developer to verify 287 * that their driver has no dependencies on scsi*(9S) size. 288 */ 289 int _pad[8]; 290 #endif /* SCSI_SIZE_CLEAN_VERIFY */ 291 }; 292 size_t scsi_hba_tran_size(); /* private */ 293 294 295 #ifdef __lock_lint 296 _NOTE(SCHEME_PROTECTS_DATA("stable data", 297 scsi_hba_tran::tran_sd 298 scsi_hba_tran::tran_hba_dip 299 scsi_hba_tran::tran_hba_flags 300 scsi_hba_tran::tran_open_flag 301 scsi_hba_tran::tran_pkt_cache_ptr)) 302 /* 303 * we only modify the dma atributes (like dma_attr_granular) upon 304 * attach and in response to a setcap. It is also up to the target 305 * driver to not have any outstanding I/Os when it is changing the 306 * capabilities of the transport. 307 */ 308 _NOTE(SCHEME_PROTECTS_DATA("serialized by target driver", \ 309 scsi_hba_tran::tran_dma_attr.dma_attr_granular)) 310 #endif 311 312 /* 313 * Prototypes for SCSI HBA interface functions 314 * 315 * All these functions are public interfaces, with the 316 * exception of: 317 * interface called by 318 * scsi_initialize_hba_interface() _init() of scsi module 319 * scsi_uninitialize_hba_interface() _fini() of scsi module 320 */ 321 322 void scsi_initialize_hba_interface(void); 323 324 #ifdef NO_SCSI_FINI_YET 325 void scsi_uninitialize_hba_interface(void); 326 #endif /* NO_SCSI_FINI_YET */ 327 328 int scsi_hba_init( 329 struct modlinkage *modlp); 330 331 void scsi_hba_fini( 332 struct modlinkage *modlp); 333 334 int scsi_hba_attach( 335 dev_info_t *hba_dip, 336 ddi_dma_lim_t *hba_lim, 337 scsi_hba_tran_t *hba_tran, 338 int flags, 339 void *hba_options); 340 341 int scsi_hba_attach_setup( 342 dev_info_t *hba_dip, 343 ddi_dma_attr_t *hba_dma_attr, 344 scsi_hba_tran_t *hba_tran, 345 int flags); 346 347 int scsi_hba_detach( 348 dev_info_t *hba_dip); 349 350 scsi_hba_tran_t *scsi_hba_tran_alloc( 351 dev_info_t *hba_dip, 352 int flags); 353 354 int scsi_tran_ext_alloc( 355 scsi_hba_tran_t *hba_tran, 356 size_t length, 357 int flags); 358 359 void scsi_tran_ext_free( 360 scsi_hba_tran_t *hba_tran, 361 size_t length); 362 363 void scsi_hba_tran_free( 364 scsi_hba_tran_t *hba_tran); 365 366 int scsi_hba_probe( 367 struct scsi_device *sd, 368 int (*callback)(void)); 369 370 char *scsi_get_device_type_string( 371 char *prop_name, 372 dev_info_t *hba_dip, 373 struct scsi_device *devp); 374 375 int scsi_get_scsi_maxluns( 376 struct scsi_device *sd); 377 378 int scsi_get_scsi_options( 379 struct scsi_device *sd, 380 int default_scsi_options); 381 382 int scsi_get_device_type_scsi_options( 383 dev_info_t *hba_dip, 384 struct scsi_device *devp, 385 int default_scsi_options); 386 387 struct scsi_pkt *scsi_hba_pkt_alloc( 388 dev_info_t *hba_dip, 389 struct scsi_address *ap, 390 int cmdlen, 391 int statuslen, 392 int tgtlen, 393 int hbalen, 394 int (*callback)(caddr_t), 395 caddr_t arg); 396 397 void scsi_hba_pkt_free( 398 struct scsi_address *ap, 399 struct scsi_pkt *pkt); 400 401 402 int scsi_hba_lookup_capstr( 403 char *capstr); 404 405 int scsi_hba_in_panic(void); 406 407 int scsi_hba_open( 408 dev_t *devp, 409 int flags, 410 int otyp, 411 cred_t *credp); 412 413 int scsi_hba_close( 414 dev_t dev, 415 int flag, 416 int otyp, 417 cred_t *credp); 418 419 int scsi_hba_ioctl( 420 dev_t dev, 421 int cmd, 422 intptr_t arg, 423 int mode, 424 cred_t *credp, 425 int *rvalp); 426 427 void scsi_hba_nodename_compatible_get( 428 struct scsi_inquiry *inq, 429 char *binding_set, 430 int dtype_node, 431 char *compat0, 432 char **nodenamep, 433 char ***compatiblep, 434 int *ncompatiblep); 435 436 void scsi_hba_nodename_compatible_free( 437 char *nodename, 438 char **compatible); 439 440 441 int scsi_hba_prop_update_inqstring( 442 struct scsi_device *devp, 443 char *name, 444 char *data, 445 size_t len); 446 447 /* 448 * Flags for scsi_hba_attach 449 * 450 * SCSI_HBA_TRAN_CLONE TRAN_CLONE is a KLUDGE to address current 451 * limitations of the scsi_address(9S) structure 452 * via duplication of scsi_hba_tran(9S) and 453 * introduction of tran_tgt_private. 454 */ 455 #define SCSI_HBA_TRAN_CLONE 0x01 /* clone scsi_hba_tran_t */ 456 /* structure per target */ 457 #define SCSI_HBA_TRAN_ALLOC 0x02 /* set if scsi_hba_tran_alloc */ 458 /* is called */ 459 #define SCSI_HBA_TRAN_CDB 0x04 /* allocate cdb */ 460 #define SCSI_HBA_TRAN_SCB 0x08 /* allocate sense */ 461 #define SCSI_HBA_TRAN_FMSCSA 0x10 /* using common ddi_fm_* */ 462 463 /* 464 * Flags for scsi_hba allocation functions 465 */ 466 #define SCSI_HBA_CANSLEEP 0x01 /* can sleep */ 467 468 /* 469 * For minor nodes created by the SCSA framework, minor numbers are 470 * formed by left-shifting instance by INST_MINOR_SHIFT and OR in a 471 * number less than 64. 472 * 473 * - Numbers 0 - 31 are reserved by the framework, part of the range are 474 * in use, as defined below. 475 * 476 * - Numbers 32 - 63 are available for HBA driver use. 477 */ 478 #define INST_MINOR_SHIFT 6 479 #define TRAN_MINOR_MASK ((1 << INST_MINOR_SHIFT) - 1) 480 #define TRAN_OPEN_EXCL (uint64_t)-1 481 482 #define DEVCTL_MINOR 0 483 #define SCSI_MINOR 1 484 485 #define INST2DEVCTL(x) (((x) << INST_MINOR_SHIFT) | DEVCTL_MINOR) 486 #define INST2SCSI(x) (((x) << INST_MINOR_SHIFT) | SCSI_MINOR) 487 #define MINOR2INST(x) ((x) >> INST_MINOR_SHIFT) 488 489 #endif /* _KERNEL */ 490 491 #ifdef __cplusplus 492 } 493 #endif 494 495 #endif /* _SYS_SCSI_IMPL_TRANSPORT_H */ 496