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 #include <sys/note.h> 27 28 /* 29 * Generic SCSI Host Bus Adapter interface implementation 30 */ 31 #include <sys/scsi/scsi.h> 32 #include <sys/file.h> 33 #include <sys/ddi_impldefs.h> 34 #include <sys/ndi_impldefs.h> 35 #include <sys/ddi.h> 36 #include <sys/sunmdi.h> 37 #include <sys/epm.h> 38 39 extern struct scsi_pkt *scsi_init_cache_pkt(struct scsi_address *, 40 struct scsi_pkt *, struct buf *, int, int, int, int, 41 int (*)(caddr_t), caddr_t); 42 extern void scsi_free_cache_pkt(struct scsi_address *, struct scsi_pkt *); 43 extern void scsi_cache_dmafree(struct scsi_address *, struct scsi_pkt *); 44 extern void scsi_sync_cache_pkt(struct scsi_address *, struct scsi_pkt *); 45 46 /* 47 * Round up all allocations so that we can guarantee 48 * long-long alignment. This is the same alignment 49 * provided by kmem_alloc(). 50 */ 51 #define ROUNDUP(x) (((x) + 0x07) & ~0x07) 52 53 /* Magic number to track correct allocations in wrappers */ 54 #define PKT_WRAPPER_MAGIC 0xa110ced /* alloced correctly */ 55 56 kmutex_t scsi_flag_nointr_mutex; 57 kcondvar_t scsi_flag_nointr_cv; 58 kmutex_t scsi_log_mutex; 59 60 /* 61 * Prototypes for static functions 62 */ 63 static int scsi_hba_bus_ctl( 64 dev_info_t *self, 65 dev_info_t *child, 66 ddi_ctl_enum_t op, 67 void *arg, 68 void *result); 69 70 static int scsi_hba_map_fault( 71 dev_info_t *self, 72 dev_info_t *child, 73 struct hat *hat, 74 struct seg *seg, 75 caddr_t addr, 76 struct devpage *dp, 77 pfn_t pfn, 78 uint_t prot, 79 uint_t lock); 80 81 static int scsi_hba_get_eventcookie( 82 dev_info_t *self, 83 dev_info_t *child, 84 char *name, 85 ddi_eventcookie_t *eventp); 86 87 static int scsi_hba_add_eventcall( 88 dev_info_t *self, 89 dev_info_t *child, 90 ddi_eventcookie_t event, 91 void (*callback)( 92 dev_info_t *dip, 93 ddi_eventcookie_t event, 94 void *arg, 95 void *bus_impldata), 96 void *arg, 97 ddi_callback_id_t *cb_id); 98 99 static int scsi_hba_remove_eventcall( 100 dev_info_t *self, 101 ddi_callback_id_t id); 102 103 static int scsi_hba_post_event( 104 dev_info_t *self, 105 dev_info_t *child, 106 ddi_eventcookie_t event, 107 void *bus_impldata); 108 109 static int scsi_hba_info( 110 dev_info_t *self, 111 ddi_info_cmd_t infocmd, 112 void *arg, 113 void **result); 114 115 static int scsi_hba_bus_config( 116 dev_info_t *self, 117 uint_t flags, 118 ddi_bus_config_op_t op, 119 void *arg, 120 dev_info_t **childp); 121 122 static int scsi_hba_bus_unconfig( 123 dev_info_t *self, 124 uint_t flags, 125 ddi_bus_config_op_t op, 126 void *arg); 127 128 static int scsi_hba_fm_init_child( 129 dev_info_t *self, 130 dev_info_t *child, 131 int cap, 132 ddi_iblock_cookie_t *ibc); 133 134 static int scsi_hba_bus_power( 135 dev_info_t *self, 136 void *impl_arg, 137 pm_bus_power_op_t op, 138 void *arg, 139 void *result); 140 141 /* busops vector for SCSI HBA's. */ 142 static struct bus_ops scsi_hba_busops = { 143 BUSO_REV, 144 nullbusmap, /* bus_map */ 145 NULL, /* bus_get_intrspec */ 146 NULL, /* bus_add_intrspec */ 147 NULL, /* bus_remove_intrspec */ 148 scsi_hba_map_fault, /* bus_map_fault */ 149 ddi_dma_map, /* bus_dma_map */ 150 ddi_dma_allochdl, /* bus_dma_allochdl */ 151 ddi_dma_freehdl, /* bus_dma_freehdl */ 152 ddi_dma_bindhdl, /* bus_dma_bindhdl */ 153 ddi_dma_unbindhdl, /* bus_unbindhdl */ 154 ddi_dma_flush, /* bus_dma_flush */ 155 ddi_dma_win, /* bus_dma_win */ 156 ddi_dma_mctl, /* bus_dma_ctl */ 157 scsi_hba_bus_ctl, /* bus_ctl */ 158 ddi_bus_prop_op, /* bus_prop_op */ 159 scsi_hba_get_eventcookie, /* bus_get_eventcookie */ 160 scsi_hba_add_eventcall, /* bus_add_eventcall */ 161 scsi_hba_remove_eventcall, /* bus_remove_eventcall */ 162 scsi_hba_post_event, /* bus_post_event */ 163 NULL, /* bus_intr_ctl */ 164 scsi_hba_bus_config, /* bus_config */ 165 scsi_hba_bus_unconfig, /* bus_unconfig */ 166 scsi_hba_fm_init_child, /* bus_fm_init */ 167 NULL, /* bus_fm_fini */ 168 NULL, /* bus_fm_access_enter */ 169 NULL, /* bus_fm_access_exit */ 170 scsi_hba_bus_power /* bus_power */ 171 }; 172 173 /* cb_ops for hotplug :devctl and :scsi support */ 174 static struct cb_ops scsi_hba_cbops = { 175 scsi_hba_open, 176 scsi_hba_close, 177 nodev, /* strategy */ 178 nodev, /* print */ 179 nodev, /* dump */ 180 nodev, /* read */ 181 nodev, /* write */ 182 scsi_hba_ioctl, /* ioctl */ 183 nodev, /* devmap */ 184 nodev, /* mmap */ 185 nodev, /* segmap */ 186 nochpoll, /* poll */ 187 ddi_prop_op, /* prop_op */ 188 NULL, /* stream */ 189 D_NEW|D_MP|D_HOTPLUG, /* cb_flag */ 190 CB_REV, /* rev */ 191 nodev, /* int (*cb_aread)() */ 192 nodev /* int (*cb_awrite)() */ 193 }; 194 195 /* 196 * SCSI_HBA_LOG is used for all messages. A logging level is specified when 197 * generating a message. Some levels correspond directly to cmn_err levels, 198 * the others are associated with increasing levels diagnostic/debug output. 199 * For _LOG() messages, a __func__ prefix will identify the function origin 200 * of the message. For _LOG_NF messages, there is no function prefix or 201 * self/child context. Filtering of messages is provided based on logging 202 * level, but messages with cmn_err logging level and messages generated 203 * generated with _LOG_NF() are never filtered. 204 * 205 * For debugging, more complete information can be displayed with each message 206 * (full device path and pointer values) by adjusting scsi_hba_log_info. 207 */ 208 /* logging levels */ 209 #define SCSI_HBA_LOGCONT CE_CONT 210 #define SCSI_HBA_LOGNOTE CE_NOTE 211 #define SCSI_HBA_LOGWARN CE_WARN 212 #define SCSI_HBA_LOGPANIC CE_PANIC 213 #define SCSI_HBA_LOGIGNORE CE_IGNORE 214 #define SCSI_HBA_LOG_CE_MASK 0x0000000F /* no filter for these levels */ 215 #define SCSI_HBA_LOG1 0x00000010 /* DIAG1 level enable */ 216 #define SCSI_HBA_LOG2 0x00000020 /* DIAG2 level enable */ 217 #define SCSI_HBA_LOG3 0x00000040 /* DIAG3 level enable */ 218 #define SCSI_HBA_LOG4 0x00000080 /* DIAG4 level enable */ 219 #define SCSI_HBA_LOGTRACE 0x00000100 /* TRACE enable */ 220 #if (CE_CONT | CE_NOTE | CE_WARN | CE_PANIC | CE_IGNORE) > SCSI_HBA_LOG_CE_MASK 221 Error, problem with CE_ definitions 222 #endif 223 224 /* 225 * Tunable log message augmentation and filters: filters do not apply to 226 * SCSI_HBA_LOG_CE_MASK level messages or LOG_NF() messages. 227 * 228 * An example set of /etc/system tunings to simplify debug a SCSA pHCI HBA 229 * driver called "pmcs", including "scsi_vhci" operation, might be: 230 * 231 * echo "set scsi:scsi_hba_log_filter_level=0xf0" >> /etc/system 232 * echo "set scsi:scsi_hba_log_filter_phci=\"pmcs\"" >> /etc/system 233 * echo "set scsi:scsi_hba_log_filter_vhci=\"scsi_vhci\"" >> /etc/system 234 * echo "set scsi:scsi_hba_log_align=1" >> /etc/system 235 * echo "set scsi:scsi_hba_log_fcif=0x21" >> /etc/system 236 * echo "set scsi:scsi_hba_log_mt_disable=0x6" >> /etc/system 237 * echo "set mtc_off=1" >> /etc/system 238 * echo "set mdi_mtc_off=1" >> /etc/system 239 */ 240 int scsi_hba_log_filter_level = 241 SCSI_HBA_LOG1 | 242 0; 243 char *scsi_hba_log_filter_phci = "\0\0\0\0\0\0\0\0\0\0\0\0"; 244 char *scsi_hba_log_filter_vhci = "\0\0\0\0\0\0\0\0\0\0\0\0"; 245 int scsi_hba_log_align = 0; /* NOTE: will not cause truncation */ 246 int scsi_hba_log_fcif = '\0'; /* "^!?" first char in format */ 247 /* ^==0x5e, !==0x21, ?==0x3F */ 248 /* See cmn_err(9F) */ 249 int scsi_hba_log_info = /* augmentation: extra info output */ 250 (0 << 0) | /* 0x0001: process information */ 251 (0 << 1) | /* 0x0002: full /devices path */ 252 (0 << 2); /* 0x0004: devinfo pointer */ 253 254 int scsi_hba_log_mt_disable = 255 /* SCSI_ENUMERATION_MT_LUN_DISABLE | (ie 0x02) */ 256 /* SCSI_ENUMERATION_MT_TARGET_DISABLE | (ie 0x04) */ 257 0; 258 259 /* static data for HBA logging subsystem */ 260 static kmutex_t scsi_hba_log_mutex; 261 static char scsi_hba_log_i[512]; 262 static char scsi_hba_log_buf[512]; 263 static char scsi_hba_fmt[512]; 264 265 /* Macros to use in scsi_hba.c source code below */ 266 #define SCSI_HBA_LOG(x) scsi_hba_log x 267 #define _LOG(level) SCSI_HBA_LOG##level, __func__ 268 #define _LOG_NF(level) SCSI_HBA_LOG##level, NULL, NULL, NULL 269 #define _LOG_TRACE _LOG(TRACE) 270 271 /*PRINTFLIKE5*/ 272 void 273 scsi_hba_log(int level, const char *func, dev_info_t *self, dev_info_t *child, 274 const char *fmt, ...) 275 { 276 va_list ap; 277 int clevel; 278 int align; 279 char *info; 280 char *f; 281 char *ua; 282 283 /* derive self from child's parent */ 284 if ((self == NULL) && child) 285 self = ddi_get_parent(child); 286 287 /* no filtering of SCSI_HBA_LOG_CE_MASK or LOG_NF messages */ 288 if (((level & SCSI_HBA_LOG_CE_MASK) != level) && (func != NULL)) { 289 /* scsi_hba_log_filter_level: filter on level as bitmask */ 290 if ((level & scsi_hba_log_filter_level) == 0) 291 return; 292 293 /* scsi_hba_log_filter_phci/vhci: on name of driver */ 294 if (*scsi_hba_log_filter_phci && 295 ((self == NULL) || 296 (ddi_driver_name(self) == NULL) || 297 strcmp(ddi_driver_name(self), scsi_hba_log_filter_phci))) { 298 /* does not match pHCI, check vHCI */ 299 if (*scsi_hba_log_filter_vhci && 300 ((self == NULL) || 301 (ddi_driver_name(self) == NULL) || 302 strcmp(ddi_driver_name(self), 303 scsi_hba_log_filter_vhci))) { 304 /* does not match vHCI */ 305 return; 306 } 307 } 308 309 310 /* passed filters, determine align */ 311 align = scsi_hba_log_align; 312 313 /* shorten func for filtered output */ 314 if (strncmp(func, "scsi_hba_", 9) == 0) 315 func += 9; 316 if (strncmp(func, "scsi_", 5) == 0) 317 func += 5; 318 } else { 319 /* don't align output that is never filtered */ 320 align = 0; 321 } 322 323 /* determine the cmn_err form from the level */ 324 clevel = ((level & SCSI_HBA_LOG_CE_MASK) == level) ? level : CE_CONT; 325 326 /* protect common buffers used to format output */ 327 mutex_enter(&scsi_hba_log_mutex); 328 329 /* skip special first characters, we add them back below */ 330 f = (char *)fmt; 331 if (*f && strchr("^!?", *f)) 332 f++; 333 va_start(ap, fmt); 334 (void) vsprintf(scsi_hba_log_buf, f, ap); 335 va_end(ap); 336 337 /* augment message with 'information' */ 338 info = scsi_hba_log_i; 339 *info = '\0'; 340 if ((scsi_hba_log_info & 0x0001) && curproc && PTOU(curproc)->u_comm) { 341 (void) sprintf(info, "%s[%d]%p ", 342 PTOU(curproc)->u_comm, curproc->p_pid, (void *)curthread); 343 info += strlen(info); 344 } 345 if (self) { 346 if ((scsi_hba_log_info & 0x0004) && (child || self)) { 347 (void) sprintf(info, "%p ", 348 (void *)(child ? child : self)); 349 info += strlen(info); 350 } 351 if (scsi_hba_log_info & 0x0002) { 352 (void) ddi_pathname(child ? child : self, info); 353 (void) strcat(info, " "); 354 info += strlen(info); 355 } 356 357 /* always provide 'default' information about self &child */ 358 (void) sprintf(info, "%s%d ", ddi_driver_name(self), 359 ddi_get_instance(self)); 360 info += strlen(info); 361 if (child) { 362 ua = ddi_get_name_addr(child); 363 (void) sprintf(info, "%s@%s ", 364 ddi_node_name(child), (ua && *ua) ? ua : ""); 365 info += strlen(info); 366 } 367 } 368 369 /* turn off alignment if truncation would occur */ 370 if (align && ((strlen(func) > 18) || (strlen(scsi_hba_log_i) > 36))) 371 align = 0; 372 373 /* adjust for aligned output */ 374 if (align) { 375 if (func == NULL) 376 func = ""; 377 /* remove trailing blank with align output */ 378 if ((info != scsi_hba_log_i) && (*(info -1) == '\b')) 379 *(info - 1) = '\0'; 380 } 381 382 /* special "first character in format" must be in format itself */ 383 f = scsi_hba_fmt; 384 if (fmt[0] && strchr("^!?", fmt[0])) 385 *f++ = fmt[0]; 386 else if (scsi_hba_log_fcif) 387 *f++ = (char)scsi_hba_log_fcif; /* add global fcif */ 388 if (align) 389 (void) sprintf(f, "%s", "%-18.18s: %36.36s: %s%s"); 390 else 391 (void) sprintf(f, "%s", func ? "%s: %s%s%s" : "%s%s%s"); 392 393 if (func) 394 cmn_err(clevel, scsi_hba_fmt, func, scsi_hba_log_i, 395 scsi_hba_log_buf, clevel == CE_CONT ? "\n" : ""); 396 else 397 cmn_err(clevel, scsi_hba_fmt, scsi_hba_log_i, 398 scsi_hba_log_buf, clevel == CE_CONT ? "\n" : ""); 399 mutex_exit(&scsi_hba_log_mutex); 400 } 401 402 /* 403 * Called from _init() when loading "scsi" module 404 */ 405 void 406 scsi_initialize_hba_interface() 407 { 408 SCSI_HBA_LOG((_LOG_TRACE, NULL, NULL, __func__)); 409 410 mutex_init(&scsi_log_mutex, NULL, MUTEX_DRIVER, NULL); 411 mutex_init(&scsi_flag_nointr_mutex, NULL, MUTEX_DRIVER, NULL); 412 cv_init(&scsi_flag_nointr_cv, NULL, CV_DRIVER, NULL); 413 mutex_init(&scsi_hba_log_mutex, NULL, MUTEX_DRIVER, NULL); 414 } 415 416 int 417 scsi_hba_pkt_constructor(void *buf, void *arg, int kmflag) 418 { 419 struct scsi_pkt_cache_wrapper *pktw; 420 struct scsi_pkt *pkt; 421 scsi_hba_tran_t *tran = (scsi_hba_tran_t *)arg; 422 int pkt_len; 423 char *ptr; 424 425 /* 426 * allocate a chunk of memory for the following: 427 * scsi_pkt 428 * pcw_* fields 429 * pkt_ha_private 430 * pkt_cdbp, if needed 431 * (pkt_private always null) 432 * pkt_scbp, if needed 433 */ 434 pkt_len = tran->tran_hba_len + sizeof (struct scsi_pkt_cache_wrapper); 435 if (tran->tran_hba_flags & SCSI_HBA_TRAN_CDB) 436 pkt_len += DEFAULT_CDBLEN; 437 if (tran->tran_hba_flags & SCSI_HBA_TRAN_SCB) 438 pkt_len += DEFAULT_SCBLEN; 439 bzero(buf, pkt_len); 440 441 ptr = buf; 442 pktw = buf; 443 ptr += sizeof (struct scsi_pkt_cache_wrapper); 444 pkt = &(pktw->pcw_pkt); 445 pkt->pkt_ha_private = (opaque_t)ptr; 446 447 pktw->pcw_magic = PKT_WRAPPER_MAGIC; /* alloced correctly */ 448 /* 449 * keep track of the granularity at the time this handle was 450 * allocated 451 */ 452 pktw->pcw_granular = tran->tran_dma_attr.dma_attr_granular; 453 454 if (ddi_dma_alloc_handle(tran->tran_hba_dip, 455 &tran->tran_dma_attr, 456 kmflag == KM_SLEEP ? SLEEP_FUNC: NULL_FUNC, NULL, 457 &pkt->pkt_handle) != DDI_SUCCESS) { 458 459 return (-1); 460 } 461 ptr += tran->tran_hba_len; 462 if (tran->tran_hba_flags & SCSI_HBA_TRAN_CDB) { 463 pkt->pkt_cdbp = (opaque_t)ptr; 464 ptr += DEFAULT_CDBLEN; 465 } 466 pkt->pkt_private = NULL; 467 if (tran->tran_hba_flags & SCSI_HBA_TRAN_SCB) 468 pkt->pkt_scbp = (opaque_t)ptr; 469 if (tran->tran_pkt_constructor) 470 return ((*tran->tran_pkt_constructor)(pkt, arg, kmflag)); 471 else 472 return (0); 473 } 474 475 #define P_TO_TRAN(pkt) ((pkt)->pkt_address.a_hba_tran) 476 477 void 478 scsi_hba_pkt_destructor(void *buf, void *arg) 479 { 480 struct scsi_pkt_cache_wrapper *pktw = buf; 481 struct scsi_pkt *pkt = &(pktw->pcw_pkt); 482 scsi_hba_tran_t *tran = (scsi_hba_tran_t *)arg; 483 484 ASSERT(pktw->pcw_magic == PKT_WRAPPER_MAGIC); 485 ASSERT((pktw->pcw_flags & PCW_BOUND) == 0); 486 if (tran->tran_pkt_destructor) 487 (*tran->tran_pkt_destructor)(pkt, arg); 488 489 /* make sure nobody messed with our pointers */ 490 ASSERT(pkt->pkt_ha_private == (opaque_t)((char *)pkt + 491 sizeof (struct scsi_pkt_cache_wrapper))); 492 ASSERT(((tran->tran_hba_flags & SCSI_HBA_TRAN_SCB) == 0) || 493 (pkt->pkt_scbp == (opaque_t)((char *)pkt + 494 tran->tran_hba_len + 495 (((tran->tran_hba_flags & SCSI_HBA_TRAN_CDB) == 0) ? 496 0 : DEFAULT_CDBLEN) + 497 DEFAULT_PRIVLEN + sizeof (struct scsi_pkt_cache_wrapper)))); 498 ASSERT(((tran->tran_hba_flags & SCSI_HBA_TRAN_CDB) == 0) || 499 (pkt->pkt_cdbp == (opaque_t)((char *)pkt + 500 tran->tran_hba_len + 501 sizeof (struct scsi_pkt_cache_wrapper)))); 502 ASSERT(pkt->pkt_handle); 503 ddi_dma_free_handle(&pkt->pkt_handle); 504 pkt->pkt_handle = NULL; 505 pkt->pkt_numcookies = 0; 506 pktw->pcw_total_xfer = 0; 507 pktw->pcw_totalwin = 0; 508 pktw->pcw_curwin = 0; 509 } 510 511 /* 512 * Called by an HBA from _init() to plumb in common SCSA bus_ops and 513 * cb_ops for the HBA's :devctl and :scsi minor nodes. 514 */ 515 int 516 scsi_hba_init(struct modlinkage *modlp) 517 { 518 struct dev_ops *hba_dev_ops; 519 520 SCSI_HBA_LOG((_LOG_TRACE, NULL, NULL, __func__)); 521 522 /* 523 * Get a pointer to the dev_ops structure of the HBA and plumb our 524 * bus_ops vector into the HBA's dev_ops structure. 525 */ 526 hba_dev_ops = ((struct modldrv *)(modlp->ml_linkage[0]))->drv_dev_ops; 527 ASSERT(hba_dev_ops->devo_bus_ops == NULL); 528 hba_dev_ops->devo_bus_ops = &scsi_hba_busops; 529 530 /* 531 * Plumb our cb_ops vector into the HBA's dev_ops structure to 532 * provide getinfo and hotplugging ioctl support if the HBA driver 533 * does not already provide this support. 534 */ 535 if (hba_dev_ops->devo_cb_ops == NULL) { 536 hba_dev_ops->devo_cb_ops = &scsi_hba_cbops; 537 } 538 if (hba_dev_ops->devo_cb_ops->cb_open == scsi_hba_open) { 539 ASSERT(hba_dev_ops->devo_cb_ops->cb_close == scsi_hba_close); 540 hba_dev_ops->devo_getinfo = scsi_hba_info; 541 } 542 return (0); 543 } 544 545 /* 546 * Called by an HBA attach(9E) to allocate a scsi_hba_tran structure. An HBA 547 * driver will then initialize the structure and then call 548 * scsi_hba_attach_setup. 549 */ 550 /*ARGSUSED*/ 551 scsi_hba_tran_t * 552 scsi_hba_tran_alloc( 553 dev_info_t *self, 554 int flags) 555 { 556 scsi_hba_tran_t *tran; 557 558 SCSI_HBA_LOG((_LOG_TRACE, self, NULL, __func__)); 559 560 /* allocate SCSA flavors for self */ 561 ndi_flavorv_alloc(self, SCSA_NFLAVORS); 562 563 tran = kmem_zalloc(sizeof (scsi_hba_tran_t), 564 (flags & SCSI_HBA_CANSLEEP) ? KM_SLEEP : KM_NOSLEEP); 565 566 if (tran) { 567 tran->tran_interconnect_type = INTERCONNECT_PARALLEL; 568 tran->tran_hba_flags |= SCSI_HBA_SCSA_TA; 569 } 570 571 return (tran); 572 } 573 574 /* 575 * Called by an HBA to free a scsi_hba_tran structure 576 */ 577 void 578 scsi_hba_tran_free( 579 scsi_hba_tran_t *tran) 580 { 581 SCSI_HBA_LOG((_LOG_TRACE, tran->tran_hba_dip, NULL, __func__)); 582 583 kmem_free(tran, sizeof (scsi_hba_tran_t)); 584 } 585 586 int 587 scsi_tran_ext_alloc( 588 scsi_hba_tran_t *tran, 589 size_t length, 590 int flags) 591 { 592 void *tran_ext; 593 int ret = DDI_FAILURE; 594 595 tran_ext = kmem_zalloc(length, 596 (flags & SCSI_HBA_CANSLEEP) ? KM_SLEEP : KM_NOSLEEP); 597 if (tran_ext != NULL) { 598 tran->tran_extension = tran_ext; 599 ret = DDI_SUCCESS; 600 } 601 return (ret); 602 } 603 604 void 605 scsi_tran_ext_free( 606 scsi_hba_tran_t *tran, 607 size_t length) 608 { 609 if (tran->tran_extension != NULL) { 610 kmem_free(tran->tran_extension, length); 611 tran->tran_extension = NULL; 612 } 613 } 614 615 /* 616 * Return the unit-address of an 'iport' node, or NULL for non-iport node. 617 */ 618 char * 619 scsi_hba_iport_unit_address(dev_info_t *self) 620 { 621 /* 622 * NOTE: Since 'self' could be a SCSA iport node or a SCSA HBA node, 623 * we can't use SCSA flavors: the flavor of a SCSA HBA node is not 624 * established/owned by SCSA, it is established by the nexus that 625 * created the SCSA HBA node (PCI) as a child. 626 * 627 * NOTE: If we want to support a node_name other than "iport" for 628 * an iport node then we can add support for a "scsa-iport-node-name" 629 * property on the SCSA HBA node. A SCSA HBA driver would set this 630 * property on the SCSA HBA node prior to using the iport API. 631 */ 632 if (strcmp(ddi_node_name(self), "iport") == 0) 633 return (ddi_get_name_addr(self)); 634 else 635 return (NULL); 636 } 637 638 /* 639 * Define a SCSI initiator port (bus/channel) for an HBA card that needs to 640 * support multiple SCSI ports, but only has a single HBA devinfo node. This 641 * function should be called from the HBA's attach(9E) implementation (when 642 * processing the HBA devinfo node attach) after the number of SCSI ports on 643 * the card is known or DR handler once DR handler detects a new port added. 644 * The function returns 0 on failure and 1 on success. 645 * 646 * The implementation will add the port value into the "scsi-iports" property 647 * value maintained on the HBA node as. These properties are used by the generic 648 * scsi bus_config implementation to dynamicaly enumerate the specified iport 649 * children. The enumeration code will, on demand, create the appropriate 650 * iport children with a "scsi-iport" unit address. This node will bind to the 651 * same driver as the HBA node itself. This means that an HBA driver that 652 * uses iports should expect probe(9E), attach(9E), and detach(9E) calls on 653 * the iport children of the HBA. If configuration for all ports was already 654 * done during HBA node attach, the driver should just return DDI_SUCCESS when 655 * confronted with an iport node. 656 * 657 * A maximum of 32 iport ports are supported per HBA devinfo node. 658 * 659 * A NULL "port" can be used to indicate that the framework should enumerate 660 * target children on the HBA node itself, in addition to enumerating target 661 * children on any iport nodes declared. There are two reasons that an HBA may 662 * wish to have target children enumerated on both the HBA node and iport 663 * node(s): 664 * 665 * o If, in the past, HBA hardware had only a single physical port but now 666 * supports multiple physical ports, the updated driver that supports 667 * multiple physical ports may want to avoid /devices path upgrade issues 668 * by enumerating the first physical port under the HBA instead of as a 669 * iport. 670 * 671 * o Some hardware RAID HBA controllers (mlx, chs, etc) support multiple 672 * SCSI physical ports configured so that various physical devices on 673 * the physical ports are amalgamated into virtual devices on a virtual 674 * port. Amalgamated physical devices no longer appear to the host OS 675 * on the physical ports, but other non-amalgamated devices may still be 676 * visible on the physical ports. These drivers use a model where the 677 * physical ports are iport nodes and the HBA node is the virtual port to 678 * the configured virtual devices. 679 * 680 */ 681 682 int 683 scsi_hba_iport_register(dev_info_t *self, char *port) 684 { 685 unsigned int ports = 0; 686 int rval, i; 687 char **iports, **newiports; 688 689 ASSERT(self); 690 if (self == NULL) 691 return (DDI_FAILURE); 692 693 rval = ddi_prop_lookup_string_array(DDI_DEV_T_ANY, self, 694 DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "scsi-iports", &iports, 695 &ports); 696 697 if (ports == SCSI_HBA_MAX_IPORTS) { 698 ddi_prop_free(iports); 699 return (DDI_FAILURE); 700 } 701 702 if (rval == DDI_PROP_SUCCESS) { 703 for (i = 0; i < ports; i++) { 704 if (strcmp(port, iports[i]) == 0) { 705 ddi_prop_free(iports); 706 return (DDI_SUCCESS); 707 } 708 } 709 } 710 711 newiports = kmem_alloc((sizeof (char *) * (ports + 1)), KM_SLEEP); 712 713 for (i = 0; i < ports; i++) { 714 newiports[i] = strdup(iports[i]); 715 } 716 newiports[ports] = strdup(port); 717 ports++; 718 719 rval = 1; 720 721 if (ddi_prop_update_string_array(DDI_DEV_T_NONE, self, 722 "scsi-iports", newiports, ports) != DDI_PROP_SUCCESS) { 723 SCSI_HBA_LOG((_LOG(WARN), self, NULL, 724 "Failed to establish scsi-iport %s", port)); 725 rval = DDI_FAILURE; 726 } else { 727 rval = DDI_SUCCESS; 728 } 729 730 /* If there is iport exist, free property */ 731 if (ports > 1) 732 ddi_prop_free(iports); 733 for (i = 0; i < ports; i++) { 734 strfree(newiports[i]); 735 } 736 kmem_free(newiports, (sizeof (char *)) * ports); 737 738 return (rval); 739 } 740 741 /* 742 * Check if the HBA is with scsi-iport under it 743 */ 744 int 745 scsi_hba_iport_exist(dev_info_t *self) 746 { 747 unsigned int ports = 0; 748 char **iports; 749 int rval; 750 751 rval = ddi_prop_lookup_string_array(DDI_DEV_T_ANY, self, 752 DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "scsi-iports", &iports, 753 &ports); 754 755 if (rval != DDI_PROP_SUCCESS) 756 return (0); 757 758 /* If there is now at least 1 iport, then iports is valid */ 759 if (ports > 0) { 760 rval = 1; 761 } else 762 rval = 0; 763 ddi_prop_free(iports); 764 765 return (rval); 766 } 767 768 dev_info_t * 769 scsi_hba_iport_find(dev_info_t *self, char *portnm) 770 { 771 char *addr = NULL; 772 char **iports; 773 unsigned int num_iports = 0; 774 int rval = DDI_FAILURE; 775 int i = 0; 776 dev_info_t *child = NULL; 777 778 /* check to see if this is an HBA that defined scsi iports */ 779 rval = ddi_prop_lookup_string_array(DDI_DEV_T_ANY, self, 780 DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "scsi-iports", &iports, 781 &num_iports); 782 783 if (rval != DDI_SUCCESS) { 784 return (NULL); 785 } 786 ASSERT(num_iports > 0); 787 788 /* check to see if this port was registered */ 789 for (i = 0; i < num_iports; i++) { 790 if (strcmp(iports[i], portnm) == 0) 791 break; 792 } 793 794 if (i == num_iports) { 795 child = NULL; 796 goto out; 797 } 798 799 addr = kmem_zalloc(SCSI_MAXNAMELEN, KM_SLEEP); 800 (void) sprintf(addr, "iport@%s", portnm); 801 rval = ndi_devi_config_one(self, addr, &child, NDI_NO_EVENT); 802 kmem_free(addr, SCSI_MAXNAMELEN); 803 804 if (rval != DDI_SUCCESS) { 805 child = NULL; 806 } 807 out: 808 ddi_prop_free(iports); 809 return (child); 810 } 811 812 /* 813 * Common nexus teardown code: used by both scsi_hba_detach() on SCSA HBA node 814 * and iport_devctl_uninitchild() on a SCSA HBA iport node (and for failure 815 * cleanup). Undo scsa_nexus_setup in reverse order. 816 */ 817 static void 818 scsa_nexus_teardown(dev_info_t *self, scsi_hba_tran_t *tran) 819 { 820 if ((self == NULL) || (tran == NULL)) 821 return; 822 /* Teardown FMA. */ 823 if (tran->tran_hba_flags & SCSI_HBA_SCSA_FM) { 824 ddi_fm_fini(self); 825 tran->tran_hba_flags &= SCSI_HBA_SCSA_FM; 826 } 827 } 828 829 /* 830 * Common nexus setup code: used by both scsi_hba_attach_setup() on SCSA HBA 831 * node and iport_devctl_initchild() on a SCSA HBA iport node. 832 * 833 * This code makes no assumptions about tran use by scsi_device children. 834 */ 835 static int 836 scsa_nexus_setup(dev_info_t *self, scsi_hba_tran_t *tran) 837 { 838 int capable; 839 int scsa_minor; 840 841 /* 842 * NOTE: SCSA maintains an 'fm-capable' domain, in tran_fm_capable, 843 * that is not dependent (limited by) the capabilities of its parents. 844 * For example a devinfo node in a branch that is not 845 * DDI_FM_EREPORT_CAPABLE may report as capable, via tran_fm_capable, 846 * to its scsi_device children. 847 * 848 * Get 'fm-capable' property from driver.conf, if present. If not 849 * present, default to the scsi_fm_capable global (which has 850 * DDI_FM_EREPORT_CAPABLE set by default). 851 */ 852 if (tran->tran_fm_capable == DDI_FM_NOT_CAPABLE) 853 tran->tran_fm_capable = ddi_prop_get_int(DDI_DEV_T_ANY, self, 854 DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, 855 "fm-capable", scsi_fm_capable); 856 /* 857 * If an HBA is *not* doing its own fma support by calling 858 * ddi_fm_init() prior to scsi_hba_attach_setup(), we provide a 859 * minimal common SCSA implementation so that scsi_device children 860 * can generate ereports via scsi_fm_ereport_post(). We use 861 * ddi_fm_capable() to detect an HBA calling ddi_fm_init() prior to 862 * scsi_hba_attach_setup(). 863 */ 864 if (tran->tran_fm_capable && 865 (ddi_fm_capable(self) == DDI_FM_NOT_CAPABLE)) { 866 /* 867 * We are capable of something, pass our capabilities up 868 * the tree, but use a local variable so our parent can't 869 * limit our capabilities (we don't want our parent to 870 * clear DDI_FM_EREPORT_CAPABLE). 871 * 872 * NOTE: iblock cookies are not important because scsi 873 * HBAs always interrupt below LOCK_LEVEL. 874 */ 875 capable = tran->tran_fm_capable; 876 ddi_fm_init(self, &capable, NULL); 877 878 /* 879 * Set SCSI_HBA_SCSA_FM bit to mark us as usiung the 880 * common minimal SCSA fm implementation - we called 881 * ddi_fm_init(), so we are responsible for calling 882 * ddi_fm_fini() in scsi_hba_detach(). 883 * NOTE: if ddi_fm_init fails in any reason, SKIP. 884 */ 885 if (DEVI(self)->devi_fmhdl) 886 tran->tran_hba_flags |= SCSI_HBA_SCSA_FM; 887 } 888 889 /* If SCSA responsible for for minor nodes, create :devctl minor. */ 890 scsa_minor = (ddi_get_driver(self)->devo_cb_ops->cb_open == 891 scsi_hba_open) ? 1 : 0; 892 if (scsa_minor && ((ddi_create_minor_node(self, "devctl", S_IFCHR, 893 INST2DEVCTL(ddi_get_instance(self)), DDI_NT_SCSI_NEXUS, 0) != 894 DDI_SUCCESS))) { 895 SCSI_HBA_LOG((_LOG(WARN), self, NULL, 896 "can't create devctl minor nodes")); 897 scsa_nexus_teardown(self, tran); 898 return (DDI_FAILURE); 899 } 900 901 return (DDI_SUCCESS); 902 } 903 904 /* 905 * Common tran teardown code: used by iport_devctl_uninitchild() on a SCSA HBA 906 * iport node and (possibly) by scsi_hba_detach() on SCSA HBA node (and for 907 * failure cleanup). Undo scsa_tran_setup in reverse order. 908 */ 909 /*ARGSUSED*/ 910 static void 911 scsa_tran_teardown(dev_info_t *self, scsi_hba_tran_t *tran) 912 { 913 if (tran == NULL) 914 return; 915 tran->tran_iport_dip = NULL; 916 917 /* 918 * In the future, if PHCI was registered in the SCSA 919 * scsa_tran_teardown is able to unregiter PHCI 920 */ 921 } 922 923 static int 924 scsa_tran_setup(dev_info_t *self, scsi_hba_tran_t *tran) 925 { 926 int scsa_minor; 927 int id; 928 static const char *interconnect[] = INTERCONNECT_TYPE_ASCII; 929 930 /* If SCSA responsible for for minor nodes, create ":scsi" */ 931 scsa_minor = (ddi_get_driver(self)->devo_cb_ops->cb_open == 932 scsi_hba_open) ? 1 : 0; 933 if (scsa_minor && (ddi_create_minor_node(self, "scsi", S_IFCHR, 934 INST2SCSI(ddi_get_instance(self)), 935 DDI_NT_SCSI_ATTACHMENT_POINT, 0) != DDI_SUCCESS)) { 936 SCSI_HBA_LOG((_LOG(WARN), self, NULL, 937 "can't create scsi minor nodes")); 938 scsa_nexus_teardown(self, tran); 939 goto fail; 940 } 941 942 /* 943 * If the property does not already exist on self then see if we can 944 * pull it from further up the tree and define it on self. If the 945 * property does not exist above (including options.conf) then use the 946 * default value specified (global variable). 947 */ 948 #define CONFIG_INT_PROP(s, p, dv) { \ 949 if ((ddi_prop_exists(DDI_DEV_T_ANY, s, \ 950 DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, p) == 0) && \ 951 (ndi_prop_update_int(DDI_DEV_T_NONE, s, p, \ 952 ddi_prop_get_int(DDI_DEV_T_ANY, ddi_get_parent(s), \ 953 DDI_PROP_NOTPROM, p, dv)) != DDI_PROP_SUCCESS)) \ 954 SCSI_HBA_LOG((_LOG(WARN), NULL, s, \ 955 "can't create property '%s'", p)); \ 956 } 957 958 /* 959 * Attach scsi configuration property parameters not already defined 960 * via driver.conf to this instance of the HBA using global variable 961 * value. Pulling things down from above us to use 962 * "DDI_PROP_NOTPROM | DDI_PROP_DONTPASS" for faster access. 963 */ 964 CONFIG_INT_PROP(self, "scsi-options", scsi_options); 965 CONFIG_INT_PROP(self, "scsi-reset-delay", scsi_reset_delay); 966 CONFIG_INT_PROP(self, "scsi-tag-age-limit", scsi_tag_age_limit); 967 CONFIG_INT_PROP(self, "scsi-watchdog-tick", scsi_watchdog_tick); 968 CONFIG_INT_PROP(self, "scsi-selection-timeout", scsi_selection_timeout); 969 970 /* 971 * cache the scsi-initiator-id as an property defined further up 972 * the tree or defined by OBP on the HBA node so can use 973 * "DDI_PROP_NOTPROM | DDI_PROP_DONTPASS" during enumeration. 974 * We perform the same type of operation that an HBA driver would 975 * use to obtain the 'initiator-id' capability. 976 */ 977 id = ddi_prop_get_int(DDI_DEV_T_ANY, self, 0, "initiator-id", -1); 978 if (id == -1) 979 id = ddi_prop_get_int(DDI_DEV_T_ANY, self, 0, 980 "scsi-initiator-id", -1); 981 if (id != -1) 982 CONFIG_INT_PROP(self, "scsi-initiator-id", id); 983 984 /* Establish 'initiator-interconnect-type' */ 985 if ((tran->tran_hba_flags & SCSI_HBA_SCSA_TA) && 986 (tran->tran_interconnect_type > 0) && 987 (tran->tran_interconnect_type < INTERCONNECT_MAX)) { 988 if (ndi_prop_update_string(DDI_DEV_T_NONE, self, 989 "initiator-interconnect-type", 990 (char *)interconnect[tran->tran_interconnect_type]) 991 != DDI_PROP_SUCCESS) { 992 SCSI_HBA_LOG((_LOG(WARN), self, NULL, 993 "failed to establish " 994 "'initiator-interconnect-type'")); 995 return (DDI_FAILURE); 996 } 997 } 998 999 tran->tran_iport_dip = self; 1000 /* 1001 * In the future SCSA v3, PHCI could be registered in the SCSA 1002 * here. 1003 */ 1004 return (DDI_SUCCESS); 1005 fail: 1006 scsa_tran_teardown(self, tran); 1007 return (DDI_FAILURE); 1008 } 1009 1010 /* 1011 * Obsolete: Called by an HBA to attach an instance of the driver 1012 * Implement this older interface in terms of the new. 1013 */ 1014 /*ARGSUSED*/ 1015 int 1016 scsi_hba_attach( 1017 dev_info_t *self, 1018 ddi_dma_lim_t *hba_lim, 1019 scsi_hba_tran_t *tran, 1020 int flags, 1021 void *hba_options) 1022 { 1023 ddi_dma_attr_t hba_dma_attr; 1024 1025 bzero(&hba_dma_attr, sizeof (ddi_dma_attr_t)); 1026 1027 hba_dma_attr.dma_attr_burstsizes = hba_lim->dlim_burstsizes; 1028 hba_dma_attr.dma_attr_minxfer = hba_lim->dlim_minxfer; 1029 1030 return (scsi_hba_attach_setup(self, &hba_dma_attr, tran, flags)); 1031 } 1032 1033 /* 1034 * Called by an HBA to attach an instance of the driver. 1035 */ 1036 int 1037 scsi_hba_attach_setup( 1038 dev_info_t *self, 1039 ddi_dma_attr_t *hba_dma_attr, 1040 scsi_hba_tran_t *tran, 1041 int flags) 1042 { 1043 SCSI_HBA_LOG((_LOG_TRACE, self, NULL, __func__)); 1044 1045 /* Verify that we are a driver */ 1046 if (ddi_get_driver(self) == NULL) 1047 return (DDI_FAILURE); 1048 1049 ASSERT(scsi_hba_iport_unit_address(self) == NULL); 1050 if (scsi_hba_iport_unit_address(self)) 1051 return (DDI_FAILURE); 1052 1053 ASSERT(tran); 1054 if (tran == NULL) 1055 return (DDI_FAILURE); 1056 1057 /* 1058 * Verify correct scsi_hba_tran_t form: 1059 * o both or none of tran_get_name/tran_get_addr. 1060 */ 1061 if ((tran->tran_get_name == NULL) ^ 1062 (tran->tran_get_bus_addr == NULL)) { 1063 return (DDI_FAILURE); 1064 } 1065 1066 /* 1067 * Save all the important HBA information that must be accessed 1068 * later by scsi_hba_bus_ctl(), and scsi_hba_map(). 1069 */ 1070 tran->tran_hba_dip = self; 1071 tran->tran_hba_flags &= SCSI_HBA_SCSA_TA; 1072 tran->tran_hba_flags |= (flags & ~SCSI_HBA_SCSA_TA); 1073 1074 /* Establish flavor of transport (and ddi_get_driver_private()) */ 1075 ndi_flavorv_set(self, SCSA_FLAVOR_SCSI_DEVICE, tran); 1076 1077 /* 1078 * Note: we only need dma_attr_minxfer and dma_attr_burstsizes 1079 * from the DMA attributes. scsi_hba_attach(9f) only 1080 * guarantees that these two fields are initialized properly. 1081 * If this changes, be sure to revisit the implementation 1082 * of scsi_hba_attach(9F). 1083 */ 1084 (void) memcpy(&tran->tran_dma_attr, hba_dma_attr, 1085 sizeof (ddi_dma_attr_t)); 1086 1087 /* create kmem_cache, if needed */ 1088 if (tran->tran_setup_pkt) { 1089 char tmp[96]; 1090 int hbalen; 1091 int cmdlen = 0; 1092 int statuslen = 0; 1093 1094 ASSERT(tran->tran_init_pkt == NULL); 1095 ASSERT(tran->tran_destroy_pkt == NULL); 1096 1097 tran->tran_init_pkt = scsi_init_cache_pkt; 1098 tran->tran_destroy_pkt = scsi_free_cache_pkt; 1099 tran->tran_sync_pkt = scsi_sync_cache_pkt; 1100 tran->tran_dmafree = scsi_cache_dmafree; 1101 1102 hbalen = ROUNDUP(tran->tran_hba_len); 1103 if (flags & SCSI_HBA_TRAN_CDB) 1104 cmdlen = ROUNDUP(DEFAULT_CDBLEN); 1105 if (flags & SCSI_HBA_TRAN_SCB) 1106 statuslen = ROUNDUP(DEFAULT_SCBLEN); 1107 1108 (void) snprintf(tmp, sizeof (tmp), "pkt_cache_%s_%d", 1109 ddi_driver_name(self), ddi_get_instance(self)); 1110 tran->tran_pkt_cache_ptr = kmem_cache_create(tmp, 1111 sizeof (struct scsi_pkt_cache_wrapper) + 1112 hbalen + cmdlen + statuslen, 8, 1113 scsi_hba_pkt_constructor, scsi_hba_pkt_destructor, 1114 NULL, tran, NULL, 0); 1115 } 1116 1117 /* Perform node setup independent of initiator role */ 1118 if (scsa_nexus_setup(self, tran) != DDI_SUCCESS) 1119 goto fail; 1120 1121 /* 1122 * The SCSI_HBA_HBA flag is passed to scsi_hba_attach_setup when the 1123 * HBA driver knows that *all* children of the SCSA HBA node will be 1124 * 'iports'. If the SCSA HBA node can have iport children and also 1125 * function as an initiator for xxx_device children then it should 1126 * not specify SCSI_HBA_HBA in its scsi_hba_attach_setup call. An 1127 * HBA driver that does not manage iports should not set SCSA_HBA_HBA. 1128 */ 1129 if (!(tran->tran_hba_flags & SCSI_HBA_HBA) && 1130 (scsa_tran_setup(self, tran) != DDI_SUCCESS)) 1131 goto fail; 1132 1133 return (DDI_SUCCESS); 1134 1135 fail: 1136 (void) scsi_hba_detach(self); 1137 return (DDI_FAILURE); 1138 } 1139 1140 /* 1141 * Called by an HBA to detach an instance of the driver 1142 */ 1143 int 1144 scsi_hba_detach(dev_info_t *self) 1145 { 1146 scsi_hba_tran_t *tran; 1147 1148 SCSI_HBA_LOG((_LOG_TRACE, self, NULL, __func__)); 1149 1150 ASSERT(scsi_hba_iport_unit_address(self) == NULL); 1151 if (scsi_hba_iport_unit_address(self)) 1152 return (DDI_FAILURE); 1153 1154 tran = ndi_flavorv_get(self, SCSA_FLAVOR_SCSI_DEVICE); 1155 ASSERT(tran); 1156 if (tran == NULL) 1157 return (DDI_FAILURE); 1158 1159 ASSERT(tran->tran_open_flag == 0); 1160 if (tran->tran_open_flag) 1161 return (DDI_FAILURE); 1162 1163 if (!(tran->tran_hba_flags & SCSI_HBA_HBA)) 1164 scsa_tran_teardown(self, tran); 1165 scsa_nexus_teardown(self, tran); 1166 1167 /* 1168 * XXX - scsi_transport.h states that these data fields should not be 1169 * referenced by the HBA. However, to be consistent with 1170 * scsi_hba_attach(), they are being reset. 1171 */ 1172 tran->tran_hba_dip = (dev_info_t *)NULL; 1173 tran->tran_hba_flags = 0; 1174 (void) memset(&tran->tran_dma_attr, 0, sizeof (ddi_dma_attr_t)); 1175 1176 if (tran->tran_pkt_cache_ptr != NULL) { 1177 kmem_cache_destroy(tran->tran_pkt_cache_ptr); 1178 tran->tran_pkt_cache_ptr = NULL; 1179 } 1180 1181 /* Teardown flavor of transport (and ddi_get_driver_private()) */ 1182 ndi_flavorv_set(self, SCSA_FLAVOR_SCSI_DEVICE, NULL); 1183 1184 return (DDI_SUCCESS); 1185 } 1186 1187 /* 1188 * Called by an HBA from _fini() 1189 */ 1190 void 1191 scsi_hba_fini(struct modlinkage *modlp) 1192 { 1193 struct dev_ops *hba_dev_ops; 1194 1195 SCSI_HBA_LOG((_LOG_TRACE, NULL, NULL, __func__)); 1196 1197 /* Get the devops structure of this module and clear bus_ops vector. */ 1198 hba_dev_ops = ((struct modldrv *)(modlp->ml_linkage[0]))->drv_dev_ops; 1199 1200 if (hba_dev_ops->devo_cb_ops == &scsi_hba_cbops) 1201 hba_dev_ops->devo_cb_ops = NULL; 1202 1203 if (hba_dev_ops->devo_getinfo == scsi_hba_info) 1204 hba_dev_ops->devo_getinfo = NULL; 1205 1206 hba_dev_ops->devo_bus_ops = (struct bus_ops *)NULL; 1207 } 1208 1209 /* 1210 * SAS specific functions 1211 */ 1212 /*ARGSUSED*/ 1213 sas_hba_tran_t * 1214 sas_hba_tran_alloc( 1215 dev_info_t *self, 1216 int flags) 1217 { 1218 /* allocate SCSA flavors for self */ 1219 ndi_flavorv_alloc(self, SCSA_NFLAVORS); 1220 return (kmem_zalloc(sizeof (sas_hba_tran_t), KM_SLEEP)); 1221 } 1222 1223 void 1224 sas_hba_tran_free( 1225 sas_hba_tran_t *tran) 1226 { 1227 kmem_free(tran, sizeof (sas_hba_tran_t)); 1228 } 1229 1230 int 1231 sas_hba_attach_setup( 1232 dev_info_t *self, 1233 sas_hba_tran_t *tran) 1234 { 1235 ASSERT(scsi_hba_iport_unit_address(self) == NULL); 1236 if (scsi_hba_iport_unit_address(self)) 1237 return (DDI_FAILURE); 1238 /* 1239 * The owner of the this devinfo_t was responsible 1240 * for informing the framework already about 1241 * additional flavors. 1242 */ 1243 ndi_flavorv_set(self, SCSA_FLAVOR_SMP, tran); 1244 return (DDI_SUCCESS); 1245 } 1246 1247 int 1248 sas_hba_detach(dev_info_t *self) 1249 { 1250 ASSERT(scsi_hba_iport_unit_address(self) == NULL); 1251 if (scsi_hba_iport_unit_address(self)) 1252 return (DDI_FAILURE); 1253 1254 ndi_flavorv_set(self, SCSA_FLAVOR_SMP, NULL); 1255 return (DDI_SUCCESS); 1256 } 1257 1258 /* 1259 * SMP child flavored functions 1260 */ 1261 1262 static int 1263 smp_busctl_reportdev(dev_info_t *child) 1264 { 1265 dev_info_t *self = ddi_get_parent(child); 1266 char *smp_wwn; 1267 1268 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child, 1269 DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, 1270 SMP_WWN, &smp_wwn) != DDI_SUCCESS) { 1271 return (DDI_FAILURE); 1272 } 1273 SCSI_HBA_LOG((_LOG_NF(CONT), "?%s%d at %s%d: wwn %s\n", 1274 ddi_driver_name(child), ddi_get_instance(child), 1275 ddi_driver_name(self), ddi_get_instance(self), smp_wwn)); 1276 ddi_prop_free(smp_wwn); 1277 return (DDI_SUCCESS); 1278 } 1279 1280 static int 1281 smp_busctl_initchild(dev_info_t *child) 1282 { 1283 dev_info_t *self = ddi_get_parent(child); 1284 sas_hba_tran_t *tran = ndi_flavorv_get(self, SCSA_FLAVOR_SMP); 1285 struct smp_device *smp; 1286 char addr[SCSI_MAXNAMELEN]; 1287 dev_info_t *ndip; 1288 char *smp_wwn = NULL; 1289 uint64_t wwn; 1290 1291 ASSERT(tran); 1292 if (tran == NULL) 1293 return (DDI_FAILURE); 1294 1295 smp = kmem_zalloc(sizeof (struct smp_device), KM_SLEEP); 1296 smp->dip = child; 1297 smp->smp_addr.a_hba_tran = tran; 1298 1299 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child, 1300 DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, 1301 SMP_WWN, &smp_wwn) != DDI_SUCCESS) { 1302 goto failure; 1303 } 1304 1305 if (ddi_devid_str_to_wwn(smp_wwn, &wwn)) { 1306 goto failure; 1307 } 1308 1309 bcopy(&wwn, smp->smp_addr.a_wwn, SAS_WWN_BYTE_SIZE); 1310 (void) snprintf(addr, SCSI_MAXNAMELEN, "w%s", smp_wwn); 1311 1312 /* Prevent duplicate nodes. */ 1313 ndip = ndi_devi_find(self, ddi_node_name(child), addr); 1314 if (ndip && (ndip != child)) { 1315 goto failure; 1316 } 1317 1318 ddi_set_name_addr(child, addr); 1319 ddi_set_driver_private(child, smp); 1320 ddi_prop_free(smp_wwn); 1321 return (DDI_SUCCESS); 1322 1323 failure: 1324 kmem_free(smp, sizeof (struct smp_device)); 1325 if (smp_wwn) { 1326 ddi_prop_free(smp_wwn); 1327 } 1328 return (DDI_FAILURE); 1329 } 1330 1331 /*ARGSUSED*/ 1332 static int 1333 smp_busctl_uninitchild(dev_info_t *child) 1334 { 1335 struct smp_device *smp = ddi_get_driver_private(child); 1336 1337 ASSERT(smp); 1338 if (smp == NULL) 1339 return (DDI_FAILURE); 1340 kmem_free(smp, sizeof (*smp)); 1341 ddi_set_driver_private(child, NULL); 1342 ddi_set_name_addr(child, NULL); 1343 return (DDI_SUCCESS); 1344 } 1345 1346 /* 1347 * Wrapper to scsi_get_name which takes a devinfo argument instead of a 1348 * scsi_device structure. 1349 */ 1350 static int 1351 scsi_hba_name_child(dev_info_t *child, char *addr, int maxlen) 1352 { 1353 struct scsi_device *sd = ddi_get_driver_private(child); 1354 1355 /* nodes are named by tran_get_name or default "tgt,lun" */ 1356 if (sd && (scsi_get_name(sd, addr, maxlen) == 1)) 1357 return (DDI_SUCCESS); 1358 1359 return (DDI_FAILURE); 1360 } 1361 1362 static int 1363 scsi_busctl_reportdev(dev_info_t *child) 1364 { 1365 dev_info_t *self = ddi_get_parent(child); 1366 scsi_hba_tran_t *tran = ddi_get_driver_private(self); 1367 struct scsi_device *sd = ddi_get_driver_private(child); 1368 char ua[SCSI_MAXNAMELEN]; 1369 char ba[SCSI_MAXNAMELEN]; 1370 1371 SCSI_HBA_LOG((_LOG_TRACE, NULL, child, __func__)); 1372 1373 ASSERT(tran && sd); 1374 if ((tran == NULL) || (sd == NULL)) 1375 return (DDI_FAILURE); 1376 1377 /* get the unit_address and bus_addr information */ 1378 if ((scsi_get_name(sd, ua, sizeof (ua)) == 0) || 1379 (scsi_get_bus_addr(sd, ba, sizeof (ba)) == 0)) { 1380 SCSI_HBA_LOG((_LOG(WARN), NULL, child, "REPORTDEV failure")); 1381 return (DDI_FAILURE); 1382 } 1383 1384 if (tran->tran_get_name == NULL) 1385 SCSI_HBA_LOG((_LOG_NF(CONT), "?%s%d at %s%d: %s", 1386 ddi_driver_name(child), ddi_get_instance(child), 1387 ddi_driver_name(self), ddi_get_instance(self), ba)); 1388 else 1389 SCSI_HBA_LOG((_LOG_NF(CONT), 1390 "?%s%d at %s%d: unit-address %s: %s", 1391 ddi_driver_name(child), ddi_get_instance(child), 1392 ddi_driver_name(self), ddi_get_instance(self), ua, ba)); 1393 return (DDI_SUCCESS); 1394 } 1395 1396 /* 1397 * scsi_busctl_initchild is called to initialize the SCSA transport for 1398 * communication with a particular child scsi target device. Successful 1399 * initialization requires properties on the node which describe the address 1400 * of the target device. If the address of the target device can't be 1401 * determined from properties then DDI_NOT_WELL_FORMED is returned. Nodes that 1402 * are DDI_NOT_WELL_FORMED are considered an implementation artifact. 1403 * The child may be one of the following types of devinfo nodes: 1404 * 1405 * OBP node: 1406 * OBP does not enumerate target devices attached a SCSI bus. These 1407 * template/stub/wildcard nodes are a legacy artifact for support of old 1408 * driver loading methods. Since they have no properties, 1409 * DDI_NOT_WELL_FORMED will be returned. 1410 * 1411 * SID node: 1412 * The node may be either a: 1413 * o probe/barrier SID node 1414 * o a dynamic SID target node 1415 * o a dynamic SID mscsi node 1416 * 1417 * driver.conf node: The situation for this nexus is different than most. 1418 * Typically a driver.conf node definition is used to either define a 1419 * new child devinfo node or to further decorate (via merge) a SID 1420 * child with properties. In our case we use the nodes for *both* 1421 * purposes. 1422 * 1423 * In both the SID node and driver.conf node cases we must form the nodes 1424 * "@addr" from the well-known scsi(9P) device unit-address properties on 1425 * the node. 1426 * 1427 * For HBA drivers that implement the deprecated tran_get_name interface, 1428 * "@addr" construction involves having that driver interpret properties via 1429 * scsi_hba_name_child -> scsi_get_name -> tran_get_name: there is no 1430 * requiremnt for the property names to be well-known. 1431 */ 1432 static int 1433 scsi_busctl_initchild(dev_info_t *child) 1434 { 1435 dev_info_t *self = ddi_get_parent(child); 1436 dev_info_t *dup; 1437 scsi_hba_tran_t *tran; 1438 struct scsi_device *sd; 1439 scsi_hba_tran_t *tran_clone; 1440 int tgt = 0; 1441 int lun = 0; 1442 int sfunc = 0; 1443 int err = DDI_FAILURE; 1444 char addr[SCSI_MAXNAMELEN]; 1445 1446 ASSERT(DEVI_BUSY_OWNED(self)); 1447 SCSI_HBA_LOG((_LOG(4), NULL, child, "init begin")); 1448 1449 /* 1450 * For a driver like fp with multiple upper-layer-protocols 1451 * it is possible for scsi_hba_init in _init to plumb SCSA 1452 * and have the load of fcp (which does scsi_hba_attach_setup) 1453 * to fail. In this case we may get here with a NULL hba. 1454 */ 1455 tran = ddi_get_driver_private(self); 1456 if (tran == NULL) 1457 return (DDI_NOT_WELL_FORMED); 1458 1459 /* 1460 * OBP may create template/stub/wildcard nodes for legacy driver 1461 * loading methods. These nodes have no properties, so we lack the 1462 * addressing properties to initchild them. Hide the node and return 1463 * DDI_NOT_WELL_FORMED. 1464 * 1465 * XXX need ndi_devi_has_properties(dip) type interface? 1466 * 1467 * XXX It would be nice if we could delete these ill formed nodes by 1468 * implementing a DDI_NOT_WELL_FORMED_DELETE return code. This can't 1469 * be done until leadville debug code removes its dependencies 1470 * on the devinfo still being present after a failed ndi_devi_online. 1471 */ 1472 if ((DEVI(child)->devi_hw_prop_ptr == NULL) && 1473 (DEVI(child)->devi_drv_prop_ptr == NULL) && 1474 (DEVI(child)->devi_sys_prop_ptr == NULL)) { 1475 SCSI_HBA_LOG((_LOG(4), NULL, child, 1476 "init failed: no properties")); 1477 return (DDI_NOT_WELL_FORMED); 1478 } 1479 1480 /* get legacy SPI addressing properties */ 1481 sfunc = ddi_prop_get_int(DDI_DEV_T_ANY, child, 1482 DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, SCSI_ADDR_PROP_SFUNC, -1); 1483 lun = ddi_prop_get_int(DDI_DEV_T_ANY, child, 1484 DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, SCSI_ADDR_PROP_LUN, 0); 1485 if ((tgt = ddi_prop_get_int(DDI_DEV_T_ANY, child, 1486 DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, 1487 SCSI_ADDR_PROP_TARGET, -1)) == -1) { 1488 tgt = 0; 1489 /* 1490 * A driver.conf node for merging always has a target= property, 1491 * even if it is just a dummy that does not contain the real 1492 * target address. However drivers that register devids may 1493 * create stub driver.conf nodes without a target= property so 1494 * that pathological devid resolution works. 1495 */ 1496 if (ndi_dev_is_persistent_node(child) == 0) { 1497 SCSI_HBA_LOG((_LOG(4), NULL, child, 1498 "init failed: stub .conf node")); 1499 return (DDI_NOT_WELL_FORMED); 1500 } 1501 } 1502 1503 /* 1504 * The scsi_address structure may not specify all the addressing 1505 * information. For an old HBA that doesn't support tran_get_name 1506 * (most pre-SCSI-3 HBAs) the scsi_address structure is still used, 1507 * so the target property must exist and the LUN must be < 256. 1508 */ 1509 if ((tran->tran_get_name == NULL) && 1510 ((tgt >= USHRT_MAX) || (lun >= 256))) { 1511 SCSI_HBA_LOG((_LOG(1), NULL, child, 1512 "init failed: illegal/missing properties")); 1513 return (DDI_NOT_WELL_FORMED); 1514 } 1515 1516 /* 1517 * We need to initialize a fair amount of our environment to invoke 1518 * tran_get_name (via scsi_hba_name_child and scsi_get_name) to 1519 * produce the "@addr" name from addressing properties. Allocate and 1520 * initialize scsi device structure. 1521 */ 1522 sd = kmem_zalloc(sizeof (struct scsi_device), KM_SLEEP); 1523 mutex_init(&sd->sd_mutex, NULL, MUTEX_DRIVER, NULL); 1524 sd->sd_dev = child; 1525 sd->sd_pathinfo = NULL; 1526 ddi_set_driver_private(child, sd); 1527 1528 if (tran->tran_hba_flags & SCSI_HBA_ADDR_COMPLEX) { 1529 /* 1530 * For a SCSI_HBA_ADDR_COMPLEX transport we store a pointer to 1531 * scsi_device in the scsi_address structure. This allows an 1532 * HBA driver to find its per-scsi_device private data 1533 * (accessable to the HBA given just the scsi_address by using 1534 * scsi_address_device(9F)/scsi_device_hba_private_get(9F)). 1535 */ 1536 sd->sd_address.a.a_sd = sd; 1537 tran_clone = NULL; 1538 } else { 1539 /* 1540 * Initialize the scsi_address so that a SCSI-2 target driver 1541 * talking to a SCSI-2 device on a SCSI-3 bus (spi) continues 1542 * to work. We skew the secondary function value so that we 1543 * can tell from the address structure if we are processing 1544 * a secondary function request. 1545 */ 1546 sd->sd_address.a_target = (ushort_t)tgt; 1547 sd->sd_address.a_lun = (uchar_t)lun; 1548 if (sfunc == -1) 1549 sd->sd_address.a_sublun = (uchar_t)0; 1550 else 1551 sd->sd_address.a_sublun = (uchar_t)sfunc + 1; 1552 1553 /* 1554 * XXX TODO: apply target/lun limitation logic for SPI 1555 * binding_set. If spi this is based on scsi_options WIDE 1556 * NLUNS some forms of lun limitation are based on the 1557 * device @lun 0 1558 */ 1559 1560 /* 1561 * Deprecated: Use SCSI_HBA_ADDR_COMPLEX: 1562 * Clone transport structure if requested. Cloning allows 1563 * an HBA to maintain target-specific information if 1564 * necessary, such as target addressing information that 1565 * does not adhere to the scsi_address structure format. 1566 */ 1567 if (tran->tran_hba_flags & SCSI_HBA_TRAN_CLONE) { 1568 tran_clone = kmem_alloc( 1569 sizeof (scsi_hba_tran_t), KM_SLEEP); 1570 bcopy((caddr_t)tran, 1571 (caddr_t)tran_clone, sizeof (scsi_hba_tran_t)); 1572 tran = tran_clone; 1573 tran->tran_sd = sd; 1574 } else { 1575 tran_clone = NULL; 1576 ASSERT(tran->tran_sd == NULL); 1577 } 1578 } 1579 1580 /* establish scsi_address pointer to the HBA's tran structure */ 1581 sd->sd_address.a_hba_tran = tran; 1582 1583 /* 1584 * This is a grotty hack that allows direct-access (non-scsa) drivers 1585 * (like chs, ata, and mlx which all make cmdk children) to put its 1586 * own vector in the 'a_hba_tran' field. When all the drivers that do 1587 * this are fixed, please remove this hack. 1588 * 1589 * NOTE: This hack is also shows up in the DEVP_TO_TRAN implementation 1590 * in scsi_confsubr.c. 1591 */ 1592 sd->sd_tran_safe = tran; 1593 1594 /* Establish the @addr name of the child. */ 1595 *addr = '\0'; 1596 if (scsi_hba_name_child(child, addr, SCSI_MAXNAMELEN) != DDI_SUCCESS) { 1597 /* 1598 * Some driver.conf files add bogus target properties (relative 1599 * to their nexus representation of target) to their stub 1600 * nodes, causing the check above to not filter them. 1601 */ 1602 SCSI_HBA_LOG((_LOG(3), NULL, child, 1603 "init failed: scsi_busctl_ua call")); 1604 err = DDI_NOT_WELL_FORMED; 1605 goto failure; 1606 } 1607 if (*addr == '\0') { 1608 SCSI_HBA_LOG((_LOG(2), NULL, child, "init failed: ua")); 1609 ndi_devi_set_hidden(child); 1610 err = DDI_NOT_WELL_FORMED; 1611 goto failure; 1612 } 1613 1614 /* set the node @addr string */ 1615 ddi_set_name_addr(child, addr); 1616 1617 /* prevent sibling duplicates */ 1618 dup = ndi_devi_find(self, ddi_node_name(child), addr); 1619 if (dup && (dup != child)) { 1620 SCSI_HBA_LOG((_LOG(4), NULL, child, 1621 "init failed: detected duplicate %p", (void *)dup)); 1622 goto failure; 1623 } 1624 1625 /* call HBA's target init entry point if it exists */ 1626 if (tran->tran_tgt_init != NULL) { 1627 SCSI_HBA_LOG((_LOG(4), NULL, child, "init tran_tgt_init")); 1628 if ((*tran->tran_tgt_init) 1629 (self, child, tran, sd) != DDI_SUCCESS) { 1630 SCSI_HBA_LOG((_LOG(2), NULL, child, 1631 "init failed: tran_tgt_init failed")); 1632 goto failure; 1633 } 1634 } 1635 1636 SCSI_HBA_LOG((_LOG(3), NULL, child, "init successful")); 1637 return (DDI_SUCCESS); 1638 1639 failure: 1640 if (tran_clone) 1641 kmem_free(tran_clone, sizeof (scsi_hba_tran_t)); 1642 mutex_destroy(&sd->sd_mutex); 1643 kmem_free(sd, sizeof (*sd)); 1644 ddi_set_driver_private(child, NULL); 1645 ddi_set_name_addr(child, NULL); 1646 1647 return (err); /* remove the node */ 1648 } 1649 1650 static int 1651 scsi_busctl_uninitchild(dev_info_t *child) 1652 { 1653 dev_info_t *self = ddi_get_parent(child); 1654 scsi_hba_tran_t *tran = ddi_get_driver_private(self); 1655 struct scsi_device *sd = ddi_get_driver_private(child); 1656 scsi_hba_tran_t *tran_clone; 1657 1658 ASSERT(DEVI_BUSY_OWNED(self)); 1659 1660 ASSERT(tran && sd); 1661 if ((tran == NULL) || (sd == NULL)) 1662 return (DDI_FAILURE); 1663 1664 1665 SCSI_HBA_LOG((_LOG(3), NULL, child, "uninit begin")); 1666 1667 if (tran->tran_hba_flags & SCSI_HBA_TRAN_CLONE) { 1668 tran_clone = sd->sd_address.a_hba_tran; 1669 1670 /* ... grotty hack, involving sd_tran_safe, continued. */ 1671 if (tran_clone != sd->sd_tran_safe) { 1672 tran_clone = sd->sd_tran_safe; 1673 #ifdef DEBUG 1674 /* 1675 * Complain so things get fixed and hack can, at 1676 * some point in time, be removed. 1677 */ 1678 SCSI_HBA_LOG((_LOG(WARN), self, NULL, 1679 "'%s' is corrupting a_hba_tran", sd->sd_dev ? 1680 ddi_driver_name(sd->sd_dev) : "unknown_driver")); 1681 #endif /* DEBUG */ 1682 } 1683 1684 ASSERT(tran_clone->tran_hba_flags & SCSI_HBA_TRAN_CLONE); 1685 ASSERT(tran_clone->tran_sd == sd); 1686 tran = tran_clone; 1687 } else { 1688 tran_clone = NULL; 1689 ASSERT(tran->tran_sd == NULL); 1690 } 1691 1692 /* 1693 * To simplify host adapter drivers we guarantee that multiple 1694 * tran_tgt_init(9E) calls of the same unit address are never 1695 * active at the same time. 1696 */ 1697 if (tran->tran_tgt_free) 1698 (*tran->tran_tgt_free) (self, child, tran, sd); 1699 1700 /* 1701 * If a inquiry data is still allocated (by scsi_probe()) we 1702 * free the allocation here. This keeps scsi_inq valid for the 1703 * same duration as the corresponding inquiry properties. It 1704 * also allows a tran_tgt_init() implementation that establishes 1705 * sd_inq (common/io/dktp/controller/ata/ata_disk.c) to deal 1706 * with deallocation in its tran_tgt_free (setting sd_inq back 1707 * to NULL) without upsetting the framework. 1708 */ 1709 if (sd->sd_inq) { 1710 kmem_free(sd->sd_inq, SUN_INQSIZE); 1711 sd->sd_inq = (struct scsi_inquiry *)NULL; 1712 } 1713 1714 mutex_destroy(&sd->sd_mutex); 1715 if (tran_clone) 1716 kmem_free(tran_clone, sizeof (scsi_hba_tran_t)); 1717 kmem_free(sd, sizeof (*sd)); 1718 1719 ddi_set_driver_private(child, NULL); 1720 SCSI_HBA_LOG((_LOG(3), NULL, child, "uninit complete")); 1721 ddi_set_name_addr(child, NULL); 1722 return (DDI_SUCCESS); 1723 } 1724 1725 static int 1726 iport_busctl_reportdev(dev_info_t *child) 1727 { 1728 dev_info_t *self = ddi_get_parent(child); 1729 char *iport; 1730 1731 1732 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child, 1733 DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, 1734 "scsi-iport", &iport) != DDI_SUCCESS) 1735 return (DDI_FAILURE); 1736 1737 SCSI_HBA_LOG((_LOG_NF(CONT), "?%s%d at %s%d: iport %s\n", 1738 ddi_driver_name(child), ddi_get_instance(child), 1739 ddi_driver_name(self), ddi_get_instance(self), 1740 iport)); 1741 1742 ddi_prop_free(iport); 1743 return (DDI_SUCCESS); 1744 } 1745 1746 /* uninitchild SCSA iport 'child' node */ 1747 static int 1748 iport_busctl_uninitchild(dev_info_t *child) 1749 { 1750 ddi_set_name_addr(child, NULL); 1751 return (DDI_SUCCESS); 1752 } 1753 1754 /* initchild SCSA iport 'child' node */ 1755 static int 1756 iport_busctl_initchild(dev_info_t *child) 1757 { 1758 dev_info_t *self = ddi_get_parent(child); 1759 dev_info_t *dup = NULL; 1760 char addr[SCSI_MAXNAMELEN]; 1761 char *iport; 1762 1763 1764 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child, 1765 DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, 1766 "scsi-iport", &iport) != DDI_SUCCESS) { 1767 return (DDI_NOT_WELL_FORMED); 1768 } 1769 1770 (void) snprintf(addr, SCSI_MAXNAMELEN, "%s", iport); 1771 ddi_prop_free(iport); 1772 1773 1774 /* set the node @addr string */ 1775 ddi_set_name_addr(child, addr); 1776 1777 /* Prevent duplicate nodes. */ 1778 dup = ndi_devi_find(self, ddi_node_name(child), addr); 1779 if (dup && (dup != child)) { 1780 ddi_set_name_addr(child, NULL); 1781 return (DDI_FAILURE); 1782 } 1783 1784 return (DDI_SUCCESS); 1785 } 1786 1787 /* Uninitialize scsi_device flavor of transport on SCSA iport 'child' node. */ 1788 static void 1789 iport_postdetach_tran_scsi_device(dev_info_t *child) 1790 { 1791 scsi_hba_tran_t *tran; 1792 1793 tran = ndi_flavorv_get(child, SCSA_FLAVOR_SCSI_DEVICE); 1794 if (tran == NULL) 1795 return; 1796 1797 scsa_tran_teardown(child, tran); 1798 scsa_nexus_teardown(child, tran); 1799 1800 ndi_flavorv_set(child, SCSA_FLAVOR_SCSI_DEVICE, NULL); 1801 scsi_hba_tran_free(tran); 1802 } 1803 1804 /* 1805 * Initialize scsi_device flavor of transport on SCSA iport 'child' node. 1806 * 1807 * NOTE: Given our past history with SCSI_HBA_TRAN_CLONE (structure-copy tran 1808 * per scsi_device), using structure-copy of tran at the iport level should 1809 * not be a problem (the most risky thing is likely tran_hba_dip). 1810 */ 1811 static void 1812 iport_preattach_tran_scsi_device(dev_info_t *child) 1813 { 1814 dev_info_t *hba = ddi_get_parent(child); 1815 scsi_hba_tran_t *htran; 1816 scsi_hba_tran_t *tran; 1817 1818 /* parent HBA node scsi_device tran is required */ 1819 htran = ndi_flavorv_get(hba, SCSA_FLAVOR_SCSI_DEVICE); 1820 ASSERT(htran != NULL); 1821 if (htran == NULL) 1822 return; 1823 1824 /* Allocate iport child's scsi_device transport vector */ 1825 tran = scsi_hba_tran_alloc(child, SCSI_HBA_CANSLEEP); 1826 if (tran == NULL) 1827 return; 1828 1829 /* Structure-copy scsi_device transport of HBA to iport. */ 1830 *tran = *htran; 1831 1832 /* 1833 * Reset scsi_device transport fields not shared with the 1834 * parent, and not established below. 1835 */ 1836 tran->tran_open_flag = 0; 1837 tran->tran_hba_private = NULL; 1838 tran->tran_iport_dip = child; 1839 1840 /* Clear SCSI_HBA_SCSA flags (except TA) */ 1841 tran->tran_hba_flags &= ~SCSI_HBA_SCSA_FM; /* clear parent state */ 1842 tran->tran_hba_flags |= SCSI_HBA_SCSA_TA; 1843 tran->tran_hba_flags &= ~SCSI_HBA_HBA; /* never HBA */ 1844 1845 /* Establish flavor of transport (and ddi_get_driver_private()) */ 1846 ndi_flavorv_set(child, SCSA_FLAVOR_SCSI_DEVICE, tran); 1847 1848 /* Setup iport node */ 1849 if ((scsa_nexus_setup(child, tran) != DDI_SUCCESS) || 1850 (scsa_tran_setup(child, tran) != DDI_SUCCESS)) { 1851 iport_postdetach_tran_scsi_device(child); 1852 } 1853 } 1854 1855 /* Uninitialize smp_device flavor of transport on SCSA iport 'child' node. */ 1856 static void 1857 iport_postdetach_tran_smp_device(dev_info_t *child) 1858 { 1859 sas_hba_tran_t *tran; 1860 1861 tran = ndi_flavorv_get(child, SCSA_FLAVOR_SMP); 1862 if (tran == NULL) 1863 return; 1864 1865 ndi_flavorv_set(child, SCSA_FLAVOR_SMP, NULL); 1866 sas_hba_tran_free(tran); 1867 } 1868 1869 /* Initialize smp_device flavor of transport on SCSA iport 'child' node. */ 1870 static void 1871 iport_preattach_tran_smp_device(dev_info_t *child) 1872 { 1873 dev_info_t *hba = ddi_get_parent(child); 1874 sas_hba_tran_t *htran; 1875 sas_hba_tran_t *tran; 1876 1877 /* parent HBA node smp_device tran is optional */ 1878 htran = ndi_flavorv_get(hba, SCSA_FLAVOR_SMP); 1879 if (htran == NULL) { 1880 ndi_flavorv_set(child, SCSA_FLAVOR_SMP, NULL); 1881 return; 1882 } 1883 1884 /* Allocate iport child's smp_device transport vector */ 1885 tran = sas_hba_tran_alloc(child, 0); 1886 1887 /* Structure-copy smp_device transport of HBA to iport. */ 1888 *tran = *htran; 1889 1890 /* Establish flavor of transport */ 1891 ndi_flavorv_set(child, SCSA_FLAVOR_SMP, tran); 1892 } 1893 1894 1895 /* 1896 * Generic bus_ctl operations for SCSI HBA's, 1897 * hiding the busctl interface from the HBA. 1898 */ 1899 /*ARGSUSED*/ 1900 static int 1901 scsi_hba_bus_ctl( 1902 dev_info_t *self, 1903 dev_info_t *child, 1904 ddi_ctl_enum_t op, 1905 void *arg, 1906 void *result) 1907 { 1908 int child_flavor = 0; 1909 int val; 1910 ddi_dma_attr_t *attr; 1911 scsi_hba_tran_t *tran; 1912 struct attachspec *as; 1913 struct detachspec *ds; 1914 1915 /* For some ops, child is 'arg'. */ 1916 if ((op == DDI_CTLOPS_INITCHILD) || (op == DDI_CTLOPS_UNINITCHILD)) 1917 child = (dev_info_t *)arg; 1918 1919 /* Determine the flavor of the child: smp .vs. scsi */ 1920 child_flavor = ndi_flavor_get(child); 1921 1922 switch (op) { 1923 case DDI_CTLOPS_INITCHILD: 1924 switch (child_flavor) { 1925 case SCSA_FLAVOR_IPORT: 1926 return (iport_busctl_initchild(child)); 1927 case SCSA_FLAVOR_SMP: 1928 return (smp_busctl_initchild(child)); 1929 default: 1930 return (scsi_busctl_initchild(child)); 1931 } 1932 case DDI_CTLOPS_UNINITCHILD: 1933 switch (child_flavor) { 1934 case SCSA_FLAVOR_IPORT: 1935 return (iport_busctl_uninitchild(child)); 1936 case SCSA_FLAVOR_SMP: 1937 return (smp_busctl_uninitchild(child)); 1938 default: 1939 return (scsi_busctl_uninitchild(child)); 1940 } 1941 case DDI_CTLOPS_REPORTDEV: 1942 switch (child_flavor) { 1943 case SCSA_FLAVOR_IPORT: 1944 return (iport_busctl_reportdev(child)); 1945 case SCSA_FLAVOR_SMP: 1946 return (smp_busctl_reportdev(child)); 1947 default: 1948 return (scsi_busctl_reportdev(child)); 1949 } 1950 case DDI_CTLOPS_ATTACH: 1951 as = (struct attachspec *)arg; 1952 1953 if (child_flavor != SCSA_FLAVOR_IPORT) 1954 return (DDI_SUCCESS); 1955 1956 /* iport processing */ 1957 if (as->when == DDI_PRE) { 1958 /* setup pre attach(9E) */ 1959 iport_preattach_tran_scsi_device(child); 1960 iport_preattach_tran_smp_device(child); 1961 } else if ((as->when == DDI_POST) && 1962 (as->result != DDI_SUCCESS)) { 1963 /* cleanup if attach(9E) failed */ 1964 iport_postdetach_tran_scsi_device(child); 1965 iport_postdetach_tran_smp_device(child); 1966 } 1967 return (DDI_SUCCESS); 1968 case DDI_CTLOPS_DETACH: 1969 ds = (struct detachspec *)arg; 1970 1971 if (child_flavor != SCSA_FLAVOR_IPORT) 1972 return (DDI_SUCCESS); 1973 1974 /* iport processing */ 1975 if ((ds->when == DDI_POST) && 1976 (ds->result == DDI_SUCCESS)) { 1977 /* cleanup if detach(9E) was successful */ 1978 iport_postdetach_tran_scsi_device(child); 1979 iport_postdetach_tran_smp_device(child); 1980 } 1981 return (DDI_SUCCESS); 1982 case DDI_CTLOPS_IOMIN: 1983 tran = ddi_get_driver_private(self); 1984 ASSERT(tran); 1985 if (tran == NULL) 1986 return (DDI_FAILURE); 1987 1988 /* 1989 * The 'arg' value of nonzero indicates 'streaming' 1990 * mode. If in streaming mode, pick the largest 1991 * of our burstsizes available and say that that 1992 * is our minimum value (modulo what minxfer is). 1993 */ 1994 attr = &tran->tran_dma_attr; 1995 val = *((int *)result); 1996 val = maxbit(val, attr->dma_attr_minxfer); 1997 *((int *)result) = maxbit(val, ((intptr_t)arg ? 1998 (1<<ddi_ffs(attr->dma_attr_burstsizes)-1) : 1999 (1<<(ddi_fls(attr->dma_attr_burstsizes)-1)))); 2000 2001 return (ddi_ctlops(self, child, op, arg, result)); 2002 2003 case DDI_CTLOPS_SIDDEV: 2004 return (ndi_dev_is_persistent_node(child) ? 2005 DDI_SUCCESS : DDI_FAILURE); 2006 2007 /* XXX these should be handled */ 2008 case DDI_CTLOPS_POWER: 2009 return (DDI_SUCCESS); 2010 2011 /* 2012 * These ops correspond to functions that "shouldn't" be called 2013 * by a SCSI target driver. So we whine when we're called. 2014 */ 2015 case DDI_CTLOPS_DMAPMAPC: 2016 case DDI_CTLOPS_REPORTINT: 2017 case DDI_CTLOPS_REGSIZE: 2018 case DDI_CTLOPS_NREGS: 2019 case DDI_CTLOPS_SLAVEONLY: 2020 case DDI_CTLOPS_AFFINITY: 2021 case DDI_CTLOPS_POKE: 2022 case DDI_CTLOPS_PEEK: 2023 SCSI_HBA_LOG((_LOG(WARN), self, NULL, "invalid op (%d)", op)); 2024 return (DDI_FAILURE); 2025 2026 /* Everything else we pass up */ 2027 case DDI_CTLOPS_PTOB: 2028 case DDI_CTLOPS_BTOP: 2029 case DDI_CTLOPS_BTOPR: 2030 case DDI_CTLOPS_DVMAPAGESIZE: 2031 default: 2032 return (ddi_ctlops(self, child, op, arg, result)); 2033 } 2034 } 2035 2036 /* 2037 * Private wrapper for scsi_pkt's allocated via scsi_hba_pkt_alloc() 2038 */ 2039 struct scsi_pkt_wrapper { 2040 struct scsi_pkt scsi_pkt; 2041 int pkt_wrapper_magic; 2042 int pkt_wrapper_len; 2043 }; 2044 2045 #if !defined(lint) 2046 _NOTE(SCHEME_PROTECTS_DATA("unique per thread", scsi_pkt_wrapper)) 2047 _NOTE(SCHEME_PROTECTS_DATA("Unshared Data", dev_ops)) 2048 #endif 2049 2050 /* 2051 * Called by an HBA to allocate a scsi_pkt 2052 */ 2053 /*ARGSUSED*/ 2054 struct scsi_pkt * 2055 scsi_hba_pkt_alloc( 2056 dev_info_t *dip, 2057 struct scsi_address *ap, 2058 int cmdlen, 2059 int statuslen, 2060 int tgtlen, 2061 int hbalen, 2062 int (*callback)(caddr_t arg), 2063 caddr_t arg) 2064 { 2065 struct scsi_pkt *pkt; 2066 struct scsi_pkt_wrapper *hba_pkt; 2067 caddr_t p; 2068 int acmdlen, astatuslen, atgtlen, ahbalen; 2069 int pktlen; 2070 2071 /* Sanity check */ 2072 if (callback != SLEEP_FUNC && callback != NULL_FUNC) 2073 SCSI_HBA_LOG((_LOG(WARN), dip, NULL, 2074 "callback must be SLEEP_FUNC or NULL_FUNC")); 2075 2076 /* 2077 * Round up so everything gets allocated on long-word boundaries 2078 */ 2079 acmdlen = ROUNDUP(cmdlen); 2080 astatuslen = ROUNDUP(statuslen); 2081 atgtlen = ROUNDUP(tgtlen); 2082 ahbalen = ROUNDUP(hbalen); 2083 pktlen = sizeof (struct scsi_pkt_wrapper) + 2084 acmdlen + astatuslen + atgtlen + ahbalen; 2085 2086 hba_pkt = kmem_zalloc(pktlen, 2087 (callback == SLEEP_FUNC) ? KM_SLEEP : KM_NOSLEEP); 2088 if (hba_pkt == NULL) { 2089 ASSERT(callback == NULL_FUNC); 2090 return (NULL); 2091 } 2092 2093 /* 2094 * Set up our private info on this pkt 2095 */ 2096 hba_pkt->pkt_wrapper_len = pktlen; 2097 hba_pkt->pkt_wrapper_magic = PKT_WRAPPER_MAGIC; /* alloced correctly */ 2098 pkt = &hba_pkt->scsi_pkt; 2099 2100 /* 2101 * Set up pointers to private data areas, cdb, and status. 2102 */ 2103 p = (caddr_t)(hba_pkt + 1); 2104 if (hbalen > 0) { 2105 pkt->pkt_ha_private = (opaque_t)p; 2106 p += ahbalen; 2107 } 2108 if (tgtlen > 0) { 2109 pkt->pkt_private = (opaque_t)p; 2110 p += atgtlen; 2111 } 2112 if (statuslen > 0) { 2113 pkt->pkt_scbp = (uchar_t *)p; 2114 p += astatuslen; 2115 } 2116 if (cmdlen > 0) { 2117 pkt->pkt_cdbp = (uchar_t *)p; 2118 } 2119 2120 /* 2121 * Initialize the pkt's scsi_address 2122 */ 2123 pkt->pkt_address = *ap; 2124 2125 /* 2126 * NB: It may not be safe for drivers, esp target drivers, to depend 2127 * on the following fields being set until all the scsi_pkt 2128 * allocation violations discussed in scsi_pkt.h are all resolved. 2129 */ 2130 pkt->pkt_cdblen = cmdlen; 2131 pkt->pkt_tgtlen = tgtlen; 2132 pkt->pkt_scblen = statuslen; 2133 2134 return (pkt); 2135 } 2136 2137 /* 2138 * Called by an HBA to free a scsi_pkt 2139 */ 2140 /*ARGSUSED*/ 2141 void 2142 scsi_hba_pkt_free( 2143 struct scsi_address *ap, 2144 struct scsi_pkt *pkt) 2145 { 2146 kmem_free(pkt, ((struct scsi_pkt_wrapper *)pkt)->pkt_wrapper_len); 2147 } 2148 2149 /* 2150 * Return 1 if the scsi_pkt used a proper allocator. 2151 * 2152 * The DDI does not allow a driver to allocate it's own scsi_pkt(9S), a 2153 * driver should not have *any* compiled in dependencies on "sizeof (struct 2154 * scsi_pkt)". While this has been the case for many years, a number of 2155 * drivers have still not been fixed. This function can be used to detect 2156 * improperly allocated scsi_pkt structures, and produce messages identifying 2157 * drivers that need to be fixed. 2158 * 2159 * While drivers in violation are being fixed, this function can also 2160 * be used by the framework to detect packets that violated allocation 2161 * rules. 2162 * 2163 * NB: It is possible, but very unlikely, for this code to return a false 2164 * positive (finding correct magic, but for wrong reasons). Careful 2165 * consideration is needed for callers using this interface to condition 2166 * access to newer scsi_pkt fields (those after pkt_reason). 2167 * 2168 * NB: As an aid to minimizing the amount of work involved in 'fixing' legacy 2169 * drivers that violate scsi_*(9S) allocation rules, private 2170 * scsi_pkt_size()/scsi_size_clean() functions are available (see their 2171 * implementation for details). 2172 * 2173 * *** Non-legacy use of scsi_pkt_size() is discouraged. *** 2174 * 2175 * NB: When supporting broken HBA drivers is not longer a concern, this 2176 * code should be removed. 2177 */ 2178 int 2179 scsi_pkt_allocated_correctly(struct scsi_pkt *pkt) 2180 { 2181 struct scsi_pkt_wrapper *hba_pkt = (struct scsi_pkt_wrapper *)pkt; 2182 int magic; 2183 major_t major; 2184 #ifdef DEBUG 2185 int *pspwm, *pspcwm; 2186 2187 /* 2188 * We are getting scsi packets from two 'correct' wrapper schemes, 2189 * make sure we are looking at the same place in both to detect 2190 * proper allocation. 2191 */ 2192 pspwm = &((struct scsi_pkt_wrapper *)0)->pkt_wrapper_magic; 2193 pspcwm = &((struct scsi_pkt_cache_wrapper *)0)->pcw_magic; 2194 ASSERT(pspwm == pspcwm); 2195 #endif /* DEBUG */ 2196 2197 2198 /* 2199 * Check to see if driver is scsi_size_clean(), assume it 2200 * is using the scsi_pkt_size() interface everywhere it needs to 2201 * if the driver indicates it is scsi_size_clean(). 2202 */ 2203 major = ddi_driver_major(P_TO_TRAN(pkt)->tran_hba_dip); 2204 if (devnamesp[major].dn_flags & DN_SCSI_SIZE_CLEAN) 2205 return (1); /* ok */ 2206 2207 /* 2208 * Special case crossing a page boundary. If the scsi_pkt was not 2209 * allocated correctly, then across a page boundary we have a 2210 * fault hazard. 2211 */ 2212 if ((((uintptr_t)(&hba_pkt->scsi_pkt)) & MMU_PAGEMASK) == 2213 (((uintptr_t)(&hba_pkt->pkt_wrapper_magic)) & MMU_PAGEMASK)) { 2214 /* fastpath, no cross-page hazard */ 2215 magic = hba_pkt->pkt_wrapper_magic; 2216 } else { 2217 /* add protection for cross-page hazard */ 2218 if (ddi_peek32((dev_info_t *)NULL, 2219 &hba_pkt->pkt_wrapper_magic, &magic) == DDI_FAILURE) { 2220 return (0); /* violation */ 2221 } 2222 } 2223 2224 /* properly allocated packet always has correct magic */ 2225 return ((magic == PKT_WRAPPER_MAGIC) ? 1 : 0); 2226 } 2227 2228 /* 2229 * Private interfaces to simplify conversion of legacy drivers so they don't 2230 * depend on scsi_*(9S) size. Instead of using these private interface, HBA 2231 * drivers should use DDI sanctioned allocation methods: 2232 * 2233 * scsi_pkt Use scsi_hba_pkt_alloc(9F), or implement 2234 * tran_setup_pkt(9E). 2235 * 2236 * scsi_device You are doing something strange/special, a scsi_device 2237 * structure should only be allocated by scsi_hba.c 2238 * initchild code or scsi_vhci.c code. 2239 * 2240 * scsi_hba_tran Use scsi_hba_tran_alloc(9F). 2241 */ 2242 size_t 2243 scsi_pkt_size() 2244 { 2245 return (sizeof (struct scsi_pkt)); 2246 } 2247 2248 size_t 2249 scsi_hba_tran_size() 2250 { 2251 return (sizeof (scsi_hba_tran_t)); 2252 } 2253 2254 size_t 2255 scsi_device_size() 2256 { 2257 return (sizeof (struct scsi_device)); 2258 } 2259 2260 /* 2261 * Legacy compliance to scsi_pkt(9S) allocation rules through use of 2262 * scsi_pkt_size() is detected by the 'scsi-size-clean' driver.conf property 2263 * or an HBA driver calling to scsi_size_clean() from attach(9E). A driver 2264 * developer should only indicate that a legacy driver is clean after using 2265 * SCSI_SIZE_CLEAN_VERIFY to ensure compliance (see scsi_pkt.h). 2266 */ 2267 void 2268 scsi_size_clean(dev_info_t *dip) 2269 { 2270 major_t major; 2271 struct devnames *dnp; 2272 2273 ASSERT(dip); 2274 major = ddi_driver_major(dip); 2275 ASSERT(major < devcnt); 2276 if (major >= devcnt) { 2277 SCSI_HBA_LOG((_LOG(WARN), dip, NULL, 2278 "scsi_pkt_size: bogus major: %d", major)); 2279 return; 2280 } 2281 2282 /* Set DN_SCSI_SIZE_CLEAN flag in dn_flags. */ 2283 dnp = &devnamesp[major]; 2284 if ((dnp->dn_flags & DN_SCSI_SIZE_CLEAN) == 0) { 2285 LOCK_DEV_OPS(&dnp->dn_lock); 2286 dnp->dn_flags |= DN_SCSI_SIZE_CLEAN; 2287 UNLOCK_DEV_OPS(&dnp->dn_lock); 2288 } 2289 } 2290 2291 2292 /* 2293 * Called by an HBA to map strings to capability indices 2294 */ 2295 int 2296 scsi_hba_lookup_capstr( 2297 char *capstr) 2298 { 2299 /* 2300 * Capability strings: only add entries to mask the legacy 2301 * '_' vs. '-' misery. All new capabilities should use '-', 2302 * and be captured be added to SCSI_CAP_ASCII. 2303 */ 2304 static struct cap_strings { 2305 char *cap_string; 2306 int cap_index; 2307 } cap_strings[] = { 2308 { "dma_max", SCSI_CAP_DMA_MAX }, 2309 { "msg_out", SCSI_CAP_MSG_OUT }, 2310 { "wide_xfer", SCSI_CAP_WIDE_XFER }, 2311 { NULL, 0 } 2312 }; 2313 static char *cap_ascii[] = SCSI_CAP_ASCII; 2314 char **cap; 2315 int i; 2316 struct cap_strings *cp; 2317 2318 for (cap = cap_ascii, i = 0; *cap != NULL; cap++, i++) 2319 if (strcmp(*cap, capstr) == 0) 2320 return (i); 2321 2322 for (cp = cap_strings; cp->cap_string != NULL; cp++) 2323 if (strcmp(cp->cap_string, capstr) == 0) 2324 return (cp->cap_index); 2325 2326 return (-1); 2327 } 2328 2329 /* 2330 * Called by an HBA to determine if the system is in 'panic' state. 2331 */ 2332 int 2333 scsi_hba_in_panic() 2334 { 2335 return (panicstr != NULL); 2336 } 2337 2338 /* 2339 * If a SCSI target driver attempts to mmap memory, 2340 * the buck stops here. 2341 */ 2342 /*ARGSUSED*/ 2343 static int 2344 scsi_hba_map_fault( 2345 dev_info_t *dip, 2346 dev_info_t *child, 2347 struct hat *hat, 2348 struct seg *seg, 2349 caddr_t addr, 2350 struct devpage *dp, 2351 pfn_t pfn, 2352 uint_t prot, 2353 uint_t lock) 2354 { 2355 return (DDI_FAILURE); 2356 } 2357 2358 static int 2359 scsi_hba_get_eventcookie( 2360 dev_info_t *self, 2361 dev_info_t *child, 2362 char *name, 2363 ddi_eventcookie_t *eventp) 2364 { 2365 scsi_hba_tran_t *tran; 2366 2367 tran = ddi_get_driver_private(self); 2368 if (tran->tran_get_eventcookie && 2369 ((*tran->tran_get_eventcookie)(self, 2370 child, name, eventp) == DDI_SUCCESS)) { 2371 return (DDI_SUCCESS); 2372 } 2373 2374 return (ndi_busop_get_eventcookie(self, child, name, eventp)); 2375 } 2376 2377 static int 2378 scsi_hba_add_eventcall( 2379 dev_info_t *self, 2380 dev_info_t *child, 2381 ddi_eventcookie_t event, 2382 void (*callback)( 2383 dev_info_t *self, 2384 ddi_eventcookie_t event, 2385 void *arg, 2386 void *bus_impldata), 2387 void *arg, 2388 ddi_callback_id_t *cb_id) 2389 { 2390 scsi_hba_tran_t *tran; 2391 2392 tran = ddi_get_driver_private(self); 2393 if (tran->tran_add_eventcall && 2394 ((*tran->tran_add_eventcall)(self, child, 2395 event, callback, arg, cb_id) == DDI_SUCCESS)) { 2396 return (DDI_SUCCESS); 2397 } 2398 2399 return (DDI_FAILURE); 2400 } 2401 2402 static int 2403 scsi_hba_remove_eventcall(dev_info_t *self, ddi_callback_id_t cb_id) 2404 { 2405 scsi_hba_tran_t *tran; 2406 ASSERT(cb_id); 2407 2408 tran = ddi_get_driver_private(self); 2409 if (tran->tran_remove_eventcall && 2410 ((*tran->tran_remove_eventcall)( 2411 self, cb_id) == DDI_SUCCESS)) { 2412 return (DDI_SUCCESS); 2413 } 2414 2415 return (DDI_FAILURE); 2416 } 2417 2418 static int 2419 scsi_hba_post_event( 2420 dev_info_t *self, 2421 dev_info_t *child, 2422 ddi_eventcookie_t event, 2423 void *bus_impldata) 2424 { 2425 scsi_hba_tran_t *tran; 2426 2427 tran = ddi_get_driver_private(self); 2428 if (tran->tran_post_event && 2429 ((*tran->tran_post_event)(self, 2430 child, event, bus_impldata) == DDI_SUCCESS)) { 2431 return (DDI_SUCCESS); 2432 } 2433 2434 return (DDI_FAILURE); 2435 } 2436 2437 /* 2438 * Default getinfo(9e) for scsi_hba 2439 */ 2440 /* ARGSUSED */ 2441 static int 2442 scsi_hba_info(dev_info_t *self, ddi_info_cmd_t infocmd, void *arg, 2443 void **result) 2444 { 2445 int error = DDI_SUCCESS; 2446 2447 switch (infocmd) { 2448 case DDI_INFO_DEVT2INSTANCE: 2449 *result = (void *)(intptr_t)(MINOR2INST(getminor((dev_t)arg))); 2450 break; 2451 default: 2452 error = DDI_FAILURE; 2453 } 2454 return (error); 2455 } 2456 2457 /* 2458 * Default open and close routine for scsi_hba 2459 */ 2460 /* ARGSUSED */ 2461 int 2462 scsi_hba_open(dev_t *devp, int flags, int otyp, cred_t *credp) 2463 { 2464 dev_info_t *self; 2465 scsi_hba_tran_t *tran; 2466 int rv = 0; 2467 2468 if (otyp != OTYP_CHR) 2469 return (EINVAL); 2470 2471 if ((self = e_ddi_hold_devi_by_dev(*devp, 0)) == NULL) 2472 return (ENXIO); 2473 2474 tran = ddi_get_driver_private(self); 2475 if (tran == NULL) { 2476 ddi_release_devi(self); 2477 return (ENXIO); 2478 } 2479 2480 /* 2481 * tran_open_flag bit field: 2482 * 0: closed 2483 * 1: shared open by minor at bit position 2484 * 1 at 31st bit: exclusive open 2485 */ 2486 mutex_enter(&(tran->tran_open_lock)); 2487 if (flags & FEXCL) { 2488 if (tran->tran_open_flag != 0) { 2489 rv = EBUSY; /* already open */ 2490 } else { 2491 tran->tran_open_flag = TRAN_OPEN_EXCL; 2492 } 2493 } else { 2494 if (tran->tran_open_flag == TRAN_OPEN_EXCL) { 2495 rv = EBUSY; /* already excl. open */ 2496 } else { 2497 int minor = getminor(*devp) & TRAN_MINOR_MASK; 2498 tran->tran_open_flag |= (1 << minor); 2499 /* 2500 * Ensure that the last framework reserved minor 2501 * is unused. Otherwise, the exclusive open 2502 * mechanism may break. 2503 */ 2504 ASSERT(minor != 31); 2505 } 2506 } 2507 mutex_exit(&(tran->tran_open_lock)); 2508 2509 ddi_release_devi(self); 2510 return (rv); 2511 } 2512 2513 /* ARGSUSED */ 2514 int 2515 scsi_hba_close(dev_t dev, int flag, int otyp, cred_t *credp) 2516 { 2517 dev_info_t *self; 2518 scsi_hba_tran_t *tran; 2519 2520 if (otyp != OTYP_CHR) 2521 return (EINVAL); 2522 2523 if ((self = e_ddi_hold_devi_by_dev(dev, 0)) == NULL) 2524 return (ENXIO); 2525 2526 tran = ddi_get_driver_private(self); 2527 if (tran == NULL) { 2528 ddi_release_devi(self); 2529 return (ENXIO); 2530 } 2531 2532 mutex_enter(&(tran->tran_open_lock)); 2533 if (tran->tran_open_flag == TRAN_OPEN_EXCL) { 2534 tran->tran_open_flag = 0; 2535 } else { 2536 int minor = getminor(dev) & TRAN_MINOR_MASK; 2537 tran->tran_open_flag &= ~(1 << minor); 2538 } 2539 mutex_exit(&(tran->tran_open_lock)); 2540 2541 ddi_release_devi(self); 2542 return (0); 2543 } 2544 2545 /* 2546 * standard ioctl commands for SCSI hotplugging 2547 */ 2548 /* ARGSUSED */ 2549 int 2550 scsi_hba_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, 2551 int *rvalp) 2552 { 2553 dev_info_t *self; 2554 struct devctl_iocdata *dcp = NULL; 2555 dev_info_t *child = NULL; 2556 struct scsi_device *sd; 2557 scsi_hba_tran_t *tran; 2558 uint_t bus_state; 2559 int rv = 0; 2560 int circ; 2561 2562 if ((self = e_ddi_hold_devi_by_dev(dev, 0)) == NULL) { 2563 rv = ENXIO; 2564 goto out; 2565 } 2566 2567 if ((tran = ddi_get_driver_private(self)) == NULL) { 2568 rv = ENXIO; 2569 goto out; 2570 } 2571 2572 /* Ioctls for which the generic implementation suffices. */ 2573 switch (cmd) { 2574 case DEVCTL_DEVICE_GETSTATE: 2575 case DEVCTL_DEVICE_ONLINE: 2576 case DEVCTL_DEVICE_OFFLINE: 2577 case DEVCTL_DEVICE_REMOVE: 2578 case DEVCTL_BUS_GETSTATE: 2579 rv = ndi_devctl_ioctl(self, cmd, arg, mode, 0); 2580 goto out; 2581 } 2582 2583 /* read devctl ioctl data */ 2584 if (ndi_dc_allochdl((void *)arg, &dcp) != NDI_SUCCESS) { 2585 rv = EFAULT; 2586 goto out; 2587 } 2588 2589 /* Ioctls that require child identification */ 2590 switch (cmd) { 2591 case DEVCTL_DEVICE_RESET: 2592 /* child identification from unit-address */ 2593 if (ndi_dc_getname(dcp) == NULL || 2594 ndi_dc_getaddr(dcp) == NULL) { 2595 rv = EINVAL; 2596 goto out; 2597 } 2598 2599 ndi_devi_enter(self, &circ); 2600 child = ndi_devi_find(self, 2601 ndi_dc_getname(dcp), ndi_dc_getaddr(dcp)); 2602 if (child == NULL) { 2603 ndi_devi_exit(self, circ); 2604 rv = ENXIO; 2605 goto out; 2606 } 2607 ndi_hold_devi(child); 2608 ndi_devi_exit(self, circ); 2609 break; 2610 2611 case DEVCTL_BUS_RESETALL: 2612 /* 2613 * Find a child's scsi_address so we can invoke tran_reset 2614 * below. 2615 * 2616 * XXX If no child exists, one may to able to fake a child. 2617 * This will be a enhancement for the future. 2618 * For now, we fall back to BUS_RESET. 2619 * XXX We sould be looking at node state to get one 2620 * that is initialized... 2621 */ 2622 ndi_devi_enter(self, &circ); 2623 child = ddi_get_child(self); 2624 sd = NULL; 2625 while (child) { 2626 /* XXX verify scsi_device 'flavor' of child */ 2627 if ((sd = ddi_get_driver_private(child)) != NULL) { 2628 ndi_hold_devi(child); 2629 break; 2630 } 2631 child = ddi_get_next_sibling(child); 2632 } 2633 ndi_devi_exit(self, circ); 2634 break; 2635 } 2636 2637 switch (cmd) { 2638 case DEVCTL_DEVICE_RESET: 2639 ASSERT(child); 2640 if (tran->tran_reset == NULL) 2641 rv = ENOTSUP; 2642 else { 2643 sd = ddi_get_driver_private(child); 2644 /* XXX verify scsi_device 'flavor' of child */ 2645 if ((sd == NULL) || 2646 (tran->tran_reset(&sd->sd_address, 2647 RESET_TARGET) != 1)) 2648 rv = EIO; 2649 } 2650 break; 2651 2652 case DEVCTL_BUS_QUIESCE: 2653 if ((ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS) && 2654 (bus_state == BUS_QUIESCED)) 2655 rv = EALREADY; 2656 else if (tran->tran_quiesce == NULL) 2657 rv = ENOTSUP; 2658 else if ((*tran->tran_quiesce)(self) != 0) 2659 rv = EIO; 2660 else 2661 (void) ndi_set_bus_state(self, BUS_QUIESCED); 2662 break; 2663 2664 case DEVCTL_BUS_UNQUIESCE: 2665 if ((ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS) && 2666 (bus_state == BUS_ACTIVE)) 2667 rv = EALREADY; 2668 else if (tran->tran_unquiesce == NULL) 2669 rv = ENOTSUP; 2670 else if ((*tran->tran_unquiesce)(self) != 0) 2671 rv = EIO; 2672 else 2673 (void) ndi_set_bus_state(self, BUS_ACTIVE); 2674 break; 2675 2676 case DEVCTL_BUS_RESET: 2677 if (tran->tran_bus_reset == NULL) 2678 rv = ENOTSUP; 2679 else if ((*tran->tran_bus_reset)(self, RESET_BUS) != 1) 2680 rv = EIO; 2681 break; 2682 2683 case DEVCTL_BUS_RESETALL: 2684 if (tran->tran_reset == NULL) { 2685 rv = ENOTSUP; 2686 } else { 2687 if (sd) { 2688 if ((*tran->tran_reset) 2689 (&sd->sd_address, RESET_ALL) != 1) 2690 rv = EIO; 2691 } else { 2692 if ((tran->tran_bus_reset == NULL) || 2693 ((*tran->tran_bus_reset) 2694 (self, RESET_BUS) != 1)) 2695 rv = EIO; 2696 } 2697 } 2698 break; 2699 2700 case DEVCTL_BUS_CONFIGURE: 2701 if (ndi_devi_config(self, NDI_DEVFS_CLEAN| 2702 NDI_DEVI_PERSIST|NDI_CONFIG_REPROBE) != NDI_SUCCESS) { 2703 rv = EIO; 2704 } 2705 break; 2706 2707 case DEVCTL_BUS_UNCONFIGURE: 2708 if (ndi_devi_unconfig(self, 2709 NDI_DEVI_REMOVE|NDI_DEVFS_CLEAN) != NDI_SUCCESS) { 2710 rv = EBUSY; 2711 } 2712 break; 2713 2714 default: 2715 rv = ENOTTY; 2716 } 2717 2718 out: if (child) 2719 ndi_rele_devi(child); 2720 if (dcp) 2721 ndi_dc_freehdl(dcp); 2722 if (self) 2723 ddi_release_devi(self); 2724 return (rv); 2725 } 2726 2727 /*ARGSUSED*/ 2728 static int 2729 scsi_hba_fm_init_child(dev_info_t *self, dev_info_t *child, int cap, 2730 ddi_iblock_cookie_t *ibc) 2731 { 2732 scsi_hba_tran_t *tran = ddi_get_driver_private(self); 2733 2734 return (tran ? tran->tran_fm_capable : scsi_fm_capable); 2735 } 2736 2737 static int 2738 scsi_hba_bus_power(dev_info_t *self, void *impl_arg, pm_bus_power_op_t op, 2739 void *arg, void *result) 2740 { 2741 scsi_hba_tran_t *tran; 2742 2743 tran = ddi_get_driver_private(self); 2744 if (tran && tran->tran_bus_power) { 2745 return (tran->tran_bus_power(self, impl_arg, 2746 op, arg, result)); 2747 } 2748 2749 return (pm_busop_bus_power(self, impl_arg, op, arg, result)); 2750 } 2751 2752 /* 2753 * Convert between normalized (SCSI-3) LUN format, as described by 2754 * scsi_lun_t, and a normalized lun64_t representation. The normalized 2755 * representation maps in a compatible way to SCSI-2 LUNs. 2756 * 2757 * SCSI-3 LUNs are 64 bits. SCSI-2 LUNs are 3 bits (up to 5 bits in 2758 * some non-compliant implementations). SCSI-3 will pass a (64-bit) 2759 * scsi_lun_t, but we need a representation from which we can for example, 2760 * make device names. For compatibility we represent 64-bit LUN numbers 2761 * in such a way that they appear like they would have under SCSI-2. 2762 * This means that the single level LUN number is in the lowest byte with 2763 * the second, third, and fourth level LUNs represented in successively 2764 * higher bytes. In particular, if (and only if) the first byte of a 64 2765 * bit LUN is zero, denoting "Peripheral Device Addressing Method" and 2766 * "Bus Identifier" zero, then the target implements LUNs compatible in 2767 * spirit with SCSI-2 LUNs (although under SCSI-3 there may be up to 2768 * 256 of them). Under SCSI-3 rules, a target is *required* to use 2769 * this format if it contains 256 or fewer Logical Units, none of which 2770 * are dependent logical units. 2771 * 2772 * These routines have knowledge of the structure and size of a scsi_lun_t. 2773 * 2774 * XXX Should these function be rewritten to take the scsi_lun_t *? 2775 */ 2776 scsi_lun64_t 2777 scsi_lun_to_lun64(scsi_lun_t lun) 2778 { 2779 scsi_lun64_t lun64; 2780 2781 /* check address method and bus identifier */ 2782 if (lun.sl_lun1_msb == 0) { 2783 /* single-level LUN */ 2784 lun64 = lun.sl_lun1_lsb; /* extract the 8-bit LUN */ 2785 2786 /* Ensure rest of LUN is zero, which it is supposed to be */ 2787 if ((lun.sl_lun2_msb == 0) && (lun.sl_lun2_lsb == 0) && 2788 (lun.sl_lun3_msb == 0) && (lun.sl_lun3_lsb == 0) && 2789 (lun.sl_lun4_msb == 0) && (lun.sl_lun4_lsb == 0)) { 2790 return (lun64); 2791 } 2792 2793 /* Oops, we got a bad scsi_lun_t. Leave it in 64-bit form */ 2794 SCSI_HBA_LOG((_LOG(WARN), NULL, NULL, 2795 "lun_to_lun64 bad lun %" PRIx64, *(scsi_lun64_t *)&lun)); 2796 } 2797 2798 /* 2799 * We have a big LUN that is not backward compatible. 2800 * Construct a 64 bit number using the right byte order. 2801 */ 2802 lun64 = 2803 ((scsi_lun64_t)lun.sl_lun1_msb << 56) | 2804 ((scsi_lun64_t)lun.sl_lun1_lsb << 48) | 2805 ((scsi_lun64_t)lun.sl_lun2_msb << 40) | 2806 ((scsi_lun64_t)lun.sl_lun2_lsb << 32) | 2807 ((scsi_lun64_t)lun.sl_lun3_msb << 24) | 2808 ((scsi_lun64_t)lun.sl_lun3_lsb << 16) | 2809 ((scsi_lun64_t)lun.sl_lun4_msb << 8) | 2810 (scsi_lun64_t)lun.sl_lun4_lsb; 2811 return (lun64); 2812 } 2813 2814 scsi_lun_t 2815 scsi_lun64_to_lun(scsi_lun64_t lun64) 2816 { 2817 scsi_lun_t lun; 2818 2819 if (lun64 < 256) { 2820 /* This LUN is in compatibility format */ 2821 lun.sl_lun1_msb = 0; 2822 lun.sl_lun1_lsb = (uchar_t)lun64; 2823 lun.sl_lun2_msb = 0; 2824 lun.sl_lun2_lsb = 0; 2825 lun.sl_lun3_msb = 0; 2826 lun.sl_lun3_lsb = 0; 2827 lun.sl_lun4_msb = 0; 2828 lun.sl_lun4_lsb = 0; 2829 } else { 2830 /* This in full 64 bit LUN format */ 2831 lun.sl_lun1_msb = (uchar_t)(lun64 >> 56); 2832 lun.sl_lun1_lsb = (uchar_t)(lun64 >> 48); 2833 lun.sl_lun2_msb = (uchar_t)(lun64 >> 40); 2834 lun.sl_lun2_lsb = (uchar_t)(lun64 >> 32); 2835 lun.sl_lun3_msb = (uchar_t)(lun64 >> 24); 2836 lun.sl_lun3_lsb = (uchar_t)(lun64 >> 16); 2837 lun.sl_lun4_msb = (uchar_t)(lun64 >> 8); 2838 lun.sl_lun4_lsb = (uchar_t)(lun64); 2839 2840 /* Oops, bad LUN -- this is required to be nonzero */ 2841 if (lun.sl_lun1_msb == 0) 2842 SCSI_HBA_LOG((_LOG(WARN), NULL, NULL, 2843 "lun64_to_lun bad lun %" PRIlun64, lun64)); 2844 } 2845 return (lun); 2846 } 2847 2848 /* 2849 * Return the lun from an address string. Either the lun is after the 2850 * first ',' or the entire addr is the lun. Return SCSI_LUN64_ILLEGAL 2851 * if the format is incorrect. 2852 * 2853 * If the addr specified has incorrect syntax (busconfig one of 2854 * bogus /devices path) then scsi_addr_to_lun64 can return SCSI_LUN64_ILLEGAL. 2855 */ 2856 scsi_lun64_t 2857 scsi_addr_to_lun64(char *addr) 2858 { 2859 scsi_lun64_t lun64; 2860 char *s; 2861 int i; 2862 2863 if (addr) { 2864 s = strchr(addr, ','); /* "addr,lun[,sfunc]" */ 2865 if (s) 2866 s++; /* skip ',' */ 2867 else 2868 s = addr; /* "lun" */ 2869 2870 for (lun64 = 0, i = 0; *s && (i < 16); s++, i++) { 2871 if (*s >= '0' && *s <= '9') 2872 lun64 = (lun64 << 4) + (*s - '0'); 2873 else if (*s >= 'A' && *s <= 'F') 2874 lun64 = (lun64 << 4) + 10 + (*s - 'A'); 2875 else if (*s >= 'a' && *s <= 'f') 2876 lun64 = (lun64 << 4) + 10 + (*s - 'a'); 2877 else 2878 break; 2879 } 2880 if (*s && (*s != ',')) /* addr,lun[,sfunc] is OK */ 2881 lun64 = SCSI_LUN64_ILLEGAL; 2882 } else 2883 lun64 = SCSI_LUN64_ILLEGAL; 2884 2885 if (lun64 == SCSI_LUN64_ILLEGAL) 2886 SCSI_HBA_LOG((_LOG(2), NULL, NULL, 2887 "addr_to_lun64 %s lun %" PRIlun64, 2888 addr ? addr : "NULL", lun64)); 2889 return (lun64); 2890 } 2891 2892 /* 2893 * Convert scsi ascii string data to NULL terminated (semi) legal IEEE 1275 2894 * "compatible" (name) property form. 2895 * 2896 * For ASCII INQUIRY data, a one-way conversion algorithm is needed to take 2897 * SCSI_ASCII (20h - 7Eh) to a 1275-like compatible form. The 1275 spec allows 2898 * letters, digits, one ",", and ". _ + -", all limited by a maximum 31 2899 * character length. Since ", ." are used as separators in the compatible 2900 * string itself, they are converted to "_". All SCSI_ASCII characters that 2901 * are illegal in 1275, as well as any illegal SCSI_ASCII characters 2902 * encountered, are converted to "_". To reduce length, trailing blanks are 2903 * trimmed from SCSI_ASCII fields prior to conversion. 2904 * 2905 * Example: SCSI_ASCII "ST32550W SUN2.1G" -> "ST32550W_SUN2_1G" 2906 * 2907 * NOTE: the 1275 string form is always less than or equal to the scsi form. 2908 */ 2909 static char * 2910 string_scsi_to_1275(char *s_1275, char *s_scsi, int len) 2911 { 2912 (void) strncpy(s_1275, s_scsi, len); 2913 s_1275[len--] = '\0'; 2914 2915 while (len >= 0) { 2916 if (s_1275[len] == ' ') 2917 s_1275[len--] = '\0'; /* trim trailing " " */ 2918 else 2919 break; 2920 } 2921 2922 while (len >= 0) { 2923 if (((s_1275[len] >= 'a') && (s_1275[len] <= 'z')) || 2924 ((s_1275[len] >= 'A') && (s_1275[len] <= 'Z')) || 2925 ((s_1275[len] >= '0') && (s_1275[len] <= '9')) || 2926 (s_1275[len] == '_') || 2927 (s_1275[len] == '+') || 2928 (s_1275[len] == '-')) 2929 len--; /* legal 1275 */ 2930 else 2931 s_1275[len--] = '_'; /* illegal SCSI_ASCII | 1275 */ 2932 } 2933 2934 return (s_1275); 2935 } 2936 2937 /* 2938 * Given the inquiry data, binding_set, and dtype_node for a scsi device, 2939 * return the nodename and compatible property for the device. The "compatible" 2940 * concept comes from IEEE-1275. The compatible information is returned is in 2941 * the correct form for direct use defining the "compatible" string array 2942 * property. Internally, "compatible" is also used to determine the nodename 2943 * to return. 2944 * 2945 * This function is provided as a separate entry point for use by drivers that 2946 * currently issue their own non-SCSA inquiry command and perform their own 2947 * node creation based their own private compiled in tables. Converting these 2948 * drivers to use this interface provides a quick easy way of obtaining 2949 * consistency as well as the flexibility associated with the 1275 techniques. 2950 * 2951 * The dtype_node is passed as a separate argument (instead of having the 2952 * implementation use inq_dtype). It indicates that information about 2953 * a secondary function embedded service should be produced. 2954 * 2955 * Callers must always use scsi_hba_nodename_compatible_free, even if 2956 * *nodenamep is null, to free the nodename and compatible information 2957 * when done. 2958 * 2959 * If a nodename can't be determined then **compatiblep will point to a 2960 * diagnostic string containing all the compatible forms. 2961 * 2962 * NOTE: some compatible strings may violate the 31 character restriction 2963 * imposed by IEEE-1275. This is not a problem because Solaris does not care 2964 * about this 31 character limit. 2965 * 2966 * Each compatible form belongs to a form-group. The form-groups currently 2967 * defined are generic ("scsiclass"), binding-set ("scsa.b"), and failover 2968 * ("scsa.f"). 2969 * 2970 * The following compatible forms, in high to low precedence 2971 * order, are defined for SCSI target device nodes. 2972 * 2973 * scsiclass,DDEEFFF.vVVVVVVVV.pPPPPPPPPPPPPPPPP.rRRRR (1 *1&2) 2974 * scsiclass,DDEE.vVVVVVVVV.pPPPPPPPPPPPPPPPP.rRRRR (2 *1) 2975 * scsiclass,DDFFF.vVVVVVVVV.pPPPPPPPPPPPPPPPP.rRRRR (3 *2) 2976 * scsiclass,DD.vVVVVVVVV.pPPPPPPPPPPPPPPPP.rRRRR (4) 2977 * scsiclass,DDEEFFF.vVVVVVVVV.pPPPPPPPPPPPPPPPP (5 *1&2) 2978 * scsiclass,DDEE.vVVVVVVVV.pPPPPPPPPPPPPPPPP (6 *1) 2979 * scsiclass,DDFFF.vVVVVVVVV.pPPPPPPPPPPPPPPPP (7 *2) 2980 * scsiclass,DD.vVVVVVVVV.pPPPPPPPPPPPPPPPP (8) 2981 * scsa,DD.bBBBBBBBB (8.5 *3) 2982 * scsiclass,DDEEFFF (9 *1&2) 2983 * scsiclass,DDEE (10 *1) 2984 * scsiclass,DDFFF (11 *2) 2985 * scsiclass,DD (12) 2986 * scsa.fFFF (12.5 *4) 2987 * scsiclass (13) 2988 * 2989 * *1 only produced on a secondary function node 2990 * *2 only produced when generic form-group flags exist. 2991 * *3 only produced when binding-set form-group legacy support is needed 2992 * *4 only produced when failover form-group flags exist. 2993 * 2994 * where: 2995 * 2996 * v is the letter 'v'. Denotest the 2997 * beginning of VVVVVVVV. 2998 * 2999 * VVVVVVVV Translated scsi_vendor. 3000 * 3001 * p is the letter 'p'. Denotes the 3002 * beginning of PPPPPPPPPPPPPPPP. 3003 * 3004 * PPPPPPPPPPPPPPPP Translated scsi_product. 3005 * 3006 * r is the letter 'r'. Denotes the 3007 * beginning of RRRR. 3008 * 3009 * RRRR Translated scsi_revision. 3010 * 3011 * DD is a two digit ASCII hexadecimal 3012 * number. The value of the two digits is 3013 * based one the SCSI "Peripheral device 3014 * type" command set associated with the 3015 * node. On a primary node this is the 3016 * scsi_dtype of the primary command set, 3017 * on a secondary node this is the 3018 * scsi_dtype associated with the embedded 3019 * function command set. 3020 * 3021 * EE Same encoding used for DD. This form is 3022 * only generated on secondary function 3023 * nodes. The DD function is embedded in 3024 * an EE device. 3025 * 3026 * FFF Concatenation, in alphabetical order, 3027 * of the flag characters within a form-group. 3028 * For a given form-group, the following 3029 * flags are defined. 3030 * 3031 * scsiclass: (generic form-group): 3032 * R Removable_Media: Used when 3033 * inq_rmb is set. 3034 * 3035 * scsa.f: (failover form-group): 3036 * E Explicit Target_Port_Group: Used 3037 * when inq_tpgse is set and 'G' is 3038 * alse present. 3039 * G GUID: Used when a GUID can be 3040 * generated for the device. 3041 * I Implicit Target_Port_Group: Used 3042 * when inq_tpgs is set and 'G' is 3043 * also present. 3044 * 3045 * Forms using FFF are only be generated 3046 * if there are applicable flag 3047 * characters. 3048 * 3049 * b is the letter 'b'. Denotes the 3050 * beginning of BBBBBBBB. 3051 * 3052 * BBBBBBBB Binding-set. Operating System Specific: 3053 * scsi-binding-set property of HBA. 3054 */ 3055 #define NCOMPAT (1 + (13 + 2) + 1) 3056 #define COMPAT_LONGEST (strlen( \ 3057 "scsiclass,DDEEFFF.vVVVVVVVV.pPPPPPPPPPPPPPPPP.rRRRR" + 1)) 3058 3059 /* 3060 * Private version with extra device 'identity' arguments to allow code 3061 * to determine GUID FFF support. 3062 */ 3063 static void 3064 scsi_hba_identity_nodename_compatible_get(struct scsi_inquiry *inq, 3065 uchar_t *inq80, size_t inq80len, uchar_t *inq83, size_t inq83len, 3066 char *binding_set, int dtype_node, char *compat0, 3067 char **nodenamep, char ***compatiblep, int *ncompatiblep) 3068 { 3069 char vid[sizeof (inq->inq_vid) + 1 ]; 3070 char pid[sizeof (inq->inq_pid) + 1]; 3071 char rev[sizeof (inq->inq_revision) + 1]; 3072 char gf[sizeof ("R\0")]; 3073 char ff[sizeof ("EGI\0")]; 3074 int dtype_device; 3075 int ncompat; /* number of compatible */ 3076 char **compatp; /* compatible ptrs */ 3077 int i; 3078 char *nname; /* nodename */ 3079 char *dname; /* driver name */ 3080 char **csp; 3081 char *p; 3082 int tlen; 3083 int len; 3084 major_t major; 3085 ddi_devid_t devid; 3086 char *guid; 3087 3088 /* 3089 * Nodename_aliases: This table was originally designed to be 3090 * implemented via a new nodename_aliases file - a peer to the 3091 * driver_aliases that selects a nodename based on compatible 3092 * forms in much the same say driver_aliases is used to select 3093 * driver bindings from compatible forms. Each compatible form 3094 * is an 'alias'. Until a more general need for a 3095 * nodename_aliases file exists, which may never occur, the 3096 * scsi mappings are described here via a compiled in table. 3097 * 3098 * This table contains nodename mappings for self-identifying 3099 * scsi devices enumerated by the Solaris kernel. For a given 3100 * device, the highest precedence "compatible" form with a 3101 * mapping is used to select the nodename for the device. This 3102 * will typically be a generic nodename, however in some legacy 3103 * compatibility cases a driver nodename mapping may be selected. 3104 * 3105 * Because of possible breakage associated with switching SCSI 3106 * target devices from driver nodenames to generic nodenames, 3107 * we are currently unable to support generic nodenames for all 3108 * SCSI devices (binding-sets). Although /devices paths are 3109 * defined as unstable, avoiding possible breakage is 3110 * important. Some of the newer SCSI transports (USB) already 3111 * use generic nodenames. All new SCSI transports and target 3112 * devices should use generic nodenames. At times this decision 3113 * may be architecture dependent (sparc .vs. intel) based on when 3114 * a transport was supported on a particular architecture. 3115 * 3116 * We provide a base set of generic nodename mappings based on 3117 * scsiclass dtype and higher-precedence driver nodename 3118 * mappings based on scsa "binding-set" to cover legacy 3119 * issues. The binding-set is typically associated with 3120 * "scsi-binding-set" property value of the HBA. The legacy 3121 * mappings are provided independent of whether the driver they 3122 * refer to is installed. This allows a correctly named node 3123 * be created at discovery time, and binding to occur when/if 3124 * an add_drv of the legacy driver occurs. 3125 * 3126 * We also have mappings for legacy SUN hardware that 3127 * misidentifies itself (enclosure services which identify 3128 * themselves as processors). All future hardware should use 3129 * the correct dtype. 3130 * 3131 * As SCSI HBAs are modified to use the SCSA interfaces for 3132 * self-identifying SCSI target devices (PSARC/2004/116) the 3133 * nodename_aliases table (PSARC/2004/420) should be augmented 3134 * with legacy mappings in order to maintain compatibility with 3135 * existing /devices paths, especially for devices that house 3136 * an OS. Failure to do this may cause upgrade problems. 3137 * Additions for new target devices or transports should not 3138 * add scsa binding-set compatible mappings. 3139 */ 3140 static struct nodename_aliases { 3141 char *na_nodename; /* nodename */ 3142 char *na_alias; /* compatible form match */ 3143 } na[] = { 3144 /* # mapping to generic nodenames based on scsi dtype */ 3145 {"disk", "scsiclass,00"}, 3146 {"tape", "scsiclass,01"}, 3147 {"printer", "scsiclass,02"}, 3148 {"processor", "scsiclass,03"}, 3149 {"worm", "scsiclass,04"}, 3150 {"cdrom", "scsiclass,05"}, 3151 {"scanner", "scsiclass,06"}, 3152 {"optical-disk", "scsiclass,07"}, 3153 {"medium-changer", "scsiclass,08"}, 3154 {"obsolete", "scsiclass,09"}, 3155 {"prepress-a", "scsiclass,0a"}, 3156 {"prepress-b", "scsiclass,0b"}, 3157 {"array-controller", "scsiclass,0c"}, 3158 {"enclosure", "scsiclass,0d"}, 3159 {"disk", "scsiclass,0e"}, 3160 {"card-reader", "scsiclass,0f"}, 3161 {"bridge", "scsiclass,10"}, 3162 {"object-store", "scsiclass,11"}, 3163 {"reserved", "scsiclass,12"}, 3164 {"reserved", "scsiclass,13"}, 3165 {"reserved", "scsiclass,14"}, 3166 {"reserved", "scsiclass,15"}, 3167 {"reserved", "scsiclass,16"}, 3168 {"reserved", "scsiclass,17"}, 3169 {"reserved", "scsiclass,18"}, 3170 {"reserved", "scsiclass,19"}, 3171 {"reserved", "scsiclass,1a"}, 3172 {"reserved", "scsiclass,1b"}, 3173 {"reserved", "scsiclass,1c"}, 3174 {"reserved", "scsiclass,1d"}, 3175 {"well-known-lun", "scsiclass,1e"}, 3176 {"unknown", "scsiclass,1f"}, 3177 3178 #ifdef sparc 3179 /* # legacy mapping to driver nodenames for fcp binding-set */ 3180 {"ssd", "scsa,00.bfcp"}, 3181 {"st", "scsa,01.bfcp"}, 3182 {"sgen", "scsa,08.bfcp"}, 3183 {"ses", "scsa,0d.bfcp"}, 3184 3185 /* # legacy mapping to driver nodenames for vhci binding-set */ 3186 {"ssd", "scsa,00.bvhci"}, 3187 {"st", "scsa,01.bvhci"}, 3188 {"sgen", "scsa,08.bvhci"}, 3189 {"ses", "scsa,0d.bvhci"}, 3190 #else /* sparc */ 3191 /* # for x86 fcp and vhci use generic nodenames */ 3192 #endif /* sparc */ 3193 3194 #ifdef notdef 3195 /* 3196 * The following binding-set specific mappings are not being 3197 * delivered at this time, but are listed here as an examples of 3198 * the type of mappings needed. 3199 */ 3200 3201 /* # legacy mapping to driver nodenames for spi binding-set */ 3202 {"sd", "scsa,00.bspi"}, 3203 {"sd", "scsa,05.bspi"}, 3204 {"sd", "scsa,07.bspi"}, 3205 {"st", "scsa,01.bspi"}, 3206 {"ses", "scsa,0d.bspi"}, 3207 3208 /* # SUN misidentified spi hardware */ 3209 {"ses", "scsiclass,03.vSUN.pD2"}, 3210 {"ses", "scsiclass,03.vSYMBIOS.pD1000"}, 3211 3212 /* # legacy mapping to driver nodenames for atapi binding-set */ 3213 {"sd", "scsa,00.batapi"}, 3214 {"sd", "scsa,05.batapi"}, 3215 {"sd", "scsa,07.batapi"}, 3216 {"st", "scsa,01.batapi"}, 3217 {"unknown", "scsa,0d.batapi"}, 3218 3219 /* # legacy mapping to generic nodenames for usb binding-set */ 3220 {"disk", "scsa,05.busb"}, 3221 {"disk", "scsa,07.busb"}, 3222 {"changer", "scsa,08.busb"}, 3223 {"comm", "scsa,09.busb"}, 3224 {"array_ctlr", "scsa,0c.busb"}, 3225 {"esi", "scsa,0d.busb"}, 3226 #endif /* notdef */ 3227 3228 /* 3229 * mapping nodenames for mpt based on scsi dtype 3230 * for being compatible with the original node names 3231 * under mpt controller 3232 */ 3233 {"sd", "scsa,00.bmpt"}, 3234 {"sd", "scsa,05.bmpt"}, 3235 {"sd", "scsa,07.bmpt"}, 3236 {"st", "scsa,01.bmpt"}, 3237 {"ses", "scsa,0d.bmpt"}, 3238 {"sgen", "scsa,08.bmpt"}, 3239 {NULL, NULL} 3240 }; 3241 struct nodename_aliases *nap; 3242 3243 ASSERT(nodenamep && compatiblep && ncompatiblep && 3244 (binding_set == NULL || (strlen(binding_set) <= 8))); 3245 if ((nodenamep == NULL) || (compatiblep == NULL) || 3246 (ncompatiblep == NULL)) 3247 return; 3248 3249 /* 3250 * In order to reduce runtime we allocate one block of memory that 3251 * contains both the NULL terminated array of pointers to compatible 3252 * forms and the individual compatible strings. This block is 3253 * somewhat larger than needed, but is short lived - it only exists 3254 * until the caller can transfer the information into the "compatible" 3255 * string array property and call scsi_hba_nodename_compatible_free. 3256 */ 3257 tlen = NCOMPAT * COMPAT_LONGEST; 3258 compatp = kmem_alloc((NCOMPAT * sizeof (char *)) + tlen, KM_SLEEP); 3259 3260 /* convert inquiry data from SCSI ASCII to 1275 string */ 3261 (void) string_scsi_to_1275(vid, inq->inq_vid, 3262 sizeof (inq->inq_vid)); 3263 (void) string_scsi_to_1275(pid, inq->inq_pid, 3264 sizeof (inq->inq_pid)); 3265 (void) string_scsi_to_1275(rev, inq->inq_revision, 3266 sizeof (inq->inq_revision)); 3267 ASSERT((strlen(vid) <= sizeof (inq->inq_vid)) && 3268 (strlen(pid) <= sizeof (inq->inq_pid)) && 3269 (strlen(rev) <= sizeof (inq->inq_revision))); 3270 3271 /* 3272 * Form flags in ***ALPHABETICAL*** order within form-group: 3273 * 3274 * NOTE: When adding a new flag to an existing form-group, carefull 3275 * consideration must be given to not breaking existing bindings 3276 * based on that form-group. 3277 */ 3278 3279 /* 3280 * generic form-group flags 3281 * R removable: 3282 * Set when inq_rmb is set and for well known scsi dtypes. For a 3283 * bus where the entire device is removable (like USB), we expect 3284 * the HBA to intercept the inquiry data and set inq_rmb. 3285 * Since OBP does not distinguish removable media in its generic 3286 * name selection we avoid setting the 'R' flag if the root is not 3287 * yet mounted. 3288 */ 3289 i = 0; 3290 dtype_device = inq->inq_dtype & DTYPE_MASK; 3291 if (rootvp && (inq->inq_rmb || 3292 (dtype_device == DTYPE_WORM) || 3293 (dtype_device == DTYPE_RODIRECT) || 3294 (dtype_device == DTYPE_OPTICAL))) 3295 gf[i++] = 'R'; /* removable */ 3296 gf[i] = '\0'; 3297 3298 /* 3299 * failover form-group flags 3300 * E Explicit Target_Port_Group_Supported: 3301 * Set for a device that has a GUID if inq_tpgse also set. 3302 * G GUID: 3303 * Set when we have identity information, can determine a devid 3304 * from the identity information, and can generate a guid from 3305 * that devid. 3306 * I Implicit Target_Port_Group_Supported: 3307 * Set for a device that has a GUID if inq_tpgs also set. 3308 */ 3309 i = 0; 3310 if ((inq80 || inq83) && 3311 (ddi_devid_scsi_encode(DEVID_SCSI_ENCODE_VERSION_LATEST, NULL, 3312 (uchar_t *)inq, sizeof (*inq), inq80, inq80len, inq83, inq83len, 3313 &devid) == DDI_SUCCESS)) { 3314 guid = ddi_devid_to_guid(devid); 3315 ddi_devid_free(devid); 3316 } else 3317 guid = NULL; 3318 if (guid && (inq->inq_tpgs & TPGS_FAILOVER_EXPLICIT)) 3319 ff[i++] = 'E'; /* EXPLICIT TPGS */ 3320 if (guid) 3321 ff[i++] = 'G'; /* GUID */ 3322 if (guid && (inq->inq_tpgs & TPGS_FAILOVER_IMPLICIT)) 3323 ff[i++] = 'I'; /* IMPLICIT TPGS */ 3324 ff[i] = '\0'; 3325 if (guid) 3326 ddi_devid_free_guid(guid); 3327 3328 /* 3329 * Construct all applicable compatible forms. See comment at the 3330 * head of the function for a description of the compatible forms. 3331 */ 3332 csp = compatp; 3333 p = (char *)(compatp + NCOMPAT); 3334 3335 /* ( 0) driver (optional, not documented in scsi(4)) */ 3336 if (compat0) { 3337 *csp++ = p; 3338 (void) snprintf(p, tlen, "%s", compat0); 3339 len = strlen(p) + 1; 3340 p += len; 3341 tlen -= len; 3342 } 3343 3344 /* ( 1) scsiclass,DDEEFFF.vV.pP.rR */ 3345 if ((dtype_device != dtype_node) && *gf && *vid && *pid && *rev) { 3346 *csp++ = p; 3347 (void) snprintf(p, tlen, "scsiclass,%02x%02x%s.v%s.p%s.r%s", 3348 dtype_node, dtype_device, gf, vid, pid, rev); 3349 len = strlen(p) + 1; 3350 p += len; 3351 tlen -= len; 3352 } 3353 3354 /* ( 2) scsiclass,DDEE.vV.pP.rR */ 3355 if ((dtype_device != dtype_node) && *vid && *pid && *rev) { 3356 *csp++ = p; 3357 (void) snprintf(p, tlen, "scsiclass,%02x%02x.v%s.p%s.r%s", 3358 dtype_node, dtype_device, vid, pid, rev); 3359 len = strlen(p) + 1; 3360 p += len; 3361 tlen -= len; 3362 } 3363 3364 /* ( 3) scsiclass,DDFFF.vV.pP.rR */ 3365 if (*gf && *vid && *pid && *rev) { 3366 *csp++ = p; 3367 (void) snprintf(p, tlen, "scsiclass,%02x%s.v%s.p%s.r%s", 3368 dtype_node, gf, vid, pid, rev); 3369 len = strlen(p) + 1; 3370 p += len; 3371 tlen -= len; 3372 } 3373 3374 /* ( 4) scsiclass,DD.vV.pP.rR */ 3375 if (*vid && *pid && rev) { 3376 *csp++ = p; 3377 (void) snprintf(p, tlen, "scsiclass,%02x.v%s.p%s.r%s", 3378 dtype_node, vid, pid, rev); 3379 len = strlen(p) + 1; 3380 p += len; 3381 tlen -= len; 3382 } 3383 3384 /* ( 5) scsiclass,DDEEFFF.vV.pP */ 3385 if ((dtype_device != dtype_node) && *gf && *vid && *pid) { 3386 *csp++ = p; 3387 (void) snprintf(p, tlen, "scsiclass,%02x%02x%s.v%s.p%s", 3388 dtype_node, dtype_device, gf, vid, pid); 3389 len = strlen(p) + 1; 3390 p += len; 3391 tlen -= len; 3392 } 3393 3394 /* ( 6) scsiclass,DDEE.vV.pP */ 3395 if ((dtype_device != dtype_node) && *vid && *pid) { 3396 *csp++ = p; 3397 (void) snprintf(p, tlen, "scsiclass,%02x%02x.v%s.p%s", 3398 dtype_node, dtype_device, vid, pid); 3399 len = strlen(p) + 1; 3400 p += len; 3401 tlen -= len; 3402 } 3403 3404 /* ( 7) scsiclass,DDFFF.vV.pP */ 3405 if (*gf && *vid && *pid) { 3406 *csp++ = p; 3407 (void) snprintf(p, tlen, "scsiclass,%02x%s.v%s.p%s", 3408 dtype_node, gf, vid, pid); 3409 len = strlen(p) + 1; 3410 p += len; 3411 tlen -= len; 3412 } 3413 3414 /* ( 8) scsiclass,DD.vV.pP */ 3415 if (*vid && *pid) { 3416 *csp++ = p; 3417 (void) snprintf(p, tlen, "scsiclass,%02x.v%s.p%s", 3418 dtype_node, vid, pid); 3419 len = strlen(p) + 1; 3420 p += len; 3421 tlen -= len; 3422 } 3423 3424 /* (8.5) scsa,DD.bB (not documented in scsi(4)) */ 3425 if (binding_set) { 3426 *csp++ = p; 3427 (void) snprintf(p, tlen, "scsa,%02x.b%s", 3428 dtype_node, binding_set); 3429 len = strlen(p) + 1; 3430 p += len; 3431 tlen -= len; 3432 } 3433 3434 /* ( 9) scsiclass,DDEEFFF */ 3435 if ((dtype_device != dtype_node) && *gf) { 3436 *csp++ = p; 3437 (void) snprintf(p, tlen, "scsiclass,%02x%02x%s", 3438 dtype_node, dtype_device, gf); 3439 len = strlen(p) + 1; 3440 p += len; 3441 tlen -= len; 3442 } 3443 3444 /* (10) scsiclass,DDEE */ 3445 if (dtype_device != dtype_node) { 3446 *csp++ = p; 3447 (void) snprintf(p, tlen, "scsiclass,%02x%02x", 3448 dtype_node, dtype_device); 3449 len = strlen(p) + 1; 3450 p += len; 3451 tlen -= len; 3452 } 3453 3454 /* (11) scsiclass,DDFFF */ 3455 if (*gf) { 3456 *csp++ = p; 3457 (void) snprintf(p, tlen, "scsiclass,%02x%s", 3458 dtype_node, gf); 3459 len = strlen(p) + 1; 3460 p += len; 3461 tlen -= len; 3462 } 3463 3464 /* (12) scsiclass,DD */ 3465 *csp++ = p; 3466 (void) snprintf(p, tlen, "scsiclass,%02x", dtype_node); 3467 len = strlen(p) + 1; 3468 p += len; 3469 tlen -= len; 3470 3471 /* (12.5) scsa.fFFF */ 3472 if (*ff) { 3473 *csp++ = p; 3474 (void) snprintf(p, tlen, "scsa.f%s", ff); 3475 len = strlen(p) + 1; 3476 p += len; 3477 tlen -= len; 3478 } 3479 3480 /* (13) scsiclass */ 3481 *csp++ = p; 3482 (void) snprintf(p, tlen, "scsiclass"); 3483 len = strlen(p) + 1; 3484 p += len; 3485 tlen -= len; 3486 ASSERT(tlen >= 0); 3487 3488 *csp = NULL; /* NULL terminate array of pointers */ 3489 ncompat = csp - compatp; 3490 3491 /* 3492 * When determining a nodename, a nodename_aliases specified 3493 * mapping has precedence over using a driver_aliases specified 3494 * driver binding as a nodename. 3495 * 3496 * See if any of the compatible forms have a nodename_aliases 3497 * specified nodename. These mappings are described by 3498 * nodename_aliases entries like: 3499 * 3500 * disk "scsiclass,00" 3501 * enclosure "scsiclass,03.vSYMBIOS.pD1000" 3502 * ssd "scsa,00.bfcp" 3503 * 3504 * All nodename_aliases mappings should idealy be to generic 3505 * names, however a higher precedence legacy mapping to a 3506 * driver name may exist. The highest precedence mapping 3507 * provides the nodename, so legacy driver nodename mappings 3508 * (if they exist) take precedence over generic nodename 3509 * mappings. 3510 */ 3511 for (nname = NULL, csp = compatp; (nname == NULL) && *csp; csp++) { 3512 for (nap = na; nap->na_nodename; nap++) { 3513 if (strcmp(*csp, nap->na_alias) == 0) { 3514 nname = nap->na_nodename; 3515 break; 3516 } 3517 } 3518 } 3519 3520 /* 3521 * If no nodename_aliases mapping exists then use the 3522 * driver_aliases specified driver binding as a nodename. 3523 * Determine the driver based on compatible (which may 3524 * have the passed in compat0 as the first item). The 3525 * driver_aliases file has entries like 3526 * 3527 * sd "scsiclass,00" 3528 * 3529 * that map compatible forms to specific drivers. These 3530 * entries are established by add_drv. We use the most specific 3531 * driver binding as the nodename. This matches the eventual 3532 * ddi_driver_compatible_major() binding that will be 3533 * established by bind_node() 3534 */ 3535 if (nname == NULL) { 3536 for (dname = NULL, csp = compatp; *csp; csp++) { 3537 major = ddi_name_to_major(*csp); 3538 if ((major == (major_t)-1) || 3539 (devnamesp[major].dn_flags & DN_DRIVER_REMOVED)) 3540 continue; 3541 if (dname = ddi_major_to_name(major)) 3542 break; 3543 } 3544 nname = dname; 3545 } 3546 3547 /* return results */ 3548 if (nname) { 3549 *nodenamep = kmem_alloc(strlen(nname) + 1, KM_SLEEP); 3550 (void) strcpy(*nodenamep, nname); 3551 } else { 3552 *nodenamep = NULL; 3553 3554 /* 3555 * If no nodename could be determined return a special 3556 * 'compatible' to be used for a diagnostic message. This 3557 * compatible contains all compatible forms concatenated 3558 * into a single string pointed to by the first element. 3559 */ 3560 if (nname == NULL) { 3561 for (csp = compatp; *(csp + 1); csp++) 3562 *((*csp) + strlen(*csp)) = ' '; 3563 *(compatp + 1) = NULL; 3564 ncompat = 1; 3565 } 3566 3567 } 3568 *compatiblep = compatp; 3569 *ncompatiblep = ncompat; 3570 } 3571 3572 void 3573 scsi_hba_nodename_compatible_get(struct scsi_inquiry *inq, 3574 char *binding_set, int dtype_node, char *compat0, 3575 char **nodenamep, char ***compatiblep, int *ncompatiblep) 3576 { 3577 scsi_hba_identity_nodename_compatible_get(inq, 3578 NULL, 0, NULL, 0, binding_set, dtype_node, compat0, nodenamep, 3579 compatiblep, ncompatiblep); 3580 } 3581 3582 /* 3583 * Free allocations associated with scsi_hba_nodename_compatible_get or 3584 * scsi_hba_identity_nodename_compatible_get use. 3585 */ 3586 void 3587 scsi_hba_nodename_compatible_free(char *nodename, char **compatible) 3588 { 3589 if (nodename) 3590 kmem_free(nodename, strlen(nodename) + 1); 3591 3592 if (compatible) 3593 kmem_free(compatible, (NCOMPAT * sizeof (char *)) + 3594 (NCOMPAT * COMPAT_LONGEST)); 3595 } 3596 3597 /* scsi_device property interfaces */ 3598 #define _TYPE_DEFINED(flags) \ 3599 (((flags & SCSI_DEVICE_PROP_TYPE_MSK) == SCSI_DEVICE_PROP_PATH) || \ 3600 ((flags & SCSI_DEVICE_PROP_TYPE_MSK) == SCSI_DEVICE_PROP_DEVICE)) 3601 3602 #define _DEVICE_PIP(sd, flags) \ 3603 ((((flags & SCSI_DEVICE_PROP_TYPE_MSK) == SCSI_DEVICE_PROP_PATH) && \ 3604 sd->sd_pathinfo) ? (mdi_pathinfo_t *)sd->sd_pathinfo : NULL) 3605 3606 /* return the unit_address associated with a scsi_device */ 3607 char * 3608 scsi_device_unit_address(struct scsi_device *sd) 3609 { 3610 mdi_pathinfo_t *pip; 3611 3612 ASSERT(sd && sd->sd_dev); 3613 if ((sd == NULL) || (sd->sd_dev == NULL)) 3614 return (NULL); 3615 3616 pip = _DEVICE_PIP(sd, SCSI_DEVICE_PROP_PATH); 3617 if (pip) 3618 return (mdi_pi_get_addr(pip)); 3619 else 3620 return (ddi_get_name_addr(sd->sd_dev)); 3621 } 3622 3623 int 3624 scsi_device_prop_get_int(struct scsi_device *sd, uint_t flags, 3625 char *name, int defval) 3626 { 3627 mdi_pathinfo_t *pip; 3628 int v = defval; 3629 int data; 3630 int rv; 3631 3632 ASSERT(sd && name && sd->sd_dev && _TYPE_DEFINED(flags)); 3633 if ((sd == NULL) || (name == NULL) || (sd->sd_dev == NULL) || 3634 !_TYPE_DEFINED(flags)) 3635 return (v); 3636 3637 pip = _DEVICE_PIP(sd, flags); 3638 if (pip) { 3639 rv = mdi_prop_lookup_int(pip, name, &data); 3640 if (rv == DDI_PROP_SUCCESS) 3641 v = data; 3642 } else 3643 v = ddi_prop_get_int(DDI_DEV_T_ANY, sd->sd_dev, 3644 DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, name, v); 3645 return (v); 3646 } 3647 3648 3649 int64_t 3650 scsi_device_prop_get_int64(struct scsi_device *sd, uint_t flags, 3651 char *name, int64_t defval) 3652 { 3653 mdi_pathinfo_t *pip; 3654 int64_t v = defval; 3655 int64_t data; 3656 int rv; 3657 3658 ASSERT(sd && name && sd->sd_dev && _TYPE_DEFINED(flags)); 3659 if ((sd == NULL) || (name == NULL) || (sd->sd_dev == NULL) || 3660 !_TYPE_DEFINED(flags)) 3661 return (v); 3662 3663 pip = _DEVICE_PIP(sd, flags); 3664 if (pip) { 3665 rv = mdi_prop_lookup_int64(pip, name, &data); 3666 if (rv == DDI_PROP_SUCCESS) 3667 v = data; 3668 } else 3669 v = ddi_prop_get_int64(DDI_DEV_T_ANY, sd->sd_dev, 3670 DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, name, v); 3671 return (v); 3672 } 3673 3674 int 3675 scsi_device_prop_lookup_byte_array(struct scsi_device *sd, uint_t flags, 3676 char *name, uchar_t **data, uint_t *nelements) 3677 { 3678 mdi_pathinfo_t *pip; 3679 int rv; 3680 3681 ASSERT(sd && name && sd->sd_dev && _TYPE_DEFINED(flags)); 3682 if ((sd == NULL) || (name == NULL) || (sd->sd_dev == NULL) || 3683 !_TYPE_DEFINED(flags)) 3684 return (DDI_PROP_INVAL_ARG); 3685 3686 pip = _DEVICE_PIP(sd, flags); 3687 if (pip) 3688 rv = mdi_prop_lookup_byte_array(pip, name, data, nelements); 3689 else 3690 rv = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, sd->sd_dev, 3691 DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, 3692 name, data, nelements); 3693 return (rv); 3694 } 3695 3696 int 3697 scsi_device_prop_lookup_int_array(struct scsi_device *sd, uint_t flags, 3698 char *name, int **data, uint_t *nelements) 3699 { 3700 mdi_pathinfo_t *pip; 3701 int rv; 3702 3703 ASSERT(sd && name && sd->sd_dev && _TYPE_DEFINED(flags)); 3704 if ((sd == NULL) || (name == NULL) || (sd->sd_dev == NULL) || 3705 !_TYPE_DEFINED(flags)) 3706 return (DDI_PROP_INVAL_ARG); 3707 3708 pip = _DEVICE_PIP(sd, flags); 3709 if (pip) 3710 rv = mdi_prop_lookup_int_array(pip, name, data, nelements); 3711 else 3712 rv = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, sd->sd_dev, 3713 DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, 3714 name, data, nelements); 3715 return (rv); 3716 } 3717 3718 3719 int 3720 scsi_device_prop_lookup_string(struct scsi_device *sd, uint_t flags, 3721 char *name, char **data) 3722 { 3723 mdi_pathinfo_t *pip; 3724 int rv; 3725 3726 ASSERT(sd && name && sd->sd_dev && _TYPE_DEFINED(flags)); 3727 if ((sd == NULL) || (name == NULL) || (sd->sd_dev == NULL) || 3728 !_TYPE_DEFINED(flags)) 3729 return (DDI_PROP_INVAL_ARG); 3730 3731 pip = _DEVICE_PIP(sd, flags); 3732 if (pip) 3733 rv = mdi_prop_lookup_string(pip, name, data); 3734 else 3735 rv = ddi_prop_lookup_string(DDI_DEV_T_ANY, sd->sd_dev, 3736 DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, 3737 name, data); 3738 return (rv); 3739 } 3740 3741 int 3742 scsi_device_prop_lookup_string_array(struct scsi_device *sd, uint_t flags, 3743 char *name, char ***data, uint_t *nelements) 3744 { 3745 mdi_pathinfo_t *pip; 3746 int rv; 3747 3748 ASSERT(sd && name && sd->sd_dev && _TYPE_DEFINED(flags)); 3749 if ((sd == NULL) || (name == NULL) || (sd->sd_dev == NULL) || 3750 !_TYPE_DEFINED(flags)) 3751 return (DDI_PROP_INVAL_ARG); 3752 3753 pip = _DEVICE_PIP(sd, flags); 3754 if (pip) 3755 rv = mdi_prop_lookup_string_array(pip, name, data, nelements); 3756 else 3757 rv = ddi_prop_lookup_string_array(DDI_DEV_T_ANY, sd->sd_dev, 3758 DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, 3759 name, data, nelements); 3760 return (rv); 3761 } 3762 3763 int 3764 scsi_device_prop_update_byte_array(struct scsi_device *sd, uint_t flags, 3765 char *name, uchar_t *data, uint_t nelements) 3766 { 3767 mdi_pathinfo_t *pip; 3768 int rv; 3769 3770 ASSERT(sd && name && sd->sd_dev && _TYPE_DEFINED(flags)); 3771 if ((sd == NULL) || (name == NULL) || (sd->sd_dev == NULL) || 3772 !_TYPE_DEFINED(flags)) 3773 return (DDI_PROP_INVAL_ARG); 3774 3775 pip = _DEVICE_PIP(sd, flags); 3776 if (pip) 3777 rv = mdi_prop_update_byte_array(pip, name, data, nelements); 3778 else 3779 rv = ndi_prop_update_byte_array(DDI_DEV_T_NONE, sd->sd_dev, 3780 name, data, nelements); 3781 return (rv); 3782 } 3783 3784 int 3785 scsi_device_prop_update_int(struct scsi_device *sd, uint_t flags, 3786 char *name, int data) 3787 { 3788 mdi_pathinfo_t *pip; 3789 int rv; 3790 3791 ASSERT(sd && name && sd->sd_dev && _TYPE_DEFINED(flags)); 3792 if ((sd == NULL) || (name == NULL) || (sd->sd_dev == NULL) || 3793 !_TYPE_DEFINED(flags)) 3794 return (DDI_PROP_INVAL_ARG); 3795 3796 pip = _DEVICE_PIP(sd, flags); 3797 if (pip) 3798 rv = mdi_prop_update_int(pip, name, data); 3799 else 3800 rv = ndi_prop_update_int(DDI_DEV_T_NONE, sd->sd_dev, 3801 name, data); 3802 return (rv); 3803 } 3804 3805 int 3806 scsi_device_prop_update_int64(struct scsi_device *sd, uint_t flags, 3807 char *name, int64_t data) 3808 { 3809 mdi_pathinfo_t *pip; 3810 int rv; 3811 3812 ASSERT(sd && name && sd->sd_dev && _TYPE_DEFINED(flags)); 3813 if ((sd == NULL) || (name == NULL) || (sd->sd_dev == NULL) || 3814 !_TYPE_DEFINED(flags)) 3815 return (DDI_PROP_INVAL_ARG); 3816 3817 pip = _DEVICE_PIP(sd, flags); 3818 if (pip) 3819 rv = mdi_prop_update_int64(pip, name, data); 3820 else 3821 rv = ndi_prop_update_int64(DDI_DEV_T_NONE, sd->sd_dev, 3822 name, data); 3823 return (rv); 3824 } 3825 3826 int 3827 scsi_device_prop_update_int_array(struct scsi_device *sd, uint_t flags, 3828 char *name, int *data, uint_t nelements) 3829 { 3830 mdi_pathinfo_t *pip; 3831 int rv; 3832 3833 ASSERT(sd && name && sd->sd_dev && _TYPE_DEFINED(flags)); 3834 if ((sd == NULL) || (name == NULL) || (sd->sd_dev == NULL) || 3835 !_TYPE_DEFINED(flags)) 3836 return (DDI_PROP_INVAL_ARG); 3837 3838 pip = _DEVICE_PIP(sd, flags); 3839 if (pip) 3840 rv = mdi_prop_update_int_array(pip, name, data, nelements); 3841 else 3842 rv = ndi_prop_update_int_array(DDI_DEV_T_NONE, sd->sd_dev, 3843 name, data, nelements); 3844 return (rv); 3845 } 3846 3847 int 3848 scsi_device_prop_update_string(struct scsi_device *sd, uint_t flags, 3849 char *name, char *data) 3850 { 3851 mdi_pathinfo_t *pip; 3852 int rv; 3853 3854 ASSERT(sd && name && sd->sd_dev && _TYPE_DEFINED(flags)); 3855 if ((sd == NULL) || (name == NULL) || (sd->sd_dev == NULL) || 3856 !_TYPE_DEFINED(flags)) 3857 return (DDI_PROP_INVAL_ARG); 3858 3859 pip = _DEVICE_PIP(sd, flags); 3860 if (pip) 3861 rv = mdi_prop_update_string(pip, name, data); 3862 else 3863 rv = ndi_prop_update_string(DDI_DEV_T_NONE, sd->sd_dev, 3864 name, data); 3865 return (rv); 3866 } 3867 3868 int 3869 scsi_device_prop_update_string_array(struct scsi_device *sd, uint_t flags, 3870 char *name, char **data, uint_t nelements) 3871 { 3872 mdi_pathinfo_t *pip; 3873 int rv; 3874 3875 ASSERT(sd && name && sd->sd_dev && _TYPE_DEFINED(flags)); 3876 if ((sd == NULL) || (name == NULL) || (sd->sd_dev == NULL) || 3877 !_TYPE_DEFINED(flags)) 3878 return (DDI_PROP_INVAL_ARG); 3879 3880 pip = _DEVICE_PIP(sd, flags); 3881 if (pip) 3882 rv = mdi_prop_update_string_array(pip, name, data, nelements); 3883 else 3884 rv = ndi_prop_update_string_array(DDI_DEV_T_NONE, sd->sd_dev, 3885 name, data, nelements); 3886 return (rv); 3887 } 3888 3889 int 3890 scsi_device_prop_remove(struct scsi_device *sd, uint_t flags, char *name) 3891 { 3892 mdi_pathinfo_t *pip; 3893 int rv; 3894 3895 ASSERT(sd && name && sd->sd_dev && _TYPE_DEFINED(flags)); 3896 if ((sd == NULL) || (name == NULL) || (sd->sd_dev == NULL) || 3897 !_TYPE_DEFINED(flags)) 3898 return (DDI_PROP_INVAL_ARG); 3899 3900 pip = _DEVICE_PIP(sd, flags); 3901 if (pip) 3902 rv = mdi_prop_remove(pip, name); 3903 else 3904 rv = ndi_prop_remove(DDI_DEV_T_NONE, sd->sd_dev, name); 3905 return (rv); 3906 } 3907 3908 void 3909 scsi_device_prop_free(struct scsi_device *sd, uint_t flags, void *data) 3910 { 3911 mdi_pathinfo_t *pip; 3912 3913 ASSERT(sd && data && sd->sd_dev && _TYPE_DEFINED(flags)); 3914 if ((sd == NULL) || (data == NULL) || (sd->sd_dev == NULL) || 3915 !_TYPE_DEFINED(flags)) 3916 return; 3917 3918 pip = _DEVICE_PIP(sd, flags); 3919 if (pip) 3920 (void) mdi_prop_free(data); 3921 else 3922 ddi_prop_free(data); 3923 } 3924 3925 /*ARGSUSED*/ 3926 /* 3927 * Search/create the specified iport node 3928 */ 3929 static dev_info_t * 3930 scsi_hba_bus_config_port(dev_info_t *self, char *nameaddr) 3931 { 3932 dev_info_t *child; 3933 char *mcompatible, *addr; 3934 3935 /* 3936 * See if the iport node already exists. 3937 */ 3938 3939 if (child = ndi_devi_findchild(self, nameaddr)) { 3940 return (child); 3941 } 3942 3943 /* allocate and initialize a new "iport" node */ 3944 ndi_devi_alloc_sleep(self, "iport", DEVI_SID_NODEID, &child); 3945 ASSERT(child); 3946 /* 3947 * Set the flavor of the child to be IPORT flavored 3948 */ 3949 ndi_flavor_set(child, SCSA_FLAVOR_IPORT); 3950 3951 /* 3952 * Add the "scsi-iport" addressing property for this child. This 3953 * property is used to identify a iport node, and to represent the 3954 * nodes @addr form via node properties. 3955 * 3956 * Add "compatible" property to the "scsi-iport" node to cause it bind 3957 * to the same driver as the HBA driver. 3958 * 3959 * Give the HBA a chance, via tran_set_name_prop, to set additional 3960 * iport node properties or to change the "compatible" binding 3961 * prior to init_child. 3962 * 3963 * NOTE: the order of these operations is important so that 3964 * scsi_hba_iport works when called. 3965 */ 3966 mcompatible = ddi_binding_name(self); 3967 addr = nameaddr + strlen("iport@"); 3968 3969 if ((ndi_prop_update_string(DDI_DEV_T_NONE, child, 3970 "scsi-iport", addr) != DDI_PROP_SUCCESS) || 3971 (ndi_prop_update_string_array(DDI_DEV_T_NONE, child, 3972 "compatible", &mcompatible, 1) != DDI_PROP_SUCCESS) || 3973 ddi_pathname_obp_set(child, NULL) != DDI_SUCCESS) { 3974 SCSI_HBA_LOG((_LOG(WARN), self, NULL, 3975 "scsi_hba_bus_config_port:%s failed dynamic decoration", 3976 nameaddr)); 3977 (void) ddi_remove_child(child, 0); 3978 child = NULL; 3979 } else { 3980 if (ddi_initchild(self, child) != DDI_SUCCESS) { 3981 ndi_prop_remove_all(child); 3982 (void) ndi_devi_free(child); 3983 child = NULL; 3984 } 3985 } 3986 3987 return (child); 3988 } 3989 3990 #ifdef sparc 3991 /* ARGSUSED */ 3992 static int 3993 scsi_hba_bus_config_prom_node(dev_info_t *self, uint_t flags, 3994 void *arg, dev_info_t **childp) 3995 { 3996 char **iports; 3997 int circ, i; 3998 int ret = NDI_FAILURE; 3999 unsigned int num_iports = 0; 4000 dev_info_t *pdip = NULL; 4001 char *addr = NULL; 4002 4003 /* check to see if this is an HBA that defined scsi iports */ 4004 ret = ddi_prop_lookup_string_array(DDI_DEV_T_ANY, self, 4005 DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "scsi-iports", &iports, 4006 &num_iports); 4007 4008 if (ret != DDI_SUCCESS) { 4009 return (ret); 4010 } 4011 4012 ASSERT(num_iports > 0); 4013 4014 addr = kmem_zalloc(SCSI_MAXNAMELEN, KM_SLEEP); 4015 4016 ret = NDI_FAILURE; 4017 4018 ndi_devi_enter(self, &circ); 4019 4020 /* create iport nodes for each scsi port/bus */ 4021 for (i = 0; i < num_iports; i++) { 4022 bzero(addr, SCSI_MAXNAMELEN); 4023 /* Prepend the iport name */ 4024 (void) snprintf(addr, SCSI_MAXNAMELEN, "iport@%s", 4025 iports[i]); 4026 if (pdip = scsi_hba_bus_config_port(self, addr)) { 4027 if (ndi_busop_bus_config(self, NDI_NO_EVENT, 4028 BUS_CONFIG_ONE, addr, &pdip, 0) != 4029 NDI_SUCCESS) { 4030 continue; 4031 } 4032 /* 4033 * Try to configure child under iport see wehter 4034 * request node is the child of the iport node 4035 */ 4036 if (ndi_devi_config_one(pdip, arg, childp, 4037 NDI_NO_EVENT) == NDI_SUCCESS) { 4038 ret = NDI_SUCCESS; 4039 break; 4040 } 4041 } 4042 } 4043 4044 ndi_devi_exit(self, circ); 4045 4046 kmem_free(addr, SCSI_MAXNAMELEN); 4047 4048 ddi_prop_free(iports); 4049 4050 return (ret); 4051 } 4052 #endif 4053 4054 /* 4055 * Perform iport port/bus bus_config. 4056 */ 4057 static int 4058 scsi_hba_bus_config_iports(dev_info_t *self, uint_t flags, 4059 ddi_bus_config_op_t op, void *arg, dev_info_t **childp) 4060 { 4061 char *nameaddr, *addr; 4062 char **iports; 4063 int circ, i; 4064 int ret = NDI_FAILURE; 4065 unsigned int num_iports = 0; 4066 4067 /* check to see if this is an HBA that defined scsi iports */ 4068 ret = ddi_prop_lookup_string_array(DDI_DEV_T_ANY, self, 4069 DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "scsi-iports", &iports, 4070 &num_iports); 4071 4072 if (ret != DDI_SUCCESS) { 4073 return (ret); 4074 } 4075 4076 ASSERT(num_iports > 0); 4077 4078 ndi_devi_enter(self, &circ); 4079 4080 switch (op) { 4081 case BUS_CONFIG_ONE: 4082 /* return if this operation is not against an iport node */ 4083 nameaddr = (char *)arg; 4084 if ((nameaddr == NULL) || 4085 (strncmp(nameaddr, "iport@", strlen("iport@")) != 0)) { 4086 ret = NDI_FAILURE; 4087 ndi_devi_exit(self, circ); 4088 return (ret); 4089 } 4090 4091 /* 4092 * parse the port number from "iport@%x" 4093 * XXX use atoi (hex) 4094 */ 4095 addr = nameaddr + strlen("iport@"); 4096 4097 /* check to see if this port was registered */ 4098 for (i = 0; i < num_iports; i++) { 4099 if (strcmp((iports[i]), addr) == 0) 4100 break; 4101 } 4102 4103 if (i == num_iports) { 4104 ret = NDI_FAILURE; 4105 break; 4106 } 4107 4108 /* create the iport node */ 4109 if (scsi_hba_bus_config_port(self, nameaddr)) { 4110 ret = NDI_SUCCESS; 4111 } 4112 break; 4113 case BUS_CONFIG_ALL: 4114 case BUS_CONFIG_DRIVER: 4115 addr = kmem_zalloc(SCSI_MAXNAMELEN, KM_SLEEP); 4116 /* create iport nodes for each scsi port/bus */ 4117 for (i = 0; i < num_iports; i++) { 4118 bzero(addr, SCSI_MAXNAMELEN); 4119 /* Prepend the iport name */ 4120 (void) snprintf(addr, SCSI_MAXNAMELEN, "iport@%s", 4121 iports[i]); 4122 (void) scsi_hba_bus_config_port(self, addr); 4123 } 4124 4125 kmem_free(addr, SCSI_MAXNAMELEN); 4126 ret = NDI_SUCCESS; 4127 break; 4128 } 4129 if (ret == NDI_SUCCESS) { 4130 #ifdef sparc 4131 /* 4132 * Mask NDI_PROMNAME since PROM doesn't have iport 4133 * node at all. 4134 */ 4135 flags &= (~NDI_PROMNAME); 4136 #endif 4137 ret = ndi_busop_bus_config(self, flags, op, 4138 arg, childp, 0); 4139 } 4140 ndi_devi_exit(self, circ); 4141 4142 ddi_prop_free(iports); 4143 4144 return (ret); 4145 } 4146 4147 4148 /*ARGSUSED*/ 4149 static int 4150 scsi_hba_bus_config(dev_info_t *self, uint_t flag, ddi_bus_config_op_t op, 4151 void *arg, dev_info_t **childp) 4152 { 4153 scsi_hba_tran_t *tran = NULL; 4154 4155 tran = ddi_get_driver_private(self); 4156 4157 if (tran && (tran->tran_hba_flags & SCSI_HBA_HBA)) { 4158 #ifdef sparc 4159 char *nameaddr = NULL; 4160 nameaddr = (char *)arg; 4161 switch (op) { 4162 case BUS_CONFIG_ONE: 4163 if (nameaddr == NULL) 4164 return (NDI_FAILURE); 4165 if (strncmp(nameaddr, "iport", strlen("iport")) == 0) { 4166 break; 4167 } 4168 /* 4169 * If this operation is not against an iport node, it's 4170 * possible the operation is requested to configure 4171 * root disk by OBP. Unfortunately, prom path is without 4172 * iport string in the boot path. 4173 */ 4174 if (strncmp(nameaddr, "disk@", strlen("disk@")) == 0) { 4175 return (scsi_hba_bus_config_prom_node(self, 4176 flag, arg, childp)); 4177 } 4178 break; 4179 default: 4180 break; 4181 } 4182 #endif 4183 /* 4184 * The request is to configure multi-port HBA. 4185 * Now start to configure iports, for the end 4186 * devices attached to iport, should be configured 4187 * by bus_configure routine of iport 4188 */ 4189 return (scsi_hba_bus_config_iports(self, flag, op, arg, 4190 childp)); 4191 } 4192 4193 #ifdef sparc 4194 if (scsi_hba_iport_unit_address(self)) { 4195 flag &= (~NDI_PROMNAME); 4196 } 4197 #endif 4198 if (tran && tran->tran_bus_config) { 4199 return (tran->tran_bus_config(self, flag, op, arg, childp)); 4200 } 4201 4202 /* 4203 * Force reprobe for BUS_CONFIG_ONE or when manually reconfiguring 4204 * via devfsadm(1m) to emulate deferred attach. 4205 * Reprobe only discovers driver.conf enumerated nodes, more 4206 * dynamic implementations probably require their own bus_config. 4207 */ 4208 if ((op == BUS_CONFIG_ONE) || (flag & NDI_DRV_CONF_REPROBE)) 4209 flag |= NDI_CONFIG_REPROBE; 4210 4211 return (ndi_busop_bus_config(self, flag, op, arg, childp, 0)); 4212 } 4213 4214 static int 4215 scsi_hba_bus_unconfig(dev_info_t *self, uint_t flag, ddi_bus_config_op_t op, 4216 void *arg) 4217 { 4218 scsi_hba_tran_t *tran = NULL; 4219 4220 tran = ddi_get_driver_private(self); 4221 4222 if (tran && tran->tran_bus_unconfig) { 4223 return (tran->tran_bus_unconfig(self, flag, op, arg)); 4224 } 4225 return (ndi_busop_bus_unconfig(self, flag, op, arg)); 4226 } 4227 4228 void 4229 scsi_hba_pkt_comp(struct scsi_pkt *pkt) 4230 { 4231 ASSERT(pkt); 4232 if (pkt->pkt_comp == NULL) 4233 return; 4234 4235 /* 4236 * For HBA drivers that implement tran_setup_pkt(9E), if we are 4237 * completing a 'consistent' mode DMA operation then we must 4238 * perform dma_sync prior to calling pkt_comp to ensure that 4239 * the target driver sees the correct data in memory. 4240 */ 4241 ASSERT((pkt->pkt_flags & FLAG_NOINTR) == 0); 4242 if (((pkt->pkt_dma_flags & DDI_DMA_CONSISTENT) && 4243 (pkt->pkt_dma_flags & DDI_DMA_READ)) && 4244 ((P_TO_TRAN(pkt)->tran_setup_pkt) != NULL)) { 4245 scsi_sync_pkt(pkt); 4246 } 4247 (*pkt->pkt_comp)(pkt); 4248 } 4249