1 0 stevel /* 2 0 stevel * CDDL HEADER START 3 0 stevel * 4 0 stevel * The contents of this file are subject to the terms of the 5 1489 webaker * Common Development and Distribution License (the "License"). 6 1489 webaker * You may not use this file except in compliance with the License. 7 0 stevel * 8 0 stevel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 0 stevel * or http://www.opensolaris.org/os/licensing. 10 0 stevel * See the License for the specific language governing permissions 11 0 stevel * and limitations under the License. 12 0 stevel * 13 0 stevel * When distributing Covered Code, include this CDDL HEADER in each 14 0 stevel * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 0 stevel * If applicable, add the following below this CDDL HEADER, with the 16 0 stevel * fields enclosed by brackets "[]" replaced with your own identifying 17 0 stevel * information: Portions Copyright [yyyy] [name of copyright owner] 18 0 stevel * 19 0 stevel * CDDL HEADER END 20 0 stevel */ 21 7563 Prasad 22 0 stevel /* 23 8551 Peng * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 0 stevel * Use is subject to license terms. 25 0 stevel */ 26 0 stevel 27 0 stevel /* 28 0 stevel * SCSI disk target driver. 29 0 stevel */ 30 0 stevel #include <sys/scsi/scsi.h> 31 0 stevel #include <sys/dkbad.h> 32 0 stevel #include <sys/dklabel.h> 33 0 stevel #include <sys/dkio.h> 34 0 stevel #include <sys/fdio.h> 35 0 stevel #include <sys/cdio.h> 36 0 stevel #include <sys/mhd.h> 37 0 stevel #include <sys/vtoc.h> 38 0 stevel #include <sys/dktp/fdisk.h> 39 0 stevel #include <sys/kstat.h> 40 0 stevel #include <sys/vtrace.h> 41 0 stevel #include <sys/note.h> 42 0 stevel #include <sys/thread.h> 43 0 stevel #include <sys/proc.h> 44 0 stevel #include <sys/efi_partition.h> 45 0 stevel #include <sys/var.h> 46 0 stevel #include <sys/aio_req.h> 47 1415 cg149915 48 1415 cg149915 #ifdef __lock_lint 49 1415 cg149915 #define _LP64 50 1415 cg149915 #define __amd64 51 1415 cg149915 #endif 52 1415 cg149915 53 0 stevel #if (defined(__fibre)) 54 0 stevel /* Note: is there a leadville version of the following? */ 55 0 stevel #include <sys/fc4/fcal_linkapp.h> 56 0 stevel #endif 57 0 stevel #include <sys/taskq.h> 58 0 stevel #include <sys/uuid.h> 59 0 stevel #include <sys/byteorder.h> 60 0 stevel #include <sys/sdt.h> 61 0 stevel 62 0 stevel #include "sd_xbuf.h" 63 0 stevel 64 0 stevel #include <sys/scsi/targets/sddef.h> 65 3525 shidokht #include <sys/cmlb.h> 66 6590 yl194034 #include <sys/sysevent/eventdefs.h> 67 6590 yl194034 #include <sys/sysevent/dev.h> 68 1415 cg149915 69 7570 David #include <sys/fm/protocol.h> 70 0 stevel 71 0 stevel /* 72 0 stevel * Loadable module info. 73 0 stevel */ 74 0 stevel #if (defined(__fibre)) 75 7355 Sheshadri #define SD_MODULE_NAME "SCSI SSA/FCAL Disk Driver" 76 3525 shidokht char _depends_on[] = "misc/scsi misc/cmlb drv/fcp"; 77 8863 Edward #else /* !__fibre */ 78 7355 Sheshadri #define SD_MODULE_NAME "SCSI Disk Driver" 79 3525 shidokht char _depends_on[] = "misc/scsi misc/cmlb"; 80 8863 Edward #endif /* !__fibre */ 81 0 stevel 82 0 stevel /* 83 0 stevel * Define the interconnect type, to allow the driver to distinguish 84 0 stevel * between parallel SCSI (sd) and fibre channel (ssd) behaviors. 85 0 stevel * 86 4451 eschrock * This is really for backward compatibility. In the future, the driver 87 0 stevel * should actually check the "interconnect-type" property as reported by 88 0 stevel * the HBA; however at present this property is not defined by all HBAs, 89 0 stevel * so we will use this #define (1) to permit the driver to run in 90 4451 eschrock * backward-compatibility mode; and (2) to print a notification message 91 0 stevel * if an FC HBA does not support the "interconnect-type" property. The 92 0 stevel * behavior of the driver will be to assume parallel SCSI behaviors unless 93 0 stevel * the "interconnect-type" property is defined by the HBA **AND** has a 94 0 stevel * value of either INTERCONNECT_FIBRE, INTERCONNECT_SSA, or 95 0 stevel * INTERCONNECT_FABRIC, in which case the driver will assume Fibre 96 0 stevel * Channel behaviors (as per the old ssd). (Note that the 97 0 stevel * INTERCONNECT_1394 and INTERCONNECT_USB types are not supported and 98 0 stevel * will result in the driver assuming parallel SCSI behaviors.) 99 0 stevel * 100 0 stevel * (see common/sys/scsi/impl/services.h) 101 0 stevel * 102 0 stevel * Note: For ssd semantics, don't use INTERCONNECT_FABRIC as the default 103 0 stevel * since some FC HBAs may already support that, and there is some code in 104 0 stevel * the driver that already looks for it. Using INTERCONNECT_FABRIC as the 105 0 stevel * default would confuse that code, and besides things should work fine 106 0 stevel * anyways if the FC HBA already reports INTERCONNECT_FABRIC for the 107 0 stevel * "interconnect_type" property. 108 2285 cg149915 * 109 0 stevel */ 110 0 stevel #if (defined(__fibre)) 111 0 stevel #define SD_DEFAULT_INTERCONNECT_TYPE SD_INTERCONNECT_FIBRE 112 0 stevel #else 113 0 stevel #define SD_DEFAULT_INTERCONNECT_TYPE SD_INTERCONNECT_PARALLEL 114 0 stevel #endif 115 0 stevel 116 0 stevel /* 117 0 stevel * The name of the driver, established from the module name in _init. 118 0 stevel */ 119 0 stevel static char *sd_label = NULL; 120 0 stevel 121 0 stevel /* 122 0 stevel * Driver name is unfortunately prefixed on some driver.conf properties. 123 0 stevel */ 124 0 stevel #if (defined(__fibre)) 125 0 stevel #define sd_max_xfer_size ssd_max_xfer_size 126 0 stevel #define sd_config_list ssd_config_list 127 0 stevel static char *sd_max_xfer_size = "ssd_max_xfer_size"; 128 0 stevel static char *sd_config_list = "ssd-config-list"; 129 0 stevel #else 130 0 stevel static char *sd_max_xfer_size = "sd_max_xfer_size"; 131 0 stevel static char *sd_config_list = "sd-config-list"; 132 0 stevel #endif 133 0 stevel 134 0 stevel /* 135 0 stevel * Driver global variables 136 0 stevel */ 137 0 stevel 138 0 stevel #if (defined(__fibre)) 139 0 stevel /* 140 0 stevel * These #defines are to avoid namespace collisions that occur because this 141 4451 eschrock * code is currently used to compile two separate driver modules: sd and ssd. 142 0 stevel * All global variables need to be treated this way (even if declared static) 143 0 stevel * in order to allow the debugger to resolve the names properly. 144 0 stevel * It is anticipated that in the near future the ssd module will be obsoleted, 145 0 stevel * at which time this namespace issue should go away. 146 0 stevel */ 147 0 stevel #define sd_state ssd_state 148 0 stevel #define sd_io_time ssd_io_time 149 0 stevel #define sd_failfast_enable ssd_failfast_enable 150 0 stevel #define sd_ua_retry_count ssd_ua_retry_count 151 0 stevel #define sd_report_pfa ssd_report_pfa 152 0 stevel #define sd_max_throttle ssd_max_throttle 153 0 stevel #define sd_min_throttle ssd_min_throttle 154 0 stevel #define sd_rot_delay ssd_rot_delay 155 0 stevel 156 0 stevel #define sd_retry_on_reservation_conflict \ 157 0 stevel ssd_retry_on_reservation_conflict 158 0 stevel #define sd_reinstate_resv_delay ssd_reinstate_resv_delay 159 0 stevel #define sd_resv_conflict_name ssd_resv_conflict_name 160 0 stevel 161 0 stevel #define sd_component_mask ssd_component_mask 162 0 stevel #define sd_level_mask ssd_level_mask 163 0 stevel #define sd_debug_un ssd_debug_un 164 0 stevel #define sd_error_level ssd_error_level 165 0 stevel 166 0 stevel #define sd_xbuf_active_limit ssd_xbuf_active_limit 167 0 stevel #define sd_xbuf_reserve_limit ssd_xbuf_reserve_limit 168 0 stevel 169 0 stevel #define sd_tr ssd_tr 170 0 stevel #define sd_reset_throttle_timeout ssd_reset_throttle_timeout 171 666 ts143224 #define sd_qfull_throttle_timeout ssd_qfull_throttle_timeout 172 666 ts143224 #define sd_qfull_throttle_enable ssd_qfull_throttle_enable 173 0 stevel #define sd_check_media_time ssd_check_media_time 174 0 stevel #define sd_wait_cmds_complete ssd_wait_cmds_complete 175 0 stevel #define sd_label_mutex ssd_label_mutex 176 0 stevel #define sd_detach_mutex ssd_detach_mutex 177 0 stevel #define sd_log_buf ssd_log_buf 178 0 stevel #define sd_log_mutex ssd_log_mutex 179 0 stevel 180 0 stevel #define sd_disk_table ssd_disk_table 181 0 stevel #define sd_disk_table_size ssd_disk_table_size 182 0 stevel #define sd_sense_mutex ssd_sense_mutex 183 0 stevel #define sd_cdbtab ssd_cdbtab 184 0 stevel 185 0 stevel #define sd_cb_ops ssd_cb_ops 186 0 stevel #define sd_ops ssd_ops 187 0 stevel #define sd_additional_codes ssd_additional_codes 188 3525 shidokht #define sd_tgops ssd_tgops 189 0 stevel 190 0 stevel #define sd_minor_data ssd_minor_data 191 0 stevel #define sd_minor_data_efi ssd_minor_data_efi 192 0 stevel 193 0 stevel #define sd_tq ssd_tq 194 0 stevel #define sd_wmr_tq ssd_wmr_tq 195 0 stevel #define sd_taskq_name ssd_taskq_name 196 0 stevel #define sd_wmr_taskq_name ssd_wmr_taskq_name 197 0 stevel #define sd_taskq_minalloc ssd_taskq_minalloc 198 0 stevel #define sd_taskq_maxalloc ssd_taskq_maxalloc 199 0 stevel 200 0 stevel #define sd_dump_format_string ssd_dump_format_string 201 0 stevel 202 0 stevel #define sd_iostart_chain ssd_iostart_chain 203 0 stevel #define sd_iodone_chain ssd_iodone_chain 204 0 stevel 205 0 stevel #define sd_pm_idletime ssd_pm_idletime 206 0 stevel 207 0 stevel #define sd_force_pm_supported ssd_force_pm_supported 208 0 stevel 209 0 stevel #define sd_dtype_optical_bind ssd_dtype_optical_bind 210 666 ts143224 211 7570 David #define sd_ssc_init ssd_ssc_init 212 7570 David #define sd_ssc_send ssd_ssc_send 213 7570 David #define sd_ssc_fini ssd_ssc_fini 214 7570 David #define sd_ssc_assessment ssd_ssc_assessment 215 7570 David #define sd_ssc_post ssd_ssc_post 216 7570 David #define sd_ssc_print ssd_ssc_print 217 7570 David #define sd_ssc_ereport_post ssd_ssc_ereport_post 218 7570 David #define sd_ssc_set_info ssd_ssc_set_info 219 7570 David #define sd_ssc_extract_info ssd_ssc_extract_info 220 7570 David 221 7570 David #endif 222 0 stevel 223 0 stevel #ifdef SDDEBUG 224 0 stevel int sd_force_pm_supported = 0; 225 0 stevel #endif /* SDDEBUG */ 226 0 stevel 227 0 stevel void *sd_state = NULL; 228 0 stevel int sd_io_time = SD_IO_TIME; 229 0 stevel int sd_failfast_enable = 1; 230 0 stevel int sd_ua_retry_count = SD_UA_RETRY_COUNT; 231 0 stevel int sd_report_pfa = 1; 232 0 stevel int sd_max_throttle = SD_MAX_THROTTLE; 233 0 stevel int sd_min_throttle = SD_MIN_THROTTLE; 234 0 stevel int sd_rot_delay = 4; /* Default 4ms Rotation delay */ 235 666 ts143224 int sd_qfull_throttle_enable = TRUE; 236 0 stevel 237 0 stevel int sd_retry_on_reservation_conflict = 1; 238 0 stevel int sd_reinstate_resv_delay = SD_REINSTATE_RESV_DELAY; 239 0 stevel _NOTE(SCHEME_PROTECTS_DATA("safe sharing", sd_reinstate_resv_delay)) 240 0 stevel 241 0 stevel static int sd_dtype_optical_bind = -1; 242 0 stevel 243 0 stevel /* Note: the following is not a bug, it really is "sd_" and not "ssd_" */ 244 0 stevel static char *sd_resv_conflict_name = "sd_retry_on_reservation_conflict"; 245 0 stevel 246 0 stevel /* 247 0 stevel * Global data for debug logging. To enable debug printing, sd_component_mask 248 0 stevel * and sd_level_mask should be set to the desired bit patterns as outlined in 249 0 stevel * sddef.h. 250 0 stevel */ 251 0 stevel uint_t sd_component_mask = 0x0; 252 0 stevel uint_t sd_level_mask = 0x0; 253 0 stevel struct sd_lun *sd_debug_un = NULL; 254 0 stevel uint_t sd_error_level = SCSI_ERR_RETRYABLE; 255 0 stevel 256 0 stevel /* Note: these may go away in the future... */ 257 0 stevel static uint32_t sd_xbuf_active_limit = 512; 258 0 stevel static uint32_t sd_xbuf_reserve_limit = 16; 259 0 stevel 260 0 stevel static struct sd_resv_reclaim_request sd_tr = { NULL, NULL, NULL, 0, 0, 0 }; 261 0 stevel 262 0 stevel /* 263 0 stevel * Timer value used to reset the throttle after it has been reduced 264 666 ts143224 * (typically in response to TRAN_BUSY or STATUS_QFULL) 265 0 stevel */ 266 0 stevel static int sd_reset_throttle_timeout = SD_RESET_THROTTLE_TIMEOUT; 267 666 ts143224 static int sd_qfull_throttle_timeout = SD_QFULL_THROTTLE_TIMEOUT; 268 0 stevel 269 0 stevel /* 270 0 stevel * Interval value associated with the media change scsi watch. 271 0 stevel */ 272 0 stevel static int sd_check_media_time = 3000000; 273 0 stevel 274 0 stevel /* 275 0 stevel * Wait value used for in progress operations during a DDI_SUSPEND 276 0 stevel */ 277 0 stevel static int sd_wait_cmds_complete = SD_WAIT_CMDS_COMPLETE; 278 0 stevel 279 0 stevel /* 280 0 stevel * sd_label_mutex protects a static buffer used in the disk label 281 0 stevel * component of the driver 282 0 stevel */ 283 0 stevel static kmutex_t sd_label_mutex; 284 0 stevel 285 0 stevel /* 286 0 stevel * sd_detach_mutex protects un_layer_count, un_detach_count, and 287 0 stevel * un_opens_in_progress in the sd_lun structure. 288 0 stevel */ 289 0 stevel static kmutex_t sd_detach_mutex; 290 0 stevel 291 0 stevel _NOTE(MUTEX_PROTECTS_DATA(sd_detach_mutex, 292 0 stevel sd_lun::{un_layer_count un_detach_count un_opens_in_progress})) 293 0 stevel 294 0 stevel /* 295 0 stevel * Global buffer and mutex for debug logging 296 0 stevel */ 297 0 stevel static char sd_log_buf[1024]; 298 0 stevel static kmutex_t sd_log_mutex; 299 0 stevel 300 2683 yl194034 /* 301 2683 yl194034 * Structs and globals for recording attached lun information. 302 2683 yl194034 * This maintains a chain. Each node in the chain represents a SCSI controller. 303 2683 yl194034 * The structure records the number of luns attached to each target connected 304 2683 yl194034 * with the controller. 305 2683 yl194034 * For parallel scsi device only. 306 2683 yl194034 */ 307 2683 yl194034 struct sd_scsi_hba_tgt_lun { 308 2683 yl194034 struct sd_scsi_hba_tgt_lun *next; 309 2683 yl194034 dev_info_t *pdip; 310 2683 yl194034 int nlun[NTARGETS_WIDE]; 311 2683 yl194034 }; 312 2683 yl194034 313 2683 yl194034 /* 314 2683 yl194034 * Flag to indicate the lun is attached or detached 315 2683 yl194034 */ 316 2683 yl194034 #define SD_SCSI_LUN_ATTACH 0 317 2683 yl194034 #define SD_SCSI_LUN_DETACH 1 318 2683 yl194034 319 2683 yl194034 static kmutex_t sd_scsi_target_lun_mutex; 320 2683 yl194034 static struct sd_scsi_hba_tgt_lun *sd_scsi_target_lun_head = NULL; 321 2683 yl194034 322 2683 yl194034 _NOTE(MUTEX_PROTECTS_DATA(sd_scsi_target_lun_mutex, 323 2683 yl194034 sd_scsi_hba_tgt_lun::next sd_scsi_hba_tgt_lun::pdip)) 324 2683 yl194034 325 2683 yl194034 _NOTE(MUTEX_PROTECTS_DATA(sd_scsi_target_lun_mutex, 326 2683 yl194034 sd_scsi_target_lun_head)) 327 0 stevel 328 0 stevel /* 329 0 stevel * "Smart" Probe Caching structs, globals, #defines, etc. 330 0 stevel * For parallel scsi and non-self-identify device only. 331 0 stevel */ 332 0 stevel 333 0 stevel /* 334 0 stevel * The following resources and routines are implemented to support 335 0 stevel * "smart" probing, which caches the scsi_probe() results in an array, 336 0 stevel * in order to help avoid long probe times. 337 0 stevel */ 338 0 stevel struct sd_scsi_probe_cache { 339 0 stevel struct sd_scsi_probe_cache *next; 340 0 stevel dev_info_t *pdip; 341 0 stevel int cache[NTARGETS_WIDE]; 342 0 stevel }; 343 0 stevel 344 0 stevel static kmutex_t sd_scsi_probe_cache_mutex; 345 0 stevel static struct sd_scsi_probe_cache *sd_scsi_probe_cache_head = NULL; 346 0 stevel 347 0 stevel /* 348 0 stevel * Really we only need protection on the head of the linked list, but 349 0 stevel * better safe than sorry. 350 0 stevel */ 351 0 stevel _NOTE(MUTEX_PROTECTS_DATA(sd_scsi_probe_cache_mutex, 352 0 stevel sd_scsi_probe_cache::next sd_scsi_probe_cache::pdip)) 353 0 stevel 354 0 stevel _NOTE(MUTEX_PROTECTS_DATA(sd_scsi_probe_cache_mutex, 355 0 stevel sd_scsi_probe_cache_head)) 356 0 stevel 357 10131 Jane /* 358 10131 Jane * Power attribute table 359 10131 Jane */ 360 10131 Jane static sd_power_attr_ss sd_pwr_ss = { 361 10131 Jane { "NAME=spindle-motor", "0=off", "1=on", NULL }, 362 10131 Jane {0, 100}, 363 10131 Jane {30, 0}, 364 10131 Jane {20000, 0} 365 10131 Jane }; 366 10131 Jane 367 10131 Jane static sd_power_attr_pc sd_pwr_pc = { 368 10131 Jane { "NAME=spindle-motor", "0=stopped", "1=standby", "2=idle", 369 10131 Jane "3=active", NULL }, 370 10131 Jane {0, 0, 0, 100}, 371 10131 Jane {90, 90, 20, 0}, 372 10131 Jane {15000, 15000, 1000, 0} 373 10131 Jane }; 374 10131 Jane 375 10131 Jane /* 376 10131 Jane * Power level to power condition 377 10131 Jane */ 378 10131 Jane static int sd_pl2pc[] = { 379 10131 Jane SD_TARGET_START_VALID, 380 10131 Jane SD_TARGET_STANDBY, 381 10131 Jane SD_TARGET_IDLE, 382 10131 Jane SD_TARGET_ACTIVE 383 10131 Jane }; 384 0 stevel 385 0 stevel /* 386 0 stevel * Vendor specific data name property declarations 387 0 stevel */ 388 0 stevel 389 0 stevel #if defined(__fibre) || defined(__i386) ||defined(__amd64) 390 0 stevel 391 0 stevel static sd_tunables seagate_properties = { 392 0 stevel SEAGATE_THROTTLE_VALUE, 393 0 stevel 0, 394 0 stevel 0, 395 0 stevel 0, 396 0 stevel 0, 397 0 stevel 0, 398 0 stevel 0, 399 0 stevel 0, 400 0 stevel 0 401 0 stevel }; 402 0 stevel 403 0 stevel 404 0 stevel static sd_tunables fujitsu_properties = { 405 0 stevel FUJITSU_THROTTLE_VALUE, 406 0 stevel 0, 407 0 stevel 0, 408 0 stevel 0, 409 0 stevel 0, 410 0 stevel 0, 411 0 stevel 0, 412 0 stevel 0, 413 0 stevel 0 414 0 stevel }; 415 0 stevel 416 0 stevel static sd_tunables ibm_properties = { 417 0 stevel IBM_THROTTLE_VALUE, 418 0 stevel 0, 419 0 stevel 0, 420 0 stevel 0, 421 0 stevel 0, 422 0 stevel 0, 423 0 stevel 0, 424 0 stevel 0, 425 0 stevel 0 426 0 stevel }; 427 0 stevel 428 0 stevel static sd_tunables purple_properties = { 429 0 stevel PURPLE_THROTTLE_VALUE, 430 0 stevel 0, 431 0 stevel 0, 432 0 stevel PURPLE_BUSY_RETRIES, 433 0 stevel PURPLE_RESET_RETRY_COUNT, 434 0 stevel PURPLE_RESERVE_RELEASE_TIME, 435 0 stevel 0, 436 0 stevel 0, 437 0 stevel 0 438 0 stevel }; 439 0 stevel 440 0 stevel static sd_tunables sve_properties = { 441 0 stevel SVE_THROTTLE_VALUE, 442 0 stevel 0, 443 0 stevel 0, 444 0 stevel SVE_BUSY_RETRIES, 445 0 stevel SVE_RESET_RETRY_COUNT, 446 0 stevel SVE_RESERVE_RELEASE_TIME, 447 0 stevel SVE_MIN_THROTTLE_VALUE, 448 0 stevel SVE_DISKSORT_DISABLED_FLAG, 449 0 stevel 0 450 0 stevel }; 451 0 stevel 452 0 stevel static sd_tunables maserati_properties = { 453 0 stevel 0, 454 0 stevel 0, 455 0 stevel 0, 456 0 stevel 0, 457 0 stevel 0, 458 0 stevel 0, 459 0 stevel 0, 460 0 stevel MASERATI_DISKSORT_DISABLED_FLAG, 461 0 stevel MASERATI_LUN_RESET_ENABLED_FLAG 462 0 stevel }; 463 0 stevel 464 0 stevel static sd_tunables pirus_properties = { 465 0 stevel PIRUS_THROTTLE_VALUE, 466 0 stevel 0, 467 0 stevel PIRUS_NRR_COUNT, 468 0 stevel PIRUS_BUSY_RETRIES, 469 0 stevel PIRUS_RESET_RETRY_COUNT, 470 0 stevel 0, 471 0 stevel PIRUS_MIN_THROTTLE_VALUE, 472 0 stevel PIRUS_DISKSORT_DISABLED_FLAG, 473 0 stevel PIRUS_LUN_RESET_ENABLED_FLAG 474 0 stevel }; 475 0 stevel 476 0 stevel #endif 477 313 ts143224 478 0 stevel #if (defined(__sparc) && !defined(__fibre)) || \ 479 0 stevel (defined(__i386) || defined(__amd64)) 480 0 stevel 481 313 ts143224 482 313 ts143224 static sd_tunables elite_properties = { 483 313 ts143224 ELITE_THROTTLE_VALUE, 484 313 ts143224 0, 485 313 ts143224 0, 486 313 ts143224 0, 487 313 ts143224 0, 488 313 ts143224 0, 489 313 ts143224 0, 490 313 ts143224 0, 491 313 ts143224 0 492 313 ts143224 }; 493 313 ts143224 494 313 ts143224 static sd_tunables st31200n_properties = { 495 313 ts143224 ST31200N_THROTTLE_VALUE, 496 313 ts143224 0, 497 313 ts143224 0, 498 313 ts143224 0, 499 313 ts143224 0, 500 313 ts143224 0, 501 313 ts143224 0, 502 313 ts143224 0, 503 313 ts143224 0 504 313 ts143224 }; 505 313 ts143224 506 313 ts143224 #endif /* Fibre or not */ 507 313 ts143224 508 0 stevel static sd_tunables lsi_properties_scsi = { 509 0 stevel LSI_THROTTLE_VALUE, 510 0 stevel 0, 511 0 stevel LSI_NOTREADY_RETRIES, 512 0 stevel 0, 513 0 stevel 0, 514 0 stevel 0, 515 0 stevel 0, 516 0 stevel 0, 517 0 stevel 0 518 0 stevel }; 519 0 stevel 520 0 stevel static sd_tunables symbios_properties = { 521 0 stevel SYMBIOS_THROTTLE_VALUE, 522 0 stevel 0, 523 0 stevel SYMBIOS_NOTREADY_RETRIES, 524 0 stevel 0, 525 0 stevel 0, 526 0 stevel 0, 527 0 stevel 0, 528 0 stevel 0, 529 0 stevel 0 530 0 stevel }; 531 0 stevel 532 313 ts143224 static sd_tunables lsi_properties = { 533 313 ts143224 0, 534 313 ts143224 0, 535 313 ts143224 LSI_NOTREADY_RETRIES, 536 313 ts143224 0, 537 313 ts143224 0, 538 313 ts143224 0, 539 313 ts143224 0, 540 313 ts143224 0, 541 313 ts143224 0 542 313 ts143224 }; 543 313 ts143224 544 313 ts143224 static sd_tunables lsi_oem_properties = { 545 313 ts143224 0, 546 313 ts143224 0, 547 313 ts143224 LSI_OEM_NOTREADY_RETRIES, 548 313 ts143224 0, 549 313 ts143224 0, 550 313 ts143224 0, 551 313 ts143224 0, 552 313 ts143224 0, 553 5065 gz161490 0, 554 5065 gz161490 1 555 313 ts143224 }; 556 0 stevel 557 0 stevel 558 0 stevel 559 0 stevel #if (defined(SD_PROP_TST)) 560 0 stevel 561 0 stevel #define SD_TST_CTYPE_VAL CTYPE_CDROM 562 0 stevel #define SD_TST_THROTTLE_VAL 16 563 0 stevel #define SD_TST_NOTREADY_VAL 12 564 0 stevel #define SD_TST_BUSY_VAL 60 565 0 stevel #define SD_TST_RST_RETRY_VAL 36 566 0 stevel #define SD_TST_RSV_REL_TIME 60 567 0 stevel 568 0 stevel static sd_tunables tst_properties = { 569 0 stevel SD_TST_THROTTLE_VAL, 570 0 stevel SD_TST_CTYPE_VAL, 571 0 stevel SD_TST_NOTREADY_VAL, 572 0 stevel SD_TST_BUSY_VAL, 573 0 stevel SD_TST_RST_RETRY_VAL, 574 0 stevel SD_TST_RSV_REL_TIME, 575 0 stevel 0, 576 0 stevel 0, 577 0 stevel 0 578 0 stevel }; 579 0 stevel #endif 580 0 stevel 581 4451 eschrock /* This is similar to the ANSI toupper implementation */ 582 0 stevel #define SD_TOUPPER(C) (((C) >= 'a' && (C) <= 'z') ? (C) - 'a' + 'A' : (C)) 583 0 stevel 584 0 stevel /* 585 0 stevel * Static Driver Configuration Table 586 0 stevel * 587 0 stevel * This is the table of disks which need throttle adjustment (or, perhaps 588 0 stevel * something else as defined by the flags at a future time.) device_id 589 0 stevel * is a string consisting of concatenated vid (vendor), pid (product/model) 590 0 stevel * and revision strings as defined in the scsi_inquiry structure. Offsets of 591 0 stevel * the parts of the string are as defined by the sizes in the scsi_inquiry 592 0 stevel * structure. Device type is searched as far as the device_id string is 593 0 stevel * defined. Flags defines which values are to be set in the driver from the 594 0 stevel * properties list. 595 0 stevel * 596 0 stevel * Entries below which begin and end with a "*" are a special case. 597 0 stevel * These do not have a specific vendor, and the string which follows 598 0 stevel * can appear anywhere in the 16 byte PID portion of the inquiry data. 599 0 stevel * 600 0 stevel * Entries below which begin and end with a " " (blank) are a special 601 0 stevel * case. The comparison function will treat multiple consecutive blanks 602 0 stevel * as equivalent to a single blank. For example, this causes a 603 0 stevel * sd_disk_table entry of " NEC CDROM " to match a device's id string 604 0 stevel * of "NEC CDROM". 605 0 stevel * 606 0 stevel * Note: The MD21 controller type has been obsoleted. 607 0 stevel * ST318202F is a Legacy device 608 0 stevel * MAM3182FC, MAM3364FC, MAM3738FC do not appear to have ever been 609 0 stevel * made with an FC connection. The entries here are a legacy. 610 0 stevel */ 611 0 stevel static sd_disk_config_t sd_disk_table[] = { 612 0 stevel #if defined(__fibre) || defined(__i386) || defined(__amd64) 613 0 stevel { "SEAGATE ST34371FC", SD_CONF_BSET_THROTTLE, &seagate_properties }, 614 0 stevel { "SEAGATE ST19171FC", SD_CONF_BSET_THROTTLE, &seagate_properties }, 615 0 stevel { "SEAGATE ST39102FC", SD_CONF_BSET_THROTTLE, &seagate_properties }, 616 0 stevel { "SEAGATE ST39103FC", SD_CONF_BSET_THROTTLE, &seagate_properties }, 617 0 stevel { "SEAGATE ST118273F", SD_CONF_BSET_THROTTLE, &seagate_properties }, 618 0 stevel { "SEAGATE ST318202F", SD_CONF_BSET_THROTTLE, &seagate_properties }, 619 0 stevel { "SEAGATE ST318203F", SD_CONF_BSET_THROTTLE, &seagate_properties }, 620 0 stevel { "SEAGATE ST136403F", SD_CONF_BSET_THROTTLE, &seagate_properties }, 621 0 stevel { "SEAGATE ST318304F", SD_CONF_BSET_THROTTLE, &seagate_properties }, 622 0 stevel { "SEAGATE ST336704F", SD_CONF_BSET_THROTTLE, &seagate_properties }, 623 0 stevel { "SEAGATE ST373405F", SD_CONF_BSET_THROTTLE, &seagate_properties }, 624 0 stevel { "SEAGATE ST336605F", SD_CONF_BSET_THROTTLE, &seagate_properties }, 625 0 stevel { "SEAGATE ST336752F", SD_CONF_BSET_THROTTLE, &seagate_properties }, 626 0 stevel { "SEAGATE ST318452F", SD_CONF_BSET_THROTTLE, &seagate_properties }, 627 0 stevel { "FUJITSU MAG3091F", SD_CONF_BSET_THROTTLE, &fujitsu_properties }, 628 0 stevel { "FUJITSU MAG3182F", SD_CONF_BSET_THROTTLE, &fujitsu_properties }, 629 0 stevel { "FUJITSU MAA3182F", SD_CONF_BSET_THROTTLE, &fujitsu_properties }, 630 0 stevel { "FUJITSU MAF3364F", SD_CONF_BSET_THROTTLE, &fujitsu_properties }, 631 0 stevel { "FUJITSU MAL3364F", SD_CONF_BSET_THROTTLE, &fujitsu_properties }, 632 0 stevel { "FUJITSU MAL3738F", SD_CONF_BSET_THROTTLE, &fujitsu_properties }, 633 0 stevel { "FUJITSU MAM3182FC", SD_CONF_BSET_THROTTLE, &fujitsu_properties }, 634 0 stevel { "FUJITSU MAM3364FC", SD_CONF_BSET_THROTTLE, &fujitsu_properties }, 635 0 stevel { "FUJITSU MAM3738FC", SD_CONF_BSET_THROTTLE, &fujitsu_properties }, 636 0 stevel { "IBM DDYFT1835", SD_CONF_BSET_THROTTLE, &ibm_properties }, 637 0 stevel { "IBM DDYFT3695", SD_CONF_BSET_THROTTLE, &ibm_properties }, 638 0 stevel { "IBM IC35LF2D2", SD_CONF_BSET_THROTTLE, &ibm_properties }, 639 0 stevel { "IBM IC35LF2PR", SD_CONF_BSET_THROTTLE, &ibm_properties }, 640 4364 sd210035 { "IBM 1724-100", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 641 3209 rb150246 { "IBM 1726-2xx", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 642 4727 sd210035 { "IBM 1726-22x", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 643 3209 rb150246 { "IBM 1726-4xx", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 644 4727 sd210035 { "IBM 1726-42x", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 645 3209 rb150246 { "IBM 1726-3xx", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 646 0 stevel { "IBM 3526", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 647 0 stevel { "IBM 3542", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 648 0 stevel { "IBM 3552", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 649 0 stevel { "IBM 1722", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 650 0 stevel { "IBM 1742", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 651 130 bs135383 { "IBM 1815", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 652 0 stevel { "IBM FAStT", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 653 2030 rb150246 { "IBM 1814", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 654 2030 rb150246 { "IBM 1814-200", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 655 6311 sd210035 { "IBM 1818", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 656 6985 jw149990 { "DELL MD3000", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 657 6985 jw149990 { "DELL MD3000i", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 658 0 stevel { "LSI INF", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 659 130 bs135383 { "ENGENIO INF", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 660 130 bs135383 { "SGI TP", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 661 130 bs135383 { "SGI IS", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 662 5065 gz161490 { "*CSM100_*", SD_CONF_BSET_NRR_COUNT | 663 5065 gz161490 SD_CONF_BSET_CACHE_IS_NV, &lsi_oem_properties }, 664 5065 gz161490 { "*CSM200_*", SD_CONF_BSET_NRR_COUNT | 665 5065 gz161490 SD_CONF_BSET_CACHE_IS_NV, &lsi_oem_properties }, 666 2030 rb150246 { "Fujitsu SX300", SD_CONF_BSET_THROTTLE, &lsi_oem_properties }, 667 0 stevel { "LSI", SD_CONF_BSET_NRR_COUNT, &lsi_properties }, 668 0 stevel { "SUN T3", SD_CONF_BSET_THROTTLE | 669 0 stevel SD_CONF_BSET_BSY_RETRY_COUNT| 670 0 stevel SD_CONF_BSET_RST_RETRIES| 671 0 stevel SD_CONF_BSET_RSV_REL_TIME, 672 0 stevel &purple_properties }, 673 0 stevel { "SUN SESS01", SD_CONF_BSET_THROTTLE | 674 0 stevel SD_CONF_BSET_BSY_RETRY_COUNT| 675 0 stevel SD_CONF_BSET_RST_RETRIES| 676 0 stevel SD_CONF_BSET_RSV_REL_TIME| 677 0 stevel SD_CONF_BSET_MIN_THROTTLE| 678 0 stevel SD_CONF_BSET_DISKSORT_DISABLED, 679 0 stevel &sve_properties }, 680 0 stevel { "SUN T4", SD_CONF_BSET_THROTTLE | 681 0 stevel SD_CONF_BSET_BSY_RETRY_COUNT| 682 0 stevel SD_CONF_BSET_RST_RETRIES| 683 0 stevel SD_CONF_BSET_RSV_REL_TIME, 684 0 stevel &purple_properties }, 685 0 stevel { "SUN SVE01", SD_CONF_BSET_DISKSORT_DISABLED | 686 0 stevel SD_CONF_BSET_LUN_RESET_ENABLED, 687 0 stevel &maserati_properties }, 688 0 stevel { "SUN SE6920", SD_CONF_BSET_THROTTLE | 689 897 bs135383 SD_CONF_BSET_NRR_COUNT| 690 897 bs135383 SD_CONF_BSET_BSY_RETRY_COUNT| 691 897 bs135383 SD_CONF_BSET_RST_RETRIES| 692 897 bs135383 SD_CONF_BSET_MIN_THROTTLE| 693 897 bs135383 SD_CONF_BSET_DISKSORT_DISABLED| 694 897 bs135383 SD_CONF_BSET_LUN_RESET_ENABLED, 695 897 bs135383 &pirus_properties }, 696 897 bs135383 { "SUN SE6940", SD_CONF_BSET_THROTTLE | 697 897 bs135383 SD_CONF_BSET_NRR_COUNT| 698 897 bs135383 SD_CONF_BSET_BSY_RETRY_COUNT| 699 897 bs135383 SD_CONF_BSET_RST_RETRIES| 700 897 bs135383 SD_CONF_BSET_MIN_THROTTLE| 701 897 bs135383 SD_CONF_BSET_DISKSORT_DISABLED| 702 897 bs135383 SD_CONF_BSET_LUN_RESET_ENABLED, 703 897 bs135383 &pirus_properties }, 704 897 bs135383 { "SUN StorageTek 6920", SD_CONF_BSET_THROTTLE | 705 897 bs135383 SD_CONF_BSET_NRR_COUNT| 706 897 bs135383 SD_CONF_BSET_BSY_RETRY_COUNT| 707 897 bs135383 SD_CONF_BSET_RST_RETRIES| 708 897 bs135383 SD_CONF_BSET_MIN_THROTTLE| 709 897 bs135383 SD_CONF_BSET_DISKSORT_DISABLED| 710 897 bs135383 SD_CONF_BSET_LUN_RESET_ENABLED, 711 897 bs135383 &pirus_properties }, 712 897 bs135383 { "SUN StorageTek 6940", SD_CONF_BSET_THROTTLE | 713 0 stevel SD_CONF_BSET_NRR_COUNT| 714 0 stevel SD_CONF_BSET_BSY_RETRY_COUNT| 715 0 stevel SD_CONF_BSET_RST_RETRIES| 716 0 stevel SD_CONF_BSET_MIN_THROTTLE| 717 0 stevel SD_CONF_BSET_DISKSORT_DISABLED| 718 0 stevel SD_CONF_BSET_LUN_RESET_ENABLED, 719 0 stevel &pirus_properties }, 720 0 stevel { "SUN PSX1000", SD_CONF_BSET_THROTTLE | 721 0 stevel SD_CONF_BSET_NRR_COUNT| 722 0 stevel SD_CONF_BSET_BSY_RETRY_COUNT| 723 0 stevel SD_CONF_BSET_RST_RETRIES| 724 0 stevel SD_CONF_BSET_MIN_THROTTLE| 725 0 stevel SD_CONF_BSET_DISKSORT_DISABLED| 726 0 stevel SD_CONF_BSET_LUN_RESET_ENABLED, 727 0 stevel &pirus_properties }, 728 0 stevel { "SUN SE6330", SD_CONF_BSET_THROTTLE | 729 0 stevel SD_CONF_BSET_NRR_COUNT| 730 0 stevel SD_CONF_BSET_BSY_RETRY_COUNT| 731 0 stevel SD_CONF_BSET_RST_RETRIES| 732 0 stevel SD_CONF_BSET_MIN_THROTTLE| 733 0 stevel SD_CONF_BSET_DISKSORT_DISABLED| 734 0 stevel SD_CONF_BSET_LUN_RESET_ENABLED, 735 0 stevel &pirus_properties }, 736 6311 sd210035 { "SUN STK6580_6780", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 737 10090 Bing { "SUN SUN_6180", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 738 0 stevel { "STK OPENstorage", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 739 0 stevel { "STK OpenStorage", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 740 0 stevel { "STK BladeCtlr", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 741 130 bs135383 { "STK FLEXLINE", SD_CONF_BSET_NRR_COUNT, &lsi_oem_properties }, 742 0 stevel { "SYMBIOS", SD_CONF_BSET_NRR_COUNT, &symbios_properties }, 743 0 stevel #endif /* fibre or NON-sparc platforms */ 744 0 stevel #if ((defined(__sparc) && !defined(__fibre)) ||\ 745 0 stevel (defined(__i386) || defined(__amd64))) 746 0 stevel { "SEAGATE ST42400N", SD_CONF_BSET_THROTTLE, &elite_properties }, 747 0 stevel { "SEAGATE ST31200N", SD_CONF_BSET_THROTTLE, &st31200n_properties }, 748 0 stevel { "SEAGATE ST41600N", SD_CONF_BSET_TUR_CHECK, NULL }, 749 0 stevel { "CONNER CP30540", SD_CONF_BSET_NOCACHE, NULL }, 750 0 stevel { "*SUN0104*", SD_CONF_BSET_FAB_DEVID, NULL }, 751 0 stevel { "*SUN0207*", SD_CONF_BSET_FAB_DEVID, NULL }, 752 0 stevel { "*SUN0327*", SD_CONF_BSET_FAB_DEVID, NULL }, 753 0 stevel { "*SUN0340*", SD_CONF_BSET_FAB_DEVID, NULL }, 754 0 stevel { "*SUN0424*", SD_CONF_BSET_FAB_DEVID, NULL }, 755 0 stevel { "*SUN0669*", SD_CONF_BSET_FAB_DEVID, NULL }, 756 0 stevel { "*SUN1.0G*", SD_CONF_BSET_FAB_DEVID, NULL }, 757 0 stevel { "SYMBIOS INF-01-00 ", SD_CONF_BSET_FAB_DEVID, NULL }, 758 0 stevel { "SYMBIOS", SD_CONF_BSET_THROTTLE|SD_CONF_BSET_NRR_COUNT, 759 0 stevel &symbios_properties }, 760 0 stevel { "LSI", SD_CONF_BSET_THROTTLE | SD_CONF_BSET_NRR_COUNT, 761 0 stevel &lsi_properties_scsi }, 762 0 stevel #if defined(__i386) || defined(__amd64) 763 0 stevel { " NEC CD-ROM DRIVE:260 ", (SD_CONF_BSET_PLAYMSF_BCD 764 0 stevel | SD_CONF_BSET_READSUB_BCD 765 0 stevel | SD_CONF_BSET_READ_TOC_ADDR_BCD 766 0 stevel | SD_CONF_BSET_NO_READ_HEADER 767 0 stevel | SD_CONF_BSET_READ_CD_XD4), NULL }, 768 0 stevel 769 0 stevel { " NEC CD-ROM DRIVE:270 ", (SD_CONF_BSET_PLAYMSF_BCD 770 0 stevel | SD_CONF_BSET_READSUB_BCD 771 0 stevel | SD_CONF_BSET_READ_TOC_ADDR_BCD 772 0 stevel | SD_CONF_BSET_NO_READ_HEADER 773 0 stevel | SD_CONF_BSET_READ_CD_XD4), NULL }, 774 0 stevel #endif /* __i386 || __amd64 */ 775 0 stevel #endif /* sparc NON-fibre or NON-sparc platforms */ 776 0 stevel 777 0 stevel #if (defined(SD_PROP_TST)) 778 0 stevel { "VENDOR PRODUCT ", (SD_CONF_BSET_THROTTLE 779 0 stevel | SD_CONF_BSET_CTYPE 780 0 stevel | SD_CONF_BSET_NRR_COUNT 781 0 stevel | SD_CONF_BSET_FAB_DEVID 782 0 stevel | SD_CONF_BSET_NOCACHE 783 0 stevel | SD_CONF_BSET_BSY_RETRY_COUNT 784 0 stevel | SD_CONF_BSET_PLAYMSF_BCD 785 0 stevel | SD_CONF_BSET_READSUB_BCD 786 0 stevel | SD_CONF_BSET_READ_TOC_TRK_BCD 787 0 stevel | SD_CONF_BSET_READ_TOC_ADDR_BCD 788 0 stevel | SD_CONF_BSET_NO_READ_HEADER 789 0 stevel | SD_CONF_BSET_READ_CD_XD4 790 0 stevel | SD_CONF_BSET_RST_RETRIES 791 0 stevel | SD_CONF_BSET_RSV_REL_TIME 792 0 stevel | SD_CONF_BSET_TUR_CHECK), &tst_properties}, 793 0 stevel #endif 794 0 stevel }; 795 0 stevel 796 0 stevel static const int sd_disk_table_size = 797 0 stevel sizeof (sd_disk_table)/ sizeof (sd_disk_config_t); 798 0 stevel 799 0 stevel 800 0 stevel 801 0 stevel #define SD_INTERCONNECT_PARALLEL 0 802 0 stevel #define SD_INTERCONNECT_FABRIC 1 803 0 stevel #define SD_INTERCONNECT_FIBRE 2 804 0 stevel #define SD_INTERCONNECT_SSA 3 805 2341 gz161490 #define SD_INTERCONNECT_SATA 4 806 9249 Javen #define SD_INTERCONNECT_SAS 5 807 9249 Javen 808 0 stevel #define SD_IS_PARALLEL_SCSI(un) \ 809 0 stevel ((un)->un_interconnect_type == SD_INTERCONNECT_PARALLEL) 810 2341 gz161490 #define SD_IS_SERIAL(un) \ 811 9249 Javen (((un)->un_interconnect_type == SD_INTERCONNECT_SATA) ||\ 812 9249 Javen ((un)->un_interconnect_type == SD_INTERCONNECT_SAS)) 813 0 stevel 814 0 stevel /* 815 0 stevel * Definitions used by device id registration routines 816 0 stevel */ 817 0 stevel #define VPD_HEAD_OFFSET 3 /* size of head for vpd page */ 818 0 stevel #define VPD_PAGE_LENGTH 3 /* offset for pge length data */ 819 0 stevel #define VPD_MODE_PAGE 1 /* offset into vpd pg for "page code" */ 820 0 stevel 821 0 stevel static kmutex_t sd_sense_mutex = {0}; 822 0 stevel 823 0 stevel /* 824 0 stevel * Macros for updates of the driver state 825 0 stevel */ 826 0 stevel #define New_state(un, s) \ 827 0 stevel (un)->un_last_state = (un)->un_state, (un)->un_state = (s) 828 0 stevel #define Restore_state(un) \ 829 0 stevel { uchar_t tmp = (un)->un_last_state; New_state((un), tmp); } 830 0 stevel 831 0 stevel static struct sd_cdbinfo sd_cdbtab[] = { 832 0 stevel { CDB_GROUP0, 0x00, 0x1FFFFF, 0xFF, }, 833 0 stevel { CDB_GROUP1, SCMD_GROUP1, 0xFFFFFFFF, 0xFFFF, }, 834 0 stevel { CDB_GROUP5, SCMD_GROUP5, 0xFFFFFFFF, 0xFFFFFFFF, }, 835 0 stevel { CDB_GROUP4, SCMD_GROUP4, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFF, }, 836 0 stevel }; 837 0 stevel 838 0 stevel /* 839 0 stevel * Specifies the number of seconds that must have elapsed since the last 840 0 stevel * cmd. has completed for a device to be declared idle to the PM framework. 841 0 stevel */ 842 0 stevel static int sd_pm_idletime = 1; 843 0 stevel 844 0 stevel /* 845 0 stevel * Internal function prototypes 846 0 stevel */ 847 0 stevel 848 0 stevel #if (defined(__fibre)) 849 0 stevel /* 850 0 stevel * These #defines are to avoid namespace collisions that occur because this 851 4451 eschrock * code is currently used to compile two separate driver modules: sd and ssd. 852 0 stevel * All function names need to be treated this way (even if declared static) 853 0 stevel * in order to allow the debugger to resolve the names properly. 854 0 stevel * It is anticipated that in the near future the ssd module will be obsoleted, 855 0 stevel * at which time this ugliness should go away. 856 0 stevel */ 857 0 stevel #define sd_log_trace ssd_log_trace 858 0 stevel #define sd_log_info ssd_log_info 859 0 stevel #define sd_log_err ssd_log_err 860 0 stevel #define sdprobe ssdprobe 861 0 stevel #define sdinfo ssdinfo 862 0 stevel #define sd_prop_op ssd_prop_op 863 0 stevel #define sd_scsi_probe_cache_init ssd_scsi_probe_cache_init 864 0 stevel #define sd_scsi_probe_cache_fini ssd_scsi_probe_cache_fini 865 0 stevel #define sd_scsi_clear_probe_cache ssd_scsi_clear_probe_cache 866 0 stevel #define sd_scsi_probe_with_cache ssd_scsi_probe_with_cache 867 2683 yl194034 #define sd_scsi_target_lun_init ssd_scsi_target_lun_init 868 2683 yl194034 #define sd_scsi_target_lun_fini ssd_scsi_target_lun_fini 869 2683 yl194034 #define sd_scsi_get_target_lun_count ssd_scsi_get_target_lun_count 870 2683 yl194034 #define sd_scsi_update_lun_on_target ssd_scsi_update_lun_on_target 871 0 stevel #define sd_spin_up_unit ssd_spin_up_unit 872 0 stevel #define sd_enable_descr_sense ssd_enable_descr_sense 873 2148 pd144616 #define sd_reenable_dsense_task ssd_reenable_dsense_task 874 0 stevel #define sd_set_mmc_caps ssd_set_mmc_caps 875 0 stevel #define sd_read_unit_properties ssd_read_unit_properties 876 0 stevel #define sd_process_sdconf_file ssd_process_sdconf_file 877 0 stevel #define sd_process_sdconf_table ssd_process_sdconf_table 878 0 stevel #define sd_sdconf_id_match ssd_sdconf_id_match 879 0 stevel #define sd_blank_cmp ssd_blank_cmp 880 0 stevel #define sd_chk_vers1_data ssd_chk_vers1_data 881 0 stevel #define sd_set_vers1_properties ssd_set_vers1_properties 882 10320 Larry #define sd_check_solid_state ssd_check_solid_state 883 3525 shidokht 884 0 stevel #define sd_get_physical_geometry ssd_get_physical_geometry 885 0 stevel #define sd_get_virtual_geometry ssd_get_virtual_geometry 886 0 stevel #define sd_update_block_info ssd_update_block_info 887 0 stevel #define sd_register_devid ssd_register_devid 888 0 stevel #define sd_get_devid ssd_get_devid 889 0 stevel #define sd_create_devid ssd_create_devid 890 0 stevel #define sd_write_deviceid ssd_write_deviceid 891 0 stevel #define sd_check_vpd_page_support ssd_check_vpd_page_support 892 0 stevel #define sd_setup_pm ssd_setup_pm 893 0 stevel #define sd_create_pm_components ssd_create_pm_components 894 0 stevel #define sd_ddi_suspend ssd_ddi_suspend 895 0 stevel #define sd_ddi_resume ssd_ddi_resume 896 10131 Jane #define sd_pm_state_change ssd_pm_state_change 897 0 stevel #define sdpower ssdpower 898 0 stevel #define sdattach ssdattach 899 0 stevel #define sddetach ssddetach 900 0 stevel #define sd_unit_attach ssd_unit_attach 901 0 stevel #define sd_unit_detach ssd_unit_detach 902 1415 cg149915 #define sd_set_unit_attributes ssd_set_unit_attributes 903 0 stevel #define sd_create_errstats ssd_create_errstats 904 0 stevel #define sd_set_errstats ssd_set_errstats 905 0 stevel #define sd_set_pstats ssd_set_pstats 906 0 stevel #define sddump ssddump 907 0 stevel #define sd_scsi_poll ssd_scsi_poll 908 0 stevel #define sd_send_polled_RQS ssd_send_polled_RQS 909 0 stevel #define sd_ddi_scsi_poll ssd_ddi_scsi_poll 910 0 stevel #define sd_init_event_callbacks ssd_init_event_callbacks 911 0 stevel #define sd_event_callback ssd_event_callback 912 1489 webaker #define sd_cache_control ssd_cache_control 913 789 ahrens #define sd_get_write_cache_enabled ssd_get_write_cache_enabled 914 5065 gz161490 #define sd_get_nv_sup ssd_get_nv_sup 915 0 stevel #define sd_make_device ssd_make_device 916 0 stevel #define sdopen ssdopen 917 0 stevel #define sdclose ssdclose 918 0 stevel #define sd_ready_and_valid ssd_ready_and_valid 919 0 stevel #define sdmin ssdmin 920 0 stevel #define sdread ssdread 921 0 stevel #define sdwrite ssdwrite 922 0 stevel #define sdaread ssdaread 923 0 stevel #define sdawrite ssdawrite 924 0 stevel #define sdstrategy ssdstrategy 925 0 stevel #define sdioctl ssdioctl 926 0 stevel #define sd_mapblockaddr_iostart ssd_mapblockaddr_iostart 927 0 stevel #define sd_mapblocksize_iostart ssd_mapblocksize_iostart 928 0 stevel #define sd_checksum_iostart ssd_checksum_iostart 929 0 stevel #define sd_checksum_uscsi_iostart ssd_checksum_uscsi_iostart 930 0 stevel #define sd_pm_iostart ssd_pm_iostart 931 0 stevel #define sd_core_iostart ssd_core_iostart 932 0 stevel #define sd_mapblockaddr_iodone ssd_mapblockaddr_iodone 933 0 stevel #define sd_mapblocksize_iodone ssd_mapblocksize_iodone 934 0 stevel #define sd_checksum_iodone ssd_checksum_iodone 935 0 stevel #define sd_checksum_uscsi_iodone ssd_checksum_uscsi_iodone 936 0 stevel #define sd_pm_iodone ssd_pm_iodone 937 0 stevel #define sd_initpkt_for_buf ssd_initpkt_for_buf 938 0 stevel #define sd_destroypkt_for_buf ssd_destroypkt_for_buf 939 0 stevel #define sd_setup_rw_pkt ssd_setup_rw_pkt 940 0 stevel #define sd_setup_next_rw_pkt ssd_setup_next_rw_pkt 941 0 stevel #define sd_buf_iodone ssd_buf_iodone 942 0 stevel #define sd_uscsi_strategy ssd_uscsi_strategy 943 0 stevel #define sd_initpkt_for_uscsi ssd_initpkt_for_uscsi 944 0 stevel #define sd_destroypkt_for_uscsi ssd_destroypkt_for_uscsi 945 0 stevel #define sd_uscsi_iodone ssd_uscsi_iodone 946 0 stevel #define sd_xbuf_strategy ssd_xbuf_strategy 947 0 stevel #define sd_xbuf_init ssd_xbuf_init 948 0 stevel #define sd_pm_entry ssd_pm_entry 949 0 stevel #define sd_pm_exit ssd_pm_exit 950 0 stevel 951 0 stevel #define sd_pm_idletimeout_handler ssd_pm_idletimeout_handler 952 0 stevel #define sd_pm_timeout_handler ssd_pm_timeout_handler 953 0 stevel 954 0 stevel #define sd_add_buf_to_waitq ssd_add_buf_to_waitq 955 0 stevel #define sdintr ssdintr 956 0 stevel #define sd_start_cmds ssd_start_cmds 957 0 stevel #define sd_send_scsi_cmd ssd_send_scsi_cmd 958 0 stevel #define sd_bioclone_alloc ssd_bioclone_alloc 959 0 stevel #define sd_bioclone_free ssd_bioclone_free 960 0 stevel #define sd_shadow_buf_alloc ssd_shadow_buf_alloc 961 0 stevel #define sd_shadow_buf_free ssd_shadow_buf_free 962 0 stevel #define sd_print_transport_rejected_message \ 963 0 stevel ssd_print_transport_rejected_message 964 0 stevel #define sd_retry_command ssd_retry_command 965 0 stevel #define sd_set_retry_bp ssd_set_retry_bp 966 0 stevel #define sd_send_request_sense_command ssd_send_request_sense_command 967 0 stevel #define sd_start_retry_command ssd_start_retry_command 968 0 stevel #define sd_start_direct_priority_command \ 969 0 stevel ssd_start_direct_priority_command 970 0 stevel #define sd_return_failed_command ssd_return_failed_command 971 0 stevel #define sd_return_failed_command_no_restart \ 972 0 stevel ssd_return_failed_command_no_restart 973 0 stevel #define sd_return_command ssd_return_command 974 0 stevel #define sd_sync_with_callback ssd_sync_with_callback 975 0 stevel #define sdrunout ssdrunout 976 0 stevel #define sd_mark_rqs_busy ssd_mark_rqs_busy 977 0 stevel #define sd_mark_rqs_idle ssd_mark_rqs_idle 978 0 stevel #define sd_reduce_throttle ssd_reduce_throttle 979 0 stevel #define sd_restore_throttle ssd_restore_throttle 980 0 stevel #define sd_print_incomplete_msg ssd_print_incomplete_msg 981 0 stevel #define sd_init_cdb_limits ssd_init_cdb_limits 982 0 stevel #define sd_pkt_status_good ssd_pkt_status_good 983 0 stevel #define sd_pkt_status_check_condition ssd_pkt_status_check_condition 984 0 stevel #define sd_pkt_status_busy ssd_pkt_status_busy 985 0 stevel #define sd_pkt_status_reservation_conflict \ 986 0 stevel ssd_pkt_status_reservation_conflict 987 0 stevel #define sd_pkt_status_qfull ssd_pkt_status_qfull 988 0 stevel #define sd_handle_request_sense ssd_handle_request_sense 989 0 stevel #define sd_handle_auto_request_sense ssd_handle_auto_request_sense 990 0 stevel #define sd_print_sense_failed_msg ssd_print_sense_failed_msg 991 0 stevel #define sd_validate_sense_data ssd_validate_sense_data 992 0 stevel #define sd_decode_sense ssd_decode_sense 993 0 stevel #define sd_print_sense_msg ssd_print_sense_msg 994 0 stevel #define sd_sense_key_no_sense ssd_sense_key_no_sense 995 0 stevel #define sd_sense_key_recoverable_error ssd_sense_key_recoverable_error 996 0 stevel #define sd_sense_key_not_ready ssd_sense_key_not_ready 997 0 stevel #define sd_sense_key_medium_or_hardware_error \ 998 0 stevel ssd_sense_key_medium_or_hardware_error 999 0 stevel #define sd_sense_key_illegal_request ssd_sense_key_illegal_request 1000 0 stevel #define sd_sense_key_unit_attention ssd_sense_key_unit_attention 1001 0 stevel #define sd_sense_key_fail_command ssd_sense_key_fail_command 1002 0 stevel #define sd_sense_key_blank_check ssd_sense_key_blank_check 1003 0 stevel #define sd_sense_key_aborted_command ssd_sense_key_aborted_command 1004 0 stevel #define sd_sense_key_default ssd_sense_key_default 1005 0 stevel #define sd_print_retry_msg ssd_print_retry_msg 1006 0 stevel #define sd_print_cmd_incomplete_msg ssd_print_cmd_incomplete_msg 1007 0 stevel #define sd_pkt_reason_cmd_incomplete ssd_pkt_reason_cmd_incomplete 1008 0 stevel #define sd_pkt_reason_cmd_tran_err ssd_pkt_reason_cmd_tran_err 1009 0 stevel #define sd_pkt_reason_cmd_reset ssd_pkt_reason_cmd_reset 1010 0 stevel #define sd_pkt_reason_cmd_aborted ssd_pkt_reason_cmd_aborted 1011 0 stevel #define sd_pkt_reason_cmd_timeout ssd_pkt_reason_cmd_timeout 1012 0 stevel #define sd_pkt_reason_cmd_unx_bus_free ssd_pkt_reason_cmd_unx_bus_free 1013 0 stevel #define sd_pkt_reason_cmd_tag_reject ssd_pkt_reason_cmd_tag_reject 1014 0 stevel #define sd_pkt_reason_default ssd_pkt_reason_default 1015 0 stevel #define sd_reset_target ssd_reset_target 1016 0 stevel #define sd_start_stop_unit_callback ssd_start_stop_unit_callback 1017 0 stevel #define sd_start_stop_unit_task ssd_start_stop_unit_task 1018 0 stevel #define sd_taskq_create ssd_taskq_create 1019 0 stevel #define sd_taskq_delete ssd_taskq_delete 1020 6590 yl194034 #define sd_target_change_task ssd_target_change_task 1021 10459 Artem #define sd_log_dev_status_event ssd_log_dev_status_event 1022 6590 yl194034 #define sd_log_lun_expansion_event ssd_log_lun_expansion_event 1023 10459 Artem #define sd_log_eject_request_event ssd_log_eject_request_event 1024 0 stevel #define sd_media_change_task ssd_media_change_task 1025 0 stevel #define sd_handle_mchange ssd_handle_mchange 1026 0 stevel #define sd_send_scsi_DOORLOCK ssd_send_scsi_DOORLOCK 1027 0 stevel #define sd_send_scsi_READ_CAPACITY ssd_send_scsi_READ_CAPACITY 1028 0 stevel #define sd_send_scsi_READ_CAPACITY_16 ssd_send_scsi_READ_CAPACITY_16 1029 0 stevel #define sd_send_scsi_GET_CONFIGURATION ssd_send_scsi_GET_CONFIGURATION 1030 0 stevel #define sd_send_scsi_feature_GET_CONFIGURATION \ 1031 0 stevel sd_send_scsi_feature_GET_CONFIGURATION 1032 0 stevel #define sd_send_scsi_START_STOP_UNIT ssd_send_scsi_START_STOP_UNIT 1033 0 stevel #define sd_send_scsi_INQUIRY ssd_send_scsi_INQUIRY 1034 0 stevel #define sd_send_scsi_TEST_UNIT_READY ssd_send_scsi_TEST_UNIT_READY 1035 0 stevel #define sd_send_scsi_PERSISTENT_RESERVE_IN \ 1036 0 stevel ssd_send_scsi_PERSISTENT_RESERVE_IN 1037 0 stevel #define sd_send_scsi_PERSISTENT_RESERVE_OUT \ 1038 0 stevel ssd_send_scsi_PERSISTENT_RESERVE_OUT 1039 0 stevel #define sd_send_scsi_SYNCHRONIZE_CACHE ssd_send_scsi_SYNCHRONIZE_CACHE 1040 789 ahrens #define sd_send_scsi_SYNCHRONIZE_CACHE_biodone \ 1041 789 ahrens ssd_send_scsi_SYNCHRONIZE_CACHE_biodone 1042 0 stevel #define sd_send_scsi_MODE_SENSE ssd_send_scsi_MODE_SENSE 1043 0 stevel #define sd_send_scsi_MODE_SELECT ssd_send_scsi_MODE_SELECT 1044 0 stevel #define sd_send_scsi_RDWR ssd_send_scsi_RDWR 1045 0 stevel #define sd_send_scsi_LOG_SENSE ssd_send_scsi_LOG_SENSE 1046 10459 Artem #define sd_send_scsi_GET_EVENT_STATUS_NOTIFICATION \ 1047 10459 Artem ssd_send_scsi_GET_EVENT_STATUS_NOTIFICATION 1048 10459 Artem #define sd_gesn_media_data_valid ssd_gesn_media_data_valid 1049 0 stevel #define sd_alloc_rqs ssd_alloc_rqs 1050 0 stevel #define sd_free_rqs ssd_free_rqs 1051 0 stevel #define sd_dump_memory ssd_dump_memory 1052 0 stevel #define sd_get_media_info ssd_get_media_info 1053 9889 Larry #define sd_get_media_info_ext ssd_get_media_info_ext 1054 0 stevel #define sd_dkio_ctrl_info ssd_dkio_ctrl_info 1055 7339 Nikko #define sd_nvpair_str_decode ssd_nvpair_str_decode 1056 7339 Nikko #define sd_strtok_r ssd_strtok_r 1057 7339 Nikko #define sd_set_properties ssd_set_properties 1058 0 stevel #define sd_get_tunables_from_conf ssd_get_tunables_from_conf 1059 0 stevel #define sd_setup_next_xfer ssd_setup_next_xfer 1060 0 stevel #define sd_dkio_get_temp ssd_dkio_get_temp 1061 0 stevel #define sd_check_mhd ssd_check_mhd 1062 0 stevel #define sd_mhd_watch_cb ssd_mhd_watch_cb 1063 0 stevel #define sd_mhd_watch_incomplete ssd_mhd_watch_incomplete 1064 0 stevel #define sd_sname ssd_sname 1065 0 stevel #define sd_mhd_resvd_recover ssd_mhd_resvd_recover 1066 0 stevel #define sd_resv_reclaim_thread ssd_resv_reclaim_thread 1067 0 stevel #define sd_take_ownership ssd_take_ownership 1068 0 stevel #define sd_reserve_release ssd_reserve_release 1069 0 stevel #define sd_rmv_resv_reclaim_req ssd_rmv_resv_reclaim_req 1070 0 stevel #define sd_mhd_reset_notify_cb ssd_mhd_reset_notify_cb 1071 0 stevel #define sd_persistent_reservation_in_read_keys \ 1072 0 stevel ssd_persistent_reservation_in_read_keys 1073 0 stevel #define sd_persistent_reservation_in_read_resv \ 1074 0 stevel ssd_persistent_reservation_in_read_resv 1075 0 stevel #define sd_mhdioc_takeown ssd_mhdioc_takeown 1076 0 stevel #define sd_mhdioc_failfast ssd_mhdioc_failfast 1077 0 stevel #define sd_mhdioc_release ssd_mhdioc_release 1078 0 stevel #define sd_mhdioc_register_devid ssd_mhdioc_register_devid 1079 0 stevel #define sd_mhdioc_inkeys ssd_mhdioc_inkeys 1080 0 stevel #define sd_mhdioc_inresv ssd_mhdioc_inresv 1081 0 stevel #define sr_change_blkmode ssr_change_blkmode 1082 0 stevel #define sr_change_speed ssr_change_speed 1083 0 stevel #define sr_atapi_change_speed ssr_atapi_change_speed 1084 0 stevel #define sr_pause_resume ssr_pause_resume 1085 0 stevel #define sr_play_msf ssr_play_msf 1086 0 stevel #define sr_play_trkind ssr_play_trkind 1087 0 stevel #define sr_read_all_subcodes ssr_read_all_subcodes 1088 0 stevel #define sr_read_subchannel ssr_read_subchannel 1089 0 stevel #define sr_read_tocentry ssr_read_tocentry 1090 0 stevel #define sr_read_tochdr ssr_read_tochdr 1091 0 stevel #define sr_read_cdda ssr_read_cdda 1092 0 stevel #define sr_read_cdxa ssr_read_cdxa 1093 0 stevel #define sr_read_mode1 ssr_read_mode1 1094 0 stevel #define sr_read_mode2 ssr_read_mode2 1095 0 stevel #define sr_read_cd_mode2 ssr_read_cd_mode2 1096 0 stevel #define sr_sector_mode ssr_sector_mode 1097 0 stevel #define sr_eject ssr_eject 1098 0 stevel #define sr_ejected ssr_ejected 1099 0 stevel #define sr_check_wp ssr_check_wp 1100 10459 Artem #define sd_watch_request_submit ssd_watch_request_submit 1101 0 stevel #define sd_check_media ssd_check_media 1102 0 stevel #define sd_media_watch_cb ssd_media_watch_cb 1103 0 stevel #define sd_delayed_cv_broadcast ssd_delayed_cv_broadcast 1104 0 stevel #define sr_volume_ctrl ssr_volume_ctrl 1105 0 stevel #define sr_read_sony_session_offset ssr_read_sony_session_offset 1106 0 stevel #define sd_log_page_supported ssd_log_page_supported 1107 0 stevel #define sd_check_for_writable_cd ssd_check_for_writable_cd 1108 0 stevel #define sd_wm_cache_constructor ssd_wm_cache_constructor 1109 0 stevel #define sd_wm_cache_destructor ssd_wm_cache_destructor 1110 0 stevel #define sd_range_lock ssd_range_lock 1111 0 stevel #define sd_get_range ssd_get_range 1112 0 stevel #define sd_free_inlist_wmap ssd_free_inlist_wmap 1113 0 stevel #define sd_range_unlock ssd_range_unlock 1114 0 stevel #define sd_read_modify_write_task ssd_read_modify_write_task 1115 0 stevel #define sddump_do_read_of_rmw ssddump_do_read_of_rmw 1116 0 stevel 1117 0 stevel #define sd_iostart_chain ssd_iostart_chain 1118 0 stevel #define sd_iodone_chain ssd_iodone_chain 1119 0 stevel #define sd_initpkt_map ssd_initpkt_map 1120 0 stevel #define sd_destroypkt_map ssd_destroypkt_map 1121 0 stevel #define sd_chain_type_map ssd_chain_type_map 1122 0 stevel #define sd_chain_index_map ssd_chain_index_map 1123 0 stevel 1124 0 stevel #define sd_failfast_flushctl ssd_failfast_flushctl 1125 0 stevel #define sd_failfast_flushq ssd_failfast_flushq 1126 0 stevel #define sd_failfast_flushq_callback ssd_failfast_flushq_callback 1127 0 stevel 1128 313 ts143224 #define sd_is_lsi ssd_is_lsi 1129 3525 shidokht #define sd_tg_rdwr ssd_tg_rdwr 1130 3525 shidokht #define sd_tg_getinfo ssd_tg_getinfo 1131 9889 Larry #define sd_rmw_msg_print_handler ssd_rmw_msg_print_handler 1132 313 ts143224 1133 0 stevel #endif /* #if (defined(__fibre)) */ 1134 0 stevel 1135 0 stevel 1136 0 stevel int _init(void); 1137 0 stevel int _fini(void); 1138 0 stevel int _info(struct modinfo *modinfop); 1139 0 stevel 1140 0 stevel /*PRINTFLIKE3*/ 1141 0 stevel static void sd_log_trace(uint_t comp, struct sd_lun *un, const char *fmt, ...); 1142 0 stevel /*PRINTFLIKE3*/ 1143 0 stevel static void sd_log_info(uint_t comp, struct sd_lun *un, const char *fmt, ...); 1144 0 stevel /*PRINTFLIKE3*/ 1145 0 stevel static void sd_log_err(uint_t comp, struct sd_lun *un, const char *fmt, ...); 1146 0 stevel 1147 0 stevel static int sdprobe(dev_info_t *devi); 1148 0 stevel static int sdinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, 1149 0 stevel void **result); 1150 0 stevel static int sd_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, 1151 0 stevel int mod_flags, char *name, caddr_t valuep, int *lengthp); 1152 0 stevel 1153 0 stevel /* 1154 0 stevel * Smart probe for parallel scsi 1155 0 stevel */ 1156 0 stevel static void sd_scsi_probe_cache_init(void); 1157 0 stevel static void sd_scsi_probe_cache_fini(void); 1158 0 stevel static void sd_scsi_clear_probe_cache(void); 1159 0 stevel static int sd_scsi_probe_with_cache(struct scsi_device *devp, int (*fn)()); 1160 0 stevel 1161 2683 yl194034 /* 1162 2683 yl194034 * Attached luns on target for parallel scsi 1163 2683 yl194034 */ 1164 2683 yl194034 static void sd_scsi_target_lun_init(void); 1165 2683 yl194034 static void sd_scsi_target_lun_fini(void); 1166 2683 yl194034 static int sd_scsi_get_target_lun_count(dev_info_t *dip, int target); 1167 2683 yl194034 static void sd_scsi_update_lun_on_target(dev_info_t *dip, int target, int flag); 1168 2683 yl194034 1169 7570 David static int sd_spin_up_unit(sd_ssc_t *ssc); 1170 7570 David 1171 7570 David /* 1172 7570 David * Using sd_ssc_init to establish sd_ssc_t struct 1173 7570 David * Using sd_ssc_send to send uscsi internal command 1174 7570 David * Using sd_ssc_fini to free sd_ssc_t struct 1175 7570 David */ 1176 7570 David static sd_ssc_t *sd_ssc_init(struct sd_lun *un); 1177 7570 David static int sd_ssc_send(sd_ssc_t *ssc, struct uscsi_cmd *incmd, 1178 7570 David int flag, enum uio_seg dataspace, int path_flag); 1179 7570 David static void sd_ssc_fini(sd_ssc_t *ssc); 1180 7570 David 1181 7570 David /* 1182 7570 David * Using sd_ssc_assessment to set correct type-of-assessment 1183 7570 David * Using sd_ssc_post to post ereport & system log 1184 7570 David * sd_ssc_post will call sd_ssc_print to print system log 1185 7570 David * sd_ssc_post will call sd_ssd_ereport_post to post ereport 1186 7570 David */ 1187 7570 David static void sd_ssc_assessment(sd_ssc_t *ssc, 1188 7570 David enum sd_type_assessment tp_assess); 1189 7570 David 1190 7570 David static void sd_ssc_post(sd_ssc_t *ssc, enum sd_driver_assessment sd_assess); 1191 7570 David static void sd_ssc_print(sd_ssc_t *ssc, int sd_severity); 1192 7570 David static void sd_ssc_ereport_post(sd_ssc_t *ssc, 1193 7570 David enum sd_driver_assessment drv_assess); 1194 7570 David 1195 7570 David /* 1196 7570 David * Using sd_ssc_set_info to mark an un-decodable-data error. 1197 7570 David * Using sd_ssc_extract_info to transfer information from internal 1198 7570 David * data structures to sd_ssc_t. 1199 7570 David */ 1200 8086 Xiao static void sd_ssc_set_info(sd_ssc_t *ssc, int ssc_flags, uint_t comp, 1201 7570 David const char *fmt, ...); 1202 7570 David static void sd_ssc_extract_info(sd_ssc_t *ssc, struct sd_lun *un, 1203 7570 David struct scsi_pkt *pktp, struct buf *bp, struct sd_xbuf *xp); 1204 7570 David 1205 7570 David static int sd_send_scsi_cmd(dev_t dev, struct uscsi_cmd *incmd, int flag, 1206 7570 David enum uio_seg dataspace, int path_flag); 1207 7570 David 1208 609 bg159949 #ifdef _LP64 1209 7570 David static void sd_enable_descr_sense(sd_ssc_t *ssc); 1210 2148 pd144616 static void sd_reenable_dsense_task(void *arg); 1211 609 bg159949 #endif /* _LP64 */ 1212 2148 pd144616 1213 7570 David static void sd_set_mmc_caps(sd_ssc_t *ssc); 1214 0 stevel 1215 0 stevel static void sd_read_unit_properties(struct sd_lun *un); 1216 0 stevel static int sd_process_sdconf_file(struct sd_lun *un); 1217 7339 Nikko static void sd_nvpair_str_decode(struct sd_lun *un, char *nvpair_str); 1218 7339 Nikko static char *sd_strtok_r(char *string, const char *sepset, char **lasts); 1219 7339 Nikko static void sd_set_properties(struct sd_lun *un, char *name, char *value); 1220 0 stevel static void sd_get_tunables_from_conf(struct sd_lun *un, int flags, 1221 0 stevel int *data_list, sd_tunables *values); 1222 0 stevel static void sd_process_sdconf_table(struct sd_lun *un); 1223 0 stevel static int sd_sdconf_id_match(struct sd_lun *un, char *id, int idlen); 1224 0 stevel static int sd_blank_cmp(struct sd_lun *un, char *id, int idlen); 1225 0 stevel static int sd_chk_vers1_data(struct sd_lun *un, int flags, int *prop_list, 1226 0 stevel int list_len, char *dataname_ptr); 1227 0 stevel static void sd_set_vers1_properties(struct sd_lun *un, int flags, 1228 0 stevel sd_tunables *prop_list); 1229 0 stevel 1230 7570 David static void sd_register_devid(sd_ssc_t *ssc, dev_info_t *devi, 1231 0 stevel int reservation_flag); 1232 7570 David static int sd_get_devid(sd_ssc_t *ssc); 1233 7570 David static ddi_devid_t sd_create_devid(sd_ssc_t *ssc); 1234 7570 David static int sd_write_deviceid(sd_ssc_t *ssc); 1235 0 stevel static int sd_get_devid_page(struct sd_lun *un, uchar_t *wwn, int *len); 1236 7570 David static int sd_check_vpd_page_support(sd_ssc_t *ssc); 1237 7570 David 1238 7570 David static void sd_setup_pm(sd_ssc_t *ssc, dev_info_t *devi); 1239 0 stevel static void sd_create_pm_components(dev_info_t *devi, struct sd_lun *un); 1240 0 stevel 1241 0 stevel static int sd_ddi_suspend(dev_info_t *devi); 1242 0 stevel static int sd_ddi_resume(dev_info_t *devi); 1243 10131 Jane static int sd_pm_state_change(struct sd_lun *un, int level, int flag); 1244 0 stevel static int sdpower(dev_info_t *devi, int component, int level); 1245 0 stevel 1246 0 stevel static int sdattach(dev_info_t *devi, ddi_attach_cmd_t cmd); 1247 0 stevel static int sddetach(dev_info_t *devi, ddi_detach_cmd_t cmd); 1248 0 stevel static int sd_unit_attach(dev_info_t *devi); 1249 0 stevel static int sd_unit_detach(dev_info_t *devi); 1250 0 stevel 1251 1415 cg149915 static void sd_set_unit_attributes(struct sd_lun *un, dev_info_t *devi); 1252 0 stevel static void sd_create_errstats(struct sd_lun *un, int instance); 1253 0 stevel static void sd_set_errstats(struct sd_lun *un); 1254 0 stevel static void sd_set_pstats(struct sd_lun *un); 1255 0 stevel 1256 0 stevel static int sddump(dev_t dev, caddr_t addr, daddr_t blkno, int nblk); 1257 0 stevel static int sd_scsi_poll(struct sd_lun *un, struct scsi_pkt *pkt); 1258 0 stevel static int sd_send_polled_RQS(struct sd_lun *un); 1259 0 stevel static int sd_ddi_scsi_poll(struct scsi_pkt *pkt); 1260 0 stevel 1261 0 stevel #if (defined(__fibre)) 1262 0 stevel /* 1263 0 stevel * Event callbacks (photon) 1264 0 stevel */ 1265 0 stevel static void sd_init_event_callbacks(struct sd_lun *un); 1266 0 stevel static void sd_event_callback(dev_info_t *, ddi_eventcookie_t, void *, void *); 1267 0 stevel #endif 1268 0 stevel 1269 1489 webaker /* 1270 1489 webaker * Defines for sd_cache_control 1271 1489 webaker */ 1272 1489 webaker 1273 1489 webaker #define SD_CACHE_ENABLE 1 1274 1489 webaker #define SD_CACHE_DISABLE 0 1275 1489 webaker #define SD_CACHE_NOCHANGE -1 1276 1489 webaker 1277 7570 David static int sd_cache_control(sd_ssc_t *ssc, int rcd_flag, int wce_flag); 1278 7570 David static int sd_get_write_cache_enabled(sd_ssc_t *ssc, int *is_enabled); 1279 7570 David static void sd_get_nv_sup(sd_ssc_t *ssc); 1280 0 stevel static dev_t sd_make_device(dev_info_t *devi); 1281 10320 Larry static void sd_check_solid_state(sd_ssc_t *ssc); 1282 0 stevel 1283 0 stevel static void sd_update_block_info(struct sd_lun *un, uint32_t lbasize, 1284 0 stevel uint64_t capacity); 1285 0 stevel 1286 0 stevel /* 1287 0 stevel * Driver entry point functions. 1288 0 stevel */ 1289 0 stevel static int sdopen(dev_t *dev_p, int flag, int otyp, cred_t *cred_p); 1290 0 stevel static int sdclose(dev_t dev, int flag, int otyp, cred_t *cred_p); 1291 7570 David static int sd_ready_and_valid(sd_ssc_t *ssc, int part); 1292 0 stevel 1293 0 stevel static void sdmin(struct buf *bp); 1294 0 stevel static int sdread(dev_t dev, struct uio *uio, cred_t *cred_p); 1295 0 stevel static int sdwrite(dev_t dev, struct uio *uio, cred_t *cred_p); 1296 0 stevel static int sdaread(dev_t dev, struct aio_req *aio, cred_t *cred_p); 1297 0 stevel static int sdawrite(dev_t dev, struct aio_req *aio, cred_t *cred_p); 1298 0 stevel 1299 0 stevel static int sdstrategy(struct buf *bp); 1300 0 stevel static int sdioctl(dev_t, int, intptr_t, int, cred_t *, int *); 1301 0 stevel 1302 0 stevel /* 1303 0 stevel * Function prototypes for layering functions in the iostart chain. 1304 0 stevel */ 1305 0 stevel static void sd_mapblockaddr_iostart(int index, struct sd_lun *un, 1306 0 stevel struct buf *bp); 1307 0 stevel static void sd_mapblocksize_iostart(int index, struct sd_lun *un, 1308 0 stevel struct buf *bp); 1309 0 stevel static void sd_checksum_iostart(int index, struct sd_lun *un, struct buf *bp); 1310 0 stevel static void sd_checksum_uscsi_iostart(int index, struct sd_lun *un, 1311 0 stevel struct buf *bp); 1312 0 stevel static void sd_pm_iostart(int index, struct sd_lun *un, struct buf *bp); 1313 0 stevel static void sd_core_iostart(int index, struct sd_lun *un, struct buf *bp); 1314 0 stevel 1315 0 stevel /* 1316 0 stevel * Function prototypes for layering functions in the iodone chain. 1317 0 stevel */ 1318 0 stevel static void sd_buf_iodone(int index, struct sd_lun *un, struct buf *bp); 1319 0 stevel static void sd_uscsi_iodone(int index, struct sd_lun *un, struct buf *bp); 1320 0 stevel static void sd_mapblockaddr_iodone(int index, struct sd_lun *un, 1321 0 stevel struct buf *bp); 1322 0 stevel static void sd_mapblocksize_iodone(int index, struct sd_lun *un, 1323 0 stevel struct buf *bp); 1324 0 stevel static void sd_checksum_iodone(int index, struct sd_lun *un, struct buf *bp); 1325 0 stevel static void sd_checksum_uscsi_iodone(int index, struct sd_lun *un, 1326 0 stevel struct buf *bp); 1327 0 stevel static void sd_pm_iodone(int index, struct sd_lun *un, struct buf *bp); 1328 0 stevel 1329 0 stevel /* 1330 0 stevel * Prototypes for functions to support buf(9S) based IO. 1331 0 stevel */ 1332 0 stevel static void sd_xbuf_strategy(struct buf *bp, ddi_xbuf_t xp, void *arg); 1333 0 stevel static int sd_initpkt_for_buf(struct buf *, struct scsi_pkt **); 1334 0 stevel static void sd_destroypkt_for_buf(struct buf *); 1335 0 stevel static int sd_setup_rw_pkt(struct sd_lun *un, struct scsi_pkt **pktpp, 1336 0 stevel struct buf *bp, int flags, 1337 0 stevel int (*callback)(caddr_t), caddr_t callback_arg, 1338 0 stevel diskaddr_t lba, uint32_t blockcount); 1339 0 stevel static int sd_setup_next_rw_pkt(struct sd_lun *un, struct scsi_pkt *pktp, 1340 0 stevel struct buf *bp, diskaddr_t lba, uint32_t blockcount); 1341 0 stevel 1342 0 stevel /* 1343 0 stevel * Prototypes for functions to support USCSI IO. 1344 0 stevel */ 1345 0 stevel static int sd_uscsi_strategy(struct buf *bp); 1346 0 stevel static int sd_initpkt_for_uscsi(struct buf *, struct scsi_pkt **); 1347 0 stevel static void sd_destroypkt_for_uscsi(struct buf *); 1348 0 stevel 1349 0 stevel static void sd_xbuf_init(struct sd_lun *un, struct buf *bp, struct sd_xbuf *xp, 1350 0 stevel uchar_t chain_type, void *pktinfop); 1351 0 stevel 1352 0 stevel static int sd_pm_entry(struct sd_lun *un); 1353 0 stevel static void sd_pm_exit(struct sd_lun *un); 1354 0 stevel 1355 0 stevel static void sd_pm_idletimeout_handler(void *arg); 1356 0 stevel 1357 0 stevel /* 1358 0 stevel * sd_core internal functions (used at the sd_core_io layer). 1359 0 stevel */ 1360 0 stevel static void sd_add_buf_to_waitq(struct sd_lun *un, struct buf *bp); 1361 0 stevel static void sdintr(struct scsi_pkt *pktp); 1362 0 stevel static void sd_start_cmds(struct sd_lun *un, struct buf *immed_bp); 1363 0 stevel 1364 3368 lh195018 static int sd_send_scsi_cmd(dev_t dev, struct uscsi_cmd *incmd, int flag, 1365 3368 lh195018 enum uio_seg dataspace, int path_flag); 1366 0 stevel 1367 0 stevel static struct buf *sd_bioclone_alloc(struct buf *bp, size_t datalen, 1368 0 stevel daddr_t blkno, int (*func)(struct buf *)); 1369 0 stevel static struct buf *sd_shadow_buf_alloc(struct buf *bp, size_t datalen, 1370 0 stevel uint_t bflags, daddr_t blkno, int (*func)(struct buf *)); 1371 0 stevel static void sd_bioclone_free(struct buf *bp); 1372 0 stevel static void sd_shadow_buf_free(struct buf *bp); 1373 0 stevel 1374 0 stevel static void sd_print_transport_rejected_message(struct sd_lun *un, 1375 0 stevel struct sd_xbuf *xp, int code); 1376 1415 cg149915 static void sd_print_incomplete_msg(struct sd_lun *un, struct buf *bp, 1377 1415 cg149915 void *arg, int code); 1378 1415 cg149915 static void sd_print_sense_failed_msg(struct sd_lun *un, struct buf *bp, 1379 1415 cg149915 void *arg, int code); 1380 1415 cg149915 static void sd_print_cmd_incomplete_msg(struct sd_lun *un, struct buf *bp, 1381 1415 cg149915 void *arg, int code); 1382 0 stevel 1383 0 stevel static void sd_retry_command(struct sd_lun *un, struct buf *bp, 1384 0 stevel int retry_check_flag, 1385 0 stevel void (*user_funcp)(struct sd_lun *un, struct buf *bp, void *argp, 1386 0 stevel int c), 1387 0 stevel void *user_arg, int failure_code, clock_t retry_delay, 1388 0 stevel void (*statp)(kstat_io_t *)); 1389 0 stevel 1390 0 stevel static void sd_set_retry_bp(struct sd_lun *un, struct buf *bp, 1391 0 stevel clock_t retry_delay, void (*statp)(kstat_io_t *)); 1392 0 stevel 1393 0 stevel static void sd_send_request_sense_command(struct sd_lun *un, struct buf *bp, 1394 0 stevel struct scsi_pkt *pktp); 1395 0 stevel static void sd_start_retry_command(void *arg); 1396 0 stevel static void sd_start_direct_priority_command(void *arg); 1397 0 stevel static void sd_return_failed_command(struct sd_lun *un, struct buf *bp, 1398 0 stevel int errcode); 1399 0 stevel static void sd_return_failed_command_no_restart(struct sd_lun *un, 1400 0 stevel struct buf *bp, int errcode); 1401 0 stevel static void sd_return_command(struct sd_lun *un, struct buf *bp); 1402 0 stevel static void sd_sync_with_callback(struct sd_lun *un); 1403 0 stevel static int sdrunout(caddr_t arg); 1404 0 stevel 1405 0 stevel static void sd_mark_rqs_busy(struct sd_lun *un, struct buf *bp); 1406 0 stevel static struct buf *sd_mark_rqs_idle(struct sd_lun *un, struct sd_xbuf *xp); 1407 0 stevel 1408 0 stevel static void sd_reduce_throttle(struct sd_lun *un, int throttle_type); 1409 0 stevel static void sd_restore_throttle(void *arg); 1410 0 stevel 1411 0 stevel static void sd_init_cdb_limits(struct sd_lun *un); 1412 0 stevel 1413 0 stevel static void sd_pkt_status_good(struct sd_lun *un, struct buf *bp, 1414 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1415 0 stevel 1416 0 stevel /* 1417 0 stevel * Error handling functions 1418 0 stevel */ 1419 0 stevel static void sd_pkt_status_check_condition(struct sd_lun *un, struct buf *bp, 1420 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1421 0 stevel static void sd_pkt_status_busy(struct sd_lun *un, struct buf *bp, 1422 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1423 0 stevel static void sd_pkt_status_reservation_conflict(struct sd_lun *un, 1424 0 stevel struct buf *bp, struct sd_xbuf *xp, struct scsi_pkt *pktp); 1425 0 stevel static void sd_pkt_status_qfull(struct sd_lun *un, struct buf *bp, 1426 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1427 0 stevel 1428 0 stevel static void sd_handle_request_sense(struct sd_lun *un, struct buf *bp, 1429 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1430 0 stevel static void sd_handle_auto_request_sense(struct sd_lun *un, struct buf *bp, 1431 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1432 0 stevel static int sd_validate_sense_data(struct sd_lun *un, struct buf *bp, 1433 5597 lh195018 struct sd_xbuf *xp, size_t actual_len); 1434 0 stevel static void sd_decode_sense(struct sd_lun *un, struct buf *bp, 1435 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1436 0 stevel 1437 0 stevel static void sd_print_sense_msg(struct sd_lun *un, struct buf *bp, 1438 0 stevel void *arg, int code); 1439 0 stevel 1440 0 stevel static void sd_sense_key_no_sense(struct sd_lun *un, struct buf *bp, 1441 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1442 0 stevel static void sd_sense_key_recoverable_error(struct sd_lun *un, 1443 2148 pd144616 uint8_t *sense_datap, 1444 0 stevel struct buf *bp, struct sd_xbuf *xp, struct scsi_pkt *pktp); 1445 0 stevel static void sd_sense_key_not_ready(struct sd_lun *un, 1446 2148 pd144616 uint8_t *sense_datap, 1447 0 stevel struct buf *bp, struct sd_xbuf *xp, struct scsi_pkt *pktp); 1448 0 stevel static void sd_sense_key_medium_or_hardware_error(struct sd_lun *un, 1449 2148 pd144616 uint8_t *sense_datap, 1450 0 stevel struct buf *bp, struct sd_xbuf *xp, struct scsi_pkt *pktp); 1451 0 stevel static void sd_sense_key_illegal_request(struct sd_lun *un, struct buf *bp, 1452 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1453 0 stevel static void sd_sense_key_unit_attention(struct sd_lun *un, 1454 2148 pd144616 uint8_t *sense_datap, 1455 0 stevel struct buf *bp, struct sd_xbuf *xp, struct scsi_pkt *pktp); 1456 0 stevel static void sd_sense_key_fail_command(struct sd_lun *un, struct buf *bp, 1457 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1458 0 stevel static void sd_sense_key_blank_check(struct sd_lun *un, struct buf *bp, 1459 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1460 0 stevel static void sd_sense_key_aborted_command(struct sd_lun *un, struct buf *bp, 1461 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1462 0 stevel static void sd_sense_key_default(struct sd_lun *un, 1463 2148 pd144616 uint8_t *sense_datap, 1464 0 stevel struct buf *bp, struct sd_xbuf *xp, struct scsi_pkt *pktp); 1465 0 stevel 1466 0 stevel static void sd_print_retry_msg(struct sd_lun *un, struct buf *bp, 1467 0 stevel void *arg, int flag); 1468 0 stevel 1469 0 stevel static void sd_pkt_reason_cmd_incomplete(struct sd_lun *un, struct buf *bp, 1470 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1471 0 stevel static void sd_pkt_reason_cmd_tran_err(struct sd_lun *un, struct buf *bp, 1472 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1473 0 stevel static void sd_pkt_reason_cmd_reset(struct sd_lun *un, struct buf *bp, 1474 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1475 0 stevel static void sd_pkt_reason_cmd_aborted(struct sd_lun *un, struct buf *bp, 1476 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1477 0 stevel static void sd_pkt_reason_cmd_timeout(struct sd_lun *un, struct buf *bp, 1478 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1479 0 stevel static void sd_pkt_reason_cmd_unx_bus_free(struct sd_lun *un, struct buf *bp, 1480 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1481 0 stevel static void sd_pkt_reason_cmd_tag_reject(struct sd_lun *un, struct buf *bp, 1482 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1483 0 stevel static void sd_pkt_reason_default(struct sd_lun *un, struct buf *bp, 1484 0 stevel struct sd_xbuf *xp, struct scsi_pkt *pktp); 1485 0 stevel 1486 0 stevel static void sd_reset_target(struct sd_lun *un, struct scsi_pkt *pktp); 1487 0 stevel 1488 0 stevel static void sd_start_stop_unit_callback(void *arg); 1489 0 stevel static void sd_start_stop_unit_task(void *arg); 1490 0 stevel 1491 0 stevel static void sd_taskq_create(void); 1492 0 stevel static void sd_taskq_delete(void); 1493 6590 yl194034 static void sd_target_change_task(void *arg); 1494 10459 Artem static void sd_log_dev_status_event(struct sd_lun *un, char *esc, int km_flag); 1495 6590 yl194034 static void sd_log_lun_expansion_event(struct sd_lun *un, int km_flag); 1496 10459 Artem static void sd_log_eject_request_event(struct sd_lun *un, int km_flag); 1497 0 stevel static void sd_media_change_task(void *arg); 1498 0 stevel 1499 0 stevel static int sd_handle_mchange(struct sd_lun *un); 1500 7570 David static int sd_send_scsi_DOORLOCK(sd_ssc_t *ssc, int flag, int path_flag); 1501 7570 David static int sd_send_scsi_READ_CAPACITY(sd_ssc_t *ssc, uint64_t *capp, 1502 0 stevel uint32_t *lbap, int path_flag); 1503 7570 David static int sd_send_scsi_READ_CAPACITY_16(sd_ssc_t *ssc, uint64_t *capp, 1504 9889 Larry uint32_t *lbap, uint32_t *psp, int path_flag); 1505 10131 Jane static int sd_send_scsi_START_STOP_UNIT(sd_ssc_t *ssc, int pc_flag, 1506 10131 Jane int flag, int path_flag); 1507 7570 David static int sd_send_scsi_INQUIRY(sd_ssc_t *ssc, uchar_t *bufaddr, 1508 0 stevel size_t buflen, uchar_t evpd, uchar_t page_code, size_t *residp); 1509 7570 David static int sd_send_scsi_TEST_UNIT_READY(sd_ssc_t *ssc, int flag); 1510 7570 David static int sd_send_scsi_PERSISTENT_RESERVE_IN(sd_ssc_t *ssc, 1511 0 stevel uchar_t usr_cmd, uint16_t data_len, uchar_t *data_bufp); 1512 7570 David static int sd_send_scsi_PERSISTENT_RESERVE_OUT(sd_ssc_t *ssc, 1513 0 stevel uchar_t usr_cmd, uchar_t *usr_bufp); 1514 789 ahrens static int sd_send_scsi_SYNCHRONIZE_CACHE(struct sd_lun *un, 1515 789 ahrens struct dk_callback *dkc); 1516 789 ahrens static int sd_send_scsi_SYNCHRONIZE_CACHE_biodone(struct buf *bp); 1517 7570 David static int sd_send_scsi_GET_CONFIGURATION(sd_ssc_t *ssc, 1518 0 stevel struct uscsi_cmd *ucmdbuf, uchar_t *rqbuf, uint_t rqbuflen, 1519 3618 cg149915 uchar_t *bufaddr, uint_t buflen, int path_flag); 1520 7570 David static int sd_send_scsi_feature_GET_CONFIGURATION(sd_ssc_t *ssc, 1521 0 stevel struct uscsi_cmd *ucmdbuf, uchar_t *rqbuf, uint_t rqbuflen, 1522 3618 cg149915 uchar_t *bufaddr, uint_t buflen, char feature, int path_flag); 1523 7570 David static int sd_send_scsi_MODE_SENSE(sd_ssc_t *ssc, int cdbsize, 1524 0 stevel uchar_t *bufaddr, size_t buflen, uchar_t page_code, int path_flag); 1525 7570 David static int sd_send_scsi_MODE_SELECT(sd_ssc_t *ssc, int cdbsize, 1526 0 stevel uchar_t *bufaddr, size_t buflen, uchar_t save_page, int path_flag); 1527 7570 David static int sd_send_scsi_RDWR(sd_ssc_t *ssc, uchar_t cmd, void *bufaddr, 1528 0 stevel size_t buflen, daddr_t start_block, int path_flag); 1529 7570 David #define sd_send_scsi_READ(ssc, bufaddr, buflen, start_block, path_flag) \ 1530 7570 David sd_send_scsi_RDWR(ssc, SCMD_READ, bufaddr, buflen, start_block, \ 1531 0 stevel path_flag) 1532 7570 David #define sd_send_scsi_WRITE(ssc, bufaddr, buflen, start_block, path_flag)\ 1533 7570 David sd_send_scsi_RDWR(ssc, SCMD_WRITE, bufaddr, buflen, start_block,\ 1534 0 stevel path_flag) 1535 0 stevel 1536 7570 David static int sd_send_scsi_LOG_SENSE(sd_ssc_t *ssc, uchar_t *bufaddr, 1537 0 stevel uint16_t buflen, uchar_t page_code, uchar_t page_control, 1538 0 stevel uint16_t param_ptr, int path_flag); 1539 10459 Artem static int sd_send_scsi_GET_EVENT_STATUS_NOTIFICATION(sd_ssc_t *ssc, 1540 10459 Artem uchar_t *bufaddr, size_t buflen, uchar_t class_req); 1541 10459 Artem static boolean_t sd_gesn_media_data_valid(uchar_t *data); 1542 0 stevel 1543 0 stevel static int sd_alloc_rqs(struct scsi_device *devp, struct sd_lun *un); 1544 0 stevel static void sd_free_rqs(struct sd_lun *un); 1545 0 stevel 1546 0 stevel static void sd_dump_memory(struct sd_lun *un, uint_t comp, char *title, 1547 0 stevel uchar_t *data, int len, int fmt); 1548 1144 pd144616 static void sd_panic_for_res_conflict(struct sd_lun *un); 1549 0 stevel 1550 0 stevel /* 1551 0 stevel * Disk Ioctl Function Prototypes 1552 0 stevel */ 1553 0 stevel static int sd_get_media_info(dev_t dev, caddr_t arg, int flag); 1554 9889 Larry static int sd_get_media_info_ext(dev_t dev, caddr_t arg, int flag); 1555 0 stevel static int sd_dkio_ctrl_info(dev_t dev, caddr_t arg, int flag); 1556 0 stevel static int sd_dkio_get_temp(dev_t dev, caddr_t arg, int flag); 1557 0 stevel 1558 0 stevel /* 1559 0 stevel * Multi-host Ioctl Prototypes 1560 0 stevel */ 1561 0 stevel static int sd_check_mhd(dev_t dev, int interval); 1562 0 stevel static int sd_mhd_watch_cb(caddr_t arg, struct scsi_watch_result *resultp); 1563 0 stevel static void sd_mhd_watch_incomplete(struct sd_lun *un, struct scsi_pkt *pkt); 1564 0 stevel static char *sd_sname(uchar_t status); 1565 0 stevel static void sd_mhd_resvd_recover(void *arg); 1566 0 stevel static void sd_resv_reclaim_thread(); 1567 0 stevel static int sd_take_ownership(dev_t dev, struct mhioctkown *p); 1568 0 stevel static int sd_reserve_release(dev_t dev, int cmd); 1569 0 stevel static void sd_rmv_resv_reclaim_req(dev_t dev); 1570 0 stevel static void sd_mhd_reset_notify_cb(caddr_t arg); 1571 0 stevel static int sd_persistent_reservation_in_read_keys(struct sd_lun *un, 1572 0 stevel mhioc_inkeys_t *usrp, int flag); 1573 0 stevel static int sd_persistent_reservation_in_read_resv(struct sd_lun *un, 1574 0 stevel mhioc_inresvs_t *usrp, int flag); 1575 0 stevel static int sd_mhdioc_takeown(dev_t dev, caddr_t arg, int flag); 1576 0 stevel static int sd_mhdioc_failfast(dev_t dev, caddr_t arg, int flag); 1577 0 stevel static int sd_mhdioc_release(dev_t dev); 1578 0 stevel static int sd_mhdioc_register_devid(dev_t dev); 1579 0 stevel static int sd_mhdioc_inkeys(dev_t dev, caddr_t arg, int flag); 1580 0 stevel static int sd_mhdioc_inresv(dev_t dev, caddr_t arg, int flag); 1581 0 stevel 1582 0 stevel /* 1583 0 stevel * SCSI removable prototypes 1584 0 stevel */ 1585 0 stevel static int sr_change_blkmode(dev_t dev, int cmd, intptr_t data, int flag); 1586 0 stevel static int sr_change_speed(dev_t dev, int cmd, intptr_t data, int flag); 1587 0 stevel static int sr_atapi_change_speed(dev_t dev, int cmd, intptr_t data, int flag); 1588 0 stevel static int sr_pause_resume(dev_t dev, int mode); 1589 0 stevel static int sr_play_msf(dev_t dev, caddr_t data, int flag); 1590 0 stevel static int sr_play_trkind(dev_t dev, caddr_t data, int flag); 1591 0 stevel static int sr_read_all_subcodes(dev_t dev, caddr_t data, int flag); 1592 0 stevel static int sr_read_subchannel(dev_t dev, caddr_t data, int flag); 1593 0 stevel static int sr_read_tocentry(dev_t dev, caddr_t data, int flag); 1594 0 stevel static int sr_read_tochdr(dev_t dev, caddr_t data, int flag); 1595 0 stevel static int sr_read_cdda(dev_t dev, caddr_t data, int flag); 1596 0 stevel static int sr_read_cdxa(dev_t dev, caddr_t data, int flag); 1597 0 stevel static int sr_read_mode1(dev_t dev, caddr_t data, int flag); 1598 0 stevel static int sr_read_mode2(dev_t dev, caddr_t data, int flag); 1599 0 stevel static int sr_read_cd_mode2(dev_t dev, caddr_t data, int flag); 1600 0 stevel static int sr_sector_mode(dev_t dev, uint32_t blksize); 1601 0 stevel static int sr_eject(dev_t dev); 1602 0 stevel static void sr_ejected(register struct sd_lun *un); 1603 0 stevel static int sr_check_wp(dev_t dev); 1604 10459 Artem static opaque_t sd_watch_request_submit(struct sd_lun *un); 1605 0 stevel static int sd_check_media(dev_t dev, enum dkio_state state); 1606 0 stevel static int sd_media_watch_cb(caddr_t arg, struct scsi_watch_result *resultp); 1607 0 stevel static void sd_delayed_cv_broadcast(void *arg); 1608 0 stevel static int sr_volume_ctrl(dev_t dev, caddr_t data, int flag); 1609 0 stevel static int sr_read_sony_session_offset(dev_t dev, caddr_t data, int flag); 1610 0 stevel 1611 7570 David static int sd_log_page_supported(sd_ssc_t *ssc, int log_page); 1612 0 stevel 1613 0 stevel /* 1614 0 stevel * Function Prototype for the non-512 support (DVDRAM, MO etc.) functions. 1615 0 stevel */ 1616 7570 David static void sd_check_for_writable_cd(sd_ssc_t *ssc, int path_flag); 1617 0 stevel static int sd_wm_cache_constructor(void *wm, void *un, int flags); 1618 0 stevel static void sd_wm_cache_destructor(void *wm, void *un); 1619 0 stevel static struct sd_w_map *sd_range_lock(struct sd_lun *un, daddr_t startb, 1620 0 stevel daddr_t endb, ushort_t typ); 1621 0 stevel static struct sd_w_map *sd_get_range(struct sd_lun *un, daddr_t startb, 1622 0 stevel daddr_t endb); 1623 0 stevel static void sd_free_inlist_wmap(struct sd_lun *un, struct sd_w_map *wmp); 1624 0 stevel static void sd_range_unlock(struct sd_lun *un, struct sd_w_map *wm); 1625 0 stevel static void sd_read_modify_write_task(void * arg); 1626 0 stevel static int 1627 0 stevel sddump_do_read_of_rmw(struct sd_lun *un, uint64_t blkno, uint64_t nblk, 1628 0 stevel struct buf **bpp); 1629 0 stevel 1630 0 stevel 1631 0 stevel /* 1632 0 stevel * Function prototypes for failfast support. 1633 0 stevel */ 1634 0 stevel static void sd_failfast_flushq(struct sd_lun *un); 1635 0 stevel static int sd_failfast_flushq_callback(struct buf *bp); 1636 0 stevel 1637 0 stevel /* 1638 313 ts143224 * Function prototypes to check for lsi devices 1639 313 ts143224 */ 1640 313 ts143224 static void sd_is_lsi(struct sd_lun *un); 1641 313 ts143224 1642 313 ts143224 /* 1643 5595 lh195018 * Function prototypes for partial DMA support 1644 5595 lh195018 */ 1645 0 stevel static int sd_setup_next_xfer(struct sd_lun *un, struct buf *bp, 1646 0 stevel struct scsi_pkt *pkt, struct sd_xbuf *xp); 1647 0 stevel 1648 3525 shidokht 1649 3525 shidokht /* Function prototypes for cmlb */ 1650 3525 shidokht static int sd_tg_rdwr(dev_info_t *devi, uchar_t cmd, void *bufaddr, 1651 3525 shidokht diskaddr_t start_block, size_t reqlength, void *tg_cookie); 1652 3525 shidokht 1653 3525 shidokht static int sd_tg_getinfo(dev_info_t *devi, int cmd, void *arg, void *tg_cookie); 1654 3525 shidokht 1655 0 stevel /* 1656 9889 Larry * For printing RMW warning message timely 1657 9889 Larry */ 1658 9889 Larry static void sd_rmw_msg_print_handler(void *arg); 1659 9889 Larry 1660 9889 Larry /* 1661 0 stevel * Constants for failfast support: 1662 0 stevel * 1663 0 stevel * SD_FAILFAST_INACTIVE: Instance is currently in a normal state, with NO 1664 0 stevel * failfast processing being performed. 1665 0 stevel * 1666 0 stevel * SD_FAILFAST_ACTIVE: Instance is in the failfast state and is performing 1667 0 stevel * failfast processing on all bufs with B_FAILFAST set. 1668 0 stevel */ 1669 0 stevel 1670 0 stevel #define SD_FAILFAST_INACTIVE 0 1671 0 stevel #define SD_FAILFAST_ACTIVE 1 1672 0 stevel 1673 0 stevel /* 1674 0 stevel * Bitmask to control behavior of buf(9S) flushes when a transition to 1675 0 stevel * the failfast state occurs. Optional bits include: 1676 0 stevel * 1677 0 stevel * SD_FAILFAST_FLUSH_ALL_BUFS: When set, flush ALL bufs including those that 1678 0 stevel * do NOT have B_FAILFAST set. When clear, only bufs with B_FAILFAST will 1679 0 stevel * be flushed. 1680 0 stevel * 1681 0 stevel * SD_FAILFAST_FLUSH_ALL_QUEUES: When set, flush any/all other queues in the 1682 0 stevel * driver, in addition to the regular wait queue. This includes the xbuf 1683 0 stevel * queues. When clear, only the driver's wait queue will be flushed. 1684 0 stevel */ 1685 0 stevel #define SD_FAILFAST_FLUSH_ALL_BUFS 0x01 1686 0 stevel #define SD_FAILFAST_FLUSH_ALL_QUEUES 0x02 1687 0 stevel 1688 0 stevel /* 1689 0 stevel * The default behavior is to only flush bufs that have B_FAILFAST set, but 1690 0 stevel * to flush all queues within the driver. 1691 0 stevel */ 1692 0 stevel static int sd_failfast_flushctl = SD_FAILFAST_FLUSH_ALL_QUEUES; 1693 0 stevel 1694 0 stevel 1695 0 stevel /* 1696 0 stevel * SD Testing Fault Injection 1697 0 stevel */ 1698 0 stevel #ifdef SD_FAULT_INJECTION 1699 0 stevel static void sd_faultinjection_ioctl(int cmd, intptr_t arg, struct sd_lun *un); 1700 0 stevel static void sd_faultinjection(struct scsi_pkt *pktp); 1701 0 stevel static void sd_injection_log(char *buf, struct sd_lun *un); 1702 0 stevel #endif 1703 0 stevel 1704 0 stevel /* 1705 0 stevel * Device driver ops vector 1706 0 stevel */ 1707 0 stevel static struct cb_ops sd_cb_ops = { 1708 0 stevel sdopen, /* open */ 1709 0 stevel sdclose, /* close */ 1710 0 stevel sdstrategy, /* strategy */ 1711 0 stevel nodev, /* print */ 1712 0 stevel sddump, /* dump */ 1713 0 stevel sdread, /* read */ 1714 0 stevel sdwrite, /* write */ 1715 0 stevel sdioctl, /* ioctl */ 1716 0 stevel nodev, /* devmap */ 1717 0 stevel nodev, /* mmap */ 1718 0 stevel nodev, /* segmap */ 1719 0 stevel nochpoll, /* poll */ 1720 0 stevel sd_prop_op, /* cb_prop_op */ 1721 0 stevel 0, /* streamtab */ 1722 0 stevel D_64BIT | D_MP | D_NEW | D_HOTPLUG, /* Driver compatibility flags */ 1723 0 stevel CB_REV, /* cb_rev */ 1724 0 stevel sdaread, /* async I/O read entry point */ 1725 0 stevel sdawrite /* async I/O write entry point */ 1726 0 stevel }; 1727 0 stevel 1728 8863 Edward struct dev_ops sd_ops = { 1729 0 stevel DEVO_REV, /* devo_rev, */ 1730 0 stevel 0, /* refcnt */ 1731 0 stevel sdinfo, /* info */ 1732 0 stevel nulldev, /* identify */ 1733 0 stevel sdprobe, /* probe */ 1734 0 stevel sdattach, /* attach */ 1735 0 stevel sddetach, /* detach */ 1736 0 stevel nodev, /* reset */ 1737 0 stevel &sd_cb_ops, /* driver operations */ 1738 0 stevel NULL, /* bus operations */ 1739 7656 Sherry sdpower, /* power */ 1740 7656 Sherry ddi_quiesce_not_needed, /* quiesce */ 1741 0 stevel }; 1742 0 stevel 1743 0 stevel /* 1744 0 stevel * This is the loadable module wrapper. 1745 0 stevel */ 1746 0 stevel #include <sys/modctl.h> 1747 0 stevel 1748 8863 Edward #ifndef XPV_HVM_DRIVER 1749 0 stevel static struct modldrv modldrv = { 1750 0 stevel &mod_driverops, /* Type of module. This one is a driver */ 1751 0 stevel SD_MODULE_NAME, /* Module name. */ 1752 0 stevel &sd_ops /* driver ops */ 1753 0 stevel }; 1754 0 stevel 1755 0 stevel static struct modlinkage modlinkage = { 1756 8863 Edward MODREV_1, &modldrv, NULL 1757 8863 Edward }; 1758 8863 Edward 1759 8863 Edward #else /* XPV_HVM_DRIVER */ 1760 8863 Edward static struct modlmisc modlmisc = { 1761 8863 Edward &mod_miscops, /* Type of module. This one is a misc */ 1762 8863 Edward "HVM " SD_MODULE_NAME, /* Module name. */ 1763 8863 Edward }; 1764 8863 Edward 1765 8863 Edward static struct modlinkage modlinkage = { 1766 8863 Edward MODREV_1, &modlmisc, NULL 1767 8863 Edward }; 1768 8863 Edward 1769 8863 Edward #endif /* XPV_HVM_DRIVER */ 1770 0 stevel 1771 3525 shidokht static cmlb_tg_ops_t sd_tgops = { 1772 3525 shidokht TG_DK_OPS_VERSION_1, 1773 3525 shidokht sd_tg_rdwr, 1774 3525 shidokht sd_tg_getinfo 1775 8863 Edward }; 1776 0 stevel 1777 0 stevel static struct scsi_asq_key_strings sd_additional_codes[] = { 1778 0 stevel 0x81, 0, "Logical Unit is Reserved", 1779 0 stevel 0x85, 0, "Audio Address Not Valid", 1780 0 stevel 0xb6, 0, "Media Load Mechanism Failed", 1781 0 stevel 0xB9, 0, "Audio Play Operation Aborted", 1782 0 stevel 0xbf, 0, "Buffer Overflow for Read All Subcodes Command", 1783 0 stevel 0x53, 2, "Medium removal prevented", 1784 0 stevel 0x6f, 0, "Authentication failed during key exchange", 1785 0 stevel 0x6f, 1, "Key not present", 1786 0 stevel 0x6f, 2, "Key not established", 1787 0 stevel 0x6f, 3, "Read without proper authentication", 1788 0 stevel 0x6f, 4, "Mismatched region to this logical unit", 1789 0 stevel 0x6f, 5, "Region reset count error", 1790 0 stevel 0xffff, 0x0, NULL 1791 0 stevel }; 1792 0 stevel 1793 0 stevel 1794 0 stevel /* 1795 0 stevel * Struct for passing printing information for sense data messages 1796 0 stevel */ 1797 0 stevel struct sd_sense_info { 1798 0 stevel int ssi_severity; 1799 0 stevel int ssi_pfa_flag; 1800 0 stevel }; 1801 0 stevel 1802 0 stevel /* 1803 4451 eschrock * Table of function pointers for iostart-side routines. Separate "chains" 1804 0 stevel * of layered function calls are formed by placing the function pointers 1805 0 stevel * sequentially in the desired order. Functions are called according to an 1806 0 stevel * incrementing table index ordering. The last function in each chain must 1807 0 stevel * be sd_core_iostart(). The corresponding iodone-side routines are expected 1808 0 stevel * in the sd_iodone_chain[] array. 1809 0 stevel * 1810 0 stevel * Note: It may seem more natural to organize both the iostart and iodone 1811 0 stevel * functions together, into an array of structures (or some similar 1812 4451 eschrock * organization) with a common index, rather than two separate arrays which 1813 0 stevel * must be maintained in synchronization. The purpose of this division is 1814 4451 eschrock * to achieve improved performance: individual arrays allows for more 1815 0 stevel * effective cache line utilization on certain platforms. 1816 0 stevel */ 1817 0 stevel 1818 0 stevel typedef void (*sd_chain_t)(int index, struct sd_lun *un, struct buf *bp); 1819 0 stevel 1820 0 stevel 1821 0 stevel static sd_chain_t sd_iostart_chain[] = { 1822 0 stevel 1823 0 stevel /* Chain for buf IO for disk drive targets (PM enabled) */ 1824 0 stevel sd_mapblockaddr_iostart, /* Index: 0 */ 1825 0 stevel sd_pm_iostart, /* Index: 1 */ 1826 0 stevel sd_core_iostart, /* Index: 2 */ 1827 0 stevel 1828 0 stevel /* Chain for buf IO for disk drive targets (PM disabled) */ 1829 0 stevel sd_mapblockaddr_iostart, /* Index: 3 */ 1830 0 stevel sd_core_iostart, /* Index: 4 */ 1831 0 stevel 1832 9889 Larry /* 1833 9889 Larry * Chain for buf IO for removable-media or large sector size 1834 9889 Larry * disk drive targets with RMW needed (PM enabled) 1835 9889 Larry */ 1836 0 stevel sd_mapblockaddr_iostart, /* Index: 5 */ 1837 0 stevel sd_mapblocksize_iostart, /* Index: 6 */ 1838 0 stevel sd_pm_iostart, /* Index: 7 */ 1839 0 stevel sd_core_iostart, /* Index: 8 */ 1840 0 stevel 1841 9889 Larry /* 1842 9889 Larry * Chain for buf IO for removable-media or large sector size 1843 9889 Larry * disk drive targets with RMW needed (PM disabled) 1844 9889 Larry */ 1845 0 stevel sd_mapblockaddr_iostart, /* Index: 9 */ 1846 0 stevel sd_mapblocksize_iostart, /* Index: 10 */ 1847 0 stevel sd_core_iostart, /* Index: 11 */ 1848 0 stevel 1849 0 stevel /* Chain for buf IO for disk drives with checksumming (PM enabled) */ 1850 0 stevel sd_mapblockaddr_iostart, /* Index: 12 */ 1851 0 stevel sd_checksum_iostart, /* Index: 13 */ 1852 0 stevel sd_pm_iostart, /* Index: 14 */ 1853 0 stevel sd_core_iostart, /* Index: 15 */ 1854 0 stevel 1855 0 stevel /* Chain for buf IO for disk drives with checksumming (PM disabled) */ 1856 0 stevel sd_mapblockaddr_iostart, /* Index: 16 */ 1857 0 stevel sd_checksum_iostart, /* Index: 17 */ 1858 0 stevel sd_core_iostart, /* Index: 18 */ 1859 0 stevel 1860 0 stevel /* Chain for USCSI commands (all targets) */ 1861 0 stevel sd_pm_iostart, /* Index: 19 */ 1862 0 stevel sd_core_iostart, /* Index: 20 */ 1863 0 stevel 1864 0 stevel /* Chain for checksumming USCSI commands (all targets) */ 1865 0 stevel sd_checksum_uscsi_iostart, /* Index: 21 */ 1866 0 stevel sd_pm_iostart, /* Index: 22 */ 1867 0 stevel sd_core_iostart, /* Index: 23 */ 1868 0 stevel 1869 0 stevel /* Chain for "direct" USCSI commands (all targets) */ 1870 0 stevel sd_core_iostart, /* Index: 24 */ 1871 0 stevel 1872 0 stevel /* Chain for "direct priority" USCSI commands (all targets) */ 1873 0 stevel sd_core_iostart, /* Index: 25 */ 1874 9889 Larry 1875 9889 Larry /* 1876 9889 Larry * Chain for buf IO for large sector size disk drive targets 1877 9889 Larry * with RMW needed with checksumming (PM enabled) 1878 9889 Larry */ 1879 9889 Larry sd_mapblockaddr_iostart, /* Index: 26 */ 1880 9889 Larry sd_mapblocksize_iostart, /* Index: 27 */ 1881 9889 Larry sd_checksum_iostart, /* Index: 28 */ 1882 9889 Larry sd_pm_iostart, /* Index: 29 */ 1883 9889 Larry sd_core_iostart, /* Index: 30 */ 1884 9889 Larry 1885 9889 Larry /* 1886 9889 Larry * Chain for buf IO for large sector size disk drive targets 1887 9889 Larry * with RMW needed with checksumming (PM disabled) 1888 9889 Larry */ 1889 9889 Larry sd_mapblockaddr_iostart, /* Index: 31 */ 1890 9889 Larry sd_mapblocksize_iostart, /* Index: 32 */ 1891 9889 Larry sd_checksum_iostart, /* Index: 33 */ 1892 9889 Larry sd_core_iostart, /* Index: 34 */ 1893 9889 Larry 1894 0 stevel }; 1895 0 stevel 1896 0 stevel /* 1897 0 stevel * Macros to locate the first function of each iostart chain in the 1898 0 stevel * sd_iostart_chain[] array. These are located by the index in the array. 1899 0 stevel */ 1900 0 stevel #define SD_CHAIN_DISK_IOSTART 0 1901 0 stevel #define SD_CHAIN_DISK_IOSTART_NO_PM 3 1902 9889 Larry #define SD_CHAIN_MSS_DISK_IOSTART 5 1903 0 stevel #define SD_CHAIN_RMMEDIA_IOSTART 5 1904 9889 Larry #define SD_CHAIN_MSS_DISK_IOSTART_NO_PM 9 1905 0 stevel #define SD_CHAIN_RMMEDIA_IOSTART_NO_PM 9 1906 0 stevel #define SD_CHAIN_CHKSUM_IOSTART 12 1907 0 stevel #define SD_CHAIN_CHKSUM_IOSTART_NO_PM 16 1908 0 stevel #define SD_CHAIN_USCSI_CMD_IOSTART 19 1909 0 stevel #define SD_CHAIN_USCSI_CHKSUM_IOSTART 21 1910 0 stevel #define SD_CHAIN_DIRECT_CMD_IOSTART 24 1911 0 stevel #define SD_CHAIN_PRIORITY_CMD_IOSTART 25 1912 9889 Larry #define SD_CHAIN_MSS_CHKSUM_IOSTART 26 1913 9889 Larry #define SD_CHAIN_MSS_CHKSUM_IOSTART_NO_PM 31 1914 0 stevel 1915 0 stevel 1916 0 stevel /* 1917 0 stevel * Table of function pointers for the iodone-side routines for the driver- 1918 0 stevel * internal layering mechanism. The calling sequence for iodone routines 1919 0 stevel * uses a decrementing table index, so the last routine called in a chain 1920 0 stevel * must be at the lowest array index location for that chain. The last 1921 0 stevel * routine for each chain must be either sd_buf_iodone() (for buf(9S) IOs) 1922 0 stevel * or sd_uscsi_iodone() (for uscsi IOs). Other than this, the ordering 1923 0 stevel * of the functions in an iodone side chain must correspond to the ordering 1924 0 stevel * of the iostart routines for that chain. Note that there is no iodone 1925 0 stevel * side routine that corresponds to sd_core_iostart(), so there is no 1926 0 stevel * entry in the table for this. 1927 0 stevel */ 1928 0 stevel 1929 0 stevel static sd_chain_t sd_iodone_chain[] = { 1930 0 stevel 1931 0 stevel /* Chain for buf IO for disk drive targets (PM enabled) */ 1932 0 stevel sd_buf_iodone, /* Index: 0 */ 1933 0 stevel sd_mapblockaddr_iodone, /* Index: 1 */ 1934 0 stevel sd_pm_iodone, /* Index: 2 */ 1935 0 stevel 1936 0 stevel /* Chain for buf IO for disk drive targets (PM disabled) */ 1937 0 stevel sd_buf_iodone, /* Index: 3 */ 1938 0 stevel sd_mapblockaddr_iodone, /* Index: 4 */ 1939 0 stevel 1940 9889 Larry /* 1941 9889 Larry * Chain for buf IO for removable-media or large sector size 1942 9889 Larry * disk drive targets with RMW needed (PM enabled) 1943 9889 Larry */ 1944 0 stevel sd_buf_iodone, /* Index: 5 */ 1945 0 stevel sd_mapblockaddr_iodone, /* Index: 6 */ 1946 0 stevel sd_mapblocksize_iodone, /* Index: 7 */ 1947 0 stevel sd_pm_iodone, /* Index: 8 */ 1948 0 stevel 1949 9889 Larry /* 1950 9889 Larry * Chain for buf IO for removable-media or large sector size 1951 9889 Larry * disk drive targets with RMW needed (PM disabled) 1952 9889 Larry */ 1953 0 stevel sd_buf_iodone, /* Index: 9 */ 1954 0 stevel sd_mapblockaddr_iodone, /* Index: 10 */ 1955 0 stevel sd_mapblocksize_iodone, /* Index: 11 */ 1956 0 stevel 1957 0 stevel /* Chain for buf IO for disk drives with checksumming (PM enabled) */ 1958 0 stevel sd_buf_iodone, /* Index: 12 */ 1959 0 stevel sd_mapblockaddr_iodone, /* Index: 13 */ 1960 0 stevel sd_checksum_iodone, /* Index: 14 */ 1961 0 stevel sd_pm_iodone, /* Index: 15 */ 1962 0 stevel 1963 0 stevel /* Chain for buf IO for disk drives with checksumming (PM disabled) */ 1964 0 stevel sd_buf_iodone, /* Index: 16 */ 1965 0 stevel sd_mapblockaddr_iodone, /* Index: 17 */ 1966 0 stevel sd_checksum_iodone, /* Index: 18 */ 1967 0 stevel 1968 0 stevel /* Chain for USCSI commands (non-checksum targets) */ 1969 0 stevel sd_uscsi_iodone, /* Index: 19 */ 1970 0 stevel sd_pm_iodone, /* Index: 20 */ 1971 0 stevel 1972 0 stevel /* Chain for USCSI commands (checksum targets) */ 1973 0 stevel sd_uscsi_iodone, /* Index: 21 */ 1974 0 stevel sd_checksum_uscsi_iodone, /* Index: 22 */ 1975 0 stevel sd_pm_iodone, /* Index: 22 */ 1976 0 stevel 1977 0 stevel /* Chain for "direct" USCSI commands (all targets) */ 1978 0 stevel sd_uscsi_iodone, /* Index: 24 */ 1979 0 stevel 1980 0 stevel /* Chain for "direct priority" USCSI commands (all targets) */ 1981 0 stevel sd_uscsi_iodone, /* Index: 25 */ 1982 9889 Larry 1983 9889 Larry /* 1984 9889 Larry * Chain for buf IO for large sector size disk drive targets 1985 9889 Larry * with checksumming (PM enabled) 1986 9889 Larry */ 1987 9889 Larry sd_buf_iodone, /* Index: 26 */ 1988 9889 Larry sd_mapblockaddr_iodone, /* Index: 27 */ 1989 9889 Larry sd_mapblocksize_iodone, /* Index: 28 */ 1990 9889 Larry sd_checksum_iodone, /* Index: 29 */ 1991 9889 Larry sd_pm_iodone, /* Index: 30 */ 1992 9889 Larry 1993 9889 Larry /* 1994 9889 Larry * Chain for buf IO for large sector size disk drive targets 1995 9889 Larry * with checksumming (PM disabled) 1996 9889 Larry */ 1997 9889 Larry sd_buf_iodone, /* Index: 31 */ 1998 9889 Larry sd_mapblockaddr_iodone, /* Index: 32 */ 1999 9889 Larry sd_mapblocksize_iodone, /* Index: 33 */ 2000 9889 Larry sd_checksum_iodone, /* Index: 34 */ 2001 0 stevel }; 2002 0 stevel 2003 0 stevel 2004 0 stevel /* 2005 0 stevel * Macros to locate the "first" function in the sd_iodone_chain[] array for 2006 0 stevel * each iodone-side chain. These are located by the array index, but as the 2007 0 stevel * iodone side functions are called in a decrementing-index order, the 2008 0 stevel * highest index number in each chain must be specified (as these correspond 2009 0 stevel * to the first function in the iodone chain that will be called by the core 2010 0 stevel * at IO completion time). 2011 0 stevel */ 2012 0 stevel 2013 0 stevel #define SD_CHAIN_DISK_IODONE 2 2014 0 stevel #define SD_CHAIN_DISK_IODONE_NO_PM 4 2015 0 stevel #define SD_CHAIN_RMMEDIA_IODONE 8 2016 9889 Larry #define SD_CHAIN_MSS_DISK_IODONE 8 2017 0 stevel #define SD_CHAIN_RMMEDIA_IODONE_NO_PM 11 2018 9889 Larry #define SD_CHAIN_MSS_DISK_IODONE_NO_PM 11 2019 0 stevel #define SD_CHAIN_CHKSUM_IODONE 15 2020 0 stevel #define SD_CHAIN_CHKSUM_IODONE_NO_PM 18 2021 0 stevel #define SD_CHAIN_USCSI_CMD_IODONE 20 2022 0 stevel #define SD_CHAIN_USCSI_CHKSUM_IODONE 22 2023 0 stevel #define SD_CHAIN_DIRECT_CMD_IODONE 24 2024 0 stevel #define SD_CHAIN_PRIORITY_CMD_IODONE 25 2025 9889 Larry #define SD_CHAIN_MSS_CHKSUM_IODONE 30 2026 9889 Larry #define SD_CHAIN_MSS_CHKSUM_IODONE_NO_PM 34 2027 0 stevel 2028 0 stevel 2029 0 stevel 2030 0 stevel /* 2031 0 stevel * Array to map a layering chain index to the appropriate initpkt routine. 2032 0 stevel * The redundant entries are present so that the index used for accessing 2033 0 stevel * the above sd_iostart_chain and sd_iodone_chain tables can be used directly 2034 0 stevel * with this table as well. 2035 0 stevel */ 2036 0 stevel typedef int (*sd_initpkt_t)(struct buf *, struct scsi_pkt **); 2037 0 stevel 2038 0 stevel static sd_initpkt_t sd_initpkt_map[] = { 2039 0 stevel 2040 0 stevel /* Chain for buf IO for disk drive targets (PM enabled) */ 2041 0 stevel sd_initpkt_for_buf, /* Index: 0 */ 2042 0 stevel sd_initpkt_for_buf, /* Index: 1 */ 2043 0 stevel sd_initpkt_for_buf, /* Index: 2 */ 2044 0 stevel 2045 0 stevel /* Chain for buf IO for disk drive targets (PM disabled) */ 2046 0 stevel sd_initpkt_for_buf, /* Index: 3 */ 2047 0 stevel sd_initpkt_for_buf, /* Index: 4 */ 2048 0 stevel 2049 9889 Larry /* 2050 9889 Larry * Chain for buf IO for removable-media or large sector size 2051 9889 Larry * disk drive targets (PM enabled) 2052 9889 Larry */ 2053 0 stevel sd_initpkt_for_buf, /* Index: 5 */ 2054 0 stevel sd_initpkt_for_buf, /* Index: 6 */ 2055 0 stevel sd_initpkt_for_buf, /* Index: 7 */ 2056 0 stevel sd_initpkt_for_buf, /* Index: 8 */ 2057 0 stevel 2058 9889 Larry /* 2059 9889 Larry * Chain for buf IO for removable-media or large sector size 2060 9889 Larry * disk drive targets (PM disabled) 2061 9889 Larry */ 2062 0 stevel sd_initpkt_for_buf, /* Index: 9 */ 2063 0 stevel sd_initpkt_for_buf, /* Index: 10 */ 2064 0 stevel sd_initpkt_for_buf, /* Index: 11 */ 2065 0 stevel 2066 0 stevel /* Chain for buf IO for disk drives with checksumming (PM enabled) */ 2067 0 stevel sd_initpkt_for_buf, /* Index: 12 */ 2068 0 stevel sd_initpkt_for_buf, /* Index: 13 */ 2069 0 stevel sd_initpkt_for_buf, /* Index: 14 */ 2070 0 stevel sd_initpkt_for_buf, /* Index: 15 */ 2071 0 stevel 2072 0 stevel /* Chain for buf IO for disk drives with checksumming (PM disabled) */ 2073 0 stevel sd_initpkt_for_buf, /* Index: 16 */ 2074 0 stevel sd_initpkt_for_buf, /* Index: 17 */ 2075 0 stevel sd_initpkt_for_buf, /* Index: 18 */ 2076 0 stevel 2077 0 stevel /* Chain for USCSI commands (non-checksum targets) */ 2078 0 stevel sd_initpkt_for_uscsi, /* Index: 19 */ 2079 0 stevel sd_initpkt_for_uscsi, /* Index: 20 */ 2080 0 stevel 2081 0 stevel /* Chain for USCSI commands (checksum targets) */ 2082 0 stevel sd_initpkt_for_uscsi, /* Index: 21 */ 2083 0 stevel sd_initpkt_for_uscsi, /* Index: 22 */ 2084 0 stevel sd_initpkt_for_uscsi, /* Index: 22 */ 2085 0 stevel 2086 0 stevel /* Chain for "direct" USCSI commands (all targets) */ 2087 0 stevel sd_initpkt_for_uscsi, /* Index: 24 */ 2088 0 stevel 2089 0 stevel /* Chain for "direct priority" USCSI commands (all targets) */ 2090 0 stevel sd_initpkt_for_uscsi, /* Index: 25 */ 2091 0 stevel 2092 9889 Larry /* 2093 9889 Larry * Chain for buf IO for large sector size disk drive targets 2094 9889 Larry * with checksumming (PM enabled) 2095 9889 Larry */ 2096 9889 Larry sd_initpkt_for_buf, /* Index: 26 */ 2097 9889 Larry sd_initpkt_for_buf, /* Index: 27 */ 2098 9889 Larry sd_initpkt_for_buf, /* Index: 28 */ 2099 9889 Larry sd_initpkt_for_buf, /* Index: 29 */ 2100 9889 Larry sd_initpkt_for_buf, /* Index: 30 */ 2101 9889 Larry 2102 9889 Larry /* 2103 9889 Larry * Chain for buf IO for large sector size disk drive targets 2104 9889 Larry * with checksumming (PM disabled) 2105 9889 Larry */ 2106 9889 Larry sd_initpkt_for_buf, /* Index: 31 */ 2107 9889 Larry sd_initpkt_for_buf, /* Index: 32 */ 2108 9889 Larry sd_initpkt_for_buf, /* Index: 33 */ 2109 9889 Larry sd_initpkt_for_buf, /* Index: 34 */ 2110 0 stevel }; 2111 0 stevel 2112 0 stevel 2113 0 stevel /* 2114 0 stevel * Array to map a layering chain index to the appropriate destroypktpkt routine. 2115 0 stevel * The redundant entries are present so that the index used for accessing 2116 0 stevel * the above sd_iostart_chain and sd_iodone_chain tables can be used directly 2117 0 stevel * with this table as well. 2118 0 stevel */ 2119 0 stevel typedef void (*sd_destroypkt_t)(struct buf *); 2120 0 stevel 2121 0 stevel static sd_destroypkt_t sd_destroypkt_map[] = { 2122 0 stevel 2123 0 stevel /* Chain for buf IO for disk drive targets (PM enabled) */ 2124 0 stevel sd_destroypkt_for_buf, /* Index: 0 */ 2125 0 stevel sd_destroypkt_for_buf, /* Index: 1 */ 2126 0 stevel sd_destroypkt_for_buf, /* Index: 2 */ 2127 0 stevel 2128 0 stevel /* Chain for buf IO for disk drive targets (PM disabled) */ 2129 0 stevel sd_destroypkt_for_buf, /* Index: 3 */ 2130 0 stevel sd_destroypkt_for_buf, /* Index: 4 */ 2131 0 stevel 2132 9889 Larry /* 2133 9889 Larry * Chain for buf IO for removable-media or large sector size 2134 9889 Larry * disk drive targets (PM enabled) 2135 9889 Larry */ 2136 0 stevel sd_destroypkt_for_buf, /* Index: 5 */ 2137 0 stevel sd_destroypkt_for_buf, /* Index: 6 */ 2138 0 stevel sd_destroypkt_for_buf, /* Index: 7 */ 2139 0 stevel sd_destroypkt_for_buf, /* Index: 8 */ 2140 0 stevel 2141 9889 Larry /* 2142 9889 Larry * Chain for buf IO for removable-media or large sector size 2143 9889 Larry * disk drive targets (PM disabled) 2144 9889 Larry */ 2145 0 stevel sd_destroypkt_for_buf, /* Index: 9 */ 2146 0 stevel sd_destroypkt_for_buf, /* Index: 10 */ 2147 0 stevel sd_destroypkt_for_buf, /* Index: 11 */ 2148 0 stevel 2149 0 stevel /* Chain for buf IO for disk drives with checksumming (PM enabled) */ 2150 0 stevel sd_destroypkt_for_buf, /* Index: 12 */ 2151 0 stevel sd_destroypkt_for_buf, /* Index: 13 */ 2152 0 stevel sd_destroypkt_for_buf, /* Index: 14 */ 2153 0 stevel sd_destroypkt_for_buf, /* Index: 15 */ 2154 0 stevel 2155 0 stevel /* Chain for buf IO for disk drives with checksumming (PM disabled) */ 2156 0 stevel sd_destroypkt_for_buf, /* Index: 16 */ 2157 0 stevel sd_destroypkt_for_buf, /* Index: 17 */ 2158 0 stevel sd_destroypkt_for_buf, /* Index: 18 */ 2159 0 stevel 2160 0 stevel /* Chain for USCSI commands (non-checksum targets) */ 2161 0 stevel sd_destroypkt_for_uscsi, /* Index: 19 */ 2162 0 stevel sd_destroypkt_for_uscsi, /* Index: 20 */ 2163 0 stevel 2164 0 stevel /* Chain for USCSI commands (checksum targets) */ 2165 0 stevel sd_destroypkt_for_uscsi, /* Index: 21 */ 2166 0 stevel sd_destroypkt_for_uscsi, /* Index: 22 */ 2167 0 stevel sd_destroypkt_for_uscsi, /* Index: 22 */ 2168 0 stevel 2169 0 stevel /* Chain for "direct" USCSI commands (all targets) */ 2170 0 stevel sd_destroypkt_for_uscsi, /* Index: 24 */ 2171 0 stevel 2172 0 stevel /* Chain for "direct priority" USCSI commands (all targets) */ 2173 0 stevel sd_destroypkt_for_uscsi, /* Index: 25 */ 2174 0 stevel 2175 9889 Larry /* 2176 9889 Larry * Chain for buf IO for large sector size disk drive targets 2177 9889 Larry * with checksumming (PM disabled) 2178 9889 Larry */ 2179 9889 Larry sd_destroypkt_for_buf, /* Index: 26 */ 2180 9889 Larry sd_destroypkt_for_buf, /* Index: 27 */ 2181 9889 Larry sd_destroypkt_for_buf, /* Index: 28 */ 2182 9889 Larry sd_destroypkt_for_buf, /* Index: 29 */ 2183 9889 Larry sd_destroypkt_for_buf, /* Index: 30 */ 2184 9889 Larry 2185 9889 Larry /* 2186 9889 Larry * Chain for buf IO for large sector size disk drive targets 2187 9889 Larry * with checksumming (PM enabled) 2188 9889 Larry */ 2189 9889 Larry sd_destroypkt_for_buf, /* Index: 31 */ 2190 9889 Larry sd_destroypkt_for_buf, /* Index: 32 */ 2191 9889 Larry sd_destroypkt_for_buf, /* Index: 33 */ 2192 9889 Larry sd_destroypkt_for_buf, /* Index: 34 */ 2193 0 stevel }; 2194 0 stevel 2195 0 stevel 2196 0 stevel 2197 0 stevel /* 2198 0 stevel * Array to map a layering chain index to the appropriate chain "type". 2199 0 stevel * The chain type indicates a specific property/usage of the chain. 2200 0 stevel * The redundant entries are present so that the index used for accessing 2201 0 stevel * the above sd_iostart_chain and sd_iodone_chain tables can be used directly 2202 0 stevel * with this table as well. 2203 0 stevel */ 2204 0 stevel 2205 0 stevel #define SD_CHAIN_NULL 0 /* for the special RQS cmd */ 2206 0 stevel #define SD_CHAIN_BUFIO 1 /* regular buf IO */ 2207 0 stevel #define SD_CHAIN_USCSI 2 /* regular USCSI commands */ 2208 0 stevel #define SD_CHAIN_DIRECT 3 /* uscsi, w/ bypass power mgt */ 2209 0 stevel #define SD_CHAIN_DIRECT_PRIORITY 4 /* uscsi, w/ bypass power mgt */ 2210 0 stevel /* (for error recovery) */ 2211 0 stevel 2212 0 stevel static int sd_chain_type_map[] = { 2213 0 stevel 2214 0 stevel /* Chain for buf IO for disk drive targets (PM enabled) */ 2215 0 stevel SD_CHAIN_BUFIO, /* Index: 0 */ 2216 0 stevel SD_CHAIN_BUFIO, /* Index: 1 */ 2217 0 stevel SD_CHAIN_BUFIO, /* Index: 2 */ 2218 0 stevel 2219 0 stevel /* Chain for buf IO for disk drive targets (PM disabled) */ 2220 0 stevel SD_CHAIN_BUFIO, /* Index: 3 */ 2221 0 stevel SD_CHAIN_BUFIO, /* Index: 4 */ 2222 0 stevel 2223 9889 Larry /* 2224 9889 Larry * Chain for buf IO for removable-media or large sector size 2225 9889 Larry * disk drive targets (PM enabled) 2226 9889 Larry */ 2227 0 stevel SD_CHAIN_BUFIO, /* Index: 5 */ 2228 0 stevel SD_CHAIN_BUFIO, /* Index: 6 */ 2229 0 stevel SD_CHAIN_BUFIO, /* Index: 7 */ 2230 0 stevel SD_CHAIN_BUFIO, /* Index: 8 */ 2231 0 stevel 2232 9889 Larry /* 2233 9889 Larry * Chain for buf IO for removable-media or large sector size 2234 9889 Larry * disk drive targets (PM disabled) 2235 9889 Larry */ 2236 0 stevel SD_CHAIN_BUFIO, /* Index: 9 */ 2237 0 stevel SD_CHAIN_BUFIO, /* Index: 10 */ 2238 0 stevel SD_CHAIN_BUFIO, /* Index: 11 */ 2239 0 stevel 2240 0 stevel /* Chain for buf IO for disk drives with checksumming (PM enabled) */ 2241 0 stevel SD_CHAIN_BUFIO, /* Index: 12 */ 2242 0 stevel SD_CHAIN_BUFIO, /* Index: 13 */ 2243 0 stevel SD_CHAIN_BUFIO, /* Index: 14 */ 2244 0 stevel SD_CHAIN_BUFIO, /* Index: 15 */ 2245 0 stevel 2246 0 stevel /* Chain for buf IO for disk drives with checksumming (PM disabled) */ 2247 0 stevel SD_CHAIN_BUFIO, /* Index: 16 */ 2248 0 stevel SD_CHAIN_BUFIO, /* Index: 17 */ 2249 0 stevel SD_CHAIN_BUFIO, /* Index: 18 */ 2250 0 stevel 2251 0 stevel /* Chain for USCSI commands (non-checksum targets) */ 2252 0 stevel SD_CHAIN_USCSI, /* Index: 19 */ 2253 0 stevel SD_CHAIN_USCSI, /* Index: 20 */ 2254 0 stevel 2255 0 stevel /* Chain for USCSI commands (checksum targets) */ 2256 0 stevel SD_CHAIN_USCSI, /* Index: 21 */ 2257 0 stevel SD_CHAIN_USCSI, /* Index: 22 */ 2258 9889 Larry SD_CHAIN_USCSI, /* Index: 23 */ 2259 0 stevel 2260 0 stevel /* Chain for "direct" USCSI commands (all targets) */ 2261 0 stevel SD_CHAIN_DIRECT, /* Index: 24 */ 2262 0 stevel 2263 0 stevel /* Chain for "direct priority" USCSI commands (all targets) */ 2264 0 stevel SD_CHAIN_DIRECT_PRIORITY, /* Index: 25 */ 2265 9889 Larry 2266 9889 Larry /* 2267 9889 Larry * Chain for buf IO for large sector size disk drive targets 2268 9889 Larry * with checksumming (PM enabled) 2269 9889 Larry */ 2270 9889 Larry SD_CHAIN_BUFIO, /* Index: 26 */ 2271 9889 Larry SD_CHAIN_BUFIO, /* Index: 27 */ 2272 9889 Larry SD_CHAIN_BUFIO, /* Index: 28 */ 2273 9889 Larry SD_CHAIN_BUFIO, /* Index: 29 */ 2274 9889 Larry SD_CHAIN_BUFIO, /* Index: 30 */ 2275 9889 Larry 2276 9889 Larry /* 2277 9889 Larry * Chain for buf IO for large sector size disk drive targets 2278 9889 Larry * with checksumming (PM disabled) 2279 9889 Larry */ 2280 9889 Larry SD_CHAIN_BUFIO, /* Index: 31 */ 2281 9889 Larry SD_CHAIN_BUFIO, /* Index: 32 */ 2282 9889 Larry SD_CHAIN_BUFIO, /* Index: 33 */ 2283 9889 Larry SD_CHAIN_BUFIO, /* Index: 34 */ 2284 0 stevel }; 2285 0 stevel 2286 0 stevel 2287 0 stevel /* Macro to return TRUE if the IO has come from the sd_buf_iostart() chain. */ 2288 0 stevel #define SD_IS_BUFIO(xp) \ 2289 0 stevel (sd_chain_type_map[(xp)->xb_chain_iostart] == SD_CHAIN_BUFIO) 2290 0 stevel 2291 0 stevel /* Macro to return TRUE if the IO has come from the "direct priority" chain. */ 2292 0 stevel #define SD_IS_DIRECT_PRIORITY(xp) \ 2293 0 stevel (sd_chain_type_map[(xp)->xb_chain_iostart] == SD_CHAIN_DIRECT_PRIORITY) 2294 0 stevel 2295 0 stevel 2296 0 stevel 2297 0 stevel /* 2298 0 stevel * Struct, array, and macros to map a specific chain to the appropriate 2299 0 stevel * layering indexes in the sd_iostart_chain[] and sd_iodone_chain[] arrays. 2300 0 stevel * 2301 0 stevel * The sd_chain_index_map[] array is used at attach time to set the various 2302 0 stevel * un_xxx_chain type members of the sd_lun softstate to the specific layering 2303 0 stevel * chain to be used with the instance. This allows different instances to use 2304 0 stevel * different chain for buf IO, uscsi IO, etc.. Also, since the xb_chain_iostart 2305 0 stevel * and xb_chain_iodone index values in the sd_xbuf are initialized to these 2306 0 stevel * values at sd_xbuf init time, this allows (1) layering chains may be changed 2307 0 stevel * dynamically & without the use of locking; and (2) a layer may update the 2308 0 stevel * xb_chain_io[start|done] member in a given xbuf with its current index value, 2309 0 stevel * to allow for deferred processing of an IO within the same chain from a 2310 0 stevel * different execution context. 2311 0 stevel */ 2312 0 stevel 2313 0 stevel struct sd_chain_index { 2314 0 stevel int sci_iostart_index; 2315 0 stevel int sci_iodone_index; 2316 0 stevel }; 2317 0 stevel 2318 0 stevel static struct sd_chain_index sd_chain_index_map[] = { 2319 0 stevel { SD_CHAIN_DISK_IOSTART, SD_CHAIN_DISK_IODONE }, 2320 0 stevel { SD_CHAIN_DISK_IOSTART_NO_PM, SD_CHAIN_DISK_IODONE_NO_PM }, 2321 0 stevel { SD_CHAIN_RMMEDIA_IOSTART, SD_CHAIN_RMMEDIA_IODONE }, 2322 0 stevel { SD_CHAIN_RMMEDIA_IOSTART_NO_PM, SD_CHAIN_RMMEDIA_IODONE_NO_PM }, 2323 0 stevel { SD_CHAIN_CHKSUM_IOSTART, SD_CHAIN_CHKSUM_IODONE }, 2324 0 stevel { SD_CHAIN_CHKSUM_IOSTART_NO_PM, SD_CHAIN_CHKSUM_IODONE_NO_PM }, 2325 0 stevel { SD_CHAIN_USCSI_CMD_IOSTART, SD_CHAIN_USCSI_CMD_IODONE }, 2326 0 stevel { SD_CHAIN_USCSI_CHKSUM_IOSTART, SD_CHAIN_USCSI_CHKSUM_IODONE }, 2327 0 stevel { SD_CHAIN_DIRECT_CMD_IOSTART, SD_CHAIN_DIRECT_CMD_IODONE }, 2328 0 stevel { SD_CHAIN_PRIORITY_CMD_IOSTART, SD_CHAIN_PRIORITY_CMD_IODONE }, 2329 9889 Larry { SD_CHAIN_MSS_CHKSUM_IOSTART, SD_CHAIN_MSS_CHKSUM_IODONE }, 2330 9889 Larry { SD_CHAIN_MSS_CHKSUM_IOSTART_NO_PM, SD_CHAIN_MSS_CHKSUM_IODONE_NO_PM }, 2331 9889 Larry 2332 0 stevel }; 2333 0 stevel 2334 0 stevel 2335 0 stevel /* 2336 0 stevel * The following are indexes into the sd_chain_index_map[] array. 2337 0 stevel */ 2338 0 stevel 2339 0 stevel /* un->un_buf_chain_type must be set to one of these */ 2340 0 stevel #define SD_CHAIN_INFO_DISK 0 2341 0 stevel #define SD_CHAIN_INFO_DISK_NO_PM 1 2342 0 stevel #define SD_CHAIN_INFO_RMMEDIA 2 2343 9889 Larry #define SD_CHAIN_INFO_MSS_DISK 2 2344 0 stevel #define SD_CHAIN_INFO_RMMEDIA_NO_PM 3 2345 9889 Larry #define SD_CHAIN_INFO_MSS_DSK_NO_PM 3 2346 0 stevel #define SD_CHAIN_INFO_CHKSUM 4 2347 0 stevel #define SD_CHAIN_INFO_CHKSUM_NO_PM 5 2348 9889 Larry #define SD_CHAIN_INFO_MSS_DISK_CHKSUM 10 2349 9889 Larry #define SD_CHAIN_INFO_MSS_DISK_CHKSUM_NO_PM 11 2350 0 stevel 2351 0 stevel /* un->un_uscsi_chain_type must be set to one of these */ 2352 0 stevel #define SD_CHAIN_INFO_USCSI_CMD 6 2353 0 stevel /* USCSI with PM disabled is the same as DIRECT */ 2354 0 stevel #define SD_CHAIN_INFO_USCSI_CMD_NO_PM 8 2355 0 stevel #define SD_CHAIN_INFO_USCSI_CHKSUM 7 2356 0 stevel 2357 0 stevel /* un->un_direct_chain_type must be set to one of these */ 2358 0 stevel #define SD_CHAIN_INFO_DIRECT_CMD 8 2359 0 stevel 2360 0 stevel /* un->un_priority_chain_type must be set to one of these */ 2361 0 stevel #define SD_CHAIN_INFO_PRIORITY_CMD 9 2362 0 stevel 2363 0 stevel /* size for devid inquiries */ 2364 0 stevel #define MAX_INQUIRY_SIZE 0xF0 2365 0 stevel 2366 0 stevel /* 2367 0 stevel * Macros used by functions to pass a given buf(9S) struct along to the 2368 0 stevel * next function in the layering chain for further processing. 2369 0 stevel * 2370 0 stevel * In the following macros, passing more than three arguments to the called 2371 0 stevel * routines causes the optimizer for the SPARC compiler to stop doing tail 2372 0 stevel * call elimination which results in significant performance degradation. 2373 0 stevel */ 2374 0 stevel #define SD_BEGIN_IOSTART(index, un, bp) \ 2375 0 stevel ((*(sd_iostart_chain[index]))(index, un, bp)) 2376 0 stevel 2377 0 stevel #define SD_BEGIN_IODONE(index, un, bp) \ 2378 0 stevel ((*(sd_iodone_chain[index]))(index, un, bp)) 2379 0 stevel 2380 0 stevel #define SD_NEXT_IOSTART(index, un, bp) \ 2381 0 stevel ((*(sd_iostart_chain[(index) + 1]))((index) + 1, un, bp)) 2382 0 stevel 2383 0 stevel #define SD_NEXT_IODONE(index, un, bp) \ 2384 0 stevel ((*(sd_iodone_chain[(index) - 1]))((index) - 1, un, bp)) 2385 0 stevel 2386 0 stevel /* 2387 0 stevel * Function: _init 2388 0 stevel * 2389 0 stevel * Description: This is the driver _init(9E) entry point. 2390 0 stevel * 2391 0 stevel * Return Code: Returns the value from mod_install(9F) or 2392 0 stevel * ddi_soft_state_init(9F) as appropriate. 2393 0 stevel * 2394 0 stevel * Context: Called when driver module loaded. 2395 0 stevel */ 2396 0 stevel 2397 0 stevel int 2398 0 stevel _init(void) 2399 0 stevel { 2400 0 stevel int err; 2401 0 stevel 2402 0 stevel /* establish driver name from module name */ 2403 7009 cth sd_label = (char *)mod_modname(&modlinkage); 2404 0 stevel 2405 8863 Edward #ifndef XPV_HVM_DRIVER 2406 0 stevel err = ddi_soft_state_init(&sd_state, sizeof (struct sd_lun), 2407 4451 eschrock SD_MAXUNIT); 2408 0 stevel if (err != 0) { 2409 0 stevel return (err); 2410 0 stevel } 2411 8863 Edward 2412 8863 Edward #else /* XPV_HVM_DRIVER */ 2413 8863 Edward /* Remove the leading "hvm_" from the module name */ 2414 8863 Edward ASSERT(strncmp(sd_label, "hvm_", strlen("hvm_")) == 0); 2415 8863 Edward sd_label += strlen("hvm_"); 2416 8863 Edward 2417 8863 Edward #endif /* XPV_HVM_DRIVER */ 2418 0 stevel 2419 0 stevel mutex_init(&sd_detach_mutex, NULL, MUTEX_DRIVER, NULL); 2420 0 stevel mutex_init(&sd_log_mutex, NULL, MUTEX_DRIVER, NULL); 2421 0 stevel mutex_init(&sd_label_mutex, NULL, MUTEX_DRIVER, NULL); 2422 0 stevel 2423 0 stevel mutex_init(&sd_tr.srq_resv_reclaim_mutex, NULL, MUTEX_DRIVER, NULL); 2424 0 stevel cv_init(&sd_tr.srq_resv_reclaim_cv, NULL, CV_DRIVER, NULL); 2425 0 stevel cv_init(&sd_tr.srq_inprocess_cv, NULL, CV_DRIVER, NULL); 2426 0 stevel 2427 0 stevel /* 2428 0 stevel * it's ok to init here even for fibre device 2429 0 stevel */ 2430 0 stevel sd_scsi_probe_cache_init(); 2431 0 stevel 2432 2683 yl194034 sd_scsi_target_lun_init(); 2433 2683 yl194034 2434 0 stevel /* 2435 0 stevel * Creating taskq before mod_install ensures that all callers (threads) 2436 7224 cth * that enter the module after a successful mod_install encounter 2437 0 stevel * a valid taskq. 2438 0 stevel */ 2439 0 stevel sd_taskq_create(); 2440 0 stevel 2441 0 stevel err = mod_install(&modlinkage); 2442 0 stevel if (err != 0) { 2443 0 stevel /* delete taskq if install fails */ 2444 0 stevel sd_taskq_delete(); 2445 0 stevel 2446 0 stevel mutex_destroy(&sd_detach_mutex); 2447 0 stevel mutex_destroy(&sd_log_mutex); 2448 0 stevel mutex_destroy(&sd_label_mutex); 2449 0 stevel 2450 0 stevel mutex_destroy(&sd_tr.srq_resv_reclaim_mutex); 2451 0 stevel cv_destroy(&sd_tr.srq_resv_reclaim_cv); 2452 0 stevel cv_destroy(&sd_tr.srq_inprocess_cv); 2453 0 stevel 2454 0 stevel sd_scsi_probe_cache_fini(); 2455 0 stevel 2456 2683 yl194034 sd_scsi_target_lun_fini(); 2457 2683 yl194034 2458 8863 Edward #ifndef XPV_HVM_DRIVER 2459 0 stevel ddi_soft_state_fini(&sd_state); 2460 8863 Edward #endif /* !XPV_HVM_DRIVER */ 2461 0 stevel return (err); 2462 0 stevel } 2463 0 stevel 2464 0 stevel return (err); 2465 0 stevel } 2466 0 stevel 2467 0 stevel 2468 0 stevel /* 2469 0 stevel * Function: _fini 2470 0 stevel * 2471 0 stevel * Description: This is the driver _fini(9E) entry point. 2472 0 stevel * 2473 0 stevel * Return Code: Returns the value from mod_remove(9F) 2474 0 stevel * 2475 0 stevel * Context: Called when driver module is unloaded. 2476 0 stevel */ 2477 0 stevel 2478 0 stevel int 2479 0 stevel _fini(void) 2480 0 stevel { 2481 0 stevel int err; 2482 0 stevel 2483 0 stevel if ((err = mod_remove(&modlinkage)) != 0) { 2484 0 stevel return (err); 2485 0 stevel } 2486 0 stevel 2487 0 stevel sd_taskq_delete(); 2488 0 stevel 2489 0 stevel mutex_destroy(&sd_detach_mutex); 2490 0 stevel mutex_destroy(&sd_log_mutex); 2491 0 stevel mutex_destroy(&sd_label_mutex); 2492 0 stevel mutex_destroy(&sd_tr.srq_resv_reclaim_mutex); 2493 0 stevel 2494 0 stevel sd_scsi_probe_cache_fini(); 2495 2683 yl194034 2496 2683 yl194034 sd_scsi_target_lun_fini(); 2497 0 stevel 2498 0 stevel cv_destroy(&sd_tr.srq_resv_reclaim_cv); 2499 0 stevel cv_destroy(&sd_tr.srq_inprocess_cv); 2500 0 stevel 2501 8863 Edward #ifndef XPV_HVM_DRIVER 2502 0 stevel ddi_soft_state_fini(&sd_state); 2503 8863 Edward #endif /* !XPV_HVM_DRIVER */ 2504 0 stevel 2505 0 stevel return (err); 2506 0 stevel } 2507 0 stevel 2508 0 stevel 2509 0 stevel /* 2510 0 stevel * Function: _info 2511 0 stevel * 2512 0 stevel * Description: This is the driver _info(9E) entry point. 2513 0 stevel * 2514 0 stevel * Arguments: modinfop - pointer to the driver modinfo structure 2515 0 stevel * 2516 0 stevel * Return Code: Returns the value from mod_info(9F). 2517 0 stevel * 2518 0 stevel * Context: Kernel thread context 2519 0 stevel */ 2520 0 stevel 2521 0 stevel int 2522 0 stevel _info(struct modinfo *modinfop) 2523 0 stevel { 2524 0 stevel return (mod_info(&modlinkage, modinfop)); 2525 0 stevel } 2526 0 stevel 2527 0 stevel 2528 0 stevel /* 2529 0 stevel * The following routines implement the driver message logging facility. 2530 0 stevel * They provide component- and level- based debug output filtering. 2531 0 stevel * Output may also be restricted to messages for a single instance by 2532 0 stevel * specifying a soft state pointer in sd_debug_un. If sd_debug_un is set 2533 0 stevel * to NULL, then messages for all instances are printed. 2534 0 stevel * 2535 0 stevel * These routines have been cloned from each other due to the language 2536 0 stevel * constraints of macros and variable argument list processing. 2537 0 stevel */ 2538 0 stevel 2539 0 stevel 2540 0 stevel /* 2541 0 stevel * Function: sd_log_err 2542 0 stevel * 2543 0 stevel * Description: This routine is called by the SD_ERROR macro for debug 2544 0 stevel * logging of error conditions. 2545 0 stevel * 2546 0 stevel * Arguments: comp - driver component being logged 2547 0 stevel * dev - pointer to driver info structure 2548 0 stevel * fmt - error string and format to be logged 2549 0 stevel */ 2550 0 stevel 2551 0 stevel static void 2552 0 stevel sd_log_err(uint_t comp, struct sd_lun *un, const char *fmt, ...) 2553 0 stevel { 2554 0 stevel va_list ap; 2555 0 stevel dev_info_t *dev; 2556 0 stevel 2557 0 stevel ASSERT(un != NULL); 2558 0 stevel dev = SD_DEVINFO(un); 2559 0 stevel ASSERT(dev != NULL); 2560 0 stevel 2561 0 stevel /* 2562 0 stevel * Filter messages based on the global component and level masks. 2563 0 stevel * Also print if un matches the value of sd_debug_un, or if 2564 0 stevel * sd_debug_un is set to NULL. 2565 0 stevel */ 2566 0 stevel if ((sd_component_mask & comp) && (sd_level_mask & SD_LOGMASK_ERROR) && 2567 0 stevel ((sd_debug_un == NULL) || (sd_debug_un == un))) { 2568 0 stevel mutex_enter(&sd_log_mutex); 2569 0 stevel va_start(ap, fmt); 2570 0 stevel (void) vsprintf(sd_log_buf, fmt, ap); 2571 0 stevel va_end(ap); 2572 0 stevel scsi_log(dev, sd_label, CE_CONT, "%s", sd_log_buf); 2573 0 stevel mutex_exit(&sd_log_mutex); 2574 0 stevel } 2575 0 stevel #ifdef SD_FAULT_INJECTION 2576 0 stevel _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::sd_injection_mask)); 2577 0 stevel if (un->sd_injection_mask & comp) { 2578 0 stevel mutex_enter(&sd_log_mutex); 2579 0 stevel va_start(ap, fmt); 2580 0 stevel (void) vsprintf(sd_log_buf, fmt, ap); 2581 0 stevel va_end(ap); 2582 0 stevel sd_injection_log(sd_log_buf, un); 2583 0 stevel mutex_exit(&sd_log_mutex); 2584 0 stevel } 2585 0 stevel #endif 2586 0 stevel } 2587 0 stevel 2588 0 stevel 2589 0 stevel /* 2590 0 stevel * Function: sd_log_info 2591 0 stevel * 2592 0 stevel * Description: This routine is called by the SD_INFO macro for debug 2593 0 stevel * logging of general purpose informational conditions. 2594 0 stevel * 2595 0 stevel * Arguments: comp - driver component being logged 2596 0 stevel * dev - pointer to driver info structure 2597 0 stevel * fmt - info string and format to be logged 2598 0 stevel */ 2599 0 stevel 2600 0 stevel static void 2601 0 stevel sd_log_info(uint_t component, struct sd_lun *un, const char *fmt, ...) 2602 0 stevel { 2603 0 stevel va_list ap; 2604 0 stevel dev_info_t *dev; 2605 0 stevel 2606 0 stevel ASSERT(un != NULL); 2607 0 stevel dev = SD_DEVINFO(un); 2608 0 stevel ASSERT(dev != NULL); 2609 0 stevel 2610 0 stevel /* 2611 0 stevel * Filter messages based on the global component and level masks. 2612 0 stevel * Also print if un matches the value of sd_debug_un, or if 2613 0 stevel * sd_debug_un is set to NULL. 2614 0 stevel */ 2615 0 stevel if ((sd_component_mask & component) && 2616 0 stevel (sd_level_mask & SD_LOGMASK_INFO) && 2617 0 stevel ((sd_debug_un == NULL) || (sd_debug_un == un))) { 2618 0 stevel mutex_enter(&sd_log_mutex); 2619 0 stevel va_start(ap, fmt); 2620 0 stevel (void) vsprintf(sd_log_buf, fmt, ap); 2621 0 stevel va_end(ap); 2622 0 stevel scsi_log(dev, sd_label, CE_CONT, "%s", sd_log_buf); 2623 0 stevel mutex_exit(&sd_log_mutex); 2624 0 stevel } 2625 0 stevel #ifdef SD_FAULT_INJECTION 2626 0 stevel _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::sd_injection_mask)); 2627 0 stevel if (un->sd_injection_mask & component) { 2628 0 stevel mutex_enter(&sd_log_mutex); 2629 0 stevel va_start(ap, fmt); 2630 0 stevel (void) vsprintf(sd_log_buf, fmt, ap); 2631 0 stevel va_end(ap); 2632 0 stevel sd_injection_log(sd_log_buf, un); 2633 0 stevel mutex_exit(&sd_log_mutex); 2634 0 stevel } 2635 0 stevel #endif 2636 0 stevel } 2637 0 stevel 2638 0 stevel 2639 0 stevel /* 2640 0 stevel * Function: sd_log_trace 2641 0 stevel * 2642 0 stevel * Description: This routine is called by the SD_TRACE macro for debug 2643 0 stevel * logging of trace conditions (i.e. function entry/exit). 2644 0 stevel * 2645 0 stevel * Arguments: comp - driver component being logged 2646 0 stevel * dev - pointer to driver info structure 2647 0 stevel * fmt - trace string and format to be logged 2648 0 stevel */ 2649 0 stevel 2650 0 stevel static void 2651 0 stevel sd_log_trace(uint_t component, struct sd_lun *un, const char *fmt, ...) 2652 0 stevel { 2653 0 stevel va_list ap; 2654 0 stevel dev_info_t *dev; 2655 0 stevel 2656 0 stevel ASSERT(un != NULL); 2657 0 stevel dev = SD_DEVINFO(un); 2658 0 stevel ASSERT(dev != NULL); 2659 0 stevel 2660 0 stevel /* 2661 0 stevel * Filter messages based on the global component and level masks. 2662 0 stevel * Also print if un matches the value of sd_debug_un, or if 2663 0 stevel * sd_debug_un is set to NULL. 2664 0 stevel */ 2665 0 stevel if ((sd_component_mask & component) && 2666 0 stevel (sd_level_mask & SD_LOGMASK_TRACE) && 2667 0 stevel ((sd_debug_un == NULL) || (sd_debug_un == un))) { 2668 0 stevel mutex_enter(&sd_log_mutex); 2669 0 stevel va_start(ap, fmt); 2670 0 stevel (void) vsprintf(sd_log_buf, fmt, ap); 2671 0 stevel va_end(ap); 2672 0 stevel scsi_log(dev, sd_label, CE_CONT, "%s", sd_log_buf); 2673 0 stevel mutex_exit(&sd_log_mutex); 2674 0 stevel } 2675 0 stevel #ifdef SD_FAULT_INJECTION 2676 0 stevel _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::sd_injection_mask)); 2677 0 stevel if (un->sd_injection_mask & component) { 2678 0 stevel mutex_enter(&sd_log_mutex); 2679 0 stevel va_start(ap, fmt); 2680 0 stevel (void) vsprintf(sd_log_buf, fmt, ap); 2681 0 stevel va_end(ap); 2682 0 stevel sd_injection_log(sd_log_buf, un); 2683 0 stevel mutex_exit(&sd_log_mutex); 2684 0 stevel } 2685 0 stevel #endif 2686 0 stevel } 2687 0 stevel 2688 0 stevel 2689 0 stevel /* 2690 0 stevel * Function: sdprobe 2691 0 stevel * 2692 0 stevel * Description: This is the driver probe(9e) entry point function. 2693 0 stevel * 2694 0 stevel * Arguments: devi - opaque device info handle 2695 0 stevel * 2696 0 stevel * Return Code: DDI_PROBE_SUCCESS: If the probe was successful. 2697 0 stevel * DDI_PROBE_FAILURE: If the probe failed. 2698 0 stevel * DDI_PROBE_PARTIAL: If the instance is not present now, 2699 0 stevel * but may be present in the future. 2700 0 stevel */ 2701 0 stevel 2702 0 stevel static int 2703 0 stevel sdprobe(dev_info_t *devi) 2704 0 stevel { 2705 0 stevel struct scsi_device *devp; 2706 0 stevel int rval; 2707 8863 Edward #ifndef XPV_HVM_DRIVER 2708 8863 Edward int instance = ddi_get_instance(devi); 2709 8863 Edward #endif /* !XPV_HVM_DRIVER */ 2710 0 stevel 2711 0 stevel /* 2712 0 stevel * if it wasn't for pln, sdprobe could actually be nulldev 2713 0 stevel * in the "__fibre" case. 2714 0 stevel */ 2715 0 stevel if (ddi_dev_is_sid(devi) == DDI_SUCCESS) { 2716 0 stevel return (DDI_PROBE_DONTCARE); 2717 0 stevel } 2718 0 stevel 2719 0 stevel devp = ddi_get_driver_private(devi); 2720 0 stevel 2721 0 stevel if (devp == NULL) { 2722 0 stevel /* Ooops... nexus driver is mis-configured... */ 2723 0 stevel return (DDI_PROBE_FAILURE); 2724 0 stevel } 2725 0 stevel 2726 8863 Edward #ifndef XPV_HVM_DRIVER 2727 0 stevel if (ddi_get_soft_state(sd_state, instance) != NULL) { 2728 0 stevel return (DDI_PROBE_PARTIAL); 2729 0 stevel } 2730 8863 Edward #endif /* !XPV_HVM_DRIVER */ 2731 0 stevel 2732 0 stevel /* 2733 0 stevel * Call the SCSA utility probe routine to see if we actually 2734 0 stevel * have a target at this SCSI nexus. 2735 0 stevel */ 2736 0 stevel switch (sd_scsi_probe_with_cache(devp, NULL_FUNC)) { 2737 0 stevel case SCSIPROBE_EXISTS: 2738 0 stevel switch (devp->sd_inq->inq_dtype) { 2739 0 stevel case DTYPE_DIRECT: 2740 0 stevel rval = DDI_PROBE_SUCCESS; 2741 0 stevel break; 2742 0 stevel case DTYPE_RODIRECT: 2743 0 stevel /* CDs etc. Can be removable media */ 2744 0 stevel rval = DDI_PROBE_SUCCESS; 2745 0 stevel break; 2746 0 stevel case DTYPE_OPTICAL: 2747 0 stevel /* 2748 0 stevel * Rewritable optical driver HP115AA 2749 0 stevel * Can also be removable media 2750 0 stevel */ 2751 0 stevel 2752 0 stevel /* 2753 0 stevel * Do not attempt to bind to DTYPE_OPTICAL if 2754 0 stevel * pre solaris 9 sparc sd behavior is required 2755 0 stevel * 2756 0 stevel * If first time through and sd_dtype_optical_bind 2757 0 stevel * has not been set in /etc/system check properties 2758 0 stevel */ 2759 0 stevel 2760 0 stevel if (sd_dtype_optical_bind < 0) { 2761 4451 eschrock sd_dtype_optical_bind = ddi_prop_get_int 2762 4451 eschrock (DDI_DEV_T_ANY, devi, 0, 2763 4451 eschrock "optical-device-bind", 1); 2764 0 stevel } 2765 0 stevel 2766 0 stevel if (sd_dtype_optical_bind == 0) { 2767 0 stevel rval = DDI_PROBE_FAILURE; 2768 0 stevel } else { 2769 0 stevel rval = DDI_PROBE_SUCCESS; 2770 0 stevel } 2771 0 stevel break; 2772 0 stevel 2773 0 stevel case DTYPE_NOTPRESENT: 2774 0 stevel default: 2775 0 stevel rval = DDI_PROBE_FAILURE; 2776 0 stevel break; 2777 0 stevel } 2778 0 stevel break; 2779 0 stevel default: 2780 0 stevel rval = DDI_PROBE_PARTIAL; 2781 0 stevel break; 2782 0 stevel } 2783 0 stevel 2784 0 stevel /* 2785 0 stevel * This routine checks for resource allocation prior to freeing, 2786 0 stevel * so it will take care of the "smart probing" case where a 2787 0 stevel * scsi_probe() may or may not have been issued and will *not* 2788 0 stevel * free previously-freed resources. 2789 0 stevel */ 2790 0 stevel scsi_unprobe(devp); 2791 0 stevel return (rval); 2792 0 stevel } 2793 0 stevel 2794 0 stevel 2795 0 stevel /* 2796 0 stevel * Function: sdinfo 2797 0 stevel * 2798 0 stevel * Description: This is the driver getinfo(9e) entry point function. 2799 0 stevel * Given the device number, return the devinfo pointer from 2800 0 stevel * the scsi_device structure or the instance number 2801 0 stevel * associated with the dev_t. 2802 0 stevel * 2803 0 stevel * Arguments: dip - pointer to device info structure 2804 0 stevel * infocmd - command argument (DDI_INFO_DEVT2DEVINFO, 2805 0 stevel * DDI_INFO_DEVT2INSTANCE) 2806 0 stevel * arg - driver dev_t 2807 0 stevel * resultp - user buffer for request response 2808 0 stevel * 2809 0 stevel * Return Code: DDI_SUCCESS 2810 0 stevel * DDI_FAILURE 2811 0 stevel */ 2812 0 stevel /* ARGSUSED */ 2813 0 stevel static int 2814 0 stevel sdinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 2815 0 stevel { 2816 0 stevel struct sd_lun *un; 2817 0 stevel dev_t dev; 2818 0 stevel int instance; 2819 0 stevel int error; 2820 0 stevel 2821 0 stevel switch (infocmd) { 2822 0 stevel case DDI_INFO_DEVT2DEVINFO: 2823 0 stevel dev = (dev_t)arg; 2824 0 stevel instance = SDUNIT(dev); 2825 0 stevel if ((un = ddi_get_soft_state(sd_state, instance)) == NULL) { 2826 0 stevel return (DDI_FAILURE); 2827 0 stevel } 2828 0 stevel *result = (void *) SD_DEVINFO(un); 2829 0 stevel error = DDI_SUCCESS; 2830 0 stevel break; 2831 0 stevel case DDI_INFO_DEVT2INSTANCE: 2832 0 stevel dev = (dev_t)arg; 2833 0 stevel instance = SDUNIT(dev); 2834 0 stevel *result = (void *)(uintptr_t)instance; 2835 0 stevel error = DDI_SUCCESS; 2836 0 stevel break; 2837 0 stevel default: 2838 0 stevel error = DDI_FAILURE; 2839 0 stevel } 2840 0 stevel return (error); 2841 0 stevel } 2842 0 stevel 2843 0 stevel /* 2844 0 stevel * Function: sd_prop_op 2845 0 stevel * 2846 0 stevel * Description: This is the driver prop_op(9e) entry point function. 2847 0 stevel * Return the number of blocks for the partition in question 2848 0 stevel * or forward the request to the property facilities. 2849 0 stevel * 2850 0 stevel * Arguments: dev - device number 2851 0 stevel * dip - pointer to device info structure 2852 0 stevel * prop_op - property operator 2853 0 stevel * mod_flags - DDI_PROP_DONTPASS, don't pass to parent 2854 0 stevel * name - pointer to property name 2855 0 stevel * valuep - pointer or address of the user buffer 2856 0 stevel * lengthp - property length 2857 0 stevel * 2858 0 stevel * Return Code: DDI_PROP_SUCCESS 2859 0 stevel * DDI_PROP_NOT_FOUND 2860 0 stevel * DDI_PROP_UNDEFINED 2861 0 stevel * DDI_PROP_NO_MEMORY 2862 0 stevel * DDI_PROP_BUF_TOO_SMALL 2863 0 stevel */ 2864 0 stevel 2865 0 stevel static int 2866 0 stevel sd_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, int mod_flags, 2867 0 stevel char *name, caddr_t valuep, int *lengthp) 2868 0 stevel { 2869 0 stevel struct sd_lun *un; 2870 7224 cth 2871 7224 cth if ((un = ddi_get_soft_state(sd_state, ddi_get_instance(dip))) == NULL) 2872 0 stevel return (ddi_prop_op(dev, dip, prop_op, mod_flags, 2873 0 stevel name, valuep, lengthp)); 2874 7224 cth 2875 7224 cth return (cmlb_prop_op(un->un_cmlbhandle, 2876 7224 cth dev, dip, prop_op, mod_flags, name, valuep, lengthp, 2877 7224 cth SDPART(dev), (void *)SD_PATH_DIRECT)); 2878 0 stevel } 2879 0 stevel 2880 0 stevel /* 2881 0 stevel * The following functions are for smart probing: 2882 0 stevel * sd_scsi_probe_cache_init() 2883 0 stevel * sd_scsi_probe_cache_fini() 2884 0 stevel * sd_scsi_clear_probe_cache() 2885 0 stevel * sd_scsi_probe_with_cache() 2886 0 stevel */ 2887 0 stevel 2888 0 stevel /* 2889 0 stevel * Function: sd_scsi_probe_cache_init 2890 0 stevel * 2891 0 stevel * Description: Initializes the probe response cache mutex and head pointer. 2892 0 stevel * 2893 0 stevel * Context: Kernel thread context 2894 0 stevel */ 2895 0 stevel 2896 0 stevel static void 2897 0 stevel sd_scsi_probe_cache_init(void) 2898 0 stevel { 2899 0 stevel mutex_init(&sd_scsi_probe_cache_mutex, NULL, MUTEX_DRIVER, NULL); 2900 0 stevel sd_scsi_probe_cache_head = NULL; 2901 0 stevel } 2902 0 stevel 2903 0 stevel 2904 0 stevel /* 2905 0 stevel * Function: sd_scsi_probe_cache_fini 2906 0 stevel * 2907 0 stevel * Description: Frees all resources associated with the probe response cache. 2908 0 stevel * 2909 0 stevel * Context: Kernel thread context 2910 0 stevel */ 2911 0 stevel 2912 0 stevel static void 2913 0 stevel sd_scsi_probe_cache_fini(void) 2914 0 stevel { 2915 0 stevel struct sd_scsi_probe_cache *cp; 2916 0 stevel struct sd_scsi_probe_cache *ncp; 2917 0 stevel 2918 0 stevel /* Clean up our smart probing linked list */ 2919 0 stevel for (cp = sd_scsi_probe_cache_head; cp != NULL; cp = ncp) { 2920 0 stevel ncp = cp->next; 2921 0 stevel kmem_free(cp, sizeof (struct sd_scsi_probe_cache)); 2922 0 stevel } 2923 0 stevel sd_scsi_probe_cache_head = NULL; 2924 0 stevel mutex_destroy(&sd_scsi_probe_cache_mutex); 2925 0 stevel } 2926 0 stevel 2927 0 stevel 2928 0 stevel /* 2929 0 stevel * Function: sd_scsi_clear_probe_cache 2930 0 stevel * 2931 0 stevel * Description: This routine clears the probe response cache. This is 2932 0 stevel * done when open() returns ENXIO so that when deferred 2933 0 stevel * attach is attempted (possibly after a device has been 2934 0 stevel * turned on) we will retry the probe. Since we don't know 2935 0 stevel * which target we failed to open, we just clear the 2936 0 stevel * entire cache. 2937 0 stevel * 2938 0 stevel * Context: Kernel thread context 2939 0 stevel */ 2940 0 stevel 2941 0 stevel static void 2942 0 stevel sd_scsi_clear_probe_cache(void) 2943 0 stevel { 2944 0 stevel struct sd_scsi_probe_cache *cp; 2945 0 stevel int i; 2946 0 stevel 2947 0 stevel mutex_enter(&sd_scsi_probe_cache_mutex); 2948 0 stevel for (cp = sd_scsi_probe_cache_head; cp != NULL; cp = cp->next) { 2949 0 stevel /* 2950 0 stevel * Reset all entries to SCSIPROBE_EXISTS. This will 2951 0 stevel * force probing to be performed the next time 2952 0 stevel * sd_scsi_probe_with_cache is called. 2953 0 stevel */ 2954 0 stevel for (i = 0; i < NTARGETS_WIDE; i++) { 2955 0 stevel cp->cache[i] = SCSIPROBE_EXISTS; 2956 0 stevel } 2957 0 stevel } 2958 0 stevel mutex_exit(&sd_scsi_probe_cache_mutex); 2959 0 stevel } 2960 0 stevel 2961 0 stevel 2962 0 stevel /* 2963 0 stevel * Function: sd_scsi_probe_with_cache 2964 0 stevel * 2965 0 stevel * Description: This routine implements support for a scsi device probe 2966 0 stevel * with cache. The driver maintains a cache of the target 2967 0 stevel * responses to scsi probes. If we get no response from a 2968 0 stevel * target during a probe inquiry, we remember that, and we 2969 0 stevel * avoid additional calls to scsi_probe on non-zero LUNs 2970 0 stevel * on the same target until the cache is cleared. By doing 2971 0 stevel * so we avoid the 1/4 sec selection timeout for nonzero 2972 0 stevel * LUNs. lun0 of a target is always probed. 2973 0 stevel * 2974 0 stevel * Arguments: devp - Pointer to a scsi_device(9S) structure 2975 0 stevel * waitfunc - indicates what the allocator routines should 2976 0 stevel * do when resources are not available. This value 2977 0 stevel * is passed on to scsi_probe() when that routine 2978 0 stevel * is called. 2979 0 stevel * 2980 0 stevel * Return Code: SCSIPROBE_NORESP if a NORESP in probe response cache; 2981 0 stevel * otherwise the value returned by scsi_probe(9F). 2982 0 stevel * 2983 0 stevel * Context: Kernel thread context 2984 0 stevel */ 2985 0 stevel 2986 0 stevel static int 2987 0 stevel sd_scsi_probe_with_cache(struct scsi_device *devp, int (*waitfn)()) 2988 0 stevel { 2989 0 stevel struct sd_scsi_probe_cache *cp; 2990 0 stevel dev_info_t *pdip = ddi_get_parent(devp->sd_dev); 2991 159 jongkis int lun, tgt; 2992 159 jongkis 2993 159 jongkis lun = ddi_prop_get_int(DDI_DEV_T_ANY, devp->sd_dev, DDI_PROP_DONTPASS, 2994 159 jongkis SCSI_ADDR_PROP_LUN, 0); 2995 159 jongkis tgt = ddi_prop_get_int(DDI_DEV_T_ANY, devp->sd_dev, DDI_PROP_DONTPASS, 2996 159 jongkis SCSI_ADDR_PROP_TARGET, -1); 2997 0 stevel 2998 0 stevel /* Make sure caching enabled and target in range */ 2999 0 stevel if ((tgt < 0) || (tgt >= NTARGETS_WIDE)) { 3000 0 stevel /* do it the old way (no cache) */ 3001 0 stevel return (scsi_probe(devp, waitfn)); 3002 0 stevel } 3003 0 stevel 3004 0 stevel mutex_enter(&sd_scsi_probe_cache_mutex); 3005 0 stevel 3006 0 stevel /* Find the cache for this scsi bus instance */ 3007 0 stevel for (cp = sd_scsi_probe_cache_head; cp != NULL; cp = cp->next) { 3008 0 stevel if (cp->pdip == pdip) { 3009 0 stevel break; 3010 0 stevel } 3011 0 stevel } 3012 0 stevel 3013 0 stevel /* If we can't find a cache for this pdip, create one */ 3014 0 stevel if (cp == NULL) { 3015 0 stevel int i; 3016 0 stevel 3017 0 stevel cp = kmem_zalloc(sizeof (struct sd_scsi_probe_cache), 3018 0 stevel KM_SLEEP); 3019 0 stevel cp->pdip = pdip; 3020 0 stevel cp->next = sd_scsi_probe_cache_head; 3021 0 stevel sd_scsi_probe_cache_head = cp; 3022 0 stevel for (i = 0; i < NTARGETS_WIDE; i++) { 3023 0 stevel cp->